social-embeds 0.2.0 → 0.3.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.
@@ -28,7 +28,6 @@ const NAMED_ENTITIES = /* @__PURE__ */ new Map([
28
28
  ["apos", "'"],
29
29
  ["nbsp", "\xA0"]
30
30
  ]);
31
- /** Parses an HTML fragment into a node list, or `null` if it is not well-formed. */
32
31
  function parseHtml(input) {
33
32
  const root = {
34
33
  type: "element",
@@ -124,7 +123,7 @@ function decodeEntities(value) {
124
123
  function hasClass(element, name) {
125
124
  return (element.attrs.get("class") ?? "").split(/\s+/).includes(name);
126
125
  }
127
- /** All descendant elements in document order. */
126
+ /** In document order. */
128
127
  function descendants(nodes) {
129
128
  const found = [];
130
129
  for (const node of nodes) {
@@ -136,9 +135,8 @@ function descendants(nodes) {
136
135
  const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "cite"]);
137
136
  const HTTP_URL = /^https?:\/\//i;
138
137
  /**
139
- * Rebuilds markup from whitelisted elements and attributes only. Elements not on the list
140
- * are dropped together with their content; `href` and `cite` must be http(s) URLs. Text is
141
- * copied as written: the tokenizer guarantees it contains no `<`, so it cannot open a tag.
138
+ * Security: the result reaches `dangerouslySetInnerHTML`. Elements off the list are dropped
139
+ * with their content, `href` and `cite` must be http(s) URLs, and text never holds a `<`.
142
140
  */
143
141
  function rebuild(nodes, whitelist) {
144
142
  let html = "";
@@ -169,7 +167,7 @@ function escapeAttribute(value) {
169
167
  }
170
168
  // src/parser/url.ts
171
169
  const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#\S*)?$/i;
172
- /** Splits an absolute or protocol-relative http(s) URL, or returns `null`. */
170
+ /** Absolute or protocol-relative http(s) URLs only. */
173
171
  function parseUrl(input) {
174
172
  const match = URL_PATTERN.exec(input.trim());
175
173
  if (!match) return null;
@@ -203,12 +201,11 @@ function coerce(value) {
203
201
  if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
204
202
  return value;
205
203
  }
206
- /** Positive integer pixel size from an attribute or query value. */
207
204
  function pixels(value) {
208
205
  return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
209
206
  }
210
207
  // src/parser/platform.ts
211
- /** Reads options from attributes; the first attribute present for a key wins. */
208
+ /** The first attribute present for a key wins. */
212
209
  function attributeOptions(element, mapping, coerceValue) {
213
210
  const options = {};
214
211
  for (const [attribute, key] of mapping) {
@@ -234,7 +231,7 @@ function withSize(embed, size) {
234
231
  } : embed;
235
232
  }
236
233
  // src/parser/platforms/facebook.ts
237
- const HOSTS$4 = /* @__PURE__ */ new Set([
234
+ const HOSTS$7 = /* @__PURE__ */ new Set([
238
235
  "facebook.com",
239
236
  "www.facebook.com",
240
237
  "m.facebook.com"
@@ -243,7 +240,7 @@ const PLUGIN_HOSTS = /* @__PURE__ */ new Set(["facebook.com", "www.facebook.com"
243
240
  const BASE = "https://www.facebook.com";
244
241
  const NAME = "[A-Za-z0-9.\\-]{1,80}";
245
242
  const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
246
- const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
243
+ const POSTS_PATH$1 = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
247
244
  const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
248
245
  const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
249
246
  const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
@@ -255,8 +252,8 @@ const PHOTO_PATHS = /* @__PURE__ */ new Set([
255
252
  ]);
256
253
  const STORY_ID = new RegExp(`^${POST_ID}$`);
257
254
  const NUMERIC_ID = /^\d{1,25}$/;
258
- const SCRIPT$4 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
259
- const OPTION_ATTRIBUTES$2 = [
255
+ const SCRIPT$8 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
256
+ const OPTION_ATTRIBUTES$5 = [
260
257
  ["data-width", "width"],
261
258
  ["data-show-text", "showText"],
262
259
  ["data-lazy", "lazy"],
@@ -281,9 +278,9 @@ const FALLBACK$3 = /* @__PURE__ */ new Map([
281
278
  ["p", []]
282
279
  ]);
283
280
  function target(url) {
284
- if (!url || !HOSTS$4.has(url.host)) return null;
281
+ if (!url || !HOSTS$7.has(url.host)) return null;
285
282
  const { path, query } = url;
286
- const [, name, postId] = POSTS_PATH.exec(path) ?? [];
283
+ const [, name, postId] = POSTS_PATH$1.exec(path) ?? [];
287
284
  if (name !== void 0 && postId !== void 0) return {
288
285
  kind: "post",
289
286
  id: postId,
@@ -357,7 +354,7 @@ const facebook = {
357
354
  const found = target(parseUrl(root.attrs.get("data-href") ?? ""));
358
355
  if (!kind || !found) return null;
359
356
  return {
360
- ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$2, coerce)),
357
+ ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$5, coerce)),
361
358
  fallbackHtml: rebuild(root.children, FALLBACK$3)
362
359
  };
363
360
  }
@@ -396,9 +393,9 @@ const facebook = {
396
393
  }
397
394
  return null;
398
395
  },
399
- isOwnScript: (src) => SCRIPT$4.test(src),
396
+ isOwnScript: (src) => SCRIPT$8.test(src),
400
397
  scriptOptions(src) {
401
- const [, locale] = SCRIPT$4.exec(src) ?? [];
398
+ const [, locale] = SCRIPT$8.exec(src) ?? [];
402
399
  return locale === void 0 ? {} : { locale };
403
400
  },
404
401
  allowsFbRoot: true,
@@ -408,8 +405,8 @@ const facebook = {
408
405
  }
409
406
  };
410
407
  // src/parser/platforms/instagram.ts
411
- const HOSTS$3 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
412
- const POST_PATH$1 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
408
+ const HOSTS$6 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
409
+ const POST_PATH$3 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
413
410
  const TYPES = /* @__PURE__ */ new Set([
414
411
  "p",
415
412
  "reel",
@@ -417,19 +414,15 @@ const TYPES = /* @__PURE__ */ new Set([
417
414
  "tv"
418
415
  ]);
419
416
  const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
420
- const SCRIPT$3 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
417
+ const SCRIPT$7 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
421
418
  const FALLBACK$2 = /* @__PURE__ */ new Map([
422
419
  ["div", []],
423
420
  ["a", ["href"]],
424
421
  ["p", []]
425
422
  ]);
426
- /**
427
- * embed.js serves only /p/, /reel/ and /tv/ permalinks; /reels/ and /{user}/… return 404
428
- * (docs/decisions.md D15), so the canonical URL drops the username and maps reels → reel.
429
- */
430
- function post$2(url) {
431
- if (!url || !HOSTS$3.has(url.host)) return null;
432
- const [, user, type, code] = POST_PATH$1.exec(url.path) ?? [];
423
+ function post$5(url) {
424
+ if (!url || !HOSTS$6.has(url.host)) return null;
425
+ const [, user, type, code] = POST_PATH$3.exec(url.path) ?? [];
433
426
  if (type === void 0 || code === void 0) return null;
434
427
  if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
435
428
  return {
@@ -446,7 +439,7 @@ const instagram = {
446
439
  parse(root) {
447
440
  if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
448
441
  const permalink = root.attrs.get("data-instgrm-permalink");
449
- const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$2(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$2(parseUrl(permalink));
442
+ 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));
450
443
  if (!found) return null;
451
444
  const options = {};
452
445
  if (root.attrs.has("data-instgrm-captioned")) options.captioned = true;
@@ -458,15 +451,310 @@ const instagram = {
458
451
  fallbackHtml: rebuild(root.children, FALLBACK$2)
459
452
  };
460
453
  },
461
- isOwnScript: (src) => SCRIPT$3.test(src),
454
+ isOwnScript: (src) => SCRIPT$7.test(src),
462
455
  match(url) {
463
- const found = post$2(url);
456
+ const found = post$5(url);
464
457
  return found && {
465
458
  ...found,
466
459
  options: {}
467
460
  };
468
461
  }
469
462
  };
463
+ // src/parser/platforms/linkedin.ts
464
+ const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
465
+ const URN = "(activity|share|ugcPost):(\\d{19})";
466
+ const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
467
+ const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
468
+ const EMBED_PATH$1 = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
469
+ function post$4(type, id, options = {}) {
470
+ const urn = `urn:li:${type}:${id}`;
471
+ return {
472
+ platform: "linkedin",
473
+ kind: "post",
474
+ url: `https://www.linkedin.com/feed/update/${urn}/`,
475
+ id: urn,
476
+ variant: "iframe",
477
+ options
478
+ };
479
+ }
480
+ const decodeColons = (path) => path.replace(/%3A/gi, ":");
481
+ const linkedin = {
482
+ platform: "linkedin",
483
+ parse(root) {
484
+ if (root.tag !== "iframe") return null;
485
+ const src = parseUrl(root.attrs.get("src") ?? "");
486
+ if (src?.host !== "www.linkedin.com") return null;
487
+ const [, type, id] = EMBED_PATH$1.exec(src.path) ?? [];
488
+ if (type === void 0 || id === void 0) return null;
489
+ return withSize(post$4(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
490
+ },
491
+ isOwnScript: () => false,
492
+ match(url) {
493
+ if (!HOST$1.test(url.host)) return null;
494
+ const path = decodeColons(url.path);
495
+ const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
496
+ return type === void 0 || id === void 0 ? null : post$4(type, id);
497
+ }
498
+ };
499
+ // src/parser/platforms/pinterest.ts
500
+ const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
501
+ const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
502
+ const PIN_ID = /^\d{1,25}$/;
503
+ const SCRIPT$6 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
504
+ const OPTION_ATTRIBUTES$4 = [
505
+ ["data-pin-width", "width"],
506
+ ["data-pin-lang", "lang"],
507
+ ["data-pin-terse", "terse"]
508
+ ];
509
+ function pin(id) {
510
+ return {
511
+ platform: "pinterest",
512
+ kind: "post",
513
+ url: `https://www.pinterest.com/pin/${id}/`,
514
+ id,
515
+ variant: "sdk"
516
+ };
517
+ }
518
+ function pinOf(url) {
519
+ if (!url || !HOST.test(url.host)) return null;
520
+ const [, id] = PIN_PATH.exec(url.path) ?? [];
521
+ return id === void 0 ? null : pin(id);
522
+ }
523
+ const pinterest = {
524
+ platform: "pinterest",
525
+ parse(root) {
526
+ if (root.tag === "a") {
527
+ if (root.attrs.get("data-pin-do") !== "embedPin") return null;
528
+ if (root.children.some((child) => child.type === "element")) return null;
529
+ const found = pinOf(parseUrl(root.attrs.get("href") ?? ""));
530
+ return found && {
531
+ ...found,
532
+ options: attributeOptions(root, OPTION_ATTRIBUTES$4, coerce)
533
+ };
534
+ }
535
+ if (root.tag !== "iframe") return null;
536
+ const src = parseUrl(root.attrs.get("src") ?? "");
537
+ if (src?.host !== "assets.pinterest.com" || src.path !== "/ext/embed.html") return null;
538
+ const id = src.query.get("id");
539
+ return id !== void 0 && PIN_ID.test(id) ? {
540
+ ...pin(id),
541
+ options: {}
542
+ } : null;
543
+ },
544
+ isOwnScript: (src) => SCRIPT$6.test(src),
545
+ match(url) {
546
+ const found = pinOf(url);
547
+ return found && {
548
+ ...found,
549
+ options: {}
550
+ };
551
+ }
552
+ };
553
+ // src/parser/platforms/reddit.ts
554
+ const HOSTS$5 = /* @__PURE__ */ new Set([
555
+ "reddit.com",
556
+ "www.reddit.com",
557
+ "old.reddit.com",
558
+ "new.reddit.com"
559
+ ]);
560
+ const POST_PATH$2 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
561
+ const SCRIPT$5 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
562
+ const OPTION_ATTRIBUTES$3 = [
563
+ "depth",
564
+ "style",
565
+ "theme",
566
+ "showmedia",
567
+ "showtitle",
568
+ "showedits",
569
+ "created",
570
+ "locale",
571
+ "showusername",
572
+ "snippet"
573
+ ].map((name) => [`data-embed-${name}`, name]);
574
+ function post$3(url) {
575
+ if (!url || !HOSTS$5.has(url.host)) return null;
576
+ const [, sub, postId, slug, commentId] = POST_PATH$2.exec(url.path) ?? [];
577
+ if (sub === void 0 || postId === void 0) return null;
578
+ const base = {
579
+ platform: "reddit",
580
+ kind: "post",
581
+ variant: "iframe"
582
+ };
583
+ const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
584
+ if (commentId === void 0) return {
585
+ ...base,
586
+ url: postUrl,
587
+ id: postId
588
+ };
589
+ if (slug === void 0) return null;
590
+ return {
591
+ ...base,
592
+ url: `${postUrl}comment/${commentId}/`,
593
+ id: commentId
594
+ };
595
+ }
596
+ const reddit = {
597
+ platform: "reddit",
598
+ parse(root) {
599
+ if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
600
+ const found = descendants(root.children).map((element) => element.tag === "a" ? post$3(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
601
+ if (!found) return null;
602
+ const height = pixels(root.attrs.get("data-embed-height"));
603
+ return withSize({
604
+ ...found,
605
+ options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
606
+ }, height === void 0 ? void 0 : { height });
607
+ },
608
+ isOwnScript: (src) => SCRIPT$5.test(src),
609
+ match(url) {
610
+ const found = post$3(url);
611
+ return found && {
612
+ ...found,
613
+ options: {}
614
+ };
615
+ }
616
+ };
617
+ // src/parser/platforms/snapchat.ts
618
+ const HOSTS$4 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
619
+ const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
620
+ const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
621
+ const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
622
+ const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
623
+ 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})$`);
624
+ const SCRIPT$4 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
625
+ function content(url) {
626
+ if (!url || !HOSTS$4.has(url.host)) return null;
627
+ const path = url.path.replace(/\/$/, "");
628
+ const base = {
629
+ platform: "snapchat",
630
+ variant: "iframe"
631
+ };
632
+ const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
633
+ if (spotlightId !== void 0) {
634
+ const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
635
+ return {
636
+ ...base,
637
+ kind: "video",
638
+ url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
639
+ id: spotlightId
640
+ };
641
+ }
642
+ const [, user] = PROFILE.exec(path) ?? [];
643
+ if (user !== void 0) return {
644
+ ...base,
645
+ kind: "post",
646
+ url: `https://www.snapchat.com/@${user}`,
647
+ id: user
648
+ };
649
+ const [, lens] = LENS.exec(path) ?? [];
650
+ if (lens !== void 0) return {
651
+ ...base,
652
+ kind: "post",
653
+ url: `https://www.snapchat.com/lens/${lens}`,
654
+ id: lens
655
+ };
656
+ const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
657
+ if (owner !== void 0 && highlight !== void 0) return {
658
+ ...base,
659
+ kind: "post",
660
+ url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
661
+ id: highlight
662
+ };
663
+ return null;
664
+ }
665
+ const snapchat = {
666
+ platform: "snapchat",
667
+ parse(root) {
668
+ if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
669
+ const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
670
+ if (!embedUrl?.path.endsWith("/embed")) return null;
671
+ const found = content({
672
+ ...embedUrl,
673
+ path: embedUrl.path.slice(0, -6)
674
+ });
675
+ if (!found) return null;
676
+ if (!descendants(root.children).filter((el) => el.tag === "a").every((link) => {
677
+ const linked = content(parseUrl(link.attrs.get("href") ?? ""));
678
+ return linked?.kind === found.kind && linked.id === found.id;
679
+ })) return null;
680
+ const title = root.attrs.get("data-snapchat-embed-title");
681
+ const width = pixels(root.attrs.get("data-snapchat-embed-width"));
682
+ const height = pixels(root.attrs.get("data-snapchat-embed-height"));
683
+ return withSize({
684
+ ...found,
685
+ options: title === void 0 ? {} : { title }
686
+ }, width === void 0 || height === void 0 ? void 0 : {
687
+ width,
688
+ height
689
+ });
690
+ },
691
+ isOwnScript: (src) => SCRIPT$4.test(src),
692
+ match(url) {
693
+ const found = content(url);
694
+ return found && {
695
+ ...found,
696
+ options: {}
697
+ };
698
+ }
699
+ };
700
+ // src/parser/platforms/telegram.ts
701
+ const HOSTS$3 = /* @__PURE__ */ new Set([
702
+ "t.me",
703
+ "telegram.me",
704
+ "www.telegram.me"
705
+ ]);
706
+ const CHANNEL = "[A-Za-z][A-Za-z0-9_]{2,31}";
707
+ const POST = new RegExp(`^(${CHANNEL})/(\\d{1,10})$`);
708
+ const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL})/(\\d{1,10})/?$`);
709
+ const SCRIPT$3 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
710
+ const OTHER_WIDGETS = [
711
+ "data-telegram-login",
712
+ "data-telegram-discussion",
713
+ "data-telegram-share-url"
714
+ ];
715
+ const OPTION_ATTRIBUTES$2 = [
716
+ ["data-width", "width"],
717
+ ["data-comment", "comment"],
718
+ ["data-userpic", "userpic"],
719
+ ["data-mode", "mode"],
720
+ ["data-color", "color"],
721
+ ["data-dark", "dark"],
722
+ ["data-dark-color", "darkColor"]
723
+ ];
724
+ function post$2(channel, id, options) {
725
+ return {
726
+ platform: "telegram",
727
+ kind: "post",
728
+ url: `https://t.me/${channel}/${id}`,
729
+ id: `${channel}/${id}`,
730
+ variant: "iframe",
731
+ options
732
+ };
733
+ }
734
+ const telegram = {
735
+ platform: "telegram",
736
+ parse: () => null,
737
+ parseScript(script) {
738
+ if (!SCRIPT$3.test(script.attrs.get("src") ?? "")) return null;
739
+ if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
740
+ const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
741
+ if (channel === void 0 || id === void 0) return null;
742
+ const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
743
+ if (script.attrs.has("data-single")) options.single = true;
744
+ return post$2(channel, id, options);
745
+ },
746
+ isOwnScript: (src) => SCRIPT$3.test(src),
747
+ match(url) {
748
+ if (!HOSTS$3.has(url.host)) return null;
749
+ const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
750
+ if (channel === void 0 || id === void 0) return null;
751
+ const options = {};
752
+ if (url.query.has("single")) options.single = true;
753
+ const comment = url.query.get("comment");
754
+ if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
755
+ return post$2(channel, id, options);
756
+ }
757
+ };
470
758
  // src/parser/platforms/threads.ts
471
759
  const HOSTS$2 = /* @__PURE__ */ new Set([
472
760
  "threads.com",
@@ -520,7 +808,6 @@ const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
520
808
  const PLAYER_PATH = /^\/player\/v1\/(\d{1,25})\/?$/;
521
809
  const VIDEO_ID$1 = /^\d{1,25}$/;
522
810
  const SCRIPT$1 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
523
- /** `user` is unknown for player iframe input; TikTok serves `/@/video/{id}` for that case. */
524
811
  function video$1(id, user = "", options = {}) {
525
812
  return {
526
813
  platform: "tiktok",
@@ -709,13 +996,15 @@ const platforms = [
709
996
  options: urlOptions(url, nocookie)
710
997
  };
711
998
  }
712
- }
999
+ },
1000
+ telegram,
1001
+ snapchat,
1002
+ linkedin,
1003
+ reddit,
1004
+ pinterest
713
1005
  ];
714
1006
  // src/parser/match-url.ts
715
- /**
716
- * Recognises a post URL. The result has no fallback content, and options only for data the
717
- * URL itself carries (docs/decisions.md D13). Never throws.
718
- */
1007
+ /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
719
1008
  function matchUrl(url) {
720
1009
  if (typeof url !== "string") return null;
721
1010
  const parsed = parseUrl(url);
@@ -728,10 +1017,8 @@ function matchUrl(url) {
728
1017
  }
729
1018
  // src/parser/parse-embed.ts
730
1019
  /**
731
- * Recognises a platform's own embed code. The input must consist of exactly one embed
732
- * element plus, optionally, the platform's own `<script src>` tags, Facebook's empty
733
- * `<div id="fb-root">`, whitespace and comments. Anything else returns `null`
734
- * (docs/decisions.md D14). Never throws.
1020
+ * Never throws. `null` unless the input is one embed element plus, at most, the platform's
1021
+ * own scripts, `<div id="fb-root">`, whitespace and comments (docs/decisions.md D14).
735
1022
  */
736
1023
  function parseEmbed(html) {
737
1024
  if (typeof html !== "string") return null;
@@ -751,7 +1038,16 @@ function parseEmbed(html) {
751
1038
  else if (root) return null;
752
1039
  else root = node;
753
1040
  }
754
- if (!root) return null;
1041
+ if (!root) {
1042
+ const [script] = scripts;
1043
+ if (fbRoot || scripts.length !== 1 || !script) return null;
1044
+ if (script.children.length !== 0) return null;
1045
+ for (const platform of platforms) {
1046
+ const embed = platform.parseScript?.(script);
1047
+ if (embed) return embed;
1048
+ }
1049
+ return null;
1050
+ }
755
1051
  for (const platform of platforms) {
756
1052
  const embed = platform.parse(root);
757
1053
  if (!embed) continue;
package/dist/parser.d.ts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as Platform, n as matchUrl, r as ParsedEmbed, t as parseEmbed } from "./index-CGSxjvGN.js";
1
+ import { i as Platform, n as matchUrl, r as ParsedEmbed, t as parseEmbed } from "./index-7CfJ3zQZ.js";
2
2
  export { type ParsedEmbed, type Platform, matchUrl, parseEmbed };
package/dist/parser.js CHANGED
@@ -1 +1 @@
1
- export { n as matchUrl, t as parseEmbed } from "./parser-B-_erpaf.js";
1
+ export { n as matchUrl, t as parseEmbed } from "./parser-HhmrfoYj.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "social-embeds",
3
- "version": "0.2.0",
3
+ "version": "0.3.0",
4
4
  "description": "Turn social media embed code or post URLs into working React components.",
5
5
  "license": "MIT",
6
6
  "author": "Atanas Mitrev",
@@ -40,17 +40,17 @@
40
40
  "@testing-library/react": "16.3.3",
41
41
  "@types/react": "19.3.0",
42
42
  "@types/react-dom": "19.3.0",
43
- "eslint": "10.14.0",
43
+ "eslint": "10.15.0",
44
44
  "eslint-plugin-react-hooks": "7.1.1",
45
45
  "happy-dom": "21.0.4",
46
- "prettier": "3.9.10",
46
+ "prettier": "3.10.1",
47
47
  "publint": "0.3.25",
48
48
  "react": "19.3.1",
49
49
  "react-dom": "19.3.1",
50
- "tsdown": "0.23.4",
50
+ "tsdown": "0.23.7",
51
51
  "typescript": "6.0.3",
52
- "typescript-eslint": "8.72.1",
53
- "vite": "8.3.5",
52
+ "typescript-eslint": "8.72.2",
53
+ "vite": "8.3.8",
54
54
  "vitest": "5.1.0"
55
55
  },
56
56
  "scripts": {