@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.
@@ -12179,134 +12179,200 @@
12179
12179
  "italic",
12180
12180
  "strike",
12181
12181
  "underline",
12182
- "letterSpacing",
12183
- "vertAlign",
12184
- "position"
12182
+ "letterSpacing"
12185
12183
  ];
12186
12184
  const DEFAULT_FONT_SIZE_HALF_POINTS = 20;
12187
- const SUBSCRIPT_SUPERSCRIPT_SCALE$1 = 0.65;
12188
- const resolveRunProperties = (params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) => {
12185
+ function isObject$4(item) {
12186
+ return item != null && typeof item === "object" && !Array.isArray(item);
12187
+ }
12188
+ function combineProperties$1(propertiesArray, options = {}) {
12189
+ const { fullOverrideProps = [], specialHandling = {} } = options;
12190
+ if (!propertiesArray || propertiesArray.length === 0) {
12191
+ return {};
12192
+ }
12193
+ const merge2 = (target, source) => {
12194
+ const output = { ...target };
12195
+ if (isObject$4(target) && isObject$4(source)) {
12196
+ for (const key2 in source) {
12197
+ if (Object.prototype.hasOwnProperty.call(source, key2)) {
12198
+ const handler2 = specialHandling[key2];
12199
+ if (handler2 && typeof handler2 === "function") {
12200
+ output[key2] = handler2(output, source);
12201
+ } else if (!fullOverrideProps.includes(key2) && isObject$4(source[key2])) {
12202
+ if (key2 in target && isObject$4(target[key2])) {
12203
+ output[key2] = merge2(target[key2], source[key2]);
12204
+ } else {
12205
+ output[key2] = source[key2];
12206
+ }
12207
+ } else {
12208
+ output[key2] = source[key2];
12209
+ }
12210
+ }
12211
+ }
12212
+ }
12213
+ return output;
12214
+ };
12215
+ return propertiesArray.reduce((acc, current) => merge2(acc, current ?? {}), {});
12216
+ }
12217
+ function combineRunProperties$1(propertiesArray) {
12218
+ return combineProperties$1(propertiesArray, {
12219
+ fullOverrideProps: ["fontFamily", "color"]
12220
+ });
12221
+ }
12222
+ function applyInlineOverrides(finalProps, inlineProps, overrideKeys = INLINE_OVERRIDE_PROPERTIES) {
12223
+ if (!inlineProps) return finalProps;
12224
+ for (const prop of overrideKeys) {
12225
+ if (inlineProps[prop] != null) {
12226
+ finalProps[prop] = inlineProps[prop];
12227
+ }
12228
+ }
12229
+ return finalProps;
12230
+ }
12231
+ function isValidFontSize(value) {
12232
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
12233
+ }
12234
+ function resolveFontSizeWithFallback(value, defaultProps2, normalProps) {
12235
+ if (isValidFontSize(value)) {
12236
+ return value;
12237
+ }
12238
+ if (defaultProps2 && isValidFontSize(defaultProps2.fontSize)) {
12239
+ return defaultProps2.fontSize;
12240
+ }
12241
+ if (normalProps && isValidFontSize(normalProps.fontSize)) {
12242
+ return normalProps.fontSize;
12243
+ }
12244
+ return DEFAULT_FONT_SIZE_HALF_POINTS;
12245
+ }
12246
+ function orderDefaultsAndNormal(defaultProps2, normalProps, isNormalDefault) {
12247
+ if (isNormalDefault) {
12248
+ return [defaultProps2, normalProps];
12249
+ } else {
12250
+ return [normalProps, defaultProps2];
12251
+ }
12252
+ }
12253
+ function createFirstLineIndentHandler() {
12254
+ return (target, source) => {
12255
+ if (target.hanging != null && source.firstLine != null) {
12256
+ delete target.hanging;
12257
+ }
12258
+ return source.firstLine;
12259
+ };
12260
+ }
12261
+ function combineIndentProperties(indentChain) {
12262
+ const indentOnly = indentChain.map((props) => props.indent != null ? { indent: props.indent } : {});
12263
+ return combineProperties$1(indentOnly, {
12264
+ specialHandling: {
12265
+ firstLine: createFirstLineIndentHandler()
12266
+ }
12267
+ });
12268
+ }
12269
+ function createOoxmlResolver(translators) {
12270
+ return {
12271
+ resolveRunProperties: (params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) => resolveRunProperties$1(translators, params2, inlineRpr, resolvedPpr, isListNumber, numberingDefinedInline),
12272
+ resolveParagraphProperties: (params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) => resolveParagraphProperties$1(translators, params2, inlineProps, insideTable, overrideInlineStyleId, tableStyleId),
12273
+ getDefaultProperties,
12274
+ getStyleProperties,
12275
+ resolveStyleChain: resolveStyleChain$1,
12276
+ getNumberingProperties: (params2, ilvl, numId, translator2, tries = 0) => getNumberingProperties(translators, params2, ilvl, numId, translator2, tries)
12277
+ };
12278
+ }
12279
+ function resolveRunProperties$1(translators, params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) {
12189
12280
  const paragraphStyleId = resolvedPpr?.styleId;
12190
- const paragraphStyleProps = resolveStyleChain$1(params2, paragraphStyleId, translator$1O);
12191
- const defaultProps2 = getDefaultProperties(params2, translator$1O);
12192
- const { properties: normalProps, isDefault: isNormalDefault } = getStyleProperties(params2, "Normal", translator$1O);
12281
+ const paragraphStyleProps = resolveStyleChain$1(params2, paragraphStyleId, translators.rPr);
12282
+ const defaultProps2 = getDefaultProperties(params2, translators.rPr);
12283
+ const { properties: normalProps, isDefault: isNormalDefault } = getStyleProperties(params2, "Normal", translators.rPr);
12193
12284
  let runStyleProps = {};
12194
12285
  if (!paragraphStyleId?.startsWith("TOC")) {
12195
- runStyleProps = inlineRpr.styleId ? resolveStyleChain$1(params2, inlineRpr.styleId, translator$1O) : {};
12286
+ runStyleProps = inlineRpr?.styleId ? resolveStyleChain$1(params2, inlineRpr.styleId, translators.rPr) : {};
12196
12287
  }
12288
+ const defaultsChain = orderDefaultsAndNormal(defaultProps2, normalProps, isNormalDefault);
12289
+ const inlineRprSafe = inlineRpr ?? {};
12197
12290
  let styleChain;
12198
- if (isNormalDefault) {
12199
- styleChain = [defaultProps2, normalProps];
12200
- } else {
12201
- styleChain = [normalProps, defaultProps2];
12202
- }
12291
+ let inlineOverrideSource = inlineRprSafe;
12203
12292
  if (isListNumber) {
12204
12293
  let numberingProps = {};
12205
- const numId = resolvedPpr?.numberingProperties?.numId;
12294
+ const numberingProperties = resolvedPpr?.numberingProperties;
12295
+ const numId = numberingProperties?.numId;
12206
12296
  if (numId != null && numId !== 0 && numId !== "0") {
12207
12297
  numberingProps = getNumberingProperties(
12298
+ translators,
12208
12299
  params2,
12209
- resolvedPpr.numberingProperties.ilvl ?? 0,
12300
+ numberingProperties?.ilvl ?? 0,
12210
12301
  numId,
12211
- translator$1O
12302
+ translators.rPr
12212
12303
  );
12213
12304
  }
12214
- if (!numberingDefinedInline) {
12215
- inlineRpr = {};
12305
+ const inlineRprForList = numberingDefinedInline ? inlineRprSafe : {};
12306
+ if (inlineRprForList?.underline) {
12307
+ delete inlineRprForList.underline;
12216
12308
  }
12217
- if (inlineRpr?.underline) {
12218
- delete inlineRpr.underline;
12219
- }
12220
- styleChain = [...styleChain, paragraphStyleProps, runStyleProps, inlineRpr, numberingProps];
12309
+ styleChain = [...defaultsChain, paragraphStyleProps, runStyleProps, inlineRprForList, numberingProps];
12310
+ inlineOverrideSource = inlineRprForList;
12221
12311
  } else {
12222
- styleChain = [...styleChain, paragraphStyleProps, runStyleProps, inlineRpr];
12223
- }
12224
- const finalProps = combineProperties(styleChain, ["fontFamily", "color"]);
12225
- for (const prop of INLINE_OVERRIDE_PROPERTIES) {
12226
- if (inlineRpr?.[prop] != null) {
12227
- finalProps[prop] = inlineRpr[prop];
12228
- }
12229
- }
12230
- if (finalProps.fontSize == null || typeof finalProps.fontSize !== "number" || !Number.isFinite(finalProps.fontSize) || finalProps.fontSize <= 0) {
12231
- let defaultFontSize = DEFAULT_FONT_SIZE_HALF_POINTS;
12232
- if (defaultProps2?.fontSize != null && typeof defaultProps2.fontSize === "number" && Number.isFinite(defaultProps2.fontSize) && defaultProps2.fontSize > 0) {
12233
- defaultFontSize = defaultProps2.fontSize;
12234
- } else if (normalProps?.fontSize != null && typeof normalProps.fontSize === "number" && Number.isFinite(normalProps.fontSize) && normalProps.fontSize > 0) {
12235
- defaultFontSize = normalProps.fontSize;
12236
- }
12237
- finalProps.fontSize = defaultFontSize;
12312
+ styleChain = [...defaultsChain, paragraphStyleProps, runStyleProps, inlineRprSafe];
12238
12313
  }
12314
+ const finalProps = combineRunProperties$1(styleChain);
12315
+ applyInlineOverrides(finalProps, inlineOverrideSource);
12316
+ finalProps.fontSize = resolveFontSizeWithFallback(finalProps.fontSize, defaultProps2, normalProps);
12239
12317
  return finalProps;
12240
- };
12241
- function resolveParagraphProperties(params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) {
12242
- const defaultProps2 = getDefaultProperties(params2, translator$14);
12243
- const { properties: normalProps, isDefault: isNormalDefault } = getStyleProperties(params2, "Normal", translator$14);
12244
- let styleId = inlineProps?.styleId;
12245
- let styleProps = inlineProps?.styleId ? resolveStyleChain$1(params2, inlineProps?.styleId, translator$14) : {};
12318
+ }
12319
+ function resolveParagraphProperties$1(translators, params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) {
12320
+ const defaultProps2 = getDefaultProperties(params2, translators.pPr);
12321
+ const { properties: normalProps, isDefault: isNormalDefault } = getStyleProperties(params2, "Normal", translators.pPr);
12322
+ const inlinePropsSafe = inlineProps ?? {};
12323
+ let styleId = inlinePropsSafe?.styleId;
12324
+ let styleProps = inlinePropsSafe?.styleId ? resolveStyleChain$1(params2, inlinePropsSafe.styleId, translators.pPr) : {};
12246
12325
  let numberingProps = {};
12247
- let ilvl = inlineProps?.numberingProperties?.ilvl ?? styleProps?.numberingProperties?.ilvl;
12248
- let numId = inlineProps?.numberingProperties?.numId ?? styleProps?.numberingProperties?.numId;
12249
- let numberingDefinedInline = inlineProps?.numberingProperties?.numId != null;
12250
- const inlineNumIdDisablesNumbering = inlineProps?.numberingProperties?.numId === 0 || inlineProps?.numberingProperties?.numId === "0";
12326
+ const ilvl = inlinePropsSafe?.numberingProperties?.ilvl ?? styleProps?.numberingProperties?.ilvl;
12327
+ let numId = inlinePropsSafe?.numberingProperties?.numId ?? styleProps?.numberingProperties?.numId;
12328
+ let numberingDefinedInline = inlinePropsSafe?.numberingProperties?.numId != null;
12329
+ const inlineNumId = inlinePropsSafe?.numberingProperties?.numId;
12330
+ const inlineNumIdDisablesNumbering = inlineNumId === 0 || inlineNumId === "0";
12251
12331
  if (inlineNumIdDisablesNumbering) {
12252
12332
  numId = null;
12253
12333
  }
12254
12334
  const isList2 = numId != null && numId !== 0 && numId !== "0";
12255
12335
  if (isList2) {
12256
- ilvl = ilvl != null ? ilvl : 0;
12257
- numberingProps = getNumberingProperties(params2, ilvl, numId, translator$14);
12336
+ const ilvlNum = ilvl != null ? ilvl : 0;
12337
+ numberingProps = getNumberingProperties(translators, params2, ilvlNum, numId, translators.pPr);
12258
12338
  if (overrideInlineStyleId && numberingProps.styleId) {
12259
12339
  styleId = numberingProps.styleId;
12260
- styleProps = resolveStyleChain$1(params2, styleId, translator$14);
12261
- if (inlineProps) {
12262
- inlineProps.styleId = styleId;
12263
- if (styleProps.numberingProperties?.ilvl === inlineProps.numberingProperties?.ilvl && styleProps.numberingProperties?.numId === inlineProps.numberingProperties?.numId) {
12264
- delete inlineProps.numberingProperties;
12340
+ styleProps = resolveStyleChain$1(params2, styleId, translators.pPr);
12341
+ if (inlinePropsSafe) {
12342
+ inlinePropsSafe.styleId = styleId;
12343
+ const inlineNumProps = inlinePropsSafe.numberingProperties;
12344
+ if (styleProps.numberingProperties?.ilvl === inlineNumProps?.ilvl && styleProps.numberingProperties?.numId === inlineNumProps?.numId) {
12345
+ delete inlinePropsSafe.numberingProperties;
12265
12346
  numberingDefinedInline = false;
12266
12347
  }
12267
12348
  }
12268
12349
  }
12269
12350
  }
12270
- const tableProps = tableStyleId ? resolveStyleChain$1(params2, tableStyleId, translator$14) : {};
12271
- let defaultsChain;
12272
- if (isNormalDefault) {
12273
- defaultsChain = [defaultProps2, normalProps];
12274
- } else {
12275
- defaultsChain = [normalProps, defaultProps2];
12276
- }
12277
- const propsChain = [...defaultsChain, tableProps, numberingProps, styleProps, inlineProps];
12351
+ const tableProps = tableStyleId ? resolveStyleChain$1(params2, tableStyleId, translators.pPr) : {};
12352
+ const defaultsChain = orderDefaultsAndNormal(defaultProps2, normalProps, isNormalDefault);
12353
+ const propsChain = [...defaultsChain, tableProps, numberingProps, styleProps, inlinePropsSafe];
12278
12354
  let indentChain;
12279
12355
  if (isList2) {
12280
12356
  if (numberingDefinedInline) {
12281
- indentChain = [...defaultsChain, styleProps, numberingProps, inlineProps];
12357
+ indentChain = [...defaultsChain, styleProps, numberingProps, inlinePropsSafe];
12282
12358
  } else {
12283
- styleProps = resolveStyleChain$1(params2, styleId, translator$14, false);
12284
- indentChain = [...defaultsChain, numberingProps, styleProps, inlineProps];
12359
+ styleProps = resolveStyleChain$1(params2, styleId, translators.pPr, false);
12360
+ indentChain = [...defaultsChain, numberingProps, styleProps, inlinePropsSafe];
12285
12361
  }
12286
12362
  } else {
12287
- indentChain = [...defaultsChain, numberingProps, styleProps, inlineProps];
12363
+ indentChain = [...defaultsChain, numberingProps, styleProps, inlinePropsSafe];
12288
12364
  }
12289
- let finalProps = combineProperties(propsChain);
12290
- let finalIndent = combineProperties(
12291
- indentChain.map((props) => props.indent != null ? { indent: props.indent } : {}),
12292
- [],
12293
- {
12294
- firstLine: (target, source) => {
12295
- if (target.hanging != null && source.firstLine != null) {
12296
- delete target.hanging;
12297
- }
12298
- return source.firstLine;
12299
- }
12300
- }
12301
- );
12365
+ const finalProps = combineProperties$1(propsChain);
12366
+ const finalIndent = combineIndentProperties(indentChain);
12302
12367
  finalProps.indent = finalIndent.indent;
12303
- if (insideTable && !inlineProps?.spacing && !styleProps.spacing) {
12368
+ if (insideTable && !inlinePropsSafe?.spacing && !styleProps?.spacing) {
12304
12369
  finalProps.spacing = void 0;
12305
12370
  }
12306
12371
  return finalProps;
12307
12372
  }
12308
- const resolveStyleChain$1 = (params2, styleId, translator2, followBasedOnChain = true) => {
12309
- let styleProps = {}, basedOn = null;
12373
+ function resolveStyleChain$1(params2, styleId, translator2, followBasedOnChain = true) {
12374
+ let styleProps = {};
12375
+ let basedOn = void 0;
12310
12376
  if (styleId && styleId !== "Normal") {
12311
12377
  ({ properties: styleProps, basedOn } = getStyleProperties(params2, styleId, translator2));
12312
12378
  }
@@ -12318,7 +12384,7 @@
12318
12384
  break;
12319
12385
  }
12320
12386
  seenStyles.add(basedOn);
12321
- const result = getStyleProperties(params2, basedOn, translator2);
12387
+ const result = getStyleProperties(params2, nextBasedOn, translator2);
12322
12388
  const basedOnProps = result.properties;
12323
12389
  nextBasedOn = result.basedOn;
12324
12390
  if (basedOnProps && Object.keys(basedOnProps).length) {
@@ -12327,120 +12393,499 @@
12327
12393
  basedOn = nextBasedOn;
12328
12394
  }
12329
12395
  styleChain = styleChain.reverse();
12330
- const combinedStyleProps = combineProperties(styleChain);
12331
- return combinedStyleProps;
12332
- };
12396
+ return combineProperties$1(styleChain);
12397
+ }
12333
12398
  function getDefaultProperties(params2, translator2) {
12334
- const { docx } = params2;
12335
- const styles = docx["word/styles.xml"];
12399
+ const docx = params2?.docx;
12400
+ const styles = docx?.["word/styles.xml"];
12336
12401
  const rootElements = styles?.elements?.[0]?.elements;
12337
12402
  if (!rootElements?.length) {
12338
12403
  return {};
12339
12404
  }
12340
12405
  const defaults2 = rootElements.find((el) => el.name === "w:docDefaults");
12341
12406
  const xmlName = translator2.xmlName;
12342
- const elementPrDefault = defaults2?.elements?.find((el) => el.name === `${xmlName}Default`) || {};
12343
- const elementPr = elementPrDefault?.elements?.find((el) => el.name === xmlName);
12407
+ const defaultsElements = defaults2?.elements;
12408
+ const elementPrDefault = defaultsElements?.find((el) => el.name === `${xmlName}Default`);
12409
+ const elementPrDefaultElements = elementPrDefault?.elements;
12410
+ const elementPr = elementPrDefaultElements?.find((el) => el.name === xmlName);
12344
12411
  if (!elementPr) {
12345
12412
  return {};
12346
12413
  }
12347
- const result = translator2.encode({ ...params2, nodes: [elementPr] }) || {};
12348
- return result;
12414
+ return translator2.encode({ ...params2, nodes: [elementPr] }) || {};
12349
12415
  }
12350
12416
  function getStyleProperties(params2, styleId, translator2) {
12351
- const { docx } = params2;
12352
- const emptyResult = { properties: {}, isDefault: false, basedOn: null };
12417
+ const emptyResult = { properties: {}, isDefault: false, basedOn: void 0 };
12353
12418
  if (!styleId) return emptyResult;
12354
- const styles = docx["word/styles.xml"];
12419
+ const docx = params2?.docx;
12420
+ const styles = docx?.["word/styles.xml"];
12355
12421
  const rootElements = styles?.elements?.[0]?.elements;
12356
12422
  if (!rootElements?.length) {
12357
12423
  return emptyResult;
12358
12424
  }
12359
- const style2 = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
12360
- let basedOn = style2?.elements?.find((el) => el.name === "w:basedOn");
12361
- if (basedOn) {
12362
- basedOn = basedOn?.attributes?.["w:val"];
12363
- }
12364
- const elementPr = style2?.elements?.find((el) => el.name === translator2.xmlName);
12425
+ const style2 = rootElements.find(
12426
+ (el) => el.name === "w:style" && el.attributes?.["w:styleId"] === styleId
12427
+ );
12428
+ const styleElements = style2?.elements;
12429
+ const basedOnElement = styleElements?.find((el) => el.name === "w:basedOn");
12430
+ const basedOn = basedOnElement?.attributes?.["w:val"];
12431
+ const elementPr = styleElements?.find((el) => el.name === translator2.xmlName);
12365
12432
  if (!elementPr) {
12366
12433
  return { ...emptyResult, basedOn };
12367
12434
  }
12368
12435
  const result = translator2.encode({ ...params2, nodes: [elementPr] }) || {};
12369
- return { properties: result, isDefault: style2?.attributes?.["w:default"] === "1", basedOn };
12436
+ const isDefault = style2?.attributes?.["w:default"] === "1";
12437
+ return { properties: result, isDefault, basedOn };
12370
12438
  }
12371
- function getNumberingProperties(params2, ilvl, numId, translator2, tries = 0) {
12372
- const { numbering: allDefinitions } = params2;
12373
- if (!allDefinitions) return {};
12374
- const { definitions, abstracts } = allDefinitions;
12439
+ function getNumberingProperties(translators, params2, ilvl, numId, translator2, tries = 0) {
12440
+ const numbering = params2?.numbering;
12441
+ if (!numbering) return {};
12442
+ const { definitions, abstracts } = numbering;
12443
+ if (!definitions || !abstracts) return {};
12375
12444
  const propertiesChain = [];
12376
12445
  const numDefinition = definitions[numId];
12377
12446
  if (!numDefinition) return {};
12378
- const lvlOverride = numDefinition?.elements?.find(
12379
- (element2) => element2.name === "w:lvlOverride" && element2.attributes["w:ilvl"] == ilvl
12447
+ const numDefElements = numDefinition.elements;
12448
+ const lvlOverride = numDefElements?.find(
12449
+ (element2) => element2.name === "w:lvlOverride" && element2.attributes?.["w:ilvl"] == ilvl
12380
12450
  );
12381
- const overridePr = lvlOverride?.elements?.find((el) => el.name === translator2.xmlName);
12451
+ const lvlOverrideElements = lvlOverride?.elements;
12452
+ const overridePr = lvlOverrideElements?.find((el) => el.name === translator2.xmlName);
12382
12453
  if (overridePr) {
12383
12454
  const overrideProps = translator2.encode({ ...params2, nodes: [overridePr] }) || {};
12384
12455
  propertiesChain.push(overrideProps);
12385
12456
  }
12386
- const abstractNumId = numDefinition.elements?.find((item) => item.name === "w:abstractNumId")?.attributes?.["w:val"];
12457
+ const abstractNumIdElement = numDefElements?.find((item) => item.name === "w:abstractNumId");
12458
+ const abstractNumId = abstractNumIdElement?.attributes?.["w:val"];
12387
12459
  const listDefinitionForThisNumId = abstracts[abstractNumId];
12388
12460
  if (!listDefinitionForThisNumId) return {};
12389
- const numStyleLink = listDefinitionForThisNumId.elements?.find((item) => item.name === "w:numStyleLink");
12461
+ const listDefElements = listDefinitionForThisNumId.elements;
12462
+ const numStyleLink = listDefElements?.find((item) => item.name === "w:numStyleLink");
12390
12463
  const styleId = numStyleLink?.attributes?.["w:val"];
12391
12464
  if (styleId && tries < 1) {
12392
- const { properties: styleProps } = getStyleProperties(params2, styleId, translator$14);
12393
- if (styleProps?.numberingProperties?.numId) {
12394
- return getNumberingProperties(params2, ilvl, styleProps.numberingProperties.numId, translator2, tries + 1);
12465
+ const { properties: styleProps } = getStyleProperties(params2, styleId, translators.pPr);
12466
+ const numIdFromStyle = styleProps?.numberingProperties?.numId;
12467
+ if (numIdFromStyle) {
12468
+ return getNumberingProperties(
12469
+ translators,
12470
+ params2,
12471
+ ilvl,
12472
+ numIdFromStyle,
12473
+ translator2,
12474
+ tries + 1
12475
+ );
12395
12476
  }
12396
12477
  }
12397
- const levelDefinition = listDefinitionForThisNumId?.elements?.find(
12398
- (element2) => element2.name === "w:lvl" && element2.attributes["w:ilvl"] == ilvl
12478
+ const levelDefinition = listDefElements?.find(
12479
+ (element2) => element2.name === "w:lvl" && element2.attributes?.["w:ilvl"] == ilvl
12399
12480
  );
12400
12481
  if (!levelDefinition) return {};
12401
- const abstractElementPr = levelDefinition?.elements?.find((el) => el.name === translator2.xmlName);
12482
+ const levelDefElements = levelDefinition.elements;
12483
+ const abstractElementPr = levelDefElements?.find((el) => el.name === translator2.xmlName);
12402
12484
  if (!abstractElementPr) return {};
12403
12485
  const abstractProps = translator2.encode({ ...params2, nodes: [abstractElementPr] }) || {};
12404
- const pStyleElement = levelDefinition?.elements?.find((el) => el.name === "w:pStyle");
12486
+ const pStyleElement = levelDefElements?.find((el) => el.name === "w:pStyle");
12405
12487
  if (pStyleElement) {
12406
- const pStyleId = pStyleElement?.attributes?.["w:val"];
12488
+ const pStyleId = pStyleElement.attributes?.["w:val"];
12407
12489
  abstractProps.styleId = pStyleId;
12408
12490
  }
12409
12491
  propertiesChain.push(abstractProps);
12410
12492
  propertiesChain.reverse();
12411
- const result = combineProperties(propertiesChain);
12412
- return result;
12493
+ return combineProperties$1(propertiesChain);
12413
12494
  }
12414
- const combineProperties = (propertiesArray, fullOverrideProps = [], specialHandling = {}) => {
12415
- if (!propertiesArray || propertiesArray.length === 0) {
12416
- return {};
12495
+ function resolveDocxFontFamily(attributes, docx, toCssFontFamily2) {
12496
+ if (!attributes || typeof attributes !== "object") return null;
12497
+ const ascii = attributes["w:ascii"] ?? attributes["ascii"];
12498
+ const themeAscii = attributes["w:asciiTheme"] ?? attributes["asciiTheme"];
12499
+ let resolved = ascii;
12500
+ if (docx && themeAscii) {
12501
+ const theme = docx["word/theme/theme1.xml"];
12502
+ const themeElements = theme?.elements;
12503
+ if (themeElements?.length) {
12504
+ const topElement = themeElements[0];
12505
+ const topElementElements = topElement?.elements;
12506
+ const themeElementsNode = topElementElements?.find((el) => el.name === "a:themeElements");
12507
+ const themeElementsElements = themeElementsNode?.elements;
12508
+ const fontScheme = themeElementsElements?.find((el) => el.name === "a:fontScheme");
12509
+ const fontSchemeElements = fontScheme?.elements;
12510
+ const prefix2 = themeAscii.startsWith("minor") ? "minor" : "major";
12511
+ const font = fontSchemeElements?.find((el) => el.name === `a:${prefix2}Font`);
12512
+ const fontElements = font?.elements;
12513
+ const latin = fontElements?.find((el) => el.name === "a:latin");
12514
+ const typeface = latin?.attributes?.typeface;
12515
+ resolved = typeface || resolved;
12516
+ }
12417
12517
  }
12418
- const isObject2 = (item) => item && typeof item === "object" && !Array.isArray(item);
12419
- const merge2 = (target, source) => {
12420
- const output = { ...target };
12421
- if (isObject2(target) && isObject2(source)) {
12422
- for (const key2 in source) {
12423
- if (Object.prototype.hasOwnProperty.call(source, key2)) {
12424
- if (!fullOverrideProps.includes(key2) && isObject2(source[key2])) {
12425
- if (key2 in target && isObject2(target[key2])) {
12426
- output[key2] = merge2(target[key2], source[key2]);
12427
- } else {
12428
- output[key2] = source[key2];
12429
- }
12430
- } else {
12431
- const handler2 = specialHandling[key2];
12432
- if (handler2 && typeof handler2 === "function") {
12433
- output[key2] = handler2(output, source);
12434
- } else {
12435
- output[key2] = source[key2];
12436
- }
12437
- }
12438
- }
12439
- }
12518
+ if (!resolved) return null;
12519
+ if (toCssFontFamily2) {
12520
+ return toCssFontFamily2(resolved, docx ?? void 0);
12521
+ }
12522
+ return resolved;
12523
+ }
12524
+ const FONT_FAMILY_FALLBACKS$1 = Object.freeze({
12525
+ swiss: "Arial, sans-serif",
12526
+ roman: "Times New Roman, serif",
12527
+ modern: "Courier New, monospace",
12528
+ script: "cursive",
12529
+ decorative: "fantasy",
12530
+ system: "system-ui",
12531
+ auto: "sans-serif"
12532
+ });
12533
+ const DEFAULT_GENERIC_FALLBACK$1 = "sans-serif";
12534
+ const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
12535
+ function mapWordFamilyFallback(wordFamily) {
12536
+ if (!wordFamily) return DEFAULT_GENERIC_FALLBACK$1;
12537
+ const mapped = FONT_FAMILY_FALLBACKS$1[wordFamily.toLowerCase()];
12538
+ return mapped || DEFAULT_GENERIC_FALLBACK$1;
12539
+ }
12540
+ function toCssFontFamily(fontName, options = {}) {
12541
+ if (!fontName || typeof fontName !== "string") return fontName;
12542
+ const trimmed = fontName.trim();
12543
+ if (!trimmed || trimmed.includes(",")) return trimmed;
12544
+ const { fallback, wordFamily } = options;
12545
+ const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK$1;
12546
+ const fallbackParts = normalizeParts(fallbackValue);
12547
+ if (fallbackParts.length === 0) {
12548
+ return trimmed;
12549
+ }
12550
+ const normalizedName = trimmed.toLowerCase();
12551
+ const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
12552
+ if (includesName) {
12553
+ return fallbackParts.join(", ");
12554
+ }
12555
+ return [trimmed, ...fallbackParts].join(", ");
12556
+ }
12557
+ const sdtMetadataCache = /* @__PURE__ */ new Map();
12558
+ function resolveStyle(node2, context, options = {}) {
12559
+ let paragraph2 = createDefaultParagraph();
12560
+ let character = createDefaultCharacter(context);
12561
+ let numbering;
12562
+ const chain = resolveStyleChain(node2.styleId, context.styles);
12563
+ for (const style2 of chain) {
12564
+ paragraph2 = mergeParagraph(paragraph2, style2.paragraph);
12565
+ character = mergeCharacter(character, style2.character);
12566
+ if (!numbering && style2.numbering) {
12567
+ numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
12440
12568
  }
12441
- return output;
12569
+ }
12570
+ paragraph2 = mergeParagraph(paragraph2, node2.paragraphProps);
12571
+ character = mergeCharacter(character, node2.characterProps);
12572
+ if (node2.numbering) {
12573
+ numbering = resolveNumbering(node2.numbering.numId, node2.numbering.level, context);
12574
+ }
12575
+ const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
12576
+ return {
12577
+ paragraph: paragraph2,
12578
+ character,
12579
+ numbering,
12580
+ sdt
12581
+ };
12582
+ }
12583
+ function resolveNumbering(numId, level, context) {
12584
+ const def2 = context.numbering?.[numId];
12585
+ if (!def2) return void 0;
12586
+ const levelDef = def2.levels.find((entry) => entry.level === level) ?? def2.levels[level];
12587
+ if (!levelDef) return void 0;
12588
+ return {
12589
+ numId,
12590
+ level,
12591
+ indent: {
12592
+ left: levelDef.indent?.left,
12593
+ hanging: levelDef.indent?.hanging
12594
+ },
12595
+ format: levelDef.format ?? "decimal",
12596
+ text: levelDef.text ?? "%1.",
12597
+ start: levelDef.start ?? 1
12598
+ };
12599
+ }
12600
+ function resolveSdtMetadata(input2) {
12601
+ if (!input2) return void 0;
12602
+ const { nodeType, attrs, cacheKey: explicitKey } = input2;
12603
+ if (!nodeType) return void 0;
12604
+ const normalizedAttrs = isPlainObject$7(attrs) ? attrs : {};
12605
+ const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
12606
+ if (cacheKey && sdtMetadataCache.has(cacheKey)) {
12607
+ return sdtMetadataCache.get(cacheKey);
12608
+ }
12609
+ let metadata;
12610
+ switch (nodeType) {
12611
+ case "fieldAnnotation":
12612
+ metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
12613
+ break;
12614
+ case "structuredContent":
12615
+ case "structuredContentBlock":
12616
+ metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
12617
+ break;
12618
+ case "documentSection":
12619
+ metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
12620
+ break;
12621
+ case "docPartObject":
12622
+ metadata = normalizeDocPartMetadata(normalizedAttrs);
12623
+ break;
12624
+ }
12625
+ if (metadata && cacheKey) {
12626
+ sdtMetadataCache.set(cacheKey, metadata);
12627
+ }
12628
+ return metadata;
12629
+ }
12630
+ function createDefaultParagraph(_context) {
12631
+ return {
12632
+ alignment: "left",
12633
+ spacing: {
12634
+ before: 0,
12635
+ after: 0,
12636
+ line: 12,
12637
+ lineRule: "auto"
12638
+ },
12639
+ indent: {
12640
+ left: 0,
12641
+ right: 0,
12642
+ firstLine: 0,
12643
+ hanging: 0
12644
+ },
12645
+ tabs: []
12646
+ };
12647
+ }
12648
+ function createDefaultCharacter(context) {
12649
+ const baseFont = context.defaults?.paragraphFont ?? "Calibri";
12650
+ const fallback = context.defaults?.paragraphFontFallback;
12651
+ const wordFamily = context.defaults?.paragraphFontFamily;
12652
+ const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
12653
+ return {
12654
+ font: {
12655
+ family: resolvedFamily,
12656
+ size: context.defaults?.fontSize ?? 11,
12657
+ weight: 400,
12658
+ italic: false
12659
+ },
12660
+ color: "#000000"
12661
+ };
12662
+ }
12663
+ function resolveStyleChain(styleId, styles) {
12664
+ if (!styleId || !styles) return [];
12665
+ const result = [];
12666
+ const visited = /* @__PURE__ */ new Set();
12667
+ let current = styles[styleId];
12668
+ while (current && !visited.has(current.id)) {
12669
+ result.unshift(current);
12670
+ visited.add(current.id);
12671
+ current = current.basedOn ? styles[current.basedOn] : void 0;
12672
+ }
12673
+ return result;
12674
+ }
12675
+ function mergeParagraph(base2, overrides) {
12676
+ if (!overrides) return base2;
12677
+ return {
12678
+ ...base2,
12679
+ alignment: overrides.alignment ?? base2.alignment,
12680
+ spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
12681
+ indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
12682
+ borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
12683
+ shading: overrides.shading ?? base2.shading,
12684
+ tabs: overrides.tabs ?? base2.tabs
12685
+ };
12686
+ }
12687
+ function mergeCharacter(base2, overrides) {
12688
+ if (!overrides) return base2;
12689
+ return {
12690
+ ...base2,
12691
+ font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
12692
+ color: overrides.color ?? base2.color,
12693
+ underline: overrides.underline ?? base2.underline,
12694
+ strike: overrides.strike ?? base2.strike,
12695
+ highlight: overrides.highlight ?? base2.highlight,
12696
+ letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
12697
+ };
12698
+ }
12699
+ function normalizeFieldAnnotationMetadata(attrs) {
12700
+ const fieldId = toOptionalString(attrs.fieldId) ?? "";
12701
+ const formatting = extractFormatting(attrs);
12702
+ const size2 = normalizeSize(attrs.size);
12703
+ const extras = isPlainObject$7(attrs.extras) ? attrs.extras : null;
12704
+ const marks = isPlainObject$7(attrs.marks) ? attrs.marks : void 0;
12705
+ return {
12706
+ type: "fieldAnnotation",
12707
+ fieldId,
12708
+ variant: normalizeFieldAnnotationVariant(attrs.type),
12709
+ fieldType: toOptionalString(attrs.fieldType),
12710
+ displayLabel: toOptionalString(attrs.displayLabel),
12711
+ defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
12712
+ alias: toOptionalString(attrs.alias),
12713
+ fieldColor: normalizeColorValue(attrs.fieldColor),
12714
+ borderColor: normalizeColorValue(attrs.borderColor),
12715
+ highlighted: toBoolean$3(attrs.highlighted, true),
12716
+ fontFamily: toNullableString(attrs.fontFamily),
12717
+ fontSize: normalizeFontSize(attrs.fontSize),
12718
+ textColor: normalizeColorValue(attrs.textColor) ?? null,
12719
+ textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
12720
+ linkUrl: toNullableString(attrs.linkUrl),
12721
+ imageSrc: toNullableString(attrs.imageSrc),
12722
+ rawHtml: attrs.rawHtml ?? void 0,
12723
+ size: size2 ?? null,
12724
+ extras,
12725
+ multipleImage: toBoolean$3(attrs.multipleImage, false),
12726
+ hash: toOptionalString(attrs.hash) ?? null,
12727
+ generatorIndex: toNumber$1(attrs.generatorIndex),
12728
+ sdtId: toOptionalString(attrs.sdtId) ?? null,
12729
+ hidden: toBoolean$3(attrs.hidden, false),
12730
+ visibility: normalizeVisibility(attrs.visibility),
12731
+ isLocked: toBoolean$3(attrs.isLocked, false),
12732
+ formatting,
12733
+ marks
12442
12734
  };
12443
- return propertiesArray.reduce((acc, current) => merge2(acc, current), {});
12735
+ }
12736
+ function normalizeStructuredContentMetadata(nodeType, attrs) {
12737
+ return {
12738
+ type: "structuredContent",
12739
+ scope: nodeType === "structuredContentBlock" ? "block" : "inline",
12740
+ id: toNullableString(attrs.id),
12741
+ tag: toOptionalString(attrs.tag),
12742
+ alias: toOptionalString(attrs.alias),
12743
+ sdtPr: attrs.sdtPr
12744
+ };
12745
+ }
12746
+ function normalizeDocumentSectionMetadata(attrs) {
12747
+ return {
12748
+ type: "documentSection",
12749
+ id: toNullableString(attrs.id),
12750
+ title: toOptionalString(attrs.title) ?? null,
12751
+ description: toOptionalString(attrs.description) ?? null,
12752
+ sectionType: toOptionalString(attrs.sectionType) ?? null,
12753
+ isLocked: toBoolean$3(attrs.isLocked, false),
12754
+ sdBlockId: toNullableString(attrs.sdBlockId)
12755
+ };
12756
+ }
12757
+ function normalizeDocPartMetadata(attrs) {
12758
+ return {
12759
+ type: "docPartObject",
12760
+ gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
12761
+ // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
12762
+ // Fall back to attrs.uniqueId for compatibility
12763
+ uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
12764
+ alias: toOptionalString(attrs.alias) ?? null,
12765
+ instruction: toOptionalString(attrs.instruction) ?? null
12766
+ };
12767
+ }
12768
+ function isPlainObject$7(value) {
12769
+ return !!value && typeof value === "object" && !Array.isArray(value);
12770
+ }
12771
+ function toOptionalString(value) {
12772
+ if (value == null) return void 0;
12773
+ if (typeof value === "string") {
12774
+ const trimmed = value.trim();
12775
+ return trimmed.length ? trimmed : void 0;
12776
+ }
12777
+ return String(value);
12778
+ }
12779
+ function toNullableString(value) {
12780
+ const str = toOptionalString(value);
12781
+ return str ?? null;
12782
+ }
12783
+ function toBoolean$3(value, fallback) {
12784
+ if (typeof value === "boolean") return value;
12785
+ if (typeof value === "string") {
12786
+ const lower = value.toLowerCase();
12787
+ if (lower === "true") return true;
12788
+ if (lower === "false") return false;
12789
+ }
12790
+ if (value == null) return fallback;
12791
+ return Boolean(value);
12792
+ }
12793
+ function normalizeVisibility(value) {
12794
+ if (typeof value !== "string") return void 0;
12795
+ const normalized = value.toLowerCase();
12796
+ if (normalized === "visible" || normalized === "hidden") {
12797
+ return normalized;
12798
+ }
12799
+ return void 0;
12800
+ }
12801
+ function normalizeColorValue(value) {
12802
+ if (typeof value !== "string") return void 0;
12803
+ const trimmed = value.trim();
12804
+ if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
12805
+ return trimmed;
12806
+ }
12807
+ function normalizeFontSize(value) {
12808
+ if (value == null) return null;
12809
+ if (typeof value === "number") {
12810
+ return Number.isFinite(value) ? value : null;
12811
+ }
12812
+ if (typeof value === "string") {
12813
+ const trimmed = value.trim();
12814
+ return trimmed.length ? trimmed : null;
12815
+ }
12816
+ return null;
12817
+ }
12818
+ function toNumber$1(value) {
12819
+ if (typeof value === "number") {
12820
+ return Number.isFinite(value) ? value : null;
12821
+ }
12822
+ if (typeof value === "string") {
12823
+ const parsed = parseFloat(value);
12824
+ return Number.isFinite(parsed) ? parsed : null;
12825
+ }
12826
+ return null;
12827
+ }
12828
+ function normalizeSize(value) {
12829
+ if (!isPlainObject$7(value)) return null;
12830
+ const obj = value;
12831
+ const width = toNumber$1(obj.width);
12832
+ const height = toNumber$1(obj.height);
12833
+ if (width == null && height == null) return null;
12834
+ const result = {};
12835
+ if (width != null) result.width = width;
12836
+ if (height != null) result.height = height;
12837
+ return result;
12838
+ }
12839
+ function normalizeFieldAnnotationVariant(value) {
12840
+ if (typeof value !== "string") return void 0;
12841
+ const normalized = value.toLowerCase();
12842
+ if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
12843
+ return normalized;
12844
+ }
12845
+ return void 0;
12846
+ }
12847
+ function extractFormatting(attrs) {
12848
+ const bold = toBoolean$3(attrs.bold, false);
12849
+ const italic = toBoolean$3(attrs.italic, false);
12850
+ const underline = toBoolean$3(attrs.underline, false);
12851
+ const formatting = {};
12852
+ if (bold) formatting.bold = true;
12853
+ if (italic) formatting.italic = true;
12854
+ if (underline) formatting.underline = true;
12855
+ return Object.keys(formatting).length ? formatting : void 0;
12856
+ }
12857
+ function buildSdtCacheKey(nodeType, attrs, explicitKey) {
12858
+ const provided = toOptionalString(explicitKey);
12859
+ if (provided) {
12860
+ return `${nodeType}:${provided}`;
12861
+ }
12862
+ const hash2 = toOptionalString(attrs.hash);
12863
+ if (hash2) {
12864
+ return `${nodeType}:${hash2}`;
12865
+ }
12866
+ const id = toOptionalString(attrs.id);
12867
+ if (id) {
12868
+ return `${nodeType}:${id}`;
12869
+ }
12870
+ return void 0;
12871
+ }
12872
+ const ooxmlResolver$1 = createOoxmlResolver({ pPr: translator$14, rPr: translator$1O });
12873
+ const getToCssFontFamily = () => {
12874
+ return SuperConverter.toCssFontFamily;
12875
+ };
12876
+ const SUBSCRIPT_SUPERSCRIPT_SCALE$1 = 0.65;
12877
+ const resolveRunProperties = (params2, inlineRpr, resolvedPpr, isListNumber = false, numberingDefinedInline = false) => ooxmlResolver$1.resolveRunProperties(params2, inlineRpr, resolvedPpr, isListNumber, numberingDefinedInline);
12878
+ function resolveParagraphProperties(params2, inlineProps, insideTable = false, overrideInlineStyleId = false, tableStyleId = null) {
12879
+ return ooxmlResolver$1.resolveParagraphProperties(
12880
+ params2,
12881
+ inlineProps,
12882
+ insideTable,
12883
+ overrideInlineStyleId,
12884
+ tableStyleId
12885
+ );
12886
+ }
12887
+ const combineProperties = (propertiesArray, fullOverrideProps = [], specialHandling = {}) => {
12888
+ return combineProperties$1(propertiesArray, { fullOverrideProps, specialHandling });
12444
12889
  };
12445
12890
  const combineRunProperties = (propertiesArray) => {
12446
12891
  return combineProperties(propertiesArray, ["fontFamily", "color"]);
@@ -12499,9 +12944,9 @@
12499
12944
  textStyleAttrs[key2] = `${spacing}pt`;
12500
12945
  break;
12501
12946
  case "fontFamily":
12502
- const fontFamily2 = getFontFamilyValue$1(value, docx);
12947
+ const fontFamily2 = resolveDocxFontFamily(value, docx, getToCssFontFamily());
12503
12948
  textStyleAttrs[key2] = fontFamily2;
12504
- const eastAsiaFamily = value["eastAsia"];
12949
+ const eastAsiaFamily = typeof value === "object" && value !== null ? value["eastAsia"] : void 0;
12505
12950
  if (eastAsiaFamily) {
12506
12951
  const eastAsiaCss = getFontFamilyValue$1({ "w:ascii": eastAsiaFamily }, docx);
12507
12952
  if (!fontFamily2 || eastAsiaCss !== textStyleAttrs.fontFamily) {
@@ -12756,11 +13201,11 @@
12756
13201
  }
12757
13202
  case "fontFamily": {
12758
13203
  if (!value) break;
12759
- const fontFamily2 = getFontFamilyValue$1(value, docx);
13204
+ const fontFamily2 = resolveDocxFontFamily(value, docx, getToCssFontFamily());
12760
13205
  if (fontFamily2) {
12761
13206
  css["font-family"] = fontFamily2;
12762
13207
  }
12763
- const eastAsiaFamily = value["eastAsia"];
13208
+ const eastAsiaFamily = typeof value === "object" && value !== null ? value["eastAsia"] : void 0;
12764
13209
  if (eastAsiaFamily) {
12765
13210
  const eastAsiaCss = getFontFamilyValue$1({ "w:ascii": eastAsiaFamily }, docx);
12766
13211
  if (eastAsiaCss && (!fontFamily2 || eastAsiaCss !== fontFamily2)) {
@@ -32519,7 +32964,8 @@ Please report this to https://github.com/markedjs/marked.`, e) {
32519
32964
  text2 = text2.replace(/^[ \t\n\r]+/, "").replace(/[ \t\n\r]+$/, "");
32520
32965
  }
32521
32966
  text2 = text2.replace(/\[\[sdspace\]\]/g, "");
32522
- if (xmlSpace !== "preserve" && typeof text2 === "string" && !text2.trim()) {
32967
+ const isWhitespaceOnly = /^[ \t\n\r]*$/.test(text2);
32968
+ if (xmlSpace !== "preserve" && isWhitespaceOnly) {
32523
32969
  return null;
32524
32970
  }
32525
32971
  } else if (!elements.length && encodedAttrs.xmlSpace === "preserve") {
@@ -35473,7 +35919,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35473
35919
  const result = additions.length ? [...existingRelationships, ...additions] : existingRelationships;
35474
35920
  return result;
35475
35921
  };
35476
- const FONT_FAMILY_FALLBACKS$1 = Object.freeze({
35922
+ const FONT_FAMILY_FALLBACKS = Object.freeze({
35477
35923
  swiss: "Arial, sans-serif",
35478
35924
  roman: "Times New Roman, serif",
35479
35925
  modern: "Courier New, monospace",
@@ -35482,7 +35928,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35482
35928
  system: "system-ui",
35483
35929
  auto: "sans-serif"
35484
35930
  });
35485
- const DEFAULT_GENERIC_FALLBACK$1 = "sans-serif";
35931
+ const DEFAULT_GENERIC_FALLBACK = "sans-serif";
35486
35932
  const DEFAULT_FONT_SIZE_PT = 10;
35487
35933
  const collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state }) => {
35488
35934
  if (!runProps?.elements?.length || !state) return;
@@ -35577,13 +36023,13 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35577
36023
  const fontEntry = SuperConverter.getFontTableEntry(docx, fontName);
35578
36024
  const family = fontEntry?.elements?.find((child) => child.name === "w:family")?.attributes?.["w:val"];
35579
36025
  if (!family) return null;
35580
- const mapped = FONT_FAMILY_FALLBACKS$1[family.toLowerCase()];
35581
- return mapped || DEFAULT_GENERIC_FALLBACK$1;
36026
+ const mapped = FONT_FAMILY_FALLBACKS[family.toLowerCase()];
36027
+ return mapped || DEFAULT_GENERIC_FALLBACK;
35582
36028
  }
35583
36029
  static toCssFontFamily(fontName, docx) {
35584
36030
  if (!fontName) return fontName;
35585
36031
  if (fontName.includes(",")) return fontName;
35586
- const fallback = SuperConverter.getFallbackFromFontTable(docx, fontName) || DEFAULT_GENERIC_FALLBACK$1;
36032
+ const fallback = SuperConverter.getFallbackFromFontTable(docx, fontName) || DEFAULT_GENERIC_FALLBACK;
35587
36033
  const normalizedFallbackParts = fallback.split(",").map((part) => part.trim().toLowerCase()).filter(Boolean);
35588
36034
  if (normalizedFallbackParts.includes(fontName.trim().toLowerCase())) {
35589
36035
  return fallback;
@@ -35919,7 +36365,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
35919
36365
  static getStoredSuperdocVersion(docx) {
35920
36366
  return SuperConverter.getStoredCustomProperty(docx, "SuperdocVersion");
35921
36367
  }
35922
- static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.2") {
36368
+ static setStoredSuperdocVersion(docx = this.convertedXml, version2 = "1.3.0-next.3") {
35923
36369
  return SuperConverter.setStoredCustomProperty(docx, "SuperdocVersion", version2, false);
35924
36370
  }
35925
36371
  /**
@@ -45269,15 +45715,19 @@ Please report this to https://github.com/markedjs/marked.`, e) {
45269
45715
  dispatchTransaction = editor.dispatch.bind(editor);
45270
45716
  }
45271
45717
  if (!dispatchTransaction) return false;
45272
- const handled = splitBlockPatch(state, (transaction) => {
45273
- dispatchTransaction(transaction);
45274
- });
45718
+ const handled = splitBlockPatch(
45719
+ state,
45720
+ (transaction) => {
45721
+ dispatchTransaction(transaction);
45722
+ },
45723
+ editor
45724
+ );
45275
45725
  if (handled) {
45276
45726
  tr.setMeta("preventDispatch", true);
45277
45727
  }
45278
45728
  return handled;
45279
45729
  };
45280
- function splitBlockPatch(state, dispatch) {
45730
+ function splitBlockPatch(state, dispatch, editor) {
45281
45731
  let { $from } = state.selection;
45282
45732
  if (state.selection instanceof NodeSelection && state.selection.node.isBlock) {
45283
45733
  if (!$from.parentOffset || !canSplit(state.doc, $from.pos)) return false;
@@ -45286,14 +45736,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
45286
45736
  }
45287
45737
  if (!$from.depth) return false;
45288
45738
  let types2 = [];
45289
- let splitDepth, deflt, atEnd = false, atStart = false;
45739
+ let splitDepth, deflt, paragraphAttrs = null, atEnd = false, atStart = false;
45290
45740
  for (let d2 = $from.depth; ; d2--) {
45291
45741
  let node2 = $from.node(d2);
45292
45742
  if (node2.isBlock) {
45293
45743
  atEnd = $from.end(d2) == $from.pos + ($from.depth - d2);
45294
45744
  atStart = $from.start(d2) == $from.pos - ($from.depth - d2);
45295
45745
  deflt = defaultBlockAt$1($from.node(d2 - 1).contentMatchAt($from.indexAfter(d2 - 1)));
45296
- types2.unshift(null);
45746
+ paragraphAttrs = { ...node2.attrs };
45747
+ types2.unshift({ type: deflt || node2.type, attrs: paragraphAttrs });
45297
45748
  splitDepth = d2;
45298
45749
  break;
45299
45750
  } else {
@@ -45306,7 +45757,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
45306
45757
  let splitPos = tr.mapping.map($from.pos);
45307
45758
  let can = canSplit(tr.doc, splitPos, types2.length, types2);
45308
45759
  if (!can) {
45309
- types2[0] = deflt ? { type: deflt } : null;
45760
+ types2[0] = deflt ? { type: deflt, attrs: paragraphAttrs } : null;
45310
45761
  can = canSplit(tr.doc, splitPos, types2.length, types2);
45311
45762
  }
45312
45763
  if (!can) return false;
@@ -45316,9 +45767,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
45316
45767
  if (deflt && $from.node(splitDepth - 1).canReplaceWith($first.index(), $first.index() + 1, deflt))
45317
45768
  tr.setNodeMarkup(tr.mapping.map($from.before(splitDepth)), deflt);
45318
45769
  }
45770
+ applyStyleMarks(state, tr, editor, paragraphAttrs);
45319
45771
  if (dispatch) dispatch(tr.scrollIntoView());
45320
45772
  return true;
45321
45773
  }
45774
+ function applyStyleMarks(state, tr, editor, paragraphAttrs) {
45775
+ const styleId = paragraphAttrs?.paragraphProperties?.styleId;
45776
+ if (!editor?.converter && !styleId) {
45777
+ return;
45778
+ }
45779
+ try {
45780
+ const params2 = { docx: editor?.converter?.convertedXml ?? {}, numbering: editor?.converter?.numbering ?? {} };
45781
+ const resolvedPpr = styleId ? { styleId } : {};
45782
+ const runProperties = styleId ? resolveRunProperties(params2, {}, resolvedPpr, false, false) : {};
45783
+ const markDefsFromStyle = styleId ? (
45784
+ /** @type {Array<{type: string, attrs: Record<string, unknown>}>} */
45785
+ encodeMarksFromRPr(runProperties, editor?.converter?.convertedXml ?? {})
45786
+ ) : [];
45787
+ const selectionMarks = state.selection?.$from?.marks ? state.selection.$from.marks() : [];
45788
+ const selectionMarkDefs = selectionMarks.map((mark2) => ({ type: mark2.type.name, attrs: mark2.attrs }));
45789
+ const markDefsToApply = selectionMarks.length ? selectionMarkDefs : markDefsFromStyle;
45790
+ const marksToApply = markDefsToApply.map((def2) => {
45791
+ const markType = state.schema.marks[def2.type];
45792
+ return markType ? markType.create(def2.attrs) : null;
45793
+ }).filter(Boolean);
45794
+ if (marksToApply.length > 0) {
45795
+ tr.ensureMarks(marksToApply);
45796
+ tr.setMeta("sdStyleMarks", markDefsToApply);
45797
+ }
45798
+ } catch {
45799
+ }
45800
+ }
45322
45801
  const splitRunAtCursor = () => (props) => {
45323
45802
  let { state, dispatch, tr } = props;
45324
45803
  const sel = state.selection;
@@ -46202,7 +46681,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
46202
46681
  }
46203
46682
  return true;
46204
46683
  };
46205
- const isPlainObject$7 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
46684
+ const isPlainObject$6 = (value) => Boolean(value) && typeof value === "object" && !Array.isArray(value);
46206
46685
  const assignNestedValue = (target, path2, value) => {
46207
46686
  if (!path2.includes(".")) {
46208
46687
  target[path2] = value;
@@ -46216,7 +46695,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
46216
46695
  if (isLast) {
46217
46696
  current[part] = value;
46218
46697
  } else {
46219
- if (!isPlainObject$7(current[part])) {
46698
+ if (!isPlainObject$6(current[part])) {
46220
46699
  current[part] = {};
46221
46700
  }
46222
46701
  current = current[part];
@@ -52665,7 +53144,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
52665
53144
  const toRawType = (value) => {
52666
53145
  return toTypeString(value).slice(8, -1);
52667
53146
  };
52668
- const isPlainObject$6 = (val) => toTypeString(val) === "[object Object]";
53147
+ const isPlainObject$5 = (val) => toTypeString(val) === "[object Object]";
52669
53148
  const isIntegerKey = (key2) => isString(key2) && key2 !== "NaN" && key2[0] !== "-" && "" + parseInt(key2, 10) === key2;
52670
53149
  const isReservedProp = /* @__PURE__ */ makeMap(
52671
53150
  // the leading comma is intentional so empty string "" is also included
@@ -52715,7 +53194,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
52715
53194
  const n = parseFloat(val);
52716
53195
  return isNaN(n) ? val : n;
52717
53196
  };
52718
- const toNumber$1 = (val) => {
53197
+ const toNumber = (val) => {
52719
53198
  const n = isString(val) ? Number(val) : NaN;
52720
53199
  return isNaN(n) ? val : n;
52721
53200
  };
@@ -52814,7 +53293,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
52814
53293
  };
52815
53294
  } else if (isSymbol$1(val)) {
52816
53295
  return stringifySymbol(val);
52817
- } else if (isObject$2(val) && !isArray$1(val) && !isPlainObject$6(val)) {
53296
+ } else if (isObject$2(val) && !isArray$1(val) && !isPlainObject$5(val)) {
52818
53297
  return String(val);
52819
53298
  }
52820
53299
  return val;
@@ -54431,7 +54910,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
54431
54910
  value.forEach((v2) => {
54432
54911
  traverse(v2, depth, seen);
54433
54912
  });
54434
- } else if (isPlainObject$6(value)) {
54913
+ } else if (isPlainObject$5(value)) {
54435
54914
  for (const key2 in value) {
54436
54915
  traverse(value[key2], depth, seen);
54437
54916
  }
@@ -59660,7 +60139,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
59660
60139
  }
59661
60140
  }
59662
60141
  function NumberOf(val) {
59663
- const res = toNumber$1(val);
60142
+ const res = toNumber(val);
59664
60143
  return res;
59665
60144
  }
59666
60145
  function addTransitionClass(el, cls) {
@@ -61541,7 +62020,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61541
62020
  return false;
61542
62021
  }
61543
62022
  };
61544
- const summaryVersion = "1.3.0-next.2";
62023
+ const summaryVersion = "1.3.0-next.3";
61545
62024
  const nodeKeys = ["group", "content", "marks", "inline", "atom", "defining", "code", "tableRole", "summary"];
61546
62025
  const markKeys = ["group", "inclusive", "excludes", "spanning", "code"];
61547
62026
  function mapAttributes(attrs) {
@@ -64175,7 +64654,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
64175
64654
  * Process collaboration migrations
64176
64655
  */
64177
64656
  processCollaborationMigrations() {
64178
- console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.2");
64657
+ console.debug("[checkVersionMigrations] Current editor version", "1.3.0-next.3");
64179
64658
  if (!this.options.ydoc) return;
64180
64659
  const metaMap = this.options.ydoc.getMap("meta");
64181
64660
  let docVersion = metaMap.get("version");
@@ -69751,39 +70230,6 @@ ${l}
69751
70230
  right: borderValueToSpec(isLastCol ? tableBorders?.right : null)
69752
70231
  };
69753
70232
  };
69754
- const FONT_FAMILY_FALLBACKS = Object.freeze({
69755
- swiss: "Arial, sans-serif",
69756
- roman: "Times New Roman, serif",
69757
- modern: "Courier New, monospace",
69758
- script: "cursive",
69759
- decorative: "fantasy",
69760
- system: "system-ui",
69761
- auto: "sans-serif"
69762
- });
69763
- const DEFAULT_GENERIC_FALLBACK = "sans-serif";
69764
- const normalizeParts = (value) => (value || "").split(",").map((part) => part.trim()).filter(Boolean);
69765
- function mapWordFamilyFallback(wordFamily) {
69766
- if (!wordFamily) return DEFAULT_GENERIC_FALLBACK;
69767
- const mapped = FONT_FAMILY_FALLBACKS[wordFamily.toLowerCase()];
69768
- return mapped || DEFAULT_GENERIC_FALLBACK;
69769
- }
69770
- function toCssFontFamily(fontName, options = {}) {
69771
- if (!fontName || typeof fontName !== "string") return fontName;
69772
- const trimmed = fontName.trim();
69773
- if (!trimmed || trimmed.includes(",")) return trimmed;
69774
- const { fallback, wordFamily } = options;
69775
- const fallbackValue = fallback ?? (wordFamily ? mapWordFamilyFallback(wordFamily) : void 0) ?? DEFAULT_GENERIC_FALLBACK;
69776
- const fallbackParts = normalizeParts(fallbackValue);
69777
- if (fallbackParts.length === 0) {
69778
- return trimmed;
69779
- }
69780
- const normalizedName = trimmed.toLowerCase();
69781
- const includesName = fallbackParts.some((part) => part.toLowerCase() === normalizedName);
69782
- if (includesName) {
69783
- return fallbackParts.join(", ");
69784
- }
69785
- return [trimmed, ...fallbackParts].join(", ");
69786
- }
69787
70233
  const LIST_MARKER_GAP$3 = 8;
69788
70234
  function renderListMarker(params2) {
69789
70235
  const { doc: doc2, lineEl, markerLayout, markerMeasure, indentLeftPx } = params2;
@@ -86335,7 +86781,7 @@ ${l}
86335
86781
  return px / PX_PER_PT;
86336
86782
  };
86337
86783
  const isFiniteNumber = (value) => typeof value === "number" && Number.isFinite(value);
86338
- const isPlainObject$5 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
86784
+ const isPlainObject$4 = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
86339
86785
  const normalizePrefix = (value) => {
86340
86786
  if (!value) return "";
86341
86787
  return String(value);
@@ -86397,7 +86843,7 @@ ${l}
86397
86843
  }
86398
86844
  return void 0;
86399
86845
  }
86400
- const toBoolean$3 = (value) => {
86846
+ const toBoolean$2 = (value) => {
86401
86847
  if (typeof value === "boolean") return value;
86402
86848
  if (typeof value === "string") {
86403
86849
  const v2 = value.trim().toLowerCase();
@@ -86688,7 +87134,7 @@ ${l}
86688
87134
  });
86689
87135
  }
86690
87136
  function isGradientFill(value) {
86691
- if (!isPlainObject$5(value)) return false;
87137
+ if (!isPlainObject$4(value)) return false;
86692
87138
  if (value.type !== "gradient") return false;
86693
87139
  const gradientType = value.gradientType;
86694
87140
  if (gradientType !== "linear" && gradientType !== "radial") return false;
@@ -86699,12 +87145,12 @@ ${l}
86699
87145
  }
86700
87146
  if (!Array.isArray(value.stops) || value.stops.length === 0) return false;
86701
87147
  return value.stops.every((stop) => {
86702
- if (!isPlainObject$5(stop)) return false;
87148
+ if (!isPlainObject$4(stop)) return false;
86703
87149
  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));
86704
87150
  });
86705
87151
  }
86706
87152
  function isSolidFillWithAlpha(value) {
86707
- return isPlainObject$5(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
87153
+ return isPlainObject$4(value) && value.type === "solidWithAlpha" && typeof value.color === "string" && typeof value.alpha === "number";
86708
87154
  }
86709
87155
  function normalizeFillColor(value) {
86710
87156
  if (value === null) return null;
@@ -86719,10 +87165,10 @@ ${l}
86719
87165
  return void 0;
86720
87166
  }
86721
87167
  function normalizeTextContent(value) {
86722
- if (!isPlainObject$5(value)) return void 0;
87168
+ if (!isPlainObject$4(value)) return void 0;
86723
87169
  if (!Array.isArray(value.parts)) return void 0;
86724
87170
  if (value.parts.length === 0) return void 0;
86725
- const validParts = value.parts.filter((p2) => isPlainObject$5(p2) && typeof p2.text === "string");
87171
+ const validParts = value.parts.filter((p2) => isPlainObject$4(p2) && typeof p2.text === "string");
86726
87172
  if (validParts.length === 0) return void 0;
86727
87173
  const result = {
86728
87174
  parts: validParts
@@ -86740,7 +87186,7 @@ ${l}
86740
87186
  return void 0;
86741
87187
  }
86742
87188
  function normalizeTextInsets(value) {
86743
- if (!isPlainObject$5(value)) return void 0;
87189
+ if (!isPlainObject$4(value)) return void 0;
86744
87190
  const top2 = pickNumber(value.top);
86745
87191
  const right2 = pickNumber(value.right);
86746
87192
  const bottom2 = pickNumber(value.bottom);
@@ -86752,7 +87198,7 @@ ${l}
86752
87198
  }
86753
87199
  const OOXML_Z_INDEX_BASE = 251658240;
86754
87200
  function normalizeZIndex(originalAttributes) {
86755
- if (!isPlainObject$5(originalAttributes)) return void 0;
87201
+ if (!isPlainObject$4(originalAttributes)) return void 0;
86756
87202
  const relativeHeight = originalAttributes.relativeHeight;
86757
87203
  if (typeof relativeHeight !== "number") return void 0;
86758
87204
  return Math.max(0, relativeHeight - OOXML_Z_INDEX_BASE);
@@ -87906,321 +88352,6 @@ ${l}
87906
88352
  }
87907
88353
  return adjusted;
87908
88354
  };
87909
- const sdtMetadataCache = /* @__PURE__ */ new Map();
87910
- function resolveStyle(node2, context, options = {}) {
87911
- let paragraph2 = createDefaultParagraph();
87912
- let character = createDefaultCharacter(context);
87913
- let numbering;
87914
- const chain = resolveStyleChain(node2.styleId, context.styles);
87915
- for (const style2 of chain) {
87916
- paragraph2 = mergeParagraph(paragraph2, style2.paragraph);
87917
- character = mergeCharacter(character, style2.character);
87918
- if (!numbering && style2.numbering) {
87919
- numbering = resolveNumbering(style2.numbering.numId, style2.numbering.level, context);
87920
- }
87921
- }
87922
- paragraph2 = mergeParagraph(paragraph2, node2.paragraphProps);
87923
- character = mergeCharacter(character, node2.characterProps);
87924
- if (node2.numbering) {
87925
- numbering = resolveNumbering(node2.numbering.numId, node2.numbering.level, context);
87926
- }
87927
- const sdt = options?.sdt ? resolveSdtMetadata(options.sdt) : void 0;
87928
- return {
87929
- paragraph: paragraph2,
87930
- character,
87931
- numbering,
87932
- sdt
87933
- };
87934
- }
87935
- function resolveNumbering(numId, level, context) {
87936
- const def2 = context.numbering?.[numId];
87937
- if (!def2) return void 0;
87938
- const levelDef = def2.levels.find((entry) => entry.level === level) ?? def2.levels[level];
87939
- if (!levelDef) return void 0;
87940
- return {
87941
- numId,
87942
- level,
87943
- indent: {
87944
- left: levelDef.indent?.left,
87945
- hanging: levelDef.indent?.hanging
87946
- },
87947
- format: levelDef.format ?? "decimal",
87948
- text: levelDef.text ?? "%1.",
87949
- start: levelDef.start ?? 1
87950
- };
87951
- }
87952
- function resolveSdtMetadata(input2) {
87953
- if (!input2) return void 0;
87954
- const { nodeType, attrs, cacheKey: explicitKey } = input2;
87955
- if (!nodeType) return void 0;
87956
- const normalizedAttrs = isPlainObject$4(attrs) ? attrs : {};
87957
- const cacheKey = buildSdtCacheKey(nodeType, normalizedAttrs, explicitKey);
87958
- if (cacheKey && sdtMetadataCache.has(cacheKey)) {
87959
- return sdtMetadataCache.get(cacheKey);
87960
- }
87961
- let metadata;
87962
- switch (nodeType) {
87963
- case "fieldAnnotation":
87964
- metadata = normalizeFieldAnnotationMetadata(normalizedAttrs);
87965
- break;
87966
- case "structuredContent":
87967
- case "structuredContentBlock":
87968
- metadata = normalizeStructuredContentMetadata(nodeType, normalizedAttrs);
87969
- break;
87970
- case "documentSection":
87971
- metadata = normalizeDocumentSectionMetadata(normalizedAttrs);
87972
- break;
87973
- case "docPartObject":
87974
- metadata = normalizeDocPartMetadata(normalizedAttrs);
87975
- break;
87976
- }
87977
- if (metadata && cacheKey) {
87978
- sdtMetadataCache.set(cacheKey, metadata);
87979
- }
87980
- return metadata;
87981
- }
87982
- function createDefaultParagraph(_context) {
87983
- return {
87984
- alignment: "left",
87985
- spacing: {
87986
- before: 0,
87987
- after: 0,
87988
- line: 12,
87989
- lineRule: "auto"
87990
- },
87991
- indent: {
87992
- left: 0,
87993
- right: 0,
87994
- firstLine: 0,
87995
- hanging: 0
87996
- },
87997
- tabs: []
87998
- };
87999
- }
88000
- function createDefaultCharacter(context) {
88001
- const baseFont = context.defaults?.paragraphFont ?? "Calibri";
88002
- const fallback = context.defaults?.paragraphFontFallback;
88003
- const wordFamily = context.defaults?.paragraphFontFamily;
88004
- const resolvedFamily = toCssFontFamily(baseFont, { fallback, wordFamily }) ?? baseFont;
88005
- return {
88006
- font: {
88007
- family: resolvedFamily,
88008
- size: context.defaults?.fontSize ?? 11,
88009
- weight: 400,
88010
- italic: false
88011
- },
88012
- color: "#000000"
88013
- };
88014
- }
88015
- function resolveStyleChain(styleId, styles) {
88016
- if (!styleId || !styles) return [];
88017
- const result = [];
88018
- const visited = /* @__PURE__ */ new Set();
88019
- let current = styles[styleId];
88020
- while (current && !visited.has(current.id)) {
88021
- result.unshift(current);
88022
- visited.add(current.id);
88023
- current = current.basedOn ? styles[current.basedOn] : void 0;
88024
- }
88025
- return result;
88026
- }
88027
- function mergeParagraph(base2, overrides) {
88028
- if (!overrides) return base2;
88029
- return {
88030
- ...base2,
88031
- alignment: overrides.alignment ?? base2.alignment,
88032
- spacing: overrides.spacing ? { ...base2.spacing, ...overrides.spacing } : base2.spacing,
88033
- indent: overrides.indent ? { ...base2.indent, ...overrides.indent } : base2.indent,
88034
- borders: overrides.borders ? { ...base2.borders, ...overrides.borders } : base2.borders,
88035
- shading: overrides.shading ?? base2.shading,
88036
- tabs: overrides.tabs ?? base2.tabs
88037
- };
88038
- }
88039
- function mergeCharacter(base2, overrides) {
88040
- if (!overrides) return base2;
88041
- return {
88042
- ...base2,
88043
- font: overrides.font ? { ...base2.font, ...overrides.font } : base2.font,
88044
- color: overrides.color ?? base2.color,
88045
- underline: overrides.underline ?? base2.underline,
88046
- strike: overrides.strike ?? base2.strike,
88047
- highlight: overrides.highlight ?? base2.highlight,
88048
- letterSpacing: overrides.letterSpacing ?? base2.letterSpacing
88049
- };
88050
- }
88051
- function normalizeFieldAnnotationMetadata(attrs) {
88052
- const fieldId = toOptionalString(attrs.fieldId) ?? "";
88053
- const formatting = extractFormatting(attrs);
88054
- const size2 = normalizeSize(attrs.size);
88055
- const extras = isPlainObject$4(attrs.extras) ? attrs.extras : null;
88056
- const marks = isPlainObject$4(attrs.marks) ? attrs.marks : void 0;
88057
- return {
88058
- type: "fieldAnnotation",
88059
- fieldId,
88060
- variant: normalizeFieldAnnotationVariant(attrs.type),
88061
- fieldType: toOptionalString(attrs.fieldType),
88062
- displayLabel: toOptionalString(attrs.displayLabel),
88063
- defaultDisplayLabel: toOptionalString(attrs.defaultDisplayLabel),
88064
- alias: toOptionalString(attrs.alias),
88065
- fieldColor: normalizeColorValue(attrs.fieldColor),
88066
- borderColor: normalizeColorValue(attrs.borderColor),
88067
- highlighted: toBoolean$2(attrs.highlighted, true),
88068
- fontFamily: toNullableString(attrs.fontFamily),
88069
- fontSize: normalizeFontSize(attrs.fontSize),
88070
- textColor: normalizeColorValue(attrs.textColor) ?? null,
88071
- textHighlight: normalizeColorValue(attrs.textHighlight) ?? null,
88072
- linkUrl: toNullableString(attrs.linkUrl),
88073
- imageSrc: toNullableString(attrs.imageSrc),
88074
- rawHtml: attrs.rawHtml ?? void 0,
88075
- size: size2 ?? null,
88076
- extras,
88077
- multipleImage: toBoolean$2(attrs.multipleImage, false),
88078
- hash: toOptionalString(attrs.hash) ?? null,
88079
- generatorIndex: toNumber(attrs.generatorIndex),
88080
- sdtId: toOptionalString(attrs.sdtId) ?? null,
88081
- hidden: toBoolean$2(attrs.hidden, false),
88082
- visibility: normalizeVisibility(attrs.visibility),
88083
- isLocked: toBoolean$2(attrs.isLocked, false),
88084
- formatting,
88085
- marks
88086
- };
88087
- }
88088
- function normalizeStructuredContentMetadata(nodeType, attrs) {
88089
- return {
88090
- type: "structuredContent",
88091
- scope: nodeType === "structuredContentBlock" ? "block" : "inline",
88092
- id: toNullableString(attrs.id),
88093
- tag: toOptionalString(attrs.tag),
88094
- alias: toOptionalString(attrs.alias),
88095
- sdtPr: attrs.sdtPr
88096
- };
88097
- }
88098
- function normalizeDocumentSectionMetadata(attrs) {
88099
- return {
88100
- type: "documentSection",
88101
- id: toNullableString(attrs.id),
88102
- title: toOptionalString(attrs.title) ?? null,
88103
- description: toOptionalString(attrs.description) ?? null,
88104
- sectionType: toOptionalString(attrs.sectionType) ?? null,
88105
- isLocked: toBoolean$2(attrs.isLocked, false),
88106
- sdBlockId: toNullableString(attrs.sdBlockId)
88107
- };
88108
- }
88109
- function normalizeDocPartMetadata(attrs) {
88110
- return {
88111
- type: "docPartObject",
88112
- gallery: toOptionalString(attrs.docPartGallery ?? attrs.gallery) ?? null,
88113
- // Source uniqueId from attrs.id (PM adapter uses getDocPartObjectId which extracts attrs.id)
88114
- // Fall back to attrs.uniqueId for compatibility
88115
- uniqueId: toOptionalString(attrs.id ?? attrs.uniqueId) ?? null,
88116
- alias: toOptionalString(attrs.alias) ?? null,
88117
- instruction: toOptionalString(attrs.instruction) ?? null
88118
- };
88119
- }
88120
- function isPlainObject$4(value) {
88121
- return !!value && typeof value === "object" && !Array.isArray(value);
88122
- }
88123
- function toOptionalString(value) {
88124
- if (value == null) return void 0;
88125
- if (typeof value === "string") {
88126
- const trimmed = value.trim();
88127
- return trimmed.length ? trimmed : void 0;
88128
- }
88129
- return String(value);
88130
- }
88131
- function toNullableString(value) {
88132
- const str = toOptionalString(value);
88133
- return str ?? null;
88134
- }
88135
- function toBoolean$2(value, fallback) {
88136
- if (typeof value === "boolean") return value;
88137
- if (typeof value === "string") {
88138
- const lower = value.toLowerCase();
88139
- if (lower === "true") return true;
88140
- if (lower === "false") return false;
88141
- }
88142
- if (value == null) return fallback;
88143
- return Boolean(value);
88144
- }
88145
- function normalizeVisibility(value) {
88146
- if (typeof value !== "string") return void 0;
88147
- const normalized = value.toLowerCase();
88148
- if (normalized === "visible" || normalized === "hidden") {
88149
- return normalized;
88150
- }
88151
- return void 0;
88152
- }
88153
- function normalizeColorValue(value) {
88154
- if (typeof value !== "string") return void 0;
88155
- const trimmed = value.trim();
88156
- if (!trimmed || trimmed.toLowerCase() === "none") return void 0;
88157
- return trimmed;
88158
- }
88159
- function normalizeFontSize(value) {
88160
- if (value == null) return null;
88161
- if (typeof value === "number") {
88162
- return Number.isFinite(value) ? value : null;
88163
- }
88164
- if (typeof value === "string") {
88165
- const trimmed = value.trim();
88166
- return trimmed.length ? trimmed : null;
88167
- }
88168
- return null;
88169
- }
88170
- function toNumber(value) {
88171
- if (typeof value === "number") {
88172
- return Number.isFinite(value) ? value : null;
88173
- }
88174
- if (typeof value === "string") {
88175
- const parsed = parseFloat(value);
88176
- return Number.isFinite(parsed) ? parsed : null;
88177
- }
88178
- return null;
88179
- }
88180
- function normalizeSize(value) {
88181
- if (!isPlainObject$4(value)) return null;
88182
- const obj = value;
88183
- const width = toNumber(obj.width);
88184
- const height = toNumber(obj.height);
88185
- if (width == null && height == null) return null;
88186
- const result = {};
88187
- if (width != null) result.width = width;
88188
- if (height != null) result.height = height;
88189
- return result;
88190
- }
88191
- function normalizeFieldAnnotationVariant(value) {
88192
- if (typeof value !== "string") return void 0;
88193
- const normalized = value.toLowerCase();
88194
- if (normalized === "text" || normalized === "image" || normalized === "signature" || normalized === "checkbox" || normalized === "html" || normalized === "link") {
88195
- return normalized;
88196
- }
88197
- return void 0;
88198
- }
88199
- function extractFormatting(attrs) {
88200
- const bold = toBoolean$2(attrs.bold, false);
88201
- const italic = toBoolean$2(attrs.italic, false);
88202
- const underline = toBoolean$2(attrs.underline, false);
88203
- const formatting = {};
88204
- if (bold) formatting.bold = true;
88205
- if (italic) formatting.italic = true;
88206
- if (underline) formatting.underline = true;
88207
- return Object.keys(formatting).length ? formatting : void 0;
88208
- }
88209
- function buildSdtCacheKey(nodeType, attrs, explicitKey) {
88210
- const provided = toOptionalString(explicitKey);
88211
- if (provided) {
88212
- return `${nodeType}:${provided}`;
88213
- }
88214
- const hash2 = toOptionalString(attrs.hash);
88215
- if (hash2) {
88216
- return `${nodeType}:${hash2}`;
88217
- }
88218
- const id = toOptionalString(attrs.id);
88219
- if (id) {
88220
- return `${nodeType}:${id}`;
88221
- }
88222
- return void 0;
88223
- }
88224
88355
  const DEFAULT_LIST_HANGING_PX = 18;
88225
88356
  const LIST_MARKER_GAP = 8;
88226
88357
  const DEFAULT_BULLET_GLYPH = "•";
@@ -88780,6 +88911,7 @@ ${l}
88780
88911
  definitions: {},
88781
88912
  abstracts: {}
88782
88913
  };
88914
+ const ooxmlResolver = createOoxmlResolver({ pPr: translator$14, rPr: translator$1O });
88783
88915
  const hydrateParagraphStyleAttrs = (para, context, preResolved) => {
88784
88916
  if (!hasParagraphStyleContext(context)) {
88785
88917
  return null;
@@ -88807,7 +88939,7 @@ ${l}
88807
88939
  // should still get docDefaults spacing from style resolution
88808
88940
  numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
88809
88941
  };
88810
- const resolved = resolveParagraphProperties(resolverParams, inlineProps);
88942
+ const resolved = ooxmlResolver.resolveParagraphProperties(resolverParams, inlineProps);
88811
88943
  if (!resolved) {
88812
88944
  return null;
88813
88945
  }
@@ -88862,6 +88994,138 @@ ${l}
88862
88994
  }
88863
88995
  return { ...value };
88864
88996
  };
88997
+ const buildCharacterStyleHydration = (resolved, docx) => {
88998
+ const fontFamily2 = extractFontFamily(resolved.fontFamily, docx);
88999
+ const fontSize2 = typeof resolved.fontSize === "number" ? resolved.fontSize : 20;
89000
+ const color2 = extractColorValue(resolved.color);
89001
+ const bold = normalizeBooleanProp(resolved.bold);
89002
+ const italic = normalizeBooleanProp(resolved.italic);
89003
+ const strike = normalizeBooleanProp(resolved.strike);
89004
+ const underline = extractUnderline(resolved.underline);
89005
+ const letterSpacing = typeof resolved.letterSpacing === "number" ? resolved.letterSpacing : void 0;
89006
+ return {
89007
+ fontFamily: fontFamily2,
89008
+ fontSize: fontSize2,
89009
+ color: color2,
89010
+ bold,
89011
+ italic,
89012
+ strike,
89013
+ underline,
89014
+ letterSpacing
89015
+ };
89016
+ };
89017
+ const hydrateCharacterStyleAttrs = (para, context, resolvedPpr) => {
89018
+ if (!hasParagraphStyleContext(context)) {
89019
+ return null;
89020
+ }
89021
+ const attrs = para.attrs ?? {};
89022
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
89023
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
89024
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
89025
+ const inlineRpr = {};
89026
+ const pprForChain = resolvedPpr ?? { styleId };
89027
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
89028
+ if (numberingProps != null) {
89029
+ pprForChain.numberingProperties = numberingProps;
89030
+ }
89031
+ const resolverParams = {
89032
+ docx: context.docx,
89033
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
89034
+ };
89035
+ let resolved = null;
89036
+ try {
89037
+ resolved = ooxmlResolver.resolveRunProperties(
89038
+ resolverParams,
89039
+ inlineRpr,
89040
+ pprForChain,
89041
+ false,
89042
+ // not list number marker
89043
+ false
89044
+ // not numberingDefinedInline
89045
+ );
89046
+ if (!resolved || typeof resolved !== "object") {
89047
+ return null;
89048
+ }
89049
+ } catch {
89050
+ return null;
89051
+ }
89052
+ return buildCharacterStyleHydration(resolved, context.docx);
89053
+ };
89054
+ const hydrateMarkerStyleAttrs = (para, context, resolvedPpr) => {
89055
+ if (!hasParagraphStyleContext(context)) {
89056
+ return null;
89057
+ }
89058
+ const attrs = para.attrs ?? {};
89059
+ const paragraphProps = typeof attrs.paragraphProperties === "object" && attrs.paragraphProperties !== null ? attrs.paragraphProperties : {};
89060
+ const styleIdSource = attrs.styleId ?? paragraphProps.styleId;
89061
+ const styleId = typeof styleIdSource === "string" && styleIdSource.trim() ? styleIdSource : null;
89062
+ const inlineRpr = {};
89063
+ const numberingProps = attrs.numberingProperties ?? paragraphProps.numberingProperties;
89064
+ const numberingDefinedInline = numberingProps?.numId != null;
89065
+ const pprForChain = resolvedPpr ? { ...resolvedPpr } : { styleId };
89066
+ if (styleId && !pprForChain.styleId) {
89067
+ pprForChain.styleId = styleId;
89068
+ }
89069
+ if (numberingProps != null) {
89070
+ pprForChain.numberingProperties = numberingProps;
89071
+ }
89072
+ const resolverParams = {
89073
+ docx: context.docx,
89074
+ numbering: context.numbering ?? EMPTY_NUMBERING_CONTEXT
89075
+ };
89076
+ let resolved = null;
89077
+ try {
89078
+ resolved = ooxmlResolver.resolveRunProperties(
89079
+ resolverParams,
89080
+ inlineRpr,
89081
+ pprForChain,
89082
+ true,
89083
+ numberingDefinedInline
89084
+ );
89085
+ if (!resolved || typeof resolved !== "object") {
89086
+ return null;
89087
+ }
89088
+ } catch {
89089
+ return null;
89090
+ }
89091
+ return buildCharacterStyleHydration(resolved, context.docx);
89092
+ };
89093
+ function extractFontFamily(fontFamily2, docx) {
89094
+ if (!fontFamily2 || typeof fontFamily2 !== "object") return void 0;
89095
+ const toCssFontFamily2 = SuperConverter.toCssFontFamily;
89096
+ const resolved = resolveDocxFontFamily(fontFamily2, docx ?? null, toCssFontFamily2);
89097
+ return resolved ?? void 0;
89098
+ }
89099
+ function extractColorValue(color2) {
89100
+ if (!color2 || typeof color2 !== "object") return void 0;
89101
+ const c2 = color2;
89102
+ const val = c2.val;
89103
+ if (typeof val !== "string") return void 0;
89104
+ if (!val || val.toLowerCase() === "auto") return void 0;
89105
+ return val;
89106
+ }
89107
+ function normalizeBooleanProp(value) {
89108
+ if (value == null) return void 0;
89109
+ if (typeof value === "boolean") return value;
89110
+ if (typeof value === "number") return value !== 0;
89111
+ if (typeof value === "string") {
89112
+ const lower = value.toLowerCase();
89113
+ if (lower === "0" || lower === "false" || lower === "off") return false;
89114
+ if (lower === "1" || lower === "true" || lower === "on" || lower === "") return true;
89115
+ }
89116
+ return Boolean(value);
89117
+ }
89118
+ function extractUnderline(underline) {
89119
+ if (!underline || typeof underline !== "object") return void 0;
89120
+ const u = underline;
89121
+ const type = u["w:val"] ?? u.type ?? u.val;
89122
+ if (typeof type !== "string" || type === "none") return void 0;
89123
+ const color2 = u["w:color"] ?? u.color;
89124
+ return {
89125
+ type,
89126
+ color: typeof color2 === "string" ? color2 : void 0
89127
+ };
89128
+ }
88865
89129
  const { resolveSpacingIndent } = Engines;
88866
89130
  const DEFAULT_DECIMAL_SEPARATOR$2 = ".";
88867
89131
  const isValidNumberingId = (numId) => {
@@ -89377,7 +89641,7 @@ ${l}
89377
89641
  }
89378
89642
  return dropCapRun;
89379
89643
  };
89380
- const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, _paragraphNode) => {
89644
+ const computeWordLayoutForParagraph = (paragraphAttrs, numberingProps, styleContext, paragraphNode, converterContext, resolvedPpr) => {
89381
89645
  if (numberingProps === null) {
89382
89646
  return null;
89383
89647
  }
@@ -89415,7 +89679,23 @@ ${l}
89415
89679
  spacing: {}
89416
89680
  }
89417
89681
  };
89418
- let markerRun = numberingProps?.resolvedMarkerRpr;
89682
+ let markerRun;
89683
+ const markerHydration = paragraphNode && converterContext ? hydrateMarkerStyleAttrs(paragraphNode, converterContext, resolvedPpr) : null;
89684
+ if (markerHydration) {
89685
+ const resolvedColor = markerHydration.color ? `#${markerHydration.color.replace("#", "")}` : void 0;
89686
+ markerRun = {
89687
+ fontFamily: markerHydration.fontFamily ?? "Times New Roman",
89688
+ fontSize: markerHydration.fontSize / 2,
89689
+ // half-points to points
89690
+ bold: markerHydration.bold,
89691
+ italic: markerHydration.italic,
89692
+ color: resolvedColor,
89693
+ letterSpacing: markerHydration.letterSpacing != null ? twipsToPx$1(markerHydration.letterSpacing) : void 0
89694
+ };
89695
+ }
89696
+ if (!markerRun) {
89697
+ markerRun = numberingProps?.resolvedMarkerRpr;
89698
+ }
89419
89699
  if (!markerRun) {
89420
89700
  const { character: characterStyle } = resolveStyle({ styleId: paragraphAttrs.styleId }, styleContext);
89421
89701
  if (characterStyle) {
@@ -89736,7 +90016,12 @@ ${l}
89736
90016
  const numId = numberingProps.numId;
89737
90017
  const ilvl = Number.isFinite(numberingProps.ilvl) ? Math.max(0, Math.floor(Number(numberingProps.ilvl))) : 0;
89738
90018
  const numericNumId = typeof numId === "number" ? numId : void 0;
89739
- const resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
90019
+ let resolvedLevel;
90020
+ try {
90021
+ resolvedLevel = resolveNumberingFromContext(numId, ilvl, converterContext?.numbering);
90022
+ } catch (error) {
90023
+ resolvedLevel = void 0;
90024
+ }
89740
90025
  if (resolvedLevel) {
89741
90026
  if (resolvedLevel.format && numberingProps.format == null) {
89742
90027
  numberingProps.format = resolvedLevel.format;
@@ -89797,7 +90082,19 @@ ${l}
89797
90082
  }
89798
90083
  }
89799
90084
  }
89800
- let wordLayout = computeWordLayoutForParagraph(paragraphAttrs, enrichedNumberingProps, styleContext);
90085
+ let wordLayout = null;
90086
+ try {
90087
+ wordLayout = computeWordLayoutForParagraph(
90088
+ paragraphAttrs,
90089
+ enrichedNumberingProps,
90090
+ styleContext,
90091
+ para,
90092
+ converterContext,
90093
+ hydrated?.resolved
90094
+ );
90095
+ } catch (error) {
90096
+ wordLayout = null;
90097
+ }
89801
90098
  if (!wordLayout && enrichedNumberingProps.resolvedLevelIndent) {
89802
90099
  const resolvedIndentPx = convertIndentTwipsToPx(enrichedNumberingProps.resolvedLevelIndent);
89803
90100
  const baseIndent = resolvedIndentPx ?? enrichedNumberingProps.resolvedLevelIndent;
@@ -90342,7 +90639,7 @@ ${l}
90342
90639
  const H_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["left", "center", "right"]);
90343
90640
  const V_ALIGN_VALUES$1 = /* @__PURE__ */ new Set(["top", "center", "bottom"]);
90344
90641
  const getAttrs$1 = (node2) => {
90345
- return isPlainObject$5(node2.attrs) ? node2.attrs : {};
90642
+ return isPlainObject$4(node2.attrs) ? node2.attrs : {};
90346
90643
  };
90347
90644
  const normalizeWrapType$1 = (value) => {
90348
90645
  if (typeof value !== "string") return void 0;
@@ -90365,7 +90662,7 @@ ${l}
90365
90662
  return polygon.length > 0 ? polygon : void 0;
90366
90663
  };
90367
90664
  const normalizeWrap$2 = (value) => {
90368
- if (!isPlainObject$5(value)) {
90665
+ if (!isPlainObject$4(value)) {
90369
90666
  return void 0;
90370
90667
  }
90371
90668
  const type = normalizeWrapType$1(value.type);
@@ -90373,7 +90670,7 @@ ${l}
90373
90670
  return void 0;
90374
90671
  }
90375
90672
  const wrap2 = { type };
90376
- const attrs = isPlainObject$5(value.attrs) ? value.attrs : {};
90673
+ const attrs = isPlainObject$4(value.attrs) ? value.attrs : {};
90377
90674
  const wrapText = normalizeWrapText$1(attrs.wrapText);
90378
90675
  if (wrapText) {
90379
90676
  wrap2.wrapText = wrapText;
@@ -90390,7 +90687,7 @@ ${l}
90390
90687
  if (polygon) {
90391
90688
  wrap2.polygon = polygon;
90392
90689
  }
90393
- const behindDoc = toBoolean$3(attrs.behindDoc);
90690
+ const behindDoc = toBoolean$2(attrs.behindDoc);
90394
90691
  if (behindDoc != null) {
90395
90692
  wrap2.behindDoc = behindDoc;
90396
90693
  }
@@ -90405,10 +90702,10 @@ ${l}
90405
90702
  return allowed.has(value) ? value : void 0;
90406
90703
  };
90407
90704
  const normalizeAnchorData$1 = (value, attrs, wrapBehindDoc) => {
90408
- const raw = isPlainObject$5(value) ? value : void 0;
90409
- const marginOffset = isPlainObject$5(attrs.marginOffset) ? attrs.marginOffset : void 0;
90410
- const simplePos = isPlainObject$5(attrs.simplePos) ? attrs.simplePos : void 0;
90411
- const originalAttrs = isPlainObject$5(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
90705
+ const raw = isPlainObject$4(value) ? value : void 0;
90706
+ const marginOffset = isPlainObject$4(attrs.marginOffset) ? attrs.marginOffset : void 0;
90707
+ const simplePos = isPlainObject$4(attrs.simplePos) ? attrs.simplePos : void 0;
90708
+ const originalAttrs = isPlainObject$4(attrs.originalAttributes) ? attrs.originalAttributes : void 0;
90412
90709
  const isAnchored = attrs.isAnchor === true || Boolean(raw);
90413
90710
  const anchor = {};
90414
90711
  if (isAnchored) {
@@ -90426,7 +90723,7 @@ ${l}
90426
90723
  if (offsetH != null) anchor.offsetH = offsetH;
90427
90724
  const offsetV = pickNumber(marginOffset?.top ?? marginOffset?.vertical ?? raw?.offsetV ?? simplePos?.y);
90428
90725
  if (offsetV != null) anchor.offsetV = offsetV;
90429
- const behindDoc = toBoolean$3(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
90726
+ const behindDoc = toBoolean$2(raw?.behindDoc ?? wrapBehindDoc ?? originalAttrs?.behindDoc);
90430
90727
  if (behindDoc != null) anchor.behindDoc = behindDoc;
90431
90728
  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;
90432
90729
  return hasData ? anchor : void 0;
@@ -90551,7 +90848,7 @@ ${l}
90551
90848
  }
90552
90849
  }
90553
90850
  const getAttrs = (node2) => {
90554
- return isPlainObject$5(node2.attrs) ? { ...node2.attrs } : {};
90851
+ return isPlainObject$4(node2.attrs) ? { ...node2.attrs } : {};
90555
90852
  };
90556
90853
  const parseFullWidth = (value) => {
90557
90854
  if (typeof value === "string") {
@@ -90570,7 +90867,7 @@ ${l}
90570
90867
  if (rawAttrs.horizontalRule !== true) {
90571
90868
  return null;
90572
90869
  }
90573
- const size2 = isPlainObject$5(rawAttrs.size) ? rawAttrs.size : void 0;
90870
+ const size2 = isPlainObject$4(rawAttrs.size) ? rawAttrs.size : void 0;
90574
90871
  const { width, isFullWidth } = parseFullWidth(size2?.width);
90575
90872
  const height = pickNumber(size2?.height);
90576
90873
  if (!height || height <= 0) {
@@ -90772,6 +91069,9 @@ ${l}
90772
91069
  return null;
90773
91070
  };
90774
91071
  const DEFAULT_IMAGE_DIMENSION_PX = 100;
91072
+ const HALF_POINTS_PER_POINT = 2;
91073
+ const SCREEN_DPI = 96;
91074
+ const POINT_DPI = 72;
90775
91075
  function isInlineImage(node2) {
90776
91076
  const attrs = node2.attrs ?? {};
90777
91077
  const wrap2 = attrs.wrap;
@@ -90799,8 +91099,8 @@ ${l}
90799
91099
  const size2 = attrs.size ?? {};
90800
91100
  const width = typeof size2.width === "number" && Number.isFinite(size2.width) && size2.width > 0 ? size2.width : DEFAULT_IMAGE_DIMENSION_PX;
90801
91101
  const height = typeof size2.height === "number" && Number.isFinite(size2.height) && size2.height > 0 ? size2.height : DEFAULT_IMAGE_DIMENSION_PX;
90802
- const wrap2 = isPlainObject$5(attrs.wrap) ? attrs.wrap : {};
90803
- const wrapAttrs = isPlainObject$5(wrap2.attrs) ? wrap2.attrs : {};
91102
+ const wrap2 = isPlainObject$4(attrs.wrap) ? attrs.wrap : {};
91103
+ const wrapAttrs = isPlainObject$4(wrap2.attrs) ? wrap2.attrs : {};
90804
91104
  const run2 = {
90805
91105
  kind: "image",
90806
91106
  src,
@@ -91010,15 +91310,6 @@ ${l}
91010
91310
  if (defaults2.letterSpacing != null && run2.letterSpacing == null) {
91011
91311
  run2.letterSpacing = defaults2.letterSpacing;
91012
91312
  }
91013
- if (defaults2.bold && run2.bold === void 0) {
91014
- run2.bold = true;
91015
- }
91016
- if (defaults2.italic && run2.italic === void 0) {
91017
- run2.italic = true;
91018
- }
91019
- if (defaults2.underline && !run2.underline) {
91020
- run2.underline = defaults2.underline;
91021
- }
91022
91313
  };
91023
91314
  function paragraphToFlowBlocks$1(para, nextBlockId, positions, defaultFont, defaultSize, styleContext, listCounterContext, trackedChanges, bookmarks, hyperlinkConfig = DEFAULT_HYPERLINK_CONFIG$1, themeColors, converters, converterContext) {
91024
91315
  const baseBlockId = nextBlockId("paragraph");
@@ -91027,28 +91318,45 @@ ${l}
91027
91318
  const paragraphHydration = converterContext ? hydrateParagraphStyleAttrs(para, converterContext) : null;
91028
91319
  let baseRunDefaults = {};
91029
91320
  try {
91030
- const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
91031
- const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
91032
- const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
91033
- const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
91034
- const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
91035
- const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
91036
- if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
91037
- styleNode.styleId = paragraphProps.styleId;
91038
- }
91039
- const resolved = resolveStyle(styleNode, styleContext);
91040
- baseRunDefaults = {
91041
- fontFamily: resolved.character.font?.family,
91042
- fontSizePx: ptToPx(resolved.character.font?.size),
91043
- color: resolved.character.color,
91044
- bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
91045
- italic: resolved.character.font?.italic,
91046
- underline: resolved.character.underline ? {
91047
- style: resolved.character.underline.style,
91048
- color: resolved.character.underline.color
91049
- } : void 0,
91050
- letterSpacing: ptToPx(resolved.character.letterSpacing)
91051
- };
91321
+ const charHydration = converterContext ? hydrateCharacterStyleAttrs(para, converterContext, paragraphHydration?.resolved) : null;
91322
+ if (charHydration) {
91323
+ const fontSizePx = charHydration.fontSize / HALF_POINTS_PER_POINT * (SCREEN_DPI / POINT_DPI);
91324
+ baseRunDefaults = {
91325
+ fontFamily: charHydration.fontFamily,
91326
+ fontSizePx,
91327
+ color: charHydration.color ? `#${charHydration.color.replace("#", "")}` : void 0,
91328
+ bold: charHydration.bold,
91329
+ italic: charHydration.italic,
91330
+ underline: charHydration.underline ? {
91331
+ style: charHydration.underline.type,
91332
+ color: charHydration.underline.color
91333
+ } : void 0,
91334
+ letterSpacing: charHydration.letterSpacing != null ? twipsToPx$1(charHydration.letterSpacing) : void 0
91335
+ };
91336
+ } else {
91337
+ const spacingSource = para.attrs?.spacing !== void 0 ? para.attrs.spacing : paragraphProps.spacing !== void 0 ? paragraphProps.spacing : paragraphHydration?.spacing;
91338
+ const indentSource = para.attrs?.indent ?? paragraphProps.indent ?? paragraphHydration?.indent;
91339
+ const normalizedSpacing = normalizeParagraphSpacing(spacingSource);
91340
+ const normalizedIndent = normalizePxIndent(indentSource) ?? normalizeParagraphIndent(indentSource ?? para.attrs?.textIndent);
91341
+ const styleNodeAttrs = paragraphHydration?.tabStops && !para.attrs?.tabStops && !para.attrs?.tabs ? { ...para.attrs ?? {}, tabStops: paragraphHydration.tabStops } : para.attrs ?? {};
91342
+ const styleNode = buildStyleNodeFromAttrs(styleNodeAttrs, normalizedSpacing, normalizedIndent);
91343
+ if (styleNodeAttrs.styleId == null && paragraphProps.styleId) {
91344
+ styleNode.styleId = paragraphProps.styleId;
91345
+ }
91346
+ const resolved = resolveStyle(styleNode, styleContext);
91347
+ baseRunDefaults = {
91348
+ fontFamily: resolved.character.font?.family,
91349
+ fontSizePx: ptToPx(resolved.character.font?.size),
91350
+ color: resolved.character.color,
91351
+ bold: resolved.character.font?.weight != null ? resolved.character.font.weight >= 600 : void 0,
91352
+ italic: resolved.character.font?.italic,
91353
+ underline: resolved.character.underline ? {
91354
+ style: resolved.character.underline.style,
91355
+ color: resolved.character.underline.color
91356
+ } : void 0,
91357
+ letterSpacing: ptToPx(resolved.character.letterSpacing)
91358
+ };
91359
+ }
91052
91360
  } catch {
91053
91361
  baseRunDefaults = {};
91054
91362
  }
@@ -94599,7 +94907,8 @@ ${l}
94599
94907
  const originX = currentLine.width;
94600
94908
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
94601
94909
  tabStopCursor = nextIndex;
94602
- const tabAdvance = Math.max(0, target - currentLine.width);
94910
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
94911
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
94603
94912
  currentLine.width = roundValue(currentLine.width + tabAdvance);
94604
94913
  run2.width = tabAdvance;
94605
94914
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, 12);
@@ -94607,14 +94916,14 @@ ${l}
94607
94916
  currentLine.toChar = 1;
94608
94917
  if (stop) {
94609
94918
  validateTabStopVal(stop);
94610
- pendingTabAlignment = { target, val: stop.val };
94919
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
94611
94920
  } else {
94612
94921
  pendingTabAlignment = null;
94613
94922
  }
94614
94923
  if (stop && stop.leader && stop.leader !== "none") {
94615
94924
  const leaderStyle = stop.leader;
94616
- const from2 = Math.min(originX, target);
94617
- const to = Math.max(originX, target);
94925
+ const from2 = Math.min(originX, clampedTarget);
94926
+ const to = Math.max(originX, clampedTarget);
94618
94927
  if (!currentLine.leaders) currentLine.leaders = [];
94619
94928
  currentLine.leaders.push({ from: from2, to, style: leaderStyle });
94620
94929
  }
@@ -95209,7 +95518,8 @@ ${l}
95209
95518
  const originX = currentLine.width;
95210
95519
  const { target, nextIndex, stop } = getNextTabStopPx(currentLine.width, tabStops, tabStopCursor);
95211
95520
  tabStopCursor = nextIndex;
95212
- const tabAdvance = Math.max(0, target - currentLine.width);
95521
+ const clampedTarget = Math.min(target, currentLine.maxWidth);
95522
+ const tabAdvance = Math.max(0, clampedTarget - currentLine.width);
95213
95523
  currentLine.width = roundValue(currentLine.width + tabAdvance);
95214
95524
  currentLine.maxFontInfo = updateMaxFontInfo(currentLine.maxFontSize, currentLine.maxFontInfo, run2);
95215
95525
  currentLine.maxFontSize = Math.max(currentLine.maxFontSize, run2.fontSize);
@@ -95218,14 +95528,14 @@ ${l}
95218
95528
  charPosInRun += 1;
95219
95529
  if (stop) {
95220
95530
  validateTabStopVal(stop);
95221
- pendingTabAlignment = { target, val: stop.val };
95531
+ pendingTabAlignment = { target: clampedTarget, val: stop.val };
95222
95532
  } else {
95223
95533
  pendingTabAlignment = null;
95224
95534
  }
95225
95535
  if (stop && stop.leader && stop.leader !== "none" && stop.leader !== "middleDot") {
95226
95536
  const leaderStyle = stop.leader;
95227
- const from2 = Math.min(originX, target);
95228
- const to = Math.max(originX, target);
95537
+ const from2 = Math.min(originX, clampedTarget);
95538
+ const to = Math.max(originX, clampedTarget);
95229
95539
  if (!currentLine.leaders) currentLine.leaders = [];
95230
95540
  currentLine.leaders.push({ from: from2, to, style: leaderStyle });
95231
95541
  }
@@ -103734,16 +104044,112 @@ ${l}
103734
104044
  });
103735
104045
  return mergeRanges$2(mapped, docSize);
103736
104046
  };
103737
- const buildWrapTransaction = (state, ranges, runType) => {
104047
+ const getParagraphAtPos = (doc2, pos) => {
104048
+ try {
104049
+ const $pos = doc2.resolve(pos);
104050
+ for (let depth = $pos.depth; depth >= 0; depth--) {
104051
+ const node2 = $pos.node(depth);
104052
+ if (node2.type.name === "paragraph") {
104053
+ return node2;
104054
+ }
104055
+ }
104056
+ } catch (_e2) {
104057
+ }
104058
+ return null;
104059
+ };
104060
+ const resolveRunPropertiesFromParagraphStyle = (paragraphNode, editor) => {
104061
+ if (!paragraphNode || !editor?.converter) return {};
104062
+ const styleId = paragraphNode.attrs?.paragraphProperties?.styleId;
104063
+ if (!styleId) return {};
104064
+ try {
104065
+ const params2 = { docx: editor.converter.convertedXml, numbering: editor.converter.numbering };
104066
+ const resolvedPpr = { styleId };
104067
+ const runProps = resolveRunProperties(params2, {}, resolvedPpr, false, false);
104068
+ const runProperties = {};
104069
+ if (runProps.fontFamily) {
104070
+ const fontValue = runProps.fontFamily.ascii || runProps.fontFamily;
104071
+ if (fontValue) {
104072
+ runProperties.fontFamily = typeof fontValue === "string" ? fontValue : fontValue.ascii;
104073
+ }
104074
+ }
104075
+ if (runProps.fontSize) {
104076
+ runProperties.fontSize = `${runProps.fontSize / 2}pt`;
104077
+ }
104078
+ if (runProps.bold) runProperties.bold = true;
104079
+ if (runProps.italic) runProperties.italic = true;
104080
+ if (runProps.underline) runProperties.underline = runProps.underline;
104081
+ if (runProps.strike) runProperties.strike = true;
104082
+ return runProperties;
104083
+ } catch (_e2) {
104084
+ return {};
104085
+ }
104086
+ };
104087
+ const createMarksFromDefs = (schema, markDefs = []) => markDefs.map((def2) => {
104088
+ const markType = schema.marks[def2.type];
104089
+ return markType ? markType.create(def2.attrs) : null;
104090
+ }).filter(Boolean);
104091
+ const createMarkDefsFromStyleRunProps = (styleRunProps) => {
104092
+ const markDefs = [];
104093
+ const textStyleAttrs = {};
104094
+ if (styleRunProps.fontSize) {
104095
+ textStyleAttrs.fontSize = styleRunProps.fontSize;
104096
+ }
104097
+ if (styleRunProps.fontFamily) {
104098
+ textStyleAttrs.fontFamily = styleRunProps.fontFamily;
104099
+ }
104100
+ if (Object.keys(textStyleAttrs).length > 0) {
104101
+ markDefs.push({ type: "textStyle", attrs: textStyleAttrs });
104102
+ }
104103
+ if (styleRunProps.bold) {
104104
+ markDefs.push({ type: "bold", attrs: { value: true } });
104105
+ }
104106
+ if (styleRunProps.italic) {
104107
+ markDefs.push({ type: "italic", attrs: { value: true } });
104108
+ }
104109
+ if (styleRunProps.strike) {
104110
+ markDefs.push({ type: "strike", attrs: { value: true } });
104111
+ }
104112
+ if (styleRunProps.underline) {
104113
+ const underlineType = styleRunProps.underline["w:val"];
104114
+ if (underlineType) {
104115
+ let underlineColor = styleRunProps.underline["w:color"];
104116
+ if (underlineColor && underlineColor.toLowerCase() !== "auto" && !underlineColor.startsWith("#")) {
104117
+ underlineColor = `#${underlineColor}`;
104118
+ }
104119
+ markDefs.push({
104120
+ type: "underline",
104121
+ attrs: { underlineType, underlineColor }
104122
+ });
104123
+ }
104124
+ }
104125
+ return markDefs;
104126
+ };
104127
+ const buildWrapTransaction = (state, ranges, runType, editor, markDefsFromMeta = []) => {
103738
104128
  if (!ranges.length) return null;
103739
104129
  const replacements = [];
104130
+ const metaStyleMarks = createMarksFromDefs(state.schema, markDefsFromMeta);
103740
104131
  ranges.forEach(({ from: from2, to }) => {
103741
104132
  state.doc.nodesBetween(from2, to, (node2, pos, parent, index2) => {
103742
104133
  if (!node2.isText || !parent || parent.type === runType) return;
103743
104134
  const match = parent.contentMatchAt ? parent.contentMatchAt(index2) : null;
103744
104135
  if (match && !match.matchType(runType)) return;
103745
104136
  if (!match && !parent.type.contentMatch.matchType(runType)) return;
103746
- const runProperties = decodeRPrFromMarks(node2.marks);
104137
+ let runProperties = decodeRPrFromMarks(node2.marks);
104138
+ if ((!node2.marks || node2.marks.length === 0) && editor?.converter) {
104139
+ const paragraphNode = getParagraphAtPos(state.doc, pos);
104140
+ const styleRunProps = resolveRunPropertiesFromParagraphStyle(paragraphNode, editor);
104141
+ if (Object.keys(styleRunProps).length > 0) {
104142
+ runProperties = styleRunProps;
104143
+ const markDefs = metaStyleMarks.length ? markDefsFromMeta : createMarkDefsFromStyleRunProps(styleRunProps);
104144
+ const styleMarks = metaStyleMarks.length ? metaStyleMarks : createMarksFromDefs(state.schema, markDefs);
104145
+ if (styleMarks.length && typeof state.schema.text === "function") {
104146
+ const textNode = state.schema.text(node2.text || "", styleMarks);
104147
+ if (textNode) {
104148
+ node2 = textNode;
104149
+ }
104150
+ }
104151
+ }
104152
+ }
103747
104153
  const runNode = runType.create({ runProperties }, node2);
103748
104154
  replacements.push({ from: pos, to: pos + node2.nodeSize, runNode });
103749
104155
  });
@@ -103753,9 +104159,10 @@ ${l}
103753
104159
  replacements.sort((a2, b2) => b2.from - a2.from).forEach(({ from: from2, to, runNode }) => tr.replaceWith(from2, to, runNode));
103754
104160
  return tr.docChanged ? tr : null;
103755
104161
  };
103756
- const wrapTextInRunsPlugin = () => {
104162
+ const wrapTextInRunsPlugin = (editor) => {
103757
104163
  let view = null;
103758
104164
  let pendingRanges = [];
104165
+ let lastStyleMarksMeta = [];
103759
104166
  const flush = () => {
103760
104167
  if (!view) return;
103761
104168
  const runType = view.state.schema.nodes.run;
@@ -103763,7 +104170,7 @@ ${l}
103763
104170
  pendingRanges = [];
103764
104171
  return;
103765
104172
  }
103766
- const tr = buildWrapTransaction(view.state, pendingRanges, runType);
104173
+ const tr = buildWrapTransaction(view.state, pendingRanges, runType, editor, lastStyleMarksMeta);
103767
104174
  pendingRanges = [];
103768
104175
  if (tr) {
103769
104176
  view.dispatch(tr);
@@ -103782,6 +104189,7 @@ ${l}
103782
104189
  editorView.dom.removeEventListener("compositionend", onCompositionEnd2);
103783
104190
  view = null;
103784
104191
  pendingRanges = [];
104192
+ lastStyleMarksMeta = [];
103785
104193
  }
103786
104194
  };
103787
104195
  },
@@ -103795,7 +104203,11 @@ ${l}
103795
104203
  if (view?.composing) {
103796
104204
  return null;
103797
104205
  }
103798
- const tr = buildWrapTransaction(newState, pendingRanges, runType);
104206
+ const latestStyleMarksMeta = [...transactions].reverse().find((tr2) => tr2.getMeta && tr2.getMeta("sdStyleMarks"))?.getMeta("sdStyleMarks") || lastStyleMarksMeta;
104207
+ if (latestStyleMarksMeta && latestStyleMarksMeta.length) {
104208
+ lastStyleMarksMeta = latestStyleMarksMeta;
104209
+ }
104210
+ const tr = buildWrapTransaction(newState, pendingRanges, runType, editor, latestStyleMarksMeta);
103799
104211
  pendingRanges = [];
103800
104212
  return tr;
103801
104213
  }
@@ -104058,7 +104470,7 @@ ${l}
104058
104470
  },
104059
104471
  addPmPlugins() {
104060
104472
  return [
104061
- wrapTextInRunsPlugin(),
104473
+ wrapTextInRunsPlugin(this.editor),
104062
104474
  splitRunsAfterMarkPlugin,
104063
104475
  calculateInlineRunPropertiesPlugin(this.editor),
104064
104476
  cleanupEmptyRunsPlugin
@@ -143192,7 +143604,7 @@ ${reason}`);
143192
143604
  this.config.colors = shuffleArray(this.config.colors);
143193
143605
  this.userColorMap = /* @__PURE__ */ new Map();
143194
143606
  this.colorIndex = 0;
143195
- this.version = "1.3.0-next.2";
143607
+ this.version = "1.3.0-next.3";
143196
143608
  this.#log("🦋 [superdoc] Using SuperDoc version:", this.version);
143197
143609
  this.superdocId = config2.superdocId || v4();
143198
143610
  this.colors = this.config.colors;