social-embeds 0.4.1 → 0.5.1

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.
@@ -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/dailymotion.ts
96
- const VIDEO_ID$2 = /^x[a-z0-9]{4,12}$/;
97
- const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
98
- const WRAPPER$1 = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
99
- const HOSTS$10 = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
100
- function video$3(id, options) {
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
- platform: "dailymotion",
103
- kind: "video",
104
- url: `https://www.dailymotion.com/video/${id}`,
105
- id,
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
- /** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
111
- function fromPlayer$2(url) {
112
- if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
113
- const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
114
- if (!match) return null;
115
- const [, playerId] = match;
116
- const id = url.query.get("video") ?? "";
117
- if (!VIDEO_ID$2.test(id)) return null;
118
- if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
119
- const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
120
- if (playerId !== void 0) options.playerId = playerId;
121
- return video$3(id, options);
122
- }
123
- function fromPage$1(url) {
124
- if (url.host === "dai.ly") {
125
- const id = url.path.replace(/^\/|\/$/g, "");
126
- return VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
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
- if (!HOSTS$10.has(url.host)) return null;
129
- const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
130
- return id !== void 0 && VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
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 dailymotion = {
133
- platform: "dailymotion",
152
+ const applepodcasts = {
153
+ platform: "applepodcasts",
134
154
  parse(root) {
135
- const wrapped = unwrapRatio(root, WRAPPER$1);
136
- const iframe = wrapped?.iframe ?? root;
137
- if (iframe.tag !== "iframe") return null;
138
- const src = parseUrl(iframe.attrs.get("src") ?? "");
139
- if (!src) return null;
140
- const embed = fromPlayer$2(src) ?? fromPage$1(src);
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
- return fromPlayer$2(url) ?? fromPage$1(url);
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, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
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$9 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
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$9.test(src),
615
+ isOwnScript: (src) => SCRIPT$10.test(src),
479
616
  scriptOptions(src) {
480
- const [, locale] = SCRIPT$9.exec(src) ?? [];
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$8 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
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$8.test(src),
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,63 @@ 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
+ "clips",
751
+ "video",
752
+ "videos",
753
+ "following",
754
+ "search",
755
+ "settings",
756
+ "dashboard",
757
+ "subscriptions",
758
+ "privacy-policy",
759
+ "terms-of-service",
760
+ "community-guidelines",
761
+ "help"
762
+ ]);
763
+ const KEPT = /* @__PURE__ */ new Set(["autoplay", "muted"]);
764
+ function channel$1(url, hosts) {
765
+ if (!url || !hosts.has(url.host)) return null;
766
+ const [, name] = CHANNEL$2.exec(url.path) ?? [];
767
+ if (name === void 0 || NOT_CHANNELS.has(name.toLowerCase())) return null;
768
+ const id = name.toLowerCase();
769
+ return {
770
+ platform: "kick",
771
+ kind: "video",
772
+ url: `https://kick.com/${id}`,
773
+ id,
774
+ variant: "iframe"
775
+ };
776
+ }
777
+ const PLAYER = /* @__PURE__ */ new Set(["player.kick.com"]);
778
+ const kick = {
779
+ platform: "kick",
780
+ parse(root) {
781
+ if (root.tag !== "iframe") return null;
782
+ const src = parseUrl(root.attrs.get("src") ?? "");
783
+ const found = channel$1(src, PLAYER);
784
+ if (!found || !src) return null;
785
+ const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
786
+ return withSize({
787
+ ...found,
788
+ options
789
+ }, sizeOf(root));
790
+ },
791
+ isOwnScript: () => false,
792
+ match(url) {
793
+ const found = channel$1(url, PAGE_HOSTS$1) ?? channel$1(url, PLAYER);
794
+ return found && {
795
+ ...found,
796
+ options: {}
797
+ };
798
+ }
799
+ };
545
800
  // src/parser/platforms/linkedin.ts
546
801
  const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
547
802
  const URN = "(activity|share|ugcPost):(\\d{19})";
@@ -582,7 +837,7 @@ const linkedin = {
582
837
  const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
583
838
  const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
584
839
  const PIN_ID = /^\d{1,25}$/;
585
- const SCRIPT$7 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
840
+ const SCRIPT$8 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
586
841
  const OPTION_ATTRIBUTES$4 = [
587
842
  ["data-pin-width", "width"],
588
843
  ["data-pin-lang", "lang"],
@@ -623,7 +878,7 @@ const pinterest = {
623
878
  options: {}
624
879
  } : null;
625
880
  },
626
- isOwnScript: (src) => SCRIPT$7.test(src),
881
+ isOwnScript: (src) => SCRIPT$8.test(src),
627
882
  match(url) {
628
883
  const found = pinOf(url);
629
884
  return found && {
@@ -640,7 +895,7 @@ const HOSTS$7 = /* @__PURE__ */ new Set([
640
895
  "new.reddit.com"
641
896
  ]);
642
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}))?\/?$/;
643
- const SCRIPT$6 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
898
+ const SCRIPT$7 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
644
899
  const OPTION_ATTRIBUTES$3 = [
645
900
  "depth",
646
901
  "style",
@@ -687,7 +942,7 @@ const reddit = {
687
942
  options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
688
943
  }, height === void 0 ? void 0 : { height });
689
944
  },
