@harbour-enterprises/superdoc 0.25.0-next.3 → 0.25.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-DDL0V0l5.cjs → PdfViewer-8kRpbCwn.cjs} +1 -1
  2. package/dist/chunks/{PdfViewer-Y13XRanw.es.js → PdfViewer-DVToyLl3.es.js} +1 -1
  3. package/dist/chunks/{index-Bo5YCvD5.cjs → index-DisCF1vr.cjs} +2 -2
  4. package/dist/chunks/{index-DKNVSdr6.es.js → index-STsumey2.es.js} +2 -2
  5. package/dist/chunks/{super-editor.es-Ct2sXbNV.cjs → super-editor.es-QqtfiJGc.cjs} +255 -245
  6. package/dist/chunks/{super-editor.es-CYtLh0Ob.es.js → super-editor.es-rBPknGqQ.es.js} +255 -245
  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-gSy6s2VK.js → converter-DOkexB95.js} +89 -72
  10. package/dist/super-editor/chunks/{docx-zipper-CceGxV02.js → docx-zipper-Ci5JbfjE.js} +1 -1
  11. package/dist/super-editor/chunks/{editor-CoX24lXQ.js → editor-BOoGDORN.js} +171 -187
  12. package/dist/super-editor/chunks/{toolbar-BTw9-jfX.js → toolbar-DPI_cCm_.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/super-editor/src/core/Editor.d.ts +1 -0
  18. package/dist/super-editor/super-editor/src/core/super-converter/v3/handlers/mc/altermateContent/alternate-content-translator.d.ts +11 -0
  19. package/dist/super-editor/super-editor/src/index.d.ts +8 -2
  20. package/dist/super-editor/super-editor.es.js +16 -12
  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 +255 -245
  27. package/dist/superdoc.umd.js.map +1 -1
  28. package/package.json +1 -1
@@ -32332,8 +32332,7 @@ const bookmarkEndNodeHandlerEntity = {
32332
32332
  handlerName: "w:bookmarkEndTranslator",
32333
32333
  handler: handleBookmarkEndNode
32334
32334
  };
32335
- const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
32336
- const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
32335
+ const SUPPORTED_ALTERNATE_CONTENT_REQUIRES = /* @__PURE__ */ new Set([
32337
32336
  "wps",
32338
32337
  "wp14",
32339
32338
  "w14",
@@ -32346,22 +32345,85 @@ const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
32346
32345
  "w16sdtfl",
32347
32346
  "w16se"
32348
32347
  ]);
32348
+ const XML_NODE_NAME$1 = "mc:AlternateContent";
32349
+ const SD_NODE_NAME$1 = [];
32350
+ const validXmlAttributes$1 = [];
32351
+ function encode$1(params2) {
32352
+ const { nodeListHandler } = params2;
32353
+ const { node } = params2.extraParams;
32354
+ if (!node || !node.type) {
32355
+ return null;
32356
+ }
32357
+ const { branch, elements } = selectAlternateContentElements(node);
32358
+ if (!elements) {
32359
+ return null;
32360
+ }
32361
+ return nodeListHandler.handler({
32362
+ ...params2,
32363
+ nodes: elements,
32364
+ path: buildPath(params2.path, node, branch)
32365
+ });
32366
+ }
32367
+ function decode$1(params2) {
32368
+ const { node } = params2;
32369
+ const { drawingContent } = node.attrs;
32370
+ const drawing = {
32371
+ name: "w:drawing",
32372
+ elements: [...drawingContent ? [...drawingContent.elements || []] : []]
32373
+ };
32374
+ const choice = {
32375
+ name: "mc:Choice",
32376
+ attributes: { Requires: "wps" },
32377
+ elements: [drawing]
32378
+ };
32379
+ return {
32380
+ name: "mc:AlternateContent",
32381
+ elements: [choice]
32382
+ };
32383
+ }
32384
+ const config$1 = {
32385
+ xmlName: XML_NODE_NAME$1,
32386
+ sdNodeOrKeyName: SD_NODE_NAME$1,
32387
+ type: NodeTranslator.translatorTypes.NODE,
32388
+ encode: encode$1,
32389
+ decode: decode$1,
32390
+ attributes: validXmlAttributes$1
32391
+ };
32392
+ function selectAlternateContentElements(node) {
32393
+ if (!node?.elements?.length) {
32394
+ return { branch: null, elements: null };
32395
+ }
32396
+ const choices = node.elements.filter((el) => el?.name === "mc:Choice");
32397
+ const fallback = node.elements.find((el) => el?.name === "mc:Fallback");
32398
+ const supportedChoice = choices.find((choice) => {
32399
+ const requiresAttr = choice?.attributes?.Requires || choice?.attributes?.requires;
32400
+ if (!requiresAttr) return false;
32401
+ return requiresAttr.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_ALTERNATE_CONTENT_REQUIRES.has(namespace2));
32402
+ });
32403
+ const branch = supportedChoice || fallback || choices[0] || null;
32404
+ const selectedElements = branch?.elements;
32405
+ if (!selectedElements) {
32406
+ return { branch, elements: null };
32407
+ }
32408
+ return {
32409
+ branch,
32410
+ elements: carbonCopy(selectedElements)
32411
+ };
32412
+ }
32413
+ const translator$1 = NodeTranslator.from(config$1);
32414
+ function buildPath(existingPath = [], node, branch) {
32415
+ const path = [...existingPath];
32416
+ if (node) path.push(node);
32417
+ if (branch) path.push(branch);
32418
+ return path;
32419
+ }
32420
+ const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
32349
32421
  const skipHandlerResponse = { nodes: [], consumed: 0 };
