"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/index.ts var src_exports = {}; __export(src_exports, { I18nProvider: () => I18nProvider, RTL_LANGS: () => RTL_LANGS, createCollator: () => createCollator, createDefaultLocale: () => createDefaultLocale, createNumberFormatter: () => createNumberFormatter, getDefaultLocale: () => getDefaultLocale, getReadingDirection: () => getReadingDirection, isRTL: () => isRTL, useLocale: () => useLocale }); module.exports = __toCommonJS(src_exports); // src/context.tsx var import_solid_js2 = require("solid-js"); // src/createDefaultLocale.ts var import_solid_js = require("solid-js"); var import_web = require("solid-js/web"); // src/utils.ts var RTL_SCRIPTS = /* @__PURE__ */ new Set([ "Avst", "Arab", "Armi", "Syrc", "Samr", "Mand", "Thaa", "Mend", "Nkoo", "Adlm", "Rohg", "Hebr" ]); var RTL_LANGS = /* @__PURE__ */ new Set([ "ae", "ar", "arc", "bcc", "bqi", "ckb", "dv", "fa", "glk", "he", "ku", "mzn", "nqo", "pnb", "ps", "sd", "ug", "ur", "yi" ]); function isRTL(locale) { if (Intl.Locale) { const script = new Intl.Locale(locale).maximize().script ?? ""; return RTL_SCRIPTS.has(script); } const lang = locale.split("-")[0]; return RTL_LANGS.has(lang); } function getReadingDirection(locale) { return isRTL(locale) ? "rtl" : "ltr"; } // src/createDefaultLocale.ts function getDefaultLocale() { const locale = typeof navigator !== "undefined" && (navigator.language || navigator.userLanguage) || "en-US"; return { locale, direction: getReadingDirection(locale) }; } var currentLocale = getDefaultLocale(); var listeners = /* @__PURE__ */ new Set(); function updateLocale() { currentLocale = getDefaultLocale(); for (const listener of listeners) { listener(currentLocale); } } function createDefaultLocale() { const defaultSSRLocale = { locale: "en-US", direction: "ltr" }; const [locale, setLocale] = (0, import_solid_js.createSignal)(currentLocale); const defaultLocale = (0, import_solid_js.createMemo)(() => import_web.isServer ? defaultSSRLocale : locale()); (0, import_solid_js.onMount)(() => { if (listeners.size === 0) { window.addEventListener("languagechange", updateLocale); } listeners.add(setLocale); (0, import_solid_js.onCleanup)(() => { listeners.delete(setLocale); if (listeners.size === 0) { window.removeEventListener("languagechange", updateLocale); } }); }); return defaultLocale; } // src/context.tsx var I18nContext = (0, import_solid_js2.createContext)(); function I18nProvider(props) { const defaultLocale = createDefaultLocale(); const value = (0, import_solid_js2.createMemo)(() => { return props.locale ? { locale: props.locale, direction: getReadingDirection(props.locale) } : defaultLocale(); }); return /* @__PURE__ */ React.createElement(I18nContext.Provider, { value }, props.children); } function useLocale() { const defaultLocale = createDefaultLocale(); const context = (0, import_solid_js2.useContext)(I18nContext); const locale = () => (context == null ? void 0 : context()) || defaultLocale(); return locale; } // src/createCollator.ts var import_solid_js3 = require("solid-js"); var cache = /* @__PURE__ */ new Map(); function createCollator(options) { const locale = useLocale(); const cacheKey = (0, import_solid_js3.createMemo)(() => { return locale().locale + (options ? Object.entries(options).sort((a, b) => a[0] < b[0] ? -1 : 1).join() : ""); }); const formatter = (0, import_solid_js3.createMemo)(() => { const key = cacheKey(); let collator; if (cache.has(key)) { collator = cache.get(key); } if (!collator) { collator = new Intl.Collator(locale().locale, options); cache.set(key, collator); } return collator; }); return formatter; } // src/createNumberFormatter.ts var import_number = require("@internationalized/number"); var import_solid_js4 = require("solid-js"); function createNumberFormatter(options) { const locale = useLocale(); const formatter = (0, import_solid_js4.createMemo)(() => new import_number.NumberFormatter(locale().locale, options())); return formatter; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { I18nProvider, RTL_LANGS, createCollator, createDefaultLocale, createNumberFormatter, getDefaultLocale, getReadingDirection, isRTL, useLocale });