1.0.1: theme performance, full Windows 98/Classic bars, the app menu on each pane's wB, restored windows fit their monitor
This commit is contained in:
parent
12eb3d9bee
commit
7e2515aa42
14 changed files with 104 additions and 32 deletions
|
|
@ -311,7 +311,9 @@ function layerCss(palette: Partial<Palette>): string {
|
|||
* all (checked live, 2026-09-28: `document.body.children` on `x.com/` logged out is plain `<div>`s),
|
||||
* so that tag's absence is how a signed-out page is told apart from X's real app shell.
|
||||
*/
|
||||
const SIGNED_OUT_ROOT = 'body:not(:has(main[role="main"]))';
|
||||
// Signed out: no X app shell. A page flag the engine keeps (THEME_FLAGS), never `body:not(:has(main))`:
|
||||
// a page-level :has() made the browser re-match every element on each node X inserted (1.0.0, all themes).
|
||||
const SIGNED_OUT_ROOT = 'html:not([data-wb-app]) body';
|
||||
function signedOutCss(palette: Partial<Palette> & { page?: string }): string {
|
||||
const bg = palette.bg;
|
||||
const text = palette.text;
|
||||
|
|
@ -353,8 +355,16 @@ function fullPalette(palette: Partial<Palette>): Palette | null {
|
|||
return bg && surface && elevated && border && text && muted && accent ? { ...palette, bg, surface, elevated, border, text, muted, accent } : null;
|
||||
}
|
||||
|
||||
/** Page states the theme's CSS keys on (`html[data-wb-app]`, `html[data-wb-chat]`), kept by the engine. */
|
||||
export const THEME_FLAGS = {
|
||||
/** X's app shell (signed in). */
|
||||
app: 'main[role="main"]',
|
||||
/** X's chat app, in the page or as its embed host. */
|
||||
chat: '[data-testid="dm-container"],[data-testid="xchatEmbedRoute"]',
|
||||
} as const;
|
||||
|
||||
/** Pure: override rules for X's palette-colored rules plus the variable and page-level overrides. */
|
||||
export function buildThemeCss(rules: Iterable<RuleLike>, source: Source, palette: Partial<Palette> & { page?: string }, vars: Record<string, string> = {}): string {
|
||||
export function buildThemeCss(rules: Iterable<RuleLike>, source: Source, palette: Partial<Palette> & { page?: string }, vars: Record<string, string> = {}, options: { signedIn?: boolean } = {}): string {
|
||||
// X's newer rules use `var(--x-white)` and Tailwind's `color-mix()` opacity form: read them as the color they paint.
|
||||
const resolve = (value: string) => resolveDeclared(value, vars);
|
||||
const out: string[] = [];
|
||||
|
|
@ -447,7 +457,9 @@ export function buildThemeCss(rules: Iterable<RuleLike>, source: Source, palette
|
|||
}
|
||||
if (full) out.push(chatSurfaceCss(full));
|
||||
out.push(...badges);
|
||||
if (palette.bg && palette.text) out.push(signedOutCss(palette));
|
||||
// Signed-out pages only: their rules carry :has() (X's sign-in buttons), and any :has() over the page
|
||||
// costs every insertion a full restyle, so a signed-in page (engine flag `app`) never gets them.
|
||||
if (palette.bg && palette.text && !options.signedIn) out.push(signedOutCss(palette));
|
||||
return out.join('\n');
|
||||
}
|
||||
|
||||
|
|
@ -498,11 +510,11 @@ export function resolvedTheme(choice: ThemeChoice, mode: 'light' | 'dim' | 'dark
|
|||
export const pageFonts = (theme: ThemeSpec): ResolvedFonts => resolvedFonts(theme.font, X_FONT_STACK);
|
||||
|
||||
/** Everything a theme adds to X: palette remapping first, then type/shape/layout/canvas/motion. */
|
||||
export function buildFullCss(rules: RuleLike[], choice: ThemeChoice, mode: 'light' | 'dim' | 'dark', vars: Record<string, string> = {}): string {
|
||||
export function buildFullCss(rules: RuleLike[], choice: ThemeChoice, mode: 'light' | 'dim' | 'dark', vars: Record<string, string> = {}, flags: readonly string[] = []): string {
|
||||
const theme = resolveTheme(choice);
|
||||
const palette = paletteFor(choice);
|
||||
const parts: string[] = [];
|
||||
if (palette) parts.push(buildThemeCss(rules, X_PALETTES[mode], { ...palette, page: theme.colors?.page }, vars));
|
||||
if (palette) parts.push(buildThemeCss(rules, X_PALETTES[mode], { ...palette, page: theme.colors?.page }, vars, { signedIn: flags.includes('app') }));
|
||||
if (!isNeutral(theme)) parts.push(buildStructureCss(rules, theme, structureColors(theme, mode)));
|
||||
return parts.join('\n');
|
||||
}
|
||||
|
|
@ -528,6 +540,7 @@ export function installTheme(win: Window, options: ThemeRuntimeOptions = {}): Th
|
|||
siteVars: [...X_PRIMITIVE_VARS, '--x-blue-500'],
|
||||
styleId: 'bt-theme',
|
||||
name: 'wayBetter for X',
|
||||
flags: THEME_FLAGS,
|
||||
// Theme engine v2: components, variants, decoration and icons (themeStructure.ts).
|
||||
// The owner's icon pick travels in the theme choice (persisted natively); `setIcons` only previews one.
|
||||
staticCss: (choice, mode) => buildThemeStructureCss(resolveTheme(choice), resolvedTheme(choice, mode), { ...env, icons: choice.icons ?? env.icons, packs: choice.packs }),
|
||||
|
|
|
|||
|
|
@ -31,8 +31,11 @@ export const X_ICONS: IconTable = {
|
|||
views: { ctx: `${ACT} a[href$="/analytics"] svg`, group: 'actions' },
|
||||
bookmark: { ctx: `${ACT} [data-testid="bookmark"] svg`, group: 'actions' },
|
||||
'bookmark.on': { ctx: `${ACT} [data-testid="removeBookmark"] svg`, group: 'actions' },
|
||||
share: { ctx: `${ACT} > div:last-child [role="button"] svg`, group: 'actions' },
|
||||
media: { ctx: `${TOOLS} [role="button"]:has(+ input[data-testid="fileInput"]) svg,${TOOLS} [data-testid="fileInput"] ~ [role="button"] svg`, group: 'composer' },
|
||||
// X's share button: the action bar's menu button without a test id (repost has one). Not `> div:last-child`:
|
||||
// a structural pseudo-class there made every node appended to a timeline restyle the last post.
|
||||
share: { ctx: `${ACT} [role="button"][aria-haspopup="menu"]:not([data-testid]) svg`, group: 'actions' },
|
||||
// No `[role="button"]:has(+ input)`: that :has() restyled the whole page on every insertion (1.0.0).
|
||||
media: { ctx: `${TOOLS} [data-testid="fileInput"] ~ [role="button"] svg`, group: 'composer' },
|
||||
gif: { ctx: `${TOOLS} [data-testid="gifSearchButton"] svg`, group: 'composer' },
|
||||
poll: { ctx: `${TOOLS} [data-testid="createPollButton"] svg`, group: 'composer' },
|
||||
emoji: { ctx: `${TOOLS} [aria-label="Add emoji"] svg`, group: 'composer' },
|
||||
|
|
|
|||
|
|
@ -11,9 +11,8 @@ import type { VariantSkins } from '../../../../waybetter/packages/runtime/src/th
|
|||
const POST = 'article[data-testid="tweet"]';
|
||||
const COLUMN = '[data-testid="primaryColumn"]';
|
||||
/** The main column on every route but chat (a drawn bar above X's chat app would push its composer out of the window). */
|
||||
/** X's chat app: in the page, or the host of its embed (an open shadow root the page's :has() cannot look into, 2026-10-01). */
|
||||
const CHAT_APP = ':is([data-testid="dm-container"],[data-testid="xchatEmbedRoute"])';
|
||||
const FRAMED = `[data-testid="primaryColumn"]:not(:has(${CHAT_APP}))`;
|
||||
// Keyed on the engine's page flag (THEME_FLAGS in theme.ts), never `:has()` over the page: see SIGNED_OUT_ROOT.
|
||||
const FRAMED = 'html:not([data-wb-chat]) [data-testid="primaryColumn"]';
|
||||
const RAIL = 'header[role="banner"]';
|
||||
const NAV = `${RAIL} nav[role="navigation"]`;
|
||||
const ACTIONS = ['reply', 'retweet', 'unretweet', 'like', 'unlike', 'bookmark', 'removeBookmark'].map(id => `[data-testid="${id}"]`).join(',');
|
||||
|
|
@ -38,7 +37,9 @@ export const X_PARTS: PartMap = {
|
|||
buttonPrimary: { sel: '[data-testid="tweetButtonInline"],[data-testid="tweetButton"],[data-testid="SideNav_NewTweet_Button"]', text: ':is([data-testid="tweetButtonInline"],[data-testid="tweetButton"],[data-testid="SideNav_NewTweet_Button"]) :is(span,div[dir])' },
|
||||
buttonSecondary: { sel: '[data-testid$="-follow"],[data-testid$="-unfollow"]', text: ':is([data-testid$="-follow"],[data-testid$="-unfollow"]) span' },
|
||||
// Live 2026-10-01: the painted box is three levels above the input's label (a div, no <label>).
|
||||
search: { sel: 'form[role="search"] div:has(> div > div > [data-testid="SearchBox_Search_Input_label"])', text: 'form[role="search"] input' },
|
||||
// X's search pill: the form's grandchild (the label sits three levels below it). No :has(): a page-wide
|
||||
// :has() made every node X inserted restyle the whole page (1.0.0).
|
||||
search: { sel: 'form[role="search"] > div > div', text: 'form[role="search"] input' },
|
||||
composer: { sel: '[data-testid="tweetTextarea_0"]', text: '[data-testid="tweetTextarea_0"] :is(span,div)' },
|
||||
composerTool: { sel: '[data-testid="toolBar"] nav [role="button"]', text: '[data-testid="toolBar"] nav [role="button"] svg' },
|
||||
sidebarCard: { sel: '[data-testid="sidebarColumn"] div:has(> :is(aside[role="complementary"],section[role="region"]))' },
|
||||
|
|
@ -79,7 +80,7 @@ export type XSkinContext = {
|
|||
|
||||
/** Only above X's narrow breakpoint, never on chat's own row, never while the pane's rail is parked. */
|
||||
const WIDE = '@media (min-width:700px)';
|
||||
const NOT_CHAT = `html:not(:has(${CHAT_APP}))`;
|
||||
const NOT_CHAT = 'html:not([data-wb-chat])';
|
||||
|
||||
/** How X looks in each layout variant. */
|
||||
export const X_SKINS: VariantSkins<XSkinContext> = {
|
||||
|
|
@ -139,7 +140,11 @@ ${NOT_CHAT} ${RAIL} > div{width:100% !important;height:56px !important}
|
|||
${NOT_CHAT} ${inner}{position:static !important;width:100% !important;height:56px !important;max-width:1280px;margin:0 auto !important}
|
||||
${NOT_CHAT} ${inner} > div{flex-direction:row !important;align-items:center !important;justify-content:space-between !important;height:56px !important;width:100% !important;padding:0 16px !important;overflow:visible !important}
|
||||
${NOT_CHAT} ${inner} > div > div{flex-direction:row !important;align-items:center !important;height:56px !important;gap:4px}
|
||||
/* The same for the groups inside the row (the nav and the Post button sit in full-width wrappers). */
|
||||
${NOT_CHAT} ${inner} > div > div > div{width:auto !important;flex:0 1 auto !important;min-width:0 !important}
|
||||
${NOT_CHAT} ${NAV}{flex-direction:row !important;align-items:center !important;flex-wrap:nowrap !important;gap:2px}
|
||||
/* X sizes each rail item to the rail (width:100%, flex-grow:1): in a row that is one window per item. */
|
||||
${NOT_CHAT} ${NAV} > :is(a,button){width:auto !important;flex:0 1 auto !important;min-width:0 !important}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div{padding:8px 10px !important}
|
||||
${NOT_CHAT} ${RAIL} [data-testid="SideNav_NewTweet_Button"]{margin:0 0 0 8px !important;width:auto !important;min-height:40px !important;padding:0 16px !important}
|
||||
${NOT_CHAT} ${RAIL} [data-testid="SideNav_AccountSwitcher_Button"]{margin:0 !important}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue