marp-share / client /src /collab /user.ts
Nipun's picture
Deploy marp-share (M1–M5): realtime + persistence + HF auth + comments + export
43370b3 verified
Raw
History Blame Contribute Delete
1.12 kB
export interface CollabUser {
name: string
color: string
colorLight: string
avatar?: string
}
const ANIMALS = [
'Otter', 'Falcon', 'Maple', 'Comet', 'Wren', 'Lynx',
'Sage', 'Cobalt', 'Ember', 'Koi', 'Birch', 'Nova',
]
const COLORS = [
'#ef4444', '#f97316', '#eab308', '#22c55e',
'#06b6d4', '#3b82f6', '#8b5cf6', '#ec4899',
]
const pick = <T>(xs: T[]) => xs[Math.floor(Math.random() * xs.length)]
/** Deterministic color so a given person keeps the same cursor color. */
export function colorFor(seed: string): string {
let h = 0
for (let i = 0; i < seed.length; i++) h = (h * 31 + seed.charCodeAt(i)) >>> 0
return COLORS[h % COLORS.length]
}
/** Anonymous identity (local dev / auth disabled). */
export function makeUser(): CollabUser {
const color = pick(COLORS)
return { name: pick(ANIMALS), color, colorLight: color + '40' }
}
/** Identity from a signed-in Hugging Face user. */
export function hfUser(u: { id: string; name: string; avatar?: string }): CollabUser {
const color = colorFor(u.id || u.name)
return { name: u.name, color, colorLight: color + '40', avatar: u.avatar }
}