@volvel/ui 0.0.0-stage → 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.
Files changed (137) hide show
  1. package/LICENSE +202 -0
  2. package/THIRD_PARTY_NOTICES.md +23018 -0
  3. package/dist/Badge.d.ts +20 -0
  4. package/dist/Badge.js +35 -0
  5. package/dist/Button.d.ts +56 -0
  6. package/dist/Button.js +52 -0
  7. package/dist/Chart.d.ts +23 -0
  8. package/dist/Chart.js +98 -0
  9. package/dist/Combobox.d.ts +45 -0
  10. package/dist/Combobox.js +42 -0
  11. package/dist/ContextMenu.d.ts +16 -0
  12. package/dist/ContextMenu.js +11 -0
  13. package/dist/DateInput.d.ts +31 -0
  14. package/dist/DateInput.js +329 -0
  15. package/dist/Details.d.ts +12 -0
  16. package/dist/Details.js +9 -0
  17. package/dist/Dialog.d.ts +44 -0
  18. package/dist/Dialog.js +95 -0
  19. package/dist/Dialogs.d.ts +56 -0
  20. package/dist/Dialogs.js +95 -0
  21. package/dist/Doc.d.ts +25 -0
  22. package/dist/Doc.js +118 -0
  23. package/dist/DocServed.d.ts +6 -0
  24. package/dist/DocServed.js +154 -0
  25. package/dist/DocZoom.d.ts +11 -0
  26. package/dist/DocZoom.js +133 -0
  27. package/dist/Facts.d.ts +12 -0
  28. package/dist/Facts.js +10 -0
  29. package/dist/Fields.d.ts +184 -0
  30. package/dist/Fields.js +249 -0
  31. package/dist/Form.d.ts +47 -0
  32. package/dist/Form.js +189 -0
  33. package/dist/Grid.d.ts +118 -0
  34. package/dist/Grid.js +475 -0
  35. package/dist/HeadingSlot.d.ts +13 -0
  36. package/dist/HeadingSlot.js +19 -0
  37. package/dist/JsonView.d.ts +11 -0
  38. package/dist/JsonView.js +68 -0
  39. package/dist/LogViewer.d.ts +45 -0
  40. package/dist/LogViewer.js +299 -0
  41. package/dist/Markdown.d.ts +21 -0
  42. package/dist/Markdown.js +27 -0
  43. package/dist/MarkdownBody.d.ts +6 -0
  44. package/dist/MarkdownBody.js +14 -0
  45. package/dist/Menu.d.ts +29 -0
  46. package/dist/Menu.js +8 -0
  47. package/dist/MoveButtons.d.ts +19 -0
  48. package/dist/MoveButtons.js +22 -0
  49. package/dist/Notice.d.ts +47 -0
  50. package/dist/Notice.js +50 -0
  51. package/dist/PageShell.d.ts +42 -0
  52. package/dist/PageShell.js +14 -0
  53. package/dist/Pagination.d.ts +13 -0
  54. package/dist/Pagination.js +9 -0
  55. package/dist/Panel.d.ts +31 -0
  56. package/dist/Panel.js +33 -0
  57. package/dist/Pickers.d.ts +37 -0
  58. package/dist/Pickers.js +44 -0
  59. package/dist/Popover.d.ts +24 -0
  60. package/dist/Popover.js +12 -0
  61. package/dist/ResultView.d.ts +28 -0
  62. package/dist/ResultView.js +140 -0
  63. package/dist/SchemaForm.d.ts +45 -0
  64. package/dist/SchemaForm.js +626 -0
  65. package/dist/SideSheet.d.ts +31 -0
  66. package/dist/SideSheet.js +136 -0
  67. package/dist/Sparkline.d.ts +14 -0
  68. package/dist/Sparkline.js +23 -0
  69. package/dist/Surfaces.d.ts +30 -0
  70. package/dist/Surfaces.js +34 -0
  71. package/dist/Switch.d.ts +18 -0
  72. package/dist/Switch.js +11 -0
  73. package/dist/Table.d.ts +15 -0
  74. package/dist/Table.js +6 -0
  75. package/dist/Tabs.d.ts +32 -0
  76. package/dist/Tabs.js +11 -0
  77. package/dist/Term.d.ts +82 -0
  78. package/dist/Term.js +153 -0
  79. package/dist/Timeline.d.ts +29 -0
  80. package/dist/Timeline.js +39 -0
  81. package/dist/Toast.d.ts +43 -0
  82. package/dist/Toast.js +140 -0
  83. package/dist/Tooltip.d.ts +34 -0
  84. package/dist/Tooltip.js +70 -0
  85. package/dist/Tree.d.ts +51 -0
  86. package/dist/Tree.js +233 -0
  87. package/dist/chartEngine.d.ts +32 -0
  88. package/dist/chartEngine.js +72 -0
  89. package/dist/chartTheme.d.ts +41 -0
  90. package/dist/chartTheme.js +131 -0
  91. package/dist/contrast.d.ts +27 -0
  92. package/dist/contrast.js +110 -0
  93. package/dist/dates.d.ts +61 -0
  94. package/dist/dates.js +294 -0
  95. package/dist/drawer/Chips.d.ts +37 -0
  96. package/dist/drawer/Chips.js +32 -0
  97. package/dist/drawer/Choices.d.ts +47 -0
  98. package/dist/drawer/Choices.js +81 -0
  99. package/dist/drawer/Drawer.d.ts +125 -0
  100. package/dist/drawer/Drawer.js +150 -0
  101. package/dist/drawer/EditorBodies.d.ts +95 -0
  102. package/dist/drawer/EditorBodies.js +169 -0
  103. package/dist/drawer/NumberFormat.d.ts +36 -0
  104. package/dist/drawer/NumberFormat.js +98 -0
  105. package/dist/drawer/SortableRows.d.ts +35 -0
  106. package/dist/drawer/SortableRows.js +23 -0
  107. package/dist/drawer/edgeShadows.d.ts +7 -0
  108. package/dist/drawer/edgeShadows.js +17 -0
  109. package/dist/drawer/index.d.ts +8 -0
  110. package/dist/drawer/index.js +8 -0
  111. package/dist/drawer/useSortable.d.ts +53 -0
  112. package/dist/drawer/useSortable.js +323 -0
  113. package/dist/format.d.ts +6 -0
  114. package/dist/format.js +17 -0
  115. package/dist/icons.d.ts +20 -0
  116. package/dist/icons.js +16 -0
  117. package/dist/index.d.ts +48 -0
  118. package/dist/index.js +48 -0
  119. package/dist/markdownKnowledge.d.ts +45 -0
  120. package/dist/markdownKnowledge.js +37 -0
  121. package/dist/overlay.d.ts +7 -0
  122. package/dist/overlay.js +10 -0
  123. package/dist/pageIcons.d.ts +12 -0
  124. package/dist/pageIcons.js +32 -0
  125. package/dist/presence.d.ts +41 -0
  126. package/dist/presence.js +108 -0
  127. package/dist/returnFocus.d.ts +9 -0
  128. package/dist/returnFocus.js +44 -0
  129. package/dist/tokens.css +437 -0
  130. package/dist/type-scale.css +34 -0
  131. package/dist/useFlip.d.ts +32 -0
  132. package/dist/useFlip.js +118 -0
  133. package/fonts/OFL.txt +193 -0
  134. package/fonts/geist-latin.woff2 +0 -0
  135. package/fonts/geist-mono-latin.woff2 +0 -0
  136. package/package.json +47 -3
  137. package/README.md +0 -3
