From 0537ddcdfcd27475d7b3c2717eb34f2a32d99a30 Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:39:29 +0530 Subject: [PATCH 1/8] Add a check that every character on the site is in its self-hosted font --- scripts/check-site-glyphs.mjs | 227 ++++++++++++++++++++++++++++++++++ 1 file changed, 227 insertions(+) create mode 100644 scripts/check-site-glyphs.mjs diff --git a/scripts/check-site-glyphs.mjs b/scripts/check-site-glyphs.mjs new file mode 100644 index 0000000..b3ae870 --- /dev/null +++ b/scripts/check-site-glyphs.mjs @@ -0,0 +1,227 @@ +// Fails when the site shows a character that none of its self-hosted fonts contain. +// Such a character falls back to whatever font the visitor's device has, so it can +// come out in another size or style on each phone. Run: node scripts/check-site-glyphs.mjs +// +// It serves site/, walks the page in Chromium at desktop and phone sizes (with a +// touch screen, so the touch wording is checked too) through every story step and +// panel, and checks each rendered character against the cmap of the @font-face file +// its font-family list would use. +import { createServer } from "node:http"; +import { readFileSync, existsSync, statSync } from "node:fs"; +import { extname, join, normalize } from "node:path"; +import { brotliDecompressSync } from "node:zlib"; +import { chromium } from "playwright-core"; + +const SITE = new URL("../site/", import.meta.url).pathname; + +/* ---------- the characters a woff2 file maps ---------- */ +function readBase128(bytes, at) { + let value = 0; + for (let n = 0; n < 5; n++) { + const b = bytes[at.pos++]; + value = value * 128 + (b & 0x7f); + if (!(b & 0x80)) return value; + } + throw new Error("bad UIntBase128"); +} + +function woff2Codepoints(path) { + const file = readFileSync(path); + if (file.toString("latin1", 0, 4) !== "wOF2") throw new Error(`${path} is not woff2`); + const numTables = file.readUInt16BE(12); + const compressedSize = file.readUInt32BE(20); + const at = { pos: 48 }; + const tables = []; + for (let t = 0; t < numTables; t++) { + const flags = file[at.pos++]; + const tagIndex = flags & 0x3f; + if (tagIndex === 63) at.pos += 4; + const version = flags >> 6; + const origLength = readBase128(file, at); + const glyfOrLoca = tagIndex === 10 || tagIndex === 11; + const transformed = glyfOrLoca ? version !== 3 : version !== 0; + const length = transformed ? readBase128(file, at) : origLength; + tables.push({ tagIndex, length }); + } + const sfnt = brotliDecompressSync(file.subarray(at.pos, at.pos + compressedSize)); + let offset = 0; + for (const table of tables) { + if (table.tagIndex === 0) return cmapCodepoints(sfnt, offset); + offset += table.length; + } + throw new Error(`${path} has no cmap`); +} + +function cmapCodepoints(buf, cmap) { + const points = new Set(); + const count = buf.readUInt16BE(cmap + 2); + for (let r = 0; r < count; r++) { + const sub = cmap + buf.readUInt32BE(cmap + 4 + r * 8 + 4); + const format = buf.readUInt16BE(sub); + if (format === 4) { + const segs = buf.readUInt16BE(sub + 6) / 2; + const ends = sub + 14, starts = ends + segs * 2 + 2, deltas = starts + segs * 2, ranges = deltas + segs * 2; + for (let s = 0; s < segs; s++) { + const end = buf.readUInt16BE(ends + s * 2), start = buf.readUInt16BE(starts + s * 2); + const delta = buf.readInt16BE(deltas + s * 2), rangeAt = ranges + s * 2, range = buf.readUInt16BE(rangeAt); + for (let c = start; c <= end && c !== 0xffff; c++) { + const glyph = range === 0 ? (c + delta) & 0xffff : buf.readUInt16BE(rangeAt + range + (c - start) * 2); + if (glyph) points.add(c); + } + } + } else if (format === 12) { + const groups = buf.readUInt32BE(sub + 12); + for (let g = 0; g < groups; g++) { + const start = buf.readUInt32BE(sub + 16 + g * 12), end = buf.readUInt32BE(sub + 20 + g * 12); + for (let c = start; c <= end; c++) points.add(c); + } + } + } + return points; +} + +/* ---------- which font a character in a given font-family list lands in ---------- */ +const inRanges = (ranges, c) => !ranges || ranges.some(([a, b]) => c >= a && c <= b); + +function makeResolver(faces) { + const cmaps = new Map(); + const cmapOf = face => { + if (!cmaps.has(face.file)) cmaps.set(face.file, woff2Codepoints(join(SITE, face.file))); + return cmaps.get(face.file); + }; + // The face of a family closest to the weight asked for, as the browser picks it. + const faceFor = (family, weight) => { + const own = faces.filter(f => f.family === family); + const distance = f => (weight >= f.weight[0] && weight <= f.weight[1] ? 0 : Math.min(Math.abs(weight - f.weight[0]), Math.abs(weight - f.weight[1]))); + return own.sort((a, b) => distance(a) - distance(b)); + }; + // The self-hosted font that draws c, or null when the device's own fallback would. + return (c, families, weight) => { + for (const family of families) { + const candidates = faceFor(family, weight).filter(f => inRanges(f.ranges, c)); + if (!candidates.length) { + if (faces.some(f => f.family === family)) continue; + return null; + } + if (cmapOf(candidates[0]).has(c)) return candidates[0].file; + } + return null; + }; +} + +/* ---------- the page ---------- */ +const TYPES = { ".html": "text/html", ".css": "text/css", ".js": "text/javascript", ".svg": "image/svg+xml", ".woff2": "font/woff2", ".png": "image/png", ".jpg": "image/jpeg" }; +const server = createServer((req, res) => { + let path = normalize(join(SITE, decodeURIComponent(new URL(req.url, "http://x").pathname))); + if (!path.startsWith(SITE) || !existsSync(path)) { res.writeHead(404).end(); return; } + if (statSync(path).isDirectory()) path = join(path, "index.html"); + res.writeHead(200, { "content-type": TYPES[extname(path)] || "application/octet-stream" }); + res.end(readFileSync(path)); +}); +await new Promise(done => server.listen(0, "127.0.0.1", done)); +const url = `http://127.0.0.1:${server.address().port}/`; + +// Every rendered text run on the page now: its text, font-family list and weight. +function collectRuns() { + const runs = []; + const families = s => s.fontFamily.split(",").map(f => f.trim().replace(/^["']|["']$/g, "")); + const visible = el => el.checkVisibility ? el.checkVisibility({ visibilityProperty: true }) : true; + const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT); + for (let n = walker.nextNode(); n; n = walker.nextNode()) { + const el = n.parentElement; + if (!n.data.trim() || !el || !visible(el) || el.closest("script, style")) continue; + const s = getComputedStyle(el); + runs.push({ text: n.data, families: families(s), weight: +s.fontWeight, where: el.className || el.tagName.toLowerCase() }); + } + for (const el of document.querySelectorAll("*")) { + for (const pseudo of ["::before", "::after"]) { + const s = getComputedStyle(el, pseudo); + const m = s.content.match(/^"(.+)"$/); + if (m && visible(el)) runs.push({ text: m[1], families: families(s), weight: +s.fontWeight, where: `${el.className || el.tagName.toLowerCase()}${pseudo}` }); + } + } + return runs; +} + +function readFaces() { + const faces = []; + for (const sheet of document.styleSheets) { + for (const rule of sheet.cssRules) { + if (!(rule instanceof CSSFontFaceRule)) continue; + const st = rule.style; + const weight = (st.getPropertyValue("font-weight") || "400").split(/\s+/).map(Number); + const range = st.getPropertyValue("unicode-range"); + faces.push({ + family: st.getPropertyValue("font-family").replace(/^["']|["']$/g, ""), + weight: [weight[0], weight[1] ?? weight[0]], + file: st.getPropertyValue("src").match(/url\("?([^")]+)"?\)/)[1].replace(location.origin + "/", ""), + ranges: range ? range.split(",").map(r => r.trim().replace(/^U\+/i, "").split("-").map(h => parseInt(h, 16))).map(([a, b]) => [a, b ?? a]) : null, + }); + } + } + return faces; +} + +const browser = await chromium.launch(); +const runs = []; +let faces; +const VIEWS = [ + { name: "desktop", viewport: { width: 1440, height: 900 } }, + { name: "phone", viewport: { width: 390, height: 844 }, isMobile: true, hasTouch: true }, +]; +for (const view of VIEWS) { + const page = await browser.newPage(view); + const errors = []; + page.on("pageerror", e => errors.push(e.message)); + await page.goto(url); + await page.evaluate(() => document.fonts.ready); + faces ??= await page.evaluate(readFaces); + const grab = async label => { for (const r of await page.evaluate(collectRuns)) runs.push({ ...r, view: `${view.name} ${label}` }); }; + await grab("top"); + const steps = await page.evaluate(() => __story.steps.length); + for (let i = 0; i < steps; i++) { + await page.evaluate(i => __story.steps[i].scrollIntoView({ block: "center" }), i); + await page.waitForFunction(i => __story.settled() && __story.active() === i, i, { timeout: 10000 }).catch(() => {}); + await page.waitForTimeout(150); + await grab(`step ${i + 1}`); + // Open what each step's panel can show: every lint reason and every trim. + for (const sel of ["#storyNote .vk-lint.is-on", "#storyNote [data-trim]"]) { + const count = await page.locator(sel).count(); + for (let k = 0; k < count; k++) { + await page.evaluate(([sel, k]) => document.querySelectorAll(sel)[k].click(), [sel, k]); + await page.waitForTimeout(100); + await grab(`step ${i + 1} after ${sel}`); + } + } + } + await page.evaluate(() => document.querySelector(".step:not([hidden]) .step-clip").click()); + await grab("clip open"); + if (errors.length) throw new Error(`page errors at ${view.name}: ${errors.join("; ")}`); + await page.close(); +} +await browser.close(); +server.close(); + +const resolve = makeResolver(faces); +const missing = new Map(); +const usage = new Map(); +for (const run of runs) { + for (const ch of run.text) { + const c = ch.codePointAt(0); + if (c === 0x0a || c === 0x09 || c === 0x0d) continue; + const file = resolve(c, run.families, run.weight); + if (file) { usage.set(file, (usage.get(file) || 0) + 1); continue; } + const key = `U+${c.toString(16).toUpperCase().padStart(4, "0")} ${ch} in ${run.families[0]} ${run.weight}`; + if (!missing.has(key)) missing.set(key, new Set()); + missing.get(key).add(`${run.where} (${run.view})`); + } +} + +console.log(`checked ${runs.length} text runs; characters per font file:`); +for (const [file, n] of usage) console.log(` ${file}: ${n}`); +if (missing.size) { + console.log(`\n${missing.size} characters fall back to the device's own fonts:`); + for (const [key, where] of missing) console.log(` ${key}: ${[...where].slice(0, 3).join("; ")}`); + process.exit(1); +} +console.log("every character is in the self-hosted font it is set in"); From b38839f5575df796fadd3db69aeb4465fa45a65b Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:39:29 +0530 Subject: [PATCH 2/8] Draw arrows, Cmd, Shift and the caret as icons so every device shows them the same Courier Prime and Reenie Beanie don't have these characters, so each phone fell back to its own font and sizes. Keys are now one height whatever they hold. The Lab count and install step use words instead of an arrow. --- site/index.html | 46 +++++++++++++++++++++++++++------------------- site/note.js | 22 ++++++++++++---------- site/style.css | 20 ++++++++++++++++---- 3 files changed, 55 insertions(+), 33 deletions(-) diff --git a/site/index.html b/site/index.html index 6911713..19aee3c 100644 --- a/site/index.html +++ b/site/index.html @@ -35,6 +35,14 @@ + + +
Vikalp

