social-embeds 0.5.0 → 0.5.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as
|
|
2
|
+
import { a as escapeAttribute, c as parseUrl, i as x$1, n as matchUrl, o as parseHtml, r as platforms, s as rebuild, t as parseEmbed } from "./parser-BSz1rCrV.js";
|
|
3
3
|
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
// src/parser/lookup.ts
|
|
6
6
|
const BLUESKY_HOSTS = /* @__PURE__ */ new Set(["bsky.app", "www.bsky.app"]);
|
|
7
7
|
const HANDLE_POST = /^\/profile\/([^/]{1,253})\/post\/[A-Za-z0-9._~:-]{1,512}\/?$/;
|
|
8
|
-
const
|
|
8
|
+
const HANDLE = /^(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?\.)+[a-z](?:[a-z0-9-]{0,61}[a-z0-9])?$/i;
|
|
9
9
|
/**
|
|
10
10
|
* The platform of a post URL that only a network lookup could turn into an embed: a Bluesky
|
|
11
11
|
* URL with a handle instead of a DID. Internal; the parser entry does not export it.
|
|
@@ -14,7 +14,7 @@ function needsLookup(url) {
|
|
|
14
14
|
const parsed = typeof url === "string" ? parseUrl(url) : null;
|
|
15
15
|
if (!parsed || !BLUESKY_HOSTS.has(parsed.host)) return null;
|
|
16
16
|
const [, profile] = HANDLE_POST.exec(parsed.path) ?? [];
|
|
17
|
-
return profile !== void 0 &&
|
|
17
|
+
return profile !== void 0 && HANDLE.test(profile) ? "bluesky" : null;
|
|
18
18
|
}
|
|
19
19
|
// src/components/hooks.ts
|
|
20
20
|
const ROOT_MARGIN = "200px 0px";
|
|
@@ -249,9 +249,13 @@ const NAMES = {
|
|
|
249
249
|
kick: "Kick",
|
|
250
250
|
giphy: "Giphy"
|
|
251
251
|
};
|
|
252
|
+
/** For a post URL that only a network lookup could resolve (docs/decisions.md D70). */
|
|
253
|
+
function lookupMessage(platform) {
|
|
254
|
+
return `social-embeds: a ${NAMES[platform]} URL needs a lookup: use the embed code`;
|
|
255
|
+
}
|
|
252
256
|
function resolveEmbed(url, given, platform) {
|
|
253
257
|
const embed = given ?? (url === void 0 ? null : matchUrl(url));
|
|
254
|
-
if (!embed && url !== void 0 && needsLookup(url) === platform) return { error:
|
|
258
|
+
if (!embed && url !== void 0 && needsLookup(url) === platform) return { error: lookupMessage(platform) };
|
|
255
259
|
if (!embed) return { error: `social-embeds: not a ${NAMES[platform]} post URL: ${String(url)}` };
|
|
256
260
|
if (embed.platform !== platform) return { error: `social-embeds: expected a ${NAMES[platform]} embed, got ${NAMES[embed.platform]}` };
|
|
257
261
|
const verified = verifyEmbed(embed);
|
|
@@ -263,7 +267,7 @@ function resolveEmbed(url, given, platform) {
|
|
|
263
267
|
* come only from the verified url and id.
|
|
264
268
|
*/
|
|
265
269
|
function optionsWithout(options, reserved) {
|
|
266
|
-
return Object.entries(options).filter(([key]) => !reserved.includes(key));
|
|
270
|
+
return Object.entries(options).filter(([key]) => !reserved.includes(key.toLowerCase()));
|
|
267
271
|
}
|
|
268
272
|
/** Later entries replace earlier ones with the same name. */
|
|
269
273
|
function query(...sources) {
|
|
@@ -1598,7 +1602,9 @@ function SocialEmbed(props) {
|
|
|
1598
1602
|
maxHeight
|
|
1599
1603
|
};
|
|
1600
1604
|
const embed = useMemo(() => html !== void 0 ? parseEmbed(html) : matchUrl(url), [html, url]);
|
|
1601
|
-
|
|
1605
|
+
const unrecognised = embed === null && !(html !== void 0 && fallback);
|
|
1606
|
+
const lookup = html === void 0 ? needsLookup(url) : null;
|
|
1607
|
+
useReportError(unrecognised ? html !== void 0 ? "social-embeds: unrecognised embed code" : lookup ? lookupMessage(lookup) : `social-embeds: not a supported post URL: ${url}` : void 0, onError);
|
|
1602
1608
|
if (!embed) return html !== void 0 && fallback ? fallback(html) : null;
|
|
1603
1609
|
switch (embed.platform) {
|
|
1604
1610
|
case "x": return /* @__PURE__ */ jsx(XEmbed, {
|
|
@@ -747,6 +747,9 @@ const NOT_CHANNELS = /* @__PURE__ */ new Set([
|
|
|
747
747
|
"browse",
|
|
748
748
|
"categories",
|
|
749
749
|
"category",
|
|
750
|
+
"clips",
|
|
751
|
+
"video",
|
|
752
|
+
"videos",
|
|
750
753
|
"following",
|
|
751
754
|
"search",
|
|
752
755
|
"settings",
|
|
@@ -1127,8 +1130,16 @@ const soundcloud = {
|
|
|
1127
1130
|
if (root.tag !== "iframe") return null;
|
|
1128
1131
|
const src = parseUrl(root.attrs.get("src") ?? "");
|
|
1129
1132
|
if (src?.host !== "w.soundcloud.com" || !/^\/player\/?$/.test(src.path)) return null;
|
|
1130
|
-
|
|
1133
|
+
let found = fromApi(parseUrl(src.query.get("url") ?? ""));
|
|
1131
1134
|
if (!found) return null;
|
|
1135
|
+
const outer = src.query.get("secret_token");
|
|
1136
|
+
if (outer !== void 0) {
|
|
1137
|
+
if (!SECRET_TOKEN.test(outer)) return null;
|
|
1138
|
+
if (!found.url.includes("?")) found = {
|
|
1139
|
+
...found,
|
|
1140
|
+
url: `${found.url}?secret_token=${outer}`
|
|
1141
|
+
};
|
|
1142
|
+
}
|
|
1132
1143
|
const options = Object.fromEntries([...src.query].filter(([key]) => key !== "url" && key !== "secret_token").map(([key, value]) => [key, coerce(value)]));
|
|
1133
1144
|
const { height } = sizeOf(root) ?? {};
|
|
1134
1145
|
return withSize({
|
|
@@ -1385,12 +1396,13 @@ const tumblr = {
|
|
|
1385
1396
|
if (root.tag !== "div" || !hasClass(root, "tumblr-post")) return null;
|
|
1386
1397
|
const frame = parseUrl(root.attrs.get("data-href") ?? "");
|
|
1387
1398
|
if (frame?.host !== "embed.tumblr.com") return null;
|
|
1388
|
-
const [, , framePost] = FRAME_PATH.exec(frame.path) ?? [];
|
|
1399
|
+
const [, frameBlog, framePost] = FRAME_PATH.exec(frame.path) ?? [];
|
|
1389
1400
|
if (framePost === void 0) return null;
|
|
1390
1401
|
const [link, ...rest] = root.children.filter((node) => node.type !== "text" || node.raw.trim() !== "");
|
|
1391
1402
|
if (rest.length > 0 || link?.type !== "element" || link.tag !== "a") return null;
|
|
1392
1403
|
const found = fromUrl(parseUrl(link.attrs.get("href") ?? ""));
|
|
1393
1404
|
if (found?.id !== framePost) return null;
|
|
1405
|
+
if (frameBlog !== void 0 && found.url !== `https://www.tumblr.com/${frameBlog}/${framePost}`) return null;
|
|
1394
1406
|
return {
|
|
1395
1407
|
...found,
|
|
1396
1408
|
options: {}
|
|
@@ -1810,7 +1822,7 @@ function parseEmbed(html) {
|
|
|
1810
1822
|
}
|
|
1811
1823
|
if (!root) {
|
|
1812
1824
|
const [script] = scripts;
|
|
1813
|
-
if (fbRoot ||
|
|
1825
|
+
if (fbRoot || scripts.length !== 1 || !script) return null;
|
|
1814
1826
|
if (script.children.length !== 0) return null;
|
|
1815
1827
|
for (const platform of platforms) {
|
|
1816
1828
|
const embed = platform.parseScript?.(script);
|
|
@@ -1836,4 +1848,4 @@ function parseEmbed(html) {
|
|
|
1836
1848
|
function isFbRoot(element) {
|
|
1837
1849
|
return element.tag === "div" && element.attrs.get("id") === "fb-root" && element.attrs.size === 1 && element.children.length === 0;
|
|
1838
1850
|
}
|
|
1839
|
-
export {
|
|
1851
|
+
export { escapeAttribute as a, parseUrl as c, x as i, matchUrl as n, parseHtml as o, platforms as r, rebuild as s, parseEmbed as t };
|
package/dist/parser.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { n as matchUrl, t as parseEmbed } from "./parser-
|
|
1
|
+
export { n as matchUrl, t as parseEmbed } from "./parser-BSz1rCrV.js";
|