@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
@@ -40057,8 +40057,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40057
40057
  handlerName: "w:bookmarkEndTranslator",
40058
40058
  handler: handleBookmarkEndNode
40059
40059
  };
40060
- const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
40061
- const SUPPORTED_REQUIRES = /* @__PURE__ */ new Set([
40060
+ const SUPPORTED_ALTERNATE_CONTENT_REQUIRES = /* @__PURE__ */ new Set([
40062
40061
  "wps",
40063
40062
  "wp14",
40064
40063
  "w14",
@@ -40071,22 +40070,85 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40071
40070
  "w16sdtfl",
40072
40071
  "w16se"
40073
40072
  ]);
40073
+ const XML_NODE_NAME$1 = "mc:AlternateContent";
40074
+ const SD_NODE_NAME$1 = [];
40075
+ const validXmlAttributes$1 = [];
40076
+ function encode$1(params2) {
40077
+ const { nodeListHandler } = params2;
40078
+ const { node } = params2.extraParams;
40079
+ if (!node || !node.type) {
40080
+ return null;
40081
+ }
40082
+ const { branch, elements } = selectAlternateContentElements(node);
40083
+ if (!elements) {
40084
+ return null;
40085
+ }
40086
+ return nodeListHandler.handler({
40087
+ ...params2,
40088
+ nodes: elements,
40089
+ path: buildPath(params2.path, node, branch)
40090
+ });
40091
+ }
40092
+ function decode$1(params2) {
40093
+ const { node } = params2;
40094
+ const { drawingContent } = node.attrs;
40095
+ const drawing = {
40096
+ name: "w:drawing",
40097
+ elements: [...drawingContent ? [...drawingContent.elements || []] : []]
40098
+ };
40099
+ const choice = {
40100
+ name: "mc:Choice",
40101
+ attributes: { Requires: "wps" },
40102
+ elements: [drawing]
40103
+ };
40104
+ return {
40105
+ name: "mc:AlternateContent",
40106
+ elements: [choice]
40107
+ };
40108
+ }
40109
+ const config$1 = {
40110
+ xmlName: XML_NODE_NAME$1,
40111
+ sdNodeOrKeyName: SD_NODE_NAME$1,
40112
+ type: NodeTranslator.translatorTypes.NODE,
40113
+ encode: encode$1,
40114
+ decode: decode$1,
40115
+ attributes: validXmlAttributes$1
40116
+ };
40117
+ function selectAlternateContentElements(node) {
40118
+ if (!node?.elements?.length) {
40119
+ return { branch: null, elements: null };
40120
+ }
40121
+ const choices = node.elements.filter((el) => el?.name === "mc:Choice");
40122
+ const fallback = node.elements.find((el) => el?.name === "mc:Fallback");
40123
+ const supportedChoice = choices.find((choice) => {
40124
+ const requiresAttr = choice?.attributes?.Requires || choice?.attributes?.requires;
40125
+ if (!requiresAttr) return false;
40126
+ return requiresAttr.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_ALTERNATE_CONTENT_REQUIRES.has(namespace2));
40127
+ });
40128
+ const branch = supportedChoice || fallback || choices[0] || null;
40129
+ const selectedElements = branch?.elements;
40130
+ if (!selectedElements) {
40131
+ return { branch, elements: null };
40132
+ }
40133
+ return {
40134
+ branch,
40135
+ elements: carbonCopy(selectedElements)
40136
+ };
40137
+ }
40138
+ const translator$1 = NodeTranslator.from(config$1);
40139
+ function buildPath(existingPath = [], node, branch) {
40140
+ const path = [...existingPath];
40141
+ if (node) path.push(node);
40142
+ if (branch) path.push(branch);
40143
+ return path;
40144
+ }
40145
+ const ALTERNATE_CONTENT_NODE = "mc:AlternateContent";
40074
40146
  const skipHandlerResponse = { nodes: [], consumed: 0 };
40075
40147
  const isAlternateContentNode = (node) => node?.name === ALTERNATE_CONTENT_NODE;
40076
- const isSupportedChoice = (choice) => {
40077
- if (!choice?.attributes) return false;
40078
- const requires = choice.attributes.Requires || choice.attributes.requires;
40079
- if (!requires) return false;
40080
- return requires.split(/\s+/).filter(Boolean).some((namespace2) => SUPPORTED_REQUIRES.has(namespace2));
40081
- };
40082
40148
  const resolveAlternateContentElements = (alternateContent) => {
40083
- if (!alternateContent?.elements?.length) return null;
40084
- const choices = alternateContent.elements.filter((el) => el.name === "mc:Choice");
40085
- const fallback = alternateContent.elements.find((el) => el.name === "mc:Fallback");
40086
- const supportedChoice = choices.find(isSupportedChoice);
40087
- const selectedElements = supportedChoice?.elements || fallback?.elements || choices[0]?.elements;
40088
- if (!selectedElements) return null;
40089
- return carbonCopy(selectedElements);
40149
+ const { elements } = selectAlternateContentElements(alternateContent);
40150
+ if (!elements) return null;
40151
+ return elements;
40090
40152
  };
40091
40153
  const buildNodeWithoutAlternateContent = (node) => {
40092
40154
  const { elements } = node || {};
@@ -40118,16 +40180,20 @@ Please report this to https://github.com/markedjs/marked.`, e) {
40118
40180
  }
40119
40181
  const [currentNode] = nodes;
40120
40182
  if (isAlternateContentNode(currentNode)) {
40121
- const resolvedElements = resolveAlternateContentElements(currentNode);
40122
- if (!resolvedElements) {
40123
- return skipHandlerResponse;
40124
- }
40125
- const result2 = nodeListHandler.handler({
40183
+ const nodeForTranslator = currentNode?.type ? currentNode : {
40184
+ ...currentNode,
40185
+ type: "element"
40186
+ };
40187
+ const translated = translator$1.encode({
40126
40188
  ...params2,
40127
- nodes: resolvedElements,
40128
- path: [...params2.path || [], currentNode]
40189
+ nodes: [nodeForTranslator],
40190
+ extraParams: { ...params2.extraParams || {}, node: nodeForTranslator }
40129
40191
  });
40130
- return { nodes: result2, consumed: 1 };
40192
+ if (!translated) {
40193
+ return skipHandlerResponse;
40194
+ }
40195
+ const nodesArray = Array.isArray(translated) ? translated : [translated];
40196
+ return { nodes: nodesArray, consumed: 1 };
40131
40197
  }
40132
40198
  const sanitizedNode = buildNodeWithoutAlternateContent(currentNode);
40133
40199
  if (!sanitizedNode) {
@@ -41398,55 +41464,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
41398
41464
  };
41399
41465
  return textbox;
41400
41466
  }
41401
- const XML_NODE_NAME$1 = "mc:AlternateContent";
41402
- const SD_NODE_NAME$1 = [];
41403
- const validXmlAttributes$1 = [];
41404
- function encode$1(params2) {
41405
- const { nodeListHandler } = params2;
41406
- const { node } = params2.extraParams;
41407
- if (!node || !node.type) {
41408
- return null;
41409
- }
41410
- const allowedNamespaces = ["wps", "wp14", "w14", "w15"];
41411
- const wpsNode = node.elements.find(
41412
- (el) => el.name === "mc:Choice" && allowedNamespaces.includes(el.attributes["Requires"])
41413
- );
41414
- if (!wpsNode) {
41415
- return null;
41416
- }
41417
- const contents = wpsNode.elements;
41418
- return nodeListHandler.handler({
41419
- ...params2,
41420
- nodes: contents,
41421
- path: [...params2.path || [], wpsNode]
41422
- });
41423
- }
41424
- function decode$1(params2) {
41425
- const { node } = params2;
41426
- const { drawingContent } = node.attrs;
41427
- const drawing = {
41428
- name: "w:drawing",
41429
- elements: [...drawingContent ? [...drawingContent.elements || []] : []]
41430
- };
41431
- const choice = {
41432
- name: "mc:Choice",
41433
- attributes: { Requires: "wps" },
41434
- elements: [drawing]
41435
- };
41436
- return {
41437
- name: "mc:AlternateContent",
41438
- elements: [choice]
41439
- };
41440
- }
41441
- const config$1 = {
41442
- xmlName: XML_NODE_NAME$1,
41443
- sdNodeOrKeyName: SD_NODE_NAME$1,
41444
- type: NodeTranslator.translatorTypes.NODE,
41445
- encode: encode$1,
41446
- decode: decode$1,
41447
- attributes: validXmlAttributes$1
41448
- };
41449
- const translator$1 = NodeTranslator.from(config$1);
41450
41467
  function translateContentBlock(params2) {
41451
41468
  const { node } = params2;
41452
41469
  const { vmlAttributes, horizontalRule } = node.attrs;
@@ -46050,7 +46067,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
46050
46067
  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);
46051
46068
  var __privateSet = (obj, member, value, setter) => (__accessCheck$1(obj, member, "write to private field"), member.set(obj, value), value);
46052
46069
  var __privateMethod$1 = (obj, member, method) => (__accessCheck$1(obj, member, "access private method"), method);
46053
- 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;
46070
+ 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;
46054
46071
  var GOOD_LEAF_SIZE = 200;
46055
46072
  var RopeSequence = function RopeSequence2() {
46056
46073
  };
@@ -60265,7 +60282,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
60265
60282
  isHeaderFooterChanged: false,
60266
60283
  isCustomXmlChanged: false,
60267
60284
  focusTarget: null,
60268
- permissionResolver: null
60285
+ permissionResolver: null,
60286
+ // header/footer editors may have parent(main) editor set
60287
+ parentEditor: null
60269
60288
  });
