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,14 @@
|
|
|
1
|
+
import { createElement } from '../util/dom.js';
|
|
2
|
+
import renderBody from './renderBody.js';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* 渲染 document 主要入口
|
|
6
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/document.html
|
|
7
|
+
*/
|
|
8
|
+
function renderDocument(word, document) {
|
|
9
|
+
var doc = createElement('article');
|
|
10
|
+
renderBody(word, doc, document.body);
|
|
11
|
+
return doc;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export { renderDocument as default };
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 渲染图片,目前只支持 picture
|
|
3
|
+
* http://officeopenxml.com/drwOverview.php
|
|
4
|
+
*
|
|
5
|
+
*/
|
|
6
|
+
function renderDrawing(word, drawing) {
|
|
7
|
+
var _a, _b, _c;
|
|
8
|
+
var pic = drawing.pic;
|
|
9
|
+
if (pic) {
|
|
10
|
+
var blip = (_a = pic.blipFill) === null || _a === void 0 ? void 0 : _a.blip;
|
|
11
|
+
if (blip && blip.embled) {
|
|
12
|
+
var img_1 = document.createElement('img');
|
|
13
|
+
img_1.style.position = 'relative';
|
|
14
|
+
(_b = word.loadImage(blip.embled)) === null || _b === void 0 ? void 0 : _b.then(function (url) {
|
|
15
|
+
if (url) {
|
|
16
|
+
img_1.src = url;
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
var xfrm = (_c = pic.spPr) === null || _c === void 0 ? void 0 : _c.xfrm;
|
|
20
|
+
if (xfrm) {
|
|
21
|
+
var off = xfrm.off;
|
|
22
|
+
if (off) {
|
|
23
|
+
img_1.style.left = off.x;
|
|
24
|
+
img_1.style.top = off.y;
|
|
25
|
+
}
|
|
26
|
+
var ext = xfrm.ext;
|
|
27
|
+
if (ext) {
|
|
28
|
+
img_1.style.width = ext.cx;
|
|
29
|
+
img_1.style.height = ext.cy;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return img_1;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export { renderDrawing };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { Hyperlink } from './../openxml/word/Hyperlink';
|
|
2
|
+
import Word from '../Word';
|
|
3
|
+
import type { Paragraph } from '../openxml/word/Paragraph';
|
|
4
|
+
/**
|
|
5
|
+
* 渲染链接
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderHyperLink(word: Word, hyperlink: Hyperlink, paragraph?: Paragraph): HTMLElement;
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { __values } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { createElement, appendChild } from '../util/dom.js';
|
|
3
|
+
import { Run } from '../openxml/word/Run.js';
|
|
4
|
+
import renderRun from './renderRun.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 渲染链接
|
|
8
|
+
*/
|
|
9
|
+
function renderHyperLink(word, hyperlink, paragraph) {
|
|
10
|
+
var e_1, _a;
|
|
11
|
+
var a = createElement('a');
|
|
12
|
+
if (hyperlink.relation) {
|
|
13
|
+
var rel = hyperlink.relation;
|
|
14
|
+
if (rel && rel.targetMode === 'External') {
|
|
15
|
+
a.href = rel.target;
|
|
16
|
+
a.target = '_blank';
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (hyperlink.anchor) {
|
|
20
|
+
a.href = '#' + hyperlink.anchor;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
for (var _b = __values(hyperlink.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
24
|
+
var child = _c.value;
|
|
25
|
+
if (child instanceof Run) {
|
|
26
|
+
var span = renderRun(word, child, paragraph);
|
|
27
|
+
appendChild(a, span);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
32
|
+
finally {
|
|
33
|
+
try {
|
|
34
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
35
|
+
}
|
|
36
|
+
finally { if (e_1) throw e_1.error; }
|
|
37
|
+
}
|
|
38
|
+
return a;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export { renderHyperLink };
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { __values } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { appendChild } from '../util/dom.js';
|
|
3
|
+
import { Run } from '../openxml/word/Run.js';
|
|
4
|
+
import { BookmarkStart } from '../openxml/word/Bookmark.js';
|
|
5
|
+
import { Hyperlink } from '../openxml/word/Hyperlink.js';
|
|
6
|
+
import renderRun from './renderRun.js';
|
|
7
|
+
import { renderHyperLink } from './renderHyperLink.js';
|
|
8
|
+
import { renderBookmarkStart } from './renderBookmark.js';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 渲染 smart tag
|
|
12
|
+
*/
|
|
13
|
+
function renderInlineText(word, inlineText, parent) {
|
|
14
|
+
var e_1, _a;
|
|
15
|
+
try {
|
|
16
|
+
for (var _b = __values(inlineText.children), _c = _b.next(); !_c.done; _c = _b.next()) {
|
|
17
|
+
var child = _c.value;
|
|
18
|
+
if (child instanceof Run) {
|
|
19
|
+
appendChild(parent, renderRun(word, child));
|
|
20
|
+
}
|
|
21
|
+
else if (child instanceof BookmarkStart) {
|
|
22
|
+
appendChild(parent, renderBookmarkStart(word, child));
|
|
23
|
+
}
|
|
24
|
+
else if (child instanceof Hyperlink) {
|
|
25
|
+
var hyperlink = renderHyperLink(word, child);
|
|
26
|
+
appendChild(parent, hyperlink);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
31
|
+
finally {
|
|
32
|
+
try {
|
|
33
|
+
if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
|
34
|
+
}
|
|
35
|
+
finally { if (e_1) throw e_1.error; }
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export { renderInlineText as default };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { InstrText } from '../openxml/word/InstrText';
|
|
2
|
+
import Word from '../Word';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染字段指令,目前基本都没实现
|
|
5
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/Field%20definitions.html
|
|
6
|
+
* http://officeopenxml.com/WPfieldInstructions.php
|
|
7
|
+
*/
|
|
8
|
+
export declare function renderInstrText(word: Word, instrText: InstrText): HTMLElement;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { __values } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { createElement } from '../util/dom.js';
|
|
3
|
+
import renderInlineText from './renderInlineText.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 渲染字段指令,目前基本都没实现
|
|
7
|
+
* http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/Field%20definitions.html
|
|
8
|
+
* http://officeopenxml.com/WPfieldInstructions.php
|
|
9
|
+
*/
|
|
10
|
+
function renderInstrText(word, instrText) {
|
|
11
|
+
var e_1, _a;
|
|
12
|
+
var _b;
|
|
13
|
+
var text = instrText.text;
|
|
14
|
+
var span = createElement('span');
|
|
15
|
+
var fldSimples = (_b = word.currentParagraph) === null || _b === void 0 ? void 0 : _b.fldSimples;
|
|
16
|
+
if (fldSimples) {
|
|
17
|
+
try {
|
|
18
|
+
// 其实不知道这样做是不是对的
|
|
19
|
+
// 另外就是这里有很多指令还不支持 http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/FILENAME.html
|
|
20
|
+
for (var fldSimples_1 = __values(fldSimples), fldSimples_1_1 = fldSimples_1.next(); !fldSimples_1_1.done; fldSimples_1_1 = fldSimples_1.next()) {
|
|
21
|
+
var fldSimple = fldSimples_1_1.value;
|
|
22
|
+
if (fldSimple.instr === text.trim() ||
|
|
23
|
+
text.startsWith(fldSimple.instr + ' ')) {
|
|
24
|
+
renderInlineText(word, fldSimple.inlineText, span);
|
|
25
|
+
break;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
30
|
+
finally {
|
|
31
|
+
try {
|
|
32
|
+
if (fldSimples_1_1 && !fldSimples_1_1.done && (_a = fldSimples_1.return)) _a.call(fldSimples_1);
|
|
33
|
+
}
|
|
34
|
+
finally { if (e_1) throw e_1.error; }
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return span;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export { renderInstrText };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { NumberPr } from '../openxml/word/numbering/NumberProperties';
|
|
2
|
+
import Word from '../Word';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染列表 http://officeopenxml.com/WPnumbering.php
|
|
5
|
+
* 为了支持复杂场景,这里使用代码来直接生成内容
|
|
6
|
+
*/
|
|
7
|
+
export declare function renderNumbering(p: HTMLElement, word: Word, numPr: NumberPr): HTMLElement | null;
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
import { __assign } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { createElement } from '../util/dom.js';
|
|
3
|
+
import { ST_NumberFormat } from '../openxml/Types.js';
|
|
4
|
+
import { setElementStyle } from './setElementStyle.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* 整数转成罗马数字,来自 https://stackoverflow.com/a/32851198
|
|
8
|
+
*/
|
|
9
|
+
function romanize(num) {
|
|
10
|
+
var lookup = {
|
|
11
|
+
M: 1000,
|
|
12
|
+
CM: 900,
|
|
13
|
+
D: 500,
|
|
14
|
+
CD: 400,
|
|
15
|
+
C: 100,
|
|
16
|
+
XC: 90,
|
|
17
|
+
L: 50,
|
|
18
|
+
XL: 40,
|
|
19
|
+
X: 10,
|
|
20
|
+
IX: 9,
|
|
21
|
+
V: 5,
|
|
22
|
+
IV: 4,
|
|
23
|
+
I: 1
|
|
24
|
+
};
|
|
25
|
+
var roman = '';
|
|
26
|
+
for (var key in lookup) {
|
|
27
|
+
while (num >= lookup[key]) {
|
|
28
|
+
roman += key;
|
|
29
|
+
num -= lookup[key];
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
return roman;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* 将数字转成列表格式,目前只支持少数几种格式,不支持的都直接返回数字
|
|
36
|
+
*/
|
|
37
|
+
function convertNumToFormat(numFmt, num) {
|
|
38
|
+
switch (numFmt) {
|
|
39
|
+
case ST_NumberFormat.decimal:
|
|
40
|
+
return num.toString();
|
|
41
|
+
case ST_NumberFormat.lowerLetter:
|
|
42
|
+
return String.fromCharCode(96 + num);
|
|
43
|
+
case ST_NumberFormat.upperLetter:
|
|
44
|
+
return String.fromCharCode(64 + num);
|
|
45
|
+
case ST_NumberFormat.lowerRoman:
|
|
46
|
+
return romanize(num).toLowerCase();
|
|
47
|
+
case ST_NumberFormat.upperRoman:
|
|
48
|
+
return romanize(num).toUpperCase();
|
|
49
|
+
case ST_NumberFormat.bullet:
|
|
50
|
+
// 原本其实是用
|
|
51
|
+
return '•';
|
|
52
|
+
default:
|
|
53
|
+
return num.toString();
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* 渲染列表 http://officeopenxml.com/WPnumbering.php
|
|
58
|
+
* 为了支持复杂场景,这里使用代码来直接生成内容
|
|
59
|
+
*/
|
|
60
|
+
function renderNumbering(p, word, numPr) {
|
|
61
|
+
var numbering = word.numbering;
|
|
62
|
+
var numId = numPr.numId;
|
|
63
|
+
if (!numId) {
|
|
64
|
+
console.warn('renderNumbering: numId is empty');
|
|
65
|
+
return null;
|
|
66
|
+
}
|
|
67
|
+
if (!numbering) {
|
|
68
|
+
console.warn('renderNumbering: numbering is empty');
|
|
69
|
+
return null;
|
|
70
|
+
}
|
|
71
|
+
var num = numbering.nums[numId];
|
|
72
|
+
if (!num) {
|
|
73
|
+
console.warn('renderNumbering: num is empty');
|
|
74
|
+
return null;
|
|
75
|
+
}
|
|
76
|
+
var abstractNum = numbering.abstractNums[num.abstractNumId];
|
|
77
|
+
var lvls = abstractNum.lvls;
|
|
78
|
+
if (num.lvlOverride) {
|
|
79
|
+
lvls = __assign(__assign({}, lvls), num.lvlOverride.lvls);
|
|
80
|
+
}
|
|
81
|
+
var lvl = lvls[numPr.ilvl];
|
|
82
|
+
if (!lvl) {
|
|
83
|
+
console.warn('renderNumbering: lvl is empty');
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
86
|
+
var ilvl = numPr.ilvl;
|
|
87
|
+
var ilvlData = numbering.numData[numId];
|
|
88
|
+
// 还不支持 http://officeopenxml.com/WPnumbering-restart.php
|
|
89
|
+
if (!ilvlData[ilvl]) {
|
|
90
|
+
ilvlData[ilvl] = lvl.start;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
ilvlData[ilvl] += 1;
|
|
94
|
+
// 加一之后,将比它大的都清空,这样才能每个级别重置
|
|
95
|
+
for (var ilvIndex in ilvlData) {
|
|
96
|
+
if (parseInt(ilvIndex) > parseInt(ilvl)) {
|
|
97
|
+
ilvlData[ilvIndex] = 0;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
var element = createElement('span');
|
|
102
|
+
var lvlText = lvl.lvlText;
|
|
103
|
+
// 格式化内容
|
|
104
|
+
var level = parseInt(ilvl);
|
|
105
|
+
// 获取每个层级的值
|
|
106
|
+
var levelNums = [];
|
|
107
|
+
for (var i = 0; i <= level; i++) {
|
|
108
|
+
var listNumber = ilvlData[i];
|
|
109
|
+
if (listNumber) {
|
|
110
|
+
var numFmt = lvls[i].numFmt;
|
|
111
|
+
var numText = convertNumToFormat(numFmt, listNumber);
|
|
112
|
+
// 强制数字显示 http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/isLgl.html
|
|
113
|
+
// http://officeopenxml.com/WPnumbering-isLgl.php
|
|
114
|
+
if (lvl.isLgl) {
|
|
115
|
+
numText = String(listNumber);
|
|
116
|
+
}
|
|
117
|
+
levelNums.push(numText);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
for (var i = 0; i < levelNums.length; i++) {
|
|
121
|
+
var levelNum = levelNums[i];
|
|
122
|
+
lvlText = lvlText.replace("%".concat(i + 1), levelNum);
|
|
123
|
+
}
|
|
124
|
+
// 这个 pPr 似乎是影响父级的
|
|
125
|
+
// http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/pPr_6.html
|
|
126
|
+
// This element specifies the paragraph properties which shall be applied as part of a given numbering level within the parent numbering definition.
|
|
127
|
+
setElementStyle(word, p, lvl.pPr);
|
|
128
|
+
setElementStyle(word, element, lvl.rPr);
|
|
129
|
+
// 还不支持 lvlJc
|
|
130
|
+
// 还不支持 image
|
|
131
|
+
// http://officeopenxml.com/WPnumbering-imagesAsSymbol.php
|
|
132
|
+
if (lvl.numFmt !== ST_NumberFormat.bullet ||
|
|
133
|
+
word.renderOptions.bulletUseFont) {
|
|
134
|
+
element.innerText = lvlText;
|
|
135
|
+
}
|
|
136
|
+
else {
|
|
137
|
+
// 如果没有字体只能尽可能模拟了
|
|
138
|
+
// 参考 https://www.w3schools.com/charsets/ref_utf_geometric.asp
|
|
139
|
+
var bulletText = '•';
|
|
140
|
+
var unicodeString = lvlText.charCodeAt(0).toString(16).padStart(4, '0');
|
|
141
|
+
if (unicodeString === 'f06e') {
|
|
142
|
+
bulletText = '■';
|
|
143
|
+
}
|
|
144
|
+
else if (unicodeString === 'f075') {
|
|
145
|
+
bulletText = '◆';
|
|
146
|
+
}
|
|
147
|
+
else if (unicodeString === 'f0d8') {
|
|
148
|
+
bulletText = '►';
|
|
149
|
+
}
|
|
150
|
+
element.innerHTML = bulletText;
|
|
151
|
+
}
|
|
152
|
+
if (lvl.suff === 'space') {
|
|
153
|
+
element.innerHTML += ' ';
|
|
154
|
+
}
|
|
155
|
+
else if (lvl.suff === 'tab') {
|
|
156
|
+
element.innerHTML += ' ';
|
|
157
|
+
}
|
|
158
|
+
return element;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
export { renderNumbering };
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Word from '../Word';
|
|
2
|
+
import { Paragraph } from '../openxml/word/Paragraph';
|
|
3
|
+
/**
|
|
4
|
+
* 渲染段落
|
|
5
|
+
* @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上
|
|
6
|
+
*/
|
|
7
|
+
export default function renderParagraph(word: Word, paragraph: Paragraph, renderEmptySpace?: boolean): HTMLElement;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { __values } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { createElement, appendChild } from '../util/dom.js';
|
|
3
|
+
import { Run } from '../openxml/word/Run.js';
|
|
4
|
+
import { BookmarkStart } from '../openxml/word/Bookmark.js';
|
|
5
|
+
import { Hyperlink } from '../openxml/word/Hyperlink.js';
|
|
6
|
+
import renderRun from './renderRun.js';
|
|
7
|
+
import { renderHyperLink } from './renderHyperLink.js';
|
|
8
|
+
import { renderBookmarkStart } from './renderBookmark.js';
|
|
9
|
+
import { renderNumbering } from './renderNumbering.js';
|
|
10
|
+
import { setElementStyle } from './setElementStyle.js';
|
|
11
|
+
import { renderTab } from './renderTab.js';
|
|
12
|
+
import { SmartTag } from '../openxml/word/SmartTag.js';
|
|
13
|
+
import renderInlineText from './renderInlineText.js';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 渲染段落
|
|
17
|
+
* @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上
|
|
18
|
+
*/
|
|
19
|
+
function renderParagraph(word, paragraph, renderEmptySpace) {
|
|
20
|
+
var e_1, _a, e_2, _b;
|
|
21
|
+
if (renderEmptySpace === void 0) { renderEmptySpace = true; }
|
|
22
|
+
word.currentParagraph = paragraph;
|
|
23
|
+
var p = createElement('p');
|
|
24
|
+
word.addClass(p, 'p');
|
|
25
|
+
var properties = paragraph.properties;
|
|
26
|
+
setElementStyle(word, p, properties);
|
|
27
|
+
// 渲染列表前缀
|
|
28
|
+
if (properties.numPr) {
|
|
29
|
+
appendChild(p, renderNumbering(p, word, properties.numPr));
|
|
30
|
+
}
|
|
31
|
+
if (properties.tabs) {
|
|
32
|
+
try {
|
|
33
|
+
for (var _c = __values(properties.tabs), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
34
|
+
var tab = _d.value;
|
|
35
|
+
appendChild(p, renderTab(word, tab));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
39
|
+
finally {
|
|
40
|
+
try {
|
|
41
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
42
|
+
}
|
|
43
|
+
finally { if (e_1) throw e_1.error; }
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
try {
|
|
47
|
+
for (var _e = __values(paragraph.children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
48
|
+
var child = _f.value;
|
|
49
|
+
if (child instanceof Run) {
|
|
50
|
+
appendChild(p, renderRun(word, child, paragraph));
|
|
51
|
+
}
|
|
52
|
+
else if (child instanceof BookmarkStart) {
|
|
53
|
+
appendChild(p, renderBookmarkStart(word, child));
|
|
54
|
+
}
|
|
55
|
+
else if (child instanceof Hyperlink) {
|
|
56
|
+
var hyperlink = renderHyperLink(word, child, paragraph);
|
|
57
|
+
appendChild(p, hyperlink);
|
|
58
|
+
}
|
|
59
|
+
else if (child instanceof SmartTag) {
|
|
60
|
+
renderInlineText(word, child, p);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
65
|
+
finally {
|
|
66
|
+
try {
|
|
67
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
68
|
+
}
|
|
69
|
+
finally { if (e_2) throw e_2.error; }
|
|
70
|
+
}
|
|
71
|
+
// 空行自动加个空格,不然会没高度
|
|
72
|
+
if (p.innerHTML === '' && renderEmptySpace) {
|
|
73
|
+
p.innerHTML = ' ';
|
|
74
|
+
}
|
|
75
|
+
return p;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
export { renderParagraph as default };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 老的 vml 格式,目前只支持图片
|
|
3
|
+
*/
|
|
4
|
+
function renderPict(word, pict) {
|
|
5
|
+
var _a;
|
|
6
|
+
if (pict.imagedata) {
|
|
7
|
+
var img_1 = document.createElement('img');
|
|
8
|
+
img_1.style.position = 'relative';
|
|
9
|
+
(_a = word.loadImage(pict.imagedata)) === null || _a === void 0 ? void 0 : _a.then(function (url) {
|
|
10
|
+
if (url) {
|
|
11
|
+
img_1.src = url;
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
return img_1;
|
|
15
|
+
}
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { renderPict };
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { __values } from '../node_modules/tslib/tslib.es6.js';
|
|
2
|
+
import { createElement } from '../util/dom.js';
|
|
3
|
+
import renderRun from './renderRun.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 渲染 ruby 标签
|
|
7
|
+
*/
|
|
8
|
+
function renderRuby(word, ruby) {
|
|
9
|
+
var e_1, _a, e_2, _b;
|
|
10
|
+
var rubyElement = createElement('ruby');
|
|
11
|
+
if (ruby.rubyBase) {
|
|
12
|
+
try {
|
|
13
|
+
for (var _c = __values(ruby.rubyBase.children), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
14
|
+
var text = _d.value;
|
|
15
|
+
rubyElement.appendChild(renderRun(word, text));
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
19
|
+
finally {
|
|
20
|
+
try {
|
|
21
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
22
|
+
}
|
|
23
|
+
finally { if (e_1) throw e_1.error; }
|
|
24
|
+
}
|
|
25
|
+
if (ruby.rt) {
|
|
26
|
+
// rp 是给不支持 ruby 的浏览器显示的
|
|
27
|
+
var rpStart = createElement('rp');
|
|
28
|
+
rpStart.innerText = '(';
|
|
29
|
+
rubyElement.appendChild(rpStart);
|
|
30
|
+
var rtElement = createElement('rt');
|
|
31
|
+
try {
|
|
32
|
+
for (var _e = __values(ruby.rt.children), _f = _e.next(); !_f.done; _f = _e.next()) {
|
|
33
|
+
var text = _f.value;
|
|
34
|
+
rtElement.appendChild(renderRun(word, text));
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
38
|
+
finally {
|
|
39
|
+
try {
|
|
40
|
+
if (_f && !_f.done && (_b = _e.return)) _b.call(_e);
|
|
41
|
+
}
|
|
42
|
+
finally { if (e_2) throw e_2.error; }
|
|
43
|
+
}
|
|
44
|
+
rubyElement.appendChild(rtElement);
|
|
45
|
+
var rpEnd = createElement('rp');
|
|
46
|
+
rpEnd.innerText = ')';
|
|
47
|
+
rubyElement.appendChild(rpEnd);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return rubyElement;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export { renderRuby };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* run 相关的 http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/Run_1.html
|
|
3
|
+
*/
|
|
4
|
+
import Word from '../Word';
|
|
5
|
+
import { Run } from '../openxml/word/Run';
|
|
6
|
+
import type { Paragraph } from './../openxml/word/Paragraph';
|
|
7
|
+
/**
|
|
8
|
+
* 更新文档里的所有变量
|
|
9
|
+
*/
|
|
10
|
+
export declare function updateVariableText(word: Word): void;
|
|
11
|
+
/**
|
|
12
|
+
* 渲染 run 节点
|
|
13
|
+
*/
|
|
14
|
+
export default function renderRun(word: Word, run: Run, paragraph?: Paragraph): HTMLElement;
|