@turnipxenon/pineapple 5.3.15 → 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.
Files changed (33) hide show
  1. package/dist/external/paraglide/.prettierignore +1 -1
  2. package/dist/external/paraglide/README.md +162 -0
  3. package/dist/external/paraglide/messages/_index.d.ts +3 -8
  4. package/dist/external/paraglide/messages/_index.d.ts.map +1 -1
  5. package/dist/external/paraglide/messages/_index.js +3 -50
  6. package/dist/external/paraglide/messages/example_message.d.ts +19 -0
  7. package/dist/external/paraglide/messages/example_message.d.ts.map +1 -0
  8. package/dist/external/paraglide/messages/example_message.js +34 -0
  9. package/dist/external/paraglide/messages/package.json +4 -0
  10. package/dist/external/paraglide/messages/settings.d.ts +17 -0
  11. package/dist/external/paraglide/messages/settings.d.ts.map +1 -0
  12. package/dist/external/paraglide/messages/settings.js +33 -0
  13. package/dist/external/paraglide/registry.d.ts +13 -0
  14. package/dist/external/paraglide/registry.d.ts.map +1 -1
  15. package/dist/external/paraglide/registry.js +15 -0
  16. package/dist/external/paraglide/runtime.d.ts +340 -139
  17. package/dist/external/paraglide/runtime.d.ts.map +1 -1
  18. package/dist/external/paraglide/runtime.js +654 -168
  19. package/dist/external/paraglide/server.d.ts +47 -18
  20. package/dist/external/paraglide/server.d.ts.map +1 -1
  21. package/dist/external/paraglide/server.js +150 -35
  22. package/dist/modules/parsnip/external-images/externalImages.remote.d.ts +2 -2
  23. package/dist/modules/parsnip/external-images/externalImages.remote.d.ts.map +1 -1
  24. package/package.json +26 -26
  25. package/dist/external/paraglide/messages/en.d.ts +0 -5
  26. package/dist/external/paraglide/messages/en.d.ts.map +0 -1
  27. package/dist/external/paraglide/messages/en.js +0 -10
  28. package/dist/external/paraglide/messages/fr.d.ts +0 -5
  29. package/dist/external/paraglide/messages/fr.d.ts.map +0 -1
  30. package/dist/external/paraglide/messages/fr.js +0 -10
  31. package/dist/external/paraglide/messages/tl.d.ts +0 -5
  32. package/dist/external/paraglide/messages/tl.d.ts.map +0 -1
  33. package/dist/external/paraglide/messages/tl.js +0 -7
@@ -1,3 +1,12 @@
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;
1
10
  /**
2
11
  * Sets the server side async local storage.
3
12
  *
@@ -10,7 +19,36 @@
10
19
  */
11
20
  export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStorage | undefined): void;
12
21
  /**
13
- * Check if something is an available locale.
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.
14
52
  *
15
53
  * @example
16
54
  * if (isLocale(params.locale)) {
@@ -19,32 +57,61 @@ export function overwriteServerAsyncLocalStorage(value: ParaglideAsyncLocalStora
19
57
  * setLocale('en');
20
58
  * }
21
59
  *
22
- * @param {any} locale
60
+ * Use `toLocale()` when you want case-insensitive matching and canonicalization.
61
+ *
62
+ * @param {unknown} locale
23
63
  * @returns {locale is Locale}
24
64
  */
25
- export function isLocale(locale: any): locale is Locale;
65
+ export function isLocale(locale: unknown): locale is Locale;
26
66
  /**
27
- * Asserts that the input is a locale.
67
+ * Asserts that the input can be normalized to a locale.
28
68
  *
29
- * @param {any} input - The input to check.
30
- * @returns {Locale} The input if it is a locale.
69
+ * @param {unknown} input - The input to check.
70
+ * @returns {Locale} The input normalized to a Locale.
31
71
  * @throws {Error} If the input is not a locale.
32
72
  */
33
- export function assertIsLocale(input: any): Locale;
73
+ export function assertIsLocale(input: unknown): Locale;
34
74
  /**
35
75
  * Extracts a cookie from the document.
36
76
  *
37
77
  * Will return undefined if the document is not available or if the cookie is not set.
38
78
  * The `document` object is not available in server-side rendering, so this function should not be called in that context.
39
79
  *
40
- * @returns {string | undefined}
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}
41
106
  */
