@pi-outpost/embed 0.23.1 → 0.25.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.
@@ -0,0 +1 @@
1
+ function e(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function t(t,n,r=1/0){if(n===``)return[];let i=new RegExp(e(n),`gi`),a=[],o;for(;(o=i.exec(t))!==null&&(a.push({start:o.index,end:o.index+o[0].length}),!(a.length>=r)););return a}function n(e){let t=document.createTreeWalker(e,NodeFilter.SHOW_TEXT),n=[],r=``;for(let e=t.nextNode();e!==null;e=t.nextNode()){let t=e.data.length;t!==0&&(n.push({node:e,start:r.length,end:r.length+t}),r+=e.data)}return{nodes:n,text:r}}function r(e,r,i=3e3){let a={matches:[],truncated:!1,clear:()=>{}};if(r===``)return a;let{nodes:o,text:s}=n(e);if(s===``)return a;let c=t(s,r,i+1),l=c.length>i,u=l?c.slice(0,i):c;if(u.length===0)return{matches:[],truncated:l,clear:()=>{}};let d=Array(u.length);for(let e=u.length-1;e>=0;e--){let{start:t,end:n}=u[e],r=[];for(let e of o){if(e.end<=t||e.start>=n)continue;let i=Math.max(0,t-e.start),a=Math.min(e.node.data.length,n-e.start);if(i>=a)continue;let o=e.node;a<o.data.length&&o.splitText(a);let s=i>0?o.splitText(i):o,c=document.createElement(`mark`);c.className=`find-match`,s.replaceWith(c),c.appendChild(s),r.push(c)}d[e]={marks:r}}return{matches:d,truncated:l,clear:()=>{for(let{marks:e}of d)for(let t of e)t.replaceWith(document.createTextNode(t.textContent??``));e.normalize()}}}Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return r}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return t}});
@@ -0,0 +1,67 @@
1
+ function e(e) {
2
+ return e.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
3
+ }
4
+ function t(t, n, r = Infinity) {
5
+ if (n === "") return [];
6
+ let i = new RegExp(e(n), "gi"), a = [], o;
7
+ for (; (o = i.exec(t)) !== null && (a.push({
8
+ start: o.index,
9
+ end: o.index + o[0].length
10
+ }), !(a.length >= r)););
11
+ return a;
12
+ }
13
+ function n(e) {
14
+ let t = document.createTreeWalker(e, NodeFilter.SHOW_TEXT), n = [], r = "";
15
+ for (let e = t.nextNode(); e !== null; e = t.nextNode()) {
16
+ let t = e.data.length;
17
+ t !== 0 && (n.push({
18
+ node: e,
19
+ start: r.length,
20
+ end: r.length + t
21
+ }), r += e.data);
22
+ }
23
+ return {
24
+ nodes: n,
25
+ text: r
26
+ };
27
+ }
28
+ function r(e, r, i = 3e3) {
29
+ let a = {
30
+ matches: [],
31
+ truncated: !1,
32
+ clear: () => {}
33
+ };
34
+ if (r === "") return a;
35
+ let { nodes: o, text: s } = n(e);
36
+ if (s === "") return a;
37
+ let c = t(s, r, i + 1), l = c.length > i, u = l ? c.slice(0, i) : c;
38
+ if (u.length === 0) return {
39
+ matches: [],
40
+ truncated: l,
41
+ clear: () => {}
42
+ };
43
+ let d = Array(u.length);
44
+ for (let e = u.length - 1; e >= 0; e--) {
45
+ let { start: t, end: n } = u[e], r = [];
46
+ for (let e of o) {
47
+ if (e.end <= t || e.start >= n) continue;
48
+ let i = Math.max(0, t - e.start), a = Math.min(e.node.data.length, n - e.start);
49
+ if (i >= a) continue;
50
+ let o = e.node;
51
+ a < o.data.length && o.splitText(a);
52
+ let s = i > 0 ? o.splitText(i) : o, c = document.createElement("mark");
53
+ c.className = "find-match", s.replaceWith(c), c.appendChild(s), r.push(c);
54
+ }
55
+ d[e] = { marks: r };
56
+ }
57
+ return {
58
+ matches: d,
59
+ truncated: l,
60
+ clear: () => {
61
+ for (let { marks: e } of d) for (let t of e) t.replaceWith(document.createTextNode(t.textContent ?? ""));
62
+ e.normalize();
63
+ }
64
+ };
65
+ }
66
+ //#endregion
67
+ export { r as n, t };