@mcp-b/react-components 0.67.0 → 0.68.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.
@@ -0,0 +1,39 @@
1
+ import { t as WallpaperOption } from "../../WallpaperPicker-C-FItmDS.js";
2
+ import { ReactNode } from "react";
3
+ //#region src/components/agents-sdk/ComputerCustomWallpaper.d.ts
4
+ /** A person's own background image, prepared for bounded browser storage. */
5
+ export interface CustomWallpaper {
6
+ label: string;
7
+ dataUrl: string;
8
+ fit: "fill" | "fit";
9
+ x: number;
10
+ y: number;
11
+ }
12
+ /** The chosen background, and the person's own image if they added one. */
13
+ export interface ComputerWallpaper {
14
+ value: string;
15
+ custom: CustomWallpaper | null;
16
+ }
17
+ /** A saved background, or null when it names no wallpaper this desktop has. */
18
+ export declare function readWallpaper(value: unknown): ComputerWallpaper | null;
19
+ export interface UseComputerWallpaperOptions {
20
+ /** The saved choice; `readWallpaper` validates one from storage. */
21
+ wallpaper: ComputerWallpaper;
22
+ /** Saves a new choice, including the prepared image and its placement. */
23
+ onChange: (next: ComputerWallpaper) => void;
24
+ /** Where the choice is kept, under the controls. */
25
+ hint: ReactNode;
26
+ }
27
+ /** The desktop background with a person's own image: `AgentComputer`'s wallpaper and Settings' fields. */
28
+ export declare function useComputerWallpaper({ wallpaper, onChange, hint }: UseComputerWallpaperOptions): {
29
+ /** The background the computer shows, for `AgentComputer`'s `wallpaper`. */
30
+ selected: WallpaperOption;
31
+ /** ComputerSettings.Host's wallpaper fields. */
32
+ settings: {
33
+ wallpapers: readonly WallpaperOption[];
34
+ wallpaper: string;
35
+ onWallpaperChange: (next: string) => void;
36
+ display: import("react").JSX.Element;
37
+ };
38
+ };
39
+ //#endregion
@@ -0,0 +1,507 @@
1
+ import { Button } from "../foundations/Button.js";
2
+ import { COMPUTER_WALLPAPERS, DEFAULT_COMPUTER_WALLPAPER } from "./ComputerWallpapers.js";
3
+ import { Slider } from "../foundations/Slider.js";
4
+ import { Radio, RadioGroup } from "../foundations/RadioGroup.js";
5
+ import { c } from "react/compiler-runtime";
6
+ import { useEffect, useEffectEvent, useId, useRef, useState } from "react";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/components/agents-sdk/ComputerCustomWallpaper.tsx
9
+ const JPEG_PREFIX = "data:image/jpeg;base64,";
10
+ const MAX_IMAGE_BYTES = 10485760;
11
+ const MAX_STORED_IMAGE_LENGTH = 75e4;
12
+ function readCustomWallpaper(image) {
13
+ if (!image || typeof image !== "object" || !("label" in image && "dataUrl" in image && "fit" in image && "x" in image && "y" in image) || typeof image.label !== "string" || !image.label.trim() || image.label.length > 240 || typeof image.dataUrl !== "string" || image.dataUrl.length > MAX_STORED_IMAGE_LENGTH || !/^data:image\/jpeg;base64,[a-z0-9+/]+=*$/i.test(image.dataUrl) || image.fit !== "fill" && image.fit !== "fit" || ![image.x, image.y].every((position) => typeof position === "number" && Number.isFinite(position) && position >= 0 && position <= 100)) return null;
14
+ const header = atob(image.dataUrl.slice(23, 31));
15
+ if (header.charCodeAt(0) !== 255 || header.charCodeAt(1) !== 216 || header.charCodeAt(2) !== 255) return null;
16
+ const { label, dataUrl, fit } = image;
17
+ return {
18
+ label,
19
+ dataUrl,
20
+ fit,
21
+ x: image.x,
22
+ y: image.y
23
+ };
24
+ }
25
+ /** A saved background, or null when it names no wallpaper this desktop has. */
26
+ function readWallpaper(value) {
27
+ if (!value || typeof value !== "object" || !("value" in value) || !("custom" in value)) return null;
28
+ const custom = value.custom === null ? null : readCustomWallpaper(value.custom);
29
+ if (value.custom !== null && !custom) return null;
30
+ if (value.value === "custom" ? !custom : !COMPUTER_WALLPAPERS.some((w) => w.value === value.value)) return null;
31
+ return {
32
+ value: value.value,
33
+ custom
34
+ };
35
+ }
36
+ async function prepareWallpaper(file) {
37
+ if (!file.size || file.size > MAX_IMAGE_BYTES) throw new Error("Choose an image smaller than 10 MB.");
38
+ const bytes = new Uint8Array(await file.slice(0, 12).arrayBuffer());
39
+ const isPng = [
40
+ 137,
41
+ 80,
42
+ 78,
43
+ 71,
44
+ 13,
45
+ 10,
46
+ 26,
47
+ 10
48
+ ].every((byte, index) => bytes[index] === byte);
49
+ const isJpeg = bytes[0] === 255 && bytes[1] === 216 && bytes[2] === 255;
50
+ const isWebp = [
51
+ 82,
52
+ 73,
53
+ 70,
54
+ 70
55
+ ].every((byte, index) => bytes[index] === byte) && [
56
+ 87,
57
+ 69,
58
+ 66,
59
+ 80
60
+ ].every((byte, index) => bytes[index + 8] === byte);
61
+ if (!(file.type === "image/png" && isPng || file.type === "image/jpeg" && isJpeg || file.type === "image/webp" && isWebp)) throw new Error("Choose a PNG, JPEG, or WebP image.");
62
+ let bitmap;
63
+ try {
64
+ bitmap = await createImageBitmap(file);
65
+ } catch {
66
+ throw new Error("This image couldn’t be opened. Choose another image.");
67
+ }
68
+ try {
69
+ if (!bitmap.width || !bitmap.height || bitmap.width * bitmap.height > 4e7) throw new Error("Choose an image with fewer than 40 million pixels.");
70
+ const canvas = document.createElement("canvas");
71
+ const context = canvas.getContext("2d");
72
+ if (!context) throw new Error("Your browser couldn’t prepare this image.");
73
+ for (const edge of [
74
+ 1600,
75
+ 1200,
76
+ 800
77
+ ]) {
78
+ const scale = Math.min(1, edge / Math.max(bitmap.width, bitmap.height));
79
+ canvas.width = Math.max(1, Math.round(bitmap.width * scale));
80
+ canvas.height = Math.max(1, Math.round(bitmap.height * scale));
81
+ context.fillStyle = "#171c22";
82
+ context.fillRect(0, 0, canvas.width, canvas.height);
83
+ context.drawImage(bitmap, 0, 0, canvas.width, canvas.height);
84
+ const dataUrl = canvas.toDataURL("image/jpeg", .82);
85
+ if (dataUrl.startsWith(JPEG_PREFIX) && dataUrl.length <= MAX_STORED_IMAGE_LENGTH) return {
86
+ label: file.name.trim().slice(0, 240) || "Custom image",
87
+ dataUrl,
88
+ fit: "fill",
89
+ x: 50,
90
+ y: 50
91
+ };
92
+ }
93
+ throw new Error("This image is too detailed to save. Choose a smaller image.");
94
+ } finally {
95
+ bitmap.close();
96
+ }
97
+ }
98
+ function customOption(image) {
99
+ return {
100
+ value: "custom",
101
+ label: image.label,
102
+ background: `url("${image.dataUrl}") ${image.x}% ${image.y}% / ${image.fit === "fill" ? "cover" : "contain"} no-repeat #171c22`
103
+ };
104
+ }
105
+ /** The desktop background with a person's own image: `AgentComputer`'s wallpaper and Settings' fields. */
106
+ function useComputerWallpaper(t0) {
107
+ const $ = c(78);
108
+ const { wallpaper, onChange, hint } = t0;
109
+ const uploadButtonId = useId();
110
+ const uploadInput = useRef(null);
111
+ const helpId = useId();
112
+ const errorId = useId();
113
+ const uploadRevision = useRef(0);
114
+ const [uploading, setUploading] = useState(false);
115
+ const [uploadError, setUploadError] = useState("");
116
+ const { value, custom: saved } = wallpaper;
117
+ const [position, setPosition] = useState(null);
118
+ let t1;
119
+ if ($[0] !== position || $[1] !== saved) {
120
+ t1 = saved && position?.dataUrl === saved.dataUrl ? {
121
+ ...saved,
122
+ x: position.x ?? saved.x,
123
+ y: position.y ?? saved.y
124
+ } : saved;
125
+ $[0] = position;
126
+ $[1] = saved;
127
+ $[2] = t1;
128
+ } else t1 = $[2];
129
+ const custom = t1;
130
+ const customUrl = saved?.dataUrl;
131
+ let t2;
132
+ if ($[3] !== onChange || $[4] !== value) {
133
+ t2 = () => {
134
+ onChange({
135
+ value: value === "custom" ? DEFAULT_COMPUTER_WALLPAPER : value,
136
+ custom: null
137
+ });
138
+ setUploadError("The saved image couldn’t be opened. Choose a new image.");
139
+ };
140
+ $[3] = onChange;
141
+ $[4] = value;
142
+ $[5] = t2;
143
+ } else t2 = $[5];
144
+ const dropUnreadable = useEffectEvent(t2);
145
+ let t3;
146
+ if ($[6] !== customUrl || $[7] !== dropUnreadable) {
147
+ t3 = () => {
148
+ if (!customUrl) return;
149
+ let active = true;
150
+ const image = new Image();
151
+ image.src = customUrl;
152
+ image.decode().catch(() => {
153
+ if (!active) return;
154
+ dropUnreadable();
155
+ });
156
+ return () => {
157
+ active = false;
158
+ };
159
+ };
160
+ $[6] = customUrl;
161
+ $[7] = dropUnreadable;
162
+ $[8] = t3;
163
+ } else t3 = $[8];
164
+ let t4;
165
+ if ($[9] !== customUrl) {
166
+ t4 = [customUrl];
167
+ $[9] = customUrl;
168
+ $[10] = t4;
169
+ } else t4 = $[10];
170
+ useEffect(t3, t4);
171
+ let t5;
172
+ let t6;
173
+ if ($[11] === Symbol.for("react.memo_cache_sentinel")) {
174
+ t5 = () => () => {
175
+ uploadRevision.current = uploadRevision.current + 1;
176
+ };
177
+ t6 = [];
178
+ $[11] = t5;
179
+ $[12] = t6;
180
+ } else {
181
+ t5 = $[11];
182
+ t6 = $[12];
183
+ }
184
+ useEffect(t5, t6);
185
+ let t7;
186
+ let wallpapers;
187
+ if ($[13] !== custom || $[14] !== value) {
188
+ wallpapers = custom ? [...COMPUTER_WALLPAPERS, customOption(custom)] : COMPUTER_WALLPAPERS;
189
+ let t8;
190
+ if ($[17] !== value) {
191
+ t8 = (wallpaper_0) => wallpaper_0.value === value;
192
+ $[17] = value;
193
+ $[18] = t8;
194
+ } else t8 = $[18];
195
+ t7 = wallpapers.find(t8);
196
+ $[13] = custom;
197
+ $[14] = value;
198
+ $[15] = t7;
199
+ $[16] = wallpapers;
200
+ } else {
201
+ t7 = $[15];
202
+ wallpapers = $[16];
203
+ }
204
+ const selected = t7;
205
+ let t8;
206
+ if ($[19] !== onChange) {
207
+ t8 = function save(next, image_0) {
208
+ setPosition(null);
209
+ onChange({
210
+ value: next,
211
+ custom: image_0
212
+ });
213
+ };
214
+ $[19] = onChange;
215
+ $[20] = t8;
216
+ } else t8 = $[20];
217
+ const save = t8;
218
+ let t9;
219
+ if ($[21] !== save || $[22] !== saved || $[23] !== wallpapers) {
220
+ t9 = function select(next_0) {
221
+ if (!wallpapers.some((wallpaper_1) => wallpaper_1.value === next_0)) return;
222
+ uploadRevision.current = uploadRevision.current + 1;
223
+ setUploading(false);
224
+ save(next_0, saved);
225
+ };
226
+ $[21] = save;
227
+ $[22] = saved;
228
+ $[23] = wallpapers;
229
+ $[24] = t9;
230
+ } else t9 = $[24];
231
+ const select = t9;
232
+ let t10;
233
+ if ($[25] !== save || $[26] !== saved) {
234
+ t10 = function updateCustom(patch, t11) {
235
+ const persist = t11 === void 0 ? true : t11;
236
+ if (!saved) return;
237
+ if (persist) save("custom", {
238
+ ...saved,
239
+ ...patch
240
+ });
241
+ else setPosition((current) => ({
242
+ ...current,
243
+ ...patch,
244
+ dataUrl: saved.dataUrl
245
+ }));
246
+ };
247
+ $[25] = save;
248
+ $[26] = saved;
249
+ $[27] = t10;
250
+ } else t10 = $[27];
251
+ const updateCustom = t10;
252
+ let t11;
253
+ if ($[28] !== save) {
254
+ t11 = async function upload(file) {
255
+ const revision = uploadRevision.current = uploadRevision.current + 1;
256
+ setUploading(true);
257
+ setUploadError("");
258
+ const prepared = await prepareWallpaper(file).then(_temp, _temp2);
259
+ if (revision !== uploadRevision.current) return;
260
+ if ("image" in prepared) save("custom", prepared.image);
261
+ else setUploadError(prepared.error instanceof Error ? prepared.error.message : "This image couldn’t be opened.");
262
+ setUploading(false);
263
+ };
264
+ $[28] = save;
265
+ $[29] = t11;
266
+ } else t11 = $[29];
267
+ const upload = t11;
268
+ const t12 = `${helpId}${uploadError ? ` ${errorId}` : ""}`;
269
+ let t13;
270
+ if ($[30] === Symbol.for("react.memo_cache_sentinel")) {
271
+ t13 = () => uploadInput.current?.click();
272
+ $[30] = t13;
273
+ } else t13 = $[30];
274
+ let t14;
275
+ if ($[31] !== t12 || $[32] !== uploadButtonId || $[33] !== uploading) {
276
+ t14 = /* @__PURE__ */ jsx(Button, {
277
+ id: uploadButtonId,
278
+ size: "xs",
279
+ variant: "surface",
280
+ color: "neutral",
281
+ disabled: uploading,
282
+ "aria-describedby": t12,
283
+ onClick: t13,
284
+ children: "Use your own image…"
285
+ });
286
+ $[31] = t12;
287
+ $[32] = uploadButtonId;
288
+ $[33] = uploading;
289
+ $[34] = t14;
290
+ } else t14 = $[34];
291
+ let t15;
292
+ if ($[35] !== uploading) {
293
+ t15 = uploading ? /* @__PURE__ */ jsx("p", {
294
+ role: "status",
295
+ children: "Preparing background…"
296
+ }) : null;
297
+ $[35] = uploading;
298
+ $[36] = t15;
299
+ } else t15 = $[36];
300
+ let t16;
301
+ if ($[37] !== errorId || $[38] !== uploadError) {
302
+ t16 = uploadError ? /* @__PURE__ */ jsx("p", {
303
+ id: errorId,
304
+ role: "alert",
305
+ children: uploadError
306
+ }) : null;
307
+ $[37] = errorId;
308
+ $[38] = uploadError;
309
+ $[39] = t16;
310
+ } else t16 = $[39];
311
+ let t17;
312
+ if ($[40] !== t14 || $[41] !== t15 || $[42] !== t16) {
313
+ t17 = /* @__PURE__ */ jsxs(Fragment, { children: [
314
+ t14,
315
+ t15,
316
+ t16
317
+ ] });
318
+ $[40] = t14;
319
+ $[41] = t15;
320
+ $[42] = t16;
321
+ $[43] = t17;
322
+ } else t17 = $[43];
323
+ const uploadControls = t17;
324
+ const t18 = Boolean(uploadError);
325
+ const t19 = `${helpId}${uploadError ? ` ${errorId}` : ""}`;
326
+ let t20;
327
+ if ($[44] !== upload) {
328
+ t20 = (event) => {
329
+ const file_0 = event.currentTarget.files?.[0];
330
+ event.currentTarget.value = "";
331
+ if (file_0) upload(file_0);
332
+ };
333
+ $[44] = upload;
334
+ $[45] = t20;
335
+ } else t20 = $[45];
336
+ let t21;
337
+ if ($[46] !== t18 || $[47] !== t19 || $[48] !== t20 || $[49] !== uploadButtonId || $[50] !== uploading) {
338
+ t21 = /* @__PURE__ */ jsx("input", {
339
+ ref: uploadInput,
340
+ hidden: true,
341
+ "aria-labelledby": uploadButtonId,
342
+ type: "file",
343
+ accept: "image/png,image/jpeg,image/webp",
344
+ disabled: uploading,
345
+ "aria-invalid": t18,
346
+ "aria-describedby": t19,
347
+ onChange: t20
348
+ });
349
+ $[46] = t18;
350
+ $[47] = t19;
351
+ $[48] = t20;
352
+ $[49] = uploadButtonId;
353
+ $[50] = uploading;
354
+ $[51] = t21;
355
+ } else t21 = $[51];
356
+ let t22;
357
+ if ($[52] !== helpId) {
358
+ t22 = /* @__PURE__ */ jsx("p", {
359
+ id: helpId,
360
+ className: "sigvelo-visually-hidden",
361
+ children: "PNG, JPEG, or WebP, up to 10 MB. Images are dimmed to keep desktop labels readable."
362
+ });
363
+ $[52] = helpId;
364
+ $[53] = t22;
365
+ } else t22 = $[53];
366
+ let t23;
367
+ if ($[54] !== custom || $[55] !== save || $[56] !== updateCustom || $[57] !== uploadButtonId || $[58] !== value) {
368
+ t23 = custom ? /* @__PURE__ */ jsxs("section", {
369
+ className: "computer-wallpapers__custom",
370
+ "aria-label": "Custom background",
371
+ children: [value === "custom" ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsxs(RadioGroup.Root, {
372
+ className: "computer-wallpapers__placement",
373
+ value: custom.fit,
374
+ onValueChange: (fit) => {
375
+ if (fit === "fill" || fit === "fit") updateCustom({ fit });
376
+ },
377
+ "aria-label": "Image placement",
378
+ children: [/* @__PURE__ */ jsxs("label", {
379
+ className: "computer-wallpapers__choice",
380
+ children: [/* @__PURE__ */ jsx(Radio.Root, {
381
+ value: "fill",
382
+ children: /* @__PURE__ */ jsx(Radio.Indicator, {})
383
+ }), "Fill the screen (crop edges)"]
384
+ }), /* @__PURE__ */ jsxs("label", {
385
+ className: "computer-wallpapers__choice",
386
+ children: [/* @__PURE__ */ jsx(Radio.Root, {
387
+ value: "fit",
388
+ children: /* @__PURE__ */ jsx(Radio.Indicator, {})
389
+ }), "Fit the entire image"]
390
+ })]
391
+ }), /* @__PURE__ */ jsx("div", {
392
+ className: "computer-wallpapers__crop",
393
+ children: ["x", "y"].map((axis) => /* @__PURE__ */ jsxs(Slider.Root, {
394
+ value: custom[axis],
395
+ min: 0,
396
+ max: 100,
397
+ step: 1,
398
+ onValueChange: (position_0) => updateCustom({ [axis]: position_0 }, false),
399
+ onValueCommitted: (position_1) => updateCustom({ [axis]: position_1 }),
400
+ children: [/* @__PURE__ */ jsxs("div", {
401
+ className: "computer-wallpapers__crop-label",
402
+ children: [/* @__PURE__ */ jsx(Slider.Label, { children: axis === "x" ? "Horizontal position" : "Vertical position" }), /* @__PURE__ */ jsxs("span", { children: [custom[axis], "%"] })]
403
+ }), /* @__PURE__ */ jsx(Slider.Control, {
404
+ className: "computer-wallpapers__crop-control",
405
+ children: /* @__PURE__ */ jsxs(Slider.Track, { children: [/* @__PURE__ */ jsx(Slider.Indicator, {}), /* @__PURE__ */ jsx(Slider.Thumb, {})] })
406
+ })]
407
+ }, axis))
408
+ })] }) : null, /* @__PURE__ */ jsxs("div", {
409
+ className: "computer-wallpapers__actions",
410
+ children: [value === "custom" ? /* @__PURE__ */ jsx(Button, {
411
+ variant: "surface",
412
+ color: "neutral",
413
+ onClick: () => updateCustom({
414
+ x: 50,
415
+ y: 50
416
+ }),
417
+ children: "Center image"
418
+ }) : null, /* @__PURE__ */ jsx(Button, {
419
+ variant: "surface",
420
+ color: "neutral",
421
+ onClick: () => {
422
+ uploadRevision.current = uploadRevision.current + 1;
423
+ setUploading(false);
424
+ setUploadError("");
425
+ save(DEFAULT_COMPUTER_WALLPAPER, null);
426
+ requestAnimationFrame(() => uploadInput.current?.ownerDocument.getElementById(uploadButtonId)?.focus());
427
+ },
428
+ children: "Remove custom image"
429
+ })]
430
+ })]
431
+ }) : null;
432
+ $[54] = custom;
433
+ $[55] = save;
434
+ $[56] = updateCustom;
435
+ $[57] = uploadButtonId;
436
+ $[58] = value;
437
+ $[59] = t23;
438
+ } else t23 = $[59];
439
+ let t24;
440
+ if ($[60] !== hint) {
441
+ t24 = /* @__PURE__ */ jsx("p", {
442
+ className: "computer-wallpapers__hint",
443
+ role: "status",
444
+ children: hint
445
+ });
446
+ $[60] = hint;
447
+ $[61] = t24;
448
+ } else t24 = $[61];
449
+ let t25;
450
+ if ($[62] !== t21 || $[63] !== t22 || $[64] !== t23 || $[65] !== t24) {
451
+ t25 = /* @__PURE__ */ jsxs(Fragment, { children: [
452
+ t21,
453
+ t22,
454
+ t23,
455
+ t24
456
+ ] });
457
+ $[62] = t21;
458
+ $[63] = t22;
459
+ $[64] = t23;
460
+ $[65] = t24;
461
+ $[66] = t25;
462
+ } else t25 = $[66];
463
+ const details = t25;
464
+ let t26;
465
+ if ($[67] !== details || $[68] !== uploadControls) {
466
+ t26 = /* @__PURE__ */ jsxs("div", {
467
+ className: "computer-wallpapers__controls",
468
+ children: [uploadControls, details]
469
+ });
470
+ $[67] = details;
471
+ $[68] = uploadControls;
472
+ $[69] = t26;
473
+ } else t26 = $[69];
474
+ let t27;
475
+ if ($[70] !== select || $[71] !== t26 || $[72] !== value || $[73] !== wallpapers) {
476
+ t27 = {
477
+ wallpapers,
478
+ wallpaper: value,
479
+ onWallpaperChange: select,
480
+ display: t26
481
+ };
482
+ $[70] = select;
483
+ $[71] = t26;
484
+ $[72] = value;
485
+ $[73] = wallpapers;
486
+ $[74] = t27;
487
+ } else t27 = $[74];
488
+ let t28;
489
+ if ($[75] !== selected || $[76] !== t27) {
490
+ t28 = {
491
+ selected,
492
+ settings: t27
493
+ };
494
+ $[75] = selected;
495
+ $[76] = t27;
496
+ $[77] = t28;
497
+ } else t28 = $[77];
498
+ return t28;
499
+ }
500
+ function _temp2(error) {
501
+ return { error };
502
+ }
503
+ function _temp(image_1) {
504
+ return { image: image_1 };
505
+ }
506
+ //#endregion
507
+ export { readWallpaper, useComputerWallpaper };
@@ -0,0 +1,15 @@
1
+ import { y as WorkspaceSource } from "../../Workspace-B9nuTfIi.js";
2
+ import { FileInfo } from "@cloudflare/shell";
3
+ //#region src/components/agents-sdk/ComputerFileThumbnail.d.ts
4
+ export interface ComputerFileThumbnailProps {
5
+ entry: FileInfo;
6
+ source: WorkspaceSource;
7
+ sourceKey: string;
8
+ }
9
+ /**
10
+ * A desktop or Finder thumbnail drawn from the file itself, the way Finder
11
+ * draws one: an SVG shows as the image, a text file as a page of its text.
12
+ * Other files draw nothing and keep their type's icon.
13
+ */
14
+ export declare function ComputerFileThumbnail({ entry, source, sourceKey }: ComputerFileThumbnailProps): import("react").JSX.Element | null;
15
+ //#endregion
@@ -0,0 +1,133 @@
1
+ import { workspaceFileQueryKey } from "./Workspace.js";
2
+ import { c } from "react/compiler-runtime";
3
+ import { jsx, jsxs } from "react/jsx-runtime";
4
+ import { useQuery } from "@tanstack/react-query";
5
+ //#region src/components/agents-sdk/ComputerFileThumbnail.tsx
6
+ /** Files small enough to read for a decoration: an SVG as the image, a text file as its page. */
7
+ const MAX_SVG_BYTES = 1048576;
8
+ const MAX_TEXT_BYTES = 65536;
9
+ const PAGE_CHARACTERS = 2048;
10
+ function thumbnailKind(entry) {
11
+ if (entry.type !== "file") return null;
12
+ if (entry.mimeType === "image/svg+xml") return entry.size <= MAX_SVG_BYTES ? "svg" : null;
13
+ return (entry.mimeType.startsWith("text/") || entry.mimeType === "application/json" || entry.mimeType === "application/javascript") && entry.size <= MAX_TEXT_BYTES ? "text" : null;
14
+ }
15
+ /**
16
+ * A desktop or Finder thumbnail drawn from the file itself, the way Finder
17
+ * draws one: an SVG shows as the image, a text file as a page of its text.
18
+ * Other files draw nothing and keep their type's icon.
19
+ */
20
+ function ComputerFileThumbnail(t0) {
21
+ const $ = c(29);
22
+ const { entry, source, sourceKey } = t0;
23
+ let t1;
24
+ if ($[0] !== entry) {
25
+ t1 = thumbnailKind(entry);
26
+ $[0] = entry;
27
+ $[1] = t1;
28
+ } else t1 = $[1];
29
+ const kind = t1;
30
+ let t2;
31
+ if ($[2] !== entry.path || $[3] !== entry.size || $[4] !== entry.updatedAt || $[5] !== sourceKey) {
32
+ t2 = [
33
+ ...workspaceFileQueryKey(sourceKey, "/", entry.path),
34
+ "thumbnail",
35
+ entry.updatedAt,
36
+ entry.size
37
+ ];
38
+ $[2] = entry.path;
39
+ $[3] = entry.size;
40
+ $[4] = entry.updatedAt;
41
+ $[5] = sourceKey;
42
+ $[6] = t2;
43
+ } else t2 = $[6];
44
+ let t3;
45
+ if ($[7] !== entry.path || $[8] !== source) {
46
+ t3 = () => source.readFile(entry.path);
47
+ $[7] = entry.path;
48
+ $[8] = source;
49
+ $[9] = t3;
50
+ } else t3 = $[9];
51
+ const t4 = kind !== null;
52
+ let t5;
53
+ if ($[10] !== t2 || $[11] !== t3 || $[12] !== t4) {
54
+ t5 = {
55
+ queryKey: t2,
56
+ queryFn: t3,
57
+ enabled: t4,
58
+ staleTime: Infinity,
59
+ retry: false
60
+ };
61
+ $[10] = t2;
62
+ $[11] = t3;
63
+ $[12] = t4;
64
+ $[13] = t5;
65
+ } else t5 = $[13];
66
+ const content = useQuery(t5).data;
67
+ if (!kind || !content) return null;
68
+ if (kind === "svg") {
69
+ const t6 = `data:image/svg+xml,${encodeURIComponent(content)}`;
70
+ let t7;
71
+ if ($[14] !== t6) {
72
+ t7 = /* @__PURE__ */ jsx("img", {
73
+ src: t6,
74
+ alt: "",
75
+ width: "64",
76
+ height: "64"
77
+ });
78
+ $[14] = t6;
79
+ $[15] = t7;
80
+ } else t7 = $[15];
81
+ return t7;
82
+ }
83
+ let lines;
84
+ let t6;
85
+ let t7;
86
+ if ($[16] !== content) {
87
+ const [t8, ...t9] = content.slice(0, PAGE_CHARACTERS).split("\n");
88
+ lines = t9;
89
+ const title = t8 === void 0 ? "" : t8;
90
+ t7 = "computer-file-thumbnail";
91
+ let t10;
92
+ if ($[20] === Symbol.for("react.memo_cache_sentinel")) {
93
+ t10 = /^# /;
94
+ $[20] = t10;
95
+ } else t10 = $[20];
96
+ t6 = title.replace(t10, "");
97
+ $[16] = content;
98
+ $[17] = lines;
99
+ $[18] = t6;
100
+ $[19] = t7;
101
+ } else {
102
+ lines = $[17];
103
+ t6 = $[18];
104
+ t7 = $[19];
105
+ }
106
+ let t8;
107
+ if ($[21] !== t6) {
108
+ t8 = /* @__PURE__ */ jsx("strong", { children: t6 });
109
+ $[21] = t6;
110
+ $[22] = t8;
111
+ } else t8 = $[22];
112
+ const t9 = lines.join("\n");
113
+ let t10;
114
+ if ($[23] !== t9) {
115
+ t10 = /* @__PURE__ */ jsx("span", { children: t9 });
116
+ $[23] = t9;
117
+ $[24] = t10;
118
+ } else t10 = $[24];
119
+ let t11;
120
+ if ($[25] !== t10 || $[26] !== t7 || $[27] !== t8) {
121
+ t11 = /* @__PURE__ */ jsxs("span", {
122
+ className: t7,
123
+ children: [t8, t10]
124
+ });
125
+ $[25] = t10;
126
+ $[26] = t7;
127
+ $[27] = t8;
128
+ $[28] = t11;
129
+ } else t11 = $[28];
130
+ return t11;
131
+ }
132
+ //#endregion
133
+ export { ComputerFileThumbnail };
@@ -564,3 +564,34 @@
564
564
  line-height: var(--sigvelo-leading-loose);
