@alulore/kumiko 0.19.1 → 0.20.1

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 (136) hide show
  1. package/dist/board/board-api.d.ts +2 -1
  2. package/dist/board/board-api.js +1 -1
  3. package/dist/board/board-motion.js +29 -1
  4. package/dist/board/board-slots.d.ts +14 -7
  5. package/dist/board/board-slots.js +5 -3
  6. package/dist/board/board.d.ts +20 -5
  7. package/dist/board/board.js +28 -5
  8. package/dist/board/keep-capture.d.ts +10 -5
  9. package/dist/board/keep-capture.js +48 -13
  10. package/dist/cooldown/cooldown-button.d.ts +30 -0
  11. package/dist/cooldown/cooldown-button.js +75 -0
  12. package/dist/cooldown/cooldown-labels.d.ts +8 -0
  13. package/dist/cooldown/cooldown-labels.js +4 -0
  14. package/dist/cooldown/cooldown-time.d.ts +8 -0
  15. package/dist/cooldown/cooldown-time.js +20 -0
  16. package/dist/cooldown/cooldown.css +21 -0
  17. package/dist/cooldown/index.d.ts +4 -0
  18. package/dist/cooldown/index.js +4 -0
  19. package/dist/cooldown/use-cooldown.d.ts +30 -0
  20. package/dist/cooldown/use-cooldown.js +63 -0
  21. package/dist/dialog/dialog-content.d.ts +5 -0
  22. package/dist/dialog/dialog-content.js +7 -0
  23. package/dist/empty-state/empty-state-labels.d.ts +14 -0
  24. package/dist/empty-state/empty-state-labels.js +10 -0
  25. package/dist/empty-state/empty-state.css +134 -0
  26. package/dist/empty-state/empty-state.d.ts +34 -0
  27. package/dist/empty-state/empty-state.js +61 -0
  28. package/dist/empty-state/index.d.ts +2 -0
  29. package/dist/empty-state/index.js +2 -0
  30. package/dist/form/choice-fields.d.ts +34 -0
  31. package/dist/form/choice-fields.js +41 -0
  32. package/dist/form/error-line.d.ts +8 -0
  33. package/dist/form/error-line.js +47 -0
  34. package/dist/form/field-props.d.ts +12 -0
  35. package/dist/form/field-props.js +8 -0
  36. package/dist/form/field-shell.d.ts +18 -0
  37. package/dist/form/field-shell.js +51 -0
  38. package/dist/form/focus-invalid.d.ts +5 -0
  39. package/dist/form/focus-invalid.js +17 -0
  40. package/dist/form/form-context.d.ts +2 -0
  41. package/dist/form/form-context.js +3 -0
  42. package/dist/form/form-parts.d.ts +20 -0
  43. package/dist/form/form-parts.js +73 -0
  44. package/dist/form/form.css +128 -0
  45. package/dist/form/index.d.ts +10 -0
  46. package/dist/form/index.js +9 -0
  47. package/dist/form/shown-error.d.ts +12 -0
  48. package/dist/form/shown-error.js +27 -0
  49. package/dist/form/submit-errors.d.ts +36 -0
  50. package/dist/form/submit-errors.js +46 -0
  51. package/dist/form/text-fields.d.ts +18 -0
  52. package/dist/form/text-fields.js +21 -0
  53. package/dist/form/use-app-form.d.ts +1655 -0
  54. package/dist/form/use-app-form.js +94 -0
  55. package/dist/form/use-dialog-link.d.ts +5 -0
  56. package/dist/form/use-dialog-link.js +30 -0
  57. package/dist/form/value-fields.d.ts +16 -0
  58. package/dist/form/value-fields.js +15 -0
  59. package/dist/map/geo.d.ts +20 -0
  60. package/dist/map/geo.js +41 -0
  61. package/dist/map/index.d.ts +5 -0
  62. package/dist/map/index.js +4 -0
  63. package/dist/map/label-overlap.d.ts +13 -0
  64. package/dist/map/label-overlap.js +23 -0
  65. package/dist/map/load-map.d.ts +12 -0
  66. package/dist/map/load-map.js +22 -0
  67. package/dist/map/location-map.d.ts +39 -0
  68. package/dist/map/location-map.js +171 -0
  69. package/dist/map/map-frame.d.ts +18 -0
  70. package/dist/map/map-frame.js +6 -0
  71. package/dist/map/map-pin.d.ts +4 -0
  72. package/dist/map/map-pin.js +38 -0
  73. package/dist/map/map-popup.d.ts +17 -0
  74. package/dist/map/map-popup.js +101 -0
  75. package/dist/map/map-source.d.ts +52 -0
  76. package/dist/map/map-source.js +59 -0
  77. package/dist/map/map.css +311 -0
  78. package/dist/map/marker-pins.d.ts +29 -0
  79. package/dist/map/marker-pins.js +144 -0
  80. package/dist/map/markers-map.d.ts +57 -0
  81. package/dist/map/markers-map.js +154 -0
  82. package/dist/map/use-label-overlap.d.ts +9 -0
  83. package/dist/map/use-label-overlap.js +55 -0
  84. package/dist/map/use-map.d.ts +49 -0
  85. package/dist/map/use-map.js +201 -0
  86. package/dist/media/encoding.d.ts +32 -0
  87. package/dist/media/encoding.js +59 -0
  88. package/dist/media/errors.d.ts +33 -0
  89. package/dist/media/errors.js +26 -0
  90. package/dist/media/image.d.ts +9 -0
  91. package/dist/media/image.js +35 -0
  92. package/dist/media/index.d.ts +10 -0
  93. package/dist/media/index.js +10 -0
  94. package/dist/media/load-mediabunny.d.ts +7 -0
  95. package/dist/media/load-mediabunny.js +13 -0
  96. package/dist/media/media-upload.d.ts +40 -0
  97. package/dist/media/media-upload.js +132 -0
  98. package/dist/media/media.css +101 -0
  99. package/dist/media/probe.d.ts +19 -0
  100. package/dist/media/probe.js +49 -0
  101. package/dist/media/sizes.d.ts +28 -0
  102. package/dist/media/sizes.js +51 -0
  103. package/dist/media/slideshow.d.ts +43 -0
  104. package/dist/media/slideshow.js +174 -0
  105. package/dist/media/timeline.d.ts +59 -0
  106. package/dist/media/timeline.js +105 -0
  107. package/dist/media/transcode.d.ts +35 -0
  108. package/dist/media/transcode.js +132 -0
  109. package/dist/media/upload.d.ts +21 -0
  110. package/dist/media/upload.js +54 -0
  111. package/dist/media/use-media-job.d.ts +79 -0
  112. package/dist/media/use-media-job.js +143 -0
  113. package/dist/server-render.test.js +93 -0
  114. package/dist/smooth-caret/caret-controller.js +16 -3
  115. package/dist/table/table-labels.d.ts +2 -0
  116. package/dist/table/table-labels.js +1 -0
  117. package/dist/table/table-sections.js +10 -2
  118. package/dist/table/table.css +1 -0
  119. package/dist/theme/define-theme.d.ts +38 -0
  120. package/dist/theme/define-theme.js +56 -0
  121. package/dist/theme/index.d.ts +3 -0
  122. package/dist/theme/index.js +3 -0
  123. package/dist/theme/theme-style.d.ts +6 -0
  124. package/dist/theme/theme-style.js +11 -0
  125. package/dist/theme/theme-types.d.ts +1 -0
  126. package/dist/theme/theme-types.js +26 -0
  127. package/dist/theme/tokens-1.generated.d.ts +1 -0
  128. package/dist/theme/tokens-1.generated.js +404 -0
  129. package/dist/theme/tokens-2.generated.d.ts +1 -0
  130. package/dist/theme/tokens-2.generated.js +404 -0
  131. package/dist/theme/tokens-3.generated.d.ts +1 -0
  132. package/dist/theme/tokens-3.generated.js +158 -0
  133. package/dist/theme/tokens.generated.d.ts +2 -0
  134. package/dist/theme/tokens.generated.js +6 -0
  135. package/dist/undo/undo-provider.js +24 -9
  136. package/package.json +82 -5
