@yudaocode/univer-docs 1.6.213 → 1.6.214
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/WORD_TEMPLATE_PROTOCOL.md +17 -0
- package/lib/cjs/index.js +772 -83
- package/lib/cjs/index.js.map +1 -1
- package/lib/es/index.js +774 -83
- package/lib/es/index.js.map +1 -1
- package/lib/types/index.d.ts +17 -1
- package/package.json +1 -1
package/lib/es/index.js
CHANGED
|
@@ -9659,6 +9659,7 @@ import {
|
|
|
9659
9659
|
AlignTypeV,
|
|
9660
9660
|
BooleanNumber as BooleanNumber2,
|
|
9661
9661
|
CustomRangeType as CustomRangeType5,
|
|
9662
|
+
DashStyleType as DashStyleType2,
|
|
9662
9663
|
DataStreamTreeTokenType as DataStreamTreeTokenType7,
|
|
9663
9664
|
DocStyleType,
|
|
9664
9665
|
generateRandomId as generateRandomId5,
|
|
@@ -9673,6 +9674,7 @@ import {
|
|
|
9673
9674
|
TableSizeType,
|
|
9674
9675
|
TextDecoration as TextDecoration2,
|
|
9675
9676
|
Tools as Tools5,
|
|
9677
|
+
VerticalAlignmentType,
|
|
9676
9678
|
WrapTextType
|
|
9677
9679
|
} from "@univerjs/core";
|
|
9678
9680
|
var DocxImportError = class extends Error {
|
|
@@ -9738,14 +9740,283 @@ function crc32(bytes) {
|
|
|
9738
9740
|
}
|
|
9739
9741
|
return (crc ^ 4294967295) >>> 0;
|
|
9740
9742
|
}
|
|
9743
|
+
var DEFLATE_LEN_BASE = [
|
|
9744
|
+
3,
|
|
9745
|
+
4,
|
|
9746
|
+
5,
|
|
9747
|
+
6,
|
|
9748
|
+
7,
|
|
9749
|
+
8,
|
|
9750
|
+
9,
|
|
9751
|
+
10,
|
|
9752
|
+
11,
|
|
9753
|
+
13,
|
|
9754
|
+
15,
|
|
9755
|
+
17,
|
|
9756
|
+
19,
|
|
9757
|
+
23,
|
|
9758
|
+
27,
|
|
9759
|
+
31,
|
|
9760
|
+
35,
|
|
9761
|
+
43,
|
|
9762
|
+
51,
|
|
9763
|
+
59,
|
|
9764
|
+
67,
|
|
9765
|
+
83,
|
|
9766
|
+
99,
|
|
9767
|
+
115,
|
|
9768
|
+
131,
|
|
9769
|
+
163,
|
|
9770
|
+
195,
|
|
9771
|
+
227,
|
|
9772
|
+
258
|
|
9773
|
+
];
|
|
9774
|
+
var DEFLATE_LEN_EXTRA = [
|
|
9775
|
+
0,
|
|
9776
|
+
0,
|
|
9777
|
+
0,
|
|
9778
|
+
0,
|
|
9779
|
+
0,
|
|
9780
|
+
0,
|
|
9781
|
+
0,
|
|
9782
|
+
0,
|
|
9783
|
+
1,
|
|
9784
|
+
1,
|
|
9785
|
+
1,
|
|
9786
|
+
1,
|
|
9787
|
+
2,
|
|
9788
|
+
2,
|
|
9789
|
+
2,
|
|
9790
|
+
2,
|
|
9791
|
+
3,
|
|
9792
|
+
3,
|
|
9793
|
+
3,
|
|
9794
|
+
3,
|
|
9795
|
+
4,
|
|
9796
|
+
4,
|
|
9797
|
+
4,
|
|
9798
|
+
4,
|
|
9799
|
+
5,
|
|
9800
|
+
5,
|
|
9801
|
+
5,
|
|
9802
|
+
5,
|
|
9803
|
+
0
|
|
9804
|
+
];
|
|
9805
|
+
var DEFLATE_DIST_BASE = [
|
|
9806
|
+
1,
|
|
9807
|
+
2,
|
|
9808
|
+
3,
|
|
9809
|
+
4,
|
|
9810
|
+
5,
|
|
9811
|
+
7,
|
|
9812
|
+
9,
|
|
9813
|
+
13,
|
|
9814
|
+
17,
|
|
9815
|
+
25,
|
|
9816
|
+
33,
|
|
9817
|
+
49,
|
|
9818
|
+
65,
|
|
9819
|
+
97,
|
|
9820
|
+
129,
|
|
9821
|
+
193,
|
|
9822
|
+
257,
|
|
9823
|
+
385,
|
|
9824
|
+
513,
|
|
9825
|
+
769,
|
|
9826
|
+
1025,
|
|
9827
|
+
1537,
|
|
9828
|
+
2049,
|
|
9829
|
+
3073,
|
|
9830
|
+
4097,
|
|
9831
|
+
6145,
|
|
9832
|
+
8193,
|
|
9833
|
+
12289,
|
|
9834
|
+
16385,
|
|
9835
|
+
24577
|
|
9836
|
+
];
|
|
9837
|
+
var DEFLATE_DIST_EXTRA = [
|
|
9838
|
+
0,
|
|
9839
|
+
0,
|
|
9840
|
+
0,
|
|
9841
|
+
0,
|
|
9842
|
+
1,
|
|
9843
|
+
1,
|
|
9844
|
+
2,
|
|
9845
|
+
2,
|
|
9846
|
+
3,
|
|
9847
|
+
3,
|
|
9848
|
+
4,
|
|
9849
|
+
4,
|
|
9850
|
+
5,
|
|
9851
|
+
5,
|
|
9852
|
+
6,
|
|
9853
|
+
6,
|
|
9854
|
+
7,
|
|
9855
|
+
7,
|
|
9856
|
+
8,
|
|
9857
|
+
8,
|
|
9858
|
+
9,
|
|
9859
|
+
9,
|
|
9860
|
+
10,
|
|
9861
|
+
10,
|
|
9862
|
+
11,
|
|
9863
|
+
11,
|
|
9864
|
+
12,
|
|
9865
|
+
12,
|
|
9866
|
+
13,
|
|
9867
|
+
13
|
|
9868
|
+
];
|
|
9869
|
+
function deflateRawSyncPure(src) {
|
|
9870
|
+
const out = [];
|
|
9871
|
+
let bitBuf = 0;
|
|
9872
|
+
let bitCount = 0;
|
|
9873
|
+
const writeBitsLsb = (val, n2) => {
|
|
9874
|
+
for (let i = 0; i < n2; i++) {
|
|
9875
|
+
bitBuf |= (val >>> i & 1) << bitCount;
|
|
9876
|
+
bitCount++;
|
|
9877
|
+
if (bitCount === 8) {
|
|
9878
|
+
out.push(bitBuf);
|
|
9879
|
+
bitBuf = 0;
|
|
9880
|
+
bitCount = 0;
|
|
9881
|
+
}
|
|
9882
|
+
}
|
|
9883
|
+
};
|
|
9884
|
+
const writeCodeMsb = (code, n2) => {
|
|
9885
|
+
for (let i = n2 - 1; i >= 0; i--) {
|
|
9886
|
+
bitBuf |= (code >>> i & 1) << bitCount;
|
|
9887
|
+
bitCount++;
|
|
9888
|
+
if (bitCount === 8) {
|
|
9889
|
+
out.push(bitBuf);
|
|
9890
|
+
bitBuf = 0;
|
|
9891
|
+
bitCount = 0;
|
|
9892
|
+
}
|
|
9893
|
+
}
|
|
9894
|
+
};
|
|
9895
|
+
const writeFixedSym = (sym) => {
|
|
9896
|
+
if (sym <= 143) {
|
|
9897
|
+
writeCodeMsb(48 + sym, 8);
|
|
9898
|
+
} else if (sym <= 255) {
|
|
9899
|
+
writeCodeMsb(400 + (sym - 144), 9);
|
|
9900
|
+
} else if (sym <= 279) {
|
|
9901
|
+
writeCodeMsb(sym - 256, 7);
|
|
9902
|
+
} else {
|
|
9903
|
+
writeCodeMsb(192 + (sym - 280), 8);
|
|
9904
|
+
}
|
|
9905
|
+
};
|
|
9906
|
+
const findLenCode = (len) => {
|
|
9907
|
+
if (len === 258) return 28;
|
|
9908
|
+
let lo = 0;
|
|
9909
|
+
let hi = 27;
|
|
9910
|
+
while (lo < hi) {
|
|
9911
|
+
const mid = lo + hi + 1 >>> 1;
|
|
9912
|
+
if (DEFLATE_LEN_BASE[mid] <= len) lo = mid;
|
|
9913
|
+
else hi = mid - 1;
|
|
9914
|
+
}
|
|
9915
|
+
return lo;
|
|
9916
|
+
};
|
|
9917
|
+
const findDistCode = (dist) => {
|
|
9918
|
+
let lo = 0;
|
|
9919
|
+
let hi = 29;
|
|
9920
|
+
while (lo < hi) {
|
|
9921
|
+
const mid = lo + hi + 1 >>> 1;
|
|
9922
|
+
if (DEFLATE_DIST_BASE[mid] <= dist) lo = mid;
|
|
9923
|
+
else hi = mid - 1;
|
|
9924
|
+
}
|
|
9925
|
+
return lo;
|
|
9926
|
+
};
|
|
9927
|
+
writeBitsLsb(1, 1);
|
|
9928
|
+
writeBitsLsb(1, 2);
|
|
9929
|
+
const n = src.length;
|
|
9930
|
+
const HASH_BITS = 15;
|
|
9931
|
+
const HASH_MASK = (1 << HASH_BITS) - 1;
|
|
9932
|
+
const head = new Int32Array(1 << HASH_BITS);
|
|
9933
|
+
head.fill(-1);
|
|
9934
|
+
const prev = new Int32Array(Math.min(n, 32768) || 1);
|
|
9935
|
+
prev.fill(-1);
|
|
9936
|
+
const hash3 = (p) => (src[p] << 10 ^ src[p + 1] << 5 ^ src[p + 2]) * 40503 & HASH_MASK;
|
|
9937
|
+
let pos = 0;
|
|
9938
|
+
while (pos < n) {
|
|
9939
|
+
let bestLen = 0;
|
|
9940
|
+
let bestDist = 0;
|
|
9941
|
+
if (pos + 3 <= n) {
|
|
9942
|
+
const h = hash3(pos);
|
|
9943
|
+
let cand = head[h];
|
|
9944
|
+
head[h] = pos;
|
|
9945
|
+
prev[pos & 32767] = cand;
|
|
9946
|
+
const minPos = Math.max(0, pos - 32768);
|
|
9947
|
+
const maxMatch = Math.min(258, n - pos);
|
|
9948
|
+
let chain = 0;
|
|
9949
|
+
while (cand >= minPos && chain < 48) {
|
|
9950
|
+
chain++;
|
|
9951
|
+
if (src[cand + bestLen] === src[pos + bestLen] && src[cand] === src[pos]) {
|
|
9952
|
+
let mLen = 0;
|
|
9953
|
+
while (mLen < maxMatch && src[cand + mLen] === src[pos + mLen]) {
|
|
9954
|
+
mLen++;
|
|
9955
|
+
}
|
|
9956
|
+
if (mLen >= 3 && mLen > bestLen && (mLen >= 4 || pos - cand <= 4096)) {
|
|
9957
|
+
bestLen = mLen;
|
|
9958
|
+
bestDist = pos - cand;
|
|
9959
|
+
if (bestLen === maxMatch) break;
|
|
9960
|
+
}
|
|
9961
|
+
}
|
|
9962
|
+
const nextCand = prev[cand & 32767];
|
|
9963
|
+
if (nextCand >= cand) break;
|
|
9964
|
+
cand = nextCand;
|
|
9965
|
+
}
|
|
9966
|
+
}
|
|
9967
|
+
if (bestLen >= 3) {
|
|
9968
|
+
const lIdx = findLenCode(bestLen);
|
|
9969
|
+
writeFixedSym(257 + lIdx);
|
|
9970
|
+
const lExtra = DEFLATE_LEN_EXTRA[lIdx];
|
|
9971
|
+
if (lExtra > 0) {
|
|
9972
|
+
writeBitsLsb(bestLen - DEFLATE_LEN_BASE[lIdx], lExtra);
|
|
9973
|
+
}
|
|
9974
|
+
const dIdx = findDistCode(bestDist);
|
|
9975
|
+
writeCodeMsb(dIdx, 5);
|
|
9976
|
+
const dExtra = DEFLATE_DIST_EXTRA[dIdx];
|
|
9977
|
+
if (dExtra > 0) {
|
|
9978
|
+
writeBitsLsb(bestDist - DEFLATE_DIST_BASE[dIdx], dExtra);
|
|
9979
|
+
}
|
|
9980
|
+
for (let step = 1; step < bestLen; step++) {
|
|
9981
|
+
const adv = pos + step;
|
|
9982
|
+
if (adv + 3 <= n) {
|
|
9983
|
+
const hAdv = hash3(adv);
|
|
9984
|
+
prev[adv & 32767] = head[hAdv];
|
|
9985
|
+
head[hAdv] = adv;
|
|
9986
|
+
}
|
|
9987
|
+
}
|
|
9988
|
+
pos += bestLen;
|
|
9989
|
+
} else {
|
|
9990
|
+
writeFixedSym(src[pos]);
|
|
9991
|
+
pos++;
|
|
9992
|
+
}
|
|
9993
|
+
}
|
|
9994
|
+
writeFixedSym(256);
|
|
9995
|
+
if (bitCount > 0) {
|
|
9996
|
+
out.push(bitBuf);
|
|
9997
|
+
}
|
|
9998
|
+
return Uint8Array.from(out);
|
|
9999
|
+
}
|
|
9741
10000
|
function packStoreZip(files) {
|
|
9742
10001
|
const encoder = new TextEncoder();
|
|
9743
10002
|
const entries = files.map((f) => {
|
|
9744
10003
|
const nameBytes = encoder.encode(f.name);
|
|
9745
10004
|
const dataBytes = typeof f.content === "string" ? encoder.encode(f.content) : f.content;
|
|
10005
|
+
const isPrecompressedMedia = /\.(?:png|jpe?g|gif|webp)$/i.test(f.name);
|
|
10006
|
+
let payloadBytes = dataBytes;
|
|
10007
|
+
let method = 0;
|
|
10008
|
+
if (!isPrecompressedMedia && dataBytes.length >= 64) {
|
|
10009
|
+
const deflated = deflateRawSyncPure(dataBytes);
|
|
10010
|
+
if (deflated.length < dataBytes.length) {
|
|
10011
|
+
payloadBytes = deflated;
|
|
10012
|
+
method = 8;
|
|
10013
|
+
}
|
|
10014
|
+
}
|
|
9746
10015
|
return {
|
|
9747
10016
|
nameBytes,
|
|
9748
10017
|
dataBytes,
|
|
10018
|
+
payloadBytes,
|
|
10019
|
+
method,
|
|
9749
10020
|
crc: crc32(dataBytes),
|
|
9750
10021
|
offset: 0
|
|
9751
10022
|
};
|
|
@@ -9753,7 +10024,7 @@ function packStoreZip(files) {
|
|
|
9753
10024
|
let localTotal = 0;
|
|
9754
10025
|
for (const e of entries) {
|
|
9755
10026
|
e.offset = localTotal;
|
|
9756
|
-
localTotal += 30 + e.nameBytes.length + e.
|
|
10027
|
+
localTotal += 30 + e.nameBytes.length + e.payloadBytes.length;
|
|
9757
10028
|
}
|
|
9758
10029
|
let centralTotal = 0;
|
|
9759
10030
|
for (const e of entries) {
|
|
@@ -9767,19 +10038,19 @@ function packStoreZip(files) {
|
|
|
9767
10038
|
view.setUint32(pos, 67324752, true);
|
|
9768
10039
|
view.setUint16(pos + 4, 20, true);
|
|
9769
10040
|
view.setUint16(pos + 6, 2048, true);
|
|
9770
|
-
view.setUint16(pos + 8,
|
|
10041
|
+
view.setUint16(pos + 8, e.method, true);
|
|
9771
10042
|
view.setUint16(pos + 10, 0, true);
|
|
9772
10043
|
view.setUint16(pos + 12, 22561, true);
|
|
9773
10044
|
view.setUint32(pos + 14, e.crc, true);
|
|
9774
|
-
view.setUint32(pos + 18, e.
|
|
10045
|
+
view.setUint32(pos + 18, e.payloadBytes.length, true);
|
|
9775
10046
|
view.setUint32(pos + 22, e.dataBytes.length, true);
|
|
9776
10047
|
view.setUint16(pos + 26, e.nameBytes.length, true);
|
|
9777
10048
|
view.setUint16(pos + 28, 0, true);
|
|
9778
10049
|
pos += 30;
|
|
9779
10050
|
out.set(e.nameBytes, pos);
|
|
9780
10051
|
pos += e.nameBytes.length;
|
|
9781
|
-
out.set(e.
|
|
9782
|
-
pos += e.
|
|
10052
|
+
out.set(e.payloadBytes, pos);
|
|
10053
|
+
pos += e.payloadBytes.length;
|
|
9783
10054
|
}
|
|
9784
10055
|
const centralDirOffset = pos;
|
|
9785
10056
|
for (const e of entries) {
|
|
@@ -9787,11 +10058,11 @@ function packStoreZip(files) {
|
|
|
9787
10058
|
view.setUint16(pos + 4, 20, true);
|
|
9788
10059
|
view.setUint16(pos + 6, 20, true);
|
|
9789
10060
|
view.setUint16(pos + 8, 2048, true);
|
|
9790
|
-
view.setUint16(pos + 10,
|
|
10061
|
+
view.setUint16(pos + 10, e.method, true);
|
|
9791
10062
|
view.setUint16(pos + 12, 0, true);
|
|
9792
10063
|
view.setUint16(pos + 14, 22561, true);
|
|
9793
10064
|
view.setUint32(pos + 16, e.crc, true);
|
|
9794
|
-
view.setUint32(pos + 20, e.
|
|
10065
|
+
view.setUint32(pos + 20, e.payloadBytes.length, true);
|
|
9795
10066
|
view.setUint32(pos + 24, e.dataBytes.length, true);
|
|
9796
10067
|
view.setUint16(pos + 28, e.nameBytes.length, true);
|
|
9797
10068
|
view.setUint16(pos + 30, 0, true);
|
|
@@ -10272,7 +10543,7 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
|
|
|
10272
10543
|
};
|
|
10273
10544
|
} else if (resolved.visualChrome === "brackets" || resolved.visualChrome === "clean" || !resolved.showingPlaceholder && resolved.visualChrome !== "highlight") {
|
|
10274
10545
|
const rawBgLower = rawTs?.bg?.rgb?.trim().toLowerCase();
|
|
10275
|
-
const isEditorChromeBg = rawBgLower === "#f3f5ff" || rawBgLower === "#eeeff1"
|
|
10546
|
+
const isEditorChromeBg = rawBgLower === "#f3f5ff" || rawBgLower === "#eeeff1";
|
|
10276
10547
|
sdtRunStyle = {
|
|
10277
10548
|
...rawTs ?? {},
|
|
10278
10549
|
bg: resolved.visualChrome === "brackets" || resolved.visualChrome === "clean" || isEditorChromeBg ? void 0 : rawTs?.bg,
|
|
@@ -10385,7 +10656,75 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
|
|
|
10385
10656
|
flushMarkersAt(spanEndExclusive);
|
|
10386
10657
|
return innerXml.join("");
|
|
10387
10658
|
}
|
|
10388
|
-
function
|
|
10659
|
+
function readMarginSideTwips(rawSide) {
|
|
10660
|
+
if (rawSide === null || rawSide === void 0) return void 0;
|
|
10661
|
+
if (typeof rawSide === "number") {
|
|
10662
|
+
return Number.isFinite(rawSide) ? Math.max(0, Math.round(rawSide * 20)) : void 0;
|
|
10663
|
+
}
|
|
10664
|
+
if (typeof rawSide === "object") {
|
|
10665
|
+
const val = rawSide.v;
|
|
10666
|
+
if (typeof val === "number" && Number.isFinite(val)) {
|
|
10667
|
+
return Math.max(0, Math.round(val * 20));
|
|
10668
|
+
}
|
|
10669
|
+
}
|
|
10670
|
+
return void 0;
|
|
10671
|
+
}
|
|
10672
|
+
function extractCellMarginTwips(rawMargin) {
|
|
10673
|
+
if (!rawMargin || typeof rawMargin !== "object") return null;
|
|
10674
|
+
const m = rawMargin;
|
|
10675
|
+
const top = readMarginSideTwips(m.top);
|
|
10676
|
+
const left = readMarginSideTwips(m.start !== void 0 ? m.start : m.left);
|
|
10677
|
+
const bottom = readMarginSideTwips(m.bottom);
|
|
10678
|
+
const right = readMarginSideTwips(m.end !== void 0 ? m.end : m.right);
|
|
10679
|
+
if (top === void 0 && left === void 0 && bottom === void 0 && right === void 0) {
|
|
10680
|
+
return null;
|
|
10681
|
+
}
|
|
10682
|
+
return { top, left, bottom, right };
|
|
10683
|
+
}
|
|
10684
|
+
function marginTwipsEqual(a, b) {
|
|
10685
|
+
return a.top === b.top && a.left === b.left && a.bottom === b.bottom && a.right === b.right;
|
|
10686
|
+
}
|
|
10687
|
+
function buildOoxmlMarginXml(tag, twips) {
|
|
10688
|
+
if (!twips) return "";
|
|
10689
|
+
const parts = [];
|
|
10690
|
+
if (twips.top !== void 0) {
|
|
10691
|
+
parts.push(`<w:top w:w="${twips.top}" w:type="dxa"/>`);
|
|
10692
|
+
}
|
|
10693
|
+
if (twips.left !== void 0) {
|
|
10694
|
+
parts.push(`<w:left w:w="${twips.left}" w:type="dxa"/>`);
|
|
10695
|
+
}
|
|
10696
|
+
if (twips.bottom !== void 0) {
|
|
10697
|
+
parts.push(`<w:bottom w:w="${twips.bottom}" w:type="dxa"/>`);
|
|
10698
|
+
}
|
|
10699
|
+
if (twips.right !== void 0) {
|
|
10700
|
+
parts.push(`<w:right w:w="${twips.right}" w:type="dxa"/>`);
|
|
10701
|
+
}
|
|
10702
|
+
return parts.length > 0 ? `<w:${tag}>${parts.join("")}</w:${tag}>` : "";
|
|
10703
|
+
}
|
|
10704
|
+
function serializeCoreTableBorderTag(tag, edge, fallbackVal = "single", fallbackColor = "CBD5E1", fallbackSz = 4) {
|
|
10705
|
+
if (!edge) {
|
|
10706
|
+
return `<w:${tag} w:val="${fallbackVal}" w:sz="${fallbackSz}" w:space="0" w:color="${fallbackColor}"/>`;
|
|
10707
|
+
}
|
|
10708
|
+
const widthPt = typeof edge.width?.v === "number" ? edge.width.v : 0.5;
|
|
10709
|
+
if (widthPt <= 0 || edge.dashStyle === DashStyleType2.DASH_STYLE_UNSPECIFIED && widthPt === 0) {
|
|
10710
|
+
return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
|
|
10711
|
+
}
|
|
10712
|
+
const wVal = edge.dashStyle === DashStyleType2.DOT ? "dotted" : edge.dashStyle === DashStyleType2.DASH ? "dashed" : fallbackVal;
|
|
10713
|
+
const wSz = Math.max(2, Math.round(widthPt * 8));
|
|
10714
|
+
const wCol = normalizeHex6(edge.color?.rgb) || fallbackColor;
|
|
10715
|
+
return `<w:${tag} w:val="${wVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
|
|
10716
|
+
}
|
|
10717
|
+
function buildTableBordersOoxml(preset, borderDefaults) {
|
|
10718
|
+
if ((!preset || preset === "all") && borderDefaults) {
|
|
10719
|
+
return `<w:tblBorders>${[
|
|
10720
|
+
serializeCoreTableBorderTag("top", borderDefaults.top),
|
|
10721
|
+
serializeCoreTableBorderTag("left", borderDefaults.left),
|
|
10722
|
+
serializeCoreTableBorderTag("bottom", borderDefaults.bottom),
|
|
10723
|
+
serializeCoreTableBorderTag("right", borderDefaults.right),
|
|
10724
|
+
serializeCoreTableBorderTag("insideH", borderDefaults.insideHorizontal),
|
|
10725
|
+
serializeCoreTableBorderTag("insideV", borderDefaults.insideVertical)
|
|
10726
|
+
].join("")}</w:tblBorders>`;
|
|
10727
|
+
}
|
|
10389
10728
|
const solid = '<w:top w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/>';
|
|
10390
10729
|
if (!preset || preset === "all") {
|
|
10391
10730
|
return `<w:tblBorders>${solid}<w:left w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/><w:bottom w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/><w:right w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/><w:insideH w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/><w:insideV w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/></w:tblBorders>`;
|
|
@@ -10401,7 +10740,17 @@ function buildTableBordersOoxml(preset) {
|
|
|
10401
10740
|
}
|
|
10402
10741
|
return '<w:tblBorders><w:top w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/><w:left w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/><w:bottom w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/><w:right w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/><w:insideH w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/><w:insideV w:val="dashed" w:sz="4" w:space="0" w:color="CBD5E1"/></w:tblBorders>';
|
|
10403
10742
|
}
|
|
10404
|
-
function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType, cellBorders, cellDef) {
|
|
10743
|
+
function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType, cellBorders, cellDef, borderDefaults, forceEmit = false) {
|
|
10744
|
+
const hasRestrictivePreset = preset === "empty" || preset === "external" || preset === "internal" || preset === "dash";
|
|
10745
|
+
const hasCustomCellBorders = Boolean(
|
|
10746
|
+
cellBorders && (cellBorders.top || cellBorders.left || cellBorders.bottom || cellBorders.right)
|
|
10747
|
+
);
|
|
10748
|
+
const hasCellDefBorders = Boolean(
|
|
10749
|
+
cellDef && (typeof cellDef.borderTop?.width?.v === "number" || typeof cellDef.borderLeft?.width?.v === "number" || typeof cellDef.borderBottom?.width?.v === "number" || typeof cellDef.borderRight?.width?.v === "number")
|
|
10750
|
+
);
|
|
10751
|
+
if (!forceEmit && !hasRestrictivePreset && !slashType && !hasCustomCellBorders && !hasCellDefBorders) {
|
|
10752
|
+
return "";
|
|
10753
|
+
}
|
|
10405
10754
|
const edgeVal = preset === "dash" ? "dashed" : "single";
|
|
10406
10755
|
const defEdgeMap = {
|
|
10407
10756
|
top: "borderTop",
|
|
@@ -10409,6 +10758,17 @@ function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType,
|
|
|
10409
10758
|
bottom: "borderBottom",
|
|
10410
10759
|
right: "borderRight"
|
|
10411
10760
|
};
|
|
10761
|
+
const isTop = rIdx === 0;
|
|
10762
|
+
const isBot = rIdx === rowCount - 1;
|
|
10763
|
+
const isLeft = cIdx === 0;
|
|
10764
|
+
const isRight = cIdx === colCount - 1;
|
|
10765
|
+
const resolveDefaultEdge = (tag) => {
|
|
10766
|
+
if (!borderDefaults) return void 0;
|
|
10767
|
+
if (tag === "top") return isTop ? borderDefaults.top : borderDefaults.insideHorizontal;
|
|
10768
|
+
if (tag === "bottom") return isBot ? borderDefaults.bottom : borderDefaults.insideHorizontal;
|
|
10769
|
+
if (tag === "left") return isLeft ? borderDefaults.left : borderDefaults.insideVertical;
|
|
10770
|
+
return isRight ? borderDefaults.right : borderDefaults.insideVertical;
|
|
10771
|
+
};
|
|
10412
10772
|
const mk = (active, tag) => {
|
|
10413
10773
|
const customEdge = cellBorders?.[tag];
|
|
10414
10774
|
if (customEdge) {
|
|
@@ -10420,24 +10780,28 @@ function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType,
|
|
|
10420
10780
|
const wCol = normalizeHex6(customEdge.color) || "CBD5E1";
|
|
10421
10781
|
return `<w:${tag} w:val="${wVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
|
|
10422
10782
|
}
|
|
10423
|
-
if (!
|
|
10783
|
+
if (!hasRestrictivePreset && cellDef) {
|
|
10424
10784
|
const defBorder = cellDef[defEdgeMap[tag]];
|
|
10425
10785
|
const defWidthPt = defBorder?.width?.v;
|
|
10426
10786
|
if (typeof defWidthPt === "number") {
|
|
10427
10787
|
if (defWidthPt <= 0) {
|
|
10428
10788
|
return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
|
|
10429
10789
|
}
|
|
10790
|
+
const defVal = defBorder?.dashStyle === DashStyleType2.DOT ? "dotted" : defBorder?.dashStyle === DashStyleType2.DASH ? "dashed" : edgeVal;
|
|
10430
10791
|
const wSz = Math.max(2, Math.round(defWidthPt * 8));
|
|
10431
10792
|
const wCol = normalizeHex6(defBorder?.color?.rgb) || "CBD5E1";
|
|
10432
|
-
return `<w:${tag} w:val="${
|
|
10793
|
+
return `<w:${tag} w:val="${defVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
|
|
10433
10794
|
}
|
|
10434
10795
|
}
|
|
10435
|
-
|
|
10796
|
+
if (!active) {
|
|
10797
|
+
return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
|
|
10798
|
+
}
|
|
10799
|
+
const tblFallbackEdge = resolveDefaultEdge(tag);
|
|
10800
|
+
if (tblFallbackEdge && !hasRestrictivePreset) {
|
|
10801
|
+
return serializeCoreTableBorderTag(tag, tblFallbackEdge, edgeVal);
|
|
10802
|
+
}
|
|
10803
|
+
return `<w:${tag} w:val="${edgeVal}" w:sz="4" w:space="0" w:color="CBD5E1"/>`;
|
|
10436
10804
|
};
|
|
10437
|
-
const isTop = rIdx === 0;
|
|
10438
|
-
const isBot = rIdx === rowCount - 1;
|
|
10439
|
-
const isLeft = cIdx === 0;
|
|
10440
|
-
const isRight = cIdx === colCount - 1;
|
|
10441
10805
|
let topOn = true;
|
|
10442
10806
|
let botOn = true;
|
|
10443
10807
|
let leftOn = true;
|
|
@@ -10776,6 +11140,25 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
|
|
|
10776
11140
|
}
|
|
10777
11141
|
return "";
|
|
10778
11142
|
};
|
|
11143
|
+
const tblCellMarginTwips = extractCellMarginTwips(tblDef?.cellMargin);
|
|
11144
|
+
const resolveCellTcMarXml = (targetCellDef) => {
|
|
11145
|
+
const cellTwips = extractCellMarginTwips(targetCellDef?.margin);
|
|
11146
|
+
if (!cellTwips) return "";
|
|
11147
|
+
if (tblCellMarginTwips && marginTwipsEqual(cellTwips, tblCellMarginTwips)) {
|
|
11148
|
+
return "";
|
|
11149
|
+
}
|
|
11150
|
+
return buildOoxmlMarginXml("tcMar", cellTwips);
|
|
11151
|
+
};
|
|
11152
|
+
const resolveCellVAlignStr = (cellProps, targetCellDef) => {
|
|
11153
|
+
if (cellProps?.verticalAlign) {
|
|
11154
|
+
return cellProps.verticalAlign;
|
|
11155
|
+
}
|
|
11156
|
+
if (targetCellDef?.vAlign === VerticalAlignmentType.TOP) return "top";
|
|
11157
|
+
if (targetCellDef?.vAlign === VerticalAlignmentType.CENTER) return "center";
|
|
11158
|
+
if (targetCellDef?.vAlign === VerticalAlignmentType.BOTTOM) return "bottom";
|
|
11159
|
+
if (targetCellDef?.vAlign === VerticalAlignmentType.BOTH) return "both";
|
|
11160
|
+
return void 0;
|
|
11161
|
+
};
|
|
10779
11162
|
const trXmlList = parsedRows.map((rSpan, rIdx) => {
|
|
10780
11163
|
const rowDef = tblDef?.tableRows?.[rIdx];
|
|
10781
11164
|
const trPrParts = [];
|
|
@@ -10820,9 +11203,33 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
|
|
|
10820
11203
|
contPr.push(`<w:gridSpan w:val="${master.colSpan}"/>`);
|
|
10821
11204
|
}
|
|
10822
11205
|
contPr.push("<w:vMerge/>");
|
|
10823
|
-
|
|
10824
|
-
|
|
11206
|
+
const contBordersXml = buildTcBordersOoxml(
|
|
11207
|
+
tblBorderPreset,
|
|
11208
|
+
rIdx,
|
|
11209
|
+
cIdx,
|
|
11210
|
+
parsedRows.length,
|
|
11211
|
+
colCount,
|
|
11212
|
+
void 0,
|
|
11213
|
+
void 0,
|
|
11214
|
+
contCellDef,
|
|
11215
|
+
tblDef?.borderDefaults,
|
|
11216
|
+
true
|
|
10825
11217
|
);
|
|
11218
|
+
if (contBordersXml) {
|
|
11219
|
+
contPr.push(contBordersXml);
|
|
11220
|
+
}
|
|
11221
|
+
const contFillHex = normalizeHex6(contCellDef?.backgroundColor?.rgb);
|
|
11222
|
+
if (contFillHex) {
|
|
11223
|
+
contPr.push(`<w:shd w:val="clear" w:color="auto" w:fill="${contFillHex}"/>`);
|
|
11224
|
+
}
|
|
11225
|
+
const contTcMarXml = resolveCellTcMarXml(contCellDef);
|
|
11226
|
+
if (contTcMarXml) {
|
|
11227
|
+
contPr.push(contTcMarXml);
|
|
11228
|
+
}
|
|
11229
|
+
const contVAlign = resolveCellVAlignStr(cellProps, contCellDef);
|
|
11230
|
+
if (contVAlign) {
|
|
11231
|
+
contPr.push(`<w:vAlign w:val="${escapeXml(contVAlign)}"/>`);
|
|
11232
|
+
}
|
|
10826
11233
|
tcXmlList.push(`<w:tc><w:tcPr>${contPr.join("")}</w:tcPr><w:p/></w:tc>`);
|
|
10827
11234
|
return;
|
|
10828
11235
|
}
|
|
@@ -10839,25 +11246,33 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
|
|
|
10839
11246
|
if (rowSpan > 1) {
|
|
10840
11247
|
tcPrParts.push('<w:vMerge w:val="restart"/>');
|
|
10841
11248
|
}
|
|
10842
|
-
|
|
10843
|
-
|
|
11249
|
+
const tcBordersXml = buildTcBordersOoxml(
|
|
11250
|
+
tblBorderPreset,
|
|
11251
|
+
rIdx,
|
|
11252
|
+
cIdx,
|
|
11253
|
+
parsedRows.length,
|
|
11254
|
+
colCount,
|
|
11255
|
+
cellProps?.slashType,
|
|
11256
|
+
cellProps?.borders,
|
|
11257
|
+
cellDef,
|
|
11258
|
+
tblDef?.borderDefaults,
|
|
11259
|
+
false
|
|
11260
|
+
);
|
|
11261
|
+
if (tcBordersXml) {
|
|
11262
|
+
tcPrParts.push(tcBordersXml);
|
|
10844
11263
|
}
|
|
10845
11264
|
const fillHex = normalizeHex6(cellDef?.backgroundColor?.rgb);
|
|
10846
11265
|
if (fillHex) {
|
|
10847
11266
|
tcPrParts.push(`<w:shd w:val="clear" w:color="auto" w:fill="${fillHex}"/>`);
|
|
10848
11267
|
}
|
|
10849
|
-
|
|
10850
|
-
|
|
10851
|
-
|
|
10852
|
-
|
|
10853
|
-
|
|
10854
|
-
|
|
10855
|
-
|
|
10856
|
-
|
|
10857
|
-
cellProps?.borders,
|
|
10858
|
-
cellDef
|
|
10859
|
-
)
|
|
10860
|
-
);
|
|
11268
|
+
const tcMarXml = resolveCellTcMarXml(cellDef);
|
|
11269
|
+
if (tcMarXml) {
|
|
11270
|
+
tcPrParts.push(tcMarXml);
|
|
11271
|
+
}
|
|
11272
|
+
const vAlignStr = resolveCellVAlignStr(cellProps, cellDef);
|
|
11273
|
+
if (vAlignStr) {
|
|
11274
|
+
tcPrParts.push(`<w:vAlign w:val="${escapeXml(vAlignStr)}"/>`);
|
|
11275
|
+
}
|
|
10861
11276
|
const cellParas = paragraphs.filter(
|
|
10862
11277
|
(cp) => cp.startIndex >= cSpan.contentStart && cp.startIndex <= cSpan.textEndExclusive
|
|
10863
11278
|
);
|
|
@@ -10913,13 +11328,18 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
|
|
|
10913
11328
|
tblWXml = '<w:tblW w:w="0" w:type="auto"/>';
|
|
10914
11329
|
}
|
|
10915
11330
|
const tblLayoutXml = tblDef?.layout === TableLayoutType.FIXED ? '<w:tblLayout w:type="fixed"/>' : tblDef?.layout === TableLayoutType.AUTO_FIT ? '<w:tblLayout w:type="autofit"/>' : "";
|
|
10916
|
-
const
|
|
11331
|
+
const tblCellMarXml = buildOoxmlMarginXml("tblCellMar", tblCellMarginTwips);
|
|
11332
|
+
const tblStyleIdXml = escapeXml(tblDef?.styleId || "TableGrid");
|
|
11333
|
+
const tblPrInner = [
|
|
11334
|
+
`<w:tblStyle w:val="${tblStyleIdXml}"/>`,
|
|
10917
11335
|
tblDir === "rtl" ? "<w:bidiVisual/>" : "",
|
|
10918
|
-
|
|
10919
|
-
|
|
11336
|
+
tblWXml,
|
|
11337
|
+
buildTableBordersOoxml(tblBorderPreset, tblDef?.borderDefaults),
|
|
11338
|
+
tblLayoutXml,
|
|
11339
|
+
tblCellMarXml
|
|
10920
11340
|
].join("");
|
|
10921
11341
|
blocksXml.push(
|
|
10922
|
-
`<w:tbl><w:tblPr
|
|
11342
|
+
`<w:tbl><w:tblPr>${tblPrInner}</w:tblPr><w:tblGrid>${gridColsXml}</w:tblGrid>${trXmlList.join("")}</w:tbl>`
|
|
10923
11343
|
);
|
|
10924
11344
|
cursor = nextTbl.endIndex;
|
|
10925
11345
|
tCursor++;
|
|
@@ -13755,7 +14175,7 @@ function parseParagraphXmlToBuilder(pXml, relsMap, entries, collectedDrawings, i
|
|
|
13755
14175
|
kind,
|
|
13756
14176
|
lock: lockMatch?.[1] || (isGroupSdt ? "contentLocked" : "sdtLocked"),
|
|
13757
14177
|
dateFormat: dateFmtMatch ? unescapeXml(dateFmtMatch[1]) : void 0,
|
|
13758
|
-
anchorTextStyle: sdtPrStyle ?? firstRunStyle,
|
|
14178
|
+
anchorTextStyle: sdtPrStyle || firstRunStyle ? { ...sdtPrStyle ?? {}, ...firstRunStyle ?? {} } : void 0,
|
|
13759
14179
|
...isRepeatingSec ? { templateText: valText } : {},
|
|
13760
14180
|
listItems: listItemMatches.length > 0 ? listItemMatches.map((m) => ({
|
|
13761
14181
|
displayText: unescapeXml(m[1]),
|
|
@@ -14102,7 +14522,7 @@ function unwrapCellParagraphBlocks(xml) {
|
|
|
14102
14522
|
}
|
|
14103
14523
|
return out;
|
|
14104
14524
|
}
|
|
14105
|
-
function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0) {
|
|
14525
|
+
function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0, pctCellMargins = 0) {
|
|
14106
14526
|
const warnings = [];
|
|
14107
14527
|
const check = (re, code, label) => {
|
|
14108
14528
|
const matches = xml.match(re);
|
|
@@ -14140,6 +14560,13 @@ function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0) {
|
|
|
14140
14560
|
message: "\u68C0\u6D4B\u5230\u52A8\u6001\u9875\u7801/\u6587\u6863\u57DF\uFF08\u5982 PAGE / NUMPAGES\uFF09\uFF0C\u6D4F\u89C8\u5668\u753B\u5E03\u9884\u89C8\u5C06\u663E\u793A\u7F13\u5B58\u9759\u6001\u6587\u672C\uFF0C\u5BFC\u51FA DOCX \u65F6\u4FDD\u7559\u52A8\u6001\u57DF\u6307\u4EE4"
|
|
14141
14561
|
});
|
|
14142
14562
|
}
|
|
14563
|
+
if (pctCellMargins > 0) {
|
|
14564
|
+
warnings.push({
|
|
14565
|
+
code: "PCT_CELL_MARGIN_APPROXIMATED",
|
|
14566
|
+
count: pctCellMargins,
|
|
14567
|
+
message: '\u68C0\u6D4B\u5230\u767E\u5206\u6BD4\u7C7B\u578B\u7684\u8868\u683C\u5355\u5143\u683C\u8FB9\u8DDD\uFF08w:type="pct"\uFF09\uFF0C\u5DF2\u6309 dxa \u8FD1\u4F3C\u6362\u7B97\u4E3A\u56FA\u5B9A\u78C5\u503C'
|
|
14568
|
+
});
|
|
14569
|
+
}
|
|
14143
14570
|
return warnings;
|
|
14144
14571
|
}
|
|
14145
14572
|
async function parseDocxBytesWithReport(bytes, title = "Imported Word Document") {
|
|
@@ -14281,12 +14708,188 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14281
14708
|
const bodyXml = bodyInnerMatch ? bodyInnerMatch[1] : xml;
|
|
14282
14709
|
const collectedDrawings = {};
|
|
14283
14710
|
const inlineBlocksQueue = [];
|
|
14284
|
-
const warningsCounter = {
|
|
14711
|
+
const warningsCounter = {
|
|
14712
|
+
floatingImages: 0,
|
|
14713
|
+
dynamicFields: 0,
|
|
14714
|
+
pctCellMargins: 0
|
|
14715
|
+
};
|
|
14285
14716
|
const xmlTableDirections = {};
|
|
14286
14717
|
const xmlTableBorderPresets = {};
|
|
14287
14718
|
const xmlTableCellProperties = {};
|
|
14288
14719
|
const xmlTableAutoFitWindow = /* @__PURE__ */ new Set();
|
|
14289
14720
|
let detectedTocSpan = null;
|
|
14721
|
+
const OOXML_DEFAULT_CELL_MARGIN_PT = {
|
|
14722
|
+
top: 0,
|
|
14723
|
+
bottom: 0,
|
|
14724
|
+
start: 5.4,
|
|
14725
|
+
end: 5.4
|
|
14726
|
+
};
|
|
14727
|
+
const parseOoxmlBorderTag = (containerXml, edgeTag) => {
|
|
14728
|
+
if (!containerXml) return void 0;
|
|
14729
|
+
const em = containerXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
|
|
14730
|
+
if (!em) return void 0;
|
|
14731
|
+
const eAttrs = em[1] || "";
|
|
14732
|
+
const rawVal = (eAttrs.match(/w:val="([^"]+)"/)?.[1] || "single").toLowerCase();
|
|
14733
|
+
if (rawVal === "none" || rawVal === "nil") {
|
|
14734
|
+
return { style: "none", widthPt: 0 };
|
|
14735
|
+
}
|
|
14736
|
+
const szEighths = Number(eAttrs.match(/w:sz="(\d+)"/)?.[1] ?? 4);
|
|
14737
|
+
const widthPt = Math.max(0.25, Math.round(szEighths / 8 * 100) / 100);
|
|
14738
|
+
const rawColor = (eAttrs.match(/w:color="([0-9a-fA-F]{6})"/)?.[1] || "CBD5E1").toUpperCase();
|
|
14739
|
+
const style = rawVal === "double" ? "double" : rawVal.includes("dash") ? "dashed" : rawVal.includes("dot") ? "dotted" : "single";
|
|
14740
|
+
return { style, widthPt, color: `#${rawColor}` };
|
|
14741
|
+
};
|
|
14742
|
+
const parseOoxmlCellMarginXml = (containerXml, warnOut) => {
|
|
14743
|
+
if (!containerXml) return void 0;
|
|
14744
|
+
const marBlock = containerXml.match(/<w:(?:tcMar|tblCellMar)[\s>][\s\S]*?<\/w:(?:tcMar|tblCellMar)>/)?.[0] || "";
|
|
14745
|
+
if (!marBlock) return void 0;
|
|
14746
|
+
const readSidePt = (tagCandidates) => {
|
|
14747
|
+
for (const tag of tagCandidates) {
|
|
14748
|
+
const m = marBlock.match(new RegExp(`<w:${tag}\\b([^>]*)\\/?>`));
|
|
14749
|
+
if (!m) continue;
|
|
14750
|
+
const attrs = m[1] || "";
|
|
14751
|
+
const rawType = (attrs.match(/\bw:type="([^"]+)"/)?.[1] || "").toLowerCase();
|
|
14752
|
+
const rawW = attrs.match(/\bw:w="(-?\d+(?:\.\d+)?)"/)?.[1];
|
|
14753
|
+
if (rawType === "nil") {
|
|
14754
|
+
return 0;
|
|
14755
|
+
}
|
|
14756
|
+
if (rawType === "auto" && (rawW === void 0 || Number(rawW) === 0)) {
|
|
14757
|
+
return void 0;
|
|
14758
|
+
}
|
|
14759
|
+
if (rawType === "pct") {
|
|
14760
|
+
if (warnOut) {
|
|
14761
|
+
warnOut.pctCellMargins = (warnOut.pctCellMargins ?? 0) + 1;
|
|
14762
|
+
}
|
|
14763
|
+
const numPct = rawW !== void 0 ? Number(rawW) : 0;
|
|
14764
|
+
return Number.isFinite(numPct) ? Math.max(0, Math.round(numPct / 20 * 1e3) / 1e3) : 0;
|
|
14765
|
+
}
|
|
14766
|
+
if (rawW === void 0) {
|
|
14767
|
+
return void 0;
|
|
14768
|
+
}
|
|
14769
|
+
const numDxa = Number(rawW);
|
|
14770
|
+
if (!Number.isFinite(numDxa)) return void 0;
|
|
14771
|
+
return Math.max(0, Math.round(numDxa / 20 * 1e3) / 1e3);
|
|
14772
|
+
}
|
|
14773
|
+
return void 0;
|
|
14774
|
+
};
|
|
14775
|
+
const top = readSidePt(["top"]);
|
|
14776
|
+
const bottom = readSidePt(["bottom"]);
|
|
14777
|
+
const start = readSidePt(["start", "left"]);
|
|
14778
|
+
const end = readSidePt(["end", "right"]);
|
|
14779
|
+
if (top === void 0 && bottom === void 0 && start === void 0 && end === void 0) {
|
|
14780
|
+
return void 0;
|
|
14781
|
+
}
|
|
14782
|
+
return {
|
|
14783
|
+
...top !== void 0 ? { top } : {},
|
|
14784
|
+
...bottom !== void 0 ? { bottom } : {},
|
|
14785
|
+
...start !== void 0 ? { start } : {},
|
|
14786
|
+
...end !== void 0 ? { end } : {}
|
|
14787
|
+
};
|
|
14788
|
+
};
|
|
14789
|
+
const hasAnyMarginSide = (m) => Boolean(
|
|
14790
|
+
m && (m.top !== void 0 || m.bottom !== void 0 || m.start !== void 0 || m.end !== void 0)
|
|
14791
|
+
);
|
|
14792
|
+
const resolveCascadedMarginPt = (tcMar, trMar, tblMar, styleMar) => ({
|
|
14793
|
+
top: tcMar?.top ?? trMar?.top ?? tblMar?.top ?? styleMar?.top ?? OOXML_DEFAULT_CELL_MARGIN_PT.top,
|
|
14794
|
+
bottom: tcMar?.bottom ?? trMar?.bottom ?? tblMar?.bottom ?? styleMar?.bottom ?? OOXML_DEFAULT_CELL_MARGIN_PT.bottom,
|
|
14795
|
+
start: tcMar?.start ?? trMar?.start ?? tblMar?.start ?? styleMar?.start ?? OOXML_DEFAULT_CELL_MARGIN_PT.start,
|
|
14796
|
+
end: tcMar?.end ?? trMar?.end ?? tblMar?.end ?? styleMar?.end ?? OOXML_DEFAULT_CELL_MARGIN_PT.end
|
|
14797
|
+
});
|
|
14798
|
+
const stylesBytes = entries.get("word/styles.xml");
|
|
14799
|
+
const stylesXmlText = stylesBytes ? decoder.decode(stylesBytes) : "";
|
|
14800
|
+
const rawTableStyles = /* @__PURE__ */ new Map();
|
|
14801
|
+
let defaultTableStyleId = "";
|
|
14802
|
+
if (stylesXmlText) {
|
|
14803
|
+
for (const sm of stylesXmlText.matchAll(/<w:style\b([^>]*)>([\s\S]*?)<\/w:style>/g)) {
|
|
14804
|
+
const sAttrs = sm[1] || "";
|
|
14805
|
+
const sType = (sAttrs.match(/\bw:type="([^"]+)"/)?.[1] || "").toLowerCase();
|
|
14806
|
+
if (sType !== "table") continue;
|
|
14807
|
+
const sId = unescapeXml(sAttrs.match(/\bw:styleId="([^"]+)"/)?.[1] || "");
|
|
14808
|
+
if (!sId) continue;
|
|
14809
|
+
if (/\bw:default="(?:1|true|on)"/i.test(sAttrs) || !defaultTableStyleId && sId === "TableNormal") {
|
|
14810
|
+
defaultTableStyleId = sId;
|
|
14811
|
+
}
|
|
14812
|
+
const baseInner = (sm[2] || "").replace(/<w:tblStylePr[\s>][\s\S]*?<\/w:tblStylePr>/g, "");
|
|
14813
|
+
const basedOn = unescapeXml(
|
|
14814
|
+
baseInner.match(/<w:basedOn\b[^>]*\bw:val="([^"]+)"/)?.[1] || ""
|
|
14815
|
+
) || void 0;
|
|
14816
|
+
const sTblPr = baseInner.match(/<w:tblPr[\s>][\s\S]*?<\/w:tblPr>/)?.[0] || "";
|
|
14817
|
+
const styleWarnCounter = { floatingImages: 0, pctCellMargins: 0 };
|
|
14818
|
+
const cellMargin = parseOoxmlCellMarginXml(sTblPr, styleWarnCounter);
|
|
14819
|
+
const sBordersXml = sTblPr.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0] || "";
|
|
14820
|
+
let borders;
|
|
14821
|
+
if (sBordersXml) {
|
|
14822
|
+
borders = {
|
|
14823
|
+
top: parseOoxmlBorderTag(sBordersXml, "top"),
|
|
14824
|
+
bottom: parseOoxmlBorderTag(sBordersXml, "bottom"),
|
|
14825
|
+
left: parseOoxmlBorderTag(sBordersXml, "left"),
|
|
14826
|
+
right: parseOoxmlBorderTag(sBordersXml, "right"),
|
|
14827
|
+
insideH: parseOoxmlBorderTag(sBordersXml, "insideH"),
|
|
14828
|
+
insideV: parseOoxmlBorderTag(sBordersXml, "insideV")
|
|
14829
|
+
};
|
|
14830
|
+
}
|
|
14831
|
+
rawTableStyles.set(sId, {
|
|
14832
|
+
basedOn,
|
|
14833
|
+
cellMargin,
|
|
14834
|
+
pctCount: styleWarnCounter.pctCellMargins ?? 0,
|
|
14835
|
+
borders
|
|
14836
|
+
});
|
|
14837
|
+
}
|
|
14838
|
+
}
|
|
14839
|
+
const countedStylePctIds = /* @__PURE__ */ new Set();
|
|
14840
|
+
const resolveTableStyleCascade = (styleId) => {
|
|
14841
|
+
if (!styleId || !rawTableStyles.has(styleId)) return void 0;
|
|
14842
|
+
const chain = [];
|
|
14843
|
+
const visited = /* @__PURE__ */ new Set();
|
|
14844
|
+
let cur = styleId;
|
|
14845
|
+
while (cur && !visited.has(cur)) {
|
|
14846
|
+
visited.add(cur);
|
|
14847
|
+
const d = rawTableStyles.get(cur);
|
|
14848
|
+
if (!d) break;
|
|
14849
|
+
chain.push({ id: cur, def: d });
|
|
14850
|
+
cur = d.basedOn;
|
|
14851
|
+
}
|
|
14852
|
+
if (chain.length === 0) return void 0;
|
|
14853
|
+
const mergedMargin = {};
|
|
14854
|
+
const mergedBorders = {};
|
|
14855
|
+
for (let i = chain.length - 1; i >= 0; i--) {
|
|
14856
|
+
const { id, def } = chain[i];
|
|
14857
|
+
if (def.pctCount > 0 && !countedStylePctIds.has(id)) {
|
|
14858
|
+
countedStylePctIds.add(id);
|
|
14859
|
+
warningsCounter.pctCellMargins = (warningsCounter.pctCellMargins ?? 0) + def.pctCount;
|
|
14860
|
+
}
|
|
14861
|
+
if (def.cellMargin) {
|
|
14862
|
+
if (def.cellMargin.top !== void 0) mergedMargin.top = def.cellMargin.top;
|
|
14863
|
+
if (def.cellMargin.bottom !== void 0) mergedMargin.bottom = def.cellMargin.bottom;
|
|
14864
|
+
if (def.cellMargin.start !== void 0) mergedMargin.start = def.cellMargin.start;
|
|
14865
|
+
if (def.cellMargin.end !== void 0) mergedMargin.end = def.cellMargin.end;
|
|
14866
|
+
}
|
|
14867
|
+
if (def.borders) {
|
|
14868
|
+
for (const edge of ["top", "bottom", "left", "right", "insideH", "insideV"]) {
|
|
14869
|
+
if (def.borders[edge]) mergedBorders[edge] = def.borders[edge];
|
|
14870
|
+
}
|
|
14871
|
+
}
|
|
14872
|
+
}
|
|
14873
|
+
return {
|
|
14874
|
+
cellMargin: hasAnyMarginSide(mergedMargin) ? mergedMargin : void 0,
|
|
14875
|
+
borders: Object.keys(mergedBorders).length > 0 ? mergedBorders : void 0
|
|
14876
|
+
};
|
|
14877
|
+
};
|
|
14878
|
+
const toCoreTableBorder = (edge) => {
|
|
14879
|
+
if (edge.style === "none" || edge.widthPt === 0) {
|
|
14880
|
+
return {
|
|
14881
|
+
color: { rgb: "#ffffff" },
|
|
14882
|
+
width: { v: 0, u: NumberUnitType2.POINT },
|
|
14883
|
+
dashStyle: DashStyleType2.DASH_STYLE_UNSPECIFIED
|
|
14884
|
+
};
|
|
14885
|
+
}
|
|
14886
|
+
const dashStyle = edge.style === "dotted" ? DashStyleType2.DOT : edge.style === "dashed" ? DashStyleType2.DASH : DashStyleType2.SOLID;
|
|
14887
|
+
return {
|
|
14888
|
+
color: { rgb: (edge.color || "#CBD5E1").toUpperCase() },
|
|
14889
|
+
width: { v: edge.widthPt ?? 0.5, u: NumberUnitType2.POINT },
|
|
14890
|
+
dashStyle
|
|
14891
|
+
};
|
|
14892
|
+
};
|
|
14290
14893
|
const parseTblBordersPreset = (tblPrXml) => {
|
|
14291
14894
|
const bXml = tblPrXml.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0];
|
|
14292
14895
|
if (!bXml) return void 0;
|
|
@@ -14311,6 +14914,13 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14311
14914
|
const tblHeadXml = firstTrMatch && typeof firstTrMatch.index === "number" ? tblXml.slice(0, firstTrMatch.index) : tblXml;
|
|
14312
14915
|
const tblPrXml = tblHeadXml.match(/<w:tblPr[\s>][\s\S]*?<\/w:tblPr>/)?.[0] || "";
|
|
14313
14916
|
const tblGridXml = tblHeadXml.match(/<w:tblGrid[\s>][\s\S]*?<\/w:tblGrid>/)?.[0] || "";
|
|
14917
|
+
const rawTblStyleId = unescapeXml(
|
|
14918
|
+
tblPrXml.match(/<w:tblStyle\b[^>]*\bw:val="([^"]+)"/)?.[1] || ""
|
|
14919
|
+
);
|
|
14920
|
+
const effectiveTblStyleId = rawTblStyleId || defaultTableStyleId;
|
|
14921
|
+
const inheritedTblStyle = effectiveTblStyleId ? resolveTableStyleCascade(effectiveTblStyleId) : void 0;
|
|
14922
|
+
const tblCellMar = parseOoxmlCellMarginXml(tblPrXml, warningsCounter);
|
|
14923
|
+
const tableCellMarginPt = hasAnyMarginSide(tblCellMar) || hasAnyMarginSide(inheritedTblStyle?.cellMargin) ? resolveCascadedMarginPt(void 0, void 0, tblCellMar, inheritedTblStyle?.cellMargin) : void 0;
|
|
14314
14924
|
if (/<w:bidiVisual(?:\s|\/|>)/.test(tblPrXml) && !/<w:bidiVisual\s[^>]*w:val="(?:0|false)"/.test(tblPrXml)) {
|
|
14315
14925
|
xmlTableDirections[tableId] = "rtl";
|
|
14316
14926
|
}
|
|
@@ -14319,34 +14929,27 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14319
14929
|
xmlTableBorderPresets[tableId] = detectedPreset;
|
|
14320
14930
|
}
|
|
14321
14931
|
const tblBordersBlockXml = tblPrXml.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0] || "";
|
|
14322
|
-
const parseOoxmlBorderTag = (containerXml, edgeTag) => {
|
|
14323
|
-
if (!containerXml) return void 0;
|
|
14324
|
-
const em = containerXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
|
|
14325
|
-
if (!em) return void 0;
|
|
14326
|
-
const eAttrs = em[1] || "";
|
|
14327
|
-
const rawVal = (eAttrs.match(/w:val="([^"]+)"/)?.[1] || "single").toLowerCase();
|
|
14328
|
-
if (rawVal === "none" || rawVal === "nil") {
|
|
14329
|
-
return { style: "none", widthPt: 0 };
|
|
14330
|
-
}
|
|
14331
|
-
const szEighths = Number(eAttrs.match(/w:sz="(\d+)"/)?.[1] ?? 4);
|
|
14332
|
-
const widthPt = Math.max(0.25, Math.round(szEighths / 8 * 100) / 100);
|
|
14333
|
-
const rawColor = (eAttrs.match(/w:color="([0-9a-fA-F]{6})"/)?.[1] || "CBD5E1").toUpperCase();
|
|
14334
|
-
const style = rawVal === "double" ? "double" : rawVal.includes("dash") ? "dashed" : rawVal.includes("dot") ? "dotted" : "single";
|
|
14335
|
-
return { style, widthPt, color: `#${rawColor}` };
|
|
14336
|
-
};
|
|
14337
14932
|
const defaultGridEdge = {
|
|
14338
14933
|
style: "single",
|
|
14339
14934
|
widthPt: 0.5,
|
|
14340
14935
|
color: "#CBD5E1"
|
|
14341
14936
|
};
|
|
14342
14937
|
const noneGridEdge = { style: "none", widthPt: 0 };
|
|
14938
|
+
const styleBorders = inheritedTblStyle?.borders;
|
|
14343
14939
|
const tblLevelBorders = tblBordersBlockXml ? {
|
|
14344
|
-
top: parseOoxmlBorderTag(tblBordersBlockXml, "top") ?? noneGridEdge,
|
|
14345
|
-
bottom: parseOoxmlBorderTag(tblBordersBlockXml, "bottom") ?? noneGridEdge,
|
|
14346
|
-
left: parseOoxmlBorderTag(tblBordersBlockXml, "left") ?? noneGridEdge,
|
|
14347
|
-
right: parseOoxmlBorderTag(tblBordersBlockXml, "right") ?? noneGridEdge,
|
|
14348
|
-
insideH: parseOoxmlBorderTag(tblBordersBlockXml, "insideH") ?? noneGridEdge,
|
|
14349
|
-
insideV: parseOoxmlBorderTag(tblBordersBlockXml, "insideV") ?? noneGridEdge
|
|
14940
|
+
top: parseOoxmlBorderTag(tblBordersBlockXml, "top") ?? styleBorders?.top ?? noneGridEdge,
|
|
14941
|
+
bottom: parseOoxmlBorderTag(tblBordersBlockXml, "bottom") ?? styleBorders?.bottom ?? noneGridEdge,
|
|
14942
|
+
left: parseOoxmlBorderTag(tblBordersBlockXml, "left") ?? styleBorders?.left ?? noneGridEdge,
|
|
14943
|
+
right: parseOoxmlBorderTag(tblBordersBlockXml, "right") ?? styleBorders?.right ?? noneGridEdge,
|
|
14944
|
+
insideH: parseOoxmlBorderTag(tblBordersBlockXml, "insideH") ?? styleBorders?.insideH ?? noneGridEdge,
|
|
14945
|
+
insideV: parseOoxmlBorderTag(tblBordersBlockXml, "insideV") ?? styleBorders?.insideV ?? noneGridEdge
|
|
14946
|
+
} : styleBorders ? {
|
|
14947
|
+
top: styleBorders.top ?? noneGridEdge,
|
|
14948
|
+
bottom: styleBorders.bottom ?? noneGridEdge,
|
|
14949
|
+
left: styleBorders.left ?? noneGridEdge,
|
|
14950
|
+
right: styleBorders.right ?? noneGridEdge,
|
|
14951
|
+
insideH: styleBorders.insideH ?? noneGridEdge,
|
|
14952
|
+
insideV: styleBorders.insideV ?? noneGridEdge
|
|
14350
14953
|
} : {
|
|
14351
14954
|
top: defaultGridEdge,
|
|
14352
14955
|
bottom: defaultGridEdge,
|
|
@@ -14355,6 +14958,14 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14355
14958
|
insideH: defaultGridEdge,
|
|
14356
14959
|
insideV: defaultGridEdge
|
|
14357
14960
|
};
|
|
14961
|
+
const tableBorderDefaults = {
|
|
14962
|
+
top: toCoreTableBorder(tblLevelBorders.top),
|
|
14963
|
+
left: toCoreTableBorder(tblLevelBorders.left),
|
|
14964
|
+
bottom: toCoreTableBorder(tblLevelBorders.bottom),
|
|
14965
|
+
right: toCoreTableBorder(tblLevelBorders.right),
|
|
14966
|
+
insideHorizontal: toCoreTableBorder(tblLevelBorders.insideH),
|
|
14967
|
+
insideVertical: toCoreTableBorder(tblLevelBorders.insideV)
|
|
14968
|
+
};
|
|
14358
14969
|
let yudaoTblWidthType;
|
|
14359
14970
|
let yudaoTblWidthDxa;
|
|
14360
14971
|
let yudaoTblWidthPct;
|
|
@@ -14402,11 +15013,13 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14402
15013
|
(m) => Math.max(1, dxaToPt(Number(m[1])))
|
|
14403
15014
|
);
|
|
14404
15015
|
const trMatches = tokenizeNestedTagBlocks(tblXml, "tr");
|
|
14405
|
-
const
|
|
15016
|
+
const trHeadFullList = trMatches.map((trXml) => {
|
|
14406
15017
|
const firstTc = trXml.match(/<w:tc(?=[\s>])/);
|
|
14407
|
-
|
|
14408
|
-
return head.match(/<w:trPr[\s>][\s\S]*?<\/w:trPr>/)?.[0] || "";
|
|
15018
|
+
return firstTc && typeof firstTc.index === "number" ? trXml.slice(0, firstTc.index) : trXml;
|
|
14409
15019
|
});
|
|
15020
|
+
const trHeadList = trHeadFullList.map(
|
|
15021
|
+
(head) => head.match(/<w:trPr[\s>][\s\S]*?<\/w:trPr>/)?.[0] || ""
|
|
15022
|
+
);
|
|
14410
15023
|
let headerRowCount = 0;
|
|
14411
15024
|
while (headerRowCount < trHeadList.length && /<w:tblHeader(?:\s|\/|>)/.test(trHeadList[headerRowCount]) && !/<w:tblHeader\s[^>]*w:val="(?:0|false|off)"/i.test(trHeadList[headerRowCount])) {
|
|
14412
15025
|
headerRowCount++;
|
|
@@ -14417,6 +15030,9 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14417
15030
|
const activeVMerges = /* @__PURE__ */ new Map();
|
|
14418
15031
|
trMatches.forEach((trXml, trIdx) => {
|
|
14419
15032
|
const trPrXml = trHeadList[trIdx] || "";
|
|
15033
|
+
const tblPrExXml = (trHeadFullList[trIdx] || "").match(/<w:tblPrEx[\s>][\s\S]*?<\/w:tblPrEx>/)?.[0] || "";
|
|
15034
|
+
const trCellMar = parseOoxmlCellMarginXml(tblPrExXml, warningsCounter);
|
|
15035
|
+
const resolvedRowCellMarginPt = hasAnyMarginSide(trCellMar) ? resolveCascadedMarginPt(void 0, trCellMar, tblCellMar, inheritedTblStyle?.cellMargin) : void 0;
|
|
14420
15036
|
let rowCantSplit;
|
|
14421
15037
|
const cantSplitMatch = trPrXml.match(/<w:cantSplit\b([^>]*)\/?>/);
|
|
14422
15038
|
if (cantSplitMatch) {
|
|
@@ -14501,6 +15117,14 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14501
15117
|
}
|
|
14502
15118
|
const shdMatch = tcPrXml.match(/<w:shd\s[^>]*w:fill="([0-9a-fA-F]{6})"/);
|
|
14503
15119
|
const vAlignMatch = tcPrXml.match(/<w:vAlign\s[^>]*w:val="([^"]+)"/)?.[1];
|
|
15120
|
+
const tcMar = parseOoxmlCellMarginXml(tcPrXml, warningsCounter);
|
|
15121
|
+
const resolvedCellMarginPt = resolveCascadedMarginPt(
|
|
15122
|
+
tcMar,
|
|
15123
|
+
trCellMar,
|
|
15124
|
+
tblCellMar,
|
|
15125
|
+
inheritedTblStyle?.cellMargin
|
|
15126
|
+
);
|
|
15127
|
+
const resolvedVAlign = vAlignMatch === "top" ? VerticalAlignmentType.TOP : vAlignMatch === "center" ? VerticalAlignmentType.CENTER : vAlignMatch === "bottom" ? VerticalAlignmentType.BOTTOM : vAlignMatch === "both" ? VerticalAlignmentType.BOTH : void 0;
|
|
14504
15128
|
const tcBordersXml = tcPrXml.match(/<w:tcBorders[\s>][\s\S]*?<\/w:tcBorders>/)?.[0] || "";
|
|
14505
15129
|
const parseTcBorderEdge = (edgeTag) => {
|
|
14506
15130
|
const em = tcBordersXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
|
|
@@ -14565,12 +15189,20 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14565
15189
|
colSpan,
|
|
14566
15190
|
rowSpan: 0,
|
|
14567
15191
|
borders: parsedCellBorders,
|
|
15192
|
+
...hasExplicitCellBorders ? { explicitBorders: cellProps.borders } : {},
|
|
15193
|
+
marginPt: resolvedCellMarginPt,
|
|
15194
|
+
...resolvedVAlign !== void 0 ? { vAlign: resolvedVAlign } : {},
|
|
14568
15195
|
...tcWidthType ? { tcWidthType } : {},
|
|
14569
15196
|
...cellSize ? { cellSize } : {},
|
|
14570
15197
|
...yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct } : {}
|
|
14571
15198
|
});
|
|
14572
15199
|
for (let k = 1; k < colSpan; k++) {
|
|
14573
|
-
rowCells.push({
|
|
15200
|
+
rowCells.push({
|
|
15201
|
+
text: "",
|
|
15202
|
+
colSpan: 0,
|
|
15203
|
+
rowSpan: 0,
|
|
15204
|
+
marginPt: resolvedCellMarginPt
|
|
15205
|
+
});
|
|
14574
15206
|
}
|
|
14575
15207
|
} else {
|
|
14576
15208
|
if (isVMergeRestart) {
|
|
@@ -14604,13 +15236,21 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14604
15236
|
rowSpan: 1,
|
|
14605
15237
|
backgroundRgb: shdMatch ? `#${shdMatch[1]}` : void 0,
|
|
14606
15238
|
borders: parsedCellBorders,
|
|
15239
|
+
...hasExplicitCellBorders ? { explicitBorders: cellProps.borders } : {},
|
|
15240
|
+
marginPt: resolvedCellMarginPt,
|
|
15241
|
+
...resolvedVAlign !== void 0 ? { vAlign: resolvedVAlign } : {},
|
|
14607
15242
|
...tcWidthType ? { tcWidthType } : {},
|
|
14608
15243
|
...cellSize ? { cellSize } : {},
|
|
14609
15244
|
...yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct } : {},
|
|
14610
15245
|
...tcParas ? { paragraphs: tcParas } : {}
|
|
14611
15246
|
});
|
|
14612
15247
|
for (let k = 1; k < colSpan; k++) {
|
|
14613
|
-
rowCells.push({
|
|
15248
|
+
rowCells.push({
|
|
15249
|
+
text: "",
|
|
15250
|
+
colSpan: 0,
|
|
15251
|
+
rowSpan: 1,
|
|
15252
|
+
marginPt: resolvedCellMarginPt
|
|
15253
|
+
});
|
|
14614
15254
|
}
|
|
14615
15255
|
}
|
|
14616
15256
|
gridCol += colSpan;
|
|
@@ -14619,6 +15259,7 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14619
15259
|
rows.push(rowCells);
|
|
14620
15260
|
rowMeta.push({
|
|
14621
15261
|
...rowCantSplit !== void 0 ? { cantSplit: rowCantSplit } : {},
|
|
15262
|
+
...resolvedRowCellMarginPt ? { cellMarginPt: resolvedRowCellMarginPt } : {},
|
|
14622
15263
|
trHeight: rowTrHeight
|
|
14623
15264
|
});
|
|
14624
15265
|
}
|
|
@@ -14647,11 +15288,15 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14647
15288
|
return {
|
|
14648
15289
|
kind: "table",
|
|
14649
15290
|
tableId,
|
|
15291
|
+
fromDocxImport: true,
|
|
15292
|
+
...rawTblStyleId ? { styleId: rawTblStyleId } : {},
|
|
14650
15293
|
columnWidthsPt: colWidthsPt.length > 0 ? colWidthsPt : void 0,
|
|
14651
15294
|
repeatHeaderRow,
|
|
14652
15295
|
headerRowCount,
|
|
14653
15296
|
rows,
|
|
14654
15297
|
rowMeta,
|
|
15298
|
+
...tableCellMarginPt ? { tableCellMarginPt } : {},
|
|
15299
|
+
tableBorderDefaults,
|
|
14655
15300
|
...tableSize ? { tableSize } : {},
|
|
14656
15301
|
...tableLayout !== void 0 ? { tableLayout } : {},
|
|
14657
15302
|
...yudaoTblWidthType ? { yudaoTblWidthType } : {},
|
|
@@ -14761,9 +15406,8 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
14761
15406
|
};
|
|
14762
15407
|
}
|
|
14763
15408
|
}
|
|
14764
|
-
|
|
14765
|
-
|
|
14766
|
-
parseStylesXmlIntoDoc(decoder.decode(stylesBytes), themeFonts, docData);
|
|
15409
|
+
if (stylesXmlText) {
|
|
15410
|
+
parseStylesXmlIntoDoc(stylesXmlText, themeFonts, docData);
|
|
14767
15411
|
}
|
|
14768
15412
|
for (const autoTblId of xmlTableAutoFitWindow) {
|
|
14769
15413
|
if (docData.tableSource?.[autoTblId]) {
|
|
@@ -15701,7 +16345,8 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
|
|
|
15701
16345
|
const warnings = scanUnsupportedDocxFeatures(
|
|
15702
16346
|
xml,
|
|
15703
16347
|
warningsCounter.floatingImages,
|
|
15704
|
-
warningsCounter.dynamicFields ?? 0
|
|
16348
|
+
warningsCounter.dynamicFields ?? 0,
|
|
16349
|
+
warningsCounter.pctCellMargins ?? 0
|
|
15705
16350
|
);
|
|
15706
16351
|
return {
|
|
15707
16352
|
documentData: docData,
|
|
@@ -22685,7 +23330,7 @@ function stripSdtAffixes(rawText, spec) {
|
|
|
22685
23330
|
return text;
|
|
22686
23331
|
}
|
|
22687
23332
|
var SDT_CHROME_TEXT_COLORS = /* @__PURE__ */ new Set(["#7d8698", "#9ca3af", "#4e5565", "#2c53f1", "#1b1c1f"]);
|
|
22688
|
-
var SDT_CHROME_BG_COLORS = /* @__PURE__ */ new Set(["#f3f5ff", "#eeeff1"
|
|
23333
|
+
var SDT_CHROME_BG_COLORS = /* @__PURE__ */ new Set(["#f3f5ff", "#eeeff1"]);
|
|
22689
23334
|
function sanitizeLoopCellRunStyle(ts, anchorTypo) {
|
|
22690
23335
|
if (!ts && !anchorTypo) return void 0;
|
|
22691
23336
|
const out = {
|
|
@@ -22789,6 +23434,11 @@ function extractAnchorTypography(ts) {
|
|
|
22789
23434
|
out.cl = { rgb };
|
|
22790
23435
|
has = true;
|
|
22791
23436
|
}
|
|
23437
|
+
const bgRgb = ts.bg?.rgb?.trim();
|
|
23438
|
+
if (bgRgb && !SDT_CHROME_BG_COLORS.has(bgRgb.toLowerCase())) {
|
|
23439
|
+
out.bg = { rgb: bgRgb };
|
|
23440
|
+
has = true;
|
|
23441
|
+
}
|
|
22792
23442
|
return has ? out : void 0;
|
|
22793
23443
|
}
|
|
22794
23444
|
function resolveBodyOffsetTypography(body, offset) {
|
|
@@ -22859,7 +23509,9 @@ function computeSdtVisualStyle(kind, lock, showingPlaceholder, hasBinding, match
|
|
|
22859
23509
|
bl
|
|
22860
23510
|
};
|
|
22861
23511
|
}
|
|
22862
|
-
const
|
|
23512
|
+
const rawBaseBg = baseTypo.bg?.rgb?.trim();
|
|
23513
|
+
const hasAuthorBg = Boolean(rawBaseBg && !SDT_CHROME_BG_COLORS.has(rawBaseBg.toLowerCase()));
|
|
23514
|
+
const bgRgb = !showingPlaceholder && hasAuthorBg ? rawBaseBg : isReadOnly ? "#eeeff1" : "#f3f5ff";
|
|
22863
23515
|
return {
|
|
22864
23516
|
...baseTypo,
|
|
22865
23517
|
bg: { rgb: bgRgb },
|
|
@@ -25551,29 +26203,50 @@ function buildStructuredDocData(params) {
|
|
|
25551
26203
|
width: { v: edge.widthPt ?? 1, u: NumberUnitType6.POINT }
|
|
25552
26204
|
};
|
|
25553
26205
|
};
|
|
25554
|
-
if (cellObj.borders) {
|
|
26206
|
+
if (cellObj.borders && !block.fromDocxImport) {
|
|
25555
26207
|
builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
|
|
25556
26208
|
...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
|
|
25557
26209
|
borders: Tools11.deepClone(cellObj.borders)
|
|
25558
26210
|
};
|
|
26211
|
+
} else if (cellObj.explicitBorders && Object.keys(cellObj.explicitBorders).length > 0) {
|
|
26212
|
+
builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
|
|
26213
|
+
...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
|
|
26214
|
+
borders: Tools11.deepClone(cellObj.explicitBorders)
|
|
26215
|
+
};
|
|
25559
26216
|
}
|
|
26217
|
+
const resolvedCellMarginPt = cellObj.marginPt ?? block.tableCellMarginPt;
|
|
26218
|
+
const cellMarginObj = resolvedCellMarginPt ? {
|
|
26219
|
+
start: { v: resolvedCellMarginPt.start, u: NumberUnitType6.POINT },
|
|
26220
|
+
end: { v: resolvedCellMarginPt.end, u: NumberUnitType6.POINT },
|
|
26221
|
+
top: { v: resolvedCellMarginPt.top, u: NumberUnitType6.POINT },
|
|
26222
|
+
bottom: { v: resolvedCellMarginPt.bottom, u: NumberUnitType6.POINT }
|
|
26223
|
+
} : {
|
|
26224
|
+
start: { v: 8, u: NumberUnitType6.POINT },
|
|
26225
|
+
end: { v: 8, u: NumberUnitType6.POINT },
|
|
26226
|
+
top: { v: 4, u: NumberUnitType6.POINT },
|
|
26227
|
+
bottom: { v: 4, u: NumberUnitType6.POINT }
|
|
26228
|
+
};
|
|
26229
|
+
const borderSrc = block.fromDocxImport ? cellObj.explicitBorders : cellObj.borders;
|
|
25560
26230
|
cellDefs.push({
|
|
25561
|
-
margin:
|
|
25562
|
-
start: { v: 8, u: NumberUnitType6.POINT },
|
|
25563
|
-
end: { v: 8, u: NumberUnitType6.POINT },
|
|
25564
|
-
top: { v: 4, u: NumberUnitType6.POINT },
|
|
25565
|
-
bottom: { v: 4, u: NumberUnitType6.POINT }
|
|
25566
|
-
},
|
|
26231
|
+
margin: cellMarginObj,
|
|
25567
26232
|
rowSpan: cellObj.rowSpan ?? 1,
|
|
25568
26233
|
columnSpan: cellObj.colSpan ?? 1,
|
|
26234
|
+
...cellObj.vAlign !== void 0 ? { vAlign: cellObj.vAlign } : {},
|
|
25569
26235
|
...cellObj.tcWidthType ? { tcWidthType: cellObj.tcWidthType } : {},
|
|
25570
26236
|
...cellObj.cellSize ? { size: Tools11.deepClone(cellObj.cellSize) } : {},
|
|
25571
26237
|
...cellObj.yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct: cellObj.yudaoTcWidthPct } : {},
|
|
25572
26238
|
...cellObj.backgroundRgb ? { backgroundColor: { rgb: cellObj.backgroundRgb } } : {},
|
|
25573
|
-
|
|
25574
|
-
|
|
25575
|
-
|
|
25576
|
-
|
|
26239
|
+
...block.fromDocxImport ? {
|
|
26240
|
+
...borderSrc?.top ? { borderTop: toCellBorderObj(borderSrc.top) } : {},
|
|
26241
|
+
...borderSrc?.bottom ? { borderBottom: toCellBorderObj(borderSrc.bottom) } : {},
|
|
26242
|
+
...borderSrc?.left ? { borderLeft: toCellBorderObj(borderSrc.left) } : {},
|
|
26243
|
+
...borderSrc?.right ? { borderRight: toCellBorderObj(borderSrc.right) } : {}
|
|
26244
|
+
} : {
|
|
26245
|
+
borderTop: toCellBorderObj(cellObj.borders?.top),
|
|
26246
|
+
borderBottom: toCellBorderObj(cellObj.borders?.bottom),
|
|
26247
|
+
borderLeft: toCellBorderObj(cellObj.borders?.left),
|
|
26248
|
+
borderRight: toCellBorderObj(cellObj.borders?.right)
|
|
26249
|
+
}
|
|
25577
26250
|
});
|
|
25578
26251
|
}
|
|
25579
26252
|
const effectiveHdrCount = typeof block.headerRowCount === "number" ? Math.max(0, block.headerRowCount) : block.repeatHeaderRow === false ? 0 : 1;
|
|
@@ -25584,6 +26257,14 @@ function buildStructuredDocData(params) {
|
|
|
25584
26257
|
const rMeta = block.rowMeta?.[rIdx];
|
|
25585
26258
|
tableRows.push({
|
|
25586
26259
|
tableCells: cellDefs,
|
|
26260
|
+
...rMeta?.cellMarginPt ? {
|
|
26261
|
+
cellMargin: {
|
|
26262
|
+
start: { v: rMeta.cellMarginPt.start, u: NumberUnitType6.POINT },
|
|
26263
|
+
end: { v: rMeta.cellMarginPt.end, u: NumberUnitType6.POINT },
|
|
26264
|
+
top: { v: rMeta.cellMarginPt.top, u: NumberUnitType6.POINT },
|
|
26265
|
+
bottom: { v: rMeta.cellMarginPt.bottom, u: NumberUnitType6.POINT }
|
|
26266
|
+
}
|
|
26267
|
+
} : {},
|
|
25587
26268
|
trHeight: rMeta?.trHeight ? Tools11.deepClone(rMeta.trHeight) : {
|
|
25588
26269
|
val: { v: 24, u: NumberUnitType6.POINT },
|
|
25589
26270
|
hRule: TableRowHeightRule4.AT_LEAST
|
|
@@ -25621,6 +26302,16 @@ function buildStructuredDocData(params) {
|
|
|
25621
26302
|
},
|
|
25622
26303
|
type: 0
|
|
25623
26304
|
},
|
|
26305
|
+
...block.styleId ? { styleId: block.styleId } : {},
|
|
26306
|
+
...block.tableCellMarginPt ? {
|
|
26307
|
+
cellMargin: {
|
|
26308
|
+
start: { v: block.tableCellMarginPt.start, u: NumberUnitType6.POINT },
|
|
26309
|
+
end: { v: block.tableCellMarginPt.end, u: NumberUnitType6.POINT },
|
|
26310
|
+
top: { v: block.tableCellMarginPt.top, u: NumberUnitType6.POINT },
|
|
26311
|
+
bottom: { v: block.tableCellMarginPt.bottom, u: NumberUnitType6.POINT }
|
|
26312
|
+
}
|
|
26313
|
+
} : {},
|
|
26314
|
+
...block.tableBorderDefaults ? { borderDefaults: Tools11.deepClone(block.tableBorderDefaults) } : {},
|
|
25624
26315
|
...block.tableLayout !== void 0 ? { layout: block.tableLayout } : {},
|
|
25625
26316
|
...block.yudaoTblWidthType ? { yudaoTblWidthType: block.yudaoTblWidthType } : {},
|
|
25626
26317
|
...block.yudaoTblWidthDxa !== void 0 ? { yudaoTblWidthDxa: block.yudaoTblWidthDxa } : {},
|