// HV leaf spike, the JS half. A minimal universal renderer with the shape of solid-js/universal's // createRenderer (createElement / setProperty / insertNode / removeNode) that records ops into a batch; // native (Swift) applies each batch to UIKit. No DOM, no canvas. Reactivity is a tiny signal so the // focus-driven hero update goes through the same op path a Solid effect would. let nextId = 1 let batch = [] function flush() { if (batch.length) { __native.apply(JSON.stringify(batch)); batch = [] } } const R = { createElement(type) { const id = nextId++; batch.push(['c', id, type]); return { id } }, setProperty(node, name, value) { batch.push(['p', node.id, name, value]) }, insertNode(parentId, node) { batch.push(['i', parentId, node.id]) }, } function signal(v) { const subs = [] return { get: () => v, set: (n) => { v = n; subs.forEach((s) => s()) }, effect: (f) => { subs.push(f); f() } } } const handlers = {} // A reactive prop is { $: signal }: the effect re-sends that one prop when the signal changes. function h(type, props, ...children) { const n = R.createElement(type) for (const [k, v] of Object.entries(props || {})) { if (v && v.$) v.$.effect(() => R.setProperty(n, k, v.$.get())) else if (typeof v === 'function') handlers[`${n.id}:${k}`] = v else R.setProperty(n, k, v) } for (const c of children.flat()) if (c) R.insertNode(n.id, c) return n } globalThis.__event = (id, name, arg) => { const f = handlers[`${id}:${name}`] if (f) { f(arg); flush() } } // Bengali and English titles: native text must shape Bengali (the canvas build's SDF atlas cannot). const TITLES = ['ফেলুদা ফেরত', 'ব্যোমকেশ', 'Mandaar', 'হইচই অরিজিনাল', 'Karnasubarner Guptodhon', 'দুপুর ঠাকুরপো', 'Byomkesh Hotyamancha', 'চরিত্রহীন', 'Taqdeer', 'একেনবাবু', 'Hello', 'মহানন্দা', 'Rudrabinar Obhishaap', 'তানসেনের তানপুরা'] const RAILS = ['Continue Watching', 'নতুন রিলিজ', 'Trending Now', 'বাংলা সিনেমা', 'Thrillers', 'হইচই অরিজিনালস'] const COLS = 20 const hero = signal('Select a title') function Home() { return h('view', { x: 0, y: 0, width: 1920, height: 1080, color: '#0b0b10' }, h('text', { x: 90, y: 50, width: 1740, height: 90, fontSize: 52, color: '#ffffff', text: { $: hero } }), h('scroll', { x: 0, y: 160, width: 1920, height: 920 }, ...RAILS.map((title, r) => h('rail', { x: 0, y: r * 340, width: 1920, height: 330, title, itemWidth: 300, itemHeight: 220, // Items are data, not nodes: the native rail recycles UICollectionView cells, as a Solid // bound to a virtualised list would. items: Array.from({ length: COLS }, (_, c) => ({ id: `${r}-${c}`, title: TITLES[(r * 7 + c) % TITLES.length], color: `hsl(${(r * 53 + c * 17) % 360},55%,38%)`, })), onFocusItem: (it) => hero.set(`${it.title} · ${title}`), onSelectItem: (it) => __native.log(`select ${it.id}`), })), ), ) } const t0 = Date.now() R.insertNode(0, Home()) const ops = batch.length flush() __native.log(`mount: ${ops} ops built in ${Date.now() - t0} ms`)