@harbour-enterprises/superdoc 0.20.0-next.3 → 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-DbuZR81Q.es.js → PdfViewer-BjZBgs8x.es.js} +1 -1
  2. package/dist/chunks/{PdfViewer-B9b7_8E2.cjs → PdfViewer-Ne_-LxpG.cjs} +1 -1
  3. package/dist/chunks/{index-CEAEymUl.es.js → index-BVjAJUtV.es.js} +2 -2
  4. package/dist/chunks/{index-CLepjsej.cjs → index-OFvCtpf7.cjs} +2 -2
  5. package/dist/chunks/{super-editor.es-TdXXCNpJ.cjs → super-editor.es-CCU9etUT.cjs} +1099 -713
  6. package/dist/chunks/{super-editor.es-C7rC3O3K.es.js → super-editor.es-DgTNVbvS.es.js} +1099 -713
  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-BZ638uQi.js → converter-BPTfSIJf.js} +919 -813
  11. package/dist/super-editor/chunks/{docx-zipper-B-DSvrA8.js → docx-zipper-ikgI-2vM.js} +1 -1
  12. package/dist/super-editor/chunks/{editor-JXnNPHDg.js → editor-C1C_smD4.js} +294 -10
  13. package/dist/super-editor/chunks/{toolbar-CGu2Zc7R.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 +1099 -713
  48. package/dist/superdoc.umd.js.map +1 -1
  49. package/package.json +1 -1
@@ -22535,6 +22535,23 @@ function processContent({ content, type: type2, schema }) {
22535
22535
  }
22536
22536
  return doc2;
22537
22537
  }
22538
+ const defaultBooleans = ["required", "readonly", "disabled", "checked", "multiple", "autofocus"];
22539
+ function updateDOMAttributes(dom, attrs = {}, options = {}) {
22540
+ const customBooleans = options.customBooleans || [];
22541
+ const booleans = [...defaultBooleans, ...customBooleans];
22542
+ Object.entries(attrs).forEach(([key, value]) => {
22543
+ if (booleans.includes(key)) {
22544
+ if (!value) dom.removeAttribute(key);
22545
+ else dom.setAttribute(key, "");
22546
+ return;
22547
+ }
22548
+ if (value != null) {
22549
+ dom.setAttribute(key, value);
22550
+ } else {
22551
+ dom.removeAttribute(key);
22552
+ }
22553
+ });
22554
+ }
22538
22555
  const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
22539
22556
  __proto__: null,
22540
22557
  chainableEditorState,
@@ -22567,7 +22584,8 @@ const helpers = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.definePrope
22567
22584
  isNodeActive,
22568
22585
  isTextSelection,
22569
22586
  posToDOMRect,
22570
- processContent
22587
+ processContent,
22588
+ updateDOMAttributes
22571
22589
  }, Symbol.toStringTag, { value: "Module" }));
22572
22590
  const generateNewListDefinition = ({ numId, listType, level, start: start2, text, fmt, editor }) => {
22573
22591
  if (typeof listType === "string") listType = editor.schema.nodes[listType];
@@ -24180,18 +24198,6 @@ const baseNumbering = {
24180
24198
  }
24181
24199
  ]
24182
24200
  };
