@puzzle-ui/i18n 0.0.0-stage → 0.14.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/README.md +91 -2
- package/ai/instructions.md +141 -0
- package/ai/manifest.json +10 -0
- package/dist/LICENSE +21 -0
- package/dist/_virtual/_rolldown/runtime.cjs +22 -0
- package/dist/adapters/next.cjs +11 -0
- package/dist/adapters/next.cjs.map +1 -0
- package/dist/adapters/next.d.cts +7 -0
- package/dist/adapters/next.d.ts +7 -0
- package/dist/adapters/next.js +10 -0
- package/dist/adapters/next.js.map +1 -0
- package/dist/adapters/react-router.cjs +13 -0
- package/dist/adapters/react-router.cjs.map +1 -0
- package/dist/adapters/react-router.d.cts +10 -0
- package/dist/adapters/react-router.d.ts +10 -0
- package/dist/adapters/react-router.js +12 -0
- package/dist/adapters/react-router.js.map +1 -0
- package/dist/adapters/request.cjs +67 -0
- package/dist/adapters/request.cjs.map +1 -0
- package/dist/adapters/request.d.cts +16 -0
- package/dist/adapters/request.d.ts +16 -0
- package/dist/adapters/request.js +65 -0
- package/dist/adapters/request.js.map +1 -0
- package/dist/adapters/tanstack.cjs +13 -0
- package/dist/adapters/tanstack.cjs.map +1 -0
- package/dist/adapters/tanstack.d.cts +10 -0
- package/dist/adapters/tanstack.d.ts +10 -0
- package/dist/adapters/tanstack.js +12 -0
- package/dist/adapters/tanstack.js.map +1 -0
- package/dist/ai/index.cjs +205 -0
- package/dist/ai/index.cjs.map +1 -0
- package/dist/ai/index.d.cts +75 -0
- package/dist/ai/index.d.ts +75 -0
- package/dist/ai/index.js +195 -0
- package/dist/ai/index.js.map +1 -0
- package/dist/ai/review.cjs +319 -0
- package/dist/ai/review.cjs.map +1 -0
- package/dist/ai/review.d.cts +91 -0
- package/dist/ai/review.d.ts +91 -0
- package/dist/ai/review.js +315 -0
- package/dist/ai/review.js.map +1 -0
- package/dist/cli/bin.cjs +10 -0
- package/dist/cli/bin.cjs.map +1 -0
- package/dist/cli/bin.d.cts +1 -0
- package/dist/cli/bin.d.ts +1 -0
- package/dist/cli/bin.js +12 -0
- package/dist/cli/bin.js.map +1 -0
- package/dist/cli/index.cjs +310 -0
- package/dist/cli/index.cjs.map +1 -0
- package/dist/cli/index.d.cts +7 -0
- package/dist/cli/index.d.ts +7 -0
- package/dist/cli/index.js +309 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/compiler/index.cjs +218 -0
- package/dist/compiler/index.cjs.map +1 -0
- package/dist/compiler/index.d.cts +18 -0
- package/dist/compiler/index.d.ts +18 -0
- package/dist/compiler/index.js +210 -0
- package/dist/compiler/index.js.map +1 -0
- package/dist/compiler/typescript.cjs +251 -0
- package/dist/compiler/typescript.cjs.map +1 -0
- package/dist/compiler/typescript.d.cts +27 -0
- package/dist/compiler/typescript.d.ts +27 -0
- package/dist/compiler/typescript.js +247 -0
- package/dist/compiler/typescript.js.map +1 -0
- package/dist/compiler/vite.cjs +94 -0
- package/dist/compiler/vite.cjs.map +1 -0
- package/dist/compiler/vite.d.cts +13 -0
- package/dist/compiler/vite.d.ts +13 -0
- package/dist/compiler/vite.js +92 -0
- package/dist/compiler/vite.js.map +1 -0
- package/dist/content/index.cjs +156 -0
- package/dist/content/index.cjs.map +1 -0
- package/dist/content/index.d.cts +75 -0
- package/dist/content/index.d.ts +75 -0
- package/dist/content/index.js +151 -0
- package/dist/content/index.js.map +1 -0
- package/dist/content/sanity.cjs +74 -0
- package/dist/content/sanity.cjs.map +1 -0
- package/dist/content/sanity.d.cts +19 -0
- package/dist/content/sanity.d.ts +19 -0
- package/dist/content/sanity.js +73 -0
- package/dist/content/sanity.js.map +1 -0
- package/dist/devtools/index.cjs +77 -0
- package/dist/devtools/index.cjs.map +1 -0
- package/dist/devtools/index.d.cts +29 -0
- package/dist/devtools/index.d.ts +29 -0
- package/dist/devtools/index.js +75 -0
- package/dist/devtools/index.js.map +1 -0
- package/dist/format.cjs +17 -0
- package/dist/format.cjs.map +1 -0
- package/dist/format.d.cts +9 -0
- package/dist/format.d.ts +9 -0
- package/dist/format.js +13 -0
- package/dist/format.js.map +1 -0
- package/dist/index.cjs +20 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.js +5 -0
- package/dist/locale.cjs +158 -0
- package/dist/locale.cjs.map +1 -0
- package/dist/locale.d.cts +42 -0
- package/dist/locale.d.ts +42 -0
- package/dist/locale.js +155 -0
- package/dist/locale.js.map +1 -0
- package/dist/react/index.cjs +239 -0
- package/dist/react/index.cjs.map +1 -0
- package/dist/react/index.d.cts +105 -0
- package/dist/react/index.d.ts +105 -0
- package/dist/react/index.js +238 -0
- package/dist/react/index.js.map +1 -0
- package/dist/routing/index.cjs +381 -0
- package/dist/routing/index.cjs.map +1 -0
- package/dist/routing/index.d.cts +44 -0
- package/dist/routing/index.d.ts +44 -0
- package/dist/routing/index.js +380 -0
- package/dist/routing/index.js.map +1 -0
- package/dist/runtime.cjs +261 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +74 -0
- package/dist/runtime.d.ts +74 -0
- package/dist/runtime.js +257 -0
- package/dist/runtime.js.map +1 -0
- package/dist/seo/index.cjs +212 -0
- package/dist/seo/index.cjs.map +1 -0
- package/dist/seo/index.d.cts +52 -0
- package/dist/seo/index.d.ts +52 -0
- package/dist/seo/index.js +209 -0
- package/dist/seo/index.js.map +1 -0
- package/dist/seo/origin.cjs +27 -0
- package/dist/seo/origin.cjs.map +1 -0
- package/dist/seo/origin.js +26 -0
- package/dist/seo/origin.js.map +1 -0
- package/dist/seo/sitemap.cjs +74 -0
- package/dist/seo/sitemap.cjs.map +1 -0
- package/dist/seo/sitemap.d.cts +16 -0
- package/dist/seo/sitemap.d.ts +16 -0
- package/dist/seo/sitemap.js +72 -0
- package/dist/seo/sitemap.js.map +1 -0
- package/dist/sources/index.cjs +227 -0
- package/dist/sources/index.cjs.map +1 -0
- package/dist/sources/index.d.cts +41 -0
- package/dist/sources/index.d.ts +41 -0
- package/dist/sources/index.js +222 -0
- package/dist/sources/index.js.map +1 -0
- package/dist/sources/node.cjs +50 -0
- package/dist/sources/node.cjs.map +1 -0
- package/dist/sources/node.d.cts +5 -0
- package/dist/sources/node.d.ts +5 -0
- package/dist/sources/node.js +49 -0
- package/dist/sources/node.js.map +1 -0
- package/package.json +256 -4
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ContentAdapterSource, ContentAdapterSourceOptions, ContentVersion } from "./index.cjs";
|
|
2
|
+
export declare const SANITY_CONTENT_QUERY = "*[\n _type == $documentType &&\n locale == $locale &&\n slug.current == $slug &&\n ($version == null || coalesce(version, _rev, _updatedAt, 1) == $version) &&\n ($preview || (!(_id in path(\"drafts.**\")) && status != \"draft\"))\n] | order(_id in path(\"drafts.**\") desc, status == \"draft\" desc)[0]";
|
|
3
|
+
export interface SanityContentQueryParams extends Record<string, string | number | boolean | null> {
|
|
4
|
+
readonly documentType: string;
|
|
5
|
+
readonly locale: string;
|
|
6
|
+
readonly slug: string;
|
|
7
|
+
readonly version: ContentVersion | null;
|
|
8
|
+
readonly preview: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SanityContentFetchOptions {
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export interface SanityContentClient {
|
|
14
|
+
fetch(query: string, params: SanityContentQueryParams, options?: SanityContentFetchOptions): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface SanityContentSourceOptions extends ContentAdapterSourceOptions {
|
|
17
|
+
readonly documentType?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const createSanityContentSource: <Data = Record<string, unknown>>(client: SanityContentClient, options?: SanityContentSourceOptions) => ContentAdapterSource<Data>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { ContentAdapterSource, ContentAdapterSourceOptions, ContentVersion } from "./index.js";
|
|
2
|
+
export declare const SANITY_CONTENT_QUERY = "*[\n _type == $documentType &&\n locale == $locale &&\n slug.current == $slug &&\n ($version == null || coalesce(version, _rev, _updatedAt, 1) == $version) &&\n ($preview || (!(_id in path(\"drafts.**\")) && status != \"draft\"))\n] | order(_id in path(\"drafts.**\") desc, status == \"draft\" desc)[0]";
|
|
3
|
+
export interface SanityContentQueryParams extends Record<string, string | number | boolean | null> {
|
|
4
|
+
readonly documentType: string;
|
|
5
|
+
readonly locale: string;
|
|
6
|
+
readonly slug: string;
|
|
7
|
+
readonly version: ContentVersion | null;
|
|
8
|
+
readonly preview: boolean;
|
|
9
|
+
}
|
|
10
|
+
export interface SanityContentFetchOptions {
|
|
11
|
+
readonly signal?: AbortSignal;
|
|
12
|
+
}
|
|
13
|
+
export interface SanityContentClient {
|
|
14
|
+
fetch(query: string, params: SanityContentQueryParams, options?: SanityContentFetchOptions): Promise<unknown>;
|
|
15
|
+
}
|
|
16
|
+
export interface SanityContentSourceOptions extends ContentAdapterSourceOptions {
|
|
17
|
+
readonly documentType?: string;
|
|
18
|
+
}
|
|
19
|
+
export declare const createSanityContentSource: <Data = Record<string, unknown>>(client: SanityContentClient, options?: SanityContentSourceOptions) => ContentAdapterSource<Data>;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { createContentSourceAdapter } from "./index.js";
|
|
2
|
+
// src/content/sanity.ts
|
|
3
|
+
const SANITY_CONTENT_QUERY = `*[
|
|
4
|
+
_type == $documentType &&
|
|
5
|
+
locale == $locale &&
|
|
6
|
+
slug.current == $slug &&
|
|
7
|
+
($version == null || coalesce(version, _rev, _updatedAt, 1) == $version) &&
|
|
8
|
+
($preview || (!(_id in path("drafts.**")) && status != "draft"))
|
|
9
|
+
] | order(_id in path("drafts.**") desc, status == "draft" desc)[0]`;
|
|
10
|
+
const SANITY_METADATA_FIELDS = /* @__PURE__ */ new Set([
|
|
11
|
+
"_createdAt",
|
|
12
|
+
"_id",
|
|
13
|
+
"_rev",
|
|
14
|
+
"_type",
|
|
15
|
+
"_updatedAt",
|
|
16
|
+
"content",
|
|
17
|
+
"locale",
|
|
18
|
+
"slug",
|
|
19
|
+
"status",
|
|
20
|
+
"version"
|
|
21
|
+
]);
|
|
22
|
+
const asRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value) ? value : void 0;
|
|
23
|
+
const readVersion = (record) => {
|
|
24
|
+
if (typeof record.version === "string" && record.version.trim().length > 0 || typeof record.version === "number" && Number.isFinite(record.version)) return record.version;
|
|
25
|
+
if (typeof record._rev === "string" && record._rev.trim().length > 0) return record._rev;
|
|
26
|
+
if (typeof record._updatedAt === "string" && record._updatedAt.trim().length > 0) return record._updatedAt;
|
|
27
|
+
return 1;
|
|
28
|
+
};
|
|
29
|
+
const readSlug = (record) => {
|
|
30
|
+
if (typeof record.slug === "string") return record.slug;
|
|
31
|
+
const slug = asRecord(record.slug)?.current;
|
|
32
|
+
return typeof slug === "string" ? slug : void 0;
|
|
33
|
+
};
|
|
34
|
+
const normalizeDocument = (value) => {
|
|
35
|
+
if (value === null || value === void 0) return;
|
|
36
|
+
const record = asRecord(value);
|
|
37
|
+
if (!record) throw new TypeError("Sanity content query must return a document or null.");
|
|
38
|
+
const id = record._id;
|
|
39
|
+
const rawLocale = record.locale;
|
|
40
|
+
const slug = readSlug(record);
|
|
41
|
+
const locale = typeof rawLocale === "string" ? Intl.getCanonicalLocales(rawLocale)[0] : void 0;
|
|
42
|
+
if (typeof id !== "string" || !id || !locale || !slug) throw new TypeError("Sanity content documents require _id, locale, and slug.current fields.");
|
|
43
|
+
const status = id.startsWith("drafts.") || record.status === "draft" ? "draft" : "published";
|
|
44
|
+
const content = Object.prototype.hasOwnProperty.call(record, "content") ? record.content : Object.fromEntries(Object.entries(record).filter(([field]) => !SANITY_METADATA_FIELDS.has(field)));
|
|
45
|
+
return {
|
|
46
|
+
id,
|
|
47
|
+
locale,
|
|
48
|
+
slug,
|
|
49
|
+
status,
|
|
50
|
+
version: readVersion(record),
|
|
51
|
+
content
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
const createSanityContentSource = (client, options = {}) => {
|
|
55
|
+
const documentType = options.documentType ?? "content";
|
|
56
|
+
if (!documentType.trim() || /[\u0000-\u001f\u007f]/.test(documentType)) throw new Error("Sanity documentType must be a non-empty string.");
|
|
57
|
+
const adapter = { async load(query, { signal }) {
|
|
58
|
+
const params = {
|
|
59
|
+
documentType,
|
|
60
|
+
locale: query.locale,
|
|
61
|
+
slug: query.slug,
|
|
62
|
+
version: query.version ?? null,
|
|
63
|
+
preview: query.preview
|
|
64
|
+
};
|
|
65
|
+
const result = signal ? await client.fetch(SANITY_CONTENT_QUERY, params, { signal }) : await client.fetch(SANITY_CONTENT_QUERY, params);
|
|
66
|
+
return normalizeDocument(result);
|
|
67
|
+
} };
|
|
68
|
+
const { documentType: _documentType, ...adapterOptions } = options;
|
|
69
|
+
return createContentSourceAdapter(adapter, adapterOptions);
|
|
70
|
+
};
|
|
71
|
+
export { SANITY_CONTENT_QUERY, createSanityContentSource };
|
|
72
|
+
|
|
73
|
+
//# sourceMappingURL=sanity.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sanity.js","names":[],"sources":["../../src/content/sanity.ts"],"sourcesContent":["import {\n createContentSourceAdapter,\n type ContentAdapter,\n type ContentAdapterSource,\n type ContentAdapterSourceOptions,\n type ContentVersion,\n type LocalizedContentDocument,\n} from \"./index\";\n\nexport const SANITY_CONTENT_QUERY = `*[\n _type == $documentType &&\n locale == $locale &&\n slug.current == $slug &&\n ($version == null || coalesce(version, _rev, _updatedAt, 1) == $version) &&\n ($preview || (!(_id in path(\"drafts.**\")) && status != \"draft\"))\n] | order(_id in path(\"drafts.**\") desc, status == \"draft\" desc)[0]`;\n\nexport interface SanityContentQueryParams\n extends Record<string, string | number | boolean | null> {\n readonly documentType: string;\n readonly locale: string;\n readonly slug: string;\n readonly version: ContentVersion | null;\n readonly preview: boolean;\n}\n\nexport interface SanityContentFetchOptions {\n readonly signal?: AbortSignal;\n}\n\nexport interface SanityContentClient {\n fetch(\n query: string,\n params: SanityContentQueryParams,\n options?: SanityContentFetchOptions,\n ): Promise<unknown>;\n}\n\nexport interface SanityContentSourceOptions\n extends ContentAdapterSourceOptions {\n readonly documentType?: string;\n}\n\nconst SANITY_METADATA_FIELDS = new Set([\n \"_createdAt\",\n \"_id\",\n \"_rev\",\n \"_type\",\n \"_updatedAt\",\n \"content\",\n \"locale\",\n \"slug\",\n \"status\",\n \"version\",\n]);\n\nconst asRecord = (value: unknown): Record<string, unknown> | undefined =>\n typeof value === \"object\" && value !== null && !Array.isArray(value)\n ? (value as Record<string, unknown>)\n : undefined;\n\nconst readVersion = (record: Record<string, unknown>): ContentVersion => {\n if (\n (typeof record.version === \"string\" && record.version.trim().length > 0) ||\n (typeof record.version === \"number\" && Number.isFinite(record.version))\n ) {\n return record.version;\n }\n\n if (typeof record._rev === \"string\" && record._rev.trim().length > 0) {\n return record._rev;\n }\n\n if (\n typeof record._updatedAt === \"string\" &&\n record._updatedAt.trim().length > 0\n ) {\n return record._updatedAt;\n }\n\n return 1;\n};\n\nconst readSlug = (record: Record<string, unknown>): string | undefined => {\n if (typeof record.slug === \"string\") {\n return record.slug;\n }\n\n const slug = asRecord(record.slug)?.current;\n return typeof slug === \"string\" ? slug : undefined;\n};\n\nconst normalizeDocument = <Data>(\n value: unknown,\n): LocalizedContentDocument<Data> | undefined => {\n if (value === null || value === undefined) {\n return undefined;\n }\n\n const record = asRecord(value);\n if (!record) {\n throw new TypeError(\"Sanity content query must return a document or null.\");\n }\n\n const id = record._id;\n const rawLocale = record.locale;\n const slug = readSlug(record);\n const locale =\n typeof rawLocale === \"string\"\n ? Intl.getCanonicalLocales(rawLocale)[0]\n : undefined;\n\n if (typeof id !== \"string\" || !id || !locale || !slug) {\n throw new TypeError(\n \"Sanity content documents require _id, locale, and slug.current fields.\",\n );\n }\n\n const status: LocalizedContentDocument<Data>[\"status\"] =\n id.startsWith(\"drafts.\") || record.status === \"draft\"\n ? \"draft\"\n : \"published\";\n const content = Object.prototype.hasOwnProperty.call(record, \"content\")\n ? record.content\n : Object.fromEntries(\n Object.entries(record).filter(\n ([field]) => !SANITY_METADATA_FIELDS.has(field),\n ),\n );\n\n return {\n id,\n locale,\n slug,\n status,\n version: readVersion(record),\n content: content as Data,\n };\n};\n\nexport const createSanityContentSource = <Data = Record<string, unknown>>(\n client: SanityContentClient,\n options: SanityContentSourceOptions = {},\n): ContentAdapterSource<Data> => {\n const documentType = options.documentType ?? \"content\";\n\n if (!documentType.trim() || /[\\u0000-\\u001f\\u007f]/.test(documentType)) {\n throw new Error(\"Sanity documentType must be a non-empty string.\");\n }\n\n const adapter: ContentAdapter<Data> = {\n async load(query, { signal }) {\n const params: SanityContentQueryParams = {\n documentType,\n locale: query.locale,\n slug: query.slug,\n version: query.version ?? null,\n preview: query.preview,\n };\n const result = signal\n ? await client.fetch(SANITY_CONTENT_QUERY, params, { signal })\n : await client.fetch(SANITY_CONTENT_QUERY, params);\n\n return normalizeDocument<Data>(result);\n },\n };\n\n const { documentType: _documentType, ...adapterOptions } = options;\n return createContentSourceAdapter(adapter, adapterOptions);\n};\n"],"mappings":";;AASA,MAAa,uBAAuB;;;;;;;AAkCpC,MAAM,yCAAyB,IAAI,IAAI;CACrC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;AAED,MAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK,IAC9D,QACD,KAAA;AAEN,MAAM,eAAe,WAAoD;CACvE,IACG,OAAO,OAAO,YAAY,YAAY,OAAO,QAAQ,KAAK,CAAC,CAAC,SAAS,KACrE,OAAO,OAAO,YAAY,YAAY,OAAO,SAAS,OAAO,OAAO,GAErE,OAAO,OAAO;CAGhB,IAAI,OAAO,OAAO,SAAS,YAAY,OAAO,KAAK,KAAK,CAAC,CAAC,SAAS,GACjE,OAAO,OAAO;CAGhB,IACE,OAAO,OAAO,eAAe,YAC7B,OAAO,WAAW,KAAK,CAAC,CAAC,SAAS,GAElC,OAAO,OAAO;CAGhB,OAAO;AACT;AAEA,MAAM,YAAY,WAAwD;CACxE,IAAI,OAAO,OAAO,SAAS,UACzB,OAAO,OAAO;CAGhB,MAAM,OAAO,SAAS,OAAO,IAAI,CAAC,EAAE;CACpC,OAAO,OAAO,SAAS,WAAW,OAAO,KAAA;AAC3C;AAEA,MAAM,qBACJ,UAC+C;CAC/C,IAAI,UAAU,QAAQ,UAAU,KAAA,GAC9B;CAGF,MAAM,SAAS,SAAS,KAAK;CAC7B,IAAI,CAAC,QACH,MAAM,IAAI,UAAU,sDAAsD;CAG5E,MAAM,KAAK,OAAO;CAClB,MAAM,YAAY,OAAO;CACzB,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SACJ,OAAO,cAAc,WACjB,KAAK,oBAAoB,SAAS,CAAC,CAAC,KACpC,KAAA;CAEN,IAAI,OAAO,OAAO,YAAY,CAAC,MAAM,CAAC,UAAU,CAAC,MAC/C,MAAM,IAAI,UACR,wEACF;CAGF,MAAM,SACJ,GAAG,WAAW,SAAS,KAAK,OAAO,WAAW,UAC1C,UACA;CACN,MAAM,UAAU,OAAO,UAAU,eAAe,KAAK,QAAQ,SAAS,IAClE,OAAO,UACP,OAAO,YACL,OAAO,QAAQ,MAAM,CAAC,CAAC,QACpB,CAAC,WAAW,CAAC,uBAAuB,IAAI,KAAK,CAChD,CACF;CAEJ,OAAO;EACL;EACA;EACA;EACA;EACA,SAAS,YAAY,MAAM;EAClB;CACX;AACF;AAEA,MAAa,6BACX,QACA,UAAsC,CAAC,MACR;CAC/B,MAAM,eAAe,QAAQ,gBAAgB;CAE7C,IAAI,CAAC,aAAa,KAAK,KAAK,wBAAwB,KAAK,YAAY,GACnE,MAAM,IAAI,MAAM,iDAAiD;CAGnE,MAAM,UAAgC,EACpC,MAAM,KAAK,OAAO,EAAE,UAAU;EAC5B,MAAM,SAAmC;GACvC;GACA,QAAQ,MAAM;GACd,MAAM,MAAM;GACZ,SAAS,MAAM,WAAW;GAC1B,SAAS,MAAM;EACjB;EACA,MAAM,SAAS,SACX,MAAM,OAAO,MAAM,sBAAsB,QAAQ,EAAE,OAAO,CAAC,IAC3D,MAAM,OAAO,MAAM,sBAAsB,MAAM;EAEnD,OAAO,kBAAwB,MAAM;CACvC,EACF;CAEA,MAAM,EAAE,cAAc,eAAe,GAAG,mBAAmB;CAC3D,OAAO,2BAA2B,SAAS,cAAc;AAC3D"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
// src/devtools/index.tsx
|
|
6
|
+
const createI18nDiagnostics = (options = {}) => {
|
|
7
|
+
const maxEvents = options.maxEvents ?? 200;
|
|
8
|
+
if (!Number.isInteger(maxEvents) || maxEvents < 1) throw new Error("maxEvents must be a positive integer.");
|
|
9
|
+
const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
10
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
11
|
+
let nextId = 1;
|
|
12
|
+
let snapshot = Object.freeze([]);
|
|
13
|
+
const notify = () => {
|
|
14
|
+
listeners.forEach((listener) => listener());
|
|
15
|
+
};
|
|
16
|
+
return {
|
|
17
|
+
record(event) {
|
|
18
|
+
const record = Object.freeze({
|
|
19
|
+
...event,
|
|
20
|
+
id: nextId,
|
|
21
|
+
timestamp: clock().toISOString()
|
|
22
|
+
});
|
|
23
|
+
nextId += 1;
|
|
24
|
+
snapshot = Object.freeze([...snapshot, record].slice(-maxEvents));
|
|
25
|
+
notify();
|
|
26
|
+
},
|
|
27
|
+
getSnapshot: () => snapshot,
|
|
28
|
+
subscribe(listener) {
|
|
29
|
+
listeners.add(listener);
|
|
30
|
+
return () => listeners.delete(listener);
|
|
31
|
+
},
|
|
32
|
+
clear() {
|
|
33
|
+
if (snapshot.length === 0) return;
|
|
34
|
+
snapshot = Object.freeze([]);
|
|
35
|
+
notify();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
const describeEvent = (event) => {
|
|
40
|
+
switch (event.type) {
|
|
41
|
+
case "missing-key": return `Missing key "${event.key}" for ${event.locale}`;
|
|
42
|
+
case "fallback": return `"${event.key}" fell back from ${event.requestedLocale} to ${event.resolvedLocale}`;
|
|
43
|
+
case "namespace-load": return `Namespace "${event.namespace}" ${event.status} for ${event.locale}`;
|
|
44
|
+
case "route": return `Route ${event.status} for ${event.locale ?? "unknown locale"} at ${event.pathname}${event.routeId ? ` (${event.routeId})` : ""}`;
|
|
45
|
+
}
|
|
46
|
+
};
|
|
47
|
+
const I18nDevTools = ({ diagnostics, title = "i18n diagnostics" }) => {
|
|
48
|
+
const events = (0, react.useSyncExternalStore)(diagnostics.subscribe, diagnostics.getSnapshot, diagnostics.getSnapshot);
|
|
49
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("details", { children: [
|
|
50
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsxs)("summary", { children: [
|
|
51
|
+
title,
|
|
52
|
+
" (",
|
|
53
|
+
events.length,
|
|
54
|
+
")"
|
|
55
|
+
] }),
|
|
56
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("button", {
|
|
57
|
+
type: "button",
|
|
58
|
+
onClick: diagnostics.clear,
|
|
59
|
+
children: "Clear"
|
|
60
|
+
}),
|
|
61
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("ol", {
|
|
62
|
+
"aria-label": "Internationalization diagnostic events",
|
|
63
|
+
children: events.map((event) => /* @__PURE__ */ (0, react_jsx_runtime.jsxs)("li", { children: [
|
|
64
|
+
/* @__PURE__ */ (0, react_jsx_runtime.jsx)("time", {
|
|
65
|
+
dateTime: event.timestamp,
|
|
66
|
+
children: event.timestamp
|
|
67
|
+
}),
|
|
68
|
+
" ",
|
|
69
|
+
describeEvent(event)
|
|
70
|
+
] }, event.id))
|
|
71
|
+
})
|
|
72
|
+
] });
|
|
73
|
+
};
|
|
74
|
+
exports.I18nDevTools = I18nDevTools;
|
|
75
|
+
exports.createI18nDiagnostics = createI18nDiagnostics;
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useSyncExternalStore"],"sources":["../../src/devtools/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\nimport type { I18nRuntimeEvent } from \"../runtime\";\n\nexport interface I18nRouteDiagnosticEvent {\n type: \"route\";\n pathname: string;\n status: \"matched\" | \"redirected\" | \"unmatched\";\n locale?: string;\n routeId?: string;\n}\n\nexport type I18nDiagnosticEvent = I18nRuntimeEvent;\n\nexport type I18nDiagnosticRecord = I18nDiagnosticEvent & {\n id: number;\n timestamp: string;\n};\n\nexport interface I18nDiagnosticsStore {\n record(event: I18nDiagnosticEvent): void;\n getSnapshot(): readonly I18nDiagnosticRecord[];\n subscribe(listener: () => void): () => void;\n clear(): void;\n}\n\nexport interface CreateI18nDiagnosticsOptions {\n maxEvents?: number;\n clock?: () => Date;\n}\n\nexport const createI18nDiagnostics = (\n options: CreateI18nDiagnosticsOptions = {},\n): I18nDiagnosticsStore => {\n const maxEvents = options.maxEvents ?? 200;\n\n if (!Number.isInteger(maxEvents) || maxEvents < 1) {\n throw new Error(\"maxEvents must be a positive integer.\");\n }\n\n const clock = options.clock ?? (() => new Date());\n const listeners = new Set<() => void>();\n let nextId = 1;\n let snapshot: readonly I18nDiagnosticRecord[] = Object.freeze([]);\n\n const notify = (): void => {\n listeners.forEach((listener) => listener());\n };\n\n return {\n record(event) {\n const record = Object.freeze({\n ...event,\n id: nextId,\n timestamp: clock().toISOString(),\n }) as I18nDiagnosticRecord;\n nextId += 1;\n snapshot = Object.freeze([...snapshot, record].slice(-maxEvents));\n notify();\n },\n\n getSnapshot: () => snapshot,\n\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n\n clear() {\n if (snapshot.length === 0) {\n return;\n }\n\n snapshot = Object.freeze([]);\n notify();\n },\n };\n};\n\nexport interface I18nDevToolsProps {\n diagnostics: I18nDiagnosticsStore;\n title?: string;\n}\n\nconst describeEvent = (event: I18nDiagnosticEvent): string => {\n switch (event.type) {\n case \"missing-key\":\n return `Missing key \"${event.key}\" for ${event.locale}`;\n case \"fallback\":\n return `\"${event.key}\" fell back from ${event.requestedLocale} to ${event.resolvedLocale}`;\n case \"namespace-load\":\n return `Namespace \"${event.namespace}\" ${event.status} for ${event.locale}`;\n case \"route\":\n return `Route ${event.status} for ${event.locale ?? \"unknown locale\"} at ${event.pathname}${event.routeId ? ` (${event.routeId})` : \"\"}`;\n }\n};\n\nexport const I18nDevTools = ({\n diagnostics,\n title = \"i18n diagnostics\",\n}: I18nDevToolsProps) => {\n const events = useSyncExternalStore(\n diagnostics.subscribe,\n diagnostics.getSnapshot,\n diagnostics.getSnapshot,\n );\n\n return (\n <details>\n <summary>\n {title} ({events.length})\n </summary>\n <button type=\"button\" onClick={diagnostics.clear}>\n Clear\n </button>\n <ol aria-label=\"Internationalization diagnostic events\">\n {events.map((event) => (\n <li key={event.id}>\n <time dateTime={event.timestamp}>{event.timestamp}</time>{\" \"}\n {describeEvent(event)}\n </li>\n ))}\n </ol>\n </details>\n );\n};\n"],"mappings":";;;;;AAiCA,MAAa,yBACX,UAAwC,CAAC,MAChB;CACzB,MAAM,YAAY,QAAQ,aAAa;CAEvC,IAAI,CAAC,OAAO,UAAU,SAAS,KAAK,YAAY,GAC9C,MAAM,IAAI,MAAM,uCAAuC;CAGzD,MAAM,QAAQ,QAAQ,gCAAgB,IAAI,KAAK;CAC/C,MAAM,4BAAY,IAAI,IAAgB;CACtC,IAAI,SAAS;CACb,IAAI,WAA4C,OAAO,OAAO,CAAC,CAAC;CAEhE,MAAM,eAAqB;EACzB,UAAU,SAAS,aAAa,SAAS,CAAC;CAC5C;CAEA,OAAO;EACL,OAAO,OAAO;GACZ,MAAM,SAAS,OAAO,OAAO;IAC3B,GAAG;IACH,IAAI;IACJ,WAAW,MAAM,CAAC,CAAC,YAAY;GACjC,CAAC;GACD,UAAU;GACV,WAAW,OAAO,OAAO,CAAC,GAAG,UAAU,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;GAChE,OAAO;EACT;EAEA,mBAAmB;EAEnB,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa,UAAU,OAAO,QAAQ;EACxC;EAEA,QAAQ;GACN,IAAI,SAAS,WAAW,GACtB;GAGF,WAAW,OAAO,OAAO,CAAC,CAAC;GAC3B,OAAO;EACT;CACF;AACF;AAOA,MAAM,iBAAiB,UAAuC;CAC5D,QAAQ,MAAM,MAAd;EACE,KAAK,eACH,OAAO,gBAAgB,MAAM,IAAI,QAAQ,MAAM;EACjD,KAAK,YACH,OAAO,IAAI,MAAM,IAAI,mBAAmB,MAAM,gBAAgB,MAAM,MAAM;EAC5E,KAAK,kBACH,OAAO,cAAc,MAAM,UAAU,IAAI,MAAM,OAAO,OAAO,MAAM;EACrE,KAAK,SACH,OAAO,SAAS,MAAM,OAAO,OAAO,MAAM,UAAU,iBAAiB,MAAM,MAAM,WAAW,MAAM,UAAU,KAAK,MAAM,QAAQ,KAAK;CACxI;AACF;AAEA,MAAa,gBAAgB,EAC3B,aACA,QAAQ,yBACe;CACvB,MAAM,UAAA,GAASA,MAAAA,qBAAAA,CACb,YAAY,WACZ,YAAY,aACZ,YAAY,WACd;CAEA,OACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,WAAD,EAAA,UAAA;EACE,iBAAA,GAAA,kBAAA,KAAA,CAAC,WAAD,EAAA,UAAA;GACG;GAAM;GAAG,OAAO;GAAO;EACjB,EAAA,CAAA;EACT,iBAAA,GAAA,kBAAA,IAAA,CAAC,UAAD;GAAQ,MAAK;GAAS,SAAS,YAAY;GAAO,UAAA;EAE1C,CAAA;EACR,iBAAA,GAAA,kBAAA,IAAA,CAAC,MAAD;GAAI,cAAW;GACZ,UAAA,OAAO,KAAK,UACX,iBAAA,GAAA,kBAAA,KAAA,CAAC,MAAD,EAAA,UAAA;IACE,iBAAA,GAAA,kBAAA,IAAA,CAAC,QAAD;KAAM,UAAU,MAAM;KAAY,UAAA,MAAM;IAAgB,CAAA;IAAE;IACzD,cAAc,KAAK;GAClB,EAAA,GAHK,MAAM,EAGX,CACL;EACC,CAAA;CACG,EAAA,CAAA;AAEb"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { I18nRuntimeEvent } from "../runtime.cjs";
|
|
2
|
+
export interface I18nRouteDiagnosticEvent {
|
|
3
|
+
type: "route";
|
|
4
|
+
pathname: string;
|
|
5
|
+
status: "matched" | "redirected" | "unmatched";
|
|
6
|
+
locale?: string;
|
|
7
|
+
routeId?: string;
|
|
8
|
+
}
|
|
9
|
+
export type I18nDiagnosticEvent = I18nRuntimeEvent;
|
|
10
|
+
export type I18nDiagnosticRecord = I18nDiagnosticEvent & {
|
|
11
|
+
id: number;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
};
|
|
14
|
+
export interface I18nDiagnosticsStore {
|
|
15
|
+
record(event: I18nDiagnosticEvent): void;
|
|
16
|
+
getSnapshot(): readonly I18nDiagnosticRecord[];
|
|
17
|
+
subscribe(listener: () => void): () => void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateI18nDiagnosticsOptions {
|
|
21
|
+
maxEvents?: number;
|
|
22
|
+
clock?: () => Date;
|
|
23
|
+
}
|
|
24
|
+
export declare const createI18nDiagnostics: (options?: CreateI18nDiagnosticsOptions) => I18nDiagnosticsStore;
|
|
25
|
+
export interface I18nDevToolsProps {
|
|
26
|
+
diagnostics: I18nDiagnosticsStore;
|
|
27
|
+
title?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const I18nDevTools: ({ diagnostics, title }: I18nDevToolsProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { I18nRuntimeEvent } from "../runtime.js";
|
|
2
|
+
export interface I18nRouteDiagnosticEvent {
|
|
3
|
+
type: "route";
|
|
4
|
+
pathname: string;
|
|
5
|
+
status: "matched" | "redirected" | "unmatched";
|
|
6
|
+
locale?: string;
|
|
7
|
+
routeId?: string;
|
|
8
|
+
}
|
|
9
|
+
export type I18nDiagnosticEvent = I18nRuntimeEvent;
|
|
10
|
+
export type I18nDiagnosticRecord = I18nDiagnosticEvent & {
|
|
11
|
+
id: number;
|
|
12
|
+
timestamp: string;
|
|
13
|
+
};
|
|
14
|
+
export interface I18nDiagnosticsStore {
|
|
15
|
+
record(event: I18nDiagnosticEvent): void;
|
|
16
|
+
getSnapshot(): readonly I18nDiagnosticRecord[];
|
|
17
|
+
subscribe(listener: () => void): () => void;
|
|
18
|
+
clear(): void;
|
|
19
|
+
}
|
|
20
|
+
export interface CreateI18nDiagnosticsOptions {
|
|
21
|
+
maxEvents?: number;
|
|
22
|
+
clock?: () => Date;
|
|
23
|
+
}
|
|
24
|
+
export declare const createI18nDiagnostics: (options?: CreateI18nDiagnosticsOptions) => I18nDiagnosticsStore;
|
|
25
|
+
export interface I18nDevToolsProps {
|
|
26
|
+
diagnostics: I18nDiagnosticsStore;
|
|
27
|
+
title?: string;
|
|
28
|
+
}
|
|
29
|
+
export declare const I18nDevTools: ({ diagnostics, title }: I18nDevToolsProps) => import("react").JSX.Element;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import { useSyncExternalStore } from "react";
|
|
3
|
+
import { jsx, jsxs } from "react/jsx-runtime";
|
|
4
|
+
// src/devtools/index.tsx
|
|
5
|
+
const createI18nDiagnostics = (options = {}) => {
|
|
6
|
+
const maxEvents = options.maxEvents ?? 200;
|
|
7
|
+
if (!Number.isInteger(maxEvents) || maxEvents < 1) throw new Error("maxEvents must be a positive integer.");
|
|
8
|
+
const clock = options.clock ?? (() => /* @__PURE__ */ new Date());
|
|
9
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
10
|
+
let nextId = 1;
|
|
11
|
+
let snapshot = Object.freeze([]);
|
|
12
|
+
const notify = () => {
|
|
13
|
+
listeners.forEach((listener) => listener());
|
|
14
|
+
};
|
|
15
|
+
return {
|
|
16
|
+
record(event) {
|
|
17
|
+
const record = Object.freeze({
|
|
18
|
+
...event,
|
|
19
|
+
id: nextId,
|
|
20
|
+
timestamp: clock().toISOString()
|
|
21
|
+
});
|
|
22
|
+
nextId += 1;
|
|
23
|
+
snapshot = Object.freeze([...snapshot, record].slice(-maxEvents));
|
|
24
|
+
notify();
|
|
25
|
+
},
|
|
26
|
+
getSnapshot: () => snapshot,
|
|
27
|
+
subscribe(listener) {
|
|
28
|
+
listeners.add(listener);
|
|
29
|
+
return () => listeners.delete(listener);
|
|
30
|
+
},
|
|
31
|
+
clear() {
|
|
32
|
+
if (snapshot.length === 0) return;
|
|
33
|
+
snapshot = Object.freeze([]);
|
|
34
|
+
notify();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
const describeEvent = (event) => {
|
|
39
|
+
switch (event.type) {
|
|
40
|
+
case "missing-key": return `Missing key "${event.key}" for ${event.locale}`;
|
|
41
|
+
case "fallback": return `"${event.key}" fell back from ${event.requestedLocale} to ${event.resolvedLocale}`;
|
|
42
|
+
case "namespace-load": return `Namespace "${event.namespace}" ${event.status} for ${event.locale}`;
|
|
43
|
+
case "route": return `Route ${event.status} for ${event.locale ?? "unknown locale"} at ${event.pathname}${event.routeId ? ` (${event.routeId})` : ""}`;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
const I18nDevTools = ({ diagnostics, title = "i18n diagnostics" }) => {
|
|
47
|
+
const events = useSyncExternalStore(diagnostics.subscribe, diagnostics.getSnapshot, diagnostics.getSnapshot);
|
|
48
|
+
return /* @__PURE__ */ jsxs("details", { children: [
|
|
49
|
+
/* @__PURE__ */ jsxs("summary", { children: [
|
|
50
|
+
title,
|
|
51
|
+
" (",
|
|
52
|
+
events.length,
|
|
53
|
+
")"
|
|
54
|
+
] }),
|
|
55
|
+
/* @__PURE__ */ jsx("button", {
|
|
56
|
+
type: "button",
|
|
57
|
+
onClick: diagnostics.clear,
|
|
58
|
+
children: "Clear"
|
|
59
|
+
}),
|
|
60
|
+
/* @__PURE__ */ jsx("ol", {
|
|
61
|
+
"aria-label": "Internationalization diagnostic events",
|
|
62
|
+
children: events.map((event) => /* @__PURE__ */ jsxs("li", { children: [
|
|
63
|
+
/* @__PURE__ */ jsx("time", {
|
|
64
|
+
dateTime: event.timestamp,
|
|
65
|
+
children: event.timestamp
|
|
66
|
+
}),
|
|
67
|
+
" ",
|
|
68
|
+
describeEvent(event)
|
|
69
|
+
] }, event.id))
|
|
70
|
+
})
|
|
71
|
+
] });
|
|
72
|
+
};
|
|
73
|
+
export { I18nDevTools, createI18nDiagnostics };
|
|
74
|
+
|
|
75
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../../src/devtools/index.tsx"],"sourcesContent":["\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\nimport type { I18nRuntimeEvent } from \"../runtime\";\n\nexport interface I18nRouteDiagnosticEvent {\n type: \"route\";\n pathname: string;\n status: \"matched\" | \"redirected\" | \"unmatched\";\n locale?: string;\n routeId?: string;\n}\n\nexport type I18nDiagnosticEvent = I18nRuntimeEvent;\n\nexport type I18nDiagnosticRecord = I18nDiagnosticEvent & {\n id: number;\n timestamp: string;\n};\n\nexport interface I18nDiagnosticsStore {\n record(event: I18nDiagnosticEvent): void;\n getSnapshot(): readonly I18nDiagnosticRecord[];\n subscribe(listener: () => void): () => void;\n clear(): void;\n}\n\nexport interface CreateI18nDiagnosticsOptions {\n maxEvents?: number;\n clock?: () => Date;\n}\n\nexport const createI18nDiagnostics = (\n options: CreateI18nDiagnosticsOptions = {},\n): I18nDiagnosticsStore => {\n const maxEvents = options.maxEvents ?? 200;\n\n if (!Number.isInteger(maxEvents) || maxEvents < 1) {\n throw new Error(\"maxEvents must be a positive integer.\");\n }\n\n const clock = options.clock ?? (() => new Date());\n const listeners = new Set<() => void>();\n let nextId = 1;\n let snapshot: readonly I18nDiagnosticRecord[] = Object.freeze([]);\n\n const notify = (): void => {\n listeners.forEach((listener) => listener());\n };\n\n return {\n record(event) {\n const record = Object.freeze({\n ...event,\n id: nextId,\n timestamp: clock().toISOString(),\n }) as I18nDiagnosticRecord;\n nextId += 1;\n snapshot = Object.freeze([...snapshot, record].slice(-maxEvents));\n notify();\n },\n\n getSnapshot: () => snapshot,\n\n subscribe(listener) {\n listeners.add(listener);\n return () => listeners.delete(listener);\n },\n\n clear() {\n if (snapshot.length === 0) {\n return;\n }\n\n snapshot = Object.freeze([]);\n notify();\n },\n };\n};\n\nexport interface I18nDevToolsProps {\n diagnostics: I18nDiagnosticsStore;\n title?: string;\n}\n\nconst describeEvent = (event: I18nDiagnosticEvent): string => {\n switch (event.type) {\n case \"missing-key\":\n return `Missing key \"${event.key}\" for ${event.locale}`;\n case \"fallback\":\n return `\"${event.key}\" fell back from ${event.requestedLocale} to ${event.resolvedLocale}`;\n case \"namespace-load\":\n return `Namespace \"${event.namespace}\" ${event.status} for ${event.locale}`;\n case \"route\":\n return `Route ${event.status} for ${event.locale ?? \"unknown locale\"} at ${event.pathname}${event.routeId ? ` (${event.routeId})` : \"\"}`;\n }\n};\n\nexport const I18nDevTools = ({\n diagnostics,\n title = \"i18n diagnostics\",\n}: I18nDevToolsProps) => {\n const events = useSyncExternalStore(\n diagnostics.subscribe,\n diagnostics.getSnapshot,\n diagnostics.getSnapshot,\n );\n\n return (\n <details>\n <summary>\n {title} ({events.length})\n </summary>\n <button type=\"button\" onClick={diagnostics.clear}>\n Clear\n </button>\n <ol aria-label=\"Internationalization diagnostic events\">\n {events.map((event) => (\n <li key={event.id}>\n <time dateTime={event.timestamp}>{event.timestamp}</time>{\" \"}\n {describeEvent(event)}\n </li>\n ))}\n </ol>\n </details>\n );\n};\n"],"mappings":";;;;AAiCA,MAAa,yBACX,UAAwC,CAAC,MAChB;CACzB,MAAM,YAAY,QAAQ,aAAa;CAEvC,IAAI,CAAC,OAAO,UAAU,SAAS,KAAK,YAAY,GAC9C,MAAM,IAAI,MAAM,uCAAuC;CAGzD,MAAM,QAAQ,QAAQ,gCAAgB,IAAI,KAAK;CAC/C,MAAM,4BAAY,IAAI,IAAgB;CACtC,IAAI,SAAS;CACb,IAAI,WAA4C,OAAO,OAAO,CAAC,CAAC;CAEhE,MAAM,eAAqB;EACzB,UAAU,SAAS,aAAa,SAAS,CAAC;CAC5C;CAEA,OAAO;EACL,OAAO,OAAO;GACZ,MAAM,SAAS,OAAO,OAAO;IAC3B,GAAG;IACH,IAAI;IACJ,WAAW,MAAM,CAAC,CAAC,YAAY;GACjC,CAAC;GACD,UAAU;GACV,WAAW,OAAO,OAAO,CAAC,GAAG,UAAU,MAAM,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC;GAChE,OAAO;EACT;EAEA,mBAAmB;EAEnB,UAAU,UAAU;GAClB,UAAU,IAAI,QAAQ;GACtB,aAAa,UAAU,OAAO,QAAQ;EACxC;EAEA,QAAQ;GACN,IAAI,SAAS,WAAW,GACtB;GAGF,WAAW,OAAO,OAAO,CAAC,CAAC;GAC3B,OAAO;EACT;CACF;AACF;AAOA,MAAM,iBAAiB,UAAuC;CAC5D,QAAQ,MAAM,MAAd;EACE,KAAK,eACH,OAAO,gBAAgB,MAAM,IAAI,QAAQ,MAAM;EACjD,KAAK,YACH,OAAO,IAAI,MAAM,IAAI,mBAAmB,MAAM,gBAAgB,MAAM,MAAM;EAC5E,KAAK,kBACH,OAAO,cAAc,MAAM,UAAU,IAAI,MAAM,OAAO,OAAO,MAAM;EACrE,KAAK,SACH,OAAO,SAAS,MAAM,OAAO,OAAO,MAAM,UAAU,iBAAiB,MAAM,MAAM,WAAW,MAAM,UAAU,KAAK,MAAM,QAAQ,KAAK;CACxI;AACF;AAEA,MAAa,gBAAgB,EAC3B,aACA,QAAQ,yBACe;CACvB,MAAM,SAAS,qBACb,YAAY,WACZ,YAAY,aACZ,YAAY,WACd;CAEA,OACE,qBAAC,WAAD,EAAA,UAAA;EACE,qBAAC,WAAD,EAAA,UAAA;GACG;GAAM;GAAG,OAAO;GAAO;EACjB,EAAA,CAAA;EACT,oBAAC,UAAD;GAAQ,MAAK;GAAS,SAAS,YAAY;GAAO,UAAA;EAE1C,CAAA;EACR,oBAAC,MAAD;GAAI,cAAW;GACZ,UAAA,OAAO,KAAK,UACX,qBAAC,MAAD,EAAA,UAAA;IACE,oBAAC,QAAD;KAAM,UAAU,MAAM;KAAY,UAAA,MAAM;IAAgB,CAAA;IAAE;IACzD,cAAc,KAAK;GAClB,EAAA,GAHK,MAAM,EAGX,CACL;EACC,CAAA;CACG,EAAA,CAAA;AAEb"}
|
package/dist/format.cjs
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
const formatNumber = (value, locale, options) => new Intl.NumberFormat(locale, options).format(value);
|
|
3
|
+
const formatCurrency = (value, locale, currency, options = {}) => new Intl.NumberFormat(locale, {
|
|
4
|
+
...options,
|
|
5
|
+
style: "currency",
|
|
6
|
+
currency
|
|
7
|
+
}).format(value);
|
|
8
|
+
const formatDate = (value, locale, options) => new Intl.DateTimeFormat(locale, options).format(value);
|
|
9
|
+
const formatRelativeTime = (value, unit, locale, options) => new Intl.RelativeTimeFormat(locale, options).format(value, unit);
|
|
10
|
+
const formatList = (values, locale, options) => new Intl.ListFormat(locale, options).format(values);
|
|
11
|
+
exports.formatCurrency = formatCurrency;
|
|
12
|
+
exports.formatDate = formatDate;
|
|
13
|
+
exports.formatList = formatList;
|
|
14
|
+
exports.formatNumber = formatNumber;
|
|
15
|
+
exports.formatRelativeTime = formatRelativeTime;
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=format.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.cjs","names":[],"sources":["../src/format.ts"],"sourcesContent":["export type NumberFormatOptions = Intl.NumberFormatOptions;\nexport type DateTimeFormatOptions = Intl.DateTimeFormatOptions;\nexport type RelativeTimeFormatOptions = Intl.RelativeTimeFormatOptions;\nexport type ListFormatOptions = Intl.ListFormatOptions;\n\nexport const formatNumber = (\n value: number,\n locale: string,\n options?: NumberFormatOptions,\n): string => new Intl.NumberFormat(locale, options).format(value);\n\nexport const formatCurrency = (\n value: number,\n locale: string,\n currency: string,\n options: Omit<NumberFormatOptions, \"style\" | \"currency\"> = {},\n): string =>\n new Intl.NumberFormat(locale, {\n ...options,\n style: \"currency\",\n currency,\n }).format(value);\n\nexport const formatDate = (\n value: Date | number,\n locale: string,\n options?: DateTimeFormatOptions,\n): string => new Intl.DateTimeFormat(locale, options).format(value);\n\nexport const formatRelativeTime = (\n value: number,\n unit: Intl.RelativeTimeFormatUnit,\n locale: string,\n options?: RelativeTimeFormatOptions,\n): string => new Intl.RelativeTimeFormat(locale, options).format(value, unit);\n\nexport const formatList = (\n values: readonly string[],\n locale: string,\n options?: ListFormatOptions,\n): string => new Intl.ListFormat(locale, options).format(values);\n"],"mappings":";AAKA,MAAa,gBACX,OACA,QACA,YACW,IAAI,KAAK,aAAa,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;AAEhE,MAAa,kBACX,OACA,QACA,UACA,UAA2D,CAAC,MAE5D,IAAI,KAAK,aAAa,QAAQ;CAC5B,GAAG;CACH,OAAO;CACP;AACF,CAAC,CAAC,CAAC,OAAO,KAAK;AAEjB,MAAa,cACX,OACA,QACA,YACW,IAAI,KAAK,eAAe,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;AAElE,MAAa,sBACX,OACA,MACA,QACA,YACW,IAAI,KAAK,mBAAmB,QAAQ,OAAO,CAAC,CAAC,OAAO,OAAO,IAAI;AAE5E,MAAa,cACX,QACA,QACA,YACW,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC,CAAC,OAAO,MAAM"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NumberFormatOptions = Intl.NumberFormatOptions;
|
|
2
|
+
export type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
|
|
3
|
+
export type RelativeTimeFormatOptions = Intl.RelativeTimeFormatOptions;
|
|
4
|
+
export type ListFormatOptions = Intl.ListFormatOptions;
|
|
5
|
+
export declare const formatNumber: (value: number, locale: string, options?: NumberFormatOptions) => string;
|
|
6
|
+
export declare const formatCurrency: (value: number, locale: string, currency: string, options?: Omit<NumberFormatOptions, "style" | "currency">) => string;
|
|
7
|
+
export declare const formatDate: (value: Date | number, locale: string, options?: DateTimeFormatOptions) => string;
|
|
8
|
+
export declare const formatRelativeTime: (value: number, unit: Intl.RelativeTimeFormatUnit, locale: string, options?: RelativeTimeFormatOptions) => string;
|
|
9
|
+
export declare const formatList: (values: readonly string[], locale: string, options?: ListFormatOptions) => string;
|
package/dist/format.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
export type NumberFormatOptions = Intl.NumberFormatOptions;
|
|
2
|
+
export type DateTimeFormatOptions = Intl.DateTimeFormatOptions;
|
|
3
|
+
export type RelativeTimeFormatOptions = Intl.RelativeTimeFormatOptions;
|
|
4
|
+
export type ListFormatOptions = Intl.ListFormatOptions;
|
|
5
|
+
export declare const formatNumber: (value: number, locale: string, options?: NumberFormatOptions) => string;
|
|
6
|
+
export declare const formatCurrency: (value: number, locale: string, currency: string, options?: Omit<NumberFormatOptions, "style" | "currency">) => string;
|
|
7
|
+
export declare const formatDate: (value: Date | number, locale: string, options?: DateTimeFormatOptions) => string;
|
|
8
|
+
export declare const formatRelativeTime: (value: number, unit: Intl.RelativeTimeFormatUnit, locale: string, options?: RelativeTimeFormatOptions) => string;
|
|
9
|
+
export declare const formatList: (values: readonly string[], locale: string, options?: ListFormatOptions) => string;
|
package/dist/format.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
// src/format.ts
|
|
2
|
+
const formatNumber = (value, locale, options) => new Intl.NumberFormat(locale, options).format(value);
|
|
3
|
+
const formatCurrency = (value, locale, currency, options = {}) => new Intl.NumberFormat(locale, {
|
|
4
|
+
...options,
|
|
5
|
+
style: "currency",
|
|
6
|
+
currency
|
|
7
|
+
}).format(value);
|
|
8
|
+
const formatDate = (value, locale, options) => new Intl.DateTimeFormat(locale, options).format(value);
|
|
9
|
+
const formatRelativeTime = (value, unit, locale, options) => new Intl.RelativeTimeFormat(locale, options).format(value, unit);
|
|
10
|
+
const formatList = (values, locale, options) => new Intl.ListFormat(locale, options).format(values);
|
|
11
|
+
export { formatCurrency, formatDate, formatList, formatNumber, formatRelativeTime };
|
|
12
|
+
|
|
13
|
+
//# sourceMappingURL=format.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"format.js","names":[],"sources":["../src/format.ts"],"sourcesContent":["export type NumberFormatOptions = Intl.NumberFormatOptions;\nexport type DateTimeFormatOptions = Intl.DateTimeFormatOptions;\nexport type RelativeTimeFormatOptions = Intl.RelativeTimeFormatOptions;\nexport type ListFormatOptions = Intl.ListFormatOptions;\n\nexport const formatNumber = (\n value: number,\n locale: string,\n options?: NumberFormatOptions,\n): string => new Intl.NumberFormat(locale, options).format(value);\n\nexport const formatCurrency = (\n value: number,\n locale: string,\n currency: string,\n options: Omit<NumberFormatOptions, \"style\" | \"currency\"> = {},\n): string =>\n new Intl.NumberFormat(locale, {\n ...options,\n style: \"currency\",\n currency,\n }).format(value);\n\nexport const formatDate = (\n value: Date | number,\n locale: string,\n options?: DateTimeFormatOptions,\n): string => new Intl.DateTimeFormat(locale, options).format(value);\n\nexport const formatRelativeTime = (\n value: number,\n unit: Intl.RelativeTimeFormatUnit,\n locale: string,\n options?: RelativeTimeFormatOptions,\n): string => new Intl.RelativeTimeFormat(locale, options).format(value, unit);\n\nexport const formatList = (\n values: readonly string[],\n locale: string,\n options?: ListFormatOptions,\n): string => new Intl.ListFormat(locale, options).format(values);\n"],"mappings":";AAKA,MAAa,gBACX,OACA,QACA,YACW,IAAI,KAAK,aAAa,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;AAEhE,MAAa,kBACX,OACA,QACA,UACA,UAA2D,CAAC,MAE5D,IAAI,KAAK,aAAa,QAAQ;CAC5B,GAAG;CACH,OAAO;CACP;AACF,CAAC,CAAC,CAAC,OAAO,KAAK;AAEjB,MAAa,cACX,OACA,QACA,YACW,IAAI,KAAK,eAAe,QAAQ,OAAO,CAAC,CAAC,OAAO,KAAK;AAElE,MAAa,sBACX,OACA,MACA,QACA,YACW,IAAI,KAAK,mBAAmB,QAAQ,OAAO,CAAC,CAAC,OAAO,OAAO,IAAI;AAE5E,MAAa,cACX,QACA,QACA,YACW,IAAI,KAAK,WAAW,QAAQ,OAAO,CAAC,CAAC,OAAO,MAAM"}
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_locale = require("./locale.cjs");
|
|
3
|
+
const require_runtime = require("./runtime.cjs");
|
|
4
|
+
const require_format = require("./format.cjs");
|
|
5
|
+
const require_compiler_index = require("./compiler/index.cjs");
|
|
6
|
+
exports.InvalidLocaleError = require_locale.InvalidLocaleError;
|
|
7
|
+
exports.createI18n = require_runtime.createI18n;
|
|
8
|
+
exports.createLocaleRegistry = require_locale.createLocaleRegistry;
|
|
9
|
+
exports.findUnusedTranslationKeys = require_compiler_index.findUnusedTranslationKeys;
|
|
10
|
+
exports.formatCurrency = require_format.formatCurrency;
|
|
11
|
+
exports.formatDate = require_format.formatDate;
|
|
12
|
+
exports.formatList = require_format.formatList;
|
|
13
|
+
exports.formatMessage = require_runtime.formatMessage;
|
|
14
|
+
exports.formatNumber = require_format.formatNumber;
|
|
15
|
+
exports.formatRelativeTime = require_format.formatRelativeTime;
|
|
16
|
+
exports.formatRichMessage = require_runtime.formatRichMessage;
|
|
17
|
+
exports.generateCatalogTypes = require_compiler_index.generateCatalogTypes;
|
|
18
|
+
exports.isValidLocale = require_locale.isValidLocale;
|
|
19
|
+
exports.resolveLocale = require_locale.resolveLocale;
|
|
20
|
+
exports.validateCatalogs = require_compiler_index.validateCatalogs;
|
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InvalidLocaleError, LocaleDefinition, LocaleRegistry, LocaleRegistryOptions, LocaleResolution, LocaleResolutionInput, createLocaleRegistry, isValidLocale, resolveLocale } from "./locale.cjs";
|
|
2
|
+
import { I18nInstance, I18nOptions, MessageAtPath, MessageCatalog, MessageEntry, MessageKeys, MessageValue, MessageValues, MissingTranslationEvent, NamespaceLoader, RichMessageResult, RichMessageValues, RichTranslationArgs, TranslationFallbackEvent, TranslationKey, Translator, createI18n, formatMessage, formatRichMessage } from "./runtime.cjs";
|
|
3
|
+
import { DateTimeFormatOptions, ListFormatOptions, NumberFormatOptions, RelativeTimeFormatOptions, formatCurrency, formatDate, formatList, formatNumber, formatRelativeTime } from "./format.cjs";
|
|
4
|
+
import { CatalogValidationIssue, ValidateCatalogsOptions, findUnusedTranslationKeys, generateCatalogTypes, validateCatalogs } from "./compiler/index.cjs";
|
|
5
|
+
export { type CatalogValidationIssue, type DateTimeFormatOptions, type I18nInstance, type I18nOptions, InvalidLocaleError, type ListFormatOptions, type LocaleDefinition, type LocaleRegistry, type LocaleRegistryOptions, type LocaleResolution, type LocaleResolutionInput, type MessageAtPath, type MessageCatalog, type MessageEntry, type MessageKeys, type MessageValue, type MessageValues, type MissingTranslationEvent, type NamespaceLoader, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichMessageResult, type RichMessageValues, type RichTranslationArgs, type TranslationFallbackEvent, type TranslationKey, type Translator, type ValidateCatalogsOptions, createI18n, createLocaleRegistry, findUnusedTranslationKeys, formatCurrency, formatDate, formatList, formatMessage, formatNumber, formatRelativeTime, formatRichMessage, generateCatalogTypes, isValidLocale, resolveLocale, validateCatalogs };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InvalidLocaleError, LocaleDefinition, LocaleRegistry, LocaleRegistryOptions, LocaleResolution, LocaleResolutionInput, createLocaleRegistry, isValidLocale, resolveLocale } from "./locale.js";
|
|
2
|
+
import { I18nInstance, I18nOptions, MessageAtPath, MessageCatalog, MessageEntry, MessageKeys, MessageValue, MessageValues, MissingTranslationEvent, NamespaceLoader, RichMessageResult, RichMessageValues, RichTranslationArgs, TranslationFallbackEvent, TranslationKey, Translator, createI18n, formatMessage, formatRichMessage } from "./runtime.js";
|
|
3
|
+
import { DateTimeFormatOptions, ListFormatOptions, NumberFormatOptions, RelativeTimeFormatOptions, formatCurrency, formatDate, formatList, formatNumber, formatRelativeTime } from "./format.js";
|
|
4
|
+
import { CatalogValidationIssue, ValidateCatalogsOptions, findUnusedTranslationKeys, generateCatalogTypes, validateCatalogs } from "./compiler/index.js";
|
|
5
|
+
export { type CatalogValidationIssue, type DateTimeFormatOptions, type I18nInstance, type I18nOptions, InvalidLocaleError, type ListFormatOptions, type LocaleDefinition, type LocaleRegistry, type LocaleRegistryOptions, type LocaleResolution, type LocaleResolutionInput, type MessageAtPath, type MessageCatalog, type MessageEntry, type MessageKeys, type MessageValue, type MessageValues, type MissingTranslationEvent, type NamespaceLoader, type NumberFormatOptions, type RelativeTimeFormatOptions, type RichMessageResult, type RichMessageValues, type RichTranslationArgs, type TranslationFallbackEvent, type TranslationKey, type Translator, type ValidateCatalogsOptions, createI18n, createLocaleRegistry, findUnusedTranslationKeys, formatCurrency, formatDate, formatList, formatMessage, formatNumber, formatRelativeTime, formatRichMessage, generateCatalogTypes, isValidLocale, resolveLocale, validateCatalogs };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { InvalidLocaleError, createLocaleRegistry, isValidLocale, resolveLocale } from "./locale.js";
|
|
2
|
+
import { createI18n, formatMessage, formatRichMessage } from "./runtime.js";
|
|
3
|
+
import { formatCurrency, formatDate, formatList, formatNumber, formatRelativeTime } from "./format.js";
|
|
4
|
+
import { findUnusedTranslationKeys, generateCatalogTypes, validateCatalogs } from "./compiler/index.js";
|
|
5
|
+
export { InvalidLocaleError, createI18n, createLocaleRegistry, findUnusedTranslationKeys, formatCurrency, formatDate, formatList, formatMessage, formatNumber, formatRelativeTime, formatRichMessage, generateCatalogTypes, isValidLocale, resolveLocale, validateCatalogs };
|
package/dist/locale.cjs
ADDED
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
// src/locale.ts
|
|
2
|
+
var InvalidLocaleError = class extends Error {
|
|
3
|
+
constructor(locale) {
|
|
4
|
+
super(`Invalid BCP 47 locale: "${locale}".`);
|
|
5
|
+
this.name = "InvalidLocaleError";
|
|
6
|
+
}
|
|
7
|
+
};
|
|
8
|
+
const canonicalize = (locale) => {
|
|
9
|
+
try {
|
|
10
|
+
const [canonical] = Intl.getCanonicalLocales(locale);
|
|
11
|
+
if (!canonical) throw new InvalidLocaleError(locale);
|
|
12
|
+
return canonical;
|
|
13
|
+
} catch {
|
|
14
|
+
throw new InvalidLocaleError(locale);
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
const localeKey = (locale) => locale.toLowerCase();
|
|
18
|
+
const isValidLocale = (locale) => {
|
|
19
|
+
try {
|
|
20
|
+
canonicalize(locale);
|
|
21
|
+
return true;
|
|
22
|
+
} catch {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
const createLocaleRegistry = (options) => {
|
|
27
|
+
if (options.locales.length === 0) throw new Error("At least one supported locale is required.");
|
|
28
|
+
const definitions = /* @__PURE__ */ new Map();
|
|
29
|
+
const aliases = /* @__PURE__ */ new Map();
|
|
30
|
+
for (const definition of options.locales) {
|
|
31
|
+
const locale = canonicalize(definition.locale);
|
|
32
|
+
if (definitions.has(locale)) throw new Error(`Duplicate locale definition: "${locale}".`);
|
|
33
|
+
const normalized = Object.freeze({
|
|
34
|
+
...definition,
|
|
35
|
+
locale,
|
|
36
|
+
aliases: definition.aliases ? Object.freeze([...definition.aliases]) : void 0,
|
|
37
|
+
fallbacks: definition.fallbacks ? Object.freeze(definition.fallbacks.map(canonicalize)) : void 0
|
|
38
|
+
});
|
|
39
|
+
definitions.set(locale, normalized);
|
|
40
|
+
for (const alias of definition.aliases ?? []) {
|
|
41
|
+
const key = localeKey(canonicalize(alias));
|
|
42
|
+
const existing = aliases.get(key);
|
|
43
|
+
if (existing && existing !== locale) throw new Error(`Locale alias "${alias}" is assigned to multiple locales.`);
|
|
44
|
+
aliases.set(key, locale);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
for (const [alias, locale] of aliases) {
|
|
48
|
+
const supportedLocale = [...definitions.keys()].find((candidate) => localeKey(candidate) === alias);
|
|
49
|
+
if (supportedLocale && supportedLocale !== locale) throw new Error(`Locale alias "${alias}" conflicts with supported locale "${supportedLocale}".`);
|
|
50
|
+
}
|
|
51
|
+
for (const definition of definitions.values()) for (const fallback of definition.fallbacks ?? []) if (!definitions.has(fallback)) throw new Error(`Fallback locale "${fallback}" from "${definition.locale}" is not supported.`);
|
|
52
|
+
const defaultLocale = canonicalize(options.defaultLocale);
|
|
53
|
+
const fallbackLocale = canonicalize(options.fallbackLocale ?? options.defaultLocale);
|
|
54
|
+
if (!definitions.has(defaultLocale)) throw new Error(`Default locale "${defaultLocale}" is not present in the locale registry.`);
|
|
55
|
+
if (!definitions.has(fallbackLocale)) throw new Error(`Fallback locale "${fallbackLocale}" is not present in the locale registry.`);
|
|
56
|
+
const resolve = (input) => {
|
|
57
|
+
let locale;
|
|
58
|
+
try {
|
|
59
|
+
locale = canonicalize(input);
|
|
60
|
+
} catch {
|
|
61
|
+
return;
|
|
62
|
+
}
|
|
63
|
+
const alias = aliases.get(localeKey(locale));
|
|
64
|
+
if (alias) return alias;
|
|
65
|
+
if (definitions.has(locale)) return locale;
|
|
66
|
+
const language = locale.split("-")[0];
|
|
67
|
+
if (language && definitions.has(language)) return language;
|
|
68
|
+
const languageMatches = [...definitions.keys()].filter((candidate) => candidate.split("-")[0] === language);
|
|
69
|
+
if (languageMatches.length === 1) return languageMatches[0];
|
|
70
|
+
};
|
|
71
|
+
const fallbackChain = (input) => {
|
|
72
|
+
const resolved = resolve(input);
|
|
73
|
+
if (!resolved) throw new InvalidLocaleError(input);
|
|
74
|
+
const chain = [];
|
|
75
|
+
const visited = /* @__PURE__ */ new Set();
|
|
76
|
+
const add = (locale) => {
|
|
77
|
+
if (visited.has(locale) || !definitions.has(locale)) return;
|
|
78
|
+
visited.add(locale);
|
|
79
|
+
chain.push(locale);
|
|
80
|
+
const definition = definitions.get(locale);
|
|
81
|
+
for (const fallback of definition?.fallbacks ?? []) add(fallback);
|
|
82
|
+
const language = locale.split("-")[0];
|
|
83
|
+
if (language && language !== locale && definitions.has(language)) add(language);
|
|
84
|
+
};
|
|
85
|
+
add(resolved);
|
|
86
|
+
add(fallbackLocale);
|
|
87
|
+
add(defaultLocale);
|
|
88
|
+
return Object.freeze(chain);
|
|
89
|
+
};
|
|
90
|
+
return Object.freeze({
|
|
91
|
+
locales: Object.freeze([...definitions.values()]),
|
|
92
|
+
defaultLocale,
|
|
93
|
+
fallbackLocale,
|
|
94
|
+
canonicalize,
|
|
95
|
+
get: (input) => {
|
|
96
|
+
const resolved = resolve(input);
|
|
97
|
+
return resolved ? definitions.get(resolved) : void 0;
|
|
98
|
+
},
|
|
99
|
+
isSupported: (input) => resolve(input) !== void 0,
|
|
100
|
+
resolve,
|
|
101
|
+
fallbackChain
|
|
102
|
+
});
|
|
103
|
+
};
|
|
104
|
+
const acceptedLanguages = (header) => header.split(",").map((part, index) => {
|
|
105
|
+
const [tag, ...parameters] = part.trim().split(";");
|
|
106
|
+
const qualityParameter = parameters.find((parameter) => parameter.trim().startsWith("q="));
|
|
107
|
+
const quality = qualityParameter ? Number(qualityParameter.trim().slice(2)) : 1;
|
|
108
|
+
return {
|
|
109
|
+
tag: tag?.trim(),
|
|
110
|
+
quality,
|
|
111
|
+
index
|
|
112
|
+
};
|
|
113
|
+
}).filter((entry) => Boolean(entry.tag) && Number.isFinite(entry.quality) && entry.quality > 0 && entry.quality <= 1).sort((left, right) => right.quality - left.quality || left.index - right.index).map((entry) => entry.tag);
|
|
114
|
+
const resolveLocale = (input) => {
|
|
115
|
+
const candidates = [
|
|
116
|
+
{
|
|
117
|
+
locale: input.explicit,
|
|
118
|
+
source: "explicit"
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
locale: input.urlLocale,
|
|
122
|
+
source: "url"
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
locale: input.userPreference,
|
|
126
|
+
source: "user-preference"
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
locale: input.cookie,
|
|
130
|
+
source: "cookie"
|
|
131
|
+
},
|
|
132
|
+
...acceptedLanguages(input.acceptLanguage ?? "").map((locale) => ({
|
|
133
|
+
locale,
|
|
134
|
+
source: "accept-language"
|
|
135
|
+
})),
|
|
136
|
+
{
|
|
137
|
+
locale: input.browserLocale,
|
|
138
|
+
source: "browser"
|
|
139
|
+
}
|
|
140
|
+
];
|
|
141
|
+
for (const candidate of candidates) {
|
|
142
|
+
const locale = candidate.locale ? input.registry.resolve(candidate.locale) : void 0;
|
|
143
|
+
if (locale) return {
|
|
144
|
+
locale,
|
|
145
|
+
source: candidate.source
|
|
146
|
+
};
|
|
147
|
+
}
|
|
148
|
+
return {
|
|
149
|
+
locale: input.registry.defaultLocale,
|
|
150
|
+
source: "default"
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
exports.InvalidLocaleError = InvalidLocaleError;
|
|
154
|
+
exports.createLocaleRegistry = createLocaleRegistry;
|
|
155
|
+
exports.isValidLocale = isValidLocale;
|
|
156
|
+
exports.resolveLocale = resolveLocale;
|
|
157
|
+
|
|
158
|
+
//# sourceMappingURL=locale.cjs.map
|