@nano_kit/intl 1.2.0 → 2.0.0-prerelease.20260913103613
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/context.d.ts.map +1 -1
- package/dist/format/datetime.d.ts +3 -3
- package/dist/format/datetime.d.ts.map +1 -1
- package/dist/format/duration.d.ts +2 -2
- package/dist/format/duration.d.ts.map +1 -1
- package/dist/format/list.d.ts +2 -2
- package/dist/format/list.d.ts.map +1 -1
- package/dist/format/match.d.ts +2 -2
- package/dist/format/match.d.ts.map +1 -1
- package/dist/format/number.d.ts +3 -3
- package/dist/format/number.d.ts.map +1 -1
- package/dist/format/plural.d.ts +2 -2
- package/dist/format/plural.d.ts.map +1 -1
- package/dist/format/range.d.ts +3 -3
- package/dist/format/range.d.ts.map +1 -1
- package/dist/format/relativetime.d.ts +2 -2
- package/dist/format/relativetime.d.ts.map +1 -1
- package/dist/index.development.js +466 -0
- package/dist/index.development.js.map +1 -0
- package/dist/{index.js → index.production.js} +6 -6
- package/dist/index.production.js.map +1 -0
- package/package.json +5 -3
- package/dist/index.js.map +0 -1
package/dist/context.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../src/context.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAOpB,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EACV,eAAe,EACf,MAAM,EACN,cAAc,EAGd,kBAAkB,EAClB,gBAAgB,EACjB,MAAM,YAAY,CAAA;AA0BnB;;;;;;GAMG;AACH,qBAAa,WAAW,CACtB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,GAAG,kBAAkB;;IAGjD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAA;IAC7B;;OAEG;IACH,QAAQ,CAAC,QAAQ,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAC1C;;OAEG;IACH,QAAQ,CAAC,MAAM,EAAE,cAAc,CAAC,OAAO,CAAC,CAAA;IAExC;;;;OAIG;IACH,YACE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC,EACpB,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC,EAWlB;IAED;;;;;OAKG;IACH,QAAQ,CAAC,CAAC,SAAS,MAAM,CAAC,EAAE,CAAC,SAAS,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,EAAE,EAC7D,SAAS,EAAE,CAAC,EACZ,MAAM,GAAE,CAAW,aAwCwC,gBAAgB,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,oDAIrF;CACF"}
|
|
@@ -22,10 +22,10 @@ export declare function datetime(fallback: Date | number | string, options: fals
|
|
|
22
22
|
/**
|
|
23
23
|
* Creates a locale-aware date/time formatter with a fallback value.
|
|
24
24
|
* @param fallback - Value used when the input is `undefined` or `null`.
|
|
25
|
-
* @param options - `Intl.DateTimeFormat` options.
|
|
25
|
+
* @param options - `Intl.DateTimeFormat` options, or `{}` for the defaults.
|
|
26
26
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
27
27
|
*/
|
|
28
|
-
export declare function datetime(fallback: Date | number | string, options
|
|
28
|
+
export declare function datetime(fallback: Date | number | string, options: Intl.DateTimeFormatOptions): Format<Date | number | string | undefined, string | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* Creates a locale-aware date/time formatter with a custom formatting function.
|
|
31
31
|
* @param optionsOrFallback - `Intl.DateTimeFormat` options, `false`, or fallback value.
|
|
@@ -33,5 +33,5 @@ export declare function datetime(fallback: Date | number | string, options?: Int
|
|
|
33
33
|
* @param format - Custom formatting function.
|
|
34
34
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
35
35
|
*/
|
|
36
|
-
export declare function datetime<I = Date | number | string>(optionsOrFallback
|
|
36
|
+
export declare function datetime<I = Date | number | string>(optionsOrFallback: Intl.DateTimeFormatOptions | false | I | undefined, maybeOptions: Intl.DateTimeFormatOptions | false | undefined, format: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>): Format<I | undefined, string | undefined>;
|
|
37
37
|
//# sourceMappingURL=datetime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../src/format/datetime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,KAAK,YAAY,EAElB,MAAM,iBAAiB,CAAA;AASxB;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;AAE7C;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GACnC,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEjE;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAChC,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,IAAI,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,CAAC,CAAA;AAErE;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAChC,OAAO,
|
|
1
|
+
{"version":3,"file":"datetime.d.ts","sourceRoot":"","sources":["../../src/format/datetime.ts"],"names":[],"mappings":"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G,SAAS,CAAC,CAAA"}
|
|
@@ -22,8 +22,8 @@ export declare function duration(fallback: Duration, options: false): Format<Dur
|
|
|
22
22
|
/**
|
|
23
23
|
* Creates a locale-aware duration formatter with a fallback value.
|
|
24
24
|
* @param fallback - Value used when the input is `undefined` or `null`.
|
|
25
|
-
* @param options - `Intl.DurationFormat` options.
|
|
25
|
+
* @param options - `Intl.DurationFormat` options, or `{}` for the defaults.
|
|
26
26
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
27
27
|
*/
|
|
28
|
-
export declare function duration(fallback: Duration, options
|
|
28
|
+
export declare function duration(fallback: Duration, options: Intl.DurationFormatOptions): Format<Duration | undefined, string | undefined>;
|
|
29
29
|
//# sourceMappingURL=duration.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/format/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMxC,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAA;AAEvE;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;AAE/B;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GACnC,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzC;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,
|
|
1
|
+
{"version":3,"file":"duration.d.ts","sourceRoot":"","sources":["../../src/format/duration.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMxC,MAAM,MAAM,QAAQ,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,EAAE,MAAM,CAAC,CAAC,CAAA;AAEvE;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,GAAG,SAAS,CAAC,CAAA;AAE/B;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,OAAO,CAAC,EAAE,IAAI,CAAC,qBAAqB,GACnC,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEnD;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,QAAQ,CAAC,CAAA;AAEzC;;;;;GAKG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,IAAI,CAAC,qBAAqB,GAClC,MAAM,CAAC,QAAQ,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA"}
|
package/dist/format/list.d.ts
CHANGED
|
@@ -21,8 +21,8 @@ export declare function list(fallback: Iterable<string>, options: false): Format
|
|
|
21
21
|
/**
|
|
22
22
|
* Creates a locale-aware list formatter with a fallback value.
|
|
23
23
|
* @param fallback - Value used when the input is `undefined` or `null`.
|
|
24
|
-
* @param options - `Intl.ListFormat` options.
|
|
24
|
+
* @param options - `Intl.ListFormat` options, or `{}` for the defaults.
|
|
25
25
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
26
26
|
*/
|
|
27
|
-
export declare function list(fallback: Iterable<string>, options
|
|
27
|
+
export declare function list(fallback: Iterable<string>, options: Intl.ListFormatOptions): Format<Iterable<string> | undefined, string | undefined>;
|
|
28
28
|
//# sourceMappingURL=list.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/format/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMxC;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAE3D;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"list.d.ts","sourceRoot":"","sources":["../../src/format/list.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAMxC;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,CAAC,CAAA;AAEvC;;;;GAIG;AACH,wBAAgB,IAAI,CAClB,OAAO,CAAC,EAAE,IAAI,CAAC,iBAAiB,GAC/B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAE3D;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAA;AAEzD;;;;;GAKG;AACH,wBAAgB,IAAI,CAClB,QAAQ,EAAE,QAAQ,CAAC,MAAM,CAAC,EAC1B,OAAO,EAAE,IAAI,CAAC,iBAAiB,GAC9B,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA"}
|
package/dist/format/match.d.ts
CHANGED
|
@@ -29,7 +29,7 @@ export declare function other(key: string): GetKey;
|
|
|
29
29
|
* @param getKey - Optional resolver used to map the parameter value to a case key.
|
|
30
30
|
* @returns Formatter that resolves cases and returns a parameterized message function.
|
|
31
31
|
*/
|
|
32
|
-
export declare function match<const K extends string, const B extends Partial<Record<string, AnyFormat>>>(param: K, getKey?: GetKey): Format<FormatsInput<B
|
|
32
|
+
export declare function match<const K extends string, const B extends Partial<Record<string, AnyFormat>>>(param: K, getKey?: GetKey): Format<FormatsInput<B> | string, MatchFn<K, B>>;
|
|
33
33
|
/**
|
|
34
34
|
* Creates a formatter that selects one case by parameter value.
|
|
35
35
|
* @param param - Parameter name used to select a case and replace `{param}` placeholders.
|
|
@@ -37,6 +37,6 @@ export declare function match<const K extends string, const B extends Partial<Re
|
|
|
37
37
|
* @param getKey - Optional resolver used to map the parameter value to a case key.
|
|
38
38
|
* @returns Formatter that resolves cases and returns a parameterized message function.
|
|
39
39
|
*/
|
|
40
|
-
export declare function match<const K extends string, const B extends Partial<Record<string, AnyFormat>>>(param: K, cases?: CasesFn<K, B>, getKey?: GetKey): Format<FormatsInput<B
|
|
40
|
+
export declare function match<const K extends string, const B extends Partial<Record<string, AnyFormat>>>(param: K, cases?: CasesFn<K, B>, getKey?: GetKey): Format<FormatsInput<B> | string, MatchFn<K, B>>;
|
|
41
41
|
export {};
|
|
42
42
|
//# sourceMappingURL=match.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../../src/format/match.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,SAAS,EAIf,MAAM,iBAAiB,CAAA;AACxB,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,aAAa,CAAA;AAChD,OAAO,KAAK,EACV,SAAS,EACT,YAAY,EACZ,MAAM,EACN,YAAY,EACZ,mBAAmB,EACnB,QAAQ,EACT,MAAM,YAAY,CAAA;AAEnB,KAAK,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,SAAS,CAAC,MAAM,CAAC,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;AAEpE,MAAM,MAAM,WAAW,CACrB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAC1C;KACD,CAAC,IAAI,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC;CACrC,GAAG,mBAAmB,CAAC,UAAU,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;AAE/C,MAAM,MAAM,UAAU,GAAG,YAAY,CAAC,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAA;AAEjE,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,IAC1C,YAAY,CAAC,WAAW,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,MAAM,GAAG,MAAM,CAAC,CAAC,CAAA;AAEhE,MAAM,MAAM,OAAO,CACjB,CAAC,SAAS,MAAM,EAChB,CAAC,SAAS,OAAO,CAAC,MAAM,CAA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,EAAE,MAAM,EACd,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAC3B,MAAM,CAAA;AAEX;;;;GAIG;AAEH,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAElD,KAAK,EAAE,CAAC,GACP,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAWf;AAED;;;;GAIG;AAEH,wBAAgB,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEzC;AAED;;;;;GAKG;AACH,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAElD,KAAK,EAAE,CAAC,EACR,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CACP,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,EACxB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CACd,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,KAAK,CACnB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,EAElD,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,EACrB,MAAM,CAAC,EAAE,MAAM,GACd,MAAM,CACP,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,EACxB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CACd,CAAA"}
|
package/dist/format/number.d.ts
CHANGED
|
@@ -22,10 +22,10 @@ export declare function number(fallback: number | bigint | string, options: fals
|
|
|
22
22
|
/**
|
|
23
23
|
* Creates a locale-aware number formatter with a fallback value.
|
|
24
24
|
* @param fallback - Value used when the input is `undefined` or `null`.
|
|
25
|
-
* @param options - `Intl.NumberFormat` options.
|
|
25
|
+
* @param options - `Intl.NumberFormat` options, or `{}` for the defaults.
|
|
26
26
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
27
27
|
*/
|
|
28
|
-
export declare function number(fallback: number | bigint | string, options
|
|
28
|
+
export declare function number(fallback: number | bigint | string, options: Intl.NumberFormatOptions): Format<number | bigint | string | undefined, string | undefined>;
|
|
29
29
|
/**
|
|
30
30
|
* Creates a locale-aware number formatter with a custom formatting function.
|
|
31
31
|
* @param optionsOrFallback - `Intl.NumberFormat` options, `false`, or fallback value.
|
|
@@ -33,5 +33,5 @@ export declare function number(fallback: number | bigint | string, options?: Int
|
|
|
33
33
|
* @param format - Custom formatting function.
|
|
34
34
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
35
35
|
*/
|
|
36
|
-
export declare function number(optionsOrFallback
|
|
36
|
+
export declare function number(optionsOrFallback: Intl.NumberFormatOptions | false | number | bigint | string | undefined, maybeOptions: Intl.NumberFormatOptions | false | undefined, format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>): Format<number | bigint | string | undefined, string | undefined>;
|
|
37
37
|
//# sourceMappingURL=number.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"number.d.ts","sourceRoot":"","sources":["../../src/format/number.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,KAAK,YAAY,EAGlB,MAAM,iBAAiB,CAAA;AAExB;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,CAAC,CAAA;AAE/C;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,OAAO,CAAC,EAAE,IAAI,CAAC,mBAAmB,GACjC,MAAM,CAAC,MAAM,GAAG,MAA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C,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEnE;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,iBAAiB,EAAE,IAAI,CAAC,mBAAmB,GAAG,KAAK,GAAG,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAC1F,YAAY,EAAE,IAAI,CAAC,mBAAmB,GAAG,KAAK,GAAG,SAAS,EAC1D,MAAM,EAAE,YAAY,CAAC,IAAI,CAAC,YAAY,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,EAAE,IAAI,CAAC,mBAAmB,CAAC,GAC1F,MAAM,CAAC,MAAM,GAAG,MAAM,GAAG,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA"}
|
package/dist/format/plural.d.ts
CHANGED
|
@@ -9,7 +9,7 @@ export { cases as forms };
|
|
|
9
9
|
* @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.
|
|
10
10
|
* @returns Formatter that resolves plural forms and returns a parameterized message function.
|
|
11
11
|
*/
|
|
12
|
-
export declare function plural<const K extends string, const B extends Partial<Record<PluralKey, AnyFormat>>>(param: K, forms?: CasesFn<K, B>): Format<FormatsInput<B
|
|
12
|
+
export declare function plural<const K extends string, const B extends Partial<Record<PluralKey, AnyFormat>>>(param: K, forms?: CasesFn<K, B>): Format<FormatsInput<B> | string, MatchFn<K, B>>;
|
|
13
13
|
/**
|
|
14
14
|
* Creates a plural formatter with `Intl.PluralRules` options.
|
|
15
15
|
* @param param - Parameter name used to select plural form and replace `{param}` placeholders.
|
|
@@ -17,5 +17,5 @@ export declare function plural<const K extends string, const B extends Partial<R
|
|
|
17
17
|
* @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.
|
|
18
18
|
* @returns Formatter that resolves plural forms and returns a parameterized message function.
|
|
19
19
|
*/
|
|
20
|
-
export declare function plural<const K extends string, const B extends Partial<Record<PluralKey, AnyFormat>>>(param: K, options: Intl.PluralRulesOptions, forms?: CasesFn<K, B>): Format<FormatsInput<B
|
|
20
|
+
export declare function plural<const K extends string, const B extends Partial<Record<PluralKey, AnyFormat>>>(param: K, options: Intl.PluralRulesOptions, forms?: CasesFn<K, B>): Format<FormatsInput<B> | string, MatchFn<K, B>>;
|
|
21
21
|
//# sourceMappingURL=plural.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../src/format/plural.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,YAAY,EACb,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EAEZ,KAAK,EACN,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAA;AAE5C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,GAAG,MAAM,EAAE,CAAA;AAEhD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,CAAA;AAEzB;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAErD,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACpB,MAAM,CACP,YAAY,CAAC,CAAC,CAAC,
|
|
1
|
+
{"version":3,"file":"plural.d.ts","sourceRoot":"","sources":["../../src/format/plural.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,YAAY,EACb,MAAM,YAAY,CAAA;AACnB,OAAO,EACL,KAAK,OAAO,EACZ,KAAK,OAAO,EAEZ,KAAK,EACN,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,GAAG,IAAI,CAAC,cAAc,CAAA;AAE5C,MAAM,MAAM,SAAS,GAAG,UAAU,GAAG,GAAG,MAAM,EAAE,CAAA;AAEhD,OAAO,EAAE,KAAK,IAAI,KAAK,EAAE,CAAA;AAEzB;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAErD,KAAK,EAAE,CAAC,EACR,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACpB,MAAM,CACP,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,EACxB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CACd,CAAA;AAED;;;;;;GAMG;AACH,wBAAgB,MAAM,CACpB,KAAK,CAAC,CAAC,SAAS,MAAM,EACtB,KAAK,CAAC,CAAC,SAAS,OAAO,CAAC,MAAM,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC,EAErD,KAAK,EAAE,CAAC,EACR,OAAO,EAAE,IAAI,CAAC,kBAAkB,EAChC,KAAK,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,GACpB,MAAM,CACP,YAAY,CAAC,CAAC,CAAC,GAAG,MAAM,EACxB,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CACd,CAAA"}
|
package/dist/format/range.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { IntlFormatFn } from './intlformat.js';
|
|
2
2
|
import type { Format, IntlFormatRange } from './types.js';
|
|
3
3
|
type RangeInput<I> = readonly [from: I, to: I];
|
|
4
|
-
type RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (optionsOrFallback
|
|
4
|
+
type RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (optionsOrFallback: O | false | I | undefined, maybeOptions: O | false | undefined, format: IntlFormatFn<F, I, O>) => Format<I | undefined, R | undefined>;
|
|
5
5
|
/**
|
|
6
6
|
* Creates a range formatter in raw mode.
|
|
7
7
|
* @param format - Formatter factory that supports a custom range formatting function.
|
|
@@ -28,9 +28,9 @@ export declare function range<F extends IntlFormatRange<I>, I, O, R>(format: Ran
|
|
|
28
28
|
* Creates a locale-aware range formatter with a fallback range.
|
|
29
29
|
* @param format - Formatter factory that supports a custom range formatting function.
|
|
30
30
|
* @param fallback - Range used when the input is `undefined` or `null`.
|
|
31
|
-
* @param options - Formatter options.
|
|
31
|
+
* @param options - Formatter options, or `{}` for the defaults.
|
|
32
32
|
* @returns Formatter that returns a formatted range string or `undefined`.
|
|
33
33
|
*/
|
|
34
|
-
export declare function range<F extends IntlFormatRange<I>, I, O, R>(format: RangeFrom<F, I, O, R>, fallback: RangeInput<I>, options
|
|
34
|
+
export declare function range<F extends IntlFormatRange<I>, I, O, R>(format: RangeFrom<F, I, O, R>, fallback: RangeInput<I>, options: O): Format<RangeInput<I> | undefined, string | undefined>;
|
|
35
35
|
export {};
|
|
36
36
|
//# sourceMappingURL=range.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/format/range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EACV,MAAM,EACN,eAAe,EAChB,MAAM,YAAY,CAAA;AAEnB,KAAK,UAAU,CAAC,CAAC,IAAI,SAAS,CAAC,IAAI,EAAE,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,CAAA;AAE9C,KAAK,SAAS,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,IAAI,CACtD,iBAAiB,
|
|
1
|
+
{"version":3,"file":"range.d.ts","sourceRoot":"","sources":["../../src/format/range.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAA;AACnD,OAAO,KAAK,EACV,MAAM,EACN,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AAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC7B,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,UAAU,CAAC,CAAC,CAAC,CAAC,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,KAAK,CAAC,CAAC,SAAS,eAAe,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EACzD,MAAM,EAAE,SAAS,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,EAC7B,QAAQ,EAAE,UAAU,CAAC,CAAC,CAAC,EACvB,OAAO,EAAE,CAAC,GACT,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA"}
|
|
@@ -13,7 +13,7 @@ export declare function relativetime(options: false): Format<number | undefined>
|
|
|
13
13
|
* @param options - `Intl.RelativeTimeFormat` options with a required `unit`.
|
|
14
14
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
15
15
|
*/
|
|
16
|
-
export declare function relativetime(options
|
|
16
|
+
export declare function relativetime(options: RelativeTimeOptions): Format<number | undefined, string | undefined>;
|
|
17
17
|
/**
|
|
18
18
|
* Creates a relative time formatter in raw mode with a fallback value.
|
|
19
19
|
* @param fallback - Value returned when the input is `undefined` or `null`.
|
|
@@ -27,5 +27,5 @@ export declare function relativetime(fallback: number, options: false): Format<n
|
|
|
27
27
|
* @param options - `Intl.RelativeTimeFormat` options with a required `unit`.
|
|
28
28
|
* @returns Formatter that returns a formatted string or `undefined`.
|
|
29
29
|
*/
|
|
30
|
-
export declare function relativetime(fallback: number, options
|
|
30
|
+
export declare function relativetime(fallback: number, options: RelativeTimeOptions): Format<number | undefined, string | undefined>;
|
|
31
31
|
//# sourceMappingURL=relativetime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"relativetime.d.ts","sourceRoot":"","sources":["../../src/format/relativetime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,yBAAyB,GAAG;IACjE,IAAI,EAAE,IAAI,CAAC,sBAAsB,CAAA;CAClC,CAAA;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;AAE7B;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,
|
|
1
|
+
{"version":3,"file":"relativetime.d.ts","sourceRoot":"","sources":["../../src/format/relativetime.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AAGxC,MAAM,MAAM,mBAAmB,GAAG,IAAI,CAAC,yBAAyB,GAAG;IACjE,IAAI,EAAE,IAAI,CAAC,sBAAsB,CAAA;CAClC,CAAA;AAUD;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,MAAM,GAAG,SAAS,CAAC,CAAA;AAE7B;;;;GAIG;AACH,wBAAgB,YAAY,CAC1B,OAAO,EAAE,mBAAmB,GAC3B,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEjD;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,KAAK,GACb,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,CAAA;AAErC;;;;;GAKG;AACH,wBAAgB,YAAY,CAC1B,QAAQ,EAAE,MAAM,EAChB,OAAO,EAAE,mBAAmB,GAC3B,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA"}
|
|
@@ -0,0 +1,466 @@
|
|
|
1
|
+
import { $get, computed, identity, isFunction, signal, untracked } from "@nano_kit/store";
|
|
2
|
+
//#region src/format/raw.ts
|
|
3
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
4
|
+
function raw(fallback) {
|
|
5
|
+
return (_ctx, input) => input ?? fallback;
|
|
6
|
+
}
|
|
7
|
+
//#endregion
|
|
8
|
+
//#region src/format/text.ts
|
|
9
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
10
|
+
function text(fallback) {
|
|
11
|
+
return /* @__PURE__ */ raw(fallback);
|
|
12
|
+
}
|
|
13
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
14
|
+
function uppercase(format) {
|
|
15
|
+
return (ctx, input) => format(ctx, input)?.toLocaleUpperCase(ctx.$locale());
|
|
16
|
+
}
|
|
17
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
18
|
+
function lowercase(format) {
|
|
19
|
+
return (ctx, input) => format(ctx, input)?.toLocaleLowerCase(ctx.$locale());
|
|
20
|
+
}
|
|
21
|
+
function toCapitalize(message, locale) {
|
|
22
|
+
return message === void 0 ? message : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1);
|
|
23
|
+
}
|
|
24
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
25
|
+
function capitalize(format) {
|
|
26
|
+
return (ctx, input) => toCapitalize(format(ctx, input), ctx.$locale());
|
|
27
|
+
}
|
|
28
|
+
//#endregion
|
|
29
|
+
//#region src/utils.ts
|
|
30
|
+
function memo(fn) {
|
|
31
|
+
let key;
|
|
32
|
+
let value;
|
|
33
|
+
return (newKey) => {
|
|
34
|
+
if (newKey !== key) {
|
|
35
|
+
value = fn(newKey);
|
|
36
|
+
key = newKey;
|
|
37
|
+
}
|
|
38
|
+
return value;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/format/intlformat.ts
|
|
43
|
+
function defaultFormat(fmt, value) {
|
|
44
|
+
return fmt.format(value);
|
|
45
|
+
}
|
|
46
|
+
function intlformat(IntlFormat, format, optionsOrFallback, maybeOptions) {
|
|
47
|
+
let fallback;
|
|
48
|
+
let options;
|
|
49
|
+
if (maybeOptions !== void 0) {
|
|
50
|
+
fallback = optionsOrFallback;
|
|
51
|
+
options = maybeOptions;
|
|
52
|
+
} else options = optionsOrFallback;
|
|
53
|
+
const rawFormat = /* @__PURE__ */ raw(fallback);
|
|
54
|
+
if (options === false) return rawFormat;
|
|
55
|
+
const fmt = memo((locale) => new IntlFormat(locale, options));
|
|
56
|
+
return (ctx, input) => {
|
|
57
|
+
const value = rawFormat(ctx, input);
|
|
58
|
+
if (value === void 0) return value;
|
|
59
|
+
return format(fmt(ctx.$locale()), value, options);
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
//#endregion
|
|
63
|
+
//#region src/format/number.ts
|
|
64
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
65
|
+
function number(optionsOrFallback, maybeOptions, format = defaultFormat) {
|
|
66
|
+
return intlformat(Intl.NumberFormat, format, optionsOrFallback, maybeOptions);
|
|
67
|
+
}
|
|
68
|
+
//#endregion
|
|
69
|
+
//#region src/format/datetime.ts
|
|
70
|
+
function datetimeFormat(fmt, value) {
|
|
71
|
+
return fmt.format(typeof value === "string" ? new Date(value) : value);
|
|
72
|
+
}
|
|
73
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
74
|
+
function datetime(optionsOrFallback, maybeOptions, format = datetimeFormat) {
|
|
75
|
+
return intlformat(Intl.DateTimeFormat, format, optionsOrFallback, maybeOptions);
|
|
76
|
+
}
|
|
77
|
+
//#endregion
|
|
78
|
+
//#region src/format/range.ts
|
|
79
|
+
function rangeFormat(fmt, [from, to]) {
|
|
80
|
+
return fmt.formatRange(from, to);
|
|
81
|
+
}
|
|
82
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
83
|
+
function range(format, optionsOrFallback, maybeOptions) {
|
|
84
|
+
return format(optionsOrFallback, maybeOptions, rangeFormat);
|
|
85
|
+
}
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/format/relativetime.ts
|
|
88
|
+
function relativeTimeFormat(fmt, value, options) {
|
|
89
|
+
return fmt.format(value, options.unit);
|
|
90
|
+
}
|
|
91
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
92
|
+
function relativetime(optionsOrFallback, maybeOptions) {
|
|
93
|
+
return intlformat(Intl.RelativeTimeFormat, relativeTimeFormat, optionsOrFallback, maybeOptions);
|
|
94
|
+
}
|
|
95
|
+
//#endregion
|
|
96
|
+
//#region src/format/duration.ts
|
|
97
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
98
|
+
function duration(optionsOrFallback, maybeOptions) {
|
|
99
|
+
return intlformat(Intl.DurationFormat, defaultFormat, optionsOrFallback, maybeOptions);
|
|
100
|
+
}
|
|
101
|
+
//#endregion
|
|
102
|
+
//#region src/format/list.ts
|
|
103
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
104
|
+
function list(optionsOrFallback, maybeOptions) {
|
|
105
|
+
return intlformat(Intl.ListFormat, defaultFormat, optionsOrFallback, maybeOptions);
|
|
106
|
+
}
|
|
107
|
+
//#endregion
|
|
108
|
+
//#region src/format/rich.ts
|
|
109
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
110
|
+
function rich(fallbackOrTags, maybeTags) {
|
|
111
|
+
let fallback;
|
|
112
|
+
let tags;
|
|
113
|
+
if (maybeTags) {
|
|
114
|
+
fallback = fallbackOrTags;
|
|
115
|
+
tags = maybeTags;
|
|
116
|
+
} else tags = fallbackOrTags;
|
|
117
|
+
return (_ctx, input) => {
|
|
118
|
+
const text = input ?? fallback;
|
|
119
|
+
if (text === void 0) return text;
|
|
120
|
+
return /* @__PURE__ */ mapTags(text, tags);
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
const tagRegex = /<(\/?)([A-Za-z][\w.-]*)\s*(\/?)>/g;
|
|
124
|
+
/**
|
|
125
|
+
* Maps rich-text tags in a string to chunks using provided tag handlers.
|
|
126
|
+
* Each handler call receives an unique index, usable as a key for framework nodes.
|
|
127
|
+
* Self-closing tags are mapped with empty chunks.
|
|
128
|
+
* Unknown or malformed tags are ignored as markup and only their text content is kept.
|
|
129
|
+
* @param input - Rich-text input string.
|
|
130
|
+
* @param tags - Tag handlers used to map known tags.
|
|
131
|
+
* @returns Mapped chunks.
|
|
132
|
+
*/
|
|
133
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
134
|
+
function mapTags(input, tags) {
|
|
135
|
+
const root = {
|
|
136
|
+
tag: "",
|
|
137
|
+
chunks: []
|
|
138
|
+
};
|
|
139
|
+
const stack = [root];
|
|
140
|
+
let lastIndex = 0;
|
|
141
|
+
let index = 0;
|
|
142
|
+
let match;
|
|
143
|
+
tagRegex.lastIndex = 0;
|
|
144
|
+
while (match = tagRegex.exec(input)) {
|
|
145
|
+
const [, closing, tag, selfClosing] = match;
|
|
146
|
+
const current = stack[stack.length - 1];
|
|
147
|
+
if (match.index > lastIndex) current.chunks.push(input.slice(lastIndex, match.index));
|
|
148
|
+
lastIndex = tagRegex.lastIndex;
|
|
149
|
+
if (tag in tags) {
|
|
150
|
+
if (closing) {
|
|
151
|
+
if (current.tag === tag) {
|
|
152
|
+
stack.pop();
|
|
153
|
+
stack[stack.length - 1].chunks.push(tags[tag](current.chunks, index++));
|
|
154
|
+
}
|
|
155
|
+
} else if (selfClosing) current.chunks.push(tags[tag]([], index++));
|
|
156
|
+
else stack.push({
|
|
157
|
+
tag,
|
|
158
|
+
chunks: []
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
tagRegex.lastIndex = lastIndex;
|
|
162
|
+
}
|
|
163
|
+
if (lastIndex < input.length) stack[stack.length - 1].chunks.push(input.slice(lastIndex));
|
|
164
|
+
for (let i = stack.length - 1; i > 0; i--) {
|
|
165
|
+
const frame = stack[i];
|
|
166
|
+
stack[i - 1].chunks.push(...frame.chunks);
|
|
167
|
+
}
|
|
168
|
+
return root.chunks;
|
|
169
|
+
}
|
|
170
|
+
//#endregion
|
|
171
|
+
//#region src/format/markup.ts
|
|
172
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
173
|
+
function markup(fallbackOrTags, maybeTags) {
|
|
174
|
+
let fallback;
|
|
175
|
+
let tags;
|
|
176
|
+
if (maybeTags) {
|
|
177
|
+
fallback = fallbackOrTags;
|
|
178
|
+
tags = maybeTags;
|
|
179
|
+
} else tags = fallbackOrTags;
|
|
180
|
+
const richTags = {};
|
|
181
|
+
for (const [tag, format] of Object.entries(tags)) richTags[tag] = (chunks) => format(chunks.join(""));
|
|
182
|
+
const richFormat = /* @__PURE__ */ rich(fallback, richTags);
|
|
183
|
+
return (ctx, input) => richFormat(ctx, input)?.join("");
|
|
184
|
+
}
|
|
185
|
+
//#endregion
|
|
186
|
+
//#region src/format/format.ts
|
|
187
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
188
|
+
function format(type) {
|
|
189
|
+
return (ctx) => (value) => type(ctx, value);
|
|
190
|
+
}
|
|
191
|
+
//#endregion
|
|
192
|
+
//#region src/format/params.ts
|
|
193
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
194
|
+
function params(params, preformat) {
|
|
195
|
+
let replaceAll;
|
|
196
|
+
for (let [key, format] of Object.entries(params)) {
|
|
197
|
+
{
|
|
198
|
+
const originalFormat = format;
|
|
199
|
+
format = (ctx, value) => {
|
|
200
|
+
const formatted = originalFormat(ctx, value);
|
|
201
|
+
if (formatted === void 0) console.warn(`[nano_kit/intl] Parameter "${key}" has no value: the message renders "undefined" in its place`);
|
|
202
|
+
return formatted;
|
|
203
|
+
};
|
|
204
|
+
}
|
|
205
|
+
const re = new RegExp(`{${key}}`, "g");
|
|
206
|
+
const replace = (ctx, text, params) => text.replace(re, () => format(ctx, $get(params[key])));
|
|
207
|
+
if (replaceAll) {
|
|
208
|
+
const prevReplace = replaceAll;
|
|
209
|
+
replaceAll = (ctx, text, params) => replace(ctx, prevReplace(ctx, text, params), params);
|
|
210
|
+
} else replaceAll = replace;
|
|
211
|
+
}
|
|
212
|
+
return (ctx, input) => {
|
|
213
|
+
const preformatted = preformat ? preformat(ctx, input) : input;
|
|
214
|
+
if (isFunction(preformatted)) return (params) => {
|
|
215
|
+
const text = preformatted(params);
|
|
216
|
+
if (text === void 0 || !replaceAll) return text;
|
|
217
|
+
return replaceAll(ctx, text, params);
|
|
218
|
+
};
|
|
219
|
+
if (preformatted === void 0 || !replaceAll) return () => preformatted;
|
|
220
|
+
return (params) => replaceAll(ctx, preformatted, params);
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
//#endregion
|
|
224
|
+
//#region src/format/match.ts
|
|
225
|
+
/**
|
|
226
|
+
* Creates a reusable cases resolver for `match`.
|
|
227
|
+
* @param cases - Case formatters keyed by possible resolved values.
|
|
228
|
+
* @returns Resolver that formats all cases for the current context and translation input.
|
|
229
|
+
*/
|
|
230
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
231
|
+
function cases(cases) {
|
|
232
|
+
const entries = Object.entries(cases);
|
|
233
|
+
const fn = ((ctx, input, resolvedCases) => {
|
|
234
|
+
for (const [key, format] of entries) resolvedCases[key] = format(ctx, input?.[key]);
|
|
235
|
+
});
|
|
236
|
+
fn.s = true;
|
|
237
|
+
return fn;
|
|
238
|
+
}
|
|
239
|
+
/**
|
|
240
|
+
* Creates a case key resolver that falls back to a known case when the parameter value is missing.
|
|
241
|
+
* @param key - Case key used when the parameter value does not exist in resolved cases.
|
|
242
|
+
* @returns Resolver that keeps existing case keys and falls back to `key` for unknown values.
|
|
243
|
+
*/
|
|
244
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
245
|
+
function other(key) {
|
|
246
|
+
return (param, _, cases) => param in cases ? param : key;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* Creates a formatter that selects one case by parameter value.
|
|
250
|
+
* @param param - Parameter name used to select a case and replace `{param}` placeholders.
|
|
251
|
+
* @param cases - Case formatters keyed by possible resolved values.
|
|
252
|
+
* @param getKey - Optional resolver used to map the parameter value to a case key.
|
|
253
|
+
* @returns Formatter that resolves cases and returns a parameterized message function.
|
|
254
|
+
*/
|
|
255
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
256
|
+
function match(param, casesOrGetKey, maybeGetKey) {
|
|
257
|
+
const valuePattern = new RegExp(`{${param}}`, "g");
|
|
258
|
+
let cases;
|
|
259
|
+
let getKey;
|
|
260
|
+
if (casesOrGetKey?.s) {
|
|
261
|
+
cases = casesOrGetKey;
|
|
262
|
+
getKey = maybeGetKey ?? identity;
|
|
263
|
+
} else getKey = maybeGetKey ?? casesOrGetKey ?? identity;
|
|
264
|
+
return (ctx, input) => {
|
|
265
|
+
const locale = ctx.$locale();
|
|
266
|
+
const isString = typeof input === "string";
|
|
267
|
+
let resolvedCases = input ?? {};
|
|
268
|
+
if (cases && !isString) {
|
|
269
|
+
resolvedCases = { ...resolvedCases };
|
|
270
|
+
cases(ctx, input, resolvedCases);
|
|
271
|
+
}
|
|
272
|
+
return (params) => {
|
|
273
|
+
const value = $get(typeof params === "object" ? params[param] : params);
|
|
274
|
+
const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)];
|
|
275
|
+
return (isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase)?.replace(valuePattern, value);
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
}
|
|
279
|
+
//#endregion
|
|
280
|
+
//#region src/format/plural.ts
|
|
281
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
282
|
+
function plural(param, optionsOrForms, maybeForms) {
|
|
283
|
+
let options;
|
|
284
|
+
let forms;
|
|
285
|
+
if (isFunction(optionsOrForms)) forms = optionsOrForms;
|
|
286
|
+
else {
|
|
287
|
+
options = optionsOrForms;
|
|
288
|
+
forms = maybeForms;
|
|
289
|
+
}
|
|
290
|
+
const rules = memo((locale) => new Intl.PluralRules(locale, options));
|
|
291
|
+
return /* @__PURE__ */ match(param, forms, (count, locale, forms) => {
|
|
292
|
+
if (count in forms) return count;
|
|
293
|
+
let form = rules(locale).select(count);
|
|
294
|
+
if (!(form in forms)) form = "other" in forms ? "other" : "many";
|
|
295
|
+
return form;
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
//#endregion
|
|
299
|
+
//#region src/context.ts
|
|
300
|
+
const proxyHandler = { get($signal, key, receiver) {
|
|
301
|
+
if (!(key in $signal)) {
|
|
302
|
+
if (key[0] === "$") {
|
|
303
|
+
const prop = key.slice(1);
|
|
304
|
+
return $signal[key] = computed(() => $signal()[prop]);
|
|
305
|
+
} else if (typeof key === "string") {
|
|
306
|
+
const $prop = receiver[`$${key}`];
|
|
307
|
+
return $signal[key] = (params) => computed(() => $prop()(params));
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
return $signal[key];
|
|
311
|
+
} };
|
|
312
|
+
/**
|
|
313
|
+
* Runtime context used by message formats.
|
|
314
|
+
*
|
|
315
|
+
* It owns the active locale, loads translation data, and exposes messages helpers
|
|
316
|
+
* that bind a messages scheme to the current namespace data.
|
|
317
|
+
* @template T - Translation data shape keyed by namespace name.
|
|
318
|
+
*/
|
|
319
|
+
var IntlContext = class {
|
|
320
|
+
#loader;
|
|
321
|
+
/**
|
|
322
|
+
* Active locale accessor.
|
|
323
|
+
*/
|
|
324
|
+
$locale;
|
|
325
|
+
/**
|
|
326
|
+
* Loading state for full-data loaders.
|
|
327
|
+
*/
|
|
328
|
+
$loading;
|
|
329
|
+
/**
|
|
330
|
+
* Loading error for full-data loaders.
|
|
331
|
+
*/
|
|
332
|
+
$error;
|
|
333
|
+
/**
|
|
334
|
+
* Creates an internationalization context.
|
|
335
|
+
* @param $locale - Active locale accessor.
|
|
336
|
+
* @param loader - Messages loader bound to the active locale.
|
|
337
|
+
*/
|
|
338
|
+
constructor($locale, loader) {
|
|
339
|
+
this.$locale = $locale;
|
|
340
|
+
this.#loader = loader;
|
|
341
|
+
if (isFunction(loader)) {
|
|
342
|
+
this.$loading = signal(false);
|
|
343
|
+
this.$error = signal(void 0);
|
|
344
|
+
} else [, this.$error, this.$loading] = loader;
|
|
345
|
+
}
|
|
346
|
+
/**
|
|
347
|
+
* Creates reactive messages for a single namespace.
|
|
348
|
+
* @param namespace - Namespace key to read from loaded translation data.
|
|
349
|
+
* @param scheme - Messages scheme compatible with the namespace data shape.
|
|
350
|
+
* @returns A tuple with formatted messages, pending state, and loading error.
|
|
351
|
+
*/
|
|
352
|
+
messages(namespace, scheme = {}) {
|
|
353
|
+
const entries = Object.entries(scheme);
|
|
354
|
+
const loaderResult = this.#loader;
|
|
355
|
+
let $data;
|
|
356
|
+
let $error;
|
|
357
|
+
let $pending;
|
|
358
|
+
if (isFunction(loaderResult)) [$data, $error, $pending] = loaderResult(namespace, entries);
|
|
359
|
+
else {
|
|
360
|
+
let $translations;
|
|
361
|
+
[$translations, $error, $pending] = loaderResult;
|
|
362
|
+
$data = computed(() => $translations()?.[namespace]);
|
|
363
|
+
}
|
|
364
|
+
const $messages = computed(() => {
|
|
365
|
+
const data = $data();
|
|
366
|
+
let result = data ?? {};
|
|
367
|
+
if (entries.length > 0) {
|
|
368
|
+
result = { ...result };
|
|
369
|
+
for (const [key, format] of entries) {
|
|
370
|
+
if (data && !(key in data)) console.warn(`[nano_kit/intl] Missing message "${String(namespace)}.${key}" for locale "${untracked(this.$locale)}"`);
|
|
371
|
+
result[key] = format(this, data?.[key]);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
return result;
|
|
375
|
+
});
|
|
376
|
+
return [
|
|
377
|
+
new Proxy($messages, proxyHandler),
|
|
378
|
+
$pending,
|
|
379
|
+
$error
|
|
380
|
+
];
|
|
381
|
+
}
|
|
382
|
+
};
|
|
383
|
+
//#endregion
|
|
384
|
+
//#region src/deflat.ts
|
|
385
|
+
function isObject(value) {
|
|
386
|
+
return value !== null && typeof value === "object" && Object.getPrototypeOf(value) === Object.prototype;
|
|
387
|
+
}
|
|
388
|
+
function ensure(target, path, offset = 0) {
|
|
389
|
+
let container = target;
|
|
390
|
+
for (let i = 0, len = path.length - offset, key; i < len; i++) {
|
|
391
|
+
key = path[i];
|
|
392
|
+
if (!isObject(container[key])) container[key] = {};
|
|
393
|
+
container = container[key];
|
|
394
|
+
}
|
|
395
|
+
return container;
|
|
396
|
+
}
|
|
397
|
+
function set(target, path, value) {
|
|
398
|
+
const key = path[path.length - 1];
|
|
399
|
+
const container = ensure(target, path, 1);
|
|
400
|
+
container[key] = value;
|
|
401
|
+
}
|
|
402
|
+
function assign(target, source, depth, level) {
|
|
403
|
+
for (const [key, value] of Object.entries(source)) {
|
|
404
|
+
const path = level >= depth ? key.split(".") : [key];
|
|
405
|
+
if (isObject(value)) assign(ensure(target, path), value, depth, level + path.length);
|
|
406
|
+
else set(target, path, value);
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
410
|
+
function deflat(input, depth = 0) {
|
|
411
|
+
const output = {};
|
|
412
|
+
assign(output, input, depth, 0);
|
|
413
|
+
return output;
|
|
414
|
+
}
|
|
415
|
+
//#endregion
|
|
416
|
+
//#region src/intl.ts
|
|
417
|
+
/**
|
|
418
|
+
* Creates an internationalization context with bound helpers.
|
|
419
|
+
* @param $locale - Active locale accessor.
|
|
420
|
+
* @param loader - Messages loader bound to the active locale.
|
|
421
|
+
* @returns Internationalization context with `messages` safe to destructure.
|
|
422
|
+
*/
|
|
423
|
+
function intl($locale, loader) {
|
|
424
|
+
const ctx = new IntlContext($locale, loader);
|
|
425
|
+
ctx.messages = ctx.messages.bind(ctx);
|
|
426
|
+
return ctx;
|
|
427
|
+
}
|
|
428
|
+
//#endregion
|
|
429
|
+
//#region src/direction.ts
|
|
430
|
+
const rtlLocales = /* @__PURE__ */ new Set([
|
|
431
|
+
"ar",
|
|
432
|
+
"arc",
|
|
433
|
+
"dv",
|
|
434
|
+
"fa",
|
|
435
|
+
"ha",
|
|
436
|
+
"he",
|
|
437
|
+
"khw",
|
|
438
|
+
"ks",
|
|
439
|
+
"ku",
|
|
440
|
+
"ps",
|
|
441
|
+
"ur",
|
|
442
|
+
"yi"
|
|
443
|
+
]);
|
|
444
|
+
/**
|
|
445
|
+
* Resolves text direction for a locale.
|
|
446
|
+
* @param locale - BCP 47 locale code.
|
|
447
|
+
* @returns `rtl` for right-to-left languages, otherwise `ltr`.
|
|
448
|
+
*/
|
|
449
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
450
|
+
function getDirection(locale) {
|
|
451
|
+
const lang = new Intl.Locale(locale).language;
|
|
452
|
+
return rtlLocales.has(lang) ? "rtl" : "ltr";
|
|
453
|
+
}
|
|
454
|
+
/**
|
|
455
|
+
* Creates a computed text direction from a locale accessor.
|
|
456
|
+
* @param $locale - Active locale accessor.
|
|
457
|
+
* @returns Signal with `rtl` or `ltr` direction.
|
|
458
|
+
*/
|
|
459
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
460
|
+
function direction($locale) {
|
|
461
|
+
return computed(() => /* @__PURE__ */ getDirection($locale()));
|
|
462
|
+
}
|
|
463
|
+
//#endregion
|
|
464
|
+
export { IntlContext, capitalize, cases, cases as forms, datetime, deflat, direction, duration, format, getDirection, intl, list, lowercase, mapTags, markup, match, number, other, params, plural, range, raw, relativetime, rich, rtlLocales, text, uppercase };
|
|
465
|
+
|
|
466
|
+
//# sourceMappingURL=index.development.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.development.js","names":["#loader"],"sources":["../src/format/raw.ts","../src/format/text.ts","../src/utils.ts","../src/format/intlformat.ts","../src/format/number.ts","../src/format/datetime.ts","../src/format/range.ts","../src/format/relativetime.ts","../src/format/duration.ts","../src/format/list.ts","../src/format/rich.ts","../src/format/markup.ts","../src/format/format.ts","../src/format/params.ts","../src/format/match.ts","../src/format/plural.ts","../src/context.ts","../src/deflat.ts","../src/intl.ts","../src/direction.ts"],"sourcesContent":["import type { Format } from './types.js'\n\n/**\n * Creates a pass-through formatter.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function raw<T>(): Format<T | undefined>\n\n/**\n * Creates a pass-through formatter with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function raw<T>(fallback: T): Format<T | undefined, T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function raw<T>(fallback?: T) {\n return (_ctx: unknown, input?: T) => input ?? fallback\n}\n","import type { Format } from './types.js'\nimport { raw } from './raw.js'\n\n/**\n * Creates a string formatter.\n * @returns Formatter that returns the input string or `undefined`.\n */\nexport function text(): Format<string | undefined>\n\n/**\n * Creates a string formatter with a fallback value.\n * @param fallback - String returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input string or fallback.\n */\nexport function text(fallback: string): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function text(fallback?: string): Format<string | undefined> {\n return raw(fallback)\n}\n\n/**\n * Creates a formatter that uppercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with uppercased output.\n */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function uppercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleUpperCase(ctx.$locale())\n}\n\n/**\n * Creates a formatter that lowercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with lowercased output.\n */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function lowercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleLowerCase(ctx.$locale())\n}\n\nfunction toCapitalize(message: string | undefined, locale: string) {\n return message === undefined\n ? message\n : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1)\n}\n\n/**\n * Creates a formatter that capitalizes another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with the first character uppercased.\n */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function capitalize<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => toCapitalize(format(ctx, input), ctx.$locale())\n}\n","export function memo<T, K>(fn: (key: K) => T): (key: K) => T {\n let key: K\n let value: T\n\n return (newKey) => {\n if (newKey !== key) {\n value = fn(newKey)\n key = newKey\n }\n\n return value\n }\n}\n","import type { FormatContext } from '../types.js'\nimport { memo } from '../utils.js'\nimport type { IntlFormat } from './types.js'\nimport { raw } from './raw.js'\n\nexport type IntlFormatConstructor<F, O> = new (\n locale: string,\n options?: O\n) => F\n\nexport type IntlFormatFn<F extends IntlFormat<unknown>, I, O> = (\n fmt: F,\n value: I,\n options: O | undefined\n) => string\n\nexport function defaultFormat<F extends IntlFormat<I>, I>(\n fmt: F,\n value: I\n) {\n return fmt.format(value)\n}\n\nexport function intlformat<\n F extends IntlFormat<unknown>,\n I,\n O\n>(\n IntlFormat: IntlFormatConstructor<NoInfer<F>, O>,\n format: IntlFormatFn<F, I, O>,\n optionsOrFallback?: O | false | I,\n maybeOptions?: O | false\n) {\n let fallback: I | undefined\n let options: O | false | undefined\n\n if (maybeOptions !== undefined) {\n fallback = optionsOrFallback as I\n options = maybeOptions\n } else {\n options = optionsOrFallback as O | false | undefined\n }\n\n const rawFormat = raw(fallback)\n\n if (options === false) {\n return rawFormat\n }\n\n const fmt = memo((locale: string) => new IntlFormat(locale, options))\n\n return (ctx: FormatContext, input?: I) => {\n const value = rawFormat(ctx, input)\n\n if (value === undefined) {\n return value\n }\n\n return format(fmt(ctx.$locale()), value, options)\n }\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a number formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function number(\n options: false\n): Format<number | bigint | string | undefined>\n\n/**\n * Creates a locale-aware number formatter.\n * @param options - `Intl.NumberFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n options?: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a number formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function number(\n fallback: number | bigint | string,\n options: false\n): Format<number | bigint | string | undefined, number | bigint | string>\n\n/**\n * Creates a locale-aware number formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.NumberFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n fallback: number | bigint | string,\n options: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware number formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.NumberFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.NumberFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n optionsOrFallback: Intl.NumberFormatOptions | false | number | bigint | string | undefined,\n maybeOptions: Intl.NumberFormatOptions | false | undefined,\n format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>\n): Format<number | bigint | string | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function number(\n optionsOrFallback?: Intl.NumberFormatOptions | false | number | bigint | string,\n maybeOptions?: Intl.NumberFormatOptions | false,\n format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions> = defaultFormat\n) {\n return intlformat<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>(\n Intl.NumberFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n intlformat\n} from './intlformat.js'\n\nfunction datetimeFormat(\n fmt: Intl.DateTimeFormat,\n value: Date | number | string\n) {\n return fmt.format(typeof value === 'string' ? new Date(value) : value)\n}\n\n/**\n * Creates a date/time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function datetime(\n options: false\n): Format<Date | number | string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter.\n * @param options - `Intl.DateTimeFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n options?: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a date/time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function datetime(\n fallback: Date | number | string,\n options: false\n): Format<Date | number | string | undefined, Date | number | string>\n\n/**\n * Creates a locale-aware date/time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DateTimeFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n fallback: Date | number | string,\n options: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.DateTimeFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.DateTimeFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime<I = Date | number | string>(\n optionsOrFallback: Intl.DateTimeFormatOptions | false | I | undefined,\n maybeOptions: Intl.DateTimeFormatOptions | false | undefined,\n format: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>\n): Format<I | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function datetime(\n optionsOrFallback?: Intl.DateTimeFormatOptions | false | Date | number | string,\n maybeOptions?: Intl.DateTimeFormatOptions | false,\n format: IntlFormatFn<Intl.DateTimeFormat, Date | number | string, Intl.DateTimeFormatOptions> = datetimeFormat\n) {\n return intlformat(\n Intl.DateTimeFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { IntlFormatFn } from './intlformat.js'\nimport type {\n Format,\n IntlFormatRange\n} from './types.js'\n\ntype RangeInput<I> = readonly [from: I, to: I]\n\ntype RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (\n optionsOrFallback: O | false | I | undefined,\n maybeOptions: O | false | undefined,\n format: IntlFormatFn<F, I, O>\n) => Format<I | undefined, R | undefined>\n\nfunction rangeFormat(\n fmt: IntlFormatRange<unknown>,\n [from, to]: RangeInput<unknown>\n) {\n return fmt.formatRange(from, to)\n}\n\n/**\n * Creates a range formatter in raw mode.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Pass `false` to return the input range without formatting.\n * @returns Formatter that returns the input range or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options: false\n): Format<RangeInput<I> | undefined>\n\n/**\n * Creates a locale-aware range formatter.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Formatter options.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options?: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/**\n * Creates a range formatter in raw mode with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input range or fallback without formatting.\n * @returns Formatter that returns the input range or fallback.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options: false\n): Format<RangeInput<I> | undefined, RangeInput<I>>\n\n/**\n * Creates a locale-aware range formatter with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range used when the input is `undefined` or `null`.\n * @param options - Formatter options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n optionsOrFallback?: O | false | RangeInput<I>,\n maybeOptions?: O | false\n) {\n return format(\n optionsOrFallback as I,\n maybeOptions,\n rangeFormat as IntlFormatFn<F, I, O>\n )\n}\n","import type { Format } from './types.js'\nimport { intlformat } from './intlformat.js'\n\nexport type RelativeTimeOptions = Intl.RelativeTimeFormatOptions & {\n unit: Intl.RelativeTimeFormatUnit\n}\n\nfunction relativeTimeFormat(\n fmt: Intl.RelativeTimeFormat,\n value: number,\n options: RelativeTimeOptions | undefined\n) {\n return fmt.format(value, options!.unit)\n}\n\n/**\n * Creates a relative time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function relativetime(\n options: false\n): Format<number | undefined>\n\n/**\n * Creates a locale-aware relative time formatter.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n options: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/**\n * Creates a relative time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function relativetime(\n fallback: number,\n options: false\n): Format<number | undefined, number>\n\n/**\n * Creates a locale-aware relative time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n fallback: number,\n options: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function relativetime(\n optionsOrFallback?: RelativeTimeOptions | false | number,\n maybeOptions?: RelativeTimeOptions | false\n) {\n return intlformat(\n Intl.RelativeTimeFormat,\n relativeTimeFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\nexport type Duration = Partial<Record<Intl.DurationFormatUnit, number>>\n\n/**\n * Creates a duration formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function duration(\n options: false\n): Format<Duration | undefined>\n\n/**\n * Creates a locale-aware duration formatter.\n * @param options - `Intl.DurationFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n options?: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/**\n * Creates a duration formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function duration(\n fallback: Duration,\n options: false\n): Format<Duration | undefined, Duration>\n\n/**\n * Creates a locale-aware duration formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DurationFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n fallback: Duration,\n options: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function duration(\n optionsOrFallback?: Intl.DurationFormatOptions | false | Duration,\n maybeOptions?: Intl.DurationFormatOptions | false\n) {\n return intlformat<Intl.DurationFormat, Duration, Intl.DurationFormatOptions>(\n Intl.DurationFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a list formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function list(\n options: false\n): Format<Iterable<string> | undefined>\n\n/**\n * Creates a locale-aware list formatter.\n * @param options - `Intl.ListFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n options?: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/**\n * Creates a list formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function list(\n fallback: Iterable<string>,\n options: false\n): Format<Iterable<string> | undefined, Iterable<string>>\n\n/**\n * Creates a locale-aware list formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.ListFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n fallback: Iterable<string>,\n options: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function list(\n optionsOrFallback?: Intl.ListFormatOptions | false | Iterable<string>,\n maybeOptions?: Intl.ListFormatOptions | false\n) {\n return intlformat<Intl.ListFormat, Iterable<string>, Intl.ListFormatOptions>(\n Intl.ListFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\n\nexport type RichChunks<T> = (string | T)[]\n\nexport type RichTag<T> = (chunks: RichChunks<T>, index: number) => T\n\nexport type RichTags<T> = Record<string, RichTag<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/**\n * Creates a rich-text formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks.\n */\nexport function rich<T>(\n fallback: string,\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param fallbackOrTags - Fallback message or tag handlers.\n * @param maybeTags - Tag handlers used when fallback is provided.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined> {\n let fallback: string | undefined\n let tags: RichTags<T>\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as RichTags<T>\n }\n\n return (_ctx: unknown, input?: string) => {\n const text = input ?? fallback\n\n if (text === undefined) {\n return text\n }\n\n return mapTags(text, tags)\n }\n}\n\nconst tagRegex = /<(\\/?)([A-Za-z][\\w.-]*)\\s*(\\/?)>/g\n\ninterface RichFrame<T> {\n tag: string\n chunks: RichChunks<T>\n}\n\n/**\n * Maps rich-text tags in a string to chunks using provided tag handlers.\n * Each handler call receives an unique index, usable as a key for framework nodes.\n * Self-closing tags are mapped with empty chunks.\n * Unknown or malformed tags are ignored as markup and only their text content is kept.\n * @param input - Rich-text input string.\n * @param tags - Tag handlers used to map known tags.\n * @returns Mapped chunks.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function mapTags<T>(\n input: string,\n tags: RichTags<T>\n): RichChunks<T> {\n const root: RichFrame<T> = {\n tag: '',\n chunks: []\n }\n const stack = [root]\n let lastIndex = 0\n let index = 0\n let match: RegExpExecArray | null\n\n // reset the shared regex state possibly clobbered by an interrupted outer call\n tagRegex.lastIndex = 0\n\n while (match = tagRegex.exec(input)) {\n const [, closing, tag, selfClosing] = match\n const current = stack[stack.length - 1]\n\n if (match.index > lastIndex) {\n current.chunks.push(input.slice(lastIndex, match.index))\n }\n\n lastIndex = tagRegex.lastIndex\n\n if (tag in tags) {\n if (closing) {\n if (current.tag === tag) {\n stack.pop()\n stack[stack.length - 1].chunks.push(\n tags[tag](current.chunks, index++)\n )\n }\n } else if (selfClosing) {\n current.chunks.push(tags[tag]([], index++))\n } else {\n stack.push({\n tag,\n chunks: []\n })\n }\n }\n\n // restore the shared regex state possibly clobbered by a nested call in a tag handler\n tagRegex.lastIndex = lastIndex\n }\n\n if (lastIndex < input.length) {\n stack[stack.length - 1].chunks.push(input.slice(lastIndex))\n }\n\n for (let i = stack.length - 1; i > 0; i--) {\n const frame = stack[i]\n\n stack[i - 1].chunks.push(...frame.chunks)\n }\n\n return root.chunks\n}\n","import type { Format } from './types.js'\nimport {\n type RichTags,\n rich\n} from './rich.js'\n\nexport type MarkupTag = (chunks: string) => string\n\nexport type MarkupTags = Record<string, MarkupTag>\n\n/**\n * Creates a markup formatter.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string or `undefined`.\n */\nexport function markup(\n tags: MarkupTags\n): Format<string | undefined, string | undefined>\n\n/**\n * Creates a markup formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string.\n */\nexport function markup(\n fallback: string,\n tags: MarkupTags\n): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function markup(\n fallbackOrTags: string | MarkupTags,\n maybeTags?: MarkupTags\n): Format<string | undefined, string | undefined> {\n let fallback: string | undefined\n let tags: MarkupTags\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as MarkupTags\n }\n\n const richTags: RichTags<string> = {}\n\n for (const [tag, format] of Object.entries(tags)) {\n richTags[tag] = chunks => format(chunks.join(''))\n }\n\n const richFormat = rich(fallback, richTags)\n\n return (ctx, input) => richFormat(ctx, input)?.join('')\n}\n","import type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n Format,\n FormatInput,\n FormatOutput\n} from './types.js'\n\nexport type Formatter<F extends AnyFormat> = (\n value: FormatInput<F>\n) => FormatOutput<F>\n\n/**\n * Creates a formatter value from another format.\n * @param type - Format used to format values later.\n * @returns Format that returns a value formatter bound to the current context.\n */\nexport function format<F extends AnyFormat>(\n type: F\n): Format<undefined, Formatter<F>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function format<F extends AnyFormat>(\n type: F\n) {\n return (ctx: FormatContext) => (value: FormatInput<F>) => type(ctx, value)\n}\n","import {\n type Signalish,\n $get,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n FnWithAnyParams,\n Format,\n FormatInput,\n FormatOutput,\n FnWithParams,\n ParamsOf,\n UnionToIntersection\n} from './types.js'\n\nexport type ReplacementValue = string | number | boolean | bigint | undefined\n\nexport type ParamsFormats = Record<string, Format<any, ReplacementValue>>\n\nexport type RequiredParamKeys<P extends ParamsFormats> = {\n [K in keyof P]: undefined extends FormatOutput<P[K]> ? K : never\n}[keyof P]\n\nexport type OptionalParamKeys<P extends ParamsFormats> = Exclude<keyof P, RequiredParamKeys<P>>\n\nexport type ParamsValues<P extends ParamsFormats> = {\n [K in RequiredParamKeys<P>]: Signalish<FormatInput<P[K]>>\n} & {\n [K in OptionalParamKeys<P>]?: Signalish<FormatInput<P[K]> | undefined>\n}\n\nexport type ParamsFn<P extends ParamsFormats> = FnWithParams<ParamsValues<P>>\n\ntype PreformatOutput = string | undefined | FnWithAnyParams\n\ntype ComposedParamsFn<P extends ParamsFormats, O> = FnWithParams<ParamsValues<P> & UnionToIntersection<ParamsOf<O>>>\n\ntype Replace = (ctx: FormatContext, text: string, params: Record<string, Signalish<ReplacementValue>>) => string\n\n/**\n * Creates a parameter interpolation formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<const P extends ParamsFormats>(\n params: P\n): Format<string | undefined, ParamsFn<P>>\n\n/**\n * Creates a parameter interpolation formatter that first applies another formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @param preformat - Formatter applied before replacing placeholders.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat?: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>> {\n let replaceAll: Replace | undefined\n\n for (let [key, format] of Object.entries(params)) {\n if (import.meta.env.DEV) {\n const originalFormat = format\n\n format = (ctx, value) => {\n const formatted = originalFormat(ctx, value)\n\n if (formatted === undefined) {\n console.warn(`[nano_kit/intl] Parameter \"${key}\" has no value: the message renders \"undefined\" in its place`)\n }\n\n return formatted\n }\n }\n\n const re = new RegExp(`{${key}}`, 'g')\n const replace: Replace = (ctx, text, params) => text.replace(re, () => format(ctx, $get(params[key])) as string)\n\n if (replaceAll) {\n const prevReplace = replaceAll\n\n replaceAll = (ctx, text, params) => replace(ctx, prevReplace(ctx, text, params), params)\n } else {\n replaceAll = replace\n }\n }\n\n return (ctx: FormatContext, input?: F) => {\n const preformatted = (preformat ? preformat(ctx, input) : input) as PreformatOutput\n\n if (isFunction(preformatted)) {\n return (params) => {\n const text = preformatted(params)\n\n if (text === undefined || !replaceAll) {\n return text\n }\n\n return replaceAll(ctx, text, params)\n }\n }\n\n if (preformatted === undefined || !replaceAll) {\n return () => preformatted\n }\n\n return params => replaceAll(ctx, preformatted, params)\n }\n}\n","import {\n type Signalish,\n $get,\n identity,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n FnWithParams,\n Format,\n FormatsInput,\n UnionToIntersection,\n ParamsOf\n} from './types.js'\n\ntype CaseParams<F> = F extends AnyFormat<infer O> ? ParamsOf<O> : {}\n\nexport type MatchParams<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = {\n [P in K]: Signalish<number | string>\n} & UnionToIntersection<CaseParams<B[keyof B]>>\n\nexport type ArgMatchFn = FnWithParams<Signalish<number | string>>\n\nexport type MatchFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = FnWithParams<MatchParams<K, B> | Signalish<number | string>>\n\nexport type CasesFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = ((\n ctx: FormatContext,\n input: FormatsInput<B> | undefined,\n resolvedCases: Record<string, string | undefined | MatchFn<K, B>>\n) => void) & {\n s: true\n}\n\ntype GetKey = (\n param: any,\n locale: string,\n cases: Record<string, unknown>\n) => string\n\n/**\n * Creates a reusable cases resolver for `match`.\n * @param cases - Case formatters keyed by possible resolved values.\n * @returns Resolver that formats all cases for the current context and translation input.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function cases<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n cases: B\n): CasesFn<K, B> {\n const entries = Object.entries(cases)\n const fn = ((ctx, input, resolvedCases) => {\n for (const [key, format] of entries) {\n resolvedCases[key] = format!(ctx, input?.[key]) as string | undefined | MatchFn<K, B>\n }\n }) as CasesFn<K, B>\n\n fn.s = true\n\n return fn\n}\n\n/**\n * Creates a case key resolver that falls back to a known case when the parameter value is missing.\n * @param key - Case key used when the parameter value does not exist in resolved cases.\n * @returns Resolver that keeps existing case keys and falls back to `key` for unknown values.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function other(key: string): GetKey {\n return (param: string, _, cases) => (param in cases ? param : key)\n}\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n getKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n cases?: CasesFn<K, B>,\n getKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n casesOrGetKey?: CasesFn<K, B> | GetKey & {\n s?: never\n },\n maybeGetKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n> {\n const valuePattern = new RegExp(`{${param}}`, 'g')\n let cases: CasesFn<K, B> | undefined\n let getKey: GetKey\n\n if (casesOrGetKey?.s) {\n cases = casesOrGetKey\n getKey = maybeGetKey ?? identity\n } else {\n getKey = maybeGetKey ?? casesOrGetKey ?? identity\n }\n\n return (ctx, input: FormatsInput<B> | string | undefined) => {\n const locale = ctx.$locale()\n const isString = typeof input === 'string'\n // A string never reaches the lookups below, so it is stored as is.\n let resolvedCases = (input ?? {}) as Record<string, string | undefined | MatchFn<K, B>>\n\n if (cases && !isString) {\n resolvedCases = {\n ...resolvedCases\n }\n\n cases(ctx, input, resolvedCases)\n }\n\n return (params) => {\n const value = $get(typeof params === 'object' ? params[param] : params)\n const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)]\n const message = isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase\n\n return message?.replace(valuePattern, value as string)\n }\n }\n}\n","import { isFunction } from '@nano_kit/store'\nimport { memo } from '../utils.js'\nimport type {\n AnyFormat,\n Format,\n FormatsInput\n} from './types.js'\nimport {\n type MatchFn,\n type CasesFn,\n match,\n cases\n} from './match.js'\n\nexport type PluralForm = Intl.LDMLPluralRule\n\nexport type PluralKey = PluralForm | `${number}`\n\nexport { cases as forms }\n\n/**\n * Creates a plural formatter.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a plural formatter with `Intl.PluralRules` options.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param options - `Intl.PluralRules` options.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n options: Intl.PluralRulesOptions,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n optionsOrForms?: Intl.PluralRulesOptions | CasesFn<K, B>,\n maybeForms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n> {\n let options: Intl.PluralRulesOptions | undefined\n let forms: CasesFn<K, B> | undefined\n\n if (isFunction(optionsOrForms)) {\n forms = optionsOrForms\n } else {\n options = optionsOrForms\n forms = maybeForms\n }\n\n const rules = memo((locale: string) => new Intl.PluralRules(locale, options))\n\n return match(param, forms, (count, locale, forms) => {\n if (count in forms) {\n return count as string\n }\n\n let form = rules(locale).select(count as number)\n\n if (!(form in forms)) {\n form = 'other' in forms ? 'other' : 'many'\n }\n\n return form\n })\n}\n","import {\n type Accessor,\n type ReadableSignal,\n type EmptyValue,\n type AnySignal,\n isFunction,\n signal,\n computed,\n untracked\n} from '@nano_kit/store'\nimport type {\n TranslationData,\n Loader,\n MessagesScheme,\n Messages,\n AnyNamespaceTranslationData,\n AnyTranslationData,\n MessagesAccessor\n} from './types.js'\n\ntype AnySignalRecord = AnySignal & Record<string, unknown>\n\nconst proxyHandler: ProxyHandler<AnySignalRecord> = {\n /* oxlint-disable */\n get($signal, key: string, receiver) {\n if (!(key in $signal)) {\n if (key[0] === '$') {\n const prop = key.slice(1)\n\n return $signal[key] = computed(() => $signal()[prop])\n } else if (typeof key === 'string') {\n const $prop = receiver[`$${key}`]\n\n return $signal[key] = (params: unknown) => computed(\n () => $prop()(params)\n )\n }\n }\n\n return $signal[key]\n }\n /* oxlint-enable */\n}\n\n/**\n * Runtime context used by message formats.\n *\n * It owns the active locale, loads translation data, and exposes messages helpers\n * that bind a messages scheme to the current namespace data.\n * @template T - Translation data shape keyed by namespace name.\n */\nexport class IntlContext<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n> {\n readonly #loader: Loader<T>\n /**\n * Active locale accessor.\n */\n readonly $locale: Accessor<L>\n /**\n * Loading state for full-data loaders.\n */\n readonly $loading: ReadableSignal<boolean>\n /**\n * Loading error for full-data loaders.\n */\n readonly $error: ReadableSignal<unknown>\n\n /**\n * Creates an internationalization context.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n */\n constructor(\n $locale: Accessor<L>,\n loader: Loader<T>\n ) {\n this.$locale = $locale\n this.#loader = loader\n\n if (isFunction(loader)) {\n this.$loading = signal(false)\n this.$error = signal(undefined)\n } else {\n [, this.$error, this.$loading] = loader\n }\n }\n\n /**\n * Creates reactive messages for a single namespace.\n * @param namespace - Namespace key to read from loaded translation data.\n * @param scheme - Messages scheme compatible with the namespace data shape.\n * @returns A tuple with formatted messages, pending state, and loading error.\n */\n messages<K extends keyof T, S extends MessagesScheme<T[K]> = {}>(\n namespace: K,\n scheme: S = {} as S\n ) {\n const entries = Object.entries(scheme)\n const loaderResult = this.#loader\n let $data: ReadableSignal<T[K] | EmptyValue>\n let $error: ReadableSignal<unknown>\n let $pending: ReadableSignal<boolean>\n\n if (isFunction(loaderResult)) {\n [$data, $error, $pending] = loaderResult(namespace, entries)\n } else {\n let $translations\n\n [$translations, $error, $pending] = loaderResult\n\n $data = computed(() => $translations()?.[namespace])\n }\n\n const $messages = computed(() => {\n const data: AnyNamespaceTranslationData | EmptyValue = $data()\n let result: Record<string, unknown> = data ?? {}\n\n if (entries.length > 0) {\n result = {\n ...result\n }\n\n for (const [key, format] of entries) {\n if (import.meta.env.DEV && data && !(key in data)) {\n console.warn(`[nano_kit/intl] Missing message \"${String(namespace)}.${key}\" for locale \"${untracked(this.$locale)}\"`)\n }\n\n result[key] = format(this, data?.[key])\n }\n }\n\n return result as Messages<T[K], S>\n })\n\n return [\n new Proxy($messages as AnySignalRecord, proxyHandler) as MessagesAccessor<T[K], S>,\n $pending,\n $error\n ] as const\n }\n}\n","import type { UnionToIntersection } from './types.js'\n\ntype Split<\n T extends string,\n S extends string = '.'\n> = string extends T\n ? [T]\n : T extends `${infer H}${S}${infer R}`\n ? [H, ...Split<R, S>]\n : [T]\n\ntype TupleOf<N extends number, T extends unknown[] = []> = T['length'] extends N\n ? T\n : TupleOf<N, [...T, unknown]>\n\ntype Add<A extends unknown[], B extends unknown[]> = [...A, ...B]\n\ntype IsAtDepth<\n L extends unknown[],\n D extends number\n> = L extends [...TupleOf<D>, ...unknown[]] ? true : false\n\ntype Simplify<T> = T extends (...args: unknown[]) => unknown\n ? T\n : T extends object\n ? {\n [K in keyof T]: Simplify<T[K]>\n }\n : T\n\ntype PathObject<\n P extends readonly string[],\n V\n> = P extends readonly [infer H extends string, ...infer R extends string[]]\n ? {\n [K in H]: R extends []\n ? V\n : PathObject<R, V>\n }\n : V\n\ninterface DeflatOpenTree<V> {\n [key: string]: V | DeflatOpenTree<V>\n}\n\ntype DeflatOpenRecord<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? DeflatOpenTree<DeflatValue<T[string], D, [...L, unknown]>>\n : Record<string, DeflatValue<T[string], D, [...L, unknown]>>\n\ntype DeflatValue<\n T,\n D extends number,\n L extends unknown[]\n> = T extends Record<string, unknown>\n ? string extends keyof T\n ? DeflatOpenRecord<T, D, L>\n : DeflatAt<T, D, L>\n : T\n\ntype DeflatEntry<\n K extends string,\n V,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? PathObject<Split<K>, DeflatValue<V, D, Add<L, TupleOf<Split<K>['length']>>>>\n : {\n [P in K]: DeflatValue<V, D, [...L, unknown]>\n }\n\ntype DeflatAt<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = Simplify<UnionToIntersection<{\n [K in keyof T & string]: DeflatEntry<K, T[K], D, L>\n}[keyof T & string]>>\n\nexport type Deflat<\n T extends Record<string, unknown>,\n D extends number = 0\n> = string extends keyof T\n ? DeflatOpenRecord<T, D, []>\n : DeflatAt<T, D, []>\n\nexport type DeflatFromDepth<T extends Record<string, unknown>> = Simplify<{\n [K in keyof T]: DeflatValue<T[K], 0, []>\n}>\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null\n && typeof value === 'object'\n && Object.getPrototypeOf(value) === Object.prototype\n}\n\nfunction ensure(\n target: Record<string, unknown>,\n path: string[],\n offset = 0\n) {\n let container = target\n\n for (let i = 0, len = path.length - offset, key; i < len; i++) {\n key = path[i]\n\n if (!isObject(container[key])) {\n container[key] = {}\n }\n\n container = container[key] as Record<string, unknown>\n }\n\n return container\n}\n\nfunction set(\n target: Record<string, unknown>,\n path: string[],\n value: unknown\n) {\n const key = path[path.length - 1]\n const container = ensure(target, path, 1)\n\n container[key] = value\n}\n\nfunction assign(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n depth: number,\n level: number\n) {\n for (const [key, value] of Object.entries(source)) {\n const path = level >= depth ? key.split('.') : [key]\n\n if (isObject(value)) {\n assign(\n ensure(target, path),\n value,\n depth,\n level + path.length\n )\n } else {\n set(target, path, value)\n }\n }\n}\n\n/**\n * Deflates dotted object keys into nested objects.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T\n): Deflat<T>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<\n const T extends Record<string, unknown>,\n const D extends number\n>(\n input: T,\n depth: D\n): Deflat<T, D>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T,\n depth: number\n): DeflatFromDepth<T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function deflat(\n input: Record<string, unknown>,\n depth = 0\n) {\n const output: Record<string, unknown> = {}\n\n assign(output, input, depth, 0)\n\n return output\n}\n","import type { Accessor } from '@nano_kit/store'\nimport type {\n Bound,\n AnyTranslationData,\n Loader,\n TranslationData\n} from './types.js'\nimport { IntlContext } from './context.js'\n\n/**\n * Creates an internationalization context with bound helpers.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n * @returns Internationalization context with `messages` safe to destructure.\n */\nexport function intl<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n>(\n $locale: Accessor<L>,\n loader: Loader<T>\n): Bound<IntlContext<L, T>, 'messages'> {\n const ctx = new IntlContext($locale, loader)\n\n ctx.messages = ctx.messages.bind(ctx)\n\n return ctx\n}\n","import {\n type Accessor,\n computed\n} from '@nano_kit/store'\n\nexport const rtlLocales = new Set([\n 'ar', // Arabic\n 'arc', // Aramaic\n 'dv', // Divehi\n 'fa', // Persian\n 'ha', // Hausa\n 'he', // Hebrew\n 'khw', // Khowar\n 'ks', // Kashmiri\n 'ku', // Kurdish\n 'ps', // Pashto\n 'ur', // Urdu\n 'yi' // Yiddish\n])\n\n/**\n * Resolves text direction for a locale.\n * @param locale - BCP 47 locale code.\n * @returns `rtl` for right-to-left languages, otherwise `ltr`.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function getDirection(locale: string) {\n const lang = new Intl.Locale(locale).language\n\n return rtlLocales.has(lang) ? 'rtl' : 'ltr'\n}\n\n/**\n * Creates a computed text direction from a locale accessor.\n * @param $locale - Active locale accessor.\n * @returns Signal with `rtl` or `ltr` direction.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function direction<T extends string>($locale: Accessor<T>) {\n return computed(() => getDirection($locale()))\n}\n"],"mappings":";;;AAgBA,SAAgB,IAAO,UAAc;CACnC,QAAQ,MAAe,UAAc,SAAS;AAChD;;;;ACDA,SAAgB,KAAK,UAA+C;CAClE,OAAO,oBAAI,QAAQ;AACrB;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,OAAO,KAAK,KAAK,CAAC,EAAE,kBAAkB,IAAI,QAAQ,CAAC;AAC5E;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,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AAsB;CAChE,OAAO,eAAe,6BAAa,QAAQ,CAAC,CAAC;AAC/C"}
|
|
@@ -193,9 +193,9 @@ function format(type) {
|
|
|
193
193
|
/* @__NO_SIDE_EFFECTS__ */
|
|
194
194
|
function params(params, preformat) {
|
|
195
195
|
let replaceAll;
|
|
196
|
-
for (
|
|
196
|
+
for (let [key, format] of Object.entries(params)) {
|
|
197
197
|
const re = new RegExp(`{${key}}`, "g");
|
|
198
|
-
const replace = (ctx, text, params) => text.replace(re, format(ctx, $get(params[key])));
|
|
198
|
+
const replace = (ctx, text, params) => text.replace(re, () => format(ctx, $get(params[key])));
|
|
199
199
|
if (replaceAll) {
|
|
200
200
|
const prevReplace = replaceAll;
|
|
201
201
|
replaceAll = (ctx, text, params) => replace(ctx, prevReplace(ctx, text, params), params);
|
|
@@ -255,15 +255,15 @@ function match(param, casesOrGetKey, maybeGetKey) {
|
|
|
255
255
|
} else getKey = maybeGetKey ?? casesOrGetKey ?? identity;
|
|
256
256
|
return (ctx, input) => {
|
|
257
257
|
const locale = ctx.$locale();
|
|
258
|
+
const isString = typeof input === "string";
|
|
258
259
|
let resolvedCases = input ?? {};
|
|
259
|
-
if (cases) {
|
|
260
|
+
if (cases && !isString) {
|
|
260
261
|
resolvedCases = { ...resolvedCases };
|
|
261
262
|
cases(ctx, input, resolvedCases);
|
|
262
263
|
}
|
|
263
264
|
return (params) => {
|
|
264
265
|
const value = $get(typeof params === "object" ? params[param] : params);
|
|
265
|
-
const
|
|
266
|
-
const resolvedCase = resolvedCases[key];
|
|
266
|
+
const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)];
|
|
267
267
|
return (isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase)?.replace(valuePattern, value);
|
|
268
268
|
};
|
|
269
269
|
};
|
|
@@ -452,4 +452,4 @@ function direction($locale) {
|
|
|
452
452
|
//#endregion
|
|
453
453
|
export { IntlContext, capitalize, cases, cases as forms, datetime, deflat, direction, duration, format, getDirection, intl, list, lowercase, mapTags, markup, match, number, other, params, plural, range, raw, relativetime, rich, rtlLocales, text, uppercase };
|
|
454
454
|
|
|
455
|
-
//# sourceMappingURL=index.js.map
|
|
455
|
+
//# sourceMappingURL=index.production.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.production.js","names":["#loader"],"sources":["../src/format/raw.ts","../src/format/text.ts","../src/utils.ts","../src/format/intlformat.ts","../src/format/number.ts","../src/format/datetime.ts","../src/format/range.ts","../src/format/relativetime.ts","../src/format/duration.ts","../src/format/list.ts","../src/format/rich.ts","../src/format/markup.ts","../src/format/format.ts","../src/format/params.ts","../src/format/match.ts","../src/format/plural.ts","../src/context.ts","../src/deflat.ts","../src/intl.ts","../src/direction.ts"],"sourcesContent":["import type { Format } from './types.js'\n\n/**\n * Creates a pass-through formatter.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function raw<T>(): Format<T | undefined>\n\n/**\n * Creates a pass-through formatter with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function raw<T>(fallback: T): Format<T | undefined, T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function raw<T>(fallback?: T) {\n return (_ctx: unknown, input?: T) => input ?? fallback\n}\n","import type { Format } from './types.js'\nimport { raw } from './raw.js'\n\n/**\n * Creates a string formatter.\n * @returns Formatter that returns the input string or `undefined`.\n */\nexport function text(): Format<string | undefined>\n\n/**\n * Creates a string formatter with a fallback value.\n * @param fallback - String returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input string or fallback.\n */\nexport function text(fallback: string): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function text(fallback?: string): Format<string | undefined> {\n return raw(fallback)\n}\n\n/**\n * Creates a formatter that uppercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with uppercased output.\n */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function uppercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleUpperCase(ctx.$locale())\n}\n\n/**\n * Creates a formatter that lowercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with lowercased output.\n */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function lowercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleLowerCase(ctx.$locale())\n}\n\nfunction toCapitalize(message: string | undefined, locale: string) {\n return message === undefined\n ? message\n : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1)\n}\n\n/**\n * Creates a formatter that capitalizes another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with the first character uppercased.\n */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function capitalize<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => toCapitalize(format(ctx, input), ctx.$locale())\n}\n","export function memo<T, K>(fn: (key: K) => T): (key: K) => T {\n let key: K\n let value: T\n\n return (newKey) => {\n if (newKey !== key) {\n value = fn(newKey)\n key = newKey\n }\n\n return value\n }\n}\n","import type { FormatContext } from '../types.js'\nimport { memo } from '../utils.js'\nimport type { IntlFormat } from './types.js'\nimport { raw } from './raw.js'\n\nexport type IntlFormatConstructor<F, O> = new (\n locale: string,\n options?: O\n) => F\n\nexport type IntlFormatFn<F extends IntlFormat<unknown>, I, O> = (\n fmt: F,\n value: I,\n options: O | undefined\n) => string\n\nexport function defaultFormat<F extends IntlFormat<I>, I>(\n fmt: F,\n value: I\n) {\n return fmt.format(value)\n}\n\nexport function intlformat<\n F extends IntlFormat<unknown>,\n I,\n O\n>(\n IntlFormat: IntlFormatConstructor<NoInfer<F>, O>,\n format: IntlFormatFn<F, I, O>,\n optionsOrFallback?: O | false | I,\n maybeOptions?: O | false\n) {\n let fallback: I | undefined\n let options: O | false | undefined\n\n if (maybeOptions !== undefined) {\n fallback = optionsOrFallback as I\n options = maybeOptions\n } else {\n options = optionsOrFallback as O | false | undefined\n }\n\n const rawFormat = raw(fallback)\n\n if (options === false) {\n return rawFormat\n }\n\n const fmt = memo((locale: string) => new IntlFormat(locale, options))\n\n return (ctx: FormatContext, input?: I) => {\n const value = rawFormat(ctx, input)\n\n if (value === undefined) {\n return value\n }\n\n return format(fmt(ctx.$locale()), value, options)\n }\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a number formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function number(\n options: false\n): Format<number | bigint | string | undefined>\n\n/**\n * Creates a locale-aware number formatter.\n * @param options - `Intl.NumberFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n options?: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a number formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function number(\n fallback: number | bigint | string,\n options: false\n): Format<number | bigint | string | undefined, number | bigint | string>\n\n/**\n * Creates a locale-aware number formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.NumberFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n fallback: number | bigint | string,\n options: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware number formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.NumberFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.NumberFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n optionsOrFallback: Intl.NumberFormatOptions | false | number | bigint | string | undefined,\n maybeOptions: Intl.NumberFormatOptions | false | undefined,\n format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>\n): Format<number | bigint | string | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function number(\n optionsOrFallback?: Intl.NumberFormatOptions | false | number | bigint | string,\n maybeOptions?: Intl.NumberFormatOptions | false,\n format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions> = defaultFormat\n) {\n return intlformat<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>(\n Intl.NumberFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n intlformat\n} from './intlformat.js'\n\nfunction datetimeFormat(\n fmt: Intl.DateTimeFormat,\n value: Date | number | string\n) {\n return fmt.format(typeof value === 'string' ? new Date(value) : value)\n}\n\n/**\n * Creates a date/time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function datetime(\n options: false\n): Format<Date | number | string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter.\n * @param options - `Intl.DateTimeFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n options?: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a date/time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function datetime(\n fallback: Date | number | string,\n options: false\n): Format<Date | number | string | undefined, Date | number | string>\n\n/**\n * Creates a locale-aware date/time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DateTimeFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n fallback: Date | number | string,\n options: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.DateTimeFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.DateTimeFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime<I = Date | number | string>(\n optionsOrFallback: Intl.DateTimeFormatOptions | false | I | undefined,\n maybeOptions: Intl.DateTimeFormatOptions | false | undefined,\n format: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>\n): Format<I | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function datetime(\n optionsOrFallback?: Intl.DateTimeFormatOptions | false | Date | number | string,\n maybeOptions?: Intl.DateTimeFormatOptions | false,\n format: IntlFormatFn<Intl.DateTimeFormat, Date | number | string, Intl.DateTimeFormatOptions> = datetimeFormat\n) {\n return intlformat(\n Intl.DateTimeFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { IntlFormatFn } from './intlformat.js'\nimport type {\n Format,\n IntlFormatRange\n} from './types.js'\n\ntype RangeInput<I> = readonly [from: I, to: I]\n\ntype RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (\n optionsOrFallback: O | false | I | undefined,\n maybeOptions: O | false | undefined,\n format: IntlFormatFn<F, I, O>\n) => Format<I | undefined, R | undefined>\n\nfunction rangeFormat(\n fmt: IntlFormatRange<unknown>,\n [from, to]: RangeInput<unknown>\n) {\n return fmt.formatRange(from, to)\n}\n\n/**\n * Creates a range formatter in raw mode.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Pass `false` to return the input range without formatting.\n * @returns Formatter that returns the input range or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options: false\n): Format<RangeInput<I> | undefined>\n\n/**\n * Creates a locale-aware range formatter.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Formatter options.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options?: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/**\n * Creates a range formatter in raw mode with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input range or fallback without formatting.\n * @returns Formatter that returns the input range or fallback.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options: false\n): Format<RangeInput<I> | undefined, RangeInput<I>>\n\n/**\n * Creates a locale-aware range formatter with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range used when the input is `undefined` or `null`.\n * @param options - Formatter options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n optionsOrFallback?: O | false | RangeInput<I>,\n maybeOptions?: O | false\n) {\n return format(\n optionsOrFallback as I,\n maybeOptions,\n rangeFormat as IntlFormatFn<F, I, O>\n )\n}\n","import type { Format } from './types.js'\nimport { intlformat } from './intlformat.js'\n\nexport type RelativeTimeOptions = Intl.RelativeTimeFormatOptions & {\n unit: Intl.RelativeTimeFormatUnit\n}\n\nfunction relativeTimeFormat(\n fmt: Intl.RelativeTimeFormat,\n value: number,\n options: RelativeTimeOptions | undefined\n) {\n return fmt.format(value, options!.unit)\n}\n\n/**\n * Creates a relative time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function relativetime(\n options: false\n): Format<number | undefined>\n\n/**\n * Creates a locale-aware relative time formatter.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n options: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/**\n * Creates a relative time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function relativetime(\n fallback: number,\n options: false\n): Format<number | undefined, number>\n\n/**\n * Creates a locale-aware relative time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n fallback: number,\n options: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function relativetime(\n optionsOrFallback?: RelativeTimeOptions | false | number,\n maybeOptions?: RelativeTimeOptions | false\n) {\n return intlformat(\n Intl.RelativeTimeFormat,\n relativeTimeFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\nexport type Duration = Partial<Record<Intl.DurationFormatUnit, number>>\n\n/**\n * Creates a duration formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function duration(\n options: false\n): Format<Duration | undefined>\n\n/**\n * Creates a locale-aware duration formatter.\n * @param options - `Intl.DurationFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n options?: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/**\n * Creates a duration formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function duration(\n fallback: Duration,\n options: false\n): Format<Duration | undefined, Duration>\n\n/**\n * Creates a locale-aware duration formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DurationFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n fallback: Duration,\n options: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function duration(\n optionsOrFallback?: Intl.DurationFormatOptions | false | Duration,\n maybeOptions?: Intl.DurationFormatOptions | false\n) {\n return intlformat<Intl.DurationFormat, Duration, Intl.DurationFormatOptions>(\n Intl.DurationFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a list formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function list(\n options: false\n): Format<Iterable<string> | undefined>\n\n/**\n * Creates a locale-aware list formatter.\n * @param options - `Intl.ListFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n options?: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/**\n * Creates a list formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function list(\n fallback: Iterable<string>,\n options: false\n): Format<Iterable<string> | undefined, Iterable<string>>\n\n/**\n * Creates a locale-aware list formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.ListFormat` options, or `{}` for the defaults.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n fallback: Iterable<string>,\n options: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function list(\n optionsOrFallback?: Intl.ListFormatOptions | false | Iterable<string>,\n maybeOptions?: Intl.ListFormatOptions | false\n) {\n return intlformat<Intl.ListFormat, Iterable<string>, Intl.ListFormatOptions>(\n Intl.ListFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\n\nexport type RichChunks<T> = (string | T)[]\n\nexport type RichTag<T> = (chunks: RichChunks<T>, index: number) => T\n\nexport type RichTags<T> = Record<string, RichTag<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/**\n * Creates a rich-text formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks.\n */\nexport function rich<T>(\n fallback: string,\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param fallbackOrTags - Fallback message or tag handlers.\n * @param maybeTags - Tag handlers used when fallback is provided.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined> {\n let fallback: string | undefined\n let tags: RichTags<T>\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as RichTags<T>\n }\n\n return (_ctx: unknown, input?: string) => {\n const text = input ?? fallback\n\n if (text === undefined) {\n return text\n }\n\n return mapTags(text, tags)\n }\n}\n\nconst tagRegex = /<(\\/?)([A-Za-z][\\w.-]*)\\s*(\\/?)>/g\n\ninterface RichFrame<T> {\n tag: string\n chunks: RichChunks<T>\n}\n\n/**\n * Maps rich-text tags in a string to chunks using provided tag handlers.\n * Each handler call receives an unique index, usable as a key for framework nodes.\n * Self-closing tags are mapped with empty chunks.\n * Unknown or malformed tags are ignored as markup and only their text content is kept.\n * @param input - Rich-text input string.\n * @param tags - Tag handlers used to map known tags.\n * @returns Mapped chunks.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function mapTags<T>(\n input: string,\n tags: RichTags<T>\n): RichChunks<T> {\n const root: RichFrame<T> = {\n tag: '',\n chunks: []\n }\n const stack = [root]\n let lastIndex = 0\n let index = 0\n let match: RegExpExecArray | null\n\n // reset the shared regex state possibly clobbered by an interrupted outer call\n tagRegex.lastIndex = 0\n\n while (match = tagRegex.exec(input)) {\n const [, closing, tag, selfClosing] = match\n const current = stack[stack.length - 1]\n\n if (match.index > lastIndex) {\n current.chunks.push(input.slice(lastIndex, match.index))\n }\n\n lastIndex = tagRegex.lastIndex\n\n if (tag in tags) {\n if (closing) {\n if (current.tag === tag) {\n stack.pop()\n stack[stack.length - 1].chunks.push(\n tags[tag](current.chunks, index++)\n )\n }\n } else if (selfClosing) {\n current.chunks.push(tags[tag]([], index++))\n } else {\n stack.push({\n tag,\n chunks: []\n })\n }\n }\n\n // restore the shared regex state possibly clobbered by a nested call in a tag handler\n tagRegex.lastIndex = lastIndex\n }\n\n if (lastIndex < input.length) {\n stack[stack.length - 1].chunks.push(input.slice(lastIndex))\n }\n\n for (let i = stack.length - 1; i > 0; i--) {\n const frame = stack[i]\n\n stack[i - 1].chunks.push(...frame.chunks)\n }\n\n return root.chunks\n}\n","import type { Format } from './types.js'\nimport {\n type RichTags,\n rich\n} from './rich.js'\n\nexport type MarkupTag = (chunks: string) => string\n\nexport type MarkupTags = Record<string, MarkupTag>\n\n/**\n * Creates a markup formatter.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string or `undefined`.\n */\nexport function markup(\n tags: MarkupTags\n): Format<string | undefined, string | undefined>\n\n/**\n * Creates a markup formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string.\n */\nexport function markup(\n fallback: string,\n tags: MarkupTags\n): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function markup(\n fallbackOrTags: string | MarkupTags,\n maybeTags?: MarkupTags\n): Format<string | undefined, string | undefined> {\n let fallback: string | undefined\n let tags: MarkupTags\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as MarkupTags\n }\n\n const richTags: RichTags<string> = {}\n\n for (const [tag, format] of Object.entries(tags)) {\n richTags[tag] = chunks => format(chunks.join(''))\n }\n\n const richFormat = rich(fallback, richTags)\n\n return (ctx, input) => richFormat(ctx, input)?.join('')\n}\n","import type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n Format,\n FormatInput,\n FormatOutput\n} from './types.js'\n\nexport type Formatter<F extends AnyFormat> = (\n value: FormatInput<F>\n) => FormatOutput<F>\n\n/**\n * Creates a formatter value from another format.\n * @param type - Format used to format values later.\n * @returns Format that returns a value formatter bound to the current context.\n */\nexport function format<F extends AnyFormat>(\n type: F\n): Format<undefined, Formatter<F>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function format<F extends AnyFormat>(\n type: F\n) {\n return (ctx: FormatContext) => (value: FormatInput<F>) => type(ctx, value)\n}\n","import {\n type Signalish,\n $get,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n FnWithAnyParams,\n Format,\n FormatInput,\n FormatOutput,\n FnWithParams,\n ParamsOf,\n UnionToIntersection\n} from './types.js'\n\nexport type ReplacementValue = string | number | boolean | bigint | undefined\n\nexport type ParamsFormats = Record<string, Format<any, ReplacementValue>>\n\nexport type RequiredParamKeys<P extends ParamsFormats> = {\n [K in keyof P]: undefined extends FormatOutput<P[K]> ? K : never\n}[keyof P]\n\nexport type OptionalParamKeys<P extends ParamsFormats> = Exclude<keyof P, RequiredParamKeys<P>>\n\nexport type ParamsValues<P extends ParamsFormats> = {\n [K in RequiredParamKeys<P>]: Signalish<FormatInput<P[K]>>\n} & {\n [K in OptionalParamKeys<P>]?: Signalish<FormatInput<P[K]> | undefined>\n}\n\nexport type ParamsFn<P extends ParamsFormats> = FnWithParams<ParamsValues<P>>\n\ntype PreformatOutput = string | undefined | FnWithAnyParams\n\ntype ComposedParamsFn<P extends ParamsFormats, O> = FnWithParams<ParamsValues<P> & UnionToIntersection<ParamsOf<O>>>\n\ntype Replace = (ctx: FormatContext, text: string, params: Record<string, Signalish<ReplacementValue>>) => string\n\n/**\n * Creates a parameter interpolation formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<const P extends ParamsFormats>(\n params: P\n): Format<string | undefined, ParamsFn<P>>\n\n/**\n * Creates a parameter interpolation formatter that first applies another formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @param preformat - Formatter applied before replacing placeholders.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat?: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>> {\n let replaceAll: Replace | undefined\n\n for (let [key, format] of Object.entries(params)) {\n if (import.meta.env.DEV) {\n const originalFormat = format\n\n format = (ctx, value) => {\n const formatted = originalFormat(ctx, value)\n\n if (formatted === undefined) {\n console.warn(`[nano_kit/intl] Parameter \"${key}\" has no value: the message renders \"undefined\" in its place`)\n }\n\n return formatted\n }\n }\n\n const re = new RegExp(`{${key}}`, 'g')\n const replace: Replace = (ctx, text, params) => text.replace(re, () => format(ctx, $get(params[key])) as string)\n\n if (replaceAll) {\n const prevReplace = replaceAll\n\n replaceAll = (ctx, text, params) => replace(ctx, prevReplace(ctx, text, params), params)\n } else {\n replaceAll = replace\n }\n }\n\n return (ctx: FormatContext, input?: F) => {\n const preformatted = (preformat ? preformat(ctx, input) : input) as PreformatOutput\n\n if (isFunction(preformatted)) {\n return (params) => {\n const text = preformatted(params)\n\n if (text === undefined || !replaceAll) {\n return text\n }\n\n return replaceAll(ctx, text, params)\n }\n }\n\n if (preformatted === undefined || !replaceAll) {\n return () => preformatted\n }\n\n return params => replaceAll(ctx, preformatted, params)\n }\n}\n","import {\n type Signalish,\n $get,\n identity,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n FnWithParams,\n Format,\n FormatsInput,\n UnionToIntersection,\n ParamsOf\n} from './types.js'\n\ntype CaseParams<F> = F extends AnyFormat<infer O> ? ParamsOf<O> : {}\n\nexport type MatchParams<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = {\n [P in K]: Signalish<number | string>\n} & UnionToIntersection<CaseParams<B[keyof B]>>\n\nexport type ArgMatchFn = FnWithParams<Signalish<number | string>>\n\nexport type MatchFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = FnWithParams<MatchParams<K, B> | Signalish<number | string>>\n\nexport type CasesFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = ((\n ctx: FormatContext,\n input: FormatsInput<B> | undefined,\n resolvedCases: Record<string, string | undefined | MatchFn<K, B>>\n) => void) & {\n s: true\n}\n\ntype GetKey = (\n param: any,\n locale: string,\n cases: Record<string, unknown>\n) => string\n\n/**\n * Creates a reusable cases resolver for `match`.\n * @param cases - Case formatters keyed by possible resolved values.\n * @returns Resolver that formats all cases for the current context and translation input.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function cases<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n cases: B\n): CasesFn<K, B> {\n const entries = Object.entries(cases)\n const fn = ((ctx, input, resolvedCases) => {\n for (const [key, format] of entries) {\n resolvedCases[key] = format!(ctx, input?.[key]) as string | undefined | MatchFn<K, B>\n }\n }) as CasesFn<K, B>\n\n fn.s = true\n\n return fn\n}\n\n/**\n * Creates a case key resolver that falls back to a known case when the parameter value is missing.\n * @param key - Case key used when the parameter value does not exist in resolved cases.\n * @returns Resolver that keeps existing case keys and falls back to `key` for unknown values.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function other(key: string): GetKey {\n return (param: string, _, cases) => (param in cases ? param : key)\n}\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n getKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n cases?: CasesFn<K, B>,\n getKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n casesOrGetKey?: CasesFn<K, B> | GetKey & {\n s?: never\n },\n maybeGetKey?: GetKey\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n> {\n const valuePattern = new RegExp(`{${param}}`, 'g')\n let cases: CasesFn<K, B> | undefined\n let getKey: GetKey\n\n if (casesOrGetKey?.s) {\n cases = casesOrGetKey\n getKey = maybeGetKey ?? identity\n } else {\n getKey = maybeGetKey ?? casesOrGetKey ?? identity\n }\n\n return (ctx, input: FormatsInput<B> | string | undefined) => {\n const locale = ctx.$locale()\n const isString = typeof input === 'string'\n // A string never reaches the lookups below, so it is stored as is.\n let resolvedCases = (input ?? {}) as Record<string, string | undefined | MatchFn<K, B>>\n\n if (cases && !isString) {\n resolvedCases = {\n ...resolvedCases\n }\n\n cases(ctx, input, resolvedCases)\n }\n\n return (params) => {\n const value = $get(typeof params === 'object' ? params[param] : params)\n const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)]\n const message = isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase\n\n return message?.replace(valuePattern, value as string)\n }\n }\n}\n","import { isFunction } from '@nano_kit/store'\nimport { memo } from '../utils.js'\nimport type {\n AnyFormat,\n Format,\n FormatsInput\n} from './types.js'\nimport {\n type MatchFn,\n type CasesFn,\n match,\n cases\n} from './match.js'\n\nexport type PluralForm = Intl.LDMLPluralRule\n\nexport type PluralKey = PluralForm | `${number}`\n\nexport { cases as forms }\n\n/**\n * Creates a plural formatter.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/**\n * Creates a plural formatter with `Intl.PluralRules` options.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param options - `Intl.PluralRules` options.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n options: Intl.PluralRulesOptions,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n optionsOrForms?: Intl.PluralRulesOptions | CasesFn<K, B>,\n maybeForms?: CasesFn<K, B>\n): Format<\n FormatsInput<B> | string,\n MatchFn<K, B>\n> {\n let options: Intl.PluralRulesOptions | undefined\n let forms: CasesFn<K, B> | undefined\n\n if (isFunction(optionsOrForms)) {\n forms = optionsOrForms\n } else {\n options = optionsOrForms\n forms = maybeForms\n }\n\n const rules = memo((locale: string) => new Intl.PluralRules(locale, options))\n\n return match(param, forms, (count, locale, forms) => {\n if (count in forms) {\n return count as string\n }\n\n let form = rules(locale).select(count as number)\n\n if (!(form in forms)) {\n form = 'other' in forms ? 'other' : 'many'\n }\n\n return form\n })\n}\n","import {\n type Accessor,\n type ReadableSignal,\n type EmptyValue,\n type AnySignal,\n isFunction,\n signal,\n computed,\n untracked\n} from '@nano_kit/store'\nimport type {\n TranslationData,\n Loader,\n MessagesScheme,\n Messages,\n AnyNamespaceTranslationData,\n AnyTranslationData,\n MessagesAccessor\n} from './types.js'\n\ntype AnySignalRecord = AnySignal & Record<string, unknown>\n\nconst proxyHandler: ProxyHandler<AnySignalRecord> = {\n /* oxlint-disable */\n get($signal, key: string, receiver) {\n if (!(key in $signal)) {\n if (key[0] === '$') {\n const prop = key.slice(1)\n\n return $signal[key] = computed(() => $signal()[prop])\n } else if (typeof key === 'string') {\n const $prop = receiver[`$${key}`]\n\n return $signal[key] = (params: unknown) => computed(\n () => $prop()(params)\n )\n }\n }\n\n return $signal[key]\n }\n /* oxlint-enable */\n}\n\n/**\n * Runtime context used by message formats.\n *\n * It owns the active locale, loads translation data, and exposes messages helpers\n * that bind a messages scheme to the current namespace data.\n * @template T - Translation data shape keyed by namespace name.\n */\nexport class IntlContext<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n> {\n readonly #loader: Loader<T>\n /**\n * Active locale accessor.\n */\n readonly $locale: Accessor<L>\n /**\n * Loading state for full-data loaders.\n */\n readonly $loading: ReadableSignal<boolean>\n /**\n * Loading error for full-data loaders.\n */\n readonly $error: ReadableSignal<unknown>\n\n /**\n * Creates an internationalization context.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n */\n constructor(\n $locale: Accessor<L>,\n loader: Loader<T>\n ) {\n this.$locale = $locale\n this.#loader = loader\n\n if (isFunction(loader)) {\n this.$loading = signal(false)\n this.$error = signal(undefined)\n } else {\n [, this.$error, this.$loading] = loader\n }\n }\n\n /**\n * Creates reactive messages for a single namespace.\n * @param namespace - Namespace key to read from loaded translation data.\n * @param scheme - Messages scheme compatible with the namespace data shape.\n * @returns A tuple with formatted messages, pending state, and loading error.\n */\n messages<K extends keyof T, S extends MessagesScheme<T[K]> = {}>(\n namespace: K,\n scheme: S = {} as S\n ) {\n const entries = Object.entries(scheme)\n const loaderResult = this.#loader\n let $data: ReadableSignal<T[K] | EmptyValue>\n let $error: ReadableSignal<unknown>\n let $pending: ReadableSignal<boolean>\n\n if (isFunction(loaderResult)) {\n [$data, $error, $pending] = loaderResult(namespace, entries)\n } else {\n let $translations\n\n [$translations, $error, $pending] = loaderResult\n\n $data = computed(() => $translations()?.[namespace])\n }\n\n const $messages = computed(() => {\n const data: AnyNamespaceTranslationData | EmptyValue = $data()\n let result: Record<string, unknown> = data ?? {}\n\n if (entries.length > 0) {\n result = {\n ...result\n }\n\n for (const [key, format] of entries) {\n if (import.meta.env.DEV && data && !(key in data)) {\n console.warn(`[nano_kit/intl] Missing message \"${String(namespace)}.${key}\" for locale \"${untracked(this.$locale)}\"`)\n }\n\n result[key] = format(this, data?.[key])\n }\n }\n\n return result as Messages<T[K], S>\n })\n\n return [\n new Proxy($messages as AnySignalRecord, proxyHandler) as MessagesAccessor<T[K], S>,\n $pending,\n $error\n ] as const\n }\n}\n","import type { UnionToIntersection } from './types.js'\n\ntype Split<\n T extends string,\n S extends string = '.'\n> = string extends T\n ? [T]\n : T extends `${infer H}${S}${infer R}`\n ? [H, ...Split<R, S>]\n : [T]\n\ntype TupleOf<N extends number, T extends unknown[] = []> = T['length'] extends N\n ? T\n : TupleOf<N, [...T, unknown]>\n\ntype Add<A extends unknown[], B extends unknown[]> = [...A, ...B]\n\ntype IsAtDepth<\n L extends unknown[],\n D extends number\n> = L extends [...TupleOf<D>, ...unknown[]] ? true : false\n\ntype Simplify<T> = T extends (...args: unknown[]) => unknown\n ? T\n : T extends object\n ? {\n [K in keyof T]: Simplify<T[K]>\n }\n : T\n\ntype PathObject<\n P extends readonly string[],\n V\n> = P extends readonly [infer H extends string, ...infer R extends string[]]\n ? {\n [K in H]: R extends []\n ? V\n : PathObject<R, V>\n }\n : V\n\ninterface DeflatOpenTree<V> {\n [key: string]: V | DeflatOpenTree<V>\n}\n\ntype DeflatOpenRecord<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? DeflatOpenTree<DeflatValue<T[string], D, [...L, unknown]>>\n : Record<string, DeflatValue<T[string], D, [...L, unknown]>>\n\ntype DeflatValue<\n T,\n D extends number,\n L extends unknown[]\n> = T extends Record<string, unknown>\n ? string extends keyof T\n ? DeflatOpenRecord<T, D, L>\n : DeflatAt<T, D, L>\n : T\n\ntype DeflatEntry<\n K extends string,\n V,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? PathObject<Split<K>, DeflatValue<V, D, Add<L, TupleOf<Split<K>['length']>>>>\n : {\n [P in K]: DeflatValue<V, D, [...L, unknown]>\n }\n\ntype DeflatAt<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = Simplify<UnionToIntersection<{\n [K in keyof T & string]: DeflatEntry<K, T[K], D, L>\n}[keyof T & string]>>\n\nexport type Deflat<\n T extends Record<string, unknown>,\n D extends number = 0\n> = string extends keyof T\n ? DeflatOpenRecord<T, D, []>\n : DeflatAt<T, D, []>\n\nexport type DeflatFromDepth<T extends Record<string, unknown>> = Simplify<{\n [K in keyof T]: DeflatValue<T[K], 0, []>\n}>\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null\n && typeof value === 'object'\n && Object.getPrototypeOf(value) === Object.prototype\n}\n\nfunction ensure(\n target: Record<string, unknown>,\n path: string[],\n offset = 0\n) {\n let container = target\n\n for (let i = 0, len = path.length - offset, key; i < len; i++) {\n key = path[i]\n\n if (!isObject(container[key])) {\n container[key] = {}\n }\n\n container = container[key] as Record<string, unknown>\n }\n\n return container\n}\n\nfunction set(\n target: Record<string, unknown>,\n path: string[],\n value: unknown\n) {\n const key = path[path.length - 1]\n const container = ensure(target, path, 1)\n\n container[key] = value\n}\n\nfunction assign(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n depth: number,\n level: number\n) {\n for (const [key, value] of Object.entries(source)) {\n const path = level >= depth ? key.split('.') : [key]\n\n if (isObject(value)) {\n assign(\n ensure(target, path),\n value,\n depth,\n level + path.length\n )\n } else {\n set(target, path, value)\n }\n }\n}\n\n/**\n * Deflates dotted object keys into nested objects.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T\n): Deflat<T>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<\n const T extends Record<string, unknown>,\n const D extends number\n>(\n input: T,\n depth: D\n): Deflat<T, D>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T,\n depth: number\n): DeflatFromDepth<T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function deflat(\n input: Record<string, unknown>,\n depth = 0\n) {\n const output: Record<string, unknown> = {}\n\n assign(output, input, depth, 0)\n\n return output\n}\n","import type { Accessor } from '@nano_kit/store'\nimport type {\n Bound,\n AnyTranslationData,\n Loader,\n TranslationData\n} from './types.js'\nimport { IntlContext } from './context.js'\n\n/**\n * Creates an internationalization context with bound helpers.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n * @returns Internationalization context with `messages` safe to destructure.\n */\nexport function intl<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n>(\n $locale: Accessor<L>,\n loader: Loader<T>\n): Bound<IntlContext<L, T>, 'messages'> {\n const ctx = new IntlContext($locale, loader)\n\n ctx.messages = ctx.messages.bind(ctx)\n\n return ctx\n}\n","import {\n type Accessor,\n computed\n} from '@nano_kit/store'\n\nexport const rtlLocales = new Set([\n 'ar', // Arabic\n 'arc', // Aramaic\n 'dv', // Divehi\n 'fa', // Persian\n 'ha', // Hausa\n 'he', // Hebrew\n 'khw', // Khowar\n 'ks', // Kashmiri\n 'ku', // Kurdish\n 'ps', // Pashto\n 'ur', // Urdu\n 'yi' // Yiddish\n])\n\n/**\n * Resolves text direction for a locale.\n * @param locale - BCP 47 locale code.\n * @returns `rtl` for right-to-left languages, otherwise `ltr`.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function getDirection(locale: string) {\n const lang = new Intl.Locale(locale).language\n\n return rtlLocales.has(lang) ? 'rtl' : 'ltr'\n}\n\n/**\n * Creates a computed text direction from a locale accessor.\n * @param $locale - Active locale accessor.\n * @returns Signal with `rtl` or `ltr` direction.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function direction<T extends string>($locale: Accessor<T>) {\n return computed(() => getDirection($locale()))\n}\n"],"mappings":";;;AAgBA,SAAgB,IAAO,UAAc;CACnC,QAAQ,MAAe,UAAc,SAAS;AAChD;;;;ACDA,SAAgB,KAAK,UAA+C;CAClE,OAAO,oBAAI,QAAQ;AACrB;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,OAAO,KAAK,KAAK,CAAC,EAAE,kBAAkB,IAAI,QAAQ,CAAC;AAC5E;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,OAAO,KAAK,KAAK,CAAC,EAAE,kBAAkB,IAAI,QAAQ,CAAC;AAC5E;AAEA,SAAS,aAAa,SAA6B,QAAgB;CACjE,OAAO,YAAY,KAAA,IACf,UACA,QAAQ,OAAO,CAAC,CAAC,CAAC,kBAAkB,MAAM,IAAI,QAAQ,MAAM,CAAC;AACnE;;AAgBA,SAAgB,WACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,aAAa,OAAO,KAAK,KAAK,GAAG,IAAI,QAAQ,CAAC;AACvE;;;ACrFA,SAAgB,KAAW,IAAkC;CAC3D,IAAI;CACJ,IAAI;CAEJ,QAAQ,WAAW;EACjB,IAAI,WAAW,KAAK;GAClB,QAAQ,GAAG,MAAM;GACjB,MAAM;EACR;EAEA,OAAO;CACT;AACF;;;ACIA,SAAgB,cACd,KACA,OACA;CACA,OAAO,IAAI,OAAO,KAAK;AACzB;AAEA,SAAgB,WAKd,YACA,QACA,mBACA,cACA;CACA,IAAI;CACJ,IAAI;CAEJ,IAAI,iBAAiB,KAAA,GAAW;EAC9B,WAAW;EACX,UAAU;CACZ,OACE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A;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;AAQD,SAAgB,aAAa,QAAgB;CAC3C,MAAM,OAAO,IAAI,KAAK,OAAO,MAAM,CAAC,CAAC;CAErC,OAAO,WAAW,IAAI,IAAI,IAAI,QAAQ;AACxC;;;;;;;AAQA,SAAgB,UAA4B,SAAsB;CAChE,OAAO,eAAe,6BAAa,QAAQ,CAAC,CAAC;AAC/C"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nano_kit/intl",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "
|
|
4
|
+
"version": "2.0.0-prerelease.20260913103613",
|
|
5
5
|
"description": "A lightweight internationalization library for Nano Kit applications.",
|
|
6
6
|
"author": "dangreen",
|
|
7
7
|
"license": "MIT",
|
|
@@ -35,13 +35,15 @@
|
|
|
35
35
|
"./package.json": "./package.json",
|
|
36
36
|
".": {
|
|
37
37
|
"types": "./dist/index.d.ts",
|
|
38
|
-
"
|
|
38
|
+
"development": "./dist/index.development.js",
|
|
39
|
+
"production": "./dist/index.production.js",
|
|
40
|
+
"default": "./dist/index.production.js"
|
|
39
41
|
}
|
|
40
42
|
},
|
|
41
43
|
"files": [
|
|
42
44
|
"dist"
|
|
43
45
|
],
|
|
44
46
|
"peerDependencies": {
|
|
45
|
-
"@nano_kit/store": "^
|
|
47
|
+
"@nano_kit/store": "^2.0.0-prerelease.20260913103613"
|
|
46
48
|
}
|
|
47
49
|
}
|
package/dist/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["#loader"],"sources":["../src/format/raw.ts","../src/format/text.ts","../src/utils.ts","../src/format/intlformat.ts","../src/format/number.ts","../src/format/datetime.ts","../src/format/range.ts","../src/format/relativetime.ts","../src/format/duration.ts","../src/format/list.ts","../src/format/rich.ts","../src/format/markup.ts","../src/format/format.ts","../src/format/params.ts","../src/format/match.ts","../src/format/plural.ts","../src/context.ts","../src/deflat.ts","../src/intl.ts","../src/direction.ts"],"sourcesContent":["import type { Format } from './types.js'\n\n/**\n * Creates a pass-through formatter.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function raw<T>(): Format<T | undefined>\n\n/**\n * Creates a pass-through formatter with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function raw<T>(fallback: T): Format<T | undefined, T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function raw<T>(fallback?: T) {\n return (_ctx: unknown, input?: T) => input ?? fallback\n}\n","import type { Format } from './types.js'\nimport { raw } from './raw.js'\n\n/**\n * Creates a string formatter.\n * @returns Formatter that returns the input string or `undefined`.\n */\nexport function text(): Format<string | undefined>\n\n/**\n * Creates a string formatter with a fallback value.\n * @param fallback - String returned when the input is `undefined` or `null`.\n * @returns Formatter that returns the input string or fallback.\n */\nexport function text(fallback: string): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function text(fallback?: string): Format<string | undefined> {\n return raw(fallback)\n}\n\n/**\n * Creates a formatter that uppercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with uppercased output.\n */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function uppercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function uppercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleUpperCase(ctx.$locale())\n}\n\n/**\n * Creates a formatter that lowercases another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with lowercased output.\n */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function lowercase<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function lowercase<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => format(ctx, input)?.toLocaleLowerCase(ctx.$locale())\n}\n\nfunction toCapitalize(message: string | undefined, locale: string) {\n return message === undefined\n ? message\n : message.charAt(0).toLocaleUpperCase(locale) + message.slice(1)\n}\n\n/**\n * Creates a formatter that capitalizes another text formatter output.\n * @param format - Text formatter to transform.\n * @returns Formatter with the first character uppercased.\n */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined>\n\nexport function capitalize<T>(\n format: Format<T, string>\n): Format<T, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function capitalize<T>(\n format: Format<T, string | undefined>\n): Format<T, string | undefined> {\n return (ctx, input) => toCapitalize(format(ctx, input), ctx.$locale())\n}\n","export function memo<T, K>(fn: (key: K) => T): (key: K) => T {\n let key: K\n let value: T\n\n return (newKey) => {\n if (newKey !== key) {\n value = fn(newKey)\n key = newKey\n }\n\n return value\n }\n}\n","import type { FormatContext } from '../types.js'\nimport { memo } from '../utils.js'\nimport type { IntlFormat } from './types.js'\nimport { raw } from './raw.js'\n\nexport type IntlFormatConstructor<F, O> = new (\n locale: string,\n options?: O\n) => F\n\nexport type IntlFormatFn<F extends IntlFormat<unknown>, I, O> = (\n fmt: F,\n value: I,\n options: O | undefined\n) => string\n\nexport function defaultFormat<F extends IntlFormat<I>, I>(\n fmt: F,\n value: I\n) {\n return fmt.format(value)\n}\n\nexport function intlformat<\n F extends IntlFormat<unknown>,\n I,\n O\n>(\n IntlFormat: IntlFormatConstructor<NoInfer<F>, O>,\n format: IntlFormatFn<F, I, O>,\n optionsOrFallback?: O | false | I,\n maybeOptions?: O | false\n) {\n let fallback: I | undefined\n let options: O | false | undefined\n\n if (maybeOptions !== undefined) {\n fallback = optionsOrFallback as I\n options = maybeOptions\n } else {\n options = optionsOrFallback as O | false | undefined\n }\n\n const rawFormat = raw(fallback)\n\n if (options === false) {\n return rawFormat\n }\n\n const fmt = memo((locale: string) => new IntlFormat(locale, options))\n\n return (ctx: FormatContext, input?: I) => {\n const value = rawFormat(ctx, input)\n\n if (value === undefined) {\n return value\n }\n\n return format(fmt(ctx.$locale()), value, options)\n }\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a number formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function number(\n options: false\n): Format<number | bigint | string | undefined>\n\n/**\n * Creates a locale-aware number formatter.\n * @param options - `Intl.NumberFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n options?: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a number formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function number(\n fallback: number | bigint | string,\n options: false\n): Format<number | bigint | string | undefined, number | bigint | string>\n\n/**\n * Creates a locale-aware number formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.NumberFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n fallback: number | bigint | string,\n options?: Intl.NumberFormatOptions\n): Format<number | bigint | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware number formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.NumberFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.NumberFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function number(\n optionsOrFallback?: Intl.NumberFormatOptions | false | number | bigint | string,\n maybeOptions?: Intl.NumberFormatOptions | false,\n format?: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>\n): Format<number | bigint | string | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function number(\n optionsOrFallback?: Intl.NumberFormatOptions | false | number | bigint | string,\n maybeOptions?: Intl.NumberFormatOptions | false,\n format: IntlFormatFn<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions> = defaultFormat\n) {\n return intlformat<Intl.NumberFormat, number | bigint | string, Intl.NumberFormatOptions>(\n Intl.NumberFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n type IntlFormatFn,\n intlformat\n} from './intlformat.js'\n\nfunction datetimeFormat(\n fmt: Intl.DateTimeFormat,\n value: Date | number | string\n) {\n return fmt.format(typeof value === 'string' ? new Date(value) : value)\n}\n\n/**\n * Creates a date/time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function datetime(\n options: false\n): Format<Date | number | string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter.\n * @param options - `Intl.DateTimeFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n options?: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a date/time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function datetime(\n fallback: Date | number | string,\n options: false\n): Format<Date | number | string | undefined, Date | number | string>\n\n/**\n * Creates a locale-aware date/time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DateTimeFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime(\n fallback: Date | number | string,\n options?: Intl.DateTimeFormatOptions\n): Format<Date | number | string | undefined, string | undefined>\n\n/**\n * Creates a locale-aware date/time formatter with a custom formatting function.\n * @param optionsOrFallback - `Intl.DateTimeFormat` options, `false`, or fallback value.\n * @param maybeOptions - `Intl.DateTimeFormat` options or `false` when fallback is provided.\n * @param format - Custom formatting function.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function datetime<I = Date | number | string>(\n optionsOrFallback?: Intl.DateTimeFormatOptions | false | I,\n maybeOptions?: Intl.DateTimeFormatOptions | false,\n format?: IntlFormatFn<Intl.DateTimeFormat, I, Intl.DateTimeFormatOptions>\n): Format<I | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function datetime(\n optionsOrFallback?: Intl.DateTimeFormatOptions | false | Date | number | string,\n maybeOptions?: Intl.DateTimeFormatOptions | false,\n format: IntlFormatFn<Intl.DateTimeFormat, Date | number | string, Intl.DateTimeFormatOptions> = datetimeFormat\n) {\n return intlformat(\n Intl.DateTimeFormat,\n format,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { IntlFormatFn } from './intlformat.js'\nimport type {\n Format,\n IntlFormatRange\n} from './types.js'\n\ntype RangeInput<I> = readonly [from: I, to: I]\n\ntype RangeFrom<F extends IntlFormatRange<I>, I, O, R> = (\n optionsOrFallback?: O | false | I,\n maybeOptions?: O | false,\n format?: IntlFormatFn<F, I, O>\n) => Format<I | undefined, R | undefined>\n\nfunction rangeFormat(\n fmt: IntlFormatRange<unknown>,\n [from, to]: RangeInput<unknown>\n) {\n return fmt.formatRange(from, to)\n}\n\n/**\n * Creates a range formatter in raw mode.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Pass `false` to return the input range without formatting.\n * @returns Formatter that returns the input range or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options: false\n): Format<RangeInput<I> | undefined>\n\n/**\n * Creates a locale-aware range formatter.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param options - Formatter options.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n options?: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/**\n * Creates a range formatter in raw mode with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input range or fallback without formatting.\n * @returns Formatter that returns the input range or fallback.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options: false\n): Format<RangeInput<I> | undefined, RangeInput<I>>\n\n/**\n * Creates a locale-aware range formatter with a fallback range.\n * @param format - Formatter factory that supports a custom range formatting function.\n * @param fallback - Range used when the input is `undefined` or `null`.\n * @param options - Formatter options.\n * @returns Formatter that returns a formatted range string or `undefined`.\n */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n fallback: RangeInput<I>,\n options?: O\n): Format<RangeInput<I> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function range<F extends IntlFormatRange<I>, I, O, R>(\n format: RangeFrom<F, I, O, R>,\n optionsOrFallback?: O | false | RangeInput<I>,\n maybeOptions?: O | false\n) {\n return format(\n optionsOrFallback as I,\n maybeOptions,\n rangeFormat as IntlFormatFn<F, I, O>\n )\n}\n","import type { Format } from './types.js'\nimport { intlformat } from './intlformat.js'\n\nexport type RelativeTimeOptions = Intl.RelativeTimeFormatOptions & {\n unit: Intl.RelativeTimeFormatUnit\n}\n\nfunction relativeTimeFormat(\n fmt: Intl.RelativeTimeFormat,\n value: number,\n options: RelativeTimeOptions | undefined\n) {\n return fmt.format(value, options!.unit)\n}\n\n/**\n * Creates a relative time formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function relativetime(\n options: false\n): Format<number | undefined>\n\n/**\n * Creates a locale-aware relative time formatter.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n options?: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/**\n * Creates a relative time formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function relativetime(\n fallback: number,\n options: false\n): Format<number | undefined, number>\n\n/**\n * Creates a locale-aware relative time formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.RelativeTimeFormat` options with a required `unit`.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function relativetime(\n fallback: number,\n options?: RelativeTimeOptions\n): Format<number | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function relativetime(\n optionsOrFallback?: RelativeTimeOptions | false | number,\n maybeOptions?: RelativeTimeOptions | false\n) {\n return intlformat(\n Intl.RelativeTimeFormat,\n relativeTimeFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\nexport type Duration = Partial<Record<Intl.DurationFormatUnit, number>>\n\n/**\n * Creates a duration formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function duration(\n options: false\n): Format<Duration | undefined>\n\n/**\n * Creates a locale-aware duration formatter.\n * @param options - `Intl.DurationFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n options?: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/**\n * Creates a duration formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function duration(\n fallback: Duration,\n options: false\n): Format<Duration | undefined, Duration>\n\n/**\n * Creates a locale-aware duration formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.DurationFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function duration(\n fallback: Duration,\n options?: Intl.DurationFormatOptions\n): Format<Duration | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function duration(\n optionsOrFallback?: Intl.DurationFormatOptions | false | Duration,\n maybeOptions?: Intl.DurationFormatOptions | false\n) {\n return intlformat<Intl.DurationFormat, Duration, Intl.DurationFormatOptions>(\n Intl.DurationFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\nimport {\n defaultFormat,\n intlformat\n} from './intlformat.js'\n\n/**\n * Creates a list formatter in raw mode.\n * @param options - Pass `false` to return the input value without formatting.\n * @returns Formatter that returns the input value or `undefined`.\n */\nexport function list(\n options: false\n): Format<Iterable<string> | undefined>\n\n/**\n * Creates a locale-aware list formatter.\n * @param options - `Intl.ListFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n options?: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/**\n * Creates a list formatter in raw mode with a fallback value.\n * @param fallback - Value returned when the input is `undefined` or `null`.\n * @param options - Pass `false` to return the input value or fallback without formatting.\n * @returns Formatter that returns the input value or fallback.\n */\nexport function list(\n fallback: Iterable<string>,\n options: false\n): Format<Iterable<string> | undefined, Iterable<string>>\n\n/**\n * Creates a locale-aware list formatter with a fallback value.\n * @param fallback - Value used when the input is `undefined` or `null`.\n * @param options - `Intl.ListFormat` options.\n * @returns Formatter that returns a formatted string or `undefined`.\n */\nexport function list(\n fallback: Iterable<string>,\n options?: Intl.ListFormatOptions\n): Format<Iterable<string> | undefined, string | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function list(\n optionsOrFallback?: Intl.ListFormatOptions | false | Iterable<string>,\n maybeOptions?: Intl.ListFormatOptions | false\n) {\n return intlformat<Intl.ListFormat, Iterable<string>, Intl.ListFormatOptions>(\n Intl.ListFormat,\n defaultFormat,\n optionsOrFallback,\n maybeOptions\n )\n}\n","import type { Format } from './types.js'\n\nexport type RichChunks<T> = (string | T)[]\n\nexport type RichTag<T> = (chunks: RichChunks<T>, index: number) => T\n\nexport type RichTags<T> = Record<string, RichTag<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/**\n * Creates a rich-text formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map rich-text tags to output chunks.\n * @returns Formatter that returns mapped chunks.\n */\nexport function rich<T>(\n fallback: string,\n tags: RichTags<T>\n): Format<string | undefined, RichChunks<T>>\n\n/**\n * Creates a rich-text formatter.\n * @param fallbackOrTags - Fallback message or tag handlers.\n * @param maybeTags - Tag handlers used when fallback is provided.\n * @returns Formatter that returns mapped chunks or `undefined`.\n */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function rich<T>(\n fallbackOrTags: string | RichTags<T> | undefined,\n maybeTags?: RichTags<T>\n): Format<string | undefined, RichChunks<T> | undefined> {\n let fallback: string | undefined\n let tags: RichTags<T>\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as RichTags<T>\n }\n\n return (_ctx: unknown, input?: string) => {\n const text = input ?? fallback\n\n if (text === undefined) {\n return text\n }\n\n return mapTags(text, tags)\n }\n}\n\nconst tagRegex = /<(\\/?)([A-Za-z][\\w.-]*)\\s*(\\/?)>/g\n\ninterface RichFrame<T> {\n tag: string\n chunks: RichChunks<T>\n}\n\n/**\n * Maps rich-text tags in a string to chunks using provided tag handlers.\n * Each handler call receives an unique index, usable as a key for framework nodes.\n * Self-closing tags are mapped with empty chunks.\n * Unknown or malformed tags are ignored as markup and only their text content is kept.\n * @param input - Rich-text input string.\n * @param tags - Tag handlers used to map known tags.\n * @returns Mapped chunks.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function mapTags<T>(\n input: string,\n tags: RichTags<T>\n): RichChunks<T> {\n const root: RichFrame<T> = {\n tag: '',\n chunks: []\n }\n const stack = [root]\n let lastIndex = 0\n let index = 0\n let match: RegExpExecArray | null\n\n // reset the shared regex state possibly clobbered by an interrupted outer call\n tagRegex.lastIndex = 0\n\n while (match = tagRegex.exec(input)) {\n const [, closing, tag, selfClosing] = match\n const current = stack[stack.length - 1]\n\n if (match.index > lastIndex) {\n current.chunks.push(input.slice(lastIndex, match.index))\n }\n\n lastIndex = tagRegex.lastIndex\n\n if (tag in tags) {\n if (closing) {\n if (current.tag === tag) {\n stack.pop()\n stack[stack.length - 1].chunks.push(\n tags[tag](current.chunks, index++)\n )\n }\n } else if (selfClosing) {\n current.chunks.push(tags[tag]([], index++))\n } else {\n stack.push({\n tag,\n chunks: []\n })\n }\n }\n\n // restore the shared regex state possibly clobbered by a nested call in a tag handler\n tagRegex.lastIndex = lastIndex\n }\n\n if (lastIndex < input.length) {\n stack[stack.length - 1].chunks.push(input.slice(lastIndex))\n }\n\n for (let i = stack.length - 1; i > 0; i--) {\n const frame = stack[i]\n\n stack[i - 1].chunks.push(...frame.chunks)\n }\n\n return root.chunks\n}\n","import type { Format } from './types.js'\nimport {\n type RichTags,\n rich\n} from './rich.js'\n\nexport type MarkupTag = (chunks: string) => string\n\nexport type MarkupTags = Record<string, MarkupTag>\n\n/**\n * Creates a markup formatter.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string or `undefined`.\n */\nexport function markup(\n tags: MarkupTags\n): Format<string | undefined, string | undefined>\n\n/**\n * Creates a markup formatter with a fallback message.\n * @param fallback - Message used when the input is `undefined` or `null`.\n * @param tags - Tag handlers used to map markup tags to strings.\n * @returns Formatter that returns a mapped string.\n */\nexport function markup(\n fallback: string,\n tags: MarkupTags\n): Format<string | undefined, string>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function markup(\n fallbackOrTags: string | MarkupTags,\n maybeTags?: MarkupTags\n): Format<string | undefined, string | undefined> {\n let fallback: string | undefined\n let tags: MarkupTags\n\n if (maybeTags) {\n fallback = fallbackOrTags as string\n tags = maybeTags\n } else {\n tags = fallbackOrTags as MarkupTags\n }\n\n const richTags: RichTags<string> = {}\n\n for (const [tag, format] of Object.entries(tags)) {\n richTags[tag] = chunks => format(chunks.join(''))\n }\n\n const richFormat = rich(fallback, richTags)\n\n return (ctx, input) => richFormat(ctx, input)?.join('')\n}\n","import type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n Format,\n FormatInput,\n FormatOutput\n} from './types.js'\n\nexport type Formatter<F extends AnyFormat> = (\n value: FormatInput<F>\n) => FormatOutput<F>\n\n/**\n * Creates a formatter value from another format.\n * @param type - Format used to format values later.\n * @returns Format that returns a value formatter bound to the current context.\n */\nexport function format<F extends AnyFormat>(\n type: F\n): Format<undefined, Formatter<F>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function format<F extends AnyFormat>(\n type: F\n) {\n return (ctx: FormatContext) => (value: FormatInput<F>) => type(ctx, value)\n}\n","import {\n type Signalish,\n $get,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n FnWithAnyParams,\n Format,\n FormatInput,\n FormatOutput,\n FnWithParams,\n ParamsOf,\n UnionToIntersection\n} from './types.js'\n\nexport type ReplacementValue = string | number | boolean | bigint | undefined\n\nexport type ParamsFormats = Record<string, Format<any, ReplacementValue>>\n\nexport type RequiredParamKeys<P extends ParamsFormats> = {\n [K in keyof P]: undefined extends FormatOutput<P[K]> ? K : never\n}[keyof P]\n\nexport type OptionalParamKeys<P extends ParamsFormats> = Exclude<keyof P, RequiredParamKeys<P>>\n\nexport type ParamsValues<P extends ParamsFormats> = {\n [K in RequiredParamKeys<P>]: Signalish<FormatInput<P[K]>>\n} & {\n [K in OptionalParamKeys<P>]?: Signalish<FormatInput<P[K]> | undefined>\n}\n\nexport type ParamsFn<P extends ParamsFormats> = FnWithParams<ParamsValues<P>>\n\ntype PreformatOutput = string | undefined | FnWithAnyParams\n\ntype ComposedParamsFn<P extends ParamsFormats, O> = FnWithParams<ParamsValues<P> & UnionToIntersection<ParamsOf<O>>>\n\ntype Replace = (ctx: FormatContext, text: string, params: Record<string, Signalish<ReplacementValue>>) => string\n\n/**\n * Creates a parameter interpolation formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<const P extends ParamsFormats>(\n params: P\n): Format<string | undefined, ParamsFn<P>>\n\n/**\n * Creates a parameter interpolation formatter that first applies another formatter.\n * @param params - Parameter formatters keyed by placeholder name.\n * @param preformat - Formatter applied before replacing placeholders.\n * @returns Formatter that replaces `{key}` placeholders using provided parameter values.\n */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function params<\n const P extends ParamsFormats,\n F = string | undefined,\n O extends PreformatOutput = string | undefined | ParamsFn<P>\n>(\n params: P,\n preformat?: Format<F, O>\n): Format<F, ComposedParamsFn<P, O>> {\n let replaceAll: Replace | undefined\n\n for (const [key, format] of Object.entries(params)) {\n const re = new RegExp(`{${key}}`, 'g')\n const replace: Replace = (ctx, text, params) => text.replace(re, format(ctx, $get(params[key])) as string)\n\n if (replaceAll) {\n const prevReplace = replaceAll\n\n replaceAll = (ctx, text, params) => replace(ctx, prevReplace(ctx, text, params), params)\n } else {\n replaceAll = replace\n }\n }\n\n return (ctx: FormatContext, input?: F) => {\n const preformatted = (preformat ? preformat(ctx, input) : input) as PreformatOutput\n\n if (isFunction(preformatted)) {\n return (params) => {\n const text = preformatted(params)\n\n if (text === undefined || !replaceAll) {\n return text\n }\n\n return replaceAll(ctx, text, params)\n }\n }\n\n if (preformatted === undefined || !replaceAll) {\n return () => preformatted\n }\n\n return params => replaceAll(ctx, preformatted, params)\n }\n}\n","import {\n type Signalish,\n $get,\n identity,\n isFunction\n} from '@nano_kit/store'\nimport type { FormatContext } from '../types.js'\nimport type {\n AnyFormat,\n FnWithParams,\n Format,\n FormatsInput,\n UnionToIntersection,\n ParamsOf\n} from './types.js'\n\ntype CaseParams<F> = F extends AnyFormat<infer O> ? ParamsOf<O> : {}\n\nexport type MatchParams<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = {\n [P in K]: Signalish<number | string>\n} & UnionToIntersection<CaseParams<B[keyof B]>>\n\nexport type ArgMatchFn = FnWithParams<Signalish<number | string>>\n\nexport type MatchFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = FnWithParams<MatchParams<K, B> | Signalish<number | string>>\n\nexport type CasesFn<\n K extends string,\n B extends Partial<Record<string, AnyFormat>>\n> = ((\n ctx: FormatContext,\n input: FormatsInput<B> | undefined,\n resolvedCases: Record<string, string | undefined | MatchFn<K, B>>\n) => void) & {\n s: true\n}\n\ntype GetKey = (\n param: any,\n locale: string,\n cases: Record<string, unknown>\n) => string\n\n/**\n * Creates a reusable cases resolver for `match`.\n * @param cases - Case formatters keyed by possible resolved values.\n * @returns Resolver that formats all cases for the current context and translation input.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function cases<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n cases: B\n): CasesFn<K, B> {\n const entries = Object.entries(cases)\n const fn = ((ctx, input, resolvedCases) => {\n for (const [key, format] of entries) {\n resolvedCases[key] = format!(ctx, input?.[key]) as string | undefined | MatchFn<K, B>\n }\n }) as CasesFn<K, B>\n\n fn.s = true\n\n return fn\n}\n\n/**\n * Creates a case key resolver that falls back to a known case when the parameter value is missing.\n * @param key - Case key used when the parameter value does not exist in resolved cases.\n * @returns Resolver that keeps existing case keys and falls back to `key` for unknown values.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function other(key: string): GetKey {\n return (param: string, _, cases) => (param in cases ? param : key)\n}\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n getKey?: GetKey\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n cases?: CasesFn<K, B>,\n getKey?: GetKey\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n>\n\n/**\n * Creates a formatter that selects one case by parameter value.\n * @param param - Parameter name used to select a case and replace `{param}` placeholders.\n * @param cases - Case formatters keyed by possible resolved values.\n * @param getKey - Optional resolver used to map the parameter value to a case key.\n * @returns Formatter that resolves cases and returns a parameterized message function.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function match<\n const K extends string,\n const B extends Partial<Record<string, AnyFormat>>\n>(\n param: K,\n casesOrGetKey?: CasesFn<K, B> | GetKey & {\n s?: never\n },\n maybeGetKey?: GetKey\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n> {\n const valuePattern = new RegExp(`{${param}}`, 'g')\n let cases: CasesFn<K, B> | undefined\n let getKey: GetKey\n\n if (casesOrGetKey?.s) {\n cases = casesOrGetKey\n getKey = maybeGetKey ?? identity\n } else {\n getKey = maybeGetKey ?? casesOrGetKey ?? identity\n }\n\n return (ctx, input: FormatsInput<B> | undefined) => {\n const locale = ctx.$locale()\n let resolvedCases: Record<string, string | undefined | MatchFn<K, B>> = input ?? {}\n\n if (cases) {\n resolvedCases = {\n ...resolvedCases\n }\n\n cases(ctx, input, resolvedCases)\n }\n\n return (params) => {\n const value = $get(typeof params === 'object' ? params[param] : params)\n const key = getKey(value, locale, resolvedCases)\n const resolvedCase = resolvedCases[key]\n const message = isFunction(resolvedCase) ? resolvedCase(params) : resolvedCase\n\n return message?.replace(valuePattern, value as string)\n }\n }\n}\n","import { isFunction } from '@nano_kit/store'\nimport { memo } from '../utils.js'\nimport type {\n AnyFormat,\n Format,\n FormatsInput\n} from './types.js'\nimport {\n type MatchFn,\n type CasesFn,\n match,\n cases\n} from './match.js'\n\nexport type PluralForm = Intl.LDMLPluralRule\n\nexport type PluralKey = PluralForm | `${number}`\n\nexport { cases as forms }\n\n/**\n * Creates a plural formatter.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n>\n\n/**\n * Creates a plural formatter with `Intl.PluralRules` options.\n * @param param - Parameter name used to select plural form and replace `{param}` placeholders.\n * @param options - `Intl.PluralRules` options.\n * @param forms - Plural form formatters keyed by LDML plural rule or exact numeric value.\n * @returns Formatter that resolves plural forms and returns a parameterized message function.\n */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n options: Intl.PluralRulesOptions,\n forms?: CasesFn<K, B>\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function plural<\n const K extends string,\n const B extends Partial<Record<PluralKey, AnyFormat>>\n>(\n param: K,\n optionsOrForms?: Intl.PluralRulesOptions | CasesFn<K, B>,\n maybeForms?: CasesFn<K, B>\n): Format<\n FormatsInput<B>,\n MatchFn<K, B>\n> {\n let options: Intl.PluralRulesOptions | undefined\n let forms: CasesFn<K, B> | undefined\n\n if (isFunction(optionsOrForms)) {\n forms = optionsOrForms\n } else {\n options = optionsOrForms\n forms = maybeForms\n }\n\n const rules = memo((locale: string) => new Intl.PluralRules(locale, options))\n\n return match(param, forms, (count, locale, forms) => {\n if (count in forms) {\n return count as string\n }\n\n let form = rules(locale).select(count as number)\n\n if (!(form in forms)) {\n form = 'other' in forms ? 'other' : 'many'\n }\n\n return form\n })\n}\n","import {\n type Accessor,\n type ReadableSignal,\n type EmptyValue,\n type AnySignal,\n isFunction,\n signal,\n computed\n} from '@nano_kit/store'\nimport type {\n TranslationData,\n Loader,\n MessagesScheme,\n Messages,\n AnyNamespaceTranslationData,\n AnyTranslationData,\n MessagesAccessor\n} from './types.js'\n\ntype AnySignalRecord = AnySignal & Record<string, unknown>\n\nconst proxyHandler: ProxyHandler<AnySignalRecord> = {\n /* oxlint-disable */\n get($signal, key: string, receiver) {\n if (!(key in $signal)) {\n if (key[0] === '$') {\n const prop = key.slice(1)\n\n return $signal[key] = computed(() => $signal()[prop])\n } else if (typeof key === 'string') {\n const $prop = receiver[`$${key}`]\n\n return $signal[key] = (params: unknown) => computed(\n () => $prop()(params)\n )\n }\n }\n\n return $signal[key]\n }\n /* oxlint-enable */\n}\n\n/**\n * Runtime context used by message formats.\n *\n * It owns the active locale, loads translation data, and exposes messages helpers\n * that bind a messages scheme to the current namespace data.\n * @template T - Translation data shape keyed by namespace name.\n */\nexport class IntlContext<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n> {\n readonly #loader: Loader<T>\n /**\n * Active locale accessor.\n */\n readonly $locale: Accessor<L>\n /**\n * Loading state for full-data loaders.\n */\n readonly $loading: ReadableSignal<boolean>\n /**\n * Loading error for full-data loaders.\n */\n readonly $error: ReadableSignal<unknown>\n\n /**\n * Creates an internationalization context.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n */\n constructor(\n $locale: Accessor<L>,\n loader: Loader<T>\n ) {\n this.$locale = $locale\n this.#loader = loader\n\n if (isFunction(loader)) {\n this.$loading = signal(false)\n this.$error = signal(undefined)\n } else {\n [, this.$error, this.$loading] = loader\n }\n }\n\n /**\n * Creates reactive messages for a single namespace.\n * @param namespace - Namespace key to read from loaded translation data.\n * @param scheme - Messages scheme compatible with the namespace data shape.\n * @returns A tuple with formatted messages, pending state, and loading error.\n */\n messages<K extends keyof T, S extends MessagesScheme<T[K]> = {}>(\n namespace: K,\n scheme: S = {} as S\n ) {\n const entries = Object.entries(scheme)\n const loaderResult = this.#loader\n let $data: ReadableSignal<T[K] | EmptyValue>\n let $error: ReadableSignal<unknown>\n let $pending: ReadableSignal<boolean>\n\n if (isFunction(loaderResult)) {\n [$data, $error, $pending] = loaderResult(namespace, entries)\n } else {\n let $translations\n\n [$translations, $error, $pending] = loaderResult\n\n $data = computed(() => $translations()?.[namespace])\n }\n\n const $messages = computed(() => {\n const data: AnyNamespaceTranslationData | EmptyValue = $data()\n let result: Record<string, unknown> = data ?? {}\n\n if (entries.length > 0) {\n result = {\n ...result\n }\n\n for (const [key, format] of entries) {\n result[key] = format(this, data?.[key])\n }\n }\n\n return result as Messages<T[K], S>\n })\n\n return [\n new Proxy($messages as AnySignalRecord, proxyHandler) as MessagesAccessor<T[K], S>,\n $pending,\n $error\n ] as const\n }\n}\n","import type { UnionToIntersection } from './types.js'\n\ntype Split<\n T extends string,\n S extends string = '.'\n> = string extends T\n ? [T]\n : T extends `${infer H}${S}${infer R}`\n ? [H, ...Split<R, S>]\n : [T]\n\ntype TupleOf<N extends number, T extends unknown[] = []> = T['length'] extends N\n ? T\n : TupleOf<N, [...T, unknown]>\n\ntype Add<A extends unknown[], B extends unknown[]> = [...A, ...B]\n\ntype IsAtDepth<\n L extends unknown[],\n D extends number\n> = L extends [...TupleOf<D>, ...unknown[]] ? true : false\n\ntype Simplify<T> = T extends (...args: unknown[]) => unknown\n ? T\n : T extends object\n ? {\n [K in keyof T]: Simplify<T[K]>\n }\n : T\n\ntype PathObject<\n P extends readonly string[],\n V\n> = P extends readonly [infer H extends string, ...infer R extends string[]]\n ? {\n [K in H]: R extends []\n ? V\n : PathObject<R, V>\n }\n : V\n\ninterface DeflatOpenTree<V> {\n [key: string]: V | DeflatOpenTree<V>\n}\n\ntype DeflatOpenRecord<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? DeflatOpenTree<DeflatValue<T[string], D, [...L, unknown]>>\n : Record<string, DeflatValue<T[string], D, [...L, unknown]>>\n\ntype DeflatValue<\n T,\n D extends number,\n L extends unknown[]\n> = T extends Record<string, unknown>\n ? string extends keyof T\n ? DeflatOpenRecord<T, D, L>\n : DeflatAt<T, D, L>\n : T\n\ntype DeflatEntry<\n K extends string,\n V,\n D extends number,\n L extends unknown[]\n> = IsAtDepth<L, D> extends true\n ? PathObject<Split<K>, DeflatValue<V, D, Add<L, TupleOf<Split<K>['length']>>>>\n : {\n [P in K]: DeflatValue<V, D, [...L, unknown]>\n }\n\ntype DeflatAt<\n T extends Record<string, unknown>,\n D extends number,\n L extends unknown[]\n> = Simplify<UnionToIntersection<{\n [K in keyof T & string]: DeflatEntry<K, T[K], D, L>\n}[keyof T & string]>>\n\nexport type Deflat<\n T extends Record<string, unknown>,\n D extends number = 0\n> = string extends keyof T\n ? DeflatOpenRecord<T, D, []>\n : DeflatAt<T, D, []>\n\nexport type DeflatFromDepth<T extends Record<string, unknown>> = Simplify<{\n [K in keyof T]: DeflatValue<T[K], 0, []>\n}>\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return value !== null\n && typeof value === 'object'\n && Object.getPrototypeOf(value) === Object.prototype\n}\n\nfunction ensure(\n target: Record<string, unknown>,\n path: string[],\n offset = 0\n) {\n let container = target\n\n for (let i = 0, len = path.length - offset, key; i < len; i++) {\n key = path[i]\n\n if (!isObject(container[key])) {\n container[key] = {}\n }\n\n container = container[key] as Record<string, unknown>\n }\n\n return container\n}\n\nfunction set(\n target: Record<string, unknown>,\n path: string[],\n value: unknown\n) {\n const key = path[path.length - 1]\n const container = ensure(target, path, 1)\n\n container[key] = value\n}\n\nfunction assign(\n target: Record<string, unknown>,\n source: Record<string, unknown>,\n depth: number,\n level: number\n) {\n for (const [key, value] of Object.entries(source)) {\n const path = level >= depth ? key.split('.') : [key]\n\n if (isObject(value)) {\n assign(\n ensure(target, path),\n value,\n depth,\n level + path.length\n )\n } else {\n set(target, path, value)\n }\n }\n}\n\n/**\n * Deflates dotted object keys into nested objects.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T\n): Deflat<T>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<\n const T extends Record<string, unknown>,\n const D extends number\n>(\n input: T,\n depth: D\n): Deflat<T, D>\n\n/**\n * Deflates dotted object keys into nested objects starting from a depth.\n * @param input - Object with dotted keys.\n * @param depth - Nesting level where dotted keys should start being deflated.\n * @returns Nested object built from dotted keys.\n */\nexport function deflat<const T extends Record<string, unknown>>(\n input: T,\n depth: number\n): DeflatFromDepth<T>\n\n/* @__NO_SIDE_EFFECTS__ */\nexport function deflat(\n input: Record<string, unknown>,\n depth = 0\n) {\n const output: Record<string, unknown> = {}\n\n assign(output, input, depth, 0)\n\n return output\n}\n","import type { Accessor } from '@nano_kit/store'\nimport type {\n Bound,\n AnyTranslationData,\n Loader,\n TranslationData\n} from './types.js'\nimport { IntlContext } from './context.js'\n\n/**\n * Creates an internationalization context with bound helpers.\n * @param $locale - Active locale accessor.\n * @param loader - Messages loader bound to the active locale.\n * @returns Internationalization context with `messages` safe to destructure.\n */\nexport function intl<\n L extends string,\n T extends TranslationData<T> = AnyTranslationData\n>(\n $locale: Accessor<L>,\n loader: Loader<T>\n): Bound<IntlContext<L, T>, 'messages'> {\n const ctx = new IntlContext($locale, loader)\n\n ctx.messages = ctx.messages.bind(ctx)\n\n return ctx\n}\n","import {\n type Accessor,\n computed\n} from '@nano_kit/store'\n\nexport const rtlLocales = new Set([\n 'ar', // Arabic\n 'arc', // Aramaic\n 'dv', // Divehi\n 'fa', // Persian\n 'ha', // Hausa\n 'he', // Hebrew\n 'khw', // Khowar\n 'ks', // Kashmiri\n 'ku', // Kurdish\n 'ps', // Pashto\n 'ur', // Urdu\n 'yi' // Yiddish\n])\n\n/**\n * Resolves text direction for a locale.\n * @param locale - BCP 47 locale code.\n * @returns `rtl` for right-to-left languages, otherwise `ltr`.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function getDirection(locale: string) {\n const lang = new Intl.Locale(locale).language\n\n return rtlLocales.has(lang) ? 'rtl' : 'ltr'\n}\n\n/**\n * Creates a computed text direction from a locale accessor.\n * @param $locale - Active locale accessor.\n * @returns Signal with `rtl` or `ltr` direction.\n */\n/* @__NO_SIDE_EFFECTS__ */\nexport function direction<T extends string>($locale: Accessor<T>) {\n return computed(() => getDirection($locale()))\n}\n"],"mappings":";;;AAgBA,SAAgB,IAAO,UAAc;CACnC,QAAQ,MAAe,UAAc,SAAS;AAChD;;;;ACDA,SAAgB,KAAK,UAA+C;CAClE,OAAO,oBAAI,QAAQ;AACrB;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,OAAO,KAAK,KAAK,CAAC,EAAE,kBAAkB,IAAI,QAAQ,CAAC;AAC5E;;AAgBA,SAAgB,UACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,OAAO,KAAK,KAAK,CAAC,EAAE,kBAAkB,IAAI,QAAQ,CAAC;AAC5E;AAEA,SAAS,aAAa,SAA6B,QAAgB;CACjE,OAAO,YAAY,KAAA,IACf,UACA,QAAQ,OAAO,CAAC,CAAC,CAAC,kBAAkB,MAAM,IAAI,QAAQ,MAAM,CAAC;AACnE;;AAgBA,SAAgB,WACd,QAC+B;CAC/B,QAAQ,KAAK,UAAU,aAAa,OAAO,KAAK,KAAK,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