office-viewer 0.1.0 → 0.1.3
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 +7 -2
- package/esm/OpenXML.d.ts +19 -0
- package/esm/OpenXML.js +43 -2
- package/esm/Word.d.ts +132 -15
- package/esm/Word.js +233 -54
- package/esm/openxml/ContentType.js +20 -6
- package/esm/openxml/Settings.d.ts +10 -0
- package/esm/openxml/Settings.js +93 -0
- package/esm/openxml/Style.d.ts +1 -1
- package/esm/openxml/Style.js +12 -12
- package/esm/openxml/Theme.js +30 -6
- package/esm/openxml/Types.d.ts +179 -2472
- package/esm/openxml/drawing/Blip.d.ts +7 -0
- package/esm/openxml/{word/drawing → drawing}/Blip.js +2 -1
- package/{lib/openxml/word → esm/openxml}/drawing/BlipFill.d.ts +1 -1
- package/esm/openxml/{word/drawing → drawing}/BlipFill.js +1 -1
- package/esm/openxml/drawing/CustomGeom.d.ts +9 -0
- package/esm/openxml/drawing/CustomGeom.js +17 -0
- package/esm/openxml/drawing/Drawing.d.ts +35 -0
- package/esm/openxml/drawing/Drawing.js +169 -0
- package/esm/openxml/drawing/Geom.d.ts +11 -0
- package/esm/openxml/drawing/Geom.js +34 -0
- package/esm/openxml/drawing/Path.d.ts +37 -0
- package/esm/openxml/drawing/Pic.d.ts +16 -0
- package/esm/openxml/drawing/Pic.js +26 -0
- package/esm/openxml/drawing/Shape.d.ts +20 -0
- package/esm/openxml/drawing/ShapeProperties.d.ts +22 -0
- package/esm/openxml/drawing/ShapeProperties.js +119 -0
- package/{lib/openxml/word → esm/openxml}/drawing/Transform.d.ts +2 -1
- package/esm/openxml/{word/drawing → drawing}/Transform.js +7 -3
- package/esm/openxml/drawing/diagram/Diagram.d.ts +7 -0
- package/esm/openxml/drawing/diagram/Diagram.js +24 -0
- package/esm/openxml/drawing/diagram/Sp.d.ts +2 -0
- package/esm/openxml/drawing/diagram/SpTree.d.ts +5 -0
- package/esm/openxml/drawing/presetShape.d.ts +3 -0
- package/esm/openxml/drawing/presetShape.js +38785 -0
- package/esm/openxml/drawing/svg/arcToA.d.ts +13 -0
- package/esm/openxml/drawing/svg/arcToA.js +88 -0
- package/esm/openxml/drawing/svg/formulas.d.ts +29 -0
- package/esm/openxml/drawing/svg/formulas.js +103 -0
- package/esm/openxml/drawing/svg/generateDefines.d.ts +12 -0
- package/esm/openxml/drawing/svg/generateDefines.js +144 -0
- package/esm/openxml/drawing/svg/presetVal.d.ts +43 -0
- package/esm/openxml/drawing/svg/presetVal.js +53 -0
- package/esm/openxml/drawing/svg/shapeToSVG.d.ts +9 -0
- package/esm/openxml/drawing/svg/shapeToSVG.js +151 -0
- package/esm/openxml/math/OMath.d.ts +5 -0
- package/esm/openxml/math/OMath.js +12 -0
- package/esm/openxml/math/convertOOML.d.ts +4 -0
- package/esm/openxml/math/convertOOML.js +13 -0
- package/esm/openxml/math/xsl.d.ts +4 -0
- package/esm/openxml/math/xsl.js +8 -0
- package/esm/openxml/word/Body.js +11 -7
- package/esm/openxml/word/Break.js +1 -3
- package/esm/openxml/word/Font.d.ts +16 -0
- package/esm/openxml/word/Font.js +78 -0
- package/esm/openxml/word/FontTable.d.ts +9 -0
- package/esm/openxml/word/FontTable.js +34 -0
- package/esm/openxml/word/Header.d.ts +11 -0
- package/esm/openxml/word/Header.js +54 -0
- package/esm/openxml/word/Hyperlink.d.ts +1 -0
- package/esm/openxml/word/Hyperlink.js +7 -3
- package/esm/openxml/word/InlineText.js +1 -1
- package/esm/openxml/word/NoBreakHyphen.d.ts +2 -0
- package/esm/openxml/word/NoBreakHyphen.js +7 -0
- package/esm/openxml/word/Note.d.ts +12 -0
- package/esm/openxml/word/Note.js +48 -0
- package/esm/openxml/word/Paragraph.d.ts +2 -2
- package/esm/openxml/word/Paragraph.js +10 -9
- package/esm/openxml/word/Pict.d.ts +1 -2
- package/esm/openxml/word/Pict.js +5 -3
- package/esm/openxml/word/Ruby.js +1 -1
- package/esm/openxml/word/Run.d.ts +7 -3
- package/esm/openxml/word/Run.js +28 -4
- package/esm/openxml/word/Section.d.ts +18 -5
- package/esm/openxml/word/Section.js +46 -2
- package/esm/openxml/word/Separator.d.ts +5 -0
- package/esm/openxml/word/Separator.js +10 -0
- package/esm/openxml/word/SoftHyphen.d.ts +5 -0
- package/esm/openxml/word/SoftHyphen.js +10 -0
- package/esm/openxml/word/Table.d.ts +4 -9
- package/esm/openxml/word/Table.js +0 -235
- package/esm/openxml/word/WDocument.d.ts +1 -2
- package/esm/openxml/word/WDocument.js +53 -7
- package/esm/openxml/word/numbering/AbstractNum.js +4 -2
- package/esm/openxml/word/numbering/Lvl.js +10 -4
- package/esm/openxml/word/numbering/Num.js +12 -4
- package/esm/openxml/word/numbering/NumberProperties.js +2 -2
- package/esm/openxml/word/numbering/Numbering.js +1 -1
- package/esm/openxml/word/table/Tc.d.ts +1 -22
- package/esm/openxml/word/table/Tc.js +1 -221
- package/esm/openxml/word/table/Tr.d.ts +0 -5
- package/esm/openxml/word/table/Tr.js +0 -97
- package/esm/openxml/word/wps/WPG.d.ts +5 -0
- package/esm/openxml/word/wps/WPS.d.ts +18 -0
- package/esm/openxml/word/wps/WPS.js +147 -0
- package/esm/openxml/word/wps/WPSStyle.d.ts +10 -0
- package/esm/openxml/word/wps/WPSStyle.js +42 -0
- package/esm/package/PackageParser.d.ts +1 -1
- package/esm/package/XMLPackageParser.d.ts +3 -3
- package/esm/package/ZipPackageParser.d.ts +1 -1
- package/esm/package/ZipPackageParser.js +7 -8
- package/esm/parse/Footnotes.d.ts +3 -0
- package/esm/parse/Footnotes.js +25 -0
- package/esm/parse/colorNameMap.d.ts +6 -0
- package/esm/parse/colorNameMap.js +201 -0
- package/esm/parse/jcToTextAlign.js +1 -0
- package/esm/parse/mergeSdt.d.ts +4 -0
- package/esm/parse/mergeSdt.js +57 -0
- package/esm/parse/modifyColor.d.ts +1 -0
- package/esm/parse/modifyColor.js +106 -0
- package/esm/parse/parseBorder.js +2 -21
- package/esm/parse/parseCellMargin.d.ts +2 -0
- package/esm/parse/parseCellMargin.js +38 -0
- package/esm/parse/parseChildColor.d.ts +5 -0
- package/esm/parse/parseChildColor.js +66 -0
- package/esm/parse/parseColor.d.ts +4 -0
- package/esm/parse/parseColor.js +41 -46
- package/esm/parse/parseEndnotes.d.ts +3 -0
- package/esm/parse/parseEndnotes.js +25 -0
- package/esm/parse/parseFont.js +1 -1
- package/esm/parse/parseInsideBorders.d.ts +9 -0
- package/esm/parse/parseInsideBorders.js +24 -0
- package/esm/parse/parsePr.d.ts +3 -0
- package/esm/parse/parsePr.js +108 -11
- package/esm/parse/parseRelationship.js +1 -1
- package/esm/parse/parseSdt.d.ts +5 -0
- package/esm/parse/parseShape.d.ts +10 -0
- package/esm/parse/parseShape.js +239 -0
- package/esm/parse/parseSize.d.ts +2 -1
- package/esm/parse/parseSize.js +7 -1
- package/esm/parse/parseSpacing.js +1 -1
- package/esm/parse/parseTable.d.ts +3 -0
- package/esm/parse/parseTable.js +62 -0
- package/esm/parse/parseTablePr.d.ts +3 -0
- package/esm/parse/parseTablePr.js +185 -0
- package/esm/parse/parseTblWidth.d.ts +4 -0
- package/esm/parse/parseTblWidth.js +23 -0
- package/esm/parse/parseTc.d.ts +10 -0
- package/esm/parse/parseTc.js +64 -0
- package/esm/parse/parseTcPr.d.ts +5 -0
- package/esm/parse/parseTcPr.js +99 -0
- package/esm/parse/parseTextDirection.js +4 -6
- package/esm/parse/parseTr.d.ts +6 -0
- package/esm/parse/parseTr.js +49 -0
- package/esm/parse/parseTrPr.d.ts +3 -0
- package/esm/parse/parseTrPr.js +59 -0
- package/esm/render/fixAbsolutePosition.d.ts +8 -0
- package/esm/render/renderBody.d.ts +6 -2
- package/esm/render/renderBody.js +184 -30
- package/esm/render/renderBr.d.ts +2 -1
- package/esm/render/renderBr.js +4 -1
- package/esm/render/renderCustGeom.d.ts +4 -0
- package/esm/render/renderCustGeom.js +10 -0
- package/esm/render/renderDocument.d.ts +2 -2
- package/esm/render/renderDocument.js +2 -2
- package/esm/render/renderDrawing.d.ts +3 -2
- package/esm/render/renderDrawing.js +129 -24
- package/esm/render/renderFont.d.ts +5 -0
- package/esm/render/renderFont.js +39 -0
- package/esm/render/renderGeom.d.ts +4 -0
- package/esm/render/renderGeom.js +14 -0
- package/esm/render/renderHeader.d.ts +6 -0
- package/esm/render/renderHeader.js +40 -0
- package/esm/render/renderHyperLink.js +4 -1
- package/esm/render/renderInlineText.js +1 -1
- package/esm/render/renderInstrText.js +1 -1
- package/esm/render/renderMath.d.ts +3 -0
- package/esm/render/renderMath.js +7 -0
- package/esm/render/renderNoBreakHyphen.d.ts +1 -0
- package/esm/render/renderNoBreakHyphen.js +9 -0
- package/esm/render/renderNotes.d.ts +5 -0
- package/esm/render/renderNotes.js +77 -0
- package/esm/render/renderNumbering.js +8 -10
- package/esm/render/renderParagraph.d.ts +1 -1
- package/esm/render/renderParagraph.js +26 -29
- package/esm/render/renderPict.js +5 -10
- package/esm/render/renderRuby.js +1 -1
- package/esm/render/renderRun.d.ts +4 -2
- package/esm/render/renderRun.js +35 -10
- package/esm/render/renderSection.d.ts +3 -2
- package/esm/render/renderSection.js +79 -5
- package/esm/render/renderSeparator.d.ts +1 -0
- package/esm/render/renderSeparator.js +9 -0
- package/esm/render/renderSoftHyphen.d.ts +1 -0
- package/esm/render/renderSoftHyphen.js +9 -0
- package/esm/render/renderStyle.js +36 -35
- package/esm/render/renderTab.d.ts +1 -0
- package/esm/render/renderTab.js +4 -6
- package/esm/render/renderTable.js +23 -20
- package/esm/render/setElementStyle.js +7 -2
- package/esm/render/zindex.d.ts +1 -0
- package/esm/util/blob.js +1 -10
- package/esm/util/color.d.ts +48 -0
- package/esm/util/color.js +211 -0
- package/esm/util/createObject.d.ts +10 -0
- package/esm/util/createObject.js +48 -0
- package/esm/util/dom.d.ts +8 -4
- package/esm/util/dom.js +21 -4
- package/esm/util/mergeRun.js +1 -1
- package/esm/util/parseSides.d.ts +11 -0
- package/esm/util/print.d.ts +5 -0
- package/esm/util/print.js +54 -0
- package/esm/util/replaceVar.d.ts +10 -0
- package/esm/util/replaceVar.js +214 -0
- package/esm/util/xml.js +4 -1
- package/lib/OpenXML.d.ts +19 -0
- package/lib/OpenXML.js +44 -1
- package/lib/Word.d.ts +132 -15
- package/lib/Word.js +238 -59
- package/lib/openxml/ContentType.js +20 -6
- package/lib/openxml/Settings.d.ts +10 -0
- package/lib/openxml/Settings.js +97 -0
- package/lib/openxml/Style.d.ts +1 -1
- package/lib/openxml/Style.js +15 -15
- package/lib/openxml/Theme.js +31 -7
- package/lib/openxml/Types.d.ts +179 -2472
- package/lib/openxml/drawing/Blip.d.ts +7 -0
- package/lib/openxml/{word/drawing → drawing}/Blip.js +2 -1
- package/{esm/openxml/word → lib/openxml}/drawing/BlipFill.d.ts +1 -1
- package/lib/openxml/{word/drawing → drawing}/BlipFill.js +1 -1
- package/lib/openxml/drawing/CustomGeom.d.ts +9 -0
- package/lib/openxml/drawing/CustomGeom.js +21 -0
- package/lib/openxml/drawing/Drawing.d.ts +35 -0
- package/lib/openxml/drawing/Drawing.js +173 -0
- package/lib/openxml/drawing/Geom.d.ts +11 -0
- package/lib/openxml/drawing/Geom.js +38 -0
- package/lib/openxml/drawing/Path.d.ts +37 -0
- package/lib/openxml/drawing/Pic.d.ts +16 -0
- package/lib/openxml/drawing/Pic.js +30 -0
- package/lib/openxml/drawing/Shape.d.ts +20 -0
- package/lib/openxml/drawing/ShapeProperties.d.ts +22 -0
- package/lib/openxml/drawing/ShapeProperties.js +123 -0
- package/{esm/openxml/word → lib/openxml}/drawing/Transform.d.ts +2 -1
- package/lib/openxml/{word/drawing → drawing}/Transform.js +7 -3
- package/lib/openxml/drawing/diagram/Diagram.d.ts +7 -0
- package/lib/openxml/drawing/diagram/Diagram.js +28 -0
- package/lib/openxml/drawing/diagram/Sp.d.ts +2 -0
- package/lib/openxml/drawing/diagram/SpTree.d.ts +5 -0
- package/lib/openxml/drawing/presetShape.d.ts +3 -0
- package/lib/openxml/drawing/presetShape.js +38789 -0
- package/lib/openxml/drawing/svg/arcToA.d.ts +13 -0
- package/lib/openxml/drawing/svg/arcToA.js +92 -0
- package/lib/openxml/drawing/svg/formulas.d.ts +29 -0
- package/lib/openxml/drawing/svg/formulas.js +108 -0
- package/lib/openxml/drawing/svg/generateDefines.d.ts +12 -0
- package/lib/openxml/drawing/svg/generateDefines.js +148 -0
- package/lib/openxml/drawing/svg/presetVal.d.ts +43 -0
- package/lib/openxml/drawing/svg/presetVal.js +57 -0
- package/lib/openxml/drawing/svg/shapeToSVG.d.ts +9 -0
- package/lib/openxml/drawing/svg/shapeToSVG.js +155 -0
- package/lib/openxml/math/OMath.d.ts +5 -0
- package/lib/openxml/math/OMath.js +16 -0
- package/lib/openxml/math/convertOOML.d.ts +4 -0
- package/lib/openxml/math/convertOOML.js +17 -0
- package/lib/openxml/math/xsl.d.ts +4 -0
- package/lib/openxml/math/xsl.js +12 -0
- package/lib/openxml/word/Body.js +11 -7
- package/lib/openxml/word/Break.js +1 -3
- package/lib/openxml/word/Font.d.ts +16 -0
- package/lib/openxml/word/Font.js +83 -0
- package/lib/openxml/word/FontTable.d.ts +9 -0
- package/lib/openxml/word/FontTable.js +38 -0
- package/lib/openxml/word/Header.d.ts +11 -0
- package/lib/openxml/word/Header.js +58 -0
- package/lib/openxml/word/Hyperlink.d.ts +1 -0
- package/lib/openxml/word/Hyperlink.js +8 -4
- package/lib/openxml/word/InlineText.js +2 -2
- package/lib/openxml/word/NoBreakHyphen.d.ts +2 -0
- package/lib/openxml/word/NoBreakHyphen.js +11 -0
- package/lib/openxml/word/Note.d.ts +12 -0
- package/lib/openxml/word/Note.js +52 -0
- package/lib/openxml/word/Paragraph.d.ts +2 -2
- package/lib/openxml/word/Paragraph.js +11 -10
- package/lib/openxml/word/Pict.d.ts +1 -2
- package/lib/openxml/word/Pict.js +5 -3
- package/lib/openxml/word/Ruby.js +4 -4
- package/lib/openxml/word/Run.d.ts +7 -3
- package/lib/openxml/word/Run.js +29 -5
- package/lib/openxml/word/Section.d.ts +18 -5
- package/lib/openxml/word/Section.js +47 -3
- package/lib/openxml/word/Separator.d.ts +5 -0
- package/lib/openxml/word/Separator.js +14 -0
- package/lib/openxml/word/SoftHyphen.d.ts +5 -0
- package/lib/openxml/word/SoftHyphen.js +14 -0
- package/lib/openxml/word/Table.d.ts +4 -9
- package/lib/openxml/word/Table.js +0 -235
- package/lib/openxml/word/WDocument.d.ts +1 -2
- package/lib/openxml/word/WDocument.js +53 -7
- package/lib/openxml/word/numbering/AbstractNum.js +5 -3
- package/lib/openxml/word/numbering/Lvl.js +11 -5
- package/lib/openxml/word/numbering/Num.js +12 -4
- package/lib/openxml/word/numbering/NumberProperties.js +2 -2
- package/lib/openxml/word/numbering/Numbering.js +3 -3
- package/lib/openxml/word/table/Tc.d.ts +1 -22
- package/lib/openxml/word/table/Tc.js +0 -224
- package/lib/openxml/word/table/Tr.d.ts +0 -5
- package/lib/openxml/word/table/Tr.js +0 -97
- package/lib/openxml/word/wps/WPG.d.ts +5 -0
- package/lib/openxml/word/wps/WPS.d.ts +18 -0
- package/lib/openxml/word/wps/WPS.js +151 -0
- package/lib/openxml/word/wps/WPSStyle.d.ts +10 -0
- package/lib/openxml/word/wps/WPSStyle.js +46 -0
- package/lib/package/PackageParser.d.ts +1 -1
- package/lib/package/XMLPackageParser.d.ts +3 -3
- package/lib/package/ZipPackageParser.d.ts +1 -1
- package/lib/package/ZipPackageParser.js +7 -8
- package/lib/parse/Footnotes.d.ts +3 -0
- package/lib/parse/Footnotes.js +29 -0
- package/lib/parse/colorNameMap.d.ts +6 -0
- package/lib/parse/colorNameMap.js +205 -0
- package/lib/parse/jcToTextAlign.js +1 -0
- package/lib/parse/mergeSdt.d.ts +4 -0
- package/lib/parse/mergeSdt.js +61 -0
- package/lib/parse/modifyColor.d.ts +1 -0
- package/lib/parse/modifyColor.js +110 -0
- package/lib/parse/parseBorder.js +3 -22
- package/lib/parse/parseCellMargin.d.ts +2 -0
- package/lib/parse/parseCellMargin.js +42 -0
- package/lib/parse/parseChildColor.d.ts +5 -0
- package/lib/parse/parseChildColor.js +70 -0
- package/lib/parse/parseColor.d.ts +4 -0
- package/lib/parse/parseColor.js +41 -45
- package/lib/parse/parseEndnotes.d.ts +3 -0
- package/lib/parse/parseEndnotes.js +29 -0
- package/lib/parse/parseFont.js +2 -2
- package/lib/parse/parseInsideBorders.d.ts +9 -0
- package/lib/parse/parseInsideBorders.js +28 -0
- package/lib/parse/parsePr.d.ts +3 -0
- package/lib/parse/parsePr.js +109 -12
- package/lib/parse/parseRelationship.js +2 -2
- package/lib/parse/parseSdt.d.ts +5 -0
- package/lib/parse/parseShape.d.ts +10 -0
- package/lib/parse/parseShape.js +247 -0
- package/lib/parse/parseSize.d.ts +2 -1
- package/lib/parse/parseSize.js +7 -0
- package/lib/parse/parseSpacing.js +1 -1
- package/lib/parse/parseTable.d.ts +3 -0
- package/lib/parse/parseTable.js +66 -0
- package/lib/parse/parseTablePr.d.ts +3 -0
- package/lib/parse/parseTablePr.js +189 -0
- package/lib/parse/parseTblWidth.d.ts +4 -0
- package/lib/parse/parseTblWidth.js +27 -0
- package/lib/parse/parseTc.d.ts +10 -0
- package/lib/parse/parseTc.js +68 -0
- package/lib/parse/parseTcPr.d.ts +5 -0
- package/lib/parse/parseTcPr.js +104 -0
- package/lib/parse/parseTextDirection.js +4 -6
- package/lib/parse/parseTr.d.ts +6 -0
- package/lib/parse/parseTr.js +53 -0
- package/lib/parse/parseTrPr.d.ts +3 -0
- package/lib/parse/parseTrPr.js +63 -0
- package/lib/render/fixAbsolutePosition.d.ts +8 -0
- package/lib/render/renderBody.d.ts +6 -2
- package/lib/render/renderBody.js +183 -29
- package/lib/render/renderBr.d.ts +2 -1
- package/lib/render/renderBr.js +4 -1
- package/lib/render/renderCustGeom.d.ts +4 -0
- package/lib/render/renderCustGeom.js +14 -0
- package/lib/render/renderDocument.d.ts +2 -2
- package/lib/render/renderDocument.js +2 -2
- package/lib/render/renderDrawing.d.ts +3 -2
- package/lib/render/renderDrawing.js +129 -24
- package/lib/render/renderFont.d.ts +5 -0
- package/lib/render/renderFont.js +43 -0
- package/lib/render/renderGeom.d.ts +4 -0
- package/lib/render/renderGeom.js +18 -0
- package/lib/render/renderHeader.d.ts +6 -0
- package/lib/render/renderHeader.js +44 -0
- package/lib/render/renderHyperLink.js +5 -2
- package/lib/render/renderInlineText.js +2 -2
- package/lib/render/renderInstrText.js +2 -2
- package/lib/render/renderMath.d.ts +3 -0
- package/lib/render/renderMath.js +11 -0
- package/lib/render/renderNoBreakHyphen.d.ts +1 -0
- package/lib/render/renderNoBreakHyphen.js +13 -0
- package/lib/render/renderNotes.d.ts +5 -0
- package/lib/render/renderNotes.js +81 -0
- package/lib/render/renderNumbering.js +9 -11
- package/lib/render/renderParagraph.d.ts +1 -1
- package/lib/render/renderParagraph.js +26 -29
- package/lib/render/renderPict.js +5 -10
- package/lib/render/renderRuby.js +3 -3
- package/lib/render/renderRun.d.ts +4 -2
- package/lib/render/renderRun.js +34 -9
- package/lib/render/renderSection.d.ts +3 -2
- package/lib/render/renderSection.js +79 -5
- package/lib/render/renderSeparator.d.ts +1 -0
- package/lib/render/renderSeparator.js +13 -0
- package/lib/render/renderSoftHyphen.d.ts +1 -0
- package/lib/render/renderSoftHyphen.js +13 -0
- package/lib/render/renderStyle.js +37 -36
- package/lib/render/renderTab.d.ts +1 -0
- package/lib/render/renderTab.js +4 -6
- package/lib/render/renderTable.js +25 -22
- package/lib/render/setElementStyle.js +6 -1
- package/lib/render/zindex.d.ts +1 -0
- package/lib/util/blob.js +0 -10
- package/lib/util/color.d.ts +48 -0
- package/lib/util/color.js +215 -0
- package/lib/util/createObject.d.ts +10 -0
- package/lib/util/createObject.js +54 -0
- package/lib/util/dom.d.ts +8 -4
- package/lib/util/dom.js +24 -5
- package/lib/util/mergeRun.js +5 -5
- package/lib/util/parseSides.d.ts +11 -0
- package/lib/util/print.d.ts +5 -0
- package/lib/util/print.js +58 -0
- package/lib/util/replaceVar.d.ts +10 -0
- package/lib/util/replaceVar.js +219 -0
- package/lib/util/xml.js +4 -0
- package/package.json +17 -6
- package/esm/node_modules/tslib/tslib.es6.js +0 -120
- package/esm/openxml/Types.js +0 -1003
- package/esm/openxml/word/CustomXml.d.ts +0 -8
- package/esm/openxml/word/SmartTag.d.ts +0 -8
- package/esm/openxml/word/SmartTag.js +0 -18
- package/esm/openxml/word/drawing/Blip.d.ts +0 -6
- package/esm/openxml/word/drawing/Drawing.d.ts +0 -6
- package/esm/openxml/word/drawing/Drawing.js +0 -15
- package/esm/openxml/word/drawing/Pic.d.ts +0 -8
- package/esm/openxml/word/drawing/Pic.js +0 -16
- package/esm/openxml/word/drawing/ShapeProperties.d.ts +0 -9
- package/esm/openxml/word/drawing/ShapeProperties.js +0 -20
- package/lib/node_modules/tslib/tslib.es6.js +0 -129
- package/lib/openxml/Types.js +0 -1005
- package/lib/openxml/word/CustomXml.d.ts +0 -8
- package/lib/openxml/word/SmartTag.d.ts +0 -8
- package/lib/openxml/word/SmartTag.js +0 -22
- package/lib/openxml/word/drawing/Blip.d.ts +0 -6
- package/lib/openxml/word/drawing/Drawing.d.ts +0 -6
- package/lib/openxml/word/drawing/Drawing.js +0 -19
- package/lib/openxml/word/drawing/Pic.d.ts +0 -8
- package/lib/openxml/word/drawing/Pic.js +0 -20
- package/lib/openxml/word/drawing/ShapeProperties.d.ts +0 -9
- package/lib/openxml/word/drawing/ShapeProperties.js +0 -24
package/esm/Word.js
CHANGED
|
@@ -1,32 +1,51 @@
|
|
|
1
|
-
import { __values,
|
|
1
|
+
import { __values, __awaiter, __generator, __assign } from 'tslib';
|
|
2
|
+
import { FontTable } from './openxml/word/FontTable.js';
|
|
2
3
|
import { parseRelationships } from './parse/parseRelationship.js';
|
|
3
4
|
import { parseContentType } from './openxml/ContentType.js';
|
|
4
5
|
import { parseStyles } from './openxml/Style.js';
|
|
5
6
|
import { parseTheme } from './openxml/Theme.js';
|
|
6
7
|
import renderDocument from './render/renderDocument.js';
|
|
7
|
-
import {
|
|
8
|
+
import { downloadBlob } from './util/blob.js';
|
|
8
9
|
import { Numbering } from './openxml/word/numbering/Numbering.js';
|
|
9
|
-
import { appendChild } from './util/dom.js';
|
|
10
|
+
import { createElement, appendChild } from './util/dom.js';
|
|
10
11
|
import { renderStyle } from './render/renderStyle.js';
|
|
11
12
|
import { mergeRun } from './util/mergeRun.js';
|
|
12
13
|
import { WDocument } from './openxml/word/WDocument.js';
|
|
13
14
|
import { updateVariableText } from './render/renderRun.js';
|
|
14
15
|
import ZipPackageParser from './package/ZipPackageParser.js';
|
|
15
16
|
import { buildXML } from './util/xml.js';
|
|
17
|
+
import { deobfuscate } from './openxml/word/Font.js';
|
|
18
|
+
import { renderFont } from './render/renderFont.js';
|
|
19
|
+
import { replaceVar, replaceT } from './util/replaceVar.js';
|
|
20
|
+
import { parseFootnotes } from './parse/Footnotes.js';
|
|
21
|
+
import { parseEndnotes } from './parse/parseEndnotes.js';
|
|
22
|
+
import { renderNotes } from './render/renderNotes.js';
|
|
23
|
+
import { printIframe } from './util/print.js';
|
|
24
|
+
import { Settings } from './openxml/Settings.js';
|
|
16
25
|
|
|
17
|
-
/**
|
|
18
|
-
* 总入口,它将包括所有 word 文档信息,后续渲染的时候依赖它来获取关联信息
|
|
19
|
-
*/
|
|
20
26
|
var defaultRenderOptions = {
|
|
21
|
-
imageDataURL: false,
|
|
22
27
|
classPrefix: 'docx-viewer',
|
|
23
|
-
|
|
28
|
+
page: false,
|
|
29
|
+
pageWrap: true,
|
|
24
30
|
bulletUseFont: true,
|
|
25
31
|
ignoreHeight: true,
|
|
26
|
-
ignoreWidth:
|
|
32
|
+
ignoreWidth: false,
|
|
27
33
|
minLineHeight: 1.0,
|
|
28
34
|
enableVar: false,
|
|
29
|
-
debug: false
|
|
35
|
+
debug: false,
|
|
36
|
+
pageWrapPadding: 20,
|
|
37
|
+
pageMarginBottom: 20,
|
|
38
|
+
pageShadow: true,
|
|
39
|
+
pageBackground: '#FFFFFF',
|
|
40
|
+
pageWrapBackground: '#ECECEC',
|
|
41
|
+
printWaitTime: 100,
|
|
42
|
+
zoomFitWidth: false,
|
|
43
|
+
renderHeader: true,
|
|
44
|
+
renderFooter: true,
|
|
45
|
+
data: {},
|
|
46
|
+
evalVar: function (t) {
|
|
47
|
+
return t;
|
|
48
|
+
}
|
|
30
49
|
};
|
|
31
50
|
var Word = /** @class */ (function () {
|
|
32
51
|
/**
|
|
@@ -51,11 +70,21 @@ var Word = /** @class */ (function () {
|
|
|
51
70
|
*/
|
|
52
71
|
this.styleIdNum = 0;
|
|
53
72
|
this.wrapClassName = 'docx-viewer-wrapper';
|
|
73
|
+
this.footNotes = {};
|
|
74
|
+
this.endNotes = {};
|
|
54
75
|
this.inited = false;
|
|
76
|
+
/**
|
|
77
|
+
* 分页标记,如果为 true,那么在渲染的时候会强制分页
|
|
78
|
+
*/
|
|
79
|
+
this.breakPage = false;
|
|
55
80
|
parser.load(docFile);
|
|
56
81
|
this.id = Word.globalId++;
|
|
57
82
|
this.parser = parser;
|
|
58
83
|
this.renderOptions = __assign(__assign({}, defaultRenderOptions), renderOptions);
|
|
84
|
+
if (this.renderOptions.page) {
|
|
85
|
+
this.renderOptions.ignoreHeight = false;
|
|
86
|
+
this.renderOptions.ignoreWidth = false;
|
|
87
|
+
}
|
|
59
88
|
}
|
|
60
89
|
/**
|
|
61
90
|
* 初始化一些公共资源,比如
|
|
@@ -66,10 +95,14 @@ var Word = /** @class */ (function () {
|
|
|
66
95
|
}
|
|
67
96
|
// 这个必须在最前面,因为后面很多依赖它来查找文件的
|
|
68
97
|
this.initContentType();
|
|
98
|
+
// relation 需要排第二
|
|
99
|
+
this.initRelation();
|
|
100
|
+
this.initSettings();
|
|
69
101
|
this.initTheme();
|
|
102
|
+
this.initFontTable();
|
|
70
103
|
this.initStyle();
|
|
71
|
-
this.initRelation();
|
|
72
104
|
this.initNumbering();
|
|
105
|
+
this.initNotes();
|
|
73
106
|
this.inited = true;
|
|
74
107
|
};
|
|
75
108
|
/**
|
|
@@ -115,6 +148,48 @@ var Word = /** @class */ (function () {
|
|
|
115
148
|
finally { if (e_2) throw e_2.error; }
|
|
116
149
|
}
|
|
117
150
|
};
|
|
151
|
+
/**
|
|
152
|
+
* 解析全局配置
|
|
153
|
+
*/
|
|
154
|
+
Word.prototype.initSettings = function () {
|
|
155
|
+
var e_3, _a;
|
|
156
|
+
try {
|
|
157
|
+
for (var _b = __values(this.conentTypes.overrides), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
158
|
+
var override = _c.value;
|
|
159
|
+
if (override.partName.startsWith('/word/settings.xml')) {
|
|
160
|
+
this.settings = Settings.parse(this, this.parser.getXML('/word/settings.xml'));
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
165
|
+
finally {
|
|
166
|
+
try {
|
|
167
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
168
|
+
}
|
|
169
|
+
finally { if (e_3) throw e_3.error; }
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
/**
|
|
173
|
+
* 解析字体表
|
|
174
|
+
*/
|
|
175
|
+
Word.prototype.initFontTable = function () {
|
|
176
|
+
var e_4, _a;
|
|
177
|
+
try {
|
|
178
|
+
for (var _b = __values(this.conentTypes.overrides), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
179
|
+
var override = _c.value;
|
|
180
|
+
if (override.partName.startsWith('/word/fontTable.xml')) {
|
|
181
|
+
this.fontTable = FontTable.fromXML(this, this.parser.getXML('/word/fontTable.xml'));
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
186
|
+
finally {
|
|
187
|
+
try {
|
|
188
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
189
|
+
}
|
|
190
|
+
finally { if (e_4) throw e_4.error; }
|
|
191
|
+
}
|
|
192
|
+
};
|
|
118
193
|
/**
|
|
119
194
|
* 解析关系
|
|
120
195
|
*/
|
|
@@ -123,11 +198,17 @@ var Word = /** @class */ (function () {
|
|
|
123
198
|
if (this.parser.fileExists('/_rels/.rels')) {
|
|
124
199
|
rels = parseRelationships(this.parser.getXML('/_rels/.rels'), 'root');
|
|
125
200
|
}
|
|
201
|
+
this.relationships = rels;
|
|
126
202
|
var documentRels = {};
|
|
127
203
|
if (this.parser.fileExists('/word/_rels/document.xml.rels')) {
|
|
128
204
|
documentRels = parseRelationships(this.parser.getXML('/word/_rels/document.xml.rels'), 'word');
|
|
129
205
|
}
|
|
130
|
-
this.
|
|
206
|
+
this.documentRels = documentRels;
|
|
207
|
+
var fontTableRels = {};
|
|
208
|
+
if (this.parser.fileExists('/word/_rels/fontTable.xml.rels')) {
|
|
209
|
+
fontTableRels = parseRelationships(this.parser.getXML('/word/_rels/fontTable.xml.rels'), 'word');
|
|
210
|
+
}
|
|
211
|
+
this.fontTableRels = fontTableRels;
|
|
131
212
|
};
|
|
132
213
|
/**
|
|
133
214
|
* 解析全局配置
|
|
@@ -140,7 +221,7 @@ var Word = /** @class */ (function () {
|
|
|
140
221
|
* 解析 numbering
|
|
141
222
|
*/
|
|
142
223
|
Word.prototype.initNumbering = function () {
|
|
143
|
-
var
|
|
224
|
+
var e_5, _a;
|
|
144
225
|
try {
|
|
145
226
|
for (var _b = __values(this.conentTypes.overrides), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
146
227
|
var override = _c.value;
|
|
@@ -150,32 +231,88 @@ var Word = /** @class */ (function () {
|
|
|
150
231
|
}
|
|
151
232
|
}
|
|
152
233
|
}
|
|
153
|
-
catch (
|
|
234
|
+
catch (e_5_1) { e_5 = { error: e_5_1 }; }
|
|
154
235
|
finally {
|
|
155
236
|
try {
|
|
156
237
|
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
157
238
|
}
|
|
158
|
-
finally { if (
|
|
239
|
+
finally { if (e_5) throw e_5.error; }
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
Word.prototype.initNotes = function () {
|
|
243
|
+
var e_6, _a;
|
|
244
|
+
try {
|
|
245
|
+
for (var _b = __values(this.conentTypes.overrides), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
246
|
+
var override = _c.value;
|
|
247
|
+
if (override.partName.startsWith('/word/footnotes.xml')) {
|
|
248
|
+
var notesData = this.parser.getXML(override.partName);
|
|
249
|
+
this.footNotes = parseFootnotes(this, notesData);
|
|
250
|
+
}
|
|
251
|
+
if (override.partName.startsWith('/word/endnotes.xml')) {
|
|
252
|
+
var notesData = this.parser.getXML(override.partName);
|
|
253
|
+
this.endNotes = parseEndnotes(this, notesData);
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
catch (e_6_1) { e_6 = { error: e_6_1 }; }
|
|
258
|
+
finally {
|
|
259
|
+
try {
|
|
260
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
261
|
+
}
|
|
262
|
+
finally { if (e_6) throw e_6.error; }
|
|
159
263
|
}
|
|
160
264
|
};
|
|
161
265
|
/**
|
|
162
|
-
*
|
|
266
|
+
* 获取全局关系
|
|
163
267
|
*/
|
|
164
268
|
Word.prototype.getRelationship = function (id) {
|
|
165
|
-
if (id) {
|
|
269
|
+
if (id && this.relationships) {
|
|
166
270
|
return this.relationships[id];
|
|
167
271
|
}
|
|
168
272
|
return null;
|
|
169
273
|
};
|
|
170
274
|
/**
|
|
171
|
-
*
|
|
275
|
+
* 获取文档对应的关系
|
|
276
|
+
*/
|
|
277
|
+
Word.prototype.getDocumentRels = function (id) {
|
|
278
|
+
if (id && this.documentRels) {
|
|
279
|
+
return this.documentRels[id];
|
|
280
|
+
}
|
|
281
|
+
return null;
|
|
282
|
+
};
|
|
283
|
+
/**
|
|
284
|
+
* 获取字体对应的关系
|
|
285
|
+
*/
|
|
286
|
+
Word.prototype.getFontTableRels = function (id) {
|
|
287
|
+
if (id && this.fontTableRels) {
|
|
288
|
+
return this.fontTableRels[id];
|
|
289
|
+
}
|
|
290
|
+
return null;
|
|
291
|
+
};
|
|
292
|
+
/**
|
|
293
|
+
* 进行单个文本替换
|
|
172
294
|
*/
|
|
173
295
|
Word.prototype.replaceText = function (text) {
|
|
174
|
-
if (this.renderOptions.enableVar === false
|
|
175
|
-
!this.renderOptions.replaceText) {
|
|
296
|
+
if (this.renderOptions.enableVar === false) {
|
|
176
297
|
return text;
|
|
177
298
|
}
|
|
178
|
-
|
|
299
|
+
var data = this.renderOptions.data;
|
|
300
|
+
if (text.indexOf('{{') !== -1) {
|
|
301
|
+
text = text.replace(/^{{/g, '').replace(/}}$/g, '');
|
|
302
|
+
var result = this.renderOptions.evalVar(text, data);
|
|
303
|
+
if (typeof result === 'undefined') {
|
|
304
|
+
return '';
|
|
305
|
+
}
|
|
306
|
+
return String(result);
|
|
307
|
+
}
|
|
308
|
+
return text;
|
|
309
|
+
};
|
|
310
|
+
Word.prototype.loadWordRelXML = function (relation) {
|
|
311
|
+
var path = relation.target;
|
|
312
|
+
if (relation.part === 'word') {
|
|
313
|
+
path = 'word/' + path;
|
|
314
|
+
}
|
|
315
|
+
return this.getXML(path);
|
|
179
316
|
};
|
|
180
317
|
/**
|
|
181
318
|
* 加载图片
|
|
@@ -187,14 +324,22 @@ var Word = /** @class */ (function () {
|
|
|
187
324
|
}
|
|
188
325
|
var data = this.parser.getFileByType(path, 'blob');
|
|
189
326
|
if (data) {
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
327
|
+
return URL.createObjectURL(data);
|
|
328
|
+
}
|
|
329
|
+
return null;
|
|
330
|
+
};
|
|
331
|
+
Word.prototype.loadFont = function (rId, key) {
|
|
332
|
+
var relation = this.getFontTableRels(rId);
|
|
333
|
+
if (!relation) {
|
|
334
|
+
return null;
|
|
335
|
+
}
|
|
336
|
+
var path = relation.target;
|
|
337
|
+
if (relation.part === 'word') {
|
|
338
|
+
path = 'word/' + path;
|
|
339
|
+
}
|
|
340
|
+
var data = this.parser.getFileByType(path, 'uint8array');
|
|
341
|
+
if (data) {
|
|
342
|
+
return URL.createObjectURL(new Blob([deobfuscate(data, key)]));
|
|
198
343
|
}
|
|
199
344
|
return null;
|
|
200
345
|
};
|
|
@@ -233,8 +378,9 @@ var Word = /** @class */ (function () {
|
|
|
233
378
|
* 添加新样式,主要用于表格的单元格样式
|
|
234
379
|
*/
|
|
235
380
|
Word.prototype.appendStyle = function (style) {
|
|
236
|
-
|
|
237
|
-
styleElement
|
|
381
|
+
if (style === void 0) { style = ''; }
|
|
382
|
+
var styleElement = createElement('style');
|
|
383
|
+
styleElement.textContent = style;
|
|
238
384
|
this.rootElement.appendChild(styleElement);
|
|
239
385
|
};
|
|
240
386
|
/**
|
|
@@ -253,6 +399,13 @@ var Word = /** @class */ (function () {
|
|
|
253
399
|
}
|
|
254
400
|
return classNames;
|
|
255
401
|
};
|
|
402
|
+
/**
|
|
403
|
+
* 根据 id 获取样式
|
|
404
|
+
* @param styleId
|
|
405
|
+
*/
|
|
406
|
+
Word.prototype.getStyle = function (styleId) {
|
|
407
|
+
return this.styles.styleMap[styleId];
|
|
408
|
+
};
|
|
256
409
|
/**
|
|
257
410
|
* 渲染时的 css 类前缀
|
|
258
411
|
*/
|
|
@@ -260,11 +413,28 @@ var Word = /** @class */ (function () {
|
|
|
260
413
|
return "".concat(this.renderOptions.classPrefix, "-").concat(this.id);
|
|
261
414
|
};
|
|
262
415
|
/**
|
|
263
|
-
*
|
|
416
|
+
* 获取主题色
|
|
264
417
|
*/
|
|
265
418
|
Word.prototype.getThemeColor = function (name) {
|
|
266
|
-
|
|
419
|
+
var _a, _b, _c;
|
|
420
|
+
if (this.settings.clrSchemeMapping) {
|
|
421
|
+
name = this.settings.clrSchemeMapping[name] || name;
|
|
422
|
+
}
|
|
423
|
+
if (this.themes && this.themes.length > 0) {
|
|
424
|
+
var theme = this.themes[0];
|
|
425
|
+
var color = (_c = (_b = (_a = theme.themeElements) === null || _a === void 0 ? void 0 : _a.clrScheme) === null || _b === void 0 ? void 0 : _b.colors) === null || _c === void 0 ? void 0 : _c[name];
|
|
426
|
+
if (color) {
|
|
427
|
+
return color;
|
|
428
|
+
}
|
|
429
|
+
else {
|
|
430
|
+
console.warn('unknown theme color: ' + name);
|
|
431
|
+
}
|
|
432
|
+
}
|
|
433
|
+
return '';
|
|
267
434
|
};
|
|
435
|
+
/**
|
|
436
|
+
* 添加类,自动加上前缀
|
|
437
|
+
*/
|
|
268
438
|
Word.prototype.addClass = function (element, className) {
|
|
269
439
|
element.classList.add("".concat(this.getClassPrefix(), "-").concat(className));
|
|
270
440
|
};
|
|
@@ -272,9 +442,7 @@ var Word = /** @class */ (function () {
|
|
|
272
442
|
* 更新页面中的变量,这个要在 render 后运行
|
|
273
443
|
*/
|
|
274
444
|
Word.prototype.updateVariable = function () {
|
|
275
|
-
if (!this.rootElement ||
|
|
276
|
-
this.renderOptions.enableVar === false ||
|
|
277
|
-
!this.renderOptions.replaceText) {
|
|
445
|
+
if (!this.rootElement || this.renderOptions.enableVar === false) {
|
|
278
446
|
return;
|
|
279
447
|
}
|
|
280
448
|
updateVariableText(this);
|
|
@@ -285,12 +453,13 @@ var Word = /** @class */ (function () {
|
|
|
285
453
|
Word.prototype.download = function (fileName) {
|
|
286
454
|
if (fileName === void 0) { fileName = 'document.docx'; }
|
|
287
455
|
var documentData = this.getXML('word/document.xml');
|
|
288
|
-
if (this.renderOptions.enableVar
|
|
456
|
+
if (this.renderOptions.enableVar) {
|
|
289
457
|
mergeRun(this, documentData);
|
|
458
|
+
replaceVar(this, documentData);
|
|
290
459
|
// 对文本进行替换
|
|
291
460
|
var ts = documentData.getElementsByTagName('w:t');
|
|
292
461
|
for (var i = 0; i < ts.length; i++) {
|
|
293
|
-
ts[i]
|
|
462
|
+
replaceT(this, ts[i], this.renderOptions.data);
|
|
294
463
|
}
|
|
295
464
|
}
|
|
296
465
|
var blob = this.parser.generateZip(buildXML(documentData));
|
|
@@ -300,26 +469,28 @@ var Word = /** @class */ (function () {
|
|
|
300
469
|
* 打印功能
|
|
301
470
|
*/
|
|
302
471
|
Word.prototype.print = function () {
|
|
303
|
-
var _a, _b;
|
|
304
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
305
|
-
var iframe;
|
|
306
|
-
return __generator(this, function (
|
|
307
|
-
switch (
|
|
473
|
+
var iframe, printDocument;
|
|
474
|
+
return __generator(this, function (_a) {
|
|
475
|
+
switch (_a.label) {
|
|
308
476
|
case 0:
|
|
309
477
|
iframe = document.createElement('iframe');
|
|
310
478
|
iframe.style.position = 'absolute';
|
|
311
479
|
iframe.style.top = '-10000px';
|
|
312
480
|
document.body.appendChild(iframe);
|
|
313
|
-
|
|
314
|
-
|
|
481
|
+
printDocument = iframe.contentDocument;
|
|
482
|
+
if (!printDocument) {
|
|
483
|
+
console.warn('printDocument is null');
|
|
484
|
+
return [2 /*return*/, null];
|
|
485
|
+
}
|
|
486
|
+
printDocument.write("<style>\n html, body { margin:0; padding:0 }\n @page { size: auto; margin: 0mm; }\n </style>\n <div id=\"print\"></div>");
|
|
487
|
+
return [4 /*yield*/, this.render(printDocument.getElementById('print'), __assign({ page: true, pageWrap: false, pageShadow: false, pageMarginBottom: 0, pageWrapPadding: undefined, zoom: 1 }, this.renderOptions.printOptions))];
|
|
315
488
|
case 1:
|
|
316
|
-
|
|
489
|
+
_a.sent();
|
|
317
490
|
setTimeout(function () {
|
|
318
|
-
var _a, _b;
|
|
319
491
|
iframe.focus();
|
|
320
|
-
(
|
|
321
|
-
|
|
322
|
-
}, 100);
|
|
492
|
+
printIframe(iframe);
|
|
493
|
+
}, this.renderOptions.printWaitTime || 100); // 需要等一下图片渲染
|
|
323
494
|
window.focus();
|
|
324
495
|
return [2 /*return*/];
|
|
325
496
|
}
|
|
@@ -330,32 +501,40 @@ var Word = /** @class */ (function () {
|
|
|
330
501
|
* 渲染文档入口
|
|
331
502
|
*
|
|
332
503
|
* @param root 渲染的根节点
|
|
504
|
+
* @param renderOptionsOverride 临时覆盖某些渲选项
|
|
333
505
|
*/
|
|
334
|
-
Word.prototype.render = function (root) {
|
|
506
|
+
Word.prototype.render = function (root, renderOptionsOverride) {
|
|
507
|
+
if (renderOptionsOverride === void 0) { renderOptionsOverride = {}; }
|
|
335
508
|
return __awaiter(this, void 0, void 0, function () {
|
|
336
509
|
var renderOptions, isDebug, documentData, document, documentElement;
|
|
337
510
|
return __generator(this, function (_a) {
|
|
338
511
|
this.init();
|
|
339
|
-
|
|
512
|
+
this.currentPage = 0;
|
|
513
|
+
renderOptions = __assign(__assign({}, this.renderOptions), renderOptionsOverride);
|
|
340
514
|
isDebug = renderOptions.debug;
|
|
341
515
|
isDebug && console.log('init', this);
|
|
342
516
|
this.rootElement = root;
|
|
343
517
|
root.innerHTML = '';
|
|
344
518
|
documentData = this.getXML('word/document.xml');
|
|
345
519
|
isDebug && console.log('documentData', documentData);
|
|
346
|
-
if (renderOptions.enableVar
|
|
520
|
+
if (renderOptions.enableVar) {
|
|
347
521
|
mergeRun(this, documentData);
|
|
522
|
+
replaceVar(this, documentData);
|
|
348
523
|
// 这里不进行变量替换,方便后续进行局部替换来更新变量
|
|
349
524
|
}
|
|
350
525
|
document = WDocument.fromXML(this, documentData);
|
|
351
526
|
isDebug && console.log('document', document);
|
|
352
|
-
documentElement = renderDocument(this, document);
|
|
527
|
+
documentElement = renderDocument(root, this, document, renderOptions);
|
|
353
528
|
root.classList.add(this.getClassPrefix());
|
|
354
|
-
if (renderOptions.
|
|
529
|
+
if (renderOptions.page && renderOptions.pageWrap) {
|
|
355
530
|
root.classList.add(this.wrapClassName);
|
|
531
|
+
root.style.padding = "".concat(renderOptions.pageWrapPadding || 0, "pt");
|
|
532
|
+
root.style.background = renderOptions.pageWrapBackground || '#ECECEC';
|
|
356
533
|
}
|
|
357
534
|
appendChild(root, renderStyle(this));
|
|
535
|
+
appendChild(root, renderFont(this.fontTable));
|
|
358
536
|
appendChild(root, documentElement);
|
|
537
|
+
appendChild(root, renderNotes(this));
|
|
359
538
|
return [2 /*return*/];
|
|
360
539
|
});
|
|
361
540
|
});
|
|
@@ -1,14 +1,28 @@
|
|
|
1
|
+
import { __values } from 'tslib';
|
|
2
|
+
|
|
1
3
|
/**
|
|
2
4
|
* 解析 [Content_Types].xml
|
|
3
5
|
*/
|
|
4
6
|
function parseContentType(doc) {
|
|
7
|
+
var e_1, _a;
|
|
5
8
|
var types = { overrides: [] };
|
|
6
|
-
doc.
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
9
|
+
var overrides = [].slice.call(doc.getElementsByTagName('Override'));
|
|
10
|
+
try {
|
|
11
|
+
for (var overrides_1 = __values(overrides), overrides_1_1 = overrides_1.next(); !overrides_1_1.done; overrides_1_1 = overrides_1.next()) {
|
|
12
|
+
var item = overrides_1_1.value;
|
|
13
|
+
types.overrides.push({
|
|
14
|
+
partName: item.getAttribute('PartName'),
|
|
15
|
+
contentType: item.getAttribute('ContentType')
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
20
|
+
finally {
|
|
21
|
+
try {
|
|
22
|
+
if (overrides_1_1 && !overrides_1_1.done && (_a = overrides_1.return)) _a.call(overrides_1);
|
|
23
|
+
}
|
|
24
|
+
finally { if (e_1) throw e_1.error; }
|
|
25
|
+
}
|
|
12
26
|
return types;
|
|
13
27
|
}
|
|
14
28
|
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { __values } from 'tslib';
|
|
2
|
+
import { getValBoolean } from '../OpenXML.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 解析 settings.xml,只支持一小部分
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 解析颜色映射
|
|
10
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/clrSchemeMapping.html
|
|
11
|
+
*/
|
|
12
|
+
function parseClrSchemeMapping(element) {
|
|
13
|
+
var e_1, _a;
|
|
14
|
+
var clrSchemeMapping = {};
|
|
15
|
+
try {
|
|
16
|
+
for (var _b = __values(element.attributes), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
17
|
+
var attribute = _c.value;
|
|
18
|
+
var name_1 = attribute.name.replace('w:', '');
|
|
19
|
+
var value = attribute.value;
|
|
20
|
+
// 文档里也说了这个等于 lt1
|
|
21
|
+
if (value === 'light1') {
|
|
22
|
+
value = 'lt1';
|
|
23
|
+
}
|
|
24
|
+
else if (value === 'light2') {
|
|
25
|
+
value = 'lt2';
|
|
26
|
+
}
|
|
27
|
+
else if (value === 'dark1') {
|
|
28
|
+
value = 'dk1';
|
|
29
|
+
}
|
|
30
|
+
else if (value === 'dark2') {
|
|
31
|
+
value = 'dk2';
|
|
32
|
+
}
|
|
33
|
+
clrSchemeMapping[name_1] = value;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
37
|
+
finally {
|
|
38
|
+
try {
|
|
39
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
40
|
+
}
|
|
41
|
+
finally { if (e_1) throw e_1.error; }
|
|
42
|
+
}
|
|
43
|
+
if (!clrSchemeMapping.bg1) {
|
|
44
|
+
clrSchemeMapping.bg1 = 'lt1';
|
|
45
|
+
}
|
|
46
|
+
if (!clrSchemeMapping.bg2) {
|
|
47
|
+
clrSchemeMapping.bg2 = 'lt2';
|
|
48
|
+
}
|
|
49
|
+
if (!clrSchemeMapping.tx1) {
|
|
50
|
+
clrSchemeMapping.tx1 = 'dk1';
|
|
51
|
+
}
|
|
52
|
+
return clrSchemeMapping;
|
|
53
|
+
}
|
|
54
|
+
var Settings = /** @class */ (function () {
|
|
55
|
+
function Settings() {
|
|
56
|
+
this.clrSchemeMapping = {};
|
|
57
|
+
this.autoHyphenation = false;
|
|
58
|
+
}
|
|
59
|
+
Settings.parse = function (word, doc) {
|
|
60
|
+
var e_2, _a;
|
|
61
|
+
var settings = new Settings();
|
|
62
|
+
var rootElement = doc;
|
|
63
|
+
if (doc.firstElementChild &&
|
|
64
|
+
doc.firstElementChild.tagName === 'w:settings') {
|
|
65
|
+
rootElement = doc.getElementsByTagName('w:settings').item(0);
|
|
66
|
+
}
|
|
67
|
+
try {
|
|
68
|
+
for (var _b = __values(Array.from(rootElement.children)), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
69
|
+
var child = _c.value;
|
|
70
|
+
var tag = child.tagName;
|
|
71
|
+
switch (tag) {
|
|
72
|
+
case 'w:clrSchemeMapping':
|
|
73
|
+
settings.clrSchemeMapping = parseClrSchemeMapping(child);
|
|
74
|
+
break;
|
|
75
|
+
case 'w:autoHyphenation':
|
|
76
|
+
settings.autoHyphenation = getValBoolean(child, false);
|
|
77
|
+
break;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
82
|
+
finally {
|
|
83
|
+
try {
|
|
84
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
85
|
+
}
|
|
86
|
+
finally { if (e_2) throw e_2.error; }
|
|
87
|
+
}
|
|
88
|
+
return settings;
|
|
89
|
+
};
|
|
90
|
+
return Settings;
|
|
91
|
+
}());
|
|
92
|
+
|
|
93
|
+
export { Settings };
|
package/esm/openxml/Style.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ import { TablePr } from './word/Table';
|
|
|
9
9
|
import { TcPr } from './word/table/Tc';
|
|
10
10
|
import { TrPr } from './word/table/Tr';
|
|
11
11
|
export interface CSSStyle {
|
|
12
|
-
[key: string]: string;
|
|
12
|
+
[key: string]: string | number;
|
|
13
13
|
}
|
|
14
14
|
export interface TblStylePrStyle {
|
|
15
15
|
rPr?: RunPr;
|
package/esm/openxml/Style.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { __values } from '
|
|
1
|
+
import { __values } from 'tslib';
|
|
2
|
+
import { parseTcPr } from '../parse/parseTcPr.js';
|
|
2
3
|
import { getVal } from '../OpenXML.js';
|
|
3
4
|
import { Paragraph } from './word/Paragraph.js';
|
|
4
5
|
import { Run } from './word/Run.js';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import { Tr } from './word/table/Tr.js';
|
|
6
|
+
import { parseTablePr } from '../parse/parseTablePr.js';
|
|
7
|
+
import { parseTrPr } from '../parse/parseTrPr.js';
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* 解析共享样式 Style
|
|
@@ -17,16 +17,16 @@ function parseDefaultStyle(word, element) {
|
|
|
17
17
|
if (!element) {
|
|
18
18
|
return defaultStyle;
|
|
19
19
|
}
|
|
20
|
-
var rPrDefault = element.
|
|
20
|
+
var rPrDefault = element.getElementsByTagName('w:rPrDefault').item(0);
|
|
21
21
|
if (rPrDefault) {
|
|
22
|
-
var rPr = rPrDefault.
|
|
22
|
+
var rPr = rPrDefault.getElementsByTagName('w:rPr').item(0);
|
|
23
23
|
if (rPr) {
|
|
24
24
|
defaultStyle.rPr = Run.parseRunPr(word, rPr);
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
|
-
var pPrDefault = element.
|
|
27
|
+
var pPrDefault = element.getElementsByTagName('w:pPrDefault').item(0);
|
|
28
28
|
if (pPrDefault) {
|
|
29
|
-
var pPr = pPrDefault.
|
|
29
|
+
var pPr = pPrDefault.getElementsByTagName('w:pPr').item(0);
|
|
30
30
|
if (pPr) {
|
|
31
31
|
defaultStyle.pPr = Paragraph.parseParagraphPr(word, pPr);
|
|
32
32
|
}
|
|
@@ -48,13 +48,13 @@ function parseTblStylePr(word, element) {
|
|
|
48
48
|
style.pPr = Paragraph.parseParagraphPr(word, child);
|
|
49
49
|
break;
|
|
50
50
|
case 'w:tblPr':
|
|
51
|
-
style.tblPr =
|
|
51
|
+
style.tblPr = parseTablePr(word, child);
|
|
52
52
|
break;
|
|
53
53
|
case 'w:tcPr':
|
|
54
|
-
style.tcPr =
|
|
54
|
+
style.tcPr = parseTcPr(word, child);
|
|
55
55
|
break;
|
|
56
56
|
case 'w:trPr':
|
|
57
|
-
style.trPr =
|
|
57
|
+
style.trPr = parseTrPr(word, child);
|
|
58
58
|
break;
|
|
59
59
|
}
|
|
60
60
|
}
|
|
@@ -149,7 +149,7 @@ function parseStyles(word, doc) {
|
|
|
149
149
|
}
|
|
150
150
|
finally { if (e_3) throw e_3.error; }
|
|
151
151
|
}
|
|
152
|
-
styles.defaultStyle = parseDefaultStyle(word, doc.
|
|
152
|
+
styles.defaultStyle = parseDefaultStyle(word, doc.getElementsByTagName('w:docDefaults').item(0));
|
|
153
153
|
return styles;
|
|
154
154
|
}
|
|
155
155
|
|