@superdoc-dev/mcp 0.6.0-next.11 → 0.6.0-next.13

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.
Files changed (2) hide show
  1. package/dist/index.js +379 -179
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -51891,7 +51891,7 @@ var init_remark_gfm_BhnWr3yf_es = __esm(() => {
51891
51891
  emptyOptions2 = {};
51892
51892
  });
51893
51893
 
51894
- // ../../packages/superdoc/dist/chunks/SuperConverter-CnwfJPj6.es.js
51894
+ // ../../packages/superdoc/dist/chunks/SuperConverter-BLUJyRB9.es.js
51895
51895
  function getExtensionConfigField(extension$1, field, context = { name: "" }) {
51896
51896
  const fieldValue = extension$1.config[field];
51897
51897
  if (typeof fieldValue === "function")
@@ -71911,8 +71911,26 @@ function mutatePart(request) {
71911
71911
  result: capturedResult
71912
71912
  };
71913
71913
  }
71914
+ function getRelationshipsRoot(part) {
71915
+ if (!part || typeof part !== "object")
71916
+ return;
71917
+ if (part.name === "Relationships")
71918
+ return part;
71919
+ const children = part.elements;
71920
+ if (!Array.isArray(children))
71921
+ return;
71922
+ return children.find((el) => el?.name === "Relationships");
71923
+ }
71924
+ function createRelationshipsPart(elements = []) {
71925
+ return {
71926
+ type: "element",
71927
+ name: "Relationships",
71928
+ attributes: { xmlns: RELS_XMLNS$2 },
71929
+ elements
71930
+ };
71931
+ }
71914
71932
  function getRelationshipsTag(part) {
71915
- const tag = part?.elements?.find((el) => el.name === "Relationships");
71933
+ const tag = getRelationshipsRoot(part);
71916
71934
  if (tag && !tag.elements)
71917
71935
  tag.elements = [];
71918
71936
  return tag;
@@ -71932,8 +71950,25 @@ function getMaxIdInt(elements) {
71932
71950
  }
71933
71951
  return max;
71934
71952
  }
