@tollbooth-dpyc/web 0.4.0 → 0.5.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/README.md CHANGED
@@ -66,7 +66,12 @@ zone the site stores under `<prefix>:timezone`, if any.
66
66
  Something to read while a page loads. The quotes are the site's own; the
67
67
  package only scrolls them. Name a remote corpus to edit the set without a
68
68
  redeploy — it is fetched once per page and replaces the inline set when it
69
- arrives, or never, if it cannot be had:
69
+ arrives, or never, if it cannot be had.
70
+
71
+ The package owns the mechanics (timing, cross-fade, reduced motion, pausing
72
+ while the tab is hidden, `aria-live`, and a reserved height taken from the
73
+ tallest quote as *your* styles lay it out). How the quotes look is yours:
74
+ without `classNames` they are plain text inheriting from the page.
70
75
 
71
76
  ```tsx
72
77
  import { QuoteScroller } from "@tollbooth-dpyc/web/react";
@@ -79,9 +84,23 @@ const QUOTES: Quote[] = [{ text: "Observe the seasons.", author: "Hesiod" }];
79
84
  source="https://raw.githubusercontent.com/lonniev/dpyc-community/main/quotes-agrarian.json"
80
85
  heading="Reading the ledger…"
81
86
  spinner
87
+ classNames={{
88
+ root: "px-4 py-6 text-center",
89
+ heading: "mb-5 font-mono text-[11px] uppercase tracking-[0.3em] text-[var(--tb-accent)]",
90
+ figure: "mx-auto flex max-w-xl flex-col gap-3",
91
+ text: "font-serif text-[17px] italic leading-relaxed",
92
+ mark: "not-italic text-[var(--tb-accent)]",
93
+ author: "font-mono text-[10.5px] uppercase tracking-[0.22em] text-[var(--tb-muted)]",
94
+ }}
82
95
  />
83
96
  ```
84
97
 
98
+ Props: `quotes`, `source`, `heading`, `spinner`, `intervalMs` (default 3500),
99
+ `classNames` (`root`, `heading`, `spinner`, `figure`, `text`, `mark`,
100
+ `author`), `marks` (curly quotes by default; `false` for none, or
101
+ `[open, close]`), and `renderQuote(quote)` to draw a quote's markup yourself
102
+ (then `text`, `mark` and `author` are unused).
103
+
85
104
  ### Styling
86
105
 
87
106
  Components use Tailwind classes coloured only through CSS variables. Tell
@@ -11,8 +11,16 @@
11
11
  * The order is shuffled and then walked, so nothing repeats until every quote
12
12
  * has shown. It cross-fades (instantly under reduced motion), stops while the
13
13
  * tab is hidden, and reserves the height of its longest quote so the page
14
- * does not jump as quotes change. Coloured only through `--tb-*` tokens.
14
+ * does not jump as quotes change.
15
+ *
16
+ * Mechanics only. The package owns the timing, the fade, the cache and the
17
+ * reserved height; every visual choice — type, size, colour, spacing,
18
+ * alignment — belongs to the site, through `classNames` or `renderQuote`.
19
+ * With neither, the quotes are plain text that inherits from the page. The
20
+ * reserved height is the tallest quote as the SITE styles it: every quote is
21
+ * laid out, invisibly, in the same grid cell as the one on show.
15
22
  */
23
+ import { type ReactNode } from "react";
16
24
  import { type Quote } from "../quotes.ts";
