Extract the wayBetter framework core from wayBetter for X

Site-agnostic parts of the X app, behind a small site adapter:

- crates/waybetter-host: webview-label security policy and tab rect
  clamp, account profiles with native-owned accounts (AccountRules),
  plugin store with bundled-plugin upgrades (PluginHost), signed
  data-only hotfix channel, update scheduling and crash handshake, tab
  payloads/link routing/tab-chrome validation, and (feature "tauri")
  webview helpers and the Windows system menu.
- packages/runtime: DOM hub, request hub, plugin API core, OKLab theme
  color model, split-view rail hiding, link routing and account
  reporting, each configured by a SiteAdapter.
- packages/shell: address bar, pane, link-drop, profile, palette and
  update-chip models, and window controls with the Tauri API injected.

Tests moved/adapted from the app: 45 Rust (headless), 40 TypeScript.
This commit is contained in:
CRTkafa 2026-09-28 03:01:33 +07:00
commit 43a9e2e1a7
48 changed files with 9768 additions and 0 deletions

View file

@ -0,0 +1,49 @@
// Command palette core: fuzzy scoring, ranking and selection movement. The app builds its own
// items (tabs, profiles, settings sections, site destinations); every item is navigation only.
export type RankedItem = { label: string; keywords?: string; group: string };
/** Subsequence match, case-insensitive. 0 = no match; prefix/word-start/consecutive hits score higher. */
export function fuzzyScore(target: string, query: string): number {
const t = target.toLowerCase();
const q = query.toLowerCase().replace(/\s+/g, ' ').trim();
if (!q) return 1;
if (!t) return 0;
if (t.startsWith(q)) return 1000 - t.length;
const at = t.indexOf(q);
if (at >= 0) return 600 - at - t.length / 10 + (/[\s/_-]/.test(t[at - 1] ?? ' ') ? 100 : 0);
let score = 0;
let ti = 0;
let previous = -2;
for (const char of q) {
if (char === ' ') continue;
const found = t.indexOf(char, ti);
if (found < 0) return 0;
score += 10;
if (found === previous + 1) score += 15;
if (found === 0 || /[\s/_-]/.test(t[found - 1]!)) score += 20;
previous = found;
ti = found + 1;
}
return Math.max(1, score - t.length / 10);
}
/** An item's score: its label, or half of its keywords/group match. */
export function scoreItem(item: RankedItem, query: string): number {
const label = fuzzyScore(item.label, query);
const extra = Math.max(fuzzyScore(item.keywords ?? '', query), fuzzyScore(item.group, query)) * 0.5;
return Math.max(label, extra);
}
/** Matching items, best first; equal scores keep their original order. `skip` items never match. */
export function rankItems<T extends RankedItem>(items: readonly T[], query: string, skip: (item: T) => boolean = () => false): T[] {
return items
.map((item, index) => ({ item, index, score: skip(item) ? 0 : scoreItem(item, query) }))
.filter(entry => entry.score > 0)
.sort((a, b) => b.score - a.score || a.index - b.index)
.map(entry => entry.item);
}
/** Wraps selection movement within the list. */
export const moveSelection = (index: number, step: number, length: number) =>
length === 0 ? 0 : (index + step + length) % length;