60270
60289
  __privateMethod$1(this, _Editor_instances, initContainerElement_fn).call(this, options);
60271
60290
  __privateMethod$1(this, _Editor_instances, checkHeadless_fn).call(this, options);
@@ -61233,9 +61252,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61233
61252
  this.emit("beforeCreate", { editor: this });
61234
61253
  this.on("contentError", this.options.onContentError);
61235
61254
  this.mount(this.options.element);
61236
- if (!this.options.isHeadless) {
61237
- __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
61238
- }
61239
61255
  this.on("create", this.options.onCreate);
61240
61256
  this.on("update", this.options.onUpdate);
61241
61257
  this.on("selectionUpdate", this.options.onSelectionUpdate);
@@ -61257,8 +61273,12 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61257
61273
  if (!this.options.isHeadless) {
61258
61274
  this.initializeCollaborationData();
61259
61275
  this.initDefaultStyles();
61276
+ __privateMethod$1(this, _Editor_instances, checkFonts_fn).call(this);
61260
61277
  }
61261
- if (!this.options.ydoc || this.options.markdown || this.options.html) {
61278
+ const shouldMigrateListsOnInit = Boolean(
61279
+ this.options.markdown || this.options.html || this.options.loadFromSchema || this.options.jsonOverride || this.options.mode === "html" || this.options.mode === "text"
61280
+ );
61281
+ if (shouldMigrateListsOnInit) {
61262
61282
  this.migrateListsToV2();
61263
61283
  }
61264
61284
  this.setDocumentMode(this.options.documentMode);
@@ -61399,52 +61419,18 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61399
61419
  if (this.options.isHeadless) {
61400
61420
  return;
61401
61421
  }
61402
- const fontsUsedInDocument = this.converter.getDocumentFonts();
61403
- if (!("queryLocalFonts" in window)) {
61404
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61405
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61406
- this.emit("fonts-resolved", {
61407
- documentFonts: fontsUsedInDocument,
61408
- unsupportedFonts
61409
- });
61410
- return;
61411
- }
61412
- const localFontAccess = await navigator.permissions.query({ name: "local-fonts" });
61413
- if (localFontAccess.state === "denied") {
61414
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61415
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61416
- this.emit("fonts-resolved", {
61417
- documentFonts: fontsUsedInDocument,
61418
- unsupportedFonts
61419
- });
61420
- return;
61421
- }
61422
61422
  try {
61423
- const localFonts = await window.queryLocalFonts();
61424
- const uniqueLocalFonts = [...new Set(localFonts.map((font) => font.family))];
61425
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithLocalFonts_fn).call(this, fontsUsedInDocument, uniqueLocalFonts);
61423
+ const fontsUsedInDocument = this.converter.getDocumentFonts();
61424
+ const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFonts_fn).call(this, fontsUsedInDocument);
61426
61425
  this.emit("fonts-resolved", {
61427
61426
  documentFonts: fontsUsedInDocument,
61428
61427
  unsupportedFonts
61429
61428
  });
