docx-wasm 0.4.12-beta2 → 0.4.12-beta3

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/js/footer.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { PageNum } from "./page-num";
1
2
  import { Paragraph } from "./paragraph";
2
3
  import { Table } from "./table";
3
4
 
4
5
  export class Footer {
5
6
  hasNumberings = false;
6
- children: (Paragraph | Table)[] = [];
7
+ children: (Paragraph | Table | PageNum)[] = [];
7
8
 
8
9
  addParagraph(p: Paragraph) {
9
10
  if (p.hasNumberings) {
@@ -20,4 +21,9 @@ export class Footer {
20
21
  this.children.push(t);
21
22
  return this;
22
23
  }
24
+
25
+ addPageNum(p: PageNum) {
26
+ this.children.push(p);
27
+ return this;
28
+ }
23
29
  }
package/js/header.ts CHANGED
@@ -1,9 +1,10 @@
1
+ import { PageNum } from "./page-num";
1
2
  import { Paragraph } from "./paragraph";
2
3
  import { Table } from "./table";
3
4
 
4
5
  export class Header {
5
6
  hasNumberings = false;
6
- children: (Paragraph | Table)[] = [];
7
+ children: (Paragraph | Table | PageNum)[] = [];
7
8
 
8
9
  addParagraph(p: Paragraph) {
9
10
  if (p.hasNumberings) {
@@ -20,4 +21,9 @@ export class Header {
20
21
  this.children.push(t);
21
22
  return this;
22
23
  }
24
+
25
+ addPageNum(p: PageNum) {
26
+ this.children.push(p);
27
+ return this;
28
+ }
23
29
  }
package/js/index.ts CHANGED
@@ -422,8 +422,11 @@ export class Docx {
422
422
  this.sectionProperty._header.children.forEach((c) => {
423
423
  if (c instanceof Paragraph) {
424
424
  header = header.add_paragraph(build(c));
425
- } else {
425
+ } else if (c instanceof Table) {
426
426
  header = header.add_table(c.build());
427
+ } else {
428
+ const p = c.build();
429
+ header = header.add_page_num(p);
427
430
  }
428
431
  });
429
432
  docx = docx.header(header);
@@ -434,8 +437,11 @@ export class Docx {
434
437
  this.sectionProperty._firstHeader.children.forEach((c) => {
435
438
  if (c instanceof Paragraph) {
436
439
  header = header.add_paragraph(build(c));
437
- } else {
440
+ } else if (c instanceof Table) {
438
441
  header = header.add_table(c.build());
442
+ } else {
443
+ const p = c.build();
444
+ header = header.add_page_num(p);
439
445
  }
440
446
  });
441
447
  docx = docx.first_header(header);
@@ -446,8 +452,11 @@ export class Docx {
446
452
  this.sectionProperty._evenHeader.children.forEach((c) => {
447
453
  if (c instanceof Paragraph) {
448
454
  header = header.add_paragraph(build(c));
449
- } else {
455
+ } else if (c instanceof Table) {
450
456
  header = header.add_table(c.build());
457
+ } else {
458
+ const p = c.build();
459
+ header = header.add_page_num(p);
451
460
  }
452
461
  });
453
462
  docx = docx.even_header(header);
@@ -458,8 +467,11 @@ export class Docx {
458
467
  this.sectionProperty._footer.children.forEach((c) => {
459
468
  if (c instanceof Paragraph) {
460
469
  footer = footer.add_paragraph(build(c));
461
- } else {
470
+ } else if (c instanceof Table) {
462
471
  footer = footer.add_table(c.build());
472
+ } else {
473
+ const p = c.build();
474
+ footer = footer.add_page_num(p);
463
475
  }
464
476
  });
465
477
  docx = docx.footer(footer);
@@ -470,8 +482,11 @@ export class Docx {
470
482
  this.sectionProperty._firstFooter.children.forEach((c) => {
471
483
  if (c instanceof Paragraph) {
472
484
  footer = footer.add_paragraph(build(c));
473
- } else {
485
+ } else if (c instanceof Table) {
474
486
  footer = footer.add_table(c.build());
487
+ } else {
488
+ const p = c.build();
489
+ footer = footer.add_page_num(p);
475
490
  }
476
491
  });
477
492
  docx = docx.first_footer(footer);
@@ -482,8 +497,11 @@ export class Docx {
482
497
  this.sectionProperty._evenFooter.children.forEach((c) => {
483
498
  if (c instanceof Paragraph) {
484
499
  footer = footer.add_paragraph(build(c));
485
- } else {
500
+ } else if (c instanceof Table) {
486
501
  footer = footer.add_table(c.build());
502
+ } else {
503
+ const p = c.build();
504
+ footer = footer.add_page_num(p);
487
505
  }
488
506
  });
489
507
  docx = docx.even_footer(footer);
@@ -668,5 +686,6 @@ export * from "./tab";
668
686
  export * from "./json";
669
687
  export * from "./webextension";
670
688
  export * from "./header";
689
+ export * from "./page-num";
671
690
  export * from "./footer";
672
691
  export * from "./image";
package/js/page-num.ts ADDED
@@ -0,0 +1,132 @@
1
+ import * as wasm from "./pkg/docx_wasm";
2
+
3
+ export type FrameProperty = {
4
+ h?: number;
5
+ hRule?: string;
6
+ hAnchor?: string;
7
+ hSpace?: number;
8
+ vAnchor?: string;
9
+ vSpace?: number;
10
+ w?: number;
11
+ wrap?: string;
12
+ x?: number;
13
+ xAlign?: string;
14
+ y?: number;
15
+ yAlign?: string;
16
+ };
17
+
18
+ export class PageNum {
19
+ frameProperty: FrameProperty | null = null;
20
+
21
+ height(h: number) {
22
+ this.frameProperty = { ...this.frameProperty };
23
+ this.frameProperty.h = h;
24
+ return this;
25
+ }
26
+ hRule(r: string) {
27
+ this.frameProperty = { ...this.frameProperty };
28
+ this.frameProperty.hRule = r;
29
+ return this;
30
+ }
31
+
32
+ hAnchor(a: string) {
33
+ this.frameProperty = { ...this.frameProperty };
34
+ this.frameProperty.hAnchor = a;
35
+ return this;
36
+ }
37
+
38
+ hSpace(s: number) {
39
+ this.frameProperty = { ...this.frameProperty };
40
+ this.frameProperty.hSpace = s;
41
+ return this;
42
+ }
43
+
44
+ vAnchor(a: string) {
45
+ this.frameProperty = { ...this.frameProperty };
46
+ this.frameProperty.vAnchor = a;
47
+ return this;
48
+ }
49
+
50
+ vSpace(s: number) {
51
+ this.frameProperty = { ...this.frameProperty };
52
+ this.frameProperty.vSpace = s;
53
+ return this;
54
+ }
55
+
56
+ width(w: number) {
57
+ this.frameProperty = { ...this.frameProperty };
58
+ this.frameProperty.w = w;
59
+ return this;
60
+ }
61
+
62
+ wrap(w: string) {
63
+ this.frameProperty = { ...this.frameProperty };
64
+ this.frameProperty.wrap = w;
65
+ return this;
66
+ }
67
+
68
+ x(x: number) {
69
+ this.frameProperty = { ...this.frameProperty };
70
+ this.frameProperty.x = x;
71
+ return this;
72
+ }
73
+
74
+ xAlign(a: string) {
75
+ this.frameProperty = { ...this.frameProperty };
76
+ this.frameProperty.xAlign = a;
77
+ return this;
78
+ }
79
+
80
+ y(y: number) {
81
+ this.frameProperty = { ...this.frameProperty };
82
+ this.frameProperty.y = y;
83
+ return this;
84
+ }
85
+
86
+ yAlign(y: string) {
87
+ this.frameProperty = { ...this.frameProperty };
88
+ this.frameProperty.yAlign = y;
89
+ return this;
90
+ }
91
+
92
+ build() {
93
+ let pageNum = wasm.createPageNum();
94
+ if (this.frameProperty?.h != null) {
95
+ pageNum = pageNum.height(this.frameProperty.h);
96
+ }
97
+ if (this.frameProperty?.hRule != null) {
98
+ pageNum = pageNum.h_rule(this.frameProperty.hRule);
99
+ }
100
+ if (this.frameProperty?.hAnchor != null) {
101
+ pageNum = pageNum.h_anchor(this.frameProperty.hAnchor);
102
+ }
103
+ if (this.frameProperty?.hSpace != null) {
104
+ pageNum = pageNum.h_space(this.frameProperty.hSpace);
105
+ }
106
+ if (this.frameProperty?.vAnchor != null) {
107
+ pageNum = pageNum.v_anchor(this.frameProperty.vAnchor);
108
+ }
109
+ if (this.frameProperty?.vSpace != null) {
110
+ pageNum = pageNum.v_space(this.frameProperty.vSpace);
111
+ }
112
+ if (this.frameProperty?.w != null) {
113
+ pageNum = pageNum.width(this.frameProperty.w);
114
+ }
115
+ if (this.frameProperty?.wrap != null) {
116
+ pageNum = pageNum.wrap(this.frameProperty.wrap);
117
+ }
118
+ if (this.frameProperty?.x != null) {
119
+ pageNum = pageNum.x(this.frameProperty.x);
120
+ }
121
+ if (this.frameProperty?.xAlign != null) {
122
+ pageNum = pageNum.x_align(this.frameProperty.xAlign);
123
+ }
124
+ if (this.frameProperty?.y != null) {
125
+ pageNum = pageNum.y(this.frameProperty.y);
126
+ }
127
+ if (this.frameProperty?.yAlign != null) {
128
+ pageNum = pageNum.y_align(this.frameProperty.yAlign);
129
+ }
130
+ return pageNum;
131
+ }
132
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docx-wasm",
3
- "version": "0.4.12-beta2",
3
+ "version": "0.4.12-beta3",
4
4
  "main": "dist/node/index.js",
5
5
  "browser": "dist/web/index.js",
6
6
  "author": "bokuweb <bokuweb12@gmail.com>",