690
- isOwnScript: (src) => SCRIPT$6.test(src),
945
+ isOwnScript: (src) => SCRIPT$7.test(src),
691
946
  match(url) {
692
947
  const found = post$3(url);
693
948
  return found && {
@@ -703,7 +958,7 @@ const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$
703
958
  const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
704
959
  const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
705
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})$`);
706
- const SCRIPT$5 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
961
+ const SCRIPT$6 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
707
962
  function content$1(url) {
708
963
  if (!url || !HOSTS$6.has(url.host)) return null;
709
964
  const path = url.path.replace(/\/$/, "");
@@ -770,7 +1025,7 @@ const snapchat = {
770
1025
  height
771
1026
  });
772
1027
  },
773
- isOwnScript: (src) => SCRIPT$5.test(src),
1028
+ isOwnScript: (src) => SCRIPT$6.test(src),
774
1029
  match(url) {
775
1030
  const found = content$1(url);
776
1031
  return found && {
@@ -779,6 +1034,129 @@ const snapchat = {
779
1034
  };
780
1035
  }
781
1036
  };
1037
+ // src/parser/platforms/soundcloud.ts
1038
+ const PAGE_HOSTS = /* @__PURE__ */ new Set([
1039
+ "soundcloud.com",
1040
+ "www.soundcloud.com",
1041
+ "m.soundcloud.com"
1042
+ ]);
1043
+ const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
1044
+ const NAME = "[a-z0-9_-]{1,64}";
1045
+ const SECRET = "s-[A-Za-z0-9]{1,32}";
1046
+ const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
1047
+ const NOT_USERS = /* @__PURE__ */ new Set([
1048
+ "discover",
1049
+ "search",
1050
+ "stream",
1051
+ "feed",
1052
+ "you",
1053
+ "upload",
1054
+ "charts",
1055
+ "pages",
1056
+ "settings",
1057
+ "messages",
1058
+ "notifications",
1059
+ "people",
1060
+ "stations",
1061
+ "library",
1062
+ "terms-of-use",
1063
+ "signin"
1064
+ ]);
1065
+ const NOT_SOUNDS = /* @__PURE__ */ new Set([
1066
+ "likes",
1067
+ "tracks",
1068
+ "sets",
1069
+ "albums",
1070
+ "reposts",
1071
+ "popular-tracks",
1072
+ "followers",
1073
+ "following",
1074
+ "comments",
1075
+ "spotlight",
1076
+ "toptracks"
1077
+ ]);
1078
+ const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
1079
+ function sound(url, id) {
1080
+ return {
1081
+ platform: "soundcloud",
1082
+ kind: "post",
1083
+ url,
1084
+ id,
1085
+ variant: "iframe"
1086
+ };
1087
+ }
1088
+ function fromApi(url) {
1089
+ if (url?.host !== "api.soundcloud.com") return null;
1090
+ const [, type, id] = API_PATH.exec(url.path) ?? [];
1091
+ if (type === void 0 || id === void 0) return null;
1092
+ const token = url.query.get("secret_token");
1093
+ if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
1094
+ const secret = token === void 0 ? "" : `?secret_token=${token}`;
1095
+ return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
1096
+ }
1097
+ function fromPage$1(url) {
1098
+ if (!PAGE_HOSTS.has(url.host)) return null;
1099
+ const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
1100
+ if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
1101
+ if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
1102
+ const path = [
1103
+ user,
1104
+ second,
1105
+ secret
1106
+ ].filter(Boolean).join("/");
1107
+ return sound(`https://soundcloud.com/${path}`, path);
1108
+ }
1109
+ const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
1110
+ "href",
1111
+ "title",
1112
+ "target",
1113
+ "style"
1114
+ ]);
1115
+ function isCreditLink(node) {
1116
+ if (node?.type !== "element" || node.tag !== "a") return false;
1117
+ if ([...node.attrs.keys()].some((name) => !LINK_ATTRIBUTES.has(name))) return false;
1118
+ const [text, ...rest] = node.children;
1119
+ return rest.length === 0 && text?.type === "text" && PAGE_HOSTS.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
1120
+ }
1121
+ /** Share code's credit: a styled `div` with the artist link, ` · `, and the sound link. */
1122
+ function isCredit(element) {
1123
+ if (element.tag !== "div" || element.attrs.size !== 1 || !element.attrs.has("style")) return false;
1124
+ const [artist, separator, sound, ...rest] = element.children;
1125
+ return rest.length === 0 && isCreditLink(artist) && separator?.type === "text" && /^\s*·\s*$/.test(separator.raw) && isCreditLink(sound);
1126
+ }
1127
+ const soundcloud = {
1128
+ platform: "soundcloud",
1129
+ parse(root) {
1130
+ if (root.tag !== "iframe") return null;
1131
+ const src = parseUrl(root.attrs.get("src") ?? "");
1132
+ if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
1133
+ let found = fromApi(parseUrl(src.query.get("url") ?? ""));
1134
+ if (!found) return null;
1135
+ const outer = src.query.get("secret_token");
1136
+ if (outer !== void 0) {
1137
+ if (!SECRET_TOKEN.test(outer)) return null;
1138
+ if (!found.url.includes("?")) found = {
1139
+ ...found,
1140
+ url: `${found.url}?secret_token=${outer}`
1141
+ };
1142
+ }
1143
+ const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
1144
+ const { height } = sizeOf(root) ?? {};
1145
+ return withSize({
1146
+ ...found,
1147
+ options
1148
+ }, height === void 0 ? void 0 : { height });
1149
+ },
1150
+ isOwnScript: () => false,
1151
+ isOwnExtra: isCredit,
1152
+ match(url) {
1153
+ const found = fromApi(url) ?? fromPage$1(url);
1154
+ return found && {
1155
+ ...found,
1156
+ options: {}
1157
+ };
1158
+ }
1159
+ };
782
1160
  // src/parser/platforms/spotify.ts
