ludicord 2.2.5 → 3.0.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.
Files changed (150) hide show
  1. package/README.md +8 -4
  2. package/dist/activity/game-loop.d.ts +16 -0
  3. package/dist/activity/game-loop.js +33 -0
  4. package/dist/activity/index.d.ts +12 -0
  5. package/dist/activity/index.js +6 -0
  6. package/dist/activity/lifecycle.d.ts +11 -0
  7. package/dist/activity/lifecycle.js +41 -0
  8. package/dist/activity/presence.d.ts +10 -0
  9. package/dist/activity/presence.js +15 -0
  10. package/dist/activity/query.d.ts +21 -0
  11. package/dist/activity/query.js +148 -0
  12. package/dist/activity/shared-state.d.ts +10 -0
  13. package/dist/activity/shared-state.js +100 -0
  14. package/dist/activity/storage.d.ts +16 -0
  15. package/dist/activity/storage.js +88 -0
  16. package/dist/api/runtime.d.ts +5 -2
  17. package/dist/api/runtime.js +53 -10
  18. package/dist/auth/client.d.ts +0 -1
  19. package/dist/auth/client.js +3 -5
  20. package/dist/auth/index.d.ts +0 -1
  21. package/dist/auth/index.js +0 -1
  22. package/dist/auth/server.d.ts +2 -1
  23. package/dist/auth/server.js +161 -16
  24. package/dist/auth/types.d.ts +5 -1
  25. package/dist/auth/types.js +0 -1
  26. package/dist/cli/index.d.ts +0 -1
  27. package/dist/cli/index.js +116 -19
  28. package/dist/cli/project-commands.d.ts +1 -5
  29. package/dist/cli/project-commands.js +14 -162
  30. package/dist/compiler/build.d.ts +10 -1
  31. package/dist/compiler/build.js +124 -16
  32. package/dist/compiler/bundle-report.d.ts +17 -0
  33. package/dist/compiler/bundle-report.js +60 -0
  34. package/dist/compiler/client-entry.d.ts +0 -1
  35. package/dist/compiler/client-entry.js +28 -4
  36. package/dist/compiler/client-tooling.d.ts +0 -1
  37. package/dist/compiler/client-tooling.js +8 -2
  38. package/dist/compiler/index.d.ts +3 -1
  39. package/dist/compiler/index.js +2 -1
  40. package/dist/compiler/scanner.d.ts +0 -1
  41. package/dist/compiler/scanner.js +59 -4
  42. package/dist/compiler/server-bundle.d.ts +1 -2
  43. package/dist/compiler/server-bundle.js +11 -2
  44. package/dist/compiler/type-generation.d.ts +0 -1
  45. package/dist/compiler/type-generation.js +2 -1
  46. package/dist/compiler/write-manifests.d.ts +0 -1
  47. package/dist/compiler/write-manifests.js +0 -1
  48. package/dist/config/defaults.d.ts +0 -1
  49. package/dist/config/defaults.js +14 -2
  50. package/dist/config/environment.d.ts +0 -1
  51. package/dist/config/environment.js +0 -1
  52. package/dist/config/index.d.ts +0 -1
  53. package/dist/config/index.js +0 -1
  54. package/dist/config/loader.d.ts +0 -1
  55. package/dist/config/loader.js +0 -1
  56. package/dist/config/project-root.d.ts +0 -1
  57. package/dist/config/project-root.js +0 -1
  58. package/dist/config/types.d.ts +25 -1
  59. package/dist/config/types.js +0 -1
  60. package/dist/discord/assets.d.ts +5 -0
  61. package/dist/discord/assets.js +29 -0
  62. package/dist/discord/data.d.ts +38 -2
  63. package/dist/discord/data.js +178 -11
  64. package/dist/discord/events.d.ts +28 -2
  65. package/dist/discord/events.js +109 -39
  66. package/dist/discord/index.d.ts +6 -5
  67. package/dist/discord/index.js +3 -3
  68. package/dist/discord/payload.d.ts +6 -0
  69. package/dist/discord/payload.js +5 -0
  70. package/dist/discord/runtime.d.ts +0 -1
  71. package/dist/discord/runtime.js +0 -1
  72. package/dist/discord/safe-area.d.ts +0 -1
  73. package/dist/discord/safe-area.js +0 -1
  74. package/dist/discord/testing.d.ts +0 -1
  75. package/dist/discord/testing.js +0 -1
  76. package/dist/index.d.ts +6 -1
  77. package/dist/index.js +3 -1
  78. package/dist/lint/index.d.ts +6 -0
  79. package/dist/lint/index.js +71 -0
  80. package/dist/manifests/types.d.ts +11 -1
  81. package/dist/manifests/types.js +0 -1
  82. package/dist/metadata/index.d.ts +13 -0
  83. package/dist/metadata/index.js +4 -0
  84. package/dist/navigation/index.d.ts +3 -1
  85. package/dist/navigation/index.js +1 -1
  86. package/dist/navigation/link.d.ts +8 -0
  87. package/dist/navigation/link.js +38 -0
  88. package/dist/router/match.d.ts +0 -1
  89. package/dist/router/match.js +0 -1
  90. package/dist/runtime/client/dev-panel.d.ts +0 -1
  91. package/dist/runtime/client/dev-panel.js +722 -38
  92. package/dist/runtime/client/embed-router.d.ts +8 -1
  93. package/dist/runtime/client/embed-router.js +116 -62
  94. package/dist/runtime/client/files.d.ts +5 -1
  95. package/dist/runtime/client/files.js +0 -1
  96. package/dist/runtime/client/minimize-card.d.ts +0 -1
  97. package/dist/runtime/client/minimize-card.js +0 -1
  98. package/dist/runtime/client/minimize.d.ts +0 -1
  99. package/dist/runtime/client/minimize.js +0 -1
  100. package/dist/runtime/client/root.d.ts +5 -3
  101. package/dist/runtime/client/root.js +28 -3
  102. package/dist/runtime/index.d.ts +1 -2
  103. package/dist/runtime/index.js +0 -1
  104. package/dist/runtime/server/dev-server.d.ts +0 -1
  105. package/dist/runtime/server/dev-server.js +187 -30
  106. package/dist/runtime/server/diagnostics.d.ts +1 -1
  107. package/dist/runtime/server/diagnostics.js +5 -4
  108. package/dist/runtime/server/index.d.ts +0 -1
  109. package/dist/runtime/server/index.js +0 -1
  110. package/dist/runtime/server/production-server.d.ts +2 -1
  111. package/dist/runtime/server/production-server.js +145 -25
  112. package/dist/security/discord.d.ts +0 -1
  113. package/dist/security/discord.js +0 -1
  114. package/dist/security/index.d.ts +0 -1
  115. package/dist/security/index.js +0 -1
  116. package/dist/security/secret-scan.d.ts +0 -1
  117. package/dist/security/secret-scan.js +0 -1
  118. package/dist/server/discord-rest.d.ts +42 -7
  119. package/dist/server/discord-rest.js +135 -18
  120. package/dist/server/index.d.ts +7 -2
  121. package/dist/server/index.js +3 -1
  122. package/dist/server/instrumentation.d.ts +16 -0
  123. package/dist/server/instrumentation.js +3 -0
  124. package/dist/server/proxy.d.ts +21 -0
  125. package/dist/server/proxy.js +76 -0
  126. package/dist/server/session.d.ts +0 -1
  127. package/dist/server/session.js +0 -1
  128. package/dist/server/types.d.ts +0 -1
  129. package/dist/server/types.js +0 -1
  130. package/dist/sessions/cookies.d.ts +0 -1
  131. package/dist/sessions/cookies.js +0 -1
  132. package/dist/sessions/crypto.d.ts +0 -1
  133. package/dist/sessions/crypto.js +0 -1
  134. package/dist/sessions/data-store.d.ts +18 -0
  135. package/dist/sessions/data-store.js +45 -0
  136. package/dist/shared/errors.d.ts +0 -1
  137. package/dist/shared/errors.js +0 -1
  138. package/dist/testing/index.d.ts +0 -1
  139. package/dist/testing/index.js +2 -2
  140. package/dist/version.d.ts +1 -2
  141. package/dist/version.js +1 -2
  142. package/dist/ws/client.d.ts +0 -1
  143. package/dist/ws/client.js +0 -1
  144. package/dist/ws/index.d.ts +3 -2
  145. package/dist/ws/index.js +1 -1
  146. package/dist/ws/server.d.ts +5 -3
  147. package/dist/ws/server.js +65 -19
  148. package/dist/ws/shared-state.d.ts +13 -0
  149. package/dist/ws/shared-state.js +137 -0
  150. package/package.json +14 -1
