w-html2docx 1.0.27 → 1.0.29

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.
@@ -45,175 +45,209 @@
45
45
 
46
46
  <section>
47
47
  <article>
48
- <pre class="prettyprint source linenums"><code>import path from 'path'
49
- import process from 'process'
50
- import get from 'lodash-es/get.js'
51
- import isestr from 'wsemi/src/isestr.mjs'
52
- import isearr from 'wsemi/src/isearr.mjs'
53
- import ispnum from 'wsemi/src/ispnum.mjs'
54
- import cdbl from 'wsemi/src/cdbl.mjs'
55
- import str2b64 from 'wsemi/src/str2b64.mjs'
56
- import execProcess from 'wsemi/src/execProcess.mjs'
57
- import fsIsFile from 'wsemi/src/fsIsFile.mjs'
58
- import autoDownloadFiles from './autoDownloadFiles.mjs'
59
-
60
-
61
- let fdSrv = path.resolve()
62
-
63
-
64
- function isWindows() {
65
- return process.platform === 'win32'
66
- }
67
-
68
-
69
- /**
70
- * Html檔轉Docx檔
71
- *
72
- * @param {String} fpInHtml 輸入來源Html檔位置字串
73
- * @param {String} fpOutDocx 輸入轉出Docx檔位置字串
74
- * @param {Object} [opt={}] 輸入設定物件,預設{}
75
- * @param {String} [opt.fpInTemp='./src/tmp.docx'] 輸入Docx模板檔案位置字串,預設'./src/tmp.docx'
76
- * @param {Array|String} [opt.fontFamilies=['標楷體','Times New Roman']] 輸入轉出Docx時強制更改字型陣列或字串,陣列順序為變更順序,若有要覆寫字型得放後面。預設['標楷體','Times New Roman']
77
- * @param {String} [opt.imgRatioWidthMax=1] 輸入圖片最大寬度比例,值介於0至1,預設1
78
- * @param {String} [opt.imgRatioHeightMax=1] 輸入圖片最大高度比例,值介於0至1,預設1
79
- * @returns {Promise} 回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息
80
- * @example
81
- *
82
- * import w from 'wsemi'
83
- * import WHtml2docx from './src/WHtml2docx.mjs'
84
- * //import WHtml2docx from 'w-html2docx/src/WHtml2docx.mjs'
85
- * //import WHtml2docx from 'w-html2docx'
86
- *
87
- * async function test() {
88
- *
89
- * let fpIn = `./test/ztmp.html`
90
- * let fpOut = `./test/ztmp.docx`
91
- * let opt = {
92
- * imgRatioWidthMax: 0.5,
93
- * }
94
- *
95
- * let r = await WHtml2docx(fpIn, fpOut, opt)
96
- * console.log(r)
97
- * // => ok
98
- *
99
- * w.fsDeleteFile(fpOut)
100
- *
101
- * }
102
- * test()
103
- * .catch((err) => {
104
- * console.log('catch', err)
105
- * })
106
- *
107
- */
108
- async function WHtml2docx(fpInHtml, fpOutDocx, opt = {}) {
109
- let errTemp = null
110
-
111
- //isWindows
112
- if (!isWindows()) {
113
- return Promise.reject('operating system is not windows')
114
- }
115
-
116
- //check
117
- if (!fsIsFile(fpInHtml)) {
118
- return Promise.reject(`fpInHtml[${fpInHtml}] does not exist`)
119
- }
120
-
121
- //fontFamilies
122
- let fontFamilies = get(opt, 'fontFamilies')
123
- if (isestr(fontFamilies)) {
124
- fontFamilies = [fontFamilies]
125
- }
126
- if (!isearr(fontFamilies)) {
127
- fontFamilies = ['標楷體', 'Times New Roman']
128
- }
129
-
130
- //imgRatioWidthMax
131
- let imgRatioWidthMax = get(opt, 'imgRatioWidthMax')
132
- if (!ispnum(imgRatioWidthMax)) {
133
- imgRatioWidthMax = 1
134
- }
135
- imgRatioWidthMax = cdbl(imgRatioWidthMax)
136
-
137
- //imgRatioHeightMax
138
- let imgRatioHeightMax = get(opt, 'imgRatioHeightMax')
139
- if (!ispnum(imgRatioHeightMax)) {
140
- imgRatioHeightMax = 1
141
- }
142
- imgRatioHeightMax = cdbl(imgRatioHeightMax)
143
-
144
- //fpInTemp
145
- let fpInTemp = get(opt, 'fpInTemp')
146
- if (!isestr(fpInTemp)) {
147
-
148
- //fnTmp
149
- let fnTmp = `tmp.docx`
150
-
151
- //fpInTemp
152
- if (true) {
153
- let fpTmpSrc = `${fdSrv}/src/${fnTmp}`
154
- let fpTmpNM = `${fdSrv}/node_modules/w-html2docx/src/${fnTmp}`
155
- if (fsIsFile(fpTmpSrc)) {
156
- fpInTemp = fpTmpSrc
157
- }
158
- else if (fsIsFile(fpTmpNM)) {
159
- fpInTemp = fpTmpNM
160
- }
161
- else {
162
- return Promise.reject(`can not find folder for ${fnTmp}`)
163
- }
164
-
165
- }
166
-
167
- }
168
-
169
- //轉絕對路徑
170
- fpInHtml = path.resolve(fpInHtml)
171
- fpInTemp = path.resolve(fpInTemp)
172
- fpOutDocx = path.resolve(fpOutDocx)
173
-
174
- //prog, 自動定位htmlToDocx.exe, 無檔案(安裝時npm封鎖scripts致postinstall未執行)則自動下載
175
- let { fpExe } = await autoDownloadFiles()
176
- let prog = fpExe
177
- // console.log('prog', prog)
178
-
179
- //inp
180
- let inp = {
181
- fpInSrc: fpInHtml,
182
- fpInTemp,
183
- fpOut: fpOutDocx,
184
- fontFamilies: ['標楷體', 'Times New Roman'],
185
- imgRatioWidthMax,
186
- imgRatioHeightMax,
187
- }
188
- // console.log('inp', inp)
189
-
190
- //input to b64
191
- let cInput = JSON.stringify(inp)
192
- let b64Input = str2b64(cInput)
193
- // console.log('b64Input', b64Input)
194
-
195
- //execProcess
196
- await execProcess(prog, b64Input)
197
- .catch((err) => {
198
- console.log('execProcess catch', err)
199
- errTemp = err.toString()
200
- })
201
-
202
- //check
203
- if (errTemp) {
204
- return Promise.reject(errTemp)
205
- }
206
-
207
- // //check
208
- // if (!isestr(output)) {
209
- // return Promise.reject(`output[${cstr(output)}] is not an effective string`)
210
- // }
211
-
212
- return 'ok'
213
- }
214
-
215
-
216
- export default WHtml2docx
48
+ <pre class="prettyprint source linenums"><code>import fs from 'fs'
49
+ import path from 'path'
50
+ import process from 'process'
51
+ import get from 'lodash-es/get.js'
52
+ import isestr from 'wsemi/src/isestr.mjs'
53
+ import isearr from 'wsemi/src/isearr.mjs'
54
+ import ispnum from 'wsemi/src/ispnum.mjs'
55
+ import cdbl from 'wsemi/src/cdbl.mjs'
56
+ import str2b64 from 'wsemi/src/str2b64.mjs'
57
+ import execProcess from 'wsemi/src/execProcess.mjs'
58
+ import fsIsFile from 'wsemi/src/fsIsFile.mjs'
59
+ import fsIsFolder from 'wsemi/src/fsIsFolder.mjs'
60
+ import fsCreateFolder from 'wsemi/src/fsCreateFolder.mjs'
61
+ import autoDownloadFiles from './autoDownloadFiles.mjs'
62
+
63
+
64
+ let fdSrv = path.resolve()
65
+
66
+
67
+ function isWindows() {
68
+ return process.platform === 'win32'
69
+ }
70
+
71
+
72
+ /**
73
+ * Html檔轉Docx
74
+ *
75
+ * 轉檔由套件內之htmlToDocx.exe調用本機Microsoft Word(win32com)完成,故須於Windows且已安裝Word之機器執行。htmlToDocx.exe若不存在(安裝時npm封鎖scripts致postinstall未執行)會於轉檔當下自動下載,下載失敗則reject並帶網址與落點。
76
+ * 轉檔器內部失敗(Word未安裝、模板無法開啟、另存失敗等)一律reject並帶轉檔器回報之原因;resolve前另確認輸出檔已產生且非空。輸出資料夾不存在時自動建立
77
+ *
78
+ * @param {String} fpInHtml 輸入來源Html檔位置字串
79
+ * @param {String} fpOutDocx 輸入轉出Docx檔位置字串
80
+ * @param {Object} [opt={}] 輸入設定物件,預設{}
81
+ * @param {String} [opt.fpInTemp=''] 輸入Docx模板檔案位置字串,有給時須存在否則reject;未給時依序取模組載入當下工作路徑之`./src/tmp.docx`或`./node_modules/w-html2docx/src/tmp.docx`(套件內建模板),預設''
82
+ * @param {Array|String} [opt.fontFamilies=['標楷體','Times New Roman']] 輸入轉出Docx時強制更改字型陣列或字串,陣列順序為變更順序,若有要覆寫字型得放後面。預設['標楷體','Times New Roman']
83
+ * @param {Number} [opt.imgRatioWidthMax=1] 輸入圖片最大寬度比例,值介於0至1,預設1
84
+ * @param {Number} [opt.imgRatioHeightMax=1] 輸入圖片最大高度比例,值介於0至1,預設1
85
+ * @param {Number} [opt.timeout=null] 輸入轉檔逾時毫秒數,預設null表示不限制;逾時時強制關閉轉檔器並reject回傳逾時訊息,惟由轉檔器經COM啟動之Word不在其程序樹內,不會一併被關閉
86
+ * @returns {Promise} 回傳Promise,resolve回傳'ok',reject回傳錯誤訊息字串
87
+ * @example
88
+ *
89
+ * import w from 'wsemi'
90
+ * import WHtml2docx from './src/WHtml2docx.mjs'
91
+ * //import WHtml2docx from 'w-html2docx/src/WHtml2docx.mjs'
92
+ * //import WHtml2docx from 'w-html2docx'
93
+ *
94
+ * async function test() {
95
+ *
96
+ * let fpIn = `./test/ztmp.html`
97
+ * let fpOut = `./test/ztmp.docx`
98
+ * let opt = {
99
+ * imgRatioWidthMax: 0.5,
100
+ * }
101
+ *
102
+ * let r = await WHtml2docx(fpIn, fpOut, opt)
103
+ * console.log(r)
104
+ * // => ok
105
+ *
106
+ * w.fsDeleteFile(fpOut)
107
+ *
108
+ * }
109
+ * test()
110
+ * .catch((err) => {
111
+ * console.log('catch', err)
112
+ * })
113
+ *
114
+ */
115
+ async function WHtml2docx(fpInHtml, fpOutDocx, opt = {}) {
116
+ let errTemp = null
117
+
118
+ //isWindows
119
+ if (!isWindows()) {
120
+ return Promise.reject('operating system is not windows')
121
+ }
122
+
123
+ //check
124
+ if (!fsIsFile(fpInHtml)) {
125
+ return Promise.reject(`fpInHtml[${fpInHtml}] does not exist`)
126
+ }
127
+
128
+ //fontFamilies
129
+ let fontFamilies = get(opt, 'fontFamilies')
130
+ if (isestr(fontFamilies)) {
131
+ fontFamilies = [fontFamilies]
132
+ }
133
+ if (!isearr(fontFamilies)) {
134
+ fontFamilies = ['標楷體', 'Times New Roman']
135
+ }
136
+
137
+ //imgRatioWidthMax
138
+ let imgRatioWidthMax = get(opt, 'imgRatioWidthMax')
139
+ if (!ispnum(imgRatioWidthMax)) {
140
+ imgRatioWidthMax = 1
141
+ }
142
+ imgRatioWidthMax = cdbl(imgRatioWidthMax)
143
+
144
+ //imgRatioHeightMax
145
+ let imgRatioHeightMax = get(opt, 'imgRatioHeightMax')
146
+ if (!ispnum(imgRatioHeightMax)) {
147
+ imgRatioHeightMax = 1
148
+ }
149
+ imgRatioHeightMax = cdbl(imgRatioHeightMax)
150
+
151
+ //timeout
152
+ let timeout = get(opt, 'timeout')
153
+ if (!ispnum(timeout)) {
154
+ timeout = null
155
+ }
156
+
157
+ //fpInTemp
158
+ let fpInTemp = get(opt, 'fpInTemp')
159
+ if (isestr(fpInTemp)) {
160
+
161
+ //check, 呼叫端有提供時須存在, 與fpInHtml之檢查對稱; 否則會由轉檔器於開啟模板時失敗, 訊息為Word之COM錯誤而看不出是路徑問題
162
+ if (!fsIsFile(fpInTemp)) {
163
+ return Promise.reject(`fpInTemp[${fpInTemp}] does not exist`)
164
+ }
165
+
166
+ }
167
+ else {
168
+
169
+ //fnTmp
170
+ let fnTmp = `tmp.docx`
171
+
172
+ //fpInTemp
173
+ if (true) {
174
+ let fpTmpSrc = `${fdSrv}/src/${fnTmp}`
175
+ let fpTmpNM = `${fdSrv}/node_modules/w-html2docx/src/${fnTmp}`
176
+ if (fsIsFile(fpTmpSrc)) {
177
+ fpInTemp = fpTmpSrc
178
+ }
179
+ else if (fsIsFile(fpTmpNM)) {
180
+ fpInTemp = fpTmpNM
181
+ }
182
+ else {
183
+ return Promise.reject(`can not find folder for ${fnTmp}`)
184
+ }
185
+
186
+ }
187
+
188
+ }
189
+
190
+ //轉絕對路徑
191
+ fpInHtml = path.resolve(fpInHtml)
192
+ fpInTemp = path.resolve(fpInTemp)
193
+ fpOutDocx = path.resolve(fpOutDocx)
194
+
195
+ //fdOutDocx, 輸出資料夾不存在時自動建立, 否則Word另存時失敗
196
+ let fdOutDocx = path.dirname(fpOutDocx)
197
+ if (!fsIsFolder(fdOutDocx)) {
198
+ fsCreateFolder(fdOutDocx)
199
+ if (!fsIsFolder(fdOutDocx)) {
200
+ return Promise.reject(`can not create folder[${fdOutDocx}] for fpOutDocx`)
201
+ }
202
+ }
203
+
204
+ //prog, 自動定位htmlToDocx.exe, 無檔案(安裝時npm封鎖scripts致postinstall未執行)則自動下載
205
+ let { fpExe } = await autoDownloadFiles()
206
+ let prog = fpExe
207
+ // console.log('prog', prog)
208
+
209
+ //inp
210
+ let inp = {
211
+ fpInSrc: fpInHtml,
212
+ fpInTemp,
213
+ fpOut: fpOutDocx,
214
+ fontFamilies,
215
+ imgRatioWidthMax,
216
+ imgRatioHeightMax,
217
+ }
218
+ // console.log('inp', inp)
219
+
220
+ //input to b64
221
+ let cInput = JSON.stringify(inp)
222
+ let b64Input = str2b64(cInput)
223
+ // console.log('b64Input', b64Input)
224
+
225
+ //execProcess, 轉檔器成功時印success且離開碼0, 失敗時印error: 原因且離開碼1, 故離開碼非0即reject並帶其輸出
226
+ // codeCmd給auto: 現行轉檔器以utf-8輸出, 尚未重新下載之舊版轉檔器以系統字碼頁(中文Windows為cp950)輸出, auto先以utf-8嚴格解碼, 遇非utf-8位元組改用系統字碼頁, 兩者皆可正確解碼; 轉檔器損毀時bootloader之ANSI訊息亦同
227
+ let output = ''
228
+ await execProcess(prog, b64Input, { codeCmd: 'auto', timeout })
229
+ .then((r) => {
230
+ output = r
231
+ })
232
+ .catch((err) => {
233
+ errTemp = String(err).trim()
234
+ })
235
+
236
+ //check
237
+ if (errTemp) {
238
+ return Promise.reject(errTemp)
239
+ }
240
+
241
+ //check, 轉檔器回報成功仍須確認輸出檔存在且非空: 舊版轉檔器於Word未安裝、模板無法開啟等失敗時仍以離開碼0結束, 只在輸出印出error
242
+ if (!fsIsFile(fpOutDocx) || fs.statSync(fpOutDocx).size === 0) {
243
+ return Promise.reject(`fpOutDocx[${fpOutDocx}] was not generated: ${output.trim()}`)
244
+ }
245
+
246
+ return 'ok'
247
+ }
248
+
249
+
250
+ export default WHtml2docx
217
251
  </code></pre>
