office-viewer 0.3.14 → 0.3.16

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 (43) hide show
  1. package/esm/Word.d.ts +4 -0
  2. package/esm/Word.js +34 -0
  3. package/esm/createOfficeViewer.js +33 -13
  4. package/esm/excel/render/dnd/handleMouseup.js +3 -2
  5. package/esm/excel/render/drawing/chart/buildLabel.d.ts +1 -62
  6. package/esm/excel/render/drawing/chart/convertLegend.d.ts +1 -1
  7. package/esm/excel/render/drawing/chart/fromAreaChart.d.ts +1 -62
  8. package/esm/excel/render/drawing/chart/fromLineChart.d.ts +1 -62
  9. package/esm/node_modules/xlsx/xlsx.mjs.js +24451 -0
  10. package/esm/openxml/word/Note.d.ts +1 -0
  11. package/esm/openxml/word/Note.js +3 -0
  12. package/esm/openxml/word/Run.d.ts +6 -1
  13. package/esm/openxml/word/Run.js +14 -1
  14. package/esm/util/fflate.js +2 -2
  15. package/esm/util/saxes.js +1 -1
  16. package/esm/word/render/renderNotes.js +19 -0
  17. package/esm/word/render/renderRun.js +17 -1
  18. package/lib/Word.d.ts +4 -0
  19. package/lib/Word.js +34 -0
  20. package/lib/createOfficeViewer.d.ts +1 -1
  21. package/lib/createOfficeViewer.js +33 -13
  22. package/lib/excel/formula/builtinFunctions.d.ts +1 -1
  23. package/lib/excel/lang/lang.d.ts +1 -1
  24. package/lib/excel/render/dnd/handleMouseup.js +3 -2
  25. package/lib/excel/render/dnd/mousedownColHeader.d.ts +1 -1
  26. package/lib/excel/render/dnd/mousedownRowHeader.d.ts +1 -1
  27. package/lib/excel/render/drawing/chart/buildLabel.d.ts +1 -62
  28. package/lib/excel/render/drawing/chart/convertLegend.d.ts +1 -1
  29. package/lib/excel/render/drawing/chart/fromAreaChart.d.ts +1 -62
  30. package/lib/excel/render/drawing/chart/fromLineChart.d.ts +1 -62
  31. package/lib/node_modules/xlsx/xlsx.mjs.js +24472 -0
  32. package/lib/openxml/word/Note.d.ts +1 -0
  33. package/lib/openxml/word/Note.js +3 -0
  34. package/lib/openxml/word/Run.d.ts +6 -1
  35. package/lib/openxml/word/Run.js +14 -0
  36. package/lib/package/XMLPackageParser.d.ts +1 -1
  37. package/lib/package/ZipPackageParser.d.ts +1 -1
  38. package/lib/util/fflate.js +2 -2
  39. package/lib/util/saxes.js +1 -1
  40. package/lib/word/parse/jcToTextAlign.d.ts +1 -1
  41. package/lib/word/render/renderNotes.js +19 -0
  42. package/lib/word/render/renderRun.js +16 -0
  43. package/package.json +8 -3
@@ -8,5 +8,6 @@ export type NoteChild = Paragraph | Table;
8
8
  export declare class Note {
9
9
  children: NoteChild[];
10
10
  addChild(child: NoteChild): void;
11
+ isEmpty(): boolean;
11
12
  static fromXML(word: Word, element: Element): Note;
12
13
  }
