@parlajs/core 0.0.0-stage → 0.0.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/LICENSE +21 -0
- package/README.md +27 -2
- package/build/acceptLanguage.d.ts +6 -0
- package/build/acceptLanguage.d.ts.map +1 -0
- package/build/acceptLanguage.js +23 -0
- package/build/catalog.d.ts +25 -0
- package/build/catalog.d.ts.map +1 -0
- package/build/catalog.js +1 -0
- package/build/direction.d.ts +3 -0
- package/build/direction.d.ts.map +1 -0
- package/build/direction.js +12 -0
- package/build/escape.d.ts +5 -0
- package/build/escape.d.ts.map +1 -0
- package/build/escape.js +18 -0
- package/build/ids.d.ts +15 -0
- package/build/ids.d.ts.map +1 -0
- package/build/ids.js +54 -0
- package/build/index.d.ts +11 -0
- package/build/index.d.ts.map +1 -0
- package/build/index.js +16 -0
- package/build/instance.d.ts +46 -0
- package/build/instance.d.ts.map +1 -0
- package/build/instance.js +1 -0
- package/build/intl.d.ts +11 -0
- package/build/intl.d.ts.map +1 -0
- package/build/intl.js +48 -0
- package/build/match.d.ts +14 -0
- package/build/match.d.ts.map +1 -0
- package/build/match.js +54 -0
- package/build/message.d.ts +3 -0
- package/build/message.d.ts.map +1 -0
- package/build/message.js +2 -0
- package/build/namespace.d.ts +56 -0
- package/build/namespace.d.ts.map +1 -0
- package/build/namespace.js +1 -0
- package/build/parla.d.ts +4 -0
- package/build/parla.d.ts.map +1 -0
- package/build/parla.js +135 -0
- package/build/pick.d.ts +4 -0
- package/build/pick.d.ts.map +1 -0
- package/build/pick.js +50 -0
- package/build/reads.d.ts +20 -0
- package/build/reads.d.ts.map +1 -0
- package/build/reads.js +26 -0
- package/build/runtime.d.ts +61 -0
- package/build/runtime.d.ts.map +1 -0
- package/build/runtime.js +153 -0
- package/build/shared.d.ts +24 -0
- package/build/shared.d.ts.map +1 -0
- package/build/shared.js +56 -0
- package/build/text.d.ts +3 -0
- package/build/text.d.ts.map +1 -0
- package/build/text.js +15 -0
- package/package.json +53 -3
- package/src/acceptLanguage.ts +25 -0
- package/src/catalog.ts +32 -0
- package/src/direction.ts +14 -0
- package/src/escape.ts +22 -0
- package/src/ids.ts +85 -0
- package/src/index.ts +50 -0
- package/src/instance.ts +60 -0
- package/src/intl.ts +65 -0
- package/src/match.ts +66 -0
- package/src/message.ts +2 -0
- package/src/namespace.ts +69 -0
- package/src/parla.ts +156 -0
- package/src/pick.ts +54 -0
- package/src/reads.ts +45 -0
- package/src/runtime.ts +251 -0
- package/src/shared.ts +82 -0
- package/src/text.ts +18 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Marco Pasqualetti
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,28 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @parlajs/core
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[Parla](https://github.com/parlajs/parla)'s framework-agnostic runtime. Apps usually use it
|
|
4
|
+
through an adapter such as [`@parlajs/react`](../react), which re-exports it.
|
|
5
|
+
|
|
6
|
+
```ts
|
|
7
|
+
import { createParla, matchLocale } from '@parlajs/core';
|
|
8
|
+
|
|
9
|
+
import { catalog } from './parla/catalog.js'; // written by `parla build`
|
|
10
|
+
import { checkout } from './parla/namespaces/checkout.js';
|
|
11
|
+
|
|
12
|
+
const parla = createParla({
|
|
13
|
+
catalog,
|
|
14
|
+
locale: matchLocale(navigator.languages, catalog.locales, catalog.sourceLocale),
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const t = await parla.load([checkout]);
|
|
18
|
+
t.checkout.cart.items({ count: 3 }); // "3 items"
|
|
19
|
+
|
|
20
|
+
await parla.switchLocale('it'); // loads what's loaded so far, then switches
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Docs: [`@parlajs/core`](https://parlajs.github.io/parla/core/api/),
|
|
24
|
+
[Server](https://parlajs.github.io/parla/core/server/).
|
|
25
|
+
|
|
26
|
+
## License
|
|
27
|
+
|
|
28
|
+
[MIT](./LICENSE)
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The tags of an `Accept-Language` header, most wanted first, for `matchLocale`. Drops `*`, `q=0`
|
|
3
|
+
* and invalid weights such as `q=1.5`, and all but the first 32; equal weights keep the header's order.
|
|
4
|
+
*/
|
|
5
|
+
export declare function parseAcceptLanguage(header: string | null | undefined): Array<string>;
|
|
6
|
+
//# sourceMappingURL=acceptLanguage.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"acceptLanguage.d.ts","sourceRoot":"","sources":["../src/acceptLanguage.ts"],"names":[],"mappings":"AAMA;;;GAGG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,GAAG,SAAS,GAAG,KAAK,CAAC,MAAM,CAAC,CAcpF"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** RFC 9110's qvalue; spaces around `=` are tolerated. */
|
|
2
|
+
const QVALUE = /^q\s*=\s*(?<q>0(?:\.\d{0,3})?|1(?:\.0{0,3})?)$/i;
|
|
3
|
+
/** A client writes the header, and `matchLocale` costs time per tag. */
|
|
4
|
+
const MAX_TAGS = 32;
|
|
5
|
+
/**
|
|
6
|
+
* The tags of an `Accept-Language` header, most wanted first, for `matchLocale`. Drops `*`, `q=0`
|
|
7
|
+
* and invalid weights such as `q=1.5`, and all but the first 32; equal weights keep the header's order.
|
|
8
|
+
*/
|
|
9
|
+
export function parseAcceptLanguage(header) {
|
|
10
|
+
const weighted = [];
|
|
11
|
+
for (const part of (header ?? '').split(',')) {
|
|
12
|
+
const [tag = '', ...params] = part.split(';').map((s) => s.trim());
|
|
13
|
+
const quality = params.find((param) => /^q(?:\s|=|$)/i.test(param));
|
|
14
|
+
const weight = quality === undefined ? 1 : Number(QVALUE.exec(quality)?.groups?.['q'] ?? 0);
|
|
15
|
+
if (tag !== '' && tag !== '*' && weight > 0) {
|
|
16
|
+
weighted.push({ tag, q: weight });
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return weighted
|
|
20
|
+
.sort((a, b) => b.q - a.q)
|
|
21
|
+
.slice(0, MAX_TAGS)
|
|
22
|
+
.map(({ tag }) => tag);
|
|
23
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
export interface LocaleRegistry {
|
|
2
|
+
}
|
|
3
|
+
export interface FunctionRegistry {
|
|
4
|
+
}
|
|
5
|
+
export interface MarkupRegistry {
|
|
6
|
+
}
|
|
7
|
+
/** Every locale a generated catalog declares; `string` before any is registered. */
|
|
8
|
+
export type Locale = [keyof LocaleRegistry] extends [never] ? string : Extract<keyof LocaleRegistry, string>;
|
|
9
|
+
/** The config's `functions`: each needs an implementation in `createParla({ functions })`. */
|
|
10
|
+
export type FunctionName = Extract<keyof FunctionRegistry, string>;
|
|
11
|
+
/** The config's `markup`: each needs a renderer in `createParla({ markup })`. */
|
|
12
|
+
export type MarkupName = Extract<keyof MarkupRegistry, string>;
|
|
13
|
+
/** Emitted by `parla build` as `catalog.js`. */
|
|
14
|
+
export interface Catalog {
|
|
15
|
+
readonly locales: ReadonlyArray<Locale>;
|
|
16
|
+
readonly sourceLocale: Locale;
|
|
17
|
+
/** Each locale's fallback chain, which `Intl` also follows where it lacks the locale's data. */
|
|
18
|
+
readonly fallbacks?: Readonly<Partial<Record<string, ReadonlyArray<string>>>>;
|
|
19
|
+
/**
|
|
20
|
+
* The locales where `Intl` writes 0 to 999 as JavaScript does, so formatting those skips it: each
|
|
21
|
+
* with what it puts between an integer's groups of three, so those skip it too, or `true`.
|
|
22
|
+
*/
|
|
23
|
+
readonly plainDigits?: Readonly<Partial<Record<string, string | true>>>;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=catalog.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"catalog.d.ts","sourceRoot":"","sources":["../src/catalog.ts"],"names":[],"mappings":"AAKA,MAAM,WAAW,cAAc;CAAG;AAElC,MAAM,WAAW,gBAAgB;CAAG;AAEpC,MAAM,WAAW,cAAc;CAAG;AAElC,oFAAoF;AACpF,MAAM,MAAM,MAAM,GAAG,CAAC,MAAM,cAAc,CAAC,SAAS,CAAC,KAAK,CAAC,GACvD,MAAM,GACN,OAAO,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,CAAC;AAC1C,8FAA8F;AAC9F,MAAM,MAAM,YAAY,GAAG,OAAO,CAAC,MAAM,gBAAgB,EAAE,MAAM,CAAC,CAAC;AACnE,iFAAiF;AACjF,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,cAAc,EAAE,MAAM,CAAC,CAAC;AAE/D,gDAAgD;AAChD,MAAM,WAAW,OAAO;IACtB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,gGAAgG;IAChG,QAAQ,CAAC,SAAS,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;IAC9E;;;OAGG;IACH,QAAQ,CAAC,WAAW,CAAC,EAAE,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;CACzE"}
|
package/build/catalog.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"direction.d.ts","sourceRoot":"","sources":["../src/direction.ts"],"names":[],"mappings":"AAOA,sGAAsG;AACtG,wBAAgB,SAAS,CAAC,MAAM,EAAE,MAAM,GAAG,KAAK,GAAG,KAAK,CAKvD"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { maximize } from './match.js';
|
|
2
|
+
// The scripts in use today; `Intl.Locale` gives the one a tag omits.
|
|
3
|
+
const RTL_SCRIPT = /^(?:adlm|arab|aran|hebr|mand|nkoo|rohg|samr|syrc|thaa|yezi)$/i;
|
|
4
|
+
// Where nothing does: without `Intl.Locale` (Hermes), or a language its data lacks.
|
|
5
|
+
const RTL_LANGUAGE = /^(?:ar|ckb|dv|fa|he|iw|ks|nqo|ps|sd|syr|ug|ur|yi)$/;
|
|
6
|
+
/** For `<html dir>`. By script, as Firefox lacks `getTextInfo` and a server and client must agree. */
|
|
7
|
+
export function direction(locale) {
|
|
8
|
+
const { language = '', script } = maximize(locale) ?? {};
|
|
9
|
+
return (script === undefined ? RTL_LANGUAGE.test(language) : RTL_SCRIPT.test(script))
|
|
10
|
+
? 'rtl'
|
|
11
|
+
: 'ltr';
|
|
12
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { MessageRuntime } from './runtime.ts';
|
|
2
|
+
/** For `createParla({ escape })` in HTML: the five characters i18next escapes too. */
|
|
3
|
+
export declare function escapeHtml(text: string): string;
|
|
4
|
+
export declare const escaping: (rt: MessageRuntime, escape: (text: string) => string) => MessageRuntime;
|
|
5
|
+
//# sourceMappingURL=escape.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"escape.d.ts","sourceRoot":"","sources":["../src/escape.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAUnD,sFAAsF;AACtF,wBAAgB,UAAU,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAE/C;AAGD,eAAO,MAAM,QAAQ,OAAQ,cAAc,UAAU,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,KAAG,cAK9E,CAAC"}
|
package/build/escape.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
const ENTITIES = {
|
|
2
|
+
'&': '&',
|
|
3
|
+
'<': '<',
|
|
4
|
+
'>': '>',
|
|
5
|
+
'"': '"',
|
|
6
|
+
"'": ''',
|
|
7
|
+
};
|
|
8
|
+
/** For `createParla({ escape })` in HTML: the five characters i18next escapes too. */
|
|
9
|
+
export function escapeHtml(text) {
|
|
10
|
+
return text.replaceAll(/[&<>"']/g, (c) => ENTITIES[c] ?? c);
|
|
11
|
+
}
|
|
12
|
+
// Every param becomes text through `str` or `f`; translations and markup output never do.
|
|
13
|
+
export const escaping = (rt, escape) => ({
|
|
14
|
+
...rt,
|
|
15
|
+
str: (value) => escape(rt.str(value)),
|
|
16
|
+
f: (name, value, options) => escape(rt.f(name, value, options)),
|
|
17
|
+
n: (value) => escape(rt.n(value)),
|
|
18
|
+
});
|
package/build/ids.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Locale } from './catalog.ts';
|
|
2
|
+
import type { Loader } from './namespace.ts';
|
|
3
|
+
/** What the runtime reads of a namespace, whatever locales the app declares. */
|
|
4
|
+
export interface Loadable {
|
|
5
|
+
readonly name: string;
|
|
6
|
+
readonly load: Readonly<Record<string, Loader>>;
|
|
7
|
+
}
|
|
8
|
+
export interface NamespaceIds {
|
|
9
|
+
/** `[name, id]` per namespace, sorted by name: one cache key for any order. */
|
|
10
|
+
readonly resolve: (namespaces: ReadonlyArray<Loadable>) => Array<[name: string, id: number]>;
|
|
11
|
+
readonly loaderOf: (id: number, locale: string) => Loader;
|
|
12
|
+
}
|
|
13
|
+
/** An instance's namespaces, each checked once for every locale. */
|
|
14
|
+
export declare function namespaceIds(locales: ReadonlyArray<Locale>): NamespaceIds;
|
|
15
|
+
//# sourceMappingURL=ids.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ids.d.ts","sourceRoot":"","sources":["../src/ids.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAE3C,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,gBAAgB,CAAC;AAE7C,gFAAgF;AAChF,MAAM,WAAW,QAAQ;IACvB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;CACjD;AAED,MAAM,WAAW,YAAY;IAC3B,+EAA+E;IAC/E,QAAQ,CAAC,OAAO,EAAE,CAAC,UAAU,EAAE,aAAa,CAAC,QAAQ,CAAC,KAAK,KAAK,CAAC,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,CAAC,CAAC,CAAC;IAC7F,QAAQ,CAAC,QAAQ,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D;AAqBD,oEAAoE;AACpE,wBAAgB,YAAY,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,GAAG,YAAY,CAgDzE"}
|
package/build/ids.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import { parlaMessage } from './message.js';
|
|
2
|
+
// A missed lookup such as `{ checkout }[name]` passes `undefined`, which must fail before it is read.
|
|
3
|
+
const isLoadable = (value) => {
|
|
4
|
+
const ns = value;
|
|
5
|
+
return (typeof ns === 'object' &&
|
|
6
|
+
ns !== null &&
|
|
7
|
+
typeof ns.name === 'string' &&
|
|
8
|
+
typeof ns.load === 'object' &&
|
|
9
|
+
ns.load !== null);
|
|
10
|
+
};
|
|
11
|
+
const describe = (value) => {
|
|
12
|
+
if (typeof value === 'object' && value !== null) {
|
|
13
|
+
return 'an object without name and load';
|
|
14
|
+
}
|
|
15
|
+
return typeof value === 'string' ? JSON.stringify(value) : String(value);
|
|
16
|
+
};
|
|
17
|
+
/** An instance's namespaces, each checked once for every locale. */
|
|
18
|
+
export function namespaceIds(locales) {
|
|
19
|
+
// By object, not name: two packages may each own a `common`, and each `t` gets its own.
|
|
20
|
+
const ids = new WeakMap();
|
|
21
|
+
const registered = new Map();
|
|
22
|
+
const adopt = (ns) => {
|
|
23
|
+
if (!isLoadable(ns)) {
|
|
24
|
+
throw new TypeError(parlaMessage(`load takes namespace objects, not ${describe(ns)}: import it from the generated namespaces/`));
|
|
25
|
+
}
|
|
26
|
+
let id = ids.get(ns);
|
|
27
|
+
if (id === undefined) {
|
|
28
|
+
const missing = locales.filter((l) => !Object.hasOwn(ns.load, l));
|
|
29
|
+
if (missing.length > 0) {
|
|
30
|
+
throw new Error(parlaMessage(`namespace "${ns.name}" was built for ${Object.keys(ns.load).join(', ') || 'no locale'}, not ${missing.join(', ')}`));
|
|
31
|
+
}
|
|
32
|
+
id = registered.size;
|
|
33
|
+
ids.set(ns, id);
|
|
34
|
+
registered.set(id, ns);
|
|
35
|
+
}
|
|
36
|
+
return id;
|
|
37
|
+
};
|
|
38
|
+
return {
|
|
39
|
+
resolve(namespaces) {
|
|
40
|
+
const byName = new Map();
|
|
41
|
+
for (const ns of namespaces) {
|
|
42
|
+
const id = adopt(ns);
|
|
43
|
+
if ((byName.get(ns.name) ?? id) !== id) {
|
|
44
|
+
throw new Error(parlaMessage(`two namespaces named "${ns.name}" in one load: t holds one per name`));
|
|
45
|
+
}
|
|
46
|
+
byName.set(ns.name, id);
|
|
47
|
+
}
|
|
48
|
+
// Not `toSorted`: Hermes (React Native) lacks it, and the spread is a copy already.
|
|
49
|
+
return [...byName].sort(([a], [b]) => (a < b ? -1 : 1));
|
|
50
|
+
},
|
|
51
|
+
// `adopt` checked every locale, and only adopted objects reach here.
|
|
52
|
+
loaderOf: (id, locale) => registered.get(id)?.load[locale],
|
|
53
|
+
};
|
|
54
|
+
}
|
package/build/index.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export { parseAcceptLanguage } from './acceptLanguage.ts';
|
|
2
|
+
export type { Catalog, FunctionName, FunctionRegistry, Locale, LocaleRegistry, MarkupName, MarkupRegistry, } from './catalog.ts';
|
|
3
|
+
export { direction } from './direction.ts';
|
|
4
|
+
export { escapeHtml } from './escape.ts';
|
|
5
|
+
export type { Parla, ParlaOptions } from './instance.ts';
|
|
6
|
+
export { matchLocale } from './match.ts';
|
|
7
|
+
export { parlaMessage } from './message.ts';
|
|
8
|
+
export type { Loaded, Loader, MessageFactory, MessageModule, Namespace, NamespaceKind, Text, Translations, } from './namespace.ts';
|
|
9
|
+
export { createParla } from './parla.ts';
|
|
10
|
+
export { createRuntime, type MessageFunction, type MessageFunctionInput, type MessageRuntime, type RuntimeOptions, type SelectorValue, type WrapRich, } from './runtime.ts';
|
|
11
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,mBAAmB,EAAE,MAAM,qBAAqB,CAAC;AAC1D,YAAY,EACV,OAAO,EACP,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,cAAc,EACd,UAAU,EACV,cAAc,GACf,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,YAAY,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,YAAY,EACV,MAAM,EACN,MAAM,EACN,cAAc,EACd,aAAa,EACb,SAAS,EACT,aAAa,EACb,IAAI,EACJ,YAAY,GACb,MAAM,gBAAgB,CAAC;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AACzC,OAAO,EACL,aAAa,EACb,KAAK,eAAe,EACpB,KAAK,oBAAoB,EACzB,KAAK,cAAc,EACnB,KAAK,cAAc,EACnB,KAAK,aAAa,EAClB,KAAK,QAAQ,GACd,MAAM,cAAc,CAAC"}
|
package/build/index.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { parlaMessage } from './message.js';
|
|
2
|
+
export { parseAcceptLanguage } from './acceptLanguage.js';
|
|
3
|
+
export { direction } from './direction.js';
|
|
4
|
+
export { escapeHtml } from './escape.js';
|
|
5
|
+
export { matchLocale } from './match.js';
|
|
6
|
+
export { parlaMessage } from './message.js';
|
|
7
|
+
export { createParla } from './parla.js';
|
|
8
|
+
export { createRuntime, } from './runtime.js';
|
|
9
|
+
const INSTANCE = Symbol.for('parlajs.core');
|
|
10
|
+
const marker = {};
|
|
11
|
+
const g = globalThis;
|
|
12
|
+
if (g[INSTANCE] && g[INSTANCE] !== marker) {
|
|
13
|
+
// oxlint-disable-next-line no-console -- two instances split locale state with no error
|
|
14
|
+
console.warn(parlaMessage('Several copies of @parlajs/core are loaded: dedupe it, so the app and its adapter share one.'));
|
|
15
|
+
}
|
|
16
|
+
g[INSTANCE] = marker;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import type { Catalog, FunctionName, Locale, MarkupName } from './catalog.ts';
|
|
2
|
+
import type { Loaded, Namespace } from './namespace.ts';
|
|
3
|
+
import type { MessageFunction, WrapRich } from './runtime.ts';
|
|
4
|
+
/** Required, with every declared name, once the config declares any. */
|
|
5
|
+
type Declared<K extends string, Name extends string, V> = [Name] extends [never] ? Partial<Record<K, undefined>> : Record<K, Readonly<Record<Name, V>>>;
|
|
6
|
+
export type ParlaOptions<Node = string> = {
|
|
7
|
+
catalog: Catalog;
|
|
8
|
+
/** Initial locale. Defaults to the source locale. */
|
|
9
|
+
locale?: Locale;
|
|
10
|
+
/**
|
|
11
|
+
* IANA zone for `:date`, `:time` and `:datetime` unless a message sets `timeZone`. Defaults to the
|
|
12
|
+
* host's, which on a server is rarely the reader's.
|
|
13
|
+
*/
|
|
14
|
+
timeZone?: string;
|
|
15
|
+
/** Turns message parts with markup into one node. Set by framework adapters. */
|
|
16
|
+
wrapRich?: WrapRich<Node>;
|
|
17
|
+
} & Declared<'functions', FunctionName, MessageFunction> & Declared<'markup', MarkupName, (children: NoInfer<Node>) => NoInfer<Node>> & Escape<Node>;
|
|
18
|
+
type Escape<Node> = [Node] extends [string] ? {
|
|
19
|
+
/** Escapes each param's text, e.g. `escapeHtml` in HTML emails; translations stay as written. */
|
|
20
|
+
escape?: (text: string) => string;
|
|
21
|
+
} : {
|
|
22
|
+
escape?: never;
|
|
23
|
+
};
|
|
24
|
+
export interface Parla<Node = string> {
|
|
25
|
+
readonly locale: Locale;
|
|
26
|
+
readonly locales: ReadonlyArray<Locale>;
|
|
27
|
+
/** Loads every namespace loaded so far for `locale`, then switches, so nothing suspends. */
|
|
28
|
+
readonly switchLocale: (locale: Locale) => Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Loads the namespaces, for the current locale by default. The same list returns the same promise,
|
|
31
|
+
* carrying `status` and `value` once settled, which React's `use()` reads without suspending. A
|
|
32
|
+
* failure is returned for a second, then retried. Throws at once for a namespace missing a locale.
|
|
33
|
+
*
|
|
34
|
+
* An adapter whose framework may hold a switch back passes the locale on screen instead.
|
|
35
|
+
*/
|
|
36
|
+
readonly load: <const L extends ReadonlyArray<Namespace>>(namespaces: L, locale?: Locale) => Promise<Loaded<L, Node>>;
|
|
37
|
+
/**
|
|
38
|
+
* `t`, if the namespaces are loaded for that locale; never downloads. Frameworks without
|
|
39
|
+
* Suspense render from it, and `load` otherwise. The same list returns the same `t` as `load`.
|
|
40
|
+
*/
|
|
41
|
+
readonly loaded: <const L extends ReadonlyArray<Namespace>>(namespaces: L, locale?: Locale) => Loaded<L, Node> | undefined;
|
|
42
|
+
/** Called after each locale switch. */
|
|
43
|
+
readonly subscribe: (listener: () => void) => () => void;
|
|
44
|
+
}
|
|
45
|
+
export {};
|
|
46
|
+
//# sourceMappingURL=instance.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"instance.d.ts","sourceRoot":"","sources":["../src/instance.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AAC9E,OAAO,KAAK,EAAE,MAAM,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACxD,OAAO,KAAK,EAAE,eAAe,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAE9D,wEAAwE;AACxE,KAAK,QAAQ,CAAC,CAAC,SAAS,MAAM,EAAE,IAAI,SAAS,MAAM,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,GAC5E,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,SAAS,CAAC,CAAC,GAC7B,MAAM,CAAC,CAAC,EAAE,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC;AAGzC,MAAM,MAAM,YAAY,CAAC,IAAI,GAAG,MAAM,IAAI;IACxC,OAAO,EAAE,OAAO,CAAC;IACjB,qDAAqD;IACrD,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,gFAAgF;IAChF,QAAQ,CAAC,EAAE,QAAQ,CAAC,IAAI,CAAC,CAAC;CAC3B,GAAG,QAAQ,CAAC,WAAW,EAAE,YAAY,EAAE,eAAe,CAAC,GACtD,QAAQ,CAAC,QAAQ,EAAE,UAAU,EAAE,CAAC,QAAQ,EAAE,OAAO,CAAC,IAAI,CAAC,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC,GAC1E,MAAM,CAAC,IAAI,CAAC,CAAC;AAGf,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,GACvC;IACE,iGAAiG;IACjG,MAAM,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACnC,GACD;IAAE,MAAM,CAAC,EAAE,KAAK,CAAA;CAAE,CAAC;AAEvB,MAAM,WAAW,KAAK,CAAC,IAAI,GAAG,MAAM;IAClC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,OAAO,EAAE,aAAa,CAAC,MAAM,CAAC,CAAC;IACxC,4FAA4F;IAC5F,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzD;;;;;;OAMG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,EACtD,UAAU,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,MAAM,KACZ,OAAO,CAAC,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,CAAC;IAC9B;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,EACxD,UAAU,EAAE,CAAC,EACb,MAAM,CAAC,EAAE,MAAM,KACZ,MAAM,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,SAAS,CAAC;IACjC,uCAAuC;IACvC,QAAQ,CAAC,SAAS,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAC1D"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/intl.d.ts
ADDED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
export type IntlName = 'NumberFormat' | 'DateTimeFormat' | 'PluralRules';
|
|
2
|
+
export type Select = (n: number) => string;
|
|
3
|
+
type Formatter = Intl.NumberFormat | Intl.DateTimeFormat | Select;
|
|
4
|
+
/** The formatter `make` builds for `key`, shared by every runtime. */
|
|
5
|
+
export declare function cached<K extends IntlName, T extends Formatter>(name: K, { key, make }: {
|
|
6
|
+
readonly key: string;
|
|
7
|
+
readonly make: (ctor: (typeof Intl)[K]) => T;
|
|
8
|
+
}): T;
|
|
9
|
+
export declare function selecting(rules: Intl.PluralRules): Select;
|
|
10
|
+
export {};
|
|
11
|
+
//# sourceMappingURL=intl.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"intl.d.ts","sourceRoot":"","sources":["../src/intl.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,QAAQ,GAAG,cAAc,GAAG,gBAAgB,GAAG,aAAa,CAAC;AAczE,MAAM,MAAM,MAAM,GAAG,CAAC,CAAC,EAAE,MAAM,KAAK,MAAM,CAAC;AAC3C,KAAK,SAAS,GAAG,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,cAAc,GAAG,MAAM,CAAC;AAYlE,sEAAsE;AACtE,wBAAgB,MAAM,CAAC,CAAC,SAAS,QAAQ,EAAE,CAAC,SAAS,SAAS,EAC5D,IAAI,EAAE,CAAC,EACP,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;IAAE,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,IAAI,EAAE,CAAC,IAAI,EAAE,CAAC,OAAO,IAAI,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAA;CAAE,GACpF,CAAC,CAoBH;AAQD,wBAAgB,SAAS,CAAC,KAAK,EAAE,IAAI,CAAC,WAAW,GAAG,MAAM,CAGzD"}
|
package/build/intl.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { parlaMessage } from './message.js';
|
|
2
|
+
/** Hermes (React Native) lacks `PluralRules`: name the polyfill, not "not a constructor". */
|
|
3
|
+
function intl(name) {
|
|
4
|
+
const ctor = typeof Intl === 'undefined' ? undefined : Intl[name];
|
|
5
|
+
if (typeof ctor !== 'function') {
|
|
6
|
+
const pkg = `@formatjs/intl-${name.toLowerCase()}`;
|
|
7
|
+
throw new Error(parlaMessage(`Intl.${name} is missing: import a polyfill such as ${pkg} first`));
|
|
8
|
+
}
|
|
9
|
+
return ctor;
|
|
10
|
+
}
|
|
11
|
+
/** Formatters kept per constructor. A catalog's constant options need far fewer. */
|
|
12
|
+
const CACHE_SIZE = 256;
|
|
13
|
+
/** The longest key kept, as options bound to params may hold text of any length. */
|
|
14
|
+
const MAX_KEY = 1024;
|
|
15
|
+
// Shared by every runtime, as a server's instance per request would build its own; by constructor,
|
|
16
|
+
// so a polyfill installed later gets its own.
|
|
17
|
+
const formats = new WeakMap();
|
|
18
|
+
/** The formatter `make` builds for `key`, shared by every runtime. */
|
|
19
|
+
export function cached(name, { key, make }) {
|
|
20
|
+
const ctor = intl(name);
|
|
21
|
+
if (key.length > MAX_KEY) {
|
|
22
|
+
return make(ctor);
|
|
23
|
+
}
|
|
24
|
+
let cache = formats.get(ctor);
|
|
25
|
+
if (!cache) {
|
|
26
|
+
cache = new Map();
|
|
27
|
+
formats.set(ctor, cache);
|
|
28
|
+
}
|
|
29
|
+
let hit = cache.get(key);
|
|
30
|
+
if (!hit) {
|
|
31
|
+
// Options bound to params (`minimumFractionDigits=$d`) make new keys: drop the oldest.
|
|
32
|
+
const [oldest] = cache.keys();
|
|
33
|
+
if (cache.size >= CACHE_SIZE && oldest !== undefined) {
|
|
34
|
+
cache.delete(oldest);
|
|
35
|
+
}
|
|
36
|
+
cache.set(key, (hit = make(ctor)));
|
|
37
|
+
}
|
|
38
|
+
return hit;
|
|
39
|
+
}
|
|
40
|
+
// The first `NumberFormat` of a page costs ~8 ms, and each call 5 to 30 times this.
|
|
41
|
+
const isSmall = (value) =>
|
|
42
|
+
// `1 / value` tells -0, which `Intl` writes as "-0".
|
|
43
|
+
typeof value === 'number' && value < 1000 && value % 1 === 0 && 1 / value > 0;
|
|
44
|
+
// `select` costs 20 times a lookup, and the categories of 0 to 999 are few enough to keep.
|
|
45
|
+
export function selecting(rules) {
|
|
46
|
+
const small = [];
|
|
47
|
+
return (n) => (isSmall(n) ? (small[n] ??= rules.select(n)) : rules.select(n));
|
|
48
|
+
}
|
package/build/match.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
interface Subtags {
|
|
2
|
+
readonly language: string;
|
|
3
|
+
readonly script?: string | undefined;
|
|
4
|
+
readonly region?: string | undefined;
|
|
5
|
+
}
|
|
6
|
+
/** `zh-TW` → `zh-Hant-TW`: the likely script and region, to compare tags that omit them. */
|
|
7
|
+
export declare function maximize(tag: string): Subtags | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Picks the best supported locale from a preference list such as `navigator.languages` or, in
|
|
10
|
+
* React Native, `getLocales().map((l) => l.languageTag)` from `expo-localization`.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchLocale<L extends string>(requested: ReadonlyArray<string>, supported: ReadonlyArray<L>, fallback: L): L;
|
|
13
|
+
export {};
|
|
14
|
+
//# sourceMappingURL=match.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.d.ts","sourceRoot":"","sources":["../src/match.ts"],"names":[],"mappings":"AAAA,UAAU,OAAO;IACf,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;IAC1B,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;IACrC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,SAAS,CAAC;CACtC;AAeD,4FAA4F;AAC5F,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,GAAG,SAAS,CAQzD;AAED;;;GAGG;AACH,wBAAgB,WAAW,CAAC,CAAC,SAAS,MAAM,EAC1C,SAAS,EAAE,aAAa,CAAC,MAAM,CAAC,EAChC,SAAS,EAAE,aAAa,CAAC,CAAC,CAAC,EAC3B,QAAQ,EAAE,CAAC,GACV,CAAC,CA2BH"}
|
package/build/match.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/** Without `Intl.Locale` (Hermes), the tag's own subtags: `en-US` still matches `en`. */
|
|
2
|
+
function subtags(tag) {
|
|
3
|
+
const [language = '', ...rest] = tag.toLowerCase().split('-');
|
|
4
|
+
if (!/^[a-z]{2,8}$/.test(language)) {
|
|
5
|
+
return undefined;
|
|
6
|
+
}
|
|
7
|
+
return {
|
|
8
|
+
language,
|
|
9
|
+
script: rest.find((s) => /^[a-z]{4}$/.test(s)),
|
|
10
|
+
region: rest.find((s) => /^(?:[a-z]{2}|\d{3})$/.test(s)),
|
|
11
|
+
};
|
|
12
|
+
}
|
|
13
|
+
/** `zh-TW` → `zh-Hant-TW`: the likely script and region, to compare tags that omit them. */
|
|
14
|
+
export function maximize(tag) {
|
|
15
|
+
// Android reports `it_IT`, which `Intl.Locale` rejects.
|
|
16
|
+
const bcp47 = tag.replaceAll('_', '-');
|
|
17
|
+
try {
|
|
18
|
+
return typeof Intl.Locale === 'function' ? new Intl.Locale(bcp47).maximize() : subtags(bcp47);
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
return undefined;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Picks the best supported locale from a preference list such as `navigator.languages` or, in
|
|
26
|
+
* React Native, `getLocales().map((l) => l.languageTag)` from `expo-localization`.
|
|
27
|
+
*/
|
|
28
|
+
export function matchLocale(requested, supported, fallback) {
|
|
29
|
+
const candidates = supported.map((tag) => ({ tag, locale: maximize(tag) }));
|
|
30
|
+
for (const req of requested) {
|
|
31
|
+
const exact = supported.find((l) => l.toLowerCase() === req.toLowerCase());
|
|
32
|
+
if (exact !== undefined) {
|
|
33
|
+
return exact;
|
|
34
|
+
}
|
|
35
|
+
const want = maximize(req);
|
|
36
|
+
if (!want) {
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// Same language; then the same script (zh-Hant ≠ zh-Hans) outranks the same region.
|
|
40
|
+
let best;
|
|
41
|
+
for (const { tag, locale } of candidates) {
|
|
42
|
+
if (locale?.language === want.language) {
|
|
43
|
+
const score = (locale.script === want.script ? 2 : 0) + (locale.region === want.region ? 1 : 0);
|
|
44
|
+
if (!best || score > best.score) {
|
|
45
|
+
best = { tag, score };
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
if (best) {
|
|
50
|
+
return best.tag;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return fallback;
|
|
54
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"message.d.ts","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,qFAAqF;AACrF,eAAO,MAAM,YAAY,YAAa,MAAM,KAAG,MAA8B,CAAC"}
|
package/build/message.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import type { Locale } from './catalog.ts';
|
|
2
|
+
import type { MessageRuntime } from './runtime.ts';
|
|
3
|
+
/** A message without params or markup, shared so a catalog of them builds one type. */
|
|
4
|
+
export type Text = () => string;
|
|
5
|
+
/** A compiled chunk: called once per locale with its runtime, it returns the namespace's accessor. */
|
|
6
|
+
export type MessageFactory = (rt: MessageRuntime) => unknown;
|
|
7
|
+
export interface MessageModule {
|
|
8
|
+
default: MessageFactory;
|
|
9
|
+
}
|
|
10
|
+
export type Loader = () => Promise<MessageModule>;
|
|
11
|
+
/**
|
|
12
|
+
* A namespace's messages. A generated kind with markup reads `this['node']`, so one namespace types
|
|
13
|
+
* a React and a string instance differently.
|
|
14
|
+
*/
|
|
15
|
+
export interface NamespaceKind {
|
|
16
|
+
readonly node: unknown;
|
|
17
|
+
readonly messages: unknown;
|
|
18
|
+
}
|
|
19
|
+
declare const kind: unique symbol;
|
|
20
|
+
/**
|
|
21
|
+
* Emitted by `parla build` as `namespaces/<name>.js`: importing it is what makes it loadable. `L`
|
|
22
|
+
* defaults to the app's locales, so `Namespace` is one built for at least those.
|
|
23
|
+
*/
|
|
24
|
+
export interface Namespace<out Name extends string = string, out Kind extends NamespaceKind = NamespaceKind, L extends string = Locale> {
|
|
25
|
+
readonly name: Name;
|
|
26
|
+
/** One chunk loader per locale it was built for. */
|
|
27
|
+
readonly load: {
|
|
28
|
+
readonly [P in L]: Loader;
|
|
29
|
+
};
|
|
30
|
+
/** Types only, never set. */
|
|
31
|
+
readonly [kind]?: Kind;
|
|
32
|
+
}
|
|
33
|
+
type MessagesOf<NS, Node> = NS extends {
|
|
34
|
+
readonly [kind]?: infer K extends NamespaceKind;
|
|
35
|
+
} ? (K & {
|
|
36
|
+
readonly node: Node;
|
|
37
|
+
})['messages'] : never;
|
|
38
|
+
/**
|
|
39
|
+
* Messages keyed by namespace name, `t.checkout.title()`: holding one proves its namespaces loaded.
|
|
40
|
+
* `Node` is invariant because the kind hides it from TypeScript's variance check.
|
|
41
|
+
*/
|
|
42
|
+
export type Translations<NS extends Namespace, in out Node = string> = {
|
|
43
|
+
readonly [N in NS as N['name']]: MessagesOf<N, Node>;
|
|
44
|
+
};
|
|
45
|
+
type IsUnion<T, Each = T> = T extends unknown ? ([Each] extends [T] ? false : true) : never;
|
|
46
|
+
/** The list's namespaces, without an element that may be one of several. */
|
|
47
|
+
type Certain<L extends ReadonlyArray<Namespace>> = {
|
|
48
|
+
readonly [I in keyof L]: IsUnion<L[I]['name']> extends false ? L[I] : never;
|
|
49
|
+
}[number];
|
|
50
|
+
/**
|
|
51
|
+
* The `t` a list loads: only what it is certain to hold. An array of unknown length, or an element
|
|
52
|
+
* such as `flag ? a : b`, loads but adds nothing to it.
|
|
53
|
+
*/
|
|
54
|
+
export type Loaded<L extends ReadonlyArray<Namespace>, Node = string> = L extends unknown ? Translations<number extends L['length'] ? never : Certain<L>, Node> : never;
|
|
55
|
+
export {};
|
|
56
|
+
//# sourceMappingURL=namespace.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"namespace.d.ts","sourceRoot":"","sources":["../src/namespace.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAEnD,uFAAuF;AACvF,MAAM,MAAM,IAAI,GAAG,MAAM,MAAM,CAAC;AAEhC,sGAAsG;AACtG,MAAM,MAAM,cAAc,GAAG,CAAC,EAAE,EAAE,cAAc,KAAK,OAAO,CAAC;AAC7D,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE,cAAc,CAAC;CACzB;AACD,MAAM,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,aAAa,CAAC,CAAC;AAElD;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,OAAO,CAAC;IACvB,QAAQ,CAAC,QAAQ,EAAE,OAAO,CAAC;CAC5B;AAED,OAAO,CAAC,MAAM,IAAI,EAAE,OAAO,MAAM,CAAC;AAElC;;;GAGG;AAGH,MAAM,WAAW,SAAS,CACxB,GAAG,CAAC,IAAI,SAAS,MAAM,GAAG,MAAM,EAChC,GAAG,CAAC,IAAI,SAAS,aAAa,GAAG,aAAa,EAC9C,CAAC,SAAS,MAAM,GAAG,MAAM;IAEzB,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAC;IACpB,oDAAoD;IAEpD,QAAQ,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,CAAC,IAAI,CAAC,GAAG,MAAM;KAAE,CAAC;IAC7C,6BAA6B;IAC7B,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;CACxB;AAED,KAAK,UAAU,CAAC,EAAE,EAAE,IAAI,IAAI,EAAE,SAAS;IAAE,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,MAAM,CAAC,SAAS,aAAa,CAAA;CAAE,GACtF,CAAC,CAAC,GAAG;IAAE,QAAQ,CAAC,IAAI,EAAE,IAAI,CAAA;CAAE,CAAC,CAAC,UAAU,CAAC,GACzC,KAAK,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,YAAY,CAAC,EAAE,SAAS,SAAS,EAAE,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG,MAAM,IAAI;IACrE,QAAQ,EAAE,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC,MAAM,CAAC,GAAG,UAAU,CAAC,CAAC,EAAE,IAAI,CAAC;CACrD,CAAC;AAEF,KAAK,OAAO,CAAC,CAAC,EAAE,IAAI,GAAG,CAAC,IAAI,CAAC,SAAS,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,GAAG,KAAK,GAAG,IAAI,CAAC,GAAG,KAAK,CAAC;AAE5F,4EAA4E;AAC5E,KAAK,OAAO,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,IAAI;IACjD,QAAQ,EAAE,CAAC,IAAI,MAAM,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,SAAS,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK;CAC5E,CAAC,MAAM,CAAC,CAAC;AAEV;;;GAGG;AACH,MAAM,MAAM,MAAM,CAAC,CAAC,SAAS,aAAa,CAAC,SAAS,CAAC,EAAE,IAAI,GAAG,MAAM,IAAI,CAAC,SAAS,OAAO,GACrF,YAAY,CAAC,MAAM,SAAS,CAAC,CAAC,QAAQ,CAAC,GAAG,KAAK,GAAG,OAAO,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,GACnE,KAAK,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/build/parla.d.ts
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Parla, ParlaOptions } from './instance.ts';
|
|
2
|
+
/** Rich text is a `string` unless `wrapRich` says otherwise: every part is then text. */
|
|
3
|
+
export declare function createParla<Node = string>(options: ParlaOptions<Node>): Parla<Node>;
|
|
4
|
+
//# sourceMappingURL=parla.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"parla.d.ts","sourceRoot":"","sources":["../src/parla.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAUzD,yFAAyF;AACzF,wBAAgB,WAAW,CAAC,IAAI,GAAG,MAAM,EAAE,OAAO,EAAE,YAAY,CAAC,IAAI,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,CA8InF"}
|