@file-viewer/docx 0.3.42 → 0.3.43
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/dist/docx-preview.js +261 -213
- package/dist/docx-preview.min.js +2 -2
- package/dist/docx-preview.min.mjs +2 -2
- package/dist/docx-preview.mjs +261 -213
- package/dist/docx-preview.worker.js +251 -25
- package/package.json +1 -1
|
@@ -11246,6 +11246,175 @@
|
|
|
11246
11246
|
return `<svg xmlns="http://www.w3.org/2000/svg" width="${fmt(physicalWidth)}mm" height="${fmt(physicalHeight)}mm" viewBox="${fmt(bounds.left)} ${fmt(bounds.top)} ${fmt(width)} ${fmt(height)}" preserveAspectRatio="xMidYMid meet" data-docx-metafile="emf"><rect x="${fmt(bounds.left)}" y="${fmt(bounds.top)}" width="${fmt(width)}" height="${fmt(height)}" fill="none" stroke="#999" stroke-width="1"/><text x="${fmt(bounds.left + width / 2)}" y="${fmt(bounds.top + height / 2)}" text-anchor="middle" font-size="12" fill="#666">${esc(message)}</text></svg>`;
|
|
11247
11247
|
}
|
|
11248
11248
|
|
|
11249
|
+
// src/document/symbol-encoding.ts
|
|
11250
|
+
var symbolEncoding = {
|
|
11251
|
+
33: 33,
|
|
11252
|
+
34: 8704,
|
|
11253
|
+
35: 35,
|
|
11254
|
+
36: 8707,
|
|
11255
|
+
37: 37,
|
|
11256
|
+
38: 38,
|
|
11257
|
+
39: 8715,
|
|
11258
|
+
40: 40,
|
|
11259
|
+
41: 41,
|
|
11260
|
+
42: 8727,
|
|
11261
|
+
43: 43,
|
|
11262
|
+
44: 44,
|
|
11263
|
+
45: 8722,
|
|
11264
|
+
46: 46,
|
|
11265
|
+
47: 47,
|
|
11266
|
+
48: 48,
|
|
11267
|
+
49: 49,
|
|
11268
|
+
50: 50,
|
|
11269
|
+
51: 51,
|
|
11270
|
+
52: 52,
|
|
11271
|
+
53: 53,
|
|
11272
|
+
54: 54,
|
|
11273
|
+
55: 55,
|
|
11274
|
+
56: 56,
|
|
11275
|
+
57: 57,
|
|
11276
|
+
58: 58,
|
|
11277
|
+
59: 59,
|
|
11278
|
+
60: 60,
|
|
11279
|
+
61: 61,
|
|
11280
|
+
62: 62,
|
|
11281
|
+
63: 63,
|
|
11282
|
+
64: 8773,
|
|
11283
|
+
65: 913,
|
|
11284
|
+
66: 914,
|
|
11285
|
+
67: 935,
|
|
11286
|
+
69: 917,
|
|
11287
|
+
70: 934,
|
|
11288
|
+
71: 915,
|
|
11289
|
+
72: 919,
|
|
11290
|
+
73: 921,
|
|
11291
|
+
74: 977,
|
|
11292
|
+
75: 922,
|
|
11293
|
+
76: 923,
|
|
11294
|
+
77: 924,
|
|
11295
|
+
78: 925,
|
|
11296
|
+
79: 927,
|
|
11297
|
+
80: 928,
|
|
11298
|
+
81: 920,
|
|
11299
|
+
82: 929,
|
|
11300
|
+
83: 931,
|
|
11301
|
+
84: 932,
|
|
11302
|
+
85: 933,
|
|
11303
|
+
86: 962,
|
|
11304
|
+
88: 926,
|
|
11305
|
+
89: 936,
|
|
11306
|
+
90: 918,
|
|
11307
|
+
91: 91,
|
|
11308
|
+
92: 8756,
|
|
11309
|
+
93: 93,
|
|
11310
|
+
94: 8869,
|
|
11311
|
+
95: 95,
|
|
11312
|
+
97: 945,
|
|
11313
|
+
98: 946,
|
|
11314
|
+
99: 967,
|
|
11315
|
+
100: 948,
|
|
11316
|
+
101: 949,
|
|
11317
|
+
102: 966,
|
|
11318
|
+
103: 947,
|
|
11319
|
+
104: 951,
|
|
11320
|
+
105: 953,
|
|
11321
|
+
106: 981,
|
|
11322
|
+
107: 954,
|
|
11323
|
+
108: 955,
|
|
11324
|
+
110: 957,
|
|
11325
|
+
111: 959,
|
|
11326
|
+
112: 960,
|
|
11327
|
+
113: 952,
|
|
11328
|
+
114: 961,
|
|
11329
|
+
115: 963,
|
|
11330
|
+
116: 964,
|
|
11331
|
+
117: 965,
|
|
11332
|
+
118: 982,
|
|
11333
|
+
119: 969,
|
|
11334
|
+
120: 958,
|
|
11335
|
+
121: 968,
|
|
11336
|
+
122: 950,
|
|
11337
|
+
123: 123,
|
|
11338
|
+
124: 124,
|
|
11339
|
+
125: 125,
|
|
11340
|
+
126: 8764,
|
|
11341
|
+
160: 8364,
|
|
11342
|
+
161: 978,
|
|
11343
|
+
162: 8242,
|
|
11344
|
+
163: 8804,
|
|
11345
|
+
165: 8734,
|
|
11346
|
+
166: 402,
|
|
11347
|
+
167: 9827,
|
|
11348
|
+
168: 9830,
|
|
11349
|
+
169: 9829,
|
|
11350
|
+
170: 9824,
|
|
11351
|
+
171: 8596,
|
|
11352
|
+
172: 8592,
|
|
11353
|
+
173: 8593,
|
|
11354
|
+
174: 8594,
|
|
11355
|
+
175: 8595,
|
|
11356
|
+
176: 176,
|
|
11357
|
+
177: 177,
|
|
11358
|
+
178: 8243,
|
|
11359
|
+
179: 8805,
|
|
11360
|
+
180: 215,
|
|
11361
|
+
181: 8733,
|
|
11362
|
+
182: 8706,
|
|
11363
|
+
183: 8226,
|
|
11364
|
+
184: 247,
|
|
11365
|
+
185: 8800,
|
|
11366
|
+
186: 8801,
|
|
11367
|
+
187: 8776,
|
|
11368
|
+
188: 8230,
|
|
11369
|
+
191: 8629,
|
|
11370
|
+
192: 8501,
|
|
11371
|
+
193: 8465,
|
|
11372
|
+
194: 8476,
|
|
11373
|
+
195: 8472,
|
|
11374
|
+
196: 8855,
|
|
11375
|
+
197: 8853,
|
|
11376
|
+
198: 8709,
|
|
11377
|
+
199: 8745,
|
|
11378
|
+
200: 8746,
|
|
11379
|
+
201: 8835,
|
|
11380
|
+
202: 8839,
|
|
11381
|
+
203: 8836,
|
|
11382
|
+
204: 8834,
|
|
11383
|
+
205: 8838,
|
|
11384
|
+
206: 8712,
|
|
11385
|
+
207: 8713,
|
|
11386
|
+
208: 8736,
|
|
11387
|
+
209: 8711,
|
|
11388
|
+
213: 8719,
|
|
11389
|
+
214: 8730,
|
|
11390
|
+
215: 8901,
|
|
11391
|
+
216: 172,
|
|
11392
|
+
217: 8743,
|
|
11393
|
+
218: 8744,
|
|
11394
|
+
219: 8660,
|
|
11395
|
+
220: 8656,
|
|
11396
|
+
221: 8657,
|
|
11397
|
+
222: 8658,
|
|
11398
|
+
223: 8659,
|
|
11399
|
+
224: 9674,
|
|
11400
|
+
225: 9001,
|
|
11401
|
+
229: 8721,
|
|
11402
|
+
241: 9002,
|
|
11403
|
+
242: 8747,
|
|
11404
|
+
243: 8992,
|
|
11405
|
+
245: 8993
|
|
11406
|
+
};
|
|
11407
|
+
function decodeWordSymbol(font, code) {
|
|
11408
|
+
const original = String.fromCharCode(code);
|
|
11409
|
+
const family = (font ?? "").trim().replace(/^(["'])(.*)\1$/, "$2").trim().toLowerCase();
|
|
11410
|
+
if (family !== "symbol")
|
|
11411
|
+
return { text: original, normalized: false };
|
|
11412
|
+
const slot = code >= 61440 && code <= 61695 ? code - 61440 : code;
|
|
11413
|
+
const unicode = slot >= 0 && slot <= 255 ? symbolEncoding[slot] : void 0;
|
|
11414
|
+
const text = unicode === void 0 ? original : String.fromCharCode(unicode);
|
|
11415
|
+
return { text, normalized: text !== original };
|
|
11416
|
+
}
|
|
11417
|
+
|
|
11249
11418
|
// src/metafile/wmf-to-svg.ts
|
|
11250
11419
|
var PLACEABLE_KEY = 2596720087;
|
|
11251
11420
|
var META = {
|
|
@@ -11321,7 +11490,7 @@
|
|
|
11321
11490
|
return null;
|
|
11322
11491
|
const fileSizeWords = view.getUint32(offset + 6, true);
|
|
11323
11492
|
const objectCount = Math.max(1, view.getUint16(offset + 10, true) || 16);
|
|
11324
|
-
const
|
|
11493
|
+
const declaredEnd = fileSizeWords > 0 ? offset + fileSizeWords * 2 : view.byteLength;
|
|
11325
11494
|
offset += 18;
|
|
11326
11495
|
const width = Math.max(1, bounds.right - bounds.left);
|
|
11327
11496
|
const height = Math.max(1, bounds.bottom - bounds.top);
|
|
@@ -11332,7 +11501,7 @@
|
|
|
11332
11501
|
let records = 0;
|
|
11333
11502
|
const maxRecords = options.maxRecords ?? 1e4;
|
|
11334
11503
|
const maxShapes = options.maxShapes ?? 5e4;
|
|
11335
|
-
const endLimit = Math.min(view.byteLength,
|
|
11504
|
+
const endLimit = Math.min(view.byteLength, declaredEnd);
|
|
11336
11505
|
const emit = (markup) => {
|
|
11337
11506
|
if (!markup || shapeCount >= maxShapes)
|
|
11338
11507
|
return;
|
|
@@ -11343,13 +11512,10 @@
|
|
|
11343
11512
|
const sizeWords = view.getUint32(offset, true);
|
|
11344
11513
|
const fn = view.getUint16(offset + 4, true);
|
|
11345
11514
|
const end = offset + sizeWords * 2;
|
|
11346
|
-
if (sizeWords < 3 || end >
|
|
11515
|
+
if (fn == META.EOF || sizeWords < 3 || end > endLimit)
|
|
11347
11516
|
break;
|
|
11348
11517
|
const params = offset + 6;
|
|
11349
11518
|
switch (fn) {
|
|
11350
|
-
case META.EOF:
|
|
11351
|
-
offset = endLimit;
|
|
11352
|
-
break;
|
|
11353
11519
|
case META.SETBKMODE:
|
|
11354
11520
|
state.bkMode = readInt16(view, params);
|
|
11355
11521
|
break;
|
|
@@ -11459,8 +11625,11 @@
|
|
|
11459
11625
|
};
|
|
11460
11626
|
}
|
|
11461
11627
|
function transformScalarX(state, value) {
|
|
11628
|
+
return Math.abs(transformDeltaX(state, value));
|
|
11629
|
+
}
|
|
11630
|
+
function transformDeltaX(state, value) {
|
|
11462
11631
|
const viewportExt = state.viewportExt ?? state.windowExt;
|
|
11463
|
-
return
|
|
11632
|
+
return value * safeRatio(viewportExt.x, state.windowExt.x);
|
|
11464
11633
|
}
|
|
11465
11634
|
function transformScalarY(state, value) {
|
|
11466
11635
|
const viewportExt = state.viewportExt ?? state.windowExt;
|
|
@@ -11532,7 +11701,7 @@
|
|
|
11532
11701
|
const alignedStringEnd = stringOffset + count + count % 2;
|
|
11533
11702
|
if (alignedStringEnd + 4 > end)
|
|
11534
11703
|
return;
|
|
11535
|
-
const text = decodeText(view, stringOffset, count, state.font
|
|
11704
|
+
const text = decodeText(readTextBytes(view, stringOffset, count), state.font);
|
|
11536
11705
|
const y = readInt16(view, alignedStringEnd);
|
|
11537
11706
|
const x = readInt16(view, alignedStringEnd + 2);
|
|
11538
11707
|
emitText2(text, resolveTextPoint(state, { x, y }), null, state, emit);
|
|
@@ -11546,17 +11715,14 @@
|
|
|
11546
11715
|
let pos = offset + 8;
|
|
11547
11716
|
if (options & 6)
|
|
11548
11717
|
pos += 8;
|
|
11549
|
-
if (pos + count > end)
|
|
11718
|
+
if (pos + count + count % 2 > end)
|
|
11550
11719
|
return;
|
|
11551
|
-
const
|
|
11720
|
+
const bytes = readTextBytes(view, pos, count);
|
|
11721
|
+
const text = decodeText(bytes, state.font);
|
|
11552
11722
|
pos += count + count % 2;
|
|
11553
|
-
const dx =
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
pos += 2;
|
|
11557
|
-
}
|
|
11558
|
-
emitText2(text, resolveTextPoint(state, { x, y }), dx.length ? dx : null, state, emit);
|
|
11559
|
-
advanceCurrentPoint(text, dx.length ? dx : null, state);
|
|
11723
|
+
const dx = count > 0 && pos + count * 2 <= end ? Array.from({ length: count }, (_, i) => readInt16(view, pos + i * 2)) : null;
|
|
11724
|
+
emitText2(text, resolveTextPoint(state, { x, y }), groupGlyphAdvances(bytes, text, dx, state.font), state, emit);
|
|
11725
|
+
advanceCurrentPoint(text, dx, state);
|
|
11560
11726
|
}
|
|
11561
11727
|
function resolveTextPoint(state, declared) {
|
|
11562
11728
|
if (state.textAlign & 1)
|
|
@@ -11568,7 +11734,7 @@
|
|
|
11568
11734
|
return;
|
|
11569
11735
|
const logicalAdvance = dx?.length ? dx.reduce((sum, value) => sum + value, 0) : text.length * state.font.size * 0.5;
|
|
11570
11736
|
state.currentPoint = {
|
|
11571
|
-
x: state.currentPoint.x +
|
|
11737
|
+
x: state.currentPoint.x + transformDeltaX(state, logicalAdvance),
|
|
11572
11738
|
y: state.currentPoint.y
|
|
11573
11739
|
};
|
|
11574
11740
|
}
|
|
@@ -11577,8 +11743,11 @@
|
|
|
11577
11743
|
return;
|
|
11578
11744
|
const font = state.font;
|
|
11579
11745
|
const size = Math.max(1, transformScalarY(state, font.size));
|
|
11746
|
+
const symbol = isSymbolFont(font);
|
|
11747
|
+
const family = symbol ? "Cambria Math, Times New Roman, serif" : quoteFont(font.family);
|
|
11748
|
+
const symbolAttr = symbol ? ` font-family="${escAttr(font.family)}"` : "";
|
|
11580
11749
|
const style = [
|
|
11581
|
-
`font-family:${
|
|
11750
|
+
`font-family:${family}`,
|
|
11582
11751
|
`font-size:${fmt2(size)}px`,
|
|
11583
11752
|
`font-weight:${font.weight >= 600 ? "700" : font.weight}`,
|
|
11584
11753
|
`font-style:${font.italic ? "italic" : "normal"}`
|
|
@@ -11596,14 +11765,17 @@
|
|
|
11596
11765
|
textAnchorAttr2(state.textAlign)
|
|
11597
11766
|
].filter(Boolean).join(" ");
|
|
11598
11767
|
if (!dx || dx.length == 0) {
|
|
11599
|
-
|
|
11768
|
+
const escaped = esc2(text);
|
|
11769
|
+
const content = symbol ? escaped.replace(/[\uf000-\uf0ff]+/g, (glyphs) => `<tspan${symbolAttr}>${glyphs}</tspan>`) : escaped;
|
|
11770
|
+
emit(`<text ${attrs}>${content}</text>`);
|
|
11600
11771
|
return;
|
|
11601
11772
|
}
|
|
11602
11773
|
let x = point.x;
|
|
11603
11774
|
const chars = Array.from(text);
|
|
11604
11775
|
const tspans = chars.map((ch, i) => {
|
|
11605
|
-
const
|
|
11606
|
-
|
|
11776
|
+
const fontAttr = symbol && /[\uf000-\uf0ff]/.test(ch) ? symbolAttr : "";
|
|
11777
|
+
const t = `<tspan x="${fmt2(x)}"${fontAttr}>${esc2(ch)}</tspan>`;
|
|
11778
|
+
x += transformDeltaX(state, dx[i] ?? 0);
|
|
11607
11779
|
return t;
|
|
11608
11780
|
}).join("");
|
|
11609
11781
|
emit(`<text ${attrs}>${tspans}</text>`);
|
|
@@ -11636,8 +11808,17 @@
|
|
|
11636
11808
|
return `text-anchor="middle"`;
|
|
11637
11809
|
return "";
|
|
11638
11810
|
}
|
|
11639
|
-
function
|
|
11640
|
-
|
|
11811
|
+
function readTextBytes(view, offset, count) {
|
|
11812
|
+
return new Uint8Array(view.buffer, view.byteOffset + offset, count);
|
|
11813
|
+
}
|
|
11814
|
+
function isSymbolFont(font) {
|
|
11815
|
+
return font.family.toLowerCase() === "symbol";
|
|
11816
|
+
}
|
|
11817
|
+
function decodeText(bytes, font) {
|
|
11818
|
+
if (isSymbolFont(font)) {
|
|
11819
|
+
return Array.from(bytes, (byte) => byte == 0 || byte == 32 ? String.fromCharCode(byte) : decodeWordSymbol(font.family, 61440 + byte).text).join("").replace(/\0+$/g, "");
|
|
11820
|
+
}
|
|
11821
|
+
const charset = font.charset;
|
|
11641
11822
|
const preferred = charset == 2 ? "symbol" : charset == 134 ? "gb18030" : "windows-1252";
|
|
11642
11823
|
try {
|
|
11643
11824
|
return new TextDecoder(preferred).decode(bytes).replace(/\0+$/g, "");
|
|
@@ -11648,6 +11829,29 @@
|
|
|
11648
11829
|
return result.replace(/\0+$/g, "");
|
|
11649
11830
|
}
|
|
11650
11831
|
}
|
|
11832
|
+
function groupGlyphAdvances(bytes, text, dx, font) {
|
|
11833
|
+
if (!dx || font.charset != 134 || isSymbolFont(font))
|
|
11834
|
+
return dx;
|
|
11835
|
+
const glyphCount = Array.from(text).length;
|
|
11836
|
+
if (glyphCount == bytes.length)
|
|
11837
|
+
return dx;
|
|
11838
|
+
const decoder = new TextDecoder("gb18030");
|
|
11839
|
+
const advances = [];
|
|
11840
|
+
let advance = 0;
|
|
11841
|
+
for (let i = 0; i < bytes.length; i++) {
|
|
11842
|
+
advance += dx[i];
|
|
11843
|
+
const glyph = decoder.decode(bytes.subarray(i, i + 1), { stream: true });
|
|
11844
|
+
if (!glyph)
|
|
11845
|
+
continue;
|
|
11846
|
+
if (Array.from(glyph).length != 1)
|
|
11847
|
+
return null;
|
|
11848
|
+
advances.push(advance);
|
|
11849
|
+
advance = 0;
|
|
11850
|
+
}
|
|
11851
|
+
if (decoder.decode())
|
|
11852
|
+
advances.push(advance);
|
|
11853
|
+
return advances.length >= glyphCount ? advances : null;
|
|
11854
|
+
}
|
|
11651
11855
|
function readPointYX(view, offset) {
|
|
11652
11856
|
return { y: readInt16(view, offset), x: readInt16(view, offset + 2) };
|
|
11653
11857
|
}
|
|
@@ -13460,7 +13664,11 @@
|
|
|
13460
13664
|
const result = { type: "vmlPicture" /* VmlPicture */, children: [] };
|
|
13461
13665
|
for (const el of xml_parser_default.elements(elem)) {
|
|
13462
13666
|
const child = parseVmlElement(el, this);
|
|
13463
|
-
|
|
13667
|
+
if (!child)
|
|
13668
|
+
continue;
|
|
13669
|
+
if (elem.localName === "object" && child.tagName === "image" && child.cssStyle?.position !== "absolute")
|
|
13670
|
+
child.props = { ...child.props, inlineObjectPreview: true };
|
|
13671
|
+
result.children.push(child);
|
|
13464
13672
|
}
|
|
13465
13673
|
return result;
|
|
13466
13674
|
}
|
|
@@ -15427,6 +15635,24 @@
|
|
|
15427
15635
|
}
|
|
15428
15636
|
};
|
|
15429
15637
|
})();
|
|
15638
|
+
/*! @license Adobe Symbol Encoding to Unicode
|
|
15639
|
+
* Copyright (c) 1991-2011 Unicode, Inc. All Rights reserved.
|
|
15640
|
+
*
|
|
15641
|
+
* This file is provided as-is by Unicode, Inc. (The Unicode Consortium). No
|
|
15642
|
+
* claims are made as to fitness for any particular purpose. No warranties of
|
|
15643
|
+
* any kind are expressed or implied. The recipient agrees to determine
|
|
15644
|
+
* applicability of information provided. If this file has been provided on
|
|
15645
|
+
* magnetic media by Unicode, Inc., the sole remedy for any claim will be
|
|
15646
|
+
* exchange of defective media within 90 days of receipt.
|
|
15647
|
+
*
|
|
15648
|
+
* Unicode, Inc. hereby grants the right to freely use the information
|
|
15649
|
+
* supplied in this file in the creation of products supporting the
|
|
15650
|
+
* Unicode Standard, and to make copies of this file in any form for
|
|
15651
|
+
* internal or external distribution as long as this notice remains
|
|
15652
|
+
* attached.
|
|
15653
|
+
*
|
|
15654
|
+
* Source: https://www.unicode.org/Public/MAPPINGS/VENDORS/ADOBE/symbol.txt
|
|
15655
|
+
*/
|
|
15430
15656
|
/*! Bundled license information:
|
|
15431
15657
|
|
|
15432
15658
|
jszip/dist/jszip.min.js:
|