17
25
  export interface QuoteScrollerProps {
18
26
  /** The site's own quotes: shown at once, and kept if `source` fails. Pass a
@@ -27,7 +35,31 @@ export interface QuoteScrollerProps {
27
35
  spinner?: boolean;
28
36
  /** How long each quote stays, in ms. Default 3500. */
29
37
  intervalMs?: number;
30
- /** Classes for the outer box (padding, placement). */
31
- className?: string;
38
+ /** Classes for each part. The package adds no typography or colour of its
39
+ * own to any of them. `text`, `mark` and `author` are unused when
40
+ * `renderQuote` is given. */
41
+ classNames?: QuoteScrollerClassNames;
42
+ /** Full control of one quote's markup. The package still wraps it for the
43
+ * fade and the reserved height. */
44
+ renderQuote?: (quote: Quote) => ReactNode;
45
+ /** Quotation marks around the text: the curly pair by default, `false` for
46
+ * none, or your own `[open, close]`. */
47
+ marks?: boolean | readonly [open: string, close: string];
48
+ }
49
+ export interface QuoteScrollerClassNames {
50
+ /** The outer box. */
51
+ root?: string;
52
+ /** The status line. */
53
+ heading?: string;
54
+ /** The spinner icon. Given, it replaces the default 1em size. */
55
+ spinner?: string;
56
+ /** Each quote's `<figure>`. */
57
+ figure?: string;
58
+ /** The `<blockquote>` holding the text and its marks. */
59
+ text?: string;
60
+ /** Each quotation mark. */
61
+ mark?: string;
62
+ /** The `<figcaption>` naming the author. */
63
+ author?: string;
32
64
  }
33
- export default function QuoteScroller({ quotes, source, heading, spinner, intervalMs, className, }: QuoteScrollerProps): import("react").JSX.Element;
65
+ export default function QuoteScroller({ quotes, source, heading, spinner, intervalMs, classNames, renderQuote, marks, }: QuoteScrollerProps): import("react").JSX.Element;
@@ -12,11 +12,19 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
12
12
  * The order is shuffled and then walked, so nothing repeats until every quote
13
13
  * has shown. It cross-fades (instantly under reduced motion), stops while the
14
14
  * tab is hidden, and reserves the height of its longest quote so the page
15
- * does not jump as quotes change. Coloured only through `--tb-*` tokens.
15
+ * does not jump as quotes change.
16
+ *
17
+ * Mechanics only. The package owns the timing, the fade, the cache and the
18
+ * reserved height; every visual choice — type, size, colour, spacing,
19
+ * alignment — belongs to the site, through `classNames` or `renderQuote`.
20
+ * With neither, the quotes are plain text that inherits from the page. The
21
+ * reserved height is the tallest quote as the SITE styles it: every quote is
22
+ * laid out, invisibly, in the same grid cell as the one on show.
16
23
  */
17
- import { useEffect, useMemo, useRef, useState } from "react";
24
+ import { useEffect, useRef, useState } from "react";
18
25
  import { Loader2 } from "lucide-react";
19
26
  import { loadQuotes, peekQuotes, shuffle } from "../quotes.js";
27
+ const CURLY = ["\u201c", "\u201d"];
20
28
  const FADE_MS = 450;
21
29
  function useReducedMotion() {
22
30
  const query = "(prefers-reduced-motion: reduce)";
@@ -40,7 +48,7 @@ function usePageVisible() {
40
48
  }, []);
41
49
  return shown;
42
50
  }
