@octanejs/remix-router 0.1.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 (63) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +90 -0
  3. package/package.json +53 -0
  4. package/src/dom.ts +16 -0
  5. package/src/index.ts +267 -0
  6. package/src/internal.ts +37 -0
  7. package/src/lib/Await.tsrx +145 -0
  8. package/src/lib/Await.tsrx.d.ts +6 -0
  9. package/src/lib/DefaultErrorComponent.tsrx +47 -0
  10. package/src/lib/DefaultErrorComponent.tsrx.d.ts +2 -0
  11. package/src/lib/RenderErrorBoundary.tsrx +117 -0
  12. package/src/lib/RenderErrorBoundary.tsrx.d.ts +14 -0
  13. package/src/lib/actions.ts +90 -0
  14. package/src/lib/components/MemoryRouter.tsrx +42 -0
  15. package/src/lib/components/MemoryRouter.tsrx.d.ts +10 -0
  16. package/src/lib/components/Navigate.ts +60 -0
  17. package/src/lib/components/Router.tsrx +88 -0
  18. package/src/lib/components/Router.tsrx.d.ts +13 -0
  19. package/src/lib/components/RouterProvider.tsrx +320 -0
  20. package/src/lib/components/RouterProvider.tsrx.d.ts +21 -0
  21. package/src/lib/components/Routes.tsrx +53 -0
  22. package/src/lib/components/Routes.tsrx.d.ts +7 -0
  23. package/src/lib/components/routes-collector.ts +317 -0
  24. package/src/lib/components/utils.ts +171 -0
  25. package/src/lib/components/with-props.ts +72 -0
  26. package/src/lib/context.ts +129 -0
  27. package/src/lib/dom/Form.tsrx +76 -0
  28. package/src/lib/dom/Form.tsrx.d.ts +22 -0
  29. package/src/lib/dom/Link.tsrx +91 -0
  30. package/src/lib/dom/Link.tsrx.d.ts +22 -0
  31. package/src/lib/dom/NavLink.tsrx +118 -0
  32. package/src/lib/dom/NavLink.tsrx.d.ts +33 -0
  33. package/src/lib/dom/dom.ts +344 -0
  34. package/src/lib/dom/hooks.ts +93 -0
  35. package/src/lib/dom/lib.ts +822 -0
  36. package/src/lib/dom/routers.tsrx +104 -0
  37. package/src/lib/dom/routers.tsrx.d.ts +23 -0
  38. package/src/lib/dom/server.tsrx +350 -0
  39. package/src/lib/dom/server.tsrx.d.ts +25 -0
  40. package/src/lib/errors.ts +84 -0
  41. package/src/lib/framework-stubs.ts +103 -0
  42. package/src/lib/hooks.ts +1797 -0
  43. package/src/lib/href.ts +71 -0
  44. package/src/lib/react-types.ts +10 -0
  45. package/src/lib/router/history.ts +763 -0
  46. package/src/lib/router/instrumentation.ts +496 -0
  47. package/src/lib/router/links.ts +192 -0
  48. package/src/lib/router/router.ts +7165 -0
  49. package/src/lib/router/server-runtime-types.ts +12 -0
  50. package/src/lib/router/url.ts +8 -0
  51. package/src/lib/router/utils.ts +2179 -0
  52. package/src/lib/server-runtime/cookies.ts +240 -0
  53. package/src/lib/server-runtime/crypto.ts +55 -0
  54. package/src/lib/server-runtime/mode.ts +16 -0
  55. package/src/lib/server-runtime/sessions/cookieStorage.ts +54 -0
  56. package/src/lib/server-runtime/sessions/memoryStorage.ts +59 -0
  57. package/src/lib/server-runtime/sessions.ts +291 -0
  58. package/src/lib/server-runtime/warnings.ts +10 -0
  59. package/src/lib/types/future.ts +16 -0
  60. package/src/lib/types/params.ts +8 -0
  61. package/src/lib/types/register.ts +39 -0
  62. package/src/lib/types/route-module.ts +17 -0
  63. package/src/lib/types/utils.ts +37 -0
