office-viewer 0.1.3 → 0.1.4

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.
Files changed (38) hide show
  1. package/README.md +1 -1
  2. package/esm/Word.js +16 -10
  3. package/esm/openxml/drawing/Drawing.d.ts +2 -0
  4. package/esm/openxml/drawing/Drawing.js +4 -0
  5. package/esm/openxml/drawing/Transform.d.ts +2 -0
  6. package/esm/openxml/drawing/Transform.js +41 -12
  7. package/esm/openxml/word/Tab.d.ts +1 -1
  8. package/esm/openxml/word/wps/WPG.d.ts +10 -1
  9. package/esm/openxml/word/wps/WPG.js +56 -0
  10. package/esm/openxml/word/wps/WPS.js +1 -0
  11. package/esm/render/renderDrawing.js +183 -71
  12. package/esm/render/renderParagraph.js +49 -6
  13. package/esm/render/renderRun.js +7 -2
  14. package/esm/render/renderStyle.js +1 -1
  15. package/esm/render/renderTab.d.ts +1 -1
  16. package/esm/render/renderTab.js +7 -1
  17. package/esm/util/get.d.ts +4 -0
  18. package/esm/util/get.js +18 -0
  19. package/esm/util/replaceVar.js +2 -1
  20. package/lib/Word.js +16 -10
  21. package/lib/openxml/drawing/Drawing.d.ts +2 -0
  22. package/lib/openxml/drawing/Drawing.js +4 -0
  23. package/lib/openxml/drawing/Transform.d.ts +2 -0
  24. package/lib/openxml/drawing/Transform.js +41 -12
  25. package/lib/openxml/word/Tab.d.ts +1 -1
  26. package/lib/openxml/word/wps/WPG.d.ts +10 -1
  27. package/lib/openxml/word/wps/WPG.js +60 -0
  28. package/lib/openxml/word/wps/WPS.js +1 -0
  29. package/lib/render/renderDrawing.js +183 -71
  30. package/lib/render/renderParagraph.js +49 -6
  31. package/lib/render/renderRun.js +7 -2
  32. package/lib/render/renderStyle.js +1 -1
  33. package/lib/render/renderTab.d.ts +1 -1
  34. package/lib/render/renderTab.js +7 -1
  35. package/lib/util/get.d.ts +4 -0
  36. package/lib/util/get.js +22 -0
  37. package/lib/util/replaceVar.js +2 -1
  38. package/package.json +2 -3
@@ -14,8 +14,9 @@ var renderCustGeom = require('./renderCustGeom.js');
14
14
  /**
15
15
  * 渲染图片
16
16
  */
