@rexezuge/web 1.10.0 → 1.12.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.
Files changed (64) hide show
  1. package/README.md +81 -6
  2. package/dist/Button.d.ts +18 -2
  3. package/dist/Button.d.ts.map +1 -1
  4. package/dist/Button.js +1 -1
  5. package/dist/Button.js.map +3 -3
  6. package/dist/FocusInput.js +1 -1
  7. package/dist/FocusInput.js.map +3 -3
  8. package/dist/LanguageSelector.d.ts +22 -1
  9. package/dist/LanguageSelector.d.ts.map +1 -1
  10. package/dist/LanguageSelector.js +1 -1
  11. package/dist/LanguageSelector.js.map +3 -3
  12. package/dist/Spinner.d.ts +1 -1
  13. package/dist/Spinner.d.ts.map +1 -1
  14. package/dist/Spinner.js +1 -1
  15. package/dist/Spinner.js.map +3 -3
  16. package/dist/api.d.ts +8 -4
  17. package/dist/api.d.ts.map +1 -1
  18. package/dist/api.js +1 -1
  19. package/dist/api.js.map +3 -3
  20. package/dist/bookmarks.d.ts +50 -0
  21. package/dist/bookmarks.d.ts.map +1 -0
  22. package/dist/bookmarks.js +1 -0
  23. package/dist/bookmarks.js.map +7 -0
  24. package/dist/contractClient.d.ts +55 -0
  25. package/dist/contractClient.d.ts.map +1 -0
  26. package/dist/contractClient.js +1 -0
  27. package/dist/contractClient.js.map +7 -0
  28. package/dist/i18n.d.ts +110 -0
  29. package/dist/i18n.d.ts.map +1 -0
  30. package/dist/i18n.js +1 -0
  31. package/dist/i18n.js.map +7 -0
  32. package/dist/index.d.ts +13 -6
  33. package/dist/index.d.ts.map +1 -1
  34. package/dist/index.js +1 -1
  35. package/dist/index.js.map +3 -3
  36. package/dist/language.d.ts +30 -0
  37. package/dist/language.d.ts.map +1 -0
  38. package/dist/language.js +1 -0
  39. package/dist/language.js.map +7 -0
  40. package/dist/legacyPalette.d.ts +24 -0
  41. package/dist/legacyPalette.d.ts.map +1 -0
  42. package/dist/legacyPalette.js +1 -0
  43. package/dist/legacyPalette.js.map +7 -0
  44. package/dist/styles.css +99 -0
  45. package/dist/theme.d.ts +38 -7
  46. package/dist/theme.d.ts.map +1 -1
  47. package/dist/theme.js +1 -1
  48. package/dist/theme.js.map +3 -3
  49. package/dist/useNotice.d.ts +6 -3
  50. package/dist/useNotice.d.ts.map +1 -1
  51. package/dist/useNotice.js.map +2 -2
  52. package/dist/useResource.d.ts +107 -0
  53. package/dist/useResource.d.ts.map +1 -0
  54. package/dist/useResource.js +1 -0
  55. package/dist/useResource.js.map +7 -0
  56. package/dist/useSpaLanguage.d.ts +71 -39
  57. package/dist/useSpaLanguage.d.ts.map +1 -1
  58. package/dist/useSpaLanguage.js +1 -1
  59. package/dist/useSpaLanguage.js.map +3 -3
  60. package/dist/utils.d.ts +15 -6
  61. package/dist/utils.d.ts.map +1 -1
  62. package/dist/utils.js +1 -1
  63. package/dist/utils.js.map +3 -3
  64. package/package.json +21 -6
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/useResource.ts"],
4
+ "sourcesContent": ["import { useCallback, useEffect, useRef, useState } from 'react';\nimport type { DependencyList } from 'react';\nimport { ServiceError } from '@rexezuge/errors';\n\n/**\n * `useResource` / `useMutation`: the two data hooks every SPA rebuilt.\n *\n * ## Provenance\n *\n * Mail-Meow's `hooks/useAsyncResource.ts`, written after two of its three data\n * hooks lost their failures: `useProcessing` swallowed the error and rendered\n * \"no task runs yet\", and the shell read a transient list failure as signed-out.\n * Every other repo still hand-rolls `useEffect` + `useState` + a `cancelled`\n * flag per view. What changed in the kit version:\n *\n * - **Aborted, not just ignored.** The loader gets an `AbortSignal`, aborted when\n * the deps change, on `reload`, and on unmount, so a superseded request stops\n * costing a Worker invocation. Hand it to `createApiClient`'s `signal` or to a\n * contract call's options.\n * - **Stale-response guard.** Only the latest run may set state, so a slow first\n * response cannot overwrite a fast second one. Mail-Meow's per-run `cancelled`\n * flag did this, and the kit keeps it.\n * - **A typed error.** `error` is an `Error` (`createApiClient` rejects with a\n * `ServiceError`, so `error.status` is there to narrow on). A non-`Error` throw\n * is normalized through `ServiceError.from`, never stored raw as `unknown`.\n * - **`null`, not `undefined`, for absent** (the kit's null rule): `data` and\n * `error` are `null` until there is one.\n * - Data is kept across a reload, so a refresh does not blank the view, and is\n * cleared on an error only if you ask (`keepDataOnError: false`).\n *\n * Deliberately thin: no cache, no dedup across components, no retries. The RFC\n * keeps react-query out until a repo proves it needs it.\n */\n\ntype ResourceStatus = 'idle' | 'loading' | 'ready' | 'error';\n\ninterface ResourceState<T> {\n /**\n The last loaded value, or `null` before the first success.\n */\n data: T | null;\n /**\n The last failure, or `null`. Cleared by the next success.\n */\n error: Error | null;\n status: ResourceStatus;\n isLoading: boolean;\n /**\n Run the loader again (aborting a run in flight).\n */\n reload: () => void;\n}\n\ninterface UseResourceOptions {\n /**\n Skip loading while `false` (a dependency not known yet). Defaults to `true`.\n */\n enabled?: boolean;\n /**\n Keep the last `data` when a later run fails. Defaults to `true`.\n */\n keepDataOnError?: boolean;\n}\n\nfunction toError(reason: unknown): Error {\n return reason instanceof Error ? reason : ServiceError.from(reason);\n}\n\nfunction isAbort(reason: unknown, signal: AbortSignal): boolean {\n return signal.aborted || (reason instanceof Error && reason.name === 'AbortError');\n}\n\n/**\n * Load data for a view:\n *\n * ```ts\n * const items = useResource((signal) => api.listItems({ query: { cursor } }, { signal }), [cursor]);\n * ```\n *\n * `deps` works like an effect's: the loader re-runs when one changes. The loader\n * itself is read from the latest render, so it may close over anything.\n */\nfunction useResource<T>(\n loader: (signal: AbortSignal) => Promise<T>,\n deps: DependencyList,\n { enabled = true, keepDataOnError = true }: Readonly<UseResourceOptions> = {},\n): ResourceState<T> {\n const [data, setData] = useState<T | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const [status, setStatus] = useState<ResourceStatus>('idle');\n const [nonce, setNonce] = useState(0);\n const loaderRef = useRef(loader);\n const keepRef = useRef(keepDataOnError);\n useEffect(() => {\n loaderRef.current = loader;\n keepRef.current = keepDataOnError;\n });\n\n useEffect(() => {\n if (!enabled) return;\n const controller = new AbortController();\n // Set from a microtask, not synchronously in the effect body (an extra\n // render before the request even starts), exactly as Mail-Meow did.\n queueMicrotask(() => {\n if (controller.signal.aborted) return;\n setStatus('loading');\n });\n loaderRef\n .current(controller.signal)\n .then((result) => {\n if (controller.signal.aborted) return;\n setData(() => result);\n setError(null);\n setStatus('ready');\n })\n .catch((reason: unknown) => {\n // Superseded or unmounted: the newer run, or nobody, owns the state.\n if (isAbort(reason, controller.signal)) return;\n setError(toError(reason));\n if (!keepRef.current) setData(null);\n setStatus('error');\n });\n return () => {\n controller.abort();\n };\n // eslint-disable-next-line react-hooks/exhaustive-deps -- `deps` is the caller's dependency list, by design\n }, [...deps, enabled, nonce]);\n\n const reload = useCallback(() => {\n setNonce((current) => current + 1);\n }, []);\n\n return { data, error, status, isLoading: status === 'loading', reload };\n}\n\ntype MutationStatus = 'idle' | 'pending' | 'success' | 'error';\n\ninterface MutationState<I, R> {\n /**\n Run it, and reject with the failure. For a caller that awaits the result.\n */\n mutateAsync: (input: I) => Promise<R>;\n /**\n Run it, fire-and-forget: the failure goes to `error`, never to an unhandled rejection.\n */\n mutate: (input: I) => void;\n /**\n The latest run's result, or `null`.\n */\n data: R | null;\n error: Error | null;\n status: MutationStatus;\n isPending: boolean;\n /**\n Back to `idle`, aborting a run in flight.\n */\n reset: () => void;\n}\n\n/**\n * A write from an event handler:\n *\n * ```ts\n * const rename = useMutation((input: { id: string; name: string }, signal) =>\n * api.renameItem({ params: { id: input.id }, body: { name: input.name } }, { signal }),\n * );\n * <Button loading={rename.isPending} onClick={() => rename.mutate({ id, name })}>Save</Button>\n * ```\n *\n * The latest call owns the state, and an earlier one still resolves its own\n * promise. Unmounting aborts the call in flight and stops every state update.\n */\nfunction useMutation<I, R>(fn: (input: I, signal: AbortSignal) => Promise<R>): MutationState<I, R> {\n const [data, setData] = useState<R | null>(null);\n const [error, setError] = useState<Error | null>(null);\n const [status, setStatus] = useState<MutationStatus>('idle');\n const fnRef = useRef(fn);\n const currentRef = useRef<AbortController | null>(null);\n const mountedRef = useRef(true);\n useEffect(() => {\n fnRef.current = fn;\n });\n useEffect(() => {\n mountedRef.current = true;\n return () => {\n mountedRef.current = false;\n currentRef.current?.abort();\n };\n }, []);\n\n const mutateAsync = useCallback(async (input: I): Promise<R> => {\n const controller = new AbortController();\n currentRef.current = controller;\n const owns = (): boolean => mountedRef.current && currentRef.current === controller;\n setStatus('pending');\n setError(null);\n try {\n const result = await fnRef.current(input, controller.signal);\n if (owns()) {\n setData(() => result);\n setStatus('success');\n }\n return result;\n } catch (reason: unknown) {\n const failure = toError(reason);\n if (owns()) {\n setError(failure);\n setStatus('error');\n }\n throw failure;\n }\n }, []);\n\n const mutate = useCallback(\n (input: I): void => {\n mutateAsync(input).catch(() => {\n // Recorded in `error` by mutateAsync; nothing to rethrow to.\n });\n },\n [mutateAsync],\n );\n\n const reset = useCallback(() => {\n currentRef.current?.abort();\n currentRef.current = null;\n setData(null);\n setError(null);\n setStatus('idle');\n }, []);\n\n return { mutateAsync, mutate, data, error, status, isPending: status === 'pending', reset };\n}\n\nexport { useMutation, useResource };\nexport type { MutationState, MutationStatus, ResourceState, ResourceStatus, UseResourceOptions };\n"],
5
+ "mappings": "+EAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,UAAAC,EAAQ,YAAAC,MAAgB,QAEzD,OAAS,gBAAAC,MAAoB,mBA8D7B,SAASC,EAAQC,EAAe,CAC9B,OAAOA,aAAkB,MAAQA,EAASF,EAAa,KAAKE,CAAM,CACpE,CAFSC,EAAAF,EAAA,WAIT,SAASG,EAAQF,EAAiBG,EAAmB,CACnD,OAAOA,EAAO,SAAYH,aAAkB,OAASA,EAAO,OAAS,YACvE,CAFSC,EAAAC,EAAA,WAcT,SAASE,EACPC,EACAC,EACA,CAAE,QAAAC,EAAU,GAAM,gBAAAC,EAAkB,EAAI,EAAmC,CAAA,EAAE,CAE7E,KAAM,CAACC,EAAMC,CAAO,EA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AAO4B,CAAE,EACjBE,EAAa9B,EAA+B,IAAI,EAChD+B,EAAa/B,EAAO,EAAI,EAC9BD,EAAU,IAAK,CACb8B,EAAM,QAAUD,CAClB,CAAC,EACD7B,EAAU,KACRgC,EAAW,QAAU,GACd,IAAK,CACVA,EAAW,QAAU,GACrBD,EAAW,SAAS,MAAK,CAC3B,GACC,CAAA,CAAE,EAEL,MAAME,EAAclC,EAAY,MAAOmC,GAAwB,CAC7D,MAAMV,EAAa,IAAI,gBACvBO,EAAW,QAAUP,EACrB,MAAMW,EAAO7B,EAAA,IAAe0B,EAAW,SAAWD,EAAW,UAAYP,EAA5D,QACbL,EAAU,SAAS,EACnBF,EAAS,IAAI,EACb,GAAI,CACF,MAAMQ,EAAS,MAAMK,EAAM,QAAQI,EAAOV,EAAW,MAAM,EAC3D,OAAIW,EAAI,IACNpB,EAAQ,IAAMU,CAAM,EACpBN,EAAU,SAAS,GAEdM,CACT,OAASpB,EAAiB,CACxB,MAAM+B,EAAUhC,EAAQC,CAAM,EAC9B,MAAI8B,EAAI,IACNlB,EAASmB,CAAO,EAChBjB,EAAU,OAAO,GAEbiB,CACR,CACF,EAAG,CAAA,CAAE,EAECC,EAAStC,EACZmC,GAAkB,CACjBD,EAAYC,CAAK,EAAE,MAAM,IAAK,CAE9B,CAAC,CACH,EACA,CAACD,CAAW,CAAC,EAGTK,EAAQvC,EAAY,IAAK,CAC7BgC,EAAW,SAAS,MAAK,EACzBA,EAAW,QAAU,KACrBhB,EAAQ,IAAI,EACZE,EAAS,IAAI,EACbE,EAAU,MAAM,CAClB,EAAG,CAAA,CAAE,EAEL,MAAO,CAAE,YAAAc,EAAa,OAAAI,EAAQ,KAAAvB,EAAM,MAAAE,EAAO,OAAAE,EAAQ,UAAWA,IAAW,UAAW,MAAAoB,CAAK,CAC3F,CA3DShC,EAAAsB,EAAA",
6
+ "names": ["useCallback", "useEffect", "useRef", "useState", "ServiceError", "toError", "reason", "__name", "isAbort", "signal", "useResource", "loader", "deps", "enabled", "keepDataOnError", "data", "setData", "error", "setError", "status", "setStatus", "nonce", "setNonce", "loaderRef", "keepRef", "controller", "result", "reload", "current", "useMutation", "fn", "fnRef", "currentRef", "mountedRef", "mutateAsync", "input", "owns", "failure", "mutate", "reset"]
7
+ }
@@ -4,35 +4,36 @@ import type { LanguageTag } from '@rexezuge/shared';
4
4
  *
