/*
* Rolls of the dice. Wherever the page shows a step the game decides at random (not the rider's choice), a pair of
* dice sits next to it. Clicking the dice shows the odds of every outcome of that roll.
*
* Dice.html(roll) an inline button for HTML text
* Dice.svg(parent, x, y, roll) the same glyph inside an SVG map
* Dice.legend(text?) the legend line ("a roll: the game decides ...")
*
* roll = { title, options: [[label, p], ...], note?, n? } (p between 0 and 1; options may be empty with a note)
*/
(function () {
"use strict";
const NS = "http://www.w3.org/2000/svg";
// two dice, the back one showing two, the front one five
const GLYPH = ``;
const TIP = "A roll: the game decides, not you. Click for the odds of each outcome.";
const esc = (s) => String(s).replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
const pack = (roll) => encodeURIComponent(JSON.stringify(roll || {}));
const pct = (p) => (p == null ? "–" : p < 0.001 && p > 0 ? "<0.1%" : `${(100 * p).toFixed(p < 0.1 ? 1 : 0)}%`);
function html(roll) {
return ``;
}
function svg(parent, x, y, roll) {
const g = document.createElementNS(NS, "g");
g.setAttribute("class", "dice dice-svg");
g.setAttribute("data-roll", pack(roll));
g.setAttribute("transform", `translate(${x - 11},${y - 8})`);
g.setAttribute("tabindex", "0");
g.setAttribute("role", "button");
g.setAttribute("aria-label", `${(roll && roll.title) || "A roll"}: show the odds`);
const t = document.createElementNS(NS, "title");
t.textContent = TIP;
g.appendChild(t);
const halo = document.createElementNS(NS, "rect");
for (const [k, v] of Object.entries({ x: -3, y: -3, width: 28, height: 22, rx: 6, fill: "var(--map-halo, var(--bg))", "fill-opacity": 0.9 })) halo.setAttribute(k, v);
g.appendChild(halo);
g.insertAdjacentHTML("beforeend", GLYPH.replace(/^