* phase 0: token foundation * phase 1: motion language * phase 2: primitives and semantic tokens * phase 3: depth and rhythm polish * phase 4: enforce design system lint rules * phase 5: split ui primitives into modules * phase 7: refactor app surfaces to ui layer * phase 9: enforce ui architecture imports * phase 10: add ui system harness * fix compact reader auth control * fix pdf loader flash * Converge sidebar and reader controls * refactor: remove initial loader state and related logic from PDFViewerPage * Remove legacy UI shim imports * Converge modal and drawer frames * Migrate secondary modals to shared frame * Move settings modal onto shared frame * Use shared cards in audiobook settings * Converge choice and popover surfaces * Converge reader navigation buttons * Refactor UI components to use consistent button and icon styles across the application * refactor(ui): unify button usage in settings, admin, and doclist components Replace native button elements with shared Button, ChoiceTile, and IconButton components for consistent UI behavior and styling. Update classNames and props to match new component APIs. Adjust FinderSidebar to use utility function for conditional class merging. * feat(ui): introduce shared Listbox components for unified select and dropdown styling Replace direct usage of Headless UI Listbox primitives with new SharedListboxButton, SharedListboxOption, and SharedListboxOptions components across AudiobookExportModal, FinderToolbar, VoicesControlBase, and select UI. Refactor related imports and classNames to centralize dropdown styling and logic. Simplify UserMenu button markup for improved consistency. This change consolidates dropdown/select UI patterns, reduces duplication, and improves maintainability by providing a single source of truth for Listbox styling and behavior. * refactor(ui): consolidate button, menu, popover, and range primitives for unified usage Remove legacy UI harness and dev/demo files. Replace scattered button, menu, popover, and range input utilities with shared, composable primitives: Button, ButtonLink, ButtonAnchor, MenuActionItem, MenuItemsSurface, PopoverSurface, PopoverTrigger, and RangeInput. Update all usages across app, admin, player, and document components to use these new primitives, eliminating duplicated class logic and improving consistency. Remove obsolete utility files and class exports. This change streamlines UI code, centralizes styling, and reduces maintenance overhead. * feat(ui): redesign range input with dynamic progress styling and improved accessibility Revamp the range input component to support dynamic progress indication using CSS custom properties and linear gradients. Add logic to compute and set the progress percentage based on current value, min, and max. Refine focus and disabled states for better accessibility and usability. Update styling for both WebKit and Mozilla engines to ensure consistent appearance. This change enhances visual feedback and modernizes the range slider UI. * style(ui): update range input to use secondary accent color for progress Switch range input progress styling from primary to secondary accent color for both WebKit and Mozilla engines. Remove drop shadow from slider thumb for a cleaner appearance. This change aligns the component with the updated design palette and simplifies visual effects. * refactor(app): remove unused Link imports from public pages and components Eliminate redundant imports of the Link component from Next.js in several public-facing pages and components. These imports were no longer in use after recent UI refactoring and consolidation of navigation elements. This cleanup reduces bundle size and improves code clarity. * chore(ui): remove unused export of segmented control classes from select component Eliminate unnecessary export statements for segmentedButtonClass and segmentedGroupClass in the select component to streamline the module's public API and reduce potential confusion. * test(accessibility): improve confirm dialog test coverage and refactor media state helper Expand accessibility tests for ConfirmDialog to assert dialog semantics, ARIA attributes, and visible destructive actions using test IDs. Refactor expectMediaState helper to check both UI control state and underlying media signals for more robust playback state detection. * refactor(ui): improve segmented control accessibility and update danger color tokens Update SegmentedControl to support full keyboard navigation and focus management, enhancing accessibility. Replace string indicator in Select with icon, and update button danger variant to use new --danger-strong variable for hover states. Add danger-strong token to Tailwind config and globals. Refine dropzone disabled behavior, adjust focus ring for better contrast, and apply minor UI consistency tweaks across components. * feat(ui): convert SidebarNavLink to forwardRef component Refactor SidebarNavLink to use React.forwardRef, enabling parent components to access the underlying anchor element's ref. Update prop typing and function signature accordingly for improved composability and integration with higher-order components.
365 lines
14 KiB
TypeScript
365 lines
14 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useEffect } from 'react';
|
|
import { useConfig, ViewType } from '@/contexts/ConfigContext';
|
|
import { ReaderSidebarShell } from '@/components/reader/ReaderSidebarShell';
|
|
import {
|
|
SEGMENT_PRELOAD_DEPTH_MIN,
|
|
SEGMENT_PRELOAD_DEPTH_MAX,
|
|
SEGMENT_PRELOAD_SENTENCE_LOOKAHEAD_MIN,
|
|
SEGMENT_PRELOAD_SENTENCE_LOOKAHEAD_MAX,
|
|
TTS_SEGMENT_MAX_BLOCK_LENGTH_MIN,
|
|
TTS_SEGMENT_MAX_BLOCK_LENGTH_MAX,
|
|
TTS_SEGMENT_MAX_BLOCK_LENGTH_STEP,
|
|
clampSegmentPreloadDepth,
|
|
clampSegmentPreloadSentenceLookahead,
|
|
clampTtsSegmentMaxBlockLength,
|
|
} from '@/types/config';
|
|
import { IconButton, RangeInput, Section, ToggleRow, CheckItem, SegmentedControl } from '@/components/ui';
|
|
import { RefreshIcon, SparkleIcon } from '@/components/icons/Icons';
|
|
import type { ParsedPdfBlockKind, PdfParseStatus } from '@/types/parsed-pdf';
|
|
import { isForceReparseDisabled } from '@/lib/client/pdf/force-reparse';
|
|
|
|
const PDF_SKIP_KIND_OPTIONS: Array<{ kind: ParsedPdfBlockKind; label: string }> = [
|
|
{ kind: 'header', label: 'Header' },
|
|
{ kind: 'footer', label: 'Footer' },
|
|
{ kind: 'footnote', label: 'Footnote' },
|
|
{ kind: 'vision_footnote', label: 'Vision footnote' },
|
|
{ kind: 'figure_title', label: 'Figure title' },
|
|
{ kind: 'doc_title', label: 'Document title' },
|
|
{ kind: 'paragraph_title', label: 'Paragraph title' },
|
|
{ kind: 'abstract', label: 'Abstract' },
|
|
{ kind: 'algorithm', label: 'Algorithm' },
|
|
{ kind: 'aside_text', label: 'Aside text' },
|
|
{ kind: 'content', label: 'Content' },
|
|
{ kind: 'reference', label: 'Reference' },
|
|
{ kind: 'reference_content', label: 'Reference content' },
|
|
{ kind: 'text', label: 'Text' },
|
|
{ kind: 'number', label: 'Number' },
|
|
{ kind: 'formula', label: 'Formula' },
|
|
{ kind: 'formula_number', label: 'Formula number' },
|
|
{ kind: 'table', label: 'Table' },
|
|
{ kind: 'chart', label: 'Chart' },
|
|
{ kind: 'image', label: 'Image' },
|
|
{ kind: 'seal', label: 'Seal' },
|
|
];
|
|
|
|
const viewTypeTextMapping = [
|
|
{ id: 'single', name: 'Single Page' },
|
|
{ id: 'dual', name: 'Two Pages' },
|
|
{ id: 'scroll', name: 'Continuous Scroll' },
|
|
];
|
|
|
|
type RangeSettingProps = {
|
|
label: string;
|
|
value: number;
|
|
min: number;
|
|
max: number;
|
|
step: number;
|
|
description: string;
|
|
valueWidth?: string;
|
|
formatter?: (value: number) => string;
|
|
onChange: (value: number) => void;
|
|
};
|
|
|
|
function RangeSetting({
|
|
label,
|
|
value,
|
|
min,
|
|
max,
|
|
step,
|
|
description,
|
|
valueWidth = 'w-10',
|
|
formatter = (next) => String(next),
|
|
onChange,
|
|
}: RangeSettingProps) {
|
|
return (
|
|
<div className="space-y-1.5">
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wide text-muted">{label}</label>
|
|
<div className="flex items-center gap-3">
|
|
<RangeInput
|
|
min={min}
|
|
max={max}
|
|
step={step}
|
|
value={value}
|
|
onChange={(event) => onChange(Number(event.target.value))}
|
|
className="flex-1"
|
|
/>
|
|
<span className={`${valueWidth} text-xs font-semibold text-right text-foreground`}>{formatter(value)}</span>
|
|
</div>
|
|
<p className="text-xs text-muted">{description}</p>
|
|
</div>
|
|
);
|
|
}
|
|
|
|
export function DocumentSettings({ isOpen, setIsOpen, epub, html, pdf }: {
|
|
isOpen: boolean,
|
|
setIsOpen: (isOpen: boolean) => void,
|
|
epub?: boolean,
|
|
html?: boolean,
|
|
pdf?: {
|
|
parseStatus: PdfParseStatus | null;
|
|
parsedOverlayEnabled: boolean;
|
|
skipBlockKinds: ParsedPdfBlockKind[];
|
|
onToggleOverlay: (enabled: boolean) => void;
|
|
onToggleSkipKind: (kind: ParsedPdfBlockKind, enabled: boolean) => void;
|
|
onForceReparse: () => void;
|
|
}
|
|
}) {
|
|
const canWordHighlight = true;
|
|
const {
|
|
viewType,
|
|
skipBlank,
|
|
epubTheme,
|
|
segmentPreloadDepthPages,
|
|
segmentPreloadSentenceLookahead,
|
|
ttsSegmentMaxBlockLength,
|
|
updateConfigKey,
|
|
pdfHighlightEnabled,
|
|
epubHighlightEnabled,
|
|
pdfWordHighlightEnabled,
|
|
epubWordHighlightEnabled,
|
|
htmlHighlightEnabled,
|
|
htmlWordHighlightEnabled,
|
|
} = useConfig();
|
|
const selectedView = viewTypeTextMapping.find(v => v.id === viewType) || viewTypeTextMapping[0];
|
|
const isPdfMode = !epub && !html && !!pdf;
|
|
const [localPreloadDepth, setLocalPreloadDepth] = useState(segmentPreloadDepthPages);
|
|
const [localSentenceLookahead, setLocalSentenceLookahead] = useState(segmentPreloadSentenceLookahead);
|
|
const [localMaxBlockLength, setLocalMaxBlockLength] = useState(ttsSegmentMaxBlockLength);
|
|
|
|
useEffect(() => {
|
|
setLocalPreloadDepth(segmentPreloadDepthPages);
|
|
}, [segmentPreloadDepthPages]);
|
|
|
|
useEffect(() => {
|
|
setLocalSentenceLookahead(segmentPreloadSentenceLookahead);
|
|
}, [segmentPreloadSentenceLookahead]);
|
|
|
|
useEffect(() => {
|
|
setLocalMaxBlockLength(ttsSegmentMaxBlockLength);
|
|
}, [ttsSegmentMaxBlockLength]);
|
|
|
|
return (
|
|
<ReaderSidebarShell
|
|
isOpen={isOpen}
|
|
onClose={() => setIsOpen(false)}
|
|
ariaLabel="Document settings"
|
|
title="Reader Settings"
|
|
subtitle="Tune layout, preloading, and playback."
|
|
bodyClassName="flex-1 overflow-y-auto px-4 py-4 bg-[radial-gradient(circle_at_top_right,color-mix(in_srgb,var(--accent),transparent_92%),transparent_35%)]"
|
|
panelClassName="w-full sm:w-[30rem]"
|
|
>
|
|
<div className="space-y-4">
|
|
{isPdfMode && pdf && (
|
|
<Section
|
|
title="PDF Essentials"
|
|
subtitle="Critical parsing and playback controls."
|
|
variant="flat"
|
|
>
|
|
<div className="space-y-1.5">
|
|
<label className="block text-[11px] font-semibold uppercase tracking-wide text-muted">Page mode</label>
|
|
<SegmentedControl
|
|
value={selectedView.id as ViewType}
|
|
options={viewTypeTextMapping.map((view) => ({ value: view.id as ViewType, label: view.name }))}
|
|
onChange={(nextViewType) => updateConfigKey('viewType', nextViewType)}
|
|
ariaLabel="Page mode"
|
|
className="grid-cols-3"
|
|
/>
|
|
{selectedView.id === 'scroll' ? (
|
|
<p className="text-xs text-warning">Scroll mode may be slower on large PDFs.</p>
|
|
) : null}
|
|
</div>
|
|
<ToggleRow
|
|
label="Highlight text during playback"
|
|
description="Highlight the current sentence in PDF."
|
|
checked={pdfHighlightEnabled}
|
|
onChange={(checked) => updateConfigKey('pdfHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
<ToggleRow
|
|
label="Word-by-word highlighting"
|
|
description={`Highlight words using timing data${!canWordHighlight ? ' (not available on this server)' : ''}.`}
|
|
checked={pdfWordHighlightEnabled && pdfHighlightEnabled}
|
|
disabled={!pdfHighlightEnabled || !canWordHighlight}
|
|
onChange={(checked) => updateConfigKey('pdfWordHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
</Section>
|
|
)}
|
|
|
|
{isPdfMode && pdf && (
|
|
<Section
|
|
title="PDF Advanced"
|
|
subtitle="Optional visual and structural tuning."
|
|
variant="flat"
|
|
action={
|
|
<div className="flex flex-col items-end gap-1">
|
|
<span className="flex items-center gap-1 text-muted">
|
|
<SparkleIcon className="h-3 w-3 text-accent" />
|
|
<span className="text-xs">PP-DocLayout-V3</span>
|
|
</span>
|
|
<span className="flex items-center gap-1 text-xs text-muted">
|
|
<span>{pdf.parseStatus ?? 'pending'}</span>
|
|
<IconButton
|
|
size="xs"
|
|
className="shrink-0"
|
|
onClick={pdf.onForceReparse}
|
|
disabled={isForceReparseDisabled(pdf.parseStatus)}
|
|
title="Force reparse"
|
|
>
|
|
<RefreshIcon className={`h-3 w-3 ${isForceReparseDisabled(pdf.parseStatus) ? 'animate-spin' : ''}`} />
|
|
</IconButton>
|
|
</span>
|
|
</div>
|
|
}
|
|
>
|
|
<ToggleRow
|
|
label="Show block overlay"
|
|
description="Render detected block boxes and labels on the page."
|
|
checked={pdf.parsedOverlayEnabled}
|
|
onChange={pdf.onToggleOverlay}
|
|
disabled={pdf.parseStatus !== 'ready'}
|
|
variant="flat"
|
|
/>
|
|
<details className="rounded-md border border-offbase bg-surface-solid px-3 py-2">
|
|
<summary className="cursor-pointer text-[11px] font-semibold uppercase tracking-wide text-muted">
|
|
Skip Block Kinds While Reading Aloud
|
|
</summary>
|
|
<div className="grid grid-cols-2 gap-x-3 pt-2">
|
|
{PDF_SKIP_KIND_OPTIONS.map((option) => (
|
|
<CheckItem
|
|
key={option.kind}
|
|
label={option.label}
|
|
checked={pdf.skipBlockKinds.includes(option.kind)}
|
|
onChange={(enabled) => pdf.onToggleSkipKind(option.kind, enabled)}
|
|
/>
|
|
))}
|
|
</div>
|
|
</details>
|
|
</Section>
|
|
)}
|
|
|
|
<Section
|
|
title="Playback Flow"
|
|
subtitle="Segment and queue behavior."
|
|
variant="flat"
|
|
>
|
|
{!html && (
|
|
<ToggleRow
|
|
label="Skip blank pages"
|
|
description="Skip pages with no readable text."
|
|
checked={skipBlank}
|
|
onChange={(checked) => updateConfigKey('skipBlank', checked)}
|
|
variant="flat"
|
|
/>
|
|
)}
|
|
|
|
|
|
<div className="space-y-3 pt-1">
|
|
<RangeSetting
|
|
label="Segment preload depth"
|
|
value={localPreloadDepth}
|
|
min={SEGMENT_PRELOAD_DEPTH_MIN}
|
|
max={SEGMENT_PRELOAD_DEPTH_MAX}
|
|
step={1}
|
|
description="Upcoming pages/locations to queue."
|
|
formatter={(value) => String(value)}
|
|
onChange={(value) => {
|
|
const next = clampSegmentPreloadDepth(value);
|
|
setLocalPreloadDepth(next);
|
|
void updateConfigKey('segmentPreloadDepthPages', next);
|
|
}}
|
|
/>
|
|
|
|
<RangeSetting
|
|
label="Segment lookahead per page/location"
|
|
value={localSentenceLookahead}
|
|
min={SEGMENT_PRELOAD_SENTENCE_LOOKAHEAD_MIN}
|
|
max={SEGMENT_PRELOAD_SENTENCE_LOOKAHEAD_MAX}
|
|
step={1}
|
|
description="Segments to prepare per queued page/section."
|
|
formatter={(value) => String(value)}
|
|
onChange={(value) => {
|
|
const next = clampSegmentPreloadSentenceLookahead(value);
|
|
setLocalSentenceLookahead(next);
|
|
void updateConfigKey('segmentPreloadSentenceLookahead', next);
|
|
}}
|
|
/>
|
|
|
|
<RangeSetting
|
|
label="TTS segment max block length"
|
|
value={localMaxBlockLength}
|
|
min={TTS_SEGMENT_MAX_BLOCK_LENGTH_MIN}
|
|
max={TTS_SEGMENT_MAX_BLOCK_LENGTH_MAX}
|
|
step={TTS_SEGMENT_MAX_BLOCK_LENGTH_STEP}
|
|
description="Max characters per TTS segment block."
|
|
valueWidth="w-14"
|
|
formatter={(value) => String(value)}
|
|
onChange={(value) => {
|
|
const next = clampTtsSegmentMaxBlockLength(value);
|
|
setLocalMaxBlockLength(next);
|
|
void updateConfigKey('ttsSegmentMaxBlockLength', next);
|
|
}}
|
|
/>
|
|
</div>
|
|
</Section>
|
|
|
|
{epub && (
|
|
<Section
|
|
title="EPUB Appearance"
|
|
subtitle="Theme and highlighting in EPUB mode."
|
|
variant="flat"
|
|
>
|
|
<ToggleRow
|
|
label="Apply app theme"
|
|
description="Apply the app theme to EPUB (refresh may be needed)."
|
|
checked={epubTheme}
|
|
onChange={(checked) => updateConfigKey('epubTheme', checked)}
|
|
variant="flat"
|
|
/>
|
|
<ToggleRow
|
|
label="Highlight text during playback"
|
|
description="Highlight the current sentence in EPUB."
|
|
checked={epubHighlightEnabled}
|
|
onChange={(checked) => updateConfigKey('epubHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
<ToggleRow
|
|
label="Word-by-word highlighting"
|
|
description={`Highlight words using timing data${!canWordHighlight ? ' (not available on this server)' : ''}.`}
|
|
checked={epubWordHighlightEnabled && epubHighlightEnabled}
|
|
disabled={!epubHighlightEnabled || !canWordHighlight}
|
|
onChange={(checked) => updateConfigKey('epubWordHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
</Section>
|
|
)}
|
|
|
|
{html && (
|
|
<Section
|
|
title="Text & Markdown Highlighting"
|
|
subtitle="Playback highlighting in text/markdown mode."
|
|
variant="flat"
|
|
>
|
|
<ToggleRow
|
|
label="Highlight text during playback"
|
|
description="Highlight the current sentence in the rendered text."
|
|
checked={htmlHighlightEnabled}
|
|
onChange={(checked) => updateConfigKey('htmlHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
<ToggleRow
|
|
label="Word-by-word highlighting"
|
|
description={`Highlight words using timing data${!canWordHighlight ? ' (not available on this server)' : ''}.`}
|
|
checked={htmlWordHighlightEnabled && htmlHighlightEnabled}
|
|
disabled={!htmlHighlightEnabled || !canWordHighlight}
|
|
onChange={(checked) => updateConfigKey('htmlWordHighlightEnabled', checked)}
|
|
variant="flat"
|
|
/>
|
|
</Section>
|
|
)}
|
|
</div>
|
|
</ReaderSidebarShell>
|
|
);
|
|
}
|