social-embeds 0.4.0 → 0.5.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 +116 -54
- package/dist/{index-CSSlJIJU.d.ts → index-BOBhkTW6.d.ts} +3 -2
- package/dist/index.d.ts +50 -3
- package/dist/index.js +316 -17
- package/dist/{parser-D7a5KPhN.js → parser-CJccut4h.js} +517 -72
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +32 -1
|
@@ -92,57 +92,80 @@ function unwrapRatio(root, pattern) {
|
|
|
92
92
|
function gcd(a, b) {
|
|
93
93
|
return b === 0 ? a : gcd(b, a % b);
|
|
94
94
|
}
|
|
95
|
-
// src/parser/platforms/
|
|
96
|
-
const
|
|
97
|
-
const
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
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;
|
|
101
105
|
return {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
variant: "iframe",
|
|
107
|
-
options
|
|
106
|
+
kind: "post",
|
|
107
|
+
url: `https://music.apple.com/${country}/${type}/${id}${song ? `?i=${song}` : ""}`,
|
|
108
|
+
id: song ?? id,
|
|
109
|
+
variant: "iframe"
|
|
108
110
|
};
|
|
109
111
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
return
|
|
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
|
+
};
|
|
127
133
|
}
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
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
|
+
};
|
|
131
151
|
}
|
|
132
|
-
const
|
|
133
|
-
platform: "
|
|
152
|
+
const applepodcasts = {
|
|
153
|
+
platform: "applepodcasts",
|
|
134
154
|
parse(root) {
|
|
135
|
-
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
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));
|
|
142
161
|
},
|
|
143
162
|
isOwnScript: () => false,
|
|
144
163
|
match(url) {
|
|
145
|
-
|
|
164
|
+
const found = content$2(url, "podcasts.apple.com");
|
|
165
|
+
return found && {
|
|
166
|
+
...found,
|
|
167
|
+
options: {}
|
|
168
|
+
};
|
|
146
169
|
}
|
|
147
170
|
};
|
|
148
171
|
// src/parser/html.ts
|
|
@@ -312,6 +335,120 @@ function rebuild(nodes, whitelist) {
|
|
|
312
335
|
function escapeAttribute(value) {
|
|
313
336
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
314
337
|
}
|
|
338
|
+
// src/parser/platforms/bluesky.ts
|
|
339
|
+
const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
|
|
340
|
+
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}/?$`);
|
|
343
|
+
const AT_URI = new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
|
|
344
|
+
const CID = /^[a-z2-7]{20,100}$/;
|
|
345
|
+
const COLOR_MODES = /* @__PURE__ */ new Set([
|
|
346
|
+
"light",
|
|
347
|
+
"dark",
|
|
348
|
+
"system"
|
|
349
|
+
]);
|
|
350
|
+
const SCRIPT$11 = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
|
|
351
|
+
const FALLBACK$4 = /* @__PURE__ */ new Map([
|
|
352
|
+
["p", ["lang"]],
|
|
353
|
+
["a", ["href"]],
|
|
354
|
+
["br", []]
|
|
355
|
+
]);
|
|
356
|
+
function post$6(did, rkey) {
|
|
357
|
+
return {
|
|
358
|
+
platform: "bluesky",
|
|
359
|
+
kind: "post",
|
|
360
|
+
url: `https://bsky.app/profile/${did}/post/${rkey}`,
|
|
361
|
+
id: `${did}/app.bsky.feed.post/${rkey}`,
|
|
362
|
+
variant: "iframe"
|
|
363
|
+
};
|
|
364
|
+
}
|
|
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);
|
|
369
|
+
}
|
|
370
|
+
const bluesky = {
|
|
371
|
+
platform: "bluesky",
|
|
372
|
+
fallback: FALLBACK$4,
|
|
373
|
+
parse(root) {
|
|
374
|
+
if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
|
|
375
|
+
const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
|
|
376
|
+
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;
|
|
379
|
+
const options = {};
|
|
380
|
+
const cid = root.attrs.get("data-bluesky-cid");
|
|
381
|
+
if (cid !== void 0 && CID.test(cid)) options.cid = cid;
|
|
382
|
+
const colorMode = root.attrs.get("data-bluesky-embed-color-mode");
|
|
383
|
+
if (colorMode !== void 0 && COLOR_MODES.has(colorMode)) options.colorMode = colorMode;
|
|
384
|
+
return {
|
|
385
|
+
...found,
|
|
386
|
+
options,
|
|
387
|
+
fallbackHtml: rebuild(root.children, FALLBACK$4)
|
|
388
|
+
};
|
|
389
|
+
},
|
|
390
|
+
isOwnScript: (src) => SCRIPT$11.test(src),
|
|
391
|
+
match(url) {
|
|
392
|
+
const found = fromUrl$1(url);
|
|
393
|
+
return found && {
|
|
394
|
+
...found,
|
|
395
|
+
options: {}
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
// src/parser/platforms/dailymotion.ts
|
|
400
|
+
const VIDEO_ID$2 = /^x[a-z0-9]{4,12}$/;
|
|
401
|
+
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) {
|
|
405
|
+
return {
|
|
406
|
+
platform: "dailymotion",
|
|
407
|
+
kind: "video",
|
|
408
|
+
url: `https://www.dailymotion.com/video/${id}`,
|
|
409
|
+
id,
|
|
410
|
+
variant: "iframe",
|
|
411
|
+
options
|
|
412
|
+
};
|
|
413
|
+
}
|
|
414
|
+
/** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
|
|
415
|
+
function fromPlayer$2(url) {
|
|
416
|
+
if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
|
|
417
|
+
const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
|
|
418
|
+
if (!match) return null;
|
|
419
|
+
const [, playerId] = match;
|
|
420
|
+
const id = url.query.get("video") ?? "";
|
|
421
|
+
if (!VIDEO_ID$2.test(id)) return null;
|
|
422
|
+
if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
|
|
423
|
+
const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
|
|
424
|
+
if (playerId !== void 0) options.playerId = playerId;
|
|
425
|
+
return video$3(id, options);
|
|
426
|
+
}
|
|
427
|
+
function fromPage$2(url) {
|
|
428
|
+
if (url.host === "dai.ly") {
|
|
429
|
+
const id = url.path.replace(/^\/|\/$/g, "");
|
|
430
|
+
return VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
|
|
431
|
+
}
|
|
432
|
+
if (!HOSTS$10.has(url.host)) return null;
|
|
433
|
+
const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
|
|
434
|
+
return id !== void 0 && VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
|
|
435
|
+
}
|
|
436
|
+
const dailymotion = {
|
|
437
|
+
platform: "dailymotion",
|
|
438
|
+
parse(root) {
|
|
439
|
+
const wrapped = unwrapRatio(root, WRAPPER$2);
|
|
440
|
+
const iframe = wrapped?.iframe ?? root;
|
|
441
|
+
if (iframe.tag !== "iframe") return null;
|
|
442
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
443
|
+
if (!src) return null;
|
|
444
|
+
const embed = fromPlayer$2(src) ?? fromPage$2(src);
|
|
445
|
+
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
446
|
+
},
|
|
447
|
+
isOwnScript: () => false,
|
|
448
|
+
match(url) {
|
|
449
|
+
return fromPlayer$2(url) ?? fromPage$2(url);
|
|
450
|
+
}
|
|
451
|
+
};
|
|
315
452
|
// src/parser/platforms/facebook.ts
|
|
316
453
|
const HOSTS$9 = /* @__PURE__ */ new Set([
|
|
317
454
|
"facebook.com",
|
|
@@ -320,11 +457,11 @@ const HOSTS$9 = /* @__PURE__ */ new Set([
|
|
|
320
457
|
]);
|
|
321
458
|
const PLUGIN_HOSTS = /* @__PURE__ */ new Set(["facebook.com", "www.facebook.com"]);
|
|
322
459
|
const BASE = "https://www.facebook.com";
|
|
323
|
-
const NAME = "[A-Za-z0-9.\\-]{1,80}";
|
|
460
|
+
const NAME$1 = "[A-Za-z0-9.\\-]{1,80}";
|
|
324
461
|
const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
|
|
325
|
-
const POSTS_PATH$1 = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
326
|
-
const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
|
|
327
|
-
const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
462
|
+
const POSTS_PATH$1 = new RegExp(`^/(${NAME$1})/posts/(${POST_ID})/?$`);
|
|
463
|
+
const PHOTOS_PATH = new RegExp(`^/(${NAME$1})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
|
|
464
|
+
const VIDEOS_PATH = new RegExp(`^/(${NAME$1})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
328
465
|
const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
|
|
329
466
|
const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
|
|
330
467
|
const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
@@ -334,7 +471,7 @@ const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
|
334
471
|
]);
|
|
335
472
|
const STORY_ID = new RegExp(`^${POST_ID}$`);
|
|
336
473
|
const NUMERIC_ID = /^\d{1,25}$/;
|
|
337
|
-
const SCRIPT$
|
|
474
|
+
const SCRIPT$10 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
|
|
338
475
|
const OPTION_ATTRIBUTES$5 = [
|
|
339
476
|
["data-width", "width"],
|
|
340
477
|
["data-show-text", "showText"],
|
|
@@ -475,9 +612,9 @@ const facebook = {
|
|
|
475
612
|
}
|
|
476
613
|
return null;
|
|
477
614
|
},
|
|
478
|
-
isOwnScript: (src) => SCRIPT$
|
|
615
|
+
isOwnScript: (src) => SCRIPT$10.test(src),
|
|
479
616
|
scriptOptions(src) {
|
|
480
|
-
const [, locale] = SCRIPT$
|
|
617
|
+
const [, locale] = SCRIPT$10.exec(src) ?? [];
|
|
481
618
|
return locale === void 0 ? {} : { locale };
|
|
482
619
|
},
|
|
483
620
|
allowsFbRoot: true,
|
|
@@ -486,6 +623,67 @@ const facebook = {
|
|
|
486
623
|
return found && embed(found, found.kind, "sdk", {});
|
|
487
624
|
}
|
|
488
625
|
};
|
|
626
|
+
// 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}/?$`);
|
|
631
|
+
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) {
|
|
635
|
+
return {
|
|
636
|
+
platform: "giphy",
|
|
637
|
+
kind: "video",
|
|
638
|
+
url: `https://giphy.com/gifs/${id}`,
|
|
639
|
+
id,
|
|
640
|
+
variant: "iframe"
|
|
641
|
+
};
|
|
642
|
+
}
|
|
643
|
+
function idOf(url) {
|
|
644
|
+
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];
|
|
646
|
+
if (MEDIA_HOST.test(url.host)) return MEDIA_PATH.exec(url.path)?.[1];
|
|
647
|
+
}
|
|
648
|
+
function fromIframe(iframe) {
|
|
649
|
+
if (iframe.tag !== "iframe") return null;
|
|
650
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
651
|
+
if (!src || !PAGE_HOSTS$2.has(src.host)) return null;
|
|
652
|
+
const [, id] = EMBED_PATH$2.exec(src.path) ?? [];
|
|
653
|
+
return id === void 0 ? null : gif(id);
|
|
654
|
+
}
|
|
655
|
+
function isCredit$1(element, embed) {
|
|
656
|
+
if (element.tag !== "p" || element.attrs.size !== 0) return false;
|
|
657
|
+
const [link, ...rest] = element.children;
|
|
658
|
+
if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return false;
|
|
659
|
+
if (link.attrs.size !== 1) return false;
|
|
660
|
+
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;
|
|
662
|
+
const [text, ...more] = link.children;
|
|
663
|
+
return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
|
|
664
|
+
}
|
|
665
|
+
const giphy = {
|
|
666
|
+
platform: "giphy",
|
|
667
|
+
parse(root) {
|
|
668
|
+
const wrapped = unwrapRatio(root, WRAPPER$1);
|
|
669
|
+
const iframe = wrapped?.iframe ?? root;
|
|
670
|
+
const found = fromIframe(iframe);
|
|
671
|
+
if (!found) return null;
|
|
672
|
+
return withSize({
|
|
673
|
+
...found,
|
|
674
|
+
options: {}
|
|
675
|
+
}, wrapped?.size ?? sizeOf(iframe));
|
|
676
|
+
},
|
|
677
|
+
isOwnScript: () => false,
|
|
678
|
+
isOwnExtra: isCredit$1,
|
|
679
|
+
match(url) {
|
|
680
|
+
const id = idOf(url);
|
|
681
|
+
return id === void 0 ? null : {
|
|
682
|
+
...gif(id),
|
|
683
|
+
options: {}
|
|
684
|
+
};
|
|
685
|
+
}
|
|
686
|
+
};
|
|
489
687
|
// src/parser/platforms/instagram.ts
|
|
490
688
|
const HOSTS$8 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
|
|
491
689
|
const POST_PATH$3 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
@@ -496,7 +694,7 @@ const TYPES = /* @__PURE__ */ new Set([
|
|
|
496
694
|
"tv"
|
|
497
695
|
]);
|
|
498
696
|
const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
|
|
499
|
-
const SCRIPT$
|
|
697
|
+
const SCRIPT$9 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
|
|
500
698
|
const FALLBACK$2 = /* @__PURE__ */ new Map([
|
|
501
699
|
["div", []],
|
|
502
700
|
["a", ["href"]],
|
|
@@ -533,7 +731,7 @@ const instagram = {
|
|
|
533
731
|
fallbackHtml: rebuild(root.children, FALLBACK$2)
|
|
534
732
|
};
|
|
535
733
|
},
|
|
536
|
-
isOwnScript: (src) => SCRIPT$
|
|
734
|
+
isOwnScript: (src) => SCRIPT$9.test(src),
|
|
537
735
|
match(url) {
|
|
538
736
|
const found = post$5(url);
|
|
539
737
|
return found && {
|
|
@@ -542,6 +740,60 @@ const instagram = {
|
|
|
542
740
|
};
|
|
543
741
|
}
|
|
544
742
|
};
|
|
743
|
+
// src/parser/platforms/kick.ts
|
|
744
|
+
const PAGE_HOSTS$1 = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
|
|
745
|
+
const CHANNEL$2 = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
|
|
746
|
+
const NOT_CHANNELS = /* @__PURE__ */ new Set([
|
|
747
|
+
"browse",
|
|
748
|
+
"categories",
|
|
749
|
+
"category",
|
|
750
|
+
"following",
|
|
751
|
+
"search",
|
|
752
|
+
"settings",
|
|
753
|
+
"dashboard",
|
|
754
|
+
"subscriptions",
|
|
755
|
+
"privacy-policy",
|
|
756
|
+
"terms-of-service",
|
|
757
|
+
"community-guidelines",
|
|
758
|
+
"help"
|
|
759
|
+
]);
|
|
760
|
+
const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
|
|
761
|
+
function channel$1(url, hosts) {
|
|
762
|
+
if (!url || !hosts.has(url.host)) return null;
|
|
763
|
+
const [, name] = CHANNEL$2.exec(url.path) ?? [];
|
|
764
|
+
if (name === void 0 || NOT_CHANNELS.has(name.toLowerCase())) return null;
|
|
765
|
+
const id = name.toLowerCase();
|
|
766
|
+
return {
|
|
767
|
+
platform: "kick",
|
|
768
|
+
kind: "video",
|
|
769
|
+
url: `https://kick.com/${id}`,
|
|
770
|
+
id,
|
|
771
|
+
variant: "iframe"
|
|
772
|
+
};
|
|
773
|
+
}
|
|
774
|
+
const PLAYER = /* @__PURE__ */ new Set(["player.kick.com"]);
|
|
775
|
+
const kick = {
|
|
776
|
+
platform: "kick",
|
|
777
|
+
parse(root) {
|
|
778
|
+
if (root.tag !== "iframe") return null;
|
|
779
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
780
|
+
const found = channel$1(src, PLAYER);
|
|
781
|
+
if (!found || !src) return null;
|
|
782
|
+
const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
|
|
783
|
+
return withSize({
|
|
784
|
+
...found,
|
|
785
|
+
options
|
|
786
|
+
}, sizeOf(root));
|
|
787
|
+
},
|
|
788
|
+
isOwnScript: () => false,
|
|
789
|
+
match(url) {
|
|
790
|
+
const found = channel$1(url, PAGE_HOSTS$1) ?? channel$1(url, PLAYER);
|
|
791
|
+
return found && {
|
|
792
|
+
...found,
|
|
793
|
+
options: {}
|
|
794
|
+
};
|
|
795
|
+
}
|
|
796
|
+
};
|
|
545
797
|
// src/parser/platforms/linkedin.ts
|
|
546
798
|
const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
|
|
547
799
|
const URN = "(activity|share|ugcPost):(\\d{19})";
|
|
@@ -582,7 +834,7 @@ const linkedin = {
|
|
|
582
834
|
const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
|
|
583
835
|
const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
|
|
584
836
|
const PIN_ID = /^\d{1,25}$/;
|
|
585
|
-
const SCRIPT$
|
|
837
|
+
const SCRIPT$8 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
|
|
586
838
|
const OPTION_ATTRIBUTES$4 = [
|
|
587
839
|
["data-pin-width", "width"],
|
|
588
840
|
["data-pin-lang", "lang"],
|
|
@@ -623,7 +875,7 @@ const pinterest = {
|
|
|
623
875
|
options: {}
|
|
624
876
|
} : null;
|
|
625
877
|
},
|
|
626
|
-
isOwnScript: (src) => SCRIPT$
|
|
878
|
+
isOwnScript: (src) => SCRIPT$8.test(src),
|
|
627
879
|
match(url) {
|
|
628
880
|
const found = pinOf(url);
|
|
629
881
|
return found && {
|
|
@@ -640,7 +892,7 @@ const HOSTS$7 = /* @__PURE__ */ new Set([
|
|
|
640
892
|
"new.reddit.com"
|
|
641
893
|
]);
|
|
642
894
|
const POST_PATH$2 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
|
|
643
|
-
const SCRIPT$
|
|
895
|
+
const SCRIPT$7 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
|
|
644
896
|
const OPTION_ATTRIBUTES$3 = [
|
|
645
897
|
"depth",
|
|
646
898
|
"style",
|
|
@@ -687,7 +939,7 @@ const reddit = {
|
|
|
687
939
|
options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
|
|
688
940
|
}, height === void 0 ? void 0 : { height });
|
|
689
941
|
},
|
|
690
|
-
isOwnScript: (src) => SCRIPT$
|
|
942
|
+
isOwnScript: (src) => SCRIPT$7.test(src),
|
|
691
943
|
match(url) {
|
|
692
944
|
const found = post$3(url);
|
|
693
945
|
return found && {
|
|
@@ -703,7 +955,7 @@ const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$
|
|
|
703
955
|
const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
|
|
704
956
|
const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
|
|
705
957
|
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})$`);
|
|
706
|
-
const SCRIPT$
|
|
958
|
+
const SCRIPT$6 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
|
|
707
959
|
function content$1(url) {
|
|
708
960
|
if (!url || !HOSTS$6.has(url.host)) return null;
|
|
709
961
|
const path = url.path.replace(/\/$/, "");
|
|
@@ -770,7 +1022,7 @@ const snapchat = {
|
|
|
770
1022
|
height
|
|
771
1023
|
});
|
|
772
1024
|
},
|
|
773
|
-
isOwnScript: (src) => SCRIPT$
|
|
1025
|
+
isOwnScript: (src) => SCRIPT$6.test(src),
|
|
774
1026
|
match(url) {
|
|
775
1027
|
const found = content$1(url);
|
|
776
1028
|
return found && {
|
|
@@ -779,6 +1031,121 @@ const snapchat = {
|
|
|
779
1031
|
};
|
|
780
1032
|
}
|
|
781
1033
|
};
|
|
1034
|
+
// src/parser/platforms/soundcloud.ts
|
|
1035
|
+
const PAGE_HOSTS = /* @__PURE__ */ new Set([
|
|
1036
|
+
"soundcloud.com",
|
|
1037
|
+
"www.soundcloud.com",
|
|
1038
|
+
"m.soundcloud.com"
|
|
1039
|
+
]);
|
|
1040
|
+
const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
|
|
1041
|
+
const NAME = "[a-z0-9_-]{1,64}";
|
|
1042
|
+
const SECRET = "s-[A-Za-z0-9]{1,32}";
|
|
1043
|
+
const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
|
|
1044
|
+
const NOT_USERS = /* @__PURE__ */ new Set([
|
|
1045
|
+
"discover",
|
|
1046
|
+
"search",
|
|
1047
|
+
"stream",
|
|
1048
|
+
"feed",
|
|
1049
|
+
"you",
|
|
1050
|
+
"upload",
|
|
1051
|
+
"charts",
|
|
1052
|
+
"pages",
|
|
1053
|
+
"settings",
|
|
1054
|
+
"messages",
|
|
1055
|
+
"notifications",
|
|
1056
|
+
"people",
|
|
1057
|
+
"stations",
|
|
1058
|
+
"library",
|
|
1059
|
+
"terms-of-use",
|
|
1060
|
+
"signin"
|
|
1061
|
+
]);
|
|
1062
|
+
const NOT_SOUNDS = /* @__PURE__ */ new Set([
|
|
1063
|
+
"likes",
|
|
1064
|
+
"tracks",
|
|
1065
|
+
"sets",
|
|
1066
|
+
"albums",
|
|
1067
|
+
"reposts",
|
|
1068
|
+
"popular-tracks",
|
|
1069
|
+
"followers",
|
|
1070
|
+
"following",
|
|
1071
|
+
"comments",
|
|
1072
|
+
"spotlight",
|
|
1073
|
+
"toptracks"
|
|
1074
|
+
]);
|
|
1075
|
+
const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
|
|
1076
|
+
function sound(url, id) {
|
|
1077
|
+
return {
|
|
1078
|
+
platform: "soundcloud",
|
|
1079
|
+
kind: "post",
|
|
1080
|
+
url,
|
|
1081
|
+
id,
|
|
1082
|
+
variant: "iframe"
|
|
1083
|
+
};
|
|
1084
|
+
}
|
|
1085
|
+
function fromApi(url) {
|
|
1086
|
+
if (url?.host !== "api.soundcloud.com") return null;
|
|
1087
|
+
const [, type, id] = API_PATH.exec(url.path) ?? [];
|
|
1088
|
+
if (type === void 0 || id === void 0) return null;
|
|
1089
|
+
const token = url.query.get("secret_token");
|
|
1090
|
+
if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
|
|
1091
|
+
const secret = token === void 0 ? "" : `?secret_token=${token}`;
|
|
1092
|
+
return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
|
|
1093
|
+
}
|
|
1094
|
+
function fromPage$1(url) {
|
|
1095
|
+
if (!PAGE_HOSTS.has(url.host)) return null;
|
|
1096
|
+
const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
|
|
1097
|
+
if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
|
|
1098
|
+
if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
|
|
1099
|
+
const path = [
|
|
1100
|
+
user,
|
|
1101
|
+
second,
|
|
1102
|
+
secret
|
|
1103
|
+
].filter(Boolean).join("/");
|
|
1104
|
+
return sound(`https://soundcloud.com/${path}`, path);
|
|
1105
|
+
}
|
|
1106
|
+
const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
|
|
1107
|
+
"href",
|
|
1108
|
+
"title",
|
|
1109
|
+
"target",
|
|
1110
|
+
"style"
|
|
1111
|
+
]);
|
|
1112
|
+
function isCreditLink(node) {
|
|
1113
|
+
if (node?.type !== "element" || node.tag !== "a") return false;
|
|
1114
|
+
if ([...node.attrs.keys()].some((name) => !LINK_ATTRIBUTES.has(name))) return false;
|
|
1115
|
+
const [text, ...rest] = node.children;
|
|
1116
|
+
return rest.length === 0 && text?.type === "text" && PAGE_HOSTS.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
|
|
1117
|
+
}
|
|
1118
|
+
/** Share code's credit: a styled `div` with the artist link, ` · `, and the sound link. */
|
|
1119
|
+
function isCredit(element) {
|
|
1120
|
+
if (element.tag !== "div" || element.attrs.size !== 1 || !element.attrs.has("style")) return false;
|
|
1121
|
+
const [artist, separator, sound, ...rest] = element.children;
|
|
1122
|
+
return rest.length === 0 && isCreditLink(artist) && separator?.type === "text" && /^\s*·\s*$/.test(separator.raw) && isCreditLink(sound);
|
|
1123
|
+
}
|
|
1124
|
+
const soundcloud = {
|
|
1125
|
+
platform: "soundcloud",
|
|
1126
|
+
parse(root) {
|
|
1127
|
+
if (root.tag !== "iframe") return null;
|
|
1128
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
1129
|
+
if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
|
|
1130
|
+
const found = fromApi(parseUrl(src.query.get("url") ?? ""));
|
|
1131
|
+
if (!found) return null;
|
|
1132
|
+
const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
|
|
1133
|
+
const { height } = sizeOf(root) ?? {};
|
|
1134
|
+
return withSize({
|
|
1135
|
+
...found,
|
|
1136
|
+
options
|
|
1137
|
+
}, height === void 0 ? void 0 : { height });
|
|
1138
|
+
},
|
|
1139
|
+
isOwnScript: () => false,
|
|
1140
|
+
isOwnExtra: isCredit,
|
|
1141
|
+
match(url) {
|
|
1142
|
+
const found = fromApi(url) ?? fromPage$1(url);
|
|
1143
|
+
return found && {
|
|
1144
|
+
...found,
|
|
1145
|
+
options: {}
|
|
1146
|
+
};
|
|
1147
|
+
}
|
|
1148
|
+
};
|
|
782
1149
|
// src/parser/platforms/spotify.ts
|
|
783
1150
|
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)?/?$`);
|
|
784
1151
|
const DROPPED$1 = /* @__PURE__ */ new Set(["utm_source", "si"]);
|
|
@@ -832,9 +1199,9 @@ const HOSTS$5 = /* @__PURE__ */ new Set([
|
|
|
832
1199
|
"www.telegram.me"
|
|
833
1200
|
]);
|
|
834
1201
|
const CHANNEL$1 = "[A-Za-z][A-Za-z0-9_]{2,31}";
|
|
835
|
-
const POST = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
|
|
1202
|
+
const POST$1 = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
|
|
836
1203
|
const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
|
|
837
|
-
const SCRIPT$
|
|
1204
|
+
const SCRIPT$5 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
|
|
838
1205
|
const OTHER_WIDGETS = [
|
|
839
1206
|
"data-telegram-login",
|
|
840
1207
|
"data-telegram-discussion",
|
|
@@ -863,15 +1230,15 @@ const telegram = {
|
|
|
863
1230
|
platform: "telegram",
|
|
864
1231
|
parse: () => null,
|
|
865
1232
|
parseScript(script) {
|
|
866
|
-
if (!SCRIPT$
|
|
1233
|
+
if (!SCRIPT$5.test(script.attrs.get("src") ?? "")) return null;
|
|
867
1234
|
if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
|
|
868
|
-
const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
|
|
1235
|
+
const [, channel, id] = POST$1.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
|
|
869
1236
|
if (channel === void 0 || id === void 0) return null;
|
|
870
1237
|
const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
|
|
871
1238
|
if (script.attrs.has("data-single")) options.single = true;
|
|
872
1239
|
return post$2(channel, id, options);
|
|
873
1240
|
},
|
|
874
|
-
isOwnScript: (src) => SCRIPT$
|
|
1241
|
+
isOwnScript: (src) => SCRIPT$5.test(src),
|
|
875
1242
|
match(url) {
|
|
876
1243
|
if (!HOSTS$5.has(url.host)) return null;
|
|
877
1244
|
const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
|
|
@@ -891,7 +1258,7 @@ const HOSTS$4 = /* @__PURE__ */ new Set([
|
|
|
891
1258
|
"www.threads.net"
|
|
892
1259
|
]);
|
|
893
1260
|
const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
894
|
-
const SCRIPT$
|
|
1261
|
+
const SCRIPT$4 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
|
|
895
1262
|
const OPTION_ATTRIBUTES$1 = [["data-theme", "theme"], ["data-text-post-version", "version"]];
|
|
896
1263
|
const FALLBACK$1 = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
|
|
897
1264
|
function post$1(url) {
|
|
@@ -921,7 +1288,7 @@ const threads = {
|
|
|
921
1288
|
fallbackHtml: rebuild(root.children, FALLBACK$1)
|
|
922
1289
|
};
|
|
923
1290
|
},
|
|
924
|
-
isOwnScript: (src) => SCRIPT$
|
|
1291
|
+
isOwnScript: (src) => SCRIPT$4.test(src),
|
|
925
1292
|
match(url) {
|
|
926
1293
|
const found = post$1(url);
|
|
927
1294
|
return found && {
|
|
@@ -935,7 +1302,7 @@ const HOSTS$3 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
|
|
|
935
1302
|
const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
|
|
936
1303
|
const PLAYER_PATH$1 = /^\/player\/v1\/(\d{1,25})\/?$/;
|
|
937
1304
|
const VIDEO_ID$1 = /^\d{1,25}$/;
|
|
938
|
-
const SCRIPT$
|
|
1305
|
+
const SCRIPT$3 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
|
|
939
1306
|
function video$2(id, user = "", options = {}) {
|
|
940
1307
|
return {
|
|
941
1308
|
platform: "tiktok",
|
|
@@ -965,13 +1332,79 @@ const tiktok = {
|
|
|
965
1332
|
if (id === void 0) return null;
|
|
966
1333
|
return withSize(video$2(id, "", Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
|
|
967
1334
|
},
|
|
968
|
-
isOwnScript: (src) => SCRIPT$
|
|
1335
|
+
isOwnScript: (src) => SCRIPT$3.test(src),
|
|
969
1336
|
match(url) {
|
|
970
1337
|
if (!HOSTS$3.has(url.host)) return null;
|
|
971
1338
|
const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
|
|
972
1339
|
return user === void 0 || id === void 0 ? null : video$2(id, user);
|
|
973
1340
|
}
|
|
974
1341
|
};
|
|
1342
|
+
// src/parser/platforms/tumblr.ts
|
|
1343
|
+
const BLOG = "([a-z0-9-]{1,32})";
|
|
1344
|
+
const POST = "(\\d{1,20})";
|
|
1345
|
+
const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
|
|
1346
|
+
const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
|
|
1347
|
+
const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
|
|
1348
|
+
const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
|
|
1349
|
+
const FRAME_PATH = new RegExp(`^/embed/post/(?:t:[A-Za-z0-9_-]{1,64}|${BLOG})/${POST}/v2$`);
|
|
1350
|
+
const NOT_BLOGS = /* @__PURE__ */ new Set([
|
|
1351
|
+
"dashboard",
|
|
1352
|
+
"explore",
|
|
1353
|
+
"tagged",
|
|
1354
|
+
"search",
|
|
1355
|
+
"settings",
|
|
1356
|
+
"blog",
|
|
1357
|
+
"www",
|
|
1358
|
+
"assets",
|
|
1359
|
+
"embed",
|
|
1360
|
+
"api",
|
|
1361
|
+
"help"
|
|
1362
|
+
]);
|
|
1363
|
+
const SCRIPT$2 = /^(?:https?:)?\/\/assets\.tumblr\.com\/post\.js(?:\?[^#]*)?$/;
|
|
1364
|
+
function fromUrl(url) {
|
|
1365
|
+
if (!url) return null;
|
|
1366
|
+
let blog;
|
|
1367
|
+
let id;
|
|
1368
|
+
if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
|
|
1369
|
+
else {
|
|
1370
|
+
[, blog] = BLOG_HOST.exec(url.host) ?? [];
|
|
1371
|
+
[, id] = BLOG_PATH.exec(url.path) ?? [];
|
|
1372
|
+
}
|
|
1373
|
+
if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
|
|
1374
|
+
return {
|
|
1375
|
+
platform: "tumblr",
|
|
1376
|
+
kind: "post",
|
|
1377
|
+
url: `https://www.tumblr.com/${blog}/${id}`,
|
|
1378
|
+
id,
|
|
1379
|
+
variant: "iframe"
|
|
1380
|
+
};
|
|
1381
|
+
}
|
|
1382
|
+
const tumblr = {
|
|
1383
|
+
platform: "tumblr",
|
|
1384
|
+
parse(root) {
|
|
1385
|
+
if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
|
|
1386
|
+
const frame = parseUrl(root.attrs.get("data-href") ?? "");
|
|
1387
|
+
if (frame?.host !== "embed.tumblr.com") return null;
|
|
1388
|
+
const [, , framePost] = FRAME_PATH.exec(frame.path) ?? [];
|
|
1389
|
+
if (framePost === void 0) return null;
|
|
1390
|
+
const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
|
|
1391
|
+
if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
|
|
1392
|
+
const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
|
|
1393
|
+
if (found?.id !== framePost) return null;
|
|
1394
|
+
return {
|
|
1395
|
+
...found,
|
|
1396
|
+
options: {}
|
|
1397
|
+
};
|
|
1398
|
+
},
|
|
1399
|
+
isOwnScript: (src) => SCRIPT$2.test(src),
|
|
1400
|
+
match(url) {
|
|
1401
|
+
const found = fromUrl(url);
|
|
1402
|
+
return found && {
|
|
1403
|
+
...found,
|
|
1404
|
+
options: {}
|
|
1405
|
+
};
|
|
1406
|
+
}
|
|
1407
|
+
};
|
|
975
1408
|
// src/parser/platforms/twitch.ts
|
|
976
1409
|
const HOSTS$2 = /* @__PURE__ */ new Set([
|
|
977
1410
|
"twitch.tv",
|
|
@@ -1327,7 +1760,14 @@ const platforms = [
|
|
|
1327
1760
|
spotify,
|
|
1328
1761
|
vimeo,
|
|
1329
1762
|
twitch,
|
|
1330
|
-
dailymotion
|
|
1763
|
+
dailymotion,
|
|
1764
|
+
soundcloud,
|
|
1765
|
+
applemusic,
|
|
1766
|
+
applepodcasts,
|
|
1767
|
+
kick,
|
|
1768
|
+
giphy,
|
|
1769
|
+
bluesky,
|
|
1770
|
+
tumblr
|
|
1331
1771
|
];
|
|
1332
1772
|
// src/parser/match-url.ts
|
|
1333
1773
|
/** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
|
|
@@ -1344,13 +1784,15 @@ function matchUrl(url) {
|
|
|
1344
1784
|
// src/parser/parse-embed.ts
|
|
1345
1785
|
/**
|
|
1346
1786
|
* Never throws. `null` unless the input is one embed element plus, at most, the platform's
|
|
1347
|
-
* own scripts, `<div id="fb-root">`,
|
|
1787
|
+
* own scripts, `<div id="fb-root">`, one platform-owned extra such as a credit, whitespace and
|
|
1788
|
+
* comments (docs/decisions.md D14).
|
|
1348
1789
|
*/
|
|
1349
1790
|
function parseEmbed(html) {
|
|
1350
1791
|
if (typeof html !== "string") return null;
|
|
1351
1792
|
const nodes = parseHtml(html);
|
|
1352
1793
|
if (!nodes) return null;
|
|
1353
1794
|
let root;
|
|
1795
|
+
let extra;
|
|
1354
1796
|
const scripts = [];
|
|
1355
1797
|
let fbRoot = false;
|
|
1356
1798
|
for (const node of nodes) {
|
|
@@ -1361,12 +1803,14 @@ function parseEmbed(html) {
|
|
|
1361
1803
|
}
|
|
1362
1804
|
if (node.tag === "script") scripts.push(node);
|
|
1363
1805
|
else if (isFbRoot(node)) fbRoot = true;
|
|
1364
|
-
else if (root)
|
|
1365
|
-
|
|
1806
|
+
else if (root) {
|
|
1807
|
+
if (extra) return null;
|
|
1808
|
+
extra = node;
|
|
1809
|
+
} else root = node;
|
|
1366
1810
|
}
|
|
1367
1811
|
if (!root) {
|
|
1368
1812
|
const [script] = scripts;
|
|
1369
|
-
if (fbRoot || scripts.length !== 1 || !script) return null;
|
|
1813
|
+
if (fbRoot || extra || scripts.length !== 1 || !script) return null;
|
|
1370
1814
|
if (script.children.length !== 0) return null;
|
|
1371
1815
|
for (const platform of platforms) {
|
|
1372
1816
|
const embed = platform.parseScript?.(script);
|
|
@@ -1378,6 +1822,7 @@ function parseEmbed(html) {
|
|
|
1378
1822
|
const embed = platform.parse(root);
|
|
1379
1823
|
if (!embed) continue;
|
|
1380
1824
|
if (fbRoot && !platform.allowsFbRoot) return null;
|
|
1825
|
+
if (extra && !platform.isOwnExtra?.(extra, embed)) return null;
|
|
1381
1826
|
const sources = scripts.map((script) => script.children.length === 0 ? script.attrs.get("src") : void 0);
|
|
1382
1827
|
if (!sources.every((src) => src !== void 0 && platform.isOwnScript(src))) return null;
|
|
1383
1828
|
const fromScripts = sources.map((src) => src === void 0 ? {} : platform.scriptOptions?.(src) ?? {});
|
|
@@ -1391,4 +1836,4 @@ function parseEmbed(html) {
|
|
|
1391
1836
|
function isFbRoot(element) {
|
|
1392
1837
|
return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
|
|
1393
1838
|
}
|
|
1394
|
-
export {
|
|
1839
|
+
export { DID as a, rebuild as c, x as i, parseUrl as l, matchUrl as n, escapeAttribute as o, platforms as r, parseHtml as s, parseEmbed as t };
|