social-embeds 0.7.1 → 0.8.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.
Files changed (176) hide show
  1. package/README.md +63 -51
  2. package/dist/components/apple-embed.d.ts +7 -0
  3. package/dist/components/apple-embed.js +39 -0
  4. package/dist/components/bluesky-embed.d.ts +10 -0
  5. package/dist/components/bluesky-embed.js +27 -0
  6. package/dist/components/dailymotion-embed.d.ts +9 -0
  7. package/dist/components/dailymotion-embed.js +30 -0
  8. package/dist/components/facebook-embed.d.ts +6 -0
  9. package/dist/components/facebook-embed.js +40 -0
  10. package/dist/components/flickr-embed.d.ts +6 -0
  11. package/dist/components/flickr-embed.js +27 -0
  12. package/dist/components/generic-iframe-embed.d.ts +11 -0
  13. package/dist/components/generic-iframe-embed.js +26 -0
  14. package/dist/components/giphy-embed.d.ts +4 -0
  15. package/dist/components/giphy-embed.js +22 -0
  16. package/dist/components/hooks.js +38 -0
  17. package/dist/components/iframe-embed.js +169 -0
  18. package/dist/components/imgur-embed.d.ts +6 -0
  19. package/dist/components/imgur-embed.js +23 -0
  20. package/dist/components/instagram-embed.d.ts +5 -0
  21. package/dist/components/instagram-embed.js +25 -0
  22. package/dist/components/kick-embed.d.ts +6 -0
  23. package/dist/components/kick-embed.js +25 -0
  24. package/dist/components/linkedin-embed.d.ts +6 -0
  25. package/dist/components/linkedin-embed.js +23 -0
  26. package/dist/components/pinterest-embed.d.ts +5 -0
  27. package/dist/components/pinterest-embed.js +25 -0
  28. package/dist/components/reddit-embed.d.ts +6 -0
  29. package/dist/components/reddit-embed.js +29 -0
  30. package/dist/components/rumble-embed.d.ts +4 -0
  31. package/dist/components/rumble-embed.js +22 -0
  32. package/dist/components/script-embed.js +108 -0
  33. package/dist/components/shared.d.ts +29 -0
  34. package/dist/components/snapchat-embed.d.ts +4 -0
  35. package/dist/components/snapchat-embed.js +22 -0
  36. package/dist/components/social-embed.d.ts +60 -0
  37. package/dist/components/social-embed.js +221 -0
  38. package/dist/components/soundcloud-embed.d.ts +6 -0
  39. package/dist/components/soundcloud-embed.js +33 -0
  40. package/dist/components/spotify-embed.d.ts +9 -0
  41. package/dist/components/spotify-embed.js +25 -0
  42. package/dist/components/strava-embed.d.ts +6 -0
  43. package/dist/components/strava-embed.js +26 -0
  44. package/dist/components/streamable-embed.d.ts +6 -0
  45. package/dist/components/streamable-embed.js +28 -0
  46. package/dist/components/telegram-embed.d.ts +6 -0
  47. package/dist/components/telegram-embed.js +27 -0
  48. package/dist/components/tenor-embed.d.ts +4 -0
  49. package/dist/components/tenor-embed.js +22 -0
  50. package/dist/components/threads-embed.d.ts +5 -0
  51. package/dist/components/threads-embed.js +25 -0
  52. package/dist/components/tiktok-embed.d.ts +6 -0
  53. package/dist/components/tiktok-embed.js +37 -0
  54. package/dist/components/truthsocial-embed.d.ts +4 -0
  55. package/dist/components/truthsocial-embed.js +22 -0
  56. package/dist/components/tumblr-embed.d.ts +4 -0
  57. package/dist/components/tumblr-embed.js +22 -0
  58. package/dist/components/twitch-embed.d.ts +6 -0
  59. package/dist/components/twitch-embed.js +26 -0
  60. package/dist/components/vimeo-embed.d.ts +5 -0
  61. package/dist/components/vimeo-embed.js +40 -0
  62. package/dist/components/x-embed.d.ts +5 -0
  63. package/dist/components/x-embed.js +32 -0
  64. package/dist/components/youtube-embed.d.ts +5 -0
  65. package/dist/components/youtube-embed.js +43 -0
  66. package/dist/core/drivers.js +125 -0
  67. package/dist/core/layout.js +73 -0
  68. package/dist/core/markup.js +30 -0
  69. package/dist/core/params.js +26 -0
  70. package/dist/core/plans/apple.js +44 -0
  71. package/dist/core/plans/bluesky.d.ts +3 -0
  72. package/dist/core/plans/bluesky.js +34 -0
  73. package/dist/core/plans/dailymotion.d.ts +8 -0
  74. package/dist/core/plans/dailymotion.js +37 -0
  75. package/dist/core/plans/facebook.d.ts +15 -0
  76. package/dist/core/plans/facebook.js +79 -0
  77. package/dist/core/plans/flickr.d.ts +7 -0
  78. package/dist/core/plans/flickr.js +37 -0
  79. package/dist/core/plans/generic.js +44 -0
  80. package/dist/core/plans/giphy.js +16 -0
  81. package/dist/core/plans/imgur.d.ts +4 -0
  82. package/dist/core/plans/imgur.js +34 -0
  83. package/dist/core/plans/instagram.d.ts +4 -0
  84. package/dist/core/plans/instagram.js +26 -0
  85. package/dist/core/plans/kick.d.ts +5 -0
  86. package/dist/core/plans/kick.js +22 -0
  87. package/dist/core/plans/linkedin.d.ts +4 -0
  88. package/dist/core/plans/linkedin.js +23 -0
  89. package/dist/core/plans/pinterest.d.ts +4 -0
  90. package/dist/core/plans/pinterest.js +31 -0
  91. package/dist/core/plans/reddit.d.ts +11 -0
  92. package/dist/core/plans/reddit.js +46 -0
  93. package/dist/core/plans/rumble.js +21 -0
  94. package/dist/core/plans/snapchat.js +20 -0
  95. package/dist/core/plans/soundcloud.d.ts +14 -0
  96. package/dist/core/plans/soundcloud.js +37 -0
  97. package/dist/core/plans/spotify.d.ts +4 -0
  98. package/dist/core/plans/spotify.js +29 -0
  99. package/dist/core/plans/strava.d.ts +8 -0
  100. package/dist/core/plans/strava.js +38 -0
  101. package/dist/core/plans/streamable.d.ts +8 -0
  102. package/dist/core/plans/streamable.js +31 -0
  103. package/dist/core/plans/telegram.d.ts +10 -0
  104. package/dist/core/plans/telegram.js +59 -0
  105. package/dist/core/plans/tenor.js +16 -0
  106. package/dist/core/plans/threads.d.ts +4 -0
  107. package/dist/core/plans/threads.js +25 -0
  108. package/dist/core/plans/tiktok.d.ts +17 -0
  109. package/dist/core/plans/tiktok.js +36 -0
  110. package/dist/core/plans/truthsocial.js +43 -0
  111. package/dist/core/plans/tumblr.js +29 -0
  112. package/dist/core/plans/twitch.d.ts +7 -0
  113. package/dist/core/plans/twitch.js +38 -0
  114. package/dist/core/plans/vimeo.d.ts +23 -0
  115. package/dist/core/plans/vimeo.js +42 -0
  116. package/dist/core/plans/x.d.ts +12 -0
  117. package/dist/core/plans/x.js +31 -0
  118. package/dist/core/plans/youtube.d.ts +25 -0
  119. package/dist/core/plans/youtube.js +59 -0
  120. package/dist/core/post-link.js +19 -0
  121. package/dist/core/resolve.js +57 -0
  122. package/dist/core/timing.js +7 -0
  123. package/dist/element.d.ts +1 -1
  124. package/dist/element.js +1 -1
  125. package/dist/index.d.ts +53 -344
  126. package/dist/index.js +30 -2575
  127. package/dist/loader/load-script.js +116 -0
  128. package/dist/loader/platform-scripts.js +89 -0
  129. package/dist/parser/frames.js +70 -0
  130. package/dist/parser/html.js +172 -0
  131. package/dist/parser/iframe.d.ts +24 -0
  132. package/dist/parser/iframe.js +151 -0
  133. package/dist/parser/lookup.js +20 -0
  134. package/dist/parser/match-url.d.ts +3 -0
  135. package/dist/parser/match-url.js +22 -0
  136. package/dist/parser/parse-embed.d.ts +7 -0
  137. package/dist/parser/parse-embed.js +69 -0
  138. package/dist/parser/platform.js +60 -0
  139. package/dist/parser/platforms/applemusic.js +45 -0
  140. package/dist/parser/platforms/applepodcasts.js +41 -0
  141. package/dist/parser/platforms/bluesky.js +64 -0
  142. package/dist/parser/platforms/dailymotion.js +57 -0
  143. package/dist/parser/platforms/facebook.js +181 -0
  144. package/dist/parser/platforms/flickr.js +134 -0
  145. package/dist/parser/platforms/giphy.js +68 -0
  146. package/dist/parser/platforms/imgur.js +107 -0
  147. package/dist/parser/platforms/index.js +62 -0
  148. package/dist/parser/platforms/instagram.js +59 -0
  149. package/dist/parser/platforms/kick.js +61 -0
  150. package/dist/parser/platforms/linkedin.js +42 -0
  151. package/dist/parser/platforms/pinterest.js +59 -0
  152. package/dist/parser/platforms/reddit.js +69 -0
  153. package/dist/parser/platforms/rumble.js +44 -0
  154. package/dist/parser/platforms/snapchat.js +87 -0
  155. package/dist/parser/platforms/soundcloud.js +128 -0
  156. package/dist/parser/platforms/spotify.js +51 -0
  157. package/dist/parser/platforms/strava.js +55 -0
  158. package/dist/parser/platforms/streamable.js +95 -0
  159. package/dist/parser/platforms/telegram.js +61 -0
  160. package/dist/parser/platforms/tenor.js +79 -0
  161. package/dist/parser/platforms/threads.js +51 -0
  162. package/dist/parser/platforms/tiktok.js +48 -0
  163. package/dist/parser/platforms/truthsocial.js +50 -0
  164. package/dist/parser/platforms/tumblr.js +72 -0
  165. package/dist/parser/platforms/twitch.js +128 -0
  166. package/dist/parser/platforms/vimeo.js +95 -0
  167. package/dist/parser/platforms/x.js +65 -0
  168. package/dist/parser/platforms/youtube.js +140 -0
  169. package/dist/parser/types.d.ts +14 -0
  170. package/dist/parser/url.js +41 -0
  171. package/dist/parser/verify.js +63 -0
  172. package/dist/parser.d.ts +4 -1
  173. package/dist/parser.js +4 -1
  174. package/package.json +1 -1
  175. package/dist/index-DrMHAkyG.d.ts +0 -46
  176. package/dist/parser-CovaPg5T.js +0 -2585
