strata-react 1.3.15 → 1.3.17
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 +47 -8
- package/UPGRADING.md +15 -0
- package/dist/components/data-table.d.ts +6 -0
- package/dist/components/field.d.ts +2 -0
- package/dist/components/hotkeys.d.ts +1 -1
- package/dist/components/link-card.d.ts +4 -2
- package/dist/components/pause-button.d.ts +7 -0
- package/dist/components/schedule-table.d.ts +24 -0
- package/dist/components/system-panel.d.ts +58 -0
- package/dist/components/theme.d.ts +46 -1
- package/dist/components/thumbnail.d.ts +2 -0
- package/dist/{errors-D99YX4XL.js → errors-jep2voNI.js} +42 -3
- package/dist/errors-jep2voNI.js.map +1 -0
- package/dist/field-t4Hoer0d.js +587 -0
- package/dist/field-t4Hoer0d.js.map +1 -0
- package/dist/index.d.ts +6 -3
- package/dist/index.js +669 -463
- package/dist/index.js.map +1 -1
- package/dist/lib/breakpoint.d.ts +4 -0
- package/dist/lib/format.d.ts +59 -6
- package/dist/map.js +2 -3
- package/dist/map.js.map +1 -1
- package/dist/microphone-Cu1u5Yml.js +547 -0
- package/dist/microphone-Cu1u5Yml.js.map +1 -0
- package/dist/panorama.js +3 -2
- package/dist/panorama.js.map +1 -1
- package/dist/query/index.d.ts +5 -1
- package/dist/query/poll.d.ts +24 -0
- package/dist/reading.css +11 -0
- package/dist/{run-hR9neQHM.js → run-BT2WKzMz.js} +83 -17
- package/dist/run-BT2WKzMz.js.map +1 -0
- package/dist/strata.bare.css +279 -0
- package/dist/strata.css +840 -10
- package/dist/strata.migrate.css +15 -6
- package/dist/testing/index.d.ts +4 -2
- package/dist/testing.js +34 -6
- package/dist/testing.js.map +1 -1
- package/dist/{theme-By3DSUTs.js → theme-DXacprlw.js} +147 -6
- package/dist/theme-DXacprlw.js.map +1 -0
- package/dist/{value-controls-B7iNh4WO.js → value-controls-DB5l5Qe2.js} +21 -46
- package/dist/value-controls-DB5l5Qe2.js.map +1 -0
- package/dist/visual/capture.d.ts +2 -0
- package/dist/visual/fonts.d.ts +18 -0
- package/dist/visual/index.d.ts +1 -0
- package/dist/visual/types.d.ts +7 -1
- package/dist/visual-cli.js +1 -1
- package/dist/visual.js +1 -1
- package/package.json +12 -3
- package/dist/errors-D99YX4XL.js.map +0 -1
- package/dist/field-QCCmWTuY.js +0 -321
- package/dist/field-QCCmWTuY.js.map +0 -1
- package/dist/format-B32-PVi2.js +0 -201
- package/dist/format-B32-PVi2.js.map +0 -1
- package/dist/microphone-BZXMKTCM.js +0 -292
- package/dist/microphone-BZXMKTCM.js.map +0 -1
- package/dist/run-hR9neQHM.js.map +0 -1
- package/dist/theme-By3DSUTs.js.map +0 -1
- package/dist/value-controls-B7iNh4WO.js.map +0 -1
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import { g as cn, m as format } from "./field-t4Hoer0d.js";
|
|
2
|
+
import { d as isDev, f as useInView, o as readErrorBody, r as describeHttpError, s as Button$1, t as HttpError } from "./errors-jep2voNI.js";
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { Button, Text, UNSTABLE_Toast, UNSTABLE_ToastContent, UNSTABLE_ToastQueue, UNSTABLE_ToastRegion } from "react-aria-components";
|
|
5
|
+
import { CircleAlert, CircleCheck, History, ImageOff, Info, RotateCcw, TriangleAlert, X } from "lucide-react";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
import { QueryClient, QueryClientProvider, useQuery } from "@tanstack/react-query";
|
|
8
|
+
// src/lib/overlay.ts
|
|
9
|
+
var overlaySurface = "rounded-overlay border border-border bg-popover text-popover-foreground shadow-overlay enter-overlay";
|
|
10
|
+
// src/query/poll.ts
|
|
11
|
+
/** The pause state and last-read time of a polled screen: pass it to `useLoad({ poll })` and to `PauseButton`. */
|
|
12
|
+
function usePoll({ every, paused: initiallyPaused = false }) {
|
|
13
|
+
const [paused, setPaused] = React.useState(initiallyPaused);
|
|
14
|
+
const [at, setAt] = React.useState(0);
|
|
15
|
+
const toggle = React.useCallback(() => setPaused((p) => !p), []);
|
|
16
|
+
const note = React.useCallback((dataUpdatedAt) => setAt((previous) => Math.max(previous, dataUpdatedAt)), []);
|
|
17
|
+
return React.useMemo(() => {
|
|
18
|
+
const poll = {
|
|
19
|
+
every,
|
|
20
|
+
paused,
|
|
21
|
+
toggle,
|
|
22
|
+
updatedAt: at ? new Date(at) : null,
|
|
23
|
+
note,
|
|
24
|
+
with: (override) => ({
|
|
25
|
+
...poll,
|
|
26
|
+
every: override.every,
|
|
27
|
+
with: (again) => poll.with(again)
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
return poll;
|
|
31
|
+
}, [
|
|
32
|
+
every,
|
|
33
|
+
paused,
|
|
34
|
+
toggle,
|
|
35
|
+
at,
|
|
36
|
+
note
|
|
37
|
+
]);
|
|
38
|
+
}
|
|
39
|
+
/** Wires a query to its `Poll`: the time of each read, and one read when the poll is resumed. */
|
|
40
|
+
function usePollBinding(poll, query) {
|
|
41
|
+
const note = poll?.note;
|
|
42
|
+
React.useEffect(() => {
|
|
43
|
+
if (note && query.dataUpdatedAt) note(query.dataUpdatedAt);
|
|
44
|
+
}, [note, query.dataUpdatedAt]);
|
|
45
|
+
const paused = poll?.paused;
|
|
46
|
+
const wasPaused = React.useRef(paused);
|
|
47
|
+
React.useEffect(() => {
|
|
48
|
+
if (wasPaused.current && paused === false) query.refetch();
|
|
49
|
+
wasPaused.current = paused;
|
|
50
|
+
}, [paused]);
|
|
51
|
+
}
|
|
52
|
+
// src/query/index.tsx
|
|
53
|
+
/** A QueryClient with Strata's defaults: one retry, 30 s stale time, no refetch on window focus. */
|
|
54
|
+
function createQueryClient(overrides) {
|
|
55
|
+
return new QueryClient({
|
|
56
|
+
...overrides,
|
|
57
|
+
defaultOptions: {
|
|
58
|
+
...overrides?.defaultOptions,
|
|
59
|
+
queries: {
|
|
60
|
+
retry: 1,
|
|
61
|
+
staleTime: 3e4,
|
|
62
|
+
refetchOnWindowFocus: false,
|
|
63
|
+
...overrides?.defaultOptions?.queries
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
/** Provides a query client (Strata's defaults unless one is passed) to the app. */
|
|
69
|
+
function StrataQueryProvider({ client, children }) {
|
|
70
|
+
const [fallback] = React.useState(() => client ?? createQueryClient());
|
|
71
|
+
return /* @__PURE__ */ jsx(QueryClientProvider, {
|
|
72
|
+
client: client ?? fallback,
|
|
73
|
+
children
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Turns a TanStack query result into the `Load<T>` that `DataView` takes; errors are described for a person by `describe`.
|
|
78
|
+
* A refetch that fails after data arrived stays `ready`, with `stale` saying why and when the data was read.
|
|
79
|
+
*/
|
|
80
|
+
function toLoad(query, describe = describeHttpError) {
|
|
81
|
+
if (query.status === "success") return {
|
|
82
|
+
status: "ready",
|
|
83
|
+
data: query.data
|
|
84
|
+
};
|
|
85
|
+
if (query.status === "error" && query.data !== void 0) return {
|
|
86
|
+
status: "ready",
|
|
87
|
+
data: query.data,
|
|
88
|
+
stale: staleOf(query, describe)
|
|
89
|
+
};
|
|
90
|
+
if (query.status === "error") return {
|
|
91
|
+
status: "error",
|
|
92
|
+
message: describe(query.error),
|
|
93
|
+
retry: () => void query.refetch()
|
|
94
|
+
};
|
|
95
|
+
return { status: "loading" };
|
|
96
|
+
}
|
|
97
|
+
/** The `Stale` of a query whose refetch failed after a good read. Shared by `toLoad` and `useInfiniteLoad`. */
|
|
98
|
+
function staleOf(query, describe = describeHttpError) {
|
|
99
|
+
return {
|
|
100
|
+
message: describe(query.error),
|
|
101
|
+
readAt: new Date(query.dataUpdatedAt),
|
|
102
|
+
retry: () => void query.refetch(),
|
|
103
|
+
retrying: query.isFetching
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
/** `useQuery`, returned as a `Load<T>` for `DataView`. With `poll` (from `usePoll`) it reads again every `poll.every` ms until the person pauses it. */
|
|
107
|
+
function useLoad(options) {
|
|
108
|
+
const { describeError, poll, ...rest } = options;
|
|
109
|
+
const query = useQuery(poll ? {
|
|
110
|
+
...rest,
|
|
111
|
+
refetchInterval: poll.paused ? false : poll.every
|
|
112
|
+
} : rest);
|
|
113
|
+
usePollBinding(poll, query);
|
|
114
|
+
return toLoad(query, describeError);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* fetch() that throws an HttpError on a non-2xx response and parses JSON: the queryFn default, and the usual commit for a write.
|
|
118
|
+
* `init.json` sends a JSON body without building the headers. A 204 or empty body resolves to undefined. An error response's body is read onto the HttpError (`body`, `reason`, `fieldErrors`).
|
|
119
|
+
*/
|
|
120
|
+
async function fetchJson(input, init, { readError = readErrorBody } = {}) {
|
|
121
|
+
const { json, ...rest } = init ?? {};
|
|
122
|
+
const headers = new Headers(rest.headers);
|
|
123
|
+
if (!headers.has("Accept")) headers.set("Accept", "application/json");
|
|
124
|
+
if (json !== void 0) {
|
|
125
|
+
if (!headers.has("Content-Type")) headers.set("Content-Type", "application/json");
|
|
126
|
+
rest.body = JSON.stringify(json);
|
|
127
|
+
rest.method ??= "POST";
|
|
128
|
+
}
|
|
129
|
+
const res = await fetch(input, {
|
|
130
|
+
...rest,
|
|
131
|
+
headers
|
|
132
|
+
});
|
|
133
|
+
if (!res.ok) {
|
|
134
|
+
const raw = await res.text().catch(() => "");
|
|
135
|
+
let body = raw || void 0;
|
|
136
|
+
try {
|
|
137
|
+
if (raw) body = JSON.parse(raw);
|
|
138
|
+
} catch {}
|
|
139
|
+
throw new HttpError(res.status, res.statusText, String(input), body, readError(body));
|
|
140
|
+
}
|
|
141
|
+
const text = res.status === 204 ? "" : await res.text();
|
|
142
|
+
return text ? JSON.parse(text) : void 0;
|
|
143
|
+
}
|
|
144
|
+
// src/components/data-view.tsx
|
|
145
|
+
/** The default failed-read panel: the reason on the danger tint, with Try again. Its parent carries `role="alert"`. */
|
|
146
|
+
function LoadError({ message, retry, className }) {
|
|
147
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
148
|
+
className: cn("flex flex-wrap items-start gap-3 rounded-surface bg-danger-subtle p-4 text-danger", className),
|
|
149
|
+
children: [
|
|
150
|
+
/* @__PURE__ */ jsx(CircleAlert, {
|
|
151
|
+
"aria-hidden": true,
|
|
152
|
+
className: "mt-0.5 size-5 shrink-0"
|
|
153
|
+
}),
|
|
154
|
+
/* @__PURE__ */ jsx("p", {
|
|
155
|
+
className: "min-w-0 flex-1 type-body",
|
|
156
|
+
children: message
|
|
157
|
+
}),
|
|
158
|
+
/* @__PURE__ */ jsxs(Button$1, {
|
|
159
|
+
size: "sm",
|
|
160
|
+
onClick: retry,
|
|
161
|
+
children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), "Try again"]
|
|
162
|
+
})
|
|
163
|
+
]
|
|
164
|
+
});
|
|
165
|
+
}
|
|
166
|
+
var defaultError = (failure) => /* @__PURE__ */ jsx(LoadError, { ...failure });
|
|
167
|
+
/** Every view of remote data: renders `skeleton` while loading, an alert with Try again on error, `empty` when `isEmpty`, else `children(data)`, under a `StaleNotice` when a refresh failed. The skeleton and empty state are required. */
|
|
168
|
+
function DataView({ state, isEmpty, skeleton, empty, children, staleNotice = (stale) => /* @__PURE__ */ jsx(StaleNotice, { stale }), error = defaultError, className }) {
|
|
169
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
170
|
+
className: cn("min-w-0", className),
|
|
171
|
+
"aria-busy": state.status === "loading" || void 0,
|
|
172
|
+
children: [
|
|
173
|
+
state.status === "loading" && skeleton,
|
|
174
|
+
state.status === "error" && /* @__PURE__ */ jsx("div", {
|
|
175
|
+
role: "alert",
|
|
176
|
+
children: error({
|
|
177
|
+
message: state.message,
|
|
178
|
+
retry: state.retry
|
|
179
|
+
})
|
|
180
|
+
}),
|
|
181
|
+
state.status === "ready" && /* @__PURE__ */ jsxs(Fragment, { children: [state.stale && staleNotice(state.stale), isEmpty(state.data) ? empty : children(state.data)] })
|
|
182
|
+
]
|
|
183
|
+
});
|
|
184
|
+
}
|
|
185
|
+
/** When `readAt` was, for a person: the clock time today, else the weekday and time. */
|
|
186
|
+
function readTime(readAt, now = /* @__PURE__ */ new Date()) {
|
|
187
|
+
return readAt.toDateString() === now.toDateString() ? format.clock.format(readAt) : format.shortDay.format(readAt);
|
|
188
|
+
}
|
|
189
|
+
/** The notice over data whose refresh failed: what happened, how old the data shown is, and Try again. A polite status, not an alert: nothing was lost. */
|
|
190
|
+
function StaleNotice({ stale, shown, className }) {
|
|
191
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
192
|
+
role: "status",
|
|
193
|
+
className: cn("mb-4 flex flex-wrap items-start gap-3 rounded-surface bg-warning-subtle p-3 text-warning", className),
|
|
194
|
+
children: [
|
|
195
|
+
/* @__PURE__ */ jsx(History, {
|
|
196
|
+
"aria-hidden": true,
|
|
197
|
+
className: "mt-0.5 size-4 shrink-0"
|
|
198
|
+
}),
|
|
199
|
+
/* @__PURE__ */ jsxs("p", {
|
|
200
|
+
className: "min-w-0 flex-1 type-body-sm",
|
|
201
|
+
children: [
|
|
202
|
+
stale.message,
|
|
203
|
+
" ",
|
|
204
|
+
shown ? shown(readTime(stale.readAt)) : `Showing data from ${readTime(stale.readAt)}.`
|
|
205
|
+
]
|
|
206
|
+
}),
|
|
207
|
+
/* @__PURE__ */ jsxs(Button$1, {
|
|
208
|
+
size: "sm",
|
|
209
|
+
onClick: stale.retry,
|
|
210
|
+
disabled: stale.retrying,
|
|
211
|
+
children: [/* @__PURE__ */ jsx(RotateCcw, { "aria-hidden": true }), stale.retrying ? "Trying again…" : "Try again"]
|
|
212
|
+
})
|
|
213
|
+
]
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
/** An empty state that teaches the next action: a title, a sentence and an action. No illustration slot, on purpose. */
|
|
217
|
+
function EmptyState({ title, children, action }) {
|
|
218
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
219
|
+
className: "grid justify-items-start gap-2 border-y border-border py-6",
|
|
220
|
+
children: [
|
|
221
|
+
/* @__PURE__ */ jsx("p", {
|
|
222
|
+
className: "type-heading",
|
|
223
|
+
children: title
|
|
224
|
+
}),
|
|
225
|
+
children && /* @__PURE__ */ jsx("p", {
|
|
226
|
+
className: "max-w-prose type-body text-muted-foreground",
|
|
227
|
+
children
|
|
228
|
+
}),
|
|
229
|
+
action && /* @__PURE__ */ jsx("div", {
|
|
230
|
+
className: "mt-2",
|
|
231
|
+
children: action
|
|
232
|
+
})
|
|
233
|
+
]
|
|
234
|
+
});
|
|
235
|
+
}
|
|
236
|
+
/** A placeholder block for a loading layout. Size it with layout classes so it mirrors the final content. */
|
|
237
|
+
function Skeleton({ className }) {
|
|
238
|
+
return /* @__PURE__ */ jsx("div", {
|
|
239
|
+
"aria-hidden": true,
|
|
240
|
+
className: cn("rounded-control bg-muted motion-safe:animate-pulse", className)
|
|
241
|
+
});
|
|
242
|
+
}
|
|
243
|
+
// src/components/toast.tsx
|
|
244
|
+
var queue = new UNSTABLE_ToastQueue({ maxVisibleToasts: 3 });
|
|
245
|
+
/** Milliseconds a toast stays: 5 s plus 40 ms a character, to at most 15 s, and at least 8 s with an action. */
|
|
246
|
+
function toastTimeout(content) {
|
|
247
|
+
if (content.timeout !== void 0) return content.timeout;
|
|
248
|
+
const chars = content.title.length + (content.description?.length ?? 0) + (content.action?.label.length ?? 0);
|
|
249
|
+
return Math.max(content.action ? 8e3 : 0, Math.min(15e3, 5e3 + 40 * chars));
|
|
250
|
+
}
|
|
251
|
+
/** The toast queue: `toast.show({ title })` from anywhere; `toast.close(key)`; `toast.clear()`. */
|
|
252
|
+
var toast = {
|
|
253
|
+
/** Shows a toast and returns its key. */
|
|
254
|
+
show(content) {
|
|
255
|
+
if (mounted.length === 0 && !warnedNoRegion && isDev()) {
|
|
256
|
+
warnedNoRegion = true;
|
|
257
|
+
console.warn("strata-react: toast.show() was called but no StrataToastRegion is mounted, so nothing will appear. Render <StrataToastRegion /> once at the app root.");
|
|
258
|
+
}
|
|
259
|
+
return queue.add(content, { timeout: toastTimeout(content) });
|
|
260
|
+
},
|
|
261
|
+
close(key) {
|
|
262
|
+
queue.close(key);
|
|
263
|
+
},
|
|
264
|
+
clear() {
|
|
265
|
+
queue.clear();
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
var marks = {
|
|
269
|
+
info: {
|
|
270
|
+
icon: Info,
|
|
271
|
+
color: "text-info"
|
|
272
|
+
},
|
|
273
|
+
success: {
|
|
274
|
+
icon: CircleCheck,
|
|
275
|
+
color: "text-success"
|
|
276
|
+
},
|
|
277
|
+
warning: {
|
|
278
|
+
icon: TriangleAlert,
|
|
279
|
+
color: "text-warning"
|
|
280
|
+
}
|
|
281
|
+
};
|
|
282
|
+
var mounted = [];
|
|
283
|
+
var warnedNoRegion = false;
|
|
284
|
+
var watchers = /* @__PURE__ */ new Set();
|
|
285
|
+
var changed = () => watchers.forEach((w) => w());
|
|
286
|
+
var watch = (w) => {
|
|
287
|
+
watchers.add(w);
|
|
288
|
+
return () => void watchers.delete(w);
|
|
289
|
+
};
|
|
290
|
+
/** True while this region is the one that draws. The server and the first client render say yes, so hydration matches. */
|
|
291
|
+
function useOwnsQueue() {
|
|
292
|
+
const id = React.useId();
|
|
293
|
+
React.useLayoutEffect(() => {
|
|
294
|
+
mounted.push(id);
|
|
295
|
+
changed();
|
|
296
|
+
return () => {
|
|
297
|
+
mounted.splice(mounted.indexOf(id), 1);
|
|
298
|
+
changed();
|
|
299
|
+
};
|
|
300
|
+
}, [id]);
|
|
301
|
+
const owns = React.useSyncExternalStore(watch, () => mounted[0] === id, () => true);
|
|
302
|
+
const [warned, setWarned] = React.useState(false);
|
|
303
|
+
React.useEffect(() => {
|
|
304
|
+
if (owns || warned || mounted.indexOf(id) < 1) return;
|
|
305
|
+
setWarned(true);
|
|
306
|
+
if (isDev()) console.warn("strata-react: a StrataToastRegion is already mounted, so this one draws nothing. Render it once at the app root; in a test of a route tree that draws its own, pass `toasts: false` to renderRoutes.");
|
|
307
|
+
}, [
|
|
308
|
+
owns,
|
|
309
|
+
warned,
|
|
310
|
+
id
|
|
311
|
+
]);
|
|
312
|
+
return owns;
|
|
313
|
+
}
|
|
314
|
+
/** The one place toasts appear. Render it once at the app root; a second one mounted at the same time draws nothing and warns in development. A labelled landmark (F6), polite, above panes and the undo bar. */
|
|
315
|
+
function StrataToastRegion({ label = "Notifications", className }) {
|
|
316
|
+
if (!useOwnsQueue()) return null;
|
|
317
|
+
return /* @__PURE__ */ jsx(UNSTABLE_ToastRegion, {
|
|
318
|
+
queue,
|
|
319
|
+
"aria-label": label,
|
|
320
|
+
className: cn("layer-bar fixed inset-x-4 top-4 grid justify-items-end gap-2 outline-none sm:inset-x-auto sm:top-auto sm:right-4 sm:bottom-4", className),
|
|
321
|
+
children: ({ toast: t }) => /* @__PURE__ */ jsxs(UNSTABLE_Toast, {
|
|
322
|
+
toast: t,
|
|
323
|
+
className: cn("flex w-full max-w-sm items-start gap-3 p-3 outline-none focus-visible:outline-2 focus-visible:outline-ring", overlaySurface),
|
|
324
|
+
children: [
|
|
325
|
+
(() => {
|
|
326
|
+
const { icon: Icon, color } = marks[t.content.tone ?? "info"];
|
|
327
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
328
|
+
"aria-hidden": true,
|
|
329
|
+
className: cn("mt-0.5 size-4 shrink-0", color)
|
|
330
|
+
});
|
|
331
|
+
})(),
|
|
332
|
+
/* @__PURE__ */ jsxs(UNSTABLE_ToastContent, {
|
|
333
|
+
className: "grid min-w-0 flex-1 gap-0.5",
|
|
334
|
+
children: [/* @__PURE__ */ jsx(Text, {
|
|
335
|
+
slot: "title",
|
|
336
|
+
className: "type-label",
|
|
337
|
+
children: t.content.title
|
|
338
|
+
}), t.content.description && /* @__PURE__ */ jsx(Text, {
|
|
339
|
+
slot: "description",
|
|
340
|
+
className: "type-body-sm text-muted-foreground",
|
|
341
|
+
children: t.content.description
|
|
342
|
+
})]
|
|
343
|
+
}),
|
|
344
|
+
t.content.action && /* @__PURE__ */ jsx(Button$1, {
|
|
345
|
+
size: "sm",
|
|
346
|
+
onPress: () => {
|
|
347
|
+
t.content.action?.onPress();
|
|
348
|
+
queue.close(t.key);
|
|
349
|
+
},
|
|
350
|
+
children: t.content.action.label
|
|
351
|
+
}),
|
|
352
|
+
/* @__PURE__ */ jsx(Button, {
|
|
353
|
+
slot: "close",
|
|
354
|
+
"aria-label": "Dismiss",
|
|
355
|
+
className: "grid size-6 shrink-0 cursor-pointer place-items-center rounded-control text-muted-foreground transition-state hover:bg-muted hover:text-foreground",
|
|
356
|
+
children: /* @__PURE__ */ jsx(X, {
|
|
357
|
+
"aria-hidden": true,
|
|
358
|
+
className: "size-4"
|
|
359
|
+
})
|
|
360
|
+
})
|
|
361
|
+
]
|
|
362
|
+
})
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// src/components/thumbnail.tsx
|
|
366
|
+
var loadedBefore = /* @__PURE__ */ new Map();
|
|
367
|
+
var LOADED_LIMIT = 2e3;
|
|
368
|
+
function remember(key, index) {
|
|
369
|
+
loadedBefore.delete(key);
|
|
370
|
+
loadedBefore.set(key, index);
|
|
371
|
+
if (loadedBefore.size > LOADED_LIMIT) loadedBefore.delete(loadedBefore.keys().next().value);
|
|
372
|
+
}
|
|
373
|
+
/** Forgets which pictures `Thumbnail` has loaded, so a test that checks the loading state starts from nothing. `renderWithStrata` and `renderRoutes` call it. */
|
|
374
|
+
function forgetLoadedThumbnails() {
|
|
375
|
+
loadedBefore.clear();
|
|
376
|
+
}
|
|
377
|
+
var ratio = (aspect) => typeof aspect === "number" ? String(aspect) : aspect.replace("/", " / ");
|
|
378
|
+
/** A box of fixed aspect ratio for a remote image: a skeleton until it loads, the `missing` words (or a `fallback`) if it cannot, a request only when it nears the screen, and `children` overlaid in its corners. `alt` and `missing` or `fallback` are required. */
|
|
379
|
+
function Thumbnail({ src, alt, missing, aspect = 1, fit = "cover", srcSet, sizes, eager = false, rootMargin = "200px", className, fallback, onLoad, onMissing, children }) {
|
|
380
|
+
const sources = React.useMemo(() => src === null ? [] : typeof src === "string" ? src ? [src] : [] : src.filter(Boolean), [src]);
|
|
381
|
+
const key = sources.length ? `${sources.join("\n")} ${srcSet ?? ""}` : null;
|
|
382
|
+
const [outcome, setOutcome] = React.useState(null);
|
|
383
|
+
const before = key === null ? void 0 : loadedBefore.get(key);
|
|
384
|
+
const mine = key !== null && outcome?.key === key ? outcome : null;
|
|
385
|
+
const index = mine?.index ?? before ?? 0;
|
|
386
|
+
const phase = key === null ? "missing" : mine?.done ?? "loading";
|
|
387
|
+
const current = sources[index];
|
|
388
|
+
const near = useInView({
|
|
389
|
+
active: !eager && sources.length > 0,
|
|
390
|
+
rootMargin,
|
|
391
|
+
once: true,
|
|
392
|
+
unsupported: true
|
|
393
|
+
});
|
|
394
|
+
const requested = eager || near.inView || before !== void 0;
|
|
395
|
+
const fail = () => setOutcome(index + 1 < sources.length ? {
|
|
396
|
+
key,
|
|
397
|
+
index: index + 1,
|
|
398
|
+
done: null
|
|
399
|
+
} : {
|
|
400
|
+
key,
|
|
401
|
+
index,
|
|
402
|
+
done: "missing"
|
|
403
|
+
});
|
|
404
|
+
const told = React.useRef(null);
|
|
405
|
+
const tell = React.useRef(onMissing);
|
|
406
|
+
tell.current = onMissing;
|
|
407
|
+
React.useEffect(() => {
|
|
408
|
+
if (phase !== "missing") told.current = null;
|
|
409
|
+
else if (key !== null && told.current !== key) {
|
|
410
|
+
told.current = key;
|
|
411
|
+
tell.current?.();
|
|
412
|
+
}
|
|
413
|
+
}, [key, phase]);
|
|
414
|
+
const name = [alt, missing].filter(Boolean).join(": ");
|
|
415
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
416
|
+
ref: near.ref,
|
|
417
|
+
className: cn("relative overflow-hidden rounded-control bg-muted", className),
|
|
418
|
+
style: { aspectRatio: ratio(aspect) },
|
|
419
|
+
"aria-busy": phase === "loading" || void 0,
|
|
420
|
+
children: [
|
|
421
|
+
phase === "loading" && /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" }),
|
|
422
|
+
key !== null && phase !== "missing" && requested && /* @__PURE__ */ jsx("img", {
|
|
423
|
+
ref: (el) => {
|
|
424
|
+
if (el && phase === "loading" && before !== void 0 && el.complete && el.naturalWidth > 0) setOutcome({
|
|
425
|
+
key,
|
|
426
|
+
index,
|
|
427
|
+
done: "loaded"
|
|
428
|
+
});
|
|
429
|
+
},
|
|
430
|
+
src: current,
|
|
431
|
+
srcSet: index === 0 ? srcSet : void 0,
|
|
432
|
+
sizes,
|
|
433
|
+
alt,
|
|
434
|
+
decoding: "async",
|
|
435
|
+
onLoad: (e) => onLoad?.(e.currentTarget, index) === false ? fail() : (remember(key, index), setOutcome({
|
|
436
|
+
key,
|
|
437
|
+
index,
|
|
438
|
+
done: "loaded"
|
|
439
|
+
})),
|
|
440
|
+
onError: fail,
|
|
441
|
+
className: cn("absolute inset-0 size-full", fit === "cover" ? "object-cover" : "object-contain", phase === "loading" && "opacity-0")
|
|
442
|
+
}, `${key}#${index}`),
|
|
443
|
+
phase === "missing" && /* @__PURE__ */ jsx("div", {
|
|
444
|
+
...name ? {
|
|
445
|
+
role: "img",
|
|
446
|
+
"aria-label": name
|
|
447
|
+
} : { "aria-hidden": true },
|
|
448
|
+
className: cn("absolute inset-0 grid", fallback === void 0 && "content-center justify-items-center gap-0.5 p-1 text-center text-muted-foreground"),
|
|
449
|
+
children: fallback === void 0 ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(ImageOff, {
|
|
450
|
+
"aria-hidden": true,
|
|
451
|
+
className: "size-4 shrink-0"
|
|
452
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
453
|
+
className: "type-caption text-balance",
|
|
454
|
+
children: missing
|
|
455
|
+
})] }) : /* @__PURE__ */ jsx("div", {
|
|
456
|
+
"aria-hidden": true,
|
|
457
|
+
className: "grid size-full min-h-0 min-w-0",
|
|
458
|
+
children: fallback
|
|
459
|
+
})
|
|
460
|
+
}),
|
|
461
|
+
children
|
|
462
|
+
]
|
|
463
|
+
});
|
|
464
|
+
}
|
|
465
|
+
/** The loading shape of a `Thumbnail`, for a `DataView` skeleton: the same box and aspect ratio, so nothing moves when the list arrives. */
|
|
466
|
+
function ThumbnailSkeleton({ aspect = 1, className }) {
|
|
467
|
+
return /* @__PURE__ */ jsx("div", {
|
|
468
|
+
"aria-hidden": true,
|
|
469
|
+
className: cn("relative overflow-hidden rounded-control bg-muted", className),
|
|
470
|
+
style: { aspectRatio: ratio(aspect) },
|
|
471
|
+
children: /* @__PURE__ */ jsx(Skeleton, { className: "absolute inset-0" })
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
// src/lib/microphone.ts
|
|
475
|
+
/** A microphone that would not open, with a sentence a person can act on. */
|
|
476
|
+
var MicrophoneError = class extends Error {};
|
|
477
|
+
/** The sentence for what getUserMedia threw. */
|
|
478
|
+
function explainMicrophoneError(e) {
|
|
479
|
+
const name = e instanceof DOMException ? e.name : "";
|
|
480
|
+
if (name === "NotAllowedError") return new MicrophoneError("The browser was not allowed to use the microphone. Allow it from the address bar, then try again.");
|
|
481
|
+
if (name === "NotFoundError") return new MicrophoneError("No microphone was found. Plug one in, then try again.");
|
|
482
|
+
if (name === "NotReadableError") return new MicrophoneError("The microphone is in use by another program. Close it, then try again.");
|
|
483
|
+
return new MicrophoneError(`The microphone could not be opened (${e instanceof DOMException || e instanceof Error ? e.message : String(e)}).`);
|
|
484
|
+
}
|
|
485
|
+
var WORKLET = `
|
|
486
|
+
class StrataTap extends AudioWorkletProcessor {
|
|
487
|
+
constructor() { super(); this.buf = new Float32Array(2048); this.n = 0 }
|
|
488
|
+
process(inputs) {
|
|
489
|
+
const ch = inputs[0] && inputs[0][0]
|
|
490
|
+
if (ch) for (let i = 0; i < ch.length; i++) {
|
|
491
|
+
this.buf[this.n++] = ch[i]
|
|
492
|
+
if (this.n === this.buf.length) { this.port.postMessage(this.buf.slice()); this.n = 0 }
|
|
493
|
+
}
|
|
494
|
+
return true
|
|
495
|
+
}
|
|
496
|
+
}
|
|
497
|
+
registerProcessor('strata-tap', StrataTap)
|
|
498
|
+
`;
|
|
499
|
+
/** The browser's own microphone, with its processing off. */
|
|
500
|
+
var browserMicrophone = { async open(onSamples) {
|
|
501
|
+
if (typeof navigator === "undefined" || !navigator.mediaDevices?.getUserMedia) throw new MicrophoneError("The microphone needs a secure page: open the app at http://localhost or over https.");
|
|
502
|
+
let media;
|
|
503
|
+
try {
|
|
504
|
+
media = await navigator.mediaDevices.getUserMedia({ audio: {
|
|
505
|
+
channelCount: 1,
|
|
506
|
+
echoCancellation: false,
|
|
507
|
+
noiseSuppression: false,
|
|
508
|
+
autoGainControl: false
|
|
509
|
+
} });
|
|
510
|
+
} catch (e) {
|
|
511
|
+
throw explainMicrophoneError(e);
|
|
512
|
+
}
|
|
513
|
+
let context;
|
|
514
|
+
const close = () => {
|
|
515
|
+
for (const t of media.getTracks()) t.stop();
|
|
516
|
+
context?.close();
|
|
517
|
+
};
|
|
518
|
+
try {
|
|
519
|
+
context = new AudioContext();
|
|
520
|
+
const url = URL.createObjectURL(new Blob([WORKLET], { type: "text/javascript" }));
|
|
521
|
+
try {
|
|
522
|
+
await context.audioWorklet.addModule(url);
|
|
523
|
+
} finally {
|
|
524
|
+
URL.revokeObjectURL(url);
|
|
525
|
+
}
|
|
526
|
+
const tap = new AudioWorkletNode(context, "strata-tap");
|
|
527
|
+
tap.port.onmessage = (event) => onSamples(event.data);
|
|
528
|
+
const mute = context.createGain();
|
|
529
|
+
mute.gain.value = 0;
|
|
530
|
+
context.createMediaStreamSource(media).connect(tap).connect(mute).connect(context.destination);
|
|
531
|
+
return {
|
|
532
|
+
sampleRate: context.sampleRate,
|
|
533
|
+
device: media.getAudioTracks()[0]?.label || null,
|
|
534
|
+
close
|
|
535
|
+
};
|
|
536
|
+
} catch (e) {
|
|
537
|
+
close();
|
|
538
|
+
throw explainMicrophoneError(e);
|
|
539
|
+
}
|
|
540
|
+
} };
|
|
541
|
+
/** The microphone screens record from: the browser's, unless a provider gives another (a fake in tests and stories). */
|
|
542
|
+
var MicrophoneContext = React.createContext(browserMicrophone);
|
|
543
|
+
/** The microphone from the nearest `MicrophoneContext`. */
|
|
544
|
+
var useMicrophone = () => React.useContext(MicrophoneContext);
|
|
545
|
+
export { usePoll as C, useLoad as S, StrataQueryProvider as _, useMicrophone as a, staleOf as b, forgetLoadedThumbnails as c, toastTimeout as d, DataView as f, StaleNotice as g, Skeleton as h, explainMicrophoneError as i, StrataToastRegion as l, LoadError as m, MicrophoneError as n, Thumbnail as o, EmptyState as p, browserMicrophone as r, ThumbnailSkeleton as s, MicrophoneContext as t, toast as u, createQueryClient as v, overlaySurface as w, toLoad as x, fetchJson as y };
|
|
546
|
+
|
|
547
|
+
//# sourceMappingURL=microphone-Cu1u5Yml.js.map
|