strata-react 0.1.10 → 0.1.12

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 CHANGED
@@ -126,7 +126,7 @@ function KilnRoom() {
126
126
  | Keyboard | `useHotkeys`, `KeysLegend`, `Shortcut`, `useActiveItem`, `ActiveList`, `isTypingTarget` | For queues worked from the keyboard; one shortcut list drives the handler and the legend; keys never fire while typing; answering moves focus to the next item |
127
127
  | Theme | `ThemeProvider`, `useColorScheme`, `useSystemColorScheme`, `ColorSchemeChoice`, `colorSchemeScript` | System, light or dark; sets `.dark`, persists in localStorage when it can; `ColorSchemeChoice` is a radio list for a settings page, or `compact` icon segments named "Appearance" for an app with no settings page |
128
128
  | Feedback | `UndoBar`, `useUndoable`, `Done` | Undo before confirm; the hook owns which rows are out of view (`isRemoved`), a failed commit brings the row back with Try again in the same bar, and `flush()` commits before a dependent action; `Done` is the one celebration, and it must say what happens next |
129
- | Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); units and counts join with a non-breaking space |
129
+ | Helpers | `cn`, `format`, `createFormat`, `NBSP` | `cn` knows `type-*`; all numbers and dates through `Intl`; `format.integer(n)`, `.decimal(n)`, `.percent(n)` are callable and keep Intl's methods; `format.bytes(n, unit?)` writes sizes in decimal units (`byteUnit` shares one unit across figures); `format.date(at)` ("8 Nov 2026") and `format.dateTime(at)` ("8 Nov 2026, 06:05"), like `clock`, `day` and `shortDay`, take a Date, ISO string or epoch ms; `createFormat(locale, { timeZone })` fixes the zone; units and counts join with a non-breaking space |
130
130
  | Testing | `strata-react/testing`: `renderWithStrata`, `createTestQueryClient`, `installLayoutShims`, `installFakeIntersectionObserver` | Router + query client around Testing Library's `render`; a fixed box and ResizeObserver so measuring components render in jsdom; an IntersectionObserver the test fires with `scrollToEnd()` or `intersect(el)`. Role names keep the non-breaking space from `format.count`, so match them with the same call or a `\s` regex |
131
131
  | Visual regression | `strata-react/visual` and the `strata-visual` command | Screenshots an app's Storybook and its routes in each MSW state, light and dark, against baselines in the app's repo |
132
132
 
