@eqtylab/equality 3.8.0 → 3.9.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,118 @@
1
+ # @eqtylab/equality
2
+
3
+ [![npm version](https://img.shields.io/npm/v/@eqtylab/equality)](https://www.npmjs.com/package/@eqtylab/equality)
4
+ [![license](https://img.shields.io/npm/l/@eqtylab/equality)](https://github.com/eqtylab/equality/blob/main/LICENSE)
5
+
6
+ EQTY Lab's design system: accessible React components and design tokens, built on Radix UI and Tailwind CSS v4.
7
+
8
+ **[Documentation](https://equality.eqtylab.io/)** · **[Components](https://equality.eqtylab.io/components/button/)** · **[GitHub](https://github.com/eqtylab/equality)**
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm install @eqtylab/equality
14
+ # or
15
+ pnpm add @eqtylab/equality
16
+ # or
17
+ yarn add @eqtylab/equality
18
+ ```
19
+
20
+ Requires `react` and `react-dom` 18.2 or newer.
21
+
22
+ ## Setup
23
+
24
+ ### Tailwind CSS v4 (recommended)
25
+
26
+ Import the theme config, then a preflight, in your global stylesheet:
27
+
28
+ ```css
29
+ @import '@eqtylab/equality/theme-config.css';
30
+ @import '@eqtylab/equality/preflight.css' layer(base);
31
+ ```
32
+
33
+ `theme-config.css` must come first, because it declares the layer order the preflight relies on. It builds on Tailwind, so `tailwindcss` v4 must be installed in your project.
34
+
35
+ | Stylesheet | Contains |
36
+ | ---------------------------------------- | ----------------------------------------------------- |
37
+ | `@eqtylab/equality/theme-config.css` | Tokens, theme, utilities and components. No reset. |
38
+ | `@eqtylab/equality/preflight.css` | Base styles reset for `html` and everything under it. |
39
+ | `@eqtylab/equality/preflight-scoped.css` | The same reset, only inside `[data-equality-root]`. |
40
+
41
+ If you're embedding Equality in a site that has its own base styles, use `preflight-scoped.css` instead so the reset doesn't affect the rest of the page.
42
+
43
+ ### Without Tailwind
44
+
45
+ Wrap your app, or the part of it that uses Equality, in `ThemeProvider`:
46
+
47
+ ```tsx
48
+ import { ThemeProvider } from '@eqtylab/equality';
49
+
50
+ export function Root() {
51
+ return (
52
+ <ThemeProvider>
53
+ <App />
54
+ </ThemeProvider>
55
+ );
56
+ }
57
+ ```
58
+
59
+ See the [Usage guide](https://equality.eqtylab.io/getting-started/usage/) for embedding in host sites, shadow DOM, and portalled surfaces.
60
+
61
+ ## Usage
62
+
63
+ ```tsx
64
+ import { Button, Card, CardContent } from '@eqtylab/equality';
65
+
66
+ export function Example() {
67
+ return (
68
+ <Card>
69
+ <CardContent>
70
+ <Button>Save changes</Button>
71
+ </CardContent>
72
+ </Card>
73
+ );
74
+ }
75
+ ```
76
+
77
+ Every component accepts a `className` prop for local style overrides. Component styles are scoped with CSS Modules, so overrides don't leak into other components.
78
+
79
+ ## Themes
80
+
81
+ Equality ships `light` and `dark` themes. Set the active theme on the root element:
82
+
83
+ ```html
84
+ <html data-equality-theme="dark"></html>
85
+ ```
86
+
87
+ To apply a stored or system preference before first paint, inline the `initializeTheme` script in your document `<head>`:
88
+
89
+ ```tsx
90
+ import { initializeTheme } from '@eqtylab/equality/scripts';
91
+
92
+ <head>
93
+ <script>{initializeTheme()}</script>
94
+ </head>;
95
+ ```
96
+
97
+ See [Themes](https://equality.eqtylab.io/getting-started/themes/) for options.
98
+
99
+ ## Entry points
100
+
101
+ | Import path | Contents |
102
+ | ---------------------------------------- | -------------------------------------------------- |
103
+ | `@eqtylab/equality` | Components, `ThemeProvider`, and hooks |
104
+ | `@eqtylab/equality/scripts` | `initializeTheme` inline script for theme startup |
105
+ | `@eqtylab/equality/syntax-language` | File name to syntax grammar mapping for CodeBlock |
106
+ | `@eqtylab/equality/theme-config.css` | Tailwind v4 theme config |
107
+ | `@eqtylab/equality/preflight.css` | Global base styles reset |
108
+ | `@eqtylab/equality/preflight-scoped.css` | Base styles reset scoped to `[data-equality-root]` |
109
+
110
+ The package ships ES modules and CommonJS builds with TypeScript types.
111
+
112
+ ## Accessibility
113
+
114
+ Components are built on [Radix UI](https://www.radix-ui.com/) primitives and designed for keyboard navigation and screen readers.
115
+
116
+ ## License
117
+
118
+ [Apache-2.0](https://github.com/eqtylab/equality/blob/main/LICENSE)
package/dist/index.cjs CHANGED
@@ -3776,6 +3776,22 @@ var RELATIVE_DIVISIONS = [
3776
3776
  { amount: Number.POSITIVE_INFINITY, unit: "year" }
3777
3777
  ];
3778
3778
  var LIVE_INTERVAL_MS = 3e4;
3779
+ var MINUTE_MS = 6e4;
3780
+ var HOUR_MS = 60 * MINUTE_MS;
3781
+ var DAY_MS = 24 * HOUR_MS;
3782
+ var YEAR_MS = 365.25 * DAY_MS;
3783
+ var MONTH_MS = YEAR_MS / 12;
3784
+ var JUST_NOW_MS = 45e3;
3785
+ var COARSE_AFTER_MS = 90 * DAY_MS;
3786
+ var FINE_UNITS = [
3787
+ { ms: DAY_MS, unit: "day" },
3788
+ { ms: HOUR_MS, unit: "hour" },
3789
+ { ms: MINUTE_MS, unit: "minute" }
3790
+ ];
3791
+ var COARSE_UNITS = [
3792
+ { ms: YEAR_MS, unit: "year" },
3793
+ { ms: MONTH_MS, unit: "month" }
3794
+ ];
3779
3795
  var NO_DATE_PLACEHOLDER = "---";
3780
3796
  function isMissing(value) {
3781
3797
  return value == null || typeof value === "string" && value.trim() === "";
@@ -3788,8 +3804,8 @@ function formatAbsolute(date, timeZone, options, locale) {
3788
3804
  return new Intl.DateTimeFormat(locale, { ...options, timeZone }).format(date);
3789
3805
  }
3790
3806
  function formatRelative(date, now, locale) {
3807
+ if (Math.abs(date.getTime() - now.getTime()) < JUST_NOW_MS) return "Just now";
3791
3808
  let duration = (date.getTime() - now.getTime()) / 1e3;
3792
- if (Math.abs(duration) < 45) return "Just now";
3793
3809
  const rtf = new Intl.RelativeTimeFormat(locale, { numeric: "auto" });
3794
3810
  for (const division of RELATIVE_DIVISIONS) {
3795
3811
  if (Math.abs(duration) < division.amount) {
@@ -3799,6 +3815,30 @@ function formatRelative(date, now, locale) {
3799
3815
  }
3800
3816
  return "Just now";
3801
3817
  }
3818
+ function measureSpan(spanMs) {
3819
+ const units = spanMs < COARSE_AFTER_MS ? FINE_UNITS : COARSE_UNITS;
3820
+ const index = units.findIndex(({ ms: ms2 }) => spanMs >= ms2);
3821
+ if (index === -1) return { value: 1, unit: units[units.length - 1].unit };
3822
+ const { ms, unit } = units[index];
3823
+ const value = Math.round(spanMs / ms);
3824
+ const next = units[index - 1];
3825
+ if (next && value * ms >= next.ms) {
3826
+ return { value: Math.round(spanMs / next.ms), unit: next.unit };
3827
+ }
3828
+ return { value, unit };
3829
+ }
3830
+ function formatDirected(date, now, mode, locale) {
3831
+ const spanMs = mode === "until" ? date.getTime() - now.getTime() : now.getTime() - date.getTime();
3832
+ if (spanMs <= 0) return null;
3833
+ if (mode === "since" && spanMs < JUST_NOW_MS) return "Just now";
3834
+ const { value, unit } = measureSpan(spanMs);
3835
+ if (mode === "until") {
3836
+ return new Intl.NumberFormat(locale, { style: "unit", unit, unitDisplay: "long" }).format(
3837
+ value
3838
+ );
3839
+ }
3840
+ return new Intl.RelativeTimeFormat(locale, { numeric: "always" }).format(-value, unit);
3841
+ }
3802
3842
  function FormatDate({
3803
3843
  date,
3804
3844
  displayAs = "absolute",
@@ -3814,13 +3854,13 @@ function FormatDate({
3814
3854
  const parsed = React15__namespace.useMemo(() => isMissing(date) ? null : toDate(date), [date]);
3815
3855
  const [now, setNow] = React15__namespace.useState(() => /* @__PURE__ */ new Date());
3816
3856
  const [mounted, setMounted] = React15__namespace.useState(false);
3817
- const isRelative = displayAs === "relative";
3857
+ const isAbsolute = displayAs === "absolute";
3818
3858
  React15__namespace.useEffect(() => setMounted(true), []);
3819
3859
  React15__namespace.useEffect(() => {
3820
- if (!isRelative || !live) return;
3860
+ if (isAbsolute || !live) return;
3821
3861
  const id = setInterval(() => setNow(/* @__PURE__ */ new Date()), LIVE_INTERVAL_MS);
3822
3862
  return () => clearInterval(id);
3823
- }, [isRelative, live]);
3863
+ }, [isAbsolute, live]);
3824
3864
  if (missing) {
3825
3865
  return /* @__PURE__ */ jsxRuntime.jsx("span", { className: cn(styles57__default.default["format-date"], className), "aria-label": "No date", ...props, children: NO_DATE_PLACEHOLDER });
3826
3866
  }
@@ -3834,12 +3874,23 @@ function FormatDate({
3834
3874
  absoluteOptions ?? DEFAULT_ABSOLUTE_OPTIONS,
3835
3875
  locale
3836
3876
  );
3837
- if (!isRelative) {
3877
+ if (isAbsolute) {
3838
3878
  return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children: absolute });
3839
3879
  }
3840
- const relative = mounted ? formatRelative(parsed, now, locale) : absolute;
3880
+ const measured = !mounted ? absolute : displayAs === "relative" ? formatRelative(parsed, now, locale) : formatDirected(parsed, now, displayAs, locale);
3881
+ if (measured === null) {
3882
+ return /* @__PURE__ */ jsxRuntime.jsx(
3883
+ "span",
3884
+ {
3885
+ className: cn(styles57__default.default["format-date"], className),
3886
+ "aria-label": displayAs === "until" ? "Date has passed" : "Date not yet reached",
3887
+ ...props,
3888
+ children: NO_DATE_PLACEHOLDER
3889
+ }
3890
+ );
3891
+ }
3841
3892
  if (!tooltip) {
3842
- return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children: relative });
3893
+ return /* @__PURE__ */ jsxRuntime.jsx("time", { dateTime: machineValue, className: cn(styles57__default.default["format-date"], className), ...props, children: measured });
3843
3894
  }
3844
3895
  return /* @__PURE__ */ jsxRuntime.jsx(TooltipProvider, { children: /* @__PURE__ */ jsxRuntime.jsxs(Tooltip, { children: [
3845
3896
  /* @__PURE__ */ jsxRuntime.jsx(TooltipTrigger, { asChild: true, children: /* @__PURE__ */ jsxRuntime.jsx(
@@ -3849,7 +3900,7 @@ function FormatDate({
3849
3900
  tabIndex: 0,
3850
3901
  className: cn(styles57__default.default["format-date"], styles57__default.default["format-date--interactive"], className),
3851
3902
  ...props,
3852
- children: relative
3903
+ children: measured
3853
3904
  }
3854
3905
  ) }),
3855
3906
  /* @__PURE__ */ jsxRuntime.jsx(TooltipContent, { children: absolute })