import { authorInfo, celebrations } from "../config.js"; import emoji from "../emoji.js"; export const backButtonSVG = ` ` export const dropdownSVG = ` ` export function switcher(obj) { let items = ``; if (obj.name === "download") { items = obj.items; } else { for (let i = 0; i < obj.items.length; i++) { let classes = obj.items[i]["classes"] ? obj.items[i]["classes"] : []; if (i === 0) classes.push("first"); if (i === (obj.items.length - 1)) classes.push("last"); items += `` } } if (obj.noParent) return `
${items}
`; return `
${obj.subtitle ? `
${obj.subtitle}
` : ``}
${items}
${obj.explanation ? `
${obj.explanation}
` : ``}
` } export function checkbox(obj) { let paddings = ["bottom-margin", "top-margin", "no-margin", "top-margin-only"]; let checkboxes = ``; for (let i = 0; i < obj.length; i++) { let paddingClass = obj[i].padding && paddings.includes(obj[i].padding) ? ` ${obj[i].padding}` : ''; checkboxes += `` } return checkboxes } export function sep(paddingType) { let paddingClass = `` switch(paddingType) { case 0: paddingClass += ` top-margin`; break; } return `
` } export function popup(obj) { let classes = obj.classes ? obj.classes : []; let body = obj.body; if (Array.isArray(obj.body)) { body = `` for (let i = 0; i < obj.body.length; i++) { if (obj.body[i]["text"].length > 0) { classes = obj.body[i]["classes"] ? obj.body[i]["classes"] : [] if (i !== obj.body.length - 1 && !obj.body[i]["nopadding"]) { classes.push("desc-padding") } body += obj.body[i]["raw"] ? obj.body[i]["text"] : `` } } } return ` ${obj.standalone ? `` : ''}` } export function multiPagePopup(obj) { let tabs = ` `; let tabContent = ``; for (let i = 0; i < obj.tabs.length; i++) { tabs += `` tabContent += `` } return ` ` } export function collapsibleList(arr) { let items = ``; for (let i = 0; i < arr.length; i++) { let classes = arr[i]["classes"] ? arr[i]["classes"] : []; if (i === 0) classes.push("first"); if (i === (arr.length - 1)) classes.push("last"); items += `
${arr[i]["title"]}
${dropdownSVG}
${arr[i]["body"]}
` } return items; } export function popupWithBottomButtons(obj) { let tabs = ` ` for (let i = 0; i < obj.buttons.length; i++) { tabs += obj.buttons[i] } return ` ` } export function socialLink(emji, name, handle, url) { return `` } export function socialLinks(lang) { let links = authorInfo.support[lang] ? authorInfo.support[lang] : authorInfo.support.default; let r = ``; for (let i in links) { r += socialLink( emoji(links[i].emoji), i, links[i].handle, links[i].url ) } return r } export function settingsCategory(obj) { return `
${obj.title ? obj.title : obj.name}
${obj.body}
` } export function footerButtons(obj) { let items = `` for (let i = 0; i < obj.length; i++) { switch (obj[i]["type"]) { case "toggle": items += ``; break; case "action": items += ``; break; case "popup": let buttonName = obj[i]["context"] ? `${obj[i]["name"]}-${obj[i]["context"]}` : obj[i]["name"], context = obj[i]["context"] ? `, '${obj[i]["context"]}'` : '', buttonName2, context2; if (obj[i+1]) { buttonName2 = obj[i+1]["context"] ? `${obj[i+1]["name"]}-${obj[i+1]["context"]}` : obj[i+1]["name"]; context2 = obj[i+1]["context"] ? `, '${obj[i+1]["context"]}'` : ''; } items += ` `; i++; break; } } return ` ` } export function explanation(text) { return `
${text}
` } export function celebrationsEmoji() { try { let n = new Date().toISOString().split('T')[0].split('-'); let dm = `${n[1]}-${n[2]}`; let f = Object.keys(celebrations).includes(dm) ? celebrations[dm] : "🐲"; return f != "🐲" ? emoji(f, 22) : false; } catch (e) { return false } } export function urgentNotice(obj) { if (obj.visible) { return `
` + `${emoji(obj.emoji, 18)} ${obj.text}` + `
` } return `` } export function keyboardShortcuts(arr) { let base = `
`; for (let i = 0; i < arr.length; i++) { base += `
`; for (let c = 0; c < arr[i].items.length; c++) { let combo = arr[i].items[c].combo.split('+').map( key => `${key}` ).join("+") base += `
${combo}: ${arr[i].items[c].name}
` } base += `
` } base += `
`; return base; } export function webLoc(t, arr) { let base = ``; for (let i = 0; i < arr.length; i++) { base += `${arr[i]}:` + "`" + t(arr[i]) + "`" + `,` } return `{${base}};` }