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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (29) hide show
  1. package/dist/chunks/{PdfViewer-OEs-MC5j.es.js → PdfViewer-BBpGCmdE.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-Ck3Syakz.cjs → PdfViewer-CxIz7yf-.cjs} +1 -1
  3. package/dist/chunks/{index-BM732Zfw.cjs → index-BE07bQaY.cjs} +39 -19
  4. package/dist/chunks/{index-B4aklZ4_.es.js → index-CYCctXm3.es.js} +39 -19
  5. package/dist/chunks/{super-editor.es-Bokezk1E.es.js → super-editor.es-Ccu1wOj1.es.js} +201 -72
  6. package/dist/chunks/{super-editor.es-DwGNbrZq.cjs → super-editor.es-cZsHkhM6.cjs} +201 -72
  7. package/dist/core/SuperDoc.d.ts +5 -0
  8. package/dist/core/SuperDoc.d.ts.map +1 -1
  9. package/dist/core/types/index.d.ts +4 -4
  10. package/dist/core/types/index.d.ts.map +1 -1
  11. package/dist/super-editor/ai-writer.es.js +2 -2
  12. package/dist/super-editor/chunks/{converter-BcqEfCTg.js → converter-DBwwYo1I.js} +187 -63
  13. package/dist/super-editor/chunks/{docx-zipper-DZ9ph0iQ.js → docx-zipper-BCI-3XE9.js} +1 -1
  14. package/dist/super-editor/chunks/{editor-CTHD3ziL.js → editor-B2S-zXBF.js} +15 -10
  15. package/dist/super-editor/chunks/{toolbar-DLQeMuoQ.js → toolbar-BX9nPPG0.js} +2 -2
  16. package/dist/super-editor/converter.es.js +1 -1
  17. package/dist/super-editor/docx-zipper.es.js +2 -2
  18. package/dist/super-editor/editor.es.js +3 -3
  19. package/dist/super-editor/file-zipper.es.js +1 -1
  20. package/dist/super-editor/src/core/super-converter/SuperConverter.d.ts +1 -13
  21. package/dist/super-editor/super-editor.es.js +7 -7
  22. package/dist/super-editor/toolbar.es.js +2 -2
  23. package/dist/super-editor.cjs +1 -1
  24. package/dist/super-editor.es.js +1 -1
  25. package/dist/superdoc.cjs +2 -2
  26. package/dist/superdoc.es.js +2 -2
  27. package/dist/superdoc.umd.js +238 -89
  28. package/dist/superdoc.umd.js.map +1 -1
  29. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  import { m as defineComponent, B as h, O as Transition, $ as process$1, I as watchEffect, d as computed, r as ref, j as onMounted, W as onUnmounted, c as createElementBlock, o as openBlock, a as createBaseVNode, f as createCommentVNode, v as createVNode, x as unref } from "./vue-CXxsqYcP.es.js";