218
252
  </article>
219
253
  </section>
@@ -228,7 +262,7 @@ export default WHtml2docx
228
262
  <br class="clear">
229
263
 
230
264
  <footer>
231
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Sep 05 2026 22:30:36 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
265
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Sep 13 2026 21:52:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
232
266
  </footer>
233
267
 
234
268
  <script>prettyPrint();</script>
@@ -65,6 +65,9 @@ let pmDownload = null
65
65
  * 依序偵測當前工作路徑的src/與node_modules/w-html2docx/src/,皆無htmlToDocx.exe時,
66
66
  * 代表安裝時npm封鎖scripts致postinstall未執行,故自動調用downloadFiles重新下載
67
67
  *
68
+ * 下載係先寫入暫存檔`htmlToDocx.exe.download`,完成後才改名為htmlToDocx.exe,故下載中途斷線或程序被終止時不會留下截斷之htmlToDocx.exe,下次呼叫會重新下載;
69
+ * 下載失敗(斷網、代理不可達、非2xx回應、中途斷線)時reject字串`failed to download url[網址] to file[落點]: 原因`
70
+ *
68
71
  * 供w-html2docx自身與其他依賴w-html2docx的套件調用,無須各自實作偵測與下載邏輯
69
72
  *
70
73
  * 因htmlToDocx.exe只能用於Windows作業系統,故調用前須自行檢核作業系統
