@turnipxenon/pineapple 5.3.16 → 5.3.17

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.
@@ -0,0 +1,785 @@
1
+ /**
2
+ * Returns the current server-side async local storage instance.
3
+ *
4
+ * Accessing the mutable value through a function keeps it observable when
5
+ * module interceptors wrap exported bindings and snapshot their initial value.
6
+ *
7
+ * @returns {ParaglideAsyncLocalStorage | undefined}
8
+ */
9
+ export function getServerAsyncLocalStorage(): ParaglideAsyncLocalStorage | undefined;
10
+ /**
11
+ * Sets the server side async local storage.
12
+ *
13
+ * The function is needed because the `runtime.js` file
14
+ * must define the `serverAsyncLocalStorage` variable to
15
+ * avoid a circular import between `runtime.js` and
16
+ * `server.js` files.
17
+ *
18
+ * @param {ParaglideAsyncLocalStorage | undefined} value
19
+ */
20
+ export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
21
+ /**
22
+ * Resolve locale for a given URL using route-aware strategies.
23
+ *
24
+ * @param {string | URL} url
25
+ * @returns {Locale}
26
+ */
27
+ export function getLocaleForUrl(url: string | URL): Locale;
28
+ /**
29
+ * Get writing direction for a locale.
30
+ *
31
+ * Uses `Intl.Locale` text info when available and falls back to a
32
+ * language-based RTL check for runtimes without `getTextInfo()`.
33
+ *
34
+ * @example
35
+ * getTextDirection(); // "ltr" or "rtl" for current locale
36
+ * getTextDirection("ar"); // "rtl"
37
+ * getTextDirection("en"); // "ltr"
38
+ *
39
+ * @param {string} [locale] - Target locale. If not provided, uses `getLocale()`
40
+ * @returns {"ltr" | "rtl"}
41
+ */
42
+ export function getTextDirection(locale?: string): "ltr" | "rtl";
43
+ /**
44
+ * Coerces a locale-like string to the canonical locale value used by the runtime.
45
+ *
46
+ * @param {unknown} value
47
+ * @returns {Locale | undefined}
48
+ */
49
+ export function toLocale(value: unknown): Locale | undefined;
50
+ /**
51
+ * Check if something is an available locale with the canonical project casing.
52
+ *
53
+ * @example
54
+ * if (isLocale(params.locale)) {
55
+ * setLocale(params.locale);
56
+ * } else {
57
+ * setLocale('en');
58
+ * }
59
+ *
60
+ * Use `toLocale()` when you want case-insensitive matching and canonicalization.
61
+ *
62
+ * @param {unknown} locale
63
+ * @returns {locale is Locale}
64
+ */
65
+ export function isLocale(locale: unknown): locale is Locale;
66
+ /**
67
+ * Asserts that the input can be normalized to a locale.
68
+ *
69
+ * @param {unknown} input - The input to check.
70
+ * @returns {Locale} The input normalized to a Locale.
71
+ * @throws {Error} If the input is not a locale.
72
+ */
73
+ export function assertIsLocale(input: unknown): Locale;
74
+ /**
75
+ * Extracts a cookie from the document.
76
+ *
77
+ * Will return undefined if the document is not available or if the cookie is not set.
78
+ * The `document` object is not available in server-side rendering, so this function should not be called in that context.
79
+ *
80
+ * @returns {Locale | undefined}
81
+ */
82
+ export function extractLocaleFromCookie(): Locale | undefined;
83
+ /**
84
+ * Extracts a locale from the accept-language header.
85
+ *
86
+ * Use the function on the server to extract the locale
87
+ * from the accept-language header that is sent by the client.
88
+ *
89
+ * @example
90
+ * const locale = extractLocaleFromHeader(request);
91
+ *
92
+ * @param {Request} request - The request object to extract the locale from.
93
+ * @returns {Locale | undefined} The negotiated preferred language.
94
+ */
95
+ export function extractLocaleFromHeader(request: Request): Locale | undefined;
96
+ /**
97
+ * Negotiates a preferred language from navigator.languages.
98
+ *
99
+ * Use the function on the client to extract the locale
100
+ * from the navigator.languages array.
101
+ *
102
+ * @example
103
+ * const locale = extractLocaleFromNavigator();
104
+ *
105
+ * @returns {Locale | undefined}
106
+ */
107
+ export function extractLocaleFromNavigator(): Locale | undefined;
108
+ /**
109
+ * Extracts the locale from a given URL using native URLPattern.
110
+ *
111
+ * The built-in default `/:locale/...` routing is case-insensitive because it
112
+ * canonicalizes the first path segment with `toLocale()`. Custom `urlPatterns`
113
+ * keep URLPattern's normal exact matching semantics for path segments.
114
+ *
115
+ * @param {URL|string} url - The full URL from which to extract the locale.
116
+ * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
117
+ */
118
+ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
119
+ /**
120
+ * Lower-level URL localization function, primarily used in server contexts.
121
+ *
122
+ * This function is designed for server-side usage where you need precise control
123
+ * over URL localization, such as in middleware or request handlers. It works with
124
+ * URL objects and always returns absolute URLs.
125
+ *
126
+ * For client-side UI components, use `localizeHref()` instead, which provides
127
+ * a more convenient API with relative paths and automatic locale detection.
128
+ *
129
+ * @see https://paraglidejs.com/i18n-routing
130
+ *
131
+ * @example
132
+ * ```typescript
133
+ * // Server middleware example
134
+ * app.use((req, res, next) => {
135
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
136
+ * const localized = localizeUrl(url, { locale: "de" });
137
+ *
138
+ * if (localized.href !== url.href) {
139
+ * return res.redirect(localized.href);
140
+ * }
141
+ * next();
142
+ * });
143
+ * ```
144
+ *
145
+ * @example
146
+ * ```typescript
147
+ * // Using with URL patterns
148
+ * const url = new URL("https://example.com/about");
149
+ * localizeUrl(url, { locale: "de" });
150
+ * // => URL("https://example.com/de/about")
151
+ *
152
+ * // Using with domain-based localization
153
+ * const url = new URL("https://example.com/store");
154
+ * localizeUrl(url, { locale: "de" });
155
+ * // => URL("https://de.example.com/store")
156
+ * ```
157
+ *
158
+ * @param {string | URL} url - The URL to localize. If string, must be absolute.
159
+ * @param {object} [options] - Options for localization
160
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
161
+ * @returns {URL} The localized URL, always absolute
162
+ */
163
+ export function localizeUrl(url: string | URL, options?: {
164
+ locale?: "en" | "fr" | "tl" | undefined;
165
+ }): URL;
166
+ /**
167
+ * Low-level URL de-localization function, primarily used in server contexts.
168
+ *
169
+ * This function is designed for server-side usage where you need precise control
170
+ * over URL de-localization, such as in middleware or request handlers. It works with
171
+ * URL objects and always returns absolute URLs.
172
+ *
173
+ * For client-side UI components, use `deLocalizeHref()` instead, which provides
174
+ * a more convenient API with relative paths.
175
+ *
176
+ * @see https://paraglidejs.com/i18n-routing
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Server middleware example
181
+ * app.use((req, res, next) => {
182
+ * const url = new URL(req.url, `${req.protocol}://${req.headers.host}`);
183
+ * const baseUrl = deLocalizeUrl(url);
184
+ *
185
+ * // Store the base URL for later use
186
+ * req.baseUrl = baseUrl;
187
+ * next();
188
+ * });
189
+ * ```
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * // Using with URL patterns
194
+ * const url = new URL("https://example.com/de/about");
195
+ * deLocalizeUrl(url); // => URL("https://example.com/about")
196
+ *
197
+ * // Using with domain-based localization
198
+ * const url = new URL("https://de.example.com/store");
199
+ * deLocalizeUrl(url); // => URL("https://example.com/store")
200
+ * ```
201
+ *
202
+ * @param {string | URL} url - The URL to de-localize. If string, must be absolute.
203
+ * @returns {URL} The de-localized URL, always absolute
204
+ */
205
+ export function deLocalizeUrl(url: string | URL): URL;
206
+ /**
207
+ * Aggregates named groups from various parts of the URLPattern match result.
208
+ *
209
+ *
210
+ * @param {any} match - The URLPattern match result object.
211
+ * @returns {Record<string, string | null | undefined>} An object containing all named groups from the match.
212
+ */
213
+ export function aggregateGroups(match: any): Record<string, string | null | undefined>;
214
+ /**
215
+ * Match route policy against both the public URL and its canonical URL.
216
+ *
217
+ * The function is deliberately separate from variables.js: configuration is
218
+ * inert data, while canonicalization and route selection form a routing layer.
219
+ *
220
+ * @param {string | URL} url
221
+ * @returns {{ match: string; strategy?: typeof strategy; exclude?: boolean } | undefined}
222
+ */
223
+ export function findMatchingRouteStrategy(url: string | URL): {
224
+ match: string;
225
+ strategy?: typeof strategy;
226
+ exclude?: boolean;
227
+ } | undefined;
228
+ /**
229
+ * Returns the strategy to use for a specific URL.
230
+ *
231
+ * If no route strategy matches (or the matching rule is `exclude: true`),
232
+ * the global strategy is returned.
233
+ *
234
+ * @param {string | URL} url
235
+ * @returns {typeof strategy}
236
+ */
237
+ export function getStrategyForUrl(url: string | URL): typeof strategy;
238
+ /**
239
+ * Returns whether the given URL is excluded from middleware i18n processing.
240
+ *
241
+ * @param {string | URL} url
242
+ * @returns {boolean}
243
+ */
244
+ export function isExcludedByRouteStrategy(url: string | URL): boolean;
245
+ /**
246
+ * @typedef {object} ShouldRedirectServerInput
247
+ * @property {Request} request
248
+ * @property {string | URL} [effectiveRequestUrl] - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
249
+ * @property {Locale} [locale]
250
+ *
251
+ * @typedef {object} ShouldRedirectClientInput
252
+ * @property {undefined} [request]
253
+ * @property {string | URL} [url]
254
+ * @property {Locale} [locale]
255
+ *
256
+ * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
257
+ *
258
+ * @typedef {object} ShouldRedirectResult
259
+ * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
260
+ * @property {Locale} locale - Locale resolved using the configured strategies.
261
+ * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
262
+ */
263
+ /**
264
+ * Determines whether a redirect is required to align the current URL with the active locale.
265
+ *
266
+ * This helper mirrors the logic that powers `paraglideMiddleware`, but works in both server
267
+ * and client environments. It evaluates the configured strategies in order, computes the
268
+ * canonical localized URL, and reports when the current URL does not match.
269
+ *
270
+ * When called in the browser without arguments, the current `window.location.href` is used.
271
+ *
272
+ * @see https://paraglidejs.com/i18n-routing#redirects
273
+ *
274
+ * @example
275
+ * // Client side usage (e.g. TanStack Router beforeLoad hook)
276
+ * async function beforeLoad({ location }) {
277
+ * const decision = await shouldRedirect({ url: location.href });
278
+ *
279
+ * if (decision.shouldRedirect) {
280
+ * throw redirect({ to: decision.redirectUrl.href });
281
+ * }
282
+ * }
283
+ *
284
+ * @example
285
+ * // Server side usage with a Request
286
+ * export async function handle(request) {
287
+ * const decision = await shouldRedirect({ request });
288
+ *
289
+ * if (decision.shouldRedirect) {
290
+ * return Response.redirect(decision.redirectUrl, 307);
291
+ * }
292
+ *
293
+ * return render(request, decision.locale);
294
+ * }
295
+ *
296
+ * @example
297
+ * // Server side usage behind a proxy where request.url is not public-facing
298
+ * export async function handle(request) {
299
+ * const effectiveRequestUrl = new URL(request.url);
300
+ * effectiveRequestUrl.protocol = "https:";
301
+ * effectiveRequestUrl.host = "example.com";
302
+ *
303
+ * const decision = await shouldRedirect({
304
+ * request,
305
+ * effectiveRequestUrl,
306
+ * });
307
+ *
308
+ * if (decision.shouldRedirect) {
309
+ * return Response.redirect(decision.redirectUrl, 307);
310
+ * }
311
+ * }
312
+ *
313
+ * @param {ShouldRedirectInput} [input]
314
+ * @returns {Promise<ShouldRedirectResult>}
315
+ */
316
+ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedirectResult>;
317
+ /**
318
+ * High-level URL localization function optimized for client-side UI usage.
319
+ *
320
+ * This is a convenience wrapper around `localizeUrl()` that provides features
321
+ * needed in UI:
322
+ *
323
+ * - Accepts relative paths (e.g., "/about")
324
+ * - Returns relative paths when possible
325
+ * - Automatically detects current locale if not specified
326
+ * - Handles string input/output instead of URL objects
327
+ *
328
+ * @see https://paraglidejs.com/i18n-routing
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * // In a React/Vue/Svelte component
333
+ * const NavLink = ({ href }) => {
334
+ * // Automatically uses current locale, keeps path relative
335
+ * return <a href={localizeHref(href)}>...</a>;
336
+ * };
337
+ *
338
+ * // Examples:
339
+ * localizeHref("/about")
340
+ * // => "/de/about" (if current locale is "de")
341
+ * localizeHref("/store", { locale: "fr" })
342
+ * // => "/fr/store" (explicit locale)
343
+ *
344
+ * // Cross-origin links remain absolute
345
+ * localizeHref("https://other-site.com/about")
346
+ * // => "https://other-site.com/de/about"
347
+ * ```
348
+ *
349
+ * For server-side URL localization (e.g., in middleware), use `localizeUrl()`
350
+ * which provides more precise control over URL handling.
351
+ *
352
+ * @param {string} href - The href to localize (can be relative or absolute)
353
+ * @param {object} [options] - Options for localization
354
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
355
+ * @returns {string} The localized href, relative if input was relative
356
+ */
357
+ export function localizeHref(href: string, options?: {
358
+ locale?: "en" | "fr" | "tl" | undefined;
359
+ }): string;
360
+ /**
361
+ * High-level URL de-localization function optimized for client-side UI usage.
362
+ *
363
+ * This is a convenience wrapper around `deLocalizeUrl()` that provides features
364
+ * needed in the UI:
365
+ *
366
+ * - Accepts relative paths (e.g., "/de/about")
367
+ * - Returns relative paths when possible
368
+ * - Handles string input/output instead of URL objects
369
+ *
370
+ * @see https://paraglidejs.com/i18n-routing
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * // In a React/Vue/Svelte component
375
+ * const LocaleSwitcher = ({ href }) => {
376
+ * // Remove locale prefix before switching
377
+ * const baseHref = deLocalizeHref(href);
378
+ * return locales.map(locale =>
379
+ * <a href={localizeHref(baseHref, { locale })}>
380
+ * Switch to {locale}
381
+ * </a>
382
+ * );
383
+ * };
384
+ *
385
+ * // Examples:
386
+ * deLocalizeHref("/de/about") // => "/about"
387
+ * deLocalizeHref("/fr/store") // => "/store"
388
+ *
389
+ * // Cross-origin links remain absolute
390
+ * deLocalizeHref("https://example.com/de/about")
391
+ * // => "https://example.com/about"
392
+ * ```
393
+ *
394
+ * For server-side URL de-localization (e.g., in middleware), use `deLocalizeUrl()`
395
+ * which provides more precise control over URL handling.
396
+ *
397
+ * @param {string} href - The href to de-localize (can be relative or absolute)
398
+ * @returns {string} The de-localized href, relative if input was relative
399
+ */
400
+ export function deLocalizeHref(href: string): string;
401
+ /**
402
+ * @param {string} safeModuleId
403
+ * @param {Locale} locale
404
+ */
405
+ export function trackMessageCall(safeModuleId: string, locale: Locale): void;
406
+ /**
407
+ * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
408
+ *
409
+ * This function is essential for Static Site Generation (SSG) where you need to tell your framework
410
+ * which pages to pre-render at build time. It's also useful for generating sitemaps and
411
+ * `<link rel="alternate" hreflang>` tags for SEO.
412
+ *
413
+ * The function respects your `urlPatterns` configuration - if you have translated pathnames
414
+ * (e.g., `/about` → `/ueber-uns` for German), it will generate the correct localized paths.
415
+ *
416
+ * @see https://paraglidejs.com/static-site-generation
417
+ *
418
+ * @example
419
+ * // Basic usage - generate all locale variants for a list of paths
420
+ * const localizedUrls = generateStaticLocalizedUrls([
421
+ * "/",
422
+ * "/about",
423
+ * "/blog/post-1",
424
+ * ]);
425
+ * // Returns URL objects for each locale:
426
+ * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
427
+ *
428
+ * @example
429
+ * // Use with framework SSG APIs
430
+ * // SvelteKit
431
+ * export function entries() {
432
+ * const paths = ["/", "/about", "/contact"];
433
+ * return generateStaticLocalizedUrls(paths).map(url => ({
434
+ * locale: extractLocaleFromUrl(url)
435
+ * }));
436
+ * }
437
+ *
438
+ * @example
439
+ * // Sitemap generation
440
+ * const allPages = ["/", "/about", "/blog"];
441
+ * const sitemapUrls = generateStaticLocalizedUrls(allPages);
442
+ *
443
+ * @param {(string | URL)[]} urls - List of canonical URLs or paths to generate localized versions for.
444
+ * Can be absolute URLs (`https://example.com/about`) or paths (`/about`).
445
+ * Paths are resolved against `http://localhost` internally.
446
+ * @returns {URL[]} Array of URL objects representing all localized variants.
447
+ * The order follows each input URL with all its locale variants before moving to the next URL.
448
+ */
449
+ export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
450
+ /**
451
+ * Checks if the given strategy is a custom strategy.
452
+ *
453
+ * @param {unknown} strategy The name of the custom strategy to validate.
454
+ * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
455
+ * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
456
+ */
457
+ export function isCustomStrategy(strategy: unknown): boolean;
458
+ /**
459
+ * Defines a custom strategy that is executed on the server.
460
+ *
461
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
462
+ *
463
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
464
+ * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
465
+ * the method getLocale.
466
+ * @returns {void}
467
+ */
468
+ export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
469
+ /**
470
+ * Defines a custom strategy that is executed on the client.
471
+ *
472
+ * @see https://paraglidejs.com/strategy#write-your-own-strategy
473
+ *
474
+ * @param {string} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
475
+ * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
476
+ * methods getLocale and setLocale.
477
+ * @returns {void}
478
+ */
479
+ export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
480
+ /**
481
+ * The project's base locale.
482
+ *
483
+ * @example
484
+ * if (locale === baseLocale) {
485
+ * // do something
486
+ * }
487
+ */
488
+ export const baseLocale: "en";
489
+ /**
490
+ * The project's locales that have been specified in the settings.
491
+ *
492
+ * @example
493
+ * if (locales.includes(userSelectedLocale) === false) {
494
+ * throw new Error('Locale is not available');
495
+ * }
496
+ */
497
+ export const locales: readonly ["en", "fr", "tl"];
498
+ /** @type {string} */
499
+ export const cookieName: string;
500
+ /** @type {number} */
501
+ export const cookieMaxAge: number;
502
+ /** @type {string} */
503
+ export const cookieDomain: string;
504
+ /** @type {string} */
505
+ export const localStorageKey: string;
506
+ /**
507
+ * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
508
+ */
509
+ export const strategy: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
510
+ /**
511
+ * Route-level strategy overrides.
512
+ *
513
+ * `match` uses URLPattern syntax.
514
+ *
515
+ * @type {Array<{
516
+ * match: string;
517
+ * strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
518
+ * exclude?: boolean;
519
+ * }>}
520
+ */
521
+ export const routeStrategies: Array<{
522
+ match: string;
523
+ strategy?: Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>;
524
+ exclude?: boolean;
525
+ }>;
526
+ /**
527
+ * The used URL patterns.
528
+ *
529
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
530
+ */
531
+ export const urlPatterns: Array<{
532
+ pattern: string;
533
+ localized: Array<[Locale, string]>;
534
+ }>;
535
+ /**
536
+ * @typedef {{
537
+ * getStore(): {
538
+ * locale?: Locale,
539
+ * origin?: string,
540
+ * messageCalls?: Set<string>
541
+ * } | undefined,
542
+ * run: (store: { locale?: Locale, origin?: string, messageCalls?: Set<string>},
543
+ * cb: any) => any
544
+ * }} ParaglideAsyncLocalStorage
545
+ */
546
+ /**
547
+ * Server side async local storage that is set by `serverMiddleware()`.
548
+ *
549
+ * The variable is used to retrieve the locale and origin in a server-side
550
+ * rendering context without effecting other requests.
551
+ *
552
+ * @type {ParaglideAsyncLocalStorage | undefined}
553
+ */
554
+ export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
555
+ export const disableAsyncLocalStorage: false;
556
+ export const experimentalMiddlewareLocaleSplitting: false;
557
+ export const isServer: boolean;
558
+ /** @type {Locale | undefined} */
559
+ export const experimentalStaticLocale: Locale | undefined;
560
+ export function getLocale(): Locale;
561
+ export function overwriteGetLocale(fn: () => Locale): void;
562
+ /**
563
+ * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
564
+ */
565
+ /**
566
+ * Set the locale.
567
+ *
568
+ * Updates the locale using your configured strategies (cookie, localStorage, URL, etc.).
569
+ * By default, this navigates the client to the localized URL or reloads the current
570
+ * document to reflect the new locale. `reload: false` is a narrow browser-only escape
571
+ * hatch for a fully client-rendered, non-URL-routed surface that owns its reactive
572
+ * updates and document state. It does not re-render the UI or update the document.
573
+ * Do not use it for normal locale pickers, URL-routed pages, or switching an SSR,
574
+ * SSG, or hydrated document. It is incompatible with per-locale builds.
575
+ *
576
+ * If any custom strategy's `setLocale` function is async, then this function
577
+ * will become async as well.
578
+ *
579
+ * @see https://paraglidejs.com/strategy
580
+ *
581
+ * @example
582
+ * setLocale('en');
583
+ *
584
+ * @example
585
+ * setLocale('en', { reload: false });
586
+ *
587
+ * @type {SetLocaleFn}
588
+ */
589
+ export let setLocale: SetLocaleFn;
590
+ export function overwriteSetLocale(fn: SetLocaleFn): void;
591
+ /**
592
+ * The origin of the current URL.
593
+ *
594
+ * Defaults to "http://example.com" in non-browser environments. If this
595
+ * behavior is not desired, the implementation can be overwritten
596
+ * by `overwriteGetUrlOrigin()`.
597
+ *
598
+ * @type {() => string}
599
+ */
600
+ export let getUrlOrigin: () => string;
601
+ export function overwriteGetUrlOrigin(fn: () => string): void;
602
+ export function extractLocaleFromRequest(request: Request, options?: ExtractLocaleFromRequestOptions): Locale;
603
+ export function extractLocaleFromRequestWithStrategies(request: Request, strategies: typeof strategy, url?: string | URL): Locale;
604
+ export function extractLocaleFromRequestAsync(request: Request, options?: {
605
+ effectiveRequestUrl?: string | URL;
606
+ }): Promise<Locale>;
607
+ /**
608
+ * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
609
+ */
610
+ /**
611
+ * @typedef {`custom_${string}`} CustomStrategy
612
+ */
613
+ /**
614
+ * @typedef {BuiltInStrategy | CustomStrategy} Strategy
615
+ */
616
+ /**
617
+ * @typedef {Array<Strategy>} Strategies
618
+ */
619
+ /**
620
+ * @typedef {{ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined) }} CustomServerStrategyHandler
621
+ */
622
+ /**
623
+ * @typedef {{ getLocale: () => Promise<string|undefined> | (string | undefined), setLocale: (locale: string) => Promise<void> | void }} CustomClientStrategyHandler
624
+ */
625
+ /** @type {Map<string, CustomServerStrategyHandler>} */
626
+ export const customServerStrategies: Map<string, CustomServerStrategyHandler>;
627
+ /** @type {Map<string, CustomClientStrategyHandler>} */
628
+ export const customClientStrategies: Map<string, CustomClientStrategyHandler>;
629
+ export type ShouldRedirectServerInput = {
630
+ request: Request;
631
+ /**
632
+ * - Effective request URL to use for route matching, locale detection with the URL strategy, and redirect targets.
633
+ */
634
+ effectiveRequestUrl?: string | URL | undefined;
635
+ locale?: "en" | "fr" | "tl" | undefined;
636
+ };
637
+ export type ShouldRedirectClientInput = {
638
+ request?: undefined;
639
+ url?: string | URL | undefined;
640
+ locale?: "en" | "fr" | "tl" | undefined;
641
+ };
642
+ export type ShouldRedirectInput = ShouldRedirectServerInput | ShouldRedirectClientInput;
643
+ export type ShouldRedirectResult = {
644
+ /**
645
+ * - Indicates whether the consumer should perform a redirect.
646
+ */
647
+ shouldRedirect: boolean;
648
+ /**
649
+ * - Locale resolved using the configured strategies.
650
+ */
651
+ locale: Locale;
652
+ /**
653
+ * - Destination URL when a redirect is required.
654
+ */
655
+ redirectUrl: URL | undefined;
656
+ };
657
+ export type ParaglideAsyncLocalStorage = {
658
+ getStore(): {
659
+ locale?: Locale;
660
+ origin?: string;
661
+ messageCalls?: Set<string>;
662
+ } | undefined;
663
+ run: (store: {
664
+ locale?: Locale;
665
+ origin?: string;
666
+ messageCalls?: Set<string>;
667
+ }, cb: any) => any;
668
+ };
669
+ export type SetLocaleFn = (newLocale: Locale, options?: {
670
+ reload?: boolean;
671
+ }) => void | Promise<void>;
672
+ export type ExtractLocaleFromRequestOptions = {
673
+ /**
674
+ * - Effective request URL to use for route matching and locale detection with the URL strategy.
675
+ */
676
+ effectiveRequestUrl?: string | URL | undefined;
677
+ };
678
+ export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
679
+ export type CustomStrategy = `custom_${string}`;
680
+ export type Strategy = BuiltInStrategy | CustomStrategy;
681
+ export type Strategies = Array<Strategy>;
682
+ export type CustomServerStrategyHandler = {
683
+ getLocale: (request?: Request) => Promise<string | undefined> | (string | undefined);
684
+ };
685
+ export type CustomClientStrategyHandler = {
686
+ getLocale: () => Promise<string | undefined> | (string | undefined);
687
+ setLocale: (locale: string) => Promise<void> | void;
688
+ };
689
+ /**
690
+ * A locale that is available in the project.
691
+ */
692
+ export type Locale = (typeof locales)[number];
693
+ /**
694
+ * A branded type representing a localized string.
695
+ *
696
+ * Message functions return this type instead of \`string\`, enabling TypeScript
697
+ * to distinguish translated strings from regular strings at compile time.
698
+ * This allows you to enforce that only properly localized content is used
699
+ * in your UI components.
700
+ *
701
+ * Since \`LocalizedString\` is a branded subtype of \`string\`, it remains fully
702
+ * backward compatible—you can pass it anywhere a \`string\` is expected.
703
+ */
704
+ export type LocalizedString = string & {
705
+ readonly __brand: "LocalizedString";
706
+ };
707
+ /**
708
+ * A single markup option passed to a tag instance.
709
+ */
710
+ export type MessageMarkupOption = {
711
+ name: string;
712
+ value: unknown;
713
+ };
714
+ /**
715
+ * A single static markup attribute attached to a tag instance.
716
+ */
717
+ export type MessageMarkupAttribute = {
718
+ name: string;
719
+ value: string | true;
720
+ };
721
+ /**
722
+ * Record of markup options for a tag instance.
723
+ */
724
+ export type MessageMarkupOptions = Record<string, unknown>;
725
+ /**
726
+ * Record of markup attributes for a tag instance.
727
+ */
728
+ export type MessageMarkupAttributes = Record<string, string | true>;
729
+ /**
730
+ * Type-level schema for a single markup tag.
731
+ */
732
+ export type MessageMarkupTag = {
733
+ options: MessageMarkupOptions;
734
+ attributes: MessageMarkupAttributes;
735
+ children: boolean;
736
+ };
737
+ /**
738
+ * Type-level schema for all markup tags in a message.
739
+ */
740
+ export type MessageMarkupSchema = Record<string, MessageMarkupTag>;
741
+ /**
742
+ * Type-only metadata attached to compiled message functions.
743
+ */
744
+ export type MessageMetadata<Inputs, Options, Markup extends MessageMarkupSchema = MessageMarkupSchema> = {
745
+ readonly __paraglide?: {
746
+ inputs: Inputs;
747
+ options: Options;
748
+ markup: Markup;
749
+ };
750
+ };
751
+ /**
752
+ * A compiled, framework-neutral message part.
753
+ */
754
+ export type MessagePart = {
755
+ type: "text";
756
+ value: string;
757
+ } | {
758
+ type: "markup-start";
759
+ name: string;
760
+ options: MessageMarkupOptions;
761
+ attributes: MessageMarkupAttributes;
762
+ } | {
763
+ type: "markup-end";
764
+ name: string;
765
+ options: MessageMarkupOptions;
766
+ attributes: MessageMarkupAttributes;
767
+ } | {
768
+ type: "markup-standalone";
769
+ name: string;
770
+ options: MessageMarkupOptions;
771
+ attributes: MessageMarkupAttributes;
772
+ };
773
+ /**
774
+ * A message function is a message for a specific locale.
775
+ */
776
+ export type MessageFunction = (inputs?: Record<string, never>) => LocalizedString;
777
+ /**
778
+ * A message bundle function that selects the message to be returned.
779
+ *
780
+ * Uses `getLocale()` under the hood to determine the locale with an option.
781
+ */
782
+ export type MessageBundleFunction<T extends string> = (params: Record<string, never>, options: {
783
+ locale: T;
784
+ }) => LocalizedString;
785
+ //# sourceMappingURL=runtime.d.ts.map