61430
61429
  } catch {
61431
- console.warn("[SuperDoc] Could not get access to local fonts. Using fallback solution.");
61432
- const unsupportedFonts = __privateMethod$1(this, _Editor_instances, determineUnsupportedFontsWithCanvas_fn).call(this, fontsUsedInDocument);
61433
- this.emit("fonts-resolved", {
61434
- documentFonts: fontsUsedInDocument,
61435
- unsupportedFonts
61436
- });
61430
+ console.warn("[SuperDoc] Could not determine document fonts and unsupported fonts");
61437
61431
  }
61438
61432
  };
61439
- determineUnsupportedFontsWithLocalFonts_fn = function(fonts, localFonts) {
61440
- const unsupportedFonts = fonts.filter((font) => {
61441
- const isLocalFont = localFonts.includes(font);
61442
- const isFontImported = this.fontsImported.includes(font);
61443
- return !isLocalFont && !isFontImported;
61444
- });
61445
- return unsupportedFonts;
61446
- };
61447
- determineUnsupportedFontsWithCanvas_fn = function(fonts) {
61433
+ determineUnsupportedFonts_fn = function(fonts) {
61448
61434
  const unsupportedFonts = fonts.filter((font) => {
61449
61435
  const canRender = canRenderFont(font);
61450
61436
  const isFontImported = this.fontsImported.includes(font);
@@ -61532,6 +61518,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
61532
61518
  if (this.options.collaborationIsReady) return;
61533
61519
  console.debug("🔗 [super-editor] Collaboration ready");
61534
61520
  __privateMethod$1(this, _Editor_instances, validateDocumentInit_fn).call(this);
61521
+ if (this.options.ydoc) {
61522
+ this.migrateListsToV2();
61523
+ }
61535
61524
  this.options.onCollaborationReady({ editor, ydoc });
61536
61525
  this.options.collaborationIsReady = true;
61537
61526
  this.options.initialState = this.state;
@@ -72503,58 +72492,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72503
72492
  }
72504
72493
  });
72505
72494
  };
