// chips.mjs — how the editor draws a [[link]], a date link and an embed // (spec §4.2): the DOM output specs internal/mapa/markup/chips.go writes // as HTML. Gate L4 compares the two byte for byte. A chip's state (team, // alias, pending, gone) is never an attribute of the node: it comes from // a resolution, the same answer the server's resolver gives (§6.8). const SVG = 'http://www.w3.org/2000/svg' // glyphs are chips.go's: Lucide's strokes on a 24px grid. const glyphs = { page: ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4', 'M9 13h6', 'M9 17h4'], 'page-plus': ['M15 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7Z', 'M14 2v4a2 2 0 0 0 2 2h4', 'M9 15h6', 'M12 12v6'], calendar: ['M8 2v4', 'M16 2v4', 'M5 4h14a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2Z', 'M3 10h18'], block: ['M13 4v16', 'M17 4v16', 'M19 4H9.5a4.5 4.5 0 0 0 0 9H13'], embed: ['M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z', 'm3.3 7 8.7 5 8.7-5', 'M12 22V12'] } export function glyph (name) { return [`${SVG} svg`, { 'mapa-i': '', viewBox: '0 0 24 24', 'aria-hidden': 'true' }, ...glyphs[name].map(path => [`${SVG} path`, { d: path }])] } // pageIcon is a page's icon in a chip's glyph cell (columns and icons // spec §2.4), as chips.go's iconHTML draws it. export function pageIcon (look) { if (look?.emoji) { return ['span', { 'mapa-i': '', 'mapa-icon': '', 'aria-hidden': 'true' }, look.emoji] } if (look?.image && /^[0-9a-z]{1,13}$/u.test(look.image)) { return ['img', { 'mapa-i': '', 'mapa-icon': '', src: `/i/${look.image}`, alt: '', width: '16', height: '16', loading: 'lazy', decoding: 'async' }] } return null } function chip ({ href, kind, title, label, icon, look, shown, note }) { const attrs = { href, 'mapa-chip': kind } if (title) attrs.title = title attrs['aria-label'] = label const spec = ['a', attrs, pageIcon(look) || glyph(icon), shown] if (note) spec.push(['span', { 'mapa-chip-note': '' }, note]) return spec } // wikiChip is a [[link]]: target, anchor and shown text as typed, and // the resolution the server gave for them. export function wikiChip ({ target, anchor, shown: typed }, answer) { const shown = typed || target if (answer.broken) return ['span', { 'mapa-chip': 'broken' }, shown] if (answer.day) return dateChip(typed, answer) if (answer.pending) { return chip({ href: answer.href, kind: 'pending', icon: 'page-plus', shown, label: `${shown}, page not written yet` }) } const title = answer.title || target const parts = { href: answer.href, kind: 'team', icon: 'page', shown, label: `${shown}, team page`, look: answer.icon } if (answer.alias) { parts.title = `Now called ${title}` parts.label = `${shown}, now called ${title}` } if (anchor) { parts.kind = parts.icon = 'block' parts.look = null parts.label = `${shown}, a block in ${title}` } if (anchor && answer.blockGone) { parts.kind = 'block gone' parts.label = `${shown}, block removed from ${title}` parts.note = 'block removed' } return chip(parts) } // dateChip is a date link: the day in words, never the ISO date. export function dateChip (shown, answer) { if (shown) { return chip({ href: answer.href, kind: 'date', icon: 'calendar', shown, label: `${shown}, your note for ${answer.day}` }) } return chip({ href: answer.href, kind: 'date', icon: 'calendar', shown: answer.day, label: `${answer.day}, your note` }) } // embedChip is slice 1's embed: a quiet chip showing the reference. export function embedChip (ref) { return ['span', { 'mapa-chip': 'embed', role: 'img', 'aria-label': `${ref}, embedded item, not shown yet` }, glyph('embed'), ref] }