import { html, nothing } from 'lit';
import { unsafeHTML } from 'lit/directives/unsafe-html.js';
import { LightElement, renderMarkdown } from '../../lib/base.js';
import { fileWatcher } from '../../lib/file-watcher.js';
/**
* Shared file-viewer engine. Holds all of the fetch / kind-detection /
* markdown-asset-rewriting / LaTeX-compile / live-watch logic plus `_renderBody`,
* driven purely by two methods: `_show(path)` and `_hide()`. It carries no
* navigation or page chrome of its own — subclasses (desktop ``
* and mobile ``) wire visibility/path to those methods
* and provide their own `render()` header.
*/
const IMG_EXTS = ['png', 'jpg', 'jpeg', 'gif', 'webp', 'bmp', 'ico', 'avif'];
const LATEX_EXTS = ['tex', 'latex'];
const TEXT_EXTS = [
'txt', 'md', 'markdown', 'rs', 'js', 'mjs', 'cjs', 'ts', 'tsx', 'jsx',
'py', 'json', 'yml', 'yaml', 'toml', 'sh', 'bash', 'zsh', 'fish',
'css', 'scss', 'less',
'sql', 'go', 'java', 'c', 'h', 'cpp', 'hpp', 'cc', 'kt', 'scala',
'lua', 'pl', 'php', 'rb', 'swift', 'dart',
'xml', 'csv', 'tsv', 'log', 'env', 'ini', 'cfg', 'conf',
'gitignore', 'dockerignore', 'editorconfig',
'vue', 'svelte', 'astro',
// LaTeX is also kept here as the fallback when compilation fails — kindFor
// still routes it to 'latex' so the viewer knows to attempt a compile first.
'tex', 'latex',
];
export function extOf(path) {
if (!path) return '';
const dot = path.lastIndexOf('.');
if (dot < 0) return '';
// Reject dots that are inside a directory segment, not the file extension.
if (path.indexOf('/', dot + 1) >= 0) return '';
return path.slice(dot + 1).toLowerCase();
}
export function kindFor(path) {
const ext = extOf(path);
// SVG is excluded from IMG_EXTS on purpose: rendered in a sandboxed iframe
// (not
), which both scales viewBox-only SVGs to fill the viewport and
// isolates any embedded