@@ -7,6 +7,14 @@ export interface LudicordEmbedModule {
7
7
  export interface LudicordEmbedDefinition {
8
8
  readonly route: string;
9
9
  readonly load: () => Promise<LudicordEmbedModule>;
10
+ readonly loading?: ComponentType;
11
+ readonly error?: ComponentType<{
12
+ readonly error: Error;
13
+ readonly reset: () => void;
14
+ }>;
15
+ readonly layouts?: readonly ComponentType<{
16
+ readonly children: ReactNode;
17
+ }>[];
10
18
  }
11
19
  export interface LudicordActivityProps {
12
20
  readonly defaultEmbed: string;
@@ -47,4 +55,3 @@ export declare function LudicordLoadingBoundary({ children, fallback, }: {
47
55
  readonly fallback?: ReactNode;
48
56
  }): import("react").JSX.Element;
49
57
  export {};
50
- //# sourceMappingURL=embed-router.d.ts.map
@@ -8,7 +8,9 @@ import { useOptionalLudicordMinimize } from "./minimize.js";
8
8
  import { useLudicordFiles, isDevelopmentRuntime, reportClientError } from "./files.js";
9
9
  import { installLudicordSafeAreaVariables } from "../../discord/safe-area.js";
10
10
  const EmbedContext = createContext(null);
11
+ const HISTORY_INDEX = "__ludicordEmbedIndex";
11
12
  const lazyComponentCache = new WeakMap();
13
+ const modulePromiseCache = new WeakMap();
12
14
  export class LudicordEmbedNotFoundError extends Error {
13
15
  code = "LUDICORD2001";
14
16
  constructor(path) {
@@ -101,16 +103,29 @@ function globalDefinitions() {
101
103
  const registry = globalThis.__LUDICORD_EMBEDS__;
102
104
  if (registry === undefined)
103
105
  return [];
104
- return Object.entries(registry).map(([route, load]) => ({ route, load }));
106
+ return Object.entries(registry).map(([route, definition]) => typeof definition === "function"
107
+ ? { route, load: definition }
108
+ : { route, ...definition });
105
109
  }
106
110
  function getLazyComponent(definition) {
107
111
  const cached = lazyComponentCache.get(definition.load);
108
112
  if (cached !== undefined)
109
113
  return cached;
110
- const component = lazy(definition.load);
114
+ const component = lazy(() => loadEmbedModule(definition));
111
115
  lazyComponentCache.set(definition.load, component);
112
116
  return component;
113
117
  }
118
+ function loadEmbedModule(definition) {
119
+ const cached = modulePromiseCache.get(definition.load);
120
+ if (cached !== undefined)
121
+ return cached;
122
+ const promise = definition.load().catch((error) => {
123
+ modulePromiseCache.delete(definition.load);
124
+ throw error;
125
+ });
126
+ modulePromiseCache.set(definition.load, promise);
127
+ return promise;
128
+ }
114
129
  function useEmbedContext() {
115
130
  const context = useContext(EmbedContext);
116
131
  if (context === null) {
@@ -139,88 +154,104 @@ export function LudicordActivity({ defaultEmbed, children, embeds, loading = nul
139
154
  const definitions = useMemo(() => [...(embeds ?? globalDefinitions())], [embeds]);
140
155
  const initialPath = normalizeEmbedPath(defaultEmbed);
141
156
  const [state, setState] = useState(() => {
142
- let path = initialPath;
143
- try {
144
- path = findMatch(definitions, hashEmbedPath(initialPath)).path;
145
- }
146
- catch {
147
- if (typeof window !== "undefined")
148
- window.history.replaceState(null, "", embedHash(initialPath, initialPath));
149
- }
157
+ const path = hashEmbedPath(initialPath);
150
158
  return { entries: [path], index: 0 };
151
159
  });
152
160
  useEffect(() => {
153
- if (window.location.hash === "")
154
- window.history.replaceState(null, "", "#/");
155
- const onHashChange = () => {
161
+ const historyState = window.history.state;
162
+ window.history.replaceState(historyState !== null && typeof historyState === "object"
163
+ ? { ...historyState, [HISTORY_INDEX]: 0 }
164
+ : { [HISTORY_INDEX]: 0 }, "", window.location.hash === "" ? "#/" : window.location.href);
165
+ const onLocationChange = (event) => {
156
166
  const nextPath = hashEmbedPath(initialPath);
157
- try {
158
- findMatch(definitions, nextPath);
159
- }
160
- catch (cause) {
161
- reportClientError(cause instanceof Error ? cause : new Error(String(cause)));
162
- window.history.replaceState(null, "", embedHash(initialPath, initialPath));
163
- setState({ entries: [initialPath], index: 0 });
164
- return;
165
- }
166
167
  setState((current) => {
168
+ const eventState = "state" in event ? event.state : undefined;
169
+ const historyIndex = eventState !== null &&
170
+ typeof eventState === "object" &&
171
+ typeof eventState[HISTORY_INDEX] === "number"
172
+ ? eventState[HISTORY_INDEX]
173
+ : undefined;
174
+ if (historyIndex !== undefined &&
175
+ historyIndex >= 0 &&
176
+ historyIndex < current.entries.length &&
177
+ current.entries[historyIndex] === nextPath) {
178
+ return { ...current, index: historyIndex };
179
+ }
167
180
  const currentPath = current.entries[current.index];
168
- return currentPath === nextPath
169
- ? current
170
- : {
171
- entries: [...current.entries.slice(0, current.index + 1), nextPath],
172
- index: current.index + 1,
173
- };
181
+ if (currentPath === nextPath)
182
+ return current;
183
+ const existingIndex = current.entries.lastIndexOf(nextPath);
184
+ if (existingIndex >= 0)
185
+ return { ...current, index: existingIndex };
186
+ const entries = [...current.entries.slice(0, current.index + 1), nextPath];
187
+ window.history.replaceState({ [HISTORY_INDEX]: entries.length - 1 }, "", window.location.href);
188
+ return { entries, index: entries.length - 1 };
174
189
  });
175
190
  };
176
- window.addEventListener("hashchange", onHashChange);
177
- return () => window.removeEventListener("hashchange", onHashChange);
178
- }, [initialPath, definitions]);
191
+ window.addEventListener("hashchange", onLocationChange);
192
+ window.addEventListener("popstate", onLocationChange);
193
+ return () => {
194
+ window.removeEventListener("hashchange", onLocationChange);
195
+ window.removeEventListener("popstate", onLocationChange);
196
+ };
197
+ }, [initialPath]);
179
198
  const currentPath = state.entries[state.index] ?? initialPath;
180
- const match = useMemo(() => findMatch(definitions, currentPath), [currentPath, definitions]);
199
+ const match = useMemo(() => {
200
+ try {
201
+ return findMatch(definitions, currentPath);
202
+ }
203
+ catch (error) {
204
+ if (error instanceof LudicordEmbedNotFoundError)
205
+ return null;
206
+ throw error;
207
+ }
208
+ }, [currentPath, definitions]);
181
209
  const push = useCallback((path) => {
182
210
  const normalized = normalizeEmbedPath(path);
183
211
  findMatch(definitions, normalized);
184
- if (typeof window !== "undefined")
185
- window.history.replaceState(null, "", embedHash(normalized, initialPath));
186
- setState((current) => ({
187
- entries: [...current.entries.slice(0, current.index + 1), normalized],
188
- index: current.index + 1,
189
- }));
190
- }, [definitions, initialPath]);
212
+ const entries = [...state.entries.slice(0, state.index + 1), normalized];
213
+ const index = state.index + 1;
214
+ if (typeof window !== "undefined") {
215
+ window.history.pushState({ [HISTORY_INDEX]: index }, "", embedHash(normalized, initialPath));
216
+ }
217
+ setState({ entries, index });
218
+ }, [definitions, initialPath, state]);
191
219
  const replace = useCallback((path) => {
192
220
  const normalized = normalizeEmbedPath(path);
193
221
  findMatch(definitions, normalized);
194
222
  if (typeof window !== "undefined")
195
- window.history.replaceState(null, "", embedHash(normalized, initialPath));
196
- setState((current) => ({
197
- entries: current.entries.map((entry, index) => index === current.index ? normalized : entry),
198
- index: current.index,
199
- }));
200
- }, [definitions, initialPath]);
201
- const back = useCallback(() => {
202
- setState((current) => {
203
- if (current.index === 0)
204
- return current;
205
- const previousPath = current.entries[current.index - 1];
206
- if (previousPath !== undefined && typeof window !== "undefined") {
207
- window.history.replaceState(null, "", embedHash(previousPath, initialPath));
208
- }
209
- return { ...current, index: current.index - 1 };
223
+ window.history.replaceState({ [HISTORY_INDEX]: state.index }, "", embedHash(normalized, initialPath));
224
+ setState({
225
+ entries: state.entries.map((entry, index) => index === state.index ? normalized : entry),
226
+ index: state.index,
210
227
  });
211
- }, [initialPath]);
228
+ }, [definitions, initialPath, state]);
229
+ const back = useCallback(() => {
230
+ if (state.index === 0)
231
+ return;
232
+ setState({ ...state, index: state.index - 1 });
233
+ if (typeof window !== "undefined")
234
+ window.history.back();
235
+ }, [state]);
236
+ const prefetch = useCallback(async (path) => {
237
+ const normalized = normalizeEmbedPath(path);
238
+ const selected = findMatch(definitions, normalized);
239
+ await loadEmbedModule(selected.definition);
240
+ }, [definitions]);
212
241
  const router = useMemo(() => ({
213
242
  push: push,
214
243
  replace: replace,
244
+ prefetch: prefetch,
215
245
  back,
216
246
  canGoBack: state.index > 0,
217
- }), [back, push, replace, state.index]);
247
+ }), [back, prefetch, push, replace, state.index]);
218
248
  const value = useMemo(() => ({
219
249
  router,
220
250
  match,
251
+ path: currentPath,
221
252
  loading: loading ?? (Loading === undefined ? null : _jsx(Loading, {})),
222
253
  ...(errorFallback !== undefined ? { errorFallback } : ErrorFile === undefined ? {} : { errorFallback: (error) => _jsx(ErrorFile, { error: error, reset: () => window.dispatchEvent(new Event("ludicord:recover")) }) }),
223
- }), [errorFallback, loading, match, router, Loading, ErrorFile]);
254
+ }), [currentPath, errorFallback, loading, match, router, Loading, ErrorFile]);
224
255
  return _jsx(EmbedContext.Provider, { value: value, children: _jsxs(ActivityAuthGate, { children: [_jsx("div", { hidden: minimized, style: { display: minimized ? "none" : "contents" }, children: children }), minimized && Minimized !== undefined ? _jsx(Minimized, {}) : null] }) });
