@clazic/kordoc 2.1.6 → 2.2.1
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 +67 -4
- package/dist/chunk-3NF22UFF.js +9617 -0
- package/dist/chunk-3NF22UFF.js.map +1 -0
- package/dist/{chunk-TFYOEQE2.js → chunk-7MXQWWUW.js} +2 -2
- package/dist/chunk-ZWE3DS7E.js +39 -0
- package/dist/cli.js +114 -11
- package/dist/cli.js.map +1 -1
- package/dist/index.cjs +2985 -179
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +36 -4
- package/dist/index.d.ts +36 -4
- package/dist/index.js +3009 -178
- package/dist/index.js.map +1 -1
- package/dist/mcp.js +100 -7
- package/dist/mcp.js.map +1 -1
- package/dist/{page-range-737B4EZW.js → page-range-ALIRXAL5.js} +2 -1
- package/dist/provider-XVKP5OGI.js +167 -0
- package/dist/provider-XVKP5OGI.js.map +1 -0
- package/dist/resolve-Z4DEPDUS.js +179 -0
- package/dist/resolve-Z4DEPDUS.js.map +1 -0
- package/dist/tesseract-provider-UNJOI25M.js +24 -0
- package/dist/tesseract-provider-UNJOI25M.js.map +1 -0
- package/dist/{utils-7JE5SKSL.js → utils-I4UIMOH7.js} +3 -2
- package/dist/utils-I4UIMOH7.js.map +1 -0
- package/dist/{watch-XALC6VOR.js → watch-XPLMUIZB.js} +4 -3
- package/dist/{watch-XALC6VOR.js.map → watch-XPLMUIZB.js.map} +1 -1
- package/package.json +5 -2
- package/dist/chunk-H7HMKSLX.js +0 -5494
- package/dist/chunk-H7HMKSLX.js.map +0 -1
- package/dist/provider-A4FHJSID.js +0 -38
- package/dist/provider-A4FHJSID.js.map +0 -1
- /package/dist/{chunk-TFYOEQE2.js.map → chunk-7MXQWWUW.js.map} +0 -0
- /package/dist/{page-range-737B4EZW.js.map → chunk-ZWE3DS7E.js.map} +0 -0
- /package/dist/{utils-7JE5SKSL.js.map → page-range-ALIRXAL5.js.map} +0 -0
package/dist/index.cjs
CHANGED
|
@@ -8,6 +8,9 @@ var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
|
8
8
|
var __esm = (fn, res) => function __init() {
|
|
9
9
|
return fn && (res = (0, fn[__getOwnPropNames(fn)[0]])(fn = 0)), res;
|
|
10
10
|
};
|
|
11
|
+
var __commonJS = (cb, mod) => function __require() {
|
|
12
|
+
return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
|
|
13
|
+
};
|
|
11
14
|
var __export = (target, all) => {
|
|
12
15
|
for (var name in all)
|
|
13
16
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -43,27 +46,2256 @@ function parsePageRange(spec, maxPages) {
|
|
|
43
46
|
const page = Math.round(n);
|
|
44
47
|
if (page >= 1 && page <= maxPages) result.add(page);
|
|
45
48
|
}
|
|
46
|
-
return result;
|
|
49
|
+
return result;
|
|
50
|
+
}
|
|
51
|
+
if (typeof spec !== "string" || spec.trim() === "") return result;
|
|
52
|
+
const parts = spec.split(",");
|
|
53
|
+
for (const part of parts) {
|
|
54
|
+
const trimmed = part.trim();
|
|
55
|
+
if (!trimmed) continue;
|
|
56
|
+
const rangeMatch = trimmed.match(/^(\d+)\s*-\s*(\d+)$/);
|
|
57
|
+
if (rangeMatch) {
|
|
58
|
+
const start = Math.max(1, parseInt(rangeMatch[1], 10));
|
|
59
|
+
const end = Math.min(maxPages, parseInt(rangeMatch[2], 10));
|
|
60
|
+
for (let i = start; i <= end; i++) result.add(i);
|
|
61
|
+
} else {
|
|
62
|
+
const page = parseInt(trimmed, 10);
|
|
63
|
+
if (!isNaN(page) && page >= 1 && page <= maxPages) result.add(page);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
var init_page_range = __esm({
|
|
69
|
+
"src/page-range.ts"() {
|
|
70
|
+
"use strict";
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
// node_modules/cfb/cfb.js
|
|
75
|
+
var require_cfb = __commonJS({
|
|
76
|
+
"node_modules/cfb/cfb.js"(exports2, module2) {
|
|
77
|
+
"use strict";
|
|
78
|
+
var Base64_map = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=";
|
|
79
|
+
function Base64_encode(input) {
|
|
80
|
+
var o = "";
|
|
81
|
+
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
|
82
|
+
for (var i = 0; i < input.length; ) {
|
|
83
|
+
c1 = input.charCodeAt(i++);
|
|
84
|
+
e1 = c1 >> 2;
|
|
85
|
+
c2 = input.charCodeAt(i++);
|
|
86
|
+
e2 = (c1 & 3) << 4 | c2 >> 4;
|
|
87
|
+
c3 = input.charCodeAt(i++);
|
|
88
|
+
e3 = (c2 & 15) << 2 | c3 >> 6;
|
|
89
|
+
e4 = c3 & 63;
|
|
90
|
+
if (isNaN(c2)) e3 = e4 = 64;
|
|
91
|
+
else if (isNaN(c3)) e4 = 64;
|
|
92
|
+
o += Base64_map.charAt(e1) + Base64_map.charAt(e2) + Base64_map.charAt(e3) + Base64_map.charAt(e4);
|
|
93
|
+
}
|
|
94
|
+
return o;
|
|
95
|
+
}
|
|
96
|
+
function Base64_decode(input) {
|
|
97
|
+
var o = "";
|
|
98
|
+
var c1 = 0, c2 = 0, c3 = 0, e1 = 0, e2 = 0, e3 = 0, e4 = 0;
|
|
99
|
+
input = input.replace(/[^\w\+\/\=]/g, "");
|
|
100
|
+
for (var i = 0; i < input.length; ) {
|
|
101
|
+
e1 = Base64_map.indexOf(input.charAt(i++));
|
|
102
|
+
e2 = Base64_map.indexOf(input.charAt(i++));
|
|
103
|
+
c1 = e1 << 2 | e2 >> 4;
|
|
104
|
+
o += String.fromCharCode(c1);
|
|
105
|
+
e3 = Base64_map.indexOf(input.charAt(i++));
|
|
106
|
+
c2 = (e2 & 15) << 4 | e3 >> 2;
|
|
107
|
+
if (e3 !== 64) o += String.fromCharCode(c2);
|
|
108
|
+
e4 = Base64_map.indexOf(input.charAt(i++));
|
|
109
|
+
c3 = (e3 & 3) << 6 | e4;
|
|
110
|
+
if (e4 !== 64) o += String.fromCharCode(c3);
|
|
111
|
+
}
|
|
112
|
+
return o;
|
|
113
|
+
}
|
|
114
|
+
var has_buf = (function() {
|
|
115
|
+
return typeof Buffer !== "undefined" && typeof process !== "undefined" && typeof process.versions !== "undefined" && !!process.versions.node;
|
|
116
|
+
})();
|
|
117
|
+
var Buffer_from = (function() {
|
|
118
|
+
if (typeof Buffer !== "undefined") {
|
|
119
|
+
var nbfs = !Buffer.from;
|
|
120
|
+
if (!nbfs) try {
|
|
121
|
+
Buffer.from("foo", "utf8");
|
|
122
|
+
} catch (e) {
|
|
123
|
+
nbfs = true;
|
|
124
|
+
}
|
|
125
|
+
return nbfs ? function(buf, enc) {
|
|
126
|
+
return enc ? new Buffer(buf, enc) : new Buffer(buf);
|
|
127
|
+
} : Buffer.from.bind(Buffer);
|
|
128
|
+
}
|
|
129
|
+
return function() {
|
|
130
|
+
};
|
|
131
|
+
})();
|
|
132
|
+
function new_raw_buf(len) {
|
|
133
|
+
if (has_buf) {
|
|
134
|
+
if (Buffer.alloc) return Buffer.alloc(len);
|
|
135
|
+
var b = new Buffer(len);
|
|
136
|
+
b.fill(0);
|
|
137
|
+
return b;
|
|
138
|
+
}
|
|
139
|
+
return typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len);
|
|
140
|
+
}
|
|
141
|
+
function new_unsafe_buf(len) {
|
|
142
|
+
if (has_buf) return Buffer.allocUnsafe ? Buffer.allocUnsafe(len) : new Buffer(len);
|
|
143
|
+
return typeof Uint8Array != "undefined" ? new Uint8Array(len) : new Array(len);
|
|
144
|
+
}
|
|
145
|
+
var s2a = function s2a2(s) {
|
|
146
|
+
if (has_buf) return Buffer_from(s, "binary");
|
|
147
|
+
return s.split("").map(function(x) {
|
|
148
|
+
return x.charCodeAt(0) & 255;
|
|
149
|
+
});
|
|
150
|
+
};
|
|
151
|
+
var chr0 = /\u0000/g;
|
|
152
|
+
var chr1 = /[\u0001-\u0006]/g;
|
|
153
|
+
var __toBuffer = function(bufs) {
|
|
154
|
+
var x = [];
|
|
155
|
+
for (var i = 0; i < bufs[0].length; ++i) {
|
|
156
|
+
x.push.apply(x, bufs[0][i]);
|
|
157
|
+
}
|
|
158
|
+
return x;
|
|
159
|
+
};
|
|
160
|
+
var ___toBuffer = __toBuffer;
|
|
161
|
+
var __utf16le = function(b, s, e) {
|
|
162
|
+
var ss = [];
|
|
163
|
+
for (var i = s; i < e; i += 2) ss.push(String.fromCharCode(__readUInt16LE(b, i)));
|
|
164
|
+
return ss.join("").replace(chr0, "");
|
|
165
|
+
};
|
|
166
|
+
var ___utf16le = __utf16le;
|
|
167
|
+
var __hexlify = function(b, s, l) {
|
|
168
|
+
var ss = [];
|
|
169
|
+
for (var i = s; i < s + l; ++i) ss.push(("0" + b[i].toString(16)).slice(-2));
|
|
170
|
+
return ss.join("");
|
|
171
|
+
};
|
|
172
|
+
var ___hexlify = __hexlify;
|
|
173
|
+
var __bconcat = function(bufs) {
|
|
174
|
+
if (Array.isArray(bufs[0])) return [].concat.apply([], bufs);
|
|
175
|
+
var maxlen = 0, i = 0;
|
|
176
|
+
for (i = 0; i < bufs.length; ++i) maxlen += bufs[i].length;
|
|
177
|
+
var o = new Uint8Array(maxlen);
|
|
178
|
+
for (i = 0, maxlen = 0; i < bufs.length; maxlen += bufs[i].length, ++i) o.set(bufs[i], maxlen);
|
|
179
|
+
return o;
|
|
180
|
+
};
|
|
181
|
+
var bconcat = __bconcat;
|
|
182
|
+
if (has_buf) {
|
|
183
|
+
__utf16le = function(b, s, e) {
|
|
184
|
+
if (!Buffer.isBuffer(b)) return ___utf16le(b, s, e);
|
|
185
|
+
return b.toString("utf16le", s, e).replace(chr0, "");
|
|
186
|
+
};
|
|
187
|
+
__hexlify = function(b, s, l) {
|
|
188
|
+
return Buffer.isBuffer(b) ? b.toString("hex", s, s + l) : ___hexlify(b, s, l);
|
|
189
|
+
};
|
|
190
|
+
__toBuffer = function(bufs) {
|
|
191
|
+
return bufs[0].length > 0 && Buffer.isBuffer(bufs[0][0]) ? Buffer.concat(bufs[0]) : ___toBuffer(bufs);
|
|
192
|
+
};
|
|
193
|
+
s2a = function(s) {
|
|
194
|
+
return Buffer_from(s, "binary");
|
|
195
|
+
};
|
|
196
|
+
bconcat = function(bufs) {
|
|
197
|
+
return Buffer.isBuffer(bufs[0]) ? Buffer.concat(bufs) : __bconcat(bufs);
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
var __readUInt8 = function(b, idx) {
|
|
201
|
+
return b[idx];
|
|
202
|
+
};
|
|
203
|
+
var __readUInt16LE = function(b, idx) {
|
|
204
|
+
return b[idx + 1] * (1 << 8) + b[idx];
|
|
205
|
+
};
|
|
206
|
+
var __readInt16LE = function(b, idx) {
|
|
207
|
+
var u = b[idx + 1] * (1 << 8) + b[idx];
|
|
208
|
+
return u < 32768 ? u : (65535 - u + 1) * -1;
|
|
209
|
+
};
|
|
210
|
+
var __readUInt32LE = function(b, idx) {
|
|
211
|
+
return b[idx + 3] * (1 << 24) + (b[idx + 2] << 16) + (b[idx + 1] << 8) + b[idx];
|
|
212
|
+
};
|
|
213
|
+
var __readInt32LE = function(b, idx) {
|
|
214
|
+
return (b[idx + 3] << 24) + (b[idx + 2] << 16) + (b[idx + 1] << 8) + b[idx];
|
|
215
|
+
};
|
|
216
|
+
function ReadShift(size, t) {
|
|
217
|
+
var oI, oS, type = 0;
|
|
218
|
+
switch (size) {
|
|
219
|
+
case 1:
|
|
220
|
+
oI = __readUInt8(this, this.l);
|
|
221
|
+
break;
|
|
222
|
+
case 2:
|
|
223
|
+
oI = (t !== "i" ? __readUInt16LE : __readInt16LE)(this, this.l);
|
|
224
|
+
break;
|
|
225
|
+
case 4:
|
|
226
|
+
oI = __readInt32LE(this, this.l);
|
|
227
|
+
break;
|
|
228
|
+
case 16:
|
|
229
|
+
type = 2;
|
|
230
|
+
oS = __hexlify(this, this.l, size);
|
|
231
|
+
}
|
|
232
|
+
this.l += size;
|
|
233
|
+
if (type === 0) return oI;
|
|
234
|
+
return oS;
|
|
235
|
+
}
|
|
236
|
+
var __writeUInt32LE = function(b, val, idx) {
|
|
237
|
+
b[idx] = val & 255;
|
|
238
|
+
b[idx + 1] = val >>> 8 & 255;
|
|
239
|
+
b[idx + 2] = val >>> 16 & 255;
|
|
240
|
+
b[idx + 3] = val >>> 24 & 255;
|
|
241
|
+
};
|
|
242
|
+
var __writeInt32LE = function(b, val, idx) {
|
|
243
|
+
b[idx] = val & 255;
|
|
244
|
+
b[idx + 1] = val >> 8 & 255;
|
|
245
|
+
b[idx + 2] = val >> 16 & 255;
|
|
246
|
+
b[idx + 3] = val >> 24 & 255;
|
|
247
|
+
};
|
|
248
|
+
function WriteShift(t, val, f) {
|
|
249
|
+
var size = 0, i = 0;
|
|
250
|
+
switch (f) {
|
|
251
|
+
case "hex":
|
|
252
|
+
for (; i < t; ++i) {
|
|
253
|
+
this[this.l++] = parseInt(val.slice(2 * i, 2 * i + 2), 16) || 0;
|
|
254
|
+
}
|
|
255
|
+
return this;
|
|
256
|
+
case "utf16le":
|
|
257
|
+
var end = this.l + t;
|
|
258
|
+
for (i = 0; i < Math.min(val.length, t); ++i) {
|
|
259
|
+
var cc = val.charCodeAt(i);
|
|
260
|
+
this[this.l++] = cc & 255;
|
|
261
|
+
this[this.l++] = cc >> 8;
|
|
262
|
+
}
|
|
263
|
+
while (this.l < end) this[this.l++] = 0;
|
|
264
|
+
return this;
|
|
265
|
+
}
|
|
266
|
+
switch (t) {
|
|
267
|
+
case 1:
|
|
268
|
+
size = 1;
|
|
269
|
+
this[this.l] = val & 255;
|
|
270
|
+
break;
|
|
271
|
+
case 2:
|
|
272
|
+
size = 2;
|
|
273
|
+
this[this.l] = val & 255;
|
|
274
|
+
val >>>= 8;
|
|
275
|
+
this[this.l + 1] = val & 255;
|
|
276
|
+
break;
|
|
277
|
+
case 4:
|
|
278
|
+
size = 4;
|
|
279
|
+
__writeUInt32LE(this, val, this.l);
|
|
280
|
+
break;
|
|
281
|
+
case -4:
|
|
282
|
+
size = 4;
|
|
283
|
+
__writeInt32LE(this, val, this.l);
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
this.l += size;
|
|
287
|
+
return this;
|
|
288
|
+
}
|
|
289
|
+
function CheckField(hexstr, fld) {
|
|
290
|
+
var m = __hexlify(this, this.l, hexstr.length >> 1);
|
|
291
|
+
if (m !== hexstr) throw new Error(fld + "Expected " + hexstr + " saw " + m);
|
|
292
|
+
this.l += hexstr.length >> 1;
|
|
293
|
+
}
|
|
294
|
+
function prep_blob(blob, pos) {
|
|
295
|
+
blob.l = pos;
|
|
296
|
+
blob.read_shift = ReadShift;
|
|
297
|
+
blob.chk = CheckField;
|
|
298
|
+
blob.write_shift = WriteShift;
|
|
299
|
+
}
|
|
300
|
+
function new_buf(sz) {
|
|
301
|
+
var o = new_raw_buf(sz);
|
|
302
|
+
prep_blob(o, 0);
|
|
303
|
+
return o;
|
|
304
|
+
}
|
|
305
|
+
var CRC32 = (function() {
|
|
306
|
+
var CRC322 = {};
|
|
307
|
+
CRC322.version = "1.2.1";
|
|
308
|
+
function signed_crc_table() {
|
|
309
|
+
var c = 0, table = new Array(256);
|
|
310
|
+
for (var n = 0; n != 256; ++n) {
|
|
311
|
+
c = n;
|
|
312
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
313
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
314
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
315
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
316
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
317
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
318
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
319
|
+
c = c & 1 ? -306674912 ^ c >>> 1 : c >>> 1;
|
|
320
|
+
table[n] = c;
|
|
321
|
+
}
|
|
322
|
+
return typeof Int32Array !== "undefined" ? new Int32Array(table) : table;
|
|
323
|
+
}
|
|
324
|
+
var T0 = signed_crc_table();
|
|
325
|
+
function slice_by_16_tables(T) {
|
|
326
|
+
var c = 0, v = 0, n = 0, table = typeof Int32Array !== "undefined" ? new Int32Array(4096) : new Array(4096);
|
|
327
|
+
for (n = 0; n != 256; ++n) table[n] = T[n];
|
|
328
|
+
for (n = 0; n != 256; ++n) {
|
|
329
|
+
v = T[n];
|
|
330
|
+
for (c = 256 + n; c < 4096; c += 256) v = table[c] = v >>> 8 ^ T[v & 255];
|
|
331
|
+
}
|
|
332
|
+
var out = [];
|
|
333
|
+
for (n = 1; n != 16; ++n) out[n - 1] = typeof Int32Array !== "undefined" ? table.subarray(n * 256, n * 256 + 256) : table.slice(n * 256, n * 256 + 256);
|
|
334
|
+
return out;
|
|
335
|
+
}
|
|
336
|
+
var TT = slice_by_16_tables(T0);
|
|
337
|
+
var T1 = TT[0], T2 = TT[1], T3 = TT[2], T4 = TT[3], T5 = TT[4];
|
|
338
|
+
var T6 = TT[5], T7 = TT[6], T8 = TT[7], T9 = TT[8], Ta = TT[9];
|
|
339
|
+
var Tb = TT[10], Tc = TT[11], Td = TT[12], Te = TT[13], Tf = TT[14];
|
|
340
|
+
function crc32_bstr(bstr, seed) {
|
|
341
|
+
var C = seed ^ -1;
|
|
342
|
+
for (var i = 0, L = bstr.length; i < L; ) C = C >>> 8 ^ T0[(C ^ bstr.charCodeAt(i++)) & 255];
|
|
343
|
+
return ~C;
|
|
344
|
+
}
|
|
345
|
+
function crc32_buf(B, seed) {
|
|
346
|
+
var C = seed ^ -1, L = B.length - 15, i = 0;
|
|
347
|
+
for (; i < L; ) C = Tf[B[i++] ^ C & 255] ^ Te[B[i++] ^ C >> 8 & 255] ^ Td[B[i++] ^ C >> 16 & 255] ^ Tc[B[i++] ^ C >>> 24] ^ Tb[B[i++]] ^ Ta[B[i++]] ^ T9[B[i++]] ^ T8[B[i++]] ^ T7[B[i++]] ^ T6[B[i++]] ^ T5[B[i++]] ^ T4[B[i++]] ^ T3[B[i++]] ^ T2[B[i++]] ^ T1[B[i++]] ^ T0[B[i++]];
|
|
348
|
+
L += 15;
|
|
349
|
+
while (i < L) C = C >>> 8 ^ T0[(C ^ B[i++]) & 255];
|
|
350
|
+
return ~C;
|
|
351
|
+
}
|
|
352
|
+
function crc32_str(str, seed) {
|
|
353
|
+
var C = seed ^ -1;
|
|
354
|
+
for (var i = 0, L = str.length, c = 0, d = 0; i < L; ) {
|
|
355
|
+
c = str.charCodeAt(i++);
|
|
356
|
+
if (c < 128) {
|
|
357
|
+
C = C >>> 8 ^ T0[(C ^ c) & 255];
|
|
358
|
+
} else if (c < 2048) {
|
|
359
|
+
C = C >>> 8 ^ T0[(C ^ (192 | c >> 6 & 31)) & 255];
|
|
360
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
|
|
361
|
+
} else if (c >= 55296 && c < 57344) {
|
|
362
|
+
c = (c & 1023) + 64;
|
|
363
|
+
d = str.charCodeAt(i++) & 1023;
|
|
364
|
+
C = C >>> 8 ^ T0[(C ^ (240 | c >> 8 & 7)) & 255];
|
|
365
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c >> 2 & 63)) & 255];
|
|
366
|
+
C = C >>> 8 ^ T0[(C ^ (128 | d >> 6 & 15 | (c & 3) << 4)) & 255];
|
|
367
|
+
C = C >>> 8 ^ T0[(C ^ (128 | d & 63)) & 255];
|
|
368
|
+
} else {
|
|
369
|
+
C = C >>> 8 ^ T0[(C ^ (224 | c >> 12 & 15)) & 255];
|
|
370
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c >> 6 & 63)) & 255];
|
|
371
|
+
C = C >>> 8 ^ T0[(C ^ (128 | c & 63)) & 255];
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return ~C;
|
|
375
|
+
}
|
|
376
|
+
CRC322.table = T0;
|
|
377
|
+
CRC322.bstr = crc32_bstr;
|
|
378
|
+
CRC322.buf = crc32_buf;
|
|
379
|
+
CRC322.str = crc32_str;
|
|
380
|
+
return CRC322;
|
|
381
|
+
})();
|
|
382
|
+
var CFB2 = (function _CFB() {
|
|
383
|
+
var exports3 = {};
|
|
384
|
+
exports3.version = "1.2.2";
|
|
385
|
+
function namecmp(l, r) {
|
|
386
|
+
var L = l.split("/"), R = r.split("/");
|
|
387
|
+
for (var i2 = 0, c = 0, Z = Math.min(L.length, R.length); i2 < Z; ++i2) {
|
|
388
|
+
if (c = L[i2].length - R[i2].length) return c;
|
|
389
|
+
if (L[i2] != R[i2]) return L[i2] < R[i2] ? -1 : 1;
|
|
390
|
+
}
|
|
391
|
+
return L.length - R.length;
|
|
392
|
+
}
|
|
393
|
+
function dirname(p) {
|
|
394
|
+
if (p.charAt(p.length - 1) == "/") return p.slice(0, -1).indexOf("/") === -1 ? p : dirname(p.slice(0, -1));
|
|
395
|
+
var c = p.lastIndexOf("/");
|
|
396
|
+
return c === -1 ? p : p.slice(0, c + 1);
|
|
397
|
+
}
|
|
398
|
+
function filename(p) {
|
|
399
|
+
if (p.charAt(p.length - 1) == "/") return filename(p.slice(0, -1));
|
|
400
|
+
var c = p.lastIndexOf("/");
|
|
401
|
+
return c === -1 ? p : p.slice(c + 1);
|
|
402
|
+
}
|
|
403
|
+
function write_dos_date(buf, date) {
|
|
404
|
+
if (typeof date === "string") date = new Date(date);
|
|
405
|
+
var hms = date.getHours();
|
|
406
|
+
hms = hms << 6 | date.getMinutes();
|
|
407
|
+
hms = hms << 5 | date.getSeconds() >>> 1;
|
|
408
|
+
buf.write_shift(2, hms);
|
|
409
|
+
var ymd = date.getFullYear() - 1980;
|
|
410
|
+
ymd = ymd << 4 | date.getMonth() + 1;
|
|
411
|
+
ymd = ymd << 5 | date.getDate();
|
|
412
|
+
buf.write_shift(2, ymd);
|
|
413
|
+
}
|
|
414
|
+
function parse_dos_date(buf) {
|
|
415
|
+
var hms = buf.read_shift(2) & 65535;
|
|
416
|
+
var ymd = buf.read_shift(2) & 65535;
|
|
417
|
+
var val = /* @__PURE__ */ new Date();
|
|
418
|
+
var d = ymd & 31;
|
|
419
|
+
ymd >>>= 5;
|
|
420
|
+
var m = ymd & 15;
|
|
421
|
+
ymd >>>= 4;
|
|
422
|
+
val.setMilliseconds(0);
|
|
423
|
+
val.setFullYear(ymd + 1980);
|
|
424
|
+
val.setMonth(m - 1);
|
|
425
|
+
val.setDate(d);
|
|
426
|
+
var S = hms & 31;
|
|
427
|
+
hms >>>= 5;
|
|
428
|
+
var M = hms & 63;
|
|
429
|
+
hms >>>= 6;
|
|
430
|
+
val.setHours(hms);
|
|
431
|
+
val.setMinutes(M);
|
|
432
|
+
val.setSeconds(S << 1);
|
|
433
|
+
return val;
|
|
434
|
+
}
|
|
435
|
+
function parse_extra_field(blob) {
|
|
436
|
+
prep_blob(blob, 0);
|
|
437
|
+
var o = {};
|
|
438
|
+
var flags = 0;
|
|
439
|
+
while (blob.l <= blob.length - 4) {
|
|
440
|
+
var type = blob.read_shift(2);
|
|
441
|
+
var sz = blob.read_shift(2), tgt = blob.l + sz;
|
|
442
|
+
var p = {};
|
|
443
|
+
switch (type) {
|
|
444
|
+
/* UNIX-style Timestamps */
|
|
445
|
+
case 21589:
|
|
446
|
+
{
|
|
447
|
+
flags = blob.read_shift(1);
|
|
448
|
+
if (flags & 1) p.mtime = blob.read_shift(4);
|
|
449
|
+
if (sz > 5) {
|
|
450
|
+
if (flags & 2) p.atime = blob.read_shift(4);
|
|
451
|
+
if (flags & 4) p.ctime = blob.read_shift(4);
|
|
452
|
+
}
|
|
453
|
+
if (p.mtime) p.mt = new Date(p.mtime * 1e3);
|
|
454
|
+
}
|
|
455
|
+
break;
|
|
456
|
+
}
|
|
457
|
+
blob.l = tgt;
|
|
458
|
+
o[type] = p;
|
|
459
|
+
}
|
|
460
|
+
return o;
|
|
461
|
+
}
|
|
462
|
+
var fs;
|
|
463
|
+
function get_fs() {
|
|
464
|
+
return fs || (fs = require("fs"));
|
|
465
|
+
}
|
|
466
|
+
function parse3(file, options) {
|
|
467
|
+
if (file[0] == 80 && file[1] == 75) return parse_zip(file, options);
|
|
468
|
+
if ((file[0] | 32) == 109 && (file[1] | 32) == 105) return parse_mad(file, options);
|
|
469
|
+
if (file.length < 512) throw new Error("CFB file size " + file.length + " < 512");
|
|
470
|
+
var mver = 3;
|
|
471
|
+
var ssz = 512;
|
|
472
|
+
var nmfs = 0;
|
|
473
|
+
var difat_sec_cnt = 0;
|
|
474
|
+
var dir_start = 0;
|
|
475
|
+
var minifat_start = 0;
|
|
476
|
+
var difat_start = 0;
|
|
477
|
+
var fat_addrs = [];
|
|
478
|
+
var blob = file.slice(0, 512);
|
|
479
|
+
prep_blob(blob, 0);
|
|
480
|
+
var mv = check_get_mver(blob);
|
|
481
|
+
mver = mv[0];
|
|
482
|
+
switch (mver) {
|
|
483
|
+
case 3:
|
|
484
|
+
ssz = 512;
|
|
485
|
+
break;
|
|
486
|
+
case 4:
|
|
487
|
+
ssz = 4096;
|
|
488
|
+
break;
|
|
489
|
+
case 0:
|
|
490
|
+
if (mv[1] == 0) return parse_zip(file, options);
|
|
491
|
+
/* falls through */
|
|
492
|
+
default:
|
|
493
|
+
throw new Error("Major Version: Expected 3 or 4 saw " + mver);
|
|
494
|
+
}
|
|
495
|
+
if (ssz !== 512) {
|
|
496
|
+
blob = file.slice(0, ssz);
|
|
497
|
+
prep_blob(
|
|
498
|
+
blob,
|
|
499
|
+
28
|
|
500
|
+
/* blob.l */
|
|
501
|
+
);
|
|
502
|
+
}
|
|
503
|
+
var header = file.slice(0, ssz);
|
|
504
|
+
check_shifts(blob, mver);
|
|
505
|
+
var dir_cnt = blob.read_shift(4, "i");
|
|
506
|
+
if (mver === 3 && dir_cnt !== 0) throw new Error("# Directory Sectors: Expected 0 saw " + dir_cnt);
|
|
507
|
+
blob.l += 4;
|
|
508
|
+
dir_start = blob.read_shift(4, "i");
|
|
509
|
+
blob.l += 4;
|
|
510
|
+
blob.chk("00100000", "Mini Stream Cutoff Size: ");
|
|
511
|
+
minifat_start = blob.read_shift(4, "i");
|
|
512
|
+
nmfs = blob.read_shift(4, "i");
|
|
513
|
+
difat_start = blob.read_shift(4, "i");
|
|
514
|
+
difat_sec_cnt = blob.read_shift(4, "i");
|
|
515
|
+
for (var q2 = -1, j = 0; j < 109; ++j) {
|
|
516
|
+
q2 = blob.read_shift(4, "i");
|
|
517
|
+
if (q2 < 0) break;
|
|
518
|
+
fat_addrs[j] = q2;
|
|
519
|
+
}
|
|
520
|
+
var sectors = sectorify(file, ssz);
|
|
521
|
+
sleuth_fat(difat_start, difat_sec_cnt, sectors, ssz, fat_addrs);
|
|
522
|
+
var sector_list = make_sector_list(sectors, dir_start, fat_addrs, ssz);
|
|
523
|
+
sector_list[dir_start].name = "!Directory";
|
|
524
|
+
if (nmfs > 0 && minifat_start !== ENDOFCHAIN) sector_list[minifat_start].name = "!MiniFAT";
|
|
525
|
+
sector_list[fat_addrs[0]].name = "!FAT";
|
|
526
|
+
sector_list.fat_addrs = fat_addrs;
|
|
527
|
+
sector_list.ssz = ssz;
|
|
528
|
+
var files = {}, Paths = [], FileIndex = [], FullPaths = [];
|
|
529
|
+
read_directory(dir_start, sector_list, sectors, Paths, nmfs, files, FileIndex, minifat_start);
|
|
530
|
+
build_full_paths(FileIndex, FullPaths, Paths);
|
|
531
|
+
Paths.shift();
|
|
532
|
+
var o = {
|
|
533
|
+
FileIndex,
|
|
534
|
+
FullPaths
|
|
535
|
+
};
|
|
536
|
+
if (options && options.raw) o.raw = { header, sectors };
|
|
537
|
+
return o;
|
|
538
|
+
}
|
|
539
|
+
function check_get_mver(blob) {
|
|
540
|
+
if (blob[blob.l] == 80 && blob[blob.l + 1] == 75) return [0, 0];
|
|
541
|
+
blob.chk(HEADER_SIGNATURE, "Header Signature: ");
|
|
542
|
+
blob.l += 16;
|
|
543
|
+
var mver = blob.read_shift(2, "u");
|
|
544
|
+
return [blob.read_shift(2, "u"), mver];
|
|
545
|
+
}
|
|
546
|
+
function check_shifts(blob, mver) {
|
|
547
|
+
var shift = 9;
|
|
548
|
+
blob.l += 2;
|
|
549
|
+
switch (shift = blob.read_shift(2)) {
|
|
550
|
+
case 9:
|
|
551
|
+
if (mver != 3) throw new Error("Sector Shift: Expected 9 saw " + shift);
|
|
552
|
+
break;
|
|
553
|
+
case 12:
|
|
554
|
+
if (mver != 4) throw new Error("Sector Shift: Expected 12 saw " + shift);
|
|
555
|
+
break;
|
|
556
|
+
default:
|
|
557
|
+
throw new Error("Sector Shift: Expected 9 or 12 saw " + shift);
|
|
558
|
+
}
|
|
559
|
+
blob.chk("0600", "Mini Sector Shift: ");
|
|
560
|
+
blob.chk("000000000000", "Reserved: ");
|
|
561
|
+
}
|
|
562
|
+
function sectorify(file, ssz) {
|
|
563
|
+
var nsectors = Math.ceil(file.length / ssz) - 1;
|
|
564
|
+
var sectors = [];
|
|
565
|
+
for (var i2 = 1; i2 < nsectors; ++i2) sectors[i2 - 1] = file.slice(i2 * ssz, (i2 + 1) * ssz);
|
|
566
|
+
sectors[nsectors - 1] = file.slice(nsectors * ssz);
|
|
567
|
+
return sectors;
|
|
568
|
+
}
|
|
569
|
+
function build_full_paths(FI, FP, Paths) {
|
|
570
|
+
var i2 = 0, L = 0, R = 0, C = 0, j = 0, pl = Paths.length;
|
|
571
|
+
var dad = [], q2 = [];
|
|
572
|
+
for (; i2 < pl; ++i2) {
|
|
573
|
+
dad[i2] = q2[i2] = i2;
|
|
574
|
+
FP[i2] = Paths[i2];
|
|
575
|
+
}
|
|
576
|
+
for (; j < q2.length; ++j) {
|
|
577
|
+
i2 = q2[j];
|
|
578
|
+
L = FI[i2].L;
|
|
579
|
+
R = FI[i2].R;
|
|
580
|
+
C = FI[i2].C;
|
|
581
|
+
if (dad[i2] === i2) {
|
|
582
|
+
if (L !== -1 && dad[L] !== L) dad[i2] = dad[L];
|
|
583
|
+
if (R !== -1 && dad[R] !== R) dad[i2] = dad[R];
|
|
584
|
+
}
|
|
585
|
+
if (C !== -1) dad[C] = i2;
|
|
586
|
+
if (L !== -1 && i2 != dad[i2]) {
|
|
587
|
+
dad[L] = dad[i2];
|
|
588
|
+
if (q2.lastIndexOf(L) < j) q2.push(L);
|
|
589
|
+
}
|
|
590
|
+
if (R !== -1 && i2 != dad[i2]) {
|
|
591
|
+
dad[R] = dad[i2];
|
|
592
|
+
if (q2.lastIndexOf(R) < j) q2.push(R);
|
|
593
|
+
}
|
|
594
|
+
}
|
|
595
|
+
for (i2 = 1; i2 < pl; ++i2) if (dad[i2] === i2) {
|
|
596
|
+
if (R !== -1 && dad[R] !== R) dad[i2] = dad[R];
|
|
597
|
+
else if (L !== -1 && dad[L] !== L) dad[i2] = dad[L];
|
|
598
|
+
}
|
|
599
|
+
for (i2 = 1; i2 < pl; ++i2) {
|
|
600
|
+
if (FI[i2].type === 0) continue;
|
|
601
|
+
j = i2;
|
|
602
|
+
if (j != dad[j]) do {
|
|
603
|
+
j = dad[j];
|
|
604
|
+
FP[i2] = FP[j] + "/" + FP[i2];
|
|
605
|
+
} while (j !== 0 && -1 !== dad[j] && j != dad[j]);
|
|
606
|
+
dad[i2] = -1;
|
|
607
|
+
}
|
|
608
|
+
FP[0] += "/";
|
|
609
|
+
for (i2 = 1; i2 < pl; ++i2) {
|
|
610
|
+
if (FI[i2].type !== 2) FP[i2] += "/";
|
|
611
|
+
}
|
|
612
|
+
}
|
|
613
|
+
function get_mfat_entry(entry, payload, mini) {
|
|
614
|
+
var start = entry.start, size = entry.size;
|
|
615
|
+
var o = [];
|
|
616
|
+
var idx = start;
|
|
617
|
+
while (mini && size > 0 && idx >= 0) {
|
|
618
|
+
o.push(payload.slice(idx * MSSZ, idx * MSSZ + MSSZ));
|
|
619
|
+
size -= MSSZ;
|
|
620
|
+
idx = __readInt32LE(mini, idx * 4);
|
|
621
|
+
}
|
|
622
|
+
if (o.length === 0) return new_buf(0);
|
|
623
|
+
return bconcat(o).slice(0, entry.size);
|
|
624
|
+
}
|
|
625
|
+
function sleuth_fat(idx, cnt, sectors, ssz, fat_addrs) {
|
|
626
|
+
var q2 = ENDOFCHAIN;
|
|
627
|
+
if (idx === ENDOFCHAIN) {
|
|
628
|
+
if (cnt !== 0) throw new Error("DIFAT chain shorter than expected");
|
|
629
|
+
} else if (idx !== -1) {
|
|
630
|
+
var sector = sectors[idx], m = (ssz >>> 2) - 1;
|
|
631
|
+
if (!sector) return;
|
|
632
|
+
for (var i2 = 0; i2 < m; ++i2) {
|
|
633
|
+
if ((q2 = __readInt32LE(sector, i2 * 4)) === ENDOFCHAIN) break;
|
|
634
|
+
fat_addrs.push(q2);
|
|
635
|
+
}
|
|
636
|
+
if (cnt >= 1) sleuth_fat(__readInt32LE(sector, ssz - 4), cnt - 1, sectors, ssz, fat_addrs);
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
function get_sector_list(sectors, start, fat_addrs, ssz, chkd) {
|
|
640
|
+
var buf = [], buf_chain = [];
|
|
641
|
+
if (!chkd) chkd = [];
|
|
642
|
+
var modulus = ssz - 1, j = 0, jj = 0;
|
|
643
|
+
for (j = start; j >= 0; ) {
|
|
644
|
+
chkd[j] = true;
|
|
645
|
+
buf[buf.length] = j;
|
|
646
|
+
buf_chain.push(sectors[j]);
|
|
647
|
+
var addr = fat_addrs[Math.floor(j * 4 / ssz)];
|
|
648
|
+
jj = j * 4 & modulus;
|
|
649
|
+
if (ssz < 4 + jj) throw new Error("FAT boundary crossed: " + j + " 4 " + ssz);
|
|
650
|
+
if (!sectors[addr]) break;
|
|
651
|
+
j = __readInt32LE(sectors[addr], jj);
|
|
652
|
+
}
|
|
653
|
+
return { nodes: buf, data: __toBuffer([buf_chain]) };
|
|
654
|
+
}
|
|
655
|
+
function make_sector_list(sectors, dir_start, fat_addrs, ssz) {
|
|
656
|
+
var sl = sectors.length, sector_list = [];
|
|
657
|
+
var chkd = [], buf = [], buf_chain = [];
|
|
658
|
+
var modulus = ssz - 1, i2 = 0, j = 0, k = 0, jj = 0;
|
|
659
|
+
for (i2 = 0; i2 < sl; ++i2) {
|
|
660
|
+
buf = [];
|
|
661
|
+
k = i2 + dir_start;
|
|
662
|
+
if (k >= sl) k -= sl;
|
|
663
|
+
if (chkd[k]) continue;
|
|
664
|
+
buf_chain = [];
|
|
665
|
+
var seen = [];
|
|
666
|
+
for (j = k; j >= 0; ) {
|
|
667
|
+
seen[j] = true;
|
|
668
|
+
chkd[j] = true;
|
|
669
|
+
buf[buf.length] = j;
|
|
670
|
+
buf_chain.push(sectors[j]);
|
|
671
|
+
var addr = fat_addrs[Math.floor(j * 4 / ssz)];
|
|
672
|
+
jj = j * 4 & modulus;
|
|
673
|
+
if (ssz < 4 + jj) throw new Error("FAT boundary crossed: " + j + " 4 " + ssz);
|
|
674
|
+
if (!sectors[addr]) break;
|
|
675
|
+
j = __readInt32LE(sectors[addr], jj);
|
|
676
|
+
if (seen[j]) break;
|
|
677
|
+
}
|
|
678
|
+
sector_list[k] = { nodes: buf, data: __toBuffer([buf_chain]) };
|
|
679
|
+
}
|
|
680
|
+
return sector_list;
|
|
681
|
+
}
|
|
682
|
+
function read_directory(dir_start, sector_list, sectors, Paths, nmfs, files, FileIndex, mini) {
|
|
683
|
+
var minifat_store = 0, pl = Paths.length ? 2 : 0;
|
|
684
|
+
var sector = sector_list[dir_start].data;
|
|
685
|
+
var i2 = 0, namelen = 0, name;
|
|
686
|
+
for (; i2 < sector.length; i2 += 128) {
|
|
687
|
+
var blob = sector.slice(i2, i2 + 128);
|
|
688
|
+
prep_blob(blob, 64);
|
|
689
|
+
namelen = blob.read_shift(2);
|
|
690
|
+
name = __utf16le(blob, 0, namelen - pl);
|
|
691
|
+
Paths.push(name);
|
|
692
|
+
var o = {
|
|
693
|
+
name,
|
|
694
|
+
type: blob.read_shift(1),
|
|
695
|
+
color: blob.read_shift(1),
|
|
696
|
+
L: blob.read_shift(4, "i"),
|
|
697
|
+
R: blob.read_shift(4, "i"),
|
|
698
|
+
C: blob.read_shift(4, "i"),
|
|
699
|
+
clsid: blob.read_shift(16),
|
|
700
|
+
state: blob.read_shift(4, "i"),
|
|
701
|
+
start: 0,
|
|
702
|
+
size: 0
|
|
703
|
+
};
|
|
704
|
+
var ctime = blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2);
|
|
705
|
+
if (ctime !== 0) o.ct = read_date(blob, blob.l - 8);
|
|
706
|
+
var mtime = blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2) + blob.read_shift(2);
|
|
707
|
+
if (mtime !== 0) o.mt = read_date(blob, blob.l - 8);
|
|
708
|
+
o.start = blob.read_shift(4, "i");
|
|
709
|
+
o.size = blob.read_shift(4, "i");
|
|
710
|
+
if (o.size < 0 && o.start < 0) {
|
|
711
|
+
o.size = o.type = 0;
|
|
712
|
+
o.start = ENDOFCHAIN;
|
|
713
|
+
o.name = "";
|
|
714
|
+
}
|
|
715
|
+
if (o.type === 5) {
|
|
716
|
+
minifat_store = o.start;
|
|
717
|
+
if (nmfs > 0 && minifat_store !== ENDOFCHAIN) sector_list[minifat_store].name = "!StreamData";
|
|
718
|
+
} else if (o.size >= 4096) {
|
|
719
|
+
o.storage = "fat";
|
|
720
|
+
if (sector_list[o.start] === void 0) sector_list[o.start] = get_sector_list(sectors, o.start, sector_list.fat_addrs, sector_list.ssz);
|
|
721
|
+
sector_list[o.start].name = o.name;
|
|
722
|
+
o.content = sector_list[o.start].data.slice(0, o.size);
|
|
723
|
+
} else {
|
|
724
|
+
o.storage = "minifat";
|
|
725
|
+
if (o.size < 0) o.size = 0;
|
|
726
|
+
else if (minifat_store !== ENDOFCHAIN && o.start !== ENDOFCHAIN && sector_list[minifat_store]) {
|
|
727
|
+
o.content = get_mfat_entry(o, sector_list[minifat_store].data, (sector_list[mini] || {}).data);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
if (o.content) prep_blob(o.content, 0);
|
|
731
|
+
files[name] = o;
|
|
732
|
+
FileIndex.push(o);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
function read_date(blob, offset) {
|
|
736
|
+
return new Date((__readUInt32LE(blob, offset + 4) / 1e7 * Math.pow(2, 32) + __readUInt32LE(blob, offset) / 1e7 - 11644473600) * 1e3);
|
|
737
|
+
}
|
|
738
|
+
function read_file(filename2, options) {
|
|
739
|
+
get_fs();
|
|
740
|
+
return parse3(fs.readFileSync(filename2), options);
|
|
741
|
+
}
|
|
742
|
+
function read(blob, options) {
|
|
743
|
+
var type = options && options.type;
|
|
744
|
+
if (!type) {
|
|
745
|
+
if (has_buf && Buffer.isBuffer(blob)) type = "buffer";
|
|
746
|
+
}
|
|
747
|
+
switch (type || "base64") {
|
|
748
|
+
case "file":
|
|
749
|
+
return read_file(blob, options);
|
|
750
|
+
case "base64":
|
|
751
|
+
return parse3(s2a(Base64_decode(blob)), options);
|
|
752
|
+
case "binary":
|
|
753
|
+
return parse3(s2a(blob), options);
|
|
754
|
+
}
|
|
755
|
+
return parse3(blob, options);
|
|
756
|
+
}
|
|
757
|
+
function init_cfb(cfb, opts) {
|
|
758
|
+
var o = opts || {}, root = o.root || "Root Entry";
|
|
759
|
+
if (!cfb.FullPaths) cfb.FullPaths = [];
|
|
760
|
+
if (!cfb.FileIndex) cfb.FileIndex = [];
|
|
761
|
+
if (cfb.FullPaths.length !== cfb.FileIndex.length) throw new Error("inconsistent CFB structure");
|
|
762
|
+
if (cfb.FullPaths.length === 0) {
|
|
763
|
+
cfb.FullPaths[0] = root + "/";
|
|
764
|
+
cfb.FileIndex[0] = { name: root, type: 5 };
|
|
765
|
+
}
|
|
766
|
+
if (o.CLSID) cfb.FileIndex[0].clsid = o.CLSID;
|
|
767
|
+
seed_cfb(cfb);
|
|
768
|
+
}
|
|
769
|
+
function seed_cfb(cfb) {
|
|
770
|
+
var nm = "Sh33tJ5";
|
|
771
|
+
if (CFB2.find(cfb, "/" + nm)) return;
|
|
772
|
+
var p = new_buf(4);
|
|
773
|
+
p[0] = 55;
|
|
774
|
+
p[1] = p[3] = 50;
|
|
775
|
+
p[2] = 54;
|
|
776
|
+
cfb.FileIndex.push({ name: nm, type: 2, content: p, size: 4, L: 69, R: 69, C: 69 });
|
|
777
|
+
cfb.FullPaths.push(cfb.FullPaths[0] + nm);
|
|
778
|
+
rebuild_cfb(cfb);
|
|
779
|
+
}
|
|
780
|
+
function rebuild_cfb(cfb, f) {
|
|
781
|
+
init_cfb(cfb);
|
|
782
|
+
var gc = false, s = false;
|
|
783
|
+
for (var i2 = cfb.FullPaths.length - 1; i2 >= 0; --i2) {
|
|
784
|
+
var _file = cfb.FileIndex[i2];
|
|
785
|
+
switch (_file.type) {
|
|
786
|
+
case 0:
|
|
787
|
+
if (s) gc = true;
|
|
788
|
+
else {
|
|
789
|
+
cfb.FileIndex.pop();
|
|
790
|
+
cfb.FullPaths.pop();
|
|
791
|
+
}
|
|
792
|
+
break;
|
|
793
|
+
case 1:
|
|
794
|
+
case 2:
|
|
795
|
+
case 5:
|
|
796
|
+
s = true;
|
|
797
|
+
if (isNaN(_file.R * _file.L * _file.C)) gc = true;
|
|
798
|
+
if (_file.R > -1 && _file.L > -1 && _file.R == _file.L) gc = true;
|
|
799
|
+
break;
|
|
800
|
+
default:
|
|
801
|
+
gc = true;
|
|
802
|
+
break;
|
|
803
|
+
}
|
|
804
|
+
}
|
|
805
|
+
if (!gc && !f) return;
|
|
806
|
+
var now = new Date(1987, 1, 19), j = 0;
|
|
807
|
+
var fullPaths = Object.create ? /* @__PURE__ */ Object.create(null) : {};
|
|
808
|
+
var data = [];
|
|
809
|
+
for (i2 = 0; i2 < cfb.FullPaths.length; ++i2) {
|
|
810
|
+
fullPaths[cfb.FullPaths[i2]] = true;
|
|
811
|
+
if (cfb.FileIndex[i2].type === 0) continue;
|
|
812
|
+
data.push([cfb.FullPaths[i2], cfb.FileIndex[i2]]);
|
|
813
|
+
}
|
|
814
|
+
for (i2 = 0; i2 < data.length; ++i2) {
|
|
815
|
+
var dad = dirname(data[i2][0]);
|
|
816
|
+
s = fullPaths[dad];
|
|
817
|
+
while (!s) {
|
|
818
|
+
while (dirname(dad) && !fullPaths[dirname(dad)]) dad = dirname(dad);
|
|
819
|
+
data.push([dad, {
|
|
820
|
+
name: filename(dad).replace("/", ""),
|
|
821
|
+
type: 1,
|
|
822
|
+
clsid: HEADER_CLSID,
|
|
823
|
+
ct: now,
|
|
824
|
+
mt: now,
|
|
825
|
+
content: null
|
|
826
|
+
}]);
|
|
827
|
+
fullPaths[dad] = true;
|
|
828
|
+
dad = dirname(data[i2][0]);
|
|
829
|
+
s = fullPaths[dad];
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
data.sort(function(x, y) {
|
|
833
|
+
return namecmp(x[0], y[0]);
|
|
834
|
+
});
|
|
835
|
+
cfb.FullPaths = [];
|
|
836
|
+
cfb.FileIndex = [];
|
|
837
|
+
for (i2 = 0; i2 < data.length; ++i2) {
|
|
838
|
+
cfb.FullPaths[i2] = data[i2][0];
|
|
839
|
+
cfb.FileIndex[i2] = data[i2][1];
|
|
840
|
+
}
|
|
841
|
+
for (i2 = 0; i2 < data.length; ++i2) {
|
|
842
|
+
var elt = cfb.FileIndex[i2];
|
|
843
|
+
var nm = cfb.FullPaths[i2];
|
|
844
|
+
elt.name = filename(nm).replace("/", "");
|
|
845
|
+
elt.L = elt.R = elt.C = -(elt.color = 1);
|
|
846
|
+
elt.size = elt.content ? elt.content.length : 0;
|
|
847
|
+
elt.start = 0;
|
|
848
|
+
elt.clsid = elt.clsid || HEADER_CLSID;
|
|
849
|
+
if (i2 === 0) {
|
|
850
|
+
elt.C = data.length > 1 ? 1 : -1;
|
|
851
|
+
elt.size = 0;
|
|
852
|
+
elt.type = 5;
|
|
853
|
+
} else if (nm.slice(-1) == "/") {
|
|
854
|
+
for (j = i2 + 1; j < data.length; ++j) if (dirname(cfb.FullPaths[j]) == nm) break;
|
|
855
|
+
elt.C = j >= data.length ? -1 : j;
|
|
856
|
+
for (j = i2 + 1; j < data.length; ++j) if (dirname(cfb.FullPaths[j]) == dirname(nm)) break;
|
|
857
|
+
elt.R = j >= data.length ? -1 : j;
|
|
858
|
+
elt.type = 1;
|
|
859
|
+
} else {
|
|
860
|
+
if (dirname(cfb.FullPaths[i2 + 1] || "") == dirname(nm)) elt.R = i2 + 1;
|
|
861
|
+
elt.type = 2;
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
function _write(cfb, options) {
|
|
866
|
+
var _opts = options || {};
|
|
867
|
+
if (_opts.fileType == "mad") return write_mad(cfb, _opts);
|
|
868
|
+
rebuild_cfb(cfb);
|
|
869
|
+
switch (_opts.fileType) {
|
|
870
|
+
case "zip":
|
|
871
|
+
return write_zip(cfb, _opts);
|
|
872
|
+
}
|
|
873
|
+
var L = (function(cfb2) {
|
|
874
|
+
var mini_size = 0, fat_size = 0;
|
|
875
|
+
for (var i3 = 0; i3 < cfb2.FileIndex.length; ++i3) {
|
|
876
|
+
var file2 = cfb2.FileIndex[i3];
|
|
877
|
+
if (!file2.content) continue;
|
|
878
|
+
var flen2 = file2.content.length;
|
|
879
|
+
if (flen2 > 0) {
|
|
880
|
+
if (flen2 < 4096) mini_size += flen2 + 63 >> 6;
|
|
881
|
+
else fat_size += flen2 + 511 >> 9;
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
var dir_cnt = cfb2.FullPaths.length + 3 >> 2;
|
|
885
|
+
var mini_cnt = mini_size + 7 >> 3;
|
|
886
|
+
var mfat_cnt = mini_size + 127 >> 7;
|
|
887
|
+
var fat_base = mini_cnt + fat_size + dir_cnt + mfat_cnt;
|
|
888
|
+
var fat_cnt = fat_base + 127 >> 7;
|
|
889
|
+
var difat_cnt = fat_cnt <= 109 ? 0 : Math.ceil((fat_cnt - 109) / 127);
|
|
890
|
+
while (fat_base + fat_cnt + difat_cnt + 127 >> 7 > fat_cnt) difat_cnt = ++fat_cnt <= 109 ? 0 : Math.ceil((fat_cnt - 109) / 127);
|
|
891
|
+
var L2 = [1, difat_cnt, fat_cnt, mfat_cnt, dir_cnt, fat_size, mini_size, 0];
|
|
892
|
+
cfb2.FileIndex[0].size = mini_size << 6;
|
|
893
|
+
L2[7] = (cfb2.FileIndex[0].start = L2[0] + L2[1] + L2[2] + L2[3] + L2[4] + L2[5]) + (L2[6] + 7 >> 3);
|
|
894
|
+
return L2;
|
|
895
|
+
})(cfb);
|
|
896
|
+
var o = new_buf(L[7] << 9);
|
|
897
|
+
var i2 = 0, T = 0;
|
|
898
|
+
{
|
|
899
|
+
for (i2 = 0; i2 < 8; ++i2) o.write_shift(1, HEADER_SIG[i2]);
|
|
900
|
+
for (i2 = 0; i2 < 8; ++i2) o.write_shift(2, 0);
|
|
901
|
+
o.write_shift(2, 62);
|
|
902
|
+
o.write_shift(2, 3);
|
|
903
|
+
o.write_shift(2, 65534);
|
|
904
|
+
o.write_shift(2, 9);
|
|
905
|
+
o.write_shift(2, 6);
|
|
906
|
+
for (i2 = 0; i2 < 3; ++i2) o.write_shift(2, 0);
|
|
907
|
+
o.write_shift(4, 0);
|
|
908
|
+
o.write_shift(4, L[2]);
|
|
909
|
+
o.write_shift(4, L[0] + L[1] + L[2] + L[3] - 1);
|
|
910
|
+
o.write_shift(4, 0);
|
|
911
|
+
o.write_shift(4, 1 << 12);
|
|
912
|
+
o.write_shift(4, L[3] ? L[0] + L[1] + L[2] - 1 : ENDOFCHAIN);
|
|
913
|
+
o.write_shift(4, L[3]);
|
|
914
|
+
o.write_shift(-4, L[1] ? L[0] - 1 : ENDOFCHAIN);
|
|
915
|
+
o.write_shift(4, L[1]);
|
|
916
|
+
for (i2 = 0; i2 < 109; ++i2) o.write_shift(-4, i2 < L[2] ? L[1] + i2 : -1);
|
|
917
|
+
}
|
|
918
|
+
if (L[1]) {
|
|
919
|
+
for (T = 0; T < L[1]; ++T) {
|
|
920
|
+
for (; i2 < 236 + T * 127; ++i2) o.write_shift(-4, i2 < L[2] ? L[1] + i2 : -1);
|
|
921
|
+
o.write_shift(-4, T === L[1] - 1 ? ENDOFCHAIN : T + 1);
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
var chainit = function(w) {
|
|
925
|
+
for (T += w; i2 < T - 1; ++i2) o.write_shift(-4, i2 + 1);
|
|
926
|
+
if (w) {
|
|
927
|
+
++i2;
|
|
928
|
+
o.write_shift(-4, ENDOFCHAIN);
|
|
929
|
+
}
|
|
930
|
+
};
|
|
931
|
+
T = i2 = 0;
|
|
932
|
+
for (T += L[1]; i2 < T; ++i2) o.write_shift(-4, consts.DIFSECT);
|
|
933
|
+
for (T += L[2]; i2 < T; ++i2) o.write_shift(-4, consts.FATSECT);
|
|
934
|
+
chainit(L[3]);
|
|
935
|
+
chainit(L[4]);
|
|
936
|
+
var j = 0, flen = 0;
|
|
937
|
+
var file = cfb.FileIndex[0];
|
|
938
|
+
for (; j < cfb.FileIndex.length; ++j) {
|
|
939
|
+
file = cfb.FileIndex[j];
|
|
940
|
+
if (!file.content) continue;
|
|
941
|
+
flen = file.content.length;
|
|
942
|
+
if (flen < 4096) continue;
|
|
943
|
+
file.start = T;
|
|
944
|
+
chainit(flen + 511 >> 9);
|
|
945
|
+
}
|
|
946
|
+
chainit(L[6] + 7 >> 3);
|
|
947
|
+
while (o.l & 511) o.write_shift(-4, consts.ENDOFCHAIN);
|
|
948
|
+
T = i2 = 0;
|
|
949
|
+
for (j = 0; j < cfb.FileIndex.length; ++j) {
|
|
950
|
+
file = cfb.FileIndex[j];
|
|
951
|
+
if (!file.content) continue;
|
|
952
|
+
flen = file.content.length;
|
|
953
|
+
if (!flen || flen >= 4096) continue;
|
|
954
|
+
file.start = T;
|
|
955
|
+
chainit(flen + 63 >> 6);
|
|
956
|
+
}
|
|
957
|
+
while (o.l & 511) o.write_shift(-4, consts.ENDOFCHAIN);
|
|
958
|
+
for (i2 = 0; i2 < L[4] << 2; ++i2) {
|
|
959
|
+
var nm = cfb.FullPaths[i2];
|
|
960
|
+
if (!nm || nm.length === 0) {
|
|
961
|
+
for (j = 0; j < 17; ++j) o.write_shift(4, 0);
|
|
962
|
+
for (j = 0; j < 3; ++j) o.write_shift(4, -1);
|
|
963
|
+
for (j = 0; j < 12; ++j) o.write_shift(4, 0);
|
|
964
|
+
continue;
|
|
965
|
+
}
|
|
966
|
+
file = cfb.FileIndex[i2];
|
|
967
|
+
if (i2 === 0) file.start = file.size ? file.start - 1 : ENDOFCHAIN;
|
|
968
|
+
var _nm = i2 === 0 && _opts.root || file.name;
|
|
969
|
+
if (_nm.length > 32) {
|
|
970
|
+
console.error("Name " + _nm + " will be truncated to " + _nm.slice(0, 32));
|
|
971
|
+
_nm = _nm.slice(0, 32);
|
|
972
|
+
}
|
|
973
|
+
flen = 2 * (_nm.length + 1);
|
|
974
|
+
o.write_shift(64, _nm, "utf16le");
|
|
975
|
+
o.write_shift(2, flen);
|
|
976
|
+
o.write_shift(1, file.type);
|
|
977
|
+
o.write_shift(1, file.color);
|
|
978
|
+
o.write_shift(-4, file.L);
|
|
979
|
+
o.write_shift(-4, file.R);
|
|
980
|
+
o.write_shift(-4, file.C);
|
|
981
|
+
if (!file.clsid) for (j = 0; j < 4; ++j) o.write_shift(4, 0);
|
|
982
|
+
else o.write_shift(16, file.clsid, "hex");
|
|
983
|
+
o.write_shift(4, file.state || 0);
|
|
984
|
+
o.write_shift(4, 0);
|
|
985
|
+
o.write_shift(4, 0);
|
|
986
|
+
o.write_shift(4, 0);
|
|
987
|
+
o.write_shift(4, 0);
|
|
988
|
+
o.write_shift(4, file.start);
|
|
989
|
+
o.write_shift(4, file.size);
|
|
990
|
+
o.write_shift(4, 0);
|
|
991
|
+
}
|
|
992
|
+
for (i2 = 1; i2 < cfb.FileIndex.length; ++i2) {
|
|
993
|
+
file = cfb.FileIndex[i2];
|
|
994
|
+
if (file.size >= 4096) {
|
|
995
|
+
o.l = file.start + 1 << 9;
|
|
996
|
+
if (has_buf && Buffer.isBuffer(file.content)) {
|
|
997
|
+
file.content.copy(o, o.l, 0, file.size);
|
|
998
|
+
o.l += file.size + 511 & -512;
|
|
999
|
+
} else {
|
|
1000
|
+
for (j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
|
|
1001
|
+
for (; j & 511; ++j) o.write_shift(1, 0);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
}
|
|
1005
|
+
for (i2 = 1; i2 < cfb.FileIndex.length; ++i2) {
|
|
1006
|
+
file = cfb.FileIndex[i2];
|
|
1007
|
+
if (file.size > 0 && file.size < 4096) {
|
|
1008
|
+
if (has_buf && Buffer.isBuffer(file.content)) {
|
|
1009
|
+
file.content.copy(o, o.l, 0, file.size);
|
|
1010
|
+
o.l += file.size + 63 & -64;
|
|
1011
|
+
} else {
|
|
1012
|
+
for (j = 0; j < file.size; ++j) o.write_shift(1, file.content[j]);
|
|
1013
|
+
for (; j & 63; ++j) o.write_shift(1, 0);
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
if (has_buf) {
|
|
1018
|
+
o.l = o.length;
|
|
1019
|
+
} else {
|
|
1020
|
+
while (o.l < o.length) o.write_shift(1, 0);
|
|
1021
|
+
}
|
|
1022
|
+
return o;
|
|
1023
|
+
}
|
|
1024
|
+
function find2(cfb, path) {
|
|
1025
|
+
var UCFullPaths = cfb.FullPaths.map(function(x) {
|
|
1026
|
+
return x.toUpperCase();
|
|
1027
|
+
});
|
|
1028
|
+
var UCPaths = UCFullPaths.map(function(x) {
|
|
1029
|
+
var y = x.split("/");
|
|
1030
|
+
return y[y.length - (x.slice(-1) == "/" ? 2 : 1)];
|
|
1031
|
+
});
|
|
1032
|
+
var k = false;
|
|
1033
|
+
if (path.charCodeAt(0) === 47) {
|
|
1034
|
+
k = true;
|
|
1035
|
+
path = UCFullPaths[0].slice(0, -1) + path;
|
|
1036
|
+
} else k = path.indexOf("/") !== -1;
|
|
1037
|
+
var UCPath = path.toUpperCase();
|
|
1038
|
+
var w = k === true ? UCFullPaths.indexOf(UCPath) : UCPaths.indexOf(UCPath);
|
|
1039
|
+
if (w !== -1) return cfb.FileIndex[w];
|
|
1040
|
+
var m = !UCPath.match(chr1);
|
|
1041
|
+
UCPath = UCPath.replace(chr0, "");
|
|
1042
|
+
if (m) UCPath = UCPath.replace(chr1, "!");
|
|
1043
|
+
for (w = 0; w < UCFullPaths.length; ++w) {
|
|
1044
|
+
if ((m ? UCFullPaths[w].replace(chr1, "!") : UCFullPaths[w]).replace(chr0, "") == UCPath) return cfb.FileIndex[w];
|
|
1045
|
+
if ((m ? UCPaths[w].replace(chr1, "!") : UCPaths[w]).replace(chr0, "") == UCPath) return cfb.FileIndex[w];
|
|
1046
|
+
}
|
|
1047
|
+
return null;
|
|
1048
|
+
}
|
|
1049
|
+
var MSSZ = 64;
|
|
1050
|
+
var ENDOFCHAIN = -2;
|
|
1051
|
+
var HEADER_SIGNATURE = "d0cf11e0a1b11ae1";
|
|
1052
|
+
var HEADER_SIG = [208, 207, 17, 224, 161, 177, 26, 225];
|
|
1053
|
+
var HEADER_CLSID = "00000000000000000000000000000000";
|
|
1054
|
+
var consts = {
|
|
1055
|
+
/* 2.1 Compund File Sector Numbers and Types */
|
|
1056
|
+
MAXREGSECT: -6,
|
|
1057
|
+
DIFSECT: -4,
|
|
1058
|
+
FATSECT: -3,
|
|
1059
|
+
ENDOFCHAIN,
|
|
1060
|
+
FREESECT: -1,
|
|
1061
|
+
/* 2.2 Compound File Header */
|
|
1062
|
+
HEADER_SIGNATURE,
|
|
1063
|
+
HEADER_MINOR_VERSION: "3e00",
|
|
1064
|
+
MAXREGSID: -6,
|
|
1065
|
+
NOSTREAM: -1,
|
|
1066
|
+
HEADER_CLSID,
|
|
1067
|
+
/* 2.6.1 Compound File Directory Entry */
|
|
1068
|
+
EntryTypes: ["unknown", "storage", "stream", "lockbytes", "property", "root"]
|
|
1069
|
+
};
|
|
1070
|
+
function write_file(cfb, filename2, options) {
|
|
1071
|
+
get_fs();
|
|
1072
|
+
var o = _write(cfb, options);
|
|
1073
|
+
fs.writeFileSync(filename2, o);
|
|
1074
|
+
}
|
|
1075
|
+
function a2s(o) {
|
|
1076
|
+
var out = new Array(o.length);
|
|
1077
|
+
for (var i2 = 0; i2 < o.length; ++i2) out[i2] = String.fromCharCode(o[i2]);
|
|
1078
|
+
return out.join("");
|
|
1079
|
+
}
|
|
1080
|
+
function write(cfb, options) {
|
|
1081
|
+
var o = _write(cfb, options);
|
|
1082
|
+
switch (options && options.type || "buffer") {
|
|
1083
|
+
case "file":
|
|
1084
|
+
get_fs();
|
|
1085
|
+
fs.writeFileSync(options.filename, o);
|
|
1086
|
+
return o;
|
|
1087
|
+
case "binary":
|
|
1088
|
+
return typeof o == "string" ? o : a2s(o);
|
|
1089
|
+
case "base64":
|
|
1090
|
+
return Base64_encode(typeof o == "string" ? o : a2s(o));
|
|
1091
|
+
case "buffer":
|
|
1092
|
+
if (has_buf) return Buffer.isBuffer(o) ? o : Buffer_from(o);
|
|
1093
|
+
/* falls through */
|
|
1094
|
+
case "array":
|
|
1095
|
+
return typeof o == "string" ? s2a(o) : o;
|
|
1096
|
+
}
|
|
1097
|
+
return o;
|
|
1098
|
+
}
|
|
1099
|
+
var _zlib;
|
|
1100
|
+
function use_zlib(zlib) {
|
|
1101
|
+
try {
|
|
1102
|
+
var InflateRaw = zlib.InflateRaw;
|
|
1103
|
+
var InflRaw = new InflateRaw();
|
|
1104
|
+
InflRaw._processChunk(new Uint8Array([3, 0]), InflRaw._finishFlushFlag);
|
|
1105
|
+
if (InflRaw.bytesRead) _zlib = zlib;
|
|
1106
|
+
else throw new Error("zlib does not expose bytesRead");
|
|
1107
|
+
} catch (e) {
|
|
1108
|
+
console.error("cannot use native zlib: " + (e.message || e));
|
|
1109
|
+
}
|
|
1110
|
+
}
|
|
1111
|
+
function _inflateRawSync(payload, usz) {
|
|
1112
|
+
if (!_zlib) return _inflate(payload, usz);
|
|
1113
|
+
var InflateRaw = _zlib.InflateRaw;
|
|
1114
|
+
var InflRaw = new InflateRaw();
|
|
1115
|
+
var out = InflRaw._processChunk(payload.slice(payload.l), InflRaw._finishFlushFlag);
|
|
1116
|
+
payload.l += InflRaw.bytesRead;
|
|
1117
|
+
return out;
|
|
1118
|
+
}
|
|
1119
|
+
function _deflateRawSync(payload) {
|
|
1120
|
+
return _zlib ? _zlib.deflateRawSync(payload) : _deflate(payload);
|
|
1121
|
+
}
|
|
1122
|
+
var CLEN_ORDER = [16, 17, 18, 0, 8, 7, 9, 6, 10, 5, 11, 4, 12, 3, 13, 2, 14, 1, 15];
|
|
1123
|
+
var LEN_LN = [3, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 17, 19, 23, 27, 31, 35, 43, 51, 59, 67, 83, 99, 115, 131, 163, 195, 227, 258];
|
|
1124
|
+
var DST_LN = [1, 2, 3, 4, 5, 7, 9, 13, 17, 25, 33, 49, 65, 97, 129, 193, 257, 385, 513, 769, 1025, 1537, 2049, 3073, 4097, 6145, 8193, 12289, 16385, 24577];
|
|
1125
|
+
function bit_swap_8(n) {
|
|
1126
|
+
var t = (n << 1 | n << 11) & 139536 | (n << 5 | n << 15) & 558144;
|
|
1127
|
+
return (t >> 16 | t >> 8 | t) & 255;
|
|
1128
|
+
}
|
|
1129
|
+
var use_typed_arrays = typeof Uint8Array !== "undefined";
|
|
1130
|
+
var bitswap8 = use_typed_arrays ? new Uint8Array(1 << 8) : [];
|
|
1131
|
+
for (var q = 0; q < 1 << 8; ++q) bitswap8[q] = bit_swap_8(q);
|
|
1132
|
+
function bit_swap_n(n, b) {
|
|
1133
|
+
var rev = bitswap8[n & 255];
|
|
1134
|
+
if (b <= 8) return rev >>> 8 - b;
|
|
1135
|
+
rev = rev << 8 | bitswap8[n >> 8 & 255];
|
|
1136
|
+
if (b <= 16) return rev >>> 16 - b;
|
|
1137
|
+
rev = rev << 8 | bitswap8[n >> 16 & 255];
|
|
1138
|
+
return rev >>> 24 - b;
|
|
1139
|
+
}
|
|
1140
|
+
function read_bits_2(buf, bl) {
|
|
1141
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1142
|
+
return (buf[h] | (w <= 6 ? 0 : buf[h + 1] << 8)) >>> w & 3;
|
|
1143
|
+
}
|
|
1144
|
+
function read_bits_3(buf, bl) {
|
|
1145
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1146
|
+
return (buf[h] | (w <= 5 ? 0 : buf[h + 1] << 8)) >>> w & 7;
|
|
1147
|
+
}
|
|
1148
|
+
function read_bits_4(buf, bl) {
|
|
1149
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1150
|
+
return (buf[h] | (w <= 4 ? 0 : buf[h + 1] << 8)) >>> w & 15;
|
|
1151
|
+
}
|
|
1152
|
+
function read_bits_5(buf, bl) {
|
|
1153
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1154
|
+
return (buf[h] | (w <= 3 ? 0 : buf[h + 1] << 8)) >>> w & 31;
|
|
1155
|
+
}
|
|
1156
|
+
function read_bits_7(buf, bl) {
|
|
1157
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1158
|
+
return (buf[h] | (w <= 1 ? 0 : buf[h + 1] << 8)) >>> w & 127;
|
|
1159
|
+
}
|
|
1160
|
+
function read_bits_n(buf, bl, n) {
|
|
1161
|
+
var w = bl & 7, h = bl >>> 3, f = (1 << n) - 1;
|
|
1162
|
+
var v = buf[h] >>> w;
|
|
1163
|
+
if (n < 8 - w) return v & f;
|
|
1164
|
+
v |= buf[h + 1] << 8 - w;
|
|
1165
|
+
if (n < 16 - w) return v & f;
|
|
1166
|
+
v |= buf[h + 2] << 16 - w;
|
|
1167
|
+
if (n < 24 - w) return v & f;
|
|
1168
|
+
v |= buf[h + 3] << 24 - w;
|
|
1169
|
+
return v & f;
|
|
1170
|
+
}
|
|
1171
|
+
function write_bits_3(buf, bl, v) {
|
|
1172
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1173
|
+
if (w <= 5) buf[h] |= (v & 7) << w;
|
|
1174
|
+
else {
|
|
1175
|
+
buf[h] |= v << w & 255;
|
|
1176
|
+
buf[h + 1] = (v & 7) >> 8 - w;
|
|
1177
|
+
}
|
|
1178
|
+
return bl + 3;
|
|
1179
|
+
}
|
|
1180
|
+
function write_bits_1(buf, bl, v) {
|
|
1181
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1182
|
+
v = (v & 1) << w;
|
|
1183
|
+
buf[h] |= v;
|
|
1184
|
+
return bl + 1;
|
|
1185
|
+
}
|
|
1186
|
+
function write_bits_8(buf, bl, v) {
|
|
1187
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1188
|
+
v <<= w;
|
|
1189
|
+
buf[h] |= v & 255;
|
|
1190
|
+
v >>>= 8;
|
|
1191
|
+
buf[h + 1] = v;
|
|
1192
|
+
return bl + 8;
|
|
1193
|
+
}
|
|
1194
|
+
function write_bits_16(buf, bl, v) {
|
|
1195
|
+
var w = bl & 7, h = bl >>> 3;
|
|
1196
|
+
v <<= w;
|
|
1197
|
+
buf[h] |= v & 255;
|
|
1198
|
+
v >>>= 8;
|
|
1199
|
+
buf[h + 1] = v & 255;
|
|
1200
|
+
buf[h + 2] = v >>> 8;
|
|
1201
|
+
return bl + 16;
|
|
1202
|
+
}
|
|
1203
|
+
function realloc(b, sz) {
|
|
1204
|
+
var L = b.length, M = 2 * L > sz ? 2 * L : sz + 5, i2 = 0;
|
|
1205
|
+
if (L >= sz) return b;
|
|
1206
|
+
if (has_buf) {
|
|
1207
|
+
var o = new_unsafe_buf(M);
|
|
1208
|
+
if (b.copy) b.copy(o);
|
|
1209
|
+
else for (; i2 < b.length; ++i2) o[i2] = b[i2];
|
|
1210
|
+
return o;
|
|
1211
|
+
} else if (use_typed_arrays) {
|
|
1212
|
+
var a = new Uint8Array(M);
|
|
1213
|
+
if (a.set) a.set(b);
|
|
1214
|
+
else for (; i2 < L; ++i2) a[i2] = b[i2];
|
|
1215
|
+
return a;
|
|
1216
|
+
}
|
|
1217
|
+
b.length = M;
|
|
1218
|
+
return b;
|
|
1219
|
+
}
|
|
1220
|
+
function zero_fill_array(n) {
|
|
1221
|
+
var o = new Array(n);
|
|
1222
|
+
for (var i2 = 0; i2 < n; ++i2) o[i2] = 0;
|
|
1223
|
+
return o;
|
|
1224
|
+
}
|
|
1225
|
+
function build_tree(clens, cmap, MAX) {
|
|
1226
|
+
var maxlen = 1, w = 0, i2 = 0, j = 0, ccode = 0, L = clens.length;
|
|
1227
|
+
var bl_count = use_typed_arrays ? new Uint16Array(32) : zero_fill_array(32);
|
|
1228
|
+
for (i2 = 0; i2 < 32; ++i2) bl_count[i2] = 0;
|
|
1229
|
+
for (i2 = L; i2 < MAX; ++i2) clens[i2] = 0;
|
|
1230
|
+
L = clens.length;
|
|
1231
|
+
var ctree = use_typed_arrays ? new Uint16Array(L) : zero_fill_array(L);
|
|
1232
|
+
for (i2 = 0; i2 < L; ++i2) {
|
|
1233
|
+
bl_count[w = clens[i2]]++;
|
|
1234
|
+
if (maxlen < w) maxlen = w;
|
|
1235
|
+
ctree[i2] = 0;
|
|
1236
|
+
}
|
|
1237
|
+
bl_count[0] = 0;
|
|
1238
|
+
for (i2 = 1; i2 <= maxlen; ++i2) bl_count[i2 + 16] = ccode = ccode + bl_count[i2 - 1] << 1;
|
|
1239
|
+
for (i2 = 0; i2 < L; ++i2) {
|
|
1240
|
+
ccode = clens[i2];
|
|
1241
|
+
if (ccode != 0) ctree[i2] = bl_count[ccode + 16]++;
|
|
1242
|
+
}
|
|
1243
|
+
var cleni = 0;
|
|
1244
|
+
for (i2 = 0; i2 < L; ++i2) {
|
|
1245
|
+
cleni = clens[i2];
|
|
1246
|
+
if (cleni != 0) {
|
|
1247
|
+
ccode = bit_swap_n(ctree[i2], maxlen) >> maxlen - cleni;
|
|
1248
|
+
for (j = (1 << maxlen + 4 - cleni) - 1; j >= 0; --j)
|
|
1249
|
+
cmap[ccode | j << cleni] = cleni & 15 | i2 << 4;
|
|
1250
|
+
}
|
|
1251
|
+
}
|
|
1252
|
+
return maxlen;
|
|
1253
|
+
}
|
|
1254
|
+
var fix_lmap = use_typed_arrays ? new Uint16Array(512) : zero_fill_array(512);
|
|
1255
|
+
var fix_dmap = use_typed_arrays ? new Uint16Array(32) : zero_fill_array(32);
|
|
1256
|
+
if (!use_typed_arrays) {
|
|
1257
|
+
for (var i = 0; i < 512; ++i) fix_lmap[i] = 0;
|
|
1258
|
+
for (i = 0; i < 32; ++i) fix_dmap[i] = 0;
|
|
1259
|
+
}
|
|
1260
|
+
(function() {
|
|
1261
|
+
var dlens = [];
|
|
1262
|
+
var i2 = 0;
|
|
1263
|
+
for (; i2 < 32; i2++) dlens.push(5);
|
|
1264
|
+
build_tree(dlens, fix_dmap, 32);
|
|
1265
|
+
var clens = [];
|
|
1266
|
+
i2 = 0;
|
|
1267
|
+
for (; i2 <= 143; i2++) clens.push(8);
|
|
1268
|
+
for (; i2 <= 255; i2++) clens.push(9);
|
|
1269
|
+
for (; i2 <= 279; i2++) clens.push(7);
|
|
1270
|
+
for (; i2 <= 287; i2++) clens.push(8);
|
|
1271
|
+
build_tree(clens, fix_lmap, 288);
|
|
1272
|
+
})();
|
|
1273
|
+
var _deflateRaw = (function _deflateRawIIFE() {
|
|
1274
|
+
var DST_LN_RE = use_typed_arrays ? new Uint8Array(32768) : [];
|
|
1275
|
+
var j = 0, k = 0;
|
|
1276
|
+
for (; j < DST_LN.length - 1; ++j) {
|
|
1277
|
+
for (; k < DST_LN[j + 1]; ++k) DST_LN_RE[k] = j;
|
|
1278
|
+
}
|
|
1279
|
+
for (; k < 32768; ++k) DST_LN_RE[k] = 29;
|
|
1280
|
+
var LEN_LN_RE = use_typed_arrays ? new Uint8Array(259) : [];
|
|
1281
|
+
for (j = 0, k = 0; j < LEN_LN.length - 1; ++j) {
|
|
1282
|
+
for (; k < LEN_LN[j + 1]; ++k) LEN_LN_RE[k] = j;
|
|
1283
|
+
}
|
|
1284
|
+
function write_stored(data, out) {
|
|
1285
|
+
var boff = 0;
|
|
1286
|
+
while (boff < data.length) {
|
|
1287
|
+
var L = Math.min(65535, data.length - boff);
|
|
1288
|
+
var h = boff + L == data.length;
|
|
1289
|
+
out.write_shift(1, +h);
|
|
1290
|
+
out.write_shift(2, L);
|
|
1291
|
+
out.write_shift(2, ~L & 65535);
|
|
1292
|
+
while (L-- > 0) out[out.l++] = data[boff++];
|
|
1293
|
+
}
|
|
1294
|
+
return out.l;
|
|
1295
|
+
}
|
|
1296
|
+
function write_huff_fixed(data, out) {
|
|
1297
|
+
var bl = 0;
|
|
1298
|
+
var boff = 0;
|
|
1299
|
+
var addrs = use_typed_arrays ? new Uint16Array(32768) : [];
|
|
1300
|
+
while (boff < data.length) {
|
|
1301
|
+
var L = (
|
|
1302
|
+
/* data.length - boff; */
|
|
1303
|
+
Math.min(65535, data.length - boff)
|
|
1304
|
+
);
|
|
1305
|
+
if (L < 10) {
|
|
1306
|
+
bl = write_bits_3(out, bl, +!!(boff + L == data.length));
|
|
1307
|
+
if (bl & 7) bl += 8 - (bl & 7);
|
|
1308
|
+
out.l = bl / 8 | 0;
|
|
1309
|
+
out.write_shift(2, L);
|
|
1310
|
+
out.write_shift(2, ~L & 65535);
|
|
1311
|
+
while (L-- > 0) out[out.l++] = data[boff++];
|
|
1312
|
+
bl = out.l * 8;
|
|
1313
|
+
continue;
|
|
1314
|
+
}
|
|
1315
|
+
bl = write_bits_3(out, bl, +!!(boff + L == data.length) + 2);
|
|
1316
|
+
var hash = 0;
|
|
1317
|
+
while (L-- > 0) {
|
|
1318
|
+
var d = data[boff];
|
|
1319
|
+
hash = (hash << 5 ^ d) & 32767;
|
|
1320
|
+
var match = -1, mlen = 0;
|
|
1321
|
+
if (match = addrs[hash]) {
|
|
1322
|
+
match |= boff & ~32767;
|
|
1323
|
+
if (match > boff) match -= 32768;
|
|
1324
|
+
if (match < boff) while (data[match + mlen] == data[boff + mlen] && mlen < 250) ++mlen;
|
|
1325
|
+
}
|
|
1326
|
+
if (mlen > 2) {
|
|
1327
|
+
d = LEN_LN_RE[mlen];
|
|
1328
|
+
if (d <= 22) bl = write_bits_8(out, bl, bitswap8[d + 1] >> 1) - 1;
|
|
1329
|
+
else {
|
|
1330
|
+
write_bits_8(out, bl, 3);
|
|
1331
|
+
bl += 5;
|
|
1332
|
+
write_bits_8(out, bl, bitswap8[d - 23] >> 5);
|
|
1333
|
+
bl += 3;
|
|
1334
|
+
}
|
|
1335
|
+
var len_eb = d < 8 ? 0 : d - 4 >> 2;
|
|
1336
|
+
if (len_eb > 0) {
|
|
1337
|
+
write_bits_16(out, bl, mlen - LEN_LN[d]);
|
|
1338
|
+
bl += len_eb;
|
|
1339
|
+
}
|
|
1340
|
+
d = DST_LN_RE[boff - match];
|
|
1341
|
+
bl = write_bits_8(out, bl, bitswap8[d] >> 3);
|
|
1342
|
+
bl -= 3;
|
|
1343
|
+
var dst_eb = d < 4 ? 0 : d - 2 >> 1;
|
|
1344
|
+
if (dst_eb > 0) {
|
|
1345
|
+
write_bits_16(out, bl, boff - match - DST_LN[d]);
|
|
1346
|
+
bl += dst_eb;
|
|
1347
|
+
}
|
|
1348
|
+
for (var q2 = 0; q2 < mlen; ++q2) {
|
|
1349
|
+
addrs[hash] = boff & 32767;
|
|
1350
|
+
hash = (hash << 5 ^ data[boff]) & 32767;
|
|
1351
|
+
++boff;
|
|
1352
|
+
}
|
|
1353
|
+
L -= mlen - 1;
|
|
1354
|
+
} else {
|
|
1355
|
+
if (d <= 143) d = d + 48;
|
|
1356
|
+
else bl = write_bits_1(out, bl, 1);
|
|
1357
|
+
bl = write_bits_8(out, bl, bitswap8[d]);
|
|
1358
|
+
addrs[hash] = boff & 32767;
|
|
1359
|
+
++boff;
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
bl = write_bits_8(out, bl, 0) - 1;
|
|
1363
|
+
}
|
|
1364
|
+
out.l = (bl + 7) / 8 | 0;
|
|
1365
|
+
return out.l;
|
|
1366
|
+
}
|
|
1367
|
+
return function _deflateRaw2(data, out) {
|
|
1368
|
+
if (data.length < 8) return write_stored(data, out);
|
|
1369
|
+
return write_huff_fixed(data, out);
|
|
1370
|
+
};
|
|
1371
|
+
})();
|
|
1372
|
+
function _deflate(data) {
|
|
1373
|
+
var buf = new_buf(50 + Math.floor(data.length * 1.1));
|
|
1374
|
+
var off = _deflateRaw(data, buf);
|
|
1375
|
+
return buf.slice(0, off);
|
|
1376
|
+
}
|
|
1377
|
+
var dyn_lmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
|
|
1378
|
+
var dyn_dmap = use_typed_arrays ? new Uint16Array(32768) : zero_fill_array(32768);
|
|
1379
|
+
var dyn_cmap = use_typed_arrays ? new Uint16Array(128) : zero_fill_array(128);
|
|
1380
|
+
var dyn_len_1 = 1, dyn_len_2 = 1;
|
|
1381
|
+
function dyn(data, boff) {
|
|
1382
|
+
var _HLIT = read_bits_5(data, boff) + 257;
|
|
1383
|
+
boff += 5;
|
|
1384
|
+
var _HDIST = read_bits_5(data, boff) + 1;
|
|
1385
|
+
boff += 5;
|
|
1386
|
+
var _HCLEN = read_bits_4(data, boff) + 4;
|
|
1387
|
+
boff += 4;
|
|
1388
|
+
var w = 0;
|
|
1389
|
+
var clens = use_typed_arrays ? new Uint8Array(19) : zero_fill_array(19);
|
|
1390
|
+
var ctree = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
|
|
1391
|
+
var maxlen = 1;
|
|
1392
|
+
var bl_count = use_typed_arrays ? new Uint8Array(8) : zero_fill_array(8);
|
|
1393
|
+
var next_code = use_typed_arrays ? new Uint8Array(8) : zero_fill_array(8);
|
|
1394
|
+
var L = clens.length;
|
|
1395
|
+
for (var i2 = 0; i2 < _HCLEN; ++i2) {
|
|
1396
|
+
clens[CLEN_ORDER[i2]] = w = read_bits_3(data, boff);
|
|
1397
|
+
if (maxlen < w) maxlen = w;
|
|
1398
|
+
bl_count[w]++;
|
|
1399
|
+
boff += 3;
|
|
1400
|
+
}
|
|
1401
|
+
var ccode = 0;
|
|
1402
|
+
bl_count[0] = 0;
|
|
1403
|
+
for (i2 = 1; i2 <= maxlen; ++i2) next_code[i2] = ccode = ccode + bl_count[i2 - 1] << 1;
|
|
1404
|
+
for (i2 = 0; i2 < L; ++i2) if ((ccode = clens[i2]) != 0) ctree[i2] = next_code[ccode]++;
|
|
1405
|
+
var cleni = 0;
|
|
1406
|
+
for (i2 = 0; i2 < L; ++i2) {
|
|
1407
|
+
cleni = clens[i2];
|
|
1408
|
+
if (cleni != 0) {
|
|
1409
|
+
ccode = bitswap8[ctree[i2]] >> 8 - cleni;
|
|
1410
|
+
for (var j = (1 << 7 - cleni) - 1; j >= 0; --j) dyn_cmap[ccode | j << cleni] = cleni & 7 | i2 << 3;
|
|
1411
|
+
}
|
|
1412
|
+
}
|
|
1413
|
+
var hcodes = [];
|
|
1414
|
+
maxlen = 1;
|
|
1415
|
+
for (; hcodes.length < _HLIT + _HDIST; ) {
|
|
1416
|
+
ccode = dyn_cmap[read_bits_7(data, boff)];
|
|
1417
|
+
boff += ccode & 7;
|
|
1418
|
+
switch (ccode >>>= 3) {
|
|
1419
|
+
case 16:
|
|
1420
|
+
w = 3 + read_bits_2(data, boff);
|
|
1421
|
+
boff += 2;
|
|
1422
|
+
ccode = hcodes[hcodes.length - 1];
|
|
1423
|
+
while (w-- > 0) hcodes.push(ccode);
|
|
1424
|
+
break;
|
|
1425
|
+
case 17:
|
|
1426
|
+
w = 3 + read_bits_3(data, boff);
|
|
1427
|
+
boff += 3;
|
|
1428
|
+
while (w-- > 0) hcodes.push(0);
|
|
1429
|
+
break;
|
|
1430
|
+
case 18:
|
|
1431
|
+
w = 11 + read_bits_7(data, boff);
|
|
1432
|
+
boff += 7;
|
|
1433
|
+
while (w-- > 0) hcodes.push(0);
|
|
1434
|
+
break;
|
|
1435
|
+
default:
|
|
1436
|
+
hcodes.push(ccode);
|
|
1437
|
+
if (maxlen < ccode) maxlen = ccode;
|
|
1438
|
+
break;
|
|
1439
|
+
}
|
|
1440
|
+
}
|
|
1441
|
+
var h1 = hcodes.slice(0, _HLIT), h2 = hcodes.slice(_HLIT);
|
|
1442
|
+
for (i2 = _HLIT; i2 < 286; ++i2) h1[i2] = 0;
|
|
1443
|
+
for (i2 = _HDIST; i2 < 30; ++i2) h2[i2] = 0;
|
|
1444
|
+
dyn_len_1 = build_tree(h1, dyn_lmap, 286);
|
|
1445
|
+
dyn_len_2 = build_tree(h2, dyn_dmap, 30);
|
|
1446
|
+
return boff;
|
|
1447
|
+
}
|
|
1448
|
+
function inflate(data, usz) {
|
|
1449
|
+
if (data[0] == 3 && !(data[1] & 3)) {
|
|
1450
|
+
return [new_raw_buf(usz), 2];
|
|
1451
|
+
}
|
|
1452
|
+
var boff = 0;
|
|
1453
|
+
var header = 0;
|
|
1454
|
+
var outbuf = new_unsafe_buf(usz ? usz : 1 << 18);
|
|
1455
|
+
var woff = 0;
|
|
1456
|
+
var OL = outbuf.length >>> 0;
|
|
1457
|
+
var max_len_1 = 0, max_len_2 = 0;
|
|
1458
|
+
while ((header & 1) == 0) {
|
|
1459
|
+
header = read_bits_3(data, boff);
|
|
1460
|
+
boff += 3;
|
|
1461
|
+
if (header >>> 1 == 0) {
|
|
1462
|
+
if (boff & 7) boff += 8 - (boff & 7);
|
|
1463
|
+
var sz = data[boff >>> 3] | data[(boff >>> 3) + 1] << 8;
|
|
1464
|
+
boff += 32;
|
|
1465
|
+
if (sz > 0) {
|
|
1466
|
+
if (!usz && OL < woff + sz) {
|
|
1467
|
+
outbuf = realloc(outbuf, woff + sz);
|
|
1468
|
+
OL = outbuf.length;
|
|
1469
|
+
}
|
|
1470
|
+
while (sz-- > 0) {
|
|
1471
|
+
outbuf[woff++] = data[boff >>> 3];
|
|
1472
|
+
boff += 8;
|
|
1473
|
+
}
|
|
1474
|
+
}
|
|
1475
|
+
continue;
|
|
1476
|
+
} else if (header >> 1 == 1) {
|
|
1477
|
+
max_len_1 = 9;
|
|
1478
|
+
max_len_2 = 5;
|
|
1479
|
+
} else {
|
|
1480
|
+
boff = dyn(data, boff);
|
|
1481
|
+
max_len_1 = dyn_len_1;
|
|
1482
|
+
max_len_2 = dyn_len_2;
|
|
1483
|
+
}
|
|
1484
|
+
for (; ; ) {
|
|
1485
|
+
if (!usz && OL < woff + 32767) {
|
|
1486
|
+
outbuf = realloc(outbuf, woff + 32767);
|
|
1487
|
+
OL = outbuf.length;
|
|
1488
|
+
}
|
|
1489
|
+
var bits = read_bits_n(data, boff, max_len_1);
|
|
1490
|
+
var code = header >>> 1 == 1 ? fix_lmap[bits] : dyn_lmap[bits];
|
|
1491
|
+
boff += code & 15;
|
|
1492
|
+
code >>>= 4;
|
|
1493
|
+
if ((code >>> 8 & 255) === 0) outbuf[woff++] = code;
|
|
1494
|
+
else if (code == 256) break;
|
|
1495
|
+
else {
|
|
1496
|
+
code -= 257;
|
|
1497
|
+
var len_eb = code < 8 ? 0 : code - 4 >> 2;
|
|
1498
|
+
if (len_eb > 5) len_eb = 0;
|
|
1499
|
+
var tgt = woff + LEN_LN[code];
|
|
1500
|
+
if (len_eb > 0) {
|
|
1501
|
+
tgt += read_bits_n(data, boff, len_eb);
|
|
1502
|
+
boff += len_eb;
|
|
1503
|
+
}
|
|
1504
|
+
bits = read_bits_n(data, boff, max_len_2);
|
|
1505
|
+
code = header >>> 1 == 1 ? fix_dmap[bits] : dyn_dmap[bits];
|
|
1506
|
+
boff += code & 15;
|
|
1507
|
+
code >>>= 4;
|
|
1508
|
+
var dst_eb = code < 4 ? 0 : code - 2 >> 1;
|
|
1509
|
+
var dst = DST_LN[code];
|
|
1510
|
+
if (dst_eb > 0) {
|
|
1511
|
+
dst += read_bits_n(data, boff, dst_eb);
|
|
1512
|
+
boff += dst_eb;
|
|
1513
|
+
}
|
|
1514
|
+
if (!usz && OL < tgt) {
|
|
1515
|
+
outbuf = realloc(outbuf, tgt + 100);
|
|
1516
|
+
OL = outbuf.length;
|
|
1517
|
+
}
|
|
1518
|
+
while (woff < tgt) {
|
|
1519
|
+
outbuf[woff] = outbuf[woff - dst];
|
|
1520
|
+
++woff;
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
}
|
|
1524
|
+
}
|
|
1525
|
+
if (usz) return [outbuf, boff + 7 >>> 3];
|
|
1526
|
+
return [outbuf.slice(0, woff), boff + 7 >>> 3];
|
|
1527
|
+
}
|
|
1528
|
+
function _inflate(payload, usz) {
|
|
1529
|
+
var data = payload.slice(payload.l || 0);
|
|
1530
|
+
var out = inflate(data, usz);
|
|
1531
|
+
payload.l += out[1];
|
|
1532
|
+
return out[0];
|
|
1533
|
+
}
|
|
1534
|
+
function warn_or_throw(wrn, msg) {
|
|
1535
|
+
if (wrn) {
|
|
1536
|
+
if (typeof console !== "undefined") console.error(msg);
|
|
1537
|
+
} else throw new Error(msg);
|
|
1538
|
+
}
|
|
1539
|
+
function parse_zip(file, options) {
|
|
1540
|
+
var blob = file;
|
|
1541
|
+
prep_blob(blob, 0);
|
|
1542
|
+
var FileIndex = [], FullPaths = [];
|
|
1543
|
+
var o = {
|
|
1544
|
+
FileIndex,
|
|
1545
|
+
FullPaths
|
|
1546
|
+
};
|
|
1547
|
+
init_cfb(o, { root: options.root });
|
|
1548
|
+
var i2 = blob.length - 4;
|
|
1549
|
+
while ((blob[i2] != 80 || blob[i2 + 1] != 75 || blob[i2 + 2] != 5 || blob[i2 + 3] != 6) && i2 >= 0) --i2;
|
|
1550
|
+
blob.l = i2 + 4;
|
|
1551
|
+
blob.l += 4;
|
|
1552
|
+
var fcnt = blob.read_shift(2);
|
|
1553
|
+
blob.l += 6;
|
|
1554
|
+
var start_cd = blob.read_shift(4);
|
|
1555
|
+
blob.l = start_cd;
|
|
1556
|
+
for (i2 = 0; i2 < fcnt; ++i2) {
|
|
1557
|
+
blob.l += 20;
|
|
1558
|
+
var csz = blob.read_shift(4);
|
|
1559
|
+
var usz = blob.read_shift(4);
|
|
1560
|
+
var namelen = blob.read_shift(2);
|
|
1561
|
+
var efsz = blob.read_shift(2);
|
|
1562
|
+
var fcsz = blob.read_shift(2);
|
|
1563
|
+
blob.l += 8;
|
|
1564
|
+
var offset = blob.read_shift(4);
|
|
1565
|
+
var EF = parse_extra_field(blob.slice(blob.l + namelen, blob.l + namelen + efsz));
|
|
1566
|
+
blob.l += namelen + efsz + fcsz;
|
|
1567
|
+
var L = blob.l;
|
|
1568
|
+
blob.l = offset + 4;
|
|
1569
|
+
parse_local_file(blob, csz, usz, o, EF);
|
|
1570
|
+
blob.l = L;
|
|
1571
|
+
}
|
|
1572
|
+
return o;
|
|
1573
|
+
}
|
|
1574
|
+
function parse_local_file(blob, csz, usz, o, EF) {
|
|
1575
|
+
blob.l += 2;
|
|
1576
|
+
var flags = blob.read_shift(2);
|
|
1577
|
+
var meth = blob.read_shift(2);
|
|
1578
|
+
var date = parse_dos_date(blob);
|
|
1579
|
+
if (flags & 8257) throw new Error("Unsupported ZIP encryption");
|
|
1580
|
+
var crc32 = blob.read_shift(4);
|
|
1581
|
+
var _csz = blob.read_shift(4);
|
|
1582
|
+
var _usz = blob.read_shift(4);
|
|
1583
|
+
var namelen = blob.read_shift(2);
|
|
1584
|
+
var efsz = blob.read_shift(2);
|
|
1585
|
+
var name = "";
|
|
1586
|
+
for (var i2 = 0; i2 < namelen; ++i2) name += String.fromCharCode(blob[blob.l++]);
|
|
1587
|
+
if (efsz) {
|
|
1588
|
+
var ef = parse_extra_field(blob.slice(blob.l, blob.l + efsz));
|
|
1589
|
+
if ((ef[21589] || {}).mt) date = ef[21589].mt;
|
|
1590
|
+
if (((EF || {})[21589] || {}).mt) date = EF[21589].mt;
|
|
1591
|
+
}
|
|
1592
|
+
blob.l += efsz;
|
|
1593
|
+
var data = blob.slice(blob.l, blob.l + _csz);
|
|
1594
|
+
switch (meth) {
|
|
1595
|
+
case 8:
|
|
1596
|
+
data = _inflateRawSync(blob, _usz);
|
|
1597
|
+
break;
|
|
1598
|
+
case 0:
|
|
1599
|
+
break;
|
|
1600
|
+
// TODO: scan for magic number
|
|
1601
|
+
default:
|
|
1602
|
+
throw new Error("Unsupported ZIP Compression method " + meth);
|
|
1603
|
+
}
|
|
1604
|
+
var wrn = false;
|
|
1605
|
+
if (flags & 8) {
|
|
1606
|
+
crc32 = blob.read_shift(4);
|
|
1607
|
+
if (crc32 == 134695760) {
|
|
1608
|
+
crc32 = blob.read_shift(4);
|
|
1609
|
+
wrn = true;
|
|
1610
|
+
}
|
|
1611
|
+
_csz = blob.read_shift(4);
|
|
1612
|
+
_usz = blob.read_shift(4);
|
|
1613
|
+
}
|
|
1614
|
+
if (_csz != csz) warn_or_throw(wrn, "Bad compressed size: " + csz + " != " + _csz);
|
|
1615
|
+
if (_usz != usz) warn_or_throw(wrn, "Bad uncompressed size: " + usz + " != " + _usz);
|
|
1616
|
+
var _crc32 = CRC32.buf(data, 0);
|
|
1617
|
+
if (crc32 >> 0 != _crc32 >> 0) warn_or_throw(wrn, "Bad CRC32 checksum: " + crc32 + " != " + _crc32);
|
|
1618
|
+
cfb_add(o, name, data, { unsafe: true, mt: date });
|
|
1619
|
+
}
|
|
1620
|
+
function write_zip(cfb, options) {
|
|
1621
|
+
var _opts = options || {};
|
|
1622
|
+
var out = [], cdirs = [];
|
|
1623
|
+
var o = new_buf(1);
|
|
1624
|
+
var method = _opts.compression ? 8 : 0, flags = 0;
|
|
1625
|
+
var desc = false;
|
|
1626
|
+
if (desc) flags |= 8;
|
|
1627
|
+
var i2 = 0, j = 0;
|
|
1628
|
+
var start_cd = 0, fcnt = 0;
|
|
1629
|
+
var root = cfb.FullPaths[0], fp = root, fi = cfb.FileIndex[0];
|
|
1630
|
+
var crcs = [];
|
|
1631
|
+
var sz_cd = 0;
|
|
1632
|
+
for (i2 = 1; i2 < cfb.FullPaths.length; ++i2) {
|
|
1633
|
+
fp = cfb.FullPaths[i2].slice(root.length);
|
|
1634
|
+
fi = cfb.FileIndex[i2];
|
|
1635
|
+
if (!fi.size || !fi.content || fp == "Sh33tJ5") continue;
|
|
1636
|
+
var start = start_cd;
|
|
1637
|
+
var namebuf = new_buf(fp.length);
|
|
1638
|
+
for (j = 0; j < fp.length; ++j) namebuf.write_shift(1, fp.charCodeAt(j) & 127);
|
|
1639
|
+
namebuf = namebuf.slice(0, namebuf.l);
|
|
1640
|
+
crcs[fcnt] = CRC32.buf(fi.content, 0);
|
|
1641
|
+
var outbuf = fi.content;
|
|
1642
|
+
if (method == 8) outbuf = _deflateRawSync(outbuf);
|
|
1643
|
+
o = new_buf(30);
|
|
1644
|
+
o.write_shift(4, 67324752);
|
|
1645
|
+
o.write_shift(2, 20);
|
|
1646
|
+
o.write_shift(2, flags);
|
|
1647
|
+
o.write_shift(2, method);
|
|
1648
|
+
if (fi.mt) write_dos_date(o, fi.mt);
|
|
1649
|
+
else o.write_shift(4, 0);
|
|
1650
|
+
o.write_shift(-4, flags & 8 ? 0 : crcs[fcnt]);
|
|
1651
|
+
o.write_shift(4, flags & 8 ? 0 : outbuf.length);
|
|
1652
|
+
o.write_shift(4, flags & 8 ? 0 : fi.content.length);
|
|
1653
|
+
o.write_shift(2, namebuf.length);
|
|
1654
|
+
o.write_shift(2, 0);
|
|
1655
|
+
start_cd += o.length;
|
|
1656
|
+
out.push(o);
|
|
1657
|
+
start_cd += namebuf.length;
|
|
1658
|
+
out.push(namebuf);
|
|
1659
|
+
start_cd += outbuf.length;
|
|
1660
|
+
out.push(outbuf);
|
|
1661
|
+
if (flags & 8) {
|
|
1662
|
+
o = new_buf(12);
|
|
1663
|
+
o.write_shift(-4, crcs[fcnt]);
|
|
1664
|
+
o.write_shift(4, outbuf.length);
|
|
1665
|
+
o.write_shift(4, fi.content.length);
|
|
1666
|
+
start_cd += o.l;
|
|
1667
|
+
out.push(o);
|
|
1668
|
+
}
|
|
1669
|
+
o = new_buf(46);
|
|
1670
|
+
o.write_shift(4, 33639248);
|
|
1671
|
+
o.write_shift(2, 0);
|
|
1672
|
+
o.write_shift(2, 20);
|
|
1673
|
+
o.write_shift(2, flags);
|
|
1674
|
+
o.write_shift(2, method);
|
|
1675
|
+
o.write_shift(4, 0);
|
|
1676
|
+
o.write_shift(-4, crcs[fcnt]);
|
|
1677
|
+
o.write_shift(4, outbuf.length);
|
|
1678
|
+
o.write_shift(4, fi.content.length);
|
|
1679
|
+
o.write_shift(2, namebuf.length);
|
|
1680
|
+
o.write_shift(2, 0);
|
|
1681
|
+
o.write_shift(2, 0);
|
|
1682
|
+
o.write_shift(2, 0);
|
|
1683
|
+
o.write_shift(2, 0);
|
|
1684
|
+
o.write_shift(4, 0);
|
|
1685
|
+
o.write_shift(4, start);
|
|
1686
|
+
sz_cd += o.l;
|
|
1687
|
+
cdirs.push(o);
|
|
1688
|
+
sz_cd += namebuf.length;
|
|
1689
|
+
cdirs.push(namebuf);
|
|
1690
|
+
++fcnt;
|
|
1691
|
+
}
|
|
1692
|
+
o = new_buf(22);
|
|
1693
|
+
o.write_shift(4, 101010256);
|
|
1694
|
+
o.write_shift(2, 0);
|
|
1695
|
+
o.write_shift(2, 0);
|
|
1696
|
+
o.write_shift(2, fcnt);
|
|
1697
|
+
o.write_shift(2, fcnt);
|
|
1698
|
+
o.write_shift(4, sz_cd);
|
|
1699
|
+
o.write_shift(4, start_cd);
|
|
1700
|
+
o.write_shift(2, 0);
|
|
1701
|
+
return bconcat([bconcat(out), bconcat(cdirs), o]);
|
|
1702
|
+
}
|
|
1703
|
+
var ContentTypeMap = {
|
|
1704
|
+
"htm": "text/html",
|
|
1705
|
+
"xml": "text/xml",
|
|
1706
|
+
"gif": "image/gif",
|
|
1707
|
+
"jpg": "image/jpeg",
|
|
1708
|
+
"png": "image/png",
|
|
1709
|
+
"mso": "application/x-mso",
|
|
1710
|
+
"thmx": "application/vnd.ms-officetheme",
|
|
1711
|
+
"sh33tj5": "application/octet-stream"
|
|
1712
|
+
};
|
|
1713
|
+
function get_content_type(fi, fp) {
|
|
1714
|
+
if (fi.ctype) return fi.ctype;
|
|
1715
|
+
var ext = fi.name || "", m = ext.match(/\.([^\.]+)$/);
|
|
1716
|
+
if (m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
|
|
1717
|
+
if (fp) {
|
|
1718
|
+
m = (ext = fp).match(/[\.\\]([^\.\\])+$/);
|
|
1719
|
+
if (m && ContentTypeMap[m[1]]) return ContentTypeMap[m[1]];
|
|
1720
|
+
}
|
|
1721
|
+
return "application/octet-stream";
|
|
1722
|
+
}
|
|
1723
|
+
function write_base64_76(bstr) {
|
|
1724
|
+
var data = Base64_encode(bstr);
|
|
1725
|
+
var o = [];
|
|
1726
|
+
for (var i2 = 0; i2 < data.length; i2 += 76) o.push(data.slice(i2, i2 + 76));
|
|
1727
|
+
return o.join("\r\n") + "\r\n";
|
|
1728
|
+
}
|
|
1729
|
+
function write_quoted_printable(text) {
|
|
1730
|
+
var encoded = text.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF=]/g, function(c) {
|
|
1731
|
+
var w = c.charCodeAt(0).toString(16).toUpperCase();
|
|
1732
|
+
return "=" + (w.length == 1 ? "0" + w : w);
|
|
1733
|
+
});
|
|
1734
|
+
encoded = encoded.replace(/ $/mg, "=20").replace(/\t$/mg, "=09");
|
|
1735
|
+
if (encoded.charAt(0) == "\n") encoded = "=0D" + encoded.slice(1);
|
|
1736
|
+
encoded = encoded.replace(/\r(?!\n)/mg, "=0D").replace(/\n\n/mg, "\n=0A").replace(/([^\r\n])\n/mg, "$1=0A");
|
|
1737
|
+
var o = [], split = encoded.split("\r\n");
|
|
1738
|
+
for (var si = 0; si < split.length; ++si) {
|
|
1739
|
+
var str = split[si];
|
|
1740
|
+
if (str.length == 0) {
|
|
1741
|
+
o.push("");
|
|
1742
|
+
continue;
|
|
1743
|
+
}
|
|
1744
|
+
for (var i2 = 0; i2 < str.length; ) {
|
|
1745
|
+
var end = 76;
|
|
1746
|
+
var tmp = str.slice(i2, i2 + end);
|
|
1747
|
+
if (tmp.charAt(end - 1) == "=") end--;
|
|
1748
|
+
else if (tmp.charAt(end - 2) == "=") end -= 2;
|
|
1749
|
+
else if (tmp.charAt(end - 3) == "=") end -= 3;
|
|
1750
|
+
tmp = str.slice(i2, i2 + end);
|
|
1751
|
+
i2 += end;
|
|
1752
|
+
if (i2 < str.length) tmp += "=";
|
|
1753
|
+
o.push(tmp);
|
|
1754
|
+
}
|
|
1755
|
+
}
|
|
1756
|
+
return o.join("\r\n");
|
|
1757
|
+
}
|
|
1758
|
+
function parse_quoted_printable(data) {
|
|
1759
|
+
var o = [];
|
|
1760
|
+
for (var di = 0; di < data.length; ++di) {
|
|
1761
|
+
var line = data[di];
|
|
1762
|
+
while (di <= data.length && line.charAt(line.length - 1) == "=") line = line.slice(0, line.length - 1) + data[++di];
|
|
1763
|
+
o.push(line);
|
|
1764
|
+
}
|
|
1765
|
+
for (var oi = 0; oi < o.length; ++oi) o[oi] = o[oi].replace(/[=][0-9A-Fa-f]{2}/g, function($$) {
|
|
1766
|
+
return String.fromCharCode(parseInt($$.slice(1), 16));
|
|
1767
|
+
});
|
|
1768
|
+
return s2a(o.join("\r\n"));
|
|
1769
|
+
}
|
|
1770
|
+
function parse_mime(cfb, data, root) {
|
|
1771
|
+
var fname = "", cte = "", ctype = "", fdata;
|
|
1772
|
+
var di = 0;
|
|
1773
|
+
for (; di < 10; ++di) {
|
|
1774
|
+
var line = data[di];
|
|
1775
|
+
if (!line || line.match(/^\s*$/)) break;
|
|
1776
|
+
var m = line.match(/^(.*?):\s*([^\s].*)$/);
|
|
1777
|
+
if (m) switch (m[1].toLowerCase()) {
|
|
1778
|
+
case "content-location":
|
|
1779
|
+
fname = m[2].trim();
|
|
1780
|
+
break;
|
|
1781
|
+
case "content-type":
|
|
1782
|
+
ctype = m[2].trim();
|
|
1783
|
+
break;
|
|
1784
|
+
case "content-transfer-encoding":
|
|
1785
|
+
cte = m[2].trim();
|
|
1786
|
+
break;
|
|
1787
|
+
}
|
|
1788
|
+
}
|
|
1789
|
+
++di;
|
|
1790
|
+
switch (cte.toLowerCase()) {
|
|
1791
|
+
case "base64":
|
|
1792
|
+
fdata = s2a(Base64_decode(data.slice(di).join("")));
|
|
1793
|
+
break;
|
|
1794
|
+
case "quoted-printable":
|
|
1795
|
+
fdata = parse_quoted_printable(data.slice(di));
|
|
1796
|
+
break;
|
|
1797
|
+
default:
|
|
1798
|
+
throw new Error("Unsupported Content-Transfer-Encoding " + cte);
|
|
1799
|
+
}
|
|
1800
|
+
var file = cfb_add(cfb, fname.slice(root.length), fdata, { unsafe: true });
|
|
1801
|
+
if (ctype) file.ctype = ctype;
|
|
1802
|
+
}
|
|
1803
|
+
function parse_mad(file, options) {
|
|
1804
|
+
if (a2s(file.slice(0, 13)).toLowerCase() != "mime-version:") throw new Error("Unsupported MAD header");
|
|
1805
|
+
var root = options && options.root || "";
|
|
1806
|
+
var data = (has_buf && Buffer.isBuffer(file) ? file.toString("binary") : a2s(file)).split("\r\n");
|
|
1807
|
+
var di = 0, row = "";
|
|
1808
|
+
for (di = 0; di < data.length; ++di) {
|
|
1809
|
+
row = data[di];
|
|
1810
|
+
if (!/^Content-Location:/i.test(row)) continue;
|
|
1811
|
+
row = row.slice(row.indexOf("file"));
|
|
1812
|
+
if (!root) root = row.slice(0, row.lastIndexOf("/") + 1);
|
|
1813
|
+
if (row.slice(0, root.length) == root) continue;
|
|
1814
|
+
while (root.length > 0) {
|
|
1815
|
+
root = root.slice(0, root.length - 1);
|
|
1816
|
+
root = root.slice(0, root.lastIndexOf("/") + 1);
|
|
1817
|
+
if (row.slice(0, root.length) == root) break;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1820
|
+
var mboundary = (data[1] || "").match(/boundary="(.*?)"/);
|
|
1821
|
+
if (!mboundary) throw new Error("MAD cannot find boundary");
|
|
1822
|
+
var boundary = "--" + (mboundary[1] || "");
|
|
1823
|
+
var FileIndex = [], FullPaths = [];
|
|
1824
|
+
var o = {
|
|
1825
|
+
FileIndex,
|
|
1826
|
+
FullPaths
|
|
1827
|
+
};
|
|
1828
|
+
init_cfb(o);
|
|
1829
|
+
var start_di, fcnt = 0;
|
|
1830
|
+
for (di = 0; di < data.length; ++di) {
|
|
1831
|
+
var line = data[di];
|
|
1832
|
+
if (line !== boundary && line !== boundary + "--") continue;
|
|
1833
|
+
if (fcnt++) parse_mime(o, data.slice(start_di, di), root);
|
|
1834
|
+
start_di = di;
|
|
1835
|
+
}
|
|
1836
|
+
return o;
|
|
1837
|
+
}
|
|
1838
|
+
function write_mad(cfb, options) {
|
|
1839
|
+
var opts = options || {};
|
|
1840
|
+
var boundary = opts.boundary || "SheetJS";
|
|
1841
|
+
boundary = "------=" + boundary;
|
|
1842
|
+
var out = [
|
|
1843
|
+
"MIME-Version: 1.0",
|
|
1844
|
+
'Content-Type: multipart/related; boundary="' + boundary.slice(2) + '"',
|
|
1845
|
+
"",
|
|
1846
|
+
"",
|
|
1847
|
+
""
|
|
1848
|
+
];
|
|
1849
|
+
var root = cfb.FullPaths[0], fp = root, fi = cfb.FileIndex[0];
|
|
1850
|
+
for (var i2 = 1; i2 < cfb.FullPaths.length; ++i2) {
|
|
1851
|
+
fp = cfb.FullPaths[i2].slice(root.length);
|
|
1852
|
+
fi = cfb.FileIndex[i2];
|
|
1853
|
+
if (!fi.size || !fi.content || fp == "Sh33tJ5") continue;
|
|
1854
|
+
fp = fp.replace(/[\x00-\x08\x0B\x0C\x0E-\x1F\x7E-\xFF]/g, function(c) {
|
|
1855
|
+
return "_x" + c.charCodeAt(0).toString(16) + "_";
|
|
1856
|
+
}).replace(/[\u0080-\uFFFF]/g, function(u) {
|
|
1857
|
+
return "_u" + u.charCodeAt(0).toString(16) + "_";
|
|
1858
|
+
});
|
|
1859
|
+
var ca = fi.content;
|
|
1860
|
+
var cstr = has_buf && Buffer.isBuffer(ca) ? ca.toString("binary") : a2s(ca);
|
|
1861
|
+
var dispcnt = 0, L = Math.min(1024, cstr.length), cc = 0;
|
|
1862
|
+
for (var csl = 0; csl <= L; ++csl) if ((cc = cstr.charCodeAt(csl)) >= 32 && cc < 128) ++dispcnt;
|
|
1863
|
+
var qp = dispcnt >= L * 4 / 5;
|
|
1864
|
+
out.push(boundary);
|
|
1865
|
+
out.push("Content-Location: " + (opts.root || "file:///C:/SheetJS/") + fp);
|
|
1866
|
+
out.push("Content-Transfer-Encoding: " + (qp ? "quoted-printable" : "base64"));
|
|
1867
|
+
out.push("Content-Type: " + get_content_type(fi, fp));
|
|
1868
|
+
out.push("");
|
|
1869
|
+
out.push(qp ? write_quoted_printable(cstr) : write_base64_76(cstr));
|
|
1870
|
+
}
|
|
1871
|
+
out.push(boundary + "--\r\n");
|
|
1872
|
+
return out.join("\r\n");
|
|
1873
|
+
}
|
|
1874
|
+
function cfb_new(opts) {
|
|
1875
|
+
var o = {};
|
|
1876
|
+
init_cfb(o, opts);
|
|
1877
|
+
return o;
|
|
1878
|
+
}
|
|
1879
|
+
function cfb_add(cfb, name, content, opts) {
|
|
1880
|
+
var unsafe = opts && opts.unsafe;
|
|
1881
|
+
if (!unsafe) init_cfb(cfb);
|
|
1882
|
+
var file = !unsafe && CFB2.find(cfb, name);
|
|
1883
|
+
if (!file) {
|
|
1884
|
+
var fpath = cfb.FullPaths[0];
|
|
1885
|
+
if (name.slice(0, fpath.length) == fpath) fpath = name;
|
|
1886
|
+
else {
|
|
1887
|
+
if (fpath.slice(-1) != "/") fpath += "/";
|
|
1888
|
+
fpath = (fpath + name).replace("//", "/");
|
|
1889
|
+
}
|
|
1890
|
+
file = { name: filename(name), type: 2 };
|
|
1891
|
+
cfb.FileIndex.push(file);
|
|
1892
|
+
cfb.FullPaths.push(fpath);
|
|
1893
|
+
if (!unsafe) CFB2.utils.cfb_gc(cfb);
|
|
1894
|
+
}
|
|
1895
|
+
file.content = content;
|
|
1896
|
+
file.size = content ? content.length : 0;
|
|
1897
|
+
if (opts) {
|
|
1898
|
+
if (opts.CLSID) file.clsid = opts.CLSID;
|
|
1899
|
+
if (opts.mt) file.mt = opts.mt;
|
|
1900
|
+
if (opts.ct) file.ct = opts.ct;
|
|
1901
|
+
}
|
|
1902
|
+
return file;
|
|
1903
|
+
}
|
|
1904
|
+
function cfb_del(cfb, name) {
|
|
1905
|
+
init_cfb(cfb);
|
|
1906
|
+
var file = CFB2.find(cfb, name);
|
|
1907
|
+
if (file) {
|
|
1908
|
+
for (var j = 0; j < cfb.FileIndex.length; ++j) if (cfb.FileIndex[j] == file) {
|
|
1909
|
+
cfb.FileIndex.splice(j, 1);
|
|
1910
|
+
cfb.FullPaths.splice(j, 1);
|
|
1911
|
+
return true;
|
|
1912
|
+
}
|
|
1913
|
+
}
|
|
1914
|
+
return false;
|
|
1915
|
+
}
|
|
1916
|
+
function cfb_mov(cfb, old_name, new_name) {
|
|
1917
|
+
init_cfb(cfb);
|
|
1918
|
+
var file = CFB2.find(cfb, old_name);
|
|
1919
|
+
if (file) {
|
|
1920
|
+
for (var j = 0; j < cfb.FileIndex.length; ++j) if (cfb.FileIndex[j] == file) {
|
|
1921
|
+
cfb.FileIndex[j].name = filename(new_name);
|
|
1922
|
+
cfb.FullPaths[j] = new_name;
|
|
1923
|
+
return true;
|
|
1924
|
+
}
|
|
1925
|
+
}
|
|
1926
|
+
return false;
|
|
1927
|
+
}
|
|
1928
|
+
function cfb_gc(cfb) {
|
|
1929
|
+
rebuild_cfb(cfb, true);
|
|
1930
|
+
}
|
|
1931
|
+
exports3.find = find2;
|
|
1932
|
+
exports3.read = read;
|
|
1933
|
+
exports3.parse = parse3;
|
|
1934
|
+
exports3.write = write;
|
|
1935
|
+
exports3.writeFile = write_file;
|
|
1936
|
+
exports3.utils = {
|
|
1937
|
+
cfb_new,
|
|
1938
|
+
cfb_add,
|
|
1939
|
+
cfb_del,
|
|
1940
|
+
cfb_mov,
|
|
1941
|
+
cfb_gc,
|
|
1942
|
+
ReadShift,
|
|
1943
|
+
CheckField,
|
|
1944
|
+
prep_blob,
|
|
1945
|
+
bconcat,
|
|
1946
|
+
use_zlib,
|
|
1947
|
+
_deflateRaw: _deflate,
|
|
1948
|
+
_inflateRaw: _inflate,
|
|
1949
|
+
consts
|
|
1950
|
+
};
|
|
1951
|
+
return exports3;
|
|
1952
|
+
})();
|
|
1953
|
+
if (typeof require !== "undefined" && typeof module2 !== "undefined" && typeof DO_NOT_EXPORT_CFB === "undefined") {
|
|
1954
|
+
module2.exports = CFB2;
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
});
|
|
1958
|
+
|
|
1959
|
+
// src/ocr/auto-detect.ts
|
|
1960
|
+
function detectAvailableOcr() {
|
|
1961
|
+
for (const cli of CLI_PRIORITY) {
|
|
1962
|
+
if (isCliInstalled(cli)) return cli;
|
|
1963
|
+
}
|
|
1964
|
+
return "tesseract";
|
|
1965
|
+
}
|
|
1966
|
+
function isCliInstalled(name) {
|
|
1967
|
+
try {
|
|
1968
|
+
const cmd = process.platform === "win32" ? "where" : "which";
|
|
1969
|
+
(0, import_child_process.execSync)(`${cmd} ${name}`, { stdio: "ignore", timeout: 3e3 });
|
|
1970
|
+
return true;
|
|
1971
|
+
} catch {
|
|
1972
|
+
return false;
|
|
1973
|
+
}
|
|
1974
|
+
}
|
|
1975
|
+
function validateOcrMode(mode) {
|
|
1976
|
+
if (mode === "auto" || mode === "off" || mode === "tesseract") return;
|
|
1977
|
+
if (!isCliInstalled(mode)) {
|
|
1978
|
+
throw new Error(`'${mode}' CLI\uAC00 \uC124\uCE58\uB418\uC9C0 \uC54A\uC558\uC2B5\uB2C8\uB2E4.
|
|
1979
|
+
${getInstallGuide(mode)}`);
|
|
1980
|
+
}
|
|
1981
|
+
}
|
|
1982
|
+
function getInstallGuide(mode) {
|
|
1983
|
+
const guides = {
|
|
1984
|
+
gemini: "\uC124\uCE58: https://ai.google.dev/gemini-api/docs/cli",
|
|
1985
|
+
claude: "\uC124\uCE58: npm install -g @anthropic-ai/claude-code \uB610\uB294 https://claude.ai/code",
|
|
1986
|
+
codex: "\uC124\uCE58: npm install -g @openai/codex \uB610\uB294 https://github.com/openai/codex",
|
|
1987
|
+
ollama: "\uC124\uCE58: brew install ollama \uB610\uB294 https://ollama.com/download"
|
|
1988
|
+
};
|
|
1989
|
+
return guides[mode] || `'${mode}'\uC744(\uB97C) \uC124\uCE58\uD574\uC8FC\uC138\uC694.`;
|
|
1990
|
+
}
|
|
1991
|
+
function getTesseractFallbackMessage() {
|
|
1992
|
+
return [
|
|
1993
|
+
"\uC124\uCE58\uB41C AI CLI\uAC00 \uC5C6\uC5B4 \uB0B4\uC7A5 tesseract.js\uB85C OCR\uC744 \uC218\uD589\uD569\uB2C8\uB2E4.",
|
|
1994
|
+
"\uB354 \uB098\uC740 \uD488\uC9C8(\uD14C\uC774\uBE14/\uD5E4\uB529 \uAD6C\uC870 \uBCF4\uC874)\uC744 \uC704\uD574 AI CLI \uC124\uCE58\uB97C \uAD8C\uC7A5\uD569\uB2C8\uB2E4:",
|
|
1995
|
+
"",
|
|
1996
|
+
" [\uAD8C\uC7A5] Gemini CLI: https://ai.google.dev/gemini-api/docs/cli",
|
|
1997
|
+
" Claude CLI: npm install -g @anthropic-ai/claude-code",
|
|
1998
|
+
" Codex CLI: npm install -g @openai/codex",
|
|
1999
|
+
" Ollama: brew install ollama (+ ollama pull gemma4:27b)"
|
|
2000
|
+
].join("\n");
|
|
2001
|
+
}
|
|
2002
|
+
var import_child_process, CLI_PRIORITY;
|
|
2003
|
+
var init_auto_detect = __esm({
|
|
2004
|
+
"src/ocr/auto-detect.ts"() {
|
|
2005
|
+
"use strict";
|
|
2006
|
+
import_child_process = require("child_process");
|
|
2007
|
+
CLI_PRIORITY = ["gemini", "claude", "codex", "ollama"];
|
|
2008
|
+
}
|
|
2009
|
+
});
|
|
2010
|
+
|
|
2011
|
+
// src/ocr/cli-provider.ts
|
|
2012
|
+
function getTempDir() {
|
|
2013
|
+
if (!_tempDir) _tempDir = (0, import_fs.mkdtempSync)((0, import_path.join)((0, import_os.tmpdir)(), "kordoc-ocr-"));
|
|
2014
|
+
return _tempDir;
|
|
2015
|
+
}
|
|
2016
|
+
function createCliOcrProvider(mode) {
|
|
2017
|
+
return async (pageImage, pageNumber) => {
|
|
2018
|
+
const tempPath = (0, import_path.join)(getTempDir(), `page-${pageNumber}.png`);
|
|
2019
|
+
try {
|
|
2020
|
+
(0, import_fs.writeFileSync)(tempPath, pageImage);
|
|
2021
|
+
let output;
|
|
2022
|
+
if (mode === "ollama") {
|
|
2023
|
+
output = await callOllamaApi(tempPath);
|
|
2024
|
+
} else {
|
|
2025
|
+
output = callCli(mode, tempPath);
|
|
2026
|
+
}
|
|
2027
|
+
return { markdown: stripCodeFence(output.trim()) };
|
|
2028
|
+
} finally {
|
|
2029
|
+
try {
|
|
2030
|
+
(0, import_fs.unlinkSync)(tempPath);
|
|
2031
|
+
} catch {
|
|
2032
|
+
}
|
|
2033
|
+
}
|
|
2034
|
+
};
|
|
2035
|
+
}
|
|
2036
|
+
function callCli(mode, imagePath) {
|
|
2037
|
+
const args = buildCliArgs(mode, imagePath);
|
|
2038
|
+
const result = (0, import_child_process2.spawnSync)(mode === "codex" ? "codex" : mode, args, {
|
|
2039
|
+
encoding: "utf-8",
|
|
2040
|
+
timeout: 6e4,
|
|
2041
|
+
maxBuffer: 10 * 1024 * 1024
|
|
2042
|
+
});
|
|
2043
|
+
if (result.error) {
|
|
2044
|
+
throw new Error(`${mode} CLI \uC2E4\uD589 \uC2E4\uD328: ${result.error.message}`);
|
|
2045
|
+
}
|
|
2046
|
+
if (result.status !== 0) {
|
|
2047
|
+
const errMsg = result.stderr?.trim() || `exit code ${result.status}`;
|
|
2048
|
+
throw new Error(`${mode} OCR \uC2E4\uD328: ${errMsg}`);
|
|
2049
|
+
}
|
|
2050
|
+
return result.stdout || "";
|
|
2051
|
+
}
|
|
2052
|
+
function buildCliArgs(mode, imagePath) {
|
|
2053
|
+
const promptWithImage = `${OCR_PROMPT}
|
|
2054
|
+
|
|
2055
|
+
\uC774\uBBF8\uC9C0: @${imagePath}`;
|
|
2056
|
+
const promptOnly = OCR_PROMPT;
|
|
2057
|
+
switch (mode) {
|
|
2058
|
+
case "gemini":
|
|
2059
|
+
return ["--prompt", promptWithImage, "--yolo"];
|
|
2060
|
+
case "claude":
|
|
2061
|
+
return ["--print", promptWithImage];
|
|
2062
|
+
case "codex":
|
|
2063
|
+
return ["exec", "--image", imagePath, promptOnly];
|
|
2064
|
+
default:
|
|
2065
|
+
throw new Error(`\uC9C0\uC6D0\uD558\uC9C0 \uC54A\uB294 CLI: ${mode}`);
|
|
2066
|
+
}
|
|
2067
|
+
}
|
|
2068
|
+
async function callOllamaApi(imagePath) {
|
|
2069
|
+
const { readFileSync } = await import("fs");
|
|
2070
|
+
const imageBase64 = readFileSync(imagePath).toString("base64");
|
|
2071
|
+
const model = process.env.KORDOC_OLLAMA_MODEL || "gemma4:27b";
|
|
2072
|
+
const host = process.env.KORDOC_OLLAMA_HOST || "http://localhost:11434";
|
|
2073
|
+
const response = await fetch(`${host}/api/chat`, {
|
|
2074
|
+
method: "POST",
|
|
2075
|
+
headers: { "Content-Type": "application/json" },
|
|
2076
|
+
body: JSON.stringify({
|
|
2077
|
+
model,
|
|
2078
|
+
messages: [{
|
|
2079
|
+
role: "user",
|
|
2080
|
+
content: OCR_PROMPT,
|
|
2081
|
+
images: [imageBase64]
|
|
2082
|
+
}],
|
|
2083
|
+
stream: false
|
|
2084
|
+
}),
|
|
2085
|
+
signal: AbortSignal.timeout(6e4)
|
|
2086
|
+
});
|
|
2087
|
+
if (!response.ok) {
|
|
2088
|
+
throw new Error(`Ollama API \uC624\uB958: ${response.status} ${response.statusText}`);
|
|
2089
|
+
}
|
|
2090
|
+
const data = await response.json();
|
|
2091
|
+
return data.message?.content || "";
|
|
2092
|
+
}
|
|
2093
|
+
function stripCodeFence(text) {
|
|
2094
|
+
const match = text.match(/^```(?:markdown|md)?\s*\n([\s\S]*?)\n```\s*$/m);
|
|
2095
|
+
return match ? match[1].trim() : text;
|
|
2096
|
+
}
|
|
2097
|
+
var import_child_process2, import_fs, import_path, import_os, OCR_PROMPT, _tempDir;
|
|
2098
|
+
var init_cli_provider = __esm({
|
|
2099
|
+
"src/ocr/cli-provider.ts"() {
|
|
2100
|
+
"use strict";
|
|
2101
|
+
import_child_process2 = require("child_process");
|
|
2102
|
+
import_fs = require("fs");
|
|
2103
|
+
import_path = require("path");
|
|
2104
|
+
import_os = require("os");
|
|
2105
|
+
OCR_PROMPT = "\uC774 PDF \uD398\uC774\uC9C0 \uC774\uBBF8\uC9C0\uC5D0\uC11C \uD14D\uC2A4\uD2B8\uC640 \uD14C\uC774\uBE14\uC744 \uCD94\uCD9C\uD558\uC5EC \uC21C\uC218 Markdown\uC73C\uB85C \uBCC0\uD658\uD558\uC138\uC694.\n\uADDC\uCE59:\n- \uD14C\uC774\uBE14\uC740 Markdown \uD14C\uC774\uBE14 \uBB38\uBC95 \uC0AC\uC6A9 (| \uAD6C\uBD84, |---|---| \uD5E4\uB354 \uAD6C\uBD84\uC120 \uD3EC\uD568)\n- \uBCD1\uD569\uB41C \uC140\uC740 \uD574\uB2F9 \uC704\uCE58\uC5D0 \uB0B4\uC6A9 \uAE30\uC7AC\n- \uD5E4\uB529\uC740 \uAE00\uC790 \uD06C\uAE30\uC5D0 \uB530\uB77C ## ~ ###### \uC0AC\uC6A9\n- \uB9AC\uC2A4\uD2B8\uB294 - \uB610\uB294 1. \uC0AC\uC6A9\n- \uC774\uBBF8\uC9C0, \uB3C4\uD615 \uB4F1 \uBE44\uD14D\uC2A4\uD2B8 \uC694\uC18C\uB294 \uBB34\uC2DC\n- \uC6D0\uBB38\uC758 \uC77D\uAE30 \uC21C\uC11C\uC640 \uAD6C\uC870\uB97C \uC720\uC9C0\n- ```\uB85C \uAC10\uC2F8\uC9C0 \uB9D0\uACE0 \uC21C\uC218 Markdown\uB9CC \uCD9C\uB825";
|
|
2106
|
+
_tempDir = null;
|
|
2107
|
+
}
|
|
2108
|
+
});
|
|
2109
|
+
|
|
2110
|
+
// src/ocr/tesseract-provider.ts
|
|
2111
|
+
var tesseract_provider_exports = {};
|
|
2112
|
+
__export(tesseract_provider_exports, {
|
|
2113
|
+
createTesseractProvider: () => createTesseractProvider
|
|
2114
|
+
});
|
|
2115
|
+
async function createTesseractProvider() {
|
|
2116
|
+
const worker = await (0, import_tesseract.createWorker)("kor+eng");
|
|
2117
|
+
let terminated = false;
|
|
2118
|
+
const provider = async (pageImage, _pageNumber, _mimeType) => {
|
|
2119
|
+
const { data } = await worker.recognize(pageImage);
|
|
2120
|
+
return data.text;
|
|
2121
|
+
};
|
|
2122
|
+
provider.terminate = async () => {
|
|
2123
|
+
if (!terminated) {
|
|
2124
|
+
await worker.terminate();
|
|
2125
|
+
terminated = true;
|
|
2126
|
+
}
|
|
2127
|
+
};
|
|
2128
|
+
return provider;
|
|
2129
|
+
}
|
|
2130
|
+
var import_tesseract;
|
|
2131
|
+
var init_tesseract_provider = __esm({
|
|
2132
|
+
"src/ocr/tesseract-provider.ts"() {
|
|
2133
|
+
"use strict";
|
|
2134
|
+
import_tesseract = require("tesseract.js");
|
|
2135
|
+
}
|
|
2136
|
+
});
|
|
2137
|
+
|
|
2138
|
+
// src/ocr/resolve.ts
|
|
2139
|
+
var resolve_exports = {};
|
|
2140
|
+
__export(resolve_exports, {
|
|
2141
|
+
resolveOcrProvider: () => resolveOcrProvider
|
|
2142
|
+
});
|
|
2143
|
+
async function resolveOcrProvider(mode, warnings) {
|
|
2144
|
+
if (mode === "off") {
|
|
2145
|
+
throw new Error("OCR\uC774 \uBE44\uD65C\uC131\uD654\uB418\uC5B4 \uC788\uC2B5\uB2C8\uB2E4 (--ocr off).");
|
|
2146
|
+
}
|
|
2147
|
+
if (mode !== "auto") {
|
|
2148
|
+
validateOcrMode(mode);
|
|
2149
|
+
if (mode === "tesseract") {
|
|
2150
|
+
const { createTesseractProvider: createTesseractProvider2 } = await Promise.resolve().then(() => (init_tesseract_provider(), tesseract_provider_exports));
|
|
2151
|
+
return createTesseractProvider2();
|
|
2152
|
+
}
|
|
2153
|
+
return createCliOcrProvider(mode);
|
|
2154
|
+
}
|
|
2155
|
+
const detected = detectAvailableOcr();
|
|
2156
|
+
if (detected !== "gemini") {
|
|
2157
|
+
if (detected === "tesseract") {
|
|
2158
|
+
warnings?.push({
|
|
2159
|
+
message: getTesseractFallbackMessage(),
|
|
2160
|
+
code: "OCR_CLI_FALLBACK"
|
|
2161
|
+
});
|
|
2162
|
+
} else {
|
|
2163
|
+
warnings?.push({
|
|
2164
|
+
message: `OCR: '${detected}' \uC0AC\uC6A9 \uC911 (gemini CLI\uAC00 \uC5C6\uC5B4 fallback). \uB354 \uB098\uC740 \uD488\uC9C8\uC744 \uC704\uD574 gemini CLI \uC124\uCE58\uB97C \uAD8C\uC7A5\uD569\uB2C8\uB2E4.`,
|
|
2165
|
+
code: "OCR_CLI_FALLBACK"
|
|
2166
|
+
});
|
|
2167
|
+
}
|
|
2168
|
+
}
|
|
2169
|
+
if (detected === "tesseract") {
|
|
2170
|
+
const { createTesseractProvider: createTesseractProvider2 } = await Promise.resolve().then(() => (init_tesseract_provider(), tesseract_provider_exports));
|
|
2171
|
+
return createTesseractProvider2();
|
|
2172
|
+
}
|
|
2173
|
+
return createCliOcrProvider(detected);
|
|
2174
|
+
}
|
|
2175
|
+
var init_resolve = __esm({
|
|
2176
|
+
"src/ocr/resolve.ts"() {
|
|
2177
|
+
"use strict";
|
|
2178
|
+
init_auto_detect();
|
|
2179
|
+
init_cli_provider();
|
|
2180
|
+
}
|
|
2181
|
+
});
|
|
2182
|
+
|
|
2183
|
+
// src/ocr/markdown-to-blocks.ts
|
|
2184
|
+
function markdownToBlocks(markdown, pageNumber) {
|
|
2185
|
+
const blocks = [];
|
|
2186
|
+
const lines = markdown.split("\n");
|
|
2187
|
+
let i = 0;
|
|
2188
|
+
while (i < lines.length) {
|
|
2189
|
+
const line = lines[i];
|
|
2190
|
+
if (line.trim() === "") {
|
|
2191
|
+
i++;
|
|
2192
|
+
continue;
|
|
2193
|
+
}
|
|
2194
|
+
const headingMatch = line.match(/^(#{1,6})\s+(.+)$/);
|
|
2195
|
+
if (headingMatch) {
|
|
2196
|
+
blocks.push({
|
|
2197
|
+
type: "heading",
|
|
2198
|
+
level: headingMatch[1].length,
|
|
2199
|
+
text: headingMatch[2].trim(),
|
|
2200
|
+
pageNumber
|
|
2201
|
+
});
|
|
2202
|
+
i++;
|
|
2203
|
+
continue;
|
|
2204
|
+
}
|
|
2205
|
+
if (/^[-*_]{3,}\s*$/.test(line.trim())) {
|
|
2206
|
+
blocks.push({ type: "separator", pageNumber });
|
|
2207
|
+
i++;
|
|
2208
|
+
continue;
|
|
2209
|
+
}
|
|
2210
|
+
if (line.trim().startsWith("|")) {
|
|
2211
|
+
const tableLines = [];
|
|
2212
|
+
while (i < lines.length && lines[i].trim().startsWith("|")) {
|
|
2213
|
+
tableLines.push(lines[i]);
|
|
2214
|
+
i++;
|
|
2215
|
+
}
|
|
2216
|
+
const table = parseMarkdownTable(tableLines);
|
|
2217
|
+
if (table) {
|
|
2218
|
+
blocks.push({ type: "table", table, pageNumber });
|
|
2219
|
+
}
|
|
2220
|
+
continue;
|
|
2221
|
+
}
|
|
2222
|
+
const ulMatch = line.match(/^(\s*)[-*+]\s+(.+)$/);
|
|
2223
|
+
if (ulMatch) {
|
|
2224
|
+
blocks.push({
|
|
2225
|
+
type: "list",
|
|
2226
|
+
listType: "unordered",
|
|
2227
|
+
text: ulMatch[2].trim(),
|
|
2228
|
+
pageNumber
|
|
2229
|
+
});
|
|
2230
|
+
i++;
|
|
2231
|
+
continue;
|
|
2232
|
+
}
|
|
2233
|
+
const olMatch = line.match(/^(\s*)\d+\.\s+(.+)$/);
|
|
2234
|
+
if (olMatch) {
|
|
2235
|
+
blocks.push({
|
|
2236
|
+
type: "list",
|
|
2237
|
+
listType: "ordered",
|
|
2238
|
+
text: olMatch[2].trim(),
|
|
2239
|
+
pageNumber
|
|
2240
|
+
});
|
|
2241
|
+
i++;
|
|
2242
|
+
continue;
|
|
2243
|
+
}
|
|
2244
|
+
const paraLines = [];
|
|
2245
|
+
while (i < lines.length && lines[i].trim() !== "" && !isStructuralLine(lines[i])) {
|
|
2246
|
+
paraLines.push(lines[i].trim());
|
|
2247
|
+
i++;
|
|
2248
|
+
}
|
|
2249
|
+
if (paraLines.length > 0) {
|
|
2250
|
+
blocks.push({
|
|
2251
|
+
type: "paragraph",
|
|
2252
|
+
text: paraLines.join("\n"),
|
|
2253
|
+
pageNumber
|
|
2254
|
+
});
|
|
2255
|
+
}
|
|
47
2256
|
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
2257
|
+
return blocks;
|
|
2258
|
+
}
|
|
2259
|
+
function isStructuralLine(line) {
|
|
2260
|
+
if (/^#{1,6}\s+/.test(line)) return true;
|
|
2261
|
+
if (line.trim().startsWith("|")) return true;
|
|
2262
|
+
if (/^[-*_]{3,}\s*$/.test(line.trim())) return true;
|
|
2263
|
+
if (/^\s*[-*+]\s+/.test(line)) return true;
|
|
2264
|
+
if (/^\s*\d+\.\s+/.test(line)) return true;
|
|
2265
|
+
return false;
|
|
2266
|
+
}
|
|
2267
|
+
function parseMarkdownTable(lines) {
|
|
2268
|
+
const hasSeparator = lines.some((line) => /^\|[\s:|-]+\|$/.test(line.trim()));
|
|
2269
|
+
const rows = [];
|
|
2270
|
+
let maxCols = 0;
|
|
2271
|
+
for (const line of lines) {
|
|
2272
|
+
if (/^\|\s*:?-+:?\s*(\|\s*:?-+:?\s*)+\|?\s*$/.test(line.trim())) continue;
|
|
2273
|
+
const parts = line.split("|");
|
|
2274
|
+
const cells = parts.slice(1, parts[parts.length - 1].trim() === "" ? -1 : void 0).map((cell) => ({
|
|
2275
|
+
text: cell.trim(),
|
|
2276
|
+
colSpan: 1,
|
|
2277
|
+
rowSpan: 1
|
|
2278
|
+
}));
|
|
2279
|
+
if (cells.length > 0) {
|
|
2280
|
+
rows.push(cells);
|
|
2281
|
+
maxCols = Math.max(maxCols, cells.length);
|
|
61
2282
|
}
|
|
62
2283
|
}
|
|
63
|
-
return
|
|
2284
|
+
if (rows.length === 0) return null;
|
|
2285
|
+
for (const row of rows) {
|
|
2286
|
+
while (row.length < maxCols) {
|
|
2287
|
+
row.push({ text: "", colSpan: 1, rowSpan: 1 });
|
|
2288
|
+
}
|
|
2289
|
+
}
|
|
2290
|
+
return {
|
|
2291
|
+
rows: rows.length,
|
|
2292
|
+
cols: maxCols,
|
|
2293
|
+
cells: rows,
|
|
2294
|
+
hasHeader: hasSeparator && rows.length > 1
|
|
2295
|
+
};
|
|
64
2296
|
}
|
|
65
|
-
var
|
|
66
|
-
"src/
|
|
2297
|
+
var init_markdown_to_blocks = __esm({
|
|
2298
|
+
"src/ocr/markdown-to-blocks.ts"() {
|
|
67
2299
|
"use strict";
|
|
68
2300
|
}
|
|
69
2301
|
});
|
|
@@ -73,18 +2305,31 @@ var provider_exports = {};
|
|
|
73
2305
|
__export(provider_exports, {
|
|
74
2306
|
ocrPages: () => ocrPages
|
|
75
2307
|
});
|
|
76
|
-
async function ocrPages(doc, provider, pageFilter, effectivePageCount) {
|
|
2308
|
+
async function ocrPages(doc, provider, pageFilter, effectivePageCount, warnings) {
|
|
77
2309
|
const blocks = [];
|
|
78
2310
|
for (let i = 1; i <= effectivePageCount; i++) {
|
|
79
2311
|
if (pageFilter && !pageFilter.has(i)) continue;
|
|
80
2312
|
const page = await doc.getPage(i);
|
|
81
2313
|
try {
|
|
82
2314
|
const imageData = await renderPageToPng(page);
|
|
83
|
-
const
|
|
84
|
-
if (
|
|
85
|
-
|
|
2315
|
+
const result = await provider(imageData, i, "image/png");
|
|
2316
|
+
if (typeof result === "string") {
|
|
2317
|
+
if (result.trim()) {
|
|
2318
|
+
blocks.push({ type: "paragraph", text: result.trim(), pageNumber: i });
|
|
2319
|
+
}
|
|
2320
|
+
} else if (result && typeof result === "object" && "markdown" in result) {
|
|
2321
|
+
const structured = result;
|
|
2322
|
+
if (structured.markdown.trim()) {
|
|
2323
|
+
const pageBlocks = markdownToBlocks(structured.markdown, i);
|
|
2324
|
+
for (const b of pageBlocks) blocks.push(b);
|
|
2325
|
+
}
|
|
86
2326
|
}
|
|
87
|
-
} catch {
|
|
2327
|
+
} catch (err) {
|
|
2328
|
+
warnings?.push({
|
|
2329
|
+
page: i,
|
|
2330
|
+
message: `\uD398\uC774\uC9C0 ${i} OCR \uC2E4\uD328: ${err instanceof Error ? err.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958"}`,
|
|
2331
|
+
code: "OCR_PAGE_FAILED"
|
|
2332
|
+
});
|
|
88
2333
|
}
|
|
89
2334
|
}
|
|
90
2335
|
return blocks;
|
|
@@ -107,6 +2352,7 @@ async function renderPageToPng(page) {
|
|
|
107
2352
|
var init_provider = __esm({
|
|
108
2353
|
"src/ocr/provider.ts"() {
|
|
109
2354
|
"use strict";
|
|
2355
|
+
init_markdown_to_blocks();
|
|
110
2356
|
}
|
|
111
2357
|
});
|
|
112
2358
|
|
|
@@ -125,7 +2371,8 @@ __export(index_exports, {
|
|
|
125
2371
|
isPdfFile: () => isPdfFile,
|
|
126
2372
|
isZipFile: () => isZipFile,
|
|
127
2373
|
markdownToHwpx: () => markdownToHwpx,
|
|
128
|
-
|
|
2374
|
+
markdownToXlsx: () => markdownToXlsx,
|
|
2375
|
+
parse: () => parse2,
|
|
129
2376
|
parseDocx: () => parseDocx,
|
|
130
2377
|
parseHwp: () => parseHwp,
|
|
131
2378
|
parseHwpx: () => parseHwpx,
|
|
@@ -181,7 +2428,7 @@ var import_jszip2 = __toESM(require("jszip"), 1);
|
|
|
181
2428
|
var import_xmldom = require("@xmldom/xmldom");
|
|
182
2429
|
|
|
183
2430
|
// src/utils.ts
|
|
184
|
-
var VERSION = true ? "2.1
|
|
2431
|
+
var VERSION = true ? "2.2.1" : "0.0.0-dev";
|
|
185
2432
|
function toArrayBuffer(buf) {
|
|
186
2433
|
if (buf.byteOffset === 0 && buf.byteLength === buf.buffer.byteLength) {
|
|
187
2434
|
return buf.buffer;
|
|
@@ -514,7 +2761,7 @@ var HEADING_RATIO_H3 = 1.15;
|
|
|
514
2761
|
// src/hwpx/parser.ts
|
|
515
2762
|
init_page_range();
|
|
516
2763
|
var MAX_DECOMPRESS_SIZE = 500 * 1024 * 1024;
|
|
517
|
-
var MAX_ZIP_ENTRIES =
|
|
2764
|
+
var MAX_ZIP_ENTRIES = 2e3;
|
|
518
2765
|
function clampSpan(val, max) {
|
|
519
2766
|
return Math.max(1, Math.min(val, max));
|
|
520
2767
|
}
|
|
@@ -673,6 +2920,16 @@ function imageExtToMime(ext) {
|
|
|
673
2920
|
return "application/octet-stream";
|
|
674
2921
|
}
|
|
675
2922
|
}
|
|
2923
|
+
function detectImageMimeFromBytes(data) {
|
|
2924
|
+
if (data.length >= 3 && data[0] === 255 && data[1] === 216 && data[2] === 255) return "image/jpeg";
|
|
2925
|
+
if (data.length >= 4 && data[0] === 137 && data[1] === 80 && data[2] === 78 && data[3] === 71) return "image/png";
|
|
2926
|
+
if (data.length >= 3 && data[0] === 71 && data[1] === 73 && data[2] === 70) return "image/gif";
|
|
2927
|
+
if (data.length >= 2 && data[0] === 66 && data[1] === 77) return "image/bmp";
|
|
2928
|
+
if (data.length >= 4 && data[0] === 215 && data[1] === 205 && data[2] === 198 && data[3] === 154) return "image/wmf";
|
|
2929
|
+
if (data.length >= 4 && (data[0] === 1 || data[0] === 2) && data[1] === 0 && data[2] === 9 && data[3] === 0) return "image/wmf";
|
|
2930
|
+
if (data.length >= 4 && data[0] === 1 && data[1] === 0 && data[2] === 0 && data[3] === 0) return "image/emf";
|
|
2931
|
+
return "image/png";
|
|
2932
|
+
}
|
|
676
2933
|
function mimeToExt(mime) {
|
|
677
2934
|
if (mime.includes("jpeg")) return "jpg";
|
|
678
2935
|
if (mime.includes("png")) return "png";
|
|
@@ -690,12 +2947,12 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
|
|
|
690
2947
|
for (const block of blocks) {
|
|
691
2948
|
if (block.type !== "image" || !block.text) continue;
|
|
692
2949
|
const ref = block.text;
|
|
693
|
-
const
|
|
694
|
-
|
|
695
|
-
`
|
|
696
|
-
ref
|
|
697
|
-
|
|
698
|
-
];
|
|
2950
|
+
const exts = ref.includes(".") ? [""] : [".jpg", ".jpeg", ".png", ".bmp", ".gif", ".wmf", ".emf", ".tif", ""];
|
|
2951
|
+
const candidates = exts.flatMap((ext) => [
|
|
2952
|
+
`BinData/${ref}${ext}`,
|
|
2953
|
+
`Contents/BinData/${ref}${ext}`,
|
|
2954
|
+
`${ref}${ext}`
|
|
2955
|
+
]);
|
|
699
2956
|
let found = false;
|
|
700
2957
|
for (const path of candidates) {
|
|
701
2958
|
if (isPathTraversal(path)) continue;
|
|
@@ -705,8 +2962,10 @@ async function extractImagesFromZip(zip, blocks, decompressed, warnings) {
|
|
|
705
2962
|
const data = await file.async("uint8array");
|
|
706
2963
|
decompressed.total += data.length;
|
|
707
2964
|
if (decompressed.total > MAX_DECOMPRESS_SIZE) throw new KordocError("ZIP \uC555\uCD95 \uD574\uC81C \uD06C\uAE30 \uCD08\uACFC (ZIP bomb \uC758\uC2EC)");
|
|
708
|
-
const
|
|
709
|
-
const
|
|
2965
|
+
const refExt = ref.includes(".") ? ref.split(".").pop().toLowerCase() : "";
|
|
2966
|
+
const pathExt = !refExt && path.includes(".") ? path.split(".").pop().toLowerCase() : "";
|
|
2967
|
+
const ext = refExt || pathExt;
|
|
2968
|
+
const mimeType = ext ? imageExtToMime(ext) : detectImageMimeFromBytes(data);
|
|
710
2969
|
imageIndex++;
|
|
711
2970
|
const filename = `image_${String(imageIndex).padStart(3, "0")}.${mimeToExt(mimeType)}`;
|
|
712
2971
|
images.push({ filename, data, mimeType });
|
|
@@ -1029,13 +3288,18 @@ function walkSection(node, blocks, tableCtx, tableStack, styleMap, warnings, sec
|
|
|
1029
3288
|
}
|
|
1030
3289
|
break;
|
|
1031
3290
|
case "p": {
|
|
1032
|
-
const { text, href, footnote, style } = extractParagraphInfo(el, styleMap);
|
|
3291
|
+
const { text, href, footnote, style, headingLevel } = extractParagraphInfo(el, styleMap);
|
|
1033
3292
|
if (text) {
|
|
1034
3293
|
if (tableCtx?.cell) {
|
|
1035
3294
|
tableCtx.cell.text += (tableCtx.cell.text ? "\n" : "") + text;
|
|
1036
3295
|
} else if (!tableCtx) {
|
|
1037
|
-
|
|
1038
|
-
if (
|
|
3296
|
+
let block;
|
|
3297
|
+
if (headingLevel) {
|
|
3298
|
+
block = { type: "heading", text, level: headingLevel, pageNumber: sectionNum };
|
|
3299
|
+
} else {
|
|
3300
|
+
block = { type: "paragraph", text, pageNumber: sectionNum };
|
|
3301
|
+
if (style) block.style = style;
|
|
3302
|
+
}
|
|
1039
3303
|
if (href) block.href = href;
|
|
1040
3304
|
if (footnote) block.footnoteText = footnote;
|
|
1041
3305
|
blocks.push(block);
|
|
@@ -1269,7 +3533,19 @@ function extractParagraphInfo(para, styleMap) {
|
|
|
1269
3533
|
if (!style.fontSize && !style.bold && !style.italic) style = void 0;
|
|
1270
3534
|
}
|
|
1271
3535
|
}
|
|
1272
|
-
|
|
3536
|
+
let headingLevel;
|
|
3537
|
+
const styleIdRef = para.getAttribute("styleIDRef");
|
|
3538
|
+
if (styleMap && styleIdRef) {
|
|
3539
|
+
const styleDef = styleMap.styles.get(styleIdRef);
|
|
3540
|
+
if (styleDef?.name) {
|
|
3541
|
+
const sn = styleDef.name;
|
|
3542
|
+
if (/장제목|대제목|간지제목|제목[\s_]?1|개요[\s_]?1|heading[\s_]?1/i.test(sn)) headingLevel = 1;
|
|
3543
|
+
else if (/절제목|제목[\s_]?2|개요[\s_]?2|heading[\s_]?2|^B-1\.$|[\s(]1\.$/i.test(sn)) headingLevel = 2;
|
|
3544
|
+
else if (/제목[\s_]?3|개요[\s_]?3|heading[\s_]?3|1\.1\s*제목|1\.1[\s_]|^B-1\.1/i.test(sn)) headingLevel = 3;
|
|
3545
|
+
else if (/제목[\s_]?4|개요[\s_]?4|heading[\s_]?4/i.test(sn)) headingLevel = 4;
|
|
3546
|
+
}
|
|
3547
|
+
}
|
|
3548
|
+
return { text: cleanText, href, footnote, style, headingLevel };
|
|
1273
3549
|
}
|
|
1274
3550
|
function extractTextFromNode(node) {
|
|
1275
3551
|
let result = "";
|
|
@@ -2335,10 +4611,7 @@ function parseLenientCfb(data) {
|
|
|
2335
4611
|
|
|
2336
4612
|
// src/hwp5/parser.ts
|
|
2337
4613
|
init_page_range();
|
|
2338
|
-
var
|
|
2339
|
-
var import_meta = {};
|
|
2340
|
-
var require2 = (0, import_module.createRequire)(import_meta.url);
|
|
2341
|
-
var CFB = require2("cfb");
|
|
4614
|
+
var CFB = __toESM(require_cfb(), 1);
|
|
2342
4615
|
var MAX_SECTIONS = 100;
|
|
2343
4616
|
var MAX_TOTAL_DECOMPRESS = 500 * 1024 * 1024;
|
|
2344
4617
|
function parseHwp5Document(buffer, options) {
|
|
@@ -3197,7 +5470,7 @@ function clusterCoordinates(values) {
|
|
|
3197
5470
|
}
|
|
3198
5471
|
function groupConnectedLines(lines) {
|
|
3199
5472
|
const parent = lines.map((_, i) => i);
|
|
3200
|
-
function
|
|
5473
|
+
function find2(x) {
|
|
3201
5474
|
while (parent[x] !== x) {
|
|
3202
5475
|
parent[x] = parent[parent[x]];
|
|
3203
5476
|
x = parent[x];
|
|
@@ -3205,7 +5478,7 @@ function groupConnectedLines(lines) {
|
|
|
3205
5478
|
return x;
|
|
3206
5479
|
}
|
|
3207
5480
|
function union(a, b) {
|
|
3208
|
-
const ra =
|
|
5481
|
+
const ra = find2(a), rb = find2(b);
|
|
3209
5482
|
if (ra !== rb) parent[ra] = rb;
|
|
3210
5483
|
}
|
|
3211
5484
|
for (let i = 0; i < lines.length; i++) {
|
|
@@ -3217,7 +5490,7 @@ function groupConnectedLines(lines) {
|
|
|
3217
5490
|
}
|
|
3218
5491
|
const groups = /* @__PURE__ */ new Map();
|
|
3219
5492
|
for (let i = 0; i < lines.length; i++) {
|
|
3220
|
-
const root =
|
|
5493
|
+
const root = find2(i);
|
|
3221
5494
|
if (!groups.has(root)) groups.set(root, []);
|
|
3222
5495
|
groups.get(root).push(lines[i]);
|
|
3223
5496
|
}
|
|
@@ -3667,18 +5940,43 @@ async function parsePdfDocument(buffer, options) {
|
|
|
3667
5940
|
}
|
|
3668
5941
|
const parsedPageCount = parsedPages || (pageFilter ? pageFilter.size : effectivePageCount);
|
|
3669
5942
|
if (totalChars / Math.max(parsedPageCount, 1) < 10) {
|
|
3670
|
-
|
|
5943
|
+
let ocrProvider = options?.ocr ?? null;
|
|
5944
|
+
const ocrMode = options?.ocrMode;
|
|
5945
|
+
if (!ocrProvider && ocrMode && ocrMode !== "off") {
|
|
5946
|
+
try {
|
|
5947
|
+
const { resolveOcrProvider: resolveOcrProvider2 } = await Promise.resolve().then(() => (init_resolve(), resolve_exports));
|
|
5948
|
+
ocrProvider = await resolveOcrProvider2(ocrMode, warnings);
|
|
5949
|
+
} catch (resolveErr) {
|
|
5950
|
+
if (ocrMode !== "auto") {
|
|
5951
|
+
throw Object.assign(
|
|
5952
|
+
new KordocError(resolveErr instanceof Error ? resolveErr.message : "OCR \uD504\uB85C\uBC14\uC774\uB354 \uCD08\uAE30\uD654 \uC2E4\uD328"),
|
|
5953
|
+
{ isImageBased: true }
|
|
5954
|
+
);
|
|
5955
|
+
}
|
|
5956
|
+
}
|
|
5957
|
+
}
|
|
5958
|
+
if (ocrProvider) {
|
|
3671
5959
|
try {
|
|
3672
5960
|
const { ocrPages: ocrPages2 } = await Promise.resolve().then(() => (init_provider(), provider_exports));
|
|
3673
|
-
const ocrBlocks = await ocrPages2(doc,
|
|
5961
|
+
const ocrBlocks = await ocrPages2(doc, ocrProvider, pageFilter, effectivePageCount, warnings);
|
|
3674
5962
|
if (ocrBlocks.length > 0) {
|
|
3675
|
-
const ocrMarkdown = ocrBlocks
|
|
3676
|
-
return {
|
|
5963
|
+
const ocrMarkdown = blocksToMarkdown(ocrBlocks);
|
|
5964
|
+
return {
|
|
5965
|
+
markdown: ocrMarkdown,
|
|
5966
|
+
blocks: ocrBlocks,
|
|
5967
|
+
metadata,
|
|
5968
|
+
warnings: warnings.length > 0 ? warnings : void 0,
|
|
5969
|
+
isImageBased: true
|
|
5970
|
+
};
|
|
3677
5971
|
}
|
|
3678
5972
|
} catch {
|
|
3679
5973
|
}
|
|
3680
5974
|
}
|
|
3681
|
-
|
|
5975
|
+
if (ocrMode === "off") {
|
|
5976
|
+
throw Object.assign(new KordocError(`\uC774\uBBF8\uC9C0 \uAE30\uBC18 PDF (${pageCount}\uD398\uC774\uC9C0, ${totalChars}\uC790)`), { isImageBased: true });
|
|
5977
|
+
}
|
|
5978
|
+
const errMsg = ocrMode ? `\uC774\uBBF8\uC9C0 \uAE30\uBC18 PDF \u2014 OCR \uC2E4\uD328 (${pageCount}\uD398\uC774\uC9C0, ${totalChars}\uC790)` : `\uC774\uBBF8\uC9C0 \uAE30\uBC18 PDF (${pageCount}\uD398\uC774\uC9C0, ${totalChars}\uC790)`;
|
|
5979
|
+
throw Object.assign(new KordocError(errMsg), { isImageBased: true });
|
|
3682
5980
|
}
|
|
3683
5981
|
if (options?.removeHeaderFooter !== false && parsedPageCount >= 3) {
|
|
3684
5982
|
const removed = removeHeaderFooterBlocks(blocks, pageHeights, warnings);
|
|
@@ -5290,8 +7588,8 @@ function levenshtein(a, b) {
|
|
|
5290
7588
|
var SIMILARITY_THRESHOLD = 0.4;
|
|
5291
7589
|
async function compare(bufferA, bufferB, options) {
|
|
5292
7590
|
const [resultA, resultB] = await Promise.all([
|
|
5293
|
-
|
|
5294
|
-
|
|
7591
|
+
parse2(bufferA, options),
|
|
7592
|
+
parse2(bufferB, options)
|
|
5295
7593
|
]);
|
|
5296
7594
|
if (!resultA.success) throw new Error(`\uBB38\uC11CA \uD30C\uC2F1 \uC2E4\uD328: ${resultA.error}`);
|
|
5297
7595
|
if (!resultB.success) throw new Error(`\uBB38\uC11CB \uD30C\uC2F1 \uC2E4\uD328: ${resultB.error}`);
|
|
@@ -5612,7 +7910,7 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5612
7910
|
</hh:font>
|
|
5613
7911
|
</hh:fontface>
|
|
5614
7912
|
</hh:fontfaces>
|
|
5615
|
-
<hh:borderFills itemCnt="
|
|
7913
|
+
<hh:borderFills itemCnt="5">
|
|
5616
7914
|
<hh:borderFill id="1" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
|
|
5617
7915
|
<hh:slash type="NONE" Crooked="0" isCounter="0"/>
|
|
5618
7916
|
<hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
|
|
@@ -5643,8 +7941,26 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5643
7941
|
<hh:bottomBorder type="SOLID" width="0.12 mm" color="#000000"/>
|
|
5644
7942
|
<hh:diagonal type="SOLID" width="0.1 mm" color="#000000"/>
|
|
5645
7943
|
</hh:borderFill>
|
|
7944
|
+
<hh:borderFill id="4" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
|
|
7945
|
+
<hh:slash type="NONE" Crooked="0" isCounter="0"/>
|
|
7946
|
+
<hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
|
|
7947
|
+
<hh:leftBorder type="SOLID" width="0.5 mm" color="#AAAAAA"/>
|
|
7948
|
+
<hh:rightBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7949
|
+
<hh:topBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7950
|
+
<hh:bottomBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7951
|
+
<hh:diagonal type="SOLID" width="0.1 mm" color="#000000"/>
|
|
7952
|
+
</hh:borderFill>
|
|
7953
|
+
<hh:borderFill id="5" threeD="0" shadow="0" centerLine="NONE" breakCellSeparateLine="0">
|
|
7954
|
+
<hh:slash type="NONE" Crooked="0" isCounter="0"/>
|
|
7955
|
+
<hh:backSlash type="NONE" Crooked="0" isCounter="0"/>
|
|
7956
|
+
<hh:leftBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7957
|
+
<hh:rightBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7958
|
+
<hh:topBorder type="NONE" width="0.1 mm" color="#000000"/>
|
|
7959
|
+
<hh:bottomBorder type="SOLID" width="0.4 mm" color="#888888"/>
|
|
7960
|
+
<hh:diagonal type="SOLID" width="0.1 mm" color="#000000"/>
|
|
7961
|
+
</hh:borderFill>
|
|
5646
7962
|
</hh:borderFills>
|
|
5647
|
-
<hh:charProperties itemCnt="
|
|
7963
|
+
<hh:charProperties itemCnt="16">
|
|
5648
7964
|
<hh:charPr id="0" height="1000" textColor="#000000" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="2">
|
|
5649
7965
|
<hh:fontRef hangul="1" latin="1" hanja="1" japanese="1" other="1" symbol="1" user="1"/>
|
|
5650
7966
|
<hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
@@ -5819,6 +8135,17 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5819
8135
|
<hh:outline type="NONE"/>
|
|
5820
8136
|
<hh:shadow type="NONE" color="#C0C0C0" offsetX="10" offsetY="10"/>
|
|
5821
8137
|
</hh:charPr>
|
|
8138
|
+
<hh:charPr id="15" height="1000" textColor="#000000" shadeColor="none" useFontSpace="0" useKerning="0" symMark="NONE" borderFillIDRef="2">
|
|
8139
|
+
<hh:fontRef hangul="1" latin="1" hanja="1" japanese="1" other="1" symbol="1" user="1"/>
|
|
8140
|
+
<hh:ratio hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
8141
|
+
<hh:spacing hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
8142
|
+
<hh:relSz hangul="100" latin="100" hanja="100" japanese="100" other="100" symbol="100" user="100"/>
|
|
8143
|
+
<hh:offset hangul="0" latin="0" hanja="0" japanese="0" other="0" symbol="0" user="0"/>
|
|
8144
|
+
<hh:underline type="NONE" shape="SOLID" color="#000000"/>
|
|
8145
|
+
<hh:strikeout shape="SINGLE" color="#000000"/>
|
|
8146
|
+
<hh:outline type="NONE"/>
|
|
8147
|
+
<hh:shadow type="NONE" color="#C0C0C0" offsetX="10" offsetY="10"/>
|
|
8148
|
+
</hh:charPr>
|
|
5822
8149
|
</hh:charProperties>
|
|
5823
8150
|
<hh:tabProperties itemCnt="3">
|
|
5824
8151
|
<hh:tabPr id="0" autoTabLeft="0" autoTabRight="0"/>
|
|
@@ -5839,7 +8166,7 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
5839
8166
|
<hh:paraHead start="1" level="10" align="LEFT" useInstWidth="1" autoIndent="1" widthAdjust="0" textOffsetType="PERCENT" textOffset="50" numFormat="ROMAN_SMALL" charPrIDRef="4294967295" checkable="1"/>
|
|
5840
8167
|
</hh:numbering>
|
|
5841
8168
|
</hh:numberings>
|
|
5842
|
-
<hh:paraProperties itemCnt="
|
|
8169
|
+
<hh:paraProperties itemCnt="22">
|
|
5843
8170
|
<hh:paraPr id="0" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="1" suppressLineNumbers="0" checked="0" textDir="LTR">
|
|
5844
8171
|
<hh:align horizontal="JUSTIFY" vertical="BASELINE"/>
|
|
5845
8172
|
<hh:heading type="NONE" idRef="0" level="0"/>
|
|
@@ -6441,6 +8768,64 @@ var HEADER_XML = `<?xml version='1.0' encoding='UTF-8'?>
|
|
|
6441
8768
|
</hp:switch>
|
|
6442
8769
|
<hh:border borderFillIDRef="2" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
|
|
6443
8770
|
</hh:paraPr>
|
|
8771
|
+
<hh:paraPr id="20" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="1" suppressLineNumbers="0" checked="0" textDir="LTR">
|
|
8772
|
+
<hh:align horizontal="JUSTIFY" vertical="BASELINE"/>
|
|
8773
|
+
<hh:heading type="NONE" idRef="0" level="0"/>
|
|
8774
|
+
<hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="BREAK_WORD" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
|
|
8775
|
+
<hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
|
|
8776
|
+
<hp:switch>
|
|
8777
|
+
<hp:case hp:required-namespace="http://www.hancom.co.kr/hwpml/2016/HwpUnitChar">
|
|
8778
|
+
<hh:margin>
|
|
8779
|
+
<hc:intent value="0" unit="HWPUNIT"/>
|
|
8780
|
+
<hc:left value="4252" unit="HWPUNIT"/>
|
|
8781
|
+
<hc:right value="0" unit="HWPUNIT"/>
|
|
8782
|
+
<hc:prev value="0" unit="HWPUNIT"/>
|
|
8783
|
+
<hc:next value="0" unit="HWPUNIT"/>
|
|
8784
|
+
</hh:margin>
|
|
8785
|
+
<hh:lineSpacing type="PERCENT" value="160" unit="HWPUNIT"/>
|
|
8786
|
+
</hp:case>
|
|
8787
|
+
<hp:default>
|
|
8788
|
+
<hh:margin>
|
|
8789
|
+
<hc:intent value="0" unit="HWPUNIT"/>
|
|
8790
|
+
<hc:left value="4252" unit="HWPUNIT"/>
|
|
8791
|
+
<hc:right value="0" unit="HWPUNIT"/>
|
|
8792
|
+
<hc:prev value="0" unit="HWPUNIT"/>
|
|
8793
|
+
<hc:next value="0" unit="HWPUNIT"/>
|
|
8794
|
+
</hh:margin>
|
|
8795
|
+
<hh:lineSpacing type="PERCENT" value="160" unit="HWPUNIT"/>
|
|
8796
|
+
</hp:default>
|
|
8797
|
+
</hp:switch>
|
|
8798
|
+
<hh:border borderFillIDRef="4" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
|
|
8799
|
+
</hh:paraPr>
|
|
8800
|
+
<hh:paraPr id="21" tabPrIDRef="0" condense="0" fontLineHeight="0" snapToGrid="1" suppressLineNumbers="0" checked="0" textDir="LTR">
|
|
8801
|
+
<hh:align horizontal="JUSTIFY" vertical="BASELINE"/>
|
|
8802
|
+
<hh:heading type="NONE" idRef="0" level="0"/>
|
|
8803
|
+
<hh:breakSetting breakLatinWord="KEEP_WORD" breakNonLatinWord="BREAK_WORD" widowOrphan="0" keepWithNext="0" keepLines="0" pageBreakBefore="0" lineWrap="BREAK"/>
|
|
8804
|
+
<hh:autoSpacing eAsianEng="0" eAsianNum="0"/>
|
|
8805
|
+
<hp:switch>
|
|
8806
|
+
<hp:case hp:required-namespace="http://www.hancom.co.kr/hwpml/2016/HwpUnitChar">
|
|
8807
|
+
<hh:margin>
|
|
8808
|
+
<hc:intent value="0" unit="HWPUNIT"/>
|
|
8809
|
+
<hc:left value="0" unit="HWPUNIT"/>
|
|
8810
|
+
<hc:right value="0" unit="HWPUNIT"/>
|
|
8811
|
+
<hc:prev value="0" unit="HWPUNIT"/>
|
|
8812
|
+
<hc:next value="0" unit="HWPUNIT"/>
|
|
8813
|
+
</hh:margin>
|
|
8814
|
+
<hh:lineSpacing type="PERCENT" value="160" unit="HWPUNIT"/>
|
|
8815
|
+
</hp:case>
|
|
8816
|
+
<hp:default>
|
|
8817
|
+
<hh:margin>
|
|
8818
|
+
<hc:intent value="0" unit="HWPUNIT"/>
|
|
8819
|
+
<hc:left value="0" unit="HWPUNIT"/>
|
|
8820
|
+
<hc:right value="0" unit="HWPUNIT"/>
|
|
8821
|
+
<hc:prev value="0" unit="HWPUNIT"/>
|
|
8822
|
+
<hc:next value="0" unit="HWPUNIT"/>
|
|
8823
|
+
</hh:margin>
|
|
8824
|
+
<hh:lineSpacing type="PERCENT" value="160" unit="HWPUNIT"/>
|
|
8825
|
+
</hp:default>
|
|
8826
|
+
</hp:switch>
|
|
8827
|
+
<hh:border borderFillIDRef="5" offsetLeft="0" offsetRight="0" offsetTop="0" offsetBottom="0" connect="0" ignoreMargin="0"/>
|
|
8828
|
+
</hh:paraPr>
|
|
6444
8829
|
</hh:paraProperties>
|
|
6445
8830
|
<hh:styles itemCnt="23">
|
|
6446
8831
|
<hh:style id="0" type="PARA" name="\uBC14\uD0D5\uAE00" engName="Normal" paraPrIDRef="0" charPrIDRef="0" nextStyleIDRef="0" langID="1042" lockForm="0"/>
|
|
@@ -6544,7 +8929,11 @@ async function extractTemplateStyles(templateArrayBuffer) {
|
|
|
6544
8929
|
charPr: /* @__PURE__ */ new Map(),
|
|
6545
8930
|
paraPr: /* @__PURE__ */ new Map(),
|
|
6546
8931
|
borderFill: /* @__PURE__ */ new Map(),
|
|
6547
|
-
fontfaces: /* @__PURE__ */ new Map()
|
|
8932
|
+
fontfaces: /* @__PURE__ */ new Map(),
|
|
8933
|
+
styles: /* @__PURE__ */ new Map(),
|
|
8934
|
+
stylesById: /* @__PURE__ */ new Map(),
|
|
8935
|
+
masterpages: [],
|
|
8936
|
+
headerXml: headerXmlText
|
|
6548
8937
|
};
|
|
6549
8938
|
const fontfaces = doc.getElementsByTagNameNS(ns.hh, "fontFamily");
|
|
6550
8939
|
for (let i = 0; i < fontfaces.length; i++) {
|
|
@@ -6619,6 +9008,34 @@ async function extractTemplateStyles(templateArrayBuffer) {
|
|
|
6619
9008
|
if (fillColor) borderFillProp.fillColor = fillColor;
|
|
6620
9009
|
template.borderFill.set(id, borderFillProp);
|
|
6621
9010
|
}
|
|
9011
|
+
const styleEls = doc.getElementsByTagNameNS(ns.hh, "style");
|
|
9012
|
+
for (let i = 0; i < styleEls.length; i++) {
|
|
9013
|
+
const el = styleEls.item(i);
|
|
9014
|
+
const id = el.getAttribute("id");
|
|
9015
|
+
const name = el.getAttribute("name") || "";
|
|
9016
|
+
const engName = el.getAttribute("engName") || "";
|
|
9017
|
+
const charPrIDRef = el.getAttribute("charPrIDRef") || "0";
|
|
9018
|
+
const paraPrIDRef = el.getAttribute("paraPrIDRef") || "0";
|
|
9019
|
+
if (!id) continue;
|
|
9020
|
+
const def = { id, name, engName, charPrIDRef, paraPrIDRef };
|
|
9021
|
+
template.styles.set(name, def);
|
|
9022
|
+
template.stylesById.set(id, def);
|
|
9023
|
+
}
|
|
9024
|
+
const section0File = zip.file("Contents/section0.xml");
|
|
9025
|
+
if (section0File) {
|
|
9026
|
+
const sec0 = await section0File.async("text");
|
|
9027
|
+
const secPrMatch = sec0.match(/<hp:secPr[\s\S]*?<\/hp:secPr>/);
|
|
9028
|
+
if (secPrMatch) template.secPrXml = secPrMatch[0];
|
|
9029
|
+
const colPrMatch = sec0.match(/<hp:ctrl>[\s\S]*?<\/hp:ctrl>/);
|
|
9030
|
+
if (colPrMatch) template.colPrXml = colPrMatch[0];
|
|
9031
|
+
}
|
|
9032
|
+
for (const [path, file] of Object.entries(zip.files)) {
|
|
9033
|
+
if (/^Contents\/masterpage\d+\.xml$/.test(path)) {
|
|
9034
|
+
const content = await file.async("text");
|
|
9035
|
+
template.masterpages.push({ filename: path, content });
|
|
9036
|
+
}
|
|
9037
|
+
}
|
|
9038
|
+
template.masterpages.sort((a, b) => a.filename.localeCompare(b.filename));
|
|
6622
9039
|
return template;
|
|
6623
9040
|
}
|
|
6624
9041
|
function findCharPrByCharacteristic(charPrMap, characteristic) {
|
|
@@ -6679,35 +9096,61 @@ function getDefaultBorderFillId(borderFillMap) {
|
|
|
6679
9096
|
}
|
|
6680
9097
|
|
|
6681
9098
|
// src/hwpx/style-matcher.ts
|
|
9099
|
+
function findStyleByName(styles, candidates) {
|
|
9100
|
+
for (const cand of candidates) {
|
|
9101
|
+
if (styles.has(cand)) return styles.get(cand);
|
|
9102
|
+
}
|
|
9103
|
+
for (const cand of candidates) {
|
|
9104
|
+
for (const [name, def] of styles) {
|
|
9105
|
+
if (name === `B-${cand}` || name.endsWith(` ${cand}`) || name.endsWith(`-${cand}`)) return def;
|
|
9106
|
+
}
|
|
9107
|
+
}
|
|
9108
|
+
for (const cand of candidates) {
|
|
9109
|
+
let best = null;
|
|
9110
|
+
for (const [name, def] of styles) {
|
|
9111
|
+
if (name.includes(cand)) {
|
|
9112
|
+
if (!best || name.length < best[0].length) best = [name, def];
|
|
9113
|
+
}
|
|
9114
|
+
}
|
|
9115
|
+
if (best) return best[1];
|
|
9116
|
+
}
|
|
9117
|
+
return null;
|
|
9118
|
+
}
|
|
6682
9119
|
function createStyleMap(template, warnings = []) {
|
|
6683
9120
|
const charPrMap = template.charPr || /* @__PURE__ */ new Map();
|
|
6684
|
-
const paraPrMap = template.paraPr || /* @__PURE__ */ new Map();
|
|
6685
9121
|
const borderFillMap = template.borderFill || /* @__PURE__ */ new Map();
|
|
9122
|
+
const styles = template.styles || /* @__PURE__ */ new Map();
|
|
6686
9123
|
const defaultCharPr = getDefaultCharPrId(charPrMap);
|
|
6687
|
-
const defaultParaPr = getDefaultParaPrId(
|
|
9124
|
+
const defaultParaPr = getDefaultParaPrId(template.paraPr || /* @__PURE__ */ new Map());
|
|
6688
9125
|
const defaultBorderFill = getDefaultBorderFillId(borderFillMap);
|
|
6689
|
-
const
|
|
6690
|
-
const
|
|
6691
|
-
|
|
6692
|
-
|
|
6693
|
-
|
|
6694
|
-
|
|
6695
|
-
|
|
6696
|
-
|
|
6697
|
-
|
|
6698
|
-
|
|
6699
|
-
|
|
6700
|
-
|
|
9126
|
+
const defaultStyleId = "0";
|
|
9127
|
+
const toEntry = (def, fallbackCharPr) => ({
|
|
9128
|
+
charPr: def?.charPrIDRef ?? fallbackCharPr,
|
|
9129
|
+
paraPr: def?.paraPrIDRef ?? defaultParaPr,
|
|
9130
|
+
styleId: def?.id ?? defaultStyleId
|
|
9131
|
+
});
|
|
9132
|
+
const bodyDef = findStyleByName(styles, ["\uBC14\uD0D5\uAE00", "Normal", "\uBCF8\uBB38", "\uBC14\uD0D5"]) || findStyleByName(styles, ["body", "normal"]);
|
|
9133
|
+
const h1Def = findStyleByName(styles, ["\uC81C\uBAA91", "\uC81C\uBAA9 1", "\uAC1C\uC694 1", "\uAC1C\uC6941", "Heading 1"]) || findStyleByName(styles, ["\uC7A5\uC81C\uBAA9", "\uB300\uC81C\uBAA9", "\uC81C\uBAA9"]);
|
|
9134
|
+
const h2Def = findStyleByName(styles, ["\uC81C\uBAA92", "\uC81C\uBAA9 2", "\uAC1C\uC694 2", "\uAC1C\uC6942", "Heading 2"]) || findStyleByName(styles, ["\uC808\uC81C\uBAA9", "1.", "1 "]);
|
|
9135
|
+
const h3Def = findStyleByName(styles, ["\uC81C\uBAA93", "\uC81C\uBAA9 3", "\uAC1C\uC694 3", "\uAC1C\uC6943", "Heading 3"]) || findStyleByName(styles, ["1.1", "\uD56D\uBAA9"]);
|
|
9136
|
+
const tableCellDef = findStyleByName(styles, ["\uD45C \uB0B4\uC6A9", "\uD45C\uB0B4\uC6A9", "B-\uD45C\uB0B4\uC6A9", "\uD45C \uB0B4\uC6A9(\uC77C\uBC18)"]) || findStyleByName(styles, ["\uD45C", "table"]);
|
|
9137
|
+
const tableHeaderDef = findStyleByName(styles, ["\uD45C\uC81C\uBAA9", "\uD45C \uC81C\uBAA9", "B-\uD45C\uC81C\uBAA9", "\uD45C \uB0B4\uC6A9(\uAC15\uC870)"]) || tableCellDef;
|
|
9138
|
+
const bodyCharPr = bodyDef?.charPrIDRef ?? findCharPrByCharacteristic(charPrMap, "normal") ?? defaultCharPr;
|
|
9139
|
+
const h1CharPr = h1Def?.charPrIDRef ?? findCharPrByCharacteristic(charPrMap, "heading1") ?? defaultCharPr;
|
|
9140
|
+
const h2CharPr = h2Def?.charPrIDRef ?? findCharPrByCharacteristic(charPrMap, "heading2") ?? defaultCharPr;
|
|
9141
|
+
const h3CharPr = h3Def?.charPrIDRef ?? findCharPrByCharacteristic(charPrMap, "heading3") ?? defaultCharPr;
|
|
9142
|
+
const boldCharPr = findCharPrByCharacteristic(charPrMap, "bold") ?? defaultCharPr;
|
|
9143
|
+
const italicCharPr = findCharPrByCharacteristic(charPrMap, "italic") ?? defaultCharPr;
|
|
6701
9144
|
return {
|
|
6702
|
-
h1: { charPr: h1CharPr, paraPr: defaultParaPr },
|
|
6703
|
-
h2: { charPr: h2CharPr, paraPr: defaultParaPr },
|
|
6704
|
-
h3: { charPr: h3CharPr, paraPr: defaultParaPr },
|
|
6705
|
-
h456: { charPr:
|
|
6706
|
-
body: { charPr: bodyCharPr, paraPr: defaultParaPr },
|
|
9145
|
+
h1: { charPr: h1CharPr, paraPr: h1Def?.paraPrIDRef ?? defaultParaPr, styleId: h1Def?.id ?? defaultStyleId },
|
|
9146
|
+
h2: { charPr: h2CharPr, paraPr: h2Def?.paraPrIDRef ?? defaultParaPr, styleId: h2Def?.id ?? defaultStyleId },
|
|
9147
|
+
h3: { charPr: h3CharPr, paraPr: h3Def?.paraPrIDRef ?? defaultParaPr, styleId: h3Def?.id ?? defaultStyleId },
|
|
9148
|
+
h456: { charPr: h3CharPr, paraPr: h3Def?.paraPrIDRef ?? defaultParaPr, styleId: h3Def?.id ?? defaultStyleId },
|
|
9149
|
+
body: { charPr: bodyCharPr, paraPr: bodyDef?.paraPrIDRef ?? defaultParaPr, styleId: bodyDef?.id ?? defaultStyleId },
|
|
6707
9150
|
bold: { charPr: boldCharPr },
|
|
6708
9151
|
italic: { charPr: italicCharPr },
|
|
6709
|
-
tableCell: { charPr: bodyCharPr, borderFill: defaultBorderFill },
|
|
6710
|
-
tableHeader: { charPr:
|
|
9152
|
+
tableCell: { charPr: tableCellDef?.charPrIDRef ?? bodyCharPr, paraPr: tableCellDef?.paraPrIDRef ?? defaultParaPr, styleId: tableCellDef?.id ?? defaultStyleId, borderFill: defaultBorderFill },
|
|
9153
|
+
tableHeader: { charPr: tableHeaderDef?.charPrIDRef ?? bodyCharPr, paraPr: tableHeaderDef?.paraPrIDRef ?? defaultParaPr, styleId: tableHeaderDef?.id ?? defaultStyleId, borderFill: defaultBorderFill }
|
|
6711
9154
|
};
|
|
6712
9155
|
}
|
|
6713
9156
|
function getStyleForBlock(styleMap, blockType, inlineStyle) {
|
|
@@ -6743,7 +9186,10 @@ var CHAR_BOLD = "11";
|
|
|
6743
9186
|
var CHAR_ITALIC = "12";
|
|
6744
9187
|
var CHAR_BOLD_ITALIC = "13";
|
|
6745
9188
|
var CHAR_CODE = "14";
|
|
9189
|
+
var CHAR_STRIKETHROUGH = "15";
|
|
6746
9190
|
var PARA_NORMAL = "0";
|
|
9191
|
+
var PARA_BLOCKQUOTE = "20";
|
|
9192
|
+
var PARA_HR = "21";
|
|
6747
9193
|
var SEC_NS = [
|
|
6748
9194
|
`xmlns:ha="http://www.hancom.co.kr/hwpml/2011/app"`,
|
|
6749
9195
|
`xmlns:hp="http://www.hancom.co.kr/hwpml/2011/paragraph"`,
|
|
@@ -6770,7 +9216,7 @@ function escapeXml(text) {
|
|
|
6770
9216
|
}
|
|
6771
9217
|
function parseInlineRuns(text) {
|
|
6772
9218
|
const runs = [];
|
|
6773
|
-
const re = /\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*|_(.+?)_|`(.+?)
|
|
9219
|
+
const re = /\*\*\*(.+?)\*\*\*|\*\*(.+?)\*\*|\*(.+?)\*|_(.+?)_|`(.+?)`|~~(.+?)~~|\[([^\]]+)\]\(([^)]+)\)/g;
|
|
6774
9220
|
let last = 0;
|
|
6775
9221
|
let m;
|
|
6776
9222
|
while ((m = re.exec(text)) !== null) {
|
|
@@ -6780,7 +9226,8 @@ function parseInlineRuns(text) {
|
|
|
6780
9226
|
else if (m[3]) runs.push({ text: m[3], italic: true });
|
|
6781
9227
|
else if (m[4]) runs.push({ text: m[4], italic: true });
|
|
6782
9228
|
else if (m[5]) runs.push({ text: m[5], code: true });
|
|
6783
|
-
else if (m[6]) runs.push({ text: m[6],
|
|
9229
|
+
else if (m[6]) runs.push({ text: m[6], strikethrough: true });
|
|
9230
|
+
else if (m[7]) runs.push({ text: m[7], url: m[8] });
|
|
6784
9231
|
last = m.index + m[0].length;
|
|
6785
9232
|
}
|
|
6786
9233
|
if (last < text.length) runs.push({ text: text.slice(last) });
|
|
@@ -6788,6 +9235,7 @@ function parseInlineRuns(text) {
|
|
|
6788
9235
|
}
|
|
6789
9236
|
function charPrForRun(run) {
|
|
6790
9237
|
if (run.code) return CHAR_CODE;
|
|
9238
|
+
if (run.strikethrough) return CHAR_STRIKETHROUGH;
|
|
6791
9239
|
if (run.bold && run.italic) return CHAR_BOLD_ITALIC;
|
|
6792
9240
|
if (run.bold) return CHAR_BOLD;
|
|
6793
9241
|
if (run.italic) return CHAR_ITALIC;
|
|
@@ -6816,25 +9264,51 @@ function makeHyperlinkRun(text, url, charPrId, nextId) {
|
|
|
6816
9264
|
].join("\n");
|
|
6817
9265
|
}
|
|
6818
9266
|
function makeRunsFromText(text, defaultCharPr, nextId) {
|
|
9267
|
+
if (/<br\s*\/?>/i.test(text)) {
|
|
9268
|
+
const parts = text.split(/<br\s*\/?>/i);
|
|
9269
|
+
return parts.map((part, i) => {
|
|
9270
|
+
const seg = makeRunsFromText(part, defaultCharPr, nextId);
|
|
9271
|
+
return i < parts.length - 1 ? seg + `<hp:run charPrIDRef="${defaultCharPr}"><hp:lf/></hp:run>` : seg;
|
|
9272
|
+
}).join("");
|
|
9273
|
+
}
|
|
6819
9274
|
const runs = parseInlineRuns(text);
|
|
6820
9275
|
if (runs.length === 0) return makeRun("", defaultCharPr);
|
|
6821
|
-
const isPlain = runs.length === 1 && !runs[0].bold && !runs[0].italic && !runs[0].code && !runs[0].url;
|
|
9276
|
+
const isPlain = runs.length === 1 && !runs[0].bold && !runs[0].italic && !runs[0].code && !runs[0].strikethrough && !runs[0].url;
|
|
6822
9277
|
if (isPlain) return makeRun(runs[0].text, defaultCharPr);
|
|
6823
9278
|
return runs.map((r) => {
|
|
6824
9279
|
if (r.url && nextId) return makeHyperlinkRun(r.text, r.url, CHAR_NORMAL, nextId);
|
|
6825
9280
|
return makeRun(r.text, charPrForRun(r));
|
|
6826
9281
|
}).join("");
|
|
6827
9282
|
}
|
|
6828
|
-
|
|
6829
|
-
|
|
9283
|
+
function makeLineseg(horzsize, vertsize) {
|
|
9284
|
+
const baseline = Math.round(vertsize * 0.85);
|
|
9285
|
+
return ` <hp:linesegarray>
|
|
9286
|
+
<hp:lineseg textpos="0" vertpos="0" vertsize="${vertsize}" textheight="${vertsize}" baseline="${baseline}" spacing="600" horzpos="0" horzsize="${horzsize}" flags="393216"/>
|
|
9287
|
+
</hp:linesegarray>`;
|
|
9288
|
+
}
|
|
9289
|
+
var CHAR_HWP = 1e3;
|
|
9290
|
+
var LINE_HWP = 1400;
|
|
9291
|
+
var BASELINE_RATIO = 0.85;
|
|
9292
|
+
function estimateCellLineseg(plainText, cellHorzsize) {
|
|
9293
|
+
const stripped = plainText.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim();
|
|
9294
|
+
const charsPerLine = Math.max(1, Math.floor(cellHorzsize / CHAR_HWP));
|
|
9295
|
+
const lineCount = Math.max(1, Math.ceil(stripped.length / charsPerLine));
|
|
9296
|
+
const baseline = Math.round(LINE_HWP * BASELINE_RATIO);
|
|
9297
|
+
const segs = Array.from({ length: lineCount }, (_, i) => {
|
|
9298
|
+
const textpos = i * charsPerLine;
|
|
9299
|
+
const vertpos = i * LINE_HWP;
|
|
9300
|
+
return ` <hp:lineseg textpos="${textpos}" vertpos="${vertpos}" vertsize="${LINE_HWP}" textheight="${LINE_HWP}" baseline="${vertpos + baseline}" spacing="600" horzpos="0" horzsize="${cellHorzsize}" flags="393216"/>`;
|
|
9301
|
+
});
|
|
9302
|
+
return ` <hp:linesegarray>
|
|
9303
|
+
${segs.join("\n")}
|
|
6830
9304
|
</hp:linesegarray>`;
|
|
6831
|
-
|
|
9305
|
+
}
|
|
9306
|
+
function makeParagraph(text, charPrId, paraPrId, nextId, styleId = "0") {
|
|
6832
9307
|
const id = nextId();
|
|
6833
9308
|
const runs = makeRunsFromText(text, charPrId, nextId);
|
|
6834
9309
|
return [
|
|
6835
|
-
`<hp:p id="${id}" paraPrIDRef="${paraPrId}" styleIDRef="
|
|
9310
|
+
`<hp:p id="${id}" paraPrIDRef="${paraPrId}" styleIDRef="${styleId}" pageBreak="0" columnBreak="0" merged="0">`,
|
|
6836
9311
|
` ${runs}`,
|
|
6837
|
-
LINESEG,
|
|
6838
9312
|
`</hp:p>`
|
|
6839
9313
|
].join("\n");
|
|
6840
9314
|
}
|
|
@@ -6843,7 +9317,23 @@ function makeEmptyParagraph(nextId) {
|
|
|
6843
9317
|
return [
|
|
6844
9318
|
`<hp:p id="${id}" paraPrIDRef="${PARA_NORMAL}" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
6845
9319
|
` <hp:run charPrIDRef="${CHAR_NORMAL}"><hp:t/></hp:run>`,
|
|
6846
|
-
|
|
9320
|
+
`</hp:p>`
|
|
9321
|
+
].join("\n");
|
|
9322
|
+
}
|
|
9323
|
+
function makeBlockquoteParagraph(text, nextId) {
|
|
9324
|
+
const id = nextId();
|
|
9325
|
+
const runs = makeRunsFromText(text, CHAR_ITALIC, nextId);
|
|
9326
|
+
return [
|
|
9327
|
+
`<hp:p id="${id}" paraPrIDRef="${PARA_BLOCKQUOTE}" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
9328
|
+
` ${runs}`,
|
|
9329
|
+
`</hp:p>`
|
|
9330
|
+
].join("\n");
|
|
9331
|
+
}
|
|
9332
|
+
function makeHrParagraph(nextId) {
|
|
9333
|
+
const id = nextId();
|
|
9334
|
+
return [
|
|
9335
|
+
`<hp:p id="${id}" paraPrIDRef="${PARA_HR}" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
9336
|
+
` <hp:run charPrIDRef="${CHAR_NORMAL}"><hp:t/></hp:run>`,
|
|
6847
9337
|
`</hp:p>`
|
|
6848
9338
|
].join("\n");
|
|
6849
9339
|
}
|
|
@@ -6854,8 +9344,7 @@ function headingCharPr(level) {
|
|
|
6854
9344
|
return CHAR_H456;
|
|
6855
9345
|
}
|
|
6856
9346
|
var BODY_WIDTH = 42520;
|
|
6857
|
-
|
|
6858
|
-
function makeTableCell(text, colAddr, rowAddr, colWidth, isHeader, nextId, styleMap) {
|
|
9347
|
+
function makeTableCell(text, colAddr, rowAddr, colWidth, cellHeight, isHeader, nextId, styleMap) {
|
|
6859
9348
|
let charPr;
|
|
6860
9349
|
let borderFill = "3";
|
|
6861
9350
|
if (styleMap) {
|
|
@@ -6865,20 +9354,28 @@ function makeTableCell(text, colAddr, rowAddr, colWidth, isHeader, nextId, style
|
|
|
6865
9354
|
} else {
|
|
6866
9355
|
charPr = isHeader ? CHAR_BOLD : CHAR_NORMAL;
|
|
6867
9356
|
}
|
|
6868
|
-
const paraId = nextId();
|
|
6869
9357
|
const subId = nextId();
|
|
9358
|
+
const cellHorzsize = Math.max(1e3, colWidth - 2e3);
|
|
9359
|
+
const segments = text.split(/<br\s*\/?>/i);
|
|
9360
|
+
const cellParas = segments.map((seg) => {
|
|
9361
|
+
const pid = nextId();
|
|
9362
|
+
return [
|
|
9363
|
+
` <hp:p id="${pid}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
9364
|
+
` ${makeRunsFromText(seg, charPr, nextId)}`,
|
|
9365
|
+
estimateCellLineseg(seg, cellHorzsize),
|
|
9366
|
+
` </hp:p>`
|
|
9367
|
+
].join("\n");
|
|
9368
|
+
}).join("\n");
|
|
6870
9369
|
return [
|
|
6871
9370
|
`<hp:tc name="" header="${isHeader ? 1 : 0}" hasMargin="0" protect="0" editable="0" dirty="1" borderFillIDRef="${borderFill}">`,
|
|
6872
9371
|
` <hp:subList id="${subId}" textDirection="HORIZONTAL" lineWrap="BREAK" vertAlign="CENTER"`,
|
|
6873
9372
|
` linkListIDRef="0" linkListNextIDRef="0" textWidth="0" textHeight="0"`,
|
|
6874
9373
|
` hasTextRef="0" hasNumRef="0">`,
|
|
6875
|
-
|
|
6876
|
-
` <hp:run charPrIDRef="${charPr}"><hp:t${text ? `>${escapeXml(text)}</hp:t` : "/"}></hp:run>`,
|
|
6877
|
-
` </hp:p>`,
|
|
9374
|
+
cellParas,
|
|
6878
9375
|
` </hp:subList>`,
|
|
6879
9376
|
` <hp:cellAddr colAddr="${colAddr}" rowAddr="${rowAddr}"/>`,
|
|
6880
9377
|
` <hp:cellSpan colSpan="1" rowSpan="1"/>`,
|
|
6881
|
-
` <hp:cellSz width="${colWidth}" height="${
|
|
9378
|
+
` <hp:cellSz width="${colWidth}" height="${cellHeight}"/>`,
|
|
6882
9379
|
` <hp:cellMargin left="1000" right="1000" top="500" bottom="500"/>`,
|
|
6883
9380
|
`</hp:tc>`
|
|
6884
9381
|
].join("\n");
|
|
@@ -6888,10 +9385,21 @@ function makeTable(rows, nextId, styleMap) {
|
|
|
6888
9385
|
const colCnt = rows[0].length;
|
|
6889
9386
|
const colWidth = Math.floor(BODY_WIDTH / colCnt);
|
|
6890
9387
|
const totalWidth = colWidth * colCnt;
|
|
6891
|
-
const
|
|
9388
|
+
const cellHorzsize = Math.max(1e3, colWidth - 2e3);
|
|
9389
|
+
const rowHeights = rows.map((row) => {
|
|
9390
|
+
const maxTotalLines = Math.max(1, ...row.map((cell) => {
|
|
9391
|
+
return cell.split(/<br\s*\/?>/i).reduce((sum, seg) => {
|
|
9392
|
+
const plain = seg.replace(/<[^>]*>/g, "").replace(/\s+/g, " ").trim();
|
|
9393
|
+
const charsPerLine = Math.max(1, Math.floor(cellHorzsize / CHAR_HWP));
|
|
9394
|
+
return sum + Math.max(1, Math.ceil(plain.length / charsPerLine));
|
|
9395
|
+
}, 0);
|
|
9396
|
+
}));
|
|
9397
|
+
return maxTotalLines * LINE_HWP + 1e3;
|
|
9398
|
+
});
|
|
9399
|
+
const totalHeight = rowHeights.reduce((s, h) => s + h, 0);
|
|
6892
9400
|
const trElements = rows.map(
|
|
6893
9401
|
(row, rowIdx) => `<hp:tr>
|
|
6894
|
-
${row.map((cell, colIdx) => makeTableCell(cell, colIdx, rowIdx, colWidth, rowIdx === 0, nextId, styleMap)).join("\n")}
|
|
9402
|
+
${row.map((cell, colIdx) => makeTableCell(cell, colIdx, rowIdx, colWidth, rowHeights[rowIdx], rowIdx === 0, nextId, styleMap)).join("\n")}
|
|
6895
9403
|
</hp:tr>`
|
|
6896
9404
|
).join("\n");
|
|
6897
9405
|
const tableId = nextId();
|
|
@@ -6912,7 +9420,7 @@ ${row.map((cell, colIdx) => makeTableCell(cell, colIdx, rowIdx, colWidth, rowIdx
|
|
|
6912
9420
|
trElements,
|
|
6913
9421
|
`</hp:tbl>`,
|
|
6914
9422
|
`</hp:run>`,
|
|
6915
|
-
|
|
9423
|
+
makeLineseg(totalWidth, totalHeight),
|
|
6916
9424
|
`</hp:p>`
|
|
6917
9425
|
].join("\n");
|
|
6918
9426
|
}
|
|
@@ -6937,6 +9445,20 @@ function parseMarkdownToBlocks(md) {
|
|
|
6937
9445
|
i++;
|
|
6938
9446
|
continue;
|
|
6939
9447
|
}
|
|
9448
|
+
if (/^(-{3,}|\*{3,}|_{3,})$/.test(trimmed)) {
|
|
9449
|
+
blocks.push({ type: "hr" });
|
|
9450
|
+
i++;
|
|
9451
|
+
continue;
|
|
9452
|
+
}
|
|
9453
|
+
if (trimmed.startsWith(">")) {
|
|
9454
|
+
const quoteLines = [];
|
|
9455
|
+
while (i < lines.length && lines[i].trim().startsWith(">")) {
|
|
9456
|
+
quoteLines.push(lines[i].trim().replace(/^>\s?/, ""));
|
|
9457
|
+
i++;
|
|
9458
|
+
}
|
|
9459
|
+
blocks.push({ type: "blockquote", text: quoteLines.join(" ") });
|
|
9460
|
+
continue;
|
|
9461
|
+
}
|
|
6940
9462
|
const hm = trimmed.match(/^(#{1,6})\s+(.+)$/);
|
|
6941
9463
|
if (hm) {
|
|
6942
9464
|
blocks.push({ type: "heading", text: hm[2].trim(), level: hm[1].length });
|
|
@@ -6996,35 +9518,108 @@ function parseMarkdownToBlocks(md) {
|
|
|
6996
9518
|
continue;
|
|
6997
9519
|
}
|
|
6998
9520
|
const paraLines = [];
|
|
6999
|
-
while (i < lines.length && lines[i].trim() && !lines[i].trim().startsWith("#") && !lines[i].trim().startsWith("|") && !/^\s*[-*+]\s/.test(lines[i]) && !/^\s*\d+\.\s/.test(lines[i]) && !lines[i].trim().startsWith("```") && !lines[i].trim().match(/^!\[[^\]]*\]\([^)]+\)$/)) paraLines.push(lines[i++].trim());
|
|
9521
|
+
while (i < lines.length && lines[i].trim() && !lines[i].trim().startsWith("#") && !lines[i].trim().startsWith("|") && !lines[i].trim().startsWith(">") && !/^\s*[-*+]\s/.test(lines[i]) && !/^\s*\d+\.\s/.test(lines[i]) && !lines[i].trim().startsWith("```") && !lines[i].trim().match(/^!\[[^\]]*\]\([^)]+\)$/) && !/^(-{3,}|\*{3,}|_{3,})$/.test(lines[i].trim())) paraLines.push(lines[i++].trim());
|
|
7000
9522
|
if (paraLines.length > 0) blocks.push({ type: "paragraph", text: paraLines.join(" ") });
|
|
7001
9523
|
}
|
|
7002
9524
|
return blocks;
|
|
7003
9525
|
}
|
|
9526
|
+
function getImageDimensions(data) {
|
|
9527
|
+
if (data[0] === 137 && data[1] === 80 && data[2] === 78 && data[3] === 71) {
|
|
9528
|
+
if (data.length < 24) return null;
|
|
9529
|
+
const w = (data[16] << 24 | data[17] << 16 | data[18] << 8 | data[19]) >>> 0;
|
|
9530
|
+
const h = (data[20] << 24 | data[21] << 16 | data[22] << 8 | data[23]) >>> 0;
|
|
9531
|
+
return w > 0 && h > 0 ? { width: w, height: h } : null;
|
|
9532
|
+
}
|
|
9533
|
+
if (data[0] === 255 && data[1] === 216) {
|
|
9534
|
+
let i = 2;
|
|
9535
|
+
while (i < data.length - 8) {
|
|
9536
|
+
if (data[i] !== 255) break;
|
|
9537
|
+
const marker = data[i + 1];
|
|
9538
|
+
if (marker >= 192 && marker <= 195) {
|
|
9539
|
+
const h = data[i + 5] << 8 | data[i + 6];
|
|
9540
|
+
const w = data[i + 7] << 8 | data[i + 8];
|
|
9541
|
+
return w > 0 && h > 0 ? { width: w, height: h } : null;
|
|
9542
|
+
}
|
|
9543
|
+
if (marker === 217 || marker === 1 || marker >= 208 && marker <= 215) {
|
|
9544
|
+
i += 2;
|
|
9545
|
+
continue;
|
|
9546
|
+
}
|
|
9547
|
+
const segLen = data[i + 2] << 8 | data[i + 3];
|
|
9548
|
+
if (segLen < 2) break;
|
|
9549
|
+
i += 2 + segLen;
|
|
9550
|
+
}
|
|
9551
|
+
}
|
|
9552
|
+
return null;
|
|
9553
|
+
}
|
|
9554
|
+
function calcHwpSize(width, height) {
|
|
9555
|
+
if (width <= 0 || height <= 0) return { widthHwp: 28346, heightHwp: 19843 };
|
|
9556
|
+
const HWP_PER_PIXEL = 7200 / 96;
|
|
9557
|
+
const naturalW = Math.round(width * HWP_PER_PIXEL);
|
|
9558
|
+
const naturalH = Math.round(height * HWP_PER_PIXEL);
|
|
9559
|
+
const maxWidthHwp = 28346;
|
|
9560
|
+
if (naturalW <= maxWidthHwp) {
|
|
9561
|
+
return { widthHwp: naturalW, heightHwp: naturalH };
|
|
9562
|
+
}
|
|
9563
|
+
const ratio = height / width;
|
|
9564
|
+
return { widthHwp: maxWidthHwp, heightHwp: Math.round(maxWidthHwp * ratio) };
|
|
9565
|
+
}
|
|
7004
9566
|
function mimeToFormat(mimeType) {
|
|
7005
9567
|
if (mimeType.includes("jpeg") || mimeType.includes("jpg")) return "JPG";
|
|
7006
9568
|
if (mimeType.includes("gif")) return "GIF";
|
|
7007
9569
|
if (mimeType.includes("bmp")) return "BMP";
|
|
7008
9570
|
return "PNG";
|
|
7009
9571
|
}
|
|
7010
|
-
function makeImageParagraph(
|
|
9572
|
+
function makeImageParagraph(ref, nextId, widthHwp = 28346, heightHwp = 19843, naturalWidth, naturalHeight) {
|
|
7011
9573
|
const paraId = nextId();
|
|
7012
|
-
|
|
7013
|
-
|
|
7014
|
-
|
|
7015
|
-
|
|
7016
|
-
|
|
7017
|
-
|
|
9574
|
+
const picId = nextId();
|
|
9575
|
+
const natW = naturalWidth || widthHwp;
|
|
9576
|
+
const natH = naturalHeight || heightHwp;
|
|
9577
|
+
const cx = Math.round(widthHwp / 2);
|
|
9578
|
+
const cy = Math.round(heightHwp / 2);
|
|
9579
|
+
const imgLineseg = [
|
|
9580
|
+
` <hp:linesegarray>`,
|
|
9581
|
+
` <hp:lineseg textpos="0" vertpos="0" vertsize="${heightHwp}" textheight="${heightHwp}"`,
|
|
9582
|
+
` baseline="${Math.round(heightHwp * 0.85)}" spacing="600"`,
|
|
9583
|
+
` horzpos="0" horzsize="42520" flags="393216"/>`,
|
|
9584
|
+
` </hp:linesegarray>`
|
|
9585
|
+
].join("\n");
|
|
9586
|
+
const pic = [
|
|
9587
|
+
` <hp:pic id="${picId}" zOrder="0" numberingType="NONE" textWrap="SQUARE" textFlow="BOTH_SIDES"`,
|
|
9588
|
+
` lock="0" dropcapstyle="None" href="" groupLevel="0" instid="0" reverse="0">`,
|
|
9589
|
+
` <hp:offset x="0" y="0"/>`,
|
|
9590
|
+
` <hp:orgSz width="${widthHwp}" height="${heightHwp}"/>`,
|
|
9591
|
+
` <hp:curSz width="${widthHwp}" height="${heightHwp}"/>`,
|
|
9592
|
+
` <hp:flip horizontal="0" vertical="0"/>`,
|
|
9593
|
+
` <hp:rotationInfo angle="0" centerX="${cx}" centerY="${cy}" rotateimage="1"/>`,
|
|
9594
|
+
` <hp:renderingInfo>`,
|
|
9595
|
+
` <hc:transMatrix e1="1" e2="0" e3="0" e4="0" e5="1" e6="0"/>`,
|
|
9596
|
+
` <hc:scaMatrix e1="1" e2="0" e3="0" e4="0" e5="1" e6="0"/>`,
|
|
9597
|
+
` <hc:rotMatrix e1="1" e2="0" e3="0" e4="0" e5="1" e6="0"/>`,
|
|
9598
|
+
` </hp:renderingInfo>`,
|
|
9599
|
+
` <hc:img binaryItemIDRef="${ref}" bright="0" contrast="0" effect="REAL_PIC" alpha="0"/>`,
|
|
9600
|
+
` <hp:imgRect>`,
|
|
9601
|
+
` <hc:pt0 x="0" y="0"/>`,
|
|
9602
|
+
` <hc:pt1 x="${widthHwp}" y="0"/>`,
|
|
9603
|
+
` <hc:pt2 x="${widthHwp}" y="${heightHwp}"/>`,
|
|
9604
|
+
` <hc:pt3 x="0" y="${heightHwp}"/>`,
|
|
9605
|
+
` </hp:imgRect>`,
|
|
9606
|
+
` <hp:imgClip left="0" right="${natW}" top="0" bottom="${natH}"/>`,
|
|
9607
|
+
` <hp:inMargin left="0" right="0" top="0" bottom="0"/>`,
|
|
9608
|
+
` <hp:imgDim dimwidth="${natW}" dimheight="${natH}"/>`,
|
|
9609
|
+
` <hp:effects/>`,
|
|
9610
|
+
` <hp:sz width="${widthHwp}" widthRelTo="ABSOLUTE" height="${heightHwp}" heightRelTo="ABSOLUTE" protect="0"/>`,
|
|
7018
9611
|
` <hp:pos treatAsChar="1" affectLSpacing="0" flowWithText="1" allowOverlap="0"`,
|
|
7019
|
-
` holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="
|
|
9612
|
+
` holdAnchorAndSO="0" vertRelTo="PARA" horzRelTo="PARA"`,
|
|
7020
9613
|
` vertAlign="TOP" horzAlign="LEFT" vertOffset="0" horzOffset="0"/>`,
|
|
7021
9614
|
` <hp:outMargin left="0" right="0" top="0" bottom="0"/>`,
|
|
7022
|
-
`
|
|
7023
|
-
|
|
7024
|
-
|
|
7025
|
-
|
|
9615
|
+
` </hp:pic>`
|
|
9616
|
+
].join("\n");
|
|
9617
|
+
return [
|
|
9618
|
+
`<hp:p id="${paraId}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
9619
|
+
` <hp:run charPrIDRef="0">`,
|
|
9620
|
+
pic,
|
|
7026
9621
|
` </hp:run>`,
|
|
7027
|
-
|
|
9622
|
+
imgLineseg,
|
|
7028
9623
|
`</hp:p>`
|
|
7029
9624
|
].join("\n");
|
|
7030
9625
|
}
|
|
@@ -7036,57 +9631,51 @@ function makeCodeParagraphs(code, nextId) {
|
|
|
7036
9631
|
return [
|
|
7037
9632
|
`<hp:p id="${id}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
7038
9633
|
` <hp:run charPrIDRef="${CHAR_CODE}"><hp:t>${safe}</hp:t></hp:run>`,
|
|
7039
|
-
LINESEG,
|
|
7040
9634
|
`</hp:p>`
|
|
7041
9635
|
].join("\n");
|
|
7042
9636
|
}).join("\n");
|
|
7043
9637
|
}
|
|
7044
|
-
function generateSectionXml(blocks, styleMap, imageMap) {
|
|
9638
|
+
function generateSectionXml(blocks, styleMap, imageMap, imageDimsMap, secPrXml, colPrXml, masterPageCnt = 0) {
|
|
7045
9639
|
const nextId = makeIdGen();
|
|
7046
9640
|
const firstId = nextId();
|
|
7047
9641
|
const defaultCharPr = styleMap ? styleMap.body.charPr : CHAR_NORMAL;
|
|
7048
9642
|
const defaultParaPr = styleMap ? styleMap.body.paraPr : PARA_NORMAL;
|
|
9643
|
+
const secPrContent = secPrXml ? secPrXml.replace(/masterPageCnt="\d+"/, `masterPageCnt="${masterPageCnt}"`) : [
|
|
9644
|
+
`<hp:secPr id="" textDirection="HORIZONTAL" spaceColumns="1134" tabStop="8000" tabStopVal="4000" tabStopUnit="HWPUNIT" outlineShapeIDRef="1" memoShapeIDRef="0" textVerticalWidthHead="0" masterPageCnt="${masterPageCnt}">`,
|
|
9645
|
+
` <hp:grid lineGrid="0" charGrid="0" wonggojiFormat="0"/>`,
|
|
9646
|
+
` <hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/>`,
|
|
9647
|
+
` <hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/>`,
|
|
9648
|
+
` <hp:lineNumberShape restartType="0" countBy="0" distance="0" startNumber="0"/>`,
|
|
9649
|
+
` <hp:pagePr landscape="WIDELY" width="59528" height="84186" gutterType="LEFT_ONLY">`,
|
|
9650
|
+
` <hp:margin header="4252" footer="4252" gutter="0" left="8504" right="8504" top="8504" bottom="8504"/>`,
|
|
9651
|
+
` </hp:pagePr>`,
|
|
9652
|
+
` <hp:footNotePr>`,
|
|
9653
|
+
` <hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/>`,
|
|
9654
|
+
` <hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/>`,
|
|
9655
|
+
` <hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/>`,
|
|
9656
|
+
` <hp:numbering type="CONTINUOUS" newNum="1"/>`,
|
|
9657
|
+
` <hp:placement place="EACH_COLUMN" beneathText="0"/>`,
|
|
9658
|
+
` </hp:footNotePr>`,
|
|
9659
|
+
` <hp:endNotePr>`,
|
|
9660
|
+
` <hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/>`,
|
|
9661
|
+
` <hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/>`,
|
|
9662
|
+
` <hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/>`,
|
|
9663
|
+
` <hp:numbering type="CONTINUOUS" newNum="1"/>`,
|
|
9664
|
+
` <hp:placement place="END_OF_DOCUMENT" beneathText="0"/>`,
|
|
9665
|
+
` </hp:endNotePr>`,
|
|
9666
|
+
`</hp:secPr>`
|
|
9667
|
+
].join("\n");
|
|
9668
|
+
const colPrContent = colPrXml || `<hp:ctrl>
|
|
9669
|
+
<hp:colPr id="" type="NEWSPAPER" layout="LEFT" colCount="1" sameSz="1" sameGap="0"/>
|
|
9670
|
+
</hp:ctrl>`;
|
|
7049
9671
|
const secPrBlock = [
|
|
7050
9672
|
`<hp:p id="${firstId}" paraPrIDRef="0" styleIDRef="0" pageBreak="0" columnBreak="0" merged="0">`,
|
|
7051
9673
|
` <hp:run charPrIDRef="0">`,
|
|
7052
|
-
|
|
7053
|
-
|
|
7054
|
-
` <hp:startNum pageStartsOn="BOTH" page="0" pic="0" tbl="0" equation="0"/>`,
|
|
7055
|
-
` <hp:visibility hideFirstHeader="0" hideFirstFooter="0" hideFirstMasterPage="0" border="SHOW_ALL" fill="SHOW_ALL" hideFirstPageNum="0" hideFirstEmptyLine="0" showLineNumber="0"/>`,
|
|
7056
|
-
` <hp:lineNumberShape restartType="0" countBy="0" distance="0" startNumber="0"/>`,
|
|
7057
|
-
` <hp:pagePr landscape="WIDELY" width="59528" height="84186" gutterType="LEFT_ONLY">`,
|
|
7058
|
-
` <hp:margin header="4252" footer="4252" gutter="0" left="8504" right="8504" top="8504" bottom="8504"/>`,
|
|
7059
|
-
` </hp:pagePr>`,
|
|
7060
|
-
` <hp:footNotePr>`,
|
|
7061
|
-
` <hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/>`,
|
|
7062
|
-
` <hp:noteLine length="-1" type="SOLID" width="0.12 mm" color="#000000"/>`,
|
|
7063
|
-
` <hp:noteSpacing betweenNotes="283" belowLine="567" aboveLine="850"/>`,
|
|
7064
|
-
` <hp:numbering type="CONTINUOUS" newNum="1"/>`,
|
|
7065
|
-
` <hp:placement place="EACH_COLUMN" beneathText="0"/>`,
|
|
7066
|
-
` </hp:footNotePr>`,
|
|
7067
|
-
` <hp:endNotePr>`,
|
|
7068
|
-
` <hp:autoNumFormat type="DIGIT" userChar="" prefixChar="" suffixChar=")" supscript="0"/>`,
|
|
7069
|
-
` <hp:noteLine length="14692344" type="SOLID" width="0.12 mm" color="#000000"/>`,
|
|
7070
|
-
` <hp:noteSpacing betweenNotes="0" belowLine="567" aboveLine="850"/>`,
|
|
7071
|
-
` <hp:numbering type="CONTINUOUS" newNum="1"/>`,
|
|
7072
|
-
` <hp:placement place="END_OF_DOCUMENT" beneathText="0"/>`,
|
|
7073
|
-
` </hp:endNotePr>`,
|
|
7074
|
-
` <hp:pageBorderFill type="BOTH" borderFillIDRef="1" textBorder="PAPER" headerInside="0" footerInside="0" fillArea="PAPER">`,
|
|
7075
|
-
` <hp:offset left="1417" right="1417" top="1417" bottom="1417"/>`,
|
|
7076
|
-
` </hp:pageBorderFill>`,
|
|
7077
|
-
` <hp:pageBorderFill type="EVEN" borderFillIDRef="1" textBorder="PAPER" headerInside="0" footerInside="0" fillArea="PAPER">`,
|
|
7078
|
-
` <hp:offset left="1417" right="1417" top="1417" bottom="1417"/>`,
|
|
7079
|
-
` </hp:pageBorderFill>`,
|
|
7080
|
-
` <hp:pageBorderFill type="ODD" borderFillIDRef="1" textBorder="PAPER" headerInside="0" footerInside="0" fillArea="PAPER">`,
|
|
7081
|
-
` <hp:offset left="1417" right="1417" top="1417" bottom="1417"/>`,
|
|
7082
|
-
` </hp:pageBorderFill>`,
|
|
7083
|
-
` </hp:secPr>`,
|
|
7084
|
-
` <hp:ctrl>`,
|
|
7085
|
-
` <hp:colPr id="" type="NEWSPAPER" layout="LEFT" colCount="1" sameSz="1" sameGap="0"/>`,
|
|
7086
|
-
` </hp:ctrl>`,
|
|
9674
|
+
secPrContent,
|
|
9675
|
+
colPrContent,
|
|
7087
9676
|
` </hp:run>`,
|
|
7088
9677
|
` <hp:run charPrIDRef="0"><hp:t/></hp:run>`,
|
|
7089
|
-
|
|
9678
|
+
makeLineseg(42520, 1e3),
|
|
7090
9679
|
`</hp:p>`
|
|
7091
9680
|
].join("\n");
|
|
7092
9681
|
const bodyParts = [];
|
|
@@ -7098,23 +9687,26 @@ function generateSectionXml(blocks, styleMap, imageMap) {
|
|
|
7098
9687
|
const level = block.level || 1;
|
|
7099
9688
|
let charPrId;
|
|
7100
9689
|
let paraPrId;
|
|
9690
|
+
let styleId = "0";
|
|
7101
9691
|
if (styleMap) {
|
|
7102
9692
|
const blockType = level === 1 ? "h1" : level === 2 ? "h2" : level === 3 ? "h3" : "h4";
|
|
7103
9693
|
const style = getStyleForBlock(styleMap, blockType);
|
|
7104
9694
|
charPrId = style.charPr;
|
|
7105
9695
|
paraPrId = style.paraPr || defaultParaPr;
|
|
9696
|
+
styleId = style.styleId ?? "0";
|
|
7106
9697
|
} else {
|
|
7107
9698
|
charPrId = headingCharPr(level);
|
|
7108
9699
|
paraPrId = PARA_NORMAL;
|
|
7109
9700
|
}
|
|
7110
|
-
bodyParts.push(makeParagraph(block.text || "", charPrId, paraPrId, nextId));
|
|
9701
|
+
bodyParts.push(makeParagraph(block.text || "", charPrId, paraPrId, nextId, styleId));
|
|
7111
9702
|
break;
|
|
7112
9703
|
}
|
|
7113
9704
|
case "paragraph": {
|
|
7114
9705
|
if (block.text) {
|
|
7115
9706
|
const charPrId = styleMap ? styleMap.body.charPr : CHAR_NORMAL;
|
|
7116
9707
|
const paraPrId = styleMap ? styleMap.body.paraPr : PARA_NORMAL;
|
|
7117
|
-
|
|
9708
|
+
const styleId = styleMap ? styleMap.body.styleId ?? "0" : "0";
|
|
9709
|
+
bodyParts.push(makeParagraph(block.text, charPrId, paraPrId, nextId, styleId));
|
|
7118
9710
|
} else {
|
|
7119
9711
|
bodyParts.push(makeEmptyParagraph(nextId));
|
|
7120
9712
|
}
|
|
@@ -7124,6 +9716,12 @@ function generateSectionXml(blocks, styleMap, imageMap) {
|
|
|
7124
9716
|
bodyParts.push(makeCodeParagraphs(block.text || "", nextId));
|
|
7125
9717
|
break;
|
|
7126
9718
|
}
|
|
9719
|
+
case "blockquote":
|
|
9720
|
+
if (block.text) bodyParts.push(makeBlockquoteParagraph(block.text, nextId));
|
|
9721
|
+
break;
|
|
9722
|
+
case "hr":
|
|
9723
|
+
bodyParts.push(makeHrParagraph(nextId));
|
|
9724
|
+
break;
|
|
7127
9725
|
case "empty":
|
|
7128
9726
|
bodyParts.push(makeEmptyParagraph(nextId));
|
|
7129
9727
|
break;
|
|
@@ -7156,9 +9754,16 @@ function generateSectionXml(blocks, styleMap, imageMap) {
|
|
|
7156
9754
|
break;
|
|
7157
9755
|
case "image": {
|
|
7158
9756
|
const src = block.src || "";
|
|
7159
|
-
const
|
|
7160
|
-
|
|
7161
|
-
|
|
9757
|
+
const srcBasename = src.includes("/") || src.includes("\\") ? src.split(/[\\/]/).pop() : src;
|
|
9758
|
+
const extLower = srcBasename.toLowerCase();
|
|
9759
|
+
if (extLower.endsWith(".wmf") || extLower.endsWith(".emf")) break;
|
|
9760
|
+
const ref = imageMap?.get(src) ?? imageMap?.get(srcBasename);
|
|
9761
|
+
if (ref !== void 0) {
|
|
9762
|
+
const dims = imageDimsMap?.get(ref);
|
|
9763
|
+
const { widthHwp, heightHwp } = dims ? calcHwpSize(dims.width, dims.height) : { widthHwp: 28346, heightHwp: 19843 };
|
|
9764
|
+
const natW = dims ? Math.round(dims.width * 75) : widthHwp;
|
|
9765
|
+
const natH = dims ? Math.round(dims.height * 75) : heightHwp;
|
|
9766
|
+
bodyParts.push(makeImageParagraph(ref, nextId, widthHwp, heightHwp, natW, natH));
|
|
7162
9767
|
} else {
|
|
7163
9768
|
const alt = block.alt || src || "(\uC774\uBBF8\uC9C0)";
|
|
7164
9769
|
bodyParts.push(makeParagraph(`[\uC774\uBBF8\uC9C0: ${alt}]`, CHAR_NORMAL, PARA_NORMAL, nextId));
|
|
@@ -7185,44 +9790,86 @@ async function markdownToHwpx(markdown, options) {
|
|
|
7185
9790
|
const warnings = opts.warnings || [];
|
|
7186
9791
|
let styleMap = null;
|
|
7187
9792
|
let headerXml = HEADER_XML;
|
|
7188
|
-
let
|
|
9793
|
+
let secPrXml;
|
|
9794
|
+
let colPrXml;
|
|
9795
|
+
let masterpages = [];
|
|
7189
9796
|
if (opts.templateArrayBuffer) {
|
|
7190
9797
|
try {
|
|
7191
9798
|
const templateStyles = await extractTemplateStyles(opts.templateArrayBuffer);
|
|
7192
9799
|
styleMap = createStyleMap(templateStyles, warnings);
|
|
7193
|
-
|
|
7194
|
-
|
|
7195
|
-
|
|
7196
|
-
if (
|
|
7197
|
-
headerXml = await headerFile.async("text");
|
|
7198
|
-
}
|
|
9800
|
+
if (templateStyles.headerXml) headerXml = templateStyles.headerXml;
|
|
9801
|
+
if (templateStyles.secPrXml) secPrXml = templateStyles.secPrXml;
|
|
9802
|
+
if (templateStyles.colPrXml) colPrXml = templateStyles.colPrXml;
|
|
9803
|
+
if (templateStyles.masterpages?.length) masterpages = templateStyles.masterpages;
|
|
7199
9804
|
} catch (err) {
|
|
7200
9805
|
const msg = err instanceof Error ? err.message : "\uC54C \uC218 \uC5C6\uB294 \uC624\uB958";
|
|
7201
9806
|
warnings.push(`[warn] \uD15C\uD50C\uB9BF \uCC98\uB9AC \uC2E4\uD328: ${msg}. \uAE30\uBCF8 \uC2A4\uD0C0\uC77C \uC0AC\uC6A9`);
|
|
7202
9807
|
}
|
|
7203
9808
|
}
|
|
7204
9809
|
const imageMap = /* @__PURE__ */ new Map();
|
|
9810
|
+
const imageDimsMap = /* @__PURE__ */ new Map();
|
|
7205
9811
|
const binDataEntries = [];
|
|
9812
|
+
const usedRefs = /* @__PURE__ */ new Set();
|
|
7206
9813
|
if (opts.images && opts.images.length > 0) {
|
|
7207
|
-
for (
|
|
7208
|
-
const img = opts.images[idx];
|
|
7209
|
-
const binId = idx + 1;
|
|
7210
|
-
const format = mimeToFormat(img.mimeType);
|
|
9814
|
+
for (const img of opts.images) {
|
|
7211
9815
|
const nameWithoutExt = img.filename.replace(/\.[^.]+$/, "");
|
|
7212
|
-
const
|
|
7213
|
-
|
|
7214
|
-
|
|
9816
|
+
const format = mimeToFormat(img.mimeType);
|
|
9817
|
+
const ext = format.toLowerCase() === "jpg" ? "jpg" : format.toLowerCase();
|
|
9818
|
+
let ref = nameWithoutExt;
|
|
9819
|
+
let counter = 1;
|
|
9820
|
+
while (usedRefs.has(ref)) ref = `${nameWithoutExt}_${counter++}`;
|
|
9821
|
+
usedRefs.add(ref);
|
|
9822
|
+
const dims = getImageDimensions(img.data) || void 0;
|
|
9823
|
+
binDataEntries.push({ ref, zipPath: `BinData/${ref}.${ext}`, data: img.data, dims });
|
|
9824
|
+
if (dims) imageDimsMap.set(ref, dims);
|
|
9825
|
+
imageMap.set(img.filename, ref);
|
|
9826
|
+
}
|
|
9827
|
+
}
|
|
9828
|
+
const allBlocks = parseMarkdownToBlocks(markdown);
|
|
9829
|
+
for (const block of allBlocks) {
|
|
9830
|
+
if (block.type === "image" && block.src?.startsWith("data:") && !imageMap.has(block.src)) {
|
|
9831
|
+
const commaIdx = block.src.indexOf(",");
|
|
9832
|
+
if (commaIdx === -1) continue;
|
|
9833
|
+
const header = block.src.slice(0, commaIdx);
|
|
9834
|
+
const b64 = block.src.slice(commaIdx + 1);
|
|
9835
|
+
const mimeMatch = header.match(/data:([^;]+)/);
|
|
9836
|
+
const mimeType = mimeMatch?.[1] || "image/png";
|
|
9837
|
+
const format = mimeToFormat(mimeType);
|
|
9838
|
+
const ext = format.toLowerCase() === "jpg" ? "jpg" : format.toLowerCase();
|
|
9839
|
+
const data = Buffer.from(b64, "base64");
|
|
9840
|
+
const ref = `datauri_${binDataEntries.length + 1}`;
|
|
9841
|
+
const dims = getImageDimensions(data) || void 0;
|
|
9842
|
+
imageMap.set(block.src, ref);
|
|
9843
|
+
binDataEntries.push({ ref, zipPath: `BinData/${ref}.${ext}`, data, dims });
|
|
9844
|
+
if (dims) imageDimsMap.set(ref, dims);
|
|
7215
9845
|
}
|
|
7216
9846
|
}
|
|
7217
|
-
if (binDataEntries.length > 0) {
|
|
7218
|
-
const binXml = binDataEntries.map((e) => ` <hh:binData id="${e.id}" type="LINK" format="${e.format}" compress="NO" access="PUBLIC"><hh:sourceFile href="${e.filename}"/></hh:binData>`).join("\n");
|
|
7219
|
-
headerXml = headerXml.replace("</hh:refList>", `${binXml}
|
|
7220
|
-
</hh:refList>`);
|
|
7221
|
-
}
|
|
7222
9847
|
const sectionXml = generateSectionXml(
|
|
7223
|
-
|
|
9848
|
+
allBlocks,
|
|
7224
9849
|
styleMap || void 0,
|
|
7225
|
-
imageMap.size > 0 ? imageMap : void 0
|
|
9850
|
+
imageMap.size > 0 ? imageMap : void 0,
|
|
9851
|
+
imageDimsMap.size > 0 ? imageDimsMap : void 0,
|
|
9852
|
+
secPrXml,
|
|
9853
|
+
colPrXml,
|
|
9854
|
+
masterpages.length
|
|
9855
|
+
);
|
|
9856
|
+
const formatToMediaType = (zipPath) => {
|
|
9857
|
+
const ext = zipPath.split(".").pop()?.toLowerCase() || "";
|
|
9858
|
+
if (ext === "png") return "image/png";
|
|
9859
|
+
if (ext === "gif") return "image/gif";
|
|
9860
|
+
if (ext === "bmp") return "image/bmp";
|
|
9861
|
+
return "image/jpg";
|
|
9862
|
+
};
|
|
9863
|
+
const imageItems = binDataEntries.map((e) => ` <opf:item id="${e.ref}" href="${e.zipPath}" media-type="${formatToMediaType(e.zipPath)}" isEmbeded="1"/>`).join("\n");
|
|
9864
|
+
const masterpageItems = masterpages.map((mp) => {
|
|
9865
|
+
const id = mp.filename.replace("Contents/", "").replace(".xml", "");
|
|
9866
|
+
return ` <opf:item id="${id}" href="${mp.filename}" media-type="application/xml"/>`;
|
|
9867
|
+
}).join("\n");
|
|
9868
|
+
const extraItems = [imageItems, masterpageItems].filter(Boolean).join("\n");
|
|
9869
|
+
const contentHpf = CONTENT_HPF.replace(
|
|
9870
|
+
` <opf:item id="header"`,
|
|
9871
|
+
extraItems ? `${extraItems}
|
|
9872
|
+
<opf:item id="header"` : ` <opf:item id="header"`
|
|
7226
9873
|
);
|
|
7227
9874
|
const zip = new import_jszip6.default();
|
|
7228
9875
|
zip.file("mimetype", "application/hwp+zip", { compression: "STORE" });
|
|
@@ -7232,20 +9879,173 @@ async function markdownToHwpx(markdown, options) {
|
|
|
7232
9879
|
zip.file("version.xml", VERSION_XML);
|
|
7233
9880
|
zip.file("settings.xml", SETTINGS_XML);
|
|
7234
9881
|
zip.file("Preview/PrvText.txt", "");
|
|
7235
|
-
zip.file("Contents/content.hpf",
|
|
9882
|
+
zip.file("Contents/content.hpf", contentHpf);
|
|
7236
9883
|
zip.file("Contents/header.xml", headerXml);
|
|
7237
9884
|
zip.file("Contents/section0.xml", sectionXml);
|
|
7238
|
-
|
|
7239
|
-
|
|
7240
|
-
|
|
7241
|
-
|
|
9885
|
+
for (const mp of masterpages) {
|
|
9886
|
+
zip.file(mp.filename, mp.content);
|
|
9887
|
+
}
|
|
9888
|
+
for (const entry of binDataEntries) {
|
|
9889
|
+
if (entry.data) {
|
|
9890
|
+
zip.file(entry.zipPath, entry.data);
|
|
7242
9891
|
}
|
|
7243
9892
|
}
|
|
7244
9893
|
return await zip.generateAsync({ type: "arraybuffer" });
|
|
7245
9894
|
}
|
|
7246
9895
|
|
|
9896
|
+
// src/xlsx/generator.ts
|
|
9897
|
+
var import_exceljs = __toESM(require("exceljs"), 1);
|
|
9898
|
+
function mimeToExtension(mimeType) {
|
|
9899
|
+
if (mimeType.includes("jpeg") || mimeType.includes("jpg")) return "jpeg";
|
|
9900
|
+
if (mimeType.includes("gif")) return "gif";
|
|
9901
|
+
return "png";
|
|
9902
|
+
}
|
|
9903
|
+
function buildImageMap(images) {
|
|
9904
|
+
const map = /* @__PURE__ */ new Map();
|
|
9905
|
+
if (!images) return map;
|
|
9906
|
+
for (const img of images) map.set(img.filename, img);
|
|
9907
|
+
return map;
|
|
9908
|
+
}
|
|
9909
|
+
async function fillBodySheet(sheet, workbook, blocks, imageMap) {
|
|
9910
|
+
sheet.getColumn(1).width = 80;
|
|
9911
|
+
for (const block of blocks) {
|
|
9912
|
+
switch (block.type) {
|
|
9913
|
+
case "heading": {
|
|
9914
|
+
const level = block.level || 1;
|
|
9915
|
+
const size = level === 1 ? 20 : level === 2 ? 16 : level === 3 ? 14 : 12;
|
|
9916
|
+
const row = sheet.addRow([block.text || ""]);
|
|
9917
|
+
row.getCell(1).font = { bold: true, size };
|
|
9918
|
+
row.getCell(1).alignment = { wrapText: true };
|
|
9919
|
+
break;
|
|
9920
|
+
}
|
|
9921
|
+
case "paragraph": {
|
|
9922
|
+
const row = sheet.addRow([block.text || ""]);
|
|
9923
|
+
row.getCell(1).alignment = { wrapText: true };
|
|
9924
|
+
break;
|
|
9925
|
+
}
|
|
9926
|
+
case "code": {
|
|
9927
|
+
const lines = (block.text || "").split("\n");
|
|
9928
|
+
for (const line of lines) {
|
|
9929
|
+
const row = sheet.addRow([line || " "]);
|
|
9930
|
+
row.getCell(1).font = { name: "Courier New", size: 9 };
|
|
9931
|
+
row.getCell(1).fill = {
|
|
9932
|
+
type: "pattern",
|
|
9933
|
+
pattern: "solid",
|
|
9934
|
+
fgColor: { argb: "FFF2F2F2" }
|
|
9935
|
+
};
|
|
9936
|
+
}
|
|
9937
|
+
break;
|
|
9938
|
+
}
|
|
9939
|
+
case "blockquote": {
|
|
9940
|
+
const row = sheet.addRow([block.text || ""]);
|
|
9941
|
+
row.getCell(1).font = { italic: true, color: { argb: "FF888888" } };
|
|
9942
|
+
row.getCell(1).alignment = { wrapText: true };
|
|
9943
|
+
break;
|
|
9944
|
+
}
|
|
9945
|
+
case "hr": {
|
|
9946
|
+
const row = sheet.addRow([""]);
|
|
9947
|
+
row.getCell(1).border = {
|
|
9948
|
+
bottom: { style: "medium", color: { argb: "FF888888" } }
|
|
9949
|
+
};
|
|
9950
|
+
break;
|
|
9951
|
+
}
|
|
9952
|
+
case "empty": {
|
|
9953
|
+
sheet.addRow([""]);
|
|
9954
|
+
break;
|
|
9955
|
+
}
|
|
9956
|
+
case "list": {
|
|
9957
|
+
for (const item of block.items || []) {
|
|
9958
|
+
const indent = " ".repeat(item.indent);
|
|
9959
|
+
const bullet = block.listType === "ordered" ? `${item.indent + 1}. ` : ["\u2022 ", "\u25E6 ", "\u25AA "][Math.min(item.indent, 2)];
|
|
9960
|
+
const row = sheet.addRow([`${indent}${bullet}${item.text}`]);
|
|
9961
|
+
row.getCell(1).alignment = { wrapText: true };
|
|
9962
|
+
}
|
|
9963
|
+
break;
|
|
9964
|
+
}
|
|
9965
|
+
case "image": {
|
|
9966
|
+
const src = block.src || "";
|
|
9967
|
+
const img = imageMap.get(src);
|
|
9968
|
+
if (img) {
|
|
9969
|
+
const currentRow = sheet.rowCount + 1;
|
|
9970
|
+
const ext = mimeToExtension(img.mimeType);
|
|
9971
|
+
const imageId = workbook.addImage({ base64: Buffer.from(img.data).toString("base64"), extension: ext });
|
|
9972
|
+
sheet.addRow([""]);
|
|
9973
|
+
sheet.addImage(imageId, {
|
|
9974
|
+
tl: { col: 0, row: currentRow - 1 },
|
|
9975
|
+
ext: { width: 300, height: 200 }
|
|
9976
|
+
});
|
|
9977
|
+
sheet.getRow(currentRow).height = 155;
|
|
9978
|
+
} else {
|
|
9979
|
+
const alt = block.alt || src || "(\uC774\uBBF8\uC9C0)";
|
|
9980
|
+
const row = sheet.addRow([`[\uC774\uBBF8\uC9C0: ${alt}]`]);
|
|
9981
|
+
row.getCell(1).font = { italic: true, color: { argb: "FF999999" } };
|
|
9982
|
+
}
|
|
9983
|
+
break;
|
|
9984
|
+
}
|
|
9985
|
+
}
|
|
9986
|
+
}
|
|
9987
|
+
}
|
|
9988
|
+
function fillTableSheet(sheet, rows) {
|
|
9989
|
+
for (let rowIdx = 0; rowIdx < rows.length; rowIdx++) {
|
|
9990
|
+
const cells = rows[rowIdx];
|
|
9991
|
+
const row = sheet.addRow(cells);
|
|
9992
|
+
cells.forEach((cell, colIdx) => {
|
|
9993
|
+
const col = sheet.getColumn(colIdx + 1);
|
|
9994
|
+
col.width = Math.max(col.width ?? 10, Math.min(cell.length + 4, 40));
|
|
9995
|
+
});
|
|
9996
|
+
if (rowIdx === 0) {
|
|
9997
|
+
row.eachCell((cell) => {
|
|
9998
|
+
cell.font = { bold: true };
|
|
9999
|
+
cell.fill = { type: "pattern", pattern: "solid", fgColor: { argb: "FFD9E1F2" } };
|
|
10000
|
+
cell.border = {
|
|
10001
|
+
top: { style: "thin" },
|
|
10002
|
+
bottom: { style: "thin" },
|
|
10003
|
+
left: { style: "thin" },
|
|
10004
|
+
right: { style: "thin" }
|
|
10005
|
+
};
|
|
10006
|
+
cell.alignment = { wrapText: true };
|
|
10007
|
+
});
|
|
10008
|
+
} else {
|
|
10009
|
+
row.eachCell((cell) => {
|
|
10010
|
+
cell.border = {
|
|
10011
|
+
top: { style: "thin" },
|
|
10012
|
+
bottom: { style: "thin" },
|
|
10013
|
+
left: { style: "thin" },
|
|
10014
|
+
right: { style: "thin" }
|
|
10015
|
+
};
|
|
10016
|
+
cell.alignment = { wrapText: true };
|
|
10017
|
+
});
|
|
10018
|
+
}
|
|
10019
|
+
}
|
|
10020
|
+
}
|
|
10021
|
+
async function markdownToXlsx(markdown, options) {
|
|
10022
|
+
const warnings = options?.warnings || [];
|
|
10023
|
+
const imageMap = buildImageMap(options?.images);
|
|
10024
|
+
const blocks = parseMarkdownToBlocks(markdown);
|
|
10025
|
+
const workbook = new import_exceljs.default.Workbook();
|
|
10026
|
+
workbook.created = /* @__PURE__ */ new Date();
|
|
10027
|
+
const tableBlocks = blocks.filter((b) => b.type === "table");
|
|
10028
|
+
const bodyBlocks = blocks.filter((b) => b.type !== "table");
|
|
10029
|
+
const hasBodyContent = bodyBlocks.some((b) => b.type !== "empty");
|
|
10030
|
+
if (hasBodyContent) {
|
|
10031
|
+
const bodySheet = workbook.addWorksheet("\uBCF8\uBB38");
|
|
10032
|
+
await fillBodySheet(bodySheet, workbook, bodyBlocks, imageMap);
|
|
10033
|
+
}
|
|
10034
|
+
tableBlocks.forEach((block, idx) => {
|
|
10035
|
+
if (!block.rows?.length) return;
|
|
10036
|
+
const sheet = workbook.addWorksheet(`Table ${idx + 1}`);
|
|
10037
|
+
fillTableSheet(sheet, block.rows);
|
|
10038
|
+
});
|
|
10039
|
+
if (workbook.worksheets.length === 0) {
|
|
10040
|
+
workbook.addWorksheet("\uBCF8\uBB38");
|
|
10041
|
+
warnings.push("[warn] \uBCC0\uD658\uD560 \uB0B4\uC6A9\uC774 \uC5C6\uC5B4 \uBE48 \uC2DC\uD2B8\uB97C \uC0DD\uC131\uD588\uC2B5\uB2C8\uB2E4.");
|
|
10042
|
+
}
|
|
10043
|
+
const buffer = await workbook.xlsx.writeBuffer();
|
|
10044
|
+
return buffer.buffer.slice(buffer.byteOffset, buffer.byteOffset + buffer.byteLength);
|
|
10045
|
+
}
|
|
10046
|
+
|
|
7247
10047
|
// src/index.ts
|
|
7248
|
-
async function
|
|
10048
|
+
async function parse2(input, options) {
|
|
7249
10049
|
let buffer;
|
|
7250
10050
|
if (typeof input === "string") {
|
|
7251
10051
|
try {
|
|
@@ -7334,6 +10134,7 @@ async function parseDocx(buffer, options) {
|
|
|
7334
10134
|
isPdfFile,
|
|
7335
10135
|
isZipFile,
|
|
7336
10136
|
markdownToHwpx,
|
|
10137
|
+
markdownToXlsx,
|
|
7337
10138
|
parse,
|
|
7338
10139
|
parseDocx,
|
|
7339
10140
|
parseHwp,
|
|
@@ -7341,4 +10142,9 @@ async function parseDocx(buffer, options) {
|
|
|
7341
10142
|
parsePdf,
|
|
7342
10143
|
parseXlsx
|
|
7343
10144
|
});
|
|
10145
|
+
/*! Bundled license information:
|
|
10146
|
+
|
|
10147
|
+
cfb/cfb.js:
|
|
10148
|
+
(*! crc32.js (C) 2014-present SheetJS -- http://sheetjs.com *)
|
|
10149
|
+
*/
|
|
7344
10150
|
//# sourceMappingURL=index.cjs.map
|