Files
Country-Game---The-Desk/web/js/ui/desk.js
T

19 lines
678 B
JavaScript

// Desk-level helpers shared by the paper panels.
export function hash(str) {
let h = 2166136261;
for (let i = 0; i < str.length; i++) h = Math.imul(h ^ str.charCodeAt(i), 16777619);
return h >>> 0;
}
// Give a paper a stable slight rotation derived from its id.
export function tilt(el, id, amp = 0.8) {
const r = ((hash(id) % 1000) / 1000 - 0.5) * 2 * amp;
el.style.setProperty("--rot", `${r.toFixed(2)}deg`);
}
export const $ = (root, sel) => root.querySelector(sel);
// Escape text for use inside innerHTML templates.
export const esc = (s) => String(s).replace(/[&<>"']/g, (c) => ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[c]);