225
256
  }
226
257
  function ActivityAuthGate({ children }) {
@@ -247,18 +278,42 @@ function ActivityAuthGate({ children }) {
247
278
  return Loading === undefined ? _jsx("main", { role: "status", style: { padding: 24, fontFamily: "system-ui" }, children: "Connecting to Discord\u2026" }) : _jsx(Loading, {});
248
279
  }
249
280
  export function EmbedOutlet() {
250
- const { match, loading, errorFallback } = useEmbedContext();
281
+ const { match, path, router, loading, errorFallback } = useEmbedContext();
282
+ const files = useLudicordFiles();
283
+ if (match === null) {
284
+ const NotFound = files.notFound;
285
+ return NotFound === undefined
286
+ ? _jsx(DefaultNotFound, { path: path, router: router })
287
+ : _jsx(NotFound, {});
288
+ }
251
289
  const Embed = getLazyComponent(match.definition);
252
- return (_jsx(LudicordErrorBoundary, { fallback: errorFallback, resetKey: match.path, children: _jsx(LudicordLoadingBoundary, { fallback: loading, children: _jsx(Embed, {}) }) }));
290
+ const RouteLoading = match.definition.loading;
291
+ const RouteError = match.definition.error;
292
+ const reset = () => window.dispatchEvent(new Event("ludicord:recover"));
293
+ const routeFallback = RouteLoading === undefined ? loading : _jsx(RouteLoading, {});
294
+ const routeErrorFallback = RouteError === undefined
295
+ ? errorFallback
296
+ : (error) => _jsx(RouteError, { error: error, reset: reset });
297
+ const content = (match.definition.layouts ?? []).reduceRight((children, Layout) => _jsx(Layout, { children: children }), _jsx(Embed, {}));
298
+ return (_jsx(LudicordErrorBoundary, { fallback: routeErrorFallback, resetKey: match.path, children: _jsx(LudicordLoadingBoundary, { fallback: routeFallback, children: content }) }));
253
299
  }
254
300
  export function useEmbedRouter() {
255
301
  return useEmbedContext().router;
256
302
  }
257
303
  export function useEmbedPath() {
258
- return useEmbedContext().match.path;
304
+ return useEmbedContext().path;
259
305
  }
260
306
  export function useEmbedParams() {
261
- return useEmbedContext().match.params;
307
+ return (useEmbedContext().match?.params ?? {});
308
+ }
309
+ function DefaultNotFound({ path, router }) {
310
+ const goBack = () => {
311
+ if (router.canGoBack)
312
+ router.back();
313
+ else if (typeof window !== "undefined")
314
+ window.history.back();
315
+ };
316
+ return _jsx("main", { "data-ludicord-not-found": "", style: { minHeight: "100vh", display: "grid", placeItems: "center", padding: 24, color: "#f5f5f5", background: "#0a0a0a", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }, children: _jsxs("section", { role: "alert", "aria-labelledby": "ludicord-not-found-title", style: { width: "min(100%, 320px)" }, children: [_jsxs("svg", { width: "24", height: "24", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", style: { marginBottom: 14 }, children: [_jsx("path", { d: "M12 3 2.8 20h18.4L12 3Z", stroke: "currentColor", strokeWidth: "1.8", strokeLinejoin: "round" }), _jsx("path", { d: "M12 9v5m0 3.2v.1", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round" })] }), _jsx("h1", { id: "ludicord-not-found-title", style: { margin: "0 0 8px", fontSize: 20, lineHeight: 1.35, letterSpacing: "-.02em" }, children: "This page couldn\u2019t load" }), _jsxs("p", { style: { margin: "0 0 18px", color: "#a3a3a3", fontSize: 13, lineHeight: 1.6 }, children: ["The Activity route ", _jsx("code", { style: { color: "#d4d4d4" }, children: path }), " wasn\u2019t found. Reload to try again, or go back."] }), _jsxs("div", { style: { display: "flex", gap: 8 }, children: [_jsx("button", { type: "button", onClick: () => window.location.reload(), style: { padding: "7px 12px", border: "1px solid #e5e5e5", borderRadius: 6, color: "#111", background: "#f5f5f5", font: "inherit", fontSize: 13, fontWeight: 600, cursor: "pointer" }, children: "Reload" }), _jsx("button", { type: "button", onClick: goBack, style: { padding: "7px 12px", border: "1px solid #292929", borderRadius: 6, color: "#e5e5e5", background: "#111", font: "inherit", fontSize: 13, cursor: "pointer" }, children: "Back" })] })] }) });
262
317
  }
