2023-10-12 12:33:26 +01:00
|
|
|
import { authorInfo, celebrations, sponsors } from "../config.js";
|
2023-05-16 21:13:11 +01:00
|
|
|
import emoji from "../emoji.js";
|
2023-10-12 12:33:26 +01:00
|
|
|
import { loadFile } from "../sub/loadFromFs.js";
|
2022-10-27 17:27:20 +01:00
|
|
|
|
2023-08-04 19:43:12 +01:00
|
|
|
export const backButtonSVG = `<svg width="22" height="22" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
2023-08-11 16:53:30 +01:00
|
|
|
<path d="M14.1905 28.5L2 16L14.1905 3.5L16.2857 5.62054L7.65986 14.4654H30V17.5346H7.65986L16.2857 26.3516L14.1905 28.5Z" fill="#E1E1E1"/>
|
|
|
|
</svg>`
|
|
|
|
|
|
|
|
export const dropdownSVG = `<svg width="18" height="18" viewBox="0 0 32 32" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
|
|
<path d="M28 12.0533L16 24L4 12.0533L6.03571 10L14.7188 18.4104L16.25 19.9348L17.7813 18.4104L25.9375 10L28 12.0533Z" fill="#E1E1E1"/>
|
2023-08-04 19:43:12 +01:00
|
|
|
</svg>`
|
|
|
|
|
2023-12-25 17:57:33 +00:00
|
|
|
export const linkSVG = '<svg xmlns="http://www.w3.org/2000/svg" width="32" height="32" viewBox="0 0 256 256"><path fill="currentColor" d="M137.54 186.36a8 8 0 0 1 0 11.31l-9.94 10a56 56 0 0 1-79.22-79.27l24.12-24.12a56 56 0 0 1 76.81-2.28a8 8 0 1 1-10.64 12a40 40 0 0 0-54.85 1.63L59.7 139.72a40 40 0 0 0 56.58 56.58l9.94-9.94a8 8 0 0 1 11.32 0Zm70.08-138a56.08 56.08 0 0 0-79.22 0l-9.94 9.95a8 8 0 0 0 11.32 11.31l9.94-9.94a40 40 0 0 1 56.58 56.58l-24.12 24.14a40 40 0 0 1-54.85 1.6a8 8 0 1 0-10.64 12a56 56 0 0 0 76.81-2.26l24.12-24.12a56.08 56.08 0 0 0 0-79.24Z"/></svg>'
|
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
export function switcher(obj) {
|
|
|
|
let items = ``;
|
2023-02-12 07:40:49 +00:00
|
|
|
if (obj.name === "download") {
|
2023-01-29 18:28:10 +00:00
|
|
|
items = obj.items;
|
2023-01-29 18:17:33 +00:00
|
|
|
} else {
|
|
|
|
for (let i = 0; i < obj.items.length; i++) {
|
2023-08-11 16:53:30 +01:00
|
|
|
let classes = obj.items[i]["classes"] ? obj.items[i]["classes"] : [];
|
2023-01-29 18:17:33 +00:00
|
|
|
items += `<button id="${obj.name}-${obj.items[i]["action"]}" class="switch${classes.length > 0 ? ' ' + classes.join(' ') : ''}" onclick="changeSwitcher('${obj.name}', '${obj.items[i]["action"]}')">${obj.items[i]["text"] ? obj.items[i]["text"] : obj.items[i]["action"]}</button>`
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-04-03 17:36:23 +01:00
|
|
|
|
2023-05-18 18:05:29 +01:00
|
|
|
if (obj.noParent) return `<div id="${obj.name}" class="switches">${items}</div>`;
|
2023-01-29 18:17:33 +00:00
|
|
|
return `<div id="${obj.name}-switcher" class="switch-container">
|
2022-08-12 14:36:19 +01:00
|
|
|
${obj.subtitle ? `<div class="subtitle">${obj.subtitle}</div>` : ``}
|
|
|
|
<div class="switches">${items}</div>
|
|
|
|
${obj.explanation ? `<div class="explanation">${obj.explanation}</div>` : ``}
|
|
|
|
</div>`
|
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
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}` : '';
|
2022-08-12 14:36:19 +01:00
|
|
|
|
2023-08-04 19:43:12 +01:00
|
|
|
checkboxes += `<label id="${obj[i].action}-chkbx" class="checkbox${paddingClass}">
|
|
|
|
<input id="${obj[i].action}" type="checkbox" aria-label="${obj[i].aria ? obj[i].aria : obj[i].name}" onclick="checkbox('${obj[i].action}')">
|
|
|
|
<span>${obj[i].name}</span>
|
|
|
|
</label>`
|
2022-09-28 13:21:36 +01:00
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
return checkboxes
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2022-12-17 11:09:49 +00:00
|
|
|
export function sep(paddingType) {
|
|
|
|
let paddingClass = ``
|
|
|
|
switch(paddingType) {
|
|
|
|
case 0:
|
|
|
|
paddingClass += ` top-margin`;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return `<div class="separator${paddingClass}"></div>`
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
export function popup(obj) {
|
2023-08-04 19:43:12 +01:00
|
|
|
let classes = obj.classes ? obj.classes : [];
|
2022-08-12 14:36:19 +01:00
|
|
|
let body = obj.body;
|
|
|
|
if (Array.isArray(obj.body)) {
|
|
|
|
body = ``
|
|
|
|
for (let i = 0; i < obj.body.length; i++) {
|
2022-10-09 18:44:00 +01:00
|
|
|
if (obj.body[i]["text"].length > 0) {
|
|
|
|
classes = obj.body[i]["classes"] ? obj.body[i]["classes"] : []
|
2022-10-24 14:03:11 +01:00
|
|
|
if (i !== obj.body.length - 1 && !obj.body[i]["nopadding"]) {
|
2022-10-09 18:44:00 +01:00
|
|
|
classes.push("desc-padding")
|
|
|
|
}
|
|
|
|
body += obj.body[i]["raw"] ? obj.body[i]["text"] : `<div id="popup-desc" class="${classes.length > 0 ? classes.join(' ') : ''}">${obj.body[i]["text"]}</div>`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `
|
2023-12-25 19:10:40 +00:00
|
|
|
${obj.standalone ? `<div id="popup-${obj.name}" class="popup center${!obj.buttonOnly ? " box" : ''}${classes.length > 0 ? ' ' + classes.join(' ') : ''}">` : ''}
|
2023-09-06 14:37:03 +01:00
|
|
|
<div id="popup-header" class="popup-header">
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-header-contents">
|
|
|
|
${obj.buttonOnly ? obj.header.emoji : ``}
|
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}
|
|
|
|
</div>
|
2023-12-25 19:10:40 +00:00
|
|
|
${!obj.buttonOnly ? `<div class="glass-bkg alone"></div>` : ''}
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-content" class="popup-content-inner">
|
2022-08-19 18:54:20 +01:00
|
|
|
${body}${obj.buttonOnly ? `<button id="close-error" class="switch" onclick="popup('${obj.name}', 0)">${obj.buttonText}</button>` : ''}
|
|
|
|
</div>
|
2023-12-25 19:10:40 +00:00
|
|
|
${classes.includes("small") ? `<div class="glass-bkg small"></div>` : ''}
|
2022-08-19 18:54:20 +01:00
|
|
|
${obj.standalone ? `</div>` : ''}`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function multiPagePopup(obj) {
|
2023-08-04 19:43:12 +01:00
|
|
|
let tabs = `
|
|
|
|
<button id="back-button" class="switch tab-${obj.name}" onclick="popup('${obj.name}', 0)" ${obj.closeAria ? `aria-label="${obj.closeAria}"` : ''}>
|
|
|
|
${backButtonSVG}
|
|
|
|
</button>`;
|
|
|
|
|
|
|
|
let tabContent = ``;
|
2022-08-12 14:36:19 +01:00
|
|
|
for (let i = 0; i < obj.tabs.length; i++) {
|
|
|
|
tabs += `<button id="tab-button-${obj.name}-${obj.tabs[i]["name"]}" class="switch tab tab-${obj.name}" onclick="changeTab(event, 'tab-${obj.name}-${obj.tabs[i]["name"]}', '${obj.name}')">${obj.tabs[i]["title"]}</button>`
|
|
|
|
tabContent += `<div id="tab-${obj.name}-${obj.tabs[i]["name"]}" class="popup-tab-content tab-content-${obj.name}">${obj.tabs[i]["content"]}</div>`
|
|
|
|
}
|
2023-08-04 19:43:12 +01:00
|
|
|
|
2022-08-12 14:36:19 +01:00
|
|
|
return `
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-${obj.name}" class="popup center box scrollable">
|
|
|
|
<div id="popup-content">
|
2023-09-06 14:37:03 +01:00
|
|
|
${obj.header ? `<div id="popup-header" class="popup-header">
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-header-contents">
|
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}
|
|
|
|
</div>
|
2023-09-06 14:37:03 +01:00
|
|
|
<div class="glass-bkg alone"></div>
|
2023-08-04 19:43:12 +01:00
|
|
|
</div>` : ''}${tabContent}</div>
|
2023-09-06 14:37:03 +01:00
|
|
|
<div id="popup-tabs" class="switches popup-tabs">
|
|
|
|
<div class="switches popup-tabs-child">${tabs}</div>
|
|
|
|
<div class="glass-bkg alone"></div>
|
|
|
|
</div>
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>`
|
|
|
|
}
|
2023-01-29 18:17:33 +00:00
|
|
|
export function collapsibleList(arr) {
|
2023-08-11 16:53:30 +01:00
|
|
|
let items = ``;
|
|
|
|
|
2023-01-29 18:17:33 +00:00
|
|
|
for (let i = 0; i < arr.length; i++) {
|
2023-08-11 16:53:30 +01:00
|
|
|
let classes = arr[i]["classes"] ? arr[i]["classes"] : [];
|
|
|
|
items += `<div id="${arr[i]["name"]}-collapse" class="collapse-list${classes.length > 0 ? ' ' + classes.join(' ') : ''}">
|
2023-01-29 18:17:33 +00:00
|
|
|
<div class="collapse-header" onclick="expandCollapsible(event)">
|
|
|
|
<div class="collapse-title">${arr[i]["title"]}</div>
|
2023-08-11 16:53:30 +01:00
|
|
|
<div class="collapse-indicator">${dropdownSVG}</div>
|
2023-01-29 18:17:33 +00:00
|
|
|
</div>
|
|
|
|
<div id="${arr[i]["name"]}-body" class="collapse-body">${arr[i]["body"]}</div>
|
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
return items;
|
|
|
|
}
|
2022-09-03 16:32:39 +01:00
|
|
|
export function popupWithBottomButtons(obj) {
|
2023-08-04 19:43:12 +01:00
|
|
|
let tabs = `
|
|
|
|
<button id="back-button" class="switch tab-${obj.name}" onclick="popup('${obj.name}', 0)" ${obj.closeAria ? `aria-label="${obj.closeAria}"` : ''}>
|
|
|
|
${backButtonSVG}
|
|
|
|
</button>`
|
|
|
|
|
2022-09-03 16:32:39 +01:00
|
|
|
for (let i = 0; i < obj.buttons.length; i++) {
|
|
|
|
tabs += obj.buttons[i]
|
|
|
|
}
|
|
|
|
return `
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-${obj.name}" class="popup center box scrollable">
|
|
|
|
<div id="popup-content">
|
2023-09-06 14:37:03 +01:00
|
|
|
${obj.header ? `<div id="popup-header" class="popup-header">
|
2023-08-04 19:43:12 +01:00
|
|
|
<div id="popup-header-contents">
|
|
|
|
${obj.header.aboveTitle ? `<a id="popup-above-title" target="_blank" href="${obj.header.aboveTitle.url}">${obj.header.aboveTitle.text}</a>` : ''}
|
|
|
|
${obj.header.title ? `<div id="popup-title">${obj.header.title}</div>` : ''}
|
|
|
|
${obj.header.subtitle ? `<div id="popup-subtitle">${obj.header.subtitle}</div>` : ''}
|
|
|
|
${obj.header.explanation ? `<div class="explanation">${obj.header.explanation}</div>` : ''}
|
|
|
|
</div>
|
2023-09-06 14:37:03 +01:00
|
|
|
<div class="glass-bkg alone"></div>
|
2023-08-04 19:43:12 +01:00
|
|
|
</div>` : ''}${obj.content}</div>
|
2023-09-06 14:37:03 +01:00
|
|
|
<div id="popup-tabs" class="switches popup-tabs">
|
|
|
|
<div id="picker-buttons" class="switches popup-tabs-child">${tabs}</div>
|
|
|
|
<div class="glass-bkg alone"></div>
|
|
|
|
</div>
|
2022-09-03 16:32:39 +01:00
|
|
|
</div>`
|
|
|
|
}
|
2023-12-25 11:46:33 +00:00
|
|
|
export function socialLink(emji, name, url) {
|
|
|
|
return `<div class="cobalt-support-link">${emji} <a class="text-backdrop link" href="${url}" target="_blank">${name}</a></div>`
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
2023-09-16 18:38:07 +01:00
|
|
|
export function socialLinks(lang) {
|
|
|
|
let links = authorInfo.support[lang] ? authorInfo.support[lang] : authorInfo.support.default;
|
|
|
|
let r = ``;
|
|
|
|
for (let i in links) {
|
|
|
|
r += socialLink(
|
2023-12-25 11:46:33 +00:00
|
|
|
emoji(links[i].emoji), links[i].name, links[i].url
|
2023-09-16 18:38:07 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
return r
|
|
|
|
}
|
2022-08-12 14:36:19 +01:00
|
|
|
export function settingsCategory(obj) {
|
|
|
|
return `<div id="settings-${obj.name}" class="settings-category">
|
|
|
|
<div class="category-title">${obj.title ? obj.title : obj.name}</div>
|
2023-01-29 18:17:33 +00:00
|
|
|
<div class="category-content">${obj.body}</div>
|
2022-08-12 14:36:19 +01:00
|
|
|
</div>`
|
|
|
|
}
|
|
|
|
|
|
|
|
export function footerButtons(obj) {
|
|
|
|
let items = ``
|
|
|
|
for (let i = 0; i < obj.length; i++) {
|
2023-12-25 19:10:40 +00:00
|
|
|
let buttonName = obj[i]["context"] ? `${obj[i]["name"]}-${obj[i]["context"]}` : obj[i]["name"],
|
|
|
|
context = obj[i]["context"] ? `, '${obj[i]["context"]}'` : '',
|
|
|
|
buttonName2,
|
|
|
|
context2;
|
2023-05-16 21:13:11 +01:00
|
|
|
|
2023-12-25 19:10:40 +00:00
|
|
|
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"]}'` : '';
|
2022-09-08 17:02:55 +01:00
|
|
|
}
|
2023-12-25 19:10:40 +00:00
|
|
|
|
|
|
|
items +=
|
|
|
|
`<div class="footer-pair">
|
|
|
|
<button id="${buttonName}-footer" class="switch footer-button" onclick="popup('${obj[i]["name"]}', 1${context})" aria-label="${obj[i]["aria"]}">${obj[i]["text"]}</button>
|
|
|
|
${obj[i + 1] ? `<button id="${buttonName2}-footer" class="switch footer-button" onclick="popup('${obj[i + 1]["name"]}', 1${context2})" aria-label="${obj[i + 1]["aria"]}">${obj[i + 1]["text"]}</button>` : ''}
|
|
|
|
</div>`;
|
|
|
|
i++;
|
2022-08-12 14:36:19 +01:00
|
|
|
}
|
|
|
|
return `
|
|
|
|
<div id="footer-buttons">${items}</div>`
|
|
|
|
}
|
2022-12-17 11:09:49 +00:00
|
|
|
export function explanation(text) {
|
|
|
|
return `<div class="explanation">${text}</div>`
|
|
|
|
}
|
2022-10-27 17:27:20 +01:00
|
|
|
export function celebrationsEmoji() {
|
2023-05-16 21:13:11 +01:00
|
|
|
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
|
|
|
|
}
|
2022-10-27 17:27:20 +01:00
|
|
|
}
|
2023-08-11 16:53:30 +01:00
|
|
|
export function urgentNotice(obj) {
|
|
|
|
if (obj.visible) {
|
2023-08-29 18:24:00 +01:00
|
|
|
return `<div id="urgent-notice" class="urgent-notice explanation">` +
|
|
|
|
`<span class="urgent-text" onclick="${obj.action}">${emoji(obj.emoji, 18)} ${obj.text}</span>` +
|
|
|
|
`</div>`
|
2023-08-11 16:53:30 +01:00
|
|
|
}
|
|
|
|
return ``
|
|
|
|
}
|
|
|
|
export function keyboardShortcuts(arr) {
|
|
|
|
let base = `<div id="keyboard-shortcuts" class="explanation">`;
|
|
|
|
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
base += `<div class="shortcut-category">`;
|
|
|
|
for (let c = 0; c < arr[i].items.length; c++) {
|
|
|
|
let combo = arr[i].items[c].combo.split('+').map(
|
|
|
|
key => `<span class="text-backdrop key">${key}</span>`
|
|
|
|
).join("+")
|
|
|
|
base += `<div class="shortcut">${combo}: ${arr[i].items[c].name}</div>`
|
|
|
|
}
|
|
|
|
base += `</div>`
|
|
|
|
}
|
|
|
|
base += `</div>`;
|
|
|
|
|
|
|
|
return base;
|
|
|
|
}
|
2023-09-08 22:10:43 +01:00
|
|
|
export function webLoc(t, arr) {
|
|
|
|
let base = ``;
|
|
|
|
for (let i = 0; i < arr.length; i++) {
|
|
|
|
base += `${arr[i]}:` + "`" + t(arr[i]) + "`" + `,`
|
|
|
|
}
|
|
|
|
return `{${base}};`
|
|
|
|
}
|
2023-10-12 12:33:26 +01:00
|
|
|
|
|
|
|
export function sponsoredList() {
|
|
|
|
let base = ``;
|
|
|
|
let altText = ``
|
|
|
|
for (let i = 0; i < sponsors.length; i++) {
|
|
|
|
let s = sponsors[i];
|
|
|
|
let loadedLogo = loadFile(`./src/front/sponsors/${s.name}.svg`);
|
|
|
|
|
|
|
|
altText += `${s.fullName ? s.fullName : s.name}, `;
|
|
|
|
base +=
|
|
|
|
`<a class="sponsored-logo ${s.name}"
|
|
|
|
href="${s.url}" target="_blank"
|
|
|
|
style="width: calc(${s.logo.width}px / ${s.logo.scale}); height: calc(${s.logo.height}px / ${s.logo.scale});">
|
|
|
|
${loadedLogo}
|
|
|
|
</a>`
|
|
|
|
}
|
|
|
|
return `<div id="sponsored-logos" aria-label="${altText.slice(0, -2)}">${base}</div>`
|
|
|
|
}
|
2023-10-28 13:51:20 +01:00
|
|
|
|
|
|
|
export function betaTag() {
|
|
|
|
return process.env.isBeta ? '<span class="logo-sub">β</span>' : ''
|
|
|
|
}
|