Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
spec: update snaps
  • Loading branch information
bokuweb committed Mar 11, 2024
commit d4520f14fdd7a85ccd46facb130073014971b6d5
1 change: 1 addition & 0 deletions docx-wasm/js/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -686,5 +686,6 @@ export * from "./tab";
export * from "./json";
export * from "./webextension";
export * from "./header";
export * from "./page-num";
export * from "./footer";
export * from "./image";
38 changes: 25 additions & 13 deletions docx-wasm/js/page-num.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,103 +16,115 @@ export type FrameProperty = {
};

export class PageNum {
frameProperty: FrameProperty = {};
frameProperty: FrameProperty | null = null;

height(h: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.h = h;
return this;
}
hRule(r: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.hRule = r;
return this;
}

hAnchor(a: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.hAnchor = a;
return this;
}

hSpace(s: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.hSpace = s;
return this;
}

vAnchor(a: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.vAnchor = a;
return this;
}

vSpace(s: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.vSpace = s;
return this;
}

width(w: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.w = w;
return this;
}

wrap(w: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.wrap = w;
return this;
}

x(x: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.x = x;
return this;
}

xAlign(a: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.xAlign = a;
return this;
}

y(y: number) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.y = y;
return this;
}

yAlign(y: string) {
this.frameProperty = { ...this.frameProperty };
this.frameProperty.yAlign = y;
return this;
}

