@file-viewer/docx 0.3.39 → 0.3.42
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/README.md +56 -0
- package/dist/document/common.d.ts +1 -0
- package/dist/document/grid-spacing.d.ts +4 -0
- package/dist/document/paragraph-spacing.d.ts +23 -0
- package/dist/docx-preview.js +470 -37
- package/dist/docx-preview.min.js +2 -2
- package/dist/docx-preview.min.mjs +2 -2
- package/dist/docx-preview.mjs +470 -37
- package/dist/docx-preview.worker.js +15436 -15510
- package/dist/font-scripts.d.ts +4 -0
- package/dist/html-renderer.d.ts +31 -0
- package/dist/settings/settings.d.ts +2 -0
- package/package.json +9 -6
package/dist/docx-preview.mjs
CHANGED
|
@@ -399,7 +399,7 @@ function parseCommonProperty(elem, props, xml) {
|
|
|
399
399
|
props.fontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
|
|
400
400
|
break;
|
|
401
401
|
case "szCs":
|
|
402
|
-
props.
|
|
402
|
+
props.complexFontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
|
|
403
403
|
break;
|
|
404
404
|
default:
|
|
405
405
|
return false;
|
|
@@ -1665,6 +1665,8 @@ function parseSettings(elem, xml) {
|
|
|
1665
1665
|
for (const c of xml.elements(el)) {
|
|
1666
1666
|
if (c.localName == "adjustLineHeightInTable")
|
|
1667
1667
|
result.adjustLineHeightInTable = xml.boolAttr(c, "val", true);
|
|
1668
|
+
else if (c.localName == "doNotUseHTMLParagraphAutoSpacing")
|
|
1669
|
+
result.doNotUseHTMLParagraphAutoSpacing = xml.boolAttr(c, "val", true);
|
|
1668
1670
|
}
|
|
1669
1671
|
break;
|
|
1670
1672
|
}
|
|
@@ -4036,6 +4038,44 @@ function createParagraphAddressResolver() {
|
|
|
4036
4038
|
};
|
|
4037
4039
|
}
|
|
4038
4040
|
|
|
4041
|
+
const WORD_PARAGRAPH_LINE_UNIT_PT = 12;
|
|
4042
|
+
function paragraphSpacingDeclaration(points, lines) {
|
|
4043
|
+
const lineValue = Number.isFinite(lines) && lines >= 0 ? `${(lines * WORD_PARAGRAPH_LINE_UNIT_PT / 100).toFixed(2)}pt` : null;
|
|
4044
|
+
const validPoints = /^(?:\d+(?:\.\d*)?|\.\d+)pt$/i.test(points ?? "");
|
|
4045
|
+
return { lines: lineValue, fallback: lines === 0 && validPoints ? points : lineValue ?? points };
|
|
4046
|
+
}
|
|
4047
|
+
const WORD_HTML_AUTO_SPACING_PT = 14;
|
|
4048
|
+
function effectiveParagraphSpacing(levels, fixed, styleId) {
|
|
4049
|
+
const value = (key) => levels.find(level => level?.[key] != null)?.[key];
|
|
4050
|
+
const side = (name) => {
|
|
4051
|
+
const prefix = `--docx-spacing-${name}`;
|
|
4052
|
+
const autoValue = value(`${prefix}-auto`);
|
|
4053
|
+
const auto = autoValue === "true";
|
|
4054
|
+
const lines = value(`${prefix}-lines`), points = value(`${prefix}-points`);
|
|
4055
|
+
const declared = autoValue === "true" || autoValue === "false"
|
|
4056
|
+
|| spacingPoints(lines) != null || spacingPoints(points) != null;
|
|
4057
|
+
const ordinary = parseFloat(lines) > 0 ? lines : points ?? lines ?? "0pt";
|
|
4058
|
+
return { auto: auto && !fixed, declared, length: auto && !fixed ? `${WORD_HTML_AUTO_SPACING_PT}pt` : ordinary };
|
|
4059
|
+
};
|
|
4060
|
+
const before = side("before"), after = side("after");
|
|
4061
|
+
return { before: before.length, after: after.length, beforeAuto: before.auto, afterAuto: after.auto,
|
|
4062
|
+
beforeDeclared: before.declared, afterDeclared: after.declared,
|
|
4063
|
+
contextual: value("--docx-contextual-spacing") === "true", styleId };
|
|
4064
|
+
}
|
|
4065
|
+
function spacingPoints(length) {
|
|
4066
|
+
const match = /^(\d+(?:\.\d*)?|\.\d+)(pt|px)$/i.exec(length ?? "");
|
|
4067
|
+
return match ? Number(match[1]) * (match[2].toLowerCase() === "px" ? .75 : 1) : null;
|
|
4068
|
+
}
|
|
4069
|
+
function paragraphSpacingGap(previous, next, fixed) {
|
|
4070
|
+
const after = spacingPoints(previous.after), before = spacingPoints(next.before);
|
|
4071
|
+
if (after == null || before == null)
|
|
4072
|
+
return null;
|
|
4073
|
+
const same = previous.styleId === next.styleId;
|
|
4074
|
+
const remainder = fixed ? before : Math.max(0, before - after);
|
|
4075
|
+
const gap = (same && previous.contextual ? 0 : after) + (same && next.contextual ? 0 : remainder);
|
|
4076
|
+
return `${Math.round(gap * 1000000) / 1000000}pt`;
|
|
4077
|
+
}
|
|
4078
|
+
|
|
4039
4079
|
var autos = {
|
|
4040
4080
|
shd: "inherit",
|
|
4041
4081
|
color: "var(--docx-auto-color, black)",
|
|
@@ -6186,8 +6226,10 @@ class DocumentParser {
|
|
|
6186
6226
|
style["font-size"] = style["min-height"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
|
6187
6227
|
break;
|
|
6188
6228
|
case "szCs":
|
|
6189
|
-
style["
|
|
6190
|
-
|
|
6229
|
+
style["--docx-complex-font-size"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
|
6230
|
+
break;
|
|
6231
|
+
case "cs":
|
|
6232
|
+
style["--docx-complex-script"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6191
6233
|
break;
|
|
6192
6234
|
case "shd":
|
|
6193
6235
|
style["background-color"] = xmlUtil.colorAttr(c, "fill", null, autos.shd);
|
|
@@ -6251,6 +6293,7 @@ class DocumentParser {
|
|
|
6251
6293
|
style["font-variant"] = globalXmlParser.boolAttr(c, "val", true) ? "small-caps" : "none";
|
|
6252
6294
|
break;
|
|
6253
6295
|
case "rtl":
|
|
6296
|
+
style["--docx-rtl-run"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6254
6297
|
if (globalXmlParser.boolAttr(c, "val", true)) {
|
|
6255
6298
|
style["direction"] = "rtl";
|
|
6256
6299
|
style["unicode-bidi"] = "embed";
|
|
@@ -6383,9 +6426,11 @@ class DocumentParser {
|
|
|
6383
6426
|
if (globalXmlParser.boolAttr(c, "val", true))
|
|
6384
6427
|
style["display"] = "none";
|
|
6385
6428
|
break;
|
|
6429
|
+
case "contextualSpacing":
|
|
6430
|
+
style["--docx-contextual-spacing"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6431
|
+
break;
|
|
6386
6432
|
case "tabs":
|
|
6387
6433
|
case "outlineLvl":
|
|
6388
|
-
case "contextualSpacing":
|
|
6389
6434
|
case "tblStyleColBandSize":
|
|
6390
6435
|
case "tblStyleRowBandSize":
|
|
6391
6436
|
case "suppressLineNumbers":
|
|
@@ -6495,6 +6540,18 @@ class DocumentParser {
|
|
|
6495
6540
|
style["--docx-latin-font-family"] = [...new Set(latinFonts)].join(', ');
|
|
6496
6541
|
style["--docx-partial-eastasia-font"] = !latinFonts.length && (eastAsia || eastAsiaTheme) && !cs && !csTheme ? "true" : "false";
|
|
6497
6542
|
}
|
|
6543
|
+
const slots = {
|
|
6544
|
+
ascii: [ascii, asciiTheme], hansi: [hAnsi, hAnsiTheme],
|
|
6545
|
+
eastasia: [eastAsia, eastAsiaTheme], complex: [cs, csTheme]
|
|
6546
|
+
};
|
|
6547
|
+
for (const [slot, [direct, themed]] of Object.entries(slots)) {
|
|
6548
|
+
const selected = themed || direct;
|
|
6549
|
+
if (!selected)
|
|
6550
|
+
continue;
|
|
6551
|
+
const family = selected.startsWith("var(") ? selected
|
|
6552
|
+
: expandDirectFont(selected, slot == "complex" ? themeScriptForLanguage(languages.bidi) : eastAsiaScript).join(', ');
|
|
6553
|
+
style[`--docx-font-${slot}`] = family;
|
|
6554
|
+
}
|
|
6498
6555
|
}
|
|
6499
6556
|
scriptThemeFontValue(value, language) {
|
|
6500
6557
|
if (!value)
|
|
@@ -6539,18 +6596,28 @@ class DocumentParser {
|
|
|
6539
6596
|
var afterAuto = globalXmlParser.boolAttr(node, "afterAutospacing", false);
|
|
6540
6597
|
var line = globalXmlParser.intAttr(node, "line", null);
|
|
6541
6598
|
var lineRule = globalXmlParser.attr(node, "lineRule");
|
|
6542
|
-
|
|
6543
|
-
|
|
6544
|
-
|
|
6545
|
-
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6599
|
+
for (const [side, margin, points, lines, auto] of [
|
|
6600
|
+
["before", "margin-top", before, beforeLines, beforeAuto],
|
|
6601
|
+
["after", "margin-bottom", after, afterLines, afterAuto]
|
|
6602
|
+
]) {
|
|
6603
|
+
const prefix = `--docx-spacing-${side}`;
|
|
6604
|
+
const { lines: lineValue, fallback } = paragraphSpacingDeclaration(points, lines);
|
|
6605
|
+
const autoSpecified = globalXmlParser.attr(node, `${side}Autospacing`) != null;
|
|
6606
|
+
if (points != null)
|
|
6607
|
+
style[`${prefix}-points`] = points;
|
|
6608
|
+
if (lineValue != null)
|
|
6609
|
+
style[`${prefix}-lines`] = lineValue;
|
|
6610
|
+
if (fallback != null)
|
|
6611
|
+
style[`${prefix}-fallback`] = fallback;
|
|
6612
|
+
if (autoSpecified)
|
|
6613
|
+
style[`${prefix}-auto`] = `${auto}`;
|
|
6614
|
+
if (auto)
|
|
6615
|
+
style[margin] = `${WORD_HTML_AUTO_SPACING_PT}pt`;
|
|
6616
|
+
else if (fallback != null)
|
|
6617
|
+
style[margin] = fallback;
|
|
6618
|
+
else if (autoSpecified)
|
|
6619
|
+
style[margin] = "0pt";
|
|
6620
|
+
}
|
|
6554
6621
|
if (line !== null) {
|
|
6555
6622
|
switch (lineRule ?? "auto") {
|
|
6556
6623
|
case "auto":
|
|
@@ -7012,6 +7079,22 @@ function decodeWordSymbol(font, code) {
|
|
|
7012
7079
|
return { text, normalized: text !== original };
|
|
7013
7080
|
}
|
|
7014
7081
|
|
|
7082
|
+
const eastAsianCharacter = /[\p{Script=Han}\p{Script=Hiragana}\p{Script=Katakana}\p{Script=Hangul}\p{Script=Bopomofo}\p{Script=Yi}\u2e80-\u2fff\u3000-\u303f\u31c0-\u31ef\u3200-\u33ff\ufe10-\ufe1f\ufe30-\ufe6f\uff00-\uffef]/u;
|
|
7083
|
+
const precedingFont = /[\p{Mark}\u200c\u200d\u2060]/u;
|
|
7084
|
+
function fontScriptRuns(text, previousEastAsian = false) {
|
|
7085
|
+
const runs = [];
|
|
7086
|
+
for (const character of text) {
|
|
7087
|
+
const previous = runs[runs.length - 1];
|
|
7088
|
+
const eastAsian = precedingFont.test(character)
|
|
7089
|
+
? previous?.eastAsian ?? previousEastAsian : eastAsianCharacter.test(character);
|
|
7090
|
+
if (previous?.eastAsian === eastAsian)
|
|
7091
|
+
previous.text += character;
|
|
7092
|
+
else
|
|
7093
|
+
runs.push({ text: character, eastAsian });
|
|
7094
|
+
}
|
|
7095
|
+
return runs;
|
|
7096
|
+
}
|
|
7097
|
+
|
|
7015
7098
|
class CommentLayer {
|
|
7016
7099
|
constructor(className, createLayer, layoutContent) {
|
|
7017
7100
|
this.className = className;
|
|
@@ -8026,6 +8109,18 @@ function layoutExplicitTabs(root, ownsElement = () => true) {
|
|
|
8026
8109
|
return applied;
|
|
8027
8110
|
}
|
|
8028
8111
|
|
|
8112
|
+
function gridAutomaticLineHeight(lineHeight, linePitch) {
|
|
8113
|
+
const multiplier = /^\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? Number(lineHeight) : NaN;
|
|
8114
|
+
return Number.isFinite(multiplier) && multiplier >= 1
|
|
8115
|
+
? `calc(${linePitch} * ${multiplier})`
|
|
8116
|
+
: /^-?\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? `calc(${lineHeight} * 1em)` : lineHeight;
|
|
8117
|
+
}
|
|
8118
|
+
function gridFontLineHeight(natural, pitch, multiplier = 1) {
|
|
8119
|
+
if (![natural, pitch, multiplier].every(Number.isFinite) || natural < 0 || pitch <= 0 || multiplier < 1)
|
|
8120
|
+
return null;
|
|
8121
|
+
return Math.max(pitch * multiplier, Math.max(1, Math.ceil((natural - 1 / 64) / pitch)) * pitch);
|
|
8122
|
+
}
|
|
8123
|
+
|
|
8029
8124
|
const DEFAULT_DARK_MODE_BASE_L = 21.247;
|
|
8030
8125
|
const LAB_EPSILON = Math.pow(6 / 29, 3);
|
|
8031
8126
|
function srgbToLinear(c) {
|
|
@@ -8688,6 +8783,22 @@ function normalizeCachedPageBreaks(elements, isHiddenRevision) {
|
|
|
8688
8783
|
return elements.map(copy);
|
|
8689
8784
|
}
|
|
8690
8785
|
|
|
8786
|
+
const legacyComplexScriptCharacters = /[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufeff]/u;
|
|
8787
|
+
const additionalComplexScriptCharacters = new RegExp([
|
|
8788
|
+
'Devanagari', 'Bengali', 'Gurmukhi', 'Gujarati', 'Oriya', 'Tamil', 'Telugu',
|
|
8789
|
+
'Kannada', 'Malayalam', 'Sinhala', 'Thai', 'Lao', 'Tibetan', 'Myanmar', 'Khmer'
|
|
8790
|
+
].map(script => `\\p{Script=${script}}`).join('|'), 'u');
|
|
8791
|
+
const neutralScriptCharacters = /[\p{Script=Common}\p{Script=Inherited}]/u;
|
|
8792
|
+
function isAdditionalComplexScriptRun(text) {
|
|
8793
|
+
if (!additionalComplexScriptCharacters.test(text))
|
|
8794
|
+
return false;
|
|
8795
|
+
for (const character of text) {
|
|
8796
|
+
if (!additionalComplexScriptCharacters.test(character)
|
|
8797
|
+
&& !legacyComplexScriptCharacters.test(character) && !neutralScriptCharacters.test(character))
|
|
8798
|
+
return false;
|
|
8799
|
+
}
|
|
8800
|
+
return true;
|
|
8801
|
+
}
|
|
8691
8802
|
const chartNamespaces = [
|
|
8692
8803
|
"http://schemas.openxmlformats.org/drawingml/2006/chart",
|
|
8693
8804
|
"http://purl.oclc.org/ooxml/drawingml/chart"
|
|
@@ -8759,6 +8870,7 @@ class HtmlRenderer {
|
|
|
8759
8870
|
this.currentTabs = [];
|
|
8760
8871
|
this.anchorLayouts = new Map();
|
|
8761
8872
|
this.currentParagraph = null;
|
|
8873
|
+
this.currentRunFont = null;
|
|
8762
8874
|
this.currentParagraphTabIndex = 0;
|
|
8763
8875
|
this.currentParagraphTabCount = 0;
|
|
8764
8876
|
this.commentMap = {};
|
|
@@ -8776,6 +8888,7 @@ class HtmlRenderer {
|
|
|
8776
8888
|
this.tasks = [];
|
|
8777
8889
|
this.postRenderTasks = [];
|
|
8778
8890
|
this.compatibleTextBoxSpacing = false;
|
|
8891
|
+
this.paragraphSpacingStates = new WeakMap();
|
|
8779
8892
|
this.h = h;
|
|
8780
8893
|
this.darkModeVarNames = new Map();
|
|
8781
8894
|
this.darkModePrintReset = {};
|
|
@@ -8787,6 +8900,9 @@ class HtmlRenderer {
|
|
|
8787
8900
|
this.rootSelector = options.inWrapper ? `.${this.className}-wrapper` : ':root';
|
|
8788
8901
|
this.h = options.h ?? h;
|
|
8789
8902
|
this.styleMap = null;
|
|
8903
|
+
this.defaultParagraphStyle = null;
|
|
8904
|
+
this.defaultCharacterStyle = null;
|
|
8905
|
+
this.defaultRunStyle = null;
|
|
8790
8906
|
this.tasks = [];
|
|
8791
8907
|
this.postRenderTasks = [];
|
|
8792
8908
|
this.commentLayer = null;
|
|
@@ -8881,6 +8997,7 @@ class HtmlRenderer {
|
|
|
8881
8997
|
variables['--docx-majorEastAsia-font'] = this.themeFontFamily(fontScheme.majorFont, "eastAsia", languages.eastAsia);
|
|
8882
8998
|
variables['--docx-majorBidi-font'] = this.themeFontFamily(fontScheme.majorFont, "complexScript", languages.bidi);
|
|
8883
8999
|
variables['--docx-majorCs-font'] = variables['--docx-majorBidi-font'];
|
|
9000
|
+
this.addThemeFontFallbackVariables(variables, "major", fontScheme.majorFont);
|
|
8884
9001
|
this.addThemeScriptFontVariables(variables, "major", fontScheme.majorFont);
|
|
8885
9002
|
}
|
|
8886
9003
|
if (fontScheme.minorFont) {
|
|
@@ -8888,6 +9005,7 @@ class HtmlRenderer {
|
|
|
8888
9005
|
variables['--docx-minorEastAsia-font'] = this.themeFontFamily(fontScheme.minorFont, "eastAsia", languages.eastAsia);
|
|
8889
9006
|
variables['--docx-minorBidi-font'] = this.themeFontFamily(fontScheme.minorFont, "complexScript", languages.bidi);
|
|
8890
9007
|
variables['--docx-minorCs-font'] = variables['--docx-minorBidi-font'];
|
|
9008
|
+
this.addThemeFontFallbackVariables(variables, "minor", fontScheme.minorFont);
|
|
8891
9009
|
this.addThemeScriptFontVariables(variables, "minor", fontScheme.minorFont);
|
|
8892
9010
|
}
|
|
8893
9011
|
}
|
|
@@ -8923,6 +9041,15 @@ class HtmlRenderer {
|
|
|
8923
9041
|
result.bidi = values["$lang-bidi"] ?? result.latin;
|
|
8924
9042
|
return result;
|
|
8925
9043
|
}
|
|
9044
|
+
addThemeFontFallbackVariables(variables, size, font) {
|
|
9045
|
+
const fallback = (direct, generic) => {
|
|
9046
|
+
const typeface = direct?.trim() || font.latinTypeface?.trim();
|
|
9047
|
+
return typeface ? `${encloseFontFamily(typeface)}, ${generic}` : generic;
|
|
9048
|
+
};
|
|
9049
|
+
variables[`--docx-${size}EastAsia-font-fallback`] = fallback(font.eaTypeface, "sans-serif");
|
|
9050
|
+
variables[`--docx-${size}Bidi-font-fallback`] = fallback(font.csTypeface, "serif");
|
|
9051
|
+
variables[`--docx-${size}Cs-font-fallback`] = variables[`--docx-${size}Bidi-font-fallback`];
|
|
9052
|
+
}
|
|
8926
9053
|
addThemeScriptFontVariables(variables, size, font) {
|
|
8927
9054
|
const eastAsianScripts = new Set(["Hans", "Hant", "Jpan", "Hang"]);
|
|
8928
9055
|
for (const script of Object.keys(font.scriptTypefaces ?? {})) {
|
|
@@ -8981,6 +9108,9 @@ class HtmlRenderer {
|
|
|
8981
9108
|
}
|
|
8982
9109
|
processStyles(styles) {
|
|
8983
9110
|
const stylesMap = keyBy(styles.filter(x => x.id != null), x => x.id);
|
|
9111
|
+
this.defaultParagraphStyle = styles.find(style => style.isDefault && style.target == "p");
|
|
9112
|
+
this.defaultCharacterStyle = styles.find(style => style.isDefault && style.target == "span");
|
|
9113
|
+
this.defaultRunStyle = styles.find(style => style.id == null);
|
|
8984
9114
|
for (const style of styles.filter(x => x.basedOn)) {
|
|
8985
9115
|
var baseStyle = stylesMap[style.basedOn];
|
|
8986
9116
|
if (baseStyle) {
|
|
@@ -9680,14 +9810,20 @@ class HtmlRenderer {
|
|
|
9680
9810
|
result.push({ paragraph: currentParagraph, breakAfter: false });
|
|
9681
9811
|
}
|
|
9682
9812
|
const last = result[result.length - 1]?.paragraph;
|
|
9813
|
+
const siblings = paragraph.parent?.children?.filter(child => ![DomType.BookmarkStart, DomType.BookmarkEnd].includes(child.type));
|
|
9683
9814
|
for (const item of result) {
|
|
9684
9815
|
item.paragraph.sectionProps = item.paragraph === last ? paragraph.sectionProps : null;
|
|
9816
|
+
item.paragraph.props = { ...item.paragraph.props,
|
|
9817
|
+
spacingFirstInFlow: siblings?.[0] === paragraph && item === result[0],
|
|
9818
|
+
spacingLastInFlow: siblings?.[siblings.length - 1] === paragraph && item.paragraph === last };
|
|
9685
9819
|
}
|
|
9686
|
-
if (
|
|
9687
|
-
const owner = result.find(part => this.
|
|
9820
|
+
if (result.length > 1) {
|
|
9821
|
+
const owner = result.find(part => this.hasPageModelContent(part.paragraph)) ?? result[0];
|
|
9688
9822
|
for (const part of result) {
|
|
9689
|
-
if (part !== owner)
|
|
9690
|
-
part.paragraph.props = { ...part.paragraph.props, anchorId: undefined
|
|
9823
|
+
if (part !== owner) {
|
|
9824
|
+
part.paragraph.props = { ...part.paragraph.props, anchorId: undefined,
|
|
9825
|
+
pageBreakContinuation: true, pageBreakEmpty: !this.hasPageModelContent(part.paragraph) };
|
|
9826
|
+
}
|
|
9691
9827
|
}
|
|
9692
9828
|
}
|
|
9693
9829
|
return result;
|
|
@@ -9698,6 +9834,73 @@ class HtmlRenderer {
|
|
|
9698
9834
|
styleValue(style, target, name) {
|
|
9699
9835
|
return this.styleValuesForTarget(style, target)?.[name];
|
|
9700
9836
|
}
|
|
9837
|
+
styleValueLevels(style, target) {
|
|
9838
|
+
const levels = [];
|
|
9839
|
+
const seen = new Set();
|
|
9840
|
+
while (style && !seen.has(style)) {
|
|
9841
|
+
seen.add(style);
|
|
9842
|
+
levels.push(this.styleValuesForTarget(style, target));
|
|
9843
|
+
style = this.findStyle(style.basedOn);
|
|
9844
|
+
}
|
|
9845
|
+
return levels;
|
|
9846
|
+
}
|
|
9847
|
+
effectiveParagraphNumbering(elem, style) {
|
|
9848
|
+
let numbering = elem?.numbering;
|
|
9849
|
+
let current = elem?.styleName ? style : this.defaultParagraphStyle;
|
|
9850
|
+
const seen = new Set();
|
|
9851
|
+
while (!numbering && current?.target == "p" && !seen.has(current)) {
|
|
9852
|
+
seen.add(current);
|
|
9853
|
+
numbering = current.paragraphProps?.numbering;
|
|
9854
|
+
current = this.findStyle(current.basedOn);
|
|
9855
|
+
}
|
|
9856
|
+
return numbering && !/^0+$/.test(String(numbering.id ?? "").trim()) ? numbering : null;
|
|
9857
|
+
}
|
|
9858
|
+
applyParagraphAutoSpacing(elem, style, result) {
|
|
9859
|
+
const paragraphStyle = elem.styleName ? style : this.defaultParagraphStyle;
|
|
9860
|
+
const numbering = this.effectiveParagraphNumbering(elem, style);
|
|
9861
|
+
const numberingStyle = numbering && this.document?.numberingPart?.domNumberings
|
|
9862
|
+
?.find(num => num.id == numbering.id && num.level == numbering.level)?.pStyle;
|
|
9863
|
+
const levels = [elem.cssStyle, ...this.styleValueLevels(paragraphStyle, "p"), numberingStyle,
|
|
9864
|
+
this.styleValuesForTarget(this.defaultRunStyle, "p")];
|
|
9865
|
+
const fixed = this.document?.settingsPart?.settings?.doNotUseHTMLParagraphAutoSpacing;
|
|
9866
|
+
const state = effectiveParagraphSpacing(levels, fixed, elem.styleName ?? paragraphStyle?.id ?? "");
|
|
9867
|
+
const siblings = elem.parent?.children?.filter(child => ![DomType.BookmarkStart, DomType.BookmarkEnd].includes(child.type));
|
|
9868
|
+
const first = elem.props?.spacingFirstInFlow ?? siblings?.[0] === elem;
|
|
9869
|
+
const last = elem.props?.spacingLastInFlow ?? siblings?.[siblings.length - 1] === elem;
|
|
9870
|
+
if (state.beforeAuto && first && [DomType.Document, DomType.Cell].includes(elem.parent?.type))
|
|
9871
|
+
state.before = "0pt";
|
|
9872
|
+
if (state.afterAuto && last && elem.parent?.type === DomType.Cell)
|
|
9873
|
+
state.after = "0pt";
|
|
9874
|
+
if (state.beforeDeclared)
|
|
9875
|
+
this.setCssStyle(result, "margin-top", state.before);
|
|
9876
|
+
if (state.afterDeclared)
|
|
9877
|
+
this.setCssStyle(result, "margin-bottom", state.after);
|
|
9878
|
+
this.paragraphSpacingStates.set(result, state);
|
|
9879
|
+
}
|
|
9880
|
+
applyFlowParagraphSpacing(nodes) {
|
|
9881
|
+
let previous = null;
|
|
9882
|
+
const fixed = this.document?.settingsPart?.settings?.doNotUseHTMLParagraphAutoSpacing;
|
|
9883
|
+
for (const node of nodes) {
|
|
9884
|
+
const state = typeof node === "object" && node && this.paragraphSpacingStates.get(node);
|
|
9885
|
+
if (!state) {
|
|
9886
|
+
const element = node;
|
|
9887
|
+
if (element?.nodeType === 3 && !element.textContent?.trim())
|
|
9888
|
+
continue;
|
|
9889
|
+
if (/^(a|span)$/i.test(element?.tagName ?? "") && !element.textContent && element.id)
|
|
9890
|
+
continue;
|
|
9891
|
+
previous = null;
|
|
9892
|
+
continue;
|
|
9893
|
+
}
|
|
9894
|
+
if (previous && (previous.state.afterDeclared || state.beforeDeclared)) {
|
|
9895
|
+
const gap = paragraphSpacingGap(previous.state, state, fixed);
|
|
9896
|
+
if (gap != null) {
|
|
9897
|
+
this.setCssStyle(previous.node, "margin-bottom", "0pt");
|
|
9898
|
+
this.setCssStyle(node, "margin-top", gap);
|
|
9899
|
+
}
|
|
9900
|
+
}
|
|
9901
|
+
previous = { node: node, state };
|
|
9902
|
+
}
|
|
9903
|
+
}
|
|
9701
9904
|
effectiveParagraphCssValue(elem, style, name) {
|
|
9702
9905
|
return elem.cssStyle?.[name] ?? this.styleValue(style, "p", name);
|
|
9703
9906
|
}
|
|
@@ -9724,6 +9927,57 @@ class HtmlRenderer {
|
|
|
9724
9927
|
this.setCssStyle(result, "--docx-latin-font-family", latin);
|
|
9725
9928
|
this.setCssStyle(result, "font-family", `var(--docx-latin-font-family), ${family}`);
|
|
9726
9929
|
}
|
|
9930
|
+
resolveRunFontSlots(elem, style) {
|
|
9931
|
+
const paragraph = elem.type == DomType.Paragraph ? elem : this.currentParagraph;
|
|
9932
|
+
const paragraphStyle = this.findStyle(paragraph?.styleName) ?? this.defaultParagraphStyle;
|
|
9933
|
+
const levels = [elem.cssStyle, ...this.styleValueLevels(style, "span"),
|
|
9934
|
+
paragraph?.cssStyle, ...this.styleValueLevels(paragraphStyle, "span"),
|
|
9935
|
+
this.styleValuesForTarget(this.defaultCharacterStyle, "span"),
|
|
9936
|
+
this.styleValuesForTarget(this.defaultRunStyle, "span")];
|
|
9937
|
+
const value = (key) => levels.find(level => level?.[key] != null)?.[key];
|
|
9938
|
+
const language = (key) => value(key) ?? value("$lang");
|
|
9939
|
+
const themedFont = (font, language) => {
|
|
9940
|
+
const match = /^var\((--docx-(?:major|minor)(?:EastAsia|Bidi|Cs)-font)(?:-[A-Za-z]{4}, var\(\1\))?\)$/.exec(font ?? "");
|
|
9941
|
+
if (!match)
|
|
9942
|
+
return font;
|
|
9943
|
+
const script = themeScriptForLanguage(language);
|
|
9944
|
+
const base = `var(${match[1]}-fallback)`;
|
|
9945
|
+
return script ? `var(${match[1]}-${script}, ${base})` : base;
|
|
9946
|
+
};
|
|
9947
|
+
const text = elem.type == DomType.Run ? (elem.children ?? [])
|
|
9948
|
+
.filter(child => child.type == DomType.Text || child.type == DomType.DeletedText)
|
|
9949
|
+
.map(child => child.text).join("") : "";
|
|
9950
|
+
const forceComplex = value("--docx-complex-script");
|
|
9951
|
+
const complex = forceComplex == "true" || value("--docx-rtl-run") == "true"
|
|
9952
|
+
|| (forceComplex != "false" && ((legacyComplexScriptCharacters.test(text)
|
|
9953
|
+
&& !/[\p{Script=Latin}\p{Script=Cyrillic}\p{Script=Han}]/u.test(text))
|
|
9954
|
+
|| isAdditionalComplexScriptRun(text)));
|
|
9955
|
+
const highAnsi = /[\p{Script=Cyrillic}\p{Script=Greek}]/u.test(text);
|
|
9956
|
+
const scriptRuns = fontScriptRuns(text);
|
|
9957
|
+
const eastAsianOnly = scriptRuns.length && scriptRuns.every(run => run.eastAsian);
|
|
9958
|
+
const slots = complex ? ["complex", "ascii", "hansi", "eastasia"]
|
|
9959
|
+
: eastAsianOnly ? ["eastasia", "ascii", "hansi", "complex"]
|
|
9960
|
+
: highAnsi ? ["hansi", "ascii", "eastasia", "complex"] : ["ascii", "hansi", "eastasia", "complex"];
|
|
9961
|
+
const resolveFonts = (slots) => slots.map(slot => {
|
|
9962
|
+
const font = value(`--docx-font-${slot}`);
|
|
9963
|
+
return slot == "eastasia" ? themedFont(font, language("$lang-eastAsia"))
|
|
9964
|
+
: slot == "complex" ? themedFont(font, language("$lang-bidi")) : font;
|
|
9965
|
+
}).filter(Boolean);
|
|
9966
|
+
const fontFamily = [...new Set(resolveFonts(slots))].join(', ');
|
|
9967
|
+
const eastAsianFontFamily = !complex && value("--docx-font-eastasia")
|
|
9968
|
+
? [...new Set(resolveFonts(["eastasia", ...slots.filter(slot => slot !== "eastasia")]))].join(', ') : null;
|
|
9969
|
+
return { fontFamily, eastAsianFontFamily,
|
|
9970
|
+
splitEastAsia: !!eastAsianFontFamily && eastAsianFontFamily !== fontFamily && scriptRuns.some(run => run.eastAsian),
|
|
9971
|
+
complexFontSize: complex ? value("--docx-complex-font-size") : null, previousEastAsian: false };
|
|
9972
|
+
}
|
|
9973
|
+
applyRunFontSlots(elem, style, result, font = this.resolveRunFontSlots(elem, style)) {
|
|
9974
|
+
if (font.fontFamily)
|
|
9975
|
+
this.setCssStyle(result, "font-family", font.fontFamily);
|
|
9976
|
+
if (font.complexFontSize) {
|
|
9977
|
+
this.setCssStyle(result, "font-size", font.complexFontSize);
|
|
9978
|
+
this.setCssStyle(result, "min-height", font.complexFontSize);
|
|
9979
|
+
}
|
|
9980
|
+
}
|
|
9727
9981
|
isInsideTableCell(elem) {
|
|
9728
9982
|
for (let p = elem.parent; p; p = p.parent) {
|
|
9729
9983
|
if (p.type == DomType.Cell)
|
|
@@ -9731,13 +9985,32 @@ class HtmlRenderer {
|
|
|
9731
9985
|
}
|
|
9732
9986
|
return false;
|
|
9733
9987
|
}
|
|
9988
|
+
paragraphSnapToGrid(elem, style) {
|
|
9989
|
+
const key = "--docx-snap-to-grid";
|
|
9990
|
+
if (elem.cssStyle?.[key] != null)
|
|
9991
|
+
return elem.cssStyle[key];
|
|
9992
|
+
let current = elem.styleName ? style : this.defaultParagraphStyle;
|
|
9993
|
+
const numbering = this.effectiveParagraphNumbering(elem, style);
|
|
9994
|
+
const seen = new Set();
|
|
9995
|
+
while (current?.target == "p" && !seen.has(current)) {
|
|
9996
|
+
seen.add(current);
|
|
9997
|
+
const value = this.styleValue(current, "p", key);
|
|
9998
|
+
if (value != null)
|
|
9999
|
+
return value;
|
|
10000
|
+
current = this.findStyle(current.basedOn);
|
|
10001
|
+
}
|
|
10002
|
+
const numberingStyle = numbering && this.document?.numberingPart?.domNumberings
|
|
10003
|
+
?.find(num => num.id == numbering.id && num.level == numbering.level)?.pStyle;
|
|
10004
|
+
return numberingStyle?.[key] ?? this.styleValue(this.defaultRunStyle, "p", key);
|
|
10005
|
+
}
|
|
9734
10006
|
paragraphUsesDocumentGrid(elem, style) {
|
|
9735
|
-
const
|
|
9736
|
-
|
|
10007
|
+
const grid = this.currentSectionProps?.docGrid;
|
|
10008
|
+
const linePitch = grid?.linePitch;
|
|
10009
|
+
if (!linePitch || !grid.type || grid.type === "default")
|
|
9737
10010
|
return false;
|
|
9738
10011
|
if (this.isInsideTableCell(elem) && !this.document.settingsPart?.settings?.adjustLineHeightInTable)
|
|
9739
10012
|
return false;
|
|
9740
|
-
const snapToGrid = this.
|
|
10013
|
+
const snapToGrid = this.paragraphSnapToGrid(elem, style);
|
|
9741
10014
|
return snapToGrid == null || !/^(0|false|off)$/i.test(snapToGrid);
|
|
9742
10015
|
}
|
|
9743
10016
|
setCssStyle(element, name, value) {
|
|
@@ -9757,17 +10030,27 @@ class HtmlRenderer {
|
|
|
9757
10030
|
const linePitch = this.currentSectionProps.docGrid.linePitch;
|
|
9758
10031
|
const lineHeight = this.effectiveParagraphCssValue(elem, style, "line-height");
|
|
9759
10032
|
const lineSpacing = elem.lineSpacing ?? style?.paragraphProps?.lineSpacing;
|
|
10033
|
+
const exact = lineSpacing?.lineRule == "exact" || lineSpacing?.lineRule == "exactly";
|
|
10034
|
+
if (!exact && !this.compatibleTextBoxSpacing && result.dataset
|
|
10035
|
+
&& ["lines", "linesAndChars"].includes(this.currentSectionProps.docGrid.type)) {
|
|
10036
|
+
const numeric = /^\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? Number(lineHeight) : 1;
|
|
10037
|
+
if (numeric >= 1) {
|
|
10038
|
+
result.dataset.docxParagraphGridPitch = linePitch;
|
|
10039
|
+
result.dataset.docxParagraphGridMultiple = `${numeric}`;
|
|
10040
|
+
result.dataset.docxParagraphGridAtLeast = `${lineSpacing?.lineRule == "atLeast"}`;
|
|
10041
|
+
}
|
|
10042
|
+
}
|
|
9760
10043
|
if (lineHeight) {
|
|
9761
|
-
if (
|
|
10044
|
+
if (exact)
|
|
9762
10045
|
return;
|
|
9763
|
-
const comparableLineHeight =
|
|
9764
|
-
? `calc(${lineHeight} * 1em)`
|
|
9765
|
-
: lineHeight;
|
|
10046
|
+
const comparableLineHeight = gridAutomaticLineHeight(lineHeight, linePitch);
|
|
9766
10047
|
this.preserveGridInlineMetrics(result);
|
|
9767
10048
|
this.setCssStyle(result, "line-height", `max(${comparableLineHeight}, ${linePitch})`);
|
|
9768
10049
|
this.applyDocumentGridMinimumHeight(elem, style, result, linePitch);
|
|
9769
10050
|
return;
|
|
9770
10051
|
}
|
|
10052
|
+
this.preserveGridInlineMetrics(result);
|
|
10053
|
+
this.setCssStyle(result, "line-height", linePitch);
|
|
9771
10054
|
this.applyDocumentGridMinimumHeight(elem, style, result, linePitch);
|
|
9772
10055
|
}
|
|
9773
10056
|
preserveGridInlineMetrics(result) {
|
|
@@ -9949,6 +10232,11 @@ class HtmlRenderer {
|
|
|
9949
10232
|
movedAny = true;
|
|
9950
10233
|
continue;
|
|
9951
10234
|
}
|
|
10235
|
+
const tail = article.lastElementChild;
|
|
10236
|
+
if (this.canRetainTablePrefix(tail, page) && this.splitOverflowBlock(tail, page, nextArticle)) {
|
|
10237
|
+
movedAny = true;
|
|
10238
|
+
continue;
|
|
10239
|
+
}
|
|
9952
10240
|
let chunk = this.pickPaginationChunk(article);
|
|
9953
10241
|
if (chunk.length == 0)
|
|
9954
10242
|
break;
|
|
@@ -10828,21 +11116,30 @@ class HtmlRenderer {
|
|
|
10828
11116
|
const rows = this.tableContentRows(table);
|
|
10829
11117
|
if (rows.length <= 1)
|
|
10830
11118
|
return false;
|
|
11119
|
+
const repeatHeaders = rows.filter(r => r.dataset.docxRepeatHeader == "true");
|
|
11120
|
+
if (repeatHeaders.length && !this.fitsTableRowPrefix(rows, page))
|
|
11121
|
+
return false;
|
|
10831
11122
|
const clone = this.cloneBlockShell(table);
|
|
10832
11123
|
clone.dataset.docxContinued = "true";
|
|
10833
11124
|
for (const child of Array.from(table.children)) {
|
|
10834
11125
|
if (child.tagName?.toLowerCase() == "colgroup")
|
|
10835
11126
|
clone.appendChild(child.cloneNode(true));
|
|
10836
11127
|
}
|
|
10837
|
-
for (const header of
|
|
11128
|
+
for (const [index, header] of repeatHeaders.entries()) {
|
|
10838
11129
|
const repeated = header.cloneNode(true);
|
|
10839
11130
|
repeated.dataset.docxRepeatedHeader = "true";
|
|
11131
|
+
for (const cell of Array.from(repeated.cells)) {
|
|
11132
|
+
const headerRowsRemaining = repeatHeaders.length - index;
|
|
11133
|
+
if (cell.rowSpan === 0 || cell.rowSpan > headerRowsRemaining)
|
|
11134
|
+
cell.rowSpan = headerRowsRemaining;
|
|
11135
|
+
}
|
|
10840
11136
|
clone.appendChild(repeated);
|
|
10841
11137
|
}
|
|
10842
11138
|
nextArticle.prepend(clone);
|
|
10843
11139
|
let movedAny = false;
|
|
10844
11140
|
let guard = 0;
|
|
10845
|
-
|
|
11141
|
+
const minimumSourceRows = repeatHeaders.length + 1;
|
|
11142
|
+
while (this.isPageOverflowing(page) && this.tableContentRows(table).length > minimumSourceRows && guard++ < 500) {
|
|
10846
11143
|
const currentRows = this.tableContentRows(table).filter(r => r.dataset.docxRepeatedHeader != "true");
|
|
10847
11144
|
const last = currentRows[currentRows.length - 1];
|
|
10848
11145
|
if (!last)
|
|
@@ -10854,8 +11151,58 @@ class HtmlRenderer {
|
|
|
10854
11151
|
clone.remove();
|
|
10855
11152
|
return false;
|
|
10856
11153
|
}
|
|
11154
|
+
const sourceRowCount = this.tableContentRows(table).length;
|
|
11155
|
+
const firstContinuationRow = this.firstMovedTableRow(clone);
|
|
11156
|
+
for (let rowIndex = 0; rowIndex < sourceRowCount; rowIndex++) {
|
|
11157
|
+
let column = 0;
|
|
11158
|
+
for (const cell of Array.from(rows[rowIndex].cells)) {
|
|
11159
|
+
const nextColumn = column + cell.colSpan;
|
|
11160
|
+
const remainingSpan = rowIndex + cell.rowSpan - sourceRowCount;
|
|
11161
|
+
if (remainingSpan > 0) {
|
|
11162
|
+
const continuation = this.cloneBlockShell(cell);
|
|
11163
|
+
continuation.textContent = "";
|
|
11164
|
+
continuation.rowSpan = remainingSpan;
|
|
11165
|
+
continuation.dataset.docxContinued = "true";
|
|
11166
|
+
let targetColumn = 0;
|
|
11167
|
+
let anchor = null;
|
|
11168
|
+
for (const targetCell of Array.from(firstContinuationRow.cells)) {
|
|
11169
|
+
if (targetColumn >= column) {
|
|
11170
|
+
anchor = targetCell;
|
|
11171
|
+
break;
|
|
11172
|
+
}
|
|
11173
|
+
targetColumn += targetCell.colSpan;
|
|
11174
|
+
}
|
|
11175
|
+
if (anchor && targetColumn === column && anchor.style.display === "none")
|
|
11176
|
+
anchor.replaceWith(continuation);
|
|
11177
|
+
else
|
|
11178
|
+
firstContinuationRow.insertBefore(continuation, anchor);
|
|
11179
|
+
cell.rowSpan = sourceRowCount - rowIndex;
|
|
11180
|
+
}
|
|
11181
|
+
column = nextColumn;
|
|
11182
|
+
}
|
|
11183
|
+
}
|
|
10857
11184
|
return true;
|
|
10858
11185
|
}
|
|
11186
|
+
canRetainTablePrefix(block, page) {
|
|
11187
|
+
if (block?.localName !== "table")
|
|
11188
|
+
return false;
|
|
11189
|
+
const style = getComputedStyle(block);
|
|
11190
|
+
if (style.position !== "static" || style.cssFloat !== "none" || block.dataset.docxFloat)
|
|
11191
|
+
return false;
|
|
11192
|
+
return this.fitsTableRowPrefix(this.tableContentRows(block), page);
|
|
11193
|
+
}
|
|
11194
|
+
fitsTableRowPrefix(rows, page) {
|
|
11195
|
+
if (rows.length < 2 || rows.some((row, index) => Array.from(row.cells).some(cell => cell.rowSpan < 1 || index + cell.rowSpan > rows.length)))
|
|
11196
|
+
return false;
|
|
11197
|
+
const firstBody = rows.findIndex(row => row.dataset.docxRepeatHeader != "true");
|
|
11198
|
+
if (firstBody < 0 || rows.slice(firstBody + 1).some(row => row.dataset.docxRepeatHeader == "true"))
|
|
11199
|
+
return false;
|
|
11200
|
+
const bottom = this.getPageBodyBottom(page) + (this.options.paginationTolerance ?? 2);
|
|
11201
|
+
return rows.slice(0, firstBody + 1).every(row => {
|
|
11202
|
+
const rect = row.getBoundingClientRect();
|
|
11203
|
+
return rect.height > 0 && rect.bottom <= bottom;
|
|
11204
|
+
});
|
|
11205
|
+
}
|
|
10859
11206
|
cloneBlockShell(element) {
|
|
10860
11207
|
const clone = element.cloneNode(false);
|
|
10861
11208
|
clone.removeAttribute("id");
|
|
@@ -11136,7 +11483,7 @@ class HtmlRenderer {
|
|
|
11136
11483
|
wrapperStyle = `@media not print { ${wrapperStyle} }`;
|
|
11137
11484
|
}
|
|
11138
11485
|
var styleText = `${wrapperStyle}
|
|
11139
|
-
.${c} { --docx-auto-color: ${autoColor}; color: var(--docx-auto-color); font-size: 10.5pt; font-family: var(--docx-minorHAnsi-font, "Times New Roman", serif); hyphens: auto; text-underline-position: from-font; font-kerning: normal; font-variant-ligatures: common-ligatures contextual; text-rendering: optimizeLegibility; line-break: auto; }
|
|
11486
|
+
.${c} { --docx-auto-color: ${autoColor}; color: var(--docx-auto-color); font-size: 10.5pt; font-family: var(--docx-minorHAnsi-font, "Times New Roman", serif); line-height: normal; hyphens: auto; text-underline-position: from-font; font-kerning: normal; font-variant-ligatures: common-ligatures contextual; text-rendering: optimizeLegibility; line-break: auto; }
|
|
11140
11487
|
section.${c} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: visible; isolation: isolate; }
|
|
11141
11488
|
section.${c}>header, section.${c}>footer { flex-shrink: 0; }
|
|
11142
11489
|
section.${c}>[data-docx-note-list] { flex-shrink: 0; }
|
|
@@ -11527,6 +11874,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11527
11874
|
}
|
|
11528
11875
|
const children = frameParagraphs
|
|
11529
11876
|
.flatMap(item => asArray(this.renderElement(item)).filter(node => node != null));
|
|
11877
|
+
this.applyFlowParagraphSpacing(children);
|
|
11530
11878
|
const frame = this.h({
|
|
11531
11879
|
tagName: "div",
|
|
11532
11880
|
className: `${this.className}-paragraph-frame`,
|
|
@@ -11546,6 +11894,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11546
11894
|
}
|
|
11547
11895
|
result.push(...asArray(this.renderElement(elems[i])).filter(e => e != null));
|
|
11548
11896
|
}
|
|
11897
|
+
this.applyFlowParagraphSpacing(result);
|
|
11549
11898
|
if (into)
|
|
11550
11899
|
result.forEach(c => into.appendChild(isString(c) ? document.createTextNode(c) : c));
|
|
11551
11900
|
return result;
|
|
@@ -11745,7 +12094,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11745
12094
|
const style = this.findStyle(this.currentParagraph?.styleName);
|
|
11746
12095
|
const isTocParagraph = this.isTocParagraphStyle(this.currentParagraph?.styleName, style);
|
|
11747
12096
|
const isNumberedTocLeader = !!trailingLeader
|
|
11748
|
-
&& !!(this.currentParagraph
|
|
12097
|
+
&& !!this.effectiveParagraphNumbering(this.currentParagraph, style)
|
|
11749
12098
|
&& isTocParagraph;
|
|
11750
12099
|
if (!trailingLeader)
|
|
11751
12100
|
return stop;
|
|
@@ -11789,18 +12138,22 @@ section.${c}>footer { z-index: 1; }
|
|
|
11789
12138
|
children = [flow];
|
|
11790
12139
|
}
|
|
11791
12140
|
var result = this.toHTML(elem, ns.html, "p", this.wrapTabLeaderChildren(children, true));
|
|
12141
|
+
this.applyParagraphAutoSpacing(elem, style, result);
|
|
11792
12142
|
this.applyTextBoxFontInheritance(elem, style, result);
|
|
12143
|
+
this.applyRunFontSlots(elem, style, result);
|
|
11793
12144
|
if (this.options.exposeDisplayTargets && elem.displayAddress) {
|
|
11794
12145
|
const part = this.currentPart ?? this.document.documentPart;
|
|
11795
12146
|
result.setAttribute("data-office-target", `${part.path}#${elem.displayAddress}`);
|
|
11796
12147
|
}
|
|
11797
|
-
const snapToGrid = this.
|
|
12148
|
+
const snapToGrid = this.paragraphSnapToGrid(elem, style);
|
|
11798
12149
|
if (/^(0|false|off)$/i.test(snapToGrid ?? ""))
|
|
11799
12150
|
result.style.letterSpacing = "normal";
|
|
11800
12151
|
this.currentParagraph = previousParagraph;
|
|
11801
12152
|
this.currentParagraphTabIndex = previousParagraphTabIndex;
|
|
11802
12153
|
this.currentParagraphTabCount = previousParagraphTabCount;
|
|
11803
|
-
const numbering = elem.
|
|
12154
|
+
const numbering = elem.props?.pageBreakContinuation ? null : this.effectiveParagraphNumbering(elem, style);
|
|
12155
|
+
if (elem.props?.pageBreakEmpty)
|
|
12156
|
+
result.style.display = "none";
|
|
11804
12157
|
if (numbering) {
|
|
11805
12158
|
result.classList.add(this.numberingClass(numbering.id, numbering.level));
|
|
11806
12159
|
}
|
|
@@ -11856,7 +12209,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11856
12209
|
return result;
|
|
11857
12210
|
}
|
|
11858
12211
|
uniformParagraphTextScale(paragraph, style) {
|
|
11859
|
-
if (paragraph
|
|
12212
|
+
if (this.effectiveParagraphNumbering(paragraph, style) || paragraph.frame
|
|
11860
12213
|
|| this.effectiveParagraphCssValue(paragraph, style, "writing-mode"))
|
|
11861
12214
|
return null;
|
|
11862
12215
|
const key = "--docx-text-scale";
|
|
@@ -12011,6 +12364,68 @@ section.${c}>footer { z-index: 1; }
|
|
|
12011
12364
|
probe.remove();
|
|
12012
12365
|
}
|
|
12013
12366
|
}
|
|
12367
|
+
refreshParagraphLineGrid(root) {
|
|
12368
|
+
const view = root.ownerDocument?.defaultView;
|
|
12369
|
+
const paragraphs = Array.from(root.querySelectorAll("[data-docx-paragraph-grid-pitch]"))
|
|
12370
|
+
.filter(paragraph => this.ownsLayoutElement(paragraph));
|
|
12371
|
+
if (!view || !paragraphs.length)
|
|
12372
|
+
return;
|
|
12373
|
+
const probe = root.ownerDocument.createElement("span");
|
|
12374
|
+
Object.assign(probe.style, { position: "absolute", visibility: "hidden", pointerEvents: "none",
|
|
12375
|
+
display: "inline-block", whiteSpace: "pre", width: "max-content", margin: "0", padding: "0", border: "0" });
|
|
12376
|
+
probe.setAttribute("aria-hidden", "true");
|
|
12377
|
+
probe.textContent = "Mg";
|
|
12378
|
+
const scope = root.getRootNode();
|
|
12379
|
+
(scope.nodeType == 11 && "host" in scope ? scope : root.ownerDocument.body).appendChild(probe);
|
|
12380
|
+
const cache = new Map();
|
|
12381
|
+
const natural = (style) => {
|
|
12382
|
+
const font = { fontFamily: style.fontFamily, fontSize: style.fontSize, fontWeight: style.fontWeight,
|
|
12383
|
+
fontStyle: style.fontStyle, fontStretch: style.fontStretch, lineHeight: "normal", height: "auto" };
|
|
12384
|
+
const key = JSON.stringify(font);
|
|
12385
|
+
if (!cache.has(key)) {
|
|
12386
|
+
Object.assign(probe.style, font);
|
|
12387
|
+
cache.set(key, probe.getBoundingClientRect().height);
|
|
12388
|
+
}
|
|
12389
|
+
return cache.get(key);
|
|
12390
|
+
};
|
|
12391
|
+
try {
|
|
12392
|
+
for (const paragraph of paragraphs) {
|
|
12393
|
+
const style = view.getComputedStyle(paragraph), size = parseFloat(style.fontSize);
|
|
12394
|
+
probe.style.height = paragraph.dataset.docxParagraphGridPitch;
|
|
12395
|
+
const pitch = parseFloat(view.getComputedStyle(probe).height);
|
|
12396
|
+
const multiplier = Number(paragraph.dataset.docxParagraphGridMultiple);
|
|
12397
|
+
let height = gridFontLineHeight(natural(style), pitch, multiplier);
|
|
12398
|
+
if (height == null)
|
|
12399
|
+
continue;
|
|
12400
|
+
if (paragraph.dataset.docxParagraphGridAtLeast === "true")
|
|
12401
|
+
height = Math.max(height, parseFloat(style.lineHeight) || 0);
|
|
12402
|
+
paragraph.style.lineHeight = `${height}px`;
|
|
12403
|
+
const visit = (parent, script = false) => {
|
|
12404
|
+
for (const child of Array.from(parent.children)) {
|
|
12405
|
+
if (child.namespaceURI !== ns.html || !/^(span|a|sub|sup|b|i|u|s|strike|strong|em)$/.test(child.localName))
|
|
12406
|
+
continue;
|
|
12407
|
+
const own = child.dataset.docxGridOwnedHeight === "true";
|
|
12408
|
+
if ((!own && child.style.lineHeight && child.style.lineHeight !== "normal")
|
|
12409
|
+
|| (child.style.display && child.style.display !== "inline" && !child.dataset.docxTextScale)
|
|
12410
|
+
|| /^(absolute|fixed)$/.test(child.style.position) || (child.style.cssFloat && child.style.cssFloat !== "none"))
|
|
12411
|
+
continue;
|
|
12412
|
+
const childStyle = view.getComputedStyle(child);
|
|
12413
|
+
const raised = script || /^(super|sub)$/.test(childStyle.verticalAlign);
|
|
12414
|
+
const breakOnly = !child.textContent && !!child.querySelector("br") && !child.querySelector("img,svg,math");
|
|
12415
|
+
const childHeight = breakOnly || (raised && parseFloat(childStyle.fontSize) <= size) ? 0
|
|
12416
|
+
: Math.max(height, gridFontLineHeight(natural(childStyle), pitch) ?? height);
|
|
12417
|
+
child.style.lineHeight = `${childHeight}px`;
|
|
12418
|
+
child.dataset.docxGridOwnedHeight = "true";
|
|
12419
|
+
visit(child, raised);
|
|
12420
|
+
}
|
|
12421
|
+
};
|
|
12422
|
+
visit(paragraph);
|
|
12423
|
+
}
|
|
12424
|
+
}
|
|
12425
|
+
finally {
|
|
12426
|
+
probe.remove();
|
|
12427
|
+
}
|
|
12428
|
+
}
|
|
12014
12429
|
async prepareLayout(root, generation = getLayoutGeneration(root)) {
|
|
12015
12430
|
if (!root.isConnected || !generation.isCurrent())
|
|
12016
12431
|
return;
|
|
@@ -12031,6 +12446,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
12031
12446
|
(owner ?? root).appendChild(this.commentLayer.root);
|
|
12032
12447
|
}
|
|
12033
12448
|
}
|
|
12449
|
+
this.refreshParagraphLineGrid(root);
|
|
12034
12450
|
this.refreshTextBoxLineGrid(root);
|
|
12035
12451
|
this.refreshTabStops(root);
|
|
12036
12452
|
this.refreshAnchors(root);
|
|
@@ -13973,7 +14389,14 @@ section.${c}>footer { z-index: 1; }
|
|
|
13973
14389
|
return false;
|
|
13974
14390
|
}
|
|
13975
14391
|
renderText(elem) {
|
|
13976
|
-
|
|
14392
|
+
const text = this.applyCjkLineBreakGuards(elem.text);
|
|
14393
|
+
if (!this.currentRunFont?.splitEastAsia)
|
|
14394
|
+
return this.h(text);
|
|
14395
|
+
const fragments = fontScriptRuns(text, this.currentRunFont.previousEastAsian);
|
|
14396
|
+
this.currentRunFont.previousEastAsian = fragments[fragments.length - 1]?.eastAsian ?? this.currentRunFont.previousEastAsian;
|
|
14397
|
+
return this.h({ tagName: "#fragment", children: fragments.map(run => run.eastAsian
|
|
14398
|
+
? this.h({ tagName: "span", className: `${this.className}-font-eastasia`, style: { fontFamily: this.currentRunFont.eastAsianFontFamily }, children: [run.text] })
|
|
14399
|
+
: this.h(run.text)) });
|
|
13977
14400
|
}
|
|
13978
14401
|
applyCjkLineBreakGuards(text) {
|
|
13979
14402
|
if (!text || !this.document.settingsPart?.settings?.kinsoku)
|
|
@@ -14155,7 +14578,17 @@ section.${c}>footer { z-index: 1; }
|
|
|
14155
14578
|
: elem.children;
|
|
14156
14579
|
if (elem.fieldRun && (!runChildren || runChildren.length == 0))
|
|
14157
14580
|
return null;
|
|
14158
|
-
|
|
14581
|
+
const previousFont = this.currentRunFont;
|
|
14582
|
+
const style = this.findStyle(elem.styleName);
|
|
14583
|
+
const font = this.resolveRunFontSlots(elem, style);
|
|
14584
|
+
this.currentRunFont = font;
|
|
14585
|
+
let children;
|
|
14586
|
+
try {
|
|
14587
|
+
children = this.renderElements(runChildren);
|
|
14588
|
+
}
|
|
14589
|
+
finally {
|
|
14590
|
+
this.currentRunFont = previousFont;
|
|
14591
|
+
}
|
|
14159
14592
|
if (elem.verticalAlign) {
|
|
14160
14593
|
children = [this.h({ tagName: elem.verticalAlign, children })];
|
|
14161
14594
|
}
|
|
@@ -14172,8 +14605,8 @@ section.${c}>footer { z-index: 1; }
|
|
|
14172
14605
|
return tab;
|
|
14173
14606
|
}
|
|
14174
14607
|
const result = this.toHTML(elem, ns.html, "span", children);
|
|
14175
|
-
const style = this.findStyle(elem.styleName);
|
|
14176
14608
|
this.applyTextBoxFontInheritance(elem, style, result);
|
|
14609
|
+
this.applyRunFontSlots(elem, style, result, font);
|
|
14177
14610
|
const snapToGrid = elem.cssStyle?.["--docx-snap-to-grid"] ?? this.styleValue(style, "span", "--docx-snap-to-grid");
|
|
14178
14611
|
if (/^(0|false|off)$/i.test(snapToGrid ?? ""))
|
|
14179
14612
|
result.style.letterSpacing = "normal";
|