@harbour-enterprises/superdoc 0.22.0-next.4 → 0.22.0-next.5

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 (28) hide show
  1. package/dist/chunks/{PdfViewer-CxIz7yf-.cjs → PdfViewer-Badqoc1e.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-BBpGCmdE.es.js → PdfViewer-dsL5uHg1.es.js} +1 -1
  3. package/dist/chunks/{index-CYCctXm3.es.js → index-DBNzXf1D.es.js} +2 -2
  4. package/dist/chunks/{index-BE07bQaY.cjs → index-DVrbZM76.cjs} +2 -2
  5. package/dist/chunks/{super-editor.es-Ccu1wOj1.es.js → super-editor.es-DruRanWK.es.js} +157 -59
  6. package/dist/chunks/{super-editor.es-cZsHkhM6.cjs → super-editor.es-p3eqHXlj.cjs} +157 -59
  7. package/dist/core/types/index.d.ts.map +1 -1
  8. package/dist/super-editor/ai-writer.es.js +2 -2
  9. package/dist/super-editor/chunks/{converter-DBwwYo1I.js → converter-DujfV3Zn.js} +46 -34
  10. package/dist/super-editor/chunks/{docx-zipper-BCI-3XE9.js → docx-zipper-DccEqL60.js} +73 -12
  11. package/dist/super-editor/chunks/{editor-B2S-zXBF.js → editor-Dq3xPdti.js} +41 -16
  12. package/dist/super-editor/chunks/{toolbar-BX9nPPG0.js → toolbar-u5oyT_9K.js} +2 -2
  13. package/dist/super-editor/converter.es.js +1 -1
  14. package/dist/super-editor/docx-zipper.es.js +2 -2
  15. package/dist/super-editor/editor.es.js +3 -3
  16. package/dist/super-editor/file-zipper.es.js +1 -1
  17. package/dist/super-editor/src/core/DocxZipper.d.ts +1 -1
  18. package/dist/super-editor/src/core/super-converter/exporter.d.ts +1 -0
  19. package/dist/super-editor/src/extensions/custom-selection/custom-selection.d.ts +5 -0
  20. package/dist/super-editor/super-editor.es.js +6 -6
  21. package/dist/super-editor/toolbar.es.js +2 -2
  22. package/dist/super-editor.cjs +1 -1
  23. package/dist/super-editor.es.js +1 -1
  24. package/dist/superdoc.cjs +2 -2
  25. package/dist/superdoc.es.js +2 -2
  26. package/dist/superdoc.umd.js +157 -59
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +1 -1
@@ -30620,6 +30620,51 @@ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30620
30620
  gutter: "0"
30621
30621
  })
30622
30622
  });