@@ -0,0 +1,79 @@
1
+ import { type MediaErrorCode } from "./errors";
2
+ import { type MediaInfo } from "./probe";
3
+ /** The step a job is on, or the one it failed in. */
4
+ export type MediaJobStep = "reading" | "converting" | "uploading";
5
+ /**
6
+ * Why a job failed: a `MediaError`'s code, `rejected` when the app's `check` turned the file away (with its
7
+ * `reason`), or `unknown` for any other error an app's own step threw (kept in `error`).
8
+ */
9
+ export interface MediaJobFailure {
10
+ readonly code: MediaErrorCode | "rejected" | "unknown";
11
+ readonly step: MediaJobStep;
12
+ readonly reason?: string;
13
+ /** The upload's HTTP status, for `upload-status`. */
14
+ readonly status?: number;
15
+ readonly error?: unknown;
16
+ }
17
+ /** Where a job stands. Progress is 0 to 1, or null when the length can't be known. */
18
+ export type MediaJobState<Result> = {
19
+ readonly phase: "idle";
20
+ } | {
21
+ readonly phase: "reading";
22
+ readonly file: File;
23
+ } | {
24
+ readonly phase: "converting";
25
+ readonly file: File;
26
+ readonly progress: number | null;
27
+ } | {
28
+ readonly phase: "uploading";
29
+ readonly file: File;
30
+ readonly progress: number | null;
31
+ } | {
32
+ readonly phase: "done";
33
+ readonly file: File;
34
+ readonly result: Result;
35
+ } | {
36
+ readonly phase: "failed";
37
+ readonly file: File;
38
+ readonly failure: MediaJobFailure;
39
+ } | {
40
+ readonly phase: "cancelled";
41
+ readonly file: File;
42
+ };
43
+ /** What every step gets: the signal that stops it, and a place to report how far it is. */
44
+ export interface MediaJobContext {
45
+ readonly file: File;
46
+ readonly info: MediaInfo | null;
47
+ readonly signal: AbortSignal;
48
+ readonly onProgress: (fraction: number | null) => void;
49
+ }
50
+ export interface MediaJobSteps<Result> {
51
+ /**
52
+ * Reads the file first, so `check` and `convert` know what it is. Pass `false` to skip it, as for pictures.
53
+ * @defaultValue `readMediaInfo`
54
+ */
55
+ readonly read?: false | ((file: File, signal: AbortSignal) => Promise<MediaInfo>);
56
+ /** Turns a file away before any work, by returning the reason, which the app shows. */
57
+ readonly check?: (info: MediaInfo | null, file: File) => string | null | undefined;
58
+ /** Converts the file, as with `transcodeVideo`. Without it, the file is uploaded as it is. */
59
+ readonly convert?: (context: MediaJobContext) => Promise<Blob>;
60
+ /** Sends the converted file, as with `uploadToSignedUrl`, and gives what the app keeps. */
61
+ readonly upload: (body: Blob, context: MediaJobContext) => Promise<Result>;
62
+ }
63
+ export interface MediaJob<Result> {
64
+ readonly state: MediaJobState<Result>;
65
+ /** Starts on `file`. A job already running is cancelled first. */
66
+ readonly start: (file: File) => void;
67
+ /** Stops a running job. It ends `cancelled`, and anything its steps finish later is dropped. */
68
+ readonly cancel: () => void;
69
+ /** Starts again on the same file after a failure or a cancel. Does nothing otherwise. */
70
+ readonly retry: () => void;
71
+ /** Back to idle, cancelling a running job. */
72
+ readonly reset: () => void;
73
+ }
74
+ /**
75
+ * Runs one file through reading, converting and uploading, with cancel and retry. The steps are the app's
76
+ * (`transcodeVideo` and `uploadToSignedUrl` fit them); the hook keeps one phase, drops whatever a cancelled run
77
+ * finishes later, and stops a running job when the component unmounts.
78
+ */
79
+ export declare function useMediaJob<Result>(steps: MediaJobSteps<Result>): MediaJob<Result>;
@@ -0,0 +1,143 @@
1
+ import { useCallback, useEffect, useRef, useState } from "react";
2
+ import { MediaError } from "./errors";
3
+ import { readMediaInfo } from "./probe";
4
+ const running = new Set(["reading", "converting", "uploading"]);
5
+ function failureOf(error, at) {
6
+ if (error instanceof MediaError) {
7
+ return { code: error.code, step: at, status: error.status, error };
8
+ }
9
+ return { code: "unknown", step: at, error };
10
+ }
11
+ /** Progress rounded to a whole percent, so a step that reports every frame renders a hundred times at most. */
12
+ function rounded(fraction) {
13
+ return fraction === null ? null : Math.round(Math.min(1, Math.max(0, fraction)) * 100) / 100;
14
+ }
15
+ /** Ends a run whose state is already set (failed) or no longer counts (cancelled). */
16
+ class StoppedError extends Error {
17
+ constructor() {
18
+ super("stopped");
19
+ this.name = "StoppedError";
20
+ }
21
+ }
22
+ function readStep(run) {
23
+ const { steps, file, signal, set } = run;
24
+ if (steps.read === false) {
25
+ return Promise.resolve(null);
26
+ }
27
+ set({ phase: "reading", file });
28
+ return (steps.read ?? ((blob, stop) => readMediaInfo(blob, { signal: stop })))(file, signal);
29
+ }
30
+ /** One step: reports its phase and progress, and turns any error into the step's failure. */
31
+ async function step(run, name, work) {
32
+ try {
33
+ const value = await work((fraction) => {
34
+ if (!run.signal.aborted && name !== "reading") {
35
+ run.set({ phase: name, file: run.file, progress: rounded(fraction) });
36
+ }
37
+ });
38
+ /* An app's step may ignore the signal and finish anyway; a stopped run still goes no further. */
39
+ if (run.signal.aborted) {
40
+ throw new StoppedError();
41
+ }
42
+ return value;
43
+ }
44
+ catch (error) {
45
+ if (error instanceof StoppedError) {
46
+ throw error;
47
+ }
48
+ if (run.signal.aborted) {
49
+ throw new StoppedError();
50
+ }
51
+ run.set({ phase: "failed", file: run.file, failure: failureOf(error, name) });
52
+ throw new StoppedError();
53
+ }
54
+ }
55
+ async function runJob(run) {
56
+ const { steps, file, signal, set } = run;
57
+ const info = await step(run, "reading", () => readStep(run));
58
+ const reason = steps.check?.(info, file);
59
+ if (reason) {
60
+ set({ phase: "failed", file, failure: { code: "rejected", step: "reading", reason } });
61
+ return;
62
+ }
63
+ const context = (onProgress) => ({
64
+ file,
65
+ info,
66
+ signal,
67
+ onProgress
68
+ });
69
+ let body = file;
70
+ const { convert } = steps;
71
+ if (convert) {
72
+ set({ phase: "converting", file, progress: 0 });
73
+ body = await step(run, "converting", (report) => convert(context(report)));
74
+ }
75
+ set({ phase: "uploading", file, progress: 0 });
76
+ const result = await step(run, "uploading", (report) => steps.upload(body, context(report)));
77
+ set({ phase: "done", file, result });
78
+ }
79
+ /** Starts and stops runs. Only the newest run may set the state, so a stopped run's late results are dropped. */
80
+ function useRunner(steps, setState) {
81
+ const latest = useRef(steps);
82
+ latest.current = steps;
83
+ const current = useRef(null);
84
+ const stop = useCallback(() => {
85
+ const controller = current.current;
86
+ current.current = null;
87
+ controller?.abort();
88
+ return controller !== null;
89
+ }, []);
90
+ const start = useCallback((file) => {
91
+ stop();
92
+ const controller = new AbortController();
93
+ current.current = controller;
94
+ const set = (next) => {
95
+ if (current.current === controller) {
96
+ setState(next);
97
+ }
98
+ };
99
+ void runJob({ steps: latest.current, file, signal: controller.signal, set })
100
+ .catch((error) => {
101
+ if (!(error instanceof StoppedError)) {
102
+ throw error;
103
+ }
104
+ })
105
+ .finally(() => {
106
+ if (current.current === controller) {
107
+ current.current = null;
108
+ }
109
+ });
110
+ }, [stop, setState]);
111
+ useEffect(() => () => {
112
+ stop();
113
+ }, [stop]);
114
+ return { stop, start };
115
+ }
116
+ /**
117
+ * Runs one file through reading, converting and uploading, with cancel and retry. The steps are the app's
118
+ * (`transcodeVideo` and `uploadToSignedUrl` fit them); the hook keeps one phase, drops whatever a cancelled run
119
+ * finishes later, and stops a running job when the component unmounts.
120
+ */
121
+ export function useMediaJob(steps) {
122
+ const [state, setState] = useState({ phase: "idle" });
123
+ const stateRef = useRef(state);
124
+ stateRef.current = state;
125
+ const { stop, start } = useRunner(steps, setState);
126
+ const cancel = useCallback(() => {
127
+ const now = stateRef.current;
128
+ if (running.has(now.phase) && "file" in now && stop()) {
129
+ setState({ phase: "cancelled", file: now.file });
130
+ }
131
+ }, [stop]);
132
+ const retry = useCallback(() => {
133
+ const now = stateRef.current;
134
+ if (now.phase === "failed" || now.phase === "cancelled") {
135
+ start(now.file);
136
+ }
137
+ }, [start]);
138
+ const reset = useCallback(() => {
139
+ stop();
140
+ setState({ phase: "idle" });
141
+ }, [stop]);
142
+ return { state, start, cancel, retry, reset };
143
+ }
@@ -2,8 +2,13 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { describe, expect, it } from "bun:test";
3
3
  import { renderToString } from "react-dom/server";
