@tdacorp/hyle-sdk 0.14.1 → 0.21.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 +171 -32
- package/dist/check-routes-bin.js +48 -21
- package/dist/chunk-56Y24XBV.js +840 -0
- package/dist/{chunk-MGSUQBDW.js → chunk-75JFLML4.js} +176 -14
- package/dist/chunk-HJX57NLI.js +1105 -0
- package/dist/chunk-K5VDLROQ.js +145 -0
- package/dist/{chunk-BUJFMR3M.js → chunk-QVYQM5R2.js} +15 -6
- package/dist/chunk-U74B7AUG.js +398 -0
- package/dist/{chunk-6VOHFFA5.js → chunk-X2TLYM7Y.js} +2 -2
- package/dist/client-41fU6OY2.d.cts +201 -0
- package/dist/client-LwzHwqpM.d.ts +201 -0
- package/dist/code-copy.cjs +72 -0
- package/dist/code-copy.d.cts +15 -0
- package/dist/code-copy.d.ts +15 -0
- package/dist/code-copy.js +48 -0
- package/dist/comments.cjs +733 -278
- package/dist/comments.d.cts +66 -3
- package/dist/comments.d.ts +66 -3
- package/dist/comments.js +414 -330
- package/dist/{diagram-viewer-DYX6R63Y.js → diagram-viewer-XY3CG75U.js} +107 -46
- package/dist/{embed-B76zRRPa.d.cts → embed-BUFRQboD.d.ts} +10 -5
- package/dist/{embed-SqOBGI-E.d.ts → embed-CYt-q13P.d.cts} +10 -5
- package/dist/fragment-alias.cjs +51 -0
- package/dist/fragment-alias.d.cts +7 -0
- package/dist/fragment-alias.d.ts +7 -0
- package/dist/fragment-alias.js +27 -0
- package/dist/html.cjs +881 -0
- package/dist/html.d.cts +20 -0
- package/dist/html.d.ts +20 -0
- package/dist/html.js +45 -0
- package/dist/index.cjs +181 -14
- package/dist/index.d.cts +14 -62
- package/dist/index.d.ts +14 -62
- package/dist/index.js +11 -1
- package/dist/labels-CrA-iqTN.d.cts +46 -0
- package/dist/labels-CrA-iqTN.d.ts +46 -0
- package/dist/mermaid-diagram.cjs +453 -148
- package/dist/mermaid-diagram.d.cts +25 -42
- package/dist/mermaid-diagram.d.ts +25 -42
- package/dist/mermaid-diagram.js +205 -50
- package/dist/mermaid-image.cjs +1456 -0
- package/dist/mermaid-image.d.cts +30 -0
- package/dist/mermaid-image.d.ts +30 -0
- package/dist/mermaid-image.js +93 -0
- package/dist/next.cjs +1709 -1134
- package/dist/next.d.cts +67 -14
- package/dist/next.d.ts +67 -14
- package/dist/next.js +950 -794
- package/dist/print-coordinator.cjs +157 -0
- package/dist/print-coordinator.d.cts +27 -0
- package/dist/print-coordinator.d.ts +27 -0
- package/dist/print-coordinator.js +83 -0
- package/dist/react.cjs +677 -264
- package/dist/react.d.cts +161 -31
- package/dist/react.d.ts +161 -31
- package/dist/react.js +23 -3
- package/dist/reactions.cjs +653 -0
- package/dist/reactions.d.cts +27 -0
- package/dist/reactions.d.ts +27 -0
- package/dist/reactions.js +364 -0
- package/dist/{resolve-DC2ccfwA.d.ts → resolve-BjAK0k_Y.d.ts} +2 -2
- package/dist/{resolve-DKLVftk_.d.cts → resolve-eI1muCKL.d.cts} +2 -2
- package/dist/revalidation-callback-BQl77tQR.d.cts +75 -0
- package/dist/revalidation-callback-BQl77tQR.d.ts +75 -0
- package/dist/sanitize-ijiWjEm9.d.cts +23 -0
- package/dist/sanitize-ijiWjEm9.d.ts +23 -0
- package/dist/styles.css +107 -47
- package/dist/toc-spy.cjs +59 -0
- package/dist/toc-spy.d.cts +15 -0
- package/dist/toc-spy.d.ts +15 -0
- package/dist/toc-spy.js +35 -0
- package/dist/{types-ByodIyEv.d.cts → types-3F0wqD-o.d.cts} +44 -4
- package/dist/{types-ByodIyEv.d.ts → types-3F0wqD-o.d.ts} +44 -4
- package/dist/use-cache.cjs +37 -11
- package/dist/use-cache.d.cts +12 -5
- package/dist/use-cache.d.ts +12 -5
- package/dist/use-cache.js +7 -7
- package/dist/youtube-facade.cjs +50 -0
- package/dist/youtube-facade.d.cts +17 -0
- package/dist/youtube-facade.d.ts +17 -0
- package/dist/youtube-facade.js +26 -0
- package/package.json +16 -3
- package/dist/chunk-4V4VKB3O.js +0 -1471
- package/dist/chunk-R5EMI4HQ.js +0 -61
- package/dist/revalidation-callback-D7Ms_Puz.d.cts +0 -42
- package/dist/revalidation-callback-D7Ms_Puz.d.ts +0 -42
package/dist/use-cache.cjs
CHANGED
|
@@ -48,6 +48,18 @@ var Cp1ClientError = class extends Error {
|
|
|
48
48
|
};
|
|
49
49
|
|
|
50
50
|
// src/client.ts
|
|
51
|
+
var RENDERER_VERSION = "4";
|
|
52
|
+
function applyCredential(headers, credential, method, url) {
|
|
53
|
+
if (!credential.auth) {
|
|
54
|
+
headers.set("authorization", `Bearer ${credential.token}`);
|
|
55
|
+
return void 0;
|
|
56
|
+
}
|
|
57
|
+
const { workspaceId } = credential;
|
|
58
|
+
return credential.auth({ method, url }).then((extra) => {
|
|
59
|
+
for (const [name, value] of Object.entries(extra)) headers.set(name, value);
|
|
60
|
+
headers.set("cp-workspace", workspaceId);
|
|
61
|
+
});
|
|
62
|
+
}
|
|
51
63
|
var DEFAULT_TIMEOUT_MS = 1e4;
|
|
52
64
|
var DEFAULT_MAX_RESPONSE_BYTES = 5 * 1024 * 1024;
|
|
53
65
|
var LOOPBACK = /* @__PURE__ */ new Set(["localhost", "127.0.0.1", "[::1]"]);
|
|
@@ -89,14 +101,16 @@ function checkBaseUrl(baseUrl, allowInsecureHttp) {
|
|
|
89
101
|
}
|
|
90
102
|
function createHyleClient(options) {
|
|
91
103
|
checkBaseUrl(options.baseUrl, options.allowInsecureHttp);
|
|
92
|
-
if (!options.token) throw new TypeError("token is required");
|
|
104
|
+
if (!options.auth && !options.token) throw new TypeError("token is required");
|
|
93
105
|
const base = options.baseUrl.replace(/\/+$/, "");
|
|
94
106
|
const fetchImpl = options.fetch ?? fetch;
|
|
95
107
|
async function get(pathname, query, init) {
|
|
96
108
|
const url = new URL(`${base}${pathname}`);
|
|
97
109
|
url.search = query.toString();
|
|
98
110
|
const headers = new Headers(init?.headers);
|
|
99
|
-
headers.set("
|
|
111
|
+
headers.set("cp-renderer-version", RENDERER_VERSION);
|
|
112
|
+
const applied = applyCredential(headers, options, "GET", url.toString());
|
|
113
|
+
if (applied) await applied;
|
|
100
114
|
const timeout = AbortSignal.timeout(options.timeoutMs ?? DEFAULT_TIMEOUT_MS);
|
|
101
115
|
const signal = init?.signal ? AbortSignal.any([init.signal, timeout]) : timeout;
|
|
102
116
|
const res = await fetchImpl(url.toString(), { ...init, method: "GET", headers, redirect: "error", signal });
|
|
@@ -136,16 +150,28 @@ function createHyleClient(options) {
|
|
|
136
150
|
if (data?.cp === 1 && data.kind === "mounts" && isMounts(data)) return data;
|
|
137
151
|
throw failure(reply);
|
|
138
152
|
}
|
|
153
|
+
async function pushPosts(opts) {
|
|
154
|
+
if (!/^[a-z0-9]([a-z0-9-]*[a-z0-9])?$/.test(opts.section)) throw new TypeError("section must be a section slug");
|
|
155
|
+
const query = new URLSearchParams();
|
|
156
|
+
if (opts.cursor !== void 0) query.set("cursor", opts.cursor);
|
|
157
|
+
const reply = await get(`/cp1/read/sections/${opts.section}/posts`, query, opts.init);
|
|
158
|
+
const data = reply.parsed?.data;
|
|
159
|
+
if (data?.cp === 1 && data.kind === "push_posts" && Array.isArray(data.posts) && typeof data.complete === "boolean") return data;
|
|
160
|
+
throw failure(reply);
|
|
161
|
+
}
|
|
139
162
|
async function asset(file, opts = {}) {
|
|
140
163
|
if (!ASSET_FILE.test(file)) throw new TypeError("asset file must be <uuid>[.<ext>]");
|
|
141
|
-
const
|
|
164
|
+
const url = `${base}/cp1/read/assets/${file}`;
|
|
165
|
+
const headers = new Headers();
|
|
166
|
+
const applied = applyCredential(headers, options, "GET", url);
|
|
167
|
+
if (applied) await applied;
|
|
142
168
|
for (const name of ["range", "if-range", "if-none-match"]) {
|
|
143
169
|
const value = opts.headers?.[name];
|
|
144
170
|
if (value) headers.set(name, value);
|
|
145
171
|
}
|
|
146
|
-
return fetchImpl(
|
|
172
|
+
return fetchImpl(url, { method: "GET", headers, redirect: "error", signal: AbortSignal.timeout(opts.timeoutMs ?? options.timeoutMs ?? DEFAULT_TIMEOUT_MS) });
|
|
147
173
|
}
|
|
148
|
-
return { resolve, mounts, asset };
|
|
174
|
+
return { resolve, mounts, pushPosts, asset };
|
|
149
175
|
}
|
|
150
176
|
|
|
151
177
|
// src/tag-validation.ts
|
|
@@ -155,24 +181,24 @@ function isValidCacheTag(tag) {
|
|
|
155
181
|
}
|
|
156
182
|
|
|
157
183
|
// src/next/resolve.ts
|
|
158
|
-
var DEFAULT_REVALIDATE =
|
|
184
|
+
var DEFAULT_REVALIDATE = 86400;
|
|
159
185
|
|
|
160
186
|
// src/next/use-cache.ts
|
|
161
187
|
var MAX_TAGS = 128;
|
|
162
188
|
var DISABLED_REVALIDATE = 30;
|
|
163
|
-
var
|
|
189
|
+
var credentials = /* @__PURE__ */ new Map();
|
|
164
190
|
var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
|
|
165
191
|
async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
|
|
166
192
|
"use cache";
|
|
167
|
-
const
|
|
168
|
-
if (!
|
|
169
|
-
const result = await createHyleClient({ baseUrl,
|
|
193
|
+
const credential = credentials.get(keyOf(baseUrl, workspaceId));
|
|
194
|
+
if (!credential) throw new Error("hyle: unknown cache configuration");
|
|
195
|
+
const result = await createHyleClient({ baseUrl, ...credential }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
|
|
170
196
|
if (result.kind !== "disabled") (0, import_cache.cacheTag)(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
|
|
171
197
|
(0, import_cache.cacheLife)({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
|
|
172
198
|
return result;
|
|
173
199
|
}
|
|
174
200
|
function cachedResolver(options) {
|
|
175
|
-
|
|
201
|
+
credentials.set(keyOf(options.baseUrl, options.workspaceId), options.auth ? { auth: options.auth, workspaceId: options.workspaceId } : { token: options.token });
|
|
176
202
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
177
203
|
return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
|
|
178
204
|
}
|
package/dist/use-cache.d.cts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { H as
|
|
2
|
-
import './
|
|
1
|
+
import { H as HyleAuth } from './client-41fU6OY2.cjs';
|
|
2
|
+
import { H as HyleResolver } from './resolve-eI1muCKL.cjs';
|
|
3
|
+
import './types-3F0wqD-o.cjs';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
|
@@ -7,14 +8,20 @@ import './types-ByodIyEv.cjs';
|
|
|
7
8
|
* if the host enables `cacheComponents: true`; with it off, merely importing this file fails the build. That is why it is
|
|
8
9
|
* a separate entry (`@tdacorp/hyle-sdk/next/use-cache`) that a host imports only when it opts in.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
type CachedResolverOptions = {
|
|
11
12
|
readonly baseUrl: string;
|
|
12
13
|
/** The workspace id (HYLE_WORKSPACE_ID). With `baseUrl` it identifies the cache entries, so it must not be secret. */
|
|
13
14
|
readonly workspaceId: string;
|
|
14
|
-
|
|
15
|
+
/** `token` (a target credential) or `auth` (an identity machine token, `HyleAuth`); never part of a cache key. */
|
|
15
16
|
/** Seconds before a cached page is revalidated in the background. Webhooks purge sooner. Default 300. */
|
|
16
17
|
readonly revalidate?: number;
|
|
17
|
-
}
|
|
18
|
+
} & ({
|
|
19
|
+
readonly token: string;
|
|
20
|
+
readonly auth?: never;
|
|
21
|
+
} | {
|
|
22
|
+
readonly auth: HyleAuth;
|
|
23
|
+
readonly token?: never;
|
|
24
|
+
});
|
|
18
25
|
declare function cachedResolver(options: CachedResolverOptions): HyleResolver;
|
|
19
26
|
|
|
20
27
|
export { type CachedResolverOptions, cachedResolver };
|
package/dist/use-cache.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { H as
|
|
2
|
-
import './
|
|
1
|
+
import { H as HyleAuth } from './client-LwzHwqpM.js';
|
|
2
|
+
import { H as HyleResolver } from './resolve-BjAK0k_Y.js';
|
|
3
|
+
import './types-3F0wqD-o.js';
|
|
3
4
|
|
|
4
5
|
/**
|
|
5
6
|
* The exact caching strategy: a `'use cache'` function that fetches, then tags its own entry with the tags the response
|
|
@@ -7,14 +8,20 @@ import './types-ByodIyEv.js';
|
|
|
7
8
|
* if the host enables `cacheComponents: true`; with it off, merely importing this file fails the build. That is why it is
|
|
8
9
|
* a separate entry (`@tdacorp/hyle-sdk/next/use-cache`) that a host imports only when it opts in.
|
|
9
10
|
*/
|
|
10
|
-
|
|
11
|
+
type CachedResolverOptions = {
|
|
11
12
|
readonly baseUrl: string;
|
|
12
13
|
/** The workspace id (HYLE_WORKSPACE_ID). With `baseUrl` it identifies the cache entries, so it must not be secret. */
|
|
13
14
|
readonly workspaceId: string;
|
|
14
|
-
|
|
15
|
+
/** `token` (a target credential) or `auth` (an identity machine token, `HyleAuth`); never part of a cache key. */
|
|
15
16
|
/** Seconds before a cached page is revalidated in the background. Webhooks purge sooner. Default 300. */
|
|
16
17
|
readonly revalidate?: number;
|
|
17
|
-
}
|
|
18
|
+
} & ({
|
|
19
|
+
readonly token: string;
|
|
20
|
+
readonly auth?: never;
|
|
21
|
+
} | {
|
|
22
|
+
readonly auth: HyleAuth;
|
|
23
|
+
readonly token?: never;
|
|
24
|
+
});
|
|
18
25
|
declare function cachedResolver(options: CachedResolverOptions): HyleResolver;
|
|
19
26
|
|
|
20
27
|
export { type CachedResolverOptions, cachedResolver };
|
package/dist/use-cache.js
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DEFAULT_REVALIDATE
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-X2TLYM7Y.js";
|
|
4
4
|
import {
|
|
5
5
|
createHyleClient,
|
|
6
6
|
isValidCacheTag
|
|
7
|
-
} from "./chunk-
|
|
7
|
+
} from "./chunk-75JFLML4.js";
|
|
8
8
|
import "./chunk-67IOIAVW.js";
|
|
9
9
|
|
|
10
10
|
// src/next/use-cache.ts
|
|
11
11
|
import { cacheLife, cacheTag } from "next/cache";
|
|
12
12
|
var MAX_TAGS = 128;
|
|
13
13
|
var DISABLED_REVALIDATE = 30;
|
|
14
|
-
var
|
|
14
|
+
var credentials = /* @__PURE__ */ new Map();
|
|
15
15
|
var keyOf = (baseUrl, workspaceId) => `${baseUrl}\0${workspaceId}`;
|
|
16
16
|
async function resolveCached(baseUrl, workspaceId, path, locale, limit, cursor, nav, revalidate) {
|
|
17
17
|
"use cache";
|
|
18
|
-
const
|
|
19
|
-
if (!
|
|
20
|
-
const result = await createHyleClient({ baseUrl,
|
|
18
|
+
const credential = credentials.get(keyOf(baseUrl, workspaceId));
|
|
19
|
+
if (!credential) throw new Error("hyle: unknown cache configuration");
|
|
20
|
+
const result = await createHyleClient({ baseUrl, ...credential }).resolve({ path, ...locale ? { locale } : {}, ...limit > 0 ? { limit } : {}, ...cursor ? { cursor } : {}, ...nav === "tree" ? { nav: "tree" } : {} });
|
|
21
21
|
if (result.kind !== "disabled") cacheTag(...result.cache.tags.filter(isValidCacheTag).slice(0, MAX_TAGS));
|
|
22
22
|
cacheLife({ stale: 30, revalidate: result.kind === "disabled" ? Math.min(revalidate, DISABLED_REVALIDATE) : revalidate });
|
|
23
23
|
return result;
|
|
24
24
|
}
|
|
25
25
|
function cachedResolver(options) {
|
|
26
|
-
|
|
26
|
+
credentials.set(keyOf(options.baseUrl, options.workspaceId), options.auth ? { auth: options.auth, workspaceId: options.workspaceId } : { token: options.token });
|
|
27
27
|
const revalidate = options.revalidate ?? DEFAULT_REVALIDATE;
|
|
28
28
|
return (path, locale, limit, cursor, nav) => resolveCached(options.baseUrl, options.workspaceId, path, locale ?? "", limit ?? 0, cursor ?? "", nav ?? "", revalidate);
|
|
29
29
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/react/youtube-facade.tsx
|
|
22
|
+
var youtube_facade_exports = {};
|
|
23
|
+
__export(youtube_facade_exports, {
|
|
24
|
+
YouTubeFacade: () => YouTubeFacade
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(youtube_facade_exports);
|
|
27
|
+
var import_react = require("react");
|
|
28
|
+
var import_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
function YouTubeFacade({ videoId, playLabel, frameTitle, children }) {
|
|
30
|
+
const [playing, setPlaying] = (0, import_react.useState)(false);
|
|
31
|
+
const id = encodeURIComponent(videoId);
|
|
32
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)("div", { className: "hyle-youtube", "data-slot-component": "YouTube", children: [
|
|
33
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("div", { className: "hyle-youtube-stage", children: playing ? /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
|
|
34
|
+
"iframe",
|
|
35
|
+
{
|
|
36
|
+
ref: (frame) => frame?.focus(),
|
|
37
|
+
src: `https://www.youtube-nocookie.com/embed/${id}?autoplay=1`,
|
|
38
|
+
title: frameTitle,
|
|
39
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox",
|
|
40
|
+
allow: "autoplay; encrypted-media; fullscreen; picture-in-picture",
|
|
41
|
+
referrerPolicy: "strict-origin-when-cross-origin"
|
|
42
|
+
}
|
|
43
|
+
) : /* @__PURE__ */ (0, import_jsx_runtime.jsx)("button", { type: "button", "aria-label": playLabel, onClick: () => setPlaying(true), children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)("img", { src: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`, alt: "", loading: "lazy", decoding: "async", referrerPolicy: "no-referrer" }) }) }),
|
|
44
|
+
children
|
|
45
|
+
] });
|
|
46
|
+
}
|
|
47
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
48
|
+
0 && (module.exports = {
|
|
49
|
+
YouTubeFacade
|
|
50
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
interface YouTubeFacadeProps {
|
|
4
|
+
/** An 11 character video id the server already validated. */
|
|
5
|
+
videoId: string;
|
|
6
|
+
playLabel: string;
|
|
7
|
+
frameTitle: string;
|
|
8
|
+
/** The plain link to the video; it stays visible, with or without JavaScript. */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Click to load: until the click the only third-party request is the thumbnail from i.ytimg.com. The click swaps in a
|
|
13
|
+
* youtube-nocookie.com frame. `allow-same-origin` is safe here because the frame is another origin, never the host's.
|
|
14
|
+
*/
|
|
15
|
+
declare function YouTubeFacade({ videoId, playLabel, frameTitle, children }: YouTubeFacadeProps): ReactElement;
|
|
16
|
+
|
|
17
|
+
export { YouTubeFacade, type YouTubeFacadeProps };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { ReactNode, ReactElement } from 'react';
|
|
2
|
+
|
|
3
|
+
interface YouTubeFacadeProps {
|
|
4
|
+
/** An 11 character video id the server already validated. */
|
|
5
|
+
videoId: string;
|
|
6
|
+
playLabel: string;
|
|
7
|
+
frameTitle: string;
|
|
8
|
+
/** The plain link to the video; it stays visible, with or without JavaScript. */
|
|
9
|
+
children?: ReactNode;
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Click to load: until the click the only third-party request is the thumbnail from i.ytimg.com. The click swaps in a
|
|
13
|
+
* youtube-nocookie.com frame. `allow-same-origin` is safe here because the frame is another origin, never the host's.
|
|
14
|
+
*/
|
|
15
|
+
declare function YouTubeFacade({ videoId, playLabel, frameTitle, children }: YouTubeFacadeProps): ReactElement;
|
|
16
|
+
|
|
17
|
+
export { YouTubeFacade, type YouTubeFacadeProps };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/react/youtube-facade.tsx
|
|
4
|
+
import { useState } from "react";
|
|
5
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
6
|
+
function YouTubeFacade({ videoId, playLabel, frameTitle, children }) {
|
|
7
|
+
const [playing, setPlaying] = useState(false);
|
|
8
|
+
const id = encodeURIComponent(videoId);
|
|
9
|
+
return /* @__PURE__ */ jsxs("div", { className: "hyle-youtube", "data-slot-component": "YouTube", children: [
|
|
10
|
+
/* @__PURE__ */ jsx("div", { className: "hyle-youtube-stage", children: playing ? /* @__PURE__ */ jsx(
|
|
11
|
+
"iframe",
|
|
12
|
+
{
|
|
13
|
+
ref: (frame) => frame?.focus(),
|
|
14
|
+
src: `https://www.youtube-nocookie.com/embed/${id}?autoplay=1`,
|
|
15
|
+
title: frameTitle,
|
|
16
|
+
sandbox: "allow-scripts allow-same-origin allow-presentation allow-popups allow-popups-to-escape-sandbox",
|
|
17
|
+
allow: "autoplay; encrypted-media; fullscreen; picture-in-picture",
|
|
18
|
+
referrerPolicy: "strict-origin-when-cross-origin"
|
|
19
|
+
}
|
|
20
|
+
) : /* @__PURE__ */ jsx("button", { type: "button", "aria-label": playLabel, onClick: () => setPlaying(true), children: /* @__PURE__ */ jsx("img", { src: `https://i.ytimg.com/vi/${id}/hqdefault.jpg`, alt: "", loading: "lazy", decoding: "async", referrerPolicy: "no-referrer" }) }) }),
|
|
21
|
+
children
|
|
22
|
+
] });
|
|
23
|
+
}
|
|
24
|
+
export {
|
|
25
|
+
YouTubeFacade
|
|
26
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tdacorp/hyle-sdk",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"description": "hyle SDK: a typed client for hyle's resolve endpoint, a hast renderer for React, and a Next.js catch-all page with tag-based revalidation.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
@@ -40,6 +40,16 @@
|
|
|
40
40
|
"default": "./dist/react.cjs"
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
+
"./html": {
|
|
44
|
+
"import": {
|
|
45
|
+
"types": "./dist/html.d.ts",
|
|
46
|
+
"default": "./dist/html.js"
|
|
47
|
+
},
|
|
48
|
+
"require": {
|
|
49
|
+
"types": "./dist/html.d.cts",
|
|
50
|
+
"default": "./dist/html.cjs"
|
|
51
|
+
}
|
|
52
|
+
},
|
|
43
53
|
"./next": {
|
|
44
54
|
"import": {
|
|
45
55
|
"types": "./dist/next.d.ts",
|
|
@@ -76,8 +86,9 @@
|
|
|
76
86
|
"LICENSE"
|
|
77
87
|
],
|
|
78
88
|
"dependencies": {
|
|
89
|
+
"hast-util-to-html": "^9.0.5",
|
|
79
90
|
"hast-util-to-jsx-runtime": "^2.3.6",
|
|
80
|
-
"mermaid": "~11.
|
|
91
|
+
"mermaid": "~11.16.0"
|
|
81
92
|
},
|
|
82
93
|
"peerDependencies": {
|
|
83
94
|
"next": ">=16",
|
|
@@ -96,13 +107,15 @@
|
|
|
96
107
|
"@types/node": "^24.10.2",
|
|
97
108
|
"@types/react": "^19.2.18",
|
|
98
109
|
"@types/react-dom": "^19.2.5",
|
|
110
|
+
"jsdom": "^26.1.0",
|
|
99
111
|
"next": "^16.3.2",
|
|
100
112
|
"react": "19.2.8",
|
|
101
113
|
"react-dom": "19.2.8",
|
|
102
114
|
"tsup": "^8.5.1",
|
|
103
115
|
"typescript": "^5.9.3",
|
|
104
116
|
"vitest": "^4.1.10",
|
|
105
|
-
"@hyle/
|
|
117
|
+
"@hyle/content": "0.6.1",
|
|
118
|
+
"@hyle/renderer": "0.5.0"
|
|
106
119
|
},
|
|
107
120
|
"keywords": [
|
|
108
121
|
"hyle",
|