social-embeds 0.9.2 → 0.9.3

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.
Files changed (90) hide show
  1. package/README.md +1 -1
  2. package/dist/components/apple-embed.js +4 -4
  3. package/dist/components/bluesky-embed.js +2 -2
  4. package/dist/components/dailymotion-embed.js +2 -2
  5. package/dist/components/facebook-embed.js +2 -2
  6. package/dist/components/flickr-embed.js +2 -2
  7. package/dist/components/giphy-embed.js +2 -2
  8. package/dist/components/imgur-embed.js +2 -2
  9. package/dist/components/instagram-embed.js +2 -2
  10. package/dist/components/kick-embed.js +2 -2
  11. package/dist/components/linkedin-embed.js +2 -2
  12. package/dist/components/pinterest-embed.js +2 -2
  13. package/dist/components/reddit-embed.js +2 -2
  14. package/dist/components/rumble-embed.js +2 -2
  15. package/dist/components/snapchat-embed.js +2 -2
  16. package/dist/components/soundcloud-embed.js +2 -2
  17. package/dist/components/spotify-embed.js +2 -2
  18. package/dist/components/strava-embed.js +2 -2
  19. package/dist/components/streamable-embed.js +2 -2
  20. package/dist/components/telegram-embed.js +2 -2
  21. package/dist/components/tenor-embed.js +2 -2
  22. package/dist/components/threads-embed.js +2 -2
  23. package/dist/components/tiktok-embed.js +2 -2
  24. package/dist/components/truthsocial-embed.js +2 -2
  25. package/dist/components/tumblr-embed.js +2 -2
  26. package/dist/components/twitch-embed.js +2 -2
  27. package/dist/components/vimeo-embed.js +2 -2
  28. package/dist/components/x-embed.js +2 -2
  29. package/dist/components/youtube-embed.js +2 -2
  30. package/dist/element.js +1 -1
  31. package/dist/parser/matchers/applemusic.js +33 -0
  32. package/dist/parser/matchers/applepodcasts.js +32 -0
  33. package/dist/parser/matchers/bluesky.js +41 -0
  34. package/dist/parser/matchers/dailymotion.js +47 -0
  35. package/dist/parser/matchers/facebook.js +118 -0
  36. package/dist/parser/matchers/flickr.js +100 -0
  37. package/dist/parser/matchers/giphy.js +38 -0
  38. package/dist/parser/matchers/imgur.js +76 -0
  39. package/dist/parser/matchers/instagram.js +43 -0
  40. package/dist/parser/matchers/kick.js +48 -0
  41. package/dist/parser/matchers/linkedin.js +31 -0
  42. package/dist/parser/matchers/pinterest.js +32 -0
  43. package/dist/parser/matchers/reddit.js +43 -0
  44. package/dist/parser/matchers/rumble.js +32 -0
  45. package/dist/parser/matchers/snapchat.js +60 -0
  46. package/dist/parser/matchers/soundcloud.js +87 -0
  47. package/dist/parser/matchers/spotify.js +39 -0
  48. package/dist/parser/matchers/strava.js +31 -0
  49. package/dist/parser/matchers/streamable.js +59 -0
  50. package/dist/parser/matchers/telegram.js +34 -0
  51. package/dist/parser/matchers/tenor.js +34 -0
  52. package/dist/parser/matchers/threads.js +36 -0
  53. package/dist/parser/matchers/tiktok.js +25 -0
  54. package/dist/parser/matchers/truthsocial.js +34 -0
  55. package/dist/parser/matchers/tumblr.js +51 -0
  56. package/dist/parser/matchers/twitch.js +90 -0
  57. package/dist/parser/matchers/vimeo.js +71 -0
  58. package/dist/parser/matchers/x.js +50 -0
  59. package/dist/parser/matchers/youtube.js +123 -0
  60. package/dist/parser/platform.d.ts +10 -4
  61. package/dist/parser/platforms/applemusic.js +4 -30
  62. package/dist/parser/platforms/applepodcasts.js +4 -29
  63. package/dist/parser/platforms/bluesky.js +4 -38
  64. package/dist/parser/platforms/dailymotion.js +4 -44
  65. package/dist/parser/platforms/facebook.js +5 -115
  66. package/dist/parser/platforms/flickr.js +5 -98
  67. package/dist/parser/platforms/giphy.js +4 -35
  68. package/dist/parser/platforms/imgur.js +4 -73
  69. package/dist/parser/platforms/instagram.js +4 -40
  70. package/dist/parser/platforms/kick.js +4 -45
  71. package/dist/parser/platforms/linkedin.js +4 -28
  72. package/dist/parser/platforms/pinterest.js +4 -29
  73. package/dist/parser/platforms/reddit.js +3 -40
  74. package/dist/parser/platforms/rumble.js +3 -29
  75. package/dist/parser/platforms/snapchat.js +3 -57
  76. package/dist/parser/platforms/soundcloud.js +4 -84
  77. package/dist/parser/platforms/spotify.js +4 -36
  78. package/dist/parser/platforms/strava.js +3 -28
  79. package/dist/parser/platforms/streamable.js +3 -56
  80. package/dist/parser/platforms/telegram.js +3 -31
  81. package/dist/parser/platforms/tenor.js +5 -32
  82. package/dist/parser/platforms/threads.js +4 -33
  83. package/dist/parser/platforms/tiktok.js +4 -22
  84. package/dist/parser/platforms/truthsocial.js +3 -31
  85. package/dist/parser/platforms/tumblr.js +3 -48
  86. package/dist/parser/platforms/twitch.js +4 -87
  87. package/dist/parser/platforms/vimeo.js +4 -68
  88. package/dist/parser/platforms/x.js +6 -46
  89. package/dist/parser/platforms/youtube.js +5 -120
  90. package/package.json +1 -1
