social-embeds 0.6.1 → 0.7.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.
@@ -1,173 +1,3 @@
1
- // src/parser/url.ts
2
- const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#(\S*))?$/i;
3
- /** Absolute or protocol-relative http(s) URLs only. */
4
- function parseUrl(input) {
5
- const match = URL_PATTERN.exec(input.trim());
6
- if (!match) return null;
7
- const [, host = "", path = "", search = "", fragment] = match;
8
- const query = /* @__PURE__ */ new Map();
9
- for (const pair of search.split("&")) {
10
- if (pair === "") continue;
11
- const eq = pair.indexOf("=");
12
- const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
13
- const value = decodeComponent(eq === -1 ? "" : pair.slice(eq + 1));
14
- if (key === null || value === null) return null;
15
- if (!query.has(key)) query.set(key, value);
16
- }
17
- return {
18
- host: host.toLowerCase(),
19
- path,
20
- query,
21
- ...fragment ? { fragment } : {}
22
- };
23
- }
24
- function decodeComponent(component) {
25
- try {
26
- return decodeURIComponent(component.replace(/\+/g, " "));
27
- } catch {
28
- return null;
29
- }
30
- }
31
- /** Types an option value: booleans, canonical integers, otherwise the string as given. */
32
- function coerce(value) {
33
- if (value === "true") return true;
34
- if (value === "false") return false;
35
- if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
36
- return value;
37
- }
38
- function pixels(value) {
39
- return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
40
- }
41
- // src/parser/platform.ts
42
- /** The first attribute present for a key wins. */
43
- function attributeOptions(element, mapping, coerceValue) {
44
- const options = {};
45
- for (const [attribute, key] of mapping) {
46
- const value = element.attrs.get(attribute);
47
- if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
48
- }
49
- return options;
50
- }
51
- function sizeOf(element) {
52
- const width = pixels(element.attrs.get("width"));
53
- const height = pixels(element.attrs.get("height"));
54
- if (width === void 0 && height === void 0) return void 0;
55
- return {
56
- ...width === void 0 ? {} : { width },
57
- ...height === void 0 ? {} : { height }
58
- };
59
- }
60
- /** Adds `size` only when known, so results stay free of `undefined` properties. */
61
- function withSize(embed, size) {
62
- return size ? {
63
- ...embed,
64
- size
65
- } : embed;
66
- }
67
- /**
68
- * A platform's own responsive wrapper: a `div` whose only attribute is a `style` that `pattern`
69
- * matches, around one iframe. The padding percentage it captures is the video's ratio.
70
- */
71
- function unwrapRatio(root, pattern) {
72
- if (root.tag !== "div" || root.attrs.size !== 1) return null;
73
- const [, percent] = pattern.exec(root.attrs.get("style") ?? "") ?? [];
74
- if (percent === void 0) return null;
75
- let iframe;
76
- for (const child of root.children) {
77
- if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
78
- if (child.type !== "element" || child.tag !== "iframe" || iframe) return null;
79
- iframe = child;
80
- }
81
- const height = Math.round(Number(percent) * 100);
82
- if (!iframe || !(height > 0 && height <= 1e5)) return null;
83
- const divisor = gcd(1e4, height);
84
- return {
85
- iframe,
86
- size: {
87
- width: 1e4 / divisor,
88
- height: height / divisor
89
- }
90
- };
91
- }
92
- function gcd(a, b) {
93
- return b === 0 ? a : gcd(b, a % b);
94
- }
95
- // src/parser/platforms/applemusic.ts
96
- const PATH$1 = /^\/([a-z]{2})\/(album|song|playlist)\/(?:[^/]{1,200}\/)?(\d{1,15}|pl\.[A-Za-z0-9-]{1,64})\/?$/;
97
- const SONG = /^\d{1,15}$/;
98
- function appleContent(url, host) {
99
- if (url?.host !== host) return null;
100
- const [, country, type, id] = PATH$1.exec(url.path) ?? [];
101
- if (country === void 0 || type === void 0 || id === void 0) return null;
102
- if (type === "playlist" ? !id.startsWith("pl.") : !SONG.test(id)) return null;
103
- const song = type === "album" ? url.query.get("i") : void 0;
104
- if (song !== void 0 && !SONG.test(song)) return null;
105
- return {
106
- kind: "post",
107
- url: `https://music.apple.com/${country}/${type}/${id}${song ? `?i=${song}` : ""}`,
108
- id: song ?? id,
109
- variant: "iframe"
110
- };
111
- }
112
- const applemusic = {
113
- platform: "applemusic",
114
- parse(root) {
115
- if (root.tag !== "iframe") return null;
116
- const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), "embed.music.apple.com");
117
- if (!found) return null;
118
- const { height } = sizeOf(root) ?? {};
119
- return withSize({
120
- platform: "applemusic",
121
- ...found,
122
- options: {}
123
- }, height === void 0 ? void 0 : { height });
124
- },
125
- isOwnScript: () => false,
126
- match(url) {
127
- const found = appleContent(url, "music.apple.com");
128
- return found && {
129
- platform: "applemusic",
130
- ...found,
131
- options: {}
132
- };
133
- }
134
- };
135
- // src/parser/platforms/applepodcasts.ts
136
- const PATH = /^\/([a-z]{2})\/podcast\/(?:[^/]{1,200}\/)?(?:id)?(\d{1,15})\/?$/;
137
- const EPISODE = /^\d{1,15}$/;
138
- function content$2(url, host) {
139
- if (url?.host !== host) return null;
140
- const [, country, show] = PATH.exec(url.path) ?? [];
141
- if (country === void 0 || show === void 0) return null;
142
- const episode = url.query.get("i");
143
- if (episode !== void 0 && !EPISODE.test(episode)) return null;
144
- return {
145
- platform: "applepodcasts",
146
- kind: "post",
147
- url: `https://podcasts.apple.com/${country}/podcast/id${show}${episode ? `?i=${episode}` : ""}`,
148
- id: episode ?? show,
149
- variant: "iframe"
150
- };
151
- }
152
- const applepodcasts = {
153
- platform: "applepodcasts",
154
- parse(root) {
155
- if (root.tag !== "iframe") return null;
156
- const found = content$2(parseUrl(root.attrs.get("src") ?? ""), "embed.podcasts.apple.com");
157
- return found && withSize({
158
- ...found,
159
- options: {}
160
- }, sizeOf(root));
161
- },
162
- isOwnScript: () => false,
163
- match(url) {
164
- const found = content$2(url, "podcasts.apple.com");
165
- return found && {
166
- ...found,
167
- options: {}
168
- };
169
- }
170
- };
171
1
  // src/parser/html.ts
172
2
  const VOID_TAGS = /* @__PURE__ */ new Set([
173
3
  "area",
@@ -296,11 +126,15 @@ function hasClass(element, name) {
296
126
  /** In document order. */
297
127
  function descendants(nodes) {
298
128
  const found = [];
129
+ collect(nodes, found);
130
+ return found;
131
+ }
132
+ function collect(nodes, found) {
299
133
  for (const node of nodes) {
300
134
  if (node.type !== "element") continue;
301
- found.push(node, ...descendants(node.children));
135
+ found.push(node);
136
+ collect(node.children, found);
302
137
  }
303
- return found;
304
138
  }
305
139
  const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "cite"]);
306
140
  const HTTP_URL = /^https?:\/\//i;
@@ -335,11 +169,189 @@ function rebuild(nodes, whitelist) {
335
169
  function escapeAttribute(value) {
336
170
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
337
171
  }
172
+ // src/parser/url.ts
173
+ const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#(\S*))?$/i;
174
+ /** Absolute or protocol-relative http(s) URLs only. */
175
+ function parseUrl(input) {
176
+ const match = URL_PATTERN.exec(input.trim());
177
+ if (!match) return null;
178
+ const [, host = "", path = "", search = "", fragment] = match;
179
+ const query = /* @__PURE__ */ new Map();
180
+ for (const pair of search.split("&")) {
181
+ if (pair === "") continue;
182
+ const eq = pair.indexOf("=");
183
+ const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
184
+ const value = decodeComponent(eq === -1 ? "" : pair.slice(eq + 1));
185
+ if (key === null || value === null) return null;
186
+ if (!query.has(key)) query.set(key, value);
187
+ }
188
+ return {
189
+ host: host.toLowerCase(),
190
+ path,
191
+ query,
192
+ ...fragment ? { fragment } : {}
193
+ };
194
+ }
195
+ function decodeComponent(component) {
196
+ try {
197
+ return decodeURIComponent(component.replace(/\+/g, " "));
198
+ } catch {
199
+ return null;
200
+ }
201
+ }
202
+ /** Types an option value: booleans, canonical integers, otherwise the string as given. */
203
+ function coerce(value) {
204
+ if (value === "true") return true;
205
+ if (value === "false") return false;
206
+ if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
207
+ return value;
208
+ }
209
+ function pixels(value) {
210
+ return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
211
+ }
212
+ // src/parser/platform.ts
213
+ /** `/embed` holds `/embed` and `/embed/…`, never `/embedded`. */
214
+ function underPath(path, folder) {
215
+ return path === folder || path.startsWith(`${folder}/`);
216
+ }
217
+ /** The first attribute present for a key wins. */
218
+ function attributeOptions(element, mapping, coerceValue) {
219
+ const options = {};
220
+ for (const [attribute, key] of mapping) {
221
+ const value = element.attrs.get(attribute);
222
+ if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
223
+ }
224
+ return options;
225
+ }
226
+ function sizeOf(element) {
227
+ const width = pixels(element.attrs.get("width"));
228
+ const height = pixels(element.attrs.get("height"));
229
+ if (width === void 0 && height === void 0) return void 0;
230
+ return {
231
+ ...width === void 0 ? {} : { width },
232
+ ...height === void 0 ? {} : { height }
233
+ };
234
+ }
235
+ /** Adds `size` only when known, so results stay free of `undefined` properties. */
236
+ function withSize(embed, size) {
237
+ return size ? {
238
+ ...embed,
239
+ size
240
+ } : embed;
241
+ }
242
+ /**
243
+ * A platform's own responsive wrapper: a `div` whose only attribute is a `style` that `pattern`
244
+ * matches, around one iframe. The padding percentage it captures is the video's ratio.
245
+ */
246
+ function unwrapRatio(root, pattern) {
247
+ if (root.tag !== "div" || root.attrs.size !== 1) return null;
248
+ const [, percent] = pattern.exec(root.attrs.get("style") ?? "") ?? [];
249
+ if (percent === void 0) return null;
250
+ let iframe;
251
+ for (const child of root.children) {
252
+ if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
253
+ if (child.type !== "element" || child.tag !== "iframe" || iframe) return null;
254
+ iframe = child;
255
+ }
256
+ const height = Math.round(Number(percent) * 100);
257
+ if (!iframe || !(height > 0 && height <= 1e5)) return null;
258
+ const divisor = gcd$1(1e4, height);
259
+ return {
260
+ iframe,
261
+ size: {
262
+ width: 1e4 / divisor,
263
+ height: height / divisor
264
+ }
265
+ };
266
+ }
267
+ function gcd$1(a, b) {
268
+ return b === 0 ? a : gcd$1(b, a % b);
269
+ }
270
+ // src/parser/platforms/applemusic.ts
271
+ const PATH$2 = /^\/([a-z]{2})\/(album|song|playlist)\/(?:[^/]{1,200}\/)?(\d{1,15}|pl\.[A-Za-z0-9-]{1,64})\/?$/;
272
+ const SONG = /^\d{1,15}$/;
273
+ const FRAME_HOST$3 = "embed.music.apple.com";
274
+ function appleContent(url, host) {
275
+ if (url?.host !== host) return null;
276
+ const [, country, type, id] = PATH$2.exec(url.path) ?? [];
277
+ if (country === void 0 || type === void 0 || id === void 0) return null;
278
+ if (type === "playlist" ? !id.startsWith("pl.") : !SONG.test(id)) return null;
279
+ const song = type === "album" ? url.query.get("i") : void 0;
280
+ if (song !== void 0 && !SONG.test(song)) return null;
281
+ return {
282
+ kind: "post",
283
+ url: `https://music.apple.com/${country}/${type}/${id}${song ? `?i=${song}` : ""}`,
284
+ id: song ?? id,
285
+ variant: "iframe"
286
+ };
287
+ }
288
+ const applemusic = {
289
+ platform: "applemusic",
290
+ parse(root) {
291
+ if (root.tag !== "iframe") return null;
292
+ const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST$3);
293
+ if (!found) return null;
294
+ const { height } = sizeOf(root) ?? {};
295
+ return withSize({
296
+ platform: "applemusic",
297
+ ...found,
298
+ options: {}
299
+ }, height === void 0 ? void 0 : { height });
300
+ },
301
+ isOwnScript: () => false,
302
+ match(url) {
303
+ const found = appleContent(url, "music.apple.com");
304
+ return found && {
305
+ platform: "applemusic",
306
+ ...found,
307
+ options: {}
308
+ };
309
+ },
310
+ ownsFrame: (src) => src.host === FRAME_HOST$3
311
+ };
312
+ // src/parser/platforms/applepodcasts.ts
313
+ const PATH$1 = /^\/([a-z]{2})\/podcast\/(?:[^/]{1,200}\/)?(?:id)?(\d{1,15})\/?$/;
314
+ const EPISODE = /^\d{1,15}$/;
315
+ const FRAME_HOST$2 = "embed.podcasts.apple.com";
316
+ function content$2(url, host) {
317
+ if (url?.host !== host) return null;
318
+ const [, country, show] = PATH$1.exec(url.path) ?? [];
319
+ if (country === void 0 || show === void 0) return null;
320
+ const episode = url.query.get("i");
321
+ if (episode !== void 0 && !EPISODE.test(episode)) return null;
322
+ return {
323
+ platform: "applepodcasts",
324
+ kind: "post",
325
+ url: `https://podcasts.apple.com/${country}/podcast/id${show}${episode ? `?i=${episode}` : ""}`,
326
+ id: episode ?? show,
327
+ variant: "iframe"
328
+ };
329
+ }
330
+ const applepodcasts = {
331
+ platform: "applepodcasts",
332
+ parse(root) {
333
+ if (root.tag !== "iframe") return null;
334
+ const found = content$2(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST$2);
335
+ return found && withSize({
336
+ ...found,
337
+ options: {}
338
+ }, sizeOf(root));
339
+ },
340
+ isOwnScript: () => false,
341
+ match(url) {
342
+ const found = content$2(url, "podcasts.apple.com");
343
+ return found && {
344
+ ...found,
345
+ options: {}
346
+ };
347
+ },
348
+ ownsFrame: (src) => src.host === FRAME_HOST$2
349
+ };
338
350
  // src/parser/platforms/bluesky.ts
339
351
  const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
340
352
  const RKEY = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9._~:-]{1,512})";