30623
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
30624
+ if (!sectPr) {
30625
+ return {
30626
+ type: "element",
30627
+ name: "w:sectPr",
30628
+ elements: []
30629
+ };
30630
+ }
30631
+ if (!sectPr.elements) sectPr.elements = [];
30632
+ const ensureChild = (name) => {
30633
+ let child = sectPr.elements.find((n) => n.name === name);
30634
+ if (!child) {
30635
+ child = {
30636
+ type: "element",
30637
+ name,
30638
+ elements: [],
30639
+ attributes: {}
30640
+ };
30641
+ sectPr.elements.push(child);
30642
+ } else {
30643
+ if (!child.elements) child.elements = [];
30644
+ if (!child.attributes) child.attributes = {};
30645
+ }
30646
+ return child;
30647
+ };
30648
+ const pageSize = converter?.pageStyles?.pageSize;
30649
+ const pgSz = ensureChild("w:pgSz");
30650
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
30651
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
30652
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30653
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30654
+ const pageMargins = converter?.pageStyles?.pageMargins;
30655
+ const pgMar = ensureChild("w:pgMar");
30656
+ if (pageMargins) {
30657
+ Object.entries(pageMargins).forEach(([key2, value]) => {
30658
+ const converted = inchesToTwips(value);
30659
+ if (converted != null) pgMar.attributes[`w:${key2}`] = String(converted);
30660
+ });
30661
+ }
30662
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key2, value]) => {
30663
+ const attrKey = `w:${key2}`;
30664
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
30665
+ });
30666
+ return sectPr;
30667
+ };
30623
30668
  const isLineBreakOnlyRun = (node) => {
30624
30669
  if (!node) return false;
30625
30670
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30682,6 +30727,7 @@ function translateBodyNode(params2) {
30682
30727
  } else if (!sectPr.elements) {
30683
30728
  sectPr = { ...sectPr, elements: [] };
30684
30729
  }
30730
+ sectPr = ensureSectionLayoutDefaults(sectPr, params2.converter);
30685
30731
  if (params2.converter) {
30686
30732
  const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30687
30733
  const hasDefaultHeader = params2.converter.headerIds?.default;
@@ -30695,40 +30741,6 @@ function translateBodyNode(params2) {
30695
30741
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
30696
30742
  sectPr.elements.push(defaultFooter);
30697
30743
  }
30698
- const newMargins = params2.converter.pageStyles?.pageMargins;
30699
- if (newMargins) {
30700
- let sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30701
- if (!sectPrMargins) {
30702
- sectPrMargins = {
30703
- type: "element",
30704
- name: "w:pgMar",
30705
- attributes: {}
30706
- };
30707
- sectPr.elements.push(sectPrMargins);
30708
- } else if (!sectPrMargins.attributes) {
30709
- sectPrMargins.attributes = {};
30710
- }
30711
- Object.entries(newMargins).forEach(([key2, value]) => {
30712
- const convertedValue = inchesToTwips(value);
30713
- sectPrMargins.attributes[`w:${key2}`] = convertedValue;
30714
- });
30715
- }
30716
- let sectPrPgSz = sectPr.elements.find((n) => n.name === "w:pgSz");
30717
- if (!sectPrPgSz) {
30718
- sectPrPgSz = {
30719
- type: "element",
30720
- name: "w:pgSz",
30721
- attributes: {}
30722
- };
30723
- sectPr.elements.push(sectPrPgSz);
30724
- } else if (!sectPrPgSz.attributes) {
30725
- sectPrPgSz.attributes = {};
30726
- }
30727
- const pageSize = params2.converter.pageStyles?.pageSize;
30728
- const widthInches = pageSize?.width;
30729
- const heightInches = pageSize?.height;
30730
- sectPrPgSz.attributes["w:w"] = widthInches ? String(inchesToTwips(widthInches)) : sectPrPgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30731
- sectPrPgSz.attributes["w:h"] = heightInches ? String(inchesToTwips(heightInches)) : sectPrPgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30732
30744
  }
30733
30745
  const elements = translateChildNodes(params2);
30734
30746
  if (params2.isHeaderFooter) {
@@ -36284,14 +36296,19 @@ class DocxZipper {
36284
36296
  /**
36285
36297
  * Update [Content_Types].xml with extensions of new Image annotations
36286
36298
  */
36287
- async updateContentTypes(docx, media, fromJson) {
36299
+ async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
36300
+ const additionalPartNames = Object.keys(updatedDocs || {});
36288
36301
  const newMediaTypes = Object.keys(media).map((name) => {
36289
36302
  return this.getFileExtension(name);
36290
36303
  }).filter(Boolean);
36291
36304
  const contentTypesPath = "[Content_Types].xml";
36292
36305
  let contentTypesXml;
36293
36306
  if (fromJson) {
36294
- contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36307
+ if (Array.isArray(docx.files)) {
36308
+ contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
36309
+ } else {
36310
+ contentTypesXml = docx.files?.[contentTypesPath] || "";
36311
+ }
36295
36312
  } else contentTypesXml = await docx.file(contentTypesPath).async("string");
36296
36313
  let typesString = "";
36297
36314
  const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
@@ -36317,24 +36334,39 @@ class DocxZipper {
36317
36334
  const hasCommentsExtensible = types2.elements?.some(
36318
36335
  (el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml"
36319
36336
  );
36320
- if (docx.files["word/comments.xml"]) {
36337
+ const hasFile = (filename) => {
36338
+ if (!docx?.files) return false;
36339
+ if (!fromJson) return Boolean(docx.files[filename]);
36340
+ if (Array.isArray(docx.files)) return docx.files.some((file) => file.name === filename);
36341
+ return Boolean(docx.files[filename]);
36342
+ };
36343
+ if (hasFile("word/comments.xml")) {
36321
36344
  const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
36322
36345
  if (!hasComments) typesString += commentsDef;
36323
36346
  }
36324
- if (docx.files["word/commentsExtended.xml"]) {
36347
+ if (hasFile("word/commentsExtended.xml")) {
36325
36348
  const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
36326
36349
  if (!hasCommentsExtended) typesString += commentsExtendedDef;
36327
36350
  }
36328
- if (docx.files["word/commentsIds.xml"]) {
36351
+ if (hasFile("word/commentsIds.xml")) {
36329
36352
  const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
36330
36353
  if (!hasCommentsIds) typesString += commentsIdsDef;
36331
36354
  }
36332
- if (docx.files["word/commentsExtensible.xml"]) {
36355
+ if (hasFile("word/commentsExtensible.xml")) {
36333
36356
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
36334
36357
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
36335
36358
  }
36336
- Object.keys(docx.files).forEach((name) => {
36337
- if (name.includes(".rels") || !name.includes("header") && !name.includes("footer")) return;
36359
+ const partNames = new Set(additionalPartNames);
36360
+ if (docx?.files) {
36361
+ if (fromJson && Array.isArray(docx.files)) {
36362
+ docx.files.forEach((file) => partNames.add(file.name));
36363
+ } else {
36364
+ Object.keys(docx.files).forEach((key2) => partNames.add(key2));
36365
+ }
36366
+ }
36367
+ partNames.forEach((name) => {
36368
+ if (name.includes(".rels")) return;
36369
+ if (!name.includes("header") && !name.includes("footer")) return;
36338
36370
  const hasExtensible = types2.elements?.some(
36339
36371
  (el) => el.name === "Override" && el.attributes.PartName === `/${name}`
36340
36372
  );
@@ -36345,7 +36377,48 @@ class DocxZipper {
36345
36377
  }
36346
36378
  });
36347
36379
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
36348
- const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36380
+ let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
36381
+ let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
36382
+ if (!relationshipsXml) {
36383
+ if (fromJson) {
36384
+ if (Array.isArray(docx.files)) {
36385
+ relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
36386
+ } else {
36387
+ relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
36388
+ }
36389
+ } else {
36390
+ relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
36391
+ }
36392
+ }
36393
+ if (relationshipsXml) {
36394
+ try {
36395
+ const relJson = xmljs.xml2js(relationshipsXml, { compact: false });
36396
+ const relationships = relJson.elements?.find((el) => el.name === "Relationships");
36397
+ relationships?.elements?.forEach((rel) => {
36398
+ const type2 = rel.attributes?.Type;
36399
+ const target = rel.attributes?.Target;
36400
+ if (!type2 || !target) return;
36401
+ const isHeader = type2.includes("/header");
36402
+ const isFooter = type2.includes("/footer");
36403
+ if (!isHeader && !isFooter) return;
36404
+ let sanitizedTarget = target.replace(/^\.\//, "");
36405
+ if (sanitizedTarget.startsWith("../")) sanitizedTarget = sanitizedTarget.slice(3);
36406
+ if (sanitizedTarget.startsWith("/")) sanitizedTarget = sanitizedTarget.slice(1);
36407
+ const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
36408
+ partNames.add(partName);
36409
+ });
36410
+ } catch (error) {
36411
+ console.warn("Failed to parse document relationships while updating content types", error);
36412
+ }
36413
+ }
36414
+ partNames.forEach((name) => {
36415
+ if (name.includes(".rels")) return;
36416
+ if (!name.includes("header") && !name.includes("footer")) return;
36417
+ if (updatedContentTypesXml.includes(`PartName="/${name}"`)) return;
36418
+ const type2 = name.includes("header") ? "header" : "footer";
36419
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type2}+xml"/>`;
36420
+ updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
36421
+ });
36349
36422
  if (fromJson) return updatedContentTypesXml;
36350
36423
  docx.file(contentTypesPath, updatedContentTypesXml);
36351
36424
  }
@@ -36386,7 +36459,7 @@ class DocxZipper {
36386
36459
  for (const [fontName, fontUintArray] of Object.entries(fonts)) {
36387
36460
  zip.file(fontName, fontUintArray);
36388
36461
  }
36389
- await this.updateContentTypes(zip, media);
36462
+ await this.updateContentTypes(zip, media, false, updatedDocs);
36390
36463
  return zip;
36391
36464
  }
36392
36465
  /**
@@ -36412,7 +36485,7 @@ class DocxZipper {
36412
36485
  Object.keys(media).forEach((path) => {
36413
36486
  unzippedOriginalDocx.file(path, media[path]);
36414
36487
  });
36415
- await this.updateContentTypes(unzippedOriginalDocx, media);
36488
+ await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
36416
36489
  return unzippedOriginalDocx;
36417
36490
  }
36418
36491
  }
@@ -51174,7 +51247,8 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
51174
51247
  files: this.options.content
51175
51248
  },
51176
51249
  media,
51177
- true
51250
+ true,
51251
+ updatedDocs
51178
51252
  );
51179
51253
  return updatedDocs;
51180
51254
  }
@@ -53733,6 +53807,16 @@ const shouldAllowNativeContextMenu = (event) => {
53733
53807
  return prefersNativeMenu(event);
53734
53808
  };
53735
53809
  const shouldBypassContextMenu = shouldAllowNativeContextMenu;
53810
+ const DEFAULT_SELECTION_STATE = Object.freeze({
53811
+ focused: false,
53812
+ preservedSelection: null,
53813
+ showVisualSelection: false,
53814
+ skipFocusReset: false
53815
+ });
53816
+ const normalizeSelectionState = (state2 = {}) => ({
53817
+ ...DEFAULT_SELECTION_STATE,
53818
+ ...state2
53819
+ });
53736
53820
  const CustomSelectionPluginKey = new PluginKey("CustomSelection");
53737
53821
  const handleClickOutside = (event, editor) => {
53738
53822
  const editorElem = editor?.options?.element;
@@ -53770,11 +53854,7 @@ const CustomSelection = Extension.create({
53770
53854
  const customSelectionPlugin = new Plugin({
53771
53855
  key: CustomSelectionPluginKey,
53772
53856
  state: {
53773
- init: () => ({
53774
- focused: false,
53775
- preservedSelection: null,
53776
- showVisualSelection: false
53777
- }),
53857
+ init: () => ({ ...DEFAULT_SELECTION_STATE }),
53778
53858
  apply: (tr, value) => {
53779
53859
  const meta = getFocusMeta(tr);
53780
53860
  if (meta !== void 0) {
@@ -53805,7 +53885,8 @@ const CustomSelection = Extension.create({
53805
53885
  setFocusMeta(view.state.tr, {
53806
53886
  focused: true,
53807
53887
  preservedSelection: selection,
53808
- showVisualSelection: true
53888
+ showVisualSelection: true,
53889
+ skipFocusReset: true
53809
53890
  })
53810
53891
  );
53811
53892
  }
@@ -53826,7 +53907,8 @@ const CustomSelection = Extension.create({
53826
53907
  setFocusMeta(view.state.tr, {
53827
53908
  focused: true,
53828
53909
  preservedSelection: selection2,
53829
- showVisualSelection: true
53910
+ showVisualSelection: true,
53911
+ skipFocusReset: true
53830
53912
  })
53831
53913
  );
53832
53914
  this.editor.setOptions({
@@ -53849,7 +53931,8 @@ const CustomSelection = Extension.create({
53849
53931
  setFocusMeta(view.state.tr, {
53850
53932
  focused: true,
53851
53933
  preservedSelection: selection,
53852
- showVisualSelection: true
53934
+ showVisualSelection: true,
53935
+ skipFocusReset: false
53853
53936
  })
53854
53937
  );
53855
53938
  this.editor.setOptions({
@@ -53867,7 +53950,8 @@ const CustomSelection = Extension.create({
53867
53950
  setFocusMeta(view.state.tr, {
53868
53951
  focused: true,
53869
53952
  preservedSelection: selection,
53870
- showVisualSelection: true
53953
+ showVisualSelection: true,
53954
+ skipFocusReset: false
53871
53955
  })
53872
53956
  );
53873
53957
  }
@@ -53878,7 +53962,8 @@ const CustomSelection = Extension.create({
53878
53962
  setFocusMeta(view.state.tr, {
53879
53963
  focused: false,
53880
53964
  preservedSelection: null,
53881
- showVisualSelection: false
53965
+ showVisualSelection: false,
53966
+ skipFocusReset: false
53882
53967
  })
53883
53968
  );
53884
53969
  if (!selection.empty && !this.editor.options.element?.contains(target)) {
@@ -53895,12 +53980,20 @@ const CustomSelection = Extension.create({
53895
53980
  const isElement2 = target instanceof Element;
53896
53981
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53897
53982
  const isToolbarInp = isElement2 && isToolbarInput(target);
53983
+ const focusState = getFocusState(view.state);
53984
+ if (focusState?.skipFocusReset) {
53985
+ view.dispatch(
53986
+ setFocusMeta(view.state.tr, normalizeSelectionState({ ...focusState, skipFocusReset: false }))
53987
+ );
53988
+ return false;
53989
+ }
53898
53990
  if (!isToolbarBtn && !isToolbarInp) {
53899
53991
  view.dispatch(
53900
53992
  setFocusMeta(view.state.tr, {
53901
53993
  focused: false,
53902
53994
  preservedSelection: null,
53903
- showVisualSelection: false
53995
+ showVisualSelection: false,
53996
+ skipFocusReset: false
53904
53997
  })
53905
53998
  );
53906
53999
  }
@@ -53911,12 +54004,16 @@ const CustomSelection = Extension.create({
53911
54004
  const isToolbarBtn = isElement2 && isToolbarButton(target);
53912
54005
  const isToolbarInp = isElement2 && isToolbarInput(target);
53913
54006
  const state2 = getFocusState(view.state);
54007
+ if (state2?.skipFocusReset) {
54008
+ return false;
54009
+ }
53914
54010
  if (isToolbarBtn || isToolbarInp) {
53915
54011
  view.dispatch(
53916
54012
  setFocusMeta(view.state.tr, {
53917
54013
  focused: true,
53918
54014
  preservedSelection: state2.preservedSelection || view.state.selection,
53919
- showVisualSelection: true
54015
+ showVisualSelection: true,
54016
+ skipFocusReset: false
53920
54017
  })
53921
54018
  );
53922
54019
  } else {
@@ -53924,7 +54021,8 @@ const CustomSelection = Extension.create({
53924
54021
  setFocusMeta(view.state.tr, {
53925
54022
  focused: false,
53926
54023
  preservedSelection: null,
53927
- showVisualSelection: false
54024
+ showVisualSelection: false,
54025
+ skipFocusReset: false
53928
54026
  })
53929
54027
  );
53930
54028
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/types/index.js"],"names":[],"mappings":";;;;;;;UAEc,MAAM;;;;WACN,MAAM;;;;YACN,MAAM,GAAG,IAAI;;;;;;;;;cAKb,OAAO;;;;iBACP,MAAM;;;;eACN,MAAM;;;;sBACN,MAAM;;;;;;SAKN,MAAM;;;;UACN,MAAM;;;;WACN,IAAI,GAAG,IAAI,GAAG,IAAI;;;;WAClB,MAAM;;;;UACN,MAAM;;;;gBACN,OAAO;;;;WACP,OAAO,KAAK,EAAE,GAAG;;;;eACjB,OAAO,sBAAsB,EAAE,kBAAkB;;;;;;;;;;SAO5D;QAAuB,MAAM,GAAlB,MAAM;QACM,QAAQ,GAApB,MAAM;KACjB;;;;;;;;;;;;gBAGA;QAA6B,WAAW;QACR,YAAY;QACb,mBAAmB,GAAvC,OAAO;KACpB;;;;;;;;;;;;;;sBAiE4o/e,aAAa;;;;;;;;;;;yBAA+xJ,aAAa;;;;;;;;;;;;;;;;+BAAm8U,aAAa;sBAA7joB,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;6CAAm1+B,UAAU;8CAAuV,UAAU,aAA+E,UAAU;gCAAgZ,UAAU;;;;;;;;;;uBA9Dzg2gB,OAAO,gBAAgB,EAAE,QAAQ;2BAGlC,MAAM;;;;;iBAQL,MAAM;;;;cACN,MAAM,GAAG,WAAW;;;;kBACpB,YAAY;;;;WACZ,QAAQ,GAAG,QAAQ,GAAG,WAAW;;;;eACjC,MAAS,MAAM,GAAG,IAAI,GAAG,IAAI;;;;gBAC7B,KAAK,CAAC,QAAQ,CAAC;;;;WACf,IA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,IAAI;;;;yBACvD,MAAM,IAAI;;;;sBACV,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI;;;;2BAC3B,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI;;;;qBACpC,CAAC,MAAM,EAAE;QAAE,MAAM,EAAE,MAAM,CAAA;KAAE,KAAK,IAAI;;;;kBACpC,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,KAAK,CAAA;KAAE,KAAK,IAAI;;;;2BAClC,CAAC,MAAM,EAAE;QAAE,UAAU,EAAE,OAAO,CAAA;KAAE,KAAK,IAAI;;;;8BACzC,CAAC,MAAM,EAAE,EAAE,KAAC,GAAA;;;;aACZ,MAAM;;;;uBACN,KAAQ;;;;iBACR,OAAO;;;;YACP,MAAM;;;;oBACN,KAAQ;;;;eACR,OAAO;;;;wBACP,CAAS,IAAI,EAAJ,IAAI,KAAG,OAAO,CAAC,MAAM,CAAC;;;;eAC/B,IAAI;;;;aACJ,OAAO;;;;gCACP,OAAO;;;;;;;;yBAEP,OAAO;;;;WACP,MAAM;;;;eACN,MAAM;;;;cACN,OAAO"}
@@ -1,6 +1,6 @@
1
1
  import { ref, onMounted, onUnmounted, computed, createElementBlock, openBlock, withModifiers, createElementVNode, withDirectives, unref, vModelText, createCommentVNode, nextTick } from "vue";
2
- import { T as TextSelection } from "./chunks/converter-DBwwYo1I.js";
3
- import { _ as _export_sfc } from "./chunks/editor-B2S-zXBF.js";
2
+ import { T as TextSelection } from "./chunks/converter-DujfV3Zn.js";
3
+ import { _ as _export_sfc } from "./chunks/editor-Dq3xPdti.js";
4
4
  const DEFAULT_API_ENDPOINT = "https://sd-dev-express-gateway-i6xtm.ondigitalocean.app/insights";
5
5
  const SYSTEM_PROMPT = "You are an expert copywriter and you are immersed in a document editor. You are to provide document related text responses based on the user prompts. Only write what is asked for. Do not provide explanations. Try to keep placeholders as short as possible. Do not output your prompt. Your instructions are: ";
6
6
  async function baseInsightsFetch(payload, options = {}) {
@@ -30610,6 +30610,51 @@ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30610
30610
  gutter: "0"
30611
30611
  })
30612
30612
  });
30613
+ const ensureSectionLayoutDefaults = (sectPr, converter) => {
30614
+ if (!sectPr) {
30615
+ return {
30616
+ type: "element",
30617
+ name: "w:sectPr",
30618
+ elements: []
30619
+ };
30620
+ }
30621
+ if (!sectPr.elements) sectPr.elements = [];
30622
+ const ensureChild = (name) => {
30623
+ let child = sectPr.elements.find((n) => n.name === name);
30624
+ if (!child) {
30625
+ child = {
30626
+ type: "element",
30627
+ name,
30628
+ elements: [],
30629
+ attributes: {}
30630
+ };
30631
+ sectPr.elements.push(child);
30632
+ } else {
30633
+ if (!child.elements) child.elements = [];
30634
+ if (!child.attributes) child.attributes = {};
30635
+ }
30636
+ return child;
30637
+ };
30638
+ const pageSize = converter?.pageStyles?.pageSize;
30639
+ const pgSz = ensureChild("w:pgSz");
30640
+ if (pageSize?.width != null) pgSz.attributes["w:w"] = String(inchesToTwips(pageSize.width));
30641
+ if (pageSize?.height != null) pgSz.attributes["w:h"] = String(inchesToTwips(pageSize.height));
30642
+ if (pgSz.attributes["w:w"] == null) pgSz.attributes["w:w"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30643
+ if (pgSz.attributes["w:h"] == null) pgSz.attributes["w:h"] = DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30644
+ const pageMargins = converter?.pageStyles?.pageMargins;
30645
+ const pgMar = ensureChild("w:pgMar");
30646
+ if (pageMargins) {
30647
+ Object.entries(pageMargins).forEach(([key, value]) => {
30648
+ const converted = inchesToTwips(value);
30649
+ if (converted != null) pgMar.attributes[`w:${key}`] = String(converted);
30650
+ });
30651
+ }
30652
+ Object.entries(DEFAULT_SECTION_PROPS_TWIPS.pageMargins).forEach(([key, value]) => {
30653
+ const attrKey = `w:${key}`;
30654
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
30655
+ });
30656
+ return sectPr;
30657
+ };
30613
30658
  const isLineBreakOnlyRun = (node) => {
30614
30659
  if (!node) return false;
30615
30660
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30672,6 +30717,7 @@ function translateBodyNode(params) {
30672
30717
  } else if (!sectPr.elements) {
30673
30718
  sectPr = { ...sectPr, elements: [] };
30674
30719
  }
30720
+ sectPr = ensureSectionLayoutDefaults(sectPr, params.converter);
30675
30721
  if (params.converter) {
30676
30722
  const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30677
30723
  const hasDefaultHeader = params.converter.headerIds?.default;
@@ -30685,40 +30731,6 @@ function translateBodyNode(params) {
30685
30731
  const defaultFooter = generateDefaultHeaderFooter("footer", params.converter.footerIds?.default);
30686
30732
  sectPr.elements.push(defaultFooter);
30687
30733
  }
30688
- const newMargins = params.converter.pageStyles?.pageMargins;
30689
- if (newMargins) {
30690
- let sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30691
- if (!sectPrMargins) {
30692
- sectPrMargins = {
30693
- type: "element",
30694
- name: "w:pgMar",
30695
- attributes: {}
30696
- };
30697
- sectPr.elements.push(sectPrMargins);
30698
- } else if (!sectPrMargins.attributes) {
30699
- sectPrMargins.attributes = {};
30700
- }
30701
- Object.entries(newMargins).forEach(([key, value]) => {
30702
- const convertedValue = inchesToTwips(value);
30703
- sectPrMargins.attributes[`w:${key}`] = convertedValue;
30704
- });
30705
- }
30706
- let sectPrPgSz = sectPr.elements.find((n) => n.name === "w:pgSz");
30707
- if (!sectPrPgSz) {
30708
- sectPrPgSz = {
30709
- type: "element",
30710
- name: "w:pgSz",
30711
- attributes: {}
30712
- };
30713
- sectPr.elements.push(sectPrPgSz);
30714
- } else if (!sectPrPgSz.attributes) {
30715
- sectPrPgSz.attributes = {};
30716
- }
30717
- const pageSize = params.converter.pageStyles?.pageSize;
30718
- const widthInches = pageSize?.width;
30719
- const heightInches = pageSize?.height;
30720
- sectPrPgSz.attributes["w:w"] = widthInches ? String(inchesToTwips(widthInches)) : sectPrPgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30721
- sectPrPgSz.attributes["w:h"] = heightInches ? String(inchesToTwips(heightInches)) : sectPrPgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30722
30734
  }
30723
30735
  const elements = translateChildNodes(params);
30724
30736
  if (params.isHeaderFooter) {
@@ -1,4 +1,4 @@
1
- import { p as process$1, au as commonjsGlobal, B as Buffer, av as getDefaultExportFromCjs, aw as getContentTypesFromXml, ax as xmljs } from "./converter-DBwwYo1I.js";
1
+ import { p as process$1, au as commonjsGlobal, B as Buffer, av as getDefaultExportFromCjs, aw as getContentTypesFromXml, ax as xmljs } from "./converter-DujfV3Zn.js";
2
2
  function commonjsRequire(path) {
3
3
  throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
4
4
  }
@@ -2414,14 +2414,19 @@ class DocxZipper {
2414
2414
  /**
2415
2415
  * Update [Content_Types].xml with extensions of new Image annotations
2416
2416
  */
2417
- async updateContentTypes(docx, media, fromJson) {
2417
+ async updateContentTypes(docx, media, fromJson, updatedDocs = {}) {
2418
+ const additionalPartNames = Object.keys(updatedDocs || {});
2418
2419
  const newMediaTypes = Object.keys(media).map((name) => {
2419
2420
  return this.getFileExtension(name);
2420
2421
  }).filter(Boolean);
2421
2422
  const contentTypesPath = "[Content_Types].xml";
2422
2423
  let contentTypesXml;
2423
2424
  if (fromJson) {
2424
- contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
2425
+ if (Array.isArray(docx.files)) {
2426
+ contentTypesXml = docx.files.find((file) => file.name === contentTypesPath)?.content || "";
2427
+ } else {
2428
+ contentTypesXml = docx.files?.[contentTypesPath] || "";
2429
+ }
2425
2430
  } else contentTypesXml = await docx.file(contentTypesPath).async("string");
2426
2431
  let typesString = "";
2427
2432
  const defaultMediaTypes = getContentTypesFromXml(contentTypesXml);
@@ -2447,24 +2452,39 @@ class DocxZipper {
2447
2452
  const hasCommentsExtensible = types.elements?.some(
2448
2453
  (el) => el.name === "Override" && el.attributes.PartName === "/word/commentsExtensible.xml"
2449
2454
  );
2450
- if (docx.files["word/comments.xml"]) {
2455
+ const hasFile = (filename) => {
2456
+ if (!docx?.files) return false;
2457
+ if (!fromJson) return Boolean(docx.files[filename]);
2458
+ if (Array.isArray(docx.files)) return docx.files.some((file) => file.name === filename);
2459
+ return Boolean(docx.files[filename]);
2460
+ };
2461
+ if (hasFile("word/comments.xml")) {
2451
2462
  const commentsDef = `<Override PartName="/word/comments.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.comments+xml" />`;
2452
2463
  if (!hasComments) typesString += commentsDef;
2453
2464
  }
2454
- if (docx.files["word/commentsExtended.xml"]) {
2465
+ if (hasFile("word/commentsExtended.xml")) {
2455
2466
  const commentsExtendedDef = `<Override PartName="/word/commentsExtended.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtended+xml" />`;
2456
2467
  if (!hasCommentsExtended) typesString += commentsExtendedDef;
2457
2468
  }
2458
- if (docx.files["word/commentsIds.xml"]) {
2469
+ if (hasFile("word/commentsIds.xml")) {
2459
2470
  const commentsIdsDef = `<Override PartName="/word/commentsIds.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsIds+xml" />`;
2460
2471
  if (!hasCommentsIds) typesString += commentsIdsDef;
2461
2472
  }
2462
- if (docx.files["word/commentsExtensible.xml"]) {
2473
+ if (hasFile("word/commentsExtensible.xml")) {
2463
2474
  const commentsExtendedDef = `<Override PartName="/word/commentsExtensible.xml" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.commentsExtensible+xml" />`;
2464
2475
  if (!hasCommentsExtensible) typesString += commentsExtendedDef;
2465
2476
  }
2466
- Object.keys(docx.files).forEach((name) => {
2467
- if (name.includes(".rels") || !name.includes("header") && !name.includes("footer")) return;
2477
+ const partNames = new Set(additionalPartNames);
2478
+ if (docx?.files) {
2479
+ if (fromJson && Array.isArray(docx.files)) {
2480
+ docx.files.forEach((file) => partNames.add(file.name));
2481
+ } else {
2482
+ Object.keys(docx.files).forEach((key) => partNames.add(key));
2483
+ }
2484
+ }
2485
+ partNames.forEach((name) => {
2486
+ if (name.includes(".rels")) return;
2487
+ if (!name.includes("header") && !name.includes("footer")) return;
2468
2488
  const hasExtensible = types.elements?.some(
2469
2489
  (el) => el.name === "Override" && el.attributes.PartName === `/${name}`
2470
2490
  );
@@ -2475,7 +2495,48 @@ class DocxZipper {
2475
2495
  }
2476
2496
  });
2477
2497
  const beginningString = '<Types xmlns="http://schemas.openxmlformats.org/package/2006/content-types">';
2478
- const updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
2498
+ let updatedContentTypesXml = contentTypesXml.replace(beginningString, `${beginningString}${typesString}`);
2499
+ let relationshipsXml = updatedDocs["word/_rels/document.xml.rels"];
2500
+ if (!relationshipsXml) {
2501
+ if (fromJson) {
2502
+ if (Array.isArray(docx.files)) {
2503
+ relationshipsXml = docx.files.find((file) => file.name === "word/_rels/document.xml.rels")?.content;
2504
+ } else {
2505
+ relationshipsXml = docx.files?.["word/_rels/document.xml.rels"];
2506
+ }
2507
+ } else {
2508
+ relationshipsXml = await docx.file("word/_rels/document.xml.rels")?.async("string");
2509
+ }
2510
+ }
2511
+ if (relationshipsXml) {
2512
+ try {
2513
+ const relJson = xmljs.xml2js(relationshipsXml, { compact: false });
2514
+ const relationships = relJson.elements?.find((el) => el.name === "Relationships");
2515
+ relationships?.elements?.forEach((rel) => {
2516
+ const type = rel.attributes?.Type;
2517
+ const target = rel.attributes?.Target;
2518
+ if (!type || !target) return;
2519
+ const isHeader = type.includes("/header");
2520
+ const isFooter = type.includes("/footer");
2521
+ if (!isHeader && !isFooter) return;
2522
+ let sanitizedTarget = target.replace(/^\.\//, "");
2523
+ if (sanitizedTarget.startsWith("../")) sanitizedTarget = sanitizedTarget.slice(3);
2524
+ if (sanitizedTarget.startsWith("/")) sanitizedTarget = sanitizedTarget.slice(1);
2525
+ const partName = sanitizedTarget.startsWith("word/") ? sanitizedTarget : `word/${sanitizedTarget}`;
2526
+ partNames.add(partName);
2527
+ });
2528
+ } catch (error) {
2529
+ console.warn("Failed to parse document relationships while updating content types", error);
2530
+ }
2531
+ }
2532
+ partNames.forEach((name) => {
2533
+ if (name.includes(".rels")) return;
2534
+ if (!name.includes("header") && !name.includes("footer")) return;
2535
+ if (updatedContentTypesXml.includes(`PartName="/${name}"`)) return;
2536
+ const type = name.includes("header") ? "header" : "footer";
2537
+ const extendedDef = `<Override PartName="/${name}" ContentType="application/vnd.openxmlformats-officedocument.wordprocessingml.${type}+xml"/>`;
2538
+ updatedContentTypesXml = updatedContentTypesXml.replace("</Types>", `${extendedDef}</Types>`);
2539
+ });
2479
2540
  if (fromJson) return updatedContentTypesXml;
2480
2541
  docx.file(contentTypesPath, updatedContentTypesXml);
2481
2542
  }
@@ -2516,7 +2577,7 @@ class DocxZipper {
2516
2577
  for (const [fontName, fontUintArray] of Object.entries(fonts)) {
2517
2578
  zip.file(fontName, fontUintArray);
2518
2579
  }
2519
- await this.updateContentTypes(zip, media);
2580
+ await this.updateContentTypes(zip, media, false, updatedDocs);
2520
2581
  return zip;
2521
2582
  }
2522
2583
  /**
@@ -2542,7 +2603,7 @@ class DocxZipper {
2542
2603
  Object.keys(media).forEach((path) => {
2543
2604
  unzippedOriginalDocx.file(path, media[path]);
2544
2605
  });
2545
- await this.updateContentTypes(unzippedOriginalDocx, media);
2606
+ await this.updateContentTypes(unzippedOriginalDocx, media, false, updatedDocs);
2546
2607
  return unzippedOriginalDocx;
2547
2608
  }
2548
2609
  }