72506
- const normalizeWrap = (attrs = {}) => {
72507
- const wrap2 = attrs.wrap;
72508
- if (wrap2?.type && wrap2.type !== "Inline") {
72509
- return {
72510
- type: wrap2.type,
72511
- attrs: wrap2.attrs ?? {}
72512
- };
72513
- }
72514
- if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72515
- return {
72516
- type: "Inline",
72517
- attrs: wrap2.attrs
72518
- };
72519
- }
72520
- if (!wrap2 && attrs.wrapText) {
72521
- return {
72522
- type: "Square",
72523
- attrs: {
72524
- wrapText: attrs.wrapText
72525
- }
72526
- };
72527
- }
72528
- if (!wrap2 && attrs.wrapTopAndBottom) {
72529
- return {
72530
- type: "TopAndBottom",
72531
- attrs: {}
72532
- };
72533
- }
72534
- if (wrap2?.type === "Inline") {
72535
- return {
72536
- type: "Inline",
72537
- attrs: wrap2.attrs ?? {}
72538
- };
72539
- }
72540
- return {
72541
- type: "Inline",
72542
- attrs: {}
72543
- };
72544
- };
72545
- const normalizeMarginOffset = (marginOffset = {}) => {
72546
- const { left: left2, horizontal, ...rest } = marginOffset;
72547
- return {
72548
- ...rest,
72549
- horizontal: horizontal ?? left2
72550
- };
72551
- };
72552
- const getNormalizedImageAttrs = (attrs = {}) => {
72553
- return {
72554
- wrap: normalizeWrap(attrs),
72555
- marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72556
- };
72557
- };
72558
72495
  const ImagePositionPluginKey = new PluginKey("ImagePosition");
