From c263497ec8b05bc0f9254ed2f7ecb4dba6f67d4e Mon Sep 17 00:00:00 2001 From: Kostya Date: Thu, 15 Oct 2026 19:35:48 +0300 Subject: ui-web: add browser client for the Ex4 bonus A React + TypeScript single-page client served by Vite, working against the same servlets as the desktop client: login, the events screen with filters, details, order books and trading, and the account screen with deposit, holdings, ledger rows and the user directory. No file upload, as the exercise specifies. It looks like the desktop client on purpose: the three skins of theme.css as CSS variables, the four animations redone with SVG and keyframes, and the desktop's Nerd Fonts, which npm run dev copies from ui-fx instead of keeping a second copy in the repo. The shared chat sits in a drawer above the status bar, as on the desktop, on its own poll because chat lines don't move the market version. Vite forwards /guess-market to Tomcat on 8080, so the page and the API share an origin and the session cookie needs no CORS. The client polls /api/sync once a second and reloads only when the version moved. run-web.bat installs the packages and starts it on localhost:5173. package.sh stages the sources under build/dist/ex4, without node_modules. --- ui-web/src/App.tsx | 502 ++++++++++++++++++++++ ui-web/src/Chart.tsx | 94 +++++ ui-web/src/Events.tsx | 370 ++++++++++++++++ ui-web/src/Users.tsx | 298 +++++++++++++ ui-web/src/api.ts | 176 ++++++++ ui-web/src/graphics.tsx | 51 +++ ui-web/src/main.tsx | 10 + ui-web/src/styles.css | 1068 +++++++++++++++++++++++++++++++++++++++++++++++ 8 files changed, 2569 insertions(+) create mode 100644 ui-web/src/App.tsx create mode 100644 ui-web/src/Chart.tsx create mode 100644 ui-web/src/Events.tsx create mode 100644 ui-web/src/Users.tsx create mode 100644 ui-web/src/api.ts create mode 100644 ui-web/src/graphics.tsx create mode 100644 ui-web/src/main.tsx create mode 100644 ui-web/src/styles.css (limited to 'ui-web/src') diff --git a/ui-web/src/App.tsx b/ui-web/src/App.tsx new file mode 100644 index 0000000..204beae --- /dev/null +++ b/ui-web/src/App.tsx @@ -0,0 +1,502 @@ +import { FormEvent, ReactNode, useCallback, useEffect, useRef, useState } from 'react'; +import { + api, + ApiError, + ChatMessage, + CHEVRON, + EventDetail, + eventPath, + GLYPH, + Ledger, + MarketData, + money, + num, + optionTitle, + same, + Sync, +} from './api'; +import { Events } from './Events'; +import { MarketChart, Pinwheel } from './graphics'; +import { Users } from './Users'; + +export type Act = (work: () => Promise, done: string) => Promise; + +const SKINS = [ + ['rose-pine-dawn', 'Rosé Pine Dawn'], + ['catppuccin', 'Catppuccin'], + ['gruvbox', 'Gruvbox'], +]; + +function useSetting(key: string, initial: string): [string, (value: string) => void] { + const [value, setValue] = useState(() => { + try { + return localStorage.getItem(key) ?? initial; + } catch { + return initial; + } + }); + const set = (next: string) => { + setValue(next); + try { + localStorage.setItem(key, next); + } catch { + } + }; + return [value, set]; +} + +export function App() { + const [user, setUser] = useState(undefined); + const [notice, setNotice] = useState(null); + const [skin, setSkin] = useSetting('gm-skin', SKINS[0][0]); + const [animations, setAnimations] = useSetting('gm-animations', 'on'); + + useEffect(() => { + document.documentElement.dataset.skin = skin; + document.documentElement.classList.toggle('anim', animations === 'on'); + }, [skin, animations]); + + useEffect(() => { + api('/user/account') + .then((account) => setUser(account.owner)) + .catch(() => setUser(null)); + }, []); + + const leave = useCallback((why?: string) => { + setNotice(why ?? null); + setUser(null); + }, []); + + const controls = ( + <> + + + + ); + + if (user === undefined) return null; + if (user === null) return ; + return ; +} + +function Login({ notice, onLoggedIn }: { notice: string | null; onLoggedIn: (user: string) => void }) { + const [name, setName] = useState(''); + const [error, setError] = useState(notice); + const [busy, setBusy] = useState(false); + + async function submit(e: FormEvent) { + e.preventDefault(); + setBusy(true); + setError(null); + try { + const res = await api<{ username: string }>('/login', { username: name }); + onLoggedIn(res.username); + } catch (err) { + setError((err as Error).message); + setBusy(false); + } + } + + return ( +
+
+

Guess Market

+

Sign in to a market server

+ + setName(e.target.value)} /> + {error &&

{error}

} + +
+
+ ); +} + +function Market(props: { user: string; onLoggedOut: (why?: string) => void; controls: ReactNode }) { + const { user, onLoggedOut } = props; + const [data, setData] = useState(null); + const [tab, setTab] = useState<'events' | 'users'>('events'); + const [selectedKey, setSelectedKey] = useState(null); + const [dialog, setDialog] = useState<'deposit' | 'resolve' | null>(null); + const [offline, setOffline] = useState(false); + const [toast, setToast] = useState(null); + const refresh = useRef<() => Promise>(async () => {}); + + useEffect(() => { + let stopped = false; + let version = -1; + let timer: number | undefined; + + async function pull() { + const sync = await api(`/sync?since=${version}`); + if (!sync.changed) return; + const details = await Promise.all(sync.events.map((e) => api(eventPath(e.name)))); + if (stopped || sync.version < version) return; + version = sync.version; + setData({ + events: sync.events, + details: Object.fromEntries(details.map((d) => [d.summary.key, d])), + users: sync.users, + account: sync.account, + }); + } + + async function tick() { + try { + await pull(); + setOffline(false); + } catch (err) { + if (err instanceof ApiError && err.status === 401) { + stopped = true; + onLoggedOut('Your session ended. Please log in again.'); + } else { + setOffline(true); + } + } + } + + async function loop() { + await tick(); + if (!stopped) timer = window.setTimeout(loop, 1000); + } + + refresh.current = tick; + loop(); + return () => { + stopped = true; + window.clearTimeout(timer); + }; + }, [onLoggedOut]); + + useEffect(() => { + if (!toast) return; + const timer = window.setTimeout(() => setToast(null), 2500); + return () => window.clearTimeout(timer); + }, [toast]); + + const act: Act = useCallback(async (work, done) => { + try { + await work(); + setToast(done); + } catch (err) { + setToast((err as Error).message); + } + await refresh.current(); + }, []); + + async function logout() { + try { + await api('/logout', {}); + } catch { + } + onLoggedOut(); + } + + const selected = data?.events.find((e) => e.key === selectedKey) ?? data?.events[0]; + const detail = selected && data?.details[selected.key]; + + return ( +
+
Guess Market
+ +
+ +
+ {CHEVRON} + {window.location.host}/guess-market +
+ {props.controls} +
+ + {offline &&
Cannot reach the server. Retrying every second…
} + + {data === null || data.events.length === 0 ? ( +
+ +

{data === null ? 'Loading the market…' : 'No events yet'}

+ {data !== null && ( +

+ Events are uploaded from the desktop client. They appear here by themselves. +

+ )} +
+ ) : ( + <> +
+ + + + + acting as {user} + ACCOUNT BALANCE + + {money(data.account.balance)} + + +
+ + {/* key: a new element per tab, so the fade-in runs on every switch */} +
+ {tab === 'events' ? ( + setTab('users')} + onResolve={() => setDialog('resolve')} + /> + ) : ( + setDialog('deposit')} + /> + )} +
+ + )} + +
+ + {data === null + ? ` IDLE ${CHEVRON}` + : ` ${GLYPH.file} ${user} ${CHEVRON} ${GLYPH.bolt} ${data.events.length} events ${CHEVRON} ${GLYPH.users} ${data.users.length} users`} + + +
+ + {dialog === 'deposit' && ( + setDialog(null)} + onConfirm={(amount) => { + setDialog(null); + act(() => api('/user/deposit', { amount }), `Deposited ${money(amount)}`); + }} + /> + )} + {dialog === 'resolve' && detail && ( + setDialog(null)} + onConfirm={(i) => { + setDialog(null); + act( + () => api(eventPath(detail.summary.name) + '/resolve', { option: detail.state.markets[i].key }), + `Event resolved as ${detail.summary.optionNames[i]}`, + ); + }} + /> + )} + + {toast && ( +
+ {toast} +
+ )} +
+ ); +} + +function Chat({ user, onError }: { user: string; onError: (message: string) => void }) { + const [messages, setMessages] = useState([]); + const [open, setOpen] = useState(false); + const [unread, setUnread] = useState(0); + const [text, setText] = useState(''); + const openRef = useRef(open); + openRef.current = open; + const list = useRef(null); + + useEffect(() => { + let stopped = false; + let last = 0; + let timer: number | undefined; + async function loop() { + try { + const said = await api(`/chat?since=${last}`); + if (!stopped && said.length > 0) { + last = said[said.length - 1].id; + setMessages((m) => [...m, ...said]); + if (!openRef.current) setUnread((n) => n + said.length); + } + } catch { + } + if (!stopped) timer = window.setTimeout(loop, 1000); + } + loop(); + return () => { + stopped = true; + window.clearTimeout(timer); + }; + }, []); + + useEffect(() => { + if (list.current) list.current.scrollTop = list.current.scrollHeight; + }, [messages, open]); + + async function send(e: FormEvent) { + e.preventDefault(); + const line = text.trim(); + if (line === '') return; + setText(''); + try { + await api('/chat', { text: line.slice(0, 500) }); + } catch (err) { + onError((err as Error).message); + } + } + + return ( + <> + + {open && ( +
+

Chat

+
+ {messages.map((m) => ( +
+
+ {m.sender} {m.at} +
+
{m.text}
+
+ ))} +
+
+ setText(e.target.value)} + /> + +
+
+ )} + + ); +} + +function DepositDialog(props: { onCancel: () => void; onConfirm: (amount: string) => void }) { + const [amount, setAmount] = useState(''); + const valid = num(amount) > 0; + return ( +
+
{ + e.preventDefault(); + if (valid) props.onConfirm(amount.trim()); + }} + > +
Deposit funds
+
+ + setAmount(e.target.value)} + /> +
+
+ + +
+
+
+ ); +} + +function ResolveDialog(props: { detail: EventDetail; onCancel: () => void; onConfirm: (option: number) => void }) { + const [option, setOption] = useState(null); + const e = props.detail.summary; + return ( +
+
+
Close & resolve event
+
+

+ Pick the option the event ended with. The contract account is emptied to holders of the winning option; a + close-time fee is moved to the market maker. This cannot be undone. +

+
+ {[0, 1].map((i) => ( + + ))} +
+
+
+ + +
+
+
+ ); +} diff --git a/ui-web/src/Chart.tsx b/ui-web/src/Chart.tsx new file mode 100644 index 0000000..4caf3a5 --- /dev/null +++ b/ui-web/src/Chart.tsx @@ -0,0 +1,94 @@ +import { EventDetail, Ledger, num } from './api'; + +export type Point = [number, number]; + +const seconds = (at: string) => { + const t = Date.parse(at.replace(' ', 'T')); + return Number.isNaN(t) ? 0 : t / 1000; +}; +const now = () => Date.now() / 1000; +const clock = (t: number) => new Date(t * 1000).toTimeString().slice(0, 8); + +export function priceSeries(detail: EventDetail): Point[] { + const first = detail.summary.optionNames[0]; + const current = num(detail.state.markets[0]?.price) || 0.5; + const trades = [...detail.history].reverse(); + if (trades.length === 0) { + return [ + [now() - 60, current], + [now(), current], + ]; + } + const start = seconds(trades[0].at) || now(); + const points: Point[] = [[start - 60, 0.5]]; + for (const t of trades) { + const quantity = num(t.quantity); + const unit = quantity > 0 ? num(t.pricePaid) / quantity : current; + const price = t.optionName === first ? unit : 1 - unit; + points.push([seconds(t.at) || start, Math.max(0, Math.min(1, price))]); + } + return points; +} + +export function balanceSeries(ledger: Ledger): Point[] { + const rows = ledger.entries; + const balance = num(ledger.balance); + if (rows.length === 0) { + return [ + [now() - 60, balance], + [now(), balance], + ]; + } + const start = seconds(rows[0].at) || now(); + const points: Point[] = [[start - 60, Math.max(0, num(rows[0].balanceAfter) - num(rows[0].amount))]]; + for (const row of rows) { + points.push([seconds(row.at) || start, num(row.balanceAfter)]); + } + return points; +} + +const TICKS = [0, 1, 2, 3, 4]; + +export function LineChart(props: { + series: { points: Point[]; tone: 'accent' | 'yes' | 'no' }[]; + range?: [number, number]; + height?: number; +}) { + const all = props.series.flatMap((s) => s.points); + const t0 = Math.min(...all.map((p) => p[0])); + const t1 = Math.max(...all.map((p) => p[0]), t0 + 60); + let [lo, hi] = props.range ?? [Math.min(...all.map((p) => p[1]), 0), Math.max(...all.map((p) => p[1]))]; + if (hi <= lo) hi = lo + 1; + if (!props.range) hi = lo + Math.ceil(((hi - lo) * 1.1) / 4) * 4; // headroom, in four whole steps + + const x = (t: number) => ((t - t0) / (t1 - t0)) * 100; + const y = (v: number) => 100 - ((v - lo) / (hi - lo)) * 100; + const label = (v: number) => (hi - lo <= 1 ? v.toFixed(2).replace(/\.?0+$/, '') || '0' : Math.round(v).toLocaleString()); + + return ( +
+
+ {TICKS.map((i) => ( + {label(hi - ((hi - lo) * i) / 4)} + ))} +
+ + {TICKS.map((i) => ( + + ))} + {props.series.map((s, i) => ( + `${j ? 'L' : 'M'}${x(p[0]).toFixed(2)} ${y(p[1]).toFixed(2)}`).join(' ')} + /> + ))} + +
+ {TICKS.map((i) => ( + {clock(t0 + ((t1 - t0) * i) / 4)} + ))} +
+
+ ); +} diff --git a/ui-web/src/Events.tsx b/ui-web/src/Events.tsx new file mode 100644 index 0000000..e33b4e2 --- /dev/null +++ b/ui-web/src/Events.tsx @@ -0,0 +1,370 @@ +import { useState } from 'react'; +import { + api, + EventDetail, + eventPath, + EventSummary, + feeLabel, + FeeTiming, + MarketData, + Mechanism, + mechanismLabel, + money, + num, + OrderBook, + same, + SEP, + Status, +} from './api'; +import type { Act } from './App'; +import { LineChart, priceSeries } from './Chart'; +import { Equalizer } from './graphics'; + +const STATUS_PILL: Record = { + DRAFT: ['', 'IDLE'], + ACTIVE: ['active', 'ACTIVE'], + SETTLED: ['closed', 'CLOSED'], +}; + +function Filter(props: { + label: string; + value: T | null; + options: [T, string][]; + onChange: (value: T | null) => void; +}) { + return ( +
+ {props.label} + + {props.options.map(([value, text]) => ( + + ))} +
+ ); +} + +export function Events(props: { + data: MarketData; + user: string; + selected: EventSummary | undefined; + onSelect: (key: string) => void; + act: Act; + onTrade: () => void; + onResolve: () => void; +}) { + const { data, selected } = props; + const [method, setMethod] = useState(null); + const [status, setStatus] = useState(null); + const [fee, setFee] = useState(null); + + const shown = data.events.filter( + (e) => + (method === null || e.mechanism === method) && + (status === null || e.status === status) && + (fee === null || e.commissionTiming === fee), + ); + const detail = selected && data.details[selected.key]; + + return ( + <> +
+ + + +
+ {shown.map((e) => ( + + ))} +
+ + {shown.length} of {data.events.length} events shown + +
+ + {detail ? ( + + ) : ( +
+ )} + + ); +} + +function EventView(props: { detail: EventDetail; user: string; act: Act; onTrade: () => void; onResolve: () => void }) { + const { detail, user, act } = props; + const e = detail.summary; + const markets = detail.state.markets; + const isMm = same(e.marketMaker, user); + const live = e.status === 'ACTIVE' ? 'LIVE' : e.status === 'SETTLED' ? 'ENDED' : 'IDLE'; + const yes = priceSeries(detail); + + return ( +
+
+
+
+

+ {e.displayId}. {e.name} +

+

+ {e.description} +

+
+ {/* Open = go trade on an active event, or the Market Maker starting their own */} + {e.status === 'ACTIVE' && ( + + )} + {e.status === 'DRAFT' && isMm && ( + + )} + {e.status === 'ACTIVE' && isMm && ( + + )} +
+
+ + + {live} + + + Method {mechanismLabel(e.mechanism)} + + + Status {e.status} + + + Market Maker {e.marketMaker} + + + Fee {feeLabel(e)} + + + Contract {money(e.accountBalance)} + +
+
+ +
+ {e.status === 'SETTLED' && ( +
+ RESOLVED + + Winning option: {detail.settledMarket} {SEP} contract emptied to its holders + +
+ )} + + {e.mechanism === 'LMSR' ? ( + <> +
+ {markets.map((m, i) => ( +
+
+ + {i === 0 ? 'YES' : 'NO'} {m.name} + + + {money(m.price)} + +
+
+ +
+ + {m.volume} shares {SEP} p = {num(m.price).toFixed(2)} + +
+ ))} +
+
+
+ Share price over time + + YES / NO {SEP} LMSR + +
+ [t, 1 - v]), tone: 'no' }, + ]} + /> +
+ + ) : ( + <> +
+ {detail.orderBooks.map((book, i) => ( + + ))} +
+
+
+ Last trade price over time + + last trade YES + +
+ +
+ + )} + +
+
+ Trade history newest first +
+
+
+ # + User + Option + Shares + Paid +
+ {detail.history.map((t, i) => ( +
+ #{detail.history.length - i} + {t.userName} + + {t.optionName} + + {t.quantity} shares + {money(t.pricePaid)} +
+ ))} + {detail.history.length === 0 &&
No trades yet
} +
+
+ +
+
Participants
+
+
+ User + YES + NO + Value + Fees paid +
+ {detail.participants.map((p) => ( +
+ + {p.user} + {p.tag && ` (${p.tag})`} + + {p.yes} + {p.no} + {p.value} + {p.fees} +
+ ))} + {detail.participants.length === 0 &&
Nobody yet
} +
+
+
+
+ ); +} + +function Book({ book, last, side }: { book: OrderBook; last: string | undefined; side: string }) { + const mid = book.bestBid && book.bestAsk ? money((num(book.bestBid) + num(book.bestAsk)) / 2) : '—'; + return ( +
+
+ {side} Order Book + {book.optionName} + {book.orders.length} orders +
+
+ {[ + ['Last', money(last)], + ['Best bid', book.bestBid ?? '—'], + ['Best ask', book.bestAsk ?? '—'], + ['Mid', mid], + ['Spread', book.spread ?? '—'], + ].map(([label, value]) => ( + + {label} + {value} + + ))} +
+
+ Price + Side + Qty + User +
+ {book.orders.map((o, i) => ( +
+ {o.price} + {o.side} + {o.quantity} + {o.user} +
+ ))} + {book.orders.length === 0 &&
No resting orders
} +
+ ); +} diff --git a/ui-web/src/Users.tsx b/ui-web/src/Users.tsx new file mode 100644 index 0000000..b2593d9 --- /dev/null +++ b/ui-web/src/Users.tsx @@ -0,0 +1,298 @@ +import { useState } from 'react'; +import { api, EventSummary, feeLabel, MarketData, mechanismLabel, money, num, same, SEP } from './api'; +import type { Act } from './App'; +import { balanceSeries, LineChart } from './Chart'; +import { Sparkline } from './graphics'; + +export function Users(props: { + data: MarketData; + user: string; + selected: EventSummary | undefined; + onSelect: (key: string) => void; + act: Act; + onDeposit: () => void; +}) { + const { data, user, selected } = props; + const account = data.account; + const balance = num(account.balance); + + const myEvents = data.events.flatMap((e) => { + const me = data.details[e.key]?.participants.find((p) => same(p.user, user)); + const owner = same(e.marketMaker, user); + return owner || (me && (me.yes > 0 || me.no > 0)) ? [{ e, me, owner }] : []; + }); + const isMm = myEvents.some((row) => row.owner); + + return ( + <> +
+
+ User + Balance +
+ {/* A directory of everyone on the server; you can only ever act as yourself */} +
+ {data.users.map((u) => { + const me = same(u.username, user); + return ( +
+ + + {u.username} + + + {u.marketMaker ? 'Market Maker' : 'Trader'} + {me ? ' (you)' : u.online ? '' : ' · offline'} + + + {money(u.balance)} +
+ ); + })} +
+ +
+ +
+
+
+
+

{user}

+ + {account.blocked ? 'BLOCKED' : isMm ? 'MARKET MAKER' : 'TRADER'} + +
+

Active in {myEvents.length} events

+
+ +
+
Balance
+
{money(account.balance)}
+
+
+ +
+ {account.blocked && ( +
+ BLOCKED + + This account reached a negative balance. All trading actions are disabled until you deposit enough + funds to bring it back above zero. + +
+ )} + +
+
+ Account balance over time + + every trade, fee and payout + +
+ +
+ +
+
Events participation / owner
+
+
+ Event + Role + Type + YES + NO + P/L +
+ {myEvents.map(({ e, me, owner }) => { + const pnl = e.status === 'SETTLED' ? (me?.pnl ?? '$0.00') : '—'; + return ( +
props.onSelect(e.key)} + > + {e.name} + {owner ? 'Market Maker' : 'Trader'} + {mechanismLabel(e.mechanism)} + {me?.yes ?? 0} + {me?.no ?? 0} + {pnl} +
+ ); + })} + {myEvents.length === 0 &&
You are not part of any event yet
} +
+
+ + {/* key: a different event starts with a fresh form */} + {selected ? ( + + ) : ( +
+ Select an event to trade. +
+ )} + +
+
+ Account activity + + newest first + +
+
+
+ Time + Type + Details + Amount + Balance +
+ {/* seq is not unique across entries, so the position is the key */} + {[...account.entries].reverse().map((row, i) => ( +
+ {row.at} + {row.type} + {row.note} + {row.amount} + {row.balanceAfter} +
+ ))} + {account.entries.length === 0 && ( +
Nothing yet. Deposit funds to start trading.
+ )} +
+
+
+
+ + ); +} + +function TradePanel(props: { data: MarketData; user: string; act: Act; event: EventSummary }) { + const { data, user, event: e } = props; + const detail = data.details[e.key]; + const markets = detail?.state.markets ?? []; + const me = detail?.participants.find((p) => same(p.user, user)); + const held = [me?.yes ?? 0, me?.no ?? 0]; + const isBook = e.mechanism === 'ORDER_BOOK'; + + const [option, setOption] = useState(0); + const [side, setSide] = useState<'BUY' | 'SELL'>('BUY'); + const [quantity, setQuantity] = useState('50'); + const [price, setPrice] = useState('0.62'); + + const qty = Number(quantity); + const qtyOk = Number.isInteger(qty) && qty > 0; + const unit = isBook ? Number(price) : num(markets[option]?.price); + const priceOk = unit > 0; + const cost = qty * unit; + + let hint: string; + let allowed = false; + if (!qtyOk) hint = 'Shares must be a positive whole number.'; + else if (!priceOk) hint = 'Price per share must be positive.'; + else if (data.account.blocked) hint = 'Trading is disabled because this account is blocked.'; + else if (e.status !== 'ACTIVE') hint = 'Trading is only available for ACTIVE events.'; + else if (side === 'SELL' && !same(e.marketMaker, user) && qty > held[option]) + hint = `Cannot sell ${qty} shares; you only hold ${held[option]}.`; + else if (side === 'BUY' && num(data.account.balance) < cost) + hint = `Insufficient balance. Required: ${money(cost)}, available: ${money(data.account.balance)}`; + else { + allowed = true; + hint = + side === 'SELL' + ? 'Sell order will match existing bids or rest as an ask.' + : isBook + ? 'Buy order will match existing asks or rest as a bid.' + : 'Orders execute immediately against the market maker.'; + } + + const submit = () => + props.act( + () => + api('/orders', { + event: e.name, + option: markets[option].key, + side, + price: isBook ? price.trim() : markets[option].price, + quantity: String(qty), + }), + `Order placed ${SEP} ${side === 'BUY' ? 'Bought' : 'Sold'} ${qty} ${e.optionNames[option]}`, + ); + + return ( +
+
+ + {e.displayId}. {e.name} + + + {mechanismLabel(e.mechanism)} {SEP} Status: {e.status} {SEP} Fee: {feeLabel(e)} + +
+
+ {markets.map((m, i) => ( + + ))} +
+
+ + + {isBook && ( + + )} + + +
+ {hint} +
+ ); +} diff --git a/ui-web/src/api.ts b/ui-web/src/api.ts new file mode 100644 index 0000000..2ce1a8d --- /dev/null +++ b/ui-web/src/api.ts @@ -0,0 +1,176 @@ + +export type Mechanism = 'LMSR' | 'ORDER_BOOK'; +export type Status = 'DRAFT' | 'ACTIVE' | 'SETTLED'; +export type FeeTiming = 'ON_PURCHASE' | 'ON_CLOSE'; + +export interface EventSummary { + key: string; + displayId: number; + name: string; + description: string; + commissionPercent: number; + commissionTiming: FeeTiming; + mechanism: Mechanism; + status: Status; + optionNames: string[]; + accountBalance: string; + marketMaker: string; +} + +export interface Market { + key: string; + name: string; + price: string; + volume: string; +} + +export interface BookOrder { + side: string; + user: string; + quantity: number; + price: string; + isBid: boolean; +} + +export interface OrderBook { + optionKey: string; + optionName: string; + bestBid: string | null; + bestAsk: string | null; + spread: string | null; + orders: BookOrder[]; +} + +export interface TradeRow { + at: string; + userName: string; + optionName: string; + quantity: string; + pricePaid: string; +} + +export interface Participant { + user: string; + tag: string; + yes: number; + no: number; + value: string; + fees: string; + pnl: string; +} + +export interface EventDetail { + summary: EventSummary; + state: { markets: Market[]; accountBalance: string; commissionCollected: string }; + history: TradeRow[]; + settledMarket: string; + orderBooks: OrderBook[]; + participants: Participant[]; +} + +export interface LedgerEntry { + seq: number; + at: string; + type: string; + amount: string; + balanceAfter: string; + note: string; +} + +export interface Ledger { + owner: string; + balance: string; + blocked: boolean; + entries: LedgerEntry[]; +} + +export interface UserSummary { + username: string; + balance: string; + marketMaker: boolean; + online: boolean; +} + +export interface Sync { + changed: boolean; + version: number; + events: EventSummary[]; + users: UserSummary[]; + account: Ledger; +} + +export interface ChatMessage { + id: number; + at: string; + sender: string; + text: string; +} + +export interface MarketData { + events: EventSummary[]; + details: Record; + users: UserSummary[]; + account: Ledger; +} + +export class ApiError extends Error { + constructor( + public status: number, + message: string, + ) { + super(message); + } +} + +const BASE = '/guess-market/api'; +const UNREACHABLE = 'Cannot reach the server. Is Tomcat running on port 8080?'; + +export async function api(path: string, form?: Record): Promise { + let res: Response; + try { + res = await fetch( + BASE + path, + form ? { method: 'POST', body: new URLSearchParams(form) } : undefined, + ); + } catch { + throw new ApiError(0, UNREACHABLE); + } + const text = await res.text(); + let body: any = null; + try { + body = text ? JSON.parse(text) : null; + } catch { + } + if (!res.ok) { + throw new ApiError(res.status, body?.message ?? (res.status >= 500 ? UNREACHABLE : `The server answered ${res.status}.`)); + } + return body as T; +} + +export const eventPath = (name: string) => '/events/' + encodeURIComponent(name); + +export function num(value: string | number | null | undefined): number { + const n = typeof value === 'number' ? value : Number(String(value ?? '').replace(/[$,]/g, '')); + return Number.isNaN(n) ? 0 : n; +} + +export const same = (a: string, b: string) => a.toLowerCase() === b.toLowerCase(); + +export function money(value: string | number | null | undefined): string { + if (value === null || value === undefined || value === '') return '—'; + const n = typeof value === 'number' ? value : Number(String(value).replace(/[$,]/g, '')); + if (Number.isNaN(n)) return String(value); + return (n < 0 ? '-$' : '$') + Math.abs(n).toFixed(2); +} + +export const mechanismLabel = (m: Mechanism) => (m === 'LMSR' ? 'LMSR' : 'Order Book'); + +export const CHEVRON = '\ue0b1'; +export const SEP = '\ueb04'; + +export const optionTitle = (e: EventSummary, i: number) => `${i === 0 ? 'YES' : 'NO'} ${SEP} ${e.optionNames[i]}`; + +export const feeLabel = (e: EventSummary) => + `${e.commissionPercent}% ${e.commissionTiming === 'ON_PURCHASE' ? 'on purchase' : 'on close'}`; + +export const GLYPH = { file: '\uf15b', bolt: '\uf0e7', users: '\uf0c0', chat: '\u{f0b79}' }; diff --git a/ui-web/src/graphics.tsx b/ui-web/src/graphics.tsx new file mode 100644 index 0000000..2d452df --- /dev/null +++ b/ui-web/src/graphics.tsx @@ -0,0 +1,51 @@ + +export function Equalizer() { + return ( + + ); +} + +export function Sparkline({ negative }: { negative: boolean }) { + return ( + + ); +} + +export function MarketChart() { + return ( + + ); +} + +export function Pinwheel() { + return ( + + ); +} diff --git a/ui-web/src/main.tsx b/ui-web/src/main.tsx new file mode 100644 index 0000000..ed3b67f --- /dev/null +++ b/ui-web/src/main.tsx @@ -0,0 +1,10 @@ +import { StrictMode } from 'react'; +import { createRoot } from 'react-dom/client'; +import { App } from './App'; +import './styles.css'; + +createRoot(document.getElementById('root')!).render( + + + , +); diff --git a/ui-web/src/styles.css b/ui-web/src/styles.css new file mode 100644 index 0000000..028e2d2 --- /dev/null +++ b/ui-web/src/styles.css @@ -0,0 +1,1068 @@ + +@font-face { + font-family: 'CaskaydiaCove NF'; + src: url('/fonts/CaskaydiaCoveNerdFont-Regular.ttf'); +} +@font-face { + font-family: 'CaskaydiaCove NF'; + font-weight: bold; + src: url('/fonts/CaskaydiaCoveNerdFont-Bold.ttf'); +} +@font-face { + font-family: 'JetBrainsMono NF'; + src: url('/fonts/JetBrainsMonoNerdFont-Regular.ttf'); +} +@font-face { + font-family: 'JetBrainsMono NF'; + font-weight: bold; + src: url('/fonts/JetBrainsMonoNerdFont-Bold.ttf'); +} +@font-face { + font-family: 'FiraCode Nerd Font'; + src: url('/fonts/FiraCodeNerdFont-Regular.ttf'); +} +@font-face { + font-family: 'FiraCode Nerd Font'; + font-weight: bold; + src: url('/fonts/FiraCodeNerdFont-Bold.ttf'); +} + +:root, +:root[data-skin='rose-pine-dawn'] { + --font: 'CaskaydiaCove NF', Consolas, monospace; + --size: 13px; + --bg: #faf4ed; + --panel: #fffaf3; + --panel2: #f2e9e1; + --panel3: #dfdad9; + --line: #cecacd; + --ink: #575279; + --ink2: #797593; + --accent: #907aa9; + --accent-fg: #fffaf3; + --btn: #f2e9e1; + --btn-line: #cecacd; + --yes: #286983; + --no: #b4637a; + --yes-soft: #e3edf0; + --no-soft: #f5e6ea; +} + +:root[data-skin='catppuccin'] { + --font: 'JetBrainsMono NF', Consolas, monospace; + --bg: #181825; + --panel: #1e1e2e; + --panel2: #313244; + --panel3: #45475a; + --line: #585b70; + --ink: #cdd6f4; + --ink2: #a6adc8; + --accent: #cba6f7; + --accent-fg: #1e1e2e; + --btn: #313244; + --btn-line: #585b70; + --yes: #a6e3a1; + --no: #f38ba8; + --yes-soft: #23312a; + --no-soft: #34232c; +} + +:root[data-skin='gruvbox'] { + --font: 'FiraCode Nerd Font', Consolas, monospace; + --size: 13.5px; + --bg: #1d2021; + --panel: #282828; + --panel2: #3c3836; + --panel3: #504945; + --line: #665c54; + --ink: #ebdbb2; + --ink2: #a89984; + --accent: #fe8019; + --accent-fg: #1d2021; + --btn: #3c3836; + --btn-line: #665c54; + --yes: #b8bb26; + --no: #fb4934; + --yes-soft: #2b3021; + --no-soft: #3b2320; +} + + box-sizing: border-box; +} +html, +body, + height: 100%; +} +body { + margin: 0; + background: var(--bg); + color: var(--ink); + font: var(--size) / 1.35 var(--font); +} +h1, +h2, +h3, +p { + margin: 0; + font-weight: inherit; +} + +.ink2 { + color: var(--ink2); +} +.accent { + color: var(--accent); +} +.yes { + color: var(--yes); +} +.no { + color: var(--no); +} +.bold { + font-weight: 700; +} +.xs { + font-size: 10.5px; +} +.sm { + font-size: 11.5px; +} +.base { + font-size: 12.5px; +} +.lg { + font-size: 14px; +} +.xl { + font-size: 17px; +} +.grow { + flex: 1; + min-width: 0; +} +.ellipsis { + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.row { + display: flex; + align-items: center; + gap: 8px; +} +.num { + text-align: right; + white-space: nowrap; +} + +button, +input, +select { + font: inherit; + color: inherit; +} +button { + cursor: pointer; +} +button:disabled { + opacity: 0.45; + cursor: default; +} +:focus-visible { + outline: 2px solid var(--accent); + outline-offset: 1px; +} +.btn { + border: 1px solid var(--btn-line); + border-radius: 5px; + background: var(--btn); + font-size: 13px; + font-weight: 700; + padding: 8px 15px; + white-space: nowrap; +} +.btn:hover:not(:disabled) { + opacity: 0.92; +} +.btn.primary { + background: var(--accent); + border-color: var(--accent); + color: var(--accent-fg); +} +.btn.destructive { + background: var(--no); + border-color: var(--no); + color: var(--accent-fg); +} +.btn.icon { + padding: 4px 8px; + min-width: 34px; + height: 30px; + display: grid; + place-items: center; +} +.btn.icon.on { + background: var(--panel3); + border-color: var(--accent); +} +.toggle { + border: 1px solid var(--btn-line); + border-radius: 4px; + background: var(--btn); + color: var(--ink2); + font-size: 12px; + padding: 5px 11px; +} +.toggle.on { + background: var(--accent); + border-color: var(--accent); + color: var(--accent-fg); +} +.seg { + border: 1px solid var(--btn-line); + background: var(--btn); + font-size: 12px; + font-weight: 700; + padding: 8px 15px; +} +.seg:first-child { + border-radius: 5px 0 0 5px; +} +.seg:last-child { + border-radius: 0 5px 5px 0; + border-left: 0; +} +.seg.on { + background: var(--accent); + color: var(--accent-fg); +} +.field { + background: var(--panel2); + border: 1px solid var(--btn-line); + border-radius: 5px; + padding: 8px 10px; + font-size: 13px; + color: var(--ink); + width: 96px; +} +.field.bad { + border-color: var(--no); + border-width: 1.5px; +} +.select { + background: var(--btn); + border: 1px solid var(--btn-line); + border-radius: 5px; + padding: 6px 8px; + font-size: 12.5px; +} + +.pill { + display: inline-flex; + align-items: center; + gap: 7px; + border-radius: 3px; + padding: 3px 6px; + font-size: 10px; + font-weight: 700; + background: var(--panel3); + color: var(--ink2); + white-space: nowrap; +} +.pill.active { + background: var(--yes-soft); + color: var(--yes); +} +.pill.closed { + background: var(--no-soft); + color: var(--no); +} +.pill.mm { + background: var(--accent); + color: var(--accent-fg); +} +.pill.blocked { + background: var(--no); + color: var(--accent-fg); +} +.pill.resolved { + background: var(--yes); + color: var(--accent-fg); +} + +.card { + background: var(--panel); + border: 1px solid var(--line); + border-radius: 7px; +} +.card2 { + background: var(--panel2); + border: 1px solid var(--line); + border-radius: 6px; +} +.table { + background: var(--panel); + border: 1px solid var(--line); + border-radius: 6px; + overflow: hidden; +} +.thead, +.trow { + display: flex; + align-items: center; + gap: 8px; + padding: 8px 11px; +} +.thead { + background: var(--panel3); + color: var(--ink2); + font-size: 10.5px; + font-weight: 700; +} +.trow { + border-top: 1px solid var(--line); + font-size: 11.5px; +} +.trow.click { + cursor: pointer; +} +.trow.click:hover { + background: var(--panel2); +} +.trow.on { + background: var(--panel3); +} +.trow.bid { + background: var(--yes-soft); +} +.trow.ask { + background: var(--no-soft); +} +.w54 { + width: 54px; +} +.w66 { + width: 66px; +} +.w78 { + width: 78px; +} +.w92 { + width: 92px; +} +.w150 { + width: 150px; +} + +.app { + display: flex; + flex-direction: column; + height: 100%; + min-width: 1040px; +} +.windowbar { + display: flex; + align-items: center; + gap: 10px; + height: 32px; + padding: 0 14px; + background: var(--panel2); + border-bottom: 1px solid var(--line); + font-size: 12.5px; + font-weight: 700; + color: var(--ink2); +} +.toolbar { + display: flex; + align-items: center; + gap: 12px; + padding: 12px 16px; + background: var(--panel); + border-bottom: 1px solid var(--line); +} +.path { + display: flex; + align-items: center; + gap: 10px; + padding: 8px 12px; + font-size: 12.5px; +} +.tabs { + display: flex; + align-items: flex-end; + gap: 2px; + padding: 6px 16px 0; + background: var(--panel); + border-bottom: 1px solid var(--line); +} +.tab { + border: 1px solid var(--line); + border-bottom: 0; + border-radius: 6px 6px 0 0; + background: var(--panel2); + color: var(--ink2); + font-size: 13px; + font-weight: 700; + padding: 9px 20px; + margin-bottom: -1px; +} +.tab.on { + background: var(--bg); + color: var(--ink); +} +.tabinfo { + display: flex; + align-items: center; + gap: 8px; + padding: 0 4px 8px; + font-size: 12.5px; + color: var(--ink2); +} +.content { + flex: 1; + min-height: 0; + display: flex; + gap: 12px; + padding: 12px 16px; +} +.statusbar { + display: flex; + align-items: center; + height: 30px; + padding: 0 14px; + background: var(--panel2); + border-top: 1px solid var(--line); + font-size: 11.5px; + color: var(--ink2); + white-space: pre; +} +.chatbtn { + border: 0; + background: none; + padding: 0 2px; + color: var(--ink2); + font-size: 14.5px; + cursor: pointer; +} +.chatbtn.on { + color: var(--accent); +} +.chat { + position: fixed; + right: 14px; + bottom: 31px; + width: 320px; + height: 380px; + display: flex; + flex-direction: column; + gap: 8px; + padding: 12px; + white-space: normal; + color: var(--ink); + box-shadow: 0 4px 18px rgb(0 0 0 / 0.3); + z-index: 2; +} +.chatlist { + flex: 1; + min-height: 0; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 9px; + overflow-wrap: anywhere; +} +.banner { + padding: 8px 16px; + font-weight: 700; + background: var(--no-soft); + color: var(--no); + border-bottom: 1px solid var(--no); +} +.toast { + position: fixed; + left: 50%; + bottom: 44px; + transform: translateX(-50%); + max-width: 90vw; + background: var(--ink); + color: var(--bg); + border-radius: 6px; + padding: 10px 16px; + font-size: 12.5px; + font-weight: 700; + z-index: 3; +} +.empty { + flex: 1; + display: flex; + flex-direction: column; + align-items: center; + justify-content: center; + gap: 14px; + text-align: center; +} + +.side { + display: flex; + flex-direction: column; + gap: 6px; + padding: 12px; +} +.side.events { + width: 498px; +} +.side.users { + width: 274px; +} +.main { + flex: 1; + min-width: 0; + display: flex; + flex-direction: column; +} +.head { + display: flex; + align-items: flex-start; + gap: 14px; + padding: 14px 16px; + border-bottom: 1px solid var(--line); +} +.body { + flex: 1; + min-height: 0; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 14px; + padding: 14px 16px; +} +.body > * { + flex-shrink: 0; +} +.section { + display: flex; + flex-direction: column; + gap: 7px; +} +.section-title { + display: flex; + align-items: baseline; + gap: 8px; + font-size: 12.5px; + font-weight: 700; +} +.filter { + display: flex; + align-items: center; + gap: 8px; + margin-bottom: 4px; +} +.filter > span { + width: 74px; + font-size: 12.5px; + color: var(--ink2); +} +.list { + flex: 1; + min-height: 0; + overflow-y: auto; + display: flex; + flex-direction: column; + gap: 2px; +} +.listrow { + display: flex; + align-items: center; + gap: 8px; + width: 100%; + text-align: left; + background: transparent; + border: 0; + border-left: 3px solid transparent; + border-radius: 5px; + padding: 9px 11px; +} +.listrow:hover { + background: var(--panel2); +} +.listrow.on { + background: var(--panel3); + border-left-color: var(--accent); +} +.listrow.plain { + cursor: default; +} +.meta { + display: flex; + align-items: center; + flex-wrap: wrap; + gap: 4px 16px; + font-size: 12.5px; +} +.meta b { + font-weight: 700; +} +.pair { + display: grid; + grid-template-columns: 1fr 1fr; + gap: 10px; +} +.optcard { + border: 1px solid var(--line); + border-radius: 6px; + padding: 12px 14px; + display: flex; + flex-direction: column; + gap: 8px; +} +.optcard.yes { + background: var(--yes-soft); +} +.optcard.no { + background: var(--no-soft); +} +.optcard.pick { + background: var(--panel); + cursor: pointer; + text-align: left; + color: var(--ink); + padding: 10px 12px; + gap: 6px; +} +.optcard.pick.yes.on { + background: var(--yes-soft); + border: 1.5px solid var(--yes); +} +.optcard.pick.no.on { + background: var(--no-soft); + border: 1.5px solid var(--no); +} +.bar { + height: 6px; + border-radius: 3px; + background: var(--panel3); + overflow: hidden; +} +.bar i { + display: block; + height: 100%; + border-radius: 3px; + background: currentColor; + transition: width 0.3s; +} +.stats { + display: flex; + gap: 16px; + padding: 8px 11px; + font-size: 11.5px; +} +.stats span { + display: flex; + flex-direction: column; + gap: 2px; +} +.tradeform { + display: flex; + flex-wrap: wrap; + align-items: flex-end; + gap: 10px; +} +.tradeform label { + display: flex; + flex-direction: column; + gap: 5px; + font-size: 12.5px; + color: var(--ink2); +} +.balance { + font-size: 22px; + font-weight: 700; + color: var(--accent); +} +.balance.neg, +.neg { + color: var(--no); +} +.balcell { + font-weight: 700; + color: var(--accent); +} +.pnl { + font-size: 12px; + font-weight: 700; + color: var(--yes); +} +.notice { + display: flex; + align-items: center; + gap: 11px; + padding: 11px 13px; + border-radius: 6px; + border: 1px solid var(--line); + background: var(--yes-soft); + font-size: 12.5px; +} +.notice.blocked { + background: var(--no-soft); + border-color: var(--no); +} + +.chart { + display: grid; + grid-template-columns: auto 1fr; + gap: 4px 6px; + padding: 10px; + font-size: 10px; + color: var(--ink2); +} +.chart .yaxis { + display: flex; + flex-direction: column; + justify-content: space-between; + text-align: right; + border-right: 1px solid var(--line); + padding-right: 6px; + line-height: 1; +} +.chart .xaxis { + grid-column: 2; + display: flex; + justify-content: space-between; + border-top: 1px solid var(--line); + padding-top: 4px; +} +.chart svg { + width: 100%; + display: block; +} +.chart .grid { + stroke: var(--line); + stroke-width: 1; + opacity: 0.6; +} +.chart path { + fill: none; + stroke-width: 2.5; + stroke-linejoin: round; + vector-effect: non-scaling-stroke; +} +.chart line { + vector-effect: non-scaling-stroke; +} +.stroke-accent { + stroke: var(--accent); +} +.stroke-yes { + stroke: var(--yes); +} +.stroke-no { + stroke: var(--no); +} + +.scrim { + position: fixed; + inset: 0; + display: grid; + place-items: center; + background: rgba(10, 10, 10, 0.42); + z-index: 2; +} +.dialog { + width: 430px; + max-width: calc(100vw - 32px); +} +.dialog > header { + padding: 16px 20px; + border-bottom: 1px solid var(--line); + font-size: 14px; + font-weight: 700; +} +.dialog > div { + display: flex; + flex-direction: column; + gap: 10px; + padding: 18px 20px; +} +.dialog > footer { + display: flex; + justify-content: flex-end; + gap: 9px; + padding: 14px 20px; + border-top: 1px solid var(--line); +} +.resolveopt { + flex: 1; + border: 1px solid var(--line); + border-radius: 6px; + background: var(--panel2); + font-size: 14px; + font-weight: 700; + padding: 14px 6px; +} +.resolveopt.yes.on { + background: var(--yes-soft); + border: 1.5px solid var(--yes); +} +.resolveopt.no.on { + background: var(--no-soft); + border: 1.5px solid var(--no); +} + +.login { + height: 100%; + display: grid; + place-items: center; + padding: 24px; +} +.login form { + width: 380px; + max-width: 100%; + display: flex; + flex-direction: column; + gap: 8px; + padding: 20px 22px; +} +.login .field { + width: 100%; +} + +.eq rect { + fill: var(--ink2); + transform-box: fill-box; + transform-origin: bottom; +} +.pill.active .eq rect { + fill: var(--yes); +} +.pill.closed .eq rect { + fill: var(--no); +} +.eq .b0 { + transform: scaleY(0.35); +} +.eq .b1 { + transform: scaleY(0.8); +} +.eq .b2 { + transform: scaleY(0.55); +} +.anim .eq .b0 { + animation: eq0 3.6s linear infinite; +} +.anim .eq .b1 { + animation: eq1 3.6s linear infinite; +} +.anim .eq .b2 { + animation: eq2 3.6s linear infinite; +} +@keyframes eq0 { + 0%, + 100% { + transform: scaleY(0.35); + } + 30% { + transform: scaleY(1); + } + 60% { + transform: scaleY(0.6); + } +} +@keyframes eq1 { + 0%, + 100% { + transform: scaleY(0.8); + } + 25% { + transform: scaleY(0.3); + } + 70% { + transform: scaleY(1); + } +} +@keyframes eq2 { + 0%, + 100% { + transform: scaleY(0.55); + } + 45% { + transform: scaleY(1); + } + 80% { + transform: scaleY(0.4); + } +} + +.draw { + fill: none; + stroke-linecap: round; + stroke-linejoin: round; + stroke-dasharray: 100; + stroke-dashoffset: 0; +} +.rider { + offset-rotate: 0deg; + offset-distance: 100%; +} +.spark .draw { + stroke: var(--accent); + stroke-width: 2; +} +.spark .rider { + fill: var(--accent); + offset-path: path('M2 20 L14 16 L26 22 L38 11 L50 14 L62 5'); +} +.spark.neg .draw { + stroke: var(--no); +} +.spark.neg .rider { + fill: var(--no); +} +.anim .spark .draw { + animation: draw70 3.6s infinite; +} +.anim .spark .rider { + animation: + ride70 3.6s infinite, + appear 3.6s linear infinite; +} +@keyframes draw70 { + 0% { + stroke-dashoffset: 100; + animation-timing-function: ease-in-out; + } + 70%, + 100% { + stroke-dashoffset: 0; + } +} +@keyframes ride70 { + 0% { + offset-distance: 0%; + animation-timing-function: ease-in-out; + } + 70%, + 100% { + offset-distance: 100%; + } +} +@keyframes appear { + 0% { + opacity: 0; + } + 8%, + 100% { + opacity: 1; + } +} + +.mchart .rule { + stroke: var(--line); +} +.mchart text { + fill: var(--ink2); + font-size: 9px; + opacity: 0.7; +} +.mchart .draw { + stroke-width: 2.5; +} +.mchart .y { + stroke: var(--yes); +} +.mchart .n { + stroke: var(--no); +} +.mchart .rider.y { + fill: var(--yes); + stroke: none; + offset-path: path('M22 66 C96 64 150 22 224 22'); +} +.mchart .rider.n { + fill: var(--no); + stroke: none; + offset-path: path('M22 66 C96 68 150 110 224 110'); +} +.anim .mchart .draw { + animation: draw55 3.6s infinite; +} +.anim .mchart .rider { + animation: + ride55 3.6s infinite, + appear 3.6s linear infinite; +} +.anim .mchart text { + animation: breathe 3.6s linear infinite; +} +.anim .mchart text.lo { + animation-delay: -3.2s; +} +@keyframes draw55 { + 0% { + stroke-dashoffset: 100; + animation-timing-function: ease-in-out; + } + 55%, + 100% { + stroke-dashoffset: 0; + } +} +@keyframes ride55 { + 0% { + offset-distance: 0%; + animation-timing-function: ease-in-out; + } + 55%, + 100% { + offset-distance: 100%; + } +} +@keyframes breathe { + 0%, + 100% { + opacity: 0.25; + } + 50% { + opacity: 0.7; + } +} + +.pinwheel path { + fill: var(--ink2); +} +.pinwheel circle { + fill: var(--panel); + stroke: var(--ink2); +} +.btn.icon.on .pinwheel path { + fill: var(--accent); +} +.btn.icon.on .pinwheel circle { + stroke: var(--accent); +} +.pinwheel g { + transform-origin: 10px 10px; +} +.anim .pinwheel g { + animation: spin 2.4s linear infinite; +} +@keyframes spin { + to { + transform: rotate(360deg); + } +} + +.anim .fade { + animation: fade 0.5s; +} +@keyframes fade { + from { + opacity: 0; + } +} + +@media (prefers-reduced-motion: reduce) { + .anim * { + animation: none !important; + } +} -- cgit v1.2.3