ooxml-core 1.24.1 → 1.24.3

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 (62) hide show
  1. package/dist/{PptxHandler-KFEE7O7W.cjs → PptxHandler-2YPMMGOJ.cjs} +3 -3
  2. package/dist/PptxHandler-VXK5EY7J.mjs +4 -0
  3. package/dist/{PptxHandler-5TWAQWPK.mjs → PptxHandler-WQPEYOSS.mjs} +2 -2
  4. package/dist/{PresentationBuilder-SXLRXYDI.cjs → PresentationBuilder-F5U4KEGH.cjs} +5 -5
  5. package/dist/{PresentationBuilder-SVHIKT4C.mjs → PresentationBuilder-FGWHIJV7.mjs} +2 -2
  6. package/dist/{PresentationBuilder-SCT5AQBP.mjs → PresentationBuilder-PS5S52M3.mjs} +2 -2
  7. package/dist/automation/index.cjs +24 -1
  8. package/dist/automation/index.mjs +24 -1
  9. package/dist/{chunk-7N7C5BNM.mjs → chunk-2AFO3HNI.mjs} +2 -2
  10. package/dist/{chunk-CWCDFPKN.mjs → chunk-4IFENOU7.mjs} +1 -1
  11. package/dist/{chunk-XK55DEUD.cjs → chunk-5SE4FGS4.cjs} +1019 -1019
  12. package/dist/{chunk-NE7626A4.mjs → chunk-HKCSJAQD.mjs} +4 -4
  13. package/dist/{chunk-GVP262WE.mjs → chunk-K2XWOVLV.mjs} +3 -3
  14. package/dist/{chunk-6IIMI5RS.mjs → chunk-O6ISWI34.mjs} +1 -1
  15. package/dist/{chunk-KVKTHGIY.mjs → chunk-OJWKGDJF.mjs} +1 -1
  16. package/dist/{chunk-4LZIUJI3.cjs → chunk-QCZX6K67.cjs} +1 -1
  17. package/dist/{chunk-ON7XVRHQ.mjs → chunk-RF2YPEKI.mjs} +3 -3
  18. package/dist/crypto/detect.d.ts +5 -1
  19. package/dist/crypto/detect.d.ts.map +1 -1
  20. package/dist/crypto/index.cjs +1 -1
  21. package/dist/crypto/index.mjs +1 -1
  22. package/dist/docx/embedded.cjs +24 -1
  23. package/dist/docx/embedded.mjs +24 -1
  24. package/dist/docx/index.cjs +24 -1
  25. package/dist/docx/index.mjs +24 -1
  26. package/dist/docx/load/index.cjs +25 -2
  27. package/dist/docx/load/index.mjs +25 -2
  28. package/dist/docx/ui/content-control-commands.d.ts +1 -1
  29. package/dist/docx/ui/content-control-commands.d.ts.map +1 -1
  30. package/dist/docx/ui/content-control-guard.d.ts.map +1 -1
  31. package/dist/docx/ui/content-control-occurrences.d.ts +17 -0
  32. package/dist/docx/ui/content-control-occurrences.d.ts.map +1 -0
  33. package/dist/docx/ui/content-control-temporary.d.ts +1 -4
  34. package/dist/docx/ui/content-control-temporary.d.ts.map +1 -1
  35. package/dist/docx/ui/form-field-guard.d.ts +10 -4
  36. package/dist/docx/ui/form-field-guard.d.ts.map +1 -1
  37. package/dist/docx/ui/form-protection-sections.d.ts +26 -0
  38. package/dist/docx/ui/form-protection-sections.d.ts.map +1 -0
  39. package/dist/docx/ui/form-text-paste.d.ts +35 -0
  40. package/dist/docx/ui/form-text-paste.d.ts.map +1 -0
  41. package/dist/docx/ui/index.cjs +266 -108
  42. package/dist/docx/ui/index.mjs +266 -108
  43. package/dist/docx/write-table-controls.d.ts +2 -1
  44. package/dist/docx/write-table-controls.d.ts.map +1 -1
  45. package/dist/pptx/automation/index.cjs +4 -4
  46. package/dist/pptx/automation/index.d.ts +4 -1
  47. package/dist/pptx/automation/index.d.ts.map +1 -1
  48. package/dist/pptx/automation/index.mjs +6 -6
  49. package/dist/pptx/chunks/index-4FmgJajb.d.ts.map +1 -1
  50. package/dist/pptx/cli/index.cjs +3 -3
  51. package/dist/pptx/cli/index.mjs +4 -4
  52. package/dist/pptx/converter/index.mjs +2 -2
  53. package/dist/pptx/editor/render/find-replace.cjs +14 -14
  54. package/dist/pptx/editor/render/find-replace.mjs +1 -1
  55. package/dist/pptx/editor/render/slide-operations.cjs +8 -8
  56. package/dist/pptx/editor/render/slide-operations.mjs +2 -2
  57. package/dist/pptx/index.cjs +3 -3
  58. package/dist/pptx/index.mjs +5 -5
  59. package/dist/xlsx/load/index.cjs +1 -1
  60. package/dist/xlsx/load/index.mjs +1 -1
  61. package/package.json +1 -1
  62. package/dist/PptxHandler-KBJ4TN3T.mjs +0 -4
