wordinweb 0.1.4 → 0.1.6
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.
- package/dist/index.d.ts +8 -0
- package/dist/index.js +206 -40
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1598,6 +1598,14 @@ interface TextMeasurer {
|
|
|
1598
1598
|
ascent: number;
|
|
1599
1599
|
descent: number;
|
|
1600
1600
|
} | undefined;
|
|
1601
|
+
/** Ink extents (actualBoundingBox*) of `text` in the RESOLVED paint face,
|
|
1602
|
+
* px above/below the baseline. The radical join needs the √ glyph's real
|
|
1603
|
+
* ink — which face paints it (real Cambria Math vs the STIX substitute)
|
|
1604
|
+
* changes the extents, so a baked table can't cover both. */
|
|
1605
|
+
inkBox?(text: string, font: FontSpec): {
|
|
1606
|
+
ascent: number;
|
|
1607
|
+
descent: number;
|
|
1608
|
+
} | undefined;
|
|
1601
1609
|
}
|
|
1602
1610
|
|
|
1603
1611
|
interface LayoutOptions {
|
package/dist/index.js
CHANGED
|
@@ -5157,6 +5157,7 @@ var CanvasMeasurer = class {
|
|
|
5157
5157
|
this.widthCache = /* @__PURE__ */ new Map();
|
|
5158
5158
|
this.metricsCache = /* @__PURE__ */ new Map();
|
|
5159
5159
|
this.paintBoxCache = /* @__PURE__ */ new Map();
|
|
5160
|
+
this.inkBoxCache = /* @__PURE__ */ new Map();
|
|
5160
5161
|
this.currentFont = "";
|
|
5161
5162
|
if (typeof OffscreenCanvas !== "undefined") {
|
|
5162
5163
|
const c = new OffscreenCanvas(1, 1);
|
|
@@ -5200,6 +5201,18 @@ var CanvasMeasurer = class {
|
|
|
5200
5201
|
}
|
|
5201
5202
|
return m ?? void 0;
|
|
5202
5203
|
}
|
|
5204
|
+
/** Glyph ink extents at 3x (like width()) from the resolved paint face. */
|
|
5205
|
+
inkBox(text, font) {
|
|
5206
|
+
const key = "ink " + fontKey(font) + " " + text;
|
|
5207
|
+
let m = this.inkBoxCache.get(key);
|
|
5208
|
+
if (m === void 0) {
|
|
5209
|
+
this.setFont({ ...font, size: font.size * 3 });
|
|
5210
|
+
const tm = this.ctx.measureText(text);
|
|
5211
|
+
m = tm.actualBoundingBoxAscent !== void 0 && tm.actualBoundingBoxDescent !== void 0 ? { ascent: tm.actualBoundingBoxAscent / 3, descent: tm.actualBoundingBoxDescent / 3 } : null;
|
|
5212
|
+
this.inkBoxCache.set(key, m);
|
|
5213
|
+
}
|
|
5214
|
+
return m ?? void 0;
|
|
5215
|
+
}
|
|
5203
5216
|
metrics(font) {
|
|
5204
5217
|
const key = fontKey(font);
|
|
5205
5218
|
let m = this.metricsCache.get(key);
|
|
@@ -5853,14 +5866,12 @@ function flow(nodes, size, dy, box, measurer, tight, display = false, breakDepth
|
|
|
5853
5866
|
for (const r of degBox.rules) box.rules.push({ ...r, x1: box.width + r.x1, x2: box.width + r.x2, dy: degDy + r.dy });
|
|
5854
5867
|
box.width += degBox.width + size * RAD_KERN_AFTER_DEG;
|
|
5855
5868
|
}
|
|
5856
|
-
|
|
5857
|
-
|
|
5858
|
-
|
|
5859
|
-
|
|
5860
|
-
|
|
5861
|
-
|
|
5862
|
-
signAnchor = (-size * RAD_GROWN_FOOT - inkBotNat * grow) / (1 - grow);
|
|
5863
|
-
}
|
|
5869
|
+
const signInk = measurer.inkBox?.("\u221A", font);
|
|
5870
|
+
const inkTopNat = signInk ? signInk.ascent : size * RAD_VARIANTS[0].top / 2048;
|
|
5871
|
+
const inkBotNat = signInk ? -signInk.descent : size * RAD_VARIANTS[0].bot / 2048;
|
|
5872
|
+
const signFoot = nestedGrown ? size * RAD_GROWN_FOOT : signDesc;
|
|
5873
|
+
const grow = (paintRuleTop + signFoot) / (inkTopNat - inkBotNat);
|
|
5874
|
+
const signAnchor = grow === 1 ? 0 : (-signFoot - inkBotNat * grow) / (1 - grow);
|
|
5864
5875
|
const topLevelDisplay = display && breakDepth === 0 && complexRad;
|
|
5865
5876
|
const signW = measurer.width("\u221A", font);
|
|
5866
5877
|
box.pieces.push({
|
|
@@ -16310,9 +16321,11 @@ function linearizeMath(nodes) {
|
|
|
16310
16321
|
case "frac":
|
|
16311
16322
|
out += group(n.num) + "/" + group(n.den);
|
|
16312
16323
|
break;
|
|
16313
|
-
case "rad":
|
|
16314
|
-
|
|
16324
|
+
case "rad": {
|
|
16325
|
+
const deg = n.deg && n.deg.length ? linearizeMath(n.deg) : "";
|
|
16326
|
+
out += deg ? "\u221A[" + deg + "]" + group(n.e) : "\u221A" + group(n.e);
|
|
16315
16327
|
break;
|
|
16328
|
+
}
|
|
16316
16329
|
case "nary":
|
|
16317
16330
|
out += n.chr + (n.sub.length ? "_" + group(n.sub) : "") + (n.sup.length ? "^" + group(n.sup) : "") + group(n.e);
|
|
16318
16331
|
break;
|
|
@@ -16442,10 +16455,12 @@ function parseMathLinear(input) {
|
|
|
16442
16455
|
const parseUnit = () => {
|
|
16443
16456
|
const ch = input[i];
|
|
16444
16457
|
if (ch === "{") return parseGroup();
|
|
16445
|
-
if (ch === "\u221A") {
|
|
16458
|
+
if (ch === "\u221A" || ch === "\u221B" || ch === "\u221C") {
|
|
16446
16459
|
i++;
|
|
16460
|
+
let deg = ch === "\u221B" ? [{ t: "run", text: "3" }] : ch === "\u221C" ? [{ t: "run", text: "4" }] : [];
|
|
16461
|
+
if (ch === "\u221A" && input[i] === "[") deg = parseMathLinear(scanDelim("[", "]"));
|
|
16447
16462
|
const e = input[i] === "{" ? parseGroup() : parseUnit();
|
|
16448
|
-
return [{ t: "rad", e }];
|
|
16463
|
+
return deg.length ? [{ t: "rad", e, deg }] : [{ t: "rad", e }];
|
|
16449
16464
|
}
|
|
16450
16465
|
if (NARY_CHRS.has(ch)) return parseNary();
|
|
16451
16466
|
if (ch in DELIM_CLOSE) return parseDelim(ch);
|
|
@@ -16631,7 +16646,11 @@ function ommlToNodes(e) {
|
|
|
16631
16646
|
}
|
|
16632
16647
|
if (ln === "sSup") return [{ t: "sup", base: kids("e"), script: kids("sup") }];
|
|
16633
16648
|
if (ln === "sSub") return [{ t: "sub", base: kids("e"), script: kids("sub") }];
|
|
16634
|
-
if (ln === "rad")
|
|
16649
|
+
if (ln === "rad") {
|
|
16650
|
+
const hide = chrAttr("radPr", "degHide", "0");
|
|
16651
|
+
const deg = hide === "1" || hide === "true" || hide === "on" ? [] : kids("deg");
|
|
16652
|
+
return deg.length ? [{ t: "rad", e: kids("e"), deg }] : [{ t: "rad", e: kids("e") }];
|
|
16653
|
+
}
|
|
16635
16654
|
if (ln === "t") return e.text ? [{ t: "run", text: e.text }] : [];
|
|
16636
16655
|
const out = [];
|
|
16637
16656
|
for (const c of e.children) {
|
|
@@ -16663,9 +16682,11 @@ function sameStructure(a, b) {
|
|
|
16663
16682
|
case "frac":
|
|
16664
16683
|
if (!sameStructure(x.num, y.num) || !sameStructure(x.den, y.den)) return false;
|
|
16665
16684
|
break;
|
|
16666
|
-
case "rad":
|
|
16667
|
-
|
|
16685
|
+
case "rad": {
|
|
16686
|
+
const yy = y;
|
|
16687
|
+
if (!sameStructure(x.e, yy.e) || !sameStructure(x.deg ?? [], yy.deg ?? [])) return false;
|
|
16668
16688
|
break;
|
|
16689
|
+
}
|
|
16669
16690
|
case "nary": {
|
|
16670
16691
|
const yy = y;
|
|
16671
16692
|
if (x.chr !== yy.chr || !sameStructure(x.sub, yy.sub) || !sameStructure(x.sup, yy.sup) || !sameStructure(x.e, yy.e))
|
|
@@ -17563,6 +17584,33 @@ function deepTextNode(el11) {
|
|
|
17563
17584
|
while (n && n.nodeType !== Node.TEXT_NODE) n = n.firstChild;
|
|
17564
17585
|
return n;
|
|
17565
17586
|
}
|
|
17587
|
+
function textElements(el11) {
|
|
17588
|
+
const out = [];
|
|
17589
|
+
const walk = (node) => {
|
|
17590
|
+
if (localName(node.name) === "t") out.push(node);
|
|
17591
|
+
for (const child3 of node.children) walk(child3);
|
|
17592
|
+
};
|
|
17593
|
+
walk(el11);
|
|
17594
|
+
return out;
|
|
17595
|
+
}
|
|
17596
|
+
function emptyParagraphLike(el11) {
|
|
17597
|
+
const prefix = el11.name.includes(":") ? el11.name.slice(0, el11.name.indexOf(":") + 1) : "";
|
|
17598
|
+
const text = {
|
|
17599
|
+
name: `${prefix}t`,
|
|
17600
|
+
attrs: { "xml:space": "preserve" },
|
|
17601
|
+
children: [],
|
|
17602
|
+
text: ""
|
|
17603
|
+
};
|
|
17604
|
+
return {
|
|
17605
|
+
paragraph: {
|
|
17606
|
+
name: `${prefix}p`,
|
|
17607
|
+
attrs: {},
|
|
17608
|
+
children: [{ name: `${prefix}r`, attrs: {}, children: [text], text: "" }],
|
|
17609
|
+
text: ""
|
|
17610
|
+
},
|
|
17611
|
+
text
|
|
17612
|
+
};
|
|
17613
|
+
}
|
|
17566
17614
|
var _DocxEditor = class _DocxEditor {
|
|
17567
17615
|
constructor(host) {
|
|
17568
17616
|
this.host = host;
|
|
@@ -17576,7 +17624,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
17576
17624
|
* our own highlight, which kills the flicker and survives toolbar focus). */
|
|
17577
17625
|
this.selection = null;
|
|
17578
17626
|
this.selectionRects = [];
|
|
17579
|
-
this.
|
|
17627
|
+
this.selectedAll = false;
|
|
17580
17628
|
/** True while a drag-selection is in progress (checked by onMouseUp, which
|
|
17581
17629
|
* bubbles from the container BEFORE the document-level drag-end listener). */
|
|
17582
17630
|
this.dragSelecting = false;
|
|
@@ -18106,11 +18154,8 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18106
18154
|
}
|
|
18107
18155
|
clearSelection() {
|
|
18108
18156
|
this.selection = null;
|
|
18157
|
+
this.selectedAll = false;
|
|
18109
18158
|
this.paintSelection();
|
|
18110
|
-
const restore = this.restoreSelectAllPages;
|
|
18111
|
-
this.restoreSelectAllPages = null;
|
|
18112
|
-
restore?.();
|
|
18113
|
-
this.host.getHandle()?.updateViewport?.();
|
|
18114
18159
|
this.notifySelection();
|
|
18115
18160
|
}
|
|
18116
18161
|
notifySelection() {
|
|
@@ -18131,11 +18176,50 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18131
18176
|
}
|
|
18132
18177
|
return boundary;
|
|
18133
18178
|
}
|
|
18179
|
+
activeTextItems() {
|
|
18180
|
+
const handle = this.host.getHandle();
|
|
18181
|
+
if (!handle) return [];
|
|
18182
|
+
const activeTexts = /* @__PURE__ */ new Set();
|
|
18183
|
+
const collect = (element) => {
|
|
18184
|
+
if (localName(element.name) === "t") activeTexts.add(element);
|
|
18185
|
+
for (const child3 of element.children) collect(child3);
|
|
18186
|
+
};
|
|
18187
|
+
for (const root of this.host.doc.editableRoots()) {
|
|
18188
|
+
const name = localName(root.name);
|
|
18189
|
+
const headerFooter = name === "hdr" || name === "ftr";
|
|
18190
|
+
if (headerFooter === this.inHeaderFooter) collect(root);
|
|
18191
|
+
}
|
|
18192
|
+
const items = handle._pages ? handle._pages.flatMap((page) => page.page.items) : handle.bindings.map((binding) => binding.item);
|
|
18193
|
+
return items.filter(
|
|
18194
|
+
(item) => item.kind === "text" && !!item.src?.t && activeTexts.has(item.src.t)
|
|
18195
|
+
);
|
|
18196
|
+
}
|
|
18134
18197
|
/** Segments covered by the owned selection, in document paint order. */
|
|
18135
18198
|
getSelectionSegments() {
|
|
18136
18199
|
const sel = this.selection;
|
|
18137
18200
|
const handle = this.host.getHandle();
|
|
18138
18201
|
if (!sel || !handle) return [];
|
|
18202
|
+
if (this.selectedAll) {
|
|
18203
|
+
const segments2 = [];
|
|
18204
|
+
for (const item of this.activeTextItems()) {
|
|
18205
|
+
const src = item.src;
|
|
18206
|
+
if (item.text.length === 0) continue;
|
|
18207
|
+
const segment = {
|
|
18208
|
+
run: src.run,
|
|
18209
|
+
t: src.t,
|
|
18210
|
+
start: src.offset,
|
|
18211
|
+
end: src.offset + item.text.length,
|
|
18212
|
+
props: item.props
|
|
18213
|
+
};
|
|
18214
|
+
const previous = segments2[segments2.length - 1];
|
|
18215
|
+
if (previous && previous.t === segment.t && segment.start <= previous.end + 1) {
|
|
18216
|
+
previous.end = Math.max(previous.end, segment.end);
|
|
18217
|
+
} else {
|
|
18218
|
+
segments2.push(segment);
|
|
18219
|
+
}
|
|
18220
|
+
}
|
|
18221
|
+
return segments2;
|
|
18222
|
+
}
|
|
18139
18223
|
let a = this.pointIndex(sel.anchor);
|
|
18140
18224
|
let f = this.pointIndex(sel.focus);
|
|
18141
18225
|
if (a === null || f === null) return [];
|
|
@@ -18303,6 +18387,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18303
18387
|
return;
|
|
18304
18388
|
}
|
|
18305
18389
|
this.hideCaret();
|
|
18390
|
+
this.selectedAll = false;
|
|
18306
18391
|
this.selection = { anchor, focus };
|
|
18307
18392
|
this.paintSelection();
|
|
18308
18393
|
this.notifySelection();
|
|
@@ -18323,21 +18408,16 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18323
18408
|
}
|
|
18324
18409
|
}
|
|
18325
18410
|
selectAll() {
|
|
18326
|
-
const
|
|
18327
|
-
if (!handle) return;
|
|
18328
|
-
if (handle._virtualized && !this.restoreSelectAllPages) {
|
|
18329
|
-
this.restoreSelectAllPages = handle.materializeAll?.() ?? null;
|
|
18330
|
-
}
|
|
18331
|
-
const editable = handle.bindings.filter(
|
|
18332
|
-
(b) => b.item.src?.t && this.regionOf(b.item.src.t) === (this.inHeaderFooter ? "hf" : "body")
|
|
18333
|
-
);
|
|
18411
|
+
const editable = this.activeTextItems();
|
|
18334
18412
|
if (editable.length === 0) return;
|
|
18335
|
-
const first = editable[0].
|
|
18336
|
-
const
|
|
18413
|
+
const first = editable[0].src;
|
|
18414
|
+
const lastItem = editable[editable.length - 1];
|
|
18415
|
+
const last = lastItem.src;
|
|
18337
18416
|
this.hideCaret();
|
|
18417
|
+
this.selectedAll = true;
|
|
18338
18418
|
this.selection = {
|
|
18339
18419
|
anchor: { t: first.t, offset: first.offset },
|
|
18340
|
-
focus: { t: last.t, offset: last.offset +
|
|
18420
|
+
focus: { t: last.t, offset: last.offset + lastItem.text.length }
|
|
18341
18421
|
};
|
|
18342
18422
|
this.paintSelection();
|
|
18343
18423
|
this.notifySelection();
|
|
@@ -18345,6 +18425,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18345
18425
|
/** Select the given post-edit ranges (used after formatting to persist). */
|
|
18346
18426
|
selectRanges(ranges) {
|
|
18347
18427
|
if (ranges.length === 0) return;
|
|
18428
|
+
this.selectedAll = false;
|
|
18348
18429
|
const first = ranges[0];
|
|
18349
18430
|
const last = ranges[ranges.length - 1];
|
|
18350
18431
|
this.selection = {
|
|
@@ -18360,10 +18441,19 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18360
18441
|
const sel = this.selection;
|
|
18361
18442
|
const handle = this.host.getHandle();
|
|
18362
18443
|
if (!sel || !handle) return;
|
|
18363
|
-
|
|
18364
|
-
|
|
18444
|
+
const activeTexts = this.selectedAll ? new Set(this.activeTextItems().map((item) => item.src.t)) : null;
|
|
18445
|
+
const bindings = activeTexts ? handle.bindings.filter((binding) => !!binding.item.src?.t && activeTexts.has(binding.item.src.t)) : handle.bindings;
|
|
18446
|
+
if (bindings.length === 0) return;
|
|
18447
|
+
let a = this.selectedAll ? 0 : this.pointIndex(sel.anchor);
|
|
18448
|
+
let f = this.selectedAll ? (bindings.length - 1) * 1e6 + bindings[bindings.length - 1].item.text.length : this.pointIndex(sel.focus);
|
|
18365
18449
|
if (a === null || f === null) return;
|
|
18366
|
-
const [startPt, endPt] =
|
|
18450
|
+
const [startPt, endPt] = this.selectedAll ? [
|
|
18451
|
+
{ t: bindings[0].item.src.t, offset: bindings[0].item.src.offset },
|
|
18452
|
+
{
|
|
18453
|
+
t: bindings[bindings.length - 1].item.src.t,
|
|
18454
|
+
offset: bindings[bindings.length - 1].item.src.offset + bindings[bindings.length - 1].item.text.length
|
|
18455
|
+
}
|
|
18456
|
+
] : a <= f ? [sel.anchor, sel.focus] : [sel.focus, sel.anchor];
|
|
18367
18457
|
if (a > f) [a, f] = [f, a];
|
|
18368
18458
|
const startIdx = Math.floor(a / 1e6);
|
|
18369
18459
|
const endIdx = Math.floor(f / 1e6);
|
|
@@ -18378,7 +18468,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18378
18468
|
run = null;
|
|
18379
18469
|
};
|
|
18380
18470
|
for (let i = startIdx; i <= endIdx; i++) {
|
|
18381
|
-
const b =
|
|
18471
|
+
const b = bindings[i];
|
|
18382
18472
|
const item = b.item;
|
|
18383
18473
|
const src = item.src;
|
|
18384
18474
|
if (!src?.t) continue;
|
|
@@ -18516,8 +18606,6 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18516
18606
|
c.removeEventListener("dragover", this.onDragOver);
|
|
18517
18607
|
c.removeEventListener("drop", this.onDrop);
|
|
18518
18608
|
this.dismissSuggestionPopover();
|
|
18519
|
-
this.restoreSelectAllPages?.();
|
|
18520
|
-
this.restoreSelectAllPages = null;
|
|
18521
18609
|
this.hideCaret();
|
|
18522
18610
|
}
|
|
18523
18611
|
// ---------- clipboard ----------
|
|
@@ -18651,6 +18739,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18651
18739
|
}
|
|
18652
18740
|
if (dragging) {
|
|
18653
18741
|
this.hideCaret();
|
|
18742
|
+
this.selectedAll = false;
|
|
18654
18743
|
this.selection = {
|
|
18655
18744
|
anchor: { t: anchor.t, offset: anchor.offset },
|
|
18656
18745
|
focus: { t: focus.t, offset: focus.offset }
|
|
@@ -18682,6 +18771,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18682
18771
|
const last = lastTextOf(pEl);
|
|
18683
18772
|
if (!first || !last) return;
|
|
18684
18773
|
this.hideCaret();
|
|
18774
|
+
this.selectedAll = false;
|
|
18685
18775
|
this.selection = {
|
|
18686
18776
|
anchor: { t: first, offset: 0 },
|
|
18687
18777
|
focus: { t: last, offset: last.text.length }
|
|
@@ -18699,6 +18789,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
18699
18789
|
while (e < text.length && isWord(text[e])) e++;
|
|
18700
18790
|
if (e > s) {
|
|
18701
18791
|
this.hideCaret();
|
|
18792
|
+
this.selectedAll = false;
|
|
18702
18793
|
this.selection = { anchor: { t: caret.t, offset: s }, focus: { t: caret.t, offset: e } };
|
|
18703
18794
|
this.paintSelection();
|
|
18704
18795
|
this.notifySelection();
|
|
@@ -19606,7 +19697,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
19606
19697
|
row.style.cssText = "display:flex;gap:6px;align-items:center;";
|
|
19607
19698
|
const input = document.createElement("input");
|
|
19608
19699
|
input.value = original;
|
|
19609
|
-
input.title = "Linear math: x^2, x_i, {a+b}/{2}, \u221A{x}";
|
|
19700
|
+
input.title = "Linear math: x^2, x_i, {a+b}/{2}, \u221A{x}, \u221A[n]{x}";
|
|
19610
19701
|
input.style.cssText = "width:260px;border:1px solid #dadce0;border-radius:6px;padding:5px 8px;outline:none;font:14px 'Cambria Math','STIX Two Math',serif;transition:border-color .12s,background .12s;";
|
|
19611
19702
|
const caption = document.createElement("div");
|
|
19612
19703
|
caption.style.cssText = "font:11px system-ui,sans-serif;color:#5f6368;max-width:300px;";
|
|
@@ -19629,7 +19720,7 @@ var _DocxEditor = class _DocxEditor {
|
|
|
19629
19720
|
}
|
|
19630
19721
|
});
|
|
19631
19722
|
} else {
|
|
19632
|
-
caption.textContent = "Linear math: x^2, x_i, {a+b}/{2}, \u221A{x}. Enter to apply.";
|
|
19723
|
+
caption.textContent = "Linear math: x^2, x_i, {a+b}/{2}, \u221A{x}, \u221A[n]{x}. Enter to apply.";
|
|
19633
19724
|
const apply = document.createElement("button");
|
|
19634
19725
|
apply.textContent = "Apply";
|
|
19635
19726
|
apply.style.cssText = "border:1px solid #dadce0;border-radius:14px;padding:3px 12px;cursor:pointer;background:#1a73e8;color:#fff;";
|
|
@@ -20081,9 +20172,10 @@ var _DocxEditor = class _DocxEditor {
|
|
|
20081
20172
|
}
|
|
20082
20173
|
deleteContents(direction) {
|
|
20083
20174
|
if (direction === void 0) {
|
|
20175
|
+
const selectedAll = this.selectedAll;
|
|
20084
20176
|
this.host.history?.checkpoint();
|
|
20085
20177
|
this.removeSelectedText();
|
|
20086
|
-
this.commit();
|
|
20178
|
+
this.commit(false, selectedAll ? "global" : "local");
|
|
20087
20179
|
return;
|
|
20088
20180
|
}
|
|
20089
20181
|
const caret = this.caret;
|
|
@@ -20196,6 +20288,24 @@ var _DocxEditor = class _DocxEditor {
|
|
|
20196
20288
|
}
|
|
20197
20289
|
/** Delete the owned selection's text from the XML; caret → start. */
|
|
20198
20290
|
removeSelectedText() {
|
|
20291
|
+
if (this.selectedAll && !this.inHeaderFooter && !this.suggesting) {
|
|
20292
|
+
const root = this.host.doc.editableRoots()[0];
|
|
20293
|
+
const body = localName(root.name) === "body" ? root : root.children.find((child3) => localName(child3.name) === "body");
|
|
20294
|
+
if (body) {
|
|
20295
|
+
const empty = emptyParagraphLike(body);
|
|
20296
|
+
const sectionProperties = body.children.filter(
|
|
20297
|
+
(child3) => localName(child3.name) === "sectPr"
|
|
20298
|
+
);
|
|
20299
|
+
body.children = [empty.paragraph, ...sectionProperties];
|
|
20300
|
+
this.clearSelection();
|
|
20301
|
+
this.caret = {
|
|
20302
|
+
t: empty.text,
|
|
20303
|
+
run: { type: "run", props: {}, content: [] },
|
|
20304
|
+
offset: 0
|
|
20305
|
+
};
|
|
20306
|
+
return;
|
|
20307
|
+
}
|
|
20308
|
+
}
|
|
20199
20309
|
const segments = this.getSelectionSegments();
|
|
20200
20310
|
if (this.suggesting) {
|
|
20201
20311
|
const ranges = segments.filter((s) => s.t).map((s) => ({ t: s.t, start: s.start, end: s.end }));
|
|
@@ -20215,12 +20325,68 @@ var _DocxEditor = class _DocxEditor {
|
|
|
20215
20325
|
list.push({ start: seg.start, end: seg.end });
|
|
20216
20326
|
byT.set(t, list);
|
|
20217
20327
|
}
|
|
20328
|
+
const fullySelected = /* @__PURE__ */ new Set();
|
|
20329
|
+
for (const [t, ranges] of byT) {
|
|
20330
|
+
const ordered = [...ranges].sort((a, b) => a.start - b.start);
|
|
20331
|
+
let end = 0;
|
|
20332
|
+
for (const range of ordered) {
|
|
20333
|
+
if (range.start > end) break;
|
|
20334
|
+
end = Math.max(end, range.end);
|
|
20335
|
+
}
|
|
20336
|
+
if (end >= t.text.length) fullySelected.add(t);
|
|
20337
|
+
}
|
|
20338
|
+
const paragraphs = /* @__PURE__ */ new Set();
|
|
20339
|
+
for (const t of fullySelected) {
|
|
20340
|
+
const paragraph = paragraphOf(this.host.doc, t);
|
|
20341
|
+
if (paragraph) paragraphs.add(paragraph);
|
|
20342
|
+
}
|
|
20343
|
+
const fullySelectedParagraphs = [...paragraphs].filter((paragraph) => {
|
|
20344
|
+
const texts = textElements(paragraph).filter((text) => text.text.length > 0);
|
|
20345
|
+
return texts.length > 0 && texts.every((text) => fullySelected.has(text));
|
|
20346
|
+
});
|
|
20347
|
+
const fullySelectedTables = /* @__PURE__ */ new Set();
|
|
20348
|
+
for (const paragraph of fullySelectedParagraphs) {
|
|
20349
|
+
const paragraphProperties = paragraph.children.find(
|
|
20350
|
+
(child3) => localName(child3.name) === "pPr"
|
|
20351
|
+
);
|
|
20352
|
+
const paragraphTexts = textElements(paragraph).filter((text) => text.text.length > 0);
|
|
20353
|
+
const style = paragraphProperties?.children.find((child3) => localName(child3.name) === "pStyle");
|
|
20354
|
+
const styleNumbering = resolveParagraphStyleChain(
|
|
20355
|
+
this.host.doc.styles,
|
|
20356
|
+
attr(style, "val"),
|
|
20357
|
+
false
|
|
20358
|
+
).pPr.numbering;
|
|
20359
|
+
const isList = paragraphTexts.some((text) => listTypeAt(this.host.doc, text)) || !!styleNumbering;
|
|
20360
|
+
if (paragraphProperties && isList) {
|
|
20361
|
+
paragraphProperties.children = paragraphProperties.children.filter(
|
|
20362
|
+
(child3) => localName(child3.name) !== "numPr" && localName(child3.name) !== "pStyle"
|
|
20363
|
+
);
|
|
20364
|
+
}
|
|
20365
|
+
let ancestor = this.host.doc.findParentOf(paragraph);
|
|
20366
|
+
while (ancestor && localName(ancestor.name) !== "tbl") {
|
|
20367
|
+
ancestor = this.host.doc.findParentOf(ancestor);
|
|
20368
|
+
}
|
|
20369
|
+
if (!ancestor) continue;
|
|
20370
|
+
const tableTexts = textElements(ancestor).filter((text) => text.text.length > 0);
|
|
20371
|
+
if (tableTexts.length > 0 && tableTexts.every((text) => fullySelected.has(text))) {
|
|
20372
|
+
fullySelectedTables.add(ancestor);
|
|
20373
|
+
}
|
|
20374
|
+
}
|
|
20218
20375
|
for (const [t, ranges] of byT) {
|
|
20219
20376
|
ranges.sort((a, b) => b.start - a.start);
|
|
20220
20377
|
for (const r of ranges) {
|
|
20221
20378
|
t.text = t.text.slice(0, r.start) + t.text.slice(r.end);
|
|
20222
20379
|
}
|
|
20223
20380
|
}
|
|
20381
|
+
for (const table2 of fullySelectedTables) {
|
|
20382
|
+
const parent = this.host.doc.findParentOf(table2);
|
|
20383
|
+
if (!parent) continue;
|
|
20384
|
+
const empty = emptyParagraphLike(table2);
|
|
20385
|
+
parent.children.splice(parent.children.indexOf(table2), 1, empty.paragraph);
|
|
20386
|
+
if (first && textElements(table2).includes(first.t)) {
|
|
20387
|
+
first = { t: empty.text, run: first.run, offset: 0 };
|
|
20388
|
+
}
|
|
20389
|
+
}
|
|
20224
20390
|
this.clearSelection();
|
|
20225
20391
|
if (first) this.caret = first;
|
|
20226
20392
|
}
|