// THE MEASURE EXTRAS' SETTINGS (weight video rev 9, lane measure-extras): the // four small modules that read the schedule's `measure` slice beside the scale // dial -- the goal stack (`goals`), the moving start (`peak`), the promise // clock (`promise`) and the diet badge (`diet`). Their defaults and validators, // the one copy. A LEAF like settings.mjs (deck.mjs imports it through // SETTINGS), so it imports only instruments.mjs (a leaf too: whether the // instruments' column is on decides two defaults here). // // render.chrome.deck.goals { show, position, x, y, scale, hold, finale, max, color, countdown, base, baseMaxDays, flash } // render.chrome.deck.peak { show, position, x, y, scale, hold, finale, title, color, values } // render.chrome.deck.promise { show, position, x, y, scale, hold, finale, label, verb, kept, broken, checks, speakers, claimVerb, claimColor } // render.chrome.deck.diet { show, position, x, y, scale, hold, finale, colors, labels, form, tags, overlap, days, flash } // render.chrome.deck.streak { show, position, x, y, scale, hold, finale, source, axis, title, color, colors, labels } // // Each is ON whenever the cut has a measure slice (the build writes one only // for a manifest with a measure ledger and `deck.measure` set) and something // of its own to draw; `false` (or `show: false`) turns it off, `true` is the // defaults. Absent, the module draws with its defaults -- and a cut with no // measure slice draws none of them, so it renders exactly as before. // // WHERE THEY SIT. The scale-dial lane's instrument panel takes the right // column (the dial in its top ~600 px, the odometer and the trail under it), // so these four default to anchors of the FOOTAGE BOX, clear of it -- and // clear of the top-left, where the streams' face cam most often sits: the // diet badge bottom-left, the goal stack bottom-right, the moving start // top-right (only for a few seconds after each telling), the promise clock // top-centre (from the promise on, the last beat). `position` moves one to another // anchor of the footage box; `x`/`y` (design pixels on the 1920×1080 frame) // put its top-left corner anywhere -- inside the panel column, say -- and // `scale` sizes it. import { instrumentsOn, resolveDial } from "../instruments.mjs"; import { resolveShelf, SHELF_EXTRAS } from "./shelf-settings.mjs"; /** The anchors in the footage box a module may sit at (`position`). */ export const MEASURE_POSITIONS = Object.freeze(["top-left", "top-right", "bottom-left", "bottom-right", "top-center", "bottom-center"]); /** * The anchors, and the SHELF (`deck.shelf`, shelf-settings.mjs): the strip the * footage leaves beside it, where a module stands in its own slot, clear of * everything (no dodging there). Diet, streak, goals and peak may take it. */ export const SHELF_POSITION = "shelf"; /** * What a module does when a post item's card (`onPosts`) or a chapter band * (`onChapters`) is up where it stands: moves to a slot clear of it (a size * down if it must, hidden when nothing fits), hides, or stays (drawn over it). */ export const MEASURE_AVOID = Object.freeze(["dodge", "hide", "show"]); /** What a module does over the finale's window (`finale`): hidden under it, or drawn over it. */ export const MEASURE_FINALE = Object.freeze(["hide", "show"]); /** Which remembered weights the moving start draws (`peak.values`): the totals' drift values, or every one. */ export const PEAK_VALUES = Object.freeze(["drift", "all"]); /** Where the streak chain's runs come from (`streak.source`): diet runs, his lost-weight runs, pledges (the sobriety video's; adapter only). */ export const STREAK_SOURCES = Object.freeze(["diet", "lostRuns", "pledges"]); /** How the streak chain lays its runs (`streak.axis`): to scale on the in-record dates, or one after another (√ of their length). */ export const STREAK_AXES = Object.freeze(["date", "runs"]); /** What a promise check's line quotes (`promise.checks`): the ledger row's label, or its transcript quote. */ export const PROMISE_CHECKS = Object.freeze(["label", "quote"]); /** How the diet is drawn (`diet.form`): the stamp that slams on, or a row of dated tags, the newest first. */ export const DIET_FORMS = Object.freeze(["stamp", "tags"]); /** How many tags the diet's row keeps (`diet.tags`). */ export const DIET_TAGS = Object.freeze([1, 4]); /** * How much of each older tag hides behind the one in front (`diet.overlap`): * 0 is the row of tags side by side; above it the tags fan sideways like the * goal stack's notes, the newest in front at the left. The bounds a value is * checked against; legibility caps it lower (dietOverlapMax: an older tag's * regime word and date need DIET_BACK_MIN of it). */ export const DIET_OVERLAP = Object.freeze([0, 0.8]); /** The design px of an older tag that must show beside the one in front of it: its regime word and its date. */ export const DIET_BACK_MIN = 110; /** A diet tag's width, design px: 220, or 300 with the running day count (`diet.days`) in a column of its own. */ export const dietTagWidth = (days) => (days ? 300 : 220); /** The most overlap that keeps an older tag's regime word and date in view. */ export const dietOverlapMax = (days) => Math.floor((1 - DIET_BACK_MIN / dietTagWidth(days)) * 100) / 100; /** The diet regimes the ledger names (ledgerSchema.regimes), and what the badge calls each. */ export const DIET_LABELS = Object.freeze({ keto: "Keto", carnivore: "Carnivore", fasting: "Fasting", calories: "Counting calories", glp1: "GLP-1", other: "Some diet", off: "No diet", }); /** Each regime's ink (the quartering-diet ledgerSchema's colours). */ export const DIET_COLORS = Object.freeze({ keto: "#E0913C", carnivore: "#C9534B", fasting: "#4E9BD8", calories: "#3FA9A0", glp1: "#B168C6", other: "#8E97A8", off: "#98A29B", }); /** The needle's red (the contract's ~#ff5a4e): the moving start's drift, an unkept promise. */ export const MEASURE_RED = "#FF5A4E"; /** Every module's bounds. */ export const MEASURE_LIMITS = Object.freeze({ scale: Object.freeze([0.5, 2]), hold: Object.freeze([2, 600]), x: Object.freeze([0, 1920]), y: Object.freeze([0, 1080]), max: Object.freeze([1, 8]), baseMaxDays: Object.freeze([0, 36500]), text: 40, quote: 160, }); // `avoid`: the anchors a dodge never moves into (the streams' face cam is most often top-left). const COMMON = Object.freeze({ show: true, position: "top-left", x: null, y: null, scale: 1, hold: null, finale: "hide", onPosts: "dodge", onChapters: "dodge", avoid: Object.freeze(["top-left"]) }); /** Each module's settings and their defaults. */ export const MEASURE_DEFAULTS = Object.freeze({ // The sticky notes pile in the bottom-right corner, up for `hold` seconds // after each goal; `max` notes show, the newest in front; `color` is the // paper (default the palette's amber). // `base`: each note also says the weight he had stated when he set it, "(FROM 346.7)" (the slice's goal base). // `baseMaxDays`: a weight said more than this many days before a loss goal is not its base (measure-slice.mjs // goalBase reads it): no "(FROM …)", no target, no tick from it. null: every base counts. // `flash`: the update flash (update-flash.mjs) -- null follows deck.measure.flash, true/false for this module. goals: Object.freeze({ ...COMMON, position: "bottom-right", hold: 20, max: 4, color: null, countdown: true, base: false, baseMaxDays: null, flash: null }), // The moving start: up for `hold` seconds after each retelling. peak: Object.freeze({ ...COMMON, position: "top-right", hold: 12, title: "The start keeps moving", color: null, values: "drift" }), // The promise clock: up from the promise on, through the finale. // Another party on it (her claims: CONTRACT addendum): `speakers` names each // by ledger speaker -- `{ madamsavvy: { handle: "MadamSavvy", color } }` -- the // handle also finding her picture in the manifest's postAvatars (else a // monogram); `claimVerb` is what her claim says she did; `claimColor` her ink. promise: Object.freeze({ ...COMMON, position: "top-center", finale: "show", label: null, verb: "offered", kept: "Posted", broken: "None posted", checks: "label", speakers: Object.freeze({}), claimVerb: "paid", claimColor: "#E37AB8", slot: "auto" }), // The diet badge: up from the first diet on, re-stamped at every change. // `form` "tags" (the default on the shelf): the last `tags` diets as dated tags, the newest slammed in at the left. diet: Object.freeze({ ...COMMON, position: "bottom-left", colors: Object.freeze({}), labels: Object.freeze({}), form: "stamp", tags: 3, overlap: 0, days: false, flash: null }), // The streak chain: bottom-centre, between the diet badge and the goal // stack, so either or both can run. `title` null is the source's own word. streak: Object.freeze({ ...COMMON, position: "bottom-center", source: "diet", axis: "date", title: null, color: null, colors: Object.freeze({}), labels: Object.freeze({}) }), }); /** Each extra's anchor beside the instruments' column (resolveMeasureExtra), when its own is not named. */ // All along the foot, a size down, so the top of the clip -- where the streams' face cam is -- stays clear: // diet 308 px at the left, the streak 446 in the middle, the goals 320 at the right (48–356, 425–871, 928–1248). export const COLUMN_POSITIONS = Object.freeze({ diet: "bottom-left", streak: "bottom-center", goals: "bottom-right", peak: "top-center", promise: "top-center" }); /** Each extra's size beside the column, when its own `scale` is not named. */ export const COLUMN_SCALES = Object.freeze({ diet: 0.7, streak: 0.72, goals: 0.8 }); /** Where the promise clock stands (`promise.slot`): the instruments' column (the trail's slot), the footage box, or the column when the instruments are on. */ export const PROMISE_SLOTS = Object.freeze(["auto", "column", "footage"]); /** The four ids, in the order they are drawn. */ export const MEASURE_EXTRAS = Object.freeze(["diet", "peak", "goals", "promise", "streak"]); const isObj = (v) => v !== null && typeof v === "object" && !Array.isArray(v); const numIn = (v, lo, hi) => typeof v === "number" && Number.isFinite(v) && v >= lo && v <= hi; const HEX_RE = /^#(?:[0-9a-fA-F]{3}|[0-9a-fA-F]{6})$/; /** * A module's settings with every default filled in, or null when it is off * (`false`, or `show: false`). Absent and `true` are the defaults. * * @param {"goals" | "peak" | "promise" | "diet"} id * @param {any} render */ export function resolveMeasureExtra(id, render) { const base = MEASURE_DEFAULTS[id]; const v = render?.chrome?.deck?.[id]; if (v === false) return null; // With the dial on, the moving start repeats its ghosts: off unless it is named // (its count rides on the dial's ghost label, "told 5×"). if (id === "peak" && v === undefined && resolveDial(render)) return null; const own = isObj(v) ? v : {}; const out = { ...base, ...own }; // Beside the instruments' column the clip box is 1248×702: the anchors and sizes // that keep them clear of each other there (the diet badge beside the streak // strip, not on it) -- unless a position is named. if (instrumentsOn(render) && own.position === undefined && own.x === undefined && COLUMN_POSITIONS[id]) { out.position = COLUMN_POSITIONS[id]; if (own.scale === undefined && COLUMN_SCALES[id]) out.scale = COLUMN_SCALES[id]; } // On the shelf (`deck.shelf.items` names it, or its own position is "shelf"): its slot there, scaled to the // shelf (shelfLayout); over the finale as the shelf is; the diet as its dated tags unless a form is named. const shelf = resolveShelf(render); if (shelf && SHELF_EXTRAS.includes(id) && (shelf.items.includes(id) || own.position === SHELF_POSITION)) { out.position = SHELF_POSITION; out.finale = shelf.finale; // The shelf is a HUD: what stands on it stays up from its first event (`hold` unset), the goals too. if (own.hold === undefined) out.hold = null; if (id === "diet" && own.form === undefined) out.form = "tags"; } else if (out.position === SHELF_POSITION) { // No shelf to stand on (validateMeasureExtra says so): its default anchor, so a stray key draws something. out.position = MEASURE_DEFAULTS[id].position; } // Where the promise clock stands: the column's trail slot when the instruments are on ("auto"). if (id === "promise") out.slot = out.slot === "auto" ? (instrumentsOn(render) ? "column" : "footage") : out.slot; if (id === "diet" || id === "streak") { out.colors = { ...DIET_COLORS, ...(isObj(own.colors) ? own.colors : {}) }; out.labels = { ...DIET_LABELS, ...(isObj(own.labels) ? own.labels : {}) }; } return out.show === false ? null : out; } function text(v, max, where, errors, { nullable = true } = {}) { if (v === undefined || (nullable && v === null)) return; if (typeof v !== "string" || !v.trim()) errors.push(`${where} must be words`); else if (/[\r\n]/.test(v)) errors.push(`${where} must be one line`); else if ([...v].length > max) errors.push(`${where} is ${[...v].length} characters (at most ${max})`); } const color = (v, where, errors) => { if (v === undefined || v === null) return; if (typeof v !== "string" || !HEX_RE.test(v)) errors.push(`${where} must be a #hex colour`); }; /** * Every reason `render.chrome.deck.` cannot be drawn, as sentences (empty: * it can). `true`/`false` or an object of the module's own keys. * * @param {"goals" | "peak" | "promise" | "diet"} id * @returns {string[]} */ export function validateMeasureExtra(id, v, where = `render.chrome.deck.${id}`, { chrome = null } = {}) { if (v === undefined || typeof v === "boolean") return []; const keys = Object.keys(MEASURE_DEFAULTS[id]); if (!isObj(v)) return [`${where} must be true, false or { ${keys.join(", ")} }`]; const errors = []; const L = MEASURE_LIMITS; for (const k of Object.keys(v)) if (!keys.includes(k)) errors.push(`${where}.${k} is not a deck setting (${keys.join(", ")})`); if (v.show !== undefined && typeof v.show !== "boolean") errors.push(`${where}.show must be true or false`); const shelfOk = SHELF_EXTRAS.includes(id); if (v.position !== undefined && !MEASURE_POSITIONS.includes(v.position) && !(shelfOk && v.position === SHELF_POSITION)) { errors.push(`${where}.position must be ${[...MEASURE_POSITIONS, ...(shelfOk ? [SHELF_POSITION] : [])].map((p) => `"${p}"`).join(", ")}`); } // The shelf is a place only while there is one (`chrome` given: the deck it sits in). if (shelfOk && v.position === SHELF_POSITION && chrome && !resolveShelf({ chrome })) { errors.push(`${where}.position is "shelf", but render.chrome.deck.shelf is off (umtool look

