@floegence/floe-webapp-core 0.99.1 → 0.101.1

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
  };
@@ -1,6 +1,8 @@
1
1
  import { type JSX } from 'solid-js';
2
2
  export interface SurfaceAnchoredLayerProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, 'children' | 'class' | 'style' | 'ref'> {
3
3
  anchor: HTMLElement | undefined;
4
+ /** Global navigation may escape its source surface while retaining the anchor. */
5
+ portalScope?: 'surface' | 'viewport';
4
6
  /** Changes when the anchor moves through a transform; no idle polling is used. */
5
7
  revision?: unknown;
6
8
  /** Screen-space clearance above labels outside the object bounds. */
@@ -1,66 +1,64 @@
1
- import { createComponent as E, mergeProps as K, memo as N } from "solid-js/web";
2
- import { splitProps as Q, createSignal as f, createEffect as M, onCleanup as R, onMount as U, Show as Z, untrack as _ } from "solid-js";
1
+ import { createComponent as L, mergeProps as K, memo as N } from "solid-js/web";
2
+ import { splitProps as Q, createSignal as m, createEffect as M, onCleanup as S, onMount as U, Show as Z, untrack as _ } from "solid-js";
3
3
  import { SurfaceFloatingLayer as tt } from "./SurfaceFloatingLayer.js";
4
4
  import { resolveFloatingBoundary as et } from "./surfaceFloatingBoundary.js";
5
5
  import { observeViewport as ot } from "../../viewport.js";
6
- import { resolveSurfacePortalHost as L } from "./dialogSurfaceScope.js";
7
- function lt(H) {
8
- const [e, $] = Q(H, ["anchor", "revision", "topOffset", "reservedSpace", "placement", "align", "gap", "children", "class", "style", "layerRef", "onAnchorDisconnect"]), [S, k] = f(!1), [q, B] = f({
6
+ import { resolveSurfacePortalHost as nt } from "./dialogSurfaceScope.js";
7
+ function ht(H) {
8
+ const [e, $] = Q(H, ["anchor", "portalScope", "revision", "topOffset", "reservedSpace", "placement", "align", "gap", "children", "class", "style", "layerRef", "onAnchorDisconnect"]), [R, k] = m(!1), [q, B] = m({
9
9
  x: 0,
10
10
  y: 0
11
- }), [V, Y] = f("above"), [A, v] = f(!1), [D, T] = f(480), [F, W] = f();
12
- let m, w = !1;
13
- const [O, X] = f({
11
+ }), [V, Y] = m("above"), [A, b] = m(!1), [D, T] = m(480), [F, W] = m();
12
+ let d, w = !1;
13
+ const [O, X] = m({
14
14
  x: 0,
15
15
  y: 0
16
- }), [j, G] = f(0), P = () => {
17
- m = void 0;
16
+ }), [j, G] = m(0), P = () => nt({
17
+ owner: e.portalScope === "viewport" ? document.documentElement : e.anchor
18
+ }), z = () => {
19
+ d = void 0;
18
20
  const n = e.anchor, l = F();
19
21
  if (!n || !l) return;
20
22
  if (!n.isConnected) {
21
- v(!1), w || e.onAnchorDisconnect?.(), w = !0;
23
+ b(!1), w || e.onAnchorDisconnect?.(), w = !0;
22
24
  return;
23
25
  }
24
26
  w = !1;
25
- const o = et(L({
26
- owner: n
27
- }));
27
+ const o = et(P());
28
28
  if (!o) {
29
- v(!1);
29
+ b(!1);
30
30
  return;
31
31
  }
32
- const t = n.getBoundingClientRect(), s = e.reservedSpace, d = o.top + (window.matchMedia("(max-width:760px)").matches ? s?.narrowTop ?? s?.top ?? 12 : s?.top ?? 12);
33
- T(Math.max(120, o.width - 24)), G(Math.max(0, o.bottom - (s?.bottom ?? 12) - d));
34
- const i = l.getBoundingClientRect(), I = (Math.max(o.left, t.left) + Math.min(o.right, t.right)) / 2, z = getComputedStyle(n).direction === "rtl", J = e.align === "start" ? z ? t.right - i.width : t.left : e.align === "end" ? z ? t.left : t.right - i.width : I - i.width / 2;
35
- let p = Math.max(o.left + 12, Math.min(J, o.right - i.width - 12));
36
- const x = t.top - (e.topOffset ?? 0), r = Math.max(0, e.gap ?? 12), g = x - i.height - r, y = Math.max(d, o.bottom - (s?.bottom ?? 12) - i.height), u = (b) => Math.max(d, Math.min(b, y));
32
+ const t = n.getBoundingClientRect(), s = e.reservedSpace, f = o.top + (window.matchMedia("(max-width:760px)").matches ? s?.narrowTop ?? s?.top ?? 12 : s?.top ?? 12);
33
+ T(Math.max(120, o.width - 24)), G(Math.max(0, o.bottom - (s?.bottom ?? 12) - f));
34
+ const r = l.getBoundingClientRect(), I = (Math.max(o.left, t.left) + Math.min(o.right, t.right)) / 2, C = getComputedStyle(n).direction === "rtl", J = e.align === "start" ? C ? t.right - r.width : t.left : e.align === "end" ? C ? t.left : t.right - r.width : I - r.width / 2;
35
+ let p = Math.max(o.left + 12, Math.min(J, o.right - r.width - 12));
36
+ const x = t.top - (e.topOffset ?? 0), i = Math.max(0, e.gap ?? 12), g = x - r.height - i, y = Math.max(f, o.bottom - (s?.bottom ?? 12) - r.height), u = (v) => Math.max(f, Math.min(v, y));
37
37
  let c = g, a = "above";
38
38
  if (e.placement === "right" || e.placement === "left") {
39
- const b = t.right + r + i.width <= o.right - 12, C = t.left - r - i.width >= o.left + 12;
40
- a = e.placement, a === "right" && !b && C ? a = "left" : a === "left" && !C && b && (a = "right"), p = Math.max(o.left + 12, Math.min(a === "right" ? t.right + r : t.left - i.width - r, o.right - i.width - 12)), c = u(t.top + t.height / 2 - i.height / 2);
41
- } else g < d ? t.bottom + r <= y ? (c = t.bottom + r, a = "below") : g >= o.top + 12 ? a = "above" : t.bottom + i.height + r <= o.bottom - 12 ? (c = t.bottom + r, a = "below") : t.right + i.width + r + 12 <= o.right ? (p = t.right + r, c = u(x), a = "right") : t.left - i.width - r - 12 >= o.left ? (p = t.left - i.width - r, c = u(x), a = "left") : (c = u(g), a = "edge") : c = Math.min(c, y);
39
+ const v = t.right + i + r.width <= o.right - 12, E = t.left - i - r.width >= o.left + 12;
40
+ a = e.placement, a === "right" && !v && E ? a = "left" : a === "left" && !E && v && (a = "right"), p = Math.max(o.left + 12, Math.min(a === "right" ? t.right + i : t.left - r.width - i, o.right - r.width - 12)), c = u(t.top + t.height / 2 - r.height / 2);
41
+ } else g < f ? t.bottom + i <= y ? (c = t.bottom + i, a = "below") : g >= o.top + 12 ? a = "above" : t.bottom + r.height + i <= o.bottom - 12 ? (c = t.bottom + i, a = "below") : t.right + r.width + i + 12 <= o.right ? (p = t.right + i, c = u(x), a = "right") : t.left - r.width - i - 12 >= o.left ? (p = t.left - r.width - i, c = u(x), a = "left") : (c = u(g), a = "edge") : c = Math.min(c, y);
42
42
  X({
43
- x: Math.max(18, Math.min(t.left + t.width / 2 - p, Math.max(18, i.width - 18))),
44
- y: Math.max(18, Math.min(t.top + t.height / 2 - c, Math.max(18, i.height - 18)))
43
+ x: Math.max(18, Math.min(t.left + t.width / 2 - p, Math.max(18, r.width - 18))),
44
+ y: Math.max(18, Math.min(t.top + t.height / 2 - c, Math.max(18, r.height - 18)))
45
45
  }), Y(a), B({
46
46
  x: Math.round(p),
47
47
  y: Math.round(c)
48
- }), v(t.right > o.left && t.left < o.right && t.bottom > o.top && t.top < o.bottom);
48
+ }), b(t.right > o.left && t.left < o.right && t.bottom > o.top && t.top < o.bottom);
49
49
  }, h = () => {
50
- m === void 0 && typeof requestAnimationFrame == "function" && (m = requestAnimationFrame(P));
50
+ d === void 0 && typeof requestAnimationFrame == "function" && (d = requestAnimationFrame(z));
51
51
  };
52
52
  return M(() => {
53
- e.anchor, e.revision, e.topOffset, e.reservedSpace, e.placement, e.align, e.gap, h();
53
+ e.anchor, e.portalScope, e.revision, e.topOffset, e.reservedSpace, e.placement, e.align, e.gap, h();
54
54
  }), M(() => {
55
55
  const n = F();
56
56
  if (!n || typeof ResizeObserver > "u") return;
57
57
  const l = new ResizeObserver(h);
58
- l.observe(n), R(() => l.disconnect());
58
+ l.observe(n), S(() => l.disconnect());
59
59
  }), U(() => k(!0)), M(() => {
60
- if (!S()) return;
61
- const n = e.anchor, l = typeof ResizeObserver == "function" ? new ResizeObserver(h) : void 0, o = L({
62
- owner: n
63
- }).boundaryHost;
60
+ if (!R()) return;
61
+ const n = e.anchor, l = typeof ResizeObserver == "function" ? new ResizeObserver(h) : void 0, o = P().boundaryHost;
64
62
  o && l?.observe(o), n && l?.observe(n);
65
63
  const t = new MutationObserver(h);
66
64
  n && t.observe(n, {
@@ -74,21 +72,24 @@ function lt(H) {
74
72
  childList: !0
75
73
  }), s !== o); )
76
74
  s = s.parentElement;
77
- const d = ot(window, h);
78
- window.addEventListener("scroll", h, !0), h(), R(() => {
79
- l?.disconnect(), t.disconnect(), d(), window.removeEventListener("scroll", h, !0);
75
+ const f = ot(window, h);
76
+ window.addEventListener("scroll", h, !0), h(), S(() => {
77
+ l?.disconnect(), t.disconnect(), f(), window.removeEventListener("scroll", h, !0);
80
78
  });
81
- }), R(() => {
82
- m !== void 0 && cancelAnimationFrame(m);
83
- }), E(Z, {
79
+ }), S(() => {
80
+ d !== void 0 && cancelAnimationFrame(d);
81
+ }), L(Z, {
84
82
  get when() {
85
- return N(() => !!S())() && e.anchor;
83
+ return N(() => !!R())() && e.anchor;
86
84
  },
87
85
  get children() {
88
- return E(tt, K($, {
86
+ return L(tt, K($, {
89
87
  get owner() {
90
88
  return e.anchor;
91
89
  },
90
+ get portalScope() {
91
+ return e.portalScope;
92
+ },
92
93
  get position() {
93
94
  return q();
94
95
  },
@@ -114,7 +115,7 @@ function lt(H) {
114
115
  },
115
116
  layerRef: (n) => {
116
117
  W(n), e.layerRef?.(n), queueMicrotask(() => _(() => {
117
- n.isConnected && (m !== void 0 && cancelAnimationFrame(m), P());
118
+ n.isConnected && (d !== void 0 && cancelAnimationFrame(d), z());
118
119
  }));
119
120
  },
120
121
  get children() {
@@ -125,5 +126,5 @@ function lt(H) {
125
126
  });
126
127
  }
127
128
  export {
128
- lt as SurfaceAnchoredLayer
129
+ ht as SurfaceAnchoredLayer
129
130
  };
@@ -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.99.1",
3
+ "version": "0.101.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",