commit 66bad58593db5f3f3d2a6e51c585e453debd6fd9 Author: Jidekin Date: Thu Nov 19 19:09:45 2026 +0800 feat: 小银 Markdown 编辑器 v2.6.1 源码 纯本地 Windows Markdown 编辑器(Electron + Tauri 双栈): - 实时预览、多标签 / 多窗口两种打开方式 - 查找高亮、大纲、侧栏面板 - 右键复制全文 / 打开目录、常用快捷键 - 不联网、不登录、不收集任何数据 仓库化时做的处理: - 路径脱敏:README 与 tools/mklink.js 里写死的 C:\Users\<用户名> 改为 %USERPROFILE% / process.env.USERPROFILE,换机器即可用(原文件含个人目录名) - 补 .gitignore(node_modules / dist / src-tauri/target / Tauri 自动生成的 gen/schemas) - 补 MIT LICENSE(与 package.json 的 license 字段一致) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..af8626d --- /dev/null +++ b/.gitignore @@ -0,0 +1,12 @@ +# ── 依赖与构建产物(都能重新生成)── +node_modules/ +dist/ +src-tauri/target/ + +# Tauri 自动生成的 ACL schema:`tauri dev/build` 会重建,不入库 +src-tauri/gen/schemas/ + +# ── 编辑器/系统杂项 ── +*.log +.DS_Store +Thumbs.db diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..3c2d71a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2026 小银 + +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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..83068db --- /dev/null +++ b/README.md @@ -0,0 +1,151 @@ +# 小银 Markdown + +一个纯本地的 Windows Markdown 编辑器。左边写、右边看,不联外网、不登录、不收集任何东西。 + +## 装在哪(示例) + +- 程序:`%USERPROFILE%\Apps\XiaoyinMarkdown\XiaoyinMarkdown.exe` +- 桌面快捷方式:`小银Markdown`(双击即可) + +## 功能 + +- **两种打开方式**:「标签」模式=一个窗口内多标签切换;「独立窗口」模式=每个文档一个窗口。点工具栏「标签 / 窗口」按钮即可切换,偏好会记住,重启后仍然生效 +- **切换时自动迁移**:从独立窗口切到标签 → 所有窗口里的文档合并进一个窗口的多个标签;从标签切到独立窗口 → 每个标签拆成一个独立窗口。未保存的正文、滚动位置、光标位置都会跟着过去,不会丢失 +- **右键打开**:文件树中右键「在新标签打开」或「在新窗口打开」——具体行为按当前记住的模式走;菜单「文件 → 在新窗口打开」快捷键 `Ctrl+Shift+N` +- **左侧文件目录**:列出当前文件夹里的 Markdown / 文本文件;**单击只选中,双击才打开**(文件夹也是双击展开),跟资源管理器的习惯一致;当前打开的文件高亮,会记住上次打开的文件夹 +- **文件条目操作**:文件树里右键「复制文件」=调用 Windows 原生复制(`Ctrl+C`),剪贴板里是**文件本身**,到资源管理器或微信等地方 `Ctrl+V` 能粘贴出文件副本;另有「复制文件内容」(正文文本)、「复制文件名」「复制完整路径」「在资源管理器中显示」 +- 实现说明:Electron 45 的 clipboard API 没有写文件的能力,所以通过 `koffi` 直接调用 Win32 `SetClipboardData(CF_HDROP)`,效果等同于在资源管理器里选中文件按 `Ctrl+C` +- **右侧章节大纲**:按 `#` 标题自动生成章节树,点一条跳到对应位置;随编辑实时更新,滚动时自动高亮当前章节 +- **两个开关标识**:「目录」紧挨在「编辑 / 分栏 / 阅读」切换按钮之前,「大纲」在它的右侧;样式统一,亮=展开、灭=收起,关掉随时能再打开,状态会记住 +- **面板宽度可拖拽**:目录右缘、大纲左缘各有一条分隔条,拖动即可调整宽度(有最小宽度限制);宽度自动记住,重启后保持 +- **查找**:`Ctrl+F` 查找条,`Enter`/`Shift+Enter` 上下切换;**右侧预览正文里所有命中都会加黄色背景标记**,当前命中橙色并自动滚到可视区,编辑内容变化时标记实时恢复,关闭查找自动清除 +- **实时预览**:编辑 / 分栏 / 阅读三种模式,分栏宽度可拖动 +- **拖进来就打开**:把 `.md` 文件拖进窗口直接打开;把**文件夹**拖进来,左侧列出该目录 +- **右键菜单**:复制全文、打开当前文件所在文件夹、剪切 / 复制 / 粘贴 / 全选 / 撤销 / 重做 +- **文件操作**:新建、打开、保存、另存为、打开文件夹,关窗时会提示未保存 +- **查找**:带匹配计数和上下跳转 +- **深色 / 浅色**主题,字号缩放 +- **渲染支持**:标题、粗体斜体删除线、行内代码、代码块、引用、有序无序与嵌套列表、任务列表、表格(含对齐)、分割线、链接、图片 +- 状态栏显示字数、字符数、光标行列;保留原文件的换行符(CRLF / LF) +- 渲染前会转义 HTML,预览里的链接用系统默认浏览器打开 + +## 快捷键 + +| 操作 | 快捷键 | +| --- | --- | +| 新建 / 打开 | `Ctrl+N` / `Ctrl+O` | +| 保存 / 另存为 | `Ctrl+S` / `Ctrl+Shift+S` | +| 撤销 / 重做 | `Ctrl+Z` / `Ctrl+Y` | +| 剪切 / 复制 / 粘贴 / 全选 | `Ctrl+X` / `C` / `V` / `A` | +| 查找 | `Ctrl+F` | +| 复制全文 | `Ctrl+Shift+C` | +| 打开文件夹 | `Ctrl+Shift+K` | +| 在新窗口打开当前文档 | `Ctrl+Shift+N` | +| 显示 / 隐藏文件目录 | `Ctrl+Shift+B` | +| 显示 / 隐藏章节大纲 | `Ctrl+Shift+T` | +| 复制文件树中选中项(文件本身) | `Ctrl+C`(焦点在条目上) | +| 在资源管理器中显示当前文件 | `Ctrl+Shift+O` | +| 编辑 / 分栏 / 阅读 | `Ctrl+1` / `Ctrl+2` / `Ctrl+3` | +| 深色浅色切换 | `Ctrl+Shift+L` | +| 放大 / 缩小 / 还原 | `Ctrl+Shift+=` / `Ctrl+Shift+-` / `Ctrl+0` | +| 全屏 / 开发者工具 | `F11` / `F12` | + +编辑区里还有两个顺手的细节:`Tab` 插入缩进;在列表项末尾按回车会自动续上下一条标记。 + +## 自己改代码 + +源码在本目录。目录结构: + +``` +md-editor/ +├─ src/ +│ ├─ main.js 主进程:窗口、菜单快捷键、文件读写、对话框 +│ ├─ preload.js 安全桥接(contextIsolation 开启) +│ └─ renderer/ +│ ├─ index.html 界面结构 +│ ├─ style.css 样式与两套主题 +│ ├─ markdown.js 自写的 Markdown 渲染引擎(零依赖) +│ └─ app.js 交互逻辑 +├─ tools/ 自测与打包辅助脚本(不参与发布) +└─ build/icon.ico 应用图标 +``` + +开发调试: + +```bash +npm start +``` + +跑一遍功能自测(31 项,覆盖渲染用例、打开保存、撤销粘贴、查找、模式切换、文件树展开与打开): + +```bash +npx electron tools/test.js +``` + +单独验证真实拖放链路(用 CDP 注入系统级拖放事件,确认能取到路径并打开文件/文件夹): + +```bash +npx electron tools/dragtest.js +``` + +验证侧栏启动行为与记忆恢复(记住文件夹、收起状态持久化): + +```bash +npx electron tools/sidetest.js +``` + +验证章节目录(生成、开关、跳转定位、实时更新、状态记忆): + +```bash +npx electron tools/outlinetest.js +``` + +验证文件树复制(右键复制文件名/路径/内容、Ctrl+C、按钮位置): + +```bash +npx electron tools/copytest.js +``` + +验证标签页、独立窗口偏好、右键打开方式(21 项): + +```bash +npx electron tools/multitest.js +``` + +验证真实主进程能否创建多个独立窗口: + +```bash +node tools/wintest.js +``` + +验证模式切换时的双向迁移(多窗口合并成标签、标签拆成多窗口,11 项): + +```bash +npx electron tools/migrationtest.js +``` + +验证关闭窗口时主进程不抛异常: + +```bash +npx electron tools/closetest.js +``` + +验证目录/大纲宽度拖拽与记忆(14 项): + +```bash +npx electron tools/paneltest.js +``` + +重新打包 exe: + +```bash +npx electron-packager . XiaoyinMarkdown --platform=win32 --arch=x64 --out=dist ^ + --overwrite --asar --icon=build/icon.ico --ignore="^/dist" --ignore="^/tools" --ignore="^/build" +``` + +打包完成后把 `dist\XiaoyinMarkdown-win32-x64` 整个目录拷到 `%USERPROFILE%\Apps\XiaoyinMarkdown` 覆盖即可(exe 依赖同目录的 dll,不能只拷 exe)。 + +## 说明 + +- 未做代码签名,首次运行 Windows SmartScreen 可能提示"未知发布者",选"仍要运行"即可。 +- 程序只读写你主动打开或保存的文件,不联网(预览里的链接除外,会交给系统浏览器)。 diff --git a/build/icon.ico b/build/icon.ico new file mode 100644 index 0000000..c93ba76 Binary files /dev/null and b/build/icon.ico differ diff --git a/build/icon.png b/build/icon.png new file mode 100644 index 0000000..a74ee1b Binary files /dev/null and b/build/icon.png differ diff --git a/package.json b/package.json new file mode 100644 index 0000000..6639e6c --- /dev/null +++ b/package.json @@ -0,0 +1,62 @@ +{ + "name": "xiaoyin-markdown-editor", + "productName": "XiaoyinMarkdown", + "version": "2.6.1", + "description": "轻量本地 Markdown 编辑器:实时预览、多标签/多窗口、查找高亮、右键复制全文/打开目录、常用快捷键", + "main": "src/main.js", + "author": "小银", + "license": "MIT", + "scripts": { + "start": "electron .", + "pack": "electron-packager . XiaoyinMarkdown --platform=win32 --arch=x64 --out=dist --overwrite --asar --app-version=1.0.0", + "installer": "electron-builder --win nsis --x64" + }, + "devDependencies": { + "@electron/packager": "^20.3.0", + "@tauri-apps/cli": "^2.12.6", + "electron": "45.4.1", + "windows-shortcuts": "^0.1.6" + }, + "dependencies": { + "koffi": "^3.3.8" + }, + "build": { + "appId": "com.xiaoyin.markdown", + "productName": "XiaoyinMarkdown", + "electronDist": "node_modules/electron/dist", + "directories": { + "output": "release" + }, + "files": [ + "src/**/*", + "package.json", + "!tools/**", + "!build/**", + "!release/**", + "!dist/**", + "!.cache/**", + "!.workbuddy/**", + "!shot-*.png", + "!README.md" + ], + "asarUnpack": [ + "**/node_modules/koffi/**" + ], + "win": { + "target": [ + "nsis" + ], + "icon": "build/icon.ico" + }, + "nsis": { + "oneClick": false, + "perMachine": false, + "allowToChangeInstallationDirectory": true, + "artifactName": "XiaoyinMarkdown-Setup-${version}.exe", + "shortcutName": "小银 Markdown", + "createDesktopShortcut": true, + "createStartMenuShortcut": true, + "uninstallDisplayName": "小银 Markdown" + } + } +} diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock new file mode 100644 index 0000000..44569e4 --- /dev/null +++ b/src-tauri/Cargo.lock @@ -0,0 +1,5089 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "adler2" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "320119579fcad9c21884f5c4861d16174d0e06250625266f50fe6898340abefa" + +[[package]] +name = "aho-corasick" +version = "1.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c982642fa9e8606056828ee9a8505737230110bb1099153c79efe865c59d12ba" +dependencies = [ + "memchr", +] + +[[package]] +name = "alloc-no-stdlib" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2fb6cfd47bf496ff64095c20eaba0c201404ee38714d4142fcfa1dc334fcc7a" + +[[package]] +name = "alloc-stdlib" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5c1865780388bfa186411ab5f247819487fc4864c6e9c3106611fa347586e1" +dependencies = [ + "alloc-no-stdlib", +] + +[[package]] +name = "android_system_properties" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae221649c9976a6f6c56ae1facf410f3ddb33cc661c4b7b61020a912d4237fbc" +dependencies = [ + "libc", +] + +[[package]] +name = "anyhow" +version = "1.0.104" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470" + +[[package]] +name = "async-broadcast" +version = "0.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "435a87a52755b8f27fcf321ac4f04b2802e337c8c4872923137471ec39c37532" +dependencies = [ + "event-listener", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-channel" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "924ed96dd52d1b75e9c1a3e6275715fd320f5f9439fb5a4a11fa51f4221158d2" +dependencies = [ + "concurrent-queue", + "event-listener-strategy", + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "async-executor" +version = "1.14.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f426a31126c735126297bc5ea7a521263c9faff4f63ca415267ee625651c4f37" +dependencies = [ + "async-task", + "concurrent-queue", + "fastrand", + "futures-lite", + "pin-project-lite", + "slab", +] + +[[package]] +name = "async-io" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456b8a8feb6f42d237746d4b3e9a178494627745c3c56c6ea55d92ba50d026fc" +dependencies = [ + "autocfg", + "cfg-if", + "concurrent-queue", + "futures-io", + "futures-lite", + "parking", + "polling", + "rustix", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-lock" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0876700b0d007ad25d5508865a4259c3af9af6d296bf663a0d586d0bc3369f6f" +dependencies = [ + "event-listener", + "event-listener-strategy", + "pin-project-lite", +] + +[[package]] +name = "async-process" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fc50921ec0055cdd8a16de48773bfeec5c972598674347252c0399676be7da75" +dependencies = [ + "async-channel", + "async-io", + "async-lock", + "async-signal", + "async-task", + "blocking", + "cfg-if", + "event-listener", + "futures-lite", + "rustix", +] + +[[package]] +name = "async-recursion" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4f8abc12baad266b1c8cec146854c195b5864b4221d4b2ca7296a7ae82d9e451" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "async-signal" +version = "0.2.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52b5aaafa020cf5053a01f2a60e8ff5dccf550f0f77ec54a4e47285ac2bab485" +dependencies = [ + "async-io", + "async-lock", + "atomic-waker", + "cfg-if", + "futures-core", + "futures-io", + "rustix", + "signal-hook-registry", + "slab", + "windows-sys 0.61.2", +] + +[[package]] +name = "async-task" +version = "4.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8b75356056920673b02621b35afd0f7dda9306d03c79a30f5c56c44cf256e3de" + +[[package]] +name = "async-trait" +version = "0.1.92" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f6aeea286b8eb4dd3431a1be1b59d290ace00f5bfd8e2a159bc2a05e2c1667" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "atk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "241b621213072e993be4f6f3a9e4b45f65b7e6faad43001be957184b7bb1824b" +dependencies = [ + "atk-sys", + "glib", + "libc", +] + +[[package]] +name = "atk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5e48b684b0ca77d2bbadeef17424c2ea3c897d44d566a1617e7e8f30614d086" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "atomic-waker" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1505bd5d3d116872e7271a6d4e16d81d0c8570876c8de68093a09ac269d8aac0" + +[[package]] +name = "autocfg" +version = "1.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2032f911046de80f0a198e0901378627c33f59ea0ac00e363d481118bd70a53" + +[[package]] +name = "base64" +version = "0.21.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d297deb1925b89f2ccc13d7635fa0714f12c87adce1c75356b39ca9b7178567" + +[[package]] +name = "base64" +version = "0.23.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac07cdecf99051d9a5238b80f35af32cdeba5b336e55d957b318b50137e18da5" + +[[package]] +name = "bit-set" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08807e080ed7f9d5433fa9b275196cfc35414f66a0c79d864dc51a0d825231a3" +dependencies = [ + "bit-vec 0.8.0", +] + +[[package]] +name = "bit-set" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "56d87354e4229f54a44f7bf2435906a4656dba36026ab6eaca629a2c436a691c" +dependencies = [ + "bit-vec 0.10.2", +] + +[[package]] +name = "bit-vec" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e764a1d40d510daf35e07be9eb06e75770908c27d411ee6c92109c9840eaaf7" + +[[package]] +name = "bit-vec" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72503af1e72be411d74ca45cd6b309878fcb35354e252fc2a3a8bda3a97082a0" + +[[package]] +name = "bitflags" +version = "1.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" + +[[package]] +name = "bitflags" +version = "2.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ded4057c258ba199e2d26386d3af3780957ecaee6c4ef4041c6b4b8b97c0b06" +dependencies = [ + "serde_core", +] + +[[package]] +name = "block-buffer" +version = "0.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71" +dependencies = [ + "generic-array", +] + +[[package]] +name = "block-buffer" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d2f6c7dbe95a6ed67ad9f18e57daf93a2f034c524b99fd2b76d18fdfeb6660aa" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "block2" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdeb9d870516001442e364c5220d3574d2da8dc765554b4a617230d33fa58ef5" +dependencies = [ + "objc2", +] + +[[package]] +name = "blocking" +version = "1.7.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a70e4329df6cb94385eed412ec92375c3cdd8a6e502493d1229b6414e4036dfa" +dependencies = [ + "async-channel", + "async-task", + "futures-io", + "futures-lite", + "piper", +] + +[[package]] +name = "brotli" +version = "9.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9071f285ed78f04f37d675abaaef5de7689e2f30a216c8dc6795465d81910a13" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", + "brotli-decompressor", +] + +[[package]] +name = "brotli-decompressor" +version = "6.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc031cd87c6529082b0b65c604e86af0ed7744841b17ccfe60b1e31fa606179e" +dependencies = [ + "alloc-no-stdlib", + "alloc-stdlib", +] + +[[package]] +name = "bs58" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf88ba1141d185c399bee5288d850d63b8369520c1eafc32a0430b5b6c287bf4" +dependencies = [ + "tinyvec", +] + +[[package]] +name = "bumpalo" +version = "3.20.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87a0cf66fd1eb2fb7b822cb78370d82303750809bc6ba855f3f58e517d3238db" + +[[package]] +name = "bytemuck" +version = "1.25.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95832e849adfb21180ccb6826a99da14e5d266ae5c2e668e1602cf234f153797" + +[[package]] +name = "byteorder" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" + +[[package]] +name = "bytes" +version = "1.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "776dfebd015e2d8732c684a2c71003674ccb49457b539b9e82151ba38e96dd7c" +dependencies = [ + "serde", +] + +[[package]] +name = "cairo-rs" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8ca26ef0159422fb77631dc9d17b102f253b876fe1586b03b803e63a309b4ee2" +dependencies = [ + "bitflags 2.13.2", + "cairo-sys-rs", + "glib", + "libc", + "once_cell", + "thiserror 1.0.69", +] + +[[package]] +name = "cairo-sys-rs" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "685c9fa8e590b8b3d678873528d83411db17242a73fccaed827770ea0fedda51" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "camino" +version = "1.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bbbad30e4b4c14a39e3cc8aed085a12a327257c316619c93581e017bc52be591" +dependencies = [ + "serde_core", +] + +[[package]] +name = "cargo-platform" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35af189006b9c0f00a064685c727031e3ed2d8020f7ba284d78cc2671bd36ea" +dependencies = [ + "serde", +] + +[[package]] +name = "cargo_metadata" +version = "0.19.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd5eb614ed4c27c5d706420e4320fbe3216ab31fa1c33cd8246ac36dae4479ba" +dependencies = [ + "camino", + "cargo-platform", + "semver", + "serde", + "serde_json", + "thiserror 2.0.21", +] + +[[package]] +name = "cargo_toml" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "82f4b26e751e711a5302649417f2da046dce6391b2ea30a4820f37462314f0b9" +dependencies = [ + "semver", + "serde", + "toml 1.2.1+spec-1.1.0", +] + +[[package]] +name = "cc" +version = "1.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33ef9e3e8154a45c7a95cff4c1299702106ad94062d7bb85fdc5d3a5afd91d45" +dependencies = [ + "find-msvc-tools", + "shlex", +] + +[[package]] +name = "cesu8" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6d43a04d8753f35258c91f8ec639f792891f748a1edbd759cf1dcea3382ad83c" + +[[package]] +name = "cfb" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a347dcabdae9c31b0825fd6a8bed285ec9c2acb89c47827126d52fa4f59cece3" +dependencies = [ + "fnv", + "uuid", + "web-time", +] + +[[package]] +name = "cfg-expr" +version = "0.15.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d067ad48b8650848b989a59a86c6c36a995d02d2bf778d45c3c5d57bc2718f02" +dependencies = [ + "smallvec", + "target-lexicon", +] + +[[package]] +name = "cfg-if" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600" + +[[package]] +name = "chrono" +version = "0.4.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1aa79e62e7697b8e29b513a68abacf485adcd1fe8284a4316c5ae868e6633327" +dependencies = [ + "iana-time-zone", + "num-traits", + "serde", + "windows-link", +] + +[[package]] +name = "clipboard-win" +version = "5.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "052af7878466feccda12ba7a6a67d019d712f296809559b47c12c8cc196d3a9a" +dependencies = [ + "error-code", +] + +[[package]] +name = "combine" +version = "4.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4356eba6976435498d05a311ee9fc486da3bc81c200d3f0d7dd9703b41913f92" +dependencies = [ + "bytes", + "memchr", +] + +[[package]] +name = "concurrent-queue" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ca0197aee26d1ae37445ee532fefce43251d24cc7c166799f4d46817f1d3973" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "const-oid" +version = "0.10.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be95d4a884358a21a199689323c29e9256b4a1b315e22f183d155422041d3a9a" + +[[package]] +name = "cookie" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a373e3602691c3cdea496d2f0ee5935151e6168fe87739483c463db1b2f2f87" +dependencies = [ + "time", + "version_check", +] + +[[package]] +name = "core-foundation" +version = "0.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2a6cd9ae233e7f62ba4e9353e81a88df7fc8a5987b8d445b4d90c879bd156f6" +dependencies = [ + "core-foundation-sys", + "libc", +] + +[[package]] +name = "core-foundation-sys" +version = "0.8.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" + +[[package]] +name = "core-graphics" +version = "0.25.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "064badf302c3194842cf2c5d61f56cc88e54a759313879cdf03abdd27d0c3b97" +dependencies = [ + "bitflags 2.13.2", + "core-foundation", + "core-graphics-types", + "foreign-types", + "libc", +] + +[[package]] +name = "core-graphics-types" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3d44a101f213f6c4cdc1853d4b78aef6db6bdfa3468798cc1d9912f4735013eb" +dependencies = [ + "bitflags 2.13.2", + "core-foundation", + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "59ed5838eebb26a2bb2e58f6d5b5316989ae9d08bab10e0e6d103e656d1b0280" +dependencies = [ + "libc", +] + +[[package]] +name = "cpufeatures" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5ca28b0ae3115b884660db4118d803791fd6756b6e88f39c0f3f7859060d7566" +dependencies = [ + "libc", +] + +[[package]] +name = "crc32fast" +version = "1.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b929dd2a135771f40afabd1073f85eed59c800b7c61901e5c254270497dad64" +dependencies = [ + "cfg-if", +] + +[[package]] +name = "crossbeam-channel" +version = "0.5.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "98b0cc327b5bc766e7fda9c9260cc0fa81b43a8e240440422dff70788e3f9ef1" +dependencies = [ + "crossbeam-utils", +] + +[[package]] +name = "crossbeam-utils" +version = "0.8.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a31eee39dddec8330830986fcd7625edb5a24ec90ea038215273bbc3adb08ac6" + +[[package]] +name = "crypto-common" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "78c8292055d1c1df0cce5d180393dc8cce0abec0a7102adb6c7b1eef6016d60a" +dependencies = [ + "generic-array", + "typenum", +] + +[[package]] +name = "crypto-common" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce6e4c961d6cd6c9a86db418387425e8bdeaf05b3c8bc1411e6dca4c252f1453" +dependencies = [ + "hybrid-array", +] + +[[package]] +name = "cssparser" +version = "0.37.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c9cdaae01d5ed7882b04d795e7f752f46ff52d2fa3b50a20d28c464510bba98" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.13.1", + "smallvec", +] + +[[package]] +name = "cssparser" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "11119743ad110e8c1bdccd930d7f5c30c99e5fc76a7b63ec9807e84eef0c5f59" +dependencies = [ + "cssparser-macros", + "dtoa-short", + "itoa", + "phf 0.14.0", + "smallvec", +] + +[[package]] +name = "cssparser-macros" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d045de693cb712d0b22c6a64be5b953f67b3ce00ab5ad3dd5d8b441886ab8e1a" +dependencies = [ + "quote", + "syn 3.0.10", +] + +[[package]] +name = "ctor" +version = "1.0.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea691ed9f36489d087419b8b2ba3ef27d89621380b4178c73e2445a379e4e0f4" +dependencies = [ + "link-section", +] + +[[package]] +name = "darling" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed17f5901b6630b993ca003def43f2f8ef4014fc13b047b57aad617ff32bc2ec" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6837e2cf7485aaae18f86181d2f0e9a7ed297a025e220aeabf63fdebd3a2ddff" +dependencies = [ + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn 3.0.10", +] + +[[package]] +name = "darling_macro" +version = "0.24.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ac7135c3ef02b2f7833bbeb1be5ba7f966dcde8a87c6b87f65a778d71a02785" +dependencies = [ + "darling_core", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "dbus" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ab69f03cc8c4340c9c8e315114e1658e6775a9b16a04357973aa21cec22b32e" +dependencies = [ + "libc", + "libdbus-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "deranged" +version = "0.5.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e9de72ce2ad1f90dc62fa25f0f430ef85eb4b0d8fa0be4f30373bc40a21d28e" +dependencies = [ + "serde_core", +] + +[[package]] +name = "derive_more" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d751e9e49156b02b44f9c1815bcb94b984cdcc4396ecc32521c739452808b134" +dependencies = [ + "derive_more-impl", +] + +[[package]] +name = "derive_more-impl" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "799a97264921d8623a957f6c3b9011f3b5492f557bbb7a5a19b7fa6d06ba8dcb" +dependencies = [ + "proc-macro2", + "quote", + "rustc_version", + "syn 2.0.119", +] + +[[package]] +name = "digest" +version = "0.10.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292" +dependencies = [ + "block-buffer 0.10.4", + "crypto-common 0.1.7", +] + +[[package]] +name = "digest" +version = "0.11.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f1dd6dbb5841937940781866fa1281a1ff7bd3bf827091440879f9994983d5c2" +dependencies = [ + "block-buffer 0.12.1", + "const-oid", + "crypto-common 0.2.2", +] + +[[package]] +name = "dirs" +version = "7.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d57d423b3c82e89b9a24ca3091fee61f456a26edbd28d26c65906f4bc1dcd8f" +dependencies = [ + "dirs-sys", +] + +[[package]] +name = "dirs-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab" +dependencies = [ + "libc", + "option-ext", + "redox_users", + "windows-sys 0.61.2", +] + +[[package]] +name = "dispatch2" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e0e367e4e7da84520dedcac1901e4da967309406d1e51017ae1abfb97adbd38" +dependencies = [ + "bitflags 2.13.2", + "block2", + "libc", + "objc2", +] + +[[package]] +name = "displaydoc" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6232dd377dcc64799954cbd3a9bb882e9cdc1308ccd87b1c098f1fb2eaf82a8" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "dlopen2" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e2c5bd4158e66d1e215c49b837e11d62f3267b30c92f1d171c4d3105e3dc4d4" +dependencies = [ + "dlopen2_derive", + "libc", + "once_cell", + "winapi", +] + +[[package]] +name = "dlopen2_derive" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fbbb781877580993a8707ec48672673ec7b81eeba04cfd2310bd28c08e47c8f" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "dom_query" +version = "0.28.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fac5fca71e65e94cc718a6e2af65d6e0f9c6027751c2aa562fbb5087fda639bc" +dependencies = [ + "bit-set 0.8.0", + "cssparser 0.37.0", + "foldhash", + "html5ever 0.39.0", + "precomputed-hash", + "selectors 0.38.0", + "tendril", +] + +[[package]] +name = "dom_query" +version = "0.29.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "498c698ac51127148a3984450e51fca7f01805a91d7a1f7a24af0a5f761e3385" +dependencies = [ + "bit-set 0.11.1", + "cssparser 0.38.0", + "foldhash", + "html5ever 0.40.1", + "precomputed-hash", + "selectors 0.41.0", + "tendril", +] + +[[package]] +name = "dpi" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d8b14ccef22fc6f5a8f4d7d768562a182c04ce9a3b3157b91390b52ddfdf1a76" +dependencies = [ + "serde", +] + +[[package]] +name = "dtoa" +version = "1.0.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c3cf4824e2d5f025c7b531afcb2325364084a16806f6d47fbc1f5fbd9960590" + +[[package]] +name = "dtoa-short" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd1511a7b6a56299bd043a9c167a6d2bfb37bf84a6dfceaba651168adfb43c87" +dependencies = [ + "dtoa", +] + +[[package]] +name = "dunce" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" + +[[package]] +name = "dyn-clone" +version = "1.0.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d0881ea181b1df73ff77ffaaf9c7544ecc11e82fba9b5f27b262a3c73a332555" + +[[package]] +name = "embed-resource" +version = "3.0.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6168487b5e7eb2673e6efe1200b1848016e436a6ca0b8031bf04bd9d493a249f" +dependencies = [ + "cc", + "memchr", + "rustc_version", + "toml 1.2.1+spec-1.1.0", + "vswhom", + "winreg", +] + +[[package]] +name = "embed_plist" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ef6b89e5b37196644d8796de5268852ff179b44e96276cf4290264843743bb7" + +[[package]] +name = "endi" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "66b7e2430c6dff6a955451e2cfc438f09cea1965a9d6f87f7e3b90decc014099" + +[[package]] +name = "enumflags2" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1027f7680c853e056ebcec683615fb6fbbc07dbaa13b4d5d9442b146ded4ecef" +dependencies = [ + "enumflags2_derive", + "serde", +] + +[[package]] +name = "enumflags2_derive" +version = "0.7.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67c78a4d8fdf9953a5c9d458f9efe940fd97a0cab0941c075a813ac594733827" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "equivalent" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826" + +[[package]] +name = "erased-serde" +version = "0.4.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e59b668157f32d3459d4bd634861a06ffa2503a461ca5f0916b9f0252605e66" +dependencies = [ + "serde", + "serde_core", + "typeid", +] + +[[package]] +name = "errno" +version = "0.3.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e35d6e78f4cebb90e51d543db8fe41528851d6deeef6ef21ebd4bfdc1e784776" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "error-code" +version = "3.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b5343afd4a8365a643ac588dab4cf234a190c7f6c88c9f6dd6ffe00837661b7" + +[[package]] +name = "event-listener" +version = "5.4.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a23add41df1562121a9393cb065eab5146a1242410f23a644851e90cfd669d2" +dependencies = [ + "parking", + "pin-project-lite", +] + +[[package]] +name = "event-listener-strategy" +version = "0.5.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93" +dependencies = [ + "event-listener", + "pin-project-lite", +] + +[[package]] +name = "fastrand" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da7c62ceae207dd37ea5b845da6a0696c799f85e97da1ab5b7910be3c1c80223" + +[[package]] +name = "fdeflate" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1e6853b52649d4ac5c0bd02320cddc5ba956bdb407c4b75a2c6b75bf51500f8c" +dependencies = [ + "simd-adler32", +] + +[[package]] +name = "field-offset" +version = "0.3.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38e2275cc4e4fc009b0669731a1e5ab7ebf11f469eaede2bab9309a5b4d6057f" +dependencies = [ + "memoffset", + "rustc_version", +] + +[[package]] +name = "find-msvc-tools" +version = "0.1.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1c66915cc5391097de7a2b0b972e8505aa33c0df401fd3a6811dbdb32881ba48" + +[[package]] +name = "flate2" +version = "1.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "626d4928326b646e70f65ed36fc7cf9f206bdb68a0019ee7c6b4709da4e084c4" +dependencies = [ + "crc32fast", + "miniz_oxide 0.9.1", + "zlib-rs", +] + +[[package]] +name = "fnv" +version = "1.0.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" + +[[package]] +name = "foldhash" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "77ce24cb58228fbb8aa041425bb1050850ac19177686ea6e0f41a70416f56fdb" + +[[package]] +name = "foreign-types" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d737d9aa519fb7b749cbc3b962edcf310a8dd1f4b67c91c4f83975dbdd17d965" +dependencies = [ + "foreign-types-macros", + "foreign-types-shared", +] + +[[package]] +name = "foreign-types-macros" +version = "0.2.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ea5190182e6915eb873ddbc16e23b711b6eb1f9c00a0d0a3a91b5f6228475225" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "foreign-types-shared" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aa9a19cbb55df58761df49b23516a86d432839add4af60fc256da840f66ed35b" + +[[package]] +name = "form_urlencoded" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb4cb245038516f5f85277875cdaa4f7d2c9a0fa0468de06ed190163b1581fcf" +dependencies = [ + "percent-encoding", +] + +[[package]] +name = "futures-channel" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f9e3d69d39e4862ffed03ed071a76f9a13ba1d9109d355b0f0aa6b15e393c4" +dependencies = [ + "futures-core", +] + +[[package]] +name = "futures-core" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92d699e522242e69e3003b94ecc1f960f3a5e015aa7c5d7486e65ad01dd94f5e" + +[[package]] +name = "futures-executor" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "031b47cf1a3c6cc8bc2fc76cd437f521619387907d469316e7c0bc278f1f5432" +dependencies = [ + "futures-core", + "futures-task", + "futures-util", +] + +[[package]] +name = "futures-io" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "53c0fa8157de1303bfffdaa1cc2a673bfffb60102f76b0ef4441659124373fed" + +[[package]] +name = "futures-lite" +version = "2.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f78e10609fe0e0b3f4157ffab1876319b5b0db102a2c60dc4626306dc46b44ad" +dependencies = [ + "fastrand", + "futures-core", + "futures-io", + "parking", + "pin-project-lite", +] + +[[package]] +name = "futures-macro" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9fb9654ba8355388abeb8dcb4fc62f511300867002afc858860463bdd9fe0c44" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "futures-sink" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1944426bf7d03f1d14f708785e4b33efd750b36d48a157b836b3efc15ede8e1d" + +[[package]] +name = "futures-task" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cd417de3d1d015fc3bfd2b1ea46dfc7bab72ef86f1cc7cc9c78e728b34a6d1fd" + +[[package]] +name = "futures-util" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0d50a92467f8ba5dd6e3ee5d4bd04d73ab2e4e1c44474a0674821dfce14b79bc" +dependencies = [ + "futures-core", + "futures-io", + "futures-macro", + "futures-sink", + "futures-task", + "memchr", + "pin-project-lite", + "slab", +] + +[[package]] +name = "gdk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d9f245958c627ac99d8e529166f9823fb3b838d1d41fd2b297af3075093c2691" +dependencies = [ + "cairo-rs", + "gdk-pixbuf", + "gdk-sys", + "gio", + "glib", + "libc", + "pango", +] + +[[package]] +name = "gdk-pixbuf" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "50e1f5f1b0bfb830d6ccc8066d18db35c487b1b2b1e8589b5dfe9f07e8defaec" +dependencies = [ + "gdk-pixbuf-sys", + "gio", + "glib", + "libc", + "once_cell", +] + +[[package]] +name = "gdk-pixbuf-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f9839ea644ed9c97a34d129ad56d38a25e6756f99f3a88e15cd39c20629caf7" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gdk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c2d13f38594ac1e66619e188c6d5a1adb98d11b2fcf7894fc416ad76aa2f3f7" +dependencies = [ + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gdkwayland-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "140071d506d223f7572b9f09b5e155afbd77428cd5cc7af8f2694c41d98dfe69" +dependencies = [ + "gdk-sys", + "glib-sys", + "gobject-sys", + "libc", + "pkg-config", + "system-deps", +] + +[[package]] +name = "gdkx11" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3caa00e14351bebbc8183b3c36690327eb77c49abc2268dd4bd36b856db3fbfe" +dependencies = [ + "gdk", + "gdkx11-sys", + "gio", + "glib", + "libc", + "x11", +] + +[[package]] +name = "gdkx11-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e7445fe01ac26f11601db260dd8608fe172514eb63b3b5e261ea6b0f4428d" +dependencies = [ + "gdk-sys", + "glib-sys", + "libc", + "system-deps", + "x11", +] + +[[package]] +name = "generic-array" +version = "0.14.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a" +dependencies = [ + "typenum", + "version_check", +] + +[[package]] +name = "getrandom" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "899def5c37c4fd7b2664648c28120ecec138e4d395b459e5ca34f9cce2dd77fd" +dependencies = [ + "cfg-if", + "libc", + "r-efi 5.3.0", + "wasip2", +] + +[[package]] +name = "getrandom" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "300e883d756b2e4ec94e02791f39b04b522276138852cfc41d9fb7e904106099" +dependencies = [ + "cfg-if", + "libc", + "r-efi 6.0.0", +] + +[[package]] +name = "gio" +version = "0.18.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d4fc8f532f87b79cbc51a79748f16a6828fb784be93145a322fa14d06d354c73" +dependencies = [ + "futures-channel", + "futures-core", + "futures-io", + "futures-util", + "gio-sys", + "glib", + "libc", + "once_cell", + "pin-project-lite", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "gio-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "37566df850baf5e4cb0dfb78af2e4b9898d817ed9263d1090a2df958c64737d2" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", + "winapi", +] + +[[package]] +name = "glib" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "233daaf6e83ae6a12a52055f568f9d7cf4671dabb78ff9560ab6da230ce00ee5" +dependencies = [ + "bitflags 2.13.2", + "futures-channel", + "futures-core", + "futures-executor", + "futures-task", + "futures-util", + "gio-sys", + "glib-macros", + "glib-sys", + "gobject-sys", + "libc", + "memchr", + "once_cell", + "smallvec", + "thiserror 1.0.69", +] + +[[package]] +name = "glib-macros" +version = "0.18.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bb0228f477c0900c880fd78c8759b95c7636dbd7842707f49e132378aa2acdc" +dependencies = [ + "heck 0.4.1", + "proc-macro-crate 2.0.2", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "glib-sys" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "063ce2eb6a8d0ea93d2bf8ba1957e78dbab6be1c2220dd3daca57d5a9d869898" +dependencies = [ + "libc", + "system-deps", +] + +[[package]] +name = "glob" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4eba85ea1d0a966a983acd07deee566e67395d2d96b6fb39e62b5a833f1eb0b" + +[[package]] +name = "gobject-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0850127b514d1c4a4654ead6dedadb18198999985908e6ffe4436f53c785ce44" +dependencies = [ + "glib-sys", + "libc", + "system-deps", +] + +[[package]] +name = "gtk" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd56fb197bfc42bd5d2751f4f017d44ff59fbb58140c6b49f9b3b2bdab08506a" +dependencies = [ + "atk", + "cairo-rs", + "field-offset", + "futures-channel", + "gdk", + "gdk-pixbuf", + "gio", + "glib", + "gtk-sys", + "gtk3-macros", + "libc", + "pango", + "pkg-config", +] + +[[package]] +name = "gtk-sys" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8f29a1c21c59553eb7dd40e918be54dccd60c52b049b75119d5d96ce6b624414" +dependencies = [ + "atk-sys", + "cairo-sys-rs", + "gdk-pixbuf-sys", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "pango-sys", + "system-deps", +] + +[[package]] +name = "gtk3-macros" +version = "0.18.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "52ff3c5b21f14f0736fed6dcfc0bfb4225ebf5725f3c0209edeec181e4d73e9d" +dependencies = [ + "proc-macro-crate 1.3.1", + "proc-macro-error", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "hashbrown" +version = "0.12.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a9ee70c43aaf417c914396645a0fa852624801b24ebb7ae78fe8272889ac888" + +[[package]] +name = "hashbrown" +version = "0.17.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a" + +[[package]] +name = "heck" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "95505c38b4572b2d910cecb0281560f54b440a19336cbbcb27bf6ce6adc6f5a8" + +[[package]] +name = "heck" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" + +[[package]] +name = "hermit-abi" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e17592d60ebacc7d5e169f4663c5f84f9161cc90328abcfe8456f41e4dfcb284" + +[[package]] +name = "hex" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f24254aa9a54b5c858eaee2f5bccdb46aaf0e486a595ed5fd8f86ba55232a70" + +[[package]] +name = "html5ever" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "46a1761807faccc9a19e86944bbf40610014066306f96edcdedc2fb714bcb7b8" +dependencies = [ + "log", + "markup5ever 0.39.0", +] + +[[package]] +name = "html5ever" +version = "0.40.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "456a1a377e608e555d22ddab27ac0114bc7a7b4199078108e34c2aeae6c9b130" +dependencies = [ + "log", + "markup5ever 0.40.0", + "memchr", +] + +[[package]] +name = "http" +version = "1.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "918d3568bebf352712bc2ef3d46a8bcf1a75b373be6539de198e9105cbbf9ce0" +dependencies = [ + "bytes", + "itoa", +] + +[[package]] +name = "http-body" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca2a8f2913ee65f60facd6a5905613afaa448497a0230cc41ce022d93290bc2c" +dependencies = [ + "bytes", + "http", +] + +[[package]] +name = "http-body-util" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23169fe34a5fbcdd3f3862e78fb9b6fccd5f02a6dc6f732547005d45631ce71c" +dependencies = [ + "bytes", + "futures-core", + "http", + "http-body", + "pin-project-lite", +] + +[[package]] +name = "httparse" +version = "1.10.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6dbf3de79e51f3d586ab4cb9d5c3e2c14aa28ed23d180cf89b4df0454a69cc87" + +[[package]] +name = "hybrid-array" +version = "0.4.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27f864f10dfb56725ce5ce5472bc52252c8f93a4ab86327122cebf62c5f59a17" +dependencies = [ + "typenum", +] + +[[package]] +name = "hyper" +version = "1.12.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2c3e324da4c95177d6291d4c8730197c0d1822f8a9766814a4a44fa5ab797c9c" +dependencies = [ + "atomic-waker", + "bytes", + "futures-core", + "http", + "http-body", + "httparse", + "itoa", + "pin-project-lite", + "smallvec", + "tokio", + "want", +] + +[[package]] +name = "hyper-util" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ddc03d96684f9226b8a787cdb71488417b53ab5ea8fdb1dac946cb9431cc8bff" +dependencies = [ + "base64 0.23.1", + "bytes", + "futures-channel", + "futures-util", + "http", + "http-body", + "httparse", + "hyper", + "ipnet", + "libc", + "percent-encoding", + "pin-project-lite", + "socket2", + "tokio", + "tower-service", + "tracing", +] + +[[package]] +name = "iana-time-zone" +version = "0.1.65" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e31bc9ad994ba00e440a8aa5c9ef0ec67d5cb5e5cb0cc7f8b744a35b389cc470" +dependencies = [ + "android_system_properties", + "core-foundation-sys", + "iana-time-zone-haiku", + "js-sys", + "log", + "wasm-bindgen", + "windows-core", +] + +[[package]] +name = "iana-time-zone-haiku" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f" +dependencies = [ + "cc", +] + +[[package]] +name = "ico" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d75e94d66081e4d8dcd098bd8dc5254800fea14a26389b298410158d834de167" +dependencies = [ + "byteorder", + "png", +] + +[[package]] +name = "icu_collections" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe090a42a0d3140fed8c63263ed1fecc02422cb2f4bfe55cd8de2de1b8e105dd" +dependencies = [ + "displaydoc", + "potential_utf", + "utf8_iter", + "yoke", + "zerofrom", + "zerovec", +] + +[[package]] +name = "icu_locale_core" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "25d29b57c17c6528d0dc4c2141cfa2d08200465acb537a3909c8b9b8a4a984c0" +dependencies = [ + "displaydoc", + "litemap", + "tinystr", + "writeable", + "zerovec", +] + +[[package]] +name = "icu_normalizer" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "404a3b8c486f205c87fe7f23ab6894d84a4ad76d6e4671ae1981ba7def87c599" +dependencies = [ + "icu_collections", + "icu_normalizer_data", + "icu_properties", + "icu_provider", + "smallvec", + "zerovec", +] + +[[package]] +name = "icu_normalizer_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20f0088bfb7441f7a37fa0c9e20cb1e9cba1cac6b9ce8cd2a6dc44294f8e8cbc" + +[[package]] +name = "icu_properties" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ea83d991c56158f7cf898bf86436c1dfe7c07ee82fe88951f2695c9f37a379f" +dependencies = [ + "displaydoc", + "icu_collections", + "icu_locale_core", + "icu_properties_data", + "icu_provider", + "zerotrie", + "zerovec", +] + +[[package]] +name = "icu_properties_data" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b98f29af82d02b163fe50161388350e743bb3107cc8e8c2f7314cb505faddfcf" + +[[package]] +name = "icu_provider" +version = "2.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "413099315636c588ee8f011190b329b971a09a8fae9d157e01dcae8379468514" +dependencies = [ + "displaydoc", + "icu_locale_core", + "writeable", + "yoke", + "zerofrom", + "zerotrie", + "zerovec", +] + +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + +[[package]] +name = "idna" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b0875f23caa03898994f6ddc501886a45c7d3d62d04d2d90788d47be1b1e4de" +dependencies = [ + "idna_adapter", + "smallvec", + "utf8_iter", +] + +[[package]] +name = "idna_adapter" +version = "1.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cb68373c0d6620ef8105e855e7745e18b0d00d3bdb07fb532e434244cdb9a714" +dependencies = [ + "icu_normalizer", + "icu_properties", +] + +[[package]] +name = "indexmap" +version = "1.9.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bd070e393353796e801d209ad339e89596eb4c8d430d18ede6a1cced8fafbd99" +dependencies = [ + "autocfg", + "hashbrown 0.12.3", + "serde", +] + +[[package]] +name = "indexmap" +version = "2.14.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855" +dependencies = [ + "equivalent", + "hashbrown 0.17.1", + "serde", + "serde_core", +] + +[[package]] +name = "infer" +version = "0.22.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f4200d433cbd5178df7797c9c2e75b348b728e39631cf14520d1e2fc424201f4" +dependencies = [ + "cfb", +] + +[[package]] +name = "ipnet" +version = "2.12.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "791930b43c0d5973160d90a8f3894509f2b273430f5c5c73b668636d0287c5c0" + +[[package]] +name = "itoa" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3bd1574e617a9a6c1f8f8181bd7e841e1f20e4277607ef28945765188d6284d4" + +[[package]] +name = "javascriptcore-rs" +version = "1.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca5671e9ffce8ffba57afc24070e906da7fc4b1ba66f2cabebf61bf2ea257fcc" +dependencies = [ + "bitflags 1.3.2", + "glib", + "javascriptcore-rs-sys", +] + +[[package]] +name = "javascriptcore-rs-sys" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af1be78d14ffa4b75b66df31840478fef72b51f8c2465d4ca7c194da9f7a5124" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "jiff" +version = "0.2.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "175dc66334db3b9ab9985bf8b61cfed50dc16d20964bb47f9e479adcae984a7f" +dependencies = [ + "jiff-core", + "jiff-static", + "jiff-tzdb-platform", + "log", + "portable-atomic", + "portable-atomic-util", + "serde_core", + "windows-link", +] + +[[package]] +name = "jiff-core" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e599b80292e597019b8b3e392de3f4bea2959ddfb8c7dff60e035e9e311a2c1b" +dependencies = [ + "log", +] + +[[package]] +name = "jiff-static" +version = "0.2.46" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7b1af7547d47354bc438d797e3854601bde8f8d185780c5ba4ab27afa54f1ba" +dependencies = [ + "jiff-core", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "jiff-tzdb" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0980fca2cc272465bd60e82397607ba9f33add9e48defd77923301bbd03808f2" + +[[package]] +name = "jiff-tzdb-platform" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "875a5a69ac2bab1a891711cf5eccbec1ce0341ea805560dcd90b7a2e925132e8" +dependencies = [ + "jiff-tzdb", +] + +[[package]] +name = "jni" +version = "0.21.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1a87aa2bb7d2af34197c04845522473242e1aa17c12f4935d5856491a7fb8c97" +dependencies = [ + "cesu8", + "cfg-if", + "combine", + "jni-sys 0.3.1", + "log", + "thiserror 1.0.69", + "walkdir", + "windows-sys 0.45.0", +] + +[[package]] +name = "jni-sys" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41a652e1f9b6e0275df1f15b32661cf0d4b78d4d87ddec5e0c3c20f097433258" +dependencies = [ + "jni-sys 0.4.1", +] + +[[package]] +name = "jni-sys" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6377a88cb3910bee9b0fa88d4f42e1d2da8e79915598f65fb0c7ee14c878af2" +dependencies = [ + "jni-sys-macros", +] + +[[package]] +name = "jni-sys-macros" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38c0b942f458fe50cdac086d2f946512305e5631e720728f2a61aabcd47a6264" +dependencies = [ + "quote", + "syn 2.0.119", +] + +[[package]] +name = "js-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8dc09d2154098bbf4ef54eab6b117a3c24cbbffe94046b16ee6d6d4510584d3a" +dependencies = [ + "cfg-if", + "futures-util", + "wasm-bindgen", +] + +[[package]] +name = "json-patch" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7421438de105a0827e44fadd05377727847d717c80ce29a229f85fd04c427b72" +dependencies = [ + "jsonptr", + "serde", + "serde_json", + "thiserror 2.0.21", +] + +[[package]] +name = "jsonptr" +version = "0.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a5a3cc660ba5d72bce0b3bb295bf20847ccbb40fd423f3f05b61273672e561fe" +dependencies = [ + "serde", + "serde_json", +] + +[[package]] +name = "keyboard-types" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0fbe853b403ae61a04233030ae8a79d94975281ed9770a1f9e246732b534b28d" +dependencies = [ + "bitflags 2.13.2", + "serde", +] + +[[package]] +name = "libappindicator" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03589b9607c868cc7ae54c0b2a22c8dc03dd41692d48f2d7df73615c6a95dc0a" +dependencies = [ + "glib", + "gtk", + "gtk-sys", + "libappindicator-sys", + "log", +] + +[[package]] +name = "libappindicator-sys" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e9ec52138abedcc58dc17a7c6c0c00a2bdb4f3427c7f63fa97fd0d859155caf" +dependencies = [ + "gtk-sys", + "libloading", + "once_cell", +] + +[[package]] +name = "libc" +version = "0.2.191" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a" + +[[package]] +name = "libdbus-sys" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "328c4789d42200f1eeec05bd86c9c13c7f091d2ba9a6ea35acdf51f31bc0f043" +dependencies = [ + "pkg-config", +] + +[[package]] +name = "libloading" +version = "0.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67380fd3b2fbe7527a606e18729d21c6f3951633d0500574c4dc22d2d638b9f" +dependencies = [ + "cfg-if", + "winapi", +] + +[[package]] +name = "libredox" +version = "0.1.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d" +dependencies = [ + "libc", +] + +[[package]] +name = "link-section" +version = "0.19.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4d9aae57673c1a235149777a74d152f3210ebd3e3b13346d2cdb6809e566bd3c" + +[[package]] +name = "linux-raw-sys" +version = "0.12.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a66949e030da00e8c7d4434b251670a91556f4144941d37452769c25d58a53" + +[[package]] +name = "litemap" +version = "0.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d9d19d1d6efa0109d2f65ff4c85cddd50bd572e5a00127ab10987290bcefae" + +[[package]] +name = "lock_api" +version = "0.4.14" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "224399e74b87b5f3557511d98dff8b14089b3dadafcab6bb93eab67d3aace965" +dependencies = [ + "scopeguard", +] + +[[package]] +name = "log" +version = "0.4.35" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d15f86d12da44cd8d4ec3c73984537eb7f4cadcb9776a575a0a8a05ca11005c" + +[[package]] +name = "markup5ever" +version = "0.39.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7122d987ec5f704ee56f6e5b41a7d93722e9aae27ae07cafa4036c4d3f9757de" +dependencies = [ + "log", + "tendril", + "web_atoms 0.2.6", +] + +[[package]] +name = "markup5ever" +version = "0.40.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab3dc68ac4a0f5719e560136778c1ee716e296030d75dbd4484e37e39e3a842" +dependencies = [ + "log", + "tendril", + "web_atoms 0.3.0", +] + +[[package]] +name = "memchr" +version = "2.8.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf8baf1c55e62ffcace7a9f06f4bd9cd3f0c4beb022d3b367256b91b87513d98" + +[[package]] +name = "memoffset" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a" +dependencies = [ + "autocfg", +] + +[[package]] +name = "mime" +version = "0.3.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5848f5a9e8117cf94f2f90faac24a87ff81600ff8628c1e3deaab572e76bfa1" + +[[package]] +name = "miniz_oxide" +version = "0.8.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fa76a2c86f704bdb222d66965fb3d63269ce38518b83cb0575fca855ebb6316" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "miniz_oxide" +version = "0.9.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b63fbc4a50860e98e7b2aa7804ded1db5cbc3aff9193adaff57a6931bf7c4b4c" +dependencies = [ + "adler2", + "simd-adler32", +] + +[[package]] +name = "mio" +version = "1.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20521a903f02b0a573cd6840e9d0a5a0cc043d361fe924092cd70f8556cc9c4a" +dependencies = [ + "libc", + "wasi", + "windows-sys 0.61.2", +] + +[[package]] +name = "muda" +version = "0.20.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cca139e57da4383727f189e43e66e84fa372347027fc996f9f1a007ec0a37996" +dependencies = [ + "crossbeam-channel", + "dpi", + "gtk", + "keyboard-types", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "once_cell", + "png", + "serde", + "thiserror 2.0.21", + "windows-sys 0.61.2", +] + +[[package]] +name = "ndk" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3f42e7bbe13d351b6bead8286a43aac9534b82bd3cc43e47037f012ebfd62d4" +dependencies = [ + "bitflags 2.13.2", + "jni-sys 0.3.1", + "log", + "ndk-sys", + "num_enum", + "raw-window-handle", + "thiserror 1.0.69", +] + +[[package]] +name = "ndk-context" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "27b02d87554356db9e9a873add8782d4ea6e3e58ea071a9adb9a2e8ddb884a8b" + +[[package]] +name = "ndk-sys" +version = "0.6.0+11769913" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ee6cda3051665f1fb8d9e08fc35c96d5a244fb1be711a03b71118828afc9a873" +dependencies = [ + "jni-sys 0.3.1", +] + +[[package]] +name = "new_debug_unreachable" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "650eef8c711430f1a879fdd01d4745a7deea475becfb90269c06775983bbf086" + +[[package]] +name = "num-conv" +version = "0.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521739c6d2bac4aa25192232afe6841231376b2b26d4d9fae5ecf8ca5772e441" + +[[package]] +name = "num-traits" +version = "0.2.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841" +dependencies = [ + "autocfg", +] + +[[package]] +name = "num_enum" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0bca838442ec211fa11de3a8b0e0e8f3a4522575b5c4c06ed722e005036f26" +dependencies = [ + "num_enum_derive", + "rustversion", +] + +[[package]] +name = "num_enum_derive" +version = "0.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "680998035259dcfcafe653688bf2aa6d3e2dc05e98be6ab46afb089dc84f1df8" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "objc2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "08849bbd4767dfae9457696856ae1c84fe4e0281bbe4a7abff2d0e06fb7981f8" +dependencies = [ + "objc2-encode", + "objc2-exception-helper", +] + +[[package]] +name = "objc2-app-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d49e936b501e5c5bf01fda3a9452ff86dc3ea98ad5f283e1455153142d97518c" +dependencies = [ + "bitflags 2.13.2", + "block2", + "objc2", + "objc2-core-foundation", + "objc2-foundation", + "objc2-quartz-core", +] + +[[package]] +name = "objc2-cloud-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73ad74d880bb43877038da939b7427bba67e9dd42004a18b809ba7d87cee241c" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-data" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b402a653efbb5e82ce4df10683b6b28027616a2715e90009947d50b8dd298fa" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2a180dd8642fa45cdb7dd721cd4c11b1cadd4929ce112ebd8b9f5803cc79d536" +dependencies = [ + "bitflags 2.13.2", + "dispatch2", + "objc2", +] + +[[package]] +name = "objc2-core-graphics" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e022c9d066895efa1345f8e33e584b9f958da2fd4cd116792e15e07e4720a807" +dependencies = [ + "bitflags 2.13.2", + "dispatch2", + "objc2", + "objc2-core-foundation", + "objc2-io-surface", +] + +[[package]] +name = "objc2-core-image" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5d563b38d2b97209f8e861173de434bd0214cf020e3423a52624cd1d989f006" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-location" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ca347214e24bc973fc025fd0d36ebb179ff30536ed1f80252706db19ee452009" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-core-text" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0cde0dfb48d25d2b4862161a4d5fcc0e3c24367869ad306b0c9ec0073bfed92d" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", + "objc2-core-graphics", +] + +[[package]] +name = "objc2-encode" +version = "4.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef25abbcd74fb2609453eb695bd2f860d389e457f67dc17cafc8b8cbc89d0c33" + +[[package]] +name = "objc2-exception-helper" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c7a1c5fbb72d7735b076bb47b578523aedc40f3c439bea6dfd595c089d79d98a" +dependencies = [ + "cc", +] + +[[package]] +name = "objc2-foundation" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3e0adef53c21f888deb4fa59fc59f7eb17404926ee8a6f59f5df0fd7f9f3272" +dependencies = [ + "bitflags 2.13.2", + "block2", + "libc", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-io-surface" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "180788110936d59bab6bd83b6060ffdfffb3b922ba1396b312ae795e1de9d81d" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", +] + +[[package]] +name = "objc2-quartz-core" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "96c1358452b371bf9f104e21ec536d37a650eb10f7ee379fff67d2e08d537f1f" +dependencies = [ + "bitflags 2.13.2", + "objc2", + "objc2-core-foundation", + "objc2-foundation", +] + +[[package]] +name = "objc2-ui-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d87d638e33c06f577498cbcc50491496a3ed4246998a7fbba7ccb98b1e7eab22" +dependencies = [ + "bitflags 2.13.2", + "block2", + "objc2", + "objc2-cloud-kit", + "objc2-core-data", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-core-image", + "objc2-core-location", + "objc2-core-text", + "objc2-foundation", + "objc2-quartz-core", + "objc2-user-notifications", +] + +[[package]] +name = "objc2-user-notifications" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9df9128cbbfef73cda168416ccf7f837b62737d748333bfe9ab71c245d76613e" +dependencies = [ + "objc2", + "objc2-foundation", +] + +[[package]] +name = "objc2-web-kit" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2e5aaab980c433cf470df9d7af96a7b46a9d892d521a2cbbb2f8a4c16751e7f" +dependencies = [ + "bitflags 2.13.2", + "block2", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", +] + +[[package]] +name = "once_cell" +version = "1.21.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50" + +[[package]] +name = "option-ext" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d" + +[[package]] +name = "ordered-stream" +version = "0.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aa2b01e1d916879f73a53d01d1d6cee68adbb31d6d9177a8cfce093cced1d50" +dependencies = [ + "futures-core", + "pin-project-lite", +] + +[[package]] +name = "pango" +version = "0.18.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ca27ec1eb0457ab26f3036ea52229edbdb74dee1edd29063f5b9b010e7ebee4" +dependencies = [ + "gio", + "glib", + "libc", + "once_cell", + "pango-sys", +] + +[[package]] +name = "pango-sys" +version = "0.18.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "436737e391a843e5933d6d9aa102cb126d501e815b83601365a948a518555dc5" +dependencies = [ + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "parking" +version = "2.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba" + +[[package]] +name = "parking_lot" +version = "0.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93857453250e3077bd71ff98b6a65ea6621a19bb0f559a85248955ac12c45a1a" +dependencies = [ + "lock_api", + "parking_lot_core", +] + +[[package]] +name = "parking_lot_core" +version = "0.9.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2621685985a2ebf1c516881c026032ac7deafcda1a2c9b7850dc81e3dfcb64c1" +dependencies = [ + "cfg-if", + "libc", + "redox_syscall", + "smallvec", + "windows-link", +] + +[[package]] +name = "percent-encoding" +version = "2.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9b4f627cb1b25917193a259e49bdad08f671f8d9708acfd5fe0a8c1455d87220" + +[[package]] +name = "phf" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c1562dc717473dbaa4c1f85a36410e03c047b2e7df7f45ee938fbef64ae7fadf" +dependencies = [ + "phf_macros 0.13.1", + "phf_shared 0.13.1", + "serde", +] + +[[package]] +name = "phf" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "010378780309880b08997fae13be7834dba947d36393bd372f2b1556deb2a2f6" +dependencies = [ + "phf_macros 0.14.0", + "phf_shared 0.14.0", + "serde", +] + +[[package]] +name = "phf_codegen" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "49aa7f9d80421bca176ca8dbfebe668cc7a2684708594ec9f3c0db0805d5d6e1" +dependencies = [ + "phf_generator 0.13.1", + "phf_shared 0.13.1", +] + +[[package]] +name = "phf_codegen" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b585a510fb76fdebead6897982ef2a03a21d8e6cbcca904999742a4afc6ffe" +dependencies = [ + "phf_generator 0.14.0", + "phf_shared 0.14.0", +] + +[[package]] +name = "phf_generator" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "135ace3a761e564ec88c03a77317a7c6b80bb7f7135ef2544dbe054243b89737" +dependencies = [ + "fastrand", + "phf_shared 0.13.1", +] + +[[package]] +name = "phf_generator" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aeb62e0959d5a1bebc965f4d15d9e2b7cea002b6b0f5ba8cde6cc26738467100" +dependencies = [ + "fastrand", + "phf_shared 0.14.0", +] + +[[package]] +name = "phf_macros" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812f032b54b1e759ccd5f8b6677695d5268c588701effba24601f6932f8269ef" +dependencies = [ + "phf_generator 0.13.1", + "phf_shared 0.13.1", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "phf_macros" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fa8d0ca26d424d27630da600c6624696e7dec8bf7b3b492b383c5dc49e5e085" +dependencies = [ + "phf_generator 0.14.0", + "phf_shared 0.14.0", + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "phf_shared" +version = "0.13.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e57fef6bc5981e38c2ce2d63bfa546861309f875b8a75f092d1d54ae2d64f266" +dependencies = [ + "siphasher", +] + +[[package]] +name = "phf_shared" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6fd9027e2d9319be6349febd1db4e8d02aa544921200c9b777720ac34a3aa89" +dependencies = [ + "siphasher", +] + +[[package]] +name = "pin-project-lite" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a89322df9ebe1c1578d689c92318e070967d1042b512afbe49518723f4e6d5cd" + +[[package]] +name = "piper" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c835479a4443ded371d6c535cbfd8d31ad92c5d23ae9770a61bc155e4992a3c1" +dependencies = [ + "atomic-waker", + "fastrand", + "futures-io", +] + +[[package]] +name = "pkg-config" +version = "0.3.34" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f6b464fbc74e149a392436b17d523f769e057cb6877f6a5c4618bc6f11800548" + +[[package]] +name = "plist" +version = "1.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d86a77b7d9cdebd9643c180c158748db7d894b24a3935ed4b5843e698ae086eb" +dependencies = [ + "base64 0.23.1", + "indexmap 2.14.2", + "quick-xml", + "serde", + "time", +] + +[[package]] +name = "png" +version = "0.18.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60769b8b31b2a9f263dae2776c37b1b28ae246943cf719eb6946a1db05128a61" +dependencies = [ + "bitflags 2.13.2", + "crc32fast", + "fdeflate", + "flate2", + "miniz_oxide 0.8.9", +] + +[[package]] +name = "polling" +version = "3.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d0e4f59085d47d8241c88ead0f274e8a0cb551f3625263c05eb8dd897c34218" +dependencies = [ + "cfg-if", + "concurrent-queue", + "hermit-abi", + "pin-project-lite", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "portable-atomic" +version = "1.15.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "05c8b63e8d9609db387f0324918f81d68fe27748f084ef092fb35954d0539a85" + +[[package]] +name = "portable-atomic-util" +version = "0.2.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "10ab3eb7f3becc3a1cbc4f2c6f20267996cfc1a6467a873763411b136a122715" +dependencies = [ + "portable-atomic", +] + +[[package]] +name = "potential_utf" +version = "0.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d83eb9bc6d8e5cf568e7a1101d60ee05e81ed50ea106026f3d18deeb046d7661" +dependencies = [ + "zerovec", +] + +[[package]] +name = "powerfmt" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a6394b9e965e73d0a289ee54f589087e2c676aedf60885baf52c76b771e4958" + +[[package]] +name = "precomputed-hash" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "925383efa346730478fb4838dbe9137d2a47675ad789c546d150a6e1dd4ab31c" + +[[package]] +name = "proc-macro-crate" +version = "1.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f4c021e1093a56626774e81216a4ce732a735e5bad4868a03f3ed65ca0c3919" +dependencies = [ + "once_cell", + "toml_edit 0.19.15", +] + +[[package]] +name = "proc-macro-crate" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b00f26d3400549137f92511a46ac1cd8ce37cb5598a96d382381458b992a5d24" +dependencies = [ + "toml_datetime 0.6.3", + "toml_edit 0.20.2", +] + +[[package]] +name = "proc-macro-crate" +version = "3.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e67ba7e9b2b56446f1d419b1d807906278ffa1a658a8a5d8a39dcb1f5a78614f" +dependencies = [ + "toml_edit 0.25.19+spec-1.1.0", +] + +[[package]] +name = "proc-macro-error" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "da25490ff9892aab3fcf7c36f08cfb902dd3e71ca0f9f9517bea02a73a5ce38c" +dependencies = [ + "proc-macro-error-attr", + "proc-macro2", + "quote", + "syn 1.0.109", + "version_check", +] + +[[package]] +name = "proc-macro-error-attr" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1be40180e52ecc98ad80b184934baf3d0d29f979574e439af5a55274b35f869" +dependencies = [ + "proc-macro2", + "quote", + "version_check", +] + +[[package]] +name = "proc-macro2" +version = "1.0.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "quick-xml" +version = "0.42.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41b1177fdf999d2321d3fb46ff47159d9c1fb9ad66a4879f8c50a0b504615e9b" +dependencies = [ + "memchr", +] + +[[package]] +name = "quote" +version = "1.0.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001" +dependencies = [ + "proc-macro2", +] + +[[package]] +name = "r-efi" +version = "5.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "69cdb34c158ceb288df11e18b4bd39de994f6657d83847bdffdbd7f346754b0f" + +[[package]] +name = "r-efi" +version = "6.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf" + +[[package]] +name = "raw-window-handle" +version = "0.6.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20675572f6f24e9e76ef639bc5552774ed45f1c30e2951e1e99c59888861c539" + +[[package]] +name = "redox_syscall" +version = "0.5.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ed2bf2547551a7053d6fdfafda3f938979645c44812fbfcda098faae3f1a362d" +dependencies = [ + "bitflags 2.13.2", +] + +[[package]] +name = "redox_users" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60dc65c0ff1a7ae1294b0c67b9f14baf70b644404010370171787bfac1038fc0" +dependencies = [ + "libredox", + "thiserror 2.0.21", +] + +[[package]] +name = "ref-cast" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e440fb4e4b4147295338efb76001ab9e4efc0e5839df2c47fc5ac2381d365c3" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "92ecd8964f8453721699a1ed72037b0db49ce2f5a5138486ee89bed6f67cdf3a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "regex" +version = "1.13.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9807af0e638c12e753aa1b4e601791bf2a8f71274023c8bbeec12fc149950857" +dependencies = [ + "aho-corasick", + "memchr", + "regex-automata", + "regex-syntax", +] + +[[package]] +name = "regex-automata" +version = "0.4.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "41d60ef07df457506a0a1a2073112eb4aae5733dbd2813c3da77d1b0fd441158" +dependencies = [ + "aho-corasick", + "memchr", + "regex-syntax", +] + +[[package]] +name = "regex-syntax" +version = "0.8.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d902046e6a28a1e4c3cab97258a0ce11e994903f01c2d97a9447a0b3df85f4f6" + +[[package]] +name = "reqwest" +version = "0.13.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "16a1cfa75cc186dd73d5818e510e042e40927bccc9c236b061cea97e1eb08029" +dependencies = [ + "base64 0.23.1", + "bytes", + "futures-core", + "futures-util", + "http", + "http-body", + "http-body-util", + "hyper", + "hyper-util", + "js-sys", + "log", + "percent-encoding", + "pin-project-lite", + "serde", + "serde_json", + "sync_wrapper", + "tokio", + "tokio-util", + "tower", + "tower-http", + "tower-service", + "url", + "wasm-bindgen", + "wasm-bindgen-futures", + "wasm-streams", + "web-sys", +] + +[[package]] +name = "rfd" +version = "0.17.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "20dafead71c16a34e1ff357ddefc8afc11e7d51d6d2b9fbd07eaa48e3e540220" +dependencies = [ + "block2", + "dispatch2", + "glib-sys", + "gobject-sys", + "gtk-sys", + "js-sys", + "libc", + "log", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "percent-encoding", + "raw-window-handle", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustc-hash" +version = "2.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6b1e7f9a428571be2dc5bc0505c13fb6bf936822b894ec87abf8a08a4e51742d" + +[[package]] +name = "rustc_version" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cfcb3a22ef46e85b45de6ee7e79d063319ebb6594faafcf1c225ea92ab6e9b92" +dependencies = [ + "semver", +] + +[[package]] +name = "rustix" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e5e76742e5294153d4dde1207dbec5bdd81eef6fabdc0d2118babadabfd858aa" +dependencies = [ + "bitflags 2.13.2", + "errno", + "libc", + "linux-raw-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "rustversion" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f" + +[[package]] +name = "same-file" +version = "1.0.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502" +dependencies = [ + "winapi-util", +] + +[[package]] +name = "schemars" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" +dependencies = [ + "dyn-clone", + "indexmap 1.9.3", + "schemars_derive", + "serde", + "serde_json", + "url", + "uuid", +] + +[[package]] +name = "schemars" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cd191f9397d57d581cddd31014772520aa448f65ef991055d7f61582c65165f" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars" +version = "1.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ab508826f74a77ca9d5aba6ff19b522583ee3eaf28a19384ff3d0e5835fadf6e" +dependencies = [ + "dyn-clone", + "ref-cast", + "serde", + "serde_json", +] + +[[package]] +name = "schemars_derive" +version = "0.8.22" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" +dependencies = [ + "proc-macro2", + "quote", + "serde_derive_internals", + "syn 2.0.119", +] + +[[package]] +name = "scopeguard" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" + +[[package]] +name = "selectors" +version = "0.38.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8adfa1c298912827b8a28b223b3b874357397ae706e6190acd9bf28cee99114d" +dependencies = [ + "bitflags 2.13.2", + "cssparser 0.37.0", + "derive_more", + "log", + "new_debug_unreachable", + "phf 0.13.1", + "phf_codegen 0.13.1", + "precomputed-hash", + "rustc-hash", + "servo_arc 0.4.3", + "smallvec", +] + +[[package]] +name = "selectors" +version = "0.41.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8322aebea94a6cc288ff884e8a49bdbceef60206c400c6c46d22e62fc4fd91a6" +dependencies = [ + "bitflags 2.13.2", + "cssparser 0.38.0", + "derive_more", + "log", + "new_debug_unreachable", + "precomputed-hash", + "rustc-hash", + "servo_arc 0.5.0", + "smallvec", +] + +[[package]] +name = "semver" +version = "1.0.28" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8a7852d02fc848982e0c167ef163aaff9cd91dc640ba85e263cb1ce46fae51cd" +dependencies = [ + "serde", + "serde_core", +] + +[[package]] +name = "serde" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4148590afebada386688f18773da617792bf2ef03ffc1e4cbd2b1d45b023e0ba" +dependencies = [ + "serde_core", + "serde_derive", +] + +[[package]] +name = "serde-untagged" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f9faf48a4a2d2693be24c6289dbe26552776eb7737074e6722891fadbe6c5058" +dependencies = [ + "erased-serde", + "serde", + "serde_core", + "typeid", +] + +[[package]] +name = "serde_core" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67dca2c9c51e58a4791a4b1ed58308b39c64224d349a935ab5039aa360942a48" +dependencies = [ + "serde_derive", +] + +[[package]] +name = "serde_derive" +version = "1.0.229" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7a5d71263a5a7d47b41f6b3f06ba276f10cc18b0931f1799f710578e2309348" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_derive_internals" +version = "0.29.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "18d26a20a969b9e3fdf2fc2d9f21eda6c40e2de84c9408bb5d3b05d499aae711" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "serde_json" +version = "1.0.154" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e7e9cc8b1b85264074fbcc02a88680c4096b1e47df8f739dceb03bf482f04bd6" +dependencies = [ + "itoa", + "memchr", + "serde", + "serde_core", + "zmij", +] + +[[package]] +name = "serde_repr" +version = "0.1.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8d3b1629de253c70a0508c3899572da79ca359fdab27c7920ff00406df418906" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serde_spanned" +version = "0.6.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bf41e0cfaf7226dca15e8197172c295a782857fcb97fad1808a166870dee75a3" +dependencies = [ + "serde", +] + +[[package]] +name = "serde_spanned" +version = "1.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c187e0a369471c550af028cba56d4f4fa2a489ad28151ae95a4d340a2a8b782" +dependencies = [ + "serde_core", +] + +[[package]] +name = "serde_with" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df9adc193c780ef8f159aee8b61e2d5801aaa555e6eb0947fe45530ec506296f" +dependencies = [ + "base64 0.23.1", + "bs58", + "chrono", + "hex", + "indexmap 1.9.3", + "indexmap 2.14.2", + "jiff", + "schemars 0.9.0", + "schemars 1.2.3", + "serde_core", + "serde_json", + "serde_with_macros", + "time", +] + +[[package]] +name = "serde_with_macros" +version = "3.24.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3e17bbc68e28663bbbb90df47e058aa7eda4fb445b89fe70457bb94fbccf6e49" +dependencies = [ + "darling", + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "serialize-to-javascript" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "04f3666a07a197cdb77cdf306c32be9b7f598d7060d50cfd4d5aa04bfd92f6c5" +dependencies = [ + "serde", + "serde_json", + "serialize-to-javascript-impl", +] + +[[package]] +name = "serialize-to-javascript-impl" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "772ee033c0916d670af7860b6e1ef7d658a4629a6d0b4c8c3e67f09b3765b75d" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "servo_arc" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "170fb83ab34de17dc69aa7c67482b22218ddb85da56546f9bd6b929e32a05930" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "servo_arc" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b4eceb519ec34d8290aaf6e46f435102f2bfa63f22b05a144fb16ab266d3b198" +dependencies = [ + "stable_deref_trait", +] + +[[package]] +name = "sha2" +version = "0.10.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a7507d819769d01a365ab707794a4084392c824f54a7a6a7862f8c3d0892b283" +dependencies = [ + "cfg-if", + "cpufeatures 0.2.17", + "digest 0.10.7", +] + +[[package]] +name = "sha2" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "47d7069beb7d6ac7b9acd1039986e73443f24234f41074da099d6f994ac9ad19" +dependencies = [ + "cfg-if", + "cpufeatures 0.3.1", + "digest 0.11.3", +] + +[[package]] +name = "shlex" +version = "2.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f8fadd59c855ef2080decdef8ff161eb6661b86933c9d82e5ba29dc602a55aba" + +[[package]] +name = "signal-hook-registry" +version = "1.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c4db69cba1110affc0e9f7bcd48bbf87b3f4fc7c61fc9155afd4c469eb3d6c1b" +dependencies = [ + "errno", + "libc", +] + +[[package]] +name = "simd-adler32" +version = "0.3.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a219298ac11a56ea9a6d2120044824d6f01aeb034955e7af7bc16858527deea" + +[[package]] +name = "siphasher" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "33f4fe9184a62d842c9ef383018f3306d8ba224fd9d836f56d7288308847c256" + +[[package]] +name = "slab" +version = "0.4.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0c790de23124f9ab44544d7ac05d60440adc586479ce501c1d6d7da3cd8c9cf5" + +[[package]] +name = "smallvec" +version = "1.16.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3244542535d5de959d90ec55d1b5ff0fd2bb7b1310223907d5f11932847f7b59" + +[[package]] +name = "socket2" +version = "0.6.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3d1e2c7f27f8d4cb10542a02c49005dbd6e93095799d6f3be745fae9f8fedd4" +dependencies = [ + "libc", + "windows-sys 0.61.2", +] + +[[package]] +name = "softbuffer" +version = "0.4.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "aac18da81ebbf05109ab275b157c22a653bb3c12cf884450179942f81bcbf6c3" +dependencies = [ + "bytemuck", + "js-sys", + "ndk", + "objc2", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-foundation", + "objc2-quartz-core", + "raw-window-handle", + "redox_syscall", + "tracing", + "wasm-bindgen", + "web-sys", + "windows-sys 0.61.2", +] + +[[package]] +name = "soup3" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "471f924a40f31251afc77450e781cb26d55c0b650842efafc9c6cbd2f7cc4f9f" +dependencies = [ + "futures-channel", + "gio", + "glib", + "libc", + "soup3-sys", +] + +[[package]] +name = "soup3-sys" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7ebe8950a680a12f24f15ebe1bf70db7af98ad242d9db43596ad3108aab86c27" +dependencies = [ + "gio-sys", + "glib-sys", + "gobject-sys", + "libc", + "system-deps", +] + +[[package]] +name = "stable_deref_trait" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6ce2be8dc25455e1f91df71bfa12ad37d7af1092ae736f3a6cd0e37bc7810596" + +[[package]] +name = "static_vcruntime" +version = "3.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff7589a1859b09232522bb9edf076ca7fcf14ded96685d3fa629db73023ffbb7" + +[[package]] +name = "string_cache" +version = "0.9.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a18596f8c785a729f2819c0f6a7eae6ebeebdfffbfe4214ae6b087f690e31901" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared 0.13.1", + "precomputed-hash", +] + +[[package]] +name = "string_cache" +version = "0.11.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ffa8a5dbe8b3f0bbe29d4c3225daafaeead63afdc1b65fc4c01a1384166038e6" +dependencies = [ + "new_debug_unreachable", + "parking_lot", + "phf_shared 0.14.0", + "precomputed-hash", +] + +[[package]] +name = "string_cache_codegen" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "585635e46db231059f76c5849798146164652513eb9e8ab2685939dd90f29b69" +dependencies = [ + "phf_generator 0.13.1", + "phf_shared 0.13.1", + "proc-macro2", + "quote", +] + +[[package]] +name = "string_cache_codegen" +version = "0.11.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "928dcdf75e47626b3617a976ec205d9f057584c371c1f23b782129268d0e6edc" +dependencies = [ + "phf_generator 0.14.0", + "phf_shared 0.14.0", + "proc-macro2", + "quote", +] + +[[package]] +name = "strsim" +version = "0.11.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7da8b5736845d9f2fcb837ea5d9e2628564b3b043a70948a3f0b778838c5fb4f" + +[[package]] +name = "swift-rs" +version = "1.0.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cefd87076fd385308ee4aff597256c902f1fbb4d031de1558efc12f8ffefadd9" +dependencies = [ + "base64 0.21.7", + "serde", + "serde_json", +] + +[[package]] +name = "syn" +version = "1.0.109" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "72b64191b275b66ffe2469e8af2c1cfe3bafa67b529ead792a6d0160888b4237" +dependencies = [ + "proc-macro2", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "2.0.119" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "872831b642d1a07999a962a351ed35b955ea2cfc8f3862091e2a240a84f17297" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "syn" +version = "3.0.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ae9ccbea3a7b0b09443036490c8f34a8b1b760fd345e5c0dae0aac718faea79" +dependencies = [ + "proc-macro2", + "quote", + "unicode-ident", +] + +[[package]] +name = "sync_wrapper" +version = "1.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0bf256ce5efdfa370213c1dabab5935a12e49f2c58d15e9eac2870d3b4f27263" +dependencies = [ + "futures-core", +] + +[[package]] +name = "synstructure" +version = "0.14.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "901704edd0dfe137f1987838ee4f259e4e063c31371bdb423f7ae38ec6f77f02" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "system-deps" +version = "6.2.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a3e535eb8dded36d55ec13eddacd30dec501792ff23a0b1682c38601b8cf2349" +dependencies = [ + "cfg-expr", + "heck 0.5.0", + "pkg-config", + "toml 0.8.2", + "version-compare", +] + +[[package]] +name = "tao" +version = "0.37.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "02ca9c0ce2a2fd70dc4ef4449ca5e8d30e6fa0db111cd8008594602a06a68371" +dependencies = [ + "bitflags 2.13.2", + "block2", + "core-foundation", + "core-graphics", + "crossbeam-channel", + "dbus", + "dispatch2", + "dlopen2", + "dpi", + "gdkwayland-sys", + "gdkx11-sys", + "gtk", + "jni", + "libc", + "log", + "ndk", + "ndk-context", + "ndk-sys", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-ui-kit", + "parking_lot", + "percent-encoding", + "raw-window-handle", + "tao-macros", + "unicode-segmentation", + "url", + "windows", + "windows-core", + "windows-version", + "x11-dl", +] + +[[package]] +name = "tao-macros" +version = "0.1.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5f7eeb6d99155545da6150a1795945f16ac9c178deb2a5f2e74d776107bd5849" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "target-lexicon" +version = "0.12.16" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1" + +[[package]] +name = "tauri" +version = "2.12.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "30fbfbb9dc9a2697b0e96d909ddc295fb18d2d82a58ed542ab8d9eba2edbe6da" +dependencies = [ + "anyhow", + "bytes", + "cookie", + "dirs", + "dunce", + "embed_plist", + "getrandom 0.3.4", + "glob", + "gtk", + "heck 0.5.0", + "http", + "jni", + "libc", + "log", + "mime", + "muda", + "objc2", + "objc2-app-kit", + "objc2-foundation", + "objc2-ui-kit", + "objc2-web-kit", + "percent-encoding", + "plist", + "raw-window-handle", + "reqwest", + "serde", + "serde_json", + "serde_repr", + "serialize-to-javascript", + "swift-rs", + "tauri-build", + "tauri-macros", + "tauri-runtime", + "tauri-runtime-wry", + "tauri-utils", + "thiserror 2.0.21", + "tokio", + "tray-icon", + "url", + "webkit2gtk", + "webview2-com", + "window-vibrancy", + "windows", +] + +[[package]] +name = "tauri-build" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "73d80784e874fa117b9b00a6680cf2f9b8a51bbd14406bea980cf8f328b00646" +dependencies = [ + "anyhow", + "cargo_toml", + "dirs", + "glob", + "heck 0.5.0", + "json-patch", + "schemars 0.8.22", + "semver", + "serde", + "serde_json", + "static_vcruntime", + "strsim", + "tauri-utils", + "tauri-winres", + "walkdir", +] + +[[package]] +name = "tauri-codegen" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c5dc6caab4da5646f57648f39b794bae118f0dd4a4305eeb8c892966171f4852" +dependencies = [ + "base64 0.23.1", + "brotli", + "ico", + "json-patch", + "plist", + "png", + "proc-macro2", + "quote", + "semver", + "serde", + "serde_json", + "sha2 0.11.1", + "syn 2.0.119", + "tauri-utils", + "thiserror 2.0.21", + "time", + "url", + "uuid", + "walkdir", +] + +[[package]] +name = "tauri-macros" +version = "2.7.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2831c5da8603a96b1efc0b650c2cb6decc69b6cda257d815fe70c7f5be53818e" +dependencies = [ + "heck 0.5.0", + "proc-macro2", + "quote", + "syn 2.0.119", + "tauri-codegen", + "tauri-utils", +] + +[[package]] +name = "tauri-plugin" +version = "2.7.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c18076d9b04211cb4899387aab97497e8edd0d02cd21710623afcdde27145d1" +dependencies = [ + "anyhow", + "glob", + "plist", + "schemars 0.8.22", + "serde", + "serde_json", + "tauri-utils", + "walkdir", +] + +[[package]] +name = "tauri-plugin-dialog" +version = "2.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ce0fb9c2b6d34a9720627ed930ebc8af26f61e648695aecaeb03d5c33c5896f5" +dependencies = [ + "log", + "raw-window-handle", + "rfd", + "serde", + "serde_json", + "tauri", + "tauri-plugin", + "tauri-plugin-fs", + "thiserror 2.0.21", + "url", +] + +[[package]] +name = "tauri-plugin-fs" +version = "2.7.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5d58eb1d4984e535f47a642ffec09a2da6f5c18a12b5902d12126cb7626d628b" +dependencies = [ + "anyhow", + "dunce", + "glob", + "log", + "objc2-foundation", + "percent-encoding", + "schemars 0.8.22", + "serde", + "serde_json", + "serde_repr", + "tauri", + "tauri-plugin", + "tauri-utils", + "thiserror 2.0.21", + "toml 1.2.1+spec-1.1.0", + "url", +] + +[[package]] +name = "tauri-plugin-single-instance" +version = "2.5.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "726b6da0dd5bd1344f84f4108a622c07d01923baacb5c803a605189672c5352f" +dependencies = [ + "serde", + "serde_json", + "tauri", + "thiserror 2.0.21", + "tokio", + "tracing", + "windows-sys 0.61.2", + "zbus", +] + +[[package]] +name = "tauri-runtime" +version = "2.12.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "60c2b14bd5265b63993cdc34ad526fb836e0fd0cf64a4634a895db0784844d5e" +dependencies = [ + "cookie", + "dpi", + "gtk", + "http", + "jni", + "objc2", + "objc2-ui-kit", + "objc2-web-kit", + "raw-window-handle", + "serde", + "serde_json", + "tauri-utils", + "thiserror 2.0.21", + "url", + "webkit2gtk", + "webview2-com", + "windows", +] + +[[package]] +name = "tauri-runtime-wry" +version = "2.12.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8c14a025255cc9816d401635035075b09b6cc9973b7b8fd7b8fcb8753f30f92" +dependencies = [ + "gtk", + "http", + "jni", + "log", + "objc2", + "objc2-app-kit", + "percent-encoding", + "raw-window-handle", + "softbuffer", + "tao", + "tauri-runtime", + "tauri-utils", + "url", + "webkit2gtk", + "webview2-com", + "windows", + "wry", +] + +[[package]] +name = "tauri-utils" +version = "2.10.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28d1d33d4453c5df0bf1672dbc7ada69d8ed74f56a4316d964a4aa73d4ecd3ad" +dependencies = [ + "anyhow", + "brotli", + "cargo_metadata", + "ctor", + "dom_query 0.28.0", + "dunce", + "glob", + "http", + "infer", + "json-patch", + "log", + "memchr", + "phf 0.13.1", + "plist", + "proc-macro2", + "quote", + "regex", + "schemars 0.8.22", + "semver", + "serde", + "serde-untagged", + "serde_json", + "serde_with", + "swift-rs", + "thiserror 2.0.21", + "toml 1.2.1+spec-1.1.0", + "url", + "urlpattern", + "uuid", + "walkdir", +] + +[[package]] +name = "tauri-winres" +version = "0.3.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c52bb6904475a6ca662f15ef787f18ade61d5740a1ee12c45d3b748efdb6f796" +dependencies = [ + "dunce", + "embed-resource", + "toml 1.2.1+spec-1.1.0", +] + +[[package]] +name = "tempfile" +version = "3.27.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32497e9a4c7b38532efcdebeef879707aa9f794296a4f0244f6f69e9bc8574bd" +dependencies = [ + "fastrand", + "getrandom 0.4.3", + "once_cell", + "rustix", + "windows-sys 0.61.2", +] + +[[package]] +name = "tendril" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fed54709c5b3a53d09bb1c113ea4f5ceafd1e772ddcb0030a82e1d56c087b08" +dependencies = [ + "new_debug_unreachable", +] + +[[package]] +name = "thiserror" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6aaf5339b578ea85b50e080feb250a3e8ae8cfcdff9a461c9ec2904bc923f52" +dependencies = [ + "thiserror-impl 1.0.69", +] + +[[package]] +name = "thiserror" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "09e52cb86a36cede5cb101bf8908837b3e4c6e5e59fe7fd85c23fb56200d189e" +dependencies = [ + "thiserror-impl 2.0.21", +] + +[[package]] +name = "thiserror-impl" +version = "1.0.69" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4fee6c4efc90059e10f81e6d42c60a18f76588c3d74cb83a0b242a2b6c7504c1" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "thiserror-impl" +version = "2.0.21" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fe5197923287db20a58125f0bc85c062f7f2c892de97b18c356f9efb14b28524" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "time" +version = "0.3.55" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "cdb87b95ec50ddfa440816d227a17b2ccbdda963a316a727fda0fc4334f7d134" +dependencies = [ + "deranged", + "num-conv", + "powerfmt", + "serde_core", + "time-core", + "time-macros", +] + +[[package]] +name = "time-core" +version = "0.1.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9e1c906769ad99c88eaa54e728060edef082f8e358ff32030cb7c7d315e81109" + +[[package]] +name = "time-macros" +version = "0.2.32" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7e689342a48d2ea927c87ea50cabf8594854bf940e9310208848d680d668ed85" +dependencies = [ + "num-conv", + "time-core", +] + +[[package]] +name = "tinystr" +version = "0.8.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "abc840c238154d58f9e86b2792261edfde565a17696e1cda1a449de27979801a" +dependencies = [ + "displaydoc", + "zerovec", +] + +[[package]] +name = "tinyvec" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fd3ca314f692efd6c868f8408f53fe444634a845f96c028b97d35f6a1f79f0ee" + +[[package]] +name = "tokio" +version = "1.54.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b52fd3255258d26fac7264ab5a76b53c13367136dc011d3d6ad4f8ed070396a3" +dependencies = [ + "bytes", + "libc", + "mio", + "pin-project-lite", + "socket2", + "windows-sys 0.61.2", +] + +[[package]] +name = "tokio-util" +version = "0.7.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e464cf451ba96ebfc6f9b6542f17ee8b8956e33f1e40d9690624e59d7a7f8a4b" +dependencies = [ + "bytes", + "futures-core", + "futures-sink", + "pin-project-lite", + "tokio", +] + +[[package]] +name = "toml" +version = "0.8.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "185d8ab0dfbb35cf1399a6344d8484209c088f75f8f68230da55d48d95d43e3d" +dependencies = [ + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.3", + "toml_edit 0.20.2", +] + +[[package]] +name = "toml" +version = "1.2.1+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d5755c51863cdac711f1956baf8eb9588e060755f7d3c4c979e70ea1e1f32cd7" +dependencies = [ + "indexmap 2.14.2", + "serde_core", + "serde_spanned 1.1.3", + "toml_datetime 1.1.3+spec-1.1.0", + "toml_parser", + "toml_writer", + "winnow 1.0.5", +] + +[[package]] +name = "toml_datetime" +version = "0.6.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7cda73e2f1397b1262d6dfdcef8aafae14d1de7748d66822d3bfeeb6d03e5e4b" +dependencies = [ + "serde", +] + +[[package]] +name = "toml_datetime" +version = "1.1.3+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "173f25c883cd2176a2d8212155638c0a60d484a9d84546d270866f40f56b6e49" +dependencies = [ + "serde_core", +] + +[[package]] +name = "toml_edit" +version = "0.19.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1b5bb770da30e5cbfde35a2d7b9b8a2c4b8ef89548a7a6aeab5c9a576e3e7421" +dependencies = [ + "indexmap 2.14.2", + "toml_datetime 0.6.3", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.20.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "396e4d48bbb2b7554c944bde63101b5ae446cff6ec4a24227428f15eb72ef338" +dependencies = [ + "indexmap 2.14.2", + "serde", + "serde_spanned 0.6.9", + "toml_datetime 0.6.3", + "winnow 0.5.40", +] + +[[package]] +name = "toml_edit" +version = "0.25.19+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dd43688c4858d7264ae1cf9a9f874a67c3feb74a883b1cd7bebd6a4ea8307218" +dependencies = [ + "indexmap 2.14.2", + "toml_datetime 1.1.3+spec-1.1.0", + "toml_parser", + "winnow 1.0.5", +] + +[[package]] +name = "toml_parser" +version = "1.1.5+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c" +dependencies = [ + "winnow 1.0.5", +] + +[[package]] +name = "toml_writer" +version = "1.2.0+spec-1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "009dbb7700f11c55ef83aebbe4c0e9cf1f1ac0844bd8d6f00dc38f302026e13a" + +[[package]] +name = "tower" +version = "0.5.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ebe5ef63511595f1344e2d5cfa636d973292adc0eec1f0ad45fae9f0851ab1d4" +dependencies = [ + "futures-core", + "futures-util", + "pin-project-lite", + "sync_wrapper", + "tokio", + "tower-layer", + "tower-service", +] + +[[package]] +name = "tower-http" +version = "0.6.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4cfcf7e2740e6fc6d4d688b4ef00650406bb94adf4731e43c096c3a19fe40840" +dependencies = [ + "bitflags 2.13.2", + "bytes", + "futures-util", + "http", + "http-body", + "pin-project-lite", + "tower", + "tower-layer", + "tower-service", + "url", +] + +[[package]] +name = "tower-layer" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" + +[[package]] +name = "tower-service" +version = "0.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" + +[[package]] +name = "tracing" +version = "0.1.44" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "63e71662fa4b2a2c3a26f570f037eb95bb1f85397f3cd8076caed2f026a6d100" +dependencies = [ + "pin-project-lite", + "tracing-attributes", + "tracing-core", +] + +[[package]] +name = "tracing-attributes" +version = "0.1.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7490cfa5ec963746568740651ac6781f701c9c5ea257c58e057f3ba8cf69e8da" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "tracing-core" +version = "0.1.36" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "db97caf9d906fbde555dd62fa95ddba9eecfd14cb388e4f491a66d74cd5fb79a" +dependencies = [ + "once_cell", +] + +[[package]] +name = "tray-icon" +version = "0.25.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b2b9c52859a94554803ccd4a24b98f74148ebc73b90676d783f3490b1bff9d72" +dependencies = [ + "crossbeam-channel", + "dirs", + "libappindicator", + "muda", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-core-graphics", + "objc2-foundation", + "once_cell", + "png", + "serde", + "thiserror 2.0.21", + "windows-sys 0.61.2", +] + +[[package]] +name = "try-lock" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e421abadd41a4225275504ea4d6566923418b7f05506fbc9c0fe86ba7396114b" + +[[package]] +name = "typeid" +version = "1.0.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bc7d623258602320d5c55d1bc22793b57daff0ec7efc270ea7d55ce1d5f5471c" + +[[package]] +name = "typenum" +version = "1.20.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b6f5e870be6c3b371b77fe0ee0bafb859fa4964b4404c27de1d380043c4dda20" + +[[package]] +name = "uds_windows" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f2f6fb2847f6742cd76af783a2a2c49e9375d0a111c7bef6f71cd9e738c72d6e" +dependencies = [ + "memoffset", + "tempfile", + "windows-sys 0.61.2", +] + +[[package]] +name = "unicode-ident" +version = "1.0.27" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563" + +[[package]] +name = "unicode-segmentation" +version = "1.13.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c6f5d3c3b1bf09027a88a6bc961fc00497d651009560b5463668dc81b0fa87a8" + +[[package]] +name = "url" +version = "2.5.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ff67a8a4397373c3ef660812acab3268222035010ab8680ec4215f38ba3d0eed" +dependencies = [ + "form_urlencoded", + "idna", + "percent-encoding", + "serde", + "serde_derive", +] + +[[package]] +name = "urlpattern" +version = "0.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df16f50ef4cc145211879a3867ba757076b25dfee812040dcb0658bd9ae7904b" +dependencies = [ + "icu_properties", + "regex", + "serde", + "url", +] + +[[package]] +name = "utf8_iter" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "af3bd9d3e571c26fcce9d033b87ea5ab061b8d2ffe9b7a5675d810d68f03edf0" +dependencies = [ + "utf_types", +] + +[[package]] +name = "utf_types" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3a3b425286980a367278453f3b6d28cdcb134b574e5a35824a6ff5eebad50bb6" + +[[package]] +name = "uuid" +version = "1.29.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3c14b15dffa2f4bd712103e857140aa04a4f2ff6e955c77d7eb8e53ee02a3b64" +dependencies = [ + "getrandom 0.4.3", + "js-sys", + "serde_core", + "wasm-bindgen", +] + +[[package]] +name = "version-compare" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "03c2856837ef78f57382f06b2b8563a2f512f7185d732608fd9176cb3b8edf0e" + +[[package]] +name = "version_check" +version = "0.9.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0b928f33d975fc6ad9f86c8f283853ad26bdd5b10b7f1542aa2fa15e2289105a" + +[[package]] +name = "vswhom" +version = "0.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be979b7f07507105799e854203b470ff7c78a1639e330a58f183b5fea574608b" +dependencies = [ + "libc", + "vswhom-sys", +] + +[[package]] +name = "vswhom-sys" +version = "0.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "fb067e4cbd1ff067d1df46c9194b5de0e98efd2810bbc95c5d5e5f25a3231150" +dependencies = [ + "cc", + "libc", +] + +[[package]] +name = "walkdir" +version = "2.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29790946404f91d9c5d06f9874efddea1dc06c5efe94541a7d6863108e3a5e4b" +dependencies = [ + "same-file", + "winapi-util", +] + +[[package]] +name = "want" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec4cdd0dd910afe868b7ef477227d8d538b46b3075031afee8a9f2acb0a2ed0b" +dependencies = [ + "try-lock", +] + +[[package]] +name = "wasi" +version = "0.11.1+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b" + +[[package]] +name = "wasip2" +version = "1.0.4+wasi-0.2.12" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b67efb37e106e55ce722a510d6b5f9c17f083e5fc79afc2badeb12cc313d9487" +dependencies = [ + "wit-bindgen", +] + +[[package]] +name = "wasm-bindgen" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a0181c14ddd6c7b8b0b0132a5f1ea2f32be0d893cd3ea97b6e3b28886b8a3d1c" +dependencies = [ + "cfg-if", + "rustversion", + "wasm-bindgen-macro", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-futures" +version = "0.4.80" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5e14e0327cb5368ad60ccb22d04a9827a693c95a926d8d125e9fa39e0baec501" +dependencies = [ + "js-sys", + "tokio", + "wasm-bindgen", +] + +[[package]] +name = "wasm-bindgen-macro" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e931a02a39abdbf66966fc35902b5ed58344750a70885bed4ebb3d8eaf28ed9" +dependencies = [ + "quote", + "wasm-bindgen-macro-support", +] + +[[package]] +name = "wasm-bindgen-macro-support" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2ca4b54280e455bd831e33a6b8e734baf432fe63fbc35c42ac14ce67a043a53a" +dependencies = [ + "bumpalo", + "proc-macro2", + "quote", + "syn 3.0.10", + "wasm-bindgen-shared", +] + +[[package]] +name = "wasm-bindgen-shared" +version = "0.2.130" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3b1f9c3798725016c6ee5f2f57869ec0831e8bbc0ab0310a86e787e97f41389e" +dependencies = [ + "unicode-ident", +] + +[[package]] +name = "wasm-streams" +version = "0.5.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9d1ec4f6517c9e11ae630e200b2b65d193279042e28edd4a2cda233e46670bbb" +dependencies = [ + "futures-util", + "js-sys", + "wasm-bindgen", + "wasm-bindgen-futures", + "web-sys", +] + +[[package]] +name = "web-sys" +version = "0.3.107" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d7d179596ff5ec0f6de4db64d54011bde6289cc49603d3a6e4ce3f329207ab88" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web-time" +version = "1.1.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5a6580f308b1fad9207618087a65c04e7a10bc77e02c8e84e9b00dd4b12fa0bb" +dependencies = [ + "js-sys", + "wasm-bindgen", +] + +[[package]] +name = "web_atoms" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba8b815c1b593dc0baf78dd0f4fc8fdb2de53198fb1163738093e9a311c33fb3" +dependencies = [ + "phf 0.13.1", + "phf_codegen 0.13.1", + "string_cache 0.9.0", + "string_cache_codegen 0.6.1", +] + +[[package]] +name = "web_atoms" +version = "0.3.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7572660c8890448ba236b7376f27e389c6a7e1c70195622faced601f855c0ada" +dependencies = [ + "phf 0.14.0", + "phf_codegen 0.14.0", + "string_cache 0.11.0", + "string_cache_codegen 0.11.2", +] + +[[package]] +name = "webkit2gtk" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "a1027150013530fb2eaf806408df88461ae4815a45c541c8975e61d6f2fc4793" +dependencies = [ + "bitflags 1.3.2", + "cairo-rs", + "gdk", + "gdk-sys", + "gio", + "gio-sys", + "glib", + "glib-sys", + "gobject-sys", + "gtk", + "gtk-sys", + "javascriptcore-rs", + "libc", + "once_cell", + "soup3", + "webkit2gtk-sys", +] + +[[package]] +name = "webkit2gtk-sys" +version = "2.0.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "916a5f65c2ef0dfe12fff695960a2ec3d4565359fdbb2e9943c974e06c734ea5" +dependencies = [ + "bitflags 1.3.2", + "cairo-sys-rs", + "gdk-sys", + "gio-sys", + "glib-sys", + "gobject-sys", + "gtk-sys", + "javascriptcore-rs-sys", + "libc", + "pkg-config", + "soup3-sys", + "system-deps", +] + +[[package]] +name = "webview2-com" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f89fca7a704cee10dcb3654c1dbb8941d1783132f1917358af75bec37a7d7e6" +dependencies = [ + "webview2-com-macros", + "webview2-com-sys", + "windows", + "windows-core", +] + +[[package]] +name = "webview2-com-macros" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "67a921c1b6914c367b2b823cd4cde6f96beec77d30a939c8199bb377cf9b9b54" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "webview2-com-sys" +version = "0.39.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b3a07132775117d6065853d9d1178157b8c90e228de47129d6bce2c7edebedfb" +dependencies = [ + "thiserror 2.0.21", + "windows", + "windows-core", +] + +[[package]] +name = "winapi" +version = "0.3.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" +dependencies = [ + "winapi-i686-pc-windows-gnu", + "winapi-x86_64-pc-windows-gnu", +] + +[[package]] +name = "winapi-i686-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" + +[[package]] +name = "winapi-util" +version = "0.1.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c2a7b1c03c876122aa43f3020e6c3c3ee5c05081c9a00739faf7503aeba10d22" +dependencies = [ + "windows-sys 0.61.2", +] + +[[package]] +name = "winapi-x86_64-pc-windows-gnu" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" + +[[package]] +name = "window-vibrancy" +version = "0.8.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "111e51caca442cafd9bab396628ac4d814880eaea4e63dfd76a12e9f342b5580" +dependencies = [ + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "objc2-quartz-core", + "raw-window-handle", + "windows-sys 0.61.2", + "windows-version", +] + +[[package]] +name = "windows" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "527fadee13e0c05939a6a05d5bd6eec6cd2e3dbd648b9f8e447c6518133d8580" +dependencies = [ + "windows-collections", + "windows-core", + "windows-future", + "windows-numerics", +] + +[[package]] +name = "windows-collections" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "23b2d95af1a8a14a3c7367e1ed4fc9c20e0a26e79551b1454d72583c97cc6610" +dependencies = [ + "windows-core", +] + +[[package]] +name = "windows-core" +version = "0.62.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b8e83a14d34d0623b51dce9581199302a221863196a1dde71a7663a4c2be9deb" +dependencies = [ + "windows-implement", + "windows-interface", + "windows-link", + "windows-result", + "windows-strings", +] + +[[package]] +name = "windows-future" +version = "0.3.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e1d6f90251fe18a279739e78025bd6ddc52a7e22f921070ccdc67dde84c605cb" +dependencies = [ + "windows-core", + "windows-link", + "windows-threading", +] + +[[package]] +name = "windows-implement" +version = "0.60.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "053e2e040ab57b9dc951b72c264860db7eb3b0200ba345b4e4c3b14f67855ddf" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-interface" +version = "0.59.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3f316c4a2570ba26bbec722032c4099d8c8bc095efccdc15688708623367e358" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.119", +] + +[[package]] +name = "windows-link" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f0805222e57f7521d6a62e36fa9163bc891acd422f971defe97d64e70d0a4fe5" + +[[package]] +name = "windows-numerics" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6e2e40844ac143cdb44aead537bbf727de9b044e107a0f1220392177d15b0f26" +dependencies = [ + "windows-core", + "windows-link", +] + +[[package]] +name = "windows-result" +version = "0.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7781fa89eaf60850ac3d2da7af8e5242a5ea78d1a11c49bf2910bb5a73853eb5" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-strings" +version = "0.5.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7837d08f69c77cf6b07689544538e017c1bfcf57e34b4c0ff58e6c2cd3b37091" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-sys" +version = "0.45.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "75283be5efb2831d37ea142365f009c02ec203cd29a3ebecbc093d52315b66d0" +dependencies = [ + "windows-targets", +] + +[[package]] +name = "windows-sys" +version = "0.61.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-targets" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8e5180c00cd44c9b1c88adb3693291f1cd93605ded80c250a75d472756b4d071" +dependencies = [ + "windows_aarch64_gnullvm", + "windows_aarch64_msvc", + "windows_i686_gnu", + "windows_i686_msvc", + "windows_x86_64_gnu", + "windows_x86_64_gnullvm", + "windows_x86_64_msvc", +] + +[[package]] +name = "windows-threading" +version = "0.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3949bd5b99cafdf1c7ca86b43ca564028dfe27d66958f2470940f73d86d75b37" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows-version" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e4060a1da109b9d0326b7262c8e12c84df67cc0dbc9e33cf49e01ccc2eb63631" +dependencies = [ + "windows-link", +] + +[[package]] +name = "windows_aarch64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "597a5118570b68bc08d8d59125332c54f1ba9d9adeedeef5b99b02ba2b0698f8" + +[[package]] +name = "windows_aarch64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e08e8864a60f06ef0d0ff4ba04124db8b0fb3be5776a5cd47641e942e58c4d43" + +[[package]] +name = "windows_i686_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c61d927d8da41da96a81f029489353e68739737d3beca43145c8afec9a31a84f" + +[[package]] +name = "windows_i686_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "44d840b6ec649f480a41c8d80f9c65108b92d89345dd94027bfe06ac444d1060" + +[[package]] +name = "windows_x86_64_gnu" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8de912b8b8feb55c064867cf047dda097f92d51efad5b491dfb98f6bbb70cb36" + +[[package]] +name = "windows_x86_64_gnullvm" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "26d41b46a36d453748aedef1486d5c7a85db22e56aff34643984ea85514e94a3" + +[[package]] +name = "windows_x86_64_msvc" +version = "0.42.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9aec5da331524158c6d1a4ac0ab1541149c0b9505fde06423b02f5ef0106b9f0" + +[[package]] +name = "winnow" +version = "0.5.40" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f593a95398737aeed53e489c785df13f3618e41dbcd6718c6addbf1395aa6876" +dependencies = [ + "memchr", +] + +[[package]] +name = "winnow" +version = "1.0.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "8c3b93199df0ab874cdf0c6a94f0a0dc3423fe41f1cafb62b8bd7b1deb277aef" +dependencies = [ + "memchr", +] + +[[package]] +name = "winreg" +version = "0.56.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7d6f32a0ff4a9f6f01231eb2059cc85479330739333e0e58cadf03b6af2cca10" +dependencies = [ + "cfg-if", + "windows-sys 0.61.2", +] + +[[package]] +name = "wit-bindgen" +version = "0.57.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1ebf944e87a7c253233ad6766e082e3cd714b5d03812acc24c318f549614536e" + +[[package]] +name = "writeable" +version = "0.6.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "3ad82d2a33cdc9674dc7465672f271e096168fcdbe0f799d9e6db8c5892679dc" + +[[package]] +name = "wry" +version = "0.57.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ceb43f824178e8110e3181bfd478359c43b041452a9560d321bd8d121e468f86" +dependencies = [ + "base64 0.23.1", + "block2", + "cookie", + "crossbeam-channel", + "dirs", + "dom_query 0.29.0", + "dpi", + "dunce", + "gdkx11", + "gtk", + "http", + "javascriptcore-rs", + "jni", + "libc", + "ndk", + "objc2", + "objc2-app-kit", + "objc2-core-foundation", + "objc2-foundation", + "objc2-ui-kit", + "objc2-web-kit", + "percent-encoding", + "raw-window-handle", + "sha2 0.10.9", + "soup3", + "tao-macros", + "thiserror 2.0.21", + "url", + "webkit2gtk", + "webkit2gtk-sys", + "webview2-com", + "windows", + "windows-core", + "windows-version", + "x11-dl", +] + +[[package]] +name = "x11" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "502da5464ccd04011667b11c435cb992822c2c0dbde1770c988480d312a0db2e" +dependencies = [ + "libc", + "pkg-config", +] + +[[package]] +name = "x11-dl" +version = "2.21.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "38735924fedd5314a6e548792904ed8c6de6636285cb9fec04d5b1db85c1516f" +dependencies = [ + "libc", + "once_cell", + "pkg-config", +] + +[[package]] +name = "xiaoyin-markdown" +version = "2.6.1" +dependencies = [ + "clipboard-win", + "serde", + "serde_json", + "tauri", + "tauri-build", + "tauri-plugin-dialog", + "tauri-plugin-single-instance", + "windows-sys 0.61.2", +] + +[[package]] +name = "yoke" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "417ef3fcf6c300b7dbd25c85531a746931c02ad536f3cf4786ed1e88223340b3" +dependencies = [ + "stable_deref_trait", + "yoke-derive", + "zerofrom", +] + +[[package]] +name = "yoke-derive" +version = "0.8.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ec8ebde2db3681e8c9980cc27822030e68752690ddfa9473e739aeb4dbde6d71" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zbus" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5db4be7c075cb421e4b7ee645541604239bd243ba7c357511f4ff3a74b555907" +dependencies = [ + "async-broadcast", + "async-executor", + "async-io", + "async-lock", + "async-process", + "async-recursion", + "async-task", + "async-trait", + "blocking", + "enumflags2", + "event-listener", + "futures-core", + "futures-lite", + "hex", + "libc", + "ordered-stream", + "rustix", + "serde", + "serde_repr", + "tracing", + "uds_windows", + "uuid", + "windows-sys 0.61.2", + "winnow 1.0.5", + "zbus_macros", + "zbus_names", + "zvariant", +] + +[[package]] +name = "zbus_macros" +version = "5.19.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2990635d09ade6df1868f72f8cac69a876a90981e8bd3c40b1be413f8dc88f40" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 3.0.10", + "zbus_names", + "zvariant", + "zvariant_utils", +] + +[[package]] +name = "zbus_names" +version = "4.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "812a12be4ead7a59e18ea8f047d08add0066b73bc62fc1467066a2472ae088dd" +dependencies = [ + "serde", + "winnow 1.0.5", + "zvariant", +] + +[[package]] +name = "zcheapstr" +version = "1.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "939f186d9ecebe044315a5cb6d6f78568bbc21152adc954d5a0c2f58bdbc9920" +dependencies = [ + "serde", +] + +[[package]] +name = "zerofrom" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ec05a11813ea801ff6d75110ad09cd0824ddba17dfe17128ea0d5f68e6c5272" +dependencies = [ + "zerofrom-derive", +] + +[[package]] +name = "zerofrom-derive" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f75b4683f6c7f45248d4d64056a24298c6281e0993356d7d1b4a1a962ef10d4a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", + "synstructure", +] + +[[package]] +name = "zerotrie" +version = "0.2.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4ea269c3bd32f0a32c321907a2ae912ba6f4649bb0fc764a15627e99a7095a3f" +dependencies = [ + "displaydoc", + "yoke", + "zerofrom", +] + +[[package]] +name = "zerovec" +version = "0.11.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f58a2799cfe9a1670c7ea8edbd52ef8edb93cb37a7f83bf31ba9e35d9dae6a40" +dependencies = [ + "yoke", + "zerofrom", + "zerovec-derive", +] + +[[package]] +name = "zerovec-derive" +version = "0.11.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c3743ddbf47738d929cd1ae2e199d40d0162979dfe31aef8ae646d2bf00bf97a" +dependencies = [ + "proc-macro2", + "quote", + "syn 3.0.10", +] + +[[package]] +name = "zlib-rs" +version = "0.6.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b268e58e7c693d7c271f93ffc4ba3b380412554231c85bf61ca7af91042a4112" + +[[package]] +name = "zmij" +version = "1.0.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29666d0abbfad1e3dc4dcf6144730dd3a3ab225bbbdac83319345b1b44ccfc1b" + +[[package]] +name = "zvariant" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "80bf6d6cd6a4b601acb64cfb8284cdc643fcfa75ef26ae3c46ec8aa4e8a1fbb7" +dependencies = [ + "endi", + "enumflags2", + "serde", + "winnow 1.0.5", + "zcheapstr", + "zvariant_derive", + "zvariant_utils", +] + +[[package]] +name = "zvariant_derive" +version = "5.15.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ef2672456ba1cb54b5eaec136e63135b3c7495fb938e53b28a62e633496d486d" +dependencies = [ + "proc-macro-crate 3.5.0", + "proc-macro2", + "quote", + "syn 3.0.10", + "zvariant_utils", +] + +[[package]] +name = "zvariant_utils" +version = "4.2.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bad0294361a320b694a328460dc73add56c306150f5cb6bfafc44446120008a3" +dependencies = [ + "proc-macro2", + "quote", + "serde", + "syn 3.0.10", + "winnow 1.0.5", +] diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml new file mode 100644 index 0000000..47f7f84 --- /dev/null +++ b/src-tauri/Cargo.toml @@ -0,0 +1,30 @@ +[package] +name = "xiaoyin-markdown" +version = "2.6.1" +description = "小银 Markdown —— 轻量本地 Markdown 编辑器" +edition = "2021" + +[build-dependencies] +tauri-build = { version = "2", features = [] } + +[dependencies] +tauri = { version = "2", features = [] } +tauri-plugin-dialog = "2" +tauri-plugin-single-instance = "2" +serde = { version = "1", features = ["derive"] } +serde_json = "1" +clipboard-win = "5" +windows-sys = { version = "0.61", features = [ + "Win32_Foundation", + "Win32_System_DataExchange", + "Win32_System_Memory", + "Win32_UI_Shell", + "Win32_UI_WindowsAndMessaging" +] } + +[profile.release] +opt-level = "s" +lto = true +codegen-units = 1 +strip = true +panic = "abort" diff --git a/src-tauri/build.rs b/src-tauri/build.rs new file mode 100644 index 0000000..261851f --- /dev/null +++ b/src-tauri/build.rs @@ -0,0 +1,3 @@ +fn main() { + tauri_build::build(); +} diff --git a/src-tauri/capabilities/default.json b/src-tauri/capabilities/default.json new file mode 100644 index 0000000..910c059 --- /dev/null +++ b/src-tauri/capabilities/default.json @@ -0,0 +1,16 @@ +{ + "$schema": "../gen/schemas/desktop-schema.json", + "identifier": "default", + "description": "小银 Markdown 全部窗口的默认权限", + "windows": ["*"], + "permissions": [ + "core:default", + "core:window:allow-set-title", + "core:window:allow-close", + "core:window:allow-destroy", + "core:window:allow-hide", + "core:window:allow-show", + "core:window:allow-set-focus", + "dialog:default" + ] +} diff --git a/src-tauri/icons/icon.ico b/src-tauri/icons/icon.ico new file mode 100644 index 0000000..c93ba76 Binary files /dev/null and b/src-tauri/icons/icon.ico differ diff --git a/src-tauri/src/main.rs b/src-tauri/src/main.rs new file mode 100644 index 0000000..a14f490 --- /dev/null +++ b/src-tauri/src/main.rs @@ -0,0 +1,502 @@ +// 小银 Markdown —— Tauri 2 后端 +#![cfg_attr(not(debug_assertions), windows_subsystem = "windows")] + +use serde::Serialize; +use std::fs; +use std::path::{Path, PathBuf}; +use tauri::{AppHandle, Emitter, Manager, WebviewUrl, WebviewWindowBuilder, WindowEvent}; +use tauri_plugin_dialog::DialogExt; + +const MD_EXTS: [&str; 6] = ["md", "markdown", "mdown", "mkd", "mdwn", "txt"]; + +/* ---------------- 数据结构 ---------------- */ + +#[derive(Serialize, Clone)] +#[serde(rename_all = "camelCase")] +struct Entry { + name: String, + path: String, + is_dir: bool, +} + +#[derive(Serialize, Clone)] +#[serde(rename_all = "camelCase")] +struct DocResult { + ok: bool, + #[serde(skip_serializing_if = "Option::is_none")] + canceled: Option, + #[serde(skip_serializing_if = "Option::is_none")] + path: Option, + #[serde(skip_serializing_if = "Option::is_none")] + name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + text: Option, + #[serde(skip_serializing_if = "Option::is_none")] + eol: Option, + #[serde(skip_serializing_if = "Option::is_none")] + error: Option, +} + +impl DocResult { + fn ok(path: &Path, text: String, eol: String) -> Self { + DocResult { + ok: true, + canceled: None, + path: Some(path.to_string_lossy().to_string()), + name: Some(path.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_default()), + text: Some(text), + eol: Some(eol), + error: None, + } + } + fn canceled() -> Self { + DocResult { ok: false, canceled: Some(true), path: None, name: None, text: None, eol: None, error: None } + } + fn err(msg: String) -> Self { + DocResult { ok: false, canceled: None, path: None, name: None, text: None, eol: None, error: Some(msg) } + } +} + +#[derive(Serialize, Clone)] +#[serde(rename_all = "camelCase")] +struct DirResult { + ok: bool, + #[serde(skip_serializing_if = "Option::is_none")] + canceled: Option, + #[serde(skip_serializing_if = "Option::is_none")] + path: Option, + #[serde(skip_serializing_if = "Option::is_none")] + name: Option, + #[serde(skip_serializing_if = "Option::is_none")] + entries: Option>, + #[serde(skip_serializing_if = "Option::is_none")] + error: Option, +} + +/* ---------------- 工具函数 ---------------- */ + +fn smart_read(path: &Path) -> Result<(String, String), String> { + let bytes = fs::read(path).map_err(|e| e.to_string())?; + let mut text = String::from_utf8_lossy(&bytes).to_string(); + if let Some(stripped) = text.clone().strip_prefix('\u{feff}') { + text = stripped.to_string(); + } + let eol = if text.contains("\r\n") { "\r\n" } else { "\n" }.to_string(); + let text = text.replace("\r\n", "\n").replace('\r', "\n"); + Ok((text, eol)) +} + +fn smart_write(path: &Path, content: &str, eol: &str) -> Result<(), String> { + let text = if eol == "\r\n" { content.replace('\n', "\r\n") } else { content.to_string() }; + fs::write(path, text).map_err(|e| e.to_string()) +} + +fn is_md_file(name: &str) -> bool { + Path::new(name) + .extension() + .map(|e| e.to_string_lossy().to_lowercase()) + .map(|e| MD_EXTS.contains(&e.as_str())) + .unwrap_or(false) +} + +fn list_dir(path: &Path) -> Result, String> { + let mut dirs: Vec = Vec::new(); + let mut files: Vec = Vec::new(); + for e in fs::read_dir(path).map_err(|e| e.to_string())? { + let Ok(e) = e else { continue }; + let name = e.file_name().to_string_lossy().to_string(); + if name.starts_with('.') { + continue; + } + let Ok(ft) = e.file_type() else { continue }; + let is_dir = ft.is_dir(); + if !is_dir && !is_md_file(&name) { + continue; + } + let full = e.path().to_string_lossy().to_string(); + let entry = Entry { name, path: full, is_dir }; + if is_dir { + dirs.push(entry); + } else { + files.push(entry); + } + } + dirs.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); + files.sort_by(|a, b| a.name.to_lowercase().cmp(&b.name.to_lowercase())); + dirs.extend(files); + Ok(dirs) +} + +fn path_of(fp: tauri_plugin_dialog::FilePath) -> Option { + match fp { + tauri_plugin_dialog::FilePath::Path(p) => Some(p), + _ => None, + } +} + +/* ---------------- 文件命令 ---------------- */ + +#[tauri::command] +fn read_text_file(path: String) -> DocResult { + let p = PathBuf::from(&path); + match smart_read(&p) { + Ok((text, eol)) => DocResult::ok(&p, text, eol), + Err(e) => DocResult::err(e), + } +} + +#[tauri::command] +fn write_text_file(path: String, content: String, eol: String) -> DocResult { + let p = PathBuf::from(&path); + match smart_write(&p, &content, &eol) { + Ok(_) => DocResult::ok(&p, String::new(), eol), + Err(e) => DocResult::err(e), + } +} + +#[tauri::command] +fn open_file_dialog(window: tauri::WebviewWindow) -> DocResult { + let picked = window + .dialog() + .file() + .add_filter("Markdown", &["md", "markdown", "mdown", "mkd", "mdwn", "txt"]) + .add_filter("所有文件", &["*"]) + .set_title("打开 Markdown 文件") + .blocking_pick_file(); + let Some(fp) = picked else { return DocResult::canceled() }; + let Some(p) = path_of(fp) else { return DocResult::canceled() }; + match smart_read(&p) { + Ok((text, eol)) => DocResult::ok(&p, text, eol), + Err(e) => DocResult::err(e), + } +} + +#[tauri::command] +fn save_file( + window: tauri::WebviewWindow, + content: String, + save_as: bool, + eol: String, + current_path: Option, +) -> DocResult { + let mut target: Option = current_path.as_ref().map(PathBuf::from); + + if target.is_none() || save_as || !Path::new(target.as_ref().unwrap()).exists() { + let default_path = current_path.clone().map(PathBuf::from).unwrap_or_else(|| { + let doc = window + .app_handle() + .path() + .document_dir() + .unwrap_or_else(|_| PathBuf::from(".")); + doc.join("未命名.md") + }); + let picked = window + .dialog() + .file() + .add_filter("Markdown", &["md"]) + .add_filter("纯文本", &["txt"]) + .add_filter("所有文件", &["*"]) + .set_file_name(default_path.to_string_lossy().as_ref()) + .set_title(if save_as { "另存为" } else { "保存" }) + .blocking_save_file(); + let Some(fp) = picked else { return DocResult::canceled() }; + let Some(p) = path_of(fp) else { return DocResult::canceled() }; + target = Some(p); + } + + let p = target.unwrap(); + match smart_write(&p, &content, &eol) { + Ok(_) => DocResult::ok(&p, String::new(), eol), + Err(e) => DocResult::err(e), + } +} + +#[tauri::command] +fn open_dir_dialog(window: tauri::WebviewWindow) -> DirResult { + let picked = window.dialog().file().set_title("选择文件夹").blocking_pick_folder(); + let Some(fp) = picked else { + return DirResult { ok: false, canceled: Some(true), path: None, name: None, entries: None, error: None }; + }; + let Some(p) = path_of(fp) else { + return DirResult { ok: false, canceled: Some(true), path: None, name: None, entries: None, error: None }; + }; + match list_dir(&p) { + Ok(entries) => DirResult { + ok: true, + canceled: None, + path: Some(p.to_string_lossy().to_string()), + name: Some(p.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_default()), + entries: Some(entries), + error: None, + }, + Err(e) => DirResult { ok: false, canceled: None, path: None, name: None, entries: None, error: Some(e) }, + } +} + +#[tauri::command] +fn read_dir(path: String) -> DirResult { + let p = PathBuf::from(&path); + match list_dir(&p) { + Ok(entries) => DirResult { + ok: true, + canceled: None, + path: Some(p.to_string_lossy().to_string()), + name: Some(p.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_default()), + entries: Some(entries), + error: None, + }, + Err(e) => DirResult { ok: false, canceled: None, path: None, name: None, entries: None, error: Some(e) }, + } +} + +/* ---------------- 剪贴板 ---------------- */ + +#[tauri::command] +fn copy_file_to_clipboard(path: String) -> Result<(), String> { + // 手写 CF_HDROP:DROPFILES 头 + 双 \0 结尾的 UTF-16 路径列表 + use windows_sys::Win32::System::DataExchange::{CloseClipboard, EmptyClipboard, OpenClipboard, SetClipboardData}; + use windows_sys::Win32::System::Memory::{GlobalAlloc, GlobalLock, GlobalUnlock, GMEM_MOVEABLE, GMEM_ZEROINIT}; + use windows_sys::Win32::UI::Shell::DROPFILES; + + const CF_HDROP: u32 = 15; + + unsafe { + if OpenClipboard(std::ptr::null_mut()) == 0 { + return Err("无法打开剪贴板".into()); + } + if EmptyClipboard() == 0 { + CloseClipboard(); + return Err("无法清空剪贴板".into()); + } + + let mut wide: Vec = path.encode_utf16().collect(); + wide.push(0); // 路径自身的 \0 终止符 + + let header_size = std::mem::size_of::(); + let list_bytes = (wide.len() + 1) * 2; // +1 是列表级双 \0 结束符 + let total = header_size + list_bytes; + + let h = GlobalAlloc(GMEM_MOVEABLE | GMEM_ZEROINIT, total); + if h.is_null() { + CloseClipboard(); + return Err("内存分配失败".into()); + } + let locked = GlobalLock(h); + if locked.is_null() { + CloseClipboard(); + return Err("内存锁定失败".into()); + } + let df = locked as *mut DROPFILES; + (*df).pFiles = header_size as u32; + (*df).fWide = 1; // UTF-16 + let dst = (locked as *mut u8).add(header_size); + std::ptr::copy_nonoverlapping(wide.as_ptr() as *const u8, dst, wide.len() * 2); + GlobalUnlock(h); + + if SetClipboardData(CF_HDROP, h).is_null() { + CloseClipboard(); + return Err("写入剪贴板失败".into()); + } + CloseClipboard(); + } + Ok(()) +} + +#[tauri::command] +fn read_clipboard_text() -> String { + use clipboard_win::formats; + use clipboard_win::get_clipboard; + get_clipboard(formats::Unicode).unwrap_or_default() +} + +#[tauri::command] +fn write_clipboard_text(text: String) -> Result<(), String> { + use clipboard_win::formats; + use clipboard_win::set_clipboard; + set_clipboard(formats::Unicode, text).map_err(|e| e.to_string()) +} + +/* ---------------- 系统 ---------------- */ + +#[tauri::command] +fn reveal_in_explorer(path: String) -> Result<(), String> { + let p = PathBuf::from(&path); + if p.is_file() { + std::process::Command::new("explorer") + .arg(format!("/select,{}", p.to_string_lossy())) + .spawn() + .map_err(|e| e.to_string())?; + } else { + std::process::Command::new("explorer") + .arg(&p) + .spawn() + .map_err(|e| e.to_string())?; + } + Ok(()) +} + +#[tauri::command] +fn open_external(url: String) -> Result<(), String> { + if !url.starts_with("http://") && !url.starts_with("https://") { + return Err("仅允许打开 http/https 链接".into()); + } + std::process::Command::new("explorer") + .arg(&url) + .spawn() + .map_err(|e| e.to_string())?; + Ok(()) +} + +#[tauri::command] +fn message_box(window: tauri::WebviewWindow, title: String, message: String, detail: Option) -> i32 { + use tauri_plugin_dialog::{MessageDialogButtons, MessageDialogKind}; + let text = match &detail { + Some(d) if !d.is_empty() => format!("{}\n{}", message, d), + _ => message.clone(), + }; + let _ = window + .dialog() + .message(text) + .title(&title) + .kind(MessageDialogKind::Info) + .buttons(MessageDialogButtons::Ok) + .blocking_show(); + 0 +} + +/* ---------------- 多窗口 ---------------- */ + +fn next_window_label(app: &AppHandle) -> String { + let mut i = 1; + let existing = app.webview_windows(); + loop { + let label = format!("win-{}", i); + if !existing.contains_key(&label) { + return label; + } + i += 1; + } +} + +fn create_doc_window(app: &AppHandle, doc: Option) -> Result { + let label = next_window_label(app); + let win = WebviewWindowBuilder::new(app, &label, WebviewUrl::App("index.html".into())) + .title("未命名 — 小银 Markdown") + .inner_size(1380.0, 880.0) + .min_inner_size(860.0, 520.0) + .build() + .map_err(|e| e.to_string())?; + if let Some(d) = doc { + let _ = win.emit("mig:adopt-doc", d); + } + Ok(label) +} + +#[tauri::command] +fn open_new_window(app: AppHandle, path: Option) -> Result { + let doc = match &path { + Some(p) => { + let pb = PathBuf::from(p); + match smart_read(&pb) { + Ok((text, eol)) => Some(serde_json::json!({ + "path": p, "name": pb.file_name().map(|s| s.to_string_lossy().to_string()).unwrap_or_default(), + "text": text, "eol": eol + })), + Err(_) => None, + } + } + None => None, + }; + create_doc_window(&app, doc) +} + +#[tauri::command] +fn force_close(window: tauri::WebviewWindow) { + window.destroy(); +} + +#[tauri::command] +fn get_window_count(app: AppHandle) -> usize { + app.webview_windows().len() +} + +/* 模式迁移:前端先通过事件收集各窗口文档,再调用这里执行窗口增删 */ +#[tauri::command] +fn migrate_apply(app: AppHandle, mode: String, docs: Vec, keep_label: String) -> Result<(), String> { + let old_labels: Vec = app.webview_windows().keys().cloned().collect(); + + match mode.as_str() { + "tabs" => { + // 全部合并进保留窗口 + if let Some(win) = app.get_webview_window(&keep_label) { + let _ = win.emit("mig:adopt-tabs", serde_json::json!({ "docs": docs })); + } + for l in old_labels.iter() { + if l != &keep_label { + if let Some(w) = app.get_webview_window(l) { + w.destroy(); + } + } + } + } + "windows" => { + // 每份文档一个新窗口 + for d in docs.iter() { + let label = create_doc_window(&app, Some(d.clone()))?; + let _ = label; + } + for l in old_labels.iter() { + if let Some(w) = app.get_webview_window(l) { + w.destroy(); + } + } + } + _ => return Err(format!("未知模式 {}", mode)), + } + Ok(()) +} + +/* ---------------- 入口 ---------------- */ + +fn main() { + tauri::Builder::default() + .plugin(tauri_plugin_dialog::init()) + .plugin(tauri_plugin_single_instance::init(|app, argv, _cwd| { + if let Some(win) = app.get_webview_window("main") { + let _ = win.set_focus(); + if let Some(path) = argv.iter().nth(1) { + let p = PathBuf::from(path); + if p.is_file() { + let _ = win.emit("open-external", p.to_string_lossy().to_string()); + } + } + } + })) + .invoke_handler(tauri::generate_handler![ + read_text_file, + write_text_file, + open_file_dialog, + save_file, + open_dir_dialog, + read_dir, + copy_file_to_clipboard, + read_clipboard_text, + write_clipboard_text, + reveal_in_explorer, + open_external, + message_box, + open_new_window, + force_close, + get_window_count, + migrate_apply + ]) + .on_window_event(|window, event| { + if let WindowEvent::CloseRequested { api, .. } = event { + // 交给前端确认(未保存提示) + api.prevent_close(); + let _ = window.emit("close-confirm", window.label()); + } + }) + .run(tauri::generate_context!()) + .expect("error while running tauri application"); +} diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json new file mode 100644 index 0000000..ec56464 --- /dev/null +++ b/src-tauri/tauri.conf.json @@ -0,0 +1,57 @@ +{ + "$schema": "https://schema.tauri.app/config/2", + "productName": "XiaoyinMarkdown", + "version": "2.6.1", + "identifier": "com.xiaoyin.markdown", + "build": { + "frontendDist": "../src/renderer" + }, + "app": { + "withGlobalTauri": true, + "windows": [ + { + "label": "main", + "title": "未命名 — 小银 Markdown", + "width": 1380, + "height": 880, + "minWidth": 860, + "minHeight": 520, + "dragDropEnabled": true + } + ], + "security": { + "csp": null + } + }, + "bundle": { + "active": true, + "targets": ["nsis"], + "icon": ["icons/icon.ico"], + "fileAssociations": [ + { + "ext": ["md", "markdown", "mdown", "mkd", "mdwn"], + "name": "XiaoyinMarkdown.Document", + "description": "Markdown 文档 — 小银 Markdown", + "role": "Editor" + }, + { + "ext": ["txt"], + "name": "XiaoyinMarkdown.Text", + "description": "文本文档 — 小银 Markdown", + "role": "Editor" + } + ], + "windows": { + "webviewInstallMode": { + "type": "downloadBootstrapper" + }, + "nsis": { + "installMode": "currentUser", + "languages": ["SimpChinese"], + "displayLanguageSelector": false, + "installerIcon": "icons/icon.ico", + "uninstallerIcon": "icons/icon.ico" + } + } + } +} diff --git a/src/clipboard-native.js b/src/clipboard-native.js new file mode 100644 index 0000000..12b49d6 --- /dev/null +++ b/src/clipboard-native.js @@ -0,0 +1,60 @@ +/* Windows 原生文件剪贴板:通过 Win32 CF_HDROP 把文件对象放进系统剪贴板, + 效果等同于在资源管理器里选中文件按 Ctrl+C(可以在别处 Ctrl+V 粘出文件副本)。 + Electron 45 的 clipboard API 没有 writeBuffer,只能走 Win32。 */ +let api = null; + +function makeHdrop(paths) { + const header = Buffer.alloc(20); + header.writeUInt32LE(20, 0); // pFiles:文件列表相对结构头的偏移 + // pt(8 字节) 与 fNC(4 字节) 留 0 + header.writeUInt32LE(1, 16); // fWide = TRUE(UTF-16LE 路径) + const parts = paths.map((p) => Buffer.from(String(p) + '\0', 'utf16le')); + return Buffer.concat([header, ...parts, Buffer.from([0, 0])]); // 双 \0 结束 +} + +function getApi() { + if (api) return api; + const koffi = require('koffi'); + const user32 = koffi.load('user32.dll'); + const kernel32 = koffi.load('kernel32.dll'); + + const OpenClipboard = user32.func('bool OpenClipboard(void* hWnd)'); + const EmptyClipboard = user32.func('bool EmptyClipboard()'); + const SetClipboardData = user32.func('void* SetClipboardData(unsigned int uFormat, void* hMem)'); + const CloseClipboard = user32.func('bool CloseClipboard()'); + const IsClipboardFormatAvailable = user32.func('bool IsClipboardFormatAvailable(unsigned int format)'); + const GlobalAlloc = kernel32.func('void* GlobalAlloc(unsigned int uFlags, size_t dwBytes)'); + const GlobalLock = kernel32.func('void* GlobalLock(void* hMem)'); + const GlobalUnlock = kernel32.func('bool GlobalUnlock(void* hMem)'); + const RtlMoveMemory = kernel32.func('void RtlMoveMemory(void* dst, void* src, size_t len)'); + + function setFiles(paths) { + const data = makeHdrop(paths); + const h = GlobalAlloc(0x0002, data.length); // GMEM_MOVEABLE + if (!h) throw new Error('内存分配失败'); + const p = GlobalLock(h); + RtlMoveMemory(p, koffi.as(data, 'void*'), data.length); + GlobalUnlock(h); + + if (!OpenClipboard(null)) throw new Error('无法打开剪贴板'); + try { + EmptyClipboard(); + if (!SetClipboardData(15, h)) throw new Error('写入剪贴板失败'); // CF_HDROP + } finally { + CloseClipboard(); + } + return true; + } + + function hasFiles() { + return !!IsClipboardFormatAvailable(15); + } + + api = { setFiles, hasFiles }; + return api; +} + +module.exports = { + setFiles: (paths) => getApi().setFiles(paths), + hasFiles: () => getApi().hasFiles() +}; diff --git a/src/main.js b/src/main.js new file mode 100644 index 0000000..134c4c6 --- /dev/null +++ b/src/main.js @@ -0,0 +1,594 @@ +/* + * 小银 Markdown 编辑器 —— 主进程 + * 负责:多窗口管理、菜单与快捷键、文件读写、系统对话框、剪贴板、资源管理器联动 + * + * 两种打开方式: + * tabs —— 一个窗口内用标签页打开多个文档 + * windows —— 每个文档开一个独立窗口 + * 偏好保存在 userData/prefs.json,切换后广播给所有窗口。 + */ +const { app, BrowserWindow, ipcMain, dialog, Menu, shell, clipboard } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); + +const windows = new Map(); // webContents.id -> state { win, path, dirty, pendingClose, closing } +const pendingAdopt = new Map(); // webContents.id -> 待装载的文档(窗口拆分时用) +let openMode = 'tabs'; + +const prefsFile = () => path.join(app.getPath('userData'), 'prefs.json'); +function loadPrefs() { + try { + const p = JSON.parse(fs.readFileSync(prefsFile(), 'utf8')); + if (p.openMode === 'tabs' || p.openMode === 'windows') openMode = p.openMode; + } catch (_) { /* 首次运行,用默认 */ } +} +function savePrefs() { + try { + fs.mkdirSync(path.dirname(prefsFile()), { recursive: true }); + fs.writeFileSync(prefsFile(), JSON.stringify({ openMode }), 'utf8'); + } catch (_) { /* 忽略 */ } +} + +function stateOf(sender) { + return sender && sender.id != null ? windows.get(sender.id) : null; +} +function focusedState() { + const win = BrowserWindow.getFocusedWindow(); + if (win && windows.has(win.webContents.id)) return windows.get(win.webContents.id); + const first = windows.values().next(); + return first.done ? null : first.value; +} +function sendTo(state, channel, ...args) { + if (state && state.win && !state.win.isDestroyed()) state.win.webContents.send(channel, ...args); +} +function primaryState() { + const first = windows.values().next(); + return first.done ? null : first.value; +} + +/* ------------------------------ 窗口 ------------------------------ */ + +/* 窗口图标(标题栏左上角 / 任务栏):打包版取安装目录 resources 下的 app-win.ico,开发环境取源码树 */ +const appIconPath = app.isPackaged + ? path.join(process.resourcesPath, 'app-win.ico') + : path.join(__dirname, 'resources', 'app.ico'); + +function createWindow(filePath) { + const win = new BrowserWindow({ + width: 1380, + height: 880, + minWidth: 860, + minHeight: 520, + show: false, + backgroundColor: '#ffffff', + autoHideMenuBar: true, + icon: appIconPath, // 标题栏左上角 / 任务栏图标(保留) + webPreferences: { + preload: path.join(__dirname, 'preload.js'), + contextIsolation: true, + nodeIntegration: false, + spellcheck: false, + sandbox: false + } + }); + + const wcId = win.webContents.id; + const state = { win, path: filePath || null, dirty: false, pendingClose: false, closing: false }; + windows.set(wcId, state); + + win.loadFile(path.join(__dirname, 'renderer', 'index.html')); + win.once('ready-to-show', () => win.show()); + win.webContents.on('did-finish-load', () => { + updateTitle(state); + sendTo(state, 'cmd', 'open-mode', openMode); + if (pendingAdopt.has(win.webContents.id)) { + // 标签拆成独立窗口:装载该窗口分到的那一份文档 + sendTo(state, 'cmd', 'adopt-doc', pendingAdopt.get(win.webContents.id)); + pendingAdopt.delete(win.webContents.id); + } else if (filePath) { + const r = readPathQuiet(filePath); + if (r.ok) sendTo(state, 'cmd', 'file-opened', r); + } + }); + win.webContents.on('will-navigate', (e) => e.preventDefault()); + win.webContents.setWindowOpenHandler(({ url }) => { + if (/^(https?|mailto):/i.test(url)) shell.openExternal(url); + return { action: 'deny' }; + }); + + win.on('close', (e) => { + if (state.closing || !state.dirty) return; + e.preventDefault(); + const choice = dialog.showMessageBoxSync(win, { + type: 'warning', + buttons: ['保存并退出', '不保存直接退出', '取消'], + defaultId: 0, + cancelId: 2, + noLink: true, + title: '未保存的修改', + message: '「' + (state.path ? path.basename(state.path) : '未命名') + '」还有未保存的修改', + detail: '是否先保存再退出?' + }); + if (choice === 2) return; + if (choice === 1) { state.closing = true; win.close(); return; } + state.pendingClose = true; + sendTo(state, 'cmd', 'save'); + }); + + // closed 触发时 webContents 已销毁,不能再读 win.webContents.id + win.on('closed', () => { + windows.delete(wcId); + pendingAdopt.delete(wcId); + }); + return win; +} + +function readPathQuiet(p) { + try { + const { text, eol } = readFileSmart(p); + return { ok: true, path: p, name: path.basename(p), text, eol }; + } catch (err) { + return { ok: false, error: String(err.message || err) }; + } +} + +/* ------------------------------ 菜单 ------------------------------ */ + +function buildMenu() { + const template = [ + { + label: '文件', + submenu: [ + { label: '新建', accelerator: 'CmdOrCtrl+N', click: () => sendTo(focusedState(), 'cmd', 'new') }, + { label: '打开…', accelerator: 'CmdOrCtrl+O', click: () => sendTo(focusedState(), 'cmd', 'open') }, + { label: '在新窗口打开', accelerator: 'CmdOrCtrl+Shift+N', click: () => sendTo(focusedState(), 'cmd', 'newWindow') }, + { type: 'separator' }, + { label: '保存', accelerator: 'CmdOrCtrl+S', click: () => sendTo(focusedState(), 'cmd', 'save') }, + { label: '另存为…', accelerator: 'CmdOrCtrl+Shift+S', click: () => sendTo(focusedState(), 'cmd', 'saveAs') }, + { type: 'separator' }, + { label: '打开文件夹…', accelerator: 'CmdOrCtrl+Shift+K', click: () => sendTo(focusedState(), 'cmd', 'openFolder') }, + { label: '在资源管理器中显示当前文件', accelerator: 'CmdOrCtrl+Shift+O', click: () => sendTo(focusedState(), 'cmd', 'openDir') }, + { label: '复制全文', accelerator: 'CmdOrCtrl+Shift+C', click: () => sendTo(focusedState(), 'cmd', 'copyAll') }, + { type: 'separator' }, + { label: '退出', accelerator: 'Alt+F4', role: 'quit' } + ] + }, + { + label: '编辑', + submenu: [ + { label: '撤销', accelerator: 'CmdOrCtrl+Z', role: 'undo' }, + { label: '重做', accelerator: 'CmdOrCtrl+Y', role: 'redo' }, + { type: 'separator' }, + { label: '剪切', accelerator: 'CmdOrCtrl+X', role: 'cut' }, + { label: '复制', accelerator: 'CmdOrCtrl+C', role: 'copy' }, + { label: '粘贴', accelerator: 'CmdOrCtrl+V', role: 'paste' }, + { label: '全选', accelerator: 'CmdOrCtrl+A', role: 'selectAll' }, + { type: 'separator' }, + { label: '查找', accelerator: 'CmdOrCtrl+F', click: () => sendTo(focusedState(), 'cmd', 'find') } + ] + }, + { + label: '视图', + submenu: [ + { label: '编辑模式', accelerator: 'CmdOrCtrl+1', click: () => sendTo(focusedState(), 'cmd', 'mode', 'edit') }, + { label: '分栏模式', accelerator: 'CmdOrCtrl+2', click: () => sendTo(focusedState(), 'cmd', 'mode', 'split') }, + { label: '阅读模式', accelerator: 'CmdOrCtrl+3', click: () => sendTo(focusedState(), 'cmd', 'mode', 'read') }, + { type: 'separator' }, + { + label: '文档打开方式', + submenu: [ + { + label: '标签页(多窗口)', type: 'radio', checked: openMode === 'tabs', + click: () => setOpenMode('tabs') + }, + { + label: '独立窗口', type: 'radio', checked: openMode === 'windows', + click: () => setOpenMode('windows') + } + ] + }, + { type: 'separator' }, + { label: '显示 / 隐藏文件目录', accelerator: 'CmdOrCtrl+Shift+B', click: () => sendTo(focusedState(), 'cmd', 'tree') }, + { label: '显示 / 隐藏章节大纲', accelerator: 'CmdOrCtrl+Shift+T', click: () => sendTo(focusedState(), 'cmd', 'outline') }, + { label: '切换深色/浅色', accelerator: 'CmdOrCtrl+Shift+L', click: () => sendTo(focusedState(), 'cmd', 'theme') }, + { label: '放大', accelerator: 'CmdOrCtrl+Shift+=', click: () => sendTo(focusedState(), 'cmd', 'zoom', 1) }, + { label: '缩小', accelerator: 'CmdOrCtrl+Shift+-', click: () => sendTo(focusedState(), 'cmd', 'zoom', -1) }, + { label: '实际大小', accelerator: 'CmdOrCtrl+0', click: () => sendTo(focusedState(), 'cmd', 'zoom', 0) }, + { type: 'separator' }, + { label: '开发者工具', accelerator: 'F12', role: 'toggleDevTools' }, + { label: '全屏', accelerator: 'F11', role: 'togglefullscreen' } + ] + } + ]; + Menu.setApplicationMenu(Menu.buildFromTemplate(template)); +} + +/* 让某个窗口把它的所有标签文档交出来(带未保存内容) */ +function collectDocsFrom(state) { + return new Promise((resolve) => { + let done = false; + const timer = setTimeout(() => finish([]), 2500); + function finish(docs) { + if (done) return; + done = true; + clearTimeout(timer); + ipcMain.removeListener('docs:exported', handler); + resolve(docs); + } + function handler(e, payload) { + if (!state || e.sender.id !== state.win.webContents.id) return; + finish(Array.isArray(payload && payload.docs) ? payload.docs : []); + } + ipcMain.on('docs:exported', handler); + sendTo(state, 'cmd', 'export-docs'); + }); +} + +function dedupeDocs(docs) { + const seen = new Set(); + const out = []; + for (const d of docs) { + if (d.path && seen.has(d.path)) continue; + if (d.path) seen.add(d.path); + out.push(d); + } + return out; +} + +function closeForMigration(state) { + if (!state || state.win.isDestroyed()) return; + state.closing = true; // 内容已收集,跳过未保存确认 + state.win.close(); +} + +/* 切换模式时做双向迁移: + windows → tabs:把各窗口的文档并到一个窗口的多标签 + tabs → windows:把标签拆成多个独立窗口 */ +async function setOpenMode(mode) { + if (mode !== 'tabs' && mode !== 'windows') return; + if (mode === openMode) { buildMenu(); return; } + + const states = [...windows.values()].filter((s) => s.win && !s.win.isDestroyed()); + const allDocs = []; + for (const st of states) { + const docs = await collectDocsFrom(st); + allDocs.push(...docs); + } + let docs = dedupeDocs(allDocs); + if (!docs.length) docs.push({ path: null, name: null, text: '', eol: '\n', dirty: false, lastSaved: '' }); + + openMode = mode; + savePrefs(); + buildMenu(); + + if (mode === 'tabs') { + const primary = states[0] || null; + for (const st of states.slice(1)) closeForMigration(st); + if (!primary) { createWindow(); return; } + sendTo(primary, 'cmd', 'open-mode', 'tabs'); + sendTo(primary, 'cmd', 'adopt-tabs', docs); + } else { + for (const d of docs) { + const win = createWindow(); + pendingAdopt.set(win.webContents.id, d); + } + for (const st of states) closeForMigration(st); + for (const st of windows.values()) sendTo(st, 'cmd', 'open-mode', 'windows'); + } +} + +/* ------------------------------ IPC ------------------------------ */ + +function readFileSmart(p) { + const buf = fs.readFileSync(p); + let text = buf.toString('utf8'); + if (text.charCodeAt(0) === 0xfeff) text = text.slice(1); // BOM + const eol = /\r\n/.test(text) ? '\r\n' : '\n'; + text = text.replace(/\r\n?/g, '\n'); + return { text, eol }; +} + +function openPathInternal(p, state) { + try { + const { text, eol } = readFileSmart(p); + if (state) { state.path = p; state.dirty = false; updateTitle(state); } + return { ok: true, path: p, name: path.basename(p), text, eol }; + } catch (err) { + const st = state || focusedState(); + dialog.showMessageBoxSync(st ? st.win : null, { + type: 'error', title: '打开失败', message: '无法读取该文件', detail: String(err.message || err), buttons: ['好'] + }); + return { ok: false, error: String(err.message || err) }; + } +} + +ipcMain.handle('file:open', async (e) => { + const state = stateOf(e.sender) || focusedState(); + const r = await dialog.showOpenDialog(state ? state.win : null, { + title: '打开 Markdown 文件', + properties: ['openFile'], + filters: [ + { name: 'Markdown', extensions: ['md', 'markdown', 'mdown', 'mkd', 'mdwn', 'txt'] }, + { name: '所有文件', extensions: ['*'] } + ] + }); + if (r.canceled || !r.filePaths.length) return { ok: false, canceled: true }; + return openPathInternal(r.filePaths[0], state); +}); + +ipcMain.handle('file:openPath', async (e, p) => openPathInternal(p, stateOf(e.sender) || focusedState())); + +/* 新窗口打开(右键菜单 / 菜单命令都走这里) */ +ipcMain.handle('window:openPath', async (_e, p) => { + if (!p) return { ok: false }; + try { + if (!fs.statSync(p).isFile()) return { ok: false }; + } catch (_) { return { ok: false }; } + createWindow(p); + return { ok: true }; +}); + +ipcMain.handle('window:new', async () => { + createWindow(); + return { ok: true }; +}); + +ipcMain.handle('app:getOpenMode', async () => openMode); +ipcMain.handle('app:setOpenMode', async (_e, mode) => { + await setOpenMode(mode); + return { ok: true, mode: openMode }; +}); + +/* ---------------------- 文件夹浏览 ---------------------- */ + +const MD_EXT = /\.(md|markdown|mdown|mkd|mdwn|txt)$/i; +const SKIP_DIRS = new Set(['node_modules', '$RECYCLE.BIN', 'System Volume Information']); + +function listDir(dir) { + const entries = []; + let items; + try { items = fs.readdirSync(dir, { withFileTypes: true }); } catch (_) { return entries; } + + for (const d of items) { + if (d.name.startsWith('.')) continue; + if (SKIP_DIRS.has(d.name)) continue; + + const full = path.join(dir, d.name); + let isDir = d.isDirectory(); + if (!isDir && !d.isFile()) { + try { isDir = fs.statSync(full).isDirectory(); } catch (_) { continue; } + } + if (!isDir && !MD_EXT.test(d.name)) continue; + entries.push({ name: d.name, path: full, isDir }); + } + entries.sort((a, b) => (Number(b.isDir) - Number(a.isDir)) || a.name.localeCompare(b.name, 'zh-Hans-CN')); + return entries; +} + +function dirInfo(p) { + return { ok: true, path: p, name: path.basename(p) || p, entries: listDir(p) }; +} + +ipcMain.handle('dir:open', async (e) => { + const state = stateOf(e.sender) || focusedState(); + const r = await dialog.showOpenDialog(state ? state.win : null, { + title: '打开文件夹', properties: ['openDirectory'] + }); + if (r.canceled || !r.filePaths.length) return { ok: false, canceled: true }; + return dirInfo(r.filePaths[0]); +}); + +ipcMain.handle('dir:read', async (_e, p) => { + try { if (!fs.statSync(p).isDirectory()) return { ok: false }; } catch (_) { return { ok: false }; } + return dirInfo(p); +}); + +ipcMain.handle('file:save', async (e, payload) => { + const state = stateOf(e.sender) || focusedState(); + const { content, saveAs, eol } = payload; + let target = state && state.path; + + if (!target || saveAs) { + const r = await dialog.showSaveDialog(state ? state.win : null, { + title: saveAs ? '另存为' : '保存', + defaultPath: target || path.join(app.getPath('documents'), '未命名.md'), + filters: [ + { name: 'Markdown', extensions: ['md'] }, + { name: '纯文本', extensions: ['txt'] }, + { name: '所有文件', extensions: ['*'] } + ] + }); + if (r.canceled || !r.filePath) return { ok: false, canceled: true }; + target = r.filePath; + } + + try { + let text = content; + if (eol === '\r\n') text = text.replace(/\r?\n/g, '\r\n'); + await fs.promises.writeFile(target, text, 'utf8'); + if (state) { state.path = target; state.dirty = false; updateTitle(state); } + return { ok: true, path: target, name: path.basename(target) }; + } catch (err) { + dialog.showMessageBoxSync(state ? state.win : null, { + type: 'error', title: '保存失败', message: '写入文件时出错', detail: String(err.message || err), buttons: ['好'] + }); + return { ok: false, error: String(err.message || err) }; + } +}); + +ipcMain.handle('file:reveal', async (e) => { + const state = stateOf(e.sender) || focusedState(); + const target = state && state.path; + if (!target) { + dialog.showMessageBoxSync(state ? state.win : null, { + type: 'info', title: '提示', message: '当前文件还没有保存到磁盘', + detail: '请先保存文件,之后即可打开它所在的文件夹。', buttons: ['好'] + }); + return { ok: false }; + } + if (!fs.existsSync(target)) { + dialog.showMessageBoxSync(state ? state.win : null, { + type: 'warning', title: '提示', message: '文件已不存在', detail: target, buttons: ['好'] + }); + return { ok: false }; + } + shell.showItemInFolder(target); + return { ok: true }; +}); + +ipcMain.handle('clip:read', () => clipboard.readText()); +ipcMain.handle('clip:write', (_e, text) => { clipboard.writeText(String(text ?? '')); return true; }); + +const nativeClip = require('./clipboard-native'); +ipcMain.handle('file:copyFile', async (_e, paths) => { + try { + const list = (Array.isArray(paths) ? paths : [paths]).filter((p) => p && fs.existsSync(p)); + if (!list.length) return { ok: false, error: '文件不存在' }; + nativeClip.setFiles(list); + return { ok: true, count: list.length }; + } catch (err) { + return { ok: false, error: String(err.message || err) }; + } +}); + +ipcMain.handle('file:readText', async (_e, p) => { + try { return { ok: true, text: readFileSmart(p).text }; } catch (_) { return { ok: false }; } +}); + +ipcMain.handle('file:revealPath', async (_e, p) => { + try { + if (!p || !fs.existsSync(p)) return { ok: false, error: '文件不存在' }; + const err = await shell.openPath(path.dirname(p)); + if (!err) return { ok: true }; + shell.showItemInFolder(p); + return { ok: true, fallback: true }; + } catch (err) { + try { shell.showItemInFolder(p); return { ok: true, fallback: true }; } + catch (_) { return { ok: false, error: String(err.message || err) }; } + } +}); + +ipcMain.handle('shell:openExternal', (_e, url) => { + const u = String(url || ''); + if (/^(https?|mailto):/i.test(u)) shell.openExternal(u); + return true; +}); + +/* 拖放:作用于收到事件的那个窗口 */ +ipcMain.on('file:drop', (e, p) => { + if (!p) return; + const state = stateOf(e.sender) || focusedState(); + let isDir = false; + try { isDir = fs.statSync(p).isDirectory(); } catch (_) { return; } + + if (isDir) { + sendTo(state, 'cmd', 'dir-opened', dirInfo(p)); + return; + } + const r = openPathInternal(p, state); + if (r.ok) sendTo(state, 'cmd', 'file-opened', r); +}); + +ipcMain.on('file:droppedText', (e, payload) => { + sendTo(stateOf(e.sender) || focusedState(), 'cmd', 'dropped-text', { + name: payload && payload.name, text: (payload && payload.text) || '' + }); +}); + +ipcMain.handle('ui:message', async (e, opts) => { + const state = stateOf(e.sender) || focusedState(); + const r = await dialog.showMessageBox(state ? state.win : null, { + type: opts.type || 'info', + title: opts.title || '提示', + message: opts.message || '', + detail: opts.detail || '', + buttons: opts.buttons || ['好'], + noLink: true, + defaultId: 0, + cancelId: (opts.buttons || ['好']).length - 1 + }); + return r.response; +}); + +ipcMain.on('app:setDirty', (e, d) => { + const state = stateOf(e.sender) || focusedState(); + if (state) { state.dirty = !!d; updateTitle(state); } +}); + +/* 切标签 / 迁移后,渲染进程把当前激活的文档路径同步给主进程, + 这样窗口标题和「保存=覆盖原文件」才不会错位 */ +ipcMain.on('doc:syncPath', (e, p) => { + const state = stateOf(e.sender); + if (!state) return; + state.path = p || null; + updateTitle(state); +}); + +ipcMain.on('win:setTitle', (e) => updateTitle(stateOf(e.sender) || focusedState())); + +ipcMain.on('save:finished', (e, ok) => { + const state = stateOf(e.sender) || focusedState(); + if (!state) return; + if (state.pendingClose && ok) { + state.pendingClose = false; + state.closing = true; + state.win.close(); + } else if (!ok) { + state.pendingClose = false; + } +}); + +function updateTitle(state) { + if (!state || !state.win || state.win.isDestroyed()) return; + const name = state.path ? path.basename(state.path) : '未命名'; + state.win.setTitle(`${state.dirty ? '● ' : ''}${name} — 小银 Markdown`); + state.win.setDocumentEdited(state.dirty); +} + +/* ------------------------------ 生命周期 ------------------------------ */ + +const gotLock = app.requestSingleInstanceLock(); +if (!gotLock) { + app.quit(); +} else { + app.on('second-instance', (_e, argv) => { + const arg = argv.find((a) => /\.(md|markdown|txt|mdown|mkd)$/i.test(a)); + if (arg) { + if (openMode === 'windows') { + createWindow(arg); + } else { + const state = primaryState(); + if (state) { + if (state.win.isMinimized()) state.win.restore(); + state.win.focus(); + sendTo(state, 'cmd', 'open-external', arg); + } else { + createWindow(arg); + } + } + return; + } + const state = primaryState(); + if (state) { + if (state.win.isMinimized()) state.win.restore(); + state.win.focus(); + } + }); + + app.whenReady().then(() => { + loadPrefs(); + buildMenu(); + const arg = process.argv.find((a) => /\.(md|markdown|txt|mdown|mkd)$/i.test(a)); + createWindow(arg || null); + app.on('activate', () => { if (BrowserWindow.getAllWindows().length === 0) createWindow(); }); + }); + + app.on('window-all-closed', () => app.quit()); +} + +/* 供迁移测试直接驱动 */ +module.exports = { + windows, + setOpenMode, + getOpenMode: () => openMode +}; diff --git a/src/preload.js b/src/preload.js new file mode 100644 index 0000000..6900634 --- /dev/null +++ b/src/preload.js @@ -0,0 +1,59 @@ +const { contextBridge, ipcRenderer, webUtils } = require('electron'); + +contextBridge.exposeInMainWorld('api', { + open: () => ipcRenderer.invoke('file:open'), + openPath: (p) => ipcRenderer.invoke('file:openPath', p), + save: (payload) => ipcRenderer.invoke('file:save', payload), + reveal: () => ipcRenderer.invoke('file:reveal'), + revealPath: (p) => ipcRenderer.invoke('file:revealPath', p), + copyFile: (p) => ipcRenderer.invoke('file:copyFile', p), + readFileText: (p) => ipcRenderer.invoke('file:readText', p), + readClipboard: () => ipcRenderer.invoke('clip:read'), + writeClipboard: (t) => ipcRenderer.invoke('clip:write', t), + openExternal: (url) => ipcRenderer.invoke('shell:openExternal', url), + dirOpen: () => ipcRenderer.invoke('dir:open'), + dirRead: (p) => ipcRenderer.invoke('dir:read', p), + openNewWindow: (p) => ipcRenderer.invoke('window:openPath', p), + newWindow: () => ipcRenderer.invoke('window:new'), + getOpenMode: () => ipcRenderer.invoke('app:getOpenMode'), + setOpenMode: (mode) => ipcRenderer.invoke('app:setOpenMode', mode), + exportDocs: (payload) => ipcRenderer.send('docs:exported', payload), + syncDoc: (p) => ipcRenderer.send('doc:syncPath', p), + setDirty: (d) => ipcRenderer.send('app:setDirty', d), + message: (o) => ipcRenderer.invoke('ui:message', o), + saveFinished: (ok) => ipcRenderer.send('save:finished', ok), + onCommand: (cb) => ipcRenderer.on('cmd', (_e, name, payload) => cb(name, payload)) +}); + +/* 拖放:在 preload 上下文里取真实路径(Electron 32+ 已移除 File.path) */ +window.addEventListener('dragover', (e) => { e.preventDefault(); }); + +window.addEventListener('drop', (e) => { + const dt = e.dataTransfer; + if (!dt) return; + e.preventDefault(); + + const files = dt.files ? Array.from(dt.files) : []; + if (!files.length) return; + + // 逐个尝试取真实路径;取到第一个就送去开(文件或文件夹都行) + for (const file of files) { + let realPath = null; + try { + realPath = webUtils.getPathForFile(file); + } catch (_) { /* 拿不到就换兜底 */ } + + if (realPath) { + ipcRenderer.send('file:drop', realPath); + return; + } + } + + // 兜底:完全拿不到路径时,按普通文件读取内容(目录会失败,忽略) + const first = files[0]; + if (typeof first.text === 'function') { + first.text() + .then((text) => ipcRenderer.send('file:droppedText', { name: first.name, text })) + .catch(() => { /* 目录或不可读文件,忽略 */ }); + } +}); diff --git a/src/renderer/app.js b/src/renderer/app.js new file mode 100644 index 0000000..9db6f18 --- /dev/null +++ b/src/renderer/app.js @@ -0,0 +1,1494 @@ +/* 小银 Markdown 编辑器 —— 渲染进程逻辑 */ +(function () { + 'use strict'; + + const $ = (id) => document.getElementById(id); + const editor = $('editor'); + const preview = $('preview'); + const workspace = $('workspace'); + const editorPane = $('editor-pane'); + const previewPane = $('preview-pane'); + const splitter = $('splitter'); + const ctxMenu = $('ctxmenu'); + const toastEl = $('toast'); + const findbar = $('findbar'); + const findInput = $('find-input'); + const findCount = $('find-count'); + const dropHint = $('drop-hint'); + const sidebar = $('sidebar'); + const sbBody = $('sb-body'); + const sbTitle = $('sb-title'); + const editorHl = $('editor-hl'); + + const tabbar = $('tabbar'); + + const state = { + path: null, + name: null, + dirty: false, + eol: '\n', + mode: 'split', + theme: 'light', + lastSaved: '', + dir: null, + openMode: 'tabs', // tabs = 标签页;windows = 独立窗口 + tabs: [], + activeKey: null + }; + + /* ---------------- 欢迎示例 ---------------- */ + const WELCOME = `# 欢迎使用 小银 Markdown + +一个纯本地的 Windows Markdown 编辑器:左边写,右边看,随手存档。 + +## 常用按键 + +| 操作 | 快捷键 | +| --- | --- | +| 新建 / 打开 | Ctrl + N / Ctrl + O | +| 保存 / 另存为 | Ctrl + S / Ctrl + Shift + S | +| 撤销 / 重做 | Ctrl + Z / Ctrl + Y | +| 剪切 / 复制 / 粘贴 | Ctrl + X / C / V | +| 查找 | Ctrl + F | +| 复制全文 | Ctrl + Shift + C | +| 切模式 | Ctrl + 1 / 2 / 3 | +| 深色 / 浅色 | Ctrl + Shift + L | + +## 右键能干的事 + +在编辑区划右键可以**复制全文**、**打开当前文件所在文件夹**,还有剪切、复制、粘贴、全选。 + +## 语法示例 + +**加粗**、*斜体*、~~删除线~~、\`行内代码\`,还有 [链接](https://www.electronjs.org)。 + +> 引用一段话:写作是把想清楚的事情,写下来再想一遍。 + +- 无序列表 + - 支持嵌套 + - 也可以再深一层 +- 第二项 + +1. 有序列表 +2. 第二项 +3. 第三项 + +- [x] 已完成的待办 +- [ ] 待办事项 + +\`\`\`js +function hello(name) { + return \`你好,\${name}\`; +} +\`\`\` + +--- + +把 .md 文件拖进窗口可以直接打开;把**整个文件夹**拖进来,左边会列成文件树,点哪个读哪个。 + +开始写吧。 + +> 这个欢迎页关掉之后,下次启动就不会再出现了。 +`; + + /* ---------------- 工具 ---------------- */ + let toastTimer = null; + function toast(msg) { + toastEl.textContent = msg; + toastEl.hidden = false; + requestAnimationFrame(() => toastEl.classList.add('show')); + clearTimeout(toastTimer); + toastTimer = setTimeout(() => { + toastEl.classList.remove('show'); + setTimeout(() => { toastEl.hidden = true; }, 200); + }, 1600); + } + + function setDirty(d) { + if (state.dirty === d) return; + state.dirty = d; + $('st-dirty').hidden = !d; + api.setDirty(d); + const t = currentTab(); + if (t) t.dirty = d; + renderTabs(); + } + + /* ---------------- 多标签管理 ---------------- */ + function currentTab() { + return state.tabs.find((t) => t.key === state.activeKey) || null; + } + + function makeTab(doc) { + const text = doc.text || ''; + const t = { + key: 'tab-' + Date.now() + '-' + Math.random().toString(36).slice(2, 7), + path: doc.path || null, + name: doc.name || null, + text, + eol: doc.eol || '\n', + dirty: false, + lastSaved: text, + editorScroll: 0, + previewScroll: 0, + cursor: 0 + }; + if (doc.isWelcome) t.isWelcome = true; + return t; + } + + function captureTab() { + const t = currentTab(); + if (!t) return; + t.text = editor.value; + t.eol = state.eol; + t.dirty = state.dirty; + t.lastSaved = state.lastSaved; + t.editorScroll = editor.scrollTop; + t.previewScroll = preview.scrollTop; + t.cursor = editor.selectionStart; + } + + function restoreTab(t) { + captureTab(); + activateTab(t); + } + + function tabFromDoc(d) { + const t = makeTab(d); + t.path = d.path || null; + t.name = d.name || null; + t.eol = d.eol || '\n'; + t.dirty = !!d.dirty; + t.lastSaved = d.lastSaved != null ? d.lastSaved : (d.text || ''); + t.editorScroll = d.editorScroll || 0; + t.previewScroll = d.previewScroll || 0; + t.cursor = d.cursor || 0; + return t; + } + + /* 装载一个标签(不保存当前内容,供模式迁移使用) */ + function activateTab(t) { + state.activeKey = t.key; + state.path = t.path; + state.name = t.name; + setEditorText(t.text, t.eol); + state.lastSaved = t.lastSaved; + setDirty(t.dirty); + updateFileLabel(); + try { api.syncDoc(t.path); } catch (_) {} + requestAnimationFrame(() => { + editor.scrollTop = t.editorScroll || 0; + preview.scrollTop = t.previewScroll || 0; + const pos = Math.min(t.cursor || 0, editor.value.length); + editor.setSelectionRange(pos, pos); + updateCursor(); + }); + renderTabs(); + highlightTree(); + } + + function openTab(doc) { + if (state.openMode !== 'tabs') return false; + captureTab(); + if (doc.path) { + const exist = state.tabs.find((t) => t.path === doc.path); + if (exist) { restoreTab(exist); return true; } + } + const tab = makeTab(doc); + // 空白占位标签(无路径、无修改、无内容)直接被第一个打开的文档顶替 + const blank = state.tabs.find((t) => !t.path && !t.dirty && (t.text || '') === '' && !t.isWelcome); + const i = state.tabs.indexOf(blank); + if (i >= 0) state.tabs.splice(i, 1, tab); + else state.tabs.push(tab); + restoreTab(tab); + return true; + } + + function renderTabs() { + tabbar.hidden = state.openMode !== 'tabs'; + if (tabbar.hidden) return; + tabbar.innerHTML = ''; + for (const t of state.tabs) { + const el = document.createElement('div'); + el.className = 'tab' + (t.key === state.activeKey ? ' active' : '') + (t.dirty ? ' dirty' : ''); + el.dataset.key = t.key; + el.title = t.path || (t.name || '未命名'); + + const dot = document.createElement('span'); + dot.className = 'tab-dot'; + el.appendChild(dot); + + const name = document.createElement('span'); + name.className = 'tab-name'; + name.textContent = t.name || '未命名'; + el.appendChild(name); + + const close = document.createElement('span'); + close.className = 'tab-close'; + close.dataset.close = t.key; + close.title = '关闭标签'; + close.innerHTML = ''; + el.appendChild(close); + + tabbar.appendChild(el); + } + } + + async function closeTab(key) { + const idx = state.tabs.findIndex((t) => t.key === key); + if (idx < 0) return; + const t = state.tabs[idx]; + if (t.isWelcome) { + // 用户主动关掉欢迎页后,以后启动不再显示 + try { localStorage.setItem('md-editor-welcome-closed', '1'); } catch (_) {} + } + if (t.dirty) { + const r = await api.message({ + type: 'question', + message: '「' + (t.name || '未命名') + '」尚未保存', + detail: '关闭标签会丢失这些修改,是否继续?', + buttons: ['关闭', '取消'] + }); + if (r !== 0) return; + } + if (state.activeKey === key) { + captureTab(); + state.tabs.splice(idx, 1); + if (state.tabs.length) { + restoreTab(state.tabs[Math.max(0, idx - 1)]); + } else { + const fresh = makeTab({ text: '', eol: '\n', name: null, path: null }); + state.tabs.push(fresh); + restoreTab(fresh); + } + } else { + state.tabs.splice(idx, 1); + renderTabs(); + } + } + + tabbar.addEventListener('click', (e) => { + const close = e.target.closest('.tab-close'); + if (close) { e.stopPropagation(); closeTab(close.dataset.close); return; } + const tab = e.target.closest('.tab'); + if (tab && tab.dataset.key !== state.activeKey) { + restoreTab(state.tabs.find((t) => t.key === tab.dataset.key)); + } + }); + + /* 打开方式:tabs / windows */ + async function setOpenMode(mode, fromMain) { + if (mode !== 'tabs' && mode !== 'windows') return; + state.openMode = mode; + try { localStorage.setItem('md-editor-open-mode', mode); } catch (_) {} + $('openmode-label').textContent = mode === 'tabs' ? '标签' : '窗口'; + $('btn-openmode').title = mode === 'tabs' + ? '当前:标签页模式(点此改为独立窗口)' + : '当前:独立窗口模式(点此改为标签页)'; + renderTabs(); + if (!fromMain) { + try { await api.setOpenMode(mode); } catch (_) {} + } + } + + function updateFileLabel() { + $('st-file').textContent = state.name || '未命名'; + $('st-file').title = state.path || '尚未保存到磁盘'; + } + + function setEditorText(text, eol) { + editor.value = text; + state.eol = eol || '\n'; + state.lastSaved = text; + renderNow(); + updateCursor(); + scrollToTop(); + } + + function scrollToTop() { + syncLock = true; + editor.scrollTop = 0; + preview.scrollTop = 0; + requestAnimationFrame(() => { + editor.scrollTop = 0; + preview.scrollTop = 0; + requestAnimationFrame(() => { syncLock = false; }); + }); + } + + /* ---------------- 渲染 ---------------- */ + let renderTimer = null; + function scheduleRender() { + clearTimeout(renderTimer); + renderTimer = setTimeout(renderNow, 80); + } + + function renderNow() { + const text = editor.value; + const started = performance.now(); + try { + preview.innerHTML = MD.render(text); + } catch (err) { + preview.innerHTML = '

渲染出错:' + MD.escapeHtml(String(err)) + '

'; + } + if (performance.now() - started > 300) { + // 超长文档,降频 + } + updateStats(); + updateOutline(); + // 查找开着时,重渲染后恢复正文里的关键字标记 + if (!findbar.hidden && findInput.value) { + highlightEditorLayer(); + highlightPreview(); + } + } + + function updateStats() { + const s = MD.stats(editor.value); + $('st-words').textContent = s.words.toLocaleString() + ' 字'; + $('st-chars').textContent = s.chars.toLocaleString() + ' 字符'; + } + + function updateCursor() { + const pos = editor.selectionStart; + const before = editor.value.slice(0, pos); + const lines = before.split('\n'); + const line = lines.length; + const col = lines[lines.length - 1].length + 1; + $('st-cursor').textContent = '第 ' + line + ' 行, 第 ' + col + ' 列'; + } + + /* ---------------- 文件操作 ---------------- */ + async function doNew() { + if (state.dirty) { + const r = await api.message({ + type: 'question', + message: '当前内容尚未保存', + detail: '新建会清空当前编辑区,是否继续?', + buttons: ['新建', '取消'] + }); + if (r !== 0) return; + } + if (state.openMode === 'tabs') { + openTab({ text: '', eol: '\n', path: null, name: null }); + editor.focus(); + return; + } + try { await api.newWindow(); } catch (_) {} + } + + async function doOpen() { + const r = await api.open(); + if (r && r.ok) applyOpened(r); + } + + async function doOpenPath(p) { + const r = await api.openPath(p); + if (r && r.ok) applyOpened(r); + } + + function applyOpened(r) { + if (state.openMode === 'tabs') { + openTab(r); + } else { + state.path = r.path; + state.name = r.name; + setEditorText(r.text, r.eol); + setDirty(false); + updateFileLabel(); + try { api.syncDoc(r.path); } catch (_) {} + } + highlightTree(); + syncDirForFile(r.path); + toast('已打开 ' + r.name); + } + + async function doSave(saveAs) { + const r = await api.save({ content: editor.value, saveAs: !!saveAs, eol: state.eol }); + if (r && r.ok) { + state.path = r.path; + state.name = r.name; + state.lastSaved = editor.value; + const t = currentTab(); + if (t) { t.path = r.path; t.name = r.name; t.text = editor.value; t.lastSaved = editor.value; t.dirty = false; } + setDirty(false); + updateFileLabel(); + renderTabs(); + api.saveFinished(true); + toast(saveAs ? '已另存为 ' + r.name : '已保存'); + } else { + api.saveFinished(false); + } + return r; + } + + async function doReveal() { + await api.reveal(); + } + + async function doCopyAll() { + await api.writeClipboard(editor.value); + toast('已复制全文(' + editor.value.length + ' 字符)'); + } + + /* ---------------- 文件夹浏览 / 文件树 ---------------- */ + let sbDismissed = false; // 用户主动收起了侧栏 + let treeToken = 0; + + function showSidebar(show) { + sidebar.hidden = !show; + const sp = $('sb-splitter'); + if (sp) sp.hidden = !show; + $('btn-tree').classList.toggle('on', show); + try { localStorage.setItem('md-editor-sb', show ? '0' : '1'); } catch (_) {} + } + + function toggleTree() { + if (!sidebar.hidden) { sbDismissed = true; showSidebar(false); return; } + if (!state.dir) { pickFolder(); return; } + sbDismissed = false; + showSidebar(true); + } + + function showEmptySidebar() { + sbTitle.textContent = '目录'; + sbTitle.title = '把文件夹拖进窗口,或点「选择文件夹」'; + sbBody.innerHTML = ''; + const box = document.createElement('div'); + box.className = 'sb-tip'; + box.appendChild(document.createTextNode('还没有打开文件夹')); + const hint = document.createElement('div'); + hint.className = 'sb-tip-sub'; + hint.textContent = '把文件夹拖进窗口,或点下面的按钮'; + box.appendChild(hint); + const btn = document.createElement('button'); + btn.className = 'sb-pick-btn'; + btn.textContent = '选择文件夹'; + btn.addEventListener('click', pickFolder); + box.appendChild(btn); + sbBody.appendChild(box); + } + + /* 启动时恢复上次的文件夹;没有就显示引导 */ + async function initSidebar() { + sbDismissed = localStorage.getItem('md-editor-sb') === '1'; + const lastDir = localStorage.getItem('md-editor-dir'); + let loaded = false; + + if (lastDir) { + const r = await api.dirRead(lastDir); + if (r && r.ok) { + setDir(r, false); + loaded = true; + } else { + try { localStorage.removeItem('md-editor-dir'); } catch (_) {} + } + } + if (!loaded) showEmptySidebar(); + showSidebar(!sbDismissed); + } + + function shortName(p) { + const parts = String(p || '').split(/[\\/]/).filter(Boolean); + return parts.length ? parts[parts.length - 1] : String(p || ''); + } + + function renderEntries(entries, depth) { + const frag = document.createDocumentFragment(); + for (const en of entries) { + const row = document.createElement('div'); + row.className = 'tree-row' + (en.isDir ? ' is-dir' : ''); + row.dataset.path = en.path; + row.dataset.depth = String(depth); + row.style.paddingLeft = 8 + depth * 14 + 'px'; + row.title = en.path; + row.tabIndex = 0; // 可聚焦,便于 Ctrl+C 复制路径 + + const tw = document.createElement('span'); + tw.className = 'twisty'; + tw.textContent = en.isDir ? '▸' : ''; + row.appendChild(tw); + + const nm = document.createElement('span'); + nm.className = 'tree-name'; + nm.textContent = en.name; + row.appendChild(nm); + + frag.appendChild(row); + + if (en.isDir) { + const kids = document.createElement('div'); + kids.className = 'tree-children'; + kids.hidden = true; + kids.dataset.loaded = '0'; + frag.appendChild(kids); + } + } + return frag; + } + + function setDir(info, force) { + if (!info || !info.ok) return; + if (force) sbDismissed = false; + state.dir = info.path; + try { localStorage.setItem('md-editor-dir', info.path); } catch (_) {} + sbTitle.textContent = info.name || shortName(info.path); + sbTitle.title = info.path; + sbBody.innerHTML = ''; + if (!info.entries || !info.entries.length) { + const tip = document.createElement('div'); + tip.className = 'sb-tip'; + tip.textContent = '这个文件夹里没有 Markdown 文件'; + sbBody.appendChild(tip); + } else { + sbBody.appendChild(renderEntries(info.entries, 0)); + } + if (!sbDismissed) showSidebar(true); + highlightTree(); + } + + function highlightTree() { + sbBody.querySelectorAll('.tree-row.active').forEach((r) => r.classList.remove('active')); + if (!state.path) return; + for (const r of sbBody.querySelectorAll('.tree-row')) { + if (r.dataset.path === state.path) { + r.classList.add('active'); + r.scrollIntoView({ block: 'nearest' }); + break; + } + } + } + + async function toggleDirRow(row) { + const kids = row.nextElementSibling; + if (!kids || !kids.classList.contains('tree-children')) return; + const tw = row.querySelector('.twisty'); + + if (!kids.hidden) { + kids.hidden = true; + if (tw) tw.textContent = '▸'; + return; + } + + if (kids.dataset.loaded === '0') { + const token = ++treeToken; + const r = await api.dirRead(row.dataset.path); + if (token !== treeToken) return; + if (r && r.ok) { + kids.innerHTML = ''; + const depth = Number(row.dataset.depth || 0) + 1; + if (r.entries && r.entries.length) { + kids.appendChild(renderEntries(r.entries, depth)); + } else { + const empty = document.createElement('div'); + empty.className = 'tree-empty'; + empty.textContent = '(空)'; + empty.style.paddingLeft = 8 + depth * 14 + 'px'; + kids.appendChild(empty); + } + kids.dataset.loaded = '1'; + } + } + kids.hidden = false; + if (tw) tw.textContent = '▾'; + } + + async function openFromTree(p) { + if (state.path === p) return; + if (state.dirty) { + const r = await api.message({ + type: 'question', + message: '当前内容尚未保存', + detail: '打开另一个文件会覆盖编辑区,是否继续?', + buttons: ['继续打开', '取消'] + }); + if (r !== 0) return; + } + const r = await api.openPath(p); + if (r && r.ok) applyOpened(r); + } + + /* 单击只选中(聚焦,便于 Ctrl+C 复制),双击才打开 / 展开 */ + sbBody.addEventListener('click', (e) => { + const row = e.target.closest('.tree-row'); + if (!row) return; + row.focus(); + }); + + sbBody.addEventListener('dblclick', (e) => { + const row = e.target.closest('.tree-row'); + if (!row) return; + e.preventDefault(); + if (row.classList.contains('is-dir')) toggleDirRow(row); + else openFromTree(row.dataset.path); + }); + + /* 右键打开:按当前偏好决定开标签还是独立窗口 */ + async function openInNewWindow(p) { + if (state.openMode === 'tabs') { + const r = await api.openPath(p); + if (r && r.ok) { openTab(r); toast('已在新标签打开 ' + r.name); return; } + } else { + try { + const r = await api.openNewWindow(p); + if (r && r.ok) { toast('已在新窗口打开'); return; } + } catch (_) {} + } + toast('打开失败'); + } + + /* 复制文件本身:走 Windows 原生 CF_HDROP,等同于资源管理器 Ctrl+C */ + async function copyFileItem(p) { + const r = await api.copyFile(p); + if (r && r.ok) toast('已复制文件,可在文件夹里粘贴'); + else toast('复制失败:' + ((r && r.error) || '未知错误')); + } + + async function copyFileItemAsText(p) { + const r = await api.readFileText(p); + if (r && r.ok) { + await api.writeClipboard(r.text); + toast('已复制文件内容'); + } else { + toast('读取文件失败'); + } + } + + async function revealTreePath(p) { + const r = await api.revealPath(p); + if (!r || !r.ok) toast('打开失败:' + ((r && r.error) || '未知错误')); + } + + async function copyTreeName(p) { + await api.writeClipboard(shortName(p)); + toast('已复制文件名:' + shortName(p)); + } + + async function copyTreePath(p) { + await api.writeClipboard(p); + toast('已复制完整路径'); + } + + /* 文件树右键:复制文件内容 / 文件名 / 路径 / 定位 */ + sbBody.addEventListener('contextmenu', (e) => { + const row = e.target.closest('.tree-row'); + if (!row) return; + e.preventDefault(); + e.stopPropagation(); + row.focus(); + const p = row.dataset.path; + const isDir = row.classList.contains('is-dir'); + showMenu(e.clientX, e.clientY, [ + { label: state.openMode === 'tabs' ? '在新标签打开' : '在新窗口打开', action: () => openInNewWindow(p) }, + { sep: true }, + { label: '复制文件', kbd: 'Ctrl+C', action: () => copyFileItem(p) }, + { label: '复制文件内容', disabled: isDir, action: () => copyFileItemAsText(p) }, + { sep: true }, + { label: '复制文件名', action: () => copyTreeName(p) }, + { label: '复制完整路径', action: () => copyTreePath(p) }, + { sep: true }, + { label: '在资源管理器中显示', action: () => revealTreePath(p) } + ]); + }); + + async function pickFolder() { + const r = await api.dirOpen(); + if (r && r.ok) setDir(r, true); + } + + /* 打开文件后把侧栏同步到它所在目录(用户收起过侧栏就不再弹出) */ + async function syncDirForFile(filePath) { + if (!filePath) return; + const dir = String(filePath).replace(/[\\/][^\\/]+$/, ''); + if (!dir || dir === filePath) return; + if (state.dir === dir) { highlightTree(); return; } + const r = await api.dirRead(dir); + if (r && r.ok) setDir(r, false); + } + + /* ---------------- 模式 / 主题 / 缩放 ---------------- */ + function setMode(mode) { + state.mode = mode; + workspace.dataset.mode = mode; + document.querySelectorAll('#mode-seg button').forEach((b) => { + b.classList.toggle('active', b.dataset.mode === mode); + }); + localStorage.setItem('md-editor-mode', mode); + if (mode !== 'edit') renderNow(); + } + + function setTheme(theme) { + state.theme = theme; + document.documentElement.dataset.theme = theme; + localStorage.setItem('md-editor-theme', theme); + } + + let zoom = 1; + function applyZoom(delta) { + if (delta === 0) zoom = 1; + else zoom = Math.min(1.6, Math.max(0.8, +(zoom + delta * 0.1).toFixed(2))); + document.documentElement.style.setProperty('--zoom', zoom); + editor.style.fontSize = (13.5 * zoom).toFixed(1) + 'px'; + if (editorHl) editorHl.style.fontSize = (13.5 * zoom).toFixed(1) + 'px'; + preview.style.fontSize = (14.5 * zoom).toFixed(1) + 'px'; + } + + /* ---------------- 查找 ---------------- */ + let findMatches = []; + let findIndex = -1; + + /* 预览正文里的关键字背景标记 */ + let previewHits = []; + function clearPreviewHits() { + preview.querySelectorAll('mark.find-hit').forEach((m) => { + const p = m.parentNode; + if (!p) return; + p.replaceChild(document.createTextNode(m.textContent), m); + p.normalize(); + }); + previewHits = []; + } + + function highlightPreview() { + clearPreviewHits(); + const q = (findInput.value || '').toLowerCase(); + if (!q || findbar.hidden) return; + const walker = document.createTreeWalker(preview, NodeFilter.SHOW_TEXT, { + acceptNode(node) { + if (!node.nodeValue || !node.nodeValue.toLowerCase().includes(q)) return NodeFilter.FILTER_REJECT; + const p = node.parentNode; + if (p && (p.nodeName === 'MARK' || p.nodeName === 'SCRIPT' || p.nodeName === 'STYLE')) return NodeFilter.FILTER_REJECT; + return NodeFilter.FILTER_ACCEPT; + } + }); + const nodes = []; + let n; + while ((n = walker.nextNode())) nodes.push(n); + nodes.forEach((node) => { + const lower = node.nodeValue.toLowerCase(); + const at = []; + let i = lower.indexOf(q); + while (i !== -1) { at.push(i); i = lower.indexOf(q, i + q.length); } + for (let k = at.length - 1; k >= 0; k--) { + const range = document.createRange(); + range.setStart(node, at[k]); + range.setEnd(node, at[k] + q.length); + const mark = document.createElement('mark'); + mark.className = 'find-hit'; + try { range.surroundContents(mark); } catch (_) { /* 跨元素边界,跳过 */ } + } + }); + previewHits = [...preview.querySelectorAll('mark.find-hit')]; + if (findIndex >= 0 && findIndex < previewHits.length) { + previewHits[findIndex].classList.add('find-hit-active'); + } + } + + function openFind() { + findbar.hidden = false; + findInput.focus(); + findInput.select(); + if (state.mode === 'read') setMode('split'); + } + + /* 编辑器叠加层:把所有匹配染上背景色,当前命中更深 */ + function highlightEditorLayer() { + if (!editorHl) return; + if (findbar.hidden || !findInput.value) { editorHl.innerHTML = ''; return; } + const esc = MD.escapeHtml(editor.value); + const re = new RegExp(findInput.value.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'), 'gi'); + let count = 0; + editorHl.innerHTML = esc.replace(re, (m) => { + const cls = count === findIndex ? ' class="find-hit-active"' : ''; + count++; + return '' + m + ''; + }); + editorHl.scrollTop = editor.scrollTop; + editorHl.scrollLeft = editor.scrollLeft; + } + + function closeFind() { + findbar.hidden = true; + findMatches = []; + findIndex = -1; + findCount.textContent = ''; + clearPreviewHits(); + if (editorHl) editorHl.innerHTML = ''; + editor.focus(); + } + + function collectMatches() { + const q = findInput.value; + findMatches = []; + if (!q) { findCount.textContent = ''; return; } + const hay = editor.value.toLowerCase(); + const needle = q.toLowerCase(); + let idx = hay.indexOf(needle); + while (idx !== -1) { + findMatches.push(idx); + idx = hay.indexOf(needle, idx + needle.length); + } + findCount.textContent = findMatches.length ? '共 ' + findMatches.length + ' 处' : '无匹配'; + } + + function selectMatch(i) { + if (!findMatches.length) return; + findIndex = (i + findMatches.length) % findMatches.length; + const start = findMatches[findIndex]; + editor.focus(); + editor.setSelectionRange(start, start + findInput.value.length); + // 粗略滚动到可见 + const lineHeight = parseFloat(getComputedStyle(editor).lineHeight) || 23; + const line = editor.value.slice(0, start).split('\n').length - 1; + const target = line * lineHeight; + if (target < editor.scrollTop || target > editor.scrollTop + editor.clientHeight - 80) { + editor.scrollTop = Math.max(0, target - editor.clientHeight / 2); + } + // 预览正文同步标记当前命中 + previewHits.forEach((m) => m.classList.remove('find-hit-active')); + const m = previewHits[findIndex]; + if (m) { + m.classList.add('find-hit-active'); + try { m.scrollIntoView({ block: 'center' }); } catch (_) {} + } + // 编辑器叠加层的当前命中刷新 + highlightEditorLayer(); + findCount.textContent = (findIndex + 1) + ' / ' + findMatches.length; + } + + function findNext(back) { + if (!findbar.hidden && findInput.value) { + collectMatches(); + if (!findMatches.length) return; + selectMatch(back ? findIndex - 1 : findIndex + 1); + } + } + + /* ---------------- 右键菜单 ---------------- */ + const KEY = { cut: 'Ctrl+X', copy: 'Ctrl+C', paste: 'Ctrl+V', selectAll: 'Ctrl+A', undo: 'Ctrl+Z', redo: 'Ctrl+Y' }; + + function buildMenu(items) { + ctxMenu.innerHTML = ''; + items.forEach((it) => { + if (it.sep) { + const d = document.createElement('div'); + d.className = 'ctx-sep'; + ctxMenu.appendChild(d); + return; + } + const d = document.createElement('div'); + d.className = 'ctx-item' + (it.disabled ? ' disabled' : ''); + const label = document.createElement('span'); + label.textContent = it.label; + d.appendChild(label); + if (it.kbd) { + const k = document.createElement('span'); + k.className = 'kbd'; + k.textContent = it.kbd; + d.appendChild(k); + } + d.addEventListener('mousedown', (e) => { e.preventDefault(); e.stopPropagation(); }); + d.addEventListener('click', () => { hideMenu(); it.action(); }); + ctxMenu.appendChild(d); + }); + } + + function showMenu(x, y, items) { + buildMenu(items); + ctxMenu.hidden = false; + const rect = ctxMenu.getBoundingClientRect(); + const px = Math.min(x, window.innerWidth - rect.width - 8); + const py = Math.min(y, window.innerHeight - rect.height - 8); + ctxMenu.style.left = Math.max(6, px) + 'px'; + ctxMenu.style.top = Math.max(6, py) + 'px'; + } + + function hideMenu() { ctxMenu.hidden = true; } + + document.addEventListener('mousedown', (e) => { + if (!ctxMenu.hidden && !ctxMenu.contains(e.target)) hideMenu(); + }); + window.addEventListener('blur', hideMenu); + window.addEventListener('resize', hideMenu); + + function hasSelection() { + return editor.selectionEnd > editor.selectionStart; + } + + editor.addEventListener('contextmenu', (e) => { + e.preventDefault(); + const sel = hasSelection(); + showMenu(e.clientX, e.clientY, [ + { label: '撤销', kbd: KEY.undo, action: () => { editor.focus(); document.execCommand('undo'); } }, + { label: '重做', kbd: KEY.redo, action: () => { editor.focus(); document.execCommand('redo'); } }, + { sep: true }, + { label: '剪切', kbd: KEY.cut, disabled: !sel, action: () => { editor.focus(); document.execCommand('cut'); } }, + { label: '复制', kbd: KEY.copy, disabled: !sel, action: () => { editor.focus(); document.execCommand('copy'); } }, + { label: '粘贴', kbd: KEY.paste, action: pasteIntoEditor }, + { label: '全选', kbd: KEY.selectAll, action: () => { editor.focus(); editor.select(); } }, + { sep: true }, + { label: '复制全文', kbd: 'Ctrl+Shift+C', action: doCopyAll }, + { label: '打开文件所在文件夹', kbd: 'Ctrl+Shift+O', action: doReveal } + ]); + }); + + previewPane.addEventListener('contextmenu', (e) => { + e.preventDefault(); + const selText = String(window.getSelection() || ''); + showMenu(e.clientX, e.clientY, [ + { label: '复制选中内容', kbd: 'Ctrl+C', disabled: !selText, action: () => { api.writeClipboard(selText); toast('已复制选中内容'); } }, + { label: '复制全文', kbd: 'Ctrl+Shift+C', action: doCopyAll }, + { sep: true }, + { label: '打开文件所在文件夹', kbd: 'Ctrl+Shift+O', action: doReveal } + ]); + }); + + async function pasteIntoEditor() { + const text = await api.readClipboard(); + editor.focus(); + // 用 insertText 让粘贴进入原生撤销栈 + if (text) document.execCommand('insertText', false, text); + } + + /* ---------------- 编辑区行为 ---------------- */ + editor.addEventListener('input', () => { + setDirty(editor.value !== state.lastSaved); + scheduleRender(); + updateCursor(); + if (!findbar.hidden && findInput.value) collectMatches(); + }); + + editor.addEventListener('keyup', updateCursor); + editor.addEventListener('click', updateCursor); + editor.addEventListener('select', updateCursor); + + editor.addEventListener('keydown', (e) => { + // Tab 缩进 + if (e.key === 'Tab') { + e.preventDefault(); + document.execCommand('insertText', false, ' '); + return; + } + // 回车续列表 + if (e.key === 'Enter' && !e.shiftKey && !e.ctrlKey && !e.altKey) { + const pos = editor.selectionStart; + if (pos !== editor.selectionEnd) return; + const before = editor.value.slice(0, pos); + const lineStart = before.lastIndexOf('\n') + 1; + const line = before.slice(lineStart); + const m = /^(\s*)([-*+]|\d{1,9}[.)])(\s+)(\[[ xX]\]\s+)?(.*)$/.exec(line); + if (m) { + const hasContent = m[5].trim().length > 0; + if (hasContent) { + e.preventDefault(); + let marker; + if (/\d/.test(m[2])) { + marker = (parseInt(m[2], 10) + 1) + m[2].slice(-1); + } else { + marker = m[2]; + } + const insert = '\n' + m[1] + marker + ' ' + (m[4] ? '[ ] ' : ''); + document.execCommand('insertText', false, insert); + } else { + // 空列表项回车 → 结束该列表 + e.preventDefault(); + const start = lineStart; + editor.setSelectionRange(start, pos); + document.execCommand('insertText', false, ''); + } + } + } + // Esc 关闭查找 + if (e.key === 'Escape' && !findbar.hidden) { + e.preventDefault(); + closeFind(); + } + }); + + /* ---------------- 预览交互 ---------------- */ + preview.addEventListener('click', (e) => { + const a = e.target.closest('a'); + if (!a) return; + e.preventDefault(); + const href = a.getAttribute('href') || ''; + if (/^https?:/i.test(href)) api.openExternal(href); + else if (href.startsWith('#')) { + const el = preview.querySelector(href) || preview.querySelector('[id="' + href.slice(1) + '"]'); + if (el) el.scrollIntoView({ behavior: 'smooth', block: 'start' }); + } else if (href && href !== '#') { + api.openExternal(href); + } + }); + + /* ---------------- 章节大纲 ---------------- */ + const outlineEl = $('outline'); + const olBody = $('ol-body'); + const olCount = $('ol-count'); + let outlineItems = []; + let activeHeading = -1; + + function setOutlineVisible(show, persist) { + outlineEl.hidden = !show; + const sp = $('ol-splitter'); + if (sp) sp.hidden = !show; + $('btn-outline').classList.toggle('on', show); + if (persist !== false) { + try { localStorage.setItem('md-editor-outline', show ? '1' : '0'); } catch (_) {} + } + if (show) syncOutlineActive(); + } + + function toggleOutline() { + setOutlineVisible(outlineEl.hidden); + } + + function updateOutline() { + const heads = Array.prototype.slice.call(preview.querySelectorAll('h1,h2,h3,h4,h5,h6')); + outlineItems = heads.map((h) => ({ + level: Number(h.tagName.charAt(1)), + text: (h.textContent || '').trim() || '(无标题)', + line: Number(h.dataset.line || 0) + })); + + olBody.innerHTML = ''; + if (!outlineItems.length) { + olCount.textContent = '0'; + const empty = document.createElement('div'); + empty.className = 'ol-empty'; + empty.textContent = '本文还没有标题,用 # 号写下小标题就会出现在这里'; + olBody.appendChild(empty); + activeHeading = -1; + return; + } + + olCount.textContent = String(outlineItems.length); + const frag = document.createDocumentFragment(); + outlineItems.forEach((it, idx) => { + const row = document.createElement('div'); + row.className = 'ol-item'; + row.dataset.idx = String(idx); + row.dataset.level = String(it.level); + row.style.paddingLeft = 10 + (it.level - 1) * 13 + 'px'; + row.textContent = it.text; + row.title = it.text; + frag.appendChild(row); + }); + olBody.appendChild(frag); + + if (activeHeading >= outlineItems.length) activeHeading = -1; + if (activeHeading >= 0) markActiveHeading(activeHeading, false); + } + + function markActiveHeading(idx, doScroll) { + activeHeading = idx; + const rows = olBody.querySelectorAll('.ol-item'); + for (let k = 0; k < rows.length; k++) rows[k].classList.toggle('active', k === idx); + const row = rows[idx]; + if (row && doScroll !== false) row.scrollIntoView({ block: 'nearest' }); + } + + function lineToOffset(line) { + const lines = editor.value.split('\n'); + let off = 0; + for (let k = 0; k < line && k < lines.length; k++) off += lines[k].length + 1; + return Math.min(off, editor.value.length); + } + + function jumpToHeading(idx) { + const it = outlineItems[idx]; + if (!it) return; + + // 编辑区与预览各滚各的,先压住滚动同步,免得互相拉扯 + suppressSyncUntil = Date.now() + 650; + + if (state.mode !== 'edit') { + const heads = preview.querySelectorAll('h1,h2,h3,h4,h5,h6'); + const h = heads[idx]; + if (h) { + const boxTop = preview.getBoundingClientRect().top; + const top = h.getBoundingClientRect().top - boxTop + preview.scrollTop - 10; + preview.scrollTo({ top: Math.max(0, top), behavior: 'smooth' }); + } + } + + if (state.mode !== 'read') { + const lh = parseFloat(getComputedStyle(editor).lineHeight) || 23; + const top = Math.max(0, it.line * lh - editor.clientHeight * 0.3); + editor.scrollTo({ top, behavior: 'smooth' }); + const pos = lineToOffset(it.line); + editor.focus(); + editor.setSelectionRange(pos, pos); + updateCursor(); + } + + markActiveHeading(idx); + } + + /* 预览滚动时高亮当前所在章节 */ + function syncOutlineActive() { + if (outlineEl.hidden || !outlineItems.length || state.mode === 'edit') return; + const heads = preview.querySelectorAll('h1,h2,h3,h4,h5,h6'); + if (!heads.length) return; + const line = preview.getBoundingClientRect().top + 30; + let idx = 0; + for (let k = 0; k < heads.length; k++) { + if (heads[k].getBoundingClientRect().top <= line) idx = k; + else break; + } + if (idx !== activeHeading) markActiveHeading(idx, false); + } + + olBody.addEventListener('click', (e) => { + const row = e.target.closest('.ol-item'); + if (!row) return; + jumpToHeading(Number(row.dataset.idx)); + }); + + /* ---------------- 滚动同步 ---------------- */ + let syncLock = false; + let suppressSyncUntil = 0; + editor.addEventListener('scroll', () => { + // 高亮层跟随滚动(与模式无关) + if (editorHl) { + editorHl.scrollTop = editor.scrollTop; + editorHl.scrollLeft = editor.scrollLeft; + } + if (state.mode !== 'split' || syncLock) return; + if (Date.now() < suppressSyncUntil) return; + syncLock = true; + const denom = Math.max(1, editor.scrollHeight - editor.clientHeight); + const ratio = editor.scrollTop / denom; + preview.scrollTop = ratio * Math.max(0, preview.scrollHeight - preview.clientHeight); + requestAnimationFrame(() => { syncLock = false; }); + }); + + preview.addEventListener('scroll', () => { + syncOutlineActive(); + if (state.mode !== 'split' || syncLock) return; + if (Date.now() < suppressSyncUntil) return; + syncLock = true; + const denom = Math.max(1, preview.scrollHeight - preview.clientHeight); + const ratio = preview.scrollTop / denom; + editor.scrollTop = ratio * Math.max(0, editor.scrollHeight - editor.clientHeight); + requestAnimationFrame(() => { syncLock = false; }); + }); + + /* ---------------- 分栏拖动 ---------------- */ + let dragging = false; + splitter.addEventListener('mousedown', (e) => { + if (state.mode !== 'split') return; + dragging = true; + splitter.classList.add('dragging'); + document.body.classList.add('resizing'); + e.preventDefault(); + }); + + document.addEventListener('mousemove', (e) => { + if (!dragging) return; + const rect = workspace.getBoundingClientRect(); + let w = e.clientX - rect.left; + const min = 220; + const max = rect.width - min; + w = Math.min(max, Math.max(min, w)); + editorPane.style.flex = '0 0 ' + w + 'px'; + previewPane.style.flex = '1 1 0'; + editorPane.dataset.split = String(w); + }); + + document.addEventListener('mouseup', () => { + if (!dragging) return; + dragging = false; + splitter.classList.remove('dragging'); + document.body.classList.remove('resizing'); + // 记住分栏比例(按工作区宽度的百分比,窗口大小变了也合理) + const rect = workspace.getBoundingClientRect(); + const pct = editorPane.getBoundingClientRect().width / rect.width; + if (pct > 0.15 && pct < 0.85) { + try { localStorage.setItem('md-editor-split-pct', String(pct)); } catch (_) {} + } + }); + + /* ---------------- 目录 / 大纲宽度拖动(记住宽度) ---------------- */ + const sbSplitter = $('sb-splitter'); + const olSplitter = $('ol-splitter'); + let panelDrag = null; // 'sb' | 'ol' + + function clampPanelWidth(w, min) { + const max = Math.floor(workspace.getBoundingClientRect().width * 0.6); + return Math.max(min, Math.min(max, w)); + } + function applySidebarWidth(w) { + w = clampPanelWidth(w, 180); + sidebar.style.flexBasis = w + 'px'; + return w; + } + function applyOutlineWidth(w) { + w = clampPanelWidth(w, 160); + outlineEl.style.flexBasis = w + 'px'; + return w; + } + function restorePanelWidths() { + try { + const sw = parseInt(localStorage.getItem('md-editor-sb-w'), 10); + if (sw) applySidebarWidth(sw); + const ow = parseInt(localStorage.getItem('md-editor-ol-w'), 10); + if (ow) applyOutlineWidth(ow); + } catch (_) {} + } + + sbSplitter.addEventListener('mousedown', (e) => { + if (sidebar.hidden) return; + panelDrag = 'sb'; + sbSplitter.classList.add('dragging'); + document.body.classList.add('resizing'); + e.preventDefault(); + }); + olSplitter.addEventListener('mousedown', (e) => { + if (outlineEl.hidden) return; + panelDrag = 'ol'; + olSplitter.classList.add('dragging'); + document.body.classList.add('resizing'); + e.preventDefault(); + }); + + document.addEventListener('mousemove', (e) => { + if (!panelDrag) return; + const rect = workspace.getBoundingClientRect(); + if (panelDrag === 'sb') { + sidebar.dataset.w = String(applySidebarWidth(e.clientX - rect.left)); + } else { + outlineEl.dataset.w = String(applyOutlineWidth(rect.right - e.clientX)); + } + }); + + document.addEventListener('mouseup', () => { + if (!panelDrag) return; + const key = panelDrag === 'sb' ? 'md-editor-sb-w' : 'md-editor-ol-w'; + const val = panelDrag === 'sb' ? sidebar.dataset.w : outlineEl.dataset.w; + if (val) { try { localStorage.setItem(key, val); } catch (_) {} } + (panelDrag === 'sb' ? sbSplitter : olSplitter).classList.remove('dragging'); + document.body.classList.remove('resizing'); + panelDrag = null; + }); + + /* ---------------- 拖放打开 ---------------- */ + let dragDepth = 0; + document.addEventListener('dragenter', (e) => { + e.preventDefault(); + dragDepth++; + if (e.dataTransfer && Array.from(e.dataTransfer.types).includes('Files')) dropHint.hidden = false; + }); + document.addEventListener('dragover', (e) => { e.preventDefault(); }); + document.addEventListener('dragleave', (e) => { + e.preventDefault(); + dragDepth = Math.max(0, dragDepth - 1); + if (dragDepth === 0) dropHint.hidden = true; + }); + document.addEventListener('drop', (e) => { + e.preventDefault(); + dragDepth = 0; + dropHint.hidden = true; + }); + + /* ---------------- 主进程指令 ---------------- */ + api.onCommand(async (name, payload) => { + switch (name) { + case 'new': doNew(); break; + case 'open': doOpen(); break; + case 'save': doSave(false); break; + case 'saveAs': doSave(true); break; + case 'openDir': doReveal(); break; + case 'openFolder': pickFolder(); break; + case 'dir-opened': setDir(payload, true); break; + case 'copyAll': doCopyAll(); break; + case 'find': openFind(); break; + case 'mode': setMode(payload); break; + case 'outline': toggleOutline(); break; + case 'tree': toggleTree(); break; + case 'open-mode': setOpenMode(payload, true); break; + case 'export-docs': { + captureTab(); + const docs = state.tabs.map((t) => Object.assign({}, t)); + api.exportDocs({ docs }); + break; + } + case 'adopt-tabs': { + const docs = Array.isArray(payload) ? payload : []; + if (!docs.length) break; + state.tabs = docs.map(tabFromDoc); + activateTab(state.tabs[0]); + toast('已合并为 ' + state.tabs.length + ' 个标签'); + break; + } + case 'adopt-doc': { + if (!payload) break; + const t = tabFromDoc(payload); + state.tabs = [t]; + activateTab(t); + break; + } + case 'newWindow': + if (state.path) openInNewWindow(state.path); + else { try { api.newWindow(); } catch (_) {} } + break; + case 'theme': setTheme(state.theme === 'dark' ? 'light' : 'dark'); break; + case 'zoom': applyZoom(payload); break; + case 'file-opened': applyOpened(payload); break; + case 'open-external': doOpenPath(payload); break; + case 'dropped-path': doOpenPath(payload); break; + case 'dropped-text': { + if (state.dirty) { + const r = await api.message({ message: '当前内容尚未保存', detail: '打开新文件会覆盖当前编辑区,是否继续?', buttons: ['继续', '取消'], type: 'question' }); + if (r !== 0) break; + } + state.path = null; + state.name = payload.name || null; + setEditorText(payload.text, '\n'); + setDirty(false); + updateFileLabel(); + try { api.syncDoc(null); } catch (_) {} + break; + } + } + }); + + /* 模式迁移时,各窗口交出自己的标签文档 */ + api.onExport(() => { + captureTab(); + return state.tabs.map((t) => Object.assign({}, t)); + }); + + /* 窗口关闭确认(Tauri: CloseRequested → close-confirm 事件) */ + api.onCloseConfirm(async () => { + const dirtyTab = state.tabs.find((t) => t.dirty); + if (!dirtyTab) { api.closeWindow(); return; } + const r = await api.message({ + type: 'question', + message: '「' + (dirtyTab.name || '未命名') + '」还有未保存的修改', + detail: '是否先保存再退出?', + buttons: ['取消', '不保存', '保存'] + }); + if (r === 1) { api.closeWindow(); return; } + if (r === 2) { + activateTab(dirtyTab); + const rr = await doSave(!dirtyTab.path); + if (!rr || !rr.ok) return; + api.closeWindow(); + } + /* r === 0 取消:什么都不做,窗口留着 */ + }); + + /* ---------------- 按钮绑定 ---------------- */ + $('btn-new').addEventListener('click', doNew); + $('btn-open').addEventListener('click', doOpen); + $('btn-tree').addEventListener('click', toggleTree); + $('btn-outline').addEventListener('click', toggleOutline); + $('sb-pick').addEventListener('click', pickFolder); + $('sb-close').addEventListener('click', () => { sbDismissed = true; showSidebar(false); }); + $('btn-save').addEventListener('click', () => doSave(false)); + $('btn-saveas').addEventListener('click', () => doSave(true)); + $('btn-undo').addEventListener('click', () => { editor.focus(); document.execCommand('undo'); }); + $('btn-redo').addEventListener('click', () => { editor.focus(); document.execCommand('redo'); }); + $('btn-find').addEventListener('click', openFind); + $('btn-copyall').addEventListener('click', doCopyAll); + $('btn-dir').addEventListener('click', doReveal); + $('btn-theme').addEventListener('click', () => setTheme(state.theme === 'dark' ? 'light' : 'dark')); + $('btn-openmode').addEventListener('click', () => setOpenMode(state.openMode === 'tabs' ? 'windows' : 'tabs')); + $('btn-outline').addEventListener('click', toggleOutline); + $('ol-close').addEventListener('click', () => setOutlineVisible(false)); + + document.querySelectorAll('#mode-seg button').forEach((b) => { + b.addEventListener('click', () => setMode(b.dataset.mode)); + }); + + $('find-next').addEventListener('click', () => findNext(false)); + $('find-prev').addEventListener('click', () => findNext(true)); + $('find-close').addEventListener('click', closeFind); + + findInput.addEventListener('input', () => { + collectMatches(); + findIndex = -1; + highlightEditorLayer(); + highlightPreview(); + if (findMatches.length) selectMatch(0); + }); + + findInput.addEventListener('keydown', (e) => { + if (e.key === 'Enter') { e.preventDefault(); findNext(e.shiftKey); } + if (e.key === 'Escape') { e.preventDefault(); closeFind(); } + }); + + // Ctrl+F 兜底(菜单已注册,双保险) + window.addEventListener('keydown', (e) => { + const ctrl = e.ctrlKey || e.metaKey; + if (ctrl && e.key.toLowerCase() === 'f') { e.preventDefault(); openFind(); } + + // 焦点在文件树的条目上 → Ctrl+C 复制文件本身(不是路径文字) + if (ctrl && !e.shiftKey && !e.altKey && e.key.toLowerCase() === 'c') { + const el = document.activeElement; + const row = el && el.closest ? el.closest('.tree-row') : null; + if (row && sbBody.contains(row)) { + e.preventDefault(); + copyFileItem(row.dataset.path); + } + } + + /* 以下快捷键原由应用菜单注册(Electron),Tauri 版统一在前端处理 */ + if (ctrl && e.key.toLowerCase() === 's') { e.preventDefault(); doSave(e.shiftKey); return; } + if (ctrl && !e.shiftKey && !e.altKey && e.key.toLowerCase() === 'n') { e.preventDefault(); doNew(); return; } + if (ctrl && !e.shiftKey && !e.altKey && e.key.toLowerCase() === 'o') { e.preventDefault(); doOpen(); return; } + if (ctrl && e.shiftKey && !e.altKey && e.key.toLowerCase() === 'o') { e.preventDefault(); pickFolder(); return; } + if (ctrl && e.shiftKey && !e.altKey && e.key.toLowerCase() === 'c') { e.preventDefault(); doCopyAll(); return; } + if (ctrl && !e.shiftKey && !e.altKey && (e.key === '1' || e.key === '2' || e.key === '3')) { + e.preventDefault(); + setMode(e.key === '1' ? 'edit' : e.key === '2' ? 'split' : 'read'); + return; + } + if (ctrl && (e.key === '=' || e.key === '+')) { e.preventDefault(); applyZoom(1); return; } + if (ctrl && e.key === '-') { e.preventDefault(); applyZoom(-1); return; } + if (ctrl && e.key === '0') { e.preventDefault(); applyZoom(0); return; } + + if (e.key === 'Escape' && !ctxMenu.hidden) hideMenu(); + }); + + /* ---------------- 启动 ---------------- */ + async function boot() { + const savedTheme = localStorage.getItem('md-editor-theme'); + setTheme(savedTheme || (window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light')); + setMode(localStorage.getItem('md-editor-mode') || 'split'); + setOutlineVisible(localStorage.getItem('md-editor-outline') !== '0', false); + + // 打开方式:主进程偏好优先,其次本地缓存 + let openMode = localStorage.getItem('md-editor-open-mode') || 'tabs'; + try { + const m = await api.getOpenMode(); + if (m && (m.mode === 'tabs' || m.mode === 'windows')) openMode = m.mode; + } catch (_) { /* 测试环境未注册时忽略 */ } + await setOpenMode(openMode, true); + restorePanelWidths(); + + // 恢复分栏比例;欢迎页一旦被用户关闭过,就不再显示 + const splitPct = parseFloat(localStorage.getItem('md-editor-split-pct')); + if (splitPct > 0.15 && splitPct < 0.85) { + editorPane.style.flex = '0 0 ' + (splitPct * 100).toFixed(2) + '%'; + } + const welcomeClosed = localStorage.getItem('md-editor-welcome-closed') === '1'; + const firstTab = welcomeClosed + ? makeTab({ text: '', eol: '\n', name: null, path: null }) + : makeTab({ text: WELCOME, eol: '\n', name: null, path: null, isWelcome: true }); + state.tabs = [firstTab]; + state.activeKey = firstTab.key; + setEditorText(firstTab.text, '\n'); + setDirty(false); + updateFileLabel(); + editor.focus(); + editor.setSelectionRange(0, 0); + updateCursor(); + renderTabs(); + + await initSidebar(); + } + + boot(); +})(); diff --git a/src/renderer/index.html b/src/renderer/index.html new file mode 100644 index 0000000..09b1c10 --- /dev/null +++ b/src/renderer/index.html @@ -0,0 +1,176 @@ + + + + + + 小银 Markdown + + + +
+ + +
+
+ 小银 Markdown +
+ +
+ +
+ + + + +
+ +
+ +
+ + + + + +
+ +
+ + + +
+ + + +
+ + + + + + +
+ + +
+ + + + + +
+ + +
+ +
+
+ + +
+
+ +
+ +
+
+
+ +
+ + +
+ + +
+
+ 未命名 + +
+
+ 0 字 + | + 0 字符 + | + 第 1 行, 第 1 列 + | + UTF-8 +
+
+ + + + + +
+ + + + + + diff --git a/src/renderer/markdown.js b/src/renderer/markdown.js new file mode 100644 index 0000000..969303b --- /dev/null +++ b/src/renderer/markdown.js @@ -0,0 +1,291 @@ +/* + * 轻量 Markdown 渲染引擎(零依赖,纯本地) + * 支持:标题 / 粗体 / 斜体 / 删除线 / 行内代码 / 代码块 / 引用 / 有序无序列表 / + * 嵌套列表 / 任务列表 / 表格(含对齐)/ 分割线 / 链接 / 图片 / 自动链接 + * 所有原始 HTML 均被转义,避免脚本注入。 + */ +(function (global) { + 'use strict'; + + const ESC_MAP = { '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }; + const escapeHtml = (s) => String(s).replace(/[&<>"']/g, (c) => ESC_MAP[c]); + + function safeUrl(u) { + const t = String(u).trim(); + const flat = t.replace(/[\s\u0000-\u001f]/g, ''); + if (/^(javascript|vbscript|data):/i.test(flat)) return '#'; + return escapeHtml(t); + } + + const PH = '\u0000'; + + /* ------------------------- 行内渲染 ------------------------- */ + function renderInline(text) { + let s = escapeHtml(text); + const slots = []; + const put = (html) => { slots.push(html); return PH + (slots.length - 1) + PH; }; + + // 行内代码(先摘出来,避免内部语法被解析) + s = s.replace(/(`+)([\s\S]*?)\1/g, (_m, _t, code) => put('' + code.replace(/^ | $/g, '') + '')); + + // 图片 + s = s.replace(/!\[([^\]]*)\]\(\s*([^\s)]+)\s*\)/g, + (_m, alt, src) => put('' + alt + '')); + + // 链接 + s = s.replace(/\[([^\]]+)\]\(\s*([^\s)]+)\s*\)/g, + (_m, label, href) => put('' + label + '')); + + // 裸链接 + s = s.replace(/(^|[\s(])(https?:\/\/[^\s<)\]]+)/g, + (_m, pre, url) => pre + put('' + url + '')); + + // 强调 + s = s.replace(/\*\*\*([^*\n]+)\*\*\*/g, '$1'); + s = s.replace(/\*\*([^*\n]+)\*\*/g, '$1'); + s = s.replace(/(^|[^\w_])__([^_\n]+)__/g, '$1$2'); + s = s.replace(/(^|[^*])\*([^*\n]+)\*/g, '$1$2'); + s = s.replace(/(^|[^\w_])_([^_\n]+)_/g, '$1$2'); + s = s.replace(/~~([^~\n]+)~~/g, '$1'); + + // 还原占位符 + s = s.replace(/\u0000(\d+)\u0000/g, (_m, i) => slots[Number(i)]); + return s; + } + + function inlineWithBreaks(text) { + return renderInline(text).replace(/\n/g, '
'); + } + + /* ------------------------- 块级解析 ------------------------- */ + const RE_FENCE = /^(\s*)(`{3,}|~{3,})\s*([^\s`]*)\s*$/; + const RE_HEADING = /^\s{0,3}(#{1,6})\s+(.*?)\s*#*\s*$/; + const RE_HR = /^\s{0,3}([-*_])(?:\s*\1){2,}\s*$/; + const RE_QUOTE = /^\s{0,3}>\s?/; + const RE_ITEM = /^(\s*)([-*+]|\d{1,9}[.)])(\s+)(.*)$/; + const RE_TASK = /^\[([ xX])\]\s+/; + + function isTableSep(line) { + if (!line || !line.includes('|')) return false; + const cells = splitRow(line); + return cells.length > 0 && cells.every((c) => /^:?-{1,}:?$/.test(c.trim())); + } + + function splitRow(line) { + let s = line.trim(); + if (s.startsWith('|')) s = s.slice(1); + if (s.endsWith('|')) s = s.slice(0, -1); + return s.split('|').map((c) => c.trim()); + } + + function parseBlocks(lines, base) { + base = base || 0; + const out = []; + let i = 0; + + while (i < lines.length) { + const line = lines[i]; + + // 空行 + if (/^\s*$/.test(line)) { i++; continue; } + + // 代码块 + let m = RE_FENCE.exec(line); + if (m) { + const fenceChar = m[2][0]; + const fenceLen = m[2].length; + const lang = m[3] || ''; + const closer = new RegExp('^\\s*' + (fenceChar === '`' ? '`' : '~') + '{' + fenceLen + ',}\\s*$'); + const buf = []; + i++; + while (i < lines.length && !closer.test(lines[i])) { buf.push(lines[i]); i++; } + i++; // 跳过闭合行 + out.push( + '
' + + (lang ? '' + escapeHtml(lang) + '' : '') + + '
' + escapeHtml(buf.join('\n')) + '
' + ); + continue; + } + + // 分割线 + if (RE_HR.test(line)) { out.push('
'); i++; continue; } + + // 标题(带原始行号,供大纲跳转用) + m = RE_HEADING.exec(line); + if (m) { + const lv = m[1].length; + out.push('' + renderInline(m[2]) + ''); + i++; + continue; + } + + // 引用 + if (RE_QUOTE.test(line)) { + const buf = []; + const startAt = i; + while (i < lines.length && RE_QUOTE.test(lines[i])) { + buf.push(lines[i].replace(RE_QUOTE, '')); + i++; + } + out.push('
' + parseBlocks(buf, base + startAt) + '
'); + continue; + } + + // 表格 + if (line.includes('|') && i + 1 < lines.length && isTableSep(lines[i + 1])) { + const head = splitRow(line); + const aligns = splitRow(lines[i + 1]).map((c) => { + const t = c.trim(); + if (/^:-+:$/.test(t)) return 'center'; + if (/^:-+$/.test(t)) return 'left'; + if (/^-+:$/.test(t)) return 'right'; + return ''; + }); + i += 2; + const rows = []; + while (i < lines.length && lines[i].includes('|') && !/^\s*$/.test(lines[i])) { + rows.push(splitRow(lines[i])); + i++; + } + const cell = (tag, txt, idx) => { + const al = aligns[idx] ? ' style="text-align:' + aligns[idx] + '"' : ''; + return '<' + tag + al + '>' + renderInline(txt) + ''; + }; + let html = '
'; + head.forEach((c, idx) => { html += cell('th', c, idx); }); + html += ''; + rows.forEach((r) => { + html += ''; + for (let k = 0; k < head.length; k++) html += cell('td', r[k] == null ? '' : r[k], k); + html += ''; + }); + html += '
'; + out.push(html); + continue; + } + + // 列表 + if (RE_ITEM.test(line)) { + const r = parseList(lines, i, base); + out.push(r.html); + i = r.next; + continue; + } + + // 段落 + const buf = []; + while (i < lines.length && !/^\s*$/.test(lines[i])) { + const l = lines[i]; + if (RE_FENCE.test(l) || RE_HEADING.test(l) || RE_HR.test(l) || RE_QUOTE.test(l) || RE_ITEM.test(l)) break; + if (l.includes('|') && i + 1 < lines.length && isTableSep(lines[i + 1])) break; + buf.push(l); + i++; + } + if (buf.length) out.push('

' + inlineWithBreaks(buf.join('\n')) + '

'); + else i++; // 防死循环 + } + + return out.join('\n'); + } + + function parseList(lines, start, base) { + base = base || 0; + const m0 = RE_ITEM.exec(lines[start]); + const baseIndent = m0[1].length; + const ordered = /\d/.test(m0[2]); + const startNum = ordered ? parseInt(m0[2], 10) : 1; + + const items = []; + let i = start; + + while (i < lines.length) { + const m = RE_ITEM.exec(lines[i]); + if (!m || m[1].length !== baseIndent || (/\d/.test(m[2])) !== ordered) break; + + const contentIndent = m[1].length + m[2].length + m[3].length; + const content = m[4]; + i++; + + // 收集该列表项的后续行(子内容) + const children = []; + let childStart = -1; + while (i < lines.length) { + const l = lines[i]; + if (/^\s*$/.test(l)) { + let j = i; + while (j < lines.length && /^\s*$/.test(lines[j])) j++; + if (j < lines.length) { + const ind = lines[j].match(/^[ \t]*/)[0].length; + if (ind >= contentIndent || (RE_ITEM.test(lines[j]) && ind > baseIndent)) { + if (childStart < 0) childStart = i; + for (let k = i; k < j; k++) children.push(''); + i = j; + continue; + } + } + break; + } + const ind = l.match(/^[ \t]*/)[0].length; + if (ind >= contentIndent) { + if (childStart < 0) childStart = i; + children.push(l.slice(Math.min(ind, contentIndent))); + i++; + continue; + } + if (ind > baseIndent) { + if (childStart < 0) childStart = i; + children.push(l.trim()); + i++; + continue; + } + break; + } + + items.push({ content, children, childStart }); + } + + let html = ordered + ? '' + : '
    '; + + for (const it of items) { + let inner; + let cls = ''; + const task = RE_TASK.exec(it.content); + if (task) { + const checked = task[1].toLowerCase() === 'x'; + inner = ' ' + + renderInline(it.content.replace(RE_TASK, '')); + cls = ' class="task-item"'; + } else { + inner = renderInline(it.content); + } + html += '' + inner; + if (it.children.length) { + html += parseBlocks(it.children, base + (it.childStart >= 0 ? it.childStart : 0)); + } + html += ''; + } + + html += ordered ? '' : '
'; + return { html, next: i }; + } + + function render(md) { + const lines = String(md == null ? '' : md).replace(/\r\n?/g, '\n').split('\n'); + return parseBlocks(lines); + } + + /* ------------------------- 统计信息 ------------------------- */ + function stats(md) { + const text = String(md || ''); + const cjk = (text.match(/[\u4e00-\u9fa5\u3040-\u30ff]/g) || []).length; + const words = (text.replace(/[\u4e00-\u9fa5\u3040-\u30ff]/g, ' ').match(/[A-Za-z0-9_'’-]+/g) || []).length; + const lines = text.split('\n').length; + const headings = (text.match(/^\s{0,3}#{1,6}\s+\S/gm) || []).length; + return { chars: text.length, words: cjk + words, lines, headings }; + } + + global.MD = { render, stats, escapeHtml }; +})(window); diff --git a/src/renderer/style.css b/src/renderer/style.css new file mode 100644 index 0000000..c346298 --- /dev/null +++ b/src/renderer/style.css @@ -0,0 +1,795 @@ +/* ============ 主题变量 ============ */ +:root { + --bg: #ffffff; + --bg-soft: #f7f8fa; + --bg-toolbar: #fbfbfc; + --bg-hover: #eef1f5; + --bg-active: #e3e9f2; + --border: #e4e7ec; + --border-strong: #d3d8e0; + --text: #1f2329; + --text-dim: #6b7280; + --text-faint: #9aa1ac; + --accent: #2f6feb; + --accent-soft: #e8f0ff; + --accent-text: #ffffff; + --danger: #d14343; + --code-bg: #f2f4f7; + --code-block-bg: #f6f8fa; + --quote-bar: #d0d7e2; + --shadow: 0 8px 28px rgba(15, 23, 42, .14); + --shadow-sm: 0 1px 2px rgba(15, 23, 42, .06); + --font-ui: "Segoe UI", "Microsoft YaHei UI", "Microsoft YaHei", system-ui, sans-serif; + --font-mono: "Cascadia Code", "JetBrains Mono", Consolas, "Courier New", monospace; +} + +html[data-theme="dark"] { + --bg: #1b1c1f; + --bg-soft: #202226; + --bg-toolbar: #1e2024; + --bg-hover: #2a2d33; + --bg-active: #32363d; + --border: #2e3238; + --border-strong: #3b4048; + --text: #e6e8ec; + --text-dim: #9aa3ae; + --text-faint: #6f7782; + --accent: #4f8ef7; + --accent-soft: #1e2c44; + --accent-text: #ffffff; + --danger: #ef6b6b; + --code-bg: #262a30; + --code-block-bg: #22252a; + --quote-bar: #3d434c; + --shadow: 0 8px 28px rgba(0, 0, 0, .5); + --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3); +} + +/* ============ 基础 ============ */ +* { box-sizing: border-box; } + +html, body { + margin: 0; + height: 100%; + overflow: hidden; +} + +body { + font-family: var(--font-ui); + font-size: 13px; + color: var(--text); + background: var(--bg); + -webkit-font-smoothing: antialiased; + user-select: none; +} + +.app { + display: flex; + flex-direction: column; + height: 100vh; +} + +button { + font-family: inherit; + font-size: inherit; + color: inherit; + border: none; + background: none; + cursor: pointer; +} + +/* ============ 工具栏 ============ */ +.toolbar { + display: flex; + align-items: center; + gap: 6px; + height: 50px; + flex: 0 0 50px; + padding: 0 10px; + background: var(--bg-toolbar); + border-bottom: 1px solid var(--border); +} + +.brand { + display: flex; + align-items: center; + gap: 8px; + padding-right: 8px; + margin-right: 4px; + -webkit-app-region: drag; +} +.brand-name { + font-size: 12.5px; + font-weight: 600; + color: var(--text-dim); + white-space: nowrap; +} + +.tb-group { display: flex; align-items: center; gap: 2px; } + +.tb-btn { + display: inline-flex; + align-items: center; + gap: 5px; + height: 30px; + padding: 0 9px; + border-radius: 7px; + color: var(--text-dim); + white-space: nowrap; + transition: background .12s, color .12s; +} +.tb-btn svg { width: 15px; height: 15px; fill: currentColor; } +.tb-btn span { font-size: 12.5px; } +.tb-btn:hover { background: var(--bg-hover); color: var(--text); } +.tb-btn:active { background: var(--bg-active); } +.tb-btn.on { background: var(--accent-soft); color: var(--accent); } +.tb-btn.primary { color: var(--accent); } +.tb-btn.primary:hover { background: var(--accent-soft); } + +.tb-icon { + display: inline-flex; + align-items: center; + justify-content: center; + width: 30px; height: 30px; + border-radius: 7px; + color: var(--text-dim); + transition: background .12s, color .12s; +} +.tb-icon svg { width: 15px; height: 15px; fill: currentColor; } +.tb-icon:hover { background: var(--bg-hover); color: var(--text); } +.tb-icon:active { background: var(--bg-active); } +.tb-icon.disabled { opacity: .35; pointer-events: none; } + +.tb-sep { + width: 1px; + height: 20px; + margin: 0 4px; + background: var(--border); +} + +.spacer { flex: 1; } + +/* 分段控件 */ +.seg { + display: flex; + padding: 2px; + border-radius: 8px; + background: var(--bg-soft); + border: 1px solid var(--border); +} +.seg button { + height: 24px; + padding: 0 11px; + border-radius: 6px; + font-size: 12px; + color: var(--text-dim); + transition: background .12s, color .12s; +} +.seg button:hover { color: var(--text); } +.seg button.active { + background: var(--bg); + color: var(--accent); + font-weight: 600; + box-shadow: var(--shadow-sm); +} +html[data-theme="dark"] .seg button.active { background: var(--bg-active); } + +/* ============ 标签栏 ============ */ +.tabbar { + display: flex; + align-items: stretch; + flex: 0 0 32px; + height: 32px; + overflow-x: auto; + overflow-y: hidden; + background: var(--bg-soft); + border-bottom: 1px solid var(--border); + user-select: none; +} +.tabbar[hidden] { display: none; } +.tabbar::-webkit-scrollbar { height: 5px; } +.tabbar::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 3px; } + +.tab { + display: flex; + align-items: center; + gap: 6px; + flex: 0 0 auto; + min-width: 118px; + max-width: 230px; + padding: 0 8px 0 12px; + border-right: 1px solid var(--border); + border-top: 2px solid transparent; + font-size: 12px; + color: var(--text-dim); + cursor: default; +} +.tab:hover { background: var(--bg-hover); } +.tab.active { + background: var(--bg); + color: var(--text); + border-top-color: var(--accent); +} +.tab .tab-name { + flex: 1; + min-width: 0; + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.tab .tab-dot { + flex: 0 0 6px; + width: 6px; + height: 6px; + border-radius: 50%; + background: var(--accent); + opacity: 0; +} +.tab.dirty .tab-dot { opacity: 1; } +.tab .tab-close { + flex: 0 0 16px; + display: inline-flex; + align-items: center; + justify-content: center; + width: 16px; + height: 16px; + border-radius: 4px; + color: var(--text-faint); + font-size: 11px; + line-height: 1; +} +.tab .tab-close:hover { background: var(--bg-active); color: var(--text); } +.tab .tab-close svg { width: 9px; height: 9px; fill: currentColor; } + +/* ============ 查找条 ============ */ +.findbar { + display: flex; + align-items: center; + gap: 8px; + padding: 6px 12px; + background: var(--bg-soft); + border-bottom: 1px solid var(--border); +} +.findbar[hidden] { display: none; } +.findbar input { + flex: 1; + height: 28px; + padding: 0 10px; + border-radius: 6px; + border: 1px solid var(--border-strong); + background: var(--bg); + color: var(--text); + font-family: var(--font-ui); + font-size: 12.5px; + outline: none; +} +.findbar input:focus { border-color: var(--accent); } +.find-count { font-size: 11.5px; color: var(--text-faint); min-width: 62px; } +.findbar button { + width: 26px; height: 26px; + border-radius: 6px; + color: var(--text-dim); + font-size: 12px; +} +.findbar button:hover { background: var(--bg-hover); color: var(--text); } + +/* ============ 工作区 ============ */ +.workspace { + flex: 1; + display: flex; + min-height: 0; + overflow: hidden; + background: var(--bg); +} + +.pane { + display: flex; + min-width: 0; + overflow: hidden; +} + +/* ============ 文件树侧栏 ============ */ +.sidebar { + flex: 0 0 232px; + display: flex; + flex-direction: column; + min-width: 0; + overflow: hidden; + background: var(--bg-soft); + border-left: 1px solid var(--border); + border-right: 1px solid var(--border); +} +.sidebar[hidden] { display: none; } + +/* 面板头部(文件目录 / 章节大纲 共用,保证视觉统一) */ +.panel-head { + display: flex; + align-items: center; + gap: 7px; + flex: 0 0 34px; + padding: 0 6px 0 12px; + border-bottom: 1px solid var(--border); +} +.panel-ico { + flex: 0 0 13px; + width: 13px; + height: 13px; + fill: var(--text-faint); +} +.panel-title { + font-size: 12px; + font-weight: 600; + color: var(--text-dim); + overflow: hidden; + text-overflow: ellipsis; + white-space: nowrap; +} +.panel-actions { display: flex; gap: 2px; flex: 0 0 auto; margin-left: auto; } +.sb-btn { + display: inline-flex; + align-items: center; + justify-content: center; + width: 24px; height: 24px; + border-radius: 5px; + color: var(--text-faint); +} +.sb-btn svg { width: 13px; height: 13px; fill: currentColor; } +.sb-btn:hover { background: var(--bg-hover); color: var(--text); } + +.sb-body { + flex: 1; + overflow-y: auto; + overflow-x: hidden; + padding: 6px 0 24px; + user-select: none; +} +.tree-row { + display: flex; + align-items: center; + gap: 5px; + height: 26px; + padding-right: 8px; + font-size: 12.5px; + color: var(--text); + white-space: nowrap; + cursor: default; +} +.tree-row:hover { background: var(--bg-hover); } +.tree-row:focus { outline: none; background: var(--bg-active); } +.tree-row:focus.active { background: var(--accent-soft); } +.tree-row.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; } +.tree-row .twisty { + flex: 0 0 12px; + text-align: center; + font-size: 9px; + line-height: 1; + color: var(--text-faint); +} +.tree-row.is-dir .tree-name { font-weight: 500; } +.tree-row .tree-name { overflow: hidden; text-overflow: ellipsis; } +.tree-empty { padding: 5px 12px 5px 30px; font-size: 11.5px; color: var(--text-faint); } +.sb-tip { + padding: 26px 16px; + font-size: 12px; + line-height: 1.7; + color: var(--text-faint); + text-align: center; +} +.sb-tip-sub { margin-top: 6px; font-size: 11.5px; color: var(--text-faint); opacity: .85; }.sb-pick-btn { + margin-top: 14px; + height: 28px; + padding: 0 16px; + border-radius: 7px; + background: var(--accent); + color: var(--accent-text); + font-size: 12px; + font-weight: 500; +} +.sb-pick-btn:hover { filter: brightness(1.06); } +.sb-pick-btn:active { filter: brightness(.94); } + +/* ============ 章节大纲 ============ */ +.outline { + flex: 0 0 210px; + display: flex; + flex-direction: column; + min-width: 0; + overflow: hidden; + background: var(--bg-soft); + border-left: 1px solid var(--border); + border-right: 1px solid var(--border); +} +.outline[hidden] { display: none; } + +.ol-count { + margin-left: auto; + padding: 1px 7px; + border-radius: 9px; + background: var(--bg-hover); + font-size: 10.5px; + color: var(--text-faint); +} + +.ol-body { + flex: 1; + overflow-y: auto; + overflow-x: hidden; + padding: 6px 0 24px; + user-select: none; +} +.ol-item { + padding: 4px 10px; + font-size: 12.5px; + line-height: 1.45; + color: var(--text-dim); + border-left: 2px solid transparent; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; + cursor: default; +} +.ol-item:hover { background: var(--bg-hover); color: var(--text); } +.ol-item.active { + color: var(--accent); + border-left-color: var(--accent); + background: var(--accent-soft); +} +.ol-item[data-level="1"] { color: var(--text); font-weight: 600; } +.ol-item[data-level="1"].active { color: var(--accent); } +.ol-empty { + padding: 22px 14px; + font-size: 12px; + line-height: 1.7; + color: var(--text-faint); + text-align: center; +} + +.editor-pane { flex: 1; position: relative; } + +/* 编辑器查找高亮叠加层:文字透明只显示 mark 背景,随编辑器滚动 */ +.editor-wrap { + position: relative; + display: flex; + flex-direction: column; + width: 100%; + height: 100%; +} +.editor-hl { + position: absolute; + inset: 0; + padding: 18px 22px; + color: transparent; + font-family: var(--font-mono); + font-size: 13.5px; + line-height: 1.7; + tab-size: 4; + white-space: pre-wrap; + word-wrap: break-word; + overflow: hidden; + pointer-events: none; +} +.editor-hl mark { + background: rgba(255, 193, 7, .32); + color: transparent; + border-radius: 3px; +} +.editor-hl mark.find-hit-active { + background: rgba(255, 159, 10, .55); +} + +#editor { + flex: 1; + width: 100%; + height: 100%; + padding: 18px 22px; + border: none; + outline: none; + resize: none; + background: transparent; + color: var(--text); + font-family: var(--font-mono); + font-size: 13.5px; + line-height: 1.7; + tab-size: 4; + overflow-y: auto; + user-select: text; + caret-color: var(--accent); +} +#editor::placeholder { color: var(--text-faint); } + +.splitter { + flex: 0 0 1px; + background: var(--border); + cursor: col-resize; + position: relative; + transition: background .15s; +} +.splitter::after { + content: ''; + position: absolute; + top: 0; bottom: 0; + left: -3px; right: -3px; +} +.splitter:hover, .splitter.dragging { background: var(--accent); } + +/* 侧栏 / 大纲的可拖拽分隔条 */ +.vsplitter { + flex: 0 0 1px; + background: var(--border); + cursor: col-resize; + position: relative; + transition: background .15s; +} +.vsplitter::after { + content: ''; + position: absolute; + top: 0; bottom: 0; + left: -3px; right: -3px; +} +.vsplitter:hover, .vsplitter.dragging { background: var(--accent); } +.vsplitter[hidden] { display: none; } + +.preview-pane { + flex: 1; + overflow: hidden; + background: var(--bg); +} + +/* 模式切换 */ +.workspace[data-mode="edit"] .preview-pane, +.workspace[data-mode="edit"] .splitter { display: none; } +.workspace[data-mode="read"] .editor-pane, +.workspace[data-mode="read"] .splitter { display: none; } + +/* ============ 预览排版 ============ */ + +/* 查找:正文关键字背景标记 */ +#preview mark.find-hit { + background: rgba(255, 193, 7, .45); + color: inherit; + padding: 0 1px; + border-radius: 3px; +} +#preview mark.find-hit.find-hit-active { + background: #ff9f0a; + color: #fff; +} +.markdown-body { + height: 100%; + overflow-y: auto; + padding: 34px 46px 120px; + max-width: 900px; + margin: 0 auto; + font-size: 14.5px; + line-height: 1.78; + color: var(--text); + user-select: text; + overflow-wrap: break-word; +} + +.markdown-body > *:first-child { margin-top: 0; } + +.markdown-body h1, .markdown-body h2, .markdown-body h3, +.markdown-body h4, .markdown-body h5, .markdown-body h6 { + margin: 1.6em 0 .6em; + font-weight: 650; + line-height: 1.35; + scroll-margin-top: 20px; +} +.markdown-body h1 { font-size: 1.9em; padding-bottom: .3em; border-bottom: 1px solid var(--border); } +.markdown-body h2 { font-size: 1.5em; padding-bottom: .25em; border-bottom: 1px solid var(--border); } +.markdown-body h3 { font-size: 1.24em; } +.markdown-body h4 { font-size: 1.08em; } +.markdown-body h5 { font-size: 1em; } +.markdown-body h6 { font-size: .94em; color: var(--text-dim); } + +.markdown-body p { margin: .85em 0; } + +.markdown-body a { + color: var(--accent); + text-decoration: none; + border-bottom: 1px solid transparent; +} +.markdown-body a:hover { border-bottom-color: currentColor; } + +.markdown-body strong { font-weight: 650; } +.markdown-body em { font-style: italic; } +.markdown-body del { color: var(--text-faint); } + +.markdown-body code { + padding: .16em .4em; + border-radius: 5px; + background: var(--code-bg); + font-family: var(--font-mono); + font-size: .88em; + color: #b5446e; +} +html[data-theme="dark"] .markdown-body code { color: #f0a1c0; } + +.code-wrap { + position: relative; + margin: 1em 0; + border-radius: 9px; + background: var(--code-block-bg); + border: 1px solid var(--border); + overflow: hidden; +} +.code-wrap pre { + margin: 0; + padding: 14px 16px; + overflow-x: auto; + font-family: var(--font-mono); + font-size: 12.8px; + line-height: 1.65; +} +.code-wrap pre code { + padding: 0; + background: none; + color: var(--text); + font-size: inherit; + white-space: pre; +} +.code-lang { + position: absolute; + top: 6px; right: 10px; + font-size: 10.5px; + letter-spacing: .04em; + text-transform: uppercase; + color: var(--text-faint); + font-family: var(--font-ui); + pointer-events: none; +} + +.markdown-body blockquote { + margin: 1em 0; + padding: .2em 1em; + border-left: 3px solid var(--quote-bar); + color: var(--text-dim); +} +.markdown-body blockquote > *:first-child { margin-top: .4em; } +.markdown-body blockquote > *:last-child { margin-bottom: .4em; } + +.markdown-body ul, .markdown-body ol { margin: .7em 0; padding-left: 1.7em; } +.markdown-body li { margin: .3em 0; } +.markdown-body li > ul, .markdown-body li > ol { margin: .3em 0; } +.markdown-body li.task-item { list-style: none; margin-left: -1.35em; } +.markdown-body li.task-item input { margin-right: .45em; vertical-align: 1px; accent-color: var(--accent); } + +.markdown-body hr { + height: 1px; + margin: 1.8em 0; + border: none; + background: var(--border); +} + +.table-wrap { overflow-x: auto; margin: 1.1em 0; } +.markdown-body table { + border-collapse: collapse; + width: 100%; + font-size: .95em; +} +.markdown-body th, .markdown-body td { + padding: 7px 13px; + border: 1px solid var(--border); + text-align: left; +} +.markdown-body th { + background: var(--bg-soft); + font-weight: 600; +} +.markdown-body tbody tr:nth-child(2n) { background: color-mix(in srgb, var(--bg-soft) 60%, transparent); } + +.markdown-body img { + max-width: 100%; + border-radius: 8px; + margin: .4em 0; +} + +/* ============ 状态栏 ============ */ +.statusbar { + display: flex; + align-items: center; + justify-content: space-between; + flex: 0 0 26px; + height: 26px; + padding: 0 12px; + background: var(--bg-toolbar); + border-top: 1px solid var(--border); + font-size: 11.5px; + color: var(--text-faint); +} +.st-left, .st-right { display: flex; align-items: center; gap: 8px; } +.st-file { color: var(--text-dim); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; } +.st-dirty { + padding: 1px 6px; + border-radius: 4px; + background: var(--accent-soft); + color: var(--accent); + font-size: 10.5px; +} +.st-div { color: var(--border-strong); } + +/* ============ 右键菜单 ============ */ +.ctx-menu { + position: fixed; + z-index: 900; + min-width: 200px; + padding: 5px; + border-radius: 9px; + background: var(--bg); + border: 1px solid var(--border); + box-shadow: var(--shadow); + font-size: 12.5px; +} +.ctx-menu[hidden] { display: none; } +.ctx-item { + display: flex; + align-items: center; + justify-content: space-between; + gap: 24px; + height: 30px; + padding: 0 10px; + border-radius: 6px; + color: var(--text); + cursor: default; +} +.ctx-item:hover { background: var(--accent); color: var(--accent-text); } +.ctx-item .kbd { font-size: 11px; color: var(--text-faint); } +.ctx-item:hover .kbd { color: rgba(255, 255, 255, .8); } +.ctx-item.disabled { color: var(--text-faint); pointer-events: none; } +.ctx-sep { height: 1px; margin: 4px 6px; background: var(--border); } + +/* ============ 提示 ============ */ +.toast { + position: fixed; + left: 50%; + bottom: 46px; + transform: translateX(-50%) translateY(8px); + padding: 8px 16px; + border-radius: 8px; + background: rgba(28, 32, 38, .92); + color: #fff; + font-size: 12.5px; + opacity: 0; + transition: opacity .18s, transform .18s; + pointer-events: none; + z-index: 950; +} +.toast[hidden] { display: none; } +.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); } + +.drop-hint { + position: fixed; + inset: 0; + z-index: 990; + display: flex; + align-items: center; + justify-content: center; + background: color-mix(in srgb, var(--accent) 12%, transparent); + border: 2px dashed var(--accent); + backdrop-filter: blur(1px); +} +.drop-hint[hidden] { display: none; } +.drop-hint div { + padding: 10px 22px; + border-radius: 10px; + background: var(--bg); + box-shadow: var(--shadow); + color: var(--accent); + font-weight: 600; +} + +/* 滚动条 */ +::-webkit-scrollbar { width: 11px; height: 11px; } +::-webkit-scrollbar-thumb { + background: color-mix(in srgb, var(--text-faint) 42%, transparent); + border: 3px solid transparent; + background-clip: content-box; + border-radius: 10px; +} +::-webkit-scrollbar-thumb:hover { background: color-mix(in srgb, var(--text-faint) 70%, transparent); background-clip: content-box; } +::-webkit-scrollbar-track { background: transparent; } + +/* 拖动分栏时禁止选中 */ +body.resizing { cursor: col-resize; } +body.resizing #editor, body.resizing .markdown-body { pointer-events: none; } diff --git a/src/renderer/tauri-bridge.js b/src/renderer/tauri-bridge.js new file mode 100644 index 0000000..d796579 --- /dev/null +++ b/src/renderer/tauri-bridge.js @@ -0,0 +1,178 @@ +/* Tauri 桥接层:替代 Electron preload,向 app.js 提供同形状的 window.api */ +(function () { + 'use strict'; + + const T = window.__TAURI__; + if (!T) { console.error('Tauri API 未注入'); return; } + const invoke = T.core.invoke; + const listen = T.event.listen; + const cur = T.window.getCurrentWindow(); + + /* ---------- 标题状态(等价原主进程窗口状态) ---------- */ + const titleState = { path: null, dirty: false }; + function baseName(p) { + if (!p) return null; + return String(p).replace(/[\\/]+$/, '').split(/[\\/]/).pop() || null; + } + function updateTitle() { + const t = (titleState.dirty ? '● ' : '') + (baseName(titleState.path) || '未命名') + ' — 小银 Markdown'; + cur.setTitle(t).catch(() => {}); + } + + /* ---------- 模态对话框(支持任意按钮数组,返回按钮索引) ---------- */ + function modalDialog(o) { + const buttons = Array.isArray(o.buttons) && o.buttons.length ? o.buttons : ['好']; + return new Promise((resolve) => { + const overlay = document.createElement('div'); + overlay.style.cssText = 'position:fixed;inset:0;background:rgba(0,0,0,.35);z-index:99999;display:flex;align-items:center;justify-content:center;font-family:system-ui,sans-serif;'; + const box = document.createElement('div'); + box.style.cssText = 'background:#fff;color:#222;border-radius:12px;padding:22px 24px 18px;max-width:440px;box-shadow:0 18px 60px rgba(0,0,0,.3);font-size:13.5px;'; + const msg = document.createElement('div'); + msg.style.cssText = 'font-weight:700;font-size:15px;margin-bottom:6px;'; + msg.textContent = o.message || ''; + box.appendChild(msg); + if (o.detail) { + const d = document.createElement('div'); + d.style.cssText = 'opacity:.7;margin-bottom:14px;line-height:1.5;'; + d.textContent = o.detail; + box.appendChild(d); + } + const row = document.createElement('div'); + row.style.cssText = 'display:flex;gap:8px;justify-content:flex-end;'; + buttons.forEach((label, i) => { + const b = document.createElement('button'); + b.textContent = label; + const primary = i === buttons.length - 1; + b.style.cssText = 'padding:7px 16px;border-radius:8px;border:1px solid #c9cdd4;cursor:pointer;font-size:13px;background:' + + (primary ? '#3b7bf6;color:#fff;border-color:#3b7bf6;' : 'transparent;color:inherit;'); + b.addEventListener('click', () => { overlay.remove(); resolve(i); }); + row.appendChild(b); + }); + box.appendChild(row); + overlay.appendChild(box); + document.body.appendChild(overlay); + }); + } + + /* ---------- 命令 / 关闭 / 导出 处理器注册表 ---------- */ + const cmdHandlers = []; + const closeHandlers = []; + let exportHandler = null; + function fire(name, payload) { + cmdHandlers.forEach((cb) => { try { cb(name, payload); } catch (err) { console.error(err); } }); + } + + /* ---------- 迁移:广播收集所有窗口的文档 ---------- */ + function collectAllDocs() { + return new Promise((resolve) => { + const replies = []; + let un = null; + listen('mig:docs', (e) => { + if (e.payload && Array.isArray(e.payload.docs)) replies.push(e.payload.docs); + }).then((u) => { un = u; }); + T.event.emit('mig:request', { from: cur.label }); + const start = Date.now(); + const tick = () => { + if (Date.now() - start >= 2200 || un) { + if (un) un(); + const seen = new Set(); + const out = []; + for (const docs of replies) { + for (const d of docs) { + if (d.path && seen.has(d.path)) continue; + if (d.path) seen.add(d.path); + out.push(d); + } + } + if (!out.length) out.push({ path: null, name: null, text: '', eol: '\n', dirty: false, lastSaved: '' }); + resolve(out); + return; + } + setTimeout(tick, 120); + }; + setTimeout(tick, 600); + }); + } + + /* ---------- 对外 API(与 Electron preload 同形状) ---------- */ + window.api = { + open: () => invoke('open_file_dialog'), + openPath: (p) => invoke('read_text_file', { path: p }), + save: async (payload) => { + const r = await invoke('save_file', { + content: payload.content, + saveAs: !!payload.saveAs, + eol: payload.eol || '\n', + currentPath: titleState.path + }); + if (r && r.ok && r.path) { + titleState.path = r.path; + titleState.dirty = false; + updateTitle(); + } + return r; + }, + reveal: () => (titleState.path ? invoke('reveal_in_explorer', { path: titleState.path }) : Promise.resolve({ ok: false })), + revealPath: (p) => invoke('reveal_in_explorer', { path: p }), + copyFile: (p) => invoke('copy_file_to_clipboard', { path: p }), + readFileText: (p) => invoke('read_text_file', { path: p }), + readClipboard: () => invoke('read_clipboard_text'), + writeClipboard: (t) => invoke('write_clipboard_text', { text: t }), + openExternal: (url) => invoke('open_external', { url }), + dirOpen: () => invoke('open_dir_dialog'), + dirRead: (p) => invoke('read_dir', { path: p }), + openNewWindow: (p) => invoke('open_new_window', { path: p }), + newWindow: () => invoke('open_new_window', { path: null }), + closeWindow: () => invoke('force_close'), + getOpenMode: async () => ({ mode: localStorage.getItem('md-editor-open-mode') || 'tabs' }), + setOpenMode: async (mode) => { + const docs = await collectAllDocs(); + await invoke('migrate_apply', { mode, docs, keepLabel: cur.label }); + return { ok: true, mode }; + }, + setDirty: (d) => { titleState.dirty = !!d; updateTitle(); }, + syncDoc: (p) => { + titleState.path = p || null; + updateTitle(); + }, + message: (o) => modalDialog(o), + saveFinished: () => {}, + exportDocs: () => {}, + onCommand: (cb) => cmdHandlers.push(cb), + onCloseConfirm: (cb) => closeHandlers.push(cb), + onExport: (cb) => { exportHandler = cb; } + }; + + /* ---------- 事件接线 ---------- */ + listen('mig:adopt-tabs', (e) => fire('adopt-tabs', e.payload && e.payload.docs)); + listen('mig:adopt-doc', (e) => fire('adopt-doc', e.payload)); + listen('open-external', (e) => fire('open-external', e.payload)); + listen('init-file', (e) => fire('file-opened', e.payload)); + listen('close-confirm', () => closeHandlers.forEach((cb) => { try { cb(cur.label); } catch (err) { console.error(err); } })); + listen('mig:request', () => { + if (exportHandler) { + try { + const docs = exportHandler(); + T.event.emit('mig:docs', { from: cur.label, docs }); + } catch (err) { console.error(err); } + } + }); + + /* ---------- 拖放(Tauri 系统级,拿得到真实路径) ---------- */ + cur.onDragDropEvent((e) => { + const p = e.payload; + if (p.type === 'drop' && Array.isArray(p.paths) && p.paths.length) { + fire('dropped-path', p.paths[0]); + } + }); + + /* ---------- 文本拖放兜底(HTML5) ---------- */ + window.addEventListener('dragover', (e) => { e.preventDefault(); }); + window.addEventListener('drop', (e) => { + const dt = e.dataTransfer; + if (!dt) return; + e.preventDefault(); + const text = dt.getData && dt.getData('text/plain'); + if (text) fire('dropped-text', { name: null, text }); + }); +})(); diff --git a/src/resources/app.ico b/src/resources/app.ico new file mode 100644 index 0000000..c93ba76 Binary files /dev/null and b/src/resources/app.ico differ diff --git a/tools/closetest.js b/tools/closetest.js new file mode 100644 index 0000000..ed32d19 --- /dev/null +++ b/tools/closetest.js @@ -0,0 +1,35 @@ +/* 验证关闭窗口时主进程不抛异常 */ +process.on('uncaughtException', (e) => { + console.log('UNCAUGHT:', e.message); + process.exit(2); +}); + +const { app, BrowserWindow } = require('electron'); +const wait = (ms) => new Promise((r) => setTimeout(r, ms)); +require('../src/main.js'); +// 阻止 window-all-closed 自动退出,便于关闭后继续检查 +app.removeAllListeners('window-all-closed'); + +let errors = []; +process.on('uncaughtException', (e) => errors.push(e.message)); + +app.whenReady().then(async () => { + await wait(1400); + const wins = BrowserWindow.getAllWindows(); + console.log('打开窗口数:', wins.length); + + // 连续开关多个窗口,覆盖正常关闭和迁移式关闭 + const w2 = new BrowserWindow({ show: false, webPreferences: { offscreen: true } }); + w2.close(); + await wait(300); + + for (const w of wins) w.close(); + await wait(1000); + + if (errors.length) { + console.log('FAIL 主进程异常:', errors.join(' | ')); + process.exit(1); + } + console.log('PASS 关闭窗口无主进程异常'); + process.exit(0); +}); diff --git a/tools/copytest.js b/tools/copytest.js new file mode 100644 index 0000000..346ae4c --- /dev/null +++ b/tools/copytest.js @@ -0,0 +1,171 @@ +/* 验证:文件树右键复制(文件名/路径/内容)+ 聚焦后 Ctrl+C + 按钮位置 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); +const nativeClip = require('../src/clipboard-native'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'copytest-')); + const mdFile = path.join(tmp, '交易日历业务交接文档.md'); + const mdText = '# 交易日历业务交接文档\n\n## 业务概览\n\n正文内容。\n'; + fs.writeFileSync(mdFile, mdText, 'utf8'); + fs.mkdirSync(path.join(tmp, '子目录')); + fs.writeFileSync(path.join(tmp, '另一个.md'), '# 另一个\n', 'utf8'); + + const list = () => fs.readdirSync(tmp, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() })) + .sort((a, b) => (Number(b.isDir) - Number(a.isDir)) || a.name.localeCompare(b.name, 'zh-Hans-CN')); + + let clipboard = ''; + let lastRevealed = ''; + let lastCopiedFile = ''; + ipcMain.handle('clip:read', () => clipboard); + ipcMain.handle('clip:write', (_e, text) => { clipboard = String(text ?? ''); return true; }); + ipcMain.handle('file:readText', async (_e, p) => { + try { return { ok: true, text: fs.readFileSync(p, 'utf8') }; } catch (_) { return { ok: false }; } + }); + ipcMain.handle('file:copyFile', async (_e, p) => { + const list = (Array.isArray(p) ? p : [p]).filter((x) => x && fs.existsSync(x)); + nativeClip.setFiles(list); + lastCopiedFile = p || ''; + return { ok: true, count: list.length }; + }); + ipcMain.handle('file:revealPath', async (_e, p) => { lastRevealed = p || ''; return { ok: true }; }); + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: list() })); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('file:reveal', async () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + + const win = new BrowserWindow({ + width: 1400, height: 880, show: true, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + await js(`localStorage.clear()`); + await win.webContents.reload(); + await wait(1200); + + /* 1. 按钮位置 */ + const pos = await js(`(() => { + const btns = [...document.querySelectorAll('.toolbar button')]; + const tree = document.getElementById('btn-tree'); + const outline = document.getElementById('btn-outline'); + const segBtn = document.querySelector('#mode-seg button'); + return { + beforeSeg: btns.indexOf(tree) < btns.indexOf(segBtn), + adjacent: btns.indexOf(segBtn) - btns.indexOf(tree) === 1, + sameClass: tree.className === outline.className, + treeText: tree.textContent.trim(), outlineText: outline.textContent.trim() + }; + })()`); + check('「目录」按钮紧挨在编辑/分栏/阅读之前', pos.beforeSeg === true && pos.adjacent === true, JSON.stringify(pos)); + check('两个开关样式类名一致', pos.sameClass === true, pos.treeClass || ''); + check('按钮文字为 目录 / 大纲', pos.treeText === '目录' && pos.outlineText === '大纲', pos.treeText + ' / ' + pos.outlineText); + + /* 2. 打开文件夹,准备文件树 */ + win.webContents.send('cmd', 'dir-opened', { ok: true, path: tmp, name: path.basename(tmp), entries: list() }); + await wait(400); + + const rightClick = async (pathSuffix, menuText) => js(`(() => { + const rows = [...document.querySelectorAll('#sb-body .tree-row')]; + const row = rows.find(r => r.dataset.path.endsWith(${JSON.stringify(pathSuffix)})); + if (!row) return { error: 'row not found' }; + row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 260, clientY: 200 })); + const menu = document.getElementById('ctxmenu'); + const items = [...menu.querySelectorAll('.ctx-item')].map(i => i.textContent); + const target = [...menu.querySelectorAll('.ctx-item')].find(i => { + const lab = i.querySelector('span'); + return lab && lab.textContent === ${JSON.stringify(menuText)}; + }); + if (!target) return { error: 'menu item not found', items }; + target.click(); + return { items }; + })()`); + + /* 3. 右键复制文件名 */ + await rightClick('交易日历业务交接文档.md', '复制文件名'); + await wait(200); + check('右键复制文件名', clipboard === '交易日历业务交接文档.md', clipboard); + + /* 4. 右键复制完整路径 */ + await rightClick('交易日历业务交接文档.md', '复制完整路径'); + await wait(200); + check('右键复制完整路径', clipboard === mdFile, clipboard); + + /* 5. 右键复制文件内容 */ + await rightClick('交易日历业务交接文档.md', '复制文件内容'); + await wait(250); + check('右键复制文件内容', clipboard === mdText, JSON.stringify(clipboard).slice(0, 60)); + + /* 6. 右键复制文件本身(Windows 文件对象) */ + await rightClick('交易日历业务交接文档.md', '复制文件'); + await wait(250); + check('右键复制文件本身', lastCopiedFile === mdFile, lastCopiedFile); + check('系统剪贴板含文件列表 CF_HDROP', nativeClip.hasFiles() === true); + + /* 7. 右键在资源管理器中显示:路径必须真的传过去 */ + await rightClick('交易日历业务交接文档.md', '在资源管理器中显示'); + await wait(200); + check('资源管理器显示:路径参数正确传递', lastRevealed === mdFile, lastRevealed); + + /* 8. 右键菜单内容齐全、目录项禁用复制内容 */ + const menuInfo = await js(`(() => { + const row = [...document.querySelectorAll('#sb-body .tree-row.is-dir')][0]; + row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 260, clientY: 200 })); + const items = [...document.querySelectorAll('#ctxmenu .ctx-item')]; + const lab = (i) => { const s = i.querySelector('span'); return s ? s.textContent : ''; }; + return { + labels: items.map(lab), + contentDisabled: items.find(i => lab(i) === '复制文件内容').classList.contains('disabled') + }; + })()`); + check('右键菜单五项齐全', ['复制文件', '复制文件内容', '复制文件名', '复制完整路径', '在资源管理器中显示'].every(x => menuInfo.labels.includes(x)), JSON.stringify(menuInfo.labels)); + check('目录项禁用复制文件内容', menuInfo.contentDisabled === true); + + /* 9. 聚焦 + Ctrl+C 复制文件 */ + const kbd = await js(`(() => { + document.getElementById('ctxmenu').hidden = true; + const row = [...document.querySelectorAll('#sb-body .tree-row')].find(r => r.dataset.path.endsWith('另一个.md')); + row.focus(); + const focused = document.activeElement === row; + row.dispatchEvent(new KeyboardEvent('keydown', { key: 'c', ctrlKey: true, bubbles: true, cancelable: true })); + return { focused }; + })()`); + await wait(250); + check('文件树条目可聚焦', kbd.focused === true); + check('Ctrl+C 复制文件本身', lastCopiedFile === path.join(tmp, '另一个.md'), lastCopiedFile); + check('Ctrl+C 后剪贴板仍是文件列表', nativeClip.hasFiles() === true); + + /* 8. 普通编辑区 Ctrl+C 不受影响 */ + await js(`(() => { + const ed = document.getElementById('editor'); + ed.value = 'EDITOR TEXT'; + ed.focus(); + ed.setSelectionRange(0, 5); + ed.dispatchEvent(new KeyboardEvent('keydown', { key: 'c', ctrlKey: true, bubbles: true, cancelable: true })); + })()`); + await wait(250); + check('编辑区 Ctrl+C 不误触文件树复制', clipboard !== 'EDITOR TEXT', clipboard); + + console.log('\n==== 文件树复制测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + const img = await win.webContents.capturePage(); + fs.writeFileSync(path.join(__dirname, '..', 'shot-copy.png'), img.toPNG()); + console.log('screenshot saved'); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/dragtest.js b/tools/dragtest.js new file mode 100644 index 0000000..220c8ac --- /dev/null +++ b/tools/dragtest.js @@ -0,0 +1,110 @@ +/* 用 CDP 模拟真实系统拖放,验证 preload 能否取到路径并打开 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +const log = (...a) => console.log(...a); + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'dragtest-')); + const file = path.join(tmp, '拖进来的文件.md'); + const dir = path.join(tmp, '文档库'); + fs.writeFileSync(file, '# 拖进来的\n\n内容是 **拖放** 打开的。\n', 'utf8'); + fs.mkdirSync(dir); + fs.writeFileSync(path.join(dir, '第一篇.md'), '# 第一篇\n', 'utf8'); + fs.writeFileSync(path.join(dir, '第二篇.md'), '# 第二篇\n', 'utf8'); + + // 真实主进程逻辑(复刻 main.js 的两条通路) + ipcMain.handle('file:openPath', async (_e, p) => { + return { ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' }; + }); + ipcMain.handle('dir:read', async (_e, p) => { + const entries = fs.readdirSync(p, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(p, d.name), isDir: d.isDirectory() })); + return { ok: true, path: p, name: path.basename(p), entries }; + }); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('clip:read', () => ''); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + + // 复刻 main.js 里 file:drop 的分支(文件 → 打开;目录 → 文件树) + ipcMain.on('file:drop', (_e, p) => { + const win = BrowserWindow.getAllWindows()[0]; + let isDir = false; + try { isDir = fs.statSync(p).isDirectory(); } catch (_) { return; } + if (isDir) { + const entries = fs.readdirSync(p, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(p, d.name), isDir: d.isDirectory() })); + win.webContents.send('cmd', 'dir-opened', { ok: true, path: p, name: path.basename(p), entries }); + } else { + win.webContents.send('cmd', 'file-opened', { + ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' + }); + } + }); + + const win = new BrowserWindow({ + width: 1280, height: 820, show: true, + webPreferences: { + preload: path.join(__dirname, '..', 'src', 'preload.js'), + contextIsolation: true, + nodeIntegration: false + } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + win.focus(); + await new Promise((r) => setTimeout(r, 800)); + + const dbg = win.webContents.debugger; + dbg.attach('1.3'); + + const dragDrop = async (absolutePath, x, y) => { + const data = { items: [], files: [absolutePath], dragOperationsMask: 1 }; + await dbg.sendCommand('Input.dispatchDragEvent', { type: 'dragEnter', x, y, data }); + await dbg.sendCommand('Input.dispatchDragEvent', { type: 'dragOver', x, y, data }); + await dbg.sendCommand('Input.dispatchDragEvent', { type: 'drop', x, y, data }); + }; + + const js = (code) => win.webContents.executeJavaScript(code); + let pass = 0; + let fail = 0; + const check = (name, ok, extra) => { + if (ok) { pass++; log('PASS ' + name); } else { fail++; log('FAIL ' + name + (extra ? ' → ' + extra : '')); } + }; + + // ---- 拖入单个 .md 文件 ---- + try { + await dragDrop(file, 400, 380); + await new Promise((r) => setTimeout(r, 900)); + const s = await js(`({ v: editor.value, name: document.getElementById('st-file').textContent, sb: !document.getElementById('sidebar').hidden, rows: [...document.querySelectorAll('#sb-body .tree-row')].map(r=>r.querySelector('.tree-name').textContent) })`); + check('拖入文件:取到真实路径并打开', s.v.indexOf('拖放') >= 0, s.name); + check('拖入文件:状态栏文件名正确', s.name === '拖进来的文件.md', s.name); + check('拖入文件:自动列出所在目录', s.sb === true && s.rows.includes('文档库'), JSON.stringify(s.rows)); + } catch (e) { + check('拖入文件(CDP 未支持 files 参数)', false, e.message); + } + + // ---- 拖入文件夹 ---- + try { + await dragDrop(dir, 400, 380); + await new Promise((r) => setTimeout(r, 900)); + const s = await js(`({ title: document.getElementById('sb-title').textContent, rows: [...document.querySelectorAll('#sb-body .tree-row')].map(r=>r.querySelector('.tree-name').textContent) })`); + check('拖入文件夹:侧栏标题为该文件夹', s.title === '文档库', s.title); + check('拖入文件夹:列出里面的 md', s.rows.includes('第一篇.md') && s.rows.includes('第二篇.md'), JSON.stringify(s.rows)); + } catch (e) { + check('拖入文件夹(CDP 未支持 files 参数)', false, e.message); + } + + log('\n==== 拖放测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/findhltest.js b/tools/findhltest.js new file mode 100644 index 0000000..fe7c3e6 --- /dev/null +++ b/tools/findhltest.js @@ -0,0 +1,130 @@ +/* 验证:查找时预览正文的关键字背景标记与当前命中高亮 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + ipcMain.handle('clip:read', () => ''); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.handle('app:getOpenMode', async () => ({ mode: 'tabs' })); + ipcMain.handle('app:setOpenMode', async () => ({ ok: true })); + ipcMain.on('app:setDirty', () => {}); ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); ipcMain.on('docs:exported', () => {}); + ipcMain.on('doc:syncPath', () => {}); + + const win = new BrowserWindow({ + width: 1400, height: 900, show: true, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + await js(`localStorage.clear()`); + await win.webContents.reload(); + await wait(1800); + + /* 1. 输入关键字,预览出现标记 */ + const r1 = await js(`(async () => { + editor.value = '# 标题\\n\\n银色是银色的银,银币也很银。\\n\\n- 银在列表里\\n\\n**银** 在加粗里。'; + editor.dispatchEvent(new Event('input', { bubbles: true })); + await new Promise(r => setTimeout(r, 250)); + document.getElementById('btn-find').click(); + await new Promise(r => setTimeout(r, 150)); + const inp = document.getElementById('find-input'); + inp.value = '银'; + inp.dispatchEvent(new Event('input', { bubbles: true })); + await new Promise(r => setTimeout(r, 200)); + return { + total: document.querySelectorAll('#preview mark.find-hit').length, + active: document.querySelectorAll('#preview mark.find-hit.find-hit-active').length, + count: document.getElementById('find-count').textContent + }; + })()`); + check('预览正文出现 7 处关键字标记', r1.total === 7, JSON.stringify(r1)); + check('当前命中有一个且仅一个', r1.active === 1, JSON.stringify(r1)); + check('计数显示正常', r1.count.indexOf('7') >= 0, r1.count); + + /* 1b. 编辑器叠加层同步高亮 */ + const r1b = await js(`(() => ({ + marks: document.querySelectorAll('#editor-hl mark').length, + active: document.querySelectorAll('#editor-hl mark.find-hit-active').length + }))()`); + check('编辑器叠加层出现 7 处标记', r1b.marks === 7, JSON.stringify(r1b)); + check('编辑器层当前命中唯一', r1b.active === 1, JSON.stringify(r1b)); + + /* 1c. 编辑模式(无预览)下叠加层仍然高亮 */ + const r1c = await js(`(async () => { + document.querySelector('.seg button[data-mode="edit"]').click(); + await new Promise(r => setTimeout(r, 150)); + const inEdit = document.getElementById('workspace').dataset.mode; + const marks = document.querySelectorAll('#editor-hl mark').length; + document.querySelector('.seg button[data-mode="split"]').click(); + await new Promise(r => setTimeout(r, 150)); + return { inEdit, marks }; + })()`); + check('编辑模式下叠加层保持标记', r1c.inEdit === 'edit' && r1c.marks === 7, JSON.stringify(r1c)); + + /* 2. 下一处:active 移动 */ + const r2 = await js(`(() => { + document.getElementById('find-next').click(); + return { + actives: [...document.querySelectorAll('#preview mark.find-hit-active')].map(m => m.textContent), + idx: document.getElementById('find-count').textContent + }; + })()`); + check('下一处后当前命中唯一', r2.actives.length === 1, JSON.stringify(r2)); + check('计数推进到 2 / 7', r2.idx.indexOf('2 /') >= 0, r2.idx); + + /* 3. 编辑内容后(renderNow 重建 DOM)标记恢复 */ + const r3 = await js(`(async () => { + editor.focus(); + editor.setSelectionRange(editor.value.length, editor.value.length); + document.execCommand('insertText', false, '\\n新增一行也带银字。'); + await new Promise(r => setTimeout(r, 350)); + return { total: document.querySelectorAll('#preview mark.find-hit').length }; + })()`); + check('编辑重渲染后标记自动恢复', r3.total === 8, JSON.stringify(r3)); + + /* 4. 关闭查找,标记清除 */ + const r4 = await js(`(() => { + document.getElementById('find-close').click(); + return { + preview: document.querySelectorAll('#preview mark.find-hit').length, + editor: document.querySelectorAll('#editor-hl mark').length + }; + })()`); + check('关闭查找后标记全部清除', r4.preview === 0, JSON.stringify(r4)); + check('编辑器叠加层同时清空', r4.editor === 0, JSON.stringify(r4)); + + /* 5. 再次查找(新关键字),标记正常 */ + const r5 = await js(`(async () => { + document.getElementById('btn-find').click(); + const inp = document.getElementById('find-input'); + inp.value = '标题'; + inp.dispatchEvent(new Event('input', { bubbles: true })); + await new Promise(r => setTimeout(r, 200)); + return { + total: document.querySelectorAll('#preview mark.find-hit').length, + text: [...document.querySelectorAll('#preview mark.find-hit')].map(m => m.textContent) + }; + })()`); + check('新关键字标记正常', r5.total === 1 && r5.text[0] === '标题', JSON.stringify(r5)); + + /* 6. 换回完整文本输入框内容,普通正文无残留 mark */ + const r6 = await js(`(() => { + document.getElementById('find-close').click(); + return { marks: document.querySelectorAll('#preview mark').length }; + })()`); + check('正文中无任何 mark 残留', r6.marks === 0, JSON.stringify(r6)); + + console.log('\n==== 预览查找高亮测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/genicon.js b/tools/genicon.js new file mode 100644 index 0000000..3c1d6e2 --- /dev/null +++ b/tools/genicon.js @@ -0,0 +1,73 @@ +/* 生成应用图标:渲染 SVG 风格图形 → PNG 多尺寸 → 打包为 .ico */ +const { app, BrowserWindow, nativeImage } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); + +const HTML = `
+
XYMD
+
`; + +function buildIco(pngs) { + const count = pngs.length; + const header = Buffer.alloc(6); + header.writeUInt16LE(0, 0); + header.writeUInt16LE(1, 2); + header.writeUInt16LE(count, 4); + let offset = 6 + count * 16; + const entries = []; + const datas = []; + for (const p of pngs) { + const e = Buffer.alloc(16); + e[0] = p.size >= 256 ? 0 : p.size; + e[1] = p.size >= 256 ? 0 : p.size; + e[2] = 0; + e[3] = 0; + e.writeUInt16LE(1, 4); + e.writeUInt16LE(32, 6); + e.writeUInt32LE(p.buf.length, 8); + e.writeUInt32LE(offset, 12); + offset += p.buf.length; + entries.push(e); + datas.push(p.buf); + } + return Buffer.concat([header, ...entries, ...datas]); +} + +app.whenReady().then(async () => { + const win = new BrowserWindow({ + width: 512, height: 512, show: false, frame: false, transparent: true, + backgroundColor: '#00000000', + webPreferences: { offscreen: false } + }); + await win.loadURL('data:text/html;charset=utf-8,' + encodeURIComponent(HTML)); + await new Promise((r) => setTimeout(r, 900)); + + const img = await win.webContents.capturePage(); + const sizes = [16, 24, 32, 48, 64, 128, 256]; + const pngs = sizes.map((size) => ({ + size, + buf: img.resize({ width: size, height: size, quality: 'best' }).toPNG() + })); + + const outDir = path.join(__dirname, '..', 'build'); + fs.mkdirSync(outDir, { recursive: true }); + fs.writeFileSync(path.join(outDir, 'icon.ico'), buildIco(pngs)); + fs.writeFileSync(path.join(outDir, 'icon.png'), img.resize({ width: 512, height: 512, quality: 'best' }).toPNG()); + console.log('icon written:', path.join(outDir, 'icon.ico'), fs.statSync(path.join(outDir, 'icon.ico')).size, 'bytes'); + app.exit(0); +}); diff --git a/tools/migrationtest.js b/tools/migrationtest.js new file mode 100644 index 0000000..460da1e --- /dev/null +++ b/tools/migrationtest.js @@ -0,0 +1,111 @@ +/* 直接驱动真实 main.js:验证标签↔独立窗口双向迁移 */ +const { app, BrowserWindow } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +const main = require('../src/main.js'); +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; +const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'migration-')); + const docs = ['A.md', 'B.md', 'C.md'].map((n) => { + const p = path.join(tmp, n); + fs.writeFileSync(p, '# ' + n + '\n\n内容 ' + n + '\n', 'utf8'); + return { path: p, name: n, text: '# ' + n + '\n\n内容 ' + n + '\n', eol: '\n' }; + }); + + await wait(1200); + let wins = BrowserWindow.getAllWindows(); + await wins[0].webContents.executeJavaScript(`localStorage.clear()`); + await wins[0].webContents.reload(); + await wait(1200); + check('启动后 1 个窗口', wins.length === 1, String(wins.length)); + + // 在标签模式下打开 3 个文档 + for (const d of docs) { + wins[0].webContents.send('cmd', 'file-opened', Object.assign({ ok: true }, d)); + await wait(300); + } + const tabCount = await wins[0].webContents.executeJavaScript(`document.querySelectorAll('#tabbar .tab').length`); + check('标签模式有 3 个标签(欢迎 + A + B)', tabCount >= 3, String(tabCount)); + check('标题显示最后打开的文件', wins[0].getTitle().indexOf('C.md') >= 0, wins[0].getTitle()); + + // 切到 A 标签,标题应跟着变(同步给主进程) + await wins[0].webContents.executeJavaScript(`document.querySelectorAll('#tabbar .tab')[1].click()`); + await wait(500); + check('切换标签后标题变成 A.md', wins[0].getTitle().indexOf('A.md') >= 0, wins[0].getTitle()); + + /* ---- 标签 → 独立窗口:应拆成多个窗口 ---- */ + await main.setOpenMode('windows'); + await wait(3200); + wins = BrowserWindow.getAllWindows(); + check('切成独立窗口模式后拆成多个窗口', wins.length >= 3, String(wins.length)); + + let allHidden = true; + let foundDoc = false; + for (const w of wins) { + try { + const info = await w.webContents.executeJavaScript(`({ + hidden: document.getElementById('tabbar').hidden, + val: editor.value.slice(0, 30) + })`); + if (!info.hidden) allHidden = false; + if (info.val.indexOf('内容') >= 0) foundDoc = true; + } catch (_) { /* 已关闭 */ } + } + check('拆分后各窗口标签栏隐藏', allHidden === true); + check('拆分后文档内容被带过去', foundDoc === true); + check('主进程模式为 windows', main.getOpenMode() === 'windows'); + + /* ---- 独立窗口 → 标签:应合并成一个窗口 ---- */ + await main.setOpenMode('tabs'); + await wait(3500); + wins = BrowserWindow.getAllWindows(); + check('切成标签模式后合并为 1 个窗口', wins.length === 1, String(wins.length)); + + if (wins.length === 1) { + const merged = await wins[0].webContents.executeJavaScript(`(() => ({ + hidden: document.getElementById('tabbar').hidden, + n: document.querySelectorAll('#tabbar .tab').length, + names: [...document.querySelectorAll('#tabbar .tab-name')].map(e => e.textContent) + }))()`); + check('合并后标签栏可见', merged.hidden === false); + check('合并后保留全部 4 个标签(含空白欢迎页)', merged.n === 4, JSON.stringify(merged.names)); + check('合并后标签名正确', ['A.md', 'B.md', 'C.md'].every((n) => merged.names.includes(n)), JSON.stringify(merged.names)); + } + check('主进程模式为 tabs', main.getOpenMode() === 'tabs'); + + /* ---- 保存必须直接覆盖原文件,而不是弹另存为 ---- */ + if (wins.length === 1) { + const before = fs.readFileSync(docs[0].path, 'utf8'); + await wins[0].webContents.executeJavaScript(`(() => { + // 确保激活的是 A.md 标签 + const idx = [...document.querySelectorAll('#tabbar .tab-name')].findIndex(e => e.textContent === 'A.md'); + if (idx >= 0) document.querySelectorAll('#tabbar .tab')[idx].click(); + })()`); + await wait(500); + await wins[0].webContents.executeJavaScript(`(() => { + editor.focus(); + editor.setSelectionRange(editor.value.length, editor.value.length); + document.execCommand('insertText', false, '\\n保存覆盖验证标记'); + })()`); + await wait(250); + wins[0].webContents.send('cmd', 'save'); + await wait(900); + const after = fs.readFileSync(docs[0].path, 'utf8'); + check('保存直接覆盖原文件(A.md 内容已更新)', after.indexOf('保存覆盖验证标记') >= 0, after.slice(-60)); + check('覆盖前原内容仍保留', before.indexOf('内容 A.md') >= 0); + const title = wins[0].getTitle(); + check('保存后标题仍是 A.md', title.indexOf('A.md') >= 0, title); + } + + console.log('\n==== 模式迁移测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/mklink.js b/tools/mklink.js new file mode 100644 index 0000000..47e8ed6 --- /dev/null +++ b/tools/mklink.js @@ -0,0 +1,23 @@ +const ws = require('windows-shortcuts'); +const path = require('path'); + +// 用 USERPROFILE 而不是写死某个人的目录 —— 换机器/换用户名都能直接用。 +const home = process.env.USERPROFILE || process.env.HOME; +const appDir = path.join(home, 'Apps', 'XiaoyinMarkdown'); +const target = path.join(appDir, 'XiaoyinMarkdown.exe'); +const workingDir = appDir; +const lnk = path.join(home, 'Desktop', '小银Markdown.lnk'); + +ws.create( + lnk, + { target, workingDir, icon: target, iconIndex: 0, desc: '小银 Markdown 编辑器', runStyle: 1 }, + (err) => { + if (err) { + console.log('ERR', err.message); + process.exit(1); + } + ws.query(lnk, (e, d) => { + console.log(e ? 'QUERY ERR ' + e.message : JSON.stringify(d, null, 2)); + }); + } +); diff --git a/tools/mklnk.js b/tools/mklnk.js new file mode 100644 index 0000000..0c0357c --- /dev/null +++ b/tools/mklnk.js @@ -0,0 +1,113 @@ +/* 生成 Windows .lnk 快捷方式(纯字节拼装,不依赖 COM) */ +const fs = require('node:fs'); +const path = require('node:path'); + +function buildLnk({ target, workdir, icon, desc, args }) { + const isUnicode = true; + + // ---- StringData ---- + const strings = []; + const pushStr = (s) => { + if (s == null) return 0; + const chars = isUnicode ? 2 : 1; + const buf = Buffer.alloc(2 + s.length * chars); + buf.writeUInt16LE(s.length, 0); + if (isUnicode) buf.write(s, 2, 'utf16le'); + else buf.write(s, 2, 'latin1'); + strings.push(buf); + return 1; + }; + + let flags = 0x00000002 /* HasLinkInfo */ | 0x00000004 /* HasName */; + const parts = []; + parts.push(pushStr(desc ? desc : null)); // NAME_STRING + if (target) { flags |= 0x00000008; parts.push(pushStr(null)); } // RELATIVE_PATH 占位(用 target) + if (workdir) { flags |= 0x00000010; parts.push(pushStr(workdir)); } + if (args) { flags |= 0x00000020; parts.push(pushStr(args)); } + if (icon) { flags |= 0x00000040; parts.push(pushStr(icon)); } + if (isUnicode) flags |= 0x00000080; + + // 重新按顺序构建(NAME, RELATIVE_PATH, WORKING_DIR, ARGUMENTS, ICON) + strings.length = 0; + const seq = []; + const add = (s) => { + const buf = Buffer.alloc(2 + String(s).length * 2); + buf.writeUInt16LE(String(s).length, 0); + buf.write(String(s), 2, 'utf16le'); + seq.push(buf); + }; + if (desc) add(desc); + if (target) add(target); // RELATIVE_PATH + if (workdir) add(workdir); + if (args) add(args); + if (icon) add(icon); + const stringData = Buffer.concat(seq); + + // ---- LinkInfo ---- + const volumeLabel = Buffer.from([0x00]); // 空卷标 + const volumeIdHeader = Buffer.alloc(16); + volumeIdHeader.writeUInt32LE(16 + volumeLabel.length, 0); // VolumeIDSize + volumeIdHeader.writeUInt32LE(3, 4); // DRIVE_FIXED + volumeIdHeader.writeUInt32LE(0x12345678, 8); // DriveSerialNumber + volumeIdHeader.writeUInt32LE(0x10, 12); // VolumeLabelOffset + const volumeId = Buffer.concat([volumeIdHeader, volumeLabel]); + + const localBaseAnsi = Buffer.from(target + '\0', 'latin1'); + const suffixAnsi = Buffer.from([0x00]); + const localBaseUni = Buffer.from(target + '\0', 'utf16le'); + const suffixUni = Buffer.from([0x00, 0x00]); + + const headerSize = 0x24; + const volumeIdOffset = headerSize; + const localBaseOffset = volumeIdOffset + volumeId.length; + const suffixOffset = localBaseOffset + localBaseAnsi.length; + const localBaseUniOffset = suffixOffset + suffixAnsi.length; + const suffixUniOffset = localBaseUniOffset + localBaseUni.length; + const linkInfoSize = suffixUniOffset + suffixUni.length; + + const li = Buffer.alloc(headerSize); + li.writeUInt32LE(linkInfoSize, 0); + li.writeUInt32LE(headerSize, 4); + li.writeUInt32LE(0x00000001, 8); // VolumeIDAndLocalBasePath + li.writeUInt32LE(volumeIdOffset, 12); + li.writeUInt32LE(localBaseOffset, 16); + li.writeUInt32LE(0, 20); // CommonNetworkRelativeLinkOffset + li.writeUInt32LE(suffixOffset, 24); + li.writeUInt32LE(localBaseUniOffset, 28); + li.writeUInt32LE(suffixUniOffset, 32); + + const linkInfo = Buffer.concat([li, volumeId, localBaseAnsi, suffixAnsi, localBaseUni, suffixUni]); + + // ---- Header (76 bytes) ---- + const h = Buffer.alloc(76); + h.writeUInt32LE(0x4c, 0); + // LinkCLSID {00021401-0000-0000-C000-000000000046} + Buffer.from('0114020000000000c000000000000046', 'hex').copy(h, 4); + h.writeUInt32LE(flags, 20); + h.writeUInt32LE(0x20, 24); // FILE_ATTRIBUTE_ARCHIVE + // 28 CreationTime / 36 AccessTime / 44 WriteTime 均留 0 + h.writeUInt32LE(0, 52); // FileSize + h.writeUInt32LE(0, 56); // IconIndex + h.writeUInt32LE(1, 60); // ShowCommand = SW_SHOWNORMAL + h.writeUInt16LE(0, 64); // HotKey + h.writeUInt16LE(0, 66); // Reserved1 + h.writeUInt32LE(0, 68); // Reserved2 + h.writeUInt32LE(0, 72); // Reserved3 + + return Buffer.concat([h, linkInfo, stringData, Buffer.alloc(4)]); // 末尾 TerminalBlock +} + +const target = (process.argv[2] || '').replace(/\//g, '\\'); +const out = process.argv[3]; +if (!target || !out) { + console.error('usage: node tools/mklnk.js '); + process.exit(1); +} +const buf = buildLnk({ + target, + workdir: path.dirname(target), + icon: target + ',0', + desc: '小银 Markdown 编辑器' +}); +fs.writeFileSync(out, buf); +console.log('written', out, buf.length, 'bytes'); diff --git a/tools/multitest.js b/tools/multitest.js new file mode 100644 index 0000000..0b09247 --- /dev/null +++ b/tools/multitest.js @@ -0,0 +1,222 @@ +/* 验证:标签页、独立窗口偏好、右键打开方式、状态保留 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'multitest-')); + const a = path.join(tmp, 'A文档.md'); + const b = path.join(tmp, 'B文档.md'); + fs.writeFileSync(a, '# A 文档\n\n这是 A。\n', 'utf8'); + fs.writeFileSync(b, '# B 文档\n\n这是 B。\n', 'utf8'); + const list = () => fs.readdirSync(tmp, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() })); + + let forcedMode = 'tabs'; + let lastNewWindow = ''; + let lastNewBlank = 0; + let lastSetMode = ''; + + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: list() })); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('file:readText', async (_e, p) => ({ ok: true, text: fs.readFileSync(p, 'utf8') })); + ipcMain.handle('file:copyFile', async () => ({ ok: true })); + ipcMain.handle('file:revealPath', async () => ({ ok: true })); + ipcMain.handle('clip:read', () => ''); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.handle('app:getOpenMode', async () => ({ mode: forcedMode })); + ipcMain.handle('app:setOpenMode', async (_e, m) => { lastSetMode = m; forcedMode = m; return { ok: true }; }); + ipcMain.handle('window:openPath', async (_e, p) => { lastNewWindow = p || ''; return { ok: true }; }); + ipcMain.handle('window:new', async () => { lastNewBlank++; return { ok: true }; }); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + ipcMain.on('file:drop', () => {}); + ipcMain.on('file:droppedText', () => {}); + + const win = new BrowserWindow({ + width: 1400, height: 880, show: true, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + await js(`localStorage.clear()`); + await win.webContents.reload(); + await wait(1300); + + /* 1. 初始标签 */ + const init = await js(`(() => ({ + visible: !document.getElementById('tabbar').hidden, + n: document.querySelectorAll('#tabbar .tab').length, + label: document.getElementById('openmode-label').textContent + }))()`); + check('默认标签栏可见且有 1 个标签', init.visible === true && init.n === 1, JSON.stringify(init)); + check('按钮显示「标签」', init.label === '标签', init.label); + + /* 2. 打开两个文件 → 两个新标签 */ + win.webContents.send('cmd', 'file-opened', { ok: true, path: a, name: 'A文档.md', text: fs.readFileSync(a, 'utf8'), eol: '\n' }); + await wait(300); + win.webContents.send('cmd', 'file-opened', { ok: true, path: b, name: 'B文档.md', text: fs.readFileSync(b, 'utf8'), eol: '\n' }); + await wait(400); + const two = await js(`(() => ({ + n: document.querySelectorAll('#tabbar .tab').length, + active: document.querySelector('#tabbar .tab.active .tab-name').textContent, + val: editor.value.slice(0, 6), + names: [...document.querySelectorAll('#tabbar .tab-name')].map(e => e.textContent) + }))()`); + check('打开两个文件得到 3 个标签', two.n === 3, JSON.stringify(two.names)); + check('当前标签是最后打开的文件', two.active === 'B文档.md', two.active); + check('编辑区显示当前标签内容', two.val.indexOf('B 文档') >= 0, two.val); + + /* 3. 切换标签,各自状态保留 */ + await js(`(() => { + editor.focus(); + editor.setSelectionRange(editor.value.length, editor.value.length); + document.execCommand('insertText', false, '\\nB 的修改'); + })()`); + await wait(250); + await js(`document.querySelectorAll('#tabbar .tab')[1].click()`); + await wait(350); + const switched = await js(`(() => ({ + active: document.querySelector('#tabbar .tab.active .tab-name').textContent, + val: editor.value.slice(0, 6) + }))()`); + check('点标签切到 A 文档', switched.active === 'A文档.md' && switched.val.indexOf('A 文档') >= 0, JSON.stringify(switched)); + + await js(`document.querySelectorAll('#tabbar .tab')[2].click()`); + await wait(350); + const back = await js(`editor.value.includes('B 的修改')`); + check('切回后 B 的修改还在', back === true); + + /* 4. 重复打开同一文件不新增标签 */ + win.webContents.send('cmd', 'file-opened', { ok: true, path: a, name: 'A文档.md', text: fs.readFileSync(a, 'utf8'), eol: '\n' }); + await wait(350); + const dup = await js(`document.querySelectorAll('#tabbar .tab').length`); + check('重复打开同一文件不新建标签', dup === 3, String(dup)); + + /* 5. 关闭标签 */ + await js(`document.querySelectorAll('#tabbar .tab-close')[2].click()`); + await wait(400); + const closed = await js(`(() => ({ n: document.querySelectorAll('#tabbar .tab').length, active: document.querySelector('#tabbar .tab.active .tab-name').textContent }))()`); + check('关闭标签后数量减 1', closed.n === 2, JSON.stringify(closed)); + check('关闭后切到相邻标签', ['A文档.md', '未命名'].includes(closed.active), closed.active); + + /* 6. 切换到独立窗口模式 */ + const modeInfo = await js(`(async () => { + document.getElementById('btn-openmode').click(); + await new Promise(r => setTimeout(r, 350)); + return { + hidden: document.getElementById('tabbar').hidden, + label: document.getElementById('openmode-label').textContent, + ls: localStorage.getItem('md-editor-open-mode') + }; + })()`); + check('切到窗口模式后标签栏隐藏', modeInfo.hidden === true, JSON.stringify(modeInfo)); + check('按钮文字变为「窗口」', modeInfo.label === '窗口', modeInfo.label); + check('模式写入本地存储', modeInfo.ls === 'windows', modeInfo.ls); + check('模式同步到主进程', lastSetMode === 'windows', lastSetMode); + + /* 7. 窗口模式下右键显示「在新窗口打开」,且真的走新窗口 */ + const ctxWin = await js(`(() => { + const row = [...document.querySelectorAll('#sb-body .tree-row')].find(r => r.dataset.path.endsWith('A文档.md')); + if (!row) return { err: 'no row' }; + const p = row.dataset.path; + row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 260, clientY: 200 })); + const items = [...document.querySelectorAll('#ctxmenu .ctx-item')]; + const lab = (i) => { const s = i.querySelector('span'); return s ? s.textContent : ''; }; + const first = items[0] ? lab(items[0]) : ''; + const target = items.find(i => lab(i) === '在新窗口打开'); + if (target) target.click(); + return { first, exists: !!target, path: p }; + })()`).catch(async () => { + // executeJavaScript 里不能引用 win,重来一次 + return js(`(() => { + const row = [...document.querySelectorAll('#sb-body .tree-row')].find(r => r.dataset.path.endsWith('A文档.md')); + if (!row) return { err: 'no row' }; + const p = row.dataset.path; + row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 260, clientY: 200 })); + const items = [...document.querySelectorAll('#ctxmenu .ctx-item')]; + const lab = (i) => { const s = i.querySelector('span'); return s ? s.textContent : ''; }; + const first = items[0] ? lab(items[0]) : ''; + const target = items.find(i => lab(i) === '在新窗口打开'); + if (target) target.click(); + return { first, exists: !!target, path: p }; + })()`); + }); + await wait(350); + check('窗口模式右键首项是「在新窗口打开」', ctxWin.first === '在新窗口打开', JSON.stringify(ctxWin)); + check('右键触发了独立窗口打开', lastNewWindow === a, lastNewWindow); + + /* 8. 切回标签模式,右键变「在新标签打开」 */ + await js(`document.getElementById('btn-openmode').click()`); + await wait(350); + const ctxTab = await js(`(() => { + const row = [...document.querySelectorAll('#sb-body .tree-row')].find(r => r.dataset.path.endsWith('B文档.md')); + row.dispatchEvent(new MouseEvent('contextmenu', { bubbles: true, cancelable: true, clientX: 260, clientY: 200 })); + const items = [...document.querySelectorAll('#ctxmenu .ctx-item')]; + const lab = (i) => { const s = i.querySelector('span'); return s ? s.textContent : ''; }; + const first = items[0] ? lab(items[0]) : ''; + const target = items.find(i => lab(i) === '在新标签打开'); + if (target) target.click(); + return { first, exists: !!target }; + })()`); + await wait(450); + check('标签模式右键首项是「在新标签打开」', ctxTab.first === '在新标签打开', JSON.stringify(ctxTab)); + const afterCtx = await js(`(() => ({ n: document.querySelectorAll('#tabbar .tab').length, val: editor.value.slice(0,6) }))()`); + check('右键在新标签打开生效', afterCtx.val.indexOf('B 文档') >= 0, JSON.stringify(afterCtx)); + + /* 9. 重启后保持模式 */ + await win.webContents.reload(); + await wait(1300); + const kept = await js(`(() => ({ + hidden: document.getElementById('tabbar').hidden, + label: document.getElementById('openmode-label').textContent, + tabs: document.querySelectorAll('#tabbar .tab').length + }))()`); + check('重启后保持标签模式', kept.hidden === false && kept.label === '标签', JSON.stringify(kept)); + check('重启后有欢迎标签', kept.tabs === 1, String(kept.tabs)); + + /* 9.5 关闭欢迎页后,下次启动不再显示 */ + const hadWelcome = await js(`editor.value.indexOf('欢迎使用') >= 0`); + await js(`document.querySelectorAll('#tabbar .tab-close')[0].click()`); + await wait(450); + const flag = await js(`localStorage.getItem('md-editor-welcome-closed')`); + check('初始打开的是欢迎页', hadWelcome === true); + check('关闭欢迎页后写入标记', flag === '1', flag); + await win.webContents.reload(); + await wait(1300); + const afterClose = await js(`(() => ({ + tabs: document.querySelectorAll('#tabbar .tab').length, + name: (document.querySelector('#tabbar .tab-name') || {}).textContent || '', + val: editor.value + }))()`); + check('重启后不再显示欢迎页', afterClose.val.indexOf('欢迎使用') < 0, JSON.stringify(afterClose.val.slice(0, 20))); + check('重启后是空白未命名标签', afterClose.tabs === 1 && afterClose.name === '未命名' && afterClose.val === '', JSON.stringify({ name: afterClose.name, len: afterClose.val.length })); + + /* 10. 主进程偏好为 windows 时启动即窗口模式 */ + forcedMode = 'windows'; + await win.webContents.reload(); + await wait(1300); + const fromMain = await js(`(() => ({ + hidden: document.getElementById('tabbar').hidden, + label: document.getElementById('openmode-label').textContent + }))()`); + check('主进程偏好为窗口时启动即窗口模式', fromMain.hidden === true && fromMain.label === '窗口', JSON.stringify(fromMain)); + + console.log('\n==== 多窗口/标签测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/outlinetest.js b/tools/outlinetest.js new file mode 100644 index 0000000..10415af --- /dev/null +++ b/tools/outlinetest.js @@ -0,0 +1,141 @@ +/* 验证章节目录:生成、开关、跳转、随编辑更新、状态记忆 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async () => ({ ok: false })); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('clip:read', () => ''); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + + const win = new BrowserWindow({ + width: 1360, height: 860, show: true, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + await win.webContents.executeJavaScript(`localStorage.clear()`); + await win.webContents.reload(); + await new Promise((r) => setTimeout(r, 1800)); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + // 清掉上次遗留的偏好,保证从"全新用户"状态开始 + await js(`localStorage.clear()`); + await win.webContents.reload(); + await wait(1200); + + /* 1. 默认显示且能生成大纲 */ + const init = await js(`(() => { + const rows = [...document.querySelectorAll('.ol-item')]; + const heads = [...preview.querySelectorAll('h1,h2,h3,h4,h5,h6')]; + return { + visible: !document.getElementById('outline').hidden, + count: rows.length, + heads: heads.length, + label: document.getElementById('ol-count').textContent, + btnOn: document.getElementById('btn-outline').classList.contains('on'), + first: rows[0] ? rows[0].textContent : '', + levels: rows.slice(0, 4).map(r => r.dataset.level) + }; + })()`); + check('默认显示章节目录', init.visible === true); + check('大纲条数等于标题数', init.count > 0 && init.count === init.heads, init.count + ' vs ' + init.heads); + check('计数徽标同步', init.label === String(init.count), init.label); + check('右上角按钮为开启态', init.btnOn === true); + check('首条是欢迎标题', init.first.indexOf('欢迎使用') >= 0, init.first); + check('层级信息正确', init.levels[0] === '1', JSON.stringify(init.levels)); + + /* 2. 关闭按钮 */ + const closed = await js(`(() => { + document.getElementById('ol-close').click(); + return { hidden: document.getElementById('outline').hidden, on: document.getElementById('btn-outline').classList.contains('on'), ls: localStorage.getItem('md-editor-outline') }; + })()`); + check('点关闭后大纲隐藏', closed.hidden === true); + check('关闭后按钮取消高亮', closed.on === false); + check('关闭状态被记住', closed.ls === '0', closed.ls); + + /* 3. 用右上角按钮再打开 */ + const reopened = await js(`(() => { + document.getElementById('btn-outline').click(); + return { hidden: document.getElementById('outline').hidden, on: document.getElementById('btn-outline').classList.contains('on'), rows: document.querySelectorAll('.ol-item').length }; + })()`); + check('右上角按钮可重新打开', reopened.hidden === false && reopened.on === true); + check('重新打开后条目仍在', reopened.rows === init.count, String(reopened.rows)); + + /* 4. 快捷键 / 菜单命令切换 */ + win.webContents.send('cmd', 'outline'); + await wait(200); + const byCmd = await js(`document.getElementById('outline').hidden`); + check('菜单命令可切换大纲', byCmd === true); + win.webContents.send('cmd', 'outline'); + await wait(200); + const byCmd2 = await js(`document.getElementById('outline').hidden`); + check('再切一次恢复显示', byCmd2 === false); + + /* 5. 点击大纲跳转 */ + const jump = await js(`(() => { + const rows = [...document.querySelectorAll('.ol-item')]; + const heads = [...preview.querySelectorAll('h1,h2,h3,h4,h5,h6')]; + const target = rows[2]; + const expectLine = Number(heads[2].dataset.line); + target.click(); + return { expectLine, activeIdx: rows.indexOf(document.querySelector('.ol-item.active')) }; + })()`); + await wait(700); + const jumped = await js(`(() => { + const pos = editor.selectionStart; + const line = editor.value.slice(0, pos).split('\\n').length - 1; + return { line, active: [...document.querySelectorAll('.ol-item')].findIndex(r => r.classList.contains('active')), pTop: preview.scrollTop }; + })()`); + check('点击大纲定位到源码对应行', jumped.line === jump.expectLine, jumped.line + ' vs ' + jump.expectLine); + check('点击后大纲高亮该项', jumped.active === 2, String(jumped.active)); + check('阅读区同步滚动', jumped.pTop > 0 || jump.expectLine === 0, String(jumped.pTop)); + + /* 6. 编辑内容后大纲实时更新 */ + const updated = await js(`(async () => { + editor.focus(); + editor.setSelectionRange(editor.value.length, editor.value.length); + document.execCommand('insertText', false, '\\n\\n## 新增的一个章节\\n\\n正文\\n\\n### 三级小节\\n'); + await new Promise(r => setTimeout(r, 350)); + const rows = [...document.querySelectorAll('.ol-item')]; + return { count: rows.length, last: rows[rows.length - 1].textContent, hasNew: rows.some(r => r.textContent === '新增的一个章节') }; + })()`); + check('新增标题后大纲自动更新', updated.hasNew === true && updated.count === init.count + 2, JSON.stringify(updated)); + check('三级标题也被收录', updated.last === '三级小节', updated.last); + + /* 7. 无标题文档显示空提示 */ + const empty = await js(`(async () => { + editor.value = '只有正文,没有任何标题。\\n'; + editor.dispatchEvent(new Event('input')); + await new Promise(r => setTimeout(r, 350)); + return { rows: document.querySelectorAll('.ol-item').length, tip: document.querySelector('.ol-empty') ? document.querySelector('.ol-empty').textContent : '', label: document.getElementById('ol-count').textContent }; + })()`); + check('无标题时给出空提示', empty.rows === 0 && empty.tip.length > 0, empty.tip); + check('无标题时计数为 0', empty.label === '0'); + + /* 8. 重启后保持隐藏状态 */ + await js(`document.getElementById('ol-close').click()`); + await wait(200); + await win.webContents.reload(); + await wait(1100); + const kept = await js(`({ hidden: document.getElementById('outline').hidden, rows: document.querySelectorAll('.ol-item').length })`); + check('重启后保持上次的显示状态', kept.hidden === true, String(kept.hidden)); + check('重启后大纲仍能生成', kept.rows > 0, String(kept.rows)); + + console.log('\n==== 章节目录测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/paneltest.js b/tools/paneltest.js new file mode 100644 index 0000000..872cd37 --- /dev/null +++ b/tools/paneltest.js @@ -0,0 +1,154 @@ +/* 验证:目录/大纲宽度可拖拽、写入本地存储、重启恢复、分隔条跟随面板显隐 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'paneltest-')); + fs.writeFileSync(path.join(tmp, '文档.md'), '# 文档\n\n正文。\n', 'utf8'); + const list = () => fs.readdirSync(tmp, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() })); + + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: list() })); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('file:readText', async (_e, p) => ({ ok: true, text: fs.readFileSync(p, 'utf8') })); + ipcMain.handle('file:copyFile', async () => ({ ok: true })); + ipcMain.handle('file:revealPath', async () => ({ ok: true })); + ipcMain.handle('clip:read', () => ''); ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.handle('app:getOpenMode', async () => ({ mode: 'tabs' })); + ipcMain.handle('app:setOpenMode', async () => ({ ok: true })); + ipcMain.on('app:setDirty', () => {}); ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); ipcMain.on('docs:exported', () => {}); + + const win = new BrowserWindow({ + width: 1440, height: 900, show: true, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + await js(`localStorage.clear(); localStorage.setItem('md-editor-dir', ${JSON.stringify(tmp)});`); + await win.webContents.reload(); + await wait(1400); + + /* 1. 初始宽度与分隔条存在 */ + const init = await js(`(() => ({ + sb: document.getElementById('sidebar').getBoundingClientRect().width, + ol: document.getElementById('outline').getBoundingClientRect().width, + sbSp: !document.getElementById('sb-splitter').hidden, + olSp: !document.getElementById('ol-splitter').hidden + }))()`); + check('分隔条存在且可见', init.sbSp === true && init.olSp === true, JSON.stringify(init)); + check('目录初始宽度约 232', Math.abs(init.sb - 232) < 4, String(init.sb)); + check('大纲初始宽度约 210', Math.abs(init.ol - 210) < 4, String(init.ol)); + + /* 2. 拖拽目录变宽 */ + const sbDrag = await js(`(() => { + const before = document.getElementById('sidebar').getBoundingClientRect().width; + const sp = document.getElementById('sb-splitter'); + sp.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, clientX: before + 6 })); + document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: before + 146 })); + document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); + const after = document.getElementById('sidebar').getBoundingClientRect().width; + return { before, after, saved: localStorage.getItem('md-editor-sb-w') }; + })()`); + check('拖拽后目录变宽约 150px', Math.abs(sbDrag.after - sbDrag.before - 140) < 25, JSON.stringify(sbDrag)); + check('目录宽度写入本地存储', !!sbDrag.saved && Math.abs(Number(sbDrag.saved) - sbDrag.after) < 3, sbDrag.saved); + + /* 3. 拖拽大纲变宽(分隔条在大纲左边缘,向左拖 = 变宽) */ + const olDrag = await js(`(() => { + const ol = document.getElementById('outline'); + const before = ol.getBoundingClientRect().width; + const left = ol.getBoundingClientRect().left; + const sp = document.getElementById('ol-splitter'); + sp.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, clientX: left + 2 })); + document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: left - 98 })); + document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); + const after = ol.getBoundingClientRect().width; + return { before, after, saved: localStorage.getItem('md-editor-ol-w') }; + })()`); + check('拖拽后大纲变宽约 100px', Math.abs(olDrag.after - olDrag.before - 98) < 20, JSON.stringify(olDrag)); + check('大纲宽度写入本地存储', !!olDrag.saved && Math.abs(Number(olDrag.saved) - olDrag.after) < 3, olDrag.saved); + + /* 4. 重启后宽度恢复 */ + await win.webContents.reload(); + await wait(1400); + const kept = await js(`(() => ({ + sb: document.getElementById('sidebar').getBoundingClientRect().width, + ol: document.getElementById('outline').getBoundingClientRect().width + }))()`); + check('重启后目录宽度恢复', Math.abs(kept.sb - sbDrag.after) < 4, JSON.stringify(kept)); + check('重启后大纲宽度恢复', Math.abs(kept.ol - olDrag.after) < 4, JSON.stringify(kept)); + + /* 5. 最小宽度限制(放在恢复验证之后,避免覆盖已保存的宽度) */ + const minTest = await js(`(() => { + document.getElementById('sb-splitter').dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, clientX: 300 })); + document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: 2 })); + document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); + return document.getElementById('sidebar').getBoundingClientRect().width; + })()`); + check('目录宽度不会被拖到小于 180', minTest >= 180 && minTest < 220, String(minTest)); + + /* 6. 关闭面板时分隔条跟随隐藏 */ + await js(`document.getElementById('sb-close').click()`); + await wait(200); + const sbHidden = await js(`document.getElementById('sb-splitter').hidden`); + check('目录隐藏时分隔条跟随隐藏', sbHidden === true); + await js(`document.getElementById('ol-close').click()`); + await wait(200); + const olHidden = await js(`document.getElementById('ol-splitter').hidden`); + check('大纲隐藏时分隔条跟随隐藏', olHidden === true); + + /* 7. 重新打开时分隔条恢复,宽度仍是记住的值 */ + await js(`(() => { + localStorage.setItem('md-editor-sb', '0'); + document.getElementById('btn-tree').click(); + })()`); + await wait(250); + await js(`document.getElementById('btn-outline').click()`); + await wait(250); + const reopened = await js(`(() => ({ + sbSp: !document.getElementById('sb-splitter').hidden, + olSp: !document.getElementById('ol-splitter').hidden, + sb: document.getElementById('sidebar').getBoundingClientRect().width, + ol: document.getElementById('outline').getBoundingClientRect().width + }))()`); + check('重新打开后分隔条恢复', reopened.sbSp === true && reopened.olSp === true, JSON.stringify(reopened)); + const savedNow = await js(`({ sb: localStorage.getItem('md-editor-sb-w'), ol: localStorage.getItem('md-editor-ol-w') })`); + check('重新打开后宽度与保存值一致', + Math.abs(reopened.sb - Number(savedNow.sb)) < 4 && Math.abs(reopened.ol - Number(savedNow.ol)) < 4, + JSON.stringify({ reopened, savedNow })); + + /* 8. 编辑/预览分栏比例记忆 */ + const splitDrag = await js(`(() => { + const ws = document.getElementById('workspace'); + const rect = ws.getBoundingClientRect(); + const sp = document.getElementById('splitter'); + const before = document.getElementById('editor-pane').getBoundingClientRect().width; + sp.dispatchEvent(new MouseEvent('mousedown', { bubbles: true, cancelable: true, clientX: rect.left + before })); + document.dispatchEvent(new MouseEvent('mousemove', { bubbles: true, clientX: rect.left + rect.width * 0.62 })); + document.dispatchEvent(new MouseEvent('mouseup', { bubbles: true })); + const after = document.getElementById('editor-pane').getBoundingClientRect().width; + return { before, after, pct: localStorage.getItem('md-editor-split-pct') }; + })()`); + check('拖拽分栏后比例写入存储', !!splitDrag.pct && Math.abs(Number(splitDrag.pct) - 0.62) < 0.05, JSON.stringify(splitDrag)); + await win.webContents.reload(); + await wait(1400); + const splitKept = await js(`document.getElementById('editor-pane').getBoundingClientRect().width / document.getElementById('workspace').getBoundingClientRect().width`); + check('重启后分栏比例恢复', Math.abs(splitKept - 0.62) < 0.03, String(splitKept)); + + console.log('\n==== 面板宽度测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/shot2.js b/tools/shot2.js new file mode 100644 index 0000000..c4464ff --- /dev/null +++ b/tools/shot2.js @@ -0,0 +1,44 @@ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); +const theme = process.env.SHOT_THEME || 'light'; +const out = process.env.SHOT_OUT || path.join(__dirname, '..', 'shot.png'); + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'shotdir-')); + const mk = (n, c) => fs.writeFileSync(path.join(tmp, n), c, 'utf8'); + mk('产品需求说明.md', '# 产品需求说明\n\n## 目标\n\n做一个**纯本地**的 Markdown 编辑器。\n\n- 实时预览\n- 右键复制全文\n- 拖进来就打开\n\n> 不联网,不登录。\n'); + mk('API 设计.md', '# API\n'); + mk('更新日志.md', '# 更新日志\n'); + mk('readme.txt', 'txt\n'); + fs.mkdirSync(path.join(tmp, '草稿')); + fs.writeFileSync(path.join(tmp, '草稿', '想法.md'), '# 想法\n', 'utf8'); + + const list = () => fs.readdirSync(tmp, { withFileTypes: true }) + .filter(d => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map(d => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() })) + .sort((a, b) => (Number(b.isDir) - Number(a.isDir)) || a.name.localeCompare(b.name, 'zh-Hans-CN')); + + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: list() })); + ipcMain.handle('dir:open', async () => ({ ok: false })); + ipcMain.handle('clip:read', () => ''); ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.on('app:setDirty', () => {}); ipcMain.on('win:setTitle', () => {}); ipcMain.on('save:finished', () => {}); + + const win = new BrowserWindow({ width: 1380, height: 880, show: true, backgroundColor: '#fff', + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false } }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + await win.webContents.executeJavaScript(`localStorage.setItem('md-editor-theme', ${JSON.stringify(theme)}); document.documentElement.dataset.theme = ${JSON.stringify(theme)};`); + win.webContents.send('cmd', 'dir-opened', { ok: true, path: tmp, name: path.basename(tmp), entries: list() }); + await new Promise(r => setTimeout(r, 500)); + win.webContents.send('cmd', 'file-opened', { ok: true, path: path.join(tmp, '产品需求说明.md'), name: '产品需求说明.md', text: fs.readFileSync(path.join(tmp, '产品需求说明.md'), 'utf8'), eol: '\n' }); + await new Promise(r => setTimeout(r, 1400)); + const img = await win.webContents.capturePage(); + fs.writeFileSync(out, img.toPNG()); + console.log('saved', out); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(0); +}); diff --git a/tools/sidetest.js b/tools/sidetest.js new file mode 100644 index 0000000..6c56682 --- /dev/null +++ b/tools/sidetest.js @@ -0,0 +1,97 @@ +/* 验证:启动即显示侧栏、空态引导、记住上次文件夹 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +let pass = 0, fail = 0; +const check = (n, ok, extra) => { + if (ok) { pass++; console.log('PASS ' + n); } + else { fail++; console.log('FAIL ' + n + (extra ? ' → ' + extra : '')); } +}; + +app.whenReady().then(async () => { + const tmp = fs.mkdtempSync(path.join(os.tmpdir(), 'sidetest-')); + fs.writeFileSync(path.join(tmp, '一篇.md'), '# 一篇\n', 'utf8'); + fs.writeFileSync(path.join(tmp, '二篇.md'), '# 二篇\n', 'utf8'); + + const list = () => fs.readdirSync(tmp, { withFileTypes: true }) + .filter((d) => !d.name.startsWith('.') && (d.isDirectory() || /\.(md|txt)$/i.test(d.name))) + .map((d) => ({ name: d.name, path: path.join(tmp, d.name), isDir: d.isDirectory() })); + + ipcMain.handle('file:openPath', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), text: fs.readFileSync(p, 'utf8'), eol: '\n' })); + ipcMain.handle('dir:read', async (_e, p) => { + if (!fs.existsSync(p)) return { ok: false }; + return { ok: true, path: p, name: path.basename(p), entries: list() }; + }); + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('clip:read', () => ''); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + + const win = new BrowserWindow({ + width: 1280, height: 820, show: false, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + const js = (c) => win.webContents.executeJavaScript(c); + const wait = (ms) => new Promise((r) => setTimeout(r, ms)); + await wait(700); + + // 1. 清空记忆后重新加载 = 首次启动 + await js(`localStorage.clear()`); + await win.webContents.reload(); + await wait(1100); + const first = await js(`({ + visible: !document.getElementById('sidebar').hidden, + hasBtn: !!document.querySelector('.sb-pick-btn'), + title: document.getElementById('sb-title').textContent, + hasTree: document.querySelectorAll('#sb-body .tree-row').length + })`); + check('首次启动显示左侧目录(空态引导)', first.visible === true, JSON.stringify(first)); + check('空态有「选择文件夹」按钮', first.hasBtn === true); + check('无文件夹时不渲染空条目', first.hasTree === 0); + check('面板标题为「目录」', first.title === '目录', first.title); + + // 2. 打开文件夹后记录到本地 + win.webContents.send('cmd', 'dir-opened', { ok: true, path: tmp, name: path.basename(tmp), entries: list() }); + await wait(400); + const after = await js(`({ saved: localStorage.getItem('md-editor-dir'), rows: document.querySelectorAll('#sb-body .tree-row').length, title: document.getElementById('sb-title').textContent })`); + check('打开文件夹后写入记忆', after.saved === tmp, after.saved); + check('文件树列出两个文件', after.rows === 2, String(after.rows)); + check('侧栏标题为文件夹名', after.title === path.basename(tmp), after.title); + + // 3. 重启后自动恢复上次文件夹 + await win.webContents.reload(); + await wait(1100); + const restored = await js(`({ + visible: !document.getElementById('sidebar').hidden, + title: document.getElementById('sb-title').textContent, + rows: [...document.querySelectorAll('#sb-body .tree-row')].map(r => r.querySelector('.tree-name').textContent) + })`); + check('重启后自动恢复上次文件夹', restored.visible === true && restored.rows.length === 2, JSON.stringify(restored)); + check('恢复后标题正确', restored.title === path.basename(tmp)); + + // 4. 收起后下次启动保持收起 + await js(`document.getElementById('sb-close').click()`); + await wait(200); + await win.webContents.reload(); + await wait(1100); + const kept = await js(`!document.getElementById('sidebar').hidden`); + check('用户收起后重启仍保持收起', kept === false, String(kept)); + + // 5. 工具栏按钮再次唤出 + await js(`document.getElementById('btn-tree').click()`); + await wait(400); + const shown = await js(`({ hidden: document.getElementById('sidebar').hidden, rows: document.querySelectorAll('#sb-body .tree-row').length })`); + check('工具栏可重新唤出文件树', shown.hidden === false && shown.rows === 2, JSON.stringify(shown)); + + console.log('\n==== 侧栏测试:通过 ' + pass + ',失败 ' + fail + ' ===='); + fs.rmSync(tmp, { recursive: true, force: true }); + app.exit(fail ? 1 : 0); +}); diff --git a/tools/test.js b/tools/test.js new file mode 100644 index 0000000..e2f154d --- /dev/null +++ b/tools/test.js @@ -0,0 +1,245 @@ +/* 自测脚本:跑真实渲染进程逻辑,验证打开/编辑/保存/撤销/渲染/查找 */ +const { app, BrowserWindow, ipcMain } = require('electron'); +const path = require('node:path'); +const fs = require('node:fs'); +const os = require('node:os'); + +const results = []; +function check(name, ok, extra) { + results.push({ name, ok: !!ok, extra }); + console.log((ok ? 'PASS ' : 'FAIL ') + name + (extra ? ' → ' + extra : '')); +} + +app.whenReady().then(async () => { + const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mdtest-')); + const tmpFile = path.join(tmpDir, '测试文档.md'); + const sample = '# 标题一\n\n**粗体** 正文\n\n| A | B |\n| --- | --- |\n| 1 | 2 |\n\n- [x] 完成\n'; + fs.writeFileSync(tmpFile, sample, 'utf8'); + fs.mkdirSync(path.join(tmpDir, 'sub')); + fs.writeFileSync(path.join(tmpDir, 'sub', 'c.md'), '# 子文件\n\n内容\n', 'utf8'); + fs.writeFileSync(path.join(tmpDir, '其他.txt'), 'hello\n', 'utf8'); + fs.writeFileSync(path.join(tmpDir, 'pic.png'), 'not markdown\n', 'utf8'); + + // 模拟主进程的保存 handler + ipcMain.handle('file:save', async (_e, p) => { + let target = p.__target || tmpFile; + await fs.promises.writeFile(target, p.content, 'utf8'); + return { ok: true, path: target, name: path.basename(target) }; + }); + ipcMain.handle('file:openPath', async (_e, p) => { + const text = fs.readFileSync(p, 'utf8'); + return { ok: true, path: p, name: path.basename(p), text, eol: '\n' }; + }); + ipcMain.handle('clip:read', () => 'PASTED'); + ipcMain.handle('clip:write', () => true); + ipcMain.handle('file:reveal', () => ({ ok: true })); + ipcMain.handle('ui:message', () => 0); + ipcMain.handle('shell:openExternal', () => true); + + // 目录读取(与 main.js 的 listDir 保持同样的过滤规则) + const MD_RE = /\.(md|markdown|mdown|mkd|mdwn|txt)$/i; + const listDir = (dir) => { + const entries = []; + for (const d of fs.readdirSync(dir, { withFileTypes: true })) { + if (d.name.startsWith('.') || d.name === 'node_modules') continue; + const full = path.join(dir, d.name); + const isDir = d.isDirectory(); + if (!isDir && !MD_RE.test(d.name)) continue; + entries.push({ name: d.name, path: full, isDir }); + } + entries.sort((a, b) => (Number(b.isDir) - Number(a.isDir)) || a.name.localeCompare(b.name, 'zh-Hans-CN')); + return entries; + }; + ipcMain.handle('dir:open', async () => ({ ok: false, canceled: true })); + ipcMain.handle('dir:read', async (_e, p) => ({ ok: true, path: p, name: path.basename(p), entries: listDir(p) })); + ipcMain.on('app:setDirty', () => {}); + ipcMain.on('win:setTitle', () => {}); + ipcMain.on('save:finished', () => {}); + + const win = new BrowserWindow({ + width: 1300, height: 860, show: false, + webPreferences: { preload: path.join(__dirname, '..', 'src', 'preload.js'), contextIsolation: true, nodeIntegration: false, backgroundThrottling: false } + }); + await win.loadFile(path.join(__dirname, '..', 'src', 'renderer', 'index.html')); + await win.webContents.executeJavaScript(`localStorage.clear()`); + await win.webContents.reload(); + await new Promise((r) => setTimeout(r, 900)); + const js = (code) => win.webContents.executeJavaScript(code); + + /* 1. 初始状态 */ + const init = await js(`({ val: editor.value.length, h1: !!preview.querySelector('h1'), table: !!preview.querySelector('table'), dirty: !document.getElementById('st-dirty').hidden })`); + check('初始渲染:有 h1 与表格', init.h1 && init.table, JSON.stringify(init)); + check('初始不标记未保存', init.dirty === false); + + /* 2. 打开文件(走真实 cmd 通道) */ + win.webContents.send('cmd', 'file-opened', { ok: true, path: tmpFile, name: '测试文档.md', text: sample, eol: '\n' }); + await new Promise((r) => setTimeout(r, 400)); + const opened = await js(`({ v: editor.value === ${JSON.stringify(sample)}, name: document.getElementById('st-file').textContent, dirty: !document.getElementById('st-dirty').hidden })`); + check('打开文件后编辑区内容正确', opened.v); + check('状态栏文件名更新', opened.name === '测试文档.md', opened.name); + check('打开后为已保存状态', opened.dirty === false); + + /* 3. 编辑 → dirty */ + await js(`(() => { + editor.focus(); + editor.setSelectionRange(editor.value.length, editor.value.length); + document.execCommand('insertText', false, '\\n\\n新增一行 **内容**'); + })()`); + await new Promise((r) => setTimeout(r, 300)); + const edited = await js(`({ dirty: !document.getElementById('st-dirty').hidden, hasNew: editor.value.includes('新增一行'), bold: !!preview.querySelector('strong') })`); + check('输入后标记未保存', edited.dirty === true); + check('插入文本成功', edited.hasNew === true); + check('预览同步出现粗体', edited.bold === true); + + /* 4. 保存 */ + await js(`document.getElementById('btn-save').click()`); + await new Promise((r) => setTimeout(r, 600)); + const saved = fs.readFileSync(tmpFile, 'utf8'); + const afterSave = await js(`!document.getElementById('st-dirty').hidden`); + check('保存后磁盘内容已更新', saved.includes('新增一行'), saved.length + ' bytes'); + check('保存后清除未保存标记', afterSave === false); + + /* 5. 撤销 / 重做 */ + const undo = await js(`(() => { + const before = editor.value; + editor.focus(); + const ok1 = document.execCommand('undo'); + const afterUndo = editor.value; + const ok2 = document.execCommand('redo'); + return { ok1, ok2, changed: afterUndo !== before, restored: editor.value === before }; + })()`); + check('撤销生效(内容发生变化)', undo.changed === true, JSON.stringify(undo)); + check('重做恢复内容', undo.restored === true); + + /* 6. 粘贴(读剪贴板 → insertText) */ + const paste = await js(`(async () => { + editor.focus(); + editor.setSelectionRange(0, 0); + const t = await api.readClipboard(); + document.execCommand('insertText', false, t); + return editor.value.startsWith('PASTED'); + })()`); + check('粘贴插入到光标处', paste === true); + + /* 7. 复制全文 */ + const copyAll = await js(`(async () => { + await document.getElementById('btn-copyall').click(); + await new Promise(r => setTimeout(r, 100)); + return document.getElementById('toast').textContent; + })()`); + check('复制全文有提示反馈', /已复制全文/.test(copyAll), copyAll); + + /* 8. 查找 */ + const find = await js(`(async () => { + document.getElementById('btn-find').click(); + const inp = document.getElementById('find-input'); + inp.value = '标题'; + inp.dispatchEvent(new Event('input')); + await new Promise(r => setTimeout(r, 100)); + return { count: document.getElementById('find-count').textContent, sel: editor.selectionStart, selEnd: editor.selectionEnd }; + })()`); + check('查找定位并显示计数', find.selEnd > find.sel, JSON.stringify(find)); + + /* 9. 模式切换 */ + const modes = await js(`(() => { + const ws = document.getElementById('workspace'); + document.querySelector('#mode-seg button[data-mode="read"]').click(); + const a = ws.dataset.mode; + document.querySelector('#mode-seg button[data-mode="split"]').click(); + return { a, b: ws.dataset.mode }; + })()`); + check('模式切换正常', modes.a === 'read' && modes.b === 'split', JSON.stringify(modes)); + + /* 10. 文件夹树 */ + win.webContents.send('cmd', 'dir-opened', { ok: true, path: tmpDir, name: path.basename(tmpDir), entries: listDir(tmpDir) }); + await new Promise((r) => setTimeout(r, 400)); + const tree = await js(`(() => { + const rows = [...document.querySelectorAll('#sb-body .tree-row')]; + return { + visible: !document.getElementById('sidebar').hidden, + names: rows.map(r => r.querySelector('.tree-name').textContent), + dirs: rows.filter(r => r.classList.contains('is-dir')).length, + pngFiltered: !rows.some(r => r.querySelector('.tree-name').textContent.includes('pic.png')) + }; + })()`); + check('拖入文件夹后侧栏显示', tree.visible === true); + check('文件树列出文件与子目录', tree.names.includes('测试文档.md') && tree.names.includes('sub') && tree.dirs === 1, JSON.stringify(tree.names)); + check('非 Markdown 文件被过滤', tree.pngFiltered === true); + + /* 11. 展开子目录 */ + await js(`(() => { + const r = [...document.querySelectorAll('.tree-row.is-dir')].find(x => x.dataset.path.endsWith('sub')); + if (r) r.dispatchEvent(new MouseEvent('dblclick', { bubbles: true, cancelable: true })); + })()`); + await new Promise((r) => setTimeout(r, 500)); + const sub = await js(`(() => { + const rows = [...document.querySelectorAll('#sb-body .tree-row')]; + return { hasC: rows.some(r => r.dataset.path.endsWith('c.md')) }; + })()`); + check('双击子目录可展开', sub.hasC === true, JSON.stringify(sub)); + + /* 12. 单击不切换,双击才打开文件 */ + const beforeSingle = await js(`editor.value`); + const single = await js(`(() => { + const r = [...document.querySelectorAll('#sb-body .tree-row')].find(x => x.dataset.path.endsWith('c.md')); + if (!r) return false; + r.click(); + return document.activeElement === r; + })()`); + await new Promise((r) => setTimeout(r, 350)); + const afterSingle = await js(`editor.value`); + check('单击文件只选中不切换文档', single === true && afterSingle === beforeSingle, JSON.stringify(single)); + + await js(`(() => { + const r = [...document.querySelectorAll('#sb-body .tree-row')].find(x => x.dataset.path.endsWith('c.md')); + if (r) r.dispatchEvent(new MouseEvent('dblclick', { bubbles: true, cancelable: true })); + })()`); + await new Promise((r) => setTimeout(r, 700)); + const byTree = await js(`(() => { + const act = document.querySelector('#sb-body .tree-row.active'); + return { v: editor.value.indexOf('子文件') >= 0, name: document.getElementById('st-file').textContent, active: act ? act.dataset.path : '' }; + })()`); + check('双击文件树打开文件', byTree.v === true, byTree.name); + check('树中高亮当前文件', String(byTree.active).endsWith('c.md'), byTree.active); + + /* 13. 收起侧栏 */ + const collapsed = await js(`(() => { + document.getElementById('sb-close').click(); + const hidden1 = document.getElementById('sidebar').hidden; + document.getElementById('btn-tree').click(); + return { hidden1, hidden2: document.getElementById('sidebar').hidden }; + })()`); + check('侧栏可收起再展开', collapsed.hidden1 === true && collapsed.hidden2 === false, JSON.stringify(collapsed)); + + /* 10. 渲染引擎边界用例 */ + const r = await js(`(() => { + const cases = { + code: MD.render('\\u0060\\u0060\\u0060py\\nprint(1)\\n\\u0060\\u0060\\u0060'), + nested: MD.render('- a\\n - b\\n - c'), + quote: MD.render('> 引用\\n> 第二行'), + hr: MD.render('---'), + xss: MD.render(''), + tableAlign: MD.render('|a|b|\\n|:--|--:|\\n|1|2|'), + task: MD.render('- [x] done'), + escape: MD.render('a & b < c') + }; + return { + code: cases.code.includes('print(1)') && cases.code.includes('
'),
+      nested: (cases.nested.match(/
    /g) || []).length === 3 && cases.nested.includes('
  • c
  • '), + quote: cases.quote.includes('
    '), + hr: cases.hr.includes('
    '), + xss: !cases.xss.includes('