@floegence/floe-webapp-core 0.98.1 → 0.100.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.
@@ -3,7 +3,17 @@ export interface SandboxedHtmlFrameLabels {
3
3
  linkUnavailable: string;
4
4
  anchorUnavailable: string;
5
5
  }
6
+ export interface SandboxedHtmlSearch {
7
+ search: (query: string, direction?: -1 | 0 | 1) => void;
8
+ clear: () => void;
9
+ }
6
10
  export interface SandboxedHtmlFrameProps {
11
+ onSearchReady?: (search: SandboxedHtmlSearch | undefined) => void;
12
+ onSearchState?: (state: {
13
+ current: number;
14
+ total: number;
15
+ }) => void;
16
+ onSearchRequest?: (action: 'open' | 'close') => void;
7
17
  html: string;
8
18
  title: string;
9
19
  class?: string;
@@ -1,19 +1,44 @@
1
- import { insert as g, createComponent as L, effect as O, setAttribute as m, className as P, style as U, template as T, use as R } from "solid-js/web";
2
- import { createSignal as E, createMemo as B, createEffect as k, untrack as D, onCleanup as C, onMount as N, Show as q } from "solid-js";
3
- import { sandboxedMarkdownHtml as W } from "../chat/markdown/media.js";
4
- import { secureRandomUUID as j } from "../../utils/secureRandom.js";
5
- var z = /* @__PURE__ */ T('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), J = /* @__PURE__ */ T('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), V = /* @__PURE__ */ T('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox=allow-scripts referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
6
- function $(t) {
1
+ import { insert as v, createComponent as M, effect as A, setAttribute as f, className as N, style as P, template as S, use as Q } from "solid-js/web";
2
+ import { createSignal as w, createMemo as U, createEffect as k, untrack as B, onCleanup as I, onMount as D, Show as H } from "solid-js";
3
+ import { sandboxedMarkdownHtml as K } from "../chat/markdown/media.js";
4
+ import { findTextRanges as W } from "../ui/textSearch.js";
5
+ import { secureRandomUUID as $ } from "../../utils/secureRandom.js";
6
+ var j = /* @__PURE__ */ S('<span data-floe-html-pending style="position:absolute;inset:0;z-index:1;background:var(--background, Canvas)">'), z = /* @__PURE__ */ S('<span role=alert class="max-h-24 shrink-0 overflow-auto break-words bg-background px-3 py-2 text-xs text-destructive">'), J = /* @__PURE__ */ S('<span class="relative flex h-full min-h-0 w-full flex-col"><iframe sandbox=allow-scripts referrerpolicy=no-referrer style="display:block;width:100%;min-height:0;flex:1 1 0%;border:0">');
7
+ function V(e) {
7
8
  return `<script>(()=>{
8
9
  const channel=new MessageChannel();
9
10
  const publish=channel.port1.postMessage.bind(channel.port1);
10
11
  const query=document.querySelectorAll.bind(document);
11
12
  const MediaElementType=HTMLMediaElement;
12
13
  const pause=Function.call.bind(MediaElementType.prototype.pause);
13
- let active=true;
14
+ let active=true,searchEnabled=false,searchOpen=false,searchQuery='',matches=[],matchIndex=0;
15
+ const findRanges=(${W.toString()});
16
+ const clearHighlights=()=>{CSS.highlights?.delete('floe-html-find');CSS.highlights?.delete('floe-html-find-current')};
17
+ const paint=()=>{
18
+ clearHighlights();
19
+ if(!active||!searchOpen)return;
20
+ if(typeof Highlight!=='undefined'&&CSS.highlights){
21
+ CSS.highlights.set('floe-html-find',new Highlight(...matches));
22
+ if(matches[matchIndex])CSS.highlights.set('floe-html-find-current',new Highlight(matches[matchIndex]));
23
+ }
24
+ };
25
+ const search=data=>{
26
+ if(!active||typeof data.query!=='string')return;
27
+ searchOpen=true;
28
+ const previous=searchQuery;
29
+ searchQuery=data.query;matches=findRanges(document.body,searchQuery);
30
+ matchIndex=matches.length?(previous!==searchQuery||!data.direction?0:(matchIndex+data.direction+matches.length)%matches.length):0;
31
+ paint();
32
+ const range=matches[matchIndex];
33
+ if(range){const element=range.startContainer.parentElement;scroll(element,{block:'center',inline:'nearest'})}
34
+ publish({type:'search-state',request:data.request,current:matches.length?matchIndex+1:0,total:matches.length});
35
+ };
14
36
  channel.port1.onmessage=event=>{
37
+ if(event.data?.type==='search'){search(event.data);return}
38
+ if(event.data?.type==='clear-search'){searchOpen=false;clearHighlights();return}
15
39
  if(event.data?.type!=='activation')return;
16
- active=event.data.active===true;
40
+ active=event.data.active===true;searchEnabled=event.data.searchEnabled===true;
41
+ paint();
17
42
  if(!active)for(const media of query('video,audio'))pause(media);
18
43
  };
19
44
  channel.port1.start();
@@ -30,6 +55,11 @@ function $(t) {
30
55
  const focus=Function.call.bind(HTMLElement.prototype.focus);
31
56
  const decode=decodeURIComponent;
32
57
  const ElementType=Element,HtmlElementType=HTMLElement;
58
+ window.addEventListener('keydown',event=>{
59
+ if(!active||!searchEnabled||!event.isTrusted||event.isComposing)return;
60
+ if((event.ctrlKey||event.metaKey)&&!event.altKey&&event.key.toLowerCase()==='f'){prevent(event);stop(event);publish({type:'search-open'})}
61
+ else if(searchOpen&&event.key==='Escape'){prevent(event);stop(event);publish({type:'search-close'})}
62
+ },true);
33
63
  window.addEventListener('click',activate,true);
34
64
  window.addEventListener('auxclick',activate,true);
35
65
  function activate(event){
@@ -53,97 +83,123 @@ function $(t) {
53
83
  }
54
84
  publish({type:'open-link',href});
55
85
  }
56
- parent.postMessage({type:'floe-html-ready',token:${JSON.stringify(t)}},'*',[channel.port2]);
57
- })()<\/script>`;
86
+ parent.postMessage({type:'floe-html-ready',token:${JSON.stringify(e)}},'*',[channel.port2]);
87
+ })()<\/script><style>::highlight(floe-html-find){background:#fde68a;color:#111}::highlight(floe-html-find-current){background:#2563eb;color:#fff}</style>`;
58
88
  }
59
- function Y(t) {
60
- let p, y;
61
- const [x, c] = E(""), [A, H] = E(""), [S, M] = E(), b = B(() => {
62
- const n = j();
89
+ function ee(e) {
90
+ let y, p;
91
+ const [x, h] = w(""), [F, L] = w(""), [R, T] = w(), b = U(() => {
92
+ const r = $();
63
93
  return {
64
- token: n,
65
- html: W($(n) + t.html)
94
+ token: r,
95
+ html: K(V(r) + e.html)
66
96
  };
67
- }), l = () => A() === b().token;
97
+ }), o = () => F() === b().token;
68
98
  k(() => {
69
- const n = l() ? "ready" : "loading";
70
- D(() => t.onPresentationStateChange?.(n));
99
+ const r = o() ? "ready" : "loading";
100
+ B(() => e.onPresentationStateChange?.(r));
71
101
  }), k(() => {
72
- S()?.postMessage({
102
+ R()?.postMessage({
73
103
  type: "activation",
74
- active: t.active !== !1
104
+ active: e.active !== !1,
105
+ searchEnabled: !!e.onSearchRequest
75
106
  });
76
107
  }), k(() => {
77
108
  const {
78
- token: n
79
- } = b(), r = new AbortController();
80
- let o, e = 0, s = 0, d = !1;
81
- c(""), y = (i) => {
82
- !i.isTrusted || i.source !== p.contentWindow || o || i.data?.type !== "floe-html-ready" || i.data?.token !== n || i.ports.length !== 1 || (o = i.ports[0], M(o), o.onmessage = (f) => {
83
- if (r.signal.aborted) return;
84
- const a = f.data;
85
- if (a?.type === "document-loaded") {
86
- if (d) return;
87
- d = !0, s = requestAnimationFrame(() => {
88
- s = requestAnimationFrame(() => {
89
- r.signal.aborted || H(n);
109
+ token: r
110
+ } = b(), a = new AbortController();
111
+ let i, t = 0, c = 0, u = !1, l = 0;
112
+ h(""), p = (s) => {
113
+ !s.isTrusted || s.source !== y.contentWindow || i || s.data?.type !== "floe-html-ready" || s.data?.token !== r || s.ports.length !== 1 || (i = s.ports[0], T(i), e.onSearchReady?.({
114
+ search: (d, n = 0) => {
115
+ a.signal.aborted || e.inert || e.active === !1 || !o() || i?.postMessage({
116
+ type: "search",
117
+ query: d,
118
+ direction: n,
119
+ request: ++l
120
+ });
121
+ },
122
+ clear: () => {
123
+ a.signal.aborted || (l++, i?.postMessage({
124
+ type: "clear-search"
125
+ }));
126
+ }
127
+ }), i.onmessage = (d) => {
128
+ if (a.signal.aborted) return;
129
+ const n = d.data;
130
+ if (n?.type === "document-loaded") {
131
+ if (u) return;
132
+ u = !0, c = requestAnimationFrame(() => {
133
+ c = requestAnimationFrame(() => {
134
+ a.signal.aborted || L(r);
90
135
  });
91
136
  });
92
137
  return;
93
138
  }
94
- if (t.inert || t.active === !1 || !l()) return;
95
- if (a?.type === "anchor-opened") {
96
- c("");
139
+ if (e.inert || e.active === !1 || !o()) return;
140
+ if (n?.type === "search-state") {
141
+ n.request === l && Number.isSafeInteger(n.current) && Number.isSafeInteger(n.total) && n.current >= 0 && n.current <= n.total && e.onSearchState?.({
142
+ current: n.current,
143
+ total: n.total
144
+ });
145
+ return;
146
+ }
147
+ if (n?.type === "search-open" || n?.type === "search-close") {
148
+ e.onSearchRequest?.(n.type === "search-open" ? "open" : "close");
149
+ return;
150
+ }
151
+ if (n?.type === "anchor-opened") {
152
+ h("");
97
153
  return;
98
154
  }
99
- if (a?.type === "anchor-missing") {
100
- c(t.labels?.anchorUnavailable ?? "The linked section was not found.");
155
+ if (n?.type === "anchor-missing") {
156
+ h(e.labels?.anchorUnavailable ?? "The linked section was not found.");
101
157
  return;
102
158
  }
103
- if (a?.type !== "open-link" || typeof a.href != "string" || a.href.length > 8192) return;
104
- const v = a.href, u = t.onOpenLink, h = t.labels?.linkUnavailable, I = ++e;
105
- c(""), Promise.resolve().then(() => {
106
- if (!r.signal.aborted) {
107
- if (!u) throw new Error(h ?? "Opening links is unavailable in this preview.");
108
- return u(v, r.signal);
159
+ if (n?.type !== "open-link" || typeof n.href != "string" || n.href.length > 8192) return;
160
+ const m = n.href, g = e.onOpenLink, q = e.labels?.linkUnavailable, O = ++t;
161
+ h(""), Promise.resolve().then(() => {
162
+ if (!a.signal.aborted) {
163
+ if (!g) throw new Error(q ?? "Opening links is unavailable in this preview.");
164
+ return g(m, a.signal);
109
165
  }
110
- }).catch((w) => {
111
- !r.signal.aborted && I === e && c(w instanceof Error && w.message ? w.message : h ?? "This link could not be opened.");
166
+ }).catch((E) => {
167
+ !a.signal.aborted && O === t && h(E instanceof Error && E.message ? E.message : q ?? "This link could not be opened.");
112
168
  });
113
- }, o.start());
114
- }, C(() => {
115
- r.abort(), cancelAnimationFrame(s), o?.close(), M(void 0), y = void 0;
169
+ }, i.start());
170
+ }, I(() => {
171
+ a.abort(), cancelAnimationFrame(c), i?.close(), T(void 0), p = void 0, e.onSearchReady?.(void 0);
116
172
  });
117
173
  });
118
- const F = (n) => y?.(n);
119
- return N(() => {
120
- window.addEventListener("message", F), C(() => window.removeEventListener("message", F));
174
+ const C = (r) => p?.(r);
175
+ return D(() => {
176
+ window.addEventListener("message", C), I(() => window.removeEventListener("message", C));
121
177
  }), (() => {
122
- var n = V(), r = n.firstChild;
123
- g(n, L(q, {
178
+ var r = J(), a = r.firstChild;
179
+ v(r, M(H, {
124
180
  get when() {
125
- return !l();
181
+ return !o();
126
182
  },
127
183
  get children() {
128
- var e = z();
129
- return g(e, () => t.renderPending?.()), e;
184
+ var t = j();
185
+ return v(t, () => e.renderPending?.()), t;
130
186
  }
131
- }), r);
132
- var o = p;
133
- return typeof o == "function" ? R(o, r) : p = r, g(n, L(q, {
187
+ }), a);
188
+ var i = y;
189
+ return typeof i == "function" ? Q(i, a) : y = a, v(r, M(H, {
134
190
  get when() {
135
191
  return x();
136
192
  },
137
193
  get children() {
138
- var e = J();
139
- return g(e, x), e;
194
+ var t = z();
195
+ return v(t, x), t;
140
196
  }
141
- }), null), O((e) => {
142
- var s = l() ? "ready" : "loading", d = !l(), i = t.class, f = t.title, a = b().html, v = t.inert || t.active === !1 || !l(), u = t.inert || t.active === !1 || !l() ? -1 : t.tabIndex, h = {
143
- ...t.style,
144
- opacity: l() ? void 0 : "0"
197
+ }), null), A((t) => {
198
+ var c = o() ? "ready" : "loading", u = !o(), l = e.class, s = e.title, d = b().html, n = e.inert || e.active === !1 || !o(), m = e.inert || e.active === !1 || !o() ? -1 : e.tabIndex, g = {
199
+ ...e.style,
200
+ opacity: o() ? void 0 : "0"
145
201
  };
146
- return s !== e.e && m(n, "data-floe-html-state", e.e = s), d !== e.t && m(n, "aria-busy", e.t = d), i !== e.a && P(r, e.a = i), f !== e.o && m(r, "title", e.o = f), a !== e.i && m(r, "srcdoc", e.i = a), v !== e.n && (r.inert = e.n = v), u !== e.s && m(r, "tabindex", e.s = u), e.h = U(r, h, e.h), e;
202
+ return c !== t.e && f(r, "data-floe-html-state", t.e = c), u !== t.t && f(r, "aria-busy", t.t = u), l !== t.a && N(a, t.a = l), s !== t.o && f(a, "title", t.o = s), d !== t.i && f(a, "srcdoc", t.i = d), n !== t.n && (a.inert = t.n = n), m !== t.s && f(a, "tabindex", t.s = m), t.h = P(a, g, t.h), t;
147
203
  }, {
148
204
  e: void 0,
149
205
  t: void 0,
@@ -153,9 +209,9 @@ function Y(t) {
153
209
  n: void 0,
154
210
  s: void 0,
155
211
  h: void 0
156
- }), n;
212
+ }), r;
157
213
  })();
158
214
  }
159
215
  export {
160
- Y as SandboxedHtmlFrame
216
+ ee as SandboxedHtmlFrame
161
217
  };
@@ -32,6 +32,8 @@ export declare function ContextMenuActions(props: {
32
32
  actions: (request: ContextMenuRequest) => readonly ContextMenuAction[];
33
33
  enabled?: boolean;
34
34
  zIndex?: number;
35
+ /** Only the fallback menu changes scope; contributed local menus keep their owner. */
36
+ portalScope?: 'surface' | 'viewport';
35
37
  editing?: {
36
38
  labels: ContextMenuEditingLabels;
37
39
  onError: (error: unknown) => void;
@@ -1,77 +1,80 @@
1
- import { createComponent as f, insert as b, effect as E, className as k, setAttribute as M, memo as q, template as L, delegateEvents as F } from "solid-js/web";
1
+ import { createComponent as f, insert as b, effect as E, className as k, setAttribute as M, memo as $, template as S, delegateEvents as F } from "solid-js/web";
2
2
  import { useResizeObserver as H } from "../../hooks/useResizeObserver.js";
3
- import { Show as T, useContext as A, For as p, createSignal as D, onMount as R, onCleanup as z, createContext as P, createMemo as K } from "solid-js";
4
- import { SurfaceFloatingLayer as N } from "./SurfaceFloatingLayer.js";
3
+ import { Show as T, useContext as A, For as p, createSignal as D, onMount as R, onCleanup as q, createContext as N, createMemo as P } from "solid-js";
4
+ import { SurfaceFloatingLayer as K } from "./SurfaceFloatingLayer.js";
5
5
  import { handleMenuKeyboardNavigation as _ } from "./menuUtils.js";
6
- var B = /* @__PURE__ */ L("<span aria-hidden=true>"), O = /* @__PURE__ */ L("<button type=button role=menuitem><span>"), X = /* @__PURE__ */ L("<button type=button role=menuitem class=floe-context-action><span>");
7
- const C = P(), W = () => A(C);
8
- function I(e) {
6
+ var B = /* @__PURE__ */ S("<span aria-hidden=true>"), O = /* @__PURE__ */ S("<button type=button role=menuitem><span>"), X = /* @__PURE__ */ S("<button type=button role=menuitem class=floe-context-action><span>");
7
+ const L = N(), W = () => A(L);
8
+ function z(e) {
9
9
  return f(T, {
10
10
  get when() {
11
11
  return e.icon;
12
12
  },
13
- children: (i) => (() => {
14
- var a = B();
15
- return b(a, () => i()()), E(() => k(a, `floe-context-action-icon ${e.class ?? ""}`)), a;
13
+ children: (r) => (() => {
14
+ var s = B();
15
+ return b(s, () => r()()), E(() => k(s, `floe-context-action-icon ${e.class ?? ""}`)), s;
16
16
  })()
17
17
  });
18
18
  }
19
19
  function Z(e) {
20
- let i, a, r;
21
- const c = /* @__PURE__ */ new Set(), [t, o] = D(), u = () => {
22
- const n = i;
23
- return i = void 0, a = void 0, r = void 0, n;
24
- }, s = (n) => {
25
- if (e.enabled === !1 || n.defaultPrevented || n instanceof KeyboardEvent && n.key !== "ContextMenu" && !(n.shiftKey && n.key === "F10")) return;
26
- const l = n.composedPath().find((h) => h instanceof HTMLElement);
27
- if (!l || l.closest('[inert], [hidden], [role="menu"], [data-floe-context-menu-native]')) return;
28
- const g = l.getBoundingClientRect(), d = n instanceof MouseEvent && (n.clientX !== 0 || n.clientY !== 0), v = l instanceof HTMLInputElement || l instanceof HTMLTextAreaElement ? l instanceof HTMLInputElement && l.type === "password" ? "" : l.value.slice(l.selectionStart ?? 0, l.selectionEnd ?? 0) : (() => {
20
+ let r, s, c;
21
+ const i = /* @__PURE__ */ new Set(), [n, o] = D(), u = () => {
22
+ const t = r;
23
+ return r = void 0, s = void 0, c = void 0, t;
24
+ }, l = (t) => {
25
+ if (e.enabled === !1 || t.defaultPrevented || t instanceof KeyboardEvent && t.key !== "ContextMenu" && !(t.shiftKey && t.key === "F10")) return;
26
+ const a = t.composedPath().find((h) => h instanceof HTMLElement);
27
+ if (!a || a.closest('[inert], [hidden], [role="menu"], [data-floe-context-menu-native]')) return;
28
+ const g = a.getBoundingClientRect(), d = t instanceof MouseEvent && (t.clientX !== 0 || t.clientY !== 0), v = a instanceof HTMLInputElement || a instanceof HTMLTextAreaElement ? a instanceof HTMLInputElement && a.type === "password" ? "" : a.value.slice(a.selectionStart ?? 0, a.selectionEnd ?? 0) : (() => {
29
29
  const h = document.getSelection();
30
- return h?.rangeCount && h.getRangeAt(0).intersectsNode(l) ? h.toString() : "";
30
+ return h?.rangeCount && h.getRangeAt(0).intersectsNode(a) ? h.toString() : "";
31
31
  })(), w = {
32
- target: l,
33
- x: d ? n.clientX : g.left + 8,
34
- y: d ? n.clientY : g.bottom,
32
+ target: a,
33
+ x: d ? t.clientX : g.left + 8,
34
+ y: d ? t.clientY : g.bottom,
35
35
  selection: v
36
- }, y = e.actions(w), x = {
36
+ }, C = e.actions(w), x = {
37
37
  origin: w,
38
- actions: y
39
- }, $ = {
38
+ actions: C
39
+ }, I = {
40
40
  origin: w,
41
- actions: [...y, ...e.editing ? j(w, e.editing.labels, e.editing.onError) : []]
41
+ actions: [...C, ...e.editing ? j(w, e.editing.labels, e.editing.onError) : []]
42
42
  };
43
43
  if (!x.actions.length) return;
44
- i = x, a = n, r = $;
45
- const S = setTimeout(() => {
46
- i === x && (i = void 0, a = void 0, r = void 0), c.delete(S);
44
+ r = x, s = t, c = I;
45
+ const y = setTimeout(() => {
46
+ r === x && (r = void 0, s = void 0, c = void 0), i.delete(y);
47
47
  }, 0);
48
- c.add(S);
49
- }, m = (n) => {
50
- i && a === n && !n.defaultPrevented && (n.preventDefault(), o(r), u());
48
+ i.add(y);
49
+ }, m = (t) => {
50
+ r && s === t && !t.defaultPrevented && (t.preventDefault(), o(c), u());
51
51
  };
52
52
  return R(() => {
53
- document.addEventListener("contextmenu", s, !0), document.addEventListener("keydown", s, !0), window.addEventListener("contextmenu", m), window.addEventListener("keydown", m), z(() => {
54
- c.forEach(clearTimeout), i = void 0, a = void 0, r = void 0, document.removeEventListener("contextmenu", s, !0), document.removeEventListener("keydown", s, !0), window.removeEventListener("contextmenu", m), window.removeEventListener("keydown", m);
53
+ document.addEventListener("contextmenu", l, !0), document.addEventListener("keydown", l, !0), window.addEventListener("contextmenu", m), window.addEventListener("keydown", m), q(() => {
54
+ i.forEach(clearTimeout), r = void 0, s = void 0, c = void 0, document.removeEventListener("contextmenu", l, !0), document.removeEventListener("keydown", l, !0), window.removeEventListener("contextmenu", m), window.removeEventListener("keydown", m);
55
55
  });
56
- }), f(C.Provider, {
56
+ }), f(L.Provider, {
57
57
  value: {
58
58
  claim: u,
59
- resolve: (n) => e.enabled === !1 ? [] : e.actions(n)
59
+ resolve: (t) => e.enabled === !1 ? [] : e.actions(t)
60
60
  },
61
61
  get children() {
62
- return [q(() => e.children), f(T, {
62
+ return [$(() => e.children), f(T, {
63
63
  get when() {
64
- return t();
64
+ return n();
65
65
  },
66
66
  keyed: !0,
67
- children: (n) => f(Y, {
68
- request: n,
67
+ children: (t) => f(Y, {
68
+ request: t,
69
69
  get label() {
70
70
  return e.label;
71
71
  },
72
72
  get zIndex() {
73
73
  return e.zIndex;
74
74
  },
75
+ get portalScope() {
76
+ return e.portalScope;
77
+ },
75
78
  onClose: () => o(void 0)
76
79
  })
77
80
  })];
@@ -79,73 +82,78 @@ function Z(e) {
79
82
  });
80
83
  }
81
84
  function ee(e) {
82
- const i = A(C)?.claim(), a = () => i?.actions.filter((r) => !e.excludeIds?.includes(r.id)) ?? [];
85
+ const r = A(L)?.claim(), s = () => r?.actions.filter((c) => !e.excludeIds?.includes(c.id)) ?? [];
83
86
  return f(p, {
84
87
  get each() {
85
- return a();
88
+ return s();
86
89
  },
87
- children: (r) => (() => {
88
- var c = O(), t = c.firstChild;
89
- return c.$$click = () => {
90
- e.onClose(), r.onSelect();
91
- }, b(c, f(I, {
90
+ children: (c) => (() => {
91
+ var i = O(), n = i.firstChild;
92
+ return i.$$click = () => {
93
+ e.onClose(), c.onSelect();
94
+ }, b(i, f(z, {
92
95
  get icon() {
93
- return r.icon;
96
+ return c.icon;
94
97
  }
95
- }), t), b(t, () => r.label), E((o) => {
96
- var u = e.itemClass ?? "floe-context-action", s = r.id, m = r.disabled;
97
- return u !== o.e && k(c, o.e = u), s !== o.t && M(c, "data-context-action-id", o.t = s), m !== o.a && (c.disabled = o.a = m), o;
98
+ }), n), b(n, () => c.label), E((o) => {
99
+ var u = e.itemClass ?? "floe-context-action", l = c.id, m = c.disabled;
100
+ return u !== o.e && k(i, o.e = u), l !== o.t && M(i, "data-context-action-id", o.t = l), m !== o.a && (i.disabled = o.a = m), o;
98
101
  }, {
99
102
  e: void 0,
100
103
  t: void 0,
101
104
  a: void 0
102
- }), c;
105
+ }), i;
103
106
  })()
104
107
  });
105
108
  }
106
109
  function Y(e) {
107
- let i;
108
- const a = H(() => i), r = K(() => {
109
- if (!a() || !i) return {
110
+ let r;
111
+ const s = H(() => r), c = P(() => {
112
+ if (!s() || !r) return {
110
113
  width: 208,
111
114
  height: 8 + e.request.actions.length * 30
112
115
  };
113
- const t = i.getBoundingClientRect();
116
+ const n = r.getBoundingClientRect();
114
117
  return {
115
- width: t.width,
116
- height: t.height
118
+ width: n.width,
119
+ height: n.height
117
120
  };
118
- }), c = (t = !1) => {
119
- e.onClose(), t && e.request.origin.target.isConnected && e.request.origin.target.focus({
121
+ }), i = (n = !1) => {
122
+ e.onClose(), n && e.request.origin.target.isConnected && e.request.origin.target.focus({
120
123
  preventScroll: !0
121
124
  });
122
125
  };
123
126
  return R(() => {
124
- i.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
127
+ r.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
125
128
  preventScroll: !0
126
129
  });
127
- const t = (u) => {
128
- u.target instanceof Node && !i.contains(u.target) && c();
129
- }, o = () => c();
130
- document.addEventListener("pointerdown", t, !0), document.addEventListener("focusin", t, !0), document.addEventListener("scroll", t, !0), window.addEventListener("resize", o), window.addEventListener("blur", o), z(() => {
131
- document.removeEventListener("pointerdown", t, !0), document.removeEventListener("focusin", t, !0), document.removeEventListener("scroll", t, !0), window.removeEventListener("resize", o), window.removeEventListener("blur", o);
130
+ const n = (l) => {
131
+ l.target instanceof Node && !r.contains(l.target) && i();
132
+ }, o = (l) => {
133
+ l.target instanceof Node && l.target.contains(e.request.origin.target) && i();
134
+ }, u = () => i();
135
+ document.addEventListener("pointerdown", n, !0), document.addEventListener("focusin", n, !0), document.addEventListener("scroll", o, !0), window.addEventListener("resize", u), window.addEventListener("blur", u), q(() => {
136
+ document.removeEventListener("pointerdown", n, !0), document.removeEventListener("focusin", n, !0), document.removeEventListener("scroll", o, !0), window.removeEventListener("resize", u), window.removeEventListener("blur", u);
132
137
  });
133
- }), f(N, {
138
+ }), f(K, {
134
139
  get owner() {
135
140
  return e.request.origin.target;
136
141
  },
142
+ get portalScope() {
143
+ return e.portalScope;
144
+ },
137
145
  get position() {
138
146
  return e.request.origin;
139
147
  },
140
148
  get estimatedSize() {
141
- return r();
149
+ return c();
142
150
  },
143
151
  role: "menu",
144
152
  get "aria-label"() {
145
153
  return e.label;
146
154
  },
147
- layerRef: (t) => {
148
- i = t;
155
+ layerRef: (n) => {
156
+ r = n;
149
157
  },
150
158
  class: "floe-context-actions",
151
159
  get style() {
@@ -153,10 +161,10 @@ function Y(e) {
153
161
  "z-index": e.zIndex
154
162
  };
155
163
  },
156
- onContextMenu: (t) => t.preventDefault(),
157
- onKeyDown: (t) => _(t, {
164
+ onContextMenu: (n) => n.preventDefault(),
165
+ onKeyDown: (n) => _(n, {
158
166
  onActivate: (o) => o.click(),
159
- onDismiss: () => c(!0),
167
+ onDismiss: () => i(!0),
160
168
  preventDefaultOnTab: !0
161
169
  }),
162
170
  get children() {
@@ -164,17 +172,17 @@ function Y(e) {
164
172
  get each() {
165
173
  return e.request.actions;
166
174
  },
167
- children: (t) => (() => {
175
+ children: (n) => (() => {
168
176
  var o = X(), u = o.firstChild;
169
177
  return o.$$click = () => {
170
- c(), t.onSelect();
171
- }, b(o, f(I, {
178
+ i(), n.onSelect();
179
+ }, b(o, f(z, {
172
180
  get icon() {
173
- return t.icon;
181
+ return n.icon;
174
182
  }
175
- }), u), b(u, () => t.label), E((s) => {
176
- var m = t.id, n = t.disabled;
177
- return m !== s.e && M(o, "data-context-action-id", s.e = m), n !== s.t && (o.disabled = s.t = n), s;
183
+ }), u), b(u, () => n.label), E((l) => {
184
+ var m = n.id, t = n.disabled;
185
+ return m !== l.e && M(o, "data-context-action-id", l.e = m), t !== l.t && (o.disabled = l.t = t), l;
178
186
  }, {
179
187
  e: void 0,
180
188
  t: void 0
@@ -184,58 +192,58 @@ function Y(e) {
184
192
  }
185
193
  });
186
194
  }
187
- function j(e, i, a) {
188
- const r = e.target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'), c = r instanceof HTMLInputElement || r instanceof HTMLTextAreaElement ? r : null, t = document.getSelection()?.rangeCount ? document.getSelection().getRangeAt(0).cloneRange() : void 0, o = c?.selectionStart, u = c?.selectionEnd, s = () => {
189
- if (r?.focus({
195
+ function j(e, r, s) {
196
+ const c = e.target.closest('input, textarea, [contenteditable]:not([contenteditable="false"])'), i = c instanceof HTMLInputElement || c instanceof HTMLTextAreaElement ? c : null, n = document.getSelection()?.rangeCount ? document.getSelection().getRangeAt(0).cloneRange() : void 0, o = i?.selectionStart, u = i?.selectionEnd, l = () => {
197
+ if (c?.focus({
190
198
  preventScroll: !0
191
- }), c && o != null && u != null) c.setSelectionRange(o, u);
192
- else if (t) {
199
+ }), i && o != null && u != null) i.setSelectionRange(o, u);
200
+ else if (n) {
193
201
  const d = document.getSelection();
194
- d?.removeAllRanges(), d?.addRange(t);
202
+ d?.removeAllRanges(), d?.addRange(n);
195
203
  }
196
204
  }, m = (d) => () => {
197
205
  try {
198
- Promise.resolve(d()).catch(a);
206
+ Promise.resolve(d()).catch(s);
199
207
  } catch (v) {
200
- a(v);
208
+ s(v);
201
209
  }
202
- }, n = (d) => ({
210
+ }, t = (d) => ({
203
211
  id: `edit.${d}`,
204
- label: i[d],
212
+ label: r[d],
205
213
  onSelect: m(async () => {
206
- if (s(), d === "selectAll" && c) {
207
- c.select();
214
+ if (l(), d === "selectAll" && i) {
215
+ i.select();
208
216
  return;
209
217
  }
210
218
  if (document.execCommand(d) || d !== "paste") return;
211
219
  const v = await navigator.clipboard.readText();
212
- if (r?.isConnected && (s(), !document.execCommand("insertText", !1, v)))
220
+ if (c?.isConnected && (l(), !document.execCommand("insertText", !1, v)))
213
221
  throw new Error("Clipboard insertion is unavailable.");
214
222
  })
215
- }), l = [];
216
- r && l.push(n("undo"), n("redo"), n("cut")), e.selection && l.push({
223
+ }), a = [];
224
+ c && a.push(t("undo"), t("redo"), t("cut")), e.selection && a.push({
217
225
  id: "edit.copy",
218
- label: i.copy,
226
+ label: r.copy,
219
227
  onSelect: m(() => navigator.clipboard.writeText(e.selection))
220
- }), r && l.push(n("paste"), n("selectAll"));
228
+ }), c && a.push(t("paste"), t("selectAll"));
221
229
  const g = e.target.closest("a[href]");
222
230
  if (g && ["http:", "https:", "mailto:"].includes(g.protocol)) {
223
231
  const d = g.href;
224
- l.push({
232
+ a.push({
225
233
  id: "link.open",
226
- label: i.openLink,
234
+ label: r.openLink,
227
235
  onSelect: () => window.open(d, "_blank", "noopener,noreferrer")
228
- }), l.push({
236
+ }), a.push({
229
237
  id: "link.copy",
230
- label: i.copyLink,
238
+ label: r.copyLink,
231
239
  onSelect: m(() => navigator.clipboard.writeText(d))
232
240
  });
233
241
  }
234
- return l;
242
+ return a;
235
243
  }
236
244
  F(["click"]);
237
245
  export {
238
- I as ContextMenuActionIcon,
246
+ z as ContextMenuActionIcon,
239
247
  ee as ContextMenuActionItems,
240
248
  Z as ContextMenuActions,
241
249
  W as useContextMenuActions
@@ -12,6 +12,8 @@ export interface SurfaceFloatingLayerProps extends Omit<JSX.HTMLAttributes<HTMLD
12
12
  position: SurfaceFloatingLayerPosition;
13
13
  /** Stable trigger or anchor used to resolve the owning projected surface. */
14
14
  owner?: Element | null;
15
+ /** Global commands may escape their source surface without changing the owner. */
16
+ portalScope?: 'surface' | 'viewport';
15
17
  boundary?: SurfaceFloatingBoundary;
16
18
  estimatedSize?: SurfaceFloatingLayerSize;
17
19
  clamp?: boolean;
@@ -1,12 +1,12 @@
1
- import { createComponent as S, Portal as v, use as h, spread as g, mergeProps as A, insert as P, template as R } from "solid-js/web";
2
- import { observeViewport as w } from "../../viewport.js";
1
+ import { createComponent as S, Portal as v, use as h, spread as g, mergeProps as w, insert as A, template as P } from "solid-js/web";
2
+ import { observeViewport as R } from "../../viewport.js";
3
3
  import { splitProps as _, createSignal as b, onMount as x, onCleanup as C, createMemo as s } from "solid-js";
4
4
  import { cn as T } from "../../utils/cn.js";
5
5
  import { LOCAL_INTERACTION_SURFACE_ATTR as z } from "./localInteractionSurface.js";
6
6
  import { clampMenuPosition as M } from "./menuUtils.js";
7
- import { readSurfaceSafeArea as F, resolveFloatingBoundary as L } from "./surfaceFloatingBoundary.js";
8
- import { resolveSurfacePortalHost as $, SURFACE_FLOATING_LAYER_ATTR as E, resolveSurfacePortalMount as O, isSurfacePortalMode as B, projectSurfacePortalPosition as I } from "./dialogSurfaceScope.js";
9
- var N = /* @__PURE__ */ R("<div>");
7
+ import { readSurfaceSafeArea as E, resolveFloatingBoundary as F } from "./surfaceFloatingBoundary.js";
8
+ import { resolveSurfacePortalHost as L, SURFACE_FLOATING_LAYER_ATTR as $, resolveSurfacePortalMount as O, isSurfacePortalMode as B, projectSurfacePortalPosition as I } from "./dialogSurfaceScope.js";
9
+ var N = /* @__PURE__ */ P("<div>");
10
10
  function j() {
11
11
  return {
12
12
  left: 0,
@@ -18,11 +18,11 @@ function j() {
18
18
  };
19
19
  }
20
20
  function J(c) {
21
- const [e, f] = _(c, ["position", "owner", "boundary", "estimatedSize", "clamp", "class", "style", "children", "layerRef"]), [a, p] = b();
22
- x(() => C(w(window, p)));
23
- const r = s(() => $({
24
- owner: e.owner ?? null
25
- })), n = () => B(r()), u = s(() => (e.position, a()?.safeArea ?? F())), i = () => L(r(), e.boundary, u()) ?? j(), m = () => e.clamp !== !1 && !!e.estimatedSize, d = s(() => {
21
+ const [e, p] = _(c, ["position", "owner", "portalScope", "boundary", "estimatedSize", "clamp", "class", "style", "children", "layerRef"]), [a, u] = b();
22
+ x(() => C(R(window, u)));
23
+ const r = s(() => L({
24
+ owner: e.portalScope === "viewport" ? document.documentElement : e.owner ?? null
25
+ })), n = () => B(r()), f = s(() => (e.position, a()?.safeArea ?? E())), i = () => F(r(), e.boundary, f()) ?? j(), m = () => e.clamp !== !1 && !!e.estimatedSize, d = s(() => {
26
26
  const t = e.position;
27
27
  return !m() || !e.estimatedSize ? t : M(t, e.estimatedSize, i());
28
28
  }), l = () => {
@@ -46,7 +46,7 @@ function J(c) {
46
46
  },
47
47
  get children() {
48
48
  var t = N(), o = e.layerRef;
49
- return typeof o == "function" ? h(o, t) : e.layerRef = t, g(t, A(f, {
49
+ return typeof o == "function" ? h(o, t) : e.layerRef = t, g(t, w(p, {
50
50
  get class() {
51
51
  return T(n() ? "absolute z-20" : "fixed z-50", e.class);
52
52
  },
@@ -54,10 +54,10 @@ function J(c) {
54
54
  return y();
55
55
  }
56
56
  }, {
57
- [E]: "true"
57
+ [$]: "true"
58
58
  }, () => ({
59
59
  [z]: n() ? "true" : void 0
60
- })), !1, !0), P(t, () => e.children), t;
60
+ })), !1, !0), A(t, () => e.children), t;
61
61
  }
62
62
  });
63
63
  }
@@ -2,7 +2,16 @@ import { type Accessor } from 'solid-js';
2
2
  /** Literal rendered-text matching; inline markup can split a match, blocks cannot. */
3
3
  export declare function findTextRanges(root: HTMLElement, query: string): Range[];
4
4
  export interface TextSearchOptions {
5
- content: Accessor<HTMLElement | undefined>;
5
+ content?: Accessor<HTMLElement | undefined>;
6
+ /** External document engines retain ownership of indexing, navigation and highlights. */
7
+ engine?: {
8
+ state: Accessor<{
9
+ current: number;
10
+ total: number;
11
+ }>;
12
+ search: (query: string, direction: -1 | 0 | 1) => void;
13
+ clear: () => void;
14
+ };
6
15
  viewport?: Accessor<HTMLElement | undefined>;
7
16
  active?: Accessor<boolean>;
8
17
  identity?: Accessor<unknown>;
@@ -1,22 +1,22 @@
1
- import { createSignal as C, createUniqueId as K, createEffect as E, batch as k, onCleanup as D, on as L, untrack as M } from "solid-js";
2
- function N(l, s) {
1
+ import { createSignal as E, createUniqueId as K, createEffect as x, batch as k, onCleanup as D, on as L, untrack as M } from "solid-js";
2
+ function N(r, s) {
3
3
  if (!s) return [];
4
- const x = new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "giu"), y = [];
5
- let f = "", c = [];
4
+ const w = new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "giu"), u = [];
5
+ let g = "", o = [];
6
6
  const b = () => {
7
- let i = 0, a = 0;
8
- for (const g of f.matchAll(x)) {
9
- const r = g.index, u = r + g[0].length;
10
- for (; c[i].end <= r; ) i++;
11
- for (a = Math.max(i, a); c[a].end < u; ) a++;
12
- const m = c[i], p = c[a], h = l.ownerDocument.createRange();
13
- h.setStart(m.node, r - m.start), h.setEnd(p.node, u - p.start), y.push(h);
7
+ let i = 0, l = 0;
8
+ for (const m of g.matchAll(w)) {
9
+ const c = m.index, d = c + m[0].length;
10
+ for (; o[i].end <= c; ) i++;
11
+ for (l = Math.max(i, l); o[l].end < d; ) l++;
12
+ const p = o[i], y = o[l], f = r.ownerDocument.createRange();
13
+ f.setStart(p.node, c - p.start), f.setEnd(y.node, d - y.start), u.push(f);
14
14
  }
15
- f = "", c = [];
16
- }, w = (i) => {
15
+ g = "", o = [];
16
+ }, C = (i) => {
17
17
  if (i.nodeType === Node.TEXT_NODE) {
18
- const r = i.textContent ?? "";
19
- r && (c.push({ node: i, start: f.length, end: f.length + r.length }), f += r);
18
+ const c = i.textContent ?? "";
19
+ c && (o.push({ node: i, start: g.length, end: g.length + c.length }), g += c);
20
20
  return;
21
21
  }
22
22
  if (!(i instanceof HTMLElement)) return;
@@ -24,86 +24,92 @@ function N(l, s) {
24
24
  b();
25
25
  return;
26
26
  }
27
- const a = getComputedStyle(i);
28
- if (a.display === "none" || a.visibility === "hidden") return;
29
- const g = !["inline", "contents"].includes(a.display) || i.tagName === "BR";
30
- g && b(), i.childNodes.forEach(w), g && b();
27
+ const l = getComputedStyle(i);
28
+ if (l.display === "none" || l.visibility === "hidden") return;
29
+ const m = !["inline", "contents"].includes(l.display) || i.tagName === "BR";
30
+ m && b(), i.childNodes.forEach(C), m && b();
31
31
  };
32
- return l.childNodes.forEach(w), b(), y;
32
+ return r.childNodes.forEach(C), b(), u;
33
33
  }
34
- function $(l) {
35
- const [s, x] = C(!1), [y, f] = C(""), [c, b] = C([]), [w, i] = C(0), [a, g] = C(0), r = "floe-find-" + K().replace(/[^a-zA-Z0-9-]/g, "");
36
- let u, m, p = 0, h;
37
- const A = () => l.identity?.(), d = () => l.active?.() !== !1, S = () => {
38
- globalThis.CSS?.highlights?.delete(r), globalThis.CSS?.highlights?.delete(r + "-current");
39
- }, H = (t) => {
40
- const n = l.viewport?.() ?? l.content();
41
- if (!t || !n || !d()) return;
42
- const e = n.getBoundingClientRect(), o = t.getBoundingClientRect(), F = e.width / n.offsetWidth || 1, I = e.height / n.offsetHeight || 1;
43
- (o.top < e.top + 8 || o.bottom > e.bottom - 8) && (n.scrollTop += (o.top - e.top - e.height / 2) / I), (o.left < e.left || o.right > e.right) && (n.scrollLeft += (o.left - e.left - e.width / 2) / F);
34
+ function $(r) {
35
+ const [s, w] = E(!1), [u, g] = E(""), [o, b] = E([]), [C, i] = E(0), [l, m] = E(0), c = "floe-find-" + K().replace(/[^a-zA-Z0-9-]/g, "");
36
+ let d, p, y = 0, f;
37
+ const A = () => r.identity?.(), h = () => r.active?.() !== !1, S = () => {
38
+ globalThis.CSS?.highlights?.delete(c), globalThis.CSS?.highlights?.delete(c + "-current");
39
+ }, H = (e) => {
40
+ const n = r.viewport?.() ?? r.content?.();
41
+ if (!e || !n || !h()) return;
42
+ const t = n.getBoundingClientRect(), a = e.getBoundingClientRect(), F = t.width / n.offsetWidth || 1, I = t.height / n.offsetHeight || 1;
43
+ (a.top < t.top + 8 || a.bottom > t.bottom - 8) && (n.scrollTop += (a.top - t.top - t.height / 2) / I), (a.left < t.left || a.right > t.right) && (n.scrollLeft += (a.left - t.left - t.width / 2) / F);
44
44
  }, T = () => {
45
- x(!1), S(), d() && m?.isConnected && !m.closest("[inert]") && m.focus({ preventScroll: !0 });
46
- }, R = (t) => {
47
- d() && (s() || (m = t ?? (document.activeElement instanceof HTMLElement ? document.activeElement : void 0)), x(!0), queueMicrotask(() => {
48
- M(s) && M(d) && u?.isConnected && (u.focus(), u.select());
45
+ w(!1), S(), r.engine?.clear(), h() && p?.isConnected && !p.closest("[inert]") && p.focus({ preventScroll: !0 });
46
+ }, R = (e) => {
47
+ h() && (s() || (p = e ?? (document.activeElement instanceof HTMLElement ? document.activeElement : void 0)), w(!0), queueMicrotask(() => {
48
+ M(s) && M(h) && d?.isConnected && (d.focus(), d.select());
49
49
  }));
50
- }, v = (t) => {
51
- const n = c().length;
52
- n && i((e) => (e + t + n) % n);
50
+ }, v = (e) => {
51
+ if (r.engine) {
52
+ h() && r.engine.search(u(), e);
53
+ return;
54
+ }
55
+ const n = o().length;
56
+ n && i((t) => (t + e + n) % n);
53
57
  };
54
- return E(() => {
58
+ return x(() => {
55
59
  A(), k(() => {
56
- x(!1), f(""), i(0);
60
+ w(!1), g(""), i(0);
57
61
  });
58
- }), E(() => {
59
- const t = l.content();
60
- if (!t || !s() || !d()) return;
62
+ }), x(() => {
63
+ r.engine && (s() && h() ? r.engine.search(u(), 0) : r.engine.clear());
64
+ }), x(() => {
65
+ const e = r.content?.();
66
+ if (!e || !s() || !h()) return;
61
67
  const n = new MutationObserver(() => {
62
- cancelAnimationFrame(p), p = requestAnimationFrame(() => g((e) => e + 1));
68
+ cancelAnimationFrame(y), y = requestAnimationFrame(() => m((t) => t + 1));
63
69
  });
64
- n.observe(t, { childList: !0, characterData: !0, subtree: !0 }), D(() => {
65
- n.disconnect(), cancelAnimationFrame(p);
70
+ n.observe(e, { childList: !0, characterData: !0, subtree: !0 }), D(() => {
71
+ n.disconnect(), cancelAnimationFrame(y);
66
72
  });
67
- }), E(() => {
68
- const t = l.content();
69
- a();
70
- const n = y();
71
- if (!s() || !d()) return;
72
- const e = t ? N(t, n) : [];
73
+ }), x(() => {
74
+ const e = r.content?.();
75
+ l();
76
+ const n = u();
77
+ if (!s() || !h()) return;
78
+ const t = e ? N(e, n) : [];
73
79
  k(() => {
74
- b(e), i((o) => Math.min(o, Math.max(0, e.length - 1)));
80
+ b(t), i((a) => Math.min(a, Math.max(0, t.length - 1)));
75
81
  });
76
- }), E(L(y, () => i(0))), E(() => {
82
+ }), x(L(u, () => i(0))), x(() => {
77
83
  S();
78
- const t = c(), n = t[w()];
79
- if (!(!s() || !d())) {
84
+ const e = o(), n = e[C()];
85
+ if (!(!s() || !h())) {
80
86
  if (typeof Highlight < "u" && CSS.highlights) {
81
- h || (h = document.createElement("style"), h.textContent = `::highlight(${r}){background:color-mix(in srgb,var(--warning,#eab308) 35%,transparent);color:inherit}::highlight(${r}-current){background:var(--primary,#2563eb);color:var(--primary-foreground,#fff)}`, document.head.append(h));
82
- const e = new Highlight();
83
- if (t.forEach((o) => e.add(o)), CSS.highlights.set(r, e), n) {
84
- const o = new Highlight(n);
85
- o.priority = 1, CSS.highlights.set(r + "-current", o);
87
+ f || (f = document.createElement("style"), f.textContent = `::highlight(${c}){background:color-mix(in srgb,var(--warning,#eab308) 35%,transparent);color:inherit}::highlight(${c}-current){background:var(--primary,#2563eb);color:var(--primary-foreground,#fff)}`, document.head.append(f));
88
+ const t = new Highlight();
89
+ if (e.forEach((a) => t.add(a)), CSS.highlights.set(c, t), n) {
90
+ const a = new Highlight(n);
91
+ a.priority = 1, CSS.highlights.set(c + "-current", a);
86
92
  }
87
93
  }
88
94
  H(n);
89
95
  }
90
96
  }), D(() => {
91
- S(), h?.remove(), cancelAnimationFrame(p);
97
+ S(), r.engine?.clear(), f?.remove(), cancelAnimationFrame(y);
92
98
  }), {
93
99
  open: s,
94
- query: y,
95
- setQuery: f,
100
+ query: u,
101
+ setQuery: g,
96
102
  show: R,
97
103
  close: T,
98
104
  next: () => v(1),
99
105
  previous: () => v(-1),
100
- count: () => c().length,
101
- current: () => c().length ? w() + 1 : 0,
102
- bindInput: (t) => {
103
- u = t;
106
+ count: () => r.engine?.state().total ?? o().length,
107
+ current: () => r.engine?.state().current ?? (o().length ? C() + 1 : 0),
108
+ bindInput: (e) => {
109
+ d = e;
104
110
  },
105
- onKeyDown: (t) => {
106
- !d() || t.isComposing || t.defaultPrevented || ((t.ctrlKey || t.metaKey) && !t.altKey && t.key.toLowerCase() === "f" ? (t.preventDefault(), t.stopPropagation(), R()) : s() && t.key === "Escape" ? (t.preventDefault(), t.stopPropagation(), T()) : s() && t.target === u && t.key === "Enter" && (t.preventDefault(), t.stopPropagation(), v(t.shiftKey ? -1 : 1)));
111
+ onKeyDown: (e) => {
112
+ !h() || e.isComposing || e.defaultPrevented || ((e.ctrlKey || e.metaKey) && !e.altKey && e.key.toLowerCase() === "f" ? (e.preventDefault(), e.stopPropagation(), R()) : s() && e.key === "Escape" ? (e.preventDefault(), e.stopPropagation(), T()) : s() && e.target === d && e.key === "Enter" && (e.preventDefault(), e.stopPropagation(), v(e.shiftKey ? -1 : 1)));
107
113
  }
108
114
  };
109
115
  }
@@ -1 +1 @@
1
- export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type SandboxedHtmlFrameLabels } from './components/html-preview/SandboxedHtmlFrame';
1
+ export { SandboxedHtmlFrame, type SandboxedHtmlFrameProps, type SandboxedHtmlSearch, type SandboxedHtmlFrameLabels } from './components/html-preview/SandboxedHtmlFrame';
package/dist/pptx.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { type TextSearchResult } from '@aiden0z/pptx-renderer/browser';
2
+ export type PptxSearchResult = TextSearchResult;
1
3
  export interface PptxSurfaceOptions {
2
4
  signal?: AbortSignal;
3
5
  onNodeError?: (nodeId: string, error: unknown) => void;
@@ -19,6 +21,8 @@ export declare class PptxDocumentSurface {
19
21
  get pageWidth(): number;
20
22
  get pageHeight(): number;
21
23
  static open(bytes: Uint8Array<ArrayBuffer>, options?: PptxSurfaceOptions): Promise<PptxDocumentSurface>;
24
+ /** Search all slides through the published renderer, including unmounted pages. */
25
+ search(query: string): PptxSearchResult[];
22
26
  renderPage(index: number, container: HTMLElement): PptxPageHandle;
23
27
  dispose(): void;
24
28
  }
package/dist/pptx.js CHANGED
@@ -1,8 +1,8 @@
1
1
  import g from "./node_modules/.pnpm/dompurify@3.4.17/node_modules/dompurify/dist/purify.es.js";
2
2
  import { parseZip as p, buildPresentation as m, PptxViewer as v, RECOMMENDED_ZIP_LIMITS as E } from "./node_modules/.pnpm/@aiden0z_pptx-renderer@1.3.0_pdfjs-dist@6.3.289/node_modules/@aiden0z/pptx-renderer/dist/aiden0z-pptx-renderer.browser.es.js";
3
3
  class f {
4
- constructor(r, s) {
5
- this.viewer = r, this.hasExternalLinks = s;
4
+ constructor(t, s) {
5
+ this.viewer = t, this.hasExternalLinks = s;
6
6
  }
7
7
  viewer;
8
8
  hasExternalLinks;
@@ -17,21 +17,21 @@ class f {
17
17
  get pageHeight() {
18
18
  return this.viewer.slideHeight;
19
19
  }
20
- static async open(r, s = {}) {
21
- if (s.signal?.throwIfAborted(), r.byteLength > 20 * 1024 * 1024)
20
+ static async open(t, s = {}) {
21
+ if (s.signal?.throwIfAborted(), t.byteLength > 20 * 1024 * 1024)
22
22
  throw new Error("Presentation exceeds the 20 MiB preview limit.");
23
- const e = await p(r.slice().buffer, E);
23
+ const e = await p(t.slice().buffer, E);
24
24
  s.signal?.throwIfAborted();
25
25
  let a = !1;
26
26
  const l = (i) => {
27
- const n = new DOMParser().parseFromString(i, "application/xml");
28
- if (n.doctype || n.querySelector("parsererror"))
27
+ const o = new DOMParser().parseFromString(i, "application/xml");
28
+ if (o.doctype || o.querySelector("parsererror"))
29
29
  throw new Error("Invalid presentation relationships.");
30
- for (const o of [...n.getElementsByTagNameNS("*", "Relationship")]) {
31
- const d = o.getAttribute("Target") ?? "";
32
- ((o.getAttribute("TargetMode") ?? "").toLowerCase() === "external" || /^(?:[a-z][a-z0-9+.-]*:|[/\\]{2})/i.test(d.trim())) && (o.remove(), a = !0);
30
+ for (const n of [...o.getElementsByTagNameNS("*", "Relationship")]) {
31
+ const d = n.getAttribute("Target") ?? "";
32
+ ((n.getAttribute("TargetMode") ?? "").toLowerCase() === "external" || /^(?:[a-z][a-z0-9+.-]*:|[/\\]{2})/i.test(d.trim())) && (n.remove(), a = !0);
33
33
  }
34
- return new XMLSerializer().serializeToString(n);
34
+ return new XMLSerializer().serializeToString(o);
35
35
  };
36
36
  e.presentationRels = l(e.presentationRels);
37
37
  for (const i of [
@@ -40,15 +40,15 @@ class f {
40
40
  e.slideMasterRels,
41
41
  e.chartRels
42
42
  ])
43
- if (i) for (const [n, o] of i) i.set(n, l(o));
44
- for (const [i, n] of e.media) {
43
+ if (i) for (const [o, n] of i) i.set(o, l(n));
44
+ for (const [i, o] of e.media) {
45
45
  if (!i.toLowerCase().endsWith(".svg")) continue;
46
- const o = g.sanitize(new TextDecoder().decode(n), {
46
+ const n = g.sanitize(new TextDecoder().decode(o), {
47
47
  USE_PROFILES: { svg: !0, svgFilters: !0 },
48
48
  ADD_TAGS: ["use"],
49
49
  FORBID_TAGS: ["style", "foreignObject"],
50
50
  FORBID_ATTR: ["style"]
51
- }), d = new DOMParser().parseFromString(o, "image/svg+xml");
51
+ }), d = new DOMParser().parseFromString(n, "image/svg+xml");
52
52
  if (d.querySelector("parsererror")) throw new Error("Invalid SVG in presentation.");
53
53
  for (const u of [...d.querySelectorAll("*")])
54
54
  for (const h of [...u.attributes])
@@ -60,37 +60,42 @@ class f {
60
60
  new TextEncoder().encode(new XMLSerializer().serializeToString(d))
61
61
  );
62
62
  }
63
- const t = m(e, { lazySlides: !0 });
64
- if (!t.slides.length || t.slides.length > 1e3 || !Number.isFinite(t.width) || !Number.isFinite(t.height) || t.width <= 0 || t.height <= 0 || t.width > 2e4 || t.height > 2e4)
63
+ const r = m(e, { lazySlides: !0 });
64
+ if (!r.slides.length || r.slides.length > 1e3 || !Number.isFinite(r.width) || !Number.isFinite(r.height) || r.width <= 0 || r.height <= 0 || r.width > 2e4 || r.height > 2e4)
65
65
  throw new Error("Invalid presentation dimensions or page count.");
66
66
  s.signal?.throwIfAborted();
67
67
  const c = new v(document.createElement("div"), {
68
68
  pdfjs: !1,
69
69
  onNodeError: s.onNodeError
70
70
  });
71
- return c.load(t), new f(c, a);
71
+ return c.load(r), new f(c, a);
72
72
  }
73
- renderPage(r, s) {
73
+ /** Search all slides through the published renderer, including unmounted pages. */
74
+ search(t) {
74
75
  if (this.disposed) throw new Error("Presentation is closed.");
75
- if (!Number.isInteger(r) || r < 0 || r >= this.pageCount)
76
+ return this.viewer.searchText(t, { matchCase: !1, useRegex: !1 });
77
+ }
78
+ renderPage(t, s) {
79
+ if (this.disposed) throw new Error("Presentation is closed.");
80
+ if (!Number.isInteger(t) || t < 0 || t >= this.pageCount)
76
81
  throw new RangeError("Invalid presentation page.");
77
- const e = this.viewer.renderSlideToContainer(r, s, 1);
82
+ const e = this.viewer.renderSlideToContainer(t, s, 1);
78
83
  if (!e) throw new Error("Presentation page could not be rendered.");
79
84
  let a = !1;
80
85
  const l = () => {
81
- a || (a = !0, this.handles.delete(t), e.dispose());
82
- }, t = {
86
+ a || (a = !0, this.handles.delete(r), e.dispose());
87
+ }, r = {
83
88
  element: e.element,
84
89
  ready: e.ready,
85
90
  dispose: l,
86
91
  [Symbol.dispose]: l
87
92
  };
88
- return this.handles.add(t), t;
93
+ return this.handles.add(r), r;
89
94
  }
90
95
  dispose() {
91
96
  if (!this.disposed) {
92
97
  this.disposed = !0;
93
- for (const r of this.handles) r.dispose();
98
+ for (const t of this.handles) t.dispose();
94
99
  this.handles.clear(), this.viewer.destroy();
95
100
  }
96
101
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@floegence/floe-webapp-core",
3
- "version": "0.98.1",
3
+ "version": "0.100.0",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",