@surfaces-ui/components 0.4.0 → 0.6.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.
package/dist/styles.css CHANGED
@@ -2968,6 +2968,56 @@ select.sf-input:disabled {
2968
2968
  margin-block: var(--sf-space-2);
2969
2969
  border-radius: var(--sf-radius);
2970
2970
  }
2971
+ /* The catalog's Image: a picture the host found an address for, or its description in a dashed box. */
2972
+ .sf-image {
2973
+ display: grid;
2974
+ gap: var(--sf-space-2);
2975
+ justify-items: start;
2976
+ max-width: min(100%, var(--sf-image-width, 100%));
2977
+ margin: 0;
2978
+ }
2979
+
2980
+ .sf-image-body {
2981
+ display: block;
2982
+ max-width: 100%;
2983
+ height: auto;
2984
+ max-height: var(--sf-image-max-height, none);
2985
+ border-radius: var(--sf-radius);
2986
+ object-fit: contain;
2987
+ }
2988
+
2989
+ .sf-image[data-fixed] .sf-image-body,
2990
+ .sf-image[data-fixed] .sf-image-missing {
2991
+ width: 100%;
2992
+ height: var(--sf-image-height);
2993
+ }
2994
+
2995
+ .sf-image[data-fit="cover"] .sf-image-body {
2996
+ object-fit: cover;
2997
+ }
2998
+
2999
+ .sf-image-missing {
3000
+ display: grid;
3001
+ place-items: center;
3002
+ box-sizing: border-box;
3003
+ width: 100%;
3004
+ min-height: calc(var(--sf-space-8) * 2);
3005
+ max-height: var(--sf-image-max-height, none);
3006
+ padding: var(--sf-space-4);
3007
+ border: 1px dashed var(--sf-color-border);
3008
+ border-radius: var(--sf-radius);
3009
+ background: var(--sf-color-bg-3);
3010
+ color: var(--sf-color-muted);
3011
+ font-size: var(--sf-font-size-sm);
3012
+ text-align: center;
3013
+ overflow: hidden;
3014
+ }
3015
+
3016
+ .sf-image figcaption {
3017
+ color: var(--sf-color-muted);
3018
+ font-size: var(--sf-font-size-sm);
3019
+ }
3020
+
2971
3021
  .sf-markdown > * {
2972
3022
  margin: 0;
2973
3023
  }
@@ -3024,7 +3074,7 @@ select.sf-input:disabled {
3024
3074
  }
3025
3075
 
3026
3076
  .sf-markdown-table:focus-visible {
3027
- outline: 2px solid var(--sf-color-focus, var(--sf-color-accent));
3077
+ outline: 2px solid var(--sf-color-focus);
3028
3078
  outline-offset: 2px;
3029
3079
  }
3030
3080
 
@@ -3671,6 +3721,25 @@ select.sf-input:disabled {
3671
3721
  color: var(--sf-color-danger);
3672
3722
  }
3673
3723
 
3724
+ /* A picture attached to a message: a small thumbnail in the chip, the file's name beside it. */
3725
+ .sf-chat-reference[data-kind="attachment"] {
3726
+ font-family: var(--sf-font);
3727
+ }
3728
+
3729
+ .sf-chat-reference[data-thumbnail] {
3730
+ padding-inline-start: var(--sf-space-1);
3731
+ }
3732
+
3733
+ .sf-chat-thumbnail {
3734
+ flex: none;
3735
+ box-sizing: border-box;
3736
+ width: var(--sf-control-size);
3737
+ height: var(--sf-control-size);
3738
+ border-radius: var(--sf-radius-sm);
3739
+ object-fit: cover;
3740
+ background: var(--sf-color-bg-3);
3741
+ }
3742
+
3674
3743
  /* What a message is about that is not data reads as words, not a name. */
