wayBetter for X 1.0.2
This commit is contained in:
parent
7e2515aa42
commit
467aea2e28
212 changed files with 10208 additions and 2345 deletions
|
|
@ -294,39 +294,6 @@ export function formatFullCount(value: number, locale?: string): string {
|
|||
|
||||
// -- Runtime: DOM patching + observers (installFeatures) --
|
||||
|
||||
const WORDING_MAP: Record<string, string> = { Post: 'Tweet', Posts: 'Tweets', Repost: 'Retweet', Reposts: 'Retweets' };
|
||||
|
||||
const WORDING_REVERSE: Record<string, string> = Object.fromEntries(Object.entries(WORDING_MAP).map(([x, twitter]) => [twitter, x]));
|
||||
const RETEXT_ATTR = 'data-bt-retext';
|
||||
const TEXT_NODE = 3;
|
||||
|
||||
/** Retexts X's own label text nodes in place. Editing the node (not `span.textContent`, which
|
||||
* swaps in a new node) keeps React owning it, so X's later updates (e.g. the label emptied when the
|
||||
* nav collapses to icon-only) still land instead of leaving a stale "Tweet" behind. */
|
||||
function retextExact(el: Element | null | undefined) {
|
||||
if (!el) return;
|
||||
for (const span of el.querySelectorAll('span')) {
|
||||
for (const node of Array.from(span.childNodes)) {
|
||||
const text = node.nodeType === TEXT_NODE ? node.nodeValue : null;
|
||||
if (text == null || !Object.hasOwn(WORDING_MAP, text)) continue;
|
||||
node.nodeValue = WORDING_MAP[text]!;
|
||||
span.setAttribute(RETEXT_ATTR, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Puts X's own wording back on labels `retextExact` changed. */
|
||||
function restoreText(root: ParentNode | null | undefined) {
|
||||
if (!root) return;
|
||||
for (const span of root.querySelectorAll(`[${RETEXT_ATTR}]`)) {
|
||||
for (const node of Array.from(span.childNodes)) {
|
||||
const text = node.nodeType === TEXT_NODE ? node.nodeValue : null;
|
||||
if (text != null && Object.hasOwn(WORDING_REVERSE, text)) node.nodeValue = WORDING_REVERSE[text]!;
|
||||
}
|
||||
span.removeAttribute(RETEXT_ATTR);
|
||||
}
|
||||
}
|
||||
|
||||
function buildFaviconDataUrl(brush: boolean): string {
|
||||
if (brush) return LOGO_PNG;
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24"><path fill="${THEME_BLUE}" d="${TWITTER_LOGO_PATH}"/></svg>`;
|
||||
|
|
@ -410,19 +377,6 @@ export function installFeatures(target: Window = window): FeatureHandle {
|
|||
} catch { /* degrade silently */ }
|
||||
};
|
||||
|
||||
const patchWording = () => {
|
||||
try {
|
||||
retextExact(doc.querySelector('button[data-testid^="tweetButton"]'));
|
||||
// Compact nav: X renders an icon-only round button (svg + empty label). Leave it as X drew it.
|
||||
const sideNav = doc.querySelector('[data-testid="SideNav_NewTweet_Button"]');
|
||||
if (sideNav?.querySelector('svg')) restoreText(sideNav);
|
||||
else retextExact(sideNav);
|
||||
for (const item of doc.querySelectorAll('[data-testid="retweetConfirm"], [data-testid="repostConfirm"], [data-testid="unretweetConfirm"], [data-testid="unrepostConfirm"]')) {
|
||||
retextExact(item);
|
||||
}
|
||||
} catch { /* degrade silently */ }
|
||||
};
|
||||
|
||||
const patchTitle = () => {
|
||||
if (!config.twitterWording) return;
|
||||
try {
|
||||
|
|
@ -448,10 +402,8 @@ export function installFeatures(target: Window = window): FeatureHandle {
|
|||
syncRoute();
|
||||
patchLogo();
|
||||
if (faviconDirty) { faviconDirty = false; patchFavicon(); }
|
||||
if (config.twitterWording) patchWording();
|
||||
else restoreText(doc);
|
||||
};
|
||||
// Shared body observer + frame (domHub.ts). Route, logo and wording also apply on chat pages.
|
||||
// Shared body observer + frame (domHub.ts). Route and logo also apply on chat pages (the wording is a string pack now; the title suffix stays here).
|
||||
const watch = watchDom(win, runPatches);
|
||||
const schedule = watch.schedule;
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ const OWN = { author: AUTHOR, license: 'own', source: 'drawn for wayBetter for X
|
|||
const documents = [
|
||||
{ id: 'wb-line', name: 'Line', description: 'Thin line icons; stroke and caps follow the theme.', ...OWN, style: { stroke: 1.75, cap: 'round', join: 'round', scale: 1 }, glyphs: LINE },
|
||||
{ id: 'wb-classic', name: 'Classic', description: 'Solid glyphs in the manner of 2012: a star to like, square-loop arrows to repost.', ...OWN, style: { stroke: 1.75, cap: 'round', join: 'round', scale: 0.92 }, glyphs: CLASSIC, symbols: { like: 'star' } },
|
||||
{ id: 'wb-aero', name: 'Aero', description: 'Glossy colored glyphs with a sheen.', ...OWN, style: { stroke: 1.75, cap: 'round', join: 'round', scale: 1 }, glyphs: AERO },
|
||||
{ id: 'wb-aero', name: 'Aero', description: 'Glossy colored glyphs with a vertical sheen, in the manner of 2008.', ...OWN, style: { stroke: 1.75, cap: 'round', join: 'round', scale: 1 }, glyphs: AERO },
|
||||
{ id: 'wb-pixel', name: 'Pixel 98', description: 'Sixteen-pixel icons in the manner of a 1998 desktop. Our own drawings.', ...OWN, style: { stroke: 1.75, cap: 'square', join: 'miter', scale: 1 }, glyphs: PIXEL },
|
||||
];
|
||||
|
||||
|
|
|
|||
400
apps/desktop/src/inject/packs/retro.ts
Normal file
400
apps/desktop/src/inject/packs/retro.ts
Normal file
|
|
@ -0,0 +1,400 @@
|
|||
// Retro icon packs for the wayBetter Store (not bundled in the app: they are installed from the
|
||||
// Store, the same way as any pack). Both are our own drawings; nothing is traced or extracted from
|
||||
// Windows, from X or from any icon archive (the Windows icon archives on the web carry Microsoft's
|
||||
// copyright, and the plan bans them). The look is the idea of the era, drawn from scratch.
|
||||
// retro-98 16 by 16 pixel art on the 98 desktop palette: black outline, silver, navy, teal.
|
||||
// retro-xp vector glyphs in the manner of 2001: gel fills, a dark edge, a lit top.
|
||||
// Both draw every name X's left rail uses (home .. compose, and the .active forms) and the action bar.
|
||||
// Generated into store/x/icons/<id>/ by scripts/build-store-icons.mjs.
|
||||
|
||||
import { sanitizeIconPack, type IconGlyph, type IconName, type IconPack } from '../../../../../waybetter/packages/runtime/src/themeIcons.ts';
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// retro-98: rows of 16 letters, `.` is transparent
|
||||
|
||||
const P98: Record<string, string> = {
|
||||
k: '#000000', w: '#ffffff', s: '#c0c0c0', g: '#808080', n: '#000080', b: '#0000ff', c: '#008080', t: '#00ffff',
|
||||
y: '#ffff00', d: '#808000', r: '#ff0000', m: '#800000', p: '#ff80c0', e: '#00a000', o: '#ff8000', u: '#800080',
|
||||
};
|
||||
|
||||
/** Rows to a glyph of 1.5px squares on the 24px box; same-colored cells are merged into rectangles; the outline is drawn last. */
|
||||
export function rasterGlyph(name: string, rows: readonly string[]): IconGlyph {
|
||||
if (rows.length !== 16) throw new Error(`${name}: ${rows.length} rows, 16 needed`);
|
||||
rows.forEach((row, y) => {
|
||||
if (row.length !== 16) throw new Error(`${name}: row ${y} has ${row.length} cells, 16 needed (${row})`);
|
||||
for (const ch of row) if (ch !== '.' && !P98[ch]) throw new Error(`${name}: row ${y} has an unknown color "${ch}"`);
|
||||
});
|
||||
const taken = rows.map(() => new Array<boolean>(16).fill(false));
|
||||
const byColor = new Map<string, string[]>();
|
||||
const f = (n: number) => +(n * 1.5).toFixed(1);
|
||||
for (let y = 0; y < 16; y++) {
|
||||
for (let x = 0; x < 16; x++) {
|
||||
const key = rows[y]![x]!;
|
||||
if (key === '.' || taken[y]![x]) continue;
|
||||
let w = 1;
|
||||
while (x + w < 16 && rows[y]![x + w] === key && !taken[y]![x + w]) w++;
|
||||
let h = 1;
|
||||
grow: while (y + h < 16) {
|
||||
for (let i = 0; i < w; i++) if (rows[y + h]![x + i] !== key || taken[y + h]![x + i]) break grow;
|
||||
h++;
|
||||
}
|
||||
for (let j = 0; j < h; j++) for (let i = 0; i < w; i++) taken[y + j]![x + i] = true;
|
||||
const list = byColor.get(key) ?? [];
|
||||
list.push(`M${f(x)} ${f(y)}h${f(w)}v${f(h)}h-${f(w)}z`);
|
||||
byColor.set(key, list);
|
||||
}
|
||||
}
|
||||
const keys = [...byColor.keys()].sort((a, b) => (a === 'k' ? 1 : 0) - (b === 'k' ? 1 : 0));
|
||||
if (keys.length > 6) throw new Error(`${name}: ${keys.length} colors, a glyph has 6 layers at most`);
|
||||
return { layers: keys.map(key => ({ d: byColor.get(key)!.join(''), fill: P98[key]! })) };
|
||||
}
|
||||
|
||||
const ART98: Record<string, readonly string[]> = {
|
||||
home: [
|
||||
'................', '.......kk.......', '......krrk......', '.....krrrrk.....', '....krrrrrrk....', '...krrrrrrrrk...', '..krrrrrrrrrrk..', '.kkkkkkkkkkkkkk.',
|
||||
'..kwwwwwwwwwwk..', '..kwbbbwwbbbwk..', '..kwbbbwwbbbwk..', '..kwwwwkkkkwwk..', '..kwwwwkmmkwwk..', '..kwwwwkmmkwwk..', '..kkkkkkkkkkkk..', '................',
|
||||
],
|
||||
search: [
|
||||
'................', '...kkkkkk.......', '..kwwwwwwk......', '.kwwwwwwwwk.....', '.kwtwwwwwwk.....', '.kwtwwwwwwk.....', '.kwwwwwwwwk.....', '.kwwwwwwwwk.....',
|
||||
'..kwwwwwwkk.....', '...kkkkkksgk....', '........kgggk...', '.........kgggk..', '..........kgggk.', '...........kgk..', '............k...', '................',
|
||||
],
|
||||
bell: [
|
||||
'................', '.......kk.......', '......kyyk......', '.....kywyyk.....', '....kywyyyyk....', '....kywyyyyk....', '....kyyyyyyk....', '...kyyyyyyyyk...',
|
||||
'...kyyyyyyyyk...', '..kyyyyyyyyyyk..', '..kddddddddddk..', '..kkkkkkkkkkkk..', '.....kkddkk.....', '......kddk......', '.......kk.......', '................',
|
||||
],
|
||||
mail: [
|
||||
'................', '................', '.kkkkkkkkkkkkkk.', '.kwwwwwwwwwwwwk.', '.kkwwwwwwwwwwkk.', '.kwkwwwwwwwwkwk.', '.kwwkwwwwwwkwwk.', '.kwwwkwwwwkwwwk.',
|
||||
'.kwwwwkwwkwwwwk.', '.kwwwwwkkwwwwwk.', '.kwwwwwwwwwwwwk.', '.kssssssssssssk.', '.kssssssssssssk.', '.kkkkkkkkkkkkkk.', '................', '................',
|
||||
],
|
||||
monitor: [
|
||||
'................', '..kkkkkkkkkkkk..', '..kssssssssssk..', '..ksnnnnnnnnsk..', '..ksnttnnnnnsk..', '..ksnttnnnwnsk..', '..ksnnnnnwwwsk..', '..ksnnnnnnwnsk..',
|
||||
'..ksnnnnnnnnsk..', '..kssssssssssk..', '..kkkkkggkkkkk..', '......kssk......', '....kkssssk.....', '...kssssssssk...', '...kkkkkkkkkk...', '................',
|
||||
],
|
||||
folder: [
|
||||
'................', '................', '..kkkkk.........', '.kyyyyyk........', '.kyyyyyykkkkkkk.', '.kywwwwwwwwwwyk.', '.kywyyyyyyyyyyk.', '.kyyyyyyyyyyyyk.',
|
||||
'.kyyyyyyyyyyyyk.', '.kyyyyyyyyyyyyk.', '.kyyyyyyyyyyyyk.', '.kyyyyyyyyyyyyk.', '.kddddddddddddk.', '.kkkkkkkkkkkkkk.', '................', '................',
|
||||
],
|
||||
notepad: [
|
||||
'................', '..kkkkkkkkkkk...', '..kwwwwwwwwwk...', '..kwkkkkkkkwk...', '..kwwwwwwwwwk...', '..kwkkkkkkkwk...', '..kwwwwwwwwwk...', '..kwkkkkkkwwk...',
|
||||
'..kwwwwwwwwwk...', '..kwkkkkkkkwk...', '..kwwwwwwwwwk...', '..kwkkkkwwwwk...', '..kwwwwwwwwwk...', '..kkkkkkkkkkk...', '................', '................',
|
||||
],
|
||||
people: [
|
||||
'................', '...kkkk..kkkk...', '..kyyyyk.kyyyk..', '..kykkyk.kkyyk..', '..kyyyyk.kyyyk..', '...kkkk..kkkk...', '..kccccck.kuuuk.', '.kcccccccckuuuuk',
|
||||
'.kccccccckkuuuuk', '.kcccccccckuuuuk', '.kkkkkkkkkkkkkkk', '................', '................', '................', '................', '................',
|
||||
],
|
||||
badge: [
|
||||
'................', '.......kk.......', '......kyyk......', '.....kyyyyk.....', '.kkkkkywyykkkk..', '.kyyyyywyyyyyk..', '..kyyyyyyyyyk...', '...kyyyyyyyk....',
|
||||
'...kyyywyyyk....', '..kyyywwwyyyk...', '..kyyywyywyyk...', '.kyyyk..kyyyk...', '.kkkk....kkkk...', '................', '................', '................',
|
||||
],
|
||||
person: [
|
||||
'................', '......kkkk......', '.....kyyyyk.....', '....kyyyyyyk....', '....kykyykyk....', '....kyyyyyyk....', '....kyykkyyk....', '.....kyyyyk.....',
|
||||
'....kkkkkkkk....', '...kcccccccck...', '..kcccccccccck..', '..kcccccccccck..', '..kcccccccccck..', '..kkkkkkkkkkkk..', '................', '................',
|
||||
],
|
||||
// Three white dots in a black frame: the frame reads on the silver desktop, the white on a dark one.
|
||||
dots: [
|
||||
'................', '................', '................', '................', '................', '.kkkk.kkkk.kkkk.', '.kwwk.kwwk.kwwk.', '.kwwk.kwwk.kwwk.',
|
||||
'.kkkk.kkkk.kkkk.', '................', '................', '................', '................', '................', '................', '................',
|
||||
],
|
||||
pencil: [
|
||||
'............kk..', '...........kmmk.', '..........kyymk.', '.........kyyyk..', '........kyyyk...', '.......kyyyk....', '......kyyyk.....', '.....kyyyk......',
|
||||
'....kyyyk.......', '...kdyyk........', '...kddk.........', '..kwwk..........', '..kkkk..........', '................', '................', '................',
|
||||
],
|
||||
balloon: [
|
||||
'................', '..kkkkkkkkkkkk..', '.kwwwwwwwwwwwwk.', '.kwwwwwwwwwwwwk.', '.kwwkkkkkkkkwwk.', '.kwwwwwwwwwwwwk.', '.kwwkkkkkkwwwwk.', '.kwwwwwwwwwwwwk.',
|
||||
'..kkkkwwkkkkkk..', '....kwwk........', '....kwk.........', '....kk..........', '................', '................', '................', '................',
|
||||
],
|
||||
// Off: white arrows like the other outlined actions (X draws repost muted until it is on); on: green.
|
||||
arrows: [
|
||||
'................', '.....k..........', '....kwk.........', '...kwwwkkkkkk...', '..kwwwwwwwwwwk..', '...kwwwkkkkkwk..', '....kwk.....kwk.', '.....k......kwk.',
|
||||
'.kwk......k.....', '.kwk.....kwk....', '.kwkkkkkkwwwk...', '..kwwwwwwwwwwk..', '...kkkkkwwwk....', '.........kwk....', '..........k.....', '................',
|
||||
],
|
||||
arrowsOn: [
|
||||
'................', '.....k..........', '....kek.........', '...keeekkkkkk...', '..keeeeeeeeeek..', '...keeekkkkkek..', '....kek.....kek.', '.....k......kek.',
|
||||
'.kek......k.....', '.kek.....kek....', '.kekkkkkkeeek...', '..keeeeeeeeeek..', '...kkkkkeeek....', '.........kek....', '..........k.....', '................',
|
||||
],
|
||||
heart: [
|
||||
'................', '..kkk.....kkk...', '.kpppk...kpppk..', 'kpwppkkkkpppppk.', 'kpwppppppppppk..', 'kppppppppppppk..', 'kppppppppppppk..', '.kppppppppppk...',
|
||||
'..kppppppppk....', '...kppppppk.....', '....kppppk......', '.....kppk.......', '......kk........', '................', '................', '................',
|
||||
],
|
||||
heartOn: [
|
||||
'................', '..kkk.....kkk...', '.krrrk...krrrk..', 'krwrrrkkkrrrrrk.', 'krwrrrrrrrrrrk..', 'krrrrrrrrrrrrk..', 'krrrrrrrrrrrrk..', '.krrrrrrrrrrk...',
|
||||
'..krrrrrrrrk....', '...krrrrrrk.....', '....krrrrk......', '.....krrk.......', '......kk........', '................', '................', '................',
|
||||
],
|
||||
bars: [
|
||||
'................', '................', '...........kkk..', '...........kbk..', '...........kbk..', '.......kkk.kbk..', '.......kbk.kbk..', '.......kbk.kbk..',
|
||||
'...kkk.kbk.kbk..', '...kbk.kbk.kbk..', '...kbk.kbk.kbk..', '...kbk.kbk.kbk..', '..kkkkkkkkkkkkk.', '................', '................', '................',
|
||||
],
|
||||
share: [
|
||||
'.......kk.......', '......kwwk......', '.....kwwwwk.....', '....kwwwwwwk....', '...kkkwwwwkkk...', '.....kwwwwk.....', '.....kwwwwk.....', '.....kwwwwk.....',
|
||||
'..kk.kkkkkk.kk..', '..ks........sk..', '..ks........sk..', '..kssssssssssk..', '..kkkkkkkkkkkk..', '................', '................', '................',
|
||||
],
|
||||
picture: [
|
||||
'................', '.kkkkkkkkkkkkkk.', '.kttttttttyyttk.', '.kttttttttyyttk.', '.kttttttttttttk.', '.ktttttteettttk.', '.kttttteeeetttk.', '.kttteeeeeeettk.',
|
||||
'.kteeeeeeeeeetk.', '.keeeeddeeeeeek.', '.keeeeeeeeeeeek.', '.kkkkkkkkkkkkkk.', '................', '................', '................', '................',
|
||||
],
|
||||
bookmark: [
|
||||
'................', '...kkkkkkkkkk...', '...kwwwwwwwwk...', '...kwwwwwwwwk...', '...kwwwwwwwwk...', '...kwwwwwwwwk...', '...kwwwwwwwwk...', '...kwwwwwwwwk...',
|
||||
'...kwwwwwwwwk...', '...kwwwwwwwwk...', '...kwwwkkwwwk...', '...kwwkk.kwwk...', '...kwkk...kwk...', '...kkk.....kk...', '................', '................',
|
||||
],
|
||||
bookmarkOn: [
|
||||
'................', '...kkkkkkkkkk...', '...kbbbbbbbbk...', '...kbwbbbbbbk...', '...kbwbbbbbbk...', '...kbbbbbbbbk...', '...kbbbbbbbbk...', '...kbbbbbbbbk...',
|
||||
'...kbbbbbbbbk...', '...kbbbbbbbbk...', '...kbbbkkbbbk...', '...kbbkk.kbbk...', '...kbkk...kbk...', '...kkk.....kk...', '................', '................',
|
||||
],
|
||||
gif: [
|
||||
'................', '................', 'kkkkkkkkkkkkkkkk', 'knnnnnnnnnnnnnnk', 'knnnnnnnnnnnnnnk', 'knnwwwnwwwnwwwnk', 'knnwnnnnwnnwnnnk', 'knnwnnnnwnnwwnnk',
|
||||
'knnwnwnnwnnwnnnk', 'knnwwwnwwwnwnnnk', 'knnnnnnnnnnnnnnk', 'knnnnnnnnnnnnnnk', 'kkkkkkkkkkkkkkkk', '................', '................', '................',
|
||||
],
|
||||
poll: [
|
||||
'................', '................', '.kkkkkkkkkkkkkk.', '.kwwwwwwwwwwwwk.', '.kwkkkkkkkwwwwk.', '.kwkbbbbbkwwwwk.', '.kwkkkkkkkwwwwk.', '.kwkkkkkkkkkkwk.',
|
||||
'.kwkeeeeeeeekwk.', '.kwkkkkkkkkkkwk.', '.kwwwwwwwwwwwwk.', '.kkkkkkkkkkkkkk.', '................', '................', '................', '................',
|
||||
],
|
||||
smile: [
|
||||
'................', '.....kkkkkk.....', '...kkyyyyyykk...', '..kyyyyyyyyyyk..', '..kyykkyykkyyk..', '.kyyykkyykkyyyk.', '.kyyyyyyyyyyyyk.', '.kykyyyyyyyykyk.',
|
||||
'.kyykyyyyyykyyk.', '..kyykkkkkkyyk..', '..kyyyyyyyyyyk..', '...kkyyyyyykk...', '.....kkkkkk.....', '................', '................', '................',
|
||||
],
|
||||
clock: [
|
||||
'................', '.....kkkkkk.....', '...kkwwwwwwkk...', '..kwwwwkwwwwwk..', '..kwwwwkwwwwwk..', '.kwwwwwkwwwwwwk.', '.kwwwwwkwwwwwwk.', '.kwwwwwkkkkwwwk.',
|
||||
'.kwwwwwwwwwwwwk.', '.kwwwwwwwwwwwwk.', '..kwwwwwwwwwwk..', '..kwwwwwwwwwwk..', '...kkwwwwwwkk...', '.....kkkkkk.....', '................', '................',
|
||||
],
|
||||
pin: [
|
||||
'................', '.....kkkkkk.....', '....krrrrrrk....', '...krrwrrrrrrk..', '...krwwrrrrrrk..', '...krrrrkkrrrk..', '...krrrrkkrrrk..', '....krrrrrrrk...',
|
||||
'.....krrrrrk....', '......krrrk.....', '.......krk......', '........k.......', '................', '................', '................', '................',
|
||||
],
|
||||
lock: [
|
||||
'................', '.....kkkkkk.....', '....kgwwwwgk....', '....kw....wk....', '....kw....wk....', '....kw....wk....', '..kkkkkkkkkkkk..', '..kyyyyyyyyyyk..',
|
||||
'..kywwwwwwwwdk..', '..kyyyykkyyyyk..', '..kyyyykkyyyyk..', '..kyyyyyyyyyyk..', '..kddddddddddk..', '..kkkkkkkkkkkk..', '................', '................',
|
||||
],
|
||||
check: [
|
||||
'................', '.....kkkkkk.....', '...kkbbbbbbkk...', '..kbbbbbbbbbbk..', '.kbbbbbbbbbwwbk.', '.kbbbbbbbbwwbbk.', '.kbwwbbbbwwbbbk.', '.kbbwwbbwwbbbbk.',
|
||||
'.kbbbwwwwbbbbbk.', '..kbbbbwwbbbbk..', '..kbbbbbbbbbbk..', '...kkbbbbbbkk...', '.....kkkkkk.....', '................', '................', '................',
|
||||
],
|
||||
back: [
|
||||
'................', '................', '.......k........', '......kk........', '.....kgk........', '....kgwwkkkkkkk.', '...kgwwwwwwwwwk.', '..kgwwwwwwwwwwk.',
|
||||
'...kgwwwwwwwwk..', '....kgwwkkkkkk..', '.....kgk........', '......kk........', '.......k........', '................', '................', '................',
|
||||
],
|
||||
// A bright red cross in a black frame (the dark red of the first draft vanished on dark grounds).
|
||||
close: [
|
||||
'................', '................', '..kk........kk..', '..krk......krk..', '...krk....krk...', '....krk..krk....', '.....krkkrk.....', '......krrk......',
|
||||
'.....krkkrk.....', '....krk..krk....', '...krk....krk...', '..krk......krk..', '..kk........kk..', '................', '................', '................',
|
||||
],
|
||||
gear: [
|
||||
'................', '......kkkk......', '...kk.kssk.kk...', '..ksskksskksk...', '...kssssssssk...', '..kksskkkksskk..', '.kssskkwwkksssk.', '.kssskwwwwksssk.',
|
||||
'.kssskwwwwksssk.', '..kksskkkksskk..', '...kssssssssk...', '..ksskksskksk...', '...kk.kssk.kk...', '......kkkk......', '................', '................',
|
||||
],
|
||||
};
|
||||
// Anything a hand-typed row got wrong is reported by rasterGlyph with the icon's name and the row.
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// retro-xp: vector gel, 24 by 24
|
||||
|
||||
const n2 = (n: number) => +n.toFixed(2);
|
||||
const circ = (cx: number, cy: number, r: number) => `M${n2(cx - r)} ${n2(cy)}a${n2(r)} ${n2(r)} 0 1 0 ${n2(2 * r)} 0a${n2(r)} ${n2(r)} 0 1 0 ${n2(-2 * r)} 0z`;
|
||||
const ell = (cx: number, cy: number, rx: number, ry: number) => `M${n2(cx - rx)} ${n2(cy)}a${n2(rx)} ${n2(ry)} 0 1 0 ${n2(2 * rx)} 0a${n2(rx)} ${n2(ry)} 0 1 0 ${n2(-2 * rx)} 0z`;
|
||||
const rr = (x: number, y: number, w: number, h: number, r: number) =>
|
||||
`M${n2(x + r)} ${n2(y)}h${n2(w - 2 * r)}a${n2(r)} ${n2(r)} 0 0 1 ${n2(r)} ${n2(r)}v${n2(h - 2 * r)}a${n2(r)} ${n2(r)} 0 0 1 ${n2(-r)} ${n2(r)}h${n2(-(w - 2 * r))}a${n2(r)} ${n2(r)} 0 0 1 ${n2(-r)} ${n2(-r)}v${n2(-(h - 2 * r))}a${n2(r)} ${n2(r)} 0 0 1 ${n2(r)} ${n2(-r)}z`;
|
||||
const poly = (...pts: Array<[number, number]>) => `M${pts.map(([x, y]) => `${n2(x)} ${n2(y)}`).join('L')}z`;
|
||||
/** A straight bar of width `w` from one point to another. */
|
||||
const bar = (x1: number, y1: number, x2: number, y2: number, w: number) => {
|
||||
const dx = x2 - x1, dy = y2 - y1, len = Math.hypot(dx, dy) || 1;
|
||||
const px = (-dy / len) * (w / 2), py = (dx / len) * (w / 2);
|
||||
return poly([x1 + px, y1 + py], [x2 + px, y2 + py], [x2 - px, y2 - py], [x1 - px, y1 - py]);
|
||||
};
|
||||
const star = (cx: number, cy: number, R: number, r: number, points = 5) => poly(...Array.from({ length: points * 2 }, (_, i): [number, number] => {
|
||||
const angle = -Math.PI / 2 + (i * Math.PI) / points, radius = i % 2 ? r : R;
|
||||
return [cx + radius * Math.cos(angle), cy + radius * Math.sin(angle)];
|
||||
}));
|
||||
type Layer = { d: string; fill: string | { from: string; to: string }; opacity?: number };
|
||||
const flat = (d: string, fill: string): Layer => ({ d, fill });
|
||||
const gel = (d: string, from: string, to: string): Layer => ({ d, fill: { from, to } });
|
||||
const sheen = (d: string, opacity = 0.42): Layer => ({ d, fill: { from: '#ffffff', to: '#ffffff' }, opacity });
|
||||
const glyph = (...layers: Layer[]): IconGlyph => {
|
||||
if (layers.length > 6) throw new Error(`a glyph has 6 layers at most (${layers.length})`);
|
||||
return { layers };
|
||||
};
|
||||
|
||||
const EDGE = { blue: '#143c8c', red: '#7a1a10', green: '#17591f', gold: '#7a5410', gray: '#3b4256', brown: '#5a3410' };
|
||||
const BLUE: [string, string] = ['#8fc0ff', '#2563d6'];
|
||||
const RED: [string, string] = ['#ff9a80', '#d2301a'];
|
||||
const GREEN: [string, string] = ['#a6ec8a', '#2f9e2b'];
|
||||
const GOLD: [string, string] = ['#ffe9a0', '#eaa21a'];
|
||||
const PAPER: [string, string] = ['#ffffff', '#dfe8f6'];
|
||||
|
||||
const XP: Record<string, IconGlyph> = {
|
||||
home: glyph(
|
||||
flat(rr(3.4, 10.4, 17.2, 11.6, 1.2), '#6a5a2a'), gel(rr(4.4, 11.4, 15.2, 9.6, 0.6), '#fff9dc', '#e8d28c'),
|
||||
flat(poly([12, 1.6], [23.4, 12.4], [0.6, 12.4]), EDGE.red), gel(poly([12, 4.2], [20.6, 11.2], [3.4, 11.2]), ...RED),
|
||||
gel(rr(9.8, 14.4, 4.4, 6.6, 0.8), '#6fa8ff', '#1c4fb8'), sheen(poly([12, 4.6], [16.4, 8.2], [7.6, 8.2]), 0.3),
|
||||
),
|
||||
explore: glyph(
|
||||
flat(bar(15.2, 15.2, 21.4, 21.4, 4.6), EDGE.brown), gel(bar(15.2, 15.2, 21.2, 21.2, 3), '#f6bd5a', '#b8651a'),
|
||||
flat(circ(10, 10, 8), EDGE.blue), gel(circ(10, 10, 6.9), ...BLUE), gel(circ(10, 10, 4.9), '#f2f9ff', '#a8cfff'), sheen(ell(8.5, 7.4, 3.1, 1.8), 0.7),
|
||||
),
|
||||
bell: glyph(
|
||||
flat('M12 1.8a1.6 1.6 0 0 1 1.6 1.6v.5a6.4 6.4 0 0 1 4.4 6.1v4.7l2.2 3.6H3.8L6 14.7V10a6.4 6.4 0 0 1 4.4-6.1v-.5A1.6 1.6 0 0 1 12 1.8z', EDGE.gold),
|
||||
gel('M12 3.2a.6.6 0 0 1 .6.6v1.1a5.2 5.2 0 0 1 4.2 5.1v4.9l1.7 2.9H5.5l1.7-2.9V10a5.2 5.2 0 0 1 4.2-5.1V3.8a.6.6 0 0 1 .6-.6z', ...GOLD),
|
||||
flat(circ(12, 20.4, 2.2), EDGE.gold), gel(circ(12, 20.4, 1.3), '#ffe28a', '#d58b10'), sheen(ell(9.6, 9, 1.6, 3.2), 0.55),
|
||||
),
|
||||
messages: glyph(
|
||||
flat(rr(1.6, 4.6, 20.8, 14.8, 1.8), EDGE.blue), gel(rr(2.6, 5.6, 18.8, 12.8, 1), ...PAPER),
|
||||
flat(poly([3, 6.6], [12, 13.6], [21, 6.6], [21, 8.4], [12, 15.4], [3, 8.4]), '#2a62d4'), sheen(poly([3.2, 6], [12, 11.8], [20.8, 6]), 0.4),
|
||||
),
|
||||
grok: glyph(
|
||||
flat(circ(12, 12, 10.4), '#10162e'), gel(circ(12, 12, 9.4), '#6a78a8', '#141a3a'), flat(bar(6.4, 17.6, 17.6, 6.4, 2.2), '#ffffff'),
|
||||
flat(poly([11, 5.6], [18.4, 5.6], [18.4, 13]), '#ffffff'), sheen(ell(9.6, 6.6, 4.4, 2.4), 0.3),
|
||||
),
|
||||
folder: glyph(
|
||||
flat('M2.2 5.4A1.6 1.6 0 0 1 3.8 3.8h5.4l2 2.2h9A1.6 1.6 0 0 1 21.8 7.6v11.2a1.6 1.6 0 0 1-1.6 1.6H3.8a1.6 1.6 0 0 1-1.6-1.6z', EDGE.gold),
|
||||
gel('M3.2 5.6a.8.8 0 0 1 .8-.8h4.8l2 2.2h9a.8.8 0 0 1 .8.8v10.8a.8.8 0 0 1-.8.8H4a.8.8 0 0 1-.8-.8z', '#fff1b0', '#f0b72a'),
|
||||
gel(rr(3.2, 9.2, 17.6, 10, 0.8), '#ffe27a', '#e69a12'), sheen(rr(4, 9.8, 16, 3.2, 0.6), 0.45),
|
||||
),
|
||||
lists: glyph(
|
||||
flat(rr(4.2, 1.8, 15.6, 20.4, 1.4), EDGE.gray), gel(rr(5.2, 2.8, 13.6, 18.4, 0.7), ...PAPER),
|
||||
flat(rr(7.4, 6.2, 9.2, 1.6, 0.8), '#2a62d4'), flat(rr(7.4, 10.2, 9.2, 1.6, 0.8), '#2a62d4'), flat(rr(7.4, 14.2, 9.2, 1.6, 0.8), '#2a62d4'), flat(rr(7.4, 17.8, 5.4, 1.4, 0.7), '#2a62d4'),
|
||||
),
|
||||
people: glyph(
|
||||
flat(circ(8, 7.6, 4.2), EDGE.blue), gel(circ(8, 7.6, 3.2), '#ffe2c0', '#e8a86c'), flat('M1.2 21a6.8 6.8 0 0 1 13.6 0z', EDGE.blue), gel('M2.4 20.2a5.6 5.6 0 0 1 11.2 0z', ...BLUE),
|
||||
flat(circ(17, 8.4, 3.6), EDGE.red), gel('M12.2 21a4.8 4.8 0 0 1 9.6 0z', ...RED),
|
||||
),
|
||||
star: glyph(
|
||||
flat(star(12, 12.6, 11, 4.9), EDGE.gold), gel(star(12, 12.8, 9.6, 4.1), ...GOLD), sheen(poly([12, 4.2], [14, 9.4], [12, 10.4], [10, 9.4]), 0.55),
|
||||
),
|
||||
person: glyph(
|
||||
flat(circ(12, 7, 5.4), EDGE.blue), gel(circ(12, 7, 4.4), '#ffe2c0', '#e8a86c'), flat('M2.6 22a9.4 9.4 0 0 1 18.8 0z', EDGE.blue), gel('M3.8 21a8.2 8.2 0 0 1 16.4 0z', ...BLUE),
|
||||
sheen(ell(10.4, 5.4, 2.2, 1.4), 0.7),
|
||||
),
|
||||
more: glyph(
|
||||
flat(rr(1.4, 7.6, 21.2, 8.8, 4.4), EDGE.blue), gel(rr(2.4, 8.6, 19.2, 6.8, 3.4), ...BLUE), flat(circ(7, 12, 1.5), '#ffffff'), flat(circ(12, 12, 1.5), '#ffffff'), flat(circ(17, 12, 1.5), '#ffffff'),
|
||||
sheen(rr(3.4, 9, 17.2, 2.8, 1.4), 0.4),
|
||||
),
|
||||
compose: glyph(
|
||||
flat(rr(2.4, 3.6, 15.6, 18, 1.4), EDGE.gray), gel(rr(3.4, 4.6, 13.6, 16, 0.7), ...PAPER),
|
||||
flat(bar(11.4, 16.4, 20.6, 4.4, 4.2), EDGE.gold), gel(bar(11.6, 16, 20.2, 4.8, 2.6), '#ffe27a', '#e69a12'),
|
||||
flat(poly([9.8, 20.4], [10.6, 15.6], [14, 17.6]), '#3b4256'), flat(poly([19.2, 3.4], [21.6, 2.2], [22.2, 5.4]), '#e0472b'),
|
||||
),
|
||||
reply: glyph(
|
||||
flat('M3 3.4h18a1.6 1.6 0 0 1 1.6 1.6v10.2a1.6 1.6 0 0 1-1.6 1.6H12.4L7 21.6v-4.8H3A1.6 1.6 0 0 1 1.4 15.2V5A1.6 1.6 0 0 1 3 3.4z', EDGE.blue),
|
||||
gel('M3.2 4.6h17.6a.6.6 0 0 1 .6.6v9.8a.6.6 0 0 1-.6.6h-9L8.2 19v-3.4H3.2a.6.6 0 0 1-.6-.6V5.2a.6.6 0 0 1 .6-.6z', '#c4e0ff', '#4c8fe8'), sheen(rr(3.6, 5.2, 16.8, 4, 0.6), 0.5),
|
||||
),
|
||||
// Off: brushed-steel arrows (X shows repost muted until it is on); on: the green gel.
|
||||
repost: glyph(
|
||||
flat('M3 11V9a3 3 0 0 1 3-3h8V2.6l6.4 5.2-6.4 5.2V9.6H7v1.4z', EDGE.gray), gel('M4.2 10.2V9.2a2.2 2.2 0 0 1 2.2-2.2h8.8V4.8l4.2 3.4-4.2 3.4V9.4H7z', '#f2f5fa', '#9aa4b8'),
|
||||
flat('M21 13v2a3 3 0 0 1-3 3h-8v3.4L3.6 16.2 10 11v3.4h7v-1.4z', EDGE.gray), gel('M19.8 13.8v1a2.2 2.2 0 0 1-2.2 2.2H8.8v2.2l-4.2-3.4 4.2-3.4v2h8z', '#f2f5fa', '#9aa4b8'),
|
||||
),
|
||||
repostOn: glyph(
|
||||
flat('M3 11V9a3 3 0 0 1 3-3h8V2.6l6.4 5.2-6.4 5.2V9.6H7v1.4z', EDGE.green), gel('M4.2 10.2V9.2a2.2 2.2 0 0 1 2.2-2.2h8.8V4.8l4.2 3.4-4.2 3.4V9.4H7z', '#d6ffb8', '#38b52a'),
|
||||
flat('M21 13v2a3 3 0 0 1-3 3h-8v3.4L3.6 16.2 10 11v3.4h7v-1.4z', EDGE.green), gel('M19.8 13.8v1a2.2 2.2 0 0 1-2.2 2.2H8.8v2.2l-4.2-3.4 4.2-3.4v2h8z', '#d6ffb8', '#38b52a'),
|
||||
sheen(rr(6, 7.2, 8, 1.2, 0.6), 0.6),
|
||||
),
|
||||
heart: glyph(
|
||||
flat('M12 22.4L2.4 12.8A6 6 0 0 1 12 5.4a6 6 0 0 1 9.6 7.4z', '#8a5568'), gel('M12 20.8L3.8 12.6A4.6 4.6 0 0 1 12 6.9a4.6 4.6 0 0 1 8.2 5.7z', '#fff0f6', '#f0a6c4'), sheen(ell(8, 9.4, 2.6, 1.5), 0.7),
|
||||
),
|
||||
heartOn: glyph(
|
||||
flat('M12 22.4L2.4 12.8A6 6 0 0 1 12 5.4a6 6 0 0 1 9.6 7.4z', '#7a0f2c'), gel('M12 20.8L3.8 12.6A4.6 4.6 0 0 1 12 6.9a4.6 4.6 0 0 1 8.2 5.7z', '#ff8fb0', '#d4123f'), sheen(ell(8, 9.4, 2.6, 1.5), 0.6),
|
||||
),
|
||||
views: glyph(
|
||||
flat(rr(2.2, 13, 5.2, 8.8, 1), EDGE.blue), gel(rr(3, 13.8, 3.6, 7.2, 0.5), ...BLUE),
|
||||
flat(rr(9.4, 4.6, 5.2, 17.2, 1), EDGE.green), gel(rr(10.2, 5.4, 3.6, 15.6, 0.5), ...GREEN),
|
||||
flat(rr(16.6, 9, 5.2, 12.8, 1), EDGE.red), gel(rr(17.4, 9.8, 3.6, 11.2, 0.5), ...RED),
|
||||
),
|
||||
share: glyph(
|
||||
flat(poly([12, 1.6], [19, 8.8], [14.4, 8.8], [14.4, 15.4], [9.6, 15.4], [9.6, 8.8], [5, 8.8]), EDGE.green), gel(poly([12, 3.8], [16.4, 8], [13.2, 8], [13.2, 14.2], [10.8, 14.2], [10.8, 8], [7.6, 8]), ...GREEN),
|
||||
flat(rr(2.6, 13.4, 18.8, 8.2, 1.4), EDGE.gray), gel(rr(3.6, 14.4, 16.8, 6.2, 0.8), '#f4f7fc', '#b8c6e0'),
|
||||
),
|
||||
bookmark: glyph(
|
||||
flat('M6 2h12a1.4 1.4 0 0 1 1.4 1.4V22.2L12 16.8 4.6 22.2V3.4A1.4 1.4 0 0 1 6 2z', EDGE.blue), gel('M6.2 3.2h11.6v15.8L12 14.8 6.2 19z', '#e8f2ff', '#8ab6f4'), sheen(rr(6.6, 3.6, 10.8, 3.4, 0.5), 0.5),
|
||||
),
|
||||
bookmarkOn: glyph(
|
||||
flat('M6 2h12a1.4 1.4 0 0 1 1.4 1.4V22.2L12 16.8 4.6 22.2V3.4A1.4 1.4 0 0 1 6 2z', EDGE.blue), gel('M6.2 3.2h11.6v15.8L12 14.8 6.2 19z', '#8fc0ff', '#1f55c4'), sheen(rr(6.6, 3.6, 10.8, 3.4, 0.5), 0.45),
|
||||
),
|
||||
back: glyph(
|
||||
flat(circ(12, 12, 10.6), '#0f4a12'), gel(circ(12, 12, 9.6), '#a6ec8a', '#2b9a28'), flat(poly([5.6, 12], [11.6, 6.2], [11.6, 9.6], [18.4, 9.6], [18.4, 14.4], [11.6, 14.4], [11.6, 17.8]), '#ffffff'), sheen(ell(12, 6.6, 7, 3.4), 0.4),
|
||||
),
|
||||
close: glyph(
|
||||
flat(rr(2, 2, 20, 20, 3.4), '#ffffff'), gel(rr(3, 3, 18, 18, 2.6), '#f6a58f', '#d2301a'), flat(bar(7.6, 7.6, 16.4, 16.4, 2.6), '#ffffff'), flat(bar(16.4, 7.6, 7.6, 16.4, 2.6), '#ffffff'), sheen(rr(3.8, 3.8, 16.4, 6.4, 1.8), 0.35),
|
||||
),
|
||||
media: glyph(
|
||||
flat(rr(1.6, 3.6, 20.8, 16.8, 1.6), EDGE.gray), gel(rr(2.6, 4.6, 18.8, 14.8, 0.8), '#b8e0ff', '#5aa8f0'),
|
||||
flat('M2.6 19.4V15l5.6-5 5.2 4.4 3-2.4 4.8 4.4v3z', '#2f8a2a'), flat(circ(16.6, 8.6, 2), '#ffd84a'), sheen(rr(3.2, 5.2, 17.6, 4, 0.6), 0.3),
|
||||
),
|
||||
gif: glyph(
|
||||
flat(rr(1.6, 5, 20.8, 14, 2.4), EDGE.blue), gel(rr(2.6, 6, 18.8, 12, 1.6), '#8fc0ff', '#2563d6'),
|
||||
// "GIF" in block letters, legible at 16px (G: top, side, foot, the hook in; I; F: stem, top, bar).
|
||||
flat([rr(4.6, 8.4, 4.8, 1.6, 0.3), rr(4.6, 8.4, 1.6, 7.2, 0.3), rr(4.6, 14, 4.8, 1.6, 0.3), rr(7.8, 11.6, 1.6, 4, 0.3), rr(7, 11.6, 2.4, 1.4, 0.3),
|
||||
rr(11.2, 8.4, 1.6, 7.2, 0.3), rr(14.4, 8.4, 1.6, 7.2, 0.3), rr(14.4, 8.4, 5, 1.6, 0.3), rr(14.4, 11.4, 3.8, 1.4, 0.3)].join(''), '#ffffff'),
|
||||
sheen(rr(3, 6.4, 18, 4, 1.2), 0.3),
|
||||
),
|
||||
poll: glyph(
|
||||
flat(rr(2, 2.6, 20, 18.8, 1.6), EDGE.gray), gel(rr(3, 3.6, 18, 16.8, 0.8), ...PAPER),
|
||||
flat(rr(5, 6.2, 12, 2.4, 1.2), '#2563d6'), flat(rr(5, 10.8, 8, 2.4, 1.2), '#2f9e2b'), flat(rr(5, 15.4, 5, 2.4, 1.2), '#d2301a'),
|
||||
),
|
||||
smile: glyph(
|
||||
flat(circ(12, 12, 10.6), '#7a5410'), gel(circ(12, 12, 9.6), '#fff3a0', '#f2b81a'), flat(ell(8.6, 9.6, 1.2, 1.8), '#3a2a08'), flat(ell(15.4, 9.6, 1.2, 1.8), '#3a2a08'),
|
||||
flat('M6.4 14a6.4 6.4 0 0 0 11.2 0z', '#3a2a08'), sheen(ell(10.4, 6, 5, 2.6), 0.55),
|
||||
),
|
||||
clock: glyph(
|
||||
flat(circ(12, 12, 10.6), EDGE.blue), gel(circ(12, 12, 9.4), '#ffffff', '#cfdcf4'), flat(bar(12, 12, 12, 5.4, 1.8), '#143c8c'), flat(bar(12, 12, 16.6, 14.8, 1.8), '#143c8c'), flat(circ(12, 12, 1.4), '#d2301a'),
|
||||
sheen(ell(10.4, 6, 5, 2.2), 0.5),
|
||||
),
|
||||
pin: glyph(
|
||||
flat('M12 22.6C8 17.6 4.8 14 4.8 9.8a7.2 7.2 0 0 1 14.4 0c0 4.2-3.2 7.8-7.2 12.8z', EDGE.red), gel('M12 20.6C9 16.8 6.2 13.6 6.2 9.8a5.8 5.8 0 0 1 11.6 0c0 3.8-2.8 7-5.8 10.8z', ...RED),
|
||||
flat(circ(12, 9.8, 2.4), '#ffffff'), sheen(ell(9.6, 6.6, 2, 1.8), 0.6),
|
||||
),
|
||||
lock: glyph(
|
||||
flat('M7 10.4V7.6a5 5 0 0 1 10 0v2.8h-2.4V7.6a2.6 2.6 0 0 0-5.2 0v2.8z', '#4a4f5c'),
|
||||
flat(rr(3.6, 10, 16.8, 12, 2), EDGE.gold), gel(rr(4.6, 11, 14.8, 10, 1.2), ...GOLD), flat(circ(12, 15.2, 1.8), '#5a3a08'), flat(rr(11.2, 15.4, 1.6, 3.6, 0.8), '#5a3a08'), sheen(rr(5, 11.4, 14, 3.4, 1), 0.45),
|
||||
),
|
||||
verified: glyph(
|
||||
flat(star(12, 12, 11.4, 9.4, 9), '#10408f'), gel(circ(12, 12, 8.6), '#8fc4ff', '#1f6fe0'), flat('M7.4 12.2l3.2 3.2 6-6.6-1.6-1.5-4.4 4.9-1.6-1.6z', '#ffffff'), sheen(ell(10.4, 7.4, 4.4, 2.2), 0.45),
|
||||
),
|
||||
gear: glyph(
|
||||
flat(star(12, 12, 11.4, 9, 8), EDGE.gray), gel(circ(12, 12, 8.6), '#f4f7fc', '#a6b4cf'), flat(circ(12, 12, 3.6), EDGE.gray), gel(circ(12, 12, 2.6), '#ffffff', '#c8d4ea'),
|
||||
),
|
||||
};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
|
||||
type Names = Partial<Record<IconName, IconGlyph>>;
|
||||
const px = (key: keyof typeof ART98) => rasterGlyph(key, ART98[key]!);
|
||||
const G98: Names = {
|
||||
home: px('home'), 'home.active': px('home'), explore: px('search'), 'explore.active': px('search'), notifications: px('bell'), 'notifications.active': px('bell'),
|
||||
messages: px('mail'), 'messages.active': px('mail'), grok: px('monitor'), bookmarks: px('folder'), 'bookmarks.active': px('folder'), lists: px('notepad'), communities: px('people'),
|
||||
premium: px('badge'), profile: px('person'), 'profile.active': px('person'), more: px('dots'), compose: px('pencil'),
|
||||
reply: px('balloon'), repost: px('arrows'), 'repost.on': px('arrowsOn'), like: px('heart'), 'like.on': px('heartOn'), views: px('bars'),
|
||||
bookmark: px('bookmark'), 'bookmark.on': px('bookmarkOn'), share: px('share'), verified: px('check'), back: px('back'), close: px('close'), search: px('search'), settings: px('gear'),
|
||||
media: px('picture'), gif: px('gif'), poll: px('poll'), emoji: px('smile'), schedule: px('clock'), location: px('pin'), lock: px('lock'),
|
||||
};
|
||||
const GXP: Names = {
|
||||
home: XP.home!, 'home.active': XP.home!, explore: XP.explore!, 'explore.active': XP.explore!, notifications: XP.bell!, 'notifications.active': XP.bell!,
|
||||
messages: XP.messages!, 'messages.active': XP.messages!, grok: XP.grok!, bookmarks: XP.folder!, 'bookmarks.active': XP.folder!, lists: XP.lists!, communities: XP.people!,
|
||||
premium: XP.star!, profile: XP.person!, 'profile.active': XP.person!, more: XP.more!, compose: XP.compose!,
|
||||
reply: XP.reply!, repost: XP.repost!, 'repost.on': XP.repostOn!, like: XP.heart!, 'like.on': XP.heartOn!, views: XP.views!,
|
||||
bookmark: XP.bookmark!, 'bookmark.on': XP.bookmarkOn!, share: XP.share!, verified: XP.verified!, back: XP.back!, close: XP.close!, search: XP.explore!, settings: XP.gear!,
|
||||
media: XP.media!, gif: XP.gif!, poll: XP.poll!, emoji: XP.smile!, schedule: XP.clock!, location: XP.pin!, lock: XP.lock!,
|
||||
};
|
||||
|
||||
const OWN = { author: 'wayBetter for X', license: 'own', source: 'drawn for wayBetter for X; no asset is taken from Windows or from any icon archive', credits: 'wayBetter for X contributors' };
|
||||
const documents = [
|
||||
{
|
||||
id: 'retro-98', name: 'Retro 98', description: 'Sixteen-pixel desktop icons in the sixteen-color palette of 1998: black outlines, silver, navy and teal. Every icon of the left navigation and the action bar.',
|
||||
...OWN, style: { stroke: 1.75, cap: 'square', join: 'miter', scale: 1 }, glyphs: G98,
|
||||
},
|
||||
{
|
||||
id: 'retro-xp', name: 'Retro XP', description: 'Glossy gel icons in the manner of 2001: a dark edge, a lit top, bright blue, green and gold. Every icon of the left navigation and the action bar.',
|
||||
...OWN, style: { stroke: 1.75, cap: 'round', join: 'round', scale: 1 }, glyphs: GXP,
|
||||
},
|
||||
];
|
||||
|
||||
/** The retro packs, validated like any imported pack. */
|
||||
export const RETRO_PACKS: IconPack[] = documents.map(doc => {
|
||||
const pack = sanitizeIconPack(doc);
|
||||
if (!pack) throw new Error(`retro icon pack ${doc.id} is not valid`);
|
||||
const wanted = Object.keys(doc.glyphs).length;
|
||||
if (Object.keys(pack.glyphs).length !== wanted) throw new Error(`retro icon pack ${doc.id}: ${wanted - Object.keys(pack.glyphs).length} glyph(s) were refused by the sanitizer`);
|
||||
return pack;
|
||||
});
|
||||
|
||||
/** A retro pack as the JSON document it is published as (`<id>.icons.json`). */
|
||||
export const retroDocument = (id: string) => {
|
||||
const pack = RETRO_PACKS.find(item => item.id === id);
|
||||
return pack ? { $schema: 'https://unpkg.com/waybetter/icons.schema.json', ...pack } : null;
|
||||
};
|
||||
|
|
@ -21,11 +21,21 @@ import {
|
|||
installStringPacks, mapChunkRequires, watchChunkArray, type CatalogHookAdapter, type CatalogReport, type CatalogSink, type StringPacksHandle,
|
||||
} from '../../../../waybetter/packages/runtime/src/stringPackHook.ts';
|
||||
import { inventoryLookup, isPageInventory, type PageInventory } from '../../../../waybetter/packages/runtime/src/stringPacks.ts';
|
||||
import { createMarker, installTranslateUi, withDraft } from '../../../../waybetter/packages/runtime/src/stringPackTranslate.ts';
|
||||
import { createMarker, installTranslateUi, withDraft, type TranslateWords } from '../../../../waybetter/packages/runtime/src/stringPackTranslate.ts';
|
||||
import { t } from './i18n.ts';
|
||||
import { richText } from './xRichText.ts';
|
||||
|
||||
export const X_SITE_ID = 'x';
|
||||
export const X_WEB_CATALOG = 'web';
|
||||
export const X_CHUNK_ARRAY = 'webpackChunk_twitter_responsive_web';
|
||||
/** Translate mode's words in the owner's language (`x.translate.*`), read each time the bar or the editor is drawn. */
|
||||
export const translateWords = (): TranslateWords => ({
|
||||
bar: t('x.translate.bar'), hint: t('x.translate.hint'), edits: count => t('x.translate.edits', { count }), exportPack: t('x.translate.exportPack'),
|
||||
copied: t('x.translate.copied'), exit: t('x.translate.exit'), reload: t('x.translate.reload'), key: t('x.translate.key'), original: t('x.translate.original'),
|
||||
parameters: t('x.translate.parameters'), plural: t('x.translate.plural'), save: t('x.translate.save'), cancel: t('x.translate.cancel'),
|
||||
remove: t('x.translate.remove'), notTranslatable: t('x.translate.notTranslatable'), choose: t('x.translate.choose'),
|
||||
});
|
||||
|
||||
export const X_PACKS_KEY = 'wayBetter.stringPacks';
|
||||
|
||||
/**
|
||||
|
|
@ -48,7 +58,7 @@ type Registry = { _register: (this: unknown, language: string, ...rest: unknown[
|
|||
const isRegistry = (value: unknown): value is Registry => typeof value === 'object' && value !== null && typeof (value as Registry)._register === 'function';
|
||||
|
||||
/** A shadow of X's registry: the same object to read from, with a `_register` that asks `sink`. */
|
||||
function shadowRegistry(registry: Registry, sink: CatalogSink, group: string): unknown {
|
||||
function shadowRegistry(registry: Registry, sink: CatalogSink, group: string, rich: ReturnType<typeof richText>): unknown {
|
||||
const shadow = Object.create(registry) as Registry;
|
||||
Object.defineProperty(shadow, '_register', {
|
||||
value(this: unknown, ...args: [string, ...unknown[]]) {
|
||||
|
|
@ -56,7 +66,9 @@ function shadowRegistry(registry: Registry, sink: CatalogSink, group: string): u
|
|||
if (typeof set !== 'function') return set;
|
||||
sink.matched(String(args[0]), group);
|
||||
return function (this: unknown, id: unknown, value: unknown, ...rest: unknown[]) {
|
||||
return (set as (...a: unknown[]) => unknown).call(this, id, typeof id === 'string' ? sink.resolve(id, value) : value, ...rest);
|
||||
// X's rich-text class and element are registered through the same setter (xRichText.ts).
|
||||
const richEntry = typeof id === 'string' ? rich.intercept(id, value) : undefined;
|
||||
return (set as (...a: unknown[]) => unknown).call(this, id, richEntry ? richEntry.value : typeof id === 'string' ? sink.resolve(id, value) : value, ...rest);
|
||||
};
|
||||
},
|
||||
});
|
||||
|
|
@ -70,7 +82,12 @@ export const xWebCatalog: CatalogHookAdapter = {
|
|||
const group = languageFile(script);
|
||||
if (!group) return;
|
||||
sink.seen(group);
|
||||
mapChunkRequires(chunk, exports => (isRegistry(exports) ? shadowRegistry(exports, sink, group) : undefined));
|
||||
const rich = richText(sink.resolve);
|
||||
mapChunkRequires(chunk, exports => {
|
||||
if (isRegistry(exports)) return shadowRegistry(exports, sink, group, rich);
|
||||
rich.seen(exports);
|
||||
return undefined;
|
||||
});
|
||||
});
|
||||
},
|
||||
};
|
||||
|
|
@ -121,7 +138,7 @@ export function installXStringPacks(win: Window, delivery: StringPackDelivery |
|
|||
if (marker && delivery) {
|
||||
const rev = String(delivery.rev);
|
||||
installTranslateUi(win, {
|
||||
inventory: delivery.inventory, marker, site: X_SITE_ID, catalog: X_WEB_CATALOG,
|
||||
inventory: delivery.inventory, marker, site: X_SITE_ID, catalog: X_WEB_CATALOG, words: translateWords,
|
||||
exit() { try { win.sessionStorage.setItem(X_TRANSLATE_OFF_KEY, rev); } catch { /* no storage */ } win.location.reload(); },
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -103,7 +103,8 @@ const PROPERTY_ROLES: Record<string, AnyRole[]> = {
|
|||
const INLINE_ROLES: Record<string, AnyRole[]> = {
|
||||
'background-color': ['bg', 'surface', 'elevated', 'inverse', 'accent'],
|
||||
color: ['text', 'muted', 'accent'],
|
||||
'border-color': ['border'],
|
||||
// X's outlined buttons (Edit profile, Follow back) draw their edge inline in its secondary-text gray (live 2026-10-02).
|
||||
'border-color': ['border', 'muted'],
|
||||
};
|
||||
|
||||
/** Verification badges keep X's exact colors under any palette or accent. */
|
||||
|
|
|
|||
|
|
@ -42,9 +42,14 @@ export const X_PARTS: PartMap = {
|
|||
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"]))' },
|
||||
// Live 2026-10-01: the painted, bordered card is the grandparent of X's aside/section (a plain div sits
|
||||
// between), or the parent of a `*_sidebar` module (news, scores).
|
||||
sidebarCard: { sel: '[data-testid="sidebarColumn"] div:has(> div > :is(aside[role="complementary"],section[role="region"])),[data-testid="sidebarColumn"] div:has(> [data-testid$="_sidebar"])' },
|
||||
menu: { sel: '#layers [role="menu"]' },
|
||||
hoverCard: { sel: '#layers [data-testid="HoverCard"]' },
|
||||
// The compose dialog's painted sheet (the child of the modal that has a composer toolbar). Never every modal: the photo
|
||||
// viewer shares X's dialog attributes and its scrim must stay dark. Fixture markup; not read live.
|
||||
dialog: { sel: '#layers [role="dialog"][aria-modal="true"]:has([data-testid="toolBar"]) > div' },
|
||||
};
|
||||
|
||||
/** Where X's decoration goes. */
|
||||
|
|
@ -135,20 +140,40 @@ export const X_SKINS: VariantSkins<XSkinContext> = {
|
|||
function bar(edge: 'top' | 'bottom', colors: RoleColors): string {
|
||||
const inner = `${RAIL} > div > div`;
|
||||
return `${WIDE}{
|
||||
${NOT_CHAT} ${RAIL}{position:fixed !important;${edge}:0;left:0;right:0;z-index:30;height:56px;width:auto !important;flex-grow:0 !important;align-items:stretch !important;background-color:${colors.surface};border-${edge === 'top' ? 'bottom' : 'top'}:1px solid ${colors.border};box-shadow:0 ${edge === 'top' ? '1px' : '-1px'} 6px rgba(0, 0, 0, 0.12)}
|
||||
${NOT_CHAT} ${RAIL}{position:fixed !important;${edge}:0;left:0;right:0;z-index:30;height:56px;width:auto !important;flex-grow:0 !important;align-items:stretch !important;background-color:var(--wb-part-nav-fill, ${colors.surface});background-image:var(--wb-part-nav-fill-1, none);box-shadow:var(--wb-part-nav-bevel, 0 ${edge === 'top' ? '1px' : '-1px'} 0 ${colors.border}, 0 ${edge === 'top' ? '1px' : '-1px'} 6px rgba(0, 0, 0, 0.12))}
|
||||
/* The bar is the nav's surface: its fill and edge move from the nav (a box inside the bar) to the whole bar. */
|
||||
${NOT_CHAT} ${NAV}{--wb-part-nav-fill:transparent;--wb-part-nav-fill-1:none;--wb-part-nav-bevel:none}
|
||||
${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}
|
||||
${NOT_CHAT} ${inner}{position:static !important;width:100% !important;height:56px !important;${edge === 'top' ? 'max-width:1280px;' : ''}margin:0 auto !important}
|
||||
${NOT_CHAT} ${inner} > div{flex-direction:row !important;align-items:center !important;justify-content:space-between !important;gap:8px;height:56px !important;width:100% !important;padding:0 8px !important;overflow:visible !important;box-sizing:border-box}
|
||||
${NOT_CHAT} ${inner} > div > div{flex-direction:row !important;align-items:center !important;height:56px !important;gap:4px;min-width:0 !important}
|
||||
/* The group with the logo, the items and the Post button takes the row; the account stays whole at the end. */
|
||||
${NOT_CHAT} ${inner} > div > div:first-child{flex:1 1 auto !important}
|
||||
${NOT_CHAT} ${inner} > div > div:last-child{flex:0 0 auto !important}
|
||||
/* 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} ${NAV}{min-width:0 !important;overflow:hidden}
|
||||
/* Items share the bar like taskbar buttons: each up to 160px, all shrinking alike, the label ending in an
|
||||
ellipsis and then only the icon (live 2026-10-02: X shows up to 12 items, more than a row of whole labels). */
|
||||
${NOT_CHAT} ${NAV} > :is(a,button){width:auto !important;flex:0 1 176px !important;min-width:36px !important;overflow:hidden}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div{padding:8px 8px !important;gap:0 !important;min-width:0 !important;max-width:100% !important;box-sizing:border-box;justify-content:flex-start !important}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div > div:first-child{flex:none !important}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div > div:last-child:not(:first-child){display:block !important;flex:0 1 auto !important;margin-left:8px !important;margin-right:0 !important;padding-right:0 !important;min-width:0 !important;overflow:hidden !important;text-overflow:ellipsis !important;white-space:nowrap !important}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div > div:last-child:not(:first-child) span{display:inline !important;white-space:nowrap !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}
|
||||
${NOT_CHAT} main[role="main"]{padding-${edge}:56px !important;align-items:center !important}
|
||||
/* X's floating Grok and Chat buttons (bottom right) ride above a bottom bar instead of over its last items. */
|
||||
${edge === 'bottom' ? `${NOT_CHAT} :is([data-testid="chat-drawer-root"],[data-testid="GrokDrawer"]){transform:translateY(-56px)}` : ''}
|
||||
${NOT_CHAT} ${COLUMN} > div > div:first-child{${edge === 'top' ? 'top:56px !important' : ''}}
|
||||
}
|
||||
/* Too narrow for words: the items are icon buttons (a label cut to one letter reads as noise). */
|
||||
@media (min-width:700px) and (max-width:1199px){
|
||||
${NOT_CHAT} ${NAV} > :is(a,button){flex:0 1 48px !important}
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div{justify-content:center !important}
|
||||
/* Only a label is hidden: below 1265px X itself renders the items with their icon alone (live 2026-10-02). */
|
||||
${NOT_CHAT} ${NAV} > :is(a,button) > div > div:last-child:not(:first-child){display:none !important}
|
||||
}`;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -265,6 +265,8 @@ const STRUCTURE: Record<string, Partial<ThemeSpec>> = {
|
|||
composerTool: { text: 'accent' },
|
||||
tab: { weight: 700 },
|
||||
sidebarCard: { radius: 5, borderWidth: 1, borderStyle: 'solid', borderColor: 'border', fill: 'bg' },
|
||||
// Menus, hover cards and the compose dialog are the same white box with a hairline as the sidebar cards.
|
||||
panel: { preset: 'sheet', radius: 5, fill: 'bg', shadow: 'soft' },
|
||||
},
|
||||
decor: { dividers: { style: 'hairline', color: 'border' }, links: { underline: 'hover' } },
|
||||
icons: { pack: 'wb-classic', symbols: { like: 'star' } },
|
||||
|
|
@ -282,7 +284,8 @@ const STRUCTURE: Record<string, Partial<ThemeSpec>> = {
|
|||
tab: { case: 'lower' },
|
||||
navItem: { case: 'lower', radius: 0, hover: { fill: 'elevated' } },
|
||||
sidebarCard: { radius: 0, borderWidth: 1, borderStyle: 'dashed', borderColor: 'border', fill: 'bg' },
|
||||
menu: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'accent', fill: 'bg' },
|
||||
// Every floating layer (menus, hover cards, the compose dialog) is the same phosphor-ruled box.
|
||||
panel: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'accent', fill: 'bg', shadow: 'none' },
|
||||
},
|
||||
decor: {
|
||||
dividers: { style: 'dashed', color: 'border', width: 1 }, chrome: { kind: 'prompt', title: 'guest@x' },
|
||||
|
|
@ -291,20 +294,32 @@ const STRUCTURE: Record<string, Partial<ThemeSpec>> = {
|
|||
icons: { pack: 'wb-line', style: { stroke: 1.5, cap: 'square', join: 'miter' }, labels: { reply: 'reply', repost: 'rt', like: 'fav', bookmark: 'save' } },
|
||||
},
|
||||
'windows-98': {
|
||||
// The main column is a raised silver-framed window on the teal desktop (the outset edge of 98.css, MIT).
|
||||
css: '[data-testid="primaryColumn"]{border:0 !important;box-shadow:inset -1px -1px #0a0a0a,inset 1px 1px #dfdfdf,inset -2px -2px #808080,inset 2px 2px #ffffff !important}',
|
||||
// The main column is a raised silver-framed window on the teal desktop, and the logo is the
|
||||
// taskbar's first raised button (the outset edges of 98.css, MIT).
|
||||
css: [
|
||||
'[data-testid="primaryColumn"]{border:0 !important;box-shadow:inset -1px -1px #0a0a0a,inset 1px 1px #dfdfdf,inset -2px -2px #808080,inset 2px 2px #ffffff !important}',
|
||||
'header[role="banner"] h1[role="heading"] > a{border-radius:0 !important;background-color:#c0c0c0 !important;box-shadow:inset -1px -1px #0a0a0a,inset 1px 1px #ffffff,inset -2px -2px #808080,inset 2px 2px #dfdfdf !important}',
|
||||
'header[role="banner"] h1[role="heading"] > a:active{box-shadow:inset -1px -1px #ffffff,inset 1px 1px #0a0a0a,inset -2px -2px #dfdfdf,inset 2px 2px #808080 !important}',
|
||||
// Live 2026-10-01: the sidebar's fixed search strip is a raised silver toolbar (X paints it white over the desktop),
|
||||
// and the compose dialog's app bar and sticky toolbar let the silver window show (X paints them its layer color).
|
||||
'[data-testid="sidebarColumn"] div:has(> div > div > div > form[role="search"]){background-color:#c0c0c0 !important;box-shadow:inset -1px -1px #0a0a0a,inset 1px 1px #ffffff,inset -2px -2px #808080,inset 2px 2px #dfdfdf !important}',
|
||||
'#layers [role="dialog"][aria-modal="true"]:has([data-testid="toolBar"]) div:has(:is([data-testid="app-bar-close"],[data-testid="toolBar"])){background-color:transparent !important}',
|
||||
].join('\n'),
|
||||
variants: { nav: 'bottom' },
|
||||
components: {
|
||||
// The rail is a taskbar: a silver bar with a raised edge, every item a raised button that presses in.
|
||||
nav: { fill: 'page', borderStyle: 'bevel-out' },
|
||||
navItem: { radius: 0, text: 'text', hover: { fill: 'elevated' }, active: { shadow: 'inset' } },
|
||||
navItem: { radius: 0, text: 'text', fill: 'page', borderStyle: 'bevel-out', fontSize: 13, active: { shadow: 'inset' } },
|
||||
avatar: { shape: 'square' },
|
||||
buttonPrimary: { preset: 'bevel', fill: 'page', text: 'text', weight: 700 },
|
||||
buttonSecondary: { preset: 'bevel', fill: 'page', text: 'text' },
|
||||
search: { preset: 'sunken', radius: 0 },
|
||||
sidebarCard: { preset: 'window', fill: 'page' },
|
||||
// Every floating layer is a window: menus, hover cards, the compose dialog.
|
||||
menu: { preset: 'window', fill: 'page' },
|
||||
hoverCard: { preset: 'window', fill: 'page' },
|
||||
tab: { radius: 0 },
|
||||
dialog: { preset: 'window', fill: 'page' },
|
||||
tab: { radius: 0, fontSize: 13 },
|
||||
composerTool: { text: 'text' },
|
||||
},
|
||||
decor: {
|
||||
|
|
@ -325,6 +340,8 @@ const STRUCTURE: Record<string, Partial<ThemeSpec>> = {
|
|||
buttonSecondary: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'text', fill: 'transparent', text: 'text' },
|
||||
search: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'text', fill: 'bg' },
|
||||
sidebarCard: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'text', fill: 'bg' },
|
||||
// Menus, hover cards and the compose dialog: boxed in a printed rule like the sidebar.
|
||||
panel: { radius: 0, borderWidth: 1, borderStyle: 'solid', borderColor: 'text', fill: 'bg', shadow: 'soft' },
|
||||
tab: { case: 'small-caps', tracking: 0.06 },
|
||||
},
|
||||
decor: { chrome: { kind: 'masthead', title: 'The Daily Timeline' }, links: { underline: 'always' } },
|
||||
|
|
@ -343,50 +360,60 @@ const STRUCTURE: Record<string, Partial<ThemeSpec>> = {
|
|||
buttonSecondary: { preset: 'gloss', fill: { from: 'surface', to: 'elevated', angle: 180 }, borderColor: 'border', text: 'accent' },
|
||||
search: { preset: 'pill', fill: 'glass' },
|
||||
sidebarCard: { preset: 'glass' },
|
||||
// Menus and hover cards stay opaque over the timeline (a menu must read whatever is under it); the bars and cards are glass.
|
||||
menu: { preset: 'sheet', radius: 16 },
|
||||
hoverCard: { preset: 'sheet', radius: 16 },
|
||||
// Menus, hover cards and the compose dialog stay opaque over the timeline (a menu must read whatever is under it); the bars and cards are glass.
|
||||
panel: { preset: 'sheet', radius: 16 },
|
||||
},
|
||||
decor: { motion: { duration: 220, curve: 'spring', press: 0.97 } },
|
||||
icons: { pack: 'wb-aero' },
|
||||
},
|
||||
// The other eight: tokens and line icons (stroke, caps and size per theme), no layout variant yet.
|
||||
'night-ink': {
|
||||
components: { navItem: { radius: 10 }, buttonPrimary: { radius: 10 }, post: { hover: { fill: 'surface' } } },
|
||||
components: { navItem: { radius: 10 }, buttonPrimary: { radius: 10 }, post: { hover: { fill: 'surface' } }, panel: { preset: 'sheet', radius: 12, shadow: 'deep' } },
|
||||
decor: { focusRing: { width: 2, color: 'accent', offset: 2 } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 1.5 } },
|
||||
},
|
||||
dracula: {
|
||||
components: { buttonPrimary: { radius: 8, fill: 'inverse' }, tab: { radius: 6 }, count: { font: 'mono' } },
|
||||
components: { buttonPrimary: { radius: 8, fill: 'inverse' }, tab: { radius: 6 }, count: { font: 'mono' }, panel: { preset: 'sheet', radius: 8, shadow: 'deep' } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 1.75 } },
|
||||
},
|
||||
nord: {
|
||||
variants: { actions: 'quiet' },
|
||||
components: { avatar: { shape: 'squircle' }, buttonPrimary: { radius: 'pill' }, sidebarCard: { radius: 14, borderWidth: 0 } },
|
||||
components: { avatar: { shape: 'squircle' }, buttonPrimary: { radius: 'pill' }, panel: { preset: 'sheet', radius: 14, shadow: 'soft' }, sidebarCard: { radius: 14, borderWidth: 0 } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 2, cap: 'round' } },
|
||||
},
|
||||
'tokyo-night': {
|
||||
variants: { post: 'compact' },
|
||||
components: { count: { font: 'numbers' }, buttonPrimary: { radius: 6 } },
|
||||
components: { count: { font: 'numbers' }, buttonPrimary: { radius: 6 }, panel: { preset: 'sheet', radius: 6, shadow: 'deep' } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 1.5 } },
|
||||
},
|
||||
'solarized-light': {
|
||||
components: { avatar: { shape: 'square' }, meta: { case: 'upper', tracking: 0.06, fontSize: 11 }, buttonPrimary: { preset: 'outline', radius: 3, text: 'accent', borderColor: 'accent' } },
|
||||
components: {
|
||||
avatar: { shape: 'square' }, meta: { case: 'upper', tracking: 0.06, fontSize: 11 }, buttonPrimary: { preset: 'outline', radius: 3, text: 'accent', borderColor: 'accent' },
|
||||
panel: { preset: 'sheet', radius: 3, fill: 'bg', shadow: 'soft' },
|
||||
},
|
||||
decor: { dividers: { style: 'dotted', color: 'border', width: 1 } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 1.75, cap: 'square', join: 'miter' } },
|
||||
},
|
||||
vaporwave: {
|
||||
components: { displayName: { case: 'upper', tracking: 0.08 }, post: { shadow: 'hard' }, avatar: { shape: 'square' } },
|
||||
components: {
|
||||
displayName: { case: 'upper', tracking: 0.08 }, post: { shadow: 'hard' }, avatar: { shape: 'square' },
|
||||
// Floating layers: neon-edged slabs with the same hard drop as the posts.
|
||||
panel: { radius: 2, borderWidth: 1, borderStyle: 'solid', borderColor: 'accent', fill: 'surface', shadow: 'hard' },
|
||||
},
|
||||
icons: { pack: 'wb-classic' },
|
||||
},
|
||||
'high-contrast': {
|
||||
components: { buttonPrimary: { borderWidth: 2, borderStyle: 'solid', borderColor: 'accent' }, action: { size: 44 } },
|
||||
components: {
|
||||
buttonPrimary: { borderWidth: 2, borderStyle: 'solid', borderColor: 'accent' }, action: { size: 44 },
|
||||
// Floating layers carry the same 2px white rule as the column.
|
||||
panel: { radius: 6, borderWidth: 2, borderStyle: 'solid', borderColor: 'border', fill: 'bg', shadow: 'none' },
|
||||
},
|
||||
decor: { focusRing: { width: 3, color: 'accent', offset: 2 }, links: { underline: 'always' } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 2.25, scale: 1.1 } },
|
||||
},
|
||||
'midnight-oled': {
|
||||
variants: { actions: 'quiet' },
|
||||
components: { buttonPrimary: { radius: 'pill' }, navItem: { radius: 'pill' } },
|
||||
components: { buttonPrimary: { radius: 'pill' }, navItem: { radius: 'pill' }, panel: { preset: 'sheet', radius: 18, shadow: 'none' } },
|
||||
icons: { pack: 'wb-line', style: { stroke: 1.25 } },
|
||||
},
|
||||
};
|
||||
|
|
@ -408,6 +435,8 @@ const CELL = '[data-testid="cellInnerDiv"]';
|
|||
const MAIN = 'main[role="main"]';
|
||||
const AVATAR = '[data-testid^="UserAvatar-Container"]';
|
||||
const RADII = ['border-top-left-radius', 'border-top-right-radius', 'border-bottom-right-radius', 'border-bottom-left-radius'];
|
||||
/** The radius tokens of X's chat (Tailwind 4 theme variables and shadcn's `--radius`). */
|
||||
const TAILWIND_RADII = ['--radius', '--radius-xs', '--radius-sm', '--radius-md', '--radius-lg', '--radius-xl', '--radius-2xl', '--radius-3xl', '--radius-4xl'];
|
||||
const DENSITY: Record<Density, { v: number; h: number; gap: number }> = { compact: { v: 8, h: 14, gap: 8 }, default: { v: 12, h: 16, gap: 12 }, comfortable: { v: 16, h: 20, gap: 14 } };
|
||||
const px = (value: string) => { const m = /^(-?[\d.]+)px$/.exec(value.trim()); return m ? parseFloat(m[1]!) : null; };
|
||||
const round = (value: number) => Math.round(value * 10) / 10;
|
||||
|
|
@ -475,6 +504,26 @@ export function buildStructureCss(rules: Iterable<RuleLike>, theme: ThemeSpec, c
|
|||
const height = px(style.getPropertyValue('line-height'));
|
||||
if (height !== null && height >= 12 && height <= 72) decl.push(`line-height:${round(height * scale)}px !important`);
|
||||
}
|
||||
// X's chat sets its radius scale on the rounded elements themselves (`:is(.rounded-md, …){--x-radius-m:1.8}`,
|
||||
// read live 2026-10-01), so the `:root` value below never reaches them: scale it where X declares it.
|
||||
if (radiusChanged) {
|
||||
const scaleVar = parseFloat(style.getPropertyValue('--x-radius-m'));
|
||||
if (Number.isFinite(scaleVar)) decl.push(`--x-radius-m:${+(scaleVar * shape.radius / 16).toFixed(3)} !important`);
|
||||
// Its Tailwind radius tokens (`.rounded-3xl{border-radius:var(--radius-3xl)}`, the message box; read live
|
||||
// 2026-10-01) are declared once on the root or host: scale them there, rem or px, pills kept.
|
||||
if (/:root|:host/.test(selector)) {
|
||||
for (const name of TAILWIND_RADII) {
|
||||
const m = /^([\d.]+)(rem|px)$/.exec(style.getPropertyValue(name).trim());
|
||||
if (!m) continue;
|
||||
const size = parseFloat(m[1]!) * (m[2] === 'rem' ? 16 : 1);
|
||||
if (size >= 2 && size < 100) decl.push(`${name}:${Math.round(size * shape.radius / 16)}px !important`);
|
||||
}
|
||||
}
|
||||
}
|
||||
// X brightens some dim glyphs with a filter (`.r-1jodnrb{filter:brightness(2.5)}` on the composer's tool
|
||||
// icons, read live 2026-10-01): a theme already gives them their final, contrast-checked color, which the
|
||||
// filter would wash out (Classic's blue rendered as cyan, any light theme's icons near white).
|
||||
if (/^brightness\(/.test(style.getPropertyValue('filter').trim())) decl.push('filter:none !important');
|
||||
if (radiusChanged || buttonChanged) {
|
||||
for (const property of RADII) {
|
||||
const value = style.getPropertyValue(property);
|
||||
|
|
@ -572,7 +621,11 @@ export function buildStructureCss(rules: Iterable<RuleLike>, theme: ThemeSpec, c
|
|||
// Canvas: the page behind the columns; sidebar modules get a solid backing when it is patterned.
|
||||
if (theme.background.kind !== 'none' || colors.page !== colors.bg) {
|
||||
out.push(...pageBackgroundCss(theme.background, colors.page));
|
||||
out.push(`[data-testid="sidebarColumn"] div:has(> :is(aside[role="complementary"],section[role="region"],div[aria-label^="Timeline"])){background-color:${colors.bg} !important}`);
|
||||
// One writer per property: a theme whose sidebar cards (or all panels) carry a fill or a preset backs them itself
|
||||
// (the v2 part is the painted card, live a level above this one, which would otherwise show a second box inside).
|
||||
const parts = theme.components ?? {};
|
||||
const cardsOwned = [parts.sidebarCard, parts.panel].some(part => part?.fill !== undefined || part?.preset !== undefined);
|
||||
if (!cardsOwned) out.push(`[data-testid="sidebarColumn"] div:has(> :is(aside[role="complementary"],section[role="region"],div[aria-label^="Timeline"])){background-color:${colors.bg} !important}`);
|
||||
out.push(`[data-testid="sidebarColumn"] form[role="search"]{background-color:transparent !important}`);
|
||||
// A photo is not a known color, so text over it (the nav) gets a frosted backing.
|
||||
if (theme.background.kind === 'image') out.push(`header[role="banner"] > div > div{background-color:${rgba(colors.page, 0.78)};backdrop-filter:blur(14px)}`);
|
||||
|
|
|
|||
107
apps/desktop/src/inject/xRichText.ts
Normal file
107
apps/desktop/src/inject/xRichText.ts
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
// X's rich-text sentences (a link or bold inside a sentence) for string packs. X renders them with a
|
||||
// class registered in each language chunk as `_ActualI18NFormatMessage`: its getters (one per key
|
||||
// id) return the text pieces, and `render` shows piece n followed by the caller's element n through
|
||||
// `templateReducer`; the callers use `I18NFormatMessage`, an arrow function that creates an element
|
||||
// of that class. A pack never touches the class or the getters. This adapter registers a subclass in
|
||||
// its place whose `render` asks the engine for the key's pieces: a pack's replacement (pieces and
|
||||
// the order of X's own elements, `RichTemplate`) is shown with the caller's real elements, a
|
||||
// rewritten array goes through X's own reducer, anything else is X's own render. Every step fails
|
||||
// open: an exception shows X's own sentence.
|
||||
import type { RichTemplate } from '../../../../waybetter/packages/runtime/src/stringPacks.ts';
|
||||
|
||||
export const RICH_CLASS = '_ActualI18NFormatMessage';
|
||||
export const RICH_ELEMENT = 'I18NFormatMessage';
|
||||
|
||||
/** The parts of React the renderer needs; found among what the language chunk itself requires. */
|
||||
export type ReactLike = {
|
||||
createElement: (...args: unknown[]) => unknown;
|
||||
Fragment: unknown;
|
||||
Children: { toArray(children: unknown): unknown[] };
|
||||
};
|
||||
export const isReact = (value: unknown): value is ReactLike => {
|
||||
const react = value as Partial<ReactLike> | null;
|
||||
return typeof react === 'object' && react !== null && typeof react.createElement === 'function' && react.Fragment !== undefined && typeof react.Children?.toArray === 'function';
|
||||
};
|
||||
|
||||
type Props = { $i18n?: unknown; children?: unknown };
|
||||
type Instance = { props: Props; templateReducer: (...args: never[]) => unknown } & Record<string, unknown>;
|
||||
|
||||
const isTemplate = (value: unknown): value is RichTemplate =>
|
||||
typeof value === 'object' && value !== null && !Array.isArray(value) && Array.isArray((value as RichTemplate).pieces) && Array.isArray((value as RichTemplate).order);
|
||||
|
||||
/** The renderer for one language chunk. `resolve(id, pieces)` is the engine's answer for a key. */
|
||||
export function richText(resolve: (id: string, original: unknown) => unknown) {
|
||||
let react: ReactLike | null = null;
|
||||
let original: (new (...args: never[]) => unknown) | null = null;
|
||||
let replacement: unknown = null;
|
||||
|
||||
/** `_ActualI18NFormatMessage`: X's class, or a subclass that asks the engine. */
|
||||
function theClass(value: unknown): unknown {
|
||||
if (typeof value !== 'function' || !react) return value;
|
||||
try {
|
||||
const Base = value as new (...args: never[]) => { render(): unknown };
|
||||
const React = react;
|
||||
class Replaced extends Base {
|
||||
render(): unknown {
|
||||
try {
|
||||
const self = this as unknown as Instance;
|
||||
const id = self.props.$i18n;
|
||||
if (typeof id !== 'string') return super.render();
|
||||
const pieces = self[id];
|
||||
const result = resolve(id, pieces);
|
||||
if (isTemplate(result)) {
|
||||
const elements = React.Children.toArray(self.props.children);
|
||||
const out: unknown[] = [React.Fragment, null];
|
||||
result.pieces.forEach((piece, index) => {
|
||||
out.push(piece);
|
||||
if (index < result.order.length) out.push(elements[result.order[index]!]);
|
||||
});
|
||||
return React.createElement(...out);
|
||||
}
|
||||
if (Array.isArray(result) && result !== pieces) {
|
||||
return React.createElement(...(result.reduce(self.templateReducer as never, [React.Fragment, null]) as unknown[]));
|
||||
}
|
||||
} catch {
|
||||
// X's own sentence below.
|
||||
}
|
||||
return super.render();
|
||||
}
|
||||
}
|
||||
original = Base;
|
||||
replacement = Replaced;
|
||||
return Replaced;
|
||||
} catch {
|
||||
return value;
|
||||
}
|
||||
}
|
||||
|
||||
/** `I18NFormatMessage`: X's arrow, with the element of X's class made of the replacement instead. */
|
||||
function theElement(value: unknown): unknown {
|
||||
if (typeof value !== 'function' || !replacement || !react) return value;
|
||||
const make = value as (props: unknown) => { type?: unknown; props?: unknown; key?: unknown } | null;
|
||||
const React = react;
|
||||
return function (this: unknown, props: unknown) {
|
||||
const element = make.call(this, props);
|
||||
try {
|
||||
if (element && element.type === original) {
|
||||
const own = (element.props ?? {}) as Record<string, unknown>;
|
||||
return React.createElement(replacement, element.key == null ? own : { ...own, key: element.key });
|
||||
}
|
||||
} catch {
|
||||
// X's own element below.
|
||||
}
|
||||
return element;
|
||||
};
|
||||
}
|
||||
|
||||
return {
|
||||
/** Offered every module a language chunk requires: React is remembered, nothing is replaced. */
|
||||
seen(exports: unknown): void { if (!react && isReact(exports)) react = exports; },
|
||||
/** What to register for a key: the replacement for X's two rich-text entries, `undefined` for any other key. */
|
||||
intercept(id: string, value: unknown): { value: unknown } | undefined {
|
||||
if (id === RICH_CLASS) return { value: theClass(value) };
|
||||
if (id === RICH_ELEMENT) return { value: theElement(value) };
|
||||
return undefined;
|
||||
},
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue