strata-react 0.1.11 → 0.1.13

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.
@@ -3,18 +3,42 @@ export declare const NBSP = "\u00A0";
3
3
  export type ByteUnit = "B" | "kB" | "MB" | "GB" | "TB" | "PB";
4
4
  /** An `Intl.NumberFormat` that can also be called directly: `f(n)` is `f.format(n)`. */
5
5
  export type NumberFormatter = ((value: number | bigint) => string) & Pick<Intl.NumberFormat, "format" | "formatToParts" | "resolvedOptions">;
6
- /** Intl formatters for one locale: integers, decimals, percent, times, days, units with a non-breaking space, byte sizes, and counted nouns. */
7
- export declare function createFormat(locale: string): {
6
+ /** What a date formatter accepts: a Date, an ISO 8601 string, or epoch milliseconds. */
7
+ export type DateInput = Date | string | number;
8
+ /** An `Intl.DateTimeFormat` that can also be called directly, with a Date, an ISO string or epoch milliseconds. */
9
+ export type DateFormatter = ((value: DateInput) => string) & {
10
+ format: (value: DateInput) => string;
11
+ formatToParts: (value: DateInput) => Intl.DateTimeFormatPart[];
12
+ formatRange: (start: DateInput, end: DateInput) => string;
13
+ } & Pick<Intl.DateTimeFormat, "resolvedOptions">;
14
+ /** Options shared by every date formatter one `createFormat` call makes. */
15
+ export interface FormatOptions {
16
+ /** An IANA zone ("Europe/London", "UTC") to show times in. Left out, times are the viewer's own. */
17
+ timeZone?: string;
18
+ }
19
+ /** A Date from a Date, an ISO string or epoch milliseconds; throws a RangeError naming the input when it is not a date. */
20
+ export declare function toDate(value: DateInput): Date;
21
+ /** 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. */
22
+ export declare function createFormat(locale: string, options?: FormatOptions): {
8
23
  locale: string;
24
+ /** The zone times are shown in, or `undefined` for the viewer's own. */
25
+ timeZone: string | undefined;
9
26
  /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
10
27
  integer: NumberFormatter;
11
28
  /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
12
29
  decimal: NumberFormatter;
13
30
  /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
14
31
  percent: NumberFormatter;
15
- clock: Intl.DateTimeFormat;
16
- day: Intl.DateTimeFormat;
17
- shortDay: Intl.DateTimeFormat;
32
+ /** A time of day: `format.clock(at)` is "06:05". */
33
+ clock: DateFormatter;
34
+ /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
35
+ day: DateFormatter;
36
+ /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
37
+ shortDay: DateFormatter;
38
+ /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
39
+ date: DateFormatter;
40
+ /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
41
+ dateTime: DateFormatter;
18
42
  /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
19
43
  withUnit: (value: number, unit: string, fmt?: Pick<Intl.NumberFormat, "format">) => string;
20
44
  /** A temperature in °C, joined by a non-breaking space. */
@@ -38,15 +62,24 @@ export type Format = ReturnType<typeof createFormat>;
38
62
  /** The en-GB formatters. */
39
63
  export declare const format: {
40
64
  locale: string;
65
+ /** The zone times are shown in, or `undefined` for the viewer's own. */
66
+ timeZone: string | undefined;
41
67
  /** Whole numbers with grouping: `format.integer(1222)` is "1,222". */
42
68
  integer: NumberFormatter;
43
69
  /** One decimal place at most: `format.decimal(3.14)` is "3.1". */
44
70
  decimal: NumberFormatter;
45
71
  /** A ratio as a whole percent: `format.percent(0.42)` is "42%". */
46
72
  percent: NumberFormatter;
47
- clock: Intl.DateTimeFormat;
48
- day: Intl.DateTimeFormat;
49
- shortDay: Intl.DateTimeFormat;
73
+ /** A time of day: `format.clock(at)` is "06:05". */
74
+ clock: DateFormatter;
75
+ /** A day without its year, for this week's things: `format.day(at)` is "Sunday 8 November". */
76
+ day: DateFormatter;
77
+ /** A weekday and time, for chart axes and recent rows: `format.shortDay(at)` is "Sun 06:05". */
78
+ shortDay: DateFormatter;
79
+ /** A date with its year, for a record or a deadline: `format.date(at)` is "8 Nov 2026". */
80
+ date: DateFormatter;
81
+ /** A date and time, for a log or history row: `format.dateTime(at)` is "8 Nov 2026, 06:05". */
82
+ dateTime: DateFormatter;
50
83
  /** A figure and its unit joined by a non-breaking space (`NBSP`), so they never wrap apart. */
51
84
  withUnit: (value: number, unit: string, fmt?: Pick<Intl.NumberFormat, "format">) => string;
52
85
  /** A temperature in °C, joined by a non-breaking space. */
@@ -1,8 +1,10 @@
1
1
  import { RenderOptions } from '@testing-library/react';
2
+ import { RouteObject, To } from 'react-router';
2
3
  import { QueryClient } from '@tanstack/react-query';
3
4
  import { ColorSchemePreference } from '../components/theme';
4
5
  /**
5
- * Test helpers: render a component inside a router and a query client, as a Strata app runs it,
6
+ * Test helpers: render a component, or a whole route tree, inside a router and a query client, as
7
+ * a Strata app runs it,
6
8
  * and fill the gaps jsdom leaves (layout, ResizeObserver, IntersectionObserver). Use with MSW for
7
9
  * the network, never module mocks.
8
10
  *
@@ -13,12 +15,80 @@ export { installLayoutShims, type LayoutBox } from './layout';
13
15
  export { installFakeIntersectionObserver, type FakeIntersectionObserverControls, type FakeObserver, } from './intersection-observer';
14
16
  /** A query client for tests: no retries, and nothing goes stale or is collected mid-test. */
15
17
  export declare function createTestQueryClient(): QueryClient;
16
- /** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */
17
- export declare function renderWithStrata(ui: React.ReactElement, { route, client, colorScheme, ...options }?: RenderOptions & {
18
+ /** The options `renderWithStrata` and `renderRoutes` share, beside Testing Library's own. */
19
+ export type StrataRenderOptions = Omit<RenderOptions, "wrapper"> & {
20
+ /** The URL the test starts at, with its search and hash (`/bookings?sort=pieces.desc`). Defaults to `/`. */
18
21
  route?: string;
22
+ /** The query client; a fresh `createTestQueryClient()` when left out. */
19
23
  client?: QueryClient;
24
+ /** The colour scheme to render; `light` when left out. */
20
25
  colorScheme?: ColorSchemePreference;
21
- }): {
26
+ };
27
+ /** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */
28
+ export declare function renderWithStrata(ui: React.ReactElement, { route, client, colorScheme, ...options }?: StrataRenderOptions): {
29
+ container: HTMLElement;
30
+ baseElement: HTMLElement;
31
+ debug: (baseElement?: import('react-dom/client').Container | (Element | Document) | Array<import('react-dom/client').Container | (Element | Document)> | undefined, maxLength?: number | undefined, options?: import('pretty-format').OptionsReceived | undefined) => void;
32
+ rerender: (ui: React.ReactNode) => void;
33
+ unmount: () => void;
34
+ asFragment: () => DocumentFragment;
35
+ getByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement;
36
+ getAllByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement[];
37
+ queryByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement | null;
38
+ queryAllByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement[];
39
+ findByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
40
+ findAllByLabelText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
41
+ getByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement;
42
+ getAllByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
43
+ queryByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement | null;
44
+ queryAllByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
45
+ findByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
46
+ findAllByPlaceholderText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
47
+ getByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement;
48
+ getAllByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement[];
49
+ queryByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement | null;
50
+ queryAllByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined) => HTMLElement[];
51
+ findByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
52
+ findAllByText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').SelectorMatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
53
+ getByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement;
54
+ getAllByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
55
+ queryByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement | null;
56
+ queryAllByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
57
+ findByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
58
+ findAllByAltText: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
59
+ getByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement;
60
+ getAllByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
61
+ queryByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement | null;
62
+ queryAllByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
63
+ findByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
64
+ findAllByTitle: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
65
+ getByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement;
66
+ getAllByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
67
+ queryByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement | null;
68
+ queryAllByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
69
+ findByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
70
+ findAllByDisplayValue: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
71
+ getByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined) => HTMLElement;
72
+ getAllByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined) => HTMLElement[];
73
+ queryByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined) => HTMLElement | null;
74
+ queryAllByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined) => HTMLElement[];
75
+ findByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
76
+ findAllByRole: (role: import('@testing-library/dom').ByRoleMatcher, options?: import('@testing-library/dom').ByRoleOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
77
+ getByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement;
78
+ getAllByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
79
+ queryByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement | null;
80
+ queryAllByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined) => HTMLElement[];
81
+ findByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
82
+ findAllByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
83
+ client: QueryClient;
84
+ };
85
+ /** `renderRoutes`'s options: `renderWithStrata`'s, plus the app's `basename`. */
86
+ export type RenderRoutesOptions = StrataRenderOptions & {
87
+ /** The base path the app is served under, as passed to `createBrowserRouter`. */
88
+ basename?: string;
89
+ };
90
+ /** Testing Library's `render` of an app's route tree in a memory data router at `route`, with Strata's providers. */
91
+ export declare function renderRoutes(routes: RouteObject[], { route, basename, client, colorScheme, ...options }?: RenderRoutesOptions): {
22
92
  container: HTMLElement;
23
93
  baseElement: HTMLElement;
24
94
  debug: (baseElement?: import('react-dom/client').Container | (Element | Document) | Array<import('react-dom/client').Container | (Element | Document)> | undefined, maxLength?: number | undefined, options?: import('pretty-format').OptionsReceived | undefined) => void;
@@ -74,4 +144,6 @@ export declare function renderWithStrata(ui: React.ReactElement, { route, client
74
144
  findByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement>;
75
145
  findAllByTestId: (id: import('@testing-library/dom').Matcher, options?: import('@testing-library/dom').MatcherOptions | undefined, waitForElementOptions?: import('@testing-library/dom').waitForOptions | undefined) => Promise<HTMLElement[]>;
76
146
  client: QueryClient;
147
+ router: import('react-router').DataRouter;
148
+ navigate: (to: To | number) => Promise<void>;
77
149
  };
package/dist/testing.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { c as ThemeProvider, n as createQueryClient, t as StrataQueryProvider } from "./query-CkOrBm3w.js";
2
2
  import "react";
3
3
  import { jsx } from "react/jsx-runtime";
4
- import { MemoryRouter } from "react-router";
4
+ import { MemoryRouter, RouterProvider, createMemoryRouter } from "react-router";
5
5
  import { act, render } from "@testing-library/react";
6
6
  // src/testing/layout.ts
7
7
  /** A DOMRect-shaped object, for stand-ins that report geometry. */
@@ -172,17 +172,24 @@ function createTestQueryClient() {
172
172
  gcTime: Infinity
173
173
  } } });
