@harbour-enterprises/superdoc 1.3.0-next.2 → 1.3.0-next.3

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.
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  const jszip = require("./jszip-C8_CqJxM.cjs");
3
3
  const helpers$1 = require("./helpers-nOdwpmwb.cjs");
4
- const superEditor_converter = require("./SuperConverter-DOTz2R8L.cjs");
4
+ const superEditor_converter = require("./SuperConverter-XGlv5pME.cjs");
5
5
  const vue = require("./vue-De9wkgLl.cjs");
6
6
  require("./jszip.min-BPh2MMAa.cjs");
7
7
  const eventemitter3 = require("./eventemitter3-BQuRcMPI.cjs");
@@ -175,6 +175,354 @@ function parseSizeUnit(val = "0") {
175
175
  function minMax(value = 0, min2 = 0, max2 = 0) {
176
176
  return Math.min(Math.max(value, min2), max2);
177
177
  }
178
+ const FONT_FAMILY_FALLBACKS = Object.freeze({
179
+ swiss: "Arial, sans-serif",
180
+ roman: "Times New Roman, serif",
181
+ modern: "Courier New, monospace",
182
+ script: "cursive",
183
+ decorative: "fantasy",
184
+ system: "system-ui",
185
+ auto: "sans-serif"
186
+ });
187
+ const DEFAULT_GENERIC_FALLBACK = "sans-serif";
188
+ const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
189
+ function mapWordFamilyFallback(wordFamily) {
190
+ if (!wordFamily) return DEFAULT_GENERIC_FALLBACK;
191
+ const mapped = FONT_FAMILY_FALLBACKS[wordFamily.toLowerCase()];
192
+ return mapped || DEFAULT_GENERIC_FALLBACK;
193
+ }
194
+ function toCssFontFamily(fontName, options = {}) {
195
+ if (!fontName || typeof fontName !== "string") return fontName;
196
+ const trimmed = fontName.trim();
197
+ if (!trimmed || trimmed.includes(",")) return trimmed;
198
+ const { fallback, wordFamily } = options;
199
+ const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK;
200
+ const fallbackParts = normalizeParts(fallbackValue);
201
+ if (fallbackParts.length === 0) {
202
+ return trimmed;
203
+ }
204
+ const normalizedName = trimmed.toLowerCase();
205
+ const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
206
+ if (includesName) {
207
+ return fallbackParts.join(", ");
208
+ }
209
+ return [trimmed, ...fallbackParts].join(", ");
210
+ }
211
+ const sdtMetadataCache = /* @__PURE__ */ new Map();
212
+ function resolveStyle(node, context, options = {}) {
213
+ let paragraph = createDefaultParagraph();
214
+ let character = createDefaultCharacter(context);
215
+ let numbering;
216
+ const chain = resolveStyleChain(node.styleId, context.styles);
217
+ for (const style2 of chain) {
218
+ paragraph = mergeParagraph(paragraph, style2.paragraph);
219
+ character = mergeCharacter(character, style2.character);
220
+ if (!numbering && style2.numbering) {
221
+ numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
222
+ }
223
+ }
224
+ paragraph = mergeParagraph(paragraph, node.paragraphProps);
225
+ character = mergeCharacter(character, node.characterProps);
226
+ if (node.numbering) {
227
+ numbering = resolveNumbering(node.numbering.numId, node.numbering.level, context);
228
+ }
229
+ const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
230
+ return {
231
+ paragraph,
232
+ character,
233
+ numbering,
234
+ sdt
235
+ };
236
+ }
237
+ function resolveNumbering(numId, level, context) {
238
+ const def = context.numbering?.[numId];
239
+ if (!def) return void 0;
240
+ const levelDef = def.levels.find((entry) => entry.level === level) ?? def.levels[level];
241
+ if (!levelDef) return void 0;
242
+ return {
243
+ numId,
244
+ level,
245
+ indent: {
246
+ left: levelDef.indent?.left,
247
+ hanging: levelDef.indent?.hanging
248
+ },
249
+ format: levelDef.format ?? "decimal",
250
+ text: levelDef.text ?? "%1.",
251
+ start: levelDef.start ?? 1
252
+ };
253
+ }
254
+ function resolveSdtMetadata(input) {
255
+ if (!input) return void 0;
256
+ const { nodeType, attrs, cacheKey: explicitKey } = input;
257
+ if (!nodeType) return void 0;
258
+ const normalizedAttrs = isPlainObject$4(attrs) ? attrs : {};
259
+ const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
260
+ if (cacheKey && sdtMetadataCache.has(cacheKey)) {
261
+ return sdtMetadataCache.get(cacheKey);
262
+ }
263
+ let metadata;
264
+ switch (nodeType) {
265
+ case "fieldAnnotation":
266
+ metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
267
+ break;
268
+ case "structuredContent":
269
+ case "structuredContentBlock":
270
+ metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
271
+ break;
272
+ case "documentSection":
273
+ metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
274
+ break;
275
+ case "docPartObject":
276
+ metadata = normalizeDocPartMetadata(normalizedAttrs);
277
+ break;
278
+ }
279
+ if (metadata && cacheKey) {
280
+ sdtMetadataCache.set(cacheKey, metadata);
281
+ }
282
+ return metadata;
283
+ }
284
+ function createDefaultParagraph(_context) {
285
+ return {
286
+ alignment: "left",
287
+ spacing: {
288
+ before: 0,
289
+ after: 0,
290
+ line: 12,
291
+ lineRule: "auto"
292
+ },
293
+ indent: {
294
+ left: 0,
295
+ right: 0,
296
+ firstLine: 0,
297
+ hanging: 0
298
+ },
299
+ tabs: []
300
+ };
301
+ }
302
+ function createDefaultCharacter(context) {
303
+ const baseFont = context.defaults?.paragraphFont ?? "Calibri";
304
+ const fallback = context.defaults?.paragraphFontFallback;
305
+ const wordFamily = context.defaults?.paragraphFontFamily;
306
+ const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
307
+ return {
308
+ font: {
309
+ family: resolvedFamily,
310
+ size: context.defaults?.fontSize ?? 11,
311
+ weight: 400,
312
+ italic: false
313
+ },
314
+ color: "#000000"
315
+ };
316
+ }
317
+ function resolveStyleChain(styleId, styles) {
318
+ if (!styleId || !styles) return [];
319
+ const result = [];
320
+ const visited = /* @__PURE__ */ new Set();
321
+ let current = styles[styleId];
322
+ while (current && !visited.has(current.id)) {
323
+ result.unshift(current);
324
+ visited.add(current.id);
325
+ current = current.basedOn ? styles[current.basedOn] : void 0;
326
+ }
327
+ return result;
328
+ }
329
+ function mergeParagraph(base2, overrides) {
330
+ if (!overrides) return base2;
331
+ return {
332
+ ...base2,
333
+ alignment: overrides.alignment ?? base2.alignment,
334
+ spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
335
+ indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
336
+ borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
337
+ shading: overrides.shading ?? base2.shading,
338
+ tabs: overrides.tabs ?? base2.tabs
339
+ };
340
+ }
341
+ function mergeCharacter(base2, overrides) {
342
+ if (!overrides) return base2;
343
+ return {
344
+ ...base2,
345
+ font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
346
+ color: overrides.color ?? base2.color,
347
+ underline: overrides.underline ?? base2.underline,
348
+ strike: overrides.strike ?? base2.strike,
349
+ highlight: overrides.highlight ?? base2.highlight,
350
+ letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
351
+ };
352
+ }
353
+ function normalizeFieldAnnotationMetadata(attrs) {
354
+ const fieldId = toOptionalString(attrs.fieldId) ?? "";
355
+ const formatting = extractFormatting(attrs);
356
+ const size2 = normalizeSize(attrs.size);
357
+ const extras = isPlainObject$4(attrs.extras) ? attrs.extras : null;
358
+ const marks = isPlainObject$4(attrs.marks) ? attrs.marks : void 0;
359
+ return {
360
+ type: "fieldAnnotation",
361
+ fieldId,
362
+ variant: normalizeFieldAnnotationVariant(attrs.type),
363
+ fieldType: toOptionalString(attrs.fieldType),
364
+ displayLabel: toOptionalString(attrs.displayLabel),
365
+ defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
366
+ alias: toOptionalString(attrs.alias),
367
+ fieldColor: normalizeColorValue(attrs.fieldColor),
368
+ borderColor: normalizeColorValue(attrs.borderColor),
369
+ highlighted: toBoolean$3(attrs.highlighted, true),
370
+ fontFamily: toNullableString(attrs.fontFamily),
371
+ fontSize: normalizeFontSize(attrs.fontSize),
372
+ textColor: normalizeColorValue(attrs.textColor) ?? null,
373
+ textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
374
+ linkUrl: toNullableString(attrs.linkUrl),
375
+ imageSrc: toNullableString(attrs.imageSrc),
376
+ rawHtml: attrs.rawHtml ?? void 0,
377
+ size: size2 ?? null,
378
+ extras,
379
+ multipleImage: toBoolean$3(attrs.multipleImage, false),
380
+ hash: toOptionalString(attrs.hash) ?? null,
381
+ generatorIndex: toNumber(attrs.generatorIndex),
382
+ sdtId: toOptionalString(attrs.sdtId) ?? null,
383
+ hidden: toBoolean$3(attrs.hidden, false),
384
+ visibility: normalizeVisibility(attrs.visibility),
385
+ isLocked: toBoolean$3(attrs.isLocked, false),
386
+ formatting,
387
+ marks
388
+ };
389
+ }
390
+ function normalizeStructuredContentMetadata(nodeType, attrs) {
391
+ return {
392
+ type: "structuredContent",
393
+ scope: nodeType === "structuredContentBlock" ? "block" : "inline",
394
+ id: toNullableString(attrs.id),
395
+ tag: toOptionalString(attrs.tag),
396
+ alias: toOptionalString(attrs.alias),
397
+ sdtPr: attrs.sdtPr
398
+ };
399
+ }
400
+ function normalizeDocumentSectionMetadata(attrs) {
401
+ return {
402
+ type: "documentSection",
403
+ id: toNullableString(attrs.id),
404
+ title: toOptionalString(attrs.title) ?? null,
405
+ description: toOptionalString(attrs.description) ?? null,
406
+ sectionType: toOptionalString(attrs.sectionType) ?? null,
407
+ isLocked: toBoolean$3(attrs.isLocked, false),
408
+ sdBlockId: toNullableString(attrs.sdBlockId)
409
+ };
410
+ }
411
+ function normalizeDocPartMetadata(attrs) {
412
+ return {
413
+ type: "docPartObject",
414
+ gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
415
+ // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
416
+ // Fall back to attrs.uniqueId for compatibility
417
+ uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
418
+ alias: toOptionalString(attrs.alias) ?? null,
419
+ instruction: toOptionalString(attrs.instruction) ?? null
420
+ };
421
+ }
422
+ function isPlainObject$4(value) {
423
+ return !!value && typeof value === "object" && !Array.isArray(value);
424
+ }
425
+ function toOptionalString(value) {
426
+ if (value == null) return void 0;
427
+ if (typeof value === "string") {
428
+ const trimmed = value.trim();
429
+ return trimmed.length ? trimmed : void 0;
430
+ }
431
+ return String(value);
432
+ }
433
+ function toNullableString(value) {
434
+ const str = toOptionalString(value);
435
+ return str ?? null;
436
+ }
437
+ function toBoolean$3(value, fallback) {
438
+ if (typeof value === "boolean") return value;
439
+ if (typeof value === "string") {
440
+ const lower = value.toLowerCase();
441
+ if (lower === "true") return true;
442
+ if (lower === "false") return false;
443
+ }
444
+ if (value == null) return fallback;
445
+ return Boolean(value);
446
+ }
447
+ function normalizeVisibility(value) {
448
+ if (typeof value !== "string") return void 0;
449
+ const normalized = value.toLowerCase();
450
+ if (normalized === "visible" || normalized === "hidden") {
451
+ return normalized;
452
+ }
453
+ return void 0;
454
+ }
455
+ function normalizeColorValue(value) {
456
+ if (typeof value !== "string") return void 0;
457
+ const trimmed = value.trim();
458
+ if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
459
+ return trimmed;
460
+ }
461
+ function normalizeFontSize(value) {
462
+ if (value == null) return null;
463
+ if (typeof value === "number") {
464
+ return Number.isFinite(value) ? value : null;
465
+ }
466
+ if (typeof value === "string") {
467
+ const trimmed = value.trim();
468
+ return trimmed.length ? trimmed : null;
469
+ }
470
+ return null;
471
+ }
472
+ function toNumber(value) {
473
+ if (typeof value === "number") {
474
+ return Number.isFinite(value) ? value : null;
475
+ }
476
+ if (typeof value === "string") {
477
+ const parsed = parseFloat(value);
478
+ return Number.isFinite(parsed) ? parsed : null;
479
+ }
480
+ return null;
481
+ }
482
+ function normalizeSize(value) {
483
+ if (!isPlainObject$4(value)) return null;
484
+ const obj = value;
485
+ const width = toNumber(obj.width);
486
+ const height = toNumber(obj.height);
487
+ if (width == null && height == null) return null;
488
+ const result = {};
489
+ if (width != null) result.width = width;
490
+ if (height != null) result.height = height;
491
+ return result;
492
+ }
493
+ function normalizeFieldAnnotationVariant(value) {
494
+ if (typeof value !== "string") return void 0;
495
+ const normalized = value.toLowerCase();
496
+ if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
497
+ return normalized;
498
+ }
499
+ return void 0;
500
+ }
501
+ function extractFormatting(attrs) {
502
+ const bold = toBoolean$3(attrs.bold, false);
503
+ const italic = toBoolean$3(attrs.italic, false);
504
+ const underline = toBoolean$3(attrs.underline, false);
505
+ const formatting = {};
506
+ if (bold) formatting.bold = true;
507
+ if (italic) formatting.italic = true;
508
+ if (underline) formatting.underline = true;
509
+ return Object.keys(formatting).length ? formatting : void 0;
510
+ }
511
+ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
512
+ const provided = toOptionalString(explicitKey);
513
+ if (provided) {
514
+ return `${nodeType}:${provided}`;
515
+ }
516
+ const hash2 = toOptionalString(attrs.hash);
517
+ if (hash2) {
518
+ return `${nodeType}:${hash2}`;
519
+ }
520
+ const id = toOptionalString(attrs.id);
521
+ if (id) {
522
+ return `${nodeType}:${id}`;
523
+ }
524
+ return void 0;
525
+ }
178
526
  function createDocument(converter, schema, editor, { check = false } = {}) {
179
527
  const documentData = converter.getSchema(editor);
180
528
  if (documentData) {
@@ -9108,15 +9456,19 @@ const splitRunToParagraph = () => (props) => {
9108
9456
  dispatchTransaction = editor.dispatch.bind(editor);
9109
9457
  }
9110
9458
  if (!dispatchTransaction) return false;
9111
- const handled = splitBlockPatch(state, (transaction) => {
9112
- dispatchTransaction(transaction);
9113
- });
9459
+ const handled = splitBlockPatch(
9460
+ state,
9461
+ (transaction) => {
9462
+ dispatchTransaction(transaction);
9463
+ },
9464
+ editor
9465
+ );
9114
9466
  if (handled) {
9115
9467
  tr.setMeta("preventDispatch", true);
9116
9468
  }
9117
9469
  return handled;
9118
9470
  };
9119
- function splitBlockPatch(state, dispatch) {
9471
+ function splitBlockPatch(state, dispatch, editor) {
9120
9472
  let { $from } = state.selection;
9121
9473
  if (state.selection instanceof superEditor_converter.NodeSelection && state.selection.node.isBlock) {
9122
9474
  if (!$from.parentOffset || !superEditor_converter.canSplit(state.doc, $from.pos)) return false;
@@ -9125,14 +9477,15 @@ function splitBlockPatch(state, dispatch) {
9125
9477
  }
9126
9478
  if (!$from.depth) return false;
9127
9479
  let types = [];
9128
- let splitDepth, deflt, atEnd = false, atStart = false;
9480
+ let splitDepth, deflt, paragraphAttrs = null, atEnd = false, atStart = false;
9129
9481
  for (let d2 = $from.depth; ; d2--) {
9130
9482
  let node = $from.node(d2);
9131
9483
  if (node.isBlock) {
9132
9484
  atEnd = $from.end(d2) == $from.pos + ($from.depth - d2);
9133
9485
  atStart = $from.start(d2) == $from.pos - ($from.depth - d2);
9134
9486
  deflt = defaultBlockAt$1($from.node(d2 - 1).contentMatchAt($from.indexAfter(d2 - 1)));
9135
- types.unshift(null);
9487
+ paragraphAttrs = { ...node.attrs };
9488
+ types.unshift({ type: deflt || node.type, attrs: paragraphAttrs });
9136
9489
  splitDepth = d2;
9137
9490
  break;
9138
9491
  } else {
@@ -9145,7 +9498,7 @@ function splitBlockPatch(state, dispatch) {
9145
9498
  let splitPos = tr.mapping.map($from.pos);
9146
9499
  let can = superEditor_converter.canSplit(tr.doc, splitPos, types.length, types);
9147
9500
  if (!can) {
9148
- types[0] = deflt ? { type: deflt } : null;
9501
+ types[0] = deflt ? { type: deflt, attrs: paragraphAttrs } : null;
9149
9502
  can = superEditor_converter.canSplit(tr.doc, splitPos, types.length, types);
9150
9503
  }
9151
9504
  if (!can) return false;
@@ -9155,9 +9508,37 @@ function splitBlockPatch(state, dispatch) {
9155
9508
  if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt))
9156
9509
  tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
9157
9510
  }
9511
+ applyStyleMarks(state, tr, editor, paragraphAttrs);
9158
9512
  if (dispatch) dispatch(tr.scrollIntoView());
9159
9513
  return true;
9160
9514
  }
9515
+ function applyStyleMarks(state, tr, editor, paragraphAttrs) {
9516
+ const styleId = paragraphAttrs?.paragraphProperties?.styleId;
9517
+ if (!editor?.converter && !styleId) {
9518
+ return;
9519
+ }
9520
+ try {
9521
+ const params2 = { docx: editor?.converter?.convertedXml ?? {}, numbering: editor?.converter?.numbering ?? {} };
9522
+ const resolvedPpr = styleId ? { styleId } : {};
9523
+ const runProperties = styleId ? superEditor_converter.resolveRunProperties(params2, {}, resolvedPpr, false, false) : {};
9524
+ const markDefsFromStyle = styleId ? (
9525
+ /** @type {Array<{type: string, attrs: Record<string, unknown>}>} */
9526
+ superEditor_converter.encodeMarksFromRPr(runProperties, editor?.converter?.convertedXml ?? {})
9527
+ ) : [];
9528
+ const selectionMarks = state.selection?.$from?.marks ? state.selection.$from.marks() : [];
9529
+ const selectionMarkDefs = selectionMarks.map((mark) => ({ type: mark.type.name, attrs: mark.attrs }));
9530
+ const markDefsToApply = selectionMarks.length ? selectionMarkDefs : markDefsFromStyle;
9531
+ const marksToApply = markDefsToApply.map((def) => {
9532
+ const markType = state.schema.marks[def.type];
9533
+ return markType ? markType.create(def.attrs) : null;
9534
+ }).filter(Boolean);
9535
+ if (marksToApply.length > 0) {
9536
+ tr.ensureMarks(marksToApply);
9537
+ tr.setMeta("sdStyleMarks", markDefsToApply);
9538
+ }
9539
+ } catch {
9540
+ }
9541
+ }
9161
9542
  const splitRunAtCursor = () => (props) => {
9162
9543
  let { state, dispatch, tr } = props;
9163
9544
  const sel = state.selection;
@@ -10041,7 +10422,7 @@ const updateAttributes = (typeOrName, attrs = {}) => ({ tr, state, dispatch }) =
10041
10422
  }
10042
10423
  return true;
10043
10424
  };
10044
- const isPlainObject$4 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
10425
+ const isPlainObject$3 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
10045
10426
  const assignNestedValue = (target, path, value) => {
10046
10427
  if (!path.includes(".")) {
10047
10428
  target[path] = value;
@@ -10055,7 +10436,7 @@ const assignNestedValue = (target, path, value) => {
10055
10436
  if (isLast) {
10056
10437
  current[part] = value;
10057
10438
  } else {
10058
- if (!isPlainObject$4(current[part])) {
10439
+ if (!isPlainObject$3(current[part])) {
10059
10440
  current[part] = {};
10060
10441
  }
10061
10442
  current = current[part];
@@ -14915,7 +15296,7 @@ const canUseDOM = () => {
14915
15296
  return false;
14916
15297
  }
14917
15298
  };
14918
- const summaryVersion = "1.3.0-next.2";
15299
+ const summaryVersion = "1.3.0-next.3";
14919
15300
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
14920
15301
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
14921
15302
  function mapAttributes(attrs) {
@@ -17548,7 +17929,7 @@ class Editor extends EventEmitter {
17548
17929
  * Process collaboration migrations
17549
17930
  */
17550
17931
  processCollaborationMigrations() {
17551
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.2");
17932
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.3");
17552
17933
  if (!this.options.ydoc) return;
17553
17934
  const metaMap = this.options.ydoc.getMap("meta");
17554
17935
  let docVersion = metaMap.get("version");
@@ -23123,39 +23504,6 @@ const resolveTableCellBorders = (tableBorders, rowIndex, colIndex, totalRows, to
23123
23504
  right: borderValueToSpec(isLastCol ? tableBorders?.right : null)
23124
23505
  };
23125
23506
  };
23126
- const FONT_FAMILY_FALLBACKS = Object.freeze({
23127
- swiss: "Arial, sans-serif",
23128
- roman: "Times New Roman, serif",
23129
- modern: "Courier New, monospace",
23130
- script: "cursive",
23131
- decorative: "fantasy",
23132
- system: "system-ui",
23133
- auto: "sans-serif"
23134
- });
23135
- const DEFAULT_GENERIC_FALLBACK = "sans-serif";
23136
- const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
23137
- function mapWordFamilyFallback(wordFamily) {
23138
- if (!wordFamily) return DEFAULT_GENERIC_FALLBACK;
23139
- const mapped = FONT_FAMILY_FALLBACKS[wordFamily.toLowerCase()];
23140
- return mapped || DEFAULT_GENERIC_FALLBACK;
23141
- }
23142
- function toCssFontFamily(fontName, options = {}) {
23143
- if (!fontName || typeof fontName !== "string") return fontName;
23144
- const trimmed = fontName.trim();
23145
- if (!trimmed || trimmed.includes(",")) return trimmed;
23146
- const { fallback, wordFamily } = options;
23147
- const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK;
23148
- const fallbackParts = normalizeParts(fallbackValue);
23149
- if (fallbackParts.length === 0) {
23150
- return trimmed;
23151
- }
23152
- const normalizedName = trimmed.toLowerCase();
23153
- const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
23154
- if (includesName) {
23155
- return fallbackParts.join(", ");
23156
- }
23157
- return [trimmed, ...fallbackParts].join(", ");
23158
- }
23159
23507
  const LIST_MARKER_GAP$3 = 8;
23160
23508
  function renderListMarker(params2) {
23161
23509
  const { doc: doc2, lineEl, markerLayout, markerMeasure, indentLeftPx } = params2;
@@ -39720,7 +40068,7 @@ const pxToPt = (px) => {
39720
40068
  return px / PX_PER_PT;
39721
40069
  };
39722
40070
  const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
39723
- const isPlainObject$3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
40071
+ const isPlainObject$2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
39724
40072
  const normalizePrefix = (value) => {
39725
40073
  if (!value) return "";
39726
40074
  return String(value);
@@ -39782,7 +40130,7 @@ function coerceBoolean(value) {
39782
40130
  }
39783
40131
  return void 0;
39784
40132
  }
39785
- const toBoolean$3 = (value) => {
40133
+ const toBoolean$2 = (value) => {
39786
40134
  if (typeof value === "boolean") return value;
39787
40135
  if (typeof value === "string") {
39788
40136
  const v = value.trim().toLowerCase();
@@ -40073,7 +40421,7 @@ function hydrateImageBlocks(blocks, mediaFiles) {
40073
40421
  });
40074
40422
  }
40075
40423
  function isGradientFill(value) {
40076
- if (!isPlainObject$3(value)) return false;
40424
+ if (!isPlainObject$2(value)) return false;
40077
40425
  if (value.type !== "gradient") return false;
40078
40426
  const gradientType = value.gradientType;
40079
40427
  if (gradientType !== "linear" && gradientType !== "radial") return false;
@@ -40084,12 +40432,12 @@ function isGradientFill(value) {
40084
40432
  }
40085
40433
  if (!Array.isArray(value.stops) || value.stops.length === 0) return false;
40086
40434
  return value.stops.every((stop) => {
40087
- if (!isPlainObject$3(stop)) return false;
40435
+ if (!isPlainObject$2(stop)) return false;
40088
40436
  return typeof stop.position === "number" && Number.isFinite(stop.position) && typeof stop.color === "string" && (stop.alpha === void 0 || typeof stop.alpha === "number" && Number.isFinite(stop.alpha));
40089
40437
  });
40090
40438
  }
40091
40439
  function isSolidFillWithAlpha(value) {
40092
- return isPlainObject$3(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
40440
+ return isPlainObject$2(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
40093
40441
  }
40094
40442
  function normalizeFillColor(value) {
40095
40443
  if (value === null) return null;
@@ -40104,10 +40452,10 @@ function normalizeStrokeColor(value) {
40104
40452
  return void 0;
40105
40453
  }
40106
40454
  function normalizeTextContent(value) {
40107
- if (!isPlainObject$3(value)) return void 0;
40455
+ if (!isPlainObject$2(value)) return void 0;
40108
40456
  if (!Array.isArray(value.parts)) return void 0;
40109
40457
  if (value.parts.length === 0) return void 0;
40110
- const validParts = value.parts.filter((p) => isPlainObject$3(p) && typeof p.text === "string");
40458
+ const validParts = value.parts.filter((p) => isPlainObject$2(p) && typeof p.text === "string");
40111
40459
  if (validParts.length === 0) return void 0;
40112
40460
  const result = {
40113
40461
  parts: validParts
@@ -40125,7 +40473,7 @@ function normalizeTextVerticalAlign(value) {
40125
40473
  return void 0;
40126
40474
  }
40127
40475
  function normalizeTextInsets(value) {
40128
- if (!isPlainObject$3(value)) return void 0;
40476
+ if (!isPlainObject$2(value)) return void 0;
40129
40477
  const top2 = pickNumber(value.top);
40130
40478
  const right2 = pickNumber(value.right);
40131
40479
  const bottom2 = pickNumber(value.bottom);
@@ -40137,7 +40485,7 @@ function normalizeTextInsets(value) {
40137
40485
  }
40138
40486
  const OOXML_Z_INDEX_BASE = 251658240;
40139
40487
  function normalizeZIndex(originalAttributes) {
40140
- if (!isPlainObject$3(originalAttributes)) return void 0;
40488
+ if (!isPlainObject$2(originalAttributes)) return void 0;
40141
40489
  const relativeHeight = originalAttributes.relativeHeight;
40142
40490
  if (typeof relativeHeight !== "number") return void 0;
40143
40491
  return Math.max(0, relativeHeight - OOXML_Z_INDEX_BASE);
@@ -41331,321 +41679,6 @@ const ensureBidiIndentPx = (indent) => {
41331
41679
  }
41332
41680
  return adjusted;
41333
41681
  };
41334
- const sdtMetadataCache = /* @__PURE__ */ new Map();
41335
- function resolveStyle(node, context, options = {}) {
41336
- let paragraph = createDefaultParagraph();
41337
- let character = createDefaultCharacter(context);
41338
- let numbering;
41339
- const chain = resolveStyleChain(node.styleId, context.styles);
41340
- for (const style2 of chain) {
41341
- paragraph = mergeParagraph(paragraph, style2.paragraph);
41342
- character = mergeCharacter(character, style2.character);
41343
- if (!numbering && style2.numbering) {
41344
- numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
41345
- }
41346
- }
41347
- paragraph = mergeParagraph(paragraph, node.paragraphProps);
41348
- character = mergeCharacter(character, node.characterProps);
41349
- if (node.numbering) {
41350
- numbering = resolveNumbering(node.numbering.numId, node.numbering.level, context);
41351
- }
41352
- const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
41353
- return {
41354
- paragraph,
41355
- character,
41356
- numbering,
41357
- sdt
41358
- };
41359
- }
41360
- function resolveNumbering(numId, level, context) {
41361
- const def = context.numbering?.[numId];
41362
- if (!def) return void 0;
41363
- const levelDef = def.levels.find((entry) => entry.level === level) ?? def.levels[level];
41364
- if (!levelDef) return void 0;
41365
- return {
41366
- numId,
41367
- level,
41368
- indent: {
41369
- left: levelDef.indent?.left,
41370
- hanging: levelDef.indent?.hanging
41371
- },
41372
- format: levelDef.format ?? "decimal",
41373
- text: levelDef.text ?? "%1.",
41374
- start: levelDef.start ?? 1
41375
- };
41376
- }
41377
- function resolveSdtMetadata(input) {
41378
- if (!input) return void 0;
41379
- const { nodeType, attrs, cacheKey: explicitKey } = input;
41380
- if (!nodeType) return void 0;
41381
- const normalizedAttrs = isPlainObject$2(attrs) ? attrs : {};
41382
- const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
41383
- if (cacheKey && sdtMetadataCache.has(cacheKey)) {
41384
- return sdtMetadataCache.get(cacheKey);
41385
- }
41386
- let metadata;
41387
- switch (nodeType) {
41388
- case "fieldAnnotation":
41389
- metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
41390
- break;
41391
- case "structuredContent":
41392
- case "structuredContentBlock":
41393
- metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
41394
- break;
41395
- case "documentSection":
41396
- metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
41397
- break;
41398
- case "docPartObject":
41399
- metadata = normalizeDocPartMetadata(normalizedAttrs);
41400
- break;
41401
- }
41402
- if (metadata && cacheKey) {
41403
- sdtMetadataCache.set(cacheKey, metadata);
41404
- }
41405
- return metadata;
41406
- }
41407
- function createDefaultParagraph(_context) {
41408
- return {
41409
- alignment: "left",
41410
- spacing: {
41411
- before: 0,
41412
- after: 0,
41413
- line: 12,
41414
- lineRule: "auto"
41415
- },
41416
- indent: {
41417
- left: 0,
41418
- right: 0,
41419
- firstLine: 0,
41420
- hanging: 0
41421
- },
41422
- tabs: []
41423
- };
41424
- }
41425
- function createDefaultCharacter(context) {
41426
- const baseFont = context.defaults?.paragraphFont ?? "Calibri";
41427
- const fallback = context.defaults?.paragraphFontFallback;
41428
- const wordFamily = context.defaults?.paragraphFontFamily;
41429
- const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
41430
- return {
41431
- font: {
41432
- family: resolvedFamily,
41433
- size: context.defaults?.fontSize ?? 11,
41434
- weight: 400,
41435
- italic: false
41436
- },
41437
- color: "#000000"
41438
- };
41439
- }
41440
- function resolveStyleChain(styleId, styles) {
41441
- if (!styleId || !styles) return [];
41442
- const result = [];
41443
- const visited = /* @__PURE__ */ new Set();
41444
- let current = styles[styleId];
41445
- while (current && !visited.has(current.id)) {
41446
- result.unshift(current);
41447
- visited.add(current.id);
41448
- current = current.basedOn ? styles[current.basedOn] : void 0;
41449
- }
41450
- return result;
41451
- }
41452
- function mergeParagraph(base2, overrides) {
41453
- if (!overrides) return base2;
41454
- return {
41455
- ...base2,
41456
- alignment: overrides.alignment ?? base2.alignment,
41457
- spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
41458
- indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
41459
- borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
41460
- shading: overrides.shading ?? base2.shading,
41461
- tabs: overrides.tabs ?? base2.tabs
41462
- };
41463
- }
41464
- function mergeCharacter(base2, overrides) {
41465
- if (!overrides) return base2;
41466
- return {
41467
- ...base2,
41468
- font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
41469
- color: overrides.color ?? base2.color,
41470
- underline: overrides.underline ?? base2.underline,
41471
- strike: overrides.strike ?? base2.strike,
41472
- highlight: overrides.highlight ?? base2.highlight,
41473
- letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
41474
- };
41475
- }
41476
- function normalizeFieldAnnotationMetadata(attrs) {
41477
- const fieldId = toOptionalString(attrs.fieldId) ?? "";
41478
- const formatting = extractFormatting(attrs);
41479
- const size2 = normalizeSize(attrs.size);
41480
- const extras = isPlainObject$2(attrs.extras) ? attrs.extras : null;
41481
- const marks = isPlainObject$2(attrs.marks) ? attrs.marks : void 0;
41482
- return {
41483
- type: "fieldAnnotation",
41484
- fieldId,
41485
- variant: normalizeFieldAnnotationVariant(attrs.type),
41486
- fieldType: toOptionalString(attrs.fieldType),
41487
- displayLabel: toOptionalString(attrs.displayLabel),
41488
- defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
41489
- alias: toOptionalString(attrs.alias),
41490
- fieldColor: normalizeColorValue(attrs.fieldColor),
41491
- borderColor: normalizeColorValue(attrs.borderColor),
41492
- highlighted: toBoolean$2(attrs.highlighted, true),
41493
- fontFamily: toNullableString(attrs.fontFamily),
41494
- fontSize: normalizeFontSize(attrs.fontSize),
41495
- textColor: normalizeColorValue(attrs.textColor) ?? null,
41496
- textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
41497
- linkUrl: toNullableString(attrs.linkUrl),
41498
- imageSrc: toNullableString(attrs.imageSrc),
41499
- rawHtml: attrs.rawHtml ?? void 0,
41500
- size: size2 ?? null,
41501
- extras,
41502
- multipleImage: toBoolean$2(attrs.multipleImage, false),
41503
- hash: toOptionalString(attrs.hash) ?? null,
41504
- generatorIndex: toNumber(attrs.generatorIndex),
41505
- sdtId: toOptionalString(attrs.sdtId) ?? null,
41506
- hidden: toBoolean$2(attrs.hidden, false),
41507
- visibility: normalizeVisibility(attrs.visibility),
41508
- isLocked: toBoolean$2(attrs.isLocked, false),
41509
- formatting,
41510
- marks
41511
- };
41512
- }
41513
- function normalizeStructuredContentMetadata(nodeType, attrs) {
41514
- return {
41515
- type: "structuredContent",
41516
- scope: nodeType === "structuredContentBlock" ? "block" : "inline",
41517
- id: toNullableString(attrs.id),
41518
- tag: toOptionalString(attrs.tag),
41519
- alias: toOptionalString(attrs.alias),
41520
- sdtPr: attrs.sdtPr
41521
- };
41522
- }
41523
- function normalizeDocumentSectionMetadata(attrs) {
41524
- return {
41525
- type: "documentSection",
41526
- id: toNullableString(attrs.id),
41527
- title: toOptionalString(attrs.title) ?? null,
41528
- description: toOptionalString(attrs.description) ?? null,
41529
- sectionType: toOptionalString(attrs.sectionType) ?? null,
41530
- isLocked: toBoolean$2(attrs.isLocked, false),
41531
- sdBlockId: toNullableString(attrs.sdBlockId)
41532
- };
41533
- }
41534
- function normalizeDocPartMetadata(attrs) {
41535
- return {
41536
- type: "docPartObject",
41537
- gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
41538
- // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
41539
- // Fall back to attrs.uniqueId for compatibility
41540
- uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
41541
- alias: toOptionalString(attrs.alias) ?? null,
41542
- instruction: toOptionalString(attrs.instruction) ?? null
41543
- };
41544
- }
41545
- function isPlainObject$2(value) {
41546
- return !!value && typeof value === "object" && !Array.isArray(value);
41547
- }
41548
- function toOptionalString(value) {
41549
- if (value == null) return void 0;
41550
- if (typeof value === "string") {
41551
- const trimmed = value.trim();
41552
- return trimmed.length ? trimmed : void 0;
41553
- }
41554
- return String(value);
41555
- }
41556
- function toNullableString(value) {
41557
- const str = toOptionalString(value);
41558
- return str ?? null;
41559
- }
41560
- function toBoolean$2(value, fallback) {
41561
- if (typeof value === "boolean") return value;
41562
- if (typeof value === "string") {
41563
- const lower = value.toLowerCase();
41564
- if (lower === "true") return true;
41565
- if (lower === "false") return false;
41566
- }
41567
- if (value == null) return fallback;
41568
- return Boolean(value);
41569
- }
41570
- function normalizeVisibility(value) {
41571
- if (typeof value !== "string") return void 0;
41572
- const normalized = value.toLowerCase();
41573
- if (normalized === "visible" || normalized === "hidden") {
41574
- return normalized;
41575
- }
41576
- return void 0;
41577
- }
41578
- function normalizeColorValue(value) {
41579
- if (typeof value !== "string") return void 0;
41580
- const trimmed = value.trim();
41581
- if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
41582
- return trimmed;
41583
- }
41584
- function normalizeFontSize(value) {
41585
- if (value == null) return null;
41586
- if (typeof value === "number") {
41587
- return Number.isFinite(value) ? value : null;
41588
- }
41589
- if (typeof value === "string") {
41590
- const trimmed = value.trim();
41591
- return trimmed.length ? trimmed : null;
41592
- }
41593
- return null;
41594
- }
41595
- function toNumber(value) {
41596
- if (typeof value === "number") {
41597
- return Number.isFinite(value) ? value : null;
41598
- }
41599
- if (typeof value === "string") {
41600
- const parsed = parseFloat(value);
41601
- return Number.isFinite(parsed) ? parsed : null;
41602
- }
41603
- return null;
41604
- }
41605
- function normalizeSize(value) {
41606
- if (!isPlainObject$2(value)) return null;
41607
- const obj = value;
41608
- const width = toNumber(obj.width);
41609
- const height = toNumber(obj.height);
41610
- if (width == null && height == null) return null;
41611
- const result = {};
41612
- if (width != null) result.width = width;
41613
- if (height != null) result.height = height;
41614
- return result;
41615
- }
41616
- function normalizeFieldAnnotationVariant(value) {
41617
- if (typeof value !== "string") return void 0;
41618
- const normalized = value.toLowerCase();
41619
- if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
41620
- return normalized;
41621
- }
41622
- return void 0;
41623
- }
41624
- function extractFormatting(attrs) {
41625
- const bold = toBoolean$2(attrs.bold, false);
41626
- const italic = toBoolean$2(attrs.italic, false);
41627
- const underline = toBoolean$2(attrs.underline, false);
41628
- const formatting = {};
41629
- if (bold) formatting.bold = true;
41630
- if (italic) formatting.italic = true;
41631
- if (underline) formatting.underline = true;
41632
- return Object.keys(formatting).length ? formatting : void 0;
41633
- }
41634
- function buildSdtCacheKey(nodeType, attrs, explicitKey) {
41635
- const provided = toOptionalString(explicitKey);
41636
- if (provided) {
41637
- return `${nodeType}:${provided}`;
41638
- }
41639
- const hash2 = toOptionalString(attrs.hash);
41640
- if (hash2) {
41641
- return `${nodeType}:${hash2}`;
41642
- }
41643
- const id = toOptionalString(attrs.id);
41644
- if (id) {
41645
- return `${nodeType}:${id}`;
41646
- }
41647
- return void 0;
41648
- }
41649
41682
  const DEFAULT_LIST_HANGING_PX = 18;
41650
41683
  const LIST_MARKER_GAP = 8;
41651
41684
  const DEFAULT_BULLET_GLYPH = "•";
@@ -42205,6 +42238,7 @@ const EMPTY_NUMBERING_CONTEXT = {
42205
42238
  definitions: {},
42206
42239
  abstracts: {}
42207
42240
  };
42241
+ const ooxmlResolver = superEditor_converter.createOoxmlResolver({ pPr: superEditor_converter.translator, rPr: superEditor_converter.translator$1 });
42208
42242
  const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
42209
42243
  if (!hasParagraphStyleContext(context)) {
42210
42244
  return null;
@@ -42232,7 +42266,7 @@ const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
42232
42266
  // should still get docDefaults spacing from style resolution
42233
42267
  numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42234
42268
  };
42235
- const resolved = superEditor_converter.resolveParagraphProperties(resolverParams, inlineProps);
42269
+ const resolved = ooxmlResolver.resolveParagraphProperties(resolverParams, inlineProps);
42236
42270
  if (!resolved) {
42237
42271
  return null;
42238
42272
  }
@@ -42287,6 +42321,138 @@ const cloneIfObject = (value) => {
42287
42321
  }
42288
42322
  return { ...value };
42289
42323
  };
42324
+ const buildCharacterStyleHydration = (resolved, docx) => {
42325
+ const fontFamily2 = extractFontFamily(resolved.fontFamily, docx);
42326
+ const fontSize2 = typeof resolved.fontSize === "number" ? resolved.fontSize : 20;
42327
+ const color = extractColorValue(resolved.color);
42328
+ const bold = normalizeBooleanProp(resolved.bold);
42329
+ const italic = normalizeBooleanProp(resolved.italic);
42330
+ const strike = normalizeBooleanProp(resolved.strike);
42331
+ const underline = extractUnderline(resolved.underline);
42332
+ const letterSpacing = typeof resolved.letterSpacing === "number" ? resolved.letterSpacing : void 0;
42333
+ return {
42334
+ fontFamily: fontFamily2,
42335
+ fontSize: fontSize2,
42336
+ color,
42337
+ bold,
42338
+ italic,
42339
+ strike,
42340
+ underline,
42341
+ letterSpacing
42342
+ };
42343
+ };
42344
+ const hydrateCharacterStyleAttrs = (para, context, resolvedPpr) => {
42345
+ if (!hasParagraphStyleContext(context)) {
42346
+ return null;
42347
+ }
42348
+ const attrs = para.attrs ?? {};
42349
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
42350
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
42351
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
42352
+ const inlineRpr = {};
42353
+ const pprForChain = resolvedPpr ?? { styleId };
42354
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
42355
+ if (numberingProps != null) {
42356
+ pprForChain.numberingProperties = numberingProps;
42357
+ }
42358
+ const resolverParams = {
42359
+ docx: context.docx,
42360
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42361
+ };
42362
+ let resolved = null;
42363
+ try {
42364
+ resolved = ooxmlResolver.resolveRunProperties(
42365
+ resolverParams,
42366
+ inlineRpr,
42367
+ pprForChain,
42368
+ false,
42369
+ // not list number marker
42370
+ false
42371
+ // not numberingDefinedInline
42372
+ );
42373
+ if (!resolved || typeof resolved !== "object") {
42374
+ return null;
42375
+ }
42376
+ } catch {
42377
+ return null;
42378
+ }
42379
+ return buildCharacterStyleHydration(resolved, context.docx);
42380
+ };
42381
+ const hydrateMarkerStyleAttrs = (para, context, resolvedPpr) => {
42382
+ if (!hasParagraphStyleContext(context)) {
42383
+ return null;
42384
+ }
42385
+ const attrs = para.attrs ?? {};
42386
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
42387
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
42388
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
42389
+ const inlineRpr = {};
42390
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
42391
+ const numberingDefinedInline = numberingProps?.numId != null;
42392
+ const pprForChain = resolvedPpr ? { ...resolvedPpr } : { styleId };
42393
+ if (styleId && !pprForChain.styleId) {
42394
+ pprForChain.styleId = styleId;
42395
+ }
42396
+ if (numberingProps != null) {
42397
+ pprForChain.numberingProperties = numberingProps;
42398
+ }
42399
+ const resolverParams = {
42400
+ docx: context.docx,
42401
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42402
+ };
42403
+ let resolved = null;
42404
+ try {
42405
+ resolved = ooxmlResolver.resolveRunProperties(
42406
+ resolverParams,
42407
+ inlineRpr,
42408
+ pprForChain,
42409
+ true,
42410
+ numberingDefinedInline
42411
+ );
42412
+ if (!resolved || typeof resolved !== "object") {
42413
+ return null;
42414
+ }
42415
+ } catch {
42416
+ return null;
42417
+ }
42418
+ return buildCharacterStyleHydration(resolved, context.docx);
42419
+ };
42420
+ function extractFontFamily(fontFamily2, docx) {
42421
+ if (!fontFamily2 || typeof fontFamily2 !== "object") return void 0;
42422
+ const toCssFontFamily2 = superEditor_converter.SuperConverter.toCssFontFamily;
42423
+ const resolved = superEditor_converter.resolveDocxFontFamily(fontFamily2, docx ?? null, toCssFontFamily2);
42424
+ return resolved ?? void 0;
42425
+ }
42426
+ function extractColorValue(color) {
42427
+ if (!color || typeof color !== "object") return void 0;
42428
+ const c2 = color;
42429
+ const val = c2.val;
42430
+ if (typeof val !== "string") return void 0;
42431
+ if (!val || val.toLowerCase() === "auto") return void 0;
42432
+ return val;
42433
+ }
42434
+ function normalizeBooleanProp(value) {
42435
+ if (value == null) return void 0;
42436
+ if (typeof value === "boolean") return value;
42437
+ if (typeof value === "number") return value !== 0;
42438
+ if (typeof value === "string") {
42439
+ const lower = value.toLowerCase();
42440
+ if (lower === "0" || lower === "false" || lower === "off") return false;
42441
+ if (lower === "1" || lower === "true" || lower === "on" || lower === "") return true;
42442
+ }
42443
+ return Boolean(value);
42444
+ }
42445
+ function extractUnderline(underline) {
42446
+ if (!underline || typeof underline !== "object") return void 0;
42447
+ const u = underline;
42448
+ const type = u["w:val"] ?? u.type ?? u.val;
42449
+ if (typeof type !== "string" || type === "none") return void 0;
42450
+ const color = u["w:color"] ?? u.color;
42451
+ return {
42452
+ type,
42453
+ color: typeof color === "string" ? color : void 0
42454
+ };
42455
+ }
42290
42456
  const { resolveSpacingIndent } = Engines;
42291
42457
  const DEFAULT_DECIMAL_SEPARATOR$2 = ".";
42292
42458
  const isValidNumberingId = (numId) => {
@@ -42802,7 +42968,7 @@ const extractDropCapRunFromParagraph = (para) => {
42802
42968
  }
42803
42969
  return dropCapRun;
42804
42970
  };
42805
- const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, _paragraphNode) => {
42971
+ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, paragraphNode, converterContext, resolvedPpr) => {
42806
42972
  if (numberingProps === null) {
42807
42973
  return null;
42808
42974
  }
@@ -42840,7 +43006,23 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
42840
43006
  spacing: {}
42841
43007
  }
42842
43008
  };
42843
- let markerRun = numberingProps?.resolvedMarkerRpr;
43009
+ let markerRun;
43010
+ const markerHydration = paragraphNode && converterContext ? hydrateMarkerStyleAttrs(paragraphNode, converterContext, resolvedPpr) : null;
43011
+ if (markerHydration) {
43012
+ const resolvedColor = markerHydration.color ? `#${markerHydration.color.replace("#", "")}` : void 0;
43013
+ markerRun = {
43014
+ fontFamily: markerHydration.fontFamily ?? "Times New Roman",
43015
+ fontSize: markerHydration.fontSize / 2,
43016
+ // half-points to points
43017
+ bold: markerHydration.bold,
43018
+ italic: markerHydration.italic,
43019
+ color: resolvedColor,
43020
+ letterSpacing: markerHydration.letterSpacing != null ? twipsToPx$1(markerHydration.letterSpacing) : void 0
43021
+ };
43022
+ }
43023
+ if (!markerRun) {
43024
+ markerRun = numberingProps?.resolvedMarkerRpr;
43025
+ }
42844
43026
  if (!markerRun) {
42845
43027
  const { character: characterStyle } = resolveStyle({ styleId: paragraphAttrs.styleId }, styleContext);
42846
43028
  if (characterStyle) {
@@ -43161,7 +43343,12 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
43161
43343
  const numId = numberingProps.numId;
43162
43344
  const ilvl = Number.isFinite(numberingProps.ilvl) ? Math.max(0, Math.floor(Number(numberingProps.ilvl))) : 0;
43163
43345
  const numericNumId = typeof numId === "number" ? numId : void 0;
43164
- const resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
43346
+ let resolvedLevel;
43347
+ try {
43348
+ resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
43349
+ } catch (error) {
43350
+ resolvedLevel = void 0;
43351
+ }
43165
43352
  if (resolvedLevel) {
43166
43353
  if (resolvedLevel.format && numberingProps.format == null) {
43167
43354
  numberingProps.format = resolvedLevel.format;
@@ -43222,7 +43409,19 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
43222
43409
  }
43223
43410
  }
43224
43411
  }
43225
- let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
43412
+ let wordLayout = null;
43413
+ try {
43414
+ wordLayout = computeWordLayoutForParagraph(
43415
+ paragraphAttrs,
43416
+ enrichedNumberingProps,
43417
+ styleContext,
43418
+ para,
43419
+ converterContext,
43420
+ hydrated?.resolved
43421
+ );
43422
+ } catch (error) {
43423
+ wordLayout = null;
43424
+ }
43226
43425
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
43227
43426
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
43228
43427
  const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
@@ -43767,7 +43966,7 @@ const V_RELATIVE_VALUES$1 = /* @__PURE__ */ new Set(["paragraph", "page", "margi
43767
43966
  const H_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["left", "center", "right"]);
43768
43967
  const V_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["top", "center", "bottom"]);
43769
43968
  const getAttrs$1 = (node) => {
43770
- return isPlainObject$3(node.attrs) ? node.attrs : {};
43969
+ return isPlainObject$2(node.attrs) ? node.attrs : {};
43771
43970
  };
43772
43971
  const normalizeWrapType$1 = (value) => {
43773
43972
  if (typeof value !== "string") return void 0;
@@ -43790,7 +43989,7 @@ const normalizePolygon$1 = (value) => {
43790
43989
  return polygon.length > 0 ? polygon : void 0;
43791
43990
  };
43792
43991
  const normalizeWrap$2 = (value) => {
43793
- if (!isPlainObject$3(value)) {
43992
+ if (!isPlainObject$2(value)) {
43794
43993
  return void 0;
43795
43994
  }
43796
43995
  const type = normalizeWrapType$1(value.type);
@@ -43798,7 +43997,7 @@ const normalizeWrap$2 = (value) => {
43798
43997
  return void 0;
43799
43998
  }
43800
43999
  const wrap = { type };
43801
- const attrs = isPlainObject$3(value.attrs) ? value.attrs : {};
44000
+ const attrs = isPlainObject$2(value.attrs) ? value.attrs : {};
43802
44001
  const wrapText = normalizeWrapText$1(attrs.wrapText);
43803
44002
  if (wrapText) {
43804
44003
  wrap.wrapText = wrapText;
@@ -43815,7 +44014,7 @@ const normalizeWrap$2 = (value) => {
43815
44014
  if (polygon) {
43816
44015
  wrap.polygon = polygon;
43817
44016
  }
43818
- const behindDoc = toBoolean$3(attrs.behindDoc);
44017
+ const behindDoc = toBoolean$2(attrs.behindDoc);
43819
44018
  if (behindDoc != null) {
43820
44019
  wrap.behindDoc = behindDoc;
43821
44020
  }
@@ -43830,10 +44029,10 @@ const normalizeAnchorAlign$1 = (value, allowed) => {
43830
44029
  return allowed.has(value) ? value : void 0;
43831
44030
  };
43832
44031
  const normalizeAnchorData$1 = (value, attrs, wrapBehindDoc) => {
43833
- const raw = isPlainObject$3(value) ? value : void 0;
43834
- const marginOffset = isPlainObject$3(attrs.marginOffset) ? attrs.marginOffset : void 0;
43835
- const simplePos = isPlainObject$3(attrs.simplePos) ? attrs.simplePos : void 0;
43836
- const originalAttrs = isPlainObject$3(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
44032
+ const raw = isPlainObject$2(value) ? value : void 0;
44033
+ const marginOffset = isPlainObject$2(attrs.marginOffset) ? attrs.marginOffset : void 0;
44034
+ const simplePos = isPlainObject$2(attrs.simplePos) ? attrs.simplePos : void 0;
44035
+ const originalAttrs = isPlainObject$2(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
43837
44036
  const isAnchored = attrs.isAnchor === true || Boolean(raw);
43838
44037
  const anchor = {};
43839
44038
  if (isAnchored) {
@@ -43851,7 +44050,7 @@ const normalizeAnchorData$1 = (value, attrs, wrapBehindDoc) => {
43851
44050
  if (offsetH != null) anchor.offsetH = offsetH;
43852
44051
  const offsetV = pickNumber(marginOffset?.top ?? marginOffset?.vertical ?? raw?.offsetV ?? simplePos?.y);
43853
44052
  if (offsetV != null) anchor.offsetV = offsetV;
43854
- const behindDoc = toBoolean$3(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
44053
+ const behindDoc = toBoolean$2(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
43855
44054
  if (behindDoc != null) anchor.behindDoc = behindDoc;
43856
44055
  const hasData = anchor.isAnchored || anchor.hRelativeFrom != null || anchor.vRelativeFrom != null || anchor.alignH != null || anchor.alignV != null || anchor.offsetH != null || anchor.offsetV != null || anchor.behindDoc != null;
43857
44056
  return hasData ? anchor : void 0;
@@ -43976,7 +44175,7 @@ function handleShapeTextboxNode(node, context) {
43976
44175
  }
43977
44176
  }
43978
44177
  const getAttrs = (node) => {
43979
- return isPlainObject$3(node.attrs) ? { ...node.attrs } : {};
44178
+ return isPlainObject$2(node.attrs) ? { ...node.attrs } : {};
43980
44179
  };
43981
44180
  const parseFullWidth = (value) => {
43982
44181
  if (typeof value === "string") {
@@ -43995,7 +44194,7 @@ function contentBlockNodeToDrawingBlock(node, nextBlockId, positions) {
43995
44194
  if (rawAttrs.horizontalRule !== true) {
43996
44195
  return null;
43997
44196
  }
43998
- const size2 = isPlainObject$3(rawAttrs.size) ? rawAttrs.size : void 0;
44197
+ const size2 = isPlainObject$2(rawAttrs.size) ? rawAttrs.size : void 0;
43999
44198
  const { width, isFullWidth } = parseFullWidth(size2?.width);
44000
44199
  const height = pickNumber(size2?.height);
44001
44200
  if (!height || height <= 0) {
@@ -44197,6 +44396,9 @@ const extractRunStyleId = (runProperties) => {
44197
44396
  return null;
44198
44397
  };
44199
44398
  const DEFAULT_IMAGE_DIMENSION_PX = 100;
44399
+ const HALF_POINTS_PER_POINT = 2;
44400
+ const SCREEN_DPI = 96;
44401
+ const POINT_DPI = 72;
44200
44402
  function isInlineImage(node) {
44201
44403
  const attrs = node.attrs ?? {};
44202
44404
  const wrap = attrs.wrap;
@@ -44224,8 +44426,8 @@ function imageNodeToRun(node, positions, activeSdt) {
44224
44426
  const size2 = attrs.size ?? {};
44225
44427
  const width = typeof size2.width === "number" && Number.isFinite(size2.width) && size2.width > 0 ? size2.width : DEFAULT_IMAGE_DIMENSION_PX;
44226
44428
  const height = typeof size2.height === "number" && Number.isFinite(size2.height) && size2.height > 0 ? size2.height : DEFAULT_IMAGE_DIMENSION_PX;
44227
- const wrap = isPlainObject$3(attrs.wrap) ? attrs.wrap : {};
44228
- const wrapAttrs = isPlainObject$3(wrap.attrs) ? wrap.attrs : {};
44429
+ const wrap = isPlainObject$2(attrs.wrap) ? attrs.wrap : {};
44430
+ const wrapAttrs = isPlainObject$2(wrap.attrs) ? wrap.attrs : {};
44229
44431
  const run = {
44230
44432
  kind: "image",
44231
44433
  src,
@@ -44435,15 +44637,6 @@ const applyBaseRunDefaults = (run, defaults, uiDisplayFallbackFont, fallbackSize
44435
44637
  if (defaults.letterSpacing != null && run.letterSpacing == null) {
44436
44638
  run.letterSpacing = defaults.letterSpacing;
44437
44639
  }
44438
- if (defaults.bold && run.bold === void 0) {
44439
- run.bold = true;
44440
- }
44441
- if (defaults.italic && run.italic === void 0) {
44442
- run.italic = true;
44443
- }
44444
- if (defaults.underline && !run.underline) {
44445
- run.underline = defaults.underline;
44446
- }
44447
44640
  };
44448
44641
  function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defaultSize, styleContext, listCounterContext, trackedChanges, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG$1, themeColors, converters, converterContext) {
44449
44642
  const baseBlockId = nextBlockId("paragraph");
@@ -44452,28 +44645,45 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
44452
44645
  const paragraphHydration = converterContext ? hydrateParagraphStyleAttrs(para, converterContext) : null;
44453
44646
  let baseRunDefaults = {};
44454
44647
  try {
44455
- const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
44456
- const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
44457
- const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
44458
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
44459
- const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
44460
- const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
44461
- if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
44462
- styleNode.styleId = paragraphProps.styleId;
44463
- }
44464
- const resolved = resolveStyle(styleNode, styleContext);
44465
- baseRunDefaults = {
44466
- fontFamily: resolved.character.font?.family,
44467
- fontSizePx: ptToPx(resolved.character.font?.size),
44468
- color: resolved.character.color,
44469
- bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
44470
- italic: resolved.character.font?.italic,
44471
- underline: resolved.character.underline ? {
44472
- style: resolved.character.underline.style,
44473
- color: resolved.character.underline.color
44474
- } : void 0,
44475
- letterSpacing: ptToPx(resolved.character.letterSpacing)
44476
- };
44648
+ const charHydration = converterContext ? hydrateCharacterStyleAttrs(para, converterContext, paragraphHydration?.resolved) : null;
44649
+ if (charHydration) {
44650
+ const fontSizePx = charHydration.fontSize / HALF_POINTS_PER_POINT * (SCREEN_DPI / POINT_DPI);
44651
+ baseRunDefaults = {
44652
+ fontFamily: charHydration.fontFamily,
44653
+ fontSizePx,
44654
+ color: charHydration.color ? `#${charHydration.color.replace("#", "")}` : void 0,
44655
+ bold: charHydration.bold,
44656
+ italic: charHydration.italic,
44657
+ underline: charHydration.underline ? {
44658
+ style: charHydration.underline.type,
44659
+ color: charHydration.underline.color
44660
+ } : void 0,
44661
+ letterSpacing: charHydration.letterSpacing != null ? twipsToPx$1(charHydration.letterSpacing) : void 0
44662
+ };
44663
+ } else {
44664
+ const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
44665
+ const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
44666
+ const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
44667
+ const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
44668
+ const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
44669
+ const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
44670
+ if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
44671
+ styleNode.styleId = paragraphProps.styleId;
44672
+ }
44673
+ const resolved = resolveStyle(styleNode, styleContext);
44674
+ baseRunDefaults = {
44675
+ fontFamily: resolved.character.font?.family,
44676
+ fontSizePx: ptToPx(resolved.character.font?.size),
44677
+ color: resolved.character.color,
44678
+ bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
44679
+ italic: resolved.character.font?.italic,
44680
+ underline: resolved.character.underline ? {
44681
+ style: resolved.character.underline.style,
44682
+ color: resolved.character.underline.color
44683
+ } : void 0,
44684
+ letterSpacing: ptToPx(resolved.character.letterSpacing)
44685
+ };
44686
+ }
44477
44687
  } catch {
44478
44688
  baseRunDefaults = {};
44479
44689
  }
@@ -48024,7 +48234,8 @@ async function measureParagraphBlock(block, maxWidth) {
48024
48234
  const originX = currentLine.width;
48025
48235
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
48026
48236
  tabStopCursor = nextIndex;
48027
- const tabAdvance = Math.max(0, target - currentLine.width);
48237
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
48238
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
48028
48239
  currentLine.width = roundValue(currentLine.width + tabAdvance);
48029
48240
  run.width = tabAdvance;
48030
48241
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, 12);
@@ -48032,14 +48243,14 @@ async function measureParagraphBlock(block, maxWidth) {
48032
48243
  currentLine.toChar = 1;
48033
48244
  if (stop) {
48034
48245
  validateTabStopVal(stop);
48035
- pendingTabAlignment = { target, val: stop.val };
48246
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
48036
48247
  } else {
48037
48248
  pendingTabAlignment = null;
48038
48249
  }
48039
48250
  if (stop && stop.leader && stop.leader !== "none") {
48040
48251
  const leaderStyle = stop.leader;
48041
- const from3 = Math.min(originX, target);
48042
- const to = Math.max(originX, target);
48252
+ const from3 = Math.min(originX, clampedTarget);
48253
+ const to = Math.max(originX, clampedTarget);
48043
48254
  if (!currentLine.leaders) currentLine.leaders = [];
48044
48255
  currentLine.leaders.push({ from: from3, to, style: leaderStyle });
48045
48256
  }
@@ -48634,7 +48845,8 @@ async function measureParagraphBlock(block, maxWidth) {
48634
48845
  const originX = currentLine.width;
48635
48846
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
48636
48847
  tabStopCursor = nextIndex;
48637
- const tabAdvance = Math.max(0, target - currentLine.width);
48848
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
48849
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
48638
48850
  currentLine.width = roundValue(currentLine.width + tabAdvance);
48639
48851
  currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run);
48640
48852
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run.fontSize);
@@ -48643,14 +48855,14 @@ async function measureParagraphBlock(block, maxWidth) {
48643
48855
  charPosInRun += 1;
48644
48856
  if (stop) {
48645
48857
  validateTabStopVal(stop);
48646
- pendingTabAlignment = { target, val: stop.val };
48858
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
48647
48859
  } else {
48648
48860
  pendingTabAlignment = null;
48649
48861
  }
48650
48862
  if (stop && stop.leader && stop.leader !== "none" && stop.leader !== "middleDot") {
48651
48863
  const leaderStyle = stop.leader;
48652
- const from3 = Math.min(originX, target);
48653
- const to = Math.max(originX, target);
48864
+ const from3 = Math.min(originX, clampedTarget);
48865
+ const to = Math.max(originX, clampedTarget);
48654
48866
  if (!currentLine.leaders) currentLine.leaders = [];
48655
48867
  currentLine.leaders.push({ from: from3, to, style: leaderStyle });
48656
48868
  }
@@ -57206,16 +57418,112 @@ const mapRangesThroughTransactions = (ranges, transactions, docSize) => {
57206
57418
  });
57207
57419
  return mergeRanges$2(mapped, docSize);
57208
57420
  };
57209
- const buildWrapTransaction = (state, ranges, runType) => {
57421
+ const getParagraphAtPos = (doc2, pos) => {
57422
+ try {
57423
+ const $pos = doc2.resolve(pos);
57424
+ for (let depth = $pos.depth; depth >= 0; depth--) {
57425
+ const node = $pos.node(depth);
57426
+ if (node.type.name === "paragraph") {
57427
+ return node;
57428
+ }
57429
+ }
57430
+ } catch (_e) {
57431
+ }
57432
+ return null;
57433
+ };
57434
+ const resolveRunPropertiesFromParagraphStyle = (paragraphNode, editor) => {
57435
+ if (!paragraphNode || !editor?.converter) return {};
57436
+ const styleId = paragraphNode.attrs?.paragraphProperties?.styleId;
57437
+ if (!styleId) return {};
57438
+ try {
57439
+ const params2 = { docx: editor.converter.convertedXml, numbering: editor.converter.numbering };
57440
+ const resolvedPpr = { styleId };
57441
+ const runProps = superEditor_converter.resolveRunProperties(params2, {}, resolvedPpr, false, false);
57442
+ const runProperties = {};
57443
+ if (runProps.fontFamily) {
57444
+ const fontValue = runProps.fontFamily.ascii || runProps.fontFamily;
57445
+ if (fontValue) {
57446
+ runProperties.fontFamily = typeof fontValue === "string" ? fontValue : fontValue.ascii;
57447
+ }
57448
+ }
57449
+ if (runProps.fontSize) {
57450
+ runProperties.fontSize = `${runProps.fontSize / 2}pt`;
57451
+ }
57452
+ if (runProps.bold) runProperties.bold = true;
57453
+ if (runProps.italic) runProperties.italic = true;
57454
+ if (runProps.underline) runProperties.underline = runProps.underline;
57455
+ if (runProps.strike) runProperties.strike = true;
57456
+ return runProperties;
57457
+ } catch (_e) {
57458
+ return {};
57459
+ }
57460
+ };
57461
+ const createMarksFromDefs = (schema, markDefs = []) => markDefs.map((def) => {
57462
+ const markType = schema.marks[def.type];
57463
+ return markType ? markType.create(def.attrs) : null;
57464
+ }).filter(Boolean);
57465
+ const createMarkDefsFromStyleRunProps = (styleRunProps) => {
57466
+ const markDefs = [];
57467
+ const textStyleAttrs = {};
57468
+ if (styleRunProps.fontSize) {
57469
+ textStyleAttrs.fontSize = styleRunProps.fontSize;
57470
+ }
57471
+ if (styleRunProps.fontFamily) {
57472
+ textStyleAttrs.fontFamily = styleRunProps.fontFamily;
57473
+ }
57474
+ if (Object.keys(textStyleAttrs).length > 0) {
57475
+ markDefs.push({ type: "textStyle", attrs: textStyleAttrs });
57476
+ }
57477
+ if (styleRunProps.bold) {
57478
+ markDefs.push({ type: "bold", attrs: { value: true } });
57479
+ }
57480
+ if (styleRunProps.italic) {
57481
+ markDefs.push({ type: "italic", attrs: { value: true } });
57482
+ }
57483
+ if (styleRunProps.strike) {
57484
+ markDefs.push({ type: "strike", attrs: { value: true } });
57485
+ }
57486
+ if (styleRunProps.underline) {
57487
+ const underlineType = styleRunProps.underline["w:val"];
57488
+ if (underlineType) {
57489
+ let underlineColor = styleRunProps.underline["w:color"];
57490
+ if (underlineColor && underlineColor.toLowerCase() !== "auto" && !underlineColor.startsWith("#")) {
57491
+ underlineColor = `#${underlineColor}`;
57492
+ }
57493
+ markDefs.push({
57494
+ type: "underline",
57495
+ attrs: { underlineType, underlineColor }
57496
+ });
57497
+ }
57498
+ }
57499
+ return markDefs;
57500
+ };
57501
+ const buildWrapTransaction = (state, ranges, runType, editor, markDefsFromMeta = []) => {
57210
57502
  if (!ranges.length) return null;
57211
57503
  const replacements = [];
57504
+ const metaStyleMarks = createMarksFromDefs(state.schema, markDefsFromMeta);
57212
57505
  ranges.forEach(({ from: from3, to }) => {
57213
57506
  state.doc.nodesBetween(from3, to, (node, pos, parent, index2) => {
57214
57507
  if (!node.isText || !parent || parent.type === runType) return;
57215
57508
  const match = parent.contentMatchAt ? parent.contentMatchAt(index2) : null;
57216
57509
  if (match && !match.matchType(runType)) return;
57217
57510
  if (!match && !parent.type.contentMatch.matchType(runType)) return;
57218
- const runProperties = superEditor_converter.decodeRPrFromMarks(node.marks);
57511
+ let runProperties = superEditor_converter.decodeRPrFromMarks(node.marks);
57512
+ if ((!node.marks || node.marks.length === 0) && editor?.converter) {
57513
+ const paragraphNode = getParagraphAtPos(state.doc, pos);
57514
+ const styleRunProps = resolveRunPropertiesFromParagraphStyle(paragraphNode, editor);
57515
+ if (Object.keys(styleRunProps).length > 0) {
57516
+ runProperties = styleRunProps;
57517
+ const markDefs = metaStyleMarks.length ? markDefsFromMeta : createMarkDefsFromStyleRunProps(styleRunProps);
57518
+ const styleMarks = metaStyleMarks.length ? metaStyleMarks : createMarksFromDefs(state.schema, markDefs);
57519
+ if (styleMarks.length && typeof state.schema.text === "function") {
57520
+ const textNode = state.schema.text(node.text || "", styleMarks);
57521
+ if (textNode) {
57522
+ node = textNode;
57523
+ }
57524
+ }
57525
+ }
57526
+ }
57219
57527
  const runNode = runType.create({ runProperties }, node);
57220
57528
  replacements.push({ from: pos, to: pos + node.nodeSize, runNode });
57221
57529
  });
@@ -57225,9 +57533,10 @@ const buildWrapTransaction = (state, ranges, runType) => {
57225
57533
  replacements.sort((a, b) => b.from - a.from).forEach(({ from: from3, to, runNode }) => tr.replaceWith(from3, to, runNode));
57226
57534
  return tr.docChanged ? tr : null;
57227
57535
  };
57228
- const wrapTextInRunsPlugin = () => {
57536
+ const wrapTextInRunsPlugin = (editor) => {
57229
57537
  let view = null;
57230
57538
  let pendingRanges = [];
57539
+ let lastStyleMarksMeta = [];
57231
57540
  const flush = () => {
57232
57541
  if (!view) return;
57233
57542
  const runType = view.state.schema.nodes.run;
@@ -57235,7 +57544,7 @@ const wrapTextInRunsPlugin = () => {
57235
57544
  pendingRanges = [];
57236
57545
  return;
57237
57546
  }
57238
- const tr = buildWrapTransaction(view.state, pendingRanges, runType);
57547
+ const tr = buildWrapTransaction(view.state, pendingRanges, runType, editor, lastStyleMarksMeta);
57239
57548
  pendingRanges = [];
57240
57549
  if (tr) {
57241
57550
  view.dispatch(tr);
@@ -57254,6 +57563,7 @@ const wrapTextInRunsPlugin = () => {
57254
57563
  editorView.dom.removeEventListener("compositionend", onCompositionEnd);
57255
57564
  view = null;
57256
57565
  pendingRanges = [];
57566
+ lastStyleMarksMeta = [];
57257
57567
  }
57258
57568
  };
57259
57569
  },
@@ -57267,7 +57577,11 @@ const wrapTextInRunsPlugin = () => {
57267
57577
  if (view?.composing) {
57268
57578
  return null;
57269
57579
  }
57270
- const tr = buildWrapTransaction(newState, pendingRanges, runType);
57580
+ const latestStyleMarksMeta = [...transactions].reverse().find((tr2) => tr2.getMeta && tr2.getMeta("sdStyleMarks"))?.getMeta("sdStyleMarks") || lastStyleMarksMeta;
57581
+ if (latestStyleMarksMeta && latestStyleMarksMeta.length) {
57582
+ lastStyleMarksMeta = latestStyleMarksMeta;
57583
+ }
57584
+ const tr = buildWrapTransaction(newState, pendingRanges, runType, editor, latestStyleMarksMeta);
57271
57585
  pendingRanges = [];
57272
57586
  return tr;
57273
57587
  }
@@ -57530,7 +57844,7 @@ const Run = OxmlNode.create({
57530
57844
  },
57531
57845
  addPmPlugins() {
57532
57846
  return [
57533
- wrapTextInRunsPlugin(),
57847
+ wrapTextInRunsPlugin(this.editor),
57534
57848
  splitRunsAfterMarkPlugin,
57535
57849
  calculateInlineRunPropertiesPlugin(this.editor),
57536
57850
  cleanupEmptyRunsPlugin