// Server-rendered pages. Plain template strings over supram's classes; the // project's own rules live in public/style.css. import { statSync } from 'node:fs'; import { humanBytes, shortId } from './tiles.js'; // The stylesheet is cached for a day; its address changes when it does, so // that new markup never meets an old stylesheet. const STYLE_V = Math.round(statSync(new URL('../public/style.css', import.meta.url)).mtimeMs).toString(36); export const esc = (s) => String(s ?? '').replace(/[&<>"']/g, (c) => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' })[c]); const attr = esc; const SITE = 'appmosphe.re'; // Path segments: encoded, but a DID keeps its colons so URLs stay readable. export const seg = (s) => encodeURIComponent(s).replace(/%3A/gi, ':'); export function fmtDate(iso) { if (!iso) return ''; const d = new Date(iso); if (Number.isNaN(d.getTime())) return ''; return d.toISOString().slice(0, 10); } function timeEl(iso, { derived = false } = {}) { if (!iso) return 'undated'; const title = derived ? `${iso} (from the record key; the record has no createdAt)` : iso; return ``; } export const actorOf = (t) => t.handle || t.did; export const tileHref = (t) => `/@${seg(actorOf(t))}/${seg(t.rkey)}`; export const authorHref = (t) => `/@${seg(actorOf(t))}`; export const imgHref = (did, cid) => `/img/${seg(did)}/${seg(cid)}`; const authorName = (t) => t.displayName || t.handle || t.did; const MARK = ``; const NAV = [ ['/feed', 'Feed'], ['/tiles', 'Tiles'], ['/authors', 'Authors'], ['/publish', 'Publish'], ['/developers', 'Developers'], ['/about', 'About'], ]; export function layout({ title, description, body, path = '/', q = '', stats, config, image, scripts = [] }) { const full = title ? `${title} · ${SITE}` : `${SITE} — Web Tiles on the Atmosphere`; const desc = description || 'Browse the Web Tiles published on the AT Protocol: find tiles by name, description, or author.'; const canonical = `${config.publicUrl}${path}`; const section = `/${path.split('/')[1] || ''}`; return ` ${esc(full)} ${image ? `` : ''} ${scripts.map((s) => ``).join('\n ')}
${body}
`; } // --- pieces ----------------------------------------------------------------- function thumb(t, { size = 'card' } = {}) { const pic = t.screenshots?.[0] || t.icon; const style = t.backgroundColor ? ` style="--tile-bg: ${attr(t.backgroundColor)}"` : ''; if (pic) { return ``; } const letter = (t.name || '?').trim().charAt(0).toUpperCase() || '?'; return `${esc(letter)}`; } export function tileCard(t) { return `
${thumb(t)}

${esc(shortId(actorOf(t), t.rkey))}

${esc(t.name || 'Untitled tile')}

${t.description ? `

${esc(t.description)}

` : ''}
`; } export function tileGrid(tiles, { min = '17rem' } = {}) { if (!tiles.length) return '

No tiles here yet.

'; return `
${tiles.map(tileCard).join('\n')}
`; } export function pager({ page, pages, base }) { if (pages <= 1) return ''; const link = (p, label, rel) => `${label}`; return ``; } function avatar(a, size = 48) { if (a?.avatar) return ``; const letter = (a?.displayName || a?.handle || '?').charAt(0).toUpperCase(); return `${esc(letter)}`; } // --- pages ------------------------------------------------------------------ export function homePage({ latest, categories, stats }) { return `

Web Tiles on the Atmosphere

Little web apps, published to your own repo.

Tiles are self-contained web docs and apps that run safely anywhere, from a chat to a feed. ${SITE} finds the ones published on the AT Protocol and runs them.

Latest tiles

The feed → All tiles →
${tileGrid(latest)}

Find more

Search

By name, description, or author.

Browse

${stats.tiles} tiles from ${stats.authors} authors so far.

The feed: every tile, newest first →

Everyone who has published one →

${categories.length ? `

${categories.slice(0, 12).map((c) => `${esc(c.category)} ${c.n}`).join(' ')}

` : ''}