2
- import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-B4aklZ4_.es.js";
2
+ import { d as derived, c, a as cB, f as fadeInTransition, b as cM, N as NBaseLoading, w as warnOnce, u as useConfig, e as useTheme, p as pxfy, g as createKey, h as useThemeClass, i as useCompitable, _ as _export_sfc, j as useSuperdocStore, s as storeToRefs, k as useSelection } from "./index-CYCctXm3.es.js";
3
3
  function self(vars) {
4
4
  const {
5
5
  opacityDisabled,
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const vue = require("./vue-DWle4Cai.cjs");
4
- const superdoc = require("./index-BM732Zfw.cjs");
4
+ const superdoc = require("./index-BE07bQaY.cjs");
5
5
  function self(vars) {
6
6
  const {
7
7
  opacityDisabled,
@@ -1,5 +1,5 @@
1
1
  "use strict";
2
- const superEditor_es = require("./super-editor.es-DwGNbrZq.cjs");
2
+ const superEditor_es = require("./super-editor.es-cZsHkhM6.cjs");
3
3
  const vue = require("./vue-DWle4Cai.cjs");
4
4
  const jszip = require("./jszip-b7l8QkfH.cjs");
5
5
  const blankDocx = require("./blank-docx-CPqX9RF5.cjs");
@@ -17409,7 +17409,7 @@ const _sfc_main = {
17409
17409
  __name: "SuperDoc",
17410
17410
  emits: ["selection-update"],
17411
17411
  setup(__props, { emit: __emit }) {
17412
- const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-Ck3Syakz.cjs")));
17412
+ const PdfViewer = vue.defineAsyncComponent(() => Promise.resolve().then(() => require("./PdfViewer-CxIz7yf-.cjs")));
17413
17413
  const superdocStore = useSuperdocStore();
17414
17414
  const commentsStore = useCommentsStore();
17415
17415
  const {
@@ -18069,6 +18069,9 @@ class SuperDoc extends eventemitter3.EventEmitter {
18069
18069
  this.isDev = this.config.isDev || false;
18070
18070
  this.activeEditor = null;
18071
18071
  this.comments = [];
18072
+ if (!this.config.selector) {
18073
+ throw new Error("SuperDoc: selector is required");
18074
+ }
18072
18075
  this.app.mount(this.config.selector);
18073
18076
  this.readyEditors = 0;
18074
18077
  this.isLocked = this.config.isLocked || false;
@@ -18088,6 +18091,16 @@ class SuperDoc extends eventemitter3.EventEmitter {
18088
18091
  users: this.users
18089
18092
  };
18090
18093
  }
18094
+ /**
18095
+ * Get the SuperDoc container element
18096
+ * @returns {HTMLElement | null}
18097
+ */
18098
+ get element() {
18099
+ if (typeof this.config.selector === "string") {
18100
+ return document.querySelector(this.config.selector);
18101
+ }
18102
+ return this.config.selector;
18103
+ }
18091
18104
  #patchNaiveUIStyles() {
18092
18105
  const cspNonce = this.config.cspNonce;
18093
18106
  const originalCreateElement = document.createElement;
@@ -18111,10 +18124,16 @@ class SuperDoc extends eventemitter3.EventEmitter {
18111
18124
  }
18112
18125
  if (hasDocumentConfig) {
18113
18126
  const normalized = normalizeDocumentEntry(this.config.document);
18114
- this.config.documents = [normalized];
18127
+ this.config.documents = [
18128
+ {
18129
+ id: uuid.v4(),
18130
+ ...normalized
18131
+ }
18132
+ ];
18115
18133
  } else if (hasDocumentUrl) {
18116
18134
  this.config.documents = [
18117
18135
  {
18136
+ id: uuid.v4(),
18118
18137
  type: DOCX,
18119
18138
  url: this.config.document,
18120
18139
  name: "document.docx",
@@ -18122,33 +18141,34 @@ class SuperDoc extends eventemitter3.EventEmitter {
18122
18141
  }
18123
18142
  ];
18124
18143
  } else if (hasDocumentFile) {
18144
+ const normalized = normalizeDocumentEntry(this.config.document);
18125
18145
  this.config.documents = [
18126
18146
  {
18127
- type: this.config.document.type,
18128
- data: this.config.document,
18129
- name: this.config.document.name,
18130
- isNewFile: true
18147
+ id: uuid.v4(),
18148
+ ...normalized
18131
18149
  }
18132
18150
  ];
18133
18151
  } else if (hasDocumentBlob) {
18134
- const docType = this.config.document.type || DOCX;
18135
- let extension = ".docx";
18136
- if (docType === PDF) {
18137
- extension = ".pdf";
18138
- } else if (docType === HTML) {
18139
- extension = ".html";
18140
- }
18152
+ const normalized = normalizeDocumentEntry(this.config.document);
18141
18153
  this.config.documents = [
18142
18154
  {
18143
- type: docType,
18144
- data: this.config.document,
18145
- name: `document${extension}`,
18146
- isNewFile: true
18155
+ id: uuid.v4(),
18156
+ ...normalized
18147
18157
  }
18148
18158
  ];
18149
18159
  }
18150
18160
  if (Array.isArray(this.config.documents) && this.config.documents.length > 0) {
18151
- this.config.documents = this.config.documents.map((d) => normalizeDocumentEntry(d));
18161
+ this.config.documents = this.config.documents.map((d) => {
18162
+ const normalized = normalizeDocumentEntry(d);
18163
+ if (!normalized || typeof normalized !== "object") {
18164
+ return normalized;
18165
+ }
18166
+ const existingId = typeof normalized === "object" && "id" in normalized && normalized.id || d && typeof d === "object" && "id" in d && d.id;
18167
+ return {
18168
+ ...normalized,
18169
+ id: existingId || uuid.v4()
18170
+ };
18171
+ });
18152
18172
  }
18153
18173
  }
18154
18174
  #initVueApp() {
@@ -1,4 +1,4 @@
1
- import { q as index$1, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-Bokezk1E.es.js";
1
+ import { q as index$1, C as CommentsPluginKey, h as TrackChangesBasePluginKey, E as Editor, n as getRichTextExtensions, f as SuperInput, e as SuperEditor, A as AIWriter, g as SuperToolbar, i as createZip } from "./super-editor.es-Ccu1wOj1.es.js";
2
2
  import { a0 as effectScope, r as ref, _ as markRaw, $ as process$1, a1 as toRaw, d as computed, a2 as isRef, a3 as isReactive, C as toRef, i as inject, p as getCurrentInstance, l as watch, x as unref, a4 as hasInjectionContext, M as reactive, s as nextTick, a5 as getCurrentScope, a6 as onScopeDispose, a7 as toRefs, g as global$1, J as shallowRef, N as readonly, j as onMounted, k as onBeforeUnmount, h as onBeforeMount, S as onActivated, q as onDeactivated, z as createTextVNode, F as Fragment, Q as Comment, m as defineComponent, D as provide, H as withDirectives, B as h, U as Teleport, R as renderSlot, V as isVNode, I as watchEffect, O as Transition, a8 as TransitionGroup, E as mergeProps, P as vShow, G as cloneVNode, T as Text, c as createElementBlock, o as openBlock, t as toDisplayString, v as createVNode, y as withCtx, a as createBaseVNode, A as normalizeStyle, f as createCommentVNode, u as createBlock, w as withModifiers, n as normalizeClass, a9 as resolveDirective, e as renderList, b as createApp, X as resolveDynamicComponent, aa as defineAsyncComponent } from "./vue-CXxsqYcP.es.js";
3
3
  import { B as Buffer$2 } from "./jszip-B8KIZSNe.es.js";
4
4
  import { B as BlankDOCX } from "./blank-docx-iwdyG9RH.es.js";
@@ -17392,7 +17392,7 @@ const _sfc_main = {
17392
17392
  __name: "SuperDoc",
17393
17393
  emits: ["selection-update"],
17394
17394
  setup(__props, { emit: __emit }) {
17395
- const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-OEs-MC5j.es.js"));
17395
+ const PdfViewer = defineAsyncComponent(() => import("./PdfViewer-BBpGCmdE.es.js"));
17396
17396
  const superdocStore = useSuperdocStore();
17397
17397
  const commentsStore = useCommentsStore();
17398
17398
  const {
@@ -18052,6 +18052,9 @@ class SuperDoc extends EventEmitter {
18052
18052
  this.isDev = this.config.isDev || false;
18053
18053
  this.activeEditor = null;
18054
18054
  this.comments = [];
18055
+ if (!this.config.selector) {
18056
+ throw new Error("SuperDoc: selector is required");
18057
+ }
18055
18058
  this.app.mount(this.config.selector);
18056
18059
  this.readyEditors = 0;
18057
18060
  this.isLocked = this.config.isLocked || false;
@@ -18071,6 +18074,16 @@ class SuperDoc extends EventEmitter {
18071
18074
  users: this.users
18072
18075
  };
18073
18076
  }
18077
+ /**
18078
+ * Get the SuperDoc container element
18079
+ * @returns {HTMLElement | null}
18080
+ */
18081
+ get element() {
18082
+ if (typeof this.config.selector === "string") {
18083
+ return document.querySelector(this.config.selector);
18084
+ }
18085
+ return this.config.selector;
18086
+ }
18074
18087
  #patchNaiveUIStyles() {
18075
18088
  const cspNonce = this.config.cspNonce;
18076
18089
  const originalCreateElement = document.createElement;
@@ -18094,10 +18107,16 @@ class SuperDoc extends EventEmitter {
18094
18107
  }
18095
18108
  if (hasDocumentConfig) {
18096
18109
  const normalized = normalizeDocumentEntry(this.config.document);
18097
- this.config.documents = [normalized];
18110
+ this.config.documents = [
18111
+ {
18112
+ id: v4(),
18113
+ ...normalized
18114
+ }
18115
+ ];
18098
18116
  } else if (hasDocumentUrl) {
18099
18117
  this.config.documents = [
18100
18118
  {
18119
+ id: v4(),
18101
18120
  type: DOCX,
18102
18121
  url: this.config.document,
18103
18122
  name: "document.docx",
@@ -18105,33 +18124,34 @@ class SuperDoc extends EventEmitter {
18105
18124
  }
18106
18125
  ];
18107
18126
  } else if (hasDocumentFile) {
18127
+ const normalized = normalizeDocumentEntry(this.config.document);
18108
18128
  this.config.documents = [
18109
18129
  {
18110
- type: this.config.document.type,
18111
- data: this.config.document,
18112
- name: this.config.document.name,
18113
- isNewFile: true
18130
+ id: v4(),
18131
+ ...normalized
18114
18132
  }
18115
18133
  ];
18116
18134
  } else if (hasDocumentBlob) {
18117
- const docType = this.config.document.type || DOCX;
18118
- let extension = ".docx";
18119
- if (docType === PDF) {
18120
- extension = ".pdf";
18121
- } else if (docType === HTML) {
18122
- extension = ".html";
18123
- }
18135
+ const normalized = normalizeDocumentEntry(this.config.document);
18124
18136
  this.config.documents = [
18125
18137
  {
18126
- type: docType,
18127
- data: this.config.document,
18128
- name: `document${extension}`,
18129
- isNewFile: true
18138
+ id: v4(),
18139
+ ...normalized
18130
18140
  }
18131
18141
  ];
18132
18142
  }
18133
18143
  if (Array.isArray(this.config.documents) && this.config.documents.length > 0) {
18134
- this.config.documents = this.config.documents.map((d) => normalizeDocumentEntry(d));
18144
+ this.config.documents = this.config.documents.map((d) => {
18145
+ const normalized = normalizeDocumentEntry(d);
18146
+ if (!normalized || typeof normalized !== "object") {
18147
+ return normalized;
18148
+ }
18149
+ const existingId = typeof normalized === "object" && "id" in normalized && normalized.id || d && typeof d === "object" && "id" in d && d.id;
18150
+ return {
18151
+ ...normalized,
18152
+ id: existingId || v4()
18153
+ };
18154
+ });
18135
18155
  }
18136
18156
  }
18137
18157
  #initVueApp() {
@@ -24839,17 +24839,16 @@ const getParagraphSpacing = (node, docx, styleId = "", marks = [], options = {})
24839
24839
  };
24840
24840
  const getDefaultParagraphStyle = (docx, styleId = "") => {
24841
24841
  const styles = docx["word/styles.xml"];
24842
- if (!styles) {
24842
+ const rootElements = styles?.elements?.[0]?.elements;
24843
+ if (!rootElements?.length) {
24843
24844
  return {};
24844
24845
  }
24845
- const defaults = styles.elements[0].elements?.find((el) => el.name === "w:docDefaults");
24846
- const pDefault = defaults.elements.find((el) => el.name === "w:pPrDefault");
24846
+ const defaults = rootElements.find((el) => el.name === "w:docDefaults");
24847
+ const pDefault = defaults?.elements?.find((el) => el.name === "w:pPrDefault") || {};
24847
24848
  const pPrDefault = pDefault?.elements?.find((el) => el.name === "w:pPr");
24848
24849
  const pPrDefaultSpacingTag = pPrDefault?.elements?.find((el) => el.name === "w:spacing") || {};
24849
24850
  const pPrDefaultIndentTag = pPrDefault?.elements?.find((el) => el.name === "w:ind") || {};
24850
- const stylesNormal = styles.elements[0].elements?.find(
24851
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal"
24852
- );
24851
+ const stylesNormal = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === "Normal");
24853
24852
  const pPrNormal = stylesNormal?.elements?.find((el) => el.name === "w:pPr");
24854
24853
  const pPrNormalSpacingTag = pPrNormal?.elements?.find((el) => el.name === "w:spacing") || {};
24855
24854
  const pPrNormalIndentTag = pPrNormal?.elements?.find((el) => el.name === "w:ind") || {};
@@ -24858,9 +24857,7 @@ const getDefaultParagraphStyle = (docx, styleId = "") => {
24858
24857
  let pPrStyleIdIndentTag = {};
24859
24858
  let pPrStyleJc = {};
24860
24859
  if (styleId) {
24861
- const stylesById = styles.elements[0].elements?.find(
24862
- (el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId
24863
- );
24860
+ const stylesById = rootElements.find((el) => el.name === "w:style" && el.attributes["w:styleId"] === styleId);
24864
24861
  const pPrById = stylesById?.elements?.find((el) => el.name === "w:pPr");
24865
24862
  pPrStyleIdSpacingTag = pPrById?.elements?.find((el) => el.name === "w:spacing") || {};
24866
24863
  pPrStyleIdIndentTag = pPrById?.elements?.find((el) => el.name === "w:ind") || {};
@@ -30594,6 +30591,18 @@ const config = {
30594
30591
  attributes: validXmlAttributes
30595
30592
  };
30596
30593
  const translator = NodeTranslator.from(config);
30594
+ const DEFAULT_SECTION_PROPS_TWIPS = Object.freeze({
30595
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
30596
+ pageMargins: Object.freeze({
30597
+ top: "1440",
30598
+ right: "1440",
30599
+ bottom: "1440",
30600
+ left: "1440",
30601
+ header: "720",
30602
+ footer: "720",
30603
+ gutter: "0"
30604
+ })
30605
+ });
30597
30606
  const isLineBreakOnlyRun = (node) => {
30598
30607
  if (!node) return false;
30599
30608
  if (node.type === "lineBreak" || node.type === "hardBreak") return true;
@@ -30646,28 +30655,63 @@ function exportSchemaToJson(params2) {
30646
30655
  return handler2(params2);
30647
30656
  }
30648
30657
  function translateBodyNode(params2) {
30649
- let sectPr = params2.bodyNode?.elements.find((n) => n.name === "w:sectPr") || {};
30658
+ let sectPr = params2.bodyNode?.elements?.find((n) => n.name === "w:sectPr");
30659
+ if (!sectPr) {
30660
+ sectPr = {
30661
+ type: "element",
30662
+ name: "w:sectPr",
30663
+ elements: []
30664
+ };
30665
+ } else if (!sectPr.elements) {
30666
+ sectPr = { ...sectPr, elements: [] };
30667
+ }
30650
30668
  if (params2.converter) {
30651
- const hasHeader = sectPr?.elements?.some((n) => n.name === "w:headerReference");
30669
+ const hasHeader = sectPr.elements?.some((n) => n.name === "w:headerReference");
30652
30670
  const hasDefaultHeader = params2.converter.headerIds?.default;
30653
30671
  if (!hasHeader && hasDefaultHeader && !params2.editor.options.isHeaderOrFooter) {
30654
30672
  const defaultHeader = generateDefaultHeaderFooter("header", params2.converter.headerIds?.default);
30655
30673
  sectPr.elements.push(defaultHeader);
30656
30674
  }
30657
- const hasFooter = sectPr?.elements?.some((n) => n.name === "w:footerReference");
30675
+ const hasFooter = sectPr.elements?.some((n) => n.name === "w:footerReference");
30658
30676
  const hasDefaultFooter = params2.converter.footerIds?.default;
30659
30677
  if (!hasFooter && hasDefaultFooter && !params2.editor.options.isHeaderOrFooter) {
30660
30678
  const defaultFooter = generateDefaultHeaderFooter("footer", params2.converter.footerIds?.default);
30661
30679
  sectPr.elements.push(defaultFooter);
30662
30680
  }
30663
- const newMargins = params2.converter.pageStyles.pageMargins;
30664
- const sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30665
- const { attributes } = sectPrMargins;
30666
- Object.entries(newMargins).forEach(([key2, value]) => {
30667
- const convertedValue = inchesToTwips(value);
30668
- attributes[`w:${key2}`] = convertedValue;
30669
- });
30670
- sectPrMargins.attributes = attributes;
30681
+ const newMargins = params2.converter.pageStyles?.pageMargins;
30682
+ if (newMargins) {
30683
+ let sectPrMargins = sectPr.elements.find((n) => n.name === "w:pgMar");
30684
+ if (!sectPrMargins) {
30685
+ sectPrMargins = {
30686
+ type: "element",
30687
+ name: "w:pgMar",
30688
+ attributes: {}
30689
+ };
30690
+ sectPr.elements.push(sectPrMargins);
30691
+ } else if (!sectPrMargins.attributes) {
30692
+ sectPrMargins.attributes = {};
30693
+ }
30694
+ Object.entries(newMargins).forEach(([key2, value]) => {
30695
+ const convertedValue = inchesToTwips(value);
30696
+ sectPrMargins.attributes[`w:${key2}`] = convertedValue;
30697
+ });
30698
+ }
30699
+ let sectPrPgSz = sectPr.elements.find((n) => n.name === "w:pgSz");
30700
+ if (!sectPrPgSz) {
30701
+ sectPrPgSz = {
30702
+ type: "element",
30703
+ name: "w:pgSz",
30704
+ attributes: {}
30705
+ };
30706
+ sectPr.elements.push(sectPrPgSz);
30707
+ } else if (!sectPrPgSz.attributes) {
30708
+ sectPrPgSz.attributes = {};
30709
+ }
30710
+ const pageSize = params2.converter.pageStyles?.pageSize;
30711
+ const widthInches = pageSize?.width;
30712
+ const heightInches = pageSize?.height;
30713
+ sectPrPgSz.attributes["w:w"] = widthInches ? String(inchesToTwips(widthInches)) : sectPrPgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.width;
30714
+ sectPrPgSz.attributes["w:h"] = heightInches ? String(inchesToTwips(heightInches)) : sectPrPgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS_TWIPS.pageSize.height;
30671
30715
  }
30672
30716
  const elements = translateChildNodes(params2);
30673
30717
  if (params2.isHeaderFooter) {
@@ -32682,6 +32726,7 @@ const createDocumentJson = (docx, converter, editor) => {
32682
32726
  const nodeListHandler = defaultNodeListHandler();
32683
32727
  const bodyNode = json.elements[0].elements.find((el) => el.name === "w:body");
32684
32728
  if (bodyNode) {
32729
+ ensureSectionProperties(bodyNode);
32685
32730
  const node = bodyNode;
32686
32731
  const contentElements = node.elements?.filter((n) => n.name !== "w:sectPr") ?? [];
32687
32732
  const content = pruneIgnoredNodes(contentElements);
@@ -32915,6 +32960,59 @@ function getDocumentStyles(node, docx, converter, editor) {
32915
32960
  styles.alternateHeaders = isAlternatingHeadersOddEven(docx);
32916
32961
  return styles;
32917
32962
  }
32963
+ const DEFAULT_SECTION_PROPS = Object.freeze({
32964
+ pageSize: Object.freeze({ width: "12240", height: "15840" }),
32965
+ pageMargins: Object.freeze({
32966
+ top: "1440",
32967
+ right: "1440",
32968
+ bottom: "1440",
32969
+ left: "1440",
32970
+ header: "720",
32971
+ footer: "720",
32972
+ gutter: "0"
32973
+ })
32974
+ });
32975
+ function ensureSectionProperties(bodyNode, converter) {
32976
+ if (!bodyNode.elements) bodyNode.elements = [];
32977
+ let sectPr = bodyNode.elements.find((el) => el.name === "w:sectPr");
32978
+ if (!sectPr) {
32979
+ sectPr = {
32980
+ type: "element",
32981
+ name: "w:sectPr",
32982
+ elements: []
32983
+ };
32984
+ bodyNode.elements.push(sectPr);
32985
+ } else if (!sectPr.elements) {
32986
+ sectPr.elements = [];
32987
+ }
32988
+ const ensureChild = (name, factory) => {
32989
+ let child = sectPr.elements.find((el) => el.name === name);
32990
+ if (!child) {
32991
+ child = factory();
32992
+ sectPr.elements.push(child);
32993
+ } else if (!child.attributes) {
32994
+ child.attributes = {};
32995
+ }
32996
+ return child;
32997
+ };
32998
+ const pgSz = ensureChild("w:pgSz", () => ({
32999
+ type: "element",
33000
+ name: "w:pgSz",
33001
+ attributes: {}
33002
+ }));
33003
+ pgSz.attributes["w:w"] = pgSz.attributes["w:w"] ?? DEFAULT_SECTION_PROPS.pageSize.width;
33004
+ pgSz.attributes["w:h"] = pgSz.attributes["w:h"] ?? DEFAULT_SECTION_PROPS.pageSize.height;
33005
+ const pgMar = ensureChild("w:pgMar", () => ({
33006
+ type: "element",
33007
+ name: "w:pgMar",
33008
+ attributes: {}
33009
+ }));
33010
+ Object.entries(DEFAULT_SECTION_PROPS.pageMargins).forEach(([key2, value]) => {
33011
+ const attrKey = `w:${key2}`;
33012
+ if (pgMar.attributes[attrKey] == null) pgMar.attributes[attrKey] = value;
33013
+ });
33014
+ return sectPr;
33015
+ }
32918
33016
  function getStyleDefinitions(docx) {
32919
33017
  const styles = docx["word/styles.xml"];
32920
33018
  if (!styles) return [];
@@ -33107,6 +33205,36 @@ const FONT_FAMILY_FALLBACKS = Object.freeze({
33107
33205
  auto: "sans-serif"
33108
33206
  });
33109
33207
  const DEFAULT_GENERIC_FALLBACK = "sans-serif";
33208
+ const DEFAULT_FONT_SIZE_PT = 10;
33209
+ const collectRunDefaultProperties = (runProps, { allowOverrideTypeface = true, allowOverrideSize = true, themeResolver, state: state2 }) => {
33210
+ if (!runProps?.elements?.length || !state2) return;
33211
+ const fontsNode = runProps.elements.find((el) => el.name === "w:rFonts");
33212
+ if (fontsNode?.attributes) {
33213
+ const themeName = fontsNode.attributes["w:asciiTheme"];
33214
+ if (themeName) {
33215
+ const themeInfo = themeResolver?.(themeName) || {};
33216
+ if ((allowOverrideTypeface || !state2.typeface) && themeInfo.typeface) state2.typeface = themeInfo.typeface;
33217
+ if ((allowOverrideTypeface || !state2.panose) && themeInfo.panose) state2.panose = themeInfo.panose;
33218
+ }
33219
+ const ascii = fontsNode.attributes["w:ascii"];
33220
+ if ((allowOverrideTypeface || !state2.typeface) && ascii) {
33221
+ state2.typeface = ascii;
33222
+ }
33223
+ }
33224
+ const sizeNode = runProps.elements.find((el) => el.name === "w:sz");
33225
+ if (sizeNode?.attributes?.["w:val"]) {
33226
+ const sizeTwips = Number(sizeNode.attributes["w:val"]);
33227
+ if (Number.isFinite(sizeTwips)) {
33228
+ if (state2.fallbackSzTwips === void 0) state2.fallbackSzTwips = sizeTwips;
33229
+ const sizePt = sizeTwips / 2;
33230
+ if (allowOverrideSize || state2.fontSizePt === void 0) state2.fontSizePt = sizePt;
33231
+ }
33232
+ }
33233
+ const kernNode = runProps.elements.find((el) => el.name === "w:kern");
33234
+ if (kernNode?.attributes?.["w:val"]) {
33235
+ if (allowOverrideSize || state2.kern === void 0) state2.kern = kernNode.attributes["w:val"];
33236
+ }
33237
+ };
33110
33238
  const _SuperConverter = class _SuperConverter2 {
33111
33239
  constructor(params2 = null) {
33112
33240
  __privateAdd$2(this, _SuperConverter_instances);
@@ -33234,49 +33362,45 @@ const _SuperConverter = class _SuperConverter2 {
33234
33362
  }
33235
33363
  getDocumentDefaultStyles() {
33236
33364
  const styles = this.convertedXml["word/styles.xml"];
33237
- if (!styles) return {};
33238
- const defaults = styles.elements[0].elements.find((el) => el.name === "w:docDefaults");
33239
- const rDefault = defaults.elements.find((el) => el.name === "w:rPrDefault");
33240
- if (!rDefault.elements) return {};
33241
- const rElements = rDefault.elements[0].elements;
33242
- const rFonts = rElements?.find((el) => el.name === "w:rFonts");
33243
- if ("elements" in rDefault) {
33244
- const fontThemeName = rElements.find((el) => el.name === "w:rFonts")?.attributes["w:asciiTheme"];
33245
- let typeface, panose, fontSizeNormal;
33246
- if (fontThemeName) {
33247
- const fontInfo = this.getThemeInfo(fontThemeName);
33248
- typeface = fontInfo.typeface;
33249
- panose = fontInfo.panose;
33250
- } else if (rFonts) {
33251
- typeface = rFonts?.attributes["w:ascii"];
33252
- }
33253
- const paragraphDefaults = styles.elements[0].elements.filter((el) => {
33254
- return el.name === "w:style" && el.attributes["w:styleId"] === "Normal";
33255
- }) || [];
33256
- paragraphDefaults.forEach((el) => {
33257
- const rPr = el.elements.find((el2) => el2.name === "w:rPr");
33258
- const fonts = rPr?.elements?.find((el2) => el2.name === "w:rFonts");
33259
- typeface = fonts?.attributes["w:ascii"];
33260
- fontSizeNormal = Number(rPr?.elements?.find((el2) => el2.name === "w:sz")?.attributes["w:val"]) / 2;
33261
- });
33262
- const rPrDefaults = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33263
- if (rPrDefaults) {
33264
- const rPr = rPrDefaults.elements?.find((el) => el.name === "w:rPr");
33265
- const fonts = rPr?.elements?.find((el) => el.name === "w:rFonts");
33266
- if (fonts?.attributes?.["w:ascii"]) {
33267
- typeface = fonts.attributes["w:ascii"];
33268
- }
33269
- const fontSizeRaw = rPr?.elements?.find((el) => el.name === "w:sz")?.attributes?.["w:val"];
33270
- if (!fontSizeNormal && fontSizeRaw) {
33271
- fontSizeNormal = Number(fontSizeRaw) / 2;
33272
- }
33273
- }
33274
- const fallbackSz = Number(rElements.find((el) => el.name === "w:sz")?.attributes?.["w:val"]);
33275
- const fontSizePt = fontSizeNormal ?? (Number.isFinite(fallbackSz) ? fallbackSz / 2 : void 0) ?? 10;
33276
- const kern = rElements.find((el) => el.name === "w:kern")?.attributes["w:val"];
33277
- const fontFamilyCss = _SuperConverter2.toCssFontFamily(typeface, this.convertedXml);
33278
- return { fontSizePt, kern, typeface, panose, fontFamilyCss };
33279
- }
33365
+ const styleRoot = styles?.elements?.[0];
33366
+ const styleElements = styleRoot?.elements || [];
33367
+ if (!styleElements.length) return {};
33368
+ const defaults = styleElements.find((el) => el.name === "w:docDefaults");
33369
+ const normalStyle = styleElements.find((el) => el.name === "w:style" && el.attributes?.["w:styleId"] === "Normal");
33370
+ const defaultsState = {
33371
+ typeface: void 0,
33372
+ panose: void 0,
33373
+ fontSizePt: void 0,
33374
+ kern: void 0,
33375
+ fallbackSzTwips: void 0
33376
+ };
33377
+ const docDefaultRun = defaults?.elements?.find((el) => el.name === "w:rPrDefault");
33378
+ const docDefaultProps = docDefaultRun?.elements?.find((el) => el.name === "w:rPr") ?? docDefaultRun;
33379
+ collectRunDefaultProperties(docDefaultProps, {
33380
+ allowOverrideTypeface: true,
33381
+ allowOverrideSize: true,
33382
+ themeResolver: (theme) => this.getThemeInfo(theme),
33383
+ state: defaultsState
33384
+ });
33385
+ const normalRunProps = normalStyle?.elements?.find((el) => el.name === "w:rPr") ?? null;
33386
+ collectRunDefaultProperties(normalRunProps, {
33387
+ allowOverrideTypeface: true,
33388
+ allowOverrideSize: true,
33389
+ themeResolver: (theme) => this.getThemeInfo(theme),
33390
+ state: defaultsState
33391
+ });
33392
+ if (defaultsState.fontSizePt === void 0) {
33393
+ if (Number.isFinite(defaultsState.fallbackSzTwips)) defaultsState.fontSizePt = defaultsState.fallbackSzTwips / 2;
33394
+ else defaultsState.fontSizePt = DEFAULT_FONT_SIZE_PT;
33395
+ }
33396
+ const fontFamilyCss = defaultsState.typeface ? _SuperConverter2.toCssFontFamily(defaultsState.typeface, this.convertedXml) : void 0;
33397
+ const result = {};
33398
+ if (defaultsState.fontSizePt !== void 0) result.fontSizePt = defaultsState.fontSizePt;
33399
+ if (defaultsState.kern !== void 0) result.kern = defaultsState.kern;
33400
+ if (defaultsState.typeface) result.typeface = defaultsState.typeface;
33401
+ if (defaultsState.panose) result.panose = defaultsState.panose;
33402
+ if (fontFamilyCss) result.fontFamilyCss = fontFamilyCss;
33403
+ return result;
33280
33404
  }
33281
33405
  getDocumentFonts() {
33282
33406
  const fontTable = this.convertedXml["word/fontTable.xml"];
@@ -47929,9 +48053,11 @@ const toggleHeaderFooterEditMode = ({ editor, focusedSectionEditor, isEditMode,
47929
48053
  item.editor.view.dom.setAttribute("documentmode", documentMode);
47930
48054
  });
47931
48055
  if (isEditMode) {
47932
- const pm = document.querySelector(".ProseMirror");
47933
- pm.classList.add("header-footer-edit");
47934
- pm.setAttribute("aria-readonly", true);
48056
+ const pm = editor.view?.dom || editor.options.element?.querySelector?.(".ProseMirror");
48057
+ if (pm) {
48058
+ pm.classList.add("header-footer-edit");
48059
+ pm.setAttribute("aria-readonly", true);
48060
+ }
47935
48061
  }
47936
48062
  if (focusedSectionEditor) {
47937
48063
  focusedSectionEditor.view.focus();
@@ -50543,7 +50669,7 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
50543
50669
  setDocumentMode(documentMode) {
50544
50670
  let cleanedMode = documentMode?.toLowerCase() || "editing";
50545
50671
  if (!this.extensionService || !this.state) return;
50546
- const pm = document.querySelector(".ProseMirror");
50672
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
50547
50673
  if (this.options.role === "viewer") cleanedMode = "viewing";
50548
50674
  if (this.options.role === "suggester" && cleanedMode === "editing") cleanedMode = "suggesting";
50549
50675
  if (cleanedMode === "viewing") {
@@ -51517,9 +51643,11 @@ createView_fn = function(element) {
51517
51643
  isEditMode: false,
51518
51644
  documentMode: this.options.documentMode
51519
51645
  });
51520
- const pm = document.querySelector(".ProseMirror");
51521
- pm.classList.remove("header-footer-edit");
51522
- pm.setAttribute("aria-readonly", false);
51646
+ const pm = this.view?.dom || this.options.element?.querySelector?.(".ProseMirror");
51647
+ if (pm) {
51648
+ pm.classList.remove("header-footer-edit");
51649
+ pm.setAttribute("aria-readonly", false);
51650
+ }
51523
51651
  }
51524
51652
  setWordSelection(view, pos);
51525
51653
  }
@@ -69554,7 +69682,8 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
69554
69682
  const prevSelection = prevState.selection;
69555
69683
  if (selection.from !== prevSelection.from || selection.to !== prevSelection.to) {
69556
69684
  setTimeout(() => {
69557
- const selectedResizableWrapper = document.querySelector(".sd-editor-resizable-wrapper");
69685
+ const searchRoot = editorView?.dom;
69686
+ const selectedResizableWrapper = searchRoot?.querySelector(".sd-editor-resizable-wrapper");
69558
69687
  if (selectedResizableWrapper) {
69559
69688
  showResizeHandles(view2, selectedResizableWrapper);
69560
69689
  } else {
@@ -83090,7 +83219,7 @@ class SuperToolbar extends EventEmitter2 {
83090
83219
  if (!argument) return;
83091
83220
  item.onActivate({ zoom: argument });
83092
83221
  this.emit("superdoc-command", { item, argument });
83093
- const layers = document.querySelector(this.superdoc.config.selector)?.querySelector(".layers");
83222
+ const layers = this.superdoc.element?.querySelector(".layers");
83094
83223
  if (!layers) return;
83095
83224
  const isMobileDevice = typeof screen.orientation !== "undefined";
83096
83225
  const isSmallScreen = window.matchMedia("(max-width: 834px)").matches;