@@ -16,6 +16,9 @@ var Note = /** @class */ (function () {
16
16
  Note.prototype.addChild = function (child) {
17
17
  this.children.push(child);
18
18
  };
19
+ Note.prototype.isEmpty = function () {
20
+ return this.children.length === 0;
21
+ };
19
22
  Note.fromXML = function (word, element) {
20
23
  var e_1, _a;
21
24
  var note = new Note();
@@ -23,7 +23,12 @@ export declare class Text {
23
23
  text: string;
24
24
  constructor(text: string | number);
25
25
  }
26
- type RunChild = Break | Drawing | Text | Tab | Pict | Ruby | InstrText | Sym | SoftHyphen | Separator | NoBreakHyphen;
26
+ export declare class FootnoteRef {
27
+ id: string;
28
+ type: 'footnote' | 'endnote';
29
+ constructor(id: string, type: 'footnote' | 'endnote');
30
+ }
31
+ type RunChild = Break | Drawing | Text | Tab | Pict | Ruby | InstrText | Sym | SoftHyphen | Separator | NoBreakHyphen | FootnoteRef;
27
32
  export declare class Run {
28
33
  properties: RunPr;
29
34
  children: RunChild[];
@@ -23,6 +23,13 @@ var Text = /** @class */ (function () {
23
23
  }
24
24
  return Text;
25
25
  }());
26
+ var FootnoteRef = /** @class */ (function () {
27
+ function FootnoteRef(id, type) {
28
+ this.id = id;
29
+ this.type = type;
30
+ }
31
+ return FootnoteRef;
32
+ }());
26
33
  var Run = /** @class */ (function () {
27
34
  function Run() {
28
35
  this.properties = {};
@@ -100,6 +107,12 @@ var Run = /** @class */ (function () {
100
107
  case 'w:noBreakHyphen':
101
108
  run.addChild(new NoBreakHyphen.NoBreakHyphen());
102
109
  break;
110
+ case 'w:footnoteReference':
111
+ run.addChild(new FootnoteRef(child.getAttribute('w:id') || '', 'footnote'));
112
+ break;
113
+ case 'w:endnoteReference':
114
+ run.addChild(new FootnoteRef(child.getAttribute('w:id') || '', 'endnote'));
115
+ break;
103
116
  case 'w:separator':
104
117
  run.addChild(new Separator.Separator());
105
118
  break;
@@ -123,5 +136,6 @@ var Run = /** @class */ (function () {
123
136
  return Run;
124
137
  }());
125
138
 
139
+ exports.FootnoteRef = FootnoteRef;
126
140
  exports.Run = Run;
127
141
  exports.Text = Text;
@@ -20,7 +20,7 @@ export default class XMLPackageParser implements PackageParser {
20
20
  /**
21
21
  * 在 xml 下基本不用这个
22
22
  */
23
- getFileByType(filePath: string, type: 'string' | 'blob'): string | Uint8Array | Blob | null;
23
+ getFileByType(filePath: string, type: 'string' | 'blob'): string | Blob | Uint8Array | null;
24
24
  /**
25
25
  * 读取文本内容
26
26
  */
@@ -18,7 +18,7 @@ export default class ZipPackageParser implements PackageParser {
18
18
  /**
19
19
  * 根据类型读取文件
20
20
  */
21
- getFileByType(filePath: string, type?: 'string' | 'blob' | 'uint8array'): string | Uint8Array | Blob | null;
21
+ getFileByType(filePath: string, type?: 'string' | 'blob' | 'uint8array'): string | Blob | Uint8Array | null;
22
22
  /**
23
23
  * 读取文本内容
24
24
  */
@@ -569,8 +569,8 @@ var wblk = function (dat, out, final, syms, lf, df, eb, li, bs, bl, p) {
569
569
  wbits(out, p + 3 * i, lct[clim[i]]);
570
570
  p += 3 * nlcc;
571
571
  var lcts = [lclt, lcdt];
572
- for (var it_1 = 0; it_1 < 2; ++it_1) {
573
- var clct = lcts[it_1];
572
+ for (var it = 0; it < 2; ++it) {
573
+ var clct = lcts[it];
574
574
  for (var i = 0; i < clct.length; ++i) {
575
575
  var len = clct[i] & 31;
576
576
  wbits(out, p, llm[len]), (p += lct[len]);
package/lib/util/saxes.js CHANGED
@@ -317,7 +317,7 @@ var SaxesParser = /** @class */ (function () {
317
317
  this.closedRoot =
318
318
  this.sawRoot =
319
319
  fragmentOpt;
320
- // An XML declaration is intially possible only when parsing whole
320
+ // An XML declaration is initially possible only when parsing whole
321
321
  // documents.
322
322
  this.xmlDeclPossible = !fragmentOpt;
323
323
  this.xmlDeclExpects = ['version'];
@@ -2,4 +2,4 @@
2
2
  *
3
3
  * http://webapp.docx4java.org/OnlineDemo/ecma376/WordML/ST_Jc.html
4
4
  */
5
- export declare function jcToTextAlign(jc: string): "left" | "center" | "right" | "justify";
5
+ export declare function jcToTextAlign(jc: string): "center" | "justify" | "left" | "right";
@@ -14,12 +14,23 @@ var renderTable = require('./renderTable.js');
14
14
  */
15
15
  function renderNote(word, noteRoot, type, id, note) {
16
16
  var e_1, _a;
17
+ var _b;
17
18
  var noteChild = note.children;
18
19
  var noteElement = dom.createElement('div');
20
+ noteElement.style.display = 'flex';
21
+ noteElement.style.alignItems = 'baseline';
19
22
  var mark = dom.createElement('a');
20
23
  var fName = type + '-' + id;
21
24
  mark.name = fName;
22
25
  mark.id = fName;
26
+ var index = (_b = word.noteIndexMap[fName]) !== null && _b !== void 0 ? _b : id;
27
+ var indexAnchor = dom.createElement('a');
28
+ indexAnchor.style.flexShrink = '0';
29
+ indexAnchor.style.marginRight = '0.3em';
30
+ indexAnchor.style.textDecoration = 'none';
31
+ indexAnchor.textContent = '[' + String(index) + ']';
32
+ noteElement.appendChild(mark);
33
+ noteElement.appendChild(indexAnchor);
23
34
  noteRoot.appendChild(noteElement);
24
35
  try {
25
36
  for (var noteChild_1 = tslib.__values(noteChild), noteChild_1_1 = noteChild_1.next(); !noteChild_1_1.done; noteChild_1_1 = noteChild_1.next()) {
@@ -62,11 +73,19 @@ function renderNotes(word) {
62
73
  var noteRoot = dom.createElement('div');
63
74
  if (hasNote(word.footNotes)) {
64
75
  for (var fId in word.footNotes) {
76
+ if (fId === '0' || fId === '-1')
77
+ continue;
78
+ if (word.footNotes[fId].isEmpty())
79
+ continue;
65
80
  renderNote(word, noteRoot, 'footnote', fId, word.footNotes[fId]);
66
81
  }
67
82
  }
68
83
  if (hasNote(word.endNotes)) {
69
84
  for (var fId in word.endNotes || {}) {
85
+ if (fId === '0' || fId === '-1')
86
+ continue;
87
+ if (word.endNotes[fId].isEmpty())
88
+ continue;
70
89
  renderNote(word, noteRoot, 'endnote', fId, word.endNotes[fId]);
71
90
  }
72
91
  }
@@ -131,6 +131,22 @@ function renderRun(word, run, paragraph, inFldChar, inHeader) {
131
131
  else if (child instanceof Separator.Separator) {
132
132
  dom.appendChild(span, renderSeparator.renderSeparator());
133
133
  }
134
+ else if (child instanceof Run.FootnoteRef) {
135
+ var target = child.type + '-' + child.id;
136
+ var displayIndex = word.noteIndexMap[target];
137
+ // 如果脚注内容为空(不在映射中),不渲染引用
138
+ if (displayIndex == null)
139
+ break;
140
+ var anchor = dom.createElement('a');
141
+ anchor.href = '#' + target;
142
+ anchor.style.verticalAlign = 'super';
143
+ anchor.style.fontSize = '0.75em';
144
+ anchor.style.textDecoration = 'none';
145
+ anchor.dataset.noteId = child.id;
146
+ anchor.dataset.noteType = child.type;
147
+ anchor.textContent = '[' + String(displayIndex) + ']';
148
+ dom.appendChild(span, anchor);
149
+ }
134
150
  else {
135
151
  console.warn('unknown child', child);
136
152
  }
package/package.json CHANGED
@@ -1,6 +1,10 @@
1
1
  {
2
2
  "name": "office-viewer",
3
- "version": "0.3.14",
3
+ "repository": {
4
+ "type": "git",
5
+ "url": "https://github.com/baidu/amis-inner.git"
6
+ },
7
+ "version": "0.3.16",
4
8
  "description": "office 文档在线预览",
5
9
  "main": "lib/index.js",
6
10
  "module": "esm/index.js",
@@ -71,6 +75,7 @@
71
75
  "@rollup/plugin-typescript": "^8.3.4",
72
76
  "@swc/jest": "^0.2.34",
73
77
  "@testing-library/jest-dom": "^5.17.0",
78
+ "@types/node": "^14.0.24",
74
79
  "@types/jest": "^28.1.0",
75
80
  "@types/prettier": "^2.7.3",
76
81
  "amis-formula": "^2.7.2",
@@ -87,7 +92,7 @@
87
92
  "xml-formatter": "^3.3.2"
88
93
  },
89
94
  "peerDependencies": {
90
- "echarts": "^5.4.0"
95
+ "echarts": "^5.5.1"
91
96
  },
92
97
  "jest": {
93
98
  "testEnvironment": "jsdom",
@@ -119,4 +124,4 @@
119
124
  "printBasicPrototype": false
120
125
  }
121
126
  }
122
- }
127
+ }