@botiverse/porthole 0.5.0 → 0.6.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/README.md +25 -0
- package/dist/bridge/bridge.d.ts +12 -4
- package/dist/bridge/bridge.js +62 -27
- package/dist/bridge/navigation.d.ts +6 -0
- package/dist/bridge/navigation.js +41 -0
- package/dist/bridge/refusal.d.ts +53 -0
- package/dist/bridge/refusal.js +121 -0
- package/dist/bridge/types.d.ts +7 -0
- package/dist/check/check.d.ts +12 -3
- package/dist/check/check.js +54 -8
- package/dist/check/files.d.ts +26 -0
- package/dist/check/files.js +307 -0
- package/dist/check/lint.js +27 -10
- package/dist/check/page-source.js +1 -1
- package/dist/check/page.js +5 -0
- package/dist/check/tools.d.ts +23 -0
- package/dist/check/tools.js +25 -0
- package/dist/compile/policy.d.ts +15 -0
- package/dist/compile/policy.js +32 -0
- package/dist/config/capabilities.d.ts +5 -0
- package/dist/config/schema.d.ts +8 -0
- package/dist/config/validate.js +8 -1
- package/dist/conformance/harness-source.js +1 -1
- package/dist/files/paths.d.ts +99 -0
- package/dist/files/paths.js +263 -0
- package/dist/files/types.d.ts +24 -0
- package/dist/files/types.js +83 -0
- package/dist/guide/guide.js +25 -5
- package/dist/host/create-host.js +36 -4
- package/dist/host/types.d.ts +15 -2
- package/dist/index.d.ts +7 -3
- package/dist/index.js +10 -3
- package/dist/mcp/adapter.js +22 -7
- package/dist/protocol/adapter.d.ts +4 -0
- package/dist/protocol/mcp-apps.d.ts +12 -0
- package/dist/protocol/mcp-apps.js +12 -0
- package/dist/protocol/shell-adapter.js +18 -2
- package/dist/react/frame.d.ts +19 -4
- package/dist/react/frame.js +37 -9
- package/dist/server/files.d.ts +44 -0
- package/dist/server/files.js +244 -0
- package/dist/server/host.d.ts +38 -1
- package/dist/server/host.js +37 -2
- package/dist/server/index.d.ts +4 -2
- package/dist/server/index.js +4 -1
- package/dist/server/keys.d.ts +8 -0
- package/dist/server/keys.js +34 -0
- package/dist/server/server.js +287 -22
- package/dist/server/types.d.ts +49 -5
- package/dist/shell/document.d.ts +19 -0
- package/dist/shell/document.js +30 -0
- package/dist/shell/runtime.d.ts +2 -1
- package/dist/shell/runtime.js +117 -10
- package/docs/ADOPTING.md +95 -13
- package/docs/ARCHITECTURE.md +13 -3
- package/docs/DECISIONS.md +396 -4
- package/docs/DESIGN.md +43 -10
- package/package.json +1 -1
- package/src/bridge/bridge.ts +74 -23
- package/src/bridge/navigation.ts +46 -0
- package/src/bridge/refusal.ts +151 -0
- package/src/bridge/types.ts +12 -1
- package/src/check/check.ts +92 -14
- package/src/check/files.ts +384 -0
- package/src/check/lint.ts +29 -10
- package/src/check/page.ts +7 -0
- package/src/check/tools.ts +50 -0
- package/src/compile/policy.ts +38 -0
- package/src/config/capabilities.ts +5 -1
- package/src/config/schema.ts +8 -0
- package/src/config/validate.ts +8 -1
- package/src/files/paths.ts +323 -0
- package/src/files/types.ts +101 -0
- package/src/guide/guide.ts +38 -4
- package/src/host/create-host.ts +37 -4
- package/src/host/types.ts +13 -2
- package/src/index.ts +41 -0
- package/src/mcp/adapter.ts +26 -6
- package/src/protocol/adapter.ts +3 -1
- package/src/protocol/mcp-apps.ts +14 -0
- package/src/protocol/shell-adapter.ts +20 -2
- package/src/react/frame.tsx +53 -14
- package/src/server/files.ts +312 -0
- package/src/server/host.ts +72 -3
- package/src/server/index.ts +19 -0
- package/src/server/keys.ts +53 -0
- package/src/server/server.ts +353 -24
- package/src/server/types.ts +56 -4
- package/src/shell/document.ts +53 -0
- package/src/shell/runtime.ts +117 -10
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { checkFileSet, DEFAULT_ENTRY, fileLimits, lookupFile, servesFiles, } from "../files/paths.js";
|
|
2
|
+
import { fileTypeOf, knownType } from "../files/types.js";
|
|
3
|
+
import { sizeWords } from "../guide/limits.js";
|
|
4
|
+
import { lintContent } from "./lint.js";
|
|
5
|
+
/** A text's line numbers by offset: its line starts found once, each line then a binary search. */
|
|
6
|
+
function linesOf(text) {
|
|
7
|
+
const starts = [0];
|
|
8
|
+
for (let at = text.indexOf("\n"); at >= 0; at = text.indexOf("\n", at + 1)) {
|
|
9
|
+
starts.push(at + 1);
|
|
10
|
+
}
|
|
11
|
+
return (index) => {
|
|
12
|
+
let low = 0;
|
|
13
|
+
let high = starts.length - 1;
|
|
14
|
+
while (low < high) {
|
|
15
|
+
const middle = (low + high + 1) >> 1;
|
|
16
|
+
if ((starts[middle] ?? 0) <= index) {
|
|
17
|
+
low = middle;
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
high = middle - 1;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return low + 1;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const textOf = (body) => typeof body === "string" ? body : new TextDecoder().decode(body);
|
|
27
|
+
const sizeOf = (body) => typeof body === "string" ? new TextEncoder().encode(body).byteLength : body.byteLength;
|
|
28
|
+
/** How much of one file the references are looked for in: its first 2 MiB of text. */
|
|
29
|
+
const SCANNED = 2 * 1024 * 1024;
|
|
30
|
+
/** The most references of one kind looked up in one file: past that, a file is only linted. */
|
|
31
|
+
const MOST_REFERENCES = 2_000;
|
|
32
|
+
/** The elements whose attribute names a file the page loads or links: which attribute. */
|
|
33
|
+
const REFERENCE_ATTRIBUTES = {
|
|
34
|
+
script: ["src"],
|
|
35
|
+
img: ["src"],
|
|
36
|
+
source: ["src"],
|
|
37
|
+
video: ["src", "poster"],
|
|
38
|
+
audio: ["src"],
|
|
39
|
+
track: ["src"],
|
|
40
|
+
embed: ["src"],
|
|
41
|
+
input: ["src"],
|
|
42
|
+
link: ["href"],
|
|
43
|
+
a: ["href"],
|
|
44
|
+
area: ["href"],
|
|
45
|
+
};
|
|
46
|
+
/** A tag: its name and its attributes' text. Bounded, and never across another `<`: linear. */
|
|
47
|
+
const TAG = /<([a-z][a-z0-9-]{0,30})\b([^<>]{0,8192})>/giu;
|
|
48
|
+
const isSpace = (code) => code === 32 || code === 9 || code === 10 || code === 12 || code === 13;
|
|
49
|
+
/** A tag's attributes, read once from left to right (linear): each name, value and its offset. */
|
|
50
|
+
function attributesOf(text) {
|
|
51
|
+
const out = [];
|
|
52
|
+
let at = 0;
|
|
53
|
+
while (at < text.length) {
|
|
54
|
+
while (at < text.length && (isSpace(text.charCodeAt(at)) || text[at] === "/")) {
|
|
55
|
+
at += 1;
|
|
56
|
+
}
|
|
57
|
+
const nameStart = at;
|
|
58
|
+
while (at < text.length &&
|
|
59
|
+
!isSpace(text.charCodeAt(at)) &&
|
|
60
|
+
text[at] !== "=" &&
|
|
61
|
+
text[at] !== "/") {
|
|
62
|
+
at += 1;
|
|
63
|
+
}
|
|
64
|
+
const name = text.slice(nameStart, at).toLowerCase();
|
|
65
|
+
if (name === "") {
|
|
66
|
+
at += 1;
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
while (at < text.length && isSpace(text.charCodeAt(at))) {
|
|
70
|
+
at += 1;
|
|
71
|
+
}
|
|
72
|
+
if (text[at] !== "=") {
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
at += 1;
|
|
76
|
+
while (at < text.length && isSpace(text.charCodeAt(at))) {
|
|
77
|
+
at += 1;
|
|
78
|
+
}
|
|
79
|
+
const quote = text[at];
|
|
80
|
+
if (quote === '"' || quote === "'") {
|
|
81
|
+
const close = text.indexOf(quote, at + 1);
|
|
82
|
+
const end = close < 0 ? text.length : close;
|
|
83
|
+
out.push({ name, value: text.slice(at + 1, end), at: at + 1 });
|
|
84
|
+
at = end + 1;
|
|
85
|
+
}
|
|
86
|
+
else {
|
|
87
|
+
const start = at;
|
|
88
|
+
while (at < text.length && !isSpace(text.charCodeAt(at))) {
|
|
89
|
+
at += 1;
|
|
90
|
+
}
|
|
91
|
+
out.push({ name, value: text.slice(start, at), at: start });
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
}
|
|
96
|
+
/** What a page's markup loads or links: each element's `src`, `href` or `poster`. */
|
|
97
|
+
function markupReferences(text) {
|
|
98
|
+
const found = [];
|
|
99
|
+
for (const tag of text.matchAll(TAG)) {
|
|
100
|
+
if (found.length >= MOST_REFERENCES) {
|
|
101
|
+
break;
|
|
102
|
+
}
|
|
103
|
+
const name = (tag[1] ?? "").toLowerCase();
|
|
104
|
+
const wanted = Object.hasOwn(REFERENCE_ATTRIBUTES, name)
|
|
105
|
+
? REFERENCE_ATTRIBUTES[name]
|
|
106
|
+
: undefined;
|
|
107
|
+
if (wanted === undefined) {
|
|
108
|
+
continue;
|
|
109
|
+
}
|
|
110
|
+
const offset = tag.index + 1 + name.length;
|
|
111
|
+
for (const attribute of attributesOf(tag[2] ?? "")) {
|
|
112
|
+
if (wanted.includes(attribute.name) && attribute.value !== "") {
|
|
113
|
+
found.push({ reference: attribute.value, index: offset + attribute.at });
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
return found;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* The references a text's patterns find (group 2 of each). Every pattern is bounded and stops at
|
|
121
|
+
* its own delimiters, so a text is read in linear time, however it was written.
|
|
122
|
+
*/
|
|
123
|
+
function patternReferences(text, patterns) {
|
|
124
|
+
const found = [];
|
|
125
|
+
for (const pattern of patterns) {
|
|
126
|
+
let count = 0;
|
|
127
|
+
for (const match of text.matchAll(pattern)) {
|
|
128
|
+
found.push({ reference: match[2] ?? "", index: match.index });
|
|
129
|
+
count += 1;
|
|
130
|
+
if (count >= MOST_REFERENCES) {
|
|
131
|
+
break;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
return found;
|
|
136
|
+
}
|
|
137
|
+
const CSS_REFERENCES = [
|
|
138
|
+
/url\(\s{0,64}(["']?)([^"'()\s]{1,2048})\1\s{0,64}\)/giu,
|
|
139
|
+
/@import\s{1,64}(["'])([^"'\n]{1,2048})\1/giu,
|
|
140
|
+
];
|
|
141
|
+
/** In a script: what resolves from the module (imports, `new URL(…, import.meta.url)`). */
|
|
142
|
+
const MODULE_REFERENCES = [
|
|
143
|
+
/\bfrom\s{0,64}(["'])(\.{1,2}\/[^"'\n]{0,2048})\1/gu,
|
|
144
|
+
/\bimport\s{0,64}\(?\s{0,64}(["'])(\.{1,2}\/[^"'\n]{0,2048})\1/gu,
|
|
145
|
+
/\bnew\s{1,64}URL\s{0,64}\(\s{0,64}(["'])([^"'\n]{1,2048})\1\s{0,64},\s{0,64}import\.meta\.url\b/gu,
|
|
146
|
+
];
|
|
147
|
+
/** In a script: what resolves from the page (fetches, workers made from a string). */
|
|
148
|
+
const PAGE_REFERENCES = [
|
|
149
|
+
/\bfetch\s{0,64}\(\s{0,64}(["'`])(\.{0,2}\/?[\w./-][^"'`$\n]{0,2048})\1/gu,
|
|
150
|
+
/\bnew\s{1,64}(?:Shared)?Worker\s{0,64}\(\s{0,64}(["'`])([^"'`$\n]{1,2048})\1/gu,
|
|
151
|
+
];
|
|
152
|
+
/** Whether a reference leaves the set for good reason: another origin, inline data, an anchor. */
|
|
153
|
+
const elsewhere = (reference) => /^[a-z][a-z0-9+.-]*:/iu.test(reference) ||
|
|
154
|
+
reference.startsWith("//") ||
|
|
155
|
+
reference.startsWith("#");
|
|
156
|
+
/** `reference` from a file in `directory` ("" or "a/b/"), as a path of the set; null above it. */
|
|
157
|
+
function resolve(directory, reference) {
|
|
158
|
+
const bare = reference.split("#")[0]?.split("?")[0] ?? "";
|
|
159
|
+
let decoded;
|
|
160
|
+
try {
|
|
161
|
+
decoded = decodeURIComponent(bare);
|
|
162
|
+
}
|
|
163
|
+
catch {
|
|
164
|
+
decoded = bare;
|
|
165
|
+
}
|
|
166
|
+
const segments = `${directory}${decoded}`.split("/");
|
|
167
|
+
const out = [];
|
|
168
|
+
for (const [index, segment] of segments.entries()) {
|
|
169
|
+
if (segment === "..") {
|
|
170
|
+
if (out.length === 0) {
|
|
171
|
+
return null;
|
|
172
|
+
}
|
|
173
|
+
out.pop();
|
|
174
|
+
}
|
|
175
|
+
else if (segment !== "." && (segment !== "" || index === segments.length - 1)) {
|
|
176
|
+
out.push(segment);
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return out.join("/");
|
|
180
|
+
}
|
|
181
|
+
const directoryOf = (path) => path.slice(0, path.lastIndexOf("/") + 1);
|
|
182
|
+
/**
|
|
183
|
+
* Lints a page that comes with files (P081): the set (paths, limits, its entry), each page as
|
|
184
|
+
* `lintContent` lints a page, each relative reference looked up in the set (a leading `/`, which
|
|
185
|
+
* names the address's root rather than the version, is an error in a page's markup), and each
|
|
186
|
+
* file whose extension the server doesn't know (a download).
|
|
187
|
+
*/
|
|
188
|
+
export function lintFiles(config, files, options = {}) {
|
|
189
|
+
const findings = [];
|
|
190
|
+
if (!servesFiles(config)) {
|
|
191
|
+
findings.push({
|
|
192
|
+
rule: "files",
|
|
193
|
+
severity: "error",
|
|
194
|
+
message: "A page here is one document: it can't come with files. Put its styles, scripts and data in the page itself.",
|
|
195
|
+
});
|
|
196
|
+
return findings;
|
|
197
|
+
}
|
|
198
|
+
const entry = options.entry ?? DEFAULT_ENTRY;
|
|
199
|
+
const sized = Object.fromEntries(Object.entries(files).map(([path, body]) => [path, { size: sizeOf(body) }]));
|
|
200
|
+
const problems = checkFileSet(sized, { entry, limits: fileLimits(config.limits) });
|
|
201
|
+
for (const problem of problems) {
|
|
202
|
+
findings.push({
|
|
203
|
+
rule: "files",
|
|
204
|
+
severity: "error",
|
|
205
|
+
message: `${problem.message}.`,
|
|
206
|
+
...(problem.path === undefined ? {} : { path: problem.path }),
|
|
207
|
+
});
|
|
208
|
+
}
|
|
209
|
+
// Over the limits, the version isn't taken: nothing in it is read.
|
|
210
|
+
if (problems.some((each) => each.code === "count" || each.code === "size" || each.code === "total")) {
|
|
211
|
+
return findings;
|
|
212
|
+
}
|
|
213
|
+
const has = (path) => Object.hasOwn(files, path);
|
|
214
|
+
const found = (path) => lookupFile(has, path, { entry, navigation: false }).kind !== "none";
|
|
215
|
+
const reported = new Set();
|
|
216
|
+
const check = (from, lineOf, references, directory, rooted, also) => {
|
|
217
|
+
const seen = new Set();
|
|
218
|
+
for (const { reference, index } of references) {
|
|
219
|
+
if (seen.has(reference)) {
|
|
220
|
+
continue;
|
|
221
|
+
}
|
|
222
|
+
seen.add(reference);
|
|
223
|
+
if (reference === "" || elsewhere(reference) || reference.includes("${")) {
|
|
224
|
+
continue;
|
|
225
|
+
}
|
|
226
|
+
if (reference.startsWith("/")) {
|
|
227
|
+
const key = `${from} / ${reference}`;
|
|
228
|
+
if (!reported.has(key)) {
|
|
229
|
+
reported.add(key);
|
|
230
|
+
findings.push({
|
|
231
|
+
rule: "root-path",
|
|
232
|
+
severity: rooted,
|
|
233
|
+
message: `${reference} starts with /: that is the address's root, not this version's files. Write it relative (.${reference})${reference.startsWith("/assets/") ? '; for a Vite build, set base: "./"' : ""}.`,
|
|
234
|
+
path: from,
|
|
235
|
+
line: lineOf(index),
|
|
236
|
+
});
|
|
237
|
+
}
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const target = resolve(directory, reference);
|
|
241
|
+
const other = also === undefined ? null : resolve(also, reference);
|
|
242
|
+
const named = (target !== null && found(target)) || (other !== null && found(other));
|
|
243
|
+
const key = `${from} ${target ?? reference}`;
|
|
244
|
+
if (!named && !reported.has(key)) {
|
|
245
|
+
reported.add(key);
|
|
246
|
+
findings.push({
|
|
247
|
+
rule: "missing-file",
|
|
248
|
+
severity: "warning",
|
|
249
|
+
message: target === null && other === null
|
|
250
|
+
? `${reference} goes above the version's own files: nothing is there.`
|
|
251
|
+
: `${reference} names ${(target ?? other) === "" ? "the version's entry" : (target ?? other)}, which isn't one of the files.`,
|
|
252
|
+
path: from,
|
|
253
|
+
line: lineOf(index),
|
|
254
|
+
});
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
};
|
|
258
|
+
const maxPage = config.limits.maxBytes;
|
|
259
|
+
for (const [path, body] of Object.entries(files)) {
|
|
260
|
+
const { role } = fileTypeOf(path);
|
|
261
|
+
if (!knownType(path)) {
|
|
262
|
+
findings.push({
|
|
263
|
+
rule: "file-type",
|
|
264
|
+
severity: "warning",
|
|
265
|
+
message: `${path} is served as a download: its extension isn't one the server knows.`,
|
|
266
|
+
path,
|
|
267
|
+
});
|
|
268
|
+
}
|
|
269
|
+
const directory = directoryOf(path);
|
|
270
|
+
if (role === "page") {
|
|
271
|
+
const bytes = sizeOf(body);
|
|
272
|
+
if (bytes > maxPage) {
|
|
273
|
+
// Over the page's limit: said, and not read further.
|
|
274
|
+
findings.push({
|
|
275
|
+
rule: "size",
|
|
276
|
+
severity: "error",
|
|
277
|
+
message: `It is ${sizeWords(bytes)}; a page may be at most ${sizeWords(maxPage)}: move what it holds into files of its own (scripts, styles, data).`,
|
|
278
|
+
path,
|
|
279
|
+
});
|
|
280
|
+
continue;
|
|
281
|
+
}
|
|
282
|
+
const text = textOf(body);
|
|
283
|
+
for (const finding of lintContent(config, text)) {
|
|
284
|
+
findings.push({ ...finding, path });
|
|
285
|
+
}
|
|
286
|
+
const lines = linesOf(text);
|
|
287
|
+
check(path, lines, markupReferences(text), directory, "error");
|
|
288
|
+
check(path, lines, patternReferences(text, CSS_REFERENCES), directory, "warning");
|
|
289
|
+
check(path, lines, patternReferences(text, [...MODULE_REFERENCES, ...PAGE_REFERENCES]), directory, "warning");
|
|
290
|
+
}
|
|
291
|
+
else if (path.endsWith(".css")) {
|
|
292
|
+
const text = textOf(body).slice(0, SCANNED);
|
|
293
|
+
check(path, linesOf(text), patternReferences(text, CSS_REFERENCES), directory, "warning");
|
|
294
|
+
}
|
|
295
|
+
else if (role === "script") {
|
|
296
|
+
const text = textOf(body).slice(0, SCANNED);
|
|
297
|
+
const lines = linesOf(text);
|
|
298
|
+
check(path, lines, patternReferences(text, MODULE_REFERENCES), directory, "warning");
|
|
299
|
+
// A fetch from a script resolves from the page that runs it: the entry's directory, or the
|
|
300
|
+
// script's own (a worker's).
|
|
301
|
+
check(path, lines, patternReferences(text, PAGE_REFERENCES), directoryOf(entry), "warning", directory);
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
return findings;
|
|
305
|
+
}
|
|
306
|
+
/** Where a finding is, for the agent: `about.html line 3: `. */
|
|
307
|
+
export const whereOf = (finding) => `${finding.path === undefined ? "" : finding.path}${finding.line === undefined ? "" : `${finding.path === undefined ? "" : " "}line ${finding.line}`}${finding.path === undefined && finding.line === undefined ? "" : ": "}`;
|
package/dist/check/lint.js
CHANGED
|
@@ -21,22 +21,39 @@ export function fragmentOf(content) {
|
|
|
21
21
|
.replace(/<head[^>]*>[\s\S]*?<\/head>/iu, "");
|
|
22
22
|
return body.trim() === "" ? null : `${kept}${kept === "" ? "" : "\n"}${body.trim()}`;
|
|
23
23
|
}
|
|
24
|
-
/**
|
|
24
|
+
/**
|
|
25
|
+
* Where content reaches out, by the kind of egress each would need. Each pattern is bounded and
|
|
26
|
+
* never runs past its own delimiters (a tag's `<`, a string's quote), so a text is read in linear
|
|
27
|
+
* time however it was written.
|
|
28
|
+
*/
|
|
25
29
|
const REACHES = [
|
|
26
|
-
{
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
{ kind: "
|
|
31
|
-
{ kind: "
|
|
30
|
+
{
|
|
31
|
+
kind: "script",
|
|
32
|
+
pattern: /<script\b[^<>]{0,8192}?\bsrc\s{0,64}=\s{0,64}["']?(https?:\/\/[^"'\s<>]{1,2048})/giu,
|
|
33
|
+
},
|
|
34
|
+
{ kind: "script", pattern: /\bfrom\s{0,64}["'](https?:\/\/[^"'\n]{1,2048})/gu },
|
|
35
|
+
{ kind: "script", pattern: /\bimport\s{0,64}\(?\s{0,64}["'](https?:\/\/[^"'\n]{1,2048})/gu },
|
|
36
|
+
{
|
|
37
|
+
kind: "style",
|
|
38
|
+
pattern: /<link\b[^<>]{0,8192}?\bhref\s{0,64}=\s{0,64}["']?(https?:\/\/[^"'\s<>]{1,2048})/giu,
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
kind: "style",
|
|
42
|
+
pattern: /@import\s{1,64}(?:url\()?["']?(https?:\/\/[^"')\s]{1,2048})/giu,
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
kind: "img",
|
|
46
|
+
pattern: /<img\b[^<>]{0,8192}?\bsrc\s{0,64}=\s{0,64}["']?(https?:\/\/[^"'\s<>]{1,2048})/giu,
|
|
47
|
+
},
|
|
48
|
+
{ kind: "img", pattern: /url\(\s{0,64}["']?(https?:\/\/[^"')\s]{1,2048})/giu },
|
|
32
49
|
{
|
|
33
50
|
kind: "media",
|
|
34
|
-
pattern: /<(?:video|audio|source)\b[
|
|
51
|
+
pattern: /<(?:video|audio|source)\b[^<>]{0,8192}?\bsrc\s{0,64}=\s{0,64}["']?(https?:\/\/[^"'\s<>]{1,2048})/giu,
|
|
35
52
|
},
|
|
36
|
-
{ kind: "connect", pattern: /\bfetch\s
|
|
53
|
+
{ kind: "connect", pattern: /\bfetch\s{0,64}\(\s{0,64}["'`](https?:\/\/[^"'`\n]{1,2048})/gu },
|
|
37
54
|
{
|
|
38
55
|
kind: "connect",
|
|
39
|
-
pattern: /\bnew\s
|
|
56
|
+
pattern: /\bnew\s{1,64}(?:WebSocket|EventSource)\s{0,64}\(\s{0,64}["'`]((?:https?|wss?):\/\/[^"'`\n]{1,2048})/gu,
|
|
40
57
|
},
|
|
41
58
|
];
|
|
42
59
|
const CDN_PACKAGE = /^https:\/\/(?:cdn\.jsdelivr\.net\/npm|unpkg\.com|esm\.sh)\/((?:@[^/]+\/)?[^/@]+)(@[^/]*)?/u;
|