office-viewer 0.1.4 → 0.1.5

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.
@@ -11,14 +11,13 @@ import { setElementStyle } from './setElementStyle.js';
11
11
  import { renderTab } from './renderTab.js';
12
12
  import { OMath } from '../openxml/math/OMath.js';
13
13
  import { renderOMath } from './renderMath.js';
14
- import { Tab } from '../openxml/word/Tab.js';
15
14
 
16
15
  /**
17
16
  * 渲染段落
18
17
  * @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上  
19
18
  */
20
19
  function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
21
- var e_1, _a, e_2, _b, e_3, _c;
20
+ var e_1, _a;
22
21
  if (renderEmptySpace === void 0) { renderEmptySpace = true; }
23
22
  if (inHeader === void 0) { inHeader = false; }
24
23
  word.currentParagraph = paragraph;
@@ -38,45 +37,25 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
38
37
  // 虽然目前这个实现很 hack,但可以支持常见情况
39
38
  appendChild(p, renderTab(word, properties.tabs[0], true));
40
39
  // 同时删掉第一个 run 中的 tab
41
- var done = false;
42
- try {
43
- for (var _d = __values(paragraph.children), _e = _d.next(); !_e.done; _e = _d.next()) {
44
- var child = _e.value;
45
- if (done) {
46
- break;
47
- }
48
- if (child instanceof Run) {
49
- try {
50
- for (var _f = (e_2 = void 0, __values(child.children)), _g = _f.next(); !_g.done; _g = _f.next()) {
51
- var runChild = _g.value;
52
- if (runChild instanceof Tab) {
53
- child.children.splice(child.children.indexOf(runChild), 1);
54
- done = true;
55
- break;
56
- }
57
- }
58
- }
59
- catch (e_2_1) { e_2 = { error: e_2_1 }; }
60
- finally {
61
- try {
62
- if (_g && !_g.done && (_b = _f.return)) _b.call(_f);
63
- }
64
- finally { if (e_2) throw e_2.error; }
65
- }
66
- }
67
- }
68
- }
69
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
70
- finally {
71
- try {
72
- if (_e && !_e.done && (_a = _d.return)) _a.call(_d);
73
- }
74
- finally { if (e_1) throw e_1.error; }
75
- }
40
+ // let done = false;
41
+ // for (const child of paragraph.children) {
42
+ // if (done) {
43
+ // break;
44
+ // }
45
+ // if (child instanceof Run) {
46
+ // for (const runChild of child.children) {
47
+ // if (runChild instanceof Tab) {
48
+ // child.children.splice(child.children.indexOf(runChild), 1);
49
+ // done = true;
50
+ // break;
51
+ // }
52
+ // }
53
+ // }
54
+ // }
76
55
  }
77
56
  try {
78
- for (var _h = __values(paragraph.children), _j = _h.next(); !_j.done; _j = _h.next()) {
79
- var child = _j.value;
57
+ for (var _b = __values(paragraph.children), _c = _b.next(); !_c.done; _c = _b.next()) {
58
+ var child = _c.value;
80
59
  if (child instanceof Run) {
81
60
  if (child.fldChar === 'begin') {
82
61
  inFldChar = true;
@@ -101,12 +80,12 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
101
80
  }
102
81
  }
103
82
  }
104
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
83
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
105
84
  finally {
106
85
  try {
107
- if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
86
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
108
87
  }
109
- finally { if (e_3) throw e_3.error; }
88
+ finally { if (e_1) throw e_1.error; }
110
89
  }
111
90
  // 空行自动加个空格,不然会没高度
112
91
  if (p.innerHTML === '' && renderEmptySpace) {
@@ -35,7 +35,13 @@ function canMerge(element) {
35
35
  if (childChild.tagName === 'w:t') {
36
36
  hasText = true;
37
37
  textHasSpace = childChild.getAttribute('xml:space') === 'preserve';
38
- break;
38
+ if (textHasSpace) {
39
+ break;
40
+ }
41
+ }
42
+ // 有 tab 的情况下不能合并
43
+ if (childChild.tagName === 'w:tab') {
44
+ return false;
39
45
  }
40
46
  }
41
47
  }
@@ -15,14 +15,13 @@ var setElementStyle = require('./setElementStyle.js');
15
15
  var renderTab = require('./renderTab.js');
16
16
  var OMath = require('../openxml/math/OMath.js');
17
17
  var renderMath = require('./renderMath.js');
18
- var Tab = require('../openxml/word/Tab.js');
19
18
 
20
19
  /**
21
20
  * 渲染段落
22
21
  * @param renderEmptySpace 如果是 true 的话,当内容为空时会自动加上  
23
22
  */
24
23
  function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
25
- var e_1, _a, e_2, _b, e_3, _c;
24
+ var e_1, _a;
26
25
  if (renderEmptySpace === void 0) { renderEmptySpace = true; }
27
26
  if (inHeader === void 0) { inHeader = false; }
28
27
  word.currentParagraph = paragraph;
@@ -42,45 +41,25 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
42
41
  // 虽然目前这个实现很 hack,但可以支持常见情况
43
42
  dom.appendChild(p, renderTab.renderTab(word, properties.tabs[0], true));
44
43
  // 同时删掉第一个 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
- }
44
+ // let done = false;
45
+ // for (const child of paragraph.children) {
46
+ // if (done) {
47
+ // break;
48
+ // }
49
+ // if (child instanceof Run) {
50
+ // for (const runChild of child.children) {
51
+ // if (runChild instanceof Tab) {
52
+ // child.children.splice(child.children.indexOf(runChild), 1);
53
+ // done = true;
54
+ // break;
55
+ // }
56
+ // }
57
+ // }
58
+ // }
80
59
  }
81
60
  try {
82
- for (var _h = tslib.__values(paragraph.children), _j = _h.next(); !_j.done; _j = _h.next()) {
83
- var child = _j.value;
61
+ for (var _b = tslib.__values(paragraph.children), _c = _b.next(); !_c.done; _c = _b.next()) {
62
+ var child = _c.value;
84
63
  if (child instanceof Run.Run) {
85
64
  if (child.fldChar === 'begin') {
86
65
  inFldChar = true;
@@ -105,12 +84,12 @@ function renderParagraph(word, paragraph, renderEmptySpace, inHeader) {
105
84
  }
106
85
  }
107
86
  }
108
- catch (e_3_1) { e_3 = { error: e_3_1 }; }
87
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
109
88
  finally {
110
89
  try {
111
- if (_j && !_j.done && (_c = _h.return)) _c.call(_h);
90
+ if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
112
91
  }
113
- finally { if (e_3) throw e_3.error; }
92
+ finally { if (e_1) throw e_1.error; }
114
93
  }
115
94
  // 空行自动加个空格,不然会没高度
116
95
  if (p.innerHTML === '' && renderEmptySpace) {
@@ -39,7 +39,13 @@ function canMerge(element) {
39
39
  if (childChild.tagName === 'w:t') {
40
40
  hasText = true;
41
41
  textHasSpace = childChild.getAttribute('xml:space') === 'preserve';
42
- break;
42
+ if (textHasSpace) {
43
+ break;
44
+ }
45
+ }
46
+ // 有 tab 的情况下不能合并
47
+ if (childChild.tagName === 'w:tab') {
48
+ return false;
43
49
  }
44
50
  }
45
51
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "office-viewer",
3
- "version": "0.1.4",
3
+ "version": "0.1.5",
4
4
  "description": "office 文档在线预览",
5
5
  "main": "lib/index.js",
6
6
  "module": "esm/index.js",