@zag-js/i18n-utils 1.34.1 → 1.35.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 (53) hide show
  1. package/dist/cache.d.mts +4 -0
  2. package/dist/cache.d.ts +4 -0
  3. package/dist/cache.js +41 -0
  4. package/dist/cache.mjs +16 -0
  5. package/dist/collator.d.mts +3 -0
  6. package/dist/collator.d.ts +3 -0
  7. package/dist/collator.js +34 -0
  8. package/dist/collator.mjs +9 -0
  9. package/dist/filter.d.mts +11 -0
  10. package/dist/filter.d.ts +11 -0
  11. package/dist/filter.js +73 -0
  12. package/dist/filter.mjs +48 -0
  13. package/dist/format-bytes.d.mts +32 -0
  14. package/dist/format-bytes.d.ts +32 -0
  15. package/dist/format-bytes.js +54 -0
  16. package/dist/format-bytes.mjs +29 -0
  17. package/dist/format-date.d.mts +7 -0
  18. package/dist/format-date.d.ts +7 -0
  19. package/dist/format-date.js +262 -0
  20. package/dist/format-date.mjs +237 -0
  21. package/dist/format-list.d.mts +3 -0
  22. package/dist/format-list.d.ts +3 -0
  23. package/dist/format-list.js +35 -0
  24. package/dist/format-list.mjs +10 -0
  25. package/dist/format-number.d.mts +3 -0
  26. package/dist/format-number.d.ts +3 -0
  27. package/dist/format-number.js +35 -0
  28. package/dist/format-number.mjs +10 -0
  29. package/dist/format-relative-time.d.mts +3 -0
  30. package/dist/format-relative-time.d.ts +3 -0
  31. package/dist/format-relative-time.js +65 -0
  32. package/dist/format-relative-time.mjs +40 -0
  33. package/dist/format-time.d.mts +13 -0
  34. package/dist/format-time.d.ts +13 -0
  35. package/dist/format-time.js +77 -0
  36. package/dist/format-time.mjs +52 -0
  37. package/dist/index.d.mts +11 -90
  38. package/dist/index.d.ts +11 -90
  39. package/dist/index.js +53 -509
  40. package/dist/index.mjs +17 -497
  41. package/dist/is-rtl.d.mts +4 -0
  42. package/dist/is-rtl.d.ts +4 -0
  43. package/dist/is-rtl.js +77 -0
  44. package/dist/is-rtl.mjs +51 -0
  45. package/dist/locale.d.mts +13 -0
  46. package/dist/locale.d.ts +13 -0
  47. package/dist/locale.js +42 -0
  48. package/dist/locale.mjs +17 -0
  49. package/dist/track-locale.d.mts +10 -0
  50. package/dist/track-locale.d.ts +10 -0
  51. package/dist/track-locale.js +43 -0
  52. package/dist/track-locale.mjs +18 -0
  53. package/package.json +2 -2
