@dads-framework/ui 0.2.0 → 0.3.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 +2 -2
- package/dist/copy/index.d.ts +17 -0
- package/dist/copy/index.d.ts.map +1 -0
- package/dist/copy/index.js +17 -0
- package/dist/copy/index.js.map +1 -0
- package/dist/copy/lib/catalog-parity.d.ts +55 -0
- package/dist/copy/lib/catalog-parity.d.ts.map +1 -0
- package/dist/copy/lib/catalog-parity.js +134 -0
- package/dist/copy/lib/catalog-parity.js.map +1 -0
- package/dist/copy/lib/copy-descriptor.d.ts +31 -0
- package/dist/copy/lib/copy-descriptor.d.ts.map +1 -0
- package/dist/copy/lib/copy-descriptor.js +35 -0
- package/dist/copy/lib/copy-descriptor.js.map +1 -0
- package/dist/copy/lib/create-copy-hook.d.ts +23 -0
- package/dist/copy/lib/create-copy-hook.d.ts.map +1 -0
- package/dist/copy/lib/create-copy-hook.js +17 -0
- package/dist/copy/lib/create-copy-hook.js.map +1 -0
- package/dist/copy/lib/english-chrome-case.d.ts +16 -0
- package/dist/copy/lib/english-chrome-case.d.ts.map +1 -0
- package/dist/copy/lib/english-chrome-case.js +111 -0
- package/dist/copy/lib/english-chrome-case.js.map +1 -0
- package/dist/copy/lib/formatted-values.d.ts +16 -0
- package/dist/copy/lib/formatted-values.d.ts.map +1 -0
- package/dist/copy/lib/formatted-values.js +15 -0
- package/dist/copy/lib/formatted-values.js.map +1 -0
- package/dist/copy/lib/glossary.d.ts +28 -0
- package/dist/copy/lib/glossary.d.ts.map +1 -0
- package/dist/copy/lib/glossary.js +22 -0
- package/dist/copy/lib/glossary.js.map +1 -0
- package/dist/copy/lib/locale-formatting.d.ts +62 -0
- package/dist/copy/lib/locale-formatting.d.ts.map +1 -0
- package/dist/copy/lib/locale-formatting.js +172 -0
- package/dist/copy/lib/locale-formatting.js.map +1 -0
- package/dist/copy/lib/locale-metadata.d.ts +15 -0
- package/dist/copy/lib/locale-metadata.d.ts.map +1 -0
- package/dist/copy/lib/locale-metadata.js +9 -0
- package/dist/copy/lib/locale-metadata.js.map +1 -0
- package/dist/copy/lib/locale-provider.d.ts +36 -0
- package/dist/copy/lib/locale-provider.d.ts.map +1 -0
- package/dist/copy/lib/locale-provider.js +41 -0
- package/dist/copy/lib/locale-provider.js.map +1 -0
- package/dist/copy/lib/localized-text.d.ts +41 -0
- package/dist/copy/lib/localized-text.d.ts.map +1 -0
- package/dist/copy/lib/localized-text.js +42 -0
- package/dist/copy/lib/localized-text.js.map +1 -0
- package/dist/copy/lib/logic/calendar-date-boundaries.d.ts +5 -0
- package/dist/copy/lib/logic/calendar-date-boundaries.d.ts.map +1 -0
- package/dist/copy/lib/logic/calendar-date-boundaries.js +69 -0
- package/dist/copy/lib/logic/calendar-date-boundaries.js.map +1 -0
- package/dist/copy/lib/logic/locale-provider-state.d.ts +12 -0
- package/dist/copy/lib/logic/locale-provider-state.d.ts.map +1 -0
- package/dist/copy/lib/logic/locale-provider-state.js +17 -0
- package/dist/copy/lib/logic/locale-provider-state.js.map +1 -0
- package/dist/copy/lib/merge-copy.d.ts +43 -0
- package/dist/copy/lib/merge-copy.d.ts.map +1 -0
- package/dist/copy/lib/merge-copy.js +26 -0
- package/dist/copy/lib/merge-copy.js.map +1 -0
- package/dist/copy/lib/placeholder-syntax.d.ts +12 -0
- package/dist/copy/lib/placeholder-syntax.d.ts.map +1 -0
- package/dist/copy/lib/placeholder-syntax.js +36 -0
- package/dist/copy/lib/placeholder-syntax.js.map +1 -0
- package/dist/copy/lib/product-vocabulary.d.ts +42 -0
- package/dist/copy/lib/product-vocabulary.d.ts.map +1 -0
- package/dist/copy/lib/product-vocabulary.js +126 -0
- package/dist/copy/lib/product-vocabulary.js.map +1 -0
- package/dist/copy/lib/resolve-initial-locale.d.ts +37 -0
- package/dist/copy/lib/resolve-initial-locale.d.ts.map +1 -0
- package/dist/copy/lib/resolve-initial-locale.js +55 -0
- package/dist/copy/lib/resolve-initial-locale.js.map +1 -0
- package/dist/copy/lib/translate.d.ts +18 -0
- package/dist/copy/lib/translate.d.ts.map +1 -0
- package/dist/copy/lib/translate.js +90 -0
- package/dist/copy/lib/translate.js.map +1 -0
- package/dist/copy/lib/use-locale-formatting.d.ts +18 -0
- package/dist/copy/lib/use-locale-formatting.d.ts.map +1 -0
- package/dist/copy/lib/use-locale-formatting.js +21 -0
- package/dist/copy/lib/use-locale-formatting.js.map +1 -0
- package/dist/data-table/components/data-table/data-table-date-filter.js +1 -1
- package/dist/data-table/components/data-table/data-table-date-filter.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-faceted-filter.js +1 -1
- package/dist/data-table/components/data-table/data-table-faceted-filter.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-date-input.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-date-input.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-input-shared.d.ts +1 -1
- package/dist/data-table/components/data-table/data-table-filter-input-shared.d.ts.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list-input.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list-input.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list-item.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list-item.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-list.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-menu-item.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-menu-item.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-filter-menu-value-selector.js +1 -1
- package/dist/data-table/components/data-table/data-table-filter-menu-value-selector.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-pagination.js +1 -1
- package/dist/data-table/components/data-table/data-table-pagination.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-slider-filter.js +1 -1
- package/dist/data-table/components/data-table/data-table-slider-filter.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-sort-list.js +1 -1
- package/dist/data-table/components/data-table/data-table-sort-list.js.map +1 -1
- package/dist/data-table/components/data-table/data-table-toolbar.js +1 -1
- package/dist/data-table/components/data-table/data-table-toolbar.js.map +1 -1
- package/dist/data-table/components/data-table/filter-pill.js +1 -1
- package/dist/data-table/components/data-table/filter-pill.js.map +1 -1
- package/dist/data-table/copy/data-table-copy.d.ts +1 -1
- package/dist/data-table/copy/data-table-copy.d.ts.map +1 -1
- package/dist/data-table/copy/data-table-copy.js +1 -1
- package/dist/data-table/copy/data-table-copy.js.map +1 -1
- package/dist/data-table/lib/format.d.ts +1 -1
- package/dist/data-table/lib/format.d.ts.map +1 -1
- package/dist/elements/copy/elements-copy.d.ts +1 -1
- package/dist/elements/copy/elements-copy.d.ts.map +1 -1
- package/dist/elements/copy/elements-copy.js +1 -1
- package/dist/elements/copy/elements-copy.js.map +1 -1
- package/dist/overlays/components/attachment-viewer/attachment-viewer.js +1 -1
- package/dist/overlays/components/attachment-viewer/attachment-viewer.js.map +1 -1
- package/dist/overlays/components/attachment-viewer/image-stage.js +1 -1
- package/dist/overlays/components/attachment-viewer/image-stage.js.map +1 -1
- package/dist/overlays/components/attachment-viewer/pdf-document-view.js +1 -1
- package/dist/overlays/components/attachment-viewer/pdf-document-view.js.map +1 -1
- package/dist/overlays/copy/overlays-copy.d.ts +1 -1
- package/dist/overlays/copy/overlays-copy.d.ts.map +1 -1
- package/dist/overlays/copy/overlays-copy.js +1 -1
- package/dist/overlays/copy/overlays-copy.js.map +1 -1
- package/dist/page/components/attachment-list.js +1 -1
- package/dist/page/components/attachment-list.js.map +1 -1
- package/dist/page/components/list-view-tabs.js +1 -1
- package/dist/page/components/list-view-tabs.js.map +1 -1
- package/dist/page/copy/page-copy.d.ts +1 -1
- package/dist/page/copy/page-copy.d.ts.map +1 -1
- package/dist/page/copy/page-copy.js +1 -1
- package/dist/page/copy/page-copy.js.map +1 -1
- package/dist/shell/copy/shell-copy.d.ts +1 -1
- package/dist/shell/copy/shell-copy.d.ts.map +1 -1
- package/dist/shell/copy/shell-copy.js +1 -1
- package/dist/shell/copy/shell-copy.js.map +1 -1
- package/package.json +46 -4
- package/styles/base.css +63 -0
- package/styles/fonts.css +8 -0
- package/styles/index.css +14 -0
- package/styles/theme.css +140 -0
- package/styles/tokens.dark.css +95 -0
- package/styles/tokens.palette.css +90 -0
- package/styles/tokens.semantic.css +119 -0
- package/styles/utilities.css +12 -0
- package/tokens/default.tokens.json +1162 -0
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/** Declare the glossary and keep its keys literal, exactly as `defineCopy`. */
|
|
2
|
+
export function defineGlossary(glossary) {
|
|
3
|
+
return glossary;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* The glossary as ordinary copy, so a feature reads a shared noun through the
|
|
7
|
+
* same hook it reads its own words with.
|
|
8
|
+
*
|
|
9
|
+
* Each entry becomes three keys: the entry's own key, for a label that names
|
|
10
|
+
* one thing, and the `_one` / `_other` pair the plural machinery selects
|
|
11
|
+
* between when a count is present.
|
|
12
|
+
*/
|
|
13
|
+
export function glossaryCatalog(glossary) {
|
|
14
|
+
const catalog = {};
|
|
15
|
+
for (const [key, entry] of Object.entries(glossary)) {
|
|
16
|
+
catalog[key] = entry.one;
|
|
17
|
+
catalog[`${key}_one`] = entry.one;
|
|
18
|
+
catalog[`${key}_other`] = entry.other;
|
|
19
|
+
}
|
|
20
|
+
return catalog;
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=glossary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"glossary.js","sourceRoot":"","sources":["../../../src/copy/lib/glossary.ts"],"names":[],"mappings":"AAoBA,+EAA+E;AAC/E,MAAM,UAAU,cAAc,CAA2B,QAAW;IAClE,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,eAAe,CAAC,QAAkB;IAChD,MAAM,OAAO,GAAkC,EAAE,CAAC;IAClD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,QAAQ,CAAC,EAAE,CAAC;QACpD,OAAO,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;QACzB,OAAO,CAAC,GAAG,GAAG,MAAM,CAAC,GAAG,KAAK,CAAC,GAAG,CAAC;QAClC,OAAO,CAAC,GAAG,GAAG,QAAQ,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC;IACxC,CAAC;IACD,OAAO,OAAO,CAAC;AACjB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation formatting owned by the reader locale.
|
|
3
|
+
*
|
|
4
|
+
* Dates refuse an implicit time zone, currency refuses an implicit code, and
|
|
5
|
+
* exact decimals never pass through JavaScript `number`. Human labels use the
|
|
6
|
+
* reader's collation rules; stable product codes deliberately do not.
|
|
7
|
+
*/
|
|
8
|
+
export type ExplicitDateTimeFormatOptions = Omit<Intl.DateTimeFormatOptions, "timeZone"> & {
|
|
9
|
+
readonly timeZone: string;
|
|
10
|
+
};
|
|
11
|
+
export type ExplicitCurrencyFormatOptions = Omit<Intl.NumberFormatOptions, "currency" | "style">;
|
|
12
|
+
export type ListFormatOptions = Intl.ListFormatOptions;
|
|
13
|
+
/** Return the YYYY-MM-DD calendar date an instant belongs to in one named zone. */
|
|
14
|
+
export declare function formatCalendarDateKey(value: Date | number | string, timeZone: string): string;
|
|
15
|
+
/** Format an instant in the reader's locale and the caller's named time zone. */
|
|
16
|
+
export declare function formatDateTime(value: Date | number | string, locale: string, options: ExplicitDateTimeFormatOptions): string;
|
|
17
|
+
/**
|
|
18
|
+
* A time zone's everyday name in the reader's language, such as "Pacific
|
|
19
|
+
* Time" for America/Los_Angeles. `null` when the zone is unknown here or has
|
|
20
|
+
* no name beyond its UTC offset, so the caller can fall back to the zone id.
|
|
21
|
+
*/
|
|
22
|
+
export declare function formatTimeZoneName(timeZone: string, locale: string, at: Date | number | string): string | null;
|
|
23
|
+
/** Format a presentation number without an implicit locale. */
|
|
24
|
+
export declare function formatNumber(value: number | bigint, locale: string, options?: Intl.NumberFormatOptions): string;
|
|
25
|
+
/** Format a count or other whole presentation number. */
|
|
26
|
+
export declare function formatInteger(value: number | bigint, locale: string): string;
|
|
27
|
+
/** Format money only when its domain-owned currency code is present. */
|
|
28
|
+
export declare function formatCurrency(value: number | bigint, locale: string, currency: string, options?: ExplicitCurrencyFormatOptions): string;
|
|
29
|
+
/** A distance from now in whole units, e.g. -2 minutes or 1 day. */
|
|
30
|
+
export type RelativeTimeFormatUnit = Intl.RelativeTimeFormatUnit;
|
|
31
|
+
/**
|
|
32
|
+
* Word a distance from now in the reader's locale: "2 minutes ago", "in 12
|
|
33
|
+
* minutes", "yesterday". The caller decides the unit and count.
|
|
34
|
+
*/
|
|
35
|
+
export declare function formatRelativeTime(value: number, unit: RelativeTimeFormatUnit, locale: string): string;
|
|
36
|
+
/**
|
|
37
|
+
* Which ordinal form a position takes in the reader's locale — in English
|
|
38
|
+
* "one" for 1st/21st, "two" for 2nd, "few" for 3rd, "other" for 4th. The
|
|
39
|
+
* caller's catalog words each form.
|
|
40
|
+
*/
|
|
41
|
+
export declare function selectOrdinalCategory(value: number, locale: string): Intl.LDMLPluralRule;
|
|
42
|
+
/** Join human-authored items with the reader locale's grammar and punctuation. */
|
|
43
|
+
export declare function formatList(values: readonly string[], locale: string, options?: ListFormatOptions): string;
|
|
44
|
+
/**
|
|
45
|
+
* Localize grouping, digits, and the decimal mark while preserving every
|
|
46
|
+
* source digit and the source scale. Invalid input stays visible unchanged;
|
|
47
|
+
* presentation formatting must not turn an integrity finding into zero.
|
|
48
|
+
*/
|
|
49
|
+
export declare function formatExactDecimal(value: string, locale: string): string;
|
|
50
|
+
/** Compare human-authored labels with the reader's collation rules. */
|
|
51
|
+
export declare function compareHumanLabels(left: string, right: string, locale: string): number;
|
|
52
|
+
/** Match human-authored text after locale-aware Unicode case folding. */
|
|
53
|
+
export declare function humanTextIncludes(value: string, query: string, locale: string): boolean;
|
|
54
|
+
/** Stable codes sort identically for every reader and every machine. */
|
|
55
|
+
export declare function compareStableCodes(left: string, right: string): number;
|
|
56
|
+
/**
|
|
57
|
+
* The browser zone for surfaces explicitly defined in terms of the reader's
|
|
58
|
+
* calendar day. Business-scoped timestamps should pass their domain time zone
|
|
59
|
+
* instead; UTC is the explicit fallback where no business zone travels.
|
|
60
|
+
*/
|
|
61
|
+
export declare function resolveReaderTimeZone(): string;
|
|
62
|
+
//# sourceMappingURL=locale-formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-formatting.d.ts","sourceRoot":"","sources":["../../../src/copy/lib/locale-formatting.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,IAAI,CAAC,qBAAqB,EAC1B,UAAU,CACX,GAAG;IACF,QAAQ,CAAC,QAAQ,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF,MAAM,MAAM,6BAA6B,GAAG,IAAI,CAC9C,IAAI,CAAC,mBAAmB,EACxB,UAAU,GAAG,OAAO,CACrB,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,IAAI,CAAC,iBAAiB,CAAC;AAIvD,mFAAmF;AACnF,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,QAAQ,EAAE,MAAM,GACf,MAAM,CAMR;AAED,iFAAiF;AACjF,wBAAgB,cAAc,CAC5B,KAAK,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,EAC7B,MAAM,EAAE,MAAM,EACd,OAAO,EAAE,6BAA6B,GACrC,MAAM,CAER;AAED;;;;GAIG;AACH,wBAAgB,kBAAkB,CAChC,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EACd,EAAE,EAAE,IAAI,GAAG,MAAM,GAAG,MAAM,GACzB,MAAM,GAAG,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b,OAAO,CAKT;AAMD,wEAAwE;AACxE,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,CAGtE;AAED;;;;GAIG;AACH,wBAAgB,qBAAqB,IAAI,MAAM,CAE9C"}
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Presentation formatting owned by the reader locale.
|
|
3
|
+
*
|
|
4
|
+
* Dates refuse an implicit time zone, currency refuses an implicit code, and
|
|
5
|
+
* exact decimals never pass through JavaScript `number`. Human labels use the
|
|
6
|
+
* reader's collation rules; stable product codes deliberately do not.
|
|
7
|
+
*/
|
|
8
|
+
const CALENDAR_DATE_FORMATTERS = new Map();
|
|
9
|
+
/** Return the YYYY-MM-DD calendar date an instant belongs to in one named zone. */
|
|
10
|
+
export function formatCalendarDateKey(value, timeZone) {
|
|
11
|
+
const parts = calendarDateFormatter(timeZone).formatToParts(new Date(value));
|
|
12
|
+
const year = parts.find((part) => part.type === "year")?.value ?? "";
|
|
13
|
+
const month = parts.find((part) => part.type === "month")?.value ?? "";
|
|
14
|
+
const day = parts.find((part) => part.type === "day")?.value ?? "";
|
|
15
|
+
return `${year}-${month}-${day}`;
|
|
16
|
+
}
|
|
17
|
+
/** Format an instant in the reader's locale and the caller's named time zone. */
|
|
18
|
+
export function formatDateTime(value, locale, options) {
|
|
19
|
+
return new Intl.DateTimeFormat(locale, options).format(new Date(value));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* A time zone's everyday name in the reader's language, such as "Pacific
|
|
23
|
+
* Time" for America/Los_Angeles. `null` when the zone is unknown here or has
|
|
24
|
+
* no name beyond its UTC offset, so the caller can fall back to the zone id.
|
|
25
|
+
*/
|
|
26
|
+
export function formatTimeZoneName(timeZone, locale, at) {
|
|
27
|
+
let name;
|
|
28
|
+
try {
|
|
29
|
+
name = new Intl.DateTimeFormat(locale, {
|
|
30
|
+
timeZone,
|
|
31
|
+
timeZoneName: "longGeneric",
|
|
32
|
+
})
|
|
33
|
+
.formatToParts(new Date(at))
|
|
34
|
+
.find((part) => part.type === "timeZoneName")?.value;
|
|
35
|
+
}
|
|
36
|
+
catch {
|
|
37
|
+
return null;
|
|
38
|
+
}
|
|
39
|
+
if (name === undefined || name === timeZone)
|
|
40
|
+
return null;
|
|
41
|
+
return /^(?:GMT|UTC)(?:[+\-−]|$)/.test(name) ? null : name;
|
|
42
|
+
}
|
|
43
|
+
/** Format a presentation number without an implicit locale. */
|
|
44
|
+
export function formatNumber(value, locale, options = {}) {
|
|
45
|
+
return new Intl.NumberFormat(locale, options).format(value);
|
|
46
|
+
}
|
|
47
|
+
/** Format a count or other whole presentation number. */
|
|
48
|
+
export function formatInteger(value, locale) {
|
|
49
|
+
return formatNumber(value, locale, {
|
|
50
|
+
maximumFractionDigits: 0,
|
|
51
|
+
minimumFractionDigits: 0,
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
/** Format money only when its domain-owned currency code is present. */
|
|
55
|
+
export function formatCurrency(value, locale, currency, options = {}) {
|
|
56
|
+
return formatNumber(value, locale, {
|
|
57
|
+
...options,
|
|
58
|
+
style: "currency",
|
|
59
|
+
currency,
|
|
60
|
+
});
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Word a distance from now in the reader's locale: "2 minutes ago", "in 12
|
|
64
|
+
* minutes", "yesterday". The caller decides the unit and count.
|
|
65
|
+
*/
|
|
66
|
+
export function formatRelativeTime(value, unit, locale) {
|
|
67
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(value, unit);
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Which ordinal form a position takes in the reader's locale — in English
|
|
71
|
+
* "one" for 1st/21st, "two" for 2nd, "few" for 3rd, "other" for 4th. The
|
|
72
|
+
* caller's catalog words each form.
|
|
73
|
+
*/
|
|
74
|
+
export function selectOrdinalCategory(value, locale) {
|
|
75
|
+
return new Intl.PluralRules(locale, { type: "ordinal" }).select(value);
|
|
76
|
+
}
|
|
77
|
+
/** Join human-authored items with the reader locale's grammar and punctuation. */
|
|
78
|
+
export function formatList(values, locale, options = {}) {
|
|
79
|
+
return new Intl.ListFormat(locale, options).format([...values]);
|
|
80
|
+
}
|
|
81
|
+
const EXACT_DECIMAL = /^(-?)(\d+)(?:\.(\d+))?$/;
|
|
82
|
+
const ASCII_DIGITS = "0123456789";
|
|
83
|
+
const DIGIT_VALUES = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
|
|
84
|
+
/**
|
|
85
|
+
* Localize grouping, digits, and the decimal mark while preserving every
|
|
86
|
+
* source digit and the source scale. Invalid input stays visible unchanged;
|
|
87
|
+
* presentation formatting must not turn an integrity finding into zero.
|
|
88
|
+
*/
|
|
89
|
+
export function formatExactDecimal(value, locale) {
|
|
90
|
+
const match = EXACT_DECIMAL.exec(value);
|
|
91
|
+
if (match === null)
|
|
92
|
+
return value;
|
|
93
|
+
const sign = match[1] ?? "";
|
|
94
|
+
const whole = match[2];
|
|
95
|
+
const fraction = match[3];
|
|
96
|
+
if (whole === undefined)
|
|
97
|
+
return value;
|
|
98
|
+
const integerFormatter = new Intl.NumberFormat(locale, {
|
|
99
|
+
maximumFractionDigits: 0,
|
|
100
|
+
minimumFractionDigits: 0,
|
|
101
|
+
});
|
|
102
|
+
const magnitude = BigInt(whole);
|
|
103
|
+
const localizedWhole = sign === "-"
|
|
104
|
+
? integerFormatter.format(magnitude === 0n ? -0 : -magnitude)
|
|
105
|
+
: integerFormatter.format(magnitude);
|
|
106
|
+
if (fraction === undefined)
|
|
107
|
+
return localizedWhole;
|
|
108
|
+
return `${localizedWhole}${decimalSeparator(locale)}${localizeDigits(fraction, locale)}`;
|
|
109
|
+
}
|
|
110
|
+
function decimalSeparator(locale) {
|
|
111
|
+
return (new Intl.NumberFormat(locale, {
|
|
112
|
+
minimumFractionDigits: 1,
|
|
113
|
+
maximumFractionDigits: 1,
|
|
114
|
+
useGrouping: false,
|
|
115
|
+
})
|
|
116
|
+
.formatToParts(1.1)
|
|
117
|
+
.find((part) => part.type === "decimal")?.value ?? ".");
|
|
118
|
+
}
|
|
119
|
+
function localizeDigits(value, locale) {
|
|
120
|
+
const formatter = new Intl.NumberFormat(locale, { useGrouping: false });
|
|
121
|
+
const localizedDigits = DIGIT_VALUES.map((digit) => formatter.format(digit));
|
|
122
|
+
let localized = "";
|
|
123
|
+
for (const digit of value) {
|
|
124
|
+
const index = ASCII_DIGITS.indexOf(digit);
|
|
125
|
+
localized += localizedDigits[index] ?? digit;
|
|
126
|
+
}
|
|
127
|
+
return localized;
|
|
128
|
+
}
|
|
129
|
+
/** Compare human-authored labels with the reader's collation rules. */
|
|
130
|
+
export function compareHumanLabels(left, right, locale) {
|
|
131
|
+
return new Intl.Collator(locale, {
|
|
132
|
+
numeric: true,
|
|
133
|
+
sensitivity: "base",
|
|
134
|
+
usage: "sort",
|
|
135
|
+
}).compare(left, right);
|
|
136
|
+
}
|
|
137
|
+
/** Match human-authored text after locale-aware Unicode case folding. */
|
|
138
|
+
export function humanTextIncludes(value, query, locale) {
|
|
139
|
+
const foldedQuery = foldHumanText(query.trim(), locale);
|
|
140
|
+
return (foldedQuery === "" || foldHumanText(value, locale).includes(foldedQuery));
|
|
141
|
+
}
|
|
142
|
+
function foldHumanText(value, locale) {
|
|
143
|
+
return value.normalize("NFKC").toLocaleLowerCase(locale);
|
|
144
|
+
}
|
|
145
|
+
/** Stable codes sort identically for every reader and every machine. */
|
|
146
|
+
export function compareStableCodes(left, right) {
|
|
147
|
+
if (left === right)
|
|
148
|
+
return 0;
|
|
149
|
+
return left < right ? -1 : 1;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* The browser zone for surfaces explicitly defined in terms of the reader's
|
|
153
|
+
* calendar day. Business-scoped timestamps should pass their domain time zone
|
|
154
|
+
* instead; UTC is the explicit fallback where no business zone travels.
|
|
155
|
+
*/
|
|
156
|
+
export function resolveReaderTimeZone() {
|
|
157
|
+
return new Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
158
|
+
}
|
|
159
|
+
function calendarDateFormatter(timeZone) {
|
|
160
|
+
const existing = CALENDAR_DATE_FORMATTERS.get(timeZone);
|
|
161
|
+
if (existing !== undefined)
|
|
162
|
+
return existing;
|
|
163
|
+
const formatter = new Intl.DateTimeFormat("en-US", {
|
|
164
|
+
timeZone,
|
|
165
|
+
year: "numeric",
|
|
166
|
+
month: "2-digit",
|
|
167
|
+
day: "2-digit",
|
|
168
|
+
});
|
|
169
|
+
CALENDAR_DATE_FORMATTERS.set(timeZone, formatter);
|
|
170
|
+
return formatter;
|
|
171
|
+
}
|
|
172
|
+
//# sourceMappingURL=locale-formatting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-formatting.js","sourceRoot":"","sources":["../../../src/copy/lib/locale-formatting.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAgBH,MAAM,wBAAwB,GAAG,IAAI,GAAG,EAA+B,CAAC;AAExE,mFAAmF;AACnF,MAAM,UAAU,qBAAqB,CACnC,KAA6B,EAC7B,QAAgB;IAEhB,MAAM,KAAK,GAAG,qBAAqB,CAAC,QAAQ,CAAC,CAAC,aAAa,CAAC,IAAI,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAC7E,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,MAAM,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IACrE,MAAM,KAAK,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,OAAO,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;IACvE,MAAM,GAAG,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,KAAK,CAAC,EAAE,KAAK,IAAI,EAAE,CAAC;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,aAAa,CAAC,KAAa,EAAE,MAAc;IAClD,OAAO,KAAK,CAAC,SAAS,CAAC,MAAM,CAAC,CAAC,iBAAiB,CAAC,MAAM,CAAC,CAAC;AAC3D,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,kBAAkB,CAAC,IAAY,EAAE,KAAa;IAC5D,IAAI,IAAI,KAAK,KAAK;QAAE,OAAO,CAAC,CAAC;IAC7B,OAAO,IAAI,GAAG,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AAC/B,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,qBAAqB;IACnC,OAAO,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC,eAAe,EAAE,CAAC,QAAQ,CAAC;AAC9D,CAAC;AAED,SAAS,qBAAqB,CAAC,QAAgB;IAC7C,MAAM,QAAQ,GAAG,wBAAwB,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAC;IACxD,IAAI,QAAQ,KAAK,SAAS;QAAE,OAAO,QAAQ,CAAC;IAE5C,MAAM,SAAS,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,OAAO,EAAE;QACjD,QAAQ;QACR,IAAI,EAAE,SAAS;QACf,KAAK,EAAE,SAAS;QAChB,GAAG,EAAE,SAAS;KACf,CAAC,CAAC;IACH,wBAAwB,CAAC,GAAG,CAAC,QAAQ,EAAE,SAAS,CAAC,CAAC;IAClD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { Locale } from "./localized-text.js";
|
|
2
|
+
/** The document flow direction a locale requires. */
|
|
3
|
+
export type TextDirection = "ltr" | "rtl";
|
|
4
|
+
export type LocaleMetadata = {
|
|
5
|
+
readonly direction: TextDirection;
|
|
6
|
+
};
|
|
7
|
+
/** Runtime metadata for every supported reader locale. */
|
|
8
|
+
export declare const LOCALE_METADATA: {
|
|
9
|
+
en: {
|
|
10
|
+
direction: "ltr";
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
/** The document flow direction for one supported locale. */
|
|
14
|
+
export declare function textDirectionForLocale(locale: Locale): TextDirection;
|
|
15
|
+
//# sourceMappingURL=locale-metadata.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-metadata.d.ts","sourceRoot":"","sources":["../../../src/copy/lib/locale-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,qDAAqD;AACrD,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,KAAK,CAAC;AAE1C,MAAM,MAAM,cAAc,GAAG;IAC3B,QAAQ,CAAC,SAAS,EAAE,aAAa,CAAC;CACnC,CAAC;AAEF,0DAA0D;AAC1D,eAAO,MAAM,eAAe;;;;CAEwB,CAAC;AAErD,4DAA4D;AAC5D,wBAAgB,sBAAsB,CAAC,MAAM,EAAE,MAAM,GAAG,aAAa,CAEpE"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** Runtime metadata for every supported reader locale. */
|
|
2
|
+
export const LOCALE_METADATA = {
|
|
3
|
+
en: { direction: "ltr" },
|
|
4
|
+
};
|
|
5
|
+
/** The document flow direction for one supported locale. */
|
|
6
|
+
export function textDirectionForLocale(locale) {
|
|
7
|
+
return LOCALE_METADATA[locale].direction;
|
|
8
|
+
}
|
|
9
|
+
//# sourceMappingURL=locale-metadata.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-metadata.js","sourceRoot":"","sources":["../../../src/copy/lib/locale-metadata.ts"],"names":[],"mappings":"AASA,0DAA0D;AAC1D,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,EAAE,EAAE,EAAE,SAAS,EAAE,KAAK,EAAE;CAC0B,CAAC;AAErD,4DAA4D;AAC5D,MAAM,UAAU,sBAAsB,CAAC,MAAc;IACnD,OAAO,eAAe,CAAC,MAAM,CAAC,CAAC,SAAS,CAAC;AAC3C,CAAC"}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import type { Locale } from "./localized-text.js";
|
|
3
|
+
import { type LocaleSignals } from "./resolve-initial-locale.js";
|
|
4
|
+
/**
|
|
5
|
+
* The one thing a copy hook reads from React: which language the reader reads.
|
|
6
|
+
*
|
|
7
|
+
* It is deliberately the ONLY thing in context. A feature's phrases are closed
|
|
8
|
+
* over by its own hook (`createCopyHook`), so nothing every feature contributes
|
|
9
|
+
* to is ever read at render time — which is what keeps an orders label edit
|
|
10
|
+
* from touching products.
|
|
11
|
+
*
|
|
12
|
+
* Nothing here persists. The identity-owned user-settings document supplies a
|
|
13
|
+
* saved preference through props; null means Automatic and therefore follows
|
|
14
|
+
* the browser signal.
|
|
15
|
+
*/
|
|
16
|
+
export type LocaleSelection = {
|
|
17
|
+
readonly locale: Locale;
|
|
18
|
+
readonly setLocale: (locale: Locale) => void;
|
|
19
|
+
};
|
|
20
|
+
export type LocaleProviderProps = LocaleSignals & {
|
|
21
|
+
readonly children: ReactNode;
|
|
22
|
+
};
|
|
23
|
+
export declare function LocaleProvider({ children, ...signals }: LocaleProviderProps): ReactNode;
|
|
24
|
+
/**
|
|
25
|
+
* The reader's language.
|
|
26
|
+
*
|
|
27
|
+
* Answers `DEFAULT_LOCALE` outside a provider rather than throwing: a component
|
|
28
|
+
* test that renders one screen should not have to mount app chrome to assert
|
|
29
|
+
* what that screen says, and the app shell mounting the provider is proven
|
|
30
|
+
* where the shell is composed. A missing provider is a composition bug with one
|
|
31
|
+
* home, not a per-component hazard.
|
|
32
|
+
*/
|
|
33
|
+
export declare function useLocale(): Locale;
|
|
34
|
+
/** The reader's language and the way to change it — for a locale switcher. */
|
|
35
|
+
export declare function useLocaleSelection(): LocaleSelection;
|
|
36
|
+
//# sourceMappingURL=locale-provider.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-provider.d.ts","sourceRoot":"","sources":["../../../src/copy/lib/locale-provider.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AAEf,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAMlD,OAAO,EAEL,KAAK,aAAa,EAEnB,MAAM,6BAA6B,CAAC;AAErC;;;;;;;;;;;GAWG;AAEH,MAAM,MAAM,eAAe,GAAG;IAC5B,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,QAAQ,CAAC,SAAS,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,CAAC;CAC9C,CAAC;AAIF,MAAM,MAAM,mBAAmB,GAAG,aAAa,GAAG;IAChD,QAAQ,CAAC,QAAQ,EAAE,SAAS,CAAC;CAC9B,CAAC;AAEF,wBAAgB,cAAc,CAAC,EAC7B,QAAQ,EACR,GAAG,OAAO,EACX,EAAE,mBAAmB,GAAG,SAAS,CA8BjC;AAED;;;;;;;;GAQG;AACH,wBAAgB,SAAS,IAAI,MAAM,CAElC;AAED,8EAA8E;AAC9E,wBAAgB,kBAAkB,IAAI,eAAe,CAQpD"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createContext, useCallback, useContext, useMemo, useState, } from "react";
|
|
3
|
+
import { followLocaleSignals, initializeLocaleProviderState, selectLocale, } from "./logic/locale-provider-state.js";
|
|
4
|
+
import { DEFAULT_LOCALE, resolveInitialLocale, } from "./resolve-initial-locale.js";
|
|
5
|
+
const LocaleContext = createContext(null);
|
|
6
|
+
export function LocaleProvider({ children, ...signals }) {
|
|
7
|
+
const signalLocale = resolveInitialLocale(signals);
|
|
8
|
+
const [providerState, setProviderState] = useState(() => initializeLocaleProviderState(signalLocale));
|
|
9
|
+
const activeState = followLocaleSignals(providerState, signalLocale);
|
|
10
|
+
// React discards this render and retries before reconciling children, so a
|
|
11
|
+
// changed saved setting never commits one frame in the previous language.
|
|
12
|
+
if (activeState !== providerState) {
|
|
13
|
+
setProviderState(activeState);
|
|
14
|
+
}
|
|
15
|
+
const setLocale = useCallback((locale) => {
|
|
16
|
+
setProviderState((currentState) => selectLocale(followLocaleSignals(currentState, signalLocale), locale));
|
|
17
|
+
}, [signalLocale]);
|
|
18
|
+
const selection = useMemo(() => ({ locale: activeState.selectedLocale, setLocale }), [activeState.selectedLocale, setLocale]);
|
|
19
|
+
return (_jsx(LocaleContext.Provider, { value: selection, children: children }));
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The reader's language.
|
|
23
|
+
*
|
|
24
|
+
* Answers `DEFAULT_LOCALE` outside a provider rather than throwing: a component
|
|
25
|
+
* test that renders one screen should not have to mount app chrome to assert
|
|
26
|
+
* what that screen says, and the app shell mounting the provider is proven
|
|
27
|
+
* where the shell is composed. A missing provider is a composition bug with one
|
|
28
|
+
* home, not a per-component hazard.
|
|
29
|
+
*/
|
|
30
|
+
export function useLocale() {
|
|
31
|
+
return useContext(LocaleContext)?.locale ?? DEFAULT_LOCALE;
|
|
32
|
+
}
|
|
33
|
+
/** The reader's language and the way to change it — for a locale switcher. */
|
|
34
|
+
export function useLocaleSelection() {
|
|
35
|
+
const selection = useContext(LocaleContext);
|
|
36
|
+
if (selection === null) {
|
|
37
|
+
throw new Error("useLocaleSelection needs a <LocaleProvider> above it — only a mounted provider can change the reader's language");
|
|
38
|
+
}
|
|
39
|
+
return selection;
|
|
40
|
+
}
|
|
41
|
+
//# sourceMappingURL=locale-provider.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-provider.js","sourceRoot":"","sources":["../../../src/copy/lib/locale-provider.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,WAAW,EACX,UAAU,EACV,OAAO,EACP,QAAQ,GACT,MAAM,OAAO,CAAC;AAGf,OAAO,EACL,mBAAmB,EACnB,6BAA6B,EAC7B,YAAY,GACb,MAAM,kCAAkC,CAA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M,UAAU,kBAAkB;IAChC,MAAM,SAAS,GAAG,UAAU,CAAC,aAAa,CAAC,CAAC;IAC5C,IAAI,SAAS,KAAK,IAAI,EAAE,CAAC;QACvB,MAAM,IAAI,KAAK,CACb,iHAAiH,CAClH,CAAC;IACJ,CAAC;IACD,OAAO,SAAS,CAAC;AACnB,CAAC"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One phrase, every language, on one line.
|
|
3
|
+
*
|
|
4
|
+
* The alternative — a file per locale — puts the English and the Spanish of the
|
|
5
|
+
* same sentence in two places that only a tool can compare, so they drift and
|
|
6
|
+
* the drift is invisible until a reader hits it. Side by side, a missing
|
|
7
|
+
* translation is a missing property and the type system is the tool.
|
|
8
|
+
*
|
|
9
|
+
* `SUPPORTED_LOCALES` is `["en"]` today by decision, not by omission: the
|
|
10
|
+
* structure ships now and Spanish is added as a reviewed second pass. When that
|
|
11
|
+
* tuple grows, `assertCatalogParity` names every key that needs a translation —
|
|
12
|
+
* a far better worklist than a diff.
|
|
13
|
+
*/
|
|
14
|
+
/** Every language this product speaks, in preference order. */
|
|
15
|
+
export declare const SUPPORTED_LOCALES: readonly ["en"];
|
|
16
|
+
export type Locale = (typeof SUPPORTED_LOCALES)[number];
|
|
17
|
+
/** One phrase in every language this product speaks. */
|
|
18
|
+
export type LocalizedText = Readonly<Record<Locale, string>>;
|
|
19
|
+
/** A feature's words: flat keys, each holding one phrase per locale. */
|
|
20
|
+
export type CopyCatalog = Readonly<Record<string, LocalizedText>>;
|
|
21
|
+
/**
|
|
22
|
+
* Declare a catalog and keep its keys literal.
|
|
23
|
+
*
|
|
24
|
+
* The `const` type parameter is the whole point. Without it every key widens to
|
|
25
|
+
* `string`, `keyof typeof catalog` becomes `string`, and a typo'd key compiles
|
|
26
|
+
* happily — which is the exact failure this kit exists to make impossible.
|
|
27
|
+
*/
|
|
28
|
+
export declare function defineCopy<const T extends CopyCatalog>(catalog: T): T;
|
|
29
|
+
/** Narrow an arbitrary language tag to a locale this product speaks. */
|
|
30
|
+
export declare function isSupportedLocale(value: string): value is Locale;
|
|
31
|
+
/**
|
|
32
|
+
* Read one locale out of a side-by-side phrase.
|
|
33
|
+
*
|
|
34
|
+
* Structural on purpose: the contract kit declares its own `LocalizedText`
|
|
35
|
+
* because a contract lib may not reach `scope:shared`, and a value carrying the
|
|
36
|
+
* same properties is accepted here without either side importing the other.
|
|
37
|
+
* The application’s locale parity test is where the two tuples are
|
|
38
|
+
* pinned to each other.
|
|
39
|
+
*/
|
|
40
|
+
export declare function resolveLocalizedText(text: LocalizedText, locale: Locale): string;
|
|
41
|
+
//# sourceMappingURL=localized-text.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localized-text.d.ts","sourceRoot":"","sources":["../../../src/copy/lib/localized-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+DAA+D;AAC/D,eAAO,MAAM,iBAAiB,YAAI,IAAI,CAAU,CAAC;AAEjD,MAAM,MAAM,MAAM,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExD,wDAAwD;AACxD,MAAM,MAAM,aAAa,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;AAE7D,wEAAwE;AACxE,MAAM,MAAM,WAAW,GAAG,QAAQ,CAAC,MAAM,CAAC,MAAM,EAAE,aAAa,CAAC,CAAC,CAAC;AAElE;;;;;;GAMG;AACH,wBAAgB,UAAU,CAAC,KAAK,CAAC,CAAC,SAAS,WAAW,EAAE,OAAO,EAAE,CAAC,GAAG,CAAC,CAErE;AAED,wEAAwE;AACxE,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,MAAM,CAEhE;AAED;;;;;;;;GAQG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,aAAa,EACnB,MAAM,EAAE,MAAM,GACb,MAAM,CAER"}
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* One phrase, every language, on one line.
|
|
3
|
+
*
|
|
4
|
+
* The alternative — a file per locale — puts the English and the Spanish of the
|
|
5
|
+
* same sentence in two places that only a tool can compare, so they drift and
|
|
6
|
+
* the drift is invisible until a reader hits it. Side by side, a missing
|
|
7
|
+
* translation is a missing property and the type system is the tool.
|
|
8
|
+
*
|
|
9
|
+
* `SUPPORTED_LOCALES` is `["en"]` today by decision, not by omission: the
|
|
10
|
+
* structure ships now and Spanish is added as a reviewed second pass. When that
|
|
11
|
+
* tuple grows, `assertCatalogParity` names every key that needs a translation —
|
|
12
|
+
* a far better worklist than a diff.
|
|
13
|
+
*/
|
|
14
|
+
/** Every language this product speaks, in preference order. */
|
|
15
|
+
export const SUPPORTED_LOCALES = ["en"];
|
|
16
|
+
/**
|
|
17
|
+
* Declare a catalog and keep its keys literal.
|
|
18
|
+
*
|
|
19
|
+
* The `const` type parameter is the whole point. Without it every key widens to
|
|
20
|
+
* `string`, `keyof typeof catalog` becomes `string`, and a typo'd key compiles
|
|
21
|
+
* happily — which is the exact failure this kit exists to make impossible.
|
|
22
|
+
*/
|
|
23
|
+
export function defineCopy(catalog) {
|
|
24
|
+
return catalog;
|
|
25
|
+
}
|
|
26
|
+
/** Narrow an arbitrary language tag to a locale this product speaks. */
|
|
27
|
+
export function isSupportedLocale(value) {
|
|
28
|
+
return SUPPORTED_LOCALES.some((locale) => locale === value);
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Read one locale out of a side-by-side phrase.
|
|
32
|
+
*
|
|
33
|
+
* Structural on purpose: the contract kit declares its own `LocalizedText`
|
|
34
|
+
* because a contract lib may not reach `scope:shared`, and a value carrying the
|
|
35
|
+
* same properties is accepted here without either side importing the other.
|
|
36
|
+
* The application’s locale parity test is where the two tuples are
|
|
37
|
+
* pinned to each other.
|
|
38
|
+
*/
|
|
39
|
+
export function resolveLocalizedText(text, locale) {
|
|
40
|
+
return text[locale];
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=localized-text.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"localized-text.js","sourceRoot":"","sources":["../../../src/copy/lib/localized-text.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;GAYG;AAEH,+DAA+D;AAC/D,MAAM,CAAC,MAAM,iBAAiB,GAAG,CAAC,IAAI,CAAU,CAAC;AAUjD;;;;;;GAMG;AACH,MAAM,UAAU,UAAU,CAA8B,OAAU;IAChE,OAAO,OAAO,CAAC;AACjB,CAAC;AAED,wEAAwE;AACxE,MAAM,UAAU,iBAAiB,CAAC,KAAa;IAC7C,OAAO,iBAAiB,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,KAAK,KAAK,CAAC,CAAC;AAC9D,CAAC;AAED;;;;;;;;GAQG;AACH,MAAM,UAAU,oBAAoB,CAClC,IAAmB,EACnB,MAAc;IAEd,OAAO,IAAI,CAAC,MAAM,CAAC,CAAC;AACtB,CAAC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** First UTC instant of an exact YYYY-MM-DD date in a named business timezone. */
|
|
2
|
+
export declare function startOfCalendarDate(value: string, timeZone: string): string | null;
|
|
3
|
+
/** Inclusive final UTC millisecond of a business date, preserving short and long DST days. */
|
|
4
|
+
export declare function endOfCalendarDate(value: string, timeZone: string): string | null;
|
|
5
|
+
//# sourceMappingURL=calendar-date-boundaries.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-date-boundaries.d.ts","sourceRoot":"","sources":["../../../../src/copy/lib/logic/calendar-date-boundaries.ts"],"names":[],"mappings":"AAWA,kFAAkF;AAClF,wBAAgB,mBAAmB,CACjC,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAKf;AAED,8FAA8F;AAC9F,wBAAgB,iBAAiB,CAC/B,KAAK,EAAE,MAAM,EACb,QAAQ,EAAE,MAAM,GACf,MAAM,GAAG,IAAI,CAOf"}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { formatCalendarDateKey } from "../locale-formatting.js";
|
|
2
|
+
const CALENDAR_DATE_PATTERN = /^(\d{4})-(\d{2})-(\d{2})$/;
|
|
3
|
+
const SEARCH_MARGIN_MS = 36 * 60 * 60 * 1000;
|
|
4
|
+
/** First UTC instant of an exact YYYY-MM-DD date in a named business timezone. */
|
|
5
|
+
export function startOfCalendarDate(value, timeZone) {
|
|
6
|
+
const parts = parseCalendarDate(value);
|
|
7
|
+
if (parts === null)
|
|
8
|
+
return null;
|
|
9
|
+
const firstInstant = firstInstantOfDate(parts, timeZone);
|
|
10
|
+
return firstInstant === null ? null : new Date(firstInstant).toISOString();
|
|
11
|
+
}
|
|
12
|
+
/** Inclusive final UTC millisecond of a business date, preserving short and long DST days. */
|
|
13
|
+
export function endOfCalendarDate(value, timeZone) {
|
|
14
|
+
const parts = parseCalendarDate(value);
|
|
15
|
+
if (parts === null)
|
|
16
|
+
return null;
|
|
17
|
+
const firstInstant = firstInstantOfDate(parts, timeZone);
|
|
18
|
+
const nextInstant = firstInstantOfDate(nextCalendarDate(parts), timeZone);
|
|
19
|
+
if (firstInstant === null || nextInstant === null)
|
|
20
|
+
return null;
|
|
21
|
+
return new Date(nextInstant - 1).toISOString();
|
|
22
|
+
}
|
|
23
|
+
function firstInstantOfDate(parts, timeZone) {
|
|
24
|
+
const target = dateKey(parts);
|
|
25
|
+
const approximateUtc = Date.UTC(parts.year, parts.month - 1, parts.day);
|
|
26
|
+
let lower = approximateUtc - SEARCH_MARGIN_MS;
|
|
27
|
+
let upper = approximateUtc + SEARCH_MARGIN_MS;
|
|
28
|
+
while (lower < upper) {
|
|
29
|
+
const middle = lower + Math.floor((upper - lower) / 2);
|
|
30
|
+
if (formatCalendarDateKey(middle, timeZone) < target) {
|
|
31
|
+
lower = middle + 1;
|
|
32
|
+
}
|
|
33
|
+
else {
|
|
34
|
+
upper = middle;
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return formatCalendarDateKey(lower, timeZone) === target ? lower : null;
|
|
38
|
+
}
|
|
39
|
+
function parseCalendarDate(value) {
|
|
40
|
+
const match = CALENDAR_DATE_PATTERN.exec(value);
|
|
41
|
+
const year = match?.[1];
|
|
42
|
+
const month = match?.[2];
|
|
43
|
+
const day = match?.[3];
|
|
44
|
+
if (year === undefined || month === undefined || day === undefined)
|
|
45
|
+
return null;
|
|
46
|
+
const parts = { year: Number(year), month: Number(month), day: Number(day) };
|
|
47
|
+
const date = new Date(Date.UTC(parts.year, parts.month - 1, parts.day));
|
|
48
|
+
return date.getUTCFullYear() === parts.year &&
|
|
49
|
+
date.getUTCMonth() + 1 === parts.month &&
|
|
50
|
+
date.getUTCDate() === parts.day
|
|
51
|
+
? parts
|
|
52
|
+
: null;
|
|
53
|
+
}
|
|
54
|
+
function nextCalendarDate(parts) {
|
|
55
|
+
const next = new Date(Date.UTC(parts.year, parts.month - 1, parts.day + 1));
|
|
56
|
+
return {
|
|
57
|
+
year: next.getUTCFullYear(),
|
|
58
|
+
month: next.getUTCMonth() + 1,
|
|
59
|
+
day: next.getUTCDate(),
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
function dateKey(parts) {
|
|
63
|
+
return [
|
|
64
|
+
parts.year,
|
|
65
|
+
String(parts.month).padStart(2, "0"),
|
|
66
|
+
String(parts.day).padStart(2, "0"),
|
|
67
|
+
].join("-");
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=calendar-date-boundaries.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"calendar-date-boundaries.js","sourceRoot":"","sources":["../../../../src/copy/lib/logic/calendar-date-boundaries.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AAEhE,MAAM,qBAAqB,GAAG,2BAA2B,CAAC;AAC1D,MAAM,gBAAgB,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,CAAC,CAAC,CAAC;IACxE,OAAO,IAAI,CAAC,cAAc,EAAE,KAAK,KAAK,CAAC,IAAI;QACzC,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,KAAK,KAAK,CAAC,KAAK;QACtC,IAAI,CAAC,UAAU,EAAE,KAAK,KAAK,CAAC,GAAG;QAC/B,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,IAAI,CAAC;AACX,CAAC;AAED,SAAS,gBAAgB,CAAC,KAAwB;IAChD,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,KAAK,GAAG,CAAC,EAAE,KAAK,CAAC,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC;IAC5E,OAAO;QACL,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE;QAC3B,KAAK,EAAE,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC;QAC7B,GAAG,EAAE,IAAI,CAAC,UAAU,EAAE;KACvB,CAAC;AACJ,CAAC;AAED,SAAS,OAAO,CAAC,KAAwB;IACvC,OAAO;QACL,KAAK,CAAC,IAAI;QACV,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;QACpC,MAAM,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC;KACnC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AACd,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/** The provider's last resolved signals and the active in-session choice. */
|
|
2
|
+
export type LocaleProviderState<TLocale extends string> = {
|
|
3
|
+
readonly signalLocale: TLocale;
|
|
4
|
+
readonly selectedLocale: TLocale;
|
|
5
|
+
};
|
|
6
|
+
/** Begin with the locale resolved from account/browser signals. */
|
|
7
|
+
export declare function initializeLocaleProviderState<TLocale extends string>(signalLocale: TLocale): LocaleProviderState<TLocale>;
|
|
8
|
+
/** Apply an explicit in-session selection without changing its signal origin. */
|
|
9
|
+
export declare function selectLocale<TLocale extends string>(state: LocaleProviderState<TLocale>, selectedLocale: TLocale): LocaleProviderState<TLocale>;
|
|
10
|
+
/** Follow a changed saved/browser signal; unchanged signals keep local choice. */
|
|
11
|
+
export declare function followLocaleSignals<TLocale extends string>(state: LocaleProviderState<TLocale>, signalLocale: TLocale): LocaleProviderState<TLocale>;
|
|
12
|
+
//# sourceMappingURL=locale-provider-state.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-provider-state.d.ts","sourceRoot":"","sources":["../../../../src/copy/lib/logic/locale-provider-state.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,MAAM,MAAM,mBAAmB,CAAC,OAAO,SAAS,MAAM,IAAI;IACxD,QAAQ,CAAC,YAAY,EAAE,OAAO,CAAC;IAC/B,QAAQ,CAAC,cAAc,EAAE,OAAO,CAAC;CAClC,CAAC;AAEF,mEAAmE;AACnE,wBAAgB,6BAA6B,CAAC,OAAO,SAAS,MAAM,EAClE,YAAY,EAAE,OAAO,GACpB,mBAAmB,CAAC,OAAO,CAAC,CAE9B;AAED,iFAAiF;AACjF,wBAAgB,YAAY,CAAC,OAAO,SAAS,MAAM,EACjD,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACnC,cAAc,EAAE,OAAO,GACtB,mBAAmB,CAAC,OAAO,CAAC,CAG9B;AAED,kFAAkF;AAClF,wBAAgB,mBAAmB,CAAC,OAAO,SAAS,MAAM,EACxD,KAAK,EAAE,mBAAmB,CAAC,OAAO,CAAC,EACnC,YAAY,EAAE,OAAO,GACpB,mBAAmB,CAAC,OAAO,CAAC,CAG9B"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/** Begin with the locale resolved from account/browser signals. */
|
|
2
|
+
export function initializeLocaleProviderState(signalLocale) {
|
|
3
|
+
return { signalLocale, selectedLocale: signalLocale };
|
|
4
|
+
}
|
|
5
|
+
/** Apply an explicit in-session selection without changing its signal origin. */
|
|
6
|
+
export function selectLocale(state, selectedLocale) {
|
|
7
|
+
if (state.selectedLocale === selectedLocale)
|
|
8
|
+
return state;
|
|
9
|
+
return { ...state, selectedLocale };
|
|
10
|
+
}
|
|
11
|
+
/** Follow a changed saved/browser signal; unchanged signals keep local choice. */
|
|
12
|
+
export function followLocaleSignals(state, signalLocale) {
|
|
13
|
+
if (state.signalLocale === signalLocale)
|
|
14
|
+
return state;
|
|
15
|
+
return { signalLocale, selectedLocale: signalLocale };
|
|
16
|
+
}
|
|
17
|
+
//# sourceMappingURL=locale-provider-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"locale-provider-state.js","sourceRoot":"","sources":["../../../../src/copy/lib/logic/locale-provider-state.ts"],"names":[],"mappings":"AAMA,mEAAmE;AACnE,MAAM,UAAU,6BAA6B,CAC3C,YAAqB;IAErB,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACxD,CAAC;AAED,iFAAiF;AACjF,MAAM,UAAU,YAAY,CAC1B,KAAmC,EACnC,cAAuB;IAEvB,IAAI,KAAK,CAAC,cAAc,KAAK,cAAc;QAAE,OAAO,KAAK,CAAC;IAC1D,OAAO,EAAE,GAAG,KAAK,EAAE,cAAc,EAAE,CAAC;AACtC,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,mBAAmB,CACjC,KAAmC,EACnC,YAAqB;IAErB,IAAI,KAAK,CAAC,YAAY,KAAK,YAAY;QAAE,OAAO,KAAK,CAAC;IACtD,OAAO,EAAE,YAAY,EAAE,cAAc,EAAE,YAAY,EAAE,CAAC;AACxD,CAAC"}
|