@devtime-ltd/ui-bench 0.0.0-stage → 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.
Files changed (112) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +247 -2
  3. package/dist/cjs/UiBench.js +67 -0
  4. package/dist/cjs/UiBench.native.js +77 -0
  5. package/dist/cjs/core/controller.js +147 -0
  6. package/dist/cjs/core/entry.js +35 -0
  7. package/dist/cjs/core/fixtures.js +102 -0
  8. package/dist/cjs/core/fragment.js +107 -0
  9. package/dist/cjs/core/inputs.js +83 -0
  10. package/dist/cjs/core/prefs.js +76 -0
  11. package/dist/cjs/core/props.js +16 -0
  12. package/dist/cjs/core/stage.js +129 -0
  13. package/dist/cjs/core/viewports.js +49 -0
  14. package/dist/cjs/dom/ControlBar.js +34 -0
  15. package/dist/cjs/dom/FixturePicker.js +105 -0
  16. package/dist/cjs/dom/Frame.js +171 -0
  17. package/dist/cjs/dom/InputsPanel.js +47 -0
  18. package/dist/cjs/dom/Landing.js +32 -0
  19. package/dist/cjs/dom/hashUrl.js +35 -0
  20. package/dist/cjs/dom/styles.js +261 -0
  21. package/dist/cjs/index.js +44 -0
  22. package/dist/cjs/native/Box.js +47 -0
  23. package/dist/cjs/native/ControlBar.js +50 -0
  24. package/dist/cjs/native/FixturePicker.js +65 -0
  25. package/dist/cjs/native/InputsPanel.js +67 -0
  26. package/dist/cjs/native/Landing.js +42 -0
  27. package/dist/cjs/native/Triangle.js +43 -0
  28. package/dist/cjs/native/theme.js +49 -0
  29. package/dist/cjs/package.json +1 -0
  30. package/dist/cjs/testing/index.js +59 -0
  31. package/dist/esm/UiBench.d.ts +2 -0
  32. package/dist/esm/UiBench.js +41 -0
  33. package/dist/esm/UiBench.js.map +1 -0
  34. package/dist/esm/UiBench.native.d.ts +2 -0
  35. package/dist/esm/UiBench.native.js +51 -0
  36. package/dist/esm/UiBench.native.js.map +1 -0
  37. package/dist/esm/core/controller.d.ts +43 -0
  38. package/dist/esm/core/controller.js +122 -0
  39. package/dist/esm/core/controller.js.map +1 -0
  40. package/dist/esm/core/entry.d.ts +8 -0
  41. package/dist/esm/core/entry.js +10 -0
  42. package/dist/esm/core/entry.js.map +1 -0
  43. package/dist/esm/core/fixtures.d.ts +27 -0
  44. package/dist/esm/core/fixtures.js +71 -0
  45. package/dist/esm/core/fixtures.js.map +1 -0
  46. package/dist/esm/core/fragment.d.ts +14 -0
  47. package/dist/esm/core/fragment.js +85 -0
  48. package/dist/esm/core/fragment.js.map +1 -0
  49. package/dist/esm/core/inputs.d.ts +30 -0
  50. package/dist/esm/core/inputs.js +52 -0
  51. package/dist/esm/core/inputs.js.map +1 -0
  52. package/dist/esm/core/prefs.d.ts +18 -0
  53. package/dist/esm/core/prefs.js +47 -0
  54. package/dist/esm/core/prefs.js.map +1 -0
  55. package/dist/esm/core/props.d.ts +23 -0
  56. package/dist/esm/core/props.js +2 -0
  57. package/dist/esm/core/props.js.map +1 -0
  58. package/dist/esm/core/stage.d.ts +50 -0
  59. package/dist/esm/core/stage.js +98 -0
  60. package/dist/esm/core/stage.js.map +1 -0
  61. package/dist/esm/core/viewports.d.ts +10 -0
  62. package/dist/esm/core/viewports.js +15 -0
  63. package/dist/esm/core/viewports.js.map +1 -0
  64. package/dist/esm/dom/ControlBar.d.ts +4 -0
  65. package/dist/esm/dom/ControlBar.js +8 -0
  66. package/dist/esm/dom/ControlBar.js.map +1 -0
  67. package/dist/esm/dom/FixturePicker.d.ts +6 -0
  68. package/dist/esm/dom/FixturePicker.js +82 -0
  69. package/dist/esm/dom/FixturePicker.js.map +1 -0
  70. package/dist/esm/dom/Frame.d.ts +9 -0
  71. package/dist/esm/dom/Frame.js +151 -0
  72. package/dist/esm/dom/Frame.js.map +1 -0
  73. package/dist/esm/dom/InputsPanel.d.ts +7 -0
  74. package/dist/esm/dom/InputsPanel.js +21 -0
  75. package/dist/esm/dom/InputsPanel.js.map +1 -0
  76. package/dist/esm/dom/Landing.d.ts +6 -0
  77. package/dist/esm/dom/Landing.js +6 -0
  78. package/dist/esm/dom/Landing.js.map +1 -0
  79. package/dist/esm/dom/hashUrl.d.ts +2 -0
  80. package/dist/esm/dom/hashUrl.js +9 -0
  81. package/dist/esm/dom/hashUrl.js.map +1 -0
  82. package/dist/esm/dom/styles.d.ts +1 -0
  83. package/dist/esm/dom/styles.js +235 -0
  84. package/dist/esm/dom/styles.js.map +1 -0
  85. package/dist/esm/index.d.ts +8 -0
  86. package/dist/esm/index.js +6 -0
  87. package/dist/esm/index.js.map +1 -0
  88. package/dist/esm/native/Box.d.ts +10 -0
  89. package/dist/esm/native/Box.js +21 -0
  90. package/dist/esm/native/Box.js.map +1 -0
  91. package/dist/esm/native/ControlBar.d.ts +5 -0
  92. package/dist/esm/native/ControlBar.js +24 -0
  93. package/dist/esm/native/ControlBar.js.map +1 -0
  94. package/dist/esm/native/FixturePicker.d.ts +6 -0
  95. package/dist/esm/native/FixturePicker.js +39 -0
  96. package/dist/esm/native/FixturePicker.js.map +1 -0
  97. package/dist/esm/native/InputsPanel.d.ts +7 -0
  98. package/dist/esm/native/InputsPanel.js +41 -0
  99. package/dist/esm/native/InputsPanel.js.map +1 -0
  100. package/dist/esm/native/Landing.d.ts +8 -0
  101. package/dist/esm/native/Landing.js +20 -0
  102. package/dist/esm/native/Landing.js.map +1 -0
  103. package/dist/esm/native/Triangle.d.ts +4 -0
  104. package/dist/esm/native/Triangle.js +17 -0
  105. package/dist/esm/native/Triangle.js.map +1 -0
  106. package/dist/esm/native/theme.d.ts +18 -0
  107. package/dist/esm/native/theme.js +19 -0
  108. package/dist/esm/native/theme.js.map +1 -0
  109. package/dist/esm/testing/index.d.ts +21 -0
  110. package/dist/esm/testing/index.js +33 -0
  111. package/dist/esm/testing/index.js.map +1 -0
  112. package/package.json +84 -4
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Devtime Ltd
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,248 @@
1
- # Temporary Holding Version
1
+ # UI Bench
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A UI bench for React, React Native and Expo. It renders your components on their own, from fixture files that sit beside them, inside your app's ordinary bundle. There is no second dev server, no config file and no generated code: the bench is a page of your own app.
4
+
5
+ - Fixtures are plain components, picked from a searchable list on the web or on the device itself.
6
+ - Inputs you can edit live, as JSON, and share in the URL.
7
+ - Viewport presets on the web that are real windows of that size, so media queries and `useWindowDimensions` respond, and a responsive one you resize by its handles.
8
+ - Seeded fixtures, against whatever your app uses for data.
9
+ - A link that shows one fixture with nothing around it, for screenshot tests.
10
+ - A helper that mounts every fixture in a unit test.
11
+
12
+ ```sh
13
+ npm install --save-dev @devtime-ltd/ui-bench
14
+ ```
15
+
16
+ ## A fixture
17
+
18
+ A fixture file is `<Name>.fixture.tsx`. Its default export is a component, or an object of named variants.
19
+
20
+ ```tsx
21
+ // Button.fixture.tsx
22
+ import { Button } from "./Button";
23
+
24
+ export default {
25
+ primary: () => <Button label="Save" />,
26
+ disabled: () => <Button label="Save" disabled />,
27
+ };
28
+ ```
29
+
30
+ A fixture module can export more:
31
+
32
+ | Export | What it does |
33
+ | --- | --- |
34
+ | `inputs` | Values the fixture receives as props and the bench lets you edit. Each key's value is its default; `{ options: [...] }` is a choice, defaulting to the first option. |
35
+ | `seed` | Runs before the fixture renders, with your harness. What it returns reaches the fixture through `useSeeded()`. |
36
+ | `viewport` | The viewport this fixture opens in on the web: a preset such as `"phone"`, `"responsive"`, or a size such as `"700x520"`. |
37
+ | `layout` | `"full"` gives the fixture the stage edge to edge, for a whole screen. The default, `"padded"`, puts space around it. |
38
+
39
+ ```tsx
40
+ import type { InputsOf } from "@devtime-ltd/ui-bench";
41
+
42
+ export const inputs = {
43
+ label: "Save changes",
44
+ size: { options: ["medium", "small", "large"] as const },
45
+ disabled: false,
46
+ };
47
+
48
+ export default (props: InputsOf<typeof inputs>) => <Button {...props} />;
49
+ ```
50
+
51
+ ## Mounting the bench
52
+
53
+ The app decides when to show the bench in place of itself. `uiBenchRequested()` answers true at `/ui` on the web. It is imported from `/entry`, which holds nothing else, so the check costs a production bundle a few lines.
54
+
55
+ ### React with Vite
56
+
57
+ ```tsx
58
+ // main.tsx
59
+ import { uiBenchRequested } from "@devtime-ltd/ui-bench/entry";
60
+
61
+ if (import.meta.env.DEV && uiBenchRequested()) {
62
+ void import("./Bench").then(({ Bench }) => root.render(<Bench />));
63
+ } else {
64
+ root.render(<App />);
65
+ }
66
+ ```
67
+
68
+ ```tsx
69
+ // Bench.tsx
70
+ import { UiBench } from "@devtime-ltd/ui-bench";
71
+
72
+ const fixtures = import.meta.glob("./components/**/*.fixture.tsx", { eager: true });
73
+
74
+ export function Bench() {
75
+ return <UiBench fixtures={fixtures} />;
76
+ }
77
+ ```
78
+
79
+ ### Expo
80
+
81
+ There is no URL on a device, so a native launch opens the bench when you tell it to, here with an environment variable (`EXPO_PUBLIC_UI_BENCH=1 npx expo start`). Keep the condition as one expression: Metro folds it away, and a production bundle then carries neither the bench nor the fixtures.
82
+
83
+ ```ts
84
+ // index.ts
85
+ import { uiBenchRequested } from "@devtime-ltd/ui-bench/entry";
86
+ import { registerRootComponent } from "expo";
87
+
88
+ import App from "./src/App";
89
+
90
+ registerRootComponent(
91
+ __DEV__ && uiBenchRequested({ native: process.env.EXPO_PUBLIC_UI_BENCH === "1" })
92
+ ? require("./src/Bench").default
93
+ : App
94
+ );
95
+ ```
96
+
97
+ ```tsx
98
+ // src/Bench.tsx
99
+ /// <reference types="expo/types" />
100
+ import { UiBench, fromRequireContext } from "@devtime-ltd/ui-bench";
101
+ import AsyncStorage from "@react-native-async-storage/async-storage";
102
+ import { Platform } from "react-native";
103
+
104
+ const fixtures = fromRequireContext(require.context("./components", true, /\.fixture\.tsx$/));
105
+
106
+ export default function Bench() {
107
+ return <UiBench fixtures={fixtures} storage={Platform.OS === "web" ? undefined : AsyncStorage} />;
108
+ }
109
+ ```
110
+
111
+ The same import gives the web control bar on Expo's web build and the native one on a device. The native bar needs `react-native-safe-area-context`.
112
+
113
+ ### React Native without Expo
114
+
115
+ As Expo, with two differences. Metro's `require.context` is off by default, so turn it on:
116
+
117
+ ```js
118
+ // metro.config.js
119
+ module.exports = mergeConfig(getDefaultConfig(__dirname), {
120
+ transformer: { unstable_allowRequireContext: true },
121
+ });
122
+ ```
123
+
124
+ And decide for yourself when a launch opens the bench, passing it as `uiBenchRequested({ native: ... })`.
125
+
126
+ ## What the bench takes
127
+
128
+ | Prop | |
129
+ | --- | --- |
130
+ | `fixtures` | The fixture modules by path: an eager `import.meta.glob`, or `fromRequireContext(require.context(...))`. |
131
+ | `wrapper` | A component given `{ mode, children }` that wraps every fixture. Put your theme, fonts and providers here; `mode` is `"light"` or `"dark"`, following the bench's theme switch. |
132
+ | `harness` | `{ open, reset }`. What `open()` returns is handed to each fixture's `seed`, and to the fixture through `useHarness()`. It is opened once, and `reset` runs before every seed run. |
133
+ | `storage` | Where the bench keeps its settings: anything with `getItem` and `setItem`. Defaults to `localStorage` on the web and to memory on a device, so pass AsyncStorage there. |
134
+ | `landing` | A component shown in place of the fixture list while nothing is selected. |
135
+ | `viewports` | Replaces the `phone`, `tablet` and `laptop` presets. Web only. |
136
+
137
+ A seeded fixture, with a fake API client as the harness:
138
+
139
+ ```tsx
140
+ // <UiBench harness={{ open: createFakeApi, reset: (api) => api.clear() }} ... />
141
+
142
+ export function seed(api: FakeApi) {
143
+ api.add("Write a fixture");
144
+ return { count: api.list().length };
145
+ }
146
+
147
+ export default function Seeded() {
148
+ const api = useHarness<FakeApi>();
149
+ const { count } = useSeeded<{ count: number }>();
150
+ return <TodoList api={api} />;
151
+ }
152
+ ```
153
+
154
+ ## The URL
155
+
156
+ On the web the bench keeps its state in the URL fragment, as keys:
157
+
158
+ ```
159
+ /ui#fixture=Button/primary&inputs={"label":"Send"}&viewport=phone&theme=dark&chrome=0
160
+ ```
161
+
162
+ | Key | |
163
+ | --- | --- |
164
+ | `fixture` | The selected fixture: its file, then its variant. |
165
+ | `inputs` | The inputs that differ from the fixture's defaults, as JSON. |
166
+ | `viewport` | A viewport preset, `full`, `responsive`, or a size such as `700x520`. |
167
+ | `theme` | `light` or `dark`. A link that names one overrides the remembered theme. |
168
+ | `chrome` | `0` renders the fixture alone: no control bar, nothing else on the page. |
169
+
170
+ Any other pair in the fragment is left as it is. The query string is never touched.
171
+
172
+ `chrome=0` is the link to give a screenshot test, and it is what a viewport preset loads in its frame.
173
+
174
+ ## A bench you can deploy
175
+
176
+ The bench is part of your app's build, so deploying one is a build with the bench left in. Put a build-time flag beside the development check:
177
+
178
+ ```ts
179
+ const benchBuilt = import.meta.env.DEV || import.meta.env.VITE_UI_BENCH === "1";
180
+ ```
181
+
182
+ ```sh
183
+ VITE_UI_BENCH=1 vite build --outDir dist-bench
184
+ EXPO_PUBLIC_UI_BENCH=1 npx expo export -p web --output-dir dist-bench
185
+ ```
186
+
187
+ Serve the result with a fallback to `index.html`, so that `/ui` reaches the app. Both examples in this repository do this.
188
+
189
+ ## Testing every fixture
190
+
191
+ `fixtureCases` gives one case per fixture. Mounting one seeds it, then returns it ready to render with its default inputs. A fixture that throws fails its test.
192
+
193
+ ```tsx
194
+ // Vitest
195
+ import { fixtureCases } from "@devtime-ltd/ui-bench/testing";
196
+ import { render } from "@testing-library/react";
197
+
198
+ const fixtures = import.meta.glob("../src/**/*.fixture.tsx", { eager: true });
199
+
200
+ it.each(fixtureCases({ fixtures }))("$id renders", async ({ mount }) => {
201
+ render(await mount());
202
+ });
203
+ ```
204
+
205
+ Jest has no glob of its own, so find the files and load them yourself:
206
+
207
+ ```tsx
208
+ import { fixtureCases, fixturesFromFiles } from "@devtime-ltd/ui-bench/testing";
209
+ import { render } from "@testing-library/react-native";
210
+ import { readdirSync } from "node:fs";
211
+ import { join } from "node:path";
212
+
213
+ const root = join(__dirname, "../src");
214
+ const files = (readdirSync(root, { recursive: true }) as string[]).filter((file) => file.endsWith(".fixture.tsx"));
215
+ const fixtures = fixturesFromFiles(files, (file) => require(join(root, file)));
216
+
217
+ it.each(fixtureCases({ fixtures }))("$id renders", async ({ mount }) => {
218
+ await render(await mount());
219
+ });
220
+ ```
221
+
222
+ `fixtureCases` takes the same `harness` and `wrapper` as the bench.
223
+
224
+ ## This repository
225
+
226
+ ```
227
+ packages/ui-bench the package
228
+ examples/vite a plain React app with a bench
229
+ examples/expo an Expo app with a bench, on the web and on a device
230
+ ```
231
+
232
+ ```sh
233
+ npm install
234
+ npm run build
235
+ ```
236
+
237
+ The examples use the built package, so build before running them.
238
+
239
+ | Command | |
240
+ | --- | --- |
241
+ | `npm run dev:vite` | The plain React example. Open `/ui` on the address it prints. |
242
+ | `npm run dev:expo` | The Expo example. Press `w`, then open `/ui`; set `EXPO_PUBLIC_UI_BENCH=1` to open the bench on a device. |
243
+ | `npm test` | Unit tests, and the Expo example's Jest tests. |
244
+ | `npm run test:e2e` | Browser tests against both examples' deployable builds. |
245
+
246
+ ## Licence
247
+
248
+ MIT
@@ -0,0 +1,67 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var UiBench_exports = {};
20
+ __export(UiBench_exports, {
21
+ UiBench: () => UiBench
22
+ });
23
+ module.exports = __toCommonJS(UiBench_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react = require("react");
26
+ var import_controller = require("./core/controller");
27
+ var import_stage = require("./core/stage");
28
+ var import_ControlBar = require("./dom/ControlBar");
29
+ var import_Frame = require("./dom/Frame");
30
+ var import_hashUrl = require("./dom/hashUrl");
31
+ var import_InputsPanel = require("./dom/InputsPanel");
32
+ var import_Landing = require("./dom/Landing");
33
+ var import_styles = require("./dom/styles");
34
+ const RESEED_EVENT = "ui-bench:reseed";
35
+ function UiBench({ fixtures, wrapper, harness, landing: CustomLanding, storage = localStorage, viewports }) {
36
+ const bench = (0, import_controller.useBenchController)({ fixtures, harness, storage, viewports, url: import_hashUrl.hashUrl });
37
+ const frame = (0, import_react.useRef)(null);
38
+ const reseed = bench?.reseed;
39
+ (0, import_react.useEffect)(() => {
40
+ if (!reseed)
41
+ return;
42
+ window.addEventListener(RESEED_EVENT, reseed);
43
+ return () => window.removeEventListener(RESEED_EVENT, reseed);
44
+ }, [reseed]);
45
+ if (!bench)
46
+ return null;
47
+ const stage = bench.stage.kind === "empty" ? CustomLanding && !bench.selectedId ? (0, import_jsx_runtime.jsx)(CustomLanding, {}) : (0, import_jsx_runtime.jsx)(import_Landing.Landing, { fixtures: bench.fixtures, missing: bench.selectedId, onSelect: bench.select }) : (0, import_jsx_runtime.jsx)("div", { className: `uib-stage-${bench.stage.fixture.layout}`, "data-testid": "stage", children: (0, import_jsx_runtime.jsx)(import_stage.StageBody, { stage: bench.stage, inputs: bench.inputs, mode: bench.mode, wrapper, renderLoading: () => (0, import_jsx_runtime.jsx)("span", { className: "uib-dim", "data-testid": "stage-loading", children: "Seeding\u2026" }), renderError: (message) => (0, import_jsx_runtime.jsx)("pre", { className: "uib-error", role: "alert", "data-testid": "stage-error", children: message }) }) });
48
+ if (!bench.chrome) {
49
+ return (0, import_jsx_runtime.jsxs)("div", { className: "uib-bare", "data-mode": bench.mode, children: [(0, import_jsx_runtime.jsx)("style", { children: import_styles.CSS }), stage] });
50
+ }
51
+ const { prefs } = bench;
52
+ const framed = (bench.viewportSize || bench.responsive) && bench.stage.kind !== "empty";
53
+ const bar = prefs.minimised ? null : (0, import_jsx_runtime.jsx)(import_ControlBar.ControlBar, { bench: framed ? { ...bench, reseed: () => reseedFrame(frame.current, bench) } : bench });
54
+ const panel = prefs.inputsOpen && !prefs.minimised && bench.selected ? (0, import_jsx_runtime.jsx)(import_InputsPanel.InputsPanel, { values: bench.inputs, changed: bench.inputsChanged, onChange: bench.setInputs, onReset: bench.resetInputs }) : null;
55
+ return (0, import_jsx_runtime.jsxs)("div", { className: "uib-root", "data-mode": bench.mode, "data-edge": prefs.edge, children: [(0, import_jsx_runtime.jsx)("style", { children: import_styles.CSS }), prefs.edge === "top" ? bar : null, prefs.edge === "top" ? panel : null, (0, import_jsx_runtime.jsx)("div", { className: "uib-area", "data-framed": framed ? true : void 0, children: framed ? (0, import_jsx_runtime.jsx)(import_Frame.Frame, { name: bench.viewport, size: bench.viewportSize, fragment: bench.bareFragment, frame, onResize: bench.responsive ? bench.resizeViewport : void 0 }) : stage }), prefs.edge === "bottom" ? panel : null, prefs.edge === "bottom" ? bar : null, prefs.minimised ? (0, import_jsx_runtime.jsx)("div", { className: "uib-restore", children: (0, import_jsx_runtime.jsx)("button", { type: "button", className: "uib-box uib-box-accent", "aria-label": "Restore control bar", "data-testid": "bar-restore", onClick: () => bench.updatePrefs({ minimised: false }), children: "+" }) }) : null] });
56
+ }
57
+ function reseedFrame(frame, bench) {
58
+ const inner = frame?.contentWindow;
59
+ if (inner)
60
+ inner.dispatchEvent(new inner.Event(RESEED_EVENT));
61
+ else
62
+ bench.reseed();
63
+ }
64
+ // Annotate the CommonJS export names for ESM import in node:
65
+ 0 && (module.exports = {
66
+ UiBench
67
+ });
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var UiBench_native_exports = {};
20
+ __export(UiBench_native_exports, {
21
+ UiBench: () => UiBench
22
+ });
23
+ module.exports = __toCommonJS(UiBench_native_exports);
24
+ var import_jsx_runtime = require("react/jsx-runtime");
25
+ var import_react_native = require("react-native");
26
+ var import_react_native_safe_area_context = require("react-native-safe-area-context");
27
+ var import_controller = require("./core/controller");
28
+ var import_prefs = require("./core/prefs");
29
+ var import_stage = require("./core/stage");
30
+ var import_Box = require("./native/Box");
31
+ var import_ControlBar = require("./native/ControlBar");
32
+ var import_InputsPanel = require("./native/InputsPanel");
33
+ var import_Landing = require("./native/Landing");
34
+ var import_theme = require("./native/theme");
35
+ const fallbackStorage = (0, import_prefs.memoryStorage)();
36
+ function UiBench(props) {
37
+ return (0, import_jsx_runtime.jsx)(import_react_native_safe_area_context.SafeAreaProvider, { children: (0, import_jsx_runtime.jsx)(Bench, { ...props }) });
38
+ }
39
+ function Bench({ fixtures, wrapper, harness, landing: CustomLanding, storage = fallbackStorage }) {
40
+ const bench = (0, import_controller.useBenchController)({ fixtures, harness, storage });
41
+ const insets = (0, import_react_native_safe_area_context.useSafeAreaInsets)();
42
+ if (!bench)
43
+ return null;
44
+ const { prefs } = bench;
45
+ const palette = import_theme.stage[bench.mode];
46
+ const barAtTop = !prefs.minimised && prefs.edge === "top";
47
+ const barAtBottom = !prefs.minimised && prefs.edge === "bottom";
48
+ const bar = prefs.minimised ? null : (0, import_jsx_runtime.jsx)(import_ControlBar.ControlBar, { bench, inset: prefs.edge === "top" ? insets.top : insets.bottom });
49
+ const panel = prefs.inputsOpen && !prefs.minimised && bench.selected ? (0, import_jsx_runtime.jsx)(import_InputsPanel.InputsPanel, { values: bench.inputs, changed: bench.inputsChanged, onChange: bench.setInputs, onReset: bench.resetInputs }) : null;
50
+ const padded = bench.stage.kind === "empty" || bench.stage.fixture.layout === "padded";
51
+ const gutter = padded ? 24 : 0;
52
+ return (0, import_jsx_runtime.jsxs)(import_react_native.KeyboardAvoidingView, { style: [styles.root, { backgroundColor: palette.background }], behavior: import_react_native.Platform.OS === "ios" ? "padding" : void 0, children: [prefs.edge === "top" ? bar : null, prefs.edge === "top" ? panel : null, (0, import_jsx_runtime.jsx)(import_react_native.ScrollView, { keyboardShouldPersistTaps: "handled", contentContainerStyle: {
53
+ flexGrow: 1,
54
+ paddingTop: gutter + (barAtTop ? 0 : insets.top),
55
+ paddingBottom: gutter + (barAtBottom ? 0 : insets.bottom),
56
+ paddingLeft: gutter + insets.left,
57
+ paddingRight: gutter + insets.right
58
+ }, testID: "stage", children: bench.stage.kind === "empty" ? CustomLanding && !bench.selectedId ? (0, import_jsx_runtime.jsx)(CustomLanding, {}) : (0, import_jsx_runtime.jsx)(import_Landing.Landing, { fixtures: bench.fixtures, missing: bench.selectedId, palette, onSelect: bench.select }) : (0, import_jsx_runtime.jsx)(import_stage.StageBody, { stage: bench.stage, inputs: bench.inputs, mode: bench.mode, wrapper, renderLoading: () => (0, import_jsx_runtime.jsx)(import_react_native.ActivityIndicator, { color: palette.dim, testID: "stage-loading" }), renderError: (message) => (0, import_jsx_runtime.jsx)(import_react_native.Text, { style: [import_theme.mono, { color: palette.danger }], testID: "stage-error", children: message }) }) }), prefs.edge === "bottom" ? panel : null, prefs.edge === "bottom" ? bar : null, prefs.minimised ? (0, import_jsx_runtime.jsx)(import_react_native.View, { style: [
59
+ styles.restore,
60
+ { right: insets.right },
61
+ prefs.edge === "top" ? { top: 24 + insets.top } : { bottom: 24 + insets.bottom }
62
+ ], children: (0, import_jsx_runtime.jsx)(import_Box.Box, { accent: true, label: "Restore control bar", onPress: () => bench.updatePrefs({ minimised: false }), testID: "bar-restore", children: "+" }) }) : null, (0, import_jsx_runtime.jsx)(import_react_native.StatusBar, { barStyle: barAtTop || bench.mode === "dark" ? "light-content" : "dark-content" })] });
63
+ }
64
+ const styles = import_react_native.StyleSheet.create({
65
+ root: { flex: 1 },
66
+ restore: {
67
+ position: "absolute",
68
+ flexDirection: "row",
69
+ alignItems: "center",
70
+ padding: 4,
71
+ backgroundColor: import_theme.bar.background
72
+ }
73
+ });
74
+ // Annotate the CommonJS export names for ESM import in node:
75
+ 0 && (module.exports = {
76
+ UiBench
77
+ });
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var controller_exports = {};
20
+ __export(controller_exports, {
21
+ useBenchController: () => useBenchController
22
+ });
23
+ module.exports = __toCommonJS(controller_exports);
24
+ var import_react = require("react");
25
+ var import_fixtures = require("./fixtures");
26
+ var import_fragment = require("./fragment");
27
+ var import_inputs = require("./inputs");
28
+ var import_prefs = require("./prefs");
29
+ var import_stage = require("./stage");
30
+ var import_viewports = require("./viewports");
31
+ function useBenchController(options) {
32
+ const { storage, url } = options;
33
+ const fixtures = (0, import_react.useMemo)(() => (0, import_fixtures.loadFixtures)(options.fixtures), [options.fixtures]);
34
+ const viewports = options.viewports ?? import_viewports.DEFAULT_VIEWPORTS;
35
+ const [prefs, setPrefs] = (0, import_react.useState)(() => {
36
+ const read = (0, import_prefs.readPrefs)(storage);
37
+ return "then" in read ? null : read;
38
+ });
39
+ (0, import_react.useEffect)(() => {
40
+ if (prefs)
41
+ return;
42
+ let alive = true;
43
+ void Promise.resolve((0, import_prefs.readPrefs)(storage)).then((read) => {
44
+ if (alive)
45
+ setPrefs(read);
46
+ });
47
+ return () => {
48
+ alive = false;
49
+ };
50
+ }, [prefs, storage]);
51
+ const updatePrefs = (0, import_react.useCallback)((patch) => setPrefs((current) => {
52
+ if (!current)
53
+ return current;
54
+ const next = { ...current, ...patch };
55
+ (0, import_prefs.writePrefs)(storage, next);
56
+ return next;
57
+ }), [storage]);
58
+ const [urlState, setUrlState] = (0, import_react.useState)(() => url ? (0, import_fragment.parseFragment)(url.read()) : import_fragment.EMPTY_URL_STATE);
59
+ const urlRef = (0, import_react.useRef)(urlState);
60
+ const commit = (0, import_react.useCallback)((patch) => {
61
+ const next = { ...urlRef.current, ...patch };
62
+ urlRef.current = next;
63
+ setUrlState(next);
64
+ url?.write((0, import_fragment.formatFragment)(next));
65
+ }, [url]);
66
+ (0, import_react.useEffect)(() => url?.subscribe(() => {
67
+ const next = (0, import_fragment.parseFragment)(url.read());
68
+ urlRef.current = next;
69
+ setUrlState(next);
70
+ }), [url]);
71
+ const selectedId = url ? urlState.fixture : prefs?.selected ?? null;
72
+ const selected = (0, import_react.useMemo)(() => fixtures.find((fixture) => fixture.id === selectedId) ?? null, [fixtures, selectedId]);
73
+ const select = (0, import_react.useCallback)((id) => {
74
+ if (url) {
75
+ commit({ fixture: id, inputs: null });
76
+ } else {
77
+ commit({ inputs: null });
78
+ updatePrefs({ selected: id });
79
+ }
80
+ }, [url, commit, updatePrefs]);
81
+ const [run, setRun] = (0, import_react.useState)(0);
82
+ const reseed = (0, import_react.useCallback)(() => setRun((count) => count + 1), []);
83
+ const stage = (0, import_stage.useStage)(selected, run, options.harness);
84
+ const mode = urlState.theme ?? prefs?.mode ?? "light";
85
+ const toggleTheme = (0, import_react.useCallback)(() => {
86
+ const next = mode === "light" ? "dark" : "light";
87
+ if (urlRef.current.theme)
88
+ commit({ theme: next });
89
+ else
90
+ updatePrefs({ mode: next });
91
+ }, [mode, commit, updatePrefs]);
92
+ const defaults = (0, import_react.useMemo)(() => (0, import_inputs.defaultInputs)(selected?.inputs ?? {}), [selected]);
93
+ const inputs = (0, import_react.useMemo)(() => (0, import_inputs.mergeInputs)(defaults, urlState.inputs), [defaults, urlState.inputs]);
94
+ const setInputs = (0, import_react.useCallback)((values) => commit({ inputs: (0, import_inputs.changedInputs)(defaults, values) }), [commit, defaults]);
95
+ const resetInputs = (0, import_react.useCallback)(() => commit({ inputs: null }), [commit]);
96
+ const fixtureViewport = selected?.viewport ?? import_viewports.FULL_VIEWPORT;
97
+ const wanted = urlState.viewport ?? fixtureViewport;
98
+ const custom = (0, import_viewports.parseViewportSize)(wanted);
99
+ const responsive = custom !== null || wanted === import_viewports.RESPONSIVE_VIEWPORT;
100
+ const viewport = responsive ? import_viewports.RESPONSIVE_VIEWPORT : wanted in viewports ? wanted : import_viewports.FULL_VIEWPORT;
101
+ const viewportSize = custom ?? viewports[viewport] ?? null;
102
+ const sizeNow = viewportSize ? (0, import_viewports.formatViewportSize)(viewportSize) : null;
103
+ const setViewport = (0, import_react.useCallback)((name) => {
104
+ const next = name === import_viewports.RESPONSIVE_VIEWPORT && sizeNow ? sizeNow : name;
105
+ commit({ viewport: next === fixtureViewport ? null : next });
106
+ }, [commit, fixtureViewport, sizeNow]);
107
+ const resizeViewport = (0, import_react.useCallback)((size) => commit({ viewport: (0, import_viewports.formatViewportSize)(size) }), [commit]);
108
+ const bareFragment = (0, import_react.useMemo)(() => (0, import_fragment.formatFragment)({
109
+ fixture: selectedId,
110
+ inputs: urlState.inputs,
111
+ viewport: null,
112
+ theme: mode,
113
+ chrome: false,
114
+ rest: []
115
+ }), [selectedId, urlState.inputs, mode]);
116
+ if (!prefs)
117
+ return null;
118
+ return {
119
+ fixtures,
120
+ selected,
121
+ selectedId,
122
+ select,
123
+ stage,
124
+ canReseed: !!selected?.seed,
125
+ reseed,
126
+ mode,
127
+ toggleTheme,
128
+ inputs,
129
+ inputsChanged: urlState.inputs !== null,
130
+ setInputs,
131
+ resetInputs,
132
+ viewports,
133
+ viewport,
134
+ viewportSize,
135
+ responsive,
136
+ setViewport,
137
+ resizeViewport,
138
+ chrome: urlState.chrome,
139
+ bareFragment,
140
+ prefs,
141
+ updatePrefs
142
+ };
143
+ }
144
+ // Annotate the CommonJS export names for ESM import in node:
145
+ 0 && (module.exports = {
146
+ useBenchController
147
+ });
@@ -0,0 +1,35 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var entry_exports = {};
20
+ __export(entry_exports, {
21
+ uiBenchRequested: () => uiBenchRequested
22
+ });
23
+ module.exports = __toCommonJS(entry_exports);
24
+ function uiBenchRequested({ path = "/ui", native = false } = {}) {
25
+ if (typeof document === "undefined" || typeof location === "undefined")
26
+ return native;
27
+ return trimSlashes(location.pathname) === trimSlashes(path);
28
+ }
29
+ function trimSlashes(path) {
30
+ return path.replace(/\/+$/, "");
31
+ }
32
+ // Annotate the CommonJS export names for ESM import in node:
33
+ 0 && (module.exports = {
34
+ uiBenchRequested
35
+ });