Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/>
<link rel="icon" href="./favicon.svg" type="image/svg+xml" />
<title>禅聊 ZenChat</title>
<script type="module" crossorigin src="/ZenChat/assets/index-CE2I8ZcW.js"></script>
<link rel="stylesheet" crossorigin href="/ZenChat/assets/index-CDh36co2.css">
<script type="module" crossorigin src="/ZenChat/assets/index-Dl0q0iBn.js"></script>
<link rel="stylesheet" crossorigin href="/ZenChat/assets/index-BxoYAeQ1.css">
</head>
<body>
<div id="app"></div>
Expand Down
1 change: 1 addition & 0 deletions assets/index-BxoYAeQ1.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion assets/index-CDh36co2.css

This file was deleted.

3 changes: 0 additions & 3 deletions assets/index-CE2I8ZcW.js

This file was deleted.

3 changes: 3 additions & 0 deletions assets/index-Dl0q0iBn.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
/>
<link rel="icon" href="./favicon.svg" type="image/svg+xml" />
<title>禅聊 ZenChat</title>
<script type="module" crossorigin src="/ZenChat/assets/index-CE2I8ZcW.js"></script>
<link rel="stylesheet" crossorigin href="/ZenChat/assets/index-CDh36co2.css">
<script type="module" crossorigin src="/ZenChat/assets/index-Dl0q0iBn.js"></script>
<link rel="stylesheet" crossorigin href="/ZenChat/assets/index-BxoYAeQ1.css">
</head>
<body>
<div id="app"></div>
Expand Down
4 changes: 2 additions & 2 deletions public/favicon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 4 additions & 3 deletions src/core/identity.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ describe('identity helpers', () => {
expect(sanitizeNick('x'.repeat(40)).length).toBe(24)
})

it('maps ids to a stable fallback nick and color', () => {
it('maps ids to a stable fallback nick and earth-tone color', () => {
expect(defaultNick('abcd')).toBe(defaultNick('abcd'))
expect(colorFromId('peer-a')).toMatch(/^hsl\(\d+ 42% 46%\)$/)
expect(colorFromId('peer-a')).not.toBe(colorFromId('peer-b'))
expect(colorFromId('peer-a')).toMatch(/^#[0-9a-f]{6}$/)
expect(colorFromId('peer-a')).toBe(colorFromId('peer-a'))
expect(new Set(['peer-a', 'peer-b', 'peer-c', 'peer-d', 'peer-e'].map(colorFromId)).size).toBeGreaterThan(1)
})
})
5 changes: 3 additions & 2 deletions src/core/identity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,15 @@ export function randomHex(bytes: number): string {
return [...buf].map((b) => b.toString(16).padStart(2, '0')).join('')
}

const EARTH_COLORS = ['#c15f3c', '#8b5e3c', '#5c6b4a', '#6b4f3a', '#9a6b3f', '#4a6b62', '#7a4e3a', '#5a5568']

export function colorFromId(id: string): string {
let hash = 2166136261
for (let i = 0; i < id.length; i += 1) {
hash ^= id.charCodeAt(i)
hash = Math.imul(hash, 16777619)
}
const hue = Math.abs(hash) % 360
return `hsl(${hue} 42% 46%)`
return EARTH_COLORS[Math.abs(hash) % EARTH_COLORS.length] ?? '#c15f3c'
}

export function sanitizeNick(raw: string): string {
Expand Down
15 changes: 5 additions & 10 deletions src/ui/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { copy } from './copy'
import { el, empty, hostOf, wsLabel } from './dom'
import { LogView } from './log-view'
import { StampPicker } from './picker'
import { applyTheme, cycleTheme, loadThemePreference, persistThemePreference } from './theme'
import { applyTheme, cycleTheme, loadThemePreference, persistThemePreference, themeLabel } from './theme'

function webrtcReady(): boolean {
return typeof RTCPeerConnection === 'function'
Expand Down Expand Up @@ -37,7 +37,7 @@ export class App {
this.root = root
this.theme = loadThemePreference()
applyTheme(this.theme)
this.themeBtn = el('button', { class: 'btn ghost', type: 'button', title: '主题' }, [themeIcon(this.theme)])
this.themeBtn = el('button', { class: 'btn ghost', type: 'button', title: '主题' }, [themeLabel(this.theme)])
this.tabsEl = el('nav', { class: 'tabs', 'aria-label': copy.recent })
this.toolsEl = el('div', { class: 'toolbar' })
this.main = el('main', { class: 'main' })
Expand Down Expand Up @@ -81,7 +81,7 @@ export class App {
this.theme = cycleTheme(this.theme)
persistThemePreference(this.theme)
applyTheme(this.theme)
this.themeBtn.textContent = themeIcon(this.theme)
this.themeBtn.textContent = themeLabel(this.theme)
})
void this.route()
}
Expand All @@ -93,6 +93,7 @@ export class App {
el('a', { class: 'brand', href: '#/' }, [
el('div', { class: 'enso', 'aria-hidden': 'true' }),
el('strong', {}, [copy.title]),
el('span', { class: 'tagline' }, [copy.tagline]),
]),
this.tabsEl,
this.toolsEl,
Expand Down Expand Up @@ -234,7 +235,7 @@ export class App {
strategy: strategy.value as SignalStrategy,
})
})
return form
return el('div', { class: 'lobby' }, [el('p', { class: 'lede' }, [copy.lobbyHint]), form])
}

private refreshTabs(active?: RoomSpec): void {
Expand Down Expand Up @@ -399,12 +400,6 @@ function field(label: string, control: HTMLElement): HTMLElement {
return el('label', { class: 'field' }, [el('span', {}, [label]), control])
}

function themeIcon(pref: ThemePreference): string {
if (pref === 'light') return '浅色'
if (pref === 'dark') return '深色'
return '自动'
}

function specFromRecent(item: RecentRoom, active?: RoomSpec): RoomSpec {
const password = active && item.name === normalizeRoomName(active.name) && item.strategy === active.strategy ? active.password : ''
return { name: item.name, password, strategy: item.strategy }
Expand Down
Loading
Loading