42
- export function extractLocaleFromCookie(): string | undefined;
43
- export function extractLocaleFromHeader(request: Request): Locale;
44
107
  export function extractLocaleFromNavigator(): Locale | undefined;
45
108
  /**
46
109
  * Extracts the locale from a given URL using native URLPattern.
47
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
+ *
48
115
  * @param {URL|string} url - The full URL from which to extract the locale.
49
116
  * @returns {Locale|undefined} The extracted locale, or undefined if no locale is found.
50
117
  */
@@ -59,6 +126,8 @@ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
59
126
  * For client-side UI components, use `localizeHref()` instead, which provides
60
127
  * a more convenient API with relative paths and automatic locale detection.
61
128
  *
129
+ * @see https://paraglidejs.com/i18n-routing
130
+ *
62
131
  * @example
63
132
  * ```typescript
64
133
  * // Server middleware example
@@ -87,12 +156,12 @@ export function extractLocaleFromUrl(url: URL | string): Locale | undefined;
87
156
  * ```
88
157
  *
89
158
  * @param {string | URL} url - The URL to localize. If string, must be absolute.
90
- * @param {Object} [options] - Options for localization
91
- * @param {string} [options.locale] - Target locale. If not provided, uses getLocale()
159
+ * @param {object} [options] - Options for localization
160
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses getLocale()
92
161
  * @returns {URL} The localized URL, always absolute
93
162
  */
94
163
  export function localizeUrl(url: string | URL, options?: {
95
- locale?: string | undefined;
164
+ locale?: "en" | "fr" | "tl" | undefined;
96
165
  }): URL;
97
166
  /**
98
167
  * Low-level URL de-localization function, primarily used in server contexts.
@@ -104,6 +173,8 @@ export function localizeUrl(url: string | URL, options?: {
104
173
  * For client-side UI components, use `deLocalizeHref()` instead, which provides
105
174
  * a more convenient API with relative paths.
106
175
  *
176
+ * @see https://paraglidejs.com/i18n-routing
177
+ *
107
178
  * @example
108
179
  * ```typescript
109
180
  * // Server middleware example
@@ -132,23 +203,61 @@ export function localizeUrl(url: string | URL, options?: {
132
203
  * @returns {URL} The de-localized URL, always absolute
133
204
  */
134
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
+ */
135
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;
136
245
  /**
137
246
  * @typedef {object} ShouldRedirectServerInput
138
247
  * @property {Request} request
139
- * @property {string | URL} [url]
140
- * @property {ReturnType<typeof assertIsLocale>} [locale]
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]
141
250
  *
142
251
  * @typedef {object} ShouldRedirectClientInput
143
252
  * @property {undefined} [request]
144
253
  * @property {string | URL} [url]
145
- * @property {ReturnType<typeof assertIsLocale>} [locale]
254
+ * @property {Locale} [locale]
146
255
  *
147
256
  * @typedef {ShouldRedirectServerInput | ShouldRedirectClientInput} ShouldRedirectInput
148
257
  *
149
258
  * @typedef {object} ShouldRedirectResult
150
259
  * @property {boolean} shouldRedirect - Indicates whether the consumer should perform a redirect.
151
- * @property {ReturnType<typeof assertIsLocale>} locale - Locale resolved using the configured strategies.
260
+ * @property {Locale} locale - Locale resolved using the configured strategies.
152
261
  * @property {URL | undefined} redirectUrl - Destination URL when a redirect is required.
153
262
  */
154
263
  /**
@@ -160,6 +269,8 @@ export function aggregateGroups(match: any): Record<string, string | null | unde
160
269
  *
161
270
  * When called in the browser without arguments, the current `window.location.href` is used.
162
271
  *
272
+ * @see https://paraglidejs.com/i18n-routing#redirects
273
+ *
163
274
  * @example
164
275
  * // Client side usage (e.g. TanStack Router beforeLoad hook)
165
276
  * async function beforeLoad({ location }) {
@@ -182,6 +293,23 @@ export function aggregateGroups(match: any): Record<string, string | null | unde
182
293
  * return render(request, decision.locale);
183
294
  * }
184
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
+ *
185
313
  * @param {ShouldRedirectInput} [input]
186
314
  * @returns {Promise<ShouldRedirectResult>}
187
315
  */