@@ -113,12 +116,11 @@ async function autoDownloadFiles() {
113
116
  //併發呼叫共用同一個下載Promise, 避免重複下載
114
117
  if (pmDownload === null) {
115
118
  pmDownload = downloadFiles(fdBaseDL)
116
- .catch((err) => {
119
+ .finally(() => {
117
120
 
118
- //下載失敗歸零, 使下次呼叫可重試下載
121
+ //下載結束(成敗皆然)歸零, 使下次呼叫重新依檔案是否存在判定; 若只於失敗時歸零, 下載成功後檔案被移除(重裝套件、防毒隔離)或程序切換工作路徑時, 會沿用已resolve之Promise而不再下載
119
122
  pmDownload = null
120
123
 
121
- return Promise.reject(err)
122
124
  })
123
125
  }
124
126
  await pmDownload
@@ -132,7 +134,7 @@ async function autoDownloadFiles() {
132
134
 
133
135
  //check
134
136
  if (fdBase === '') {
135
- return Promise.reject('can not find htmlToDocx.exe')
137
+ return Promise.reject(`can not find ${fnExe} in [${fdBaseSelf}] or [${fdBaseNM}]`)
136
138
  }
137
139
 
138
140
  //fpExe
@@ -159,7 +161,7 @@ export default autoDownloadFiles
159
161
  <br class="clear">
160
162
 
161
163
  <footer>
162
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Sep 05 2026 22:30:36 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
164
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Sep 13 2026 21:52:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
163
165
  </footer>
164
166
 
165
167
  <script>prettyPrint();</script>
package/docs/global.html CHANGED
@@ -140,13 +140,15 @@
140
140
  <dl class="details">
141
141
 
142
142
  <dt class="tag-description">Description:</dt>
143
- <dd class="tag-description"><ul class="dummy"><li><p>Html檔轉Docx檔</p></li></ul></dd>
143
+ <dd class="tag-description"><ul class="dummy"><li><p>Html檔轉Docx檔</p>
144
+ <p>轉檔由套件內之htmlToDocx.exe調用本機Microsoft Word(win32com)完成,故須於Windows且已安裝Word之機器執行。htmlToDocx.exe若不存在(安裝時npm封鎖scripts致postinstall未執行)會於轉檔當下自動下載,下載失敗則reject並帶網址與落點。
145
+ 轉檔器內部失敗(Word未安裝、模板無法開啟、另存失敗等)一律reject並帶轉檔器回報之原因;resolve前另確認輸出檔已產生且非空。輸出資料夾不存在時自動建立</p></li></ul></dd>
144
146
 
145
147
 
146
148
 
147
149
  <dt class="tag-source">Source:</dt>
148
150
  <dd class="tag-source"><ul class="dummy"><li>
149
- <a href="WHtml2docx.mjs.html">WHtml2docx.mjs</a>, <a href="WHtml2docx.mjs.html#line61">line 61</a>
151
+ <a href="WHtml2docx.mjs.html">WHtml2docx.mjs</a>, <a href="WHtml2docx.mjs.html#line68">line 68</a>
150
152
  </li></ul></dd>
151
153
 
152
154
 
@@ -193,7 +195,30 @@
193
195
 
194
196
  <h5 class="h5-examples">Example</h5>
195
197
 
196
- <pre class="prettyprint"><code>import w from 'wsemi'
197
198
  let fpIn = `./test/ztmp.html`
198
199
  let fpOut = `./test/ztmp.docx`
199
200
  let opt = {
200
201
  imgRatioWidthMax: 0.5,
201
202
  }
202
203
  let r = await WHtml2docx(fpIn, fpOut, opt)
203
204
  console.log(r)
204
205
  // => ok
205
206
  w.fsDeleteFile(fpOut)
206
207
  .catch((err) => {
207
208
  console.log('catch', err)
208
209
  })</code></pre>
210
+ <pre class="prettyprint"><code>import w from 'wsemi'
211
+ import WHtml2docx from './src/WHtml2docx.mjs'
212
+ //import WHtml2docx from 'w-html2docx/src/WHtml2docx.mjs'
213
+ //import WHtml2docx from 'w-html2docx'
214
+
215
+ async function test() {
216
+
217
+ let fpIn = `./test/ztmp.html`
218
+ let fpOut = `./test/ztmp.docx`
219
+ let opt = {
220
+ imgRatioWidthMax: 0.5,
221
+ }
222
+
223
+ let r = await WHtml2docx(fpIn, fpOut, opt)
224
+ console.log(r)
225
+ // => ok
226
+
227
+ w.fsDeleteFile(fpOut)
228
+
229
+ }
230
+ test()
231
+ .catch((err) => {
232
+ console.log('catch', err)
233
+ })</code></pre>
209
234
 
210
235
 
211
236
 
@@ -390,12 +415,12 @@
390
415
 
391
416
  <td class="default">
392
417
 
393
- <code>'./src/tmp.docx'</code>
418
+ <code>''</code>
394
419
 
395
420
  </td>
396
421
 
397
422
 
398
- <td class="description last"><p>輸入Docx模板檔案位置字串,預設'./src/tmp.docx'</p></td>
423
+ <td class="description last"><p>輸入Docx模板檔案位置字串,有給時須存在否則reject;未給時依序取模組載入當下工作路徑之<code>./src/tmp.docx</code>或<code>./node_modules/w-html2docx/src/tmp.docx</code>(套件內建模板),預設''</p></td>
399
424
  </tr>
400
425
 
401
426
 
@@ -451,7 +476,7 @@
451
476
  <td class="type">
452
477
 
453
478
 
454
- <span class="param-type">String</span>
479
+ <span class="param-type">Number</span>
455
480
 
456
481
 
457
482
 
@@ -491,7 +516,7 @@
491
516
  <td class="type">
492
517
 
493
518
 
494
- <span class="param-type">String</span>
519
+ <span class="param-type">Number</span>
495
520
 
496
521
 
497
522
 
@@ -522,6 +547,46 @@
522
547
  </tr>
523
548
 
524
549
 
550
+
551
+ <tr>
552
+
553
+ <td class="name"><code>timeout</code></td>
554
+
555
+
556
+ <td class="type">
557
+
558
+
559
+ <span class="param-type">Number</span>
560
+
561
+
562
+
563
+
564
+ </td>
565
+
566
+
567
+ <td class="attributes">
568
+
569
+ &lt;optional><br>
570
+
571
+
572
+
573
+
574
+
575
+ </td>
576
+
577
+
578
+
579
+ <td class="default">
580
+
581
+ <code>null</code>
582
+
583
+ </td>
584
+
585
+
586
+ <td class="description last"><p>輸入轉檔逾時毫秒數,預設null表示不限制;逾時時強制關閉轉檔器並reject回傳逾時訊息,惟由轉檔器經COM啟動之Word不在其程序樹內,不會一併被關閉</p></td>
587
+ </tr>
588
+
589
+
525
590
  </tbody>
526
591
  </table>
527
592
 
@@ -551,7 +616,7 @@
551
616
 
552
617
 
553
618
  <div class="param-desc">
554
- <p>回傳Promise,resolve回傳成功訊息,reject回傳錯誤訊息</p>
619
+ <p>回傳Promise,resolve回傳'ok',reject回傳錯誤訊息字串</p>
555
620
  </div>
556
621
 
557
622
 
@@ -591,6 +656,8 @@
591
656
  <dd class="tag-description"><ul class="dummy"><li><p>自動定位htmlToDocx.exe,若無檔案則自動下載,回傳htmlToDocx.exe的絕對路徑</p>
592
657
  <p>依序偵測當前工作路徑的src/與node_modules/w-html2docx/src/,皆無htmlToDocx.exe時,
593
658
  代表安裝時npm封鎖scripts致postinstall未執行,故自動調用downloadFiles重新下載</p>
659
+ <p>下載係先寫入暫存檔<code>htmlToDocx.exe.download</code>,完成後才改名為htmlToDocx.exe,故下載中途斷線或程序被終止時不會留下截斷之htmlToDocx.exe,下次呼叫會重新下載;
660
+ 下載失敗(斷網、代理不可達、非2xx回應、中途斷線)時reject字串<code>failed to download url[網址] to file[落點]: 原因</code></p>
594
661
  <p>供w-html2docx自身與其他依賴w-html2docx的套件調用,無須各自實作偵測與下載邏輯</p>
595
662
  <p>因htmlToDocx.exe只能用於Windows作業系統,故調用前須自行檢核作業系統</p></li></ul></dd>
596
663
 
@@ -598,7 +665,7 @@
598
665
 
599
666
  <dt class="tag-source">Source:</dt>
600
667
  <dd class="tag-source"><ul class="dummy"><li>
601
- <a href="autoDownloadFiles.mjs.html">autoDownloadFiles.mjs</a>, <a href="autoDownloadFiles.mjs.html#line43">line 43</a>
668
+ <a href="autoDownloadFiles.mjs.html">autoDownloadFiles.mjs</a>, <a href="autoDownloadFiles.mjs.html#line46">line 46</a>
602
669
  </li></ul></dd>
603
670
 
604
671
 
@@ -723,7 +790,7 @@ test()
723
790
  <br class="clear">
724
791
 
725
792
  <footer>
726
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Sep 05 2026 22:30:36 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
793
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Sep 13 2026 21:52:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
727
794
  </footer>
728
795
 
729
796
  <script>prettyPrint();</script>
package/docs/index.html CHANGED
@@ -71,7 +71,7 @@
71
71
  <br class="clear">
72
72
 
73
73
  <footer>
74
- Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sat Sep 05 2026 22:30:36 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
74
+ Documentation generated by <a href="https://github.com/jsdoc3/jsdoc">JSDoc 4.0.5</a> on Sun Sep 13 2026 21:52:07 GMT+0800 (台北標準時間) using the <a href="https://github.com/clenemt/docdash">docdash</a> theme.
75
75
  </footer>
76
76
 
77
77
  <script>prettyPrint();</script>
package/package.json CHANGED
@@ -1,17 +1,17 @@
1
1
  {
2
2
  "name": "w-html2docx",
3
- "version": "1.0.27",
3
+ "version": "1.0.29",
4
4
  "main": "dist/w-html2docx.umd.js",
5
5
  "dependencies": {
6
- "wsemi": "^1.8.85"
6
+ "wsemi": "^1.8.93"
7
7
  },
8
8
  "devDependencies": {
9
9
  "fflate": "^0.8.3",
10
- "w-package-tools": "^1.1.15"
10
+ "w-package-tools": "^1.1.16"
11
11
  },
12
12
  "scripts": {
13
13
  "postinstall": "node scripts/install.mjs",
14
- "test": "mocha --parallel --timeout 60000",
14
+ "test": "mocha --parallel \"test/*.test.mjs\" --timeout 180000",
15
15
  "deploy": "gh-pages -d docs"
16
16
  },
17
17
  "repository": {