Styling
An extension can change how a chat looks in three ways, from strongest to gentlest:
| Call | Permission | What it styles |
|---|---|---|
rin.ui.style(css) | ui.style | The chat window, like a card's chat style |
rin.ui.partStyle(css) | any drawing ui.* permission | Only this extension's own panel and notes |
rin.ui.theme(theme) | ui.theme | Nothing, until the user picks the theme it offers |
The script never writes a stylesheet. It hands Rin Chat a string, and Rin Chat scopes and sanitizes it before any of it reaches the page.
ui.style: the chat window
rin.on("onChatOpen", async () => {
await rin.ui.style(`
:scope { --rc-glow: #8b7cf6; }
.rc-message .rc-bubble { border-left: 3px solid var(--rc-glow); }
:scope[data-rc-mood="angry"] .rc-bubble { border-left-color: #e5484d; }
`);
});
ui.style CSS goes through the same sanitizer as a card's chat style, in its "window" mode, with :scope as
the chat window root. Writing it is writing a card chat style; you can preview the same CSS in the card
editor's Chat style tab. At most 64 KiB; a new call replaces the last; null removes it.
What the sanitizer does
- Scopes every selector under the window. A selector that tries to leave it is dropped.
- Drops
url()in every spelling (so no images, fonts or requests from CSS),@import,@font-face,@layer,@page,@namespaceand other at-rules it does not keep. - Renames
@keyframesand@propertynames per style, so yours never replace the app's own. - Turns
position: fixedintoabsolute, inside the window. - Limits the root. Declarations on
:scopeitself keep only properties that cannot move the window or paint outside it: custom properties, color, font and text properties, background, padding, gap, border (notborder-image), opacity, cursor, line and letter spacing, transitions, scrollbar colors and backdrop filters. No margin, transform, position, display, outline, box-shadow or filter on the root. Everything inside the window is clipped to it.
On top, for extensions
- The trust marks are out of reach. A selector is dropped when it names the composer or its send button,
the extension marks ("Extension", "Changed by", the names on panels and notes), badges, the prompt
inspector, the network review dialog, or any modal or dialog. Selectors on class or id attributes
(
[class*=...],[id^=...], with or without a namespace) are dropped too, since they reach a class without naming it. CSS escapes and comments do not get around this: the check reads the selector with both removed. - Generic selectors skip the composer.
*,button,textareaordivnever match the composer or anything inside it, so a style cannot hide or fake it. - The marks stay visible. Rin Chat pins the marks (visibility, opacity, size, color) with rules your CSS cannot override, and draws them above anything you position.
z-indexis capped. It must beautoor a plain integer from -99999 to 99999. Anything else (var(),calc(), a larger number, a keyframe animating it) is dropped.- The card wins. Your style sits before the card's own chat style at the same specificity, so where both set something, the card's chat style wins.
- The user can turn it off in one chat: the chat's Extensions dialog has Use its styling in this chat for each extension that set a style there. The extension keeps running.
Reacting to the story
Chat variables reach the window root, as they do for card chat styles, but only those your CSS mentions:
- A variable holding a number becomes the custom property
--rc-var-<name>(unitless), socalc(var(--rc-var-hp) * 1%)works. - A variable holding a short word becomes the attribute
data-rc-<name>="<word>"on the root (lowercased, accents removed, other characters turned into-, at most 32 characters). - In Adventure Mode,
data-rc-combat="on"while a turn order is declared, anddata-rc-hpisdown,low,hurtorokfrom the player's hit points.
Names are written in lowercase in the CSS. With chat.vars, an extension can set the variable and style on
it:
await rin.chat.vars.set({ mood: "angry" });
// :scope[data-rc-mood="angry"] .rc-bubble { ... }
ui.partStyle: your own parts
await rin.ui.partStyle(`
:scope { background: #1e2430; border-radius: 8px; }
:scope button { border-color: #8b7cf6; }
`);
CSS for the extension's own sidebar panel and message notes only, with :scope as each part's root. The same
sanitizer and the same extension rules apply. It needs any of ui.widget, ui.panel, ui.hud,
ui.annotate, ui.choices, ui.notify, ui.style or ui.theme; without one it resolves false. No install
sentence: it reaches nothing but what the extension already draws.
ui.theme: offer, never apply
rin.on("onChatOpen", async () => {
await rin.ui.theme({
name: "Midnight Ink",
mode: "dark",
colors: { "--bg": "#0e1116", "--surface": "#171c24", "--foreground": "#e6e9ef", "--muted": "#9aa3b2", "--purple": "#8b7cf6" },
chat: { quoteColor: "#c9b8ff" },
});
});
A theme is token values, not CSS. It is offered under the extension in Settings > Extensions, and nothing
changes until the user presses Use: then it is saved as one of the user's own themes, named
"<theme name> (<extension name>)", and picked, just like choosing a theme in Theme & Colors. The user can
switch back there at any time. Offering again replaces the earlier offer; null withdraws it.
name: 1 to 40 characters.mode:"dark"or"light".colors: at least one Theme & Colors token, each#rgbor#rrggbb. The tokens are--bg,--bg-alt,--surface,--surface-accent,--surface-2,--color-nav-header,--foreground,--muted,--border,--border-accent,--purple,--highlight,--button-border,--purple-light,--purple-dark,--reply-bg,--selected-bg,--tab-bg,--orange,--orange-dark,--green,--danger,--warning. Any other key refuses the offer.chat: optional message colors,quoteColor,italicColor,boldColor,textColor, each a hex color.- Contrast:
--foregroundand--muted, where the theme sets them, must reach 3:1 against each of--bg,--bg-alt,--surface,--surface-accent,--surface-2and--reply-bgthe theme sets. A theme whose text disappears into its backgrounds would hide the extension marks too, so it is refused (bad_request).
The Midnight Ink example offers a complete theme.
Testing styles
rinext test records what you pass: chat.style() returns the window style as given, and p6b.themes lists
the themes offered (null for a withdrawal). The sanitizer needs a browser, so a test does not show what it
keeps; preview ui.style CSS in the card editor's Chat style tab. Theme offers are fully checked in tests,
contrast included.