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

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,6 +1,6 @@
1
1
  import { B as Buffer$2 } from "./jszip-B1fkPkPJ.es.js";
2
2
  import { t as twipsToInches, i as inchesToTwips, p as ptToTwips, l as linesToTwips, a as twipsToLines, b as pixelsToTwips, h as halfPointToPoints, c as twipsToPixels$2, d as convertSizeToCSS, e as inchesToPixels } from "./helpers-C8e9wR5l.es.js";
3
- import { g as generateDocxRandomId, T as TextSelection$1, o as objectIncludes, w as wrapTextsInRuns, D as DOMParser$1, c as createDocFromMarkdown, a as createDocFromHTML, b as chainableEditorState, d as convertMarkdownToHTML, f as findParentNode, e as findParentNodeClosestToPos, h as generateRandom32BitHex, i as generateRandomSigned32BitIntStrId, P as PluginKey, j as Plugin, M as Mapping, N as NodeSelection, k as Selection, l as Slice, m as DOMSerializer, F as Fragment, n as Mark$1, p as dropPoint, A as AllSelection, q as Schema$1, s as canSplit, t as liftTarget, u as canJoin, v as joinPoint, x as replaceStep$1, R as ReplaceAroundStep$1, y as htmlHandler, z as ReplaceStep, B as getResolvedParagraphProperties, C as changeListLevel, E as isList$1, G as updateNumberingProperties, L as ListHelpers, H as inputRulesPlugin, I as TrackDeleteMarkName$1, J as TrackInsertMarkName$1, K as TrackFormatMarkName$1, O as AddMarkStep, Q as RemoveMarkStep, U as CommandService, S as SuperConverter, V as EditorState, W as unflattenListsInHtml, X as SelectionRange, Y as Transform, Z as resolveParagraphProperties, _ as _getReferencedTableStyles, $ as decodeRPrFromMarks, a0 as calculateResolvedParagraphProperties, a1 as resolveRunProperties, a2 as encodeCSSFromPPr, a3 as encodeCSSFromRPr, a4 as generateOrderedListIndex, a5 as docxNumberingHelpers, a6 as InputRule, a7 as insertNewRelationship, a8 as kebabCase$1, a9 as getUnderlineCssString } from "./SuperConverter-ClzyObj7.es.js";
3
+ import { g as generateDocxRandomId, T as TextSelection$1, o as objectIncludes, w as wrapTextsInRuns, D as DOMParser$1, c as createDocFromMarkdown, a as createDocFromHTML, b as chainableEditorState, d as convertMarkdownToHTML, f as findParentNode, e as findParentNodeClosestToPos, h as generateRandom32BitHex, i as generateRandomSigned32BitIntStrId, P as PluginKey, j as Plugin, M as Mapping, N as NodeSelection, k as Selection, l as Slice, m as DOMSerializer, F as Fragment, n as Mark$1, p as dropPoint, A as AllSelection, q as Schema$1, s as canSplit, t as resolveRunProperties, u as encodeMarksFromRPr, v as liftTarget, x as canJoin, y as joinPoint, z as replaceStep$1, R as ReplaceAroundStep$1, B as htmlHandler, C as ReplaceStep, E as getResolvedParagraphProperties, G as changeListLevel, H as isList$1, I as updateNumberingProperties, L as ListHelpers, J as inputRulesPlugin, K as TrackDeleteMarkName$1, O as TrackInsertMarkName$1, Q as TrackFormatMarkName$1, U as AddMarkStep, V as RemoveMarkStep, W as CommandService, S as SuperConverter, X as EditorState, Y as unflattenListsInHtml, Z as SelectionRange, _ as Transform, $ as createOoxmlResolver, a0 as translator, a1 as translator$1, a2 as resolveDocxFontFamily, a3 as _getReferencedTableStyles, a4 as decodeRPrFromMarks, a5 as calculateResolvedParagraphProperties, a6 as encodeCSSFromPPr, a7 as encodeCSSFromRPr, a8 as generateOrderedListIndex, a9 as docxNumberingHelpers, aa as InputRule, ab as insertNewRelationship, ac as kebabCase$1, ad as getUnderlineCssString } from "./SuperConverter-D62X6P1R.es.js";
4
4
  import { p as process$1, r as ref, C as global$1, c as computed, E as createElementBlock, F as Fragment$1, S as renderList, O as withModifiers, G as openBlock, P as normalizeClass, M as createCommentVNode, H as toDisplayString, K as createBaseVNode, U as createApp, f as onMounted, X as onUnmounted, R as withDirectives, v as unref, Y as vModelText, y as nextTick, L as normalizeStyle, u as watch, Z as withKeys, _ as createTextVNode, I as createVNode, h, $ as readonly, s as getCurrentInstance, o as onBeforeUnmount, j as reactive, b as onBeforeMount, i as inject, a0 as onActivated, a1 as onDeactivated, a2 as Comment, d as defineComponent, a as provide, g as Teleport, t as toRef, a3 as renderSlot, a4 as isVNode, D as shallowRef, w as watchEffect, T as Transition, a5 as mergeProps, a6 as vShow, a7 as cloneVNode, a8 as Text$2, m as markRaw, N as createBlock, J as withCtx, a9 as useCssVars, V as resolveDynamicComponent, aa as normalizeProps, ab as guardReactiveProps } from "./vue-BnBKJwCW.es.js";
5
5
  import "./jszip.min-DCl8qkFO.es.js";
6
6
  import { E as EventEmitter$1 } from "./eventemitter3-CwrdEv8r.es.js";
