commonform-docx 10.1.0 → 10.1.2
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/README.md +15 -2
- package/bin.js +2 -2
- package/index.js +115 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,7 +12,7 @@ The exported function takes three arguments:
|
|
|
12
12
|
|
|
13
13
|
The options object must contain:
|
|
14
14
|
|
|
15
|
-
1. a `numbering` property whose value is an [abstract numbering](https://npmjs.com/
|
|
15
|
+
1. a `numbering` property whose value is an [abstract numbering](https://npmjs.com/package/abstract-numbering)
|
|
16
16
|
|
|
17
17
|
It may contain:
|
|
18
18
|
|
|
@@ -26,4 +26,17 @@ It may contain:
|
|
|
26
26
|
|
|
27
27
|
5. other properties you can find in function exported from `index.js`
|
|
28
28
|
|
|
29
|
-
The function returns a [JSZip](https://npmjs.com/
|
|
29
|
+
The function returns a [JSZip](https://npmjs.com/package/jszip) Object primed with `.docx` document data.
|
|
30
|
+
|
|
31
|
+
For example:
|
|
32
|
+
|
|
33
|
+
```javascript
|
|
34
|
+
const zip = docx(form, {
|
|
35
|
+
title: 'Example Document',
|
|
36
|
+
version: 'Version 1.0.0'
|
|
37
|
+
})
|
|
38
|
+
await writeFile(
|
|
39
|
+
'example.docx',
|
|
40
|
+
await zip.generateAsync({ type: 'nodebuffer' })
|
|
41
|
+
)
|
|
42
|
+
```
|
package/bin.js
CHANGED
|
@@ -14,7 +14,7 @@ const usage = [
|
|
|
14
14
|
' -h, --help Show this screen.',
|
|
15
15
|
' -v, --version Show version.',
|
|
16
16
|
' -H, --hash Render form hash',
|
|
17
|
-
' -a, --a4-paper
|
|
17
|
+
' -a, --a4-paper Set paper size to A4',
|
|
18
18
|
' -b TEXT, --blank-text TEXT Render blanks with custom text',
|
|
19
19
|
' --complete Throw an error if any blank does not have a value.',
|
|
20
20
|
' --component-style STYLE Change component style [default: both]',
|
|
@@ -32,7 +32,7 @@ const usage = [
|
|
|
32
32
|
' -r --left-align-body Left-align body paragraphs.',
|
|
33
33
|
' -s PAGES, --signatures PAGES Signature page data',
|
|
34
34
|
' -t TITLE, --title TITLE Render title as <h1>',
|
|
35
|
-
'
|
|
35
|
+
' --values JSON Use values to fill in blanks',
|
|
36
36
|
' -y JSON, --styles JSON Render with custom styles'
|
|
37
37
|
].join('\n')
|
|
38
38
|
|
package/index.js
CHANGED
|
@@ -81,7 +81,7 @@ module.exports = (form, values = [], options = {}) => {
|
|
|
81
81
|
}
|
|
82
82
|
)
|
|
83
83
|
const scaffold = require('./data/scaffold.json')
|
|
84
|
-
const clone =
|
|
84
|
+
const clone = structuredClone(scaffold)
|
|
85
85
|
clone.word['document.xml'] = result.xml
|
|
86
86
|
clone.word._rels['document.xml.rels'] = docRels(result.hrefs)
|
|
87
87
|
// Set default font size. We need to replace <w:sz> and <w:szCs>
|
|
@@ -101,9 +101,122 @@ module.exports = (form, values = [], options = {}) => {
|
|
|
101
101
|
clone.word['styles.xml'] = clone.word['styles.xml']
|
|
102
102
|
.replaceAll(
|
|
103
103
|
'<w:rFonts w:ascii="Times New Roman" w:hAnsi="Times New Roman"/>',
|
|
104
|
-
`<w:rFonts w:ascii="${font}" w:hAnsi="${font}"/>`
|
|
104
|
+
`<w:rFonts w:ascii="${font}" w:hAnsi="${font}" w:cs="${font}"/>`
|
|
105
105
|
)
|
|
106
106
|
}
|
|
107
|
+
// Set styles for comment bubble text to match main body.
|
|
108
|
+
// It's not exactly clear what each of these styles apply to. It at
|
|
109
|
+
// least appears that some versions of Word, like 365 and For Mac, use
|
|
110
|
+
// primarily or exclusively the "Balloon" styles, while Word for
|
|
111
|
+
// Windows seems to use primarily the "Comment" styles.
|
|
112
|
+
const rsid = '<w:rsid w:val="009714CB"/>'
|
|
113
|
+
const fontAndSizeTags = `<w:rFonts w:ascii="${font}" w:hAnsi="${font}" w:cs="${font}"/><w:sz w:val="${fontSizeInHalfPoints}"/><w:szCs w:val="${fontSizeInHalfPoints}"/>`
|
|
114
|
+
clone.word['styles.xml'] = clone.word['styles.xml']
|
|
115
|
+
.replace(
|
|
116
|
+
'</w:styles>',
|
|
117
|
+
[
|
|
118
|
+
// Balloon Text
|
|
119
|
+
'<w:style w:type="paragraph" w:styleId="BalloonText">',
|
|
120
|
+
'<w:name w:val="Balloon Text"/>',
|
|
121
|
+
'<w:basedOn w:val="Normal"/>',
|
|
122
|
+
'<w:link w:val="BalloonTextChar"/>',
|
|
123
|
+
'<w:uiPriority w:val="99"/>',
|
|
124
|
+
'<w:semiHidden/>',
|
|
125
|
+
'<w:unhideWhenUsed/>',
|
|
126
|
+
rsid,
|
|
127
|
+
'<w:pPr><w:spacing w:before="0" w:after="0"/></w:pPr>',
|
|
128
|
+
'<w:rPr>',
|
|
129
|
+
fontAndSizeTags,
|
|
130
|
+
'</w:rPr>',
|
|
131
|
+
'</w:style>',
|
|
132
|
+
|
|
133
|
+
// Balloon Text Char
|
|
134
|
+
'<w:style w:type="character" w:customStyle="1" w:styleId="BalloonTextChar">',
|
|
135
|
+
'<w:name w:val="Balloon Text Char"/>',
|
|
136
|
+
'<w:basedOn w:val="DefaultParagraphFont"/>',
|
|
137
|
+
'<w:link w:val="BalloonText"/>',
|
|
138
|
+
'<w:uiPriority w:val="99"/>',
|
|
139
|
+
'<w:semiHidden/>',
|
|
140
|
+
rsid,
|
|
141
|
+
'<w:rPr>',
|
|
142
|
+
fontAndSizeTags,
|
|
143
|
+
'</w:rPr>',
|
|
144
|
+
'</w:style>',
|
|
145
|
+
|
|
146
|
+
// Comment Reference
|
|
147
|
+
'<w:style w:type="character" w:styleId="CommentReference">',
|
|
148
|
+
'<w:name w:val="annotation reference"/>',
|
|
149
|
+
'<w:basedOn w:val="DefaultParagraphFont"/>',
|
|
150
|
+
'<w:uiPriority w:val="99"/>',
|
|
151
|
+
'<w:semiHidden/>',
|
|
152
|
+
'<w:unhideWhenUsed/>',
|
|
153
|
+
rsid,
|
|
154
|
+
'<w:rPr>',
|
|
155
|
+
fontAndSizeTags,
|
|
156
|
+
'</w:rPr>',
|
|
157
|
+
'</w:style>',
|
|
158
|
+
|
|
159
|
+
// Comment Text
|
|
160
|
+
'<w:style w:type="paragraph" w:styleId="CommentText">',
|
|
161
|
+
'<w:name w:val="annotation text"/>',
|
|
162
|
+
'<w:basedOn w:val="Normal"/>',
|
|
163
|
+
'<w:link w:val="CommentTextChar"/>',
|
|
164
|
+
'<w:uiPriority w:val="99"/>',
|
|
165
|
+
'<w:semiHidden/>',
|
|
166
|
+
'<w:unhideWhenUsed/>',
|
|
167
|
+
rsid,
|
|
168
|
+
'<w:pPr><w:spacing w:line="240" w:lineRule="auto"/></w:pPr>',
|
|
169
|
+
'<w:rPr>',
|
|
170
|
+
fontAndSizeTags,
|
|
171
|
+
'</w:rPr>',
|
|
172
|
+
'</w:style>',
|
|
173
|
+
|
|
174
|
+
// Comment Text Char
|
|
175
|
+
'<w:style w:type="character" w:customStyle="1" w:styleId="CommentTextChar">',
|
|
176
|
+
'<w:name w:val="Comment Text Char"/>',
|
|
177
|
+
'<w:basedOn w:val="DefaultParagraphFont"/>',
|
|
178
|
+
'<w:link w:val="CommentText"/>',
|
|
179
|
+
'<w:uiPriority w:val="99"/>',
|
|
180
|
+
'<w:semiHidden/>',
|
|
181
|
+
rsid,
|
|
182
|
+
'<w:rPr>',
|
|
183
|
+
fontAndSizeTags,
|
|
184
|
+
'</w:rPr>',
|
|
185
|
+
'</w:style>',
|
|
186
|
+
|
|
187
|
+
// Comment Subject
|
|
188
|
+
'<w:style w:type="paragraph" w:styleId="CommentSubject">',
|
|
189
|
+
'<w:name w:val="annotation subject"/>',
|
|
190
|
+
'<w:basedOn w:val="CommentText"/>',
|
|
191
|
+
'<w:next w:val="CommentText"/>',
|
|
192
|
+
'<w:link w:val="CommentSubjectChar"/>',
|
|
193
|
+
'<w:uiPriority w:val="99"/>',
|
|
194
|
+
'<w:semiHidden/>',
|
|
195
|
+
'<w:unhideWhenUsed/>',
|
|
196
|
+
rsid,
|
|
197
|
+
'<w:rPr>',
|
|
198
|
+
'<w:b/><w:bCs/>',
|
|
199
|
+
fontAndSizeTags,
|
|
200
|
+
'</w:rPr>',
|
|
201
|
+
'</w:style>',
|
|
202
|
+
|
|
203
|
+
// Comment Subject Char
|
|
204
|
+
'<w:style w:type="character" w:customStyle="1" w:styleId="CommentSubjectChar">',
|
|
205
|
+
'<w:name w:val="Comment Subject Char"/>',
|
|
206
|
+
'<w:basedOn w:val="CommentTextChar"/>',
|
|
207
|
+
'<w:link w:val="CommentSubject"/>',
|
|
208
|
+
'<w:uiPriority w:val="99"/>',
|
|
209
|
+
'<w:semiHidden/>',
|
|
210
|
+
rsid,
|
|
211
|
+
'<w:rPr>',
|
|
212
|
+
'<w:b/><w:bCs/>',
|
|
213
|
+
fontAndSizeTags,
|
|
214
|
+
'</w:rPr>',
|
|
215
|
+
'</w:style>',
|
|
216
|
+
|
|
217
|
+
'</w:styles>'
|
|
218
|
+
].join('')
|
|
219
|
+
)
|
|
107
220
|
const zip = new JSZip()
|
|
108
221
|
zipObject(zip, clone)
|
|
109
222
|
return zip
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "commonform-docx",
|
|
3
3
|
"description": "render Common Forms in Office Open XML (Microsoft Word .docx format)",
|
|
4
|
-
"version": "10.1.
|
|
4
|
+
"version": "10.1.2",
|
|
5
5
|
"author": "Kyle E. Mitchell <kyle@kemitchell.com> (http://kemitchell.com)",
|
|
6
6
|
"bin": "bin.js",
|
|
7
7
|
"files": [
|