code wiki / _hdl_build / nx_video_embed_bundle.nx

nx_video_embed_bundle.nx source

↩ module page · 55 lines · 2802 B

1// nx_video_embed_bundle.nx -- emits the SELF-CONTAINED sovereign embed bundle nishi-video.js (organ-emitted 2// SSOT for the <nishi-video> Web Component). Reads the sovereign wasm core + base64-encodes it (standard 3// alphabet, browser-atob-compatible) + prepends it to the component template -> ONE file a host site drops in 4// with NO cross-origin asset fetch (only the WSS is cross-origin, which the relay accepts). Hardware-up: we 5// own the entire bundle; the wasm is still the sovereign nx-compiled core, just carried inline. 6// out: web_assets/nishi-video.js expect_exit: 0 license_tier: ORIGINAL 7import "nx_syscalls.nx" 8import "nx_base64.nx" 9 10func bw(s: *u8) -> i64 { var n: i64=0; while s[n]!=(0 as u8){n=n+1} sys_write(1,s,n); return 0 } 11func bn(v: i64) -> i64 { 12 let b: *u8=sys_mmap(28); var m: i64=v; if m<0{sys_write(1,"-" as *u8,1);m=0-m} 13 let t: *u8=sys_mmap(28); var k: i64=0; if m==0{t[0]=48 as u8;k=1} while m>0{t[k]=(48+(m%10)) as u8;m=m/10;k=k+1} 14 var i: i64=0; while i<k{b[i]=t[k-1-i];i=i+1} sys_write(1,b,k); return 0 } 15 16func main() -> i64 { 17 // 1. sovereign wasm core 18 let wbox: *i64 = sys_mmap(16) as *i64; wbox[0]=0 19 let wasm: *u8 = sys_read_file("web_assets/nx_video_client.wasm" as *u8, wbox) 20 if (wasm as i64)==0 { bw("no nx_video_client.wasm\n" as *u8); return 1 } 21 let wlen: i64 = wbox[0] 22 // 2. base64 (standard, atob-compatible) 23 let b64: *u8 = sys_mmap(wlen * 2 + 128) 24 let blen: i64 = b64_encode(wasm, wlen, b64) 25 // 3. component template 26 let cbox: *i64 = sys_mmap(16) as *i64; cbox[0]=0 27 let comp: *u8 = sys_read_file("sites/nishifamily/video/nishi-video.component.js" as *u8, cbox) 28 if (comp as i64)==0 { bw("no nishi-video.component.js\n" as *u8); return 1 } 29 let clen: i64 = cbox[0] 30 // 4. assemble: const WASM_B64="<b64>";\n<component> 31 let out: *u8 = sys_mmap(blen + clen + 256) 32 var o: i64 = 0 33 let pre: *u8 = "const WASM_B64=\"" as *u8 34 var i: i64 = 0 35 while pre[i]!=(0 as u8) { out[o]=pre[i]; o=o+1; i=i+1 } 36 i = 0 37 while i < blen { out[o]=b64[i]; o=o+1; i=i+1 } 38 let mid: *u8 = "\";\n" as *u8 39 i = 0 40 while mid[i]!=(0 as u8) { out[o]=mid[i]; o=o+1; i=i+1 } 41 i = 0 42 while i < clen { out[o]=comp[i]; o=o+1; i=i+1 } 43 // 5. write 44 let fd: i64 = sys_openat_wr("web_assets/nishi-video.js" as *u8, 0x1a4) 45 if fd < 0 { bw("cannot write nishi-video.js\n" as *u8); return 1 } 46 var wr: i64 = 0 47 while wr < o { 48 let w: i64 = sys_write(fd, ((out as i64)+wr) as *u8, o - wr) 49 if w <= 0 { sys_close(fd); return 1 } 50 wr = wr + w 51 } 52 sys_close(fd) 53 bw("EMITTED nishi-video.js: wasm=" as *u8); bn(wlen); bw("B -> b64=" as *u8); bn(blen); bw("B + component=" as *u8); bn(clen); bw("B = " as *u8); bn(o); bw("B total\n" as *u8) 54 return 0 55}