24183
- const sanitizeDocxMediaName = (value, fallback = "image") => {
24184
- if (!value) return fallback;
24185
- const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
24186
- return sanitized || fallback;
24187
- };
24188
- const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
24189
- if (!src || typeof src !== "string") return fallback;
24190
- const [prefix2] = src.split(";");
24191
- const [, maybeType] = prefix2.split("/");
24192
- const extension = maybeType?.toLowerCase();
24193
- return extension ? `${fallback}.${extension}` : fallback;
24194
- };
24195
24201
  function preProcessVerticalMergeCells(table, { editorSchema }) {
24196
24202
  if (!table || !Array.isArray(table.content)) {
24197
24203
  return table;
@@ -24352,37 +24358,37 @@ const _NodeTranslator = class _NodeTranslator2 {
24352
24358
  };
24353
24359
  __publicField$2(_NodeTranslator, "translatorTypes", TranslatorTypes);
24354
24360
  let NodeTranslator = _NodeTranslator;
24355
- const encode$j = (attributes) => {
24361
+ const encode$m = (attributes) => {
24356
24362
  return attributes["w:type"];
24357
24363
  };
24358
- const decode$j = (attrs) => {
24364
+ const decode$m = (attrs) => {
24359
24365
  const { lineBreakType } = attrs;
24360
24366
  return lineBreakType;
24361
24367
  };
24362
24368
  const attrConfig$b = Object.freeze({
24363
24369
  xmlName: "w:type",
24364
24370
  sdName: "lineBreakType",
24365
- encode: encode$j,
24366
- decode: decode$j
24371
+ encode: encode$m,
24372
+ decode: decode$m
24367
24373
  });
24368
- const encode$i = (attributes) => {
24374
+ const encode$l = (attributes) => {
24369
24375
  const xmlAttrValue = attributes["w:clear"];
24370
24376
  return xmlAttrValue;
24371
24377
  };
24372
- const decode$i = (attrs) => {
24378
+ const decode$l = (attrs) => {
24373
24379
  const { clear } = attrs;
24374
24380
  return clear;
24375
24381
  };
24376
24382
  const attrConfig$a = Object.freeze({
24377
24383
  xmlName: "w:clear",
24378
24384
  sdName: "clear",
24379
- encode: encode$i,
24380
- decode: decode$i
24385
+ encode: encode$l,
24386
+ decode: decode$l
24381
24387
  });
24382
- const validXmlAttributes$6 = [attrConfig$b, attrConfig$a];
24383
- const XML_NODE_NAME$7 = "w:br";
24384
- const SD_NODE_NAME$6 = "lineBreak";
24385
- const encode$h = (_2, encodedAttrs) => {
24388
+ const validXmlAttributes$9 = [attrConfig$b, attrConfig$a];
24389
+ const XML_NODE_NAME$a = "w:br";
24390
+ const SD_NODE_NAME$9 = "lineBreak";
24391
+ const encode$k = (_2, encodedAttrs) => {
24386
24392
  const isPageBreak = encodedAttrs?.lineBreakType === "page";
24387
24393
  const translated = {
24388
24394
  type: isPageBreak ? "hardBreak" : "lineBreak"
@@ -24392,7 +24398,7 @@ const encode$h = (_2, encodedAttrs) => {
24392
24398
  }
24393
24399
  return translated;
24394
24400
  };
24395
- const decode$h = (params2, decodedAttrs) => {
24401
+ const decode$k = (params2, decodedAttrs) => {
24396
24402
  const { node } = params2;
24397
24403
  if (!node) return;
24398
24404
  const wBreak = { name: "w:br" };
@@ -24409,63 +24415,63 @@ const decode$h = (params2, decodedAttrs) => {
24409
24415
  };
24410
24416
  return translated;
24411
24417
  };
24412
- const config$7 = {
24413
- xmlName: XML_NODE_NAME$7,
24414
- sdNodeOrKeyName: SD_NODE_NAME$6,
24418
+ const config$a = {
24419
+ xmlName: XML_NODE_NAME$a,
24420
+ sdNodeOrKeyName: SD_NODE_NAME$9,
24415
24421
  type: NodeTranslator.translatorTypes.NODE,
24416
- encode: encode$h,
24417
- decode: decode$h,
24418
- attributes: validXmlAttributes$6
24422
+ encode: encode$k,
24423
+ decode: decode$k,
24424
+ attributes: validXmlAttributes$9
24419
24425
  };
24420
- const translator$j = NodeTranslator.from(config$7);
24421
- const encode$g = (attributes) => {
24426
+ const translator$m = NodeTranslator.from(config$a);
24427
+ const encode$j = (attributes) => {
24422
24428
  return attributes["w:val"];
24423
24429
  };
24424
- const decode$g = (attrs) => {
24430
+ const decode$j = (attrs) => {
24425
24431
  const { tabSize } = attrs || {};
24426
24432
  return tabSize;
24427
24433
  };
24428
24434
  const attrConfig$9 = Object.freeze({
24429
24435
  xmlName: "w:val",
24430
24436
  sdName: "tabSize",
24431
- encode: encode$g,
24432
- decode: decode$g
24437
+ encode: encode$j,
24438
+ decode: decode$j
24433
24439
  });
24434
- const encode$f = (attributes) => {
24440
+ const encode$i = (attributes) => {
24435
24441
  return attributes["w:leader"];
24436
24442
  };
24437
- const decode$f = (attrs) => {
24443
+ const decode$i = (attrs) => {
24438
24444
  const { leader } = attrs || {};
24439
24445
  return leader;
24440
24446
  };
24441
24447
  const attrConfig$8 = Object.freeze({
24442
24448
  xmlName: "w:leader",
24443
24449
  sdName: "leader",
24444
- encode: encode$f,
24445
- decode: decode$f
24450
+ encode: encode$i,
24451
+ decode: decode$i
24446
24452
  });
24447
- const encode$e = (attributes) => {
24453
+ const encode$h = (attributes) => {
24448
24454
  return attributes["w:pos"];
24449
24455
  };
24450
- const decode$e = (attrs) => {
24456
+ const decode$h = (attrs) => {
24451
24457
  const { pos } = attrs || {};
24452
24458
  return pos;
24453
24459
  };
24454
24460
  const attrConfig$7 = Object.freeze({
24455
24461
  xmlName: "w:pos",
24456
24462
  sdName: "pos",
24457
- encode: encode$e,
24458
- decode: decode$e
24463
+ encode: encode$h,
24464
+ decode: decode$h
24459
24465
  });
24460
- const validXmlAttributes$5 = [attrConfig$9, attrConfig$7, attrConfig$8];
24461
- const XML_NODE_NAME$6 = "w:tab";
24462
- const SD_NODE_NAME$5 = "tab";
24463
- const encode$d = (_2, encodedAttrs = {}) => {
24466
+ const validXmlAttributes$8 = [attrConfig$9, attrConfig$7, attrConfig$8];
24467
+ const XML_NODE_NAME$9 = "w:tab";
24468
+ const SD_NODE_NAME$8 = "tab";
24469
+ const encode$g = (_2, encodedAttrs = {}) => {
24464
24470
  const translated = { type: "tab" };
24465
24471
  if (encodedAttrs) translated.attrs = { ...encodedAttrs };
24466
24472
  return translated;
24467
24473
  };
24468
- const decode$d = (params2, decodedAttrs = {}) => {
24474
+ const decode$g = (params2, decodedAttrs = {}) => {
24469
24475
  const { node } = params2 || {};
24470
24476
  if (!node) return;
24471
24477
  const wTab = { name: "w:tab" };
@@ -24481,15 +24487,15 @@ const decode$d = (params2, decodedAttrs = {}) => {
24481
24487
  }
24482
24488
  return translated;
24483
24489
  };
24484
- const config$6 = {
24485
- xmlName: XML_NODE_NAME$6,
24486
- sdNodeOrKeyName: SD_NODE_NAME$5,
24490
+ const config$9 = {
24491
+ xmlName: XML_NODE_NAME$9,
24492
+ sdNodeOrKeyName: SD_NODE_NAME$8,
24487
24493
  type: NodeTranslator.translatorTypes.NODE,
24488
- encode: encode$d,
24489
- decode: decode$d,
24490
- attributes: validXmlAttributes$5
24494
+ encode: encode$g,
24495
+ decode: decode$g,
24496
+ attributes: validXmlAttributes$8
24491
24497
  };
24492
- const translator$i = NodeTranslator.from(config$6);
24498
+ const translator$l = NodeTranslator.from(config$9);
24493
24499
  const mergeTextNodes = (nodes) => {
24494
24500
  if (!nodes || !Array.isArray(nodes)) {
24495
24501
  return nodes;
@@ -25059,91 +25065,91 @@ const handleParagraphNode$1 = (params2) => {
25059
25065
  }
25060
25066
  return schemaNode;
25061
25067
  };
25062
- const encode$c = (attributes) => {
25068
+ const encode$f = (attributes) => {
25063
25069
  return attributes["w:rsidDel"];
25064
25070
  };
25065
- const decode$c = (attrs) => {
25071
+ const decode$f = (attrs) => {
25066
25072
  return attrs.rsidDel;
25067
25073
  };
25068
25074
  const attrConfig$6 = Object.freeze({
25069
25075
  xmlName: "w:rsidDel",
25070
25076
  sdName: "rsidDel",
25071
- encode: encode$c,
25072
- decode: decode$c
25077
+ encode: encode$f,
25078
+ decode: decode$f
25073
25079
  });
25074
- const encode$b = (attributes) => {
25080
+ const encode$e = (attributes) => {
25075
25081
  return attributes["w:rsidP"];
25076
25082
  };
25077
- const decode$b = (attrs) => {
25083
+ const decode$e = (attrs) => {
25078
25084
  return attrs.rsidP;
25079
25085
  };
25080
25086
  const attrConfig$5 = Object.freeze({
25081
25087
  xmlName: "w:rsidP",
25082
25088
  sdName: "rsidP",
25083
- encode: encode$b,
25084
- decode: decode$b
25089
+ encode: encode$e,
25090
+ decode: decode$e
25085
25091
  });
25086
- const encode$a = (attributes) => {
25092
+ const encode$d = (attributes) => {
25087
25093
  return attributes["w:rsidR"];
25088
25094
  };
25089
- const decode$a = (attrs) => {
25095
+ const decode$d = (attrs) => {
25090
25096
  return attrs.rsidR;
25091
25097
  };
25092
25098
  const attrConfig$4 = Object.freeze({
25093
25099
  xmlName: "w:rsidR",
25094
25100
  sdName: "rsidR",
25095
- encode: encode$a,
25096
- decode: decode$a
25101
+ encode: encode$d,
25102
+ decode: decode$d
25097
25103
  });
25098
- const encode$9 = (attributes) => {
25104
+ const encode$c = (attributes) => {
25099
25105
  return attributes["w:rsidRPr"];
25100
25106
  };
25101
- const decode$9 = (attrs) => {
25107
+ const decode$c = (attrs) => {
25102
25108
  return attrs.rsidRPr;
25103
25109
  };
25104
25110
  const attrConfig$3 = Object.freeze({
25105
25111
  xmlName: "w:rsidRPr",
25106
25112
  sdName: "rsidRPr",
25107
- encode: encode$9,
25108
- decode: decode$9
25113
+ encode: encode$c,
25114
+ decode: decode$c
25109
25115
  });
25110
- const encode$8 = (attributes) => {
25116
+ const encode$b = (attributes) => {
25111
25117
  return attributes["w:rsidRDefault"];
25112
25118
  };
25113
- const decode$8 = (attrs) => {
25119
+ const decode$b = (attrs) => {
25114
25120
  return attrs.rsidRDefault;
25115
25121
  };
25116
25122
  const attrConfig$2 = Object.freeze({
25117
25123
  xmlName: "w:rsidRDefault",
25118
25124
  sdName: "rsidRDefault",
25119
- encode: encode$8,
25120
- decode: decode$8
25125
+ encode: encode$b,
25126
+ decode: decode$b
25121
25127
  });
25122
- const encode$7 = (attributes) => {
25128
+ const encode$a = (attributes) => {
25123
25129
  return attributes["w14:paraId"];
25124
25130
  };
25125
- const decode$7 = (attrs) => {
25131
+ const decode$a = (attrs) => {
25126
25132
  return attrs.paraId;
25127
25133
  };
25128
25134
  const attrConfig$1 = Object.freeze({
25129
25135
  xmlName: "w14:paraId",
25130
25136
  sdName: "paraId",
25131
- encode: encode$7,
25132
- decode: decode$7
25137
+ encode: encode$a,
25138
+ decode: decode$a
25133
25139
  });
25134
- const encode$6 = (attributes) => {
25140
+ const encode$9 = (attributes) => {
25135
25141
  return attributes["w14:textId"];
25136
25142
  };
25137
- const decode$6 = (attrs) => {
25143
+ const decode$9 = (attrs) => {
25138
25144
  return attrs.textId;
25139
25145
  };
25140
25146
  const attrConfig = Object.freeze({
25141
25147
  xmlName: "w14:textId",
25142
25148
  sdName: "textId",
25143
- encode: encode$6,
25144
- decode: decode$6
25149
+ encode: encode$9,
25150
+ decode: decode$9
25145
25151
  });
25146
- const validXmlAttributes$4 = [
25152
+ const validXmlAttributes$7 = [
25147
25153
  attrConfig$1,
25148
25154
  attrConfig,
25149
25155
  attrConfig$4,
@@ -25152,9 +25158,9 @@ const validXmlAttributes$4 = [
25152
25158
  attrConfig$3,
25153
25159
  attrConfig$6
25154
25160
  ];
25155
- const XML_NODE_NAME$5 = "w:p";
25156
- const SD_NODE_NAME$4 = "paragraph";
25157
- const encode$5 = (params2, encodedAttrs = {}) => {
25161
+ const XML_NODE_NAME$8 = "w:p";
25162
+ const SD_NODE_NAME$7 = "paragraph";
25163
+ const encode$8 = (params2, encodedAttrs = {}) => {
25158
25164
  const node = handleParagraphNode$1(params2);
25159
25165
  if (!node) return void 0;
25160
25166
  if (encodedAttrs && Object.keys(encodedAttrs).length) {
@@ -25162,7 +25168,7 @@ const encode$5 = (params2, encodedAttrs = {}) => {
25162
25168
  }
25163
25169
  return node;
25164
25170
  };
25165
- const decode$5 = (params2, decodedAttrs = {}) => {
25171
+ const decode$8 = (params2, decodedAttrs = {}) => {
25166
25172
  const translated = translateParagraphNode(params2);
25167
25173
  if (!translated) return void 0;
25168
25174
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
@@ -25170,15 +25176,15 @@ const decode$5 = (params2, decodedAttrs = {}) => {
25170
25176
  }
25171
25177
  return translated;
25172
25178
  };
25173
- const config$5 = {
25174
- xmlName: XML_NODE_NAME$5,
25175
- sdNodeOrKeyName: SD_NODE_NAME$4,
25179
+ const config$8 = {
25180
+ xmlName: XML_NODE_NAME$8,
25181
+ sdNodeOrKeyName: SD_NODE_NAME$7,
25176
25182
  type: NodeTranslator.translatorTypes.NODE,
25177
- encode: encode$5,
25178
- decode: decode$5,
25179
- attributes: validXmlAttributes$4
25183
+ encode: encode$8,
25184
+ decode: decode$8,
25185
+ attributes: validXmlAttributes$7
25180
25186
  };
25181
- const translator$h = NodeTranslator.from(config$5);
25187
+ const translator$k = NodeTranslator.from(config$8);
25182
25188
  const generateV2HandlerEntity = (handlerName, translator2) => ({
25183
25189
  handlerName,
25184
25190
  handler: (params2) => {
@@ -25285,13 +25291,13 @@ const integerToString = (value) => {
25285
25291
  const intValue = parseInteger(value);
25286
25292
  return intValue != void 0 ? String(intValue) : void 0;
25287
25293
  };
25288
- const translator$g = NodeTranslator.from({
25294
+ const translator$j = NodeTranslator.from({
25289
25295
  xmlName: "w:cantSplit",
25290
25296
  sdNodeOrKeyName: "cantSplit",
25291
25297
  encode: ({ nodes }) => ["1", "true"].includes(nodes[0].attributes?.["w:val"] ?? "1"),
25292
25298
  decode: ({ node }) => node.attrs?.cantSplit ? {} : void 0
25293
25299
  });
25294
- const translator$f = NodeTranslator.from({
25300
+ const translator$i = NodeTranslator.from({
25295
25301
  xmlName: "w:cnfStyle",
25296
25302
  sdNodeOrKeyName: "cnfStyle",
25297
25303
  attributes: [
@@ -25324,8 +25330,8 @@ const translator$f = NodeTranslator.from({
25324
25330
  return Object.keys(cnfStyleAttrs).length > 0 ? cnfStyleAttrs : void 0;
25325
25331
  }
25326
25332
  });
25327
- const translator$e = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25328
- const translator$d = NodeTranslator.from(
25333
+ const translator$h = NodeTranslator.from(createSingleAttrPropertyHandler("w:divId"));
25334
+ const translator$g = NodeTranslator.from(
25329
25335
  createSingleAttrPropertyHandler(
25330
25336
  "w:gridAfter",
25331
25337
  null,
@@ -25334,7 +25340,7 @@ const translator$d = NodeTranslator.from(
25334
25340
  (v2) => integerToString(v2)
25335
25341
  )
25336
25342
  );
25337
- const translator$c = NodeTranslator.from(
25343
+ const translator$f = NodeTranslator.from(
25338
25344
  createSingleAttrPropertyHandler(
25339
25345
  "w:gridBefore",
25340
25346
  null,
@@ -25343,21 +25349,21 @@ const translator$c = NodeTranslator.from(
25343
25349
  (v2) => integerToString(v2)
25344
25350
  )
25345
25351
  );
25346
- const translator$b = NodeTranslator.from({
25352
+ const translator$e = NodeTranslator.from({
25347
25353
  xmlName: "w:hidden",
25348
25354
  sdNodeOrKeyName: "hidden",
25349
25355
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25350
25356
  decode: ({ node }) => node.attrs.hidden ? {} : void 0
25351
25357
  });
25352
- const translator$a = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25353
- const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25354
- const translator$8 = NodeTranslator.from({
25358
+ const translator$d = NodeTranslator.from(createSingleAttrPropertyHandler("w:jc"));
25359
+ const translator$c = NodeTranslator.from(createMeasurementPropertyHandler("w:tblCellSpacing", "cellSpacing"));
25360
+ const translator$b = NodeTranslator.from({
25355
25361
  xmlName: "w:tblHeader",
25356
25362
  sdNodeOrKeyName: "repeatHeader",
25357
25363
  encode: ({ nodes }) => parseBoolean(nodes[0].attributes?.["w:val"] ?? "1"),
25358
25364
  decode: ({ node }) => node.attrs.repeatHeader ? {} : void 0
25359
25365
  });
25360
- const translator$7 = NodeTranslator.from({
25366
+ const translator$a = NodeTranslator.from({
25361
25367
  xmlName: "w:trHeight",
25362
25368
  sdNodeOrKeyName: "rowHeight",
25363
25369
  encode: ({ nodes }) => {
@@ -25384,11 +25390,11 @@ const translator$7 = NodeTranslator.from({
25384
25390
  return Object.keys(heightAttrs).length > 0 ? heightAttrs : void 0;
25385
25391
  }
25386
25392
  });
25387
- const translator$6 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25388
- const translator$5 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25389
- const XML_NODE_NAME$4 = "w:trPr";
25393
+ const translator$9 = NodeTranslator.from(createMeasurementPropertyHandler("w:wAfter"));
25394
+ const translator$8 = NodeTranslator.from(createMeasurementPropertyHandler("w:wBefore"));
25395
+ const XML_NODE_NAME$7 = "w:trPr";
25390
25396
  const SD_ATTR_KEY = "tableRowProperties";
25391
- const encode$4 = (params2) => {
25397
+ const encode$7 = (params2) => {
25392
25398
  const { nodes } = params2;
25393
25399
  const node = nodes[0];
25394
25400
  let attributes = {
@@ -25402,12 +25408,12 @@ const encode$4 = (params2) => {
25402
25408
  };
25403
25409
  return {
25404
25410
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25405
- xmlName: XML_NODE_NAME$4,
25411
+ xmlName: XML_NODE_NAME$7,
25406
25412
  sdNodeOrKeyName: SD_ATTR_KEY,
25407
25413
  attributes
25408
25414
  };
25409
25415
  };
25410
- const decode$4 = (params2) => {
25416
+ const decode$7 = (params2) => {
25411
25417
  const { tableRowProperties = {} } = params2.node.attrs || {};
25412
25418
  const elements = decodeProperties(propertyTranslatorsBySdName, tableRowProperties);
25413
25419
  const newNode = {
@@ -25419,6 +25425,9 @@ const decode$4 = (params2) => {
25419
25425
  return newNode;
25420
25426
  };
25421
25427
  const propertyTranslators = [
25428
+ translator$j,
25429
+ translator$i,
25430
+ translator$h,
25422
25431
  translator$g,
25423
25432
  translator$f,
25424
25433
  translator$e,
@@ -25427,10 +25436,7 @@ const propertyTranslators = [
25427
25436
  translator$b,
25428
25437
  translator$a,
25429
25438
  translator$9,
25430
- translator$8,
25431
- translator$7,
25432
- translator$6,
25433
- translator$5
25439
+ translator$8
25434
25440
  ];
25435
25441
  const propertyTranslatorsByXmlName = {};
25436
25442
  propertyTranslators.forEach((translator2) => {
@@ -25440,25 +25446,25 @@ const propertyTranslatorsBySdName = {};
25440
25446
  propertyTranslators.forEach((translator2) => {
25441
25447
  propertyTranslatorsBySdName[translator2.sdNodeOrKeyName] = translator2;
25442
25448
  });
25443
- const config$4 = {
25444
- xmlName: XML_NODE_NAME$4,
25449
+ const config$7 = {
25450
+ xmlName: XML_NODE_NAME$7,
25445
25451
  sdNodeOrKeyName: SD_ATTR_KEY,
25446
25452
  type: NodeTranslator.translatorTypes.ATTRIBUTE,
25447
- encode: encode$4,
25448
- decode: decode$4
25453
+ encode: encode$7,
25454
+ decode: decode$7
25449
25455
  };
25450
- const translator$4 = NodeTranslator.from(config$4);
25451
- const XML_NODE_NAME$3 = "w:tr";
25452
- const SD_NODE_NAME$3 = "tableRow";
25453
- const validXmlAttributes$3 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25456
+ const translator$7 = NodeTranslator.from(config$7);
25457
+ const XML_NODE_NAME$6 = "w:tr";
25458
+ const SD_NODE_NAME$6 = "tableRow";
25459
+ const validXmlAttributes$6 = ["w:rsidDel", "w:rsidR", "w:rsidRPr", "w:rsidTr", "w14:paraId", "w14:textId"].map(
25454
25460
  (xmlName) => createAttributeHandler(xmlName)
25455
25461
  );
25456
- const encode$3 = (params2, encodedAttrs) => {
25462
+ const encode$6 = (params2, encodedAttrs) => {
25457
25463
  const { row, table } = params2.extraParams;
25458
25464
  let tableRowProperties = {};
25459
25465
  const tPr = row.elements.find((el) => el.name === "w:trPr");
25460
25466
  if (tPr) {
25461
- ({ attributes: tableRowProperties } = translator$4.encode({
25467
+ ({ attributes: tableRowProperties } = translator$7.encode({
25462
25468
  ...params2,
25463
25469
  nodes: [tPr]
25464
25470
  }));
@@ -25471,7 +25477,7 @@ const encode$3 = (params2, encodedAttrs) => {
25471
25477
  let currentColumnIndex = 0;
25472
25478
  const content = cellNodes?.map((n) => {
25473
25479
  let columnWidth = gridColumnWidths?.[currentColumnIndex] || null;
25474
- const result = translator$2.encode({
25480
+ const result = translator$5.encode({
25475
25481
  ...params2,
25476
25482
  extraParams: {
25477
25483
  ...params2.extraParams,
@@ -25502,7 +25508,7 @@ const _getGridColumnWidths = (tableNode) => {
25502
25508
  }) || [];
25503
25509
  return columnWidths;
25504
25510
  };
25505
- const decode$3 = (params2, decodedAttrs) => {
25511
+ const decode$6 = (params2, decodedAttrs) => {
25506
25512
  const { node } = params2;
25507
25513
  const elements = translateChildNodes(params2);
25508
25514
  if (node.attrs?.tableRowProperties) {
@@ -25514,7 +25520,7 @@ const decode$3 = (params2, decodedAttrs) => {
25514
25520
  }
25515
25521
  }
25516
25522
  tableRowProperties["cantSplit"] = node.attrs["cantSplit"];
25517
- const trPr = translator$4.decode({
25523
+ const trPr = translator$7.decode({
25518
25524
  ...params2,
25519
25525
  node: { ...node, attrs: { ...node.attrs, tableRowProperties } }
25520
25526
  });
@@ -25526,15 +25532,15 @@ const decode$3 = (params2, decodedAttrs) => {
25526
25532
  elements
25527
25533
  };
25528
25534
  };
25529
- const config$3 = {
25530
- xmlName: XML_NODE_NAME$3,
25531
- sdNodeOrKeyName: SD_NODE_NAME$3,
25535
+ const config$6 = {
25536
+ xmlName: XML_NODE_NAME$6,
25537
+ sdNodeOrKeyName: SD_NODE_NAME$6,
25532
25538
  type: NodeTranslator.translatorTypes.NODE,
25533
- encode: encode$3,
25534
- decode: decode$3,
25535
- attributes: validXmlAttributes$3
25539
+ encode: encode$6,
25540
+ decode: decode$6,
25541
+ attributes: validXmlAttributes$6
25536
25542
  };
25537
- const translator$3 = NodeTranslator.from(config$3);
25543
+ const translator$6 = NodeTranslator.from(config$6);
25538
25544
  const handleAllTableNodes = (params2) => {
25539
25545
  const { nodes } = params2;
25540
25546
  if (nodes.length === 0) {
@@ -25598,7 +25604,7 @@ function handleTableNode(node, params2) {
25598
25604
  attrs["borders"] = borderData;
25599
25605
  const content = [];
25600
25606
  rows.forEach((row) => {
25601
- const result = translator$3.encode({
25607
+ const result = translator$6.encode({
25602
25608
  ...params2,
25603
25609
  nodes: [row],
25604
25610
  extraParams: {
@@ -25979,10 +25985,10 @@ function generateCellMargins(cellMargins) {
25979
25985
  if (left2 != null) elements.push({ name: "w:left", attributes: { "w:w": pixelsToTwips(left2) } });
25980
25986
  return elements;
25981
25987
  }
25982
- const XML_NODE_NAME$2 = "w:tc";
25983
- const SD_NODE_NAME$2 = "tableCell";
25984
- const validXmlAttributes$2 = [];
25985
- function encode$2(params2, encodedAttrs) {
25988
+ const XML_NODE_NAME$5 = "w:tc";
25989
+ const SD_NODE_NAME$5 = "tableCell";
25990
+ const validXmlAttributes$5 = [];
25991
+ function encode$5(params2, encodedAttrs) {
25986
25992
  const { node, table, row, rowBorders, styleTag, columnIndex, columnWidth } = params2.extraParams;
25987
25993
  const schemaNode = handleTableCellNode({
25988
25994
  params: params2,
@@ -25999,31 +26005,31 @@ function encode$2(params2, encodedAttrs) {
25999
26005
  }
26000
26006
  return schemaNode;
26001
26007
  }
26002
- function decode$2(params2, decodedAttrs) {
26008
+ function decode$5(params2, decodedAttrs) {
26003
26009
  const translated = translateTableCell(params2);
26004
26010
  if (decodedAttrs && Object.keys(decodedAttrs).length) {
26005
26011
  translated.attributes = { ...translated.attributes || {}, ...decodedAttrs };
26006
26012
  }
26007
26013
  return translated;
26008
26014
  }
26009
- const config$2 = {
26010
- xmlName: XML_NODE_NAME$2,
26011
- sdNodeOrKeyName: SD_NODE_NAME$2,
26015
+ const config$5 = {
26016
+ xmlName: XML_NODE_NAME$5,
26017
+ sdNodeOrKeyName: SD_NODE_NAME$5,
26012
26018
  type: NodeTranslator.translatorTypes.NODE,
26013
- encode: encode$2,
26014
- decode: decode$2,
26015
- attributes: validXmlAttributes$2
26019
+ encode: encode$5,
26020
+ decode: decode$5,
26021
+ attributes: validXmlAttributes$5
26016
26022
  };
26017
- const translator$2 = NodeTranslator.from(config$2);
26018
- const XML_NODE_NAME$1 = "w:hyperlink";
26019
- const SD_NODE_NAME$1 = "link";
26023
+ const translator$5 = NodeTranslator.from(config$5);
26024
+ const XML_NODE_NAME$4 = "w:hyperlink";
26025
+ const SD_NODE_NAME$4 = "link";
26020
26026
  const _createAttributeHandler = (xmlName, sdName) => ({
26021
26027
  xmlName,
26022
26028
  sdName,
26023
26029
  encode: (attributes) => attributes[xmlName],
26024
26030
  decode: (attributes) => attributes[sdName]
26025
26031
  });
26026
- const validXmlAttributes$1 = [
26032
+ const validXmlAttributes$4 = [
26027
26033
  _createAttributeHandler("w:anchor", "anchor"),
26028
26034
  _createAttributeHandler("w:docLocation", "docLocation"),
26029
26035
  {
@@ -26036,7 +26042,7 @@ const validXmlAttributes$1 = [
26036
26042
  _createAttributeHandler("r:id", "rId"),
26037
26043
  _createAttributeHandler("w:tgtFrame", "target")
26038
26044
  ];
26039
- const encode$1 = (params2, encodedAttrs) => {
26045
+ const encode$4 = (params2, encodedAttrs) => {
26040
26046
  const { nodes, docx, nodeListHandler } = params2;
26041
26047
  const node = nodes[0];
26042
26048
  let href = _resolveHref(docx, encodedAttrs);
@@ -26067,7 +26073,7 @@ const _resolveHref = (docx, encodedAttrs) => {
26067
26073
  }
26068
26074
  return href;
26069
26075
  };
26070
- function decode$1(params2) {
26076
+ function decode$4(params2) {
26071
26077
  const { node } = params2;
26072
26078
  const linkMark = node.marks.find((m2) => m2.type === "link");
26073
26079
  const linkAttrs = this.decodeAttributes({ ...params2, node: linkMark });
@@ -26111,15 +26117,15 @@ function _addNewLinkRelationship(params2, link, rId) {
26111
26117
  });
26112
26118
  return rId;
26113
26119
  }
26114
- const config$1 = {
26115
- xmlName: XML_NODE_NAME$1,
26116
- sdNodeOrKeyName: SD_NODE_NAME$1,
26120
+ const config$4 = {
26121
+ xmlName: XML_NODE_NAME$4,
26122
+ sdNodeOrKeyName: SD_NODE_NAME$4,
26117
26123
  type: NodeTranslator.translatorTypes.NODE,
26118
- encode: encode$1,
26119
- decode: decode$1,
26120
- attributes: validXmlAttributes$1
26124
+ encode: encode$4,
26125
+ decode: decode$4,
26126
+ attributes: validXmlAttributes$4
26121
26127
  };
26122
- const translator$1 = NodeTranslator.from(config$1);
26128
+ const translator$4 = NodeTranslator.from(config$4);
26123
26129
  function parseTagValueJSON(json) {
26124
26130
  if (typeof json !== "string") {
26125
26131
  return {};
@@ -26361,6 +26367,623 @@ function sdtNodeTypeStrategy(node) {
26361
26367
  }
26362
26368
  return { type: "unknown", handler: null };
26363
26369
  }
26370
+ function handleImageNode(node, params2, isAnchor) {
26371
+ const { docx, filename } = params2;
26372
+ const { attributes } = node;
26373
+ const padding = {
26374
+ top: emuToPixels(attributes["distT"]),
26375
+ bottom: emuToPixels(attributes["distB"]),
26376
+ left: emuToPixels(attributes["distL"]),
26377
+ right: emuToPixels(attributes["distR"])
26378
+ };
26379
+ const extent = node.elements.find((el) => el.name === "wp:extent");
26380
+ const size2 = {
26381
+ width: emuToPixels(extent.attributes?.cx),
26382
+ height: emuToPixels(extent.attributes?.cy)
26383
+ };
26384
+ const graphic = node.elements.find((el) => el.name === "a:graphic");
26385
+ const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
26386
+ const { uri: uri2 } = graphicData?.attributes || {};
26387
+ const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
26388
+ if (!!uri2 && uri2 === shapeURI) {
26389
+ return handleShapeDrawing(params2, node, graphicData);
26390
+ }
26391
+ const picture = graphicData.elements.find((el) => el.name === "pic:pic");
26392
+ if (!picture || !picture.elements) return null;
26393
+ const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
26394
+ const blip = blipFill.elements.find((el) => el.name === "a:blip");
26395
+ const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
26396
+ const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
26397
+ const positionHValue = emuToPixels(positionH?.elements[0]?.text);
26398
+ const hRelativeFrom = positionHTag?.attributes.relativeFrom;
26399
+ const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
26400
+ const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
26401
+ const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
26402
+ const positionVValue = emuToPixels(positionV?.elements[0]?.text);
26403
+ const vRelativeFrom = positionVTag?.attributes.relativeFrom;
26404
+ const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
26405
+ const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
26406
+ const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
26407
+ const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
26408
+ const docPr = node.elements.find((el) => el.name === "wp:docPr");
26409
+ let anchorData = null;
26410
+ if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
26411
+ anchorData = {
26412
+ hRelativeFrom,
26413
+ vRelativeFrom,
26414
+ alignH,
26415
+ alignV
26416
+ };
26417
+ }
26418
+ const marginOffset = {
26419
+ left: positionHValue,
26420
+ top: positionVValue
26421
+ };
26422
+ const { attributes: blipAttributes = {} } = blip;
26423
+ const rEmbed = blipAttributes["r:embed"];
26424
+ if (!rEmbed) return null;
26425
+ const currentFile = filename || "document.xml";
26426
+ let rels = docx[`word/_rels/${currentFile}.rels`];
26427
+ if (!rels) rels = docx[`word/_rels/document.xml.rels`];
26428
+ const relationships = rels.elements.find((el) => el.name === "Relationships");
26429
+ const { elements } = relationships || [];
26430
+ const rel = elements?.find((el) => el.attributes["Id"] === rEmbed);
26431
+ if (!rel) return null;
26432
+ const { attributes: relAttributes } = rel;
26433
+ const targetPath = relAttributes["Target"];
26434
+ let path = `word/${targetPath}`;
26435
+ if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
26436
+ const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
26437
+ return {
26438
+ type: "image",
26439
+ attrs: {
26440
+ src: path,
26441
+ alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
26442
+ extension,
26443
+ id: docPr?.attributes.id || "",
26444
+ title: docPr?.attributes.descr || "Image",
26445
+ inline: true,
26446
+ padding,
26447
+ marginOffset,
26448
+ size: size2,
26449
+ anchorData,
26450
+ isAnchor,
26451
+ ...simplePos && {
26452
+ simplePos: {
26453
+ x: simplePos.attributes.x,
26454
+ y: simplePos.attributes.y
26455
+ }
26456
+ },
26457
+ ...wrapSquare && {
26458
+ wrapText: wrapSquare.attributes.wrapText
26459
+ },
26460
+ wrapTopAndBottom: !!wrapTopAndBottom,
26461
+ originalPadding: {
26462
+ distT: attributes["distT"],
26463
+ distB: attributes["distB"],
26464
+ distL: attributes["distL"],
26465
+ distR: attributes["distR"]
26466
+ },
26467
+ originalAttributes: node.attributes,
26468
+ rId: relAttributes["Id"]
26469
+ }
26470
+ };
26471
+ }
26472
+ const handleShapeDrawing = (params2, node, graphicData) => {
26473
+ const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
26474
+ const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
26475
+ const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
26476
+ node.elements.find((el) => el.name === "wp:docPr");
26477
+ const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
26478
+ const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
26479
+ if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
26480
+ return getRectangleShape(params2, spPr);
26481
+ }
26482
+ if (!textBoxContent) {
26483
+ return null;
26484
+ }
26485
+ const { nodeListHandler } = params2;
26486
+ const translatedElement = nodeListHandler.handler({
26487
+ ...params2,
26488
+ node: textBoxContent.elements[0],
26489
+ nodes: textBoxContent.elements,
26490
+ path: [...params2.path || [], textBoxContent]
26491
+ });
26492
+ return translatedElement[0];
26493
+ };
26494
+ const getRectangleShape = (params2, node) => {
26495
+ const schemaAttrs = {};
26496
+ const [drawingNode] = params2.nodes;
26497
+ if (drawingNode?.name === "w:drawing") {
26498
+ schemaAttrs.drawingContent = drawingNode;
26499
+ }
26500
+ const xfrm = node.elements.find((el) => el.name === "a:xfrm");
26501
+ const start2 = xfrm.elements.find((el) => el.name === "a:off");
26502
+ const size2 = xfrm.elements.find((el) => el.name === "a:ext");
26503
+ const solidFill = node.elements.find((el) => el.name === "a:solidFill");
26504
+ node.elements.find((el) => el.name === "a:ln");
26505
+ const rectangleSize = {
26506
+ top: emuToPixels(start2.attributes["y"]),
26507
+ left: emuToPixels(start2.attributes["x"]),
26508
+ width: emuToPixels(size2.attributes["cx"]),
26509
+ height: emuToPixels(size2.attributes["cy"])
26510
+ };
26511
+ schemaAttrs.size = rectangleSize;
26512
+ const background = solidFill?.elements[0]?.attributes["val"];
26513
+ if (background) {
26514
+ schemaAttrs.background = "#" + background;
26515
+ }
26516
+ return {
26517
+ type: "contentBlock",
26518
+ attrs: schemaAttrs
26519
+ };
26520
+ };
26521
+ function handleAnchorNode(params2) {
26522
+ const { node } = params2.extraParams;
26523
+ if (node.name !== "wp:anchor") {
26524
+ return null;
26525
+ }
26526
+ return handleImageNode(node, params2, true);
26527
+ }
26528
+ const sanitizeDocxMediaName = (value, fallback = "image") => {
26529
+ if (!value) return fallback;
26530
+ const sanitized = value.replace(/[^a-zA-Z0-9_-]/g, "_");
26531
+ return sanitized || fallback;
26532
+ };
26533
+ const getFallbackImageNameFromDataUri = (src = "", fallback = "image") => {
26534
+ if (!src || typeof src !== "string") return fallback;
26535
+ const [prefix2] = src.split(";");
26536
+ const [, maybeType] = prefix2.split("/");
26537
+ const extension = maybeType?.toLowerCase();
26538
+ return extension ? `${fallback}.${extension}` : fallback;
26539
+ };
26540
+ const translateImageNode = (params2) => {
26541
+ const {
26542
+ node: { attrs = {} },
26543
+ tableCell,
26544
+ imageSize
26545
+ } = params2;
26546
+ let imageId = attrs.rId;
26547
+ const src = attrs.src || attrs.imageSrc;
26548
+ const { originalWidth, originalHeight } = getPngDimensions(src);
26549
+ let imageName;
26550
+ if (params2.node.type === "image") {
26551
+ if (src?.startsWith("data:")) {
26552
+ imageName = getFallbackImageNameFromDataUri(src);
26553
+ } else {
26554
+ imageName = src?.split("/").pop();
26555
+ }
26556
+ } else {
26557
+ imageName = attrs.fieldId;
26558
+ }
26559
+ imageName = sanitizeDocxMediaName(imageName);
26560
+ let size2 = attrs.size ? {
26561
+ w: pixelsToEmu(attrs.size.width),
26562
+ h: pixelsToEmu(attrs.size.height)
26563
+ } : imageSize;
26564
+ if (originalWidth && originalHeight) {
26565
+ const boxWidthPx = emuToPixels(size2.w);
26566
+ const boxHeightPx = emuToPixels(size2.h);
26567
+ const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
26568
+ size2 = {
26569
+ w: pixelsToEmu(scaledWidth),
26570
+ h: pixelsToEmu(scaledHeight)
26571
+ };
26572
+ }
26573
+ if (tableCell) {
26574
+ const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
26575
+ const leftMargin = tableCell.attrs.cellMargins?.left || 8;
26576
+ const rightMargin = tableCell.attrs.cellMargins?.right || 8;
26577
+ const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
26578
+ const { width: w2, height: h2 } = resizeKeepAspectRatio(size2.w, size2.h, maxWidthEmu);
26579
+ if (w2 && h2) size2 = { w: w2, h: h2 };
26580
+ }
26581
+ if (params2.node.type === "image" && !imageId) {
26582
+ const path = src?.split("word/")[1];
26583
+ imageId = addNewImageRelationship(params2, path);
26584
+ } else if (params2.node.type === "fieldAnnotation" && !imageId) {
26585
+ const type2 = src?.split(";")[0].split("/")[1];
26586
+ if (!type2) {
26587
+ return prepareTextAnnotation(params2);
26588
+ }
26589
+ const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
26590
+ const fileName = `${imageName}_${sanitizedHash}.${type2}`;
26591
+ const relationshipTarget = `media/${fileName}`;
26592
+ const packagePath = `word/${relationshipTarget}`;
26593
+ imageId = addNewImageRelationship(params2, relationshipTarget);
26594
+ params2.media[packagePath] = src;
26595
+ }
26596
+ const inlineAttrs = attrs.originalPadding || {
26597
+ distT: 0,
26598
+ distB: 0,
26599
+ distL: 0,
26600
+ distR: 0
26601
+ };
26602
+ const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
26603
+ const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
26604
+ return {
26605
+ attributes: inlineAttrs,
26606
+ elements: [
26607
+ {
26608
+ name: "wp:extent",
26609
+ attributes: {
26610
+ cx: size2.w,
26611
+ cy: size2.h
26612
+ }
26613
+ },
26614
+ {
26615
+ name: "wp:effectExtent",
26616
+ attributes: {
26617
+ l: 0,
26618
+ t: 0,
26619
+ r: 0,
26620
+ b: 0
26621
+ }
26622
+ },
26623
+ {
26624
+ name: "wp:docPr",
26625
+ attributes: {
26626
+ id: attrs.id || 0,
26627
+ name: attrs.alt || `Picture ${imageName}`
26628
+ }
26629
+ },
26630
+ {
26631
+ name: "wp:cNvGraphicFramePr",
26632
+ elements: [
26633
+ {
26634
+ name: "a:graphicFrameLocks",
26635
+ attributes: {
26636
+ "xmlns:a": drawingXmlns,
26637
+ noChangeAspect: 1
26638
+ }
26639
+ }
26640
+ ]
26641
+ },
26642
+ {
26643
+ name: "a:graphic",
26644
+ attributes: { "xmlns:a": drawingXmlns },
26645
+ elements: [
26646
+ {
26647
+ name: "a:graphicData",
26648
+ attributes: { uri: pictureXmlns },
26649
+ elements: [
26650
+ {
26651
+ name: "pic:pic",
26652
+ attributes: { "xmlns:pic": pictureXmlns },
26653
+ elements: [
26654
+ {
26655
+ name: "pic:nvPicPr",
26656
+ elements: [
26657
+ {
26658
+ name: "pic:cNvPr",
26659
+ attributes: {
26660
+ id: attrs.id || 0,
26661
+ name: attrs.title || `Picture ${imageName}`
26662
+ }
26663
+ },
26664
+ {
26665
+ name: "pic:cNvPicPr",
26666
+ elements: [
26667
+ {
26668
+ name: "a:picLocks",
26669
+ attributes: {
26670
+ noChangeAspect: 1,
26671
+ noChangeArrowheads: 1
26672
+ }
26673
+ }
26674
+ ]
26675
+ }
26676
+ ]
26677
+ },
26678
+ {
26679
+ name: "pic:blipFill",
26680
+ elements: [
26681
+ {
26682
+ name: "a:blip",
26683
+ attributes: {
26684
+ "r:embed": imageId
26685
+ }
26686
+ },
26687
+ {
26688
+ name: "a:stretch",
26689
+ elements: [{ name: "a:fillRect" }]
26690
+ }
26691
+ ]
26692
+ },
26693
+ {
26694
+ name: "pic:spPr",
26695
+ attributes: {
26696
+ bwMode: "auto"
26697
+ },
26698
+ elements: [
26699
+ {
26700
+ name: "a:xfrm",
26701
+ elements: [
26702
+ {
26703
+ name: "a:ext",
26704
+ attributes: {
26705
+ cx: size2.w,
26706
+ cy: size2.h
26707
+ }
26708
+ },
26709
+ {
26710
+ name: "a:off",
26711
+ attributes: {
26712
+ x: 0,
26713
+ y: 0
26714
+ }
26715
+ }
26716
+ ]
26717
+ },
26718
+ {
26719
+ name: "a:prstGeom",
26720
+ attributes: { prst: "rect" },
26721
+ elements: [{ name: "a:avLst" }]
26722
+ },
26723
+ {
26724
+ name: "a:noFill"
26725
+ }
26726
+ ]
26727
+ }
26728
+ ]
26729
+ }
26730
+ ]
26731
+ }
26732
+ ]
26733
+ }
26734
+ ]
26735
+ };
26736
+ };
26737
+ function getPngDimensions(base64) {
26738
+ if (!base64) return {};
26739
+ const type2 = base64.split(";")[0].split("/")[1];
26740
+ if (!base64 || type2 !== "png") {
26741
+ return {
26742
+ originalWidth: void 0,
26743
+ originalHeight: void 0
26744
+ };
26745
+ }
26746
+ let header = base64.split(",")[1].slice(0, 50);
26747
+ let uint8 = Uint8Array.from(atob(header), (c2) => c2.charCodeAt(0));
26748
+ let dataView = new DataView(uint8.buffer, 0, 28);
26749
+ return {
26750
+ originalWidth: dataView.getInt32(16),
26751
+ originalHeight: dataView.getInt32(20)
26752
+ };
26753
+ }
26754
+ function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
26755
+ let scaledWidth = originalWidth;
26756
+ let scaledHeight = originalHeight;
26757
+ let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
26758
+ scaledWidth = Math.round(scaledWidth * ratio);
26759
+ scaledHeight = Math.round(scaledHeight * ratio);
26760
+ return { scaledWidth, scaledHeight };
26761
+ }
26762
+ function resizeKeepAspectRatio(width, height, maxWidth) {
26763
+ if (width > maxWidth) {
26764
+ let scale = maxWidth / width;
26765
+ let newHeight = Math.round(height * scale);
26766
+ return { width: maxWidth, height: newHeight };
26767
+ }
26768
+ return { width, height };
26769
+ }
26770
+ function addNewImageRelationship(params2, imagePath) {
26771
+ const newId = "rId" + generateDocxRandomId();
26772
+ const newRel = {
26773
+ type: "element",
26774
+ name: "Relationship",
26775
+ attributes: {
26776
+ Id: newId,
26777
+ Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
26778
+ Target: imagePath
26779
+ }
26780
+ };
26781
+ params2.relationships.push(newRel);
26782
+ return newId;
26783
+ }
26784
+ function translateAnchorNode(params2) {
26785
+ const { attrs } = params2.node;
26786
+ const anchorElements = [];
26787
+ const wrapElements = [];
26788
+ if (attrs.simplePos) {
26789
+ anchorElements.push({
26790
+ name: "wp:simplePos",
26791
+ attributes: {
26792
+ x: 0,
26793
+ y: 0
26794
+ }
26795
+ });
26796
+ }
26797
+ if (attrs.anchorData) {
26798
+ const hElements = [];
26799
+ if (attrs.marginOffset.left !== void 0) {
26800
+ hElements.push({
26801
+ name: "wp:posOffset",
26802
+ elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.left).toString() }]
26803
+ });
26804
+ }
26805
+ if (attrs.anchorData.alignH) {
26806
+ hElements.push({
26807
+ name: "wp:align",
26808
+ elements: [{ type: "text", text: attrs.anchorData.alignH }]
26809
+ });
26810
+ }
26811
+ anchorElements.push({
26812
+ name: "wp:positionH",
26813
+ attributes: { relativeFrom: attrs.anchorData.hRelativeFrom },
26814
+ ...hElements.length && { elements: hElements }
26815
+ });
26816
+ const vElements = [];
26817
+ if (attrs.marginOffset.top !== void 0) {
26818
+ vElements.push({
26819
+ name: "wp:posOffset",
26820
+ elements: [{ type: "text", text: pixelsToEmu(attrs.marginOffset.top).toString() }]
26821
+ });
26822
+ }
26823
+ if (attrs.anchorData.alignV) {
26824
+ vElements.push({
26825
+ name: "wp:align",
26826
+ elements: [{ type: "text", text: attrs.anchorData.alignV }]
26827
+ });
26828
+ }
26829
+ anchorElements.push({
26830
+ name: "wp:positionV",
26831
+ attributes: { relativeFrom: attrs.anchorData.vRelativeFrom },
26832
+ ...vElements.length && { elements: vElements }
26833
+ });
26834
+ }
26835
+ if (attrs.wrapText) {
26836
+ wrapElements.push({
26837
+ name: "wp:wrapSquare",
26838
+ attributes: {
26839
+ wrapText: attrs.wrapText
26840
+ }
26841
+ });
26842
+ }
26843
+ if (attrs.wrapTopAndBottom) {
26844
+ wrapElements.push({
26845
+ name: "wp:wrapTopAndBottom"
26846
+ });
26847
+ }
26848
+ if (!wrapElements.length) {
26849
+ wrapElements.push({
26850
+ name: "wp:wrapNone"
26851
+ });
26852
+ }
26853
+ const nodeElements = translateImageNode(params2);
26854
+ const inlineAttrs = {
26855
+ ...nodeElements.attributes,
26856
+ simplePos: attrs.originalAttributes?.simplePos,
26857
+ relativeHeight: 1,
26858
+ behindDoc: attrs.originalAttributes?.behindDoc,
26859
+ locked: attrs.originalAttributes?.locked,
26860
+ layoutInCell: attrs.originalAttributes?.layoutInCell,
26861
+ allowOverlap: attrs.originalAttributes?.allowOverlap
26862
+ };
26863
+ const effectIndex = nodeElements.elements.findIndex((el) => el.name === "wp:effectExtent");
26864
+ const elementsWithWrap = [
26865
+ ...nodeElements.elements.slice(0, effectIndex + 1),
26866
+ ...wrapElements,
26867
+ ...nodeElements.elements.slice(effectIndex + 1)
26868
+ ];
26869
+ return {
26870
+ name: "wp:anchor",
26871
+ attributes: inlineAttrs,
26872
+ elements: [...anchorElements, ...elementsWithWrap]
26873
+ };
26874
+ }
26875
+ const XML_NODE_NAME$3 = "wp:anchor";
26876
+ const SD_NODE_NAME$3 = ["image"];
26877
+ const validXmlAttributes$3 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
26878
+ function encode$3(params2, encodedAttrs) {
26879
+ const { node } = params2.extraParams;
26880
+ if (!node || !node.type) {
26881
+ return null;
26882
+ }
26883
+ return handleAnchorNode(params2);
26884
+ }
26885
+ function decode$3(params2, decodedAttrs) {
26886
+ const { node } = params2;
26887
+ if (!node || !node.type) {
26888
+ return null;
26889
+ }
26890
+ return translateAnchorNode(params2);
26891
+ }
26892
+ const config$3 = {
26893
+ xmlName: XML_NODE_NAME$3,
26894
+ sdNodeOrKeyName: SD_NODE_NAME$3,
26895
+ type: NodeTranslator.translatorTypes.NODE,
26896
+ encode: encode$3,
26897
+ decode: decode$3,
26898
+ attributes: validXmlAttributes$3
26899
+ };
26900
+ const translator$3 = NodeTranslator.from(config$3);
26901
+ function handleInlineNode(params2) {
26902
+ const { node } = params2.extraParams;
26903
+ if (node.name !== "wp:inline") {
26904
+ return null;
26905
+ }
26906
+ return handleImageNode(node, params2, false);
26907
+ }
26908
+ function translateInlineNode(params2) {
26909
+ const nodeElements = translateImageNode(params2);
26910
+ return {
26911
+ name: "wp:inline",
26912
+ attributes: nodeElements.attributes,
26913
+ elements: nodeElements.elements
26914
+ };
26915
+ }
26916
+ const XML_NODE_NAME$2 = "wp:inline";
26917
+ const SD_NODE_NAME$2 = ["image"];
26918
+ const validXmlAttributes$2 = ["distT", "distB", "distL", "distR"].map((xmlName) => createAttributeHandler(xmlName));
26919
+ function encode$2(params2, encodedAttrs) {
26920
+ const { node } = params2.extraParams;
26921
+ if (!node || !node.type) {
26922
+ return null;
26923
+ }
26924
+ return handleInlineNode(params2);
26925
+ }
26926
+ function decode$2(params2, decodedAttrs) {
26927
+ const { node } = params2;
26928
+ if (!node || !node.type) {
26929
+ return null;
26930
+ }
26931
+ return translateInlineNode(params2);
26932
+ }
26933
+ const config$2 = {
26934
+ xmlName: XML_NODE_NAME$2,
26935
+ sdNodeOrKeyName: SD_NODE_NAME$2,
26936
+ type: NodeTranslator.translatorTypes.NODE,
26937
+ encode: encode$2,
26938
+ decode: decode$2,
26939
+ attributes: validXmlAttributes$2
26940
+ };
26941
+ const translator$2 = NodeTranslator.from(config$2);
26942
+ const registeredHandlers = Object.freeze({
26943
+ "w:br": translator$m,
26944
+ "w:tab": translator$l,
26945
+ "w:p": translator$k,
26946
+ "wp:anchor": translator$3,
26947
+ "wp:inline": translator$2
26948
+ });
26949
+ const XML_NODE_NAME$1 = "w:drawing";
26950
+ const SD_NODE_NAME$1 = [];
26951
+ const validXmlAttributes$1 = [];
26952
+ function encode$1(params2, encodedAttrs) {
26953
+ const nodes = params2.nodes;
26954
+ const node = nodes[0];
26955
+ const validChildTranslators = ["wp:anchor", "wp:inline"];
26956
+ return node.elements.reduce((acc, child) => {
26957
+ if (acc) return acc;
26958
+ if (!validChildTranslators.includes(child.name)) return acc;
26959
+ const translator2 = registeredHandlers[child.name];
26960
+ return translator2.encode({ ...params2, extraParams: { node: child } }) || acc;
26961
+ }, null);
26962
+ }
26963
+ function decode$1(params2, decodedAttrs) {
26964
+ const { node } = params2;
26965
+ if (!node || !node.type) {
26966
+ return null;
26967
+ }
26968
+ const handlerName = node.attrs.isAnchor ? "wp:anchor" : "wp:inline";
26969
+ const resultNode = registeredHandlers[handlerName].decode(params2);
26970
+ return wrapTextInRun(
26971
+ {
26972
+ name: "w:drawing",
26973
+ elements: [resultNode]
26974
+ },
26975
+ []
26976
+ );
26977
+ }
26978
+ const config$1 = {
26979
+ xmlName: XML_NODE_NAME$1,
26980
+ sdNodeOrKeyName: SD_NODE_NAME$1,
26981
+ type: NodeTranslator.translatorTypes.NODE,
26982
+ encode: encode$1,
26983
+ decode: decode$1,
26984
+ attributes: validXmlAttributes$1
26985
+ };
26986
+ const translator$1 = NodeTranslator.from(config$1);
26364
26987
  class CommandService {
26365
26988
  /**
26366
26989
  * @param {import('./commands/types/index.js').CommandServiceOptions} props
@@ -27698,7 +28321,10 @@ function prepareTextAnnotation(params2) {
27698
28321
  return getTextNodeForExport(attrs.displayLabel, [...marks, ...marksFromAttrs], params2);
27699
28322
  }
27700
28323
  function prepareImageAnnotation(params2, imageSize) {
27701
- return translateImageNode(params2, imageSize);
28324
+ return translator$1.decode({
28325
+ ...params2,
28326
+ imageSize
28327
+ });
27702
28328
  }
27703
28329
  function prepareCheckboxAnnotation(params2) {
27704
28330
  const {
@@ -27935,7 +28561,7 @@ function translateStructuredContent(params2) {
27935
28561
  const XML_NODE_NAME = "w:sdt";
27936
28562
  const SD_NODE_NAME = ["fieldAnnotation", "structuredContent", "structuredContentBlock", "documentSection"];
27937
28563
  const validXmlAttributes = [];
27938
- function encode$k(params2, encodedAttrs) {
28564
+ function encode$n(params2, encodedAttrs) {
27939
28565
  const nodes = params2.nodes;
27940
28566
  const node = nodes[0];
27941
28567
  const { type: sdtType, handler: handler2 } = sdtNodeTypeStrategy(node);
@@ -27965,7 +28591,7 @@ const config = {
27965
28591
  xmlName: XML_NODE_NAME,
27966
28592
  sdNodeOrKeyName: SD_NODE_NAME,
27967
28593
  type: NodeTranslator.translatorTypes.NODE,
27968
- encode: encode$k,
28594
+ encode: encode$n,
27969
28595
  decode,
27970
28596
  attributes: validXmlAttributes
27971
28597
  };
@@ -27976,19 +28602,19 @@ function exportSchemaToJson(params2) {
27976
28602
  doc: translateDocumentNode,
27977
28603
  body: translateBodyNode,
27978
28604
  heading: translateHeadingNode,
27979
- paragraph: translator$h,
28605
+ paragraph: translator$k,
27980
28606
  text: translateTextNode,
27981
28607
  bulletList: translateList,
27982
28608
  orderedList: translateList,
27983
- lineBreak: translator$j,
28609
+ lineBreak: translator$m,
27984
28610
  table: translateTable,
27985
- tableRow: translator$3,
27986
- tableCell: translator$2,
28611
+ tableRow: translator$6,
28612
+ tableCell: translator$5,
27987
28613
  bookmarkStart: translateBookmarkStart,
27988
28614
  fieldAnnotation: translator,
27989
- tab: translator$i,
27990
- image: translateImageNode,
27991
- hardBreak: translator$j,
28615
+ tab: translator$l,
28616
+ image: translator$1,
28617
+ hardBreak: translator$m,
27992
28618
  commentRangeStart: () => translateCommentNode(params2, "Start"),
27993
28619
  commentRangeEnd: () => translateCommentNode(params2, "End"),
27994
28620
  commentReference: () => null,
@@ -28320,7 +28946,7 @@ function translateTextNode(params2) {
28320
28946
  const isTrackedNode = node.marks?.some((m2) => trackedMarks.includes(m2.type));
28321
28947
  if (isTrackedNode) return translateTrackedNode(params2);
28322
28948
  const isLinkNode = node.marks?.some((m2) => m2.type === "link");
28323
- if (isLinkNode) return translator$1.decode(params2);
28949
+ if (isLinkNode) return translator$4.decode(params2);
28324
28950
  const { text, marks = [] } = node;
28325
28951
  return getTextNodeForExport(text, marks, params2);
28326
28952
  }
@@ -28453,20 +29079,6 @@ function addNewLinkRelationship(params2, link) {
28453
29079
  });
28454
29080
  return newId;
28455
29081
  }
28456
- function addNewImageRelationship(params2, imagePath) {
28457
- const newId = "rId" + generateDocxRandomId();
28458
- const newRel = {
28459
- type: "element",
28460
- name: "Relationship",
28461
- attributes: {
28462
- Id: newId,
28463
- Type: "http://schemas.openxmlformats.org/officeDocument/2006/relationships/image",
28464
- Target: imagePath
28465
- }
28466
- };
28467
- params2.relationships.push(newRel);
28468
- return newId;
28469
- }
28470
29082
  function translateList(params2) {
28471
29083
  const { node, editor } = params2;
28472
29084
  const listItem = node.content[0];
@@ -28825,345 +29437,6 @@ function translateMark(mark) {
28825
29437
  }
28826
29438
  return markElement;
28827
29439
  }
28828
- function getPngDimensions(base64) {
28829
- if (!base64) return {};
28830
- const type2 = base64.split(";")[0].split("/")[1];
28831
- if (!base64 || type2 !== "png") {
28832
- return {
28833
- originalWidth: void 0,
28834
- originalHeight: void 0
28835
- };
28836
- }
28837
- let header = base64.split(",")[1].slice(0, 50);
28838
- let uint8 = Uint8Array.from(atob(header), (c2) => c2.charCodeAt(0));
28839
- let dataView = new DataView(uint8.buffer, 0, 28);
28840
- return {
28841
- originalWidth: dataView.getInt32(16),
28842
- originalHeight: dataView.getInt32(20)
28843
- };
28844
- }
28845
- function getScaledSize(originalWidth, originalHeight, maxWidth, maxHeight) {
28846
- let scaledWidth = originalWidth;
28847
- let scaledHeight = originalHeight;
28848
- let ratio = Math.min(maxWidth / originalWidth, maxHeight / originalHeight);
28849
- scaledWidth = Math.round(scaledWidth * ratio);
28850
- scaledHeight = Math.round(scaledHeight * ratio);
28851
- return { scaledWidth, scaledHeight };
28852
- }
28853
- function translateImageNode(params2, imageSize) {
28854
- const {
28855
- node: { attrs = {} },
28856
- tableCell
28857
- } = params2;
28858
- let imageId = attrs.rId;
28859
- const src = attrs.src || attrs.imageSrc;
28860
- const { originalWidth, originalHeight } = getPngDimensions(src);
28861
- let imageName;
28862
- if (params2.node.type === "image") {
28863
- if (src?.startsWith("data:")) {
28864
- imageName = getFallbackImageNameFromDataUri(src);
28865
- } else {
28866
- imageName = src?.split("/").pop();
28867
- }
28868
- } else {
28869
- imageName = attrs.fieldId;
28870
- }
28871
- imageName = sanitizeDocxMediaName(imageName);
28872
- let size2 = attrs.size ? {
28873
- w: pixelsToEmu(attrs.size.width),
28874
- h: pixelsToEmu(attrs.size.height)
28875
- } : imageSize;
28876
- if (originalWidth && originalHeight) {
28877
- const boxWidthPx = emuToPixels(size2.w);
28878
- const boxHeightPx = emuToPixels(size2.h);
28879
- const { scaledWidth, scaledHeight } = getScaledSize(originalWidth, originalHeight, boxWidthPx, boxHeightPx);
28880
- size2 = {
28881
- w: pixelsToEmu(scaledWidth),
28882
- h: pixelsToEmu(scaledHeight)
28883
- };
28884
- }
28885
- if (tableCell) {
28886
- const colwidthSum = tableCell.attrs.colwidth.reduce((acc, curr) => acc + curr, 0);
28887
- const leftMargin = tableCell.attrs.cellMargins?.left || 8;
28888
- const rightMargin = tableCell.attrs.cellMargins?.right || 8;
28889
- const maxWidthEmu = pixelsToEmu(colwidthSum - (leftMargin + rightMargin));
28890
- const { width: w2, height: h2 } = resizeKeepAspectRatio(size2.w, size2.h, maxWidthEmu);
28891
- if (w2 && h2) size2 = { w: w2, h: h2 };
28892
- }
28893
- if (params2.node.type === "image" && !imageId) {
28894
- const path = src?.split("word/")[1];
28895
- imageId = addNewImageRelationship(params2, path);
28896
- } else if (params2.node.type === "fieldAnnotation" && !imageId) {
28897
- const type2 = src?.split(";")[0].split("/")[1];
28898
- if (!type2) {
28899
- return prepareTextAnnotation(params2);
28900
- }
28901
- const sanitizedHash = sanitizeDocxMediaName(attrs.hash, generateDocxRandomId(4));
28902
- const fileName = `${imageName}_${sanitizedHash}.${type2}`;
28903
- const relationshipTarget = `media/${fileName}`;
28904
- const packagePath = `word/${relationshipTarget}`;
28905
- imageId = addNewImageRelationship(params2, relationshipTarget);
28906
- params2.media[packagePath] = src;
28907
- }
28908
- let inlineAttrs = attrs.originalPadding || {
28909
- distT: 0,
28910
- distB: 0,
28911
- distL: 0,
28912
- distR: 0
28913
- };
28914
- const anchorElements = [];
28915
- let wrapProp = [];
28916
- if (attrs.isAnchor) {
28917
- inlineAttrs = {
28918
- ...inlineAttrs,
28919
- simplePos: attrs.originalAttributes?.simplePos,
28920
- relativeHeight: 1,
28921
- behindDoc: attrs.originalAttributes?.behindDoc,
28922
- locked: attrs.originalAttributes?.locked,
28923
- layoutInCell: attrs.originalAttributes?.layoutInCell,
28924
- allowOverlap: attrs.originalAttributes?.allowOverlap
28925
- };
28926
- if (attrs.simplePos) {
28927
- anchorElements.push({
28928
- name: "wp:simplePos",
28929
- attributes: {
28930
- x: 0,
28931
- y: 0
28932
- }
28933
- });
28934
- }
28935
- if (attrs.anchorData) {
28936
- anchorElements.push({
28937
- name: "wp:positionH",
28938
- attributes: {
28939
- relativeFrom: attrs.anchorData.hRelativeFrom
28940
- },
28941
- ...attrs.marginOffset.left !== void 0 && {
28942
- elements: [
28943
- {
28944
- name: "wp:posOffset",
28945
- elements: [
28946
- {
28947
- type: "text",
28948
- text: pixelsToEmu(attrs.marginOffset.left).toString()
28949
- }
28950
- ]
28951
- }
28952
- ]
28953
- },
28954
- ...attrs.anchorData.alignH && {
28955
- elements: [
28956
- {
28957
- name: "wp:align",
28958
- elements: [
28959
- {
28960
- type: "text",
28961
- text: attrs.anchorData.alignH
28962
- }
28963
- ]
28964
- }
28965
- ]
28966
- }
28967
- });
28968
- anchorElements.push({
28969
- name: "wp:positionV",
28970
- attributes: {
28971
- relativeFrom: attrs.anchorData.vRelativeFrom
28972
- },
28973
- ...attrs.marginOffset.top !== void 0 && {
28974
- elements: [
28975
- {
28976
- name: "wp:posOffset",
28977
- elements: [
28978
- {
28979
- type: "text",
28980
- text: pixelsToEmu(attrs.marginOffset.top).toString()
28981
- }
28982
- ]
28983
- }
28984
- ]
28985
- },
28986
- ...attrs.anchorData.alignV && {
28987
- elements: [
28988
- {
28989
- name: "wp:align",
28990
- elements: [
28991
- {
28992
- type: "text",
28993
- text: attrs.anchorData.alignV
28994
- }
28995
- ]
28996
- }
28997
- ]
28998
- }
28999
- });
29000
- }
29001
- if (attrs.wrapText) {
29002
- wrapProp.push({
29003
- name: "wp:wrapSquare",
29004
- attributes: {
29005
- wrapText: attrs.wrapText
29006
- }
29007
- });
29008
- }
29009
- if (attrs.wrapTopAndBottom) {
29010
- wrapProp.push({
29011
- name: "wp:wrapTopAndBottom"
29012
- });
29013
- }
29014
- if (attrs.isAnchor && !wrapProp.length) {
29015
- wrapProp.push({
29016
- name: "wp:wrapNone"
29017
- });
29018
- }
29019
- }
29020
- const drawingXmlns = "http://schemas.openxmlformats.org/drawingml/2006/main";
29021
- const pictureXmlns = "http://schemas.openxmlformats.org/drawingml/2006/picture";
29022
- const textNode = wrapTextInRun(
29023
- {
29024
- name: "w:drawing",
29025
- elements: [
29026
- {
29027
- name: attrs.isAnchor ? "wp:anchor" : "wp:inline",
29028
- attributes: inlineAttrs,
29029
- elements: [
29030
- ...anchorElements,
29031
- {
29032
- name: "wp:extent",
29033
- attributes: {
29034
- cx: size2.w,
29035
- cy: size2.h
29036
- }
29037
- },
29038
- {
29039
- name: "wp:effectExtent",
29040
- attributes: {
29041
- l: 0,
29042
- t: 0,
29043
- r: 0,
29044
- b: 0
29045
- }
29046
- },
29047
- ...wrapProp,
29048
- {
29049
- name: "wp:docPr",
29050
- attributes: {
29051
- id: attrs.id || 0,
29052
- name: attrs.alt || `Picture ${imageName}`
29053
- }
29054
- },
29055
- {
29056
- name: "wp:cNvGraphicFramePr",
29057
- elements: [
29058
- {
29059
- name: "a:graphicFrameLocks",
29060
- attributes: {
29061
- "xmlns:a": drawingXmlns,
29062
- noChangeAspect: 1
29063
- }
29064
- }
29065
- ]
29066
- },
29067
- {
29068
- name: "a:graphic",
29069
- attributes: { "xmlns:a": drawingXmlns },
29070
- elements: [
29071
- {
29072
- name: "a:graphicData",
29073
- attributes: { uri: pictureXmlns },
29074
- elements: [
29075
- {
29076
- name: "pic:pic",
29077
- attributes: { "xmlns:pic": pictureXmlns },
29078
- elements: [
29079
- {
29080
- name: "pic:nvPicPr",
29081
- elements: [
29082
- {
29083
- name: "pic:cNvPr",
29084
- attributes: {
29085
- id: attrs.id || 0,
29086
- name: attrs.title || `Picture ${imageName}`
29087
- }
29088
- },
29089
- {
29090
- name: "pic:cNvPicPr",
29091
- elements: [
29092
- {
29093
- name: "a:picLocks",
29094
- attributes: {
29095
- noChangeAspect: 1,
29096
- noChangeArrowheads: 1
29097
- }
29098
- }
29099
- ]
29100
- }
29101
- ]
29102
- },
29103
- {
29104
- name: "pic:blipFill",
29105
- elements: [
29106
- {
29107
- name: "a:blip",
29108
- attributes: {
29109
- "r:embed": imageId
29110
- }
29111
- },
29112
- {
29113
- name: "a:stretch",
29114
- elements: [{ name: "a:fillRect" }]
29115
- }
29116
- ]
29117
- },
29118
- {
29119
- name: "pic:spPr",
29120
- attributes: {
29121
- bwMode: "auto"
29122
- },
29123
- elements: [
29124
- {
29125
- name: "a:xfrm",
29126
- elements: [
29127
- {
29128
- name: "a:ext",
29129
- attributes: {
29130
- cx: size2.w,
29131
- cy: size2.h
29132
- }
29133
- },
29134
- {
29135
- name: "a:off",
29136
- attributes: {
29137
- x: 0,
29138
- y: 0
29139
- }
29140
- }
29141
- ]
29142
- },
29143
- {
29144
- name: "a:prstGeom",
29145
- attributes: { prst: "rect" },
29146
- elements: [{ name: "a:avLst" }]
29147
- },
29148
- {
29149
- name: "a:noFill"
29150
- }
29151
- ]
29152
- }
29153
- ]
29154
- }
29155
- ]
29156
- }
29157
- ]
29158
- }
29159
- ]
29160
- }
29161
- ]
29162
- },
29163
- []
29164
- );
29165
- return textNode;
29166
- }
29167
29440
  function translateShapeContainer(params2) {
29168
29441
  const { node } = params2;
29169
29442
  const elements = translateChildNodes(params2);
@@ -29341,14 +29614,6 @@ generateXml_fn = function(node) {
29341
29614
  if (!selfClosing) tags.push(`</${name}>`);
29342
29615
  return tags;
29343
29616
  };
29344
- function resizeKeepAspectRatio(width, height, maxWidth) {
29345
- if (width > maxWidth) {
29346
- let scale = maxWidth / width;
29347
- let newHeight = Math.round(height * scale);
29348
- return { width: maxWidth, height: newHeight };
29349
- }
29350
- return { width, height };
29351
- }
29352
29617
  const translatePageNumberNode = (params2) => {
29353
29618
  const outputMarks = processOutputMarks(params2.node.attrs?.marksAsAttrs || []);
29354
29619
  return getAutoPageJson("PAGE", outputMarks);
@@ -29432,7 +29697,7 @@ const getInitialJSON = (parsedDocx, fallbackXml = defaultInitialXml) => {
29432
29697
  return parsedDocx["word/document.xml"] || parseXmlToJson(fallbackXml);
29433
29698
  };
29434
29699
  const handleDrawingNode = (params2) => {
29435
- const { nodes, filename } = params2;
29700
+ const { nodes } = params2;
29436
29701
  const validNodes = ["w:drawing", "w:p"];
29437
29702
  if (nodes.length === 0 || !validNodes.includes(nodes[0].name)) {
29438
29703
  return { nodes: [], consumed: 0 };
@@ -29442,167 +29707,9 @@ const handleDrawingNode = (params2) => {
29442
29707
  if (mainNode.name === "w:drawing") node = mainNode;
29443
29708
  else node = mainNode.elements.find((el) => el.name === "w:drawing");
29444
29709
  if (!node) return { nodes: [], consumed: 0 };
29445
- let result;
29446
- const { elements } = node;
29447
- const currentFileName = filename || null;
29448
- const isAnchor = elements.find((el) => el.name === "wp:anchor");
29449
- if (isAnchor) {
29450
- result = handleImageImport(elements[0], currentFileName, params2);
29451
- if (result && result.attrs) result.attrs.isAnchor = isAnchor;
29452
- }
29453
- const inlineImage = elements.find((el) => el.name === "wp:inline");
29454
- if (inlineImage) result = handleImageImport(inlineImage, currentFileName, params2);
29455
- return { nodes: result ? [result] : [], consumed: 1 };
29456
- };
29457
- function handleImageImport(node, currentFileName, params2) {
29458
- const { docx } = params2;
29459
- const { attributes } = node;
29460
- const padding = {
29461
- top: emuToPixels(attributes["distT"]),
29462
- bottom: emuToPixels(attributes["distB"]),
29463
- left: emuToPixels(attributes["distL"]),
29464
- right: emuToPixels(attributes["distR"])
29465
- };
29466
- const extent = node.elements.find((el) => el.name === "wp:extent");
29467
- const size2 = {
29468
- width: emuToPixels(extent.attributes?.cx),
29469
- height: emuToPixels(extent.attributes?.cy)
29470
- };
29471
- const graphic = node.elements.find((el) => el.name === "a:graphic");
29472
- const graphicData = graphic.elements.find((el) => el.name === "a:graphicData");
29473
- const { uri: uri2 } = graphicData?.attributes || {};
29474
- const shapeURI = "http://schemas.microsoft.com/office/word/2010/wordprocessingShape";
29475
- if (!!uri2 && uri2 === shapeURI) {
29476
- return handleShapeDrawing(params2, node, graphicData);
29477
- }
29478
- const picture = graphicData.elements.find((el) => el.name === "pic:pic");
29479
- if (!picture || !picture.elements) return null;
29480
- const blipFill = picture.elements.find((el) => el.name === "pic:blipFill");
29481
- const blip = blipFill.elements.find((el) => el.name === "a:blip");
29482
- const positionHTag = node.elements.find((el) => el.name === "wp:positionH");
29483
- const positionH = positionHTag?.elements.find((el) => el.name === "wp:posOffset");
29484
- const positionHValue = emuToPixels(positionH?.elements[0]?.text);
29485
- const hRelativeFrom = positionHTag?.attributes.relativeFrom;
29486
- const alignH = positionHTag?.elements.find((el) => el.name === "wp:align")?.elements[0]?.text;
29487
- const positionVTag = node.elements.find((el) => el.name === "wp:positionV");
29488
- const positionV = positionVTag?.elements?.find((el) => el.name === "wp:posOffset");
29489
- const positionVValue = emuToPixels(positionV?.elements[0]?.text);
29490
- const vRelativeFrom = positionVTag?.attributes.relativeFrom;
29491
- const alignV = positionVTag?.elements?.find((el) => el.name === "wp:align")?.elements[0]?.text;
29492
- const simplePos = node.elements.find((el) => el.name === "wp:simplePos");
29493
- const wrapSquare = node.elements.find((el) => el.name === "wp:wrapSquare");
29494
- const wrapTopAndBottom = node.elements.find((el) => el.name === "wp:wrapTopAndBottom");
29495
- const docPr = node.elements.find((el) => el.name === "wp:docPr");
29496
- let anchorData = null;
29497
- if (hRelativeFrom || alignH || vRelativeFrom || alignV) {
29498
- anchorData = {
29499
- hRelativeFrom,
29500
- vRelativeFrom,
29501
- alignH,
29502
- alignV
29503
- };
29504
- }
29505
- const marginOffset = {
29506
- left: positionHValue,
29507
- top: positionVValue
29508
- };
29509
- const { attributes: blipAttributes = {} } = blip;
29510
- const rEmbed = blipAttributes["r:embed"];
29511
- if (!rEmbed) return null;
29512
- const currentFile = currentFileName || "document.xml";
29513
- let rels = docx[`word/_rels/${currentFile}.rels`];
29514
- if (!rels) rels = docx[`word/_rels/document.xml.rels`];
29515
- const relationships = rels.elements.find((el) => el.name === "Relationships");
29516
- const { elements } = relationships;
29517
- const rel = elements.find((el) => el.attributes["Id"] === rEmbed);
29518
- if (!rel) return null;
29519
- const { attributes: relAttributes } = rel;
29520
- const targetPath = relAttributes["Target"];
29521
- let path = `word/${targetPath}`;
29522
- if (targetPath.startsWith("/word") || targetPath.startsWith("/media")) path = targetPath.substring(1);
29523
- const extension = targetPath.substring(targetPath.lastIndexOf(".") + 1);
29524
- return {
29525
- type: "image",
29526
- attrs: {
29527
- src: path,
29528
- alt: ["emf", "wmf"].includes(extension) ? "Unable to render EMF/WMF image" : docPr?.attributes.name || "Image",
29529
- extension,
29530
- id: docPr?.attributes.id || "",
29531
- title: docPr?.attributes.descr || "Image",
29532
- inline: true,
29533
- padding,
29534
- marginOffset,
29535
- size: size2,
29536
- anchorData,
29537
- ...simplePos && {
29538
- simplePos: {
29539
- x: simplePos.attributes.x,
29540
- y: simplePos.attributes.y
29541
- }
29542
- },
29543
- ...wrapSquare && {
29544
- wrapText: wrapSquare.attributes.wrapText
29545
- },
29546
- wrapTopAndBottom: !!wrapTopAndBottom,
29547
- originalPadding: {
29548
- distT: attributes["distT"],
29549
- distB: attributes["distB"],
29550
- distL: attributes["distL"],
29551
- distR: attributes["distR"]
29552
- },
29553
- originalAttributes: node.attributes,
29554
- rId: relAttributes["Id"]
29555
- }
29556
- };
29557
- }
29558
- const handleShapeDrawing = (params2, node, graphicData) => {
29559
- const wsp = graphicData.elements.find((el) => el.name === "wps:wsp");
29560
- const textBox = wsp.elements.find((el) => el.name === "wps:txbx");
29561
- const textBoxContent = textBox?.elements?.find((el) => el.name === "w:txbxContent");
29562
- node.elements.find((el) => el.name === "wp:docPr");
29563
- const spPr = wsp.elements.find((el) => el.name === "wps:spPr");
29564
- const prstGeom = spPr?.elements.find((el) => el.name === "a:prstGeom");
29565
- if (!!prstGeom && prstGeom.attributes["prst"] === "rect" && !textBoxContent) {
29566
- return getRectangleShape(params2, spPr);
29567
- }
29568
- if (!textBoxContent) {
29569
- return null;
29570
- }
29571
- const { nodeListHandler } = params2;
29572
- const translatedElement = nodeListHandler.handler({
29573
- ...params2,
29574
- node: textBoxContent.elements[0],
29575
- nodes: textBoxContent.elements,
29576
- path: [...params2.path || [], textBoxContent]
29577
- });
29578
- return translatedElement[0];
29579
- };
29580
- const getRectangleShape = (params2, node) => {
29581
- const schemaAttrs = {};
29582
- const [drawingNode] = params2.nodes;
29583
- if (drawingNode?.name === "w:drawing") {
29584
- schemaAttrs.drawingContent = drawingNode;
29585
- }
29586
- const xfrm = node.elements.find((el) => el.name === "a:xfrm");
29587
- const start2 = xfrm.elements.find((el) => el.name === "a:off");
29588
- const size2 = xfrm.elements.find((el) => el.name === "a:ext");
29589
- const solidFill = node.elements.find((el) => el.name === "a:solidFill");
29590
- node.elements.find((el) => el.name === "a:ln");
29591
- const rectangleSize = {
29592
- top: emuToPixels(start2.attributes["y"]),
29593
- left: emuToPixels(start2.attributes["x"]),
29594
- width: emuToPixels(size2.attributes["cx"]),
29595
- height: emuToPixels(size2.attributes["cy"])
29596
- };
29597
- schemaAttrs.size = rectangleSize;
29598
- const background = solidFill?.elements[0]?.attributes["val"];
29599
- if (background) {
29600
- schemaAttrs.background = "#" + background;
29601
- }
29602
- return {
29603
- type: "contentBlock",
29604
- attrs: schemaAttrs
29605
- };
29710
+ const schemaNode = translator$1.encode(params2);
29711
+ const newNodes = schemaNode ? [schemaNode] : [];
29712
+ return { nodes: newNodes, consumed: 1 };
29606
29713
  };
29607
29714
  const drawingNodeHandlerEntity = {
29608
29715
  handlerName: "drawingNodeHandler",
@@ -29702,7 +29809,7 @@ const trackChangeNodeHandlerEntity = {
29702
29809
  handlerName: "trackChangeNodeHandler",
29703
29810
  handler: handleTrackChangeNode
29704
29811
  };
29705
- const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$1);
29812
+ const hyperlinkNodeHandlerEntity = generateV2HandlerEntity("hyperlinkNodeHandler", translator$4);
29706
29813
  const handleRunNode = (params2) => {
29707
29814
  const { nodes, nodeListHandler, parentStyleId, docx } = params2;
29708
29815
  if (nodes.length === 0 || nodes[0].name !== "w:r") {
@@ -29814,7 +29921,7 @@ const handleParagraphNode = (params2) => {
29814
29921
  if (nodes.length === 0 || nodes[0].name !== "w:p") {
29815
29922
  return { nodes: [], consumed: 0 };
29816
29923
  }
29817
- const schemaNode = translator$h.encode(params2);
29924
+ const schemaNode = translator$k.encode(params2);
29818
29925
  const newNodes = schemaNode ? [schemaNode] : [];
29819
29926
  return { nodes: newNodes, consumed: 1 };
29820
29927
  };
@@ -29917,7 +30024,7 @@ const handler = (params2) => {
29917
30024
  if (nodes.length === 0 || nodes[0].name !== "w:br") {
29918
30025
  return { nodes: [], consumed: 0 };
29919
30026
  }
29920
- const result = translator$j.encode(params2);
30027
+ const result = translator$m.encode(params2);
29921
30028
  if (!result) return { nodes: [], consumed: 0 };
29922
30029
  return {
29923
30030
  nodes: [result],
@@ -30613,7 +30720,7 @@ const handleTabNode = (params2) => {
30613
30720
  if (!nodes.length || nodes[0].name !== "w:tab") {
30614
30721
  return { nodes: [], consumed: 0 };
30615
30722
  }
30616
- const node = translator$i.encode(params2);
30723
+ const node = translator$l.encode(params2);
30617
30724
  return { nodes: [node], consumed: 1 };
30618
30725
  };
30619
30726
  const tabNodeEntityHandler = {
@@ -59455,69 +59562,353 @@ const ContentBlock = Node$1.create({
59455
59562
  };
59456
59563
  }
59457
59564
  });
59565
+ class StructuredContentViewBase {
59566
+ constructor(props) {
59567
+ __publicField$1(this, "node");
59568
+ __publicField$1(this, "view");
59569
+ __publicField$1(this, "getPos");
59570
+ __publicField$1(this, "decorations");
59571
+ __publicField$1(this, "innerDecorations");
59572
+ __publicField$1(this, "editor");
59573
+ __publicField$1(this, "extension");
59574
+ __publicField$1(this, "htmlAttributes");
59575
+ __publicField$1(this, "root");
59576
+ __publicField$1(this, "isDragging", false);
59577
+ this.node = props.node;
59578
+ this.view = props.editor.view;
59579
+ this.getPos = props.getPos;
59580
+ this.decorations = props.decorations;
59581
+ this.innerDecorations = props.innerDecorations;
59582
+ this.editor = props.editor;
59583
+ this.extension = props.extension;
59584
+ this.htmlAttributes = props.htmlAttributes;
59585
+ this.mount(props);
59586
+ }
59587
+ mount(props) {
59588
+ return;
59589
+ }
59590
+ get dom() {
59591
+ return this.root;
59592
+ }
59593
+ get contentDOM() {
59594
+ return null;
59595
+ }
59596
+ update(node, decorations, innerDecorations) {
59597
+ if (node.type !== this.node.type) {
59598
+ return false;
59599
+ }
59600
+ this.node = node;
59601
+ this.decorations = decorations;
59602
+ this.innerDecorations = innerDecorations;
59603
+ this.updateHTMLAttributes();
59604
+ return true;
59605
+ }
59606
+ stopEvent(event) {
59607
+ if (!this.dom) return false;
59608
+ const target = event.target;
59609
+ const isInElement = this.dom.contains(target) && !this.contentDOM?.contains(target);
59610
+ if (!isInElement) return false;
59611
+ const isDragEvent = event.type.startsWith("drag");
59612
+ const isDropEvent = event.type === "drop";
59613
+ const isInput = ["INPUT", "BUTTON", "SELECT", "TEXTAREA"].includes(target.tagName) || target.isContentEditable;
59614
+ if (isInput && !isDropEvent && !isDragEvent) return true;
59615
+ const { isEditable } = this.editor;
59616
+ const { isDragging } = this;
59617
+ const isDraggable = !!this.node.type.spec.draggable;
59618
+ const isSelectable = NodeSelection.isSelectable(this.node);
59619
+ const isCopyEvent = event.type === "copy";
59620
+ const isPasteEvent = event.type === "paste";
59621
+ const isCutEvent = event.type === "cut";
59622
+ const isClickEvent = event.type === "mousedown";
59623
+ if (!isDraggable && isSelectable && isDragEvent && event.target === this.dom) {
59624
+ event.preventDefault();
59625
+ }
59626
+ if (isDraggable && isDragEvent && !isDragging && event.target === this.dom) {
59627
+ event.preventDefault();
59628
+ return false;
59629
+ }
59630
+ if (isDraggable && isEditable && !isDragging && isClickEvent) {
59631
+ const dragHandle = target.closest("[data-drag-handle]");
59632
+ const isValidDragHandle = dragHandle && (this.dom === dragHandle || this.dom.contains(dragHandle));
59633
+ if (isValidDragHandle) {
59634
+ this.isDragging = true;
59635
+ document.addEventListener(
59636
+ "dragend",
59637
+ () => {
59638
+ this.isDragging = false;
59639
+ },
59640
+ { once: true }
59641
+ );
59642
+ document.addEventListener(
59643
+ "drop",
59644
+ () => {
59645
+ this.isDragging = false;
59646
+ },
59647
+ { once: true }
59648
+ );
59649
+ document.addEventListener(
59650
+ "mouseup",
59651
+ () => {
59652
+ this.isDragging = false;
59653
+ },
59654
+ { once: true }
59655
+ );
59656
+ }
59657
+ }
59658
+ if (isDragging || isDropEvent || isCopyEvent || isPasteEvent || isCutEvent || isClickEvent && isSelectable) {
59659
+ return false;
59660
+ }
59661
+ return true;
59662
+ }
59663
+ ignoreMutation(mutation) {
59664
+ if (!this.dom || !this.contentDOM) return true;
59665
+ if (this.node.isLeaf || this.node.isAtom) return true;
59666
+ if (mutation.type === "selection") return false;
59667
+ if (this.contentDOM === mutation.target && mutation.type === "attributes") return true;
59668
+ if (this.contentDOM.contains(mutation.target)) return false;
59669
+ return true;
59670
+ }
59671
+ destroy() {
59672
+ this.dom.remove();
59673
+ this.contentDOM?.remove();
59674
+ }
59675
+ updateAttributes(attrs) {
59676
+ const pos = this.getPos();
59677
+ if (typeof pos !== "number") {
59678
+ return;
59679
+ }
59680
+ return this.view.dispatch(
59681
+ this.view.state.tr.setNodeMarkup(pos, void 0, {
59682
+ ...this.node.attrs,
59683
+ ...attrs
59684
+ })
59685
+ );
59686
+ }
59687
+ updateHTMLAttributes() {
59688
+ const { extensionService } = this.editor;
59689
+ const { attributes } = extensionService;
59690
+ const extensionAttrs = attributes.filter((i) => i.type === this.node.type.name);
59691
+ this.htmlAttributes = Attribute2.getAttributesToRender(this.node, extensionAttrs);
59692
+ }
59693
+ createDragHandle() {
59694
+ const dragHandle = document.createElement("span");
59695
+ dragHandle.classList.add("sd-structured-content-draggable");
59696
+ dragHandle.draggable = true;
59697
+ dragHandle.contentEditable = "false";
59698
+ dragHandle.dataset.dragHandle = "";
59699
+ const textElement = document.createElement("span");
59700
+ textElement.textContent = "Structured content";
59701
+ dragHandle.append(textElement);
59702
+ return dragHandle;
59703
+ }
59704
+ onDragStart(event) {
59705
+ const { view } = this.editor;
59706
+ const target = event.target;
59707
+ const dragHandle = target.nodeType === 3 ? target.parentElement?.closest("[data-drag-handle]") : target.closest("[data-drag-handle]");
59708
+ if (!this.dom || this.contentDOM?.contains(target) || !dragHandle) {
59709
+ return;
59710
+ }
59711
+ let x = 0;
59712
+ let y2 = 0;
59713
+ if (this.dom !== dragHandle) {
59714
+ const domBox = this.dom.getBoundingClientRect();
59715
+ const handleBox = dragHandle.getBoundingClientRect();
59716
+ const offsetX = event.offsetX ?? event.nativeEvent?.offsetX;
59717
+ const offsetY = event.offsetY ?? event.nativeEvent?.offsetY;
59718
+ x = handleBox.x - domBox.x + offsetX;
59719
+ y2 = handleBox.y - domBox.y + offsetY;
59720
+ }
59721
+ event.dataTransfer?.setDragImage(this.dom, x, y2);
59722
+ const pos = this.getPos();
59723
+ if (typeof pos !== "number") {
59724
+ return;
59725
+ }
59726
+ const selection = NodeSelection.create(view.state.doc, pos);
59727
+ const transaction = view.state.tr.setSelection(selection);
59728
+ view.dispatch(transaction);
59729
+ }
59730
+ }
59731
+ class StructuredContentInlineView extends StructuredContentViewBase {
59732
+ constructor(props) {
59733
+ super(props);
59734
+ }
59735
+ mount() {
59736
+ this.buildView();
59737
+ }
59738
+ get contentDOM() {
59739
+ const contentElement = this.dom?.querySelector(`.${structuredContentInnerClass$1}`);
59740
+ return contentElement || null;
59741
+ }
59742
+ createElement() {
59743
+ const element = document.createElement("span");
59744
+ element.classList.add(structuredContentClass$1);
59745
+ element.setAttribute("data-structured-content", "");
59746
+ const contentElement = document.createElement("span");
59747
+ contentElement.classList.add(structuredContentInnerClass$1);
59748
+ element.append(contentElement);
59749
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59750
+ updateDOMAttributes(element, { ...domAttrs });
59751
+ return { element, contentElement };
59752
+ }
59753
+ buildView() {
59754
+ const { element } = this.createElement();
59755
+ const dragHandle = this.createDragHandle();
59756
+ element.prepend(dragHandle);
59757
+ element.addEventListener("dragstart", (e) => this.onDragStart(e));
59758
+ this.root = element;
59759
+ }
59760
+ updateView() {
59761
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59762
+ updateDOMAttributes(this.dom, { ...domAttrs });
59763
+ }
59764
+ update(node, decorations, innerDecorations) {
59765
+ const result = super.update(node, decorations, innerDecorations);
59766
+ if (!result) return false;
59767
+ this.updateView();
59768
+ return true;
59769
+ }
59770
+ }
59771
+ const structuredContentClass$1 = "sd-structured-content";
59772
+ const structuredContentInnerClass$1 = "sd-structured-content__content";
59458
59773
  const StructuredContent = Node$1.create({
59459
59774
  name: "structuredContent",
59460
- group: "inline",
59775
+ group: "inline structuredContent",
59461
59776
  inline: true,
59462
59777
  content: "inline*",
59778
+ isolating: true,
59779
+ atom: false,
59780
+ // false - has editable content.
59781
+ draggable: true,
59463
59782
  addOptions() {
59464
59783
  return {
59465
- structuredContentClass: "sd-structured-content-tag",
59466
59784
  htmlAttributes: {
59785
+ class: structuredContentClass$1,
59467
59786
  "aria-label": "Structured content node"
59468
59787
  }
59469
59788
  };
59470
59789
  },
59471
59790
  addAttributes() {
59472
59791
  return {
59792
+ id: {
59793
+ default: null,
59794
+ parseDOM: (elem) => elem.getAttribute("data-id"),
59795
+ renderDOM: (attrs) => {
59796
+ if (!attrs.id) return {};
59797
+ return { "data-id": attrs.id };
59798
+ }
59799
+ },
59473
59800
  sdtPr: {
59474
59801
  rendered: false
59475
59802
  }
59476
59803
  };
59477
59804
  },
59478
59805
  parseDOM() {
59479
- return [{ tag: `span.${this.options.structuredContentClass}` }];
59806
+ return [{ tag: "span[data-structured-content]" }];
59480
59807
  },
59481
59808
  renderDOM({ htmlAttributes }) {
59482
59809
  return [
59483
59810
  "span",
59484
59811
  Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes, {
59485
- class: this.options.structuredContentClass
59812
+ "data-structured-content": ""
59486
59813
  }),
59487
59814
  0
59488
59815
  ];
59816
+ },
59817
+ addNodeView() {
59818
+ return (props) => {
59819
+ return new StructuredContentInlineView({ ...props });
59820
+ };
59489
59821
  }
59490
59822
  });
59823
+ class StructuredContentBlockView extends StructuredContentViewBase {
59824
+ constructor(props) {
59825
+ super(props);
59826
+ }
59827
+ mount() {
59828
+ this.buildView();
59829
+ }
59830
+ get contentDOM() {
59831
+ const contentElement = this.dom?.querySelector(`.${structuredContentInnerClass}`);
59832
+ return contentElement || null;
59833
+ }
59834
+ createElement() {
59835
+ const element = document.createElement("div");
59836
+ element.classList.add(structuredContentClass);
59837
+ element.setAttribute("data-structured-content-block", "");
59838
+ const contentElement = document.createElement("div");
59839
+ contentElement.classList.add(structuredContentInnerClass);
59840
+ element.append(contentElement);
59841
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59842
+ updateDOMAttributes(element, { ...domAttrs });
59843
+ return { element, contentElement };
59844
+ }
59845
+ buildView() {
59846
+ const { element } = this.createElement();
59847
+ const dragHandle = this.createDragHandle();
59848
+ element.prepend(dragHandle);
59849
+ element.addEventListener("dragstart", (e) => this.onDragStart(e));
59850
+ this.root = element;
59851
+ }
59852
+ updateView() {
59853
+ const domAttrs = Attribute2.mergeAttributes(this.htmlAttributes);
59854
+ updateDOMAttributes(this.dom, { ...domAttrs });
59855
+ }
59856
+ update(node, decorations, innerDecorations) {
59857
+ const result = super.update(node, decorations, innerDecorations);
59858
+ if (!result) return false;
59859
+ this.updateView();
59860
+ return true;
59861
+ }
59862
+ }
59863
+ const structuredContentClass = "sd-structured-content-block";
59864
+ const structuredContentInnerClass = "sd-structured-content-block__content";
59491
59865
  const StructuredContentBlock = Node$1.create({
59492
59866
  name: "structuredContentBlock",
59493
- group: "block",
59867
+ group: "block structuredContent",
59494
59868
  content: "block*",
59869
+ isolating: true,
59870
+ atom: false,
59871
+ // false - has editable content.
59872
+ draggable: true,
59495
59873
  addOptions() {
59496
59874
  return {
59497
- structuredContentClass: "sd-structured-content-block-tag",
59498
59875
  htmlAttributes: {
59876
+ class: structuredContentClass,
59499
59877
  "aria-label": "Structured content block node"
59500
59878
  }
59501
59879
  };
59502
59880
  },
59503
59881
  addAttributes() {
59504
59882
  return {
59883
+ id: {
59884
+ default: null,
59885
+ parseDOM: (elem) => elem.getAttribute("data-id"),
59886
+ renderDOM: (attrs) => {
59887
+ if (!attrs.id) return {};
59888
+ return { "data-id": attrs.id };
59889
+ }
59890
+ },
59505
59891
  sdtPr: {
59506
59892
  rendered: false
59507
59893
  }
59508
59894
  };
59509
59895
  },
59510
59896
  parseDOM() {
59511
- return [{ tag: `div.${this.options.structuredContentClass}` }];
59897
+ return [{ tag: "div[data-structured-content-block]" }];
59512
59898
  },
59513
59899
  renderDOM({ htmlAttributes }) {
59514
59900
  return [
59515
59901
  "div",
59516
59902
  Attribute2.mergeAttributes(this.options.htmlAttributes, htmlAttributes, {
59517
- class: this.options.structuredContentClass
59903
+ "data-structured-content-block": ""
59518
59904
  }),
59519
59905
  0
59520
59906
  ];
59907
+ },
59908
+ addNodeView() {
59909
+ return (props) => {
59910
+ return new StructuredContentBlockView({ ...props });
59911
+ };
59521
59912
  }
59522
59913
  });
59523
59914
  class DocumentSectionView {
@@ -81919,11 +82310,6 @@ const _sfc_main = {
81919
82310
  }
81920
82311
  };
81921
82312
  const SuperInput = /* @__PURE__ */ _export_sfc(_sfc_main, [["__scopeId", "data-v-4d5cff52"]]);
81922
- const registeredHandlers = Object.freeze({
81923
- "w:br": translator$j,
81924
- "w:tab": translator$i,
81925
- "w:p": translator$h
81926
- });
81927
82313
  const Extensions = {
81928
82314
  Node: Node$1,
81929
82315
  Attribute: Attribute2,