social-embeds 0.2.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +174 -44
- package/dist/{index-DCF8EEVz.d.ts → index-CSSlJIJU.d.ts} +1 -1
- package/dist/index.d.ts +105 -3
- package/dist/index.js +773 -255
- package/dist/{parser-BrlUKvvo.js → parser-D7a5KPhN.js} +739 -104
- package/dist/parser.d.ts +1 -1
- package/dist/parser.js +1 -1
- package/package.json +5 -5
|
@@ -1,3 +1,150 @@
|
|
|
1
|
+
// src/parser/url.ts
|
|
2
|
+
const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#(\S*))?$/i;
|
|
3
|
+
/** Absolute or protocol-relative http(s) URLs only. */
|
|
4
|
+
function parseUrl(input) {
|
|
5
|
+
const match = URL_PATTERN.exec(input.trim());
|
|
6
|
+
if (!match) return null;
|
|
7
|
+
const [, host = "", path = "", search = "", fragment] = match;
|
|
8
|
+
const query = /* @__PURE__ */ new Map();
|
|
9
|
+
for (const pair of search.split("&")) {
|
|
10
|
+
if (pair === "") continue;
|
|
11
|
+
const eq = pair.indexOf("=");
|
|
12
|
+
const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
|
|
13
|
+
const value = decodeComponent(eq === -1 ? "" : pair.slice(eq + 1));
|
|
14
|
+
if (key === null || value === null) return null;
|
|
15
|
+
if (!query.has(key)) query.set(key, value);
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
host: host.toLowerCase(),
|
|
19
|
+
path,
|
|
20
|
+
query,
|
|
21
|
+
...fragment ? { fragment } : {}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
function decodeComponent(component) {
|
|
25
|
+
try {
|
|
26
|
+
return decodeURIComponent(component.replace(/\+/g, " "));
|
|
27
|
+
} catch {
|
|
28
|
+
return null;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
/** Types an option value: booleans, canonical integers, otherwise the string as given. */
|
|
32
|
+
function coerce(value) {
|
|
33
|
+
if (value === "true") return true;
|
|
34
|
+
if (value === "false") return false;
|
|
35
|
+
if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
|
|
36
|
+
return value;
|
|
37
|
+
}
|
|
38
|
+
function pixels(value) {
|
|
39
|
+
return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
|
|
40
|
+
}
|
|
41
|
+
// src/parser/platform.ts
|
|
42
|
+
/** The first attribute present for a key wins. */
|
|
43
|
+
function attributeOptions(element, mapping, coerceValue) {
|
|
44
|
+
const options = {};
|
|
45
|
+
for (const [attribute, key] of mapping) {
|
|
46
|
+
const value = element.attrs.get(attribute);
|
|
47
|
+
if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
|
|
48
|
+
}
|
|
49
|
+
return options;
|
|
50
|
+
}
|
|
51
|
+
function sizeOf(element) {
|
|
52
|
+
const width = pixels(element.attrs.get("width"));
|
|
53
|
+
const height = pixels(element.attrs.get("height"));
|
|
54
|
+
if (width === void 0 && height === void 0) return void 0;
|
|
55
|
+
return {
|
|
56
|
+
...width === void 0 ? {} : { width },
|
|
57
|
+
...height === void 0 ? {} : { height }
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
/** Adds `size` only when known, so results stay free of `undefined` properties. */
|
|
61
|
+
function withSize(embed, size) {
|
|
62
|
+
return size ? {
|
|
63
|
+
...embed,
|
|
64
|
+
size
|
|
65
|
+
} : embed;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* A platform's own responsive wrapper: a `div` whose only attribute is a `style` that `pattern`
|
|
69
|
+
* matches, around one iframe. The padding percentage it captures is the video's ratio.
|
|
70
|
+
*/
|
|
71
|
+
function unwrapRatio(root, pattern) {
|
|
72
|
+
if (root.tag !== "div" || root.attrs.size !== 1) return null;
|
|
73
|
+
const [, percent] = pattern.exec(root.attrs.get("style") ?? "") ?? [];
|
|
74
|
+
if (percent === void 0) return null;
|
|
75
|
+
let iframe;
|
|
76
|
+
for (const child of root.children) {
|
|
77
|
+
if (child.type === "text" && /^\s*$/.test(child.raw)) continue;
|
|
78
|
+
if (child.type !== "element" || child.tag !== "iframe" || iframe) return null;
|
|
79
|
+
iframe = child;
|
|
80
|
+
}
|
|
81
|
+
const height = Math.round(Number(percent) * 100);
|
|
82
|
+
if (!iframe || !(height > 0 && height <= 1e5)) return null;
|
|
83
|
+
const divisor = gcd(1e4, height);
|
|
84
|
+
return {
|
|
85
|
+
iframe,
|
|
86
|
+
size: {
|
|
87
|
+
width: 1e4 / divisor,
|
|
88
|
+
height: height / divisor
|
|
89
|
+
}
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
function gcd(a, b) {
|
|
93
|
+
return b === 0 ? a : gcd(b, a % b);
|
|
94
|
+
}
|
|
95
|
+
// src/parser/platforms/dailymotion.ts
|
|
96
|
+
const VIDEO_ID$2 = /^x[a-z0-9]{4,12}$/;
|
|
97
|
+
const PLAYER_ID = /^x[a-z0-9]{3,12}$/;
|
|
98
|
+
const WRAPPER$1 = /^position:\s*relative;\s*padding-bottom:\s*(\d{1,3}(?:\.\d{1,4})?)%;\s*height:\s*0;\s*overflow:\s*hidden;?$/;
|
|
99
|
+
const HOSTS$10 = /* @__PURE__ */ new Set(["dailymotion.com", "www.dailymotion.com"]);
|
|
100
|
+
function video$3(id, options) {
|
|
101
|
+
return {
|
|
102
|
+
platform: "dailymotion",
|
|
103
|
+
kind: "video",
|
|
104
|
+
url: `https://www.dailymotion.com/video/${id}`,
|
|
105
|
+
id,
|
|
106
|
+
variant: "iframe",
|
|
107
|
+
options
|
|
108
|
+
};
|
|
109
|
+
}
|
|
110
|
+
/** A geo.dailymotion.com player, with or without a Player ID. Playlists are left out. */
|
|
111
|
+
function fromPlayer$2(url) {
|
|
112
|
+
if (url.host !== "geo.dailymotion.com" || url.query.has("playlist")) return null;
|
|
113
|
+
const match = /^\/player(?:\/([a-z0-9]+))?\.html$/.exec(url.path);
|
|
114
|
+
if (!match) return null;
|
|
115
|
+
const [, playerId] = match;
|
|
116
|
+
const id = url.query.get("video") ?? "";
|
|
117
|
+
if (!VIDEO_ID$2.test(id)) return null;
|
|
118
|
+
if (playerId !== void 0 && !PLAYER_ID.test(playerId)) return null;
|
|
119
|
+
const options = Object.fromEntries([...url.query].filter(([key]) => key !== "video").map(([key, value]) => [key, coerce(value)]));
|
|
120
|
+
if (playerId !== void 0) options.playerId = playerId;
|
|
121
|
+
return video$3(id, options);
|
|
122
|
+
}
|
|
123
|
+
function fromPage$1(url) {
|
|
124
|
+
if (url.host === "dai.ly") {
|
|
125
|
+
const id = url.path.replace(/^\/|\/$/g, "");
|
|
126
|
+
return VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
|
|
127
|
+
}
|
|
128
|
+
if (!HOSTS$10.has(url.host)) return null;
|
|
129
|
+
const [, id] = /^(?:\/embed)?\/video\/([a-z0-9]+)\/?$/.exec(url.path) ?? [];
|
|
130
|
+
return id !== void 0 && VIDEO_ID$2.test(id) ? video$3(id, {}) : null;
|
|
131
|
+
}
|
|
132
|
+
const dailymotion = {
|
|
133
|
+
platform: "dailymotion",
|
|
134
|
+
parse(root) {
|
|
135
|
+
const wrapped = unwrapRatio(root, WRAPPER$1);
|
|
136
|
+
const iframe = wrapped?.iframe ?? root;
|
|
137
|
+
if (iframe.tag !== "iframe") return null;
|
|
138
|
+
const src = parseUrl(iframe.attrs.get("src") ?? "");
|
|
139
|
+
if (!src) return null;
|
|
140
|
+
const embed = fromPlayer$2(src) ?? fromPage$1(src);
|
|
141
|
+
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
142
|
+
},
|
|
143
|
+
isOwnScript: () => false,
|
|
144
|
+
match(url) {
|
|
145
|
+
return fromPlayer$2(url) ?? fromPage$1(url);
|
|
146
|
+
}
|
|
147
|
+
};
|
|
1
148
|
// src/parser/html.ts
|
|
2
149
|
const VOID_TAGS = /* @__PURE__ */ new Set([
|
|
3
150
|
"area",
|
|
@@ -165,73 +312,8 @@ function rebuild(nodes, whitelist) {
|
|
|
165
312
|
function escapeAttribute(value) {
|
|
166
313
|
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
167
314
|
}
|
|
168
|
-
// src/parser/url.ts
|
|
169
|
-
const URL_PATTERN = /^(?:https?:)?\/\/([^/?#\s@]+)((?:\/[^?#\s]*)?)(?:\?([^#\s]*))?(?:#\S*)?$/i;
|
|
170
|
-
/** Absolute or protocol-relative http(s) URLs only. */
|
|
171
|
-
function parseUrl(input) {
|
|
172
|
-
const match = URL_PATTERN.exec(input.trim());
|
|
173
|
-
if (!match) return null;
|
|
174
|
-
const [, host = "", path = "", search = ""] = match;
|
|
175
|
-
const query = /* @__PURE__ */ new Map();
|
|
176
|
-
for (const pair of search.split("&")) {
|
|
177
|
-
if (pair === "") continue;
|
|
178
|
-
const eq = pair.indexOf("=");
|
|
179
|
-
const key = decodeComponent(eq === -1 ? pair : pair.slice(0, eq));
|
|
180
|
-
const value = decodeComponent(eq === -1 ? "" : pair.slice(eq + 1));
|
|
181
|
-
if (key === null || value === null) return null;
|
|
182
|
-
if (!query.has(key)) query.set(key, value);
|
|
183
|
-
}
|
|
184
|
-
return {
|
|
185
|
-
host: host.toLowerCase(),
|
|
186
|
-
path,
|
|
187
|
-
query
|
|
188
|
-
};
|
|
189
|
-
}
|
|
190
|
-
function decodeComponent(component) {
|
|
191
|
-
try {
|
|
192
|
-
return decodeURIComponent(component.replace(/\+/g, " "));
|
|
193
|
-
} catch {
|
|
194
|
-
return null;
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
/** Types an option value: booleans, canonical integers, otherwise the string as given. */
|
|
198
|
-
function coerce(value) {
|
|
199
|
-
if (value === "true") return true;
|
|
200
|
-
if (value === "false") return false;
|
|
201
|
-
if (/^(?:0|[1-9]\d{0,14})$/.test(value)) return Number(value);
|
|
202
|
-
return value;
|
|
203
|
-
}
|
|
204
|
-
function pixels(value) {
|
|
205
|
-
return value !== void 0 && /^[1-9]\d{0,5}$/.test(value) ? Number(value) : void 0;
|
|
206
|
-
}
|
|
207
|
-
// src/parser/platform.ts
|
|
208
|
-
/** The first attribute present for a key wins. */
|
|
209
|
-
function attributeOptions(element, mapping, coerceValue) {
|
|
210
|
-
const options = {};
|
|
211
|
-
for (const [attribute, key] of mapping) {
|
|
212
|
-
const value = element.attrs.get(attribute);
|
|
213
|
-
if (value !== void 0 && !(key in options)) options[key] = coerceValue(value);
|
|
214
|
-
}
|
|
215
|
-
return options;
|
|
216
|
-
}
|
|
217
|
-
function sizeOf(element) {
|
|
218
|
-
const width = pixels(element.attrs.get("width"));
|
|
219
|
-
const height = pixels(element.attrs.get("height"));
|
|
220
|
-
if (width === void 0 && height === void 0) return void 0;
|
|
221
|
-
return {
|
|
222
|
-
...width === void 0 ? {} : { width },
|
|
223
|
-
...height === void 0 ? {} : { height }
|
|
224
|
-
};
|
|
225
|
-
}
|
|
226
|
-
/** Adds `size` only when known, so results stay free of `undefined` properties. */
|
|
227
|
-
function withSize(embed, size) {
|
|
228
|
-
return size ? {
|
|
229
|
-
...embed,
|
|
230
|
-
size
|
|
231
|
-
} : embed;
|
|
232
|
-
}
|
|
233
315
|
// src/parser/platforms/facebook.ts
|
|
234
|
-
const HOSTS$
|
|
316
|
+
const HOSTS$9 = /* @__PURE__ */ new Set([
|
|
235
317
|
"facebook.com",
|
|
236
318
|
"www.facebook.com",
|
|
237
319
|
"m.facebook.com"
|
|
@@ -240,7 +322,7 @@ const PLUGIN_HOSTS = /* @__PURE__ */ new Set(["facebook.com", "www.facebook.com"
|
|
|
240
322
|
const BASE = "https://www.facebook.com";
|
|
241
323
|
const NAME = "[A-Za-z0-9.\\-]{1,80}";
|
|
242
324
|
const POST_ID = "(?:\\d{1,25}|pfbid[A-Za-z0-9]{10,120})";
|
|
243
|
-
const POSTS_PATH = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
325
|
+
const POSTS_PATH$1 = new RegExp(`^/(${NAME})/posts/(${POST_ID})/?$`);
|
|
244
326
|
const PHOTOS_PATH = new RegExp(`^/(${NAME})/photos/([A-Za-z0-9.]{1,40})/(\\d{1,25})/?$`);
|
|
245
327
|
const VIDEOS_PATH = new RegExp(`^/(${NAME})/videos/(?:[^/]{1,200}/)?(\\d{1,25})/?$`);
|
|
246
328
|
const REEL_PATH = /^\/reel\/(\d{1,25})\/?$/;
|
|
@@ -252,8 +334,8 @@ const PHOTO_PATHS = /* @__PURE__ */ new Set([
|
|
|
252
334
|
]);
|
|
253
335
|
const STORY_ID = new RegExp(`^${POST_ID}$`);
|
|
254
336
|
const NUMERIC_ID = /^\d{1,25}$/;
|
|
255
|
-
const SCRIPT$
|
|
256
|
-
const OPTION_ATTRIBUTES$
|
|
337
|
+
const SCRIPT$9 = /^(?:https?:)?\/\/connect\.facebook\.net\/([a-z]{2,3}_[A-Z]{2})\/sdk\.js(?:[?#].*)?$/;
|
|
338
|
+
const OPTION_ATTRIBUTES$5 = [
|
|
257
339
|
["data-width", "width"],
|
|
258
340
|
["data-show-text", "showText"],
|
|
259
341
|
["data-lazy", "lazy"],
|
|
@@ -277,10 +359,10 @@ const FALLBACK$3 = /* @__PURE__ */ new Map([
|
|
|
277
359
|
["a", ["href"]],
|
|
278
360
|
["p", []]
|
|
279
361
|
]);
|
|
280
|
-
function target(url) {
|
|
281
|
-
if (!url || !HOSTS$
|
|
362
|
+
function target$1(url) {
|
|
363
|
+
if (!url || !HOSTS$9.has(url.host)) return null;
|
|
282
364
|
const { path, query } = url;
|
|
283
|
-
const [, name, postId] = POSTS_PATH.exec(path) ?? [];
|
|
365
|
+
const [, name, postId] = POSTS_PATH$1.exec(path) ?? [];
|
|
284
366
|
if (name !== void 0 && postId !== void 0) return {
|
|
285
367
|
kind: "post",
|
|
286
368
|
id: postId,
|
|
@@ -351,17 +433,17 @@ const facebook = {
|
|
|
351
433
|
parse(root) {
|
|
352
434
|
if (root.tag === "div") {
|
|
353
435
|
const kind = hasClass(root, "fb-post") ? "post" : hasClass(root, "fb-video") ? "video" : null;
|
|
354
|
-
const found = target(parseUrl(root.attrs.get("data-href") ?? ""));
|
|
436
|
+
const found = target$1(parseUrl(root.attrs.get("data-href") ?? ""));
|
|
355
437
|
if (!kind || !found) return null;
|
|
356
438
|
return {
|
|
357
|
-
...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$
|
|
439
|
+
...embed(found, kind, "sdk", attributeOptions(root, OPTION_ATTRIBUTES$5, coerce)),
|
|
358
440
|
fallbackHtml: rebuild(root.children, FALLBACK$3)
|
|
359
441
|
};
|
|
360
442
|
}
|
|
361
443
|
if (root.tag !== "iframe") return null;
|
|
362
444
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
363
445
|
if (!src || !PLUGIN_HOSTS.has(src.host)) return null;
|
|
364
|
-
const found = target(parseUrl(src.query.get("href") ?? ""));
|
|
446
|
+
const found = target$1(parseUrl(src.query.get("href") ?? ""));
|
|
365
447
|
if (!found) return null;
|
|
366
448
|
if (src.path === "/plugins/post.php") {
|
|
367
449
|
const options = {};
|
|
@@ -393,20 +475,20 @@ const facebook = {
|
|
|
393
475
|
}
|
|
394
476
|
return null;
|
|
395
477
|
},
|
|
396
|
-
isOwnScript: (src) => SCRIPT$
|
|
478
|
+
isOwnScript: (src) => SCRIPT$9.test(src),
|
|
397
479
|
scriptOptions(src) {
|
|
398
|
-
const [, locale] = SCRIPT$
|
|
480
|
+
const [, locale] = SCRIPT$9.exec(src) ?? [];
|
|
399
481
|
return locale === void 0 ? {} : { locale };
|
|
400
482
|
},
|
|
401
483
|
allowsFbRoot: true,
|
|
402
484
|
match(url) {
|
|
403
|
-
const found = target(url);
|
|
485
|
+
const found = target$1(url);
|
|
404
486
|
return found && embed(found, found.kind, "sdk", {});
|
|
405
487
|
}
|
|
406
488
|
};
|
|
407
489
|
// src/parser/platforms/instagram.ts
|
|
408
|
-
const HOSTS$
|
|
409
|
-
const POST_PATH$
|
|
490
|
+
const HOSTS$8 = /* @__PURE__ */ new Set(["instagram.com", "www.instagram.com"]);
|
|
491
|
+
const POST_PATH$3 = /^\/(?:([A-Za-z0-9._]{1,30})\/)?(p|reel|reels|tv)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
410
492
|
const TYPES = /* @__PURE__ */ new Set([
|
|
411
493
|
"p",
|
|
412
494
|
"reel",
|
|
@@ -414,15 +496,15 @@ const TYPES = /* @__PURE__ */ new Set([
|
|
|
414
496
|
"tv"
|
|
415
497
|
]);
|
|
416
498
|
const USER_POST_TYPES = /* @__PURE__ */ new Set(["p", "reel"]);
|
|
417
|
-
const SCRIPT$
|
|
499
|
+
const SCRIPT$8 = /^(?:https?:)?\/\/www\.instagram\.com\/embed\.js$/;
|
|
418
500
|
const FALLBACK$2 = /* @__PURE__ */ new Map([
|
|
419
501
|
["div", []],
|
|
420
502
|
["a", ["href"]],
|
|
421
503
|
["p", []]
|
|
422
504
|
]);
|
|
423
|
-
function post$
|
|
424
|
-
if (!url || !HOSTS$
|
|
425
|
-
const [, user, type, code] = POST_PATH$
|
|
505
|
+
function post$5(url) {
|
|
506
|
+
if (!url || !HOSTS$8.has(url.host)) return null;
|
|
507
|
+
const [, user, type, code] = POST_PATH$3.exec(url.path) ?? [];
|
|
426
508
|
if (type === void 0 || code === void 0) return null;
|
|
427
509
|
if (user !== void 0 && (TYPES.has(user) || !USER_POST_TYPES.has(type))) return null;
|
|
428
510
|
return {
|
|
@@ -439,7 +521,7 @@ const instagram = {
|
|
|
439
521
|
parse(root) {
|
|
440
522
|
if (root.tag !== "blockquote" || !hasClass(root, "instagram-media")) return null;
|
|
441
523
|
const permalink = root.attrs.get("data-instgrm-permalink");
|
|
442
|
-
const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$
|
|
524
|
+
const found = permalink === void 0 ? descendants(root.children).reverse().map((element) => element.tag === "a" ? post$5(parseUrl(element.attrs.get("href") ?? "")) : null).find((candidate) => candidate !== null) : post$5(parseUrl(permalink));
|
|
443
525
|
if (!found) return null;
|
|
444
526
|
const options = {};
|
|
445
527
|
if (root.attrs.has("data-instgrm-captioned")) options.captioned = true;
|
|
@@ -451,28 +533,369 @@ const instagram = {
|
|
|
451
533
|
fallbackHtml: rebuild(root.children, FALLBACK$2)
|
|
452
534
|
};
|
|
453
535
|
},
|
|
454
|
-
isOwnScript: (src) => SCRIPT$
|
|
536
|
+
isOwnScript: (src) => SCRIPT$8.test(src),
|
|
455
537
|
match(url) {
|
|
456
|
-
const found = post$
|
|
538
|
+
const found = post$5(url);
|
|
457
539
|
return found && {
|
|
458
540
|
...found,
|
|
459
541
|
options: {}
|
|
460
542
|
};
|
|
461
543
|
}
|
|
462
544
|
};
|
|
545
|
+
// src/parser/platforms/linkedin.ts
|
|
546
|
+
const HOST$1 = /^(?:www\.|[a-z]{2}\.)?linkedin\.com$/;
|
|
547
|
+
const URN = "(activity|share|ugcPost):(\\d{19})";
|
|
548
|
+
const UPDATE_PATH = new RegExp(`^(?:/embed)?/feed/update/urn:li:${URN}/?$`);
|
|
549
|
+
const POSTS_PATH = new RegExp(`^/posts/[^/]{1,300}-(activity|share|ugcPost)-(\\d{19})-[A-Za-z0-9_-]{1,8}/?$`);
|
|
550
|
+
const EMBED_PATH$1 = new RegExp(`^/embed/feed/update/urn:li:${URN}$`);
|
|
551
|
+
function post$4(type, id, options = {}) {
|
|
552
|
+
const urn = `urn:li:${type}:${id}`;
|
|
553
|
+
return {
|
|
554
|
+
platform: "linkedin",
|
|
555
|
+
kind: "post",
|
|
556
|
+
url: `https://www.linkedin.com/feed/update/${urn}/`,
|
|
557
|
+
id: urn,
|
|
558
|
+
variant: "iframe",
|
|
559
|
+
options
|
|
560
|
+
};
|
|
561
|
+
}
|
|
562
|
+
const decodeColons = (path) => path.replace(/%3A/gi, ":");
|
|
563
|
+
const linkedin = {
|
|
564
|
+
platform: "linkedin",
|
|
565
|
+
parse(root) {
|
|
566
|
+
if (root.tag !== "iframe") return null;
|
|
567
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
568
|
+
if (src?.host !== "www.linkedin.com") return null;
|
|
569
|
+
const [, type, id] = EMBED_PATH$1.exec(src.path) ?? [];
|
|
570
|
+
if (type === void 0 || id === void 0) return null;
|
|
571
|
+
return withSize(post$4(type, id, Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
|
|
572
|
+
},
|
|
573
|
+
isOwnScript: () => false,
|
|
574
|
+
match(url) {
|
|
575
|
+
if (!HOST$1.test(url.host)) return null;
|
|
576
|
+
const path = decodeColons(url.path);
|
|
577
|
+
const [, type, id] = UPDATE_PATH.exec(path) ?? POSTS_PATH.exec(path) ?? [];
|
|
578
|
+
return type === void 0 || id === void 0 ? null : post$4(type, id);
|
|
579
|
+
}
|
|
580
|
+
};
|
|
581
|
+
// src/parser/platforms/pinterest.ts
|
|
582
|
+
const HOST = /^(?:(?:www|[a-z]{2})\.)?pinterest\.(?:[a-z]{2,3}|co\.[a-z]{2}|com\.[a-z]{2})$/;
|
|
583
|
+
const PIN_PATH = /^\/pin\/(?:[A-Za-z0-9-]{0,200}--)?(\d{1,25})\/?$/;
|
|
584
|
+
const PIN_ID = /^\d{1,25}$/;
|
|
585
|
+
const SCRIPT$7 = /^(?:https?:)?\/\/assets\.pinterest\.com\/js\/pinit(?:_main)?\.js$/;
|
|
586
|
+
const OPTION_ATTRIBUTES$4 = [
|
|
587
|
+
["data-pin-width", "width"],
|
|
588
|
+
["data-pin-lang", "lang"],
|
|
589
|
+
["data-pin-terse", "terse"]
|
|
590
|
+
];
|
|
591
|
+
function pin(id) {
|
|
592
|
+
return {
|
|
593
|
+
platform: "pinterest",
|
|
594
|
+
kind: "post",
|
|
595
|
+
url: `https://www.pinterest.com/pin/${id}/`,
|
|
596
|
+
id,
|
|
597
|
+
variant: "sdk"
|
|
598
|
+
};
|
|
599
|
+
}
|
|
600
|
+
function pinOf(url) {
|
|
601
|
+
if (!url || !HOST.test(url.host)) return null;
|
|
602
|
+
const [, id] = PIN_PATH.exec(url.path) ?? [];
|
|
603
|
+
return id === void 0 ? null : pin(id);
|
|
604
|
+
}
|
|
605
|
+
const pinterest = {
|
|
606
|
+
platform: "pinterest",
|
|
607
|
+
parse(root) {
|
|
608
|
+
if (root.tag === "a") {
|
|
609
|
+
if (root.attrs.get("data-pin-do") !== "embedPin") return null;
|
|
610
|
+
if (root.children.some((child) => child.type === "element")) return null;
|
|
611
|
+
const found = pinOf(parseUrl(root.attrs.get("href") ?? ""));
|
|
612
|
+
return found && {
|
|
613
|
+
...found,
|
|
614
|
+
options: attributeOptions(root, OPTION_ATTRIBUTES$4, coerce)
|
|
615
|
+
};
|
|
616
|
+
}
|
|
617
|
+
if (root.tag !== "iframe") return null;
|
|
618
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
619
|
+
if (src?.host !== "assets.pinterest.com" || src.path !== "/ext/embed.html") return null;
|
|
620
|
+
const id = src.query.get("id");
|
|
621
|
+
return id !== void 0 && PIN_ID.test(id) ? {
|
|
622
|
+
...pin(id),
|
|
623
|
+
options: {}
|
|
624
|
+
} : null;
|
|
625
|
+
},
|
|
626
|
+
isOwnScript: (src) => SCRIPT$7.test(src),
|
|
627
|
+
match(url) {
|
|
628
|
+
const found = pinOf(url);
|
|
629
|
+
return found && {
|
|
630
|
+
...found,
|
|
631
|
+
options: {}
|
|
632
|
+
};
|
|
633
|
+
}
|
|
634
|
+
};
|
|
635
|
+
// src/parser/platforms/reddit.ts
|
|
636
|
+
const HOSTS$7 = /* @__PURE__ */ new Set([
|
|
637
|
+
"reddit.com",
|
|
638
|
+
"www.reddit.com",
|
|
639
|
+
"old.reddit.com",
|
|
640
|
+
"new.reddit.com"
|
|
641
|
+
]);
|
|
642
|
+
const POST_PATH$2 = /^\/r\/([A-Za-z0-9_]{2,21})\/comments\/([a-z0-9]{1,12})(?:\/([^/]{1,300}))?(?:\/([a-z0-9]{1,16}))?\/?$/;
|
|
643
|
+
const SCRIPT$6 = /^(?:https?:)?\/\/embed\.reddit\.com\/widgets\.js$/;
|
|
644
|
+
const OPTION_ATTRIBUTES$3 = [
|
|
645
|
+
"depth",
|
|
646
|
+
"style",
|
|
647
|
+
"theme",
|
|
648
|
+
"showmedia",
|
|
649
|
+
"showtitle",
|
|
650
|
+
"showedits",
|
|
651
|
+
"created",
|
|
652
|
+
"locale",
|
|
653
|
+
"showusername",
|
|
654
|
+
"snippet"
|
|
655
|
+
].map((name) => [`data-embed-${name}`, name]);
|
|
656
|
+
function post$3(url) {
|
|
657
|
+
if (!url || !HOSTS$7.has(url.host)) return null;
|
|
658
|
+
const [, sub, postId, slug, commentId] = POST_PATH$2.exec(url.path) ?? [];
|
|
659
|
+
if (sub === void 0 || postId === void 0) return null;
|
|
660
|
+
const base = {
|
|
661
|
+
platform: "reddit",
|
|
662
|
+
kind: "post",
|
|
663
|
+
variant: "iframe"
|
|
664
|
+
};
|
|
665
|
+
const postUrl = `https://www.reddit.com/r/${sub}/comments/${postId}/`;
|
|
666
|
+
if (commentId === void 0) return {
|
|
667
|
+
...base,
|
|
668
|
+
url: postUrl,
|
|
669
|
+
id: postId
|
|
670
|
+
};
|
|
671
|
+
if (slug === void 0) return null;
|
|
672
|
+
return {
|
|
673
|
+
...base,
|
|
674
|
+
url: `${postUrl}comment/${commentId}/`,
|
|
675
|
+
id: commentId
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
const reddit = {
|
|
679
|
+
platform: "reddit",
|
|
680
|
+
parse(root) {
|
|
681
|
+
if (root.tag !== "blockquote" || !hasClass(root, "reddit-embed-bq")) return null;
|
|
682
|
+
const found = descendants(root.children).map((element) => element.tag === "a" ? post$3(parseUrl(element.attrs.get("href") ?? "")) : null).find((embed) => embed !== null);
|
|
683
|
+
if (!found) return null;
|
|
684
|
+
const height = pixels(root.attrs.get("data-embed-height"));
|
|
685
|
+
return withSize({
|
|
686
|
+
...found,
|
|
687
|
+
options: attributeOptions(root, OPTION_ATTRIBUTES$3, coerce)
|
|
688
|
+
}, height === void 0 ? void 0 : { height });
|
|
689
|
+
},
|
|
690
|
+
isOwnScript: (src) => SCRIPT$6.test(src),
|
|
691
|
+
match(url) {
|
|
692
|
+
const found = post$3(url);
|
|
693
|
+
return found && {
|
|
694
|
+
...found,
|
|
695
|
+
options: {}
|
|
696
|
+
};
|
|
697
|
+
}
|
|
698
|
+
};
|
|
699
|
+
// src/parser/platforms/snapchat.ts
|
|
700
|
+
const HOSTS$6 = /* @__PURE__ */ new Set(["snapchat.com", "www.snapchat.com"]);
|
|
701
|
+
const USER = "([A-Za-z][A-Za-z0-9._-]{1,29})";
|
|
702
|
+
const SPOTLIGHT = new RegExp(`^(?:/@${USER})?/spotlight/([A-Za-z0-9_-]{20,120})$`);
|
|
703
|
+
const PROFILE = new RegExp(`^/(?:@|add/)${USER}$`);
|
|
704
|
+
const LENS = /^\/lens\/([0-9a-f]{32}|\d{1,20})$/;
|
|
705
|
+
const HIGHLIGHT = new RegExp(`^/@${USER}/highlight/([0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12})$`);
|
|
706
|
+
const SCRIPT$5 = /^(?:https?:)?\/\/www\.snapchat\.com\/embed\.js$/;
|
|
707
|
+
function content$1(url) {
|
|
708
|
+
if (!url || !HOSTS$6.has(url.host)) return null;
|
|
709
|
+
const path = url.path.replace(/\/$/, "");
|
|
710
|
+
const base = {
|
|
711
|
+
platform: "snapchat",
|
|
712
|
+
variant: "iframe"
|
|
713
|
+
};
|
|
714
|
+
const [, spotlightUser, spotlightId] = SPOTLIGHT.exec(path) ?? [];
|
|
715
|
+
if (spotlightId !== void 0) {
|
|
716
|
+
const prefix = spotlightUser === void 0 ? "" : `/@${spotlightUser}`;
|
|
717
|
+
return {
|
|
718
|
+
...base,
|
|
719
|
+
kind: "video",
|
|
720
|
+
url: `https://www.snapchat.com${prefix}/spotlight/${spotlightId}`,
|
|
721
|
+
id: spotlightId
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
const [, user] = PROFILE.exec(path) ?? [];
|
|
725
|
+
if (user !== void 0) return {
|
|
726
|
+
...base,
|
|
727
|
+
kind: "post",
|
|
728
|
+
url: `https://www.snapchat.com/@${user}`,
|
|
729
|
+
id: user
|
|
730
|
+
};
|
|
731
|
+
const [, lens] = LENS.exec(path) ?? [];
|
|
732
|
+
if (lens !== void 0) return {
|
|
733
|
+
...base,
|
|
734
|
+
kind: "post",
|
|
735
|
+
url: `https://www.snapchat.com/lens/${lens}`,
|
|
736
|
+
id: lens
|
|
737
|
+
};
|
|
738
|
+
const [, owner, highlight] = HIGHLIGHT.exec(path) ?? [];
|
|
739
|
+
if (owner !== void 0 && highlight !== void 0) return {
|
|
740
|
+
...base,
|
|
741
|
+
kind: "post",
|
|
742
|
+
url: `https://www.snapchat.com/@${owner}/highlight/${highlight}`,
|
|
743
|
+
id: highlight
|
|
744
|
+
};
|
|
745
|
+
return null;
|
|
746
|
+
}
|
|
747
|
+
const snapchat = {
|
|
748
|
+
platform: "snapchat",
|
|
749
|
+
parse(root) {
|
|
750
|
+
if (root.tag !== "blockquote" || !hasClass(root, "snapchat-embed")) return null;
|
|
751
|
+
const embedUrl = parseUrl(root.attrs.get("data-snapchat-embed-url") ?? "");
|
|
752
|
+
if (!embedUrl?.path.endsWith("/embed")) return null;
|
|
753
|
+
const found = content$1({
|
|
754
|
+
...embedUrl,
|
|
755
|
+
path: embedUrl.path.slice(0, -6)
|
|
756
|
+
});
|
|
757
|
+
if (!found) return null;
|
|
758
|
+
if (!descendants(root.children).filter((el) => el.tag === "a").every((link) => {
|
|
759
|
+
const linked = content$1(parseUrl(link.attrs.get("href") ?? ""));
|
|
760
|
+
return linked?.kind === found.kind && linked.id === found.id;
|
|
761
|
+
})) return null;
|
|
762
|
+
const title = root.attrs.get("data-snapchat-embed-title");
|
|
763
|
+
const width = pixels(root.attrs.get("data-snapchat-embed-width"));
|
|
764
|
+
const height = pixels(root.attrs.get("data-snapchat-embed-height"));
|
|
765
|
+
return withSize({
|
|
766
|
+
...found,
|
|
767
|
+
options: title === void 0 ? {} : { title }
|
|
768
|
+
}, width === void 0 || height === void 0 ? void 0 : {
|
|
769
|
+
width,
|
|
770
|
+
height
|
|
771
|
+
});
|
|
772
|
+
},
|
|
773
|
+
isOwnScript: (src) => SCRIPT$5.test(src),
|
|
774
|
+
match(url) {
|
|
775
|
+
const found = content$1(url);
|
|
776
|
+
return found && {
|
|
777
|
+
...found,
|
|
778
|
+
options: {}
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
};
|
|
782
|
+
// src/parser/platforms/spotify.ts
|
|
783
|
+
const CONTENT_PATH = new RegExp(`^(?:/intl-[a-z]{2}(?:-[A-Za-z]{2})?)?(?:/embed)?/(track|album|playlist|artist|episode|show|audiobook|chapter)/([A-Za-z0-9]{22})(/video)?/?$`);
|
|
784
|
+
const DROPPED$1 = /* @__PURE__ */ new Set(["utm_source", "si"]);
|
|
785
|
+
function content(url) {
|
|
786
|
+
if (url?.host !== "open.spotify.com") return null;
|
|
787
|
+
const [, type, id, video] = CONTENT_PATH.exec(url.path) ?? [];
|
|
788
|
+
if (type === void 0 || id === void 0) return null;
|
|
789
|
+
return {
|
|
790
|
+
platform: "spotify",
|
|
791
|
+
kind: video ? "video" : "post",
|
|
792
|
+
url: `https://open.spotify.com/${type}/${id}`,
|
|
793
|
+
id,
|
|
794
|
+
variant: "iframe",
|
|
795
|
+
query: url.query
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
function options(query) {
|
|
799
|
+
return Object.fromEntries([...query].filter(([key]) => !DROPPED$1.has(key)).map(([key, value]) => [key, coerce(value)]));
|
|
800
|
+
}
|
|
801
|
+
const spotify = {
|
|
802
|
+
platform: "spotify",
|
|
803
|
+
parse(root) {
|
|
804
|
+
if (root.tag !== "iframe") return null;
|
|
805
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
806
|
+
if (!src?.path.startsWith("/embed/")) return null;
|
|
807
|
+
const found = content(src);
|
|
808
|
+
if (!found) return null;
|
|
809
|
+
const { query, ...embed } = found;
|
|
810
|
+
return withSize({
|
|
811
|
+
...embed,
|
|
812
|
+
options: options(query)
|
|
813
|
+
}, sizeOf(root));
|
|
814
|
+
},
|
|
815
|
+
isOwnScript: () => false,
|
|
816
|
+
match(url) {
|
|
817
|
+
const found = content(url);
|
|
818
|
+
return found && {
|
|
819
|
+
platform: found.platform,
|
|
820
|
+
kind: "post",
|
|
821
|
+
url: found.url,
|
|
822
|
+
id: found.id,
|
|
823
|
+
variant: found.variant,
|
|
824
|
+
options: {}
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
};
|
|
828
|
+
// src/parser/platforms/telegram.ts
|
|
829
|
+
const HOSTS$5 = /* @__PURE__ */ new Set([
|
|
830
|
+
"t.me",
|
|
831
|
+
"telegram.me",
|
|
832
|
+
"www.telegram.me"
|
|
833
|
+
]);
|
|
834
|
+
const CHANNEL$1 = "[A-Za-z][A-Za-z0-9_]{2,31}";
|
|
835
|
+
const POST = new RegExp(`^(${CHANNEL$1})/(\\d{1,10})$`);
|
|
836
|
+
const POST_PATH$1 = new RegExp(`^/(?:s/)?(${CHANNEL$1})/(\\d{1,10})/?$`);
|
|
837
|
+
const SCRIPT$4 = /^(?:https?:)?\/\/telegram\.org\/js\/telegram-widget\.js(?:\?\d{1,3})?$/;
|
|
838
|
+
const OTHER_WIDGETS = [
|
|
839
|
+
"data-telegram-login",
|
|
840
|
+
"data-telegram-discussion",
|
|
841
|
+
"data-telegram-share-url"
|
|
842
|
+
];
|
|
843
|
+
const OPTION_ATTRIBUTES$2 = [
|
|
844
|
+
["data-width", "width"],
|
|
845
|
+
["data-comment", "comment"],
|
|
846
|
+
["data-userpic", "userpic"],
|
|
847
|
+
["data-mode", "mode"],
|
|
848
|
+
["data-color", "color"],
|
|
849
|
+
["data-dark", "dark"],
|
|
850
|
+
["data-dark-color", "darkColor"]
|
|
851
|
+
];
|
|
852
|
+
function post$2(channel, id, options) {
|
|
853
|
+
return {
|
|
854
|
+
platform: "telegram",
|
|
855
|
+
kind: "post",
|
|
856
|
+
url: `https://t.me/${channel}/${id}`,
|
|
857
|
+
id: `${channel}/${id}`,
|
|
858
|
+
variant: "iframe",
|
|
859
|
+
options
|
|
860
|
+
};
|
|
861
|
+
}
|
|
862
|
+
const telegram = {
|
|
863
|
+
platform: "telegram",
|
|
864
|
+
parse: () => null,
|
|
865
|
+
parseScript(script) {
|
|
866
|
+
if (!SCRIPT$4.test(script.attrs.get("src") ?? "")) return null;
|
|
867
|
+
if (OTHER_WIDGETS.some((name) => script.attrs.has(name))) return null;
|
|
868
|
+
const [, channel, id] = POST.exec(script.attrs.get("data-telegram-post") ?? "") ?? [];
|
|
869
|
+
if (channel === void 0 || id === void 0) return null;
|
|
870
|
+
const options = attributeOptions(script, OPTION_ATTRIBUTES$2, coerce);
|
|
871
|
+
if (script.attrs.has("data-single")) options.single = true;
|
|
872
|
+
return post$2(channel, id, options);
|
|
873
|
+
},
|
|
874
|
+
isOwnScript: (src) => SCRIPT$4.test(src),
|
|
875
|
+
match(url) {
|
|
876
|
+
if (!HOSTS$5.has(url.host)) return null;
|
|
877
|
+
const [, channel, id] = POST_PATH$1.exec(url.path) ?? [];
|
|
878
|
+
if (channel === void 0 || id === void 0) return null;
|
|
879
|
+
const options = {};
|
|
880
|
+
if (url.query.has("single")) options.single = true;
|
|
881
|
+
const comment = url.query.get("comment");
|
|
882
|
+
if (comment !== void 0 && /^\d{1,10}$/.test(comment)) options.comment = Number(comment);
|
|
883
|
+
return post$2(channel, id, options);
|
|
884
|
+
}
|
|
885
|
+
};
|
|
463
886
|
// src/parser/platforms/threads.ts
|
|
464
|
-
const HOSTS$
|
|
887
|
+
const HOSTS$4 = /* @__PURE__ */ new Set([
|
|
465
888
|
"threads.com",
|
|
466
889
|
"www.threads.com",
|
|
467
890
|
"threads.net",
|
|
468
891
|
"www.threads.net"
|
|
469
892
|
]);
|
|
470
893
|
const POST_PATH = /^\/(?:@[A-Za-z0-9._]{1,30}\/post|t)\/([A-Za-z0-9_-]{1,64})\/?$/;
|
|
471
|
-
const SCRIPT$
|
|
894
|
+
const SCRIPT$3 = /^(?:https?:)?\/\/www\.threads\.(?:com|net)\/embed\.js$/;
|
|
472
895
|
const OPTION_ATTRIBUTES$1 = [["data-theme", "theme"], ["data-text-post-version", "version"]];
|
|
473
896
|
const FALLBACK$1 = /* @__PURE__ */ new Map([["a", ["href"]], ["div", []]]);
|
|
474
897
|
function post$1(url) {
|
|
475
|
-
if (!url || !HOSTS$
|
|
898
|
+
if (!url || !HOSTS$4.has(url.host)) return null;
|
|
476
899
|
const [, code] = POST_PATH.exec(url.path) ?? [];
|
|
477
900
|
if (code === void 0) return null;
|
|
478
901
|
return {
|
|
@@ -498,7 +921,7 @@ const threads = {
|
|
|
498
921
|
fallbackHtml: rebuild(root.children, FALLBACK$1)
|
|
499
922
|
};
|
|
500
923
|
},
|
|
501
|
-
isOwnScript: (src) => SCRIPT$
|
|
924
|
+
isOwnScript: (src) => SCRIPT$3.test(src),
|
|
502
925
|
match(url) {
|
|
503
926
|
const found = post$1(url);
|
|
504
927
|
return found && {
|
|
@@ -508,12 +931,12 @@ const threads = {
|
|
|
508
931
|
}
|
|
509
932
|
};
|
|
510
933
|
// src/parser/platforms/tiktok.ts
|
|
511
|
-
const HOSTS$
|
|
934
|
+
const HOSTS$3 = /* @__PURE__ */ new Set(["tiktok.com", "www.tiktok.com"]);
|
|
512
935
|
const VIDEO_PATH = /^\/@([A-Za-z0-9._]{0,64})\/video\/(\d{1,25})\/?$/;
|
|
513
|
-
const PLAYER_PATH = /^\/player\/v1\/(\d{1,25})\/?$/;
|
|
936
|
+
const PLAYER_PATH$1 = /^\/player\/v1\/(\d{1,25})\/?$/;
|
|
514
937
|
const VIDEO_ID$1 = /^\d{1,25}$/;
|
|
515
|
-
const SCRIPT$
|
|
516
|
-
function video$
|
|
938
|
+
const SCRIPT$2 = /^(?:https?:)?\/\/www\.tiktok\.com\/embed\.js$/;
|
|
939
|
+
function video$2(id, user = "", options = {}) {
|
|
517
940
|
return {
|
|
518
941
|
platform: "tiktok",
|
|
519
942
|
kind: "video",
|
|
@@ -528,25 +951,219 @@ const tiktok = {
|
|
|
528
951
|
parse(root) {
|
|
529
952
|
if (root.tag === "blockquote" && hasClass(root, "tiktok-embed")) {
|
|
530
953
|
const cite = parseUrl(root.attrs.get("cite") ?? "");
|
|
531
|
-
const [, user, citeId] = cite && HOSTS$
|
|
954
|
+
const [, user, citeId] = cite && HOSTS$3.has(cite.host) ? VIDEO_PATH.exec(cite.path) ?? [] : [];
|
|
532
955
|
const dataId = root.attrs.get("data-video-id");
|
|
533
956
|
if (dataId !== void 0 && !VIDEO_ID$1.test(dataId)) return null;
|
|
534
957
|
if (dataId !== void 0 && citeId !== void 0 && dataId !== citeId) return null;
|
|
535
958
|
const id = dataId ?? citeId;
|
|
536
|
-
return id === void 0 ? null : video$
|
|
959
|
+
return id === void 0 ? null : video$2(id, user);
|
|
537
960
|
}
|
|
538
961
|
if (root.tag !== "iframe") return null;
|
|
539
962
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
540
|
-
if (!src || !HOSTS$
|
|
541
|
-
const [, id] = PLAYER_PATH.exec(src.path) ?? [];
|
|
963
|
+
if (!src || !HOSTS$3.has(src.host)) return null;
|
|
964
|
+
const [, id] = PLAYER_PATH$1.exec(src.path) ?? [];
|
|
965
|
+
if (id === void 0) return null;
|
|
966
|
+
return withSize(video$2(id, "", Object.fromEntries([...src.query].map(([key, value]) => [key, coerce(value)]))), sizeOf(root));
|
|
967
|
+
},
|
|
968
|
+
isOwnScript: (src) => SCRIPT$2.test(src),
|
|
969
|
+
match(url) {
|
|
970
|
+
if (!HOSTS$3.has(url.host)) return null;
|
|
971
|
+
const [, user, id] = VIDEO_PATH.exec(url.path) ?? [];
|
|
972
|
+
return user === void 0 || id === void 0 ? null : video$2(id, user);
|
|
973
|
+
}
|
|
974
|
+
};
|
|
975
|
+
// src/parser/platforms/twitch.ts
|
|
976
|
+
const HOSTS$2 = /* @__PURE__ */ new Set([
|
|
977
|
+
"twitch.tv",
|
|
978
|
+
"www.twitch.tv",
|
|
979
|
+
"m.twitch.tv"
|
|
980
|
+
]);
|
|
981
|
+
const CHANNEL = /^[A-Za-z0-9_]{3,25}$/;
|
|
982
|
+
const VIDEO$1 = /^v?(\d{1,12})$/;
|
|
983
|
+
const COLLECTION = /^[A-Za-z0-9_-]{6,30}$/;
|
|
984
|
+
const CLIP = /^[A-Za-z0-9_-]{6,100}$/;
|
|
985
|
+
const TIME = /^(?:\d+h)?(?:\d+m)?(?:\d+s)?$/;
|
|
986
|
+
const RESERVED = /* @__PURE__ */ new Set([
|
|
987
|
+
"directory",
|
|
988
|
+
"videos",
|
|
989
|
+
"collections",
|
|
990
|
+
"settings",
|
|
991
|
+
"subscriptions",
|
|
992
|
+
"inventory",
|
|
993
|
+
"wallet",
|
|
994
|
+
"drops",
|
|
995
|
+
"search",
|
|
996
|
+
"downloads",
|
|
997
|
+
"jobs",
|
|
998
|
+
"turbo",
|
|
999
|
+
"p",
|
|
1000
|
+
"login",
|
|
1001
|
+
"signup"
|
|
1002
|
+
]);
|
|
1003
|
+
const PLAYER_OPTIONS = [
|
|
1004
|
+
"autoplay",
|
|
1005
|
+
"muted",
|
|
1006
|
+
"time"
|
|
1007
|
+
];
|
|
1008
|
+
function target(path, id) {
|
|
1009
|
+
return {
|
|
1010
|
+
platform: "twitch",
|
|
1011
|
+
kind: "video",
|
|
1012
|
+
url: path,
|
|
1013
|
+
id,
|
|
1014
|
+
variant: "iframe"
|
|
1015
|
+
};
|
|
1016
|
+
}
|
|
1017
|
+
const channel = (name) => target(`https://www.twitch.tv/${name.toLowerCase()}`, name.toLowerCase());
|
|
1018
|
+
const vod = (id) => target(`https://www.twitch.tv/videos/${id}`, id);
|
|
1019
|
+
const collection = (id) => target(`https://www.twitch.tv/collections/${id}`, id);
|
|
1020
|
+
const clip = (slug) => target(`https://clips.twitch.tv/${slug}`, slug);
|
|
1021
|
+
function playerOptions(query) {
|
|
1022
|
+
const options = {};
|
|
1023
|
+
for (const name of PLAYER_OPTIONS) {
|
|
1024
|
+
const value = query.get(name);
|
|
1025
|
+
if (value !== void 0) options[name] = coerce(value);
|
|
1026
|
+
}
|
|
1027
|
+
return options;
|
|
1028
|
+
}
|
|
1029
|
+
/** The player's own precedence: channel, then video, then collection. */
|
|
1030
|
+
function fromPlayer$1(url) {
|
|
1031
|
+
const name = url.query.get("channel");
|
|
1032
|
+
if (name !== void 0) return CHANNEL.test(name) ? channel(name) : null;
|
|
1033
|
+
const [, id] = VIDEO$1.exec(url.query.get("video") ?? "") ?? [];
|
|
1034
|
+
if (id !== void 0) return vod(id);
|
|
1035
|
+
const list = url.query.get("collection");
|
|
1036
|
+
return list !== void 0 && COLLECTION.test(list) ? collection(list) : null;
|
|
1037
|
+
}
|
|
1038
|
+
function fromPage(url) {
|
|
1039
|
+
if (url.host === "clips.twitch.tv") {
|
|
1040
|
+
const slug = url.path.replace(/^\/|\/$/g, "");
|
|
1041
|
+
return CLIP.test(slug) ? {
|
|
1042
|
+
found: clip(slug),
|
|
1043
|
+
options: {}
|
|
1044
|
+
} : null;
|
|
1045
|
+
}
|
|
1046
|
+
if (!HOSTS$2.has(url.host)) return null;
|
|
1047
|
+
const parts = url.path.replace(/^\/|\/$/g, "").split("/");
|
|
1048
|
+
const [first = "", second, third] = parts;
|
|
1049
|
+
if (parts.length === 2 && first === "videos") {
|
|
1050
|
+
const [, id] = VIDEO$1.exec(second ?? "") ?? [];
|
|
542
1051
|
if (id === void 0) return null;
|
|
543
|
-
|
|
1052
|
+
const time = url.query.get("t");
|
|
1053
|
+
return {
|
|
1054
|
+
found: vod(id),
|
|
1055
|
+
options: time !== void 0 && TIME.test(time) && time ? { time } : {}
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
1058
|
+
if (parts.length === 2 && first === "collections") return COLLECTION.test(second ?? "") ? {
|
|
1059
|
+
found: collection(second ?? ""),
|
|
1060
|
+
options: {}
|
|
1061
|
+
} : null;
|
|
1062
|
+
if (parts.length === 3 && second === "clip") return CHANNEL.test(first) && CLIP.test(third ?? "") ? {
|
|
1063
|
+
found: clip(third ?? ""),
|
|
1064
|
+
options: {}
|
|
1065
|
+
} : null;
|
|
1066
|
+
if (parts.length === 1 && CHANNEL.test(first) && !RESERVED.has(first.toLowerCase())) return {
|
|
1067
|
+
found: channel(first),
|
|
1068
|
+
options: {}
|
|
1069
|
+
};
|
|
1070
|
+
return null;
|
|
1071
|
+
}
|
|
1072
|
+
const twitch = {
|
|
1073
|
+
platform: "twitch",
|
|
1074
|
+
parse(root) {
|
|
1075
|
+
if (root.tag !== "iframe") return null;
|
|
1076
|
+
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
1077
|
+
if (!src) return null;
|
|
1078
|
+
let found = null;
|
|
1079
|
+
if (src.host === "player.twitch.tv" && /^\/?$/.test(src.path)) found = fromPlayer$1(src);
|
|
1080
|
+
if (src.host === "clips.twitch.tv" && src.path === "/embed") {
|
|
1081
|
+
const slug = src.query.get("clip") ?? "";
|
|
1082
|
+
found = CLIP.test(slug) ? clip(slug) : null;
|
|
1083
|
+
}
|
|
1084
|
+
return found && withSize({
|
|
1085
|
+
...found,
|
|
1086
|
+
options: playerOptions(src.query)
|
|
1087
|
+
}, sizeOf(root));
|
|
1088
|
+
},
|
|
1089
|
+
isOwnScript: () => false,
|
|
1090
|
+
match(url) {
|
|
1091
|
+
const page = fromPage(url);
|
|
1092
|
+
return page && {
|
|
1093
|
+
...page.found,
|
|
1094
|
+
options: page.options
|
|
1095
|
+
};
|
|
1096
|
+
}
|
|
1097
|
+
};
|
|
1098
|
+
// src/parser/platforms/vimeo.ts
|
|
1099
|
+
const HOSTS$1 = /* @__PURE__ */ new Set(["vimeo.com", "www.vimeo.com"]);
|
|
1100
|
+
const VIDEO = "(\\d{1,12})";
|
|
1101
|
+
const HASH = "([0-9a-f]{6,20})";
|
|
1102
|
+
const PAGE_PATHS = [
|
|
1103
|
+
new RegExp(`^/${VIDEO}(?:/${HASH})?/?$`),
|
|
1104
|
+
new RegExp(`^/channels/[A-Za-z0-9_-]{1,64}/${VIDEO}/?$`),
|
|
1105
|
+
new RegExp(`^/groups/[A-Za-z0-9_-]{1,64}/videos/${VIDEO}/?$`),
|
|
1106
|
+
new RegExp(`^/showcase/\\d{1,12}/video/${VIDEO}/?$`)
|
|
1107
|
+
];
|
|
1108
|
+
const PLAYER_PATH = new RegExp(`^/video/${VIDEO}/?$`);
|
|
1109
|
+
const WRAPPER = /^padding:\s*(\d{1,3}(?:\.\d{1,4})?)% 0 0 0;\s*position:\s*relative;?$/;
|
|
1110
|
+
const SCRIPT$1 = /^(?:https?:)?\/\/player\.vimeo\.com\/api\/player\.js$/;
|
|
1111
|
+
const DROPPED = /* @__PURE__ */ new Set([
|
|
1112
|
+
"h",
|
|
1113
|
+
"app_id",
|
|
1114
|
+
"player_id"
|
|
1115
|
+
]);
|
|
1116
|
+
const START = /^t=(\d+(?:\.\d+)?|(?:\d+h)?(?:\d+m)?(?:\d+s)?)$/;
|
|
1117
|
+
function video$1(id, hash) {
|
|
1118
|
+
return {
|
|
1119
|
+
platform: "vimeo",
|
|
1120
|
+
kind: "video",
|
|
1121
|
+
url: `https://vimeo.com/${id}${hash ? `/${hash}` : ""}`,
|
|
1122
|
+
id,
|
|
1123
|
+
variant: "iframe"
|
|
1124
|
+
};
|
|
1125
|
+
}
|
|
1126
|
+
function start(url) {
|
|
1127
|
+
const [, time] = START.exec(url.fragment ?? "") ?? [];
|
|
1128
|
+
return time ? { t: time } : {};
|
|
1129
|
+
}
|
|
1130
|
+
function fromPlayer(url) {
|
|
1131
|
+
if (url?.host !== "player.vimeo.com") return null;
|
|
1132
|
+
const [, id] = PLAYER_PATH.exec(url.path) ?? [];
|
|
1133
|
+
if (id === void 0) return null;
|
|
1134
|
+
const hash = url.query.get("h");
|
|
1135
|
+
if (hash !== void 0 && !new RegExp(`^${HASH}$`).test(hash)) return null;
|
|
1136
|
+
const options = Object.fromEntries([...url.query].filter(([key]) => !DROPPED.has(key)).map(([key, value]) => [key, coerce(value)]));
|
|
1137
|
+
return {
|
|
1138
|
+
...video$1(id, hash),
|
|
1139
|
+
options: {
|
|
1140
|
+
...options,
|
|
1141
|
+
...start(url)
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
}
|
|
1145
|
+
const vimeo = {
|
|
1146
|
+
platform: "vimeo",
|
|
1147
|
+
parse(root) {
|
|
1148
|
+
const wrapped = unwrapRatio(root, WRAPPER);
|
|
1149
|
+
const iframe = wrapped?.iframe ?? root;
|
|
1150
|
+
if (iframe.tag !== "iframe") return null;
|
|
1151
|
+
const embed = fromPlayer(parseUrl(iframe.attrs.get("src") ?? ""));
|
|
1152
|
+
return embed && withSize(embed, wrapped?.size ?? sizeOf(iframe));
|
|
544
1153
|
},
|
|
545
1154
|
isOwnScript: (src) => SCRIPT$1.test(src),
|
|
546
1155
|
match(url) {
|
|
1156
|
+
const player = fromPlayer(url);
|
|
1157
|
+
if (player) return player;
|
|
547
1158
|
if (!HOSTS$1.has(url.host)) return null;
|
|
548
|
-
const
|
|
549
|
-
|
|
1159
|
+
for (const path of PAGE_PATHS) {
|
|
1160
|
+
const [, id, hash] = path.exec(url.path) ?? [];
|
|
1161
|
+
if (id !== void 0) return {
|
|
1162
|
+
...video$1(id, hash),
|
|
1163
|
+
options: start(url)
|
|
1164
|
+
};
|
|
1165
|
+
}
|
|
1166
|
+
return null;
|
|
550
1167
|
}
|
|
551
1168
|
};
|
|
552
1169
|
// src/parser/platforms/x.ts
|
|
@@ -701,7 +1318,16 @@ const platforms = [
|
|
|
701
1318
|
options: urlOptions(url, nocookie)
|
|
702
1319
|
};
|
|
703
1320
|
}
|
|
704
|
-
}
|
|
1321
|
+
},
|
|
1322
|
+
telegram,
|
|
1323
|
+
snapchat,
|
|
1324
|
+
linkedin,
|
|
1325
|
+
reddit,
|
|
1326
|
+
pinterest,
|
|
1327
|
+
spotify,
|
|
1328
|
+
vimeo,
|
|
1329
|
+
twitch,
|
|
1330
|
+
dailymotion
|
|
705
1331
|
];
|
|
706
1332
|
// src/parser/match-url.ts
|
|
707
1333
|
/** Never throws. Options hold only what the URL itself carries (docs/decisions.md D13). */
|
|
@@ -738,7 +1364,16 @@ function parseEmbed(html) {
|
|
|
738
1364
|
else if (root) return null;
|
|
739
1365
|
else root = node;
|
|
740
1366
|
}
|
|
741
|
-
if (!root)
|
|
1367
|
+
if (!root) {
|
|
1368
|
+
const [script] = scripts;
|
|
1369
|
+
if (fbRoot || scripts.length !== 1 || !script) return null;
|
|
1370
|
+
if (script.children.length !== 0) return null;
|
|
1371
|
+
for (const platform of platforms) {
|
|
1372
|
+
const embed = platform.parseScript?.(script);
|
|
1373
|
+
if (embed) return embed;
|
|
1374
|
+
}
|
|
1375
|
+
return null;
|
|
1376
|
+
}
|
|
742
1377
|
for (const platform of platforms) {
|
|
743
1378
|
const embed = platform.parse(root);
|
|
744
1379
|
if (!embed) continue;
|