mirror of
https://github.com/jparkerweb/plan2code.git
synced 2026-11-29 21:21:18 -08:00
Add text size buttons to the console's top bar (v3.2.1)
AI Assisted
This commit is contained in:
1 parent
8277c8b548
commit
634e4df10e
25 files changed
+188
-40
No files matched your search
@@ -207,6 +207,17 @@
|
||||
<path class="mg-line" d="M7 14.5l1.2 5h2.4l-.9-3.8M17.5 9.5a4 4 0 0 1 0 5M20 7a7.5 7.5 0 0 1 0 10" />
|
||||
</svg>
|
||||
</a>
|
||||
<!-- Text size: [-], the size (a click returns to 100%), [+]. Saved with
|
||||
the looks; the page's type tokens scale from it (tokens.css). -->
|
||||
<div class="text-size" id="text-size" role="group" aria-label="Text size">
|
||||
<button type="button" class="icon-btn" id="btn-text-smaller" title="Smaller text" aria-label="Smaller text">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 12h12" /></svg>
|
||||
</button>
|
||||
<button type="button" class="text-size-label" id="btn-text-size" title="Back to 100%" aria-label="Text size, back to 100%">100%</button>
|
||||
<button type="button" class="icon-btn" id="btn-text-larger" title="Larger text" aria-label="Larger text">
|
||||
<svg viewBox="0 0 24 24" aria-hidden="true" focusable="false"><path d="M6 12h12M12 6v12" /></svg>
|
||||
</button>
|
||||
</div>
|
||||
<!-- Activities: small games for a long wait. Opens a dialog that pauses
|
||||
the moment Plan2Code needs the person; nothing in it reaches the agent. -->
|
||||
<button type="button" class="icon-btn" id="btn-activities" title="Activities" aria-label="Activities">
|
||||
@@ -1542,6 +1553,12 @@
|
||||
The <strong>megaphone</strong> button opens Plan2Code's
|
||||
GitHub issues, where you can report a bug or suggest an idea.
|
||||
</li>
|
||||
<li>
|
||||
The <strong>[-]</strong> and <strong>[+]</strong> buttons make the
|
||||
whole page's text smaller or larger, in seven steps from 80% to 150%;
|
||||
the size between them (click it) returns to 100%. Your choice is kept, and
|
||||
Back to default on the Appearance tab resets it.
|
||||
</li>
|
||||
<li>
|
||||
The <strong>die</strong> beside it opens <strong>Activities</strong>,
|
||||
small games to play while you wait. See "Activities".
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
// `looks` is a live binding: every file reads the current object, and only
|
||||
// this file replaces it.
|
||||
|
||||
import { DEFAULT_ACCENT, soundPrefs, soundFilePrefs, DEFAULT_CARD_WIDTH, ACCENTS, accentId, cardWidth, soundKey, soundFileKey } from "./palette.js";
|
||||
import { DEFAULT_ACCENT, soundPrefs, soundFilePrefs, DEFAULT_CARD_WIDTH, DEFAULT_TEXT_SIZE, TEXT_SIZES, ACCENTS, accentId, cardWidth, textSize, soundKey, soundFileKey } from "./palette.js";
|
||||
import { normalizeRole, ROLE_NOT_SET } from "./starters.js";
|
||||
import { bootData, hooks } from "./state.js";
|
||||
import { el } from "./render.js";
|
||||
@@ -32,6 +32,8 @@ export const DEFAULT_LOOKS = {
|
||||
// Which sound file each pickable cue plays (soundFileQuestion: "sound-03").
|
||||
...soundFilePrefs(null),
|
||||
width: DEFAULT_CARD_WIDTH,
|
||||
// The top bar's text size, in percent (palette.js TEXT_SIZES).
|
||||
textSize: DEFAULT_TEXT_SIZE,
|
||||
hideUnavailable: true,
|
||||
// Skip the wake-up intro: never play the dashboard's first-open wake-up (Planny asleep), off by default.
|
||||
skipIntro: false,
|
||||
@@ -77,6 +79,7 @@ export function adoptLooks(saved) {
|
||||
Object.assign(looks, soundFilePrefs(looks));
|
||||
if (typeof looks.hideUnavailable !== "boolean") looks.hideUnavailable = DEFAULT_LOOKS.hideUnavailable;
|
||||
looks.width = cardWidth(looks.width);
|
||||
looks.textSize = textSize(looks.textSize);
|
||||
if (typeof looks.skipIntro !== "boolean") looks.skipIntro = DEFAULT_LOOKS.skipIntro;
|
||||
if (typeof looks.skillLaunched !== "boolean") looks.skillLaunched = DEFAULT_LOOKS.skillLaunched;
|
||||
if (typeof looks.meterTipSeen !== "boolean") looks.meterTipSeen = DEFAULT_LOOKS.meterTipSeen;
|
||||
@@ -190,6 +193,18 @@ const systemDark = () => matchMedia("(prefers-color-scheme: dark)").matches;
|
||||
|
||||
const effectiveTheme = () => (looks.theme === "system" ? (systemDark() ? "dark" : "light") : looks.theme);
|
||||
|
||||
// The top bar's text size control: the label says the size, and a button at an end of the range is spent.
|
||||
function paintTextSize() {
|
||||
const at = TEXT_SIZES.indexOf(looks.textSize);
|
||||
const label = $("btn-text-size");
|
||||
if (!label) return;
|
||||
label.textContent = looks.textSize + "%";
|
||||
// The accessible name replaces the visible text, so it carries the size too.
|
||||
label.setAttribute("aria-label", `Text size ${looks.textSize}%, back to 100%`);
|
||||
$("btn-text-smaller").setAttribute("aria-disabled", String(at <= 0));
|
||||
$("btn-text-larger").setAttribute("aria-disabled", String(at >= TEXT_SIZES.length - 1));
|
||||
}
|
||||
|
||||
export function applyLooks() {
|
||||
const root = document.documentElement;
|
||||
// The desktop app's shell wears this page's theme and highlight: the resolved
|
||||
@@ -208,6 +223,9 @@ export function applyLooks() {
|
||||
// Before the accent's early return, so a default accent never skips it.
|
||||
if (looks.width === DEFAULT_CARD_WIDTH) root.removeAttribute("data-width");
|
||||
else root.dataset.width = looks.width;
|
||||
if (looks.textSize === DEFAULT_TEXT_SIZE) root.removeAttribute("data-text-size");
|
||||
else root.dataset.textSize = String(looks.textSize);
|
||||
paintTextSize();
|
||||
|
||||
// The default lives in the stylesheet, where it is written once per theme.
|
||||
// Clearing the override is how it gets its own values back.
|
||||
|
||||
@@ -249,6 +249,17 @@ export function cardWidth(value) {
|
||||
return typeof value === "string" && Object.hasOwn(CARD_WIDTHS, value) ? value : DEFAULT_CARD_WIDTH;
|
||||
}
|
||||
|
||||
// The text size steps, in percent, for the top bar's [-] and [+]. Here for the
|
||||
// same reason the card widths are: the page validates a saved `looks.textSize`
|
||||
// with textSize(), and the server paints the first-load `data-text-size`.
|
||||
export const TEXT_SIZES = [80, 90, 100, 110, 120, 135, 150];
|
||||
|
||||
export const DEFAULT_TEXT_SIZE = 100;
|
||||
|
||||
export function textSize(value) {
|
||||
return TEXT_SIZES.includes(value) ? value : DEFAULT_TEXT_SIZE;
|
||||
}
|
||||
|
||||
// The sound files a person can give a cue, sound-01 to sound-19, served from
|
||||
// /sounds/<name>.mp3 (static.mjs).
|
||||
export const SOUND_FILES = Array.from({ length: 19 }, (_, i) => `sound-${String(i + 1).padStart(2, "0")}`);
|
||||
|
||||
@@ -25,7 +25,7 @@ export function prefsOpenTab(asked) {
|
||||
// The looks keys Back to default resets on a tab, or null where it has
|
||||
// nothing to reset (and is hidden).
|
||||
export function prefsResetScope(tab) {
|
||||
if (tab === "appearance") return ["theme", "width", "accent", "role", "skipIntro"];
|
||||
if (tab === "appearance") return ["theme", "width", "textSize", "accent", "role", "skipIntro"];
|
||||
if (tab === "sounds") return ["sound", ...Object.keys(SOUND_EVENTS).map(soundKey), ...PICKABLE_SOUNDS.map(soundFileKey), "hideActivities", "activitySounds", "gameMusic"];
|
||||
return null;
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import { adoptLooks, applyLooks, loadLooks, looks, renderSwatches, saveLooks, sy
|
||||
import { dropHeldSound, previewSound, releaseHeldSound, sound, soundOn } from "../sound.js";
|
||||
import { hushTones, tone, unlockTones } from "../tones.js";
|
||||
import { hushMusic } from "../music.js";
|
||||
import { SOUND_EVENTS, soundFileKey, soundKey } from "../palette.js";
|
||||
import { DEFAULT_TEXT_SIZE, SOUND_EVENTS, TEXT_SIZES, soundFileKey, soundKey } from "../palette.js";
|
||||
import { ROLES, ROLE_NOT_SET, ROLE_NOT_SET_LABEL, needsRoleNudge, normalizeRole } from "../starters.js";
|
||||
import { isDashboard } from "../selectors.js";
|
||||
import { el } from "../render.js";
|
||||
@@ -63,6 +63,19 @@ export function wireLooks() {
|
||||
hooks.markSaved(fieldsetOf(radio), saveLooks());
|
||||
});
|
||||
}
|
||||
// The top bar's text size: one step each way, the label back to 100%.
|
||||
const stepText = (by) => {
|
||||
const at = TEXT_SIZES.indexOf(looks.textSize) + by;
|
||||
if (at < 0 || at >= TEXT_SIZES.length) return;
|
||||
looks.textSize = TEXT_SIZES[at];
|
||||
saveLooks();
|
||||
};
|
||||
$("btn-text-smaller").addEventListener("click", () => stepText(-1));
|
||||
$("btn-text-larger").addEventListener("click", () => stepText(1));
|
||||
$("btn-text-size").addEventListener("click", () => {
|
||||
looks.textSize = DEFAULT_TEXT_SIZE;
|
||||
saveLooks();
|
||||
});
|
||||
for (const radio of document.querySelectorAll('input[name="looks-width"]')) {
|
||||
radio.addEventListener("change", () => {
|
||||
looks.width = radio.value;
|
||||
|
||||
@@ -28,6 +28,28 @@
|
||||
.icon-btn:hover svg .ab-dot, .icon-btn:hover svg .dc-pip { fill: var(--accent); stroke: none; }
|
||||
|
||||
a.icon-btn { box-sizing: border-box; text-decoration: none; }
|
||||
|
||||
/* The text size control: [-] size [+], one group in the tools. The label is the
|
||||
reset, so it reads as text and gets the same hover as an icon. */
|
||||
.text-size { display: flex; align-items: center; gap: 0; }
|
||||
.text-size-label {
|
||||
appearance: none;
|
||||
min-width: 44px;
|
||||
height: 36px;
|
||||
padding: 0 4px;
|
||||
border: 1px solid transparent;
|
||||
border-radius: var(--radius-md);
|
||||
background: transparent;
|
||||
color: var(--ink-2);
|
||||
font: 600 var(--fs-xs)/1 var(--sans);
|
||||
font-variant-numeric: tabular-nums;
|
||||
cursor: pointer;
|
||||
}
|
||||
.text-size-label:hover { background: var(--panel-2); border-color: var(--rule); color: var(--accent); }
|
||||
/* An end of the range: dimmed, not disabled, so Playwright and keyboards still reach it. */
|
||||
.text-size .icon-btn[aria-disabled="true"] { opacity: 0.4; cursor: default; }
|
||||
.text-size .icon-btn[aria-disabled="true"]:hover { background: transparent; border-color: transparent; }
|
||||
.text-size .icon-btn[aria-disabled="true"]:hover svg * { stroke: var(--ink-2); }
|
||||
/* A link in a dialog (the update modal's release, Help's version) keeps the
|
||||
accent once visited: the browser's purple is unreadable on the dark theme. */
|
||||
.modal a:not(.btn), .modal a:not(.btn):visited { color: var(--accent); }
|
||||
|
||||
@@ -76,17 +76,19 @@
|
||||
/* The column's width: the card, the pager and the documents. */
|
||||
--card-width: 880px;
|
||||
/* Type: text steps, h1 to h4, one poster size; weights 400, 600, 700 only. */
|
||||
--fs-2xs: 11px;
|
||||
--fs-xs: 12px;
|
||||
--fs-sm: 13px;
|
||||
--fs-md: 14px;
|
||||
--fs-base: 15px;
|
||||
--fs-lg: 17px;
|
||||
--fs-h4: 16px;
|
||||
--fs-h3: 18px;
|
||||
--fs-h2: 21px;
|
||||
--fs-h1: 25px;
|
||||
--fs-poster: 38px;
|
||||
--fs-2xs: calc(11px * var(--text-scale));
|
||||
--fs-xs: calc(12px * var(--text-scale));
|
||||
--fs-sm: calc(13px * var(--text-scale));
|
||||
--fs-md: calc(14px * var(--text-scale));
|
||||
--fs-base: calc(15px * var(--text-scale));
|
||||
--fs-lg: calc(17px * var(--text-scale));
|
||||
--fs-h4: calc(16px * var(--text-scale));
|
||||
--fs-h3: calc(18px * var(--text-scale));
|
||||
--fs-h2: calc(21px * var(--text-scale));
|
||||
--fs-h1: calc(25px * var(--text-scale));
|
||||
--fs-poster: calc(38px * var(--text-scale));
|
||||
/* The top bar's text size: 1 until [data-text-size] says otherwise (rules below). */
|
||||
--text-scale: 1;
|
||||
--lh-tight: 1.25;
|
||||
--lh-ui: 1.4;
|
||||
--lh-body: 1.55;
|
||||
@@ -101,6 +103,12 @@
|
||||
:root[data-width="narrow"] { --card-width: 720px; }
|
||||
:root[data-width="wide"] { --card-width: 1080px; }
|
||||
:root[data-width="ultrawide"] { --card-width: 1440px; }
|
||||
:root[data-text-size="80"] { --text-scale: 0.8; }
|
||||
:root[data-text-size="90"] { --text-scale: 0.9; }
|
||||
:root[data-text-size="110"] { --text-scale: 1.1; }
|
||||
:root[data-text-size="120"] { --text-scale: 1.2; }
|
||||
:root[data-text-size="135"] { --text-scale: 1.35; }
|
||||
:root[data-text-size="150"] { --text-scale: 1.5; }
|
||||
|
||||
/* Dark is written twice on purpose. The first copy follows the system unless
|
||||
light was chosen; the second is the explicit ask. Without the `:not()` a
|
||||
|
||||
Reference in new issue
Block a user