feat(slides): add sandboxed Reveal.js viewer and editor preview
Build and publish container images / images (push) Successful in 9m2s
Release container images / release (push) Successful in 21s

This commit is contained in:
Anya Tokugawa committed 2026-11-08 22:10:52 +09:00
1 parent 09afb438c9
commit 02fb77f72b
30 files changed
+532 -9

No files matched your search

+33
View File
@@ -0,0 +1,33 @@
(async()=>{
const assert=(ok,msg)=>{if(!ok)throw Error(msg)},delay=ms=>new Promise(r=>setTimeout(r,ms));
const wait=async fn=>{for(let n=0;n<300;n++){if(fn())return;await delay(25)}throw Error('Timeout '+fn)};
const ready=()=>document.querySelector('.slides-frame[data-ready=true]');
await wait(()=>window.PagesSlides);
const e=window.PagesEditor;
if(e){await wait(()=>document.querySelector('[data-editor-action=slides]')&&e.preview);e.paused=true;document.querySelector('[data-editor-action=slides]').click();}
await wait(ready);
const frame=ready(),source=e?.text(),historyLength=history.length;
assert(frame.dataset.count==='2','Wrong slide count');
assert(frame.sandbox.contains('allow-scripts')&&!frame.sandbox.contains('allow-same-origin'),'Isolation missing');
let isolated=false;try{isolated=!frame.contentDocument}catch{isolated=true}assert(isolated,'Frame can access parent origin');
assert(frame.getBoundingClientRect().height>=240,'Slide frame collapsed');
assert(frame.getBoundingClientRect().width<=innerWidth,'Mobile slide overflow');
if(e&&innerWidth<=700){assert(getComputedStyle(document.querySelector('.editor-pane')).display==='none','Mobile preview not full width');setEditorPreviewVisible(false);assert(getComputedStyle(document.querySelector('.editor-pane')).display!=='none','Mobile source inaccessible');setEditorPreviewVisible(true);}
const host=frame.parentElement;
// Verify the defensive DOM boundary independently of server sanitization.
PagesSlides.render(host,'<h1 onclick="alert(1)" data-background-iframe="https://evil.invalid">Safe</h1><script>alert(1)</scr'+'ipt><iframe src="https://evil.invalid"></iframe><img src="https://evil.invalid/x"><hr><p>Next</p>','/deck');
await wait(ready);
let projected=ready().srcdoc;
assert(!projected.includes('evil.invalid')&&!projected.includes('onclick=')&&!projected.includes('alert(1)'),'Unsafe content entered frame');
assert(!projected.includes('data-background-iframe'),'Reveal directives leaked');
assert(history.length===historyLength,'Slide render changed history');
let rejected=false;try{PagesSlides.render(host,'<p>x</p><hr>'.repeat(101),'/deck')}catch{rejected=true}assert(rejected,'Too many slides accepted');
if(e){
assert(e.text()===source,'Preview mutated canonical source');
e.setText('<h1>Edited</h1><hr><p>Second</p><hr><p>Third</p>');await e.renderPreview();await wait(ready);assert(ready().dataset.count==='3','Live preview stale');
document.querySelector('[data-editor-action=slides]').click();await wait(()=>!document.querySelector('.slides-frame'));assert(e.preview.textContent.includes('Edited'),'Normal preview not restored');
document.querySelector('[data-editor-action=slides]').click();await wait(ready);
clearTimeout(e.autosaveTimer);clearInterval(e.stateTimer);e.paused=true;
}else{PagesSlides.render(host,document.querySelector('[data-slides-source]').value,'/deck');await wait(ready);}
document.body.dataset.vimReady='true';
})().catch(error=>{const p=document.createElement('pre');p.id='error';p.textContent=error.stack;document.body.append(p)});