@sdxc/ui 2026.11.10 → 2026.11.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +92 -45
- package/dist/app/app-shell-toggle.d.ts +2 -0
- package/dist/app/app-shell-toggle.js +5 -2
- package/dist/app/app-shell.d.ts +25 -1
- package/dist/app/app-shell.js +73 -38
- package/dist/app/auto-refresh.d.ts +2 -0
- package/dist/app/auto-refresh.js +3 -3
- package/dist/app/behaviors/refresh-schedule.d.ts +8 -3
- package/dist/app/behaviors/refresh-schedule.js +4 -3
- package/dist/app/board.d.ts +123 -0
- package/dist/app/board.js +224 -0
- package/dist/app/chart.d.ts +2 -2
- package/dist/app/chart.js +7 -3
- package/dist/app/check-runs.d.ts +116 -0
- package/dist/app/check-runs.js +201 -0
- package/dist/app/code-view.d.ts +172 -0
- package/dist/app/code-view.js +414 -0
- package/dist/app/command-palette.d.ts +38 -3
- package/dist/app/command-palette.js +53 -5
- package/dist/app/contribution-graph.d.ts +106 -0
- package/dist/app/contribution-graph.js +289 -0
- package/dist/app/detail-sheet.d.ts +7 -0
- package/dist/app/detail-sheet.js +7 -7
- package/dist/app/diff.d.ts +200 -0
- package/dist/app/diff.js +702 -0
- package/dist/app/filter-bar.d.ts +20 -0
- package/dist/app/filter-bar.js +35 -15
- package/dist/app/filter-menu.d.ts +144 -0
- package/dist/app/filter-menu.js +480 -0
- package/dist/app/gantt.d.ts +108 -0
- package/dist/app/gantt.js +420 -0
- package/dist/app/index.d.ts +19 -0
- package/dist/app/index.js +19 -0
- package/dist/app/log-viewer.d.ts +120 -0
- package/dist/app/log-viewer.js +384 -0
- package/dist/app/merge-box.d.ts +97 -0
- package/dist/app/merge-box.js +227 -0
- package/dist/app/mixins/app-shell-controls.d.ts +4 -1
- package/dist/app/mixins/app-shell-controls.js +64 -4
- package/dist/app/mixins/auto-refresh.d.ts +5 -2
- package/dist/app/mixins/auto-refresh.js +9 -3
- package/dist/app/mixins/close-popover-on-submit.d.ts +16 -0
- package/dist/app/mixins/close-popover-on-submit.js +32 -0
- package/dist/app/mixins/code-view-selection.d.ts +60 -0
- package/dist/app/mixins/code-view-selection.js +276 -0
- package/dist/app/mixins/command-palette.d.ts +15 -4
- package/dist/app/mixins/command-palette.js +94 -6
- package/dist/app/mixins/contribution-graph-keys.d.ts +19 -0
- package/dist/app/mixins/contribution-graph-keys.js +155 -0
- package/dist/app/mixins/diff-interactions.d.ts +72 -0
- package/dist/app/mixins/diff-interactions.js +269 -0
- package/dist/app/mixins/filter-menu-keys.d.ts +41 -0
- package/dist/app/mixins/filter-menu-keys.js +91 -0
- package/dist/app/mixins/gantt-today.d.ts +17 -0
- package/dist/app/mixins/gantt-today.js +50 -0
- package/dist/app/mixins/log-viewer.d.ts +29 -0
- package/dist/app/mixins/log-viewer.js +333 -0
- package/dist/app/mixins/optimistic-toggle-sync.d.ts +5 -0
- package/dist/app/mixins/optimistic-toggle-sync.js +25 -1
- package/dist/app/mixins/save-bar-sync.d.ts +7 -1
- package/dist/app/mixins/save-bar-sync.js +23 -4
- package/dist/app/mixins/save-status-sync.js +23 -1
- package/dist/app/mixins/split-view.js +1 -1
- package/dist/app/mixins/submit-on-close.d.ts +17 -0
- package/dist/app/mixins/submit-on-close.js +52 -0
- package/dist/app/mixins/tree-filter.d.ts +44 -0
- package/dist/app/mixins/tree-filter.js +111 -0
- package/dist/app/mixins/tree-navigation.d.ts +50 -0
- package/dist/app/mixins/tree-navigation.js +216 -0
- package/dist/app/optimistic-toggle.d.ts +8 -0
- package/dist/app/optimistic-toggle.js +3 -2
- package/dist/app/page-header.d.ts +18 -3
- package/dist/app/page-header.js +105 -50
- package/dist/app/review-thread.d.ts +115 -0
- package/dist/app/review-thread.js +116 -0
- package/dist/app/save-bar.d.ts +5 -0
- package/dist/app/save-bar.js +1 -1
- package/dist/app/settings-layout.d.ts +5 -0
- package/dist/app/settings-layout.js +5 -5
- package/dist/app/skeleton.d.ts +9 -0
- package/dist/app/skeleton.js +28 -0
- package/dist/app/split-view.d.ts +4 -0
- package/dist/app/split-view.js +3 -3
- package/dist/app/styles/code-tokens.d.ts +24 -0
- package/dist/app/styles/code-tokens.js +47 -0
- package/dist/app/tab-bar.d.ts +59 -0
- package/dist/app/tab-bar.js +111 -0
- package/dist/app/tree.d.ts +111 -14
- package/dist/app/tree.js +202 -15
- package/dist/app/utils/ansi.d.ts +55 -0
- package/dist/app/utils/ansi.js +157 -0
- package/dist/app/utils/diff-rows.d.ts +82 -0
- package/dist/app/utils/diff-rows.js +209 -0
- package/dist/app/utils/fuzzy-path.d.ts +58 -0
- package/dist/app/utils/fuzzy-path.js +202 -0
- package/dist/app/utils/line-range.d.ts +48 -0
- package/dist/app/utils/line-range.js +61 -0
- package/dist/app/utils/log-lines.d.ts +107 -0
- package/dist/app/utils/log-lines.js +170 -0
- package/dist/app/utils/tree-filter.d.ts +19 -0
- package/dist/app/utils/tree-filter.js +26 -0
- package/dist/app/view-options.d.ts +2 -0
- package/dist/app/view-options.js +2 -2
- package/dist/chat/activity.d.ts +72 -0
- package/dist/chat/activity.js +184 -0
- package/dist/chat/composer-submit.d.ts +38 -0
- package/dist/chat/composer-submit.js +44 -0
- package/dist/chat/composer.d.ts +47 -0
- package/dist/chat/composer.js +100 -0
- package/dist/chat/index.d.ts +6 -0
- package/dist/chat/index.js +6 -0
- package/dist/chat/mixins/composer-send.d.ts +32 -0
- package/dist/chat/mixins/composer-send.js +121 -0
- package/dist/chat/mixins/reveal-stream.d.ts +68 -0
- package/dist/chat/mixins/reveal-stream.js +184 -0
- package/dist/chat/mixins/stream-target.d.ts +18 -0
- package/dist/chat/mixins/stream-target.js +38 -0
- package/dist/components/button.js +7 -1
- package/dist/components/character-count.d.ts +44 -0
- package/dist/components/character-count.js +68 -0
- package/dist/components/index.d.ts +2 -0
- package/dist/components/index.js +2 -0
- package/dist/components/label-chip.d.ts +42 -0
- package/dist/components/label-chip.js +86 -0
- package/dist/components/property-list.d.ts +9 -2
- package/dist/components/property-list.js +11 -6
- package/dist/components/textarea.js +6 -1
- package/dist/components/timeline.d.ts +62 -5
- package/dist/components/timeline.js +124 -5
- package/dist/docs/code-block.js +8 -31
- package/dist/docs/file-tree.js +3 -48
- package/dist/landing/case-study.d.ts +79 -0
- package/dist/landing/case-study.js +162 -0
- package/dist/landing/contributor-wall.d.ts +72 -0
- package/dist/landing/contributor-wall.js +129 -0
- package/dist/landing/countdown.d.ts +88 -0
- package/dist/landing/countdown.js +91 -0
- package/dist/landing/episode-player.d.ts +87 -0
- package/dist/landing/episode-player.js +113 -0
- package/dist/landing/faq-band.d.ts +3 -2
- package/dist/landing/faq-band.js +4 -3
- package/dist/landing/feature-band.d.ts +8 -0
- package/dist/landing/feature-band.js +9 -3
- package/dist/landing/index.d.ts +9 -0
- package/dist/landing/index.js +9 -0
- package/dist/landing/landing-header.js +15 -4
- package/dist/landing/mixins/countdown-tick.d.ts +29 -0
- package/dist/landing/mixins/countdown-tick.js +65 -0
- package/dist/landing/mixins/usage-estimate-live.d.ts +32 -0
- package/dist/landing/mixins/usage-estimate-live.js +120 -0
- package/dist/landing/phone-fan.d.ts +38 -0
- package/dist/landing/phone-fan.js +89 -0
- package/dist/landing/phone-frame.d.ts +48 -0
- package/dist/landing/phone-frame.js +41 -0
- package/dist/landing/price-list.d.ts +68 -0
- package/dist/landing/price-list.js +125 -0
- package/dist/landing/scroll-scene.d.ts +59 -0
- package/dist/landing/scroll-scene.js +70 -0
- package/dist/landing/sponsor-wall.d.ts +30 -6
- package/dist/landing/sponsor-wall.js +70 -14
- package/dist/landing/typed-terminal.d.ts +24 -6
- package/dist/landing/typed-terminal.js +22 -14
- package/dist/landing/usage-estimate.d.ts +127 -0
- package/dist/landing/usage-estimate.js +164 -0
- package/dist/landing/utils/countdown.d.ts +33 -0
- package/dist/landing/utils/countdown.js +42 -0
- package/dist/landing/utils/pause-toggle.d.ts +2 -1
- package/dist/mixins/character-count.d.ts +62 -0
- package/dist/mixins/character-count.js +139 -0
- package/dist/mixins/index.d.ts +6 -2
- package/dist/mixins/index.js +6 -2
- package/dist/mixins/invoker-fields.d.ts +18 -0
- package/dist/mixins/invoker-fields.js +60 -0
- package/dist/mixins/media-sync.d.ts +58 -0
- package/dist/mixins/media-sync.js +102 -0
- package/dist/mixins/menu-keys.d.ts +11 -0
- package/dist/mixins/menu-keys.js +79 -70
- package/dist/mixins/sortable.d.ts +96 -0
- package/dist/mixins/sortable.js +433 -0
- package/dist/utils/code-lines.d.ts +26 -0
- package/dist/utils/code-lines.js +29 -0
- package/dist/utils/file-icon.d.ts +31 -0
- package/dist/utils/file-icon.js +60 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/write-cookie.d.ts +15 -15
- package/dist/utils/write-cookie.js +10 -16
- package/dist/video/index.d.ts +11 -0
- package/dist/video/index.js +11 -0
- package/dist/video/mixins/video-player-sync.d.ts +27 -0
- package/dist/video/mixins/video-player-sync.js +413 -0
- package/dist/video/utils/timeline.d.ts +55 -0
- package/dist/video/utils/timeline.js +90 -0
- package/dist/video/video-player.d.ts +261 -0
- package/dist/video/video-player.js +927 -0
- package/package.json +6 -3
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
import { jsx as _jsx } from "remix/component/jsx-runtime";
|
|
2
|
+
import { bg, border, fg, outline } from "@sdxc/u/color";
|
|
3
|
+
import { shadow } from "@sdxc/u/effects";
|
|
4
|
+
import { mergeMix, raw } from "@sdxc/u/general";
|
|
5
|
+
import { hstack, vstack } from "@sdxc/u/layout";
|
|
6
|
+
import { media } from "@sdxc/u/responsive";
|
|
7
|
+
import { m, p } from "@sdxc/u/size";
|
|
8
|
+
import { when } from "@sdxc/u/state";
|
|
9
|
+
import { text } from "@sdxc/u/typography";
|
|
10
|
+
/** The slot the text field carries, which `ComposerSubmit` finds to send on Enter. */
|
|
11
|
+
export const COMPOSER_INPUT_SLOT = "composer-input";
|
|
12
|
+
/**
|
|
13
|
+
* Renders the composer's surface: one rounded box that draws the focus ring for the field
|
|
14
|
+
* inside it, so the field, its attachments and its toolbar read as a single control.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* <Composer method="post" action="/chat">
|
|
18
|
+
* <Composer.Input name="prompt" aria-label="Message" required />
|
|
19
|
+
* <Composer.Toolbar><ComposerSubmit labels={{ send: "Send", stop: "Stop" }} /></Composer.Toolbar>
|
|
20
|
+
* </Composer>
|
|
21
|
+
*/
|
|
22
|
+
export function Composer(handle) {
|
|
23
|
+
return () => {
|
|
24
|
+
let { children, mix, ...rest } = handle.props;
|
|
25
|
+
return (_jsx("form", { ...rest, "data-slot": "composer", mix: mergeMix([
|
|
26
|
+
vstack({ gap: 1, align: "stretch" }),
|
|
27
|
+
p(2),
|
|
28
|
+
raw({ borderRadius: "var(--ui-composer-radius, calc(var(--ui-radius-lg) * 2))" }),
|
|
29
|
+
border({ color: "neutral", width: 1 }),
|
|
30
|
+
bg(),
|
|
31
|
+
shadow("sm"),
|
|
32
|
+
when("&:focus-within", [
|
|
33
|
+
border("neutral.border-strong"),
|
|
34
|
+
outline({ color: "neutral.ring", offset: 0 }),
|
|
35
|
+
]),
|
|
36
|
+
], mix), children: children }));
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* The message field: borderless inside the composer's frame, one line tall when empty,
|
|
41
|
+
* growing with its text to `--ui-composer-max-block-size` (twelve lines) and scrolling past it.
|
|
42
|
+
*/
|
|
43
|
+
Composer.Input = function ComposerInput(handle) {
|
|
44
|
+
return () => {
|
|
45
|
+
let { mix, rows = 1, ...rest } = handle.props;
|
|
46
|
+
return (_jsx("textarea", { ...rest, rows: rows, "data-slot": COMPOSER_INPUT_SLOT, mix: mergeMix([
|
|
47
|
+
m(0),
|
|
48
|
+
raw({
|
|
49
|
+
display: "block",
|
|
50
|
+
inlineSize: "100%",
|
|
51
|
+
boxSizing: "border-box",
|
|
52
|
+
paddingInline: "0.5rem",
|
|
53
|
+
paddingBlock: "0.5rem",
|
|
54
|
+
border: "none",
|
|
55
|
+
background: "transparent",
|
|
56
|
+
color: "inherit",
|
|
57
|
+
font: "inherit",
|
|
58
|
+
fontSize: "1rem",
|
|
59
|
+
lineHeight: "1.5",
|
|
60
|
+
resize: "none",
|
|
61
|
+
fieldSizing: "content",
|
|
62
|
+
minBlockSize: "calc(1lh + 1rem)",
|
|
63
|
+
maxBlockSize: "var(--ui-composer-max-block-size, calc(12lh + 1rem))",
|
|
64
|
+
overflowY: "auto",
|
|
65
|
+
outline: "none",
|
|
66
|
+
}),
|
|
67
|
+
when("&::placeholder", fg("neutral.fg-muted")),
|
|
68
|
+
], mix) }));
|
|
69
|
+
};
|
|
70
|
+
};
|
|
71
|
+
/** The row under the field: controls at the start, the hint and send control at the end. */
|
|
72
|
+
Composer.Toolbar = function ComposerToolbar(handle) {
|
|
73
|
+
return () => {
|
|
74
|
+
let { children, mix, ...rest } = handle.props;
|
|
75
|
+
return (_jsx("div", { ...rest, "data-slot": "composer-toolbar", mix: mergeMix([hstack({ gap: 1, align: "center" }), raw({ minInlineSize: 0 })], mix), children: children }));
|
|
76
|
+
};
|
|
77
|
+
};
|
|
78
|
+
/**
|
|
79
|
+
* How to send, set at the toolbar's end before the send control. It truncates rather than
|
|
80
|
+
* widen a narrow composer, and hides on touch screens, where only the send button sends.
|
|
81
|
+
*/
|
|
82
|
+
Composer.Hint = function ComposerHint(handle) {
|
|
83
|
+
return () => {
|
|
84
|
+
let { children, mix, ...rest } = handle.props;
|
|
85
|
+
return (_jsx("p", { ...rest, "data-slot": "composer-hint", mix: mergeMix([
|
|
86
|
+
m(0),
|
|
87
|
+
raw({
|
|
88
|
+
marginInlineStart: "auto",
|
|
89
|
+
paddingInline: "0.5rem",
|
|
90
|
+
minInlineSize: 0,
|
|
91
|
+
overflow: "hidden",
|
|
92
|
+
whiteSpace: "nowrap",
|
|
93
|
+
textOverflow: "ellipsis",
|
|
94
|
+
}),
|
|
95
|
+
text("xs"),
|
|
96
|
+
fg("neutral.fg-muted"),
|
|
97
|
+
media("(hover: none)", raw({ display: "none" })),
|
|
98
|
+
], mix), children: children }));
|
|
99
|
+
};
|
|
100
|
+
};
|
package/dist/chat/index.d.ts
CHANGED
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
export * from "./activity.js";
|
|
9
10
|
export * from "./attachment.js";
|
|
10
11
|
export * from "./behaviors/scroll-follow-model.js";
|
|
12
|
+
export * from "./mixins/reveal-stream.js";
|
|
11
13
|
export * from "./bubble.js";
|
|
14
|
+
export * from "./composer-submit.js";
|
|
15
|
+
export * from "./composer.js";
|
|
12
16
|
export * from "./marker.js";
|
|
13
17
|
export * from "./message-scroller.js";
|
|
14
18
|
export * from "./message.js";
|
|
15
19
|
export * from "./mixins/attachment-trigger.js";
|
|
20
|
+
export * from "./mixins/composer-send.js";
|
|
16
21
|
export * from "./mixins/message-follow.js";
|
|
22
|
+
export * from "./mixins/stream-target.js";
|
package/dist/chat/index.js
CHANGED
|
@@ -6,11 +6,17 @@
|
|
|
6
6
|
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
7
|
* @copyright Sergio Xalambrí 2026
|
|
8
8
|
*/
|
|
9
|
+
export * from "./activity.js";
|
|
9
10
|
export * from "./attachment.js";
|
|
10
11
|
export * from "./behaviors/scroll-follow-model.js";
|
|
12
|
+
export * from "./mixins/reveal-stream.js";
|
|
11
13
|
export * from "./bubble.js";
|
|
14
|
+
export * from "./composer-submit.js";
|
|
15
|
+
export * from "./composer.js";
|
|
12
16
|
export * from "./marker.js";
|
|
13
17
|
export * from "./message-scroller.js";
|
|
14
18
|
export * from "./message.js";
|
|
15
19
|
export * from "./mixins/attachment-trigger.js";
|
|
20
|
+
export * from "./mixins/composer-send.js";
|
|
16
21
|
export * from "./mixins/message-follow.js";
|
|
22
|
+
export * from "./mixins/stream-target.js";
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wires a composer's send control: Enter sends, Shift+Enter writes a new line, the field
|
|
3
|
+
* clears once a message goes, and a reply the page just answered replays as a stream that
|
|
4
|
+
* Stop or Escape freezes. Why JS: keys, clearing and the replay need script. No-JS baseline:
|
|
5
|
+
* the send button submits the form, Enter writes a new line, and the reply shows whole.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import type { MixinFactory } from "remix/component";
|
|
11
|
+
/** The slot of the button that stops a streaming reply, inside the mixin's host. */
|
|
12
|
+
export declare const COMPOSER_STOP_SLOT = "composer-stop";
|
|
13
|
+
/** Options for {@link composerSend}. */
|
|
14
|
+
export interface ComposerSendOptions {
|
|
15
|
+
/**
|
|
16
|
+
* The `id` of a reply the page just answered with, marked `data-stream-pending`; it replays
|
|
17
|
+
* as a stream, or shows at once under reduced motion.
|
|
18
|
+
*/
|
|
19
|
+
stream?: string;
|
|
20
|
+
/** Changes with every new reply, so a reply that reuses the previous one's `id` replays too. */
|
|
21
|
+
streamKey?: string;
|
|
22
|
+
/** Told when a replay starts and ends, so the host can swap Send for Stop. */
|
|
23
|
+
onStreamingChange: (streaming: boolean) => void;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Put on an element inside a composer's form, around its send and stop buttons. It finds the
|
|
27
|
+
* form's `Composer.Input`, and a click on a `[data-slot="composer-stop"]` inside it stops the
|
|
28
|
+
* replay.
|
|
29
|
+
*
|
|
30
|
+
* @example <span mix={[composerSend({ stream: "reply-7", onStreamingChange: (on) => … })]}>…</span>
|
|
31
|
+
*/
|
|
32
|
+
export declare const composerSend: MixinFactory<HTMLElement, [options: ComposerSendOptions]>;
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Wires a composer's send control: Enter sends, Shift+Enter writes a new line, the field
|
|
3
|
+
* clears once a message goes, and a reply the page just answered replays as a stream that
|
|
4
|
+
* Stop or Escape freezes. Why JS: keys, clearing and the replay need script. No-JS baseline:
|
|
5
|
+
* the send button submits the form, Enter writes a new line, and the reply shows whole.
|
|
6
|
+
*
|
|
7
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
8
|
+
* @copyright Sergio Xalambrí 2026
|
|
9
|
+
*/
|
|
10
|
+
import { createMixin } from "remix/component";
|
|
11
|
+
import { prefersReducedMotion } from "../../utils/prefers-reduced-motion.js";
|
|
12
|
+
import { COMPOSER_INPUT_SLOT } from "../composer.js";
|
|
13
|
+
import { STREAM_PENDING_ATTRIBUTE, collapseStream, revealStream } from "./reveal-stream.js";
|
|
14
|
+
/**
|
|
15
|
+
* Empties the field once the submission it belongs to has been read. A script that takes the
|
|
16
|
+
* submission over (`preventDefault` in a later `submit` listener) reads it during `submit`, so
|
|
17
|
+
* the field empties a task later. A navigation's form data is taken when its `navigate` event
|
|
18
|
+
* fires, which for a multipart form comes a task after `submit`, so it empties after that.
|
|
19
|
+
*/
|
|
20
|
+
function clearAfterSubmit(event, input, signal) {
|
|
21
|
+
let clear = () => setTimeout(() => (input.value = ""));
|
|
22
|
+
let navigation = input.ownerDocument.defaultView?.navigation;
|
|
23
|
+
if (navigation === undefined)
|
|
24
|
+
return clear();
|
|
25
|
+
let controller = new AbortController();
|
|
26
|
+
signal.addEventListener("abort", () => controller.abort(), { once: true });
|
|
27
|
+
navigation.addEventListener("navigate", clear, { once: true, signal: controller.signal });
|
|
28
|
+
setTimeout(() => {
|
|
29
|
+
if (!event.defaultPrevented)
|
|
30
|
+
return;
|
|
31
|
+
controller.abort();
|
|
32
|
+
input.value = "";
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** The slot of the button that stops a streaming reply, inside the mixin's host. */
|
|
36
|
+
export const COMPOSER_STOP_SLOT = "composer-stop";
|
|
37
|
+
/**
|
|
38
|
+
* Put on an element inside a composer's form, around its send and stop buttons. It finds the
|
|
39
|
+
* form's `Composer.Input`, and a click on a `[data-slot="composer-stop"]` inside it stops the
|
|
40
|
+
* replay.
|
|
41
|
+
*
|
|
42
|
+
* @example <span mix={[composerSend({ stream: "reply-7", onStreamingChange: (on) => … })]}>…</span>
|
|
43
|
+
*/
|
|
44
|
+
export const composerSend = createMixin((handle) => {
|
|
45
|
+
let options;
|
|
46
|
+
let host;
|
|
47
|
+
/** The host's lifetime, taken while it is inserted, so a replay started later still ends with it. */
|
|
48
|
+
let lifetime;
|
|
49
|
+
let started;
|
|
50
|
+
let streaming = false;
|
|
51
|
+
let stop = () => { };
|
|
52
|
+
/** Records the replay's state and tells the host. */
|
|
53
|
+
function setStreaming(next) {
|
|
54
|
+
if (streaming === next)
|
|
55
|
+
return;
|
|
56
|
+
streaming = next;
|
|
57
|
+
options?.onStreamingChange(next);
|
|
58
|
+
}
|
|
59
|
+
/** Replays the reply `stream` names, once per key, while it is still pending. */
|
|
60
|
+
function startStream() {
|
|
61
|
+
let id = options?.stream;
|
|
62
|
+
let key = `${id}|${options?.streamKey ?? ""}`;
|
|
63
|
+
if (id === undefined || host === undefined || key === started)
|
|
64
|
+
return;
|
|
65
|
+
let target = host.ownerDocument.getElementById(id);
|
|
66
|
+
if (target === null || !target.hasAttribute(STREAM_PENDING_ATTRIBUTE))
|
|
67
|
+
return;
|
|
68
|
+
started = key;
|
|
69
|
+
stop();
|
|
70
|
+
if (prefersReducedMotion()) {
|
|
71
|
+
target.removeAttribute(STREAM_PENDING_ATTRIBUTE);
|
|
72
|
+
collapseStream(target);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
let controller = new AbortController();
|
|
76
|
+
lifetime?.addEventListener("abort", () => controller.abort(), { once: true });
|
|
77
|
+
let reveal = revealStream(target, {
|
|
78
|
+
signal: controller.signal,
|
|
79
|
+
onEnd: () => {
|
|
80
|
+
stop = () => { };
|
|
81
|
+
setStreaming(false);
|
|
82
|
+
},
|
|
83
|
+
});
|
|
84
|
+
stop = () => reveal.stop();
|
|
85
|
+
setStreaming(true);
|
|
86
|
+
}
|
|
87
|
+
handle.addEventListener("insert", ({ node }) => {
|
|
88
|
+
host = node;
|
|
89
|
+
let signal = handle.signal;
|
|
90
|
+
lifetime = signal;
|
|
91
|
+
let form = node.closest("form");
|
|
92
|
+
let input = form?.querySelector(`[data-slot="${COMPOSER_INPUT_SLOT}"]`);
|
|
93
|
+
input?.addEventListener("keydown", (event) => {
|
|
94
|
+
if (event.key === "Escape" && streaming)
|
|
95
|
+
return stop();
|
|
96
|
+
if (event.key !== "Enter" || event.shiftKey || event.altKey || event.isComposing)
|
|
97
|
+
return;
|
|
98
|
+
event.preventDefault();
|
|
99
|
+
if (streaming || input.value.trim() === "")
|
|
100
|
+
return;
|
|
101
|
+
form?.requestSubmit();
|
|
102
|
+
}, { signal });
|
|
103
|
+
form?.addEventListener("submit", (event) => {
|
|
104
|
+
if (event.defaultPrevented || !input)
|
|
105
|
+
return;
|
|
106
|
+
clearAfterSubmit(event, input, signal);
|
|
107
|
+
}, { signal });
|
|
108
|
+
node.addEventListener("click", (event) => {
|
|
109
|
+
if (!(event.target instanceof Element))
|
|
110
|
+
return;
|
|
111
|
+
if (event.target.closest(`[data-slot="${COMPOSER_STOP_SLOT}"]`))
|
|
112
|
+
stop();
|
|
113
|
+
}, { signal });
|
|
114
|
+
startStream();
|
|
115
|
+
});
|
|
116
|
+
return (next) => {
|
|
117
|
+
options = next;
|
|
118
|
+
handle.queueTask(() => startStream());
|
|
119
|
+
return handle.element;
|
|
120
|
+
};
|
|
121
|
+
});
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replays a server-rendered reply as if it were arriving from a model: its text shows a few
|
|
3
|
+
* words at a time and each block (a paragraph, a list item, a table row, a code block) appears
|
|
4
|
+
* when the text reaches it. The markup is already final, so a stop keeps what has shown.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Attribute a reply waiting to stream carries in the server's HTML; `streamTarget()` keeps it
|
|
11
|
+
* unpainted while scripts run and motion is allowed, and {@link revealStream} removes it.
|
|
12
|
+
*/
|
|
13
|
+
export declare const STREAM_PENDING_ATTRIBUTE = "data-stream-pending";
|
|
14
|
+
/** Attribute {@link revealStream} sets on the reply when it ends: `"done"` or `"stopped"`. */
|
|
15
|
+
export declare const STREAM_END_ATTRIBUTE = "data-stream-end";
|
|
16
|
+
/** Attribute {@link revealStream} keeps on the block it showed last, while it runs. */
|
|
17
|
+
export declare const STREAM_CURRENT_ATTRIBUTE = "data-stream-current";
|
|
18
|
+
/**
|
|
19
|
+
* Attribute a block carries to hold the replay that many milliseconds once it shows, for a
|
|
20
|
+
* step that should read as taking time.
|
|
21
|
+
*/
|
|
22
|
+
export declare const STREAM_PAUSE_ATTRIBUTE = "data-stream-pause";
|
|
23
|
+
/**
|
|
24
|
+
* Attribute a `<details>` carries to fold away once the replay moves past it, such as an
|
|
25
|
+
* assistant's thinking once its answer starts.
|
|
26
|
+
*/
|
|
27
|
+
export declare const STREAM_COLLAPSE_ATTRIBUTE = "data-stream-collapse";
|
|
28
|
+
/** Attribute a folded `<details>` gains, so its summary can say it is done. */
|
|
29
|
+
export declare const STREAM_COLLAPSED_ATTRIBUTE = "data-stream-collapsed";
|
|
30
|
+
/** Attribute {@link revealStream} puts on a block the text has not reached yet. */
|
|
31
|
+
export declare const STREAM_HIDDEN_ATTRIBUTE = "data-stream-hidden";
|
|
32
|
+
/** How a reveal finished. */
|
|
33
|
+
export type StreamRevealEnd = "done" | "stopped";
|
|
34
|
+
/** Options for {@link revealStream}. */
|
|
35
|
+
export interface StreamRevealOptions {
|
|
36
|
+
/** Milliseconds between ticks. @default 32 */
|
|
37
|
+
interval?: number;
|
|
38
|
+
/** Called once, when the whole reply has shown or {@link StreamReveal.stop} ran. */
|
|
39
|
+
onEnd?: (end: StreamRevealEnd) => void;
|
|
40
|
+
/** Stops the reveal where it is when aborted, as {@link StreamReveal.stop} does. */
|
|
41
|
+
signal?: AbortSignal;
|
|
42
|
+
}
|
|
43
|
+
/** A running reveal. */
|
|
44
|
+
export interface StreamReveal {
|
|
45
|
+
/** Freezes the reply at what has shown; the rest of it stays out of the page. */
|
|
46
|
+
stop(): void;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Starts revealing `root`'s content from nothing. Text inside buttons and
|
|
50
|
+
* `[data-stream-skip]` is left whole, and whitespace between blocks is kept, so the
|
|
51
|
+
* finished reply is exactly the markup the server sent.
|
|
52
|
+
*
|
|
53
|
+
* @param root The reply's element, already holding its final content.
|
|
54
|
+
* @param options Pace, completion callback and an abort signal.
|
|
55
|
+
* @returns The running reveal.
|
|
56
|
+
* @example revealStream(document.getElementById("reply-7")!, { onEnd: () => setIdle() })
|
|
57
|
+
*/
|
|
58
|
+
export declare function revealStream(root: HTMLElement, options?: StreamRevealOptions): StreamReveal;
|
|
59
|
+
/**
|
|
60
|
+
* Folds every `[data-stream-collapse]` disclosure in `root` that comes before `block`, or all
|
|
61
|
+
* of them without one, marking each `data-stream-collapsed`. A reply shown without a replay
|
|
62
|
+
* calls it with no block, so it reads the same as one that streamed.
|
|
63
|
+
*
|
|
64
|
+
* @param root The reply.
|
|
65
|
+
* @param block The block the replay is about to show.
|
|
66
|
+
* @example collapseStream(document.getElementById("reply-7")!)
|
|
67
|
+
*/
|
|
68
|
+
export declare function collapseStream(root: HTMLElement, block?: Element): void;
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Replays a server-rendered reply as if it were arriving from a model: its text shows a few
|
|
3
|
+
* words at a time and each block (a paragraph, a list item, a table row, a code block) appears
|
|
4
|
+
* when the text reaches it. The markup is already final, so a stop keeps what has shown.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Attribute a reply waiting to stream carries in the server's HTML; `streamTarget()` keeps it
|
|
11
|
+
* unpainted while scripts run and motion is allowed, and {@link revealStream} removes it.
|
|
12
|
+
*/
|
|
13
|
+
export const STREAM_PENDING_ATTRIBUTE = "data-stream-pending";
|
|
14
|
+
/** Attribute {@link revealStream} sets on the reply when it ends: `"done"` or `"stopped"`. */
|
|
15
|
+
export const STREAM_END_ATTRIBUTE = "data-stream-end";
|
|
16
|
+
/** Attribute {@link revealStream} keeps on the block it showed last, while it runs. */
|
|
17
|
+
export const STREAM_CURRENT_ATTRIBUTE = "data-stream-current";
|
|
18
|
+
/**
|
|
19
|
+
* Attribute a block carries to hold the replay that many milliseconds once it shows, for a
|
|
20
|
+
* step that should read as taking time.
|
|
21
|
+
*/
|
|
22
|
+
export const STREAM_PAUSE_ATTRIBUTE = "data-stream-pause";
|
|
23
|
+
/**
|
|
24
|
+
* Attribute a `<details>` carries to fold away once the replay moves past it, such as an
|
|
25
|
+
* assistant's thinking once its answer starts.
|
|
26
|
+
*/
|
|
27
|
+
export const STREAM_COLLAPSE_ATTRIBUTE = "data-stream-collapse";
|
|
28
|
+
/** Attribute a folded `<details>` gains, so its summary can say it is done. */
|
|
29
|
+
export const STREAM_COLLAPSED_ATTRIBUTE = "data-stream-collapsed";
|
|
30
|
+
/** Attribute {@link revealStream} puts on a block the text has not reached yet. */
|
|
31
|
+
export const STREAM_HIDDEN_ATTRIBUTE = "data-stream-hidden";
|
|
32
|
+
/** Elements that appear whole once the reveal reaches them, so a half-built list never shows. */
|
|
33
|
+
const BLOCK_SELECTOR = "p, li, tr, h1, h2, h3, h4, h5, h6, pre, figure, blockquote, table, ul, ol, dl, dt, dd, hr, img, [data-stream-block]";
|
|
34
|
+
/**
|
|
35
|
+
* Controls, notes that belong to the reply's frame, and the folded content of a closed
|
|
36
|
+
* disclosure, which stay whole and shown throughout.
|
|
37
|
+
*/
|
|
38
|
+
const SKIP_SELECTOR = "button, [data-stream-skip], details:not([open]) > :not(summary)";
|
|
39
|
+
/** Words per tick, cycled, so the pace reads as a model's uneven chunks. */
|
|
40
|
+
const CHUNKS = [2, 1, 3, 2, 1, 2];
|
|
41
|
+
/** Milliseconds between ticks. */
|
|
42
|
+
const DEFAULT_INTERVAL = 32;
|
|
43
|
+
/**
|
|
44
|
+
* Starts revealing `root`'s content from nothing. Text inside buttons and
|
|
45
|
+
* `[data-stream-skip]` is left whole, and whitespace between blocks is kept, so the
|
|
46
|
+
* finished reply is exactly the markup the server sent.
|
|
47
|
+
*
|
|
48
|
+
* @param root The reply's element, already holding its final content.
|
|
49
|
+
* @param options Pace, completion callback and an abort signal.
|
|
50
|
+
* @returns The running reveal.
|
|
51
|
+
* @example revealStream(document.getElementById("reply-7")!, { onEnd: () => setIdle() })
|
|
52
|
+
*/
|
|
53
|
+
export function revealStream(root, options = {}) {
|
|
54
|
+
let { interval = DEFAULT_INTERVAL, onEnd, signal } = options;
|
|
55
|
+
let runs = collectRuns(root);
|
|
56
|
+
let blocks = [...root.querySelectorAll(BLOCK_SELECTOR)].filter((block) => block.closest(SKIP_SELECTOR) === null);
|
|
57
|
+
for (let block of blocks)
|
|
58
|
+
block.setAttribute(STREAM_HIDDEN_ATTRIBUTE, "");
|
|
59
|
+
for (let run of runs)
|
|
60
|
+
run.node.data = "";
|
|
61
|
+
root.removeAttribute(STREAM_PENDING_ATTRIBUTE);
|
|
62
|
+
root.setAttribute("aria-busy", "true");
|
|
63
|
+
let runIndex = 0;
|
|
64
|
+
let tokenIndex = 0;
|
|
65
|
+
let blockIndex = 0;
|
|
66
|
+
let tick = 0;
|
|
67
|
+
let ended = false;
|
|
68
|
+
let current;
|
|
69
|
+
let holdUntil = 0;
|
|
70
|
+
let waited = new Set();
|
|
71
|
+
/**
|
|
72
|
+
* Shows every hidden block that comes before `node` in the document or holds it. When the
|
|
73
|
+
* block shown last asks for a pause, it waits that long first and answers `false`.
|
|
74
|
+
*/
|
|
75
|
+
function showBlocksUpTo(node) {
|
|
76
|
+
while (blockIndex < blocks.length) {
|
|
77
|
+
let block = blocks[blockIndex];
|
|
78
|
+
let position = block.compareDocumentPosition(node);
|
|
79
|
+
let reached = position & Node.DOCUMENT_POSITION_FOLLOWING ||
|
|
80
|
+
position & Node.DOCUMENT_POSITION_CONTAINED_BY;
|
|
81
|
+
if (!reached)
|
|
82
|
+
return true;
|
|
83
|
+
let owner = current?.closest(`[${STREAM_PAUSE_ATTRIBUTE}]`);
|
|
84
|
+
let pause = Number(owner?.getAttribute(STREAM_PAUSE_ATTRIBUTE));
|
|
85
|
+
if (owner &&
|
|
86
|
+
root.contains(owner) &&
|
|
87
|
+
pause > 0 &&
|
|
88
|
+
!waited.has(owner) &&
|
|
89
|
+
!owner.contains(block)) {
|
|
90
|
+
waited.add(owner);
|
|
91
|
+
holdUntil = Date.now() + pause;
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
collapseStream(root, block);
|
|
95
|
+
block.removeAttribute(STREAM_HIDDEN_ATTRIBUTE);
|
|
96
|
+
current?.removeAttribute(STREAM_CURRENT_ATTRIBUTE);
|
|
97
|
+
block.setAttribute(STREAM_CURRENT_ATTRIBUTE, "");
|
|
98
|
+
current = block;
|
|
99
|
+
blockIndex++;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
/** Ends the reveal once, showing the rest when it ran to completion. */
|
|
104
|
+
function end(how) {
|
|
105
|
+
if (ended)
|
|
106
|
+
return;
|
|
107
|
+
ended = true;
|
|
108
|
+
clearInterval(timer);
|
|
109
|
+
current?.removeAttribute(STREAM_CURRENT_ATTRIBUTE);
|
|
110
|
+
if (how === "done") {
|
|
111
|
+
for (let block of blocks)
|
|
112
|
+
block.removeAttribute(STREAM_HIDDEN_ATTRIBUTE);
|
|
113
|
+
collapseStream(root);
|
|
114
|
+
}
|
|
115
|
+
root.removeAttribute("aria-busy");
|
|
116
|
+
root.setAttribute(STREAM_END_ATTRIBUTE, how);
|
|
117
|
+
onEnd?.(how);
|
|
118
|
+
}
|
|
119
|
+
/** Adds the next chunk of words to the reply. */
|
|
120
|
+
function step() {
|
|
121
|
+
if (Date.now() < holdUntil)
|
|
122
|
+
return;
|
|
123
|
+
let budget = CHUNKS[tick++ % CHUNKS.length];
|
|
124
|
+
while (budget > 0) {
|
|
125
|
+
let run = runs[runIndex];
|
|
126
|
+
if (run === undefined)
|
|
127
|
+
return end("done");
|
|
128
|
+
if (tokenIndex === 0 && !showBlocksUpTo(run.node))
|
|
129
|
+
return;
|
|
130
|
+
let token = run.tokens[tokenIndex++];
|
|
131
|
+
if (token !== undefined)
|
|
132
|
+
run.node.data += token;
|
|
133
|
+
if (tokenIndex >= run.tokens.length) {
|
|
134
|
+
runIndex++;
|
|
135
|
+
tokenIndex = 0;
|
|
136
|
+
}
|
|
137
|
+
if (token !== undefined && token.trim() !== "")
|
|
138
|
+
budget--;
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
let timer = setInterval(step, interval);
|
|
142
|
+
signal?.addEventListener("abort", () => end("stopped"), { once: true });
|
|
143
|
+
if (runs.length === 0)
|
|
144
|
+
end("done");
|
|
145
|
+
return { stop: () => end("stopped") };
|
|
146
|
+
}
|
|
147
|
+
/**
|
|
148
|
+
* Folds every `[data-stream-collapse]` disclosure in `root` that comes before `block`, or all
|
|
149
|
+
* of them without one, marking each `data-stream-collapsed`. A reply shown without a replay
|
|
150
|
+
* calls it with no block, so it reads the same as one that streamed.
|
|
151
|
+
*
|
|
152
|
+
* @param root The reply.
|
|
153
|
+
* @param block The block the replay is about to show.
|
|
154
|
+
* @example collapseStream(document.getElementById("reply-7")!)
|
|
155
|
+
*/
|
|
156
|
+
export function collapseStream(root, block) {
|
|
157
|
+
for (let details of root.querySelectorAll(`details[${STREAM_COLLAPSE_ATTRIBUTE}]:not([${STREAM_COLLAPSED_ATTRIBUTE}])`)) {
|
|
158
|
+
if (block !== undefined) {
|
|
159
|
+
if (details.contains(block))
|
|
160
|
+
continue;
|
|
161
|
+
if (!(details.compareDocumentPosition(block) & Node.DOCUMENT_POSITION_FOLLOWING))
|
|
162
|
+
continue;
|
|
163
|
+
}
|
|
164
|
+
details.open = false;
|
|
165
|
+
details.setAttribute(STREAM_COLLAPSED_ATTRIBUTE, "");
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Lists the reply's text nodes in reading order with their words, leaving out text that is
|
|
170
|
+
* only whitespace or belongs to a control.
|
|
171
|
+
*/
|
|
172
|
+
function collectRuns(root) {
|
|
173
|
+
let runs = [];
|
|
174
|
+
let walker = root.ownerDocument.createTreeWalker(root, NodeFilter.SHOW_TEXT);
|
|
175
|
+
for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
|
|
176
|
+
let text = node;
|
|
177
|
+
if (text.data.trim() === "")
|
|
178
|
+
continue;
|
|
179
|
+
if (text.parentElement?.closest(SKIP_SELECTOR))
|
|
180
|
+
continue;
|
|
181
|
+
runs.push({ node: text, tokens: text.data.match(/\s*\S+\s*/g) ?? [text.data] });
|
|
182
|
+
}
|
|
183
|
+
return runs;
|
|
184
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styles for a reply that streams in with `revealStream()`: a block the text has not reached
|
|
3
|
+
* stays out of the layout, and a reply still pending is unpainted while scripts run and
|
|
4
|
+
* motion is allowed, so the finished text never flashes before its replay starts.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { UtilityMixin } from "@sdxc/u";
|
|
10
|
+
/**
|
|
11
|
+
* Put on the element a reply streams into, the one carrying `data-stream-pending`. Without
|
|
12
|
+
* scripts, or under reduced motion, the reply shows whole at once; with them it waits for
|
|
13
|
+
* the replay, and shows whole after {@link FALLBACK_DELAY} if the replay never starts.
|
|
14
|
+
*
|
|
15
|
+
* @returns The mixins to spread into the reply's `mix`.
|
|
16
|
+
* @example <div id="reply-7" data-stream-pending mix={[streamTarget()]}>…</div>
|
|
17
|
+
*/
|
|
18
|
+
export declare function streamTarget(): UtilityMixin[];
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Styles for a reply that streams in with `revealStream()`: a block the text has not reached
|
|
3
|
+
* stays out of the layout, and a reply still pending is unpainted while scripts run and
|
|
4
|
+
* motion is allowed, so the finished text never flashes before its replay starts.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import { keyframes } from "@sdxc/u/animation";
|
|
10
|
+
import { raw } from "@sdxc/u/general";
|
|
11
|
+
import { media } from "@sdxc/u/responsive";
|
|
12
|
+
import { when } from "@sdxc/u/state";
|
|
13
|
+
import { STREAM_HIDDEN_ATTRIBUTE, STREAM_PENDING_ATTRIBUTE } from "./reveal-stream.js";
|
|
14
|
+
/** The keyframes that paint a pending reply after all when its script never arrives. */
|
|
15
|
+
const FALLBACK_KEYFRAMES = "ui-stream-target-fallback";
|
|
16
|
+
/** How long a pending reply waits for its replay before it shows whole. */
|
|
17
|
+
const FALLBACK_DELAY = "2.5s";
|
|
18
|
+
/**
|
|
19
|
+
* Put on the element a reply streams into, the one carrying `data-stream-pending`. Without
|
|
20
|
+
* scripts, or under reduced motion, the reply shows whole at once; with them it waits for
|
|
21
|
+
* the replay, and shows whole after {@link FALLBACK_DELAY} if the replay never starts.
|
|
22
|
+
*
|
|
23
|
+
* @returns The mixins to spread into the reply's `mix`.
|
|
24
|
+
* @example <div id="reply-7" data-stream-pending mix={[streamTarget()]}>…</div>
|
|
25
|
+
*/
|
|
26
|
+
export function streamTarget() {
|
|
27
|
+
return [
|
|
28
|
+
keyframes(FALLBACK_KEYFRAMES, { to: { visibility: "visible" } }),
|
|
29
|
+
when(`& [${STREAM_HIDDEN_ATTRIBUTE}]`, raw({ display: "none" })),
|
|
30
|
+
media("(scripting: enabled) and (prefers-reduced-motion: no-preference)", when(`&[${STREAM_PENDING_ATTRIBUTE}]`, raw({
|
|
31
|
+
visibility: "hidden",
|
|
32
|
+
animationName: FALLBACK_KEYFRAMES,
|
|
33
|
+
animationDuration: "0s",
|
|
34
|
+
animationDelay: FALLBACK_DELAY,
|
|
35
|
+
animationFillMode: "forwards",
|
|
36
|
+
}))),
|
|
37
|
+
];
|
|
38
|
+
}
|
|
@@ -94,7 +94,13 @@ export function Button(handle) {
|
|
|
94
94
|
fontWeight: "var(--ui-button-weight, 500)",
|
|
95
95
|
}),
|
|
96
96
|
cursor("default"),
|
|
97
|
-
/**
|
|
97
|
+
/**
|
|
98
|
+
* A small control reaches `--ui-target-size` however a consumer positions it. The
|
|
99
|
+
* control is its target's containing block, so a scrolling row of buttons clips
|
|
100
|
+
* every target and the page never grows to fit one; a consumer's own position
|
|
101
|
+
* utility in `mix` replaces it.
|
|
102
|
+
*/
|
|
103
|
+
relative(),
|
|
98
104
|
hitArea({ anchor: "flex-center" }),
|
|
99
105
|
userSelect(),
|
|
100
106
|
pi(4),
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A ring that fills as a limited field is typed in, the characters left once the limit is
|
|
3
|
+
* near, and how far over once past it, for a post, a bio or a short reply. A client island
|
|
4
|
+
* the server draws for the field's text, so a re-rendered form opens on the right count.
|
|
5
|
+
*
|
|
6
|
+
* @author [Sergio Xalambrí](https://sergiodxa.com)
|
|
7
|
+
* @copyright Sergio Xalambrí 2026
|
|
8
|
+
*/
|
|
9
|
+
import type { EntryComponent } from "remix/component";
|
|
10
|
+
export { countCharacters } from "../mixins/character-count.js";
|
|
11
|
+
/**
|
|
12
|
+
* Props {@link CharacterCount} serializes into the page for hydration, which is why they are
|
|
13
|
+
* a `type`: `SerializableProps` rejects an interface.
|
|
14
|
+
*/
|
|
15
|
+
export type CharacterCountProps = {
|
|
16
|
+
/** The `id` of the `<textarea>` or `<input>` counted. */
|
|
17
|
+
for: string;
|
|
18
|
+
/** The most characters the field takes, counted by `countCharacters`. */
|
|
19
|
+
max: number;
|
|
20
|
+
/** The field's text as the server renders it, so the first paint shows its count. */
|
|
21
|
+
value?: string;
|
|
22
|
+
/** How many characters left show the number. @default 20 */
|
|
23
|
+
warn?: number;
|
|
24
|
+
/** Disables the form's submit buttons while the field is empty or over the limit. @default false */
|
|
25
|
+
holdSubmit?: boolean;
|
|
26
|
+
/** What a screen reader hears as the state changes; `{count}` is the number left or over. */
|
|
27
|
+
labels: {
|
|
28
|
+
/** Such as "{count} characters left". */
|
|
29
|
+
remaining: string;
|
|
30
|
+
/** Such as "{count} characters over the limit". */
|
|
31
|
+
over: string;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
/**
|
|
35
|
+
* Renders the ring and its number. The ring sits in a fixed box and scales up for the
|
|
36
|
+
* warning, so the controls beside it never move; past ten over, only the number remains.
|
|
37
|
+
* The island loads from `@sdxc/ui/character-count`, which the browser entry maps.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* <Textarea id="draft" name="text" />
|
|
41
|
+
* <CharacterCount for="draft" max={280} holdSubmit
|
|
42
|
+
* labels={{ remaining: "{count} characters left", over: "{count} characters over" }} />
|
|
43
|
+
*/
|
|
44
|
+
export declare const CharacterCount: EntryComponent<CharacterCountProps>;
|