@pixerate/editor 0.43.0 → 0.45.0
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/README.md +27 -2
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/agent/index.cjs +548 -45
- package/dist/agent/index.cjs.map +1 -1
- package/dist/agent/index.d.cts +47 -17
- package/dist/agent/index.d.ts +47 -17
- package/dist/agent/index.js +536 -33
- package/dist/agent/index.js.map +1 -1
- package/dist/{builtins-BLud97fC.d.cts → builtins-CZW-aYKS.d.cts} +1 -1
- package/dist/{builtins-D0BDyAgw.d.ts → builtins-DghNQbT-.d.ts} +1 -1
- package/dist/{chunk-I6BZB5ZH.cjs → chunk-EFDCLENW.cjs} +73 -6
- package/dist/chunk-EFDCLENW.cjs.map +1 -0
- package/dist/chunk-HHQ4XJWT.js +826 -0
- package/dist/chunk-HHQ4XJWT.js.map +1 -0
- package/dist/chunk-J3R2OWOE.cjs +1465 -0
- package/dist/chunk-J3R2OWOE.cjs.map +1 -0
- package/dist/chunk-K2LVZ4FA.cjs +826 -0
- package/dist/chunk-K2LVZ4FA.cjs.map +1 -0
- package/dist/{chunk-6MDQKHRH.cjs → chunk-N4MLNJPO.cjs} +21 -899
- package/dist/chunk-N4MLNJPO.cjs.map +1 -0
- package/dist/chunk-PQM5W7ZN.js +168 -0
- package/dist/chunk-PQM5W7ZN.js.map +1 -0
- package/dist/{chunk-DDADOHJW.js → chunk-Q25ZS4F7.js} +5 -883
- package/dist/chunk-Q25ZS4F7.js.map +1 -0
- package/dist/chunk-TK2XZK6Z.js +1465 -0
- package/dist/chunk-TK2XZK6Z.js.map +1 -0
- package/dist/commands/index.cjs +3 -2
- package/dist/commands/index.cjs.map +1 -1
- package/dist/commands/index.d.cts +5 -5
- package/dist/commands/index.d.ts +5 -5
- package/dist/commands/index.js +2 -1
- package/dist/commands/index.js.map +1 -1
- package/dist/extensions/index.cjs +4 -4
- package/dist/extensions/index.cjs.map +1 -1
- package/dist/extensions/index.d.cts +3 -3
- package/dist/extensions/index.d.ts +3 -3
- package/dist/extensions/index.js +12 -12
- package/dist/generation/index.cjs +2 -2
- package/dist/generation/index.d.cts +4 -4
- package/dist/generation/index.d.ts +4 -4
- package/dist/generation/index.js +1 -1
- package/dist/image-editor/index.cjs +24 -24
- package/dist/image-editor/index.cjs.map +1 -1
- package/dist/image-editor/index.d.cts +2 -2
- package/dist/image-editor/index.d.ts +2 -2
- package/dist/image-editor/index.js +24 -24
- package/dist/image-editor/index.js.map +1 -1
- package/dist/{index-C6gaQRH0.d.cts → index-CfOQf70b.d.cts} +1 -1
- package/dist/{index-DXAv_R08.d.ts → index-jwJ_onWf.d.ts} +1 -1
- package/dist/index.cjs +9 -9
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +4 -4
- package/dist/index.d.ts +4 -4
- package/dist/index.js +12 -12
- package/dist/parameters/index.d.cts +2 -2
- package/dist/parameters/index.d.ts +2 -2
- package/dist/{registry-DnzpgY27.d.cts → registry-B4l-lYts.d.cts} +1 -1
- package/dist/{registry-DhVUZioj.d.ts → registry-BfVD-vVg.d.ts} +1 -1
- package/dist/{registry-BDe-vlv3.d.ts → registry-CSlH4iUn.d.ts} +1 -1
- package/dist/{registry-D0GADKc7.d.cts → registry-vz6HOiiy.d.cts} +1 -1
- package/dist/{schema-DYDGdYL9.d.cts → schema-Di0CS6Pe.d.cts} +26 -2
- package/dist/{schema-DYDGdYL9.d.ts → schema-Di0CS6Pe.d.ts} +26 -2
- package/dist/tools/index.cjs +37 -3
- package/dist/tools/index.cjs.map +1 -1
- package/dist/tools/index.d.cts +871 -11
- package/dist/tools/index.d.ts +871 -11
- package/dist/tools/index.js +36 -2
- package/dist/vector/index.cjs +1982 -301
- package/dist/vector/index.cjs.map +1 -1
- package/dist/vector/index.d.cts +624 -154
- package/dist/vector/index.d.ts +624 -154
- package/dist/vector/index.js +1755 -74
- package/dist/vector/index.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-36BLROHV.js +0 -438
- package/dist/chunk-36BLROHV.js.map +0 -1
- package/dist/chunk-5H2OPMXZ.js +0 -586
- package/dist/chunk-5H2OPMXZ.js.map +0 -1
- package/dist/chunk-6MDQKHRH.cjs.map +0 -1
- package/dist/chunk-D6S5M7HV.js +0 -101
- package/dist/chunk-D6S5M7HV.js.map +0 -1
- package/dist/chunk-DDADOHJW.js.map +0 -1
- package/dist/chunk-I6BZB5ZH.cjs.map +0 -1
- package/dist/chunk-MC2LQN5S.cjs +0 -586
- package/dist/chunk-MC2LQN5S.cjs.map +0 -1
- package/dist/chunk-V7CC7RZ6.cjs +0 -438
- package/dist/chunk-V7CC7RZ6.cjs.map +0 -1
|
@@ -9,6 +9,8 @@ import {
|
|
|
9
9
|
MAX_TABLE_COLUMNS,
|
|
10
10
|
MAX_TABLE_ROWS,
|
|
11
11
|
TABLE_ACTIONS,
|
|
12
|
+
applyReplacements,
|
|
13
|
+
compileFindPattern,
|
|
12
14
|
createTableExtensions,
|
|
13
15
|
getTableActionState,
|
|
14
16
|
getTableState,
|
|
@@ -16,8 +18,9 @@ import {
|
|
|
16
18
|
insertSliceAfterTable,
|
|
17
19
|
outermostTableDepth,
|
|
18
20
|
runTableAction,
|
|
21
|
+
searchDocument,
|
|
19
22
|
sliceContainsTable
|
|
20
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-TK2XZK6Z.js";
|
|
21
24
|
import {
|
|
22
25
|
compareDocuments
|
|
23
26
|
} from "./chunk-QJSOZFCZ.js";
|
|
@@ -5513,877 +5516,6 @@ import { Extension as Extension12 } from "@tiptap/core";
|
|
|
5513
5516
|
import { Plugin as Plugin14, PluginKey as PluginKey11, TextSelection as TextSelection7 } from "@tiptap/pm/state";
|
|
5514
5517
|
import { Decoration as Decoration4, DecorationSet as DecorationSet4 } from "@tiptap/pm/view";
|
|
5515
5518
|
import { closeHistory as closeHistory2 } from "@tiptap/pm/history";
|
|
5516
|
-
|
|
5517
|
-
// src/extensions/find-replace/pattern.ts
|
|
5518
|
-
var FIND_PARAGRAPH_MARK = "\r";
|
|
5519
|
-
var MAX_FIND_PATTERN_LENGTH = 1024;
|
|
5520
|
-
var MAX_COUNT = 1e3;
|
|
5521
|
-
var MAX_PROGRAM_SIZE = 2e4;
|
|
5522
|
-
var now = () => typeof performance !== "undefined" && typeof performance.now === "function" ? performance.now() : Date.now();
|
|
5523
|
-
function createSearchBudget(options = {}) {
|
|
5524
|
-
return {
|
|
5525
|
-
deadline: now() + (options.timeLimitMs ?? 250),
|
|
5526
|
-
steps: options.maxSteps ?? 5e7,
|
|
5527
|
-
exhausted: false
|
|
5528
|
-
};
|
|
5529
|
-
}
|
|
5530
|
-
var PARA = 13;
|
|
5531
|
-
var ANY = (cp) => cp !== PARA;
|
|
5532
|
-
var LETTER = /\p{L}/u;
|
|
5533
|
-
var PUNCT = /\p{P}/u;
|
|
5534
|
-
var WORD = /[\p{L}\p{M}\p{Nd}\p{Pc}]/u;
|
|
5535
|
-
var foldCache = /* @__PURE__ */ new Map();
|
|
5536
|
-
function foldCodePoint(cp) {
|
|
5537
|
-
if (cp < 128) return cp >= 65 && cp <= 90 ? cp + 32 : cp;
|
|
5538
|
-
const cached = foldCache.get(cp);
|
|
5539
|
-
if (cached !== void 0) return cached;
|
|
5540
|
-
const lower = String.fromCodePoint(cp).toLowerCase();
|
|
5541
|
-
const folded = [...lower].length === 1 ? lower.codePointAt(0) : cp;
|
|
5542
|
-
if (foldCache.size < 4096) foldCache.set(cp, folded);
|
|
5543
|
-
return folded;
|
|
5544
|
-
}
|
|
5545
|
-
function isWordChar(cp) {
|
|
5546
|
-
if (cp < 0) return false;
|
|
5547
|
-
if (cp < 128) {
|
|
5548
|
-
return cp >= 48 && cp <= 57 || cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122 || cp === 95;
|
|
5549
|
-
}
|
|
5550
|
-
return WORD.test(String.fromCodePoint(cp));
|
|
5551
|
-
}
|
|
5552
|
-
var isLetter = (cp) => cp < 128 ? cp >= 65 && cp <= 90 || cp >= 97 && cp <= 122 : LETTER.test(String.fromCodePoint(cp));
|
|
5553
|
-
function isPunct(cp) {
|
|
5554
|
-
if (cp < 128) {
|
|
5555
|
-
return cp >= 33 && cp <= 47 || cp >= 58 && cp <= 64 || cp >= 91 && cp <= 96 || cp >= 123 && cp <= 126;
|
|
5556
|
-
}
|
|
5557
|
-
return cp >= 8208 && cp <= 8231 || cp === 161 || cp === 191 || cp === 171 || cp === 187 || PUNCT.test(String.fromCodePoint(cp));
|
|
5558
|
-
}
|
|
5559
|
-
var isSpace = (cp) => cp === 32 || cp === 9 || cp === 160;
|
|
5560
|
-
function cpBefore(hay, pos) {
|
|
5561
|
-
if (pos <= 0) return -1;
|
|
5562
|
-
const low = hay.charCodeAt(pos - 1);
|
|
5563
|
-
if (low >= 56320 && low <= 57343 && pos >= 2) {
|
|
5564
|
-
const high = hay.charCodeAt(pos - 2);
|
|
5565
|
-
if (high >= 55296 && high <= 56319) return hay.codePointAt(pos - 2);
|
|
5566
|
-
}
|
|
5567
|
-
return low;
|
|
5568
|
-
}
|
|
5569
|
-
var cpAt = (hay, pos) => pos < hay.length ? hay.codePointAt(pos) : -1;
|
|
5570
|
-
var PatternError = class extends Error {
|
|
5571
|
-
constructor(code, message) {
|
|
5572
|
-
super(message);
|
|
5573
|
-
this.code = code;
|
|
5574
|
-
}
|
|
5575
|
-
code;
|
|
5576
|
-
};
|
|
5577
|
-
var charNode = (test) => ({ k: "char", test });
|
|
5578
|
-
var exact = (cp) => charNode((c) => c === cp);
|
|
5579
|
-
var literalNode = (cp, caseInsensitive) => {
|
|
5580
|
-
if (!caseInsensitive) return exact(cp);
|
|
5581
|
-
const f = foldCodePoint(cp);
|
|
5582
|
-
return charNode((_c, folded) => folded === f);
|
|
5583
|
-
};
|
|
5584
|
-
var star = (body, lazy) => ({ k: "rep", body, min: 0, max: -1, lazy });
|
|
5585
|
-
function findCode(c) {
|
|
5586
|
-
switch (c) {
|
|
5587
|
-
case "p":
|
|
5588
|
-
return exact(PARA);
|
|
5589
|
-
case "t":
|
|
5590
|
-
return exact(9);
|
|
5591
|
-
case "?":
|
|
5592
|
-
return charNode(ANY);
|
|
5593
|
-
case "#":
|
|
5594
|
-
return charNode((cp) => cp >= 48 && cp <= 57);
|
|
5595
|
-
case "$":
|
|
5596
|
-
return charNode((cp) => isLetter(cp));
|
|
5597
|
-
case "^":
|
|
5598
|
-
return exact(94);
|
|
5599
|
-
case "l":
|
|
5600
|
-
return exact(10);
|
|
5601
|
-
case "m":
|
|
5602
|
-
return exact(12);
|
|
5603
|
-
case "n":
|
|
5604
|
-
return exact(14);
|
|
5605
|
-
case "+":
|
|
5606
|
-
return exact(8212);
|
|
5607
|
-
case "=":
|
|
5608
|
-
return exact(8211);
|
|
5609
|
-
case "s":
|
|
5610
|
-
return exact(160);
|
|
5611
|
-
case "~":
|
|
5612
|
-
return exact(8209);
|
|
5613
|
-
case "-":
|
|
5614
|
-
return exact(173);
|
|
5615
|
-
case "w":
|
|
5616
|
-
return { k: "rep", body: charNode((cp) => isSpace(cp)), min: 1, max: -1, lazy: false };
|
|
5617
|
-
case "g":
|
|
5618
|
-
return exact(65532);
|
|
5619
|
-
case "%":
|
|
5620
|
-
return exact(167);
|
|
5621
|
-
case "v":
|
|
5622
|
-
return exact(182);
|
|
5623
|
-
default:
|
|
5624
|
-
return null;
|
|
5625
|
-
}
|
|
5626
|
-
}
|
|
5627
|
-
function replaceCode(c) {
|
|
5628
|
-
switch (c) {
|
|
5629
|
-
case "p":
|
|
5630
|
-
return FIND_PARAGRAPH_MARK;
|
|
5631
|
-
case "t":
|
|
5632
|
-
return " ";
|
|
5633
|
-
case "^":
|
|
5634
|
-
return "^";
|
|
5635
|
-
case "l":
|
|
5636
|
-
return "\n";
|
|
5637
|
-
case "m":
|
|
5638
|
-
return "\f";
|
|
5639
|
-
case "n":
|
|
5640
|
-
return "";
|
|
5641
|
-
case "+":
|
|
5642
|
-
return "\u2014";
|
|
5643
|
-
case "=":
|
|
5644
|
-
return "\u2013";
|
|
5645
|
-
case "s":
|
|
5646
|
-
return "\xA0";
|
|
5647
|
-
case "~":
|
|
5648
|
-
return "\u2011";
|
|
5649
|
-
case "-":
|
|
5650
|
-
return "\xAD";
|
|
5651
|
-
case "%":
|
|
5652
|
-
return "\xA7";
|
|
5653
|
-
case "v":
|
|
5654
|
-
return "\xB6";
|
|
5655
|
-
default:
|
|
5656
|
-
return null;
|
|
5657
|
-
}
|
|
5658
|
-
}
|
|
5659
|
-
function codeChar(n) {
|
|
5660
|
-
switch (n) {
|
|
5661
|
-
case 13:
|
|
5662
|
-
return PARA;
|
|
5663
|
-
case 11:
|
|
5664
|
-
return 10;
|
|
5665
|
-
case 12:
|
|
5666
|
-
return 12;
|
|
5667
|
-
case 14:
|
|
5668
|
-
return 14;
|
|
5669
|
-
case 30:
|
|
5670
|
-
return 8209;
|
|
5671
|
-
case 31:
|
|
5672
|
-
return 173;
|
|
5673
|
-
}
|
|
5674
|
-
if (n > 1114111 || n >= 55296 && n <= 57343) return null;
|
|
5675
|
-
if (n < 32 && n !== 9 || n >= 127 && n < 160) return null;
|
|
5676
|
-
return n;
|
|
5677
|
-
}
|
|
5678
|
-
function numericCode(chars, i) {
|
|
5679
|
-
const unicode = chars[i] === "u";
|
|
5680
|
-
const start2 = unicode ? i + 1 : i;
|
|
5681
|
-
const max = unicode ? 5 : 4;
|
|
5682
|
-
let digits = "";
|
|
5683
|
-
for (let j = start2; j < chars.length && digits.length < max && /[0-9]/.test(chars[j]); j++) digits += chars[j];
|
|
5684
|
-
if (!digits) return null;
|
|
5685
|
-
const cp = codeChar(parseInt(digits, 10));
|
|
5686
|
-
return cp === null ? null : { cp, used: start2 - i + digits.length };
|
|
5687
|
-
}
|
|
5688
|
-
var toChars = (s) => Array.from(s);
|
|
5689
|
-
var cpOf = (ch) => ch.codePointAt(0);
|
|
5690
|
-
function parseSpecial(query, o, caseInsensitive) {
|
|
5691
|
-
const chars = toChars(query);
|
|
5692
|
-
const atoms = [];
|
|
5693
|
-
let spans = false;
|
|
5694
|
-
let i = 0;
|
|
5695
|
-
while (i < chars.length) {
|
|
5696
|
-
const c = chars[i++];
|
|
5697
|
-
if (c === "^" && !o.literal && i < chars.length) {
|
|
5698
|
-
const n = chars[i];
|
|
5699
|
-
const code = findCode(n);
|
|
5700
|
-
if (code) {
|
|
5701
|
-
if (n === "p") spans = true;
|
|
5702
|
-
atoms.push(code);
|
|
5703
|
-
i++;
|
|
5704
|
-
continue;
|
|
5705
|
-
}
|
|
5706
|
-
const num = numericCode(chars, i);
|
|
5707
|
-
if (num) {
|
|
5708
|
-
if (num.cp === PARA) spans = true;
|
|
5709
|
-
atoms.push(literalNode(num.cp, caseInsensitive));
|
|
5710
|
-
i += num.used;
|
|
5711
|
-
continue;
|
|
5712
|
-
}
|
|
5713
|
-
}
|
|
5714
|
-
const cp = cpOf(c);
|
|
5715
|
-
if (o.ignorePunctuation && isPunct(cp) || o.ignoreWhitespace && isSpace(cp)) continue;
|
|
5716
|
-
atoms.push(literalNode(cp, caseInsensitive));
|
|
5717
|
-
}
|
|
5718
|
-
const filler = o.ignorePunctuation && o.ignoreWhitespace ? (cp) => isPunct(cp) || isSpace(cp) : o.ignorePunctuation ? (cp) => isPunct(cp) : o.ignoreWhitespace ? (cp) => isSpace(cp) : null;
|
|
5719
|
-
const items = [];
|
|
5720
|
-
atoms.forEach((atom, index) => {
|
|
5721
|
-
if (index > 0 && filler) items.push(star(charNode(filler), false));
|
|
5722
|
-
items.push(atom);
|
|
5723
|
-
});
|
|
5724
|
-
return { node: { k: "cat", items }, spans };
|
|
5725
|
-
}
|
|
5726
|
-
function parseCount(body) {
|
|
5727
|
-
const bad = () => new PatternError("invalid_pattern", `{${body}} is not a valid count`);
|
|
5728
|
-
const num = (s) => {
|
|
5729
|
-
const t = s.trim();
|
|
5730
|
-
if (!t) return null;
|
|
5731
|
-
if (!/^[0-9]+$/.test(t)) throw bad();
|
|
5732
|
-
const n = parseInt(t, 10);
|
|
5733
|
-
if (n > MAX_COUNT) throw new PatternError("invalid_pattern", `counts go up to ${MAX_COUNT}`);
|
|
5734
|
-
return n;
|
|
5735
|
-
};
|
|
5736
|
-
const sep = body.search(/[,;]/);
|
|
5737
|
-
if (sep < 0) {
|
|
5738
|
-
const n = num(body);
|
|
5739
|
-
if (n === null) throw bad();
|
|
5740
|
-
return { min: n, max: n };
|
|
5741
|
-
}
|
|
5742
|
-
const a = num(body.slice(0, sep)) ?? 0;
|
|
5743
|
-
const b = num(body.slice(sep + 1));
|
|
5744
|
-
if (b !== null && b < a) throw bad();
|
|
5745
|
-
return { min: a, max: b ?? -1 };
|
|
5746
|
-
}
|
|
5747
|
-
function parseClass(inner) {
|
|
5748
|
-
let negated = false;
|
|
5749
|
-
if (inner[0] === "!") {
|
|
5750
|
-
negated = true;
|
|
5751
|
-
inner = inner.slice(1);
|
|
5752
|
-
}
|
|
5753
|
-
if (inner.length === 0) throw new PatternError("invalid_pattern", "[ ] needs at least one character");
|
|
5754
|
-
const singles = /* @__PURE__ */ new Set();
|
|
5755
|
-
const ranges = [];
|
|
5756
|
-
let i = 0;
|
|
5757
|
-
while (i < inner.length) {
|
|
5758
|
-
let c = inner[i];
|
|
5759
|
-
if (c === "\\" && i + 1 < inner.length) c = inner[++i];
|
|
5760
|
-
i++;
|
|
5761
|
-
if (inner[i] === "-" && i + 1 < inner.length) {
|
|
5762
|
-
const hi = inner[i + 1];
|
|
5763
|
-
if (cpOf(hi) < cpOf(c)) throw new PatternError("invalid_pattern", `[${c}-${hi}] is not in ascending order`);
|
|
5764
|
-
ranges.push([cpOf(c), cpOf(hi)]);
|
|
5765
|
-
i += 2;
|
|
5766
|
-
} else {
|
|
5767
|
-
singles.add(cpOf(c));
|
|
5768
|
-
}
|
|
5769
|
-
}
|
|
5770
|
-
const inSet = (cp) => singles.has(cp) || ranges.some(([lo, hi]) => cp >= lo && cp <= hi);
|
|
5771
|
-
return negated ? (cp) => cp !== PARA && !inSet(cp) : (cp) => inSet(cp);
|
|
5772
|
-
}
|
|
5773
|
-
function parseWildcards(query) {
|
|
5774
|
-
const chars = toChars(query);
|
|
5775
|
-
const stack = [{ items: [], group: 0 }];
|
|
5776
|
-
let groups = 0;
|
|
5777
|
-
let spans = false;
|
|
5778
|
-
const top = () => stack[stack.length - 1].items;
|
|
5779
|
-
const quantify = (min, max, what) => {
|
|
5780
|
-
const items = top();
|
|
5781
|
-
const last = items[items.length - 1];
|
|
5782
|
-
if (!last || last.k === "assert" || last.k === "rep") {
|
|
5783
|
-
throw new PatternError("invalid_pattern", `${what} needs something to repeat before it`);
|
|
5784
|
-
}
|
|
5785
|
-
items[items.length - 1] = { k: "rep", body: last, min, max, lazy: false };
|
|
5786
|
-
};
|
|
5787
|
-
let i = 0;
|
|
5788
|
-
while (i < chars.length) {
|
|
5789
|
-
const c = chars[i++];
|
|
5790
|
-
switch (c) {
|
|
5791
|
-
case "?":
|
|
5792
|
-
top().push(charNode(ANY));
|
|
5793
|
-
break;
|
|
5794
|
-
case "*":
|
|
5795
|
-
top().push(star(charNode(ANY), true));
|
|
5796
|
-
break;
|
|
5797
|
-
case "@":
|
|
5798
|
-
quantify(1, -1, "@");
|
|
5799
|
-
break;
|
|
5800
|
-
case "<":
|
|
5801
|
-
top().push({ k: "assert", kind: "wordStart" });
|
|
5802
|
-
break;
|
|
5803
|
-
case ">":
|
|
5804
|
-
top().push({ k: "assert", kind: "wordEnd" });
|
|
5805
|
-
break;
|
|
5806
|
-
case "(":
|
|
5807
|
-
stack.push({ items: [], group: ++groups });
|
|
5808
|
-
break;
|
|
5809
|
-
case ")": {
|
|
5810
|
-
if (stack.length === 1) throw new PatternError("invalid_pattern", "a ) has no opening (");
|
|
5811
|
-
const frame = stack.pop();
|
|
5812
|
-
top().push({ k: "group", index: frame.group, body: { k: "cat", items: frame.items } });
|
|
5813
|
-
break;
|
|
5814
|
-
}
|
|
5815
|
-
case "{": {
|
|
5816
|
-
const end = chars.indexOf("}", i);
|
|
5817
|
-
if (end < 0) throw new PatternError("invalid_pattern", "a { needs a closing }");
|
|
5818
|
-
const { min, max } = parseCount(chars.slice(i, end).join(""));
|
|
5819
|
-
quantify(min, max, `{${chars.slice(i, end).join("")}}`);
|
|
5820
|
-
i = end + 1;
|
|
5821
|
-
break;
|
|
5822
|
-
}
|
|
5823
|
-
case "[": {
|
|
5824
|
-
const end = chars.indexOf("]", i);
|
|
5825
|
-
if (end < 0) throw new PatternError("invalid_pattern", "a [ needs a closing ]");
|
|
5826
|
-
top().push(charNode(parseClass(chars.slice(i, end))));
|
|
5827
|
-
i = end + 1;
|
|
5828
|
-
break;
|
|
5829
|
-
}
|
|
5830
|
-
case "\\": {
|
|
5831
|
-
if (i >= chars.length) {
|
|
5832
|
-
top().push(exact(92));
|
|
5833
|
-
} else if (/[0-9]/.test(chars[i])) {
|
|
5834
|
-
throw new PatternError("invalid_pattern", "back-references (\\1) work in Replace with, not in Find what");
|
|
5835
|
-
} else {
|
|
5836
|
-
top().push(exact(cpOf(chars[i++])));
|
|
5837
|
-
}
|
|
5838
|
-
break;
|
|
5839
|
-
}
|
|
5840
|
-
case "^": {
|
|
5841
|
-
if (i >= chars.length) {
|
|
5842
|
-
top().push(exact(94));
|
|
5843
|
-
break;
|
|
5844
|
-
}
|
|
5845
|
-
const n = chars[i];
|
|
5846
|
-
const code = findCode(n);
|
|
5847
|
-
if (code) {
|
|
5848
|
-
if (n === "p") spans = true;
|
|
5849
|
-
top().push(code);
|
|
5850
|
-
i++;
|
|
5851
|
-
break;
|
|
5852
|
-
}
|
|
5853
|
-
const num = numericCode(chars, i);
|
|
5854
|
-
if (num) {
|
|
5855
|
-
if (num.cp === PARA) spans = true;
|
|
5856
|
-
top().push(exact(num.cp));
|
|
5857
|
-
i += num.used;
|
|
5858
|
-
} else {
|
|
5859
|
-
top().push(exact(94));
|
|
5860
|
-
}
|
|
5861
|
-
break;
|
|
5862
|
-
}
|
|
5863
|
-
default:
|
|
5864
|
-
top().push(exact(cpOf(c)));
|
|
5865
|
-
}
|
|
5866
|
-
}
|
|
5867
|
-
if (stack.length > 1) throw new PatternError("invalid_pattern", "a ( needs a closing )");
|
|
5868
|
-
return { node: { k: "cat", items: stack[0].items }, spans, groups };
|
|
5869
|
-
}
|
|
5870
|
-
function compileProgram(node) {
|
|
5871
|
-
const prog = [];
|
|
5872
|
-
const push = (inst) => {
|
|
5873
|
-
if (prog.length >= MAX_PROGRAM_SIZE) {
|
|
5874
|
-
throw new PatternError("too_complex", "the pattern is too complex (too many repeats)");
|
|
5875
|
-
}
|
|
5876
|
-
prog.push(inst);
|
|
5877
|
-
return prog.length - 1;
|
|
5878
|
-
};
|
|
5879
|
-
const emit = (n) => {
|
|
5880
|
-
switch (n.k) {
|
|
5881
|
-
case "char":
|
|
5882
|
-
push({ op: 0 /* Char */, test: n.test });
|
|
5883
|
-
return;
|
|
5884
|
-
case "cat":
|
|
5885
|
-
n.items.forEach(emit);
|
|
5886
|
-
return;
|
|
5887
|
-
case "group":
|
|
5888
|
-
push({ op: 3 /* Save */, n: 2 * n.index });
|
|
5889
|
-
emit(n.body);
|
|
5890
|
-
push({ op: 3 /* Save */, n: 2 * n.index + 1 });
|
|
5891
|
-
return;
|
|
5892
|
-
case "assert":
|
|
5893
|
-
push({ op: 4 /* Assert */, kind: n.kind });
|
|
5894
|
-
return;
|
|
5895
|
-
case "rep": {
|
|
5896
|
-
for (let k = 0; k < n.min; k++) emit(n.body);
|
|
5897
|
-
if (n.max < 0) {
|
|
5898
|
-
const split = push({ op: 1 /* Split */, x: 0, y: 0 });
|
|
5899
|
-
emit(n.body);
|
|
5900
|
-
push({ op: 2 /* Jmp */, x: split });
|
|
5901
|
-
const exit2 = prog.length;
|
|
5902
|
-
const inst = prog[split];
|
|
5903
|
-
inst.x = n.lazy ? exit2 : split + 1;
|
|
5904
|
-
inst.y = n.lazy ? split + 1 : exit2;
|
|
5905
|
-
return;
|
|
5906
|
-
}
|
|
5907
|
-
const splits = [];
|
|
5908
|
-
for (let k = n.min; k < n.max; k++) {
|
|
5909
|
-
splits.push(push({ op: 1 /* Split */, x: 0, y: 0 }));
|
|
5910
|
-
emit(n.body);
|
|
5911
|
-
}
|
|
5912
|
-
const exit = prog.length;
|
|
5913
|
-
for (const s of splits) {
|
|
5914
|
-
const inst = prog[s];
|
|
5915
|
-
inst.x = n.lazy ? exit : s + 1;
|
|
5916
|
-
inst.y = n.lazy ? s + 1 : exit;
|
|
5917
|
-
}
|
|
5918
|
-
return;
|
|
5919
|
-
}
|
|
5920
|
-
}
|
|
5921
|
-
};
|
|
5922
|
-
push({ op: 3 /* Save */, n: 0 });
|
|
5923
|
-
emit(node);
|
|
5924
|
-
push({ op: 3 /* Save */, n: 1 });
|
|
5925
|
-
push({ op: 5 /* Match */ });
|
|
5926
|
-
return prog;
|
|
5927
|
-
}
|
|
5928
|
-
function checkAssert(kind, hay, pos) {
|
|
5929
|
-
const before = isWordChar(cpBefore(hay, pos));
|
|
5930
|
-
const after = isWordChar(cpAt(hay, pos));
|
|
5931
|
-
switch (kind) {
|
|
5932
|
-
case "boundary":
|
|
5933
|
-
return before !== after;
|
|
5934
|
-
case "wordStart":
|
|
5935
|
-
return !before && after;
|
|
5936
|
-
case "wordEnd":
|
|
5937
|
-
return before && !after;
|
|
5938
|
-
}
|
|
5939
|
-
}
|
|
5940
|
-
function pikeExec(prog, groupCount, caseInsensitive, hay, start2, end, budget) {
|
|
5941
|
-
const ncap = 2 * (groupCount + 1);
|
|
5942
|
-
const mark = new Int32Array(prog.length);
|
|
5943
|
-
let gen = 1;
|
|
5944
|
-
let clistPc = [];
|
|
5945
|
-
let clistCaps = [];
|
|
5946
|
-
let nlistPc = [];
|
|
5947
|
-
let nlistCaps = [];
|
|
5948
|
-
const stackPc = [];
|
|
5949
|
-
const stackCaps = [];
|
|
5950
|
-
let matched = null;
|
|
5951
|
-
const initial = new Int32Array(ncap).fill(-1);
|
|
5952
|
-
const add = (listPc, listCaps, pc0, caps0, pos) => {
|
|
5953
|
-
stackPc.push(pc0);
|
|
5954
|
-
stackCaps.push(caps0);
|
|
5955
|
-
while (stackPc.length) {
|
|
5956
|
-
const pc = stackPc.pop();
|
|
5957
|
-
const caps = stackCaps.pop();
|
|
5958
|
-
if (mark[pc] === gen) continue;
|
|
5959
|
-
mark[pc] = gen;
|
|
5960
|
-
const inst = prog[pc];
|
|
5961
|
-
switch (inst.op) {
|
|
5962
|
-
case 2 /* Jmp */:
|
|
5963
|
-
stackPc.push(inst.x);
|
|
5964
|
-
stackCaps.push(caps);
|
|
5965
|
-
break;
|
|
5966
|
-
case 1 /* Split */:
|
|
5967
|
-
stackPc.push(inst.y, inst.x);
|
|
5968
|
-
stackCaps.push(caps, caps);
|
|
5969
|
-
break;
|
|
5970
|
-
case 3 /* Save */: {
|
|
5971
|
-
const next = caps.slice();
|
|
5972
|
-
next[inst.n] = pos;
|
|
5973
|
-
stackPc.push(pc + 1);
|
|
5974
|
-
stackCaps.push(next);
|
|
5975
|
-
break;
|
|
5976
|
-
}
|
|
5977
|
-
case 4 /* Assert */:
|
|
5978
|
-
if (checkAssert(inst.kind, hay, pos)) {
|
|
5979
|
-
stackPc.push(pc + 1);
|
|
5980
|
-
stackCaps.push(caps);
|
|
5981
|
-
}
|
|
5982
|
-
break;
|
|
5983
|
-
default:
|
|
5984
|
-
listPc.push(pc);
|
|
5985
|
-
listCaps.push(caps);
|
|
5986
|
-
}
|
|
5987
|
-
}
|
|
5988
|
-
};
|
|
5989
|
-
let i = start2;
|
|
5990
|
-
if (budget.steps <= 0 || now() > budget.deadline) {
|
|
5991
|
-
budget.exhausted = true;
|
|
5992
|
-
return "budget";
|
|
5993
|
-
}
|
|
5994
|
-
let steps = 0;
|
|
5995
|
-
for (; ; ) {
|
|
5996
|
-
if (!matched) add(clistPc, clistCaps, 0, initial, i);
|
|
5997
|
-
const cp = i < end ? hay.codePointAt(i) : -1;
|
|
5998
|
-
const width = cp > 65535 ? 2 : 1;
|
|
5999
|
-
if (clistPc.length === 0) {
|
|
6000
|
-
if (matched || i >= end) break;
|
|
6001
|
-
gen++;
|
|
6002
|
-
i += width;
|
|
6003
|
-
continue;
|
|
6004
|
-
}
|
|
6005
|
-
const folded = cp >= 0 && caseInsensitive ? foldCodePoint(cp) : cp;
|
|
6006
|
-
gen++;
|
|
6007
|
-
nlistPc = [];
|
|
6008
|
-
nlistCaps = [];
|
|
6009
|
-
for (let t = 0; t < clistPc.length; t++) {
|
|
6010
|
-
if (++steps >= 4096) {
|
|
6011
|
-
budget.steps -= steps;
|
|
6012
|
-
steps = 0;
|
|
6013
|
-
if (budget.steps <= 0 || now() > budget.deadline) {
|
|
6014
|
-
budget.exhausted = true;
|
|
6015
|
-
return "budget";
|
|
6016
|
-
}
|
|
6017
|
-
}
|
|
6018
|
-
const inst = prog[clistPc[t]];
|
|
6019
|
-
if (inst.op === 0 /* Char */) {
|
|
6020
|
-
if (cp >= 0 && inst.test(cp, folded)) add(nlistPc, nlistCaps, clistPc[t] + 1, clistCaps[t], i + width);
|
|
6021
|
-
} else if (inst.op === 5 /* Match */) {
|
|
6022
|
-
matched = clistCaps[t];
|
|
6023
|
-
break;
|
|
6024
|
-
}
|
|
6025
|
-
}
|
|
6026
|
-
clistPc = nlistPc;
|
|
6027
|
-
clistCaps = nlistCaps;
|
|
6028
|
-
if (i >= end) break;
|
|
6029
|
-
i += width;
|
|
6030
|
-
}
|
|
6031
|
-
budget.steps -= steps;
|
|
6032
|
-
if (!matched) return null;
|
|
6033
|
-
const groups = [];
|
|
6034
|
-
for (let g = 0; g <= groupCount; g++) {
|
|
6035
|
-
const a = matched[2 * g];
|
|
6036
|
-
const b = matched[2 * g + 1];
|
|
6037
|
-
groups.push(a >= 0 && b >= 0 ? hay.slice(a, b) : void 0);
|
|
6038
|
-
}
|
|
6039
|
-
return { start: matched[0], end: matched[1], groups };
|
|
6040
|
-
}
|
|
6041
|
-
var WORD_CLASS = "[\\p{L}\\p{M}\\p{Nd}\\p{Pc}]";
|
|
6042
|
-
var REGEX_BOUNDARY = `(?:(?<=${WORD_CLASS})(?!${WORD_CLASS})|(?<!${WORD_CLASS})(?=${WORD_CLASS}))`;
|
|
6043
|
-
function hasNestedRepeat(source) {
|
|
6044
|
-
const quantifierAt = (i) => {
|
|
6045
|
-
const c = source[i];
|
|
6046
|
-
if (c === "*" || c === "+") return { repeats: true, many: true };
|
|
6047
|
-
if (c === "{") {
|
|
6048
|
-
const m = /^\{(\d*)(,?)(\d*)\}/.exec(source.slice(i));
|
|
6049
|
-
if (m) {
|
|
6050
|
-
const max = m[2] ? m[3] ? Number(m[3]) : Infinity : Number(m[1]);
|
|
6051
|
-
return { repeats: max > 1, many: max > 1 };
|
|
6052
|
-
}
|
|
6053
|
-
}
|
|
6054
|
-
return { repeats: false, many: false };
|
|
6055
|
-
};
|
|
6056
|
-
const stack = [];
|
|
6057
|
-
let inClass = false;
|
|
6058
|
-
for (let i = 0; i < source.length; i++) {
|
|
6059
|
-
const c = source[i];
|
|
6060
|
-
if (c === "\\") {
|
|
6061
|
-
i++;
|
|
6062
|
-
continue;
|
|
6063
|
-
}
|
|
6064
|
-
if (inClass) {
|
|
6065
|
-
if (c === "]") inClass = false;
|
|
6066
|
-
continue;
|
|
6067
|
-
}
|
|
6068
|
-
if (c === "[") {
|
|
6069
|
-
inClass = true;
|
|
6070
|
-
} else if (c === "(") {
|
|
6071
|
-
stack.push(false);
|
|
6072
|
-
} else if (c === ")") {
|
|
6073
|
-
const inner = stack.pop() ?? false;
|
|
6074
|
-
const q = quantifierAt(i + 1);
|
|
6075
|
-
if (inner && q.many) return true;
|
|
6076
|
-
if (stack.length && (inner || q.repeats)) stack[stack.length - 1] = true;
|
|
6077
|
-
} else if (stack.length && quantifierAt(i).repeats) {
|
|
6078
|
-
stack[stack.length - 1] = true;
|
|
6079
|
-
}
|
|
6080
|
-
}
|
|
6081
|
-
return false;
|
|
6082
|
-
}
|
|
6083
|
-
function compileRegex(query, o) {
|
|
6084
|
-
if (hasNestedRepeat(query)) {
|
|
6085
|
-
throw new PatternError(
|
|
6086
|
-
"too_complex",
|
|
6087
|
-
"a repeated group containing a repeat, like (a+)+, can take exponential time; rewrite it without nesting"
|
|
6088
|
-
);
|
|
6089
|
-
}
|
|
6090
|
-
let source = query;
|
|
6091
|
-
if (o.wholeWord || o.matchPrefix && o.matchSuffix) source = `${REGEX_BOUNDARY}(?:${query})${REGEX_BOUNDARY}`;
|
|
6092
|
-
else if (o.matchPrefix) source = `${REGEX_BOUNDARY}(?:${query})`;
|
|
6093
|
-
else if (o.matchSuffix) source = `(?:${query})${REGEX_BOUNDARY}`;
|
|
6094
|
-
let re;
|
|
6095
|
-
try {
|
|
6096
|
-
re = new RegExp(source, o.matchCase ? "gu" : "giu");
|
|
6097
|
-
} catch (error) {
|
|
6098
|
-
throw new PatternError("invalid_pattern", `bad pattern: ${error instanceof Error ? error.message : String(error)}`);
|
|
6099
|
-
}
|
|
6100
|
-
let slicedFor = null;
|
|
6101
|
-
return {
|
|
6102
|
-
mode: "regex",
|
|
6103
|
-
spansParagraphs: false,
|
|
6104
|
-
caseInsensitive: !o.matchCase,
|
|
6105
|
-
groupCount: 0,
|
|
6106
|
-
exec(hay, start2, end, budget) {
|
|
6107
|
-
if (now() > budget.deadline) {
|
|
6108
|
-
budget.exhausted = true;
|
|
6109
|
-
return "budget";
|
|
6110
|
-
}
|
|
6111
|
-
let text = hay;
|
|
6112
|
-
if (end < hay.length) {
|
|
6113
|
-
if (!slicedFor || slicedFor.hay !== hay || slicedFor.end !== end) {
|
|
6114
|
-
slicedFor = { hay, end, text: hay.slice(0, end) };
|
|
6115
|
-
}
|
|
6116
|
-
text = slicedFor.text;
|
|
6117
|
-
}
|
|
6118
|
-
re.lastIndex = start2;
|
|
6119
|
-
const m = re.exec(text);
|
|
6120
|
-
if (!m) return null;
|
|
6121
|
-
return { start: m.index, end: m.index + m[0].length, groups: Array.from(m) };
|
|
6122
|
-
}
|
|
6123
|
-
};
|
|
6124
|
-
}
|
|
6125
|
-
function compileFindPattern(query, options = {}) {
|
|
6126
|
-
try {
|
|
6127
|
-
if (Array.from(query).length > MAX_FIND_PATTERN_LENGTH) {
|
|
6128
|
-
throw new PatternError("too_long", `the Find what text is longer than ${MAX_FIND_PATTERN_LENGTH} characters`);
|
|
6129
|
-
}
|
|
6130
|
-
if (options.regex) return { ok: true, pattern: compileRegex(query, options) };
|
|
6131
|
-
const wildcards = !!options.wildcards && !options.literal;
|
|
6132
|
-
const caseInsensitive = !options.matchCase && !wildcards;
|
|
6133
|
-
let node;
|
|
6134
|
-
let spans;
|
|
6135
|
-
let groups = 0;
|
|
6136
|
-
if (wildcards) {
|
|
6137
|
-
({ node, spans, groups } = parseWildcards(query));
|
|
6138
|
-
} else {
|
|
6139
|
-
({ node, spans } = parseSpecial(query, options, caseInsensitive));
|
|
6140
|
-
const before = options.wholeWord || options.matchPrefix;
|
|
6141
|
-
const after = options.wholeWord || options.matchSuffix;
|
|
6142
|
-
if (before || after) {
|
|
6143
|
-
const items = [];
|
|
6144
|
-
if (before) items.push({ k: "assert", kind: "boundary" });
|
|
6145
|
-
items.push(node);
|
|
6146
|
-
if (after) items.push({ k: "assert", kind: "boundary" });
|
|
6147
|
-
node = { k: "cat", items };
|
|
6148
|
-
}
|
|
6149
|
-
}
|
|
6150
|
-
const prog = compileProgram(node);
|
|
6151
|
-
return {
|
|
6152
|
-
ok: true,
|
|
6153
|
-
pattern: {
|
|
6154
|
-
mode: wildcards ? "wildcards" : "special",
|
|
6155
|
-
spansParagraphs: spans,
|
|
6156
|
-
caseInsensitive,
|
|
6157
|
-
groupCount: groups,
|
|
6158
|
-
exec: (hay, start2, end, budget) => pikeExec(prog, groups, caseInsensitive, hay, start2, end, budget)
|
|
6159
|
-
}
|
|
6160
|
-
};
|
|
6161
|
-
} catch (error) {
|
|
6162
|
-
if (error instanceof PatternError) return { ok: false, error: { code: error.code, message: error.message } };
|
|
6163
|
-
return { ok: false, error: { code: "invalid_pattern", message: error instanceof Error ? error.message : String(error) } };
|
|
6164
|
-
}
|
|
6165
|
-
}
|
|
6166
|
-
function findAllMatches(pattern, hay, options = {}) {
|
|
6167
|
-
const budget = options.budget ?? createSearchBudget();
|
|
6168
|
-
const maxMatches = options.maxMatches ?? 1e4;
|
|
6169
|
-
const cuts = [...options.cuts ?? [], hay.length].sort((a, b) => a - b);
|
|
6170
|
-
const matches = [];
|
|
6171
|
-
let from = 0;
|
|
6172
|
-
for (const cut of cuts) {
|
|
6173
|
-
if (cut <= from) continue;
|
|
6174
|
-
let pos = from;
|
|
6175
|
-
from = cut;
|
|
6176
|
-
for (; ; ) {
|
|
6177
|
-
const m = pattern.exec(hay, pos, cut, budget);
|
|
6178
|
-
if (m === "budget") return { matches, truncated: true };
|
|
6179
|
-
if (!m) break;
|
|
6180
|
-
const empty = m.end === m.start;
|
|
6181
|
-
const next = empty ? m.end + (cpAt(hay, m.end) > 65535 ? 2 : 1) : m.end;
|
|
6182
|
-
if (next > cut) break;
|
|
6183
|
-
pos = next;
|
|
6184
|
-
if (empty) continue;
|
|
6185
|
-
matches.push(m);
|
|
6186
|
-
if (matches.length >= maxMatches) return { matches, truncated: true };
|
|
6187
|
-
}
|
|
6188
|
-
}
|
|
6189
|
-
return { matches, truncated: false };
|
|
6190
|
-
}
|
|
6191
|
-
function parseReplacement(replacement, options = {}) {
|
|
6192
|
-
if (options.literal || options.regex) return replacement ? [{ type: "text", text: replacement }] : [];
|
|
6193
|
-
const chars = toChars(replacement);
|
|
6194
|
-
const out = [];
|
|
6195
|
-
let cur = "";
|
|
6196
|
-
const flush = () => {
|
|
6197
|
-
if (cur) out.push({ type: "text", text: cur });
|
|
6198
|
-
cur = "";
|
|
6199
|
-
};
|
|
6200
|
-
let i = 0;
|
|
6201
|
-
while (i < chars.length) {
|
|
6202
|
-
const c = chars[i++];
|
|
6203
|
-
if (c === "\\" && options.wildcards && i < chars.length) {
|
|
6204
|
-
const d = chars[i];
|
|
6205
|
-
if (/[1-9]/.test(d)) {
|
|
6206
|
-
flush();
|
|
6207
|
-
out.push({ type: "group", index: Number(d) });
|
|
6208
|
-
} else {
|
|
6209
|
-
cur += d;
|
|
6210
|
-
}
|
|
6211
|
-
i++;
|
|
6212
|
-
continue;
|
|
6213
|
-
}
|
|
6214
|
-
if (c === "^" && i < chars.length) {
|
|
6215
|
-
const n = chars[i];
|
|
6216
|
-
if (n === "&" || n === "c") {
|
|
6217
|
-
flush();
|
|
6218
|
-
out.push(n === "&" ? { type: "found" } : { type: "clipboard" });
|
|
6219
|
-
i++;
|
|
6220
|
-
continue;
|
|
6221
|
-
}
|
|
6222
|
-
const code = replaceCode(n);
|
|
6223
|
-
if (code !== null) {
|
|
6224
|
-
cur += code;
|
|
6225
|
-
i++;
|
|
6226
|
-
continue;
|
|
6227
|
-
}
|
|
6228
|
-
const num = numericCode(chars, i);
|
|
6229
|
-
if (num) {
|
|
6230
|
-
cur += String.fromCodePoint(num.cp);
|
|
6231
|
-
i += num.used;
|
|
6232
|
-
continue;
|
|
6233
|
-
}
|
|
6234
|
-
}
|
|
6235
|
-
cur += c;
|
|
6236
|
-
}
|
|
6237
|
-
flush();
|
|
6238
|
-
return out;
|
|
6239
|
-
}
|
|
6240
|
-
function expandReplacement(pieces, match, clipboardText = "") {
|
|
6241
|
-
let out = "";
|
|
6242
|
-
for (const piece of pieces) {
|
|
6243
|
-
switch (piece.type) {
|
|
6244
|
-
case "text":
|
|
6245
|
-
out += piece.text;
|
|
6246
|
-
break;
|
|
6247
|
-
case "found":
|
|
6248
|
-
out += match.groups[0] ?? "";
|
|
6249
|
-
break;
|
|
6250
|
-
case "group":
|
|
6251
|
-
out += match.groups[piece.index] ?? "";
|
|
6252
|
-
break;
|
|
6253
|
-
case "clipboard":
|
|
6254
|
-
out += clipboardText.replace(/\r\n/g, "\r").replace(/\n/g, "\r");
|
|
6255
|
-
break;
|
|
6256
|
-
}
|
|
6257
|
-
}
|
|
6258
|
-
return out;
|
|
6259
|
-
}
|
|
6260
|
-
|
|
6261
|
-
// src/extensions/find-replace/search.ts
|
|
6262
|
-
var DELETION_MARK = "deletion";
|
|
6263
|
-
var DROPPED_REPLACEMENT_MARKS = /* @__PURE__ */ new Set([DELETION_MARK, "formatChange"]);
|
|
6264
|
-
var OBJECT_CHAR = "\uFFFC";
|
|
6265
|
-
function searchDocument(doc, query, options = {}, searchOptions = {}) {
|
|
6266
|
-
if (!query) return { matches: [], truncated: false, error: null };
|
|
6267
|
-
const compiled = compileFindPattern(query, options);
|
|
6268
|
-
if (!compiled.ok) return { matches: [], truncated: false, error: compiled.error };
|
|
6269
|
-
const pattern = compiled.pattern;
|
|
6270
|
-
const pieces = parseReplacement(searchOptions.replacement ?? "", options);
|
|
6271
|
-
const budget = createSearchBudget({ timeLimitMs: searchOptions.timeLimitMs });
|
|
6272
|
-
const maxMatches = searchOptions.maxMatches ?? 1e4;
|
|
6273
|
-
const blocks = [];
|
|
6274
|
-
doc.descendants((node, pos, parent, index) => {
|
|
6275
|
-
if (!node.isTextblock) return true;
|
|
6276
|
-
blocks.push({ node, pos, parent, index });
|
|
6277
|
-
return false;
|
|
6278
|
-
});
|
|
6279
|
-
const chunks = [];
|
|
6280
|
-
blocks.forEach((block, i) => {
|
|
6281
|
-
const prev = blocks[i - 1];
|
|
6282
|
-
const joins = pattern.spansParagraphs && prev && prev.parent === block.parent && prev.index + 1 === block.index;
|
|
6283
|
-
if (joins) chunks[chunks.length - 1].push(block);
|
|
6284
|
-
else chunks.push([block]);
|
|
6285
|
-
});
|
|
6286
|
-
const matches = [];
|
|
6287
|
-
let truncated = false;
|
|
6288
|
-
for (const chunk of chunks) {
|
|
6289
|
-
let hay = "";
|
|
6290
|
-
const posOf = [];
|
|
6291
|
-
const endOf = [];
|
|
6292
|
-
const cuts = [];
|
|
6293
|
-
chunk.forEach((block, k) => {
|
|
6294
|
-
const contentStart = block.pos + 1;
|
|
6295
|
-
block.node.forEach((child, offset) => {
|
|
6296
|
-
const at = contentStart + offset;
|
|
6297
|
-
if (child.marks.some((m) => m.type.name === DELETION_MARK)) {
|
|
6298
|
-
if (cuts[cuts.length - 1] !== hay.length) cuts.push(hay.length);
|
|
6299
|
-
return;
|
|
6300
|
-
}
|
|
6301
|
-
if (child.isText) {
|
|
6302
|
-
const text = child.text ?? "";
|
|
6303
|
-
for (let j = 0; j < text.length; j++) {
|
|
6304
|
-
posOf.push(at + j);
|
|
6305
|
-
endOf.push(at + j + 1);
|
|
6306
|
-
}
|
|
6307
|
-
hay += text;
|
|
6308
|
-
} else {
|
|
6309
|
-
posOf.push(at);
|
|
6310
|
-
endOf.push(at + child.nodeSize);
|
|
6311
|
-
hay += child.type.name === "hardBreak" ? "\n" : OBJECT_CHAR;
|
|
6312
|
-
}
|
|
6313
|
-
});
|
|
6314
|
-
const next = chunk[k + 1];
|
|
6315
|
-
if (next) {
|
|
6316
|
-
posOf.push(contentStart + block.node.content.size);
|
|
6317
|
-
endOf.push(next.pos + 1);
|
|
6318
|
-
hay += FIND_PARAGRAPH_MARK;
|
|
6319
|
-
}
|
|
6320
|
-
});
|
|
6321
|
-
if (!hay) continue;
|
|
6322
|
-
const result = findAllMatches(pattern, hay, {
|
|
6323
|
-
cuts,
|
|
6324
|
-
budget,
|
|
6325
|
-
maxMatches: maxMatches - matches.length
|
|
6326
|
-
});
|
|
6327
|
-
for (const m of result.matches) {
|
|
6328
|
-
matches.push({
|
|
6329
|
-
from: posOf[m.start],
|
|
6330
|
-
to: endOf[m.end - 1],
|
|
6331
|
-
text: m.groups[0] ?? hay.slice(m.start, m.end),
|
|
6332
|
-
replacement: expandReplacement(pieces, m, searchOptions.clipboardText ?? "")
|
|
6333
|
-
});
|
|
6334
|
-
}
|
|
6335
|
-
if (result.truncated) {
|
|
6336
|
-
truncated = true;
|
|
6337
|
-
break;
|
|
6338
|
-
}
|
|
6339
|
-
}
|
|
6340
|
-
return { matches, truncated, error: null };
|
|
6341
|
-
}
|
|
6342
|
-
function replacementMarks(doc, from, to) {
|
|
6343
|
-
const $from = doc.resolve(from);
|
|
6344
|
-
const node = from < to ? $from.nodeAfter : null;
|
|
6345
|
-
const marks = node ? node.marks : $from.marks();
|
|
6346
|
-
return marks.filter((m) => !DROPPED_REPLACEMENT_MARKS.has(m.type.name));
|
|
6347
|
-
}
|
|
6348
|
-
function inlineContent(schema, text, marks) {
|
|
6349
|
-
const nodes = [];
|
|
6350
|
-
const hardBreak = schema.nodes.hardBreak;
|
|
6351
|
-
const parts = hardBreak ? text.split("\n") : [text];
|
|
6352
|
-
parts.forEach((part, i) => {
|
|
6353
|
-
if (i > 0) nodes.push(hardBreak.create(null, null, marks));
|
|
6354
|
-
if (part) nodes.push(schema.text(part, marks));
|
|
6355
|
-
});
|
|
6356
|
-
return nodes;
|
|
6357
|
-
}
|
|
6358
|
-
function applyReplacements(tr, matches) {
|
|
6359
|
-
const ends = new Array(matches.length);
|
|
6360
|
-
const schema = tr.doc.type.schema;
|
|
6361
|
-
for (let i = matches.length - 1; i >= 0; i--) {
|
|
6362
|
-
const { from, to, replacement } = matches[i];
|
|
6363
|
-
const marks = replacementMarks(tr.doc, from, to);
|
|
6364
|
-
const parts = replacement.split(/[\r\u2029]/);
|
|
6365
|
-
const stepsBefore = tr.steps.length;
|
|
6366
|
-
const first = inlineContent(schema, parts[0], marks);
|
|
6367
|
-
if (first.length) tr.replaceWith(from, to, first);
|
|
6368
|
-
else if (to > from) tr.delete(from, to);
|
|
6369
|
-
let pos = tr.mapping.slice(stepsBefore).map(to, 1);
|
|
6370
|
-
for (let k = 1; k < parts.length; k++) {
|
|
6371
|
-
tr.split(pos);
|
|
6372
|
-
pos += 2;
|
|
6373
|
-
const content = inlineContent(schema, parts[k], marks);
|
|
6374
|
-
if (content.length) {
|
|
6375
|
-
tr.insert(pos, content);
|
|
6376
|
-
pos += content.reduce((size, node) => size + node.nodeSize, 0);
|
|
6377
|
-
}
|
|
6378
|
-
}
|
|
6379
|
-
const map = tr.mapping.slice(stepsBefore);
|
|
6380
|
-
for (let j = i + 1; j < matches.length; j++) ends[j] = map.map(ends[j], 1);
|
|
6381
|
-
ends[i] = pos;
|
|
6382
|
-
}
|
|
6383
|
-
return ends;
|
|
6384
|
-
}
|
|
6385
|
-
|
|
6386
|
-
// src/extensions/find-replace/extension.ts
|
|
6387
5519
|
var EMPTY_OPTIONS = Object.freeze({});
|
|
6388
5520
|
var EMPTY_FIND_REPLACE_SNAPSHOT = Object.freeze({
|
|
6389
5521
|
open: false,
|
|
@@ -7618,16 +6750,6 @@ export {
|
|
|
7618
6750
|
CrossReference,
|
|
7619
6751
|
documentStructureCommandItems,
|
|
7620
6752
|
getDocumentStructureCommandItems,
|
|
7621
|
-
FIND_PARAGRAPH_MARK,
|
|
7622
|
-
MAX_FIND_PATTERN_LENGTH,
|
|
7623
|
-
createSearchBudget,
|
|
7624
|
-
foldCodePoint,
|
|
7625
|
-
compileFindPattern,
|
|
7626
|
-
findAllMatches,
|
|
7627
|
-
parseReplacement,
|
|
7628
|
-
expandReplacement,
|
|
7629
|
-
searchDocument,
|
|
7630
|
-
applyReplacements,
|
|
7631
6753
|
EMPTY_FIND_REPLACE_SNAPSHOT,
|
|
7632
6754
|
FindReplaceStore,
|
|
7633
6755
|
findReplacePluginKey,
|
|
@@ -7651,4 +6773,4 @@ export {
|
|
|
7651
6773
|
validateFindPattern,
|
|
7652
6774
|
createTableCommands
|
|
7653
6775
|
};
|
|
7654
|
-
//# sourceMappingURL=chunk-
|
|
6776
|
+
//# sourceMappingURL=chunk-Q25ZS4F7.js.map
|