johnandersen777.bsky.social/atlibs-socialweb-computer-app
app.socialweb.computer: socialweb.computer in one page, one atlibs composition
0
0
// This page as a web tiles mothership (https://dasl.ing/tiles.html): a tile is a frame on its own origin with
// no network; it gets the page's state over tp-data and sends nothing back here. Loaded on first use.
import { Tile, TileMothership } from '@dasl/tile-loader'
import { ATTileLoader } from '@dasl/tile-loader/at'
export const TILES = [
{ url: 'local', name: 'Your socialweb.computer', description: 'Your VMs, agents and vouches, as a tile (./tile/, the same files `atlibs publish tile tile app-summary` publishes).' },
]
// "local": ./tile/, manifest.json as the MASL, its files as the resources
const local = (base) => ({
async load(url, mothership) {
if (url !== 'local') return false
const manifest = await (await fetch(new URL('tile/manifest.json', base))).json()
return new Tile(mothership, url, manifest, {
async resolvePath(path) {
const r = await fetch(new URL(`tile${path === '/' ? '/index.html' : path}`, base))
if (!r.ok) return { ok: false, status: r.status }
return { ok: true, status: 200, headers: { 'content-type': r.headers.get('content-type') }, body: new Uint8Array(await r.arrayBuffer()) }
},
})
},
})
export function mothership({ base = new URL('./', import.meta.url), loadDomain = 'load.webtil.es' } = {}) {
const m = new TileMothership({ loadDomain })
m.init()
m.addLoader(local(base))
m.addLoader(new ATTileLoader())
return {
list: TILES,
// the tile's frame; it gets `state` whenever it says it is ready
async show(url, state) {
const tile = await m.loadTile(url)
if (!tile) throw new Error(`no tile at ${url}`)
tile.addEventListener('data-ready', () => tile.sendData(state))
return tile.renderContent(tile.manifest.sizing?.height ?? 600)
},
}
}