4
4
  import { Avatar } from "./avatar";
5
+ import { CooldownButton, useCooldown } from "./cooldown";
5
6
  import { Drawer, DrawerContent, DrawerTitle, DrawerTrigger } from "./drawer";
7
+ import { EmptyState } from "./empty-state";
6
8
  import { FileDropzone, FilePreview } from "./file-input";
9
+ import { useAppForm } from "./form";
10
+ import { defineMapSource, LocationMap, MarkersMap } from "./map";
11
+ import { MediaUpload, useMediaJob } from "./media";
7
12
  import { OTPInput } from "./otp-input";
8
13
  import { Page, PageAction, PageActions, PageBreadcrumbs, PageCrumb, PageHeader } from "./page";
9
14
  import { Pagination } from "./pagination";
@@ -11,6 +16,7 @@ import { AppShell, cookieStorage, readSidebarCookie, Sidebar, SidebarBody, Sideb
11
16
  import { Skeleton, SkeletonGroup, SkeletonText } from "./skeleton";
12
17
  import { column, DataTable, numberColumn } from "./table";
13
18
  import { Tabs, TabsList, TabsPanel, TabsTab } from "./tabs";
19
+ import { defineTheme, ThemeStyle } from "./theme";
14
20
  /*
15
21
  * Bun runs these with no DOM, as a server does: a component that reads `window` or `document`, or makes a
16
22
  * browser-only value, while it renders fails here before it fails an app's server.
@@ -91,6 +97,87 @@ function aPageHeaderIsEveryActionInline() {
91
97
  }
92
98
  expect(header).not.toContain('aria-label="More actions"');
93
99
  }
100
+ function ContactForm() {
101
+ const form = useAppForm({
102
+ defaultValues: { name: "", notes: "", plan: "free" },
103
+ onSubmit: () => undefined
104
+ });
105
+ return (_jsxs(form.Form, { "aria-label": "Contact", children: [_jsx(form.AppField, { name: "name", children: (field) => _jsx(field.TextField, { label: "Name", required: true }) }), _jsx(form.AppField, { name: "notes", children: (field) => (_jsx(field.TextareaField, { label: "Notes", description: "Anything we should know." })) }), _jsx(form.AppField, { name: "plan", children: (field) => (_jsx(field.SelectField, { label: "Plan", options: [
106
+ { value: "free", label: "Free" },
107
+ { value: "pro", label: "Pro" }
108
+ ] })) }), _jsx(form.FormError, {}), _jsx(form.Actions, { children: _jsx(form.SubmitButton, { children: "Send" }) })] }));
109
+ }
110
+ function aFormIsItsFieldsWithLabels() {
111
+ const html = renderToString(_jsx(ContactForm, {}));
112
+ expect(html).toMatch(/<form [^>]*aria-label="Contact"[^>]*novalidate/iu);
113
+ for (const label of ["Name", "Notes", "Plan"]) {
114
+ expect(html).toMatch(new RegExp(`data-slot="field-label"[^>]*>${label}<`, "u"));
115
+ }
116
+ expect(html).toContain("Anything we should know.");
117
+ expect(html).toMatch(/<button [^>]*type="submit"[^>]*>.*Send</u);
118
+ expect(html).not.toContain('role="alert"');
119
+ }
120
+ function ResendCode() {
121
+ const cooldown = useCooldown({ key: "reset:ana@example.com", seconds: 30 });
122
+ return (_jsx(CooldownButton, { cooldown: cooldown, onPress: () => undefined, children: "Resend code" }));
123
+ }
124
+ function aCooldownButtonWithAKeyIsIdle() {
125
+ const html = renderToString(_jsx(ResendCode, {}));
126
+ expect(html).toMatch(/<button [^>]*>.*Resend code</u);
127
+ expect(html).not.toContain("Resend in");
128
+ expect(html).not.toContain("aria-disabled");
129
+ expect(html).not.toContain("data-cooldown");
130
+ expect(html).toMatch(/<span [^>]*data-slot="cooldown-live"[^>]*role="status"[^>]*><\/span>/u);
131
+ }
132
+ function anErrorStateIsAnAlertWithItsIconAndRetry() {
133
+ const html = renderToString(_jsx(EmptyState, { kind: "error", icon: _jsx("svg", { "data-drawing": "warning" }), onRetry: () => undefined }));
134
+ expect(html).toMatch(/role="alert"[^>]*data-slot="empty-state"[^>]*data-kind="error"/u);
135
+ expect(html).toMatch(/data-slot="empty-state-icon"[^>]*aria-hidden="true"[^>]*><svg/u);
136
+ expect(html).toMatch(/<h2 [^>]*data-slot="empty-state-title"[^>]*>Couldn&#x27;t load this</u);
137
+ expect(html).toMatch(/<button [^>]*>.*Try again</u);
138
+ }
139
+ function aThemeKeepsItsSelectorQuotes() {
140
+ const theme = defineTheme({
141
+ name: "plum",
142
+ selector: '[data-theme="x"]',
143
+ tokens: { "button-radius": "4px" }
144
+ });
145
+ const html = renderToString(_jsx(ThemeStyle, { theme: theme }));
146
+ expect(html).toContain('[data-theme="x"] {');
147
+ expect(html).not.toContain("&quot;");
148
+ expect(html).toContain("--kumiko-button-radius: 4px;");
149
+ }
150
+ const mapSource = defineMapSource({
151
+ tiles: "/tiles/world.pmtiles",
152
+ glyphs: "/fonts/{fontstack}/{range}.pbf",
153
+ sprite: "/sprites",
154
+ attribution: "© Tiles",
155
+ workerUrl: "/maplibre-worker.js"
156
+ });
157
+ function theMapsAreLoadingFramesWithTheirRegion() {
158
+ const location = renderToString(_jsx(LocationMap, { source: mapSource, label: "Delivery address", value: { latitude: 38.7, longitude: -9.1 }, onChange: () => undefined, loading: "Loading the map" }));
159
+ expect(location).toMatch(/<div data-slot="map" data-state="loading"/u);
160
+ expect(location).toMatch(/data-slot="map-canvas" role="region" aria-label="Delivery address" aria-busy="true"/u);
161
+ expect(location).toContain("Loading the map");
162
+ expect(location).not.toContain('data-slot="map-pin"');
163
+ const markers = renderToString(_jsx(MarkersMap, { source: mapSource, label: "Shops", markers: [{ id: "a", label: "Shop A", latitude: 38.7, longitude: -9.1 }], selectedId: "a" }));
164
+ expect(markers).toMatch(/<div data-slot="map" data-state="loading"/u);
165
+ expect(markers).toMatch(/data-slot="map-canvas" role="region" aria-label="Shops"/u);
166
+ expect(markers).not.toContain("Shop A");
167
+ expect(markers).not.toContain("data-flavor");
168
+ }
169
+ function ReceiveVideo() {
170
+ const job = useMediaJob({ upload: () => Promise.resolve("stored") });
171
+ return _jsx(MediaUpload, { job: job });
172
+ }
173
+ function aMediaUploadIsItsDropZoneAndLoadsNoMediabunny() {
174
+ const html = renderToString(_jsx(ReceiveVideo, {}));
175
+ expect(html).toMatch(/data-slot="file-input-trigger"[^>]*>Choose a file</u);
176
+ expect(html).not.toContain('data-slot="media-upload"');
177
+ expect(html).not.toContain('role="progressbar"');
178
+ const loaded = Object.keys(require.cache).filter((path) => /node_modules[\\/]mediabunny[\\/]/u.test(path));
179
+ expect(loaded).toStrictEqual([]);
180
+ }
94
181
  describe("server render", () => {
95
182
  it("renders tabs with the chosen tab selected and its panel", tabsShowTheChosenTab);
96
183
  it("renders a closed drawer as its trigger alone", aClosedDrawerIsItsTrigger);
@@ -103,4 +190,10 @@ describe("server render", () => {
103
190
  it("renders a table with its rows, links and paging", aTableIsItsRowsAndPaging);
104
191
  it("renders an app shell with its sidebar in place, as the cookie left it", anAppShellIsItsSidebarInPlace);
105
192
  it("renders a page header with every action inline and no menu", aPageHeaderIsEveryActionInline);
193
+ it("renders a form with its labels and no browser globals", aFormIsItsFieldsWithLabels);
194
+ it("renders a cooldown button with a key as idle, with no time and no aria-disabled", aCooldownButtonWithAKeyIsIdle);
195
+ it("renders an error state as an alert with its icon and Try again button", anErrorStateIsAnAlertWithItsIconAndRetry);
196
+ it("renders a theme with its selector's quotes unescaped", aThemeKeepsItsSelectorQuotes);
197
+ it("renders a location map and a markers map as loading frames with their region", theMapsAreLoadingFramesWithTheirRegion);
198
+ it("renders a media upload card as its idle drop zone, with no browser global and no mediabunny loaded", aMediaUploadIsItsDropZoneAndLoadsNoMediabunny);
106
199
  });
@@ -122,14 +122,28 @@ class CaretController {
122
122
  return;
123
123
  }
124
124
  if (this.stillFrames < STILL_FRAMES) {
125
- this.watchFrame = requestAnimationFrame(() => this.followField());
125
+ this.afterPaint();
126
126
  return;
127
127
  }
128
128
  this.watchTimer = window.setTimeout(() => {
129
129
  this.watchTimer = 0;
130
- this.watchFrame = requestAnimationFrame(() => this.followField());
130
+ this.afterPaint();
131
131
  }, STILL_POLL_MS);
132
132
  }
133
+ /*
134
+ * Looks at the field once the next frame has painted. Layout is clean then,
135
+ * so reading the field's box costs nothing, where a read inside the frame
136
+ * forces layout whenever something else on the page has just changed styles.
137
+ */
138
+ afterPaint() {
139
+ this.watchFrame = requestAnimationFrame(() => {
140
+ this.watchFrame = 0;
141
+ this.watchTimer = window.setTimeout(() => {
142
+ this.watchTimer = 0;
143
+ this.followField();
144
+ }, 0);
145
+ });
146
+ }
133
147
  wakeWatch() {
134
148
  this.stillFrames = 0;
135
149
  if (this.watchTimer) {
@@ -139,7 +153,6 @@ class CaretController {
139
153
  }
140
154
  }
141
155
  followField() {
142
- this.watchFrame = 0;
143
156
  const { tracked } = this;
144
157
  if (!tracked || !document.hasFocus() || document.hidden) {
145
158
  return;
@@ -3,6 +3,8 @@ import type { PaginationLabels } from "../pagination";
3
3
  export interface TableLabels {
4
4
  search: string;
5
5
  noResults: string;
6
+ /** The button in the no-results message that empties the search. */
7
+ clearSearch: string;
6
8
  empty: string;
7
9
  loading: string;
8
10
  actions: string;
@@ -1,6 +1,7 @@
1
1
  export const tableLabels = {
2
2
  search: "Search",
3
3
  noResults: "No results",
4
+ clearSearch: "Clear the search",
4
5
  empty: "Nothing here yet",
5
6
  loading: "Loading",
6
7
  actions: "Actions",
@@ -1,6 +1,7 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Button } from "../button";
3
3
  import { Checkbox } from "../checkbox";
4
+ import { EmptyState } from "../empty-state";
4
5
  import { SearchInput } from "../input";
5
6
  import { Skeleton } from "../skeleton";
6
7
  import { BodyRow } from "./table-cells";
@@ -52,10 +53,17 @@ export function Body({ context, empty }) {
52
53
  content = _jsx(SkeletonRows, { columns: columns, view: view, selection: selection });
53
54
  break;
54
55
  case "empty":
55
- content = _jsx(MessageRow, { span: span, children: empty ?? view.words.empty });
56
+ content = (_jsx(MessageRow, { span: span, children: empty ?? _jsx(EmptyState, { size: "inline", kind: "empty", title: view.words.empty }) }));
56
57
  break;
57
58
  case "no-results":
58
- content = _jsx(MessageRow, { span: span, children: view.words.noResults });
59
+ content = (_jsx(MessageRow, { span: span, children: _jsx(EmptyState, { size: "inline", kind: "no-results", title: view.words.noResults, description: null, labels: { clear: view.words.clearSearch }, onClear: (event) => {
60
+ // The Clear button goes away with the empty state, so focus moves to the search box.
61
+ const table = event.currentTarget.closest('[data-slot="table"]');
62
+ view.dispatch({ type: "search", text: "" });
63
+ table
64
+ ?.querySelector('[data-slot="table-toolbar"] input')
65
+ ?.focus();
66
+ } }) }));
59
67
  break;
60
68
  case "rows":
61
69
  content = view.pageRows.map((item) => (_jsx(BodyRow, { context: context, item: item }, item.id)));
@@ -1,4 +1,5 @@
1
1
  @import "../motion/motion.css";
2
+ @import "../empty-state/empty-state.css";
2
3
 
3
4
  @layer kumiko {
4
5
  :where(:root) {
@@ -0,0 +1,38 @@
1
+ import type { KumikoToken } from "./tokens.generated";
2
+ /** One CSS value, or a light and a dark one that flip with `color-scheme`. */
3
+ export type ThemeValue = string | {
4
+ readonly light: string;
5
+ readonly dark: string;
6
+ };
7
+ /** The palette as a token's function sees it: every key is the `var()` that reads that colour. */
8
+ export type Palette<Key extends string = string> = Readonly<Record<Key, string>>;
9
+ export interface ThemeInput<Key extends string = string> {
10
+ /** The palette's prefix, so a colour `ink` is `--<name>-ink`. A CSS identifier. */
11
+ readonly name: string;
12
+ /** Where the theme applies. Defaults to `:root`. */
13
+ readonly selector?: string;
14
+ /**
15
+ * A media query the theme applies under, such as `not (forced-colors: active)` for a theme whose colours
16
+ * should give way to the system ones. Defaults to always.
17
+ */
18
+ readonly media?: string;
19
+ /** Named colours, each one value or a light and dark pair. */
20
+ readonly palette?: Readonly<Record<Key, ThemeValue>>;
21
+ /** Kumiko tokens, without the `--kumiko-` prefix. A function receives the palette. */
22
+ readonly tokens?: Readonly<Partial<Record<KumikoToken, ThemeValue | ((palette: Palette<Key>) => ThemeValue)>>>;
23
+ }
24
+ /** A checked theme, ready for `themeCss` or `<ThemeStyle>`. */
25
+ export interface Theme {
26
+ readonly name: string;
27
+ readonly selector: string;
28
+ readonly media: string | undefined;
29
+ /** Every declaration in output order: the palette first, then the tokens as given. */
30
+ readonly declarations: readonly (readonly [property: string, value: string])[];
31
+ }
32
+ /**
33
+ * Checks a theme and fixes its output order. Throws when a value could close its own rule or the
34
+ * style tag, or when `name` is not a CSS identifier.
35
+ */
36
+ export declare function defineTheme<const Key extends string = never>(input: ThemeInput<Key>): Theme;
37
+ /** The theme as CSS text, in `@layer kumiko` so Kumiko's own defaults and an app's unlayered CSS keep their place. */
38
+ export declare function themeCss(theme: Theme): string;
@@ -0,0 +1,56 @@
1
+ /** True when every colour in the palette has its `var()`, so token functions can read any key they were typed with. */
2
+ function coversPalette(references, palette) {
3
+ return Object.keys(palette).every((key) => key in references);
4
+ }
5
+ const identifier = /^-?[A-Za-z_][\w-]*$/u;
6
+ const unsafe = /[;{}]|<\//u;
7
+ function safe(what, value) {
8
+ if (unsafe.test(value)) {
9
+ throw new Error(`${what} has a value with ";", "{", "}" or "</" in it: ${value}`);
10
+ }
11
+ return value;
12
+ }
13
+ function resolve(what, value) {
14
+ if (typeof value === "string") {
15
+ return safe(what, value);
16
+ }
17
+ return `light-dark(${safe(what, value.light)}, ${safe(what, value.dark)})`;
18
+ }
19
+ /**
20
+ * Checks a theme and fixes its output order. Throws when a value could close its own rule or the
21
+ * style tag, or when `name` is not a CSS identifier.
22
+ */
23
+ export function defineTheme(input) {
24
+ if (!identifier.test(input.name)) {
25
+ throw new Error(`Theme name "${input.name}" is not a CSS identifier`);
26
+ }
27
+ const selector = safe("The selector", input.selector ?? ":root");
28
+ const media = input.media === undefined ? undefined : safe("The media query", input.media);
29
+ const declarations = [];
30
+ const palette = input.palette ?? {};
31
+ const references = {};
32
+ for (const [key, value] of Object.entries(palette)) {
33
+ if (!identifier.test(key)) {
34
+ throw new Error(`Palette key "${key}" is not a CSS identifier`);
35
+ }
36
+ const property = `--${input.name}-${key}`;
37
+ declarations.push([property, resolve(`Palette colour "${key}"`, value)]);
38
+ references[key] = `var(${property})`;
39
+ }
40
+ if (!coversPalette(references, palette)) {
41
+ throw new Error(`Theme "${input.name}" lost a palette colour while reading it`);
42
+ }
43
+ for (const [token, value] of Object.entries(input.tokens ?? {})) {
44
+ const resolved = typeof value === "function" ? value(references) : value;
45
+ declarations.push([`--kumiko-${token}`, resolve(`Token "${token}"`, resolved)]);
46
+ }
47
+ return { name: input.name, selector, media, declarations };
48
+ }
49
+ /** The theme as CSS text, in `@layer kumiko` so Kumiko's own defaults and an app's unlayered CSS keep their place. */
50
+ export function themeCss(theme) {
51
+ const indent = theme.media === undefined ? " " : " ";
52
+ const lines = theme.declarations.map(([property, value]) => `${indent} ${property}: ${value};`);
53
+ const rule = [`${indent}${theme.selector} {`, ...lines, `${indent}}`];
54
+ const body = theme.media === undefined ? rule : [` @media ${theme.media} {`, ...rule, " }"];
55
+ return ["@layer kumiko {", ...body, "}", ""].join("\n");
56
+ }
@@ -0,0 +1,3 @@
1
+ export { defineTheme, themeCss, type Palette, type Theme, type ThemeInput, type ThemeValue } from "./define-theme";
2
+ export { ThemeStyle, type ThemeStyleProps } from "./theme-style";
3
+ export { tokenNames, type KumikoToken } from "./tokens.generated";
@@ -0,0 +1,3 @@
1
+ export { defineTheme, themeCss } from "./define-theme";
2
+ export { ThemeStyle } from "./theme-style";
3
+ export { tokenNames } from "./tokens.generated";
@@ -0,0 +1,6 @@
1
+ import { type Theme } from "./define-theme";
2
+ export interface ThemeStyleProps {
3
+ readonly theme: Theme;
4
+ }
5
+ /** Puts a theme in the page. It renders in a server render too. */
6
+ export declare function ThemeStyle({ theme }: ThemeStyleProps): React.JSX.Element;
@@ -0,0 +1,11 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { themeCss } from "./define-theme";
3
+ /*
4
+ * A plain <style>, not React 19's `<style href precedence>`: that form is keyed by `href`, so a theme
5
+ * whose values change while the page is open would keep its first CSS. The text is safe to inject
6
+ * because `defineTheme` rejects any value that could close the rule or the tag.
7
+ */
8
+ /** Puts a theme in the page. It renders in a server render too. */
9
+ export function ThemeStyle({ theme }) {
10
+ return (_jsx("style", { "data-kumiko-theme": theme.name, dangerouslySetInnerHTML: { __html: themeCss(theme) } }));
11
+ }
@@ -0,0 +1 @@
1
+ export declare function unknownNamesDoNotTypecheck(): void;
@@ -0,0 +1,26 @@
1
+ import { defineTheme } from "./define-theme";
2
+ /*
3
+ * Type tests, checked by `tsc -p packages/kumiko` (`bun run typecheck`): each line below must be a type
4
+ * error. When a line stops being one, the `@ts-expect-error` above it is unused and tsc fails. This
5
+ * function is never called, and the prover can't run tsc, so these have no proofs.
6
+ */
7
+ export function unknownNamesDoNotTypecheck() {
8
+ defineTheme({
9
+ name: "plum",
10
+ tokens: {
11
+ // @ts-expect-error: there is no --kumiko-button-radios token
12
+ "button-radios": "4px"
13
+ }
14
+ });
15
+ defineTheme({
16
+ name: "plum",
17
+ palette: { ink: "#222" },
18
+ tokens: {
19
+ "button-solid-bg": (palette) => {
20
+ // @ts-expect-error: the palette has no key called paper
21
+ const missing = palette.paper;
22
+ return String(missing);
23
+ }
24
+ }
25
+ });
26
+ }
@@ -0,0 +1 @@
1
+ export declare const tokenNames1: readonly ["alert-bar-width", "alert-border-width", "alert-error-color", "alert-error-on", "alert-focus-ring", "alert-font-size", "alert-gap", "alert-glow-size", "alert-glow-strength", "alert-icon-size", "alert-info-color", "alert-info-on", "alert-lamp-size", "alert-lamp-wash", "alert-line-height", "alert-nudge", "alert-padding-block", "alert-padding-inline", "alert-radius", "alert-success-color", "alert-success-on", "alert-text-tint", "alert-title-weight", "alert-warning-color", "alert-warning-on", "alert-wash", "avatar-away", "avatar-busy", "avatar-detail-fg", "avatar-font-weight", "avatar-group-overlap", "avatar-hue-0", "avatar-hue-1", "avatar-hue-2", "avatar-hue-3", "avatar-hue-4", "avatar-hue-5", "avatar-hue-6", "avatar-hue-7", "avatar-label-gap", "avatar-neutral-bg", "avatar-neutral-fg", "avatar-offline", "avatar-online", "avatar-ring", "avatar-ring-width", "avatar-size", "avatar-size-lg", "avatar-size-sm", "avatar-size-xl", "avatar-square-radius", "badge-accent", "badge-bump-scale", "badge-danger", "badge-dot-size", "badge-dot-size-lg", "badge-dot-size-sm", "badge-fg", "badge-font-family", "badge-font-size", "badge-font-size-lg", "badge-font-size-sm", "badge-font-weight", "badge-glow-mix", "badge-glow-size", "badge-height", "badge-height-lg", "badge-height-sm", "badge-info", "badge-neutral", "badge-pulse-duration", "badge-pulse-scale", "badge-soft-letter-spacing", "badge-soft-mix", "badge-success", "badge-warning", "board-badge-bg", "board-badge-fg", "board-card-bg", "board-card-border", "board-card-border-width", "board-card-gap", "board-card-height", "board-card-hover-bg", "board-card-padding", "board-card-radius", "board-card-shadow", "board-cards", "board-cell-height", "board-cell-padding", "board-focus", "board-folded-height", "board-gap", "board-insert-gap", "board-insert-height", "board-lane-bg", "board-lane-cards", "board-lane-width", "board-lift-shadow", "board-radius", "board-row-cards", "board-scroll-inset", "board-scrollbar-thumb", "board-scrollbar-track", "board-selected", "board-selected-ring", "board-slot-bg", "board-slot-border", "board-target-bg", "board-target-ring", "button-angle", "button-border-width", "button-breathe-duration", "button-breathe-min", "button-danger", "button-danger-fg", "button-disabled-opacity", "button-dot-gap", "button-dot-lift", "button-dot-size", "button-dot-stagger", "button-dots-duration", "button-dots-ease", "button-error-ring-width", "button-focus-ring", "button-focus-ring-offset", "button-focus-ring-width", "button-font-family", "button-font-size", "button-font-size-lg", "button-font-size-xs", "button-font-weight", "button-gap", "button-ghost-fg", "button-height", "button-height-lg", "button-height-sm", "button-height-xs", "button-icon-size", "button-icon-size-xs", "button-link-fg", "button-loading-dim", "button-nudge", "button-orbit-color", "button-orbit-duration", "button-orbit-length", "button-orbit-width", "button-outline-border", "button-outline-fg", "button-padding-x", "button-padding-x-lg", "button-padding-x-sm", "button-padding-x-touch", "button-padding-x-xs", "button-pulse-ease", "button-radius", "button-reduced-duration", "button-secondary-bg", "button-secondary-fg", "button-shimmer-color", "button-shimmer-duration", "button-solid-bg", "button-solid-fg", "button-spin-duration", "button-spinner-size", "button-success", "button-success-fg", "button-sweep-ease", "button-tint", "card-add-border", "card-add-border-width", "card-add-fg", "card-add-plus-size", "card-add-plus-thickness", "card-add-soft-bg", "card-banner-gap", "card-banner-padding", "card-bg", "card-brighten-mix", "card-disabled-opacity", "card-edge-color", "card-edge-width", "card-fg", "card-focus-ring", "card-hover-mix", "card-hover-tint", "card-inset-bg", "card-over-color", "card-over-mix", "card-over-ring-mix", "card-over-ring-width", "card-padding", "card-radius", "card-radius-inset", "card-shadow-lift", "card-shadow-raised", "card-shadow-sink", "card-sink-mix", "card-sink-tint", "card-well-bg", "card-well-shadow", "card-well-solid-bg", "checkbox-bg", "checkbox-border", "checkbox-border-width", "checkbox-brush-width", "checkbox-checked-bg", "checkbox-checked-fg", "checkbox-disabled-opacity", "checkbox-focus-ring", "checkbox-line-width", "checkbox-mark-size", "checkbox-radius", "checkbox-size", "checkbox-size-sm", "chip-bg", "chip-border", "chip-border-width", "chip-disabled-opacity", "chip-fg", "chip-focus-ring", "chip-font-size", "chip-font-size-sm", "chip-font-weight", "chip-gap", "chip-height", "chip-height-sm", "chip-icon-size", "chip-outline-width", "chip-padding", "chip-pressed-bg", "chip-pressed-color", "chip-pressed-fg", "chip-tint", "chip-tint-fg", "dialog-backdrop", "dialog-backdrop-blur", "dialog-bg", "dialog-border-width", "dialog-close-size", "dialog-description-size", "dialog-description-weight", "dialog-error-fg", "dialog-fg", "dialog-font-size", "dialog-gap", "dialog-gutter", "dialog-max-width", "dialog-padding", "dialog-radius", "dialog-shadow", "dialog-sheet-max-height", "dialog-title-font", "dialog-title-size", "dialog-title-weight", "dialog-warning-bg", "dialog-warning-fg", "dialog-width", "dialog-width-lg", "dialog-width-sm", "drawer-float-gap", "drawer-focus-ring", "drawer-gap", "drawer-grip-height", "drawer-grip-width", "drawer-max-height", "drawer-padding", "drawer-push", "drawer-room", "drawer-sheet-width", "drawer-width", "empty-state-art-max-size", "empty-state-description-color", "empty-state-description-size", "empty-state-gap", "empty-state-icon-bg", "empty-state-icon-color", "empty-state-icon-size-inline", "empty-state-icon-size-page", "empty-state-measure", "empty-state-min-height", "empty-state-padding-inline", "empty-state-padding-page", "empty-state-text-gap", "empty-state-title-color", "empty-state-title-size-inline", "empty-state-title-size-page", "empty-state-title-weight", "enter-ease", "exit-ease", "fade-duration", "fade-ease", "file-input-bg", "file-input-border", "file-input-border-width", "file-input-compact-padding", "file-input-done", "file-input-focus-ring", "file-input-gap", "file-input-hint-fg", "file-input-hover-bg", "file-input-icon-size", "file-input-item-bg", "file-input-item-radius", "file-input-overlay-bg", "file-input-overlay-blur", "file-input-overlay-z", "file-input-padding", "file-input-preview-size", "file-input-radius", "file-input-trigger-bg", "file-input-trigger-hover-bg", "file-input-trigger-radius", "form-actions-gap", "form-error-color", "form-error-size", "form-gap", "form-group-gap", "form-inline-gap", "form-inline-label-size", "form-inline-label-weight", "form-label-gap", "form-message-gap", "form-required-color", "hover-card-arrow-size", "hover-card-bg", "hover-card-border-width", "hover-card-fg", "hover-card-font-size", "hover-card-max-width", "hover-card-padding", "hover-card-radius", "hover-card-shadow", "hover-card-width", "hover-scale", "hover-tilt", "input-accent", "input-border-width", "input-calm-bg", "input-calm-bg-hover", "input-calm-border", "input-calm-border-hover", "input-calm-font-size", "input-calm-height", "input-calm-inset", "input-calm-padding-block", "input-calm-padding-inline", "input-calm-placeholder", "input-calm-radius", "input-calm-ring-width", "input-calm-shadow", "input-calm-shadow-focus", "input-calm-shadow-hover", "input-clear-hover-bg", "input-clear-pop", "input-clear-size", "input-cozy-bg", "input-cozy-bg-hover", "input-cozy-border", "input-cozy-border-hover", "input-cozy-font-size", "input-cozy-height", "input-cozy-inset", "input-cozy-padding-block", "input-cozy-padding-inline", "input-cozy-placeholder", "input-cozy-radius", "input-cozy-ring", "input-cozy-ring-width", "input-cozy-shadow", "input-cozy-shadow-focus", "input-cozy-shadow-hover", "input-disabled-opacity", "input-fg", "input-field-gap", "input-hint-size", "input-invalid", "input-label-size", "input-label-weight", "input-message-size", "input-muted", "input-raised-bg", "input-raised-bg-hover", "input-raised-border", "input-raised-border-hover", "input-raised-font-size", "input-raised-height", "input-raised-inset", "input-raised-padding-block", "input-raised-padding-inline", "input-raised-placeholder", "input-raised-radius", "input-raised-ring-width", "input-raised-shadow", "input-raised-shadow-focus", "input-raised-shadow-hover", "input-readonly-bg", "input-readonly-border", "input-remote-caret-width", "input-remote-color"];