Spaces:
Sleeping
Sleeping
Download dashboard/features/studio/layout.js from JuanCS-Dev/twitch-byte-bot: direct link, hf CLI and curl.
- Browser
- Download file 2.76 kB
-
https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/dashboard/features/studio/layout.js
- Command line
-
hf download hf://spaces/JuanCS-Dev/twitch-byte-bot/dashboard/features/studio/layout.js
-
curl -L -o layout.js https://huggingface.co/spaces/JuanCS-Dev/twitch-byte-bot/resolve/main/dashboard/features/studio/layout.js
2.76 kB
| // dashboard/features/studio/layout.js | |
| // Pure layout model for the tile grid: order, hidden set, density. Persisted as | |
| // JSON in localStorage by main.js; this module stays DOM-free and validated. | |
| export const TILE_IDS = [ | |
| "tilePause", | |
| "tileSpeak", | |
| "tileHype", | |
| "tileApprove", | |
| "tileVision", | |
| "tileClips", | |
| "tileChannels", | |
| "tileAct", | |
| "tileRecap", | |
| ]; | |
| export const DENSITIES = ["comfortable", "compact"]; | |
| export function defaultLayout() { | |
| return { order: TILE_IDS.slice(), hidden: [], density: "comfortable" }; | |
| } | |
| /** Coerce any input into a valid layout (drops unknown ids, appends missing). */ | |
| export function normalizeLayout(raw) { | |
| if (!raw || typeof raw !== "object") return defaultLayout(); | |
| const order = (Array.isArray(raw.order) ? raw.order : []).filter((id) => | |
| TILE_IDS.includes(id), | |
| ); | |
| for (const id of TILE_IDS) if (!order.includes(id)) order.push(id); | |
| const hidden = (Array.isArray(raw.hidden) ? raw.hidden : []).filter((id) => | |
| TILE_IDS.includes(id), | |
| ); | |
| const density = DENSITIES.includes(raw.density) ? raw.density : "comfortable"; | |
| return { order, hidden, density }; | |
| } | |
| export function serializeLayout(layout) { | |
| return JSON.stringify(normalizeLayout(layout)); | |
| } | |
| export function parseLayout(str) { | |
| try { | |
| return normalizeLayout(JSON.parse(str)); | |
| } catch { | |
| return defaultLayout(); | |
| } | |
| } | |
| /** Move a tile up (-1) or down (+1) in the order. Returns a new layout. */ | |
| export function moveTile(layout, id, dir) { | |
| const next = normalizeLayout(layout); | |
| const i = next.order.indexOf(id); | |
| const j = i + (dir < 0 ? -1 : 1); | |
| if (i < 0 || j < 0 || j >= next.order.length) return next; | |
| [next.order[i], next.order[j]] = [next.order[j], next.order[i]]; | |
| return next; | |
| } | |
| /** Toggle a tile's visibility. Returns a new layout. */ | |
| export function toggleHidden(layout, id) { | |
| const next = normalizeLayout(layout); | |
| if (!TILE_IDS.includes(id)) return next; | |
| next.hidden = next.hidden.includes(id) | |
| ? next.hidden.filter((x) => x !== id) | |
| : [...next.hidden, id]; | |
| return next; | |
| } | |
| /** Curated profiles the streamer can apply in one click. */ | |
| export const PROFILES = { | |
| full: defaultLayout(), | |
| fps: { | |
| order: [ | |
| "tilePause", | |
| "tileApprove", | |
| "tileHype", | |
| "tileChannels", | |
| "tileAct", | |
| "tileRecap", | |
| "tileSpeak", | |
| "tileVision", | |
| "tileClips", | |
| ], | |
| hidden: [], | |
| density: "compact", | |
| }, | |
| chatting: { | |
| order: [ | |
| "tileSpeak", | |
| "tileHype", | |
| "tileApprove", | |
| "tilePause", | |
| "tileRecap", | |
| "tileChannels", | |
| "tileVision", | |
| "tileClips", | |
| "tileAct", | |
| ], | |
| hidden: [], | |
| density: "comfortable", | |
| }, | |
| }; | |
| export function profileLayout(name) { | |
| return normalizeLayout(PROFILES[name] || PROFILES.full); | |
| } | |