@@ -1,2585 +0,0 @@
1
- // src/parser/html.ts
2
- const VOID_TAGS = /* @__PURE__ */ new Set([
3
- "area",
4
- "base",
5
- "br",
6
- "col",
7
- "embed",
8
- "hr",
9
- "img",
10
- "input",
11
- "link",
12
- "meta",
13
- "source",
14
- "track",
15
- "wbr"
16
- ]);
17
- const RAW_TEXT_END = /* @__PURE__ */ new Map([["script", /<\/script\s*>/giu], ["style", /<\/style\s*>/giu]]);
18
- const MAX_DEPTH = 100;
19
- const START_TAG = /<([a-zA-Z][a-zA-Z0-9-]*)/y;
20
- const ATTRIBUTE = /\s+([^\s"'>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/y;
21
- const START_TAG_END = /\s*(\/?)>/y;
22
- const END_TAG = /<\/([a-zA-Z][a-zA-Z0-9-]*)\s*>/y;
23
- const NAMED_ENTITIES = /* @__PURE__ */ new Map([
24
- ["amp", "&"],
25
- ["lt", "<"],
26
- ["gt", ">"],
27
- ["quot", "\""],
28
- ["apos", "'"],
29
- ["nbsp", "\xA0"]
30
- ]);
31
- function parseHtml(input) {
32
- const root = {
33
- type: "element",
34
- tag: "",
35
- attrs: /* @__PURE__ */ new Map(),
36
- children: []
37
- };
38
- const open = [root];
39
- let pos = 0;
40
- while (pos < input.length) {
41
- const parent = open[open.length - 1] ?? root;
42
- const lt = input.indexOf("<", pos);
43
- const textEnd = lt === -1 ? input.length : lt;
44
- if (textEnd > pos) parent.children.push({
45
- type: "text",
46
- raw: input.slice(pos, textEnd)
47
- });
48
- if (lt === -1) break;
49
- if (input.startsWith("<!--", lt)) {
50
- const close = input.indexOf("-->", lt + 4);
51
- if (close === -1) return null;
52
- parent.children.push({ type: "comment" });
53
- pos = close + 3;
54
- continue;
55
- }
56
- END_TAG.lastIndex = lt;
57
- const end = END_TAG.exec(input);
58
- if (end) {
59
- if (parent === root || parent.tag !== end[1]?.toLowerCase()) return null;
60
- open.pop();
61
- pos = END_TAG.lastIndex;
62
- continue;
63
- }
64
- const start = readStartTag(input, lt);
65
- if (!start) return null;
66
- const { element } = start;
67
- parent.children.push(element);
68
- pos = start.end;
69
- const rawTextEnd = start.selfClosing ? void 0 : RAW_TEXT_END.get(element.tag);
70
- if (rawTextEnd) {
71
- rawTextEnd.lastIndex = pos;
72
- const close = rawTextEnd.exec(input);
73
- if (!close) return null;
74
- if (close.index > pos) element.children.push({
75
- type: "text",
76
- raw: input.slice(pos, close.index)
77
- });
78
- pos = rawTextEnd.lastIndex;
79
- } else if (!start.selfClosing && !VOID_TAGS.has(element.tag)) {
80
- if (open.length > MAX_DEPTH) return null;
81
- open.push(element);
82
- }
83
- }
84
- return open.length === 1 ? root.children : null;
85
- }
86
- function readStartTag(input, at) {
87
- START_TAG.lastIndex = at;
88
- const name = START_TAG.exec(input)?.[1];
89
- if (name === void 0) return null;
90
- const attrs = /* @__PURE__ */ new Map();
91
- let pos = START_TAG.lastIndex;
92
- for (;;) {
93
- START_TAG_END.lastIndex = pos;
94
- const close = START_TAG_END.exec(input);
95
- if (close) return {
96
- element: {
97
- type: "element",
98
- tag: name.toLowerCase(),
99
- attrs,
100
- children: []
101
- },
102
- selfClosing: close[1] === "/",
103
- end: START_TAG_END.lastIndex
104
- };
105
- ATTRIBUTE.lastIndex = pos;
106
- const attribute = ATTRIBUTE.exec(input);
107
- if (!attribute) return null;
108
- const [, attributeName = "", doubleQuoted, singleQuoted, unquoted] = attribute;
109
- const key = attributeName.toLowerCase();
110
- if (!attrs.has(key)) attrs.set(key, decodeEntities(doubleQuoted ?? singleQuoted ?? unquoted ?? ""));
111
- pos = ATTRIBUTE.lastIndex;
112
- }
113
- }
114
- /** Decodes numeric references and the few named entities that appear in embed attributes. */
115
- function decodeEntities(value) {
116
- return value.replace(/&(#[0-9]{1,7}|#[xX][0-9a-fA-F]{1,6}|[a-zA-Z]+);/g, (reference, body) => {
117
- if (!body.startsWith("#")) return NAMED_ENTITIES.get(body) ?? reference;
118
- const hex = body[1] === "x" || body[1] === "X";
119
- const codePoint = Number.parseInt(body.slice(hex ? 2 : 1), hex ? 16 : 10);
120
- return codePoint > 0 && codePoint <= 1114111 && (codePoint < 55296 || codePoint > 57343) ? String.fromCodePoint(codePoint) : reference;
121
- });
122
- }
123
- function hasClass(element, name) {
124
- return (element.attrs.get("class") ?? "").split(/\s+/).includes(name);
125
- }
126
- /** In document order. */
127
- function descendants(nodes) {
128
- const found = [];
129
- collect(nodes, found);
130
- return found;
131
- }
132
- function collect(nodes, found) {
133
- for (const node of nodes) {
134
- if (node.type !== "element") continue;
135
- found.push(node);
136
- collect(node.children, found);
137
- }
138
- }
139
- const URL_ATTRIBUTES = /* @__PURE__ */ new Set(["href", "cite"]);
140
- const HTTP_URL = /^https?:\/\//i;
141
- /**
142
- * Security: the result reaches `dangerouslySetInnerHTML`. Elements off the list are dropped
143
- * with their content, `href` and `cite` must be http(s) URLs, and text never holds a `<`.
144
- */
145
- function rebuild(nodes, whitelist) {
146
- let html = "";
147
- for (const node of nodes) {
148
- if (node.type === "text") {
149
- html += node.raw;
150
- continue;
151
- }
152
- if (node.type !== "element") continue;
153
- const allowed = whitelist.get(node.tag);
154
- if (!allowed) continue;
155
- html += `<${node.tag}`;
156
- for (const rule of allowed) {
157
- const name = typeof rule === "string" ? rule : rule.name;
158
- const value = node.attrs.get(name);
159
- if (value === void 0) continue;
160
- if (typeof rule !== "string" && !rule.value.test(value)) continue;
161
- if (URL_ATTRIBUTES.has(name) && !HTTP_URL.test(value)) continue;
162
- html += ` ${name}="${escapeAttribute(value)}"`;
163
- }
164
- html += ">";
165
- if (!VOID_TAGS.has(node.tag)) html += `${rebuild(node.children, whitelist)}</${node.tag}>`;
166
- }
167
- return html;
168
- }
169
- function escapeAttribute(value) {
170
- return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
171
- }
172
- // src/parser/url.ts
173
- const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#(\S*))?$/i;
174
- /** Absolute or protocol-relative http(s) URLs only. */
175
- function parseUrl(input) {
176
- const match = URL_PATTERN.exec(input.trim());
177
- if (!match) return null;
178
- const [, host = "", path = "", search = "", fragment] = match;
179
- const query = /* @__PURE__ */ new Map();
180
- for (const pair of search.split("&")) {
181
- if (pair === "") continue;
182
- const eq = pair.indexOf("=");
183
- const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
184
- const value = decodeComponent(eq === -1 ? "" : pair.slice(eq + 1));
185
- if (key === null || value === null) return null;
186
- if (!query.has(key)) query.set(key, value);
187
- }
188
- return {
189
- host: host.toLowerCase(),
190
- path,
191
- query,
192
- ...fragment ? { fragment } : {}
193
- };
194
- }
195
- function decodeComponent(component) {
196
- try {
197
- return decodeURIComponent(component.replace(/\+/g, " "));
198
- } catch {
199
- return null;
200
- }
201
- }
202
- /** Types an option value: booleans, canonical integers, otherwise the string as given. */
203
- function coerce(value) {
204
- if (value === "true") return true;
205
- if (value === "false") return false;
206
- if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
207
- return value;
208
- }
209
- function pixels(value) {
210
- return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
211
- }
212
- // src/parser/platform.ts
213
- /** `/embed` holds `/embed` and `/embed/…`, never `/embedded`. */
214
- function underPath(path, folder) {
215
- return path === folder || path.startsWith(`${folder}/`);
216
- }
217
- /** The first attribute present for a key wins. */
218
- function attributeOptions(element, mapping, coerceValue) {
219
- const options = {};
220
- for (const [attribute, key] of mapping) {
221
- const value = element.attrs.get(attribute);
222
- if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
223
- }
224
- return options;
225
- }
226
- function sizeOf(element) {
227
- const width = pixels(element.attrs.get("width"));
228
- const height = pixels(element.attrs.get("height"));
229
- if (width === void 0 && height === void 0) return void 0;
230
- return {
231
- ...width === void 0 ? {} : { width },
232
- ...height === void 0 ? {} : { height }
233
- };
234
- }
235
- /** Adds `size` only when known, so results stay free of `undefined` properties. */
236
- function withSize(embed, size) {
237
- return size ? {
238
- ...embed,
239
- size
240
- } : embed;
241
- }
242
- /**
243
- * A platform's own responsive wrapper: a `div` whose only attribute is a `style` that `pattern`
244
- * matches, around one iframe. The padding percentage it captures is the video's ratio.
245
- */
246
- function unwrapRatio(root, pattern) {
247
- if (root.tag !== "div" || root.attrs.size !== 1) return null;
248
- const [, percent] = pattern.exec(root.attrs.get("style") ?? "") ?? [];
249
- if (percent === void 0) return null;
250
- let iframe;
251
- for (const child of root.children) {
252
- if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
253
- if (child.type !== "element" || child.tag !== "iframe" || iframe) return null;
254
- iframe = child;
255
- }
256
- const height = Math.round(Number(percent) * 100);
257
- if (!iframe || !(height > 0 && height <= 1e5)) return null;
258
- const divisor = gcd$1(1e4, height);
259
- return {
260
- iframe,
261
- size: {
262
- width: 1e4 / divisor,
263
- height: height / divisor
264
- }
265
- };
266
- }
267
- function gcd$1(a, b) {
268
- return b === 0 ? a : gcd$1(b, a % b);
269
- }
270
- // src/parser/platforms/applemusic.ts
271
- const PATH$2 = /^\/([a-z]{2})\/(album|song|playlist)\/(?:[^/]{1,200}\/)?(\d{1,15}|pl\.[A-Za-z0-9-]{1,64})\/?$/;
272
- const SONG = /^\d{1,15}$/;
273
- const FRAME_HOST$3 = "embed.music.apple.com";
274
- function appleContent(url, host) {
275
- if (url?.host !== host) return null;
276
- const [, country, type, id] = PATH$2.exec(url.path) ?? [];
277
- if (country === void 0 || type === void 0 || id === void 0) return null;
278
- if (type === "playlist" ? !id.startsWith("pl.") : !SONG.test(id)) return null;
279
- const song = type === "album" ? url.query.get("i") : void 0;
280
- if (song !== void 0 && !SONG.test(song)) return null;
281
- return {
282
- kind: "post",
283
- url: `https://music.apple.com/${country}/${type}/${id}${song ? `?i=${song}` : ""}`,
284
- id: song ?? id,
285
- variant: "iframe"
286
- };
287
- }
288
- const applemusic = {
289
- platform: "applemusic",
290
- parse(root) {
291
- if (root.tag !== "iframe") return null;
292
- const found = appleContent(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST$3);
293
- if (!found) return null;
294
- const { height } = sizeOf(root) ?? {};
295
- return withSize({
296
- platform: "applemusic",
297
- ...found,
298
- options: {}
299
- }, height === void 0 ? void 0 : { height });
300
- },
301
- isOwnScript: () => false,
302
- match(url) {
303
- const found = appleContent(url, "music.apple.com");
304
- return found && {
305
- platform: "applemusic",
306
- ...found,
307
- options: {}
308
- };
309
- },
310
- ownsFrame: (src) => src.host === FRAME_HOST$3
311
- };
312
- // src/parser/platforms/applepodcasts.ts
313
- const PATH$1 = /^\/([a-z]{2})\/podcast\/(?:[^/]{1,200}\/)?(?:id)?(\d{1,15})\/?$/;
314
- const EPISODE = /^\d{1,15}$/;
315
- const FRAME_HOST$2 = "embed.podcasts.apple.com";
316
- function content$2(url, host) {
317
- if (url?.host !== host) return null;
318
- const [, country, show] = PATH$1.exec(url.path) ?? [];
319
- if (country === void 0 || show === void 0) return null;
320
- const episode = url.query.get("i");
321
- if (episode !== void 0 && !EPISODE.test(episode)) return null;
322
- return {
323
- platform: "applepodcasts",
324
- kind: "post",
325
- url: `https://podcasts.apple.com/${country}/podcast/id${show}${episode ? `?i=${episode}` : ""}`,
326
- id: episode ?? show,
327
- variant: "iframe"
328
- };
329
- }
330
- const applepodcasts = {
331
- platform: "applepodcasts",
332
- parse(root) {
333
- if (root.tag !== "iframe") return null;
334
- const found = content$2(parseUrl(root.attrs.get("src") ?? ""), FRAME_HOST$2);
335
- return found && withSize({
336
- ...found,
337
- options: {}
338
- }, sizeOf(root));
339
- },
340
- isOwnScript: () => false,
341
- match(url) {
342
- const found = content$2(url, "podcasts.apple.com");
343
- return found && {
344
- ...found,
345
- options: {}
346
- };
347
- },
348
- ownsFrame: (src) => src.host === FRAME_HOST$2
349
- };
350
- // src/parser/platforms/bluesky.ts
351
- const DID = "(did:(?:plc:[a-z2-7]{24}|web:[a-z0-9.-]{1,253}))";
352
- const RKEY = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9._~:-]{1,512})";
353
- const HOSTS$17 = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
354
- const POST_PATH$5 = new RegExp(`^/profile/${DID}/post/${RKEY}/?$`);
355
- const AT_URI = new RegExp(`^at://${DID}/app\\.bsky\\.feed\\.post/${RKEY}$`);
356
- const CID = /^[a-z2-7]{20,100}$/;
357
- const COLOR_MODES = /* @__PURE__ */ new Set([
358
- "light",
359
- "dark",
360
- "system"
361
- ]);
362
- const SCRIPT$16 = /^(?:https?:)?\/\/embed\.bsky\.app\/static\/embed\.js$/;
363
- const FALLBACK$7 = /* @__PURE__ */ new Map([
364
- ["p", ["lang"]],
365
- ["a", ["href"]],
366
- ["br", []]
367
- ]);
368
- function post$8(did, rkey) {
369
- return {
370
- platform: "bluesky",
371
- kind: "post",
372
- url: `https://bsky.app/profile/${did}/post/${rkey}`,
373
- id: `${did}/app.bsky.feed.post/${rkey}`,
374
- variant: "iframe"
375
- };
376
- }
377
- function fromUrl$2(url) {
378
- if (!url || !HOSTS$17.has(url.host)) return null;
379
- const [, did, rkey] = POST_PATH$5.exec(url.path) ?? [];
380
- return did === void 0 || rkey === void 0 ? null : post$8(did, rkey);
381
- }
382
- const bluesky = {
383
- platform: "bluesky",
384
- fallback: FALLBACK$7,
385
- parse(root) {
386
- if (root.tag !== "blockquote" || !hasClass(root, "bluesky-embed")) return null;
387
- const [, did, rkey] = AT_URI.exec(root.attrs.get("data-bluesky-uri") ?? "") ?? [];
388
- if (did === void 0 || rkey === void 0) return null;
389
- const found = post$8(did, rkey);
390
- if (descendants(root.children).reverse().map((element) => element.tag === "a" ? fromUrl$2(parseUrl(element.attrs.get("href") ?? "")) : null).find((linked) => linked !== null)?.id !== found.id) return null;
391
- const options = {};
392
- const cid = root.attrs.get("data-bluesky-cid");
393
- if (cid !== void 0 && CID.test(cid)) options.cid = cid;
394
- const colorMode = root.attrs.get("data-bluesky-embed-color-mode");
395
- if (colorMode !== void 0 && COLOR_MODES.has(colorMode)) options.colorMode = colorMode;
396
- return {
397
- ...found,
398
- options,
399
- fallbackHtml: rebuild(root.children, FALLBACK$7)
400
- };
401
- },
402
- isOwnScript: (src) => SCRIPT$16.test(src),
403
- match(url) {
404
- const found = fromUrl$2(url);
405
- return found && {
406
- ...found,
407
- options: {}
408
- };
409
- }
410
- };
411
- // src/parser/platforms/dailymotion.ts
412
- const VIDEO_ID$2 = /^x[a-z0-9]{4,12}$/;
413
- const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
414
- const WRAPPER$4 = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
415
- const HOSTS$16 = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
416
- const PLAYER_HOST$2 = "geo.dailymotion.com";
417
- const SHORT_HOST = "dai.ly";
418
- function video$5(id, options) {
419
- return {
420
- platform: "dailymotion",
421
- kind: "video",
422
- url: `https://www.dailymotion.com/video/${id}`,
423
- id,
424
- variant: "iframe",
425
- options
426
- };
427
- }
428
- /** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
429
- function fromPlayer$2(url) {
430
- if (url.host !== PLAYER_HOST$2 || url.query.has("playlist")) return null;
431
- const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
432
- if (!match) return null;
433
- const [, playerId] = match;
434
- const id = url.query.get("video") ?? "";
435
- if (!VIDEO_ID$2.test(id)) return null;
436
- if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
437
- const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
438
- if (playerId !== void 0) options.playerId = playerId;
439
- return video$5(id, options);
440
- }
441
- function fromPage$2(url) {
442
- if (url.host === SHORT_HOST) {
443
- const id = url.path.replace(/^\/|\/$/g, "");
444
- return VIDEO_ID$2.test(id) ? video$5(id, {}) : null;
445
- }
446
- if (!HOSTS$16.has(url.host)) return null;
447
- const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
448
- return id !== void 0 && VIDEO_ID$2.test(id) ? video$5(id, {}) : null;
449
- }
450
- const dailymotion = {
451
- platform: "dailymotion",
452
- parse(root) {
453
- const wrapped = unwrapRatio(root, WRAPPER$4);
454
- const iframe = wrapped?.iframe ?? root;
455
- if (iframe.tag !== "iframe") return null;
456
- const src = parseUrl(iframe.attrs.get("src") ?? "");
457
- if (!src) return null;
458
- const embed = fromPlayer$2(src) ?? fromPage$2(src);
459
- return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
460
- },
461
- isOwnScript: () => false,
462
- match(url) {
463
- return fromPlayer$2(url) ?? fromPage$2(url);
464
- },
465
- ownsFrame: (src) => src.host === PLAYER_HOST$2 || src.host === SHORT_HOST || HOSTS$16.has(src.host) && (underPath(src.path, "/embed") || underPath(src.path, "/video"))
466
- };
467
- // src/parser/platforms/facebook.ts
468
- const HOSTS$15 = /* @__PURE__ */ new Set([
469
- "facebook.com",
470
- "www.facebook.com",
471
- "m.facebook.com"
472
- ]);
473
- const PLUGIN_HOSTS = /* @__PURE__ */ new Set(["facebook.com", "www.facebook.com"]);
474
- const BASE = "https://www.facebook.com";
475
- const NAME$1 = "[A-Za-z0-9.\\-]{1,80}";
476
- const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
477
- const POSTS_PATH$1 = new RegExp(`^/(${NAME$1})/posts/(${POST_ID})/?$`);
478
- const PHOTOS_PATH = new RegExp(`^/(${NAME$1})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
479
- const VIDEOS_PATH = new RegExp(`^/(${NAME$1})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
480
- const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
481
- const STORY_PATHS = /* @__PURE__ */ new Set(["/permalink.php", "/story.php"]);
482
- const PHOTO_PATHS = /* @__PURE__ */ new Set([
483
- "/photo.php",
484
- "/photo/",
485
- "/photo"
486
- ]);
487
- const STORY_ID = new RegExp(`^${POST_ID}$`);
488
- const NUMERIC_ID = /^\d{1,25}$/;
489
- const SCRIPT$15 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
490
- const OPTION_ATTRIBUTES$5 = [
491
- ["data-width", "width"],
492
- ["data-show-text", "showText"],
493
- ["data-lazy", "lazy"],
494
- ["data-allowfullscreen", "allowfullscreen"],
495
- ["data-autoplay", "autoplay"],
496
- ["data-show-captions", "showCaptions"]
497
- ];
498
- const VIDEO_SDK_PARAMETERS = [
499
- ["show_text", "showText"],
500
- ["allowfullscreen", "allowfullscreen"],
501
- ["autoplay", "autoplay"],
502
- ["show_captions", "showCaptions"]
503
- ];
504
- const PARSE_IGNORE = {
505
- name: "class",
506
- value: /^fb-xfbml-parse-ignore$/
507
- };
508
- const FALLBACK$6 = /* @__PURE__ */ new Map([
509
- ["div", [PARSE_IGNORE]],
510
- ["blockquote", ["cite", PARSE_IGNORE]],
511
- ["a", ["href"]],
512
- ["p", []]
513
- ]);
514
- function target$1(url) {
515
- if (!url || !HOSTS$15.has(url.host)) return null;
516
- const { path, query } = url;
517
- const [, name, postId] = POSTS_PATH$1.exec(path) ?? [];
518
- if (name !== void 0 && postId !== void 0) return {
519
- kind: "post",
520
- id: postId,
521
- url: `${BASE}/${name}/posts/${postId}`
522
- };
523
- if (STORY_PATHS.has(path)) {
524
- const storyId = query.get("story_fbid");
525
- if (storyId === void 0 || !STORY_ID.test(storyId)) return null;
526
- const owner = query.get("id");
527
- const ownerQuery = owner !== void 0 && NUMERIC_ID.test(owner) ? `&id=${owner}` : "";
528
- return {
529
- kind: "post",
530
- id: storyId,
531
- url: `${BASE}${path}?story_fbid=${storyId}${ownerQuery}`
532
- };
533
- }
534
- if (PHOTO_PATHS.has(path)) {
535
- const fbid = query.get("fbid");
536
- if (fbid === void 0 || !NUMERIC_ID.test(fbid)) return null;
537
- return {
538
- kind: "post",
539
- id: fbid,
540
- url: `${BASE}${path}?fbid=${fbid}`
541
- };
542
- }
543
- const [, owner, album, photoId] = PHOTOS_PATH.exec(path) ?? [];
544
- if (owner !== void 0 && album !== void 0 && photoId !== void 0) return {
545
- kind: "post",
546
- id: photoId,
547
- url: `${BASE}/${owner}/photos/${album}/${photoId}/`
548
- };
549
- const [, page, videoId] = VIDEOS_PATH.exec(path) ?? [];
550
- if (page !== void 0 && videoId !== void 0) return {
551
- kind: "video",
552
- id: videoId,
553
- url: `${BASE}/${page}/videos/${videoId}/`
554
- };
555
- if (path === "/watch" || path === "/watch/" || path === "/video.php") {
556
- const v = query.get("v");
557
- if (v === void 0 || !NUMERIC_ID.test(v)) return null;
558
- return {
559
- kind: "video",
560
- id: v,
561
- url: `${BASE}${path === "/video.php" ? path : "/watch/"}?v=${v}`
562
- };
563
- }
564
- const [, reelId] = REEL_PATH.exec(path) ?? [];
565
- if (reelId !== void 0) return {
566
- kind: "video",
567
- id: reelId,
568
- url: `${BASE}/reel/${reelId}`
569
- };
570
- return null;
571
- }
572
- function embed(found, kind, variant, options) {
573
- return {
574
- platform: "facebook",
575
- kind,
576
- url: found.url,
577
- id: found.id,
578
- variant,
579
- options
580
- };
581
- }
582
- const facebook = {
583
- platform: "facebook",
584
- fallback: FALLBACK$6,
585
- parse(root) {
586
- if (root.tag === "div") {
587
- const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
588
- const found = target$1(parseUrl(root.attrs.get("data-href") ?? ""));
589
- if (!kind || !found) return null;
590
- return {
591
- ...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$5, coerce)),
592
- fallbackHtml: rebuild(root.children, FALLBACK$6)
593
- };
594
- }
595
- if (root.tag !== "iframe") return null;
596
- const src = parseUrl(root.attrs.get("src") ?? "");
597
- if (!src || !PLUGIN_HOSTS.has(src.host)) return null;
598
- const found = target$1(parseUrl(src.query.get("href") ?? ""));
599
- if (!found) return null;
600
- if (src.path === "/plugins/post.php") {
601
- const options = {};
602
- const showText = src.query.get("show_text");
603
- const width = src.query.get("width");
604
- if (showText !== void 0) options.showText = coerce(showText);
605
- if (width !== void 0) options.width = coerce(width);
606
- return embed(found, "post", "sdk", options);
607
- }
608
- if (src.path === "/plugins/video.php") {
609
- const showText = coerce(src.query.get("show_text") ?? "");
610
- if (showText === true || showText === 1) {
611
- const options = {};
612
- for (const [parameter, key] of VIDEO_SDK_PARAMETERS) {
613
- const value = src.query.get(parameter);
614
- if (value !== void 0) options[key] = coerce(value);
615
- }
616
- const width = pixels(src.query.get("width"));
617
- const height = pixels(src.query.get("height"));
618
- return withSize(embed(found, "video", "sdk", {
619
- ...options,
620
- showText: true
621
- }), width === void 0 || height === void 0 ? void 0 : {
622
- width,
623
- height
624
- });
625
- }
626
- return withSize(embed(found, "video", "iframe", Object.fromEntries([...src.query].filter(([key]) => key !== "href").map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
627
- }
628
- return null;
629
- },
630
- isOwnScript: (src) => SCRIPT$15.test(src),
631
- scriptOptions(src) {
632
- const [, locale] = SCRIPT$15.exec(src) ?? [];
633
- return locale === void 0 ? {} : { locale };
634
- },
635
- allowsFbRoot: true,
636
- match(url) {
637
- const found = target$1(url);
638
- return found && embed(found, found.kind, "sdk", {});
639
- },
640
- ownsFrame: (src) => PLUGIN_HOSTS.has(src.host) && underPath(src.path, "/plugins")
641
- };
642
- // src/parser/platforms/flickr.ts
643
- const HOSTS$14 = /* @__PURE__ */ new Set(["flickr.com", "www.flickr.com"]);
644
- const USER$2 = "((?!\\.{1,2}(?:/|$))[A-Za-z0-9@_.-]{1,64})";
645
- const ID$4 = "(\\d{1,20})";
646
- const PHOTO_PATH = new RegExp(`^/photos/${USER$2}/${ID$4}(?:/in/[A-Za-z0-9_@./-]{1,200})?/?$`);
647
- const ALBUM_PATH$1 = new RegExp(`^/photos/${USER$2}/(?:albums|sets)/${ID$4}/?$`);
648
- const SHORT_PATH = /^\/p\/([1-9a-km-zA-HJ-NP-Z]{1,12})$/;
649
- const SCRIPT$14 = /^(?:https?:)?\/\/embedr\.flickr\.com\/assets\/client-code\.js$/;
650
- const ALPHABET = "123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ";
651
- const OPTIONS = [
652
- "header",
653
- "footer",
654
- "context"
655
- ];
656
- const IMAGE_SRC = /^https:\/\/(?:live|farm\d{1,3})\.staticflickr\.com\//;
657
- const FALLBACK$5 = /* @__PURE__ */ new Map([["a", [{
658
- name: "href",
659
- value: /^https:\/\/(?:www\.)?flickr\.com\//
660
- }]], ["img", [
661
- {
662
- name: "src",
663
- value: IMAGE_SRC
664
- },
665
- {
666
- name: "width",
667
- value: /^\d{1,6}$/
668
- },
669
- {
670
- name: "height",
671
- value: /^\d{1,6}$/
672
- },
673
- "alt"
674
- ]]]);
675
- /** The photo id of a `flic.kr/p/{code}` code, or `null` for an empty code or a character outside Flickr's base-58 alphabet. */
676
- function decodeFlickrCode(code) {
677
- if (code === "") return null;
678
- let id = 0n;
679
- for (const character of code) {
680
- const digit = ALPHABET.indexOf(character);
681
- if (digit === -1) return null;
682
- id = id * 58n + BigInt(digit);
683
- }
684
- return id.toString();
685
- }
686
- function encodeFlickrCode(id) {
687
- let rest = BigInt(id);
688
- let code = "";
689
- while (rest > 0n) {
690
- code = ALPHABET.charAt(Number(rest % 58n)) + code;
691
- rest /= 58n;
692
- }
693
- return code;
694
- }
695
- function photo(user, id) {
696
- return {
697
- platform: "flickr",
698
- kind: "post",
699
- url: `https://www.flickr.com/photos/${user}/${id}/`,
700
- id,
701
- variant: "iframe"
702
- };
703
- }
704
- function album(user, id) {
705
- return {
706
- platform: "flickr",
707
- kind: "post",
708
- url: `https://www.flickr.com/photos/${user}/albums/${id}`,
709
- id,
710
- variant: "iframe"
711
- };
712
- }
713
- function fromLongUrl(url) {
714
- if (!url || !HOSTS$14.has(url.host)) return null;
715
- const [, albumUser, albumId] = ALBUM_PATH$1.exec(url.path) ?? [];
716
- if (albumUser !== void 0 && albumId !== void 0) return album(albumUser, albumId);
717
- const [, user, id] = PHOTO_PATH.exec(url.path) ?? [];
718
- return user === void 0 || id === void 0 ? null : photo(user, id);
719
- }
720
- function fromShortUrl(url) {
721
- if (url.host !== "flic.kr") return null;
722
- const [, code] = SHORT_PATH.exec(url.path) ?? [];
723
- const id = code === void 0 ? null : decodeFlickrCode(code);
724
- if (code === void 0 || id === null || encodeFlickrCode(id) !== code) return null;
725
- return {
726
- platform: "flickr",
727
- kind: "post",
728
- url: `https://flic.kr/p/${code}`,
729
- id,
730
- variant: "iframe"
731
- };
732
- }
733
- function onlyImage(root) {
734
- let image = null;
735
- for (const child of root.children) {
736
- if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
737
- if (child.type !== "element" || child.tag !== "img" || image) return null;
738
- image = child;
739
- }
740
- return image;
741
- }
742
- const flickr = {
743
- platform: "flickr",
744
- fallback: FALLBACK$5,
745
- parse(root) {
746
- if (root.tag !== "a" || root.attrs.get("data-flickr-embed") !== "true") return null;
747
- const found = fromLongUrl(parseUrl(root.attrs.get("href") ?? ""));
748
- const image = onlyImage(root);
749
- if (!found || !image) return null;
750
- const options = {};
751
- for (const name of OPTIONS) if (root.attrs.get(`data-${name}`) === "true") options[name] = true;
752
- const size = sizeOf(image);
753
- const linked = IMAGE_SRC.test(image.attrs.get("src") ?? "") ? root : {
754
- ...root,
755
- children: []
756
- };
757
- return withSize({
758
- ...found,
759
- options,
760
- fallbackHtml: rebuild([linked], FALLBACK$5)
761
- }, size?.width !== void 0 && size.height !== void 0 ? size : void 0);
762
- },
763
- isOwnScript: (src) => SCRIPT$14.test(src),
764
- match(url) {
765
- const found = fromLongUrl(url) ?? fromShortUrl(url);
766
- return found && {
767
- ...found,
768
- options: {}
769
- };
770
- }
771
- };
772
- // src/parser/platforms/giphy.ts
773
- const ID$3 = "([A-Za-z0-9]{6,40})";
774
- const PAGE_HOSTS$3 = /* @__PURE__ */ new Set(["giphy.com", "www.giphy.com"]);
775
- const PAGE_PATH$3 = new RegExp(`^/gifs/(?:[A-Za-z0-9-]{0,200}-)?${ID$3}/?$`);
776
- const EMBED_PATH$2 = new RegExp(`^/embed/${ID$3}/?$`);
777
- const MEDIA_HOST = /^media\d?\.giphy\.com$/;
778
- const MEDIA_PATH = new RegExp(`^/media/${ID$3}/giphy\\.(?:gif|webp|mp4)$`);
779
- const WRAPPER$3 = /^width:\s*100%;\s*height:\s*0;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*position:\s*relative;?$/;
780
- function gif$1(id) {
781
- return {
782
- platform: "giphy",
783
- kind: "video",
784
- url: `https://giphy.com/gifs/${id}`,
785
- id,
786
- variant: "iframe"
787
- };
788
- }
789
- function idOf$4(url) {
790
- if (!url) return void 0;
791
- if (PAGE_HOSTS$3.has(url.host)) return (PAGE_PATH$3.exec(url.path) ?? EMBED_PATH$2.exec(url.path))?.[1];
792
- if (MEDIA_HOST.test(url.host)) return MEDIA_PATH.exec(url.path)?.[1];
793
- }
794
- function fromIframe$2(iframe) {
795
- if (iframe.tag !== "iframe") return null;
796
- const src = parseUrl(iframe.attrs.get("src") ?? "");
797
- if (!src || !PAGE_HOSTS$3.has(src.host)) return null;
798
- const [, id] = EMBED_PATH$2.exec(src.path) ?? [];
799
- return id === void 0 ? null : gif$1(id);
800
- }
801
- function isCredit$1(element, embed) {
802
- if (element.tag !== "p" || element.attrs.size !== 0) return false;
803
- const [link, ...rest] = element.children;
804
- if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return false;
805
- if (link.attrs.size !== 1) return false;
806
- const href = parseUrl(link.attrs.get("href") ?? "");
807
- if (!href || !PAGE_HOSTS$3.has(href.host) || PAGE_PATH$3.exec(href.path)?.[1] !== embed.id) return false;
808
- const [text, ...more] = link.children;
809
- return more.length === 0 && text?.type === "text" && text.raw.trim() === "via GIPHY";
810
- }
811
- const giphy = {
812
- platform: "giphy",
813
- parse(root) {
814
- const wrapped = unwrapRatio(root, WRAPPER$3);
815
- const iframe = wrapped?.iframe ?? root;
816
- const found = fromIframe$2(iframe);
817
- if (!found) return null;
818
- return withSize({
819
- ...found,
820
- options: {}
821
- }, wrapped?.size ?? sizeOf(iframe));
822
- },
823
- isOwnScript: () => false,
824
- isOwnExtra: isCredit$1,
825
- match(url) {
826
- const id = idOf$4(url);
827
- return id === void 0 ? null : {
828
- ...gif$1(id),
829
- options: {}
830
- };
831
- },
832
- ownsFrame: (src) => PAGE_HOSTS$3.has(src.host) && underPath(src.path, "/embed")
833
- };
834
- // src/parser/platforms/imgur.ts
835
- const HOSTS$13 = /* @__PURE__ */ new Set([
836
- "imgur.com",
837
- "www.imgur.com",
838
- "m.imgur.com"
839
- ]);
840
- const HASH$1 = "([A-Za-z0-9]{5,7})";
841
- const DATA_ID = new RegExp(`^(a/)?${HASH$1}$`);
842
- const ALBUM_PATH = new RegExp(`^/a/${HASH$1}/?$`);
843
- const GALLERY_PATH = new RegExp(`^/gallery/(?:[A-Za-z0-9-]{1,200}-)?${HASH$1}/?$`);
844
- const IMAGE_PATH = new RegExp(`^/${HASH$1}/?$`);
845
- const FILE_PATH = new RegExp(`^/${HASH$1}\\.(?:jpe?g|png|gif|gifv|mp4|webp)$`);
846
- const SCRIPT$13 = /^(?:https?:)?\/\/s\.imgur\.com\/min\/embed\.js$/;
847
- const NOT_IMAGES = /* @__PURE__ */ new Set([
848
- "about",
849
- "apps",
850
- "blog",
851
- "help",
852
- "jobs",
853
- "login",
854
- "press",
855
- "privacy",
856
- "random",
857
- "search",
858
- "signin",
859
- "signup",
860
- "terms",
861
- "tools",
862
- "upload",
863
- "account",
864
- "contact",
865
- "emerald",
866
- "explore",
867
- "gallery",
868
- "hot",
869
- "new",
870
- "rules",
871
- "user"
872
- ]);
873
- const FALLBACK$4 = /* @__PURE__ */ new Map([["a", [{
874
- name: "href",
875
- value: /^https:\/\/(?:www\.)?imgur\.com\//
876
- }]]]);
877
- function post$7(id) {
878
- return {
879
- platform: "imgur",
880
- kind: "post",
881
- url: `https://imgur.com/${id}`,
882
- id,
883
- variant: "iframe"
884
- };
885
- }
886
- function image(hash) {
887
- return hash === void 0 || NOT_IMAGES.has(hash.toLowerCase()) ? void 0 : hash;
888
- }
889
- function idOf$3(url) {
890
- if (!url) return void 0;
891
- if (url.host === "i.imgur.com") return image(FILE_PATH.exec(url.path)?.[1]);
892
- if (!HOSTS$13.has(url.host)) return void 0;
893
- const album = (ALBUM_PATH.exec(url.path) ?? GALLERY_PATH.exec(url.path))?.[1];
894
- if (album !== void 0) return `a/${album}`;
895
- return image(IMAGE_PATH.exec(url.path)?.[1]);
896
- }
897
- function withScheme(nodes) {
898
- return nodes.map((node) => {
899
- if (node.type !== "element") return node;
900
- const href = node.attrs.get("href");
901
- const attrs = new Map(node.attrs);
902
- if (node.tag === "a" && href?.startsWith("//")) attrs.set("href", `https:${href}`);
903
- return {
904
- ...node,
905
- attrs,
906
- children: withScheme(node.children)
907
- };
908
- });
909
- }
910
- function falseOption(root, attribute) {
911
- return root.attrs.get(attribute) === "false";
912
- }
913
- const imgur = {
914
- platform: "imgur",
915
- fallback: FALLBACK$4,
916
- parse(root) {
917
- if (root.tag !== "blockquote" || !hasClass(root, "imgur-embed-pub")) return null;
918
- const id = root.attrs.get("data-id") ?? "";
919
- const [, album, hash] = DATA_ID.exec(id) ?? [];
920
- if (hash === void 0 || album === void 0 && !image(hash)) return null;
921
- const options = {};
922
- if (falseOption(root, "data-context")) options.context = false;
923
- if (falseOption(root, "data-analytics")) options.analytics = false;
924
- return {
925
- ...post$7(id),
926
- options,
927
- fallbackHtml: rebuild(withScheme(root.children), FALLBACK$4)
928
- };
929
- },
930
- isOwnScript: (src) => SCRIPT$13.test(src),
931
- match(url) {
932
- const id = idOf$3(url);
933
- return id === void 0 ? null : {
934
- ...post$7(id),
935
- options: {}
936
- };
937
- }
938
- };
939
- // src/parser/platforms/instagram.ts
940
- const HOSTS$12 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
941
- const POST_PATH$4 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
942
- const TYPES = /* @__PURE__ */ new Set([
943
- "p",
944
- "reel",
945
- "reels",
946
- "tv"
947
- ]);
948
- const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
949
- const SCRIPT$12 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
950
- const FALLBACK$3 = /* @__PURE__ */ new Map([
951
- ["div", []],
952
- ["a", ["href"]],
953
- ["p", []]
954
- ]);
955
- function post$6(url) {
956
- if (!url || !HOSTS$12.has(url.host)) return null;
957
- const [, user, type, code] = POST_PATH$4.exec(url.path) ?? [];
958
- if (type === void 0 || code === void 0) return null;
959
- if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
960
- return {
961
- platform: "instagram",
962
- kind: "post",
963
- url: `https://www.instagram.com/${type === "reels" ? "reel" : type}/${code}/`,
964
- id: code,
965
- variant: "sdk"
966
- };
967
- }
968
- const instagram = {
969
- platform: "instagram",
970
- fallback: FALLBACK$3,
971
- parse(root) {
972
- if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
973
- const permalink = root.attrs.get("data-instgrm-permalink");
974
- const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$6(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$6(parseUrl(permalink));
975
- if (!found) return null;
976
- const options = {};
977
- if (root.attrs.has("data-instgrm-captioned")) options.captioned = true;
978
- const version = root.attrs.get("data-instgrm-version");
979
- if (version !== void 0) options.version = coerce(version);
980
- return {
981
- ...found,
982
- options,
983
- fallbackHtml: rebuild(root.children, FALLBACK$3)
984
- };
985
- },
986
- isOwnScript: (src) => SCRIPT$12.test(src),
987
- match(url) {
988
- const found = post$6(url);
989
- return found && {
990
- ...found,
991
- options: {}
992
- };
993
- }
994
- };
995
- // src/parser/platforms/kick.ts
996
- const PAGE_HOSTS$2 = /* @__PURE__ */ new Set(["kick.com", "www.kick.com"]);
997
- const CHANNEL$2 = /^\/([A-Za-z0-9_-]{1,32})\/?$/;
998
- const NOT_CHANNELS = /* @__PURE__ */ new Set([
999
- "browse",
1000
- "categories",
1001
- "category",
1002
- "clips",
1003
- "video",
1004
- "videos",
1005
- "following",
1006
- "search",
1007
- "settings",
1008
- "dashboard",
1009
- "subscriptions",
1010
- "privacy-policy",
1011
- "terms-of-service",
1012
- "community-guidelines",
1013
- "help"
1014
- ]);
1015
- const KEPT$1 = /* @__PURE__ */ new Set(["autoplay", "muted"]);
1016
- function channel$1(url, hosts) {
1017
- if (!url || !hosts.has(url.host)) return null;
1018
- const [, name] = CHANNEL$2.exec(url.path) ?? [];
1019
- if (name === void 0 || NOT_CHANNELS.has(name.toLowerCase())) return null;
1020
- const id = name.toLowerCase();
1021
- return {
1022
- platform: "kick",
1023
- kind: "video",
1024
- url: `https://kick.com/${id}`,
1025
- id,
1026
- variant: "iframe"
1027
- };
1028
- }
1029
- const PLAYER = /* @__PURE__ */ new Set(["player.kick.com"]);
1030
- const kick = {
1031
- platform: "kick",
1032
- parse(root) {
1033
- if (root.tag !== "iframe") return null;
1034
- const src = parseUrl(root.attrs.get("src") ?? "");
1035
- const found = channel$1(src, PLAYER);
1036
- if (!found || !src) return null;
1037
- const options = Object.fromEntries([...src.query].filter(([key]) => KEPT$1.has(key)).map(([key, value]) => [key, coerce(value)]));
1038
- return withSize({
1039
- ...found,
1040
- options
1041
- }, sizeOf(root));
1042
- },
1043
- isOwnScript: () => false,
1044
- match(url) {
1045
- const found = channel$1(url, PAGE_HOSTS$2) ?? channel$1(url, PLAYER);
1046
- return found && {
1047
- ...found,
1048
- options: {}
1049
- };
1050
- },
1051
- ownsFrame: (src) => PLAYER.has(src.host)
1052
- };
1053
- // src/parser/platforms/linkedin.ts
1054
- const HOST$3 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
1055
- const FRAME_HOST$1 = "www.linkedin.com";
1056
- const URN = "(activity|share|ugcPost):(\\d{19})";
1057
- const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
1058
- const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
1059
- const EMBED_PATH$1 = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
1060
- function post$5(type, id, options = {}) {
1061
- const urn = `urn:li:${type}:${id}`;
1062
- return {
1063
- platform: "linkedin",
1064
- kind: "post",
1065
- url: `https://www.linkedin.com/feed/update/${urn}/`,
1066
- id: urn,
1067
- variant: "iframe",
1068
- options
1069
- };
1070
- }
1071
- const decodeColons = (path) => path.replace(/%3A/gi, ":");
1072
- const linkedin = {
1073
- platform: "linkedin",
1074
- parse(root) {
1075
- if (root.tag !== "iframe") return null;
1076
- const src = parseUrl(root.attrs.get("src") ?? "");
1077
- if (src?.host !== FRAME_HOST$1) return null;
1078
- const [, type, id] = EMBED_PATH$1.exec(src.path) ?? [];
1079
- if (type === void 0 || id === void 0) return null;
1080
- return withSize(post$5(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
1081
- },
1082
- isOwnScript: () => false,
1083
- match(url) {
1084
- if (!HOST$3.test(url.host)) return null;
1085
- const path = decodeColons(url.path);
1086
- const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
1087
- return type === void 0 || id === void 0 ? null : post$5(type, id);
1088
- },
1089
- ownsFrame: (src) => src.host === FRAME_HOST$1 && underPath(src.path, "/embed")
1090
- };
1091
- // src/parser/platforms/pinterest.ts
1092
- const HOST$2 = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
1093
- const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
1094
- const PIN_ID = /^\d{1,25}$/;
1095
- const FRAME_HOST = "assets.pinterest.com";
1096
- const SCRIPT$11 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
1097
- const OPTION_ATTRIBUTES$4 = [
1098
- ["data-pin-width", "width"],
1099
- ["data-pin-lang", "lang"],
1100
- ["data-pin-terse", "terse"]
1101
- ];
1102
- function pin(id) {
1103
- return {
1104
- platform: "pinterest",
1105
- kind: "post",
1106
- url: `https://www.pinterest.com/pin/${id}/`,
1107
- id,
1108
- variant: "sdk"
1109
- };
1110
- }
1111
- function pinOf(url) {
1112
- if (!url || !HOST$2.test(url.host)) return null;
1113
- const [, id] = PIN_PATH.exec(url.path) ?? [];
1114
- return id === void 0 ? null : pin(id);
1115
- }
1116
- const pinterest = {
1117
- platform: "pinterest",
1118
- parse(root) {
1119
- if (root.tag === "a") {
1120
- if (root.attrs.get("data-pin-do") !== "embedPin") return null;
1121
- if (root.children.some((child) => child.type === "element")) return null;
1122
- const found = pinOf(parseUrl(root.attrs.get("href") ?? ""));
1123
- return found && {
1124
- ...found,
1125
- options: attributeOptions(root, OPTION_ATTRIBUTES$4, coerce)
1126
- };
1127
- }
1128
- if (root.tag !== "iframe") return null;
1129
- const src = parseUrl(root.attrs.get("src") ?? "");
1130
- if (src?.host !== FRAME_HOST || src.path !== "/ext/embed.html") return null;
1131
- const id = src.query.get("id");
1132
- return id !== void 0 && PIN_ID.test(id) ? {
1133
- ...pin(id),
1134
- options: {}
1135
- } : null;
1136
- },
1137
- isOwnScript: (src) => SCRIPT$11.test(src),
1138
- match(url) {
1139
- const found = pinOf(url);
1140
- return found && {
1141
- ...found,
1142
- options: {}
1143
- };
1144
- },
1145
- ownsFrame: (src) => src.host === FRAME_HOST
1146
- };
1147
- // src/parser/platforms/reddit.ts
1148
- const HOSTS$11 = /* @__PURE__ */ new Set([
1149
- "reddit.com",
1150
- "www.reddit.com",
1151
- "old.reddit.com",
1152
- "new.reddit.com"
1153
- ]);
1154
- const POST_PATH$3 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
1155
- const SCRIPT$10 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
1156
- const OPTION_ATTRIBUTES$3 = [
1157
- "depth",
1158
- "style",
1159
- "theme",
1160
- "showmedia",
1161
- "showtitle",
1162
- "showedits",
1163
- "created",
1164
- "locale",
1165
- "showusername",
1166
- "snippet"
1167
- ].map((name) => [`data-embed-${name}`, name]);
1168
- function post$4(url) {
1169
- if (!url || !HOSTS$11.has(url.host)) return null;
1170
- const [, sub, postId, slug, commentId] = POST_PATH$3.exec(url.path) ?? [];
1171
- if (sub === void 0 || postId === void 0) return null;
1172
- const base = {
1173
- platform: "reddit",
1174
- kind: "post",
1175
- variant: "iframe"
1176
- };
1177
- const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
1178
- if (commentId === void 0) return {
1179
- ...base,
1180
- url: postUrl,
1181
- id: postId
1182
- };
1183
- if (slug === void 0) return null;
1184
- return {
1185
- ...base,
1186
- url: `${postUrl}comment/${commentId}/`,
1187
- id: commentId
1188
- };
1189
- }
1190
- const reddit = {
1191
- platform: "reddit",
1192
- parse(root) {
1193
- if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
1194
- const found = descendants(root.children).map((element) => element.tag === "a" ? post$4(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
1195
- if (!found) return null;
1196
- const height = pixels(root.attrs.get("data-embed-height"));
1197
- return withSize({
1198
- ...found,
1199
- options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
1200
- }, height === void 0 ? void 0 : { height });
1201
- },
1202
- isOwnScript: (src) => SCRIPT$10.test(src),
1203
- match(url) {
1204
- const found = post$4(url);
1205
- return found && {
1206
- ...found,
1207
- options: {}
1208
- };
1209
- }
1210
- };
1211
- // src/parser/platforms/snapchat.ts
1212
- const HOSTS$10 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
1213
- const USER$1 = "([A-Za-z][A-Za-z0-9._-]{1,29})";
1214
- const SPOTLIGHT = new RegExp(`^(?:/@${USER$1})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
1215
- const PROFILE = new RegExp(`^/(?:@|add/)${USER$1}$`);
1216
- const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
1217
- const HIGHLIGHT = new RegExp(`^/@${USER$1}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
1218
- const SCRIPT$9 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
1219
- function content$1(url) {
1220
- if (!url || !HOSTS$10.has(url.host)) return null;
1221
- const path = url.path.replace(/\/$/, "");
1222
- const base = {
1223
- platform: "snapchat",
1224
- variant: "iframe"
1225
- };
1226
- const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
1227
- if (spotlightId !== void 0) {
1228
- const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
1229
- return {
1230
- ...base,
1231
- kind: "video",
1232
- url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
1233
- id: spotlightId
1234
- };
1235
- }
1236
- const [, user] = PROFILE.exec(path) ?? [];
1237
- if (user !== void 0) return {
1238
- ...base,
1239
- kind: "post",
1240
- url: `https://www.snapchat.com/@${user}`,
1241
- id: user
1242
- };
1243
- const [, lens] = LENS.exec(path) ?? [];
1244
- if (lens !== void 0) return {
1245
- ...base,
1246
- kind: "post",
1247
- url: `https://www.snapchat.com/lens/${lens}`,
1248
- id: lens
1249
- };
1250
- const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
1251
- if (owner !== void 0 && highlight !== void 0) return {
1252
- ...base,
1253
- kind: "post",
1254
- url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
1255
- id: highlight
1256
- };
1257
- return null;
1258
- }
1259
- const snapchat = {
1260
- platform: "snapchat",
1261
- parse(root) {
1262
- if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
1263
- const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
1264
- if (!embedUrl?.path.endsWith("/embed")) return null;
1265
- const found = content$1({
1266
- ...embedUrl,
1267
- path: embedUrl.path.slice(0, -6)
1268
- });
1269
- if (!found) return null;
1270
- if (!descendants(root.children).filter((el) => el.tag === "a").every((link) => {
1271
- const linked = content$1(parseUrl(link.attrs.get("href") ?? ""));
1272
- return linked?.kind === found.kind && linked.id === found.id;
1273
- })) return null;
1274
- const title = root.attrs.get("data-snapchat-embed-title");
1275
- const width = pixels(root.attrs.get("data-snapchat-embed-width"));
1276
- const height = pixels(root.attrs.get("data-snapchat-embed-height"));
1277
- return withSize({
1278
- ...found,
1279
- options: title === void 0 ? {} : { title }
1280
- }, width === void 0 || height === void 0 ? void 0 : {
1281
- width,
1282
- height
1283
- });
1284
- },
1285
- isOwnScript: (src) => SCRIPT$9.test(src),
1286
- match(url) {
1287
- const found = content$1(url);
1288
- return found && {
1289
- ...found,
1290
- options: {}
1291
- };
1292
- }
1293
- };
1294
- // src/parser/platforms/soundcloud.ts
1295
- const PAGE_HOSTS$1 = /* @__PURE__ */ new Set([
1296
- "soundcloud.com",
1297
- "www.soundcloud.com",
1298
- "m.soundcloud.com"
1299
- ]);
1300
- const API_PATH = /^\/(tracks|playlists|users)\/(?:soundcloud%3A(?:tracks|playlists|users)%3A)?(\d{1,15})\/?$/i;
1301
- const NAME = "[a-z0-9_-]{1,64}";
1302
- const SECRET = "s-[A-Za-z0-9]{1,32}";
1303
- const PERMALINK = new RegExp(`^/(${NAME})(?:/(sets/${NAME}|${NAME})(?:/(${SECRET}))?)?/?$`, "i");
1304
- const NOT_USERS = /* @__PURE__ */ new Set([
1305
- "discover",
1306
- "search",
1307
- "stream",
1308
- "feed",
1309
- "you",
1310
- "upload",
1311
- "charts",
1312
- "pages",
1313
- "settings",
1314
- "messages",
1315
- "notifications",
1316
- "people",
1317
- "stations",
1318
- "library",
1319
- "terms-of-use",
1320
- "signin"
1321
- ]);
1322
- const NOT_SOUNDS = /* @__PURE__ */ new Set([
1323
- "likes",
1324
- "tracks",
1325
- "sets",
1326
- "albums",
1327
- "reposts",
1328
- "popular-tracks",
1329
- "followers",
1330
- "following",
1331
- "comments",
1332
- "spotlight",
1333
- "toptracks"
1334
- ]);
1335
- const SECRET_TOKEN = new RegExp(`^${SECRET}$`);
1336
- const WIDGET_HOST = "w.soundcloud.com";
1337
- function sound(url, id) {
1338
- return {
1339
- platform: "soundcloud",
1340
- kind: "post",
1341
- url,
1342
- id,
1343
- variant: "iframe"
1344
- };
1345
- }
1346
- function fromApi(url) {
1347
- if (url?.host !== "api.soundcloud.com") return null;
1348
- const [, type, id] = API_PATH.exec(url.path) ?? [];
1349
- if (type === void 0 || id === void 0) return null;
1350
- const token = url.query.get("secret_token");
1351
- if (token !== void 0 && !SECRET_TOKEN.test(token)) return null;
1352
- const secret = token === void 0 ? "" : `?secret_token=${token}`;
1353
- return sound(`https://api.soundcloud.com/${type.toLowerCase()}/${id}${secret}`, id);
1354
- }
1355
- function fromPage$1(url) {
1356
- if (!PAGE_HOSTS$1.has(url.host)) return null;
1357
- const [, user, second, secret] = PERMALINK.exec(url.path) ?? [];
1358
- if (user === void 0 || NOT_USERS.has(user.toLowerCase())) return null;
1359
- if (second !== void 0 && NOT_SOUNDS.has(second.toLowerCase())) return null;
1360
- const path = [
1361
- user,
1362
- second,
1363
- secret
1364
- ].filter(Boolean).join("/");
1365
- return sound(`https://soundcloud.com/${path}`, path);
1366
- }
1367
- const LINK_ATTRIBUTES = /* @__PURE__ */ new Set([
1368
- "href",
1369
- "title",
1370
- "target",
1371
- "style"
1372
- ]);
1373
- function isCreditLink(node) {
1374
- if (node?.type !== "element" || node.tag !== "a") return false;
1375
- if ([...node.attrs.keys()].some((name) => !LINK_ATTRIBUTES.has(name))) return false;
1376
- const [text, ...rest] = node.children;
1377
- return rest.length === 0 && text?.type === "text" && PAGE_HOSTS$1.has(parseUrl(node.attrs.get("href") ?? "")?.host ?? "");
1378
- }
1379
- /** Share code's credit: a styled `div` with the artist link, ` · `, and the sound link. */
1380
- function isCredit(element) {
1381
- if (element.tag !== "div" || element.attrs.size !== 1 || !element.attrs.has("style")) return false;
1382
- const [artist, separator, sound, ...rest] = element.children;
1383
- return rest.length === 0 && isCreditLink(artist) && separator?.type === "text" && /^\s*·\s*$/.test(separator.raw) && isCreditLink(sound);
1384
- }
1385
- const soundcloud = {
1386
- platform: "soundcloud",
1387
- parse(root) {
1388
- if (root.tag !== "iframe") return null;
1389
- const src = parseUrl(root.attrs.get("src") ?? "");
1390
- if (src?.host !== WIDGET_HOST || !/^\/player\/?$/.test(src.path)) return null;
1391
- let found = fromApi(parseUrl(src.query.get("url") ?? ""));
1392
- if (!found) return null;
1393
- const outer = src.query.get("secret_token");
1394
- if (outer !== void 0) {
1395
- if (!SECRET_TOKEN.test(outer)) return null;
1396
- if (!found.url.includes("?")) found = {
1397
- ...found,
1398
- url: `${found.url}?secret_token=${outer}`
1399
- };
1400
- }
1401
- const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
1402
- const { height } = sizeOf(root) ?? {};
1403
- return withSize({
1404
- ...found,
1405
- options
1406
- }, height === void 0 ? void 0 : { height });
1407
- },
1408
- isOwnScript: () => false,
1409
- isOwnExtra: isCredit,
1410
- match(url) {
1411
- const found = fromApi(url) ?? fromPage$1(url);
1412
- return found && {
1413
- ...found,
1414
- options: {}
1415
- };
1416
- },
1417
- ownsFrame: (src) => src.host === WIDGET_HOST
1418
- };
1419
- // src/parser/platforms/rumble.ts
1420
- const PATH = /^\/embed\/(v[a-z0-9]{1,12})\/?$/;
1421
- const HOSTS$9 = /* @__PURE__ */ new Set(["rumble.com", "www.rumble.com"]);
1422
- function video$4(id) {
1423
- return {
1424
- platform: "rumble",
1425
- kind: "video",
1426
- url: `https://rumble.com/embed/${id}/`,
1427
- id,
1428
- variant: "iframe"
1429
- };
1430
- }
1431
- function idOf$2(url, hosts) {
1432
- return url && hosts.has(url.host) ? PATH.exec(url.path)?.[1] : void 0;
1433
- }
1434
- const rumble = {
1435
- platform: "rumble",
1436
- parse(root) {
1437
- if (root.tag !== "iframe") return null;
1438
- const src = parseUrl(root.attrs.get("src") ?? "");
1439
- const id = idOf$2(src, /* @__PURE__ */ new Set(["rumble.com"]));
1440
- if (id === void 0 || !src) return null;
1441
- const options = {};
1442
- const pub = src.query.get("pub");
1443
- if (pub) options.pub = coerce(pub);
1444
- return withSize({
1445
- ...video$4(id),
1446
- options
1447
- }, sizeOf(root));
1448
- },
1449
- isOwnScript: () => false,
1450
- match(url) {
1451
- const id = idOf$2(url, HOSTS$9);
1452
- return id === void 0 ? null : {
1453
- ...video$4(id),
1454
- options: {}
1455
- };
1456
- },
1457
- ownsFrame: (src) => src.host === "rumble.com" && underPath(src.path, "/embed")
1458
- };
1459
- // src/parser/platforms/spotify.ts
1460
- const CONTENT_PATH = new RegExp(`^(?:/intl-[a-z]{2}(?:-[A-Za-z]{2})?)?(?:/embed)?/(track|album|playlist|artist|episode|show|audiobook|chapter)/([A-Za-z0-9]{22})(/video)?/?$`);
1461
- const DROPPED$1 = /* @__PURE__ */ new Set(["utm_source", "si"]);
1462
- const HOST$1 = "open.spotify.com";
1463
- function content(url) {
1464
- if (url?.host !== HOST$1) return null;
1465
- const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
1466
- if (type === void 0 || id === void 0) return null;
1467
- return {
1468
- platform: "spotify",
1469
- kind: video ? "video" : "post",
1470
- url: `https://open.spotify.com/${type}/${id}`,
1471
- id,
1472
- variant: "iframe",
1473
- query: url.query
1474
- };
1475
- }
1476
- function options(query) {
1477
- return Object.fromEntries([...query].filter(([key]) => !DROPPED$1.has(key)).map(([key, value]) => [key, coerce(value)]));
1478
- }
1479
- const spotify = {
1480
- platform: "spotify",
1481
- parse(root) {
1482
- if (root.tag !== "iframe") return null;
1483
- const src = parseUrl(root.attrs.get("src") ?? "");
1484
- if (!src?.path.startsWith("/embed/")) return null;
1485
- const found = content(src);
1486
- if (!found) return null;
1487
- const { query, ...embed } = found;
1488
- return withSize({
1489
- ...embed,
1490
- options: options(query)
1491
- }, sizeOf(root));
1492
- },
1493
- isOwnScript: () => false,
1494
- match(url) {
1495
- const found = content(url);
1496
- return found && {
1497
- platform: found.platform,
1498
- kind: "post",
1499
- url: found.url,
1500
- id: found.id,
1501
- variant: found.variant,
1502
- options: {}
1503
- };
1504
- },
1505
- ownsFrame: (src) => src.host === HOST$1 && underPath(src.path, "/embed")
1506
- };
1507
- // src/parser/platforms/strava.ts
1508
- const HOSTS$8 = /* @__PURE__ */ new Set(["strava.com", "www.strava.com"]);
1509
- const NUMBER = /^\d{1,20}$/;
1510
- const PAGE_PATH$2 = /^\/(activities|routes)\/(\d{1,20})\/?$/;
1511
- const SCRIPT$8 = /^(?:https?:)?\/\/strava-embeds\.com\/embed\.js$/;
1512
- const STYLES = /* @__PURE__ */ new Set(["standard", "minimal"]);
1513
- const MAP_HASH = /^[A-Za-z0-9_-]{1,100}$/;
1514
- const PAGES = {
1515
- activity: "activities",
1516
- route: "routes"
1517
- };
1518
- function item(type, number) {
1519
- return {
1520
- platform: "strava",
1521
- kind: "post",
1522
- url: `https://www.strava.com/${PAGES[type]}/${number}`,
1523
- id: `${type}/${number}`,
1524
- variant: "iframe"
1525
- };
1526
- }
1527
- function isType(value) {
1528
- return value === "activity" || value === "route";
1529
- }
1530
- const strava = {
1531
- platform: "strava",
1532
- parse(root) {
1533
- if (root.tag !== "div" || !hasClass(root, "strava-embed-placeholder")) return null;
1534
- if (!root.children.every((child) => child.type === "comment" || child.type === "text" && /^\s*$/.test(child.raw))) return null;
1535
- const type = root.attrs.get("data-embed-type");
1536
- const number = root.attrs.get("data-embed-id") ?? "";
1537
- if (!isType(type) || !NUMBER.test(number)) return null;
1538
- const options = {};
1539
- const style = root.attrs.get("data-style");
1540
- if (style !== void 0 && STYLES.has(style)) options.style = style;
1541
- if (type === "route" && root.attrs.get("data-full-width") === "true") options.fullWidth = true;
1542
- const mapHash = root.attrs.get("data-map-hash");
1543
- if (mapHash !== void 0 && MAP_HASH.test(mapHash)) options.mapHash = mapHash;
1544
- return {
1545
- ...item(type, number),
1546
- options
1547
- };
1548
- },
1549
- isOwnScript: (src) => SCRIPT$8.test(src),
1550
- match(url) {
1551
- if (!HOSTS$8.has(url.host)) return null;
1552
- const [, page, number] = PAGE_PATH$2.exec(url.path) ?? [];
1553
- if (page === void 0 || number === void 0) return null;
1554
- return {
1555
- ...item(page === "routes" ? "route" : "activity", number),
1556
- options: {}
1557
- };
1558
- }
1559
- };
1560
- // src/parser/platforms/streamable.ts
1561
- const ID$2 = "([a-z0-9]{4,8})";
1562
- const PAGE_HOSTS = /* @__PURE__ */ new Set(["streamable.com", "www.streamable.com"]);
1563
- const PLAYER_PATH$2 = new RegExp(`^/[eo]/${ID$2}$`);
1564
- const PAGE_PATH$1 = new RegExp(`^/${ID$2}$`);
1565
- const NOT_VIDEOS = /* @__PURE__ */ new Set([
1566
- "about",
1567
- "login",
1568
- "signup",
1569
- "terms",
1570
- "privacy",
1571
- "pricing",
1572
- "upload",
1573
- "help",
1574
- "apps",
1575
- "blog",
1576
- "jobs",
1577
- "press",
1578
- "tools",
1579
- "embed",
1580
- "plans",
1581
- "contact",
1582
- "support",
1583
- "videos",
1584
- "account",
1585
- "profile"
1586
- ]);
1587
- const WRAPPER$2 = /^width:\s*100%;\s*height:\s*0(?:px)?;\s*position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;?$/;
1588
- const KEPT = /* @__PURE__ */ new Set([
1589
- "loop",
1590
- "autoplay",
1591
- "nocontrols",
1592
- "hd",
1593
- "muted"
1594
- ]);
1595
- const STRAY_END = /<\/div\s*>$/i;
1596
- function video$3(id) {
1597
- return {
1598
- platform: "streamable",
1599
- kind: "video",
1600
- url: `https://streamable.com/${id}`,
1601
- id,
1602
- variant: "iframe"
1603
- };
1604
- }
1605
- function validId(id) {
1606
- return id !== void 0 && !NOT_VIDEOS.has(id);
1607
- }
1608
- function fromIframe$1(iframe) {
1609
- if (iframe.tag !== "iframe") return null;
1610
- const src = parseUrl(iframe.attrs.get("src") ?? "");
1611
- if (!src || src.host !== "streamable.com") return null;
1612
- const [, id] = PLAYER_PATH$2.exec(src.path) ?? [];
1613
- if (!validId(id)) return null;
1614
- const options = Object.fromEntries([...src.query].filter(([key]) => KEPT.has(key)).map(([key, value]) => [key, coerce(value)]));
1615
- return {
1616
- ...video$3(id),
1617
- options
1618
- };
1619
- }
1620
- function idOf$1(url) {
1621
- if (!url || !PAGE_HOSTS.has(url.host)) return void 0;
1622
- const id = (PLAYER_PATH$2.exec(url.path) ?? PAGE_PATH$1.exec(url.path))?.[1];
1623
- return validId(id) ? id : void 0;
1624
- }
1625
- const streamable = {
1626
- platform: "streamable",
1627
- parse(root) {
1628
- const wrapped = unwrapRatio(root, WRAPPER$2);
1629
- const iframe = wrapped?.iframe ?? root;
1630
- const found = fromIframe$1(iframe);
1631
- if (!found) return null;
1632
- return withSize(found, wrapped?.size ?? sizeOf(iframe));
1633
- },
1634
- isOwnScript: () => false,
1635
- repair(html) {
1636
- const code = html.trimEnd();
1637
- const end = STRAY_END.exec(code);
1638
- if (!end) return null;
1639
- const trimmed = code.slice(0, end.index).trimEnd();
1640
- return /^\s*<iframe[\s>]/i.test(trimmed) ? trimmed : null;
1641
- },
1642
- match(url) {
1643
- const id = idOf$1(url);
1644
- return id === void 0 ? null : {
1645
- ...video$3(id),
1646
- options: {}
1647
- };
1648
- },
1649
- ownsFrame: (src) => src.host === "streamable.com" && (underPath(src.path, "/e") || underPath(src.path, "/o"))
1650
- };
1651
- // src/parser/platforms/telegram.ts
1652
- const HOSTS$7 = /* @__PURE__ */ new Set([
1653
- "t.me",
1654
- "telegram.me",
1655
- "www.telegram.me"
1656
- ]);
1657
- const CHANNEL$1 = "[A-Za-z][A-Za-z0-9_]{2,31}";
1658
- const POST$1 = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
1659
- const POST_PATH$2 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
1660
- const SCRIPT$7 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
1661
- const OTHER_WIDGETS = [
1662
- "data-telegram-login",
1663
- "data-telegram-discussion",
1664
- "data-telegram-share-url"
1665
- ];
1666
- const OPTION_ATTRIBUTES$2 = [
1667
- ["data-width", "width"],
1668
- ["data-comment", "comment"],
1669
- ["data-userpic", "userpic"],
1670
- ["data-mode", "mode"],
1671
- ["data-color", "color"],
1672
- ["data-dark", "dark"],
1673
- ["data-dark-color", "darkColor"]
1674
- ];
1675
- function post$3(channel, id, options) {
1676
- return {
1677
- platform: "telegram",
1678
- kind: "post",
1679
- url: `https://t.me/${channel}/${id}`,
1680
- id: `${channel}/${id}`,
1681
- variant: "iframe",
1682
- options
1683
- };
1684
- }
1685
- const telegram = {
1686
- platform: "telegram",
1687
- parse: () => null,
1688
- parseScript(script) {
1689
- if (!SCRIPT$7.test(script.attrs.get("src") ?? "")) return null;
1690
- if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
1691
- const [, channel, id] = POST$1.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
1692
- if (channel === void 0 || id === void 0) return null;
1693
- const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
1694
- if (script.attrs.has("data-single")) options.single = true;
1695
- return post$3(channel, id, options);
1696
- },
1697
- isOwnScript: (src) => SCRIPT$7.test(src),
1698
- match(url) {
1699
- if (!HOSTS$7.has(url.host)) return null;
1700
- const [, channel, id] = POST_PATH$2.exec(url.path) ?? [];
1701
- if (channel === void 0 || id === void 0) return null;
1702
- const options = {};
1703
- if (url.query.has("single")) options.single = true;
1704
- const comment = url.query.get("comment");
1705
- if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
1706
- return post$3(channel, id, options);
1707
- }
1708
- };
1709
- // src/parser/platforms/tenor.ts
1710
- const HOSTS$6 = /* @__PURE__ */ new Set(["tenor.com", "www.tenor.com"]);
1711
- const ID$1 = "(\\d{1,20})";
1712
- const PAGE_PATH = new RegExp(`^/(?:[a-z]{2}(?:-[A-Za-z]{2,4})?/)?view/(?:[A-Za-z0-9%_.~-]{1,300}-gif-)?${ID$1}/?$`);
1713
- const FRAME_PATH$2 = new RegExp(`^/embed/${ID$1}$`);
1714
- const SCRIPT$6 = /^(?:https?:)?\/\/tenor\.com\/embed\.js$/;
1715
- const RATIO = /^\d{1,3}(?:\.\d{1,4})?$/;
1716
- const DEFAULT_RATIO = 1.33;
1717
- const FALLBACK$2 = /* @__PURE__ */ new Map([["a", ["href"]]]);
1718
- function gif(id) {
1719
- return {
1720
- platform: "tenor",
1721
- kind: "video",
1722
- url: `https://tenor.com/view/${id}`,
1723
- id,
1724
- variant: "iframe"
1725
- };
1726
- }
1727
- function idOf(url) {
1728
- return url && HOSTS$6.has(url.host) ? PAGE_PATH.exec(url.path)?.[1] : void 0;
1729
- }
1730
- function ratioSize(ratio) {
1731
- const width = Math.round(ratio * 1e4);
1732
- if (!(width > 0 && width <= 1e6)) return void 0;
1733
- const divisor = gcd(width, 1e4);
1734
- return {
1735
- width: width / divisor,
1736
- height: 1e4 / divisor
1737
- };
1738
- }
1739
- function gcd(a, b) {
1740
- return b === 0 ? a : gcd(b, a % b);
1741
- }
1742
- function fromDiv(root) {
1743
- if (!hasClass(root, "tenor-gif-embed")) return null;
1744
- const id = root.attrs.get("data-postid") ?? "";
1745
- if (!new RegExp(`^${ID$1}$`).test(id)) return null;
1746
- const given = root.attrs.get("data-aspect-ratio");
1747
- if (given !== void 0 && !RATIO.test(given)) return null;
1748
- const size = ratioSize(given === void 0 ? DEFAULT_RATIO : Number(given));
1749
- if (!size) return null;
1750
- return withSize({
1751
- ...gif(id),
1752
- options: {},
1753
- fallbackHtml: rebuild(root.children, FALLBACK$2)
1754
- }, size);
1755
- }
1756
- function fromIframe(root) {
1757
- const src = parseUrl(root.attrs.get("src") ?? "");
1758
- if (!src || src.host !== "tenor.com") return null;
1759
- const [, id] = FRAME_PATH$2.exec(src.path) ?? [];
1760
- return id === void 0 ? null : withSize({
1761
- ...gif(id),
1762
- options: {}
1763
- }, sizeOf(root));
1764
- }
1765
- const tenor = {
1766
- platform: "tenor",
1767
- fallback: FALLBACK$2,
1768
- parse(root) {
1769
- if (root.tag === "div") return fromDiv(root);
1770
- return root.tag === "iframe" ? fromIframe(root) : null;
1771
- },
1772
- isOwnScript: (src) => SCRIPT$6.test(src),
1773
- match(url) {
1774
- const id = idOf(url);
1775
- return id === void 0 ? null : {
1776
- ...gif(id),
1777
- options: {}
1778
- };
1779
- },
1780
- ownsFrame: (src) => src.host === "tenor.com" && underPath(src.path, "/embed")
1781
- };
1782
- // src/parser/platforms/threads.ts
1783
- const HOSTS$5 = /* @__PURE__ */ new Set([
1784
- "threads.com",
1785
- "www.threads.com",
1786
- "threads.net",
1787
- "www.threads.net"
1788
- ]);
1789
- const POST_PATH$1 = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
1790
- const SCRIPT$5 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
1791
- const OPTION_ATTRIBUTES$1 = [["data-theme", "theme"], ["data-text-post-version", "version"]];
1792
- const FALLBACK$1 = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
1793
- function post$2(url) {
1794
- if (!url || !HOSTS$5.has(url.host)) return null;
1795
- const [, code] = POST_PATH$1.exec(url.path) ?? [];
1796
- if (code === void 0) return null;
1797
- return {
1798
- platform: "threads",
1799
- kind: "post",
1800
- url: `https://www.threads.com/t/${code}`,
1801
- id: code,
1802
- variant: "sdk"
1803
- };
1804
- }
1805
- const threads = {
1806
- platform: "threads",
1807
- fallback: FALLBACK$1,
1808
- parse(root) {
1809
- if (root.tag !== "blockquote" || !hasClass(root, "text-post-media")) return null;
1810
- const found = post$2(parseUrl(root.attrs.get("data-text-post-permalink") ?? ""));
1811
- if (!found) return null;
1812
- const elementId = root.attrs.get("id");
1813
- if (elementId !== void 0 && elementId !== `ig-tp-${found.id}`) return null;
1814
- return {
1815
- ...found,
1816
- options: attributeOptions(root, OPTION_ATTRIBUTES$1, coerce),
1817
- fallbackHtml: rebuild(root.children, FALLBACK$1)
1818
- };
1819
- },
1820
- isOwnScript: (src) => SCRIPT$5.test(src),
1821
- match(url) {
1822
- const found = post$2(url);
1823
- return found && {
1824
- ...found,
1825
- options: {}
1826
- };
1827
- }
1828
- };
1829
- // src/parser/platforms/tiktok.ts
1830
- const HOSTS$4 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
1831
- const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
1832
- const PLAYER_PATH$1 = /^\/player\/v1\/(\d{1,25})\/?$/;
1833
- const VIDEO_ID$1 = /^\d{1,25}$/;
1834
- const SCRIPT$4 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
1835
- function video$2(id, user = "", options = {}) {
1836
- return {
1837
- platform: "tiktok",
1838
- kind: "video",
1839
- url: `https://www.tiktok.com/@${user}/video/${id}`,
1840
- id,
1841
- variant: "iframe",
1842
- options
1843
- };
1844
- }
1845
- const tiktok = {
1846
- platform: "tiktok",
1847
- parse(root) {
1848
- if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
1849
- const cite = parseUrl(root.attrs.get("cite") ?? "");
1850
- const [, user, citeId] = cite && HOSTS$4.has(cite.host) ? VIDEO_PATH.exec(cite.path) ?? [] : [];
1851
- const dataId = root.attrs.get("data-video-id");
1852
- if (dataId !== void 0 && !VIDEO_ID$1.test(dataId)) return null;
1853
- if (dataId !== void 0 && citeId !== void 0 && dataId !== citeId) return null;
1854
- const id = dataId ?? citeId;
1855
- return id === void 0 ? null : video$2(id, user);
1856
- }
1857
- if (root.tag !== "iframe") return null;
1858
- const src = parseUrl(root.attrs.get("src") ?? "");
1859
- if (!src || !HOSTS$4.has(src.host)) return null;
1860
- const [, id] = PLAYER_PATH$1.exec(src.path) ?? [];
1861
- if (id === void 0) return null;
1862
- return withSize(video$2(id, "", Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
1863
- },
1864
- isOwnScript: (src) => SCRIPT$4.test(src),
1865
- match(url) {
1866
- if (!HOSTS$4.has(url.host)) return null;
1867
- const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
1868
- return user === void 0 || id === void 0 ? null : video$2(id, user);
1869
- },
1870
- ownsFrame: (src) => HOSTS$4.has(src.host) && underPath(src.path, "/player")
1871
- };
1872
- // src/parser/platforms/truthsocial.ts
1873
- const HOSTS$3 = /* @__PURE__ */ new Set(["truthsocial.com", "www.truthsocial.com"]);
1874
- const USER = "(@[A-Za-z0-9_.-]{1,64})";
1875
- const ID = "(\\d{1,25})";
1876
- const POST_PATH = new RegExp(`^/${USER}/(?:posts/)?${ID}/?$`);
1877
- const FRAME_PATH$1 = new RegExp(`^/${USER}/${ID}/embed$`);
1878
- const SCRIPT$3 = /^(?:https?:)?\/\/truthsocial\.com\/embed\.js$/;
1879
- function post$1(user, id) {
1880
- return {
1881
- platform: "truthsocial",
1882
- kind: "post",
1883
- url: `https://truthsocial.com/${user}/posts/${id}`,
1884
- id,
1885
- variant: "iframe"
1886
- };
1887
- }
1888
- function fromUrl$1(url) {
1889
- if (!url || !HOSTS$3.has(url.host)) return null;
1890
- const [, user, id] = POST_PATH.exec(url.path) ?? [];
1891
- return user === void 0 || id === void 0 ? null : post$1(user, id);
1892
- }
1893
- const truthsocial = {
1894
- platform: "truthsocial",
1895
- parse(root) {
1896
- if (root.tag !== "iframe") return null;
1897
- const src = parseUrl(root.attrs.get("src") ?? "");
1898
- if (!src || src.host !== "truthsocial.com") return null;
1899
- const [, user, id] = FRAME_PATH$1.exec(src.path) ?? [];
1900
- if (user === void 0 || id === void 0) return null;
1901
- const options = hasClass(root, "truthsocial-video") ? { video: true } : {};
1902
- return withSize({
1903
- ...post$1(user, id),
1904
- options
1905
- }, sizeOf(root));
1906
- },
1907
- isOwnScript: (src) => SCRIPT$3.test(src),
1908
- match(url) {
1909
- const found = fromUrl$1(url);
1910
- return found && {
1911
- ...found,
1912
- options: {}
1913
- };
1914
- },
1915
- ownsFrame: (src) => src.host === "truthsocial.com" && src.path.startsWith("/@")
1916
- };
1917
- // src/parser/platforms/tumblr.ts
1918
- const BLOG = "([a-z0-9-]{1,32})";
1919
- const POST = "(\\d{1,20})";
1920
- const WWW_HOSTS = /* @__PURE__ */ new Set(["www.tumblr.com", "tumblr.com"]);
1921
- const WWW_PATH = new RegExp(`^/${BLOG}/${POST}(?:/[^/]{1,200})?/?$`);
1922
- const BLOG_HOST = new RegExp(`^${BLOG}\\.tumblr\\.com$`);
1923
- const BLOG_PATH = new RegExp(`^/post/${POST}(?:/[^/]{1,200})?/?$`);
1924
- const FRAME_PATH = new RegExp(`^/embed/post/(?:t:[A-Za-z0-9_-]{1,64}|${BLOG})/${POST}/v2$`);
1925
- const NOT_BLOGS = /* @__PURE__ */ new Set([
1926
- "dashboard",
1927
- "explore",
1928
- "tagged",
1929
- "search",
1930
- "settings",
1931
- "blog",
1932
- "www",
1933
- "assets",
1934
- "embed",
1935
- "api",
1936
- "help"
1937
- ]);
1938
- const SCRIPT$2 = /^(?:https?:)?\/\/assets\.tumblr\.com\/post\.js(?:\?[^#]*)?$/;
1939
- function fromUrl(url) {
1940
- if (!url) return null;
1941
- let blog;
1942
- let id;
1943
- if (WWW_HOSTS.has(url.host)) [, blog, id] = WWW_PATH.exec(url.path) ?? [];
1944
- else {
1945
- [, blog] = BLOG_HOST.exec(url.host) ?? [];
1946
- [, id] = BLOG_PATH.exec(url.path) ?? [];
1947
- }
1948
- if (blog === void 0 || id === void 0 || NOT_BLOGS.has(blog)) return null;
1949
- return {
1950
- platform: "tumblr",
1951
- kind: "post",
1952
- url: `https://www.tumblr.com/${blog}/${id}`,
1953
- id,
1954
- variant: "iframe"
1955
- };
1956
- }
1957
- const tumblr = {
1958
- platform: "tumblr",
1959
- parse(root) {
1960
- if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
1961
- const frame = parseUrl(root.attrs.get("data-href") ?? "");
1962
- if (frame?.host !== "embed.tumblr.com") return null;
1963
- const [, frameBlog, framePost] = FRAME_PATH.exec(frame.path) ?? [];
1964
- if (framePost === void 0) return null;
1965
- const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
1966
- if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
1967
- const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
1968
- if (found?.id !== framePost) return null;
1969
- if (frameBlog !== void 0 && found.url !== `https://www.tumblr.com/${frameBlog}/${framePost}`) return null;
1970
- return {
1971
- ...found,
1972
- options: {}
1973
- };
1974
- },
1975
- isOwnScript: (src) => SCRIPT$2.test(src),
1976
- match(url) {
1977
- const found = fromUrl(url);
1978
- return found && {
1979
- ...found,
1980
- options: {}
1981
- };
1982
- }
1983
- };
1984
- // src/parser/platforms/twitch.ts
1985
- const HOSTS$2 = /* @__PURE__ */ new Set([
1986
- "twitch.tv",
1987
- "www.twitch.tv",
1988
- "m.twitch.tv"
1989
- ]);
1990
- const PLAYER_HOST$1 = "player.twitch.tv";
1991
- const CLIPS_HOST = "clips.twitch.tv";
1992
- const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
1993
- const VIDEO$1 = /^v?(\d{1,12})$/;
1994
- const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
1995
- const CLIP = /^[A-Za-z0-9_-]{6,100}$/;
1996
- const TIME = /^(?:\d+h)?(?:\d+m)?(?:\d+s)?$/;
1997
- const RESERVED = /* @__PURE__ */ new Set([
1998
- "directory",
1999
- "videos",
2000
- "collections",
2001
- "settings",
2002
- "subscriptions",
2003
- "inventory",
2004
- "wallet",
2005
- "drops",
2006
- "search",
2007
- "downloads",
2008
- "jobs",
2009
- "turbo",
2010
- "p",
2011
- "login",
2012
- "signup"
2013
- ]);
2014
- const PLAYER_OPTIONS = [
2015
- "autoplay",
2016
- "muted",
2017
- "time"
2018
- ];
2019
- function target(path, id) {
2020
- return {
2021
- platform: "twitch",
2022
- kind: "video",
2023
- url: path,
2024
- id,
2025
- variant: "iframe"
2026
- };
2027
- }
2028
- const channel = (name) => target(`https://www.twitch.tv/${name.toLowerCase()}`, name.toLowerCase());
2029
- const vod = (id) => target(`https://www.twitch.tv/videos/${id}`, id);
2030
- const collection = (id) => target(`https://www.twitch.tv/collections/${id}`, id);
2031
- const clip = (slug) => target(`https://clips.twitch.tv/${slug}`, slug);
2032
- function playerOptions(query) {
2033
- const options = {};
2034
- for (const name of PLAYER_OPTIONS) {
2035
- const value = query.get(name);
2036
- if (value !== void 0) options[name] = coerce(value);
2037
- }
2038
- return options;
2039
- }
2040
- /** The player's own precedence: channel, then video, then collection. */
2041
- function fromPlayer$1(url) {
2042
- const name = url.query.get("channel");
2043
- if (name !== void 0) return CHANNEL.test(name) ? channel(name) : null;
2044
- const [, id] = VIDEO$1.exec(url.query.get("video") ?? "") ?? [];
2045
- if (id !== void 0) return vod(id);
2046
- const list = url.query.get("collection");
2047
- return list !== void 0 && COLLECTION.test(list) ? collection(list) : null;
2048
- }
2049
- function fromPage(url) {
2050
- if (url.host === CLIPS_HOST) {
2051
- const slug = url.path.replace(/^\/|\/$/g, "");
2052
- return CLIP.test(slug) ? {
2053
- found: clip(slug),
2054
- options: {}
2055
- } : null;
2056
- }
2057
- if (!HOSTS$2.has(url.host)) return null;
2058
- const parts = url.path.replace(/^\/|\/$/g, "").split("/");
2059
- const [first = "", second, third] = parts;
2060
- if (parts.length === 2 && first === "videos") {
2061
- const [, id] = VIDEO$1.exec(second ?? "") ?? [];
2062
- if (id === void 0) return null;
2063
- const time = url.query.get("t");
2064
- return {
2065
- found: vod(id),
2066
- options: time !== void 0 && TIME.test(time) && time ? { time } : {}
2067
- };
2068
- }
2069
- if (parts.length === 2 && first === "collections") return COLLECTION.test(second ?? "") ? {
2070
- found: collection(second ?? ""),
2071
- options: {}
2072
- } : null;
2073
- if (parts.length === 3 && second === "clip") return CHANNEL.test(first) && CLIP.test(third ?? "") ? {
2074
- found: clip(third ?? ""),
2075
- options: {}
2076
- } : null;
2077
- if (parts.length === 1 && CHANNEL.test(first) && !RESERVED.has(first.toLowerCase())) return {
2078
- found: channel(first),
2079
- options: {}
2080
- };
2081
- return null;
2082
- }
2083
- const twitch = {
2084
- platform: "twitch",
2085
- parse(root) {
2086
- if (root.tag !== "iframe") return null;
2087
- const src = parseUrl(root.attrs.get("src") ?? "");
2088
- if (!src) return null;
2089
- let found = null;
2090
- if (src.host === PLAYER_HOST$1 && /^\/?$/.test(src.path)) found = fromPlayer$1(src);
2091
- if (src.host === CLIPS_HOST && src.path === "/embed") {
2092
- const slug = src.query.get("clip") ?? "";
2093
- found = CLIP.test(slug) ? clip(slug) : null;
2094
- }
2095
- return found && withSize({
2096
- ...found,
2097
- options: playerOptions(src.query)
2098
- }, sizeOf(root));
2099
- },
2100
- isOwnScript: () => false,
2101
- match(url) {
2102
- const page = fromPage(url);
2103
- return page && {
2104
- ...page.found,
2105
- options: page.options
2106
- };
2107
- },
2108
- ownsFrame: (src) => src.host === PLAYER_HOST$1 || src.host === CLIPS_HOST && underPath(src.path, "/embed")
2109
- };
2110
- // src/parser/platforms/vimeo.ts
2111
- const HOSTS$1 = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
2112
- const VIDEO = "(\\d{1,12})";
2113
- const HASH = "([0-9a-f]{6,20})";
2114
- const PAGE_PATHS = [
2115
- new RegExp(`^/${VIDEO}(?:/${HASH})?/?$`),
2116
- new RegExp(`^/channels/[A-Za-z0-9_-]{1,64}/${VIDEO}/?$`),
2117
- new RegExp(`^/groups/[A-Za-z0-9_-]{1,64}/videos/${VIDEO}/?$`),
2118
- new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
2119
- ];
2120
- const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
2121
- const WRAPPER$1 = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
2122
- const SCRIPT$1 = /^(?:https?:)?\/\/player\.vimeo\.com\/api\/player\.js$/;
2123
- const DROPPED = /* @__PURE__ */ new Set([
2124
- "h",
2125
- "app_id",
2126
- "player_id"
2127
- ]);
2128
- const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
2129
- const PLAYER_HOST = "player.vimeo.com";
2130
- function video$1(id, hash) {
2131
- return {
2132
- platform: "vimeo",
2133
- kind: "video",
2134
- url: `https://vimeo.com/${id}${hash ? `/${hash}` : ""}`,
2135
- id,
2136
- variant: "iframe"
2137
- };
2138
- }
2139
- function start(url) {
2140
- const [, time] = START.exec(url.fragment ?? "") ?? [];
2141
- return time ? { t: time } : {};
2142
- }
2143
- function fromPlayer(url) {
2144
- if (url?.host !== PLAYER_HOST) return null;
2145
- const [, id] = PLAYER_PATH.exec(url.path) ?? [];
2146
- if (id === void 0) return null;
2147
- const hash = url.query.get("h");
2148
- if (hash !== void 0 && !new RegExp(`^${HASH}$`).test(hash)) return null;
2149
- const options = Object.fromEntries([...url.query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
2150
- return {
2151
- ...video$1(id, hash),
2152
- options: {
2153
- ...options,
2154
- ...start(url)
2155
- }
2156
- };
2157
- }
2158
- const vimeo = {
2159
- platform: "vimeo",
2160
- parse(root) {
2161
- const wrapped = unwrapRatio(root, WRAPPER$1);
2162
- const iframe = wrapped?.iframe ?? root;
2163
- if (iframe.tag !== "iframe") return null;
2164
- const embed = fromPlayer(parseUrl(iframe.attrs.get("src") ?? ""));
2165
- return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
2166
- },
2167
- isOwnScript: (src) => SCRIPT$1.test(src),
2168
- match(url) {
2169
- const player = fromPlayer(url);
2170
- if (player) return player;
2171
- if (!HOSTS$1.has(url.host)) return null;
2172
- for (const path of PAGE_PATHS) {
2173
- const [, id, hash] = path.exec(url.path) ?? [];
2174
- if (id !== void 0) return {
2175
- ...video$1(id, hash),
2176
- options: start(url)
2177
- };
2178
- }
2179
- return null;
2180
- },
2181
- ownsFrame: (src) => src.host === PLAYER_HOST
2182
- };
2183
- // src/parser/platforms/x.ts
2184
- const HOSTS = /* @__PURE__ */ new Set([
2185
- "x.com",
2186
- "www.x.com",
2187
- "mobile.x.com",
2188
- "twitter.com",
2189
- "www.twitter.com",
2190
- "mobile.twitter.com"
2191
- ]);
2192
- const STATUS_PATH = /^\/([A-Za-z0-9_]{1,15})\/status\/(\d{1,20})\/?$/;
2193
- const SCRIPT = /^(?:https?:)?\/\/platform\.(?:x|twitter)\.com\/widgets\.js$/;
2194
- const OPTION_ATTRIBUTES = [
2195
- ["data-theme", "theme"],
2196
- ["data-conversation", "conversation"],
2197
- ["data-cards", "cards"],
2198
- ["data-align", "align"],
2199
- ["align", "align"],
2200
- ["data-lang", "lang"],
2201
- ["data-dnt", "dnt"],
2202
- ["data-width", "width"]
2203
- ];
2204
- const FALLBACK = /* @__PURE__ */ new Map([
2205
- ["p", ["lang", "dir"]],
2206
- ["a", ["href"]],
2207
- ["br", []]
2208
- ]);
2209
- function post(url) {
2210
- if (!url || !HOSTS.has(url.host)) return null;
2211
- const [, user, id] = STATUS_PATH.exec(url.path) ?? [];
2212
- if (user === void 0 || id === void 0) return null;
2213
- return {
2214
- platform: "x",
2215
- kind: "post",
2216
- url: `https://x.com/${user}/status/${id}`,
2217
- id,
2218
- variant: "sdk"
2219
- };
2220
- }
2221
- const x = {
2222
- platform: "x",
2223
- fallback: FALLBACK,
2224
- parse(root) {
2225
- if (root.tag !== "blockquote" || !hasClass(root, "twitter-tweet")) return null;
2226
- const status = descendants(root.children).reverse().map((element) => element.tag === "a" ? post(parseUrl(element.attrs.get("href") ?? "")) : null).find((found) => found !== null);
2227
- if (!status) return null;
2228
- return {
2229
- ...status,
2230
- options: attributeOptions(root, OPTION_ATTRIBUTES, coerce),
2231
- fallbackHtml: rebuild(root.children, FALLBACK)
2232
- };
2233
- },
2234
- isOwnScript: (src) => SCRIPT.test(src),
2235
- match(url) {
2236
- const status = post(url);
2237
- return status && {
2238
- ...status,
2239
- options: {}
2240
- };
2241
- }
2242
- };
2243
- // src/parser/platforms/youtube.ts
2244
- const YOUTUBE_HOSTS = /* @__PURE__ */ new Set([
2245
- "youtube.com",
2246
- "www.youtube.com",
2247
- "m.youtube.com"
2248
- ]);
2249
- const NOCOOKIE_HOSTS = /* @__PURE__ */ new Set(["youtube-nocookie.com", "www.youtube-nocookie.com"]);
2250
- const VIDEO_ID = /^(?!videoseries)[A-Za-z0-9_-]{11}$/;
2251
- const EMBED_PATH = /^\/embed\/((?!videoseries)[A-Za-z0-9_-]{11})\/?$/;
2252
- const URL_PATHS = /^\/(shorts|embed|live)\/((?!videoseries)[A-Za-z0-9_-]{11})\/?$/;
2253
- const SHORT_LINK_PATH = /^\/([A-Za-z0-9_-]{11})\/?$/;
2254
- const DURATION = /^(?:(\d{1,5})h)?(?:(\d{1,6})m)?(?:(\d{1,7})s?)?$/;
2255
- /** `90`, `90s`, `1m30s`, `1h2m3s` → seconds. */
2256
- function seconds(value) {
2257
- if (value === void 0 || value === "") return void 0;
2258
- const match = DURATION.exec(value);
2259
- if (!match) return void 0;
2260
- const [, hours = "0", minutes = "0", secs = "0"] = match;
2261
- return Number(hours) * 3600 + Number(minutes) * 60 + Number(secs);
2262
- }
2263
- /** `start` wins over `t`; `t` is converted, because the embed player only reads `start`. */
2264
- function startOf(query) {
2265
- return seconds(query.get("start")) ?? seconds(query.get("t"));
2266
- }
2267
- function video(id, shorts = false) {
2268
- return {
2269
- platform: "youtube",
2270
- kind: "video",
2271
- url: shorts ? `https://www.youtube.com/shorts/${id}` : `https://www.youtube.com/watch?v=${id}`,
2272
- id,
2273
- variant: "iframe"
2274
- };
2275
- }
2276
- function urlOptions(url, nocookie) {
2277
- const start = startOf(url.query);
2278
- return {
2279
- ...start === void 0 ? {} : { start },
2280
- ...nocookie ? { nocookie: true } : {}
2281
- };
2282
- }
2283
- // src/parser/platforms/index.ts
2284
- const platforms = [
2285
- x,
2286
- instagram,
2287
- facebook,
2288
- threads,
2289
- tiktok,
2290
- {
2291
- platform: "youtube",
2292
- parse(root) {
2293
- if (root.tag !== "iframe") return null;
2294
- const src = parseUrl(root.attrs.get("src") ?? "");
2295
- const nocookie = src !== null && NOCOOKIE_HOSTS.has(src.host);
2296
- if (!src || !(nocookie || YOUTUBE_HOSTS.has(src.host))) return null;
2297
- const [, id] = EMBED_PATH.exec(src.path) ?? [];
2298
- if (id === void 0) return null;
2299
- const entries = [...src.query].filter(([key]) => key !== "t").map(([key, value]) => [key, coerce(value)]);
2300
- const options = Object.fromEntries(entries);
2301
- const start = startOf(src.query);
2302
- if (start !== void 0) options.start = start;
2303
- if (nocookie) options.nocookie = true;
2304
- return withSize({
2305
- ...video(id),
2306
- options
2307
- }, sizeOf(root));
2308
- },
2309
- isOwnScript: () => false,
2310
- match(url) {
2311
- if (url.host === "youtu.be") {
2312
- const [, id] = SHORT_LINK_PATH.exec(url.path) ?? [];
2313
- return id === void 0 ? null : {
2314
- ...video(id),
2315
- options: urlOptions(url, false)
2316
- };
2317
- }
2318
- const nocookie = NOCOOKIE_HOSTS.has(url.host);
2319
- if (!nocookie && !YOUTUBE_HOSTS.has(url.host)) return null;
2320
- if (!nocookie && /^\/watch\/?$/.test(url.path)) {
2321
- const id = url.query.get("v");
2322
- return id !== void 0 && VIDEO_ID.test(id) ? {
2323
- ...video(id),
2324
- options: urlOptions(url, false)
2325
- } : null;
2326
- }
2327
- const [, kind, id] = URL_PATHS.exec(url.path) ?? [];
2328
- if (kind === void 0 || id === void 0) return null;
2329
- if (nocookie && kind !== "embed") return null;
2330
- return {
2331
- ...video(id, kind === "shorts"),
2332
- options: urlOptions(url, nocookie)
2333
- };
2334
- },
2335
- ownsFrame: (src) => NOCOOKIE_HOSTS.has(src.host) || YOUTUBE_HOSTS.has(src.host) && underPath(src.path, "/embed")
2336
- },
2337
- telegram,
2338
- snapchat,
2339
- linkedin,
2340
- reddit,
2341
- pinterest,
2342
- spotify,
2343
- vimeo,
2344
- twitch,
2345
- dailymotion,
2346
- soundcloud,
2347
- applemusic,
2348
- applepodcasts,
2349
- kick,
2350
- giphy,
2351
- tenor,
2352
- streamable,
2353
- rumble,
2354
- truthsocial,
2355
- imgur,
2356
- strava,
2357
- flickr,
2358
- bluesky,
2359
- tumblr
2360
- ];
2361
- // src/parser/iframe.ts
2362
- const REFERRER_POLICIES = [
2363
- "no-referrer",
2364
- "origin",
2365
- "same-origin",
2366
- "strict-origin",
2367
- "strict-origin-when-cross-origin"
2368
- ];
2369
- const SANDBOX_KEYWORDS = /* @__PURE__ */ new Set([
2370
- "allow-downloads",
2371
- "allow-forms",
2372
- "allow-modals",
2373
- "allow-orientation-lock",
2374
- "allow-pointer-lock",
2375
- "allow-popups",
2376
- "allow-popups-to-escape-sandbox",
2377
- "allow-presentation",
2378
- "allow-same-origin",
2379
- "allow-scripts",
2380
- "allow-top-navigation",
2381
- "allow-top-navigation-by-user-activation",
2382
- "allow-top-navigation-to-custom-protocols"
2383
- ]);
2384
- const FEATURES = /* @__PURE__ */ new Set([
2385
- "autoplay",
2386
- "fullscreen",
2387
- "encrypted-media",
2388
- "picture-in-picture",
2389
- "clipboard-write",
2390
- "web-share"
2391
- ]);
2392
- const HOST = "[a-z0-9-]+(?:\\.[a-z0-9-]+)*(?::\\d{1,5})?";
2393
- const SRC = new RegExp(`^(?:https:)?//${HOST}(?:[/?#]|$)`, "i");
2394
- const ORIGIN = new RegExp(`^(?:\\*|'self'|'src'|'none'|https://${HOST})$`, "i");
2395
- const REWRITTEN_PATH = /\/\.{1,2}(?:\/|$)|\/\/|%(?:2[de]|3\d|[46][1-9a-f]|[57][\da]|5f|7e)/i;
2396
- const ASCII_WHITESPACE = /[\t\n\f\r ]+/;
2397
- const STYLE_SIZE = /^\s*(width|height)\s*:(.*)$/is;
2398
- const PX = /^(\d+)px$/i;
2399
- const WRAPPER = /(?:^|;)\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,20})?)%\s*(?:;|$)/i;
2400
- /**
2401
- * Never throws. `null` unless the code holds exactly one `<iframe>` with an https `src` that no
2402
- * named platform owns; everything around the iframe is dropped.
2403
- */
2404
- function parseIframe(html) {
2405
- if (typeof html !== "string") return null;
2406
- const nodes = parseHtml(html);
2407
- if (!nodes) return null;
2408
- const elements = descendants(nodes);
2409
- const [iframe, ...others] = elements.filter((element) => element.tag === "iframe");
2410
- if (!iframe || others.length > 0) return null;
2411
- const parent = elements.find((element) => element.children.includes(iframe));
2412
- const { attrs } = iframe;
2413
- const size = sizeOf(iframe) ?? styleSize(iframe);
2414
- return check({
2415
- src: attrs.get("src"),
2416
- title: attrs.get("title"),
2417
- allow: attrs.get("allow"),
2418
- allowFullscreen: attrs.has("allowfullscreen"),
2419
- referrerPolicy: attrs.get("referrerpolicy"),
2420
- sandbox: attrs.get("sandbox"),
2421
- scrolling: attrs.get("scrolling"),
2422
- size: size ?? {},
2423
- ratio: size ? void 0 : parent && unwrapRatio(parent, WRAPPER)?.size
2424
- });
2425
- }
2426
- /** Re-checks a value a host built or stored; `null` when its `src` is unsafe or a named platform's. */
2427
- function checkIframe(embed) {
2428
- return check(embed);
2429
- }
2430
- function check(value) {
2431
- if (typeof value !== "object" || value === null) return null;
2432
- const raw = value;
2433
- const src = checkSrc(raw.src);
2434
- if (src === null) return null;
2435
- const title = typeof raw.title === "string" ? raw.title.trim() : "";
2436
- const policy = typeof raw.referrerPolicy === "string" ? raw.referrerPolicy.toLowerCase() : void 0;
2437
- const referrerPolicy = REFERRER_POLICIES.find((keyword) => keyword === policy);
2438
- const ratio = checkRatio(raw.ratio);
2439
- return {
2440
- src,
2441
- ...title ? { title } : {},
2442
- allow: typeof raw.allow === "string" ? checkAllow(raw.allow) : "",
2443
- allowFullscreen: raw.allowFullscreen === true,
2444
- ...referrerPolicy ? { referrerPolicy } : {},
2445
- ...typeof raw.sandbox === "string" ? { sandbox: checkSandbox(raw.sandbox) } : {},
2446
- ...typeof raw.scrolling === "string" && raw.scrolling.toLowerCase() === "no" ? { scrolling: "no" } : {},
2447
- size: checkSize(raw.size),
2448
- ...ratio ? { ratio } : {}
2449
- };
2450
- }
2451
- function checkSrc(value) {
2452
- if (typeof value !== "string") return null;
2453
- const src = value.trim();
2454
- const url = SRC.test(src) && !src.includes("\\") ? parseUrl(src) : null;
2455
- if (!url || REWRITTEN_PATH.test(url.path)) return null;
2456
- const frame = {
2457
- ...url,
2458
- host: url.host.replace(/:\d+$/, ""),
2459
- path: (url.path.toLowerCase().split(";")[0] ?? "").replaceAll("%2f", "/")
2460
- };
2461
- if (platforms.some((platform) => platform.ownsFrame?.(frame))) return null;
2462
- return src.startsWith("//") ? `https:${src}` : src;
2463
- }
2464
- /** A feature keeps its origin list as written, or is dropped whole when one origin is not safe. */
2465
- function checkAllow(value) {
2466
- return value.split(";").map((directive) => directive.split(ASCII_WHITESPACE).filter(Boolean)).filter(([feature, ...origins]) => feature !== void 0 && FEATURES.has(feature) && origins.every((origin) => ORIGIN.test(origin))).map((tokens) => tokens.join(" ")).join("; ");
2467
- }
2468
- function checkSandbox(value) {
2469
- const keywords = value.split(ASCII_WHITESPACE).map((token) => token.toLowerCase()).filter((token) => SANDBOX_KEYWORDS.has(token));
2470
- return [...new Set(keywords)].join(" ");
2471
- }
2472
- function checkRatio(value) {
2473
- if (typeof value !== "object" || value === null) return void 0;
2474
- const { width, height } = value;
2475
- return isPositive(width) && isPositive(height) ? {
2476
- width,
2477
- height
2478
- } : void 0;
2479
- }
2480
- function isPositive(value) {
2481
- return typeof value === "number" && Number.isFinite(value) && value > 0;
2482
- }
2483
- function checkSize(value) {
2484
- if (typeof value !== "object" || value === null) return {};
2485
- const { width, height } = value;
2486
- const checkedWidth = typeof width === "number" ? pixels(String(width)) : void 0;
2487
- const checkedHeight = typeof height === "number" ? pixels(String(height)) : void 0;
2488
- return {
2489
- ...checkedWidth === void 0 ? {} : { width: checkedWidth },
2490
- ...checkedHeight === void 0 ? {} : { height: checkedHeight }
2491
- };
2492
- }
2493
- function styleSize(iframe) {
2494
- let width;
2495
- let height;
2496
- for (const declaration of (iframe.attrs.get("style") ?? "").split(";")) {
2497
- const [, name = "", value = ""] = STYLE_SIZE.exec(declaration) ?? [];
2498
- const px = pixels(PX.exec(value.trim())?.[1]);
2499
- if (name.toLowerCase() === "width") width = px;
2500
- if (name.toLowerCase() === "height") height = px;
2501
- }
2502
- return width === void 0 && height === void 0 ? void 0 : {
2503
- width,
2504
- height
2505
- };
2506
- }
2507
- // src/parser/match-url.ts
2508
- /** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
2509
- function matchUrl(url) {
2510
- if (typeof url !== "string") return null;
2511
- const parsed = parseUrl(url);
2512
- if (!parsed) return null;
2513
- for (const platform of platforms) {
2514
- const embed = platform.match(parsed);
2515
- if (embed) return embed;
2516
- }
2517
- return null;
2518
- }
2519
- // src/parser/parse-embed.ts
2520
- /**
2521
- * Never throws. `null` unless the input is one embed element plus, at most, the platform's
2522
- * own scripts, `<div id="fb-root">`, one platform-owned extra such as a credit, whitespace and
2523
- * comments (docs/decisions.md D14).
2524
- */
2525
- function parseEmbed(html) {
2526
- if (typeof html !== "string") return null;
2527
- const nodes = parseHtml(html);
2528
- return nodes ? parseNodes(nodes) : parseRepaired(html);
2529
- }
2530
- function parseRepaired(html) {
2531
- for (const platform of platforms) {
2532
- const repaired = platform.repair?.(html);
2533
- const nodes = repaired === void 0 || repaired === null ? null : parseHtml(repaired);
2534
- const embed = nodes && parseNodes(nodes);
2535
- if (embed?.platform === platform.platform) return embed;
2536
- }
2537
- return null;
2538
- }
2539
- function parseNodes(nodes) {
2540
- let root;
2541
- let extra;
2542
- const scripts = [];
2543
- let fbRoot = false;
2544
- for (const node of nodes) {
2545
- if (node.type === "comment") continue;
2546
- if (node.type === "text") {
2547
- if (/^\s*$/.test(node.raw)) continue;
2548
- return null;
2549
- }
2550
- if (node.tag === "script") scripts.push(node);
2551
- else if (isFbRoot(node)) fbRoot = true;
2552
- else if (root) {
2553
- if (extra) return null;
2554
- extra = node;
2555
- } else root = node;
2556
- }
2557
- if (!root) {
2558
- const [script] = scripts;
2559
- if (fbRoot || scripts.length !== 1 || !script) return null;
2560
- if (script.children.length !== 0) return null;
2561
- for (const platform of platforms) {
2562
- const embed = platform.parseScript?.(script);
2563
- if (embed) return embed;
2564
- }
2565
- return null;
2566
- }
2567
- for (const platform of platforms) {
2568
- const embed = platform.parse(root);
2569
- if (!embed) continue;
2570
- if (fbRoot && !platform.allowsFbRoot) return null;
2571
- if (extra && !platform.isOwnExtra?.(extra, embed)) return null;
2572
- const sources = scripts.map((script) => script.children.length === 0 ? script.attrs.get("src") : void 0);
2573
- if (!sources.every((src) => src !== void 0 && platform.isOwnScript(src))) return null;
2574
- const fromScripts = sources.map((src) => src === void 0 ? {} : platform.scriptOptions?.(src) ?? {});
2575
- return {
2576
- ...embed,
2577
- options: Object.assign({}, ...fromScripts, embed.options)
2578
- };
2579
- }
2580
- return null;
2581
- }
2582
- function isFbRoot(element) {
2583
- return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
2584
- }
2585
- export { platforms as a, escapeAttribute as c, parseIframe as i, parseHtml as l, matchUrl as n, x as o, checkIframe as r, parseUrl as s, parseEmbed as t, rebuild as u };