72559
72496
  const ImagePositionPlugin = ({ editor }) => {
72560
72497
  const { view } = editor;
@@ -72567,8 +72504,9 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72567
72504
  return DecorationSet.empty;
72568
72505
  },
72569
72506
  apply(tr, oldDecorationSet, oldState, newState) {
72570
- if (!tr.docChanged) return oldDecorationSet;
72507
+ if (!tr.docChanged && !shouldUpdate) return oldDecorationSet;
72571
72508
  const decorations = getImagePositionDecorations(newState, view);
72509
+ shouldUpdate = false;
72572
72510
  return DecorationSet.create(newState.doc, decorations);
72573
72511
  }
72574
72512
  },
@@ -72577,7 +72515,6 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72577
72515
  update: (view2, lastState) => {
72578
72516
  const pagination = PaginationPluginKey.getState(lastState);
72579
72517
  if (shouldUpdate) {
72580
- shouldUpdate = false;
72581
72518
  const decorations = getImagePositionDecorations(lastState, view2);
72582
72519
  const updateTransaction = view2.state.tr.setMeta(ImagePositionPluginKey, { decorations });
72583
72520
  view2.dispatch(updateTransaction);
@@ -72603,41 +72540,35 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72603
72540
  let className = "";
72604
72541
  const { vRelativeFrom, alignH } = node.attrs.anchorData;
72605
72542
  const { size: size2, padding } = node.attrs;
72606
- const { marginOffset } = getNormalizedImageAttrs(node.attrs);
72607
72543
  const pageBreak = findPreviousDomNodeWithClass(view, pos, "pagination-break-wrapper");
72608
- if (pageBreak) {
72609
- switch (alignH) {
72610
- case "left":
72611
- style2 += "float: left; left: 0; margin-left: 0; ";
72612
- break;
72613
- case "right":
72614
- style2 += "float: right; right: 0; margin-right: 0; ";
72615
- break;
72616
- case "center":
72617
- style2 += "display: block; margin-left: auto; margin-right: auto; ";
72618
- break;
72544
+ if (pageBreak && vRelativeFrom === "margin" && alignH) {
72545
+ const topPos = pageBreak?.offsetTop + pageBreak?.offsetHeight;
72546
+ let horizontalAlignment = `${alignH}: 0;`;
72547
+ if (alignH === "center") horizontalAlignment = "left: 50%; transform: translateX(-50%);";
72548
+ style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ${horizontalAlignment}` : "";
72549
+ const nextPos = view.posAtDOM(pageBreak, 1);
72550
+ if (nextPos < 0) {
72551
+ const $pos = view.state.doc.resolve(pos);
72552
+ decorations.push(
72553
+ Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72554
+ style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72555
+ })
72556
+ );
72619
72557
  }
72620
- const topPos = marginOffset.top !== void 0 ? marginOffset.top : pageBreak?.offsetTop + pageBreak?.offsetHeight;
72621
- style2 += vRelativeFrom === "margin" ? `position: absolute; top: ${topPos}px; ` : "";
72622
- if (vRelativeFrom === "margin") {
72623
- const nextPos = view.posAtDOM(pageBreak, 1);
72624
- if (nextPos < 0) {
72625
- const $pos = view.state.doc.resolve(pos);
72626
- decorations.push(
72627
- Decoration.node(pos - 1, pos + $pos.parent.nodeSize - 1, {
72628
- style: `height: ${size2.height + parseInt(padding.top) + parseInt(padding.bottom)}px`
72629
- })
72630
- );
72631
- }
72632
- const imageBlock = document.createElement("div");
72633
- imageBlock.className = "anchor-image-placeholder";
72634
- imageBlock.style.float = alignH;
72635
- imageBlock.style.width = size2.width + parseInt(padding[alignH]) + "px";
72636
- imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72637
- decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72558
+ const imageBlock = document.createElement("div");
72559
+ imageBlock.className = "anchor-image-placeholder";
72560
+ imageBlock.style.float = alignH === "left" || alignH === "right" ? alignH : "none";
72561
+ let paddingHorizontal;
72562
+ if (alignH === "center") {
72563
+ paddingHorizontal = (parseInt(padding.left) || 0) + (parseInt(padding.right) || 0);
72564
+ } else {
72565
+ paddingHorizontal = parseInt(padding[alignH]) || 0;
72638
72566
  }
72567
+ imageBlock.style.width = size2.width + paddingHorizontal + "px";
72568
+ imageBlock.style.height = size2.height + parseInt(padding.top) + parseInt(padding.bottom) + "px";
72569
+ decorations.push(Decoration.widget(nextPos, imageBlock, { key: "stable-key" }));
72570
+ decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72639
72571
  }
72640
- decorations.push(Decoration.inline(pos, pos + node.nodeSize, { style: style2, class: className }));
72641
72572
  }
72642
72573
  });
72643
72574
  return decorations;
@@ -72662,6 +72593,58 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72662
72593
  }
72663
72594
  return null;
72664
72595
  };
72596
+ const normalizeWrap = (attrs = {}) => {
72597
+ const wrap2 = attrs.wrap;
72598
+ if (wrap2?.type && wrap2.type !== "Inline") {
72599
+ return {
72600
+ type: wrap2.type,
72601
+ attrs: wrap2.attrs ?? {}
72602
+ };
72603
+ }
72604
+ if (wrap2?.type === "Inline" && Object.keys(wrap2.attrs ?? {}).length) {
72605
+ return {
72606
+ type: "Inline",
72607
+ attrs: wrap2.attrs
72608
+ };
72609
+ }
72610
+ if (!wrap2 && attrs.wrapText) {
72611
+ return {
72612
+ type: "Square",
72613
+ attrs: {
72614
+ wrapText: attrs.wrapText
72615
+ }
72616
+ };
72617
+ }
72618
+ if (!wrap2 && attrs.wrapTopAndBottom) {
72619
+ return {
72620
+ type: "TopAndBottom",
72621
+ attrs: {}
72622
+ };
72623
+ }
72624
+ if (wrap2?.type === "Inline") {
72625
+ return {
72626
+ type: "Inline",
72627
+ attrs: wrap2.attrs ?? {}
72628
+ };
72629
+ }
72630
+ return {
72631
+ type: "Inline",
72632
+ attrs: {}
72633
+ };
72634
+ };
72635
+ const normalizeMarginOffset = (marginOffset = {}) => {
72636
+ const { left: left2, horizontal, ...rest } = marginOffset;
72637
+ return {
72638
+ ...rest,
72639
+ horizontal: horizontal ?? left2
72640
+ };
72641
+ };
72642
+ const getNormalizedImageAttrs = (attrs = {}) => {
72643
+ return {
72644
+ wrap: normalizeWrap(attrs),
72645
+ marginOffset: normalizeMarginOffset(attrs.marginOffset ?? {})
72646
+ };
72647
+ };
72665
72648
  const getRotationMargins = (w2, h2, angleDegrees) => {
72666
72649
  const rad = angleDegrees * (Math.PI / 180);
72667
72650
  const cos = Math.abs(Math.cos(rad));
@@ -72870,27 +72853,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72870
72853
  style2 += "float: right;";
72871
72854
  floatRight = true;
72872
72855
  } else if (["largest", "bothSides"].includes(attrs.wrapText)) {
72873
- const pageStyles2 = this.editor?.converter?.pageStyles;
72874
- if (pageStyles2?.pageSize && pageStyles2?.pageMargins && size2.width) {
72875
- const pageWidth = inchesToPixels(pageStyles2.pageSize.width);
72876
- const leftMargin = inchesToPixels(pageStyles2.pageMargins.left);
72877
- const rightMargin = inchesToPixels(pageStyles2.pageMargins.right);
72878
- const contentWidth = pageWidth - leftMargin - rightMargin;
72879
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72880
- const leftSpace = marginOffset.horizontal;
72881
- const rightSpace = contentWidth - leftSpace - imageWidth;
72882
- if (rightSpace < 0) {
72883
- style2 += "float: left;";
72884
- } else if (rightSpace > leftSpace) {
72885
- style2 += "float: left;";
72886
- } else {
72887
- style2 += "float: right;";
72888
- floatRight = true;
72889
- baseHorizontal = rightSpace;
72890
- }
72891
- } else {
72892
- style2 += "float: left;";
72893
- }
72856
+ const pageStylesData2 = getDataFromPageStyles({
72857
+ editor: this.editor,
72858
+ marginOffset,
72859
+ size: size2,
72860
+ attrs
72861
+ });
72862
+ style2 += pageStylesData2.style;
72863
+ floatRight = pageStylesData2.floatRight;
72864
+ baseHorizontal = pageStylesData2.baseHorizontal;
72894
72865
  }
72895
72866
  if (attrs.distTop) margin.top += attrs.distTop;
72896
72867
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
@@ -72900,27 +72871,15 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72900
72871
  case "Through":
72901
72872
  case "Tight":
72902
72873
  style2 += "clear: both;";
72903
- const pageStyles = this.editor?.converter?.pageStyles;
72904
- if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
72905
- const pageWidth = inchesToPixels(pageStyles.pageSize.width);
72906
- const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
72907
- const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
72908
- const contentWidth = pageWidth - leftMargin - rightMargin;
72909
- const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
72910
- const leftSpace = marginOffset.horizontal;
72911
- const rightSpace = contentWidth - leftSpace - imageWidth;
72912
- if (rightSpace < 0) {
72913
- style2 += "float: left;";
72914
- } else if (rightSpace > leftSpace) {
72915
- style2 += "float: left;";
72916
- } else {
72917
- style2 += "float: right;";
72918
- floatRight = true;
72919
- baseHorizontal = rightSpace;
72920
- }
72921
- } else {
72922
- style2 += "float: left;";
72923
- }
72874
+ const pageStylesData = getDataFromPageStyles({
72875
+ editor: this.editor,
72876
+ marginOffset,
72877
+ size: size2,
72878
+ attrs
72879
+ });
72880
+ style2 += pageStylesData.style;
72881
+ floatRight = pageStylesData.floatRight;
72882
+ baseHorizontal = pageStylesData.baseHorizontal;
72924
72883
  if (attrs.distTop) margin.top += attrs.distTop;
72925
72884
  if (attrs.distBottom) margin.bottom += attrs.distBottom;
72926
72885
  if (attrs.distLeft) margin.left += attrs.distLeft;
@@ -72957,6 +72916,22 @@ Please report this to https://github.com/markedjs/marked.`, e) {
72957
72916
  }
72958
72917
  const hasAnchorData = Boolean(anchorData);
72959
72918
  const hasMarginOffsets = marginOffset?.horizontal != null || marginOffset?.top != null;
72919
+ if (hasAnchorData) {
72920
+ switch (anchorData.hRelativeFrom) {
72921
+ case "page":
72922
+ const pageStyles = this.editor?.converter?.pageStyles || this.editor?.options.parentEditor?.converter?.pageStyles;
72923
+ margin.left -= inchesToPixels(pageStyles?.pageMargins?.left) || 0;
72924
+ break;
72925
+ case "margin":
72926
+ if (anchorData.alignH === "center") {
72927
+ style2 += "position: absolute; left: 50%; transform: translateX(-50%);";
72928
+ }
72929
+ if (anchorData.alignH === "left" || anchorData.alignH === "right") {
72930
+ style2 += `position: absolute; ${anchorData.alignH}: 0;`;
72931
+ }
72932
+ break;
72933
+ }
72934
+ }
72960
72935
  if (hasAnchorData || hasMarginOffsets) {
72961
72936
  const relativeFromPageV = anchorData?.vRelativeFrom === "page";
72962
72937
  const maxMarginV = 500;
@@ -73105,6 +73080,37 @@ Please report this to https://github.com/markedjs/marked.`, e) {
73105
73080
  return [ImageRegistrationPlugin({ editor: this.editor }), ImagePositionPlugin({ editor: this.editor })];
73106
73081
  }
73107
73082
  });
73083
+ const getDataFromPageStyles = ({ editor, marginOffset, size: size2, attrs }) => {
73084
+ let style2 = "";
73085
+ let floatRight = false;
73086
+ let baseHorizontal = marginOffset?.horizontal || 0;
73087
+ const pageStyles = editor?.converter?.pageStyles || editor?.options.parentEditor?.converter?.pageStyles;
73088
+ if (pageStyles?.pageSize && pageStyles?.pageMargins && size2.width) {
73089
+ const pageWidth = inchesToPixels(pageStyles.pageSize.width);
73090
+ const leftMargin = inchesToPixels(pageStyles.pageMargins.left);
73091
+ const rightMargin = inchesToPixels(pageStyles.pageMargins.right);
73092
+ const contentWidth = pageWidth - leftMargin - rightMargin;
73093
+ const imageWidth = size2.width + (attrs.distLeft || 0) + (attrs.distRight || 0);
73094
+ const leftSpace = marginOffset.horizontal;
73095
+ const rightSpace = contentWidth - leftSpace - imageWidth;
73096
+ if (rightSpace < 0) {
73097
+ style2 += "float: left;";
73098
+ } else if (rightSpace > leftSpace) {
73099
+ style2 += "float: left;";
73100
+ } else {
73101
+ style2 += "float: right;";
73102
+ floatRight = true;
73103
+ baseHorizontal = rightSpace;
73104
+ }
73105
+ } else {
73106
+ style2 += "float: left;";
73107
+ }
73108
+ return {
73109
+ style: style2,
73110
+ floatRight,
73111
+ baseHorizontal
73112
+ };
73113
+ };
73108
73114
  const ACCEPT_IMAGE_TYPES = [".jpg", ".jpeg", ".png", "image/jpeg", "image/png"];
73109
73115
  const getFileOpener = () => {
73110
73116
  let fileInput = document.createElement("input");
@@ -80547,7 +80553,7 @@ Please report this to https://github.com/markedjs/marked.`, e) {
80547
80553
  return oldState;
80548
80554
  }
80549
80555
  if (typeof document === "undefined" || editor.options.isHeadless) return oldState;
80550
- if (editor.options.documentMode === "viewing" || !editor.isEditable) {
80556
+ if (!editor.options.isHeaderOrFooter && (editor.options.documentMode === "viewing" || !editor.isEditable)) {
80551
80557
  return DecorationSet.empty;
80552
80558
  }
80553
80559
  const { selection } = newState;
@@ -96689,8 +96695,12 @@ ${style2}
96689
96695
  Node: Node$1,
96690
96696
  Attribute,
96691
96697
  Extension,
96698
+ Mark,
96699
+ //
96692
96700
  Plugin,
96693
- Mark
96701
+ PluginKey,
96702
+ Decoration,
96703
+ DecorationSet
96694
96704
  };
96695
96705
  const DOCX = "application/vnd.openxmlformats-officedocument.wordprocessingml.document";
96696
96706
  const PDF = "application/pdf";