+

try: click an underlined word

+

In Obsidian: J ·

  • Fade, don’t delete

    -

    Fade a sentence instead of deleting it. It stays readable, leaves the word count, and comes back with a click.

    -

    try: click the faded line

    -

    In Obsidian: ⌘. then G ·

    +

    Fade a sentence instead of deleting it. It stays readable, leaves the word count, and comes back with a click.

    +

    try: click the faded line

    +

    In Obsidian: . then G ·

  • Keep what you cut

    Move a line to Overflow, a side panel kept with the note. Put it back when it fits.

    -

    try: click the ‸ to put it back

    -

    In Obsidian: ⌘. then S ·

    +

    try: click the to put it back

    +

    In Obsidian: . then S ·

  • Ideas when you’re stuck

    Ask AI for a few other ways to say a word or a sentence. They sit next to your own versions, marked with a robot, and you decide what fits. Your note only changes when you pick one.

    -

    try: pick a robot version

    -

    In Obsidian: ⌘⇧J ·

    +

    try: pick a robot version

    +

    In Obsidian: J ·

  • Lint when you ask

    Check your note for hedging, wordy phrases, passive voice and AI-sounding lines. Edit the rules or write your own.

    -

    try: click a wavy line

    -

    In Obsidian: ⌘. then L ·

    +

    try: click a wavy line

    +

    In Obsidian: . then L ·

  • The Lab

    Ask a model to mark typos and weak sentences, or to strike what it would cut. You keep or cut each one.

    -

    try: click a struck phrase

    -

    In Obsidian: ⌘. then T ·

    +

    try: click a struck phrase

    +

    In Obsidian: . then T ·

  • Read it clean

    Hide every marker and read your note the way a reader will.

    -

    try: switch it off

    -

    In Obsidian: ⌘. then R ·

    +

    try: switch it off

    +

    In Obsidian: . then R ·

  • @@ -144,8 +152,8 @@

    Get Vikalp

    Install in Obsidian
      -
    1. 1.In Obsidian, open Settings → Community plugins and search for Vikalp.
    2. -
    3. 2.Put the cursor on a word and press ⌘J.
    4. +
    5. 1.In Obsidian, open Settings, then Community plugins, and search for Vikalp.
    6. +
    7. 2.Put the cursor on a word and press J.
    8. 3.For AI features, add a key for OpenRouter, Anthropic or OpenAI, or run a model locally with Ollama or LM Studio. Everything else works offline.
    diff --git a/site/note.js b/site/note.js index 891149d..9e34745 100644 --- a/site/note.js +++ b/site/note.js @@ -34,12 +34,14 @@ window.Vikalp = (() => { }; const EASE = 'cubic-bezier(.2, .7, .2, 1)'; const robot = () => ''; + const tap = matchMedia('(hover: none)').matches ? 'Tap' : 'Click'; document.body.insertAdjacentHTML('afterbegin', ``); - /* ← → go to the focused span, or else the hovered one */ + /* Left and right arrows go to the focused span, or else the hovered one */ let hovered = null; document.addEventListener('keydown', e => { if (e.key !== 'ArrowLeft' && e.key !== 'ArrowRight') return; @@ -307,7 +309,7 @@ window.Vikalp = (() => { return r; } - // a cut line: in the text, or in Overflow with a red ‸ where it was + // a cut line: in the text, or in Overflow with a red caret where it was r.type = 'cut'; r.live = false; r.on = false; @@ -319,7 +321,7 @@ window.Vikalp = (() => { r.state = state; el.className = state === 'back' ? 'vk-cut-back' : ''; el.innerHTML = r.on - ? '' + ? '' : esc(seg.cut); } const caret = el.querySelector('.vk-caret'); @@ -332,8 +334,8 @@ window.Vikalp = (() => { /* Moving a line to Overflow and back. One motion at a time: the line leaves as a card that flies to Overflow, then its paragraph closes - around a ‸. Going back, the paragraph opens a space for the line while - the card flies to the ‸ and shrinks into it; only once the card is gone + around a caret. Going back, the paragraph opens a space for the line while + the card flies to the caret and shrinks into it; only once the card is gone does the line fade in, so the two copies never show at once. */ // Where the line starts in the text, kept inside the note so the card never hangs over the panel. function spot(el, width) { @@ -353,7 +355,7 @@ window.Vikalp = (() => { const left = Math.max(box.left - inset, Math.min(rows[0].left - inset, box.right - size.width + inset)); return { left, top: rows[rows.length - 1].bottom - size.height }; } - // Where the ‸ stood: the restored line's first character, less the card's inset. + // Where the caret stood: the restored line's first character, less the card's inset. function caretSpot(el, card) { const row = el.getClientRects()[0]; const style = getComputedStyle(card); @@ -412,7 +414,7 @@ window.Vikalp = (() => { } function renderLint() { const r = note.lintShown; - if (!r || !r.live()) { lintBox.innerHTML = '

    Click a wavy line to see why it’s marked.

    '; return; } + if (!r || !r.live()) { lintBox.innerHTML = `

    ${tap} a wavy line to see why it’s marked.

    `; return; } lintBox.innerHTML = `

    ${esc(r.seg.rule)}

    ${esc(r.seg.why)}

    ` + (r.seg.fix ? `
    ` : ''); } @@ -420,7 +422,7 @@ window.Vikalp = (() => { host.querySelectorAll('[data-trim]').forEach(b => b.setAttribute('aria-pressed', String(+b.dataset.trim === note.trim))); const struck = recs.filter(r => r.type === 'strike' && r.struck()); const before = after + struck.reduce((n, r) => n + countWords(r.seg.strike), 0); - host.querySelector('.vk-trimnums').textContent = note.trim ? `${before} → ${after} words` : 'Pick a trim to see what a model would cut.'; + host.querySelector('.vk-trimnums').textContent = note.trim ? `${before} words, cut to ${after}` : 'Pick a trim to see what a model would cut.'; } panel.addEventListener('click', e => { @@ -447,8 +449,8 @@ window.Vikalp = (() => { host.querySelector('.vk-wc').textContent = plural(count, 'word', 'words'); host.querySelector('.vk-state').textContent = extra.length ? ' · ' + extra.join(' · ') : ''; host.querySelector('.vk-fadebox').textContent = faded - ? 'The faded line stays in the note and leaves the word count. Tap it to bring it back.' - : 'The line is back in the word count. Tap it to fade it again.'; + ? `The faded line stays in the note and leaves the word count. ${tap} it to bring it back.` + : `The line is back in the word count. ${tap} it to fade it again.`; renderVersions(); renderOverflow(); renderLint(); diff --git a/site/style.css b/site/style.css index 77e1da9..5b056f1 100644 --- a/site/style.css +++ b/site/style.css @@ -123,9 +123,20 @@ a { color: inherit; } .wrap--wide { max-width: var(--col-wide); } .hand { font: 400 var(--hand-size)/1.1 var(--hand); letter-spacing: 0.02em; color: var(--blue); } .keys { white-space: nowrap; } +/* Every key is the same height and sits on the text's baseline, whether it holds a letter or an icon. */ kbd { - font: 400 var(--step--2)/1 var(--mono); color: var(--ink-2); - border: 1px solid var(--rule-strong); border-radius: 2px; padding: 2px 5px; white-space: nowrap; + display: inline-block; min-width: 1.9em; text-align: center; vertical-align: baseline; + font: 400 var(--step--2)/1.45 var(--mono); color: var(--ink-2); + border: 1px solid var(--rule-strong); border-radius: 2px; padding: 0 5px; white-space: nowrap; +} +/* icons drawn in place of characters the fonts don't have, sized to the text around them */ +.ic { display: inline-block; width: 0.95em; height: 0.95em; vertical-align: -0.12em; overflow: visible; } +kbd .ic + .ic { margin-left: 1px; } +.step-try .ic-caret { color: var(--red); width: 0.7em; height: 0.7em; vertical-align: 0; } +.hint .for-touch { display: none; } +@media (hover: none) { + .hint .for-touch { display: inline; } + .hint .for-pointer { display: none; } } /* ---------- top bar ---------- */ @@ -302,7 +313,7 @@ h2 { font: 700 var(--step-3)/1.15 var(--mono); letter-spacing: -0.025em; margin: .install-steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 20px; } .install-steps li { display: grid; grid-template-columns: 2.4ch 1fr; gap: 14px; font: 400 18px/1.6 var(--mono); } .install-steps b { color: var(--blue); } -.install-steps kbd { font: inherit; font-weight: 700; color: inherit; border: 0; padding: 0; } +.install-steps kbd { display: inline; min-width: 0; font: inherit; font-weight: 700; color: inherit; border: 0; padding: 0; } footer.wrap { padding-block: 48px 56px; font: 400 var(--step--1)/1.5 var(--mono); color: var(--ink-3); } footer .end { margin: 0 0 28px; letter-spacing: 0.6em; } @@ -400,9 +411,10 @@ footer a:hover { color: var(--ink); text-decoration-color: var(--blue); } .vk-strike.is-armed { cursor: pointer; } .vk-strike.is-struck { color: var(--ink-2); background-size: 100% 2px; } .vk-caret { - font: 400 1.3em/1 var(--hand); color: var(--red); background: none; border: 0; padding: 0 0.2em; margin: 0 -0.1em; cursor: pointer; vertical-align: -0.15em; + font: inherit; line-height: 1; color: var(--red); background: none; border: 0; padding: 0 0.15em; margin: 0 -0.05em; cursor: pointer; transition: opacity var(--dur-slow); } +.vk-caret svg { display: inline-block; width: 0.85em; height: 0.85em; vertical-align: -0.05em; } /* blue pencil: lint marks */ .vk-lint { From 67c79efc94c9e93655e2f8a1276464126d9951ac Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:39:29 +0530 Subject: [PATCH 3/8] Say tap instead of hover and click on touch screens --- site/page.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/site/page.js b/site/page.js index a03fc83..7071b0c 100644 --- a/site/page.js +++ b/site/page.js @@ -168,8 +168,12 @@ const frame = noteHost.querySelector('.vk-frame'); let active = -1, raf = 0; + // Touch screens tap rather than click. Only text is rewritten, so icons in a hint stay. if (matchMedia('(hover: none)').matches) { - document.querySelectorAll('.step-try').forEach(p => { p.textContent = p.textContent.replace(/\bclick\b/g, 'tap'); }); + document.querySelectorAll('.say-tap').forEach(p => { + const walker = document.createTreeWalker(p, NodeFilter.SHOW_TEXT); + for (let n = walker.nextNode(); n; n = walker.nextNode()) n.data = n.data.replace(/\bclick\b/g, 'tap').replace(/\bClick\b/g, 'Tap'); + }); } // The phone caption: a copy of each phone step, stacked in one cell so the From ec6e96e78e5c8777610331bf0f8893aad3a2c7a3 Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:44:57 +0530 Subject: [PATCH 4/8] Add a soft wooden tap for swapping versions --- site/sound.js | 77 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 site/sound.js diff --git a/site/sound.js b/site/sound.js new file mode 100644 index 0000000..6531f08 --- /dev/null +++ b/site/sound.js @@ -0,0 +1,77 @@ +/* A soft wooden tap when the visitor swaps a version: a short rounded knock with a + little paper on top, about 60 ms, peaking near -18 dBFS. Synthesised, so there is + no file to load. + + window.VikalpSound = { play(), on } + play() taps once, at most every 60 ms, with a ±3% change in pitch so repeats + don't sound mechanical. Call it only from the visitor's own click or key press: + browsers start audio only then. + on is the visitor's choice, kept in localStorage; it starts on. */ +window.VikalpSound = (() => { + const KEY = 'vk-sound'; + const GAIN = 0.145; + let on = true; + try { on = localStorage.getItem(KEY) !== 'off'; } catch (e) {} + let ctx = null, last = -Infinity, noise = null; + + function envelope(t, attack, decay, peak) { + const g = ctx.createGain(); + g.gain.setValueAtTime(0, t); + g.gain.linearRampToValueAtTime(peak, t + attack); + g.gain.exponentialRampToValueAtTime(0.0001, t + attack + decay); + return g; + } + + function tap(pitch) { + const t = ctx.currentTime + 0.005; + const out = ctx.createGain(); + out.gain.value = GAIN; + const warm = ctx.createBiquadFilter(); + warm.type = 'lowpass'; + warm.frequency.value = 2600; + warm.connect(out).connect(ctx.destination); + + const knock = ctx.createOscillator(); + knock.frequency.setValueAtTime(620 * pitch, t); + knock.frequency.exponentialRampToValueAtTime(410 * pitch, t + 0.03); + knock.connect(envelope(t, 0.002, 0.075, 0.8)).connect(warm); + knock.start(t); + knock.stop(t + 0.1); + + noise ??= (() => { + const b = ctx.createBuffer(1, Math.ceil(ctx.sampleRate * 0.02), ctx.sampleRate); + const d = b.getChannelData(0); + for (let i = 0; i < d.length; i++) d[i] = Math.random() * 2 - 1; + return b; + })(); + const paper = ctx.createBufferSource(); + paper.buffer = noise; + const band = ctx.createBiquadFilter(); + band.type = 'bandpass'; + band.frequency.value = 2000 * pitch; + band.Q.value = 0.7; + paper.connect(band).connect(envelope(t, 0.001, 0.012, 0.35)).connect(warm); + paper.start(t); + } + + function play() { + if (!on) return; + const now = performance.now(); + if (now - last < 60) return; + last = now; + try { + ctx ??= new AudioContext(); + if (ctx.state === 'suspended') ctx.resume(); + tap(1 + (Math.random() * 2 - 1) * 0.03); + } catch (e) {} + } + + return { + play, + get on() { return on; }, + set on(value) { + on = !!value; + try { localStorage.setItem(KEY, on ? 'on' : 'off'); } catch (e) {} + }, + }; +})(); From 65921104f7e02e1a5a3dffb8af030792bc02e6bf Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:44:57 +0530 Subject: [PATCH 5/8] Play the tap when the visitor swaps a version, with a sound toggle in the header --- site/index.html | 16 ++++++++++++---- site/note.js | 3 +++ site/page.js | 12 +++++++++++- site/style.css | 2 ++ 4 files changed, 28 insertions(+), 5 deletions(-) diff --git a/site/index.html b/site/index.html index 19aee3c..c0ed584 100644 --- a/site/index.html +++ b/site/index.html @@ -41,14 +41,21 @@ + +
    Vikalp - +
    + + +
    @@ -173,6 +180,7 @@

    Get Vikalp

    + diff --git a/site/note.js b/site/note.js index 9e34745..0a03aa5 100644 --- a/site/note.js +++ b/site/note.js @@ -5,6 +5,8 @@ createSpan(el, versions, opts) turns an element into a span with versions. versions: ['a', 'b', 'ai:c'] (an "ai:" prefix marks an AI version) opts: { kind, onChange(span), onEnter(span), onLeave(span), disabled() } + A swap fires a bubbling "vk-swap" event on el right away, inside the click or + key press that caused it. Only the visitor swaps; nothing in the note does. createNote(host, data) renders a note and wires every interaction. data: { title, paragraphs: [[segment, ...], ...] } @@ -88,6 +90,7 @@ window.Vikalp = (() => { if (k === span.i) return; span.prev = span.i; span.i = k; + el.dispatchEvent(new CustomEvent('vk-swap', { bubbles: true })); paintDots(); const d = ms('--dur-fast'); clearTimeout(timer); diff --git a/site/page.js b/site/page.js index 7071b0c..c4fb604 100644 --- a/site/page.js +++ b/site/page.js @@ -1,4 +1,4 @@ -/* Page wiring: the theme toggle, the hero word, the scroll story and the clip lightbox. */ +/* Page wiring: the theme and sound toggles, the hero word, the scroll story and the clip lightbox. */ (() => { const root = document.documentElement; const theme = () => (root.dataset.theme === 'dark' ? 'dark' : 'light'); @@ -16,6 +16,16 @@ new MutationObserver(paintThemeLabel).observe(root, { attributes: true, attributeFilter: ['data-theme'] }); paintThemeLabel(); + /* ---------- sound: a soft tap when the visitor swaps a version ---------- */ + const soundBtn = document.getElementById('soundBtn'); + const paintSound = () => { + soundBtn.setAttribute('aria-pressed', String(VikalpSound.on)); + soundBtn.querySelector('use').setAttribute('href', VikalpSound.on ? '#ic-sound-on' : '#ic-sound-off'); + }; + soundBtn.addEventListener('click', () => { VikalpSound.on = !VikalpSound.on; paintSound(); }); + paintSound(); + document.addEventListener('vk-swap', () => VikalpSound.play()); + /* ---------- hero: one word, its other versions pencilled above it ---------- */ const heroAlts = document.getElementById('heroAlts'); const paintAlts = span => { diff --git a/site/style.css b/site/style.css index 5b056f1..35f7350 100644 --- a/site/style.css +++ b/site/style.css @@ -150,6 +150,8 @@ kbd .ic + .ic { margin-left: 1px; } } .theme-btn:hover { color: var(--ink); border-color: var(--ink-2); } .theme-btn svg { width: 14px; height: 14px; } +.top-actions { display: flex; gap: 8px; } +.sound-btn { padding-inline: 10px; } /* ---------- hero ---------- */ .hero { padding-block: clamp(48px, 8vh, 88px) clamp(64px, 10vh, 112px); } From 39e166c9d4c842da8749ed5dbf6e3e261a613238 Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:57:29 +0530 Subject: [PATCH 6/8] Drop the sound toggle; the tap only plays on the visitor's own swap --- site/index.html | 15 ++++----------- site/page.js | 15 ++++----------- site/sound.js | 22 +++++----------------- 3 files changed, 13 insertions(+), 39 deletions(-) diff --git a/site/index.html b/site/index.html index c0ed584..1747f02 100644 --- a/site/index.html +++ b/site/index.html @@ -41,21 +41,14 @@ - -
    Vikalp -
    - - -
    +
    diff --git a/site/page.js b/site/page.js index c4fb604..42bdac5 100644 --- a/site/page.js +++ b/site/page.js @@ -1,4 +1,4 @@ -/* Page wiring: the theme and sound toggles, the hero word, the scroll story and the clip lightbox. */ +/* Page wiring: the theme toggle, the swap sound, the hero word, the scroll story and the clip lightbox. */ (() => { const root = document.documentElement; const theme = () => (root.dataset.theme === 'dark' ? 'dark' : 'light'); @@ -13,17 +13,10 @@ root.dataset.theme = theme() === 'dark' ? 'light' : 'dark'; try { localStorage.setItem('vk-theme', root.dataset.theme); } catch (e) {} }); - new MutationObserver(paintThemeLabel).observe(root, { attributes: true, attributeFilter: ['data-theme'] }); - paintThemeLabel(); + new MutationObserver(paintThemeBtn).observe(root, { attributes: true, attributeFilter: ['data-theme'] }); + paintThemeBtn(); - /* ---------- sound: a soft tap when the visitor swaps a version ---------- */ - const soundBtn = document.getElementById('soundBtn'); - const paintSound = () => { - soundBtn.setAttribute('aria-pressed', String(VikalpSound.on)); - soundBtn.querySelector('use').setAttribute('href', VikalpSound.on ? '#ic-sound-on' : '#ic-sound-off'); - }; - soundBtn.addEventListener('click', () => { VikalpSound.on = !VikalpSound.on; paintSound(); }); - paintSound(); + /* ---------- a soft tap when the visitor swaps a version ---------- */ document.addEventListener('vk-swap', () => VikalpSound.play()); /* ---------- hero: one word, its other versions pencilled above it ---------- */ diff --git a/site/sound.js b/site/sound.js index 6531f08..95f4f9e 100644 --- a/site/sound.js +++ b/site/sound.js @@ -2,16 +2,12 @@ little paper on top, about 60 ms, peaking near -18 dBFS. Synthesised, so there is no file to load. - window.VikalpSound = { play(), on } - play() taps once, at most every 60 ms, with a ±3% change in pitch so repeats - don't sound mechanical. Call it only from the visitor's own click or key press: - browsers start audio only then. - on is the visitor's choice, kept in localStorage; it starts on. */ + window.VikalpSound = { play() } + play() taps once, at most every 60 ms, with a 3% change in pitch either way so + repeats don't sound mechanical. Call it only from the visitor's own click or key + press: browsers start audio only then, and the page never plays sound by itself. */ window.VikalpSound = (() => { - const KEY = 'vk-sound'; const GAIN = 0.145; - let on = true; - try { on = localStorage.getItem(KEY) !== 'off'; } catch (e) {} let ctx = null, last = -Infinity, noise = null; function envelope(t, attack, decay, peak) { @@ -55,7 +51,6 @@ window.VikalpSound = (() => { } function play() { - if (!on) return; const now = performance.now(); if (now - last < 60) return; last = now; @@ -66,12 +61,5 @@ window.VikalpSound = (() => { } catch (e) {} } - return { - play, - get on() { return on; }, - set on(value) { - on = !!value; - try { localStorage.setItem(KEY, on ? 'on' : 'off'); } catch (e) {} - }, - }; + return { play }; })(); From 3c3c2985c153b5da92781b48f85fd22d2d3a1fdd Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:57:30 +0530 Subject: [PATCH 7/8] Make the theme toggle an icon: a sun in dark mode, a moon in light --- site/page.js | 11 ++++++++--- site/style.css | 16 +++++++++++----- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/site/page.js b/site/page.js index 42bdac5..bbafc6a 100644 --- a/site/page.js +++ b/site/page.js @@ -7,9 +7,14 @@ const wait = d => new Promise(done => setTimeout(done, d)); /* ---------- theme toggle ---------- */ - const themeLabel = document.getElementById('themeLabel'); - const paintThemeLabel = () => { themeLabel.textContent = theme() === 'dark' ? 'Light' : 'Dark'; }; - document.getElementById('themeBtn').addEventListener('click', () => { + // The button shows where it goes: a sun in dark mode, a moon in light mode. + const themeBtn = document.getElementById('themeBtn'); + const paintThemeBtn = () => { + const label = `Switch to ${theme() === 'dark' ? 'light' : 'dark'} theme`; + themeBtn.setAttribute('aria-label', label); + themeBtn.title = label; + }; + themeBtn.addEventListener('click', () => { root.dataset.theme = theme() === 'dark' ? 'light' : 'dark'; try { localStorage.setItem('vk-theme', root.dataset.theme); } catch (e) {} }); diff --git a/site/style.css b/site/style.css index 35f7350..097c217 100644 --- a/site/style.css +++ b/site/style.css @@ -144,14 +144,20 @@ kbd .ic + .ic { margin-left: 1px; } .wordmark { font: 700 22px/1 var(--mono); letter-spacing: -0.01em; text-decoration: none; display: inline-flex; align-items: baseline; gap: 10px; } .wordmark small { font: 300 19px/1 var(--hand-deva); color: var(--blue); transform: rotate(-4deg) translateY(-3px); display: inline-block; } .theme-btn { - font: 400 var(--step--1)/1 var(--mono); color: var(--ink-2); background: none; border: 1px solid var(--rule-strong); - padding: 8px 12px; border-radius: 2px; cursor: pointer; display: inline-flex; gap: 8px; align-items: center; + position: relative; width: 38px; height: 38px; padding: 0; flex: none; + color: var(--ink-2); background: none; border: 1px solid var(--rule-strong); border-radius: 2px; cursor: pointer; transition: color var(--dur), border-color var(--dur); } .theme-btn:hover { color: var(--ink); border-color: var(--ink-2); } -.theme-btn svg { width: 14px; height: 14px; } -.top-actions { display: flex; gap: 8px; } -.sound-btn { padding-inline: 10px; } +/* both icons sit in one place; switching crossfades and turns them a little. The page itself flips at once. */ +.theme-btn svg { + position: absolute; inset: 0; margin: auto; width: 18px; height: 18px; + transition: opacity 160ms var(--ease), transform 160ms var(--ease); +} +.theme-btn .theme-sun, :root[data-theme="dark"] .theme-btn .theme-moon { opacity: 0; transform: rotate(-45deg); } +:root[data-theme="dark"] .theme-btn .theme-sun { opacity: 1; transform: none; } +@media (prefers-reduced-motion: reduce) { .theme-btn svg { transition: none; } } +@media (max-width: 860px), (pointer: coarse) { .theme-btn { width: 44px; height: 44px; } } /* ---------- hero ---------- */ .hero { padding-block: clamp(48px, 8vh, 88px) clamp(64px, 10vh, 112px); } From d0d8b5c4874ba9820ec00778c714c6090f84a86d Mon Sep 17 00:00:00 2001 From: Tushar Tripathi Date: Sun, 1 Nov 2026 20:57:30 +0530 Subject: [PATCH 8/8] Ease the hero word's width on a swap so the next word glides --- site/note.js | 34 ++++++++++++++++++++++++++++++++-- site/page.js | 2 +- site/style.css | 21 +++++++++++++++++++-- 3 files changed, 52 insertions(+), 5 deletions(-) diff --git a/site/note.js b/site/note.js index 0a03aa5..fa5c6fb 100644 --- a/site/note.js +++ b/site/note.js @@ -4,7 +4,9 @@ createSpan(el, versions, opts) turns an element into a span with versions. versions: ['a', 'b', 'ai:c'] (an "ai:" prefix marks an AI version) - opts: { kind, onChange(span), onEnter(span), onLeave(span), disabled() } + opts: { kind, glide, onChange(span), onEnter(span), onLeave(span), disabled() } + With glide, a swap eases the span's width from the old version to the new one, + so the text after it moves along instead of jumping. For a span on one line. A swap fires a bubbling "vk-swap" event on el right away, inside the click or key press that caused it. Only the visitor swaps; nothing in the note does. @@ -70,7 +72,8 @@ window.Vikalp = (() => { el.innerHTML = ''; const text = el.querySelector('.vk-v-text'); const dots = el.querySelector('.vk-dots'); - let timer = 0; + let timer = 0, widthAnim = null; + if (opts.glide) el.classList.add('vk-glide'); const paintDots = () => { dots.innerHTML = versions.map((v, k) => ``).join(''); @@ -92,6 +95,7 @@ window.Vikalp = (() => { span.i = k; el.dispatchEvent(new CustomEvent('vk-swap', { bubbles: true })); paintDots(); + if (opts.glide) { glide(); return; } const d = ms('--dur-fast'); clearTimeout(timer); const done = () => { paintText(); text.classList.remove('is-swapping'); opts.onChange && opts.onChange(span); }; @@ -99,6 +103,32 @@ window.Vikalp = (() => { text.classList.add('is-swapping'); timer = setTimeout(done, d); }; + // The old version lifts out on top while the new one settles in below it, and + // the slot between them eases to the new width. A swap during a swap starts + // from wherever the width and the fading text are, so nothing jumps. + function glide() { + const d = ms('--dur-glide'); + const from = el.getBoundingClientRect().width; + const leaving = text.cloneNode(true); + leaving.className = 'vk-v-out'; + leaving.style.opacity = getComputedStyle(text).opacity; + if (widthAnim) widthAnim.cancel(); + text.getAnimations().forEach(a => a.cancel()); + el.querySelectorAll('.vk-v-out').forEach(o => o.remove()); + el.style.width = ''; + paintText(); + opts.onChange && opts.onChange(span); + if (!d) return; + const to = el.getBoundingClientRect().width; + el.prepend(leaving); + const lift = '-0.16em', settle = '0.16em'; + leaving.animate([{ transform: 'none' }, { opacity: 0, transform: `translateY(${lift})` }], { duration: d * 0.45, easing: 'ease-out', fill: 'forwards' }) + .finished.then(() => leaving.remove(), () => leaving.remove()); + text.animate([{ opacity: 0, transform: `translateY(${settle})` }, { opacity: 1, transform: 'none' }], { duration: d * 0.6, delay: d * 0.4, easing: EASE, fill: 'backwards' }); + widthAnim = el.animate([{ width: from + 'px' }, { width: to + 'px' }], { duration: d, easing: EASE }); + widthAnim.finished.then(() => { widthAnim = null; }, () => {}); + } + span.step = d => span.set(span.i + d); span.pick = k => span.set(k); span.add = v => { versions.push(v); paintDots(); }; diff --git a/site/page.js b/site/page.js index bbafc6a..de9cdb2 100644 --- a/site/page.js +++ b/site/page.js @@ -38,7 +38,7 @@ return [b]; })); }; - paintAlts(Vikalp.createSpan(document.getElementById('heroWord'), ['right', 'exact', 'plain', 'true'], { onChange: paintAlts })); + paintAlts(Vikalp.createSpan(document.getElementById('heroWord'), ['right', 'exact', 'plain', 'true'], { glide: true, onChange: paintAlts })); /* ---------- the story's note ---------- */ const noteHost = document.getElementById('storyNote'); diff --git a/site/style.css b/site/style.css index 097c217..9668bcf 100644 --- a/site/style.css +++ b/site/style.css @@ -65,6 +65,7 @@ --dur-fast: 140ms; /* version crossfade */ --dur: 220ms; /* hovers, small fades */ --dur-slow: 420ms; /* each story change */ + --dur-glide: 260ms; /* the hero word's slot easing to a new width */ --ease: cubic-bezier(.2, .7, .2, 1); } :root[data-theme="dark"] { @@ -97,10 +98,10 @@ --grain-blend: soft-light; } @media (prefers-reduced-motion: reduce) { - :root { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; } + :root { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; --dur-glide: 0ms; } } /* the story skipping past several steps at once */ -:root.vk-instant { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; } +:root.vk-instant { --dur-fast: 0ms; --dur: 0ms; --dur-slow: 0ms; --dur-glide: 0ms; } /* ---------- page ---------- */ * { box-sizing: border-box; } @@ -193,6 +194,9 @@ h1 .line { display: block; } /* the hero word is a note span, scaled up */ h1 .vk-v { text-decoration-thickness: 3px; text-underline-offset: 0.16em; text-decoration-skip-ink: none; } h1 .vk-anchor .vk-dots { top: calc(100% + 0.06em); gap: 6px; right: 0.04em; } +/* the slot's underline and dots where the text's own underline and dots were */ +h1 .vk-glide::after { height: 3px; bottom: calc(0.28em - 3px); } +h1 .vk-glide .vk-anchor { bottom: 0.1em; } h1 .vk-dots i { width: 9px; height: 9px; border-width: 1.5px; } h2 { font: 700 var(--step-3)/1.15 var(--mono); letter-spacing: -0.025em; margin: 0; } @@ -339,6 +343,8 @@ footer a:hover { color: var(--ink); text-decoration-color: var(--blue); } .alts { font-size: 24px; } h1 .vk-dots i { width: 6px; height: 6px; border-width: 1px; } h1 .vk-anchor .vk-dots { gap: 4px; top: calc(100% + 0.06em); } + h1 .vk-glide::after { bottom: calc(0.41em - 3px); } + h1 .vk-glide .vk-anchor { bottom: 0.21em; } .kicker { font-size: 14px; margin-bottom: 20px; } .lede { font-size: 18px; margin-top: 28px; } .actions { margin-top: 28px; } @@ -394,6 +400,17 @@ footer a:hover { color: var(--ink); text-decoration-color: var(--blue); } .vk-v:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; } .vk-v-text { transition: opacity var(--dur-fast) ease-out; } .vk-v-text.is-swapping { opacity: 0; } +/* a gliding span: one line whose box eases between widths. The underline and dots + belong to the box, so they follow it; the leaving version sits on top of the new one. */ +.vk-glide { display: inline-block; position: relative; white-space: nowrap; vertical-align: baseline; text-decoration: none; } +.vk-glide .vk-v-text { display: inline-block; } +.vk-glide .vk-v-out { position: absolute; left: 0; top: 0; pointer-events: none; } +.vk-glide::after { + content: ""; position: absolute; left: 0; right: 0; bottom: var(--glide-line, 0.12em); height: 1.5px; + background: var(--blue-soft); transition: background-color var(--dur-slow) var(--ease); +} +.vk-glide:hover::after, .vk-glide:focus-visible::after, .vk-glide.is-active::after { background: var(--blue); } +.vk-glide .vk-anchor { position: absolute; right: 0; top: 0; bottom: 0; } /* an empty inline anchor: unlike an inline-block, it adds no line break before trailing punctuation */ .vk-anchor { position: relative; } .vk-anchor .vk-dots { position: absolute; right: 0; top: calc(100% + 0.22em); }