5
5
  * ## Provenance
6
6
  *
7
- * `hooks/useSpaLanguage.ts` in **AWS-AccessBridge**, **Durable-DAV**,
8
- * **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six
9
- * copies that agree on the detection precedence and disagree on everything
10
- * else, because each one also owned its app's i18next wiring:
7
+ * `hooks/useSpaLanguage.ts` in **Agent-Router**, **AWS-AccessBridge**,
8
+ * **Durable-DAV**, **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic**,
9
+ * **Mail-Meow** and **Mail-Otter**. The eight copies agree on the detection
10
+ * precedence (backend `preferredLanguage` > `localStorage` > `navigator.language`
11
+ * > fallback, first *present* source wins) and on `<html lang>` sync.
11
12
  *
12
- * - **Detection precedence.** All six: backend `preferredLanguage` when present
13
- * > `localStorage` > `navigator.language` > `en`, with the *first present
14
- * source* winning rather than the first *supported* one — AWS's
15
- * `lib/language.ts` spells out why: an unsupported backend value falls to
16
- * `en` rather than to the next source, because the backend value is the
17
- * user's own choice and silently replacing it with whatever the browser
18
- * reports would flip the UI the moment the profile loaded.
19
- * - **`<html lang>` sync**, in all six, guarded because a non-browser
20
- * environment has no `document`.
21
- * - **Bundle loading, `languageChanged` bridging, and the backend write** —
22
- * Mail-Otter/AWS `await updatePreferredLanguage(...)`, the others
23
- * localStorage-only. These are *left to the app*: the kit hook keeps
24
- * i18next out so it can be exercised without an i18n instance, and a caller
25
- * that wants the authoritative save calls its own API from its `setLanguage`
26
- * wrapper.
27
- * - **`languageStatus`/`languagePending`** — left out for the same reason: both
28
- * exist to describe *bundle* loading, which the app now owns.
13
+ * ## The adoption gap this closes
29
14
  *
30
- * ## Normalization
15
+ * The first kit version left bundle loading, the backend write and the
16
+ * `languageStatus`/`languagePending` pair to the app, to keep i18next out of the
17
+ * hook. That is why none of the eight adopted it: those three things are most of
18
+ * every copy, so adopting the kit hook meant keeping the copy *and* the hook.
19
+ * They come in now through two structural ports. The hook still imports no i18n
20
+ * library:
31
21
  *