@@ -0,0 +1,95 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { createContext, useCallback, useContext, useMemo, useRef, useState, } from "react";
3
+ import { Button } from "./Button.js";
4
+ import { Dialog } from "./Dialog.js";
5
+ import { TextAreaField, TextField } from "./Fields.js";
6
+ const DialogsContext = createContext(undefined);
7
+ /**
8
+ * Holds the questions an app asks before it acts: a confirmation, a short
9
+ * answer, a name typed out before something is destroyed. Put one around the
10
+ * app and ask through `useDialogs`. They take the place of the browser's own
11
+ * `confirm`, `prompt` and `alert`, which cannot be styled, block the page,
12
+ * and are switched off in some embedded browsers.
13
+ */
14
+ export function DialogsProvider({ children }) {
15
+ const [asked, setAsked] = useState();
16
+ const [text, setText] = useState("");
17
+ const [fieldError, setFieldError] = useState();
18
+ const [working, setWorking] = useState(false);
19
+ const current = useRef(undefined);
20
+ const ask = useCallback((next) => {
21
+ // A second question while one is open cancels the first.
22
+ const before = current.current;
23
+ if (before)
24
+ before.kind === "prompt" ? before.answer(null) : before.answer(false);
25
+ current.current = next;
26
+ setText(next.kind === "prompt" ? (next.options.initial ?? "") : "");
27
+ setFieldError(undefined);
28
+ setAsked(next);
29
+ }, []);
30
+ const dialogs = useMemo(() => ({
31
+ confirm: (options) => new Promise((answer) => ask({ kind: "confirm", options, answer })),
32
+ prompt: (options) => new Promise((answer) => ask({ kind: "prompt", options, answer })),
33
+ typeToConfirm: (options) => new Promise((answer) => ask({ kind: "type", options, answer })),
34
+ }), [ask]);
35
+ const close = (went) => {
36
+ const open = current.current;
37
+ if (!open)
38
+ return;
39
+ current.current = undefined;
40
+ setAsked(undefined);
41
+ if (open.kind === "prompt")
42
+ open.answer(went ? text : null);
43
+ else
44
+ open.answer(went);
45
+ };
46
+ const options = asked?.options;
47
+ const required = asked?.kind === "prompt" ? (asked.options.required ?? true) : false;
48
+ // The limit is said at the field and refused, never cut quietly while a person types.
49
+ const limit = asked?.kind === "prompt" ? asked.options.maxLength : undefined;
50
+ const tooLong = asked?.kind === "prompt" && limit !== undefined && text.length > limit;
51
+ const lengthSaid = tooLong
52
+ ? `Use at most ${limit} characters. This is ${text.length}.`
53
+ : undefined;
54
+ const ready = asked?.kind === "type"
55
+ ? text === asked.options.expected
56
+ : asked?.kind === "prompt"
57
+ ? (!required || text.trim() !== "") && !tooLong
58
+ : true;
59
+ return (_jsxs(DialogsContext.Provider, { value: dialogs, children: [children, _jsx(Dialog, { open: asked !== undefined, onClose: () => close(false), title: options?.title ?? "", children: asked ? (_jsxs("form", { className: "flex flex-col gap-4", onSubmit: (event) => {
60
+ event.preventDefault();
61
+ if (!ready || working)
62
+ return;
63
+ const submit = asked.kind === "prompt" ? asked.options.submit : undefined;
64
+ if (!submit)
65
+ return close(true);
66
+ setWorking(true);
67
+ setFieldError(undefined);
68
+ submit(text)
69
+ .then((refused) => (refused ? setFieldError(refused) : close(true)))
70
+ // A failure that was not foreseen is said on the field too, keeping what was typed.
71
+ .catch((caught) => setFieldError(caught instanceof Error ? caught.message : String(caught)))
72
+ .finally(() => setWorking(false));
73
+ }, children: [options?.text ? _jsx("div", { className: "text-ink-muted", children: options.text }) : null, options?.links && options.links.length > 0 ? (_jsx("ul", { className: "m-0 flex list-none flex-col gap-1 p-0 text-body-sm", children: options.links.map((one) => (_jsxs("li", { className: "flex items-center justify-between gap-3", children: [_jsx("span", { className: "min-w-0 text-ink", children: one.label }), _jsx("button", { type: "button", "aria-label": `Show ${one.label}`, className: "shrink-0 cursor-pointer border-0 bg-transparent p-0 text-meta text-action underline outline-offset-2 focus-visible:outline-2 focus-visible:outline-focus", onClick: () => {
74
+ close(false);
75
+ one.onSelect();
76
+ }, children: "Show it" })] }, one.label))) })) : null, asked.kind === "prompt" ? (asked.options.multiline ? (_jsx(TextAreaField, { name: "answer", label: asked.options.label, value: text, rows: 4, ...(limit !== undefined ? { maxLength: limit } : {}), ...(asked.options.hint ? { hint: asked.options.hint } : {}), ...(asked.options.placeholder ? { placeholder: asked.options.placeholder } : {}), onChange: setText })) : (_jsx(TextField, { name: "answer", label: asked.options.label, value: text, required: required, ...(fieldError || lengthSaid
77
+ ? { error: (fieldError ?? lengthSaid) }
78
+ : {}), ...(asked.options.hint || limit
79
+ ? {
80
+ hint: [asked.options.hint, limit ? `Up to ${limit} characters.` : undefined]
81
+ .filter(Boolean)
82
+ .join(" "),
83
+ }
84
+ : {}), ...(asked.options.placeholder ? { placeholder: asked.options.placeholder } : {}), onChange: (value) => {
85
+ setFieldError(undefined);
86
+ setText(value);
87
+ } }))) : null, asked.kind === "type" ? (_jsx(TextField, { name: "answer", label: `Type ${asked.options.expected} to confirm`, value: text, autoComplete: "off", onChange: setText })) : null, _jsxs("div", { className: "flex justify-end gap-2", children: [_jsx(Button, { onClick: () => close(false), ...(asked.kind === "confirm" && options?.danger ? { "data-autofocus": "" } : {}), children: options?.cancel ?? "Cancel" }), _jsx(Button, { type: "submit", ...(asked.kind === "confirm" && !options?.danger ? { "data-autofocus": "" } : {}), variant: options?.danger ? "danger-solid" : "primary", disabled: !ready, loading: working, children: options?.action ?? "Continue" })] })] })) : null })] }));
88
+ }
89
+ /** The way to ask a question from anywhere under a `DialogsProvider`. */
90
+ export function useDialogs() {
91
+ const dialogs = useContext(DialogsContext);
92
+ if (!dialogs)
93
+ throw new Error("useDialogs needs a DialogsProvider above it.");
94
+ return dialogs;
95
+ }
package/dist/Doc.d.ts ADDED
@@ -0,0 +1,25 @@
1
+ import { type Root } from "@volvel/markup";
2
+ import { type Components, type ReactOptions } from "@volvel/markup/react";
3
+ import { type ReactNode } from "react";
4
+ export interface DocProps extends Omit<ReactOptions, "components"> {
5
+ tree: Root;
6
+ /**
7
+ * Draws the link to read more about a term, given where it leads. Left out,
8
+ * it is a plain link. A console gives one that opens its help panel.
9
+ */
10
+ more?: (href: string, word: string) => ReactNode;
11
+ /**
12
+ * Draw the page as it is served, with no component of the kit: the elements
13
+ * and the stylesheet the site uses, behaving as the site's script makes them.
14
+ * For a preview that must match the site.
15
+ */
16
+ asServed?: boolean;
17
+ /** Components to use in place of the kit's, or beside them. */
18
+ components?: Components;
19
+ }
20
+ /**
21
+ * A page of documentation, from its tree. Text and its layout come from the
22
+ * same stylesheet a served site uses. Alerts, tabs, folded sections, keys and
23
+ * terms are the kit's own, so they look and behave as they do everywhere else.
24
+ */
25
+ export declare function Doc({ tree, more, asServed, components, ...rest }: DocProps): import("react").JSX.Element;
package/dist/Doc.js ADDED
@@ -0,0 +1,118 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { DOC_CSS, DOC_DARK_CSS, highlightCode } from "@volvel/markup";
3
+ import { renderReact } from "@volvel/markup/react";
4
+ import { CircleCheck, Info, OctagonAlert, TriangleAlert } from "lucide-react";
5
+ import { useMemo, useRef, useState } from "react";
6
+ import { Details } from "./Details.js";
7
+ import { servedComponents } from "./DocServed.js";
8
+ import { DocZoom, zoomButton } from "./DocZoom.js";
9
+ import { Tabs } from "./Tabs.js";
10
+ import { Term } from "./Term.js";
11
+ import { Kbd } from "./Tooltip.js";
12
+ /** The documentation stylesheet's colors, taken from the theme's tokens. */
13
+ const THEMED = `
14
+ .vd-doc {
15
+ --vd-ink: var(--vx-ink);
16
+ --vd-muted: var(--vx-ink-muted);
17
+ --vd-line: var(--vx-line);
18
+ --vd-surface: var(--vx-surface);
19
+ --vd-sunken: var(--vx-sunken);
20
+ --vd-action: var(--vx-action);
21
+ /* A note is neutral: the accent of a tenant's theme may be green, which reads as success. */
22
+ --vd-info: var(--vx-ink-muted);
23
+ --vd-info-soft: var(--vx-sunken);
24
+ --vd-success: var(--vx-success);
25
+ --vd-success-soft: var(--vx-success-soft);
26
+ --vd-attention: var(--vx-attention);
27
+ --vd-attention-soft: var(--vx-attention-soft);
28
+ --vd-danger: var(--vx-danger);
29
+ --vd-danger-soft: var(--vx-danger-soft);
30
+ --vd-font-code: var(--vx-font-code);
31
+ --vd-radius: var(--vx-radius-control);
32
+ }
33
+ /* As a served site sets its pages: a size of its own, whatever is around it. */
34
+ .vd-doc.vd-served { font-size: 16px; line-height: 1.6; }
35
+ `;
36
+ /** An alert's type, as its rail, icon and words are colored. */
37
+ const ALERT = {
38
+ // Neutral, never the theme's accent: a green accent would make a note read as success.
39
+ info: { rail: "bg-ink-subtle", ink: "text-ink-muted", Icon: Info, label: "Note" },
40
+ success: { rail: "bg-success", ink: "text-success", Icon: CircleCheck, label: "Done" },
41
+ warning: { rail: "bg-attention", ink: "text-attention", Icon: TriangleAlert, label: "Warning" },
42
+ danger: { rail: "bg-danger", ink: "text-danger", Icon: OctagonAlert, label: "Danger" },
43
+ };
44
+ /** A picture in the text; where it cannot be loaded, its description in its place. */
45
+ function Picture({ src, alt, title, zoom, }) {
46
+ const [failed, setFailed] = useState(false);
47
+ if (failed)
48
+ return _jsx("span", { className: "text-ink-muted italic", children: alt });
49
+ const picture = (_jsx("img", { src: src, alt: alt, ...(title ? { title } : {}), loading: "lazy", onError: () => setFailed(true) }));
50
+ // Pressed, it opens larger: the page's `Doc` listens for the press, as the site's script does.
51
+ return zoom ? (_jsx("button", { type: "button", className: "vd-zoom", "data-vd-zoom": "", "aria-haspopup": "dialog", children: picture })) : (picture);
52
+ }
53
+ /** The kit's own components, for the parts of a page that are more than text. */
54
+ const KIT = {
55
+ image: ({ src, alt, title, zoom }) => _jsx(Picture, { src: src, alt: alt, title: title, zoom: zoom }),
56
+ // A callout, as the documentation site draws one: a colored rail and an icon for its type,
57
+ // its border kept wherever it sits (inside a widget's card too, where a notice drops its own).
58
+ alert: ({ type, title, children }) => {
59
+ const tone = ALERT[type] ?? ALERT.info;
60
+ return (_jsxs("div", { role: "note", "aria-label": typeof title === "string" && title ? title : tone.label, className: "relative mb-4 rounded-panel border border-line bg-surface py-3 pr-4 pl-10", children: [_jsx("span", { "aria-hidden": "true", className: `absolute top-3 bottom-3 left-2 w-0.5 rounded-full ${tone.rail}` }), _jsx(tone.Icon, { "aria-hidden": "true", size: 16, className: `absolute top-3.5 left-4 ${tone.ink}` }), title ? _jsx("p", { className: "m-0! mb-1! font-semibold text-ink", children: title }) : null, _jsx("div", { className: `[&>:last-child]:mb-0! ${title ? "text-ink-muted" : "text-ink"}`, children: children })] }));
61
+ },
62
+ tabs: ({ tabs }) => (_jsx("div", { className: "mb-4", children: _jsx(Tabs, { label: "Ways to do this", tabs: tabs.map((tab, index) => ({
63
+ id: String(index),
64
+ label: tab.label,
65
+ content: _jsx("div", { className: "[&>:last-child]:mb-0!", children: tab.children }),
66
+ })) }) })),
67
+ details: ({ summary, children }) => (_jsx("div", { className: "mb-4", children: _jsx(Details, { summary: summary, children: _jsx("div", { className: "[&>:last-child]:mb-0!", children: children }) }) })),
68
+ kbd: ({ keys }) => _jsx(Kbd, { children: keys }),
69
+ // What a kind says of a field, as a line; with nothing to say of it, its path alone (never the directive as typed).
70
+ field: ({ path, info }) => (_jsxs("p", { className: "vd-field", children: [_jsx("code", { children: path }), info?.description ? _jsxs(_Fragment, { children: [" \u2014 ", info.description] }) : null] })),
71
+ };
72
+ /** The last object given, for as long as each of its values is the one it had. */
73
+ function useShallowStable(next) {
74
+ const last = useRef(next);
75
+ const a = last.current;
76
+ const b = next;
77
+ const keys = Object.keys(b);
78
+ const same = Object.keys(a).length === keys.length && keys.every((key) => Object.is(a[key], b[key]));
79
+ if (!same)
80
+ last.current = next;
81
+ return last.current;
82
+ }
83
+ /**
84
+ * A page of documentation, from its tree. Text and its layout come from the
85
+ * same stylesheet a served site uses. Alerts, tabs, folded sections, keys and
86
+ * terms are the kit's own, so they look and behave as they do everywhere else.
87
+ */
88
+ export function Doc({ tree, more, asServed, components, ...rest }) {
89
+ // Every other prop is an option of the drawing, passed on as it is, so that an option the
90
+ // renderer gains is never dropped here. Held to the last object that is the same by value.
91
+ const options = useShallowStable(rest);
92
+ const drawn = useMemo(() => {
93
+ if (asServed) {
94
+ return renderReact(tree, {
95
+ highlight: highlightCode,
96
+ ...options,
97
+ components: { ...servedComponents(more), ...components },
98
+ });
99
+ }
100
+ const drawTerm = ({ props, word, info, children }) => {
101
+ const href = info?.href;
102
+ return (_jsx(Term, { id: props.id ?? Object.values(props).join(":"), word: word, short: info?.short, more: href === undefined ? undefined : more ? (more(href, word)) : (_jsxs("a", { href: href, className: "text-action underline", children: ["More about ", word] })), children: children }));
103
+ };
104
+ return renderReact(tree, {
105
+ highlight: highlightCode,
106
+ ...options,
107
+ components: { ...KIT, term: drawTerm, ...components },
108
+ });
109
+ }, [tree, more, asServed, components, options]);
110
+ const [zoomed, setZoomed] = useState(null);
111
+ return (_jsxs("div", { className: asServed ? "vd-doc vd-served" : "vd-doc", onClick: (event) => {
112
+ const button = zoomButton(event.target);
113
+ if (button) {
114
+ event.preventDefault();
115
+ setZoomed(button);
116
+ }
117
+ }, children: [_jsx("style", { href: "volvel-doc", precedence: "default", children: DOC_CSS + DOC_DARK_CSS + THEMED }), drawn, zoomed ? _jsx(DocZoom, { opener: zoomed, onClose: () => setZoomed(null) }) : null] }));
118
+ }
@@ -0,0 +1,6 @@
1
+ import type { Components } from "@volvel/markup/react";
2
+ import { type ReactNode } from "react";
3
+ /** Asks every tab and fold a node is in to show it. */
4
+ export declare function reveal(node: Element): void;
5
+ /** The components of a served page, for a preview. `more` draws a term's link to read more. */
6
+ export declare function servedComponents(more?: (href: string, word: string) => ReactNode): Components;
@@ -0,0 +1,154 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState, } from "react";
3
+ /**
4
+ * A page's components as a served site draws them, for a preview that must
5
+ * look and behave as the site does: the same elements and classes the HTML
6
+ * renderer writes, and what the site's own script does to them, done here by
7
+ * React. Tabs are tabs, a fold opens and closes as it moves, a term opens as a
8
+ * button does.
9
+ *
10
+ * Each listens for `vd-reveal`, sent from something inside it, and shows that
11
+ * thing: a tab chooses itself, a fold opens. An editor's preview sends it to
12
+ * follow the cursor into a part of the page that is hidden.
13
+ */
14
+ const EASE = "cubic-bezier(0.2, 0, 0, 1)";
15
+ const still = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
16
+ /** Asks every tab and fold a node is in to show it. */
17
+ export function reveal(node) {
18
+ node.dispatchEvent(new CustomEvent("vd-reveal", { bubbles: true }));
19
+ }
20
+ function ServedTabs({ tabs, marks, }) {
21
+ const [shown, setShown] = useState(0);
22
+ const id = useId();
23
+ const root = useRef(null);
24
+ const sections = useRef([]);
25
+ const buttons = useRef([]);
26
+ const chosen = useRef(false);
27
+ useEffect(() => {
28
+ const element = root.current;
29
+ if (!element)
30
+ return;
31
+ const show = (event) => {
32
+ const from = event.target;
33
+ const at = sections.current.findIndex((section) => section?.contains(from));
34
+ if (at !== -1)
35
+ setShown(at);
36
+ };
37
+ element.addEventListener("vd-reveal", show);
38
+ return () => element.removeEventListener("vd-reveal", show);
39
+ }, []);
40
+ // A tab chosen fades in, as on the site.
41
+ useEffect(() => {
42
+ if (!chosen.current)
43
+ return;
44
+ const section = sections.current[shown];
45
+ if (!section || still() || typeof section.animate !== "function")
46
+ return;
47
+ section.animate([
48
+ { opacity: 0, transform: "translateY(2px)" },
49
+ { opacity: 1, transform: "none" },
50
+ ], {
51
+ duration: 160,
52
+ easing: EASE,
53
+ });
54
+ }, [shown]);
55
+ if (tabs.length < 2) {
56
+ return (_jsx("div", { className: "vd-tabs", "data-vd-tabs": "1", ...marks, children: tabs.map((tab, index) => (_jsxs("section", { className: "vd-tab", ...tab.marks, children: [_jsx("h4", { className: "vd-tab-label", children: tab.label }), _jsx("div", { className: "vd-tab-body", children: tab.children })] }, index))) }));
57
+ }
58
+ const choose = (index, focus) => {
59
+ chosen.current = true;
60
+ setShown(index);
61
+ if (focus)
62
+ buttons.current[index]?.focus();
63
+ };
64
+ const keys = (event, index) => {
65
+ const move = { ArrowRight: 1, ArrowLeft: -1 }[event.key];
66
+ if (move)
67
+ choose((index + move + tabs.length) % tabs.length, true);
68
+ else if (event.key === "Home")
69
+ choose(0, true);
70
+ else if (event.key === "End")
71
+ choose(tabs.length - 1, true);
72
+ else
73
+ return;
74
+ event.preventDefault();
75
+ };
76
+ return (_jsxs("div", { ref: root, className: "vd-tabs vd-tabs-on", "data-vd-tabs": "1", ...marks, children: [_jsx("div", { className: "vd-tablist", role: "tablist", children: tabs.map((tab, index) => (_jsx("button", { ref: (button) => {
77
+ buttons.current[index] = button;
78
+ }, type: "button", role: "tab", id: `${id}-tab-${index}`, className: "vd-tab-button", "aria-selected": index === shown, "aria-controls": `${id}-panel-${index}`, tabIndex: index === shown ? 0 : -1, onClick: () => choose(index, false), onKeyDown: (event) => keys(event, index), children: tab.label }, index))) }), tabs.map((tab, index) => (_jsxs("section", { ref: (section) => {
79
+ sections.current[index] = section;
80
+ }, className: "vd-tab", hidden: index !== shown, ...tab.marks, children: [_jsx("h4", { className: "vd-tab-label", hidden: true, children: tab.label }), _jsx("div", { className: "vd-tab-body", id: `${id}-panel-${index}`, role: "tabpanel", "aria-labelledby": `${id}-tab-${index}`, children: tab.children })] }, index)))] }));
81
+ }
82
+ function ServedDetails({ summary, children, marks, }) {
83
+ const fold = useRef(null);
84
+ const moving = useRef(null);
85
+ const set = (open) => {
86
+ const element = fold.current;
87
+ if (!element || element.open === open)
88
+ return;
89
+ moving.current?.cancel();
90
+ if (still() || typeof element.animate !== "function") {
91
+ element.open = open;
92
+ return;
93
+ }
94
+ const from = element.getBoundingClientRect().height;
95
+ element.open = open;
96
+ const to = element.getBoundingClientRect().height;
97
+ element.open = true;
98
+ element.style.overflow = "hidden";
99
+ const run = element.animate({ height: [`${from}px`, `${to}px`] }, { duration: 200, easing: EASE });
100
+ moving.current = run;
101
+ run.onfinish = () => {
102
+ moving.current = null;
103
+ element.style.overflow = "";
104
+ element.open = open;
105
+ };
106
+ run.oncancel = () => {
107
+ element.style.overflow = "";
108
+ };
109
+ };
110
+ useEffect(() => {
111
+ const element = fold.current;
112
+ if (!element)
113
+ return;
114
+ const show = () => {
115
+ if (!element.open)
116
+ element.open = true;
117
+ };
118
+ element.addEventListener("vd-reveal", show);
119
+ return () => element.removeEventListener("vd-reveal", show);
120
+ }, []);
121
+ return (_jsxs("details", { ref: fold, className: "vd-details", ...marks, children: [_jsx("summary", { onClick: (event) => {
122
+ event.preventDefault();
123
+ set(!fold.current?.open);
124
+ }, children: summary }), _jsx("div", { className: "vd-details-body", children: children })] }));
125
+ }
126
+ function ServedTerm({ word, info, children, more, }) {
127
+ const [open, setOpen] = useState(false);
128
+ const id = useId();
129
+ const holder = useRef(null);
130
+ useEffect(() => {
131
+ if (!open)
132
+ return;
133
+ const away = (event) => {
134
+ if (!holder.current?.contains(event.target))
135
+ setOpen(false);
136
+ };
137
+ document.addEventListener("pointerdown", away);
138
+ return () => document.removeEventListener("pointerdown", away);
139
+ }, [open]);
140
+ if (!info || (!info.short && !info.href))
141
+ return _jsx(_Fragment, { children: children });
142
+ return (_jsxs("span", { ref: holder, className: `vd-term vd-term-on${open ? " vd-term-open" : ""}`, children: [_jsx("button", { type: "button", className: "vd-term-word", "aria-describedby": id, "aria-expanded": open, onClick: () => setOpen((now) => !now), onKeyDown: (event) => {
143
+ if (event.key === "Escape" && open)
144
+ setOpen(false);
145
+ }, children: children }), _jsxs("span", { className: "vd-term-tip", role: "tooltip", id: id, children: [info.short, info.href ? (_jsxs(_Fragment, { children: [info.short ? " " : null, more ? more(info.href, word) : _jsxs("a", { href: info.href, children: ["More about ", word] })] })) : null] })] }));
146
+ }
147
+ /** The components of a served page, for a preview. `more` draws a term's link to read more. */
148
+ export function servedComponents(more) {
149
+ return {
150
+ tabs: ({ tabs, marks }) => _jsx(ServedTabs, { tabs: tabs, marks: marks }),
151
+ details: ({ summary, children, marks }) => (_jsx(ServedDetails, { summary: summary, marks: marks, children: children })),
152
+ term: ({ word, info, children }) => (_jsx(ServedTerm, { word: word, info: info, more: more, children: children })),
153
+ };
154
+ }
@@ -0,0 +1,11 @@
1
+ /** The button of a picture that a press landed on, if it landed on one. */
2
+ export declare function zoomButton(target: EventTarget | null): HTMLElement | null;
3
+ /**
4
+ * The larger view of a picture: the whole of it, fitted to the window, its words under it. It grows
5
+ * from where the picture is and goes back there. The same elements and stylesheet as the served
6
+ * site's script draws, so a page looks and behaves the same in a console's help.
7
+ */
8
+ export declare function DocZoom({ opener, onClose }: {
9
+ opener: HTMLElement;
10
+ onClose: () => void;
11
+ }): import("react").JSX.Element;
@@ -0,0 +1,133 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useLayoutEffect, useRef } from "react";
3
+ const EASE = "cubic-bezier(0.2, 0, 0, 1)";
4
+ const FADE = [{ opacity: 0 }, { opacity: 1 }];
5
+ const reduced = () => typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
6
+ /** The picture of a pressed button that is in view: of a light and dark pair, the one the page shows. */
7
+ function seen(button) {
8
+ const pictures = [...button.querySelectorAll("img")];
9
+ return pictures.find((one) => getComputedStyle(one).display !== "none") ?? pictures[0];
10
+ }
11
+ /** The words of a pressed picture: its own, or those of the other look of the pair. */
12
+ function wordsOf(button) {
13
+ const picture = seen(button);
14
+ return (picture?.getAttribute("alt") ||
15
+ [...button.querySelectorAll("img")].map((one) => one.getAttribute("alt")).find(Boolean) ||
16
+ "");
17
+ }
18
+ /** The button of a picture that a press landed on, if it landed on one. */
19
+ export function zoomButton(target) {
20
+ return target instanceof Element ? target.closest("[data-vd-zoom]") : null;
21
+ }
22
+ const play = (node, frames, options, pseudo) => {
23
+ if (!node || reduced() || typeof node.animate !== "function")
24
+ return null;
25
+ try {
26
+ return node.animate(frames, pseudo ? { ...options, pseudoElement: "::backdrop" } : options);
27
+ }
28
+ catch {
29
+ return null;
30
+ }
31
+ };
32
+ /**
33
+ * The larger view of a picture: the whole of it, fitted to the window, its words under it. It grows
34
+ * from where the picture is and goes back there. The same elements and stylesheet as the served
35
+ * site's script draws, so a page looks and behaves the same in a console's help.
36
+ */
37
+ export function DocZoom({ opener, onClose }) {
38
+ const box = useRef(null);
39
+ const big = useRef(null);
40
+ const caption = useRef(null);
41
+ const closer = useRef(null);
42
+ const closing = useRef(false);
43
+ const picture = seen(opener);
44
+ const words = wordsOf(opener);
45
+ const src = picture?.getAttribute("src") ?? "";
46
+ const natural = picture && picture.naturalWidth > 0 ? picture : undefined;
47
+ useLayoutEffect(() => {
48
+ const dialog = box.current;
49
+ const image = big.current;
50
+ if (!dialog || !image)
51
+ return;
52
+ dialog.showModal();
53
+ closer.current?.focus();
54
+ const from = picture?.getBoundingClientRect();
55
+ const to = image.getBoundingClientRect();
56
+ const frames = from && from.width > 0 && to.width > 0
57
+ ? [
58
+ {
59
+ transform: `translate(${from.left - to.left}px, ${from.top - to.top}px) scale(${from.width / to.width}, ${from.height / to.height})`,
60
+ },
61
+ { transform: "none" },
62
+ ]
63
+ : [
64
+ { opacity: 0, transform: "scale(0.96)" },
65
+ { opacity: 1, transform: "none" },
66
+ ];
67
+ play(image, frames, { duration: 260, easing: EASE });
68
+ play(dialog, FADE, { duration: 200, easing: EASE }, true);
69
+ play(closer.current, FADE, { duration: 200, easing: EASE });
70
+ play(caption.current, FADE, { duration: 200, easing: EASE });
71
+ return () => {
72
+ if (dialog.open)
73
+ dialog.close();
74
+ };
75
+ }, [picture]);
76
+ const hide = () => {
77
+ const dialog = box.current;
78
+ const image = big.current;
79
+ if (!dialog || !image || closing.current)
80
+ return;
81
+ closing.current = true;
82
+ const finish = () => {
83
+ onClose();
84
+ if (opener.isConnected)
85
+ opener.focus();
86
+ };
87
+ const back = seen(opener)?.getBoundingClientRect();
88
+ const here = image.getBoundingClientRect();
89
+ const inView = back &&
90
+ back.width > 0 &&
91
+ here.width > 0 &&
92
+ back.bottom > 0 &&
93
+ back.top < window.innerHeight &&
94
+ back.right > 0 &&
95
+ back.left < window.innerWidth;
96
+ const frames = inView
97
+ ? [
98
+ { transform: "none" },
99
+ {
100
+ transform: `translate(${back.left - here.left}px, ${back.top - here.top}px) scale(${back.width / here.width}, ${back.height / here.height})`,
101
+ },
102
+ ]
103
+ : [
104
+ { opacity: 1, transform: "none" },
105
+ { opacity: 0, transform: "scale(0.96)" },
106
+ ];
107
+ const run = play(image, frames, { duration: 200, easing: EASE, fill: "forwards" });
108
+ play(dialog, [...FADE].reverse(), { duration: 200, easing: EASE, fill: "forwards" }, true);
109
+ play(closer.current, [...FADE].reverse(), { duration: 120, easing: EASE, fill: "forwards" });
110
+ play(caption.current, [...FADE].reverse(), { duration: 120, easing: EASE, fill: "forwards" });
111
+ if (run) {
112
+ run.onfinish = finish;
113
+ run.oncancel = finish;
114
+ }
115
+ else
116
+ finish();
117
+ };
118
+ return (_jsxs("dialog", { ref: box, className: "vd-lightbox", "aria-label": words || "Larger picture", onCancel: (event) => {
119
+ event.preventDefault();
120
+ hide();
121
+ }, onClick: (event) => {
122
+ // A press anywhere but on the picture, its words or the button closes it.
123
+ if (!(event.target instanceof Element) ||
124
+ !event.target.closest(".vd-lightbox-img, .vd-lightbox-caption, .vd-lightbox-close"))
125
+ hide();
126
+ }, onKeyDown: (event) => {
127
+ // Nothing else in it can take focus, so Tab stays on the one button.
128
+ if (event.key === "Tab") {
129
+ event.preventDefault();
130
+ closer.current?.focus();
131
+ }
132
+ }, children: [_jsxs("figure", { className: "vd-lightbox-figure", children: [_jsx("img", { ref: big, className: "vd-lightbox-img", src: src, alt: words, ...(natural ? { width: natural.naturalWidth, height: natural.naturalHeight } : {}) }), _jsx("figcaption", { ref: caption, className: "vd-lightbox-caption", "aria-hidden": "true", hidden: !words, children: words })] }), _jsx("button", { ref: closer, type: "button", className: "vd-lightbox-close", "aria-label": "Close", onClick: hide, children: "×" })] }));
133
+ }
@@ -0,0 +1,12 @@
1
+ import type { ReactNode } from "react";
2
+ export interface Fact {
3
+ label: string;
4
+ value: ReactNode;
5
+ /** Shows the value in the code font: an ID, a path, a hash. */
6
+ code?: boolean;
7
+ }
8
+ /** Short facts about one thing, as labels and values in columns. An empty value is left out. */
9
+ export declare function Facts({ facts, columns }: {
10
+ facts: readonly Fact[];
11
+ columns?: 2 | 3 | 4;
12
+ }): import("react").JSX.Element;
package/dist/Facts.js ADDED
@@ -0,0 +1,10 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useContained } from "./Panel.js";
3
+ /** Short facts about one thing, as labels and values in columns. An empty value is left out. */
4
+ export function Facts({ facts, columns = 4 }) {
5
+ const shown = facts.filter((fact) => fact.value !== undefined && fact.value !== null && fact.value !== "");
6
+ const grid = { 2: "", 3: "md:grid-cols-3", 4: "md:grid-cols-2 xl:grid-cols-4" }[columns];
7
+ // Inside a panel it is already in a box (07 §7.5): no second border.
8
+ const box = useContained() ? "" : "rounded-control border border-line p-3";
9
+ return (_jsx("dl", { className: `m-0 grid grid-cols-1 gap-x-6 gap-y-2 ${box} ${grid}`, children: shown.map((fact) => (_jsxs("div", { className: "flex min-w-0 items-baseline gap-3", children: [_jsx("dt", { className: "w-16 shrink-0 text-meta text-ink-muted", children: fact.label }), _jsx("dd", { className: `m-0 min-w-0 truncate text-code ${fact.code ? "font-mono text-code-sm" : ""}`, children: fact.value })] }, fact.label))) }));
10
+ }