vomebook commited on
Commit ·
479bcbd
1
Parent(s): 2834080
Restore compact toolbar and set browser filename early
Browse filesFiles changed (11)
- static/reader.css+12-30
- static/reader.html+1-1
- static/reader/core/reader-bindings.mjs-10
- static/reader/core/reader-source.mjs+1-2
- static/search/reader-navigation.js+15-3
- tests/test_browser.py+1-1
- tests/test_reader_close_responsiveness.py+37-2
- tests/test_reader_navigation_host.py+29-1
- tests/test_reader_performance.py+1-1
- tests/test_reader_refactor.py+3-3
- tests/test_reader_style.py+44-70
50 unmodified lines515253545556575859601542 unmodified lines1603160416051606160716081609161047 unmodified lines16581659166016611662166316641665166616671668166916701671167216 unmodified lines1689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171750 unmodified linesfont-size: 14px;line-height: 18px;}.reader-heading strong:focus-visible {outline: 2px solid var(--reader-focus-color);outline-offset: 1px;}.reader-heading span,.reader-path {color: #9ba3aa;1542 unmodified lines/* Mobile toolbar and bookmark placement */@media (max-width: 600px) {:root {--reader-toolbar-height: 65px;--reader-popover-top: 107px;}.reader-panel {width: 85vw;47 unmodified linesmin-width: 42px;}.reader-toolbar {display: grid;grid-template-areas: "back heading history" "actions actions actions";grid-template-columns: 26px minmax(0, 1fr) 26px;grid-template-rows: 30px 30px;gap: 0 1px;padding: 2px 5px;}.reader-toolbar > #back { grid-area: back; }.reader-toolbar > #history { grid-area: history; }.reader-content {padding: 10px;}16 unmodified linesmax-width: 100%;}.reader-heading {grid-area: heading;min-width: 0;}.reader-heading strong {overflow-x: auto;overflow-y: hidden;text-overflow: clip;scrollbar-width: none;overscroll-behavior-x: contain;-webkit-overflow-scrolling: touch;user-select: text;-webkit-user-select: text;}.reader-heading strong::-webkit-scrollbar { display: none; }.reader-heading > :not(strong) {display: none;}.reader-actions {grid-area: actions;justify-content: flex-end;gap: 1px;min-width: 0;}.reader-actions .control-group {gap: 0;}50 unmodified lines5152535455561542 unmodified lines1599160016011602160316041605160647 unmodified lines16541655165616571658165916601661166216 unmodified lines16791680168116821683168416851686168716881689169016911692169316941695169616971698169950 unmodified linesfont-size: 14px;line-height: 18px;}.reader-heading span,.reader-path {color: #9ba3aa;1542 unmodified lines/* Mobile toolbar and bookmark placement */@media (max-width: 600px) {:root {--reader-toolbar-height: 36px;--reader-popover-top: 78px;}.reader-panel {width: 85vw;47 unmodified linesmin-width: 42px;}.reader-toolbar {gap: 1px;padding: 2px 5px;}.reader-content {padding: 10px;}16 unmodified linesmax-width: 100%;}.reader-heading {display: none;}.reader-actions {flex: 1;justify-content: flex-start;gap: 1px;min-width: 0;overflow-x: auto;scrollbar-width: none;overscroll-behavior-x: contain;-webkit-overflow-scrolling: touch;}.reader-actions::-webkit-scrollbar { display: none; }.reader-actions > * { flex-shrink: 0; }.reader-actions::before { content: ""; margin-left: auto; }.reader-actions .control-group {gap: 0;}
69 unmodified lines7071727374757669 unmodified lines</svg></button><div class="reader-heading"><strong id="title" tabindex="0" role="region" aria-label="书名,可横向滚动" title="在线阅读">在线阅读</strong><button id="reader-path" class="reader-path" type="button" hidden></button><span id="status">正在准备...</span></div>69 unmodified lines7071727374757669 unmodified lines</svg></button><div class="reader-heading"><strong id="title">在线阅读</strong><button id="reader-path" class="reader-path" type="button" hidden></button><span id="status">正在准备...</span></div>
357 unmodified lines358359360361362363364365366367368369370371372373357 unmodified linesreaderContext.applyReaderTheme(readerContext.readerTheme, false, false);readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);document.querySelector("#title").addEventListener("keydown", (event) => {const amount = event.currentTarget.clientWidth * 0.8;if (event.currentTarget.scrollWidth <= event.currentTarget.clientWidth) return;if (event.key === "ArrowRight") event.currentTarget.scrollLeft += amount;else if (event.key === "ArrowLeft") event.currentTarget.scrollLeft -= amount;else if (event.key === "Home") event.currentTarget.scrollLeft = 0;else if (event.key === "End") event.currentTarget.scrollLeft = event.currentTarget.scrollWidth;else return;event.preventDefault();});document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);let closing = false;window.addEventListener("pageshow", event => { if (event.persisted) closing = false; });357 unmodified lines358359360361362363357 unmodified linesreaderContext.applyReaderTheme(readerContext.readerTheme, false, false);readerContext.readerPath.addEventListener("click", readerContext.navigateReaderFolder);document.querySelector("#reader-panel-path")?.addEventListener("click", readerContext.navigateReaderFolder);let closing = false;window.addEventListener("pageshow", event => { if (event.persisted) closing = false; });
125 unmodified lines126127128129130131132133125 unmodified linesheading.scrollLeft = 0;}heading.title = displayName;heading.setAttribute("aria-label", `书名:${displayName};可横向滚动`);document.title = `${displayName} - VoiceOfML Reader`;if (readerContext.isReaderOverlayFrame())window.parent.postMessage({ type: "voice-reader-title", title: document.title }, location.origin);readerContext.applyReaderPathMetadata(readerContext.resolvedReaderData);125 unmodified lines126127128129130131132125 unmodified linesheading.scrollLeft = 0;}heading.title = displayName;document.title = displayName;if (readerContext.isReaderOverlayFrame())window.parent.postMessage({ type: "voice-reader-title", title: document.title }, location.origin);readerContext.applyReaderPathMetadata(readerContext.resolvedReaderData);
52 unmodified lines5354555657585960217 unmodified lines27827928028128228322 unmodified lines30630730830931031131231331431531631731831932032152 unmodified linesfunction showTitle(target, title) {if (frame !== target || titleDismissed || typeof title !== "string" || !title.trim()) return;target.title = title;document.title = title;}// A Reader closed while reading aloud stays alive, hidden, with a small// player on the search page; reopening the same book reuses it.let parked = null;217 unmodified linesnext.classList.add("reader-overlay-pending");returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;frame = next;opening = document.createElement("div");opening.className = "reader-overlay-opening";const back = document.createElement("button");22 unmodified lines};window.addEventListener("message", onShell);releaseOpening = () => { window.removeEventListener("message", onShell); releaseOpening = null; };document.body.append(next, opening);back.focus();shade(next);next.addEventListener("load",() => {if (next.contentDocument?.URL === "about:blank") return;reveal();});return next;}function dismiss() {52 unmodified lines53545556575859606162636465217 unmodified lines28328428528628728828929029122 unmodified lines31431531631731831932032132232332432532632732832933033133233352 unmodified linesfunction showTitle(target, title) {if (frame !== target || titleDismissed || typeof title !== "string" || !title.trim()) return;target.title = title;if (document.title === title) return;document.title = title;}function initialTitle(url) {const title = url.searchParams.get("title");return title && title.trim() ? title : "";}// A Reader closed while reading aloud stays alive, hidden, with a small// player on the search page; reopening the same book reuses it.let parked = null;217 unmodified linesnext.classList.add("reader-overlay-pending");returnFocus = document.activeElement instanceof HTMLElement ? document.activeElement : null;frame = next;// The initial filename is known at the search click. Publish it before// creating the history entry, instead of waiting for the iframe lookup.showTitle(next, initialTitle(url));opening = document.createElement("div");opening.className = "reader-overlay-opening";const back = document.createElement("button");22 unmodified lines};window.addEventListener("message", onShell);releaseOpening = () => { window.removeEventListener("message", onShell); releaseOpening = null; };next.addEventListener("load",() => {if (next.contentDocument?.URL === "about:blank") return;try {const title = next.contentDocument?.title;if (title && title !== "VoiceOfML Reader") showTitle(next, title);} catch (_) {}reveal();});document.body.append(next, opening);back.focus();shade(next);return next;}function dismiss() {
979 unmodified lines980981982983984985986979 unmodified linespath = reader.locator('#reader-panel-path')path.wait_for(state='visible')self.assertEqual(path.locator('.reader-panel-folder').inner_text(), '所在目录:VOMEBOOK/一级目录/二级目录')self.assertIn('测试', reader.locator('#title').inner_text())path.click()page.locator('iframe.reader-overlay').wait_for(state='detached')page.wait_for_function("STATE.browserPath==='一级目录/二级目录' && STATE.filterFolderSelfs.join()==='一级目录/二级目录'")979 unmodified lines980981982983984985986979 unmodified linespath = reader.locator('#reader-panel-path')path.wait_for(state='visible')self.assertEqual(path.locator('.reader-panel-folder').inner_text(), '所在目录:VOMEBOOK/一级目录/二级目录')self.assertIn('测试', reader.locator('#title').text_content())path.click()page.locator('iframe.reader-overlay').wait_for(state='detached')page.wait_for_function("STATE.browserPath==='一级目录/二级目录' && STATE.filterFolderSelfs.join()==='一级目录/二级目录'")
31 unmodified lines323334353637381 unmodified line404142434445464748495031 unmodified linesself.page.evaluate('url => navigateToReader(url)', url)frame = self.page.frame_locator('iframe.reader-overlay')frame.locator('html[data-reader-phase="ready"]').wait_for()self.page.wait_for_function("()=>document.title==='真实书名.txt - VoiceOfML Reader'")self.assertEqual(frame.locator('#title').inner_text(), '真实书名.txt')self.assertEqual(frame.locator('body').evaluate('()=>document.title'), self.page.title())self.page.evaluate('history.back()')1 unmodified lineself.assertEqual(self.page.title(), original)self.page.evaluate('history.forward()')frame.locator('html[data-reader-phase="ready"]').wait_for()self.page.wait_for_function("()=>document.title==='真实书名.txt - VoiceOfML Reader'")frame.locator('#back').click()self.page.locator('iframe.reader-overlay').wait_for(state='detached')self.assertEqual(self.page.title(), original)def test_slow_old_write_cannot_delay_close_or_overwrite_last_position(self):source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/responsive.txt'self.page.route('**/api/reader-content**', lambda route: route.fulfill(31 unmodified lines323334353637381 unmodified line4041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848531 unmodified linesself.page.evaluate('url => navigateToReader(url)', url)frame = self.page.frame_locator('iframe.reader-overlay')frame.locator('html[data-reader-phase="ready"]').wait_for()self.page.wait_for_function("()=>document.title==='真实书名.txt'")self.assertEqual(frame.locator('#title').inner_text(), '真实书名.txt')self.assertEqual(frame.locator('body').evaluate('()=>document.title'), self.page.title())self.page.evaluate('history.back()')1 unmodified lineself.assertEqual(self.page.title(), original)self.page.evaluate('history.forward()')frame.locator('html[data-reader-phase="ready"]').wait_for()self.page.wait_for_function("()=>document.title==='真实书名.txt'")frame.locator('#back').click()self.page.locator('iframe.reader-overlay').wait_for(state='detached')self.assertEqual(self.page.title(), original)def test_html_filename_titles_search_history_before_embedded_reader_loads(self):self.page.set_viewport_size({'width':390,'height':844})source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/bb_204.html'self.page.route('**/api/reader-content**', lambda route: route.fulfill(content_type='text/html',body='<html><head><title>页面文章标题</title></head><body><h1>文章标题</h1><p>正文</p></body></html>'))original = self.page.title()url = '/static/reader.html?' + urlencode(dict(url=source, ext='html', title='bb_204.html'))state=self.page.evaluate('''url=>{const native=history.pushState;let atPush=null;history.pushState=function(...args){atPush=document.title;return native.apply(this,args)};try{navigateToReader(url);return {atPush,title:document.title}}finally{history.pushState=native}}''',url)self.assertEqual(state, dict(atPush='bb_204.html',title='bb_204.html'))frame=self.page.frame_locator('iframe.reader-overlay')frame.locator('html[data-reader-phase="ready"]').wait_for()self.page.wait_for_function("()=>document.title==='bb_204.html'")self.assertEqual(frame.locator('iframe.html-frame').content_frame.locator('h1').inner_text(),'文章标题')self.assertEqual(frame.locator('#title').text_content(),'bb_204.html')self.assertTrue(frame.locator('#title').is_hidden())self.assertEqual(frame.locator('.reader-toolbar').bounding_box()['height'],36)frame.locator('#back').click()self.page.locator('iframe.reader-overlay').wait_for(state='detached')self.assertEqual(self.page.title(),original)def test_standalone_html_uses_original_filename_as_title(self):self.page.set_viewport_size({'width':390,'height':844})source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/bb_204.html'self.page.route('**/api/reader-content**', lambda route: route.fulfill(content_type='text/html',body='<h1>文章标题</h1><p>正文</p>'))self.page.goto(self.fixture.origin+'/static/reader.html?'+urlencode(dict(url=source,ext='html',title='bb_204.html')))self.page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")self.assertEqual(self.page.title(),'bb_204.html')self.assertTrue(self.page.locator('#title').is_hidden())self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'],36)def test_slow_old_write_cannot_delay_close_or_overwrite_last_position(self):source = 'https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/responsive.txt'self.page.route('**/api/reader-content**', lambda route: route.fulfill(
101 unmodified lines102103104105106107108109110101 unmodified lines}''')self.assertEqual(result, dict(firstTitle='第一本.txt - VoiceOfML Reader',frameTitle='第一本.txt - VoiceOfML Reader', rejected='第一本.txt - VoiceOfML Reader',duringReplace='搜索原始标题', stale='搜索原始标题', next='第二本.pdf - VoiceOfML Reader',dismissed='搜索原始标题', closed='搜索原始标题'))def test_parked_reader_title_is_restored_only_when_reopened(self):self.page.evaluate('navigateToReader("/static/reader.html?id=speech-title&ext=txt")')self.page.frame_locator('.reader-overlay').locator('body').wait_for()101 unmodified lines102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138101 unmodified lines}''')self.assertEqual(result, dict(firstTitle='第一本.txt - VoiceOfML Reader',frameTitle='第一本.txt - VoiceOfML Reader', rejected='第一本.txt - VoiceOfML Reader',duringReplace='second', stale='second', next='第二本.pdf - VoiceOfML Reader',dismissed='搜索原始标题', closed='搜索原始标题'))def test_filename_is_set_before_reader_history_entry(self):result = self.page.evaluate('''() => {const before=document.title, original=history.pushState, seen=[];history.pushState=function(...args){seen.push({title:document.title,url:String(args[2])});return original.apply(this,args)};try {navigateToReader('/static/reader.html?id=sample&ext=html&title=bb_204.html');const title=document.title, share=location.href;closeReaderOverlay();return {before,title,share,seen,restored:document.title};} finally {history.pushState=original}}''')self.assertEqual(result['title'], 'bb_204.html')self.assertEqual(result['seen'][0]['title'], 'bb_204.html')self.assertIn('title=bb_204.html', result['share'])self.assertEqual(result['restored'], result['before'])def test_older_embedded_reader_still_refreshes_host_title_on_load(self):self.page.unroute('**/static/reader.html?**')self.page.evaluate("()=>caches.keys().then(keys=>Promise.all(keys.map(key=>caches.delete(key))))")self.fixture.context.route('**/static/reader.html?**', lambda route: route.fulfill(content_type='text/html',body='<title>旧阅读器文档.txt</title><body>reader</body>'))before=self.page.title()self.page.evaluate('navigateToReader("/static/reader.html?id=older&ext=txt")')self.page.frame_locator('iframe.reader-overlay').locator('body').wait_for()self.page.wait_for_function("()=>document.title==='旧阅读器文档.txt'")self.page.evaluate('closeReaderOverlay()')self.assertEqual(self.page.title(),before)def test_parked_reader_title_is_restored_only_when_reopened(self):self.page.evaluate('navigateToReader("/static/reader.html?id=speech-title&ext=txt")')self.page.frame_locator('.reader-overlay').locator('body').wait_for()
2343 unmodified lines23442345234623472348234923502343 unmodified linespath=page.locator('#reader-panel-path')path.wait_for(state='visible')self.assertTrue(path.evaluate("n=>n.closest('#reader-panel-location').parentElement.id==='history-panel'"))self.assertTrue(page.locator('#title').is_visible())self.assertEqual(path.locator('.reader-panel-folder').inner_text(),'所在目录:Test/音乐')page.locator('#bookmarks-tab').click()self.assertTrue(path.is_visible())2343 unmodified lines23442345234623472348234923502343 unmodified linespath=page.locator('#reader-panel-path')path.wait_for(state='visible')self.assertTrue(path.evaluate("n=>n.closest('#reader-panel-location').parentElement.id==='history-panel'"))self.assertTrue(page.locator('#title').is_hidden())self.assertEqual(path.locator('.reader-panel-folder').inner_text(),'所在目录:Test/音乐')page.locator('#bookmarks-tab').click()self.assertTrue(path.is_visible())
3143 unmodified lines31443145314631473148314931503 unmodified lines315431553156315731583159316031613143 unmodified linesself.serve("Folder document")self.open(self.origin + "/static/reader.html?id=mobile-folder&ext=txt")self.assertTrue(self.page.locator('#reader-path').is_hidden())self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 65)self.assertTrue(self.page.locator('#history-panel').evaluate('node=>node.inert'))self.page.locator('#reader-panel-path').evaluate('node=>node.focus()')self.assertNotEqual(self.page.evaluate('document.activeElement.id'), 'reader-panel-path')3 unmodified linesaction = self.page.locator('#reader-panel-path')action.wait_for(state='visible')self.assertIn('打开所在目录:Test/docs/子', action.get_attribute('aria-label'))self.assertEqual(self.page.locator('#title').inner_text(), '原件.txt.txt')self.assertEqual(self.page.title(), '原件.txt.txt - VoiceOfML Reader')self.page.keyboard.press('Tab')action.focus()self.assertNotEqual(action.evaluate('node=>getComputedStyle(node).outlineStyle'), 'none')3143 unmodified lines31443145314631473148314931503 unmodified lines315431553156315731583159316031613143 unmodified linesself.serve("Folder document")self.open(self.origin + "/static/reader.html?id=mobile-folder&ext=txt")self.assertTrue(self.page.locator('#reader-path').is_hidden())self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36)self.assertTrue(self.page.locator('#history-panel').evaluate('node=>node.inert'))self.page.locator('#reader-panel-path').evaluate('node=>node.focus()')self.assertNotEqual(self.page.evaluate('document.activeElement.id'), 'reader-panel-path')3 unmodified linesaction = self.page.locator('#reader-panel-path')action.wait_for(state='visible')self.assertIn('打开所在目录:Test/docs/子', action.get_attribute('aria-label'))self.assertEqual(self.page.locator('#title').text_content(), '原件.txt.txt')self.assertEqual(self.page.title(), '原件.txt.txt')self.page.keyboard.press('Tab')action.focus()self.assertNotEqual(action.evaluate('node=>getComputedStyle(node).outlineStyle'), 'none')
405 unmodified lines4064074084094104114127 unmodified lines42042142242342442542642742838 unmodified lines46746846947047147247347447547647747822 unmodified lines50150250350450550650738 unmodified lines546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615405 unmodified linesminHeight: parseFloat(style.minHeight), padding: style.padding,video: content.firstChild?.getBoundingClientRect().height};}""", mode)expected_toolbar = 65 if width <= 600 else 44self.assertEqual(metrics["toolbar"], expected_toolbar)self.assertAlmostEqual(metrics["height"], height - expected_toolbar, delta=1)self.assertEqual(metrics["padding"], "0px")7 unmodified linesfor width, height in ((320, 568), (390, 844), (600, 500), (601, 500)):with self.subTest(width=width, height=height):self.page.set_viewport_size({'width': width, 'height': height})self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 65 if width <= 600 else 44)self.assertEqual(self.page.locator('#reader-path').is_visible(), width > 600)self.assertTrue(self.page.locator('#title').is_visible())self.page.locator('#history').click()self.page.wait_for_function("()=>document.querySelector('#history').getAttribute('aria-expanded') === 'true'")info=self.page.locator('#reader-panel-location')38 unmodified linesreturn {id:n.id,left:r.left,right:r.right,top:r.top,bottom:r.bottom,inside:r.left>=toolbar.left&&r.right<=toolbar.right&&r.top>=toolbar.top&&r.bottom<=toolbar.bottom};});}''')self.assertTrue(all(box['inside'] for box in boxes), boxes)for i, a in enumerate(boxes):for b in boxes[i+1:]:overlap=min(a['right'], b['right'])-max(a['left'], b['left'])vertical=min(a['bottom'], b['bottom'])-max(a['top'], b['top'])self.assertFalse(overlap > 0.5 and vertical > 0.5, (a, b))def test_mobile_folder_action_has_contrast_and_stays_out_of_header(self):self.page.set_viewport_size({'width': 320, 'height': 568})22 unmodified linesself.page.locator('#history').click()self.assertEqual(self.page.get_by_role('button',name='文件信息',exact=True).count(), 0)self.assertTrue(self.page.locator('#reader-panel-path').is_disabled())self.assertTrue(self.page.locator('#title').is_visible())self.assertTrue(self.page.locator('#reader-panel-location').is_visible())self.page.locator('#history-tab').click()self.assertTrue(self.page.locator('#reader-panel-location').is_visible())38 unmodified linesself.page.wait_for_function("()=>document.querySelector('#history-panel').hidden")self.assertTrue(info.is_hidden())def test_mobile_long_filename_scrolls_without_expanding_or_hiding_folder(self):self.page.set_viewport_size({'width':320,'height':700})self.page.emulate_media(reduced_motion='reduce')self.assertIn('Style.txt', self.page.locator('#title').get_attribute('aria-label'))self.page.evaluate("()=>document.querySelector('#title').textContent=('很长的文件名称'.repeat(15))+'.pdf'")self.page.locator('#history').click()name=self.page.locator('#title')self.assertTrue(name.evaluate('n=>n.scrollWidth>n.clientWidth'))before=name.bounding_box()['height']name.focus()self.page.keyboard.press('Tab')name.focus()self.assertEqual(name.evaluate('n=>getComputedStyle(n).outlineStyle'),'solid')name.press('End')self.assertGreater(name.evaluate('n=>n.scrollLeft'),0)self.assertEqual(name.evaluate('n=>getComputedStyle(n).whiteSpace'),'nowrap')self.assertAlmostEqual(name.bounding_box()['height'],before,delta=1)self.assertTrue(self.page.locator('#reader-panel-path').is_visible())self.assertTrue(self.page.locator('#history-panel').is_visible())def test_mobile_filename_accepts_horizontal_touch_swipe(self):context=self.browser.new_context(viewport={'width':320,'height':700},is_mobile=True,has_touch=True)try:page=context.new_page()page.route('**/api/reader-content**',lambda route:route.fulfill(content_type='text/plain',body='Readable text'))source=urllib.parse.quote('https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/touch.txt',safe='')page.goto(f'{self.origin}/static/reader.html?url={source}&ext=txt&title=Touch')page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")page.evaluate("()=>document.querySelector('#title').textContent=('非常长的文件名称'.repeat(20))+'.pdf'")page.locator('#history').click()name=page.locator('#title')box=name.bounding_box()session=context.new_cdp_session(page)x,y=box['x']+box['width']-20,box['y']+box['height']/2session.send('Input.dispatchTouchEvent',{'type':'touchStart','touchPoints':[{'x':x,'y':y}]})for delta in (30,60,90,120):session.send('Input.dispatchTouchEvent',{'type':'touchMove','touchPoints':[{'x':x-delta,'y':y}]})page.wait_for_timeout(25)session.send('Input.dispatchTouchEvent',{'type':'touchEnd','touchPoints':[]})page.wait_for_function("()=>document.querySelector('#title').scrollLeft>0")self.assertTrue(page.locator('#reader-panel-path').is_visible())self.assertTrue(page.locator('#reader-panel-location').is_visible())finally:context.close()def test_mobile_short_filename_does_not_scroll_and_long_name_adapts_on_resize(self):self.page.set_viewport_size({'width':390,'height':700})self.page.emulate_media(reduced_motion='reduce')self.page.locator('#history').click()name=self.page.locator('#title')self.page.evaluate("()=>document.querySelector('#title').textContent='短文.txt'")self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth===document.querySelector('#title').clientWidth")self.assertEqual(name.evaluate('n=>getComputedStyle(n).display'),'block')self.assertEqual(name.evaluate('n=>n.scrollWidth'),name.evaluate('n=>n.clientWidth'))self.assertEqual(self.page.locator('.reader-panel-filename').count(),0)self.page.evaluate("()=>document.querySelector('#title').textContent=('很长的文件名称'.repeat(15))+'.pdf'")self.assertGreater(name.evaluate('n=>n.scrollWidth'),name.evaluate('n=>n.clientWidth'))self.page.evaluate("()=>document.querySelector('#title').textContent=('宽度测试'.repeat(7))+'.pdf'")self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth>document.querySelector('#title').clientWidth")self.page.set_viewport_size({'width':600,'height':700})self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth===document.querySelector('#title').clientWidth")self.page.set_viewport_size({'width':320,'height':700})self.page.wait_for_function("()=>document.querySelector('#title').scrollWidth>document.querySelector('#title').clientWidth")def test_theme_transition_preserves_drawer_and_filter_motion(self):self.page.locator("#history").click()self.page.locator("#bookmarks-tab").click()405 unmodified lines4064074084094104114127 unmodified lines42042142242342442542642742838 unmodified lines46746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551622 unmodified lines53954054154254354454538 unmodified lines584585586587588589405 unmodified linesminHeight: parseFloat(style.minHeight), padding: style.padding,video: content.firstChild?.getBoundingClientRect().height};}""", mode)expected_toolbar = 36 if width <= 600 else 44self.assertEqual(metrics["toolbar"], expected_toolbar)self.assertAlmostEqual(metrics["height"], height - expected_toolbar, delta=1)self.assertEqual(metrics["padding"], "0px")7 unmodified linesfor width, height in ((320, 568), (390, 844), (600, 500), (601, 500)):with self.subTest(width=width, height=height):self.page.set_viewport_size({'width': width, 'height': height})self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36 if width <= 600 else 44)self.assertEqual(self.page.locator('#reader-path').is_visible(), width > 600)self.assertEqual(self.page.locator('#title').is_visible(), width > 600)self.page.locator('#history').click()self.page.wait_for_function("()=>document.querySelector('#history').getAttribute('aria-expanded') === 'true'")info=self.page.locator('#reader-panel-location')38 unmodified linesreturn {id:n.id,left:r.left,right:r.right,top:r.top,bottom:r.bottom,inside:r.left>=toolbar.left&&r.right<=toolbar.right&&r.top>=toolbar.top&&r.bottom<=toolbar.bottom};});}''')self.assertEqual(self.page.locator('.reader-toolbar').bounding_box()['height'], 36)self.assertTrue(self.page.locator('#title').is_hidden())self.assertTrue(all(box['inside'] for box in boxes), boxes)actions=self.page.locator('.reader-actions')metrics=actions.evaluate('''n=>{const r=n.getBoundingClientRect(),back=document.querySelector('#back').getBoundingClientRect(),menu=document.querySelector('#history').getBoundingClientRect();return {left:r.left,right:r.right,back:back.right,menu:menu.left,scroll:n.scrollWidth>n.clientWidth}}''')self.assertGreaterEqual(metrics['left'],metrics['back']-.5)self.assertLessEqual(metrics['right'],metrics['menu']+.5)inside=[b for b in boxes if b['id'] in ('back','history') orb['left'] >= metrics['left']-.5 and b['right'] <= metrics['right']+.5]for i, a in enumerate(inside):for b in inside[i+1:]:overlap=min(a['right'], b['right'])-max(a['left'], b['left'])vertical=min(a['bottom'], b['bottom'])-max(a['top'], b['top'])self.assertFalse(overlap > 0.5 and vertical > 0.5, (a, b))if metrics['scroll']:actions.evaluate('n=>n.scrollLeft=n.scrollWidth')self.assertGreater(actions.evaluate('n=>n.scrollLeft'),0)def test_mobile_overflowing_toolbar_supports_touch_swipe(self):context=self.browser.new_context(viewport={'width':280,'height':700},is_mobile=True,has_touch=True)try:page=context.new_page()page.route('**/api/reader-content**',lambda route:route.fulfill(content_type='text/plain',body='Readable text'))source=urllib.parse.quote('https://huggingface.co/datasets/VoiceOfML/Test/resolve/main/touch.txt',safe='')page.goto(f'{self.origin}/static/reader.html?url={source}&ext=txt&title=Touch')page.wait_for_function("()=>document.documentElement.dataset.readerPhase==='ready'")page.evaluate('''()=>{document.querySelector('.page-controls').hidden=false;const ocr=document.createElement('a');ocr.className='text-button';ocr.textContent='OCR';document.querySelector('.reader-actions').prepend(ocr)}''')actions=page.locator('.reader-actions')self.assertGreater(actions.evaluate('n=>n.scrollWidth'),actions.evaluate('n=>n.clientWidth'))box=actions.bounding_box();session=context.new_cdp_session(page)x,y=box['x']+box['width']-15,box['y']+box['height']/2session.send('Input.dispatchTouchEvent',{'type':'touchStart','touchPoints':[{'x':x,'y':y}]})for delta in (25,50,75,100):session.send('Input.dispatchTouchEvent',{'type':'touchMove','touchPoints':[{'x':x-delta,'y':y}]})page.wait_for_timeout(25)session.send('Input.dispatchTouchEvent',{'type':'touchEnd','touchPoints':[]})page.wait_for_function("()=>document.querySelector('.reader-actions').scrollLeft>0")self.assertEqual(page.locator('.reader-toolbar').bounding_box()['height'],36)finally:context.close()def test_mobile_folder_action_has_contrast_and_stays_out_of_header(self):self.page.set_viewport_size({'width': 320, 'height': 568})22 unmodified linesself.page.locator('#history').click()self.assertEqual(self.page.get_by_role('button',name='文件信息',exact=True).count(), 0)self.assertTrue(self.page.locator('#reader-panel-path').is_disabled())self.assertTrue(self.page.locator('#title').is_hidden())self.assertTrue(self.page.locator('#reader-panel-location').is_visible())self.page.locator('#history-tab').click()self.assertTrue(self.page.locator('#reader-panel-location').is_visible())38 unmodified linesself.page.wait_for_function("()=>document.querySelector('#history-panel').hidden")self.assertTrue(info.is_hidden())def test_theme_transition_preserves_drawer_and_filter_motion(self):self.page.locator("#history").click()self.page.locator("#bookmarks-tab").click()
static/reader.css+12-30
static/reader.html+1-1
static/reader/core/reader-bindings.mjs-10
static/reader/core/reader-source.mjs+1-2
static/search/reader-navigation.js+15-3
tests/test_browser.py+1-1
tests/test_reader_close_responsiveness.py+37-2
tests/test_reader_navigation_host.py+29-1
tests/test_reader_performance.py+1-1
tests/test_reader_refactor.py+3-3
tests/test_reader_style.py+44-70