@@ -187,10 +187,28 @@ npx strata-visual --filter review--error # only some shots
187
187
  ```
188
188
 
189
189
  Baselines are named `route--state--viewport--theme.png` (`review--empty--phone--dark.png`) and
190
- stories `story-id--theme.png`. A shot fails when it differs from its baseline (pixelmatch at
191
- threshold 0.1, anti-aliasing ignored, 20 stray pixels allowed, any size change), when the page
190
+ stories `story-id--theme.png`. A shot fails when it differs from its baseline, when any of its
191
+ text is drawn in a font installed on the machine rather than one the page loaded, when the page
192
192
  throws or logs an error, when it makes a request no handler answers, or, in CI, when it has no
193
- baseline. Story tags pick the viewport: `visual-wide`, `visual-phone`, `no-visual` to skip.
193
+ baseline.
194
+
195
+ **Comparison.** Both images are box-blurred 3×3, then compared with pixelmatch at threshold 0.1
196
+ (anti-aliased pixels ignored) and 4 differing pixels allowed; any size change fails. The blur
197
+ keeps the ink an edge or glyph lays down and drops where exactly it fell, which is what differs
198
+ between rasterisers: on Strata's 218 shots, Chromium's GPU raster path moved up to 159 pixels a
199
+ shot under plain pixelmatch and at most 1 after the blur, while a changed letter still moved 2 to
200
+ 4,500 (172 of 182 caught, against 145 before). Override with `compare: { threshold, blur,
201
+ maxDiffPixels, includeAA }` only with evidence from your own screens. The summary line says how
202
+ many shots were pixel-identical and how many matched within tolerance (the five closest to
203
+ failing are listed as `within`).
204
+
205
+ **Fonts.** Every face must be one the page loads: bundle it with `@fontsource` (or your own
206
+ `@font-face`) and name it first in the theme's `--font-*`. Strata's defaults fall through to
207
+ `ui-sans-serif`, which is Cantarell on one Linux, DejaVu Sans on another and San Francisco on a
208
+ Mac, and a glyph missing from a web font (an arrow, `⌘`) falls back the same way; no threshold
209
+ absorbs that. The runner asks Chromium which face drew each element's text and fails the shot
210
+ naming the face and an example (`"DejaVu Sans" in <kbd> "⌘"`). `systemFonts: "warn"` reports
211
+ instead; `"allow"` skips the check. Story tags pick the viewport: `visual-wide`, `visual-phone`, `no-visual` to skip.
194
212
  Pages run in UTC and `en-US`; set `timezone`, `locale` or a frozen `time` in the config.
195
213
  Strata's own suite (`strata-visual.config.ts`, with the kiln-room example app in
196
214
  `examples/kiln-app/`) is a working reference.
@@ -210,6 +228,9 @@ In CI, install the pinned Chromium and upload the diffs when it fails:
210
228
  Write the baselines in that same Chromium on Linux (in CI, or in the Playwright Docker image of
211
229
  the pinned version): a Mac renders text differently. `--update` records the Chromium and platform
212
230
  in `.strata-visual.json`, and a run that differs says so beside its failures.
231
+ `STRATA_VISUAL_CHROMIUM_ARGS` adds Chromium flags for experiments; Strata's
232
+ `visual-portability` workflow uses it to run the suite under GPU rasterisation, on arm64 and on
233
+ another Ubuntu against the committed baselines.
213
234
 
214
235
  ## Develop
215
236
 
package/dist/index.d.ts CHANGED
@@ -6,7 +6,7 @@
6
6
  * @module strata-react
7
7
  */
8
8
  export { cn, typeSteps } from './lib/utils';
9
- export { createFormat, format, NBSP, type ByteUnit, type Format, type NumberFormatter } from './lib/format';
9
+ export { createFormat, format, NBSP, toDate, type ByteUnit, type DateFormatter, type DateInput, type Format, type FormatOptions, type NumberFormatter } from './lib/format';
10
10
  export type { IconComponent } from './lib/icon';
11
11
  export { Button, IconButton, RowAction, buttonVariants, type ButtonProps, type IconButtonProps, type RowActionProps, } from './components/button';
12
12
  export { Checkbox, type CheckboxProps } from './components/checkbox';
package/dist/index.js CHANGED
@@ -19,6 +19,21 @@ var BYTE_UNITS = [
19
19
  "PB"
20
20
  ];
21
21
  var BYTE_SIZE = Object.fromEntries(BYTE_UNITS.map((u, i) => [u, 1e3 ** i]));
22
+ /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
23
+ function toDate(value) {
24
+ const date = value instanceof Date ? value : new Date(value);
25
+ if (Number.isNaN(date.getTime())) throw new RangeError(`Not a date: ${JSON.stringify(String(value))}`);
26
+ return date;
27
+ }
28
+ function callableDate(df) {
29
+ const format = (value) => df.format(toDate(value));
30
+ return Object.assign(format, {
31
+ format,
32
+ formatToParts: (value) => df.formatToParts(toDate(value)),
33
+ formatRange: (start, end) => df.formatRange(toDate(start), toDate(end)),
34
+ resolvedOptions: () => df.resolvedOptions()
35
+ });
36
+ }
22
37
  function callable(nf) {
23
38
  const format = (value) => nf.format(value);
24
39
  return Object.assign(format, {
@@ -27,40 +42,59 @@ function callable(nf) {
27
42
  resolvedOptions: () => nf.resolvedOptions()
28
43
  });
29
44
  }
30
- /** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, byte sizes, and counted nouns. */
31
- function createFormat(locale) {
45
+ /** Intl formatters for one locale (and optionally one time zone): integers, decimals, percent, dates, times, units with a non-breaking space, byte sizes, and counted nouns. */
46
+ function createFormat(locale, options = {}) {
47
+ const { timeZone } = options;
48
+ const dates = (opts) => callableDate(new Intl.DateTimeFormat(locale, {
49
+ ...opts,
50
+ timeZone
51
+ }));
32
52
  const integer = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 0 }));
33
53
  const decimal = callable(new Intl.NumberFormat(locale, { maximumFractionDigits: 1 }));
34
54
  const percent = callable(new Intl.NumberFormat(locale, {
35
55
  style: "percent",
36
56
  maximumFractionDigits: 0
37
57
  }));
38
- const clock = new Intl.DateTimeFormat(locale, {
58
+ const clock = dates({
39
59
  hour: "2-digit",
40
60
  minute: "2-digit"
41
61
  });
42
- const day = new Intl.DateTimeFormat(locale, {
62
+ const day = dates({
43
63
  weekday: "long",
44
64
  day: "numeric",
45
65
  month: "long"
46
66
  });
47
- const shortDay = new Intl.DateTimeFormat(locale, {
67
+ const shortDay = dates({
48
68
  weekday: "short",
49
69
  hour: "2-digit",
50
70
  minute: "2-digit"
51
71
  });
72
+ const date = dates({ dateStyle: "medium" });
73
+ const dateTime = dates({
74
+ dateStyle: "medium",
75
+ timeStyle: "short"
76
+ });
52
77
  const withUnit = (value, unit, fmt = integer) => `${fmt.format(value)} ${unit}`;
53
78
  return {
54
79
  locale,
80
+ /** The zone times are shown in, or `undefined` for the viewer's own. */
81
+ timeZone,
55
82
  /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
56
83
  integer,
57
84
  /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
58
85
  decimal,
59
86
  /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
60
87
  percent,
88
+ /** A time of day: `format.clock(at)` is "06:05". */
61
89
  clock,
90
+ /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
62
91
  day,
92
+ /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
63
93
  shortDay,
94
+ /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
95
+ date,
96
+ /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
97
+ dateTime,
64
98
  /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
65
99
  withUnit,
66
100
  /** A temperature in °C, joined by a non-breaking space. */
@@ -2086,6 +2120,6 @@ function nextAfter(pages, items, itemKey, hidden) {
2086
2120
  if (held.length === 0 || pages.length > 1 && !lastPageAddedAny) return last;
2087
2121
  return held[held.length - 1];
2088
2122
  }
2089
- export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
2123
+ export { ActiveList, AppShell, AsyncButton, Breadcrumb, BulkBar, Button, COLOR_SCHEME_STORAGE_KEY, Checkbox, ChoiceGroup, ColorSchemeChoice, CompositionBar, DataTable, DataView, Done, EmptyState, Field, HttpError, IconButton, InfiniteList, Input, KeysLegend, LineChart, LinkCard, LinkCardList, Meter, Metric, MetricStrip, NBSP, NativeSelect, PageHeader, RowAction, SideNav, Skeleton, Status, StrataQueryProvider, TableSkeleton, Tabs, Textarea, ThemeProvider, UndoBar, VirtualList, buttonVariants, cn, colorSchemeScript, createFormat, createQueryClient, crossedThreshold, describeActionError, describeHttpError, fetchJson, format, isTypingTarget, parseSort, serialiseSort, toDate, toLoad, typeSteps, useActiveItem, useAsyncAction, useColorScheme, useHotkeys, useInfiniteLoad, useLoad, useSelection, useSystemColorScheme, useUndoable };
2090
2124
 
2091
2125
  //# sourceMappingURL=index.js.map