32350
32422
  const isAlternateContentNode = (node) => node?.name === ALTERNATE_CONTENT_NODE;
32351
- const isSupportedChoice = (choice) => {
32352
- if (!choice?.attributes) return false;
32353
- const requires = choice.attributes.Requires || choice.attributes.requires;
32354
- if (!requires) return false;
32355
- return requires.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_REQUIRES.has(namespace2));
32356
- };
32357
32423
  const resolveAlternateContentElements = (alternateContent) => {
32358
- if (!alternateContent?.elements?.length) return null;
32359
- const choices = alternateContent.elements.filter((el) => el.name === "mc:Choice");
32360
- const fallback = alternateContent.elements.find((el) => el.name === "mc:Fallback");
32361
- const supportedChoice = choices.find(isSupportedChoice);
32362
- const selectedElements = supportedChoice?.elements || fallback?.elements || choices[0]?.elements;
32363
- if (!selectedElements) return null;
32364
- return carbonCopy(selectedElements);
32424
+ const { elements } = selectAlternateContentElements(alternateContent);
32425
+ if (!elements) return null;
32426
+ return elements;
32365
32427
  };
32366
32428
  const buildNodeWithoutAlternateContent = (node) => {
32367
32429
  const { elements } = node || {};
@@ -32393,16 +32455,20 @@ const handleAlternateChoice = (params2) => {
32393
32455
  }
32394
32456
  const [currentNode] = nodes;
32395
32457
  if (isAlternateContentNode(currentNode)) {
32396
- const resolvedElements = resolveAlternateContentElements(currentNode);
32397
- if (!resolvedElements) {
32398
- return skipHandlerResponse;
32399
- }
32400
- const result2 = nodeListHandler.handler({
32458
+ const nodeForTranslator = currentNode?.type ? currentNode : {
32459
+ ...currentNode,
32460
+ type: "element"
32461
+ };
32462
+ const translated = translator$1.encode({
32401
32463
  ...params2,
32402
- nodes: resolvedElements,
32403
- path: [...params2.path || [], currentNode]
32464
+ nodes: [nodeForTranslator],
32465
+ extraParams: { ...params2.extraParams || {}, node: nodeForTranslator }
32404
32466
  });
32405
- return { nodes: result2, consumed: 1 };
32467
+ if (!translated) {
32468
+ return skipHandlerResponse;
32469
+ }
32470
+ const nodesArray = Array.isArray(translated) ? translated : [translated];
32471
+ return { nodes: nodesArray, consumed: 1 };
32406
32472
  }
32407
32473
  const sanitizedNode = buildNodeWithoutAlternateContent(currentNode);
32408
32474
  if (!sanitizedNode) {
@@ -33700,55 +33766,6 @@ function translateShapeTextbox(params2) {
33700
33766
  };
33701
33767
  return textbox;
33702
33768
  }
33703
- const XML_NODE_NAME$1 = "mc:AlternateContent";
33704
- const SD_NODE_NAME$1 = [];
33705
- const validXmlAttributes$1 = [];
33706
- function encode$1(params2) {
33707
- const { nodeListHandler } = params2;
33708
- const { node } = params2.extraParams;
33709
- if (!node || !node.type) {
33710
- return null;
33711
- }
33712
- const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
33713
- const wpsNode = node.elements.find(
33714
- (el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
33715
- );
33716
- if (!wpsNode) {
33717
- return null;
33718
- }
33719
- const contents = wpsNode.elements;
33720
- return nodeListHandler.handler({
33721
- ...params2,
33722
- nodes: contents,
33723
- path: [...params2.path || [], wpsNode]
33724
- });
33725
- }
33726
- function decode$1(params2) {
33727
- const { node } = params2;
33728
- const { drawingContent } = node.attrs;
33729
- const drawing = {
33730
- name: "w:drawing",
33731
- elements: [...drawingContent ? [...drawingContent.elements || []] : []]
33732
- };
33733
- const choice = {
33734
- name: "mc:Choice",
33735
- attributes: { Requires: "wps" },
33736
- elements: [drawing]
33737
- };
33738
- return {
33739
- name: "mc:AlternateContent",
33740
- elements: [choice]
33741
- };
33742
- }
33743
- const config$1 = {
33744
- xmlName: XML_NODE_NAME$1,
33745
- sdNodeOrKeyName: SD_NODE_NAME$1,
33746
- type: NodeTranslator.translatorTypes.NODE,
33747
- encode: encode$1,
33748
- decode: decode$1,
33749
- attributes: validXmlAttributes$1
33750
- };
33751
- const translator$1 = NodeTranslator.from(config$1);
33752
33769
  function translateContentBlock(params2) {
33753
33770
  const { node } = params2;
33754
33771
  const { vmlAttributes, horizontalRule } = node.attrs;
@@ -38352,7 +38369,7 @@ var __privateGet$1 = (obj, member, getter) => (__accessCheck$1(obj, member, "rea
38352
38369
  var __privateAdd$1 = (obj, member, value) => member.has(obj) ? __typeError$1("Cannot add the same private member more than once") : member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
38353
38370
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
38354
38371
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
38355
- var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFontsWithLocalFonts_fn, determineUnsupportedFontsWithCanvas_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
38372
+ var _Attribute_static, getGlobalAttributes_fn, getNodeAndMarksAttributes_fn, _Schema_static, createNodesSchema_fn, createMarksSchema_fn, _events, _ExtensionService_instances, setupExtensions_fn, attachEditorEvents_fn, _editor, _stateValidators, _xmlValidators, _requiredNodeTypes, _requiredMarkTypes, _SuperValidator_instances, initializeValidators_fn, collectValidatorRequirements_fn, analyzeDocument_fn, _commandService, _Editor_instances, initContainerElement_fn, init_fn, initRichText_fn, onFocus_fn, checkHeadless_fn, registerCopyHandler_fn, insertNewFileData_fn, registerPluginByNameIfNotExists_fn, createExtensionService_fn, createCommandService_fn, createConverter_fn, initMedia_fn, initFonts_fn, checkFonts_fn, determineUnsupportedFonts_fn, createSchema_fn, generatePmData_fn, createView_fn, onCollaborationReady_fn, initComments_fn, initPagination_fn, dispatchTransaction_fn, handleNodeSelection_fn, prepareDocumentForImport_fn, prepareDocumentForExport_fn, endCollaboration_fn, validateDocumentInit_fn, validateDocumentExport_fn, initDevTools_fn, _DocumentSectionView_instances, init_fn2, addToolTip_fn, _ListItemNodeView_instances, init_fn3, _FieldAnnotationView_instances, createAnnotation_fn, _AutoPageNumberNodeView_instances, renderDom_fn, scheduleUpdateNodeStyle_fn;
38356
38373
  var GOOD_LEAF_SIZE = 200;
38357
38374
  var RopeSequence = function RopeSequence2() {
38358
38375
  };
@@ -52567,7 +52584,9 @@ const _Editor = class _Editor2 extends EventEmitter$1 {
52567
52584
  isHeaderFooterChanged: false,
52568
52585
  isCustomXmlChanged: false,
52569
52586
  focusTarget: null,
52570
- permissionResolver: null
52587
+ permissionResolver: null,
52588
+ // header/footer editors may have parent(main) editor set
52589
+ parentEditor: null
52571
52590
  });
52572
52591
  __privateMethod$1(this, _Editor_instances, initContainerElement_fn).call(this, options);
52573
52592
  __privateMethod$1(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -53535,9 +53554,6 @@ init_fn = function() {
53535
53554
  this.emit("beforeCreate", { editor: this });
53536
53555
  this.on("contentError", this.options.onContentError);
53537
53556
  this.mount(this.options.element);
53538
- if (!this.options.isHeadless) {
53539
- __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
53540
- }
53541
53557
  this.on("create", this.options.onCreate);
53542
53558
  this.on("update", this.options.onUpdate);
53543
53559
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -53559,8 +53575,12 @@ init_fn = function() {
53559
53575
  if (!this.options.isHeadless) {
53560
53576
  this.initializeCollaborationData();
53561
53577
  this.initDefaultStyles();
53578
+ __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
53562
53579
  }
53563
- if (!this.options.ydoc || this.options.markdown || this.options.html) {
53580
+ const shouldMigrateListsOnInit = Boolean(
53581
+ this.options.markdown || this.options.html || this.options.loadFromSchema || this.options.jsonOverride || this.options.mode === "html" || this.options.mode === "text"
53582
+ );
53583
+ if (shouldMigrateListsOnInit) {
53564
53584
  this.migrateListsToV2();
53565
53585
  }
53566
53586
  this.setDocumentMode(this.options.documentMode);
@@ -53701,52 +53721,18 @@ checkFonts_fn = async function() {
53701
53721
  if (this.options.isHeadless) {
53702
53722
  return;
53703
53723
  }
53704
- const fontsUsedInDocument = this.converter.getDocumentFonts();
53705
- if (!("queryLocalFonts" in window)) {
53706
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53707
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53708
- this.emit("fonts-resolved", {
53709
- documentFonts: fontsUsedInDocument,
53710
- unsupportedFonts
53711
- });
53712
- return;
53713
- }
53714
- const localFontAccess = await navigator.permissions.query({ name: "local-fonts" });
53715
- if (localFontAccess.state === "denied") {
53716
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53717
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53718
- this.emit("fonts-resolved", {
53719
- documentFonts: fontsUsedInDocument,
53720
- unsupportedFonts
53721
- });
53722
- return;
53723
- }
53724
53724
  try {
53725
- const localFonts = await window.queryLocalFonts();
53726
- const uniqueLocalFonts = [...new Set(localFonts.map((font) => font.family))];
53727
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithLocalFonts_fn).call(this, fontsUsedInDocument, uniqueLocalFonts);
53725
+ const fontsUsedInDocument = this.converter.getDocumentFonts();
53726
+ const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFonts_fn).call(this, fontsUsedInDocument);
53728
53727
  this.emit("fonts-resolved", {
53729
53728
  documentFonts: fontsUsedInDocument,
53730
53729
  unsupportedFonts
53731
53730
  });
53732
53731
  } catch {
53733
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
53734
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
53735
- this.emit("fonts-resolved", {
53736
- documentFonts: fontsUsedInDocument,
53737
- unsupportedFonts
53738
- });
53732
+ console.warn("[SuperDoc] Could not determine document fonts and unsupported fonts");
53739
53733
  }
53740
53734
  };
53741
- determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
53742
- const unsupportedFonts = fonts.filter((font) => {
53743
- const isLocalFont = localFonts.includes(font);
53744
- const isFontImported = this.fontsImported.includes(font);
53745
- return !isLocalFont && !isFontImported;
53746
- });
53747
- return unsupportedFonts;
53748
- };
53749
- determineUnsupportedFontsWithCanvas_fn = function(fonts) {
53735
+ determineUnsupportedFonts_fn = function(fonts) {
53750
53736
  const unsupportedFonts = fonts.filter((font) => {
53751
53737
  const canRender = canRenderFont(font);
53752
53738
  const isFontImported = this.fontsImported.includes(font);
@@ -53834,6 +53820,9 @@ onCollaborationReady_fn = function({ editor, ydoc }) {
53834
53820
  if (this.options.collaborationIsReady) return;
53835
53821
  console.debug("🔗 [super-editor] Collaboration ready");
53836
53822
  __privateMethod$1(this, _Editor_instances, validateDocumentInit_fn).call(this);
53823
+ if (this.options.ydoc) {
53824
+ this.migrateListsToV2();
53825
+ }
53837
53826
  this.options.onCollaborationReady({ editor, ydoc });
53838
53827
  this.options.collaborationIsReady = true;
53839
53828
  this.options.initialState = this.state;
@@ -64805,58 +64794,6 @@ const registerImages = async (foundImages, editor, view) => {
64805
64794
  }
64806
64795
  });
64807
64796
  };
64808
- const normalizeWrap = (attrs = {}) => {
64809
- const wrap2 = attrs.wrap;
64810
- if (wrap2?.type && wrap2.type !== "Inline") {
64811
- return {
64812
- type: wrap2.type,
64813
- attrs: wrap2.attrs ?? {}
64814
- };
64815
- }
64816
- if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
64817
- return {
64818
- type: "Inline",
64819
- attrs: wrap2.attrs
64820
- };
64821
- }
64822
- if (!wrap2 && attrs.wrapText) {
64823
- return {
64824
- type: "Square",
64825
- attrs: {
64826
- wrapText: attrs.wrapText
64827
- }
64828
- };
64829
- }
64830
- if (!wrap2 && attrs.wrapTopAndBottom) {
64831
- return {
64832
- type: "TopAndBottom",
64833
- attrs: {}
64834
- };
64835
- }
64836
- if (wrap2?.type === "Inline") {
64837
- return {
64838
- type: "Inline",
64839
- attrs: wrap2.attrs ?? {}
64840
- };
64841
- }
64842
- return {
64843
- type: "Inline",
64844
- attrs: {}
64845
- };
64846
- };
64847
- const normalizeMarginOffset = (marginOffset = {}) => {
64848
- const { left: left2, horizontal, ...rest } = marginOffset;
64849
- return {
64850
- ...rest,
64851
- horizontal: horizontal ?? left2
64852
- };
64853
- };
64854
- const getNormalizedImageAttrs = (attrs = {}) => {
64855
- return {
64856
- wrap: normalizeWrap(attrs),
64857
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
64858
- };
64859
- };
64860
64797
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
64861
64798
  const ImagePositionPlugin = ({ editor }) => {
64862
64799
  const { view } = editor;
@@ -64869,8 +64806,9 @@ const ImagePositionPlugin = ({ editor }) => {
64869
64806
  return DecorationSet.empty;
64870
64807
  },
64871
64808
  apply(tr, oldDecorationSet, oldState, newState) {
64872
- if (!tr.docChanged) return oldDecorationSet;
64809
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
64873
64810
  const decorations = getImagePositionDecorations(newState, view);
64811
+ shouldUpdate = false;
64874
64812
  return DecorationSet.create(newState.doc, decorations);
64875
64813
  }
64876
64814
  },
@@ -64879,7 +64817,6 @@ const ImagePositionPlugin = ({ editor }) => {
64879
64817
  update: (view2, lastState) => {
64880
64818
  const pagination = PaginationPluginKey.getState(lastState);
64881
64819
  if (shouldUpdate) {
64882
- shouldUpdate = false;
64883
64820
  const decorations = getImagePositionDecorations(lastState, view2);
64884
64821
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
64885
64822
  view2.dispatch(updateTransaction);
@@ -64905,41 +64842,35 @@ const getImagePositionDecorations = (state2, view) => {
64905
64842
  let className = "";
64906
64843
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
64907
64844
  const { size: size2, padding } = node.attrs;
64908
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
64909
64845
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
64910
- if (pageBreak) {
64911
- switch (alignH) {
64912
- case "left":
64913
- style2 += "float: left; left: 0; margin-left: 0; ";
64914
- break;
64915
- case "right":
64916
- style2 += "float: right; right: 0; margin-right: 0; ";
64917
- break;
64918
- case "center":
64919
- style2 += "display: block; margin-left: auto; margin-right: auto; ";
64920
- break;
64846
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
64847
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
64848
+ let horizontalAlignment = `${alignH}: 0;`;
64849
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
64850
+ style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
64851
+ const nextPos = view.posAtDOM(pageBreak, 1);
64852
+ if (nextPos < 0) {
64853
+ const $pos = view.state.doc.resolve(pos);
64854
+ decorations.push(
64855
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
64856
+ style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
64857
+ })
64858
+ );
64921
64859
  }
64922
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
64923
- style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
64924
- if (vRelativeFrom === "margin") {
64925
- const nextPos = view.posAtDOM(pageBreak, 1);
64926
- if (nextPos < 0) {
64927
- const $pos = view.state.doc.resolve(pos);
64928
- decorations.push(
64929
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
64930
- style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
64931
- })
64932
- );
64933
- }
64934
- const imageBlock = document.createElement("div");
64935
- imageBlock.className = "anchor-image-placeholder";
64936
- imageBlock.style.float = alignH;
64937
- imageBlock.style.width = size2.width + parseInt(padding[alignH]) + "px";
64938
- imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
64939
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
64860
+ const imageBlock = document.createElement("div");
64861
+ imageBlock.className = "anchor-image-placeholder";
64862
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
64863
+ let paddingHorizontal;
64864
+ if (alignH === "center") {
64865
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
64866
+ } else {
64867
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
64940
64868
  }
64869
+ imageBlock.style.width = size2.width + paddingHorizontal + "px";
64870
+ imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
64871
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
64872
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
64941
64873
  }
64942
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
64943
64874
  }
64944
64875
  });
64945
64876
  return decorations;
@@ -64964,6 +64895,58 @@ const findPreviousDomNodeWithClass = (view, pos, className) => {
64964
64895
  }
64965
64896
  return null;
64966
64897
  };
64898
+ const normalizeWrap = (attrs = {}) => {
64899
+ const wrap2 = attrs.wrap;
64900
+ if (wrap2?.type && wrap2.type !== "Inline") {
64901
+ return {
64902
+ type: wrap2.type,
64903
+ attrs: wrap2.attrs ?? {}
64904
+ };
64905
+ }
64906
+ if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
64907
+ return {
64908
+ type: "Inline",
64909
+ attrs: wrap2.attrs
64910
+ };
64911
+ }
64912
+ if (!wrap2 && attrs.wrapText) {
64913
+ return {
64914
+ type: "Square",
64915
+ attrs: {
64916
+ wrapText: attrs.wrapText
64917
+ }
64918
+ };
64919
+ }
64920
+ if (!wrap2 && attrs.wrapTopAndBottom) {
64921
+ return {
64922
+ type: "TopAndBottom",
64923
+ attrs: {}
64924
+ };
64925
+ }
64926
+ if (wrap2?.type === "Inline") {
64927
+ return {
64928
+ type: "Inline",
64929
+ attrs: wrap2.attrs ?? {}
64930
+ };
64931
+ }
64932
+ return {
64933
+ type: "Inline",
64934
+ attrs: {}
64935
+ };
64936
+ };
64937
+ const normalizeMarginOffset = (marginOffset = {}) => {
64938
+ const { left: left2, horizontal, ...rest } = marginOffset;
64939
+ return {
64940
+ ...rest,
64941
+ horizontal: horizontal ?? left2
64942
+ };
64943
+ };
64944
+ const getNormalizedImageAttrs = (attrs = {}) => {
64945
+ return {
64946
+ wrap: normalizeWrap(attrs),
64947
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
64948
+ };
64949
+ };
64967
64950
  const getRotationMargins = (w2, h2, angleDegrees) => {
64968
64951
  const rad = angleDegrees * (Math.PI / 180);
64969
64952
  const cos = Math.abs(Math.cos(rad));
@@ -65172,27 +65155,15 @@ const Image = Node$1.create({
65172
65155
  style2 += "float: right;";
65173
65156
  floatRight = true;
65174
65157
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
65175
- const pageStyles2 = this.editor?.converter?.pageStyles;
65176
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size2.width) {
65177
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
65178
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
65179
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
65180
- const contentWidth = pageWidth - leftMargin - rightMargin;
65181
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65182
- const leftSpace = marginOffset.horizontal;
65183
- const rightSpace = contentWidth - leftSpace - imageWidth;
65184
- if (rightSpace < 0) {
65185
- style2 += "float: left;";
65186
- } else if (rightSpace > leftSpace) {
65187
- style2 += "float: left;";
65188
- } else {
65189
- style2 += "float: right;";
65190
- floatRight = true;
65191
- baseHorizontal = rightSpace;
65192
- }
65193
- } else {
65194
- style2 += "float: left;";
65195
- }
65158
+ const pageStylesData2 = getDataFromPageStyles({
65159
+ editor: this.editor,
65160
+ marginOffset,
65161
+ size: size2,
65162
+ attrs
65163
+ });
65164
+ style2 += pageStylesData2.style;
65165
+ floatRight = pageStylesData2.floatRight;
65166
+ baseHorizontal = pageStylesData2.baseHorizontal;
65196
65167
  }
65197
65168
  if (attrs.distTop) margin.top += attrs.distTop;
65198
65169
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -65202,27 +65173,15 @@ const Image = Node$1.create({
65202
65173
  case "Through":
65203
65174
  case "Tight":
65204
65175
  style2 += "clear: both;";
65205
- const pageStyles = this.editor?.converter?.pageStyles;
65206
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
65207
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
65208
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
65209
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
65210
- const contentWidth = pageWidth - leftMargin - rightMargin;
65211
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65212
- const leftSpace = marginOffset.horizontal;
65213
- const rightSpace = contentWidth - leftSpace - imageWidth;
65214
- if (rightSpace < 0) {
65215
- style2 += "float: left;";
65216
- } else if (rightSpace > leftSpace) {
65217
- style2 += "float: left;";
65218
- } else {
65219
- style2 += "float: right;";
65220
- floatRight = true;
65221
- baseHorizontal = rightSpace;
65222
- }
65223
- } else {
65224
- style2 += "float: left;";
65225
- }
65176
+ const pageStylesData = getDataFromPageStyles({
65177
+ editor: this.editor,
65178
+ marginOffset,
65179
+ size: size2,
65180
+ attrs
65181
+ });
65182
+ style2 += pageStylesData.style;
65183
+ floatRight = pageStylesData.floatRight;
65184
+ baseHorizontal = pageStylesData.baseHorizontal;
65226
65185
  if (attrs.distTop) margin.top += attrs.distTop;
65227
65186
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
65228
65187
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -65259,6 +65218,22 @@ const Image = Node$1.create({
65259
65218
  }
65260
65219
  const hasAnchorData = Boolean(anchorData);
65261
65220
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
65221
+ if (hasAnchorData) {
65222
+ switch (anchorData.hRelativeFrom) {
65223
+ case "page":
65224
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
65225
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
65226
+ break;
65227
+ case "margin":
65228
+ if (anchorData.alignH === "center") {
65229
+ style2 += "position: absolute; left: 50%; transform: translateX(-50%);";
65230
+ }
65231
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
65232
+ style2 += `position: absolute; ${anchorData.alignH}: 0;`;
65233
+ }
65234
+ break;
65235
+ }
65236
+ }
65262
65237
  if (hasAnchorData || hasMarginOffsets) {
65263
65238
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
65264
65239
  const maxMarginV = 500;
@@ -65407,6 +65382,37 @@ const Image = Node$1.create({
65407
65382
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
65408
65383
  }
65409
65384
  });
65385
+ const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
65386
+ let style2 = "";
65387
+ let floatRight = false;
65388
+ let baseHorizontal = marginOffset?.horizontal || 0;
65389
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
65390
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
65391
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
65392
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
65393
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
65394
+ const contentWidth = pageWidth - leftMargin - rightMargin;
65395
+ const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
65396
+ const leftSpace = marginOffset.horizontal;
65397
+ const rightSpace = contentWidth - leftSpace - imageWidth;
65398
+ if (rightSpace < 0) {
65399
+ style2 += "float: left;";
65400
+ } else if (rightSpace > leftSpace) {
65401
+ style2 += "float: left;";
65402
+ } else {
65403
+ style2 += "float: right;";
65404
+ floatRight = true;
65405
+ baseHorizontal = rightSpace;
65406
+ }
65407
+ } else {
65408
+ style2 += "float: left;";
65409
+ }
65410
+ return {
65411
+ style: style2,
65412
+ floatRight,
65413
+ baseHorizontal
65414
+ };
65415
+ };
65410
65416
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
65411
65417
  const getFileOpener = () => {
65412
65418
  let fileInput = document.createElement("input");
@@ -72849,7 +72855,7 @@ const nodeResizer = (nodeNames = ["image"], editor) => {
72849
72855
  return oldState;
72850
72856
  }
72851
72857
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
72852
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
72858
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
72853
72859
  return DecorationSet.empty;
72854
72860
  }
72855
72861
  const { selection } = newState;
@@ -88991,8 +88997,12 @@ const Extensions = {
88991
88997
  Node: Node$1,
88992
88998
  Attribute: Attribute2,
88993
88999
  Extension,
89000
+ Mark: Mark2,
89001
+ //
88994
89002
  Plugin,
88995
- Mark: Mark2
89003
+ PluginKey,
89004
+ Decoration,
89005
+ DecorationSet
88996
89006
  };
88997
89007
  exports.AIWriter = AIWriter;
88998
89008
  exports.AnnotatorHelpers = AnnotatorHelpers;