oficina / mapa Public

Clone
git clone https://amadan.net/oficina/mapa

Plain git — no account needed to clone.

Download

Download this file

1// imagedom.mjs — how the editor draws an image (images spec §2.1,
2// §4.5): exactly the markup internal/mapa/markup/images.go writes, an
3// <img> with its box reserved or the fixed box that says it is not
4// available. Width, height and state come from a resolution, never from
5// the node (§2.3), so an image's state never makes its block count as
6// edited. A lone image (its textblock's only child) is drawn as a block
7// by the class alone, which is a node decoration (images.mjs), not part
8// of toDOM.
9
10import { ImagePrefix } from './markup.mjs'
11
12// imageSpec is one image's DOM output spec.
13export function imageSpec ({ id, alt }, answer) {
14 if (!answer?.available) {
15 return ['span', { 'mapa-image': 'unavailable' }, 'Image not available']
16 }
17 return ['img', {
18 src: ImagePrefix + id,
19 alt: alt ?? '',
20 width: String(answer.width),
21 height: String(answer.height),
22 loading: 'lazy',
23 decoding: 'async'
24 }]
25}
26
27// isAlone is whether a textblock's text is only one image, which the
28// server draws with the class alone.
29export function isAlone (textblock) {
30 return textblock.isTextblock && textblock.childCount === 1 &&
31 textblock.firstChild.type.name === 'image'
32}
33