kosmio 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md ADDED
@@ -0,0 +1,37 @@
1
+ # Kosmio
2
+
3
+ Reusable React components, design-system tokens, and pure UI utilities.
4
+
5
+ ## Install
6
+
7
+ ```bash
8
+ npm install kosmio
9
+ ```
10
+
11
+ ## Use
12
+
13
+ ```jsx
14
+ import { Button, Text } from "kosmio";
15
+ import "kosmio/styles.css";
16
+
17
+ export function Example() {
18
+ return (
19
+ <Button variant="primary">
20
+ <Text as="span" size="sm">Save</Text>
21
+ </Button>
22
+ );
23
+ }
24
+ ```
25
+
26
+ ## Design System
27
+
28
+ Kosmio ships default CSS variables and expects each app to override them as needed.
29
+
30
+ ```css
31
+ :root {
32
+ --kosmio-color-primary: #26a474;
33
+ --kosmio-font-family: Inter, system-ui, sans-serif;
34
+ }
35
+ ```
36
+
37
+ Every component style uses the public `--kosmio-*` contract.
@@ -0,0 +1,145 @@
1
+ import { jsx as m } from "react/jsx-runtime";
2
+ const f = {
3
+ mode: "light",
4
+ colors: {
5
+ bg: { light: "#ffffff", dark: "#0f172a" },
6
+ surface: { light: "#f8fafc", dark: "#111827" },
7
+ surfaceMuted: { light: "#eef2f7", dark: "#1f2937" },
8
+ surfaceStrong: { light: "#e2e8f0", dark: "#374151" },
9
+ text: { light: "#111827", dark: "#f9fafb" },
10
+ textMuted: { light: "#6b7280", dark: "#9ca3af" },
11
+ primary: { light: "#2563eb", dark: "#60a5fa" },
12
+ primaryText: { light: "#ffffff", dark: "#0f172a" },
13
+ danger: { light: "#dc2626", dark: "#f87171" },
14
+ dangerText: { light: "#ffffff", dark: "#0f172a" },
15
+ success: { light: "#16a34a", dark: "#4ade80" },
16
+ border: { light: "rgba(17, 24, 39, 0.14)", dark: "rgba(249, 250, 251, 0.16)" },
17
+ focus: { light: "rgba(37, 99, 235, 0.28)", dark: "rgba(96, 165, 250, 0.32)" }
18
+ },
19
+ colorAliases: {
20
+ bg: "bg",
21
+ surface: "surface",
22
+ surfaceMuted: "surfaceMuted",
23
+ surfaceStrong: "surfaceStrong",
24
+ text: "text",
25
+ textMuted: "textMuted",
26
+ primary: "primary",
27
+ primaryText: "primaryText",
28
+ tag: "primary",
29
+ danger: "danger",
30
+ dangerText: "dangerText",
31
+ success: "success",
32
+ border: "border",
33
+ focus: "focus"
34
+ },
35
+ fontSizes: {
36
+ xs: "12px",
37
+ sm: "13px",
38
+ md: "14px",
39
+ lg: "18px",
40
+ xl: "24px",
41
+ xxl: "28px"
42
+ }
43
+ }, g = {
44
+ bg: "--kosmio-color-bg",
45
+ surface: "--kosmio-color-surface",
46
+ surfaceMuted: "--kosmio-color-surface-muted",
47
+ surfaceStrong: "--kosmio-color-surface-strong",
48
+ text: "--kosmio-color-text",
49
+ textMuted: "--kosmio-color-text-muted",
50
+ primary: "--kosmio-color-primary",
51
+ primaryText: "--kosmio-color-primary-text",
52
+ tag: "--kosmio-tag-color",
53
+ danger: "--kosmio-color-danger",
54
+ dangerText: "--kosmio-color-danger-text",
55
+ success: "--kosmio-color-success",
56
+ border: "--kosmio-color-border",
57
+ focus: "--kosmio-color-focus"
58
+ }, x = {
59
+ xs: "--kosmio-font-size-xs",
60
+ sm: "--kosmio-font-size-sm",
61
+ md: "--kosmio-font-size-md",
62
+ lg: "--kosmio-font-size-lg",
63
+ xl: "--kosmio-font-size-xl",
64
+ xxl: "--kosmio-font-size-xxl"
65
+ };
66
+ function n(o, r) {
67
+ return {
68
+ ...o,
69
+ ...r ?? {}
70
+ };
71
+ }
72
+ function k(o = {}) {
73
+ return {
74
+ mode: o.mode ?? f.mode,
75
+ colors: n(f.colors, o.colors),
76
+ colorAliases: n(f.colorAliases, o.colorAliases),
77
+ fontSizes: n(f.fontSizes, o.fontSizes)
78
+ };
79
+ }
80
+ function l(o, r = f.mode) {
81
+ return o === "dark" || o === "light" ? o : r;
82
+ }
83
+ function d(o, r) {
84
+ if (o != null) {
85
+ if (typeof o != "object") return o;
86
+ if (o[r] != null) return o[r];
87
+ if (o.value != null) return o.value;
88
+ if (o.light != null) return o.light;
89
+ if (o.dark != null) return o.dark;
90
+ }
91
+ }
92
+ function b(o, r, e) {
93
+ Object.entries(r).forEach(([s, t]) => {
94
+ const i = d(t, e);
95
+ i != null && (o[`--kosmio-color-${s}`] = i);
96
+ });
97
+ }
98
+ function h(o, r, e, s) {
99
+ Object.entries(g).forEach(([t, i]) => {
100
+ const a = e[t] ?? t, c = d(r[a], s);
101
+ c != null && (o[i] = c);
102
+ });
103
+ }
104
+ function p(o, r) {
105
+ Object.entries(r).forEach(([e, s]) => {
106
+ o[`--kosmio-font-size-${e}`] = s;
107
+ }), Object.entries(x).forEach(([e, s]) => {
108
+ r[e] != null && (o[s] = r[e]);
109
+ });
110
+ }
111
+ function T(o = {}, r = {}) {
112
+ const e = k(o), s = l(r.mode ?? e.mode, e.mode), t = {};
113
+ return b(t, e.colors, s), h(t, e.colors, e.colorAliases, s), p(t, e.fontSizes), t;
114
+ }
115
+ function M({
116
+ as: o = "div",
117
+ theme: r,
118
+ mode: e,
119
+ className: s = "",
120
+ style: t,
121
+ children: i,
122
+ ...a
123
+ }) {
124
+ const c = l(e ?? r?.mode), u = T(r, { mode: c });
125
+ return /* @__PURE__ */ m(
126
+ o,
127
+ {
128
+ className: s,
129
+ "data-kosmio-theme": c,
130
+ style: {
131
+ ...u,
132
+ ...t
133
+ },
134
+ ...a,
135
+ children: i
136
+ }
137
+ );
138
+ }
139
+ export {
140
+ f as K,
141
+ M as a,
142
+ T as b,
143
+ k as c,
144
+ l as r
145
+ };
@@ -0,0 +1,161 @@
1
+ import E from "i18next";
2
+ import { initReactI18next as C, useTranslation as b } from "react-i18next";
3
+ import { useCallback as y, useMemo as z, useEffect as v, useContext as M, createContext as N } from "react";
4
+ import { jsx as T } from "react/jsx-runtime";
5
+ import { useNavigate as U, useLocation as j } from "react-router-dom";
6
+ function k(a) {
7
+ if (!a || typeof window > "u")
8
+ return null;
9
+ try {
10
+ return window.localStorage.getItem(a);
11
+ } catch {
12
+ return null;
13
+ }
14
+ }
15
+ function A({
16
+ defaultLanguage: a,
17
+ storageKey: e,
18
+ router: t,
19
+ normalizeLanguage: r = (c) => c || a,
20
+ matchRoute: g,
21
+ pathname: o,
22
+ navigatorLanguage: i
23
+ } = {}) {
24
+ const c = t?.normalizeLanguage ?? r, l = t?.matchLocalizedRoute ?? g;
25
+ if (typeof window > "u")
26
+ return a;
27
+ const u = k(e);
28
+ if (u)
29
+ return c(u);
30
+ const m = i ?? window.navigator?.language;
31
+ if (m)
32
+ return c(m);
33
+ const n = typeof l == "function" ? l(o ?? window.location.pathname) : null;
34
+ return n?.lang && !n.ambiguous ? c(n.lang) : a;
35
+ }
36
+ function Q({
37
+ instance: a = E,
38
+ resources: e,
39
+ defaultLanguage: t,
40
+ supportedLanguages: r,
41
+ storageKey: g,
42
+ router: o,
43
+ normalizeLanguage: i,
44
+ matchRoute: c,
45
+ initReact: l = !0,
46
+ options: u = {}
47
+ } = {}) {
48
+ return l && a.use(C), a.init({
49
+ resources: e,
50
+ lng: A({
51
+ defaultLanguage: t,
52
+ storageKey: g,
53
+ router: o,
54
+ normalizeLanguage: i,
55
+ matchRoute: c
56
+ }),
57
+ fallbackLng: t,
58
+ supportedLngs: r,
59
+ defaultNS: "translation",
60
+ interpolation: { escapeValue: !1 },
61
+ ...u
62
+ }), a;
63
+ }
64
+ function d(a, e, t = "") {
65
+ const r = a(e);
66
+ return r === e ? t || "" : r ?? "";
67
+ }
68
+ function D(a) {
69
+ return typeof a == "string" || typeof a == "number";
70
+ }
71
+ function V(a) {
72
+ return D(a) ? { value: a } : a && typeof a == "object" && "value" in a ? a : null;
73
+ }
74
+ function W(a) {
75
+ const { t: e } = b();
76
+ return y(
77
+ (t, r) => t ? d(e, `${a}.${t}`, r ?? t) : "",
78
+ [a, e]
79
+ );
80
+ }
81
+ function X(a, e, t = {}) {
82
+ const { t: r } = b(), { includeIcon: g = !1 } = t;
83
+ return z(
84
+ () => (Array.isArray(a) ? a : []).map(V).filter(Boolean).map((o) => {
85
+ const i = String(o.value), c = o.label != null ? o.label : o.labelKey ? d(r, o.labelKey, i) : e ? d(r, `${e}.${o.value}`, i) : i, { icon: l, iconName: u, ...m } = o;
86
+ return {
87
+ ...m,
88
+ value: o.value,
89
+ label: c,
90
+ ...g && l != null ? { icon: l } : {},
91
+ ...g && u != null ? { iconName: u } : {}
92
+ };
93
+ }),
94
+ [e, a, g, r]
95
+ );
96
+ }
97
+ const I = N({
98
+ lang: "",
99
+ changeLanguage: () => {
100
+ }
101
+ }), Y = () => M(I);
102
+ function x(a, e) {
103
+ if (!(!a || typeof localStorage > "u"))
104
+ try {
105
+ localStorage.setItem(a, e);
106
+ } catch {
107
+ }
108
+ }
109
+ function B(a) {
110
+ return `${a.pathname}${a.search}${a.hash}`;
111
+ }
112
+ function Z({
113
+ children: a,
114
+ defaultLanguage: e,
115
+ storageKey: t,
116
+ router: r,
117
+ normalizeLanguage: g = (u) => u || e,
118
+ translateRoutePath: o,
119
+ matchRoute: i,
120
+ getPreferredLanguage: c,
121
+ onLanguageChange: l
122
+ }) {
123
+ const { i18n: u } = b(), m = U(), n = j(), p = r?.normalizeLanguage ?? g, L = r?.translateRoutePath ?? o, $ = r?.matchLocalizedRoute ?? i, s = p(u.resolvedLanguage ?? u.language), w = y(async (h) => {
124
+ const f = p(h);
125
+ if (f === s)
126
+ return;
127
+ const P = `${L?.(n.pathname, f) ?? n.pathname}${n.search}${n.hash}`, S = B(n);
128
+ x(t, f), await u.changeLanguage(f), await l?.(f), P !== S && m(P, { replace: !0 });
129
+ }, [
130
+ u,
131
+ s,
132
+ n,
133
+ m,
134
+ l,
135
+ p,
136
+ L,
137
+ t
138
+ ]);
139
+ v(() => {
140
+ x(t, s);
141
+ }, [s, t]), v(() => {
142
+ const h = p(c?.() ?? "");
143
+ !h || h === s || u.changeLanguage(h);
144
+ }, [c, u, s, p]), v(() => {
145
+ const h = $?.(n.pathname);
146
+ if (!h?.lang || h.ambiguous)
147
+ return;
148
+ const f = L?.(n.pathname, s);
149
+ !f || f === n.pathname || m(`${f}${n.search}${n.hash}`, { replace: !0 });
150
+ }, [s, n.hash, n.pathname, n.search, m, $, L]);
151
+ const R = z(() => ({ lang: s, changeLanguage: w }), [w, s]);
152
+ return /* @__PURE__ */ T(I.Provider, { value: R, children: a });
153
+ }
154
+ export {
155
+ Z as L,
156
+ X as a,
157
+ Y as b,
158
+ Q as c,
159
+ A as d,
160
+ W as u
161
+ };
@@ -0,0 +1,124 @@
1
+ import { jsx as O } from "react/jsx-runtime";
2
+ import { useRef as T, useState as W, useLayoutEffect as Y } from "react";
3
+ import { useOutlet as q, useLocation as G, useNavigationType as J } from "react-router-dom";
4
+ import { c as C } from "./classNames-CcykAxZN.js";
5
+ const Q = "kosmioMobileTransitionDirection", _ = {
6
+ enabled: !0
7
+ };
8
+ function m(e = "/") {
9
+ const t = String(e ?? "").trim();
10
+ return !t || t === "/" ? "/" : t.replace(/\/+$/, "") || "/";
11
+ }
12
+ function V(e, t) {
13
+ return !(e.routeKey && e.routeKey !== t.routeMatch?.routeKey || e.pathname && m(e.pathname) !== t.pathname || typeof e.match == "function" && !e.match(t));
14
+ }
15
+ function $(e) {
16
+ return m(e).split("/").filter(Boolean);
17
+ }
18
+ function z(e, t) {
19
+ return t.length > e.length ? !1 : t.every((n, o) => e[o] === n);
20
+ }
21
+ function X(e, t) {
22
+ const n = m(e), o = m(t);
23
+ if (n === o)
24
+ return null;
25
+ const r = $(n), a = $(o);
26
+ return z(a, r) ? "forward" : z(r, a) ? "back" : null;
27
+ }
28
+ function Z({ navigationType: e, directionHint: t, previousPathname: n, pathname: o }) {
29
+ if (t === "back" || t === "forward")
30
+ return t;
31
+ const r = n ? X(n, o) : null;
32
+ return r || (e === "POP" ? "back" : "forward");
33
+ }
34
+ function H({
35
+ pathname: e,
36
+ navigationType: t,
37
+ directionHint: n,
38
+ previousPathname: o = null,
39
+ rules: r = [],
40
+ matchRoute: a,
41
+ defaultTransition: b = _
42
+ }) {
43
+ const c = m(e), u = typeof a == "function" ? a(c) : null, M = {
44
+ pathname: c,
45
+ navigationType: t,
46
+ routeMatch: u
47
+ }, N = [...r].reverse().find((v) => V(v, M)), l = Z({
48
+ pathname: c,
49
+ navigationType: t,
50
+ directionHint: n,
51
+ previousPathname: o
52
+ }), i = {
53
+ ..._,
54
+ ...b,
55
+ ...N ?? {}
56
+ };
57
+ return {
58
+ enabled: i.enabled !== !1,
59
+ durationMs: Number.isFinite(i.durationMs) ? i.durationMs : null,
60
+ routeMatch: u,
61
+ direction: l,
62
+ enterClassName: i.enterClassName ?? (l === "back" ? "mobile-route-layer--enter-back" : "mobile-route-layer--enter-forward"),
63
+ exitClassName: i.exitClassName ?? (l === "back" ? "mobile-route-layer--exit-back" : "mobile-route-layer--exit-forward")
64
+ };
65
+ }
66
+ function ee() {
67
+ return typeof window > "u" || typeof window.matchMedia != "function" ? !1 : window.matchMedia("(prefers-reduced-motion: reduce)").matches;
68
+ }
69
+ function ae({
70
+ outlet: e,
71
+ location: t,
72
+ navigationType: n,
73
+ isMobile: o,
74
+ rules: r = [],
75
+ router: a,
76
+ matchRoute: b,
77
+ stateKey: c = Q,
78
+ defaultTransition: u,
79
+ className: M = "",
80
+ layerClassName: N = "",
81
+ style: l,
82
+ ...i
83
+ }) {
84
+ const v = q(), I = G(), K = J(), F = e ?? v, k = t ?? I, R = n ?? K, s = k?.pathname ?? "/", g = a?.matchLocalizedRoute ?? b, w = k?.key ?? s, L = k?.state, x = T(!1), D = T(s), E = T(null), [f, U] = W(() => ({
85
+ className: "",
86
+ key: w,
87
+ durationMs: u?.durationMs
88
+ }));
89
+ Y(() => {
90
+ const d = `${w ?? ""}:${s}`;
91
+ if (E.current === d)
92
+ return;
93
+ E.current = d;
94
+ const P = L?.[c], S = D.current, h = H({
95
+ pathname: s,
96
+ navigationType: R,
97
+ directionHint: P,
98
+ previousPathname: S,
99
+ rules: r,
100
+ matchRoute: g,
101
+ defaultTransition: u
102
+ }), j = S !== s, A = o && x.current && j && h.enabled && !ee() && (R !== "REPLACE" || P === "back"), y = {
103
+ className: A ? h.enterClassName : "",
104
+ key: A ? `${d}:${h.direction}` : d,
105
+ durationMs: h.durationMs
106
+ };
107
+ D.current = s, x.current = !0, U((p) => p.key === y.key && p.className === y.className && p.durationMs === y.durationMs ? p : y);
108
+ }, [u, o, w, L, s, g, R, r, c]);
109
+ const B = f.durationMs != null ? { "--kosmio-mobile-route-duration": `${f.durationMs}ms` } : void 0;
110
+ return /* @__PURE__ */ O("div", { className: C("mobile-route-stack full-w full-view", M), style: l, ...i, children: /* @__PURE__ */ O(
111
+ "div",
112
+ {
113
+ className: C("mobile-route-layer mobile-route-layer--current", f.className, N),
114
+ style: B,
115
+ children: F
116
+ },
117
+ f.key
118
+ ) });
119
+ }
120
+ export {
121
+ Q as D,
122
+ ae as M,
123
+ H as r
124
+ };
@@ -0,0 +1,105 @@
1
+ import { useRef as d, useMemo as B, useEffect as O } from "react";
2
+ import { useLocation as M, useNavigate as q, useNavigationType as A } from "react-router-dom";
3
+ const D = /* @__PURE__ */ new Set(["recommendations", "livestock", "operations", "analytics", "registry"]), H = [".overlay-layer", ".select-dropdown.is-open"], N = ".backdrop", P = ".select-dropdown.is-open", x = [".overlay-layer", '[aria-modal="true"]', ".profile-operations-menu"];
4
+ function R(e) {
5
+ return `${e.pathname}${e.search}${e.hash}`;
6
+ }
7
+ function I(e, n, o) {
8
+ if (e.length === 0)
9
+ return e.push(n), e;
10
+ if (o === "REPLACE")
11
+ return e[e.length - 1] = n, e;
12
+ if (o === "POP") {
13
+ const t = e.lastIndexOf(n);
14
+ return t >= 0 ? e.slice(0, t + 1) : (e.push(n), e);
15
+ }
16
+ return e[e.length - 1] !== n && e.push(n), e;
17
+ }
18
+ function T(e) {
19
+ return typeof document > "u" ? !1 : e.some((n) => document.querySelector(n));
20
+ }
21
+ function h(e) {
22
+ e.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: !0, cancelable: !0 }));
23
+ }
24
+ function S(e) {
25
+ e.dispatchEvent(new MouseEvent("mousedown", { bubbles: !0, cancelable: !0 }));
26
+ }
27
+ function $(e) {
28
+ return T(e) ? (typeof document < "u" && h(document), typeof window < "u" && h(window), !0) : !1;
29
+ }
30
+ function Y({
31
+ closeableSelectSelectors: e,
32
+ selectSheetBackdropSelector: n,
33
+ selectDropdownSelector: o
34
+ }) {
35
+ if (!T(e) || typeof document > "u")
36
+ return !1;
37
+ const t = document.querySelector(n);
38
+ return t instanceof HTMLElement ? (t.click(), !0) : document.querySelector(o) && document.body ? (S(document.body), !0) : !1;
39
+ }
40
+ function z(e) {
41
+ return $(e);
42
+ }
43
+ function U(e, n, o) {
44
+ const t = o?.matchLocalizedRoute?.(e);
45
+ return n.has(t?.routeKey ?? "");
46
+ }
47
+ function j({
48
+ app: e,
49
+ isNative: n = !1,
50
+ router: o,
51
+ mainRouteKeys: t = D,
52
+ transitionStateKey: i,
53
+ closeableSelectSelectors: a = H,
54
+ selectSheetBackdropSelector: l = N,
55
+ selectDropdownSelector: E = P,
56
+ closeableOverlaySelectors: p = x
57
+ }) {
58
+ const r = M(), m = q(), L = A(), u = d([]), w = d(r), v = d(R(r)), C = B(
59
+ () => t instanceof Set ? t : new Set(t),
60
+ [t]
61
+ );
62
+ return O(() => {
63
+ const c = R(r);
64
+ w.current = r, v.current = c, u.current = I([...u.current], c, L);
65
+ }, [r, L]), O(() => {
66
+ if (!n || typeof e?.addListener != "function")
67
+ return;
68
+ let c = !1, b = null;
69
+ const _ = ({ canGoBack: s }) => {
70
+ if (c || Y({ closeableSelectSelectors: a, selectSheetBackdropSelector: l, selectDropdownSelector: E }) || z(p))
71
+ return;
72
+ const y = w.current, g = v.current;
73
+ if (!U(y.pathname, C, o)) {
74
+ const f = u.current.at(-2);
75
+ if (f && f !== g) {
76
+ u.current = u.current.slice(0, -1), m(f, {
77
+ replace: !0,
78
+ state: i ? { [i]: "back" } : void 0
79
+ });
80
+ return;
81
+ }
82
+ s && typeof window < "u" && window.history.back();
83
+ }
84
+ };
85
+ return e.addListener("backButton", _).then((s) => {
86
+ b = s;
87
+ }), () => {
88
+ c = !0, b?.remove?.();
89
+ };
90
+ }, [
91
+ e,
92
+ p,
93
+ a,
94
+ n,
95
+ C,
96
+ m,
97
+ o,
98
+ E,
99
+ l,
100
+ i
101
+ ]), null;
102
+ }
103
+ export {
104
+ j as N
105
+ };
@@ -0,0 +1,34 @@
1
+ import { jsx as a } from "react/jsx-runtime";
2
+ import { useSyncExternalStore as c, useMemo as u, useContext as l, createContext as S } from "react";
3
+ import { k as m, a as O } from "./offlineWriteQueue-C31IjyB_.js";
4
+ const o = {
5
+ isOnline: !0,
6
+ isSyncing: !1,
7
+ pendingSyncCount: 0,
8
+ hasPendingSync: !1,
9
+ scopeKey: "anonymous:no-tenant"
10
+ }, s = S(o), C = () => l(s);
11
+ function d({
12
+ children: i,
13
+ scopeKey: n = o.scopeKey,
14
+ getQueueState: e = O,
15
+ subscribeQueue: r = m
16
+ }) {
17
+ const t = c(
18
+ r,
19
+ () => e(n),
20
+ () => e(n)
21
+ ), f = u(
22
+ () => ({
23
+ ...t,
24
+ scopeKey: n
25
+ }),
26
+ [n, t]
27
+ );
28
+ return /* @__PURE__ */ a(s.Provider, { value: f, children: i });
29
+ }
30
+ export {
31
+ o as D,
32
+ d as O,
33
+ C as u
34
+ };