Publish

Post a tile from a .tile file or a directory, straight from your browser to your repo.

Publish a tile →

Build with tiles →

Not seeing a tile that exists? Ask for its repo to be indexed.

`; } // --- the feed ----------------------------------------------------------------- const HEART = ''; const RIBBON = ''; // Like and bookmark. The buttons come disabled and social.js wakes them: // both write records to the signed-in account's repo from the browser. // A like points at one version of the record (a strongRef), so a tile // whose record CID the index doesn't have can't be liked. export function tileActions(t) { return `
`; } function feedItem(t) { const pic = t.screenshots?.[0] || t.icon; const letter = (t.name || '?').trim().charAt(0).toUpperCase() || '?'; const height = Math.max(200, Math.min(720, t.height || 480)); const style = [`--stage-h: ${height}px`, t.width ? `--tile-w: ${t.width}px` : '', t.backgroundColor ? `--tile-bg: ${attr(t.backgroundColor)}` : ''].filter(Boolean).join('; '); const name = esc(t.name || 'Untitled tile'); return `

${avatar(t, 32)}${esc(authorName(t))} ${t.handle ? `@${esc(t.handle)} · ` : ''}${timeEl(t.createdAt, { derived: t.createdAtDerived })}

${name}

${t.description ? `

${esc(t.description)}

` : ''}
${tileActions(t)} Open tile →
`; } // A run of feed items and, when there are older ones, the link to them. // This is both the body of the feed page and the fragment its script // fetches: the link is what gets followed as the page scrolls. export function feedItems({ tiles, next }) { return `${tiles.map(feedItem).join('\n')} ${next ? `

` : ''}`; } export function feedPage({ tiles, next, view, paged }) { const tab = (v, href, label) => `${label}`; const empty = { bookmarks: 'Tiles you bookmark turn up here.', likes: 'Tiles you like turn up here.' }[view]; return `

${{ latest: 'Feed', bookmarks: 'Bookmarks', likes: 'Liked' }[view]}

${view === 'latest' ? `Every tile, newest first.${paged ? ' Back to the newest' : ''}` : ''}

${view === 'latest' ? feedItems({ tiles, next }) : `

${empty}

`}

`; } export function tilesPage({ tiles, page, pages, total, category }) { const base = category ? `/tiles?category=${encodeURIComponent(category)}` : '/tiles'; return `

${category ? `Tiles in ${esc(category)}` : 'All tiles'}

${total} ${total === 1 ? 'tile' : 'tiles'}
${tileGrid(tiles)} ${pager({ page, pages, base })}`; } export function searchPage({ q, tiles, page, pages, total }) { return `

Search