@@ -158,6 +158,354 @@ function parseSizeUnit(val = "0") {
158
158
  function minMax(value = 0, min2 = 0, max2 = 0) {
159
159
  return Math.min(Math.max(value, min2), max2);
160
160
  }
161
+ const FONT_FAMILY_FALLBACKS = Object.freeze({
162
+ swiss: "Arial, sans-serif",
163
+ roman: "Times New Roman, serif",
164
+ modern: "Courier New, monospace",
165
+ script: "cursive",
166
+ decorative: "fantasy",
167
+ system: "system-ui",
168
+ auto: "sans-serif"
169
+ });
170
+ const DEFAULT_GENERIC_FALLBACK = "sans-serif";
171
+ const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
172
+ function mapWordFamilyFallback(wordFamily) {
173
+ if (!wordFamily) return DEFAULT_GENERIC_FALLBACK;
174
+ const mapped = FONT_FAMILY_FALLBACKS[wordFamily.toLowerCase()];
175
+ return mapped || DEFAULT_GENERIC_FALLBACK;
176
+ }
177
+ function toCssFontFamily(fontName, options = {}) {
178
+ if (!fontName || typeof fontName !== "string") return fontName;
179
+ const trimmed = fontName.trim();
180
+ if (!trimmed || trimmed.includes(",")) return trimmed;
181
+ const { fallback, wordFamily } = options;
182
+ const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK;
183
+ const fallbackParts = normalizeParts(fallbackValue);
184
+ if (fallbackParts.length === 0) {
185
+ return trimmed;
186
+ }
187
+ const normalizedName = trimmed.toLowerCase();
188
+ const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
189
+ if (includesName) {
190
+ return fallbackParts.join(", ");
191
+ }
192
+ return [trimmed, ...fallbackParts].join(", ");
193
+ }
194
+ const sdtMetadataCache = /* @__PURE__ */ new Map();
195
+ function resolveStyle(node, context, options = {}) {
196
+ let paragraph = createDefaultParagraph();
197
+ let character = createDefaultCharacter(context);
198
+ let numbering;
199
+ const chain = resolveStyleChain(node.styleId, context.styles);
200
+ for (const style2 of chain) {
201
+ paragraph = mergeParagraph(paragraph, style2.paragraph);
202
+ character = mergeCharacter(character, style2.character);
203
+ if (!numbering && style2.numbering) {
204
+ numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
205
+ }
206
+ }
207
+ paragraph = mergeParagraph(paragraph, node.paragraphProps);
208
+ character = mergeCharacter(character, node.characterProps);
209
+ if (node.numbering) {
210
+ numbering = resolveNumbering(node.numbering.numId, node.numbering.level, context);
211
+ }
212
+ const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
213
+ return {
214
+ paragraph,
215
+ character,
216
+ numbering,
217
+ sdt
218
+ };
219
+ }
220
+ function resolveNumbering(numId, level, context) {
221
+ const def = context.numbering?.[numId];
222
+ if (!def) return void 0;
223
+ const levelDef = def.levels.find((entry) => entry.level === level) ?? def.levels[level];
224
+ if (!levelDef) return void 0;
225
+ return {
226
+ numId,
227
+ level,
228
+ indent: {
229
+ left: levelDef.indent?.left,
230
+ hanging: levelDef.indent?.hanging
231
+ },
232
+ format: levelDef.format ?? "decimal",
233
+ text: levelDef.text ?? "%1.",
234
+ start: levelDef.start ?? 1
235
+ };
236
+ }
237
+ function resolveSdtMetadata(input) {
238
+ if (!input) return void 0;
239
+ const { nodeType, attrs, cacheKey: explicitKey } = input;
240
+ if (!nodeType) return void 0;
241
+ const normalizedAttrs = isPlainObject$4(attrs) ? attrs : {};
242
+ const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
243
+ if (cacheKey && sdtMetadataCache.has(cacheKey)) {
244
+ return sdtMetadataCache.get(cacheKey);
245
+ }
246
+ let metadata;
247
+ switch (nodeType) {
248
+ case "fieldAnnotation":
249
+ metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
250
+ break;
251
+ case "structuredContent":
252
+ case "structuredContentBlock":
253
+ metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
254
+ break;
255
+ case "documentSection":
256
+ metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
257
+ break;
258
+ case "docPartObject":
259
+ metadata = normalizeDocPartMetadata(normalizedAttrs);
260
+ break;
261
+ }
262
+ if (metadata && cacheKey) {
263
+ sdtMetadataCache.set(cacheKey, metadata);
264
+ }
265
+ return metadata;
266
+ }
267
+ function createDefaultParagraph(_context) {
268
+ return {
269
+ alignment: "left",
270
+ spacing: {
271
+ before: 0,
272
+ after: 0,
273
+ line: 12,
274
+ lineRule: "auto"
275
+ },
276
+ indent: {
277
+ left: 0,
278
+ right: 0,
279
+ firstLine: 0,
280
+ hanging: 0
281
+ },
282
+ tabs: []
283
+ };
284
+ }
285
+ function createDefaultCharacter(context) {
286
+ const baseFont = context.defaults?.paragraphFont ?? "Calibri";
287
+ const fallback = context.defaults?.paragraphFontFallback;
288
+ const wordFamily = context.defaults?.paragraphFontFamily;
289
+ const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
290
+ return {
291
+ font: {
292
+ family: resolvedFamily,
293
+ size: context.defaults?.fontSize ?? 11,
294
+ weight: 400,
295
+ italic: false
296
+ },
297
+ color: "#000000"
298
+ };
299
+ }
300
+ function resolveStyleChain(styleId, styles) {
301
+ if (!styleId || !styles) return [];
302
+ const result = [];
303
+ const visited = /* @__PURE__ */ new Set();
304
+ let current = styles[styleId];
305
+ while (current && !visited.has(current.id)) {
306
+ result.unshift(current);
307
+ visited.add(current.id);
308
+ current = current.basedOn ? styles[current.basedOn] : void 0;
309
+ }
310
+ return result;
311
+ }
312
+ function mergeParagraph(base2, overrides) {
313
+ if (!overrides) return base2;
314
+ return {
315
+ ...base2,
316
+ alignment: overrides.alignment ?? base2.alignment,
317
+ spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
318
+ indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
319
+ borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
320
+ shading: overrides.shading ?? base2.shading,
321
+ tabs: overrides.tabs ?? base2.tabs
322
+ };
323
+ }
324
+ function mergeCharacter(base2, overrides) {
325
+ if (!overrides) return base2;
326
+ return {
327
+ ...base2,
328
+ font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
329
+ color: overrides.color ?? base2.color,
330
+ underline: overrides.underline ?? base2.underline,
331
+ strike: overrides.strike ?? base2.strike,
332
+ highlight: overrides.highlight ?? base2.highlight,
333
+ letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
334
+ };
335
+ }
336
+ function normalizeFieldAnnotationMetadata(attrs) {
337
+ const fieldId = toOptionalString(attrs.fieldId) ?? "";
338
+ const formatting = extractFormatting(attrs);
339
+ const size2 = normalizeSize(attrs.size);
340
+ const extras = isPlainObject$4(attrs.extras) ? attrs.extras : null;
341
+ const marks = isPlainObject$4(attrs.marks) ? attrs.marks : void 0;
342
+ return {
343
+ type: "fieldAnnotation",
344
+ fieldId,
345
+ variant: normalizeFieldAnnotationVariant(attrs.type),
346
+ fieldType: toOptionalString(attrs.fieldType),
347
+ displayLabel: toOptionalString(attrs.displayLabel),
348
+ defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
349
+ alias: toOptionalString(attrs.alias),
350
+ fieldColor: normalizeColorValue(attrs.fieldColor),
351
+ borderColor: normalizeColorValue(attrs.borderColor),
352
+ highlighted: toBoolean$3(attrs.highlighted, true),
353
+ fontFamily: toNullableString(attrs.fontFamily),
354
+ fontSize: normalizeFontSize(attrs.fontSize),
355
+ textColor: normalizeColorValue(attrs.textColor) ?? null,
356
+ textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
357
+ linkUrl: toNullableString(attrs.linkUrl),
358
+ imageSrc: toNullableString(attrs.imageSrc),
359
+ rawHtml: attrs.rawHtml ?? void 0,
360
+ size: size2 ?? null,
361
+ extras,
362
+ multipleImage: toBoolean$3(attrs.multipleImage, false),
363
+ hash: toOptionalString(attrs.hash) ?? null,
364
+ generatorIndex: toNumber(attrs.generatorIndex),
365
+ sdtId: toOptionalString(attrs.sdtId) ?? null,
366
+ hidden: toBoolean$3(attrs.hidden, false),
367
+ visibility: normalizeVisibility(attrs.visibility),
368
+ isLocked: toBoolean$3(attrs.isLocked, false),
369
+ formatting,
370
+ marks
371
+ };
372
+ }
373
+ function normalizeStructuredContentMetadata(nodeType, attrs) {
374
+ return {
375
+ type: "structuredContent",
376
+ scope: nodeType === "structuredContentBlock" ? "block" : "inline",
377
+ id: toNullableString(attrs.id),
378
+ tag: toOptionalString(attrs.tag),
379
+ alias: toOptionalString(attrs.alias),
380
+ sdtPr: attrs.sdtPr
381
+ };
382
+ }
383
+ function normalizeDocumentSectionMetadata(attrs) {
384
+ return {
385
+ type: "documentSection",
386
+ id: toNullableString(attrs.id),
387
+ title: toOptionalString(attrs.title) ?? null,
388
+ description: toOptionalString(attrs.description) ?? null,
389
+ sectionType: toOptionalString(attrs.sectionType) ?? null,
390
+ isLocked: toBoolean$3(attrs.isLocked, false),
391
+ sdBlockId: toNullableString(attrs.sdBlockId)
392
+ };
393
+ }
394
+ function normalizeDocPartMetadata(attrs) {
395
+ return {
396
+ type: "docPartObject",
397
+ gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
398
+ // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
399
+ // Fall back to attrs.uniqueId for compatibility
400
+ uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
401
+ alias: toOptionalString(attrs.alias) ?? null,
402
+ instruction: toOptionalString(attrs.instruction) ?? null
403
+ };
404
+ }
405
+ function isPlainObject$4(value) {
406
+ return !!value && typeof value === "object" && !Array.isArray(value);
407
+ }
408
+ function toOptionalString(value) {
409
+ if (value == null) return void 0;
410
+ if (typeof value === "string") {
411
+ const trimmed = value.trim();
412
+ return trimmed.length ? trimmed : void 0;
413
+ }
414
+ return String(value);
415
+ }
416
+ function toNullableString(value) {
417
+ const str = toOptionalString(value);
418
+ return str ?? null;
419
+ }
420
+ function toBoolean$3(value, fallback) {
421
+ if (typeof value === "boolean") return value;
422
+ if (typeof value === "string") {
423
+ const lower = value.toLowerCase();
424
+ if (lower === "true") return true;
425
+ if (lower === "false") return false;
426
+ }
427
+ if (value == null) return fallback;
428
+ return Boolean(value);
429
+ }
430
+ function normalizeVisibility(value) {
431
+ if (typeof value !== "string") return void 0;
432
+ const normalized = value.toLowerCase();
433
+ if (normalized === "visible" || normalized === "hidden") {
434
+ return normalized;
435
+ }
436
+ return void 0;
437
+ }
438
+ function normalizeColorValue(value) {
439
+ if (typeof value !== "string") return void 0;
440
+ const trimmed = value.trim();
441
+ if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
442
+ return trimmed;
443
+ }
444
+ function normalizeFontSize(value) {
445
+ if (value == null) return null;
446
+ if (typeof value === "number") {
447
+ return Number.isFinite(value) ? value : null;
448
+ }
449
+ if (typeof value === "string") {
450
+ const trimmed = value.trim();
451
+ return trimmed.length ? trimmed : null;
452
+ }
453
+ return null;
454
+ }
455
+ function toNumber(value) {
456
+ if (typeof value === "number") {
457
+ return Number.isFinite(value) ? value : null;
458
+ }
459
+ if (typeof value === "string") {
460
+ const parsed = parseFloat(value);
461
+ return Number.isFinite(parsed) ? parsed : null;
462
+ }
463
+ return null;
464
+ }
465
+ function normalizeSize(value) {
466
+ if (!isPlainObject$4(value)) return null;
467
+ const obj = value;
468
+ const width = toNumber(obj.width);
469
+ const height = toNumber(obj.height);
470
+ if (width == null && height == null) return null;
471
+ const result = {};
472
+ if (width != null) result.width = width;
473
+ if (height != null) result.height = height;
474
+ return result;
475
+ }
476
+ function normalizeFieldAnnotationVariant(value) {
477
+ if (typeof value !== "string") return void 0;
478
+ const normalized = value.toLowerCase();
479
+ if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
480
+ return normalized;
481
+ }
482
+ return void 0;
483
+ }
484
+ function extractFormatting(attrs) {
485
+ const bold = toBoolean$3(attrs.bold, false);
486
+ const italic = toBoolean$3(attrs.italic, false);
487
+ const underline = toBoolean$3(attrs.underline, false);
488
+ const formatting = {};
489
+ if (bold) formatting.bold = true;
490
+ if (italic) formatting.italic = true;
491
+ if (underline) formatting.underline = true;
492
+ return Object.keys(formatting).length ? formatting : void 0;
493
+ }
494
+ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
495
+ const provided = toOptionalString(explicitKey);
496
+ if (provided) {
497
+ return `${nodeType}:${provided}`;
498
+ }
499
+ const hash2 = toOptionalString(attrs.hash);
500
+ if (hash2) {
501
+ return `${nodeType}:${hash2}`;
502
+ }
503
+ const id = toOptionalString(attrs.id);
504
+ if (id) {
505
+ return `${nodeType}:${id}`;
506
+ }
507
+ return void 0;
508
+ }
161
509
  function createDocument(converter, schema, editor, { check = false } = {}) {
162
510
  const documentData = converter.getSchema(editor);
163
511
  if (documentData) {
@@ -9091,15 +9439,19 @@ const splitRunToParagraph = () => (props) => {
9091
9439
  dispatchTransaction = editor.dispatch.bind(editor);
9092
9440
  }
9093
9441
  if (!dispatchTransaction) return false;
9094
- const handled = splitBlockPatch(state, (transaction) => {
9095
- dispatchTransaction(transaction);
9096
- });
9442
+ const handled = splitBlockPatch(
9443
+ state,
9444
+ (transaction) => {
9445
+ dispatchTransaction(transaction);
9446
+ },
9447
+ editor
9448
+ );
9097
9449
  if (handled) {
9098
9450
  tr.setMeta("preventDispatch", true);
9099
9451
  }
9100
9452
  return handled;
9101
9453
  };
9102
- function splitBlockPatch(state, dispatch) {
9454
+ function splitBlockPatch(state, dispatch, editor) {
9103
9455
  let { $from } = state.selection;
9104
9456
  if (state.selection instanceof NodeSelection && state.selection.node.isBlock) {
9105
9457
  if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false;
@@ -9108,14 +9460,15 @@ function splitBlockPatch(state, dispatch) {
9108
9460
  }
9109
9461
  if (!$from.depth) return false;
9110
9462
  let types = [];
9111
- let splitDepth, deflt, atEnd = false, atStart = false;
9463
+ let splitDepth, deflt, paragraphAttrs = null, atEnd = false, atStart = false;
9112
9464
  for (let d2 = $from.depth; ; d2--) {
9113
9465
  let node = $from.node(d2);
9114
9466
  if (node.isBlock) {
9115
9467
  atEnd = $from.end(d2) == $from.pos + ($from.depth - d2);
9116
9468
  atStart = $from.start(d2) == $from.pos - ($from.depth - d2);
9117
9469
  deflt = defaultBlockAt$1($from.node(d2 - 1).contentMatchAt($from.indexAfter(d2 - 1)));
9118
- types.unshift(null);
9470
+ paragraphAttrs = { ...node.attrs };
9471
+ types.unshift({ type: deflt || node.type, attrs: paragraphAttrs });
9119
9472
  splitDepth = d2;
9120
9473
  break;
9121
9474
  } else {
@@ -9128,7 +9481,7 @@ function splitBlockPatch(state, dispatch) {
9128
9481
  let splitPos = tr.mapping.map($from.pos);
9129
9482
  let can = canSplit(tr.doc, splitPos, types.length, types);
9130
9483
  if (!can) {
9131
- types[0] = deflt ? { type: deflt } : null;
9484
+ types[0] = deflt ? { type: deflt, attrs: paragraphAttrs } : null;
9132
9485
  can = canSplit(tr.doc, splitPos, types.length, types);
9133
9486
  }
9134
9487
  if (!can) return false;
@@ -9138,9 +9491,37 @@ function splitBlockPatch(state, dispatch) {
9138
9491
  if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt))
9139
9492
  tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
9140
9493
  }
9494
+ applyStyleMarks(state, tr, editor, paragraphAttrs);
9141
9495
  if (dispatch) dispatch(tr.scrollIntoView());
9142
9496
  return true;
9143
9497
  }
9498
+ function applyStyleMarks(state, tr, editor, paragraphAttrs) {
9499
+ const styleId = paragraphAttrs?.paragraphProperties?.styleId;
9500
+ if (!editor?.converter && !styleId) {
9501
+ return;
9502
+ }
9503
+ try {
9504
+ const params2 = { docx: editor?.converter?.convertedXml ?? {}, numbering: editor?.converter?.numbering ?? {} };
9505
+ const resolvedPpr = styleId ? { styleId } : {};
9506
+ const runProperties = styleId ? resolveRunProperties(params2, {}, resolvedPpr, false, false) : {};
9507
+ const markDefsFromStyle = styleId ? (
9508
+ /** @type {Array<{type: string, attrs: Record<string, unknown>}>} */
9509
+ encodeMarksFromRPr(runProperties, editor?.converter?.convertedXml ?? {})
9510
+ ) : [];
9511
+ const selectionMarks = state.selection?.$from?.marks ? state.selection.$from.marks() : [];
9512
+ const selectionMarkDefs = selectionMarks.map((mark) => ({ type: mark.type.name, attrs: mark.attrs }));
9513
+ const markDefsToApply = selectionMarks.length ? selectionMarkDefs : markDefsFromStyle;
9514
+ const marksToApply = markDefsToApply.map((def) => {
9515
+ const markType = state.schema.marks[def.type];
9516
+ return markType ? markType.create(def.attrs) : null;
9517
+ }).filter(Boolean);
9518
+ if (marksToApply.length > 0) {
9519
+ tr.ensureMarks(marksToApply);
9520
+ tr.setMeta("sdStyleMarks", markDefsToApply);
9521
+ }
9522
+ } catch {
9523
+ }
9524
+ }
9144
9525
  const splitRunAtCursor = () => (props) => {
9145
9526
  let { state, dispatch, tr } = props;
9146
9527
  const sel = state.selection;
@@ -10024,7 +10405,7 @@ const updateAttributes = (typeOrName, attrs = {}) => ({ tr, state, dispatch }) =
10024
10405
  }
10025
10406
  return true;
10026
10407
  };
10027
- const isPlainObject$4 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
10408
+ const isPlainObject$3 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
10028
10409
  const assignNestedValue = (target, path, value) => {
10029
10410
  if (!path.includes(".")) {
10030
10411
  target[path] = value;
@@ -10038,7 +10419,7 @@ const assignNestedValue = (target, path, value) => {
10038
10419
  if (isLast) {
10039
10420
  current[part] = value;
10040
10421
  } else {
10041
- if (!isPlainObject$4(current[part])) {
10422
+ if (!isPlainObject$3(current[part])) {
10042
10423
  current[part] = {};
10043
10424
  }
10044
10425
  current = current[part];
@@ -13011,8 +13392,12 @@ const createOrUpdateTrackedChangeComment = ({ event, marks, deletionNodes, nodes
13011
13392
  const hasMatchingId = changeMarks.find((mark) => mark.attrs.id === id);
13012
13393
  if (hasMatchingId) nodesWithMark.push(node2);
13013
13394
  });
13395
+ const nodesToProcess = nodesWithMark.length ? nodesWithMark : node ? [node] : [];
13396
+ if (!nodesToProcess.length) {
13397
+ return;
13398
+ }
13014
13399
  const { deletionText, trackedChangeText } = getTrackedChangeText({
13015
- nodes: nodesWithMark.length ? nodesWithMark : [node],
13400
+ nodes: nodesToProcess,
13016
13401
  mark: trackedMark,
13017
13402
  trackedChangeType,
13018
13403
  isDeletionInsertion
@@ -13728,6 +14113,45 @@ const updateYdocDocxData = async (editor, ydoc) => {
13728
14113
  console.warn("[collaboration] Failed to update Ydoc docx data", error);
13729
14114
  }
13730
14115
  };
14116
+ let isApplyingRemoteChanges = false;
14117
+ const isApplyingRemoteHeaderFooterChanges = () => isApplyingRemoteChanges;
14118
+ const pushHeaderFooterToYjs = (editor, type, sectionId, content) => {
14119
+ if (isApplyingRemoteChanges) return;
14120
+ const ydoc = editor?.options?.ydoc;
14121
+ if (!ydoc) return;
14122
+ const headerFooterMap = ydoc.getMap("headerFooterJson");
14123
+ const key2 = `${type}:${sectionId}`;
14124
+ const existing = headerFooterMap.get(key2)?.content;
14125
+ if (existing && JSON.stringify(existing) === JSON.stringify(content)) {
14126
+ return;
14127
+ }
14128
+ ydoc.transact(() => headerFooterMap.set(key2, { type, sectionId, content }), {
14129
+ event: "header-footer-update",
14130
+ user: editor.options.user
14131
+ });
14132
+ };
14133
+ const applyRemoteHeaderFooterChanges = (editor, key2, data) => {
14134
+ if (!editor || editor.isDestroyed || !editor.converter) return;
14135
+ const { type, sectionId, content } = data;
14136
+ if (!type || !sectionId || !content) return;
14137
+ isApplyingRemoteChanges = true;
14138
+ try {
14139
+ const storage = editor.converter[`${type}s`];
14140
+ if (storage) storage[sectionId] = content;
14141
+ editor.converter.headerFooterModified = true;
14142
+ const editors = editor.converter[`${type}Editors`];
14143
+ editors?.forEach((item) => {
14144
+ if (item.id === sectionId && item.editor) {
14145
+ item.editor.replaceContent(content);
14146
+ }
14147
+ });
14148
+ editor.emit("remoteHeaderFooterChanged", { type, sectionId, content });
14149
+ } finally {
14150
+ setTimeout(() => {
14151
+ isApplyingRemoteChanges = false;
14152
+ }, 0);
14153
+ }
14154
+ };
13731
14155
  new PluginKey("collaboration");
13732
14156
  const Collaboration = Extension.create({
13733
14157
  name: "collaboration",
@@ -13756,6 +14180,18 @@ const Collaboration = Extension.create({
13756
14180
  }
13757
14181
  });
13758
14182
  });
14183
+ const headerFooterMap = this.options.ydoc.getMap("headerFooterJson");
14184
+ headerFooterMap.observe((event) => {
14185
+ if (event.transaction.local) return;
14186
+ event.changes.keys.forEach((change, key2) => {
14187
+ if (change.action === "add" || change.action === "update") {
14188
+ const data = headerFooterMap.get(key2);
14189
+ if (data) {
14190
+ applyRemoteHeaderFooterChanges(this.editor, key2, data);
14191
+ }
14192
+ }
14193
+ });
14194
+ });
13759
14195
  return [syncPlugin];
13760
14196
  },
13761
14197
  addCommands() {
@@ -14898,7 +15334,7 @@ const canUseDOM = () => {
14898
15334
  return false;
14899
15335
  }
14900
15336
  };
14901
- const summaryVersion = "1.3.0-next.2";
15337
+ const summaryVersion = "1.3.0-next.4";
14902
15338
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
14903
15339
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
14904
15340
  function mapAttributes(attrs) {
@@ -17531,7 +17967,7 @@ class Editor extends EventEmitter {
17531
17967
  * Process collaboration migrations
17532
17968
  */
17533
17969
  processCollaborationMigrations() {
17534
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.2");
17970
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.4");
17535
17971
  if (!this.options.ydoc) return;
17536
17972
  const metaMap = this.options.ydoc.getMap("meta");
17537
17973
  let docVersion = metaMap.get("version");
@@ -23106,39 +23542,6 @@ const resolveTableCellBorders = (tableBorders, rowIndex, colIndex, totalRows, to
23106
23542
  right: borderValueToSpec(isLastCol ? tableBorders?.right : null)
23107
23543
  };
23108
23544
  };
23109
- const FONT_FAMILY_FALLBACKS = Object.freeze({
23110
- swiss: "Arial, sans-serif",
23111
- roman: "Times New Roman, serif",
23112
- modern: "Courier New, monospace",
23113
- script: "cursive",
23114
- decorative: "fantasy",
23115
- system: "system-ui",
23116
- auto: "sans-serif"
23117
- });
23118
- const DEFAULT_GENERIC_FALLBACK = "sans-serif";
23119
- const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
23120
- function mapWordFamilyFallback(wordFamily) {
23121
- if (!wordFamily) return DEFAULT_GENERIC_FALLBACK;
23122
- const mapped = FONT_FAMILY_FALLBACKS[wordFamily.toLowerCase()];
23123
- return mapped || DEFAULT_GENERIC_FALLBACK;
23124
- }
23125
- function toCssFontFamily(fontName, options = {}) {
23126
- if (!fontName || typeof fontName !== "string") return fontName;
23127
- const trimmed = fontName.trim();
23128
- if (!trimmed || trimmed.includes(",")) return trimmed;
23129
- const { fallback, wordFamily } = options;
23130
- const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK;
23131
- const fallbackParts = normalizeParts(fallbackValue);
23132
- if (fallbackParts.length === 0) {
23133
- return trimmed;
23134
- }
23135
- const normalizedName = trimmed.toLowerCase();
23136
- const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
23137
- if (includesName) {
23138
- return fallbackParts.join(", ");
23139
- }
23140
- return [trimmed, ...fallbackParts].join(", ");
23141
- }
23142
23545
  const LIST_MARKER_GAP$3 = 8;
23143
23546
  function renderListMarker(params2) {
23144
23547
  const { doc: doc2, lineEl, markerLayout, markerMeasure, indentLeftPx } = params2;
@@ -27141,7 +27544,12 @@ class DomPainter {
27141
27544
  const hanging = paraIndent?.hanging ?? 0;
27142
27545
  const isFirstLineOfPara = lineIndex === 0 || lineIndex === void 0;
27143
27546
  const firstLineOffsetForCumX = isFirstLineOfPara ? firstLine - hanging : 0;
27144
- const indentOffset = indentLeft + firstLineOffsetForCumX;
27547
+ const wordLayoutValue = block.attrs?.wordLayout;
27548
+ const wordLayout = isMinimalWordLayout(wordLayoutValue) ? wordLayoutValue : void 0;
27549
+ const isListParagraph = Boolean(wordLayout?.marker);
27550
+ const rawTextStartPx = typeof wordLayout?.marker?.textStartX === "number" && Number.isFinite(wordLayout.marker.textStartX) ? wordLayout.marker.textStartX : typeof wordLayout?.textStartPx === "number" && Number.isFinite(wordLayout.textStartPx) ? wordLayout.textStartPx : void 0;
27551
+ const listIndentOffset = isFirstLineOfPara ? rawTextStartPx ?? indentLeft : indentLeft;
27552
+ const indentOffset = isListParagraph ? listIndentOffset : indentLeft + firstLineOffsetForCumX;
27145
27553
  let cumulativeX = 0;
27146
27554
  const segmentsByRun = /* @__PURE__ */ new Map();
27147
27555
  line.segments.forEach((segment) => {
@@ -39702,8 +40110,17 @@ const pxToPt = (px) => {
39702
40110
  if (px == null || !Number.isFinite(px)) return void 0;
39703
40111
  return px / PX_PER_PT;
39704
40112
  };
40113
+ const convertIndentTwipsToPx$1 = (indent) => {
40114
+ if (!indent) return void 0;
40115
+ const result = {};
40116
+ if (isFiniteNumber(indent.left)) result.left = twipsToPx$1(indent.left);
40117
+ if (isFiniteNumber(indent.right)) result.right = twipsToPx$1(indent.right);
40118
+ if (isFiniteNumber(indent.firstLine)) result.firstLine = twipsToPx$1(indent.firstLine);
40119
+ if (isFiniteNumber(indent.hanging)) result.hanging = twipsToPx$1(indent.hanging);
40120
+ return Object.keys(result).length ? result : void 0;
40121
+ };
39705
40122
  const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
39706
- const isPlainObject$3 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
40123
+ const isPlainObject$2 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
39707
40124
  const normalizePrefix = (value) => {
39708
40125
  if (!value) return "";
39709
40126
  return String(value);
@@ -39765,7 +40182,7 @@ function coerceBoolean(value) {
39765
40182
  }
39766
40183
  return void 0;
39767
40184
  }
39768
- const toBoolean$3 = (value) => {
40185
+ const toBoolean$2 = (value) => {
39769
40186
  if (typeof value === "boolean") return value;
39770
40187
  if (typeof value === "string") {
39771
40188
  const v = value.trim().toLowerCase();
@@ -40056,7 +40473,7 @@ function hydrateImageBlocks(blocks, mediaFiles) {
40056
40473
  });
40057
40474
  }
40058
40475
  function isGradientFill(value) {
40059
- if (!isPlainObject$3(value)) return false;
40476
+ if (!isPlainObject$2(value)) return false;
40060
40477
  if (value.type !== "gradient") return false;
40061
40478
  const gradientType = value.gradientType;
40062
40479
  if (gradientType !== "linear" && gradientType !== "radial") return false;
@@ -40067,12 +40484,12 @@ function isGradientFill(value) {
40067
40484
  }
40068
40485
  if (!Array.isArray(value.stops) || value.stops.length === 0) return false;
40069
40486
  return value.stops.every((stop) => {
40070
- if (!isPlainObject$3(stop)) return false;
40487
+ if (!isPlainObject$2(stop)) return false;
40071
40488
  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));
40072
40489
  });
40073
40490
  }
40074
40491
  function isSolidFillWithAlpha(value) {
40075
- return isPlainObject$3(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
40492
+ return isPlainObject$2(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
40076
40493
  }
40077
40494
  function normalizeFillColor(value) {
40078
40495
  if (value === null) return null;
@@ -40087,10 +40504,10 @@ function normalizeStrokeColor(value) {
40087
40504
  return void 0;
40088
40505
  }
40089
40506
  function normalizeTextContent(value) {
40090
- if (!isPlainObject$3(value)) return void 0;
40507
+ if (!isPlainObject$2(value)) return void 0;
40091
40508
  if (!Array.isArray(value.parts)) return void 0;
40092
40509
  if (value.parts.length === 0) return void 0;
40093
- const validParts = value.parts.filter((p) => isPlainObject$3(p) && typeof p.text === "string");
40510
+ const validParts = value.parts.filter((p) => isPlainObject$2(p) && typeof p.text === "string");
40094
40511
  if (validParts.length === 0) return void 0;
40095
40512
  const result = {
40096
40513
  parts: validParts
@@ -40108,7 +40525,7 @@ function normalizeTextVerticalAlign(value) {
40108
40525
  return void 0;
40109
40526
  }
40110
40527
  function normalizeTextInsets(value) {
40111
- if (!isPlainObject$3(value)) return void 0;
40528
+ if (!isPlainObject$2(value)) return void 0;
40112
40529
  const top2 = pickNumber(value.top);
40113
40530
  const right2 = pickNumber(value.right);
40114
40531
  const bottom2 = pickNumber(value.bottom);
@@ -40120,7 +40537,7 @@ function normalizeTextInsets(value) {
40120
40537
  }
40121
40538
  const OOXML_Z_INDEX_BASE = 251658240;
40122
40539
  function normalizeZIndex(originalAttributes) {
40123
- if (!isPlainObject$3(originalAttributes)) return void 0;
40540
+ if (!isPlainObject$2(originalAttributes)) return void 0;
40124
40541
  const relativeHeight = originalAttributes.relativeHeight;
40125
40542
  if (typeof relativeHeight !== "number") return void 0;
40126
40543
  return Math.max(0, relativeHeight - OOXML_Z_INDEX_BASE);
@@ -41314,321 +41731,6 @@ const ensureBidiIndentPx = (indent) => {
41314
41731
  }
41315
41732
  return adjusted;
41316
41733
  };
41317
- const sdtMetadataCache = /* @__PURE__ */ new Map();
41318
- function resolveStyle(node, context, options = {}) {
41319
- let paragraph = createDefaultParagraph();
41320
- let character = createDefaultCharacter(context);
41321
- let numbering;
41322
- const chain = resolveStyleChain(node.styleId, context.styles);
41323
- for (const style2 of chain) {
41324
- paragraph = mergeParagraph(paragraph, style2.paragraph);
41325
- character = mergeCharacter(character, style2.character);
41326
- if (!numbering && style2.numbering) {
41327
- numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
41328
- }
41329
- }
41330
- paragraph = mergeParagraph(paragraph, node.paragraphProps);
41331
- character = mergeCharacter(character, node.characterProps);
41332
- if (node.numbering) {
41333
- numbering = resolveNumbering(node.numbering.numId, node.numbering.level, context);
41334
- }
41335
- const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
41336
- return {
41337
- paragraph,
41338
- character,
41339
- numbering,
41340
- sdt
41341
- };
41342
- }
41343
- function resolveNumbering(numId, level, context) {
41344
- const def = context.numbering?.[numId];
41345
- if (!def) return void 0;
41346
- const levelDef = def.levels.find((entry) => entry.level === level) ?? def.levels[level];
41347
- if (!levelDef) return void 0;
41348
- return {
41349
- numId,
41350
- level,
41351
- indent: {
41352
- left: levelDef.indent?.left,
41353
- hanging: levelDef.indent?.hanging
41354
- },
41355
- format: levelDef.format ?? "decimal",
41356
- text: levelDef.text ?? "%1.",
41357
- start: levelDef.start ?? 1
41358
- };
41359
- }
41360
- function resolveSdtMetadata(input) {
41361
- if (!input) return void 0;
41362
- const { nodeType, attrs, cacheKey: explicitKey } = input;
41363
- if (!nodeType) return void 0;
41364
- const normalizedAttrs = isPlainObject$2(attrs) ? attrs : {};
41365
- const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
41366
- if (cacheKey && sdtMetadataCache.has(cacheKey)) {
41367
- return sdtMetadataCache.get(cacheKey);
41368
- }
41369
- let metadata;
41370
- switch (nodeType) {
41371
- case "fieldAnnotation":
41372
- metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
41373
- break;
41374
- case "structuredContent":
41375
- case "structuredContentBlock":
41376
- metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
41377
- break;
41378
- case "documentSection":
41379
- metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
41380
- break;
41381
- case "docPartObject":
41382
- metadata = normalizeDocPartMetadata(normalizedAttrs);
41383
- break;
41384
- }
41385
- if (metadata && cacheKey) {
41386
- sdtMetadataCache.set(cacheKey, metadata);
41387
- }
41388
- return metadata;
41389
- }
41390
- function createDefaultParagraph(_context) {
41391
- return {
41392
- alignment: "left",
41393
- spacing: {
41394
- before: 0,
41395
- after: 0,
41396
- line: 12,
41397
- lineRule: "auto"
41398
- },
41399
- indent: {
41400
- left: 0,
41401
- right: 0,
41402
- firstLine: 0,
41403
- hanging: 0
41404
- },
41405
- tabs: []
41406
- };
41407
- }
41408
- function createDefaultCharacter(context) {
41409
- const baseFont = context.defaults?.paragraphFont ?? "Calibri";
41410
- const fallback = context.defaults?.paragraphFontFallback;
41411
- const wordFamily = context.defaults?.paragraphFontFamily;
41412
- const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
41413
- return {
41414
- font: {
41415
- family: resolvedFamily,
41416
- size: context.defaults?.fontSize ?? 11,
41417
- weight: 400,
41418
- italic: false
41419
- },
41420
- color: "#000000"
41421
- };
41422
- }
41423
- function resolveStyleChain(styleId, styles) {
41424
- if (!styleId || !styles) return [];
41425
- const result = [];
41426
- const visited = /* @__PURE__ */ new Set();
41427
- let current = styles[styleId];
41428
- while (current && !visited.has(current.id)) {
41429
- result.unshift(current);
41430
- visited.add(current.id);
41431
- current = current.basedOn ? styles[current.basedOn] : void 0;
41432
- }
41433
- return result;
41434
- }
41435
- function mergeParagraph(base2, overrides) {
41436
- if (!overrides) return base2;
41437
- return {
41438
- ...base2,
41439
- alignment: overrides.alignment ?? base2.alignment,
41440
- spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
41441
- indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
41442
- borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
41443
- shading: overrides.shading ?? base2.shading,
41444
- tabs: overrides.tabs ?? base2.tabs
41445
- };
41446
- }
41447
- function mergeCharacter(base2, overrides) {
41448
- if (!overrides) return base2;
41449
- return {
41450
- ...base2,
41451
- font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
41452
- color: overrides.color ?? base2.color,
41453
- underline: overrides.underline ?? base2.underline,
41454
- strike: overrides.strike ?? base2.strike,
41455
- highlight: overrides.highlight ?? base2.highlight,
41456
- letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
41457
- };
41458
- }
41459
- function normalizeFieldAnnotationMetadata(attrs) {
41460
- const fieldId = toOptionalString(attrs.fieldId) ?? "";
41461
- const formatting = extractFormatting(attrs);
41462
- const size2 = normalizeSize(attrs.size);
41463
- const extras = isPlainObject$2(attrs.extras) ? attrs.extras : null;
41464
- const marks = isPlainObject$2(attrs.marks) ? attrs.marks : void 0;
41465
- return {
41466
- type: "fieldAnnotation",
41467
- fieldId,
41468
- variant: normalizeFieldAnnotationVariant(attrs.type),
41469
- fieldType: toOptionalString(attrs.fieldType),
41470
- displayLabel: toOptionalString(attrs.displayLabel),
41471
- defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
41472
- alias: toOptionalString(attrs.alias),
41473
- fieldColor: normalizeColorValue(attrs.fieldColor),
41474
- borderColor: normalizeColorValue(attrs.borderColor),
41475
- highlighted: toBoolean$2(attrs.highlighted, true),
41476
- fontFamily: toNullableString(attrs.fontFamily),
41477
- fontSize: normalizeFontSize(attrs.fontSize),
41478
- textColor: normalizeColorValue(attrs.textColor) ?? null,
41479
- textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
41480
- linkUrl: toNullableString(attrs.linkUrl),
41481
- imageSrc: toNullableString(attrs.imageSrc),
41482
- rawHtml: attrs.rawHtml ?? void 0,
41483
- size: size2 ?? null,
41484
- extras,
41485
- multipleImage: toBoolean$2(attrs.multipleImage, false),
41486
- hash: toOptionalString(attrs.hash) ?? null,
41487
- generatorIndex: toNumber(attrs.generatorIndex),
41488
- sdtId: toOptionalString(attrs.sdtId) ?? null,
41489
- hidden: toBoolean$2(attrs.hidden, false),
41490
- visibility: normalizeVisibility(attrs.visibility),
41491
- isLocked: toBoolean$2(attrs.isLocked, false),
41492
- formatting,
41493
- marks
41494
- };
41495
- }
41496
- function normalizeStructuredContentMetadata(nodeType, attrs) {
41497
- return {
41498
- type: "structuredContent",
41499
- scope: nodeType === "structuredContentBlock" ? "block" : "inline",
41500
- id: toNullableString(attrs.id),
41501
- tag: toOptionalString(attrs.tag),
41502
- alias: toOptionalString(attrs.alias),
41503
- sdtPr: attrs.sdtPr
41504
- };
41505
- }
41506
- function normalizeDocumentSectionMetadata(attrs) {
41507
- return {
41508
- type: "documentSection",
41509
- id: toNullableString(attrs.id),
41510
- title: toOptionalString(attrs.title) ?? null,
41511
- description: toOptionalString(attrs.description) ?? null,
41512
- sectionType: toOptionalString(attrs.sectionType) ?? null,
41513
- isLocked: toBoolean$2(attrs.isLocked, false),
41514
- sdBlockId: toNullableString(attrs.sdBlockId)
41515
- };
41516
- }
41517
- function normalizeDocPartMetadata(attrs) {
41518
- return {
41519
- type: "docPartObject",
41520
- gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
41521
- // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
41522
- // Fall back to attrs.uniqueId for compatibility
41523
- uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
41524
- alias: toOptionalString(attrs.alias) ?? null,
41525
- instruction: toOptionalString(attrs.instruction) ?? null
41526
- };
41527
- }
41528
- function isPlainObject$2(value) {
41529
- return !!value && typeof value === "object" && !Array.isArray(value);
41530
- }
41531
- function toOptionalString(value) {
41532
- if (value == null) return void 0;
41533
- if (typeof value === "string") {
41534
- const trimmed = value.trim();
41535
- return trimmed.length ? trimmed : void 0;
41536
- }
41537
- return String(value);
41538
- }
41539
- function toNullableString(value) {
41540
- const str = toOptionalString(value);
41541
- return str ?? null;
41542
- }
41543
- function toBoolean$2(value, fallback) {
41544
- if (typeof value === "boolean") return value;
41545
- if (typeof value === "string") {
41546
- const lower = value.toLowerCase();
41547
- if (lower === "true") return true;
41548
- if (lower === "false") return false;
41549
- }
41550
- if (value == null) return fallback;
41551
- return Boolean(value);
41552
- }
41553
- function normalizeVisibility(value) {
41554
- if (typeof value !== "string") return void 0;
41555
- const normalized = value.toLowerCase();
41556
- if (normalized === "visible" || normalized === "hidden") {
41557
- return normalized;
41558
- }
41559
- return void 0;
41560
- }
41561
- function normalizeColorValue(value) {
41562
- if (typeof value !== "string") return void 0;
41563
- const trimmed = value.trim();
41564
- if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
41565
- return trimmed;
41566
- }
41567
- function normalizeFontSize(value) {
41568
- if (value == null) return null;
41569
- if (typeof value === "number") {
41570
- return Number.isFinite(value) ? value : null;
41571
- }
41572
- if (typeof value === "string") {
41573
- const trimmed = value.trim();
41574
- return trimmed.length ? trimmed : null;
41575
- }
41576
- return null;
41577
- }
41578
- function toNumber(value) {
41579
- if (typeof value === "number") {
41580
- return Number.isFinite(value) ? value : null;
41581
- }
41582
- if (typeof value === "string") {
41583
- const parsed = parseFloat(value);
41584
- return Number.isFinite(parsed) ? parsed : null;
41585
- }
41586
- return null;
41587
- }
41588
- function normalizeSize(value) {
41589
- if (!isPlainObject$2(value)) return null;
41590
- const obj = value;
41591
- const width = toNumber(obj.width);
41592
- const height = toNumber(obj.height);
41593
- if (width == null && height == null) return null;
41594
- const result = {};
41595
- if (width != null) result.width = width;
41596
- if (height != null) result.height = height;
41597
- return result;
41598
- }
41599
- function normalizeFieldAnnotationVariant(value) {
41600
- if (typeof value !== "string") return void 0;
41601
- const normalized = value.toLowerCase();
41602
- if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
41603
- return normalized;
41604
- }
41605
- return void 0;
41606
- }
41607
- function extractFormatting(attrs) {
41608
- const bold = toBoolean$2(attrs.bold, false);
41609
- const italic = toBoolean$2(attrs.italic, false);
41610
- const underline = toBoolean$2(attrs.underline, false);
41611
- const formatting = {};
41612
- if (bold) formatting.bold = true;
41613
- if (italic) formatting.italic = true;
41614
- if (underline) formatting.underline = true;
41615
- return Object.keys(formatting).length ? formatting : void 0;
41616
- }
41617
- function buildSdtCacheKey(nodeType, attrs, explicitKey) {
41618
- const provided = toOptionalString(explicitKey);
41619
- if (provided) {
41620
- return `${nodeType}:${provided}`;
41621
- }
41622
- const hash2 = toOptionalString(attrs.hash);
41623
- if (hash2) {
41624
- return `${nodeType}:${hash2}`;
41625
- }
41626
- const id = toOptionalString(attrs.id);
41627
- if (id) {
41628
- return `${nodeType}:${id}`;
41629
- }
41630
- return void 0;
41631
- }
41632
41734
  const DEFAULT_LIST_HANGING_PX = 18;
41633
41735
  const LIST_MARKER_GAP = 8;
41634
41736
  const DEFAULT_BULLET_GLYPH = "•";
@@ -42188,6 +42290,7 @@ const EMPTY_NUMBERING_CONTEXT = {
42188
42290
  definitions: {},
42189
42291
  abstracts: {}
42190
42292
  };
42293
+ const ooxmlResolver = createOoxmlResolver({ pPr: translator, rPr: translator$1 });
42191
42294
  const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
42192
42295
  if (!hasParagraphStyleContext(context)) {
42193
42296
  return null;
@@ -42215,7 +42318,7 @@ const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
42215
42318
  // should still get docDefaults spacing from style resolution
42216
42319
  numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42217
42320
  };
42218
- const resolved = resolveParagraphProperties(resolverParams, inlineProps);
42321
+ const resolved = ooxmlResolver.resolveParagraphProperties(resolverParams, inlineProps);
42219
42322
  if (!resolved) {
42220
42323
  return null;
42221
42324
  }
@@ -42270,6 +42373,138 @@ const cloneIfObject = (value) => {
42270
42373
  }
42271
42374
  return { ...value };
42272
42375
  };
42376
+ const buildCharacterStyleHydration = (resolved, docx) => {
42377
+ const fontFamily2 = extractFontFamily(resolved.fontFamily, docx);
42378
+ const fontSize2 = typeof resolved.fontSize === "number" ? resolved.fontSize : 20;
42379
+ const color = extractColorValue(resolved.color);
42380
+ const bold = normalizeBooleanProp(resolved.bold);
42381
+ const italic = normalizeBooleanProp(resolved.italic);
42382
+ const strike = normalizeBooleanProp(resolved.strike);
42383
+ const underline = extractUnderline(resolved.underline);
42384
+ const letterSpacing = typeof resolved.letterSpacing === "number" ? resolved.letterSpacing : void 0;
42385
+ return {
42386
+ fontFamily: fontFamily2,
42387
+ fontSize: fontSize2,
42388
+ color,
42389
+ bold,
42390
+ italic,
42391
+ strike,
42392
+ underline,
42393
+ letterSpacing
42394
+ };
42395
+ };
42396
+ const hydrateCharacterStyleAttrs = (para, context, resolvedPpr) => {
42397
+ if (!hasParagraphStyleContext(context)) {
42398
+ return null;
42399
+ }
42400
+ const attrs = para.attrs ?? {};
42401
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
42402
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
42403
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
42404
+ const inlineRpr = {};
42405
+ const pprForChain = resolvedPpr ?? { styleId };
42406
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
42407
+ if (numberingProps != null) {
42408
+ pprForChain.numberingProperties = numberingProps;
42409
+ }
42410
+ const resolverParams = {
42411
+ docx: context.docx,
42412
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42413
+ };
42414
+ let resolved = null;
42415
+ try {
42416
+ resolved = ooxmlResolver.resolveRunProperties(
42417
+ resolverParams,
42418
+ inlineRpr,
42419
+ pprForChain,
42420
+ false,
42421
+ // not list number marker
42422
+ false
42423
+ // not numberingDefinedInline
42424
+ );
42425
+ if (!resolved || typeof resolved !== "object") {
42426
+ return null;
42427
+ }
42428
+ } catch {
42429
+ return null;
42430
+ }
42431
+ return buildCharacterStyleHydration(resolved, context.docx);
42432
+ };
42433
+ const hydrateMarkerStyleAttrs = (para, context, resolvedPpr) => {
42434
+ if (!hasParagraphStyleContext(context)) {
42435
+ return null;
42436
+ }
42437
+ const attrs = para.attrs ?? {};
42438
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
42439
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
42440
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
42441
+ const inlineRpr = {};
42442
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
42443
+ const numberingDefinedInline = numberingProps?.numId != null;
42444
+ const pprForChain = resolvedPpr ? { ...resolvedPpr } : { styleId };
42445
+ if (styleId && !pprForChain.styleId) {
42446
+ pprForChain.styleId = styleId;
42447
+ }
42448
+ if (numberingProps != null) {
42449
+ pprForChain.numberingProperties = numberingProps;
42450
+ }
42451
+ const resolverParams = {
42452
+ docx: context.docx,
42453
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
42454
+ };
42455
+ let resolved = null;
42456
+ try {
42457
+ resolved = ooxmlResolver.resolveRunProperties(
42458
+ resolverParams,
42459
+ inlineRpr,
42460
+ pprForChain,
42461
+ true,
42462
+ numberingDefinedInline
42463
+ );
42464
+ if (!resolved || typeof resolved !== "object") {
42465
+ return null;
42466
+ }
42467
+ } catch {
42468
+ return null;
42469
+ }
42470
+ return buildCharacterStyleHydration(resolved, context.docx);
42471
+ };
42472
+ function extractFontFamily(fontFamily2, docx) {
42473
+ if (!fontFamily2 || typeof fontFamily2 !== "object") return void 0;
42474
+ const toCssFontFamily2 = SuperConverter.toCssFontFamily;
42475
+ const resolved = resolveDocxFontFamily(fontFamily2, docx ?? null, toCssFontFamily2);
42476
+ return resolved ?? void 0;
42477
+ }
42478
+ function extractColorValue(color) {
42479
+ if (!color || typeof color !== "object") return void 0;
42480
+ const c2 = color;
42481
+ const val = c2.val;
42482
+ if (typeof val !== "string") return void 0;
42483
+ if (!val || val.toLowerCase() === "auto") return void 0;
42484
+ return val;
42485
+ }
42486
+ function normalizeBooleanProp(value) {
42487
+ if (value == null) return void 0;
42488
+ if (typeof value === "boolean") return value;
42489
+ if (typeof value === "number") return value !== 0;
42490
+ if (typeof value === "string") {
42491
+ const lower = value.toLowerCase();
42492
+ if (lower === "0" || lower === "false" || lower === "off") return false;
42493
+ if (lower === "1" || lower === "true" || lower === "on" || lower === "") return true;
42494
+ }
42495
+ return Boolean(value);
42496
+ }
42497
+ function extractUnderline(underline) {
42498
+ if (!underline || typeof underline !== "object") return void 0;
42499
+ const u = underline;
42500
+ const type = u["w:val"] ?? u.type ?? u.val;
42501
+ if (typeof type !== "string" || type === "none") return void 0;
42502
+ const color = u["w:color"] ?? u.color;
42503
+ return {
42504
+ type,
42505
+ color: typeof color === "string" ? color : void 0
42506
+ };
42507
+ }
42273
42508
  const { resolveSpacingIndent } = Engines;
42274
42509
  const DEFAULT_DECIMAL_SEPARATOR$2 = ".";
42275
42510
  const isValidNumberingId = (numId) => {
@@ -42785,7 +43020,7 @@ const extractDropCapRunFromParagraph = (para) => {
42785
43020
  }
42786
43021
  return dropCapRun;
42787
43022
  };
42788
- const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, _paragraphNode) => {
43023
+ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, paragraphNode, converterContext, resolvedPpr) => {
42789
43024
  if (numberingProps === null) {
42790
43025
  return null;
42791
43026
  }
@@ -42823,7 +43058,23 @@ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleCont
42823
43058
  spacing: {}
42824
43059
  }
42825
43060
  };
42826
- let markerRun = numberingProps?.resolvedMarkerRpr;
43061
+ let markerRun;
43062
+ const markerHydration = paragraphNode && converterContext ? hydrateMarkerStyleAttrs(paragraphNode, converterContext, resolvedPpr) : null;
43063
+ if (markerHydration) {
43064
+ const resolvedColor = markerHydration.color ? `#${markerHydration.color.replace("#", "")}` : void 0;
43065
+ markerRun = {
43066
+ fontFamily: markerHydration.fontFamily ?? "Times New Roman",
43067
+ fontSize: markerHydration.fontSize / 2,
43068
+ // half-points to points
43069
+ bold: markerHydration.bold,
43070
+ italic: markerHydration.italic,
43071
+ color: resolvedColor,
43072
+ letterSpacing: markerHydration.letterSpacing != null ? twipsToPx$1(markerHydration.letterSpacing) : void 0
43073
+ };
43074
+ }
43075
+ if (!markerRun) {
43076
+ markerRun = numberingProps?.resolvedMarkerRpr;
43077
+ }
42827
43078
  if (!markerRun) {
42828
43079
  const { character: characterStyle } = resolveStyle({ styleId: paragraphAttrs.styleId }, styleContext);
42829
43080
  if (characterStyle) {
@@ -42892,8 +43143,11 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
42892
43143
  const hydrated = hydrationOverride ?? hydrateParagraphStyleAttrs(para, converterContext);
42893
43144
  const mergedSpacing = mergeSpacingSources(hydrated?.spacing, paragraphProps.spacing, attrs.spacing);
42894
43145
  const normalizedSpacing = normalizeParagraphSpacing(mergedSpacing);
42895
- const indentSource = attrs.indent ?? paragraphProps.indent ?? hydrated?.indent;
42896
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? attrs.textIndent);
43146
+ const normalizeIndentObject = (value) => {
43147
+ if (!value || typeof value !== "object") return;
43148
+ return normalizePxIndent(value) ?? convertIndentTwipsToPx(value);
43149
+ };
43150
+ const normalizedIndent = normalizeIndentObject(attrs.indent) ?? convertIndentTwipsToPx(paragraphProps.indent) ?? convertIndentTwipsToPx(hydrated?.indent) ?? normalizeParagraphIndent(attrs.textIndent);
42897
43151
  const unwrapTabStops = (tabStops) => {
42898
43152
  if (!Array.isArray(tabStops)) {
42899
43153
  return void 0;
@@ -43144,7 +43398,12 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
43144
43398
  const numId = numberingProps.numId;
43145
43399
  const ilvl = Number.isFinite(numberingProps.ilvl) ? Math.max(0, Math.floor(Number(numberingProps.ilvl))) : 0;
43146
43400
  const numericNumId = typeof numId === "number" ? numId : void 0;
43147
- const resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
43401
+ let resolvedLevel;
43402
+ try {
43403
+ resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
43404
+ } catch (error) {
43405
+ resolvedLevel = void 0;
43406
+ }
43148
43407
  if (resolvedLevel) {
43149
43408
  if (resolvedLevel.format && numberingProps.format == null) {
43150
43409
  numberingProps.format = resolvedLevel.format;
@@ -43205,7 +43464,19 @@ const computeParagraphAttrs = (para, styleContext, listCounterContext, converter
43205
43464
  }
43206
43465
  }
43207
43466
  }
43208
- let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
43467
+ let wordLayout = null;
43468
+ try {
43469
+ wordLayout = computeWordLayoutForParagraph(
43470
+ paragraphAttrs,
43471
+ enrichedNumberingProps,
43472
+ styleContext,
43473
+ para,
43474
+ converterContext,
43475
+ hydrated?.resolved
43476
+ );
43477
+ } catch (error) {
43478
+ wordLayout = null;
43479
+ }
43209
43480
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
43210
43481
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
43211
43482
  const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
@@ -43750,7 +44021,7 @@ const V_RELATIVE_VALUES$1 = /* @__PURE__ */ new Set(["paragraph", "page", "margi
43750
44021
  const H_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["left", "center", "right"]);
43751
44022
  const V_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["top", "center", "bottom"]);
43752
44023
  const getAttrs$1 = (node) => {
43753
- return isPlainObject$3(node.attrs) ? node.attrs : {};
44024
+ return isPlainObject$2(node.attrs) ? node.attrs : {};
43754
44025
  };
43755
44026
  const normalizeWrapType$1 = (value) => {
43756
44027
  if (typeof value !== "string") return void 0;
@@ -43773,7 +44044,7 @@ const normalizePolygon$1 = (value) => {
43773
44044
  return polygon.length > 0 ? polygon : void 0;
43774
44045
  };
43775
44046
  const normalizeWrap$2 = (value) => {
43776
- if (!isPlainObject$3(value)) {
44047
+ if (!isPlainObject$2(value)) {
43777
44048
  return void 0;
43778
44049
  }
43779
44050
  const type = normalizeWrapType$1(value.type);
@@ -43781,7 +44052,7 @@ const normalizeWrap$2 = (value) => {
43781
44052
  return void 0;
43782
44053
  }
43783
44054
  const wrap = { type };
43784
- const attrs = isPlainObject$3(value.attrs) ? value.attrs : {};
44055
+ const attrs = isPlainObject$2(value.attrs) ? value.attrs : {};
43785
44056
  const wrapText = normalizeWrapText$1(attrs.wrapText);
43786
44057
  if (wrapText) {
43787
44058
  wrap.wrapText = wrapText;
@@ -43798,7 +44069,7 @@ const normalizeWrap$2 = (value) => {
43798
44069
  if (polygon) {
43799
44070
  wrap.polygon = polygon;
43800
44071
  }
43801
- const behindDoc = toBoolean$3(attrs.behindDoc);
44072
+ const behindDoc = toBoolean$2(attrs.behindDoc);
43802
44073
  if (behindDoc != null) {
43803
44074
  wrap.behindDoc = behindDoc;
43804
44075
  }
@@ -43813,10 +44084,10 @@ const normalizeAnchorAlign$1 = (value, allowed) => {
43813
44084
  return allowed.has(value) ? value : void 0;
43814
44085
  };
43815
44086
  const normalizeAnchorData$1 = (value, attrs, wrapBehindDoc) => {
43816
- const raw = isPlainObject$3(value) ? value : void 0;
43817
- const marginOffset = isPlainObject$3(attrs.marginOffset) ? attrs.marginOffset : void 0;
43818
- const simplePos = isPlainObject$3(attrs.simplePos) ? attrs.simplePos : void 0;
43819
- const originalAttrs = isPlainObject$3(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
44087
+ const raw = isPlainObject$2(value) ? value : void 0;
44088
+ const marginOffset = isPlainObject$2(attrs.marginOffset) ? attrs.marginOffset : void 0;
44089
+ const simplePos = isPlainObject$2(attrs.simplePos) ? attrs.simplePos : void 0;
44090
+ const originalAttrs = isPlainObject$2(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
43820
44091
  const isAnchored = attrs.isAnchor === true || Boolean(raw);
43821
44092
  const anchor = {};
43822
44093
  if (isAnchored) {
@@ -43834,7 +44105,7 @@ const normalizeAnchorData$1 = (value, attrs, wrapBehindDoc) => {
43834
44105
  if (offsetH != null) anchor.offsetH = offsetH;
43835
44106
  const offsetV = pickNumber(marginOffset?.top ?? marginOffset?.vertical ?? raw?.offsetV ?? simplePos?.y);
43836
44107
  if (offsetV != null) anchor.offsetV = offsetV;
43837
- const behindDoc = toBoolean$3(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
44108
+ const behindDoc = toBoolean$2(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
43838
44109
  if (behindDoc != null) anchor.behindDoc = behindDoc;
43839
44110
  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;
43840
44111
  return hasData ? anchor : void 0;
@@ -43959,7 +44230,7 @@ function handleShapeTextboxNode(node, context) {
43959
44230
  }
43960
44231
  }
43961
44232
  const getAttrs = (node) => {
43962
- return isPlainObject$3(node.attrs) ? { ...node.attrs } : {};
44233
+ return isPlainObject$2(node.attrs) ? { ...node.attrs } : {};
43963
44234
  };
43964
44235
  const parseFullWidth = (value) => {
43965
44236
  if (typeof value === "string") {
@@ -43978,7 +44249,7 @@ function contentBlockNodeToDrawingBlock(node, nextBlockId, positions) {
43978
44249
  if (rawAttrs.horizontalRule !== true) {
43979
44250
  return null;
43980
44251
  }
43981
- const size2 = isPlainObject$3(rawAttrs.size) ? rawAttrs.size : void 0;
44252
+ const size2 = isPlainObject$2(rawAttrs.size) ? rawAttrs.size : void 0;
43982
44253
  const { width, isFullWidth } = parseFullWidth(size2?.width);
43983
44254
  const height = pickNumber(size2?.height);
43984
44255
  if (!height || height <= 0) {
@@ -44180,6 +44451,9 @@ const extractRunStyleId = (runProperties) => {
44180
44451
  return null;
44181
44452
  };
44182
44453
  const DEFAULT_IMAGE_DIMENSION_PX = 100;
44454
+ const HALF_POINTS_PER_POINT = 2;
44455
+ const SCREEN_DPI = 96;
44456
+ const POINT_DPI = 72;
44183
44457
  function isInlineImage(node) {
44184
44458
  const attrs = node.attrs ?? {};
44185
44459
  const wrap = attrs.wrap;
@@ -44207,8 +44481,8 @@ function imageNodeToRun(node, positions, activeSdt) {
44207
44481
  const size2 = attrs.size ?? {};
44208
44482
  const width = typeof size2.width === "number" && Number.isFinite(size2.width) && size2.width > 0 ? size2.width : DEFAULT_IMAGE_DIMENSION_PX;
44209
44483
  const height = typeof size2.height === "number" && Number.isFinite(size2.height) && size2.height > 0 ? size2.height : DEFAULT_IMAGE_DIMENSION_PX;
44210
- const wrap = isPlainObject$3(attrs.wrap) ? attrs.wrap : {};
44211
- const wrapAttrs = isPlainObject$3(wrap.attrs) ? wrap.attrs : {};
44484
+ const wrap = isPlainObject$2(attrs.wrap) ? attrs.wrap : {};
44485
+ const wrapAttrs = isPlainObject$2(wrap.attrs) ? wrap.attrs : {};
44212
44486
  const run = {
44213
44487
  kind: "image",
44214
44488
  src,
@@ -44418,15 +44692,6 @@ const applyBaseRunDefaults = (run, defaults, uiDisplayFallbackFont, fallbackSize
44418
44692
  if (defaults.letterSpacing != null && run.letterSpacing == null) {
44419
44693
  run.letterSpacing = defaults.letterSpacing;
44420
44694
  }
44421
- if (defaults.bold && run.bold === void 0) {
44422
- run.bold = true;
44423
- }
44424
- if (defaults.italic && run.italic === void 0) {
44425
- run.italic = true;
44426
- }
44427
- if (defaults.underline && !run.underline) {
44428
- run.underline = defaults.underline;
44429
- }
44430
44695
  };
44431
44696
  function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defaultSize, styleContext, listCounterContext, trackedChanges, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG$1, themeColors, converters, converterContext) {
44432
44697
  const baseBlockId = nextBlockId("paragraph");
@@ -44435,28 +44700,48 @@ function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defa
44435
44700
  const paragraphHydration = converterContext ? hydrateParagraphStyleAttrs(para, converterContext) : null;
44436
44701
  let baseRunDefaults = {};
44437
44702
  try {
44438
- const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
44439
- const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
44440
- const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
44441
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
44442
- const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
44443
- const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
44444
- if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
44445
- styleNode.styleId = paragraphProps.styleId;
44446
- }
44447
- const resolved = resolveStyle(styleNode, styleContext);
44448
- baseRunDefaults = {
44449
- fontFamily: resolved.character.font?.family,
44450
- fontSizePx: ptToPx(resolved.character.font?.size),
44451
- color: resolved.character.color,
44452
- bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
44453
- italic: resolved.character.font?.italic,
44454
- underline: resolved.character.underline ? {
44455
- style: resolved.character.underline.style,
44456
- color: resolved.character.underline.color
44457
- } : void 0,
44458
- letterSpacing: ptToPx(resolved.character.letterSpacing)
44459
- };
44703
+ const charHydration = converterContext ? hydrateCharacterStyleAttrs(para, converterContext, paragraphHydration?.resolved) : null;
44704
+ if (charHydration) {
44705
+ const fontSizePx = charHydration.fontSize / HALF_POINTS_PER_POINT * (SCREEN_DPI / POINT_DPI);
44706
+ baseRunDefaults = {
44707
+ fontFamily: charHydration.fontFamily,
44708
+ fontSizePx,
44709
+ color: charHydration.color ? `#${charHydration.color.replace("#", "")}` : void 0,
44710
+ bold: charHydration.bold,
44711
+ italic: charHydration.italic,
44712
+ underline: charHydration.underline ? {
44713
+ style: charHydration.underline.type,
44714
+ color: charHydration.underline.color
44715
+ } : void 0,
44716
+ letterSpacing: charHydration.letterSpacing != null ? twipsToPx$1(charHydration.letterSpacing) : void 0
44717
+ };
44718
+ } else {
44719
+ const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
44720
+ const normalizeIndentObject = (value) => {
44721
+ if (!value || typeof value !== "object") return;
44722
+ return normalizePxIndent(value) ?? convertIndentTwipsToPx$1(value);
44723
+ };
44724
+ const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
44725
+ const normalizedIndent = normalizeIndentObject(para.attrs?.indent) ?? convertIndentTwipsToPx$1(paragraphProps.indent) ?? convertIndentTwipsToPx$1(paragraphHydration?.indent) ?? normalizeParagraphIndent(para.attrs?.textIndent);
44726
+ const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
44727
+ const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
44728
+ if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
44729
+ styleNode.styleId = paragraphProps.styleId;
44730
+ }
44731
+ const resolved = resolveStyle(styleNode, styleContext);
44732
+ baseRunDefaults = {
44733
+ fontFamily: resolved.character.font?.family,
44734
+ fontSizePx: ptToPx(resolved.character.font?.size),
44735
+ color: resolved.character.color,
44736
+ bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
44737
+ italic: resolved.character.font?.italic,
44738
+ underline: resolved.character.underline ? {
44739
+ style: resolved.character.underline.style,
44740
+ color: resolved.character.underline.color
44741
+ } : void 0,
44742
+ letterSpacing: ptToPx(resolved.character.letterSpacing)
44743
+ };
44744
+ }
44460
44745
  } catch {
44461
44746
  baseRunDefaults = {};
44462
44747
  }
@@ -46158,6 +46443,9 @@ const createHeaderFooterEditor = ({
46158
46443
  };
46159
46444
  const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sectionId, type) => {
46160
46445
  if (!type || !sectionId) return;
46446
+ if (isApplyingRemoteHeaderFooterChanges()) {
46447
+ return;
46448
+ }
46161
46449
  const updatedData = editor.getUpdatedJson();
46162
46450
  const editorsList = mainEditor.converter[`${type}Editors`];
46163
46451
  if (Array.isArray(editorsList)) {
@@ -46181,6 +46469,7 @@ const onHeaderFooterDataUpdate = async ({ editor, transaction }, mainEditor, sec
46181
46469
  if (editor.docChanged && mainEditor.converter) {
46182
46470
  mainEditor.converter.headerFooterModified = true;
46183
46471
  }
46472
+ pushHeaderFooterToYjs(mainEditor, type, sectionId, updatedData);
46184
46473
  await updateYdocDocxData(mainEditor);
46185
46474
  };
46186
46475
  const setEditorToolbar = ({ editor }, mainEditor) => {
@@ -48007,7 +48296,8 @@ async function measureParagraphBlock(block, maxWidth) {
48007
48296
  const originX = currentLine.width;
48008
48297
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
48009
48298
  tabStopCursor = nextIndex;
48010
- const tabAdvance = Math.max(0, target - currentLine.width);
48299
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
48300
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
48011
48301
  currentLine.width = roundValue(currentLine.width + tabAdvance);
48012
48302
  run.width = tabAdvance;
48013
48303
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, 12);
@@ -48015,14 +48305,14 @@ async function measureParagraphBlock(block, maxWidth) {
48015
48305
  currentLine.toChar = 1;
48016
48306
  if (stop) {
48017
48307
  validateTabStopVal(stop);
48018
- pendingTabAlignment = { target, val: stop.val };
48308
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
48019
48309
  } else {
48020
48310
  pendingTabAlignment = null;
48021
48311
  }
48022
48312
  if (stop && stop.leader && stop.leader !== "none") {
48023
48313
  const leaderStyle = stop.leader;
48024
- const from3 = Math.min(originX, target);
48025
- const to = Math.max(originX, target);
48314
+ const from3 = Math.min(originX, clampedTarget);
48315
+ const to = Math.max(originX, clampedTarget);
48026
48316
  if (!currentLine.leaders) currentLine.leaders = [];
48027
48317
  currentLine.leaders.push({ from: from3, to, style: leaderStyle });
48028
48318
  }
@@ -48617,7 +48907,8 @@ async function measureParagraphBlock(block, maxWidth) {
48617
48907
  const originX = currentLine.width;
48618
48908
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
48619
48909
  tabStopCursor = nextIndex;
48620
- const tabAdvance = Math.max(0, target - currentLine.width);
48910
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
48911
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
48621
48912
  currentLine.width = roundValue(currentLine.width + tabAdvance);
48622
48913
  currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run);
48623
48914
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run.fontSize);
@@ -48626,14 +48917,14 @@ async function measureParagraphBlock(block, maxWidth) {
48626
48917
  charPosInRun += 1;
48627
48918
  if (stop) {
48628
48919
  validateTabStopVal(stop);
48629
- pendingTabAlignment = { target, val: stop.val };
48920
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
48630
48921
  } else {
48631
48922
  pendingTabAlignment = null;
48632
48923
  }
48633
48924
  if (stop && stop.leader && stop.leader !== "none" && stop.leader !== "middleDot") {
48634
48925
  const leaderStyle = stop.leader;
48635
- const from3 = Math.min(originX, target);
48636
- const to = Math.max(originX, target);
48926
+ const from3 = Math.min(originX, clampedTarget);
48927
+ const to = Math.max(originX, clampedTarget);
48637
48928
  if (!currentLine.leaders) currentLine.leaders = [];
48638
48929
  currentLine.leaders.push({ from: from3, to, style: leaderStyle });
48639
48930
  }
@@ -51030,6 +51321,17 @@ class PresentationEditor extends EventEmitter {
51030
51321
  event: "collaborationReady",
51031
51322
  handler: handleCollaborationReady
51032
51323
  });
51324
+ const handleRemoteHeaderFooterChanged = (payload) => {
51325
+ this.#headerFooterAdapter?.invalidate(payload.sectionId);
51326
+ this.#headerFooterManager?.refresh();
51327
+ this.#pendingDocChange = true;
51328
+ this.#scheduleRerender();
51329
+ };
51330
+ this.#editor.on("remoteHeaderFooterChanged", handleRemoteHeaderFooterChanged);
51331
+ this.#editorListeners.push({
51332
+ event: "remoteHeaderFooterChanged",
51333
+ handler: handleRemoteHeaderFooterChanged
51334
+ });
51033
51335
  }
51034
51336
  /**
51035
51337
  * Setup awareness event subscriptions for remote cursor tracking.
@@ -57189,16 +57491,112 @@ const mapRangesThroughTransactions = (ranges, transactions, docSize) => {
57189
57491
  });
57190
57492
  return mergeRanges$2(mapped, docSize);
57191
57493
  };
57192
- const buildWrapTransaction = (state, ranges, runType) => {
57494
+ const getParagraphAtPos = (doc2, pos) => {
57495
+ try {
57496
+ const $pos = doc2.resolve(pos);
57497
+ for (let depth = $pos.depth; depth >= 0; depth--) {
57498
+ const node = $pos.node(depth);
57499
+ if (node.type.name === "paragraph") {
57500
+ return node;
57501
+ }
57502
+ }
57503
+ } catch (_e) {
57504
+ }
57505
+ return null;
57506
+ };
57507
+ const resolveRunPropertiesFromParagraphStyle = (paragraphNode, editor) => {
57508
+ if (!paragraphNode || !editor?.converter) return {};
57509
+ const styleId = paragraphNode.attrs?.paragraphProperties?.styleId;
57510
+ if (!styleId) return {};
57511
+ try {
57512
+ const params2 = { docx: editor.converter.convertedXml, numbering: editor.converter.numbering };
57513
+ const resolvedPpr = { styleId };
57514
+ const runProps = resolveRunProperties(params2, {}, resolvedPpr, false, false);
57515
+ const runProperties = {};
57516
+ if (runProps.fontFamily) {
57517
+ const fontValue = runProps.fontFamily.ascii || runProps.fontFamily;
57518
+ if (fontValue) {
57519
+ runProperties.fontFamily = typeof fontValue === "string" ? fontValue : fontValue.ascii;
57520
+ }
57521
+ }
57522
+ if (runProps.fontSize) {
57523
+ runProperties.fontSize = `${runProps.fontSize / 2}pt`;
57524
+ }
57525
+ if (runProps.bold) runProperties.bold = true;
57526
+ if (runProps.italic) runProperties.italic = true;
57527
+ if (runProps.underline) runProperties.underline = runProps.underline;
57528
+ if (runProps.strike) runProperties.strike = true;
57529
+ return runProperties;
57530
+ } catch (_e) {
57531
+ return {};
57532
+ }
57533
+ };
57534
+ const createMarksFromDefs = (schema, markDefs = []) => markDefs.map((def) => {
57535
+ const markType = schema.marks[def.type];
57536
+ return markType ? markType.create(def.attrs) : null;
57537
+ }).filter(Boolean);
57538
+ const createMarkDefsFromStyleRunProps = (styleRunProps) => {
57539
+ const markDefs = [];
57540
+ const textStyleAttrs = {};
57541
+ if (styleRunProps.fontSize) {
57542
+ textStyleAttrs.fontSize = styleRunProps.fontSize;
57543
+ }
57544
+ if (styleRunProps.fontFamily) {
57545
+ textStyleAttrs.fontFamily = styleRunProps.fontFamily;
57546
+ }
57547
+ if (Object.keys(textStyleAttrs).length > 0) {
57548
+ markDefs.push({ type: "textStyle", attrs: textStyleAttrs });
57549
+ }
57550
+ if (styleRunProps.bold) {
57551
+ markDefs.push({ type: "bold", attrs: { value: true } });
57552
+ }
57553
+ if (styleRunProps.italic) {
57554
+ markDefs.push({ type: "italic", attrs: { value: true } });
57555
+ }
57556
+ if (styleRunProps.strike) {
57557
+ markDefs.push({ type: "strike", attrs: { value: true } });
57558
+ }
57559
+ if (styleRunProps.underline) {
57560
+ const underlineType = styleRunProps.underline["w:val"];
57561
+ if (underlineType) {
57562
+ let underlineColor = styleRunProps.underline["w:color"];
57563
+ if (underlineColor && underlineColor.toLowerCase() !== "auto" && !underlineColor.startsWith("#")) {
57564
+ underlineColor = `#${underlineColor}`;
57565
+ }
57566
+ markDefs.push({
57567
+ type: "underline",
57568
+ attrs: { underlineType, underlineColor }
57569
+ });
57570
+ }
57571
+ }
57572
+ return markDefs;
57573
+ };
57574
+ const buildWrapTransaction = (state, ranges, runType, editor, markDefsFromMeta = []) => {
57193
57575
  if (!ranges.length) return null;
57194
57576
  const replacements = [];
57577
+ const metaStyleMarks = createMarksFromDefs(state.schema, markDefsFromMeta);
57195
57578
  ranges.forEach(({ from: from3, to }) => {
57196
57579
  state.doc.nodesBetween(from3, to, (node, pos, parent, index2) => {
57197
57580
  if (!node.isText || !parent || parent.type === runType) return;
57198
57581
  const match = parent.contentMatchAt ? parent.contentMatchAt(index2) : null;
57199
57582
  if (match && !match.matchType(runType)) return;
57200
57583
  if (!match && !parent.type.contentMatch.matchType(runType)) return;
57201
- const runProperties = decodeRPrFromMarks(node.marks);
57584
+ let runProperties = decodeRPrFromMarks(node.marks);
57585
+ if ((!node.marks || node.marks.length === 0) && editor?.converter) {
57586
+ const paragraphNode = getParagraphAtPos(state.doc, pos);
57587
+ const styleRunProps = resolveRunPropertiesFromParagraphStyle(paragraphNode, editor);
57588
+ if (Object.keys(styleRunProps).length > 0) {
57589
+ runProperties = styleRunProps;
57590
+ const markDefs = metaStyleMarks.length ? markDefsFromMeta : createMarkDefsFromStyleRunProps(styleRunProps);
57591
+ const styleMarks = metaStyleMarks.length ? metaStyleMarks : createMarksFromDefs(state.schema, markDefs);
57592
+ if (styleMarks.length && typeof state.schema.text === "function") {
57593
+ const textNode = state.schema.text(node.text || "", styleMarks);
57594
+ if (textNode) {
57595
+ node = textNode;
57596
+ }
57597
+ }
57598
+ }
57599
+ }
57202
57600
  const runNode = runType.create({ runProperties }, node);
57203
57601
  replacements.push({ from: pos, to: pos + node.nodeSize, runNode });
57204
57602
  });
@@ -57208,9 +57606,10 @@ const buildWrapTransaction = (state, ranges, runType) => {
57208
57606
  replacements.sort((a, b) => b.from - a.from).forEach(({ from: from3, to, runNode }) => tr.replaceWith(from3, to, runNode));
57209
57607
  return tr.docChanged ? tr : null;
57210
57608
  };
57211
- const wrapTextInRunsPlugin = () => {
57609
+ const wrapTextInRunsPlugin = (editor) => {
57212
57610
  let view = null;
57213
57611
  let pendingRanges = [];
57612
+ let lastStyleMarksMeta = [];
57214
57613
  const flush = () => {
57215
57614
  if (!view) return;
57216
57615
  const runType = view.state.schema.nodes.run;
@@ -57218,7 +57617,7 @@ const wrapTextInRunsPlugin = () => {
57218
57617
  pendingRanges = [];
57219
57618
  return;
57220
57619
  }
57221
- const tr = buildWrapTransaction(view.state, pendingRanges, runType);
57620
+ const tr = buildWrapTransaction(view.state, pendingRanges, runType, editor, lastStyleMarksMeta);
57222
57621
  pendingRanges = [];
57223
57622
  if (tr) {
57224
57623
  view.dispatch(tr);
@@ -57237,6 +57636,7 @@ const wrapTextInRunsPlugin = () => {
57237
57636
  editorView.dom.removeEventListener("compositionend", onCompositionEnd);
57238
57637
  view = null;
57239
57638
  pendingRanges = [];
57639
+ lastStyleMarksMeta = [];
57240
57640
  }
57241
57641
  };
57242
57642
  },
@@ -57250,7 +57650,11 @@ const wrapTextInRunsPlugin = () => {
57250
57650
  if (view?.composing) {
57251
57651
  return null;
57252
57652
  }
57253
- const tr = buildWrapTransaction(newState, pendingRanges, runType);
57653
+ const latestStyleMarksMeta = [...transactions].reverse().find((tr2) => tr2.getMeta && tr2.getMeta("sdStyleMarks"))?.getMeta("sdStyleMarks") || lastStyleMarksMeta;
57654
+ if (latestStyleMarksMeta && latestStyleMarksMeta.length) {
57655
+ lastStyleMarksMeta = latestStyleMarksMeta;
57656
+ }
57657
+ const tr = buildWrapTransaction(newState, pendingRanges, runType, editor, latestStyleMarksMeta);
57254
57658
  pendingRanges = [];
57255
57659
  return tr;
57256
57660
  }
@@ -57513,7 +57917,7 @@ const Run = OxmlNode.create({
57513
57917
  },
57514
57918
  addPmPlugins() {
57515
57919
  return [
57516
- wrapTextInRunsPlugin(),
57920
+ wrapTextInRunsPlugin(this.editor),
57517
57921
  splitRunsAfterMarkPlugin,
57518
57922
  calculateInlineRunPropertiesPlugin(this.editor),
57519
57923
  cleanupEmptyRunsPlugin