build() {
let pageNum = wasm.createPageNum();
if (this.frameProperty.h != null) {
if (this.frameProperty?.h != null) {
pageNum = pageNum.height(this.frameProperty.h);
}
if (this.frameProperty.hRule != null) {
if (this.frameProperty?.hRule != null) {
pageNum = pageNum.h_rule(this.frameProperty.hRule);
}
if (this.frameProperty.hAnchor != null) {
if (this.frameProperty?.hAnchor != null) {
pageNum = pageNum.h_anchor(this.frameProperty.hAnchor);
}
if (this.frameProperty.hSpace != null) {
if (this.frameProperty?.hSpace != null) {
pageNum = pageNum.h_space(this.frameProperty.hSpace);
}
if (this.frameProperty.vAnchor != null) {
if (this.frameProperty?.vAnchor != null) {
pageNum = pageNum.v_anchor(this.frameProperty.vAnchor);
}
if (this.frameProperty.vSpace != null) {
if (this.frameProperty?.vSpace != null) {
pageNum = pageNum.v_space(this.frameProperty.vSpace);
}
if (this.frameProperty.w != null) {
if (this.frameProperty?.w != null) {
pageNum = pageNum.width(this.frameProperty.w);
}
if (this.frameProperty.wrap != null) {
if (this.frameProperty?.wrap != null) {
pageNum = pageNum.wrap(this.frameProperty.wrap);
}
if (this.frameProperty.x != null) {
if (this.frameProperty?.x != null) {
pageNum = pageNum.x(this.frameProperty.x);
}
if (this.frameProperty.xAlign != null) {
if (this.frameProperty?.xAlign != null) {
pageNum = pageNum.x_align(this.frameProperty.xAlign);
}
if (this.frameProperty.y != null) {
if (this.frameProperty?.y != null) {
pageNum = pageNum.y(this.frameProperty.y);
}
if (this.frameProperty.yAlign != null) {
if (this.frameProperty?.yAlign != null) {
pageNum = pageNum.y_align(this.frameProperty.yAlign);
}
return pageNum;
Expand Down
69 changes: 69 additions & 0 deletions docx-wasm/test/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -36217,6 +36217,13 @@ Object {
"hasNumbering": false,
"id": "2948A9FC",
"property": Object {
"frameProperty": Object {
"hAnchor": "margin",
"vAnchor": "text",
"wrap": "none",
"xAlign": "right",
"y": 1,
},
"runProperty": Object {
"style": "ae",
},
Expand Down Expand Up @@ -36358,6 +36365,13 @@ Object {
"hasNumbering": false,
"id": "66B15C28",
"property": Object {
"frameProperty": Object {
"hAnchor": "margin",
"vAnchor": "text",
"wrap": "none",
"xAlign": "right",
"y": 1,
},
"runProperty": Object {
"style": "ae",
},
Expand Down Expand Up @@ -105236,6 +105250,16 @@ Object {
"name": "envelope address",
"next": null,
"paragraphProperty": Object {
"frameProperty": Object {
"h": 2268,
"hAnchor": "page",
"hRule": "exact",
"hSpace": 142,
"w": 6804,
"wrap": "auto",
"xAlign": "center",
"yAlign": "bottom",
},
"indent": Object {
"end": null,
"firstLineChars": null,
Expand Down Expand Up @@ -119878,6 +119902,16 @@ Object {
"name": "envelope address",
"next": null,
"paragraphProperty": Object {
"frameProperty": Object {
"h": 1980,
"hAnchor": "page",
"hRule": "exact",
"hSpace": 180,
"w": 7920,
"wrap": "auto",
"xAlign": "center",
"yAlign": "bottom",
},
"indent": Object {
"end": null,
"firstLineChars": null,
Expand Down Expand Up @@ -137972,6 +138006,13 @@ Object {
"next": null,
"paragraphProperty": Object {
"alignment": "right",
"frameProperty": Object {
"hAnchor": "text",
"hSpace": 181,
"vAnchor": "text",
"wrap": "around",
"y": 1,
},
"runProperty": Object {},
"tabs": Array [],
},
Expand Down Expand Up @@ -139121,6 +139162,9 @@ Object {
"name": "TRILOGO",
"next": null,
"paragraphProperty": Object {
"frameProperty": Object {
"wrap": "around",
},
"lineSpacing": Object {
"before": 5280,
},
Expand Down Expand Up @@ -156530,6 +156574,13 @@ Object {
"hasNumbering": false,
"id": "638F96CF",
"property": Object {
"frameProperty": Object {
"hAnchor": "margin",
"vAnchor": "text",
"wrap": "around",
"xAlign": "center",
"y": 1,
},
"runProperty": Object {},
"tabs": Array [],
},
Expand Down Expand Up @@ -171523,6 +171574,24 @@ exports[`writer should write page size 3`] = `
</w:num></w:numbering>"
`;

exports[`writer should write pageNum in header 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
<Relationship Id=\\"rId1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles\\" Target=\\"styles.xml\\" />
<Relationship Id=\\"rId2\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/fontTable\\" Target=\\"fontTable.xml\\" />
<Relationship Id=\\"rId3\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/settings\\" Target=\\"settings.xml\\" />
<Relationship Id=\\"rId5\\" Type=\\"http://schemas.microsoft.com/office/2011/relationships/commentsExtended\\" Target=\\"commentsExtended.xml\\" />
<Relationship Id=\\"rIdHeader1\\" Type=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships/header\\" Target=\\"header1.xml\\" />
</Relationships>"
`;

exports[`writer should write pageNum in header 2`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\" standalone=\\"yes\\"?>
<w:document xmlns:o=\\"urn:schemas-microsoft-com:office:office\\" xmlns:r=\\"http://schemas.openxmlformats.org/officeDocument/2006/relationships\\" xmlns:v=\\"urn:schemas-microsoft-com:vml\\" xmlns:w=\\"http://schemas.openxmlformats.org/wordprocessingml/2006/main\\" xmlns:w10=\\"urn:schemas-microsoft-com:office:word\\" xmlns:wp=\\"http://schemas.openxmlformats.org/drawingml/2006/wordprocessingDrawing\\" xmlns:wps=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingShape\\" xmlns:wpg=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingGroup\\" xmlns:mc=\\"http://schemas.openxmlformats.org/markup-compatibility/2006\\" xmlns:wp14=\\"http://schemas.microsoft.com/office/word/2010/wordprocessingDrawing\\" xmlns:w14=\\"http://schemas.microsoft.com/office/word/2010/wordml\\" xmlns:w15=\\"http://schemas.microsoft.com/office/word/2012/wordml\\" mc:Ignorable=\\"w14 wp14\\">
<w:body><w:p w14:paraId=\\"00000001\\"><w:pPr><w:rPr /></w:pPr><w:r><w:rPr /><w:t xml:space=\\"preserve\\">Hello world!!</w:t></w:r></w:p><w:sectPr><w:pgSz w:w=\\"11906\\" w:h=\\"16838\\" /><w:pgMar w:top=\\"1985\\" w:right=\\"1701\\" w:bottom=\\"1701\\" w:left=\\"1701\\" w:header=\\"851\\" w:footer=\\"992\\" w:gutter=\\"0\\" /><w:cols w:space=\\"425\\" w:num=\\"1\\" /><w:headerReference w:type=\\"default\\" r:id=\\"rIdHeader1\\" /></w:sectPr></w:body>
</w:document>"
`;

exports[`writer should write paragraph delete 1`] = `
"<?xml version=\\"1.0\\" encoding=\\"UTF-8\\"?>
<Relationships xmlns=\\"http://schemas.openxmlformats.org/package/2006/relationships\\">
Expand Down
16 changes: 16 additions & 0 deletions docx-wasm/test/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1043,4 +1043,20 @@ describe("writer", () => {
}
}
});

test("should write pageNum in header", () => {
const p = new w.Paragraph().addRun(new w.Run().addText("Hello world!!"));
const page = new w.PageNum();
const header = new w.Header().addParagraph(p).addPageNum(page);
const buffer = new w.Docx().header(header).addParagraph(p).build();

writeFileSync("../output/js/header_in_page_num.docx", buffer);

const z = new Zip(Buffer.from(buffer));
for (const e of z.getEntries()) {
if (e.entryName.match(/document.xml/)) {
expect(z.readAsText(e)).toMatchSnapshot();
}
}
});
});