263
318
  export class LudicordErrorBoundary extends Component {
264
319
  state = { error: null };
@@ -292,4 +347,3 @@ export class LudicordErrorBoundary extends Component {
292
347
  export function LudicordLoadingBoundary({ children, fallback = null, }) {
293
348
  return _jsx(Suspense, { fallback: fallback, children: children });
294
349
  }
295
- //# sourceMappingURL=embed-router.js.map
@@ -8,6 +8,11 @@ export interface LudicordFileComponents {
8
8
  readonly error: Error;
9
9
  readonly reset: () => void;
10
10
  }>;
11
+ readonly globalError?: ComponentType<{
12
+ readonly error: Error;
13
+ readonly reset: () => void;
14
+ }>;
15
+ readonly notFound?: ComponentType;
11
16
  readonly minimize?: ComponentType;
12
17
  readonly authLoading?: ComponentType;
13
18
  readonly authError?: ComponentType<{
@@ -20,4 +25,3 @@ export declare const LudicordFilesContext: import("react").Context<LudicordFileC
20
25
  export declare function useLudicordFiles(): LudicordFileComponents;
21
26
  export declare function isDevelopmentRuntime(): boolean;
22
27
  export declare function reportClientError(error: Error, componentStack?: string | null): void;
23
- //# sourceMappingURL=files.d.ts.map
@@ -9,4 +9,3 @@ export function reportClientError(error, componentStack) {
9
9
  return;
10
10
  window.dispatchEvent(new CustomEvent("ludicord:runtime-error", { detail: { message: error.message, stack: error.stack, componentStack } }));
11
11
  }
12
- //# sourceMappingURL=files.js.map
@@ -10,4 +10,3 @@ export interface MinimizeProps {
10
10
  readonly children?: ReactNode;
11
11
  }
12
12
  export declare function Minimize({ heading, message, author: customAuthor, channelName: customChannelName, timestamp, avatar: customAvatar, card, children, }?: MinimizeProps): import("react").JSX.Element;
13
- //# sourceMappingURL=minimize-card.d.ts.map
@@ -16,4 +16,3 @@ export function Minimize({ heading = "Message preview", message = "Welcome to th
16
16
  toggle();
17
17
  }, role: "button", tabIndex: 0, children: content })] }));