43
- export default function QuoteScroller({ quotes, source, heading, spinner = false, intervalMs = 3500, className = "", }) {
51
+ export default function QuoteScroller({ quotes, source, heading, spinner = false, intervalMs = 3500, classNames = {}, renderQuote, marks = true, }) {
44
52
  const reduced = useReducedMotion();
45
53
  const pageVisible = usePageVisible();
46
54
  // Content, not identity: a site that passes an inline array still gets one
@@ -94,13 +102,17 @@ export default function QuoteScroller({ quotes, source, heading, spinner = false
94
102
  setShown(true);
95
103
  };
96
104
  }, [list, intervalMs, reduced, pageVisible]);
97
- const longest = useMemo(() => list.reduce((a, q) => (!a || q.text.length + q.author.length > a.text.length + a.author.length ? q : a), undefined), [list]);
98
105
  const q = list[index % Math.max(list.length, 1)];
99
- return (_jsxs("div", { className: `px-4 py-6 text-center ${className}`, children: [heading && (_jsxs("div", { className: "mb-5 flex items-center justify-center gap-2 font-mono text-[11px] uppercase tracking-[0.3em] text-[var(--tb-accent)]", children: [spinner && _jsx(Loader2, { "aria-hidden": true, className: "h-3.5 w-3.5 motion-safe:animate-spin" }), heading] })), q && longest && (_jsxs("div", { className: "mx-auto grid max-w-xl", children: [_jsx(QuoteText, { quote: longest, className: "invisible [grid-area:1/1]", hidden: true }), _jsx(QuoteText, { quote: q, className: "[grid-area:1/1]", style: {
106
+ const pair = marks === true ? CURLY : marks === false ? null : marks;
107
+ const draw = renderQuote ??
108
+ ((quote) => (_jsxs("figure", { className: classNames.figure, children: [_jsxs("blockquote", { className: classNames.text, children: [pair && _jsx("span", { className: classNames.mark, children: pair[0] }), quote.text, pair && _jsx("span", { className: classNames.mark, children: pair[1] })] }), _jsx("figcaption", { className: classNames.author, children: quote.author })] })));
109
+ return (_jsxs("div", { className: classNames.root, children: [heading && (_jsxs("div", { className: classNames.heading, children: [spinner && (_jsx(Loader2, { "aria-hidden": true, className: `${classNames.spinner ?? "inline-block h-[1em] w-[1em]"} motion-safe:animate-spin` })), spinner && " ", heading] })), q && (_jsxs("div", { style: STAGE, children: [list.map((each, i) => (_jsx("div", { style: HOLDER, "aria-hidden": true, children: draw(each) }, i))), _jsx("div", { style: {
110
+ ...CELL,
100
111
  opacity: shown ? 1 : 0,
101
112
  transition: reduced ? "none" : `opacity ${FADE_MS}ms ease`,
102
- }, live: true })] }))] }));
103
- }
104
- function QuoteText({ quote, className, style, hidden = false, live = false, }) {
105
- return (_jsxs("figure", { className: `m-0 flex flex-col justify-center gap-3 ${className}`, style: style, "aria-hidden": hidden || undefined, "aria-live": live ? "polite" : undefined, "aria-atomic": live || undefined, children: [_jsxs("blockquote", { className: "m-0 font-serif text-[17px] italic leading-relaxed text-[var(--tb-ink)]", children: [_jsx("span", { className: "not-italic text-[var(--tb-accent)]", children: "\u201C" }), quote.text, _jsx("span", { className: "not-italic text-[var(--tb-accent)]", children: "\u201D" })] }), _jsx("figcaption", { className: "font-mono text-[10.5px] uppercase tracking-[0.22em] text-[var(--tb-muted)]", children: quote.author })] }));
113
+ }, "aria-live": "polite", "aria-atomic": true, children: draw(q) })] }))] }));
106
114
  }
115
+ // Structure for the mechanism only, inline so it needs no stylesheet.
116
+ const STAGE = { display: "grid" };
117
+ const CELL = { gridArea: "1 / 1", minWidth: 0 };
118
+ const HOLDER = { ...CELL, visibility: "hidden" };
@@ -3,8 +3,9 @@
3
3
  *
4
4
  * Renders ONLY when this browser holds the session nsec for the signed-in
5
5
  * npub. NIP-07 and courier-proof sign-ins see nothing: no disabled control,
6
- * no placeholder, no mention. Reveal takes a deliberate second step so an
7
- * account page opened in front of other people does not paint the key.
6
+ * no placeholder, no mention. Painting the key takes two deliberate taps —
7
+ * "Claim your session key", then the Reveal chip — so an account page opened
8
+ * in front of other people does not show it.
8
9
  *
9
10
  * Destinations: copy, download .env, password-manager prompt, and an
10
11
  * encrypted DM to another npub the patron names. The nsec never reaches a
@@ -4,8 +4,9 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  *
5
5
  * Renders ONLY when this browser holds the session nsec for the signed-in
6
6
  * npub. NIP-07 and courier-proof sign-ins see nothing: no disabled control,