565
565
  color: var(--sigvelo-color-text-muted);
566
566
  }
567
+
568
+ /* A desktop icon's thumbnail: a picture of a document, not a document. Every
569
+ length here is off the ramp on purpose — a 4px body and a 50x64 page are a
570
+ drawing of a text file at icon scale, the way Finder draws one, and there is
571
+ no step on the type scale below 11px to draw it with. The colours are the
572
+ theme's, so it still turns with the appearance. */
573
+ .computer-file-thumbnail {
574
+ display: flex;
575
+ flex-direction: column;
576
+ gap: var(--sigvelo-spacing-1);
577
+ inline-size: 50px;
578
+ block-size: 64px;
579
+ padding: 8px 6px;
580
+ overflow: hidden;
581
+ background: var(--sigvelo-color-surface-raised);
582
+ color: var(--sigvelo-color-text);
583
+ border-radius: var(--sigvelo-radius-sm);
584
+ box-shadow: var(--sigvelo-elevation-raised);
585
+ /* A page drawn at 40% of the smallest text: 4px. */
586
+ font-size: calc(var(--sigvelo-text-3xs) * 0.4);
587
+ line-height: var(--sigvelo-leading-normal);
588
+ text-align: start;
589
+ white-space: pre-wrap;
590
+ }
591
+ .computer-file-thumbnail strong {
592
+ font-size: 1.5em;
593
+ }
594
+ /* A row draws the desktop's page thumbnail at row scale, as Finder's list does. */
595
+ .computer-finder .workspace-browser__entries[data-layout="list"] .computer-file-thumbnail {
596
+ zoom: 0.3;
597
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcp-b/react-components",
3
- "version": "0.67.0",
3
+ "version": "0.68.0",
4
4
  "description": "MCP-B React components built on Base UI and shared design tokens, including Cloudflare Think chat primitives.",
5
5
  "homepage": "https://design-system.sigvelo.com",
6
6
  "bugs": {
@@ -55,7 +55,7 @@
55
55
  "streamdown": "^2.7.0",
56
56
  "unist-util-visit": "^5.1.0",
57
57
  "yet-another-react-lightbox": "^3.32.2",
58
- "@mcp-b/design-tokens": "0.67.0"
58
+ "@mcp-b/design-tokens": "0.68.0"
59
59
  },
60
60
  "devDependencies": {
61
61
  "@ai-sdk/react": "^4.0.136",