package/dist/locale.js ADDED
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/locale.ts
21
+ var locale_exports = {};
22
+ __export(locale_exports, {
23
+ getDefaultLocale: () => getDefaultLocale
24
+ });
25
+ module.exports = __toCommonJS(locale_exports);
26
+ var import_is_rtl = require("./is-rtl.cjs");
27
+ function getDefaultLocale() {
28
+ let locale = typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
29
+ try {
30
+ Intl.DateTimeFormat.supportedLocalesOf([locale]);
31
+ } catch {
32
+ locale = "en-US";
33
+ }
34
+ return {
35
+ locale,
36
+ dir: (0, import_is_rtl.isRTL)(locale) ? "rtl" : "ltr"
37
+ };
38
+ }
39
+ // Annotate the CommonJS export names for ESM import in node:
40
+ 0 && (module.exports = {
41
+ getDefaultLocale
42
+ });
@@ -0,0 +1,17 @@
1
+ // src/locale.ts
2
+ import { isRTL } from "./is-rtl.mjs";
3
+ function getDefaultLocale() {
4
+ let locale = typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US";
5
+ try {
6
+ Intl.DateTimeFormat.supportedLocalesOf([locale]);
7
+ } catch {
8
+ locale = "en-US";
9
+ }
10
+ return {
11
+ locale,
12
+ dir: isRTL(locale) ? "rtl" : "ltr"
13
+ };
14
+ }
15
+ export {
16
+ getDefaultLocale
17
+ };
@@ -0,0 +1,10 @@
1
+ import { Locale } from './locale.mjs';
2
+
3
+ interface LocaleOptions {
4
+ locale?: string | undefined;
5
+ getRootNode?: (() => ShadowRoot | Document | Node) | undefined;
6
+ onLocaleChange?: ((locale: Locale) => void) | undefined;
7
+ }
8
+ declare function trackLocale(options?: LocaleOptions): () => void;
9
+
10
+ export { type LocaleOptions, trackLocale };
@@ -0,0 +1,10 @@
1
+ import { Locale } from './locale.js';
2
+
3
+ interface LocaleOptions {
4
+ locale?: string | undefined;
5
+ getRootNode?: (() => ShadowRoot | Document | Node) | undefined;
6
+ onLocaleChange?: ((locale: Locale) => void) | undefined;
7
+ }
8
+ declare function trackLocale(options?: LocaleOptions): () => void;
9
+
10
+ export { type LocaleOptions, trackLocale };
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/track-locale.ts
21
+ var track_locale_exports = {};
22
+ __export(track_locale_exports, {
23
+ trackLocale: () => trackLocale
24
+ });
25
+ module.exports = __toCommonJS(track_locale_exports);
26
+ var import_dom_query = require("@zag-js/dom-query");
27
+ var import_locale = require("./locale.cjs");
28
+ function trackLocale(options = {}) {
29
+ const { getRootNode, onLocaleChange } = options;
30
+ onLocaleChange?.((0, import_locale.getDefaultLocale)());
31
+ const handleLocaleChange = () => {
32
+ onLocaleChange?.((0, import_locale.getDefaultLocale)());
33
+ };
34
+ const win = getRootNode ? (0, import_dom_query.getWindow)(getRootNode()) : window;
35
+ win.addEventListener("languagechange", handleLocaleChange);
36
+ return () => {
37
+ win.removeEventListener("languagechange", handleLocaleChange);
38
+ };
39
+ }
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ trackLocale
43
+ });
@@ -0,0 +1,18 @@
1
+ // src/track-locale.ts
2
+ import { getWindow } from "@zag-js/dom-query";
3
+ import { getDefaultLocale } from "./locale.mjs";
4
+ function trackLocale(options = {}) {
5
+ const { getRootNode, onLocaleChange } = options;
6
+ onLocaleChange?.(getDefaultLocale());
7
+ const handleLocaleChange = () => {
8
+ onLocaleChange?.(getDefaultLocale());
9
+ };
10
+ const win = getRootNode ? getWindow(getRootNode()) : window;
11
+ win.addEventListener("languagechange", handleLocaleChange);
12
+ return () => {
13
+ win.removeEventListener("languagechange", handleLocaleChange);
14
+ };
15
+ }
16
+ export {
17
+ trackLocale
18
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zag-js/i18n-utils",
3
- "version": "1.34.1",
3
+ "version": "1.35.0",
4
4
  "description": "Interationalization utilities for Zag.js",
5
5
  "keywords": [
6
6
  "js",
@@ -24,7 +24,7 @@
24
24
  },
25
25
  "clean-package": "../../../clean-package.config.json",
26
26
  "dependencies": {
27
- "@zag-js/dom-query": "1.34.1"
27
+ "@zag-js/dom-query": "1.35.0"
28
28
  },
29
29
  "devDependencies": {
30
30
  "clean-package": "2.2.0",