3675
3744
  .sf-chat-reference[data-kind="context"] {
3676
3745
  font-family: var(--sf-font);
@@ -4285,6 +4354,48 @@ select.sf-input:disabled {
4285
4354
  margin-inline-start: auto;
4286
4355
  }
4287
4356
 
4357
+ .sf-a2-conversation {
4358
+ display: grid;
4359
+ gap: var(--sf-space-3);
4360
+ min-inline-size: 0;
4361
+ }
4362
+
4363
+ .sf-a2-conversation-thread {
4364
+ display: grid;
4365
+ align-content: start;
4366
+ gap: var(--sf-space-3);
4367
+ max-block-size: 32rem;
4368
+ overflow-y: auto;
4369
+ overscroll-behavior: contain;
4370
+ padding: var(--sf-space-1);
4371
+ border-radius: var(--sf-radius-md);
4372
+ }
4373
+
4374
+ .sf-a2-conversation-thread:focus-visible {
4375
+ outline: 2px solid var(--sf-color-focus);
4376
+ outline-offset: 2px;
4377
+ }
4378
+
4379
+ .sf-a2-conversation-waiting {
4380
+ margin: 0;
4381
+ color: var(--sf-color-muted);
4382
+ font-size: var(--sf-font-size-sm);
4383
+ }
4384
+
4385
+ .sf-a2-conversation-composer {
4386
+ display: flex;
4387
+ gap: var(--sf-space-2);
4388
+ align-items: end;
4389
+ }
4390
+
4391
+ .sf-a2-conversation-composer > textarea {
4392
+ flex: 1;
4393
+ min-inline-size: 0;
4394
+ resize: vertical;
4395
+ field-sizing: content;
4396
+ max-block-size: 10rem;
4397
+ }
4398
+
4288
4399
  .sf-a2-message-who {
4289
4400
  display: flex;
4290
4401
  flex-wrap: wrap;
@@ -6205,6 +6316,9 @@ select.sf-input:disabled {
6205
6316
  display: flex;
6206
6317
  flex-direction: column;
6207
6318
  align-items: center;
6319
+ /* Both ways: the button is at least a touch target wide and tall, and its icon sits in the middle of that, whether
6320
+ the rail runs down the side (a column) or across the top of a narrow workspace (a row). */
6321
+ justify-content: center;
6208
6322
  gap: var(--sf-space-1);
6209
6323
  min-width: var(--sf-target-min);
6210
6324
  min-height: var(--sf-target-min);
@@ -6576,7 +6690,8 @@ select.sf-input:disabled {
6576
6690
  /* Folded away, the panel waits off the left edge of its stage and slides in when the menu button is pressed: a drawer
6577
6691
  beside a dimmed page where there is room, the whole stage where there is not. The stage is the window, or the part
6578
6692
  on screen of the region the navigation is drawn in (measured when it opens, since a fixed box cannot be told its
6579
- container in CSS), and it clips the drawer, so nothing outside that region is covered even while it slides. Hover
6693
+ container in CSS; the offsets are counted from the stage's own containing block, which a contained or
6694
+ transformed holder is, so they are not always the window's), and it clips the drawer, so nothing outside that region is covered even while it slides. Hover
6580
6695
  and focus do not open it: a drawer that opened under a passing pointer would cover the page by surprise. */
6581
6696
  .sf-sidenav[data-pinned="false"] .sf-sidenav-stage {
6582
6697
  display: block;
@@ -2970,6 +2970,56 @@ select.sf-input:disabled {
2970
2970
  margin-block: var(--sf-space-2);
2971
2971
  border-radius: var(--sf-radius);
2972
2972
  }
2973
+ /* The catalog's Image: a picture the host found an address for, or its description in a dashed box. */
2974
+ .sf-image {
2975
+ display: grid;
2976
+ gap: var(--sf-space-2);
2977
+ justify-items: start;
2978
+ max-width: min(100%, var(--sf-image-width, 100%));
2979
+ margin: 0;
2980
+ }
2981
+
2982
+ .sf-image-body {
2983
+ display: block;
2984
+ max-width: 100%;
2985
+ height: auto;
2986
+ max-height: var(--sf-image-max-height, none);
2987
+ border-radius: var(--sf-radius);
2988
+ object-fit: contain;
2989
+ }
2990
+
2991
+ .sf-image[data-fixed] .sf-image-body,
2992
+ .sf-image[data-fixed] .sf-image-missing {
2993
+ width: 100%;
2994
+ height: var(--sf-image-height);
2995
+ }
2996
+
2997
+ .sf-image[data-fit="cover"] .sf-image-body {
2998
+ object-fit: cover;
2999
+ }
3000
+
3001
+ .sf-image-missing {
3002
+ display: grid;
3003
+ place-items: center;
3004
+ box-sizing: border-box;
3005
+ width: 100%;
3006
+ min-height: calc(var(--sf-space-8) * 2);
3007
+ max-height: var(--sf-image-max-height, none);
3008
+ padding: var(--sf-space-4);
3009
+ border: 1px dashed var(--sf-color-border);
3010
+ border-radius: var(--sf-radius);
3011
+ background: var(--sf-color-bg-3);
3012
+ color: var(--sf-color-muted);
3013
+ font-size: var(--sf-font-size-sm);
3014
+ text-align: center;
3015
+ overflow: hidden;
3016
+ }
3017
+
3018
+ .sf-image figcaption {
3019
+ color: var(--sf-color-muted);
3020
+ font-size: var(--sf-font-size-sm);
3021
+ }
3022
+
2973
3023
  .sf-markdown > * {
2974
3024
  margin: 0;
2975
3025
  }
@@ -3026,7 +3076,7 @@ select.sf-input:disabled {
3026
3076
  }
3027
3077
 
3028
3078
  .sf-markdown-table:focus-visible {
3029
- outline: 2px solid var(--sf-color-focus, var(--sf-color-accent));
3079
+ outline: 2px solid var(--sf-color-focus);
3030
3080
  outline-offset: 2px;
3031
3081
  }
3032
3082
 
@@ -3673,6 +3723,25 @@ select.sf-input:disabled {
3673
3723
  color: var(--sf-color-danger);
3674
3724
  }
3675
3725
 
3726
+ /* A picture attached to a message: a small thumbnail in the chip, the file's name beside it. */
3727
+ .sf-chat-reference[data-kind="attachment"] {
3728
+ font-family: var(--sf-font);
3729
+ }
3730
+
3731
+ .sf-chat-reference[data-thumbnail] {
3732
+ padding-inline-start: var(--sf-space-1);
3733
+ }
3734
+
3735
+ .sf-chat-thumbnail {
3736
+ flex: none;
3737
+ box-sizing: border-box;
3738
+ width: var(--sf-control-size);
3739
+ height: var(--sf-control-size);
3740
+ border-radius: var(--sf-radius-sm);
3741
+ object-fit: cover;
3742
+ background: var(--sf-color-bg-3);
3743
+ }
3744
+
3676
3745
  /* What a message is about that is not data reads as words, not a name. */
3677
3746
  .sf-chat-reference[data-kind="context"] {
3678
3747
  font-family: var(--sf-font);
@@ -4287,6 +4356,48 @@ select.sf-input:disabled {
4287
4356
  margin-inline-start: auto;
4288
4357
  }
4289
4358
 
4359
+ .sf-a2-conversation {
4360
+ display: grid;
4361
+ gap: var(--sf-space-3);
4362
+ min-inline-size: 0;
4363
+ }
4364
+
4365
+ .sf-a2-conversation-thread {
4366
+ display: grid;
4367
+ align-content: start;
4368
+ gap: var(--sf-space-3);
4369
+ max-block-size: 32rem;
4370
+ overflow-y: auto;
4371
+ overscroll-behavior: contain;
4372
+ padding: var(--sf-space-1);
4373
+ border-radius: var(--sf-radius-md);
4374
+ }
4375
+
4376
+ .sf-a2-conversation-thread:focus-visible {
4377
+ outline: 2px solid var(--sf-color-focus);
4378
+ outline-offset: 2px;
4379
+ }
4380
+
4381
+ .sf-a2-conversation-waiting {
4382
+ margin: 0;
4383
+ color: var(--sf-color-muted);
4384
+ font-size: var(--sf-font-size-sm);
4385
+ }
4386
+
4387
+ .sf-a2-conversation-composer {
4388
+ display: flex;
4389
+ gap: var(--sf-space-2);
4390
+ align-items: end;
4391
+ }
4392
+
4393
+ .sf-a2-conversation-composer > textarea {
4394
+ flex: 1;
4395
+ min-inline-size: 0;
4396
+ resize: vertical;
4397
+ field-sizing: content;
4398
+ max-block-size: 10rem;
4399
+ }
4400
+
4290
4401
  .sf-a2-message-who {
4291
4402
  display: flex;
4292
4403
  flex-wrap: wrap;
@@ -6207,6 +6318,9 @@ select.sf-input:disabled {
6207
6318
  display: flex;
6208
6319
  flex-direction: column;
6209
6320
  align-items: center;
6321
+ /* Both ways: the button is at least a touch target wide and tall, and its icon sits in the middle of that, whether
6322
+ the rail runs down the side (a column) or across the top of a narrow workspace (a row). */
6323
+ justify-content: center;
6210
6324
  gap: var(--sf-space-1);
6211
6325
  min-width: var(--sf-target-min);
6212
6326
  min-height: var(--sf-target-min);
@@ -6578,7 +6692,8 @@ select.sf-input:disabled {
6578
6692
  /* Folded away, the panel waits off the left edge of its stage and slides in when the menu button is pressed: a drawer
6579
6693
  beside a dimmed page where there is room, the whole stage where there is not. The stage is the window, or the part
6580
6694
  on screen of the region the navigation is drawn in (measured when it opens, since a fixed box cannot be told its
6581
- container in CSS), and it clips the drawer, so nothing outside that region is covered even while it slides. Hover
6695
+ container in CSS; the offsets are counted from the stage's own containing block, which a contained or
6696
+ transformed holder is, so they are not always the window's), and it clips the drawer, so nothing outside that region is covered even while it slides. Hover
6582
6697
  and focus do not open it: a drawer that opened under a passing pointer would cover the page by surprise. */
6583
6698
  .sf-sidenav[data-pinned="false"] .sf-sidenav-stage {
6584
6699
  display: block;
@@ -0,0 +1,50 @@
1
+ import { type ReactNode } from "react";
2
+ /**
3
+ * Turns the name or address an image was given into the address to draw, or nothing. The host owns it: it is the
4
+ * only way an address reaches an `<img>` for text or a catalog component an agent wrote.
5
+ */
6
+ export type ImageResolver = (src: string) => string | undefined;
7
+ /**
8
+ * Says, once for everything below it, how an image an agent named is turned into an address: the catalog's `Image`
9
+ * and the images in `Markdown` (`![alt](src)`) both ask it, unless they are given a `resolveImage` of their own.
10
+ * `SurfaceView` takes `resolveImage` and provides it, so a host with one surface needs no provider.
11
+ */
12
+ export declare function ImageResolverProvider({ resolve, children }: {
13
+ resolve: ImageResolver | undefined;
14
+ children: ReactNode;
15
+ }): import("react").JSX.Element;
16
+ /** The resolver a host provided above, if any. */
17
+ export declare function useImageResolver(): ImageResolver | undefined;
18
+ /**
19
+ * Whether an address may be drawn as an image: http(s), a `blob:` the host made from a file, a raster `data:image/`,
20
+ * or a path on the same origin (`/files/1.png`). Never a script, `file:` or a protocol-relative address. Used for
21
+ * what a host's resolver returned and for a preview a host supplies; never for text an agent wrote.
22
+ */
23
+ export declare function safeImageAddress(value: string | undefined): string | undefined;
24
+ /** The address to draw for an image the text or an agent gave, or nothing: the host's resolver is the only source. */
25
+ export declare function resolveImageAddress(resolve: ImageResolver | undefined, src: string): string | undefined;
26
+ export type ImageFit = "contain" | "cover";
27
+ export interface ImageProps {
28
+ /** What the image is called: the name or address the text or agent gave. It is never loaded as written; the resolver turns it into the address to draw. */
29
+ src: string;
30
+ /** What it shows, for anyone who cannot see it. Required; shown in its place when there is no address. An empty string marks decoration. */
31
+ alt: string;
32
+ caption?: ReactNode;
33
+ /** The most the image is wide, in pixels. It never grows past its container. */
34
+ width?: number;
35
+ /** A fixed height in pixels; the image then fills the box by `fit`. */
36
+ height?: number;
37
+ /** How a fixed box is filled: whole (`contain`, the default) or edge to edge, cropped (`cover`). */
38
+ fit?: ImageFit;
39
+ /** The most the image is tall, in pixels. */
40
+ maxHeight?: number;
41
+ /** Overrides the resolver provided above (`ImageResolverProvider`). */
42
+ resolveImage?: ImageResolver;
43
+ className?: string;
44
+ }
45
+ /**
46
+ * A picture the host decides how to find. The address is drawn only when the host's resolver gives one for `src`;
47
+ * without a resolver, or when it gives nothing, the `alt` text stands in its place, so what a model wrote can never
48
+ * load an address of its own choosing.
49
+ */
50
+ export declare function Image({ src, alt, caption, width, height, fit, maxHeight, resolveImage, className }: ImageProps): import("react").JSX.Element;
@@ -0,0 +1,65 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useContext } from "react";
3
+ const ImageResolverContext = createContext(undefined);
4
+ /**
5
+ * Says, once for everything below it, how an image an agent named is turned into an address: the catalog's `Image`
6
+ * and the images in `Markdown` (`![alt](src)`) both ask it, unless they are given a `resolveImage` of their own.
7
+ * `SurfaceView` takes `resolveImage` and provides it, so a host with one surface needs no provider.
8
+ */
9
+ export function ImageResolverProvider({ resolve, children }) {
10
+ return _jsx(ImageResolverContext.Provider, { value: resolve, children: children });
11
+ }
12
+ /** The resolver a host provided above, if any. */
13
+ export function useImageResolver() {
14
+ return useContext(ImageResolverContext);
15
+ }
16
+ const IMAGE_DATA = /^data:image\/(?:png|jpe?g|gif|webp|avif);/i;
17
+ /**
18
+ * Whether an address may be drawn as an image: http(s), a `blob:` the host made from a file, a raster `data:image/`,
19
+ * or a path on the same origin (`/files/1.png`). Never a script, `file:` or a protocol-relative address. Used for
20
+ * what a host's resolver returned and for a preview a host supplies; never for text an agent wrote.
21
+ */
22
+ export function safeImageAddress(value) {
23
+ if (!value)
24
+ return undefined;
25
+ if (/^\/(?![/\\])/.test(value))
26
+ return value;
27
+ if (IMAGE_DATA.test(value))
28
+ return value;
29
+ try {
30
+ const url = new URL(value);
31
+ return url.protocol === "https:" || url.protocol === "http:" || url.protocol === "blob:" ? value : undefined;
32
+ }
33
+ catch {
34
+ return undefined;
35
+ }
36
+ }
37
+ /** The address to draw for an image the text or an agent gave, or nothing: the host's resolver is the only source. */
38
+ export function resolveImageAddress(resolve, src) {
39
+ if (!resolve || !src)
40
+ return undefined;
41
+ try {
42
+ return safeImageAddress(resolve(src));
43
+ }
44
+ catch {
45
+ return undefined;
46
+ }
47
+ }
48
+ /**
49
+ * A picture the host decides how to find. The address is drawn only when the host's resolver gives one for `src`;
50
+ * without a resolver, or when it gives nothing, the `alt` text stands in its place, so what a model wrote can never
51
+ * load an address of its own choosing.
52
+ */
53
+ export function Image({ src, alt, caption, width, height, fit = "contain", maxHeight, resolveImage, className }) {
54
+ const provided = useImageResolver();
55
+ const address = resolveImageAddress(resolveImage ?? provided, src);
56
+ const style = {};
57
+ if (width)
58
+ style["--sf-image-width"] = `${width}px`;
59
+ if (height)
60
+ style["--sf-image-height"] = `${height}px`;
61
+ if (maxHeight)
62
+ style["--sf-image-max-height"] = `${maxHeight}px`;
63
+ return (_jsxs("figure", { className: ["sf-image", className].filter(Boolean).join(" "), "data-fit": fit, "data-fixed": height ? true : undefined, style: style, children: [address ? (_jsx("img", { className: "sf-image-body", src: address, alt: alt, loading: "lazy", decoding: "async" })) : (_jsx("div", { className: "sf-image-missing", role: alt ? "img" : undefined, "aria-label": alt || undefined, children: _jsx("span", { "aria-hidden": "true", children: alt || "Image" }) })), caption != null && caption !== "" && _jsx("figcaption", { children: caption })] }));
64
+ }
65
+ //# sourceMappingURL=Image.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Image.js","sourceRoot":"","sources":["../../src/text/Image.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsC,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAQtF,MAAM,oBAAoB,GAAG,aAAa,CAA4B,SAAS,CAAC,CAAC;AAEjF;;;;GAIG;AACH,MAAM,UAAU,qBAAqB,CAAC,EAAE,OAAO,EAAE,QAAQ,EAA+D;IACtH,OAAO,KAAC,oBAAoB,CAAC,QAAQ,IAAC,KAAK,EAAE,OAAO,YAAG,QAAQ,GAAiC,CAAC;AACnG,CAAC;AAED,kDAAkD;AAClD,MAAM,UAAU,gBAAgB;IAC9B,OAAO,UAAU,CAAC,oBAAoB,CAAC,CAAC;AAC1C,CAAC;AAED,MAAM,UAAU,GAAG,4CAA4C,CAAC;AAEhE;;;;GAIG;AACH,MAAM,UAAU,gBAAgB,CAAC,KAAyB;IACxD,IAAI,CAAC,KAAK;QAAE,OAAO,SAAS,CAAC;IAC7B,IAAI,cAAc,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IAC7C,IAAI,UAAU,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,KAAK,CAAC;IACzC,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,GAAG,CA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G,gBAAc,MAAM,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,EAAE,KAAK,EAAE,KAAsB,aACtJ,OAAO,CAAC,CAAC,CAAC,CACT,cAAK,SAAS,EAAC,eAAe,EAAC,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,OAAO,EAAC,MAAM,EAAC,QAAQ,EAAC,OAAO,GAAG,CAC1F,CAAC,CAAC,CAAC,CACF,cAAK,SAAS,EAAC,kBAAkB,EAAC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,gBAAc,GAAG,IAAI,SAAS,YAC3F,8BAAkB,MAAM,YAAE,GAAG,IAAI,OAAO,GAAQ,GAC5C,CACP,EACA,OAAO,IAAI,IAAI,IAAI,OAAO,KAAK,EAAE,IAAI,+BAAa,OAAO,GAAc,IACjE,CACV,CAAC;AACJ,CAAC","sourcesContent":["import { type CSSProperties, type ReactNode, createContext, useContext } from \"react\";\n\n/**\n * Turns the name or address an image was given into the address to draw, or nothing. The host owns it: it is the\n * only way an address reaches an `<img>` for text or a catalog component an agent wrote.\n */\nexport type ImageResolver = (src: string) => string | undefined;\n\nconst ImageResolverContext = createContext<ImageResolver | undefined>(undefined);\n\n/**\n * Says, once for everything below it, how an image an agent named is turned into an address: the catalog's `Image`\n * and the images in `Markdown` (`![alt](src)`) both ask it, unless they are given a `resolveImage` of their own.\n * `SurfaceView` takes `resolveImage` and provides it, so a host with one surface needs no provider.\n */\nexport function ImageResolverProvider({ resolve, children }: { resolve: ImageResolver | undefined; children: ReactNode }) {\n return <ImageResolverContext.Provider value={resolve}>{children}</ImageResolverContext.Provider>;\n}\n\n/** The resolver a host provided above, if any. */\nexport function useImageResolver(): ImageResolver | undefined {\n return useContext(ImageResolverContext);\n}\n\nconst IMAGE_DATA = /^data:image\\/(?:png|jpe?g|gif|webp|avif);/i;\n\n/**\n * Whether an address may be drawn as an image: http(s), a `blob:` the host made from a file, a raster `data:image/`,\n * or a path on the same origin (`/files/1.png`). Never a script, `file:` or a protocol-relative address. Used for\n * what a host's resolver returned and for a preview a host supplies; never for text an agent wrote.\n */\nexport function safeImageAddress(value: string | undefined): string | undefined {\n if (!value) return undefined;\n if (/^\\/(?![/\\\\])/.test(value)) return value;\n if (IMAGE_DATA.test(value)) return value;\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\" || url.protocol === \"blob:\" ? value : undefined;\n } catch {\n return undefined;\n }\n}\n\n/** The address to draw for an image the text or an agent gave, or nothing: the host's resolver is the only source. */\nexport function resolveImageAddress(resolve: ImageResolver | undefined, src: string): string | undefined {\n if (!resolve || !src) return undefined;\n try {\n return safeImageAddress(resolve(src));\n } catch {\n return undefined;\n }\n}\n\nexport type ImageFit = \"contain\" | \"cover\";\n\nexport interface ImageProps {\n /** What the image is called: the name or address the text or agent gave. It is never loaded as written; the resolver turns it into the address to draw. */\n src: string;\n /** What it shows, for anyone who cannot see it. Required; shown in its place when there is no address. An empty string marks decoration. */\n alt: string;\n caption?: ReactNode;\n /** The most the image is wide, in pixels. It never grows past its container. */\n width?: number;\n /** A fixed height in pixels; the image then fills the box by `fit`. */\n height?: number;\n /** How a fixed box is filled: whole (`contain`, the default) or edge to edge, cropped (`cover`). */\n fit?: ImageFit;\n /** The most the image is tall, in pixels. */\n maxHeight?: number;\n /** Overrides the resolver provided above (`ImageResolverProvider`). */\n resolveImage?: ImageResolver;\n className?: string;\n}\n\n/**\n * A picture the host decides how to find. The address is drawn only when the host's resolver gives one for `src`;\n * without a resolver, or when it gives nothing, the `alt` text stands in its place, so what a model wrote can never\n * load an address of its own choosing.\n */\nexport function Image({ src, alt, caption, width, height, fit = \"contain\", maxHeight, resolveImage, className }: ImageProps) {\n const provided = useImageResolver();\n const address = resolveImageAddress(resolveImage ?? provided, src);\n const style: Record<string, string> = {};\n if (width) style[\"--sf-image-width\"] = `${width}px`;\n if (height) style[\"--sf-image-height\"] = `${height}px`;\n if (maxHeight) style[\"--sf-image-max-height\"] = `${maxHeight}px`;\n return (\n <figure className={[\"sf-image\", className].filter(Boolean).join(\" \")} data-fit={fit} data-fixed={height ? true : undefined} style={style as CSSProperties}>\n {address ? (\n <img className=\"sf-image-body\" src={address} alt={alt} loading=\"lazy\" decoding=\"async\" />\n ) : (\n <div className=\"sf-image-missing\" role={alt ? \"img\" : undefined} aria-label={alt || undefined}>\n <span aria-hidden=\"true\">{alt || \"Image\"}</span>\n </div>\n )}\n {caption != null && caption !== \"\" && <figcaption>{caption}</figcaption>}\n </figure>\n );\n}\n"]}
@@ -56,7 +56,11 @@ export interface MarkdownProps {
56
56
  headingStart?: number;
57
57
  /** Turns a link the text gives (such as a relative path) into a full http(s) address, or undefined to leave it as text. */
58
58
  resolveLink?(href: string): string | undefined;
59
- /** Turns an image the text gives (`![alt](src)`) into a full http(s) address. Without it, or when it returns undefined, the image's description is shown instead. */
59
+ /**
60
+ * Turns an image the text gives (`![alt](src)`) into the address to draw (http(s), a `blob:`, a raster `data:image/` or a
61
+ * path on the same origin). Without it, or when it returns undefined, the image's description is shown instead. Left out,
62
+ * the resolver given to `ImageResolverProvider` (or `SurfaceView`'s `resolveImage`) above is used.
63
+ */
60
64
  resolveImage?(src: string): string | undefined;
61
65
  /** Called on a plain click on a link, with its full address; return true to handle it in the app, so it does not open a new tab. */
62
66
  openLink?(href: string): boolean;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { Fragment, useMemo, useState } from "react";
3
3
  import { highlight } from "./highlight.js";
4
+ import { resolveImageAddress, useImageResolver } from "./Image.js";
4
5
  /** Only http(s) and mailto links are rendered as links; anything else stays text. */
5
6
  function safeHref(value) {
6
7
  try {
@@ -32,7 +33,7 @@ function inline(text, links = {}) {
32
33
  // so text from a model cannot load an image from anywhere it likes.
33
34
  const split = token.indexOf("](");
34
35
  const alt = token.slice(2, split);
35
- const src = links.image ? safeHref(links.image(token.slice(split + 2, -1)) ?? "") : undefined;
36
+ const src = resolveImageAddress(links.image, token.slice(split + 2, -1));
36
37
  out.push(src ? _jsx("img", { className: "sf-markdown-image", src: src, alt: alt, loading: "lazy", decoding: "async" }, key++) : alt);
37
38
  }
38
39
  else {
@@ -156,7 +157,8 @@ export function CodeBlock({ code, language, onRun, label, bare, className }) {
156
157
  * inserted as HTML, so model output cannot add markup or scripts.
157
158
  */
158
159
  export function Markdown({ text, onRunSql, inline: oneLine, headingStart = 3, resolveLink, resolveImage, openLink, className }) {
159
- const links = { resolve: resolveLink, image: resolveImage, open: openLink };
160
+ const provided = useImageResolver();
161
+ const links = { resolve: resolveLink, image: resolveImage ?? provided, open: openLink };
160
162
  const line = (value) => inline(value, links);
161
163
  if (oneLine)
162
164
  return _jsx("span", { className: ["sf-markdown-inline", className].filter(Boolean).join(" "), children: line(text) });
@@ -1 +1 @@
1
- {"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../src/text/Markdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,qFAAqF;AACrF,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACpH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,MAAM,GAAG,2GAA2G,CAAC;AAS3H,uGAAuG;AACvG,SAAS,MAAM,CAAC,IAAY,EAAE,KAAK,GAAU,EAAE;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tC,CAAC,IAHK,CAAC,CAIL,CACN,CAAC,GACI,IACF,IApBA,KAAK,CAqBT,CACP,CAAC;oBACJ;wBACE,OAAO,sBAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAxB,KAAK,CAAwB,CAAC;gBACjD,CAAC;YACH,CAAC,CAAC,EACF,KAAC,QAAQ,KAAG,IACR,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Fragment, type ReactNode, useMemo, useState } from \"react\";\nimport { highlight } from \"./highlight.js\";\n\n/** Only http(s) and mailto links are rendered as links; anything else stays text. */\nfunction safeHref(value: string): string | undefined {\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\" || url.protocol === \"mailto:\" ? url.href : undefined;\n } catch {\n return undefined;\n }\n}\n\nconst INLINE = /(`[^`\\n]+`)|(\\*\\*[^*\\n]+\\*\\*)|(\\*[^*\\n]+\\*|_[^_\\n]+_)|(!\\[[^\\]\\n]*\\]\\([^)\\s]+\\)|\\[[^\\]\\n]+\\]\\([^)\\s]+\\))/g;\n\n/** How a host takes part in links and images; every address is checked again as http(s) before use. */\ninterface Links {\n resolve?: (href: string) => string | undefined;\n image?: (src: string) => string | undefined;\n open?: (href: string) => boolean;\n}\n\n/** Inline Markdown as React nodes: code, bold, italic and links. Never produces HTML from the text. */\nfunction inline(text: string, links: Links = {}): ReactNode[] {\n const out: ReactNode[] = [];\n let last = 0;\n let key = 0;\n for (const match of text.matchAll(INLINE)) {\n if (match.index > last) out.push(text.slice(last, match.index));\n const token = match[0];\n if (match[1]) out.push(<code key={key++}>{token.slice(1, -1)}</code>);\n else if (match[2]) out.push(<strong key={key++}>{inline(token.slice(2, -2), links)}</strong>);\n else if (match[3]) out.push(<em key={key++}>{inline(token.slice(1, -1), links)}</em>);\n else if (token.startsWith(\"!\")) {\n // An image is drawn only when the host gives its address (`resolveImage`); otherwise its description stands in,\n // so text from a model cannot load an image from anywhere it likes.\n const split = token.indexOf(\"](\");\n const alt = token.slice(2, split);\n const src = links.image ? safeHref(links.image(token.slice(split + 2, -1)) ?? \"\") : undefined;\n out.push(src ? <img key={key++} className=\"sf-markdown-image\" src={src} alt={alt} loading=\"lazy\" decoding=\"async\" /> : alt);\n } else {\n const split = token.indexOf(\"](\");\n const label = token.slice(1, split);\n const target = token.slice(split + 2, -1);\n // A host may turn its own links (a relative docs path, an anchor) into safe ones; the result is checked again.\n const href = safeHref(target) ?? (links.resolve ? safeHref(links.resolve(target) ?? \"\") : undefined);\n const open = links.open;\n out.push(\n href ? (\n <a\n key={key++}\n href={href}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n onClick={\n open &&\n ((event) => {\n // A plain click on a link the host keeps (a page of its own) stays in the app; any modifier opens a tab.\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;\n if (open(href)) event.preventDefault();\n })\n }\n >\n {inline(label, links)}\n </a>\n ) : (\n label\n ),\n );\n }\n last = match.index + token.length;\n }\n if (last < text.length) out.push(text.slice(last));\n return out;\n}\n\ntype Block =\n | { kind: \"heading\"; level: number; text: string }\n | { kind: \"paragraph\"; text: string }\n | { kind: \"code\"; language: string; code: string }\n | { kind: \"list\"; ordered: boolean; items: string[]; start?: number }\n | { kind: \"quote\"; text: string }\n | { kind: \"table\"; head: string[]; rows: string[][] }\n | { kind: \"rule\" };\n\nconst cells = (line: string) =>\n line\n .trim()\n .replace(/^\\||\\|$/g, \"\")\n .split(\"|\")\n .map((cell) => cell.trim());\n\n/** Splits Markdown into blocks. Text still arriving (an unclosed code fence, a half table) is handled. */\nexport function parseMarkdown(source: string): Block[] {\n const lines = source.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const blocks: Block[] = [];\n for (let i = 0; i < lines.length; ) {\n const line = lines[i]!;\n const fence = /^\\s*```(\\S*)\\s*$/.exec(line);\n if (fence) {\n const body: string[] = [];\n for (i++; i < lines.length && !/^\\s*```\\s*$/.test(lines[i]!); i++) body.push(lines[i]!);\n i++;\n blocks.push({ kind: \"code\", language: fence[1] ?? \"\", code: body.join(\"\\n\") });\n continue;\n }\n if (line.trim() === \"\") {\n i++;\n continue;\n }\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n if (heading) {\n blocks.push({ kind: \"heading\", level: heading[1]!.length, text: heading[2]! });\n i++;\n continue;\n }\n if (/^\\s*([-*_])\\s*\\1\\s*\\1[\\s\\-*_]*$/.test(line)) {\n blocks.push({ kind: \"rule\" });\n i++;\n continue;\n }\n if (line.includes(\"|\") && /^\\s*\\|?\\s*:?-{2,}:?\\s*(\\|\\s*:?-{2,}:?\\s*)*\\|?\\s*$/.test(lines[i + 1] ?? \"\")) {\n const head = cells(line);\n const rows: string[][] = [];\n for (i += 2; i < lines.length && lines[i]!.includes(\"|\") && lines[i]!.trim() !== \"\"; i++) rows.push(cells(lines[i]!));\n blocks.push({ kind: \"table\", head, rows });\n continue;\n }\n const bullet = /^\\s*(?:[-*+]|(\\d+)[.)])\\s+(.*)$/.exec(line);\n if (bullet) {\n const ordered = bullet[1] !== undefined;\n const items: string[] = [];\n for (; i < lines.length; i++) {\n const item = /^\\s*(?:[-*+]|(\\d+)[.)])\\s+(.*)$/.exec(lines[i]!);\n if (item && (item[1] !== undefined) === ordered) items.push(item[2]!);\n else if (items.length > 0 && /^\\s{2,}\\S/.test(lines[i]!)) items[items.length - 1] += ` ${lines[i]!.trim()}`;\n else break;\n }\n // A numbered list broken by a code block carries on from its own number (\"2.\" after the code).\n const start = ordered ? Number(bullet[1]) : undefined;\n blocks.push(start !== undefined && start !== 1 ? { kind: \"list\", ordered, items, start } : { kind: \"list\", ordered, items });\n continue;\n }\n if (/^\\s*>/.test(line)) {\n const body: string[] = [];\n for (; i < lines.length && /^\\s*>/.test(lines[i]!); i++) body.push(lines[i]!.replace(/^\\s*>\\s?/, \"\"));\n blocks.push({ kind: \"quote\", text: body.join(\" \") });\n continue;\n }\n const body: string[] = [];\n for (; i < lines.length && lines[i]!.trim() !== \"\" && !/^\\s*(```|#{1,6}\\s|>|[-*+]\\s|\\d+[.)]\\s)/.test(lines[i]!); i++) body.push(lines[i]!.trim());\n if (body.length === 0) body.push(lines[i++]!.trim());\n blocks.push({ kind: \"paragraph\", text: body.join(\" \") });\n }\n return blocks;\n}\n\nexport interface CodeBlockProps {\n code: string;\n /** Shown as a label, e.g. \"sql\". */\n language?: string;\n /** Shows a Run button for SQL and is called with the code. Nothing runs unless a person presses it. */\n onRun?(code: string): void;\n /** Accessible name for the block; defaults to the language. */\n label?: string;\n /** Hide the bar with the language and the Copy button, for code shown as part of a larger view. */\n bare?: boolean;\n className?: string;\n}\n\n/** Code as coloured tokens. Colours come from `--sf-code-*`, so they follow the theme. */\nexport function HighlightedCode({ code, language }: { code: string; language?: string }) {\n const tokens = useMemo(() => highlight(code, language), [code, language]);\n return (\n <code data-language={language || undefined}>\n {tokens.map((token, i) =>\n token.kind ? (\n <span key={i} className={`sf-tok-${token.kind}`}>\n {token.text}\n </span>\n ) : (\n <Fragment key={i}>{token.text}</Fragment>\n ),\n )}\n </code>\n );\n}\n\n/** A block of code with a copy button. */\nexport function CodeBlock({ code, language, onRun, label, bare, className }: CodeBlockProps) {\n const [copied, setCopied] = useState(false);\n const copy = () => {\n void navigator.clipboard?.writeText(code).then(\n () => {\n setCopied(true);\n setTimeout(() => setCopied(false), 1500);\n },\n () => {},\n );\n };\n return (\n <div className={[\"sf-code\", bare && \"sf-code-bare\", className].filter(Boolean).join(\" \")}>\n {!bare && (\n <div className=\"sf-code-bar\">\n <span>{language || \"text\"}</span>\n <span className=\"sf-code-actions\">\n {onRun && (\n <button type=\"button\" className=\"sf-button\" onClick={() => onRun(code)}>\n Run\n </button>\n )}\n <button type=\"button\" className=\"sf-button\" onClick={copy} aria-live=\"polite\">\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n </span>\n </div>\n )}\n <pre tabIndex={0} aria-label={label ?? (language ? `${language} code` : \"Code\")}>\n <HighlightedCode code={code} language={language} />\n </pre>\n </div>\n );\n}\n\nexport interface MarkdownProps {\n /** Markdown text. May be incomplete while it streams in. */\n text: string;\n /** Called when a person presses Run on a SQL code block. Omit to show no Run button. */\n onRunSql?(sql: string): void;\n /** Render one line of inline Markdown (code, emphasis, links) in a span, for labels and descriptions. */\n inline?: boolean;\n /** The heading level a `#` becomes. Defaults to 3, so a reply never outranks the page's own headings. */\n headingStart?: number;\n /** Turns a link the text gives (such as a relative path) into a full http(s) address, or undefined to leave it as text. */\n resolveLink?(href: string): string | undefined;\n /** Turns an image the text gives (`![alt](src)`) into a full http(s) address. Without it, or when it returns undefined, the image's description is shown instead. */\n resolveImage?(src: string): string | undefined;\n /** Called on a plain click on a link, with its full address; return true to handle it in the app, so it does not open a new tab. */\n openLink?(href: string): boolean;\n className?: string;\n}\n\n/**\n * Renders Markdown as React elements: headings, paragraphs, lists, quotes,\n * tables, code blocks, and inline code, emphasis and links. The text is never\n * inserted as HTML, so model output cannot add markup or scripts.\n */\nexport function Markdown({ text, onRunSql, inline: oneLine, headingStart = 3, resolveLink, resolveImage, openLink, className }: MarkdownProps) {\n const links: Links = { resolve: resolveLink, image: resolveImage, open: openLink };\n const line = (value: string) => inline(value, links);\n if (oneLine) return <span className={[\"sf-markdown-inline\", className].filter(Boolean).join(\" \")}>{line(text)}</span>;\n return (\n <div className={[\"sf-markdown\", className].filter(Boolean).join(\" \")}>\n {parseMarkdown(text).map((block, index) => {\n switch (block.kind) {\n case \"heading\": {\n // Headings start at h3 so a reply never outranks the page's own headings.\n const Tag = `h${Math.min(6, block.level + Math.max(0, Math.min(5, headingStart - 1)))}` as \"h3\";\n return <Tag key={index}>{line(block.text)}</Tag>;\n }\n case \"code\":\n return <CodeBlock key={index} code={block.code} language={block.language} onRun={onRunSql && /^sql$/i.test(block.language) ? onRunSql : undefined} />;\n case \"list\": {\n const Tag = block.ordered ? \"ol\" : \"ul\";\n return (\n <Tag key={index} start={block.start}>\n {block.items.map((item, i) => (\n <li key={i}>{line(item)}</li>\n ))}\n </Tag>\n );\n }\n case \"quote\":\n return <blockquote key={index}>{line(block.text)}</blockquote>;\n case \"rule\":\n return <hr key={index} />;\n case \"table\":\n return (\n // A wide table scrolls sideways, so it can be focused and scrolled with the arrow keys.\n // biome-ignore lint/a11y/noNoninteractiveTabindex: a scrolling region must be reachable by keyboard.\n <div key={index} className=\"sf-markdown-table\" tabIndex={0} role=\"region\" aria-label={`Table: ${block.head.slice(0, 3).join(\", \")}`}>\n <table>\n <thead>\n <tr>\n {block.head.map((cell, i) => (\n <th key={i} scope=\"col\">\n {line(cell)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {block.rows.map((row, r) => (\n <tr key={r}>\n {block.head.map((_, c) => (\n <td key={c}>{line(row[c] ?? \"\")}</td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n default:\n return <p key={index}>{line(block.text)}</p>;\n }\n })}\n <Fragment />\n </div>\n );\n}\n"]}
1
+ {"version":3,"file":"Markdown.js","sourceRoot":"","sources":["../../src/text/Markdown.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,QAAQ,EAAkB,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACpE,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAEnE,qFAAqF;AACrF,SAAS,QAAQ,CAAC,KAAa;IAC7B,IAAI,CAAC;QACH,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,KAAK,CAAC,CAAC;QAC3B,OAAO,GAAG,CAAC,QAAQ,KAAK,QAAQ,IAAI,GAAG,CAAC,QAAQ,KAAK,OAAO,IAAI,GAAG,CAAC,QAAQ,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC;IACpH,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,SAAS,CAAC;IACnB,CAAC;AACH,CAAC;AAED,MAAM,MAAM,GAAG,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,GAAG,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,IAAtB,CAAC,CAA2B,CACtC,CAAC,IAHK,CAAC,CAIL,CACN,CAAC,GACI,IACF,IApBA,KAAK,CAqBT,CACP,CAAC;oBACJ;wBACE,OAAO,sBAAgB,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,IAAxB,KAAK,CAAwB,CAAC;gBACjD,CAAC;YACH,CAAC,CAAC,EACF,KAAC,QAAQ,KAAG,IACR,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { Fragment, type ReactNode, useMemo, useState } from \"react\";\nimport { highlight } from \"./highlight.js\";\nimport { resolveImageAddress, useImageResolver } from \"./Image.js\";\n\n/** Only http(s) and mailto links are rendered as links; anything else stays text. */\nfunction safeHref(value: string): string | undefined {\n try {\n const url = new URL(value);\n return url.protocol === \"https:\" || url.protocol === \"http:\" || url.protocol === \"mailto:\" ? url.href : undefined;\n } catch {\n return undefined;\n }\n}\n\nconst INLINE = /(`[^`\\n]+`)|(\\*\\*[^*\\n]+\\*\\*)|(\\*[^*\\n]+\\*|_[^_\\n]+_)|(!\\[[^\\]\\n]*\\]\\([^)\\s]+\\)|\\[[^\\]\\n]+\\]\\([^)\\s]+\\))/g;\n\n/** How a host takes part in links and images; every address is checked again as http(s) before use. */\ninterface Links {\n resolve?: (href: string) => string | undefined;\n image?: (src: string) => string | undefined;\n open?: (href: string) => boolean;\n}\n\n/** Inline Markdown as React nodes: code, bold, italic and links. Never produces HTML from the text. */\nfunction inline(text: string, links: Links = {}): ReactNode[] {\n const out: ReactNode[] = [];\n let last = 0;\n let key = 0;\n for (const match of text.matchAll(INLINE)) {\n if (match.index > last) out.push(text.slice(last, match.index));\n const token = match[0];\n if (match[1]) out.push(<code key={key++}>{token.slice(1, -1)}</code>);\n else if (match[2]) out.push(<strong key={key++}>{inline(token.slice(2, -2), links)}</strong>);\n else if (match[3]) out.push(<em key={key++}>{inline(token.slice(1, -1), links)}</em>);\n else if (token.startsWith(\"!\")) {\n // An image is drawn only when the host gives its address (`resolveImage`); otherwise its description stands in,\n // so text from a model cannot load an image from anywhere it likes.\n const split = token.indexOf(\"](\");\n const alt = token.slice(2, split);\n const src = resolveImageAddress(links.image, token.slice(split + 2, -1));\n out.push(src ? <img key={key++} className=\"sf-markdown-image\" src={src} alt={alt} loading=\"lazy\" decoding=\"async\" /> : alt);\n } else {\n const split = token.indexOf(\"](\");\n const label = token.slice(1, split);\n const target = token.slice(split + 2, -1);\n // A host may turn its own links (a relative docs path, an anchor) into safe ones; the result is checked again.\n const href = safeHref(target) ?? (links.resolve ? safeHref(links.resolve(target) ?? \"\") : undefined);\n const open = links.open;\n out.push(\n href ? (\n <a\n key={key++}\n href={href}\n target=\"_blank\"\n rel=\"noreferrer noopener\"\n onClick={\n open &&\n ((event) => {\n // A plain click on a link the host keeps (a page of its own) stays in the app; any modifier opens a tab.\n if (event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;\n if (open(href)) event.preventDefault();\n })\n }\n >\n {inline(label, links)}\n </a>\n ) : (\n label\n ),\n );\n }\n last = match.index + token.length;\n }\n if (last < text.length) out.push(text.slice(last));\n return out;\n}\n\ntype Block =\n | { kind: \"heading\"; level: number; text: string }\n | { kind: \"paragraph\"; text: string }\n | { kind: \"code\"; language: string; code: string }\n | { kind: \"list\"; ordered: boolean; items: string[]; start?: number }\n | { kind: \"quote\"; text: string }\n | { kind: \"table\"; head: string[]; rows: string[][] }\n | { kind: \"rule\" };\n\nconst cells = (line: string) =>\n line\n .trim()\n .replace(/^\\||\\|$/g, \"\")\n .split(\"|\")\n .map((cell) => cell.trim());\n\n/** Splits Markdown into blocks. Text still arriving (an unclosed code fence, a half table) is handled. */\nexport function parseMarkdown(source: string): Block[] {\n const lines = source.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n const blocks: Block[] = [];\n for (let i = 0; i < lines.length; ) {\n const line = lines[i]!;\n const fence = /^\\s*```(\\S*)\\s*$/.exec(line);\n if (fence) {\n const body: string[] = [];\n for (i++; i < lines.length && !/^\\s*```\\s*$/.test(lines[i]!); i++) body.push(lines[i]!);\n i++;\n blocks.push({ kind: \"code\", language: fence[1] ?? \"\", code: body.join(\"\\n\") });\n continue;\n }\n if (line.trim() === \"\") {\n i++;\n continue;\n }\n const heading = /^(#{1,6})\\s+(.*)$/.exec(line);\n if (heading) {\n blocks.push({ kind: \"heading\", level: heading[1]!.length, text: heading[2]! });\n i++;\n continue;\n }\n if (/^\\s*([-*_])\\s*\\1\\s*\\1[\\s\\-*_]*$/.test(line)) {\n blocks.push({ kind: \"rule\" });\n i++;\n continue;\n }\n if (line.includes(\"|\") && /^\\s*\\|?\\s*:?-{2,}:?\\s*(\\|\\s*:?-{2,}:?\\s*)*\\|?\\s*$/.test(lines[i + 1] ?? \"\")) {\n const head = cells(line);\n const rows: string[][] = [];\n for (i += 2; i < lines.length && lines[i]!.includes(\"|\") && lines[i]!.trim() !== \"\"; i++) rows.push(cells(lines[i]!));\n blocks.push({ kind: \"table\", head, rows });\n continue;\n }\n const bullet = /^\\s*(?:[-*+]|(\\d+)[.)])\\s+(.*)$/.exec(line);\n if (bullet) {\n const ordered = bullet[1] !== undefined;\n const items: string[] = [];\n for (; i < lines.length; i++) {\n const item = /^\\s*(?:[-*+]|(\\d+)[.)])\\s+(.*)$/.exec(lines[i]!);\n if (item && (item[1] !== undefined) === ordered) items.push(item[2]!);\n else if (items.length > 0 && /^\\s{2,}\\S/.test(lines[i]!)) items[items.length - 1] += ` ${lines[i]!.trim()}`;\n else break;\n }\n // A numbered list broken by a code block carries on from its own number (\"2.\" after the code).\n const start = ordered ? Number(bullet[1]) : undefined;\n blocks.push(start !== undefined && start !== 1 ? { kind: \"list\", ordered, items, start } : { kind: \"list\", ordered, items });\n continue;\n }\n if (/^\\s*>/.test(line)) {\n const body: string[] = [];\n for (; i < lines.length && /^\\s*>/.test(lines[i]!); i++) body.push(lines[i]!.replace(/^\\s*>\\s?/, \"\"));\n blocks.push({ kind: \"quote\", text: body.join(\" \") });\n continue;\n }\n const body: string[] = [];\n for (; i < lines.length && lines[i]!.trim() !== \"\" && !/^\\s*(```|#{1,6}\\s|>|[-*+]\\s|\\d+[.)]\\s)/.test(lines[i]!); i++) body.push(lines[i]!.trim());\n if (body.length === 0) body.push(lines[i++]!.trim());\n blocks.push({ kind: \"paragraph\", text: body.join(\" \") });\n }\n return blocks;\n}\n\nexport interface CodeBlockProps {\n code: string;\n /** Shown as a label, e.g. \"sql\". */\n language?: string;\n /** Shows a Run button for SQL and is called with the code. Nothing runs unless a person presses it. */\n onRun?(code: string): void;\n /** Accessible name for the block; defaults to the language. */\n label?: string;\n /** Hide the bar with the language and the Copy button, for code shown as part of a larger view. */\n bare?: boolean;\n className?: string;\n}\n\n/** Code as coloured tokens. Colours come from `--sf-code-*`, so they follow the theme. */\nexport function HighlightedCode({ code, language }: { code: string; language?: string }) {\n const tokens = useMemo(() => highlight(code, language), [code, language]);\n return (\n <code data-language={language || undefined}>\n {tokens.map((token, i) =>\n token.kind ? (\n <span key={i} className={`sf-tok-${token.kind}`}>\n {token.text}\n </span>\n ) : (\n <Fragment key={i}>{token.text}</Fragment>\n ),\n )}\n </code>\n );\n}\n\n/** A block of code with a copy button. */\nexport function CodeBlock({ code, language, onRun, label, bare, className }: CodeBlockProps) {\n const [copied, setCopied] = useState(false);\n const copy = () => {\n void navigator.clipboard?.writeText(code).then(\n () => {\n setCopied(true);\n setTimeout(() => setCopied(false), 1500);\n },\n () => {},\n );\n };\n return (\n <div className={[\"sf-code\", bare && \"sf-code-bare\", className].filter(Boolean).join(\" \")}>\n {!bare && (\n <div className=\"sf-code-bar\">\n <span>{language || \"text\"}</span>\n <span className=\"sf-code-actions\">\n {onRun && (\n <button type=\"button\" className=\"sf-button\" onClick={() => onRun(code)}>\n Run\n </button>\n )}\n <button type=\"button\" className=\"sf-button\" onClick={copy} aria-live=\"polite\">\n {copied ? \"Copied\" : \"Copy\"}\n </button>\n </span>\n </div>\n )}\n <pre tabIndex={0} aria-label={label ?? (language ? `${language} code` : \"Code\")}>\n <HighlightedCode code={code} language={language} />\n </pre>\n </div>\n );\n}\n\nexport interface MarkdownProps {\n /** Markdown text. May be incomplete while it streams in. */\n text: string;\n /** Called when a person presses Run on a SQL code block. Omit to show no Run button. */\n onRunSql?(sql: string): void;\n /** Render one line of inline Markdown (code, emphasis, links) in a span, for labels and descriptions. */\n inline?: boolean;\n /** The heading level a `#` becomes. Defaults to 3, so a reply never outranks the page's own headings. */\n headingStart?: number;\n /** Turns a link the text gives (such as a relative path) into a full http(s) address, or undefined to leave it as text. */\n resolveLink?(href: string): string | undefined;\n /**\n * Turns an image the text gives (`![alt](src)`) into the address to draw (http(s), a `blob:`, a raster `data:image/` or a\n * path on the same origin). Without it, or when it returns undefined, the image's description is shown instead. Left out,\n * the resolver given to `ImageResolverProvider` (or `SurfaceView`'s `resolveImage`) above is used.\n */\n resolveImage?(src: string): string | undefined;\n /** Called on a plain click on a link, with its full address; return true to handle it in the app, so it does not open a new tab. */\n openLink?(href: string): boolean;\n className?: string;\n}\n\n/**\n * Renders Markdown as React elements: headings, paragraphs, lists, quotes,\n * tables, code blocks, and inline code, emphasis and links. The text is never\n * inserted as HTML, so model output cannot add markup or scripts.\n */\nexport function Markdown({ text, onRunSql, inline: oneLine, headingStart = 3, resolveLink, resolveImage, openLink, className }: MarkdownProps) {\n const provided = useImageResolver();\n const links: Links = { resolve: resolveLink, image: resolveImage ?? provided, open: openLink };\n const line = (value: string) => inline(value, links);\n if (oneLine) return <span className={[\"sf-markdown-inline\", className].filter(Boolean).join(\" \")}>{line(text)}</span>;\n return (\n <div className={[\"sf-markdown\", className].filter(Boolean).join(\" \")}>\n {parseMarkdown(text).map((block, index) => {\n switch (block.kind) {\n case \"heading\": {\n // Headings start at h3 so a reply never outranks the page's own headings.\n const Tag = `h${Math.min(6, block.level + Math.max(0, Math.min(5, headingStart - 1)))}` as \"h3\";\n return <Tag key={index}>{line(block.text)}</Tag>;\n }\n case \"code\":\n return <CodeBlock key={index} code={block.code} language={block.language} onRun={onRunSql && /^sql$/i.test(block.language) ? onRunSql : undefined} />;\n case \"list\": {\n const Tag = block.ordered ? \"ol\" : \"ul\";\n return (\n <Tag key={index} start={block.start}>\n {block.items.map((item, i) => (\n <li key={i}>{line(item)}</li>\n ))}\n </Tag>\n );\n }\n case \"quote\":\n return <blockquote key={index}>{line(block.text)}</blockquote>;\n case \"rule\":\n return <hr key={index} />;\n case \"table\":\n return (\n // A wide table scrolls sideways, so it can be focused and scrolled with the arrow keys.\n // biome-ignore lint/a11y/noNoninteractiveTabindex: a scrolling region must be reachable by keyboard.\n <div key={index} className=\"sf-markdown-table\" tabIndex={0} role=\"region\" aria-label={`Table: ${block.head.slice(0, 3).join(\", \")}`}>\n <table>\n <thead>\n <tr>\n {block.head.map((cell, i) => (\n <th key={i} scope=\"col\">\n {line(cell)}\n </th>\n ))}\n </tr>\n </thead>\n <tbody>\n {block.rows.map((row, r) => (\n <tr key={r}>\n {block.head.map((_, c) => (\n <td key={c}>{line(row[c] ?? \"\")}</td>\n ))}\n </tr>\n ))}\n </tbody>\n </table>\n </div>\n );\n default:\n return <p key={index}>{line(block.text)}</p>;\n }\n })}\n <Fragment />\n </div>\n );\n}\n"]}
@@ -47,6 +47,20 @@ export declare function drawerBox(holder: NavBox | undefined, viewport: {
47
47
  width: number;
48
48
  height: number;
49
49
  }, least?: number): NavBox | undefined;
50
+ /**
51
+ * Where the drawer's stage is put, in the px its `top` and `left` are counted in. A fixed box is placed from the window
52
+ * unless something around it is its containing block: a `.sf-container` in a browser where a container query brings
53
+ * layout containment (Chrome 156 does not), or anything a host has contained, transformed or filtered. `origin` is where that block starts on screen, measured
54
+ * from the stage itself, and the box is counted from there. With the window as the block nothing changes, and no box
55
+ * stays no box (the stylesheet's own window). Inside another block "the whole window" has to be worked out too.
56
+ */
57
+ export declare function stageBox(box: NavBox | undefined, origin: {
58
+ top: number;
59
+ left: number;
60
+ }, viewport: {
61
+ width: number;
62
+ height: number;
63
+ }): NavBox | undefined;
50
64
  /** "Site navigation" for "Site", and "Main navigation" left as it is: a label that already says so is not said twice. */
51
65
  export declare const navigationName: (label: string) => string;
52
66
  /**