7
- * no placeholder, no mention. Reveal takes a deliberate second step so an
8
- * account page opened in front of other people does not paint the key.
7
+ * no placeholder, no mention. Painting the key takes two deliberate taps —
8
+ * "Claim your session key", then the Reveal chip — so an account page opened
9
+ * in front of other people does not show it.
9
10
  *
10
11
  * Destinations: copy, download .env, password-manager prompt, and an
11
12
  * encrypted DM to another npub the patron names. The nsec never reaches a
@@ -161,10 +162,10 @@ function SessionKeyClaimInner() {
161
162
  setDmOpen(false);
162
163
  setFlash(null);
163
164
  setRecipient("");
164
- }, className: `text-[12px] ${muted} hover:text-[var(--tb-ink)]`, children: "Hide" })] }), _jsxs("p", { className: `mb-3 text-[12.5px] leading-relaxed ${muted}`, children: ["Anyone who holds this key is you. It leaves this page only when you choose a destination below \u2014 never logged, never sent to ", appName, "."] }), showKey ? (_jsx("div", { className: "mb-3 break-all rounded-lg border border-[var(--tb-line)] bg-[var(--tb-surface-2)] px-3 py-2 font-mono text-[12px] text-[var(--tb-ink)]", children: getSessionNsec() })) : (_jsx("button", { type: "button", onClick: () => setShowKey(true), className: `mb-3 text-[12.5px] ${muted} underline-offset-2 hover:text-[var(--tb-ink)] hover:underline`, children: "Show the key on screen" })), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(DestButton, { onClick: () => void copyKey(), disabled: busy, children: copied ? "Copied" : "Copy" }), _jsx(DestButton, { onClick: () => void downloadEnv(), disabled: busy, children: "Download .env" }), _jsx(DestButton, { onClick: () => void passwordManagerSave(), disabled: busy, children: "Password manager" }), _jsx(DestButton, { onClick: () => {
165
+ }, className: `text-[12px] ${muted} hover:text-[var(--tb-ink)]`, children: "Hide" })] }), _jsxs("p", { className: `mb-3 text-[12.5px] leading-relaxed ${muted}`, children: ["Anyone who holds this key is you. It leaves this page only when you choose a destination below \u2014 never logged, never sent to ", appName, "."] }), _jsxs("div", { className: "flex flex-wrap gap-2", children: [_jsx(DestButton, { onClick: () => setShowKey((v) => !v), active: showKey, children: showKey ? "Conceal" : "Reveal" }), _jsx(DestButton, { onClick: () => void copyKey(), disabled: busy, children: copied ? "Copied" : "Copy" }), _jsx(DestButton, { onClick: () => void downloadEnv(), disabled: busy, children: "Download .env" }), _jsx(DestButton, { onClick: () => void passwordManagerSave(), disabled: busy, children: "Password manager" }), _jsx(DestButton, { onClick: () => {
165
166
  setDmOpen((v) => !v);
166
167
  setFlash(null);
167
- }, disabled: busy, active: dmOpen, children: "Send by DM" })] }), dmOpen && (_jsxs("div", { className: "mt-3 space-y-2 rounded-lg border border-[var(--tb-line)] bg-[var(--tb-surface-2)] p-3", children: [_jsx("p", { className: `text-[12px] leading-relaxed ${muted}`, children: "Encrypts the key to an npub you own and publishes the sealed message to public relays. Only that npub can open it." }), _jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsxs("label", { className: `block min-w-[16rem] flex-1 text-[12px] ${muted}`, children: ["Recipient npub", _jsx("input", { value: recipient, onChange: (e) => setRecipient(e.target.value), spellCheck: false, autoCapitalize: "off", autoCorrect: "off", placeholder: "npub1\u2026", className: `mt-1 h-11 ${input}` })] }), _jsx("button", { type: "button", onClick: () => void sendDm(), disabled: busy || recipient.trim().length < 60, className: "min-h-11 shrink-0 rounded-full border border-[var(--tb-accent)] bg-[var(--tb-accent)] px-4 text-[13px] font-semibold text-[var(--tb-on-accent)] disabled:opacity-40", children: busy ? "Sending…" : "Send encrypted DM" })] })] })), _jsxs("form", { ref: formRef, className: "absolute h-px w-px overflow-hidden opacity-0", "aria-hidden": "true", autoComplete: "on", onSubmit: (e) => {
168
+ }, disabled: busy, active: dmOpen, children: "Send by DM" })] }), showKey && (_jsx("div", { className: "mt-3 break-all rounded-lg border border-[var(--tb-line)] bg-[var(--tb-surface-2)] px-3 py-2 font-mono text-[12px] text-[var(--tb-ink)]", children: getSessionNsec() })), dmOpen && (_jsxs("div", { className: "mt-3 space-y-2 rounded-lg border border-[var(--tb-line)] bg-[var(--tb-surface-2)] p-3", children: [_jsx("p", { className: `text-[12px] leading-relaxed ${muted}`, children: "Encrypts the key to an npub you own and publishes the sealed message to public relays. Only that npub can open it." }), _jsxs("div", { className: "flex flex-wrap items-end gap-2", children: [_jsxs("label", { className: `block min-w-[16rem] flex-1 text-[12px] ${muted}`, children: ["Recipient npub", _jsx("input", { value: recipient, onChange: (e) => setRecipient(e.target.value), spellCheck: false, autoCapitalize: "off", autoCorrect: "off", placeholder: "npub1\u2026", className: `mt-1 h-11 ${input}` })] }), _jsx("button", { type: "button", onClick: () => void sendDm(), disabled: busy || recipient.trim().length < 60, className: "min-h-11 shrink-0 rounded-full border border-[var(--tb-accent)] bg-[var(--tb-accent)] px-4 text-[13px] font-semibold text-[var(--tb-on-accent)] disabled:opacity-40", children: busy ? "Sending…" : "Send encrypted DM" })] })] })), _jsxs("form", { ref: formRef, className: "absolute h-px w-px overflow-hidden opacity-0", "aria-hidden": "true", autoComplete: "on", onSubmit: (e) => {
168
169
  e.preventDefault();
169
170
  }, children: [_jsx("input", { ref: userRef, name: "username", autoComplete: "username", defaultValue: "", readOnly: true, tabIndex: -1 }), _jsx("input", { ref: passRef, name: "password", type: "password", autoComplete: "new-password", defaultValue: "", readOnly: true, tabIndex: -1 })] }), flash && (_jsx("p", { className: `mt-3 text-[12.5px] leading-relaxed ${flash.tone === "ok" ? "text-[var(--tb-ink)]" : "text-[var(--tb-err-ink)]"}`, role: "status", children: flash.text }))] }));
170
171
  }
@@ -3,7 +3,7 @@ export { default as AvatarPicker } from "./AvatarPicker.tsx";
3
3
  export { default as DebugPanel, type DebugPanelProps } from "./DebugPanel.tsx";
4
4
  export { default as NpubGate } from "./NpubGate.tsx";
5
5
  export { default as NostrProfilePanel } from "./NostrProfilePanel.tsx";
6
- export { default as QuoteScroller, type QuoteScrollerProps } from "./QuoteScroller.tsx";
6
+ export { default as QuoteScroller, type QuoteScrollerProps, type QuoteScrollerClassNames } from "./QuoteScroller.tsx";
7
7
  export { default as SessionKeyClaim } from "./SessionKeyClaim.tsx";
8
8
  export { default as WalletCard } from "./WalletCard.tsx";
9
9
  export { useSession, type Session } from "./useSession.ts";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tollbooth-dpyc/web",
3
- "version": "0.4.0",
3
+ "version": "0.5.0",
4
4
  "description": "Shared browser SDK for Tollbooth DPYC operator front ends: npub sign-in, proofs, MCP client, profile and wallet",
5
5
  "license": "Apache-2.0",
6
6
  "author": "Lonnie VanZandt",