@harbour-enterprises/superdoc 0.20.0-next.2 → 0.20.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 (49) hide show
  1. package/dist/chunks/{PdfViewer-_tL5RYr9.es.js → PdfViewer-BjZBgs8x.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-B6adMXJl.cjs → PdfViewer-Ne_-LxpG.cjs} +1 -1
  3. package/dist/chunks/{index-DwXeHvLq.es.js → index-BVjAJUtV.es.js} +2 -2
  4. package/dist/chunks/{index-mjjKSLDT.cjs → index-OFvCtpf7.cjs} +2 -2
  5. package/dist/chunks/{super-editor.es-DJHyk0Zs.cjs → super-editor.es-CCU9etUT.cjs} +1101 -715
  6. package/dist/chunks/{super-editor.es-CPrd1wq8.es.js → super-editor.es-DgTNVbvS.es.js} +1101 -715
  7. package/dist/core/SuperDoc.d.ts.map +1 -1
  8. package/dist/style.css +38 -0
  9. package/dist/super-editor/ai-writer.es.js +2 -2
  10. package/dist/super-editor/chunks/{converter-KHB8spG5.js → converter-BPTfSIJf.js} +919 -813
  11. package/dist/super-editor/chunks/{docx-zipper-B-vl4ISA.js → docx-zipper-ikgI-2vM.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-Df2sUgT0.js → editor-C1C_smD4.js} +294 -10
  13. package/dist/super-editor/chunks/{toolbar-C6JoUIM_.js → toolbar-pP4CmNcz.js} +2 -2
  14. package/dist/super-editor/converter.es.js +1 -1
  15. package/dist/super-editor/docx-zipper.es.js +2 -2
  16. package/dist/super-editor/editor.es.js +3 -3
  17. package/dist/super-editor/file-zipper.es.js +1 -1
  18. package/dist/super-editor/src/core/helpers/index.d.ts +1 -0
  19. package/dist/super-editor/src/core/helpers/updateDOMAttributes.d.ts +1 -0
  20. package/dist/super-editor/src/core/super-converter/exporter.d.ts +7 -1
  21. package/dist/super-editor/src/core/super-converter/v2/importer/imageImporter.d.ts +0 -1
  22. package/dist/super-editor/src/core/super-converter/v3/handlers/index.d.ts +2 -0
  23. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/drawing-translator.d.ts +6 -0
  24. package/dist/super-editor/src/core/super-converter/v3/handlers/w/drawing/index.d.ts +1 -0
  25. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/anchor-translator.d.ts +6 -0
  26. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/handle-anchor-node.d.ts +6 -0
  27. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/helpers/translate-anchor-node.d.ts +6 -0
  28. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/anchor/index.d.ts +1 -0
  29. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/decode-image-node-helpers.d.ts +18 -0
  30. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/helpers/encode-image-node-helpers.d.ts +6 -0
  31. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/handle-inline-node.d.ts +6 -0
  32. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/helpers/translate-inline-node.d.ts +6 -0
  33. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/index.d.ts +1 -0
  34. package/dist/super-editor/src/core/super-converter/v3/handlers/wp/inline/inline-translator.d.ts +6 -0
  35. package/dist/super-editor/src/extensions/structured-content/StructuredContentBlockView.d.ts +10 -0
  36. package/dist/super-editor/src/extensions/structured-content/StructuredContentInlineView.d.ts +10 -0
  37. package/dist/super-editor/src/extensions/structured-content/StructuredContentViewBase.d.ts +24 -0
  38. package/dist/super-editor/src/extensions/structured-content/structured-content-block.d.ts +3 -1
  39. package/dist/super-editor/src/extensions/structured-content/structured-content.d.ts +3 -1
  40. package/dist/super-editor/style.css +38 -0
  41. package/dist/super-editor/super-editor.es.js +8 -13
  42. package/dist/super-editor/toolbar.es.js +2 -2
  43. package/dist/super-editor.cjs +1 -1
  44. package/dist/super-editor.es.js +1 -1
  45. package/dist/superdoc.cjs +2 -2
  46. package/dist/superdoc.es.js +2 -2
  47. package/dist/superdoc.umd.js +1101 -715
  48. package/dist/superdoc.umd.js.map +1 -1
  49. package/package.json +1 -1
@@ -21390,7 +21390,7 @@ const isInTable$1 = (state2) => {
21390
21390
  };
21391
21391
  function stripHtmlStyles(html) {
21392
21392
  if (!html) return "";
21393
- const parser = new DOMParser();
21393
+ const parser = new window.DOMParser();
21394
21394
  const doc2 = parser.parseFromString(html, "text/html");
21395
21395
  const SUPPORTED_ATTRS = [
21396
21396
  "href",
@@ -21409,7 +21409,7 @@ function stripHtmlStyles(html) {
21409
21409
  "styleid"
21410
21410
  ];
21411
21411
  const cleanNode = (node) => {
21412
- if (node.nodeType !== Node.ELEMENT_NODE) return;
21412
+ if (node.nodeType !== window.Node.ELEMENT_NODE) return;
21413
21413
  [...node.attributes].forEach((attr) => {
21414
21414
  const name = attr.name.toLowerCase();
21415
21415
  const shouldKeep = SUPPORTED_ATTRS.includes(name) || name.startsWith("data-");
@@ -22552,6 +22552,23 @@ function processContent({ content, type: type2, schema }) {
22552
22552
  }
22553
22553
  return doc2;
22554
22554
  }
22555
+ const defaultBooleans = ["required", "readonly", "disabled", "checked", "multiple", "autofocus"];
22556
+ function updateDOMAttributes(dom, attrs = {}, options = {}) {
22557
+ const customBooleans = options.customBooleans || [];
22558
+ const booleans = [...defaultBooleans, ...customBooleans];
22559
+ Object.entries(attrs).forEach(([key, value]) => {
22560
+ if (booleans.includes(key)) {
22561
+ if (!value) dom.removeAttribute(key);
22562
+ else dom.setAttribute(key, "");
22563
+ return;
22564
+ }
22565
+ if (value != null) {
22566
+ dom.setAttribute(key, value);
22567
+ } else {
22568
+ dom.removeAttribute(key);
22569
+ }
22570
+ });
22571
+ }
22555
22572
  const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22556
22573
  __proto__: null,
22557
22574
  chainableEditorState,
@@ -22584,7 +22601,8 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
22584
22601
  isNodeActive,
22585
22602
  isTextSelection,
22586
22603
  posToDOMRect,
22587
- processContent
22604
+ processContent,
22605
+ updateDOMAttributes
22588
22606
  }, Symbol.toStringTag, { value: "Module" }));
22589
22607
  const generateNewListDefinition = ({ numId, listType, level, start: start2, text, fmt, editor }) => {
22590
22608
  if (typeof listType === "string") listType = editor.schema.nodes[listType];
@@ -24197,18 +24215,6 @@ const baseNumbering = {
24197
24215
  }
24198
24216
  ]
24199
24217
  };