${q ? `

${total} ${total === 1 ? 'result' : 'results'} for ${esc(q)}${total ? '' : '. Try fewer words, or an author handle.'}

` : '

Type something to search tile names, descriptions, categories, and authors. Pasting an at:// URI or a short ID like @robin.berjon.com/3meis42djm22d jumps straight to the tile.

'} ${q ? tileGrid(tiles) : ''} ${pager({ page, pages, base: `/search?q=${encodeURIComponent(q)}` })}`; } function cidCode(cid) { if (!cid) return '—'; return `${esc(cid)}`; } export function tilePage({ tile: t, author, config, prevTile, pds }) { const actor = actorOf(t); const id = shortId(actor, t.rkey); const pics = t.screenshots?.length ? t.screenshots : []; const kv = []; if (t.width && t.height) kv.push(['Size', `${t.width} × ${t.height}`]); if (t.themeColor) kv.push(['Theme colour', ` ${esc(t.themeColor)}`]); if (t.backgroundColor) kv.push(['Background', ` ${esc(t.backgroundColor)}`]); kv.push(['Resources', `${t.resourceCount} ${t.resourceCount === 1 ? 'file' : 'files'}${t.totalSize ? `, ${humanBytes(t.totalSize)}` : ''}`]); kv.push(['Published', timeEl(t.createdAt, { derived: t.createdAtDerived })]); kv.push(['Indexed', timeEl(t.indexedAt)]); if (t.shape === 'manifest') kv.push(['Record shape', 'bare MASL manifest']); const height = Math.max(200, Math.min(1400, t.height || 480)); const runStyle = [t.width ? `--tile-w: ${t.width}px` : '', t.backgroundColor ? `--tile-bg: ${attr(t.backgroundColor)}` : ''].filter(Boolean).join('; '); return `

@${esc(actor)}/${esc(t.rkey)}

${esc(t.name || 'Untitled tile')}

Loading the tile…

${t.description ? `

${esc(t.description)}

` : ''} ${t.categories.length ? `

${t.categories.map((c) => `${esc(c)}`).join(' ')}

` : ''}

${avatar(author ?? t, 40)}${esc(authorName(author ?? t))}${t.handle ? `
@${esc(t.handle)}` : ''}

${tileActions(t)}

Copy at:// link View record ↗ JSON ${t.handle ? `Publish a new version` : ''}

Short ID
${esc(id)}
AT URI
${esc(t.uri)}
${kv.map(([k, v]) => `
${k}
${v}
`).join('\n')}
Manifest CID
${cidCode(t.manifestCid)}
Record CID
${cidCode(t.recordCid)}
${t.prev ? `
Previous
${prevTile ? `${esc(prevTile.name || shortId(actorOf(prevTile), prevTile.rkey))} ` : ''}${cidCode(t.prev)}
` : ''}
${pics.length || t.icon ? `

${pics.length ? 'Screenshots' : 'Icon'}

` : ''} ${pics.length ? `
${pics.map((p) => `${attr(p.label || 'Screenshot')}`).join('')}
` : ''} ${t.icon ? `

${esc(t.icon.path)}

` : ''}

Resources

${(t.record ? describeResources(t) : []).map((r) => ``).join('\n')}
PathTypeSizeCID
${esc(r.path)}${Object.keys(r.headers).length ? `
${Object.entries(r.headers).map(([k, v]) => `${esc(k)}: ${esc(v)}`).join(' · ')}` : ''}
${esc(r.contentType || '—')}${humanBytes(r.size)}${cidCode(r.cid)}
Raw record
${esc(JSON.stringify(t.record, null, 2))}
`; } // The resources table is rebuilt from the stored record, so the page always // shows what the record says rather than a second copy of it. function describeResources(t) { const manifest = t.record?.tile?.resources ? t.record.tile : t.record; const out = []; for (const [path, meta] of Object.entries(manifest?.resources ?? {})) { if (!meta || typeof meta !== 'object') continue; const src = meta.src && typeof meta.src === 'object' ? meta.src : null; out.push({ path, cid: src?.ref?.$link ?? src?.$link ?? (typeof meta.src === 'string' ? meta.src : null), contentType: typeof meta['content-type'] === 'string' ? meta['content-type'] : null, size: typeof src?.size === 'number' ? src.size : null, headers: Object.fromEntries(Object.entries(meta).filter(([k, v]) => k !== 'src' && k !== 'content-type' && typeof v === 'string')), }); } out.sort((a, b) => (a.path === '/' ? -1 : b.path === '/' ? 1 : a.path.localeCompare(b.path))); return out; } export function authorPage({ author, tiles, repo, pending }) { const a = author; const handle = a.handle; const bsky = `https://bsky.app/profile/${seg(handle || a.did)}`; const p = a.profile; const counts = p ? [[p.followersCount, 'followers'], [p.followsCount, 'following'], [p.postsCount, 'posts']].filter(([n]) => typeof n === 'number') : []; return `
${avatar(a, 96)}

${esc(a.displayName || handle || a.did)}

${handle ? `@${esc(handle)}` : ''}${p?.pronouns ? ` · ${esc(p.pronouns)}` : ''} · ${esc(a.did)}

${p?.description ? `

${esc(p.description)}

` : a.error ? `

No Bluesky profile${repo?.pds ? `; account on ${esc(new URL(repo.pds).host)}` : ''}.

` : ''}

${counts.map(([n, l]) => `${n} ${l}`).join(' ')} ${tiles.length} ${tiles.length === 1 ? 'tile' : 'tiles'}

Bluesky profile ↗ Repo records ↗ JSON

${pending ? `

Indexing requested. Tiles from this account will appear here once its repo has been synced, usually within a minute; reload to check.

` : ''}

Tiles

${tileGrid(tiles)}
`; } export function authorsPage({ authors }) { return `

Authors

${authors.length} ${authors.length === 1 ? 'account has' : 'accounts have'} published tiles
${authors.map((a) => ` ${avatar(a, 48)} ${esc(a.displayName || a.handle || a.did)} ${a.handle ? `@${esc(a.handle)}` : esc(a.did)} ${a.tileCount} ${a.tileCount === 1 ? 'tile' : 'tiles'} · latest ${fmtDate(a.latestAt) || 'undated'} `).join('\n')}
`; } export function indexPage({ result, error, recent }) { return `

Index wishes

Get a repo indexed

${SITE} watches the network for ing.dasl.masl records, so new tiles turn up by themselves. If yours hasn't, or you'd like it synced right now, ask here.

${error ? `

${esc(error)}

` : ''} ${result ? `

Tracking @${esc(result.handle || result.did)}. ${result.count ? `${result.count} ${result.count === 1 ? 'tile is' : 'tiles are'} indexed: see them.` : `Nothing indexed yet; tiles appear on the author page once the repo has been synced.`}

` : ''}

A handle, a DID, a Bluesky profile URL, or any at:// URI in the repo.

Programmatically

curl -X POST https://${SITE}/api/index \\
  -H 'content-type: application/json' \\
  -d '{"actor": "robin.berjon.com"}'

Returns { did, handle, tiles, url }; 400 if the account can't be resolved. Please keep it to a few requests a minute.

`; } export function publishPage({ config }) { return `

Publish

Post a tile to your repo

From a .tile carball or a tile source directory. Everything happens in your browser: resources go to your PDS as blobs, and the manifest becomes an ing.dasl.masl record signed by your account.

1 · Account

Loading…

2 · Tile

Preview

Running from memory, nothing uploaded yet.

3 · Manifest

4 · Record

Will be published at

Record preview

Each blob reference is replaced by the one your PDS answers the upload with, whose mimeType is the type it stored the blob under.

Blobs upload first; the record is written last.


    

Nothing you load here leaves your browser until you press Publish, and then it goes to your own PDS only; ${SITE} just gets told to index the result. To update a tile you published elsewhere, choose it under "Update one of my tiles" and prev is filled in for you. Developing locally? Use http://127.0.0.1 rather than localhost, so the loopback OAuth client's origin matches.

`; } export function developersPage({ config }) { const code = (s) => `
${esc(s)}
`; return `

Developers

Building with Web Tiles

What a tile is on AT, the tools that make, run and publish them, and how to put all of that in your own app.

The model

A tile is a bundle of web resources described by a MASL manifest in bundle mode: a name, a resources map from paths to content-addressed blobs with their HTTP headers (at least content-type), and the usual web-app-manifest extras (description, icons, screenshots, categories, theme_color, background_color, sizing). The / entry is what gets rendered. When it runs, a tile can only load what its manifest lists; the embedding app mediates everything else. The Web Tiles spec has the details, including the CSP that a tile execution context must enforce.

On AT, a tile is a record in the ing.dasl.masl collection of its author's repository. Each resource is uploaded as a blob, and the manifest's src entries are blob refs, so the PDS keeps the blobs alive:

${code(`{ "$type": "ing.dasl.masl", "cid": "bafyrei…", // the DRISL (dag-cbor) CID of "tile" "createdAt": "2026-10-02T15:26:26.697Z", "tile": { "name": "Cosmic Junkyard", "description": "Dodge falling dice…", "sizing": { "width": 720, "height": 520 }, "icons": [{ "src": "/icon.png" }], "screenshots": [{ "src": "/shot.png" }], "prev": { "$link": "bafyrei…" }, // optional: manifest CID of the version this replaces "resources": { "/": { "src": { "$type": "blob", "ref": { "$link": "bafkrei…" }, "mimeType": "application/octet-stream", "size": 50720 }, "content-type": "text/html; charset=utf-8" }, "/icon.png": { "src": { …, "mimeType": "image/png" }, "content-type": "image/png" } } } }`)}

Making tiles

A tile source directory is just index.html (it becomes /), a manifest.json with at least a name, and whatever else the page needs. Content types are guessed from file names; anything you put under resources in the manifest is kept.

atile (@dasl/tiles)

The command-line tool. It bundles a directory into a .tile, or publishes it to your repo with an app password.

${code(`npm install -g @dasl/tiles atile bundle ./my-tile my-tile.tile # write a carball, no login needed atile login you.example # asks for an app password; kept in the OS keychain atile publish ./my-tile # upload blobs + write the record (fresh TID) atile publish -s ./my-tile # stable id: reuse this directory's record key next time atile publish --tid 3mwvoqidyqd24 ./my-tile # an explicit record key atile delete at://did:plc:…/ing.dasl.masl/3mwvoqidyqd24`)}

-s remembers the at:// URI per directory in ~/.atile/identifiers.json, so republishing overwrites the same record. atile does not set prev; add "prev": { "$link": "…" } to manifest.json yourself if you want the chain.

Blastile

Blastile is an app for working with tiles: open a .tile or an at:// URI, watch a source directory with live reload, exchange data with the tile from a console, and publish over AT OAuth. A published tile links to its page here.

It comes two ways. In the browser, with nothing to install: tiles stay in your browser and publishing goes straight to your PDS. And as a desktop app to download, which reads tile directories from disk, shares ~/.atile/identifiers.json with atile so a directory keeps the same record whichever tool publishes it, and runs tiles isolated on random *.localhost origins with the network locked down. The source is in the DASL tiles repository.

tilers

tilers follows RSS, Atom and JSON feeds and turns each new entry into a self-contained tile (article, styles, fonts, images), saved as .tile and optionally published to your repo.

This site

The publish page takes a .tile or a directory, lets you check and edit the manifest, pick the record key (a fresh TID, your own, or an existing tile to update with prev set), previews the tile, and writes it to your repo from the browser.

Running tiles in your app

Tiles must run in an origin of their own with the spec's CSP sandbox, which the browser can't fake in-page. @dasl/tile-loader gives you a mothership on your page, which mints an iframe on a random subdomain of a load domain running @dasl/tile-server; the server serves the shuttle runtime with the right headers, and the shuttle asks the mothership for the tile's resources over postMessage. The tile never touches the network itself.

${code(`npm install @dasl/tile-loader import { TileMothership } from '@dasl/tile-loader'; import { ATTileLoader } from '@dasl/tile-loader/at'; import { tileSize } from '@dasl/tile-loader/size'; import { tileLinks, linkPrompt } from '@dasl/tile-loader/link'; const ship = new TileMothership({ loadDomain: 'load.webtil.es' }); // or your own ship.init(); // once per page ship.addLoader(new ATTileLoader()); const tile = await ship.loadTile('at://did:plc:…/ing.dasl.masl/3mwvoqidyqd24'); document.body.append(await tile.renderCard()); // name, icon, screenshot; runs on click const frame = tile.renderContent(); // or run it now document.body.append(frame); tileSize(tile, frame, { width: 'tile', limits: { maxWidth: 720, maxHeight: 800 } }); // its size: what it asks for, within your limits tileLinks(tile, { frame, open: linkPrompt(underTheTile) }); // its links: shown to the user, who opens them or not`)} ${code(`npm install @dasl/tile-server import { createServer } from 'node:http'; import express from 'express'; import { createTileLoadingRouter, hardenServer } from '@dasl/tile-server'; const app = express(); app.set('trust proxy', 'loopback'); app.use(createTileLoadingRouter('tiles.example')); // answers load.tiles.example and *.tiles.example hardenServer(createServer({ maxHeaderSize: 1024 * 1024 }, app).listen(1503));`)}

Every tile load is a new hostname, so the certificate has to be a wildcard (DNS-01), not per-host on-demand issuance. hardenServer makes what Node answers by itself a dead end too, and the larger header limit leaves room for the cookies a tile can leave. Under /.well-known/web-tiles/ the runtime also serves the modules a tile imports for the tiles protocols: data.js, size.js and link.js. On your page, tileData(tile) from @dasl/tile-loader/data is the other end of data.js.

Publishing from your app

It is a short sequence of XRPC calls against the author's PDS, which the publish page makes from the browser (web/publish-tile.js in its source). The part about blobs is in @dasl/tile-lexicon, as atile and Blastile use it: blobUploadType, uploadedBlobRef and verifyUploadedBlob.

  1. Compute each resource's CID (CIDv1, raw codec 0x55, sha-256; @atcute/cid's create(CODEC_RAW, bytes)). Resources with the same bytes share a CID.
  2. com.atproto.repo.uploadBlob each one with Content-Type: application/octet-stream (blobUploadType), and keep the blob reference it answers with, once you have checked that it names your bytes: verifyUploadedBlob(path, ours, uploadedBlobRef(answer.blob)), where ours is { "$type": "blob", "ref": { "$link": cid }, "mimeType": "application/octet-stream", "size": bytes.length }. It throws if the CID or the size differ.
  3. Build the manifest with that reference as each resource's src, mimeType and all (not a type of your own: the PDS refuses a record that names another type than the one it stored), and a content-type per resource; set prev to the previous manifest CID when you are replacing a tile.
  4. cid = the DRISL CID of that tile object, with the PDS's references in it (@atcute/cbor's encode, then create(CODEC_DCBOR, bytes)). Encoding { "$link": … } yields CBOR tag 42, as it must.
  5. com.atproto.repo.putRecord with collection: "ing.dasl.masl", your record key, and { $type, cid, tile, createdAt }.

