@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/lib/cjs/index.js CHANGED
@@ -10117,14 +10117,283 @@ function crc32(bytes) {
10117
10117
  }
10118
10118
  return (crc ^ 4294967295) >>> 0;
10119
10119
  }
10120
+ var DEFLATE_LEN_BASE = [
10121
+ 3,
10122
+ 4,
10123
+ 5,
10124
+ 6,
10125
+ 7,
10126
+ 8,
10127
+ 9,
10128
+ 10,
10129
+ 11,
10130
+ 13,
10131
+ 15,
10132
+ 17,
10133
+ 19,
10134
+ 23,
10135
+ 27,
10136
+ 31,
10137
+ 35,
10138
+ 43,
10139
+ 51,
10140
+ 59,
10141
+ 67,
10142
+ 83,
10143
+ 99,
10144
+ 115,
10145
+ 131,
10146
+ 163,
10147
+ 195,
10148
+ 227,
10149
+ 258
10150
+ ];
10151
+ var DEFLATE_LEN_EXTRA = [
10152
+ 0,
10153
+ 0,
10154
+ 0,
10155
+ 0,
10156
+ 0,
10157
+ 0,
10158
+ 0,
10159
+ 0,
10160
+ 1,
10161
+ 1,
10162
+ 1,
10163
+ 1,
10164
+ 2,
10165
+ 2,
10166
+ 2,
10167
+ 2,
10168
+ 3,
10169
+ 3,
10170
+ 3,
10171
+ 3,
10172
+ 4,
10173
+ 4,
10174
+ 4,
10175
+ 4,
10176
+ 5,
10177
+ 5,
10178
+ 5,
10179
+ 5,
10180
+ 0
10181
+ ];
10182
+ var DEFLATE_DIST_BASE = [
10183
+ 1,
10184
+ 2,
10185
+ 3,
10186
+ 4,
10187
+ 5,
10188
+ 7,
10189
+ 9,
10190
+ 13,
10191
+ 17,
10192
+ 25,
10193
+ 33,
10194
+ 49,
10195
+ 65,
10196
+ 97,
10197
+ 129,
10198
+ 193,
10199
+ 257,
10200
+ 385,
10201
+ 513,
10202
+ 769,
10203
+ 1025,
10204
+ 1537,
10205
+ 2049,
10206
+ 3073,
10207
+ 4097,
10208
+ 6145,
10209
+ 8193,
10210
+ 12289,
10211
+ 16385,
10212
+ 24577
10213
+ ];
10214
+ var DEFLATE_DIST_EXTRA = [
10215
+ 0,
10216
+ 0,
10217
+ 0,
10218
+ 0,
10219
+ 1,
10220
+ 1,
10221
+ 2,
10222
+ 2,
10223
+ 3,
10224
+ 3,
10225
+ 4,
10226
+ 4,
10227
+ 5,
10228
+ 5,
10229
+ 6,
10230
+ 6,
10231
+ 7,
10232
+ 7,
10233
+ 8,
10234
+ 8,
10235
+ 9,
10236
+ 9,
10237
+ 10,
10238
+ 10,
10239
+ 11,
10240
+ 11,
10241
+ 12,
10242
+ 12,
10243
+ 13,
10244
+ 13
10245
+ ];
10246
+ function deflateRawSyncPure(src) {
10247
+ const out = [];
10248
+ let bitBuf = 0;
10249
+ let bitCount = 0;
10250
+ const writeBitsLsb = (val, n2) => {
10251
+ for (let i = 0; i < n2; i++) {
10252
+ bitBuf |= (val >>> i & 1) << bitCount;
10253
+ bitCount++;
10254
+ if (bitCount === 8) {
10255
+ out.push(bitBuf);
10256
+ bitBuf = 0;
10257
+ bitCount = 0;
10258
+ }
10259
+ }
10260
+ };
10261
+ const writeCodeMsb = (code, n2) => {
10262
+ for (let i = n2 - 1; i >= 0; i--) {
10263
+ bitBuf |= (code >>> i & 1) << bitCount;
10264
+ bitCount++;
10265
+ if (bitCount === 8) {
10266
+ out.push(bitBuf);
10267
+ bitBuf = 0;
10268
+ bitCount = 0;
10269
+ }
10270
+ }
10271
+ };
10272
+ const writeFixedSym = (sym) => {
10273
+ if (sym <= 143) {
10274
+ writeCodeMsb(48 + sym, 8);
10275
+ } else if (sym <= 255) {
10276
+ writeCodeMsb(400 + (sym - 144), 9);
10277
+ } else if (sym <= 279) {
10278
+ writeCodeMsb(sym - 256, 7);
10279
+ } else {
10280
+ writeCodeMsb(192 + (sym - 280), 8);
10281
+ }
10282
+ };
10283
+ const findLenCode = (len) => {
10284
+ if (len === 258) return 28;
10285
+ let lo = 0;
10286
+ let hi = 27;
10287
+ while (lo < hi) {
10288
+ const mid = lo + hi + 1 >>> 1;
10289
+ if (DEFLATE_LEN_BASE[mid] <= len) lo = mid;
10290
+ else hi = mid - 1;
10291
+ }
10292
+ return lo;
10293
+ };
10294
+ const findDistCode = (dist) => {
10295
+ let lo = 0;
10296
+ let hi = 29;
10297
+ while (lo < hi) {
10298
+ const mid = lo + hi + 1 >>> 1;
10299
+ if (DEFLATE_DIST_BASE[mid] <= dist) lo = mid;
10300
+ else hi = mid - 1;
10301
+ }
10302
+ return lo;
10303
+ };
10304
+ writeBitsLsb(1, 1);
10305
+ writeBitsLsb(1, 2);
10306
+ const n = src.length;
10307
+ const HASH_BITS = 15;
10308
+ const HASH_MASK = (1 << HASH_BITS) - 1;
10309
+ const head = new Int32Array(1 << HASH_BITS);
10310
+ head.fill(-1);
10311
+ const prev = new Int32Array(Math.min(n, 32768) || 1);
10312
+ prev.fill(-1);
10313
+ const hash3 = (p) => (src[p] << 10 ^ src[p + 1] << 5 ^ src[p + 2]) * 40503 & HASH_MASK;
10314
+ let pos = 0;
10315
+ while (pos < n) {
10316
+ let bestLen = 0;
10317
+ let bestDist = 0;
10318
+ if (pos + 3 <= n) {
10319
+ const h = hash3(pos);
10320
+ let cand = head[h];
10321
+ head[h] = pos;
10322
+ prev[pos & 32767] = cand;
10323
+ const minPos = Math.max(0, pos - 32768);
10324
+ const maxMatch = Math.min(258, n - pos);
10325
+ let chain = 0;
10326
+ while (cand >= minPos && chain < 48) {
10327
+ chain++;
10328
+ if (src[cand + bestLen] === src[pos + bestLen] && src[cand] === src[pos]) {
10329
+ let mLen = 0;
10330
+ while (mLen < maxMatch && src[cand + mLen] === src[pos + mLen]) {
10331
+ mLen++;
10332
+ }
10333
+ if (mLen >= 3 && mLen > bestLen && (mLen >= 4 || pos - cand <= 4096)) {
10334
+ bestLen = mLen;
10335
+ bestDist = pos - cand;
10336
+ if (bestLen === maxMatch) break;
10337
+ }
10338
+ }
10339
+ const nextCand = prev[cand & 32767];
10340
+ if (nextCand >= cand) break;
10341
+ cand = nextCand;
10342
+ }
10343
+ }
10344
+ if (bestLen >= 3) {
10345
+ const lIdx = findLenCode(bestLen);
10346
+ writeFixedSym(257 + lIdx);
10347
+ const lExtra = DEFLATE_LEN_EXTRA[lIdx];
10348
+ if (lExtra > 0) {
10349
+ writeBitsLsb(bestLen - DEFLATE_LEN_BASE[lIdx], lExtra);
10350
+ }
10351
+ const dIdx = findDistCode(bestDist);
10352
+ writeCodeMsb(dIdx, 5);
10353
+ const dExtra = DEFLATE_DIST_EXTRA[dIdx];
10354
+ if (dExtra > 0) {
10355
+ writeBitsLsb(bestDist - DEFLATE_DIST_BASE[dIdx], dExtra);
10356
+ }
10357
+ for (let step = 1; step < bestLen; step++) {
10358
+ const adv = pos + step;
10359
+ if (adv + 3 <= n) {
10360
+ const hAdv = hash3(adv);
10361
+ prev[adv & 32767] = head[hAdv];
10362
+ head[hAdv] = adv;
10363
+ }
10364
+ }
10365
+ pos += bestLen;
10366
+ } else {
10367
+ writeFixedSym(src[pos]);
10368
+ pos++;
10369
+ }
10370
+ }
10371
+ writeFixedSym(256);
10372
+ if (bitCount > 0) {
10373
+ out.push(bitBuf);
10374
+ }
10375
+ return Uint8Array.from(out);
10376
+ }
10120
10377
  function packStoreZip(files) {
10121
10378
  const encoder = new TextEncoder();
10122
10379
  const entries = files.map((f) => {
10123
10380
  const nameBytes = encoder.encode(f.name);
10124
10381
  const dataBytes = typeof f.content === "string" ? encoder.encode(f.content) : f.content;
10382
+ const isPrecompressedMedia = /\.(?:png|jpe?g|gif|webp)$/i.test(f.name);
10383
+ let payloadBytes = dataBytes;
10384
+ let method = 0;
10385
+ if (!isPrecompressedMedia && dataBytes.length >= 64) {
10386
+ const deflated = deflateRawSyncPure(dataBytes);
10387
+ if (deflated.length < dataBytes.length) {
10388
+ payloadBytes = deflated;
10389
+ method = 8;
10390
+ }
10391
+ }
10125
10392
  return {
10126
10393
  nameBytes,
10127
10394
  dataBytes,
10395
+ payloadBytes,
10396
+ method,
10128
10397
  crc: crc32(dataBytes),
10129
10398
  offset: 0
10130
10399
  };
@@ -10132,7 +10401,7 @@ function packStoreZip(files) {
10132
10401
  let localTotal = 0;
10133
10402
  for (const e of entries) {
10134
10403
  e.offset = localTotal;
10135
- localTotal += 30 + e.nameBytes.length + e.dataBytes.length;
10404
+ localTotal += 30 + e.nameBytes.length + e.payloadBytes.length;
10136
10405
  }
10137
10406
  let centralTotal = 0;
10138
10407
  for (const e of entries) {
@@ -10146,19 +10415,19 @@ function packStoreZip(files) {
10146
10415
  view.setUint32(pos, 67324752, true);
10147
10416
  view.setUint16(pos + 4, 20, true);
10148
10417
  view.setUint16(pos + 6, 2048, true);
10149
- view.setUint16(pos + 8, 0, true);
10418
+ view.setUint16(pos + 8, e.method, true);
10150
10419
  view.setUint16(pos + 10, 0, true);
10151
10420
  view.setUint16(pos + 12, 22561, true);
10152
10421
  view.setUint32(pos + 14, e.crc, true);
10153
- view.setUint32(pos + 18, e.dataBytes.length, true);
10422
+ view.setUint32(pos + 18, e.payloadBytes.length, true);
10154
10423
  view.setUint32(pos + 22, e.dataBytes.length, true);
10155
10424
  view.setUint16(pos + 26, e.nameBytes.length, true);
10156
10425
  view.setUint16(pos + 28, 0, true);
10157
10426
  pos += 30;
10158
10427
  out.set(e.nameBytes, pos);
10159
10428
  pos += e.nameBytes.length;
10160
- out.set(e.dataBytes, pos);
10161
- pos += e.dataBytes.length;
10429
+ out.set(e.payloadBytes, pos);
10430
+ pos += e.payloadBytes.length;
10162
10431
  }
10163
10432
  const centralDirOffset = pos;
10164
10433
  for (const e of entries) {
@@ -10166,11 +10435,11 @@ function packStoreZip(files) {
10166
10435
  view.setUint16(pos + 4, 20, true);
10167
10436
  view.setUint16(pos + 6, 20, true);
10168
10437
  view.setUint16(pos + 8, 2048, true);
10169
- view.setUint16(pos + 10, 0, true);
10438
+ view.setUint16(pos + 10, e.method, true);
10170
10439
  view.setUint16(pos + 12, 0, true);
10171
10440
  view.setUint16(pos + 14, 22561, true);
10172
10441
  view.setUint32(pos + 16, e.crc, true);
10173
- view.setUint32(pos + 20, e.dataBytes.length, true);
10442
+ view.setUint32(pos + 20, e.payloadBytes.length, true);
10174
10443
  view.setUint32(pos + 24, e.dataBytes.length, true);
10175
10444
  view.setUint16(pos + 28, e.nameBytes.length, true);
10176
10445
  view.setUint16(pos + 30, 0, true);
@@ -10651,7 +10920,7 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
10651
10920
  };
10652
10921
  } else if (resolved.visualChrome === "brackets" || resolved.visualChrome === "clean" || !resolved.showingPlaceholder && resolved.visualChrome !== "highlight") {
10653
10922
  const rawBgLower = rawTs?.bg?.rgb?.trim().toLowerCase();
10654
- const isEditorChromeBg = rawBgLower === "#f3f5ff" || rawBgLower === "#eeeff1" || rawBgLower === "#eff6ff";
10923
+ const isEditorChromeBg = rawBgLower === "#f3f5ff" || rawBgLower === "#eeeff1";
10655
10924
  sdtRunStyle = {
10656
10925
  ...rawTs ?? {},
10657
10926
  bg: resolved.visualChrome === "brackets" || resolved.visualChrome === "clean" || isEditorChromeBg ? void 0 : rawTs?.bg,
@@ -10764,7 +11033,75 @@ function serializeSpanToRunsAndSdtXml(body, spanStart, spanEndExclusive, exportC
10764
11033
  flushMarkersAt(spanEndExclusive);
10765
11034
  return innerXml.join("");
10766
11035
  }
10767
- function buildTableBordersOoxml(preset) {
11036
+ function readMarginSideTwips(rawSide) {
11037
+ if (rawSide === null || rawSide === void 0) return void 0;
11038
+ if (typeof rawSide === "number") {
11039
+ return Number.isFinite(rawSide) ? Math.max(0, Math.round(rawSide * 20)) : void 0;
11040
+ }
11041
+ if (typeof rawSide === "object") {
11042
+ const val = rawSide.v;
11043
+ if (typeof val === "number" && Number.isFinite(val)) {
11044
+ return Math.max(0, Math.round(val * 20));
11045
+ }
11046
+ }
11047
+ return void 0;
11048
+ }
11049
+ function extractCellMarginTwips(rawMargin) {
11050
+ if (!rawMargin || typeof rawMargin !== "object") return null;
11051
+ const m = rawMargin;
11052
+ const top = readMarginSideTwips(m.top);
11053
+ const left = readMarginSideTwips(m.start !== void 0 ? m.start : m.left);
11054
+ const bottom = readMarginSideTwips(m.bottom);
11055
+ const right = readMarginSideTwips(m.end !== void 0 ? m.end : m.right);
11056
+ if (top === void 0 && left === void 0 && bottom === void 0 && right === void 0) {
11057
+ return null;
11058
+ }
11059
+ return { top, left, bottom, right };
11060
+ }
11061
+ function marginTwipsEqual(a, b) {
11062
+ return a.top === b.top && a.left === b.left && a.bottom === b.bottom && a.right === b.right;
11063
+ }
11064
+ function buildOoxmlMarginXml(tag, twips) {
11065
+ if (!twips) return "";
11066
+ const parts = [];
11067
+ if (twips.top !== void 0) {
11068
+ parts.push(`<w:top w:w="${twips.top}" w:type="dxa"/>`);
11069
+ }
11070
+ if (twips.left !== void 0) {
11071
+ parts.push(`<w:left w:w="${twips.left}" w:type="dxa"/>`);
11072
+ }
11073
+ if (twips.bottom !== void 0) {
11074
+ parts.push(`<w:bottom w:w="${twips.bottom}" w:type="dxa"/>`);
11075
+ }
11076
+ if (twips.right !== void 0) {
11077
+ parts.push(`<w:right w:w="${twips.right}" w:type="dxa"/>`);
11078
+ }
11079
+ return parts.length > 0 ? `<w:${tag}>${parts.join("")}</w:${tag}>` : "";
11080
+ }
11081
+ function serializeCoreTableBorderTag(tag, edge, fallbackVal = "single", fallbackColor = "CBD5E1", fallbackSz = 4) {
11082
+ if (!edge) {
11083
+ return `<w:${tag} w:val="${fallbackVal}" w:sz="${fallbackSz}" w:space="0" w:color="${fallbackColor}"/>`;
11084
+ }
11085
+ const widthPt = typeof edge.width?.v === "number" ? edge.width.v : 0.5;
11086
+ if (widthPt <= 0 || edge.dashStyle === import_core7.DashStyleType.DASH_STYLE_UNSPECIFIED && widthPt === 0) {
11087
+ return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
11088
+ }
11089
+ const wVal = edge.dashStyle === import_core7.DashStyleType.DOT ? "dotted" : edge.dashStyle === import_core7.DashStyleType.DASH ? "dashed" : fallbackVal;
11090
+ const wSz = Math.max(2, Math.round(widthPt * 8));
11091
+ const wCol = normalizeHex6(edge.color?.rgb) || fallbackColor;
11092
+ return `<w:${tag} w:val="${wVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
11093
+ }
11094
+ function buildTableBordersOoxml(preset, borderDefaults) {
11095
+ if ((!preset || preset === "all") && borderDefaults) {
11096
+ return `<w:tblBorders>${[
11097
+ serializeCoreTableBorderTag("top", borderDefaults.top),
11098
+ serializeCoreTableBorderTag("left", borderDefaults.left),
11099
+ serializeCoreTableBorderTag("bottom", borderDefaults.bottom),
11100
+ serializeCoreTableBorderTag("right", borderDefaults.right),
11101
+ serializeCoreTableBorderTag("insideH", borderDefaults.insideHorizontal),
11102
+ serializeCoreTableBorderTag("insideV", borderDefaults.insideVertical)
11103
+ ].join("")}</w:tblBorders>`;
11104
+ }
10768
11105
  const solid = '<w:top w:val="single" w:sz="4" w:space="0" w:color="CBD5E1"/>';
10769
11106
  if (!preset || preset === "all") {
10770
11107
  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>`;
@@ -10780,7 +11117,17 @@ function buildTableBordersOoxml(preset) {
10780
11117
  }
10781
11118
  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>';
10782
11119
  }
10783
- function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType, cellBorders, cellDef) {
11120
+ function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType, cellBorders, cellDef, borderDefaults, forceEmit = false) {
11121
+ const hasRestrictivePreset = preset === "empty" || preset === "external" || preset === "internal" || preset === "dash";
11122
+ const hasCustomCellBorders = Boolean(
11123
+ cellBorders && (cellBorders.top || cellBorders.left || cellBorders.bottom || cellBorders.right)
11124
+ );
11125
+ const hasCellDefBorders = Boolean(
11126
+ 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")
11127
+ );
11128
+ if (!forceEmit && !hasRestrictivePreset && !slashType && !hasCustomCellBorders && !hasCellDefBorders) {
11129
+ return "";
11130
+ }
10784
11131
  const edgeVal = preset === "dash" ? "dashed" : "single";
10785
11132
  const defEdgeMap = {
10786
11133
  top: "borderTop",
@@ -10788,6 +11135,17 @@ function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType,
10788
11135
  bottom: "borderBottom",
10789
11136
  right: "borderRight"
10790
11137
  };
11138
+ const isTop = rIdx === 0;
11139
+ const isBot = rIdx === rowCount - 1;
11140
+ const isLeft = cIdx === 0;
11141
+ const isRight = cIdx === colCount - 1;
11142
+ const resolveDefaultEdge = (tag) => {
11143
+ if (!borderDefaults) return void 0;
11144
+ if (tag === "top") return isTop ? borderDefaults.top : borderDefaults.insideHorizontal;
11145
+ if (tag === "bottom") return isBot ? borderDefaults.bottom : borderDefaults.insideHorizontal;
11146
+ if (tag === "left") return isLeft ? borderDefaults.left : borderDefaults.insideVertical;
11147
+ return isRight ? borderDefaults.right : borderDefaults.insideVertical;
11148
+ };
10791
11149
  const mk = (active, tag) => {
10792
11150
  const customEdge = cellBorders?.[tag];
10793
11151
  if (customEdge) {
@@ -10799,24 +11157,28 @@ function buildTcBordersOoxml(preset, rIdx, cIdx, rowCount, colCount, slashType,
10799
11157
  const wCol = normalizeHex6(customEdge.color) || "CBD5E1";
10800
11158
  return `<w:${tag} w:val="${wVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
10801
11159
  }
10802
- if (!preset && cellDef) {
11160
+ if (!hasRestrictivePreset && cellDef) {
10803
11161
  const defBorder = cellDef[defEdgeMap[tag]];
10804
11162
  const defWidthPt = defBorder?.width?.v;
10805
11163
  if (typeof defWidthPt === "number") {
10806
11164
  if (defWidthPt <= 0) {
10807
11165
  return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
10808
11166
  }
11167
+ const defVal = defBorder?.dashStyle === import_core7.DashStyleType.DOT ? "dotted" : defBorder?.dashStyle === import_core7.DashStyleType.DASH ? "dashed" : edgeVal;
10809
11168
  const wSz = Math.max(2, Math.round(defWidthPt * 8));
10810
11169
  const wCol = normalizeHex6(defBorder?.color?.rgb) || "CBD5E1";
10811
- return `<w:${tag} w:val="${edgeVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
11170
+ return `<w:${tag} w:val="${defVal}" w:sz="${wSz}" w:space="0" w:color="${wCol}"/>`;
10812
11171
  }
10813
11172
  }
10814
- return active ? `<w:${tag} w:val="${edgeVal}" w:sz="4" w:space="0" w:color="CBD5E1"/>` : `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
11173
+ if (!active) {
11174
+ return `<w:${tag} w:val="none" w:sz="0" w:space="0" w:color="auto"/>`;
11175
+ }
11176
+ const tblFallbackEdge = resolveDefaultEdge(tag);
11177
+ if (tblFallbackEdge && !hasRestrictivePreset) {
11178
+ return serializeCoreTableBorderTag(tag, tblFallbackEdge, edgeVal);
11179
+ }
11180
+ return `<w:${tag} w:val="${edgeVal}" w:sz="4" w:space="0" w:color="CBD5E1"/>`;
10815
11181
  };
10816
- const isTop = rIdx === 0;
10817
- const isBot = rIdx === rowCount - 1;
10818
- const isLeft = cIdx === 0;
10819
- const isRight = cIdx === colCount - 1;
10820
11182
  let topOn = true;
10821
11183
  let botOn = true;
10822
11184
  let leftOn = true;
@@ -11155,6 +11517,25 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
11155
11517
  }
11156
11518
  return "";
11157
11519
  };
11520
+ const tblCellMarginTwips = extractCellMarginTwips(tblDef?.cellMargin);
11521
+ const resolveCellTcMarXml = (targetCellDef) => {
11522
+ const cellTwips = extractCellMarginTwips(targetCellDef?.margin);
11523
+ if (!cellTwips) return "";
11524
+ if (tblCellMarginTwips && marginTwipsEqual(cellTwips, tblCellMarginTwips)) {
11525
+ return "";
11526
+ }
11527
+ return buildOoxmlMarginXml("tcMar", cellTwips);
11528
+ };
11529
+ const resolveCellVAlignStr = (cellProps, targetCellDef) => {
11530
+ if (cellProps?.verticalAlign) {
11531
+ return cellProps.verticalAlign;
11532
+ }
11533
+ if (targetCellDef?.vAlign === import_core7.VerticalAlignmentType.TOP) return "top";
11534
+ if (targetCellDef?.vAlign === import_core7.VerticalAlignmentType.CENTER) return "center";
11535
+ if (targetCellDef?.vAlign === import_core7.VerticalAlignmentType.BOTTOM) return "bottom";
11536
+ if (targetCellDef?.vAlign === import_core7.VerticalAlignmentType.BOTH) return "both";
11537
+ return void 0;
11538
+ };
11158
11539
  const trXmlList = parsedRows.map((rSpan, rIdx) => {
11159
11540
  const rowDef = tblDef?.tableRows?.[rIdx];
11160
11541
  const trPrParts = [];
@@ -11199,9 +11580,33 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
11199
11580
  contPr.push(`<w:gridSpan w:val="${master.colSpan}"/>`);
11200
11581
  }
11201
11582
  contPr.push("<w:vMerge/>");
11202
- contPr.push(
11203
- buildTcBordersOoxml(tblBorderPreset, rIdx, cIdx, parsedRows.length, colCount)
11583
+ const contBordersXml = buildTcBordersOoxml(
11584
+ tblBorderPreset,
11585
+ rIdx,
11586
+ cIdx,
11587
+ parsedRows.length,
11588
+ colCount,
11589
+ void 0,
11590
+ void 0,
11591
+ contCellDef,
11592
+ tblDef?.borderDefaults,
11593
+ true
11204
11594
  );
11595
+ if (contBordersXml) {
11596
+ contPr.push(contBordersXml);
11597
+ }
11598
+ const contFillHex = normalizeHex6(contCellDef?.backgroundColor?.rgb);
11599
+ if (contFillHex) {
11600
+ contPr.push(`<w:shd w:val="clear" w:color="auto" w:fill="${contFillHex}"/>`);
11601
+ }
11602
+ const contTcMarXml = resolveCellTcMarXml(contCellDef);
11603
+ if (contTcMarXml) {
11604
+ contPr.push(contTcMarXml);
11605
+ }
11606
+ const contVAlign = resolveCellVAlignStr(cellProps, contCellDef);
11607
+ if (contVAlign) {
11608
+ contPr.push(`<w:vAlign w:val="${escapeXml(contVAlign)}"/>`);
11609
+ }
11205
11610
  tcXmlList.push(`<w:tc><w:tcPr>${contPr.join("")}</w:tcPr><w:p/></w:tc>`);
11206
11611
  return;
11207
11612
  }
@@ -11218,25 +11623,33 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
11218
11623
  if (rowSpan > 1) {
11219
11624
  tcPrParts.push('<w:vMerge w:val="restart"/>');
11220
11625
  }
11221
- if (cellProps?.verticalAlign) {
11222
- tcPrParts.push(`<w:vAlign w:val="${escapeXml(cellProps.verticalAlign)}"/>`);
11626
+ const tcBordersXml = buildTcBordersOoxml(
11627
+ tblBorderPreset,
11628
+ rIdx,
11629
+ cIdx,
11630
+ parsedRows.length,
11631
+ colCount,
11632
+ cellProps?.slashType,
11633
+ cellProps?.borders,
11634
+ cellDef,
11635
+ tblDef?.borderDefaults,
11636
+ false
11637
+ );
11638
+ if (tcBordersXml) {
11639
+ tcPrParts.push(tcBordersXml);
11223
11640
  }
11224
11641
  const fillHex = normalizeHex6(cellDef?.backgroundColor?.rgb);
11225
11642
  if (fillHex) {
11226
11643
  tcPrParts.push(`<w:shd w:val="clear" w:color="auto" w:fill="${fillHex}"/>`);
11227
11644
  }
11228
- tcPrParts.push(
11229
- buildTcBordersOoxml(
11230
- tblBorderPreset,
11231
- rIdx,
11232
- cIdx,
11233
- parsedRows.length,
11234
- colCount,
11235
- cellProps?.slashType,
11236
- cellProps?.borders,
11237
- cellDef
11238
- )
11239
- );
11645
+ const tcMarXml = resolveCellTcMarXml(cellDef);
11646
+ if (tcMarXml) {
11647
+ tcPrParts.push(tcMarXml);
11648
+ }
11649
+ const vAlignStr = resolveCellVAlignStr(cellProps, cellDef);
11650
+ if (vAlignStr) {
11651
+ tcPrParts.push(`<w:vAlign w:val="${escapeXml(vAlignStr)}"/>`);
11652
+ }
11240
11653
  const cellParas = paragraphs.filter(
11241
11654
  (cp) => cp.startIndex >= cSpan.contentStart && cp.startIndex <= cSpan.textEndExclusive
11242
11655
  );
@@ -11292,13 +11705,18 @@ function serializeStoryBodyXml(snapshot, body, exportCtx) {
11292
11705
  tblWXml = '<w:tblW w:w="0" w:type="auto"/>';
11293
11706
  }
11294
11707
  const tblLayoutXml = tblDef?.layout === import_core7.TableLayoutType.FIXED ? '<w:tblLayout w:type="fixed"/>' : tblDef?.layout === import_core7.TableLayoutType.AUTO_FIT ? '<w:tblLayout w:type="autofit"/>' : "";
11295
- const tblPrExtra = [
11708
+ const tblCellMarXml = buildOoxmlMarginXml("tblCellMar", tblCellMarginTwips);
11709
+ const tblStyleIdXml = escapeXml(tblDef?.styleId || "TableGrid");
11710
+ const tblPrInner = [
11711
+ `<w:tblStyle w:val="${tblStyleIdXml}"/>`,
11296
11712
  tblDir === "rtl" ? "<w:bidiVisual/>" : "",
11297
- buildTableBordersOoxml(tblBorderPreset),
11298
- tblLayoutXml
11713
+ tblWXml,
11714
+ buildTableBordersOoxml(tblBorderPreset, tblDef?.borderDefaults),
11715
+ tblLayoutXml,
11716
+ tblCellMarXml
11299
11717
  ].join("");
11300
11718
  blocksXml.push(
11301
- `<w:tbl><w:tblPr><w:tblStyle w:val="TableGrid"/>${tblWXml}${tblPrExtra}</w:tblPr><w:tblGrid>${gridColsXml}</w:tblGrid>${trXmlList.join("")}</w:tbl>`
11719
+ `<w:tbl><w:tblPr>${tblPrInner}</w:tblPr><w:tblGrid>${gridColsXml}</w:tblGrid>${trXmlList.join("")}</w:tbl>`
11302
11720
  );
11303
11721
  cursor = nextTbl.endIndex;
11304
11722
  tCursor++;
@@ -14134,7 +14552,7 @@ function parseParagraphXmlToBuilder(pXml, relsMap, entries, collectedDrawings, i
14134
14552
  kind,
14135
14553
  lock: lockMatch?.[1] || (isGroupSdt ? "contentLocked" : "sdtLocked"),
14136
14554
  dateFormat: dateFmtMatch ? unescapeXml(dateFmtMatch[1]) : void 0,
14137
- anchorTextStyle: sdtPrStyle ?? firstRunStyle,
14555
+ anchorTextStyle: sdtPrStyle || firstRunStyle ? { ...sdtPrStyle ?? {}, ...firstRunStyle ?? {} } : void 0,
14138
14556
  ...isRepeatingSec ? { templateText: valText } : {},
14139
14557
  listItems: listItemMatches.length > 0 ? listItemMatches.map((m) => ({
14140
14558
  displayText: unescapeXml(m[1]),
@@ -14481,7 +14899,7 @@ function unwrapCellParagraphBlocks(xml) {
14481
14899
  }
14482
14900
  return out;
14483
14901
  }
14484
- function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0) {
14902
+ function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0, pctCellMargins = 0) {
14485
14903
  const warnings = [];
14486
14904
  const check = (re, code, label) => {
14487
14905
  const matches = xml.match(re);
@@ -14519,6 +14937,13 @@ function scanUnsupportedDocxFeatures(xml, floatingImages, dynamicFields = 0) {
14519
14937
  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"
14520
14938
  });
14521
14939
  }
14940
+ if (pctCellMargins > 0) {
14941
+ warnings.push({
14942
+ code: "PCT_CELL_MARGIN_APPROXIMATED",
14943
+ count: pctCellMargins,
14944
+ 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'
14945
+ });
14946
+ }
14522
14947
  return warnings;
14523
14948
  }
14524
14949
  async function parseDocxBytesWithReport(bytes, title = "Imported Word Document") {
@@ -14660,12 +15085,188 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14660
15085
  const bodyXml = bodyInnerMatch ? bodyInnerMatch[1] : xml;
14661
15086
  const collectedDrawings = {};
14662
15087
  const inlineBlocksQueue = [];
14663
- const warningsCounter = { floatingImages: 0, dynamicFields: 0 };
15088
+ const warningsCounter = {
15089
+ floatingImages: 0,
15090
+ dynamicFields: 0,
15091
+ pctCellMargins: 0
15092
+ };
14664
15093
  const xmlTableDirections = {};
14665
15094
  const xmlTableBorderPresets = {};
14666
15095
  const xmlTableCellProperties = {};
14667
15096
  const xmlTableAutoFitWindow = /* @__PURE__ */ new Set();
14668
15097
  let detectedTocSpan = null;
15098
+ const OOXML_DEFAULT_CELL_MARGIN_PT = {
15099
+ top: 0,
15100
+ bottom: 0,
15101
+ start: 5.4,
15102
+ end: 5.4
15103
+ };
15104
+ const parseOoxmlBorderTag = (containerXml, edgeTag) => {
15105
+ if (!containerXml) return void 0;
15106
+ const em = containerXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
15107
+ if (!em) return void 0;
15108
+ const eAttrs = em[1] || "";
15109
+ const rawVal = (eAttrs.match(/w:val="([^"]+)"/)?.[1] || "single").toLowerCase();
15110
+ if (rawVal === "none" || rawVal === "nil") {
15111
+ return { style: "none", widthPt: 0 };
15112
+ }
15113
+ const szEighths = Number(eAttrs.match(/w:sz="(\d+)"/)?.[1] ?? 4);
15114
+ const widthPt = Math.max(0.25, Math.round(szEighths / 8 * 100) / 100);
15115
+ const rawColor = (eAttrs.match(/w:color="([0-9a-fA-F]{6})"/)?.[1] || "CBD5E1").toUpperCase();
15116
+ const style = rawVal === "double" ? "double" : rawVal.includes("dash") ? "dashed" : rawVal.includes("dot") ? "dotted" : "single";
15117
+ return { style, widthPt, color: `#${rawColor}` };
15118
+ };
15119
+ const parseOoxmlCellMarginXml = (containerXml, warnOut) => {
15120
+ if (!containerXml) return void 0;
15121
+ const marBlock = containerXml.match(/<w:(?:tcMar|tblCellMar)[\s>][\s\S]*?<\/w:(?:tcMar|tblCellMar)>/)?.[0] || "";
15122
+ if (!marBlock) return void 0;
15123
+ const readSidePt = (tagCandidates) => {
15124
+ for (const tag of tagCandidates) {
15125
+ const m = marBlock.match(new RegExp(`<w:${tag}\\b([^>]*)\\/?>`));
15126
+ if (!m) continue;
15127
+ const attrs = m[1] || "";
15128
+ const rawType = (attrs.match(/\bw:type="([^"]+)"/)?.[1] || "").toLowerCase();
15129
+ const rawW = attrs.match(/\bw:w="(-?\d+(?:\.\d+)?)"/)?.[1];
15130
+ if (rawType === "nil") {
15131
+ return 0;
15132
+ }
15133
+ if (rawType === "auto" && (rawW === void 0 || Number(rawW) === 0)) {
15134
+ return void 0;
15135
+ }
15136
+ if (rawType === "pct") {
15137
+ if (warnOut) {
15138
+ warnOut.pctCellMargins = (warnOut.pctCellMargins ?? 0) + 1;
15139
+ }
15140
+ const numPct = rawW !== void 0 ? Number(rawW) : 0;
15141
+ return Number.isFinite(numPct) ? Math.max(0, Math.round(numPct / 20 * 1e3) / 1e3) : 0;
15142
+ }
15143
+ if (rawW === void 0) {
15144
+ return void 0;
15145
+ }
15146
+ const numDxa = Number(rawW);
15147
+ if (!Number.isFinite(numDxa)) return void 0;
15148
+ return Math.max(0, Math.round(numDxa / 20 * 1e3) / 1e3);
15149
+ }
15150
+ return void 0;
15151
+ };
15152
+ const top = readSidePt(["top"]);
15153
+ const bottom = readSidePt(["bottom"]);
15154
+ const start = readSidePt(["start", "left"]);
15155
+ const end = readSidePt(["end", "right"]);
15156
+ if (top === void 0 && bottom === void 0 && start === void 0 && end === void 0) {
15157
+ return void 0;
15158
+ }
15159
+ return {
15160
+ ...top !== void 0 ? { top } : {},
15161
+ ...bottom !== void 0 ? { bottom } : {},
15162
+ ...start !== void 0 ? { start } : {},
15163
+ ...end !== void 0 ? { end } : {}
15164
+ };
15165
+ };
15166
+ const hasAnyMarginSide = (m) => Boolean(
15167
+ m && (m.top !== void 0 || m.bottom !== void 0 || m.start !== void 0 || m.end !== void 0)
15168
+ );
15169
+ const resolveCascadedMarginPt = (tcMar, trMar, tblMar, styleMar) => ({
15170
+ top: tcMar?.top ?? trMar?.top ?? tblMar?.top ?? styleMar?.top ?? OOXML_DEFAULT_CELL_MARGIN_PT.top,
15171
+ bottom: tcMar?.bottom ?? trMar?.bottom ?? tblMar?.bottom ?? styleMar?.bottom ?? OOXML_DEFAULT_CELL_MARGIN_PT.bottom,
15172
+ start: tcMar?.start ?? trMar?.start ?? tblMar?.start ?? styleMar?.start ?? OOXML_DEFAULT_CELL_MARGIN_PT.start,
15173
+ end: tcMar?.end ?? trMar?.end ?? tblMar?.end ?? styleMar?.end ?? OOXML_DEFAULT_CELL_MARGIN_PT.end
15174
+ });
15175
+ const stylesBytes = entries.get("word/styles.xml");
15176
+ const stylesXmlText = stylesBytes ? decoder.decode(stylesBytes) : "";
15177
+ const rawTableStyles = /* @__PURE__ */ new Map();
15178
+ let defaultTableStyleId = "";
15179
+ if (stylesXmlText) {
15180
+ for (const sm of stylesXmlText.matchAll(/<w:style\b([^>]*)>([\s\S]*?)<\/w:style>/g)) {
15181
+ const sAttrs = sm[1] || "";
15182
+ const sType = (sAttrs.match(/\bw:type="([^"]+)"/)?.[1] || "").toLowerCase();
15183
+ if (sType !== "table") continue;
15184
+ const sId = unescapeXml(sAttrs.match(/\bw:styleId="([^"]+)"/)?.[1] || "");
15185
+ if (!sId) continue;
15186
+ if (/\bw:default="(?:1|true|on)"/i.test(sAttrs) || !defaultTableStyleId && sId === "TableNormal") {
15187
+ defaultTableStyleId = sId;
15188
+ }
15189
+ const baseInner = (sm[2] || "").replace(/<w:tblStylePr[\s>][\s\S]*?<\/w:tblStylePr>/g, "");
15190
+ const basedOn = unescapeXml(
15191
+ baseInner.match(/<w:basedOn\b[^>]*\bw:val="([^"]+)"/)?.[1] || ""
15192
+ ) || void 0;
15193
+ const sTblPr = baseInner.match(/<w:tblPr[\s>][\s\S]*?<\/w:tblPr>/)?.[0] || "";
15194
+ const styleWarnCounter = { floatingImages: 0, pctCellMargins: 0 };
15195
+ const cellMargin = parseOoxmlCellMarginXml(sTblPr, styleWarnCounter);
15196
+ const sBordersXml = sTblPr.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0] || "";
15197
+ let borders;
15198
+ if (sBordersXml) {
15199
+ borders = {
15200
+ top: parseOoxmlBorderTag(sBordersXml, "top"),
15201
+ bottom: parseOoxmlBorderTag(sBordersXml, "bottom"),
15202
+ left: parseOoxmlBorderTag(sBordersXml, "left"),
15203
+ right: parseOoxmlBorderTag(sBordersXml, "right"),
15204
+ insideH: parseOoxmlBorderTag(sBordersXml, "insideH"),
15205
+ insideV: parseOoxmlBorderTag(sBordersXml, "insideV")
15206
+ };
15207
+ }
15208
+ rawTableStyles.set(sId, {
15209
+ basedOn,
15210
+ cellMargin,
15211
+ pctCount: styleWarnCounter.pctCellMargins ?? 0,
15212
+ borders
15213
+ });
15214
+ }
15215
+ }
15216
+ const countedStylePctIds = /* @__PURE__ */ new Set();
15217
+ const resolveTableStyleCascade = (styleId) => {
15218
+ if (!styleId || !rawTableStyles.has(styleId)) return void 0;
15219
+ const chain = [];
15220
+ const visited = /* @__PURE__ */ new Set();
15221
+ let cur = styleId;
15222
+ while (cur && !visited.has(cur)) {
15223
+ visited.add(cur);
15224
+ const d = rawTableStyles.get(cur);
15225
+ if (!d) break;
15226
+ chain.push({ id: cur, def: d });
15227
+ cur = d.basedOn;
15228
+ }
15229
+ if (chain.length === 0) return void 0;
15230
+ const mergedMargin = {};
15231
+ const mergedBorders = {};
15232
+ for (let i = chain.length - 1; i >= 0; i--) {
15233
+ const { id, def } = chain[i];
15234
+ if (def.pctCount > 0 && !countedStylePctIds.has(id)) {
15235
+ countedStylePctIds.add(id);
15236
+ warningsCounter.pctCellMargins = (warningsCounter.pctCellMargins ?? 0) + def.pctCount;
15237
+ }
15238
+ if (def.cellMargin) {
15239
+ if (def.cellMargin.top !== void 0) mergedMargin.top = def.cellMargin.top;
15240
+ if (def.cellMargin.bottom !== void 0) mergedMargin.bottom = def.cellMargin.bottom;
15241
+ if (def.cellMargin.start !== void 0) mergedMargin.start = def.cellMargin.start;
15242
+ if (def.cellMargin.end !== void 0) mergedMargin.end = def.cellMargin.end;
15243
+ }
15244
+ if (def.borders) {
15245
+ for (const edge of ["top", "bottom", "left", "right", "insideH", "insideV"]) {
15246
+ if (def.borders[edge]) mergedBorders[edge] = def.borders[edge];
15247
+ }
15248
+ }
15249
+ }
15250
+ return {
15251
+ cellMargin: hasAnyMarginSide(mergedMargin) ? mergedMargin : void 0,
15252
+ borders: Object.keys(mergedBorders).length > 0 ? mergedBorders : void 0
15253
+ };
15254
+ };
15255
+ const toCoreTableBorder = (edge) => {
15256
+ if (edge.style === "none" || edge.widthPt === 0) {
15257
+ return {
15258
+ color: { rgb: "#ffffff" },
15259
+ width: { v: 0, u: import_core7.NumberUnitType.POINT },
15260
+ dashStyle: import_core7.DashStyleType.DASH_STYLE_UNSPECIFIED
15261
+ };
15262
+ }
15263
+ const dashStyle = edge.style === "dotted" ? import_core7.DashStyleType.DOT : edge.style === "dashed" ? import_core7.DashStyleType.DASH : import_core7.DashStyleType.SOLID;
15264
+ return {
15265
+ color: { rgb: (edge.color || "#CBD5E1").toUpperCase() },
15266
+ width: { v: edge.widthPt ?? 0.5, u: import_core7.NumberUnitType.POINT },
15267
+ dashStyle
15268
+ };
15269
+ };
14669
15270
  const parseTblBordersPreset = (tblPrXml) => {
14670
15271
  const bXml = tblPrXml.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0];
14671
15272
  if (!bXml) return void 0;
@@ -14690,6 +15291,13 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14690
15291
  const tblHeadXml = firstTrMatch && typeof firstTrMatch.index === "number" ? tblXml.slice(0, firstTrMatch.index) : tblXml;
14691
15292
  const tblPrXml = tblHeadXml.match(/<w:tblPr[\s>][\s\S]*?<\/w:tblPr>/)?.[0] || "";
14692
15293
  const tblGridXml = tblHeadXml.match(/<w:tblGrid[\s>][\s\S]*?<\/w:tblGrid>/)?.[0] || "";
15294
+ const rawTblStyleId = unescapeXml(
15295
+ tblPrXml.match(/<w:tblStyle\b[^>]*\bw:val="([^"]+)"/)?.[1] || ""
15296
+ );
15297
+ const effectiveTblStyleId = rawTblStyleId || defaultTableStyleId;
15298
+ const inheritedTblStyle = effectiveTblStyleId ? resolveTableStyleCascade(effectiveTblStyleId) : void 0;
15299
+ const tblCellMar = parseOoxmlCellMarginXml(tblPrXml, warningsCounter);
15300
+ const tableCellMarginPt = hasAnyMarginSide(tblCellMar) || hasAnyMarginSide(inheritedTblStyle?.cellMargin) ? resolveCascadedMarginPt(void 0, void 0, tblCellMar, inheritedTblStyle?.cellMargin) : void 0;
14693
15301
  if (/<w:bidiVisual(?:\s|\/|>)/.test(tblPrXml) && !/<w:bidiVisual\s[^>]*w:val="(?:0|false)"/.test(tblPrXml)) {
14694
15302
  xmlTableDirections[tableId] = "rtl";
14695
15303
  }
@@ -14698,34 +15306,27 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14698
15306
  xmlTableBorderPresets[tableId] = detectedPreset;
14699
15307
  }
14700
15308
  const tblBordersBlockXml = tblPrXml.match(/<w:tblBorders[\s>][\s\S]*?<\/w:tblBorders>/)?.[0] || "";
14701
- const parseOoxmlBorderTag = (containerXml, edgeTag) => {
14702
- if (!containerXml) return void 0;
14703
- const em = containerXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
14704
- if (!em) return void 0;
14705
- const eAttrs = em[1] || "";
14706
- const rawVal = (eAttrs.match(/w:val="([^"]+)"/)?.[1] || "single").toLowerCase();
14707
- if (rawVal === "none" || rawVal === "nil") {
14708
- return { style: "none", widthPt: 0 };
14709
- }
14710
- const szEighths = Number(eAttrs.match(/w:sz="(\d+)"/)?.[1] ?? 4);
14711
- const widthPt = Math.max(0.25, Math.round(szEighths / 8 * 100) / 100);
14712
- const rawColor = (eAttrs.match(/w:color="([0-9a-fA-F]{6})"/)?.[1] || "CBD5E1").toUpperCase();
14713
- const style = rawVal === "double" ? "double" : rawVal.includes("dash") ? "dashed" : rawVal.includes("dot") ? "dotted" : "single";
14714
- return { style, widthPt, color: `#${rawColor}` };
14715
- };
14716
15309
  const defaultGridEdge = {
14717
15310
  style: "single",
14718
15311
  widthPt: 0.5,
14719
15312
  color: "#CBD5E1"
14720
15313
  };
14721
15314
  const noneGridEdge = { style: "none", widthPt: 0 };
15315
+ const styleBorders = inheritedTblStyle?.borders;
14722
15316
  const tblLevelBorders = tblBordersBlockXml ? {
14723
- top: parseOoxmlBorderTag(tblBordersBlockXml, "top") ?? noneGridEdge,
14724
- bottom: parseOoxmlBorderTag(tblBordersBlockXml, "bottom") ?? noneGridEdge,
14725
- left: parseOoxmlBorderTag(tblBordersBlockXml, "left") ?? noneGridEdge,
14726
- right: parseOoxmlBorderTag(tblBordersBlockXml, "right") ?? noneGridEdge,
14727
- insideH: parseOoxmlBorderTag(tblBordersBlockXml, "insideH") ?? noneGridEdge,
14728
- insideV: parseOoxmlBorderTag(tblBordersBlockXml, "insideV") ?? noneGridEdge
15317
+ top: parseOoxmlBorderTag(tblBordersBlockXml, "top") ?? styleBorders?.top ?? noneGridEdge,
15318
+ bottom: parseOoxmlBorderTag(tblBordersBlockXml, "bottom") ?? styleBorders?.bottom ?? noneGridEdge,
15319
+ left: parseOoxmlBorderTag(tblBordersBlockXml, "left") ?? styleBorders?.left ?? noneGridEdge,
15320
+ right: parseOoxmlBorderTag(tblBordersBlockXml, "right") ?? styleBorders?.right ?? noneGridEdge,
15321
+ insideH: parseOoxmlBorderTag(tblBordersBlockXml, "insideH") ?? styleBorders?.insideH ?? noneGridEdge,
15322
+ insideV: parseOoxmlBorderTag(tblBordersBlockXml, "insideV") ?? styleBorders?.insideV ?? noneGridEdge
15323
+ } : styleBorders ? {
15324
+ top: styleBorders.top ?? noneGridEdge,
15325
+ bottom: styleBorders.bottom ?? noneGridEdge,
15326
+ left: styleBorders.left ?? noneGridEdge,
15327
+ right: styleBorders.right ?? noneGridEdge,
15328
+ insideH: styleBorders.insideH ?? noneGridEdge,
15329
+ insideV: styleBorders.insideV ?? noneGridEdge
14729
15330
  } : {
14730
15331
  top: defaultGridEdge,
14731
15332
  bottom: defaultGridEdge,
@@ -14734,6 +15335,14 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14734
15335
  insideH: defaultGridEdge,
14735
15336
  insideV: defaultGridEdge
14736
15337
  };
15338
+ const tableBorderDefaults = {
15339
+ top: toCoreTableBorder(tblLevelBorders.top),
15340
+ left: toCoreTableBorder(tblLevelBorders.left),
15341
+ bottom: toCoreTableBorder(tblLevelBorders.bottom),
15342
+ right: toCoreTableBorder(tblLevelBorders.right),
15343
+ insideHorizontal: toCoreTableBorder(tblLevelBorders.insideH),
15344
+ insideVertical: toCoreTableBorder(tblLevelBorders.insideV)
15345
+ };
14737
15346
  let yudaoTblWidthType;
14738
15347
  let yudaoTblWidthDxa;
14739
15348
  let yudaoTblWidthPct;
@@ -14781,11 +15390,13 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14781
15390
  (m) => Math.max(1, dxaToPt(Number(m[1])))
14782
15391
  );
14783
15392
  const trMatches = tokenizeNestedTagBlocks(tblXml, "tr");
14784
- const trHeadList = trMatches.map((trXml) => {
15393
+ const trHeadFullList = trMatches.map((trXml) => {
14785
15394
  const firstTc = trXml.match(/<w:tc(?=[\s>])/);
14786
- const head = firstTc && typeof firstTc.index === "number" ? trXml.slice(0, firstTc.index) : trXml;
14787
- return head.match(/<w:trPr[\s>][\s\S]*?<\/w:trPr>/)?.[0] || "";
15395
+ return firstTc && typeof firstTc.index === "number" ? trXml.slice(0, firstTc.index) : trXml;
14788
15396
  });
15397
+ const trHeadList = trHeadFullList.map(
15398
+ (head) => head.match(/<w:trPr[\s>][\s\S]*?<\/w:trPr>/)?.[0] || ""
15399
+ );
14789
15400
  let headerRowCount = 0;
14790
15401
  while (headerRowCount < trHeadList.length && /<w:tblHeader(?:\s|\/|>)/.test(trHeadList[headerRowCount]) && !/<w:tblHeader\s[^>]*w:val="(?:0|false|off)"/i.test(trHeadList[headerRowCount])) {
14791
15402
  headerRowCount++;
@@ -14796,6 +15407,9 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14796
15407
  const activeVMerges = /* @__PURE__ */ new Map();
14797
15408
  trMatches.forEach((trXml, trIdx) => {
14798
15409
  const trPrXml = trHeadList[trIdx] || "";
15410
+ const tblPrExXml = (trHeadFullList[trIdx] || "").match(/<w:tblPrEx[\s>][\s\S]*?<\/w:tblPrEx>/)?.[0] || "";
15411
+ const trCellMar = parseOoxmlCellMarginXml(tblPrExXml, warningsCounter);
15412
+ const resolvedRowCellMarginPt = hasAnyMarginSide(trCellMar) ? resolveCascadedMarginPt(void 0, trCellMar, tblCellMar, inheritedTblStyle?.cellMargin) : void 0;
14799
15413
  let rowCantSplit;
14800
15414
  const cantSplitMatch = trPrXml.match(/<w:cantSplit\b([^>]*)\/?>/);
14801
15415
  if (cantSplitMatch) {
@@ -14880,6 +15494,14 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14880
15494
  }
14881
15495
  const shdMatch = tcPrXml.match(/<w:shd\s[^>]*w:fill="([0-9a-fA-F]{6})"/);
14882
15496
  const vAlignMatch = tcPrXml.match(/<w:vAlign\s[^>]*w:val="([^"]+)"/)?.[1];
15497
+ const tcMar = parseOoxmlCellMarginXml(tcPrXml, warningsCounter);
15498
+ const resolvedCellMarginPt = resolveCascadedMarginPt(
15499
+ tcMar,
15500
+ trCellMar,
15501
+ tblCellMar,
15502
+ inheritedTblStyle?.cellMargin
15503
+ );
15504
+ const resolvedVAlign = vAlignMatch === "top" ? import_core7.VerticalAlignmentType.TOP : vAlignMatch === "center" ? import_core7.VerticalAlignmentType.CENTER : vAlignMatch === "bottom" ? import_core7.VerticalAlignmentType.BOTTOM : vAlignMatch === "both" ? import_core7.VerticalAlignmentType.BOTH : void 0;
14883
15505
  const tcBordersXml = tcPrXml.match(/<w:tcBorders[\s>][\s\S]*?<\/w:tcBorders>/)?.[0] || "";
14884
15506
  const parseTcBorderEdge = (edgeTag) => {
14885
15507
  const em = tcBordersXml.match(new RegExp(`<w:${edgeTag}\\b([^>]*)\\/?>`));
@@ -14944,12 +15566,20 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14944
15566
  colSpan,
14945
15567
  rowSpan: 0,
14946
15568
  borders: parsedCellBorders,
15569
+ ...hasExplicitCellBorders ? { explicitBorders: cellProps.borders } : {},
15570
+ marginPt: resolvedCellMarginPt,
15571
+ ...resolvedVAlign !== void 0 ? { vAlign: resolvedVAlign } : {},
14947
15572
  ...tcWidthType ? { tcWidthType } : {},
14948
15573
  ...cellSize ? { cellSize } : {},
14949
15574
  ...yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct } : {}
14950
15575
  });
14951
15576
  for (let k = 1; k < colSpan; k++) {
14952
- rowCells.push({ text: "", colSpan: 0, rowSpan: 0 });
15577
+ rowCells.push({
15578
+ text: "",
15579
+ colSpan: 0,
15580
+ rowSpan: 0,
15581
+ marginPt: resolvedCellMarginPt
15582
+ });
14953
15583
  }
14954
15584
  } else {
14955
15585
  if (isVMergeRestart) {
@@ -14983,13 +15613,21 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14983
15613
  rowSpan: 1,
14984
15614
  backgroundRgb: shdMatch ? `#${shdMatch[1]}` : void 0,
14985
15615
  borders: parsedCellBorders,
15616
+ ...hasExplicitCellBorders ? { explicitBorders: cellProps.borders } : {},
15617
+ marginPt: resolvedCellMarginPt,
15618
+ ...resolvedVAlign !== void 0 ? { vAlign: resolvedVAlign } : {},
14986
15619
  ...tcWidthType ? { tcWidthType } : {},
14987
15620
  ...cellSize ? { cellSize } : {},
14988
15621
  ...yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct } : {},
14989
15622
  ...tcParas ? { paragraphs: tcParas } : {}
14990
15623
  });
14991
15624
  for (let k = 1; k < colSpan; k++) {
14992
- rowCells.push({ text: "", colSpan: 0, rowSpan: 1 });
15625
+ rowCells.push({
15626
+ text: "",
15627
+ colSpan: 0,
15628
+ rowSpan: 1,
15629
+ marginPt: resolvedCellMarginPt
15630
+ });
14993
15631
  }
14994
15632
  }
14995
15633
  gridCol += colSpan;
@@ -14998,6 +15636,7 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
14998
15636
  rows.push(rowCells);
14999
15637
  rowMeta.push({
15000
15638
  ...rowCantSplit !== void 0 ? { cantSplit: rowCantSplit } : {},
15639
+ ...resolvedRowCellMarginPt ? { cellMarginPt: resolvedRowCellMarginPt } : {},
15001
15640
  trHeight: rowTrHeight
15002
15641
  });
15003
15642
  }
@@ -15026,11 +15665,15 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
15026
15665
  return {
15027
15666
  kind: "table",
15028
15667
  tableId,
15668
+ fromDocxImport: true,
15669
+ ...rawTblStyleId ? { styleId: rawTblStyleId } : {},
15029
15670
  columnWidthsPt: colWidthsPt.length > 0 ? colWidthsPt : void 0,
15030
15671
  repeatHeaderRow,
15031
15672
  headerRowCount,
15032
15673
  rows,
15033
15674
  rowMeta,
15675
+ ...tableCellMarginPt ? { tableCellMarginPt } : {},
15676
+ tableBorderDefaults,
15034
15677
  ...tableSize ? { tableSize } : {},
15035
15678
  ...tableLayout !== void 0 ? { tableLayout } : {},
15036
15679
  ...yudaoTblWidthType ? { yudaoTblWidthType } : {},
@@ -15140,9 +15783,8 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
15140
15783
  };
15141
15784
  }
