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,37 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 中英文间自动加空格,基于下面代码改的,去掉了 lodash 依赖
|
|
7
|
+
* https://gist.github.com/wyl8899/e0f31068681023480e20c34f6b19a275
|
|
8
|
+
*/
|
|
9
|
+
/* Partial implementation from https://zhuanlan.zhihu.com/p/33612593 */
|
|
10
|
+
/* 标点 */
|
|
11
|
+
var punctuationRegex = /\p{Punctuation}/u;
|
|
12
|
+
/* 空格 */
|
|
13
|
+
var spaceRegex = /\p{Separator}/u;
|
|
14
|
+
/* CJK 字符,中日韩 */
|
|
15
|
+
var cjkRegex = /\p{Script=Han}|\p{Script=Katakana}|\p{Script=Hiragana}|\p{Script=Hangul}/u;
|
|
16
|
+
var shouldSpace = function (a, b) {
|
|
17
|
+
if (cjkRegex.test(a)) {
|
|
18
|
+
return !(punctuationRegex.test(b) ||
|
|
19
|
+
spaceRegex.test(b) ||
|
|
20
|
+
cjkRegex.test(b));
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
return cjkRegex.test(b) && !punctuationRegex.test(a) && !spaceRegex.test(a);
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
var join = function (parts, sepFunc) {
|
|
27
|
+
return parts.reduce(function (r, p, i) {
|
|
28
|
+
var sep = i !== 0 ? sepFunc(p, parts[i - 1]) : '';
|
|
29
|
+
return r + sep + p;
|
|
30
|
+
}, '');
|
|
31
|
+
};
|
|
32
|
+
var cjkspace = function (strings) {
|
|
33
|
+
var filtered = strings.filter(function (c) { return c !== undefined && c !== ''; });
|
|
34
|
+
return join(filtered, function (a, b) { return (shouldSpace(a, b) ? ' ' : ''); });
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
exports.cjkspace = cjkspace;
|
package/lib/util/blob.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 将 blob 转成 data url
|
|
7
|
+
*/
|
|
8
|
+
function blobToDataURL(blob) {
|
|
9
|
+
return new Promise(function (resolve, reject) {
|
|
10
|
+
var reader = new FileReader();
|
|
11
|
+
reader.onload = function (_e) { return resolve(reader.result); };
|
|
12
|
+
reader.onerror = function (_e) { return reject(reader.error); };
|
|
13
|
+
reader.onabort = function (_e) { return reject(new Error('Read aborted')); };
|
|
14
|
+
reader.readAsDataURL(blob);
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* 下载 blob
|
|
19
|
+
* https://dev.to/nombrekeff/download-file-from-blob-21ho
|
|
20
|
+
*/
|
|
21
|
+
function downloadBlob(blob, name) {
|
|
22
|
+
if (name === void 0) { name = 'file.txt'; }
|
|
23
|
+
// Convert your blob into a Blob URL (a special url that points to an object in the browser's memory)
|
|
24
|
+
var blobUrl = URL.createObjectURL(blob);
|
|
25
|
+
// Create a link element
|
|
26
|
+
var link = document.createElement('a');
|
|
27
|
+
// Set link's href to point to the Blob URL
|
|
28
|
+
link.href = blobUrl;
|
|
29
|
+
link.download = name;
|
|
30
|
+
// Append link to the body
|
|
31
|
+
document.body.appendChild(link);
|
|
32
|
+
// Dispatch click event on the link
|
|
33
|
+
// This is necessary as link.click() does not work on the latest firefox
|
|
34
|
+
link.dispatchEvent(new MouseEvent('click', {
|
|
35
|
+
bubbles: true,
|
|
36
|
+
cancelable: true,
|
|
37
|
+
view: window
|
|
38
|
+
}));
|
|
39
|
+
// Remove link from body
|
|
40
|
+
document.body.removeChild(link);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
exports.blobToDataURL = blobToDataURL;
|
|
44
|
+
exports.downloadBlob = downloadBlob;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* dom 相关的操作
|
|
3
|
+
*/
|
|
4
|
+
import { CSSStyle } from '../openxml/Style';
|
|
5
|
+
/**
|
|
6
|
+
* 样式对象转成 css 文本
|
|
7
|
+
*/
|
|
8
|
+
export declare function styleToText(style?: CSSStyle): string;
|
|
9
|
+
/**
|
|
10
|
+
* 设置元素样式
|
|
11
|
+
*/
|
|
12
|
+
export declare function setStyle(el: HTMLElement, style: CSSStyle): void;
|
|
13
|
+
/**
|
|
14
|
+
* 创建元素
|
|
15
|
+
*/
|
|
16
|
+
export declare function createElement(tagName: string): HTMLElement;
|
|
17
|
+
/**
|
|
18
|
+
* 创建片段
|
|
19
|
+
*/
|
|
20
|
+
export declare function createDocumentFragment(): DocumentFragment;
|
|
21
|
+
/**
|
|
22
|
+
* 添加子节点,会做一些判断避免报错
|
|
23
|
+
*/
|
|
24
|
+
export declare function appendChild(parent: HTMLElement, child: HTMLElement | null): void;
|
|
25
|
+
/**
|
|
26
|
+
* 添加注释节点
|
|
27
|
+
*/
|
|
28
|
+
export declare function appendComment(parent: HTMLElement, comment: string): void;
|
|
29
|
+
/**
|
|
30
|
+
* 添加 css 类
|
|
31
|
+
*/
|
|
32
|
+
export declare function addClassName(el: HTMLElement, className: string): void;
|
|
33
|
+
/**
|
|
34
|
+
* 批量添加 css 类
|
|
35
|
+
*/
|
|
36
|
+
export declare function addClassNames(el: HTMLElement, classNames: string[]): void;
|
package/lib/util/dom.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var tslib_es6 = require('../node_modules/tslib/tslib.es6.js');
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* dom 相关的操作
|
|
9
|
+
*/
|
|
10
|
+
/**
|
|
11
|
+
* 样式对象转成 css 文本
|
|
12
|
+
*/
|
|
13
|
+
function styleToText(style) {
|
|
14
|
+
if (style === void 0) { style = {}; }
|
|
15
|
+
var text = '';
|
|
16
|
+
for (var key in style) {
|
|
17
|
+
var value = style[key];
|
|
18
|
+
if (value != null && value !== '') {
|
|
19
|
+
text += "".concat(key, ": ").concat(value, ";\n");
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
return text;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* 设置元素样式
|
|
26
|
+
*/
|
|
27
|
+
function setStyle(el, style) {
|
|
28
|
+
for (var key in style) {
|
|
29
|
+
var value = style[key];
|
|
30
|
+
if (value != null && value !== '') {
|
|
31
|
+
el.style.setProperty(key, style[key]);
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* 创建元素
|
|
37
|
+
*/
|
|
38
|
+
function createElement(tagName) {
|
|
39
|
+
return document.createElement(tagName);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* 添加子节点,会做一些判断避免报错
|
|
43
|
+
*/
|
|
44
|
+
function appendChild(parent, child) {
|
|
45
|
+
if (parent && child) {
|
|
46
|
+
parent.appendChild(child);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* 添加 css 类
|
|
51
|
+
*/
|
|
52
|
+
function addClassName(el, className) {
|
|
53
|
+
if (el && className) {
|
|
54
|
+
el.classList.add(className);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 批量添加 css 类
|
|
59
|
+
*/
|
|
60
|
+
function addClassNames(el, classNames) {
|
|
61
|
+
var _a;
|
|
62
|
+
if (el && classNames) {
|
|
63
|
+
(_a = el.classList).add.apply(_a, tslib_es6.__spreadArray([], tslib_es6.__read(classNames), false));
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
exports.addClassName = addClassName;
|
|
68
|
+
exports.addClassNames = addClassNames;
|
|
69
|
+
exports.appendChild = appendChild;
|
|
70
|
+
exports.createElement = createElement;
|
|
71
|
+
exports.setStyle = setStyle;
|
|
72
|
+
exports.styleToText = styleToText;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 合并 p 下相同的文本,主要是为了方便替换变量
|
|
3
|
+
*/
|
|
4
|
+
import Word from '../Word';
|
|
5
|
+
/**
|
|
6
|
+
* 只支持处理 w:r 下有 w:t 的情况
|
|
7
|
+
*/
|
|
8
|
+
export declare function canMerge(element: Element): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* 合并 p 下相同的文本
|
|
11
|
+
*/
|
|
12
|
+
export declare function mergeRunInP(word: Word, p: Element): void;
|
|
13
|
+
/**
|
|
14
|
+
* 合并
|
|
15
|
+
* @param document
|
|
16
|
+
*/
|
|
17
|
+
export declare function mergeRun(word: Word, doc: Document): void;
|
|
@@ -0,0 +1,140 @@
|
|
|
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 parsePr = require('../parse/parsePr.js');
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* 合并 p 下相同的文本,主要是为了方便替换变量
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* 是否具有相同样式
|
|
13
|
+
*/
|
|
14
|
+
function hasSomeStyle(word, first, second) {
|
|
15
|
+
var firstStyle = first ? parsePr.parsePr(word, first) : {};
|
|
16
|
+
var secondStyle = second ? parsePr.parsePr(word, second) : {};
|
|
17
|
+
return JSON.stringify(firstStyle) === JSON.stringify(secondStyle);
|
|
18
|
+
}
|
|
19
|
+
function mergeText(first, second) {
|
|
20
|
+
var firstT = first.getElementsByTagName('w:t')[0];
|
|
21
|
+
var secondT = second.getElementsByTagName('w:t')[0];
|
|
22
|
+
if (firstT && secondT) {
|
|
23
|
+
var secondText = secondT.textContent || '';
|
|
24
|
+
firstT.textContent += secondText || '';
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
28
|
+
* 只支持处理 w:r 下有 w:t 的情况
|
|
29
|
+
*/
|
|
30
|
+
function canMerge(element) {
|
|
31
|
+
var e_1, _a;
|
|
32
|
+
var tagName = element.tagName;
|
|
33
|
+
var childChildren = element.children;
|
|
34
|
+
var hasText = false;
|
|
35
|
+
var textHasSpace = false;
|
|
36
|
+
try {
|
|
37
|
+
for (var childChildren_1 = tslib_es6.__values(childChildren), childChildren_1_1 = childChildren_1.next(); !childChildren_1_1.done; childChildren_1_1 = childChildren_1.next()) {
|
|
38
|
+
var childChild = childChildren_1_1.value;
|
|
39
|
+
if (childChild.tagName === 'w:t') {
|
|
40
|
+
hasText = true;
|
|
41
|
+
textHasSpace = childChild.getAttribute('xml:space') === 'preserve';
|
|
42
|
+
break;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
|
47
|
+
finally {
|
|
48
|
+
try {
|
|
49
|
+
if (childChildren_1_1 && !childChildren_1_1.done && (_a = childChildren_1.return)) _a.call(childChildren_1);
|
|
50
|
+
}
|
|
51
|
+
finally { if (e_1) throw e_1.error; }
|
|
52
|
+
}
|
|
53
|
+
return tagName === 'w:r' && hasText && !textHasSpace;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 合并 p 下相同的文本
|
|
57
|
+
*/
|
|
58
|
+
function mergeRunInP(word, p) {
|
|
59
|
+
var e_2, _a, e_3, _b;
|
|
60
|
+
var newElements = [];
|
|
61
|
+
var lastRun = null;
|
|
62
|
+
try {
|
|
63
|
+
for (var _c = tslib_es6.__values(p.children), _d = _c.next(); !_d.done; _d = _c.next()) {
|
|
64
|
+
var child = _d.value;
|
|
65
|
+
var tagName = child.tagName;
|
|
66
|
+
// 避免图片和空格被合并了
|
|
67
|
+
if (canMerge(child)) {
|
|
68
|
+
if (lastRun) {
|
|
69
|
+
var lastRunProps = lastRun.getElementsByTagName('w:rPr')[0];
|
|
70
|
+
var thisProps = child.getElementsByTagName('w:rPr')[0];
|
|
71
|
+
if (hasSomeStyle(word, lastRunProps, thisProps)) {
|
|
72
|
+
mergeText(lastRun, child);
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
lastRun = child;
|
|
76
|
+
newElements.push(child);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
// 说明是第一次运行
|
|
81
|
+
lastRun = child;
|
|
82
|
+
newElements.push(child);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
else {
|
|
86
|
+
// 忽略这个标签
|
|
87
|
+
if (tagName !== 'w:proofErr') {
|
|
88
|
+
lastRun = null;
|
|
89
|
+
newElements.push(child);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
|
95
|
+
finally {
|
|
96
|
+
try {
|
|
97
|
+
if (_d && !_d.done && (_a = _c.return)) _a.call(_c);
|
|
98
|
+
}
|
|
99
|
+
finally { if (e_2) throw e_2.error; }
|
|
100
|
+
}
|
|
101
|
+
p.innerHTML = '';
|
|
102
|
+
try {
|
|
103
|
+
for (var newElements_1 = tslib_es6.__values(newElements), newElements_1_1 = newElements_1.next(); !newElements_1_1.done; newElements_1_1 = newElements_1.next()) {
|
|
104
|
+
var newElement = newElements_1_1.value;
|
|
105
|
+
p.appendChild(newElement);
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
|
109
|
+
finally {
|
|
110
|
+
try {
|
|
111
|
+
if (newElements_1_1 && !newElements_1_1.done && (_b = newElements_1.return)) _b.call(newElements_1);
|
|
112
|
+
}
|
|
113
|
+
finally { if (e_3) throw e_3.error; }
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* 合并
|
|
118
|
+
* @param document
|
|
119
|
+
*/
|
|
120
|
+
function mergeRun(word, doc) {
|
|
121
|
+
var e_4, _a;
|
|
122
|
+
var ps = doc.getElementsByTagName('w:p');
|
|
123
|
+
try {
|
|
124
|
+
for (var ps_1 = tslib_es6.__values(ps), ps_1_1 = ps_1.next(); !ps_1_1.done; ps_1_1 = ps_1.next()) {
|
|
125
|
+
var p = ps_1_1.value;
|
|
126
|
+
mergeRunInP(word, p);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
catch (e_4_1) { e_4 = { error: e_4_1 }; }
|
|
130
|
+
finally {
|
|
131
|
+
try {
|
|
132
|
+
if (ps_1_1 && !ps_1_1.done && (_a = ps_1.return)) _a.call(ps_1);
|
|
133
|
+
}
|
|
134
|
+
finally { if (e_4) throw e_4.error; }
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
exports.canMerge = canMerge;
|
|
139
|
+
exports.mergeRun = mergeRun;
|
|
140
|
+
exports.mergeRunInP = mergeRunInP;
|
package/lib/util/xml.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 解析 xml
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 构建 xml 文本
|
|
10
|
+
*/
|
|
11
|
+
function buildXML(doc) {
|
|
12
|
+
var serializer = new XMLSerializer();
|
|
13
|
+
return serializer.serializeToString(doc);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
exports.buildXML = buildXML;
|
package/package.json
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "office-viewer",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "office 文档在线预览",
|
|
5
|
+
"main": "lib/index.js",
|
|
6
|
+
"module": "esm/index.js",
|
|
7
|
+
"types": "lib/index.d.ts",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"dev": "vite",
|
|
10
|
+
"build": "npm run clean-dist && cross-env NODE_ENV=production rollup -c ",
|
|
11
|
+
"test": "jest",
|
|
12
|
+
"lib": "npm run clean-dist && cross-env NODE_ENV=production IS_LIB=1 rollup -c",
|
|
13
|
+
"coverage": "jest --coverage",
|
|
14
|
+
"declaration": "tsc --project tsconfig-for-declaration.json --allowJs --declaration --emitDeclarationOnly --declarationDir ./lib --rootDir ./src",
|
|
15
|
+
"clean-dist": "rimraf lib/** esm/**",
|
|
16
|
+
"xsd2ts": "cd tools && ts-node --transpileOnly xsd2ts.ts"
|
|
17
|
+
},
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"require": "./lib/index.js",
|
|
21
|
+
"import": "./esm/index.js"
|
|
22
|
+
},
|
|
23
|
+
"./lib/*": {
|
|
24
|
+
"require": "./lib/*.js",
|
|
25
|
+
"import": "./esm/*.js"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"files": [
|
|
29
|
+
"lib",
|
|
30
|
+
"esm"
|
|
31
|
+
],
|
|
32
|
+
"keywords": [
|
|
33
|
+
"office",
|
|
34
|
+
"docx"
|
|
35
|
+
],
|
|
36
|
+
"license": "Apache 2.0",
|
|
37
|
+
"bugs": {
|
|
38
|
+
"url": "https://github.com/baidu/amis/issues"
|
|
39
|
+
},
|
|
40
|
+
"homepage": "https://github.com/baidu/amis#readme",
|
|
41
|
+
"dependencies": {
|
|
42
|
+
"fflate": "^0.7.4"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {
|
|
45
|
+
"@rollup/plugin-commonjs": "^22.0.2",
|
|
46
|
+
"@rollup/plugin-json": "^4.1.0",
|
|
47
|
+
"@rollup/plugin-node-resolve": "^14.1.0",
|
|
48
|
+
"@rollup/plugin-typescript": "^8.3.4",
|
|
49
|
+
"@types/jest": "^28.1.0",
|
|
50
|
+
"amis-formula": "^2.7.2",
|
|
51
|
+
"jest": "^29.0.3",
|
|
52
|
+
"ts-jest": "^29.0.2",
|
|
53
|
+
"ts-loader": "^9.2.3",
|
|
54
|
+
"ts-node": "^10.4.0",
|
|
55
|
+
"typescript": "^4.3.5",
|
|
56
|
+
"rollup": "^2.60.2",
|
|
57
|
+
"rollup-plugin-terser": "^7.0.2",
|
|
58
|
+
"vite": "^3.2.2"
|
|
59
|
+
},
|
|
60
|
+
"jest": {
|
|
61
|
+
"testEnvironment": "jsdom",
|
|
62
|
+
"collectCoverageFrom": [
|
|
63
|
+
"src/**/*"
|
|
64
|
+
],
|
|
65
|
+
"moduleFileExtensions": [
|
|
66
|
+
"ts",
|
|
67
|
+
"tsx",
|
|
68
|
+
"js"
|
|
69
|
+
],
|
|
70
|
+
"transform": {
|
|
71
|
+
"\\.(ts|tsx)$": [
|
|
72
|
+
"ts-jest",
|
|
73
|
+
{
|
|
74
|
+
"diagnostics": false
|
|
75
|
+
}
|
|
76
|
+
]
|
|
77
|
+
},
|
|
78
|
+
"setupFiles": [
|
|
79
|
+
"jest-canvas-mock"
|
|
80
|
+
],
|
|
81
|
+
"testRegex": "/.*\\.test\\.(ts|tsx|js)$",
|
|
82
|
+
"moduleNameMapper": {
|
|
83
|
+
"\\.(css|less|sass|scss)$": "<rootDir>/../__mocks__/styleMock.js",
|
|
84
|
+
"\\.(svg)$": "<rootDir>/../__mocks__/svgMock.js"
|
|
85
|
+
},
|
|
86
|
+
"snapshotFormat": {
|
|
87
|
+
"escapeString": false,
|
|
88
|
+
"printBasicPrototype": false
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
}
|