With OAuth, ask for ${esc(config.oauthScope)}: the repo: scope covers the collection, blob:*/* the uploads. Then POST ${esc(config.publicUrl)}/api/index with {"actor": did} so the tile shows up here within seconds rather than on the next relay sweep.

Finding tiles

`; } export function aboutPage({ stats, mode }) { return `

About

${SITE}

A map of the Web Tiles published on the AT Protocol, and a place to run and publish them.

Web Tiles are composable web docs and apps that can be embedded safely anywhere: a tile can only load the resources its manifest lists, and the embedding app mediates everything else. On AT, a tile is an ing.dasl.masl record in its author's repository, with its resources uploaded as blobs; the manifest is a MASL document.

${SITE} follows the network for those records, keeps the manifests, shows them with the metadata they carry, and runs each tile on its page through @dasl/tile-loader. The feed has all of them, newest first; sign in to like and bookmark tiles, which writes public records to your own repo. You can also publish a tile from here, and read how to build with them.

Short IDs

Every tile has an at:// URI. The short form drops the collection and swaps the DID for the author's handle: at://robin.berjon.com/ing.dasl.masl/3meis42djm22d is @robin.berjon.com/3meis42djm22d, and that is also its path here. Handles can change, so the DID form (/@did:plc:…/3meis42djm22d) always works too.

How it indexes

${mode === 'tap' ? 'A dedicated Tap instance subscribes to the relay, tracks every repo with at least one ing.dasl.masl record, verifies signatures, backfills, and streams records here.' : 'The index polls each repo\'s PDS directly (development mode).'} The relay is also asked hourly which repos carry the collection, and anyone can ask for a repo to be indexed right away. Author profiles come from the public Bluesky API and are refreshed daily.

Right now: ${stats.tiles} tiles from ${stats.authors} authors, ${stats.repos} repos tracked.

JSON

Built by Robin Berjon; source on Tangled.

`; } export function messagePage({ title, text, status = 404 }) { return `

${status}

${esc(title)}

${text}

Back to the front page

`; }