deck.shelf=true, or another position)`); } for (const k of ["x", "y"]) { if (v[k] !== undefined && v[k] !== null && !numIn(v[k], L[k][0], L[k][1])) { errors.push(`${where}.${k} must be null or from ${L[k][0]} to ${L[k][1]} (design pixels on the 1920×1080 frame)`); } } if ((v.x === undefined || v.x === null) !== (v.y === undefined || v.y === null)) errors.push(`${where}.x and .y are set together (or neither)`); if (v.scale !== undefined && !numIn(v.scale, L.scale[0], L.scale[1])) errors.push(`${where}.scale must be from ${L.scale[0]} to ${L.scale[1]}`); // 0 (or null in the file) is "stays up from its first event on": 0 because // `umtool look … hold=null` removes the key, which is the default again. if (v.hold !== undefined && v.hold !== null && v.hold !== 0 && !numIn(v.hold, L.hold[0], L.hold[1])) { errors.push(`${where}.hold must be 0 (up from its first event on) or from ${L.hold[0]} to ${L.hold[1]} seconds`); } if (v.finale !== undefined && !MEASURE_FINALE.includes(v.finale)) errors.push(`${where}.finale must be "hide" or "show"`); if (v.avoid !== undefined && !(Array.isArray(v.avoid) && v.avoid.every((a) => MEASURE_POSITIONS.includes(a)))) { errors.push(`${where}.avoid must be a list of anchors (${MEASURE_POSITIONS.join(", ")})`); } for (const k of ["onPosts", "onChapters"]) { if (v[k] !== undefined && !MEASURE_AVOID.includes(v[k])) errors.push(`${where}.${k} must be "dodge", "hide" or "show"`); } if (id === "goals") { if (v.max !== undefined && !(Number.isInteger(v.max) && numIn(v.max, L.max[0], L.max[1]))) { errors.push(`${where}.max must be a whole number from ${L.max[0]} to ${L.max[1]}`); } color(v.color, `${where}.color`, errors); if (v.countdown !== undefined && typeof v.countdown !== "boolean") errors.push(`${where}.countdown must be true or false`); if (v.base !== undefined && typeof v.base !== "boolean") errors.push(`${where}.base must be true or false`); if (v.baseMaxDays !== undefined && v.baseMaxDays !== null && !(Number.isInteger(v.baseMaxDays) && numIn(v.baseMaxDays, L.baseMaxDays[0], L.baseMaxDays[1]))) { errors.push(`${where}.baseMaxDays must be null (every base counts) or whole days from ${L.baseMaxDays[0]} to ${L.baseMaxDays[1]}`); } } if (id === "goals" || id === "diet") { if (v.flash !== undefined && v.flash !== null && typeof v.flash !== "boolean") errors.push(`${where}.flash must be true, false or null (deck.measure.flash)`); } if (id === "peak") { text(v.title, L.text, `${where}.title`, errors, { nullable: false }); color(v.color, `${where}.color`, errors); if (v.values !== undefined && !PEAK_VALUES.includes(v.values)) errors.push(`${where}.values must be "drift" or "all"`); } if (id === "promise") { for (const k of ["label", "verb", "kept", "broken"]) text(v[k], L.text, `${where}.${k}`, errors, { nullable: k === "label" }); if (v.checks !== undefined && !PROMISE_CHECKS.includes(v.checks)) errors.push(`${where}.checks must be "label" or "quote"`); if (v.slot !== undefined && !PROMISE_SLOTS.includes(v.slot)) errors.push(`${where}.slot must be "auto", "column" or "footage"`); text(v.claimVerb, L.text, `${where}.claimVerb`, errors, { nullable: false }); color(v.claimColor, `${where}.claimColor`, errors); if (v.speakers !== undefined) { if (!isObj(v.speakers)) errors.push(`${where}.speakers must be { : { handle, color } }`); else { for (const [k, x] of Object.entries(v.speakers)) { const at = `${where}.speakers.${k}`; if (!/^[a-z0-9][a-z0-9_.-]{0,63}$/i.test(k)) { errors.push(`${at} is not a speaker key`); continue; } if (!isObj(x)) { errors.push(`${at} must be { handle, color }`); continue; } for (const kk of Object.keys(x)) if (!["handle", "color"].includes(kk)) errors.push(`${at}.${kk} is not a speaker setting (handle, color)`); if (x.handle !== undefined && !(typeof x.handle === "string" && /^@?[A-Za-z0-9_.-]{1,64}$/.test(x.handle))) errors.push(`${at}.handle must be a handle`); color(x.color, `${at}.color`, errors); } } } } if (id === "streak") { if (v.source !== undefined && !STREAK_SOURCES.includes(v.source)) errors.push(`${where}.source must be ${STREAK_SOURCES.map((x) => `"${x}"`).join(", ")}`); if (v.axis !== undefined && !STREAK_AXES.includes(v.axis)) errors.push(`${where}.axis must be "date" or "runs"`); text(v.title, L.text, `${where}.title`, errors); color(v.color, `${where}.color`, errors); } if (id === "diet") { if (v.form !== undefined && !DIET_FORMS.includes(v.form)) errors.push(`${where}.form must be "stamp" or "tags"`); if (v.tags !== undefined && !(Number.isInteger(v.tags) && numIn(v.tags, DIET_TAGS[0], DIET_TAGS[1]))) { errors.push(`${where}.tags must be a whole number from ${DIET_TAGS[0]} to ${DIET_TAGS[1]}`); } if (v.days !== undefined && typeof v.days !== "boolean") errors.push(`${where}.days must be true or false`); if (v.overlap !== undefined) { const max = dietOverlapMax(v.days === true); if (!numIn(v.overlap, DIET_OVERLAP[0], DIET_OVERLAP[1])) errors.push(`${where}.overlap must be from ${DIET_OVERLAP[0]} to ${DIET_OVERLAP[1]}`); else if (v.overlap > max) { errors.push(`${where}.overlap ${v.overlap} hides an older tag's regime word and date: they need ${DIET_BACK_MIN} of its ${dietTagWidth(v.days === true)} design px (overlap at most ${max}${v.days === true ? "" : `, or ${dietOverlapMax(true)} with days`})`); } } } if (id === "diet" || id === "streak") { for (const k of ["colors", "labels"]) { if (v[k] === undefined) continue; if (!isObj(v[k])) { errors.push(`${where}.${k} must be { : … }`); continue; } for (const [r, x] of Object.entries(v[k])) { if (!/^[a-z][a-z0-9_-]{0,23}$/.test(r)) errors.push(`${where}.${k}.${r} is not a regime key`); else if (k === "colors") color(x, `${where}.colors.${r}`, errors); else text(x, L.text, `${where}.labels.${r}`, errors, { nullable: false }); } } } return errors; }