32
- * The hook returns `{ language, setLanguage }`. `setLanguage` is synchronous and
33
- * total: it resolves the tag, persists it, and syncs `<html lang>`; the caller
34
- * awaits its own bundle load before or after calling it. `supported` comes back
35
- * too, so a `LanguageSelector` does not need a second import to render the list.
22
+ * - **`runtime`** ({@link LanguageRuntime}): `load(tag)` loads the bundle and
23
+ * switches the i18n instance, and the optional `subscribe(listener)` reports a
24
+ * language change made elsewhere (i18next's `languageChanged`). `createSpaI18n`
25
+ * from `@rexezuge/web/i18n` returns an object that satisfies it.
26
+ * - **`persist`**: the authoritative save (`PUT /user/me`), awaited after the
27
+ * bundle loaded.
28
+ *
29
+ * With them the hook reports `status` (`loading` until the bundle for the
30
+ * current tag is in, `error` if it failed) and `pending` (a change is in
31
+ * flight), and `changeLanguage` is the one-call manual flow every copy
32
+ * hand-rolled. Strings stay the app's: a failure is a `false` from
33
+ * `changeLanguage` and `status: 'error'`, never a notice text.
34
+ *
35
+ * Without a runtime the hook behaves exactly as before: `status` is always
36
+ * `ready`, and `setLanguage` is synchronous.
36
37
  */
37
38
  /**
38
39
  The tags offered when a caller does not say. English-only is the safe default.
@@ -47,14 +48,23 @@ The `localStorage` key used when a caller does not say.
47
48
  */
48
49
  declare const DEFAULT_LANGUAGE_STORAGE_KEY = "language";
49
50
  /**
50
- * Resolves a tag against the supported list: an exact match wins, then the
51
- * primary subtag (`de-DE` resolves to a supported `de`), then the fallback.
52
- *
53
- * The prefix step is why a browser reporting `en-US` does not defeat an
54
- * English-only app, and why a browser reporting `zh-TW` does not land on
55
- * `zh-CN` when both are supported.
51
+ * The port to the app's i18n instance. Structural: `createSpaI18n` satisfies it,
52
+ * and so does any object with these members.
56
53
  */
57
- declare function resolveLanguageTag(value: string | null | undefined, supported: readonly LanguageTag[], fallback: LanguageTag): LanguageTag;
54
+ interface LanguageRuntime {
55
+ /**
56
+ Make `tag` the rendered language, loading its bundle first if needed.
57
+ */
58
+ load(tag: LanguageTag): Promise<void>;
59
+ /**
60
+ Report a language change made outside the hook. Returns the unsubscribe.
61
+ */
62
+ subscribe?(listener: (tag: string) => void): () => void;
63
+ }
64
+ /**
65
+ `loading` until the current tag's bundle is in; `error` when loading or saving failed.
66
+ */
67
+ type LanguageStatus = 'loading' | 'ready' | 'error';
58
68
  interface UseSpaLanguageOptions {
59
69
  /**
60
70
  * The backend-authoritative preference (a user's `preferredLanguage`), or
@@ -73,6 +83,14 @@ interface UseSpaLanguageOptions {
73
83
  The tag used when nothing supported resolves. Defaults to `en`.
74
84
  */
75
85
  fallbackLanguage?: LanguageTag;
86
+ /**
87
+ Loads bundles and switches the i18n instance. Keep it stable (a module constant).
88
+ */
89
+ runtime?: LanguageRuntime;
90
+ /**
91
+ Saves an explicit choice to the backend. Awaited by `changeLanguage`.
92
+ */
93
+ persist?: (tag: LanguageTag) => Promise<void>;
76
94
  }
77
95
  interface UseSpaLanguageResult {
78
96
  /**
@@ -80,18 +98,32 @@ interface UseSpaLanguageResult {
80
98
  */
81
99
  language: LanguageTag;
82
100
  /**
83
- * Switches the language: resolves the tag, persists it, and syncs
84
- * `<html lang>`. An unsupported tag resolves to the fallback rather than
85
- * being ignored, so a mistake is visible instead of silent.
101
+ * Switches the language immediately: resolves the tag, persists it locally, and
102
+ * syncs `<html lang>`. An unsupported tag resolves to the fallback rather than
103
+ * being ignored, so a mistake is visible instead of silent. With a `runtime`,
104
+ * the bundle loads afterwards and `status` follows it. It never calls `persist`.
86
105
  */
87
106
  setLanguage: (tag: string) => void;
107
+ /**
108
+ * The manual-change flow: load the bundle, `persist`, then commit the tag and
109
+ * store it locally. Resolves `true` on success and `false` on failure (or when
110
+ * a change is already in flight). On failure the previous language is kept and
111
+ * reloaded. Show your own notice on `false`.
112
+ */
113
+ changeLanguage: (tag: string) => Promise<boolean>;
88
114
  /**
89
115
  The tags offered, as resolved — render this list in a selector.
90
116
  */
91
117
  supported: readonly LanguageTag[];
118
+ status: LanguageStatus;
119
+ /**
120
+ A `changeLanguage` call is in flight. Disable the selector on it.
121
+ */
122
+ pending: boolean;
92
123
  }
93
- declare function useSpaLanguage({ preferred, supported, storageKey, fallbackLanguage, }?: Readonly<UseSpaLanguageOptions>): UseSpaLanguageResult;
94
- export { DEFAULT_FALLBACK_LANGUAGE, DEFAULT_LANGUAGE_STORAGE_KEY, DEFAULT_SUPPORTED_LANGUAGES, resolveLanguageTag, useSpaLanguage };
95
- export type { UseSpaLanguageOptions, UseSpaLanguageResult };
124
+ declare function useSpaLanguage({ preferred, supported, storageKey, fallbackLanguage, runtime, persist, }?: Readonly<UseSpaLanguageOptions>): UseSpaLanguageResult;
125
+ export { DEFAULT_FALLBACK_LANGUAGE, DEFAULT_LANGUAGE_STORAGE_KEY, DEFAULT_SUPPORTED_LANGUAGES, useSpaLanguage };
126
+ export { resolveLanguageTag } from './language.ts';
127
+ export type { LanguageRuntime, LanguageStatus, UseSpaLanguageOptions, UseSpaLanguageResult };
96
128
  export { canonicalizeLanguageTag, type LanguageTag } from '@rexezuge/shared';
97
129
  //# sourceMappingURL=useSpaLanguage.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useSpaLanguage.d.ts","sourceRoot":"","sources":["../src/useSpaLanguage.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAEpD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;EAEE;AACF,QAAA,MAAM,2BAA2B,EAAE,SAAS,WAAW,EAAW,CAAC;AAEnE;;EAEE;AACF,QAAA,MAAM,yBAAyB,EAAE,WAAkB,CAAC;AAEpD;;EAEE;AACF,QAAA,MAAM,4BAA4B,aAAa,CAAC;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uC,EACvC,UAAyC,EACzC,gBAA4C,EAC5C,OAAO,EACP,OAAO,GACR,GAAE,QAAQ,CAAC,qBAAqB,CAAM,GAAG,oBAAoB,CAkI7D;AAED,OAAO,EAAE,yBAAyB,EAAE,4BAA4B,EAAE,2BAA2B,EAAE,cAAc,EAAE,CAAC;AAChH,OAAO,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AACnD,YAAY,EAAE,eAAe,EAAE,cAAc,EAAE,qBAAqB,EAAE,oBAAoB,EAAE,CAAC;AAE7F,OAAO,EAAE,uBAAuB,EAAE,KAAK,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1 +1 @@
1
- var d=Object.defineProperty;var r=(t,n)=>d(t,"name",{value:n,configurable:!0});import{useCallback as h,useEffect as G,useMemo as U,useState as p}from"react";import{canonicalizeLanguageTag as L}from"@rexezuge/shared";const f=["en"],A="en",y="language";function _(t){return t.map(n=>{const e=L(n);return{tag:n,key:e,primary:e.split("-",1)[0]??e}})}r(_,"describeSupported");function s(t,n,e){if(typeof t!="string"||t.trim()==="")return e;const u=L(t),i=u.split("-",1)[0]??u;let o=null;for(const a of _(n)){if(a.key===u)return a.tag;o===null&&a.primary===i&&(o=a.tag)}return o??e}r(s,"resolveLanguageTag");function x(t){try{return globalThis.localStorage?.getItem(t)??null}catch{return null}}r(x,"readStoredLanguage");function P(t,n){try{globalThis.localStorage?.setItem(t,n)}catch{}}r(P,"writeStoredLanguage");function D(){try{return globalThis.navigator?.language??null}catch{return null}}r(D,"readNavigatorLanguage");function F({preferred:t,supported:n=f,storageKey:e=y,fallbackLanguage:u=A}={}){const i=n.join(" "),o=U(()=>i===""?[]:i.split(" "),[i]),[a,l]=p(()=>s(t??x(e)??D(),o,u)),[E,S]=p(t);if(t!==E&&(S(t),t!=null&&t.trim()!=="")){const c=s(t,o,u);c!==a&&l(c)}G(()=>{try{document.documentElement.lang=a}catch{}},[a]);const T=h(c=>{const g=s(c,o,u);l(m=>m===g?m:g),P(e,g)},[o,u,e]);return{language:a,setLanguage:T,supported:o}}r(F,"useSpaLanguage");import{canonicalizeLanguageTag as M}from"@rexezuge/shared";export{A as DEFAULT_FALLBACK_LANGUAGE,y as DEFAULT_LANGUAGE_STORAGE_KEY,f as DEFAULT_SUPPORTED_LANGUAGES,M as canonicalizeLanguageTag,s as resolveLanguageTag,F as useSpaLanguage};
1
+ var O=Object.defineProperty;var G=(r,p)=>O(r,"name",{value:p,configurable:!0});import{useCallback as U,useEffect as L,useMemo as j,useRef as _,useState as g}from"react";import{detectLanguage as z,resolveLanguageTag as A,writeStoredLanguage as y}from"./language.js";const P=["en"],v="en",R="language";function B({preferred:r,supported:p=P,storageKey:i=R,fallbackLanguage:u=v,runtime:e,persist:S}={}){const E=p.join(" "),o=j(()=>E===""?[]:E.split(" "),[E]),[s,f]=g(()=>z({preferred:r,supported:o,fallback:u,storageKey:i})),[w,c]=g(e===void 0?"ready":"loading"),[T,h]=g(!1),l=_(!1),a=_(null),[D,F]=g(r);if(r!==D&&(F(r),!T&&r!==void 0&&r!==null&&r.trim()!=="")){const t=A(r,o,u);t!==s&&f(t)}L(()=>{if(e===void 0||l.current||a.current===s)return;let t=!1;return c("loading"),e.load(s).then(()=>{t||(a.current=s,c("ready"))}).catch(()=>{t||c("error")}),()=>{t=!0}},[e,s]),L(()=>{if(e?.subscribe!==void 0)return e.subscribe(t=>{const n=A(t,o,u);a.current=n,f(n),c("ready")})},[e,o,u]),L(()=>{try{document.documentElement.lang=s}catch{}},[s]);const N=U(t=>{const n=A(t,o,u);f(d=>d===n?d:n),y(i,n)},[o,u,i]),C=U(async t=>{if(l.current)return!1;const n=A(t,o,u),d=s;l.current=!0,h(!0),c("loading");try{return e!==void 0&&(await e.load(n),a.current=n),await S?.(n),y(i,n),f(n),c("ready"),!0}catch{let x=!0;return e!==void 0&&a.current!==d&&(a.current=d,x=await e.load(d).then(()=>!0).catch(()=>!1)),c(x?"ready":"error"),!1}finally{l.current=!1,h(!1)}},[o,u,i,s,e,S]);return{language:s,setLanguage:N,changeLanguage:C,supported:o,status:w,pending:T}}G(B,"useSpaLanguage");import{resolveLanguageTag as I}from"./language.js";import{canonicalizeLanguageTag as Q}from"@rexezuge/shared";export{v as DEFAULT_FALLBACK_LANGUAGE,R as DEFAULT_LANGUAGE_STORAGE_KEY,P as DEFAULT_SUPPORTED_LANGUAGES,Q as canonicalizeLanguageTag,I as resolveLanguageTag,B as useSpaLanguage};
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/useSpaLanguage.ts"],
4
- "sourcesContent": ["import { useCallback, useEffect, useMemo, useState } from 'react';\nimport { canonicalizeLanguageTag } from '@rexezuge/shared';\nimport type { LanguageTag } from '@rexezuge/shared';\n\n/**\n * The language the SPA is rendering, and the setter that changes it.\n *\n * ## Provenance\n *\n * `hooks/useSpaLanguage.ts` in **AWS-AccessBridge**, **Durable-DAV**,\n * **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six\n * copies that agree on the detection precedence and disagree on everything\n * else, because each one also owned its app's i18next wiring:\n *\n * - **Detection precedence.** All six: backend `preferredLanguage` when present\n * > `localStorage` > `navigator.language` > `en`, with the *first present\n * source* winning rather than the first *supported* one — AWS's\n * `lib/language.ts` spells out why: an unsupported backend value falls to\n * `en` rather than to the next source, because the backend value is the\n * user's own choice and silently replacing it with whatever the browser\n * reports would flip the UI the moment the profile loaded.\n * - **`<html lang>` sync**, in all six, guarded because a non-browser\n * environment has no `document`.\n * - **Bundle loading, `languageChanged` bridging, and the backend write** —\n * Mail-Otter/AWS `await updatePreferredLanguage(...)`, the others\n * localStorage-only. These are *left to the app*: the kit hook keeps\n * i18next out so it can be exercised without an i18n instance, and a caller\n * that wants the authoritative save calls its own API from its `setLanguage`\n * wrapper.\n * - **`languageStatus`/`languagePending`** — left out for the same reason: both\n * exist to describe *bundle* loading, which the app now owns.\n *\n * ## Normalization\n *\n * The hook returns `{ language, setLanguage }`. `setLanguage` is synchronous and\n * total: it resolves the tag, persists it, and syncs `<html lang>`; the caller\n * awaits its own bundle load before or after calling it. `supported` comes back\n * too, so a `LanguageSelector` does not need a second import to render the list.\n */\n\n/**\nThe tags offered when a caller does not say. English-only is the safe default.\n*/\nconst DEFAULT_SUPPORTED_LANGUAGES: readonly LanguageTag[] = ['en'];\n\n/**\nThe tag used when nothing supported can be resolved.\n*/\nconst DEFAULT_FALLBACK_LANGUAGE: LanguageTag = 'en';\n\n/**\nThe `localStorage` key used when a caller does not say.\n*/\nconst DEFAULT_LANGUAGE_STORAGE_KEY = 'language';\n\n/**\nOne entry of the supported list, pre-canonicalized for comparison.\n*/\ninterface SupportedLanguage {\n /**\n The tag as the caller spells it — what the hook returns.\n */\n tag: LanguageTag;\n /**\n Its canonical form, for matching.\n */\n key: string;\n /**\n Its primary subtag (`zh` for `zh-CN`).\n */\n primary: string;\n}\n\n/**\nThe supported list in canonical form, computed once per render of the hook.\n*/\nfunction describeSupported(supported: readonly LanguageTag[]): SupportedLanguage[] {\n return supported.map((tag) => {\n const key = canonicalizeLanguageTag(tag);\n return { tag, key, primary: key.split('-', 1)[0] ?? key };\n });\n}\n\n/**\n * Resolves a tag against the supported list: an exact match wins, then the\n * primary subtag (`de-DE` resolves to a supported `de`), then the fallback.\n *\n * The prefix step is why a browser reporting `en-US` does not defeat an\n * English-only app, and why a browser reporting `zh-TW` does not land on\n * `zh-CN` when both are supported.\n */\nfunction resolveLanguageTag(value: string | null | undefined, supported: readonly LanguageTag[], fallback: LanguageTag): LanguageTag {\n if (typeof value !== 'string' || value.trim() === '') {\n return fallback;\n }\n // The shared canonicalizer maps a degenerate tag to `en`, so the empty check\n // above has to happen first — otherwise an empty stored value would silently\n // resolve to `en` instead of the caller's fallback.\n const key = canonicalizeLanguageTag(value);\n const primary = key.split('-', 1)[0] ?? key;\n let prefixMatch: LanguageTag | null = null;\n for (const entry of describeSupported(supported)) {\n if (entry.key === key) {\n return entry.tag;\n }\n if (prefixMatch === null && entry.primary === primary) {\n prefixMatch = entry.tag;\n }\n }\n return prefixMatch ?? fallback;\n}\n\nfunction readStoredLanguage(storageKey: string): string | null {\n try {\n return globalThis.localStorage?.getItem(storageKey) ?? null;\n } catch {\n // Private-mode Safari and a blocked-storage context both throw. Detection\n // carries on without the stored value; the language still works.\n return null;\n }\n}\n\nfunction writeStoredLanguage(storageKey: string, language: LanguageTag): void {\n try {\n globalThis.localStorage?.setItem(storageKey, language);\n } catch {\n // Non-fatal: the selection still applies to this session, it just does not\n // survive a reload.\n }\n}\n\nfunction readNavigatorLanguage(): string | null {\n try {\n return globalThis.navigator?.language ?? null;\n } catch {\n return null;\n }\n}\n\ninterface UseSpaLanguageOptions {\n /**\n * The backend-authoritative preference (a user's `preferredLanguage`), or\n * `null`/`undefined` while the profile is not known. Adopted when it changes.\n */\n preferred?: string | null;\n /**\n The tags the app ships bundles for. Memoize it: it is a dependency.\n */\n supported?: readonly LanguageTag[];\n /**\n The `localStorage` key the choice is persisted under.\n */\n storageKey?: string;\n /**\n The tag used when nothing supported resolves. Defaults to `en`.\n */\n fallbackLanguage?: LanguageTag;\n}\n\ninterface UseSpaLanguageResult {\n /**\n The tag currently in effect — a member of `supported`.\n */\n language: LanguageTag;\n /**\n * Switches the language: resolves the tag, persists it, and syncs\n * `<html lang>`. An unsupported tag resolves to the fallback rather than\n * being ignored, so a mistake is visible instead of silent.\n */\n setLanguage: (tag: string) => void;\n /**\n The tags offered, as resolved — render this list in a selector.\n */\n supported: readonly LanguageTag[];\n}\n\nfunction useSpaLanguage({\n preferred,\n supported = DEFAULT_SUPPORTED_LANGUAGES,\n storageKey = DEFAULT_LANGUAGE_STORAGE_KEY,\n fallbackLanguage = DEFAULT_FALLBACK_LANGUAGE,\n}: Readonly<UseSpaLanguageOptions> = {}): UseSpaLanguageResult {\n // Serialized so an inline `supported` array literal does not change identity\n // on every render and re-run the effects below. Tags never contain spaces.\n const supportedKey = supported.join(' ');\n const supportedLanguages = useMemo<readonly LanguageTag[]>(() => (supportedKey === '' ? [] : supportedKey.split(' ')), [supportedKey]);\n\n const [language, setLanguageState] = useState<LanguageTag>(() =>\n // Precedence: backend > stored > navigator > fallback. The backend value is\n // undefined on a first paint and arrives later, which is what the adoption\n // below is for.\n resolveLanguageTag(preferred ?? readStoredLanguage(storageKey) ?? readNavigatorLanguage(), supportedLanguages, fallbackLanguage),\n );\n\n // Adopt the backend preference once it is known. `preferred` is the\n // authoritative source, so it overrides a value detection picked earlier —\n // which is also what makes a returning user land on the language they chose\n // on another device.\n //\n // Adjusted during render, not in an effect: the guarded `prevPreferred`\n // comparison is React's documented derive-from-props pattern, and it adopts\n // in the render the value arrives in rather than one render later.\n const [prevPreferred, setPrevPreferred] = useState<string | null | undefined>(preferred);\n if (preferred !== prevPreferred) {\n setPrevPreferred(preferred);\n if (preferred !== undefined && preferred !== null && preferred.trim() !== '') {\n const next = resolveLanguageTag(preferred, supportedLanguages, fallbackLanguage);\n if (next !== language) {\n setLanguageState(next);\n }\n }\n }\n\n // `<html lang>` drives hyphenation, font choice and screen-reader\n // pronunciation, so it has to follow the tag even when the change came from\n // detection rather than from `setLanguage`.\n useEffect(() => {\n try {\n document.documentElement.lang = language;\n } catch {\n // No DOM: server rendering, or a worker-ish test environment.\n }\n }, [language]);\n\n const setLanguage = useCallback(\n (tag: string) => {\n const next = resolveLanguageTag(tag, supportedLanguages, fallbackLanguage);\n setLanguageState((current) => (current === next ? current : next));\n // Persisted only on an explicit choice. Writing on mount would turn \"the\n // browser happened to report `de`\" into a stored preference, which is a\n // different claim.\n writeStoredLanguage(storageKey, next);\n },\n [supportedLanguages, fallbackLanguage, storageKey],\n );\n\n return { language, setLanguage, supported: supportedLanguages };\n}\n\nexport { DEFAULT_FALLBACK_LANGUAGE, DEFAULT_LANGUAGE_STORAGE_KEY, DEFAULT_SUPPORTED_LANGUAGES, resolveLanguageTag, useSpaLanguage };\nexport type { UseSpaLanguageOptions, UseSpaLanguageResult };\n\nexport { canonicalizeLanguageTag, type LanguageTag } from '@rexez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BA6CT,SAASC,EAAe,CACtB,UAAAC,EACA,UAAAhB,EAAYJ,EACZ,WAAAe,EAAab,EACb,iBAAAmB,EAAmBpB,CAAyB,EACT,CAAA,EAAE,CAGrC,MAAMqB,EAAelB,EAAU,KAAK,GAAG,EACjCmB,EAAqB1B,EAAgC,IAAOyB,IAAiB,GAAK,CAAA,EAAKA,EAAa,MAAM,GAAG,EAAI,CAACA,CAAY,CAAC,EAE/H,CAACL,EAAUO,CAAgB,EAAI1B,EAAsB,IAIzDU,EAAmBY,GAAaN,EAAmBC,CAAU,GAAKG,EAAqB,EAAIK,EAAoBF,CAAgB,CAAC,EAW5H,CAACI,EAAeC,CAAgB,EAAI5B,EAAoCsB,CAAS,EACvF,GAAIA,IAAcK,IAChBC,EAAiBN,CAAS,EACKA,GAAc,MAAQA,EAAU,KAAI,IAAO,IAAI,CAC5E,MAAMO,EAAOnB,EAAmBY,EAAWG,EAAoBF,CAAgB,EAC3EM,IAASV,GACXO,EAAiBG,CAAI,CAEzB,CAMF/B,EAAU,IAAK,CACb,GAAI,CACF,SAAS,gBAAgB,KAAOqB,CAClC,MAAQ,CAER,CACF,EAAG,CAACA,CAAQ,CAAC,EAEb,MAAMW,EAAcjC,EACjBU,GAAe,CACd,MAAMsB,EAAOnB,EAAmBH,EAAKkB,EAAoBF,CAAgB,EACzEG,EAAkBK,GAAaA,IAAYF,EAAOE,EAAUF,CAAK,EAIjEX,EAAoBD,EAAYY,CAAI,CACtC,EACA,CAACJ,EAAoBF,EAAkBN,CAAU,CAAC,EAGpD,MAAO,CAAE,SAAAE,EAAU,YAAAW,EAAa,UAAWL,CAAkB,CAC/D,CA7DShB,EAAAY,EAAA,kBAkET,OAAS,2BAAApB,MAAiD",
6
- "names": ["useCallback", "useEffect", "useMemo", "useState", "canonicalizeLanguageTag", "DEFAULT_SUPPORTED_LANGUAGES", "DEFAULT_FALLBACK_LANGUAGE", "DEFAULT_LANGUAGE_STORAGE_KEY", "describeSupported", "supported", "tag", "key", "__name", "resolveLanguageTag", "value", "fallback", "primary", "prefixMatch", "entry", "readStoredLanguage", "storageKey", "writeStoredLanguage", "language", "readNavigatorLanguage", "useSpaLanguage", "preferred", "fallbackLanguage", "supportedKey", "supportedLanguages", "setLanguageState", "prevPreferred", "setPrevPreferred", "next", "setLanguage", "current"]
4
+ "sourcesContent": ["import { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport type { LanguageTag } from '@rexezuge/shared';\nimport { detectLanguage, resolveLanguageTag, writeStoredLanguage } from './language.ts';\n\n/**\n * The language the SPA is rendering, and the setter that changes it.\n *\n * ## Provenance\n *\n * `hooks/useSpaLanguage.ts` in **Agent-Router**, **AWS-AccessBridge**,\n * **Durable-DAV**, **Durable-DAV-Router**, **Edge-Git**, **Edge-Sonic**,\n * **Mail-Meow** and **Mail-Otter**. The eight copies agree on the detection\n * precedence (backend `preferredLanguage` > `localStorage` > `navigator.language`\n * > fallback, first *present* source wins) and on `<html lang>` sync.\n *\n * ## The adoption gap this closes\n *\n * The first kit version left bundle loading, the backend write and the\n * `languageStatus`/`languagePending` pair to the app, to keep i18next out of the\n * hook. That is why none of the eight adopted it: those three things are most of\n * every copy, so adopting the kit hook meant keeping the copy *and* the hook.\n * They come in now through two structural ports. The hook still imports no i18n\n * library:\n *\n * - **`runtime`** ({@link LanguageRuntime}): `load(tag)` loads the bundle and\n * switches the i18n instance, and the optional `subscribe(listener)` reports a\n * language change made elsewhere (i18next's `languageChanged`). `createSpaI18n`\n * from `@rexezuge/web/i18n` returns an object that satisfies it.\n * - **`persist`**: the authoritative save (`PUT /user/me`), awaited after the\n * bundle loaded.\n *\n * With them the hook reports `status` (`loading` until the bundle for the\n * current tag is in, `error` if it failed) and `pending` (a change is in\n * flight), and `changeLanguage` is the one-call manual flow every copy\n * hand-rolled. Strings stay the app's: a failure is a `false` from\n * `changeLanguage` and `status: 'error'`, never a notice text.\n *\n * Without a runtime the hook behaves exactly as before: `status` is always\n * `ready`, and `setLanguage` is synchronous.\n */\n\n/**\nThe tags offered when a caller does not say. English-only is the safe default.\n*/\nconst DEFAULT_SUPPORTED_LANGUAGES: readonly LanguageTag[] = ['en'];\n\n/**\nThe tag used when nothing supported can be resolved.\n*/\nconst DEFAULT_FALLBACK_LANGUAGE: LanguageTag = 'en';\n\n/**\nThe `localStorage` key used when a caller does not say.\n*/\nconst DEFAULT_LANGUAGE_STORAGE_KEY = 'language';\n\n/**\n * The port to the app's i18n instance. Structural: `createSpaI18n` satisfies it,\n * and so does any object with these members.\n */\ninterface LanguageRuntime {\n /**\n Make `tag` the rendered language, loading its bundle first if needed.\n */\n load(tag: LanguageTag): Promise<void>;\n /**\n Report a language change made outside the hook. Returns the unsubscribe.\n */\n subscribe?(listener: (tag: string) => void): () => void;\n}\n\n/**\n`loading` until the current tag's bundle is in; `error` when loading or saving failed.\n*/\ntype LanguageStatus = 'loading' | 'ready' | 'error';\n\ninterface UseSpaLanguageOptions {\n /**\n * The backend-authoritative preference (a user's `preferredLanguage`), or\n * `null`/`undefined` while the profile is not known. Adopted when it changes.\n */\n preferred?: string | null;\n /**\n The tags the app ships bundles for. Memoize it: it is a dependency.\n */\n supported?: readonly LanguageTag[];\n /**\n The `localStorage` key the choice is persisted under.\n */\n storageKey?: string;\n /**\n The tag used when nothing supported resolves. Defaults to `en`.\n */\n fallbackLanguage?: LanguageTag;\n /**\n Loads bundles and switches the i18n instance. Keep it stable (a module constant).\n */\n runtime?: LanguageRuntime;\n /**\n Saves an explicit choice to the backend. Awaited by `changeLanguage`.\n */\n persist?: (tag: LanguageTag) => Promise<void>;\n}\n\ninterface UseSpaLanguageResult {\n /**\n The tag currently in effect — a member of `supported`.\n */\n language: LanguageTag;\n /**\n * Switches the language immediately: resolves the tag, persists it locally, and\n * syncs `<html lang>`. An unsupported tag resolves to the fallback rather than\n * being ignored, so a mistake is visible instead of silent. With a `runtime`,\n * the bundle loads afterwards and `status` follows it. It never calls `persist`.\n */\n setLanguage: (tag: string) => void;\n /**\n * The manual-change flow: load the bundle, `persist`, then commit the tag and\n * store it locally. Resolves `true` on success and `false` on failure (or when\n * a change is already in flight). On failure the previous language is kept and\n * reloaded. Show your own notice on `false`.\n */\n changeLanguage: (tag: string) => Promise<boolean>;\n /**\n The tags offered, as resolved — render this list in a selector.\n */\n supported: readonly LanguageTag[];\n status: LanguageStatus;\n /**\n A `changeLanguage` call is in flight. Disable the selector on it.\n */\n pending: boolean;\n}\n\nfunction useSpaLanguage({\n preferred,\n supported = DEFAULT_SUPPORTED_LANGUAGES,\n storageKey = DEFAULT_LANGUAGE_STORAGE_KEY,\n fallbackLanguage = DEFAULT_FALLBACK_LANGUAGE,\n runtime,\n persist,\n}: Readonly<UseSpaLanguageOptions> = {}): UseSpaLanguageResult {\n // Serialized so an inline `supported` array literal does not change identity\n // on every render and re-run the effects below. Tags never contain spaces.\n const supportedKey = supported.join(' ');\n const supportedLanguages = useMemo<readonly LanguageTag[]>(() => (supportedKey === '' ? [] : supportedKey.split(' ')), [supportedKey]);\n\n const [language, setLanguageState] = useState<LanguageTag>(() =>\n // The backend value is undefined on a first paint and arrives later, which\n // is what the adoption below is for.\n detectLanguage({ preferred, supported: supportedLanguages, fallback: fallbackLanguage, storageKey }),\n );\n const [status, setStatus] = useState<LanguageStatus>(runtime === undefined ? 'ready' : 'loading');\n const [pending, setPending] = useState(false);\n const pendingRef = useRef(false);\n // The tag whose bundle the runtime last loaded, so the load effect does not\n // re-load what `changeLanguage` already did.\n const loadedRef = useRef<LanguageTag | null>(null);\n\n // Adopt the backend preference once it is known. `preferred` is the\n // authoritative source, so it overrides a value detection picked earlier —\n // which is also what makes a returning user land on the language they chose\n // on another device. Adjusted during render (React's derive-from-props\n // pattern), so it adopts in the render the value arrives in. A change in\n // flight wins over a profile that arrives while it runs.\n const [prevPreferred, setPrevPreferred] = useState<string | null | undefined>(preferred);\n if (preferred !== prevPreferred) {\n setPrevPreferred(preferred);\n if (!pending && preferred !== undefined && preferred !== null && preferred.trim() !== '') {\n const next = resolveLanguageTag(preferred, supportedLanguages, fallbackLanguage);\n if (next !== language) {\n setLanguageState(next);\n }\n }\n }\n\n // Load the bundle for whatever the current tag is, however it got there.\n useEffect(() => {\n if (runtime === undefined || pendingRef.current || loadedRef.current === language) return;\n let cancelled = false;\n setStatus('loading');\n runtime\n .load(language)\n .then(() => {\n if (cancelled) return;\n loadedRef.current = language;\n setStatus('ready');\n })\n .catch(() => {\n if (!cancelled) setStatus('error');\n });\n return () => {\n cancelled = true;\n };\n }, [runtime, language]);\n\n // Follow a change made outside the hook (another component, i18next itself).\n useEffect(() => {\n if (runtime?.subscribe === undefined) return;\n return runtime.subscribe((tag) => {\n const next = resolveLanguageTag(tag, supportedLanguages, fallbackLanguage);\n loadedRef.current = next;\n setLanguageState(next);\n setStatus('ready');\n });\n }, [runtime, supportedLanguages, fallbackLanguage]);\n\n // `<html lang>` drives hyphenation, font choice and screen-reader\n // pronunciation, so it has to follow the tag even when the change came from\n // detection rather than from `setLanguage`.\n useEffect(() => {\n try {\n document.documentElement.lang = language;\n } catch {\n // No DOM: server rendering, or a worker-ish test environment.\n }\n }, [language]);\n\n const setLanguage = useCallback(\n (tag: string) => {\n const next = resolveLanguageTag(tag, supportedLanguages, fallbackLanguage);\n setLanguageState((current) => (current === next ? current : next));\n // Persisted only on an explicit choice. Writing on mount would turn \"the\n // browser happened to report `de`\" into a stored preference, which is a\n // different claim.\n writeStoredLanguage(storageKey, next);\n },\n [supportedLanguages, fallbackLanguage, storageKey],\n );\n\n const changeLanguage = useCallback(\n async (tag: string): Promise<boolean> => {\n if (pendingRef.current) return false;\n const next = resolveLanguageTag(tag, supportedLanguages, fallbackLanguage);\n const previous = language;\n pendingRef.current = true;\n setPending(true);\n setStatus('loading');\n try {\n if (runtime !== undefined) {\n await runtime.load(next);\n loadedRef.current = next;\n }\n await persist?.(next);\n writeStoredLanguage(storageKey, next);\n setLanguageState(next);\n setStatus('ready');\n return true;\n } catch {\n // Keep the language the reader still has, and put its bundle back if the\n // runtime already switched. `error` only sticks when that fails too:\n // otherwise the reader has a working language and an enabled selector.\n let restored = true;\n if (runtime !== undefined && loadedRef.current !== previous) {\n loadedRef.current = previous;\n restored = await runtime\n .load(previous)\n .then(() => true)\n .catch(() => false);\n }\n setStatus(restored ? 'ready' : 'error');\n return false;\n } finally {\n pendingRef.current = false;\n setPending(false);\n }\n },\n [supportedLanguages, fallbackLanguage, storageKey, language, runtime, persist],\n );\n\n return { language, setLanguage, changeLanguage, supported: supportedLanguages, status, pending };\n}\n\nexport { DEFAULT_FALLBACK_LANGUAGE, DEFAULT_LANGUAGE_STORAGE_KEY, DEFAULT_SUPPORTED_LANGUAGES, useSpaLanguage };\nexport { resolveLanguageTag } from './language.ts';\nexport type { LanguageRuntime, LanguageStatus, UseSpaLanguageOptions, UseSpaLanguageResult };\n\nexport { canonicalizeLanguageTag, type LanguageTag } from '@rexezuge/shared';\n"],
5
+ "mappings": "+EAAA,OAAS,eAAAA,EAAa,aAAAC,EAAW,WAAAC,EAAS,UAAAC,EAAQ,YAAAC,MAAgB,QAElE,OAAS,kBAAAC,EAAgB,sBAAAC,EAAoB,uBAAAC,MAA2B,gBA0CxE,MAAMC,EAAsD,CAAC,IAAI,EAK3DC,EAAyC,KAKzCC,EAA+B,WAgFrC,SAASC,EAAe,CACtB,UAAAC,EACA,UAAAC,EAAYL,EACZ,WAAAM,EAAaJ,EACb,iBAAAK,EAAmBN,EACnB,QAAAO,EACA,QAAAC,CAAO,EAC4B,CAAA,EAAE,CAGrC,MAAMC,EAAeL,EAAU,KAAK,GAAG,EACjCM,EAAqBjB,EAAgC,IAAOgB,IAAiB,GAAK,CAAA,EAAKA,EAAa,MAAM,GAAG,EAAI,CAACA,CAAY,CAAC,EAE/H,CAACE,EAAUC,CAAgB,EAAIjB,EAAsB,IAGzDC,EAAe,CAAE,UAAAO,EAAW,UAAWO,EAAoB,SAAUJ,EAAkB,WAAAD,CAAU,CAAE,CAAC,EAEhG,CAACQ,EAAQC,CAAS,EAAInB,EAAyBY,IAAY,OAAY,Q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AAK,EAIjEvB,EAAoBO,EAAYgB,CAAI,CACtC,EACA,CAACX,EAAoBJ,EAAkBD,CAAU,CAAC,EAG9CqB,EAAiBnC,EACrB,MAAOgC,GAAiC,CACtC,GAAIN,EAAW,QAAS,MAAO,GAC/B,MAAMI,EAAOxB,EAAmB0B,EAAKb,EAAoBJ,CAAgB,EACnEqB,EAAWhB,EACjBM,EAAW,QAAU,GACrBD,EAAW,EAAI,EACfF,EAAU,SAAS,EACnB,GAAI,CACF,OAAIP,IAAY,SACd,MAAMA,EAAQ,KAAKc,CAAI,EACvBH,EAAU,QAAUG,GAEtB,MAAMb,IAAUa,CAAI,EACpBvB,EAAoBO,EAAYgB,CAAI,EACpCT,EAAiBS,CAAI,EACrBP,EAAU,OAAO,EACV,EACT,MAAQ,CAIN,IAAIc,EAAW,GACf,OAAIrB,IAAY,QAAaW,EAAU,UAAYS,IACjDT,EAAU,QAAUS,EACpBC,EAAW,MAAMrB,EACd,KAAKoB,CAAQ,EACb,KAAK,IAAM,EAAI,EACf,MAAM,IAAM,EAAK,GAEtBb,EAAUc,EAAW,QAAU,OAAO,EAC/B,EACT,SACEX,EAAW,QAAU,GACrBD,EAAW,EAAK,CAClB,CACF,EACA,CAACN,EAAoBJ,EAAkBD,EAAYM,EAAUJ,EAASC,CAAO,CAAC,EAGhF,MAAO,CAAE,SAAAG,EAAU,YAAAa,EAAa,eAAAE,EAAgB,UAAWhB,EAAoB,OAAAG,EAAQ,QAAAE,CAAO,CAChG,CAzISc,EAAA3B,EAAA,kBA4IT,OAAS,sBAAAL,MAA0B,gBAGnC,OAAS,2BAAAiC,MAAiD",
6
+ "names": ["useCallback", "useEffect", "useMemo", "useRef", "useState", "detectLanguage", "resolveLanguageTag", "writeStoredLanguage", "DEFAULT_SUPPORTED_LANGUAGES", "DEFAULT_FALLBACK_LANGUAGE", "DEFAULT_LANGUAGE_STORAGE_KEY", "useSpaLanguage", "preferred", "supported", "storageKey", "fallbackLanguage", "runtime", "persist", "supportedKey", "supportedLanguages", "language", "setLanguageState", "status", "setStatus", "pending", "setPending", "pendingRef", "loadedRef", "prevPreferred", "setPrevPreferred", "next", "cancelled", "tag", "setLanguage", "current", "changeLanguage", "previous", "restored", "__name", "canonicalizeLanguageTag"]
7
7
  }
package/dist/utils.d.ts CHANGED
@@ -30,8 +30,8 @@
30
30
  * (`text-red-500`, `bg-[var(--color-accent)]`, `border-white`) are left in
31
31
  * source order on purpose: telling `text-sm` from `text-red-500` takes
32
32
  * tailwind-merge's full class table, and guessing wrong would silently drop a
33
- * colour. A consumer that needs the complete table can wrap this one:
34
- * `const cn = (...values: ClassValue[]) => twMerge(kitCn(...values))`.
33
+ * colour. A consumer that needs the complete table registers it once with
34
+ * `configureClassMerge(twMerge)`, and every kit component then uses it.
35
35
  */
36
36
  /**
37
37
  Everything `cn` accepts, mirroring clsx's `ClassValue`.
@@ -44,14 +44,23 @@ interface ClassDictionary {
44
44
  [className: string]: boolean | null | undefined;
45
45
  }
46
46
  /**
47
- * Joins class names, dropping falsy entries, exact duplicates, and superseded
48
- * utilities.
47
+ * Register the app's full class merger, once, at startup:
49
48
  *
50
49
  * ```ts
51
- * cn('px-4', undefined, ['py-2', { 'font-bold': isActive }], 'px-6'); // 'py-2 px-6'
50
+ * import { twMerge } from 'tailwind-merge';
51
+ * configureClassMerge(twMerge);
52
52
  * ```
53
+ *
54
+ * The kit's own merge covers lengths and keywords but leaves colours in source
55
+ * order, because telling `text-sm` from `text-red-500` takes tailwind-merge's full
56
+ * table. That was the gap keeping the local `Button`/`Card` copies alive: every
57
+ * copy's `cn` was `twMerge(clsx(...))`, so `<Button variant="ghost"
58
+ * className="text-[var(--color-text-muted)]">` replaced the variant's colour
59
+ * there and shipped both classes with the kit's. With a merger registered, every
60
+ * kit component composes exactly as the copies did. Pass `null` to unregister.
53
61
  */
62
+ declare function configureClassMerge(merge: ((className: string) => string) | null): void;
54
63
  declare function cn(...inputs: ClassValue[]): string;
55
- export { cn };
64
+ export { cn, configureClassMerge };
56
65
  export type { ClassDictionary, ClassValue };
57
66
  //# sourceMappingURL=utils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;EAEE;AACF,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,UAAU,EAAE,CAAC;AAEzG;;EAEE;AACF,UAAU,eAAe;IACvB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;CACjD;AA6TD;;;;;;;GAOG;AACH,iBAAS,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAI3C;AAED,OAAO,EAAE,EAAE,EAAE,CAAC;AACd,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC"}
1
+ {"version":3,"file":"utils.d.ts","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AAEH;;EAEE;AACF,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,GAAG,eAAe,GAAG,SAAS,UAAU,EAAE,CAAC;AAEzG;;EAEE;AACF,UAAU,eAAe;IACvB,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,GAAG,IAAI,GAAG,SAAS,CAAC;CACjD;AA+UD;;;;;;;;;;;;;;;GAeG;AACH,iBAAS,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,SAAS,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,IAAI,GAAG,IAAI,CAEhF;AAED,iBAAS,EAAE,CAAC,GAAG,MAAM,EAAE,UAAU,EAAE,GAAG,MAAM,CAK3C;AAED,OAAO,EAAE,EAAE,EAAE,mBAAmB,EAAE,CAAC;AACnC,YAAY,EAAE,eAAe,EAAE,UAAU,EAAE,CAAC"}
package/dist/utils.js CHANGED
@@ -1 +1 @@
1
- var d=Object.defineProperty;var r=(n,e)=>d(n,"name",{value:e,configurable:!0});const u=["inset-x","inset-y","inset","scroll-mx","scroll-my","scroll-m","scroll-px","scroll-py","scroll-p","start","end","top","right","bottom","left","space-x","space-y","gap-x","gap-y","gap","px","py","pt","pr","pb","pl","ps","pe","p","mx","my","mt","mr","mb","ml","ms","me","m","min-w","min-h","max-w","max-h","size","w","h","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl","rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded","border-x","border-y","border-t","border-r","border-b","border-l","border-s","border-e","border","ring-offset","ring","divide-x","divide-y","outline-offset","translate-x","translate-y","scale","rotate","col-span","row-span","grid-cols","grid-rows","basis","grow","shrink","order","z","opacity","leading","tracking","duration","delay"],l={static:"position",fixed:"position",absolute:"position",relative:"position",sticky:"position",block:"display",inline:"display","inline-block":"display",flex:"display","inline-flex":"display",grid:"display","inline-grid":"display",table:"display",hidden:"display",contents:"display","flow-root":"display","list-item":"display","flex-row":"flex-direction","flex-col":"flex-direction","flex-row-reverse":"flex-direction","flex-col-reverse":"flex-direction","flex-wrap":"flex-wrap","flex-wrap-reverse":"flex-wrap","flex-nowrap":"flex-wrap","justify-normal":"justify-content","justify-start":"justify-content","justify-end":"justify-content","justify-center":"justify-content","justify-between":"justify-content","justify-around":"justify-content","justify-evenly":"justify-content","justify-stretch":"justify-content","items-start":"align-items","items-end":"align-items","items-center":"align-items","items-baseline":"align-items","items-stretch":"align-items","self-auto":"align-self","self-start":"align-self","self-end":"align-self","self-center":"align-self","self-stretch":"align-self","text-left":"text-align","text-center":"text-align","text-right":"text-align","text-justify":"text-align","text-start":"text-align","text-end":"text-align","font-thin":"font-weight","font-extralight":"font-weight","font-light":"font-weight","font-normal":"font-weight","font-medium":"font-weight","font-semibold":"font-weight","font-bold":"font-weight","font-extrabold":"font-weight","font-black":"font-weight",visible:"visibility",invisible:"visibility",collapse:"visibility"},c=/^-?(?:\d+(?:\.\d*)?|\[[^\]]*\]|px|full|none|auto|screen|min|max|fit)$/;function p(n){return Array.isArray(n)}r(p,"isClassList");function f(n,e){for(const t of e.split(/\s+/))t!==""&&n.push(t)}r(f,"pushClasses");function a(n,e){for(const t of n)if(!(t==null||t===!1||t==="")){if(typeof t=="string"){f(e,t);continue}if(typeof t=="number"){e.push(String(t));continue}if(p(t)){a(t,e);continue}for(const[i,s]of Object.entries(t))s&&f(e,i)}}r(a,"flattenClasses");function g(n){let e=0,t=-1,i=0;for(;i<n.length;){const s=n[i];s==="["||s==="("?e+=1:s==="]"||s===")"?e-=1:s===":"&&e===0&&(t=i),i+=1}return t===-1?{variants:"",base:n}:{variants:n.slice(0,t),base:n.slice(t+1)}}r(g,"splitVariants");function y(n){const{variants:e,base:t}=g(n);if(Object.hasOwn(l,t))return`${e}|${l[t]}`;for(const i of u){if(t===i)return`${e}|${i}`;if(!t.startsWith(`${i}-`))continue;const s=t.slice(i.length+1);return c.test(s)?`${e}|${i}`:null}return null}r(y,"groupKeyFor");function x(n){const e=new Map;return n.forEach((t,i)=>{e.set(t,i)}),n.filter((t,i)=>e.get(t)===i)}r(x,"dedupeClasses");function b(n){const e=[],t=new Map;for(const i of n){const s=y(i);if(s!==null){const o=t.get(s);o!==void 0&&(e[o]=""),t.set(s,e.length)}e.push(i)}return e.filter(i=>i!=="")}r(b,"mergeGroups");function m(...n){const e=[];return a(n,e),b(x(e)).join(" ")}r(m,"cn");export{m as cn};
1
+ var u=Object.defineProperty;var r=(n,e)=>u(n,"name",{value:e,configurable:!0});const c=["inset-x","inset-y","inset","scroll-mx","scroll-my","scroll-m","scroll-px","scroll-py","scroll-p","start","end","top","right","bottom","left","space-x","space-y","gap-x","gap-y","gap","px","py","pt","pr","pb","pl","ps","pe","p","mx","my","mt","mr","mb","ml","ms","me","m","min-w","min-h","max-w","max-h","size","w","h","rounded-ss","rounded-se","rounded-ee","rounded-es","rounded-tl","rounded-tr","rounded-br","rounded-bl","rounded-s","rounded-e","rounded-t","rounded-r","rounded-b","rounded-l","rounded","border-x","border-y","border-t","border-r","border-b","border-l","border-s","border-e","border","ring-offset","ring","divide-x","divide-y","outline-offset","translate-x","translate-y","scale","rotate","col-span","row-span","grid-cols","grid-rows","basis","grow","shrink","order","z","opacity","leading","tracking","duration","delay"],f={static:"position",fixed:"position",absolute:"position",relative:"position",sticky:"position",block:"display",inline:"display","inline-block":"display",flex:"display","inline-flex":"display",grid:"display","inline-grid":"display",table:"display",hidden:"display",contents:"display","flow-root":"display","list-item":"display","flex-row":"flex-direction","flex-col":"flex-direction","flex-row-reverse":"flex-direction","flex-col-reverse":"flex-direction","flex-wrap":"flex-wrap","flex-wrap-reverse":"flex-wrap","flex-nowrap":"flex-wrap","justify-normal":"justify-content","justify-start":"justify-content","justify-end":"justify-content","justify-center":"justify-content","justify-between":"justify-content","justify-around":"justify-content","justify-evenly":"justify-content","justify-stretch":"justify-content","items-start":"align-items","items-end":"align-items","items-center":"align-items","items-baseline":"align-items","items-stretch":"align-items","self-auto":"align-self","self-start":"align-self","self-end":"align-self","self-center":"align-self","self-stretch":"align-self","text-left":"text-align","text-center":"text-align","text-right":"text-align","text-justify":"text-align","text-start":"text-align","text-end":"text-align","font-thin":"font-weight","font-extralight":"font-weight","font-light":"font-weight","font-normal":"font-weight","font-medium":"font-weight","font-semibold":"font-weight","font-bold":"font-weight","font-extrabold":"font-weight","font-black":"font-weight",visible:"visibility",invisible:"visibility",collapse:"visibility"},p=/^-?(?:\d+(?:\.\d*)?|\[[^\]]*\]|px|full|none|auto|screen|min|max|fit)$/;function g(n){return Array.isArray(n)}r(g,"isClassList");function a(n,e){for(const t of e.split(/\s+/))t!==""&&n.push(t)}r(a,"pushClasses");function d(n,e){for(const t of n)if(!(t==null||t===!1||t==="")){if(typeof t=="string"){a(e,t);continue}if(typeof t=="number"){e.push(String(t));continue}if(g(t)){d(t,e);continue}for(const[i,s]of Object.entries(t))s&&a(e,i)}}r(d,"flattenClasses");function y(n){let e=0,t=-1,i=0;for(;i<n.length;){const s=n[i];s==="["||s==="("?e+=1:s==="]"||s===")"?e-=1:s===":"&&e===0&&(t=i),i+=1}return t===-1?{variants:"",base:n}:{variants:n.slice(0,t),base:n.slice(t+1)}}r(y,"splitVariants");function x(n){const{variants:e,base:t}=y(n);if(Object.hasOwn(f,t))return`${e}|${f[t]}`;for(const i of c){if(t===i)return`${e}|${i}`;if(!t.startsWith(`${i}-`))continue;const s=t.slice(i.length+1);return p.test(s)?`${e}|${i}`:null}return null}r(x,"groupKeyFor");function b(n){const e=new Map;return n.forEach((t,i)=>{e.set(t,i)}),n.filter((t,i)=>e.get(t)===i)}r(b,"dedupeClasses");function m(n){const e=[],t=new Map;for(const i of n){const s=x(i);if(s!==null){const l=t.get(s);l!==void 0&&(e[l]=""),t.set(s,e.length)}e.push(i)}return e.filter(i=>i!=="")}r(m,"mergeGroups");let o=null;function h(n){o=n}r(h,"configureClassMerge");function w(...n){const e=[];d(n,e);const t=m(b(e)).join(" ");return o===null?t:o(t)}r(w,"cn");export{w as cn,h as configureClassMerge};
package/dist/utils.js.map CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/utils.ts"],
4
- "sourcesContent": ["/**\n * Class-name composition.\n *\n * ## Provenance\n *\n * `lib/utils.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six byte-identical copies of\n *\n * ```ts\n * export function cn(...inputs: ClassValue[]) {\n * return twMerge(clsx(inputs));\n * }\n * ```\n *\n * The kit cannot import `clsx` or `tailwind-merge` (this package declares no\n * dependency on either, and the consumers' own copies stay theirs), so the same\n * contract is implemented here in-dependency-free form:\n *\n * - **clsx semantics** — strings, numbers, arrays and `{ [class]: active }`\n * dictionaries are flattened, and falsy entries are dropped.\n * - **tailwind-merge semantics, for a documented subset** — when a later class\n * belongs to the same utility family as an earlier one, the earlier one is\n * dropped, so `<Button className=\"px-6\">` really does override the base\n * `px-4` instead of shipping both and letting stylesheet order decide.\n *\n * The merged families are the ones whose value is a length or a count —\n * spacing, sizing, border width, radius, transitions — plus the single-word\n * utilities (position, display, flex direction, justification, alignment, text\n * alignment, font weight). Families whose suffix is *not* a value\n * (`text-red-500`, `bg-[var(--color-accent)]`, `border-white`) are left in\n * source order on purpose: telling `text-sm` from `text-red-500` takes\n * tailwind-merge's full class table, and guessing wrong would silently drop a\n * colour. A consumer that needs the complete table can wrap this one:\n * `const cn = (...values: ClassValue[]) => twMerge(kitCn(...values))`.\n */\n\n/**\nEverything `cn` accepts, mirroring clsx's `ClassValue`.\n*/\ntype ClassValue = string | number | boolean | null | undefined | ClassDictionary | readonly ClassValue[];\n\n/**\n`{ 'px-4': isActive }` — a class is present when its value is truthy.\n*/\ninterface ClassDictionary {\n [className: string]: boolean | null | undefined;\n}\n\n/**\n * Utility prefixes whose remainder is a length/count, merged longest-first so\n * `px-` is matched before `p-`.\n */\nconst VALUE_UTILITY_PREFIXES: readonly string[] = [\n // Inset / spacing\n 'inset-x',\n 'inset-y',\n 'inset',\n 'scroll-mx',\n 'scroll-my',\n 'scroll-m',\n 'scroll-px',\n 'scroll-py',\n 'scroll-p',\n 'start',\n 'end',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'space-x',\n 'space-y',\n 'gap-x',\n 'gap-y',\n 'gap',\n 'px',\n 'py',\n 'pt',\n 'pr',\n 'pb',\n 'pl',\n 'ps',\n 'pe',\n 'p',\n 'mx',\n 'my',\n 'mt',\n 'mr',\n 'mb',\n 'ml',\n 'ms',\n 'me',\n 'm',\n // Sizing\n 'min-w',\n 'min-h',\n 'max-w',\n 'max-h',\n 'size',\n 'w',\n 'h',\n // Radius\n 'rounded-ss',\n 'rounded-se',\n 'rounded-ee',\n 'rounded-es',\n 'rounded-tl',\n 'rounded-tr',\n 'rounded-br',\n 'rounded-bl',\n 'rounded-s',\n 'rounded-e',\n 'rounded-t',\n 'rounded-r',\n 'rounded-b',\n 'rounded-l',\n 'rounded',\n // Border width (a border *colour* never has a numeric suffix)\n 'border-x',\n 'border-y',\n 'border-t',\n 'border-r',\n 'border-b',\n 'border-l',\n 'border-s',\n 'border-e',\n 'border',\n // Ring / outline width, divide, translate/scale/rotate\n 'ring-offset',\n 'ring',\n 'divide-x',\n 'divide-y',\n 'outline-offset',\n 'translate-x',\n 'translate-y',\n 'scale',\n 'rotate',\n // Grid\n 'col-span',\n 'row-span',\n 'grid-cols',\n 'grid-rows',\n // Flex box\n 'basis',\n 'grow',\n 'shrink',\n 'order',\n 'z',\n 'opacity',\n 'leading',\n 'tracking',\n 'duration',\n 'delay',\n];\n\n/**\n * Single-word utilities that have no value, grouped by the property they set.\n * Only words that are unambiguously that property are listed — `font-medium`\n * (weight) is here, `font-mono` (family) is not.\n */\nconst SINGLETON_UTILITIES: Record<string, string> = {\n // Position\n static: 'position',\n fixed: 'position',\n absolute: 'position',\n relative: 'position',\n sticky: 'position',\n // Display\n block: 'display',\n inline: 'display',\n 'inline-block': 'display',\n flex: 'display',\n 'inline-flex': 'display',\n grid: 'display',\n 'inline-grid': 'display',\n table: 'display',\n hidden: 'display',\n contents: 'display',\n 'flow-root': 'display',\n 'list-item': 'display',\n // Flex direction / wrapping\n 'flex-row': 'flex-direction',\n 'flex-col': 'flex-direction',\n 'flex-row-reverse': 'flex-direction',\n 'flex-col-reverse': 'flex-direction',\n 'flex-wrap': 'flex-wrap',\n 'flex-wrap-reverse': 'flex-wrap',\n 'flex-nowrap': 'flex-wrap',\n // Justification / alignment\n 'justify-normal': 'justify-content',\n 'justify-start': 'justify-content',\n 'justify-end': 'justify-content',\n 'justify-center': 'justify-content',\n 'justify-between': 'justify-content',\n 'justify-around': 'justify-content',\n 'justify-evenly': 'justify-content',\n 'justify-stretch': 'justify-content',\n 'items-start': 'align-items',\n 'items-end': 'align-items',\n 'items-center': 'align-items',\n 'items-baseline': 'align-items',\n 'items-stretch': 'align-items',\n 'self-auto': 'align-self',\n 'self-start': 'align-self',\n 'self-end': 'align-self',\n 'self-center': 'align-self',\n 'self-stretch': 'align-self',\n // Text alignment\n 'text-left': 'text-align',\n 'text-center': 'text-align',\n 'text-right': 'text-align',\n 'text-justify': 'text-align',\n 'text-start': 'text-align',\n 'text-end': 'text-align',\n // Font weight (families are deliberately absent — see the comment above)\n 'font-thin': 'font-weight',\n 'font-extralight': 'font-weight',\n 'font-light': 'font-weight',\n 'font-normal': 'font-weight',\n 'font-medium': 'font-weight',\n 'font-semibold': 'font-weight',\n 'font-bold': 'font-weight',\n 'font-extrabold': 'font-weight',\n 'font-black': 'font-weight',\n // Visibility\n visible: 'visibility',\n invisible: 'visibility',\n collapse: 'visibility',\n};\n\n/**\nA length/count-like remainder: `-2`, `1.5`, `[3px]`, `px`, `full`, `none`.\n*/\nconst VALUE_SUFFIX = /^-?(?:\\d+(?:\\.\\d*)?|\\[[^\\]]*\\]|px|full|none|auto|screen|min|max|fit)$/;\n\nfunction isClassList(value: ClassValue): value is readonly ClassValue[] {\n return Array.isArray(value);\n}\n\n/**\nPushes the whitespace-separated classes of one string, dropping empties.\n*/\nfunction pushClasses(into: string[], value: string): void {\n for (const className of value.split(/\\s+/)) {\n if (className !== '') {\n into.push(className);\n }\n }\n}\n\n/**\nFlattens clsx-style inputs into the classes they contribute, in order.\n*/\nfunction flattenClasses(values: readonly ClassValue[], into: string[]): void {\n for (const value of values) {\n if (value === null || value === undefined || value === false || value === '') {\n continue;\n }\n if (typeof value === 'string') {\n pushClasses(into, value);\n continue;\n }\n if (typeof value === 'number') {\n into.push(String(value));\n continue;\n }\n if (isClassList(value)) {\n flattenClasses(value, into);\n continue;\n }\n for (const [className, active] of Object.entries(value)) {\n if (active) {\n // A dictionary key may itself carry several classes.\n pushClasses(into, className);\n }\n }\n }\n}\n\n/**\n * Splits `hover:focus:px-2` into its variants and base, ignoring the colons\n * that appear inside an arbitrary value such as `bg-[url(https://…)]`.\n */\nfunction splitVariants(className: string): { variants: string; base: string } {\n let depth = 0;\n let lastSeparator = -1;\n let index = 0;\n while (index < className.length) {\n const character = className[index];\n if (character === '[' || character === '(') {\n depth += 1;\n } else if (character === ']' || character === ')') {\n depth -= 1;\n } else if (character === ':' && depth === 0) {\n lastSeparator = index;\n }\n index += 1;\n }\n if (lastSeparator === -1) {\n return { variants: '', base: className };\n }\n return { variants: className.slice(0, lastSeparator), base: className.slice(lastSeparator + 1) };\n}\n\n/**\n * The merge group a class belongs to, or `null` when it must be left alone.\n *\n * Two classes merge only when their group is equal, and the group carries the\n * variant prefix — `sm:px-2` never overrides a bare `px-4`.\n */\nfunction groupKeyFor(className: string): string | null {\n const { variants, base } = splitVariants(className);\n if (Object.hasOwn(SINGLETON_UTILITIES, base)) {\n return `${variants}|${SINGLETON_UTILITIES[base]}`;\n }\n for (const prefix of VALUE_UTILITY_PREFIXES) {\n if (base === prefix) {\n return `${variants}|${prefix}`;\n }\n if (!base.startsWith(`${prefix}-`)) {\n continue;\n }\n // `important` and a trailing `!` are not values; neither is an unknown word,\n // which is how `text-sm`/`border-white` escape the numeric families.\n const suffix = base.slice(prefix.length + 1);\n if (!VALUE_SUFFIX.test(suffix)) {\n return null;\n }\n return `${variants}|${prefix}`;\n }\n return null;\n}\n\n/**\nDrops an exact duplicate, keeping its last occurrence.\n*/\nfunction dedupeClasses(classes: readonly string[]): string[] {\n const lastIndex = new Map<string, number>();\n classes.forEach((className, index) => {\n lastIndex.set(className, index);\n });\n return classes.filter((className, index) => lastIndex.get(className) === index);\n}\n\n/**\nDrops each class that a later member of its own group has replaced.\n*/\nfunction mergeGroups(classes: readonly string[]): string[] {\n const merged: string[] = [];\n const positionByGroup = new Map<string, number>();\n for (const className of classes) {\n const group = groupKeyFor(className);\n if (group !== null) {\n const previous = positionByGroup.get(group);\n if (previous !== undefined) {\n merged[previous] = '';\n }\n positionByGroup.set(group, merged.length);\n }\n merged.push(className);\n }\n return merged.filter((className) => className !== '');\n}\n\n/**\n * Joins class names, dropping falsy entries, exact duplicates, and superseded\n * utilities.\n *\n * ```ts\n * cn('px-4', undefined, ['py-2', { 'font-bold': isActive }], 'px-6'); // 'py-2 px-6'\n * ```\n */\nfunction cn(...inputs: ClassValue[]): string {\n const flattened: string[] = [];\n flattenClasses(inputs, flattened);\n return mergeGroups(dedupeClasses(flattened)).join(' ');\n}\n\nexport { cn };\nexport type { ClassDictionary, ClassValue };\n"],
5
- "mappings": "+EAoDA,MAAMA,EAA4C,CAEhD,UACA,UACA,QACA,YACA,YACA,WACA,YACA,YACA,WACA,QACA,MACA,MACA,QACA,SACA,OACA,UACA,UACA,QACA,QACA,MACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,IAEA,QACA,QACA,QACA,QACA,OACA,IACA,IAEA,aACA,aACA,aACA,aACA,aACA,aACA,aACA,aACA,YACA,YACA,YACA,YACA,YACA,YACA,UAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,SAEA,cACA,OACA,WACA,WACA,iBACA,cACA,cACA,QACA,SAEA,WACA,WACA,YACA,YAEA,QACA,OACA,SACA,QACA,IACA,UACA,UACA,WACA,WACA,SAQIC,EAA8C,CAElD,OAAQ,WACR,MAAO,WACP,SAAU,WACV,SAAU,WACV,OAAQ,WAER,MAAO,UACP,OAAQ,UACR,eAAgB,UAChB,KAAM,UACN,cAAe,UACf,KAAM,UACN,cAAe,UACf,MAAO,UACP,OAAQ,UACR,SAAU,UACV,YAAa,UACb,YAAa,UAEb,WAAY,iBACZ,WAAY,iBACZ,mBAAoB,iBACpB,mBAAoB,iBACpB,YAAa,YACb,oBAAqB,YACrB,cAAe,YAEf,iBAAkB,kBAClB,gBAAiB,kBACjB,cAAe,kBACf,iBAAkB,kBAClB,kBAAmB,kBACnB,iBAAkB,kBAClB,iBAAkB,kBAClB,kBAAmB,kB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AAOG,CAAQ,EAAI,IAErBF,EAAgB,IAAIC,EAAOF,EAAO,MAAM,CAC1C,CACAA,EAAO,KAAKlB,CAAS,CACvB,CACA,OAAOkB,EAAO,OAAQlB,GAAcA,IAAc,EAAE,CACtD,CAfSH,EAAAoB,EAAA,eAyBT,SAASK,KAAMC,EAAoB,CACjC,MAAMC,EAAsB,CAAA,EAC5B,OAAAvB,EAAesB,EAAQC,CAAS,EACzBP,EAAYH,EAAcU,CAAS,CAAC,EAAE,KAAK,GAAG,CACvD,CAJS3B,EAAAyB,EAAA",
6
- "names": ["VALUE_UTILITY_PREFIXES", "SINGLETON_UTILITIES", "VALUE_SUFFIX", "isClassList", "value", "__name", "pushClasses", "into", "className", "flattenClasses", "values", "active", "splitVariants", "depth", "lastSeparator", "index", "character", "groupKeyFor", "variants", "base", "prefix", "suffix", "dedupeClasses", "classes", "lastIndex", "mergeGroups", "merged", "positionByGroup", "group", "previous", "cn", "inputs", "flattened"]
4
+ "sourcesContent": ["/**\n * Class-name composition.\n *\n * ## Provenance\n *\n * `lib/utils.ts` in **CalDAV-Bridge**, **Durable-DAV**, **Durable-DAV-Router**,\n * **Edge-Git**, **Edge-Sonic** and **Mail-Otter** — six byte-identical copies of\n *\n * ```ts\n * export function cn(...inputs: ClassValue[]) {\n * return twMerge(clsx(inputs));\n * }\n * ```\n *\n * The kit cannot import `clsx` or `tailwind-merge` (this package declares no\n * dependency on either, and the consumers' own copies stay theirs), so the same\n * contract is implemented here in-dependency-free form:\n *\n * - **clsx semantics** — strings, numbers, arrays and `{ [class]: active }`\n * dictionaries are flattened, and falsy entries are dropped.\n * - **tailwind-merge semantics, for a documented subset** — when a later class\n * belongs to the same utility family as an earlier one, the earlier one is\n * dropped, so `<Button className=\"px-6\">` really does override the base\n * `px-4` instead of shipping both and letting stylesheet order decide.\n *\n * The merged families are the ones whose value is a length or a count —\n * spacing, sizing, border width, radius, transitions — plus the single-word\n * utilities (position, display, flex direction, justification, alignment, text\n * alignment, font weight). Families whose suffix is *not* a value\n * (`text-red-500`, `bg-[var(--color-accent)]`, `border-white`) are left in\n * source order on purpose: telling `text-sm` from `text-red-500` takes\n * tailwind-merge's full class table, and guessing wrong would silently drop a\n * colour. A consumer that needs the complete table registers it once with\n * `configureClassMerge(twMerge)`, and every kit component then uses it.\n */\n\n/**\nEverything `cn` accepts, mirroring clsx's `ClassValue`.\n*/\ntype ClassValue = string | number | boolean | null | undefined | ClassDictionary | readonly ClassValue[];\n\n/**\n`{ 'px-4': isActive }` — a class is present when its value is truthy.\n*/\ninterface ClassDictionary {\n [className: string]: boolean | null | undefined;\n}\n\n/**\n * Utility prefixes whose remainder is a length/count, merged longest-first so\n * `px-` is matched before `p-`.\n */\nconst VALUE_UTILITY_PREFIXES: readonly string[] = [\n // Inset / spacing\n 'inset-x',\n 'inset-y',\n 'inset',\n 'scroll-mx',\n 'scroll-my',\n 'scroll-m',\n 'scroll-px',\n 'scroll-py',\n 'scroll-p',\n 'start',\n 'end',\n 'top',\n 'right',\n 'bottom',\n 'left',\n 'space-x',\n 'space-y',\n 'gap-x',\n 'gap-y',\n 'gap',\n 'px',\n 'py',\n 'pt',\n 'pr',\n 'pb',\n 'pl',\n 'ps',\n 'pe',\n 'p',\n 'mx',\n 'my',\n 'mt',\n 'mr',\n 'mb',\n 'ml',\n 'ms',\n 'me',\n 'm',\n // Sizing\n 'min-w',\n 'min-h',\n 'max-w',\n 'max-h',\n 'size',\n 'w',\n 'h',\n // Radius\n 'rounded-ss',\n 'rounded-se',\n 'rounded-ee',\n 'rounded-es',\n 'rounded-tl',\n 'rounded-tr',\n 'rounded-br',\n 'rounded-bl',\n 'rounded-s',\n 'rounded-e',\n 'rounded-t',\n 'rounded-r',\n 'rounded-b',\n 'rounded-l',\n 'rounded',\n // Border width (a border *colour* never has a numeric suffix)\n 'border-x',\n 'border-y',\n 'border-t',\n 'border-r',\n 'border-b',\n 'border-l',\n 'border-s',\n 'border-e',\n 'border',\n // Ring / outline width, divide, translate/scale/rotate\n 'ring-offset',\n 'ring',\n 'divide-x',\n 'divide-y',\n 'outline-offset',\n 'translate-x',\n 'translate-y',\n 'scale',\n 'rotate',\n // Grid\n 'col-span',\n 'row-span',\n 'grid-cols',\n 'grid-rows',\n // Flex box\n 'basis',\n 'grow',\n 'shrink',\n 'order',\n 'z',\n 'opacity',\n 'leading',\n 'tracking',\n 'duration',\n 'delay',\n];\n\n/**\n * Single-word utilities that have no value, grouped by the property they set.\n * Only words that are unambiguously that property are listed — `font-medium`\n * (weight) is here, `font-mono` (family) is not.\n */\nconst SINGLETON_UTILITIES: Record<string, string> = {\n // Position\n static: 'position',\n fixed: 'position',\n absolute: 'position',\n relative: 'position',\n sticky: 'position',\n // Display\n block: 'display',\n inline: 'display',\n 'inline-block': 'display',\n flex: 'display',\n 'inline-flex': 'display',\n grid: 'display',\n 'inline-grid': 'display',\n table: 'display',\n hidden: 'display',\n contents: 'display',\n 'flow-root': 'display',\n 'list-item': 'display',\n // Flex direction / wrapping\n 'flex-row': 'flex-direction',\n 'flex-col': 'flex-direction',\n 'flex-row-reverse': 'flex-direction',\n 'flex-col-reverse': 'flex-direction',\n 'flex-wrap': 'flex-wrap',\n 'flex-wrap-reverse': 'flex-wrap',\n 'flex-nowrap': 'flex-wrap',\n // Justification / alignment\n 'justify-normal': 'justify-content',\n 'justify-start': 'justify-content',\n 'justify-end': 'justify-content',\n 'justify-center': 'justify-content',\n 'justify-between': 'justify-content',\n 'justify-around': 'justify-content',\n 'justify-evenly': 'justify-content',\n 'justify-stretch': 'justify-content',\n 'items-start': 'align-items',\n 'items-end': 'align-items',\n 'items-center': 'align-items',\n 'items-baseline': 'align-items',\n 'items-stretch': 'align-items',\n 'self-auto': 'align-self',\n 'self-start': 'align-self',\n 'self-end': 'align-self',\n 'self-center': 'align-self',\n 'self-stretch': 'align-self',\n // Text alignment\n 'text-left': 'text-align',\n 'text-center': 'text-align',\n 'text-right': 'text-align',\n 'text-justify': 'text-align',\n 'text-start': 'text-align',\n 'text-end': 'text-align',\n // Font weight (families are deliberately absent — see the comment above)\n 'font-thin': 'font-weight',\n 'font-extralight': 'font-weight',\n 'font-light': 'font-weight',\n 'font-normal': 'font-weight',\n 'font-medium': 'font-weight',\n 'font-semibold': 'font-weight',\n 'font-bold': 'font-weight',\n 'font-extrabold': 'font-weight',\n 'font-black': 'font-weight',\n // Visibility\n visible: 'visibility',\n invisible: 'visibility',\n collapse: 'visibility',\n};\n\n/**\nA length/count-like remainder: `-2`, `1.5`, `[3px]`, `px`, `full`, `none`.\n*/\nconst VALUE_SUFFIX = /^-?(?:\\d+(?:\\.\\d*)?|\\[[^\\]]*\\]|px|full|none|auto|screen|min|max|fit)$/;\n\nfunction isClassList(value: ClassValue): value is readonly ClassValue[] {\n return Array.isArray(value);\n}\n\n/**\nPushes the whitespace-separated classes of one string, dropping empties.\n*/\nfunction pushClasses(into: string[], value: string): void {\n for (const className of value.split(/\\s+/)) {\n if (className !== '') {\n into.push(className);\n }\n }\n}\n\n/**\nFlattens clsx-style inputs into the classes they contribute, in order.\n*/\nfunction flattenClasses(values: readonly ClassValue[], into: string[]): void {\n for (const value of values) {\n if (value === null || value === undefined || value === false || value === '') {\n continue;\n }\n if (typeof value === 'string') {\n pushClasses(into, value);\n continue;\n }\n if (typeof value === 'number') {\n into.push(String(value));\n continue;\n }\n if (isClassList(value)) {\n flattenClasses(value, into);\n continue;\n }\n for (const [className, active] of Object.entries(value)) {\n if (active) {\n // A dictionary key may itself carry several classes.\n pushClasses(into, className);\n }\n }\n }\n}\n\n/**\n * Splits `hover:focus:px-2` into its variants and base, ignoring the colons\n * that appear inside an arbitrary value such as `bg-[url(https://…)]`.\n */\nfunction splitVariants(className: string): { variants: string; base: string } {\n let depth = 0;\n let lastSeparator = -1;\n let index = 0;\n while (index < className.length) {\n const character = className[index];\n if (character === '[' || character === '(') {\n depth += 1;\n } else if (character === ']' || character === ')') {\n depth -= 1;\n } else if (character === ':' && depth === 0) {\n lastSeparator = index;\n }\n index += 1;\n }\n if (lastSeparator === -1) {\n return { variants: '', base: className };\n }\n return { variants: className.slice(0, lastSeparator), base: className.slice(lastSeparator + 1) };\n}\n\n/**\n * The merge group a class belongs to, or `null` when it must be left alone.\n *\n * Two classes merge only when their group is equal, and the group carries the\n * variant prefix — `sm:px-2` never overrides a bare `px-4`.\n */\nfunction groupKeyFor(className: string): string | null {\n const { variants, base } = splitVariants(className);\n if (Object.hasOwn(SINGLETON_UTILITIES, base)) {\n return `${variants}|${SINGLETON_UTILITIES[base]}`;\n }\n for (const prefix of VALUE_UTILITY_PREFIXES) {\n if (base === prefix) {\n return `${variants}|${prefix}`;\n }\n if (!base.startsWith(`${prefix}-`)) {\n continue;\n }\n // `important` and a trailing `!` are not values; neither is an unknown word,\n // which is how `text-sm`/`border-white` escape the numeric families.\n const suffix = base.slice(prefix.length + 1);\n if (!VALUE_SUFFIX.test(suffix)) {\n return null;\n }\n return `${variants}|${prefix}`;\n }\n return null;\n}\n\n/**\nDrops an exact duplicate, keeping its last occurrence.\n*/\nfunction dedupeClasses(classes: readonly string[]): string[] {\n const lastIndex = new Map<string, number>();\n classes.forEach((className, index) => {\n lastIndex.set(className, index);\n });\n return classes.filter((className, index) => lastIndex.get(className) === index);\n}\n\n/**\nDrops each class that a later member of its own group has replaced.\n*/\nfunction mergeGroups(classes: readonly string[]): string[] {\n const merged: string[] = [];\n const positionByGroup = new Map<string, number>();\n for (const className of classes) {\n const group = groupKeyFor(className);\n if (group !== null) {\n const previous = positionByGroup.get(group);\n if (previous !== undefined) {\n merged[previous] = '';\n }\n positionByGroup.set(group, merged.length);\n }\n merged.push(className);\n }\n return merged.filter((className) => className !== '');\n}\n\n/**\n * Joins class names, dropping falsy entries, exact duplicates, and superseded\n * utilities.\n *\n * ```ts\n * cn('px-4', undefined, ['py-2', { 'font-bold': isActive }], 'px-6'); // 'py-2 px-6'\n * ```\n */\n/**\n * The app's full class merger (`twMerge`), when it registered one.\n *\n * Module state on purpose: class merging is page-wide, every kit component\n * calls `cn` at render, and threading a merger through every component's props\n * (or a context every test has to provide) would be the wrong shape for a\n * value that never differs between two components on one page.\n */\nlet classMerger: ((className: string) => string) | null = null;\n\n/**\n * Register the app's full class merger, once, at startup:\n *\n * ```ts\n * import { twMerge } from 'tailwind-merge';\n * configureClassMerge(twMerge);\n * ```\n *\n * The kit's own merge covers lengths and keywords but leaves colours in source\n * order, because telling `text-sm` from `text-red-500` takes tailwind-merge's full\n * table. That was the gap keeping the local `Button`/`Card` copies alive: every\n * copy's `cn` was `twMerge(clsx(...))`, so `<Button variant=\"ghost\"\n * className=\"text-[var(--color-text-muted)]\">` replaced the variant's colour\n * there and shipped both classes with the kit's. With a merger registered, every\n * kit component composes exactly as the copies did. Pass `null` to unregister.\n */\nfunction configureClassMerge(merge: ((className: string) => string) | null): void {\n classMerger = merge;\n}\n\nfunction cn(...inputs: ClassValue[]): string {\n const flattened: string[] = [];\n flattenClasses(inputs, flattened);\n const joined = mergeGroups(dedupeClasses(flattened)).join(' ');\n return classMerger === null ? joined : classMerger(joined);\n}\n\nexport { cn, configureClassMerge };\nexport type { ClassDictionary, ClassValue };\n"],
5
+ "mappings": "+EAoDA,MAAMA,EAA4C,CAEhD,UACA,UACA,QACA,YACA,YACA,WACA,YACA,YACA,WACA,QACA,MACA,MACA,QACA,SACA,OACA,UACA,UACA,QACA,QACA,MACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,IACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,KACA,IAEA,QACA,QACA,QACA,QACA,OACA,IACA,IAEA,aACA,aACA,aACA,aACA,aACA,aACA,aACA,aACA,YACA,YACA,YACA,YACA,YACA,YACA,UAEA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,WACA,SAEA,cACA,OACA,WACA,WACA,iBACA,cACA,cACA,QACA,SAEA,WACA,WACA,YACA,YAEA,QACA,OACA,SACA,QACA,IACA,UACA,UACA,WACA,WACA,SAQIC,EAA8C,CAElD,OAAQ,WACR,MAAO,WACP,SAAU,WACV,SAAU,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AU,IAAIhB,EAAWO,CAAK,CAChC,CAAC,EACMQ,EAAQ,OAAO,CAACf,EAAWO,IAAUS,EAAU,IAAIhB,CAAS,IAAMO,CAAK,CAChF,CANSV,EAAAiB,EAAA,iBAWT,SAASG,EAAYF,EAA0B,CAC7C,MAAMG,EAAmB,CAAA,EACnBC,EAAkB,IAAI,IAC5B,UAAWnB,KAAae,EAAS,CAC/B,MAAMK,EAAQX,EAAYT,CAAS,EACnC,GAAIoB,IAAU,KAAM,CAClB,MAAMC,EAAWF,EAAgB,IAAIC,CAAK,EACtCC,IAAa,SACfH,EAAOG,CAAQ,EAAI,IAErBF,EAAgB,IAAIC,EAAOF,EAAO,MAAM,CAC1C,CACAA,EAAO,KAAKlB,CAAS,CACvB,CACA,OAAOkB,EAAO,OAAQlB,GAAcA,IAAc,EAAE,CACtD,CAfSH,EAAAoB,EAAA,eAiCT,IAAIK,EAAsD,KAkB1D,SAASC,EAAoBC,EAA6C,CACxEF,EAAcE,CAChB,CAFS3B,EAAA0B,EAAA,uBAIT,SAASE,KAAMC,EAAoB,CACjC,MAAMC,EAAsB,CAAA,EAC5B1B,EAAeyB,EAAQC,CAAS,EAChC,MAAMC,EAASX,EAAYH,EAAca,CAAS,CAAC,EAAE,KAAK,GAAG,EAC7D,OAAOL,IAAgB,KAAOM,EAASN,EAAYM,CAAM,CAC3D,CALS/B,EAAA4B,EAAA",
6
+ "names": ["VALUE_UTILITY_PREFIXES", "SINGLETON_UTILITIES", "VALUE_SUFFIX", "isClassList", "value", "__name", "pushClasses", "into", "className", "flattenClasses", "values", "active", "splitVariants", "depth", "lastSeparator", "index", "character", "groupKeyFor", "variants", "base", "prefix", "suffix", "dedupeClasses", "classes", "lastIndex", "mergeGroups", "merged", "positionByGroup", "group", "previous", "classMerger", "configureClassMerge", "merge", "cn", "inputs", "flattened", "joined"]
7
7
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rexezuge/web",
3
- "version": "1.10.0",
3
+ "version": "1.12.0",
4
4
  "private": false,
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -16,6 +16,11 @@
16
16
  "types": "./dist/index.d.ts",