@@ -197,6 +325,8 @@ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedir
197
325
  * - Automatically detects current locale if not specified
198
326
  * - Handles string input/output instead of URL objects
199
327
  *
328
+ * @see https://paraglidejs.com/i18n-routing
329
+ *
200
330
  * @example
201
331
  * ```typescript
202
332
  * // In a React/Vue/Svelte component
@@ -220,12 +350,12 @@ export function shouldRedirect(input?: ShouldRedirectInput): Promise<ShouldRedir
220
350
  * which provides more precise control over URL handling.
221
351
  *
222
352
  * @param {string} href - The href to localize (can be relative or absolute)
223
- * @param {Object} [options] - Options for localization
224
- * @param {string} [options.locale] - Target locale. If not provided, uses `getLocale()`
353
+ * @param {object} [options] - Options for localization
354
+ * @param {Locale} [options.locale] - Target locale. If not provided, uses `getLocale()`
225
355
  * @returns {string} The localized href, relative if input was relative
226
356
  */
227
357
  export function localizeHref(href: string, options?: {
228
- locale?: string | undefined;
358
+ locale?: "en" | "fr" | "tl" | undefined;
229
359
  }): string;
230
360
  /**
231
361
  * High-level URL de-localization function optimized for client-side UI usage.
@@ -237,6 +367,8 @@ export function localizeHref(href: string, options?: {
237
367
  * - Returns relative paths when possible
238
368
  * - Handles string input/output instead of URL objects
239
369
  *
370
+ * @see https://paraglidejs.com/i18n-routing
371
+ *
240
372
  * @example
241
373
  * ```typescript
242
374
  * // In a React/Vue/Svelte component