71953
+ function createRelationshipElement(id, mappedType, target, isExternal) {
71954
+ const rel = {
71955
+ type: "element",
71956
+ name: "Relationship",
71957
+ attributes: {
71958
+ Id: id,
71959
+ Type: mappedType,
71960
+ Target: target
71961
+ }
71962
+ };
71963
+ if (isExternal)
71964
+ rel.attributes.TargetMode = "External";
71965
+ return rel;
71966
+ }
71967
+ function findExistingRelationship(elements, target, normalized, mappedType) {
71968
+ return elements.find((rel) => (rel.attributes?.Target === normalized || rel.attributes?.Target === target) && rel.attributes?.Type === mappedType);
71969
+ }
71935
71970
  function findOrCreateRelationship(editor, source, options) {
71936
- const { target, type, dryRun, expectedRevision } = options;
71971
+ const { target, type, partId = RELS_PART_ID, dryRun, expectedRevision } = options;
71937
71972
  if (!target || typeof target !== "string")
71938
71973
  return null;
71939
71974
  if (!type || typeof type !== "string")
@@ -71945,9 +71980,22 @@ function findOrCreateRelationship(editor, source, options) {
71945
71980
  }
71946
71981
  const normalized = normalizeTarget(target);
71947
71982
  const isExternal = type === "hyperlink";
71983
+ if (!hasPart(editor, partId)) {
71984
+ const newId = "rId1";
71985
+ mutatePart({
71986
+ editor,
71987
+ partId,
71988
+ operation: "create",
71989
+ source,
71990
+ dryRun,
71991
+ expectedRevision,
71992
+ initial: createRelationshipsPart([createRelationshipElement(newId, mappedType, isExternal ? target : normalized, isExternal)])
71993
+ });
71994
+ return newId;
71995
+ }
71948
71996
  return mutatePart({
71949
71997
  editor,
71950
- partId: RELS_PART_ID,
71998
+ partId,
71951
71999
  operation: "mutate",
71952
72000
  source,
71953
72001
  dryRun,
@@ -71956,24 +72004,11 @@ function findOrCreateRelationship(editor, source, options) {
71956
72004
  const tag = getRelationshipsTag(part);
71957
72005
  if (!tag)
71958
72006
  return null;
71959
- const existing = tag.elements.find((rel) => rel.attributes?.Target === normalized && rel.attributes?.Type === mappedType);
72007
+ const existing = findExistingRelationship(tag.elements, target, normalized, mappedType);
71960
72008
  if (existing)
71961
72009
  return existing.attributes.Id;
71962
- const existingRaw = tag.elements.find((rel) => rel.attributes?.Target === target && rel.attributes?.Type === mappedType);
71963
- if (existingRaw)
71964
- return existingRaw.attributes.Id;
71965
72010
  const newId = `rId${getMaxIdInt(tag.elements) + 1}`;
71966
- const newRel = {
71967
- type: "element",
71968
- name: "Relationship",
71969
- attributes: {
71970
- Id: newId,
71971
- Type: mappedType,
71972
- Target: isExternal ? target : normalized
71973
- }
71974
- };
71975
- if (isExternal)
71976
- newRel.attributes.TargetMode = "External";
72011
+ const newRel = createRelationshipElement(newId, mappedType, isExternal ? target : normalized, isExternal);
71977
72012
  tag.elements.push(newRel);
71978
72013
  return newId;
71979
72014
  }
@@ -79234,12 +79269,26 @@ function addImageRelationshipForId(params, id, imagePath) {
79234
79269
  name: "Relationship",
79235
79270
  attributes: {
79236
79271
  Id: id,
79237
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
79272
+ Type: IMAGE_REL_TYPE,
79238
79273
  Target: imagePath
79239
79274
  }
79240
79275
  };
79241
79276
  params.relationships.push(newRel);
79242
79277
  }
79278
+ function getDocumentRelationships(params) {
79279
+ return (params.converter?.convertedXml || {})["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships")?.elements ?? [];
79280
+ }
79281
+ function findImageRelationship(relationships = [], { id, target }) {
79282
+ return relationships.find((rel) => {
79283
+ if (rel?.attributes?.Type !== IMAGE_REL_TYPE)
79284
+ return false;
79285
+ if (id)
79286
+ return rel.attributes.Id === id;
79287
+ if (target)
79288
+ return rel.attributes.Target === target;
79289
+ return false;
79290
+ });
79291
+ }
79243
79292
  function translateVectorShape(params) {
79244
79293
  const { node: node2 } = params;
79245
79294
  const { drawingContent } = node2.attrs;
@@ -85680,6 +85729,16 @@ function registerStaticInvalidationHandlers() {
85680
85729
  function registerHeaderFooterInvalidation(partId) {
85681
85730
  registerInvalidationHandler(partId, handleHeaderFooterInvalidation);
85682
85731
  }
85732
+ function normalizeWordPartPath(target = "") {
85733
+ return `word/${String(target).replace(/\\/g, "/").replace(/^(\.\/|\/)+/, "").replace(/^word\//, "")}`;
85734
+ }
85735
+ function getWordPartRelsPath(partPath = "") {
85736
+ const normalized = String(partPath).replace(/\\/g, "/");
85737
+ const lastSlash = normalized.lastIndexOf("/");
85738
+ if (lastSlash < 0 || lastSlash === normalized.length - 1)
85739
+ return `word/_rels/${lastSlash < 0 ? normalized : normalized.slice(lastSlash + 1)}.rels`;
85740
+ return `${normalized.slice(0, lastSlash)}/_rels/${normalized.slice(lastSlash + 1)}.rels`;
85741
+ }
85683
85742
  function getConverterForHeaderFooter(editor) {
85684
85743
  return editor.converter;
85685
85744
  }
@@ -85703,11 +85762,7 @@ function normalizeRelationshipTarget(target) {
85703
85762
  return normalized;
85704
85763
  }
85705
85764
  function toRelsPathForPart(partPath) {
85706
- const normalized = normalizeRelationshipTarget(partPath);
85707
- const fileName = normalized.split("/").pop();
85708
- if (!fileName)
85709
- return normalized;
85710
- return `word/_rels/${fileName}.rels`;
85765
+ return getWordPartRelsPath(normalizeRelationshipTarget(partPath));
85711
85766
  }
85712
85767
  function ensureConvertedXml(converter) {
85713
85768
  if (!converter.convertedXml || typeof converter.convertedXml !== "object")
@@ -85723,7 +85778,7 @@ function readRelationshipsRoot(converter) {
85723
85778
  return null;
85724
85779
  return relationshipsRoot;
85725
85780
  }
85726
- function getRelationshipElements(root2) {
85781
+ function getRelationshipElements$1(root2) {
85727
85782
  if (!Array.isArray(root2.elements))
85728
85783
  return [];
85729
85784
  return root2.elements.filter((entry) => entry.name === "Relationship");
@@ -85735,7 +85790,7 @@ function hasHeaderFooterRelationship(converter, input) {
85735
85790
  const relationshipsRoot = readRelationshipsRoot(converter);
85736
85791
  if (!relationshipsRoot)
85737
85792
  return false;
85738
- return findRelationshipById(getRelationshipElements(relationshipsRoot), input.refId, toRelationshipType(input.kind)) !== undefined;
85793
+ return findRelationshipById(getRelationshipElements$1(relationshipsRoot), input.refId, toRelationshipType(input.kind)) !== undefined;
85739
85794
  }
85740
85795
  function nextRelationshipId(relationships) {
85741
85796
  const usedIds = new Set(relationships.map((entry) => String(entry.attributes?.Id ?? "")).filter((value) => value.length > 0));
@@ -85845,7 +85900,7 @@ function createHeaderFooterPart(editor, input) {
85845
85900
  ensureConvertedXml(converter);
85846
85901
  const convertedXml = converter.convertedXml;
85847
85902
  const relationshipsRoot = readRelationshipsRoot(converter);
85848
- const relationships = relationshipsRoot ? getRelationshipElements(relationshipsRoot) : [];
85903
+ const relationships = relationshipsRoot ? getRelationshipElements$1(relationshipsRoot) : [];
85849
85904
  const newRefId = nextRelationshipId(relationships);
85850
85905
  const relationshipType = toRelationshipType(input.kind);
85851
85906
  const newFilename = nextHeaderFooterFilename(input.kind, relationships, convertedXml);
@@ -86207,6 +86262,15 @@ function registerHeaderFooterInvalidationHandler(partId) {
86207
86262
  function getConverter$3(editor) {
86208
86263
  return editor.converter;
86209
86264
  }
86265
+ function normalizeHeaderFooterPartPath(target = "") {
86266
+ return normalizeWordPartPath(target);
86267
+ }
86268
+ function getHeaderFooterRelsPartId(partId) {
86269
+ return getWordPartRelsPath(partId);
86270
+ }
86271
+ function getRelationshipElements(part) {
86272
+ return getRelationshipsRoot(part)?.elements ?? [];
86273
+ }
86210
86274
  function resolvePartIdFromRefId(editor, headerFooterRefId) {
86211
86275
  const relsRoot = getConverter$3(editor)?.convertedXml?.["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships");
86212
86276
  if (!relsRoot?.elements)
@@ -86222,10 +86286,14 @@ function resolvePartIdFromRefId(editor, headerFooterRefId) {
86222
86286
  const target = el.attributes?.Target;
86223
86287
  if (!target)
86224
86288
  continue;
86225
- return `word/${target}`;
86289
+ return normalizeHeaderFooterPartPath(target);
86226
86290
  }
86227
86291
  return null;
86228
86292
  }
86293
+ function resolveHeaderFooterRelsPartIdFromRefId(editor, headerFooterRefId) {
86294
+ const partId = resolvePartIdFromRefId(editor, headerFooterRefId);
86295
+ return partId ? getHeaderFooterRelsPartId(partId) : null;
86296
+ }
86229
86297
  function resolveRIdFromRelsData(relsData, partId) {
86230
86298
  const target = partId.replace(/^word\//, "");
86231
86299
  const relsRoot = relsData?.elements?.find((el) => el.name === "Relationships");
@@ -86264,6 +86332,8 @@ function exportSubEditorToPart(mainEditor, subEditor, headerFooterRefId, type) {
86264
86332
  if (!partId)
86265
86333
  return false;
86266
86334
  ensureHeaderFooterDescriptor(partId, headerFooterRefId);
86335
+ const relsPartId = getHeaderFooterRelsPartId(partId);
86336
+ const existingRelationships = getRelationshipElements(converter.convertedXml?.[relsPartId]);
86267
86337
  const pmJson = typeof subEditor.getUpdatedJson === "function" ? subEditor.getUpdatedJson() : converter[`${type}s`]?.[headerFooterRefId];
86268
86338
  if (!pmJson)
86269
86339
  return false;
@@ -86275,7 +86345,8 @@ function exportSubEditorToPart(mainEditor, subEditor, headerFooterRefId, type) {
86275
86345
  editorSchema: subEditor.schema,
86276
86346
  isHeaderFooter: true,
86277
86347
  comments: [],
86278
- commentDefinitions: []
86348
+ commentDefinitions: [],
86349
+ existingRelationships
86279
86350
  });
86280
86351
  bodyContent = result?.elements?.[0]?.elements ?? [];
86281
86352
  } catch (err$1) {
@@ -86336,7 +86407,7 @@ function registerExistingHeaderFooterDescriptors(editor) {
86336
86407
  const id = el.attributes?.Id;
86337
86408
  if (!target || !id)
86338
86409
  continue;
86339
- const partId = `word/${target}`;
86410
+ const partId = normalizeHeaderFooterPartPath(target);
86340
86411
  if (isHeaderFooterPartId(partId))
86341
86412
  ensureHeaderFooterDescriptor(partId, id);
86342
86413
  }
@@ -86507,7 +86578,7 @@ function cleanupCreatedPart(editor, partPath) {
86507
86578
  if (hasPart(editor, partId))
86508
86579
  removePart(editor, partId);
86509
86580
  removeInvalidationHandler(partId);
86510
- const relsPath = `word/_rels/${partPath.split("/").pop()}.rels`;
86581
+ const relsPath = getWordPartRelsPath(partPath);
86511
86582
  if (hasPart(editor, relsPath))
86512
86583
  removePart(editor, relsPath);
86513
86584
  }
@@ -99960,7 +100031,7 @@ var isRegExp = (value) => {
99960
100031
  this.prevTime = prevTime;
99961
100032
  this.prevComposition = prevComposition;
99962
100033
  }
99963
- }, DEPTH_OVERFLOW = 20, cachedPreserveItems = false, cachedPreserveItemsPlugins = null, historyKey, closeHistoryKey, undo, redo, ySyncPluginKey, yUndoPluginKey, yCursorPluginKey, descriptors, PlanError, revisionMap, subscribedEditors, handlers, stalePartIds, RELATIONSHIP_TYPES, RELS_PART_ID = "word/_rels/document.xml.rels", handleDecimal = (path2, lvlText) => generateNumbering(path2, lvlText, numberToStringFormatter), handleRoman = (path2, lvlText) => generateNumbering(path2, lvlText, intToRoman), handleLowerRoman = (path2, lvlText) => {
100034
+ }, DEPTH_OVERFLOW = 20, cachedPreserveItems = false, cachedPreserveItemsPlugins = null, historyKey, closeHistoryKey, undo, redo, ySyncPluginKey, yUndoPluginKey, yCursorPluginKey, descriptors, PlanError, revisionMap, subscribedEditors, handlers, stalePartIds, RELATIONSHIP_TYPES, RELS_XMLNS$2 = "http://schemas.openxmlformats.org/package/2006/relationships", RELS_PART_ID = "word/_rels/document.xml.rels", handleDecimal = (path2, lvlText) => generateNumbering(path2, lvlText, numberToStringFormatter), handleRoman = (path2, lvlText) => generateNumbering(path2, lvlText, intToRoman), handleLowerRoman = (path2, lvlText) => {
99964
100035
  const result = handleRoman(path2, lvlText);
99965
100036
  return result ? result.toLowerCase() : null;
99966
100037
  }, handleAlpha = (path2, lvlText) => generateNumbering(path2, lvlText, intToAlpha), handleLowerAlpha = (path2, lvlText) => {
@@ -101413,7 +101484,7 @@ var isRegExp = (value) => {
101413
101484
  tr,
101414
101485
  changed: true
101415
101486
  };
101416
- }, STRUCTURED_CONTENT_NODE_TYPES, helpers_exports, DECORATIVE_EXT_URI = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_NAMESPACE = "http://schemas.microsoft.com/office/drawing/2017/decorative", HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", translateImageNode = (params) => {
101487
+ }, STRUCTURED_CONTENT_NODE_TYPES, helpers_exports, DECORATIVE_EXT_URI = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_NAMESPACE = "http://schemas.microsoft.com/office/drawing/2017/decorative", HYPERLINK_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", IMAGE_REL_TYPE = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", translateImageNode = (params) => {
101417
101488
  const { node: { attrs = {} }, tableCell, imageSize } = params;
101418
101489
  let imageId = attrs.rId;
101419
101490
  const src = attrs.originalSrc || attrs.src || attrs.imageSrc;
@@ -101453,9 +101524,14 @@ var isRegExp = (value) => {
101453
101524
  };
101454
101525
  }
101455
101526
  if (imageId) {
101456
- const hasRelation = (params.converter?.convertedXml || {})["word/_rels/document.xml.rels"]?.elements?.find((el) => el.name === "Relationships")?.elements.find((el) => el.attributes.Id === imageId);
101457
101527
  const path2 = src?.split("word/")[1];
101458
- if (!hasRelation)
101528
+ const existingRelation = findImageRelationship(params.isHeaderFooter ? params.existingRelationships : getDocumentRelationships(params), {
101529
+ id: imageId,
101530
+ target: path2
101531
+ });
101532
+ if (existingRelation)
101533
+ imageId = existingRelation.attributes.Id;
101534
+ else
101459
101535
  addImageRelationshipForId(params, imageId, path2);
101460
101536
  } else if (params.node.type === "image" && !imageId) {
101461
101537
  const path2 = src?.split("word/")[1];
@@ -105687,7 +105763,7 @@ var isRegExp = (value) => {
105687
105763
  state.kern = kernNode.attributes["w:val"];
105688
105764
  }
105689
105765
  }, SuperConverter;
105690
- var init_SuperConverter_CnwfJPj6_es = __esm(() => {
105766
+ var init_SuperConverter_BLUJyRB9_es = __esm(() => {
105691
105767
  init_rolldown_runtime_Bg48TavK_es();
105692
105768
  init_jszip_C49i9kUs_es();
105693
105769
  init_xml_js_CqGKpaft_es();
@@ -143433,7 +143509,7 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143433
143509
  this.#exportNumberingFile(params);
143434
143510
  return xml;
143435
143511
  }
143436
- exportToXmlJson({ data, editorSchema, comments, commentDefinitions, commentsExportType = "clean", isFinalDoc = false, editor, isHeaderFooter = false, fieldsHighlightColor = null, preserveSdtWrappers = false, statFieldCacheMap = undefined }) {
143512
+ exportToXmlJson({ data, editorSchema, comments, commentDefinitions, commentsExportType = "clean", isFinalDoc = false, editor, isHeaderFooter = false, fieldsHighlightColor = null, preserveSdtWrappers = false, statFieldCacheMap = undefined, existingRelationships = [] }) {
143437
143513
  const bodyNode = this.savedTagsToRestore.find((el) => el.name === "w:body");
143438
143514
  let resolvedCacheMap = statFieldCacheMap ?? this._currentStatFieldCacheMap;
143439
143515
  if (!resolvedCacheMap)
@@ -143458,7 +143534,8 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143458
143534
  isHeaderFooter,
143459
143535
  fieldsHighlightColor,
143460
143536
  preserveSdtWrappers,
143461
- statFieldCacheMap: resolvedCacheMap
143537
+ statFieldCacheMap: resolvedCacheMap,
143538
+ existingRelationships
143462
143539
  });
143463
143540
  return {
143464
143541
  result,
@@ -143545,8 +143622,10 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143545
143622
  const relationships = this.convertedXml["word/_rels/document.xml.rels"].elements.find((x) => x.name === "Relationships");
143546
143623
  const newDocRels = [];
143547
143624
  Object.entries(this.headers).forEach(([id, header], index2) => {
143548
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index2 + 1}.xml`;
143625
+ const partPath = normalizeWordPartPath(relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `header${index2 + 1}.xml`);
143626
+ const relsPath = getWordPartRelsPath(partPath);
143549
143627
  const headerEditor = this.headerEditors.find((item) => item.id === id);
143628
+ const existingRelationships = this.convertedXml[relsPath]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
143550
143629
  if (!headerEditor)
143551
143630
  return;
143552
143631
  const { result, params } = this.exportToXmlJson({
@@ -143556,11 +143635,12 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143556
143635
  comments: [],
143557
143636
  commentDefinitions: [],
143558
143637
  isHeaderFooter: true,
143559
- isFinalDoc
143638
+ isFinalDoc,
143639
+ existingRelationships
143560
143640
  });
143561
143641
  const bodyContent = result.elements[0].elements;
143562
- if (!this.convertedXml[`word/${fileName}`]) {
143563
- this.convertedXml[`word/${fileName}`] = {
143642
+ if (!this.convertedXml[partPath]) {
143643
+ this.convertedXml[partPath] = {
143564
143644
  declaration: this.initialJSON?.declaration,
143565
143645
  elements: [{
143566
143646
  attributes: DEFAULT_DOCX_DEFS,
@@ -143575,26 +143655,26 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143575
143655
  attributes: {
143576
143656
  Id: id,
143577
143657
  Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
143578
- Target: fileName
143658
+ Target: partPath.replace(/^word\//, "")
143579
143659
  }
143580
143660
  });
143581
143661
  }
143582
- this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
143583
- if (params.relationships.length) {
143584
- const relationships$1 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
143585
- this.convertedXml[`word/_rels/${fileName}.rels`] = {
143662
+ this.convertedXml[partPath].elements[0].elements = bodyContent;
143663
+ if (params.relationships.length)
143664
+ this.convertedXml[relsPath] = {
143586
143665
  declaration: this.initialJSON?.declaration,
143587
143666
  elements: [{
143588
143667
  name: "Relationships",
143589
143668
  attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
143590
- elements: [...relationships$1, ...params.relationships]
143669
+ elements: mergeRelationshipElements(existingRelationships, params.relationships)
143591
143670
  }]
143592
143671
  };
143593
- }
143594
143672
  });
143595
143673
  Object.entries(this.footers).forEach(([id, footer], index2) => {
143596
- const fileName = relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index2 + 1}.xml`;
143674
+ const partPath = normalizeWordPartPath(relationships.elements.find((el) => el.attributes.Id === id)?.attributes.Target || `footer${index2 + 1}.xml`);
143675
+ const relsPath = getWordPartRelsPath(partPath);
143597
143676
  const footerEditor = this.footerEditors.find((item) => item.id === id);
143677
+ const existingRelationships = this.convertedXml[relsPath]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
143598
143678
  if (!footerEditor)
143599
143679
  return;
143600
143680
  const { result, params } = this.exportToXmlJson({
@@ -143604,11 +143684,12 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143604
143684
  comments: [],
143605
143685
  commentDefinitions: [],
143606
143686
  isHeaderFooter: true,
143607
- isFinalDoc
143687
+ isFinalDoc,
143688
+ existingRelationships
143608
143689
  });
143609
143690
  const bodyContent = result.elements[0].elements;
143610
- if (!this.convertedXml[`word/${fileName}`]) {
143611
- this.convertedXml[`word/${fileName}`] = {
143691
+ if (!this.convertedXml[partPath]) {
143692
+ this.convertedXml[partPath] = {
143612
143693
  declaration: this.initialJSON?.declaration,
143613
143694
  elements: [{
143614
143695
  attributes: DEFAULT_DOCX_DEFS,
@@ -143623,22 +143704,20 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143623
143704
  attributes: {
143624
143705
  Id: id,
143625
143706
  Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
143626
- Target: fileName
143707
+ Target: partPath.replace(/^word\//, "")
143627
143708
  }
143628
143709
  });
143629
143710
  }
143630
- this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
143631
- if (params.relationships.length) {
143632
- const relationships$1 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
143633
- this.convertedXml[`word/_rels/${fileName}.rels`] = {
143711
+ this.convertedXml[partPath].elements[0].elements = bodyContent;
143712
+ if (params.relationships.length)
143713
+ this.convertedXml[relsPath] = {
143634
143714
  declaration: this.initialJSON?.declaration,
143635
143715
  elements: [{
143636
143716
  name: "Relationships",
143637
143717
  attributes: { xmlns: "http://schemas.openxmlformats.org/package/2006/relationships" },
143638
- elements: [...relationships$1, ...params.relationships]
143718
+ elements: mergeRelationshipElements(existingRelationships, params.relationships)
143639
143719
  }]
143640
143720
  };
143641
- }
143642
143721
  });
143643
143722
  return newDocRels;
143644
143723
  }
@@ -143721,7 +143800,7 @@ var init_SuperConverter_CnwfJPj6_es = __esm(() => {
143721
143800
  };
143722
143801
  });
143723
143802
 
143724
- // ../../packages/superdoc/dist/chunks/create-headless-toolbar-Btizo_Im.es.js
143803
+ // ../../packages/superdoc/dist/chunks/create-headless-toolbar-DCioTQPP.es.js
143725
143804
  function parseSizeUnit(val = "0") {
143726
143805
  const length = val.toString() || "0";
143727
143806
  const value = Number.parseFloat(length);
@@ -143938,11 +144017,36 @@ function replaceSelectionWithImagePlaceholder({ editorOptions, view, id }) {
143938
144017
  tr = addImagePlaceholder(view.state, tr, id, selection.from);
143939
144018
  view.dispatch(tr);
143940
144019
  }
144020
+ function getImageMediaStores(editor) {
144021
+ const own4 = editor?.storage?.image?.media;
144022
+ const parent = editor?.options?.parentEditor?.storage?.image?.media;
144023
+ const stores = [];
144024
+ if (own4)
144025
+ stores.push(own4);
144026
+ if (parent && parent !== own4)
144027
+ stores.push(parent);
144028
+ return stores;
144029
+ }
144030
+ function getExistingImageFileNames(editor) {
144031
+ const names = /* @__PURE__ */ new Set;
144032
+ for (const media of getImageMediaStores(editor))
144033
+ Object.keys(media).forEach((key$1) => names.add(key$1.split("/").pop()));
144034
+ return names;
144035
+ }
144036
+ function registerImageMedia(editor, mediaPath, url2) {
144037
+ const stores = getImageMediaStores(editor);
144038
+ if (!stores.length) {
144039
+ editor.storage.image.media = { [mediaPath]: url2 };
144040
+ return;
144041
+ }
144042
+ for (const media of stores)
144043
+ media[mediaPath] = url2;
144044
+ }
143941
144045
  async function uploadAndInsertImage({ editor, view, file: file2, size, id }) {
143942
144046
  const imageUploadHandler = typeof editor.options.handleImageUpload === "function" ? editor.options.handleImageUpload : handleImageUpload;
143943
144047
  const placeholderId = id;
143944
144048
  try {
143945
- const existingFileNames = new Set(Object.keys(editor.storage.image.media ?? {}).map((key$1) => key$1.split("/").pop()));
144049
+ const existingFileNames = getExistingImageFileNames(editor);
143946
144050
  const uniqueFileName = ensureUniqueFileName(file2.name, existingFileNames);
143947
144051
  let url2 = await imageUploadHandler(uniqueFileName === file2.name ? file2 : new File([file2], uniqueFileName, {
143948
144052
  type: file2.type,
@@ -143969,7 +144073,7 @@ async function uploadAndInsertImage({ editor, view, file: file2, size, id }) {
143969
144073
  id: docPrId,
143970
144074
  rId
143971
144075
  });
143972
- editor.storage.image.media = Object.assign(editor.storage.image.media, { [mediaPath]: url2 });
144076
+ registerImageMedia(editor, mediaPath, url2);
143973
144077
  if (editor.options.ydoc && typeof editor.commands.addImageToCollaboration === "function")
143974
144078
  editor.commands.addImageToCollaboration({
143975
144079
  mediaPath,
@@ -143985,6 +144089,20 @@ async function uploadAndInsertImage({ editor, view, file: file2, size, id }) {
143985
144089
  }
143986
144090
  }
143987
144091
  function addImageRelationship({ editor, path: path2 }) {
144092
+ if (editor.options.isHeaderOrFooter) {
144093
+ const parentEditor = editor.options.parentEditor;
144094
+ const headerFooterRefId = editor.options.headerFooterRefId;
144095
+ if (!parentEditor || !headerFooterRefId)
144096
+ return null;
144097
+ const relsPartId = resolveHeaderFooterRelsPartIdFromRefId(parentEditor, headerFooterRefId);
144098
+ if (!relsPartId)
144099
+ return null;
144100
+ return findOrCreateRelationship(parentEditor, "startImageUpload:addHeaderFooterImageRelationship", {
144101
+ target: path2,
144102
+ type: "image",
144103
+ partId: relsPartId
144104
+ });
144105
+ }
143988
144106
  return findOrCreateRelationship(editor, "startImageUpload:addImageRelationship", {
143989
144107
  target: path2,
143990
144108
  type: "image"
@@ -146443,8 +146561,8 @@ var CSS_DIMENSION_REGEX, DOM_SIZE_UNITS, Extension = class Extension2 {
146443
146561
  }
146444
146562
  };
146445
146563
  };
146446
- var init_create_headless_toolbar_Btizo_Im_es = __esm(() => {
146447
- init_SuperConverter_CnwfJPj6_es();
146564
+ var init_create_headless_toolbar_DCioTQPP_es = __esm(() => {
146565
+ init_SuperConverter_BLUJyRB9_es();
146448
146566
  init_constants_DrU4EASo_es();
146449
146567
  init_dist_B8HfvhaK_es();
146450
146568
  CSS_DIMENSION_REGEX = /[\d-.]+(\w+)$/;
@@ -200676,7 +200794,7 @@ var init_remark_gfm_eZN6yzWQ_es = __esm(() => {
200676
200794
  init_remark_gfm_BhnWr3yf_es();
200677
200795
  });
200678
200796
 
200679
- // ../../packages/superdoc/dist/chunks/src-DnrLgjeO.es.js
200797
+ // ../../packages/superdoc/dist/chunks/src-CLqPyVCp.es.js
200680
200798
  function deleteProps(obj, propOrProps) {
200681
200799
  const props = typeof propOrProps === "string" ? [propOrProps] : propOrProps;
200682
200800
  const removeNested = (target, pathParts, index2 = 0) => {
@@ -211432,10 +211550,9 @@ function slotsEqual(previous3, next2) {
211432
211550
  function toRelsPathForPart2(partPath) {
211433
211551
  if (partPath === DOCUMENT_RELS_PATH$2 || partPath.endsWith(".rels"))
211434
211552
  return null;
211435
- const lastSlash = partPath.lastIndexOf("/");
211436
- if (lastSlash < 0 || lastSlash === partPath.length - 1)
211553
+ if (!partPath.includes("/") || partPath.endsWith("/"))
211437
211554
  return null;
211438
- return `${partPath.slice(0, lastSlash)}/_rels/${partPath.slice(lastSlash + 1)}.rels`;
211555
+ return getWordPartRelsPath(partPath);
211439
211556
  }
211440
211557
  function capturePartsState(editor, headerFooters) {
211441
211558
  const convertedXml = editor.converter?.convertedXml ?? {};
@@ -232356,7 +232473,7 @@ function syncHeaderFooterCaches(editor, part) {
232356
232473
  const converter = getConverter$52(editor);
232357
232474
  if (!converter)
232358
232475
  return;
232359
- const relsRoot = part?.elements?.find((el) => el.name === "Relationships");
232476
+ const relsRoot = getRelationshipsRoot(part);
232360
232477
  if (!relsRoot?.elements)
232361
232478
  return;
232362
232479
  let changed = false;
@@ -237686,9 +237803,7 @@ function headerFootersPartsDeleteAdapter(editor, input2, options) {
237686
237803
  root3.elements = root3.elements.filter((e) => !(e.name === "Relationship" && String(e.attributes?.Id ?? "") === refId));
237687
237804
  }
237688
237805
  delete convertedXml[partPath];
237689
- const partFileName = partPath.split("/").pop();
237690
- if (partFileName)
237691
- delete convertedXml[`word/_rels/${partFileName}.rels`];
237806
+ delete convertedXml[getWordPartRelsPath(partPath)];
237692
237807
  const collection = kind === "header" ? converter.headers : converter.footers;
237693
237808
  if (collection && typeof collection === "object")
237694
237809
  delete collection[refId];
@@ -279059,7 +279174,7 @@ var Node$13 = class Node$14 {
279059
279174
  listener(snapshot2);
279060
279175
  } catch {}
279061
279176
  }
279062
- }, TRACK_MARK_TYPE_BY_NAME, EMITTABLE_BLOCK_TYPES, SDT_BLOCK_NODE_NAMES, REQUIRED_COMMANDS, VALID_CAPABILITY_REASON_CODES, REQUIRED_HELPERS, SCHEMA_NODE_GATES, schemaGatedIds, SUPPORTED_NON_UNIFORM_STRATEGIES, SUPPORTED_SET_MARKS, REGEX_MAX_PATTERN_LENGTH = 1024, STYLES_PART = "word/styles.xml", PROPERTIES_KEY_BY_CHANNEL, XML_PATH_BY_CHANNEL, UNDERLINE_API_TO_STORAGE, UNDERLINE_STORAGE_TO_API, HEX_SUBKEYS_BY_PROPERTY, SUPPORTED_DELETE_NODE_TYPES2, REJECTED_DELETE_NODE_TYPES2, TEXT_PREVIEW_MAX_LENGTH = 80, RANGE_DELETE_SAFE_NODE_TYPES, HEADING_PATTERN, OOXML_DEFAULT_FONT_SIZE_PT = 10, INDENT_PER_LEVEL_TWIPS = 720, HANGING_INDENT_TWIPS = 360, SYMBOL_FONT_NAMES, RFONTS_FAMILY_ATTRS, ORDERED_PRESET_CONFIG, BULLET_PRESET_CONFIG, PRESET_TEMPLATES, LevelFormattingHelpers, PRESET_KIND_MAP, NUMBERING_PART = "word/numbering.xml", DEFAULT_PRESET_FOR_KIND, _setValueDelegate, PREVIEW_TEXT_MAX_LENGTH = 2000, BLOCK_PREVIEW_MAX_LENGTH = 200, EDGE_NODE_TYPES$1, COMMENT_MARK_NAME2 = "commentMark", TRACK_CHANGE_MARK_NAMES, POINTS_TO_PIXELS, POINTS_TO_TWIPS = 20, PIXELS_TO_TWIPS, DEFAULT_TABLE_GRID_WIDTH_TWIPS = 1500, SETTINGS_PART$1 = "word/settings.xml", PRESET_GREY = "999999", PRESET_BLACK = "000000", STATIC_PRESETS, IDENTITY_BLOCK_ATTRS, WORD_DEFAULT_TBL_LOOK, FLAG_TO_OOXML_KEY, INVERTED_FLAGS, XML_KEY_TO_STYLE_OPTION, CLEARED_BORDER_OOXML, TABLE_MARGIN_KEY_GROUPS, TABLE_ADAPTER_DISPATCH, ROW_TARGETED_TABLE_OPS, registered = false, STYLES_PART_ID = "word/styles.xml", stylesPartDescriptor, settingsPartDescriptor, RELS_PART_ID2 = "word/_rels/document.xml.rels", RELS_XMLNS2 = "http://schemas.openxmlformats.org/package/2006/relationships", HEADER_RELATIONSHIP_TYPE$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", relsPartDescriptor, BatchHistoryAdapter = class {
279177
+ }, TRACK_MARK_TYPE_BY_NAME, EMITTABLE_BLOCK_TYPES, SDT_BLOCK_NODE_NAMES, REQUIRED_COMMANDS, VALID_CAPABILITY_REASON_CODES, REQUIRED_HELPERS, SCHEMA_NODE_GATES, schemaGatedIds, SUPPORTED_NON_UNIFORM_STRATEGIES, SUPPORTED_SET_MARKS, REGEX_MAX_PATTERN_LENGTH = 1024, STYLES_PART = "word/styles.xml", PROPERTIES_KEY_BY_CHANNEL, XML_PATH_BY_CHANNEL, UNDERLINE_API_TO_STORAGE, UNDERLINE_STORAGE_TO_API, HEX_SUBKEYS_BY_PROPERTY, SUPPORTED_DELETE_NODE_TYPES2, REJECTED_DELETE_NODE_TYPES2, TEXT_PREVIEW_MAX_LENGTH = 80, RANGE_DELETE_SAFE_NODE_TYPES, HEADING_PATTERN, OOXML_DEFAULT_FONT_SIZE_PT = 10, INDENT_PER_LEVEL_TWIPS = 720, HANGING_INDENT_TWIPS = 360, SYMBOL_FONT_NAMES, RFONTS_FAMILY_ATTRS, ORDERED_PRESET_CONFIG, BULLET_PRESET_CONFIG, PRESET_TEMPLATES, LevelFormattingHelpers, PRESET_KIND_MAP, NUMBERING_PART = "word/numbering.xml", DEFAULT_PRESET_FOR_KIND, _setValueDelegate, PREVIEW_TEXT_MAX_LENGTH = 2000, BLOCK_PREVIEW_MAX_LENGTH = 200, EDGE_NODE_TYPES$1, COMMENT_MARK_NAME2 = "commentMark", TRACK_CHANGE_MARK_NAMES, POINTS_TO_PIXELS, POINTS_TO_TWIPS = 20, PIXELS_TO_TWIPS, DEFAULT_TABLE_GRID_WIDTH_TWIPS = 1500, SETTINGS_PART$1 = "word/settings.xml", PRESET_GREY = "999999", PRESET_BLACK = "000000", STATIC_PRESETS, IDENTITY_BLOCK_ATTRS, WORD_DEFAULT_TBL_LOOK, FLAG_TO_OOXML_KEY, INVERTED_FLAGS, XML_KEY_TO_STYLE_OPTION, CLEARED_BORDER_OOXML, TABLE_MARGIN_KEY_GROUPS, TABLE_ADAPTER_DISPATCH, ROW_TARGETED_TABLE_OPS, registered = false, STYLES_PART_ID = "word/styles.xml", stylesPartDescriptor, settingsPartDescriptor, RELS_PART_ID2 = "word/_rels/document.xml.rels", HEADER_RELATIONSHIP_TYPE$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE$1 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", relsPartDescriptor, BatchHistoryAdapter = class {
279063
279178
  #done = [];
279064
279179
  #redone = [];
279065
279180
  #listeners = /* @__PURE__ */ new Set;
@@ -293382,6 +293497,7 @@ menclose::after {
293382
293497
  totalPageCount,
293383
293498
  element: editorContainer,
293384
293499
  editorOptions: {
293500
+ headerFooterRefId,
293385
293501
  headerFooterType: type,
293386
293502
  onCreate: (evt) => setEditorToolbar(evt, editor),
293387
293503
  onBlur: (evt) => onHeaderFooterDataUpdate(evt, editor, headerFooterRefId, type)
@@ -295430,6 +295546,16 @@ menclose::after {
295430
295546
  cursor: grabbing;
295431
295547
  }
295432
295548
 
295549
+ /* Header/footer decoration containers are pointer-events:none; keep images targetable for hover/resize. */
295550
+ .superdoc-layout .superdoc-page-header .superdoc-image-fragment,
295551
+ .superdoc-layout .superdoc-page-footer .superdoc-image-fragment,
295552
+ .superdoc-layout .superdoc-page-header .superdoc-inline-image-clip-wrapper,
295553
+ .superdoc-layout .superdoc-page-footer .superdoc-inline-image-clip-wrapper,
295554
+ .superdoc-layout .superdoc-page-header .superdoc-inline-image,
295555
+ .superdoc-layout .superdoc-page-footer .superdoc-inline-image {
295556
+ pointer-events: auto;
295557
+ }
295558
+
295433
295559
  /* Keep the active drag source from selecting text while dragging */
295434
295560
  .superdoc-layout .superdoc-structured-content__label,
295435
295561
  .superdoc-layout .superdoc-structured-content-inline__label,
@@ -295445,13 +295571,13 @@ menclose::after {
295445
295571
  return;
295446
295572
  console.log(...args$1);
295447
295573
  }, HEADER_FOOTER_INIT_BUDGET_MS = 200, MAX_ZOOM_WARNING_THRESHOLD = 10, MAX_SELECTION_RECTS_PER_USER = 100, SEMANTIC_RESIZE_DEBOUNCE_MS = 120, MIN_SEMANTIC_CONTENT_WIDTH_PX = 1, GLOBAL_PERFORMANCE, PresentationEditor, ICONS, TEXTS, tableActionsOptions;
295448
- var init_src_DnrLgjeO_es = __esm(() => {
295574
+ var init_src_CLqPyVCp_es = __esm(() => {
295449
295575
  init_rolldown_runtime_Bg48TavK_es();
295450
- init_SuperConverter_CnwfJPj6_es();
295576
+ init_SuperConverter_BLUJyRB9_es();
295451
295577
  init_jszip_C49i9kUs_es();
295452
295578
  init_xml_js_CqGKpaft_es();
295453
295579
  init_uuid_qzgm05fK_es();
295454
- init_create_headless_toolbar_Btizo_Im_es();
295580
+ init_create_headless_toolbar_DCioTQPP_es();
295455
295581
  init_constants_DrU4EASo_es();
295456
295582
  init_dist_B8HfvhaK_es();
295457
295583
  init_unified_Dsuw2be5_es();
@@ -319427,16 +319553,7 @@ function print() { __p += __j.call(arguments, '') }
319427
319553
  relsPartDescriptor = {
319428
319554
  id: RELS_PART_ID2,
319429
319555
  ensurePart() {
319430
- return {
319431
- type: "element",
319432
- name: "document",
319433
- elements: [{
319434
- type: "element",
319435
- name: "Relationships",
319436
- attributes: { xmlns: RELS_XMLNS2 },
319437
- elements: []
319438
- }]
319439
- };
319556
+ return createRelationshipsPart();
319440
319557
  },
319441
319558
  afterCommit({ editor, part }) {
319442
319559
  syncHeaderFooterCaches(editor, part);
@@ -321034,7 +321151,11 @@ function print() { __p += __j.call(arguments, '') }
321034
321151
  this.view.setProps({ nodeViews: this.extensionService.nodeViews });
321035
321152
  }
321036
321153
  getMaxContentSize() {
321037
- if (!this.converter)
321154
+ const localPageStyles = this.converter?.pageStyles;
321155
+ const parentPageStyles = this.options.parentEditor?.converter?.pageStyles;
321156
+ const localPageSize = localPageStyles?.pageSize;
321157
+ const pageStyles$1 = localPageSize?.width && localPageSize?.height ? localPageStyles : parentPageStyles ?? localPageStyles;
321158
+ if (!pageStyles$1)
321038
321159
  return {};
321039
321160
  let cellConstraintWidth = 0;
321040
321161
  const { $head } = this.state.selection;
@@ -321053,7 +321174,7 @@ function print() { __p += __j.call(arguments, '') }
321053
321174
  };
321054
321175
  return {};
321055
321176
  }
321056
- const { pageSize = {}, pageMargins = {} } = this.converter.pageStyles ?? {};
321177
+ const { pageSize = {}, pageMargins = {} } = pageStyles$1;
321057
321178
  const { width, height } = pageSize;
321058
321179
  if (!width || !height)
321059
321180
  return {};
@@ -330378,13 +330499,15 @@ function print() { __p += __j.call(arguments, '') }
330378
330499
  const { runtime, hostElement, activationOptions } = input2;
330379
330500
  const editorContext = activationOptions.editorContext ?? {};
330380
330501
  const pmJson = runtime.editor.getJSON();
330502
+ const headerFooterRefId = runtime.locator.storyType === "headerFooterPart" ? runtime.locator.refId : undefined;
330381
330503
  const fresh = createStoryEditor(this.#editor, pmJson, {
330382
330504
  documentId: runtime.storyKey,
330383
330505
  isHeaderOrFooter: runtime.kind === "headerFooter",
330384
330506
  headless: false,
330385
330507
  element: hostElement,
330386
330508
  currentPageNumber: editorContext.currentPageNumber,
330387
- totalPageCount: editorContext.totalPageCount
330509
+ totalPageCount: editorContext.totalPageCount,
330510
+ editorOptions: headerFooterRefId ? { headerFooterRefId } : undefined
330388
330511
  });
330389
330512
  return {
330390
330513
  editor: fresh,
@@ -333618,11 +333741,11 @@ function print() { __p += __j.call(arguments, '') }
333618
333741
  ];
333619
333742
  });
333620
333743
 
333621
- // ../../packages/superdoc/dist/chunks/create-super-doc-ui-BgATtiYQ.es.js
333744
+ // ../../packages/superdoc/dist/chunks/create-super-doc-ui-6HZGNd4y.es.js
333622
333745
  var MOD_ALIASES, ALT_ALIASES, CTRL_ALIASES, SHIFT_ALIASES, BUILTIN_CONTEXT_MENU_GROUPS, BUILTIN_GROUP_ORDER, RESERVED_PROXY_PROPERTY_NAMES, ALL_TOOLBAR_COMMAND_IDS, EMPTY_ACTIVE_IDS;
333623
- var init_create_super_doc_ui_BgATtiYQ_es = __esm(() => {
333624
- init_SuperConverter_CnwfJPj6_es();
333625
- init_create_headless_toolbar_Btizo_Im_es();
333746
+ var init_create_super_doc_ui_6HZGNd4y_es = __esm(() => {
333747
+ init_SuperConverter_BLUJyRB9_es();
333748
+ init_create_headless_toolbar_DCioTQPP_es();
333626
333749
  MOD_ALIASES = new Set([
333627
333750
  "Mod",
333628
333751
  "Meta",
@@ -333664,16 +333787,16 @@ var init_zipper_yaJVJ4z9_es = __esm(() => {
333664
333787
 
333665
333788
  // ../../packages/superdoc/dist/super-editor.es.js
333666
333789
  var init_super_editor_es = __esm(() => {
333667
- init_src_DnrLgjeO_es();
333668
- init_SuperConverter_CnwfJPj6_es();
333790
+ init_src_CLqPyVCp_es();
333791
+ init_SuperConverter_BLUJyRB9_es();
333669
333792
  init_jszip_C49i9kUs_es();
333670
333793
  init_xml_js_CqGKpaft_es();
333671
- init_create_headless_toolbar_Btizo_Im_es();
333794
+ init_create_headless_toolbar_DCioTQPP_es();
333672
333795
  init_constants_DrU4EASo_es();
333673
333796
  init_dist_B8HfvhaK_es();
333674
333797
  init_unified_Dsuw2be5_es();
333675
333798
  init_DocxZipper_DoY5OEjc_es();
333676
- init_create_super_doc_ui_BgATtiYQ_es();
333799
+ init_create_super_doc_ui_6HZGNd4y_es();
333677
333800
  init_ui_C5PAS9hY_es();
333678
333801
  init_eventemitter3_BnGqBE_Q_es();
333679
333802
  init_errors_CNaD6vcg_es();
@@ -370985,6 +371108,23 @@ var init_invalidation_handlers = __esm(() => {
370985
371108
  init_document_settings();
370986
371109
  });
370987
371110
 
371111
+ // ../../packages/super-editor/src/editors/v1/core/helpers/word-part-path.js
371112
+ function normalizeWordPartPath2(target = "") {
371113
+ const normalized = String(target).replace(/\\/g, "/").replace(/^(\.\/|\/)+/, "").replace(/^word\//, "");
371114
+ return `word/${normalized}`;
371115
+ }
371116
+ function getWordPartRelsPath2(partPath = "") {
371117
+ const normalized = String(partPath).replace(/\\/g, "/");
371118
+ const lastSlash = normalized.lastIndexOf("/");
371119
+ if (lastSlash < 0 || lastSlash === normalized.length - 1) {
371120
+ const fileName2 = lastSlash < 0 ? normalized : normalized.slice(lastSlash + 1);
371121
+ return `word/_rels/${fileName2}.rels`;
371122
+ }
371123
+ const directory = normalized.slice(0, lastSlash);
371124
+ const fileName = normalized.slice(lastSlash + 1);
371125
+ return `${directory}/_rels/${fileName}.rels`;
371126
+ }
371127
+
370988
371128
  // ../../packages/super-editor/src/editors/v1/document-api-adapters/helpers/header-footer-parts.ts
370989
371129
  function getConverterForHeaderFooter2(editor) {
370990
371130
  return editor.converter;
@@ -371009,11 +371149,7 @@ function normalizeRelationshipTarget2(target) {
371009
371149
  return normalized;
371010
371150
  }
371011
371151
  function toRelsPathForPart3(partPath) {
371012
- const normalized = normalizeRelationshipTarget2(partPath);
371013
- const fileName = normalized.split("/").pop();
371014
- if (!fileName)
371015
- return normalized;
371016
- return `word/_rels/${fileName}.rels`;
371152
+ return getWordPartRelsPath2(normalizeRelationshipTarget2(partPath));
371017
371153
  }
371018
371154
  function ensureConvertedXml2(converter) {
371019
371155
  if (!converter.convertedXml || typeof converter.convertedXml !== "object") {
@@ -371195,7 +371331,7 @@ function createHeaderFooterPart2(editor, input2) {
371195
371331
  root3.elements = [];
371196
371332
  let relsRoot = root3.elements.find((el) => el.name === "Relationships");
371197
371333
  if (!relsRoot) {
371198
- relsRoot = { type: "element", name: "Relationships", attributes: { xmlns: RELS_XMLNS3 }, elements: [] };
371334
+ relsRoot = { type: "element", name: "Relationships", attributes: { xmlns: RELS_XMLNS2 }, elements: [] };
371199
371335
  root3.elements.push(relsRoot);
371200
371336
  }
371201
371337
  if (!relsRoot.elements)
@@ -371237,7 +371373,7 @@ function createHeaderFooterPart2(editor, input2) {
371237
371373
  }
371238
371374
  return finalResult;
371239
371375
  }
371240
- var DOCUMENT_RELS_PATH3 = "word/_rels/document.xml.rels", RELS_XMLNS3 = "http://schemas.openxmlformats.org/package/2006/relationships", HEADER_RELATIONSHIP_TYPE4 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE4 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", WORDPROCESSINGML_XMLNS2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", OFFICE_DOCUMENT_RELS_XMLNS2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", RELATIONSHIP_ID_PATTERN2, HEADER_FILE_PATTERN3, FOOTER_FILE_PATTERN3;
371376
+ var DOCUMENT_RELS_PATH3 = "word/_rels/document.xml.rels", RELS_XMLNS2 = "http://schemas.openxmlformats.org/package/2006/relationships", HEADER_RELATIONSHIP_TYPE4 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE4 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", WORDPROCESSINGML_XMLNS2 = "http://schemas.openxmlformats.org/wordprocessingml/2006/main", OFFICE_DOCUMENT_RELS_XMLNS2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships", RELATIONSHIP_ID_PATTERN2, HEADER_FILE_PATTERN3, FOOTER_FILE_PATTERN3;
371241
371377
  var init_header_footer_parts = __esm(() => {
371242
371378
  init_mutate_part();
371243
371379
  init_compound_mutation();
@@ -371564,10 +371700,40 @@ var init_header_footer_part_descriptor = __esm(() => {
371564
371700
  };
371565
371701
  });
371566
371702
 
371703
+ // ../../packages/super-editor/src/editors/v1/core/helpers/rels-part-helpers.js
371704
+ function getRelationshipsRoot2(part) {
371705
+ if (!part || typeof part !== "object")
371706
+ return;
371707
+ if (part.name === "Relationships")
371708
+ return part;
371709
+ const children = part.elements;
371710
+ if (!Array.isArray(children))
371711
+ return;
371712
+ return children.find((el) => el?.name === "Relationships");
371713
+ }
371714
+ function createRelationshipsPart2(elements = []) {
371715
+ return {
371716
+ type: "element",
371717
+ name: "Relationships",
371718
+ attributes: { xmlns: RELS_XMLNS3 },
371719
+ elements
371720
+ };
371721
+ }
371722
+ var RELS_XMLNS3 = "http://schemas.openxmlformats.org/package/2006/relationships";
371723
+
371567
371724
  // ../../packages/super-editor/src/editors/v1/core/parts/adapters/header-footer-sync.ts
371568
371725
  function getConverter8(editor) {
371569
371726
  return editor.converter;
371570
371727
  }
371728
+ function normalizeHeaderFooterPartPath2(target = "") {
371729
+ return normalizeWordPartPath2(target);
371730
+ }
371731
+ function getHeaderFooterRelsPartId2(partId) {
371732
+ return getWordPartRelsPath2(partId);
371733
+ }
371734
+ function getRelationshipElements3(part) {
371735
+ return getRelationshipsRoot2(part)?.elements ?? [];
371736
+ }
371571
371737
  function resolvePartIdFromRefId2(editor, headerFooterRefId) {
371572
371738
  const converter = getConverter8(editor);
371573
371739
  const relsPart = converter?.convertedXml?.["word/_rels/document.xml.rels"];
@@ -371585,7 +371751,7 @@ function resolvePartIdFromRefId2(editor, headerFooterRefId) {
371585
371751
  const target = el.attributes?.Target;
371586
371752
  if (!target)
371587
371753
  continue;
371588
- return `word/${target}`;
371754
+ return normalizeHeaderFooterPartPath2(target);
371589
371755
  }
371590
371756
  return null;
371591
371757
  }
@@ -371615,6 +371781,8 @@ function exportSubEditorToPart2(mainEditor, subEditor, headerFooterRefId, type)
371615
371781
  if (!partId)
371616
371782
  return false;
371617
371783
  ensureHeaderFooterDescriptor2(partId, headerFooterRefId);
371784
+ const relsPartId = getHeaderFooterRelsPartId2(partId);
371785
+ const existingRelationships = getRelationshipElements3(converter.convertedXml?.[relsPartId]);
371618
371786
  const pmJson = typeof subEditor.getUpdatedJson === "function" ? subEditor.getUpdatedJson() : converter[`${type}s`]?.[headerFooterRefId];
371619
371787
  if (!pmJson)
371620
371788
  return false;
@@ -371626,7 +371794,8 @@ function exportSubEditorToPart2(mainEditor, subEditor, headerFooterRefId, type)
371626
371794
  editorSchema: subEditor.schema,
371627
371795
  isHeaderFooter: true,
371628
371796
  comments: [],
371629
- commentDefinitions: []
371797
+ commentDefinitions: [],
371798
+ existingRelationships
371630
371799
  });
371631
371800
  bodyContent = result?.elements?.[0]?.elements ?? [];
371632
371801
  } catch (err) {
@@ -371869,7 +372038,7 @@ function cleanupCreatedPart2(editor, partPath) {
371869
372038
  if (hasPart2(editor, partId))
371870
372039
  removePart2(editor, partId);
371871
372040
  removeInvalidationHandler2(partId);
371872
- const relsPath = `word/_rels/${partPath.split("/").pop()}.rels`;
372041
+ const relsPath = getWordPartRelsPath2(partPath);
371873
372042
  if (hasPart2(editor, relsPath))
371874
372043
  removePart2(editor, relsPath);
371875
372044
  }
@@ -415736,12 +415905,28 @@ function addImageRelationshipForId2(params3, id2, imagePath) {
415736
415905
  name: "Relationship",
415737
415906
  attributes: {
415738
415907
  Id: id2,
415739
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
415908
+ Type: IMAGE_REL_TYPE2,
415740
415909
  Target: imagePath
415741
415910
  }
415742
415911
  };
415743
415912
  params3.relationships.push(newRel);
415744
415913
  }
415914
+ function getDocumentRelationships2(params3) {
415915
+ const docx = params3.converter?.convertedXml || {};
415916
+ const rels = docx["word/_rels/document.xml.rels"];
415917
+ return rels?.elements?.find((el) => el.name === "Relationships")?.elements ?? [];
415918
+ }
415919
+ function findImageRelationship2(relationships = [], { id: id2, target }) {
415920
+ return relationships.find((rel) => {
415921
+ if (rel?.attributes?.Type !== IMAGE_REL_TYPE2)
415922
+ return false;
415923
+ if (id2)
415924
+ return rel.attributes.Id === id2;
415925
+ if (target)
415926
+ return rel.attributes.Target === target;
415927
+ return false;
415928
+ });
415929
+ }
415745
415930
  function translateVectorShape2(params3) {
415746
415931
  const { node: node4 } = params3;
415747
415932
  const { drawingContent } = node4.attrs;
@@ -415784,7 +415969,7 @@ function translateShapeGroup2(params3) {
415784
415969
  elements: []
415785
415970
  });
415786
415971
  }
415787
- var DECORATIVE_EXT_URI2 = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_NAMESPACE2 = "http://schemas.microsoft.com/office/drawing/2017/decorative", HYPERLINK_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", translateImageNode2 = (params3) => {
415972
+ var DECORATIVE_EXT_URI2 = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_NAMESPACE2 = "http://schemas.microsoft.com/office/drawing/2017/decorative", HYPERLINK_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/hyperlink", IMAGE_REL_TYPE2 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image", translateImageNode2 = (params3) => {
415788
415973
  const {
415789
415974
  node: { attrs = {} },
415790
415975
  tableCell: tableCell2,
@@ -415832,12 +416017,15 @@ var DECORATIVE_EXT_URI2 = "{C183D7F6-B498-43B3-948B-1728B52AA6E4}", DECORATIVE_N
415832
416017
  size3 = { w, h: h3 };
415833
416018
  }
415834
416019
  if (imageId) {
415835
- const docx = params3.converter?.convertedXml || {};
415836
- const rels = docx["word/_rels/document.xml.rels"];
415837
- const relsTag = rels?.elements?.find((el) => el.name === "Relationships");
415838
- const hasRelation = relsTag?.elements.find((el) => el.attributes.Id === imageId);
415839
416020
  const path3 = src?.split("word/")[1];
415840
- if (!hasRelation) {
416021
+ const relationships = params3.isHeaderFooter ? params3.existingRelationships : getDocumentRelationships2(params3);
416022
+ const existingRelation = findImageRelationship2(relationships, {
416023
+ id: imageId,
416024
+ target: path3
416025
+ });
416026
+ if (existingRelation) {
416027
+ imageId = existingRelation.attributes.Id;
416028
+ } else {
415841
416029
  addImageRelationshipForId2(params3, imageId, path3);
415842
416030
  }
415843
416031
  } else if (params3.node.type === "image" && !imageId) {
@@ -416788,7 +416976,7 @@ var init_docx_constants = __esm(() => {
416788
416976
 
416789
416977
  // ../../packages/super-editor/src/editors/v1/core/parts/adapters/relationships-mutation.ts
416790
416978
  function getRelationshipsTag2(part) {
416791
- const tag = part?.elements?.find((el) => el.name === "Relationships");
416979
+ const tag = getRelationshipsRoot2(part);
416792
416980
  if (tag && !tag.elements)
416793
416981
  tag.elements = [];
416794
416982
  return tag;
@@ -416808,8 +416996,26 @@ function getMaxIdInt2(elements) {
416808
416996
  }
416809
416997
  return max3;
416810
416998
  }
416999
+ function createRelationshipElement2(id2, mappedType, target, isExternal) {
417000
+ const rel = {
417001
+ type: "element",
417002
+ name: "Relationship",
417003
+ attributes: {
417004
+ Id: id2,
417005
+ Type: mappedType,
417006
+ Target: target
417007
+ }
417008
+ };
417009
+ if (isExternal) {
417010
+ rel.attributes.TargetMode = "External";
417011
+ }
417012
+ return rel;
417013
+ }
417014
+ function findExistingRelationship2(elements, target, normalized, mappedType) {
417015
+ return elements.find((rel) => (rel.attributes?.Target === normalized || rel.attributes?.Target === target) && rel.attributes?.Type === mappedType);
417016
+ }
416811
417017
  function findOrCreateRelationship2(editor, source, options) {
416812
- const { target, type, dryRun, expectedRevision } = options;
417018
+ const { target, type, partId = RELS_PART_ID3, dryRun, expectedRevision } = options;
416813
417019
  if (!target || typeof target !== "string")
416814
417020
  return null;
416815
417021
  if (!type || typeof type !== "string")
@@ -416821,9 +417027,23 @@ function findOrCreateRelationship2(editor, source, options) {
416821
417027
  }
416822
417028
  const normalized = normalizeTarget3(target);
416823
417029
  const isExternal = type === "hyperlink";
417030
+ if (!hasPart2(editor, partId)) {
417031
+ const newId = "rId1";
417032
+ const targetValue = isExternal ? target : normalized;
417033
+ mutatePart2({
417034
+ editor,
417035
+ partId,
417036
+ operation: "create",
417037
+ source,
417038
+ dryRun,
417039
+ expectedRevision,
417040
+ initial: createRelationshipsPart2([createRelationshipElement2(newId, mappedType, targetValue, isExternal)])
417041
+ });
417042
+ return newId;
417043
+ }
416824
417044
  const result = mutatePart2({
416825
417045
  editor,
416826
- partId: RELS_PART_ID3,
417046
+ partId,
416827
417047
  operation: "mutate",
416828
417048
  source,
416829
417049
  dryRun,
@@ -416832,26 +417052,12 @@ function findOrCreateRelationship2(editor, source, options) {
416832
417052
  const tag = getRelationshipsTag2(part);
416833
417053
  if (!tag)
416834
417054
  return null;
416835
- const existing = tag.elements.find((rel) => rel.attributes?.Target === normalized && rel.attributes?.Type === mappedType);
417055
+ const existing = findExistingRelationship2(tag.elements, target, normalized, mappedType);
416836
417056
  if (existing)
416837
417057
  return existing.attributes.Id;
416838
- const existingRaw = tag.elements.find((rel) => rel.attributes?.Target === target && rel.attributes?.Type === mappedType);
416839
- if (existingRaw)
416840
- return existingRaw.attributes.Id;
416841
417058
  const newIdInt = getMaxIdInt2(tag.elements) + 1;
416842
417059
  const newId = `rId${newIdInt}`;
416843
- const newRel = {
416844
- type: "element",
416845
- name: "Relationship",
416846
- attributes: {
416847
- Id: newId,
416848
- Type: mappedType,
416849
- Target: isExternal ? target : normalized
416850
- }
416851
- };
416852
- if (isExternal) {
416853
- newRel.attributes.TargetMode = "External";
416854
- }
417060
+ const newRel = createRelationshipElement2(newId, mappedType, isExternal ? target : normalized, isExternal);
416855
417061
  tag.elements.push(newRel);
416856
417062
  return newId;
416857
417063
  }
@@ -429762,7 +429968,8 @@ var init_SuperConverter = __esm(() => {
429762
429968
  isHeaderFooter = false,
429763
429969
  fieldsHighlightColor = null,
429764
429970
  preserveSdtWrappers = false,
429765
- statFieldCacheMap = undefined
429971
+ statFieldCacheMap = undefined,
429972
+ existingRelationships = []
429766
429973
  }) {
429767
429974
  const bodyNode = this.savedTagsToRestore.find((el) => el.name === "w:body");
429768
429975
  let resolvedCacheMap = statFieldCacheMap ?? this._currentStatFieldCacheMap;
@@ -429790,7 +429997,8 @@ var init_SuperConverter = __esm(() => {
429790
429997
  isHeaderFooter,
429791
429998
  fieldsHighlightColor,
429792
429999
  preserveSdtWrappers,
429793
- statFieldCacheMap: resolvedCacheMap
430000
+ statFieldCacheMap: resolvedCacheMap,
430001
+ existingRelationships
429794
430002
  });
429795
430003
  return { result, params: params3 };
429796
430004
  }
@@ -429887,8 +430095,11 @@ var init_SuperConverter = __esm(() => {
429887
430095
  const relationships = relsData.elements.find((x) => x.name === "Relationships");
429888
430096
  const newDocRels = [];
429889
430097
  Object.entries(this.headers).forEach(([id2, header], index3) => {
429890
- const fileName = relationships.elements.find((el) => el.attributes.Id === id2)?.attributes.Target || `header${index3 + 1}.xml`;
430098
+ const relationshipTarget = relationships.elements.find((el) => el.attributes.Id === id2)?.attributes.Target || `header${index3 + 1}.xml`;
430099
+ const partPath = normalizeWordPartPath2(relationshipTarget);
430100
+ const relsPath = getWordPartRelsPath2(partPath);
429891
430101
  const headerEditor = this.headerEditors.find((item) => item.id === id2);
430102
+ const existingRelationships = this.convertedXml[relsPath]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
429892
430103
  if (!headerEditor)
429893
430104
  return;
429894
430105
  const { result, params: params3 } = this.exportToXmlJson({
@@ -429898,12 +430109,13 @@ var init_SuperConverter = __esm(() => {
429898
430109
  comments: [],
429899
430110
  commentDefinitions: [],
429900
430111
  isHeaderFooter: true,
429901
- isFinalDoc
430112
+ isFinalDoc,
430113
+ existingRelationships
429902
430114
  });
429903
430115
  const bodyContent = result.elements[0].elements;
429904
- const file2 = this.convertedXml[`word/${fileName}`];
430116
+ const file2 = this.convertedXml[partPath];
429905
430117
  if (!file2) {
429906
- this.convertedXml[`word/${fileName}`] = {
430118
+ this.convertedXml[partPath] = {
429907
430119
  declaration: this.initialJSON?.declaration,
429908
430120
  elements: [
429909
430121
  {
@@ -429920,14 +430132,13 @@ var init_SuperConverter = __esm(() => {
429920
430132
  attributes: {
429921
430133
  Id: id2,
429922
430134
  Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header",
429923
- Target: fileName
430135
+ Target: partPath.replace(/^word\//, "")
429924
430136
  }
429925
430137
  });
429926
430138
  }
429927
- this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
430139
+ this.convertedXml[partPath].elements[0].elements = bodyContent;
429928
430140
  if (params3.relationships.length) {
429929
- const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
429930
- this.convertedXml[`word/_rels/${fileName}.rels`] = {
430141
+ this.convertedXml[relsPath] = {
429931
430142
  declaration: this.initialJSON?.declaration,
429932
430143
  elements: [
429933
430144
  {
@@ -429935,15 +430146,18 @@ var init_SuperConverter = __esm(() => {
429935
430146
  attributes: {
429936
430147
  xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
429937
430148
  },
429938
- elements: [...relationships2, ...params3.relationships]
430149
+ elements: mergeRelationshipElements2(existingRelationships, params3.relationships)
429939
430150
  }
429940
430151
  ]
429941
430152
  };
429942
430153
  }
429943
430154
  });
429944
430155
  Object.entries(this.footers).forEach(([id2, footer], index3) => {
429945
- const fileName = relationships.elements.find((el) => el.attributes.Id === id2)?.attributes.Target || `footer${index3 + 1}.xml`;
430156
+ const relationshipTarget = relationships.elements.find((el) => el.attributes.Id === id2)?.attributes.Target || `footer${index3 + 1}.xml`;
430157
+ const partPath = normalizeWordPartPath2(relationshipTarget);
430158
+ const relsPath = getWordPartRelsPath2(partPath);
429946
430159
  const footerEditor = this.footerEditors.find((item) => item.id === id2);
430160
+ const existingRelationships = this.convertedXml[relsPath]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
429947
430161
  if (!footerEditor)
429948
430162
  return;
429949
430163
  const { result, params: params3 } = this.exportToXmlJson({
@@ -429953,12 +430167,13 @@ var init_SuperConverter = __esm(() => {
429953
430167
  comments: [],
429954
430168
  commentDefinitions: [],
429955
430169
  isHeaderFooter: true,
429956
- isFinalDoc
430170
+ isFinalDoc,
430171
+ existingRelationships
429957
430172
  });
429958
430173
  const bodyContent = result.elements[0].elements;
429959
- const file2 = this.convertedXml[`word/${fileName}`];
430174
+ const file2 = this.convertedXml[partPath];
429960
430175
  if (!file2) {
429961
- this.convertedXml[`word/${fileName}`] = {
430176
+ this.convertedXml[partPath] = {
429962
430177
  declaration: this.initialJSON?.declaration,
429963
430178
  elements: [
429964
430179
  {
@@ -429975,14 +430190,13 @@ var init_SuperConverter = __esm(() => {
429975
430190
  attributes: {
429976
430191
  Id: id2,
429977
430192
  Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer",
429978
- Target: fileName
430193
+ Target: partPath.replace(/^word\//, "")
429979
430194
  }
429980
430195
  });
429981
430196
  }
429982
- this.convertedXml[`word/${fileName}`].elements[0].elements = bodyContent;
430197
+ this.convertedXml[partPath].elements[0].elements = bodyContent;
429983
430198
  if (params3.relationships.length) {
429984
- const relationships2 = this.convertedXml[`word/_rels/${fileName}.rels`]?.elements?.find((x) => x.name === "Relationships")?.elements || [];
429985
- this.convertedXml[`word/_rels/${fileName}.rels`] = {
430199
+ this.convertedXml[relsPath] = {
429986
430200
  declaration: this.initialJSON?.declaration,
429987
430201
  elements: [
429988
430202
  {
@@ -429990,7 +430204,7 @@ var init_SuperConverter = __esm(() => {
429990
430204
  attributes: {
429991
430205
  xmlns: "http://schemas.openxmlformats.org/package/2006/relationships"
429992
430206
  },
429993
- elements: [...relationships2, ...params3.relationships]
430207
+ elements: mergeRelationshipElements2(existingRelationships, params3.relationships)
429994
430208
  }
429995
430209
  ]
429996
430210
  };
@@ -451175,8 +451389,7 @@ function syncHeaderFooterCaches2(editor, part) {
451175
451389
  const converter = getConverter16(editor);
451176
451390
  if (!converter)
451177
451391
  return;
451178
- const root4 = part;
451179
- const relsRoot = root4?.elements?.find((el) => el.name === "Relationships");
451392
+ const relsRoot = getRelationshipsRoot2(part);
451180
451393
  if (!relsRoot?.elements)
451181
451394
  return;
451182
451395
  let changed = false;
@@ -451207,23 +451420,12 @@ function syncHeaderFooterCaches2(editor, part) {
451207
451420
  converter.headerFooterModified = true;
451208
451421
  }
451209
451422
  }
451210
- var RELS_PART_ID4 = "word/_rels/document.xml.rels", RELS_XMLNS5 = "http://schemas.openxmlformats.org/package/2006/relationships", HEADER_RELATIONSHIP_TYPE6 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE6 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", relsPartDescriptor2;
451423
+ var RELS_PART_ID4 = "word/_rels/document.xml.rels", HEADER_RELATIONSHIP_TYPE6 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE6 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer", relsPartDescriptor2;
451211
451424
  var init_rels_part_descriptor = __esm(() => {
451212
451425
  relsPartDescriptor2 = {
451213
451426
  id: RELS_PART_ID4,
451214
451427
  ensurePart() {
451215
- return {
451216
- type: "element",
451217
- name: "document",
451218
- elements: [
451219
- {
451220
- type: "element",
451221
- name: "Relationships",
451222
- attributes: { xmlns: RELS_XMLNS5 },
451223
- elements: []
451224
- }
451225
- ]
451226
- };
451428
+ return createRelationshipsPart2();
451227
451429
  },
451228
451430
  afterCommit({ editor, part }) {
451229
451431
  syncHeaderFooterCaches2(editor, part);
@@ -453232,15 +453434,13 @@ function toRelsPathForPart4(partPath) {
453232
453434
  if (partPath === DOCUMENT_RELS_PATH4 || partPath.endsWith(".rels")) {
453233
453435
  return null;
453234
453436
  }
453235
- const lastSlash = partPath.lastIndexOf("/");
453236
- if (lastSlash < 0 || lastSlash === partPath.length - 1) {
453437
+ if (!partPath.includes("/") || partPath.endsWith("/")) {
453237
453438
  return null;
453238
453439
  }
453239
- const directory = partPath.slice(0, lastSlash);
453240
- const fileName = partPath.slice(lastSlash + 1);
453241
- return `${directory}/_rels/${fileName}.rels`;
453440
+ return getWordPartRelsPath2(partPath);
453242
453441
  }
453243
453442
  var DOCUMENT_RELS_PATH4 = "word/_rels/document.xml.rels";
453443
+ var init_part_paths = () => {};
453244
453444
 
453245
453445
  // ../../packages/super-editor/src/editors/v1/extensions/diffing/algorithm/parts-diffing.ts
453246
453446
  function capturePartsState2(editor, headerFooters) {
@@ -453426,6 +453626,7 @@ function partSnapshotsEqual2(a2, b2) {
453426
453626
  var DOCUMENT_RELS_PATH5 = "word/_rels/document.xml.rels", BODY_RELATIONSHIP_EXCLUSIONS2;
453427
453627
  var init_parts_diffing = __esm(() => {
453428
453628
  init_helpers();
453629
+ init_part_paths();
453429
453630
  BODY_RELATIONSHIP_EXCLUSIONS2 = new Set([
453430
453631
  "http://schemas.openxmlformats.org/officeDocument/2006/relationships/styles",
453431
453632
  "http://schemas.openxmlformats.org/officeDocument/2006/relationships/numbering",
@@ -456404,6 +456605,7 @@ function ensureRelationshipsRoot2(convertedXml) {
456404
456605
  var HEADER_RELATIONSHIP_TYPE7 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/header", FOOTER_RELATIONSHIP_TYPE7 = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/footer";
456405
456606
  var init_replay_header_footers = __esm(() => {
456406
456607
  init_dist5();
456608
+ init_part_paths();
456407
456609
  init_replay_doc();
456408
456610
  init_header_footer_diffing();
456409
456611
  init_sections_resolver();
@@ -458523,6 +458725,7 @@ var init_startImageUpload = __esm(() => {
458523
458725
  init_imageRegistrationPlugin();
458524
458726
  init_helpers5();
458525
458727
  init_relationships_mutation();
458728
+ init_header_footer_sync();
458526
458729
  });
458527
458730
 
458528
458731
  // ../../packages/super-editor/src/editors/v1/document-api-adapters/plan-engine/images-wrappers.ts
@@ -461605,10 +461808,7 @@ function headerFootersPartsDeleteAdapter2(editor, input2, options) {
461605
461808
  }
461606
461809
  }
461607
461810
  delete convertedXml[partPath];
461608
- const partFileName = partPath.split("/").pop();
461609
- if (partFileName) {
461610
- delete convertedXml[`word/_rels/${partFileName}.rels`];
461611
- }
461811
+ delete convertedXml[getWordPartRelsPath2(partPath)];
461612
461812
  const collection = kind === "header" ? converter.headers : converter.footers;
461613
461813
  if (collection && typeof collection === "object") {
461614
461814
  delete collection[refId];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@superdoc-dev/mcp",
3
- "version": "0.6.0-next.11",
3
+ "version": "0.6.0-next.13",
4
4
  "type": "module",
5
5
  "engines": {
6
6
  "node": ">=20"
@@ -19,9 +19,9 @@
19
19
  "@types/bun": "^1.3.8",
20
20
  "@types/node": "22.19.2",
21
21
  "typescript": "^5.9.2",
22
- "@superdoc/document-api": "0.0.1",
22
+ "superdoc": "1.33.1",
23
23
  "@superdoc/super-editor": "0.0.1",
24
- "superdoc": "1.33.1"
24
+ "@superdoc/document-api": "0.0.1"
25
25
  },
26
26
  "publishConfig": {
27
27
  "access": "public"