@@ -1,29 +1,9 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
- import { coerce, parseUrl } from "../url.js";
3
- import { spotifyFrame } from "../frames.js";
2
+ import { parseUrl } from "../url.js";
3
+ import { content, options, spotifyMatcher } from "../matchers/spotify.js";
4
4
  // src/parser/platforms/spotify.ts
5
- 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)?/?$`);
6
- const DROPPED = /* @__PURE__ */ new Set(["utm_source", "si"]);
7
- function content(url) {
8
- if (url?.host !== "open.spotify.com") return null;
9
- const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
10
- if (type === void 0 || id === void 0) return null;
11
- return {
12
- platform: "spotify",
13
- kind: video ? "video" : "post",
14
- url: `https://open.spotify.com/${type}/${id}`,
15
- id,
16
- variant: "iframe",
17
- query: url.query
18
- };
19
- }
20
- function options(query) {
21
- return Object.fromEntries([...query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
22
- }
23
5
  const spotify = {
24
- platform: "spotify",
25
- name: "Spotify",
26
- shapes: ["post iframe", "video iframe"],
6
+ ...spotifyMatcher,
27
7
  parse(root) {
28
8
  if (root.tag !== "iframe") return null;
29
9
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -36,18 +16,6 @@ const spotify = {
36
16
  options: options(query)
37
17
  }, sizeOf(root));
38
18
  },
39
- isOwnScript: () => false,
40
- match(url) {
41
- const found = content(url);
42
- return found && {
43
- platform: found.platform,
44
- kind: "post",
45
- url: found.url,
46
- id: found.id,
47
- variant: found.variant,
48
- options: {}
49
- };
50
- },
51
- ownsFrame: spotifyFrame
19
+ isOwnScript: () => false
52
20
  };
53
21
  export { spotify };
@@ -1,31 +1,15 @@
1
1
  import { hasClass } from "../html.js";
2
+ import { item, stravaMatcher } from "../matchers/strava.js";
2
3
  // src/parser/platforms/strava.ts
3
- const HOSTS = /* @__PURE__ */ new Set(["strava.com", "www.strava.com"]);
4
4
  const NUMBER = /^\d{1,20}$/;
5
- const PAGE_PATH = /^\/(activities|routes)\/(\d{1,20})\/?$/;
6
5
  const SCRIPT = /^(?:https?:)?\/\/strava-embeds\.com\/embed\.js$/;
7
6
  const STYLES = /* @__PURE__ */ new Set(["standard", "minimal"]);
8
7
  const MAP_HASH = /^[A-Za-z0-9_-]{1,100}$/;
9
- const PAGES = {
10
- activity: "activities",
11
- route: "routes"
12
- };
13
- function item(type, number) {
14
- return {
15
- platform: "strava",
16
- kind: "post",
17
- url: `https://www.strava.com/${PAGES[type]}/${number}`,
18
- id: `${type}/${number}`,
19
- variant: "iframe"
20
- };
21
- }
22
8
  function isType(value) {
23
9
  return value === "activity" || value === "route";
24
10
  }
25
11
  const strava = {
26
- platform: "strava",
27
- name: "Strava",
28
- shapes: ["post iframe"],
12
+ ...stravaMatcher,
29
13
  parse(root) {
30
14
  if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
31
15
  if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
@@ -43,15 +27,6 @@ const strava = {
43
27
  options
44
28
  };
45
29
  },
46
- isOwnScript: (src) => SCRIPT.test(src),
47
- match(url) {
48
- if (!HOSTS.has(url.host)) return null;
49
- const [, page, number] = PAGE_PATH.exec(url.path) ?? [];
50
- if (page === void 0 || number === void 0) return null;
51
- return {
52
- ...item(page === "routes" ? "route" : "activity", number),
53
- options: {}
54
- };
55
- }
30
+ isOwnScript: (src) => SCRIPT.test(src)
56
31
  };
57
32
  export { strava };
@@ -1,33 +1,7 @@
1
1
  import { sizeOf, unwrapRatio, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
- import { streamableFrame } from "../frames.js";
3
+ import { PLAYER_PATH, streamableMatcher, validId, video } from "../matchers/streamable.js";
4
4
  // src/parser/platforms/streamable.ts
5
- const ID = "([a-z0-9]{4,8})";
6
- const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
7
- const PLAYER_PATH = new RegExp(`^/[eo]/${ID}$`);
8
- const PAGE_PATH = new RegExp(`^/${ID}/?$`);
9
- const NOT_VIDEOS = /* @__PURE__ */ new Set([
10
- "about",
11
- "login",
12
- "signup",
13
- "terms",
14
- "privacy",
15
- "pricing",
16
- "upload",
17
- "help",
18
- "apps",
19
- "blog",
20
- "jobs",
21
- "press",
22
- "tools",
23
- "embed",
24
- "plans",
25
- "contact",
26
- "support",
27
- "videos",
28
- "account",
29
- "profile"
30
- ]);
31
5
  const WRAPPER = /^width:\s*100%;\s*height:\s*0(?:px)?;\s*position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;?$/;
32
6
  const KEPT = /* @__PURE__ */ new Set([
33
7
  "loop",
@@ -37,18 +11,6 @@ const KEPT = /* @__PURE__ */ new Set([
37
11
  "muted"
38
12
  ]);
39
13
  const STRAY_END = /<\/div\s*>$/i;
40
- function video(id) {
41
- return {
42
- platform: "streamable",
43
- kind: "video",
44
- url: `https://streamable.com/${id}`,
45
- id,
46
- variant: "iframe"
47
- };
48
- }
49
- function validId(id) {
50
- return id !== void 0 && !NOT_VIDEOS.has(id);
51
- }
52
14
  function fromIframe(iframe) {
53
15
  if (iframe.tag !== "iframe") return null;
54
16
  const src = parseUrl(iframe.attrs.get("src") ?? "");
@@ -61,15 +23,8 @@ function fromIframe(iframe) {
61
23
  options
62
24
  };
63
25
  }
64
- function idOf(url) {
65
- if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
66
- const id = (PLAYER_PATH.exec(url.path) ?? PAGE_PATH.exec(url.path))?.[1];
67
- return validId(id) ? id : void 0;
68
- }
69
26
  const streamable = {
70
- platform: "streamable",
71
- name: "Streamable",
72
- shapes: ["video iframe"],
27
+ ...streamableMatcher,
73
28
  parse(root) {
74
29
  const wrapped = unwrapRatio(root, WRAPPER);
75
30
  const iframe = wrapped?.iframe ?? root;
@@ -84,14 +39,6 @@ const streamable = {
84
39
  if (!end) return null;
85
40
  const trimmed = code.slice(0, end.index).trimEnd();
86
41
  return /^\s*<iframe[\s>]/i.test(trimmed) ? trimmed : null;
87
- },
88
- match(url) {
89
- const id = idOf(url);
90
- return id === void 0 ? null : {
91
- ...video(id),
92
- options: {}
93
- };
94
- },
95
- ownsFrame: streamableFrame
42
+ }
96
43
  };
97
44
  export { streamable };
@@ -1,14 +1,8 @@
1
1
  import { attributeOptions } from "../platform.js";
2
2
  import { coerce } from "../url.js";
3
+ import { CHANNEL, post, telegramMatcher } from "../matchers/telegram.js";
3
4
  // src/parser/platforms/telegram.ts
4
- const HOSTS = /* @__PURE__ */ new Set([
5
- "t.me",
6
- "telegram.me",
7
- "www.telegram.me"
8
- ]);
9
- const CHANNEL = "[A-Za-z][A-Za-z0-9_]{2,31}";
10
5
  const POST = new RegExp(`^(${CHANNEL})/(\\d{1,10})$`);
11
- const POST_PATH = new RegExp(`^/(?:s/)?(${CHANNEL})/(\\d{1,10})/?$`);
12
6
  const SCRIPT = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
13
7
  const OTHER_WIDGETS = [
14
8
  "data-telegram-login",
@@ -24,20 +18,8 @@ const OPTION_ATTRIBUTES = [
24
18
  ["data-dark", "dark"],
25
19
  ["data-dark-color", "darkColor"]
26
20
  ];
27
- function post(channel, id, options) {
28
- return {
29
- platform: "telegram",
30
- kind: "post",
31
- url: `https://t.me/${channel}/${id}`,
32
- id: `${channel}/${id}`,
33
- variant: "iframe",
34
- options
35
- };
36
- }
37
21
  const telegram = {
38
- platform: "telegram",
39
- name: "Telegram",
40
- shapes: ["post iframe"],
22
+ ...telegramMatcher,
41
23
  parse: () => null,
42
24
  parseScript(script) {
43
25
  if (!SCRIPT.test(script.attrs.get("src") ?? "")) return null;
@@ -48,16 +30,6 @@ const telegram = {
48
30
  if (script.attrs.has("data-single")) options.single = true;
49
31
  return post(channel, id, options);
50
32
  },
51
- isOwnScript: (src) => SCRIPT.test(src),
52
- match(url) {
53
- if (!HOSTS.has(url.host)) return null;
54
- const [, channel, id] = POST_PATH.exec(url.path) ?? [];
55
- if (channel === void 0 || id === void 0) return null;
56
- const options = {};
57
- if (url.query.has("single")) options.single = true;
58
- const comment = url.query.get("comment");
59
- if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
60
- return post(channel, id, options);
61
- }
33
+ isOwnScript: (src) => SCRIPT.test(src)
62
34
  };
63
35
  export { telegram };
@@ -1,28 +1,12 @@
1
- import { hasClass, rebuild, rebuildsAs } from "../html.js";
1
+ import { hasClass, rebuild } from "../html.js";
2
2
  import { sizeOf, withSize } from "../platform.js";
3
3
  import { parseUrl } from "../url.js";
4
- import { tenorFrame } from "../frames.js";
4
+ import { FALLBACK, ID, gif, tenorMatcher } from "../matchers/tenor.js";
5
5
  // src/parser/platforms/tenor.ts
6
- const HOSTS = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
7
- const ID = "(\\d{1,20})";
8
- const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID}/?$`);
9
6
  const FRAME_PATH = new RegExp(`^/embed/${ID}$`);
10
7
  const SCRIPT = /^(?:https?:)?\/\/tenor\.com\/embed\.js$/;
11
8
  const RATIO = /^\d{1,3}(?:\.\d{1,20})?$/;
12
9
  const DEFAULT_RATIO = 1.33;
13
- const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]]]);
14
- function gif(id) {
15
- return {
16
- platform: "tenor",
17
- kind: "video",
18
- url: `https://tenor.com/view/${id}`,
19
- id,
20
- variant: "iframe"
21
- };
22
- }
23
- function idOf(url) {
24
- return url && HOSTS.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
25
- }
26
10
  /** To four decimals, from 1:100 to 100:1. */
27
11
  function ratioSize(ratio) {
28
12
  const width = Math.round(ratio * 1e4);
@@ -39,7 +23,7 @@ function gcd(a, b) {
39
23
  function fromDiv(root) {
40
24
  if (!hasClass(root, "tenor-gif-embed")) return null;
41
25
  const id = root.attrs.get("data-postid") ?? "";
42
- if (!new RegExp(`^${ID}$`).test(id)) return null;
26
+ if (!new RegExp(`^(\\d{1,20})$`).test(id)) return null;
43
27
  const given = root.attrs.get("data-aspect-ratio");
44
28
  if (given !== void 0 && !RATIO.test(given)) return null;
45
29
  const size = ratioSize(given === void 0 ? DEFAULT_RATIO : Number(given));
@@ -60,22 +44,11 @@ function fromIframe(root) {
60
44
  }, sizeOf(root));
61
45
  }
62
46
  const tenor = {
63
- platform: "tenor",
64
- name: "Tenor",
65
- shapes: ["video iframe"],
66
- trustsFallback: (html) => rebuildsAs(html, FALLBACK),
47
+ ...tenorMatcher,
67
48
  parse(root) {
68
49
  if (root.tag === "div") return fromDiv(root);
69
50
  return root.tag === "iframe" ? fromIframe(root) : null;
70
51
  },
71
- isOwnScript: (src) => SCRIPT.test(src),
72
- match(url) {
73
- const id = idOf(url);
74
- return id === void 0 ? null : {
75
- ...gif(id),
76
- options: {}
77
- };
78
- },
79
- ownsFrame: tenorFrame
52
+ isOwnScript: (src) => SCRIPT.test(src)
80
53
  };
81
54
  export { tenor };
@@ -1,34 +1,12 @@
1
- import { hasClass, rebuild, rebuildsAs } from "../html.js";
1
+ import { hasClass, rebuild } from "../html.js";
2
2
  import { attributeOptions } from "../platform.js";
3
3
  import { coerce, parseUrl } from "../url.js";
4
+ import { FALLBACK, post, threadsMatcher } from "../matchers/threads.js";
4
5
  // src/parser/platforms/threads.ts
5
- const HOSTS = /* @__PURE__ */ new Set([
6
- "threads.com",
7
- "www.threads.com",
8
- "threads.net",
9
- "www.threads.net"
10
- ]);
11
- const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
12
6
  const SCRIPT = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
13
7
  const OPTION_ATTRIBUTES = [["data-theme", "theme"], ["data-text-post-version", "version"]];
14
- const FALLBACK = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
15
- function post(url) {
16
- if (!url || !HOSTS.has(url.host)) return null;
17
- const [, code] = POST_PATH.exec(url.path) ?? [];
18
- if (code === void 0) return null;
19
- return {
20
- platform: "threads",
21
- kind: "post",
22
- url: `https://www.threads.com/t/${code}`,
23
- id: code,
24
- variant: "sdk"
25
- };
26
- }
27
8
  const threads = {
28
- platform: "threads",
29
- name: "Threads",
30
- shapes: ["post sdk"],
31
- trustsFallback: (html) => rebuildsAs(html, FALLBACK),
9
+ ...threadsMatcher,
32
10
  parse(root) {
33
11
  if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
34
12
  const found = post(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
@@ -41,13 +19,6 @@ const threads = {
41
19
  fallbackHtml: rebuild(root.children, FALLBACK)
42
20
  };
43
21
  },
44
- isOwnScript: (src) => SCRIPT.test(src),
45
- match(url) {
46
- const found = post(url);
47
- return found && {
48
- ...found,
49
- options: {}
50
- };
51
- }
22
+ isOwnScript: (src) => SCRIPT.test(src)
52
23
  };
53
24
  export { threads };
@@ -1,26 +1,14 @@
1
1
  import { hasClass } from "../html.js";
2
2
  import { sizeOf, withSize } from "../platform.js";
3
3
  import { coerce, parseUrl } from "../url.js";
4
- import { TIKTOK_HOSTS, tiktokFrame } from "../frames.js";
4
+ import { TIKTOK_HOSTS } from "../frames.js";
5
+ import { VIDEO_PATH, tiktokMatcher, video } from "../matchers/tiktok.js";
5
6
  // src/parser/platforms/tiktok.ts
6
- const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
7
7
  const PLAYER_PATH = /^\/player\/v1\/(\d{1,25})\/?$/;
8
8
  const VIDEO_ID = /^\d{1,25}$/;
9
9
  const SCRIPT = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
10
- function video(id, user = "", options = {}) {
11
- return {
12
- platform: "tiktok",
13
- kind: "video",
14
- url: `https://www.tiktok.com/@${user}/video/${id}`,
15
- id,
16
- variant: "iframe",
17
- options
18
- };
19
- }
20
10
  const tiktok = {
21
- platform: "tiktok",
22
- name: "TikTok",
23
- shapes: ["video iframe"],
11
+ ...tiktokMatcher,
24
12
  parse(root) {
25
13
  if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
26
14
  const cite = parseUrl(root.attrs.get("cite") ?? "");
@@ -39,12 +27,6 @@ const tiktok = {
39
27
  const options = Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]));
40
28
  return withSize(video(id, "", options), sizeOf(root));
41
29
  },
42
- isOwnScript: (src) => SCRIPT.test(src),
43
- match(url) {
44
- if (!TIKTOK_HOSTS.has(url.host)) return null;
45
- const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
46
- return user === void 0 || id === void 0 ? null : video(id, user);
47
- },
48
- ownsFrame: tiktokFrame
30
+ isOwnScript: (src) => SCRIPT.test(src)
49
31
  };
50
32
  export { tiktok };
@@ -1,32 +1,12 @@
1
1
  import { hasClass } from "../html.js";
2
2
  import { sizeOf, withSize } from "../platform.js";
3
3
  import { parseUrl } from "../url.js";
4
- import { truthsocialFrame } from "../frames.js";
4
+ import { ID, USER, post, truthsocialMatcher } from "../matchers/truthsocial.js";
5
5
  // src/parser/platforms/truthsocial.ts
6
- const HOSTS = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
7
- const USER = "(@[A-Za-z0-9_.-]{1,64})";
8
- const ID = "(\\d{1,25})";
9
- const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
10
6
  const FRAME_PATH = new RegExp(`^/${USER}/${ID}/embed$`);
11
7
  const SCRIPT = /^(?:https?:)?\/\/truthsocial\.com\/embed\.js$/;
12
- function post(user, id) {
13
- return {
14
- platform: "truthsocial",
15
- kind: "post",
16
- url: `https://truthsocial.com/${user}/posts/${id}`,
17
- id,
18
- variant: "iframe"
19
- };
20
- }
21
- function fromUrl(url) {
22
- if (!url || !HOSTS.has(url.host)) return null;
23
- const [, user, id] = POST_PATH.exec(url.path) ?? [];
24
- return user === void 0 || id === void 0 ? null : post(user, id);
25
- }
26
8
  const truthsocial = {
27
- platform: "truthsocial",
28
- name: "Truth Social",
29
- shapes: ["post iframe"],
9
+ ...truthsocialMatcher,
30
10
  parse(root) {
31
11
  if (root.tag !== "iframe") return null;
32
12
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -39,14 +19,6 @@ const truthsocial = {
39
19
  options
40
20
  }, sizeOf(root));
41
21
  },
42
- isOwnScript: (src) => SCRIPT.test(src),
43
- match(url) {
44
- const found = fromUrl(url);
45
- return found && {
46
- ...found,
47
- options: {}
48
- };
49
- },
50
- ownsFrame: truthsocialFrame
22
+ isOwnScript: (src) => SCRIPT.test(src)
51
23
  };
52
24
  export { truthsocial };
@@ -1,50 +1,12 @@
1
1
  import { hasClass } from "../html.js";
2
2
  import { parseUrl } from "../url.js";
3
+ import { BLOG, POST, fromUrl, tumblrMatcher } from "../matchers/tumblr.js";
3
4
  // src/parser/platforms/tumblr.ts
4
- const BLOG = "([a-z0-9-]{1,32})";
5
- const POST = "(\\d{1,20})";
6
- const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
7
- const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
8
- const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
9
- const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
10
5
  const FRAME_PATH = new RegExp(`^/embed/post/(?:t:[A-Za-z0-9_-]{1,64}|${BLOG})/${POST}/v2$`);
11
6
  const OLD_FRAME_PATH = new RegExp(`^/embed/post/(?:t:)?[A-Za-z0-9_-]{1,64}/${POST}$`);
12
- const NOT_BLOGS = /* @__PURE__ */ new Set([
13
- "dashboard",
14
- "explore",
15
- "tagged",
16
- "search",
17
- "settings",
18
- "blog",
19
- "www",
20
- "assets",
21
- "embed",
22
- "api",
23
- "help"
24
- ]);
25
7
  const SCRIPT = /^(?:https?:)?\/\/(?:secure\.)?assets\.tumblr\.com\/post\.js(?:\?[^#]*)?$/;
26
- function fromUrl(url) {
27
- if (!url) return null;
28
- let blog;
29
- let id;
30
- if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
31
- else {
32
- [, blog] = BLOG_HOST.exec(url.host) ?? [];
33
- [, id] = BLOG_PATH.exec(url.path) ?? [];
34
- }
35
- if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
36
- return {
37
- platform: "tumblr",
38
- kind: "post",
39
- url: `https://www.tumblr.com/${blog}/${id}`,
40
- id,
41
- variant: "iframe"
42
- };
43
- }
44
8
  const tumblr = {
45
- platform: "tumblr",
46
- name: "Tumblr",
47
- shapes: ["post iframe"],
9
+ ...tumblrMatcher,
48
10
  parse(root) {
49
11
  if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
50
12
  const frame = parseUrl(root.attrs.get("data-href") ?? "");
@@ -62,13 +24,6 @@ const tumblr = {
62
24
  options: {}
63
25
  };
64
26
  },
65
- isOwnScript: (src) => SCRIPT.test(src),
66
- match(url) {
67
- const found = fromUrl(url);
68
- return found && {
69
- ...found,
70
- options: {}
71
- };
72
- }
27
+ isOwnScript: (src) => SCRIPT.test(src)
73
28
  };
74
29
  export { tumblr };
@@ -1,52 +1,13 @@
1
1
  import { sizeOf, withSize } from "../platform.js";
2
2
  import { coerce, parseUrl } from "../url.js";
3
- import { twitchFrame } from "../frames.js";
3
+ import "../frames.js";
4
+ import { CHANNEL, CLIP, COLLECTION, VIDEO, channel, clip, collection, twitchMatcher, vod } from "../matchers/twitch.js";
4
5
  // src/parser/platforms/twitch.ts
5
- const HOSTS = /* @__PURE__ */ new Set([
6
- "twitch.tv",
7
- "www.twitch.tv",
8
- "m.twitch.tv"
9
- ]);
10
- const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
11
- const VIDEO = /^v?(\d{1,12})$/;
12
- const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
13
- const CLIP = /^[A-Za-z0-9_-]{6,100}$/;
14
- const TIME = /^(?:\d+h)?(?:\d+m)?(?:\d+s)?$/;
15
- const RESERVED = /* @__PURE__ */ new Set([
16
- "directory",
17
- "videos",
18
- "collections",
19
- "settings",
20
- "subscriptions",
21
- "inventory",
22
- "wallet",
23
- "drops",
24
- "search",
25
- "downloads",
26
- "jobs",
27
- "turbo",
28
- "p",
29
- "login",
30
- "signup"
31
- ]);
32
6
  const PLAYER_OPTIONS = [
33
7
  "autoplay",
34
8
  "muted",
35
9
  "time"
36
10
  ];
37
- function target(path, id) {
38
- return {
39
- platform: "twitch",
40
- kind: "video",
41
- url: path,
42
- id,
43
- variant: "iframe"
44
- };
45
- }
46
- const channel = (name) => target(`https://www.twitch.tv/${name.toLowerCase()}`, name.toLowerCase());
47
- const vod = (id) => target(`https://www.twitch.tv/videos/${id}`, id);
48
- const collection = (id) => target(`https://www.twitch.tv/collections/${id}`, id);
49
- const clip = (slug) => target(`https://clips.twitch.tv/${slug}`, slug);
50
11
  function playerOptions(query) {
51
12
  const options = {};
52
13
  for (const name of PLAYER_OPTIONS) {
@@ -64,44 +25,8 @@ function fromPlayer(url) {
64
25
  const list = url.query.get("collection");
65
26
  return list !== void 0 && COLLECTION.test(list) ? collection(list) : null;
66
27
  }
67
- function fromPage(url) {
68
- if (url.host === "clips.twitch.tv") {
69
- const slug = url.path.replace(/^\/|\/$/g, "");
70
- return CLIP.test(slug) ? {
71
- found: clip(slug),
72
- options: {}
73
- } : null;
74
- }
75
- if (!HOSTS.has(url.host)) return null;
76
- const parts = url.path.replace(/^\/|\/$/g, "").split("/");
77
- const [first = "", second, third] = parts;
78
- if (parts.length === 2 && first === "videos") {
79
- const [, id] = VIDEO.exec(second ?? "") ?? [];
80
- if (id === void 0) return null;
81
- const time = url.query.get("t");
82
- return {
83
- found: vod(id),
84
- options: time !== void 0 && TIME.test(time) && time ? { time } : {}
85
- };
86
- }
87
- if (parts.length === 2 && first === "collections") return COLLECTION.test(second ?? "") ? {
88
- found: collection(second ?? ""),
89
- options: {}
90
- } : null;
91
- if (parts.length === 3 && second === "clip") return CHANNEL.test(first) && CLIP.test(third ?? "") ? {
92
- found: clip(third ?? ""),
93
- options: {}
94
- } : null;
95
- if (parts.length === 1 && CHANNEL.test(first) && !RESERVED.has(first.toLowerCase())) return {
96
- found: channel(first),
97
- options: {}
98
- };
99
- return null;
100
- }
101
28
  const twitch = {
102
- platform: "twitch",
103
- name: "Twitch",
104
- shapes: ["video iframe"],
29
+ ...twitchMatcher,
105
30
  parse(root) {
106
31
  if (root.tag !== "iframe") return null;
107
32
  const src = parseUrl(root.attrs.get("src") ?? "");
@@ -117,14 +42,6 @@ const twitch = {
117
42
  options: playerOptions(src.query)
118
43
  }, sizeOf(root));
119
44
  },
120
- isOwnScript: () => false,
121
- match(url) {
122
- const page = fromPage(url);
123
- return page && {
124
- ...page.found,
125
- options: page.options
126
- };
127
- },
128
- ownsFrame: twitchFrame
45
+ isOwnScript: () => false
129
46
  };
130
47
  export { twitch };