feat: 内置阅读器、批注笔记与 AI 助手,发布 1.3.0
新增 PDF/EPUB/MOBI/AZW 内置阅读器,PDF 分段读取支持超大文件, 批注、读书与画布笔记、封面生成与本地导入。AI 助手支持三种协议、 图像上下文与安全 Markdown 渲染,上下文范围改为 选中/当前页/全文, 页面与全文无需选中文本即可发送,全文会提示可能超出模型限制。 便携版输出目录固定为 PeopleLib-windows-x64,不再随版本号变化, 避免升级后 data/ 被遗留在旧目录。 Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
co-authored by
factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
parent
b8c8d24107
commit
3ccd044527
@@ -0,0 +1,96 @@
|
||||
(() => {
|
||||
const MarkdownIt = window.markdownit;
|
||||
const purifier = window.DOMPurify;
|
||||
const MAX_MARKDOWN_LENGTH = 256 * 1024;
|
||||
|
||||
function safeExternalUrl(value) {
|
||||
const raw = String(value || '').trim();
|
||||
if (!/^https?:\/\//i.test(raw)) return '';
|
||||
try {
|
||||
const url = new URL(raw);
|
||||
if (!/^https?:$/.test(url.protocol) || url.username || url.password) return '';
|
||||
return url.toString();
|
||||
} catch (error) {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if (typeof MarkdownIt !== 'function' || !purifier || typeof purifier.sanitize !== 'function') {
|
||||
window.AiMarkdown = Object.freeze({
|
||||
available: false,
|
||||
mount(root, source) {
|
||||
root.classList.add('ai-output-plain');
|
||||
root.textContent = String(source || '');
|
||||
},
|
||||
externalUrl() {
|
||||
return '';
|
||||
}
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
const markdown = new MarkdownIt({
|
||||
html: false,
|
||||
breaks: true,
|
||||
linkify: true,
|
||||
typographer: false
|
||||
});
|
||||
|
||||
markdown.renderer.rules.link_open = (tokens, index, options, env, renderer) => {
|
||||
const token = tokens[index];
|
||||
const url = safeExternalUrl(token.attrGet('href'));
|
||||
token.attrSet('href', '#');
|
||||
if (url) {
|
||||
token.attrSet('data-external-url', url);
|
||||
token.attrSet('rel', 'noopener noreferrer');
|
||||
} else {
|
||||
token.attrJoin('class', 'ai-md-link-blocked');
|
||||
token.attrSet('aria-disabled', 'true');
|
||||
}
|
||||
return renderer.renderToken(tokens, index, options);
|
||||
};
|
||||
|
||||
markdown.renderer.rules.image = (tokens, index) => {
|
||||
const alt = markdown.utils.escapeHtml(String(tokens[index].content || '').trim());
|
||||
const label = alt ? `图片:${alt}` : '外部图片已阻止';
|
||||
return `<span class="ai-md-image-placeholder" role="note">[${label}]</span>`;
|
||||
};
|
||||
|
||||
const sanitizeOptions = Object.freeze({
|
||||
ALLOWED_TAGS: [
|
||||
'p', 'br', 'strong', 'em', 's', 'blockquote', 'pre', 'code',
|
||||
'ul', 'ol', 'li', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
||||
'table', 'thead', 'tbody', 'tr', 'th', 'td', 'hr', 'a', 'span'
|
||||
],
|
||||
ALLOWED_ATTR: [
|
||||
'href', 'title', 'class', 'rel', 'role', 'aria-disabled', 'data-external-url'
|
||||
],
|
||||
ALLOW_DATA_ATTR: true,
|
||||
ALLOW_ARIA_ATTR: true
|
||||
});
|
||||
|
||||
function render(source) {
|
||||
return purifier.sanitize(markdown.render(String(source || '')), sanitizeOptions);
|
||||
}
|
||||
|
||||
window.AiMarkdown = Object.freeze({
|
||||
available: true,
|
||||
render,
|
||||
mount(root, source) {
|
||||
const text = String(source || '');
|
||||
if (text.length > MAX_MARKDOWN_LENGTH) {
|
||||
root.classList.add('ai-output-plain');
|
||||
root.textContent = text;
|
||||
return;
|
||||
}
|
||||
root.classList.remove('ai-output-plain');
|
||||
root.innerHTML = render(text);
|
||||
},
|
||||
externalUrl(target) {
|
||||
const link = target && typeof target.closest === 'function'
|
||||
? target.closest('a[data-external-url]')
|
||||
: null;
|
||||
return link ? safeExternalUrl(link.getAttribute('data-external-url')) : '';
|
||||
}
|
||||
});
|
||||
})();
|
||||
+130
-3
@@ -2,15 +2,43 @@ $('minBtn').onclick = () => window.api.minimize();
|
||||
$('maxBtn').onclick = () => window.api.maximize();
|
||||
$('closeBtn').onclick = () => window.api.close();
|
||||
|
||||
let uiTheme = 'dark';
|
||||
function applyUiTheme(value) {
|
||||
uiTheme = value === 'light' ? 'light' : 'dark';
|
||||
document.documentElement.dataset.uiTheme = uiTheme;
|
||||
const label = uiTheme === 'light' ? '切换到暗色主题' : '切换到明亮主题';
|
||||
$('uiThemeBtn').title = label;
|
||||
$('uiThemeBtn').setAttribute('aria-label', label);
|
||||
}
|
||||
|
||||
$('uiThemeBtn').onclick = async () => {
|
||||
const next = uiTheme === 'dark' ? 'light' : 'dark';
|
||||
applyUiTheme(next);
|
||||
const result = await window.api.ui.setTheme(next);
|
||||
if (!result || !result.ok) applyUiTheme(uiTheme === 'dark' ? 'light' : 'dark');
|
||||
};
|
||||
|
||||
async function initUiTheme() {
|
||||
const result = await window.api.ui.getTheme();
|
||||
applyUiTheme(result && result.ok ? result.data : 'dark');
|
||||
const unsubscribe = window.api.ui.onThemeChanged(applyUiTheme);
|
||||
if (typeof unsubscribe === 'function') {
|
||||
window.addEventListener('beforeunload', unsubscribe, { once: true });
|
||||
}
|
||||
}
|
||||
initUiTheme();
|
||||
|
||||
let currentTab = 'library';
|
||||
|
||||
function switchTab(tab) {
|
||||
currentTab = tab;
|
||||
document.querySelectorAll('.tab').forEach((t) => t.classList.toggle('active', t.dataset.tab === tab));
|
||||
$('libraryTab').classList.toggle('hidden', tab !== 'library');
|
||||
$('notesTab').classList.toggle('hidden', tab !== 'notes');
|
||||
$('browseTab').classList.toggle('hidden', tab !== 'browse');
|
||||
$('settingsTab').classList.toggle('hidden', tab !== 'settings');
|
||||
if (tab === 'library') Library.refresh(true);
|
||||
if (tab === 'notes') Notes.refresh();
|
||||
}
|
||||
|
||||
document.querySelectorAll('.tab').forEach((t) => {
|
||||
@@ -19,6 +47,17 @@ document.querySelectorAll('.tab').forEach((t) => {
|
||||
|
||||
Browse.init();
|
||||
Library.init();
|
||||
Notes.init();
|
||||
|
||||
if (window.api.reader && window.api.reader.onNotesChanged) {
|
||||
const unsubscribeNotes = window.api.reader.onNotesChanged(() => {
|
||||
Notes.markDirty();
|
||||
if (currentTab === 'notes') Notes.refresh(true);
|
||||
});
|
||||
if (typeof unsubscribeNotes === 'function') {
|
||||
window.addEventListener('beforeunload', unsubscribeNotes, { once: true });
|
||||
}
|
||||
}
|
||||
|
||||
const sortSelect = $('sortSelect');
|
||||
sortSelect.value = Library.getSortMode();
|
||||
@@ -60,9 +99,9 @@ $('zlibLoginBtn').onclick = async () => {
|
||||
const r = await openModal('Z-Library 登录', `
|
||||
<p style="margin-bottom:8px;">使用 Z-Library 账号登录(保存在本地 userData 目录)</p>
|
||||
<div style="display:flex;flex-direction:column;gap:8px;">
|
||||
<input id="zlibEmail" type="email" placeholder="邮箱" style="padding:8px;background:#222;border:1px solid #444;color:#eee;border-radius:4px;" />
|
||||
<input id="zlibPassword" type="password" placeholder="密码" style="padding:8px;background:#222;border:1px solid #444;color:#eee;border-radius:4px;" />
|
||||
<div id="zlibErr" style="color:#f66;font-size:12px;min-height:16px;"></div>
|
||||
<input id="zlibEmail" class="modal-input" type="email" placeholder="邮箱" />
|
||||
<input id="zlibPassword" class="modal-input" type="password" placeholder="密码" />
|
||||
<div id="zlibErr" class="note-form-error"></div>
|
||||
</div>
|
||||
`, async () => {
|
||||
const email = $('zlibEmail').value.trim();
|
||||
@@ -180,6 +219,94 @@ $('semanticKeyClearBtn').onclick = async () => {
|
||||
|
||||
refreshSemanticKeyStatus();
|
||||
|
||||
const AI_PROTOCOL_INFO = {
|
||||
anthropic: {
|
||||
label: 'Anthropic',
|
||||
baseUrl: 'https://api.anthropic.com/v1',
|
||||
model: 'claude-sonnet-4-5',
|
||||
hint: 'Anthropic 原生 Messages API,图像使用 base64 source 格式。'
|
||||
},
|
||||
'openai-responses': {
|
||||
label: 'OpenAI Responses',
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
model: 'gpt-4.1-mini',
|
||||
hint: 'OpenAI 原生 Responses API,使用 /v1/responses。'
|
||||
},
|
||||
'chat-completions': {
|
||||
label: 'OpenAI 兼容',
|
||||
baseUrl: 'https://api.openai.com/v1',
|
||||
model: 'gpt-4o-mini',
|
||||
hint: 'Chat Completions API,适用于 DeepSeek、Kimi、硅基流动、Ollama 等兼容服务。'
|
||||
}
|
||||
};
|
||||
|
||||
function syncAiProtocolUi() {
|
||||
const info = AI_PROTOCOL_INFO[$('aiProtocol').value] || AI_PROTOCOL_INFO['chat-completions'];
|
||||
$('aiBaseUrl').placeholder = info.baseUrl;
|
||||
$('aiModel').placeholder = info.model;
|
||||
$('aiProtocolHint').textContent = info.hint;
|
||||
}
|
||||
|
||||
$('aiProtocol').onchange = syncAiProtocolUi;
|
||||
|
||||
async function refreshAiStatus() {
|
||||
const r = await window.api.ai.status();
|
||||
const s = r.ok && r.data ? r.data : null;
|
||||
if (!s) { $('aiStatus').textContent = '状态读取失败'; return; }
|
||||
$('aiProtocol').value = s.protocol || 'chat-completions';
|
||||
$('aiBaseUrl').value = s.baseUrl || '';
|
||||
$('aiModel').value = s.model || '';
|
||||
$('aiVision').checked = !!s.vision;
|
||||
syncAiProtocolUi();
|
||||
const ready = s.ready === undefined ? (s.hasKey || s.isLocal) : !!s.ready;
|
||||
const protocol = AI_PROTOCOL_INFO[s.protocol] || AI_PROTOCOL_INFO['chat-completions'];
|
||||
if (ready) {
|
||||
$('aiStatus').textContent = `已就绪 · ${protocol.label} · ${s.model}${s.vision ? ' · 支持图像' : ''}${s.hasKey ? (s.persistent ? '(Key 已加密存储)' : '(Key 仅本次运行有效)') : '(本地模型,无需 Key)'}`;
|
||||
} else if (s.modelConfigured) {
|
||||
$('aiStatus').textContent = s.keyState === 'unreadable'
|
||||
? `模型已配置 · ${protocol.label} · ${s.model} · 已保存的 API Key 无法读取,请重新输入`
|
||||
: `模型已配置 · ${protocol.label} · ${s.model} · 尚缺 API Key`;
|
||||
} else {
|
||||
$('aiStatus').textContent = '尚未保存模型配置:请填写接口地址与模型名称';
|
||||
}
|
||||
$('aiKey').placeholder = s.hasKey
|
||||
? '已保存,留空表示不修改'
|
||||
: (s.keyState === 'unreadable'
|
||||
? '原 Key 无法读取,请重新输入'
|
||||
: (s.isLocal ? '本地模型可留空' : '必填(仅本地模型可留空)'));
|
||||
$('aiClearBtn').classList.toggle('hidden', !s.hasKey);
|
||||
}
|
||||
|
||||
$('aiSaveBtn').onclick = async () => {
|
||||
const btn = $('aiSaveBtn');
|
||||
const keyInput = $('aiKey');
|
||||
const cfg = {
|
||||
protocol: $('aiProtocol').value,
|
||||
baseUrl: $('aiBaseUrl').value.trim(),
|
||||
model: $('aiModel').value.trim(),
|
||||
vision: $('aiVision').checked
|
||||
};
|
||||
// 留空表示不改动已存的 Key,避免用户只改模型名就把 Key 清掉
|
||||
if (keyInput.value.trim()) cfg.apiKey = keyInput.value.trim();
|
||||
const r = await window.api.ai.save(cfg);
|
||||
keyInput.value = '';
|
||||
btn.textContent = r.ok ? '已保存 ✓' : '保存失败';
|
||||
btn.title = r.ok ? '' : (r.error || '');
|
||||
if (!r.ok) await confirmModal('保存失败', r.error || '请检查接口地址与模型名称');
|
||||
await refreshAiStatus();
|
||||
setTimeout(() => { btn.textContent = '保存'; }, 1500);
|
||||
};
|
||||
|
||||
$('aiClearBtn').onclick = async () => {
|
||||
const ok = await confirmModal('清除 AI 配置', '确定清除接口地址、模型与 API Key 吗?');
|
||||
if (!ok) return;
|
||||
await window.api.ai.clear();
|
||||
$('aiKey').value = '';
|
||||
await refreshAiStatus();
|
||||
};
|
||||
|
||||
refreshAiStatus();
|
||||
|
||||
async function runUpdateCheck(silent) {
|
||||
const statusEl = $('updateStatus');
|
||||
const btn = $('checkUpdateBtn');
|
||||
|
||||
@@ -0,0 +1,427 @@
|
||||
const FLOW_VERSION = 1;
|
||||
const MAX_OPS = 5000;
|
||||
const MAX_TEXT = 20000;
|
||||
const PAGE_ID_RE = /^[a-z0-9][a-z0-9_-]{0,127}$/i;
|
||||
const INLINE_FORMATS = ['bold', 'italic', 'underline', 'strike', 'code'];
|
||||
const BLOCK_FORMATS = ['header', 'blockquote', 'code-block', 'list'];
|
||||
const FLOW_FORMATS = [...INLINE_FORMATS, ...BLOCK_FORMATS, 'canvasPageBreak'];
|
||||
|
||||
function cloneJson(value) {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
function normalizedAttributes(value) {
|
||||
if (!value || typeof value !== 'object' || Array.isArray(value)) return null;
|
||||
const result = {};
|
||||
for (const key of INLINE_FORMATS) {
|
||||
if (value[key] === true) result[key] = true;
|
||||
}
|
||||
if (value.header === 1 || value.header === 2) result.header = value.header;
|
||||
if (value.blockquote === true) result.blockquote = true;
|
||||
if (value['code-block'] === true || value['code-block'] === 'plain') {
|
||||
result['code-block'] = 'plain';
|
||||
}
|
||||
if (value.list === 'ordered' || value.list === 'bullet') result.list = value.list;
|
||||
return Object.keys(result).length ? result : null;
|
||||
}
|
||||
|
||||
export function normalizeFlowContent(value) {
|
||||
if (!value || value.version !== FLOW_VERSION || !Array.isArray(value.ops)) return null;
|
||||
if (value.ops.length > MAX_OPS) return null;
|
||||
const ops = [];
|
||||
const pageIds = new Set();
|
||||
let textLength = 0;
|
||||
for (const raw of value.ops) {
|
||||
if (!raw || typeof raw !== 'object' || !Object.hasOwn(raw, 'insert')) continue;
|
||||
if (typeof raw.insert === 'string') {
|
||||
textLength += raw.insert.length;
|
||||
if (textLength > MAX_TEXT) return null;
|
||||
if (!raw.insert) continue;
|
||||
const attributes = normalizedAttributes(raw.attributes);
|
||||
ops.push({
|
||||
insert: raw.insert,
|
||||
...(attributes ? { attributes } : {})
|
||||
});
|
||||
continue;
|
||||
}
|
||||
const pageId = raw.insert && typeof raw.insert === 'object'
|
||||
? String(raw.insert.canvasPageBreak || '')
|
||||
: '';
|
||||
if (!PAGE_ID_RE.test(pageId) || pageIds.has(pageId)) continue;
|
||||
pageIds.add(pageId);
|
||||
ops.push({ insert: { canvasPageBreak: pageId } });
|
||||
}
|
||||
return ops.some((op) => (
|
||||
typeof op.insert === 'string' ? op.insert.trim() : !!op.insert.canvasPageBreak
|
||||
)) ? { version: FLOW_VERSION, ops } : null;
|
||||
}
|
||||
|
||||
export function flowPlainText(value) {
|
||||
const flow = normalizeFlowContent(value);
|
||||
if (!flow) return '';
|
||||
return flow.ops
|
||||
.filter((op) => typeof op.insert === 'string')
|
||||
.map((op) => op.insert)
|
||||
.join('')
|
||||
.replace(/\n$/, '')
|
||||
.slice(0, MAX_TEXT);
|
||||
}
|
||||
|
||||
function registerPageBreak(Quill) {
|
||||
if (globalThis.__peoplelibCanvasPageBreakRegistered) return;
|
||||
const BlockEmbed = Quill.import('blots/block/embed');
|
||||
class CanvasPageBreak extends BlockEmbed {
|
||||
static create(value) {
|
||||
const node = super.create();
|
||||
const pageId = String(value || '');
|
||||
if (PAGE_ID_RE.test(pageId)) node.dataset.pageId = pageId;
|
||||
node.setAttribute('aria-hidden', 'true');
|
||||
return node;
|
||||
}
|
||||
|
||||
static value(node) {
|
||||
return String(node?.dataset?.pageId || '');
|
||||
}
|
||||
}
|
||||
CanvasPageBreak.blotName = 'canvasPageBreak';
|
||||
CanvasPageBreak.tagName = 'div';
|
||||
CanvasPageBreak.className = 'canvas-flow-page-break';
|
||||
Quill.register(CanvasPageBreak, true);
|
||||
globalThis.__peoplelibCanvasPageBreakRegistered = true;
|
||||
}
|
||||
|
||||
function makeFormatButton(name, title, value = null) {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = `ql-${name}`;
|
||||
if (value != null) button.value = value;
|
||||
button.title = title;
|
||||
button.setAttribute('aria-label', title);
|
||||
return button;
|
||||
}
|
||||
|
||||
function createToolbar() {
|
||||
const toolbar = document.createElement('div');
|
||||
toolbar.className = 'canvas-flow-toolbar ql-toolbar ql-snow';
|
||||
toolbar.setAttribute('role', 'toolbar');
|
||||
toolbar.setAttribute('aria-label', '全局文本格式');
|
||||
const formats = document.createElement('span');
|
||||
formats.className = 'ql-formats';
|
||||
const header = document.createElement('select');
|
||||
header.className = 'ql-header';
|
||||
header.title = '段落样式';
|
||||
[
|
||||
['', '正文'],
|
||||
['1', '一级标题'],
|
||||
['2', '二级标题']
|
||||
].forEach(([value, label], index) => {
|
||||
const option = document.createElement('option');
|
||||
option.value = value;
|
||||
option.textContent = label;
|
||||
option.selected = index === 0;
|
||||
header.appendChild(option);
|
||||
});
|
||||
formats.append(
|
||||
header,
|
||||
makeFormatButton('bold', '加粗'),
|
||||
makeFormatButton('italic', '斜体'),
|
||||
makeFormatButton('underline', '下划线'),
|
||||
makeFormatButton('strike', '删除线'),
|
||||
makeFormatButton('blockquote', '引用'),
|
||||
makeFormatButton('code-block', '代码块'),
|
||||
makeFormatButton('list', '有序列表', 'ordered'),
|
||||
makeFormatButton('list', '无序列表', 'bullet')
|
||||
);
|
||||
toolbar.appendChild(formats);
|
||||
return toolbar;
|
||||
}
|
||||
|
||||
function dataUrl(value) {
|
||||
const bytes = new TextEncoder().encode(value);
|
||||
let binary = '';
|
||||
for (let offset = 0; offset < bytes.length; offset += 0x8000) {
|
||||
binary += String.fromCharCode(...bytes.subarray(offset, offset + 0x8000));
|
||||
}
|
||||
return `data:image/svg+xml;base64,${btoa(binary)}`;
|
||||
}
|
||||
|
||||
function imageFromUrl(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const image = new Image();
|
||||
image.onload = () => resolve(image);
|
||||
image.onerror = () => reject(new Error('全局文本导出失败'));
|
||||
image.src = url;
|
||||
});
|
||||
}
|
||||
|
||||
export function mountFlowText(layerHost, toolbarHost, initialContent, options = {}) {
|
||||
if (typeof window.Quill !== 'function') throw new Error('富文本编辑组件加载失败');
|
||||
registerPageBreak(window.Quill);
|
||||
layerHost.textContent = '';
|
||||
toolbarHost.textContent = '';
|
||||
|
||||
const toolbar = createToolbar();
|
||||
const editorHost = document.createElement('div');
|
||||
editorHost.className = 'canvas-flow-quill';
|
||||
layerHost.appendChild(editorHost);
|
||||
toolbarHost.appendChild(toolbar);
|
||||
|
||||
const quill = new window.Quill(editorHost, {
|
||||
theme: 'snow',
|
||||
placeholder: '输入正文,内容超过纸张后会自动分页',
|
||||
formats: FLOW_FORMATS,
|
||||
modules: {
|
||||
toolbar,
|
||||
history: {
|
||||
delay: 700,
|
||||
maxStack: 100,
|
||||
userOnly: true
|
||||
}
|
||||
}
|
||||
});
|
||||
const surface = quill.root;
|
||||
surface.classList.add('canvas-flow-surface');
|
||||
surface.setAttribute('aria-label', '画布全局文本');
|
||||
surface.setAttribute('aria-multiline', 'true');
|
||||
|
||||
const initial = normalizeFlowContent(initialContent);
|
||||
if (initial) quill.setContents(initial.ops, 'silent');
|
||||
quill.history.clear();
|
||||
|
||||
let destroyed = false;
|
||||
let active = false;
|
||||
let frame = 0;
|
||||
let secondFrame = 0;
|
||||
let measuredPages = 1;
|
||||
let suppressUserFollowSelection = false;
|
||||
let layout = { width: 640, height: 960, gap: 48, pageIndex: 0 };
|
||||
let pendingResolvers = [];
|
||||
|
||||
function content() {
|
||||
return normalizeFlowContent({
|
||||
version: FLOW_VERSION,
|
||||
ops: quill.getContents().ops
|
||||
});
|
||||
}
|
||||
|
||||
function resolvePending() {
|
||||
const resolvers = pendingResolvers;
|
||||
pendingResolvers = [];
|
||||
resolvers.forEach((resolve) => resolve());
|
||||
}
|
||||
|
||||
function pageCount() {
|
||||
const rootRect = surface.getBoundingClientRect();
|
||||
const span = layout.width + layout.gap;
|
||||
let maxColumn = 0;
|
||||
for (const child of surface.children) {
|
||||
for (const rect of child.getClientRects()) {
|
||||
const relativeLeft = rect.left - rootRect.left;
|
||||
maxColumn = Math.max(maxColumn, Math.max(0, Math.round(relativeLeft / span)));
|
||||
}
|
||||
}
|
||||
const scrollColumns = Math.max(1, Math.ceil(
|
||||
(Math.max(layout.width, surface.scrollWidth) + layout.gap) / span
|
||||
));
|
||||
return Math.max(1, maxColumn + 1, scrollColumns);
|
||||
}
|
||||
|
||||
function measure() {
|
||||
if (destroyed) return;
|
||||
const next = pageCount();
|
||||
if (next !== measuredPages) {
|
||||
measuredPages = next;
|
||||
options.onPageCount?.(next);
|
||||
}
|
||||
options.onHistoryChange?.();
|
||||
resolvePending();
|
||||
}
|
||||
|
||||
function selectionPage() {
|
||||
const range = quill.getSelection();
|
||||
if (!range) return layout.pageIndex;
|
||||
const index = Math.min(Math.max(0, range.index), Math.max(0, quill.getLength() - 1));
|
||||
const bounds = quill.getBounds(index, Math.max(0, range.length));
|
||||
const span = layout.width + layout.gap;
|
||||
return Math.max(0, Math.round((Number(bounds?.left) || 0) / span));
|
||||
}
|
||||
|
||||
function followSelection() {
|
||||
if (!active || destroyed) return;
|
||||
options.onActivePage?.(selectionPage());
|
||||
}
|
||||
|
||||
function scheduleLayout() {
|
||||
if (destroyed) return Promise.resolve();
|
||||
const promise = new Promise((resolve) => pendingResolvers.push(resolve));
|
||||
if (frame) cancelAnimationFrame(frame);
|
||||
if (secondFrame) cancelAnimationFrame(secondFrame);
|
||||
frame = requestAnimationFrame(() => {
|
||||
frame = 0;
|
||||
secondFrame = requestAnimationFrame(() => {
|
||||
secondFrame = 0;
|
||||
measure();
|
||||
});
|
||||
});
|
||||
return promise;
|
||||
}
|
||||
|
||||
function applyLayout() {
|
||||
const container = surface.parentElement;
|
||||
const span = layout.width + layout.gap;
|
||||
layerHost.style.width = `${layout.width}px`;
|
||||
layerHost.style.height = `${layout.height}px`;
|
||||
if (container) {
|
||||
container.style.width = `${layout.width}px`;
|
||||
container.style.height = `${layout.height}px`;
|
||||
}
|
||||
surface.style.width = `${layout.width}px`;
|
||||
surface.style.height = `${layout.height}px`;
|
||||
surface.style.columnWidth = `${layout.width}px`;
|
||||
surface.style.columnGap = `${layout.gap}px`;
|
||||
surface.style.transform = `translateX(${-layout.pageIndex * span}px)`;
|
||||
scheduleLayout();
|
||||
}
|
||||
|
||||
function findPageBreak(pageId) {
|
||||
const target = String(pageId || '');
|
||||
let index = 0;
|
||||
for (const op of quill.getContents().ops) {
|
||||
if (op.insert && typeof op.insert === 'object'
|
||||
&& op.insert.canvasPageBreak === target) return index;
|
||||
index += typeof op.insert === 'string' ? op.insert.length : 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
quill.on('text-change', (delta, oldDelta, source) => {
|
||||
if (source === 'user'
|
||||
&& (quill.getLength() - 1 > MAX_TEXT || quill.getContents().ops.length > MAX_OPS)) {
|
||||
quill.setContents(oldDelta, 'silent');
|
||||
options.onError?.(`全局文本最多支持 ${MAX_TEXT.toLocaleString()} 个字符`);
|
||||
scheduleLayout();
|
||||
return;
|
||||
}
|
||||
const layoutPromise = scheduleLayout();
|
||||
options.onHistoryChange?.();
|
||||
if (source === 'user') {
|
||||
const follow = !suppressUserFollowSelection;
|
||||
suppressUserFollowSelection = false;
|
||||
options.onChange?.(content(), delta, oldDelta);
|
||||
if (follow) layoutPromise.then(followSelection);
|
||||
}
|
||||
});
|
||||
quill.on('selection-change', (range, oldRange, source) => {
|
||||
if (source === 'user' && range) requestAnimationFrame(followSelection);
|
||||
});
|
||||
|
||||
return {
|
||||
content,
|
||||
text: () => flowPlainText(content()),
|
||||
hasContent: () => !!flowPlainText(content()).trim(),
|
||||
pageBreakIds() {
|
||||
const ids = [];
|
||||
for (const op of content()?.ops || []) {
|
||||
if (op.insert && typeof op.insert === 'object' && op.insert.canvasPageBreak) {
|
||||
ids.push(op.insert.canvasPageBreak);
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
},
|
||||
activePageIndex: selectionPage,
|
||||
insertPageBreak(pageId) {
|
||||
const id = String(pageId || '');
|
||||
if (!PAGE_ID_RE.test(id) || findPageBreak(id) >= 0) return false;
|
||||
const range = quill.getSelection();
|
||||
const index = range
|
||||
? Math.min(quill.getLength() - 1, range.index + range.length)
|
||||
: Math.max(0, quill.getLength() - 1);
|
||||
suppressUserFollowSelection = true;
|
||||
quill.insertEmbed(index, 'canvasPageBreak', id, 'user');
|
||||
quill.setSelection(index + 1, 0, 'silent');
|
||||
scheduleLayout();
|
||||
return true;
|
||||
},
|
||||
removePageBreak(pageId) {
|
||||
const index = findPageBreak(pageId);
|
||||
if (index < 0) return false;
|
||||
suppressUserFollowSelection = true;
|
||||
quill.deleteText(index, 1, 'user');
|
||||
if (index > 0 && quill.getText(index - 1, 1) === '\n') {
|
||||
suppressUserFollowSelection = true;
|
||||
quill.deleteText(index - 1, 1, 'user');
|
||||
}
|
||||
scheduleLayout();
|
||||
return true;
|
||||
},
|
||||
setActive(nextActive) {
|
||||
active = Boolean(nextActive);
|
||||
toolbarHost.classList.toggle('hidden', !active);
|
||||
layerHost.classList.toggle('canvas-flow-active', active);
|
||||
quill.enable(active);
|
||||
},
|
||||
setLayout(width, height, pageIndex) {
|
||||
layout = {
|
||||
width: Math.max(240, Math.round(Number(width) || 640)),
|
||||
height: Math.max(240, Math.round(Number(height) || 960)),
|
||||
gap: 48,
|
||||
pageIndex: Math.max(0, Math.round(Number(pageIndex) || 0))
|
||||
};
|
||||
applyLayout();
|
||||
},
|
||||
setPageIndex(pageIndex) {
|
||||
layout.pageIndex = Math.max(0, Math.round(Number(pageIndex) || 0));
|
||||
applyLayout();
|
||||
},
|
||||
focus() {
|
||||
if (!active) return;
|
||||
quill.focus();
|
||||
},
|
||||
undo() {
|
||||
quill.history.undo();
|
||||
scheduleLayout();
|
||||
},
|
||||
redo() {
|
||||
quill.history.redo();
|
||||
scheduleLayout();
|
||||
},
|
||||
canUndo: () => (quill.history.stack?.undo?.length || 0) > 0,
|
||||
canRedo: () => (quill.history.stack?.redo?.length || 0) > 0,
|
||||
async flush() {
|
||||
await scheduleLayout();
|
||||
return cloneJson(content());
|
||||
},
|
||||
async renderPage(pageIndex, pageWidth, pageHeight) {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = pageWidth;
|
||||
canvas.height = pageHeight;
|
||||
if (!flowPlainText(content()).trim()) return canvas;
|
||||
const clone = surface.cloneNode(true);
|
||||
clone.removeAttribute('contenteditable');
|
||||
clone.classList.remove('ql-blank');
|
||||
clone.querySelectorAll('.ql-ui, .ql-cursor').forEach((node) => node.remove());
|
||||
clone.style.position = 'relative';
|
||||
clone.style.margin = '0';
|
||||
clone.style.padding = '0';
|
||||
clone.style.overflow = 'visible';
|
||||
clone.style.color = '#111827';
|
||||
clone.style.background = 'transparent';
|
||||
clone.style.transform = `translateX(${-Math.max(0, pageIndex) * (layout.width + layout.gap)}px)`;
|
||||
const x = Math.max(0, Math.round((pageWidth - layout.width) / 2));
|
||||
const y = Math.max(0, Math.round((pageHeight - layout.height) / 2));
|
||||
const serialized = new XMLSerializer().serializeToString(clone);
|
||||
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${pageWidth}" height="${pageHeight}"><foreignObject x="${x}" y="${y}" width="${layout.width}" height="${layout.height}"><div xmlns="http://www.w3.org/1999/xhtml" style="width:${layout.width}px;height:${layout.height}px;overflow:hidden;font-family:'Microsoft YaHei','Segoe UI',sans-serif;font-size:16px;line-height:1.7;color:#111827">${serialized}</div></foreignObject></svg>`;
|
||||
const image = await imageFromUrl(dataUrl(svg));
|
||||
canvas.getContext('2d')?.drawImage(image, 0, 0, pageWidth, pageHeight);
|
||||
return canvas;
|
||||
},
|
||||
destroy() {
|
||||
destroyed = true;
|
||||
if (frame) cancelAnimationFrame(frame);
|
||||
if (secondFrame) cancelAnimationFrame(secondFrame);
|
||||
resolvePending();
|
||||
toolbarHost.textContent = '';
|
||||
layerHost.textContent = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
||||
const { contextBridge, ipcRenderer } = require('electron');
|
||||
|
||||
contextBridge.exposeInMainWorld('coverBridge', {
|
||||
onExtract: (callback) => {
|
||||
if (typeof callback !== 'function') return;
|
||||
ipcRenderer.on('cover:extract', (_event, payload) => callback(payload));
|
||||
},
|
||||
ready: () => ipcRenderer.send('cover:ready'),
|
||||
complete: (payload) => ipcRenderer.send('cover:result', payload)
|
||||
});
|
||||
@@ -0,0 +1,12 @@
|
||||
<!doctype html>
|
||||
<html lang="zh-CN">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data: blob:; worker-src 'self' blob:; script-src 'self'" />
|
||||
<title>封面生成器</title>
|
||||
</head>
|
||||
<body>
|
||||
<script src="vendor/jszip.min.js"></script>
|
||||
<script type="module" src="cover-renderer.mjs"></script>
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,295 @@
|
||||
import * as pdfjs from './vendor/pdf.min.mjs';
|
||||
|
||||
pdfjs.GlobalWorkerOptions.workerSrc = new URL('./vendor/pdf.worker.min.mjs', import.meta.url).href;
|
||||
|
||||
const WIDTH = 320;
|
||||
const HEIGHT = 440;
|
||||
const PDF_ASSET_OPTIONS = Object.freeze({
|
||||
cMapUrl: new URL('./vendor/pdfjs/cmaps/', import.meta.url).href,
|
||||
cMapPacked: true,
|
||||
iccUrl: new URL('./vendor/pdfjs/iccs/', import.meta.url).href,
|
||||
standardFontDataUrl: new URL('./vendor/pdfjs/standard_fonts/', import.meta.url).href,
|
||||
wasmUrl: new URL('./vendor/pdfjs/wasm/', import.meta.url).href
|
||||
});
|
||||
const IMAGE_MIMES = new Set([
|
||||
'image/jpeg', 'image/png', 'image/webp', 'image/gif', 'image/bmp', 'image/svg+xml', 'image/avif'
|
||||
]);
|
||||
const EXT_MIMES = {
|
||||
jpg: 'image/jpeg',
|
||||
jpeg: 'image/jpeg',
|
||||
png: 'image/png',
|
||||
webp: 'image/webp',
|
||||
gif: 'image/gif',
|
||||
bmp: 'image/bmp',
|
||||
svg: 'image/svg+xml',
|
||||
avif: 'image/avif'
|
||||
};
|
||||
|
||||
function toBytes(value) {
|
||||
if (value instanceof Uint8Array) return value.slice();
|
||||
if (value instanceof ArrayBuffer) return new Uint8Array(value.slice(0));
|
||||
if (value && value.buffer instanceof ArrayBuffer) {
|
||||
return new Uint8Array(value.buffer, value.byteOffset || 0, value.byteLength).slice();
|
||||
}
|
||||
throw new Error('文件数据无效');
|
||||
}
|
||||
|
||||
function resolvePath(base, href) {
|
||||
const raw = String(href || '').split('#')[0].split('?')[0].trim();
|
||||
if (!raw || /^[a-z][a-z0-9+.\-]*:/i.test(raw)) return '';
|
||||
const parts = (raw.startsWith('/') ? raw.slice(1) : base + raw).split('/');
|
||||
const out = [];
|
||||
for (const part of parts) {
|
||||
if (!part || part === '.') continue;
|
||||
if (part === '..') out.pop();
|
||||
else out.push(part);
|
||||
}
|
||||
return out.join('/');
|
||||
}
|
||||
|
||||
function zipEntry(zip, name) {
|
||||
let entry = zip.file(name);
|
||||
if (entry) return entry;
|
||||
let decoded = name;
|
||||
try { decoded = decodeURIComponent(name); } catch (e) { /* keep original */ }
|
||||
const target = decoded.toLowerCase();
|
||||
return (zip.file(/./) || []).find((item) => {
|
||||
let itemName = item.name;
|
||||
try { itemName = decodeURIComponent(itemName); } catch (e) { /* keep original */ }
|
||||
return itemName.toLowerCase() === target;
|
||||
}) || null;
|
||||
}
|
||||
|
||||
async function zipText(entry, maxBytes) {
|
||||
const declared = entry && entry._data && Number(entry._data.uncompressedSize);
|
||||
if (!entry || (Number.isFinite(declared) && declared > maxBytes)) throw new Error('EPUB 资源过大');
|
||||
const text = await entry.async('text');
|
||||
if (text.length > maxBytes) throw new Error('EPUB 资源过大');
|
||||
return text;
|
||||
}
|
||||
|
||||
async function zipBytes(entry, maxBytes) {
|
||||
const declared = entry && entry._data && Number(entry._data.uncompressedSize);
|
||||
if (!entry || (Number.isFinite(declared) && declared > maxBytes)) return null;
|
||||
const bytes = await entry.async('uint8array');
|
||||
return bytes.length <= maxBytes ? bytes : null;
|
||||
}
|
||||
|
||||
function canvasToJpeg(canvas) {
|
||||
return canvas.toDataURL('image/jpeg', 0.86);
|
||||
}
|
||||
|
||||
async function pdfCover(bytes) {
|
||||
const loadingTask = pdfjs.getDocument({
|
||||
...PDF_ASSET_OPTIONS,
|
||||
data: toBytes(bytes),
|
||||
isEvalSupported: false,
|
||||
enableXfa: false
|
||||
});
|
||||
let doc;
|
||||
try {
|
||||
doc = await loadingTask.promise;
|
||||
const page = await doc.getPage(1);
|
||||
const base = page.getViewport({ scale: 1 });
|
||||
const scale = Math.min(WIDTH / base.width, HEIGHT / base.height);
|
||||
const viewport = page.getViewport({ scale });
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = Math.max(1, Math.round(viewport.width));
|
||||
canvas.height = Math.max(1, Math.round(viewport.height));
|
||||
const context = canvas.getContext('2d', { alpha: false });
|
||||
context.fillStyle = '#fff';
|
||||
context.fillRect(0, 0, canvas.width, canvas.height);
|
||||
await page.render({ canvasContext: context, viewport }).promise;
|
||||
page.cleanup();
|
||||
const cover = document.createElement('canvas');
|
||||
cover.width = WIDTH;
|
||||
cover.height = HEIGHT;
|
||||
const coverContext = cover.getContext('2d', { alpha: false });
|
||||
coverContext.fillStyle = '#e7e3dc';
|
||||
coverContext.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
coverContext.drawImage(canvas, (WIDTH - canvas.width) / 2, (HEIGHT - canvas.height) / 2);
|
||||
return canvasToJpeg(cover);
|
||||
} finally {
|
||||
if (doc && typeof doc.destroy === 'function') await doc.destroy();
|
||||
else if (loadingTask && typeof loadingTask.destroy === 'function') await loadingTask.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
async function loadImage(data, mime) {
|
||||
const blobUrl = URL.createObjectURL(new Blob([data], { type: mime }));
|
||||
try {
|
||||
const image = new Image();
|
||||
image.decoding = 'async';
|
||||
image.src = blobUrl;
|
||||
await image.decode();
|
||||
return image;
|
||||
} finally {
|
||||
URL.revokeObjectURL(blobUrl);
|
||||
}
|
||||
}
|
||||
|
||||
function imageCover(image) {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = WIDTH;
|
||||
canvas.height = HEIGHT;
|
||||
const context = canvas.getContext('2d', { alpha: false });
|
||||
context.fillStyle = '#f5f1e8';
|
||||
context.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
const scale = Math.min(WIDTH / image.naturalWidth, HEIGHT / image.naturalHeight);
|
||||
const width = Math.max(1, image.naturalWidth * scale);
|
||||
const height = Math.max(1, image.naturalHeight * scale);
|
||||
context.drawImage(image, (WIDTH - width) / 2, (HEIGHT - height) / 2, width, height);
|
||||
return canvasToJpeg(canvas);
|
||||
}
|
||||
|
||||
function titleCover(title, authors) {
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = WIDTH;
|
||||
canvas.height = HEIGHT;
|
||||
const context = canvas.getContext('2d', { alpha: false });
|
||||
const gradient = context.createLinearGradient(0, 0, WIDTH, HEIGHT);
|
||||
gradient.addColorStop(0, '#242225');
|
||||
gradient.addColorStop(1, '#6f5546');
|
||||
context.fillStyle = gradient;
|
||||
context.fillRect(0, 0, WIDTH, HEIGHT);
|
||||
context.fillStyle = '#c49a6c';
|
||||
context.fillRect(28, 34, 3, HEIGHT - 68);
|
||||
|
||||
const text = String(title || '未命名书籍').trim() || '未命名书籍';
|
||||
context.fillStyle = '#fffaf2';
|
||||
context.font = '600 28px sans-serif';
|
||||
context.textBaseline = 'top';
|
||||
const maxWidth = WIDTH - 76;
|
||||
const lines = [];
|
||||
let line = '';
|
||||
for (const char of text) {
|
||||
const next = line + char;
|
||||
if (line && context.measureText(next).width > maxWidth) {
|
||||
lines.push(line);
|
||||
line = char;
|
||||
if (lines.length === 6) break;
|
||||
} else {
|
||||
line = next;
|
||||
}
|
||||
}
|
||||
if (line && lines.length < 7) lines.push(line);
|
||||
lines.forEach((value, index) => context.fillText(value, 48, 84 + index * 38, maxWidth));
|
||||
|
||||
const authorText = (Array.isArray(authors) ? authors : []).filter(Boolean).join(' · ');
|
||||
if (authorText) {
|
||||
context.fillStyle = '#decbb8';
|
||||
context.font = '16px sans-serif';
|
||||
context.fillText(authorText, 48, HEIGHT - 72, maxWidth);
|
||||
}
|
||||
return canvasToJpeg(canvas);
|
||||
}
|
||||
|
||||
async function epubCover(bytes, fallbackTitle, authors) {
|
||||
if (!window.JSZip) throw new Error('缺少 JSZip');
|
||||
const zip = await window.JSZip.loadAsync(toBytes(bytes));
|
||||
const encryptedPaths = new Set();
|
||||
const encryptionEntry = zipEntry(zip, 'META-INF/encryption.xml');
|
||||
if (encryptionEntry) {
|
||||
try {
|
||||
const encryption = new DOMParser().parseFromString(await zipText(encryptionEntry, 1024 * 1024), 'text/xml');
|
||||
Array.from(encryption.getElementsByTagName('*'))
|
||||
.filter((item) => item.localName === 'CipherReference')
|
||||
.forEach((item) => {
|
||||
const encryptedPath = resolvePath('', item.getAttribute('URI'));
|
||||
if (encryptedPath) encryptedPaths.add(encryptedPath);
|
||||
});
|
||||
} catch (e) { /* individual encrypted resources will fail safely if selected */ }
|
||||
}
|
||||
const containerEntry = zipEntry(zip, 'META-INF/container.xml');
|
||||
if (!containerEntry) throw new Error('EPUB 缺少 container.xml');
|
||||
const container = new DOMParser().parseFromString(await zipText(containerEntry, 512 * 1024), 'text/xml');
|
||||
const rootfile = container.querySelector('rootfile');
|
||||
const opfPath = resolvePath('', rootfile && rootfile.getAttribute('full-path'));
|
||||
const opfEntry = zipEntry(zip, opfPath);
|
||||
if (!opfEntry) throw new Error('EPUB 缺少 OPF');
|
||||
const opf = new DOMParser().parseFromString(await zipText(opfEntry, 2 * 1024 * 1024), 'text/xml');
|
||||
if (opf.querySelector('parsererror')) throw new Error('EPUB 的 OPF 无法解析');
|
||||
const opfBase = opfPath.includes('/') ? opfPath.slice(0, opfPath.lastIndexOf('/') + 1) : '';
|
||||
const manifest = Array.from(opf.querySelectorAll('manifest > item, item')).map((item) => ({
|
||||
id: item.getAttribute('id') || '',
|
||||
href: item.getAttribute('href') || '',
|
||||
mime: (item.getAttribute('media-type') || '').toLowerCase(),
|
||||
properties: (item.getAttribute('properties') || '').split(/\s+/)
|
||||
})).filter((item, index, all) => item.id && all.findIndex((other) => other.id === item.id) === index);
|
||||
manifest.forEach((item) => { item.path = resolvePath(opfBase, item.href); });
|
||||
const byId = new Map(manifest.map((item) => [item.id, item]));
|
||||
const byPath = new Map(manifest.map((item) => [item.path, item]));
|
||||
const mimeFromPath = (value) => EXT_MIMES[value.slice(value.lastIndexOf('.') + 1).toLowerCase()] || '';
|
||||
const pageImage = async (pagePath) => {
|
||||
const entry = zipEntry(zip, pagePath);
|
||||
if (!entry) return null;
|
||||
let text;
|
||||
try { text = await zipText(entry, 2 * 1024 * 1024); } catch (e) { return null; }
|
||||
const page = new DOMParser().parseFromString(text, 'text/html');
|
||||
const image = page.querySelector('img[src], image[href], image[xlink\\:href]');
|
||||
if (!image) return null;
|
||||
const href = image.getAttribute('src') || image.getAttribute('href') || image.getAttribute('xlink:href');
|
||||
const base = pagePath.includes('/') ? pagePath.slice(0, pagePath.lastIndexOf('/') + 1) : '';
|
||||
const imagePath = resolvePath(base, href);
|
||||
const known = byPath.get(imagePath);
|
||||
return imagePath ? { path: imagePath, mime: (known && known.mime) || mimeFromPath(imagePath) } : null;
|
||||
};
|
||||
const coverMeta = Array.from(opf.querySelectorAll('meta')).find((item) => (
|
||||
(item.getAttribute('name') || '').toLowerCase() === 'cover'
|
||||
));
|
||||
const declared = manifest.find((item) => item.properties.includes('cover-image'))
|
||||
|| (coverMeta && byId.get(coverMeta.getAttribute('content')));
|
||||
const guideRef = Array.from(opf.querySelectorAll('guide > reference, reference')).find((item) => (
|
||||
/\bcover\b/i.test(item.getAttribute('type') || '')
|
||||
));
|
||||
const guidePath = resolvePath(opfBase, guideRef && guideRef.getAttribute('href'));
|
||||
let guideCandidate = guidePath && byPath.get(guidePath);
|
||||
if (guidePath && (!guideCandidate || !IMAGE_MIMES.has(guideCandidate.mime))) {
|
||||
guideCandidate = await pageImage(guidePath);
|
||||
}
|
||||
const firstSpineRef = opf.querySelector('spine > itemref, itemref');
|
||||
const firstSpineItem = firstSpineRef && byId.get(firstSpineRef.getAttribute('idref'));
|
||||
const firstPageCandidate = firstSpineItem && await pageImage(firstSpineItem.path);
|
||||
const candidates = [
|
||||
declared,
|
||||
guideCandidate,
|
||||
firstPageCandidate,
|
||||
...manifest.filter((item) => IMAGE_MIMES.has(item.mime)
|
||||
&& /(^|[\/_.-])(cover|title|front|book)([\/_.-]|$)/i.test(item.href)),
|
||||
...manifest.filter((item) => IMAGE_MIMES.has(item.mime))
|
||||
].filter(Boolean);
|
||||
|
||||
const seen = new Set();
|
||||
for (const item of candidates) {
|
||||
const imagePath = item.path || resolvePath(opfBase, item.href);
|
||||
if (!imagePath || seen.has(imagePath) || encryptedPaths.has(imagePath)) continue;
|
||||
seen.add(imagePath);
|
||||
const entry = zipEntry(zip, imagePath);
|
||||
if (!entry) continue;
|
||||
const data = await zipBytes(entry, 12 * 1024 * 1024);
|
||||
if (!data || !data.length) continue;
|
||||
try {
|
||||
const image = await loadImage(data, item.mime || mimeFromPath(imagePath));
|
||||
if (image.naturalWidth < 32 || image.naturalHeight < 32) continue;
|
||||
return imageCover(image);
|
||||
} catch (e) { /* try the next image */ }
|
||||
}
|
||||
|
||||
const titleNode = Array.from(opf.querySelectorAll('title')).find((node) => /(^|:)title$/i.test(node.nodeName));
|
||||
return titleCover((titleNode && titleNode.textContent) || fallbackTitle, authors);
|
||||
}
|
||||
|
||||
window.coverBridge.onExtract(async (payload) => {
|
||||
const id = payload && payload.id;
|
||||
try {
|
||||
const format = String(payload && payload.format || '').toLowerCase();
|
||||
const dataUrl = format === 'pdf'
|
||||
? await pdfCover(payload.bytes)
|
||||
: await epubCover(payload.bytes, payload.title, payload.authors);
|
||||
window.coverBridge.complete({ id, ok: true, dataUrl });
|
||||
} catch (error) {
|
||||
window.coverBridge.complete({ id, ok: false, error: (error && error.message) || String(error) });
|
||||
}
|
||||
});
|
||||
|
||||
window.coverBridge.ready();
|
||||
+154
-10
@@ -3,20 +3,36 @@
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src https: http: data: file:; style-src 'self' 'unsafe-inline';" />
|
||||
<title>PeopleLib 文献库</title>
|
||||
<title>PeopleLib</title>
|
||||
<link rel="stylesheet" href="style.css" />
|
||||
<link rel="stylesheet" href="vendor/quill/quill.snow.css" />
|
||||
<link rel="stylesheet" href="rich-note.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="titlebar">
|
||||
<div class="titlebar-left">
|
||||
<span class="brand">PeopleLib <span class="brand-sub">开放文献库</span></span>
|
||||
<span class="brand">
|
||||
<img class="brand-logo brand-logo-dark" src="../../icons/dist/dark/icon-32.png" alt="" />
|
||||
<img class="brand-logo brand-logo-light" src="../../icons/dist/light/icon-32.png" alt="" />
|
||||
<span>人民阅读器</span>
|
||||
<span class="brand-sub">PeopleLib</span>
|
||||
</span>
|
||||
</div>
|
||||
<nav class="tabs">
|
||||
<button class="tab active" data-tab="library">我的书库</button>
|
||||
<button class="tab" data-tab="notes">我的笔记</button>
|
||||
<button class="tab" data-tab="browse">检索</button>
|
||||
</nav>
|
||||
<div class="titlebar-spacer"></div>
|
||||
<div class="titlebar-controls">
|
||||
<button id="uiThemeBtn" class="win-btn ui-theme-btn" title="切换到明亮主题" aria-label="切换到明亮主题">
|
||||
<svg class="titlebar-icon ui-theme-sun" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="4"></circle><path d="M12 2v2M12 20v2M4.93 4.93l1.42 1.42M17.66 17.66l1.41 1.41M2 12h2M20 12h2M4.93 19.07l1.42-1.42M17.66 6.34l1.41-1.41"></path>
|
||||
</svg>
|
||||
<svg class="titlebar-icon ui-theme-moon" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M20 15.5A8.5 8.5 0 0 1 8.5 4 8.5 8.5 0 1 0 20 15.5Z"></path>
|
||||
</svg>
|
||||
</button>
|
||||
<button class="win-btn tab" data-tab="settings" title="设置">⚙</button>
|
||||
<button id="minBtn" class="win-btn" title="最小化">─</button>
|
||||
<button id="maxBtn" class="win-btn" title="最大化">□</button>
|
||||
@@ -27,13 +43,74 @@
|
||||
<main id="main">
|
||||
<!-- 我的书库 -->
|
||||
<section id="libraryTab" class="tab-panel">
|
||||
<div class="toolbar">
|
||||
<span id="libStatus" class="status-bar"></span>
|
||||
<div class="spacer"></div>
|
||||
<button id="rescanBtn" class="tb-btn ghost">重新扫描</button>
|
||||
<button id="addLocalBtn" class="tb-btn">+ 添加本地文件</button>
|
||||
<div class="library-page">
|
||||
<aside class="library-sidebar">
|
||||
<div class="library-sidebar-head">
|
||||
<h2>书架</h2>
|
||||
<button id="addShelfBtn" class="notes-icon-btn" title="新建书架" aria-label="新建书架">+</button>
|
||||
</div>
|
||||
<button class="library-filter active" data-shelf="">全部书籍</button>
|
||||
<button class="library-filter" data-shelf="__uncategorized__">未分类</button>
|
||||
<div id="libraryShelfList"></div>
|
||||
<div class="library-sidebar-section">
|
||||
<div class="library-sidebar-section-head">
|
||||
<h3>标签</h3>
|
||||
<button id="addTagBtn" class="notes-icon-btn" title="新建标签" aria-label="新建标签">+</button>
|
||||
</div>
|
||||
<div id="libraryTagList" class="library-tag-list"></div>
|
||||
</div>
|
||||
</aside>
|
||||
<div class="library-content">
|
||||
<div class="toolbar">
|
||||
<div class="library-search" role="search">
|
||||
<input id="librarySearchInput" type="search" placeholder="搜索标题或作者..." autocomplete="off" />
|
||||
<button id="librarySearchBtn" class="tb-btn">搜索</button>
|
||||
<button id="libraryClearSearchBtn" class="tb-btn ghost hidden">清除</button>
|
||||
</div>
|
||||
<span id="libStatus" class="status-bar"></span>
|
||||
<div class="spacer"></div>
|
||||
<button id="rescanBtn" class="tb-btn ghost">重新扫描</button>
|
||||
<button id="addLocalBtn" class="tb-btn">+ 添加本地</button>
|
||||
</div>
|
||||
<div id="libGrid" class="grid"></div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
|
||||
<!-- 我的笔记 -->
|
||||
<section id="notesTab" class="tab-panel hidden">
|
||||
<div class="notes-page">
|
||||
<aside class="notes-sidebar">
|
||||
<div class="notes-sidebar-head">
|
||||
<h2>笔记本</h2>
|
||||
<button id="addCollectionBtn" class="notes-icon-btn" title="新建笔记本" aria-label="新建笔记本">+</button>
|
||||
</div>
|
||||
<button class="notes-collection active" data-collection="">全部笔记</button>
|
||||
<button class="notes-collection" data-collection="__uncategorized__">未分类</button>
|
||||
<div id="notesCollectionList"></div>
|
||||
</aside>
|
||||
<div class="notes-content">
|
||||
<div class="notes-toolbar">
|
||||
<div class="notes-search">
|
||||
<input id="notesSearchInput" type="search" placeholder="搜索笔记、摘录或书名..." autocomplete="off" />
|
||||
<button id="notesSearchBtn" class="tb-btn">搜索</button>
|
||||
<button id="notesClearSearchBtn" class="tb-btn ghost hidden">清除</button>
|
||||
</div>
|
||||
<select id="notesSourceSelect" class="source-select" aria-label="按来源筛选">
|
||||
<option value="">全部来源</option>
|
||||
</select>
|
||||
<button id="addGlobalNoteBtn" class="tb-btn">+ 新建笔记</button>
|
||||
</div>
|
||||
<div id="notesTypeTabs" class="notes-type-tabs" role="tablist" aria-label="笔记类型">
|
||||
<button class="notes-type-tab active" data-note-type="" role="tab" aria-selected="true">全部</button>
|
||||
<button class="notes-type-tab" data-note-type="canvas" role="tab" aria-selected="false">画布笔记</button>
|
||||
<button class="notes-type-tab" data-note-type="reading" role="tab" aria-selected="false">读书笔记</button>
|
||||
</div>
|
||||
<div id="notesTagFilters" class="notes-tag-filters hidden"></div>
|
||||
<div id="notesStatus" class="status-bar"></div>
|
||||
<div id="notesList" class="notes-list"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div id="libGrid" class="grid"></div>
|
||||
</section>
|
||||
|
||||
<!-- 检索 -->
|
||||
@@ -106,6 +183,7 @@
|
||||
<div class="settings-item-desc">控制书库条目的排列顺序</div>
|
||||
</div>
|
||||
<select id="sortSelect" class="source-select">
|
||||
<option value="recent">最近阅读</option>
|
||||
<option value="added">添加时间</option>
|
||||
<option value="title">标题</option>
|
||||
<option value="author">作者</option>
|
||||
@@ -118,7 +196,7 @@
|
||||
<div class="settings-item-label">网络代理</div>
|
||||
<div class="settings-item-desc">对所有数据源与下载统一生效;访问 LibGen / Z-Library 通常需要代理(留空表示直连)</div>
|
||||
</div>
|
||||
<input id="proxyInput" type="text" placeholder="留空表示直连,例如 http://localhost:7897" style="width:220px;padding:6px;background:#222;border:1px solid #444;color:#eee;border-radius:4px;" />
|
||||
<input id="proxyInput" class="settings-input" type="text" placeholder="留空表示直连,例如 http://localhost:7897" />
|
||||
<button id="proxySaveBtn" class="tb-btn">保存</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -133,6 +211,46 @@
|
||||
<button id="semanticKeyClearBtn" class="tb-btn ghost hidden">清除</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="settings-item settings-item-block">
|
||||
<div class="settings-item-info">
|
||||
<div class="settings-item-label">阅读器 AI 助手</div>
|
||||
<div class="settings-item-desc" id="aiStatus">未配置</div>
|
||||
</div>
|
||||
<div class="ai-form">
|
||||
<label class="ai-row">
|
||||
<span>接口类型</span>
|
||||
<select id="aiProtocol" class="settings-input ai-protocol">
|
||||
<option value="anthropic">Anthropic 接口(/v1/messages)</option>
|
||||
<option value="openai-responses">OpenAI 接口(/v1/responses)</option>
|
||||
<option value="chat-completions">OpenAI 兼容接口(/v1/chat/completions)</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="ai-row">
|
||||
<span>接口地址</span>
|
||||
<input id="aiBaseUrl" class="settings-input" type="text" placeholder="https://api.openai.com/v1" autocomplete="off" />
|
||||
</label>
|
||||
<label class="ai-row">
|
||||
<span>模型名称</span>
|
||||
<input id="aiModel" class="settings-input" type="text" placeholder="gpt-4o-mini" autocomplete="off" />
|
||||
</label>
|
||||
<label class="ai-row">
|
||||
<span>API Key</span>
|
||||
<input id="aiKey" class="settings-input" type="password" placeholder="本地模型可留空" autocomplete="off" />
|
||||
</label>
|
||||
<label class="ai-row ai-vision-row">
|
||||
<span>图像输入</span>
|
||||
<input id="aiVision" type="checkbox" />
|
||||
<small>仅在模型明确支持图片时开启</small>
|
||||
</label>
|
||||
<div class="ai-row ai-actions">
|
||||
<span id="aiProtocolHint" class="ai-hint">服务地址填写到版本根路径,PeopleLib 会按接口类型调用对应端点。</span>
|
||||
<button id="aiSaveBtn" class="tb-btn">保存</button>
|
||||
<button id="aiClearBtn" class="tb-btn ghost hidden">清除</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-group">
|
||||
<div class="settings-item">
|
||||
<div class="settings-item-info">
|
||||
@@ -161,6 +279,27 @@
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
<div class="settings-group" aria-label="关于 PeopleLib">
|
||||
<div class="settings-item settings-item-block">
|
||||
<div class="settings-item-info">
|
||||
<div class="settings-item-label">关于 PeopleLib</div>
|
||||
<div class="settings-item-desc">人民阅读器支持的本地图书格式</div>
|
||||
</div>
|
||||
<div class="about-formats">
|
||||
<div>
|
||||
<span class="about-format-label">内置阅读</span>
|
||||
<span>PDF、EPUB、MOBI、AZW、AZW3</span>
|
||||
</div>
|
||||
<div>
|
||||
<span class="about-format-label">书库导入与管理</span>
|
||||
<span>PDF、EPUB、MOBI、AZW、AZW3、TXT、DJVU、FB2、CBZ、CBR</span>
|
||||
</div>
|
||||
<div class="settings-item-desc">
|
||||
MOBI、AZW 与 AZW3 由 Foliate 解析,支持无 DRM 的 MOBI/KF7/KF8 内容;DRM、KFX 与损坏文件可改用系统应用打开。
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
</main>
|
||||
@@ -171,7 +310,7 @@
|
||||
<div id="modalTitle" class="modal-title"></div>
|
||||
<div id="modalBody" class="modal-body"></div>
|
||||
<div class="modal-actions">
|
||||
<button id="modalCancel" class="page-btn">取消</button>
|
||||
<button id="modalCancel" class="tb-btn ghost">取消</button>
|
||||
<button id="modalOk" class="tb-btn">确定</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -180,6 +319,11 @@
|
||||
<script src="util.js"></script>
|
||||
<script src="views/browse.js"></script>
|
||||
<script src="views/library.js"></script>
|
||||
<script src="vendor/quill/quill.js"></script>
|
||||
<script src="vendor/jspdf.umd.min.js"></script>
|
||||
<script src="rich-note.js"></script>
|
||||
<script src="mixed-note.js"></script>
|
||||
<script src="views/notes.js"></script>
|
||||
<script src="app.js"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
||||
@@ -0,0 +1,203 @@
|
||||
window.MixedNote = (() => {
|
||||
function resultData(result, fallback) {
|
||||
if (!result || !result.ok) throw new Error((result && result.error) || fallback);
|
||||
return result.data;
|
||||
}
|
||||
|
||||
function canvasOptions(options) {
|
||||
return {
|
||||
async pickPdf() {
|
||||
return resultData(await window.api.reader.pickNotePdf(), '无法选择 PDF 底版');
|
||||
},
|
||||
async readPdf(ref) {
|
||||
return resultData(await window.api.reader.notePdfBytes(ref), '无法读取 PDF 底版');
|
||||
},
|
||||
async savePdf(bytes, suggestedName) {
|
||||
return resultData(
|
||||
await window.api.reader.saveNotePdf(bytes, suggestedName),
|
||||
'导出 PDF 失败'
|
||||
);
|
||||
},
|
||||
onError: options.onError,
|
||||
onChange: options.onChange
|
||||
};
|
||||
}
|
||||
|
||||
function mountTyped(host, noteType, initialRich, initialCanvas, options) {
|
||||
host.textContent = '';
|
||||
const box = document.createElement('div');
|
||||
box.className = `mixed-note-editor note-editor-${noteType}`;
|
||||
const editorHost = document.createElement('div');
|
||||
editorHost.className = noteType === 'canvas' ? 'mixed-note-canvas' : 'mixed-note-text';
|
||||
box.appendChild(editorHost);
|
||||
host.appendChild(box);
|
||||
|
||||
if (noteType === 'reading') {
|
||||
const rich = window.RichNote.mount(editorHost, initialRich, {
|
||||
placeholder: options.placeholder,
|
||||
onError: options.onError
|
||||
});
|
||||
return {
|
||||
noteType,
|
||||
ready: async () => {},
|
||||
richContent: () => rich.content(),
|
||||
canvasContent: () => null,
|
||||
text: () => rich.text(),
|
||||
hasContent: () => window.RichNote.hasContent(rich.content()),
|
||||
focus: () => rich.focus(),
|
||||
setMode: async () => {},
|
||||
destroy: () => {
|
||||
rich.destroy();
|
||||
host.textContent = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
editorHost.textContent = '正在加载画布...';
|
||||
let canvas = null;
|
||||
let destroyed = false;
|
||||
const canvasPromise = import('./canvas-note.mjs').then(async (module) => {
|
||||
if (destroyed) return null;
|
||||
canvas = await module.mountCanvasNote(editorHost, initialCanvas, canvasOptions(options));
|
||||
return canvas;
|
||||
}).catch((error) => {
|
||||
if (typeof options.onError === 'function') options.onError(error.message || String(error));
|
||||
throw error;
|
||||
});
|
||||
return {
|
||||
noteType,
|
||||
ready: async () => {
|
||||
await canvasPromise;
|
||||
if (canvas) await canvas.flush();
|
||||
},
|
||||
richContent: () => null,
|
||||
canvasContent: () => canvas ? canvas.content() : initialCanvas || null,
|
||||
text: () => '',
|
||||
hasContent: () => !!(canvas ? canvas.hasContent() : initialCanvas),
|
||||
focus: () => { canvasPromise.then((value) => value?.focus()).catch(() => {}); },
|
||||
setMode: async () => {},
|
||||
destroy: () => {
|
||||
destroyed = true;
|
||||
if (canvas) canvas.destroy();
|
||||
host.textContent = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function mount(host, initialRich, initialCanvas, options = {}) {
|
||||
if (options.noteType === 'reading' || options.noteType === 'canvas') {
|
||||
return mountTyped(host, options.noteType, initialRich, initialCanvas, options);
|
||||
}
|
||||
host.textContent = '';
|
||||
const box = document.createElement('div');
|
||||
box.className = 'mixed-note-editor';
|
||||
const modes = document.createElement('div');
|
||||
modes.className = 'mixed-note-modes';
|
||||
modes.setAttribute('role', 'tablist');
|
||||
const textButton = document.createElement('button');
|
||||
textButton.type = 'button';
|
||||
textButton.className = 'mixed-note-mode active';
|
||||
textButton.textContent = '文本';
|
||||
textButton.setAttribute('role', 'tab');
|
||||
textButton.setAttribute('aria-selected', 'true');
|
||||
const canvasButton = document.createElement('button');
|
||||
canvasButton.type = 'button';
|
||||
canvasButton.className = 'mixed-note-mode';
|
||||
canvasButton.textContent = '自由画布';
|
||||
canvasButton.setAttribute('role', 'tab');
|
||||
canvasButton.setAttribute('aria-selected', 'false');
|
||||
modes.append(textButton, canvasButton);
|
||||
|
||||
const textHost = document.createElement('div');
|
||||
textHost.className = 'mixed-note-text';
|
||||
const canvasHost = document.createElement('div');
|
||||
canvasHost.className = 'mixed-note-canvas hidden';
|
||||
box.append(modes, textHost, canvasHost);
|
||||
host.appendChild(box);
|
||||
|
||||
const rich = window.RichNote.mount(textHost, initialRich, {
|
||||
placeholder: options.placeholder,
|
||||
onError: options.onError
|
||||
});
|
||||
let canvas = null;
|
||||
let canvasPromise = null;
|
||||
let destroyed = false;
|
||||
|
||||
function legacyCanvasOptions() {
|
||||
return {
|
||||
async pickPdf() {
|
||||
const value = resultData(await window.api.reader.pickNotePdf(), '无法选择 PDF 底版');
|
||||
return value;
|
||||
},
|
||||
async readPdf(ref) {
|
||||
return resultData(await window.api.reader.notePdfBytes(ref), '无法读取 PDF 底版');
|
||||
},
|
||||
async savePdf(bytes, suggestedName) {
|
||||
return resultData(
|
||||
await window.api.reader.saveNotePdf(bytes, suggestedName),
|
||||
'导出 PDF 失败'
|
||||
);
|
||||
},
|
||||
onError: options.onError,
|
||||
onChange: options.onChange
|
||||
};
|
||||
}
|
||||
|
||||
async function ensureCanvas() {
|
||||
if (canvas) return canvas;
|
||||
if (!canvasPromise) {
|
||||
canvasPromise = import('./canvas-note.mjs').then(async (module) => {
|
||||
if (destroyed) return null;
|
||||
canvas = await module.mountCanvasNote(canvasHost, initialCanvas, legacyCanvasOptions());
|
||||
return canvas;
|
||||
}).catch((error) => {
|
||||
canvasPromise = null;
|
||||
if (typeof options.onError === 'function') options.onError(error.message || String(error));
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
return canvasPromise;
|
||||
}
|
||||
|
||||
async function setMode(mode) {
|
||||
const showCanvas = mode === 'canvas';
|
||||
if (showCanvas) await ensureCanvas();
|
||||
textHost.classList.toggle('hidden', showCanvas);
|
||||
canvasHost.classList.toggle('hidden', !showCanvas);
|
||||
textButton.classList.toggle('active', !showCanvas);
|
||||
canvasButton.classList.toggle('active', showCanvas);
|
||||
textButton.setAttribute('aria-selected', String(!showCanvas));
|
||||
canvasButton.setAttribute('aria-selected', String(showCanvas));
|
||||
if (showCanvas && canvas) canvas.focus();
|
||||
else rich.focus();
|
||||
}
|
||||
|
||||
textButton.onclick = () => { setMode('text'); };
|
||||
canvasButton.onclick = () => { setMode('canvas'); };
|
||||
if (initialCanvas) ensureCanvas();
|
||||
|
||||
return {
|
||||
ready: async () => {
|
||||
if (canvasPromise) await canvasPromise;
|
||||
if (canvas) await canvas.flush();
|
||||
},
|
||||
richContent: () => rich.content(),
|
||||
canvasContent: () => canvas ? canvas.content() : initialCanvas || null,
|
||||
text: () => rich.text(),
|
||||
hasContent: () => (
|
||||
window.RichNote.hasContent(rich.content())
|
||||
|| !!((canvas ? canvas.content() : initialCanvas) && (canvas ? canvas.hasContent() : true))
|
||||
),
|
||||
focus: () => rich.focus(),
|
||||
setMode,
|
||||
destroy: () => {
|
||||
destroyed = true;
|
||||
rich.destroy();
|
||||
if (canvas) canvas.destroy();
|
||||
host.textContent = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return { mount };
|
||||
})();
|
||||
@@ -0,0 +1,884 @@
|
||||
:root {
|
||||
color-scheme: dark;
|
||||
--bg: #14161a;
|
||||
--bg-soft: #181b20;
|
||||
--bg-card: #1c2027;
|
||||
--line: #2a2f38;
|
||||
--accent: #6ea8fe;
|
||||
--accent-bright: #9cc2ff;
|
||||
--text: #dfe4ec;
|
||||
--text-dim: #8b94a3;
|
||||
--green: #3fb96f;
|
||||
--danger: #d9534f;
|
||||
--titlebar-start: #171b26;
|
||||
--titlebar-end: #12141c;
|
||||
--hover-bg: rgba(255,255,255,0.08);
|
||||
--hover-bg-soft: rgba(255,255,255,0.05);
|
||||
--accent-soft: rgba(110,168,254,0.14);
|
||||
--accent-faint: rgba(110,168,254,0.08);
|
||||
--on-accent: #0d1420;
|
||||
--doc-bg: #101216;
|
||||
--doc-overlay: rgba(16,18,22,0.92);
|
||||
--error-text: #ffb4b1;
|
||||
--warn-text: #ffcf8b;
|
||||
--warn-line: #6b5320;
|
||||
--input-bg: rgba(255,255,255,0.06);
|
||||
--floating-shadow: rgba(0,0,0,0.5);
|
||||
--scrollbar: #2a2f38;
|
||||
--scrollbar-hover: #3a4150;
|
||||
}
|
||||
|
||||
:root[data-ui-theme="light"] {
|
||||
color-scheme: light;
|
||||
--bg: #edf1f6;
|
||||
--bg-soft: #f7f9fc;
|
||||
--bg-card: #ffffff;
|
||||
--line: #d4dbe6;
|
||||
--accent: #397bd3;
|
||||
--accent-bright: #245fae;
|
||||
--text: #1f2937;
|
||||
--text-dim: #667386;
|
||||
--green: #268a50;
|
||||
--danger: #c2413b;
|
||||
--titlebar-start: #ffffff;
|
||||
--titlebar-end: #edf2f8;
|
||||
--hover-bg: rgba(31,48,70,0.09);
|
||||
--hover-bg-soft: rgba(31,48,70,0.055);
|
||||
--accent-soft: rgba(57,123,211,0.14);
|
||||
--accent-faint: rgba(57,123,211,0.08);
|
||||
--on-accent: #ffffff;
|
||||
--doc-bg: #e7ecf2;
|
||||
--doc-overlay: rgba(255,255,255,0.92);
|
||||
--error-text: #b42318;
|
||||
--warn-text: #8a4b08;
|
||||
--warn-line: #d7a55a;
|
||||
--input-bg: #ffffff;
|
||||
--floating-shadow: rgba(42,55,76,0.18);
|
||||
--scrollbar: #c1c9d5;
|
||||
--scrollbar-hover: #a7b2c1;
|
||||
}
|
||||
|
||||
* { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
|
||||
body {
|
||||
font-family: "Microsoft YaHei", "PingFang SC", -apple-system, "Segoe UI", sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
height: 100vh;
|
||||
overflow: hidden;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.hidden { display: none !important; }
|
||||
.spacer { flex: 1; }
|
||||
|
||||
button,
|
||||
select,
|
||||
input[type="range"],
|
||||
input[type="color"],
|
||||
.titlebar,
|
||||
.doctabs,
|
||||
.annotation-toolbar,
|
||||
.pane-head,
|
||||
.pane-tabs,
|
||||
.pane-toolbar,
|
||||
.statusbar,
|
||||
.sel-bar,
|
||||
.modal-title,
|
||||
.modal-actions {
|
||||
-webkit-user-select: none;
|
||||
user-select: none;
|
||||
}
|
||||
|
||||
/* 标题栏 */
|
||||
.titlebar {
|
||||
height: 44px;
|
||||
background: linear-gradient(135deg, var(--titlebar-start), var(--titlebar-end));
|
||||
display: flex; align-items: center;
|
||||
padding: 0 8px 0 16px;
|
||||
-webkit-app-region: drag;
|
||||
border-bottom: 1px solid var(--line);
|
||||
flex-shrink: 0;
|
||||
}
|
||||
.titlebar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
|
||||
.brand {
|
||||
display: flex; align-items: center; gap: 7px; flex-shrink: 0;
|
||||
font-size: 15px; font-weight: 700; color: var(--accent-bright); letter-spacing: 0.5px;
|
||||
}
|
||||
.brand-logo { width: 25px; height: 25px; border-radius: 6px; object-fit: contain; }
|
||||
.brand-logo-light { display: none; }
|
||||
:root[data-ui-theme="light"] .brand-logo-dark { display: none; }
|
||||
:root[data-ui-theme="light"] .brand-logo-light { display: block; }
|
||||
.brand-sub {
|
||||
color: var(--text-dim); font-weight: 400; font-size: 12px;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
}
|
||||
.titlebar-spacer { flex: 1; }
|
||||
.titlebar-controls { display: flex; gap: 2px; -webkit-app-region: no-drag; flex-shrink: 0; }
|
||||
.win-btn {
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
width: 40px; height: 30px;
|
||||
background: transparent; border: none; border-radius: 6px;
|
||||
color: var(--text-dim); font-size: 14px; cursor: pointer;
|
||||
}
|
||||
.win-btn:hover { background: var(--hover-bg); color: var(--text); }
|
||||
.win-close:hover { background: var(--danger); color: #fff; }
|
||||
.ui-theme-btn { margin-right: 6px; }
|
||||
:root[data-ui-theme="light"] .ui-theme-sun,
|
||||
:root:not([data-ui-theme="light"]) .ui-theme-moon { display: none; }
|
||||
|
||||
/* 文档 tab 条 */
|
||||
.doctabs {
|
||||
height: 36px; flex-shrink: 0;
|
||||
display: flex; align-items: stretch;
|
||||
background: var(--bg-soft);
|
||||
border-bottom: 1px solid var(--line);
|
||||
padding: 0 6px;
|
||||
}
|
||||
.doctabs-list { display: flex; align-items: stretch; gap: 4px; overflow-x: auto; overflow-y: hidden; flex: 1; }
|
||||
.doctabs-list::-webkit-scrollbar { height: 0; }
|
||||
.doctab {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
max-width: 220px; padding: 0 8px 0 14px;
|
||||
margin: 4px 0;
|
||||
background: transparent; border: 1px solid transparent; border-radius: 8px;
|
||||
color: var(--text-dim); font-size: 13px; cursor: pointer; flex-shrink: 0;
|
||||
}
|
||||
.doctab:hover { background: var(--hover-bg-soft); color: var(--text); }
|
||||
.doctab.active { background: var(--bg-card); border-color: var(--line); color: var(--text); }
|
||||
.doctab-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.doctab.active .doctab-name { color: var(--accent-bright); font-weight: 600; }
|
||||
.doctab-fmt {
|
||||
font-size: 10px; padding: 0 5px; border-radius: 5px; flex-shrink: 0;
|
||||
border: 1px solid var(--line); color: var(--text-dim); text-transform: uppercase;
|
||||
}
|
||||
.doctab-close {
|
||||
width: 18px; height: 18px; flex-shrink: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: transparent; border: none; border-radius: 5px;
|
||||
color: var(--text-dim); font-size: 11px; cursor: pointer;
|
||||
}
|
||||
.doctab-close:hover { background: var(--danger); color: #fff; }
|
||||
.doctab-add {
|
||||
align-self: center; width: 28px; height: 26px; flex-shrink: 0;
|
||||
background: transparent; border: 1px solid var(--line); border-radius: 8px;
|
||||
color: var(--text-dim); font-size: 14px; cursor: pointer;
|
||||
}
|
||||
.doctab-add:hover { color: var(--accent); border-color: var(--accent); }
|
||||
|
||||
/* PDF 批注工具栏 */
|
||||
.annotation-toolbar {
|
||||
min-height: 42px; flex-shrink: 0;
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 6px 10px;
|
||||
background: var(--bg-soft); border-bottom: 1px solid var(--line);
|
||||
overflow-x: auto; overflow-y: hidden;
|
||||
}
|
||||
.annotation-toolbar::-webkit-scrollbar { height: 4px; }
|
||||
.annotation-title {
|
||||
color: var(--accent-bright); font-size: 12px; font-weight: 700; white-space: nowrap;
|
||||
}
|
||||
.annotation-tools { display: flex; align-items: center; gap: 3px; }
|
||||
.toolbar-icon {
|
||||
width: 16px; height: 16px; flex: none; pointer-events: none;
|
||||
fill: none; stroke: currentColor; stroke-width: 1.8;
|
||||
stroke-linecap: round; stroke-linejoin: round;
|
||||
}
|
||||
.annotation-tool {
|
||||
width: 28px; height: 28px; padding: 0;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
background: transparent; border: 1px solid transparent; border-radius: 6px;
|
||||
color: var(--text-dim); font: inherit; cursor: pointer;
|
||||
}
|
||||
.annotation-tool:hover { color: var(--text); border-color: var(--line); }
|
||||
.annotation-tool.active {
|
||||
background: var(--accent-soft); border-color: var(--accent); color: var(--accent-bright);
|
||||
}
|
||||
.annotation-divider { width: 1px; height: 22px; flex: none; background: var(--line); }
|
||||
.annotation-color,
|
||||
.annotation-width {
|
||||
display: flex; align-items: center; gap: 5px;
|
||||
color: var(--text-dim); font-size: 11px; white-space: nowrap;
|
||||
}
|
||||
.annotation-color input {
|
||||
width: 28px; height: 24px; padding: 2px;
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 6px; cursor: pointer;
|
||||
}
|
||||
.annotation-width .toolbar-icon { width: 14px; height: 14px; }
|
||||
.annotation-width .mini-select { width: 42px; padding: 0 3px; }
|
||||
.annotation-icon-btn,
|
||||
.annotation-toggle-btn {
|
||||
width: 28px; padding: 0;
|
||||
display: inline-flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.annotation-status {
|
||||
margin-left: auto; color: var(--text-dim); font-size: 11px; white-space: nowrap;
|
||||
}
|
||||
|
||||
/* 主体三栏 */
|
||||
.reader-body { flex: 1; min-height: 0; display: flex; }
|
||||
|
||||
.side-pane {
|
||||
width: 250px; flex-shrink: 0;
|
||||
background: var(--bg-soft);
|
||||
display: flex; flex-direction: column;
|
||||
min-height: 0;
|
||||
}
|
||||
.side-left { border-right: 1px solid var(--line); }
|
||||
.side-right { width: 320px; border-left: 1px solid var(--line); }
|
||||
.side-pane.collapsed { display: none; }
|
||||
|
||||
.pane-head {
|
||||
height: 34px; flex-shrink: 0;
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
padding: 0 6px 0 14px;
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.pane-head-title { font-size: 13px; font-weight: 600; color: var(--text); flex: 1; }
|
||||
.icon-btn {
|
||||
width: 22px; height: 22px; flex-shrink: 0;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
background: transparent; border: none; border-radius: 5px;
|
||||
color: var(--text-dim); font-size: 11px; cursor: pointer;
|
||||
}
|
||||
.icon-btn:hover { background: var(--hover-bg); color: var(--text); }
|
||||
|
||||
.pane-tabs {
|
||||
height: 34px; flex-shrink: 0;
|
||||
display: flex; align-items: center; gap: 2px;
|
||||
padding: 0 6px; border-bottom: 1px solid var(--line);
|
||||
}
|
||||
.pane-tab {
|
||||
height: 24px; padding: 0 12px;
|
||||
background: transparent; border: none; border-radius: 6px;
|
||||
color: var(--text-dim); font-size: 13px; cursor: pointer;
|
||||
}
|
||||
.pane-tab:hover { color: var(--text); background: var(--hover-bg-soft); }
|
||||
.pane-tab.active { color: var(--on-accent); background: var(--accent); font-weight: 600; }
|
||||
.pane-tabs-close { margin-left: auto; }
|
||||
|
||||
.pane-body { flex: 1; min-height: 0; overflow-y: auto; padding: 10px 12px; }
|
||||
.pane-toolbar { margin-bottom: 10px; }
|
||||
.note-pane-toolbar { display: flex; align-items: center; gap: 6px; }
|
||||
.note-pane-toolbar .mini-select { flex: 1; min-width: 0; }
|
||||
|
||||
/* 目录 */
|
||||
.toc-item {
|
||||
display: block; width: 100%; text-align: left;
|
||||
padding: 6px 8px; margin-bottom: 2px;
|
||||
background: transparent; border: none; border-radius: 6px;
|
||||
color: var(--text-dim); font-size: 12px; line-height: 1.5; cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.toc-item:hover { background: var(--hover-bg); color: var(--text); }
|
||||
.toc-item.current { color: var(--accent-bright); background: var(--accent-soft); }
|
||||
|
||||
/* 正文区 */
|
||||
.doc-area { flex: 1; min-width: 0; position: relative; overflow: hidden; background: var(--doc-bg); }
|
||||
.doc-view { position: absolute; inset: 0; touch-action: pan-x pan-y; }
|
||||
.doc-view.inactive { display: none; }
|
||||
.doc-view[data-theme="light"] { background: #f3f3f3; }
|
||||
.doc-view[data-theme="sepia"] { background: #e8dcc4; }
|
||||
.doc-view[data-theme="dark"] { background: #1b1b1b; }
|
||||
|
||||
.host-pdf { position: absolute; inset: 0; }
|
||||
.epub-scroll { position: absolute; inset: 0; overflow-y: auto; }
|
||||
.host-epub { max-width: 46em; margin: 0 auto; padding: 20px 24px 60px; }
|
||||
.pinch-preview { will-change: transform; }
|
||||
|
||||
/* 正文列有 max-width,两侧留白会露出容器底色,需与适配器内的主题色一致 */
|
||||
.doc-view[data-theme="light"] .epub-scroll { background: #ffffff; }
|
||||
.doc-view[data-theme="sepia"] .epub-scroll { background: #f6ecd9; }
|
||||
.doc-view[data-theme="dark"] .epub-scroll { background: #15171c; }
|
||||
|
||||
.doc-empty {
|
||||
position: absolute; inset: 0;
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 10px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.doc-empty-title { font-size: 16px; color: var(--text); }
|
||||
.doc-empty-sub { font-size: 13px; }
|
||||
.doc-empty .tb-btn { margin-top: 8px; }
|
||||
|
||||
.doc-overlay {
|
||||
position: absolute; inset: 0; z-index: 4;
|
||||
display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px;
|
||||
background: var(--doc-overlay);
|
||||
color: var(--text-dim); font-size: 13px; text-align: center; padding: 24px;
|
||||
}
|
||||
.doc-overlay.err { color: var(--error-text); }
|
||||
.doc-overlay-title { font-size: 15px; color: var(--text); }
|
||||
.doc-overlay-msg { max-width: 460px; line-height: 1.7; word-break: break-word; }
|
||||
.prog-track { width: 220px; height: 4px; background: var(--line); border-radius: 3px; overflow: hidden; }
|
||||
.prog-fill { height: 100%; width: 0; background: var(--accent); transition: width 0.15s; }
|
||||
|
||||
/* 底部状态栏 */
|
||||
.statusbar {
|
||||
height: 40px; flex-shrink: 0;
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
padding: 0 12px;
|
||||
background: var(--bg-soft);
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.statusbar-group { display: flex; align-items: center; gap: 4px; }
|
||||
.pdf-view-controls { gap: 7px; }
|
||||
.pdf-view-controls label {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 4px;
|
||||
color: var(--text-dim);
|
||||
font-size: 11px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.status-text { font-size: 12px; color: var(--text); white-space: nowrap; }
|
||||
.status-text.dim { color: var(--text-dim); }
|
||||
#statusMsg { overflow: hidden; text-overflow: ellipsis; max-width: 320px; }
|
||||
#posLabel { max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
|
||||
#zoomLabel { min-width: 44px; text-align: center; }
|
||||
.fit-width-btn {
|
||||
width: 28px;
|
||||
padding: 0;
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
|
||||
.progress-range { width: 140px; accent-color: var(--accent); cursor: pointer; }
|
||||
.mini-select {
|
||||
height: 24px; padding: 0 6px;
|
||||
background: var(--bg-card); color: var(--text);
|
||||
border: 1px solid var(--line); border-radius: 6px; font-size: 12px; cursor: pointer; outline: none;
|
||||
}
|
||||
|
||||
@media (max-width: 1050px) {
|
||||
.statusbar { gap: 6px; padding-inline: 8px; }
|
||||
#statusMsg { display: none; }
|
||||
#posLabel { max-width: 90px; }
|
||||
.progress-range { width: auto; min-width: 50px; max-width: 100px; flex: 1; }
|
||||
}
|
||||
|
||||
@media (max-width: 850px) {
|
||||
.pdf-view-controls label > span,
|
||||
#pctLabel { display: none; }
|
||||
.pdf-view-controls { gap: 4px; }
|
||||
.pdf-view-controls .mini-select { width: 52px; padding-inline: 3px; }
|
||||
}
|
||||
|
||||
/* 按钮(沿用主窗口风格) */
|
||||
.tb-btn {
|
||||
height: 28px; padding: 0 14px;
|
||||
background: var(--accent); color: var(--on-accent); border: none; border-radius: 8px;
|
||||
font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
|
||||
font-family: inherit;
|
||||
}
|
||||
.tb-btn:hover { background: var(--accent-bright); }
|
||||
.tb-btn.ghost { background: transparent; color: var(--text-dim); border: 1px solid var(--line); }
|
||||
.tb-btn.ghost:hover { color: var(--text); border-color: var(--accent); }
|
||||
.tb-btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); }
|
||||
.tb-btn.danger:hover { background: var(--danger); color: #fff; }
|
||||
.tb-btn.sm { height: 24px; padding: 0 10px; font-size: 12px; font-weight: 500; }
|
||||
.tb-btn:disabled { opacity: 0.4; cursor: not-allowed; }
|
||||
|
||||
/* 列表(书签 / 笔记) */
|
||||
.list { display: flex; flex-direction: column; gap: 8px; }
|
||||
.list-item {
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
|
||||
padding: 8px 10px;
|
||||
}
|
||||
.list-item-head { display: flex; align-items: center; gap: 8px; }
|
||||
.list-item-label {
|
||||
flex: 1; min-width: 0;
|
||||
background: transparent; border: none; padding: 0; text-align: left;
|
||||
color: var(--accent-bright); font-size: 12px; font-weight: 600; cursor: pointer;
|
||||
overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
font-family: inherit;
|
||||
}
|
||||
.list-item-label:hover { text-decoration: underline; }
|
||||
.list-item-del {
|
||||
width: 20px; height: 20px; flex-shrink: 0;
|
||||
background: transparent; border: none; border-radius: 5px;
|
||||
color: var(--text-dim); font-size: 12px; cursor: pointer;
|
||||
}
|
||||
.list-item-del:hover { background: var(--danger); color: #fff; }
|
||||
.list-item-edit {
|
||||
width: 20px; height: 20px; flex-shrink: 0;
|
||||
background: transparent; border: none; border-radius: 5px;
|
||||
color: var(--text-dim); font-size: 12px; cursor: pointer;
|
||||
}
|
||||
.list-item-edit:hover { background: var(--hover-bg); color: var(--text); }
|
||||
.list-item-text {
|
||||
margin-top: 6px; font-size: 12px; line-height: 1.6; color: var(--text-dim);
|
||||
white-space: pre-wrap; word-break: break-word;
|
||||
max-height: 9.6em; overflow: hidden;
|
||||
}
|
||||
.rich-note-content { white-space: normal; }
|
||||
.rich-note-content > :first-child { margin-top: 0; }
|
||||
.rich-note-content > :last-child { margin-bottom: 0; }
|
||||
.rich-note-content p,
|
||||
.rich-note-content h2,
|
||||
.rich-note-content h3,
|
||||
.rich-note-content blockquote,
|
||||
.rich-note-content pre,
|
||||
.rich-note-content ul,
|
||||
.rich-note-content ol { margin: 0.4em 0; }
|
||||
.rich-note-content h2 { font-size: 1.3em; }
|
||||
.rich-note-content h3 { font-size: 1.12em; }
|
||||
.rich-note-content blockquote {
|
||||
padding: 6px 8px; background: var(--accent-faint);
|
||||
border-left: 3px solid var(--accent); color: var(--text-dim);
|
||||
}
|
||||
.rich-note-content pre,
|
||||
.rich-note-content code { font-family: Consolas, "Cascadia Mono", monospace; }
|
||||
.rich-note-content pre {
|
||||
overflow-x: auto; padding: 7px 8px;
|
||||
background: var(--input-bg); border-radius: 6px; white-space: pre-wrap;
|
||||
}
|
||||
.rich-note-content ul,
|
||||
.rich-note-content ol { padding-left: 1.5em; }
|
||||
.rich-note-image { position: relative; width: fit-content; max-width: 100%; margin: 8px 0; }
|
||||
.rich-note-image img {
|
||||
display: block; max-width: 100%; max-height: 420px;
|
||||
border: 1px solid var(--line); border-radius: 7px; object-fit: contain;
|
||||
}
|
||||
.list-item-quote {
|
||||
margin-top: 6px; padding-left: 8px;
|
||||
border-left: 2px solid var(--line);
|
||||
font-size: 11px; line-height: 1.6; color: var(--text-dim);
|
||||
word-break: break-word;
|
||||
max-height: 4.8em; overflow: hidden;
|
||||
}
|
||||
.list-item-time { margin-top: 6px; font-size: 11px; color: var(--text-dim); }
|
||||
.list-item-tags { margin-top: 6px; color: var(--accent); font-size: 11px; word-break: break-word; }
|
||||
.list-item-kind {
|
||||
display: inline-block; padding: 0 6px; margin-left: 6px;
|
||||
font-size: 10px; border-radius: 8px;
|
||||
background: var(--accent-soft); color: var(--accent);
|
||||
}
|
||||
.list-empty {
|
||||
color: var(--text-dim); font-size: 12px; line-height: 1.8;
|
||||
text-align: center; padding: 30px 6px; white-space: pre-line;
|
||||
}
|
||||
|
||||
/* AI 面板 */
|
||||
.ai-pane { display: flex; flex-direction: column; gap: 10px; overflow: hidden; }
|
||||
.ai-status {
|
||||
font-size: 11px; line-height: 1.6; color: var(--text-dim);
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
|
||||
padding: 6px 8px; word-break: break-word; flex-shrink: 0;
|
||||
}
|
||||
.ai-status.warn { color: var(--warn-text); border-color: var(--warn-line); }
|
||||
.ai-scope { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
|
||||
.ai-scope-label { font-size: 11px; color: var(--text-dim); flex: none; }
|
||||
.ai-scope-select {
|
||||
background: var(--bg-card); border: 1px solid var(--line); color: var(--text);
|
||||
border-radius: 6px; padding: 3px 6px; font-size: 11px;
|
||||
}
|
||||
.ai-cost { font-size: 11px; color: var(--text-dim); margin-left: auto; text-align: right; }
|
||||
.ai-visual-card {
|
||||
display: grid; grid-template-columns: 68px minmax(0, 1fr); gap: 8px;
|
||||
padding: 8px; border: 1px solid var(--accent); border-radius: 8px;
|
||||
background: var(--bg-card); flex-shrink: 0;
|
||||
}
|
||||
.ai-visual-card img {
|
||||
width: 68px; height: 76px; object-fit: contain;
|
||||
border: 1px solid var(--line); border-radius: 5px; background: #fff;
|
||||
}
|
||||
.ai-visual-body {
|
||||
min-width: 0; display: flex; flex-direction: column; gap: 3px;
|
||||
font-size: 11px; color: var(--text-dim);
|
||||
}
|
||||
.ai-visual-body strong { color: var(--text); font-size: 12px; }
|
||||
.ai-visual-body span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
.ai-visual-actions {
|
||||
grid-column: 1 / -1; display: flex; flex-wrap: wrap; gap: 5px;
|
||||
}
|
||||
.ai-visual-actions .tb-btn { flex: 1 1 auto; }
|
||||
.ai-quick { display: flex; flex-wrap: wrap; gap: 6px; flex-shrink: 0; }
|
||||
.ai-quote {
|
||||
flex-shrink: 0; padding-left: 8px; border-left: 2px solid var(--accent);
|
||||
font-size: 11px; line-height: 1.6; color: var(--text-dim);
|
||||
max-height: 4.8em; overflow-y: auto; word-break: break-word;
|
||||
}
|
||||
.ai-output {
|
||||
flex: 1; min-height: 120px; overflow-y: auto;
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 8px;
|
||||
padding: 10px; font-size: 13px; line-height: 1.75;
|
||||
white-space: normal; overflow-wrap: anywhere;
|
||||
}
|
||||
.ai-output.ai-output-plain { white-space: pre-wrap; }
|
||||
.ai-output:empty::before { content: "AI 回复会显示在这里"; color: var(--text-dim); font-size: 12px; }
|
||||
.ai-output.streaming { border-color: var(--accent); }
|
||||
.ai-output > :first-child { margin-top: 0; }
|
||||
.ai-output > :last-child { margin-bottom: 0; }
|
||||
.ai-output p,
|
||||
.ai-output ul,
|
||||
.ai-output ol,
|
||||
.ai-output blockquote,
|
||||
.ai-output pre,
|
||||
.ai-output table,
|
||||
.ai-output hr { margin: 0.65em 0; }
|
||||
.ai-output h1,
|
||||
.ai-output h2,
|
||||
.ai-output h3,
|
||||
.ai-output h4,
|
||||
.ai-output h5,
|
||||
.ai-output h6 {
|
||||
margin: 0.9em 0 0.45em;
|
||||
color: var(--text);
|
||||
line-height: 1.35;
|
||||
}
|
||||
.ai-output h1 { font-size: 1.5em; }
|
||||
.ai-output h2 { font-size: 1.32em; }
|
||||
.ai-output h3 { font-size: 1.16em; }
|
||||
.ai-output h4,
|
||||
.ai-output h5,
|
||||
.ai-output h6 { font-size: 1em; }
|
||||
.ai-output ul,
|
||||
.ai-output ol { padding-left: 1.7em; }
|
||||
.ai-output li + li { margin-top: 0.2em; }
|
||||
.ai-output blockquote {
|
||||
padding: 0.35em 0.75em;
|
||||
border-left: 3px solid var(--accent);
|
||||
background: var(--accent-faint);
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.ai-output code {
|
||||
padding: 0.12em 0.35em;
|
||||
border-radius: 4px;
|
||||
background: var(--input-bg);
|
||||
font-family: Consolas, "Cascadia Mono", monospace;
|
||||
font-size: 0.92em;
|
||||
}
|
||||
.ai-output pre {
|
||||
max-width: 100%;
|
||||
overflow: auto;
|
||||
padding: 9px 10px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 7px;
|
||||
background: var(--input-bg);
|
||||
white-space: pre;
|
||||
overflow-wrap: normal;
|
||||
}
|
||||
.ai-output pre code {
|
||||
padding: 0;
|
||||
background: transparent;
|
||||
white-space: inherit;
|
||||
}
|
||||
.ai-output table {
|
||||
display: block;
|
||||
max-width: 100%;
|
||||
overflow-x: auto;
|
||||
border-collapse: collapse;
|
||||
}
|
||||
.ai-output th,
|
||||
.ai-output td {
|
||||
padding: 5px 8px;
|
||||
border: 1px solid var(--line);
|
||||
text-align: left;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.ai-output th { background: var(--accent-faint); }
|
||||
.ai-output hr {
|
||||
border: 0;
|
||||
border-top: 1px solid var(--line);
|
||||
}
|
||||
.ai-output a {
|
||||
color: var(--accent-bright);
|
||||
text-decoration: underline;
|
||||
cursor: pointer;
|
||||
}
|
||||
.ai-output .ai-md-link-blocked {
|
||||
color: var(--text-dim);
|
||||
cursor: not-allowed;
|
||||
text-decoration-style: dotted;
|
||||
}
|
||||
.ai-md-image-placeholder {
|
||||
color: var(--text-dim);
|
||||
font-style: italic;
|
||||
}
|
||||
.ai-error { flex-shrink: 0; font-size: 12px; line-height: 1.6; color: var(--error-text); word-break: break-word; }
|
||||
.ai-out-actions { display: flex; gap: 6px; flex-shrink: 0; flex-wrap: wrap; }
|
||||
.ai-input { display: flex; gap: 6px; align-items: flex-end; flex-shrink: 0; }
|
||||
.ai-input textarea {
|
||||
flex: 1; resize: none;
|
||||
background: var(--input-bg); color: var(--text);
|
||||
border: 1px solid var(--line); border-radius: 8px;
|
||||
padding: 6px 8px; font-size: 12px; line-height: 1.6; outline: none;
|
||||
font-family: inherit;
|
||||
}
|
||||
.ai-input textarea:focus { border-color: var(--accent); }
|
||||
|
||||
.visual-select-overlay {
|
||||
position: absolute; inset: 0; z-index: 45; overflow: hidden;
|
||||
cursor: crosshair; touch-action: none;
|
||||
-webkit-user-select: none; user-select: none;
|
||||
}
|
||||
.visual-select-overlay.visual-select-capturing { opacity: 0; pointer-events: none; }
|
||||
.visual-select-hint {
|
||||
position: absolute; top: 12px; left: 50%; z-index: 3;
|
||||
transform: translateX(-50%); max-width: calc(100% - 24px);
|
||||
padding: 7px 11px; border: 1px solid rgba(255,255,255,0.3);
|
||||
border-radius: 7px; background: rgba(20,20,20,0.9);
|
||||
color: #fff; font-size: 12px; white-space: nowrap; pointer-events: none;
|
||||
}
|
||||
.visual-select-box {
|
||||
position: absolute; z-index: 2; box-sizing: border-box;
|
||||
border: 2px solid #4ca3ff; background: rgba(76,163,255,0.08);
|
||||
box-shadow: 0 0 0 9999px rgba(0,0,0,0.52); cursor: move;
|
||||
}
|
||||
.visual-select-handle {
|
||||
position: absolute; width: 12px; height: 12px;
|
||||
border: 2px solid #fff; border-radius: 50%; background: #1687ff;
|
||||
}
|
||||
.handle-nw { left: -7px; top: -7px; cursor: nwse-resize; }
|
||||
.handle-ne { right: -7px; top: -7px; cursor: nesw-resize; }
|
||||
.handle-se { right: -7px; bottom: -7px; cursor: nwse-resize; }
|
||||
.handle-sw { left: -7px; bottom: -7px; cursor: nesw-resize; }
|
||||
.visual-select-actions {
|
||||
position: absolute; left: 50%; bottom: 14px; z-index: 4;
|
||||
transform: translateX(-50%); display: flex; gap: 6px; padding: 6px;
|
||||
border: 1px solid var(--line); border-radius: 8px; background: var(--bg-card);
|
||||
box-shadow: 0 8px 28px rgba(0,0,0,0.45); cursor: default;
|
||||
}
|
||||
|
||||
/* 划选浮动工具条 */
|
||||
.sel-bar {
|
||||
position: fixed; z-index: 40;
|
||||
display: flex; gap: 2px;
|
||||
padding: 4px;
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 10px;
|
||||
box-shadow: 0 6px 20px var(--floating-shadow);
|
||||
}
|
||||
.sel-btn {
|
||||
height: 24px; padding: 0 10px;
|
||||
background: transparent; border: none; border-radius: 6px;
|
||||
color: var(--text); font-size: 12px; cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.sel-btn:hover { background: var(--accent); color: var(--on-accent); }
|
||||
|
||||
/* 提示条 */
|
||||
.toast {
|
||||
position: fixed; left: 50%; bottom: 58px; transform: translateX(-50%);
|
||||
z-index: 60; max-width: 70vw;
|
||||
padding: 8px 16px;
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 20px;
|
||||
color: var(--text); font-size: 12px; line-height: 1.5;
|
||||
box-shadow: 0 6px 20px var(--floating-shadow);
|
||||
word-break: break-word;
|
||||
}
|
||||
.toast.err { border-color: var(--danger); color: var(--error-text); }
|
||||
|
||||
/* 书库选择弹窗 */
|
||||
.modal {
|
||||
position: fixed; inset: 0; z-index: 50;
|
||||
background: rgba(0,0,0,0.6);
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
}
|
||||
.modal-box {
|
||||
width: 460px; max-width: 90vw;
|
||||
background: var(--bg-card); border: 1px solid var(--line); border-radius: 14px; padding: 18px;
|
||||
box-shadow: 0 18px 60px rgba(0,0,0,0.45);
|
||||
}
|
||||
.modal-title { font-size: 15px; font-weight: 700; margin-bottom: 12px; }
|
||||
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 14px; }
|
||||
.ai-confirm-box { width: 480px; }
|
||||
.ai-confirm-summary {
|
||||
display: grid; grid-template-columns: minmax(0, 0.8fr) minmax(0, 1.2fr); gap: 8px;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
.ai-confirm-summary > div {
|
||||
min-width: 0; padding: 10px 12px;
|
||||
background: var(--accent-faint); border: 1px solid var(--line); border-radius: 9px;
|
||||
}
|
||||
.ai-confirm-label {
|
||||
display: block; margin-bottom: 4px;
|
||||
color: var(--text-dim); font-size: 11px;
|
||||
}
|
||||
.ai-confirm-summary strong {
|
||||
display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
|
||||
color: var(--accent-bright); font-size: 13px;
|
||||
}
|
||||
.ai-confirm-notice {
|
||||
color: var(--text-dim); font-size: 12px; line-height: 1.7;
|
||||
}
|
||||
.pick-list { max-height: 48vh; overflow-y: auto; display: flex; flex-direction: column; gap: 4px; }
|
||||
.pick-item {
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
width: 100%; padding: 8px 10px; text-align: left;
|
||||
background: transparent; border: 1px solid var(--line); border-radius: 8px;
|
||||
color: var(--text); font-size: 13px; cursor: pointer;
|
||||
font-family: inherit;
|
||||
}
|
||||
.pick-item:hover { border-color: var(--accent); background: var(--accent-faint); }
|
||||
.pick-item:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
.pick-item-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
.note-editor-box {
|
||||
display: flex;
|
||||
width: 760px;
|
||||
max-height: 92vh;
|
||||
flex-direction: column;
|
||||
}
|
||||
.note-editor-fields { display: flex; flex-direction: column; gap: 10px; }
|
||||
.note-type-chooser {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(2, minmax(0, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
.note-type-choice {
|
||||
display: flex;
|
||||
min-height: 128px;
|
||||
padding: 18px;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 11px;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
text-align: left;
|
||||
}
|
||||
.note-type-choice:hover,
|
||||
.note-type-choice:focus-visible {
|
||||
background: var(--accent-faint);
|
||||
border-color: var(--accent);
|
||||
outline: none;
|
||||
}
|
||||
.note-type-choice-title { font-size: 15px; font-weight: 700; }
|
||||
.note-type-choice-desc { color: var(--text-dim); font-size: 12px; line-height: 1.55; }
|
||||
.canvas-note-modal .note-editor-box {
|
||||
height: 94vh;
|
||||
width: min(1180px, 96vw);
|
||||
max-width: 96vw;
|
||||
max-height: 94vh;
|
||||
padding: 16px;
|
||||
}
|
||||
.canvas-note-modal .note-editor-fields {
|
||||
display: grid;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
grid-template-columns: minmax(0, 1fr) minmax(220px, 0.55fr);
|
||||
grid-template-rows: auto minmax(0, 1fr) auto;
|
||||
gap: 8px 10px;
|
||||
overflow: hidden;
|
||||
}
|
||||
.canvas-note-modal .modal-title,
|
||||
.canvas-note-modal .modal-actions {
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
.canvas-note-modal #noteRichEditor {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
grid-column: 1 / -1;
|
||||
flex-direction: column;
|
||||
}
|
||||
.canvas-note-modal #noteRichEditor .mixed-note-editor,
|
||||
.canvas-note-modal #noteRichEditor .mixed-note-canvas {
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
}
|
||||
.canvas-note-modal .note-editor-quote {
|
||||
max-height: 3.2em;
|
||||
grid-column: 1 / -1;
|
||||
overflow: hidden;
|
||||
}
|
||||
.canvas-note-modal .note-editor-row {
|
||||
min-width: 0;
|
||||
}
|
||||
.canvas-note-modal .note-editor-pin {
|
||||
align-self: end;
|
||||
justify-self: end;
|
||||
white-space: nowrap;
|
||||
}
|
||||
@media (max-width: 680px) {
|
||||
.canvas-note-modal .note-editor-box {
|
||||
height: 98vh;
|
||||
max-height: 98vh;
|
||||
}
|
||||
.canvas-note-modal .note-editor-fields {
|
||||
grid-template-columns: minmax(0, 1fr);
|
||||
grid-template-rows: auto auto minmax(0, 1fr) auto auto;
|
||||
}
|
||||
.canvas-note-modal #noteRichEditor {
|
||||
grid-column: 1;
|
||||
}
|
||||
.canvas-note-modal .note-editor-pin {
|
||||
justify-self: start;
|
||||
}
|
||||
}
|
||||
.note-editor-association {
|
||||
padding: 7px 9px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
background: var(--panel);
|
||||
color: var(--text-dim);
|
||||
font-size: 12px;
|
||||
}
|
||||
.note-editor-input {
|
||||
width: 100%; padding: 8px 10px;
|
||||
background: var(--input-bg); color: var(--text);
|
||||
border: 1px solid var(--line); border-radius: 8px; outline: none;
|
||||
font: inherit; font-size: 12px; line-height: 1.6;
|
||||
}
|
||||
textarea.note-editor-input { resize: vertical; min-height: 110px; }
|
||||
.note-editor-input:focus { border-color: var(--accent); }
|
||||
.rich-note-editor {
|
||||
overflow: hidden;
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 9px;
|
||||
}
|
||||
.rich-note-editor:focus-within { border-color: var(--accent); }
|
||||
.rich-note-toolbar {
|
||||
display: flex; align-items: center; gap: 4px; padding: 6px;
|
||||
background: var(--panel); border-bottom: 1px solid var(--line); flex-wrap: wrap;
|
||||
}
|
||||
.rich-note-style,
|
||||
.rich-note-tool {
|
||||
height: 28px; background: var(--bg-card); border: 1px solid var(--line);
|
||||
border-radius: 6px; color: var(--text); font: inherit;
|
||||
}
|
||||
.rich-note-style { padding: 0 7px; }
|
||||
.rich-note-tool { min-width: 29px; padding: 0 7px; cursor: pointer; }
|
||||
.rich-note-tool:hover { border-color: var(--accent); color: var(--accent-bright); }
|
||||
.rich-note-tool-bold { font-weight: 700; }
|
||||
.rich-note-tool-italic { font-style: italic; }
|
||||
.rich-note-tool-underline { text-decoration: underline; }
|
||||
.rich-note-tool-strikeThrough { text-decoration: line-through; }
|
||||
.rich-note-surface {
|
||||
min-height: 220px; max-height: 42vh; padding: 12px 14px; overflow-y: auto;
|
||||
color: var(--text); font-size: 13px; line-height: 1.7; outline: none;
|
||||
}
|
||||
.rich-note-surface:empty::before {
|
||||
color: var(--text-dim); content: attr(data-placeholder); pointer-events: none;
|
||||
}
|
||||
.rich-note-surface .rich-note-image { cursor: default; }
|
||||
.rich-note-image-remove {
|
||||
position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; padding: 0;
|
||||
background: rgba(20,20,20,0.78); border: 1px solid rgba(255,255,255,0.35);
|
||||
border-radius: 50%; color: #fff; cursor: pointer; font-size: 18px; line-height: 22px;
|
||||
}
|
||||
.rich-note-image-remove:hover { background: var(--danger); }
|
||||
.note-editor-quote {
|
||||
max-height: 120px; overflow-y: auto;
|
||||
padding: 8px 10px; border-left: 3px solid var(--accent);
|
||||
background: var(--accent-faint); color: var(--text-dim);
|
||||
font-size: 12px; line-height: 1.6; white-space: pre-wrap;
|
||||
}
|
||||
.note-editor-row { display: flex; align-items: flex-end; gap: 10px; }
|
||||
.note-editor-row label {
|
||||
display: flex; flex-direction: column; gap: 5px;
|
||||
color: var(--text-dim); font-size: 11px;
|
||||
}
|
||||
.note-editor-row .mini-select { min-width: 140px; }
|
||||
.note-editor-tags { flex: 1; }
|
||||
.note-editor-pin { color: var(--text-dim); font-size: 12px; }
|
||||
|
||||
/* 滚动条 */
|
||||
::-webkit-scrollbar { width: 10px; height: 10px; }
|
||||
::-webkit-scrollbar-track { background: transparent; }
|
||||
::-webkit-scrollbar-thumb { background: var(--scrollbar); border-radius: 6px; }
|
||||
::-webkit-scrollbar-thumb:hover { background: var(--scrollbar-hover); }
|
||||
@@ -0,0 +1,334 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN" data-ui-theme="dark">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta http-equiv="Content-Security-Policy" content="default-src 'self'; img-src 'self' data: blob:; style-src 'self' 'unsafe-inline'; worker-src 'self' blob:; script-src 'self'" />
|
||||
<title>PeopleLib</title>
|
||||
<link rel="stylesheet" href="reader.css" />
|
||||
<link rel="stylesheet" href="vendor/quill/quill.snow.css" />
|
||||
<link rel="stylesheet" href="rich-note.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div class="titlebar">
|
||||
<div class="titlebar-left">
|
||||
<span class="brand">
|
||||
<img class="brand-logo brand-logo-dark" src="../../icons/dist/dark/icon-32.png" alt="" />
|
||||
<img class="brand-logo brand-logo-light" src="../../icons/dist/light/icon-32.png" alt="" />
|
||||
<span>人民阅读器</span>
|
||||
</span>
|
||||
<span id="bookTitle" class="brand-sub">未打开书籍</span>
|
||||
</div>
|
||||
<div class="titlebar-spacer"></div>
|
||||
<div class="titlebar-controls">
|
||||
<button id="uiThemeBtn" class="win-btn ui-theme-btn" title="切换到明亮主题" aria-label="切换到明亮主题">
|
||||
<svg class="toolbar-icon ui-theme-sun" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<circle cx="12" cy="12" r="4"/><path d="M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4"/>
|
||||
</svg>
|
||||
<svg class="toolbar-icon ui-theme-moon" viewBox="0 0 24 24" aria-hidden="true">
|
||||
<path d="M20 15.5A8.5 8.5 0 0 1 8.5 4 8.5 8.5 0 1 0 20 15.5Z"/>
|
||||
</svg>
|
||||
</button>
|
||||
<button id="minBtn" class="win-btn" title="最小化">─</button>
|
||||
<button id="maxBtn" class="win-btn" title="最大化">□</button>
|
||||
<button id="closeBtn" class="win-btn win-close" title="关闭">✕</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="doctabs">
|
||||
<div id="docTabs" class="doctabs-list"></div>
|
||||
<button id="addTabBtn" class="doctab-add" title="打开其它书籍">+</button>
|
||||
</div>
|
||||
|
||||
<div id="annotationToolbar" class="annotation-toolbar hidden" role="toolbar" aria-label="PDF 批注工具">
|
||||
<span class="annotation-title">PDF 批注</span>
|
||||
<div class="annotation-tools">
|
||||
<button class="annotation-tool active" data-annotation-tool="pan" title="拖拽页面" aria-label="拖拽页面">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 11V6a1.5 1.5 0 0 1 3 0v4-6a1.5 1.5 0 0 1 3 0v6-5a1.5 1.5 0 0 1 3 0v6-3a1.5 1.5 0 0 1 3 0v5c0 5-3 8-8 8h-1c-2 0-3.5-1-4.5-2.5L3 13.5A1.5 1.5 0 0 1 5.3 12L8 14.5Z"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="text-select" title="选择正文文本" aria-label="选择正文文本">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M8 4h8M12 4v16M8 20h8"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="select" title="选择、移动或缩放批注" aria-label="选择、移动或缩放批注">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m5 3 13 9-6 1.5L9 19Z"/><path d="m13 14 4 6"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="pen" title="自由画笔" aria-label="自由画笔">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m4 20 4.5-1 10-10a2 2 0 0 0-3-3l-10 10Z"/><path d="m14 7 3 3M4 20l1.5-4"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="highlight" title="半透明高亮笔" aria-label="半透明高亮笔">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m7 15 8-11 4 3-8 11H7Z"/><path d="m13 7 4 3M4 20h16"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="rectangle" title="绘制矩形" aria-label="绘制矩形">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><rect x="4" y="5" width="16" height="14" rx="1"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="text" title="添加文本" aria-label="添加文本">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M5 5h14M12 5v14M8 19h8"/></svg>
|
||||
</button>
|
||||
<button class="annotation-tool" data-annotation-tool="eraser" title="点击删除批注对象" aria-label="点击删除批注对象">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m4 15 8-10 7 6-7 8H7Z"/><path d="m9 19 7-11M12 19h8"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
<span class="annotation-divider"></span>
|
||||
<label class="annotation-color" title="批注颜色">
|
||||
<input id="annotationColor" type="color" value="#ff4d4f" aria-label="批注颜色" />
|
||||
</label>
|
||||
<label class="annotation-width" title="线条粗细">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M4 12h16M4 18h16" class="stroke-widths"/></svg>
|
||||
<select id="annotationWidth" class="mini-select" aria-label="线条粗细">
|
||||
<option value="1">1</option>
|
||||
<option value="3" selected>3</option>
|
||||
<option value="5">5</option>
|
||||
<option value="8">8</option>
|
||||
</select>
|
||||
</label>
|
||||
<button id="annotationUndoBtn" class="tb-btn ghost sm annotation-icon-btn" title="撤销" aria-label="撤销" disabled>
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m9 7-5 5 5 5"/><path d="M5 12h8a6 6 0 0 1 6 6"/></svg>
|
||||
</button>
|
||||
<button id="annotationRedoBtn" class="tb-btn ghost sm annotation-icon-btn" title="重做" aria-label="重做" disabled>
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m15 7 5 5-5 5"/><path d="M19 12h-8a6 6 0 0 0-6 6"/></svg>
|
||||
</button>
|
||||
<button id="annotationClearBtn" class="tb-btn danger sm annotation-icon-btn" title="清除当前页所有批注" aria-label="清除当前页所有批注">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 7h16M9 7V4h6v3M7 7l1 13h8l1-13M10 11v5M14 11v5"/></svg>
|
||||
</button>
|
||||
<span id="annotationStatus" class="annotation-status">第 1 页 · 0 项</span>
|
||||
<button id="annotationCloseBtn" class="icon-btn" title="收起批注工具栏">✕</button>
|
||||
</div>
|
||||
|
||||
<div class="reader-body">
|
||||
<aside id="tocPane" class="side-pane side-left">
|
||||
<div class="pane-head">
|
||||
<span class="pane-head-title">目录</span>
|
||||
<button id="tocHideBtn" class="icon-btn" title="收起目录">✕</button>
|
||||
</div>
|
||||
<div id="tocList" class="pane-body"></div>
|
||||
</aside>
|
||||
|
||||
<main id="docArea" class="doc-area">
|
||||
<div id="docEmpty" class="doc-empty">
|
||||
<div class="doc-empty-title">没有打开的书籍</div>
|
||||
<div class="doc-empty-sub">点击上方的 + 从书库中选择 PDF、EPUB、MOBI、AZW 或 AZW3 图书</div>
|
||||
<button id="emptyOpenBtn" class="tb-btn">从书库打开</button>
|
||||
</div>
|
||||
</main>
|
||||
|
||||
<aside id="sidePane" class="side-pane side-right">
|
||||
<div class="pane-tabs">
|
||||
<button class="pane-tab active" data-pane="bookmarks">书签</button>
|
||||
<button class="pane-tab" data-pane="annotations">标注</button>
|
||||
<button class="pane-tab" data-pane="notes">笔记</button>
|
||||
<button class="pane-tab" data-pane="ai">AI 助手</button>
|
||||
<button id="sideHideBtn" class="icon-btn pane-tabs-close" title="收起面板">✕</button>
|
||||
</div>
|
||||
|
||||
<div id="pane-bookmarks" class="pane-body">
|
||||
<div class="pane-toolbar">
|
||||
<button id="addBookmarkBtn" class="tb-btn sm">在当前位置加书签</button>
|
||||
</div>
|
||||
<div id="bookmarkList" class="list"></div>
|
||||
</div>
|
||||
|
||||
<div id="pane-annotations" class="pane-body hidden">
|
||||
<div id="annotationList" class="list"></div>
|
||||
</div>
|
||||
|
||||
<div id="pane-notes" class="pane-body hidden">
|
||||
<div class="pane-toolbar note-pane-toolbar">
|
||||
<button id="addNoteBtn" class="tb-btn sm">+ 新建笔记</button>
|
||||
<select id="noteCollectionFilter" class="mini-select" title="按笔记本筛选">
|
||||
<option value="">全部笔记本</option>
|
||||
</select>
|
||||
</div>
|
||||
<div id="noteList" class="list"></div>
|
||||
</div>
|
||||
|
||||
<div id="pane-ai" class="pane-body hidden ai-pane">
|
||||
<div id="aiStatus" class="ai-status">正在读取模型配置…</div>
|
||||
<div class="ai-scope">
|
||||
<span class="ai-scope-label">上下文</span>
|
||||
<select id="aiScope" class="ai-scope-select" title="决定每次提问发送多少正文,范围越大消耗越多">
|
||||
<option value="selection">仅选中文本</option>
|
||||
<option value="page">当前页</option>
|
||||
<option value="document">全文</option>
|
||||
<option value="page-image" data-requires-vision="true">当前页面(图像)</option>
|
||||
<option value="region-image" data-requires-vision="true">框选区域(图像)</option>
|
||||
</select>
|
||||
<span id="aiCost" class="ai-cost">未选中文本</span>
|
||||
</div>
|
||||
<div id="aiVisualCard" class="ai-visual-card hidden">
|
||||
<img id="aiVisualPreview" alt="待发送的图像上下文" />
|
||||
<div class="ai-visual-body">
|
||||
<strong id="aiVisualLabel">图像上下文</strong>
|
||||
<span id="aiVisualMeta"></span>
|
||||
<span id="aiOcrStatus">OCR:尚未识别</span>
|
||||
</div>
|
||||
<div class="ai-visual-actions">
|
||||
<button id="aiVisualReselectBtn" class="tb-btn ghost sm">重新获取</button>
|
||||
<button id="aiOcrBtn" class="tb-btn ghost sm" disabled title="OCR 引擎将在后续版本接入">OCR 识别</button>
|
||||
<button id="aiVisualRemoveBtn" class="tb-btn ghost sm">移除</button>
|
||||
</div>
|
||||
</div>
|
||||
<div class="ai-quick">
|
||||
<button class="tb-btn ghost sm" data-ai-task="summarize">总结</button>
|
||||
</div>
|
||||
<div id="aiQuote" class="ai-quote hidden"></div>
|
||||
<div id="aiOutput" class="ai-output" aria-live="polite"></div>
|
||||
<div id="aiError" class="ai-error hidden"></div>
|
||||
<div class="ai-out-actions">
|
||||
<button id="aiStopBtn" class="tb-btn danger sm hidden">停止生成</button>
|
||||
<button id="aiSaveBtn" class="tb-btn sm hidden">保存为笔记</button>
|
||||
<button id="aiCopyBtn" class="tb-btn ghost sm hidden">复制</button>
|
||||
</div>
|
||||
<div class="ai-input">
|
||||
<textarea id="aiQuestion" rows="3" maxlength="4000" placeholder="基于当前章节内容提问…"></textarea>
|
||||
<button id="aiSendBtn" class="tb-btn sm">发送</button>
|
||||
</div>
|
||||
</div>
|
||||
</aside>
|
||||
</div>
|
||||
|
||||
<div class="statusbar">
|
||||
<button id="tocToggleBtn" class="tb-btn ghost sm">目录</button>
|
||||
<span id="posLabel" class="status-text">—</span>
|
||||
<input id="progressRange" class="progress-range" type="range" min="0" max="1000" value="0" title="拖动跳转" />
|
||||
<span id="pctLabel" class="status-text dim">0%</span>
|
||||
<div class="spacer"></div>
|
||||
<span id="statusMsg" class="status-text dim"></span>
|
||||
<div class="statusbar-group">
|
||||
<button id="prevBtn" class="tb-btn ghost sm" title="上一页">←</button>
|
||||
<button id="nextBtn" class="tb-btn ghost sm" title="下一页">→</button>
|
||||
</div>
|
||||
<div class="statusbar-group">
|
||||
<button id="zoomOutBtn" class="tb-btn ghost sm" title="缩小">−</button>
|
||||
<span id="zoomLabel" class="status-text dim">—</span>
|
||||
<button id="zoomInBtn" class="tb-btn ghost sm" title="放大">+</button>
|
||||
<button id="fitWidthBtn" class="tb-btn ghost sm fit-width-btn hidden" title="适应内容宽度" aria-label="适应内容宽度">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="M4 5v14M20 5v14M7 12h10M10 9l-3 3 3 3M14 9l3 3-3 3"/></svg>
|
||||
</button>
|
||||
</div>
|
||||
<div id="pdfViewControls" class="statusbar-group pdf-view-controls hidden">
|
||||
<label><span>阅读</span>
|
||||
<select id="pdfViewMode" class="mini-select" title="PDF 阅读方式">
|
||||
<option value="continuous">连续</option>
|
||||
<option value="paged">分页</option>
|
||||
</select>
|
||||
</label>
|
||||
<label><span>版式</span>
|
||||
<select id="pdfPageLayout" class="mini-select" title="PDF 页面版式">
|
||||
<option value="single">单页</option>
|
||||
<option value="auto">自动</option>
|
||||
</select>
|
||||
</label>
|
||||
</div>
|
||||
<select id="themeSelect" class="mini-select" title="阅读主题">
|
||||
<option value="light">浅色</option>
|
||||
<option value="sepia">羊皮纸</option>
|
||||
<option value="dark">深色</option>
|
||||
</select>
|
||||
<button id="annotationToggleBtn" class="tb-btn ghost sm annotation-toggle-btn hidden" title="PDF 批注" aria-label="PDF 批注">
|
||||
<svg class="toolbar-icon" viewBox="0 0 24 24" aria-hidden="true"><path d="m4 20 4.5-1 10-10a2 2 0 0 0-3-3l-10 10Z"/><path d="m14 7 3 3M4 20l1.5-4"/></svg>
|
||||
</button>
|
||||
<button id="sideToggleBtn" class="tb-btn ghost sm">面板</button>
|
||||
</div>
|
||||
|
||||
<div id="selBar" class="sel-bar hidden">
|
||||
<button class="sel-btn" data-sel="translate">翻译</button>
|
||||
<button class="sel-btn" data-sel="explain">解释</button>
|
||||
<button class="sel-btn" data-sel="excerpt">摘录</button>
|
||||
<button class="sel-btn" data-sel="note">记笔记</button>
|
||||
<button class="sel-btn" data-sel="bookmark">加书签</button>
|
||||
<button class="sel-btn" data-sel="copy">复制</button>
|
||||
</div>
|
||||
|
||||
<div id="toast" class="toast hidden"></div>
|
||||
|
||||
<div id="pickModal" class="modal hidden">
|
||||
<div class="modal-box">
|
||||
<div class="modal-title">从书库打开</div>
|
||||
<div id="pickList" class="pick-list"></div>
|
||||
<div class="modal-actions">
|
||||
<button id="pickCancelBtn" class="tb-btn ghost">取消</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="aiConfirmModal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="aiConfirmTitle">
|
||||
<div class="modal-box ai-confirm-box">
|
||||
<div id="aiConfirmTitle" class="modal-title">确认发送到模型</div>
|
||||
<div class="ai-confirm-summary">
|
||||
<div>
|
||||
<span class="ai-confirm-label">上下文</span>
|
||||
<strong id="aiConfirmScope">—</strong>
|
||||
</div>
|
||||
<div>
|
||||
<span class="ai-confirm-label">预计用量</span>
|
||||
<strong id="aiConfirmCost">—</strong>
|
||||
</div>
|
||||
</div>
|
||||
<p id="aiConfirmNotice" class="ai-confirm-notice">正文将发送到你配置的模型接口,并可能产生费用。PeopleLib 不会自动发送,只有确认后才会继续。</p>
|
||||
<div class="modal-actions">
|
||||
<button id="aiConfirmCancelBtn" class="tb-btn ghost">取消</button>
|
||||
<button id="aiConfirmSendBtn" class="tb-btn">继续发送</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="annotationClearModal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="annotationClearTitle">
|
||||
<div class="modal-box confirm-box">
|
||||
<div id="annotationClearTitle" class="modal-title">清空当前页批注?</div>
|
||||
<p class="ai-confirm-notice">这会删除当前 PDF 页面上的全部批注,可以立即使用“撤销”恢复。</p>
|
||||
<div class="modal-actions">
|
||||
<button id="annotationClearCancelBtn" class="tb-btn ghost">取消</button>
|
||||
<button id="annotationClearConfirmBtn" class="tb-btn danger">清空本页</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="noteEditorModal" class="modal hidden" role="dialog" aria-modal="true" aria-labelledby="noteEditorTitle">
|
||||
<div class="modal-box note-editor-box">
|
||||
<div id="noteEditorTitle" class="modal-title">新建笔记</div>
|
||||
<div id="noteTypeChooser" class="note-type-chooser hidden">
|
||||
<button type="button" class="note-type-choice" data-note-type="reading">
|
||||
<span class="note-type-choice-title">读书笔记</span>
|
||||
<span class="note-type-choice-desc">富文本、摘录和阅读心得</span>
|
||||
</button>
|
||||
<button type="button" class="note-type-choice" data-note-type="canvas">
|
||||
<span class="note-type-choice-title">画布笔记</span>
|
||||
<span class="note-type-choice-desc">分页画布、手写工具和 PDF 底版</span>
|
||||
</button>
|
||||
</div>
|
||||
<div id="noteEditorFields" class="note-editor-fields">
|
||||
<div id="noteAssociation" class="note-editor-association"></div>
|
||||
<input id="noteTitleInput" class="note-editor-input" type="text" maxlength="300" placeholder="标题(可选)" />
|
||||
<div id="noteRichEditor"></div>
|
||||
<blockquote id="noteQuotePreview" class="note-editor-quote hidden"></blockquote>
|
||||
<div class="note-editor-row">
|
||||
<label>
|
||||
<span>笔记本</span>
|
||||
<select id="noteCollectionInput" class="mini-select">
|
||||
<option value="">未分类</option>
|
||||
</select>
|
||||
</label>
|
||||
<label class="note-editor-tags">
|
||||
<span>标签</span>
|
||||
<input id="noteTagsInput" class="note-editor-input" type="text" placeholder="用逗号分隔" />
|
||||
</label>
|
||||
</div>
|
||||
<label class="note-editor-pin"><input id="notePinnedInput" type="checkbox" /> 置顶笔记</label>
|
||||
</div>
|
||||
<div class="modal-actions">
|
||||
<button id="noteEditorCancelBtn" class="tb-btn ghost">取消</button>
|
||||
<button id="noteEditorSaveBtn" class="tb-btn">保存笔记</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="vendor/jszip.min.js"></script>
|
||||
<script src="vendor/quill/quill.js"></script>
|
||||
<script src="vendor/jspdf.umd.min.js"></script>
|
||||
<script src="vendor/purify.min.js"></script>
|
||||
<script src="vendor/markdown-it.min.js"></script>
|
||||
<script src="ai-markdown.js"></script>
|
||||
<script src="rich-note.js"></script>
|
||||
<script src="mixed-note.js"></script>
|
||||
<script type="module" src="reader/shell.mjs"></script>
|
||||
</body>
|
||||
</html>
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,488 @@
|
||||
import { isMOBI, MOBI } from '../../../node_modules/foliate-js/mobi.js';
|
||||
import { unzlibSync } from '../../../node_modules/foliate-js/vendor/fflate.js';
|
||||
import { createEpubAdapter } from './epub-adapter.mjs';
|
||||
|
||||
const MAX_FILE_SIZE = 256 * 1024 * 1024;
|
||||
const MAX_RECORDS = 20_000;
|
||||
const MAX_RESOURCE_SIZE = 32 * 1024 * 1024;
|
||||
const MAX_RESOURCE_TOTAL = 160 * 1024 * 1024;
|
||||
|
||||
const MIME_EXT = new Map([
|
||||
['image/jpeg', 'jpg'],
|
||||
['image/png', 'png'],
|
||||
['image/gif', 'gif'],
|
||||
['image/svg+xml', 'svg'],
|
||||
['image/webp', 'webp'],
|
||||
['image/bmp', 'bmp'],
|
||||
['text/css', 'css'],
|
||||
['font/woff', 'woff'],
|
||||
['font/woff2', 'woff2'],
|
||||
['application/vnd.ms-opentype', 'otf'],
|
||||
['font/otf', 'otf'],
|
||||
['font/ttf', 'ttf'],
|
||||
['audio/mpeg', 'mp3'],
|
||||
['video/mp4', 'mp4']
|
||||
]);
|
||||
|
||||
function clamp(value, low, high) {
|
||||
const number = Number(value);
|
||||
if (!Number.isFinite(number)) return low;
|
||||
return Math.min(high, Math.max(low, number));
|
||||
}
|
||||
|
||||
function tidy(value) {
|
||||
return String(value == null ? '' : value)
|
||||
.replace(/\r/g, '')
|
||||
.replace(/[ \t\f\v\u00a0]+/g, ' ')
|
||||
.replace(/ ?\n ?/g, '\n')
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim();
|
||||
}
|
||||
|
||||
function xml(value) {
|
||||
return String(value == null ? '' : value)
|
||||
.replace(/&/g, '&')
|
||||
.replace(/</g, '<')
|
||||
.replace(/>/g, '>')
|
||||
.replace(/"/g, '"')
|
||||
.replace(/'/g, ''');
|
||||
}
|
||||
|
||||
function localized(value) {
|
||||
if (value == null) return '';
|
||||
if (typeof value === 'string') return value;
|
||||
if (Array.isArray(value)) return localized(value[0]);
|
||||
if (typeof value === 'object') return localized(value['zh-CN'] || value.zh || value.en || Object.values(value)[0]);
|
||||
return String(value);
|
||||
}
|
||||
|
||||
function authorText(metadata) {
|
||||
const value = metadata && (metadata.author || metadata.creator);
|
||||
const list = Array.isArray(value) ? value : value == null ? [] : [value];
|
||||
return list.map((entry) => {
|
||||
if (typeof entry === 'object' && entry) return localized(entry.name || entry);
|
||||
return localized(entry);
|
||||
}).filter(Boolean).join('、');
|
||||
}
|
||||
|
||||
function bytesView(bytes) {
|
||||
if (bytes instanceof ArrayBuffer) return new Uint8Array(bytes);
|
||||
if (ArrayBuffer.isView(bytes)) {
|
||||
return new Uint8Array(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
||||
}
|
||||
throw new Error('MOBI 文件字节无效');
|
||||
}
|
||||
|
||||
function preflight(bytes) {
|
||||
const data = bytesView(bytes);
|
||||
if (data.byteLength < 100) throw new Error('MOBI 文件结构损坏:文件过短');
|
||||
if (data.byteLength > MAX_FILE_SIZE) throw new Error('MOBI 文件过大,暂不支持在内置阅读器中打开');
|
||||
const magic = new TextDecoder().decode(data.subarray(60, 68));
|
||||
if (magic !== 'BOOKMOBI') throw new Error('文件不是有效的 MOBI/KF8 图书');
|
||||
const view = new DataView(data.buffer, data.byteOffset, data.byteLength);
|
||||
const records = view.getUint16(76);
|
||||
if (!records || records > MAX_RECORDS) throw new Error('MOBI 文件结构损坏:记录数量异常');
|
||||
if (78 + records * 8 > data.byteLength) throw new Error('MOBI 文件结构损坏:记录表越界');
|
||||
const first = view.getUint32(78);
|
||||
if (first + 14 > data.byteLength) throw new Error('MOBI 文件结构损坏:主记录越界');
|
||||
if (view.getUint16(first + 12) !== 0) throw new Error('该 MOBI/AZW 图书有 DRM 保护,无法打开');
|
||||
return data;
|
||||
}
|
||||
|
||||
function sanitizeSourceDocument(doc) {
|
||||
doc.querySelectorAll('script, iframe, object, embed, link, meta, form, base').forEach((node) => node.remove());
|
||||
doc.querySelectorAll('*').forEach((element) => {
|
||||
for (const attribute of [...element.attributes]) {
|
||||
const name = attribute.name.toLowerCase();
|
||||
if (name.startsWith('on')) element.removeAttribute(attribute.name);
|
||||
if (['href', 'src', 'xlink:href'].includes(name)
|
||||
&& /^\s*(?:javascript|vbscript|file):/i.test(attribute.value)) {
|
||||
element.removeAttribute(attribute.name);
|
||||
} else if (['src', 'xlink:href', 'poster'].includes(name)
|
||||
&& /^\s*[a-z][a-z0-9+.-]*:/i.test(attribute.value)
|
||||
&& !/^\s*kindle:(?:flow|embed):/i.test(attribute.value)) {
|
||||
element.removeAttribute(attribute.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
doc.querySelectorAll('[srcset]').forEach((element) => element.removeAttribute('srcset'));
|
||||
}
|
||||
|
||||
function safeCss(value) {
|
||||
return String(value || '')
|
||||
.replace(/@import\s+[^;]+;?/gi, '')
|
||||
.replace(/url\(\s*(['"]?)\s*(?:https?:|file:|javascript:)[^)]*\)/gi, 'none');
|
||||
}
|
||||
|
||||
function ensureTargetId(target, doc, fallback) {
|
||||
if (!target) return '';
|
||||
let node = target;
|
||||
if (typeof Range !== 'undefined' && target instanceof Range) node = target.startContainer;
|
||||
if (node && node.nodeType === Node.TEXT_NODE) node = node.parentElement;
|
||||
if (!node || node.ownerDocument !== doc || !node.setAttribute) return '';
|
||||
if (!node.id) node.id = fallback;
|
||||
return node.id;
|
||||
}
|
||||
|
||||
function flattenToc(items, depth = 0, output = []) {
|
||||
for (const item of Array.isArray(items) ? items : []) {
|
||||
output.push({ item, depth });
|
||||
flattenToc(item && item.subitems, depth + 1, output);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
function extensionFor(blob, url) {
|
||||
const exact = MIME_EXT.get(String(blob.type || '').toLowerCase());
|
||||
if (exact) return exact;
|
||||
const match = String(url || '').match(/\.([a-z0-9]{2,5})(?:[?#]|$)/i);
|
||||
return match ? match[1].toLowerCase() : 'bin';
|
||||
}
|
||||
|
||||
function contentKind(blob) {
|
||||
const type = String(blob.type || '').toLowerCase();
|
||||
if (type.startsWith('image/')) return 'image';
|
||||
if (type.startsWith('audio/')) return 'audio';
|
||||
if (type.startsWith('video/')) return 'video';
|
||||
if (type.includes('font') || /(?:woff|ttf|otf)/.test(type)) return 'font';
|
||||
return 'resource';
|
||||
}
|
||||
|
||||
function mimeForBytes(value) {
|
||||
const bytes = bytesView(value);
|
||||
if (bytes[0] === 0xff && bytes[1] === 0xd8) return 'image/jpeg';
|
||||
if (bytes[0] === 0x89 && bytes[1] === 0x50 && bytes[2] === 0x4e && bytes[3] === 0x47) return 'image/png';
|
||||
if (new TextDecoder().decode(bytes.subarray(0, 6)).startsWith('GIF8')) return 'image/gif';
|
||||
if (new TextDecoder().decode(bytes.subarray(0, 4)) === 'RIFF') return 'image/webp';
|
||||
return 'application/octet-stream';
|
||||
}
|
||||
|
||||
export function createMobiAdapter(format = 'mobi') {
|
||||
const inner = createEpubAdapter();
|
||||
let book = null;
|
||||
let sourceFormat = ['mobi', 'azw', 'azw3'].includes(format) ? format : 'mobi';
|
||||
|
||||
async function buildEpub(onProgress) {
|
||||
const zip = new window.JSZip();
|
||||
const docs = [];
|
||||
const resources = new Map();
|
||||
let resourceBytes = 0;
|
||||
let resourceId = 0;
|
||||
|
||||
const storeResource = async (key, value) => {
|
||||
if (!key || !value) return '';
|
||||
if (resources.has(key)) return resources.get(key);
|
||||
const blob = value instanceof Blob
|
||||
? value
|
||||
: new Blob([value], { type: mimeForBytes(value) });
|
||||
if (blob.size > MAX_RESOURCE_SIZE || resourceBytes + blob.size > MAX_RESOURCE_TOTAL) return '';
|
||||
resourceBytes += blob.size;
|
||||
const name = `res-${++resourceId}.${extensionFor(blob, key)}`;
|
||||
const path = `resources/${name}`;
|
||||
zip.file(path, new Uint8Array(await blob.arrayBuffer()));
|
||||
const record = { path, href: `../${path}`, mediaType: blob.type || 'application/octet-stream', kind: contentKind(blob) };
|
||||
resources.set(key, record);
|
||||
return record;
|
||||
};
|
||||
|
||||
const rewriteCssResources = async (value) => {
|
||||
let css = String(value || '');
|
||||
const urls = [...new Set(css.match(/kindle:(?:flow|embed):[^'"\s)]+/gi) || [])];
|
||||
for (const url of urls) {
|
||||
let record = '';
|
||||
try {
|
||||
const [blob] = await book.loadResourceBlob(url);
|
||||
record = await storeResource(url, blob);
|
||||
} catch (error) { /* ignore damaged resource */ }
|
||||
css = css.split(url).join(record ? record.href : '');
|
||||
}
|
||||
return safeCss(css);
|
||||
};
|
||||
|
||||
for (let index = 0; index < book.sections.length; index++) {
|
||||
const section = book.sections[index];
|
||||
if (!section || typeof section.createDocument !== 'function') {
|
||||
docs[index] = null;
|
||||
continue;
|
||||
}
|
||||
const doc = await section.createDocument();
|
||||
for (const link of doc.querySelectorAll('link[href]')) {
|
||||
const href = link.getAttribute('href') || '';
|
||||
if (!/\bstylesheet\b/i.test(link.getAttribute('rel') || '')
|
||||
|| !/^kindle:(?:flow|embed):/i.test(href)
|
||||
|| typeof book.loadResourceBlob !== 'function') continue;
|
||||
try {
|
||||
const [blob] = await book.loadResourceBlob(href);
|
||||
const style = doc.createElement('style');
|
||||
style.textContent = await rewriteCssResources(await blob.text());
|
||||
link.replaceWith(style);
|
||||
} catch (error) { link.remove(); }
|
||||
}
|
||||
sanitizeSourceDocument(doc);
|
||||
|
||||
for (const element of doc.querySelectorAll('img[recindex], [mediarecindex]')) {
|
||||
const imageIndex = Number(element.getAttribute('recindex')) - 1;
|
||||
const mediaIndex = Number(element.getAttribute('mediarecindex')) - 1;
|
||||
if (Number.isInteger(imageIndex) && imageIndex >= 0) {
|
||||
try {
|
||||
const record = await storeResource(
|
||||
`recindex:${imageIndex}`,
|
||||
await book.mobi.loadResource(imageIndex)
|
||||
);
|
||||
if (record) {
|
||||
if (element.hasAttribute('mediarecindex')) element.setAttribute('poster', record.href);
|
||||
else element.setAttribute('src', record.href);
|
||||
}
|
||||
} catch (error) { /* ignore damaged resource */ }
|
||||
}
|
||||
if (Number.isInteger(mediaIndex) && mediaIndex >= 0) {
|
||||
try {
|
||||
const record = await storeResource(
|
||||
`mediarecindex:${mediaIndex}`,
|
||||
await book.mobi.loadResource(mediaIndex)
|
||||
);
|
||||
if (record) element.setAttribute('src', record.href);
|
||||
} catch (error) { /* ignore damaged resource */ }
|
||||
}
|
||||
element.removeAttribute('recindex');
|
||||
element.removeAttribute('mediarecindex');
|
||||
}
|
||||
|
||||
const resourceAttributes = [
|
||||
['img[src]', 'src'],
|
||||
['image[href]', 'href'],
|
||||
['image[xlink\\:href]', 'xlink:href'],
|
||||
['source[src]', 'src'],
|
||||
['video[poster]', 'poster'],
|
||||
['audio[src]', 'src'],
|
||||
['video[src]', 'src']
|
||||
];
|
||||
for (const [selector, attribute] of resourceAttributes) {
|
||||
for (const element of doc.querySelectorAll(selector)) {
|
||||
const original = element.getAttribute(attribute);
|
||||
if (!/^kindle:(?:flow|embed):/i.test(original || '') || typeof book.loadResourceBlob !== 'function') continue;
|
||||
try {
|
||||
const [blob] = await book.loadResourceBlob(original);
|
||||
const record = await storeResource(original, blob);
|
||||
if (!record) element.removeAttribute(attribute);
|
||||
else element.setAttribute(attribute, record.href);
|
||||
} catch (error) { element.removeAttribute(attribute); }
|
||||
}
|
||||
}
|
||||
for (const style of doc.querySelectorAll('style')) {
|
||||
style.textContent = await rewriteCssResources(style.textContent);
|
||||
}
|
||||
for (const element of doc.querySelectorAll('[style]')) {
|
||||
element.setAttribute('style', await rewriteCssResources(element.getAttribute('style')));
|
||||
}
|
||||
docs[index] = doc;
|
||||
if (onProgress) onProgress(0.15 + 0.35 * ((index + 1) / book.sections.length));
|
||||
}
|
||||
|
||||
const resolveTarget = async (href, fallback) => {
|
||||
let target;
|
||||
try { target = await book.resolveHref(href); } catch (error) { return null; }
|
||||
if (!target || !Number.isInteger(target.index) || !docs[target.index]) return null;
|
||||
let anchor;
|
||||
try { anchor = typeof target.anchor === 'function' ? target.anchor(docs[target.index]) : null; } catch (error) { anchor = null; }
|
||||
const id = ensureTargetId(anchor, docs[target.index], fallback);
|
||||
return { index: target.index, id };
|
||||
};
|
||||
|
||||
for (let index = 0; index < docs.length; index++) {
|
||||
const doc = docs[index];
|
||||
if (!doc) continue;
|
||||
let linkId = 0;
|
||||
for (const anchor of doc.querySelectorAll('a[href]')) {
|
||||
const href = anchor.getAttribute('href') || '';
|
||||
if (!href || (book.isExternal && book.isExternal(href))) {
|
||||
anchor.removeAttribute('href');
|
||||
continue;
|
||||
}
|
||||
const target = await resolveTarget(href, `mobi-link-${index}-${++linkId}`);
|
||||
if (!target) anchor.removeAttribute('href');
|
||||
else anchor.setAttribute('href', `chapter-${target.index}.xhtml${target.id ? `#${target.id}` : ''}`);
|
||||
}
|
||||
}
|
||||
|
||||
const toc = [];
|
||||
let tocId = 0;
|
||||
for (const entry of flattenToc(book.toc)) {
|
||||
const target = await resolveTarget(entry.item.href, `mobi-toc-${++tocId}`);
|
||||
if (target) toc.push({
|
||||
label: tidy(entry.item.label) || '未命名',
|
||||
depth: entry.depth,
|
||||
href: `text/chapter-${target.index}.xhtml${target.id ? `#${target.id}` : ''}`
|
||||
});
|
||||
}
|
||||
|
||||
const serializer = new XMLSerializer();
|
||||
const validSections = [];
|
||||
for (let index = 0; index < docs.length; index++) {
|
||||
const doc = docs[index];
|
||||
if (!doc) continue;
|
||||
doc.documentElement.setAttribute('xmlns', 'http://www.w3.org/1999/xhtml');
|
||||
doc.querySelectorAll('style').forEach((style) => { style.textContent = safeCss(style.textContent); });
|
||||
const path = `text/chapter-${index}.xhtml`;
|
||||
zip.file(path, serializer.serializeToString(doc));
|
||||
validSections.push({ index, path });
|
||||
}
|
||||
if (!validSections.length) throw new Error('MOBI 文件中没有可阅读的正文');
|
||||
|
||||
const metadata = book.metadata || {};
|
||||
const title = tidy(localized(metadata.title)) || '未命名书籍';
|
||||
const author = tidy(authorText(metadata));
|
||||
const language = tidy(localized(metadata.language)) || 'zh-CN';
|
||||
const identifier = tidy(localized(metadata.identifier)) || `peoplelib-mobi-${Date.now()}`;
|
||||
const manifest = validSections
|
||||
.map(({ index, path }) => `<item id="chapter-${index}" href="${xml(path)}" media-type="application/xhtml+xml"/>`)
|
||||
.concat([...resources.values()].map((record, index) =>
|
||||
`<item id="resource-${index}" href="${xml(record.path)}" media-type="${xml(record.mediaType)}"/>`))
|
||||
.concat('<item id="nav" href="nav.xhtml" media-type="application/xhtml+xml" properties="nav"/>')
|
||||
.join('');
|
||||
const spine = validSections.map(({ index }) => `<itemref idref="chapter-${index}"/>`).join('');
|
||||
const navItems = toc.length
|
||||
? toc.map((entry) => `<li style="margin-inline-start:${entry.depth * 1.2}em"><a href="${xml(entry.href)}">${xml(entry.label)}</a></li>`).join('')
|
||||
: validSections.map(({ index }) => `<li><a href="text/chapter-${index}.xhtml">第 ${index + 1} 章</a></li>`).join('');
|
||||
|
||||
zip.file('mimetype', 'application/epub+zip', { compression: 'STORE' });
|
||||
zip.file('META-INF/container.xml',
|
||||
'<?xml version="1.0" encoding="UTF-8"?><container version="1.0" xmlns="urn:oasis:names:tc:opendocument:xmlns:container"><rootfiles><rootfile full-path="content.opf" media-type="application/oebps-package+xml"/></rootfiles></container>');
|
||||
zip.file('content.opf',
|
||||
`<?xml version="1.0" encoding="UTF-8"?><package version="3.0" unique-identifier="book-id" xmlns="http://www.idpf.org/2007/opf"><metadata xmlns:dc="http://purl.org/dc/elements/1.1/"><dc:identifier id="book-id">${xml(identifier)}</dc:identifier><dc:title>${xml(title)}</dc:title>${author ? `<dc:creator>${xml(author)}</dc:creator>` : ''}<dc:language>${xml(language)}</dc:language></metadata><manifest>${manifest}</manifest><spine>${spine}</spine></package>`);
|
||||
zip.file('nav.xhtml',
|
||||
`<!doctype html><html xmlns="http://www.w3.org/1999/xhtml"><head><title>${xml(title)}</title></head><body><nav epub:type="toc" xmlns:epub="http://www.idpf.org/2007/ops"><ol>${navItems}</ol></nav></body></html>`);
|
||||
return zip.generateAsync({ type: 'uint8array', compression: 'DEFLATE', compressionOptions: { level: 6 } });
|
||||
}
|
||||
|
||||
async function load(bytes, options = {}) {
|
||||
destroyBook();
|
||||
if (!window.JSZip) throw new Error('缺少 jszip 依赖,无法准备 MOBI 内容');
|
||||
const data = preflight(bytes);
|
||||
const report = typeof options.onProgress === 'function'
|
||||
? (value) => options.onProgress(clamp(value, 0, 1))
|
||||
: null;
|
||||
if (report) report(0.02);
|
||||
const file = new File([data], `book.${sourceFormat}`, { type: 'application/x-mobipocket-ebook' });
|
||||
if (!await isMOBI(file)) throw new Error('文件不是有效的 MOBI/KF8 图书');
|
||||
try {
|
||||
book = await new MOBI({ unzlib: unzlibSync }).open(file);
|
||||
} catch (error) {
|
||||
const message = String(error && error.message || error);
|
||||
if (/compression/i.test(message)) throw new Error('该 MOBI 使用了暂不支持的压缩方式');
|
||||
throw new Error(`MOBI 文件无法解析:${message}`);
|
||||
}
|
||||
if (report) report(0.15);
|
||||
const epubBytes = await buildEpub(report);
|
||||
const result = await inner.load(epubBytes, {
|
||||
...options,
|
||||
onProgress: report ? (value) => report(0.55 + value * 0.45) : null
|
||||
});
|
||||
return { ...result, title: tidy(localized(book.metadata && book.metadata.title)) || result.title, format: sourceFormat };
|
||||
}
|
||||
|
||||
function toInner(locator) {
|
||||
const value = locator && typeof locator === 'object' ? locator : {};
|
||||
return { kind: 'epub', chapter: value.chapter, offset: value.offset };
|
||||
}
|
||||
|
||||
function fromInner(locator) {
|
||||
const value = locator && typeof locator === 'object' ? locator : {};
|
||||
return { kind: sourceFormat, chapter: value.chapter || 0, offset: value.offset || 0 };
|
||||
}
|
||||
|
||||
function renderTo(container, locator, options) {
|
||||
return inner.renderTo(container, toInner(locator), options)
|
||||
.then((result) => ({ ...result, locator: fromInner(result.locator) }));
|
||||
}
|
||||
|
||||
async function toc() {
|
||||
return (await inner.toc()).map((entry) => ({ ...entry, locator: fromInner(entry.locator) }));
|
||||
}
|
||||
|
||||
function getSelection() {
|
||||
const selection = inner.getSelection();
|
||||
return selection ? { ...selection, locator: fromInner(selection.locator) } : null;
|
||||
}
|
||||
|
||||
function textOf(locator, span) {
|
||||
return inner.textOf(toInner(locator), span);
|
||||
}
|
||||
|
||||
function visualViewportRect() {
|
||||
const value = inner.visualViewportRect();
|
||||
return value ? { ...value, locator: fromInner(value.locator) } : null;
|
||||
}
|
||||
|
||||
function locatorLabel(locator) {
|
||||
return inner.locatorLabel(toInner(locator));
|
||||
}
|
||||
|
||||
function nextLocator(locator) {
|
||||
const next = inner.nextLocator(toInner(locator));
|
||||
return next ? fromInner(next) : null;
|
||||
}
|
||||
|
||||
function prevLocator(locator) {
|
||||
const previous = inner.prevLocator(toInner(locator));
|
||||
return previous ? fromInner(previous) : null;
|
||||
}
|
||||
|
||||
function percentOf(locator) {
|
||||
return inner.percentOf(toInner(locator));
|
||||
}
|
||||
|
||||
function locatorFromPercent(percent) {
|
||||
return fromInner(inner.locatorFromPercent(percent));
|
||||
}
|
||||
|
||||
function capturePinchAnchor(x, y) {
|
||||
const anchor = inner.capturePinchAnchor(x, y);
|
||||
return anchor ? { ...anchor, kind: sourceFormat } : null;
|
||||
}
|
||||
|
||||
function restorePinchAnchor(anchor) {
|
||||
inner.restorePinchAnchor(anchor);
|
||||
}
|
||||
|
||||
function setLocatorChangeHandler(handler) {
|
||||
inner.setLocatorChangeHandler(typeof handler === 'function'
|
||||
? (locator, percent) => handler(fromInner(locator), percent)
|
||||
: null);
|
||||
}
|
||||
|
||||
function setTouchGestureHandler(handler) {
|
||||
inner.setTouchGestureHandler(handler);
|
||||
}
|
||||
|
||||
function destroyBook() {
|
||||
if (book && typeof book.destroy === 'function') {
|
||||
try { book.destroy(); } catch (error) { /* ignore */ }
|
||||
}
|
||||
book = null;
|
||||
}
|
||||
|
||||
function destroy() {
|
||||
inner.destroy();
|
||||
destroyBook();
|
||||
}
|
||||
|
||||
return {
|
||||
load,
|
||||
renderTo,
|
||||
toc,
|
||||
getSelection,
|
||||
textOf,
|
||||
visualViewportRect,
|
||||
locatorLabel,
|
||||
nextLocator,
|
||||
prevLocator,
|
||||
percentOf,
|
||||
locatorFromPercent,
|
||||
capturePinchAnchor,
|
||||
restorePinchAnchor,
|
||||
setLocatorChangeHandler,
|
||||
setTouchGestureHandler,
|
||||
destroy
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
const MAX_OCR_CHARS = 12000;
|
||||
let provider = null;
|
||||
|
||||
function imageBytes(base64) {
|
||||
const binary = atob(String(base64 || ''));
|
||||
const bytes = new Uint8Array(binary.length);
|
||||
for (let index = 0; index < binary.length; index++) bytes[index] = binary.charCodeAt(index);
|
||||
return bytes;
|
||||
}
|
||||
|
||||
export function registerOcrProvider(next) {
|
||||
if (next == null) {
|
||||
provider = null;
|
||||
return;
|
||||
}
|
||||
if (
|
||||
typeof next !== 'object'
|
||||
|| typeof next.id !== 'string'
|
||||
|| typeof next.isAvailable !== 'function'
|
||||
|| typeof next.recognize !== 'function'
|
||||
) {
|
||||
throw new Error('OCR 提供器接口无效');
|
||||
}
|
||||
provider = next;
|
||||
}
|
||||
|
||||
export function ocrAvailability() {
|
||||
if (!provider) return { available: false, providerId: null };
|
||||
let available = false;
|
||||
try { available = provider.isAvailable() === true; } catch (error) { available = false; }
|
||||
return { available, providerId: available ? provider.id : null };
|
||||
}
|
||||
|
||||
export async function recognizeOcr(image, options = {}) {
|
||||
const availability = ocrAvailability();
|
||||
if (!availability.available) throw new Error('尚未安装 OCR 引擎');
|
||||
const result = await provider.recognize({
|
||||
bytes: imageBytes(image.base64),
|
||||
mimeType: image.mimeType,
|
||||
width: image.width,
|
||||
height: image.height,
|
||||
languageHints: Array.isArray(options.languageHints) ? options.languageHints.slice(0, 4) : [],
|
||||
signal: options.signal
|
||||
});
|
||||
const text = String(result && result.text || '').slice(0, MAX_OCR_CHARS);
|
||||
return {
|
||||
text,
|
||||
engine: availability.providerId,
|
||||
language: result && result.language ? String(result.language) : null,
|
||||
confidence: Number.isFinite(Number(result && result.confidence))
|
||||
? Math.max(0, Math.min(1, Number(result.confidence)))
|
||||
: null
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,404 @@
|
||||
import {
|
||||
Canvas, FabricObject, PencilBrush, Rect, IText, version as fabricVersion
|
||||
} from '../vendor/fabric.min.mjs';
|
||||
|
||||
const HISTORY_LIMIT = 50;
|
||||
const SERIAL_PROPS = ['annotationKind'];
|
||||
const TYPE_BY_KIND = {
|
||||
rectangle: 'Rect',
|
||||
pen: 'Path',
|
||||
highlight: 'Path',
|
||||
text: 'IText'
|
||||
};
|
||||
FabricObject.customProperties = SERIAL_PROPS;
|
||||
|
||||
function pageData(canvas) {
|
||||
const json = canvas.toObject(SERIAL_PROPS);
|
||||
return { version: fabricVersion, objects: Array.isArray(json.objects) ? json.objects : [] };
|
||||
}
|
||||
|
||||
function rgba(hex, alpha) {
|
||||
const value = String(hex || '#ff4d4f').replace('#', '');
|
||||
const full = value.length === 3 ? value.split('').map((x) => x + x).join('') : value;
|
||||
if (!/^[0-9a-f]{6}$/i.test(full)) return `rgba(255,77,79,${alpha})`;
|
||||
const n = parseInt(full, 16);
|
||||
return `rgba(${n >> 16},${(n >> 8) & 255},${n & 255},${alpha})`;
|
||||
}
|
||||
|
||||
export function createAnnotationLayer(options) {
|
||||
const {
|
||||
host, page, width, height, scale, initial,
|
||||
history: initialHistory,
|
||||
tool: initialTool, style: initialStyle, onChange, onState
|
||||
} = options;
|
||||
|
||||
const element = document.createElement('canvas');
|
||||
host.textContent = '';
|
||||
host.appendChild(element);
|
||||
|
||||
const canvas = new Canvas(element, {
|
||||
width: Math.max(1, Math.round(width * scale)),
|
||||
height: Math.max(1, Math.round(height * scale)),
|
||||
selection: false,
|
||||
preserveObjectStacking: true,
|
||||
enableRetinaScaling: true
|
||||
});
|
||||
canvas.setViewportTransform([scale, 0, 0, scale, 0, 0]);
|
||||
|
||||
let tool = initialTool || 'text-select';
|
||||
let style = { color: '#ff4d4f', width: 3, ...(initialStyle || {}) };
|
||||
let draft = null;
|
||||
let destroyed = false;
|
||||
let restoring = true;
|
||||
let history = [];
|
||||
let historyIndex = -1;
|
||||
let textTimer = 0;
|
||||
let touchSuspended = false;
|
||||
let touchBaselineIndex = -1;
|
||||
|
||||
function state() {
|
||||
const count = canvas.getObjects().length;
|
||||
return {
|
||||
page,
|
||||
count,
|
||||
canUndo: historyIndex > 0,
|
||||
canRedo: historyIndex >= 0 && historyIndex < history.length - 1
|
||||
};
|
||||
}
|
||||
|
||||
function emitState() {
|
||||
if (!destroyed && onState) onState(state());
|
||||
}
|
||||
|
||||
function serialized() {
|
||||
return JSON.stringify(pageData(canvas));
|
||||
}
|
||||
|
||||
function pushHistory(emit = true) {
|
||||
if (destroyed || restoring) return;
|
||||
const value = serialized();
|
||||
if (history[historyIndex] !== value) {
|
||||
history = history.slice(0, historyIndex + 1);
|
||||
history.push(value);
|
||||
if (history.length > HISTORY_LIMIT) history.shift();
|
||||
historyIndex = history.length - 1;
|
||||
}
|
||||
if (emit && onChange) onChange(page, JSON.parse(value));
|
||||
emitState();
|
||||
}
|
||||
|
||||
function brushStyle() {
|
||||
if (!canvas.freeDrawingBrush) canvas.freeDrawingBrush = new PencilBrush(canvas);
|
||||
canvas.freeDrawingBrush.width = tool === 'highlight'
|
||||
? Math.max(8, Number(style.width) * 4)
|
||||
: Math.max(1, Number(style.width));
|
||||
canvas.freeDrawingBrush.color = tool === 'highlight'
|
||||
? rgba(style.color, 0.28)
|
||||
: style.color;
|
||||
}
|
||||
|
||||
function applyMode() {
|
||||
if (destroyed) return;
|
||||
const passive = tool === 'pan' || tool === 'text-select';
|
||||
const select = tool === 'select';
|
||||
const draw = tool === 'pen' || tool === 'highlight';
|
||||
host.style.pointerEvents = passive ? 'none' : 'auto';
|
||||
canvas.isDrawingMode = draw;
|
||||
canvas.selection = select;
|
||||
canvas.defaultCursor = select ? 'default' : (passive ? 'default' : 'crosshair');
|
||||
canvas.hoverCursor = tool === 'eraser' ? 'not-allowed' : (select ? 'move' : 'crosshair');
|
||||
for (const object of canvas.getObjects()) {
|
||||
object.selectable = select;
|
||||
object.evented = select || tool === 'eraser';
|
||||
}
|
||||
if (!select) canvas.discardActiveObject();
|
||||
if (draw) brushStyle();
|
||||
canvas.requestRenderAll();
|
||||
}
|
||||
|
||||
function pointer(event) {
|
||||
return canvas.getScenePoint(event);
|
||||
}
|
||||
|
||||
function startRectangle(event) {
|
||||
const point = pointer(event);
|
||||
const object = new Rect({
|
||||
left: point.x,
|
||||
top: point.y,
|
||||
originX: 'left',
|
||||
originY: 'top',
|
||||
width: 1,
|
||||
height: 1,
|
||||
fill: 'rgba(0,0,0,0)',
|
||||
stroke: style.color,
|
||||
strokeWidth: Math.max(1, Number(style.width)),
|
||||
selectable: false,
|
||||
evented: false,
|
||||
objectCaching: false,
|
||||
annotationKind: 'rectangle'
|
||||
});
|
||||
draft = { start: point, object };
|
||||
canvas.add(object);
|
||||
}
|
||||
|
||||
function resizeRectangle(event) {
|
||||
if (!draft) return;
|
||||
const point = pointer(event);
|
||||
const left = Math.min(draft.start.x, point.x);
|
||||
const top = Math.min(draft.start.y, point.y);
|
||||
draft.object.set({
|
||||
left,
|
||||
top,
|
||||
width: Math.abs(point.x - draft.start.x),
|
||||
height: Math.abs(point.y - draft.start.y)
|
||||
});
|
||||
draft.object.setCoords();
|
||||
canvas.requestRenderAll();
|
||||
}
|
||||
|
||||
function finishRectangle() {
|
||||
if (!draft) return;
|
||||
const object = draft.object;
|
||||
draft = null;
|
||||
if (object.width < 2 || object.height < 2) {
|
||||
canvas.remove(object);
|
||||
return;
|
||||
}
|
||||
pushHistory();
|
||||
}
|
||||
|
||||
function addText(event) {
|
||||
const point = pointer(event);
|
||||
const object = new IText('输入文字', {
|
||||
left: point.x,
|
||||
top: point.y,
|
||||
originX: 'left',
|
||||
originY: 'top',
|
||||
fill: style.color,
|
||||
fontFamily: 'Microsoft YaHei, sans-serif',
|
||||
fontSize: 16,
|
||||
selectable: true,
|
||||
evented: true,
|
||||
annotationKind: 'text'
|
||||
});
|
||||
canvas.add(object);
|
||||
canvas.setActiveObject(object);
|
||||
object.enterEditing();
|
||||
object.selectAll();
|
||||
canvas.requestRenderAll();
|
||||
pushHistory();
|
||||
}
|
||||
|
||||
function erase(target) {
|
||||
if (!target) return;
|
||||
canvas.remove(target);
|
||||
pushHistory();
|
||||
}
|
||||
|
||||
canvas.on('mouse:down', (event) => {
|
||||
if (restoring || destroyed) return;
|
||||
if (event.e && event.e.touches && event.e.touches.length === 1) {
|
||||
touchBaselineIndex = historyIndex;
|
||||
}
|
||||
if (tool === 'rectangle' && !event.target) startRectangle(event.e);
|
||||
else if (tool === 'text' && !event.target) addText(event.e);
|
||||
else if (tool === 'eraser') erase(event.target);
|
||||
});
|
||||
canvas.on('mouse:move', (event) => {
|
||||
if (tool === 'rectangle') resizeRectangle(event.e);
|
||||
});
|
||||
canvas.on('mouse:up', () => {
|
||||
if (tool === 'rectangle') finishRectangle();
|
||||
touchBaselineIndex = -1;
|
||||
});
|
||||
canvas.on('path:created', (event) => {
|
||||
if (!event.path) return;
|
||||
event.path.set({
|
||||
annotationKind: tool === 'highlight' ? 'highlight' : 'pen',
|
||||
selectable: false,
|
||||
evented: false
|
||||
});
|
||||
pushHistory();
|
||||
});
|
||||
canvas.on('object:modified', () => pushHistory());
|
||||
canvas.on('text:changed', () => {
|
||||
if (textTimer) clearTimeout(textTimer);
|
||||
textTimer = setTimeout(() => {
|
||||
textTimer = 0;
|
||||
pushHistory();
|
||||
}, 300);
|
||||
});
|
||||
canvas.on('text:editing:exited', () => {
|
||||
if (textTimer) {
|
||||
clearTimeout(textTimer);
|
||||
textTimer = 0;
|
||||
}
|
||||
pushHistory();
|
||||
});
|
||||
|
||||
async function restore(value, recordHistory) {
|
||||
restoring = true;
|
||||
canvas.discardActiveObject();
|
||||
const objects = value && Array.isArray(value.objects)
|
||||
? value.objects.filter((object) => {
|
||||
return object && TYPE_BY_KIND[object.annotationKind] === object.type && !object.clipPath;
|
||||
})
|
||||
: [];
|
||||
try {
|
||||
await canvas.loadFromJSON({ objects });
|
||||
} catch (e) {
|
||||
canvas.clear();
|
||||
} finally {
|
||||
restoring = false;
|
||||
}
|
||||
applyMode();
|
||||
canvas.requestRenderAll();
|
||||
if (recordHistory) {
|
||||
history = [serialized()];
|
||||
historyIndex = 0;
|
||||
}
|
||||
emitState();
|
||||
}
|
||||
|
||||
async function suspendTouchGesture() {
|
||||
if (destroyed || touchSuspended) return;
|
||||
touchSuspended = true;
|
||||
if (textTimer) {
|
||||
clearTimeout(textTimer);
|
||||
textTimer = 0;
|
||||
}
|
||||
draft = null;
|
||||
canvas._isCurrentlyDrawing = false;
|
||||
canvas.isDrawingMode = false;
|
||||
host.style.pointerEvents = 'none';
|
||||
const restoreIndex = touchBaselineIndex >= 0 ? touchBaselineIndex : historyIndex;
|
||||
const snapshot = history[restoreIndex] || '{"objects":[]}';
|
||||
if (restoreIndex >= 0 && restoreIndex < history.length) {
|
||||
history = history.slice(0, restoreIndex + 1);
|
||||
historyIndex = restoreIndex;
|
||||
}
|
||||
touchBaselineIndex = -1;
|
||||
await restore(JSON.parse(snapshot), false);
|
||||
canvas.isDrawingMode = false;
|
||||
host.style.pointerEvents = 'none';
|
||||
}
|
||||
|
||||
function resumeTouchGesture() {
|
||||
if (destroyed || !touchSuspended) return;
|
||||
touchSuspended = false;
|
||||
touchBaselineIndex = -1;
|
||||
applyMode();
|
||||
}
|
||||
|
||||
function flushPending() {
|
||||
if (destroyed) return;
|
||||
if (textTimer) {
|
||||
clearTimeout(textTimer);
|
||||
textTimer = 0;
|
||||
pushHistory();
|
||||
}
|
||||
}
|
||||
|
||||
const ready = restore(initial, true).then(() => {
|
||||
const snapshots = initialHistory && Array.isArray(initialHistory.snapshots)
|
||||
? initialHistory.snapshots.filter((value) => typeof value === 'string')
|
||||
: [];
|
||||
const index = initialHistory && Number(initialHistory.index);
|
||||
if (
|
||||
snapshots.length
|
||||
&& Number.isInteger(index)
|
||||
&& index >= 0
|
||||
&& index < snapshots.length
|
||||
&& snapshots[index] === serialized()
|
||||
) {
|
||||
history = snapshots.slice(-HISTORY_LIMIT);
|
||||
historyIndex = Math.min(history.length - 1, index - Math.max(0, snapshots.length - HISTORY_LIMIT));
|
||||
emitState();
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
ready,
|
||||
setTool(next) {
|
||||
tool = next || 'text-select';
|
||||
applyMode();
|
||||
},
|
||||
setStyle(next, applySelection = false) {
|
||||
style = { ...style, ...(next || {}) };
|
||||
if (canvas.isDrawingMode) brushStyle();
|
||||
if (!applySelection) return;
|
||||
const active = canvas.getActiveObjects();
|
||||
if (!active.length) return;
|
||||
for (const object of active) {
|
||||
const kind = object.annotationKind;
|
||||
if (kind === 'text') object.set({ fill: style.color });
|
||||
else if (kind === 'highlight') {
|
||||
object.set({ stroke: rgba(style.color, 0.28), strokeWidth: Math.max(8, Number(style.width) * 4) });
|
||||
} else {
|
||||
object.set({ stroke: style.color, strokeWidth: Math.max(1, Number(style.width)) });
|
||||
}
|
||||
object.setCoords();
|
||||
}
|
||||
canvas.requestRenderAll();
|
||||
pushHistory();
|
||||
},
|
||||
async undo() {
|
||||
if (historyIndex <= 0) return false;
|
||||
historyIndex -= 1;
|
||||
await restore(JSON.parse(history[historyIndex]), false);
|
||||
if (onChange) onChange(page, pageData(canvas));
|
||||
emitState();
|
||||
return true;
|
||||
},
|
||||
async redo() {
|
||||
if (historyIndex < 0 || historyIndex >= history.length - 1) return false;
|
||||
historyIndex += 1;
|
||||
await restore(JSON.parse(history[historyIndex]), false);
|
||||
if (onChange) onChange(page, pageData(canvas));
|
||||
emitState();
|
||||
return true;
|
||||
},
|
||||
clear() {
|
||||
if (!canvas.getObjects().length) return false;
|
||||
canvas.clear();
|
||||
applyMode();
|
||||
pushHistory();
|
||||
return true;
|
||||
},
|
||||
deleteSelected() {
|
||||
const active = canvas.getActiveObjects();
|
||||
if (!active.length) return false;
|
||||
if (active.some((object) => object.isEditing)) return false;
|
||||
for (const object of active) canvas.remove(object);
|
||||
canvas.discardActiveObject();
|
||||
pushHistory();
|
||||
return true;
|
||||
},
|
||||
serialize() {
|
||||
return pageData(canvas);
|
||||
},
|
||||
snapshot() {
|
||||
canvas.requestRenderAll();
|
||||
return element;
|
||||
},
|
||||
historyState() {
|
||||
return { snapshots: history.slice(), index: historyIndex };
|
||||
},
|
||||
state,
|
||||
suspendTouchGesture,
|
||||
resumeTouchGesture,
|
||||
flushPending,
|
||||
destroy() {
|
||||
if (destroyed) return;
|
||||
if (textTimer) {
|
||||
clearTimeout(textTimer);
|
||||
textTimer = 0;
|
||||
pushHistory();
|
||||
}
|
||||
destroyed = true;
|
||||
try { canvas.dispose(); } catch (e) { /* ignore */ }
|
||||
host.textContent = '';
|
||||
host.style.pointerEvents = 'none';
|
||||
}
|
||||
};
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,132 @@
|
||||
export const VISUAL_CONTEXT_VERSION = 1;
|
||||
export const MAX_CAPTURE_DIMENSION = 1600;
|
||||
export const MAX_CAPTURE_BYTES = 3 * 1024 * 1024;
|
||||
// 视觉模型多按图块计费,超过这个体积再提高清晰度基本换不来识别率,
|
||||
// 所以先按目标体积压,压不到再退回硬上限。
|
||||
export const TARGET_CAPTURE_BYTES = 400 * 1024;
|
||||
|
||||
function base64Bytes(value) {
|
||||
const text = String(value || '');
|
||||
const padding = text.endsWith('==') ? 2 : (text.endsWith('=') ? 1 : 0);
|
||||
return Math.max(0, Math.floor(text.length * 3 / 4) - padding);
|
||||
}
|
||||
|
||||
function scaledCanvas(source, ratio) {
|
||||
if (ratio >= 0.999) return source;
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = Math.max(1, Math.round(source.width * ratio));
|
||||
canvas.height = Math.max(1, Math.round(source.height * ratio));
|
||||
const context = canvas.getContext('2d', { alpha: false });
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, 0, canvas.width, canvas.height);
|
||||
context.drawImage(source, 0, 0, canvas.width, canvas.height);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
export function normalizeCrop(crop, width, height) {
|
||||
const pageWidth = Math.max(1, Number(width) || 1);
|
||||
const pageHeight = Math.max(1, Number(height) || 1);
|
||||
const raw = crop && typeof crop === 'object'
|
||||
? crop
|
||||
: { x: 0, y: 0, width: pageWidth, height: pageHeight };
|
||||
const x = Math.max(0, Math.min(pageWidth - 1, Number(raw.x) || 0));
|
||||
const y = Math.max(0, Math.min(pageHeight - 1, Number(raw.y) || 0));
|
||||
const w = Math.max(1, Math.min(pageWidth - x, Number(raw.width) || pageWidth));
|
||||
const h = Math.max(1, Math.min(pageHeight - y, Number(raw.height) || pageHeight));
|
||||
return { x, y, width: w, height: h };
|
||||
}
|
||||
|
||||
export function cropCanvas(source, crop) {
|
||||
const area = normalizeCrop(crop, source.width, source.height);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = Math.max(1, Math.round(area.width));
|
||||
canvas.height = Math.max(1, Math.round(area.height));
|
||||
const context = canvas.getContext('2d', { alpha: false });
|
||||
context.fillStyle = '#ffffff';
|
||||
context.fillRect(0, 0, canvas.width, canvas.height);
|
||||
context.drawImage(
|
||||
source,
|
||||
area.x, area.y, area.width, area.height,
|
||||
0, 0, canvas.width, canvas.height
|
||||
);
|
||||
return canvas;
|
||||
}
|
||||
|
||||
export function canvasToImage(source) {
|
||||
if (!source || !source.width || !source.height) throw new Error('没有可用的页面图像');
|
||||
const longest = Math.max(source.width, source.height);
|
||||
let canvas = scaledCanvas(source, Math.min(1, MAX_CAPTURE_DIMENSION / longest));
|
||||
const qualities = [0.82, 0.74, 0.66, 0.58];
|
||||
let fallback = null;
|
||||
for (let attempt = 0; attempt < 5; attempt++) {
|
||||
for (const quality of qualities) {
|
||||
const dataUrl = canvas.toDataURL('image/jpeg', quality);
|
||||
const base64 = dataUrl.slice(dataUrl.indexOf(',') + 1);
|
||||
const bytes = base64Bytes(base64);
|
||||
const image = {
|
||||
mimeType: 'image/jpeg',
|
||||
base64,
|
||||
width: canvas.width,
|
||||
height: canvas.height,
|
||||
bytes
|
||||
};
|
||||
if (bytes <= TARGET_CAPTURE_BYTES) return image;
|
||||
if (bytes <= MAX_CAPTURE_BYTES && (!fallback || bytes < fallback.bytes)) fallback = image;
|
||||
}
|
||||
// 文字页缩得太狠会糊,缩到 800px 就停手,改用已经达标的兜底结果
|
||||
if (Math.max(canvas.width, canvas.height) <= 800) break;
|
||||
canvas = scaledCanvas(canvas, 0.78);
|
||||
}
|
||||
if (fallback) return fallback;
|
||||
throw new Error('页面图像过大,无法安全发送');
|
||||
}
|
||||
|
||||
export function createVisualContext({ kind, format, source, locator, crop, image }) {
|
||||
if (!image || !image.base64) throw new Error('缺少图像数据');
|
||||
return {
|
||||
version: VISUAL_CONTEXT_VERSION,
|
||||
id: `visual_${Date.now().toString(36)}_${Math.random().toString(36).slice(2, 8)}`,
|
||||
kind: kind === 'region' ? 'region' : 'page',
|
||||
format: String(format || ''),
|
||||
source: source && typeof source === 'object' ? { ...source } : {},
|
||||
locator: locator && typeof locator === 'object' ? { ...locator } : null,
|
||||
crop: crop && typeof crop === 'object' ? { ...crop } : null,
|
||||
image: { ...image },
|
||||
includeImage: true,
|
||||
ocr: {
|
||||
status: 'idle',
|
||||
text: '',
|
||||
include: false,
|
||||
engine: null,
|
||||
error: null
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function withOcrResult(context, result) {
|
||||
const text = String(result && result.text || '').slice(0, 12000);
|
||||
return {
|
||||
...context,
|
||||
ocr: {
|
||||
status: text.trim() ? 'ready' : 'error',
|
||||
text,
|
||||
include: !!text.trim(),
|
||||
engine: String(result && result.engine || '') || null,
|
||||
error: text.trim() ? null : String(result && result.error || '未识别到文字')
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function toAiVisualContext(context) {
|
||||
if (!context || (!context.includeImage && !context.ocr.include)) return null;
|
||||
return {
|
||||
kind: context.kind,
|
||||
includeImage: !!context.includeImage,
|
||||
image: context.includeImage ? { ...context.image } : null,
|
||||
ocr: {
|
||||
status: context.ocr.status,
|
||||
text: context.ocr.text,
|
||||
include: context.ocr.include
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,501 @@
|
||||
.quill-note-editor {
|
||||
overflow: visible;
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 9px;
|
||||
}
|
||||
|
||||
.quill-note-editor:focus-within { border-color: var(--accent); }
|
||||
|
||||
.quill-note-editor .rich-note-toolbar.ql-toolbar.ql-snow {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
flex-wrap: nowrap;
|
||||
gap: 4px;
|
||||
min-height: 42px;
|
||||
padding: 6px;
|
||||
overflow: visible;
|
||||
background: var(--bg-soft);
|
||||
border: 0;
|
||||
border-bottom: 1px solid var(--line);
|
||||
border-radius: 8px 8px 0 0;
|
||||
color: var(--text);
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-formats {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
gap: 2px;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-picker.ql-header {
|
||||
width: 102px;
|
||||
color: var(--text);
|
||||
}
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-label::before,
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-item::before { content: "正文"; }
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {
|
||||
content: "一级标题";
|
||||
}
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
|
||||
.quill-note-editor .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {
|
||||
content: "二级标题";
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-picker-label {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-picker-label:hover,
|
||||
.quill-note-editor .ql-toolbar .ql-picker-label.ql-active {
|
||||
border-color: var(--accent);
|
||||
color: var(--accent-bright);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-picker-options {
|
||||
z-index: 20;
|
||||
max-height: 210px;
|
||||
overflow-y: auto;
|
||||
background: var(--bg-card);
|
||||
border-color: var(--line);
|
||||
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar .ql-picker-item:hover,
|
||||
.quill-note-editor .ql-toolbar .ql-picker-item.ql-selected {
|
||||
color: var(--accent-bright);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar button {
|
||||
float: none;
|
||||
border-radius: 5px;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-toolbar button:hover,
|
||||
.quill-note-editor .ql-toolbar button:focus-visible,
|
||||
.quill-note-editor .ql-toolbar button.ql-active {
|
||||
background: var(--hover-bg);
|
||||
color: var(--accent-bright);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-snow .ql-stroke { stroke: var(--text-dim); }
|
||||
.quill-note-editor .ql-snow .ql-fill { fill: var(--text-dim); }
|
||||
.quill-note-editor .ql-snow .ql-picker-label:hover .ql-stroke,
|
||||
.quill-note-editor .ql-snow button:hover .ql-stroke,
|
||||
.quill-note-editor .ql-snow button:focus-visible .ql-stroke,
|
||||
.quill-note-editor .ql-snow button.ql-active .ql-stroke {
|
||||
stroke: var(--accent-bright);
|
||||
}
|
||||
.quill-note-editor .ql-snow button:hover .ql-fill,
|
||||
.quill-note-editor .ql-snow button:focus-visible .ql-fill,
|
||||
.quill-note-editor .ql-snow button.ql-active .ql-fill {
|
||||
fill: var(--accent-bright);
|
||||
}
|
||||
|
||||
.quill-note-editor .rich-note-history {
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.quill-note-editor .rich-note-undo,
|
||||
.quill-note-editor .rich-note-redo {
|
||||
font-size: 18px;
|
||||
line-height: 20px;
|
||||
}
|
||||
|
||||
.quill-note-editor .rich-note-quill.ql-container.ql-snow {
|
||||
overflow: hidden;
|
||||
background: var(--input-bg);
|
||||
border: 0;
|
||||
border-radius: 0 0 8px 8px;
|
||||
color: var(--text);
|
||||
font-family: inherit;
|
||||
font-size: 13px;
|
||||
}
|
||||
|
||||
.quill-note-editor .rich-note-surface.ql-editor {
|
||||
min-height: 220px;
|
||||
max-height: 48vh;
|
||||
padding: 12px 14px;
|
||||
overflow-y: auto;
|
||||
color: var(--text);
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-editor.ql-blank::before {
|
||||
color: var(--text-dim);
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-editor blockquote {
|
||||
border-color: var(--accent);
|
||||
color: var(--text-dim);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-editor pre.ql-syntax {
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.quill-note-editor .ql-editor img {
|
||||
max-width: 100%;
|
||||
max-height: 520px;
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.mixed-note-editor {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex-direction: column;
|
||||
gap: 7px;
|
||||
}
|
||||
|
||||
.mixed-note-modes {
|
||||
display: inline-flex;
|
||||
align-self: flex-start;
|
||||
padding: 3px;
|
||||
background: var(--bg-soft);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.mixed-note-mode {
|
||||
height: 28px;
|
||||
padding: 0 14px;
|
||||
background: transparent;
|
||||
border: 0;
|
||||
border-radius: 6px;
|
||||
color: var(--text-dim);
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
}
|
||||
|
||||
.mixed-note-mode:hover { color: var(--text); }
|
||||
.mixed-note-mode.active {
|
||||
background: var(--accent);
|
||||
color: var(--on-accent, #fff);
|
||||
}
|
||||
|
||||
.mixed-note-canvas { min-height: 360px; }
|
||||
.mixed-note-editor.note-editor-canvas {
|
||||
height: 100%;
|
||||
}
|
||||
.note-editor-canvas .mixed-note-canvas {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.note-canvas-summary,
|
||||
.list-item-canvas-summary {
|
||||
width: fit-content;
|
||||
margin-top: 7px;
|
||||
padding: 4px 8px;
|
||||
background: var(--hover-bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 999px;
|
||||
color: var(--text-dim);
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.canvas-note-root {
|
||||
display: flex;
|
||||
min-height: 0;
|
||||
flex: 1;
|
||||
flex-direction: column;
|
||||
overflow: hidden;
|
||||
background: var(--input-bg);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 9px;
|
||||
}
|
||||
|
||||
.canvas-note-toolbar {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
align-content: flex-start;
|
||||
flex: 0 0 auto;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
min-height: 42px;
|
||||
padding: 6px;
|
||||
overflow: visible;
|
||||
background: var(--bg-soft);
|
||||
border-bottom: 1px solid var(--line);
|
||||
white-space: normal;
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar-host {
|
||||
flex: 0 0 auto;
|
||||
background: var(--bg-soft);
|
||||
border-bottom: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar.ql-toolbar.ql-snow {
|
||||
display: flex;
|
||||
min-height: 38px;
|
||||
padding: 5px 8px;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
overflow: visible;
|
||||
border: 0;
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar .ql-formats {
|
||||
display: inline-flex;
|
||||
margin: 0;
|
||||
align-items: center;
|
||||
flex-wrap: wrap;
|
||||
gap: 2px;
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar .ql-picker.ql-header {
|
||||
width: 102px;
|
||||
color: var(--text);
|
||||
}
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-label::before,
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-item::before { content: "正文"; }
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-label[data-value="1"]::before,
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-item[data-value="1"]::before {
|
||||
content: "一级标题";
|
||||
}
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-label[data-value="2"]::before,
|
||||
.canvas-flow-toolbar .ql-picker.ql-header .ql-picker-item[data-value="2"]::before {
|
||||
content: "二级标题";
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar .ql-picker-label {
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar button {
|
||||
float: none;
|
||||
border-radius: 5px;
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar button:hover,
|
||||
.canvas-flow-toolbar button:focus-visible,
|
||||
.canvas-flow-toolbar button.ql-active,
|
||||
.canvas-flow-toolbar .ql-picker-label:hover,
|
||||
.canvas-flow-toolbar .ql-picker-label.ql-active {
|
||||
background: var(--hover-bg);
|
||||
color: var(--accent-bright);
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar .ql-picker-options {
|
||||
z-index: 30;
|
||||
max-height: 210px;
|
||||
overflow-y: auto;
|
||||
background: var(--bg-card);
|
||||
border-color: var(--line);
|
||||
color: var(--text);
|
||||
}
|
||||
|
||||
.canvas-flow-toolbar .ql-stroke { stroke: var(--text-dim); }
|
||||
.canvas-flow-toolbar .ql-fill { fill: var(--text-dim); }
|
||||
.canvas-flow-toolbar button:hover .ql-stroke,
|
||||
.canvas-flow-toolbar button.ql-active .ql-stroke { stroke: var(--accent-bright); }
|
||||
.canvas-flow-toolbar button:hover .ql-fill,
|
||||
.canvas-flow-toolbar button.ql-active .ql-fill { fill: var(--accent-bright); }
|
||||
|
||||
.canvas-note-tool-group {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
max-width: 100%;
|
||||
padding-right: 5px;
|
||||
flex-wrap: wrap;
|
||||
gap: 4px;
|
||||
border-right: 1px solid var(--line);
|
||||
}
|
||||
|
||||
.canvas-note-tool-group:last-of-type {
|
||||
padding-right: 0;
|
||||
border-right: 0;
|
||||
}
|
||||
|
||||
.canvas-note-button,
|
||||
.canvas-note-toolbar select,
|
||||
.canvas-note-color {
|
||||
flex-shrink: 0;
|
||||
height: 28px;
|
||||
background: var(--bg-card);
|
||||
border: 1px solid var(--line);
|
||||
border-radius: 6px;
|
||||
color: var(--text);
|
||||
cursor: pointer;
|
||||
font: inherit;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.canvas-note-button {
|
||||
display: inline-flex;
|
||||
width: 30px;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 0;
|
||||
color: var(--text-dim);
|
||||
}
|
||||
.canvas-note-icon {
|
||||
width: 16px;
|
||||
height: 16px;
|
||||
flex: none;
|
||||
fill: none;
|
||||
stroke: currentColor;
|
||||
stroke-width: 1.8;
|
||||
stroke-linecap: round;
|
||||
stroke-linejoin: round;
|
||||
pointer-events: none;
|
||||
}
|
||||
.canvas-note-toolbar select { padding: 0 5px; }
|
||||
.canvas-note-color { width: 34px; padding: 2px; }
|
||||
.canvas-note-button:hover,
|
||||
.canvas-note-button.canvas-note-active,
|
||||
.canvas-note-toolbar select:hover {
|
||||
border-color: var(--accent);
|
||||
color: var(--accent-bright);
|
||||
}
|
||||
.canvas-note-button.canvas-note-active { background: var(--hover-bg); }
|
||||
.canvas-note-button.canvas-note-delete-confirm {
|
||||
background: var(--danger);
|
||||
border-color: var(--danger);
|
||||
color: #fff;
|
||||
}
|
||||
.canvas-note-button:disabled,
|
||||
.canvas-note-toolbar select:disabled { opacity: 0.45; cursor: not-allowed; }
|
||||
|
||||
.canvas-note-page-controls {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
flex-shrink: 0;
|
||||
gap: 4px;
|
||||
margin-left: auto;
|
||||
}
|
||||
|
||||
.canvas-note-page-counter {
|
||||
min-width: 46px;
|
||||
color: var(--text-dim);
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.canvas-note-viewport {
|
||||
min-height: 0;
|
||||
padding: 18px;
|
||||
flex: 1 1 0;
|
||||
overflow: auto;
|
||||
overscroll-behavior: contain;
|
||||
scrollbar-gutter: stable;
|
||||
background: var(--bg);
|
||||
outline: none;
|
||||
}
|
||||
|
||||
.canvas-note-page {
|
||||
position: relative;
|
||||
margin: 0 auto;
|
||||
flex-shrink: 0;
|
||||
overflow: hidden;
|
||||
background: #fff;
|
||||
box-shadow: 0 3px 18px rgba(0, 0, 0, 0.3);
|
||||
}
|
||||
|
||||
.canvas-note-background {
|
||||
z-index: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.canvas-note-fabric-container {
|
||||
z-index: 2;
|
||||
}
|
||||
|
||||
.canvas-note-fabric-container canvas {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.canvas-flow-layer {
|
||||
position: absolute;
|
||||
z-index: 1;
|
||||
top: 72px;
|
||||
left: 50%;
|
||||
overflow: hidden;
|
||||
color: #111827;
|
||||
transform: translateX(-50%);
|
||||
pointer-events: none;
|
||||
}
|
||||
|
||||
.canvas-flow-layer.canvas-flow-active {
|
||||
cursor: text;
|
||||
outline: 1px dashed rgba(57, 123, 211, 0.55);
|
||||
outline-offset: 4px;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.canvas-flow-quill.ql-container.ql-snow {
|
||||
overflow: hidden;
|
||||
border: 0;
|
||||
color: #111827;
|
||||
font-family: "Microsoft YaHei", "PingFang SC", "Segoe UI", sans-serif;
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.canvas-flow-surface.ql-editor {
|
||||
min-height: 0;
|
||||
max-height: none;
|
||||
padding: 0;
|
||||
overflow: visible;
|
||||
column-fill: auto;
|
||||
color: #111827;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.canvas-flow-surface.ql-editor.ql-blank::before {
|
||||
right: 0;
|
||||
left: 0;
|
||||
color: #8792a2;
|
||||
font-style: normal;
|
||||
}
|
||||
|
||||
.canvas-flow-surface .canvas-flow-page-break {
|
||||
width: 100%;
|
||||
height: 1px;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
break-after: column;
|
||||
border: 0;
|
||||
}
|
||||
|
||||
.canvas-flow-surface blockquote {
|
||||
border-color: #397bd3;
|
||||
color: #526175;
|
||||
}
|
||||
|
||||
.canvas-flow-surface pre.ql-syntax {
|
||||
background: #eef2f7;
|
||||
color: #1f2937;
|
||||
}
|
||||
|
||||
@media (max-width: 720px) {
|
||||
.canvas-note-toolbar {
|
||||
align-items: flex-start;
|
||||
}
|
||||
|
||||
.canvas-note-page-controls {
|
||||
flex-basis: 100%;
|
||||
justify-content: flex-end;
|
||||
margin-left: 0;
|
||||
}
|
||||
|
||||
.canvas-note-viewport {
|
||||
padding: 10px;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,412 @@
|
||||
window.RichNote = (() => {
|
||||
const IMAGE_TYPES = new Set(['image/jpeg', 'image/png', 'image/gif', 'image/webp']);
|
||||
const IMAGE_MAX_BYTES = 2 * 1024 * 1024;
|
||||
|
||||
function safeImageUrl(value) {
|
||||
return /^data:image\/(?:jpeg|png|gif|webp);base64,[A-Za-z0-9+/]*={0,2}$/.test(
|
||||
String(value || '')
|
||||
);
|
||||
}
|
||||
|
||||
function imageFigure(block, editable) {
|
||||
if (!safeImageUrl(block && block.dataUrl)) return null;
|
||||
const figure = document.createElement('figure');
|
||||
figure.className = 'rich-note-image';
|
||||
figure.dataset.richImage = 'true';
|
||||
figure.dataset.dataUrl = block.dataUrl;
|
||||
figure.dataset.alt = String(block.alt || '');
|
||||
figure.contentEditable = 'false';
|
||||
const image = document.createElement('img');
|
||||
image.src = block.dataUrl;
|
||||
image.alt = String(block.alt || '');
|
||||
figure.appendChild(image);
|
||||
if (editable) {
|
||||
const remove = document.createElement('button');
|
||||
remove.type = 'button';
|
||||
remove.className = 'rich-note-image-remove';
|
||||
remove.title = '删除图片';
|
||||
remove.setAttribute('aria-label', '删除图片');
|
||||
remove.textContent = '×';
|
||||
remove.onclick = () => figure.remove();
|
||||
figure.appendChild(remove);
|
||||
}
|
||||
return figure;
|
||||
}
|
||||
|
||||
function legacyToDelta(value) {
|
||||
if (!value || !Array.isArray(value.blocks)) return value;
|
||||
const ops = [];
|
||||
value.blocks.forEach((block) => {
|
||||
if (block && block.type === 'image' && safeImageUrl(block.dataUrl)) {
|
||||
ops.push({ insert: { image: block.dataUrl } });
|
||||
return;
|
||||
}
|
||||
if (!block || block.type !== 'text' || !Array.isArray(block.runs)) return;
|
||||
block.runs.forEach((run) => {
|
||||
const insert = String(run && run.text || '');
|
||||
if (!insert) return;
|
||||
const attributes = {
|
||||
...(run.bold === true ? { bold: true } : {}),
|
||||
...(run.italic === true ? { italic: true } : {}),
|
||||
...(run.underline === true ? { underline: true } : {}),
|
||||
...(run.strike === true ? { strike: true } : {}),
|
||||
...(run.code === true ? { code: true } : {})
|
||||
};
|
||||
ops.push({
|
||||
insert,
|
||||
...(Object.keys(attributes).length ? { attributes } : {})
|
||||
});
|
||||
});
|
||||
const attributes = block.style === 'heading1'
|
||||
? { header: 1 }
|
||||
: block.style === 'heading2'
|
||||
? { header: 2 }
|
||||
: block.style === 'quote'
|
||||
? { blockquote: true }
|
||||
: block.style === 'bullet'
|
||||
? { list: 'bullet' }
|
||||
: block.style === 'number'
|
||||
? { list: 'ordered' }
|
||||
: block.style === 'code'
|
||||
? { 'code-block': 'plain' }
|
||||
: null;
|
||||
ops.push({ insert: '\n', ...(attributes ? { attributes } : {}) });
|
||||
});
|
||||
return { version: 2, ops };
|
||||
}
|
||||
|
||||
function clientDelta(value) {
|
||||
const source = legacyToDelta(value);
|
||||
if (!source || !Array.isArray(source.ops)) return null;
|
||||
const ops = [];
|
||||
source.ops.forEach((op) => {
|
||||
if (!op || !Object.prototype.hasOwnProperty.call(op, 'insert')) return;
|
||||
const attributes = {};
|
||||
const rawAttributes = op.attributes && typeof op.attributes === 'object'
|
||||
? op.attributes
|
||||
: {};
|
||||
['bold', 'italic', 'underline', 'strike', 'code', 'blockquote']
|
||||
.forEach((key) => {
|
||||
if (rawAttributes[key] === true) attributes[key] = true;
|
||||
});
|
||||
if (rawAttributes['code-block'] === true || rawAttributes['code-block'] === 'plain') {
|
||||
attributes['code-block'] = 'plain';
|
||||
}
|
||||
if (rawAttributes.header === 1 || rawAttributes.header === 2) {
|
||||
attributes.header = rawAttributes.header;
|
||||
}
|
||||
if (rawAttributes.list === 'bullet' || rawAttributes.list === 'ordered') {
|
||||
attributes.list = rawAttributes.list;
|
||||
}
|
||||
if (typeof op.insert === 'string') {
|
||||
if (op.insert) {
|
||||
ops.push({
|
||||
insert: op.insert,
|
||||
...(Object.keys(attributes).length ? { attributes } : {})
|
||||
});
|
||||
}
|
||||
} else if (op.insert && safeImageUrl(op.insert.image)) {
|
||||
ops.push({ insert: { image: op.insert.image } });
|
||||
}
|
||||
});
|
||||
return ops.length ? { version: 2, ops } : null;
|
||||
}
|
||||
|
||||
function plainText(content) {
|
||||
const delta = clientDelta(content);
|
||||
if (!delta) return '';
|
||||
return delta.ops
|
||||
.filter((op) => typeof op.insert === 'string')
|
||||
.map((op) => op.insert)
|
||||
.join('')
|
||||
.replace(/\n$/, '');
|
||||
}
|
||||
|
||||
function hasContent(content) {
|
||||
const delta = clientDelta(content);
|
||||
return !!(delta && delta.ops.some((op) => (
|
||||
typeof op.insert === 'string' ? op.insert.trim() : !!op.insert.image
|
||||
)));
|
||||
}
|
||||
|
||||
function fromText(value) {
|
||||
const text = String(value || '');
|
||||
if (!text) return null;
|
||||
return {
|
||||
version: 2,
|
||||
ops: [{ insert: text.endsWith('\n') ? text : `${text}\n` }]
|
||||
};
|
||||
}
|
||||
|
||||
function inlineText(value, attributes) {
|
||||
let node = document.createTextNode(value);
|
||||
[
|
||||
['code', 'code'],
|
||||
['strike', 's'],
|
||||
['underline', 'u'],
|
||||
['italic', 'em'],
|
||||
['bold', 'strong']
|
||||
].forEach(([field, tag]) => {
|
||||
if (attributes && attributes[field] === true) {
|
||||
const wrapper = document.createElement(tag);
|
||||
wrapper.appendChild(node);
|
||||
node = wrapper;
|
||||
}
|
||||
});
|
||||
return node;
|
||||
}
|
||||
|
||||
function renderDelta(target, content) {
|
||||
target.textContent = '';
|
||||
let line = document.createDocumentFragment();
|
||||
const finishLine = (attributes = {}) => {
|
||||
const tag = attributes.header === 1
|
||||
? 'h2'
|
||||
: attributes.header === 2
|
||||
? 'h3'
|
||||
: attributes.blockquote === true
|
||||
? 'blockquote'
|
||||
: attributes['code-block'] === 'plain'
|
||||
? 'pre'
|
||||
: attributes.list === 'bullet'
|
||||
? 'ul'
|
||||
: attributes.list === 'ordered'
|
||||
? 'ol'
|
||||
: 'p';
|
||||
const block = document.createElement(tag);
|
||||
const body = tag === 'ul' || tag === 'ol'
|
||||
? block.appendChild(document.createElement('li'))
|
||||
: block;
|
||||
if (line.childNodes.length) body.appendChild(line);
|
||||
else body.appendChild(document.createElement('br'));
|
||||
target.appendChild(block);
|
||||
line = document.createDocumentFragment();
|
||||
};
|
||||
content.ops.forEach((op) => {
|
||||
if (op.insert && typeof op.insert === 'object') {
|
||||
if (line.childNodes.length) finishLine();
|
||||
const figure = imageFigure({
|
||||
dataUrl: op.insert.image,
|
||||
alt: ''
|
||||
}, false);
|
||||
if (figure) target.appendChild(figure);
|
||||
return;
|
||||
}
|
||||
const parts = String(op.insert || '').split('\n');
|
||||
parts.forEach((part, index) => {
|
||||
if (part) line.appendChild(inlineText(part, op.attributes));
|
||||
if (index < parts.length - 1) finishLine(op.attributes || {});
|
||||
});
|
||||
});
|
||||
if (line.childNodes.length) finishLine();
|
||||
}
|
||||
|
||||
function render(target, content, fallbackText) {
|
||||
const delta = clientDelta(content);
|
||||
if (delta && hasContent(delta)) {
|
||||
target.classList.add('rich-note-content');
|
||||
renderDelta(target, delta);
|
||||
return;
|
||||
}
|
||||
target.classList.remove('rich-note-content');
|
||||
target.textContent = String(fallbackText || '');
|
||||
}
|
||||
|
||||
function readImage(file) {
|
||||
return new Promise((resolve, reject) => {
|
||||
if (!file || !IMAGE_TYPES.has(file.type)) {
|
||||
reject(new Error('仅支持 JPEG、PNG、GIF 和 WebP 图片'));
|
||||
return;
|
||||
}
|
||||
if (file.size <= 0 || file.size > IMAGE_MAX_BYTES) {
|
||||
reject(new Error('单张图片不能超过 2 MB'));
|
||||
return;
|
||||
}
|
||||
const reader = new FileReader();
|
||||
reader.onerror = () => reject(new Error('图片读取失败'));
|
||||
reader.onload = () => resolve({
|
||||
type: 'image',
|
||||
dataUrl: String(reader.result || ''),
|
||||
alt: String(file.name || '').slice(0, 500)
|
||||
});
|
||||
reader.readAsDataURL(file);
|
||||
});
|
||||
}
|
||||
|
||||
function mount(host, initialContent, options = {}) {
|
||||
host.textContent = '';
|
||||
if (typeof window.Quill !== 'function') {
|
||||
throw new Error('富文本编辑组件加载失败');
|
||||
}
|
||||
const box = document.createElement('div');
|
||||
box.className = 'rich-note-editor quill-note-editor';
|
||||
const toolbar = document.createElement('div');
|
||||
toolbar.className = 'rich-note-toolbar ql-toolbar ql-snow';
|
||||
toolbar.setAttribute('role', 'toolbar');
|
||||
toolbar.setAttribute('aria-label', '笔记格式工具栏');
|
||||
|
||||
const formats = document.createElement('span');
|
||||
formats.className = 'ql-formats';
|
||||
const header = document.createElement('select');
|
||||
header.className = 'ql-header';
|
||||
header.title = '段落样式';
|
||||
[
|
||||
['', '正文'],
|
||||
['1', '一级标题'],
|
||||
['2', '二级标题']
|
||||
].forEach(([value, label], index) => {
|
||||
const option = document.createElement('option');
|
||||
option.value = value;
|
||||
option.textContent = label;
|
||||
if (index === 0) option.selected = true;
|
||||
header.appendChild(option);
|
||||
});
|
||||
formats.appendChild(header);
|
||||
[
|
||||
['bold', '加粗'],
|
||||
['italic', '斜体'],
|
||||
['underline', '下划线'],
|
||||
['strike', '删除线'],
|
||||
['blockquote', '引用'],
|
||||
['code-block', '代码块']
|
||||
].forEach(([name, title]) => {
|
||||
const button = document.createElement('button');
|
||||
button.type = 'button';
|
||||
button.className = `ql-${name}`;
|
||||
button.title = title;
|
||||
button.setAttribute('aria-label', title);
|
||||
formats.appendChild(button);
|
||||
});
|
||||
const ordered = document.createElement('button');
|
||||
ordered.type = 'button';
|
||||
ordered.className = 'ql-list';
|
||||
ordered.value = 'ordered';
|
||||
ordered.title = '有序列表';
|
||||
ordered.setAttribute('aria-label', '有序列表');
|
||||
formats.appendChild(ordered);
|
||||
const bullet = document.createElement('button');
|
||||
bullet.type = 'button';
|
||||
bullet.className = 'ql-list';
|
||||
bullet.value = 'bullet';
|
||||
bullet.title = '无序列表';
|
||||
bullet.setAttribute('aria-label', '无序列表');
|
||||
formats.appendChild(bullet);
|
||||
const imageButton = document.createElement('button');
|
||||
imageButton.type = 'button';
|
||||
imageButton.className = 'ql-image';
|
||||
imageButton.title = '插入图片';
|
||||
imageButton.setAttribute('aria-label', '插入图片');
|
||||
formats.appendChild(imageButton);
|
||||
toolbar.appendChild(formats);
|
||||
|
||||
const fileInput = document.createElement('input');
|
||||
fileInput.type = 'file';
|
||||
fileInput.accept = 'image/jpeg,image/png,image/gif,image/webp';
|
||||
fileInput.multiple = true;
|
||||
fileInput.className = 'hidden';
|
||||
|
||||
const history = document.createElement('span');
|
||||
history.className = 'ql-formats rich-note-history';
|
||||
const undo = document.createElement('button');
|
||||
undo.type = 'button';
|
||||
undo.className = 'rich-note-undo';
|
||||
undo.title = '撤销';
|
||||
undo.setAttribute('aria-label', '撤销');
|
||||
undo.textContent = '↶';
|
||||
const redo = document.createElement('button');
|
||||
redo.type = 'button';
|
||||
redo.className = 'rich-note-redo';
|
||||
redo.title = '重做';
|
||||
redo.setAttribute('aria-label', '重做');
|
||||
redo.textContent = '↷';
|
||||
history.append(undo, redo);
|
||||
toolbar.append(history, fileInput);
|
||||
|
||||
const surface = document.createElement('div');
|
||||
surface.className = 'rich-note-quill';
|
||||
box.append(toolbar, surface);
|
||||
host.appendChild(box);
|
||||
|
||||
const quill = new window.Quill(surface, {
|
||||
theme: 'snow',
|
||||
placeholder: options.placeholder || '记录想法、摘要或研究结论',
|
||||
formats: [
|
||||
'header', 'bold', 'italic', 'underline', 'strike', 'blockquote',
|
||||
'code', 'code-block', 'list', 'image'
|
||||
],
|
||||
modules: {
|
||||
toolbar: {
|
||||
container: toolbar,
|
||||
handlers: {
|
||||
image() { fileInput.click(); }
|
||||
}
|
||||
},
|
||||
history: {
|
||||
delay: 700,
|
||||
maxStack: 100,
|
||||
userOnly: true
|
||||
}
|
||||
}
|
||||
});
|
||||
quill.root.classList.add('rich-note-surface');
|
||||
quill.root.setAttribute('aria-label', '笔记正文');
|
||||
quill.root.setAttribute('aria-multiline', 'true');
|
||||
undo.onclick = () => quill.history.undo();
|
||||
redo.onclick = () => quill.history.redo();
|
||||
|
||||
const insertFiles = async (files) => {
|
||||
for (const file of Array.from(files || [])) {
|
||||
if (!IMAGE_TYPES.has(file.type)) continue;
|
||||
try {
|
||||
const block = await readImage(file);
|
||||
const range = quill.getSelection(true);
|
||||
const index = range ? range.index : Math.max(0, quill.getLength() - 1);
|
||||
quill.insertEmbed(index, 'image', block.dataUrl, 'user');
|
||||
quill.setSelection(index + 1, 0, 'silent');
|
||||
} catch (error) {
|
||||
if (typeof options.onError === 'function') options.onError(error.message || String(error));
|
||||
}
|
||||
}
|
||||
};
|
||||
fileInput.onchange = async () => {
|
||||
await insertFiles(fileInput.files);
|
||||
fileInput.value = '';
|
||||
};
|
||||
quill.clipboard.addMatcher('IMG', (node, delta) => {
|
||||
const Delta = window.Quill.import('delta');
|
||||
return safeImageUrl(node && node.getAttribute('src')) ? delta : new Delta();
|
||||
});
|
||||
quill.root.addEventListener('paste', (event) => {
|
||||
const files = Array.from(event.clipboardData && event.clipboardData.files || []);
|
||||
if (files.some((file) => IMAGE_TYPES.has(file.type))) {
|
||||
event.preventDefault();
|
||||
insertFiles(files);
|
||||
}
|
||||
});
|
||||
quill.root.addEventListener('dragover', (event) => {
|
||||
if (Array.from(event.dataTransfer && event.dataTransfer.files || [])
|
||||
.some((file) => IMAGE_TYPES.has(file.type))) event.preventDefault();
|
||||
});
|
||||
quill.root.addEventListener('drop', (event) => {
|
||||
const files = Array.from(event.dataTransfer && event.dataTransfer.files || []);
|
||||
if (!files.some((file) => IMAGE_TYPES.has(file.type))) return;
|
||||
event.preventDefault();
|
||||
insertFiles(files);
|
||||
});
|
||||
|
||||
const initial = clientDelta(initialContent);
|
||||
if (initial) quill.setContents(initial.ops, 'silent');
|
||||
quill.history.clear();
|
||||
|
||||
return {
|
||||
content: () => clientDelta({ version: 2, ops: quill.getContents().ops }),
|
||||
text: () => plainText({ version: 2, ops: quill.getContents().ops }),
|
||||
focus: () => quill.focus(),
|
||||
surface: quill.root,
|
||||
quill,
|
||||
destroy: () => { host.textContent = ''; }
|
||||
};
|
||||
}
|
||||
|
||||
return { mount, render, plainText, fromText, hasContent };
|
||||
})();
|
||||
+952
-27
File diff suppressed because it is too large
Load Diff
+7
-2
@@ -4,10 +4,15 @@ window.escapeHtml = (s) => String(s == null ? '' : s).replace(/[&<>"']/g, (c) =>
|
||||
'&': '&', '<': '<', '>': '>', '"': '"', "'": '''
|
||||
}[c]));
|
||||
|
||||
// 结果会被插进 style="...",cover 来自第三方接口,属不可信输入。
|
||||
// 既要防 CSS 串逃逸(引号、反斜杠、括号),也要防 HTML 属性逃逸(交给 escapeHtml)。
|
||||
window.coverStyle = (cover) => {
|
||||
if (!cover) return '';
|
||||
const url = /^(https?:|data:)/.test(cover) ? cover : 'file:///' + String(cover).replace(/\\/g, '/');
|
||||
return `background-image:url('${url.replace(/'/g, "\\'")}')`;
|
||||
const raw = String(cover);
|
||||
const url = /^(https?:|data:)/i.test(raw) ? raw : 'file:///' + raw.replace(/\\/g, '/');
|
||||
if (/[\r\n]/.test(url)) return '';
|
||||
const css = url.replace(/[\\'"()]/g, (c) => '\\' + c);
|
||||
return window.escapeHtml(`background-image:url('${css}')`);
|
||||
};
|
||||
|
||||
window.copyText = async (btn, text) => {
|
||||
|
||||
Vendored
+202
@@ -0,0 +1,202 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2008-2015 Printio (Juriy Zaytsev, Maxim Chernyak)
|
||||
Copyright (c) 2016-present Andrea Bogazzi, Shachar Nen and Fabric.js contributors (https://github.com/fabricjs/fabric.js/graphs/contributors)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
Vendored
+440
File diff suppressed because one or more lines are too long
Vendored
+22
@@ -0,0 +1,22 @@
|
||||
Copyright
|
||||
(c) 2010-2025 James Hall, https://github.com/MrRio/jsPDF
|
||||
(c) 2015-2025 yWorks GmbH, https://www.yworks.com/
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining
|
||||
a copy of this software and associated documentation files (the
|
||||
"Software"), to deal in the Software without restriction, including
|
||||
without limitation the rights to use, copy, modify, merge, publish,
|
||||
distribute, sublicense, and/or sell copies of the Software, and to
|
||||
permit persons to whom the Software is furnished to do so, subject to
|
||||
the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+373
File diff suppressed because one or more lines are too long
Vendored
+651
@@ -0,0 +1,651 @@
|
||||
JSZip is dual licensed. At your choice you may use it under the MIT license *or* the GPLv3
|
||||
license.
|
||||
|
||||
The MIT License
|
||||
===============
|
||||
|
||||
Copyright (c) 2009-2016 Stuart Knightley, David Duponchel, Franz Buchinger, António Afonso
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in
|
||||
all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
THE SOFTWARE.
|
||||
|
||||
|
||||
GPL version 3
|
||||
=============
|
||||
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
Vendored
+13
File diff suppressed because one or more lines are too long
+22
@@ -0,0 +1,22 @@
|
||||
Copyright (c) 2014 Vitaly Puzrin, Alex Kocharin.
|
||||
|
||||
Permission is hereby granted, free of charge, to any person
|
||||
obtaining a copy of this software and associated documentation
|
||||
files (the "Software"), to deal in the Software without
|
||||
restriction, including without limitation the rights to use,
|
||||
copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the
|
||||
Software is furnished to do so, subject to the following
|
||||
conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be
|
||||
included in all copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
|
||||
OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
|
||||
HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
|
||||
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
||||
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
||||
OTHER DEALINGS IN THE SOFTWARE.
|
||||
Vendored
+14
File diff suppressed because one or more lines are too long
Vendored
+29
File diff suppressed because one or more lines are too long
Vendored
+29
File diff suppressed because one or more lines are too long
Vendored
+64962
File diff suppressed because one or more lines are too long
Vendored
+177
@@ -0,0 +1,177 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Binary file not shown.
Vendored
BIN
Binary file not shown.
Vendored
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+3
@@ -0,0 +1,3 @@
|
||||
àRCopyright 1990-2009 Adobe Systems Incorporated.
|
||||
All rights reserved.
|
||||
See ./LICENSEáCNS2-H
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
+3
@@ -0,0 +1,3 @@
|
||||
àRCopyright 1990-2009 Adobe Systems Incorporated.
|
||||
All rights reserved.
|
||||
See ./LICENSEá ETen-B5-H` ^
|
||||
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
BIN
Binary file not shown.
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user