// imagedom.mjs — how the editor draws an image (images spec §2.1, // §4.5): exactly the markup internal/mapa/markup/images.go writes, an // with its box reserved or the fixed box that says it is not // available. Width, height and state come from a resolution, never from // the node (§2.3), so an image's state never makes its block count as // edited. A lone image (its textblock's only child) is drawn as a block // by the class alone, which is a node decoration (images.mjs), not part // of toDOM. import { ImagePrefix } from './markup.mjs' // imageSpec is one image's DOM output spec. export function imageSpec ({ id, alt }, answer) { if (!answer?.available) { return ['span', { 'mapa-image': 'unavailable' }, 'Image not available'] } return ['img', { src: ImagePrefix + id, alt: alt ?? '', width: String(answer.width), height: String(answer.height), loading: 'lazy', decoding: 'async' }] } // isAlone is whether a textblock's text is only one image, which the // server draws with the class alone. export function isAlone (textblock) { return textblock.isTextblock && textblock.childCount === 1 && textblock.firstChild.type.name === 'image' }