@floegence/floe-webapp-core 0.99.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/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
|
};
|
|
@@ -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
|
}
|