Compare commits
24 Commits
8.3.0
...
feature/im
Author | SHA1 | Date | |
---|---|---|---|
7d53e5d5f2 | |||
d23f453d28 | |||
6c28f8bab0 | |||
10b87b5a70 | |||
6b6f9d7ed4 | |||
0434d00ff7 | |||
7e3acc25b9 | |||
62ad8f12b7 | |||
a6a656f1a0 | |||
1bf36009e8 | |||
86bdf3e199 | |||
a3c796aae3 | |||
dbe0586f70 | |||
7e2538dffc | |||
c3080ff9d9 | |||
772fc8462a | |||
e194780cd1 | |||
5b80ea32d7 | |||
31b7e07ab3 | |||
939d418af1 | |||
4258dd2a2e | |||
b7334a1ab5 | |||
9229f45d59 | |||
2bd4aacdd5 |
@ -54,7 +54,8 @@
|
||||
"\\.to\\.include\\.members\\(\\[[^\\]]+]\\)",
|
||||
"/new [a-zA-Z]+\\({[^£]+}\\)/g",
|
||||
"/<element name=\"[a-z]+\"/gi",
|
||||
"/<attribute name=\"[a-z]+\"/gi"
|
||||
"/<attribute name=\"[a-z]+\"/gi",
|
||||
"/key: \".+\"/"
|
||||
],
|
||||
"ignorePaths": ["package.json", "docs/api", "*.docx", "build"],
|
||||
"allowCompoundWords": true,
|
||||
|
@ -92,6 +92,7 @@ rules:
|
||||
format:
|
||||
- camelCase
|
||||
- PascalCase
|
||||
- UPPER_CASE # for constants
|
||||
filter:
|
||||
regex: (^[a-z]+:.+)|_attr|[0-9]
|
||||
match: false
|
||||
|
12
.github/actions/install-and-build/action.yml
vendored
Normal file
12
.github/actions/install-and-build/action.yml
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
name: Install dependencies and build ⚙️
|
||||
description: Install dependencies and build
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Install Dependencies
|
||||
shell: bash
|
||||
run: npm ci --force
|
||||
- name: Build
|
||||
shell: bash
|
||||
run: npm run build
|
14
.github/actions/validate-docx/action.yml
vendored
Normal file
14
.github/actions/validate-docx/action.yml
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
name: Extract and Validate Document ⚙️
|
||||
description: Extract the document and validate the XML against the schema.
|
||||
|
||||
runs:
|
||||
using: composite
|
||||
steps:
|
||||
- name: Extract Word Document
|
||||
shell: bash
|
||||
run: npm run extract
|
||||
- name: Validate XML
|
||||
uses: ChristophWurst/xmllint-action@v1
|
||||
with:
|
||||
xml-file: build/extracted-doc/word/document.xml
|
||||
xml-schema-file: ooxml-schemas/microsoft/wml-2010.xsd
|
9
.github/workflows/default.yml
vendored
9
.github/workflows/default.yml
vendored
@ -14,10 +14,7 @@ jobs:
|
||||
steps:
|
||||
- name: Checkout Repo
|
||||
uses: actions/checkout@master
|
||||
- name: Install Dependencies
|
||||
run: npm ci --force
|
||||
- name: Build
|
||||
run: npm run build
|
||||
- uses: "./.github/actions/install-and-build"
|
||||
- name: Archive Production Artifact
|
||||
uses: actions/upload-artifact@master
|
||||
with:
|
||||
@ -32,7 +29,7 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: npm ci --force
|
||||
- name: Test
|
||||
run: npm run test.ci
|
||||
run: npm run test:ci
|
||||
- name: Codecov
|
||||
uses: codecov/codecov-action@v3
|
||||
with:
|
||||
@ -57,7 +54,7 @@ jobs:
|
||||
- name: Install Dependencies
|
||||
run: npm ci --force
|
||||
- name: Prettier
|
||||
run: npm run style
|
||||
run: npm run prettier
|
||||
cspell:
|
||||
name: CSpell
|
||||
runs-on: ubuntu-latest
|
||||
|
1503
.github/workflows/demos.yml
vendored
1503
.github/workflows/demos.yml
vendored
File diff suppressed because it is too large
Load Diff
@ -3,6 +3,142 @@
|
||||
import * as fs from "fs";
|
||||
import { AlignmentType, Document, Footer, Header, Packer, PageBreak, PageNumber, Paragraph, TextRun } from "docx";
|
||||
|
||||
// cspell: disable
|
||||
const createLoremIpsumParagraphs = () => [
|
||||
new Paragraph(
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aliquam accumsan condimentum elit ut placerat. Integer vitae justo est. Quisque tempus augue eu diam pulvinar aliquam. Pellentesque neque sem, posuere eget augue pretium, feugiat mattis diam. Mauris libero arcu, elementum sit amet nunc sed, vestibulum posuere sapien. Nullam",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"ultrices efficitur magna et commodo. Morbi vitae dolor vulputate, dapibus ipsum in, finibus enim. Aliquam dapibus tellus libero. Nullam nulla eros, ullamcorper eu risus at, luctus aliquet nunc. Nunc dictum turpis eu quam suscipit porta. In rutrum scelerisque nunc in consectetur. Pellentesque ut nibh eget neque congue auctor. Nunc dapibus massa elit, vel cursus metus condimentum et. Nunc venenatis dolor eu lobortis fringilla. Nulla sed risus id lectus scelerisque sollicitudin. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Nulla lobortis et purus convallis ullamcorper. Nunc scelerisque, urna eu vestibulum feugiat, orci turpis pulvinar odio, vitae faucibus elit tortor et urna. Curabitur eros mauris, mollis a vestibulum nec, vestibulum sed velit. Nam semper metus ut felis ultricies rutrum. Cras hendrerit eros vel placerat vulputate. Proin placerat ",
|
||||
),
|
||||
new Paragraph(
|
||||
"mollis lacus a ultricies. Mauris vel turpis vitae purus suscipit dignissim. Donec egestas molestie libero in suscipit. Aenean auctor tellus convallis eros porttitor, id vehicula risus commodo. Sed accumsan turpis elit, eget molestie tortor efficitur eget. Aliquam ut lectus quis augue pellentesque tincidunt id id quam. Maecenas auctor, lorem eu ornare tempor, lacus metus ultrices turpis, nec feugiat nibh purus id justo.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Sed semper feugiat ante, sit amet accumsan lorem vulputate vel. Morbi interdum, mauris sit amet efficitur mattis, nunc sapien tempor ante, eget maximus ipsum arcu quis dolor. Suspendisse id consequat justo, quis sollicitudin nisi. Duis euismod, velit non faucibus placerat, eros sem fermentum lectus, ut egestas nisi ipsum eget mi. ",
|
||||
),
|
||||
new Paragraph(
|
||||
"Donec vitae mollis libero. Etiam magna leo, auctor sit amet nibh sit amet, interdum finibus nunc. Quisque a pellentesque velit, a laoreet ante.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Quisque fringilla orci quis dui facilisis, quis auctor urna cursus. Mauris eget justo lacus. Integer placerat, leo vitae ullamcorper varius, nulla mauris gravida massa, ac dignissim odio erat eu ante. Duis non dui semper, eleifend neque nec, ultricies ligula. Sed nec sem nec dolor ultrices finibus. Praesent rutrum iaculis mollis. ",
|
||||
),
|
||||
new Paragraph(
|
||||
"Fusce accumsan dui tortor, quis feugiat urna efficitur sed. Fusce viverra tristique lacinia. Sed nec faucibus ipsum, vel pulvinar ligula. Curabitur ut viverra nisl. Nulla nisi tortor, imperdiet et ipsum sit amet, egestas lacinia leo. Quisque interdum mauris non nunc egestas tempor a vehicula diam. Vestibulum convallis quam sit amet tincidunt posuere. Mauris velit sem, fermentum a diam sit amet, pulvinar iaculis lectus. In dolor turpis, cursus id libero sit amet, aliquet ullamcorper urna. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Etiam tincidunt euismod nisi, ut dignissim neque blandit sit amet. Etiam vel velit rhoncus, tincidunt diam quis, dignissim felis. Integer dolor urna, rutrum vitae ultricies ut, sagittis quis felis. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec pharetra aliquam augue. Donec ",
|
||||
),
|
||||
new Paragraph(
|
||||
"imperdiet placerat augue, nec consequat leo placerat a. Mauris accumsan ornare massa vitae volutpat. Sed commodo purus ac fringilla ultricies. Donec quis urna hendrerit dolor efficitur sollicitudin. Pellentesque diam arcu, dapibus a nisl pretium, auctor lobortis augue.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Aliquam libero lorem, scelerisque a volutpat ac, venenatis eu nisl. Maecenas turpis diam, consequat eget elementum eget, venenatis at lacus. In maximus erat magna, ut hendrerit erat malesuada vel. Suspendisse iaculis, lacus posuere convallis gravida, nisi purus blandit nunc, imperdiet tempor nunc turpis et sapien. Duis euismod id ",
|
||||
),
|
||||
new Paragraph(
|
||||
"ligula ac laoreet. Ut facilisis massa quis turpis imperdiet, eu ornare lorem placerat. Vestibulum pharetra feugiat eleifend. Quisque ornare pretium urna, lacinia aliquam eros placerat et. Integer sit amet auctor ipsum. Morbi imperdiet dictum ex sed lacinia. Curabitur interdum mattis nunc non vestibulum. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Pellentesque odio libero, viverra ac quam eleifend, dignissim euismod nibh. Etiam sit amet semper ante. Morbi in tellus lacinia, bibendum dolor quis, viverra nisi. Proin condimentum purus ipsum, et accumsan sapien finibus ac.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Maecenas congue in leo id faucibus. Etiam porta dapibus ultricies. Nunc ac volutpat magna. Nam pretium dolor ac ultrices tincidunt. Vestibulum pharetra elit vitae lacus pharetra euismod. Pellentesque fringilla lacus ac neque varius sagittis. Mauris tincidunt rutrum velit. Etiam pretium est vitae lacus ultricies, vitae viverra ",
|
||||
),
|
||||
new Paragraph(
|
||||
"turpis auctor. Nulla at lectus pellentesque enim dapibus aliquet eleifend et quam. Suspendisse cursus sed velit et lobortis. Integer sed facilisis ligula, ultrices molestie neque. Nulla porta mauris vitae quam consequat, eget fringilla enim luctus. Integer vitae rhoncus nibh, ac ornare ligula. Sed sed placerat libero. Suspendisse laoreet erat lacus, et lacinia nibh maximus in. Maecenas vitae enim at urna gravida euismod.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Interdum et malesuada fames ac ante ipsum primis in faucibus. Nullam lacinia lobortis tortor mollis venenatis. Sed sodales iaculis justo in rhoncus. Proin orci sapien, fermentum nec eleifend in, tristique vel mi. Donec vitae ornare justo, sed rhoncus nibh. Quisque a interdum est, in scelerisque odio. Ut luctus eget ex non ",
|
||||
),
|
||||
new Paragraph(
|
||||
"fringilla. Morbi nec iaculis nisi. Donec porta libero ac ex sollicitudin, vitae interdum erat faucibus. Donec ornare, arcu ullamcorper pretium euismod, nibh nisi consectetur justo, ac aliquet sem eros non nibh. Nulla vitae elementum arcu. Aenean ut consectetur dui. Donec posuere condimentum velit ac hendrerit. Sed aliquet aliquet mi, sed rutrum justo ultrices eget.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Donec volutpat libero dui, ac bibendum nunc eleifend a. Fusce ultricies ligula non sollicitudin lobortis. Integer sit amet elit sapien. Morbi rhoncus bibendum nibh et facilisis. Etiam consectetur elementum sem non elementum. Nunc rutrum sagittis ipsum non sodales. Orci varius natoque penatibus et magnis dis parturient montes, ",
|
||||
),
|
||||
new Paragraph(
|
||||
"nascetur ridiculus mus. Quisque porttitor nulla ultrices mollis porta. Cras non metus sed quam rutrum ultricies. Curabitur aliquet in sem eget auctor. Ut sodales quis leo bibendum venenatis. Etiam pellentesque eros ut metus dignissim commodo. Aliquam vitae sem gravida, convallis ipsum at, imperdiet tellus. Pellentesque consectetur odio sit amet sapien vestibulum aliquam nec id libero. Proin a maximus felis. Aenean molestie vulputate massa, eu eleifend sem consequat id.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Etiam quis ante nec leo faucibus dignissim eu at mi. Nam nec ligula nec sapien rhoncus faucibus. Fusce vestibulum orci libero, vel commodo est congue iaculis. In hac habitasse platea dictumst. Sed lacinia magna eu arcu commodo pretium. Fusce id elementum enim. Mauris tristique tortor dolor, at pretium magna tempor nec. Vivamus non ",
|
||||
),
|
||||
new Paragraph(
|
||||
"dui sit amet odio porttitor tincidunt. Nam pulvinar aliquet tortor tristique tempor. Duis finibus tincidunt elit, at viverra justo sagittis in. Morbi pellentesque gravida mi, in pulvinar metus molestie at. Fusce bibendum eleifend sapien a fermentum. Nam efficitur tellus dignissim, vehicula tortor ac, tristique enim. Aliquam pretium dui interdum varius elementum. Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Donec a finibus elit.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Phasellus cursus tortor at justo bibendum aliquam. Sed nec hendrerit nibh, eu finibus tortor. Aenean sit amet dui rutrum, sollicitudin justo eu, condimentum ipsum. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Maecenas dictum neque lacus, vel posuere eros pretium nec. Morbi ac ante at ",
|
||||
),
|
||||
new Paragraph(
|
||||
"ex semper ultricies ac quis augue. In hac habitasse platea dictumst. Mauris laoreet porta nisl. Sed augue lorem, aliquet in volutpat ut, rhoncus eget nibh. Sed rhoncus arcu diam, accumsan rhoncus sem iaculis ac. Duis dolor magna, semper et tellus non, condimentum volutpat nisi. Donec eget metus eget elit eleifend vestibulum et ut purus.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Nam a dui accumsan, efficitur ex at, commodo eros. Pellentesque sit amet nunc ac odio egestas suscipit id sodales ligula. Duis non mi vitae mi mollis fringilla at sit amet sem. Morbi laoreet mattis dolor sit amet tincidunt. Aliquam erat volutpat. Pellentesque porta sem odio, at lobortis quam commodo vitae. Curabitur ut urna dolor.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Nulla vitae pretium ex. Nulla facilisi. Vestibulum placerat odio eget enim ultrices, et imperdiet tellus consequat. Sed dignissim, erat ut dignissim interdum, dui mi rhoncus nunc, id rhoncus turpis nunc eu risus. Mauris leo orci, euismod sit amet velit ac, condimentum dictum dui. Cras cursus dolor augue, et vestibulum lorem ",
|
||||
),
|
||||
new Paragraph(
|
||||
"fringilla in. Nulla fermentum odio vehicula justo placerat, et aliquet velit vulputate. Sed aliquam auctor dictum. Phasellus sit amet sollicitudin elit. Cras eget gravida ex. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Duis tortor erat, ornare id feugiat eget, pellentesque at lectus. Sed vitae nisi ullamcorper, tincidunt augue vitae, accumsan ligula. Curabitur ut lobortis lacus, imperdiet placerat arcu.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Sed vestibulum tempor nulla vel dignissim. Phasellus imperdiet, dolor nec mollis tempor, nulla nibh pretium nibh, nec elementum lacus neque in sapien. Nam et eleifend lorem. Nam pretium molestie enim quis porta. Proin eu pharetra enim. Etiam a velit eget augue congue tempor. Interdum et malesuada fames ac ante ipsum primis in ",
|
||||
),
|
||||
new Paragraph("faucibus. Sed urna tellus, euismod ac pharetra nec, ultrices vel nisi."),
|
||||
|
||||
new Paragraph(
|
||||
"Phasellus at arcu eget tellus mattis ultricies non quis urna. Vestibulum non eros fringilla, porttitor massa id, ornare metus. Quisque lacinia, massa a ornare vulputate, ex lectus ullamcorper ligula, eget facilisis mi turpis at dolor. Curabitur posuere elementum enim, non placerat tortor tincidunt sit amet. Pellentesque habitant ",
|
||||
),
|
||||
new Paragraph(
|
||||
"morbi tristique senectus et netus et malesuada fames ac turpis egestas. Nam fermentum ut felis et dapibus. Ut consectetur finibus bibendum. Phasellus semper sapien neque, nec consequat nibh convallis et. Nunc nec egestas enim. Nulla facilisi.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Quisque sed nibh sed lorem placerat ornare sed nec sapien. Morbi et risus vitae magna varius varius eget at leo. Curabitur a eleifend elit. Mauris augue nulla, convallis vel ante in, consequat feugiat orci. Donec sagittis risus nibh, eget porta purus faucibus non. Curabitur ultrices, ex et placerat rutrum, velit odio accumsan ",
|
||||
),
|
||||
new Paragraph(
|
||||
"nulla, et elementum mi leo in velit. Pellentesque auctor egestas ultricies. In viverra est a mauris sollicitudin, a laoreet augue cursus. Vestibulum non sollicitudin massa. Curabitur ac tellus metus. Pellentesque hendrerit dolor sed mi vestibulum imperdiet. Nulla vitae odio ultrices, tempor enim sed, vestibulum eros. Cras libero ex, malesuada nec porttitor sit amet, efficitur sit amet ligula.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Morbi pellentesque tempus felis, id iaculis quam euismod non. Sed scelerisque id massa eu elementum. Vestibulum id malesuada arcu. Maecenas eget placerat sem, at consectetur orci. Nullam interdum erat urna, ac rhoncus odio feugiat sed. Morbi rutrum auctor sem eget pulvinar. Suspendisse egestas tempor volutpat.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Vivamus euismod, sem eget molestie rhoncus, metus dui laoreet lacus, et lobortis est metus ut felis. Aenean imperdiet lacus nunc, vitae molestie orci ultrices nec. Cras egestas maximus diam, vitae efficitur nisl luctus imperdiet. Nulla pellentesque sodales ante, nec facilisis turpis. Vivamus at hendrerit enim, ac dictum lorem. Cras ",
|
||||
),
|
||||
new Paragraph(
|
||||
"congue accumsan dui, non pretium sem auctor quis. Nunc a mauris vehicula, elementum ex vitae, sollicitudin eros. Nunc non sapien vitae justo sodales condimentum. Praesent nisl felis, tristique ac odio at, rhoncus porttitor orci. Morbi egestas placerat iaculis.",
|
||||
),
|
||||
new Paragraph(
|
||||
"Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In at lorem nec neque faucibus ultricies ut in ipsum.",
|
||||
),
|
||||
new Paragraph(
|
||||
"Suspendisse fermentum feugiat augue eu convallis. Maecenas eros velit, efficitur sit amet posuere sed, tristique sit amet nisi. Donec vel convallis justo, id tempor neque. Nunc pulvinar maximus nulla, vitae congue lacus cursus ut. Morbi at mollis est, a vehicula nisi. Cras venenatis nibh vel massa interdum commodo. Nulla mattis ",
|
||||
),
|
||||
new Paragraph(
|
||||
"neque sed sem bibendum, iaculis hendrerit neque fringilla. Sed a lobortis orci. Morbi in est sed libero vestibulum semper. Suspendisse potenti. Aliquam pretium erat tellus, in suscipit lorem aliquet iaculis. Aenean ac viverra ipsum. Sed at diam luctus, pharetra lorem vel, aliquam magna. Donec mollis orci eget enim efficitur ultricies. Proin neque diam, dignissim euismod ex vel, sollicitudin sodales sapien.",
|
||||
),
|
||||
|
||||
new Paragraph(
|
||||
"Sed a egestas nunc, a ullamcorper est. Aenean vulputate fringilla justo non vestibulum. Donec ac dolor in nisl finibus tristique. Donec sed turpis at felis congue porttitor sed sit amet metus. In in ex nulla. Donec sodales vel velit ut congue. Nullam vitae egestas purus. Vivamus non mi consequat, molestie enim nec, hendrerit mi.",
|
||||
),
|
||||
];
|
||||
// cspell: enable
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
{
|
||||
@ -45,7 +181,20 @@ const doc = new Document({
|
||||
children: [
|
||||
new TextRun("My Title "),
|
||||
new TextRun({
|
||||
children: ["Footer - Page ", PageNumber.CURRENT],
|
||||
children: ["Footer - Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun({
|
||||
children: [
|
||||
"Footer - Page in section ",
|
||||
PageNumber.CURRENT_SECTION,
|
||||
" of ",
|
||||
PageNumber.TOTAL_PAGES_IN_SECTION,
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -70,6 +219,96 @@ const doc = new Document({
|
||||
children: [new TextRun("First Page"), new PageBreak()],
|
||||
}),
|
||||
new Paragraph("Second Page"),
|
||||
...createLoremIpsumParagraphs(),
|
||||
new Paragraph({
|
||||
children: [new TextRun("Next Page"), new PageBreak()],
|
||||
}),
|
||||
...createLoremIpsumParagraphs(),
|
||||
],
|
||||
},
|
||||
{
|
||||
properties: {
|
||||
titlePage: true,
|
||||
},
|
||||
headers: {
|
||||
default: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun("My Title "),
|
||||
new TextRun({
|
||||
children: ["Page ", PageNumber.CURRENT],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
first: new Header({
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun("First Page Header "),
|
||||
new TextRun({
|
||||
children: ["Page ", PageNumber.CURRENT],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
footers: {
|
||||
default: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun("My Title "),
|
||||
new TextRun({
|
||||
children: ["Footer - Page ", PageNumber.CURRENT, " of ", PageNumber.TOTAL_PAGES],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun({
|
||||
children: [
|
||||
"Footer - Page in section ",
|
||||
PageNumber.CURRENT_SECTION,
|
||||
" of ",
|
||||
PageNumber.TOTAL_PAGES_IN_SECTION,
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
first: new Footer({
|
||||
children: [
|
||||
new Paragraph({
|
||||
alignment: AlignmentType.RIGHT,
|
||||
children: [
|
||||
new TextRun("First Page Footer "),
|
||||
new TextRun({
|
||||
children: ["Page ", PageNumber.CURRENT],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
},
|
||||
children: [
|
||||
new Paragraph({
|
||||
children: [new TextRun("First Page"), new PageBreak()],
|
||||
}),
|
||||
new Paragraph("Second Page"),
|
||||
...createLoremIpsumParagraphs(),
|
||||
new Paragraph({
|
||||
children: [new TextRun("Next Page"), new PageBreak()],
|
||||
}),
|
||||
...createLoremIpsumParagraphs(),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -1,7 +1,7 @@
|
||||
// Example of how you would create a table and add data to it
|
||||
|
||||
import * as fs from "fs";
|
||||
import { Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
||||
import { BorderStyle, Document, HeadingLevel, Packer, Paragraph, Table, TableCell, TableRow, VerticalAlign, TextDirection } from "docx";
|
||||
|
||||
const doc = new Document({
|
||||
sections: [
|
||||
@ -67,6 +67,173 @@ const doc = new Document({
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new Paragraph("Table with borders"),
|
||||
new Table({
|
||||
rows: [
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Dash small gap border")],
|
||||
}),
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.DASH_SMALL_GAP,
|
||||
size: 1,
|
||||
color: "000000",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Dash small gap border")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Double border")],
|
||||
}),
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.DOUBLE,
|
||||
size: 1,
|
||||
color: "ff0000",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Double border")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
new TableRow({
|
||||
children: [
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Should have no border")],
|
||||
}),
|
||||
new TableCell({
|
||||
borders: {
|
||||
top: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
bottom: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
left: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
right: {
|
||||
style: BorderStyle.NONE,
|
||||
size: 0,
|
||||
color: "ffffff",
|
||||
},
|
||||
},
|
||||
children: [new Paragraph("Should have no border")],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
}),
|
||||
],
|
||||
},
|
||||
],
|
||||
|
@ -2,6 +2,7 @@
|
||||
|
||||
import * as fs from "fs";
|
||||
import {
|
||||
convertMillimetersToTwip,
|
||||
Document,
|
||||
HorizontalPositionAlign,
|
||||
HorizontalPositionRelativeFrom,
|
||||
@ -41,6 +42,11 @@ const doc = new Document({
|
||||
width: 100,
|
||||
height: 100,
|
||||
},
|
||||
outline: {
|
||||
type: "solidFill",
|
||||
solidFillType: "rgb",
|
||||
value: "FF0000",
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
@ -55,6 +61,12 @@ const doc = new Document({
|
||||
vertical: true,
|
||||
},
|
||||
},
|
||||
outline: {
|
||||
type: "solidFill",
|
||||
solidFillType: "rgb",
|
||||
value: "0000FF",
|
||||
width: convertMillimetersToTwip(600),
|
||||
},
|
||||
}),
|
||||
],
|
||||
}),
|
||||
|
@ -107,5 +107,5 @@ const doc = new Document({
|
||||
|
||||
// Used to export the file into a .docx file
|
||||
Packer.toBuffer(doc).then((buffer) => {
|
||||
fs.writeFileSync("6-numbering.docx", buffer);
|
||||
fs.writeFileSync("My Document.docx", buffer);
|
||||
});
|
||||
|
@ -18,6 +18,7 @@ const receiptTabStops = [
|
||||
const twoTabStops = [{ type: TabStopType.RIGHT, position: TabStopPosition.MAX }];
|
||||
|
||||
const doc = new Document({
|
||||
defaultTabStop: 0,
|
||||
sections: [
|
||||
{
|
||||
properties: {},
|
||||
|
4788
package-lock.json
generated
4788
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
26
package.json
26
package.json
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "docx",
|
||||
"version": "8.3.0",
|
||||
"version": "8.4.0",
|
||||
"description": "Easily generate .docx files with JS/TS with a nice declarative API. Works for Node and on the Browser.",
|
||||
"type": "module",
|
||||
"main": "build/index.umd.js",
|
||||
@ -20,21 +20,21 @@
|
||||
"scripts": {
|
||||
"build": "tsc && vite build",
|
||||
"test": "vitest --ui --coverage",
|
||||
"test.ci": "vitest run --coverage",
|
||||
"test:ci": "vitest run --coverage",
|
||||
"prepublishOnly": "npm run build --omit=dev",
|
||||
"lint": "eslint --ext .ts src",
|
||||
"predemo": "npm run build",
|
||||
"demo": "tsx ./demo/index.ts",
|
||||
"typedoc": "typedoc src/index.ts --tsconfig tsconfig.typedoc.json",
|
||||
"style": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||
"style.fix": "npm run style -- --write",
|
||||
"prettier": "prettier -l \"{src,scripts,demo}/**/*.{ts,html}\"",
|
||||
"prettier:fix": "npm run prettier -- --write",
|
||||
"cspell": "cspell \"{src,demo,docs,scripts}/**/*.{ts,scss,html,md}\" && cspell \"./*.*\"",
|
||||
"serve.docs": "cd docs && docsify serve",
|
||||
"extract": "tsx scripts/extract-document.ts",
|
||||
"run-ts": "tsx"
|
||||
},
|
||||
"pre-commit": [
|
||||
"style",
|
||||
"prettier",
|
||||
"lint"
|
||||
],
|
||||
"repository": {
|
||||
@ -73,9 +73,9 @@
|
||||
"@types/xml": "^1.0.8",
|
||||
"@typescript-eslint/eslint-plugin": "^6.9.1",
|
||||
"@typescript-eslint/parser": "^6.9.1",
|
||||
"@vitest/coverage-v8": "^0.34.6",
|
||||
"@vitest/ui": "^0.33.0",
|
||||
"cspell": "^7.3.8",
|
||||
"@vitest/coverage-v8": "^1.1.0",
|
||||
"@vitest/ui": "^1.1.0",
|
||||
"cspell": "^8.2.3",
|
||||
"docsify-cli": "^4.3.0",
|
||||
"eslint": "^8.23.0",
|
||||
"eslint-plugin-functional": "^6.0.0",
|
||||
@ -87,19 +87,19 @@
|
||||
"execa": "^8.0.1",
|
||||
"glob": "^10.2.7",
|
||||
"inquirer": "^9.2.7",
|
||||
"jsdom": "^22.1.0",
|
||||
"jsdom": "^23.0.1",
|
||||
"pre-commit": "^1.2.2",
|
||||
"prettier": "^3.0.0",
|
||||
"prettier": "^3.1.1",
|
||||
"tsconfig-paths": "^4.0.0",
|
||||
"tsx": "^4.7.0",
|
||||
"typedoc": "^0.24.8",
|
||||
"typescript": "5.1.6",
|
||||
"typedoc": "^0.25.4",
|
||||
"typescript": "5.3.3",
|
||||
"unzipper": "^0.10.11",
|
||||
"vite": "^5.0.10",
|
||||
"vite-plugin-dts": "^3.3.1",
|
||||
"vite-plugin-node-polyfills": "^0.9.0",
|
||||
"vite-tsconfig-paths": "^4.2.0",
|
||||
"vitest": "^0.33.0"
|
||||
"vitest": "^1.1.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">=10"
|
||||
|
@ -39,6 +39,7 @@ export interface IPropertiesOptions {
|
||||
readonly compatibility?: ICompatibilityOptions;
|
||||
readonly customProperties?: readonly ICustomPropertyOptions[];
|
||||
readonly evenAndOddHeaderAndFooters?: boolean;
|
||||
readonly defaultTabStop?: number;
|
||||
}
|
||||
|
||||
// <xs:element name="coreProperties" type="CT_CoreProperties"/>
|
||||
|
@ -1,5 +1,5 @@
|
||||
// http://officeopenxml.com/WPsectionLineNumbering.php
|
||||
import { NextAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
import { decimalNumber, PositiveUniversalMeasure, twipsMeasureValue } from "@util/values";
|
||||
|
||||
// <xsd:simpleType name="ST_LineNumberRestart">
|
||||
@ -25,31 +25,23 @@ export const LineNumberRestartFormat = {
|
||||
// <xsd:attribute name="restart" type="ST_LineNumberRestart" use="optional" default="newPage"/>
|
||||
// </xsd:complexType>
|
||||
|
||||
export interface ILineNumberAttributes {
|
||||
export type ILineNumberAttributes = {
|
||||
readonly countBy?: number;
|
||||
readonly start?: number;
|
||||
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
||||
readonly distance?: number | PositiveUniversalMeasure;
|
||||
}
|
||||
};
|
||||
|
||||
export class LineNumberType extends XmlComponent {
|
||||
public constructor({ countBy, start, restart, distance }: ILineNumberAttributes) {
|
||||
super("w:lnNumType");
|
||||
this.root.push(
|
||||
new NextAttributeComponent<{
|
||||
readonly countBy?: number;
|
||||
readonly start?: number;
|
||||
readonly restart?: (typeof LineNumberRestartFormat)[keyof typeof LineNumberRestartFormat];
|
||||
readonly distance?: number | PositiveUniversalMeasure;
|
||||
}>({
|
||||
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||
restart: { key: "w:restart", value: restart },
|
||||
distance: {
|
||||
key: "w:distance",
|
||||
value: distance === undefined ? undefined : twipsMeasureValue(distance),
|
||||
},
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
export const createLineNumberType = ({ countBy, start, restart, distance }: ILineNumberAttributes): XmlComponent =>
|
||||
new BuilderElement<ILineNumberAttributes>({
|
||||
name: "w:lnNumType",
|
||||
attributes: {
|
||||
countBy: { key: "w:countBy", value: countBy === undefined ? undefined : decimalNumber(countBy) },
|
||||
start: { key: "w:start", value: start === undefined ? undefined : decimalNumber(start) },
|
||||
restart: { key: "w:restart", value: restart },
|
||||
distance: {
|
||||
key: "w:distance",
|
||||
value: distance === undefined ? undefined : twipsMeasureValue(distance),
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -9,7 +9,7 @@ import { OnOffElement, XmlComponent } from "@file/xml-components";
|
||||
import { HeaderFooterReference, HeaderFooterReferenceType, HeaderFooterType } from "./properties/header-footer-reference";
|
||||
import { Columns, IColumnsAttributes } from "./properties/columns";
|
||||
import { DocumentGrid, IDocGridAttributesProperties } from "./properties/doc-grid";
|
||||
import { ILineNumberAttributes, LineNumberType } from "./properties/line-number";
|
||||
import { ILineNumberAttributes, createLineNumberType } from "./properties/line-number";
|
||||
import { IPageBordersOptions, PageBorders } from "./properties/page-borders";
|
||||
import { IPageMarginAttributes, PageMargin } from "./properties/page-margin";
|
||||
import { IPageNumberTypeAttributes, PageNumberType } from "./properties/page-number";
|
||||
@ -137,7 +137,7 @@ export class SectionProperties extends XmlComponent {
|
||||
}
|
||||
|
||||
if (lineNumbers) {
|
||||
this.root.push(new LineNumberType(lineNumbers));
|
||||
this.root.push(createLineNumberType(lineNumbers));
|
||||
}
|
||||
|
||||
this.root.push(new PageNumberType(pageNumbers));
|
||||
|
@ -9,10 +9,10 @@ import { TextWrappingType } from "../text-wrap";
|
||||
import { Anchor } from "./anchor";
|
||||
|
||||
const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||
new Anchor(
|
||||
{
|
||||
new Anchor({
|
||||
mediaData: {
|
||||
fileName: "test.png",
|
||||
stream: new Buffer(""),
|
||||
stream: Buffer.from(""),
|
||||
transformation: {
|
||||
pixels: {
|
||||
x: 0,
|
||||
@ -24,7 +24,7 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
transform: {
|
||||
pixels: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
@ -35,7 +35,7 @@ const createAnchor = (drawingOptions: IDrawingOptions): Anchor =>
|
||||
},
|
||||
},
|
||||
drawingOptions,
|
||||
);
|
||||
});
|
||||
|
||||
describe("Anchor", () => {
|
||||
let anchor: Anchor;
|
||||
|
@ -6,7 +6,7 @@ import { HorizontalPosition, IFloating, SimplePos, VerticalPosition } from "../f
|
||||
import { Graphic } from "../inline/graphic";
|
||||
import { TextWrappingType, WrapNone, WrapSquare, WrapTight, WrapTopAndBottom } from "../text-wrap";
|
||||
import { DocProperties } from "./../doc-properties/doc-properties";
|
||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
||||
import { createEffectExtent } from "./../effect-extent/effect-extent";
|
||||
import { Extent } from "./../extent/extent";
|
||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||
import { AnchorAttributes } from "./anchor-attributes";
|
||||
@ -37,7 +37,15 @@ import { AnchorAttributes } from "./anchor-attributes";
|
||||
// <xsd:attribute name="allowOverlap" type="xsd:boolean" use="required"/>
|
||||
// </xsd:complexType>
|
||||
export class Anchor extends XmlComponent {
|
||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation, drawingOptions: IDrawingOptions) {
|
||||
public constructor({
|
||||
mediaData,
|
||||
transform,
|
||||
drawingOptions,
|
||||
}: {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly drawingOptions: IDrawingOptions;
|
||||
}) {
|
||||
super("wp:anchor");
|
||||
|
||||
const floating: IFloating = {
|
||||
@ -69,7 +77,7 @@ export class Anchor extends XmlComponent {
|
||||
this.root.push(new HorizontalPosition(floating.horizontalPosition));
|
||||
this.root.push(new VerticalPosition(floating.verticalPosition));
|
||||
this.root.push(new Extent(transform.emus.x, transform.emus.y));
|
||||
this.root.push(new EffectExtent());
|
||||
this.root.push(createEffectExtent({ top: 0, right: 0, bottom: 0, left: 0 }));
|
||||
|
||||
if (drawingOptions.floating !== undefined && drawingOptions.floating.wrap !== undefined) {
|
||||
switch (drawingOptions.floating.wrap.type) {
|
||||
@ -92,6 +100,6 @@ export class Anchor extends XmlComponent {
|
||||
|
||||
this.root.push(new DocProperties(drawingOptions.docProperties));
|
||||
this.root.push(new GraphicFrameProperties());
|
||||
this.root.push(new Graphic(mediaData, transform));
|
||||
this.root.push(new Graphic({ mediaData, transform, outline: drawingOptions.outline }));
|
||||
}
|
||||
}
|
||||
|
@ -4,18 +4,20 @@ import { XmlComponent } from "@file/xml-components";
|
||||
import { Anchor } from "./anchor";
|
||||
import { DocPropertiesOptions } from "./doc-properties/doc-properties";
|
||||
import { IFloating } from "./floating";
|
||||
import { Inline } from "./inline";
|
||||
import { createInline } from "./inline";
|
||||
import { OutlineOptions } from "./inline/graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||
|
||||
export interface IDistance {
|
||||
export type IDistance = {
|
||||
readonly distT?: number;
|
||||
readonly distB?: number;
|
||||
readonly distL?: number;
|
||||
readonly distR?: number;
|
||||
}
|
||||
};
|
||||
|
||||
export interface IDrawingOptions {
|
||||
readonly floating?: IFloating;
|
||||
readonly docProperties?: DocPropertiesOptions;
|
||||
readonly outline?: OutlineOptions;
|
||||
}
|
||||
|
||||
// <xsd:complexType name="CT_Drawing">
|
||||
@ -30,14 +32,16 @@ export class Drawing extends XmlComponent {
|
||||
super("w:drawing");
|
||||
|
||||
if (!drawingOptions.floating) {
|
||||
const inline = new Inline({
|
||||
mediaData: imageData,
|
||||
transform: imageData.transformation,
|
||||
docProperties: drawingOptions.docProperties,
|
||||
});
|
||||
this.root.push(inline);
|
||||
this.root.push(
|
||||
createInline({
|
||||
mediaData: imageData,
|
||||
transform: imageData.transformation,
|
||||
docProperties: drawingOptions.docProperties,
|
||||
outline: drawingOptions.outline,
|
||||
}),
|
||||
);
|
||||
} else {
|
||||
this.root.push(new Anchor(imageData, imageData.transformation, drawingOptions));
|
||||
this.root.push(new Anchor({ mediaData: imageData, transform: imageData.transformation, drawingOptions }));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
import { XmlAttributeComponent } from "@file/xml-components";
|
||||
|
||||
export class EffectExtentAttributes extends XmlAttributeComponent<{
|
||||
readonly b?: number;
|
||||
readonly l?: number;
|
||||
readonly r?: number;
|
||||
readonly t?: number;
|
||||
}> {
|
||||
protected readonly xmlKeys = {
|
||||
b: "b",
|
||||
l: "l",
|
||||
r: "r",
|
||||
t: "t",
|
||||
};
|
||||
}
|
@ -1,17 +1,31 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { EffectExtentAttributes } from "./effect-extent-attributes";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class EffectExtent extends XmlComponent {
|
||||
public constructor() {
|
||||
super("wp:effectExtent");
|
||||
export type EffectExtentAttributes = {
|
||||
readonly top: number;
|
||||
readonly right: number;
|
||||
readonly bottom: number;
|
||||
readonly left: number;
|
||||
};
|
||||
|
||||
this.root.push(
|
||||
new EffectExtentAttributes({
|
||||
b: 0,
|
||||
l: 0,
|
||||
r: 0,
|
||||
t: 0,
|
||||
}),
|
||||
);
|
||||
}
|
||||
}
|
||||
export const createEffectExtent = ({ top, right, bottom, left }: EffectExtentAttributes): XmlComponent =>
|
||||
new BuilderElement<EffectExtentAttributes>({
|
||||
name: "wp:effectExtent",
|
||||
attributes: {
|
||||
top: {
|
||||
key: "t",
|
||||
value: top,
|
||||
},
|
||||
right: {
|
||||
key: "r",
|
||||
value: right,
|
||||
},
|
||||
bottom: {
|
||||
key: "b",
|
||||
value: bottom,
|
||||
},
|
||||
left: {
|
||||
key: "l",
|
||||
value: left,
|
||||
},
|
||||
},
|
||||
});
|
||||
|
@ -3,11 +3,20 @@ import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { GraphicDataAttributes } from "./graphic-data-attribute";
|
||||
import { Pic } from "./pic";
|
||||
import { OutlineOptions } from "./pic/shape-properties/outline/outline";
|
||||
|
||||
export class GraphicData extends XmlComponent {
|
||||
private readonly pic: Pic;
|
||||
|
||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||
public constructor({
|
||||
mediaData,
|
||||
transform,
|
||||
outline,
|
||||
}: {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly outline?: OutlineOptions;
|
||||
}) {
|
||||
super("a:graphicData");
|
||||
|
||||
this.root.push(
|
||||
@ -16,7 +25,7 @@ export class GraphicData extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
|
||||
this.pic = new Pic(mediaData, transform);
|
||||
this.pic = new Pic({ mediaData, transform, outline });
|
||||
|
||||
this.root.push(this.pic);
|
||||
}
|
||||
|
@ -6,9 +6,18 @@ import { BlipFill } from "./blip/blip-fill";
|
||||
import { NonVisualPicProperties } from "./non-visual-pic-properties/non-visual-pic-properties";
|
||||
import { PicAttributes } from "./pic-attributes";
|
||||
import { ShapeProperties } from "./shape-properties/shape-properties";
|
||||
import { OutlineOptions } from "./shape-properties/outline/outline";
|
||||
|
||||
export class Pic extends XmlComponent {
|
||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||
public constructor({
|
||||
mediaData,
|
||||
transform,
|
||||
outline,
|
||||
}: {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly outline?: OutlineOptions;
|
||||
}) {
|
||||
super("pic:pic");
|
||||
|
||||
this.root.push(
|
||||
@ -19,6 +28,6 @@ export class Pic extends XmlComponent {
|
||||
|
||||
this.root.push(new NonVisualPicProperties());
|
||||
this.root.push(new BlipFill(mediaData));
|
||||
this.root.push(new ShapeProperties(transform));
|
||||
this.root.push(new ShapeProperties({ transform, outline }));
|
||||
}
|
||||
}
|
||||
|
@ -2,12 +2,12 @@ import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { NoFill } from "./no-fill";
|
||||
import { createNoFill } from "./no-fill";
|
||||
|
||||
describe("NoFill", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create", () => {
|
||||
const tree = new Formatter().format(new NoFill());
|
||||
const tree = new Formatter().format(createNoFill());
|
||||
expect(tree).to.deep.equal({
|
||||
"a:noFill": {},
|
||||
});
|
||||
|
@ -1,7 +1,3 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
export class NoFill extends XmlComponent {
|
||||
public constructor() {
|
||||
super("a:noFill");
|
||||
}
|
||||
}
|
||||
export const createNoFill = (): XmlComponent => new BuilderElement({ name: "a:noFill" });
|
||||
|
@ -1,19 +1,66 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
import { Outline } from "./outline";
|
||||
|
||||
describe("Outline", () => {
|
||||
describe("#constructor()", () => {
|
||||
it("should create", () => {
|
||||
const tree = new Formatter().format(new Outline());
|
||||
expect(tree).to.deep.equal({
|
||||
"a:ln": [
|
||||
{
|
||||
"a:noFill": {},
|
||||
},
|
||||
],
|
||||
});
|
||||
import { createOutline } from "./outline";
|
||||
import { SchemeColor } from "./scheme-color";
|
||||
|
||||
describe("createOutline", () => {
|
||||
it("should create no fill", () => {
|
||||
const tree = new Formatter().format(createOutline({ type: "noFill" }));
|
||||
expect(tree).to.deep.equal({
|
||||
"a:ln": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
{
|
||||
"a:noFill": {},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create solid rgb fill", () => {
|
||||
const tree = new Formatter().format(createOutline({ type: "solidFill", solidFillType: "rgb", value: "FFFFFF" }));
|
||||
expect(tree).to.deep.equal({
|
||||
"a:ln": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
{
|
||||
"a:solidFill": [
|
||||
{
|
||||
"a:srgbClr": {
|
||||
_attr: {
|
||||
val: "FFFFFF",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create solid scheme fill", () => {
|
||||
const tree = new Formatter().format(createOutline({ type: "solidFill", solidFillType: "scheme", value: SchemeColor.ACCENT1 }));
|
||||
expect(tree).to.deep.equal({
|
||||
"a:ln": [
|
||||
{
|
||||
_attr: {},
|
||||
},
|
||||
{
|
||||
"a:solidFill": [
|
||||
{
|
||||
"a:schemeClr": {
|
||||
_attr: {
|
||||
val: "accent1",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -1,11 +1,130 @@
|
||||
// http://officeopenxml.com/drwSp-outline.php
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { NoFill } from "./no-fill";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
import { createNoFill } from "./no-fill";
|
||||
import { createSolidFill } from "./solid-fill";
|
||||
import { SchemeColor } from "./scheme-color";
|
||||
|
||||
export class Outline extends XmlComponent {
|
||||
public constructor() {
|
||||
super("a:ln");
|
||||
// <xsd:complexType name="CT_TextOutlineEffect">
|
||||
// <xsd:sequence>
|
||||
// <xsd:group ref="EG_FillProperties" minOccurs="0"/>
|
||||
// <xsd:group ref="EG_LineDashProperties" minOccurs="0"/>
|
||||
// <xsd:group ref="EG_LineJoinProperties" minOccurs="0"/>
|
||||
// </xsd:sequence>
|
||||
// <xsd:attribute name="w" use="optional" type="a:ST_LineWidth"/>
|
||||
// <xsd:attribute name="cap" use="optional" type="ST_LineCap"/>
|
||||
// <xsd:attribute name="cmpd" use="optional" type="ST_CompoundLine"/>
|
||||
// <xsd:attribute name="algn" use="optional" type="ST_PenAlignment"/>
|
||||
// </xsd:complexType>
|
||||
|
||||
this.root.push(new NoFill());
|
||||
}
|
||||
}
|
||||
// <xsd:simpleType name="ST_LineCap">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="rnd"/>
|
||||
// <xsd:enumeration value="sq"/>
|
||||
// <xsd:enumeration value="flat"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export const LineCap = {
|
||||
ROUND: "rnd",
|
||||
SQUARE: "sq",
|
||||
FLAT: "flat",
|
||||
} as const;
|
||||
|
||||
// <xsd:simpleType name="ST_CompoundLine">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="sng"/>
|
||||
// <xsd:enumeration value="dbl"/>
|
||||
// <xsd:enumeration value="thickThin"/>
|
||||
// <xsd:enumeration value="thinThick"/>
|
||||
// <xsd:enumeration value="tri"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export const CompoundLine = {
|
||||
SINGLE: "sng",
|
||||
DOUBLE: "dbl",
|
||||
THICK_THIN: "thickThin",
|
||||
THIN_THICK: "thinThick",
|
||||
TRI: "tri",
|
||||
} as const;
|
||||
|
||||
// <xsd:simpleType name="ST_PenAlignment">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="ctr"/>
|
||||
// <xsd:enumeration value="in"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
export const PenAlignment = {
|
||||
CENTER: "ctr",
|
||||
INSET: "in",
|
||||
} as const;
|
||||
|
||||
export type OutlineAttributes = {
|
||||
readonly width?: number;
|
||||
readonly cap?: keyof typeof LineCap;
|
||||
readonly compoundLine?: keyof typeof CompoundLine;
|
||||
readonly align?: keyof typeof PenAlignment;
|
||||
};
|
||||
|
||||
type OutlineNoFill = {
|
||||
readonly type: "noFill";
|
||||
};
|
||||
|
||||
type OutlineRgbSolidFill = {
|
||||
readonly type: "solidFill";
|
||||
readonly solidFillType: "rgb";
|
||||
readonly value: string;
|
||||
};
|
||||
|
||||
type OutlineSchemeSolidFill = {
|
||||
readonly type: "solidFill";
|
||||
readonly solidFillType: "scheme";
|
||||
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||
};
|
||||
|
||||
type OutlineSolidFill = OutlineRgbSolidFill | OutlineSchemeSolidFill;
|
||||
|
||||
// <xsd:group name="EG_FillProperties">
|
||||
// <xsd:choice>
|
||||
// <xsd:element name="noFill" type="w:CT_Empty"/>
|
||||
// <xsd:element name="solidFill" type="CT_SolidColorFillProperties"/>
|
||||
// <xsd:element name="gradFill" type="CT_GradientFillProperties"/>
|
||||
// </xsd:choice>
|
||||
// </xsd:group>
|
||||
type OutlineFillProperties = OutlineNoFill | OutlineSolidFill;
|
||||
|
||||
export type OutlineOptions = OutlineAttributes & OutlineFillProperties;
|
||||
|
||||
export const createOutline = (options: OutlineOptions): XmlComponent =>
|
||||
new BuilderElement<OutlineAttributes>({
|
||||
name: "a:ln",
|
||||
attributes: {
|
||||
width: {
|
||||
key: "w",
|
||||
value: options.width,
|
||||
},
|
||||
cap: {
|
||||
key: "cap",
|
||||
value: options.cap,
|
||||
},
|
||||
compoundLine: {
|
||||
key: "cmpd",
|
||||
value: options.compoundLine,
|
||||
},
|
||||
align: {
|
||||
key: "algn",
|
||||
value: options.align,
|
||||
},
|
||||
},
|
||||
children: [
|
||||
options.type === "noFill"
|
||||
? createNoFill()
|
||||
: options.solidFillType === "rgb"
|
||||
? createSolidFill({
|
||||
type: "rgb",
|
||||
value: options.value,
|
||||
})
|
||||
: createSolidFill({
|
||||
type: "scheme",
|
||||
value: options.value,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
@ -0,0 +1,22 @@
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
type SolidRgbColorOptions = {
|
||||
readonly value: string;
|
||||
};
|
||||
|
||||
// <xsd:complexType name="CT_SRgbColor">
|
||||
// <xsd:sequence>
|
||||
// <xsd:group ref="EG_ColorTransform" minOccurs="0" maxOccurs="unbounded"/>
|
||||
// </xsd:sequence>
|
||||
// <xsd:attribute name="val" type="s:ST_HexColorRGB" use="required"/>
|
||||
// </xsd:complexType>
|
||||
export const createSolidRgbColor = (options: SolidRgbColorOptions): XmlComponent =>
|
||||
new BuilderElement<SolidRgbColorOptions>({
|
||||
name: "a:srgbClr",
|
||||
attributes: {
|
||||
value: {
|
||||
key: "val",
|
||||
value: options.value,
|
||||
},
|
||||
},
|
||||
});
|
@ -0,0 +1,65 @@
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
type SchemeColorOptions = {
|
||||
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||
};
|
||||
|
||||
// <xsd:simpleType name="ST_SchemeColorVal">
|
||||
// <xsd:restriction base="xsd:string">
|
||||
// <xsd:enumeration value="bg1"/>
|
||||
// <xsd:enumeration value="tx1"/>
|
||||
// <xsd:enumeration value="bg2"/>
|
||||
// <xsd:enumeration value="tx2"/>
|
||||
// <xsd:enumeration value="accent1"/>
|
||||
// <xsd:enumeration value="accent2"/>
|
||||
// <xsd:enumeration value="accent3"/>
|
||||
// <xsd:enumeration value="accent4"/>
|
||||
// <xsd:enumeration value="accent5"/>
|
||||
// <xsd:enumeration value="accent6"/>
|
||||
// <xsd:enumeration value="hlink"/>
|
||||
// <xsd:enumeration value="folHlink"/>
|
||||
// <xsd:enumeration value="dk1"/>
|
||||
// <xsd:enumeration value="lt1"/>
|
||||
// <xsd:enumeration value="dk2"/>
|
||||
// <xsd:enumeration value="lt2"/>
|
||||
// <xsd:enumeration value="phClr"/>
|
||||
// </xsd:restriction>
|
||||
// </xsd:simpleType>
|
||||
|
||||
// cspell:ignore folHlink, phClr, hlink
|
||||
export const SchemeColor = {
|
||||
BG1: "bg1",
|
||||
TX1: "tx1",
|
||||
BG2: "bg2",
|
||||
TX2: "tx2",
|
||||
ACCENT1: "accent1",
|
||||
ACCENT2: "accent2",
|
||||
ACCENT3: "accent3",
|
||||
ACCENT4: "accent4",
|
||||
ACCENT5: "accent5",
|
||||
ACCENT6: "accent6",
|
||||
HLINK: "hlink",
|
||||
FOLHLINK: "folHlink",
|
||||
DK1: "dk1",
|
||||
LT1: "lt1",
|
||||
DK2: "dk2",
|
||||
LT2: "lt2",
|
||||
PHCLR: "phClr",
|
||||
} as const;
|
||||
|
||||
// <xsd:complexType name="CT_SchemeColor">
|
||||
// <xsd:sequence>
|
||||
// <xsd:group ref="EG_ColorTransform" minOccurs="0" maxOccurs="unbounded"/>
|
||||
// </xsd:sequence>
|
||||
// <xsd:attribute name="val" type="ST_SchemeColorVal" use="required"/>
|
||||
// </xsd:complexType>
|
||||
export const createSchemeColor = (options: SchemeColorOptions): XmlComponent =>
|
||||
new BuilderElement<SchemeColorOptions>({
|
||||
name: "a:schemeClr",
|
||||
attributes: {
|
||||
value: {
|
||||
key: "val",
|
||||
value: options.value,
|
||||
},
|
||||
},
|
||||
});
|
@ -0,0 +1,38 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
|
||||
import { createSolidFill } from "./solid-fill";
|
||||
import { SchemeColor } from "./scheme-color";
|
||||
|
||||
describe("createSolidFill", () => {
|
||||
it("should create of rgb", () => {
|
||||
const tree = new Formatter().format(createSolidFill({ type: "rgb", value: "FFFFFF" }));
|
||||
expect(tree).to.deep.equal({
|
||||
"a:solidFill": [
|
||||
{
|
||||
"a:srgbClr": {
|
||||
_attr: {
|
||||
val: "FFFFFF",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create of scheme", () => {
|
||||
const tree = new Formatter().format(createSolidFill({ type: "scheme", value: SchemeColor.TX1 }));
|
||||
expect(tree).to.deep.equal({
|
||||
"a:solidFill": [
|
||||
{
|
||||
"a:schemeClr": {
|
||||
_attr: {
|
||||
val: "tx1",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
@ -0,0 +1,22 @@
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { createSchemeColor, SchemeColor } from "./scheme-color";
|
||||
import { createSolidRgbColor } from "./rgb-color";
|
||||
|
||||
export type RgbColorOptions = {
|
||||
readonly type: "rgb";
|
||||
readonly value: string;
|
||||
};
|
||||
|
||||
export type SchemeColorOptions = {
|
||||
readonly type: "scheme";
|
||||
readonly value: (typeof SchemeColor)[keyof typeof SchemeColor];
|
||||
};
|
||||
|
||||
export type SolidFillOptions = RgbColorOptions | SchemeColorOptions;
|
||||
|
||||
export const createSolidFill = (options: SolidFillOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "a:solidFill",
|
||||
children: [options.type === "rgb" ? createSolidRgbColor(options) : createSchemeColor(options)],
|
||||
});
|
@ -2,15 +2,15 @@
|
||||
import { IMediaDataTransformation } from "@file/media";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { Form } from "./form";
|
||||
// import { NoFill } from "./no-fill";
|
||||
// import { Outline } from "./outline/outline";
|
||||
import { OutlineOptions, createOutline } from "./outline/outline";
|
||||
import { PresetGeometry } from "./preset-geometry/preset-geometry";
|
||||
import { ShapePropertiesAttributes } from "./shape-properties-attributes";
|
||||
import { createNoFill } from "./outline/no-fill";
|
||||
|
||||
export class ShapeProperties extends XmlComponent {
|
||||
private readonly form: Form;
|
||||
|
||||
public constructor(transform: IMediaDataTransformation) {
|
||||
public constructor({ outline, transform }: { readonly outline?: OutlineOptions; readonly transform: IMediaDataTransformation }) {
|
||||
super("pic:spPr");
|
||||
|
||||
this.root.push(
|
||||
@ -23,7 +23,10 @@ export class ShapeProperties extends XmlComponent {
|
||||
|
||||
this.root.push(this.form);
|
||||
this.root.push(new PresetGeometry());
|
||||
// this.root.push(new NoFill());
|
||||
// this.root.push(new Outline());
|
||||
|
||||
if (outline) {
|
||||
this.root.push(createNoFill());
|
||||
this.root.push(createOutline(outline));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ import { IMediaData, IMediaDataTransformation } from "@file/media";
|
||||
import { XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { GraphicData } from "./graphic-data";
|
||||
import { OutlineOptions } from "./graphic-data/pic/shape-properties/outline/outline";
|
||||
|
||||
class GraphicAttributes extends XmlAttributeComponent<{
|
||||
readonly a: string;
|
||||
@ -14,7 +15,15 @@ class GraphicAttributes extends XmlAttributeComponent<{
|
||||
export class Graphic extends XmlComponent {
|
||||
private readonly data: GraphicData;
|
||||
|
||||
public constructor(mediaData: IMediaData, transform: IMediaDataTransformation) {
|
||||
public constructor({
|
||||
mediaData,
|
||||
transform,
|
||||
outline,
|
||||
}: {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly outline?: OutlineOptions;
|
||||
}) {
|
||||
super("a:graphic");
|
||||
this.root.push(
|
||||
new GraphicAttributes({
|
||||
@ -22,7 +31,7 @@ export class Graphic extends XmlComponent {
|
||||
}),
|
||||
);
|
||||
|
||||
this.data = new GraphicData(mediaData, transform);
|
||||
this.data = new GraphicData({ mediaData, transform, outline });
|
||||
|
||||
this.root.push(this.data);
|
||||
}
|
||||
|
@ -1,12 +0,0 @@
|
||||
import { XmlAttributeComponent } from "@file/xml-components";
|
||||
import { IDistance } from "../drawing";
|
||||
|
||||
// distT, distB etc have no effect on inline images, only floating
|
||||
export class InlineAttributes extends XmlAttributeComponent<IDistance> {
|
||||
protected readonly xmlKeys = {
|
||||
distT: "distT",
|
||||
distB: "distB",
|
||||
distL: "distL",
|
||||
distR: "distR",
|
||||
};
|
||||
}
|
58
src/file/drawing/inline/inline.spec.ts
Normal file
58
src/file/drawing/inline/inline.spec.ts
Normal file
@ -0,0 +1,58 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
import { Formatter } from "@export/formatter";
|
||||
import { createInline } from "./inline";
|
||||
|
||||
describe("Inline", () => {
|
||||
it("should create with default effect extent", () => {
|
||||
const tree = new Formatter().format(
|
||||
createInline({
|
||||
mediaData: {
|
||||
fileName: "test.png",
|
||||
stream: Buffer.from(""),
|
||||
transformation: {
|
||||
pixels: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
emus: {
|
||||
x: 0,
|
||||
y: 0,
|
||||
},
|
||||
},
|
||||
},
|
||||
transform: {
|
||||
pixels: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
emus: {
|
||||
x: 100,
|
||||
y: 100,
|
||||
},
|
||||
},
|
||||
docProperties: {
|
||||
name: "test",
|
||||
description: "test",
|
||||
title: "test",
|
||||
},
|
||||
outline: { type: "solidFill", solidFillType: "rgb", value: "FFFFFF" },
|
||||
}),
|
||||
);
|
||||
|
||||
expect(tree).toStrictEqual({
|
||||
"wp:inline": expect.arrayContaining([
|
||||
{
|
||||
"wp:effectExtent": {
|
||||
_attr: {
|
||||
b: 19050,
|
||||
l: 19050,
|
||||
r: 19050,
|
||||
t: 19050,
|
||||
},
|
||||
},
|
||||
},
|
||||
]),
|
||||
});
|
||||
});
|
||||
});
|
@ -1,18 +1,19 @@
|
||||
// http://officeopenxml.com/drwPicInline.php
|
||||
import { IMediaData, IMediaDataTransformation } from "@file/media";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
import { BuilderElement, XmlComponent } from "@file/xml-components";
|
||||
import { DocProperties, DocPropertiesOptions } from "./../doc-properties/doc-properties";
|
||||
import { EffectExtent } from "./../effect-extent/effect-extent";
|
||||
import { createEffectExtent } from "./../effect-extent/effect-extent";
|
||||
import { Extent } from "./../extent/extent";
|
||||
import { GraphicFrameProperties } from "./../graphic-frame/graphic-frame-properties";
|
||||
import { Graphic } from "./../inline/graphic";
|
||||
import { InlineAttributes } from "./inline-attributes";
|
||||
import { OutlineOptions } from "./graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||
|
||||
interface InlineOptions {
|
||||
type InlineOptions = {
|
||||
readonly mediaData: IMediaData;
|
||||
readonly transform: IMediaDataTransformation;
|
||||
readonly docProperties?: DocPropertiesOptions;
|
||||
}
|
||||
readonly outline?: OutlineOptions;
|
||||
};
|
||||
|
||||
// <xsd:complexType name="CT_Inline">
|
||||
// <xsd:sequence>
|
||||
@ -28,29 +29,41 @@ interface InlineOptions {
|
||||
// <xsd:attribute name="distL" type="ST_WrapDistance" use="optional"/>
|
||||
// <xsd:attribute name="distR" type="ST_WrapDistance" use="optional"/>
|
||||
// </xsd:complexType>
|
||||
export class Inline extends XmlComponent {
|
||||
private readonly extent: Extent;
|
||||
private readonly graphic: Graphic;
|
||||
|
||||
public constructor({ mediaData, transform, docProperties }: InlineOptions) {
|
||||
super("wp:inline");
|
||||
|
||||
this.root.push(
|
||||
new InlineAttributes({
|
||||
distT: 0,
|
||||
distB: 0,
|
||||
distL: 0,
|
||||
distR: 0,
|
||||
}),
|
||||
);
|
||||
|
||||
this.extent = new Extent(transform.emus.x, transform.emus.y);
|
||||
this.graphic = new Graphic(mediaData, transform);
|
||||
|
||||
this.root.push(this.extent);
|
||||
this.root.push(new EffectExtent());
|
||||
this.root.push(new DocProperties(docProperties));
|
||||
this.root.push(new GraphicFrameProperties());
|
||||
this.root.push(this.graphic);
|
||||
}
|
||||
}
|
||||
export const createInline = ({ mediaData, transform, docProperties, outline }: InlineOptions): XmlComponent =>
|
||||
new BuilderElement({
|
||||
name: "wp:inline",
|
||||
attributes: {
|
||||
distanceTop: {
|
||||
key: "distT",
|
||||
value: 0,
|
||||
},
|
||||
distanceBottom: {
|
||||
key: "distB",
|
||||
value: 0,
|
||||
},
|
||||
distanceLeft: {
|
||||
key: "distL",
|
||||
value: 0,
|
||||
},
|
||||
distanceRight: {
|
||||
key: "distR",
|
||||
value: 0,
|
||||
},
|
||||
},
|
||||
children: [
|
||||
new Extent(transform.emus.x, transform.emus.y),
|
||||
createEffectExtent(
|
||||
outline
|
||||
? {
|
||||
top: (outline.width ?? 9525) * 2,
|
||||
right: (outline.width ?? 9525) * 2,
|
||||
bottom: (outline.width ?? 9525) * 2,
|
||||
left: (outline.width ?? 9525) * 2,
|
||||
}
|
||||
: { top: 0, right: 0, bottom: 0, left: 0 },
|
||||
),
|
||||
new DocProperties(docProperties),
|
||||
new GraphicFrameProperties(),
|
||||
new Graphic({ mediaData, transform, outline }),
|
||||
],
|
||||
});
|
||||
|
@ -77,6 +77,7 @@ export class File {
|
||||
evenAndOddHeaders: options.evenAndOddHeaderAndFooters ? true : false,
|
||||
trackRevisions: options.features?.trackRevisions,
|
||||
updateFields: options.features?.updateFields,
|
||||
defaultTabStop: options.defaultTabStop,
|
||||
});
|
||||
|
||||
this.media = new Media();
|
||||
|
@ -2,7 +2,7 @@ import { SpaceType } from "@file/shared";
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { TextAttributes } from "../run/text-attributes";
|
||||
import { IPageReferenceOptions } from "./pageref-properties";
|
||||
import { IPageReferenceOptions } from "./pageref";
|
||||
|
||||
export class PageReferenceFieldInstruction extends XmlComponent {
|
||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||
|
@ -1,16 +0,0 @@
|
||||
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
||||
|
||||
export interface IPageReferenceOptions {
|
||||
/**
|
||||
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
||||
*/
|
||||
readonly hyperlink?: boolean;
|
||||
/**
|
||||
* \p option - Causes the field to display its position relative to the source
|
||||
* bookmark. If the PAGEREF field is on the same page as the
|
||||
* bookmark, it omits "on page #" and returns "above" or "below"
|
||||
* only. If the PAGEREF field is not on the same page as the
|
||||
* bookmark, the string "on page #" is used.
|
||||
*/
|
||||
readonly useRelativePosition?: boolean;
|
||||
}
|
@ -2,7 +2,22 @@
|
||||
import { Begin, End } from "@file/paragraph/run/field";
|
||||
import { Run } from "../run";
|
||||
import { PageReferenceFieldInstruction } from "./pageref-field-instruction";
|
||||
import type { IPageReferenceOptions } from "./pageref-properties";
|
||||
|
||||
// Options according to https://www.ecma-international.org/publications/standards/Ecma-376.htm (at Part 1, Page 1234)
|
||||
export type IPageReferenceOptions = {
|
||||
/**
|
||||
* \h option - Creates a hyperlink to the bookmarked paragraph.
|
||||
*/
|
||||
readonly hyperlink?: boolean;
|
||||
/**
|
||||
* \p option - Causes the field to display its position relative to the source
|
||||
* bookmark. If the PAGEREF field is on the same page as the
|
||||
* bookmark, it omits "on page #" and returns "above" or "below"
|
||||
* only. If the PAGEREF field is not on the same page as the
|
||||
* bookmark, the string "on page #" is used.
|
||||
*/
|
||||
readonly useRelativePosition?: boolean;
|
||||
};
|
||||
|
||||
export class PageReference extends Run {
|
||||
public constructor(bookmarkId: string, options: IPageReferenceOptions = {}) {
|
||||
|
@ -159,6 +159,21 @@ describe("ParagraphProperties", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with the overflowPunct property", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
overflowPunctuation: true,
|
||||
});
|
||||
const tree = new Formatter().format(properties);
|
||||
|
||||
expect(tree).to.deep.equal({
|
||||
"w:pPr": [
|
||||
{
|
||||
"w:overflowPunct": {},
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
it("should create with the run property", () => {
|
||||
const properties = new ParagraphProperties({
|
||||
run: {
|
||||
|
@ -60,6 +60,7 @@ export interface IParagraphPropertiesOptions extends IParagraphStylePropertiesOp
|
||||
readonly frame?: IFrameOptions;
|
||||
readonly suppressLineNumbers?: boolean;
|
||||
readonly wordWrap?: boolean;
|
||||
readonly overflowPunctuation?: boolean;
|
||||
readonly scale?: number;
|
||||
/**
|
||||
* This element specifies whether inter-character spacing shall automatically be adjusted between regions of numbers and regions of East Asian text in the current paragraph. These regions shall be determined by the Unicode character values of the text content within the paragraph.
|
||||
@ -152,14 +153,18 @@ export class ParagraphProperties extends IgnoreIfEmptyXmlComponent {
|
||||
this.push(new WordWrap());
|
||||
}
|
||||
|
||||
if (options.overflowPunctuation) {
|
||||
this.push(new OnOffElement("w:overflowPunct", options.overflowPunctuation));
|
||||
}
|
||||
|
||||
/**
|
||||
* FIX: Multitab support for Libre Writer
|
||||
* Ensure there is only one w:tabs tag with multiple w:tab
|
||||
*/
|
||||
const tabDefinitions: readonly TabStopDefinition[] = [
|
||||
...(options.rightTabStop ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
||||
...(options.rightTabStop !== undefined ? [{ type: TabStopType.RIGHT, position: options.rightTabStop }] : []),
|
||||
...(options.tabStops ? options.tabStops : []),
|
||||
...(options.leftTabStop ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
||||
...(options.leftTabStop !== undefined ? [{ type: TabStopType.LEFT, position: options.leftTabStop }] : []),
|
||||
];
|
||||
|
||||
if (tabDefinitions.length > 0) {
|
||||
|
@ -3,6 +3,7 @@ import { uniqueId } from "@util/convenience-functions";
|
||||
import { IContext, IXmlableObject } from "@file/xml-components";
|
||||
import { DocPropertiesOptions } from "@file/drawing/doc-properties/doc-properties";
|
||||
|
||||
import { OutlineOptions } from "../../drawing/inline/graphic/graphic-data/pic/shape-properties/outline/outline";
|
||||
import { Drawing, IFloating } from "../../drawing";
|
||||
import { IMediaTransformation } from "../../media";
|
||||
import { IMediaData } from "../../media/data";
|
||||
@ -13,6 +14,7 @@ export interface IImageOptions {
|
||||
readonly transformation: IMediaTransformation;
|
||||
readonly floating?: IFloating;
|
||||
readonly altText?: DocPropertiesOptions;
|
||||
readonly outline?: OutlineOptions;
|
||||
}
|
||||
|
||||
export class ImageRun extends Run {
|
||||
@ -39,7 +41,11 @@ export class ImageRun extends Run {
|
||||
rotation: options.transformation.rotation ? options.transformation.rotation * 60000 : undefined,
|
||||
},
|
||||
};
|
||||
const drawing = new Drawing(this.imageData, { floating: options.floating, docProperties: options.altText });
|
||||
const drawing = new Drawing(this.imageData, {
|
||||
floating: options.floating,
|
||||
docProperties: options.altText,
|
||||
outline: options.outline,
|
||||
});
|
||||
|
||||
this.root.push(drawing);
|
||||
}
|
||||
@ -65,6 +71,8 @@ export class ImageRun extends Run {
|
||||
.map((c) => c.charCodeAt(0)),
|
||||
);
|
||||
} else {
|
||||
/* c8 ignore next 4 */
|
||||
// Not possible to test this branch in NodeJS
|
||||
// eslint-disable-next-line @typescript-eslint/no-require-imports, @typescript-eslint/no-var-requires
|
||||
const b = require("buf" + "fer");
|
||||
return new b.Buffer(dataURI, "base64");
|
||||
|
@ -26,3 +26,11 @@ export class NumberOfPagesSection extends XmlComponent {
|
||||
this.root.push("SECTIONPAGES");
|
||||
}
|
||||
}
|
||||
|
||||
export class CurrentPageInSection extends XmlComponent {
|
||||
public constructor() {
|
||||
super("w:instrText");
|
||||
this.root.push(new TextAttributes({ space: SpaceType.PRESERVE }));
|
||||
this.root.push("SECTION");
|
||||
}
|
||||
}
|
||||
|
@ -432,6 +432,23 @@ describe("Run", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("#section", () => {
|
||||
it("should set the run to the RTL mode", () => {
|
||||
const run = new Run({
|
||||
children: [PageNumber.CURRENT_SECTION],
|
||||
});
|
||||
const tree = new Formatter().format(run);
|
||||
expect(tree).to.deep.equal({
|
||||
"w:r": [
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "begin" } } },
|
||||
{ "w:instrText": [{ _attr: { "xml:space": "preserve" } }, "SECTION"] },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "separate" } } },
|
||||
{ "w:fldChar": { _attr: { "w:fldCharType": "end" } } },
|
||||
],
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("#style", () => {
|
||||
it("should set the style to the given styleId", () => {
|
||||
const run = new Run({
|
||||
|
@ -6,7 +6,7 @@ import { FieldInstruction } from "@file/table-of-contents/field-instruction";
|
||||
|
||||
import { Break } from "./break";
|
||||
import { Begin, End, Separate } from "./field";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page } from "./page-number";
|
||||
import { NumberOfPages, NumberOfPagesSection, Page, CurrentPageInSection } from "./page-number";
|
||||
import { IRunPropertiesOptions, RunProperties } from "./properties";
|
||||
import { Text } from "./run-components/text";
|
||||
import {
|
||||
@ -103,6 +103,7 @@ export const PageNumber = {
|
||||
CURRENT: "CURRENT",
|
||||
TOTAL_PAGES: "TOTAL_PAGES",
|
||||
TOTAL_PAGES_IN_SECTION: "TOTAL_PAGES_IN_SECTION",
|
||||
CURRENT_SECTION: "SECTION",
|
||||
} as const;
|
||||
|
||||
/* eslint-enable */
|
||||
@ -143,6 +144,12 @@ export class Run extends XmlComponent {
|
||||
this.root.push(new Separate());
|
||||
this.root.push(new End());
|
||||
break;
|
||||
case PageNumber.CURRENT_SECTION:
|
||||
this.root.push(new Begin());
|
||||
this.root.push(new CurrentPageInSection());
|
||||
this.root.push(new Separate());
|
||||
this.root.push(new End());
|
||||
break;
|
||||
default:
|
||||
this.root.push(new Text(child));
|
||||
break;
|
||||
|
@ -112,6 +112,23 @@ describe("Settings", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("should add defaultTabStop setting with version", () => {
|
||||
const settings = new Settings({
|
||||
defaultTabStop: 100,
|
||||
});
|
||||
|
||||
const tree = new Formatter().format(settings);
|
||||
expect(Object.keys(tree)).has.length(1);
|
||||
expect(tree["w:settings"]).to.be.an("array");
|
||||
expect(tree["w:settings"]).to.deep.include({
|
||||
"w:defaultTabStop": {
|
||||
_attr: {
|
||||
"w:val": 100,
|
||||
},
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
// TODO: Remove when deprecating compatibilityModeVersion
|
||||
it("should add compatibility setting with legacy version", () => {
|
||||
const settings = new Settings({
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
import { NumberValueElement, OnOffElement, XmlAttributeComponent, XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { Compatibility, ICompatibilityOptions } from "./compatibility";
|
||||
|
||||
@ -152,6 +152,7 @@ export interface ISettingsOptions {
|
||||
readonly trackRevisions?: boolean;
|
||||
readonly updateFields?: boolean;
|
||||
readonly compatibility?: ICompatibilityOptions;
|
||||
readonly defaultTabStop?: number;
|
||||
}
|
||||
|
||||
export class Settings extends XmlComponent {
|
||||
@ -198,6 +199,11 @@ export class Settings extends XmlComponent {
|
||||
this.root.push(new OnOffElement("w:updateFields", options.updateFields));
|
||||
}
|
||||
|
||||
// https://c-rex.net/samples/ooxml/e1/Part4/OOXML_P4_DOCX_defaultTabStop_topic_ID0EIXSX.html
|
||||
if (options.defaultTabStop !== undefined) {
|
||||
this.root.push(new NumberValueElement("w:defaultTabStop", options.defaultTabStop));
|
||||
}
|
||||
|
||||
this.root.push(
|
||||
new Compatibility({
|
||||
...(options.compatibility ?? {}),
|
||||
|
@ -1,10 +1,10 @@
|
||||
import { XmlComponent } from "@file/xml-components";
|
||||
|
||||
import { IRunOptions, RunProperties } from "../../index";
|
||||
import { Break } from "../../paragraph/run/break";
|
||||
import { Begin, End, Separate } from "../../paragraph/run/field";
|
||||
import { PageNumber } from "../../paragraph/run/run";
|
||||
import { IRunOptions, PageNumber } from "../../paragraph/run/run";
|
||||
import { ChangeAttributes, IChangedAttributesProperties } from "../track-revision";
|
||||
import { RunProperties } from "../../paragraph/run/properties";
|
||||
import { DeletedNumberOfPages, DeletedNumberOfPagesSection, DeletedPage } from "./deleted-page-number";
|
||||
import { DeletedText } from "./deleted-text";
|
||||
|
||||
|
@ -93,6 +93,8 @@ export class BuilderElement<T extends AttributeData> extends XmlComponent {
|
||||
this.root.push(new NextAttributeComponent(options.attributes));
|
||||
}
|
||||
|
||||
// TODO: Children
|
||||
for (const child of options.children ?? []) {
|
||||
this.root.push(child);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ export abstract class XmlComponent extends BaseXmlComponent {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated Do not use this method. It is only used internally by the library. It will be removed in a future version.
|
||||
*/
|
||||
public addChildElement(child: XmlComponent | string): XmlComponent {
|
||||
this.root.push(child);
|
||||
|
||||
|
@ -1,9 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"target": "ES2020",
|
||||
"target": "ES2015",
|
||||
"useDefineForClassFields": true,
|
||||
"module": "ESNext",
|
||||
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||
"lib": ["ES2015", "DOM", "DOM.Iterable"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { defineConfig } from "vitest/config";
|
||||
import { configDefaults, defineConfig } from "vitest/config";
|
||||
import { resolve } from "path";
|
||||
import tsconfigPaths from "vite-tsconfig-paths";
|
||||
import dts from "vite-plugin-dts";
|
||||
@ -60,10 +60,31 @@ export default defineConfig({
|
||||
coverage: {
|
||||
provider: "v8",
|
||||
reporter: ["text", "json", "html"],
|
||||
statements: 99.93,
|
||||
branches: 98.85,
|
||||
functions: 100,
|
||||
lines: 99.93,
|
||||
thresholds: {
|
||||
statements: 99.96,
|
||||
branches: 98.98,
|
||||
functions: 100,
|
||||
lines: 99.96,
|
||||
},
|
||||
exclude: [
|
||||
...configDefaults.exclude,
|
||||
'**/build/**',
|
||||
'**/demo/**',
|
||||
'**/docs/**',
|
||||
'**/scripts/**',
|
||||
'**/src/**/index.ts',
|
||||
],
|
||||
},
|
||||
include: [
|
||||
'**/src/**/*.spec.ts',
|
||||
'**/packages/**/*.spec.ts'
|
||||
],
|
||||
exclude: [
|
||||
...configDefaults.exclude,
|
||||
'**/build/**',
|
||||
'**/demo/**',
|
||||
'**/docs/**',
|
||||
'**/scripts/**'
|
||||
],
|
||||
},
|
||||
});
|
||||
|
Reference in New Issue
Block a user