18
18
  }
19
- //# sourceMappingURL=minimize-card.js.map
@@ -12,4 +12,3 @@ export interface LudicordMinimizeProviderProps {
12
12
  export declare function LudicordMinimizeProvider({ children, defaultMinimized, }: LudicordMinimizeProviderProps): import("react").JSX.Element;
13
13
  export declare function useLudicordMinimize(): LudicordMinimizeState;
14
14
  export declare function useOptionalLudicordMinimize(): LudicordMinimizeState | null;
15
- //# sourceMappingURL=minimize.d.ts.map
@@ -19,4 +19,3 @@ export function useLudicordMinimize() {
19
19
  return value;
20
20
  }
21
21
  export function useOptionalLudicordMinimize() { return useContext(MinimizeContext); }
22
- //# sourceMappingURL=minimize.js.map
@@ -1,7 +1,9 @@
1
1
  import type { ReactNode } from "react";
2
2
  import type { LudicordFileComponents } from "./files.js";
3
- export declare function LudicordRoot({ children, files }: {
3
+ import type { LudicordMetadata } from "../../metadata/index.js";
4
+ export interface LudicordRootProps {
4
5
  readonly children: ReactNode;
5
6
  readonly files?: LudicordFileComponents;
6
- }): import("react").JSX.Element;
7
- //# sourceMappingURL=root.d.ts.map
7
+ readonly metadata?: LudicordMetadata;
8
+ }
9
+ export declare function LudicordRoot({ children, files, metadata }: LudicordRootProps): import("react").JSX.Element;
@@ -3,8 +3,34 @@ import { useEffect, useState } from "react";
3
3
  import { LudicordErrorBoundary, LudicordLoadingBoundary } from "./embed-router.js";
4
4
  import { LudicordMinimizeProvider } from "./minimize.js";
5
5
  import { LudicordFilesContext } from "./files.js";
6
- export function LudicordRoot({ children, files = {} }) {
6
+ function metadataTitle(title) {
7
+ return typeof title === "string" ? title : title?.default;
8
+ }
9
+ function updateMeta(name, content) {
10
+ const selector = `meta[name="${name}"][data-ludicord-metadata]`;
11
+ const current = document.head.querySelector(selector);
12
+ if (content === undefined) {
13
+ current?.remove();
14
+ return;
15
+ }
16
+ const element = current ?? document.createElement("meta");
17
+ element.name = name;
18
+ element.content = content;
19
+ element.dataset.ludicordMetadata = "";
20
+ if (current === null)
21
+ document.head.append(element);
22
+ }
23
+ export function LudicordRoot({ children, files = {}, metadata }) {
7
24
  const [revision, setRevision] = useState(0);
25
+ useEffect(() => {
26
+ const title = metadataTitle(metadata?.title);
27
+ if (title !== undefined)
28
+ document.title = title;
29
+ updateMeta("description", metadata?.description);
30
+ updateMeta("application-name", metadata?.applicationName);
31
+ updateMeta("theme-color", metadata?.themeColor);
32
+ updateMeta("color-scheme", metadata?.colorScheme);
33
+ }, [metadata]);
8
34
  useEffect(() => {
9
35
  const recover = () => setRevision((value) => value + 1);
10
36
  window.addEventListener("ludicord:recover", recover);
@@ -12,8 +38,7 @@ export function LudicordRoot({ children, files = {} }) {
12
38
  }, []);
13
39
  const Layout = files.layout;
14
40
  const Loading = files.loading;
15
- const ErrorFile = files.error;
41
+ const ErrorFile = files.globalError ?? files.error;
16
42
  const reset = () => setRevision((value) => value + 1);
17
43
  return _jsx(LudicordFilesContext.Provider, { value: files, children: _jsx(LudicordMinimizeProvider, { children: _jsx(LudicordErrorBoundary, { resetKey: String(revision), fallback: ErrorFile === undefined ? undefined : (error) => _jsx(ErrorFile, { error: error, reset: reset }), children: _jsx(LudicordLoadingBoundary, { fallback: Loading === undefined ? null : _jsx(Loading, {}), children: Layout === undefined ? children : _jsx(Layout, { children: children }) }) }) }) });
18
44
  }
19
- //# sourceMappingURL=root.js.map
@@ -1,9 +1,8 @@
1
1
  export declare function useLudicordRuntime(): {
2
2
  readonly environment: string;
3
- readonly version: "2.2.5";
3
+ readonly version: "3.0.0";
4
4
  readonly activityReady: boolean;
5
5
  readonly discordReady: boolean;
6
6
  readonly authStatus: import("../auth/types.js").LudicordAuthStatus;
7
7
  readonly wsReady: boolean;
8
8
  };
9
- //# sourceMappingURL=index.d.ts.map
@@ -12,4 +12,3 @@ export function useLudicordRuntime() {
12
12
  const config = globalThis.__LUDICORD_PUBLIC_CONFIG__;
13
13
  return { environment: config?.environment ?? "production", version: LUDICORD_VERSION, activityReady, discordReady: discord.status === "ready", authStatus, wsReady };
14
14
  }
15
- //# sourceMappingURL=index.js.map
@@ -22,4 +22,3 @@ export interface LudicordDevServer {
22
22
  close(): Promise<void>;
23
23
  }
24
24
  export declare function createLudicordDevServer(options: LudicordDevServerOptions): Promise<LudicordDevServer>;
25
- //# sourceMappingURL=dev-server.d.ts.map