17
- function renderPic(pic, word, drawing) {
18
- var _a, _b;
17
+ function renderPic(pic, word, wpg) {
18
+ var _a, _b, _c;
19
+ if (wpg === void 0) { wpg = null; }
19
20
  var blip = (_a = pic.blipFill) === null || _a === void 0 ? void 0 : _a.blip;
20
21
  if (blip && blip.src) {
21
22
  var img = document.createElement('img');
@@ -35,15 +36,27 @@ function renderPic(pic, word, drawing) {
35
36
  }
36
37
  var xfrm = (_b = pic.spPr) === null || _b === void 0 ? void 0 : _b.xfrm;
37
38
  if (xfrm) {
38
- var off = xfrm.off;
39
- if (off) {
40
- img.style.left = off.x;
41
- img.style.top = off.y;
39
+ if (wpg) {
40
+ var rect = getRectInGroup(xfrm, (_c = wpg.spPr) === null || _c === void 0 ? void 0 : _c.xfrm);
41
+ if (rect) {
42
+ img.style.position = 'absolute';
43
+ img.style.left = rect.left + 'px';
44
+ img.style.top = rect.top + 'px';
45
+ img.style.width = rect.width + 'px';
46
+ img.style.height = rect.height + 'px';
47
+ }
42
48
  }
43
- var ext = xfrm.ext;
44
- if (ext) {
45
- img.style.width = ext.cx;
46
- img.style.height = ext.cy;
49
+ else {
50
+ var off = xfrm.off;
51
+ if (off) {
52
+ img.style.left = off.x;
53
+ img.style.top = off.y;
54
+ }
55
+ var ext = xfrm.ext;
56
+ if (ext) {
57
+ img.style.width = ext.cx;
58
+ img.style.height = ext.cy;
59
+ }
47
60
  }
48
61
  if (xfrm.rot) {
49
62
  img.style.transform = "rotate(".concat(xfrm.rot, "deg)");
@@ -53,6 +66,162 @@ function renderPic(pic, word, drawing) {
53
66
  }
54
67
  return null;
55
68
  }
69
+ /**
70
+ * 获取在 group 中的位置
71
+ * @param xfrm 元素的位置定义
72
+ * @param groupXfrm 分组中的位置定义
73
+ */
74
+ function getRectInGroup(xfrm, groupXfrm) {
75
+ var off = xfrm.off;
76
+ var width = parseFloat(xfrm.ext.cx.replace('px', ''));
77
+ var height = parseFloat(xfrm.ext.cy.replace('px', ''));
78
+ if (off && groupXfrm.chOff && groupXfrm.ext && groupXfrm.chExt) {
79
+ // 先算缩放比
80
+ var scaleX = parseFloat(groupXfrm.ext.cx.replace('px', '')) /
81
+ parseFloat(groupXfrm.chExt.cx.replace('px', ''));
82
+ var scaleY = parseFloat(groupXfrm.ext.cy.replace('px', '')) /
83
+ parseFloat(groupXfrm.chExt.cy.replace('px', ''));
84
+ var groupOffX = parseFloat(groupXfrm.chOff.x.replace('px', ''));
85
+ var groupOffY = parseFloat(groupXfrm.chOff.y.replace('px', ''));
86
+ var x = parseFloat(off.x.replace('px', ''));
87
+ var y = parseFloat(off.y.replace('px', ''));
88
+ return {
89
+ left: scaleX * (x - groupOffX),
90
+ top: scaleY * (y - groupOffY),
91
+ width: scaleX * width,
92
+ height: scaleY * height
93
+ };
94
+ }
95
+ return null;
96
+ }
97
+ /**
98
+ * 渲染文本框
99
+ */
100
+ function renderWps(word, container, wps, wpg) {
101
+ var e_1, _a;
102
+ var _b;
103
+ if (wpg === void 0) { wpg = null; }
104
+ var wpsStyle = wps.wpsStyle;
105
+ var spPr = wps.spPr;
106
+ dom.applyStyle(container, wps.style);
107
+ if (wpsStyle === null || wpsStyle === void 0 ? void 0 : wpsStyle.fontColor) {
108
+ container.style.color = wpsStyle.fontColor;
109
+ }
110
+ if (spPr === null || spPr === void 0 ? void 0 : spPr.xfrm) {
111
+ var ext = spPr.xfrm.ext;
112
+ if (ext) {
113
+ var width = parseFloat(ext.cx.replace('px', ''));
114
+ var height = parseFloat(ext.cy.replace('px', ''));
115
+ // 在分组中的计算方式不一样,另外在分组中还需要绝对定位
116
+ // 这个计算方法在官方文档里没找到
117
+ if (wpg) {
118
+ container.style.position = 'absolute';
119
+ var rect = getRectInGroup(spPr.xfrm, (_b = wpg.spPr) === null || _b === void 0 ? void 0 : _b.xfrm);
120
+ if (rect) {
121
+ container.style.left = rect.left + 'px';
122
+ container.style.top = rect.top + 'px';
123
+ width = rect.width;
124
+ height = rect.height;
125
+ }
126
+ }
127
+ container.style.width = width + 'px';
128
+ container.style.height = height + 'px';
129
+ if (spPr.geom) {
130
+ dom.appendChild(container, renderGeom.renderGeom(spPr.geom, spPr, width, height, wps.wpsStyle));
131
+ }
132
+ if (spPr.custGeom) {
133
+ dom.appendChild(container, renderCustGeom.renderCustGeom(spPr.custGeom, spPr, width, height, wps.wpsStyle));
134
+ }
135
+ }
136
+ if (spPr.xfrm.rot) {
137
+ container.style.transform = "rotate(".concat(spPr.xfrm.rot, "deg)");
138
+ }
139
+ }
140
+ var txbxContent = wps.txbxContent;
141
+ if (txbxContent.length) {
142
+ // 为了实现垂直居中,将父容器改成 table 布局
143
+ var textContainer = document.createElement('div');
144
+ textContainer.dataset.name = 'textContainer';
145
+ container.style.display = 'table';
146
+ textContainer.style.display = 'table-cell';
147
+ textContainer.style.verticalAlign = 'middle';
148
+ if (wps.style && wps.style['vertical-align']) {
149
+ textContainer.style.verticalAlign = wps.style['vertical-align'];
150
+ // 容器的 vertical-align 需要去掉,虽然也不影响
151
+ container.style.verticalAlign = '';
152
+ }
153
+ dom.appendChild(container, textContainer);
154
+ try {
155
+ for (var txbxContent_1 = tslib.__values(txbxContent), txbxContent_1_1 = txbxContent_1.next(); !txbxContent_1_1.done; txbxContent_1_1 = txbxContent_1.next()) {
156
+ var txbxContentChild = txbxContent_1_1.value;
157
+ if (txbxContentChild instanceof Paragraph.Paragraph) {
158
+ dom.appendChild(textContainer, renderParagraph["default"](word, txbxContentChild));
159
+ }
160
+ else if (txbxContentChild instanceof Table.Table) {
161
+ dom.appendChild(textContainer, renderTable["default"](word, txbxContentChild));
162
+ }
163
+ }
164
+ }
165
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
166
+ finally {
167
+ try {
168
+ if (txbxContent_1_1 && !txbxContent_1_1.done && (_a = txbxContent_1.return)) _a.call(txbxContent_1);
169
+ }
170
+ finally { if (e_1) throw e_1.error; }
171
+ }
172
+ }
173
+ }
174
+ function renderWpg(word, wpg) {
175
+ var e_2, _a, e_3, _b;
176
+ var _c, _d;
177
+ var container = document.createElement('div');
178
+ var wpgContainer = document.createElement('div');
179
+ var spPr = wpg.spPr;
180
+ if (spPr === null || spPr === void 0 ? void 0 : spPr.xfrm) {
181
+ var ext = (_c = spPr === null || spPr === void 0 ? void 0 : spPr.xfrm) === null || _c === void 0 ? void 0 : _c.ext;
182
+ if (ext) {
183
+ wpgContainer.style.width = ext.cx;
184
+ wpgContainer.style.height = ext.cy;
185
+ }
186
+ var rot = (_d = spPr === null || spPr === void 0 ? void 0 : spPr.xfrm) === null || _d === void 0 ? void 0 : _d.rot;
187
+ if (rot) {
188
+ wpgContainer.style.transform = "rotate(".concat(rot, "deg)");
189
+ }
190
+ }
191
+ try {
192
+ for (var _e = tslib.__values(wpg.wps), _f = _e.next(); !_f.done; _f = _e.next()) {
193
+ var wps = _f.value;
194
+ var wpsContainer = document.createElement('div');
195
+ renderWps(word, wpsContainer, wps, wpg);
196
+ dom.appendChild(wpgContainer, wpsContainer);
197
+ }
198
+ }
199
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
200
+ finally {
201
+ try {
202
+ if (_f && !_f.done && (_a = _e.return)) _a.call(_e);
203
+ }
204
+ finally { if (e_2) throw e_2.error; }
205
+ }
206
+ try {
207
+ for (var _g = tslib.__values(wpg.wpg), _h = _g.next(); !_h.done; _h = _g.next()) {
208
+ var childWpg = _h.value;
209
+ dom.appendChild(container, renderWpg(word, childWpg));
210
+ }
211
+ }
212
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
213
+ finally {
214
+ try {
215
+ if (_h && !_h.done && (_b = _g.return)) _b.call(_g);
216
+ }
217
+ finally { if (e_3) throw e_3.error; }
218
+ }
219
+ if (wpg.pic) {
220
+ dom.appendChild(wpgContainer, renderPic(wpg.pic, word, wpg));
221
+ }
222
+ dom.appendChild(container, wpgContainer);
223
+ return container;
224
+ }
56
225
  /**
57
226
  * 渲染图片,目前只支持 picture
58
227
  * http://officeopenxml.com/drwOverview.php
@@ -60,7 +229,6 @@ function renderPic(pic, word, drawing) {
60
229
  *
61
230
  */
62
231
  function renderDrawing(word, drawing, inHeader) {
63
- var e_1, _a;
64
232
  var container = document.createElement('div');
65
233
  if (drawing.position === 'inline') {
66
234
  container.style.display = 'inline-block';
@@ -76,66 +244,10 @@ function renderDrawing(word, drawing, inHeader) {
76
244
  container.dataset.id = drawing.id || '';
77
245
  container.dataset.name = drawing.name || '';
78
246
  if (drawing.wps) {
79
- var wps = drawing.wps;
80
- var wpsStyle = wps.wpsStyle;
81
- var spPr = wps.spPr;
82
- dom.applyStyle(container, wps.style);
83
- if (wpsStyle === null || wpsStyle === void 0 ? void 0 : wpsStyle.fontColor) {
84
- container.style.color = wpsStyle.fontColor;
85
- }
86
- if (spPr === null || spPr === void 0 ? void 0 : spPr.xfrm) {
87
- var ext = spPr.xfrm.ext;
88
- if (ext) {
89
- container.style.width = ext.cx;
90
- container.style.height = ext.cy;
91
- if (spPr.geom) {
92
- var width = parseFloat(ext.cx.replace('px', ''));
93
- var height = parseFloat(ext.cy.replace('px', ''));
94
- dom.appendChild(container, renderGeom.renderGeom(spPr.geom, spPr, width, height, wps.wpsStyle));
95
- }
96
- if (spPr.custGeom) {
97
- var width = parseFloat(ext.cx.replace('px', ''));
98
- var height = parseFloat(ext.cy.replace('px', ''));
99
- dom.appendChild(container, renderCustGeom.renderCustGeom(spPr.custGeom, spPr, width, height, wps.wpsStyle));
100
- }
101
- }
102
- if (spPr.xfrm.rot) {
103
- container.style.transform = "rotate(".concat(spPr.xfrm.rot, "deg)");
104
- }
105
- }
106
- var txbxContent = wps.txbxContent;
107
- if (txbxContent.length) {
108
- // 为了实现垂直居中,将父容器改成 table 布局
109
- var textContainer = document.createElement('div');
110
- textContainer.dataset.name = 'textContainer';
111
- container.style.display = 'table';
112
- textContainer.style.display = 'table-cell';
113
- textContainer.style.verticalAlign = 'middle';
114
- if (wps.style && wps.style['vertical-align']) {
115
- textContainer.style.verticalAlign = wps.style['vertical-align'];
116
- // 容器的 vertical-align 需要去掉,虽然也不影响
117
- container.style.verticalAlign = '';
118
- }
119
- dom.appendChild(container, textContainer);
120
- try {
121
- for (var txbxContent_1 = tslib.__values(txbxContent), txbxContent_1_1 = txbxContent_1.next(); !txbxContent_1_1.done; txbxContent_1_1 = txbxContent_1.next()) {
122
- var txbxContentChild = txbxContent_1_1.value;
123
- if (txbxContentChild instanceof Paragraph.Paragraph) {
124
- dom.appendChild(textContainer, renderParagraph["default"](word, txbxContentChild));
125
- }
126
- else if (txbxContentChild instanceof Table.Table) {
127
- dom.appendChild(textContainer, renderTable["default"](word, txbxContentChild));
128
- }
129
- }
130
- }
131
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
132
- finally {
133
- try {
134
- if (txbxContent_1_1 && !txbxContent_1_1.done && (_a = txbxContent_1.return)) _a.call(txbxContent_1);
135
- }
136
- finally { if (e_1) throw e_1.error; }
137
- }
138
- }
247
+ renderWps(word, container, drawing.wps);
248
+ }
249
+ if (drawing.wpg) {
250
+ dom.appendChild(container, renderWpg(word, drawing.wpg));
139
251
  }
140
252
  // 如果没内容就不渲染了,避免高度导致撑开父节点
141
253
  if (container.children.length === 0) {
@@ -12,15 +12,17 @@ var renderHyperLink = require('./renderHyperLink.js');
12
12
  var renderBookmark = require('./renderBookmark.js');
13
13
  var renderNumbering = require('./renderNumbering.js');
14
14
  var setElementStyle = require('./setElementStyle.js');
15
+ var renderTab = require('./renderTab.js');
15
16
  var OMath = require('../openxml/math/OMath.js');
16
17
  var renderMath = require('./renderMath.js');
18
+ var Tab = require('../openxml/word/Tab.js');
17
19
 
18
20
  /**
19
21
  * 渲染段落
20
22
  * @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上  
21
23
  */
22
24
  function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
23
- var e_1, _a;
25
+ var e_1, _a, e_2, _b, e_3, _c;
24
26
  if (renderEmptySpace === void 0) { renderEmptySpace = true; }
25
27
  if (inHeader === void 0) { inHeader = false; }
26
28
  word.currentParagraph = paragraph;
@@ -35,9 +37,50 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
35
37
  dom.appendChild(p, renderNumbering.renderNumbering(p, word, properties.numPr));
36
38
  }
37
39
  var inFldChar = false;
40
+ if (properties.tabs && properties.tabs.length) {
41
+ // 目前只支持渲染第一个,因为第二个位置取决于前面内容位置,挺麻烦
42
+ // 虽然目前这个实现很 hack,但可以支持常见情况
43
+ dom.appendChild(p, renderTab.renderTab(word, properties.tabs[0], true));
44
+ // 同时删掉第一个 run 中的 tab
45
+ var done = false;
46
+ try {
47
+ for (var _d = tslib.__values(paragraph.children), _e = _d.next(); !_e.done; _e = _d.next()) {
48
+ var child = _e.value;
49
+ if (done) {
50
+ break;
51
+ }
52
+ if (child instanceof Run.Run) {
53
+ try {
54
+ for (var _f = (e_2 = void 0, tslib.__values(child.children)), _g = _f.next(); !_g.done; _g = _f.next()) {
55
+ var runChild = _g.value;
56
+ if (runChild instanceof Tab.Tab) {
57
+ child.children.splice(child.children.indexOf(runChild), 1);
58
+ done = true;
59
+ break;
60
+ }
61
+ }
62
+ }
63
+ catch (e_2_1) { e_2 = { error: e_2_1 }; }
64
+ finally {
65
+ try {
66
+ if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
67
+ }
68
+ finally { if (e_2) throw e_2.error; }
69
+ }
70
+ }
71
+ }
72
+ }
73
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
74
+ finally {
75
+ try {
76
+ if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
77
+ }
78
+ finally { if (e_1) throw e_1.error; }
79
+ }
80
+ }
38
81
  try {
39
- for (var _b = tslib.__values(paragraph.children), _c = _b.next(); !_c.done; _c = _b.next()) {
40
- var child = _c.value;
82
+ for (var _h = tslib.__values(paragraph.children), _j = _h.next(); !_j.done; _j = _h.next()) {
83
+ var child = _j.value;
41
84
  if (child instanceof Run.Run) {
42
85
  if (child.fldChar === 'begin') {
43
86
  inFldChar = true;
@@ -62,12 +105,12 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
62
105
  }
63
106
  }
64
107
  }
65
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
108
+ catch (e_3_1) { e_3 = { error: e_3_1 }; }
66
109
  finally {
67
110
  try {
68
- if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
111
+ if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
69
112
  }
70
- finally { if (e_1) throw e_1.error; }
113
+ finally { if (e_3) throw e_3.error; }
71
114
  }
72
115
  // 空行自动加个空格,不然会没高度
73
116
  if (p.innerHTML === '' && renderEmptySpace) {
@@ -39,12 +39,14 @@ function renderText(span, word, text, paragraph) {
39
39
  var _a;
40
40
  // 简单过滤一下提升性能
41
41
  if (text.indexOf('{{') === -1) {
42
+ var finalText = void 0;
42
43
  if ((_a = paragraph === null || paragraph === void 0 ? void 0 : paragraph.properties) === null || _a === void 0 ? void 0 : _a.autoSpace) {
43
- span.textContent = autoSpace.cjkspace(text.split(''));
44
+ finalText = autoSpace.cjkspace(text.split(''));
44
45
  }
45
46
  else {
46
- span.textContent = text;
47
+ finalText = text;
47
48
  }
49
+ span.textContent = finalText;
48
50
  }
49
51
  else {
50
52
  span.dataset.originText = text;
@@ -52,6 +54,9 @@ function renderText(span, word, text, paragraph) {
52
54
  span.classList.add(VARIABLE_CLASS_NAME);
53
55
  span.textContent = word.replaceText(text);
54
56
  }
57
+ // 大于两个空格才转成 nbsp
58
+ var html = span.innerHTML.split(' ').join('  ');
59
+ span.innerHTML = html;
55
60
  }
56
61
  /**
57
62
  * 更新文档里的所有变量
@@ -25,7 +25,7 @@ function generateDefaultStyle(word) {
25
25
  }
26
26
  var hyphens = ((_a = word.settings) === null || _a === void 0 ? void 0 : _a.autoHyphenation) ? 'hyphens: auto;' : '';
27
27
  var classPrefix = word.getClassPrefix();
28
- return "\n\n\n /** docDefaults **/\n .".concat(classPrefix, " {\n --docx-theme-font-minorHAnsi: Calibri, Helvetica, Arial, 'Helvetica Neue';\n --docx-theme-font-minorEastAsia: 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', 'STHeiti',\n 'Microsoft YaHei';\n }\n\n .").concat(classPrefix, " p {\n margin: 0;\n padding: 0;\n line-height: 1.5;\n ").concat(hyphens, "\n }\n\n .").concat(classPrefix, " .justify:after {\n content: \"\";\n display: inline-block;\n width: 100%;\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
+ return "\n\n\n /** docDefaults **/\n .".concat(classPrefix, " {\n --docx-theme-font-minorHAnsi: Calibri, Helvetica, Arial, 'Helvetica Neue';\n --docx-theme-font-minorEastAsia: 'PingFang SC', 'Microsoft YaHei', 'Hiragino Sans GB', 'STHeiti',\n 'Microsoft YaHei';\n }\n\n .").concat(classPrefix, " p {\n margin: 0;\n padding: 0;\n line-height: 1.5;\n ").concat(hyphens, "\n }\n\n .").concat(classPrefix, " .justify:after {\n content: \"\";\n display: inline-block;\n width: 100%;\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 overflow-wrap: break-word;\n ").concat(defaultRStyle, "\n }\n ");
29
29
  }
30
30
  /**
31
31
  * 生成表格级别样式
@@ -5,4 +5,4 @@ import Word from '../Word';
5
5
  * 不支持 tabs 里的自定义宽度,因为要算渲染后的宽度,比较麻烦
6
6
  * http://officeopenxml.com/WPtab.php
7
7
  */
8
- export declare function renderTab(word: Word, tab: Tab): HTMLElement;
8
+ export declare function renderTab(word: Word, tab: Tab, renderWidth?: boolean): HTMLElement;
@@ -9,12 +9,18 @@ var dom = require('../util/dom.js');
9
9
  * 不支持 tabs 里的自定义宽度,因为要算渲染后的宽度,比较麻烦
10
10
  * http://officeopenxml.com/WPtab.php
11
11
  */
12
- function renderTab(word, tab) {
12
+ function renderTab(word, tab, renderWidth) {
13
+ if (renderWidth === void 0) { renderWidth = false; }
13
14
  var tabElement = dom.createElement('span');
15
+ tabElement.style.display = 'inline-block';
16
+ tabElement.style.width = '2em';
14
17
  tabElement.innerHTML = ' ';
15
18
  if (tab.leader === 'dot') {
16
19
  tabElement.style.borderBottom = '1pt dotted';
17
20
  }
21
+ if (renderWidth && tab.pos && (tab.type === 'start' || tab.type == 'left')) {
22
+ tabElement.style.width = tab.pos;
23
+ }
18
24
  return tabElement;
19
25
  }
20
26
 
@@ -0,0 +1,4 @@
1
+ /**
2
+ * https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
3
+ */
4
+ export declare const get: (obj: any, path: string, defaultValue?: undefined) => any;
@@ -0,0 +1,22 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /**
6
+ * https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
7
+ */
8
+ var get = function (obj, path, defaultValue) {
9
+ if (defaultValue === void 0) { defaultValue = undefined; }
10
+ var travel = function (regexp) {
11
+ return String.prototype.split
12
+ .call(path, regexp)
13
+ .filter(Boolean)
14
+ .reduce(function (res, key) {
15
+ return res !== null && res !== undefined ? res[key] : res;
16
+ }, obj);
17
+ };
18
+ var result = travel(/[,[\]]+?/) || travel(/[,[\].]+?/);
19
+ return result === undefined || result === obj ? defaultValue : result;
20
+ };
21
+
22
+ exports.get = get;
@@ -28,6 +28,7 @@ function replaceText(word, text, data) {
28
28
  return String(result);
29
29
  }
30
30
  else {
31
+ console.warn('var error: [', text, '] not found in data');
31
32
  return '';
32
33
  }
33
34
  }
@@ -129,7 +130,7 @@ function replaceTableRow(word, tr) {
129
130
  }
130
131
  finally { if (e_5) throw e_5.error; }
131
132
  }
132
- table.appendChild(newTr);
133
+ table.insertBefore(newTr, tr);
133
134
  }
134
135
  }
135
136
  catch (e_3_1) { e_3 = { error: e_3_1 }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "office-viewer",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "office 文档在线预览",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",
@@ -65,7 +65,6 @@
65
65
  },
66
66
  "jest": {
67
67
  "testEnvironment": "jsdom",
68
- "collectCoverage": true,
69
68
  "coverageReporters": [
70
69
  "text",
71
70
  "cobertura"
@@ -99,4 +98,4 @@
99
98
  "printBasicPrototype": false
100
99
  }
101
100
  }
102
- }
101
+ }