@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.js
CHANGED
|
@@ -403,7 +403,7 @@
|
|
|
403
403
|
props.fontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
|
|
404
404
|
break;
|
|
405
405
|
case "szCs":
|
|
406
|
-
props.
|
|
406
|
+
props.complexFontSize = xml.lengthAttr(elem, "val", LengthUsage.FontSize);
|
|
407
407
|
break;
|
|
408
408
|
default:
|
|
409
409
|
return false;
|
|
@@ -1669,6 +1669,8 @@
|
|
|
1669
1669
|
for (const c of xml.elements(el)) {
|
|
1670
1670
|
if (c.localName == "adjustLineHeightInTable")
|
|
1671
1671
|
result.adjustLineHeightInTable = xml.boolAttr(c, "val", true);
|
|
1672
|
+
else if (c.localName == "doNotUseHTMLParagraphAutoSpacing")
|
|
1673
|
+
result.doNotUseHTMLParagraphAutoSpacing = xml.boolAttr(c, "val", true);
|
|
1672
1674
|
}
|
|
1673
1675
|
break;
|
|
1674
1676
|
}
|
|
@@ -4040,6 +4042,44 @@
|
|
|
4040
4042
|
};
|
|
4041
4043
|
}
|
|
4042
4044
|
|
|
4045
|
+
const WORD_PARAGRAPH_LINE_UNIT_PT = 12;
|
|
4046
|
+
function paragraphSpacingDeclaration(points, lines) {
|
|
4047
|
+
const lineValue = Number.isFinite(lines) && lines >= 0 ? `${(lines * WORD_PARAGRAPH_LINE_UNIT_PT / 100).toFixed(2)}pt` : null;
|
|
4048
|
+
const validPoints = /^(?:\d+(?:\.\d*)?|\.\d+)pt$/i.test(points ?? "");
|
|
4049
|
+
return { lines: lineValue, fallback: lines === 0 && validPoints ? points : lineValue ?? points };
|
|
4050
|
+
}
|
|
4051
|
+
const WORD_HTML_AUTO_SPACING_PT = 14;
|
|
4052
|
+
function effectiveParagraphSpacing(levels, fixed, styleId) {
|
|
4053
|
+
const value = (key) => levels.find(level => level?.[key] != null)?.[key];
|
|
4054
|
+
const side = (name) => {
|
|
4055
|
+
const prefix = `--docx-spacing-${name}`;
|
|
4056
|
+
const autoValue = value(`${prefix}-auto`);
|
|
4057
|
+
const auto = autoValue === "true";
|
|
4058
|
+
const lines = value(`${prefix}-lines`), points = value(`${prefix}-points`);
|
|
4059
|
+
const declared = autoValue === "true" || autoValue === "false"
|
|
4060
|
+
|| spacingPoints(lines) != null || spacingPoints(points) != null;
|
|
4061
|
+
const ordinary = parseFloat(lines) > 0 ? lines : points ?? lines ?? "0pt";
|
|
4062
|
+
return { auto: auto && !fixed, declared, length: auto && !fixed ? `${WORD_HTML_AUTO_SPACING_PT}pt` : ordinary };
|
|
4063
|
+
};
|
|
4064
|
+
const before = side("before"), after = side("after");
|
|
4065
|
+
return { before: before.length, after: after.length, beforeAuto: before.auto, afterAuto: after.auto,
|
|
4066
|
+
beforeDeclared: before.declared, afterDeclared: after.declared,
|
|
4067
|
+
contextual: value("--docx-contextual-spacing") === "true", styleId };
|
|
4068
|
+
}
|
|
4069
|
+
function spacingPoints(length) {
|
|
4070
|
+
const match = /^(\d+(?:\.\d*)?|\.\d+)(pt|px)$/i.exec(length ?? "");
|
|
4071
|
+
return match ? Number(match[1]) * (match[2].toLowerCase() === "px" ? .75 : 1) : null;
|
|
4072
|
+
}
|
|
4073
|
+
function paragraphSpacingGap(previous, next, fixed) {
|
|
4074
|
+
const after = spacingPoints(previous.after), before = spacingPoints(next.before);
|
|
4075
|
+
if (after == null || before == null)
|
|
4076
|
+
return null;
|
|
4077
|
+
const same = previous.styleId === next.styleId;
|
|
4078
|
+
const remainder = fixed ? before : Math.max(0, before - after);
|
|
4079
|
+
const gap = (same && previous.contextual ? 0 : after) + (same && next.contextual ? 0 : remainder);
|
|
4080
|
+
return `${Math.round(gap * 1000000) / 1000000}pt`;
|
|
4081
|
+
}
|
|
4082
|
+
|
|
4043
4083
|
var autos = {
|
|
4044
4084
|
shd: "inherit",
|
|
4045
4085
|
color: "var(--docx-auto-color, black)",
|
|
@@ -6190,8 +6230,10 @@
|
|
|
6190
6230
|
style["font-size"] = style["min-height"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
|
6191
6231
|
break;
|
|
6192
6232
|
case "szCs":
|
|
6193
|
-
style["
|
|
6194
|
-
|
|
6233
|
+
style["--docx-complex-font-size"] = globalXmlParser.lengthAttr(c, "val", LengthUsage.FontSize);
|
|
6234
|
+
break;
|
|
6235
|
+
case "cs":
|
|
6236
|
+
style["--docx-complex-script"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6195
6237
|
break;
|
|
6196
6238
|
case "shd":
|
|
6197
6239
|
style["background-color"] = xmlUtil.colorAttr(c, "fill", null, autos.shd);
|
|
@@ -6255,6 +6297,7 @@
|
|
|
6255
6297
|
style["font-variant"] = globalXmlParser.boolAttr(c, "val", true) ? "small-caps" : "none";
|
|
6256
6298
|
break;
|
|
6257
6299
|
case "rtl":
|
|
6300
|
+
style["--docx-rtl-run"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6258
6301
|
if (globalXmlParser.boolAttr(c, "val", true)) {
|
|
6259
6302
|
style["direction"] = "rtl";
|
|
6260
6303
|
style["unicode-bidi"] = "embed";
|
|
@@ -6387,9 +6430,11 @@
|
|
|
6387
6430
|
if (globalXmlParser.boolAttr(c, "val", true))
|
|
6388
6431
|
style["display"] = "none";
|
|
6389
6432
|
break;
|
|
6433
|
+
case "contextualSpacing":
|
|
6434
|
+
style["--docx-contextual-spacing"] = `${globalXmlParser.boolAttr(c, "val", true)}`;
|
|
6435
|
+
break;
|
|
6390
6436
|
case "tabs":
|
|
6391
6437
|
case "outlineLvl":
|
|
6392
|
-
case "contextualSpacing":
|
|
6393
6438
|
case "tblStyleColBandSize":
|
|
6394
6439
|
case "tblStyleRowBandSize":
|
|
6395
6440
|
case "suppressLineNumbers":
|
|
@@ -6499,6 +6544,18 @@
|
|
|
6499
6544
|
style["--docx-latin-font-family"] = [...new Set(latinFonts)].join(', ');
|
|
6500
6545
|
style["--docx-partial-eastasia-font"] = !latinFonts.length && (eastAsia || eastAsiaTheme) && !cs && !csTheme ? "true" : "false";
|
|
6501
6546
|
}
|
|
6547
|
+
const slots = {
|
|
6548
|
+
ascii: [ascii, asciiTheme], hansi: [hAnsi, hAnsiTheme],
|
|
6549
|
+
eastasia: [eastAsia, eastAsiaTheme], complex: [cs, csTheme]
|
|
6550
|
+
};
|
|
6551
|
+
for (const [slot, [direct, themed]] of Object.entries(slots)) {
|
|
6552
|
+
const selected = themed || direct;
|
|
6553
|
+
if (!selected)
|
|
6554
|
+
continue;
|
|
6555
|
+
const family = selected.startsWith("var(") ? selected
|
|
6556
|
+
: expandDirectFont(selected, slot == "complex" ? themeScriptForLanguage(languages.bidi) : eastAsiaScript).join(', ');
|
|
6557
|
+
style[`--docx-font-${slot}`] = family;
|
|
6558
|
+
}
|
|
6502
6559
|
}
|
|
6503
6560
|
scriptThemeFontValue(value, language) {
|
|
6504
6561
|
if (!value)
|
|
@@ -6543,18 +6600,28 @@
|
|
|
6543
6600
|
var afterAuto = globalXmlParser.boolAttr(node, "afterAutospacing", false);
|
|
6544
6601
|
var line = globalXmlParser.intAttr(node, "line", null);
|
|
6545
6602
|
var lineRule = globalXmlParser.attr(node, "lineRule");
|
|
6546
|
-
|
|
6547
|
-
|
|
6548
|
-
|
|
6549
|
-
|
|
6550
|
-
|
|
6551
|
-
|
|
6552
|
-
|
|
6553
|
-
|
|
6554
|
-
|
|
6555
|
-
|
|
6556
|
-
|
|
6557
|
-
|
|
6603
|
+
for (const [side, margin, points, lines, auto] of [
|
|
6604
|
+
["before", "margin-top", before, beforeLines, beforeAuto],
|
|
6605
|
+
["after", "margin-bottom", after, afterLines, afterAuto]
|
|
6606
|
+
]) {
|
|
6607
|
+
const prefix = `--docx-spacing-${side}`;
|
|
6608
|
+
const { lines: lineValue, fallback } = paragraphSpacingDeclaration(points, lines);
|
|
6609
|
+
const autoSpecified = globalXmlParser.attr(node, `${side}Autospacing`) != null;
|
|
6610
|
+
if (points != null)
|
|
6611
|
+
style[`${prefix}-points`] = points;
|
|
6612
|
+
if (lineValue != null)
|
|
6613
|
+
style[`${prefix}-lines`] = lineValue;
|
|
6614
|
+
if (fallback != null)
|
|
6615
|
+
style[`${prefix}-fallback`] = fallback;
|
|
6616
|
+
if (autoSpecified)
|
|
6617
|
+
style[`${prefix}-auto`] = `${auto}`;
|
|
6618
|
+
if (auto)
|
|
6619
|
+
style[margin] = `${WORD_HTML_AUTO_SPACING_PT}pt`;
|
|
6620
|
+
else if (fallback != null)
|
|
6621
|
+
style[margin] = fallback;
|
|
6622
|
+
else if (autoSpecified)
|
|
6623
|
+
style[margin] = "0pt";
|
|
6624
|
+
}
|
|
6558
6625
|
if (line !== null) {
|
|
6559
6626
|
switch (lineRule ?? "auto") {
|
|
6560
6627
|
case "auto":
|
|
@@ -7016,6 +7083,22 @@
|
|
|
7016
7083
|
return { text, normalized: text !== original };
|
|
7017
7084
|
}
|
|
7018
7085
|
|
|
7086
|
+
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;
|
|
7087
|
+
const precedingFont = /[\p{Mark}\u200c\u200d\u2060]/u;
|
|
7088
|
+
function fontScriptRuns(text, previousEastAsian = false) {
|
|
7089
|
+
const runs = [];
|
|
7090
|
+
for (const character of text) {
|
|
7091
|
+
const previous = runs[runs.length - 1];
|
|
7092
|
+
const eastAsian = precedingFont.test(character)
|
|
7093
|
+
? previous?.eastAsian ?? previousEastAsian : eastAsianCharacter.test(character);
|
|
7094
|
+
if (previous?.eastAsian === eastAsian)
|
|
7095
|
+
previous.text += character;
|
|
7096
|
+
else
|
|
7097
|
+
runs.push({ text: character, eastAsian });
|
|
7098
|
+
}
|
|
7099
|
+
return runs;
|
|
7100
|
+
}
|
|
7101
|
+
|
|
7019
7102
|
class CommentLayer {
|
|
7020
7103
|
constructor(className, createLayer, layoutContent) {
|
|
7021
7104
|
this.className = className;
|
|
@@ -8030,6 +8113,18 @@
|
|
|
8030
8113
|
return applied;
|
|
8031
8114
|
}
|
|
8032
8115
|
|
|
8116
|
+
function gridAutomaticLineHeight(lineHeight, linePitch) {
|
|
8117
|
+
const multiplier = /^\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? Number(lineHeight) : NaN;
|
|
8118
|
+
return Number.isFinite(multiplier) && multiplier >= 1
|
|
8119
|
+
? `calc(${linePitch} * ${multiplier})`
|
|
8120
|
+
: /^-?\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? `calc(${lineHeight} * 1em)` : lineHeight;
|
|
8121
|
+
}
|
|
8122
|
+
function gridFontLineHeight(natural, pitch, multiplier = 1) {
|
|
8123
|
+
if (![natural, pitch, multiplier].every(Number.isFinite) || natural < 0 || pitch <= 0 || multiplier < 1)
|
|
8124
|
+
return null;
|
|
8125
|
+
return Math.max(pitch * multiplier, Math.max(1, Math.ceil((natural - 1 / 64) / pitch)) * pitch);
|
|
8126
|
+
}
|
|
8127
|
+
|
|
8033
8128
|
const DEFAULT_DARK_MODE_BASE_L = 21.247;
|
|
8034
8129
|
const LAB_EPSILON = Math.pow(6 / 29, 3);
|
|
8035
8130
|
function srgbToLinear(c) {
|
|
@@ -8692,6 +8787,22 @@
|
|
|
8692
8787
|
return elements.map(copy);
|
|
8693
8788
|
}
|
|
8694
8789
|
|
|
8790
|
+
const legacyComplexScriptCharacters = /[\u0590-\u08ff\ufb1d-\ufdff\ufe70-\ufeff]/u;
|
|
8791
|
+
const additionalComplexScriptCharacters = new RegExp([
|
|
8792
|
+
'Devanagari', 'Bengali', 'Gurmukhi', 'Gujarati', 'Oriya', 'Tamil', 'Telugu',
|
|
8793
|
+
'Kannada', 'Malayalam', 'Sinhala', 'Thai', 'Lao', 'Tibetan', 'Myanmar', 'Khmer'
|
|
8794
|
+
].map(script => `\\p{Script=${script}}`).join('|'), 'u');
|
|
8795
|
+
const neutralScriptCharacters = /[\p{Script=Common}\p{Script=Inherited}]/u;
|
|
8796
|
+
function isAdditionalComplexScriptRun(text) {
|
|
8797
|
+
if (!additionalComplexScriptCharacters.test(text))
|
|
8798
|
+
return false;
|
|
8799
|
+
for (const character of text) {
|
|
8800
|
+
if (!additionalComplexScriptCharacters.test(character)
|
|
8801
|
+
&& !legacyComplexScriptCharacters.test(character) && !neutralScriptCharacters.test(character))
|
|
8802
|
+
return false;
|
|
8803
|
+
}
|
|
8804
|
+
return true;
|
|
8805
|
+
}
|
|
8695
8806
|
const chartNamespaces = [
|
|
8696
8807
|
"http://schemas.openxmlformats.org/drawingml/2006/chart",
|
|
8697
8808
|
"http://purl.oclc.org/ooxml/drawingml/chart"
|
|
@@ -8763,6 +8874,7 @@
|
|
|
8763
8874
|
this.currentTabs = [];
|
|
8764
8875
|
this.anchorLayouts = new Map();
|
|
8765
8876
|
this.currentParagraph = null;
|
|
8877
|
+
this.currentRunFont = null;
|
|
8766
8878
|
this.currentParagraphTabIndex = 0;
|
|
8767
8879
|
this.currentParagraphTabCount = 0;
|
|
8768
8880
|
this.commentMap = {};
|
|
@@ -8780,6 +8892,7 @@
|
|
|
8780
8892
|
this.tasks = [];
|
|
8781
8893
|
this.postRenderTasks = [];
|
|
8782
8894
|
this.compatibleTextBoxSpacing = false;
|
|
8895
|
+
this.paragraphSpacingStates = new WeakMap();
|
|
8783
8896
|
this.h = h;
|
|
8784
8897
|
this.darkModeVarNames = new Map();
|
|
8785
8898
|
this.darkModePrintReset = {};
|
|
@@ -8791,6 +8904,9 @@
|
|
|
8791
8904
|
this.rootSelector = options.inWrapper ? `.${this.className}-wrapper` : ':root';
|
|
8792
8905
|
this.h = options.h ?? h;
|
|
8793
8906
|
this.styleMap = null;
|
|
8907
|
+
this.defaultParagraphStyle = null;
|
|
8908
|
+
this.defaultCharacterStyle = null;
|
|
8909
|
+
this.defaultRunStyle = null;
|
|
8794
8910
|
this.tasks = [];
|
|
8795
8911
|
this.postRenderTasks = [];
|
|
8796
8912
|
this.commentLayer = null;
|
|
@@ -8885,6 +9001,7 @@
|
|
|
8885
9001
|
variables['--docx-majorEastAsia-font'] = this.themeFontFamily(fontScheme.majorFont, "eastAsia", languages.eastAsia);
|
|
8886
9002
|
variables['--docx-majorBidi-font'] = this.themeFontFamily(fontScheme.majorFont, "complexScript", languages.bidi);
|
|
8887
9003
|
variables['--docx-majorCs-font'] = variables['--docx-majorBidi-font'];
|
|
9004
|
+
this.addThemeFontFallbackVariables(variables, "major", fontScheme.majorFont);
|
|
8888
9005
|
this.addThemeScriptFontVariables(variables, "major", fontScheme.majorFont);
|
|
8889
9006
|
}
|
|
8890
9007
|
if (fontScheme.minorFont) {
|
|
@@ -8892,6 +9009,7 @@
|
|
|
8892
9009
|
variables['--docx-minorEastAsia-font'] = this.themeFontFamily(fontScheme.minorFont, "eastAsia", languages.eastAsia);
|
|
8893
9010
|
variables['--docx-minorBidi-font'] = this.themeFontFamily(fontScheme.minorFont, "complexScript", languages.bidi);
|
|
8894
9011
|
variables['--docx-minorCs-font'] = variables['--docx-minorBidi-font'];
|
|
9012
|
+
this.addThemeFontFallbackVariables(variables, "minor", fontScheme.minorFont);
|
|
8895
9013
|
this.addThemeScriptFontVariables(variables, "minor", fontScheme.minorFont);
|
|
8896
9014
|
}
|
|
8897
9015
|
}
|
|
@@ -8927,6 +9045,15 @@
|
|
|
8927
9045
|
result.bidi = values["$lang-bidi"] ?? result.latin;
|
|
8928
9046
|
return result;
|
|
8929
9047
|
}
|
|
9048
|
+
addThemeFontFallbackVariables(variables, size, font) {
|
|
9049
|
+
const fallback = (direct, generic) => {
|
|
9050
|
+
const typeface = direct?.trim() || font.latinTypeface?.trim();
|
|
9051
|
+
return typeface ? `${encloseFontFamily(typeface)}, ${generic}` : generic;
|
|
9052
|
+
};
|
|
9053
|
+
variables[`--docx-${size}EastAsia-font-fallback`] = fallback(font.eaTypeface, "sans-serif");
|
|
9054
|
+
variables[`--docx-${size}Bidi-font-fallback`] = fallback(font.csTypeface, "serif");
|
|
9055
|
+
variables[`--docx-${size}Cs-font-fallback`] = variables[`--docx-${size}Bidi-font-fallback`];
|
|
9056
|
+
}
|
|
8930
9057
|
addThemeScriptFontVariables(variables, size, font) {
|
|
8931
9058
|
const eastAsianScripts = new Set(["Hans", "Hant", "Jpan", "Hang"]);
|
|
8932
9059
|
for (const script of Object.keys(font.scriptTypefaces ?? {})) {
|
|
@@ -8985,6 +9112,9 @@
|
|
|
8985
9112
|
}
|
|
8986
9113
|
processStyles(styles) {
|
|
8987
9114
|
const stylesMap = keyBy(styles.filter(x => x.id != null), x => x.id);
|
|
9115
|
+
this.defaultParagraphStyle = styles.find(style => style.isDefault && style.target == "p");
|
|
9116
|
+
this.defaultCharacterStyle = styles.find(style => style.isDefault && style.target == "span");
|
|
9117
|
+
this.defaultRunStyle = styles.find(style => style.id == null);
|
|
8988
9118
|
for (const style of styles.filter(x => x.basedOn)) {
|
|
8989
9119
|
var baseStyle = stylesMap[style.basedOn];
|
|
8990
9120
|
if (baseStyle) {
|
|
@@ -9684,14 +9814,20 @@
|
|
|
9684
9814
|
result.push({ paragraph: currentParagraph, breakAfter: false });
|
|
9685
9815
|
}
|
|
9686
9816
|
const last = result[result.length - 1]?.paragraph;
|
|
9817
|
+
const siblings = paragraph.parent?.children?.filter(child => ![DomType.BookmarkStart, DomType.BookmarkEnd].includes(child.type));
|
|
9687
9818
|
for (const item of result) {
|
|
9688
9819
|
item.paragraph.sectionProps = item.paragraph === last ? paragraph.sectionProps : null;
|
|
9820
|
+
item.paragraph.props = { ...item.paragraph.props,
|
|
9821
|
+
spacingFirstInFlow: siblings?.[0] === paragraph && item === result[0],
|
|
9822
|
+
spacingLastInFlow: siblings?.[siblings.length - 1] === paragraph && item.paragraph === last };
|
|
9689
9823
|
}
|
|
9690
|
-
if (
|
|
9691
|
-
const owner = result.find(part => this.
|
|
9824
|
+
if (result.length > 1) {
|
|
9825
|
+
const owner = result.find(part => this.hasPageModelContent(part.paragraph)) ?? result[0];
|
|
9692
9826
|
for (const part of result) {
|
|
9693
|
-
if (part !== owner)
|
|
9694
|
-
part.paragraph.props = { ...part.paragraph.props, anchorId: undefined
|
|
9827
|
+
if (part !== owner) {
|
|
9828
|
+
part.paragraph.props = { ...part.paragraph.props, anchorId: undefined,
|
|
9829
|
+
pageBreakContinuation: true, pageBreakEmpty: !this.hasPageModelContent(part.paragraph) };
|
|
9830
|
+
}
|
|
9695
9831
|
}
|
|
9696
9832
|
}
|
|
9697
9833
|
return result;
|
|
@@ -9702,6 +9838,73 @@
|
|
|
9702
9838
|
styleValue(style, target, name) {
|
|
9703
9839
|
return this.styleValuesForTarget(style, target)?.[name];
|
|
9704
9840
|
}
|
|
9841
|
+
styleValueLevels(style, target) {
|
|
9842
|
+
const levels = [];
|
|
9843
|
+
const seen = new Set();
|
|
9844
|
+
while (style && !seen.has(style)) {
|
|
9845
|
+
seen.add(style);
|
|
9846
|
+
levels.push(this.styleValuesForTarget(style, target));
|
|
9847
|
+
style = this.findStyle(style.basedOn);
|
|
9848
|
+
}
|
|
9849
|
+
return levels;
|
|
9850
|
+
}
|
|
9851
|
+
effectiveParagraphNumbering(elem, style) {
|
|
9852
|
+
let numbering = elem?.numbering;
|
|
9853
|
+
let current = elem?.styleName ? style : this.defaultParagraphStyle;
|
|
9854
|
+
const seen = new Set();
|
|
9855
|
+
while (!numbering && current?.target == "p" && !seen.has(current)) {
|
|
9856
|
+
seen.add(current);
|
|
9857
|
+
numbering = current.paragraphProps?.numbering;
|
|
9858
|
+
current = this.findStyle(current.basedOn);
|
|
9859
|
+
}
|
|
9860
|
+
return numbering && !/^0+$/.test(String(numbering.id ?? "").trim()) ? numbering : null;
|
|
9861
|
+
}
|
|
9862
|
+
applyParagraphAutoSpacing(elem, style, result) {
|
|
9863
|
+
const paragraphStyle = elem.styleName ? style : this.defaultParagraphStyle;
|
|
9864
|
+
const numbering = this.effectiveParagraphNumbering(elem, style);
|
|
9865
|
+
const numberingStyle = numbering && this.document?.numberingPart?.domNumberings
|
|
9866
|
+
?.find(num => num.id == numbering.id && num.level == numbering.level)?.pStyle;
|
|
9867
|
+
const levels = [elem.cssStyle, ...this.styleValueLevels(paragraphStyle, "p"), numberingStyle,
|
|
9868
|
+
this.styleValuesForTarget(this.defaultRunStyle, "p")];
|
|
9869
|
+
const fixed = this.document?.settingsPart?.settings?.doNotUseHTMLParagraphAutoSpacing;
|
|
9870
|
+
const state = effectiveParagraphSpacing(levels, fixed, elem.styleName ?? paragraphStyle?.id ?? "");
|
|
9871
|
+
const siblings = elem.parent?.children?.filter(child => ![DomType.BookmarkStart, DomType.BookmarkEnd].includes(child.type));
|
|
9872
|
+
const first = elem.props?.spacingFirstInFlow ?? siblings?.[0] === elem;
|
|
9873
|
+
const last = elem.props?.spacingLastInFlow ?? siblings?.[siblings.length - 1] === elem;
|
|
9874
|
+
if (state.beforeAuto && first && [DomType.Document, DomType.Cell].includes(elem.parent?.type))
|
|
9875
|
+
state.before = "0pt";
|
|
9876
|
+
if (state.afterAuto && last && elem.parent?.type === DomType.Cell)
|
|
9877
|
+
state.after = "0pt";
|
|
9878
|
+
if (state.beforeDeclared)
|
|
9879
|
+
this.setCssStyle(result, "margin-top", state.before);
|
|
9880
|
+
if (state.afterDeclared)
|
|
9881
|
+
this.setCssStyle(result, "margin-bottom", state.after);
|
|
9882
|
+
this.paragraphSpacingStates.set(result, state);
|
|
9883
|
+
}
|
|
9884
|
+
applyFlowParagraphSpacing(nodes) {
|
|
9885
|
+
let previous = null;
|
|
9886
|
+
const fixed = this.document?.settingsPart?.settings?.doNotUseHTMLParagraphAutoSpacing;
|
|
9887
|
+
for (const node of nodes) {
|
|
9888
|
+
const state = typeof node === "object" && node && this.paragraphSpacingStates.get(node);
|
|
9889
|
+
if (!state) {
|
|
9890
|
+
const element = node;
|
|
9891
|
+
if (element?.nodeType === 3 && !element.textContent?.trim())
|
|
9892
|
+
continue;
|
|
9893
|
+
if (/^(a|span)$/i.test(element?.tagName ?? "") && !element.textContent && element.id)
|
|
9894
|
+
continue;
|
|
9895
|
+
previous = null;
|
|
9896
|
+
continue;
|
|
9897
|
+
}
|
|
9898
|
+
if (previous && (previous.state.afterDeclared || state.beforeDeclared)) {
|
|
9899
|
+
const gap = paragraphSpacingGap(previous.state, state, fixed);
|
|
9900
|
+
if (gap != null) {
|
|
9901
|
+
this.setCssStyle(previous.node, "margin-bottom", "0pt");
|
|
9902
|
+
this.setCssStyle(node, "margin-top", gap);
|
|
9903
|
+
}
|
|
9904
|
+
}
|
|
9905
|
+
previous = { node: node, state };
|
|
9906
|
+
}
|
|
9907
|
+
}
|
|
9705
9908
|
effectiveParagraphCssValue(elem, style, name) {
|
|
9706
9909
|
return elem.cssStyle?.[name] ?? this.styleValue(style, "p", name);
|
|
9707
9910
|
}
|
|
@@ -9728,6 +9931,57 @@
|
|
|
9728
9931
|
this.setCssStyle(result, "--docx-latin-font-family", latin);
|
|
9729
9932
|
this.setCssStyle(result, "font-family", `var(--docx-latin-font-family), ${family}`);
|
|
9730
9933
|
}
|
|
9934
|
+
resolveRunFontSlots(elem, style) {
|
|
9935
|
+
const paragraph = elem.type == DomType.Paragraph ? elem : this.currentParagraph;
|
|
9936
|
+
const paragraphStyle = this.findStyle(paragraph?.styleName) ?? this.defaultParagraphStyle;
|
|
9937
|
+
const levels = [elem.cssStyle, ...this.styleValueLevels(style, "span"),
|
|
9938
|
+
paragraph?.cssStyle, ...this.styleValueLevels(paragraphStyle, "span"),
|
|
9939
|
+
this.styleValuesForTarget(this.defaultCharacterStyle, "span"),
|
|
9940
|
+
this.styleValuesForTarget(this.defaultRunStyle, "span")];
|
|
9941
|
+
const value = (key) => levels.find(level => level?.[key] != null)?.[key];
|
|
9942
|
+
const language = (key) => value(key) ?? value("$lang");
|
|
9943
|
+
const themedFont = (font, language) => {
|
|
9944
|
+
const match = /^var\((--docx-(?:major|minor)(?:EastAsia|Bidi|Cs)-font)(?:-[A-Za-z]{4}, var\(\1\))?\)$/.exec(font ?? "");
|
|
9945
|
+
if (!match)
|
|
9946
|
+
return font;
|
|
9947
|
+
const script = themeScriptForLanguage(language);
|
|
9948
|
+
const base = `var(${match[1]}-fallback)`;
|
|
9949
|
+
return script ? `var(${match[1]}-${script}, ${base})` : base;
|
|
9950
|
+
};
|
|
9951
|
+
const text = elem.type == DomType.Run ? (elem.children ?? [])
|
|
9952
|
+
.filter(child => child.type == DomType.Text || child.type == DomType.DeletedText)
|
|
9953
|
+
.map(child => child.text).join("") : "";
|
|
9954
|
+
const forceComplex = value("--docx-complex-script");
|
|
9955
|
+
const complex = forceComplex == "true" || value("--docx-rtl-run") == "true"
|
|
9956
|
+
|| (forceComplex != "false" && ((legacyComplexScriptCharacters.test(text)
|
|
9957
|
+
&& !/[\p{Script=Latin}\p{Script=Cyrillic}\p{Script=Han}]/u.test(text))
|
|
9958
|
+
|| isAdditionalComplexScriptRun(text)));
|
|
9959
|
+
const highAnsi = /[\p{Script=Cyrillic}\p{Script=Greek}]/u.test(text);
|
|
9960
|
+
const scriptRuns = fontScriptRuns(text);
|
|
9961
|
+
const eastAsianOnly = scriptRuns.length && scriptRuns.every(run => run.eastAsian);
|
|
9962
|
+
const slots = complex ? ["complex", "ascii", "hansi", "eastasia"]
|
|
9963
|
+
: eastAsianOnly ? ["eastasia", "ascii", "hansi", "complex"]
|
|
9964
|
+
: highAnsi ? ["hansi", "ascii", "eastasia", "complex"] : ["ascii", "hansi", "eastasia", "complex"];
|
|
9965
|
+
const resolveFonts = (slots) => slots.map(slot => {
|
|
9966
|
+
const font = value(`--docx-font-${slot}`);
|
|
9967
|
+
return slot == "eastasia" ? themedFont(font, language("$lang-eastAsia"))
|
|
9968
|
+
: slot == "complex" ? themedFont(font, language("$lang-bidi")) : font;
|
|
9969
|
+
}).filter(Boolean);
|
|
9970
|
+
const fontFamily = [...new Set(resolveFonts(slots))].join(', ');
|
|
9971
|
+
const eastAsianFontFamily = !complex && value("--docx-font-eastasia")
|
|
9972
|
+
? [...new Set(resolveFonts(["eastasia", ...slots.filter(slot => slot !== "eastasia")]))].join(', ') : null;
|
|
9973
|
+
return { fontFamily, eastAsianFontFamily,
|
|
9974
|
+
splitEastAsia: !!eastAsianFontFamily && eastAsianFontFamily !== fontFamily && scriptRuns.some(run => run.eastAsian),
|
|
9975
|
+
complexFontSize: complex ? value("--docx-complex-font-size") : null, previousEastAsian: false };
|
|
9976
|
+
}
|
|
9977
|
+
applyRunFontSlots(elem, style, result, font = this.resolveRunFontSlots(elem, style)) {
|
|
9978
|
+
if (font.fontFamily)
|
|
9979
|
+
this.setCssStyle(result, "font-family", font.fontFamily);
|
|
9980
|
+
if (font.complexFontSize) {
|
|
9981
|
+
this.setCssStyle(result, "font-size", font.complexFontSize);
|
|
9982
|
+
this.setCssStyle(result, "min-height", font.complexFontSize);
|
|
9983
|
+
}
|
|
9984
|
+
}
|
|
9731
9985
|
isInsideTableCell(elem) {
|
|
9732
9986
|
for (let p = elem.parent; p; p = p.parent) {
|
|
9733
9987
|
if (p.type == DomType.Cell)
|
|
@@ -9735,13 +9989,32 @@
|
|
|
9735
9989
|
}
|
|
9736
9990
|
return false;
|
|
9737
9991
|
}
|
|
9992
|
+
paragraphSnapToGrid(elem, style) {
|
|
9993
|
+
const key = "--docx-snap-to-grid";
|
|
9994
|
+
if (elem.cssStyle?.[key] != null)
|
|
9995
|
+
return elem.cssStyle[key];
|
|
9996
|
+
let current = elem.styleName ? style : this.defaultParagraphStyle;
|
|
9997
|
+
const numbering = this.effectiveParagraphNumbering(elem, style);
|
|
9998
|
+
const seen = new Set();
|
|
9999
|
+
while (current?.target == "p" && !seen.has(current)) {
|
|
10000
|
+
seen.add(current);
|
|
10001
|
+
const value = this.styleValue(current, "p", key);
|
|
10002
|
+
if (value != null)
|
|
10003
|
+
return value;
|
|
10004
|
+
current = this.findStyle(current.basedOn);
|
|
10005
|
+
}
|
|
10006
|
+
const numberingStyle = numbering && this.document?.numberingPart?.domNumberings
|
|
10007
|
+
?.find(num => num.id == numbering.id && num.level == numbering.level)?.pStyle;
|
|
10008
|
+
return numberingStyle?.[key] ?? this.styleValue(this.defaultRunStyle, "p", key);
|
|
10009
|
+
}
|
|
9738
10010
|
paragraphUsesDocumentGrid(elem, style) {
|
|
9739
|
-
const
|
|
9740
|
-
|
|
10011
|
+
const grid = this.currentSectionProps?.docGrid;
|
|
10012
|
+
const linePitch = grid?.linePitch;
|
|
10013
|
+
if (!linePitch || !grid.type || grid.type === "default")
|
|
9741
10014
|
return false;
|
|
9742
10015
|
if (this.isInsideTableCell(elem) && !this.document.settingsPart?.settings?.adjustLineHeightInTable)
|
|
9743
10016
|
return false;
|
|
9744
|
-
const snapToGrid = this.
|
|
10017
|
+
const snapToGrid = this.paragraphSnapToGrid(elem, style);
|
|
9745
10018
|
return snapToGrid == null || !/^(0|false|off)$/i.test(snapToGrid);
|
|
9746
10019
|
}
|
|
9747
10020
|
setCssStyle(element, name, value) {
|
|
@@ -9761,17 +10034,27 @@
|
|
|
9761
10034
|
const linePitch = this.currentSectionProps.docGrid.linePitch;
|
|
9762
10035
|
const lineHeight = this.effectiveParagraphCssValue(elem, style, "line-height");
|
|
9763
10036
|
const lineSpacing = elem.lineSpacing ?? style?.paragraphProps?.lineSpacing;
|
|
10037
|
+
const exact = lineSpacing?.lineRule == "exact" || lineSpacing?.lineRule == "exactly";
|
|
10038
|
+
if (!exact && !this.compatibleTextBoxSpacing && result.dataset
|
|
10039
|
+
&& ["lines", "linesAndChars"].includes(this.currentSectionProps.docGrid.type)) {
|
|
10040
|
+
const numeric = /^\d+(?:\.\d+)?$/.test(lineHeight ?? "") ? Number(lineHeight) : 1;
|
|
10041
|
+
if (numeric >= 1) {
|
|
10042
|
+
result.dataset.docxParagraphGridPitch = linePitch;
|
|
10043
|
+
result.dataset.docxParagraphGridMultiple = `${numeric}`;
|
|
10044
|
+
result.dataset.docxParagraphGridAtLeast = `${lineSpacing?.lineRule == "atLeast"}`;
|
|
10045
|
+
}
|
|
10046
|
+
}
|
|
9764
10047
|
if (lineHeight) {
|
|
9765
|
-
if (
|
|
10048
|
+
if (exact)
|
|
9766
10049
|
return;
|
|
9767
|
-
const comparableLineHeight =
|
|
9768
|
-
? `calc(${lineHeight} * 1em)`
|
|
9769
|
-
: lineHeight;
|
|
10050
|
+
const comparableLineHeight = gridAutomaticLineHeight(lineHeight, linePitch);
|
|
9770
10051
|
this.preserveGridInlineMetrics(result);
|
|
9771
10052
|
this.setCssStyle(result, "line-height", `max(${comparableLineHeight}, ${linePitch})`);
|
|
9772
10053
|
this.applyDocumentGridMinimumHeight(elem, style, result, linePitch);
|
|
9773
10054
|
return;
|
|
9774
10055
|
}
|
|
10056
|
+
this.preserveGridInlineMetrics(result);
|
|
10057
|
+
this.setCssStyle(result, "line-height", linePitch);
|
|
9775
10058
|
this.applyDocumentGridMinimumHeight(elem, style, result, linePitch);
|
|
9776
10059
|
}
|
|
9777
10060
|
preserveGridInlineMetrics(result) {
|
|
@@ -9953,6 +10236,11 @@
|
|
|
9953
10236
|
movedAny = true;
|
|
9954
10237
|
continue;
|
|
9955
10238
|
}
|
|
10239
|
+
const tail = article.lastElementChild;
|
|
10240
|
+
if (this.canRetainTablePrefix(tail, page) && this.splitOverflowBlock(tail, page, nextArticle)) {
|
|
10241
|
+
movedAny = true;
|
|
10242
|
+
continue;
|
|
10243
|
+
}
|
|
9956
10244
|
let chunk = this.pickPaginationChunk(article);
|
|
9957
10245
|
if (chunk.length == 0)
|
|
9958
10246
|
break;
|
|
@@ -10832,21 +11120,30 @@
|
|
|
10832
11120
|
const rows = this.tableContentRows(table);
|
|
10833
11121
|
if (rows.length <= 1)
|
|
10834
11122
|
return false;
|
|
11123
|
+
const repeatHeaders = rows.filter(r => r.dataset.docxRepeatHeader == "true");
|
|
11124
|
+
if (repeatHeaders.length && !this.fitsTableRowPrefix(rows, page))
|
|
11125
|
+
return false;
|
|
10835
11126
|
const clone = this.cloneBlockShell(table);
|
|
10836
11127
|
clone.dataset.docxContinued = "true";
|
|
10837
11128
|
for (const child of Array.from(table.children)) {
|
|
10838
11129
|
if (child.tagName?.toLowerCase() == "colgroup")
|
|
10839
11130
|
clone.appendChild(child.cloneNode(true));
|
|
10840
11131
|
}
|
|
10841
|
-
for (const header of
|
|
11132
|
+
for (const [index, header] of repeatHeaders.entries()) {
|
|
10842
11133
|
const repeated = header.cloneNode(true);
|
|
10843
11134
|
repeated.dataset.docxRepeatedHeader = "true";
|
|
11135
|
+
for (const cell of Array.from(repeated.cells)) {
|
|
11136
|
+
const headerRowsRemaining = repeatHeaders.length - index;
|
|
11137
|
+
if (cell.rowSpan === 0 || cell.rowSpan > headerRowsRemaining)
|
|
11138
|
+
cell.rowSpan = headerRowsRemaining;
|
|
11139
|
+
}
|
|
10844
11140
|
clone.appendChild(repeated);
|
|
10845
11141
|
}
|
|
10846
11142
|
nextArticle.prepend(clone);
|
|
10847
11143
|
let movedAny = false;
|
|
10848
11144
|
let guard = 0;
|
|
10849
|
-
|
|
11145
|
+
const minimumSourceRows = repeatHeaders.length + 1;
|
|
11146
|
+
while (this.isPageOverflowing(page) && this.tableContentRows(table).length > minimumSourceRows && guard++ < 500) {
|
|
10850
11147
|
const currentRows = this.tableContentRows(table).filter(r => r.dataset.docxRepeatedHeader != "true");
|
|
10851
11148
|
const last = currentRows[currentRows.length - 1];
|
|
10852
11149
|
if (!last)
|
|
@@ -10858,8 +11155,58 @@
|
|
|
10858
11155
|
clone.remove();
|
|
10859
11156
|
return false;
|
|
10860
11157
|
}
|
|
11158
|
+
const sourceRowCount = this.tableContentRows(table).length;
|
|
11159
|
+
const firstContinuationRow = this.firstMovedTableRow(clone);
|
|
11160
|
+
for (let rowIndex = 0; rowIndex < sourceRowCount; rowIndex++) {
|
|
11161
|
+
let column = 0;
|
|
11162
|
+
for (const cell of Array.from(rows[rowIndex].cells)) {
|
|
11163
|
+
const nextColumn = column + cell.colSpan;
|
|
11164
|
+
const remainingSpan = rowIndex + cell.rowSpan - sourceRowCount;
|
|
11165
|
+
if (remainingSpan > 0) {
|
|
11166
|
+
const continuation = this.cloneBlockShell(cell);
|
|
11167
|
+
continuation.textContent = "";
|
|
11168
|
+
continuation.rowSpan = remainingSpan;
|
|
11169
|
+
continuation.dataset.docxContinued = "true";
|
|
11170
|
+
let targetColumn = 0;
|
|
11171
|
+
let anchor = null;
|
|
11172
|
+
for (const targetCell of Array.from(firstContinuationRow.cells)) {
|
|
11173
|
+
if (targetColumn >= column) {
|
|
11174
|
+
anchor = targetCell;
|
|
11175
|
+
break;
|
|
11176
|
+
}
|
|
11177
|
+
targetColumn += targetCell.colSpan;
|
|
11178
|
+
}
|
|
11179
|
+
if (anchor && targetColumn === column && anchor.style.display === "none")
|
|
11180
|
+
anchor.replaceWith(continuation);
|
|
11181
|
+
else
|
|
11182
|
+
firstContinuationRow.insertBefore(continuation, anchor);
|
|
11183
|
+
cell.rowSpan = sourceRowCount - rowIndex;
|
|
11184
|
+
}
|
|
11185
|
+
column = nextColumn;
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
10861
11188
|
return true;
|
|
10862
11189
|
}
|
|
11190
|
+
canRetainTablePrefix(block, page) {
|
|
11191
|
+
if (block?.localName !== "table")
|
|
11192
|
+
return false;
|
|
11193
|
+
const style = getComputedStyle(block);
|
|
11194
|
+
if (style.position !== "static" || style.cssFloat !== "none" || block.dataset.docxFloat)
|
|
11195
|
+
return false;
|
|
11196
|
+
return this.fitsTableRowPrefix(this.tableContentRows(block), page);
|
|
11197
|
+
}
|
|
11198
|
+
fitsTableRowPrefix(rows, page) {
|
|
11199
|
+
if (rows.length < 2 || rows.some((row, index) => Array.from(row.cells).some(cell => cell.rowSpan < 1 || index + cell.rowSpan > rows.length)))
|
|
11200
|
+
return false;
|
|
11201
|
+
const firstBody = rows.findIndex(row => row.dataset.docxRepeatHeader != "true");
|
|
11202
|
+
if (firstBody < 0 || rows.slice(firstBody + 1).some(row => row.dataset.docxRepeatHeader == "true"))
|
|
11203
|
+
return false;
|
|
11204
|
+
const bottom = this.getPageBodyBottom(page) + (this.options.paginationTolerance ?? 2);
|
|
11205
|
+
return rows.slice(0, firstBody + 1).every(row => {
|
|
11206
|
+
const rect = row.getBoundingClientRect();
|
|
11207
|
+
return rect.height > 0 && rect.bottom <= bottom;
|
|
11208
|
+
});
|
|
11209
|
+
}
|
|
10863
11210
|
cloneBlockShell(element) {
|
|
10864
11211
|
const clone = element.cloneNode(false);
|
|
10865
11212
|
clone.removeAttribute("id");
|
|
@@ -11140,7 +11487,7 @@
|
|
|
11140
11487
|
wrapperStyle = `@media not print { ${wrapperStyle} }`;
|
|
11141
11488
|
}
|
|
11142
11489
|
var styleText = `${wrapperStyle}
|
|
11143
|
-
.${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; }
|
|
11490
|
+
.${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; }
|
|
11144
11491
|
section.${c} { box-sizing: border-box; display: flex; flex-flow: column nowrap; position: relative; overflow: visible; isolation: isolate; }
|
|
11145
11492
|
section.${c}>header, section.${c}>footer { flex-shrink: 0; }
|
|
11146
11493
|
section.${c}>[data-docx-note-list] { flex-shrink: 0; }
|
|
@@ -11531,6 +11878,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11531
11878
|
}
|
|
11532
11879
|
const children = frameParagraphs
|
|
11533
11880
|
.flatMap(item => asArray(this.renderElement(item)).filter(node => node != null));
|
|
11881
|
+
this.applyFlowParagraphSpacing(children);
|
|
11534
11882
|
const frame = this.h({
|
|
11535
11883
|
tagName: "div",
|
|
11536
11884
|
className: `${this.className}-paragraph-frame`,
|
|
@@ -11550,6 +11898,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11550
11898
|
}
|
|
11551
11899
|
result.push(...asArray(this.renderElement(elems[i])).filter(e => e != null));
|
|
11552
11900
|
}
|
|
11901
|
+
this.applyFlowParagraphSpacing(result);
|
|
11553
11902
|
if (into)
|
|
11554
11903
|
result.forEach(c => into.appendChild(isString(c) ? document.createTextNode(c) : c));
|
|
11555
11904
|
return result;
|
|
@@ -11749,7 +12098,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11749
12098
|
const style = this.findStyle(this.currentParagraph?.styleName);
|
|
11750
12099
|
const isTocParagraph = this.isTocParagraphStyle(this.currentParagraph?.styleName, style);
|
|
11751
12100
|
const isNumberedTocLeader = !!trailingLeader
|
|
11752
|
-
&& !!(this.currentParagraph
|
|
12101
|
+
&& !!this.effectiveParagraphNumbering(this.currentParagraph, style)
|
|
11753
12102
|
&& isTocParagraph;
|
|
11754
12103
|
if (!trailingLeader)
|
|
11755
12104
|
return stop;
|
|
@@ -11793,18 +12142,22 @@ section.${c}>footer { z-index: 1; }
|
|
|
11793
12142
|
children = [flow];
|
|
11794
12143
|
}
|
|
11795
12144
|
var result = this.toHTML(elem, ns.html, "p", this.wrapTabLeaderChildren(children, true));
|
|
12145
|
+
this.applyParagraphAutoSpacing(elem, style, result);
|
|
11796
12146
|
this.applyTextBoxFontInheritance(elem, style, result);
|
|
12147
|
+
this.applyRunFontSlots(elem, style, result);
|
|
11797
12148
|
if (this.options.exposeDisplayTargets && elem.displayAddress) {
|
|
11798
12149
|
const part = this.currentPart ?? this.document.documentPart;
|
|
11799
12150
|
result.setAttribute("data-office-target", `${part.path}#${elem.displayAddress}`);
|
|
11800
12151
|
}
|
|
11801
|
-
const snapToGrid = this.
|
|
12152
|
+
const snapToGrid = this.paragraphSnapToGrid(elem, style);
|
|
11802
12153
|
if (/^(0|false|off)$/i.test(snapToGrid ?? ""))
|
|
11803
12154
|
result.style.letterSpacing = "normal";
|
|
11804
12155
|
this.currentParagraph = previousParagraph;
|
|
11805
12156
|
this.currentParagraphTabIndex = previousParagraphTabIndex;
|
|
11806
12157
|
this.currentParagraphTabCount = previousParagraphTabCount;
|
|
11807
|
-
const numbering = elem.
|
|
12158
|
+
const numbering = elem.props?.pageBreakContinuation ? null : this.effectiveParagraphNumbering(elem, style);
|
|
12159
|
+
if (elem.props?.pageBreakEmpty)
|
|
12160
|
+
result.style.display = "none";
|
|
11808
12161
|
if (numbering) {
|
|
11809
12162
|
result.classList.add(this.numberingClass(numbering.id, numbering.level));
|
|
11810
12163
|
}
|
|
@@ -11860,7 +12213,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
11860
12213
|
return result;
|
|
11861
12214
|
}
|
|
11862
12215
|
uniformParagraphTextScale(paragraph, style) {
|
|
11863
|
-
if (paragraph
|
|
12216
|
+
if (this.effectiveParagraphNumbering(paragraph, style) || paragraph.frame
|
|
11864
12217
|
|| this.effectiveParagraphCssValue(paragraph, style, "writing-mode"))
|
|
11865
12218
|
return null;
|
|
11866
12219
|
const key = "--docx-text-scale";
|
|
@@ -12015,6 +12368,68 @@ section.${c}>footer { z-index: 1; }
|
|
|
12015
12368
|
probe.remove();
|
|
12016
12369
|
}
|
|
12017
12370
|
}
|
|
12371
|
+
refreshParagraphLineGrid(root) {
|
|
12372
|
+
const view = root.ownerDocument?.defaultView;
|
|
12373
|
+
const paragraphs = Array.from(root.querySelectorAll("[data-docx-paragraph-grid-pitch]"))
|
|
12374
|
+
.filter(paragraph => this.ownsLayoutElement(paragraph));
|
|
12375
|
+
if (!view || !paragraphs.length)
|
|
12376
|
+
return;
|
|
12377
|
+
const probe = root.ownerDocument.createElement("span");
|
|
12378
|
+
Object.assign(probe.style, { position: "absolute", visibility: "hidden", pointerEvents: "none",
|
|
12379
|
+
display: "inline-block", whiteSpace: "pre", width: "max-content", margin: "0", padding: "0", border: "0" });
|
|
12380
|
+
probe.setAttribute("aria-hidden", "true");
|
|
12381
|
+
probe.textContent = "Mg";
|
|
12382
|
+
const scope = root.getRootNode();
|
|
12383
|
+
(scope.nodeType == 11 && "host" in scope ? scope : root.ownerDocument.body).appendChild(probe);
|
|
12384
|
+
const cache = new Map();
|
|
12385
|
+
const natural = (style) => {
|
|
12386
|
+
const font = { fontFamily: style.fontFamily, fontSize: style.fontSize, fontWeight: style.fontWeight,
|
|
12387
|
+
fontStyle: style.fontStyle, fontStretch: style.fontStretch, lineHeight: "normal", height: "auto" };
|
|
12388
|
+
const key = JSON.stringify(font);
|
|
12389
|
+
if (!cache.has(key)) {
|
|
12390
|
+
Object.assign(probe.style, font);
|
|
12391
|
+
cache.set(key, probe.getBoundingClientRect().height);
|
|
12392
|
+
}
|
|
12393
|
+
return cache.get(key);
|
|
12394
|
+
};
|
|
12395
|
+
try {
|
|
12396
|
+
for (const paragraph of paragraphs) {
|
|
12397
|
+
const style = view.getComputedStyle(paragraph), size = parseFloat(style.fontSize);
|
|
12398
|
+
probe.style.height = paragraph.dataset.docxParagraphGridPitch;
|
|
12399
|
+
const pitch = parseFloat(view.getComputedStyle(probe).height);
|
|
12400
|
+
const multiplier = Number(paragraph.dataset.docxParagraphGridMultiple);
|
|
12401
|
+
let height = gridFontLineHeight(natural(style), pitch, multiplier);
|
|
12402
|
+
if (height == null)
|
|
12403
|
+
continue;
|
|
12404
|
+
if (paragraph.dataset.docxParagraphGridAtLeast === "true")
|
|
12405
|
+
height = Math.max(height, parseFloat(style.lineHeight) || 0);
|
|
12406
|
+
paragraph.style.lineHeight = `${height}px`;
|
|
12407
|
+
const visit = (parent, script = false) => {
|
|
12408
|
+
for (const child of Array.from(parent.children)) {
|
|
12409
|
+
if (child.namespaceURI !== ns.html || !/^(span|a|sub|sup|b|i|u|s|strike|strong|em)$/.test(child.localName))
|
|
12410
|
+
continue;
|
|
12411
|
+
const own = child.dataset.docxGridOwnedHeight === "true";
|
|
12412
|
+
if ((!own && child.style.lineHeight && child.style.lineHeight !== "normal")
|
|
12413
|
+
|| (child.style.display && child.style.display !== "inline" && !child.dataset.docxTextScale)
|
|
12414
|
+
|| /^(absolute|fixed)$/.test(child.style.position) || (child.style.cssFloat && child.style.cssFloat !== "none"))
|
|
12415
|
+
continue;
|
|
12416
|
+
const childStyle = view.getComputedStyle(child);
|
|
12417
|
+
const raised = script || /^(super|sub)$/.test(childStyle.verticalAlign);
|
|
12418
|
+
const breakOnly = !child.textContent && !!child.querySelector("br") && !child.querySelector("img,svg,math");
|
|
12419
|
+
const childHeight = breakOnly || (raised && parseFloat(childStyle.fontSize) <= size) ? 0
|
|
12420
|
+
: Math.max(height, gridFontLineHeight(natural(childStyle), pitch) ?? height);
|
|
12421
|
+
child.style.lineHeight = `${childHeight}px`;
|
|
12422
|
+
child.dataset.docxGridOwnedHeight = "true";
|
|
12423
|
+
visit(child, raised);
|
|
12424
|
+
}
|
|
12425
|
+
};
|
|
12426
|
+
visit(paragraph);
|
|
12427
|
+
}
|
|
12428
|
+
}
|
|
12429
|
+
finally {
|
|
12430
|
+
probe.remove();
|
|
12431
|
+
}
|
|
12432
|
+
}
|
|
12018
12433
|
async prepareLayout(root, generation = getLayoutGeneration(root)) {
|
|
12019
12434
|
if (!root.isConnected || !generation.isCurrent())
|
|
12020
12435
|
return;
|
|
@@ -12035,6 +12450,7 @@ section.${c}>footer { z-index: 1; }
|
|
|
12035
12450
|
(owner ?? root).appendChild(this.commentLayer.root);
|
|
12036
12451
|
}
|
|
12037
12452
|
}
|
|
12453
|
+
this.refreshParagraphLineGrid(root);
|
|
12038
12454
|
this.refreshTextBoxLineGrid(root);
|
|
12039
12455
|
this.refreshTabStops(root);
|
|
12040
12456
|
this.refreshAnchors(root);
|
|
@@ -13977,7 +14393,14 @@ section.${c}>footer { z-index: 1; }
|
|
|
13977
14393
|
return false;
|
|
13978
14394
|
}
|
|
13979
14395
|
renderText(elem) {
|
|
13980
|
-
|
|
14396
|
+
const text = this.applyCjkLineBreakGuards(elem.text);
|
|
14397
|
+
if (!this.currentRunFont?.splitEastAsia)
|
|
14398
|
+
return this.h(text);
|
|
14399
|
+
const fragments = fontScriptRuns(text, this.currentRunFont.previousEastAsian);
|
|
14400
|
+
this.currentRunFont.previousEastAsian = fragments[fragments.length - 1]?.eastAsian ?? this.currentRunFont.previousEastAsian;
|
|
14401
|
+
return this.h({ tagName: "#fragment", children: fragments.map(run => run.eastAsian
|
|
14402
|
+
? this.h({ tagName: "span", className: `${this.className}-font-eastasia`, style: { fontFamily: this.currentRunFont.eastAsianFontFamily }, children: [run.text] })
|
|
14403
|
+
: this.h(run.text)) });
|
|
13981
14404
|
}
|
|
13982
14405
|
applyCjkLineBreakGuards(text) {
|
|
13983
14406
|
if (!text || !this.document.settingsPart?.settings?.kinsoku)
|
|
@@ -14159,7 +14582,17 @@ section.${c}>footer { z-index: 1; }
|
|
|
14159
14582
|
: elem.children;
|
|
14160
14583
|
if (elem.fieldRun && (!runChildren || runChildren.length == 0))
|
|
14161
14584
|
return null;
|
|
14162
|
-
|
|
14585
|
+
const previousFont = this.currentRunFont;
|
|
14586
|
+
const style = this.findStyle(elem.styleName);
|
|
14587
|
+
const font = this.resolveRunFontSlots(elem, style);
|
|
14588
|
+
this.currentRunFont = font;
|
|
14589
|
+
let children;
|
|
14590
|
+
try {
|
|
14591
|
+
children = this.renderElements(runChildren);
|
|
14592
|
+
}
|
|
14593
|
+
finally {
|
|
14594
|
+
this.currentRunFont = previousFont;
|
|
14595
|
+
}
|
|
14163
14596
|
if (elem.verticalAlign) {
|
|
14164
14597
|
children = [this.h({ tagName: elem.verticalAlign, children })];
|
|
14165
14598
|
}
|
|
@@ -14176,8 +14609,8 @@ section.${c}>footer { z-index: 1; }
|
|
|
14176
14609
|
return tab;
|
|
14177
14610
|
}
|
|
14178
14611
|
const result = this.toHTML(elem, ns.html, "span", children);
|
|
14179
|
-
const style = this.findStyle(elem.styleName);
|
|
14180
14612
|
this.applyTextBoxFontInheritance(elem, style, result);
|
|
14613
|
+
this.applyRunFontSlots(elem, style, result, font);
|
|
14181
14614
|
const snapToGrid = elem.cssStyle?.["--docx-snap-to-grid"] ?? this.styleValue(style, "span", "--docx-snap-to-grid");
|
|
14182
14615
|
if (/^(0|false|off)$/i.test(snapToGrid ?? ""))
|
|
14183
14616
|
result.style.letterSpacing = "normal";
|