@@ -0,0 +1,496 @@
1
+ // Vendored from react-router@7.18.1 packages/react-router/lib/router/instrumentation.ts — unmodified except: type-only ../server-runtime/* imports → local ./server-runtime-types stub.
2
+ // Re-vendor with `node scripts/vendor-remix-router.mjs`; never hand-edit.
3
+ import type { AppLoadContext, RequestHandler } from './server-runtime-types';
4
+ import type { MiddlewareEnabled } from '../types/future';
5
+ import { createPath, invariant } from './history';
6
+ import type { Router } from './router';
7
+ import type {
8
+ ActionFunctionArgs,
9
+ DataRouteObject,
10
+ FormEncType,
11
+ HTMLFormMethod,
12
+ LazyRouteObject,
13
+ LoaderFunction,
14
+ LoaderFunctionArgs,
15
+ MaybePromise,
16
+ MiddlewareFunction,
17
+ RouterContext,
18
+ RouterContextProvider,
19
+ } from './utils';
20
+
21
+ // Public APIs
22
+ export type ServerInstrumentation = {
23
+ handler?: InstrumentRequestHandlerFunction;
24
+ route?: InstrumentRouteFunction;
25
+ };
26
+
27
+ export type ClientInstrumentation = {
28
+ router?: InstrumentRouterFunction;
29
+ route?: InstrumentRouteFunction;
30
+ };
31
+
32
+ export type InstrumentRequestHandlerFunction = (handler: InstrumentableRequestHandler) => void;
33
+
34
+ export type InstrumentRouterFunction = (router: InstrumentableRouter) => void;
35
+
36
+ export type InstrumentRouteFunction = (route: InstrumentableRoute) => void;
37
+
38
+ export type InstrumentationHandlerResult =
39
+ | { status: 'success'; error: undefined }
40
+ | { status: 'error'; error: Error };
41
+
42
+ // Shared
43
+ type InstrumentFunction<T> = (
44
+ handler: () => Promise<InstrumentationHandlerResult>,
45
+ info: T,
46
+ ) => Promise<void>;
47
+
48
+ type InstrumentationInfo =
49
+ | RouteLazyInstrumentationInfo
50
+ | RouteHandlerInstrumentationInfo
51
+ | RouterNavigationInstrumentationInfo
52
+ | RouterFetchInstrumentationInfo
53
+ | RequestHandlerInstrumentationInfo;
54
+
55
+ type ReadonlyRequest = {
56
+ method: string;
57
+ url: string;
58
+ headers: Pick<Headers, 'get'>;
59
+ };
60
+
61
+ type ReadonlyContext = MiddlewareEnabled extends true
62
+ ? Pick<RouterContextProvider, 'get'>
63
+ : Readonly<AppLoadContext>;
64
+
65
+ // Route Instrumentation
66
+ type InstrumentableRoute = {
67
+ id: string;
68
+ index: boolean | undefined;
69
+ path: string | undefined;
70
+ instrument(instrumentations: RouteInstrumentations): void;
71
+ };
72
+
73
+ type RouteInstrumentations = {
74
+ lazy?: InstrumentFunction<RouteLazyInstrumentationInfo>;
75
+ 'lazy.loader'?: InstrumentFunction<RouteLazyInstrumentationInfo>;
76
+ 'lazy.action'?: InstrumentFunction<RouteLazyInstrumentationInfo>;
77
+ 'lazy.middleware'?: InstrumentFunction<RouteLazyInstrumentationInfo>;
78
+ middleware?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
79
+ loader?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
80
+ action?: InstrumentFunction<RouteHandlerInstrumentationInfo>;
81
+ };
82
+
83
+ type RouteLazyInstrumentationInfo = undefined;
84
+
85
+ type RouteHandlerInstrumentationInfo = Readonly<{
86
+ request: ReadonlyRequest;
87
+ params: LoaderFunctionArgs['params'];
88
+ pattern: string;
89
+ context: ReadonlyContext;
90
+ }>;
91
+
92
+ // Router Instrumentation
93
+ type InstrumentableRouter = {
94
+ instrument(instrumentations: RouterInstrumentations): void;
95
+ };
96
+
97
+ type RouterInstrumentations = {
98
+ navigate?: InstrumentFunction<RouterNavigationInstrumentationInfo>;
99
+ fetch?: InstrumentFunction<RouterFetchInstrumentationInfo>;
100
+ };
101
+
102
+ type RouterNavigationInstrumentationInfo = Readonly<{
103
+ to: string | number;
104
+ currentUrl: string;
105
+ formMethod?: HTMLFormMethod;
106
+ formEncType?: FormEncType;
107
+ formData?: FormData;
108
+ body?: any;
109
+ }>;
110
+
111
+ type RouterFetchInstrumentationInfo = Readonly<{
112
+ href: string;
113
+ currentUrl: string;
114
+ fetcherKey: string;
115
+ formMethod?: HTMLFormMethod;
116
+ formEncType?: FormEncType;
117
+ formData?: FormData;
118
+ body?: any;
119
+ }>;
120
+
121
+ // Request Handler Instrumentation
122
+ type InstrumentableRequestHandler = {
123
+ instrument(instrumentations: RequestHandlerInstrumentations): void;
124
+ };
125
+
126
+ type RequestHandlerInstrumentations = {
127
+ request?: InstrumentFunction<RequestHandlerInstrumentationInfo>;
128
+ };
129
+
130
+ type RequestHandlerInstrumentationInfo = Readonly<{
131
+ request: ReadonlyRequest;
132
+ context: ReadonlyContext | undefined;
133
+ }>;
134
+
135
+ const UninstrumentedSymbol = Symbol('Uninstrumented');
136
+
137
+ export function getRouteInstrumentationUpdates(
138
+ fns: InstrumentRouteFunction[],
139
+ route: Readonly<DataRouteObject>,
140
+ ) {
141
+ let aggregated: {
142
+ lazy: InstrumentFunction<RouteLazyInstrumentationInfo>[];
143
+ 'lazy.loader': InstrumentFunction<RouteLazyInstrumentationInfo>[];
144
+ 'lazy.action': InstrumentFunction<RouteLazyInstrumentationInfo>[];
145
+ 'lazy.middleware': InstrumentFunction<RouteLazyInstrumentationInfo>[];
146
+ middleware: InstrumentFunction<RouteHandlerInstrumentationInfo>[];
147
+ loader: InstrumentFunction<RouteHandlerInstrumentationInfo>[];
148
+ action: InstrumentFunction<RouteHandlerInstrumentationInfo>[];
149
+ } = {
150
+ lazy: [],
151
+ 'lazy.loader': [],
152
+ 'lazy.action': [],
153
+ 'lazy.middleware': [],
154
+ middleware: [],
155
+ loader: [],
156
+ action: [],
157
+ };
158
+
159
+ fns.forEach((fn) =>
160
+ fn({
161
+ id: route.id,
162
+ index: route.index,
163
+ path: route.path,
164
+ instrument(i) {
165
+ let keys = Object.keys(aggregated) as Array<keyof typeof aggregated>;
166
+ for (let key of keys) {
167
+ if (i[key]) {
168
+ aggregated[key].push(i[key] as any);
169
+ }
170
+ }
171
+ },
172
+ }),
173
+ );
174
+
175
+ let updates: {
176
+ middleware?: DataRouteObject['middleware'];
177
+ loader?: DataRouteObject['loader'];
178
+ action?: DataRouteObject['action'];
179
+ lazy?: DataRouteObject['lazy'];
180
+ } = {};
181
+
182
+ // Instrument lazy functions
183
+ if (typeof route.lazy === 'function' && aggregated.lazy.length > 0) {
184
+ let instrumented = wrapImpl(aggregated.lazy, route.lazy, () => undefined);
185
+ if (instrumented) {
186
+ updates.lazy = instrumented as DataRouteObject['lazy'];
187
+ }
188
+ }
189
+
190
+ // Instrument the lazy object format
191
+ if (typeof route.lazy === 'object') {
192
+ let lazyObject: LazyRouteObject<DataRouteObject> = route.lazy;
193
+ (['middleware', 'loader', 'action'] as const).forEach((key) => {
194
+ let lazyFn = lazyObject[key];
195
+ let instrumentations = aggregated[`lazy.${key}`];
196
+ if (typeof lazyFn === 'function' && instrumentations.length > 0) {
197
+ let instrumented = wrapImpl(instrumentations, lazyFn, () => undefined);
198
+ if (instrumented) {
199
+ updates.lazy = Object.assign(updates.lazy || {}, {
200
+ [key]: instrumented,
201
+ });
202
+ }
203
+ }
204
+ });
205
+ }
206
+
207
+ // Instrument loader/action functions
208
+ (['loader', 'action'] as const).forEach((key) => {
209
+ let handler = route[key];
210
+ if (typeof handler === 'function' && aggregated[key].length > 0) {
211
+ // @ts-expect-error
212
+ let original = handler[UninstrumentedSymbol] ?? handler;
213
+ let instrumented = wrapImpl(aggregated[key], original, (...args) =>
214
+ getHandlerInfo(args[0] as LoaderFunctionArgs | ActionFunctionArgs),
215
+ );
216
+ if (instrumented) {
217
+ if (key === 'loader' && original.hydrate === true) {
218
+ (instrumented as LoaderFunction).hydrate = true;
219
+ }
220
+ // @ts-expect-error
221
+ instrumented[UninstrumentedSymbol] = original;
222
+ updates[key] = instrumented;
223
+ }
224
+ }
225
+ });
226
+
227
+ // Instrument middleware functions
228
+ if (route.middleware && route.middleware.length > 0 && aggregated.middleware.length > 0) {
229
+ updates.middleware = route.middleware.map((middleware) => {
230
+ // @ts-expect-error
231
+ let original = middleware[UninstrumentedSymbol] ?? middleware;
232
+ let instrumented = wrapImpl(aggregated.middleware, original, (...args) =>
233
+ getHandlerInfo(args[0] as Parameters<MiddlewareFunction>[0]),
234
+ );
235
+ if (instrumented) {
236
+ // @ts-expect-error
237
+ instrumented[UninstrumentedSymbol] = original;
238
+ return instrumented;
239
+ }
240
+ return middleware;
241
+ });
242
+ }
243
+
244
+ return updates;
245
+ }
246
+
247
+ export function instrumentClientSideRouter(
248
+ router: Router,
249
+ fns: InstrumentRouterFunction[],
250
+ ): Router {
251
+ let aggregated: {
252
+ navigate: InstrumentFunction<RouterNavigationInstrumentationInfo>[];
253
+ fetch: InstrumentFunction<RouterFetchInstrumentationInfo>[];
254
+ } = {
255
+ navigate: [],
256
+ fetch: [],
257
+ };
258
+
259
+ fns.forEach((fn) =>
260
+ fn({
261
+ instrument(i) {
262
+ let keys = Object.keys(i) as Array<keyof RouterInstrumentations>;
263
+ for (let key of keys) {
264
+ if (i[key]) {
265
+ aggregated[key].push(i[key] as any);
266
+ }
267
+ }
268
+ },
269
+ }),
270
+ );
271
+
272
+ if (aggregated.navigate.length > 0) {
273
+ // @ts-expect-error
274
+ let navigate = router.navigate[UninstrumentedSymbol] ?? router.navigate;
275
+ let instrumentedNavigate = wrapImpl(aggregated.navigate, navigate, (...args) => {
276
+ let [to, opts] = args as Parameters<Router['navigate']>;
277
+ return {
278
+ to: typeof to === 'number' || typeof to === 'string' ? to : to ? createPath(to) : '.',
279
+ ...getRouterInfo(router, opts ?? {}),
280
+ } satisfies RouterNavigationInstrumentationInfo;
281
+ }) as Router['navigate'];
282
+ if (instrumentedNavigate) {
283
+ // @ts-expect-error
284
+ instrumentedNavigate[UninstrumentedSymbol] = navigate;
285
+ router.navigate = instrumentedNavigate;
286
+ }
287
+ }
288
+
289
+ if (aggregated.fetch.length > 0) {
290
+ // @ts-expect-error
291
+ let fetch = router.fetch[UninstrumentedSymbol] ?? router.fetch;
292
+ let instrumentedFetch = wrapImpl(aggregated.fetch, fetch, (...args) => {
293
+ let [key, , href, opts] = args as Parameters<Router['fetch']>;
294
+ return {
295
+ href: href ?? '.',
296
+ fetcherKey: key,
297
+ ...getRouterInfo(router, opts ?? {}),
298
+ } satisfies RouterFetchInstrumentationInfo;
299
+ }) as Router['fetch'];
300
+ if (instrumentedFetch) {
301
+ // @ts-expect-error
302
+ instrumentedFetch[UninstrumentedSymbol] = fetch;
303
+ router.fetch = instrumentedFetch;
304
+ }
305
+ }
306
+
307
+ return router;
308
+ }
309
+
310
+ export function instrumentHandler(
311
+ handler: RequestHandler,
312
+ fns: InstrumentRequestHandlerFunction[],
313
+ ): RequestHandler {
314
+ let aggregated: {
315
+ request: InstrumentFunction<RequestHandlerInstrumentationInfo>[];
316
+ } = {
317
+ request: [],
318
+ };
319
+
320
+ fns.forEach((fn) =>
321
+ fn({
322
+ instrument(i) {
323
+ let keys = Object.keys(i) as Array<keyof typeof i>;
324
+ for (let key of keys) {
325
+ if (i[key]) {
326
+ aggregated[key].push(i[key] as any);
327
+ }
328
+ }
329
+ },
330
+ }),
331
+ );
332
+
333
+ let instrumentedHandler = handler;
334
+
335
+ if (aggregated.request.length > 0) {
336
+ instrumentedHandler = wrapImpl(aggregated.request, handler, (...args) => {
337
+ let [request, context] = args as Parameters<RequestHandler>;
338
+ return {
339
+ request: getReadonlyRequest(request),
340
+ context: context != null ? getReadonlyContext(context) : context,
341
+ } satisfies RequestHandlerInstrumentationInfo;
342
+ }) as RequestHandler;
343
+ }
344
+
345
+ return instrumentedHandler;
346
+ }
347
+
348
+ function wrapImpl<T extends InstrumentationInfo>(
349
+ impls: InstrumentFunction<T>[],
350
+ handler: (...args: any[]) => MaybePromise<any>,
351
+ getInfo: (...args: unknown[]) => T,
352
+ ) {
353
+ if (impls.length === 0) {
354
+ return null;
355
+ }
356
+ return async (...args: unknown[]) => {
357
+ let result = await recurseRight(
358
+ impls,
359
+ getInfo(...args),
360
+ () => handler(...args),
361
+ impls.length - 1,
362
+ );
363
+ if (result.type === 'error') {
364
+ throw result.value;
365
+ }
366
+ return result.value;
367
+ };
368
+ }
369
+
370
+ type RecurseResult = { type: 'success' | 'error'; value: unknown };
371
+
372
+ async function recurseRight<T extends InstrumentationInfo>(
373
+ impls: InstrumentFunction<T>[],
374
+ info: T,
375
+ handler: () => MaybePromise<void>,
376
+ index: number,
377
+ ): Promise<RecurseResult> {
378
+ let impl = impls[index];
379
+ let result: RecurseResult | undefined;
380
+ if (!impl) {
381
+ try {
382
+ let value = await handler();
383
+ result = { type: 'success', value };
384
+ } catch (e) {
385
+ result = { type: 'error', value: e };
386
+ }
387
+ } else {
388
+ // If they forget to call the handler, or if they throw before calling the
389
+ // handler, we need to ensure the handlers still gets called
390
+ let handlerPromise: ReturnType<typeof recurseRight> | undefined = undefined;
391
+ let callHandler = async (): Promise<InstrumentationHandlerResult> => {
392
+ if (handlerPromise) {
393
+ console.error('You cannot call instrumented handlers more than once');
394
+ } else {
395
+ handlerPromise = recurseRight(impls, info, handler, index - 1);
396
+ }
397
+ result = await handlerPromise;
398
+ invariant(result, 'Expected a result');
399
+ if (result.type === 'error' && result.value instanceof Error) {
400
+ return { status: 'error', error: result.value };
401
+ }
402
+ return { status: 'success', error: undefined };
403
+ };
404
+
405
+ try {
406
+ await impl(callHandler, info);
407
+ } catch (e) {
408
+ console.error('An instrumentation function threw an error:', e);
409
+ }
410
+
411
+ if (!handlerPromise) {
412
+ await callHandler();
413
+ }
414
+
415
+ // If the user forgot to await the handler, we can wait for it to resolve here
416
+ await handlerPromise;
417
+ }
418
+
419
+ if (result) {
420
+ return result;
421
+ }
422
+
423
+ return {
424
+ type: 'error',
425
+ value: new Error('No result assigned in instrumentation chain.'),
426
+ };
427
+ }
428
+
429
+ function getHandlerInfo(
430
+ args: LoaderFunctionArgs | ActionFunctionArgs | Parameters<MiddlewareFunction>[0],
431
+ ): RouteHandlerInstrumentationInfo {
432
+ let { request, context, params, pattern } = args;
433
+ return {
434
+ request: getReadonlyRequest(request),
435
+ params: { ...params },
436
+ pattern,
437
+ context: getReadonlyContext(context),
438
+ };
439
+ }
440
+
441
+ function getRouterInfo(
442
+ router: Router,
443
+ opts: NonNullable<Parameters<Router['navigate']>[1] | Parameters<Router['fetch']>[3]>,
444
+ ) {
445
+ return {
446
+ currentUrl: createPath(router.state.location),
447
+ ...('formMethod' in opts ? { formMethod: opts.formMethod } : {}),
448
+ ...('formEncType' in opts ? { formEncType: opts.formEncType } : {}),
449
+ ...('formData' in opts ? { formData: opts.formData } : {}),
450
+ ...('body' in opts ? { body: opts.body } : {}),
451
+ };
452
+ }
453
+ // Return a shallow readonly "clone" of the Request with the info they may
454
+ // want to read from during instrumentation
455
+ function getReadonlyRequest(request: Request): {
456
+ method: string;
457
+ url: string;
458
+ headers: Pick<Headers, 'get'>;
459
+ } {
460
+ return {
461
+ method: request.method,
462
+ url: request.url,
463
+ headers: {
464
+ get: (...args) => request.headers.get(...args),
465
+ },
466
+ };
467
+ }
468
+
469
+ function getReadonlyContext(
470
+ context: MiddlewareEnabled extends true ? RouterContextProvider : AppLoadContext,
471
+ ): MiddlewareEnabled extends true ? Pick<RouterContextProvider, 'get'> : Readonly<AppLoadContext> {
472
+ if (isPlainObject(context)) {
473
+ let frozen = { ...context };
474
+ Object.freeze(frozen);
475
+ return frozen;
476
+ } else {
477
+ return {
478
+ get: <T>(ctx: RouterContext<T>) => (context as unknown as RouterContextProvider).get(ctx),
479
+ };
480
+ }
481
+ }
482
+
483
+ // From turbo-stream-v2/flatten.ts
484
+ const objectProtoNames = Object.getOwnPropertyNames(Object.prototype).sort().join('\0');
485
+
486
+ function isPlainObject(thing: unknown): thing is Record<string | number | symbol, unknown> {
487
+ if (thing === null || typeof thing !== 'object') {
488
+ return false;
489
+ }
490
+ const proto = Object.getPrototypeOf(thing);
491
+ return (
492
+ proto === Object.prototype ||
493
+ proto === null ||
494
+ Object.getOwnPropertyNames(proto).sort().join('\0') === objectProtoNames
495
+ );
496
+ }
@@ -0,0 +1,192 @@
1
+ // Vendored from react-router@7.18.1 packages/react-router/lib/router/links.ts — unmodified.
2
+ // Re-vendor with `node scripts/vendor-remix-router.mjs`; never hand-edit.
3
+ type Primitive = null | undefined | string | number | boolean | symbol | bigint;
4
+
5
+ type LiteralUnion<LiteralType, BaseType extends Primitive> =
6
+ | LiteralType
7
+ | (BaseType & Record<never, never>);
8
+
9
+ interface HtmlLinkProps {
10
+ /**
11
+ * Address of the hyperlink
12
+ */
13
+ href?: string;
14
+
15
+ /**
16
+ * How the element handles crossorigin requests
17
+ */
18
+ crossOrigin?: 'anonymous' | 'use-credentials';
19
+
20
+ /**
21
+ * Relationship between the document containing the hyperlink and the destination resource
22
+ */
23
+ rel: LiteralUnion<
24
+ | 'alternate'
25
+ | 'dns-prefetch'
26
+ | 'icon'
27
+ | 'manifest'
28
+ | 'modulepreload'
29
+ | 'next'
30
+ | 'pingback'
31
+ | 'preconnect'
32
+ | 'prefetch'
33
+ | 'preload'
34
+ | 'prerender'
35
+ | 'search'
36
+ | 'stylesheet',
37
+ string
38
+ >;
39
+
40
+ /**
41
+ * Applicable media: "screen", "print", "(max-width: 764px)"
42
+ */
43
+ media?: string;
44
+
45
+ /**
46
+ * Integrity metadata used in Subresource Integrity checks
47
+ */
48
+ integrity?: string;
49
+
50
+ /**
51
+ * Language of the linked resource
52
+ */
53
+ hrefLang?: string;
54
+
55
+ /**
56
+ * Hint for the type of the referenced resource
57
+ */
58
+ type?: string;
59
+
60
+ /**
61
+ * Referrer policy for fetches initiated by the element
62
+ */
63
+ referrerPolicy?:
64
+ | ''
65
+ | 'no-referrer'
66
+ | 'no-referrer-when-downgrade'
67
+ | 'same-origin'
68
+ | 'origin'
69
+ | 'strict-origin'
70
+ | 'origin-when-cross-origin'
71
+ | 'strict-origin-when-cross-origin'
72
+ | 'unsafe-url';
73
+
74
+ /**
75
+ * Sizes of the icons (for rel="icon")
76
+ */
77
+ sizes?: string;
78
+
79
+ /**
80
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
81
+ */
82
+ as?: LiteralUnion<
83
+ | 'audio'
84
+ | 'audioworklet'
85
+ | 'document'
86
+ | 'embed'
87
+ | 'fetch'
88
+ | 'font'
89
+ | 'frame'
90
+ | 'iframe'
91
+ | 'image'
92
+ | 'manifest'
93
+ | 'object'
94
+ | 'paintworklet'
95
+ | 'report'
96
+ | 'script'
97
+ | 'serviceworker'
98
+ | 'sharedworker'
99
+ | 'style'
100
+ | 'track'
101
+ | 'video'
102
+ | 'worker'
103
+ | 'xslt',
104
+ string
105
+ >;
106
+
107
+ /**
108
+ * Color to use when customizing a site's icon (for rel="mask-icon")
109
+ */
110
+ color?: string;
111
+
112
+ /**
113
+ * Whether the link is disabled
114
+ */
115
+ disabled?: boolean;
116
+
117
+ /**
118
+ * The title attribute has special semantics on this element: Title of the link; CSS style sheet set name.
119
+ */
120
+ title?: string;
121
+
122
+ /**
123
+ * Images to use in different situations, e.g., high-resolution displays,
124
+ * small monitors, etc. (for rel="preload")
125
+ */
126
+ imageSrcSet?: string;
127
+
128
+ /**
129
+ * Image sizes for different page layouts (for rel="preload")
130
+ */
131
+ imageSizes?: string;
132
+ }
133
+
134
+ interface HtmlLinkPreloadImage extends HtmlLinkProps {
135
+ /**
136
+ * Relationship between the document containing the hyperlink and the destination resource
137
+ */
138
+ rel: 'preload';
139
+
140
+ /**
141
+ * Potential destination for a preload request (for rel="preload" and rel="modulepreload")
142
+ */
143
+ as: 'image';
144
+
145
+ /**
146
+ * Address of the hyperlink
147
+ */
148
+ href?: string;
149
+
150
+ /**
151
+ * Images to use in different situations, e.g., high-resolution displays,
152
+ * small monitors, etc. (for rel="preload")
153
+ */
154
+ imageSrcSet: string;
155
+
156
+ /**
157
+ * Image sizes for different page layouts (for rel="preload")
158
+ */
159
+ imageSizes?: string;
160
+ }
161
+
162
+ /**
163
+ * Represents a `<link>` element.
164
+ *
165
+ * WHATWG Specification: https://html.spec.whatwg.org/multipage/semantics.html#the-link-element
166
+ */
167
+ export type HtmlLinkDescriptor =
168
+ // Must have an href *unless* it's a `<link rel="preload" as="image">` with an
169
+ // `imageSrcSet` and `imageSizes` props
170
+ | (HtmlLinkProps & Pick<Required<HtmlLinkProps>, 'href'>)
171
+ | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, 'imageSizes'>)
172
+ | (HtmlLinkPreloadImage & Pick<Required<HtmlLinkPreloadImage>, 'href'> & { imageSizes?: never });
173
+
174
+ export interface PageLinkDescriptor extends Omit<
175
+ HtmlLinkDescriptor,
176
+ 'href' | 'rel' | 'type' | 'sizes' | 'imageSrcSet' | 'imageSizes' | 'as' | 'color' | 'title'
177
+ > {
178
+ /**
179
+ * A [`nonce`](https://developer.mozilla.org/en-US/docs/Web/HTML/Reference/Global_attributes/nonce)
180
+ * attribute to render on the [`<link>`](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/link)
181
+ * element. If not provided in Framework Mode, it will default to any
182
+ * {@link ServerRouter | `<ServerRouter nonce>`} prop.
183
+
184
+ */
185
+ nonce?: string | undefined;
186
+ /**
187
+ * The absolute path of the page to prefetch, e.g. `/absolute/path`.
188
+ */
189
+ page: string;
190
+ }
191
+
192
+ export type LinkDescriptor = HtmlLinkDescriptor | PageLinkDescriptor;