24200
- const sanitizeDocxMediaName = (value, fallback = "image") => {
24201
- if (!value) return fallback;
24202
- const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
24203
- return sanitized || fallback;
24204
- };
24205
- const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
24206
- if (!src || typeof src !== "string") return fallback;
24207
- const [prefix2] = src.split(";");
24208
- const [, maybeType] = prefix2.split("/");
24209
- const extension = maybeType?.toLowerCase();
24210
- return extension ? `${fallback}.${extension}` : fallback;
24211
- };
24212
24218
  function preProcessVerticalMergeCells(table, { editorSchema }) {
24213
24219
  if (!table || !Array.isArray(table.content)) {
24214
24220
  return table;
@@ -24369,37 +24375,37 @@ const _NodeTranslator = class _NodeTranslator2 {
24369
24375
  };
24370
24376
  __publicField$2(_NodeTranslator, "translatorTypes", TranslatorTypes);
24371
24377
  let NodeTranslator = _NodeTranslator;
24372
- const encode$j = (attributes) => {
24378
+ const encode$m = (attributes) => {
24373
24379
  return attributes["w:type"];
24374
24380
  };
24375
- const decode$j = (attrs) => {
24381
+ const decode$m = (attrs) => {
24376
24382
  const { lineBreakType } = attrs;
24377
24383
  return lineBreakType;
24378
24384
  };
24379
24385
  const attrConfig$b = Object.freeze({
24380
24386
  xmlName: "w:type",
24381
24387
  sdName: "lineBreakType",
24382
- encode: encode$j,
24383
- decode: decode$j
24388
+ encode: encode$m,
24389
+ decode: decode$m
24384
24390
  });
24385
- const encode$i = (attributes) => {
24391
+ const encode$l = (attributes) => {
24386
24392
  const xmlAttrValue = attributes["w:clear"];
24387
24393
  return xmlAttrValue;
24388
24394
  };
24389
- const decode$i = (attrs) => {
24395
+ const decode$l = (attrs) => {
24390
24396
  const { clear } = attrs;
24391
24397
  return clear;
24392
24398
  };
24393
24399
  const attrConfig$a = Object.freeze({
24394
24400
  xmlName: "w:clear",
24395
24401
  sdName: "clear",
24396
- encode: encode$i,
24397
- decode: decode$i
24402
+ encode: encode$l,
24403
+ decode: decode$l
24398
24404
  });
24399
- const validXmlAttributes$6 = [attrConfig$b, attrConfig$a];
24400
- const XML_NODE_NAME$7 = "w:br";
24401
- const SD_NODE_NAME$6 = "lineBreak";
24402
- const encode$h = (_2, encodedAttrs) => {
24405
+ const validXmlAttributes$9 = [attrConfig$b, attrConfig$a];
24406
+ const XML_NODE_NAME$a = "w:br";
24407
+ const SD_NODE_NAME$9 = "lineBreak";
24408
+ const encode$k = (_2, encodedAttrs) => {
24403
24409
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24404
24410
  const translated = {
24405
24411
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24409,7 +24415,7 @@ const encode$h = (_2, encodedAttrs) => {
24409
24415
  }
24410
24416
  return translated;
24411
24417
  };
24412
- const decode$h = (params2, decodedAttrs) => {
24418
+ const decode$k = (params2, decodedAttrs) => {
24413
24419
  const { node } = params2;
24414
24420
  if (!node) return;
24415
24421
  const wBreak = { name: "w:br" };
@@ -24426,63 +24432,63 @@ const decode$h = (params2, decodedAttrs) => {
24426
24432
  };
24427
24433
  return translated;
24428
24434
  };
24429
- const config$7 = {
24430
- xmlName: XML_NODE_NAME$7,
24431
- sdNodeOrKeyName: SD_NODE_NAME$6,
24435
+ const config$a = {
24436
+ xmlName: XML_NODE_NAME$a,
24437
+ sdNodeOrKeyName: SD_NODE_NAME$9,
24432
24438
  type: NodeTranslator.translatorTypes.NODE,
24433
- encode: encode$h,
24434
- decode: decode$h,
24435
- attributes: validXmlAttributes$6
24439
+ encode: encode$k,
24440
+ decode: decode$k,
24441
+ attributes: validXmlAttributes$9
24436
24442
  };
24437
- const translator$j = NodeTranslator.from(config$7);
24438
- const encode$g = (attributes) => {
24443
+ const translator$m = NodeTranslator.from(config$a);
24444
+ const encode$j = (attributes) => {
24439
24445
  return attributes["w:val"];
24440
24446
  };
24441
- const decode$g = (attrs) => {
24447
+ const decode$j = (attrs) => {
24442
24448
  const { tabSize } = attrs || {};
24443
24449
  return tabSize;
24444
24450
  };
24445
24451
  const attrConfig$9 = Object.freeze({
24446
24452
  xmlName: "w:val",
24447
24453
  sdName: "tabSize",
24448
- encode: encode$g,
24449
- decode: decode$g
24454
+ encode: encode$j,
24455
+ decode: decode$j
24450
24456
  });
24451
- const encode$f = (attributes) => {
24457
+ const encode$i = (attributes) => {
24452
24458
  return attributes["w:leader"];
24453
24459
  };
24454
- const decode$f = (attrs) => {
24460
+ const decode$i = (attrs) => {
24455
24461
  const { leader } = attrs || {};
24456
24462
  return leader;
24457
24463
  };
24458
24464
  const attrConfig$8 = Object.freeze({
24459
24465
  xmlName: "w:leader",
24460
24466
  sdName: "leader",
24461
- encode: encode$f,
24462
- decode: decode$f
24467
+ encode: encode$i,
24468
+ decode: decode$i
24463
24469
  });
24464
- const encode$e = (attributes) => {
24470
+ const encode$h = (attributes) => {
24465
24471
  return attributes["w:pos"];
24466
24472
  };
24467
- const decode$e = (attrs) => {
24473
+ const decode$h = (attrs) => {
24468
24474
  const { pos } = attrs || {};
24469
24475
  return pos;
24470
24476
  };
24471
24477
  const attrConfig$7 = Object.freeze({
24472
24478
  xmlName: "w:pos",
24473
24479
  sdName: "pos",
24474
- encode: encode$e,
24475
- decode: decode$e
24480
+ encode: encode$h,
24481
+ decode: decode$h
24476
24482
  });
24477
- const validXmlAttributes$5 = [attrConfig$9, attrConfig$7, attrConfig$8];
24478
- const XML_NODE_NAME$6 = "w:tab";
24479
- const SD_NODE_NAME$5 = "tab";
24480
- const encode$d = (_2, encodedAttrs = {}) => {
24483
+ const validXmlAttributes$8 = [attrConfig$9, attrConfig$7, attrConfig$8];
24484
+ const XML_NODE_NAME$9 = "w:tab";
24485
+ const SD_NODE_NAME$8 = "tab";
24486
+ const encode$g = (_2, encodedAttrs = {}) => {
24481
24487
  const translated = { type: "tab" };
24482
24488
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24483
24489
  return translated;
24484
24490
  };
24485
- const decode$d = (params2, decodedAttrs = {}) => {
24491
+ const decode$g = (params2, decodedAttrs = {}) => {
24486
24492
  const { node } = params2 || {};
24487
24493
  if (!node) return;
24488
24494
  const wTab = { name: "w:tab" };
@@ -24498,15 +24504,15 @@ const decode$d = (params2, decodedAttrs = {}) => {
24498
24504
  }
24499
24505
  return translated;
24500
24506
  };
24501
- const config$6 = {
24502
- xmlName: XML_NODE_NAME$6,
24503
- sdNodeOrKeyName: SD_NODE_NAME$5,
24507
+ const config$9 = {
24508
+ xmlName: XML_NODE_NAME$9,
24509
+ sdNodeOrKeyName: SD_NODE_NAME$8,
24504
24510
  type: NodeTranslator.translatorTypes.NODE,
24505
- encode: encode$d,
24506
- decode: decode$d,
24507
- attributes: validXmlAttributes$5
24511
+ encode: encode$g,
24512
+ decode: decode$g,
24513
+ attributes: validXmlAttributes$8
24508
24514
  };
24509
- const translator$i = NodeTranslator.from(config$6);
24515
+ const translator$l = NodeTranslator.from(config$9);
24510
24516
  const mergeTextNodes = (nodes) => {
24511
24517
  if (!nodes || !Array.isArray(nodes)) {
24512
24518
  return nodes;
@@ -25076,91 +25082,91 @@ const handleParagraphNode$1 = (params2) => {
25076
25082
  }
25077
25083
  return schemaNode;
25078
25084
  };
25079
- const encode$c = (attributes) => {
25085
+ const encode$f = (attributes) => {
25080
25086
  return attributes["w:rsidDel"];
25081
25087
  };
25082
- const decode$c = (attrs) => {
25088
+ const decode$f = (attrs) => {
25083
25089
  return attrs.rsidDel;
25084
25090
  };
25085
25091
  const attrConfig$6 = Object.freeze({
25086
25092
  xmlName: "w:rsidDel",
25087
25093
  sdName: "rsidDel",
25088
- encode: encode$c,
25089
- decode: decode$c
25094
+ encode: encode$f,
25095
+ decode: decode$f
25090
25096
  });
25091
- const encode$b = (attributes) => {
25097
+ const encode$e = (attributes) => {
25092
25098
  return attributes["w:rsidP"];
25093
25099
  };
25094
- const decode$b = (attrs) => {
25100
+ const decode$e = (attrs) => {
25095
25101
  return attrs.rsidP;
25096
25102
  };
25097
25103
  const attrConfig$5 = Object.freeze({
25098
25104
  xmlName: "w:rsidP",
25099
25105
  sdName: "rsidP",
25100
- encode: encode$b,
25101
- decode: decode$b
25106
+ encode: encode$e,
25107
+ decode: decode$e
25102
25108
  });
25103
- const encode$a = (attributes) => {
25109
+ const encode$d = (attributes) => {
25104
25110
  return attributes["w:rsidR"];
25105
25111
  };
25106
- const decode$a = (attrs) => {
25112
+ const decode$d = (attrs) => {
25107
25113
  return attrs.rsidR;
25108
25114
  };
25109
25115
  const attrConfig$4 = Object.freeze({
25110
25116
  xmlName: "w:rsidR",
25111
25117
  sdName: "rsidR",
25112
- encode: encode$a,
25113
- decode: decode$a
25118
+ encode: encode$d,
25119
+ decode: decode$d
25114
25120
  });
25115
- const encode$9 = (attributes) => {
25121
+ const encode$c = (attributes) => {
25116
25122
  return attributes["w:rsidRPr"];
25117
25123
  };
25118
- const decode$9 = (attrs) => {
25124
+ const decode$c = (attrs) => {
25119
25125
  return attrs.rsidRPr;
25120
25126
  };
25121
25127
  const attrConfig$3 = Object.freeze({
25122
25128
  xmlName: "w:rsidRPr",
25123
25129
  sdName: "rsidRPr",
25124
- encode: encode$9,
25125
- decode: decode$9
25130
+ encode: encode$c,
25131
+ decode: decode$c
25126
25132
  });
25127
- const encode$8 = (attributes) => {
25133
+ const encode$b = (attributes) => {
25128
25134
  return attributes["w:rsidRDefault"];
25129
25135
  };
25130
- const decode$8 = (attrs) => {
25136
+ const decode$b = (attrs) => {
25131
25137
  return attrs.rsidRDefault;
25132
25138
  };
25133
25139
  const attrConfig$2 = Object.freeze({
25134
25140
  xmlName: "w:rsidRDefault",
25135
25141
  sdName: "rsidRDefault",
25136
- encode: encode$8,
25137
- decode: decode$8
25142
+ encode: encode$b,
25143
+ decode: decode$b
25138
25144
  });
25139
- const encode$7 = (attributes) => {
25145
+ const encode$a = (attributes) => {
25140
25146
  return attributes["w14:paraId"];
25141
25147
  };
25142
- const decode$7 = (attrs) => {
25148
+ const decode$a = (attrs) => {
25143
25149
  return attrs.paraId;
25144
25150
  };
25145
25151
  const attrConfig$1 = Object.freeze({
25146
25152
  xmlName: "w14:paraId",
25147
25153
  sdName: "paraId",
25148
- encode: encode$7,
25149
- decode: decode$7
25154
+ encode: encode$a,
25155
+ decode: decode$a
25150
25156
  });
25151
- const encode$6 = (attributes) => {
25157
+ const encode$9 = (attributes) => {
25152
25158
  return attributes["w14:textId"];
25153
25159
  };
25154
- const decode$6 = (attrs) => {
25160
+ const decode$9 = (attrs) => {
25155
25161
  return attrs.textId;
25156
25162
  };
25157
25163
  const attrConfig = Object.freeze({
25158
25164
  xmlName: "w14:textId",
25159
25165
  sdName: "textId",
25160
- encode: encode$6,
25161
- decode: decode$6
25166
+ encode: encode$9,
25167
+ decode: decode$9
25162
25168
  });
25163
- const validXmlAttributes$4 = [
25169
+ const validXmlAttributes$7 = [
25164
25170
  attrConfig$1,
25165
25171
  attrConfig,
25166
25172
  attrConfig$4,
@@ -25169,9 +25175,9 @@ const validXmlAttributes$4 = [
25169
25175
  attrConfig$3,
25170
25176
  attrConfig$6
25171
25177
  ];
25172
- const XML_NODE_NAME$5 = "w:p";
25173
- const SD_NODE_NAME$4 = "paragraph";
25174
- const encode$5 = (params2, encodedAttrs = {}) => {
25178
+ const XML_NODE_NAME$8 = "w:p";
25179
+ const SD_NODE_NAME$7 = "paragraph";
25180
+ const encode$8 = (params2, encodedAttrs = {}) => {
25175
25181
  const node = handleParagraphNode$1(params2);
25176
25182
  if (!node) return void 0;
25177
25183
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25179,7 +25185,7 @@ const encode$5 = (params2, encodedAttrs = {}) => {
25179
25185
  }
25180
25186
  return node;
25181
25187
  };
25182
- const decode$5 = (params2, decodedAttrs = {}) => {
25188
+ const decode$8 = (params2, decodedAttrs = {}) => {
25183
25189
  const translated = translateParagraphNode(params2);
25184
25190
  if (!translated) return void 0;
25185
25191
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25187,15 +25193,15 @@ const decode$5 = (params2, decodedAttrs = {}) => {
25187
25193
  }
25188
25194
  return translated;
25189
25195
  };
25190
- const config$5 = {
25191
- xmlName: XML_NODE_NAME$5,
25192
- sdNodeOrKeyName: SD_NODE_NAME$4,
25196
+ const config$8 = {
25197
+ xmlName: XML_NODE_NAME$8,
25198
+ sdNodeOrKeyName: SD_NODE_NAME$7,
25193
25199
  type: NodeTranslator.translatorTypes.NODE,
25194
- encode: encode$5,
25195
- decode: decode$5,
25196
- attributes: validXmlAttributes$4
25200
+ encode: encode$8,
25201
+ decode: decode$8,
25202
+ attributes: validXmlAttributes$7
25197
25203
  };
25198
- const translator$h = NodeTranslator.from(config$5);
25204
+ const translator$k = NodeTranslator.from(config$8);
25199
25205
  const generateV2HandlerEntity = (handlerName, translator2) => ({
25200
25206
  handlerName,
25201
25207
  handler: (params2) => {
@@ -25302,13 +25308,13 @@ const integerToString = (value) => {
25302
25308
  const intValue = parseInteger(value);
25303
25309
  return intValue != void 0 ? String(intValue) : void 0;
25304
25310
  };
25305
- const translator$g = NodeTranslator.from({
25311
+ const translator$j = NodeTranslator.from({
25306
25312
  xmlName: "w:cantSplit",
25307
25313
  sdNodeOrKeyName: "cantSplit",
25308
25314
  encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
25309
25315
  decode: ({ node }) => node.attrs?.cantSplit ? {} : void 0
25310
25316
  });
25311
- const translator$f = NodeTranslator.from({
25317
+ const translator$i = NodeTranslator.from({
25312
25318
  xmlName: "w:cnfStyle",
25313
25319
  sdNodeOrKeyName: "cnfStyle",
25314
25320
  attributes: [
@@ -25341,8 +25347,8 @@ const translator$f = NodeTranslator.from({
25341
25347
  return Object.keys(cnfStyleAttrs).length > 0 ? cnfStyleAttrs : void 0;
25342
25348
  }
25343
25349
  });
25344
- const translator$e = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25345
- const translator$d = NodeTranslator.from(
25350
+ const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25351
+ const translator$g = NodeTranslator.from(
25346
25352
  createSingleAttrPropertyHandler(
25347
25353
  "w:gridAfter",
25348
25354
  null,
@@ -25351,7 +25357,7 @@ const translator$d = NodeTranslator.from(
25351
25357
  (v2) => integerToString(v2)
25352
25358
  )
25353
25359
  );
25354
- const translator$c = NodeTranslator.from(
25360
+ const translator$f = NodeTranslator.from(
25355
25361
  createSingleAttrPropertyHandler(
25356
25362
  "w:gridBefore",
25357
25363
  null,
@@ -25360,21 +25366,21 @@ const translator$c = NodeTranslator.from(
25360
25366
  (v2) => integerToString(v2)
25361
25367
  )
25362
25368
  );
25363
- const translator$b = NodeTranslator.from({
25369
+ const translator$e = NodeTranslator.from({
25364
25370
  xmlName: "w:hidden",
25365
25371
  sdNodeOrKeyName: "hidden",
25366
25372
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25367
25373
  decode: ({ node }) => node.attrs.hidden ? {} : void 0
25368
25374
  });
25369
- const translator$a = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25370
- const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25371
- const translator$8 = NodeTranslator.from({
25375
+ const translator$d = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25376
+ const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25377
+ const translator$b = NodeTranslator.from({
25372
25378
  xmlName: "w:tblHeader",
25373
25379
  sdNodeOrKeyName: "repeatHeader",
25374
25380
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25375
25381
  decode: ({ node }) => node.attrs.repeatHeader ? {} : void 0
25376
25382
  });
25377
- const translator$7 = NodeTranslator.from({
25383
+ const translator$a = NodeTranslator.from({
25378
25384
  xmlName: "w:trHeight",
25379
25385
  sdNodeOrKeyName: "rowHeight",
25380
25386
  encode: ({ nodes }) => {
@@ -25401,11 +25407,11 @@ const translator$7 = NodeTranslator.from({
25401
25407
  return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
25402
25408
  }
25403
25409
  });
25404
- const translator$6 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25405
- const translator$5 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25406
- const XML_NODE_NAME$4 = "w:trPr";
25410
+ const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25411
+ const translator$8 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25412
+ const XML_NODE_NAME$7 = "w:trPr";
25407
25413
  const SD_ATTR_KEY = "tableRowProperties";
25408
- const encode$4 = (params2) => {
25414
+ const encode$7 = (params2) => {
25409
25415
  const { nodes } = params2;
25410
25416
  const node = nodes[0];
25411
25417
  let attributes = {
@@ -25419,12 +25425,12 @@ const encode$4 = (params2) => {
25419
25425
  };
25420
25426
  return {
25421
25427
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25422
- xmlName: XML_NODE_NAME$4,
25428
+ xmlName: XML_NODE_NAME$7,
25423
25429
  sdNodeOrKeyName: SD_ATTR_KEY,
25424
25430
  attributes
25425
25431
  };
25426
25432
  };
25427
- const decode$4 = (params2) => {
25433
+ const decode$7 = (params2) => {
25428
25434
  const { tableRowProperties = {} } = params2.node.attrs || {};
25429
25435
  const elements = decodeProperties(propertyTranslatorsBySdName, tableRowProperties);
25430
25436
  const newNode = {
@@ -25436,6 +25442,9 @@ const decode$4 = (params2) => {
25436
25442
  return newNode;
25437
25443
  };
25438
25444
  const propertyTranslators = [
25445
+ translator$j,
25446
+ translator$i,
25447
+ translator$h,
25439
25448
  translator$g,
25440
25449
  translator$f,
25441
25450
  translator$e,
@@ -25444,10 +25453,7 @@ const propertyTranslators = [
25444
25453
  translator$b,
25445
25454
  translator$a,
25446
25455
  translator$9,
25447
- translator$8,
25448
- translator$7,
25449
- translator$6,
25450
- translator$5
25456
+ translator$8
25451
25457
  ];
25452
25458
  const propertyTranslatorsByXmlName = {};
25453
25459
  propertyTranslators.forEach((translator2) => {
@@ -25457,25 +25463,25 @@ const propertyTranslatorsBySdName = {};
25457
25463
  propertyTranslators.forEach((translator2) => {
25458
25464
  propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25459
25465
  });
25460
- const config$4 = {
25461
- xmlName: XML_NODE_NAME$4,
25466
+ const config$7 = {
25467
+ xmlName: XML_NODE_NAME$7,
25462
25468
  sdNodeOrKeyName: SD_ATTR_KEY,
25463
25469
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25464
- encode: encode$4,
25465
- decode: decode$4
25470
+ encode: encode$7,
25471
+ decode: decode$7
25466
25472
  };
25467
- const translator$4 = NodeTranslator.from(config$4);
25468
- const XML_NODE_NAME$3 = "w:tr";
25469
- const SD_NODE_NAME$3 = "tableRow";
25470
- const validXmlAttributes$3 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25473
+ const translator$7 = NodeTranslator.from(config$7);
25474
+ const XML_NODE_NAME$6 = "w:tr";
25475
+ const SD_NODE_NAME$6 = "tableRow";
25476
+ const validXmlAttributes$6 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25471
25477
  (xmlName) => createAttributeHandler(xmlName)
25472
25478
  );
25473
- const encode$3 = (params2, encodedAttrs) => {
25479
+ const encode$6 = (params2, encodedAttrs) => {
25474
25480
  const { row, table } = params2.extraParams;
25475
25481
  let tableRowProperties = {};
25476
25482
  const tPr = row.elements.find((el) => el.name === "w:trPr");
25477
25483
  if (tPr) {
25478
- ({ attributes: tableRowProperties } = translator$4.encode({
25484
+ ({ attributes: tableRowProperties } = translator$7.encode({
25479
25485
  ...params2,
25480
25486
  nodes: [tPr]
25481
25487
  }));
@@ -25488,7 +25494,7 @@ const encode$3 = (params2, encodedAttrs) => {
25488
25494
  let currentColumnIndex = 0;
25489
25495
  const content = cellNodes?.map((n) => {
25490
25496
  let columnWidth = gridColumnWidths?.[currentColumnIndex] || null;
25491
- const result = translator$2.encode({
25497
+ const result = translator$5.encode({
25492
25498
  ...params2,
25493
25499
  extraParams: {
25494
25500
  ...params2.extraParams,
@@ -25519,7 +25525,7 @@ const _getGridColumnWidths = (tableNode) => {
25519
25525
  }) || [];
25520
25526
  return columnWidths;
25521
25527
  };
25522
- const decode$3 = (params2, decodedAttrs) => {
25528
+ const decode$6 = (params2, decodedAttrs) => {
25523
25529
  const { node } = params2;
25524
25530
  const elements = translateChildNodes(params2);
25525
25531
  if (node.attrs?.tableRowProperties) {
@@ -25531,7 +25537,7 @@ const decode$3 = (params2, decodedAttrs) => {
25531
25537
  }
25532
25538
  }
25533
25539
  tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
25534
- const trPr = translator$4.decode({
25540
+ const trPr = translator$7.decode({
25535
25541
  ...params2,
25536
25542
  node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
25537
25543
  });
@@ -25543,15 +25549,15 @@ const decode$3 = (params2, decodedAttrs) => {
25543
25549
  elements
25544
25550
  };
25545
25551
  };
25546
- const config$3 = {
25547
- xmlName: XML_NODE_NAME$3,
25548
- sdNodeOrKeyName: SD_NODE_NAME$3,
25552
+ const config$6 = {
25553
+ xmlName: XML_NODE_NAME$6,
25554
+ sdNodeOrKeyName: SD_NODE_NAME$6,
25549
25555
  type: NodeTranslator.translatorTypes.NODE,
25550
- encode: encode$3,
25551
- decode: decode$3,
25552
- attributes: validXmlAttributes$3
25556
+ encode: encode$6,
25557
+ decode: decode$6,
25558
+ attributes: validXmlAttributes$6
25553
25559
  };
25554
- const translator$3 = NodeTranslator.from(config$3);
25560
+ const translator$6 = NodeTranslator.from(config$6);
25555
25561
  const handleAllTableNodes = (params2) => {
25556
25562
  const { nodes } = params2;
25557
25563
  if (nodes.length === 0) {
@@ -25615,7 +25621,7 @@ function handleTableNode(node, params2) {
25615
25621
  attrs["borders"] = borderData;
25616
25622
  const content = [];
25617
25623
  rows.forEach((row) => {
25618
- const result = translator$3.encode({
25624
+ const result = translator$6.encode({
25619
25625
  ...params2,
25620
25626
  nodes: [row],
25621
25627
  extraParams: {
@@ -25996,10 +26002,10 @@ function generateCellMargins(cellMargins) {
25996
26002
  if (left2 != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left2) } });
25997
26003
  return elements;
25998
26004
  }
25999
- const XML_NODE_NAME$2 = "w:tc";
26000
- const SD_NODE_NAME$2 = "tableCell";
26001
- const validXmlAttributes$2 = [];
26002
- function encode$2(params2, encodedAttrs) {
26005
+ const XML_NODE_NAME$5 = "w:tc";
26006
+ const SD_NODE_NAME$5 = "tableCell";
26007
+ const validXmlAttributes$5 = [];
26008
+ function encode$5(params2, encodedAttrs) {
26003
26009
  const { node, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params2.extraParams;
26004
26010
  const schemaNode = handleTableCellNode({
26005
26011
  params: params2,
@@ -26016,31 +26022,31 @@ function encode$2(params2, encodedAttrs) {
26016
26022
  }
26017
26023
  return schemaNode;
26018
26024
  }
26019
- function decode$2(params2, decodedAttrs) {
26025
+ function decode$5(params2, decodedAttrs) {
26020
26026
  const translated = translateTableCell(params2);
26021
26027
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
26022
26028
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
26023
26029
  }
26024
26030
  return translated;
26025
26031
  }
26026
- const config$2 = {
26027
- xmlName: XML_NODE_NAME$2,
26028
- sdNodeOrKeyName: SD_NODE_NAME$2,
26032
+ const config$5 = {
26033
+ xmlName: XML_NODE_NAME$5,
26034
+ sdNodeOrKeyName: SD_NODE_NAME$5,
26029
26035
  type: NodeTranslator.translatorTypes.NODE,
26030
- encode: encode$2,
26031
- decode: decode$2,
26032
- attributes: validXmlAttributes$2
26036
+ encode: encode$5,
26037
+ decode: decode$5,
26038
+ attributes: validXmlAttributes$5
26033
26039
  };
26034
- const translator$2 = NodeTranslator.from(config$2);
26035
- const XML_NODE_NAME$1 = "w:hyperlink";
26036
- const SD_NODE_NAME$1 = "link";
26040
+ const translator$5 = NodeTranslator.from(config$5);
26041
+ const XML_NODE_NAME$4 = "w:hyperlink";
26042
+ const SD_NODE_NAME$4 = "link";
26037
26043
  const _createAttributeHandler = (xmlName, sdName) => ({
26038
26044
  xmlName,
26039
26045
  sdName,
26040
26046
  encode: (attributes) => attributes[xmlName],
26041
26047
  decode: (attributes) => attributes[sdName]
26042
26048
  });
26043
- const validXmlAttributes$1 = [
26049
+ const validXmlAttributes$4 = [
26044
26050
  _createAttributeHandler("w:anchor", "anchor"),
26045
26051
  _createAttributeHandler("w:docLocation", "docLocation"),
26046
26052
  {
@@ -26053,7 +26059,7 @@ const validXmlAttributes$1 = [
26053
26059
  _createAttributeHandler("r:id", "rId"),
26054
26060
  _createAttributeHandler("w:tgtFrame", "target")
26055
26061
  ];
26056
- const encode$1 = (params2, encodedAttrs) => {
26062
+ const encode$4 = (params2, encodedAttrs) => {
26057
26063
  const { nodes, docx, nodeListHandler } = params2;
26058
26064
  const node = nodes[0];
26059
26065
  let href = _resolveHref(docx, encodedAttrs);
@@ -26084,7 +26090,7 @@ const _resolveHref = (docx, encodedAttrs) => {
26084
26090
  }
26085
26091
  return href;
26086
26092
  };
26087
- function decode$1(params2) {
26093
+ function decode$4(params2) {
26088
26094
  const { node } = params2;
26089
26095
  const linkMark = node.marks.find((m2) => m2.type === "link");
26090
26096
  const linkAttrs = this.decodeAttributes({ ...params2, node: linkMark });
@@ -26128,15 +26134,15 @@ function _addNewLinkRelationship(params2, link, rId) {
26128
26134
  });
26129
26135
  return rId;
26130
26136
  }
26131
- const config$1 = {
26132
- xmlName: XML_NODE_NAME$1,
26133
- sdNodeOrKeyName: SD_NODE_NAME$1,
26137
+ const config$4 = {
26138
+ xmlName: XML_NODE_NAME$4,
26139
+ sdNodeOrKeyName: SD_NODE_NAME$4,
26134
26140
  type: NodeTranslator.translatorTypes.NODE,
26135
- encode: encode$1,
26136
- decode: decode$1,
26137
- attributes: validXmlAttributes$1
26141
+ encode: encode$4,
26142
+ decode: decode$4,
26143
+ attributes: validXmlAttributes$4
26138
26144
  };
26139
- const translator$1 = NodeTranslator.from(config$1);
26145
+ const translator$4 = NodeTranslator.from(config$4);
26140
26146
  function parseTagValueJSON(json) {
26141
26147
  if (typeof json !== "string") {
26142
26148
  return {};
@@ -26378,6 +26384,623 @@ function sdtNodeTypeStrategy(node) {
26378
26384
  }
26379
26385
  return { type: "unknown", handler: null };
26380
26386
  }
26387
+ function handleImageNode(node, params2, isAnchor) {
26388
+ const { docx, filename } = params2;
26389
+ const { attributes } = node;
26390
+ const padding = {
26391
+ top: emuToPixels(attributes["distT"]),
26392
+ bottom: emuToPixels(attributes["distB"]),
26393
+ left: emuToPixels(attributes["distL"]),
26394
+ right: emuToPixels(attributes["distR"])
26395
+ };
26396
+ const extent = node.elements.find((el) => el.name === "wp:extent");
26397
+ const size2 = {
26398
+ width: emuToPixels(extent.attributes?.cx),
26399
+ height: emuToPixels(extent.attributes?.cy)
26400
+ };
26401
+ const graphic = node.elements.find((el) => el.name === "a:graphic");
26402
+ const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
26403
+ const { uri: uri2 } = graphicData?.attributes || {};
26404
+ const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
26405
+ if (!!uri2 && uri2 === shapeURI) {
26406
+ return handleShapeDrawing(params2, node, graphicData);
26407
+ }
26408
+ const picture = graphicData.elements.find((el) => el.name === "pic:pic");
26409
+ if (!picture || !picture.elements) return null;
26410
+ const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
26411
+ const blip = blipFill.elements.find((el) => el.name === "a:blip");
26412
+ const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
26413
+ const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
26414
+ const positionHValue = emuToPixels(positionH?.elements[0]?.text);
26415
+ const hRelativeFrom = positionHTag?.attributes.relativeFrom;
26416
+ const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
26417
+ const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
26418
+ const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
26419
+ const positionVValue = emuToPixels(positionV?.elements[0]?.text);
26420
+ const vRelativeFrom = positionVTag?.attributes.relativeFrom;
26421
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
26422
+ const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
26423
+ const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
26424
+ const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
26425
+ const docPr = node.elements.find((el) => el.name === "wp:docPr");
26426
+ let anchorData = null;
26427
+ if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
26428
+ anchorData = {
26429
+ hRelativeFrom,
26430
+ vRelativeFrom,
26431
+ alignH,
26432
+ alignV
26433
+ };
26434
+ }
26435
+ const marginOffset = {
26436
+ left: positionHValue,
26437
+ top: positionVValue
26438
+ };
26439
+ const { attributes: blipAttributes = {} } = blip;
26440
+ const rEmbed = blipAttributes["r:embed"];
26441
+ if (!rEmbed) return null;
26442
+ const currentFile = filename || "document.xml";
26443
+ let rels = docx[`word/_rels/${currentFile}.rels`];
26444
+ if (!rels) rels = docx[`word/_rels/document.xml.rels`];
26445
+ const relationships = rels.elements.find((el) => el.name === "Relationships");
26446
+ const { elements } = relationships || [];
26447
+ const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
26448
+ if (!rel) return null;
26449
+ const { attributes: relAttributes } = rel;
26450
+ const targetPath = relAttributes["Target"];
26451
+ let path = `word/${targetPath}`;
26452
+ if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
26453
+ const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
26454
+ return {
26455
+ type: "image",
26456
+ attrs: {
26457
+ src: path,
26458
+ alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
26459
+ extension,
26460
+ id: docPr?.attributes.id || "",
26461
+ title: docPr?.attributes.descr || "Image",
26462
+ inline: true,
26463
+ padding,
26464
+ marginOffset,
26465
+ size: size2,
26466
+ anchorData,
26467
+ isAnchor,
26468
+ ...simplePos && {
26469
+ simplePos: {
26470
+ x: simplePos.attributes.x,
26471
+ y: simplePos.attributes.y
26472
+ }
26473
+ },
26474
+ ...wrapSquare && {
26475
+ wrapText: wrapSquare.attributes.wrapText
26476
+ },
26477
+ wrapTopAndBottom: !!wrapTopAndBottom,
26478
+ originalPadding: {
26479
+ distT: attributes["distT"],
26480
+ distB: attributes["distB"],
26481
+ distL: attributes["distL"],
26482
+ distR: attributes["distR"]
26483
+ },
26484
+ originalAttributes: node.attributes,
26485
+ rId: relAttributes["Id"]
26486
+ }
26487
+ };
26488
+ }
26489
+ const handleShapeDrawing = (params2, node, graphicData) => {
26490
+ const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
26491
+ const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
26492
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
26493
+ node.elements.find((el) => el.name === "wp:docPr");
26494
+ const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
26495
+ const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
26496
+ if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
26497
+ return getRectangleShape(params2, spPr);
26498
+ }
26499
+ if (!textBoxContent) {
26500
+ return null;
26501
+ }
26502
+ const { nodeListHandler } = params2;
26503
+ const translatedElement = nodeListHandler.handler({
26504
+ ...params2,
26505
+ node: textBoxContent.elements[0],
26506
+ nodes: textBoxContent.elements,
26507
+ path: [...params2.path || [], textBoxContent]
26508
+ });
26509
+ return translatedElement[0];
26510
+ };
26511
+ const getRectangleShape = (params2, node) => {
26512
+ const schemaAttrs = {};
26513
+ const [drawingNode] = params2.nodes;
26514
+ if (drawingNode?.name === "w:drawing") {
26515
+ schemaAttrs.drawingContent = drawingNode;
26516
+ }
26517
+ const xfrm = node.elements.find((el) => el.name === "a:xfrm");
26518
+ const start2 = xfrm.elements.find((el) => el.name === "a:off");
26519
+ const size2 = xfrm.elements.find((el) => el.name === "a:ext");
26520
+ const solidFill = node.elements.find((el) => el.name === "a:solidFill");
26521
+ node.elements.find((el) => el.name === "a:ln");
26522
+ const rectangleSize = {
26523
+ top: emuToPixels(start2.attributes["y"]),
26524
+ left: emuToPixels(start2.attributes["x"]),
26525
+ width: emuToPixels(size2.attributes["cx"]),
26526
+ height: emuToPixels(size2.attributes["cy"])
26527
+ };
26528
+ schemaAttrs.size = rectangleSize;
26529
+ const background = solidFill?.elements[0]?.attributes["val"];
26530
+ if (background) {
26531
+ schemaAttrs.background = "#" + background;
26532
+ }
26533
+ return {
26534
+ type: "contentBlock",
26535
+ attrs: schemaAttrs
26536
+ };
26537
+ };
26538
+ function handleAnchorNode(params2) {
26539
+ const { node } = params2.extraParams;
26540
+ if (node.name !== "wp:anchor") {
26541
+ return null;
26542
+ }
26543
+ return handleImageNode(node, params2, true);
26544
+ }
26545
+ const sanitizeDocxMediaName = (value, fallback = "image") => {
26546
+ if (!value) return fallback;
26547
+ const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
26548
+ return sanitized || fallback;
26549
+ };
26550
+ const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
26551
+ if (!src || typeof src !== "string") return fallback;
26552
+ const [prefix2] = src.split(";");
26553
+ const [, maybeType] = prefix2.split("/");
26554
+ const extension = maybeType?.toLowerCase();
26555
+ return extension ? `${fallback}.${extension}` : fallback;
26556
+ };
26557
+ const translateImageNode = (params2) => {
26558
+ const {
26559
+ node: { attrs = {} },
26560
+ tableCell,
26561
+ imageSize
26562
+ } = params2;
26563
+ let imageId = attrs.rId;
26564
+ const src = attrs.src || attrs.imageSrc;
26565
+ const { originalWidth, originalHeight } = getPngDimensions(src);
26566
+ let imageName;
26567
+ if (params2.node.type === "image") {
26568
+ if (src?.startsWith("data:")) {
26569
+ imageName = getFallbackImageNameFromDataUri(src);
26570
+ } else {
26571
+ imageName = src?.split("/").pop();
26572
+ }
26573
+ } else {
26574
+ imageName = attrs.fieldId;
26575
+ }
26576
+ imageName = sanitizeDocxMediaName(imageName);
26577
+ let size2 = attrs.size ? {
26578
+ w: pixelsToEmu(attrs.size.width),
26579
+ h: pixelsToEmu(attrs.size.height)
26580
+ } : imageSize;
26581
+ if (originalWidth && originalHeight) {
26582
+ const boxWidthPx = emuToPixels(size2.w);
26583
+ const boxHeightPx = emuToPixels(size2.h);
26584
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
26585
+ size2 = {
26586
+ w: pixelsToEmu(scaledWidth),
26587
+ h: pixelsToEmu(scaledHeight)
26588
+ };
26589
+ }
26590
+ if (tableCell) {
26591
+ const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
26592
+ const leftMargin = tableCell.attrs.cellMargins?.left || 8;
26593
+ const rightMargin = tableCell.attrs.cellMargins?.right || 8;
26594
+ const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
26595
+ const { width: w2, height: h2 } = resizeKeepAspectRatio(size2.w, size2.h, maxWidthEmu);
26596
+ if (w2 && h2) size2 = { w: w2, h: h2 };
26597
+ }
26598
+ if (params2.node.type === "image" && !imageId) {
26599
+ const path = src?.split("word/")[1];
26600
+ imageId = addNewImageRelationship(params2, path);
26601
+ } else if (params2.node.type === "fieldAnnotation" && !imageId) {
26602
+ const type2 = src?.split(";")[0].split("/")[1];
26603
+ if (!type2) {
26604
+ return prepareTextAnnotation(params2);
26605
+ }
26606
+ const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
26607
+ const fileName = `${imageName}_${sanitizedHash}.${type2}`;
26608
+ const relationshipTarget = `media/${fileName}`;
26609
+ const packagePath = `word/${relationshipTarget}`;
26610
+ imageId = addNewImageRelationship(params2, relationshipTarget);
26611
+ params2.media[packagePath] = src;
26612
+ }
26613
+ const inlineAttrs = attrs.originalPadding || {
26614
+ distT: 0,
26615
+ distB: 0,
26616
+ distL: 0,
26617
+ distR: 0
26618
+ };
26619
+ const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
26620
+ const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
26621
+ return {
26622
+ attributes: inlineAttrs,
26623
+ elements: [
26624
+ {
26625
+ name: "wp:extent",
26626
+ attributes: {
26627
+ cx: size2.w,
26628
+ cy: size2.h
26629
+ }
26630
+ },
26631
+ {
26632
+ name: "wp:effectExtent",
26633
+ attributes: {
26634
+ l: 0,
26635
+ t: 0,
26636
+ r: 0,
26637
+ b: 0
26638
+ }
26639
+ },
26640
+ {
26641
+ name: "wp:docPr",
26642
+ attributes: {
26643
+ id: attrs.id || 0,
26644
+ name: attrs.alt || `Picture ${imageName}`
26645
+ }
26646
+ },
26647
+ {
26648
+ name: "wp:cNvGraphicFramePr",
26649
+ elements: [
26650
+ {
26651
+ name: "a:graphicFrameLocks",
26652
+ attributes: {
26653
+ "xmlns:a": drawingXmlns,
26654
+ noChangeAspect: 1
26655
+ }
26656
+ }
26657
+ ]
26658
+ },
26659
+ {
26660
+ name: "a:graphic",
26661
+ attributes: { "xmlns:a": drawingXmlns },
26662
+ elements: [
26663
+ {
26664
+ name: "a:graphicData",
26665
+ attributes: { uri: pictureXmlns },
26666
+ elements: [
26667
+ {
26668
+ name: "pic:pic",
26669
+ attributes: { "xmlns:pic": pictureXmlns },
26670
+ elements: [
26671
+ {
26672
+ name: "pic:nvPicPr",
26673
+ elements: [
26674
+ {
26675
+ name: "pic:cNvPr",
26676
+ attributes: {
26677
+ id: attrs.id || 0,
26678
+ name: attrs.title || `Picture ${imageName}`
26679
+ }
26680
+ },
26681
+ {
26682
+ name: "pic:cNvPicPr",
26683
+ elements: [
26684
+ {
26685
+ name: "a:picLocks",
26686
+ attributes: {
26687
+ noChangeAspect: 1,
26688
+ noChangeArrowheads: 1
26689
+ }
26690
+ }
26691
+ ]
26692
+ }
26693
+ ]
26694
+ },
26695
+ {
26696
+ name: "pic:blipFill",
26697
+ elements: [
26698
+ {
26699
+ name: "a:blip",
26700
+ attributes: {
26701
+ "r:embed": imageId
26702
+ }
26703
+ },
26704
+ {
26705
+ name: "a:stretch",
26706
+ elements: [{ name: "a:fillRect" }]
26707
+ }
26708
+ ]
26709
+ },
26710
+ {
26711
+ name: "pic:spPr",
26712
+ attributes: {
26713
+ bwMode: "auto"
26714
+ },
26715
+ elements: [
26716
+ {
26717
+ name: "a:xfrm",
26718
+ elements: [
26719
+ {
26720
+ name: "a:ext",
26721
+ attributes: {
26722
+ cx: size2.w,
26723
+ cy: size2.h
26724
+ }
26725
+ },
26726
+ {
26727
+ name: "a:off",
26728
+ attributes: {
26729
+ x: 0,
26730
+ y: 0
26731
+ }
26732
+ }
26733
+ ]
26734
+ },
26735
+ {
26736
+ name: "a:prstGeom",
26737
+ attributes: { prst: "rect" },
26738
+ elements: [{ name: "a:avLst" }]
26739
+ },
26740
+ {
26741
+ name: "a:noFill"
26742
+ }
26743
+ ]
26744
+ }
26745
+ ]
26746
+ }
26747
+ ]
26748
+ }
26749
+ ]
26750
+ }
26751
+ ]
26752
+ };
26753
+ };
26754
+ function getPngDimensions(base64) {
26755
+ if (!base64) return {};
26756
+ const type2 = base64.split(";")[0].split("/")[1];
26757
+ if (!base64 || type2 !== "png") {
26758
+ return {
26759
+ originalWidth: void 0,
26760
+ originalHeight: void 0
26761
+ };
26762
+ }
26763
+ let header = base64.split(",")[1].slice(0, 50);
26764
+ let uint8 = Uint8Array.from(atob(header), (c2) => c2.charCodeAt(0));
26765
+ let dataView = new DataView(uint8.buffer, 0, 28);
26766
+ return {
26767
+ originalWidth: dataView.getInt32(16),
26768
+ originalHeight: dataView.getInt32(20)
26769
+ };
26770
+ }
26771
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
26772
+ let scaledWidth = originalWidth;
26773
+ let scaledHeight = originalHeight;
26774
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
26775
+ scaledWidth = Math.round(scaledWidth * ratio);
26776
+ scaledHeight = Math.round(scaledHeight * ratio);
26777
+ return { scaledWidth, scaledHeight };
26778
+ }
26779
+ function resizeKeepAspectRatio(width, height, maxWidth) {
26780
+ if (width > maxWidth) {
26781
+ let scale = maxWidth / width;
26782
+ let newHeight = Math.round(height * scale);
26783
+ return { width: maxWidth, height: newHeight };
26784
+ }
26785
+ return { width, height };
26786
+ }
26787
+ function addNewImageRelationship(params2, imagePath) {
26788
+ const newId = "rId" + generateDocxRandomId();
26789
+ const newRel = {
26790
+ type: "element",
26791
+ name: "Relationship",
26792
+ attributes: {
26793
+ Id: newId,
26794
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
26795
+ Target: imagePath
26796
+ }
26797
+ };
26798
+ params2.relationships.push(newRel);
26799
+ return newId;
26800
+ }
26801
+ function translateAnchorNode(params2) {
26802
+ const { attrs } = params2.node;
26803
+ const anchorElements = [];
26804
+ const wrapElements = [];
26805
+ if (attrs.simplePos) {
26806
+ anchorElements.push({
26807
+ name: "wp:simplePos",
26808
+ attributes: {
26809
+ x: 0,
26810
+ y: 0
26811
+ }
26812
+ });
26813
+ }
26814
+ if (attrs.anchorData) {
26815
+ const hElements = [];
26816
+ if (attrs.marginOffset.left !== void 0) {
26817
+ hElements.push({
26818
+ name: "wp:posOffset",
26819
+ elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.left).toString() }]
26820
+ });
26821
+ }
26822
+ if (attrs.anchorData.alignH) {
26823
+ hElements.push({
26824
+ name: "wp:align",
26825
+ elements: [{ type: "text", text: attrs.anchorData.alignH }]
26826
+ });
26827
+ }
26828
+ anchorElements.push({
26829
+ name: "wp:positionH",
26830
+ attributes: { relativeFrom: attrs.anchorData.hRelativeFrom },
26831
+ ...hElements.length && { elements: hElements }
26832
+ });
26833
+ const vElements = [];
26834
+ if (attrs.marginOffset.top !== void 0) {
26835
+ vElements.push({
26836
+ name: "wp:posOffset",
26837
+ elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.top).toString() }]
26838
+ });
26839
+ }
26840
+ if (attrs.anchorData.alignV) {
26841
+ vElements.push({
26842
+ name: "wp:align",
26843
+ elements: [{ type: "text", text: attrs.anchorData.alignV }]
26844
+ });
26845
+ }
26846
+ anchorElements.push({
26847
+ name: "wp:positionV",
26848
+ attributes: { relativeFrom: attrs.anchorData.vRelativeFrom },
26849
+ ...vElements.length && { elements: vElements }
26850
+ });
26851
+ }
26852
+ if (attrs.wrapText) {
26853
+ wrapElements.push({
26854
+ name: "wp:wrapSquare",
26855
+ attributes: {
26856
+ wrapText: attrs.wrapText
26857
+ }
26858
+ });
26859
+ }
26860
+ if (attrs.wrapTopAndBottom) {
26861
+ wrapElements.push({
26862
+ name: "wp:wrapTopAndBottom"
26863
+ });
26864
+ }
26865
+ if (!wrapElements.length) {
26866
+ wrapElements.push({
26867
+ name: "wp:wrapNone"
26868
+ });
26869
+ }
26870
+ const nodeElements = translateImageNode(params2);
26871
+ const inlineAttrs = {
26872
+ ...nodeElements.attributes,
26873
+ simplePos: attrs.originalAttributes?.simplePos,
26874
+ relativeHeight: 1,
26875
+ behindDoc: attrs.originalAttributes?.behindDoc,
26876
+ locked: attrs.originalAttributes?.locked,
26877
+ layoutInCell: attrs.originalAttributes?.layoutInCell,
26878
+ allowOverlap: attrs.originalAttributes?.allowOverlap
26879
+ };
26880
+ const effectIndex = nodeElements.elements.findIndex((el) => el.name === "wp:effectExtent");
26881
+ const elementsWithWrap = [
26882
+ ...nodeElements.elements.slice(0, effectIndex + 1),
26883
+ ...wrapElements,
26884
+ ...nodeElements.elements.slice(effectIndex + 1)
26885
+ ];
26886
+ return {
26887
+ name: "wp:anchor",
26888
+ attributes: inlineAttrs,
26889
+ elements: [...anchorElements, ...elementsWithWrap]
26890
+ };
26891
+ }
26892
+ const XML_NODE_NAME$3 = "wp:anchor";
26893
+ const SD_NODE_NAME$3 = ["image"];
26894
+ const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
26895
+ function encode$3(params2, encodedAttrs) {
26896
+ const { node } = params2.extraParams;
26897
+ if (!node || !node.type) {
26898
+ return null;
26899
+ }
26900
+ return handleAnchorNode(params2);
26901
+ }
26902
+ function decode$3(params2, decodedAttrs) {
26903
+ const { node } = params2;
26904
+ if (!node || !node.type) {
26905
+ return null;
26906
+ }
26907
+ return translateAnchorNode(params2);
26908
+ }
26909
+ const config$3 = {
26910
+ xmlName: XML_NODE_NAME$3,
26911
+ sdNodeOrKeyName: SD_NODE_NAME$3,
26912
+ type: NodeTranslator.translatorTypes.NODE,
26913
+ encode: encode$3,
26914
+ decode: decode$3,
26915
+ attributes: validXmlAttributes$3
26916
+ };
26917
+ const translator$3 = NodeTranslator.from(config$3);
26918
+ function handleInlineNode(params2) {
26919
+ const { node } = params2.extraParams;
26920
+ if (node.name !== "wp:inline") {
26921
+ return null;
26922
+ }
26923
+ return handleImageNode(node, params2, false);
26924
+ }
26925
+ function translateInlineNode(params2) {
26926
+ const nodeElements = translateImageNode(params2);
26927
+ return {
26928
+ name: "wp:inline",
26929
+ attributes: nodeElements.attributes,
26930
+ elements: nodeElements.elements
26931
+ };
26932
+ }
26933
+ const XML_NODE_NAME$2 = "wp:inline";
26934
+ const SD_NODE_NAME$2 = ["image"];
26935
+ const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
26936
+ function encode$2(params2, encodedAttrs) {
26937
+ const { node } = params2.extraParams;
26938
+ if (!node || !node.type) {
26939
+ return null;
26940
+ }
26941
+ return handleInlineNode(params2);
26942
+ }
26943
+ function decode$2(params2, decodedAttrs) {
26944
+ const { node } = params2;
26945
+ if (!node || !node.type) {
26946
+ return null;
26947
+ }
26948
+ return translateInlineNode(params2);
26949
+ }
26950
+ const config$2 = {
26951
+ xmlName: XML_NODE_NAME$2,
26952
+ sdNodeOrKeyName: SD_NODE_NAME$2,
26953
+ type: NodeTranslator.translatorTypes.NODE,
26954
+ encode: encode$2,
26955
+ decode: decode$2,
26956
+ attributes: validXmlAttributes$2
26957
+ };
26958
+ const translator$2 = NodeTranslator.from(config$2);
26959
+ const registeredHandlers = Object.freeze({
26960
+ "w:br": translator$m,
26961
+ "w:tab": translator$l,
26962
+ "w:p": translator$k,
26963
+ "wp:anchor": translator$3,
26964
+ "wp:inline": translator$2
26965
+ });
26966
+ const XML_NODE_NAME$1 = "w:drawing";
26967
+ const SD_NODE_NAME$1 = [];
26968
+ const validXmlAttributes$1 = [];
26969
+ function encode$1(params2, encodedAttrs) {
26970
+ const nodes = params2.nodes;
26971
+ const node = nodes[0];
26972
+ const validChildTranslators = ["wp:anchor", "wp:inline"];
26973
+ return node.elements.reduce((acc, child) => {
26974
+ if (acc) return acc;
26975
+ if (!validChildTranslators.includes(child.name)) return acc;
26976
+ const translator2 = registeredHandlers[child.name];
26977
+ return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
26978
+ }, null);
26979
+ }
26980
+ function decode$1(params2, decodedAttrs) {
26981
+ const { node } = params2;
26982
+ if (!node || !node.type) {
26983
+ return null;
26984
+ }
26985
+ const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
26986
+ const resultNode = registeredHandlers[handlerName].decode(params2);
26987
+ return wrapTextInRun(
26988
+ {
26989
+ name: "w:drawing",
26990
+ elements: [resultNode]
26991
+ },
26992
+ []
26993
+ );
26994
+ }
26995
+ const config$1 = {
26996
+ xmlName: XML_NODE_NAME$1,
26997
+ sdNodeOrKeyName: SD_NODE_NAME$1,
26998
+ type: NodeTranslator.translatorTypes.NODE,
26999
+ encode: encode$1,
27000
+ decode: decode$1,
27001
+ attributes: validXmlAttributes$1
27002
+ };
27003
+ const translator$1 = NodeTranslator.from(config$1);
26381
27004
  class CommandService {
26382
27005
  /**
26383
27006
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -27715,7 +28338,10 @@ function prepareTextAnnotation(params2) {
27715
28338
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
27716
28339
  }
27717
28340
  function prepareImageAnnotation(params2, imageSize) {
27718
- return translateImageNode(params2, imageSize);
28341
+ return translator$1.decode({
28342
+ ...params2,
28343
+ imageSize
28344
+ });
27719
28345
  }
27720
28346
  function prepareCheckboxAnnotation(params2) {
27721
28347
  const {
@@ -27952,7 +28578,7 @@ function translateStructuredContent(params2) {
27952
28578
  const XML_NODE_NAME = "w:sdt";
27953
28579
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
27954
28580
  const validXmlAttributes = [];
27955
- function encode$k(params2, encodedAttrs) {
28581
+ function encode$n(params2, encodedAttrs) {
27956
28582
  const nodes = params2.nodes;
27957
28583
  const node = nodes[0];
27958
28584
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -27982,7 +28608,7 @@ const config = {
27982
28608
  xmlName: XML_NODE_NAME,
27983
28609
  sdNodeOrKeyName: SD_NODE_NAME,
27984
28610
  type: NodeTranslator.translatorTypes.NODE,
27985
- encode: encode$k,
28611
+ encode: encode$n,
27986
28612
  decode,
27987
28613
  attributes: validXmlAttributes
27988
28614
  };
@@ -27993,19 +28619,19 @@ function exportSchemaToJson(params2) {
27993
28619
  doc: translateDocumentNode,
27994
28620
  body: translateBodyNode,
27995
28621
  heading: translateHeadingNode,
27996
- paragraph: translator$h,
28622
+ paragraph: translator$k,
27997
28623
  text: translateTextNode,
27998
28624
  bulletList: translateList,
27999
28625
  orderedList: translateList,
28000
- lineBreak: translator$j,
28626
+ lineBreak: translator$m,
28001
28627
  table: translateTable,
28002
- tableRow: translator$3,
28003
- tableCell: translator$2,
28628
+ tableRow: translator$6,
28629
+ tableCell: translator$5,
28004
28630
  bookmarkStart: translateBookmarkStart,
28005
28631
  fieldAnnotation: translator,
28006
- tab: translator$i,
28007
- image: translateImageNode,
28008
- hardBreak: translator$j,
28632
+ tab: translator$l,
28633
+ image: translator$1,
28634
+ hardBreak: translator$m,
28009
28635
  commentRangeStart: () => translateCommentNode(params2, "Start"),
28010
28636
  commentRangeEnd: () => translateCommentNode(params2, "End"),
28011
28637
  commentReference: () => null,
@@ -28337,7 +28963,7 @@ function translateTextNode(params2) {
28337
28963
  const isTrackedNode = node.marks?.some((m2) => trackedMarks.includes(m2.type));
28338
28964
  if (isTrackedNode) return translateTrackedNode(params2);
28339
28965
  const isLinkNode = node.marks?.some((m2) => m2.type === "link");
28340
- if (isLinkNode) return translator$1.decode(params2);
28966
+ if (isLinkNode) return translator$4.decode(params2);
28341
28967
  const { text, marks = [] } = node;
28342
28968
  return getTextNodeForExport(text, marks, params2);
28343
28969
  }
@@ -28470,20 +29096,6 @@ function addNewLinkRelationship(params2, link) {
28470
29096
  });
28471
29097
  return newId;
28472
29098
  }
28473
- function addNewImageRelationship(params2, imagePath) {
28474
- const newId = "rId" + generateDocxRandomId();
28475
- const newRel = {
28476
- type: "element",
28477
- name: "Relationship",
28478
- attributes: {
28479
- Id: newId,
28480
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
28481
- Target: imagePath
28482
- }
28483
- };
28484
- params2.relationships.push(newRel);
28485
- return newId;
28486
- }
28487
29099
  function translateList(params2) {
28488
29100
  const { node, editor } = params2;
28489
29101
  const listItem = node.content[0];
@@ -28842,345 +29454,6 @@ function translateMark(mark) {
28842
29454
  }
28843
29455
  return markElement;
28844
29456
  }
28845
- function getPngDimensions(base64) {
28846
- if (!base64) return {};
28847
- const type2 = base64.split(";")[0].split("/")[1];
28848
- if (!base64 || type2 !== "png") {
28849
- return {
28850
- originalWidth: void 0,
28851
- originalHeight: void 0
28852
- };
28853
- }
28854
- let header = base64.split(",")[1].slice(0, 50);
28855
- let uint8 = Uint8Array.from(atob(header), (c2) => c2.charCodeAt(0));
28856
- let dataView = new DataView(uint8.buffer, 0, 28);
28857
- return {
28858
- originalWidth: dataView.getInt32(16),
28859
- originalHeight: dataView.getInt32(20)
28860
- };
28861
- }
28862
- function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
28863
- let scaledWidth = originalWidth;
28864
- let scaledHeight = originalHeight;
28865
- let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
28866
- scaledWidth = Math.round(scaledWidth * ratio);
28867
- scaledHeight = Math.round(scaledHeight * ratio);
28868
- return { scaledWidth, scaledHeight };
28869
- }
28870
- function translateImageNode(params2, imageSize) {
28871
- const {
28872
- node: { attrs = {} },
28873
- tableCell
28874
- } = params2;
28875
- let imageId = attrs.rId;
28876
- const src = attrs.src || attrs.imageSrc;
28877
- const { originalWidth, originalHeight } = getPngDimensions(src);
28878
- let imageName;
28879
- if (params2.node.type === "image") {
28880
- if (src?.startsWith("data:")) {
28881
- imageName = getFallbackImageNameFromDataUri(src);
28882
- } else {
28883
- imageName = src?.split("/").pop();
28884
- }
28885
- } else {
28886
- imageName = attrs.fieldId;
28887
- }
28888
- imageName = sanitizeDocxMediaName(imageName);
28889
- let size2 = attrs.size ? {
28890
- w: pixelsToEmu(attrs.size.width),
28891
- h: pixelsToEmu(attrs.size.height)
28892
- } : imageSize;
28893
- if (originalWidth && originalHeight) {
28894
- const boxWidthPx = emuToPixels(size2.w);
28895
- const boxHeightPx = emuToPixels(size2.h);
28896
- const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
28897
- size2 = {
28898
- w: pixelsToEmu(scaledWidth),
28899
- h: pixelsToEmu(scaledHeight)
28900
- };
28901
- }
28902
- if (tableCell) {
28903
- const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
28904
- const leftMargin = tableCell.attrs.cellMargins?.left || 8;
28905
- const rightMargin = tableCell.attrs.cellMargins?.right || 8;
28906
- const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
28907
- const { width: w2, height: h2 } = resizeKeepAspectRatio(size2.w, size2.h, maxWidthEmu);
28908
- if (w2 && h2) size2 = { w: w2, h: h2 };
28909
- }
28910
- if (params2.node.type === "image" && !imageId) {
28911
- const path = src?.split("word/")[1];
28912
- imageId = addNewImageRelationship(params2, path);
28913
- } else if (params2.node.type === "fieldAnnotation" && !imageId) {
28914
- const type2 = src?.split(";")[0].split("/")[1];
28915
- if (!type2) {
28916
- return prepareTextAnnotation(params2);
28917
- }
28918
- const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
28919
- const fileName = `${imageName}_${sanitizedHash}.${type2}`;
28920
- const relationshipTarget = `media/${fileName}`;
28921
- const packagePath = `word/${relationshipTarget}`;
28922
- imageId = addNewImageRelationship(params2, relationshipTarget);
28923
- params2.media[packagePath] = src;
28924
- }
28925
- let inlineAttrs = attrs.originalPadding || {
28926
- distT: 0,
28927
- distB: 0,
28928
- distL: 0,
28929
- distR: 0
28930
- };
28931
- const anchorElements = [];
28932
- let wrapProp = [];
28933
- if (attrs.isAnchor) {
28934
- inlineAttrs = {
28935
- ...inlineAttrs,
28936
- simplePos: attrs.originalAttributes?.simplePos,
28937
- relativeHeight: 1,
28938
- behindDoc: attrs.originalAttributes?.behindDoc,
28939
- locked: attrs.originalAttributes?.locked,
28940
- layoutInCell: attrs.originalAttributes?.layoutInCell,
28941
- allowOverlap: attrs.originalAttributes?.allowOverlap
28942
- };
28943
- if (attrs.simplePos) {
28944
- anchorElements.push({
28945
- name: "wp:simplePos",
28946
- attributes: {
28947
- x: 0,
28948
- y: 0
28949
- }
28950
- });
28951
- }
28952
- if (attrs.anchorData) {
28953
- anchorElements.push({
28954
- name: "wp:positionH",
28955
- attributes: {
28956
- relativeFrom: attrs.anchorData.hRelativeFrom
28957
- },
28958
- ...attrs.marginOffset.left !== void 0 && {
28959
- elements: [
28960
- {
28961
- name: "wp:posOffset",
28962
- elements: [
28963
- {
28964
- type: "text",
28965
- text: pixelsToEmu(attrs.marginOffset.left).toString()
28966
- }
28967
- ]
28968
- }
28969
- ]
28970
- },
28971
- ...attrs.anchorData.alignH && {
28972
- elements: [
28973
- {
28974
- name: "wp:align",
28975
- elements: [
28976
- {
28977
- type: "text",
28978
- text: attrs.anchorData.alignH
28979
- }
28980
- ]
28981
- }
28982
- ]
28983
- }
28984
- });
28985
- anchorElements.push({
28986
- name: "wp:positionV",
28987
- attributes: {
28988
- relativeFrom: attrs.anchorData.vRelativeFrom
28989
- },
28990
- ...attrs.marginOffset.top !== void 0 && {
28991
- elements: [
28992
- {
28993
- name: "wp:posOffset",
28994
- elements: [
28995
- {
28996
- type: "text",
28997
- text: pixelsToEmu(attrs.marginOffset.top).toString()
28998
- }
28999
- ]
29000
- }
29001
- ]
29002
- },
29003
- ...attrs.anchorData.alignV && {
29004
- elements: [
29005
- {
29006
- name: "wp:align",
29007
- elements: [
29008
- {
29009
- type: "text",
29010
- text: attrs.anchorData.alignV
29011
- }
29012
- ]
29013
- }
29014
- ]
29015
- }
29016
- });
29017
- }
29018
- if (attrs.wrapText) {
29019
- wrapProp.push({
29020
- name: "wp:wrapSquare",
29021
- attributes: {
29022
- wrapText: attrs.wrapText
29023
- }
29024
- });
29025
- }
29026
- if (attrs.wrapTopAndBottom) {
29027
- wrapProp.push({
29028
- name: "wp:wrapTopAndBottom"
29029
- });
29030
- }
29031
- if (attrs.isAnchor && !wrapProp.length) {
29032
- wrapProp.push({
29033
- name: "wp:wrapNone"
29034
- });
29035
- }
29036
- }
29037
- const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
29038
- const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
29039
- const textNode = wrapTextInRun(
29040
- {
29041
- name: "w:drawing",
29042
- elements: [
29043
- {
29044
- name: attrs.isAnchor ? "wp:anchor" : "wp:inline",
29045
- attributes: inlineAttrs,
29046
- elements: [
29047
- ...anchorElements,
29048
- {
29049
- name: "wp:extent",
29050
- attributes: {
29051
- cx: size2.w,
29052
- cy: size2.h
29053
- }
29054
- },
29055
- {
29056
- name: "wp:effectExtent",
29057
- attributes: {
29058
- l: 0,
29059
- t: 0,
29060
- r: 0,
29061
- b: 0
29062
- }
29063
- },
29064
- ...wrapProp,
29065
- {
29066
- name: "wp:docPr",
29067
- attributes: {
29068
- id: attrs.id || 0,
29069
- name: attrs.alt || `Picture ${imageName}`
29070
- }
29071
- },
29072
- {
29073
- name: "wp:cNvGraphicFramePr",
29074
- elements: [
29075
- {
29076
- name: "a:graphicFrameLocks",
29077
- attributes: {
29078
- "xmlns:a": drawingXmlns,
29079
- noChangeAspect: 1
29080
- }
29081
- }
29082
- ]
29083
- },
29084
- {
29085
- name: "a:graphic",
29086
- attributes: { "xmlns:a": drawingXmlns },
29087
- elements: [
29088
- {
29089
- name: "a:graphicData",
29090
- attributes: { uri: pictureXmlns },
29091
- elements: [
29092
- {
29093
- name: "pic:pic",
29094
- attributes: { "xmlns:pic": pictureXmlns },
29095
- elements: [
29096
- {
29097
- name: "pic:nvPicPr",
29098
- elements: [
29099
- {
29100
- name: "pic:cNvPr",
29101
- attributes: {
29102
- id: attrs.id || 0,
29103
- name: attrs.title || `Picture ${imageName}`
29104
- }
29105
- },
29106
- {
29107
- name: "pic:cNvPicPr",
29108
- elements: [
29109
- {
29110
- name: "a:picLocks",
29111
- attributes: {
29112
- noChangeAspect: 1,
29113
- noChangeArrowheads: 1
29114
- }
29115
- }
29116
- ]
29117
- }
29118
- ]
29119
- },
29120
- {
29121
- name: "pic:blipFill",
29122
- elements: [
29123
- {
29124
- name: "a:blip",
29125
- attributes: {
29126
- "r:embed": imageId
29127
- }
29128
- },
29129
- {
29130
- name: "a:stretch",
29131
- elements: [{ name: "a:fillRect" }]
29132
- }
29133
- ]
29134
- },
29135
- {
29136
- name: "pic:spPr",
29137
- attributes: {
29138
- bwMode: "auto"
29139
- },
29140
- elements: [
29141
- {
29142
- name: "a:xfrm",
29143
- elements: [
29144
- {
29145
- name: "a:ext",
29146
- attributes: {
29147
- cx: size2.w,
29148
- cy: size2.h
29149
- }
29150
- },
29151
- {
29152
- name: "a:off",
29153
- attributes: {
29154
- x: 0,
29155
- y: 0
29156
- }
29157
- }
29158
- ]
29159
- },
29160
- {
29161
- name: "a:prstGeom",
29162
- attributes: { prst: "rect" },
29163
- elements: [{ name: "a:avLst" }]
29164
- },
29165
- {
29166
- name: "a:noFill"
29167
- }
29168
- ]
29169
- }
29170
- ]
29171
- }
29172
- ]
29173
- }
29174
- ]
29175
- }
29176
- ]
29177
- }
29178
- ]
29179
- },
29180
- []
29181
- );
29182
- return textNode;
29183
- }
29184
29457
  function translateShapeContainer(params2) {
29185
29458
  const { node } = params2;
29186
29459
  const elements = translateChildNodes(params2);
@@ -29358,14 +29631,6 @@ generateXml_fn = function(node) {
29358
29631
  if (!selfClosing) tags.push(`</${name}>`);
29359
29632
  return tags;
29360
29633
  };
29361
- function resizeKeepAspectRatio(width, height, maxWidth) {
29362
- if (width > maxWidth) {
29363
- let scale = maxWidth / width;
29364
- let newHeight = Math.round(height * scale);
29365
- return { width: maxWidth, height: newHeight };
29366
- }
29367
- return { width, height };
29368
- }
29369
29634
  const translatePageNumberNode = (params2) => {
29370
29635
  const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
29371
29636
  return getAutoPageJson("PAGE", outputMarks);
@@ -29449,7 +29714,7 @@ const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
29449
29714
  return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
29450
29715
  };
29451
29716
  const handleDrawingNode = (params2) => {
29452
- const { nodes, filename } = params2;
29717
+ const { nodes } = params2;
29453
29718
  const validNodes = ["w:drawing", "w:p"];
29454
29719
  if (nodes.length === 0 || !validNodes.includes(nodes[0].name)) {
29455
29720
  return { nodes: [], consumed: 0 };
@@ -29459,167 +29724,9 @@ const handleDrawingNode = (params2) => {
29459
29724
  if (mainNode.name === "w:drawing") node = mainNode;
29460
29725
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
29461
29726
  if (!node) return { nodes: [], consumed: 0 };
29462
- let result;
29463
- const { elements } = node;
29464
- const currentFileName = filename || null;
29465
- const isAnchor = elements.find((el) => el.name === "wp:anchor");
29466
- if (isAnchor) {
29467
- result = handleImageImport(elements[0], currentFileName, params2);
29468
- if (result && result.attrs) result.attrs.isAnchor = isAnchor;
29469
- }
29470
- const inlineImage = elements.find((el) => el.name === "wp:inline");
29471
- if (inlineImage) result = handleImageImport(inlineImage, currentFileName, params2);
29472
- return { nodes: result ? [result] : [], consumed: 1 };
29473
- };
29474
- function handleImageImport(node, currentFileName, params2) {
29475
- const { docx } = params2;
29476
- const { attributes } = node;
29477
- const padding = {
29478
- top: emuToPixels(attributes["distT"]),
29479
- bottom: emuToPixels(attributes["distB"]),
29480
- left: emuToPixels(attributes["distL"]),
29481
- right: emuToPixels(attributes["distR"])
29482
- };
29483
- const extent = node.elements.find((el) => el.name === "wp:extent");
29484
- const size2 = {
29485
- width: emuToPixels(extent.attributes?.cx),
29486
- height: emuToPixels(extent.attributes?.cy)
29487
- };
29488
- const graphic = node.elements.find((el) => el.name === "a:graphic");
29489
- const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
29490
- const { uri: uri2 } = graphicData?.attributes || {};
29491
- const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
29492
- if (!!uri2 && uri2 === shapeURI) {
29493
- return handleShapeDrawing(params2, node, graphicData);
29494
- }
29495
- const picture = graphicData.elements.find((el) => el.name === "pic:pic");
29496
- if (!picture || !picture.elements) return null;
29497
- const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
29498
- const blip = blipFill.elements.find((el) => el.name === "a:blip");
29499
- const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
29500
- const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
29501
- const positionHValue = emuToPixels(positionH?.elements[0]?.text);
29502
- const hRelativeFrom = positionHTag?.attributes.relativeFrom;
29503
- const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
29504
- const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
29505
- const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
29506
- const positionVValue = emuToPixels(positionV?.elements[0]?.text);
29507
- const vRelativeFrom = positionVTag?.attributes.relativeFrom;
29508
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
29509
- const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
29510
- const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
29511
- const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
29512
- const docPr = node.elements.find((el) => el.name === "wp:docPr");
29513
- let anchorData = null;
29514
- if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
29515
- anchorData = {
29516
- hRelativeFrom,
29517
- vRelativeFrom,
29518
- alignH,
29519
- alignV
29520
- };
29521
- }
29522
- const marginOffset = {
29523
- left: positionHValue,
29524
- top: positionVValue
29525
- };
29526
- const { attributes: blipAttributes = {} } = blip;
29527
- const rEmbed = blipAttributes["r:embed"];
29528
- if (!rEmbed) return null;
29529
- const currentFile = currentFileName || "document.xml";
29530
- let rels = docx[`word/_rels/${currentFile}.rels`];
29531
- if (!rels) rels = docx[`word/_rels/document.xml.rels`];
29532
- const relationships = rels.elements.find((el) => el.name === "Relationships");
29533
- const { elements } = relationships;
29534
- const rel = elements.find((el) => el.attributes["Id"] === rEmbed);
29535
- if (!rel) return null;
29536
- const { attributes: relAttributes } = rel;
29537
- const targetPath = relAttributes["Target"];
29538
- let path = `word/${targetPath}`;
29539
- if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
29540
- const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
29541
- return {
29542
- type: "image",
29543
- attrs: {
29544
- src: path,
29545
- alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
29546
- extension,
29547
- id: docPr?.attributes.id || "",
29548
- title: docPr?.attributes.descr || "Image",
29549
- inline: true,
29550
- padding,
29551
- marginOffset,
29552
- size: size2,
29553
- anchorData,
29554
- ...simplePos && {
29555
- simplePos: {
29556
- x: simplePos.attributes.x,
29557
- y: simplePos.attributes.y
29558
- }
29559
- },
29560
- ...wrapSquare && {
29561
- wrapText: wrapSquare.attributes.wrapText
29562
- },
29563
- wrapTopAndBottom: !!wrapTopAndBottom,
29564
- originalPadding: {
29565
- distT: attributes["distT"],
29566
- distB: attributes["distB"],
29567
- distL: attributes["distL"],
29568
- distR: attributes["distR"]
29569
- },
29570
- originalAttributes: node.attributes,
29571
- rId: relAttributes["Id"]
29572
- }
29573
- };
29574
- }
29575
- const handleShapeDrawing = (params2, node, graphicData) => {
29576
- const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
29577
- const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
29578
- const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
29579
- node.elements.find((el) => el.name === "wp:docPr");
29580
- const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
29581
- const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
29582
- if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
29583
- return getRectangleShape(params2, spPr);
29584
- }
29585
- if (!textBoxContent) {
29586
- return null;
29587
- }
29588
- const { nodeListHandler } = params2;
29589
- const translatedElement = nodeListHandler.handler({
29590
- ...params2,
29591
- node: textBoxContent.elements[0],
29592
- nodes: textBoxContent.elements,
29593
- path: [...params2.path || [], textBoxContent]
29594
- });
29595
- return translatedElement[0];
29596
- };
29597
- const getRectangleShape = (params2, node) => {
29598
- const schemaAttrs = {};
29599
- const [drawingNode] = params2.nodes;
29600
- if (drawingNode?.name === "w:drawing") {
29601
- schemaAttrs.drawingContent = drawingNode;
29602
- }
29603
- const xfrm = node.elements.find((el) => el.name === "a:xfrm");
29604
- const start2 = xfrm.elements.find((el) => el.name === "a:off");
29605
- const size2 = xfrm.elements.find((el) => el.name === "a:ext");
29606
- const solidFill = node.elements.find((el) => el.name === "a:solidFill");
29607
- node.elements.find((el) => el.name === "a:ln");
29608
- const rectangleSize = {
29609
- top: emuToPixels(start2.attributes["y"]),
29610
- left: emuToPixels(start2.attributes["x"]),
29611
- width: emuToPixels(size2.attributes["cx"]),
29612
- height: emuToPixels(size2.attributes["cy"])
29613
- };
29614
- schemaAttrs.size = rectangleSize;
29615
- const background = solidFill?.elements[0]?.attributes["val"];
29616
- if (background) {
29617
- schemaAttrs.background = "#" + background;
29618
- }
29619
- return {
29620
- type: "contentBlock",
29621
- attrs: schemaAttrs
29622
- };
29727
+ const schemaNode = translator$1.encode(params2);
29728
+ const newNodes = schemaNode ? [schemaNode] : [];
29729
+ return { nodes: newNodes, consumed: 1 };
29623
29730
  };
29624
29731
  const drawingNodeHandlerEntity = {
29625
29732
  handlerName: "drawingNodeHandler",
@@ -29719,7 +29826,7 @@ const trackChangeNodeHandlerEntity = {
29719
29826
  handlerName: "trackChangeNodeHandler",
29720
29827
  handler: handleTrackChangeNode
29721
29828
  };
29722
- const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$1);
29829
+ const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$4);
29723
29830
  const handleRunNode = (params2) => {
29724
29831
  const { nodes, nodeListHandler, parentStyleId, docx } = params2;
29725
29832
  if (nodes.length === 0 || nodes[0].name !== "w:r") {
@@ -29831,7 +29938,7 @@ const handleParagraphNode = (params2) => {
29831
29938
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
29832
29939
  return { nodes: [], consumed: 0 };
29833
29940
  }
29834
- const schemaNode = translator$h.encode(params2);
29941
+ const schemaNode = translator$k.encode(params2);
29835
29942
  const newNodes = schemaNode ? [schemaNode] : [];
29836
29943
  return { nodes: newNodes, consumed: 1 };
29837
29944
  };
@@ -29934,7 +30041,7 @@ const handler = (params2) => {
29934
30041
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
29935
30042
  return { nodes: [], consumed: 0 };
29936
30043
  }
29937
- const result = translator$j.encode(params2);
30044
+ const result = translator$m.encode(params2);
29938
30045
  if (!result) return { nodes: [], consumed: 0 };
29939
30046
  return {
29940
30047
  nodes: [result],
@@ -30630,7 +30737,7 @@ const handleTabNode = (params2) => {
30630
30737
  if (!nodes.length || nodes[0].name !== "w:tab") {
30631
30738
  return { nodes: [], consumed: 0 };
30632
30739
  }
30633
- const node = translator$i.encode(params2);
30740
+ const node = translator$l.encode(params2);
30634
30741
  return { nodes: [node], consumed: 1 };
30635
30742
  };
30636
30743
  const tabNodeEntityHandler = {
@@ -59472,69 +59579,353 @@ const ContentBlock = Node$1.create({
59472
59579
  };
59473
59580
  }
59474
59581
  });
59582
+ class StructuredContentViewBase {
59583
+ constructor(props) {
59584
+ __publicField$1(this, "node");
59585
+ __publicField$1(this, "view");
59586
+ __publicField$1(this, "getPos");
59587
+ __publicField$1(this, "decorations");
59588
+ __publicField$1(this, "innerDecorations");
59589
+ __publicField$1(this, "editor");
59590
+ __publicField$1(this, "extension");
59591
+ __publicField$1(this, "htmlAttributes");
59592
+ __publicField$1(this, "root");
59593
+ __publicField$1(this, "isDragging", false);
59594
+ this.node = props.node;
59595
+ this.view = props.editor.view;
59596
+ this.getPos = props.getPos;
59597
+ this.decorations = props.decorations;
59598
+ this.innerDecorations = props.innerDecorations;
59599
+ this.editor = props.editor;
59600
+ this.extension = props.extension;
59601
+ this.htmlAttributes = props.htmlAttributes;
59602
+ this.mount(props);
59603
+ }
59604
+ mount(props) {
59605
+ return;
59606
+ }
59607
+ get dom() {
59608
+ return this.root;
59609
+ }
59610
+ get contentDOM() {
59611
+ return null;
59612
+ }
59613
+ update(node, decorations, innerDecorations) {
59614
+ if (node.type !== this.node.type) {
59615
+ return false;
59616
+ }
59617
+ this.node = node;
59618
+ this.decorations = decorations;
59619
+ this.innerDecorations = innerDecorations;
59620
+ this.updateHTMLAttributes();
59621
+ return true;
59622
+ }
59623
+ stopEvent(event) {
59624
+ if (!this.dom) return false;
59625
+ const target = event.target;
59626
+ const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target);
59627
+ if (!isInElement) return false;
59628
+ const isDragEvent = event.type.startsWith("drag");
59629
+ const isDropEvent = event.type === "drop";
59630
+ const isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) || target.isContentEditable;
59631
+ if (isInput && !isDropEvent && !isDragEvent) return true;
59632
+ const { isEditable } = this.editor;
59633
+ const { isDragging } = this;
59634
+ const isDraggable = !!this.node.type.spec.draggable;
59635
+ const isSelectable = NodeSelection.isSelectable(this.node);
59636
+ const isCopyEvent = event.type === "copy";
59637
+ const isPasteEvent = event.type === "paste";
59638
+ const isCutEvent = event.type === "cut";
59639
+ const isClickEvent = event.type === "mousedown";
59640
+ if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) {
59641
+ event.preventDefault();
59642
+ }
59643
+ if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) {
59644
+ event.preventDefault();
59645
+ return false;
59646
+ }
59647
+ if (isDraggable && isEditable && !isDragging && isClickEvent) {
59648
+ const dragHandle = target.closest("[data-drag-handle]");
59649
+ const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle));
59650
+ if (isValidDragHandle) {
59651
+ this.isDragging = true;
59652
+ document.addEventListener(
59653
+ "dragend",
59654
+ () => {
59655
+ this.isDragging = false;
59656
+ },
59657
+ { once: true }
59658
+ );
59659
+ document.addEventListener(
59660
+ "drop",
59661
+ () => {
59662
+ this.isDragging = false;
59663
+ },
59664
+ { once: true }
59665
+ );
59666
+ document.addEventListener(
59667
+ "mouseup",
59668
+ () => {
59669
+ this.isDragging = false;
59670
+ },
59671
+ { once: true }
59672
+ );
59673
+ }
59674
+ }
59675
+ if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || isClickEvent && isSelectable) {
59676
+ return false;
59677
+ }
59678
+ return true;
59679
+ }
59680
+ ignoreMutation(mutation) {
59681
+ if (!this.dom || !this.contentDOM) return true;
59682
+ if (this.node.isLeaf || this.node.isAtom) return true;
59683
+ if (mutation.type === "selection") return false;
59684
+ if (this.contentDOM === mutation.target && mutation.type === "attributes") return true;
59685
+ if (this.contentDOM.contains(mutation.target)) return false;
59686
+ return true;
59687
+ }
59688
+ destroy() {
59689
+ this.dom.remove();
59690
+ this.contentDOM?.remove();
59691
+ }
59692
+ updateAttributes(attrs) {
59693
+ const pos = this.getPos();
59694
+ if (typeof pos !== "number") {
59695
+ return;
59696
+ }
59697
+ return this.view.dispatch(
59698
+ this.view.state.tr.setNodeMarkup(pos, void 0, {
59699
+ ...this.node.attrs,
59700
+ ...attrs
59701
+ })
59702
+ );
59703
+ }
59704
+ updateHTMLAttributes() {
59705
+ const { extensionService } = this.editor;
59706
+ const { attributes } = extensionService;
59707
+ const extensionAttrs = attributes.filter((i) => i.type === this.node.type.name);
59708
+ this.htmlAttributes = Attribute2.getAttributesToRender(this.node, extensionAttrs);
59709
+ }
59710
+ createDragHandle() {
59711
+ const dragHandle = document.createElement("span");
59712
+ dragHandle.classList.add("sd-structured-content-draggable");
59713
+ dragHandle.draggable = true;
59714
+ dragHandle.contentEditable = "false";
59715
+ dragHandle.dataset.dragHandle = "";
59716
+ const textElement = document.createElement("span");
59717
+ textElement.textContent = "Structured content";
59718
+ dragHandle.append(textElement);
59719
+ return dragHandle;
59720
+ }
59721
+ onDragStart(event) {
59722
+ const { view } = this.editor;
59723
+ const target = event.target;
59724
+ const dragHandle = target.nodeType === 3 ? target.parentElement?.closest("[data-drag-handle]") : target.closest("[data-drag-handle]");
59725
+ if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {
59726
+ return;
59727
+ }
59728
+ let x = 0;
59729
+ let y2 = 0;
59730
+ if (this.dom !== dragHandle) {
59731
+ const domBox = this.dom.getBoundingClientRect();
59732
+ const handleBox = dragHandle.getBoundingClientRect();
59733
+ const offsetX = event.offsetX ?? event.nativeEvent?.offsetX;
59734
+ const offsetY = event.offsetY ?? event.nativeEvent?.offsetY;
59735
+ x = handleBox.x - domBox.x + offsetX;
59736
+ y2 = handleBox.y - domBox.y + offsetY;
59737
+ }
59738
+ event.dataTransfer?.setDragImage(this.dom, x, y2);
59739
+ const pos = this.getPos();
59740
+ if (typeof pos !== "number") {
59741
+ return;
59742
+ }
59743
+ const selection = NodeSelection.create(view.state.doc, pos);
59744
+ const transaction = view.state.tr.setSelection(selection);
59745
+ view.dispatch(transaction);
59746
+ }
59747
+ }
59748
+ class StructuredContentInlineView extends StructuredContentViewBase {
59749
+ constructor(props) {
59750
+ super(props);
59751
+ }
59752
+ mount() {
59753
+ this.buildView();
59754
+ }
59755
+ get contentDOM() {
59756
+ const contentElement = this.dom?.querySelector(`.${structuredContentInnerClass$1}`);
59757
+ return contentElement || null;
59758
+ }
59759
+ createElement() {
59760
+ const element = document.createElement("span");
59761
+ element.classList.add(structuredContentClass$1);
59762
+ element.setAttribute("data-structured-content", "");
59763
+ const contentElement = document.createElement("span");
59764
+ contentElement.classList.add(structuredContentInnerClass$1);
59765
+ element.append(contentElement);
59766
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59767
+ updateDOMAttributes(element, { ...domAttrs });
59768
+ return { element, contentElement };
59769
+ }
59770
+ buildView() {
59771
+ const { element } = this.createElement();
59772
+ const dragHandle = this.createDragHandle();
59773
+ element.prepend(dragHandle);
59774
+ element.addEventListener("dragstart", (e) => this.onDragStart(e));
59775
+ this.root = element;
59776
+ }
59777
+ updateView() {
59778
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59779
+ updateDOMAttributes(this.dom, { ...domAttrs });
59780
+ }
59781
+ update(node, decorations, innerDecorations) {
59782
+ const result = super.update(node, decorations, innerDecorations);
59783
+ if (!result) return false;
59784
+ this.updateView();
59785
+ return true;
59786
+ }
59787
+ }
59788
+ const structuredContentClass$1 = "sd-structured-content";
59789
+ const structuredContentInnerClass$1 = "sd-structured-content__content";
59475
59790
  const StructuredContent = Node$1.create({
59476
59791
  name: "structuredContent",
59477
- group: "inline",
59792
+ group: "inline structuredContent",
59478
59793
  inline: true,
59479
59794
  content: "inline*",
59795
+ isolating: true,
59796
+ atom: false,
59797
+ // false - has editable content.
59798
+ draggable: true,
59480
59799
  addOptions() {
59481
59800
  return {
59482
- structuredContentClass: "sd-structured-content-tag",
59483
59801
  htmlAttributes: {
59802
+ class: structuredContentClass$1,
59484
59803
  "aria-label": "Structured content node"
59485
59804
  }
59486
59805
  };
59487
59806
  },
59488
59807
  addAttributes() {
59489
59808
  return {
59809
+ id: {
59810
+ default: null,
59811
+ parseDOM: (elem) => elem.getAttribute("data-id"),
59812
+ renderDOM: (attrs) => {
59813
+ if (!attrs.id) return {};
59814
+ return { "data-id": attrs.id };
59815
+ }
59816
+ },
59490
59817
  sdtPr: {
59491
59818
  rendered: false
59492
59819
  }
59493
59820
  };
59494
59821
  },
59495
59822
  parseDOM() {
59496
- return [{ tag: `span.${this.options.structuredContentClass}` }];
59823
+ return [{ tag: "span[data-structured-content]" }];
59497
59824
  },
59498
59825
  renderDOM({ htmlAttributes }) {
59499
59826
  return [
59500
59827
  "span",
59501
59828
  Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes, {
59502
- class: this.options.structuredContentClass
59829
+ "data-structured-content": ""
59503
59830
  }),
59504
59831
  0
59505
59832
  ];
59833
+ },
59834
+ addNodeView() {
59835
+ return (props) => {
59836
+ return new StructuredContentInlineView({ ...props });
59837
+ };
59506
59838
  }
59507
59839
  });
59840
+ class StructuredContentBlockView extends StructuredContentViewBase {
59841
+ constructor(props) {
59842
+ super(props);
59843
+ }
59844
+ mount() {
59845
+ this.buildView();
59846
+ }
59847
+ get contentDOM() {
59848
+ const contentElement = this.dom?.querySelector(`.${structuredContentInnerClass}`);
59849
+ return contentElement || null;
59850
+ }
59851
+ createElement() {
59852
+ const element = document.createElement("div");
59853
+ element.classList.add(structuredContentClass);
59854
+ element.setAttribute("data-structured-content-block", "");
59855
+ const contentElement = document.createElement("div");
59856
+ contentElement.classList.add(structuredContentInnerClass);
59857
+ element.append(contentElement);
59858
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59859
+ updateDOMAttributes(element, { ...domAttrs });
59860
+ return { element, contentElement };
59861
+ }
59862
+ buildView() {
59863
+ const { element } = this.createElement();
59864
+ const dragHandle = this.createDragHandle();
59865
+ element.prepend(dragHandle);
59866
+ element.addEventListener("dragstart", (e) => this.onDragStart(e));
59867
+ this.root = element;
59868
+ }
59869
+ updateView() {
59870
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59871
+ updateDOMAttributes(this.dom, { ...domAttrs });
59872
+ }
59873
+ update(node, decorations, innerDecorations) {
59874
+ const result = super.update(node, decorations, innerDecorations);
59875
+ if (!result) return false;
59876
+ this.updateView();
59877
+ return true;
59878
+ }
59879
+ }
59880
+ const structuredContentClass = "sd-structured-content-block";
59881
+ const structuredContentInnerClass = "sd-structured-content-block__content";
59508
59882
  const StructuredContentBlock = Node$1.create({
59509
59883
  name: "structuredContentBlock",
59510
- group: "block",
59884
+ group: "block structuredContent",
59511
59885
  content: "block*",
59886
+ isolating: true,
59887
+ atom: false,
59888
+ // false - has editable content.
59889
+ draggable: true,
59512
59890
  addOptions() {
59513
59891
  return {
59514
- structuredContentClass: "sd-structured-content-block-tag",
59515
59892
  htmlAttributes: {
59893
+ class: structuredContentClass,
59516
59894
  "aria-label": "Structured content block node"
59517
59895
  }
59518
59896
  };
59519
59897
  },
59520
59898
  addAttributes() {
59521
59899
  return {
59900
+ id: {
59901
+ default: null,
59902
+ parseDOM: (elem) => elem.getAttribute("data-id"),
59903
+ renderDOM: (attrs) => {
59904
+ if (!attrs.id) return {};
59905
+ return { "data-id": attrs.id };
59906
+ }
59907
+ },
59522
59908
  sdtPr: {
59523
59909
  rendered: false
59524
59910
  }
59525
59911
  };
59526
59912
  },
59527
59913
  parseDOM() {
59528
- return [{ tag: `div.${this.options.structuredContentClass}` }];
59914
+ return [{ tag: "div[data-structured-content-block]" }];
59529
59915
  },
59530
59916
  renderDOM({ htmlAttributes }) {
59531
59917
  return [
59532
59918
  "div",
59533
59919
  Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes, {
59534
- class: this.options.structuredContentClass
59920
+ "data-structured-content-block": ""
59535
59921
  }),
59536
59922
  0
59537
59923
  ];
59924
+ },
59925
+ addNodeView() {
59926
+ return (props) => {
59927
+ return new StructuredContentBlockView({ ...props });
59928
+ };
59538
59929
  }
59539
59930
  });
59540
59931
  class DocumentSectionView {
@@ -81936,11 +82327,6 @@ const _sfc_main = {
81936
82327
  }
81937
82328
  };
81938
82329
  const SuperInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4d5cff52"]]);
81939
- const registeredHandlers = Object.freeze({
81940
- "w:br": translator$j,
81941
- "w:tab": translator$i,
81942
- "w:p": translator$h
81943
- });
81944
82330
  const Extensions = {
81945
82331
  Node: Node$1,
81946
82332
  Attribute: Attribute2,