/* Chapter 22 library explorer and Chapter 23 methods example. No fetch needed. */ (function () { const R=window.REBASE, esc=R.escape, files=R.library.files; const parent=path=>path.split('/').slice(0,-1).join('/'); const button=(path,label,cls='')=>''; R.libraryHasPath=path=>typeof path==='string' && (path==='' || Object.hasOwn(files,path) || Object.keys(files).some(file=>file.startsWith(path+'/'))); function explorer(state) { const path=state.library, isFile=Object.hasOwn(files,path); let crumbs=button('','Standard library'); path.split('/').filter(Boolean).forEach((part,i,parts)=>{ crumbs+='/'+button(parts.slice(0,i+1).join('/'),esc(part)); }); let contents; if(isFile) { contents='
'+esc(files[path])+'
'; } else { const entries=new Map(), prefix=path?path+'/':''; for(const file of Object.keys(files)) if(file.startsWith(prefix)) { const rest=file.slice(prefix.length), name=rest.split('/')[0]; entries.set(name,rest.includes('/')); } contents='
'+ [...entries].sort(([a,ad],[b,bd])=>Number(bd)-Number(ad)||a.localeCompare(b)).map(([name,dir])=> button(prefix+name,''+(dir?'DIR':'SMP')+''+esc(name)+(dir?'/':'')+''+(dir?'›':'↗')+'','library-entry')).join('')+'
'; } return '
'+(isFile?'':'')+'

Chapter 25 · '+esc(R.library.origin)+'

'+contents+'
'; } function intro(which,state) { const methods=which==='methods'; return '
'; } function methods(state) { return '
23 · Counter
'+esc(R.library.methods)+'

c.add(3).add(4) passes c as self.
The program returns arg + 7.

'; } R.languageBody=state=>'

The language starts
using its compiler.

'+ (state.library===null?intro('library',state):explorer(state))+ (state.library!==null && state.libraryWide?'':state.methods?methods(state):intro('methods',state))+'
'; })();