174
174
  }
175
- /** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */
176
- function renderWithStrata(ui, { route = "/", client = createTestQueryClient(), colorScheme = "light", ...options } = {}) {
177
- const Wrapper = ({ children }) => /* @__PURE__ */ jsx(ThemeProvider, {
175
+ function StrataProviders({ client, colorScheme, children }) {
176
+ return /* @__PURE__ */ jsx(ThemeProvider, {
178
177
  defaultPreference: colorScheme,
179
178
  storageKey: null,
180
179
  children: /* @__PURE__ */ jsx(StrataQueryProvider, {
181
180
  client,
182
- children: /* @__PURE__ */ jsx(MemoryRouter, {
183
- initialEntries: [route],
184
- children
185
- })
181
+ children
182
+ })
183
+ });
184
+ }
185
+ /** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */
186
+ function renderWithStrata(ui, { route = "/", client = createTestQueryClient(), colorScheme = "light", ...options } = {}) {
187
+ const Wrapper = ({ children }) => /* @__PURE__ */ jsx(StrataProviders, {
188
+ client,
189
+ colorScheme,
190
+ children: /* @__PURE__ */ jsx(MemoryRouter, {
191
+ initialEntries: [route],
192
+ children
186
193
  })
187
194
  });
188
195
  return {
@@ -193,6 +200,27 @@ function renderWithStrata(ui, { route = "/", client = createTestQueryClient(), c
193
200
  })
194
201
  };
195
202
  }
196
- export { createTestQueryClient, installFakeIntersectionObserver, installLayoutShims, renderWithStrata };
203
+ /** Testing Library's `render` of an app's route tree in a memory data router at `route`, with Strata's providers. */
204
+ function renderRoutes(routes, { route, basename, client = createTestQueryClient(), colorScheme = "light", ...options } = {}) {
205
+ const router = createMemoryRouter(routes, {
206
+ initialEntries: [route ?? basename ?? "/"],
207
+ basename
208
+ });
209
+ const result = render(/* @__PURE__ */ jsx(StrataProviders, {
210
+ client,
211
+ colorScheme,
212
+ children: /* @__PURE__ */ jsx(RouterProvider, { router })
213
+ }), options);
214
+ const navigate = (to) => act(async () => {
215
+ await (typeof to === "number" ? router.navigate(to) : router.navigate(to));
216
+ });
217
+ return {
218
+ client,
219
+ router,
220
+ navigate,
221
+ ...result
222
+ };
223
+ }
224
+ export { createTestQueryClient, installFakeIntersectionObserver, installLayoutShims, renderRoutes, renderWithStrata };
197
225
 
198
226
  //# sourceMappingURL=testing.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"testing.js","names":[],"sources":["../src/testing/layout.ts","../src/testing/intersection-observer.ts","../src/testing/index.tsx"],"sourcesContent":["// jsdom does no layout: every box is 0×0 and there is no ResizeObserver. Components that measure\n// (LineChart's width, DataTable and VirtualList through TanStack Virtual) then render nothing to\n// assert on, so an app testing a screen built from them hits the same wall Strata's own suite did.\n// These shims give every element one fixed box and a ResizeObserver that reports it once on\n// observe. Real layout is checked by the visual suite in Chromium, never here.\n\n// jsdom has no DOMRect constructor in every version, so rects are plain objects of the same shape.\n/** A DOMRect-shaped object, for stand-ins that report geometry. */\nexport function box(x: number, y: number, width: number, height: number): DOMRect {\n return { x, y, width, height, top: y, left: x, right: x + width, bottom: y + height, toJSON() { return this; } } as DOMRect;\n}\n\n/** The box every element reports while the shims are installed. */\nexport interface LayoutBox {\n width: number;\n height: number;\n}\n\n/**\n * Give jsdom a fixed box for every element (`getBoundingClientRect`, `offset*`, `client*`) and a\n * ResizeObserver that reports it on observe, so measuring components render. Defaults to 640×280.\n * Call once in a Vitest setup file; returns a function that puts the originals back.\n */\nexport function installLayoutShims({ width = 640, height = 280 }: Partial<LayoutBox> = {}): () => void {\n const restore: (() => void)[] = [];\n const replace = (target: object, prop: string, descriptor: PropertyDescriptor) => {\n const before = Object.getOwnPropertyDescriptor(target, prop);\n Object.defineProperty(target, prop, { configurable: true, ...descriptor });\n restore.push(() => {\n if (before) Object.defineProperty(target, prop, before);\n else delete (target as Record<string, unknown>)[prop];\n });\n };\n\n class FixedResizeObserver implements ResizeObserver {\n constructor(private readonly callback: ResizeObserverCallback) {}\n observe(target: Element) {\n this.callback([{ target, contentRect: { width, height } } as unknown as ResizeObserverEntry], this);\n }\n unobserve() {}\n disconnect() {}\n }\n if (!globalThis.ResizeObserver) replace(globalThis, \"ResizeObserver\", { writable: true, value: FixedResizeObserver });\n\n replace(Element.prototype, \"getBoundingClientRect\", {\n writable: true,\n value: () => box(0, 0, width, height),\n });\n for (const [prop, value] of [[\"offsetWidth\", width], [\"offsetHeight\", height], [\"clientWidth\", width], [\"clientHeight\", height]] as const) {\n replace(HTMLElement.prototype, prop, { get: () => value });\n }\n\n return () => {\n for (const undo of restore.reverse()) undo();\n };\n}\n","// jsdom has no IntersectionObserver and does no layout, so nothing a component observes ever comes\n// into view in a unit test. Infinite lists load the next page when a sentinel at the end of the\n// list intersects, and before this helper every app wrote its own firable fake to test that\n// (strata-react issue #12, from strata-listory). This one stands in for the global, records what\n// each observer watches, and lets the test say when something scrolls into view: `scrollToEnd()`\n// for the common case, `intersect(el)` for one element. Entries are delivered inside `act` so the\n// state updates they cause are flushed before the next assertion, as a real scroll would be.\n\nimport { act } from \"@testing-library/react\";\nimport { box } from \"./layout\";\n\n/** One stand-in observer: its callback, options and the elements it currently watches. */\nexport interface FakeObserver {\n readonly callback: IntersectionObserverCallback;\n readonly options: IntersectionObserverInit;\n readonly targets: ReadonlySet<Element>;\n}\n\n/** The controls `installFakeIntersectionObserver` returns. */\nexport interface FakeIntersectionObserverControls {\n /** Every observer created since install, including disconnected ones (their target sets are empty). */\n readonly observers: readonly FakeObserver[];\n /** Report `el` to every observer watching it: in view by default, or out of view with `false`. Returns how many observers were told. */\n intersect(el: Element, isIntersecting?: boolean): number;\n /** Report every watched element as in view, as if the person scrolled to the end of the list. Returns how many elements were reported. */\n scrollToEnd(): number;\n /** Put back whatever `IntersectionObserver` was there before install. */\n uninstall(): void;\n}\n\nfunction entryFor(target: Element, isIntersecting: boolean): IntersectionObserverEntry {\n const rect = target.getBoundingClientRect();\n return {\n target,\n isIntersecting,\n intersectionRatio: isIntersecting ? 1 : 0,\n boundingClientRect: rect,\n intersectionRect: isIntersecting ? rect : box(0, 0, 0, 0),\n rootBounds: null,\n time: performance.now(),\n };\n}\n\n/**\n * Replace `globalThis.IntersectionObserver` with a stand-in the test fires by hand. Call it in\n * `beforeEach` and call `uninstall()` in `afterEach`.\n *\n * @example\n * let io: FakeIntersectionObserverControls;\n * beforeEach(() => { io = installFakeIntersectionObserver(); });\n * afterEach(() => io.uninstall());\n *\n * it(\"loads the next page at the end of the list\", async () => {\n * renderWithStrata(<Pieces />);\n * await screen.findByRole(\"list\", { name: \"Pieces\" });\n * io.scrollToEnd();\n * expect(await screen.findByText(\"Celadon bowl\")).toBeInTheDocument();\n * });\n */\nexport function installFakeIntersectionObserver(): FakeIntersectionObserverControls {\n const previous = Object.getOwnPropertyDescriptor(globalThis, \"IntersectionObserver\");\n const observers: (FakeObserver & { targets: Set<Element>; self: IntersectionObserver })[] = [];\n\n class FakeIntersectionObserver implements IntersectionObserver {\n readonly root: Element | Document | null;\n readonly rootMargin: string;\n readonly thresholds: readonly number[];\n readonly scrollMargin = \"0px\";\n private readonly record: (typeof observers)[number];\n\n constructor(callback: IntersectionObserverCallback, options: IntersectionObserverInit = {}) {\n this.root = options.root ?? null;\n this.rootMargin = options.rootMargin ?? \"0px\";\n const threshold = options.threshold ?? 0;\n this.thresholds = Array.isArray(threshold) ? threshold : [threshold];\n this.record = { callback, options, targets: new Set(), self: this };\n observers.push(this.record);\n }\n observe(target: Element) {\n this.record.targets.add(target);\n }\n unobserve(target: Element) {\n this.record.targets.delete(target);\n }\n disconnect() {\n this.record.targets.clear();\n }\n takeRecords(): IntersectionObserverEntry[] {\n return [];\n }\n }\n\n Object.defineProperty(globalThis, \"IntersectionObserver\", {\n configurable: true,\n writable: true,\n value: FakeIntersectionObserver,\n });\n\n const deliver = (observer: (typeof observers)[number], targets: readonly Element[], isIntersecting: boolean) => {\n act(() => observer.callback(targets.map((t) => entryFor(t, isIntersecting)), observer.self));\n };\n\n return {\n observers,\n intersect(el, isIntersecting = true) {\n const watching = observers.filter((o) => o.targets.has(el));\n for (const o of watching) deliver(o, [el], isIntersecting);\n return watching.length;\n },\n scrollToEnd() {\n // Snapshot every observer's targets before any callback runs: a callback that loads more\n // may observe a new sentinel, on this observer or another, which the person has not\n // scrolled to yet.\n const batches = observers.map((o) => [o, [...o.targets]] as const).filter(([, targets]) => targets.length > 0);\n for (const [o, targets] of batches) deliver(o, targets, true);\n return batches.reduce((n, [, targets]) => n + targets.length, 0);\n },\n uninstall() {\n if (previous) Object.defineProperty(globalThis, \"IntersectionObserver\", previous);\n else delete (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver;\n },\n };\n}\n","/**\n * Test helpers: render a component inside a router and a query client, as a Strata app runs it,\n * and fill the gaps jsdom leaves (layout, ResizeObserver, IntersectionObserver). Use with MSW for\n * the network, never module mocks.\n *\n * @module strata-react/testing\n */\nimport * as React from \"react\";\nimport { render, type RenderOptions } from \"@testing-library/react\";\nimport { MemoryRouter } from \"react-router\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { StrataQueryProvider, createQueryClient } from \"../query\";\nimport { ThemeProvider, type ColorSchemePreference } from \"../components/theme\";\n\nexport { installLayoutShims, type LayoutBox } from \"./layout\";\nexport {\n installFakeIntersectionObserver,\n type FakeIntersectionObserverControls,\n type FakeObserver,\n} from \"./intersection-observer\";\n\n// Render a component the way a Strata app runs it: inside a router and a query client. Tests use\n// MSW for the network (see CLAUDE.md), never module mocks, so the real fetch/query/DataView path\n// runs. Each call gets a fresh QueryClient with retries off, so a test that serves a 500 sees the\n// error at once instead of after the retry delay. It also runs inside a ThemeProvider with\n// storage off, so `useColorScheme` works and a test can render the dark scheme with\n// `colorScheme: \"dark\"` without touching localStorage or leaking state into the next test.\n\n/** A query client for tests: no retries, and nothing goes stale or is collected mid-test. */\nexport function createTestQueryClient() {\n return createQueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, gcTime: Infinity } } });\n}\n\n/** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */\nexport function renderWithStrata(\n ui: React.ReactElement,\n {\n route = \"/\",\n client = createTestQueryClient(),\n colorScheme = \"light\",\n ...options\n }: RenderOptions & { route?: string; client?: QueryClient; colorScheme?: ColorSchemePreference } = {},\n) {\n const Wrapper = ({ children }: { children: React.ReactNode }) => (\n <ThemeProvider defaultPreference={colorScheme} storageKey={null}>\n <StrataQueryProvider client={client}>\n <MemoryRouter initialEntries={[route]}>{children}</MemoryRouter>\n </StrataQueryProvider>\n </ThemeProvider>\n );\n return { client, ...render(ui, { wrapper: Wrapper, ...options }) };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,IAAI,GAAW,GAAW,OAAe,QAAyB;CAChF,OAAO;EAAE;EAAG;EAAG;EAAO;EAAQ,KAAK;EAAG,MAAM;EAAG,OAAO,IAAI;EAAO,QAAQ,IAAI;EAAQ,SAAS;GAAE,OAAO;EAAM;CAAE;AACjH;;;;;;AAaA,SAAgB,mBAAmB,EAAE,QAAQ,KAAK,SAAS,QAA4B,CAAC,GAAe;CACrG,MAAM,UAA0B,CAAC;CACjC,MAAM,WAAW,QAAgB,MAAc,eAAmC;EAChF,MAAM,SAAS,OAAO,yBAAyB,QAAQ,IAAI;EAC3D,OAAO,eAAe,QAAQ,MAAM;GAAE,cAAc;GAAM,GAAG;EAAW,CAAC;EACzE,QAAQ,WAAW;GACjB,IAAI,QAAQ,OAAO,eAAe,QAAQ,MAAM,MAAM;QACjD,OAAQ,OAAmC;EAClD,CAAC;CACH;CAEA,MAAM,oBAA8C;EACrB;EAA7B,YAAY,UAAmD;GAAlC,KAAA,WAAA;EAAmC;EAChE,QAAQ,QAAiB;GACvB,KAAK,SAAS,CAAC;IAAE;IAAQ,aAAa;KAAE;KAAO;IAAO;GAAE,CAAmC,GAAG,IAAI;EACpG;EACA,YAAY,CAAC;EACb,aAAa,CAAC;CAChB;CACA,IAAI,CAAC,WAAW,gBAAgB,QAAQ,YAAY,kBAAkB;EAAE,UAAU;EAAM,OAAO;CAAoB,CAAC;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;GAC3B,UAAA,oBAAC,cAAD;IAAc,gBAAgB,CAAC,KAAK;IAAI;GAAuB,CAAA;EAC5C,CAAA;CACR,CAAA;CAEjB,OAAO;EAAE;EAAQ,GAAG,OAAO,IAAI;GAAE,SAAS;GAAS,GAAG;EAAQ,CAAC;CAAE;AACnE"}
1
+ {"version":3,"file":"testing.js","names":[],"sources":["../src/testing/layout.ts","../src/testing/intersection-observer.ts","../src/testing/index.tsx"],"sourcesContent":["// jsdom does no layout: every box is 0×0 and there is no ResizeObserver. Components that measure\n// (LineChart's width, DataTable and VirtualList through TanStack Virtual) then render nothing to\n// assert on, so an app testing a screen built from them hits the same wall Strata's own suite did.\n// These shims give every element one fixed box and a ResizeObserver that reports it once on\n// observe. Real layout is checked by the visual suite in Chromium, never here.\n\n// jsdom has no DOMRect constructor in every version, so rects are plain objects of the same shape.\n/** A DOMRect-shaped object, for stand-ins that report geometry. */\nexport function box(x: number, y: number, width: number, height: number): DOMRect {\n return { x, y, width, height, top: y, left: x, right: x + width, bottom: y + height, toJSON() { return this; } } as DOMRect;\n}\n\n/** The box every element reports while the shims are installed. */\nexport interface LayoutBox {\n width: number;\n height: number;\n}\n\n/**\n * Give jsdom a fixed box for every element (`getBoundingClientRect`, `offset*`, `client*`) and a\n * ResizeObserver that reports it on observe, so measuring components render. Defaults to 640×280.\n * Call once in a Vitest setup file; returns a function that puts the originals back.\n */\nexport function installLayoutShims({ width = 640, height = 280 }: Partial<LayoutBox> = {}): () => void {\n const restore: (() => void)[] = [];\n const replace = (target: object, prop: string, descriptor: PropertyDescriptor) => {\n const before = Object.getOwnPropertyDescriptor(target, prop);\n Object.defineProperty(target, prop, { configurable: true, ...descriptor });\n restore.push(() => {\n if (before) Object.defineProperty(target, prop, before);\n else delete (target as Record<string, unknown>)[prop];\n });\n };\n\n class FixedResizeObserver implements ResizeObserver {\n constructor(private readonly callback: ResizeObserverCallback) {}\n observe(target: Element) {\n this.callback([{ target, contentRect: { width, height } } as unknown as ResizeObserverEntry], this);\n }\n unobserve() {}\n disconnect() {}\n }\n if (!globalThis.ResizeObserver) replace(globalThis, \"ResizeObserver\", { writable: true, value: FixedResizeObserver });\n\n replace(Element.prototype, \"getBoundingClientRect\", {\n writable: true,\n value: () => box(0, 0, width, height),\n });\n for (const [prop, value] of [[\"offsetWidth\", width], [\"offsetHeight\", height], [\"clientWidth\", width], [\"clientHeight\", height]] as const) {\n replace(HTMLElement.prototype, prop, { get: () => value });\n }\n\n return () => {\n for (const undo of restore.reverse()) undo();\n };\n}\n","// jsdom has no IntersectionObserver and does no layout, so nothing a component observes ever comes\n// into view in a unit test. Infinite lists load the next page when a sentinel at the end of the\n// list intersects, and before this helper every app wrote its own firable fake to test that\n// (strata-react issue #12, from strata-listory). This one stands in for the global, records what\n// each observer watches, and lets the test say when something scrolls into view: `scrollToEnd()`\n// for the common case, `intersect(el)` for one element. Entries are delivered inside `act` so the\n// state updates they cause are flushed before the next assertion, as a real scroll would be.\n\nimport { act } from \"@testing-library/react\";\nimport { box } from \"./layout\";\n\n/** One stand-in observer: its callback, options and the elements it currently watches. */\nexport interface FakeObserver {\n readonly callback: IntersectionObserverCallback;\n readonly options: IntersectionObserverInit;\n readonly targets: ReadonlySet<Element>;\n}\n\n/** The controls `installFakeIntersectionObserver` returns. */\nexport interface FakeIntersectionObserverControls {\n /** Every observer created since install, including disconnected ones (their target sets are empty). */\n readonly observers: readonly FakeObserver[];\n /** Report `el` to every observer watching it: in view by default, or out of view with `false`. Returns how many observers were told. */\n intersect(el: Element, isIntersecting?: boolean): number;\n /** Report every watched element as in view, as if the person scrolled to the end of the list. Returns how many elements were reported. */\n scrollToEnd(): number;\n /** Put back whatever `IntersectionObserver` was there before install. */\n uninstall(): void;\n}\n\nfunction entryFor(target: Element, isIntersecting: boolean): IntersectionObserverEntry {\n const rect = target.getBoundingClientRect();\n return {\n target,\n isIntersecting,\n intersectionRatio: isIntersecting ? 1 : 0,\n boundingClientRect: rect,\n intersectionRect: isIntersecting ? rect : box(0, 0, 0, 0),\n rootBounds: null,\n time: performance.now(),\n };\n}\n\n/**\n * Replace `globalThis.IntersectionObserver` with a stand-in the test fires by hand. Call it in\n * `beforeEach` and call `uninstall()` in `afterEach`.\n *\n * @example\n * let io: FakeIntersectionObserverControls;\n * beforeEach(() => { io = installFakeIntersectionObserver(); });\n * afterEach(() => io.uninstall());\n *\n * it(\"loads the next page at the end of the list\", async () => {\n * renderWithStrata(<Pieces />);\n * await screen.findByRole(\"list\", { name: \"Pieces\" });\n * io.scrollToEnd();\n * expect(await screen.findByText(\"Celadon bowl\")).toBeInTheDocument();\n * });\n */\nexport function installFakeIntersectionObserver(): FakeIntersectionObserverControls {\n const previous = Object.getOwnPropertyDescriptor(globalThis, \"IntersectionObserver\");\n const observers: (FakeObserver & { targets: Set<Element>; self: IntersectionObserver })[] = [];\n\n class FakeIntersectionObserver implements IntersectionObserver {\n readonly root: Element | Document | null;\n readonly rootMargin: string;\n readonly thresholds: readonly number[];\n readonly scrollMargin = \"0px\";\n private readonly record: (typeof observers)[number];\n\n constructor(callback: IntersectionObserverCallback, options: IntersectionObserverInit = {}) {\n this.root = options.root ?? null;\n this.rootMargin = options.rootMargin ?? \"0px\";\n const threshold = options.threshold ?? 0;\n this.thresholds = Array.isArray(threshold) ? threshold : [threshold];\n this.record = { callback, options, targets: new Set(), self: this };\n observers.push(this.record);\n }\n observe(target: Element) {\n this.record.targets.add(target);\n }\n unobserve(target: Element) {\n this.record.targets.delete(target);\n }\n disconnect() {\n this.record.targets.clear();\n }\n takeRecords(): IntersectionObserverEntry[] {\n return [];\n }\n }\n\n Object.defineProperty(globalThis, \"IntersectionObserver\", {\n configurable: true,\n writable: true,\n value: FakeIntersectionObserver,\n });\n\n const deliver = (observer: (typeof observers)[number], targets: readonly Element[], isIntersecting: boolean) => {\n act(() => observer.callback(targets.map((t) => entryFor(t, isIntersecting)), observer.self));\n };\n\n return {\n observers,\n intersect(el, isIntersecting = true) {\n const watching = observers.filter((o) => o.targets.has(el));\n for (const o of watching) deliver(o, [el], isIntersecting);\n return watching.length;\n },\n scrollToEnd() {\n // Snapshot every observer's targets before any callback runs: a callback that loads more\n // may observe a new sentinel, on this observer or another, which the person has not\n // scrolled to yet.\n const batches = observers.map((o) => [o, [...o.targets]] as const).filter(([, targets]) => targets.length > 0);\n for (const [o, targets] of batches) deliver(o, targets, true);\n return batches.reduce((n, [, targets]) => n + targets.length, 0);\n },\n uninstall() {\n if (previous) Object.defineProperty(globalThis, \"IntersectionObserver\", previous);\n else delete (globalThis as { IntersectionObserver?: unknown }).IntersectionObserver;\n },\n };\n}\n","/**\n * Test helpers: render a component, or a whole route tree, inside a router and a query client, as\n * a Strata app runs it,\n * and fill the gaps jsdom leaves (layout, ResizeObserver, IntersectionObserver). Use with MSW for\n * the network, never module mocks.\n *\n * @module strata-react/testing\n */\nimport * as React from \"react\";\nimport { act, render, type RenderOptions } from \"@testing-library/react\";\nimport { MemoryRouter, RouterProvider, createMemoryRouter, type RouteObject, type To } from \"react-router\";\nimport { QueryClient } from \"@tanstack/react-query\";\nimport { StrataQueryProvider, createQueryClient } from \"../query\";\nimport { ThemeProvider, type ColorSchemePreference } from \"../components/theme\";\n\nexport { installLayoutShims, type LayoutBox } from \"./layout\";\nexport {\n installFakeIntersectionObserver,\n type FakeIntersectionObserverControls,\n type FakeObserver,\n} from \"./intersection-observer\";\n\n// Render a component the way a Strata app runs it: inside a router and a query client. Tests use\n// MSW for the network (see CLAUDE.md), never module mocks, so the real fetch/query/DataView path\n// runs. Each call gets a fresh QueryClient with retries off, so a test that serves a 500 sees the\n// error at once instead of after the retry delay. It also runs inside a ThemeProvider with\n// storage off, so `useColorScheme` works and a test can render the dark scheme with\n// `colorScheme: \"dark\"` without touching localStorage or leaking state into the next test.\n\n/** A query client for tests: no retries, and nothing goes stale or is collected mid-test. */\nexport function createTestQueryClient() {\n return createQueryClient({ defaultOptions: { queries: { retry: false, staleTime: Infinity, gcTime: Infinity } } });\n}\n\n/** The options `renderWithStrata` and `renderRoutes` share, beside Testing Library's own. */\nexport type StrataRenderOptions = Omit<RenderOptions, \"wrapper\"> & {\n /** The URL the test starts at, with its search and hash (`/bookings?sort=pieces.desc`). Defaults to `/`. */\n route?: string;\n /** The query client; a fresh `createTestQueryClient()` when left out. */\n client?: QueryClient;\n /** The colour scheme to render; `light` when left out. */\n colorScheme?: ColorSchemePreference;\n};\n\n// The providers every Strata app has above its router, in the order an app nests them.\nfunction StrataProviders({\n client,\n colorScheme,\n children,\n}: {\n client: QueryClient;\n colorScheme: ColorSchemePreference;\n children: React.ReactNode;\n}) {\n return (\n <ThemeProvider defaultPreference={colorScheme} storageKey={null}>\n <StrataQueryProvider client={client}>{children}</StrataQueryProvider>\n </ThemeProvider>\n );\n}\n\n/** Testing Library's `render` inside `StrataQueryProvider` and a `MemoryRouter` at `route`. */\nexport function renderWithStrata(\n ui: React.ReactElement,\n { route = \"/\", client = createTestQueryClient(), colorScheme = \"light\", ...options }: StrataRenderOptions = {},\n) {\n const Wrapper = ({ children }: { children: React.ReactNode }) => (\n <StrataProviders client={client} colorScheme={colorScheme}>\n <MemoryRouter initialEntries={[route]}>{children}</MemoryRouter>\n </StrataProviders>\n );\n return { client, ...render(ui, { wrapper: Wrapper, ...options }) };\n}\n\n// Render an app's own route tree: its layout routes and <Outlet />s, index routes, redirects\n// (<Navigate /> or a loader's redirect()), loaders, actions and error elements. Those only run in\n// a data router, which <MemoryRouter> is not, so renderWithStrata cannot show them; this builds\n// the memory twin of the app's createBrowserRouter from the same RouteObject[] the app exports,\n// so the test and the app cannot drift. The providers and options are renderWithStrata's.\n// `basename` is the app's own (the kiln app runs under /kiln), and `route` is the full URL,\n// basename included, as the browser would show it. The router is returned so a test can assert\n// where a redirect landed (`router.state.location`), and `navigate` moves it inside act().\n\n/** `renderRoutes`'s options: `renderWithStrata`'s, plus the app's `basename`. */\nexport type RenderRoutesOptions = StrataRenderOptions & {\n /** The base path the app is served under, as passed to `createBrowserRouter`. */\n basename?: string;\n};\n\n/** Testing Library's `render` of an app's route tree in a memory data router at `route`, with Strata's providers. */\nexport function renderRoutes(\n routes: RouteObject[],\n {\n route,\n basename,\n client = createTestQueryClient(),\n colorScheme = \"light\",\n ...options\n }: RenderRoutesOptions = {},\n) {\n const router = createMemoryRouter(routes, { initialEntries: [route ?? basename ?? \"/\"], basename });\n const result = render(\n <StrataProviders client={client} colorScheme={colorScheme}>\n <RouterProvider router={router} />\n </StrataProviders>,\n options,\n );\n const navigate = (to: To | number) =>\n act(async () => {\n await (typeof to === \"number\" ? router.navigate(to) : router.navigate(to));\n });\n return { client, router, navigate, ...result };\n}\n"],"mappings":";;;;;;;AAQA,SAAgB,IAAI,GAAW,GAAW,OAAe,QAAyB;CAChF,OAAO;EAAE;EAAG;EAAG;EAAO;EAAQ,KAAK;EAAG,MAAM;EAAG,OAAO,IAAI;EAAO,QAAQ,IAAI;EAAQ,SAAS;GAAE,OAAO;EAAM;CAAE;AACjH;;;;;;AAaA,SAAgB,mBAAmB,EAAE,QAAQ,KAAK,SAAS,QAA4B,CAAC,GAAe;CACrG,MAAM,UAA0B,CAAC;CACjC,MAAM,WAAW,QAAgB,MAAc,eAAmC;EAChF,MAAM,SAAS,OAAO,yBAAyB,QAAQ,IAAI;EAC3D,OAAO,eAAe,QAAQ,MAAM;GAAE,cAAc;GAAM,GAAG;EAAW,CAAC;EACzE,QAAQ,WAAW;GACjB,IAAI,QAAQ,OAAO,eAAe,QAAQ,MAAM,MAAM;QACjD,OAAQ,OAAmC;EAClD,CAAC;CACH;CAEA,MAAM,oBAA8C;EACrB;EAA7B,YAAY,UAAmD;GAAlC,KAAA,WAAA;EAAmC;EAChE,QAAQ,QAAiB;GACvB,KAAK,SAAS,CAAC;IAAE;IAAQ,aAAa;KAAE;KAAO;IAAO;GAAE,CAAmC,GAAG,IAAI;EACpG;EACA,YAAY,CAAC;EACb,aAAa,CAAC;CAChB;CACA,IAAI,CAAC,WAAW,gBAAgB,QAAQ,YAAY,kBAAkB;EAAE,UAAU;EAAM,OAA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ACA,EAAE,QAAQ,KAAK,SAAS,sBAAsB,GAAG,cAAc,SAAS,GAAG,YAAiC,CAAC,GAC7G;CACA,MAAM,WAAW,EAAE,eACjB,oBAAC,iBAAD;EAAyB;EAAqB;EAC5C,UAAA,oBAAC,cAAD;GAAc,gBAAgB,CAAC,KAAK;GAAI;EAAuB,CAAA;CAChD,CAAA;CAEnB,OAAO;EAAE;EAAQ,GAAG,OAAO,IAAI;GAAE,SAAS;GAAS,GAAG;EAAQ,CAAC;CAAE;AACnE;;AAkBA,SAAgB,aACd,QACA,EACE,OACA,UACA,SAAS,sBAAsB,GAC/B,cAAc,SACd,GAAG,YACoB,CAAC,GAC1B;CACA,MAAM,SAAS,mBAAmB,QAAQ;EAAE,gBAAgB,CAAC,SAAS,YAAY,GAAG;EAAG;CAAS,CAAC;CAClG,MAAM,SAAS,OACb,oBAAC,iBAAD;EAAyB;EAAqB;EAC5C,UAAA,oBAAC,gBAAD,EAAwB,OAAS,CAAA;CAClB,CAAA,GACjB,OACF;CACA,MAAM,YAAY,OAChB,IAAI,YAAY;EACd,OAAO,OAAO,OAAO,WAAW,OAAO,SAAS,EAAE,IAAI,OAAO,SAAS,EAAE;CAC1E,CAAC;CACH,OAAO;EAAE;EAAQ;EAAQ;EAAU,GAAG;CAAO;AAC/C"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "strata-react",
3
- "version": "0.1.11",
3
+ "version": "0.1.13",
4
4
  "description": "React + Tailwind v4 components that ship structure, behaviour, states and a token contract, and no look: each product brings a theme generated from its own subject.",
5
5
  "repository": {
6
6
  "type": "git",