783
1161
  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
1162
  const DROPPED$1 = /* @__PURE__ */ new Set(["utm_source", "si"]);
@@ -832,9 +1210,9 @@ const HOSTS$5 = /* @__PURE__ */ new Set([
832
1210
  "www.telegram.me"
833
1211
  ]);
834
1212
  const CHANNEL$1 = "[A-Za-z][A-Za-z0-9_]{2,31}";
835
- const POST = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
1213
+ const POST$1 = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
836
1214
  const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
837
- const SCRIPT$4 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
1215
+ const SCRIPT$5 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
838
1216
  const OTHER_WIDGETS = [
839
1217
  "data-telegram-login",
840
1218
  "data-telegram-discussion",
@@ -863,15 +1241,15 @@ const telegram = {
863
1241
  platform: "telegram",
864
1242
  parse: () => null,
865
1243
  parseScript(script) {
866
- if (!SCRIPT$4.test(script.attrs.get("src") ?? "")) return null;
1244
+ if (!SCRIPT$5.test(script.attrs.get("src") ?? "")) return null;
867
1245
  if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
868
- const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
1246
+ const [, channel, id] = POST$1.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
869
1247
  if (channel === void 0 || id === void 0) return null;
870
1248
  const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
871
1249
  if (script.attrs.has("data-single")) options.single = true;
872
1250
  return post$2(channel, id, options);
873
1251
  },
874
- isOwnScript: (src) => SCRIPT$4.test(src),
1252
+ isOwnScript: (src) => SCRIPT$5.test(src),
875
1253
  match(url) {
876
1254
  if (!HOSTS$5.has(url.host)) return null;
877
1255
  const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
@@ -891,7 +1269,7 @@ const HOSTS$4 = /* @__PURE__ */ new Set([
891
1269
  "www.threads.net"
892
1270
  ]);
893
1271
  const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
894
- const SCRIPT$3 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
1272
+ const SCRIPT$4 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
895
1273
  const OPTION_ATTRIBUTES$1 = [["data-theme", "theme"], ["data-text-post-version", "version"]];
896
1274
  const FALLBACK$1 = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
897
1275
  function post$1(url) {
@@ -921,7 +1299,7 @@ const threads = {
921
1299
  fallbackHtml: rebuild(root.children, FALLBACK$1)
922
1300
  };
923
1301
  },
924
- isOwnScript: (src) => SCRIPT$3.test(src),
1302
+ isOwnScript: (src) => SCRIPT$4.test(src),
925
1303
  match(url) {
926
1304
  const found = post$1(url);
927
1305
  return found && {
@@ -935,7 +1313,7 @@ const HOSTS$3 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
935
1313
  const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
936
1314
  const PLAYER_PATH$1 = /^\/player\/v1\/(\d{1,25})\/?$/;
937
1315
  const VIDEO_ID$1 = /^\d{1,25}$/;
938
- const SCRIPT$2 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
1316
+ const SCRIPT$3 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
939
1317
  function video$2(id, user = "", options = {}) {
940
1318
  return {
941
1319
  platform: "tiktok",
@@ -965,13 +1343,80 @@ const tiktok = {
965
1343
  if (id === void 0) return null;
966
1344
  return withSize(video$2(id, "", Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
967
1345
  },
968
- isOwnScript: (src) => SCRIPT$2.test(src),
1346
+ isOwnScript: (src) => SCRIPT$3.test(src),
969
1347
  match(url) {
970
1348
  if (!HOSTS$3.has(url.host)) return null;
971
1349
  const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
972
1350
  return user === void 0 || id === void 0 ? null : video$2(id, user);
973
1351
  }
974
1352
  };
1353
+ // src/parser/platforms/tumblr.ts
1354
+ const BLOG = "([a-z0-9-]{1,32})";
1355
+ const POST = "(\\d{1,20})";
1356
+ const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
1357
+ const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
1358
+ const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
1359
+ const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
1360
+ const FRAME_PATH = new RegExp(`^/embed/post/(?:t:[A-Za-z0-9_-]{1,64}|${BLOG})/${POST}/v2$`);
1361
+ const NOT_BLOGS = /* @__PURE__ */ new Set([
1362
+ "dashboard",
1363
+ "explore",
1364
+ "tagged",
1365
+ "search",
1366
+ "settings",
1367
+ "blog",
1368
+ "www",
1369
+ "assets",
1370
+ "embed",
1371
+ "api",
1372
+ "help"
1373
+ ]);
1374
+ const SCRIPT$2 = /^(?:https?:)?\/\/assets\.tumblr\.com\/post\.js(?:\?[^#]*)?$/;
1375
+ function fromUrl(url) {
1376
+ if (!url) return null;
1377
+ let blog;
1378
+ let id;
1379
+ if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
1380
+ else {
1381
+ [, blog] = BLOG_HOST.exec(url.host) ?? [];
1382
+ [, id] = BLOG_PATH.exec(url.path) ?? [];
1383
+ }
1384
+ if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
1385
+ return {
1386
+ platform: "tumblr",
1387
+ kind: "post",
1388
+ url: `https://www.tumblr.com/${blog}/${id}`,
1389
+ id,
1390
+ variant: "iframe"
1391
+ };
1392
+ }
1393
+ const tumblr = {
1394
+ platform: "tumblr",
1395
+ parse(root) {
1396
+ if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
1397
+ const frame = parseUrl(root.attrs.get("data-href") ?? "");
1398
+ if (frame?.host !== "embed.tumblr.com") return null;
1399
+ const [, frameBlog, framePost] = FRAME_PATH.exec(frame.path) ?? [];
1400
+ if (framePost === void 0) return null;
1401
+ const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
1402
+ if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
1403
+ const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
1404
+ if (found?.id !== framePost) return null;
1405
+ if (frameBlog !== void 0 && found.url !== `https://www.tumblr.com/${frameBlog}/${framePost}`) return null;
1406
+ return {
1407
+ ...found,
1408
+ options: {}
1409
+ };
1410
+ },
1411
+ isOwnScript: (src) => SCRIPT$2.test(src),
1412
+ match(url) {
1413
+ const found = fromUrl(url);
1414
+ return found && {
1415
+ ...found,
1416
+ options: {}
1417
+ };
1418
+ }
1419
+ };
975
1420
  // src/parser/platforms/twitch.ts
976
1421
  const HOSTS$2 = /* @__PURE__ */ new Set([
977
1422
  "twitch.tv",
@@ -1327,7 +1772,14 @@ const platforms = [
1327
1772
  spotify,
1328
1773
  vimeo,
1329
1774
  twitch,
1330
- dailymotion
1775
+ dailymotion,
1776
+ soundcloud,
1777
+ applemusic,
1778
+ applepodcasts,
1779
+ kick,
1780
+ giphy,
1781
+ bluesky,
1782
+ tumblr
1331
1783
  ];
1332
1784
  // src/parser/match-url.ts
1333
1785
  /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
@@ -1344,13 +1796,15 @@ function matchUrl(url) {
1344
1796
  // src/parser/parse-embed.ts
1345
1797
  /**
1346
1798
  * Never throws. `null` unless the input is one embed element plus, at most, the platform's
1347
- * own scripts, `<div id="fb-root">`, whitespace and comments (docs/decisions.md D14).
1799
+ * own scripts, `<div id="fb-root">`, one platform-owned extra such as a credit, whitespace and
1800
+ * comments (docs/decisions.md D14).
1348
1801
  */
1349
1802
  function parseEmbed(html) {
1350
1803
  if (typeof html !== "string") return null;
1351
1804
  const nodes = parseHtml(html);
1352
1805
  if (!nodes) return null;
1353
1806
  let root;
1807
+ let extra;
1354
1808
  const scripts = [];
1355
1809
  let fbRoot = false;
1356
1810
  for (const node of nodes) {
@@ -1361,8 +1815,10 @@ function parseEmbed(html) {
1361
1815
  }
1362
1816
  if (node.tag === "script") scripts.push(node);
1363
1817
  else if (isFbRoot(node)) fbRoot = true;
1364
- else if (root) return null;
1365
- else root = node;
1818
+ else if (root) {
1819
+ if (extra) return null;
1820
+ extra = node;
1821
+ } else root = node;
1366
1822
  }
1367
1823
  if (!root) {
1368
1824
  const [script] = scripts;
@@ -1378,6 +1834,7 @@ function parseEmbed(html) {
1378
1834
  const embed = platform.parse(root);
1379
1835
  if (!embed) continue;
1380
1836
  if (fbRoot && !platform.allowsFbRoot) return null;
1837
+ if (extra && !platform.isOwnExtra?.(extra, embed)) return null;
1381
1838
  const sources = scripts.map((script) => script.children.length === 0 ? script.attrs.get("src") : void 0);
1382
1839
  if (!sources.every((src) => src !== void 0 && platform.isOwnScript(src))) return null;
1383
1840
  const fromScripts = sources.map((src) => src === void 0 ? {} : platform.scriptOptions?.(src) ?? {});
@@ -1391,4 +1848,4 @@ function parseEmbed(html) {
1391
1848
  function isFbRoot(element) {
1392
1849
  return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
1393
1850
  }
1394
- export { escapeAttribute as a, x as i, matchUrl as n, parseHtml as o, platforms as r, rebuild as s, parseEmbed as t };
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 };