@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.
- package/dist/components/html-preview/SandboxedHtmlFrame.d.ts +10 -0
- package/dist/components/html-preview/SandboxedHtmlFrame.js +125 -69
- package/dist/components/ui/ContextMenuActions.d.ts +2 -0
- package/dist/components/ui/ContextMenuActions.js +111 -103
- package/dist/components/ui/SurfaceFloatingLayer.d.ts +2 -0
- package/dist/components/ui/SurfaceFloatingLayer.js +13 -13
- package/dist/components/ui/textSearch.d.ts +10 -1
- package/dist/components/ui/textSearch.js +75 -69
- package/dist/html-preview.d.ts +1 -1
- package/dist/pptx.d.ts +4 -0
- package/dist/pptx.js +30 -25
- package/package.json +1 -1
|
@@ -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
|
|
2
|
-
import { createSignal as
|
|
3
|
-
import { sandboxedMarkdownHtml as
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
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(
|
|
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
|
|
60
|
-
let
|
|
61
|
-
const [x,
|
|
62
|
-
const
|
|
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:
|
|
65
|
-
html:
|
|
94
|
+
token: r,
|
|
95
|
+
html: K(V(r) + e.html)
|
|
66
96
|
};
|
|
67
|
-
}),
|
|
97
|
+
}), o = () => F() === b().token;
|
|
68
98
|
k(() => {
|
|
69
|
-
const
|
|
70
|
-
|
|
99
|
+
const r = o() ? "ready" : "loading";
|
|
100
|
+
B(() => e.onPresentationStateChange?.(r));
|
|
71
101
|
}), k(() => {
|
|
72
|
-
|
|
102
|
+
R()?.postMessage({
|
|
73
103
|
type: "activation",
|
|
74
|
-
active:
|
|
104
|
+
active: e.active !== !1,
|
|
105
|
+
searchEnabled: !!e.onSearchRequest
|
|
75
106
|
});
|
|
76
107
|
}), k(() => {
|
|
77
108
|
const {
|
|
78
|
-
token:
|
|
79
|
-
} = b(),
|
|
80
|
-
let
|
|
81
|
-
|
|
82
|
-
!
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
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 (
|
|
95
|
-
if (
|
|
96
|
-
|
|
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 (
|
|
100
|
-
|
|
155
|
+
if (n?.type === "anchor-missing") {
|
|
156
|
+
h(e.labels?.anchorUnavailable ?? "The linked section was not found.");
|
|
101
157
|
return;
|
|
102
158
|
}
|
|
103
|
-
if (
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
if (!
|
|
107
|
-
if (!
|
|
108
|
-
return
|
|
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((
|
|
111
|
-
!
|
|
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
|
-
},
|
|
114
|
-
},
|
|
115
|
-
|
|
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
|
|
119
|
-
return
|
|
120
|
-
window.addEventListener("message",
|
|
174
|
+
const C = (r) => p?.(r);
|
|
175
|
+
return D(() => {
|
|
176
|
+
window.addEventListener("message", C), I(() => window.removeEventListener("message", C));
|
|
121
177
|
}), (() => {
|
|
122
|
-
var
|
|
123
|
-
|
|
178
|
+
var r = J(), a = r.firstChild;
|
|
179
|
+
v(r, M(H, {
|
|
124
180
|
get when() {
|
|
125
|
-
return !
|
|
181
|
+
return !o();
|
|
126
182
|
},
|
|
127
183
|
get children() {
|
|
128
|
-
var
|
|
129
|
-
return
|
|
184
|
+
var t = j();
|
|
185
|
+
return v(t, () => e.renderPending?.()), t;
|
|
130
186
|
}
|
|
131
|
-
}),
|
|
132
|
-
var
|
|
133
|
-
return typeof
|
|
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
|
|
139
|
-
return
|
|
194
|
+
var t = z();
|
|
195
|
+
return v(t, x), t;
|
|
140
196
|
}
|
|
141
|
-
}), null),
|
|
142
|
-
var
|
|
143
|
-
...
|
|
144
|
-
opacity:
|
|
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
|
|
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
|
-
}),
|
|
212
|
+
}), r;
|
|
157
213
|
})();
|
|
158
214
|
}
|
|
159
215
|
export {
|
|
160
|
-
|
|
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
|
|
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
|
|
4
|
-
import { SurfaceFloatingLayer as
|
|
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__ */
|
|
7
|
-
const
|
|
8
|
-
function
|
|
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: (
|
|
14
|
-
var
|
|
15
|
-
return b(
|
|
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
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
return
|
|
24
|
-
},
|
|
25
|
-
if (e.enabled === !1 ||
|
|
26
|
-
const
|
|
27
|
-
if (!
|
|
28
|
-
const g =
|
|
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(
|
|
30
|
+
return h?.rangeCount && h.getRangeAt(0).intersectsNode(a) ? h.toString() : "";
|
|
31
31
|
})(), w = {
|
|
32
|
-
target:
|
|
33
|
-
x: d ?
|
|
34
|
-
y: d ?
|
|
32
|
+
target: a,
|
|
33
|
+
x: d ? t.clientX : g.left + 8,
|
|
34
|
+
y: d ? t.clientY : g.bottom,
|
|
35
35
|
selection: v
|
|
36
|
-
},
|
|
36
|
+
}, C = e.actions(w), x = {
|
|
37
37
|
origin: w,
|
|
38
|
-
actions:
|
|
39
|
-
},
|
|
38
|
+
actions: C
|
|
39
|
+
}, I = {
|
|
40
40
|
origin: w,
|
|
41
|
-
actions: [...
|
|
41
|
+
actions: [...C, ...e.editing ? j(w, e.editing.labels, e.editing.onError) : []]
|
|
42
42
|
};
|
|
43
43
|
if (!x.actions.length) return;
|
|
44
|
-
|
|
45
|
-
const
|
|
46
|
-
|
|
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
|
-
|
|
49
|
-
}, m = (
|
|
50
|
-
|
|
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",
|
|
54
|
-
|
|
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(
|
|
56
|
+
}), f(L.Provider, {
|
|
57
57
|
value: {
|
|
58
58
|
claim: u,
|
|
59
|
-
resolve: (
|
|
59
|
+
resolve: (t) => e.enabled === !1 ? [] : e.actions(t)
|
|
60
60
|
},
|
|
61
61
|
get children() {
|
|
62
|
-
return [
|
|
62
|
+
return [$(() => e.children), f(T, {
|
|
63
63
|
get when() {
|
|
64
|
-
return
|
|
64
|
+
return n();
|
|
65
65
|
},
|
|
66
66
|
keyed: !0,
|
|
67
|
-
children: (
|
|
68
|
-
request:
|
|
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
|
|
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
|
|
88
|
+
return s();
|
|
86
89
|
},
|
|
87
|
-
children: (
|
|
88
|
-
var
|
|
89
|
-
return
|
|
90
|
-
e.onClose(),
|
|
91
|
-
}, b(
|
|
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
|
|
96
|
+
return c.icon;
|
|
94
97
|
}
|
|
95
|
-
}),
|
|
96
|
-
var u = e.itemClass ?? "floe-context-action",
|
|
97
|
-
return u !== o.e && k(
|
|
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
|
-
}),
|
|
105
|
+
}), i;
|
|
103
106
|
})()
|
|
104
107
|
});
|
|
105
108
|
}
|
|
106
109
|
function Y(e) {
|
|
107
|
-
let
|
|
108
|
-
const
|
|
109
|
-
if (!
|
|
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
|
|
116
|
+
const n = r.getBoundingClientRect();
|
|
114
117
|
return {
|
|
115
|
-
width:
|
|
116
|
-
height:
|
|
118
|
+
width: n.width,
|
|
119
|
+
height: n.height
|
|
117
120
|
};
|
|
118
|
-
}),
|
|
119
|
-
e.onClose(),
|
|
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
|
-
|
|
127
|
+
r.querySelector('[role="menuitem"]:not(:disabled)')?.focus({
|
|
125
128
|
preventScroll: !0
|
|
126
129
|
});
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
}, o = () =>
|
|
130
|
-
|
|
131
|
-
|
|
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(
|
|
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
|
|
149
|
+
return c();
|
|
142
150
|
},
|
|
143
151
|
role: "menu",
|
|
144
152
|
get "aria-label"() {
|
|
145
153
|
return e.label;
|
|
146
154
|
},
|
|
147
|
-
layerRef: (
|
|
148
|
-
|
|
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: (
|
|
157
|
-
onKeyDown: (
|
|
164
|
+
onContextMenu: (n) => n.preventDefault(),
|
|
165
|
+
onKeyDown: (n) => _(n, {
|
|
158
166
|
onActivate: (o) => o.click(),
|
|
159
|
-
onDismiss: () =>
|
|
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: (
|
|
175
|
+
children: (n) => (() => {
|
|
168
176
|
var o = X(), u = o.firstChild;
|
|
169
177
|
return o.$$click = () => {
|
|
170
|
-
|
|
171
|
-
}, b(o, f(
|
|
178
|
+
i(), n.onSelect();
|
|
179
|
+
}, b(o, f(z, {
|
|
172
180
|
get icon() {
|
|
173
|
-
return
|
|
181
|
+
return n.icon;
|
|
174
182
|
}
|
|
175
|
-
}), u), b(u, () =>
|
|
176
|
-
var m =
|
|
177
|
-
return m !==
|
|
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,
|
|
188
|
-
const
|
|
189
|
-
if (
|
|
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
|
-
}),
|
|
192
|
-
else if (
|
|
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(
|
|
202
|
+
d?.removeAllRanges(), d?.addRange(n);
|
|
195
203
|
}
|
|
196
204
|
}, m = (d) => () => {
|
|
197
205
|
try {
|
|
198
|
-
Promise.resolve(d()).catch(
|
|
206
|
+
Promise.resolve(d()).catch(s);
|
|
199
207
|
} catch (v) {
|
|
200
|
-
|
|
208
|
+
s(v);
|
|
201
209
|
}
|
|
202
|
-
},
|
|
210
|
+
}, t = (d) => ({
|
|
203
211
|
id: `edit.${d}`,
|
|
204
|
-
label:
|
|
212
|
+
label: r[d],
|
|
205
213
|
onSelect: m(async () => {
|
|
206
|
-
if (
|
|
207
|
-
|
|
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 (
|
|
220
|
+
if (c?.isConnected && (l(), !document.execCommand("insertText", !1, v)))
|
|
213
221
|
throw new Error("Clipboard insertion is unavailable.");
|
|
214
222
|
})
|
|
215
|
-
}),
|
|
216
|
-
|
|
223
|
+
}), a = [];
|
|
224
|
+
c && a.push(t("undo"), t("redo"), t("cut")), e.selection && a.push({
|
|
217
225
|
id: "edit.copy",
|
|
218
|
-
label:
|
|
226
|
+
label: r.copy,
|
|
219
227
|
onSelect: m(() => navigator.clipboard.writeText(e.selection))
|
|
220
|
-
}),
|
|
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
|
-
|
|
232
|
+
a.push({
|
|
225
233
|
id: "link.open",
|
|
226
|
-
label:
|
|
234
|
+
label: r.openLink,
|
|
227
235
|
onSelect: () => window.open(d, "_blank", "noopener,noreferrer")
|
|
228
|
-
}),
|
|
236
|
+
}), a.push({
|
|
229
237
|
id: "link.copy",
|
|
230
|
-
label:
|
|
238
|
+
label: r.copyLink,
|
|
231
239
|
onSelect: m(() => navigator.clipboard.writeText(d))
|
|
232
240
|
});
|
|
233
241
|
}
|
|
234
|
-
return
|
|
242
|
+
return a;
|
|
235
243
|
}
|
|
236
244
|
F(["click"]);
|
|
237
245
|
export {
|
|
238
|
-
|
|
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
|
|
2
|
-
import { observeViewport as
|
|
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
|
|
8
|
-
import { resolveSurfacePortalHost as
|
|
9
|
-
var N = /* @__PURE__ */
|
|
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,
|
|
22
|
-
x(() => C(
|
|
23
|
-
const r = s(() =>
|
|
24
|
-
owner: e.owner ?? null
|
|
25
|
-
})), n = () => B(r()),
|
|
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,
|
|
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
|
-
[
|
|
57
|
+
[$]: "true"
|
|
58
58
|
}, () => ({
|
|
59
59
|
[z]: n() ? "true" : void 0
|
|
60
|
-
})), !1, !0),
|
|
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
|
|
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
|
|
2
|
-
function N(
|
|
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
|
|
5
|
-
let
|
|
4
|
+
const w = new RegExp(s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), "giu"), u = [];
|
|
5
|
+
let g = "", o = [];
|
|
6
6
|
const b = () => {
|
|
7
|
-
let i = 0,
|
|
8
|
-
for (const
|
|
9
|
-
const
|
|
10
|
-
for (;
|
|
11
|
-
for (
|
|
12
|
-
const
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
},
|
|
15
|
+
g = "", o = [];
|
|
16
|
+
}, C = (i) => {
|
|
17
17
|
if (i.nodeType === Node.TEXT_NODE) {
|
|
18
|
-
const
|
|
19
|
-
|
|
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
|
|
28
|
-
if (
|
|
29
|
-
const
|
|
30
|
-
|
|
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
|
|
32
|
+
return r.childNodes.forEach(C), b(), u;
|
|
33
33
|
}
|
|
34
|
-
function $(
|
|
35
|
-
const [s,
|
|
36
|
-
let
|
|
37
|
-
const A = () =>
|
|
38
|
-
globalThis.CSS?.highlights?.delete(
|
|
39
|
-
}, H = (
|
|
40
|
-
const n =
|
|
41
|
-
if (!
|
|
42
|
-
const
|
|
43
|
-
(
|
|
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
|
-
|
|
46
|
-
}, R = (
|
|
47
|
-
|
|
48
|
-
M(s) && M(
|
|
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 = (
|
|
51
|
-
|
|
52
|
-
|
|
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
|
|
58
|
+
return x(() => {
|
|
55
59
|
A(), k(() => {
|
|
56
|
-
|
|
60
|
+
w(!1), g(""), i(0);
|
|
57
61
|
});
|
|
58
|
-
}),
|
|
59
|
-
|
|
60
|
-
|
|
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(
|
|
68
|
+
cancelAnimationFrame(y), y = requestAnimationFrame(() => m((t) => t + 1));
|
|
63
69
|
});
|
|
64
|
-
n.observe(
|
|
65
|
-
n.disconnect(), cancelAnimationFrame(
|
|
70
|
+
n.observe(e, { childList: !0, characterData: !0, subtree: !0 }), D(() => {
|
|
71
|
+
n.disconnect(), cancelAnimationFrame(y);
|
|
66
72
|
});
|
|
67
|
-
}),
|
|
68
|
-
const
|
|
69
|
-
|
|
70
|
-
const n =
|
|
71
|
-
if (!s() || !
|
|
72
|
-
const
|
|
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(
|
|
80
|
+
b(t), i((a) => Math.min(a, Math.max(0, t.length - 1)));
|
|
75
81
|
});
|
|
76
|
-
}),
|
|
82
|
+
}), x(L(u, () => i(0))), x(() => {
|
|
77
83
|
S();
|
|
78
|
-
const
|
|
79
|
-
if (!(!s() || !
|
|
84
|
+
const e = o(), n = e[C()];
|
|
85
|
+
if (!(!s() || !h())) {
|
|
80
86
|
if (typeof Highlight < "u" && CSS.highlights) {
|
|
81
|
-
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
const
|
|
85
|
-
|
|
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(),
|
|
97
|
+
S(), r.engine?.clear(), f?.remove(), cancelAnimationFrame(y);
|
|
92
98
|
}), {
|
|
93
99
|
open: s,
|
|
94
|
-
query:
|
|
95
|
-
setQuery:
|
|
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: () =>
|
|
101
|
-
current: () =>
|
|
102
|
-
bindInput: (
|
|
103
|
-
|
|
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: (
|
|
106
|
-
!
|
|
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
|
}
|
package/dist/html-preview.d.ts
CHANGED
|
@@ -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(
|
|
5
|
-
this.viewer =
|
|
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(
|
|
21
|
-
if (s.signal?.throwIfAborted(),
|
|
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(
|
|
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
|
|
28
|
-
if (
|
|
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
|
|
31
|
-
const d =
|
|
32
|
-
((
|
|
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(
|
|
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 [
|
|
44
|
-
for (const [i,
|
|
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
|
|
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(
|
|
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
|
|
64
|
-
if (!
|
|
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(
|
|
71
|
+
return c.load(r), new f(c, a);
|
|
72
72
|
}
|
|
73
|
-
|
|
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
|
-
|
|
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(
|
|
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(
|
|
82
|
-
},
|
|
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(
|
|
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
|
|
98
|
+
for (const t of this.handles) t.dispose();
|
|
94
99
|
this.handles.clear(), this.viewer.destroy();
|
|
95
100
|
}
|
|
96
101
|
}
|