341
- const HOSTS$11 = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
342
- const POST_PATH$4 = new RegExp(`^/profile/${DID}/post/${RKEY}/?$`);
353
+ const HOSTS$17 = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
354
+ const POST_PATH$5 = new RegExp(`^/profile/${DID}/post/${RKEY}/?$`);
343
355
  const AT_URI = new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
344
356
  const CID = /^[a-z2-7]{20,100}$/;
345
357
  const COLOR_MODES = /* @__PURE__ */ new Set([
@@ -347,13 +359,13 @@ const COLOR_MODES = /* @__PURE__ */ new Set([
347
359
  "dark",
348
360
  "system"
349
361
  ]);
350
- const SCRIPT$11 = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
351
- const FALLBACK$4 = /* @__PURE__ */ new Map([
362
+ const SCRIPT$16 = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
363
+ const FALLBACK$7 = /* @__PURE__ */ new Map([
352
364
  ["p", ["lang"]],
353
365
  ["a", ["href"]],
354
366
  ["br", []]
355
367
  ]);
356
- function post$6(did, rkey) {
368
+ function post$8(did, rkey) {
357
369
  return {
358
370
  platform: "bluesky",
359
371
  kind: "post",
@@ -362,20 +374,20 @@ function post$6(did, rkey) {
362
374
  variant: "iframe"
363
375
  };
364
376
  }
365
- function fromUrl$1(url) {
366
- if (!url || !HOSTS$11.has(url.host)) return null;
367
- const [, did, rkey] = POST_PATH$4.exec(url.path) ?? [];
368
- return did === void 0 || rkey === void 0 ? null : post$6(did, rkey);
377
+ function fromUrl$2(url) {
378
+ if (!url || !HOSTS$17.has(url.host)) return null;
379
+ const [, did, rkey] = POST_PATH$5.exec(url.path) ?? [];
380
+ return did === void 0 || rkey === void 0 ? null : post$8(did, rkey);
369
381
  }
370
382
  const bluesky = {
371
383
  platform: "bluesky",
372
- fallback: FALLBACK$4,
384
+ fallback: FALLBACK$7,
373
385
  parse(root) {
374
386
  if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
375
387
  const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
376
388
  if (did === void 0 || rkey === void 0) return null;
377
- const found = post$6(did, rkey);
378
- if (descendants(root.children).reverse().map((element) => element.tag === "a" ? fromUrl$1(parseUrl(element.attrs.get("href") ?? "")) : null).find((linked) => linked !== null)?.id !== found.id) return null;
389
+ const found = post$8(did, rkey);
390
+ if (descendants(root.children).reverse().map((element) => element.tag === "a" ? fromUrl$2(parseUrl(element.attrs.get("href") ?? "")) : null).find((linked) => linked !== null)?.id !== found.id) return null;
379
391
  const options = {};
380
392
  const cid = root.attrs.get("data-bluesky-cid");
381
393
  if (cid !== void 0 && CID.test(cid)) options.cid = cid;
@@ -384,12 +396,12 @@ const bluesky = {
384
396
  return {
385
397
  ...found,
386
398
  options,
387
- fallbackHtml: rebuild(root.children, FALLBACK$4)
399
+ fallbackHtml: rebuild(root.children, FALLBACK$7)
388
400
  };
389
401
  },
390
- isOwnScript: (src) => SCRIPT$11.test(src),
402
+ isOwnScript: (src) => SCRIPT$16.test(src),
391
403
  match(url) {
392
- const found = fromUrl$1(url);
404
+ const found = fromUrl$2(url);
393
405
  return found && {
394
406
  ...found,
395
407
  options: {}
@@ -399,9 +411,11 @@ const bluesky = {
399
411
  // src/parser/platforms/dailymotion.ts
400
412
  const VIDEO_ID$2 = /^x[a-z0-9]{4,12}$/;
401
413
  const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
402
- const WRAPPER$2 = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
403
- const HOSTS$10 = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
404
- function video$3(id, options) {
414
+ const WRAPPER$4 = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
415
+ const HOSTS$16 = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
416
+ const PLAYER_HOST$2 = "geo.dailymotion.com";
417
+ const SHORT_HOST = "dai.ly";
418
+ function video$5(id, options) {
405
419
  return {
406
420
  platform: "dailymotion",
407
421
  kind: "video",
@@ -413,7 +427,7 @@ function video$3(id, options) {
413
427
  }
414
428
  /** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
415
429
  function fromPlayer$2(url) {
416
- if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
430
+ if (url.host !== PLAYER_HOST$2 || url.query.has("playlist")) return null;
417
431
  const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
418
432
  if (!match) return null;
419
433
  const [, playerId] = match;
@@ -422,21 +436,21 @@ function fromPlayer$2(url) {
422
436
  if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
423
437
  const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
424
438
  if (playerId !== void 0) options.playerId = playerId;
425
- return video$3(id, options);
439
+ return video$5(id, options);
426
440
  }
427
441
  function fromPage$2(url) {
428
- if (url.host === "dai.ly") {
442
+ if (url.host === SHORT_HOST) {
429
443
  const id = url.path.replace(/^\/|\/$/g, "");
430
- return VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
444
+ return VIDEO_ID$2.test(id) ? video$5(id, {}) : null;
431
445
  }
432
- if (!HOSTS$10.has(url.host)) return null;
446
+ if (!HOSTS$16.has(url.host)) return null;
433
447
  const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
434
- return id !== void 0 && VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
448
+ return id !== void 0 && VIDEO_ID$2.test(id) ? video$5(id, {}) : null;
435
449
  }
436
450
  const dailymotion = {
437
451
  platform: "dailymotion",
438
452
  parse(root) {
439
- const wrapped = unwrapRatio(root, WRAPPER$2);
453
+ const wrapped = unwrapRatio(root, WRAPPER$4);
440
454
  const iframe = wrapped?.iframe ?? root;
441
455
  if (iframe.tag !== "iframe") return null;
442
456
  const src = parseUrl(iframe.attrs.get("src") ?? "");
@@ -447,10 +461,11 @@ const dailymotion = {
447
461
  isOwnScript: () => false,
448
462
  match(url) {
449
463
  return fromPlayer$2(url) ?? fromPage$2(url);
450
- }
464
+ },
465
+ ownsFrame: (src) => src.host === PLAYER_HOST$2 || src.host === SHORT_HOST || HOSTS$16.has(src.host) && (underPath(src.path, "/embed") || underPath(src.path, "/video"))
451
466
  };
452
467
  // src/parser/platforms/facebook.ts
453
- const HOSTS$9 = /* @__PURE__ */ new Set([
468
+ const HOSTS$15 = /* @__PURE__ */ new Set([
454
469
  "facebook.com",
455
470
  "www.facebook.com",
456
471
  "m.facebook.com"
@@ -471,7 +486,7 @@ const PHOTO_PATHS = /* @__PURE__ */ new Set([
471
486
  ]);
472
487
  const STORY_ID = new RegExp(`^${POST_ID}$`);
473
488
  const NUMERIC_ID = /^\d{1,25}$/;
474
- const SCRIPT$10 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
489
+ const SCRIPT$15 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
475
490
  const OPTION_ATTRIBUTES$5 = [
476
491
  ["data-width", "width"],
477
492
  ["data-show-text", "showText"],
@@ -490,14 +505,14 @@ const PARSE_IGNORE = {
490
505
  name: "class",
491
506
  value: /^fb-xfbml-parse-ignore$/
492
507
  };
493
- const FALLBACK$3 = /* @__PURE__ */ new Map([
508
+ const FALLBACK$6 = /* @__PURE__ */ new Map([
494
509
  ["div", [PARSE_IGNORE]],
495
510
  ["blockquote", ["cite", PARSE_IGNORE]],
496
511
  ["a", ["href"]],
497
512
  ["p", []]
498
513
  ]);
499
514
  function target$1(url) {
500
- if (!url || !HOSTS$9.has(url.host)) return null;
515
+ if (!url || !HOSTS$15.has(url.host)) return null;
501
516
  const { path, query } = url;
502
517
  const [, name, postId] = POSTS_PATH$1.exec(path) ?? [];
503
518
  if (name !== void 0 && postId !== void 0) return {
@@ -566,7 +581,7 @@ function embed(found, kind, variant, options) {
566
581
  }
567
582
  const facebook = {
568
583
  platform: "facebook",
569
- fallback: FALLBACK$3,
584
+ fallback: FALLBACK$6,
570
585
  parse(root) {
571
586
  if (root.tag === "div") {
572
587
  const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
@@ -574,7 +589,7 @@ const facebook = {
574
589
  if (!kind || !found) return null;
575
590
  return {
576
591
  ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$5, coerce)),
577
- fallbackHtml: rebuild(root.children, FALLBACK$3)
592
+ fallbackHtml: rebuild(root.children, FALLBACK$6)
578
593
  };
579
594
  }
580
595
  if (root.tag !== "iframe") return null;
@@ -612,26 +627,157 @@ const facebook = {
612
627
  }
613
628
  return null;
614
629
  },
615
- isOwnScript: (src) => SCRIPT$10.test(src),
630
+ isOwnScript: (src) => SCRIPT$15.test(src),
616
631
  scriptOptions(src) {
617
- const [, locale] = SCRIPT$10.exec(src) ?? [];
632
+ const [, locale] = SCRIPT$15.exec(src) ?? [];
618
633
  return locale === void 0 ? {} : { locale };
619
634
  },
620
- allowsFbRoot: true,
635
+ allowsFbRoot: true,
636
+ match(url) {
637
+ const found = target$1(url);
638
+ return found && embed(found, found.kind, "sdk", {});
639
+ },
640
+ ownsFrame: (src) => PLUGIN_HOSTS.has(src.host) && underPath(src.path, "/plugins")
641
+ };
642
+ // src/parser/platforms/flickr.ts
643
+ const HOSTS$14 = /* @__PURE__ */ new Set(["flickr.com", "www.flickr.com"]);
644
+ const USER$2 = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9@_.-]{1,64})";
645
+ const ID$4 = "(\\d{1,20})";
646
+ const PHOTO_PATH = new RegExp(`^/photos/${USER$2}/${ID$4}(?:/in/[A-Za-z0-9_@./-]{1,200})?/?$`);
647
+ const ALBUM_PATH$1 = new RegExp(`^/photos/${USER$2}/(?:albums|sets)/${ID$4}/?$`);
648
+ const SHORT_PATH = /^\/p\/([1-9a-km-zA-HJ-NP-Z]{1,12})$/;
649
+ const SCRIPT$14 = /^(?:https?:)?\/\/embedr\.flickr\.com\/assets\/client-code\.js$/;
650
+ const ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
651
+ const OPTIONS = [
652
+ "header",
653
+ "footer",
654
+ "context"
655
+ ];
656
+ const IMAGE_SRC = /^https:\/\/(?:live|farm\d{1,3})\.staticflickr\.com\//;
657
+ const FALLBACK$5 = /* @__PURE__ */ new Map([["a", [{
658
+ name: "href",
659
+ value: /^https:\/\/(?:www\.)?flickr\.com\//
660
+ }]], ["img", [
661
+ {
662
+ name: "src",
663
+ value: IMAGE_SRC
664
+ },
665
+ {
666
+ name: "width",
667
+ value: /^\d{1,6}$/
668
+ },
669
+ {
670
+ name: "height",
671
+ value: /^\d{1,6}$/
672
+ },
673
+ "alt"
674
+ ]]]);
675
+ /** The photo id of a `flic.kr/p/{code}` code, or `null` for an empty code or a character outside Flickr's base-58 alphabet. */
676
+ function decodeFlickrCode(code) {
677
+ if (code === "") return null;
678
+ let id = 0n;
679
+ for (const character of code) {
680
+ const digit = ALPHABET.indexOf(character);
681
+ if (digit === -1) return null;
682
+ id = id * 58n + BigInt(digit);
683
+ }
684
+ return id.toString();
685
+ }
686
+ function encodeFlickrCode(id) {
687
+ let rest = BigInt(id);
688
+ let code = "";
689
+ while (rest > 0n) {
690
+ code = ALPHABET.charAt(Number(rest % 58n)) + code;
691
+ rest /= 58n;
692
+ }
693
+ return code;
694
+ }
695
+ function photo(user, id) {
696
+ return {
697
+ platform: "flickr",
698
+ kind: "post",
699
+ url: `https://www.flickr.com/photos/${user}/${id}/`,
700
+ id,
701
+ variant: "iframe"
702
+ };
703
+ }
704
+ function album(user, id) {
705
+ return {
706
+ platform: "flickr",
707
+ kind: "post",
708
+ url: `https://www.flickr.com/photos/${user}/albums/${id}`,
709
+ id,
710
+ variant: "iframe"
711
+ };
712
+ }
713
+ function fromLongUrl(url) {
714
+ if (!url || !HOSTS$14.has(url.host)) return null;
715
+ const [, albumUser, albumId] = ALBUM_PATH$1.exec(url.path) ?? [];
716
+ if (albumUser !== void 0 && albumId !== void 0) return album(albumUser, albumId);
717
+ const [, user, id] = PHOTO_PATH.exec(url.path) ?? [];
718
+ return user === void 0 || id === void 0 ? null : photo(user, id);
719
+ }
720
+ function fromShortUrl(url) {
721
+ if (url.host !== "flic.kr") return null;
722
+ const [, code] = SHORT_PATH.exec(url.path) ?? [];
723
+ const id = code === void 0 ? null : decodeFlickrCode(code);
724
+ if (code === void 0 || id === null || encodeFlickrCode(id) !== code) return null;
725
+ return {
726
+ platform: "flickr",
727
+ kind: "post",
728
+ url: `https://flic.kr/p/${code}`,
729
+ id,
730
+ variant: "iframe"
731
+ };
732
+ }
733
+ function onlyImage(root) {
734
+ let image = null;
735
+ for (const child of root.children) {
736
+ if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
737
+ if (child.type !== "element" || child.tag !== "img" || image) return null;
738
+ image = child;
739
+ }
740
+ return image;
741
+ }
742
+ const flickr = {
743
+ platform: "flickr",
744
+ fallback: FALLBACK$5,
745
+ parse(root) {
746
+ if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
747
+ const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
748
+ const image = onlyImage(root);
749
+ if (!found || !image) return null;
750
+ const options = {};
751
+ for (const name of OPTIONS) if (root.attrs.get(`data-${name}`) === "true") options[name] = true;
752
+ const size = sizeOf(image);
753
+ const linked = IMAGE_SRC.test(image.attrs.get("src") ?? "") ? root : {
754
+ ...root,
755
+ children: []
756
+ };
757
+ return withSize({
758
+ ...found,
759
+ options,
760
+ fallbackHtml: rebuild([linked], FALLBACK$5)
761
+ }, size?.width !== void 0 && size.height !== void 0 ? size : void 0);
762
+ },
763
+ isOwnScript: (src) => SCRIPT$14.test(src),
621
764
  match(url) {
622
- const found = target$1(url);
623
- return found && embed(found, found.kind, "sdk", {});
765
+ const found = fromLongUrl(url) ?? fromShortUrl(url);
766
+ return found && {
767
+ ...found,
768
+ options: {}
769
+ };
624
770
  }
625
771
  };
626
772
  // src/parser/platforms/giphy.ts
627
- const ID = "([A-Za-z0-9]{6,40})";
628
- const PAGE_HOSTS$2 = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
629
- const PAGE_PATH = new RegExp(`^/gifs/(?:[A-Za-z0-9-]{0,200}-)?${ID}/?$`);
630
- const EMBED_PATH$2 = new RegExp(`^/embed/${ID}/?$`);
773
+ const ID$3 = "([A-Za-z0-9]{6,40})";
774
+ const PAGE_HOSTS$3 = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
775
+ const PAGE_PATH$3 = new RegExp(`^/gifs/(?:[A-Za-z0-9-]{0,200}-)?${ID$3}/?$`);
776
+ const EMBED_PATH$2 = new RegExp(`^/embed/${ID$3}/?$`);
631
777
  const MEDIA_HOST = /^media\d?\.giphy\.com$/;
632
- const MEDIA_PATH = new RegExp(`^/media/${ID}/giphy\\.(?:gif|webp|mp4)$`);
633
- const WRAPPER$1 = /^width:\s*100%;\s*height:\s*0;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*position:\s*relative;?$/;
634
- function gif(id) {
778
+ const MEDIA_PATH = new RegExp(`^/media/${ID$3}/giphy\\.(?:gif|webp|mp4)$`);
779
+ const WRAPPER$3 = /^width:\s*100%;\s*height:\s*0;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*position:\s*relative;?$/;
780
+ function gif$1(id) {
635
781
  return {
636
782
  platform: "giphy",
637
783
  kind: "video",
@@ -640,17 +786,17 @@ function gif(id) {
640
786
  variant: "iframe"
641
787
  };
642
788
  }
643
- function idOf(url) {
789
+ function idOf$4(url) {
644
790
  if (!url) return void 0;
645
- if (PAGE_HOSTS$2.has(url.host)) return (PAGE_PATH.exec(url.path) ?? EMBED_PATH$2.exec(url.path))?.[1];
791
+ if (PAGE_HOSTS$3.has(url.host)) return (PAGE_PATH$3.exec(url.path) ?? EMBED_PATH$2.exec(url.path))?.[1];
646
792
  if (MEDIA_HOST.test(url.host)) return MEDIA_PATH.exec(url.path)?.[1];
647
793
  }
648
- function fromIframe(iframe) {
794
+ function fromIframe$2(iframe) {
649
795
  if (iframe.tag !== "iframe") return null;
650
796
  const src = parseUrl(iframe.attrs.get("src") ?? "");
651
- if (!src || !PAGE_HOSTS$2.has(src.host)) return null;
797
+ if (!src || !PAGE_HOSTS$3.has(src.host)) return null;
652
798
  const [, id] = EMBED_PATH$2.exec(src.path) ?? [];
653
- return id === void 0 ? null : gif(id);
799
+ return id === void 0 ? null : gif$1(id);
654
800
  }
655
801
  function isCredit$1(element, embed) {
656
802
  if (element.tag !== "p" || element.attrs.size !== 0) return false;
@@ -658,16 +804,16 @@ function isCredit$1(element, embed) {
658
804
  if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return false;
659
805
  if (link.attrs.size !== 1) return false;
660
806
  const href = parseUrl(link.attrs.get("href") ?? "");
661
- if (!href || !PAGE_HOSTS$2.has(href.host) || PAGE_PATH.exec(href.path)?.[1] !== embed.id) return false;
807
+ if (!href || !PAGE_HOSTS$3.has(href.host) || PAGE_PATH$3.exec(href.path)?.[1] !== embed.id) return false;
662
808
  const [text, ...more] = link.children;
663
809
  return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
664
810
  }
665
811
  const giphy = {
666
812
  platform: "giphy",
667
813
  parse(root) {
668
- const wrapped = unwrapRatio(root, WRAPPER$1);
814
+ const wrapped = unwrapRatio(root, WRAPPER$3);
669
815
  const iframe = wrapped?.iframe ?? root;
670
- const found = fromIframe(iframe);
816
+ const found = fromIframe$2(iframe);
671
817
  if (!found) return null;
672
818
  return withSize({
673
819
  ...found,
@@ -677,16 +823,122 @@ const giphy = {
677
823
  isOwnScript: () => false,
678
824
  isOwnExtra: isCredit$1,
679
825
  match(url) {
680
- const id = idOf(url);
826
+ const id = idOf$4(url);
681
827
  return id === void 0 ? null : {
682
- ...gif(id),
828
+ ...gif$1(id),
829
+ options: {}
830
+ };
831
+ },
832
+ ownsFrame: (src) => PAGE_HOSTS$3.has(src.host) && underPath(src.path, "/embed")
833
+ };
834
+ // src/parser/platforms/imgur.ts
835
+ const HOSTS$13 = /* @__PURE__ */ new Set([
836
+ "imgur.com",
837
+ "www.imgur.com",
838
+ "m.imgur.com"
839
+ ]);
840
+ const HASH$1 = "([A-Za-z0-9]{5,7})";
841
+ const DATA_ID = new RegExp(`^(a/)?${HASH$1}$`);
842
+ const ALBUM_PATH = new RegExp(`^/a/${HASH$1}/?$`);
843
+ const GALLERY_PATH = new RegExp(`^/gallery/(?:[A-Za-z0-9-]{1,200}-)?${HASH$1}/?$`);
844
+ const IMAGE_PATH = new RegExp(`^/${HASH$1}/?$`);
845
+ const FILE_PATH = new RegExp(`^/${HASH$1}\\.(?:jpe?g|png|gif|gifv|mp4|webp)$`);
846
+ const SCRIPT$13 = /^(?:https?:)?\/\/s\.imgur\.com\/min\/embed\.js$/;
847
+ const NOT_IMAGES = /* @__PURE__ */ new Set([
848
+ "about",
849
+ "apps",
850
+ "blog",
851
+ "help",
852
+ "jobs",
853
+ "login",
854
+ "press",
855
+ "privacy",
856
+ "random",
857
+ "search",
858
+ "signin",
859
+ "signup",
860
+ "terms",
861
+ "tools",
862
+ "upload",
863
+ "account",
864
+ "contact",
865
+ "emerald",
866
+ "explore",
867
+ "gallery",
868
+ "hot",
869
+ "new",
870
+ "rules",
871
+ "user"
872
+ ]);
873
+ const FALLBACK$4 = /* @__PURE__ */ new Map([["a", [{
874
+ name: "href",
875
+ value: /^https:\/\/(?:www\.)?imgur\.com\//
876
+ }]]]);
877
+ function post$7(id) {
878
+ return {
879
+ platform: "imgur",
880
+ kind: "post",
881
+ url: `https://imgur.com/${id}`,
882
+ id,
883
+ variant: "iframe"
884
+ };
885
+ }
886
+ function image(hash) {
887
+ return hash === void 0 || NOT_IMAGES.has(hash.toLowerCase()) ? void 0 : hash;
888
+ }
889
+ function idOf$3(url) {
890
+ if (!url) return void 0;
891
+ if (url.host === "i.imgur.com") return image(FILE_PATH.exec(url.path)?.[1]);
892
+ if (!HOSTS$13.has(url.host)) return void 0;
893
+ const album = (ALBUM_PATH.exec(url.path) ?? GALLERY_PATH.exec(url.path))?.[1];
894
+ if (album !== void 0) return `a/${album}`;
895
+ return image(IMAGE_PATH.exec(url.path)?.[1]);
896
+ }
897
+ function withScheme(nodes) {
898
+ return nodes.map((node) => {
899
+ if (node.type !== "element") return node;
900
+ const href = node.attrs.get("href");
901
+ const attrs = new Map(node.attrs);
902
+ if (node.tag === "a" && href?.startsWith("//")) attrs.set("href", `https:${href}`);
903
+ return {
904
+ ...node,
905
+ attrs,
906
+ children: withScheme(node.children)
907
+ };
908
+ });
909
+ }
910
+ function falseOption(root, attribute) {
911
+ return root.attrs.get(attribute) === "false";
912
+ }
913
+ const imgur = {
914
+ platform: "imgur",
915
+ fallback: FALLBACK$4,
916
+ parse(root) {
917
+ if (root.tag !== "blockquote" || !hasClass(root, "imgur-embed-pub")) return null;
918
+ const id = root.attrs.get("data-id") ?? "";
919
+ const [, album, hash] = DATA_ID.exec(id) ?? [];
920
+ if (hash === void 0 || album === void 0 && !image(hash)) return null;
921
+ const options = {};
922
+ if (falseOption(root, "data-context")) options.context = false;
923
+ if (falseOption(root, "data-analytics")) options.analytics = false;
924
+ return {
925
+ ...post$7(id),
926
+ options,
927
+ fallbackHtml: rebuild(withScheme(root.children), FALLBACK$4)
928
+ };
929
+ },
930
+ isOwnScript: (src) => SCRIPT$13.test(src),
931
+ match(url) {
932
+ const id = idOf$3(url);
933
+ return id === void 0 ? null : {
934
+ ...post$7(id),
683
935
  options: {}
684
936
  };
685
937
  }
686
938
  };
687
939
  // src/parser/platforms/instagram.ts
688
- const HOSTS$8 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
689
- const POST_PATH$3 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
940
+ const HOSTS$12 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
941
+ const POST_PATH$4 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
690
942
  const TYPES = /* @__PURE__ */ new Set([
691
943
  "p",
692
944
  "reel",
@@ -694,15 +946,15 @@ const TYPES = /* @__PURE__ */ new Set([
694
946
  "tv"
695
947
  ]);
696
948
  const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
697
- const SCRIPT$9 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
698
- const FALLBACK$2 = /* @__PURE__ */ new Map([
949
+ const SCRIPT$12 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
950
+ const FALLBACK$3 = /* @__PURE__ */ new Map([
699
951
  ["div", []],
700
952
  ["a", ["href"]],
701
953
  ["p", []]
702
954
  ]);
703
- function post$5(url) {
704
- if (!url || !HOSTS$8.has(url.host)) return null;
705
- const [, user, type, code] = POST_PATH$3.exec(url.path) ?? [];
955
+ function post$6(url) {
956
+ if (!url || !HOSTS$12.has(url.host)) return null;
957
+ const [, user, type, code] = POST_PATH$4.exec(url.path) ?? [];
706
958
  if (type === void 0 || code === void 0) return null;
707
959
  if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
708
960
  return {
@@ -715,11 +967,11 @@ function post$5(url) {
715
967
  }
716
968
  const instagram = {
717
969
  platform: "instagram",
718
- fallback: FALLBACK$2,
970
+ fallback: FALLBACK$3,
719
971
  parse(root) {
720
972
  if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
721
973
  const permalink = root.attrs.get("data-instgrm-permalink");
722
- const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$5(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$5(parseUrl(permalink));
974
+ const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$6(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$6(parseUrl(permalink));
723
975
  if (!found) return null;
724
976
  const options = {};
725
977
  if (root.attrs.has("data-instgrm-captioned")) options.captioned = true;
@@ -728,12 +980,12 @@ const instagram = {
728
980
  return {
729
981
  ...found,
730
982
  options,
731
- fallbackHtml: rebuild(root.children, FALLBACK$2)
983
+ fallbackHtml: rebuild(root.children, FALLBACK$3)
732
984
  };
733
985
  },
734
- isOwnScript: (src) => SCRIPT$9.test(src),
986
+ isOwnScript: (src) => SCRIPT$12.test(src),
735
987
  match(url) {
736
- const found = post$5(url);
988
+ const found = post$6(url);
737
989
  return found && {
738
990
  ...found,
739
991
  options: {}
@@ -741,7 +993,7 @@ const instagram = {
741
993
  }
742
994
  };
743
995
  // src/parser/platforms/kick.ts
744
- const PAGE_HOSTS$1 = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
996
+ const PAGE_HOSTS$2 = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
745
997
  const CHANNEL$2 = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
746
998
  const NOT_CHANNELS = /* @__PURE__ */ new Set([
747
999
  "browse",
@@ -760,7 +1012,7 @@ const NOT_CHANNELS = /* @__PURE__ */ new Set([
760
1012
  "community-guidelines",
761
1013
  "help"
762
1014
  ]);
763
- const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
1015
+ const KEPT$1 = /* @__PURE__ */ new Set(["autoplay", "muted"]);
764
1016
  function channel$1(url, hosts) {
765
1017
  if (!url || !hosts.has(url.host)) return null;
766
1018
  const [, name] = CHANNEL$2.exec(url.path) ?? [];
@@ -782,7 +1034,7 @@ const kick = {
782
1034
  const src = parseUrl(root.attrs.get("src") ?? "");
783
1035
  const found = channel$1(src, PLAYER);
784
1036
  if (!found || !src) return null;
785
- const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
1037
+ const options = Object.fromEntries([...src.query].filter(([key]) => KEPT$1.has(key)).map(([key, value]) => [key, coerce(value)]));
786
1038
  return withSize({
787
1039
  ...found,
788
1040
  options
@@ -790,20 +1042,22 @@ const kick = {
790
1042
  },
791
1043
  isOwnScript: () => false,
792
1044
  match(url) {
793
- const found = channel$1(url, PAGE_HOSTS$1) ?? channel$1(url, PLAYER);
1045
+ const found = channel$1(url, PAGE_HOSTS$2) ?? channel$1(url, PLAYER);
794
1046
  return found && {
795
1047
  ...found,
796
1048
  options: {}
797
1049
  };
798
- }
1050
+ },
1051
+ ownsFrame: (src) => PLAYER.has(src.host)
799
1052
  };
800
1053
  // src/parser/platforms/linkedin.ts
801
- const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
1054
+ const HOST$3 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
1055
+ const FRAME_HOST$1 = "www.linkedin.com";
802
1056
  const URN = "(activity|share|ugcPost):(\\d{19})";
803
1057
  const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
804
1058
  const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
805
1059
  const EMBED_PATH$1 = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
806
- function post$4(type, id, options = {}) {
1060
+ function post$5(type, id, options = {}) {
807
1061
  const urn = `urn:li:${type}:${id}`;
808
1062
  return {
809
1063
  platform: "linkedin",
@@ -820,24 +1074,26 @@ const linkedin = {
820
1074
  parse(root) {
821
1075
  if (root.tag !== "iframe") return null;
822
1076
  const src = parseUrl(root.attrs.get("src") ?? "");
823
- if (src?.host !== "www.linkedin.com") return null;
1077
+ if (src?.host !== FRAME_HOST$1) return null;
824
1078
  const [, type, id] = EMBED_PATH$1.exec(src.path) ?? [];
825
1079
  if (type === void 0 || id === void 0) return null;
826
- return withSize(post$4(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
1080
+ return withSize(post$5(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
827
1081
  },
828
1082
  isOwnScript: () => false,
829
1083
  match(url) {
830
- if (!HOST$1.test(url.host)) return null;
1084
+ if (!HOST$3.test(url.host)) return null;
831
1085
  const path = decodeColons(url.path);
832
1086
  const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
833
- return type === void 0 || id === void 0 ? null : post$4(type, id);
834
- }
1087
+ return type === void 0 || id === void 0 ? null : post$5(type, id);
1088
+ },
1089
+ ownsFrame: (src) => src.host === FRAME_HOST$1 && underPath(src.path, "/embed")
835
1090
  };
836
1091
  // src/parser/platforms/pinterest.ts
837
- const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
1092
+ const HOST$2 = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
838
1093
  const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
839
1094
  const PIN_ID = /^\d{1,25}$/;
840
- const SCRIPT$8 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
1095
+ const FRAME_HOST = "assets.pinterest.com";
1096
+ const SCRIPT$11 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
841
1097
  const OPTION_ATTRIBUTES$4 = [
842
1098
  ["data-pin-width", "width"],
843
1099
  ["data-pin-lang", "lang"],
@@ -853,7 +1109,7 @@ function pin(id) {
853
1109
  };
854
1110
  }
855
1111
  function pinOf(url) {
856
- if (!url || !HOST.test(url.host)) return null;
1112
+ if (!url || !HOST$2.test(url.host)) return null;
857
1113
  const [, id] = PIN_PATH.exec(url.path) ?? [];
858
1114
  return id === void 0 ? null : pin(id);
859
1115
  }
@@ -871,31 +1127,32 @@ const pinterest = {
871
1127
  }
872
1128
  if (root.tag !== "iframe") return null;
873
1129
  const src = parseUrl(root.attrs.get("src") ?? "");
874
- if (src?.host !== "assets.pinterest.com" || src.path !== "/ext/embed.html") return null;
1130
+ if (src?.host !== FRAME_HOST || src.path !== "/ext/embed.html") return null;
875
1131
  const id = src.query.get("id");
876
1132
  return id !== void 0 && PIN_ID.test(id) ? {
877
1133
  ...pin(id),
878
1134
  options: {}
879
1135
  } : null;
880
1136
  },
881
- isOwnScript: (src) => SCRIPT$8.test(src),
1137
+ isOwnScript: (src) => SCRIPT$11.test(src),
882
1138
  match(url) {
883
1139
  const found = pinOf(url);
884
1140
  return found && {
885
1141
  ...found,
886
1142
  options: {}
887
1143
  };
888
- }
1144
+ },
1145
+ ownsFrame: (src) => src.host === FRAME_HOST
889
1146
  };
890
1147
  // src/parser/platforms/reddit.ts
891
- const HOSTS$7 = /* @__PURE__ */ new Set([
1148
+ const HOSTS$11 = /* @__PURE__ */ new Set([
892
1149
  "reddit.com",
893
1150
  "www.reddit.com",
894
1151
  "old.reddit.com",
895
1152
  "new.reddit.com"
896
1153
  ]);
897
- const POST_PATH$2 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
898
- const SCRIPT$7 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
1154
+ const POST_PATH$3 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
1155
+ const SCRIPT$10 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
899
1156
  const OPTION_ATTRIBUTES$3 = [
900
1157
  "depth",
901
1158
  "style",
@@ -908,9 +1165,9 @@ const OPTION_ATTRIBUTES$3 = [
908
1165
  "showusername",
909
1166
  "snippet"
910
1167
  ].map((name) => [`data-embed-${name}`, name]);
911
- function post$3(url) {
912
- if (!url || !HOSTS$7.has(url.host)) return null;
913
- const [, sub, postId, slug, commentId] = POST_PATH$2.exec(url.path) ?? [];
1168
+ function post$4(url) {
1169
+ if (!url || !HOSTS$11.has(url.host)) return null;
1170
+ const [, sub, postId, slug, commentId] = POST_PATH$3.exec(url.path) ?? [];
914
1171
  if (sub === void 0 || postId === void 0) return null;
915
1172
  const base = {
916
1173
  platform: "reddit",
@@ -934,7 +1191,7 @@ const reddit = {
934
1191
  platform: "reddit",
935
1192
  parse(root) {
936
1193
  if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
937
- const found = descendants(root.children).map((element) => element.tag === "a" ? post$3(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
1194
+ const found = descendants(root.children).map((element) => element.tag === "a" ? post$4(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
938
1195
  if (!found) return null;
939
1196
  const height = pixels(root.attrs.get("data-embed-height"));
940
1197
  return withSize({
@@ -942,9 +1199,9 @@ const reddit = {
942
1199
  options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
943
1200
  }, height === void 0 ? void 0 : { height });
944
1201
  },
945
- isOwnScript: (src) => SCRIPT$7.test(src),
1202
+ isOwnScript: (src) => SCRIPT$10.test(src),
946
1203
  match(url) {
947
- const found = post$3(url);
1204
+ const found = post$4(url);
948
1205
  return found && {
949
1206
  ...found,
950
1207
  options: {}
@@ -952,15 +1209,15 @@ const reddit = {
952
1209
  }
953
1210
  };
954
1211
  // src/parser/platforms/snapchat.ts
955
- const HOSTS$6 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
956
- const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
957
- const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
958
- const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
1212
+ const HOSTS$10 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
1213
+ const USER$1 = "([A-Za-z][A-Za-z0-9._-]{1,29})";
1214
+ const SPOTLIGHT = new RegExp(`^(?:/@${USER$1})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
1215
+ const PROFILE = new RegExp(`^/(?:@|add/)${USER$1}$`);
959
1216
  const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
960
- const HIGHLIGHT = new RegExp(`^/@${USER}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
961
- const SCRIPT$6 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
1217
+ const HIGHLIGHT = new RegExp(`^/@${USER$1}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
1218
+ const SCRIPT$9 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
962
1219
  function content$1(url) {
963
- if (!url || !HOSTS$6.has(url.host)) return null;
1220
+ if (!url || !HOSTS$10.has(url.host)) return null;
964
1221
  const path = url.path.replace(/\/$/, "");
965
1222
  const base = {
966
1223
  platform: "snapchat",
@@ -1025,7 +1282,7 @@ const snapchat = {
1025
1282
  height
1026
1283
  });
1027
1284
  },
1028
- isOwnScript: (src) => SCRIPT$6.test(src),
1285
+ isOwnScript: (src) => SCRIPT$9.test(src),
1029
1286
  match(url) {
1030
1287
  const found = content$1(url);
1031
1288
  return found && {
@@ -1035,7 +1292,7 @@ const snapchat = {
1035
1292
  }
1036
1293
  };
1037
1294
  // src/parser/platforms/soundcloud.ts
1038
- const PAGE_HOSTS = /* @__PURE__ */ new Set([
1295
+ const PAGE_HOSTS$1 = /* @__PURE__ */ new Set([
1039
1296
  "soundcloud.com",
1040
1297
  "www.soundcloud.com",
1041
1298
  "m.soundcloud.com"
@@ -1076,6 +1333,7 @@ const NOT_SOUNDS = /* @__PURE__ */ new Set([
1076
1333
  "toptracks"
1077
1334
  ]);
1078
1335
  const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
1336
+ const WIDGET_HOST = "w.soundcloud.com";
1079
1337
  function sound(url, id) {
1080
1338
  return {
1081
1339
  platform: "soundcloud",
@@ -1095,7 +1353,7 @@ function fromApi(url) {
1095
1353
  return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
1096
1354
  }
1097
1355
  function fromPage$1(url) {
1098
- if (!PAGE_HOSTS.has(url.host)) return null;
1356
+ if (!PAGE_HOSTS$1.has(url.host)) return null;
1099
1357
  const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
1100
1358
  if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
1101
1359
  if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
@@ -1116,7 +1374,7 @@ function isCreditLink(node) {
1116
1374
  if (node?.type !== "element" || node.tag !== "a") return false;
1117
1375
  if ([...node.attrs.keys()].some((name) => !LINK_ATTRIBUTES.has(name))) return false;
1118
1376
  const [text, ...rest] = node.children;
1119
- return rest.length === 0 && text?.type === "text" && PAGE_HOSTS.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
1377
+ return rest.length === 0 && text?.type === "text" && PAGE_HOSTS$1.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
1120
1378
  }
1121
1379
  /** Share code's credit: a styled `div` with the artist link, ` · `, and the sound link. */
1122
1380
  function isCredit(element) {
@@ -1129,7 +1387,7 @@ const soundcloud = {
1129
1387
  parse(root) {
1130
1388
  if (root.tag !== "iframe") return null;
1131
1389
  const src = parseUrl(root.attrs.get("src") ?? "");
1132
- if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
1390
+ if (src?.host !== WIDGET_HOST || !/^\/player\/?$/.test(src.path)) return null;
1133
1391
  let found = fromApi(parseUrl(src.query.get("url") ?? ""));
1134
1392
  if (!found) return null;
1135
1393
  const outer = src.query.get("secret_token");
@@ -1155,13 +1413,55 @@ const soundcloud = {
1155
1413
  ...found,
1156
1414
  options: {}
1157
1415
  };
1158
- }
1416
+ },
1417
+ ownsFrame: (src) => src.host === WIDGET_HOST
1418
+ };
1419
+ // src/parser/platforms/rumble.ts
1420
+ const PATH = /^\/embed\/(v[a-z0-9]{1,12})\/?$/;
1421
+ const HOSTS$9 = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
1422
+ function video$4(id) {
1423
+ return {
1424
+ platform: "rumble",
1425
+ kind: "video",
1426
+ url: `https://rumble.com/embed/${id}/`,
1427
+ id,
1428
+ variant: "iframe"
1429
+ };
1430
+ }
1431
+ function idOf$2(url, hosts) {
1432
+ return url && hosts.has(url.host) ? PATH.exec(url.path)?.[1] : void 0;
1433
+ }
1434
+ const rumble = {
1435
+ platform: "rumble",
1436
+ parse(root) {
1437
+ if (root.tag !== "iframe") return null;
1438
+ const src = parseUrl(root.attrs.get("src") ?? "");
1439
+ const id = idOf$2(src, /* @__PURE__ */ new Set(["rumble.com"]));
1440
+ if (id === void 0 || !src) return null;
1441
+ const options = {};
1442
+ const pub = src.query.get("pub");
1443
+ if (pub) options.pub = coerce(pub);
1444
+ return withSize({
1445
+ ...video$4(id),
1446
+ options
1447
+ }, sizeOf(root));
1448
+ },
1449
+ isOwnScript: () => false,
1450
+ match(url) {
1451
+ const id = idOf$2(url, HOSTS$9);
1452
+ return id === void 0 ? null : {
1453
+ ...video$4(id),
1454
+ options: {}
1455
+ };
1456
+ },
1457
+ ownsFrame: (src) => src.host === "rumble.com" && underPath(src.path, "/embed")
1159
1458
  };
1160
1459
  // src/parser/platforms/spotify.ts
1161
1460
  const CONTENT_PATH = new RegExp(`^(?:/intl-[a-z]{2}(?:-[A-Za-z]{2})?)?(?:/embed)?/(track|album|playlist|artist|episode|show|audiobook|chapter)/([A-Za-z0-9]{22})(/video)?/?$`);
1162
1461
  const DROPPED$1 = /* @__PURE__ */ new Set(["utm_source", "si"]);
1462
+ const HOST$1 = "open.spotify.com";
1163
1463
  function content(url) {
1164
- if (url?.host !== "open.spotify.com") return null;
1464
+ if (url?.host !== HOST$1) return null;
1165
1465
  const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
1166
1466
  if (type === void 0 || id === void 0) return null;
1167
1467
  return {
@@ -1201,18 +1501,163 @@ const spotify = {
1201
1501
  variant: found.variant,
1202
1502
  options: {}
1203
1503
  };
1504
+ },
1505
+ ownsFrame: (src) => src.host === HOST$1 && underPath(src.path, "/embed")
1506
+ };
1507
+ // src/parser/platforms/strava.ts
1508
+ const HOSTS$8 = /* @__PURE__ */ new Set(["strava.com", "www.strava.com"]);
1509
+ const NUMBER = /^\d{1,20}$/;
1510
+ const PAGE_PATH$2 = /^\/(activities|routes)\/(\d{1,20})\/?$/;
1511
+ const SCRIPT$8 = /^(?:https?:)?\/\/strava-embeds\.com\/embed\.js$/;
1512
+ const STYLES = /* @__PURE__ */ new Set(["standard", "minimal"]);
1513
+ const MAP_HASH = /^[A-Za-z0-9_-]{1,100}$/;
1514
+ const PAGES = {
1515
+ activity: "activities",
1516
+ route: "routes"
1517
+ };
1518
+ function item(type, number) {
1519
+ return {
1520
+ platform: "strava",
1521
+ kind: "post",
1522
+ url: `https://www.strava.com/${PAGES[type]}/${number}`,
1523
+ id: `${type}/${number}`,
1524
+ variant: "iframe"
1525
+ };
1526
+ }
1527
+ function isType(value) {
1528
+ return value === "activity" || value === "route";
1529
+ }
1530
+ const strava = {
1531
+ platform: "strava",
1532
+ parse(root) {
1533
+ if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
1534
+ if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
1535
+ const type = root.attrs.get("data-embed-type");
1536
+ const number = root.attrs.get("data-embed-id") ?? "";
1537
+ if (!isType(type) || !NUMBER.test(number)) return null;
1538
+ const options = {};
1539
+ const style = root.attrs.get("data-style");
1540
+ if (style !== void 0 && STYLES.has(style)) options.style = style;
1541
+ if (type === "route" && root.attrs.get("data-full-width") === "true") options.fullWidth = true;
1542
+ const mapHash = root.attrs.get("data-map-hash");
1543
+ if (mapHash !== void 0 && MAP_HASH.test(mapHash)) options.mapHash = mapHash;
1544
+ return {
1545
+ ...item(type, number),
1546
+ options
1547
+ };
1548
+ },
1549
+ isOwnScript: (src) => SCRIPT$8.test(src),
1550
+ match(url) {
1551
+ if (!HOSTS$8.has(url.host)) return null;
1552
+ const [, page, number] = PAGE_PATH$2.exec(url.path) ?? [];
1553
+ if (page === void 0 || number === void 0) return null;
1554
+ return {
1555
+ ...item(page === "routes" ? "route" : "activity", number),
1556
+ options: {}
1557
+ };
1204
1558
  }
1205
1559
  };
1560
+ // src/parser/platforms/streamable.ts
1561
+ const ID$2 = "([a-z0-9]{4,8})";
1562
+ const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
1563
+ const PLAYER_PATH$2 = new RegExp(`^/[eo]/${ID$2}$`);
1564
+ const PAGE_PATH$1 = new RegExp(`^/${ID$2}$`);
1565
+ const NOT_VIDEOS = /* @__PURE__ */ new Set([
1566
+ "about",
1567
+ "login",
1568
+ "signup",
1569
+ "terms",
1570
+ "privacy",
1571
+ "pricing",
1572
+ "upload",
1573
+ "help",
1574
+ "apps",
1575
+ "blog",
1576
+ "jobs",
1577
+ "press",
1578
+ "tools",
1579
+ "embed",
1580
+ "plans",
1581
+ "contact",
1582
+ "support",
1583
+ "videos",
1584
+ "account",
1585
+ "profile"
1586
+ ]);
1587
+ const WRAPPER$2 = /^width:\s*100%;\s*height:\s*0(?:px)?;\s*position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;?$/;
1588
+ const KEPT = /* @__PURE__ */ new Set([
1589
+ "loop",
1590
+ "autoplay",
1591
+ "nocontrols",
1592
+ "hd",
1593
+ "muted"
1594
+ ]);
1595
+ const STRAY_END = /<\/div\s*>$/i;
1596
+ function video$3(id) {
1597
+ return {
1598
+ platform: "streamable",
1599
+ kind: "video",
1600
+ url: `https://streamable.com/${id}`,
1601
+ id,
1602
+ variant: "iframe"
1603
+ };
1604
+ }
1605
+ function validId(id) {
1606
+ return id !== void 0 && !NOT_VIDEOS.has(id);
1607
+ }
1608
+ function fromIframe$1(iframe) {
1609
+ if (iframe.tag !== "iframe") return null;
1610
+ const src = parseUrl(iframe.attrs.get("src") ?? "");
1611
+ if (!src || src.host !== "streamable.com") return null;
1612
+ const [, id] = PLAYER_PATH$2.exec(src.path) ?? [];
1613
+ if (!validId(id)) return null;
1614
+ const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
1615
+ return {
1616
+ ...video$3(id),
1617
+ options
1618
+ };
1619
+ }
1620
+ function idOf$1(url) {
1621
+ if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
1622
+ const id = (PLAYER_PATH$2.exec(url.path) ?? PAGE_PATH$1.exec(url.path))?.[1];
1623
+ return validId(id) ? id : void 0;
1624
+ }
1625
+ const streamable = {
1626
+ platform: "streamable",
1627
+ parse(root) {
1628
+ const wrapped = unwrapRatio(root, WRAPPER$2);
1629
+ const iframe = wrapped?.iframe ?? root;
1630
+ const found = fromIframe$1(iframe);
1631
+ if (!found) return null;
1632
+ return withSize(found, wrapped?.size ?? sizeOf(iframe));
1633
+ },
1634
+ isOwnScript: () => false,
1635
+ repair(html) {
1636
+ const code = html.trimEnd();
1637
+ const end = STRAY_END.exec(code);
1638
+ if (!end) return null;
1639
+ const trimmed = code.slice(0, end.index).trimEnd();
1640
+ return /^\s*<iframe[\s>]/i.test(trimmed) ? trimmed : null;
1641
+ },
1642
+ match(url) {
1643
+ const id = idOf$1(url);
1644
+ return id === void 0 ? null : {
1645
+ ...video$3(id),
1646
+ options: {}
1647
+ };
1648
+ },
1649
+ ownsFrame: (src) => src.host === "streamable.com" && (underPath(src.path, "/e") || underPath(src.path, "/o"))
1650
+ };
1206
1651
  // src/parser/platforms/telegram.ts
1207
- const HOSTS$5 = /* @__PURE__ */ new Set([
1652
+ const HOSTS$7 = /* @__PURE__ */ new Set([
1208
1653
  "t.me",
1209
1654
  "telegram.me",
1210
1655
  "www.telegram.me"
1211
1656
  ]);
1212
1657
  const CHANNEL$1 = "[A-Za-z][A-Za-z0-9_]{2,31}";
1213
1658
  const POST$1 = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
1214
- const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
1215
- const SCRIPT$5 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
1659
+ const POST_PATH$2 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
1660
+ const SCRIPT$7 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
1216
1661
  const OTHER_WIDGETS = [
1217
1662
  "data-telegram-login",
1218
1663
  "data-telegram-discussion",
@@ -1227,7 +1672,7 @@ const OPTION_ATTRIBUTES$2 = [
1227
1672
  ["data-dark", "dark"],
1228
1673
  ["data-dark-color", "darkColor"]
1229
1674
  ];
1230
- function post$2(channel, id, options) {
1675
+ function post$3(channel, id, options) {
1231
1676
  return {
1232
1677
  platform: "telegram",
1233
1678
  kind: "post",
@@ -1241,40 +1686,113 @@ const telegram = {
1241
1686
  platform: "telegram",
1242
1687
  parse: () => null,
1243
1688
  parseScript(script) {
1244
- if (!SCRIPT$5.test(script.attrs.get("src") ?? "")) return null;
1689
+ if (!SCRIPT$7.test(script.attrs.get("src") ?? "")) return null;
1245
1690
  if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
1246
1691
  const [, channel, id] = POST$1.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
1247
1692
  if (channel === void 0 || id === void 0) return null;
1248
1693
  const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
1249
1694
  if (script.attrs.has("data-single")) options.single = true;
1250
- return post$2(channel, id, options);
1695
+ return post$3(channel, id, options);
1251
1696
  },
1252
- isOwnScript: (src) => SCRIPT$5.test(src),
1697
+ isOwnScript: (src) => SCRIPT$7.test(src),
1253
1698
  match(url) {
1254
- if (!HOSTS$5.has(url.host)) return null;
1255
- const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
1699
+ if (!HOSTS$7.has(url.host)) return null;
1700
+ const [, channel, id] = POST_PATH$2.exec(url.path) ?? [];
1256
1701
  if (channel === void 0 || id === void 0) return null;
1257
1702
  const options = {};
1258
1703
  if (url.query.has("single")) options.single = true;
1259
1704
  const comment = url.query.get("comment");
1260
1705
  if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
1261
- return post$2(channel, id, options);
1706
+ return post$3(channel, id, options);
1262
1707
  }
1263
1708
  };
1709
+ // src/parser/platforms/tenor.ts
1710
+ const HOSTS$6 = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
1711
+ const ID$1 = "(\\d{1,20})";
1712
+ const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID$1}/?$`);
1713
+ const FRAME_PATH$2 = new RegExp(`^/embed/${ID$1}$`);
1714
+ const SCRIPT$6 = /^(?:https?:)?\/\/tenor\.com\/embed\.js$/;
1715
+ const RATIO = /^\d{1,3}(?:\.\d{1,4})?$/;
1716
+ const DEFAULT_RATIO = 1.33;
1717
+ const FALLBACK$2 = /* @__PURE__ */ new Map([["a", ["href"]]]);
1718
+ function gif(id) {
1719
+ return {
1720
+ platform: "tenor",
1721
+ kind: "video",
1722
+ url: `https://tenor.com/view/${id}`,
1723
+ id,
1724
+ variant: "iframe"
1725
+ };
1726
+ }
1727
+ function idOf(url) {
1728
+ return url && HOSTS$6.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
1729
+ }
1730
+ function ratioSize(ratio) {
1731
+ const width = Math.round(ratio * 1e4);
1732
+ if (!(width > 0 && width <= 1e6)) return void 0;
1733
+ const divisor = gcd(width, 1e4);
1734
+ return {
1735
+ width: width / divisor,
1736
+ height: 1e4 / divisor
1737
+ };
1738
+ }
1739
+ function gcd(a, b) {
1740
+ return b === 0 ? a : gcd(b, a % b);
1741
+ }
1742
+ function fromDiv(root) {
1743
+ if (!hasClass(root, "tenor-gif-embed")) return null;
1744
+ const id = root.attrs.get("data-postid") ?? "";
1745
+ if (!new RegExp(`^${ID$1}$`).test(id)) return null;
1746
+ const given = root.attrs.get("data-aspect-ratio");
1747
+ if (given !== void 0 && !RATIO.test(given)) return null;
1748
+ const size = ratioSize(given === void 0 ? DEFAULT_RATIO : Number(given));
1749
+ if (!size) return null;
1750
+ return withSize({
1751
+ ...gif(id),
1752
+ options: {},
1753
+ fallbackHtml: rebuild(root.children, FALLBACK$2)
1754
+ }, size);
1755
+ }
1756
+ function fromIframe(root) {
1757
+ const src = parseUrl(root.attrs.get("src") ?? "");
1758
+ if (!src || src.host !== "tenor.com") return null;
1759
+ const [, id] = FRAME_PATH$2.exec(src.path) ?? [];
1760
+ return id === void 0 ? null : withSize({
1761
+ ...gif(id),
1762
+ options: {}
1763
+ }, sizeOf(root));
1764
+ }
1765
+ const tenor = {
1766
+ platform: "tenor",
1767
+ fallback: FALLBACK$2,
1768
+ parse(root) {
1769
+ if (root.tag === "div") return fromDiv(root);
1770
+ return root.tag === "iframe" ? fromIframe(root) : null;
1771
+ },
1772
+ isOwnScript: (src) => SCRIPT$6.test(src),
1773
+ match(url) {
1774
+ const id = idOf(url);
1775
+ return id === void 0 ? null : {
1776
+ ...gif(id),
1777
+ options: {}
1778
+ };
1779
+ },
1780
+ ownsFrame: (src) => src.host === "tenor.com" && underPath(src.path, "/embed")
1781
+ };
1264
1782
  // src/parser/platforms/threads.ts
1265
- const HOSTS$4 = /* @__PURE__ */ new Set([
1783
+ const HOSTS$5 = /* @__PURE__ */ new Set([
1266
1784
  "threads.com",
1267
1785
  "www.threads.com",
1268
1786
  "threads.net",
1269
1787
  "www.threads.net"
1270
1788
  ]);
1271
- const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
1272
- const SCRIPT$4 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
1789
+ const POST_PATH$1 = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
1790
+ const SCRIPT$5 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
1273
1791
  const OPTION_ATTRIBUTES$1 = [["data-theme", "theme"], ["data-text-post-version", "version"]];
1274
1792
  const FALLBACK$1 = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
1275
- function post$1(url) {
1276
- if (!url || !HOSTS$4.has(url.host)) return null;
1277
- const [, code] = POST_PATH.exec(url.path) ?? [];
1793
+ function post$2(url) {
1794
+ if (!url || !HOSTS$5.has(url.host)) return null;
1795
+ const [, code] = POST_PATH$1.exec(url.path) ?? [];
1278
1796
  if (code === void 0) return null;
1279
1797
  return {
1280
1798
  platform: "threads",
@@ -1289,7 +1807,7 @@ const threads = {
1289
1807
  fallback: FALLBACK$1,
1290
1808
  parse(root) {
1291
1809
  if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
1292
- const found = post$1(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
1810
+ const found = post$2(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
1293
1811
  if (!found) return null;
1294
1812
  const elementId = root.attrs.get("id");
1295
1813
  if (elementId !== void 0 && elementId !== `ig-tp-${found.id}`) return null;
@@ -1299,9 +1817,9 @@ const threads = {
1299
1817
  fallbackHtml: rebuild(root.children, FALLBACK$1)
1300
1818
  };
1301
1819
  },
1302
- isOwnScript: (src) => SCRIPT$4.test(src),
1820
+ isOwnScript: (src) => SCRIPT$5.test(src),
1303
1821
  match(url) {
1304
- const found = post$1(url);
1822
+ const found = post$2(url);
1305
1823
  return found && {
1306
1824
  ...found,
1307
1825
  options: {}
@@ -1309,11 +1827,11 @@ const threads = {
1309
1827
  }
1310
1828
  };
1311
1829
  // src/parser/platforms/tiktok.ts
1312
- const HOSTS$3 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
1830
+ const HOSTS$4 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
1313
1831
  const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
1314
1832
  const PLAYER_PATH$1 = /^\/player\/v1\/(\d{1,25})\/?$/;
1315
1833
  const VIDEO_ID$1 = /^\d{1,25}$/;
1316
- const SCRIPT$3 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
1834
+ const SCRIPT$4 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
1317
1835
  function video$2(id, user = "", options = {}) {
1318
1836
  return {
1319
1837
  platform: "tiktok",
@@ -1329,7 +1847,7 @@ const tiktok = {
1329
1847
  parse(root) {
1330
1848
  if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
1331
1849
  const cite = parseUrl(root.attrs.get("cite") ?? "");
1332
- const [, user, citeId] = cite && HOSTS$3.has(cite.host) ? VIDEO_PATH.exec(cite.path) ?? [] : [];
1850
+ const [, user, citeId] = cite && HOSTS$4.has(cite.host) ? VIDEO_PATH.exec(cite.path) ?? [] : [];
1333
1851
  const dataId = root.attrs.get("data-video-id");
1334
1852
  if (dataId !== void 0 && !VIDEO_ID$1.test(dataId)) return null;
1335
1853
  if (dataId !== void 0 && citeId !== void 0 && dataId !== citeId) return null;
@@ -1338,17 +1856,63 @@ const tiktok = {
1338
1856
  }
1339
1857
  if (root.tag !== "iframe") return null;
1340
1858
  const src = parseUrl(root.attrs.get("src") ?? "");
1341
- if (!src || !HOSTS$3.has(src.host)) return null;
1859
+ if (!src || !HOSTS$4.has(src.host)) return null;
1342
1860
  const [, id] = PLAYER_PATH$1.exec(src.path) ?? [];
1343
1861
  if (id === void 0) return null;
1344
1862
  return withSize(video$2(id, "", Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
1345
1863
  },
1346
- isOwnScript: (src) => SCRIPT$3.test(src),
1864
+ isOwnScript: (src) => SCRIPT$4.test(src),
1347
1865
  match(url) {
1348
- if (!HOSTS$3.has(url.host)) return null;
1866
+ if (!HOSTS$4.has(url.host)) return null;
1349
1867
  const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
1350
1868
  return user === void 0 || id === void 0 ? null : video$2(id, user);
1351
- }
1869
+ },
1870
+ ownsFrame: (src) => HOSTS$4.has(src.host) && underPath(src.path, "/player")
1871
+ };
1872
+ // src/parser/platforms/truthsocial.ts
1873
+ const HOSTS$3 = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
1874
+ const USER = "(@[A-Za-z0-9_.-]{1,64})";
1875
+ const ID = "(\\d{1,25})";
1876
+ const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
1877
+ const FRAME_PATH$1 = new RegExp(`^/${USER}/${ID}/embed$`);
1878
+ const SCRIPT$3 = /^(?:https?:)?\/\/truthsocial\.com\/embed\.js$/;
1879
+ function post$1(user, id) {
1880
+ return {
1881
+ platform: "truthsocial",
1882
+ kind: "post",
1883
+ url: `https://truthsocial.com/${user}/posts/${id}`,
1884
+ id,
1885
+ variant: "iframe"
1886
+ };
1887
+ }
1888
+ function fromUrl$1(url) {
1889
+ if (!url || !HOSTS$3.has(url.host)) return null;
1890
+ const [, user, id] = POST_PATH.exec(url.path) ?? [];
1891
+ return user === void 0 || id === void 0 ? null : post$1(user, id);
1892
+ }
1893
+ const truthsocial = {
1894
+ platform: "truthsocial",
1895
+ parse(root) {
1896
+ if (root.tag !== "iframe") return null;
1897
+ const src = parseUrl(root.attrs.get("src") ?? "");
1898
+ if (!src || src.host !== "truthsocial.com") return null;
1899
+ const [, user, id] = FRAME_PATH$1.exec(src.path) ?? [];
1900
+ if (user === void 0 || id === void 0) return null;
1901
+ const options = hasClass(root, "truthsocial-video") ? { video: true } : {};
1902
+ return withSize({
1903
+ ...post$1(user, id),
1904
+ options
1905
+ }, sizeOf(root));
1906
+ },
1907
+ isOwnScript: (src) => SCRIPT$3.test(src),
1908
+ match(url) {
1909
+ const found = fromUrl$1(url);
1910
+ return found && {
1911
+ ...found,
1912
+ options: {}
1913
+ };
1914
+ },
1915
+ ownsFrame: (src) => src.host === "truthsocial.com" && src.path.startsWith("/@")
1352
1916
  };
1353
1917
  // src/parser/platforms/tumblr.ts
1354
1918
  const BLOG = "([a-z0-9-]{1,32})";
@@ -1423,6 +1987,8 @@ const HOSTS$2 = /* @__PURE__ */ new Set([
1423
1987
  "www.twitch.tv",
1424
1988
  "m.twitch.tv"
1425
1989
  ]);
1990
+ const PLAYER_HOST$1 = "player.twitch.tv";
1991
+ const CLIPS_HOST = "clips.twitch.tv";
1426
1992
  const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
1427
1993
  const VIDEO$1 = /^v?(\d{1,12})$/;
1428
1994
  const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
@@ -1481,7 +2047,7 @@ function fromPlayer$1(url) {
1481
2047
  return list !== void 0 && COLLECTION.test(list) ? collection(list) : null;
1482
2048
  }
1483
2049
  function fromPage(url) {
1484
- if (url.host === "clips.twitch.tv") {
2050
+ if (url.host === CLIPS_HOST) {
1485
2051
  const slug = url.path.replace(/^\/|\/$/g, "");
1486
2052
  return CLIP.test(slug) ? {
1487
2053
  found: clip(slug),
@@ -1521,8 +2087,8 @@ const twitch = {
1521
2087
  const src = parseUrl(root.attrs.get("src") ?? "");
1522
2088
  if (!src) return null;
1523
2089
  let found = null;
1524
- if (src.host === "player.twitch.tv" && /^\/?$/.test(src.path)) found = fromPlayer$1(src);
1525
- if (src.host === "clips.twitch.tv" && src.path === "/embed") {
2090
+ if (src.host === PLAYER_HOST$1 && /^\/?$/.test(src.path)) found = fromPlayer$1(src);
2091
+ if (src.host === CLIPS_HOST && src.path === "/embed") {
1526
2092
  const slug = src.query.get("clip") ?? "";
1527
2093
  found = CLIP.test(slug) ? clip(slug) : null;
1528
2094
  }
@@ -1538,7 +2104,8 @@ const twitch = {
1538
2104
  ...page.found,
1539
2105
  options: page.options
1540
2106
  };
1541
- }
2107
+ },
2108
+ ownsFrame: (src) => src.host === PLAYER_HOST$1 || src.host === CLIPS_HOST && underPath(src.path, "/embed")
1542
2109
  };
1543
2110
  // src/parser/platforms/vimeo.ts
1544
2111
  const HOSTS$1 = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
@@ -1551,7 +2118,7 @@ const PAGE_PATHS = [
1551
2118
  new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
1552
2119
  ];
1553
2120
  const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
1554
- const WRAPPER = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
2121
+ const WRAPPER$1 = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
1555
2122
  const SCRIPT$1 = /^(?:https?:)?\/\/player\.vimeo\.com\/api\/player\.js$/;
1556
2123
  const DROPPED = /* @__PURE__ */ new Set([
1557
2124
  "h",
@@ -1559,6 +2126,7 @@ const DROPPED = /* @__PURE__ */ new Set([
1559
2126
  "player_id"
1560
2127
  ]);
1561
2128
  const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
2129
+ const PLAYER_HOST = "player.vimeo.com";
1562
2130
  function video$1(id, hash) {
1563
2131
  return {
1564
2132
  platform: "vimeo",
@@ -1573,7 +2141,7 @@ function start(url) {
1573
2141
  return time ? { t: time } : {};
1574
2142
  }
1575
2143
  function fromPlayer(url) {
1576
- if (url?.host !== "player.vimeo.com") return null;
2144
+ if (url?.host !== PLAYER_HOST) return null;
1577
2145
  const [, id] = PLAYER_PATH.exec(url.path) ?? [];
1578
2146
  if (id === void 0) return null;
1579
2147
  const hash = url.query.get("h");
@@ -1590,7 +2158,7 @@ function fromPlayer(url) {
1590
2158
  const vimeo = {
1591
2159
  platform: "vimeo",
1592
2160
  parse(root) {
1593
- const wrapped = unwrapRatio(root, WRAPPER);
2161
+ const wrapped = unwrapRatio(root, WRAPPER$1);
1594
2162
  const iframe = wrapped?.iframe ?? root;
1595
2163
  if (iframe.tag !== "iframe") return null;
1596
2164
  const embed = fromPlayer(parseUrl(iframe.attrs.get("src") ?? ""));
@@ -1609,7 +2177,8 @@ const vimeo = {
1609
2177
  };
1610
2178
  }
1611
2179
  return null;
1612
- }
2180
+ },
2181
+ ownsFrame: (src) => src.host === PLAYER_HOST
1613
2182
  };
1614
2183
  // src/parser/platforms/x.ts
1615
2184
  const HOSTS = /* @__PURE__ */ new Set([
@@ -1762,7 +2331,8 @@ const platforms = [
1762
2331
  ...video(id, kind === "shorts"),
1763
2332
  options: urlOptions(url, nocookie)
1764
2333
  };
1765
- }
2334
+ },
2335
+ ownsFrame: (src) => NOCOOKIE_HOSTS.has(src.host) || YOUTUBE_HOSTS.has(src.host) && underPath(src.path, "/embed")
1766
2336
  },
1767
2337
  telegram,
1768
2338
  snapchat,
@@ -1778,9 +2348,162 @@ const platforms = [
1778
2348
  applepodcasts,
1779
2349
  kick,
1780
2350
  giphy,
2351
+ tenor,
2352
+ streamable,
2353
+ rumble,
2354
+ truthsocial,
2355
+ imgur,
2356
+ strava,
2357
+ flickr,
1781
2358
  bluesky,
1782
2359
  tumblr
1783
2360
  ];
2361
+ // src/parser/iframe.ts
2362
+ const REFERRER_POLICIES = [
2363
+ "no-referrer",
2364
+ "origin",
2365
+ "same-origin",
2366
+ "strict-origin",
2367
+ "strict-origin-when-cross-origin"
2368
+ ];
2369
+ const SANDBOX_KEYWORDS = /* @__PURE__ */ new Set([
2370
+ "allow-downloads",
2371
+ "allow-forms",
2372
+ "allow-modals",
2373
+ "allow-orientation-lock",
2374
+ "allow-pointer-lock",
2375
+ "allow-popups",
2376
+ "allow-popups-to-escape-sandbox",
2377
+ "allow-presentation",
2378
+ "allow-same-origin",
2379
+ "allow-scripts",
2380
+ "allow-top-navigation",
2381
+ "allow-top-navigation-by-user-activation",
2382
+ "allow-top-navigation-to-custom-protocols"
2383
+ ]);
2384
+ const FEATURES = /* @__PURE__ */ new Set([
2385
+ "autoplay",
2386
+ "fullscreen",
2387
+ "encrypted-media",
2388
+ "picture-in-picture",
2389
+ "clipboard-write",
2390
+ "web-share"
2391
+ ]);
2392
+ const HOST = "[a-z0-9-]+(?:\\.[a-z0-9-]+)*(?::\\d{1,5})?";
2393
+ const SRC = new RegExp(`^(?:https:)?//${HOST}(?:[/?#]|$)`, "i");
2394
+ const ORIGIN = new RegExp(`^(?:\\*|'self'|'src'|'none'|https://${HOST})$`, "i");
2395
+ const REWRITTEN_PATH = /\/\.{1,2}(?:\/|$)|\/\/|%(?:2[de]|3\d|[46][1-9a-f]|[57][\da]|5f|7e)/i;
2396
+ const ASCII_WHITESPACE = /[\t\n\f\r ]+/;
2397
+ const STYLE_SIZE = /^\s*(width|height)\s*:(.*)$/is;
2398
+ const PX = /^(\d+)px$/i;
2399
+ const WRAPPER = /(?:^|;)\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,20})?)%\s*(?:;|$)/i;
2400
+ /**
2401
+ * Never throws. `null` unless the code holds exactly one `<iframe>` with an https `src` that no
2402
+ * named platform owns; everything around the iframe is dropped.
2403
+ */
2404
+ function parseIframe(html) {
2405
+ if (typeof html !== "string") return null;
2406
+ const nodes = parseHtml(html);
2407
+ if (!nodes) return null;
2408
+ const elements = descendants(nodes);
2409
+ const [iframe, ...others] = elements.filter((element) => element.tag === "iframe");
2410
+ if (!iframe || others.length > 0) return null;
2411
+ const parent = elements.find((element) => element.children.includes(iframe));
2412
+ const { attrs } = iframe;
2413
+ const size = sizeOf(iframe) ?? styleSize(iframe);
2414
+ return check({
2415
+ src: attrs.get("src"),
2416
+ title: attrs.get("title"),
2417
+ allow: attrs.get("allow"),
2418
+ allowFullscreen: attrs.has("allowfullscreen"),
2419
+ referrerPolicy: attrs.get("referrerpolicy"),
2420
+ sandbox: attrs.get("sandbox"),
2421
+ scrolling: attrs.get("scrolling"),
2422
+ size: size ?? {},
2423
+ ratio: size ? void 0 : parent && unwrapRatio(parent, WRAPPER)?.size
2424
+ });
2425
+ }
2426
+ /** Re-checks a value a host built or stored; `null` when its `src` is unsafe or a named platform's. */
2427
+ function checkIframe(embed) {
2428
+ return check(embed);
2429
+ }
2430
+ function check(value) {
2431
+ if (typeof value !== "object" || value === null) return null;
2432
+ const raw = value;
2433
+ const src = checkSrc(raw.src);
2434
+ if (src === null) return null;
2435
+ const title = typeof raw.title === "string" ? raw.title.trim() : "";
2436
+ const policy = typeof raw.referrerPolicy === "string" ? raw.referrerPolicy.toLowerCase() : void 0;
2437
+ const referrerPolicy = REFERRER_POLICIES.find((keyword) => keyword === policy);
2438
+ const ratio = checkRatio(raw.ratio);
2439
+ return {
2440
+ src,
2441
+ ...title ? { title } : {},
2442
+ allow: typeof raw.allow === "string" ? checkAllow(raw.allow) : "",
2443
+ allowFullscreen: raw.allowFullscreen === true,
2444
+ ...referrerPolicy ? { referrerPolicy } : {},
2445
+ ...typeof raw.sandbox === "string" ? { sandbox: checkSandbox(raw.sandbox) } : {},
2446
+ ...typeof raw.scrolling === "string" && raw.scrolling.toLowerCase() === "no" ? { scrolling: "no" } : {},
2447
+ size: checkSize(raw.size),
2448
+ ...ratio ? { ratio } : {}
2449
+ };
2450
+ }
2451
+ function checkSrc(value) {
2452
+ if (typeof value !== "string") return null;
2453
+ const src = value.trim();
2454
+ const url = SRC.test(src) && !src.includes("\\") ? parseUrl(src) : null;
2455
+ if (!url || REWRITTEN_PATH.test(url.path)) return null;
2456
+ const frame = {
2457
+ ...url,
2458
+ host: url.host.replace(/:\d+$/, ""),
2459
+ path: (url.path.toLowerCase().split(";")[0] ?? "").replaceAll("%2f", "/")
2460
+ };
2461
+ if (platforms.some((platform) => platform.ownsFrame?.(frame))) return null;
2462
+ return src.startsWith("//") ? `https:${src}` : src;
2463
+ }
2464
+ /** A feature keeps its origin list as written, or is dropped whole when one origin is not safe. */
2465
+ function checkAllow(value) {
2466
+ return value.split(";").map((directive) => directive.split(ASCII_WHITESPACE).filter(Boolean)).filter(([feature, ...origins]) => feature !== void 0 && FEATURES.has(feature) && origins.every((origin) => ORIGIN.test(origin))).map((tokens) => tokens.join(" ")).join("; ");
2467
+ }
2468
+ function checkSandbox(value) {
2469
+ const keywords = value.split(ASCII_WHITESPACE).map((token) => token.toLowerCase()).filter((token) => SANDBOX_KEYWORDS.has(token));
2470
+ return [...new Set(keywords)].join(" ");
2471
+ }
2472
+ function checkRatio(value) {
2473
+ if (typeof value !== "object" || value === null) return void 0;
2474
+ const { width, height } = value;
2475
+ return isPositive(width) && isPositive(height) ? {
2476
+ width,
2477
+ height
2478
+ } : void 0;
2479
+ }
2480
+ function isPositive(value) {
2481
+ return typeof value === "number" && Number.isFinite(value) && value > 0;
2482
+ }
2483
+ function checkSize(value) {
2484
+ if (typeof value !== "object" || value === null) return {};
2485
+ const { width, height } = value;
2486
+ const checkedWidth = typeof width === "number" ? pixels(String(width)) : void 0;
2487
+ const checkedHeight = typeof height === "number" ? pixels(String(height)) : void 0;
2488
+ return {
2489
+ ...checkedWidth === void 0 ? {} : { width: checkedWidth },
2490
+ ...checkedHeight === void 0 ? {} : { height: checkedHeight }
2491
+ };
2492
+ }
2493
+ function styleSize(iframe) {
2494
+ let width;
2495
+ let height;
2496
+ for (const declaration of (iframe.attrs.get("style") ?? "").split(";")) {
2497
+ const [, name = "", value = ""] = STYLE_SIZE.exec(declaration) ?? [];
2498
+ const px = pixels(PX.exec(value.trim())?.[1]);
2499
+ if (name.toLowerCase() === "width") width = px;
2500
+ if (name.toLowerCase() === "height") height = px;
2501
+ }
2502
+ return width === void 0 && height === void 0 ? void 0 : {
2503
+ width,
2504
+ height
2505
+ };
2506
+ }
1784
2507
  // src/parser/match-url.ts
1785
2508
  /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
1786
2509
  function matchUrl(url) {
@@ -1802,7 +2525,18 @@ function matchUrl(url) {
1802
2525
  function parseEmbed(html) {
1803
2526
  if (typeof html !== "string") return null;
1804
2527
  const nodes = parseHtml(html);
1805
- if (!nodes) return null;
2528
+ return nodes ? parseNodes(nodes) : parseRepaired(html);
2529
+ }
2530
+ function parseRepaired(html) {
2531
+ for (const platform of platforms) {
2532
+ const repaired = platform.repair?.(html);
2533
+ const nodes = repaired === void 0 || repaired === null ? null : parseHtml(repaired);
2534
+ const embed = nodes && parseNodes(nodes);
2535
+ if (embed?.platform === platform.platform) return embed;
2536
+ }
2537
+ return null;
2538
+ }
2539
+ function parseNodes(nodes) {
1806
2540
  let root;
1807
2541
  let extra;
1808
2542
  const scripts = [];
@@ -1848,4 +2582,4 @@ function parseEmbed(html) {
1848
2582
  function isFbRoot(element) {
1849
2583
  return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
1850
2584
  }
1851
- export { escapeAttribute as a, parseUrl as c, x as i, matchUrl as n, parseHtml as o, platforms as r, rebuild as s, parseEmbed as t };
2585
+ export { platforms as a, escapeAttribute as c, parseIframe as i, parseHtml as l, matchUrl as n, x as o, checkIframe as r, parseUrl as s, parseEmbed as t, rebuild as u };