15142
15785
  }
15143
- const stylesBytes = entries.get("word/styles.xml");
15144
- if (stylesBytes) {
15145
- parseStylesXmlIntoDoc(decoder.decode(stylesBytes), themeFonts, docData);
15786
+ if (stylesXmlText) {
15787
+ parseStylesXmlIntoDoc(stylesXmlText, themeFonts, docData);
15146
15788
  }
15147
15789
  for (const autoTblId of xmlTableAutoFitWindow) {
15148
15790
  if (docData.tableSource?.[autoTblId]) {
@@ -16080,7 +16722,8 @@ async function parseDocxBytesWithReport(bytes, title = "Imported Word Document")
16080
16722
  const warnings = scanUnsupportedDocxFeatures(
16081
16723
  xml,
16082
16724
  warningsCounter.floatingImages,
16083
- warningsCounter.dynamicFields ?? 0
16725
+ warningsCounter.dynamicFields ?? 0,
16726
+ warningsCounter.pctCellMargins ?? 0
16084
16727
  );
16085
16728
  return {
16086
16729
  documentData: docData,
@@ -23064,7 +23707,7 @@ function stripSdtAffixes(rawText, spec) {
23064
23707
  return text;
23065
23708
  }
23066
23709
  var SDT_CHROME_TEXT_COLORS = /* @__PURE__ */ new Set(["#7d8698", "#9ca3af", "#4e5565", "#2c53f1", "#1b1c1f"]);
23067
- var SDT_CHROME_BG_COLORS = /* @__PURE__ */ new Set(["#f3f5ff", "#eeeff1", "#eff6ff"]);
23710
+ var SDT_CHROME_BG_COLORS = /* @__PURE__ */ new Set(["#f3f5ff", "#eeeff1"]);
23068
23711
  function sanitizeLoopCellRunStyle(ts, anchorTypo) {
23069
23712
  if (!ts && !anchorTypo) return void 0;
23070
23713
  const out = {
@@ -23168,6 +23811,11 @@ function extractAnchorTypography(ts) {
23168
23811
  out.cl = { rgb };
23169
23812
  has = true;
23170
23813
  }
23814
+ const bgRgb = ts.bg?.rgb?.trim();
23815
+ if (bgRgb && !SDT_CHROME_BG_COLORS.has(bgRgb.toLowerCase())) {
23816
+ out.bg = { rgb: bgRgb };
23817
+ has = true;
23818
+ }
23171
23819
  return has ? out : void 0;
23172
23820
  }
23173
23821
  function resolveBodyOffsetTypography(body, offset) {
@@ -23238,7 +23886,9 @@ function computeSdtVisualStyle(kind, lock, showingPlaceholder, hasBinding, match
23238
23886
  bl
23239
23887
  };
23240
23888
  }
23241
- const bgRgb = isReadOnly ? "#eeeff1" : "#f3f5ff";
23889
+ const rawBaseBg = baseTypo.bg?.rgb?.trim();
23890
+ const hasAuthorBg = Boolean(rawBaseBg && !SDT_CHROME_BG_COLORS.has(rawBaseBg.toLowerCase()));
23891
+ const bgRgb = !showingPlaceholder && hasAuthorBg ? rawBaseBg : isReadOnly ? "#eeeff1" : "#f3f5ff";
23242
23892
  return {
23243
23893
  ...baseTypo,
23244
23894
  bg: { rgb: bgRgb },
@@ -25930,29 +26580,50 @@ function buildStructuredDocData(params) {
25930
26580
  width: { v: edge.widthPt ?? 1, u: import_core13.NumberUnitType.POINT }
25931
26581
  };
25932
26582
  };
25933
- if (cellObj.borders) {
26583
+ if (cellObj.borders && !block.fromDocxImport) {
25934
26584
  builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
25935
26585
  ...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
25936
26586
  borders: import_core13.Tools.deepClone(cellObj.borders)
25937
26587
  };
26588
+ } else if (cellObj.explicitBorders && Object.keys(cellObj.explicitBorders).length > 0) {
26589
+ builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] = {
26590
+ ...builtTableCellProps[`${tableId}:${rIdx}:${cIdx}`] ?? {},
26591
+ borders: import_core13.Tools.deepClone(cellObj.explicitBorders)
26592
+ };
25938
26593
  }
26594
+ const resolvedCellMarginPt = cellObj.marginPt ?? block.tableCellMarginPt;
26595
+ const cellMarginObj = resolvedCellMarginPt ? {
26596
+ start: { v: resolvedCellMarginPt.start, u: import_core13.NumberUnitType.POINT },
26597
+ end: { v: resolvedCellMarginPt.end, u: import_core13.NumberUnitType.POINT },
26598
+ top: { v: resolvedCellMarginPt.top, u: import_core13.NumberUnitType.POINT },
26599
+ bottom: { v: resolvedCellMarginPt.bottom, u: import_core13.NumberUnitType.POINT }
26600
+ } : {
26601
+ start: { v: 8, u: import_core13.NumberUnitType.POINT },
26602
+ end: { v: 8, u: import_core13.NumberUnitType.POINT },
26603
+ top: { v: 4, u: import_core13.NumberUnitType.POINT },
26604
+ bottom: { v: 4, u: import_core13.NumberUnitType.POINT }
26605
+ };
26606
+ const borderSrc = block.fromDocxImport ? cellObj.explicitBorders : cellObj.borders;
25939
26607
  cellDefs.push({
25940
- margin: {
25941
- start: { v: 8, u: import_core13.NumberUnitType.POINT },
25942
- end: { v: 8, u: import_core13.NumberUnitType.POINT },
25943
- top: { v: 4, u: import_core13.NumberUnitType.POINT },
25944
- bottom: { v: 4, u: import_core13.NumberUnitType.POINT }
25945
- },
26608
+ margin: cellMarginObj,
25946
26609
  rowSpan: cellObj.rowSpan ?? 1,
25947
26610
  columnSpan: cellObj.colSpan ?? 1,
26611
+ ...cellObj.vAlign !== void 0 ? { vAlign: cellObj.vAlign } : {},
25948
26612
  ...cellObj.tcWidthType ? { tcWidthType: cellObj.tcWidthType } : {},
25949
26613
  ...cellObj.cellSize ? { size: import_core13.Tools.deepClone(cellObj.cellSize) } : {},
25950
26614
  ...cellObj.yudaoTcWidthPct !== void 0 ? { yudaoTcWidthPct: cellObj.yudaoTcWidthPct } : {},
25951
26615
  ...cellObj.backgroundRgb ? { backgroundColor: { rgb: cellObj.backgroundRgb } } : {},
25952
- borderTop: toCellBorderObj(cellObj.borders?.top),
25953
- borderBottom: toCellBorderObj(cellObj.borders?.bottom),
25954
- borderLeft: toCellBorderObj(cellObj.borders?.left),
25955
- borderRight: toCellBorderObj(cellObj.borders?.right)
26616
+ ...block.fromDocxImport ? {
26617
+ ...borderSrc?.top ? { borderTop: toCellBorderObj(borderSrc.top) } : {},
26618
+ ...borderSrc?.bottom ? { borderBottom: toCellBorderObj(borderSrc.bottom) } : {},
26619
+ ...borderSrc?.left ? { borderLeft: toCellBorderObj(borderSrc.left) } : {},
26620
+ ...borderSrc?.right ? { borderRight: toCellBorderObj(borderSrc.right) } : {}
26621
+ } : {
26622
+ borderTop: toCellBorderObj(cellObj.borders?.top),
26623
+ borderBottom: toCellBorderObj(cellObj.borders?.bottom),
26624
+ borderLeft: toCellBorderObj(cellObj.borders?.left),
26625
+ borderRight: toCellBorderObj(cellObj.borders?.right)
26626
+ }
25956
26627
  });
25957
26628
  }
25958
26629
  const effectiveHdrCount = typeof block.headerRowCount === "number" ? Math.max(0, block.headerRowCount) : block.repeatHeaderRow === false ? 0 : 1;
@@ -25963,6 +26634,14 @@ function buildStructuredDocData(params) {
25963
26634
  const rMeta = block.rowMeta?.[rIdx];
25964
26635
  tableRows.push({
25965
26636
  tableCells: cellDefs,
26637
+ ...rMeta?.cellMarginPt ? {
26638
+ cellMargin: {
26639
+ start: { v: rMeta.cellMarginPt.start, u: import_core13.NumberUnitType.POINT },
26640
+ end: { v: rMeta.cellMarginPt.end, u: import_core13.NumberUnitType.POINT },
26641
+ top: { v: rMeta.cellMarginPt.top, u: import_core13.NumberUnitType.POINT },
26642
+ bottom: { v: rMeta.cellMarginPt.bottom, u: import_core13.NumberUnitType.POINT }
26643
+ }
26644
+ } : {},
25966
26645
  trHeight: rMeta?.trHeight ? import_core13.Tools.deepClone(rMeta.trHeight) : {
25967
26646
  val: { v: 24, u: import_core13.NumberUnitType.POINT },
25968
26647
  hRule: import_core13.TableRowHeightRule.AT_LEAST
@@ -26000,6 +26679,16 @@ function buildStructuredDocData(params) {
26000
26679
  },
26001
26680
  type: 0
26002
26681
  },
26682
+ ...block.styleId ? { styleId: block.styleId } : {},
26683
+ ...block.tableCellMarginPt ? {
26684
+ cellMargin: {
26685
+ start: { v: block.tableCellMarginPt.start, u: import_core13.NumberUnitType.POINT },
26686
+ end: { v: block.tableCellMarginPt.end, u: import_core13.NumberUnitType.POINT },
26687
+ top: { v: block.tableCellMarginPt.top, u: import_core13.NumberUnitType.POINT },
26688
+ bottom: { v: block.tableCellMarginPt.bottom, u: import_core13.NumberUnitType.POINT }
26689
+ }
26690
+ } : {},
26691
+ ...block.tableBorderDefaults ? { borderDefaults: import_core13.Tools.deepClone(block.tableBorderDefaults) } : {},
26003
26692
  ...block.tableLayout !== void 0 ? { layout: block.tableLayout } : {},
26004
26693
  ...block.yudaoTblWidthType ? { yudaoTblWidthType: block.yudaoTblWidthType } : {},
26005
26694
  ...block.yudaoTblWidthDxa !== void 0 ? { yudaoTblWidthDxa: block.yudaoTblWidthDxa } : {},