@@ -926,12 +926,56 @@ var isPlaceholderStyle = (mark) => mark.type.name === "characterStyle" && mark.a
926
926
  function firstText(state, span) {
927
927
  if (span.level === "inline") return state.doc.nodeAt(span.from);
928
928
  let found = null;
929
- state.doc.nodesBetween(span.from, span.to, (node) => {
929
+ state.doc.nodesBetween(span.from, span.to, (node, pos) => {
930
930
  if (!found && node.isText) found = node;
931
+ return !found && !(span.level === "cell" && node.type.name === "table" && pos > span.from);
932
+ });
933
+ return found;
934
+ }
935
+ function holdsNothing(doc, from, to) {
936
+ let nothing = true;
937
+ if (from < to)
938
+ doc.nodesBetween(from, to, (node) => {
939
+ if (node.isInline) nothing = false;
940
+ return nothing;
941
+ });
942
+ return nothing;
943
+ }
944
+ function touchesTable(doc, cell, from, to) {
945
+ let found = false;
946
+ doc.nodesBetween(from, to, (node, pos) => {
947
+ found ||= node.type.name === "table" && pos > cell;
931
948
  return !found;
932
949
  });
933
950
  return found;
934
951
  }
952
+ function cellText(doc, pos) {
953
+ const cell = doc.nodeAt(pos);
954
+ const text2 = { from: pos + 2, to: pos + cell.nodeSize - 2 };
955
+ let first3 = true;
956
+ cell.forEach((child, offset) => {
957
+ if (child.type.name !== "paragraph") return;
958
+ if (first3) text2.from = pos + 2 + offset;
959
+ text2.to = pos + offset + child.nodeSize;
960
+ first3 = false;
961
+ });
962
+ return text2;
963
+ }
964
+ function cellContent(state, cell, text2) {
965
+ const nodes = [];
966
+ let placed = false;
967
+ cell.forEach((child) => {
968
+ if (child.type.name !== "paragraph") {
969
+ nodes.push(child);
970
+ return;
971
+ }
972
+ const attrs2 = child.attrs.contentControl ? { ...child.attrs, contentControl: null } : child.attrs;
973
+ nodes.push(child.type.create(attrs2, placed ? null : text2));
974
+ placed = true;
975
+ });
976
+ if (!placed) nodes.push(state.schema.nodes.paragraph.create(null, text2));
977
+ return Fragment.fromArray(nodes);
978
+ }
935
979
  function contentMarks(state, span, change) {
936
980
  const schema = state.schema;
937
981
  const first3 = firstText(state, span);
@@ -963,10 +1007,7 @@ function replaceControlContent(state, span, edit) {
963
1007
  if (span.level !== "cell")
964
1008
  return state.tr.replaceWith(span.from, span.to, text2 ?? []).setMeta(CONTROL_EDIT_META, true);
965
1009
  const cell = state.doc.nodeAt(span.from);
966
- const first3 = cell.firstChild?.type.name === "paragraph" ? cell.firstChild : void 0;
967
- const attrs2 = first3?.attrs.contentControl ? { ...first3.attrs, contentControl: null } : first3?.attrs;
968
- const paragraph = (first3?.type ?? state.schema.nodes.paragraph).create(attrs2, text2);
969
- const tr = state.tr.replaceWith(span.from + 1, span.to - 1, paragraph);
1010
+ const tr = state.tr.replaceWith(span.from + 1, span.to - 1, cellContent(state, cell, text2));
970
1011
  tr.setNodeMarkup(span.from, void 0, {
971
1012
  ...cell.attrs,
972
1013
  contentControl: change.removed ? null : change.control
@@ -974,7 +1015,7 @@ function replaceControlContent(state, span, edit) {
974
1015
  const { from, to } = state.selection;
975
1016
  if (from > span.from && to < span.to) {
976
1017
  const shown = change.control.showingPlaceholder && !change.removed;
977
- const start = span.from + 2;
1018
+ const start = cellText(tr.doc, span.from).from;
978
1019
  tr.setSelection(TextSelection.create(tr.doc, shown ? start : start + (text2?.nodeSize ?? 0)));
979
1020
  }
980
1021
  return tr.setMeta(CONTROL_EDIT_META, true);
@@ -1033,8 +1074,14 @@ function chooseDate(state, id, date, at) {
1033
1074
  return void 0;
1034
1075
  return replaceControlContent(state, span, setControlDate(span.control, date));
1035
1076
  }
1077
+ function inputControlAt(spans, pos) {
1078
+ const span = controlAt(spans, pos, true);
1079
+ if (span?.level !== "block") return span;
1080
+ const cells = spans.filter((other) => other.level === "cell");
1081
+ return controlAt(cells, pos) ?? span;
1082
+ }
1036
1083
  function typeOverPlaceholder(state, from, text2, to = from) {
1037
- const span = controlAt(controlSpans(state.doc), from, true);
1084
+ const span = inputControlAt(controlSpans(state.doc), from);
1038
1085
  if (span?.level === "cell") return typeInCell(state, span, text2, to);
1039
1086
  if (span?.level !== "inline") return void 0;
1040
1087
  const { control } = span;
@@ -1057,7 +1104,9 @@ function typeInCell(state, span, text2, to) {
1057
1104
  return void 0;
1058
1105
  if (!editable(state, span)) return "blocked";
1059
1106
  const tr = replaceControlContent(state, span, afterEdit({ control: withValue(control), text: text2 }));
1060
- return tr.setSelection(TextSelection.create(tr.doc, span.from + 2 + text2.length));
1107
+ return tr.setSelection(
1108
+ TextSelection.create(tr.doc, cellText(tr.doc, span.from).from + text2.length)
1109
+ );
1061
1110
  }
1062
1111
  function withoutPlaceholderStyle(fragment) {
1063
1112
  const nodes = [];
@@ -1070,7 +1119,7 @@ function withoutPlaceholderStyle(fragment) {
1070
1119
  }
1071
1120
  function pasteInCell(state, slice) {
1072
1121
  const { from, to } = state.selection;
1073
- const span = controlAt(controlSpans(state.doc), from, true);
1122
+ const span = inputControlAt(controlSpans(state.doc), from);
1074
1123
  if (span?.level !== "cell" || to > span.to - 1) return void 0;
1075
1124
  const { control } = span;
1076
1125
  if (control.kind === "checkbox" || control.kind === "dropDownList") return "blocked";
@@ -1081,23 +1130,26 @@ function pasteInCell(state, slice) {
1081
1130
  span,
1082
1131
  afterEdit({ control: withValue(control), text: "" })
1083
1132
  );
1084
- const at = TextSelection.create(tr.doc, span.from + 2);
1133
+ const at = TextSelection.create(tr.doc, cellText(tr.doc, span.from).from);
1085
1134
  return tr.setSelection(at).replaceSelection(
1086
1135
  new Slice(withoutPlaceholderStyle(slice.content), slice.openStart, slice.openEnd)
1087
1136
  );
1088
1137
  }
1089
1138
  function deleteToPlaceholder(state, direction) {
1090
1139
  const { selection } = state;
1091
- const span = controlAt(controlSpans(state.doc), selection.from, true);
1140
+ const span = inputControlAt(controlSpans(state.doc), selection.from);
1092
1141
  if (!span || span.level === "block" || span.control.showingPlaceholder) return void 0;
1093
1142
  if (!editable(state, span) || span.control.kind === "checkbox") return void 0;
1094
1143
  if (!replaceable(state, span)) return void 0;
1095
1144
  if (removedByEdit(span.control)) return void 0;
1096
1145
  const [from, to] = selection.empty ? direction === "backward" ? [selection.from - 1, selection.from] : [selection.from, selection.from + 1] : [selection.from, selection.to];
1097
1146
  const cell = span.level === "cell";
1098
- const inner = cell ? { from: span.from + 2, to: span.to - 2 } : span;
1147
+ const inner = cell ? cellText(state.doc, span.from) : span;
1099
1148
  const outer = cell ? { from: span.from + 1, to: span.to - 1 } : span;
1100
- if (from > inner.from || to < inner.to || from < outer.from || to > outer.to) return void 0;
1149
+ if (from < outer.from || to > outer.to) return void 0;
1150
+ if (cell && touchesTable(state.doc, span.from, from, to)) return void 0;
1151
+ if (!holdsNothing(state.doc, inner.from, from) || !holdsNothing(state.doc, to, inner.to))
1152
+ return void 0;
1101
1153
  return replaceControlContent(state, span, placeholderChange(span.control));
1102
1154
  }
1103
1155
  var newControlId = (doc) => freshControlId(new Set(everyControlSpan(doc).map((span) => span.control.id)));
@@ -1130,6 +1182,43 @@ function insertContentControl(state, kind, options2 = {}) {
1130
1182
  tr.setSelection(TextSelection.create(tr.doc, start, start + change.text.length));
1131
1183
  return tr.setMeta(CONTROL_EDIT_META, true);
1132
1184
  }
1185
+
1186
+ // docx/ui/content-control-occurrences.ts
1187
+ function continues(doc, inline, end, span) {
1188
+ if (span.from === end) return true;
1189
+ if (span.level === "inline") {
1190
+ let at = end;
1191
+ for (const other of inline) if (other.from === at && other.to <= span.from) at = other.to;
1192
+ return at === span.from;
1193
+ }
1194
+ if (span.level !== "block") return false;
1195
+ const $end = doc.resolve(end);
1196
+ if (doc.resolve(span.from).parent !== $end.parent) return false;
1197
+ let split = true;
1198
+ $end.parent.forEach((node, offset) => {
1199
+ const pos = $end.start() + offset;
1200
+ if (pos < end || pos >= span.from || node.type.name !== "paragraph") return;
1201
+ if (!node.attrs.contentControl) split = false;
1202
+ });
1203
+ return split;
1204
+ }
1205
+ function controlOccurrences(doc, spans, inline) {
1206
+ const found = [];
1207
+ const last = /* @__PURE__ */ new Map();
1208
+ for (const span of [...spans].sort((a, b) => a.from - b.from)) {
1209
+ const key = `${span.level}:${span.control.id}`;
1210
+ const previous = last.get(key);
1211
+ if (previous && continues(doc, inline, previous.to, span)) {
1212
+ previous.spans.push(span);
1213
+ previous.to = span.to;
1214
+ continue;
1215
+ }
1216
+ const occurrence = { key, spans: [span], from: span.from, to: span.to };
1217
+ found.push(occurrence);
1218
+ last.set(key, occurrence);
1219
+ }
1220
+ return found;
1221
+ }
1133
1222
  var VERBATIM = ["sourceXml", "endSourceXml"];
1134
1223
  var INLINE = ["endSourceXml"];
1135
1224
  var sourcesOf = (control, fields = VERBATIM) => fields.flatMap((field) => {
@@ -4119,8 +4208,8 @@ function resolveChartStyleDefinition(style, resolve) {
4119
4208
  }
4120
4209
  return Object.keys(out).length ? out : void 0;
4121
4210
  }
4122
- function effectiveBuiltInChartStyle(formatting) {
4123
- return formatting?.builtInStyle ?? (formatting?.sourceXml ? void 0 : 102);
4211
+ function effectiveBuiltInChartStyle(formatting2) {
4212
+ return formatting2?.builtInStyle ?? (formatting2?.sourceXml ? void 0 : 102);
4124
4213
  }
4125
4214
  function builtInChartTextStyle(id) {
4126
4215
  if (id === void 0 || !Number.isInteger(id) || !(id >= 1 && id <= 48 || id >= 101 && id <= 148))
@@ -5893,10 +5982,10 @@ function properties(run) {
5893
5982
  };
5894
5983
  }
5895
5984
  function chartTitleText(chart, theme) {
5896
- const formatting = chart.formatting;
5897
- const entry = formatting?.entries.title;
5985
+ const formatting2 = chart.formatting;
5986
+ const entry = formatting2?.entries.title;
5898
5987
  const body = entry?.textBody;
5899
- if (!formatting || !body || body.text !== chart.title) return void 0;
5988
+ if (!formatting2 || !body || body.text !== chart.title) return void 0;
5900
5989
  if (body.paragraphs.length === 1 && body.paragraphs[0].runs.length <= 1 && !body.text.includes("\n") && !body.paragraphs[0].lineSpacing && !body.paragraphs[0].spaceBefore && !body.paragraphs[0].spaceAfter)
5901
5990
  return void 0;
5902
5991
  return {
@@ -5915,7 +6004,7 @@ function chartTitleText(chart, theme) {
5915
6004
  const appearance = chartAppearance(
5916
6005
  {
5917
6006
  ...chart,
5918
- formatting: { ...formatting, entries: { ...formatting.entries, title: direct } }
6007
+ formatting: { ...formatting2, entries: { ...formatting2.entries, title: direct } }
5919
6008
  },
5920
6009
  theme
5921
6010
  )?.title ?? {};
@@ -7284,9 +7373,9 @@ function chartSpaceKind(space) {
7284
7373
  return { type, drawn: DRAWN_CHART_TYPES.has(type) };
7285
7374
  }
7286
7375
  function renderChartSpaceSvg(space, options2) {
7287
- const { width, height, theme, fonts, formatting, colorPalette, styleDefinition, ...svg } = options2;
7376
+ const { width, height, theme, fonts, formatting: formatting2, colorPalette, styleDefinition, ...svg } = options2;
7288
7377
  const summary = chartSummaryFromSpace(space, {
7289
- ...formatting ? { formatting } : {},
7378
+ ...formatting2 ? { formatting: formatting2 } : {},
7290
7379
  ...colorPalette !== void 0 ? { colorPalette } : {},
7291
7380
  ...styleDefinition ? { styleDefinition } : {}
7292
7381
  });
@@ -8767,12 +8856,12 @@ function resolveTableStyleFormatting(tableStyleId, catalog, look, rowIndex, rowC
8767
8856
  if (style.borders) result.borders = { ...result.borders, ...style.borders };
8768
8857
  if (style.shadingFill) result.shadingFill = style.shadingFill;
8769
8858
  for (const region of regions) {
8770
- const formatting = style.conditional[region];
8771
- if (!formatting) continue;
8772
- if (formatting.borders) result.borders = { ...result.borders, ...formatting.borders };
8773
- if (formatting.shadingFill) result.shadingFill = formatting.shadingFill;
8774
- if (formatting.shadingThemeFill) result.shadingThemeFill = formatting.shadingThemeFill;
8775
- if (formatting.run) result.run = { ...result.run, ...formatting.run };
8859
+ const formatting2 = style.conditional[region];
8860
+ if (!formatting2) continue;
8861
+ if (formatting2.borders) result.borders = { ...result.borders, ...formatting2.borders };
8862
+ if (formatting2.shadingFill) result.shadingFill = formatting2.shadingFill;
8863
+ if (formatting2.shadingThemeFill) result.shadingThemeFill = formatting2.shadingThemeFill;
8864
+ if (formatting2.run) result.run = { ...result.run, ...formatting2.run };
8776
8865
  }
8777
8866
  }
8778
8867
  return result;
@@ -12685,7 +12774,7 @@ function trackChangesPlugin(getAuthor, isEnabled, idGenerator = createCollaborat
12685
12774
  if (boundary) return boundary.setMeta(trackChangesPluginKey, { tracked: true });
12686
12775
  if (!steps.length || !steps.every((step) => step instanceof ReplaceStep)) {
12687
12776
  if (newState.doc.attrs.trackFormatting === false) return null;
12688
- const formatting = trackRunFormatting(
12777
+ const formatting2 = trackRunFormatting(
12689
12778
  steps,
12690
12779
  oldState,
12691
12780
  newState,
@@ -12700,7 +12789,7 @@ function trackChangesPlugin(getAuthor, isEnabled, idGenerator = createCollaborat
12700
12789
  date,
12701
12790
  () => idGenerator("revision")
12702
12791
  );
12703
- return formatting?.setMeta(trackChangesPluginKey, { tracked: true }) ?? null;
12792
+ return formatting2?.setMeta(trackChangesPluginKey, { tracked: true }) ?? null;
12704
12793
  }
12705
12794
  const transform = new Transform(oldState.doc);
12706
12795
  const untracked = new Mapping();
@@ -12787,46 +12876,15 @@ function removeControl(tr, span) {
12787
12876
  return tr;
12788
12877
  }
12789
12878
  var BLOCKS = /* @__PURE__ */ new Set(["paragraph", "table"]);
12790
- function continues(doc, inline, end, span) {
12791
- if (span.from === end) return true;
12792
- if (span.level === "inline") {
12793
- let at = end;
12794
- for (const other of inline) if (other.from === at && other.to <= span.from) at = other.to;
12795
- return at === span.from;
12796
- }
12797
- if (span.level !== "block") return false;
12798
- const $end = doc.resolve(end);
12799
- if (doc.resolve(span.from).parent !== $end.parent) return false;
12800
- let split = true;
12801
- $end.parent.forEach((node, offset) => {
12802
- const pos = $end.start() + offset;
12803
- if (pos < end || pos >= span.from || node.type.name !== "paragraph") return;
12804
- if (!node.attrs.contentControl) split = false;
12805
- });
12806
- return split;
12807
- }
12808
12879
  function temporaryControls(doc) {
12809
12880
  const spans = controlSpans(doc);
12810
12881
  const inline = spans.filter((span) => span.level === "inline");
12811
- const found = [];
12812
- const last = /* @__PURE__ */ new Map();
12813
- const candidates = [...spans, ...tableControlSpans(doc), ...rowControlSpans(doc)].sort(
12814
- (a, b) => a.from - b.from
12882
+ const candidates = [...spans, ...tableControlSpans(doc), ...rowControlSpans(doc)];
12883
+ return controlOccurrences(
12884
+ doc,
12885
+ candidates.filter((span) => removedByEdit(span.control)),
12886
+ inline
12815
12887
  );
12816
- for (const span of candidates) {
12817
- if (!removedByEdit(span.control)) continue;
12818
- const key = `${span.level}:${span.control.id}`;
12819
- const previous = last.get(key);
12820
- if (previous && continues(doc, inline, previous.to, span)) {
12821
- previous.spans.push(span);
12822
- previous.to = span.to;
12823
- continue;
12824
- }
12825
- const occurrence = { key, spans: [span], from: span.from, to: span.to };
12826
- found.push(occurrence);
12827
- last.set(key, occurrence);
12828
- }
12829
- return found;
12830
12888
  }
12831
12889
  function removeEditedTemporaryControls(transactions, before, after) {
12832
12890
  const local = transactions.filter(
@@ -12885,22 +12943,46 @@ function changesAttributesOnly(step, doc) {
12885
12943
  const next = slice.content.firstChild;
12886
12944
  return insert === 1 && gapFrom === from + 1 && gapTo === to - 1 && slice.openStart === 0 && slice.openEnd === 0 && slice.content.childCount === 1 && node !== null && next !== null && !node.isLeaf && next.content.size === 0 && node.nodeSize === to - from && next.type === node.type && sameControl(nodeControlOf(node)?.value, nodeControlOf(next)?.value);
12887
12945
  }
12888
- var isMarkOf = (mark, control) => mark.type.name === "contentControl" && sameControl(controlOfMark(mark), control);
12946
+ function sameId(left, right) {
12947
+ const id = left?.id;
12948
+ return typeof id === "string" && id === right?.id;
12949
+ }
12950
+ var isMarkOf = (mark, control, same2 = sameControl) => mark.type.name === "contentControl" && same2(controlOfMark(mark), control);
12951
+ function holdsControl(node, span, same2 = sameControl) {
12952
+ if (span.level === "inline") return node.marks.some((mark) => isMarkOf(mark, span.control, same2));
12953
+ const held = nodeControlOf(node);
12954
+ return held?.level === span.level && same2(held.value, span.control);
12955
+ }
12956
+ function putsBack(step, span, same2 = sameControl) {
12957
+ let found = false;
12958
+ if (step instanceof ReplaceStep)
12959
+ step.slice.content.descendants((node) => {
12960
+ found ||= holdsControl(node, span, same2);
12961
+ return !found;
12962
+ });
12963
+ return found;
12964
+ }
12889
12965
  function keepsControl(step, span) {
12890
12966
  if (step instanceof AddMarkStep)
12891
12967
  return span.level !== "inline" || step.mark.type.name !== "contentControl" || isMarkOf(step.mark, span.control);
12892
12968
  if (step instanceof RemoveMarkStep)
12893
12969
  return span.level !== "inline" || !isMarkOf(step.mark, span.control);
12894
- let kept = false;
12895
- if (span.level === "inline" && step instanceof ReplaceStep)
12896
- step.slice.content.descendants((node) => {
12897
- kept ||= node.marks.some((mark) => isMarkOf(mark, span.control));
12898
- return !kept;
12899
- });
12900
- return kept;
12970
+ return putsBack(step, span);
12971
+ }
12972
+ function lockedControls(doc) {
12973
+ const locked = everyControlSpan(doc).filter((span) => span.control.lock);
12974
+ const inline = locked.filter((span) => span.level === "inline");
12975
+ return [
12976
+ ...inline.map((span) => ({ key: "", spans: [span], from: span.from, to: span.to })),
12977
+ ...controlOccurrences(
12978
+ doc,
12979
+ locked.filter((span) => span.level !== "inline"),
12980
+ []
12981
+ )
12982
+ ];
12901
12983
  }
12902
12984
  function violatesControlLock(tr, state, history = false) {
12903
- const locked = everyControlSpan(state.doc).filter((span) => span.control.lock);
12985
+ const locked = lockedControls(state.doc);
12904
12986
  return tr.steps.some((step, index) => {
12905
12987
  const before = tr.mapping.slice(0, index);
12906
12988
  if (step instanceof AttrStep) {
@@ -12908,18 +12990,20 @@ function violatesControlLock(tr, state, history = false) {
12908
12990
  if (node && isContentControlLocked(inlineRunProperties(node).contentControl, "content"))
12909
12991
  return true;
12910
12992
  return locked.some(
12911
- (span) => isContentControlLocked(span.control, "content") && step.pos >= before.map(span.from, 1) && step.pos < before.map(span.to, -1)
12993
+ (occurrence) => isContentControlLocked(occurrence.spans[0].control, "content") && step.pos >= before.map(occurrence.from, 1) && step.pos < before.map(occurrence.to, -1)
12912
12994
  );
12913
12995
  }
12914
12996
  if (!locked.length || !isRangeStep(step)) return false;
12915
12997
  const { from, to } = step;
12916
12998
  const inserts = from === to;
12917
12999
  const kept = changesAttributesOnly(step, tr.docs[index]);
12918
- return locked.some((span) => {
12919
- const spanFrom = before.map(span.from, 1);
12920
- const spanTo = before.map(span.to, -1);
13000
+ return locked.some((occurrence) => {
13001
+ const span = occurrence.spans[0];
13002
+ const spanFrom = before.map(occurrence.from, 1);
13003
+ const spanTo = before.map(occurrence.to, -1);
12921
13004
  const removesWhole = !inserts && from <= spanFrom && to >= spanTo;
12922
13005
  const keeps = kept || keepsControl(step, span);
13006
+ if (removesWhole && !keeps && putsBack(step, span, sameId)) return true;
12923
13007
  if (isContentControlLocked(span.control, "control") && removesWhole && !keeps && !history)
12924
13008
  return true;
12925
13009
  if (!isContentControlLocked(span.control, "content") || removesWhole && !keeps)
@@ -16357,25 +16441,6 @@ function replacedBlanks(before, beforeResults, after, afterResults, mapping) {
16357
16441
  (space) => filled.some((result) => space.from >= result.from && space.to <= result.to)
16358
16442
  );
16359
16443
  }
16360
-
16361
- // docx/ui/form-field-guard.ts
16362
- var isRemote2 = (tr) => tr.getMeta("y-sync$") !== void 0;
16363
- var isHistory = (tr) => tr.getMeta("history$") !== void 0;
16364
- var isFormsProtected = (protection) => Boolean(protection?.enforced) && protection?.edit === "forms";
16365
- function exceedsFormTextLength(tr) {
16366
- const beforeResults = formTextResults(tr.before);
16367
- const afterResults = formTextResults(tr.doc);
16368
- const replaced = replacedBlanks(tr.before, beforeResults, tr.doc, afterResults, tr.mapping);
16369
- const length = (doc, result, removed = []) => isBlankFormText(doc, result) ? 0 : result.length - removed.filter((space) => space.from >= result.from && space.to <= result.to).length;
16370
- const before = new Map(
16371
- beforeResults.map((result) => [tr.mapping.map(result.begin), length(tr.before, result)])
16372
- );
16373
- return afterResults.some((result) => {
16374
- const max = result.field.textInput?.maxLength;
16375
- const now = length(tr.doc, result, replaced);
16376
- return Boolean(max) && now > max && now > (before.get(result.begin) ?? 0);
16377
- });
16378
- }
16379
16444
  function unprotectedSections(doc) {
16380
16445
  if (typeof doc.attrs.sections !== "string") return [];
16381
16446
  const sections2 = JSON.parse(doc.attrs.sections);
@@ -16428,14 +16493,92 @@ function renamesBlock(step, before, after) {
16428
16493
  )
16429
16494
  );
16430
16495
  }
16431
- function staysInFormFields(tr) {
16496
+ function inProtectedFormText(doc, from, to, free) {
16497
+ return formTextResults(doc).some(
16498
+ (result) => result.field.enabled !== false && from >= result.from && to <= result.to && !free.some((range) => result.from >= range.from && result.to <= range.to)
16499
+ );
16500
+ }
16501
+ function inFormatting(fragment, marks) {
16502
+ const children3 = [];
16503
+ fragment.forEach((node) => {
16504
+ if (node.isText) children3.push(node.mark(marks));
16505
+ else children3.push(node.isLeaf ? node : node.copy(inFormatting(node.content, marks)));
16506
+ });
16507
+ return Fragment.fromArray(children3);
16508
+ }
16509
+ function landingMarks(state) {
16510
+ const { $from, $to, empty } = state.selection;
16511
+ if (state.storedMarks) return state.storedMarks;
16512
+ if (!empty) return $from.marksAcross($to) ?? $from.marks();
16513
+ const after = $from.nodeAfter;
16514
+ return !$from.nodeBefore?.isText && after?.isText ? after.marks : $from.marks();
16515
+ }
16516
+ function pasteIntoFormText(view, slice, free) {
16517
+ const { state } = view;
16518
+ const { from, to } = state.selection;
16519
+ if (!slice.size || !inProtectedFormText(state.doc, from, to, free)) return false;
16520
+ const text2 = new Slice(
16521
+ inFormatting(slice.content, landingMarks(state)),
16522
+ slice.openStart,
16523
+ slice.openEnd
16524
+ );
16525
+ view.dispatch(
16526
+ state.tr.replaceSelection(text2).scrollIntoView().setMeta("paste", true).setMeta("uiEvent", "paste")
16527
+ );
16528
+ return true;
16529
+ }
16530
+ var formatting = (marks) => marks.filter((mark) => mark.type.name !== "field");
16531
+ function writesFormatting(step, doc, stored) {
16532
+ const $from = doc.resolve(step.from);
16533
+ const allowed = [...$from.marks(), ...stored ?? []];
16534
+ const around = [$from.nodeBefore, doc.resolve(step.to).nodeAfter];
16535
+ for (const node of around) if (node?.isText) allowed.push(...node.marks);
16536
+ doc.nodesBetween(step.from, step.to, (node) => {
16537
+ if (node.isText) allowed.push(...node.marks);
16538
+ });
16539
+ let found = false;
16540
+ step.slice.content.descendants((node) => {
16541
+ found ||= node.isText && formatting(node.marks).some((mark) => !mark.isInSet(allowed));
16542
+ return !found;
16543
+ });
16544
+ return found;
16545
+ }
16546
+ function storesFormatting(tr, free) {
16547
+ if (tr.docChanged || !tr.storedMarksSet || !tr.storedMarks) return false;
16548
+ const { from, to, $from } = tr.selection;
16549
+ if (Mark.sameSet(formatting(tr.storedMarks), formatting($from.marks()))) return false;
16550
+ return inProtectedFormText(tr.doc, from, to, free());
16551
+ }
16552
+
16553
+ // docx/ui/form-field-guard.ts
16554
+ var isRemote2 = (tr) => tr.getMeta("y-sync$") !== void 0;
16555
+ var isHistory = (tr) => tr.getMeta("history$") !== void 0;
16556
+ var isFormsProtected = (protection) => Boolean(protection?.enforced) && protection?.edit === "forms";
16557
+ function exceedsFormTextLength(tr) {
16558
+ const beforeResults = formTextResults(tr.before);
16559
+ const afterResults = formTextResults(tr.doc);
16560
+ const replaced = replacedBlanks(tr.before, beforeResults, tr.doc, afterResults, tr.mapping);
16561
+ const length = (doc, result, removed = []) => isBlankFormText(doc, result) ? 0 : result.length - removed.filter((space) => space.from >= result.from && space.to <= result.to).length;
16562
+ const before = new Map(
16563
+ beforeResults.map((result) => [tr.mapping.map(result.begin), length(tr.before, result)])
16564
+ );
16565
+ return afterResults.some((result) => {
16566
+ const max = result.field.textInput?.maxLength;
16567
+ const now = length(tr.doc, result, replaced);
16568
+ return Boolean(max) && now > max && now > (before.get(result.begin) ?? 0);
16569
+ });
16570
+ }
16571
+ function staysInFormFields(tr, kept) {
16432
16572
  const doc = tr.before;
16433
- const fields = [
16434
- ...formTextResults(doc).filter(({ field }) => field.enabled !== false).map(({ from, to }) => ({ from, to })),
16435
- ...controlSpans(doc).map(({ from, to }) => ({ from, to }))
16436
- ];
16573
+ const results = formTextResults(doc);
16574
+ const values = results.filter(({ field }) => field.enabled !== false);
16575
+ const fields = [...values, ...controlSpans(doc).map(({ from, to }) => ({ from, to }))];
16437
16576
  const sections2 = unprotectedSections(doc);
16438
- const fixed = formTextResults(doc).filter(({ field }) => field.enabled === false).map(({ begin, to }) => ({ from: begin, to: to + 1 })).filter((range) => !sections2.some((free) => range.from >= free.from && range.to <= free.to));
16577
+ const free = (range) => sections2.some((it) => range.from >= it.from && range.to <= it.to);
16578
+ const fixed = results.filter(({ field }) => field.enabled === false).map(({ begin, to }) => ({ from: begin, to: to + 1 })).filter((range) => !free(range));
16579
+ const plain = values.filter((range) => !free(range));
16580
+ const internal = isHistory(tr) || Boolean(tr.getMeta(FIELD_RESULT_REPAIR_META));
16581
+ const tracked = Boolean(tr.getMeta(trackChangesPluginKey));
16439
16582
  let sectionsAfter;
16440
16583
  return tr.steps.every((step, index) => {
16441
16584
  const after = tr.docs[index + 1] ?? tr.doc;
@@ -16450,16 +16593,23 @@ function staysInFormFields(tr) {
16450
16593
  if (!(step instanceof ReplaceStep || step instanceof ReplaceAroundStep || step instanceof AddMarkStep || step instanceof RemoveMarkStep))
16451
16594
  return false;
16452
16595
  const { from, to } = step;
16453
- const touchesFixed = (start2, end2) => fixed.some((range) => start2 < map.map(range.to, -1) && end2 > map.map(range.from, 1));
16454
- let changesFixed = (step instanceof AddMarkStep || step instanceof RemoveMarkStep) && touchesFixed(from, to);
16596
+ const touches = (ranges, start2, end2) => ranges.some((range) => start2 < map.map(range.to, -1) && end2 > map.map(range.from, 1));
16597
+ const marks = step instanceof AddMarkStep || step instanceof RemoveMarkStep;
16598
+ if (!internal && !tracked && (within2(plain, from, to) || touches(plain, from, to))) {
16599
+ if (marks) return false;
16600
+ const stored = kept && from === map.map(kept.at) ? kept.marks : null;
16601
+ if (step instanceof ReplaceStep && writesFormatting(step, tr.docs[index], stored))
16602
+ return false;
16603
+ }
16604
+ let changesFixed = marks && touches(fixed, from, to);
16455
16605
  step.getMap().forEach((start2, end2) => {
16456
- changesFixed ||= touchesFixed(start2, end2);
16606
+ changesFixed ||= touches(fixed, start2, end2);
16457
16607
  });
16458
16608
  if (changesFixed) return false;
16459
16609
  if (within2(fields, from, to))
16460
16610
  return !sections2.length || keepsSections(step, tr.docs[index], after);
16461
16611
  if (!within2(sections2, from, to)) return false;
16462
- if (step instanceof AddMarkStep || step instanceof RemoveMarkStep) return true;
16612
+ if (marks) return true;
16463
16613
  const rest = tr.mapping.slice(index + 1);
16464
16614
  const own2 = step.getMap();
16465
16615
  const start = rest.map(own2.map(from, -1), -1);
@@ -16494,12 +16644,20 @@ function formFieldGuardPlugin(protection) {
16494
16644
  init: (_config, state) => textFieldsOf(state.doc),
16495
16645
  apply: (tr, fields) => insertsFieldMarker(tr) ? textFieldsOf(tr.doc) : fields
16496
16646
  },
16647
+ props: {
16648
+ handlePaste: (view, _event, slice) => isFormsProtected(protection()) && pasteIntoFormText(view, slice, unprotectedSections(view.state.doc))
16649
+ },
16497
16650
  filterTransaction: (tr, state) => {
16651
+ if (isFormsProtected(protection()) && storesFormatting(tr, () => unprotectedSections(tr.doc)))
16652
+ return false;
16498
16653
  if (!tr.docChanged || isRemote2(tr)) return true;
16499
16654
  const limited = textFields.getState(state)?.limited || insertsFieldMarker(tr);
16500
16655
  if (limited && !isHistory(tr) && exceedsFormTextLength(tr)) return false;
16501
16656
  if (!isFormsProtected(protection())) return true;
16502
- return Boolean(tr.getMeta(CONTROL_EDIT_META) || tr.getMeta(FORM_FIELD_EDIT_META)) || staysInFormFields(tr);
16657
+ return Boolean(tr.getMeta(CONTROL_EDIT_META) || tr.getMeta(FORM_FIELD_EDIT_META)) || staysInFormFields(
16658
+ tr,
16659
+ state.storedMarks && { marks: state.storedMarks, at: state.selection.from }
16660
+ );
16503
16661
  },
16504
16662
  appendTransaction: (transactions, old, state) => {
16505
16663
  if (!transactions.some((tr2) => tr2.docChanged) || transactions.some(isRemote2)) return null;
@@ -9,7 +9,8 @@ export declare function placeTableControl(doc: XmlDocument, element: XmlElement,
9
9
  /**
10
10
  * Unwraps each `w:sdt` around `elements` (the rows of a table or the cells of a row, in place)
11
11
  * that the model takes off every one of them it holds: `next` is each element's control. The
12
- * rows or cells stay; a control the model keeps on any of them stays around all of them.
12
+ * rows or cells stay. One the model keeps on some of them stays around those: a row or cell it
13
+ * gives no control is taken out of it, as one given another control is.
13
14
  */
14
15
  export declare function unwrapDroppedControls(elements: readonly XmlElement[], next: readonly (ContentControl | undefined)[]): void;
15
16
  //# sourceMappingURL=write-table-controls.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"write-table-controls.d.ts","sourceRoot":"","sources":["../../docx/write-table-controls.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAQ9D,OAAO,EAA+B,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAgFvF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,IAAI,EAAE,cAAc,GAAG,SAAS,GAC9B,IAAI,CA2CN;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,SAAS,UAAU,EAAE,EAC/B,IAAI,EAAE,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC,EAAE,GAC3C,IAAI,CAON"}
1
+ {"version":3,"file":"write-table-controls.d.ts","sourceRoot":"","sources":["../../docx/write-table-controls.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,yBAAyB,CAAC;AAQ9D,OAAO,EAA+B,KAAK,WAAW,EAAE,KAAK,UAAU,EAAE,MAAM,OAAO,CAAC;AAwGvF;;;;GAIG;AACH,wBAAgB,iBAAiB,CAChC,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,UAAU,EACnB,IAAI,EAAE,cAAc,GAAG,SAAS,EAChC,IAAI,EAAE,cAAc,GAAG,SAAS,GAC9B,IAAI,CA4CN;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CACpC,QAAQ,EAAE,SAAS,UAAU,EAAE,EAC/B,IAAI,EAAE,SAAS,CAAC,cAAc,GAAG,SAAS,CAAC,EAAE,GAC3C,IAAI,CAWN"}
@@ -41934,7 +41934,7 @@ function toArrayBuffer(bytes) {
41934
41934
  if (bytes.byteOffset === 0 && bytes.byteLength === bytes.buffer.byteLength) {
41935
41935
  return bytes.buffer;
41936
41936
  }
41937
- return bytes.slice().buffer;
41937
+ return new Uint8Array(bytes).buffer;
41938
41938
  }
41939
41939
  function isCompoundFile(input2) {
41940
41940
  const bytes = toBytes(input2);
@@ -108217,7 +108217,7 @@ async function tiffToPicture(bytes) {
108217
108217
  try {
108218
108218
  const imported = await import('utif');
108219
108219
  const utif = "default" in imported ? imported.default : imported;
108220
- const buffer = bytes.slice().buffer;
108220
+ const buffer = new Uint8Array(bytes).buffer;
108221
108221
  const page = utif.decode(buffer)[0];
108222
108222
  if (!page) {
108223
108223
  return void 0;
@@ -148221,7 +148221,7 @@ async function inflateZlib(data) {
148221
148221
  return void 0;
148222
148222
  }
148223
148223
  try {
148224
- const stream = new Blob([data.slice().buffer]).stream().pipeThrough(new DecompressionStream("deflate"));
148224
+ const stream = new Blob([new Uint8Array(data).buffer]).stream().pipeThrough(new DecompressionStream("deflate"));
148225
148225
  const reader2 = stream.getReader();
148226
148226
  const chunks = [];
148227
148227
  let total = 0;
@@ -159642,7 +159642,7 @@ async function loadPresentation(filePath, execCtx) {
159642
159642
  return { pptxData, rawBytes };
159643
159643
  }
159644
159644
  function arrayBufferOf(bytes) {
159645
- return bytes.slice().buffer;
159645
+ return new Uint8Array(bytes).buffer;
159646
159646
  }
159647
159647
  async function saveDeckBytes(result, original) {
159648
159648
  const handler = new PptxHandler();
@@ -1363,7 +1363,10 @@ export declare function loadPresentation(filePath: string, execCtx: ExecutionCon
1363
1363
  pptxData: PptxData;
1364
1364
  rawBytes: Uint8Array;
1365
1365
  }>;
1366
- /** The bytes as a standalone ArrayBuffer (a view into a pooled buffer must not leak the rest). */
1366
+ /**
1367
+ * The bytes as a standalone ArrayBuffer (a view into a pooled buffer must not leak the rest). The copy
1368
+ * goes through the Uint8Array constructor because `slice()` on a Node Buffer is a view, not a copy.
1369
+ */
1367
1370
  export declare function arrayBufferOf(bytes: Uint8Array): ArrayBuffer;
1368
1371
  /**
1369
1372
  * Saves a deck a tool changed, loading the original first so package parts the model does not