@nano_kit/intl 2.4.2 → 2.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/format/choose.d.ts +16 -0
- package/dist/format/choose.d.ts.map +1 -0
- package/dist/format/index.d.ts +1 -0
- package/dist/format/index.d.ts.map +1 -1
- package/dist/format/markup.d.ts +18 -0
- package/dist/format/markup.d.ts.map +1 -1
- package/dist/format/match.d.ts.map +1 -1
- package/dist/format/params.d.ts +1 -1
- package/dist/format/rich.d.ts +25 -5
- package/dist/format/rich.d.ts.map +1 -1
- package/dist/format/types.d.ts +1 -1
- package/dist/format/types.d.ts.map +1 -1
- package/dist/format/wrap.d.ts +4 -1
- package/dist/format/wrap.d.ts.map +1 -1
- package/dist/index.development.js +50 -30
- package/dist/index.development.js.map +1 -1
- package/dist/index.production.js +50 -30
- package/dist/index.production.js.map +1 -1
- package/dist/utils.d.ts +1 -0
- package/dist/utils.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { Signalish } from '@nano_kit/store';
|
|
2
|
+
import type { AnyFormat, Format, FormatInput, FormatOutput } from './types.js';
|
|
3
|
+
export type ChooseFormats<F extends Record<string, AnyFormat>> = {
|
|
4
|
+
[K in keyof F]: (value: FormatInput<F[K]> | null) => FormatOutput<F[K]>;
|
|
5
|
+
};
|
|
6
|
+
export type ChooseArg<V> = [V] extends [Record<string, unknown>] ? {
|
|
7
|
+
[K in keyof V]: Signalish<V[K]>;
|
|
8
|
+
} : Signalish<V>;
|
|
9
|
+
/**
|
|
10
|
+
* Creates a callable message that renders a value with the formats a function chooses.
|
|
11
|
+
* @param formats - Formats keyed by name, like `datetime` or `relativetime`.
|
|
12
|
+
* @param fn - Function that receives the formats bound to the active locale, the value of the call read from a signal or an accessor, and the active locale, and returns what the message renders. Each value of a plain object passed instead is read the same way.
|
|
13
|
+
* @returns Format that returns the callable message.
|
|
14
|
+
*/
|
|
15
|
+
export declare function choose<F extends Record<string, AnyFormat>, V = FormatInput<F[keyof F]> | null, O = unknown>(formats: F, fn: (formats: ChooseFormats<F>, value: V, locale: string) => O): Format<undefined, (value: ChooseArg<V>) => O>;
|
|
16
|
+
//# sourceMappingURL=choose.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"choose.d.ts","sourceRoot":"","sources":["../../src/format/choose.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAGhD,OAAO,KAAK,EACV,SAAS,EACT,MAAM,EACN,WAAW,EACX,YAAY,EACb,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,aAAa,CAAC,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,IAAI;KAC9D,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,IAAI,KAAK,YAAY,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACxE,CAAA;AAED,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,GAC5D;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CAChC,GACC,SAAS,CAAC,CAAC,CAAC,CAAA;AAEhB;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,EACnC,CAAC,GAAG,WAAW,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,GAAG,IAAI,EAClC,CAAC,GAAG,OAAO,EAEX,OAAO,EAAE,CAAC,EACV,EAAE,EAAE,CAAC,OAAO,EAAE,aAAa,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,KAAK,CAAC,GAC7D,MAAM,CAAC,SAAS,EAAE,CAAC,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAA"}
|
package/dist/format/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,MAAM,EACN,SAAS,EACT,UAAU,EACV,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/format/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,MAAM,EACN,SAAS,EACT,UAAU,EACV,eAAe,EAChB,MAAM,YAAY,CAAA;AACnB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,eAAe,CAAA;AAC7B,cAAc,YAAY,CAAA;AAC1B,cAAc,mBAAmB,CAAA;AACjC,cAAc,eAAe,CAAA;AAC7B,cAAc,WAAW,CAAA;AACzB,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,aAAa,CAAA;AAC3B,cAAc,WAAW,CAAA;AACzB,cAAc,aAAa,CAAA;AAC3B,cAAc,YAAY,CAAA;AAC1B,cAAc,aAAa,CAAA"}
|
package/dist/format/markup.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import type { Format } from './types.js';
|
|
2
|
+
import { type RichPreformat } from './rich.js';
|
|
2
3
|
export type MarkupTag = (chunks: string) => string;
|
|
3
4
|
export type MarkupTags = Record<string, MarkupTag>;
|
|
4
5
|
/**
|
|
@@ -14,4 +15,21 @@ export declare function markup(tags: MarkupTags): Format<string | undefined, str
|
|
|
14
15
|
* @returns Formatter that returns a mapped string.
|
|
15
16
|
*/
|
|
16
17
|
export declare function markup(fallback: string, tags: MarkupTags): Format<string | undefined, string>;
|
|
18
|
+
/**
|
|
19
|
+
* Creates a markup formatter that formats each text piece before the tag handlers get it.
|
|
20
|
+
* Values filled in by the preformat are never parsed as tags.
|
|
21
|
+
* @param tags - Tag handlers used to map markup tags to strings.
|
|
22
|
+
* @param preformat - Formatter of each text piece between the tags, like `params`.
|
|
23
|
+
* @returns Formatter that returns a message function of the preformat parameters.
|
|
24
|
+
*/
|
|
25
|
+
export declare function markup<P>(tags: MarkupTags, preformat: RichPreformat<P>): Format<string | undefined, (params: P) => string | undefined>;
|
|
26
|
+
/**
|
|
27
|
+
* Creates a markup formatter with a fallback message that formats each text piece before the tag handlers get it.
|
|
28
|
+
* Values filled in by the preformat are never parsed as tags.
|
|
29
|
+
* @param fallback - Message used when the input is `undefined` or `null`.
|
|
30
|
+
* @param tags - Tag handlers used to map markup tags to strings.
|
|
31
|
+
* @param preformat - Formatter of each text piece between the tags, like `params`.
|
|
32
|
+
* @returns Formatter that returns a message function of the preformat parameters.
|
|
33
|
+
*/
|
|
34
|
+
export declare function markup<P>(fallback: string, tags: MarkupTags, preformat: RichPreformat<P>): Format<string | undefined, (params: P) => string>;
|
|
17
35
|
//# sourceMappingURL=markup.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markup.d.ts","sourceRoot":"","sources":["../../src/format/markup.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markup.d.ts","sourceRoot":"","sources":["../../src/format/markup.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,YAAY,CAAA;AACxC,OAAO,EACL,KAAK,aAAa,EAGnB,MAAM,WAAW,CAAA;AAElB,MAAM,MAAM,SAAS,GAAG,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAA;AAElD,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;AAElD;;;;GAIG;AACH,wBAAgB,MAAM,CACpB,IAAI,EAAE,UAAU,GACf,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,GAAG,SAAS,CAAC,CAAA;AAEjD;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,GACf,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,MAAM,CAAC,CAAA;AAErC;;;;;;GAMG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,GAC1B,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,GAAG,SAAS,CAAC,CAAA;AAEhE;;;;;;;GAOG;AACH,wBAAgB,MAAM,CAAC,CAAC,EACtB,QAAQ,EAAE,MAAM,EAChB,IAAI,EAAE,UAAU,EAChB,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,GAC1B,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,CAAC,MAAM,EAAE,CAAC,KAAK,MAAM,CAAC,CAAA"}
|
|
@@ -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,EAA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,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/params.d.ts
CHANGED
|
@@ -23,7 +23,7 @@ export declare function params<const P extends ParamsFormats>(params: P): Format
|
|
|
23
23
|
/**
|
|
24
24
|
* Creates a parameter interpolation formatter that first applies another formatter.
|
|
25
25
|
* @param params - Parameter formatters keyed by placeholder name.
|
|
26
|
-
* @param preformat - Formatter applied before replacing placeholders.
|
|
26
|
+
* @param preformat - Formatter applied before replacing placeholders. `match` and `plural` leave the placeholders of the parameters listed here to be replaced by these formatters.
|
|
27
27
|
* @returns Formatter that replaces `{key}` placeholders using provided parameter values.
|
|
28
28
|
*/
|
|
29
29
|
export declare function params<const P extends ParamsFormats, F = string | undefined, O extends PreformatOutput = string | undefined | ParamsFn<P>>(params: P, preformat: Format<F, O>): Format<F, ComposedParamsFn<P, O>>;
|
package/dist/format/rich.d.ts
CHANGED
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import type { Format } from './types.js';
|
|
1
|
+
import type { FnWithParams, Format } from './types.js';
|
|
2
2
|
export type RichChunks<T> = (string | T)[];
|
|
3
3
|
export type RichTag<T> = (chunks: RichChunks<T>, index: number) => T;
|
|
4
4
|
export type RichTags<T> = Record<string, RichTag<T>>;
|
|
5
|
+
export type RichPreformat<P> = Format<string | undefined, FnWithParams<P>>;
|
|
5
6
|
/**
|
|
6
7
|
* Creates a rich-text formatter.
|
|
7
8
|
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
@@ -15,13 +16,31 @@ export declare function rich<T>(tags: RichTags<T>): Format<string | undefined, R
|
|
|
15
16
|
* @returns Formatter that returns mapped chunks.
|
|
16
17
|
*/
|
|
17
18
|
export declare function rich<T>(fallback: string, tags: RichTags<T>): Format<string | undefined, RichChunks<T>>;
|
|
19
|
+
/**
|
|
20
|
+
* Creates a rich-text formatter that formats each text piece before the tag handlers get it.
|
|
21
|
+
* Values filled in by the preformat are never parsed as tags.
|
|
22
|
+
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
23
|
+
* @param preformat - Formatter of each text piece between the tags, like `params`.
|
|
24
|
+
* @returns Formatter that returns a message function of the preformat parameters.
|
|
25
|
+
*/
|
|
26
|
+
export declare function rich<T, P>(tags: RichTags<T>, preformat: RichPreformat<P>): Format<string | undefined, (params: P) => RichChunks<T> | undefined>;
|
|
27
|
+
/**
|
|
28
|
+
* Creates a rich-text formatter with a fallback message that formats each text piece before the tag handlers get it.
|
|
29
|
+
* Values filled in by the preformat are never parsed as tags.
|
|
30
|
+
* @param fallback - Message used when the input is `undefined` or `null`.
|
|
31
|
+
* @param tags - Tag handlers used to map rich-text tags to output chunks.
|
|
32
|
+
* @param preformat - Formatter of each text piece between the tags, like `params`.
|
|
33
|
+
* @returns Formatter that returns a message function of the preformat parameters.
|
|
34
|
+
*/
|
|
35
|
+
export declare function rich<T, P>(fallback: string, tags: RichTags<T>, preformat: RichPreformat<P>): Format<string | undefined, (params: P) => RichChunks<T>>;
|
|
18
36
|
/**
|
|
19
37
|
* Creates a rich-text formatter.
|
|
20
38
|
* @param fallbackOrTags - Fallback message or tag handlers.
|
|
21
|
-
* @param
|
|
22
|
-
* @
|
|
39
|
+
* @param tagsOrPreformat - Tag handlers used when fallback is provided, or the preformat.
|
|
40
|
+
* @param maybePreformat - Formatter of each text piece used when fallback is provided.
|
|
41
|
+
* @returns Formatter that returns mapped chunks, a message function of them or `undefined`.
|
|
23
42
|
*/
|
|
24
|
-
export declare function rich<T>(fallbackOrTags: string | RichTags<T> | undefined,
|
|
43
|
+
export declare function rich<T, P>(fallbackOrTags: string | RichTags<T> | undefined, tagsOrPreformat?: RichTags<T> | RichPreformat<P>, maybePreformat?: RichPreformat<P>): Format<string | undefined, RichChunks<T> | ((params: P) => RichChunks<T> | undefined) | undefined>;
|
|
25
44
|
/**
|
|
26
45
|
* Maps rich-text tags in a string to chunks using provided tag handlers.
|
|
27
46
|
* Each handler call receives an unique index, usable as a key for framework nodes.
|
|
@@ -29,7 +48,8 @@ export declare function rich<T>(fallbackOrTags: string | RichTags<T> | undefined
|
|
|
29
48
|
* Unknown or malformed tags are ignored as markup and only their text content is kept.
|
|
30
49
|
* @param input - Rich-text input string.
|
|
31
50
|
* @param tags - Tag handlers used to map known tags.
|
|
51
|
+
* @param formatText - Formatter of each text piece between the tags, applied before the tag handlers get it.
|
|
32
52
|
* @returns Mapped chunks.
|
|
33
53
|
*/
|
|
34
|
-
export declare function mapTags<T>(input: string, tags: RichTags<T
|
|
54
|
+
export declare function mapTags<T>(input: string, tags: RichTags<T>, formatText?: (text: string) => string): RichChunks<T>;
|
|
35
55
|
//# sourceMappingURL=rich.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rich.d.ts","sourceRoot":"","sources":["../../src/format/rich.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"rich.d.ts","sourceRoot":"","sources":["../../src/format/rich.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,YAAY,EACZ,MAAM,EACP,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,EAAE,CAAA;AAE1C,MAAM,MAAM,OAAO,CAAC,CAAC,IAAI,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,MAAM,KAAK,CAAC,CAAA;AAEpE,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpD,MAAM,MAAM,aAAa,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,GAAG,SAAS,EAAE,YAAY,CAAC,CAAC,CAAC,CAAC,CAAA;AAE1E;;;;GAIG;AACH,wBAAgB,IAAI,CAAC,CAAC,EACpB,IAAI,EA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,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,GAAG,SAAS,CAAC,CAAA;AAyCrG;;;;;;;;;GASG;AAEH,wBAAgB,OAAO,CAAC,CAAC,EACvB,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,EACjB,UAAU,GAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAe,GAC5C,UAAU,CAAC,CAAC,CAAC,CAwDf"}
|
package/dist/format/types.d.ts
CHANGED
|
@@ -11,7 +11,7 @@ export type FormatsInput<T extends Partial<Record<PropertyKey, AnyFormat>>> = Pa
|
|
|
11
11
|
[K in keyof T]: FormatInput<T[K]>;
|
|
12
12
|
}>;
|
|
13
13
|
export type FnWithParams<P> = (params: P) => string | undefined;
|
|
14
|
-
export type FnWithAnyParams =
|
|
14
|
+
export type FnWithAnyParams = (params: any, formats?: Record<string, unknown>) => string | undefined;
|
|
15
15
|
export interface IntlFormat<T> {
|
|
16
16
|
format(value: T, ...args: unknown[]): string;
|
|
17
17
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/format/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAA;AAC5C,OAAO,KAAK,EACV,aAAa,EACb,mBAAmB,EACpB,MAAM,aAAa,CAAA;AAEpB,YAAY,EAAE,mBAAmB,EAAE,CAAA;AAEnC,KAAK,YAAY,CAAC,CAAC,IAAI,CAAC,SAAS,MAAM,GACnC,CAAC,SAAS,KAAK,GACb,KAAK,GACL,CAAC,GACH,KAAK,CAAA;AAET,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE,MAAM,CAAC,KAAK,OAAO,GAAG,YAAY,CAAC,CAAC,CAAC,GAAG,EAAE,CAAA;AAEvF,MAAM,MAAM,MAAM,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IA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,CAAA;CACpC"}
|
package/dist/format/wrap.d.ts
CHANGED
|
@@ -1,8 +1,11 @@
|
|
|
1
1
|
import { type Accessor, type SignalishValue } from '@nano_kit/store';
|
|
2
2
|
import type { Format } from './types.js';
|
|
3
|
-
export type WrapValues<A> = A extends Accessor<infer V> ? V : A extends
|
|
3
|
+
export type WrapValues<A> = A extends Accessor<infer V> ? V : A extends Record<string, unknown> ? {
|
|
4
4
|
[K in keyof A]: SignalishValue<A[K]>;
|
|
5
5
|
} : A;
|
|
6
|
+
/**
|
|
7
|
+
* @todo Pass the message first at the next major, `[message, values, locale]`, like the value form and `choose`
|
|
8
|
+
*/
|
|
6
9
|
export type WrapArgs<R> = [R] extends [(arg: infer A) => unknown] ? [values: WrapValues<A>, message: R, locale: string] : [message: R, locale: string];
|
|
7
10
|
export type Wrapped<R, O> = [R] extends [(arg: infer A) => unknown] ? (arg: A) => O : O;
|
|
8
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/format/wrap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,
|
|
1
|
+
{"version":3,"file":"wrap.d.ts","sourceRoot":"","sources":["../../src/format/wrap.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,QAAQ,EACb,KAAK,cAAc,EAEpB,MAAM,iBAAiB,CAAA;AAExB,OAAO,KAAK,EAEV,MAAM,EACP,MAAM,YAAY,CAAA;AAEnB,MAAM,MAAM,UAAU,CAAC,CAAC,IAAI,CAAC,SAAS,QAAQ,CAAC,MAAM,CAAC,CAAC,GACnD,CAAC,GACD,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAC/B;KACC,CAAC,IAAI,MAAM,CAAC,GAAG,cAAc,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;CACrC,GACC,CAAC,CAAA;AAEP;;GAEG;AACH,MAAM,MAAM,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,GAC7D,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,GACnD,CAAC,OAAO,EAAE,CAAC,EAAE,MAAM,EAAE,MAAM,CAAC,CAAA;AAEhC,MAAM,MAAM,OAAO,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,GAAG,EAAE,MAAM,CAAC,KAAK,OAAO,CAAC,GAC/D,CAAC,GAAG,EAAE,CAAC,KAAK,CAAC,GACb,CAAC,CAAA;AAEL;;;;;GAKG;AACH,wBAAgB,IAAI,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EAC1B,MAAM,EAAE,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,EACpB,EAAE,EAAE,CAAC,GAAG,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,GAC9B,MAAM,CAAC,CAAC,EAAE,OAAO,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAA"}
|
|
@@ -38,6 +38,12 @@ function memo(fn) {
|
|
|
38
38
|
return value;
|
|
39
39
|
};
|
|
40
40
|
}
|
|
41
|
+
function read(arg) {
|
|
42
|
+
if (arg?.constructor !== Object) return $get(arg);
|
|
43
|
+
const values = {};
|
|
44
|
+
for (const key in arg) values[key] = $get(arg[key]);
|
|
45
|
+
return values;
|
|
46
|
+
}
|
|
41
47
|
//#endregion
|
|
42
48
|
//#region src/format/intlformat.ts
|
|
43
49
|
function defaultFormat(fmt, value) {
|
|
@@ -130,17 +136,19 @@ function list(optionsOrFallback, maybeOptions) {
|
|
|
130
136
|
//#endregion
|
|
131
137
|
//#region src/format/rich.ts
|
|
132
138
|
/* @__NO_SIDE_EFFECTS__ */
|
|
133
|
-
function rich(fallbackOrTags,
|
|
139
|
+
function rich(fallbackOrTags, tagsOrPreformat, maybePreformat) {
|
|
134
140
|
let fallback;
|
|
135
|
-
let tags;
|
|
136
|
-
|
|
141
|
+
let tags = fallbackOrTags;
|
|
142
|
+
let preformat = maybePreformat;
|
|
143
|
+
if (isFunction(tagsOrPreformat)) preformat = tagsOrPreformat;
|
|
144
|
+
else if (tagsOrPreformat) {
|
|
137
145
|
fallback = fallbackOrTags;
|
|
138
|
-
tags =
|
|
139
|
-
}
|
|
140
|
-
return (
|
|
146
|
+
tags = tagsOrPreformat;
|
|
147
|
+
}
|
|
148
|
+
return (ctx, input) => {
|
|
141
149
|
const text = input ?? fallback;
|
|
142
|
-
if (text === void 0)
|
|
143
|
-
return /* @__PURE__ */ mapTags(text, tags);
|
|
150
|
+
if (preformat) return (params) => text === void 0 ? text : /* @__PURE__ */ mapTags(text, tags, (piece) => preformat(ctx, piece)(params));
|
|
151
|
+
return text === void 0 ? text : /* @__PURE__ */ mapTags(text, tags);
|
|
144
152
|
};
|
|
145
153
|
}
|
|
146
154
|
const tagRegex = /<(\/?)([A-Za-z][\w.-]*)\s*(\/?)>/g;
|
|
@@ -151,10 +159,11 @@ const tagRegex = /<(\/?)([A-Za-z][\w.-]*)\s*(\/?)>/g;
|
|
|
151
159
|
* Unknown or malformed tags are ignored as markup and only their text content is kept.
|
|
152
160
|
* @param input - Rich-text input string.
|
|
153
161
|
* @param tags - Tag handlers used to map known tags.
|
|
162
|
+
* @param formatText - Formatter of each text piece between the tags, applied before the tag handlers get it.
|
|
154
163
|
* @returns Mapped chunks.
|
|
155
164
|
*/
|
|
156
165
|
/* @__NO_SIDE_EFFECTS__ */
|
|
157
|
-
function mapTags(input, tags) {
|
|
166
|
+
function mapTags(input, tags, formatText = String) {
|
|
158
167
|
const root = {
|
|
159
168
|
tag: "",
|
|
160
169
|
chunks: []
|
|
@@ -167,7 +176,7 @@ function mapTags(input, tags) {
|
|
|
167
176
|
while (match = tagRegex.exec(input)) {
|
|
168
177
|
const [, closing, tag, selfClosing] = match;
|
|
169
178
|
const current = stack[stack.length - 1];
|
|
170
|
-
if (match.index > lastIndex) current.chunks.push(input.slice(lastIndex, match.index));
|
|
179
|
+
if (match.index > lastIndex) current.chunks.push(formatText(input.slice(lastIndex, match.index)));
|
|
171
180
|
lastIndex = tagRegex.lastIndex;
|
|
172
181
|
if (tag in tags) {
|
|
173
182
|
if (closing) {
|
|
@@ -183,7 +192,7 @@ function mapTags(input, tags) {
|
|
|
183
192
|
}
|
|
184
193
|
tagRegex.lastIndex = lastIndex;
|
|
185
194
|
}
|
|
186
|
-
if (lastIndex < input.length) stack[stack.length - 1].chunks.push(input.slice(lastIndex));
|
|
195
|
+
if (lastIndex < input.length) stack[stack.length - 1].chunks.push(formatText(input.slice(lastIndex)));
|
|
187
196
|
for (let i = stack.length - 1; i > 0; i--) {
|
|
188
197
|
const frame = stack[i];
|
|
189
198
|
stack[i - 1].chunks.push(...frame.chunks);
|
|
@@ -193,17 +202,22 @@ function mapTags(input, tags) {
|
|
|
193
202
|
//#endregion
|
|
194
203
|
//#region src/format/markup.ts
|
|
195
204
|
/* @__NO_SIDE_EFFECTS__ */
|
|
196
|
-
function markup(fallbackOrTags,
|
|
205
|
+
function markup(fallbackOrTags, tagsOrPreformat, maybePreformat) {
|
|
197
206
|
let fallback;
|
|
198
|
-
let tags;
|
|
199
|
-
|
|
207
|
+
let tags = fallbackOrTags;
|
|
208
|
+
let preformat = maybePreformat;
|
|
209
|
+
if (isFunction(tagsOrPreformat)) preformat = tagsOrPreformat;
|
|
210
|
+
else if (tagsOrPreformat) {
|
|
200
211
|
fallback = fallbackOrTags;
|
|
201
|
-
tags =
|
|
202
|
-
}
|
|
212
|
+
tags = tagsOrPreformat;
|
|
213
|
+
}
|
|
203
214
|
const richTags = {};
|
|
204
215
|
for (const [tag, format] of Object.entries(tags)) richTags[tag] = (chunks) => format(chunks.join(""));
|
|
205
|
-
const richFormat = /* @__PURE__ */ rich(fallback, richTags);
|
|
206
|
-
return (ctx, input) =>
|
|
216
|
+
const richFormat = /* @__PURE__ */ rich(fallback, richTags, preformat);
|
|
217
|
+
return (ctx, input) => {
|
|
218
|
+
const chunks = richFormat(ctx, input);
|
|
219
|
+
return isFunction(chunks) ? (params) => chunks(params)?.join("") : chunks?.join("");
|
|
220
|
+
};
|
|
207
221
|
}
|
|
208
222
|
//#endregion
|
|
209
223
|
//#region src/format/format.ts
|
|
@@ -234,10 +248,10 @@ function params(params, preformat) {
|
|
|
234
248
|
}
|
|
235
249
|
return (ctx, input) => {
|
|
236
250
|
const preformatted = preformat ? preformat(ctx, input) : input;
|
|
237
|
-
if (isFunction(preformatted)) return (
|
|
238
|
-
const text = preformatted(params);
|
|
251
|
+
if (isFunction(preformatted)) return (values) => {
|
|
252
|
+
const text = preformatted(values, params);
|
|
239
253
|
if (text === void 0 || !replaceAll) return text;
|
|
240
|
-
return replaceAll(ctx, text,
|
|
254
|
+
return replaceAll(ctx, text, values);
|
|
241
255
|
};
|
|
242
256
|
if (preformatted === void 0 || !replaceAll) return () => preformatted;
|
|
243
257
|
return (params) => replaceAll(ctx, preformatted, params);
|
|
@@ -245,12 +259,6 @@ function params(params, preformat) {
|
|
|
245
259
|
}
|
|
246
260
|
//#endregion
|
|
247
261
|
//#region src/format/wrap.ts
|
|
248
|
-
function read(arg) {
|
|
249
|
-
if (typeof arg !== "object" || !arg) return $get(arg);
|
|
250
|
-
const values = {};
|
|
251
|
-
for (const key in arg) values[key] = $get(arg[key]);
|
|
252
|
-
return values;
|
|
253
|
-
}
|
|
254
262
|
/* @__NO_SIDE_EFFECTS__ */
|
|
255
263
|
function wrap(format, fn) {
|
|
256
264
|
return (ctx, input) => {
|
|
@@ -260,6 +268,17 @@ function wrap(format, fn) {
|
|
|
260
268
|
};
|
|
261
269
|
}
|
|
262
270
|
//#endregion
|
|
271
|
+
//#region src/format/choose.ts
|
|
272
|
+
/* @__NO_SIDE_EFFECTS__ */
|
|
273
|
+
function choose(formats, fn) {
|
|
274
|
+
return (ctx) => {
|
|
275
|
+
const bound = {};
|
|
276
|
+
const locale = ctx.$locale();
|
|
277
|
+
for (const key in formats) bound[key] = (value) => formats[key](ctx, value);
|
|
278
|
+
return (value) => fn(bound, read(value), locale);
|
|
279
|
+
};
|
|
280
|
+
}
|
|
281
|
+
//#endregion
|
|
263
282
|
//#region src/format/match.ts
|
|
264
283
|
/**
|
|
265
284
|
* Creates a reusable cases resolver for `match`.
|
|
@@ -308,10 +327,11 @@ function match(param, casesOrGetKey, maybeGetKey) {
|
|
|
308
327
|
resolvedCases = { ...resolvedCases };
|
|
309
328
|
cases(ctx, input, resolvedCases);
|
|
310
329
|
}
|
|
311
|
-
return (params) => {
|
|
330
|
+
return (params, formats) => {
|
|
312
331
|
const value = $get(typeof params === "object" ? params[param] : params);
|
|
313
332
|
const resolvedCase = isString ? input : resolvedCases[getKey(value, locale, resolvedCases)];
|
|
314
|
-
|
|
333
|
+
const message = isFunction(resolvedCase) ? resolvedCase(params, formats) : resolvedCase;
|
|
334
|
+
return formats && param in formats ? message : message?.replace(valuePattern, value);
|
|
315
335
|
};
|
|
316
336
|
};
|
|
317
337
|
}
|
|
@@ -515,6 +535,6 @@ function direction($locale) {
|
|
|
515
535
|
return computed(() => /* @__PURE__ */ getDirection($locale()));
|
|
516
536
|
}
|
|
517
537
|
//#endregion
|
|
518
|
-
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, wrap };
|
|
538
|
+
export { IntlContext, capitalize, cases, cases as forms, choose, datetime, deflat, direction, duration, format, getDirection, intl, list, lowercase, mapTags, markup, match, number, other, params, plural, range, raw, relativetime, rich, rtlLocales, text, uppercase, wrap };
|
|
519
539
|
|
|
520
540
|
//# sourceMappingURL=index.development.js.map
|