@@ -264,7 +396,6 @@ export function localizeHref(href: string, options?: {
264
396
  *
265
397
  * @param {string} href - The href to de-localize (can be relative or absolute)
266
398
  * @returns {string} The de-localized href, relative if input was relative
267
- * @see deLocalizeUrl - For low-level URL de-localization in server contexts
268
399
  */
269
400
  export function deLocalizeHref(href: string): string;
270
401
  /**
@@ -273,54 +404,79 @@ export function deLocalizeHref(href: string): string;
273
404
  */
274
405
  export function trackMessageCall(safeModuleId: string, locale: Locale): void;
275
406
  /**
276
- * Generates a list of localized URLs for all provided URLs.
407
+ * Generates localized URL variants for all provided URLs based on your configured locales and URL patterns.
277
408
  *
278
- * This is useful for SSG (Static Site Generation) and sitemap generation.
279
- * NextJS and other frameworks use this function for SSG.
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
280
417
  *
281
418
  * @example
282
- * ```typescript
283
- * const urls = generateStaticLocalizedUrls([
284
- * "https://example.com/about",
285
- * "https://example.com/blog",
419
+ * // Basic usage - generate all locale variants for a list of paths
420
+ * const localizedUrls = generateStaticLocalizedUrls([
421
+ * "/",
422
+ * "/about",
423
+ * "/blog/post-1",
286
424
  * ]);
287
- * urls[0].href // => "https://example.com/about"
288
- * urls[1].href // => "https://example.com/blog"
289
- * urls[2].href // => "https://example.com/de/about"
290
- * urls[3].href // => "https://example.com/de/blog"
291
- * ...
292
- * ```
425
+ * // Returns URL objects for each locale:
426
+ * // ["/en/", "/de/", "/en/about", "/de/about", "/en/blog/post-1", "/de/blog/post-1"]
293
427
  *
294
- * @param {(string | URL)[]} urls - List of URLs to generate localized versions for. Can be absolute URLs or paths.
295
- * @returns {URL[]} List of localized URLs as URL objects
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.
296
448
  */
297
449
  export function generateStaticLocalizedUrls(urls: (string | URL)[]): URL[];
298
450
  /**
299
451
  * Checks if the given strategy is a custom strategy.
300
452
  *
301
- * @param {any} strategy The name of the custom strategy to validate.
453
+ * @param {unknown} strategy The name of the custom strategy to validate.
302
454
  * Must be a string that starts with "custom-" followed by alphanumeric characters, hyphens, or underscores.
303
455
  * @returns {boolean} Returns true if it is a custom strategy, false otherwise.
304
456
  */
305
- export function isCustomStrategy(strategy: any): boolean;
457
+ export function isCustomStrategy(strategy: unknown): boolean;
306
458
  /**
307
459
  * Defines a custom strategy that is executed on the server.
308
460
  *
309
- * @param {any} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
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.
310
464
  * @param {CustomServerStrategyHandler} handler The handler for the custom strategy, which should implement
311
465
  * the method getLocale.
312
466
  * @returns {void}
313
467
  */
314
- export function defineCustomServerStrategy(strategy: any, handler: CustomServerStrategyHandler): void;
468
+ export function defineCustomServerStrategy(strategy: string, handler: CustomServerStrategyHandler): void;
315
469
  /**
316
470
  * Defines a custom strategy that is executed on the client.
317
471
  *
318
- * @param {any} strategy The name of the custom strategy to define. Must follow the pattern custom-name with alphanumeric characters, hyphens, or underscores.
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.
319
475
  * @param {CustomClientStrategyHandler} handler The handler for the custom strategy, which should implement the
320
476
  * methods getLocale and setLocale.
321
477
  * @returns {void}
322
478
  */
323
- export function defineCustomClientStrategy(strategy: any, handler: CustomClientStrategyHandler): void;
479
+ export function defineCustomClientStrategy(strategy: string, handler: CustomClientStrategyHandler): void;
324
480
  /**
325
481
  * The project's base locale.
326
482
  *
@@ -351,10 +507,26 @@ export const localStorageKey: string;
351
507
  * @type {Array<"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage" | `custom-${string}`>}
352
508
  */
353
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
+ }>;
354
526
  /**
355
527
  * The used URL patterns.
356
528
  *
357
- * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }> }
529
+ * @type {Array<{ pattern: string, localized: Array<[Locale, string]> }>}
358
530
  */
359
531
  export const urlPatterns: Array<{
360
532
  pattern: string;
@@ -383,48 +555,28 @@ export let serverAsyncLocalStorage: ParaglideAsyncLocalStorage | undefined;
383
555
  export const disableAsyncLocalStorage: false;
384
556
  export const experimentalMiddlewareLocaleSplitting: false;
385
557
  export const isServer: boolean;
386
- /**
387
- * Get the current locale.
388
- *
389
- * @example
390
- * if (getLocale() === 'de') {
391
- * console.log('Germany 🇩🇪');
392
- * } else if (getLocale() === 'nl') {
393
- * console.log('Netherlands 🇳🇱');
394
- * }
395
- *
396
- * @type {() => Locale}
397
- */
398
- export let getLocale: () => Locale;
399
- /**
400
- * Overwrite the \`getLocale()\` function.
401
- *
402
- * Use this function to overwrite how the locale is resolved. For example,
403
- * you can resolve the locale from the browser's preferred language,
404
- * a cookie, env variable, or a user's preference.
405
- *
406
- * @example
407
- * overwriteGetLocale(() => {
408
- * // resolve the locale from a cookie. fallback to the base locale.
409
- * return Cookies.get('locale') ?? baseLocale
410
- * }
411
- *
412
- * @type {(fn: () => Locale) => void}
413
- */
414
- export const overwriteGetLocale: (fn: () => Locale) => void;
558
+ /** @type {Locale | undefined} */
559
+ export const experimentalStaticLocale: Locale | undefined;
560
+ export function getLocale(): Locale;
561
+ export function overwriteGetLocale(fn: () => Locale): void;
415
562
  /**
416
563
  * @typedef {(newLocale: Locale, options?: { reload?: boolean }) => void | Promise<void>} SetLocaleFn
417
564
  */
418
565
  /**
419
566
  * Set the locale.
420
567
  *
421
- * Set locale reloads the site by default on the client. Reloading
422
- * can be disabled by passing \`reload: false\` as an option. If
423
- * reloading is disabled, you need to ensure that the UI is updated
424
- * to reflect the new locale.
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.
425
575
  *
426
- * If any custom strategy's \`setLocale\` function is async, then this
427
- * function will become async as well.
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
428
580
  *
429
581
  * @example
430
582
  * setLocale('en');
@@ -439,71 +591,19 @@ export function overwriteSetLocale(fn: SetLocaleFn): void;
439
591
  /**
440
592
  * The origin of the current URL.
441
593
  *
442
- * Defaults to "http://y.com" in non-browser environments. If this
594
+ * Defaults to "http://example.com" in non-browser environments. If this
443
595
  * behavior is not desired, the implementation can be overwritten
444
596
  * by `overwriteGetUrlOrigin()`.
445
597
  *
446
598
  * @type {() => string}
447
599
  */
448
600
  export let getUrlOrigin: () => string;
449
- /**
450
- * Overwrite the getUrlOrigin function.
451
- *
452
- * Use this function in server environments to
453
- * define how the URL origin is resolved.
454
- *
455
- * @type {(fn: () => string) => void}
456
- */
457
- export let overwriteGetUrlOrigin: (fn: () => string) => void;
458
- /**
459
- * Extracts a locale from a request.
460
- *
461
- * Use the function on the server to extract the locale
462
- * from a request.
463
- *
464
- * The function goes through the strategies in the order
465
- * they are defined. If a strategy returns an invalid locale,
466
- * it will fall back to the next strategy.
467
- *
468
- * Note: Custom server strategies are not supported in this synchronous version.
469
- * Use `extractLocaleFromRequestAsync` if you need custom server strategies with async getLocale methods.
470
- *
471
- * @example
472
- * const locale = extractLocaleFromRequest(request);
473
- *
474
- * @type {(request: Request) => Locale}
475
- */
476
- export const extractLocaleFromRequest: (request: Request) => Locale;
477
- /**
478
- * Asynchronously extracts a locale from a request.
479
- *
480
- * This function supports async custom server strategies, unlike the synchronous
481
- * `extractLocaleFromRequest`. Use this function when you have custom server strategies
482
- * that need to perform asynchronous operations (like database calls) in their getLocale method.
483
- *
484
- * The function first processes any custom server strategies asynchronously, then falls back
485
- * to the synchronous `extractLocaleFromRequest` for all other strategies.
486
- *
487
- * @see {@link https://github.com/opral/inlang-paraglide-js/issues/527#issuecomment-2978151022}
488
- *
489
- * @example
490
- * // Basic usage
491
- * const locale = await extractLocaleFromRequestAsync(request);
492
- *
493
- * @example
494
- * // With custom async server strategy
495
- * defineCustomServerStrategy("custom-database", {
496
- * getLocale: async (request) => {
497
- * const userId = extractUserIdFromRequest(request);
498
- * return await getUserLocaleFromDatabase(userId);
499
- * }
500
- * });
501
- *
502
- * const locale = await extractLocaleFromRequestAsync(request);
503
- *
504
- * @type {(request: Request) => Promise<Locale>}
505
- */
506
- export const extractLocaleFromRequestAsync: (request: Request) => Promise<Locale>;
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>;
507
607
  /**
508
608
  * @typedef {"cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage"} BuiltInStrategy
509
609
  */
@@ -528,7 +628,10 @@ export const customServerStrategies: Map<string, CustomServerStrategyHandler>;
528
628
  export const customClientStrategies: Map<string, CustomClientStrategyHandler>;
529
629
  export type ShouldRedirectServerInput = {
530
630
  request: Request;
531
- url?: string | URL | undefined;
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;
532
635
  locale?: "en" | "fr" | "tl" | undefined;
533
636
  };
534
637
  export type ShouldRedirectClientInput = {
@@ -545,7 +648,7 @@ export type ShouldRedirectResult = {
545
648
  /**
546
649
  * - Locale resolved using the configured strategies.
547
650
  */
548
- locale: ReturnType<typeof assertIsLocale>;
651
+ locale: Locale;
549
652
  /**
550
653
  * - Destination URL when a redirect is required.
551
654
  */
@@ -566,6 +669,12 @@ export type ParaglideAsyncLocalStorage = {
566
669
  export type SetLocaleFn = (newLocale: Locale, options?: {
567
670
  reload?: boolean;
568
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
+ };
569
678
  export type BuiltInStrategy = "cookie" | "baseLocale" | "globalVariable" | "url" | "preferredLanguage" | "localStorage";
570
679
  export type CustomStrategy = `custom_${string}`;
571
680
  export type Strategy = BuiltInStrategy | CustomStrategy;
@@ -581,4 +690,96 @@ export type CustomClientStrategyHandler = {
581
690
  * A locale that is available in the project.
582
691
  */
583
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;
584
785
  //# sourceMappingURL=runtime.d.ts.map