office-viewer 0.1.0
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 +23 -0
- package/esm/OpenXML.d.ts +21 -0
- package/esm/OpenXML.js +60 -0
- package/esm/Word.d.ts +208 -0
- package/esm/Word.js +370 -0
- package/esm/index.d.ts +6 -0
- package/esm/index.js +6 -0
- package/esm/node_modules/tslib/tslib.es6.js +120 -0
- package/esm/openxml/ContentType.d.ts +12 -0
- package/esm/openxml/ContentType.js +15 -0
- package/esm/openxml/Style.d.ts +41 -0
- package/esm/openxml/Style.js +156 -0
- package/esm/openxml/Theme.d.ts +26 -0
- package/esm/openxml/Theme.js +69 -0
- package/esm/openxml/Types.d.ts +2512 -0
- package/esm/openxml/Types.js +1003 -0
- package/esm/openxml/word/Background.d.ts +11 -0
- package/esm/openxml/word/Body.d.ts +18 -0
- package/esm/openxml/word/Body.js +67 -0
- package/esm/openxml/word/Bookmark.d.ts +6 -0
- package/esm/openxml/word/Bookmark.js +18 -0
- package/esm/openxml/word/Border.d.ts +10 -0
- package/esm/openxml/word/Break.d.ts +13 -0
- package/esm/openxml/word/Break.js +19 -0
- package/esm/openxml/word/CustomXml.d.ts +8 -0
- package/esm/openxml/word/FldSimple.d.ts +7 -0
- package/esm/openxml/word/FldSimple.js +15 -0
- package/esm/openxml/word/FrameProperties.d.ts +18 -0
- package/esm/openxml/word/Hyperlink.d.ts +13 -0
- package/esm/openxml/word/Hyperlink.js +53 -0
- package/esm/openxml/word/Indent.d.ts +8 -0
- package/esm/openxml/word/InlineText.d.ts +14 -0
- package/esm/openxml/word/InlineText.js +62 -0
- package/esm/openxml/word/InstrText.d.ts +4 -0
- package/esm/openxml/word/InstrText.js +8 -0
- package/esm/openxml/word/Paragraph.d.ts +34 -0
- package/esm/openxml/word/Paragraph.js +133 -0
- package/esm/openxml/word/Pict.d.ts +6 -0
- package/esm/openxml/word/Pict.js +19 -0
- package/esm/openxml/word/Ruby.d.ts +20 -0
- package/esm/openxml/word/Ruby.js +87 -0
- package/esm/openxml/word/Run.d.ts +31 -0
- package/esm/openxml/word/Run.js +98 -0
- package/esm/openxml/word/Section.d.ts +38 -0
- package/esm/openxml/word/Section.js +59 -0
- package/esm/openxml/word/Shading.d.ts +9 -0
- package/esm/openxml/word/SmartTag.d.ts +8 -0
- package/esm/openxml/word/SmartTag.js +18 -0
- package/esm/openxml/word/Spacing.d.ts +9 -0
- package/esm/openxml/word/Sym.d.ts +8 -0
- package/esm/openxml/word/Sym.js +16 -0
- package/esm/openxml/word/Tab.d.ts +8 -0
- package/esm/openxml/word/Tab.js +17 -0
- package/esm/openxml/word/Table.d.ts +49 -0
- package/esm/openxml/word/Table.js +248 -0
- package/esm/openxml/word/VerticalAlign.d.ts +6 -0
- package/esm/openxml/word/WDocument.d.ts +13 -0
- package/esm/openxml/word/WDocument.js +58 -0
- package/esm/openxml/word/drawing/Blip.d.ts +6 -0
- package/esm/openxml/word/drawing/Blip.js +17 -0
- package/esm/openxml/word/drawing/BlipFill.d.ts +9 -0
- package/esm/openxml/word/drawing/BlipFill.js +20 -0
- package/esm/openxml/word/drawing/Drawing.d.ts +6 -0
- package/esm/openxml/word/drawing/Drawing.js +15 -0
- package/esm/openxml/word/drawing/Pic.d.ts +8 -0
- package/esm/openxml/word/drawing/Pic.js +16 -0
- package/esm/openxml/word/drawing/ShapeProperties.d.ts +9 -0
- package/esm/openxml/word/drawing/ShapeProperties.js +20 -0
- package/esm/openxml/word/drawing/Transform.d.ts +17 -0
- package/esm/openxml/word/drawing/Transform.js +30 -0
- package/esm/openxml/word/numbering/AbstractNum.d.ts +13 -0
- package/esm/openxml/word/numbering/AbstractNum.js +42 -0
- package/esm/openxml/word/numbering/Lvl.d.ts +16 -0
- package/esm/openxml/word/numbering/Lvl.js +62 -0
- package/esm/openxml/word/numbering/Num.d.ts +10 -0
- package/esm/openxml/word/numbering/Num.js +46 -0
- package/esm/openxml/word/numbering/NumberProperties.d.ts +6 -0
- package/esm/openxml/word/numbering/NumberProperties.js +21 -0
- package/esm/openxml/word/numbering/Numbering.d.ts +9 -0
- package/esm/openxml/word/numbering/Numbering.js +50 -0
- package/esm/openxml/word/properties/Properties.d.ts +12 -0
- package/esm/openxml/word/table/Tc.d.ts +46 -0
- package/esm/openxml/word/table/Tc.js +234 -0
- package/esm/openxml/word/table/Tr.d.ts +18 -0
- package/esm/openxml/word/table/Tr.js +106 -0
- package/esm/package/PackageParser.d.ts +26 -0
- package/esm/package/XMLPackageParser.d.ts +31 -0
- package/esm/package/ZipPackageParser.d.ts +29 -0
- package/esm/package/ZipPackageParser.js +70 -0
- package/esm/parse/jcToTextAlign.d.ts +5 -0
- package/esm/parse/jcToTextAlign.js +21 -0
- package/esm/parse/parseBorder.d.ts +13 -0
- package/esm/parse/parseBorder.js +78 -0
- package/esm/parse/parseColor.d.ts +22 -0
- package/esm/parse/parseColor.js +131 -0
- package/esm/parse/parseFont.d.ts +7 -0
- package/esm/parse/parseFont.js +54 -0
- package/esm/parse/parseInd.d.ts +5 -0
- package/esm/parse/parseInd.js +27 -0
- package/esm/parse/parsePr.d.ts +8 -0
- package/esm/parse/parsePr.js +325 -0
- package/esm/parse/parseRelationship.d.ts +12 -0
- package/esm/parse/parseRelationship.js +40 -0
- package/esm/parse/parseSize.d.ts +27 -0
- package/esm/parse/parseSize.js +38 -0
- package/esm/parse/parseSpacing.d.ts +7 -0
- package/esm/parse/parseSpacing.js +43 -0
- package/esm/parse/parseTextDirection.d.ts +2 -0
- package/esm/parse/parseTextDirection.js +25 -0
- package/esm/parse/parseTrHeight.d.ts +2 -0
- package/esm/parse/parseTrHeight.js +17 -0
- package/esm/render/renderBody.d.ts +6 -0
- package/esm/render/renderBody.js +53 -0
- package/esm/render/renderBookmark.d.ts +6 -0
- package/esm/render/renderBookmark.js +17 -0
- package/esm/render/renderBr.d.ts +7 -0
- package/esm/render/renderBr.js +13 -0
- package/esm/render/renderDocument.d.ts +7 -0
- package/esm/render/renderDocument.js +14 -0
- package/esm/render/renderDrawing.d.ts +8 -0
- package/esm/render/renderDrawing.js +38 -0
- package/esm/render/renderHyperLink.d.ts +7 -0
- package/esm/render/renderHyperLink.js +41 -0
- package/esm/render/renderInlineText.d.ts +6 -0
- package/esm/render/renderInlineText.js +39 -0
- package/esm/render/renderInstrText.d.ts +8 -0
- package/esm/render/renderInstrText.js +40 -0
- package/esm/render/renderNumbering.d.ts +7 -0
- package/esm/render/renderNumbering.js +161 -0
- package/esm/render/renderParagraph.d.ts +7 -0
- package/esm/render/renderParagraph.js +78 -0
- package/esm/render/renderPict.d.ts +6 -0
- package/esm/render/renderPict.js +19 -0
- package/esm/render/renderRuby.d.ts +6 -0
- package/esm/render/renderRuby.js +53 -0
- package/esm/render/renderRun.d.ts +14 -0
- package/esm/render/renderRun.js +116 -0
- package/esm/render/renderSection.d.ts +6 -0
- package/esm/render/renderSection.js +36 -0
- package/esm/render/renderStyle.d.ts +13 -0
- package/esm/render/renderStyle.js +194 -0
- package/esm/render/renderSym.d.ts +3 -0
- package/esm/render/renderSym.js +10 -0
- package/esm/render/renderTab.d.ts +7 -0
- package/esm/render/renderTab.js +19 -0
- package/esm/render/renderTable.d.ts +6 -0
- package/esm/render/renderTable.js +186 -0
- package/esm/render/setElementStyle.d.ts +6 -0
- package/esm/render/setElementStyle.js +21 -0
- package/esm/util/autoSpace.d.ts +5 -0
- package/esm/util/autoSpace.js +33 -0
- package/esm/util/blob.d.ts +9 -0
- package/esm/util/blob.js +39 -0
- package/esm/util/dom.d.ts +36 -0
- package/esm/util/dom.js +63 -0
- package/esm/util/mergeRun.d.ts +17 -0
- package/esm/util/mergeRun.js +134 -0
- package/esm/util/xml.d.ts +8 -0
- package/esm/util/xml.js +12 -0
- package/lib/OpenXML.d.ts +21 -0
- package/lib/OpenXML.js +69 -0
- package/lib/Word.d.ts +208 -0
- package/lib/Word.js +374 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +10 -0
- package/lib/node_modules/tslib/tslib.es6.js +129 -0
- package/lib/openxml/ContentType.d.ts +12 -0
- package/lib/openxml/ContentType.js +19 -0
- package/lib/openxml/Style.d.ts +41 -0
- package/lib/openxml/Style.js +160 -0
- package/lib/openxml/Theme.d.ts +26 -0
- package/lib/openxml/Theme.js +73 -0
- package/lib/openxml/Types.d.ts +2512 -0
- package/lib/openxml/Types.js +1005 -0
- package/lib/openxml/word/Background.d.ts +11 -0
- package/lib/openxml/word/Body.d.ts +18 -0
- package/lib/openxml/word/Body.js +71 -0
- package/lib/openxml/word/Bookmark.d.ts +6 -0
- package/lib/openxml/word/Bookmark.js +22 -0
- package/lib/openxml/word/Border.d.ts +10 -0
- package/lib/openxml/word/Break.d.ts +13 -0
- package/lib/openxml/word/Break.js +23 -0
- package/lib/openxml/word/CustomXml.d.ts +8 -0
- package/lib/openxml/word/FldSimple.d.ts +7 -0
- package/lib/openxml/word/FldSimple.js +19 -0
- package/lib/openxml/word/FrameProperties.d.ts +18 -0
- package/lib/openxml/word/Hyperlink.d.ts +13 -0
- package/lib/openxml/word/Hyperlink.js +57 -0
- package/lib/openxml/word/Indent.d.ts +8 -0
- package/lib/openxml/word/InlineText.d.ts +14 -0
- package/lib/openxml/word/InlineText.js +66 -0
- package/lib/openxml/word/InstrText.d.ts +4 -0
- package/lib/openxml/word/InstrText.js +12 -0
- package/lib/openxml/word/Paragraph.d.ts +34 -0
- package/lib/openxml/word/Paragraph.js +137 -0
- package/lib/openxml/word/Pict.d.ts +6 -0
- package/lib/openxml/word/Pict.js +23 -0
- package/lib/openxml/word/Ruby.d.ts +20 -0
- package/lib/openxml/word/Ruby.js +91 -0
- package/lib/openxml/word/Run.d.ts +31 -0
- package/lib/openxml/word/Run.js +103 -0
- package/lib/openxml/word/Section.d.ts +38 -0
- package/lib/openxml/word/Section.js +63 -0
- package/lib/openxml/word/Shading.d.ts +9 -0
- package/lib/openxml/word/SmartTag.d.ts +8 -0
- package/lib/openxml/word/SmartTag.js +22 -0
- package/lib/openxml/word/Spacing.d.ts +9 -0
- package/lib/openxml/word/Sym.d.ts +8 -0
- package/lib/openxml/word/Sym.js +20 -0
- package/lib/openxml/word/Tab.d.ts +8 -0
- package/lib/openxml/word/Tab.js +21 -0
- package/lib/openxml/word/Table.d.ts +49 -0
- package/lib/openxml/word/Table.js +252 -0
- package/lib/openxml/word/VerticalAlign.d.ts +6 -0
- package/lib/openxml/word/WDocument.d.ts +13 -0
- package/lib/openxml/word/WDocument.js +62 -0
- package/lib/openxml/word/drawing/Blip.d.ts +6 -0
- package/lib/openxml/word/drawing/Blip.js +21 -0
- package/lib/openxml/word/drawing/BlipFill.d.ts +9 -0
- package/lib/openxml/word/drawing/BlipFill.js +24 -0
- package/lib/openxml/word/drawing/Drawing.d.ts +6 -0
- package/lib/openxml/word/drawing/Drawing.js +19 -0
- package/lib/openxml/word/drawing/Pic.d.ts +8 -0
- package/lib/openxml/word/drawing/Pic.js +20 -0
- package/lib/openxml/word/drawing/ShapeProperties.d.ts +9 -0
- package/lib/openxml/word/drawing/ShapeProperties.js +24 -0
- package/lib/openxml/word/drawing/Transform.d.ts +17 -0
- package/lib/openxml/word/drawing/Transform.js +34 -0
- package/lib/openxml/word/numbering/AbstractNum.d.ts +13 -0
- package/lib/openxml/word/numbering/AbstractNum.js +46 -0
- package/lib/openxml/word/numbering/Lvl.d.ts +16 -0
- package/lib/openxml/word/numbering/Lvl.js +66 -0
- package/lib/openxml/word/numbering/Num.d.ts +10 -0
- package/lib/openxml/word/numbering/Num.js +50 -0
- package/lib/openxml/word/numbering/NumberProperties.d.ts +6 -0
- package/lib/openxml/word/numbering/NumberProperties.js +25 -0
- package/lib/openxml/word/numbering/Numbering.d.ts +9 -0
- package/lib/openxml/word/numbering/Numbering.js +54 -0
- package/lib/openxml/word/properties/Properties.d.ts +12 -0
- package/lib/openxml/word/table/Tc.d.ts +46 -0
- package/lib/openxml/word/table/Tc.js +242 -0
- package/lib/openxml/word/table/Tr.d.ts +18 -0
- package/lib/openxml/word/table/Tr.js +110 -0
- package/lib/package/PackageParser.d.ts +26 -0
- package/lib/package/XMLPackageParser.d.ts +31 -0
- package/lib/package/ZipPackageParser.d.ts +29 -0
- package/lib/package/ZipPackageParser.js +74 -0
- package/lib/parse/jcToTextAlign.d.ts +5 -0
- package/lib/parse/jcToTextAlign.js +25 -0
- package/lib/parse/parseBorder.d.ts +13 -0
- package/lib/parse/parseBorder.js +83 -0
- package/lib/parse/parseColor.d.ts +22 -0
- package/lib/parse/parseColor.js +137 -0
- package/lib/parse/parseFont.d.ts +7 -0
- package/lib/parse/parseFont.js +58 -0
- package/lib/parse/parseInd.d.ts +5 -0
- package/lib/parse/parseInd.js +31 -0
- package/lib/parse/parsePr.d.ts +8 -0
- package/lib/parse/parsePr.js +329 -0
- package/lib/parse/parseRelationship.d.ts +12 -0
- package/lib/parse/parseRelationship.js +45 -0
- package/lib/parse/parseSize.d.ts +27 -0
- package/lib/parse/parseSize.js +44 -0
- package/lib/parse/parseSpacing.d.ts +7 -0
- package/lib/parse/parseSpacing.js +47 -0
- package/lib/parse/parseTextDirection.d.ts +2 -0
- package/lib/parse/parseTextDirection.js +29 -0
- package/lib/parse/parseTrHeight.d.ts +2 -0
- package/lib/parse/parseTrHeight.js +21 -0
- package/lib/render/renderBody.d.ts +6 -0
- package/lib/render/renderBody.js +57 -0
- package/lib/render/renderBookmark.d.ts +6 -0
- package/lib/render/renderBookmark.js +21 -0
- package/lib/render/renderBr.d.ts +7 -0
- package/lib/render/renderBr.js +17 -0
- package/lib/render/renderDocument.d.ts +7 -0
- package/lib/render/renderDocument.js +18 -0
- package/lib/render/renderDrawing.d.ts +8 -0
- package/lib/render/renderDrawing.js +42 -0
- package/lib/render/renderHyperLink.d.ts +7 -0
- package/lib/render/renderHyperLink.js +45 -0
- package/lib/render/renderInlineText.d.ts +6 -0
- package/lib/render/renderInlineText.js +43 -0
- package/lib/render/renderInstrText.d.ts +8 -0
- package/lib/render/renderInstrText.js +44 -0
- package/lib/render/renderNumbering.d.ts +7 -0
- package/lib/render/renderNumbering.js +165 -0
- package/lib/render/renderParagraph.d.ts +7 -0
- package/lib/render/renderParagraph.js +82 -0
- package/lib/render/renderPict.d.ts +6 -0
- package/lib/render/renderPict.js +23 -0
- package/lib/render/renderRuby.d.ts +6 -0
- package/lib/render/renderRuby.js +57 -0
- package/lib/render/renderRun.d.ts +14 -0
- package/lib/render/renderRun.js +121 -0
- package/lib/render/renderSection.d.ts +6 -0
- package/lib/render/renderSection.js +40 -0
- package/lib/render/renderStyle.d.ts +13 -0
- package/lib/render/renderStyle.js +199 -0
- package/lib/render/renderSym.d.ts +3 -0
- package/lib/render/renderSym.js +14 -0
- package/lib/render/renderTab.d.ts +7 -0
- package/lib/render/renderTab.js +23 -0
- package/lib/render/renderTable.d.ts +6 -0
- package/lib/render/renderTable.js +190 -0
- package/lib/render/setElementStyle.d.ts +6 -0
- package/lib/render/setElementStyle.js +25 -0
- package/lib/util/autoSpace.d.ts +5 -0
- package/lib/util/autoSpace.js +37 -0
- package/lib/util/blob.d.ts +9 -0
- package/lib/util/blob.js +44 -0
- package/lib/util/dom.d.ts +36 -0
- package/lib/util/dom.js +72 -0
- package/lib/util/mergeRun.d.ts +17 -0
- package/lib/util/mergeRun.js +140 -0
- package/lib/util/xml.d.ts +8 -0
- package/lib/util/xml.js +16 -0
- package/package.json +91 -0
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
|
|
6
|
+
var renderBr = require('./renderBr.js');
|
|
7
|
+
var dom = require('../util/dom.js');
|
|
8
|
+
var Run = require('../openxml/word/Run.js');
|
|
9
|
+
var Break = require('../openxml/word/Break.js');
|
|
10
|
+
var Drawing = require('../openxml/word/drawing/Drawing.js');
|
|
11
|
+
var renderDrawing = require('./renderDrawing.js');
|
|
12
|
+
var setElementStyle = require('./setElementStyle.js');
|
|
13
|
+
var Tab = require('../openxml/word/Tab.js');
|
|
14
|
+
var renderTab = require('./renderTab.js');
|
|
15
|
+
var renderPict = require('./renderPict.js');
|
|
16
|
+
var Pict = require('../openxml/word/Pict.js');
|
|
17
|
+
var Ruby = require('../openxml/word/Ruby.js');
|
|
18
|
+
var renderRuby = require('./renderRuby.js');
|
|
19
|
+
var InstrText = require('../openxml/word/InstrText.js');
|
|
20
|
+
var renderInstrText = require('./renderInstrText.js');
|
|
21
|
+
var Sym = require('../openxml/word/Sym.js');
|
|
22
|
+
var renderSym = require('./renderSym.js');
|
|
23
|
+
var autoSpace = require('../util/autoSpace.js');
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* run 相关的 http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/Run_1.html
|
|
27
|
+
*/
|
|
28
|
+
var VARIABLE_CLASS_NAME = 'variable';
|
|
29
|
+
/**
|
|
30
|
+
* 对文本进行替换
|
|
31
|
+
*/
|
|
32
|
+
function renderText(span, word, text, paragraph) {
|
|
33
|
+
var _a;
|
|
34
|
+
// 简单过滤一下提升性能
|
|
35
|
+
if (text.indexOf('{{') === -1) {
|
|
36
|
+
if ((_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.properties) === null || _a === void 0 ? void 0 : _a.autoSpace) {
|
|
37
|
+
span.textContent = autoSpace.cjkspace(text.split(''));
|
|
38
|
+
}
|
|
39
|
+
else {
|
|
40
|
+
span.textContent = text;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
span.dataset.originText = text;
|
|
45
|
+
// 加个标识,后续可以通过它来查找哪些变量需要替换,这样就不用重新渲染整个文档了
|
|
46
|
+
span.classList.add(VARIABLE_CLASS_NAME);
|
|
47
|
+
span.textContent = word.replaceText(text);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 更新文档里的所有变量
|
|
52
|
+
*/
|
|
53
|
+
function updateVariableText(word) {
|
|
54
|
+
var spans = word.rootElement.querySelectorAll(".".concat(VARIABLE_CLASS_NAME));
|
|
55
|
+
for (var i = 0; i < spans.length; i++) {
|
|
56
|
+
var span = spans[i];
|
|
57
|
+
var text = span.dataset.originText || '';
|
|
58
|
+
span.textContent = word.replaceText(text);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* 渲染 run 节点
|
|
63
|
+
*/
|
|
64
|
+
function renderRun(word, run, paragraph) {
|
|
65
|
+
var e_1, _a;
|
|
66
|
+
var span = dom.createElement('span');
|
|
67
|
+
word.addClass(span, 'r');
|
|
68
|
+
setElementStyle.setElementStyle(word, span, run.properties);
|
|
69
|
+
if (run.children.length === 1 && run.children[0] instanceof Run.Text) {
|
|
70
|
+
var text = run.children[0];
|
|
71
|
+
renderText(span, word, text.text, paragraph);
|
|
72
|
+
}
|
|
73
|
+
else {
|
|
74
|
+
try {
|
|
75
|
+
for (var _b = tslib_es6.__values(run.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
76
|
+
var child = _c.value;
|
|
77
|
+
if (child instanceof Run.Text) {
|
|
78
|
+
var newSpan = dom.createElement('span');
|
|
79
|
+
renderText(span, word, child.text, paragraph);
|
|
80
|
+
dom.appendChild(span, newSpan);
|
|
81
|
+
}
|
|
82
|
+
else if (child instanceof Break.Break) {
|
|
83
|
+
var br = renderBr.renderBr(child);
|
|
84
|
+
dom.appendChild(span, br);
|
|
85
|
+
}
|
|
86
|
+
else if (child instanceof Drawing.Drawing) {
|
|
87
|
+
dom.appendChild(span, renderDrawing.renderDrawing(word, child));
|
|
88
|
+
}
|
|
89
|
+
else if (child instanceof Tab.Tab) {
|
|
90
|
+
dom.appendChild(span, renderTab.renderTab(word, child));
|
|
91
|
+
}
|
|
92
|
+
else if (child instanceof Pict.Pict) {
|
|
93
|
+
dom.appendChild(span, renderPict.renderPict(word, child));
|
|
94
|
+
}
|
|
95
|
+
else if (child instanceof Ruby.Ruby) {
|
|
96
|
+
dom.appendChild(span, renderRuby.renderRuby(word, child));
|
|
97
|
+
}
|
|
98
|
+
else if (child instanceof InstrText.InstrText) {
|
|
99
|
+
dom.appendChild(span, renderInstrText.renderInstrText(word, child));
|
|
100
|
+
}
|
|
101
|
+
else if (child instanceof Sym.Sym) {
|
|
102
|
+
dom.appendChild(span, renderSym.renderSym(word, child));
|
|
103
|
+
}
|
|
104
|
+
else {
|
|
105
|
+
console.warn('unknown child', child);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
110
|
+
finally {
|
|
111
|
+
try {
|
|
112
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
113
|
+
}
|
|
114
|
+
finally { if (e_1) throw e_1.error; }
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return span;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
exports["default"] = renderRun;
|
|
121
|
+
exports.updateVariableText = updateVariableText;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dom = require('../util/dom.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 渲染「节」,在 word 中每个节都可以有自己的页边距和页面大小设置,但目前其实并没有实现分页展现,等后续再考虑
|
|
9
|
+
*/
|
|
10
|
+
function renderSection(word, section) {
|
|
11
|
+
var sectionEl = dom.createElement('section');
|
|
12
|
+
// 用于后续绝对定位
|
|
13
|
+
sectionEl.style.position = 'relative';
|
|
14
|
+
var props = section.properties;
|
|
15
|
+
var pageSize = props.pageSize;
|
|
16
|
+
if (pageSize) {
|
|
17
|
+
if (!word.renderOptions.ignoreWidth) {
|
|
18
|
+
sectionEl.style.width = pageSize.width;
|
|
19
|
+
}
|
|
20
|
+
if (!word.renderOptions.ignoreHeight) {
|
|
21
|
+
sectionEl.style.height = pageSize.height;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
// 强制控制 padding
|
|
25
|
+
if (word.renderOptions.padding) {
|
|
26
|
+
sectionEl.style.padding = word.renderOptions.padding;
|
|
27
|
+
}
|
|
28
|
+
else {
|
|
29
|
+
var pageMargin = props.pageMargin;
|
|
30
|
+
if (pageMargin) {
|
|
31
|
+
sectionEl.style.paddingLeft = pageMargin.left || '0';
|
|
32
|
+
sectionEl.style.paddingRight = pageMargin.right || '0';
|
|
33
|
+
sectionEl.style.paddingTop = pageMargin.top || '0';
|
|
34
|
+
sectionEl.style.paddingBottom = pageMargin.bottom || '0';
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return sectionEl;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
exports.renderSection = renderSection;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 渲染内置样式及自定义样式
|
|
3
|
+
*/
|
|
4
|
+
import { TblStylePrStyle } from '../openxml/Style';
|
|
5
|
+
import Word from '../Word';
|
|
6
|
+
/**
|
|
7
|
+
* 生成表格级别样式
|
|
8
|
+
*/
|
|
9
|
+
export declare function generateTableStyle(classPrefix: string, styleDisplayId: string, style: TblStylePrStyle): string;
|
|
10
|
+
/**
|
|
11
|
+
* 渲染所有样式
|
|
12
|
+
*/
|
|
13
|
+
export declare function renderStyle(word: Word): HTMLStyleElement;
|
|
@@ -0,0 +1,199 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
|
|
6
|
+
var Types = require('../openxml/Types.js');
|
|
7
|
+
var dom = require('../util/dom.js');
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* 渲染内置样式及自定义样式
|
|
11
|
+
*/
|
|
12
|
+
/**
|
|
13
|
+
* 文档基础默认样式
|
|
14
|
+
*/
|
|
15
|
+
function generateDefaultStyle(word) {
|
|
16
|
+
var styles = word.styles;
|
|
17
|
+
var defaultStyle = styles.defaultStyle;
|
|
18
|
+
var defaultPStyle = '';
|
|
19
|
+
if (defaultStyle === null || defaultStyle === void 0 ? void 0 : defaultStyle.pPr) {
|
|
20
|
+
defaultPStyle = dom.styleToText(defaultStyle.pPr.cssStyle);
|
|
21
|
+
}
|
|
22
|
+
var defaultRStyle = '';
|
|
23
|
+
if (defaultStyle === null || defaultStyle === void 0 ? void 0 : defaultStyle.rPr) {
|
|
24
|
+
defaultRStyle = dom.styleToText(defaultStyle.rPr.cssStyle);
|
|
25
|
+
}
|
|
26
|
+
var classPrefix = word.getClassPrefix();
|
|
27
|
+
return "\n .".concat(word.wrapClassName, " {\n\n }\n\n .").concat(word.wrapClassName, " > article > section {\n background: white;\n }\n\n /** docDefaults **/\n\n .").concat(classPrefix, " p {\n margin: 0;\n padding: 0;\n }\n\n .").concat(classPrefix, " table {\n border-spacing: 0;\n }\n\n .").concat(classPrefix, " .").concat(classPrefix, "-p {\n ").concat(defaultPStyle, "\n }\n\n .").concat(classPrefix, " .").concat(classPrefix, "-r {\n white-space: pre-wrap;\n overflow-wrap: break-word;\n ").concat(defaultRStyle, "\n }\n ");
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* 生成表格级别样式
|
|
31
|
+
*/
|
|
32
|
+
function generateTableStyle(classPrefix, styleDisplayId, style) {
|
|
33
|
+
var tblStyleText = '';
|
|
34
|
+
var tblPr = style.tblPr;
|
|
35
|
+
var tcPr = style.tcPr;
|
|
36
|
+
if (tblPr) {
|
|
37
|
+
var tblStyle = dom.styleToText(tblPr.cssStyle);
|
|
38
|
+
var tblTcStyle = dom.styleToText(tblPr.tcCSSStyle);
|
|
39
|
+
tblStyleText += "\n .".concat(classPrefix, " .").concat(styleDisplayId, " {\n border-collapse: collapse;\n ").concat(tblStyle, "\n }\n\n .").concat(classPrefix, " .").concat(styleDisplayId, " > tbody > tr > td {\n ").concat(tblTcStyle, "\n }\n ");
|
|
40
|
+
if (tblPr.insideBorder) {
|
|
41
|
+
var insideBorder = tblPr.insideBorder;
|
|
42
|
+
if (insideBorder.H) {
|
|
43
|
+
tblStyleText += "\n .".concat(classPrefix, " .").concat(styleDisplayId, " > tbody > tr > td {\n border-top: ").concat(insideBorder.H, ";\n }");
|
|
44
|
+
}
|
|
45
|
+
if (insideBorder.V) {
|
|
46
|
+
tblStyleText += "\n .".concat(classPrefix, " .").concat(styleDisplayId, " > tbody > tr > td {\n border-left: ").concat(insideBorder.V, ";\n }");
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
if (tcPr) {
|
|
51
|
+
var tcStyle = dom.styleToText(tcPr.cssStyle);
|
|
52
|
+
tblStyleText += "\n .".concat(classPrefix, " .").concat(styleDisplayId, " > tbody > tr > td {\n ").concat(tcStyle, "\n }\n ");
|
|
53
|
+
}
|
|
54
|
+
return tblStyleText;
|
|
55
|
+
}
|
|
56
|
+
// 用于生成表格 override 相关的样式,用于行或列
|
|
57
|
+
function genTblOverrideStyle(prefix, overrideType, tblStylePrStyle) {
|
|
58
|
+
var _a, _b, _c, _d, _e, _f;
|
|
59
|
+
var styleText = '';
|
|
60
|
+
var trStyle = dom.styleToText((_a = tblStylePrStyle.trPr) === null || _a === void 0 ? void 0 : _a.cssStyle);
|
|
61
|
+
var enableType = '';
|
|
62
|
+
// 在 tblLook 里可以通过这些属性来控制是否启用
|
|
63
|
+
switch (overrideType) {
|
|
64
|
+
case Types.ST_TblStyleOverrideType.firstCol:
|
|
65
|
+
enableType = 'enable-firstColumn';
|
|
66
|
+
break;
|
|
67
|
+
case Types.ST_TblStyleOverrideType.lastCol:
|
|
68
|
+
enableType = 'enable-lastColumn';
|
|
69
|
+
break;
|
|
70
|
+
case Types.ST_TblStyleOverrideType.firstRow:
|
|
71
|
+
enableType = 'enable-firstRow';
|
|
72
|
+
break;
|
|
73
|
+
case Types.ST_TblStyleOverrideType.lastRow:
|
|
74
|
+
enableType = 'enable-lastRow';
|
|
75
|
+
break;
|
|
76
|
+
case Types.ST_TblStyleOverrideType.band1Horz:
|
|
77
|
+
case Types.ST_TblStyleOverrideType.band2Horz:
|
|
78
|
+
enableType = 'enable-hBand';
|
|
79
|
+
break;
|
|
80
|
+
case Types.ST_TblStyleOverrideType.band1Vert:
|
|
81
|
+
case Types.ST_TblStyleOverrideType.band2Vert:
|
|
82
|
+
enableType = 'enable-vBand';
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
if (trStyle) {
|
|
86
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr.").concat(overrideType, "{\n ").concat(trStyle, "\n }\n ");
|
|
87
|
+
}
|
|
88
|
+
var tcStyle = dom.styleToText((_b = tblStylePrStyle.tcPr) === null || _b === void 0 ? void 0 : _b.cssStyle);
|
|
89
|
+
if (tcStyle) {
|
|
90
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " {\n ").concat(tcStyle, "\n }\n ");
|
|
91
|
+
if ((_c = tblStylePrStyle.tcPr) === null || _c === void 0 ? void 0 : _c.insideBorder) {
|
|
92
|
+
var insideBorder = (_d = tblStylePrStyle.tcPr) === null || _d === void 0 ? void 0 : _d.insideBorder;
|
|
93
|
+
if (insideBorder.H) {
|
|
94
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " {\n border-top: ").concat(insideBorder.H, ";\n }");
|
|
95
|
+
}
|
|
96
|
+
if (insideBorder.V) {
|
|
97
|
+
// 这个主要是为了应对 GridTable5Dark-Accent5 里 firstRow 的情况,它其实有 right 设置,也得去掉
|
|
98
|
+
if (insideBorder.V === 'none') {
|
|
99
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " {\n border-left: none;\n border-right: none;\n }");
|
|
100
|
+
}
|
|
101
|
+
else {
|
|
102
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " {\n border-left: ").concat(insideBorder.V, ";\n }");
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
var pStyle = dom.styleToText((_e = tblStylePrStyle.pPr) === null || _e === void 0 ? void 0 : _e.cssStyle);
|
|
108
|
+
if (pStyle) {
|
|
109
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " > .p {\n ").concat(pStyle, "\n }\n ");
|
|
110
|
+
}
|
|
111
|
+
var rStyle = dom.styleToText((_f = tblStylePrStyle.rPr) === null || _f === void 0 ? void 0 : _f.cssStyle);
|
|
112
|
+
if (rStyle) {
|
|
113
|
+
styleText += "\n ".concat(prefix, ".").concat(enableType, " > tbody > tr > td.").concat(overrideType, " > .p > .r {\n ").concat(rStyle, "\n }\n ");
|
|
114
|
+
}
|
|
115
|
+
return styleText;
|
|
116
|
+
}
|
|
117
|
+
// 表格覆盖样式的顺序,权重高的放后面
|
|
118
|
+
var overrideTypeOrder = new Set([
|
|
119
|
+
Types.ST_TblStyleOverrideType.wholeTable,
|
|
120
|
+
Types.ST_TblStyleOverrideType.band1Horz,
|
|
121
|
+
Types.ST_TblStyleOverrideType.band2Horz,
|
|
122
|
+
Types.ST_TblStyleOverrideType.band1Vert,
|
|
123
|
+
Types.ST_TblStyleOverrideType.band2Vert,
|
|
124
|
+
Types.ST_TblStyleOverrideType.firstCol,
|
|
125
|
+
Types.ST_TblStyleOverrideType.firstRow,
|
|
126
|
+
Types.ST_TblStyleOverrideType.lastCol,
|
|
127
|
+
Types.ST_TblStyleOverrideType.lastRow,
|
|
128
|
+
Types.ST_TblStyleOverrideType.neCell,
|
|
129
|
+
Types.ST_TblStyleOverrideType.nwCell,
|
|
130
|
+
Types.ST_TblStyleOverrideType.seCell,
|
|
131
|
+
Types.ST_TblStyleOverrideType.swCell
|
|
132
|
+
]);
|
|
133
|
+
// 生成表格覆盖样式
|
|
134
|
+
function genOverrideTblStylePr(classPrefix, styleDisplayId, tblStylePr) {
|
|
135
|
+
var e_1, _a;
|
|
136
|
+
if (!tblStylePr) {
|
|
137
|
+
return '';
|
|
138
|
+
}
|
|
139
|
+
var tblStylePrText = '';
|
|
140
|
+
var stylePrefix = ".".concat(classPrefix, " .").concat(styleDisplayId);
|
|
141
|
+
try {
|
|
142
|
+
for (var overrideTypeOrder_1 = tslib_es6.__values(overrideTypeOrder), overrideTypeOrder_1_1 = overrideTypeOrder_1.next(); !overrideTypeOrder_1_1.done; overrideTypeOrder_1_1 = overrideTypeOrder_1.next()) {
|
|
143
|
+
var overrideType = overrideTypeOrder_1_1.value;
|
|
144
|
+
if (overrideType in tblStylePr) {
|
|
145
|
+
var overrideStylePr = tblStylePr[overrideType];
|
|
146
|
+
tblStylePrText += genTblOverrideStyle(stylePrefix, overrideType, overrideStylePr);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
151
|
+
finally {
|
|
152
|
+
try {
|
|
153
|
+
if (overrideTypeOrder_1_1 && !overrideTypeOrder_1_1.done && (_a = overrideTypeOrder_1.return)) _a.call(overrideTypeOrder_1);
|
|
154
|
+
}
|
|
155
|
+
finally { if (e_1) throw e_1.error; }
|
|
156
|
+
}
|
|
157
|
+
return tblStylePrText;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* 生成样式类
|
|
161
|
+
*/
|
|
162
|
+
function generateStyle(word) {
|
|
163
|
+
var styles = word.styles;
|
|
164
|
+
var styleMap = styles.styleMap;
|
|
165
|
+
var classPrefix = word.getClassPrefix();
|
|
166
|
+
var styleResult = '';
|
|
167
|
+
for (var styleId in styleMap) {
|
|
168
|
+
var styleDisplayId = word.getStyleIdDisplayName(styleId);
|
|
169
|
+
var styleData = styleMap[styleId];
|
|
170
|
+
var pPr = styleData.pPr;
|
|
171
|
+
var pStyleText = '';
|
|
172
|
+
if (pPr) {
|
|
173
|
+
var pStyle = dom.styleToText(pPr.cssStyle);
|
|
174
|
+
pStyleText = "\n .".concat(classPrefix, " .").concat(styleDisplayId, " {\n ").concat(pStyle, "\n }\n ");
|
|
175
|
+
}
|
|
176
|
+
var rStyleText = '';
|
|
177
|
+
if (styleData.rPr) {
|
|
178
|
+
var rStyle = dom.styleToText(styleData.rPr.cssStyle);
|
|
179
|
+
rStyleText = "\n .".concat(classPrefix, " .").concat(styleDisplayId, " > .r {\n ").concat(rStyle, "\n }\n ");
|
|
180
|
+
}
|
|
181
|
+
var tblStyleText = generateTableStyle(classPrefix, styleDisplayId, styleData);
|
|
182
|
+
var tblStylePr = genOverrideTblStylePr(classPrefix, styleDisplayId, styleData.tblStylePr);
|
|
183
|
+
styleResult += "\n ".concat(pStyleText, "\n ").concat(rStyleText, "\n ").concat(tblStyleText, "\n ").concat(tblStylePr, "\n ");
|
|
184
|
+
}
|
|
185
|
+
return styleResult;
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* 渲染所有样式
|
|
189
|
+
*/
|
|
190
|
+
function renderStyle(word) {
|
|
191
|
+
var style = dom.createElement('style');
|
|
192
|
+
var docDefaults = generateDefaultStyle(word);
|
|
193
|
+
var styleText = generateStyle(word);
|
|
194
|
+
style.innerHTML = "\n ".concat(docDefaults, "\n\n ").concat(styleText, "\n ");
|
|
195
|
+
return style;
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
exports.generateTableStyle = generateTableStyle;
|
|
199
|
+
exports.renderStyle = renderStyle;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dom = require('../util/dom.js');
|
|
6
|
+
|
|
7
|
+
function renderSym(word, sym) {
|
|
8
|
+
var span = dom.createElement('span');
|
|
9
|
+
span.style.fontFamily = sym.font;
|
|
10
|
+
span.innerHTML = "&#x".concat(sym.char, ";");
|
|
11
|
+
return span;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
exports.renderSym = renderSym;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var Types = require('../openxml/Types.js');
|
|
6
|
+
var dom = require('../util/dom.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 渲染 tab
|
|
10
|
+
* http://officeopenxml.com/WPtab.php
|
|
11
|
+
*/
|
|
12
|
+
function renderTab(word, tab) {
|
|
13
|
+
var tabElement = dom.createElement('span');
|
|
14
|
+
tabElement.style.display = 'inline-block';
|
|
15
|
+
tabElement.style.width = tab.pos;
|
|
16
|
+
tabElement.innerHTML = ' ';
|
|
17
|
+
if (tab.leader === Types.ST_TabTlc.dot) {
|
|
18
|
+
tabElement.style.borderBottom = '1px dotted';
|
|
19
|
+
}
|
|
20
|
+
return tabElement;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.renderTab = renderTab;
|
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
|
|
6
|
+
var Types = require('../openxml/Types.js');
|
|
7
|
+
var Paragraph = require('../openxml/word/Paragraph.js');
|
|
8
|
+
var Table = require('../openxml/word/Table.js');
|
|
9
|
+
var dom = require('../util/dom.js');
|
|
10
|
+
var renderParagraph = require('./renderParagraph.js');
|
|
11
|
+
var renderStyle = require('./renderStyle.js');
|
|
12
|
+
var setElementStyle = require('./setElementStyle.js');
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* 设置 td 的类,用于支持各种表格条件样式
|
|
16
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_TblStyleOverrideType.html
|
|
17
|
+
*/
|
|
18
|
+
function setTdClassName(rowIndex, colIndex, rowLength, colLength, element, rowBandSize, colBandSize) {
|
|
19
|
+
// 左上角
|
|
20
|
+
if (rowIndex === 0 && colIndex === 0) {
|
|
21
|
+
element.classList.add(Types.ST_TblStyleOverrideType.nwCell);
|
|
22
|
+
}
|
|
23
|
+
// 右上角
|
|
24
|
+
if (rowIndex === 0 && colIndex === colLength - 1) {
|
|
25
|
+
element.classList.add(Types.ST_TblStyleOverrideType.neCell);
|
|
26
|
+
}
|
|
27
|
+
// 左下角
|
|
28
|
+
if (rowIndex === rowLength - 1 && colIndex === 0) {
|
|
29
|
+
element.classList.add(Types.ST_TblStyleOverrideType.swCell);
|
|
30
|
+
}
|
|
31
|
+
// 右下角
|
|
32
|
+
if (rowIndex === rowLength - 1 && colIndex === colLength - 1) {
|
|
33
|
+
element.classList.add(Types.ST_TblStyleOverrideType.seCell);
|
|
34
|
+
}
|
|
35
|
+
// 第一行
|
|
36
|
+
if (rowIndex === 0) {
|
|
37
|
+
element.classList.add(Types.ST_TblStyleOverrideType.firstRow);
|
|
38
|
+
}
|
|
39
|
+
// 最后一行
|
|
40
|
+
if (rowIndex === rowLength - 1) {
|
|
41
|
+
element.classList.add(Types.ST_TblStyleOverrideType.lastRow);
|
|
42
|
+
}
|
|
43
|
+
// 第一列
|
|
44
|
+
if (colIndex === 0) {
|
|
45
|
+
element.classList.add(Types.ST_TblStyleOverrideType.firstCol);
|
|
46
|
+
}
|
|
47
|
+
// 最后一列
|
|
48
|
+
if (colIndex === colLength - 1) {
|
|
49
|
+
element.classList.add(Types.ST_TblStyleOverrideType.lastCol);
|
|
50
|
+
}
|
|
51
|
+
// 奇数行
|
|
52
|
+
if (isOdd(rowIndex + 1)) {
|
|
53
|
+
element.classList.add(Types.ST_TblStyleOverrideType.band1Horz);
|
|
54
|
+
}
|
|
55
|
+
// 偶数行
|
|
56
|
+
if (!isOdd(rowIndex + 1)) {
|
|
57
|
+
element.classList.add(Types.ST_TblStyleOverrideType.band2Horz);
|
|
58
|
+
}
|
|
59
|
+
// 奇数列
|
|
60
|
+
if (isOdd(colIndex + 1)) {
|
|
61
|
+
element.classList.add(Types.ST_TblStyleOverrideType.band1Vert);
|
|
62
|
+
}
|
|
63
|
+
// 偶数列
|
|
64
|
+
if (!isOdd(colIndex + 1)) {
|
|
65
|
+
element.classList.add(Types.ST_TblStyleOverrideType.band2Vert);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* 根据倍数判断是否是奇数,目前看来似乎 word 编辑器也没提供 size 设置
|
|
70
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/tblStyleRowBandSize.html
|
|
71
|
+
*/
|
|
72
|
+
function isOdd(num, size) {
|
|
73
|
+
return !(num % 2);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 渲染表格
|
|
77
|
+
*/
|
|
78
|
+
function renderTable(word, table) {
|
|
79
|
+
var e_1, _a, e_2, _b, e_3, _c;
|
|
80
|
+
var tableEl = document.createElement('table');
|
|
81
|
+
var properties = table.properties;
|
|
82
|
+
if (properties.tblCaption) {
|
|
83
|
+
var caption = document.createElement('caption');
|
|
84
|
+
caption.textContent = properties.tblCaption;
|
|
85
|
+
tableEl.appendChild(caption);
|
|
86
|
+
}
|
|
87
|
+
if (properties.tblLook) {
|
|
88
|
+
for (var key in properties.tblLook) {
|
|
89
|
+
// 这两个属性是反过来的
|
|
90
|
+
if (key === 'noHBand') {
|
|
91
|
+
if (!properties.tblLook[key]) {
|
|
92
|
+
dom.addClassName(tableEl, 'enable-hBand');
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
else if (key === 'noVBand') {
|
|
96
|
+
if (!properties.tblLook[key]) {
|
|
97
|
+
dom.addClassName(tableEl, 'enable-vBand');
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
else if (properties.tblLook[key]) {
|
|
101
|
+
dom.addClassName(tableEl, 'enable-' + key);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
setElementStyle.setElementStyle(word, tableEl, properties);
|
|
106
|
+
var customClass = word.genClassName();
|
|
107
|
+
tableEl.classList.add(customClass);
|
|
108
|
+
word.appendStyle(renderStyle.generateTableStyle(word.getClassPrefix(), customClass, { tblPr: properties }));
|
|
109
|
+
// 这里或许应该生成 classname 来支持 tcCSSStyle
|
|
110
|
+
var tbody = document.createElement('tbody');
|
|
111
|
+
tableEl.appendChild(tbody);
|
|
112
|
+
var rowIndex = 0;
|
|
113
|
+
try {
|
|
114
|
+
for (var _d = tslib_es6.__values(table.trs), _e = _d.next(); !_e.done; _e = _d.next()) {
|
|
115
|
+
var tr = _e.value;
|
|
116
|
+
var trEl = document.createElement('tr');
|
|
117
|
+
tbody.appendChild(trEl);
|
|
118
|
+
var colIndex = 0;
|
|
119
|
+
try {
|
|
120
|
+
for (var _f = (e_2 = void 0, tslib_es6.__values(tr.tcs)), _g = _f.next(); !_g.done; _g = _f.next()) {
|
|
121
|
+
var tc = _g.value;
|
|
122
|
+
var tdEl = document.createElement('td');
|
|
123
|
+
trEl.appendChild(tdEl);
|
|
124
|
+
setTdClassName(rowIndex, colIndex, table.trs.length, tr.tcs.length, tdEl, properties.rowBandSize, properties.colBandSize);
|
|
125
|
+
// tr 也能设置 tc style,所以先应用这个
|
|
126
|
+
if (tr.properties.tcStyle) {
|
|
127
|
+
dom.setStyle(tdEl, tr.properties.tcStyle);
|
|
128
|
+
}
|
|
129
|
+
var tcPr = tc.properties;
|
|
130
|
+
setElementStyle.setElementStyle(word, tdEl, tcPr);
|
|
131
|
+
if (tcPr.gridSpan) {
|
|
132
|
+
tdEl.colSpan = tcPr.gridSpan;
|
|
133
|
+
}
|
|
134
|
+
if (tcPr.rowSpan) {
|
|
135
|
+
tdEl.rowSpan = tcPr.rowSpan;
|
|
136
|
+
}
|
|
137
|
+
// 如果已经有表格的话,就不再渲染空段落了,避免底部多个空行
|
|
138
|
+
var hasTable = false;
|
|
139
|
+
try {
|
|
140
|
+
for (var _h = (e_3 = void 0, tslib_es6.__values(tc.children)), _j = _h.next(); !_j.done; _j = _h.next()) {
|
|
141
|
+
var tcChild = _j.value;
|
|
142
|
+
if (tcChild instanceof Paragraph.Paragraph) {
|
|
143
|
+
var p = renderParagraph["default"](word, tcChild, !hasTable);
|
|
144
|
+
dom.appendChild(tdEl, p);
|
|
145
|
+
}
|
|
146
|
+
else if (tcChild instanceof Table.Table) {
|
|
147
|
+
hasTable = true;
|
|
148
|
+
dom.appendChild(tdEl, renderTable(word, tcChild));
|
|
149
|
+
}
|
|
150
|
+
else {
|
|
151
|
+
console.warn('unknown child type: ' + tcChild);
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
156
|
+
finally {
|
|
157
|
+
try {
|
|
158
|
+
if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
|
|
159
|
+
}
|
|
160
|
+
finally { if (e_3) throw e_3.error; }
|
|
161
|
+
}
|
|
162
|
+
if (tcPr.rowSpan) {
|
|
163
|
+
colIndex += tcPr.rowSpan;
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
colIndex++;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
171
|
+
finally {
|
|
172
|
+
try {
|
|
173
|
+
if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
|
|
174
|
+
}
|
|
175
|
+
finally { if (e_2) throw e_2.error; }
|
|
176
|
+
}
|
|
177
|
+
rowIndex++;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
181
|
+
finally {
|
|
182
|
+
try {
|
|
183
|
+
if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
|
|
184
|
+
}
|
|
185
|
+
finally { if (e_1) throw e_1.error; }
|
|
186
|
+
}
|
|
187
|
+
return tableEl;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
exports["default"] = renderTable;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var dom = require('../util/dom.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* 设置元素样式,因为好几个地方用所以统一一下
|
|
9
|
+
*/
|
|
10
|
+
function setElementStyle(word, element, properties) {
|
|
11
|
+
if (!properties) {
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
14
|
+
if (properties.cssStyle) {
|
|
15
|
+
dom.setStyle(element, properties.cssStyle);
|
|
16
|
+
}
|
|
17
|
+
if (properties.pStyle) {
|
|
18
|
+
dom.addClassNames(element, word.getStyleClassName(properties.pStyle));
|
|
19
|
+
}
|
|
20
|
+
if (properties.rStyle) {
|
|
21
|
+
dom.addClassNames(element, word.getStyleClassName(properties.rStyle));
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
exports.setElementStyle = setElementStyle;
|