17
17
  "default": "./dist/index.js"
18
18
  },
19
+ "./i18n": {
20
+ "types": "./dist/i18n.d.ts",
21
+ "default": "./dist/i18n.js"
22
+ },
23
+ "./styles.css": "./dist/styles.css",
19
24
  "./*": {
20
25
  "types": "./dist/*.d.ts",
21
26
  "default": "./dist/*.js"
@@ -25,15 +30,21 @@
25
30
  "dist"
26
31
  ],
27
32
  "dependencies": {
28
- "@rexezuge/errors": "1.10.0",
29
- "@rexezuge/shared": "1.10.0"
33
+ "@rexezuge/contracts": "1.12.0",
34
+ "@rexezuge/errors": "1.12.0",
35
+ "@rexezuge/shared": "1.12.0"
30
36
  },
31
37
  "peerDependencies": {
38
+ "i18next": "^26.0.0 || ^27.0.0",
32
39
  "lucide-react": "^1.49.0",
33
40
  "react": "^19.3.0",
34
- "react-dom": "^19.3.0"
41
+ "react-dom": "^19.3.0",
42
+ "react-i18next": "^17.0.0 || ^18.0.0"
35
43
  },
36
44
  "peerDependenciesMeta": {
45
+ "i18next": {
46
+ "optional": true
47
+ },
37
48
  "lucide-react": {
38
49
  "optional": true
39
50
  },
@@ -42,6 +53,9 @@
42
53
  },
43
54
  "react-dom": {
44
55
  "optional": true
56
+ },
57
+ "react-i18next": {
58
+ "optional": true
45
59
  }
46
60
  },
47
61
  "devDependencies": {
@@ -57,11 +71,12 @@
57
71
  "react-dom": "19.3.0",
58
72
  "react-i18next": "17.0.15",
59
73
  "typescript": "6.0.3",
60
- "vitest": "4.1.11"
74
+ "vitest": "4.1.11",
75
+ "zod": "^4.6.5"
61
76
  },
62
77
  "description": "React UI primitives, hooks, and API client for the family SPAs.",
63
78
  "scripts": {
64
- "build": "tsc -p tsconfig.json && node ../../scripts/minify-dist.mjs",
79
+ "build": "tsc -p tsconfig.json && node ../../scripts/minify-dist.mjs && node -e \"require('node:fs').copyFileSync('src/styles.css', 'dist/styles.css')\"",
65
80
  "typecheck": "tsc -p tsconfig.test.json --noEmit",
66
81
  "test": "vitest run",
67
82
  "test:coverage": "vitest run --coverage"