diff --git a/README.md b/README.md index 3ee196e..dc21e7c 100644 --- a/README.md +++ b/README.md @@ -17,9 +17,9 @@ |------|------| | 三栏联动 | 左编辑 / 中 Emoji 纯文本 / 右长文富文本;滚动按比例同步,语法与渲染对应 | | Markdown 实时预览 | 基于 `marked`:中间栏自定义 Emoji Renderer,右侧栏 GFM 富文本 | -| 四套主题 A–D | 经典 / 青简 / 精简 / 聚焦;各预览栏独立切换主题与复制 | -| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现 | -| 一键复制 | 中间栏复制纯文本(表格全角网格);右侧栏复制富文本 HTML | +| 四套 + A2 主题 | 经典 / **A2 商务**(B 式线框 H1 + 📋📌🔹1️⃣ 职场 emoji;表格全角 `-|`)/ 青简 / 精简 / 聚焦 | +| Emoji 装饰排版 | 标题边框、列表符号、任务勾选、引用、分隔线等用 Unicode/Emoji 呈现;纯文本栏禁止 CSS 画框 | +| 一键复制 | 中间栏复制纯文本(所见即粘贴);右侧栏复制富文本 HTML | | 可视化表格 | MarkText 风格插入/编辑表格,插入前可填单元格 | | 本地图片 | 拖拽或右键选图插入;Markdown 使用标准 `images/xxx.png`;预览经本地协议显示 | | 可选 S3 上传 | 设置中开启后,图片可上传到 MinIO/S3(默认端点可配) | @@ -44,6 +44,14 @@ - **图片**:纯文本 `🖼 说明:url`;长文栏正常渲染图片 - **表格**:全角字符网格(Theme B 为 pipe 风格) +### 主题 A2 · 商务(纯文本栏) + +- **H1**:主题 B 同款 `┌─┐│└─┘` 线框 + `📋` +- **H2**:`📌` + 细横线;**H3**:`📎`;列表 `🔹` / `1️⃣…` +- **行内代码**:`『…』`;代码块:`┌─┐` 线框 +- **表格**:全角 `-|` 线框(与微信/雅黑对齐);图片在纯文本栏不输出 +- **任务**:`✅` / `⬜`(无额外列表符) + ## 技术栈 - **桌面**:Electron 44 + electron-builder 26 @@ -121,6 +129,7 @@ npm start ## 已知说明 - 包名 / `productName` 已统一为 **emojitool** / **emojiTool**。 +- Windows 使用自定义标题栏(隐藏原生菜单栏,`Alt` 可临时唤出);青绿品牌图标见 `assets/icon.png`。 - 草稿与设置保存在本机;S3 上传需在设置中自行配置。 - 图片写入 Markdown 为相对路径 `images/...` 或 `https://...`,不含专有协议。 - 三栏滚动按可视进度比例联动,长文档下源码与两侧预览位置大致对应。 diff --git a/assets/icon.ico b/assets/icon.ico deleted file mode 100644 index 98948ea..0000000 Binary files a/assets/icon.ico and /dev/null differ diff --git a/assets/icon.png b/assets/icon.png index 755a6e5..c11270e 100644 Binary files a/assets/icon.png and b/assets/icon.png differ diff --git a/assets/icon.svg b/assets/icon.svg index b064abf..707fc96 100644 --- a/assets/icon.svg +++ b/assets/icon.svg @@ -1,23 +1,11 @@ - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + diff --git a/package.json b/package.json index 4ef16ea..f6dcfb1 100644 --- a/package.json +++ b/package.json @@ -248,8 +248,9 @@ "electronmon": { "patterns": [ "!**/**", - "src/main/**" + "src/main/**/*", + "src/shared/**/*" ], - "logLevel": "quiet" + "logLevel": "info" } } diff --git a/src/__tests__/emojiNestedList.test.ts b/src/__tests__/emojiNestedList.test.ts new file mode 100644 index 0000000..547a67b --- /dev/null +++ b/src/__tests__/emojiNestedList.test.ts @@ -0,0 +1,38 @@ +import { renderEmojiMarkdown } from '../renderer/lib/emojiMarkdown'; + +describe('emojiMarkdown nested lists', () => { + it('keeps nested unordered items on their own indented lines', () => { + const md = `## 无序列表 + +- 第一项要点 +- 第二项要点 + - 嵌套子项 A + - 嵌套子项 B +- 第三项要点 +`; + const html = renderEmojiMarkdown(md, { + appendFooter: false, + themeId: 'A2', + }); + const text = html + .replace(//gi, '\n') + .replace(/<\/div>/gi, '\n') + .replace(/<[^>]+>/g, ''); + + const lines = text + .split('\n') + .map((line) => line.trimEnd()) + .filter((line) => line.trim().length > 0); + + const parentIdx = lines.findIndex((line) => line.includes('第二项要点')); + const childAIdx = lines.findIndex((line) => line.includes('嵌套子项 A')); + const childBIdx = lines.findIndex((line) => line.includes('嵌套子项 B')); + + expect(parentIdx).toBeGreaterThanOrEqual(0); + expect(childAIdx).toBe(parentIdx + 1); + expect(childBIdx).toBe(parentIdx + 2); + expect(lines[childAIdx]).toMatch(/^ │/); + expect(lines[childBIdx]).toMatch(/^ │/); + expect(lines[parentIdx]).toMatch(/^🔹/); + }); +}); diff --git a/src/main/main.ts b/src/main/main.ts index 332b20a..ca90b3e 100644 --- a/src/main/main.ts +++ b/src/main/main.ts @@ -87,6 +87,9 @@ const createWindow = async () => { return path.join(RESOURCES_PATH, ...paths); }; + const isMac = process.platform === 'darwin'; + const chromeBg = '#eef2f3'; + mainWindow = new BrowserWindow({ show: false, width: 1560, @@ -95,6 +98,21 @@ const createWindow = async () => { minHeight: 600, title: 'emojiTool', icon: getAssetPath('icon.png'), + backgroundColor: chromeBg, + autoHideMenuBar: !isMac, + ...(isMac + ? { + titleBarStyle: 'hiddenInset' as const, + trafficLightPosition: { x: 14, y: 12 }, + } + : { + titleBarStyle: 'hidden' as const, + titleBarOverlay: { + color: chromeBg, + symbolColor: '#334155', + height: 44, + }, + }), webPreferences: { preload: app.isPackaged ? path.join(__dirname, 'preload.js') @@ -153,6 +171,9 @@ app.on('window-all-closed', () => { app .whenReady() .then(() => { + if (process.platform === 'win32') { + app.setAppUserModelId('cn.nomadro.emojitool'); + } installLocalImageProtocol(); const migrated = migrateLegacyImages(); if (migrated > 0) { diff --git a/src/renderer/App.module.scss b/src/renderer/App.module.scss index 0a1fa93..02e194d 100644 --- a/src/renderer/App.module.scss +++ b/src/renderer/App.module.scss @@ -7,9 +7,23 @@ :global(body) { background: - radial-gradient(1200px 600px at 10% -10%, rgba(13, 148, 136, 0.12), transparent 55%), - radial-gradient(900px 500px at 100% 0%, rgba(15, 118, 110, 0.08), transparent 50%), - linear-gradient(180deg, #eef2f4 0%, #e7ecef 100%); + linear-gradient( + 135deg, + rgba(13, 148, 136, 0.07) 0%, + transparent 42% + ), + linear-gradient( + 200deg, + rgba(15, 118, 110, 0.05) 0%, + transparent 38% + ), + repeating-linear-gradient( + 0deg, + transparent, + transparent 23px, + rgba(26, 35, 48, 0.018) 24px + ), + linear-gradient(180deg, #f3f6f7 0%, #e9eef0 100%); color: #1a2330; font-family: 'Segoe UI', @@ -30,23 +44,93 @@ color: #0f766e; } +/* Thin shared scrollbars */ +@mixin thin-scroll { + scrollbar-width: thin; + scrollbar-color: rgba(26, 35, 48, 0.22) transparent; + + &::-webkit-scrollbar { + width: 8px; + height: 8px; + } + + &::-webkit-scrollbar-track { + background: transparent; + } + + &::-webkit-scrollbar-thumb { + background: rgba(26, 35, 48, 0.18); + border-radius: 8px; + border: 2px solid transparent; + background-clip: padding-box; + + &:hover { + background: rgba(26, 35, 48, 0.3); + background-clip: padding-box; + border: 2px solid transparent; + } + } +} + .app { --accent: #0d9488; --accent-deep: #0f766e; + --accent-soft: rgba(13, 148, 136, 0.1); --ink: #1a2330; - --muted: #5b6b7c; - --line: rgba(26, 35, 48, 0.1); - --panel: rgba(255, 255, 255, 0.78); + --muted: #64748b; + --line: rgba(26, 35, 48, 0.09); + --surface: rgba(255, 255, 255, 0.82); + --surface-raised: #ffffff; + --panel: var(--surface); --panel-solid: #fbfcfd; --preview-paper: #f4f7f8; + --shadow: 0 4px 20px rgba(26, 35, 48, 0.06); + --radius: 12px; + --radius-sm: 8px; + --titlebar-height: 44px; + --titlebar-controls: 146px; box-sizing: border-box; display: flex; flex-direction: column; height: 100%; min-height: 100vh; - padding: 18px 20px 16px; + padding: 0 18px 14px; + gap: 10px; +} + +.titleBar { + display: flex; + align-items: center; + justify-content: space-between; gap: 12px; + flex-shrink: 0; + flex-wrap: nowrap; + height: var(--titlebar-height); + margin: 0 -18px; + padding: 0 var(--titlebar-controls) 0 14px; + background: #eef2f3; + border-bottom: 1px solid rgba(26, 35, 48, 0.06); + -webkit-app-region: drag; + app-region: drag; + user-select: none; + animation: riseIn 320ms ease both; +} + +.titleBar .actions { + :global(.ant-btn) { + height: 28px; + font-size: 12px; + } + + :global(.ant-btn-text) { + color: var(--muted); + + &:hover:not(:disabled) { + color: var(--accent-deep); + background: var(--accent-soft); + } + } } .header { @@ -56,56 +140,97 @@ gap: 12px; flex-shrink: 0; flex-wrap: nowrap; - animation: riseIn 420ms ease both; } .brand { display: flex; align-items: center; - gap: 12px; + gap: 10px; min-width: 0; flex: 0 1 auto; } .brandText { min-width: 0; + display: flex; + align-items: baseline; + gap: 8px; } .brandMark { - width: 42px; - height: 42px; - border-radius: 12px; + width: 26px; + height: 26px; + border-radius: 7px; display: grid; place-items: center; - color: #ecfeff; - font-size: 18px; + position: relative; background: linear-gradient(145deg, #14b8a6 0%, #0f766e 100%); - box-shadow: 0 10px 24px rgba(13, 148, 136, 0.28); + box-shadow: 0 2px 8px rgba(13, 148, 136, 0.28); + overflow: hidden; + flex-shrink: 0; + + &::before { + content: ''; + width: 9px; + height: 9px; + border: 1.8px solid #ecfeff; + border-radius: 2.5px; + transform: rotate(18deg); + } + + &::after { + content: ''; + position: absolute; + width: 4px; + height: 4px; + border-radius: 1px; + background: #ecfeff; + bottom: 6px; + right: 6px; + } } .title { margin: 0; - font-size: 22px; + font-size: 14px; line-height: 1.2; - letter-spacing: 0.02em; + letter-spacing: -0.01em; font-weight: 700; color: var(--ink); } .subtitle { - margin: 4px 0 0; - font-size: 12px; + margin: 0; + font-size: 11px; color: var(--muted); letter-spacing: 0.01em; + white-space: nowrap; } .actions { display: flex; align-items: center; - gap: 8px; + gap: 6px; flex-wrap: nowrap; flex-shrink: 0; justify-content: flex-end; + -webkit-app-region: no-drag; + app-region: no-drag; +} + +.actionGroup { + display: inline-flex; + align-items: center; + gap: 6px; + padding-left: 8px; + margin-left: 2px; + border-left: 1px solid var(--line); + + &:first-child { + padding-left: 0; + margin-left: 0; + border-left: none; + } } .copyGroup { @@ -119,13 +244,14 @@ .copyArticleBtn { background: #fff !important; - border-color: rgba(13, 148, 136, 0.45) !important; + border-color: rgba(13, 148, 136, 0.4) !important; color: var(--accent-deep) !important; font-weight: 600; &:hover:not(:disabled) { border-color: var(--accent) !important; color: var(--accent) !important; + background: var(--accent-soft) !important; } } @@ -147,7 +273,7 @@ span { font-size: 12px; - color: var(--muted, #5b6b7c); + color: var(--muted, #64748b); line-height: 1.4; white-space: normal; } @@ -157,15 +283,20 @@ display: flex; align-items: center; gap: 8px; - padding: 6px 10px; - border-radius: 999px; - background: rgba(255, 255, 255, 0.65); + padding: 5px 10px; + border-radius: var(--radius-sm); + background: rgba(255, 255, 255, 0.75); border: 1px solid var(--line); color: var(--muted); font-size: 12px; flex-shrink: 0; cursor: pointer; margin: 0; + transition: border-color 160ms ease, background 160ms ease; + + &:hover { + border-color: rgba(13, 148, 136, 0.35); + } } .footerPanel { @@ -173,17 +304,28 @@ display: flex; flex-direction: column; gap: 8px; - padding: 12px 14px; - border-radius: 14px; - background: var(--panel); - border: 1px solid rgba(255, 255, 255, 0.7); - box-shadow: 0 8px 24px rgba(26, 35, 48, 0.06); - animation: riseIn 600ms ease both; - transition: opacity 180ms ease; + padding: 10px 14px; + border-radius: var(--radius); + background: var(--surface); + border: 1px solid rgba(255, 255, 255, 0.8); + box-shadow: var(--shadow); + backdrop-filter: blur(10px); + animation: riseIn 520ms ease both; + transition: + opacity 180ms ease, + padding 180ms ease, + gap 180ms ease; } .footerPanelOff { - opacity: 0.72; + opacity: 0.55; + padding-top: 8px; + padding-bottom: 8px; + gap: 0; + + .footerEditor { + display: none; + } } .footerPanelHead { @@ -210,51 +352,70 @@ monospace !important; font-size: 13px !important; line-height: 1.55 !important; - background: rgba(255, 255, 255, 0.85) !important; + background: rgba(255, 255, 255, 0.9) !important; + border-radius: var(--radius-sm) !important; } .snippetBar { display: flex; align-items: center; - gap: 8px; + gap: 6px; flex-wrap: wrap; flex-shrink: 0; - animation: riseIn 480ms ease both; + padding: 6px 8px; + margin-top: 2px; + border-radius: var(--radius); + background: rgba(255, 255, 255, 0.55); + border: 1px solid rgba(255, 255, 255, 0.75); + box-shadow: var(--shadow); + animation: riseIn 440ms ease both; + -webkit-app-region: no-drag; + app-region: no-drag; } .snippetLabel { - font-size: 12px; - color: var(--muted); + display: inline-flex; + align-items: center; + height: 26px; + padding: 0 8px; margin-right: 2px; + font-size: 11px; + font-weight: 600; + letter-spacing: 0.04em; + color: var(--accent-deep); + background: var(--accent-soft); + border-radius: 6px; + flex-shrink: 0; } .snippetBtn { appearance: none; border: 1px solid var(--line); - background: rgba(255, 255, 255, 0.7); + background: rgba(255, 255, 255, 0.85); color: var(--ink); - border-radius: 999px; - padding: 4px 12px; + border-radius: var(--radius-sm); + height: 26px; + padding: 0 10px; font-size: 12px; + line-height: 1; cursor: pointer; transition: background 160ms ease, border-color 160ms ease, - transform 160ms ease, - opacity 160ms ease; + color 160ms ease; &:hover:not(:disabled) { - background: #fff; - border-color: rgba(13, 148, 136, 0.45); - transform: translateY(-1px); + background: var(--accent-soft); + border-color: rgba(13, 148, 136, 0.35); + color: var(--accent-deep); } &:active:not(:disabled) { - transform: translateY(0); + background: rgba(13, 148, 136, 0.16); } &:disabled { - opacity: 0.45; + opacity: 0.4; cursor: not-allowed; } @@ -265,14 +426,19 @@ } .snippetBarPlain { - opacity: 0.85; + opacity: 0.8; } .saveHint { margin-left: auto; font-size: 12px; color: var(--muted); - transition: color 200ms ease; + transition: color 220ms ease; +} + +.saveHintSaved { + color: var(--accent-deep); + font-weight: 500; } .workspace { @@ -280,8 +446,8 @@ min-height: 0; display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr) minmax(0, 1.12fr); - gap: 12px; - animation: riseIn 560ms ease both; + gap: 10px; + animation: riseIn 500ms ease both; } .pane { @@ -289,28 +455,89 @@ min-height: 0; display: flex; flex-direction: column; - background: var(--panel); + background: var(--surface); backdrop-filter: blur(10px); - border: 1px solid rgba(255, 255, 255, 0.7); - border-radius: 16px; - box-shadow: 0 12px 40px rgba(26, 35, 48, 0.08); + border: 1px solid rgba(255, 255, 255, 0.75); + border-radius: var(--radius); + box-shadow: var(--shadow); overflow: hidden; + position: relative; +} + +.paneAccent { + &::before { + content: ''; + position: absolute; + top: 0; + left: 0; + width: 3px; + height: 100%; + background: var(--accent); + opacity: 0.85; + z-index: 1; + pointer-events: none; + } +} + +.editorPane { + min-width: 0; + background: #f7f8f9; + + &::before { + content: ''; + position: absolute; + top: 0; + left: 0; + width: 3px; + height: 100%; + background: var(--accent); + opacity: 0.9; + z-index: 2; + pointer-events: none; + } } .previewPane { background: var(--panel-solid); + + &::before { + content: ''; + position: absolute; + top: 0; + left: 0; + width: 3px; + height: 100%; + background: #5eead4; + opacity: 0.7; + z-index: 1; + pointer-events: none; + } } .articlePane { background: #fff; + + &::before { + content: ''; + position: absolute; + top: 0; + left: 0; + width: 3px; + height: 100%; + background: #94a3b8; + opacity: 0.55; + z-index: 1; + pointer-events: none; + } } .paneHeader { display: flex; align-items: center; justify-content: space-between; - padding: 10px 12px 10px 16px; + padding: 9px 12px 9px 14px; border-bottom: 1px solid var(--line); + background: rgba(255, 255, 255, 0.55); flex-shrink: 0; gap: 10px; } @@ -319,54 +546,101 @@ .paneHeaderRight { display: flex; align-items: center; - gap: 10px; + gap: 8px; min-width: 0; } .paneHeaderActions { display: flex; align-items: center; - gap: 8px; + gap: 6px; flex-shrink: 0; margin-left: auto; } .paneThemeBtn { - background: rgba(255, 255, 255, 0.88) !important; + background: rgba(255, 255, 255, 0.92) !important; border-color: var(--line) !important; color: var(--ink) !important; font-size: 12px !important; height: 28px !important; padding: 0 10px !important; + border-radius: var(--radius-sm) !important; } .paneTitle { font-size: 13px; font-weight: 600; - letter-spacing: 0.02em; - color: var(--accent-deep); + letter-spacing: 0.01em; + color: var(--ink); flex-shrink: 0; } +.paneBadge { + display: inline-flex; + align-items: center; + height: 20px; + padding: 0 7px; + border-radius: 5px; + font-size: 10px; + font-weight: 600; + letter-spacing: 0.04em; + color: var(--accent-deep); + background: var(--accent-soft); + flex-shrink: 0; +} + +.paneBadgeIm { + color: #0f766e; + background: rgba(45, 212, 191, 0.16); +} + +.paneBadgeArticle { + color: #475569; + background: rgba(148, 163, 184, 0.22); +} + .paneMeta { font-size: 12px; color: var(--muted); white-space: nowrap; + font-variant-numeric: tabular-nums; +} + +.modeSegmented { + :global(.ant-segmented) { + background: rgba(26, 35, 48, 0.06); + padding: 2px; + border-radius: 8px; + } + + :global(.ant-segmented-item) { + border-radius: 6px; + min-height: 24px; + line-height: 22px; + font-size: 12px; + } } .tocToggle { appearance: none; border: 1px solid var(--line); - background: rgba(255, 255, 255, 0.75); + background: rgba(255, 255, 255, 0.85); color: var(--muted); - border-radius: 999px; - padding: 2px 10px; + border-radius: var(--radius-sm); + height: 26px; + padding: 0 9px; font-size: 12px; cursor: pointer; + transition: + color 160ms ease, + border-color 160ms ease, + background 160ms ease; &:hover { color: var(--accent-deep); - border-color: rgba(13, 148, 136, 0.4); + border-color: rgba(13, 148, 136, 0.35); + background: var(--accent-soft); } &:focus-visible { @@ -375,10 +649,6 @@ } } -.editorPane { - min-width: 0; -} - .editorBody { flex: 1; min-height: 0; @@ -387,25 +657,27 @@ } .tocPanel { - width: 168px; + width: 160px; flex-shrink: 0; border-right: 1px solid var(--line); - background: rgba(247, 250, 251, 0.95); + background: rgba(248, 250, 251, 0.98); overflow: auto; - padding: 10px 8px 12px; + padding: 8px 6px 10px; + @include thin-scroll; } .tocTitle { - font-size: 11px; - font-weight: 600; - letter-spacing: 0.04em; + font-size: 10px; + font-weight: 700; + letter-spacing: 0.06em; + text-transform: uppercase; color: var(--muted); - padding: 0 6px 8px; + padding: 2px 8px 8px; } .tocEmpty { margin: 0; - padding: 6px; + padding: 6px 8px; font-size: 12px; color: var(--muted); line-height: 1.5; @@ -426,31 +698,36 @@ cursor: pointer; color: var(--ink); font-size: 12px; - line-height: 1.4; - padding: 6px 8px; - border-radius: 8px; + line-height: 1.35; + padding: 5px 8px; + border-radius: 6px; display: flex; align-items: flex-start; gap: 6px; overflow: hidden; text-overflow: ellipsis; + border-left: 2px solid transparent; + transition: background 150ms ease, border-color 150ms ease; &:hover { - background: rgba(13, 148, 136, 0.1); + background: var(--accent-soft); } } .tocItemActive { - background: rgba(13, 148, 136, 0.14); + background: var(--accent-soft); color: var(--accent-deep); font-weight: 600; + border-left-color: var(--accent); } .tocLevel { flex-shrink: 0; - font-size: 10px; + font-size: 9px; + font-weight: 600; color: var(--muted); - margin-top: 1px; + margin-top: 2px; + opacity: 0.85; } .editorWrap { @@ -463,7 +740,7 @@ } .editorWrapDragOver { - outline: 2px dashed rgba(13, 148, 136, 0.55); + outline: 2px dashed rgba(13, 148, 136, 0.5); outline-offset: -2px; background: rgba(13, 148, 136, 0.04); } @@ -519,6 +796,7 @@ padding: 16px 18px !important; font-size: 14px !important; line-height: 1.7 !important; + @include thin-scroll; &:focus { box-shadow: none !important; @@ -530,13 +808,14 @@ min-height: 0; overflow: auto; background: - linear-gradient(180deg, rgba(244, 247, 248, 0.95), rgba(244, 247, 248, 1)), + linear-gradient(180deg, rgba(244, 247, 248, 0.98), #f2f6f7), repeating-linear-gradient( 0deg, transparent, transparent 27px, - rgba(13, 148, 136, 0.04) 28px + rgba(13, 148, 136, 0.03) 28px ); + @include thin-scroll; } .previewHtml { @@ -573,46 +852,146 @@ line-height: 1.45; } + /* 纯文本预览:表格/代码块禁止上色与装饰边框,所见即复制结果 */ :global(.emoji-table pre) { margin: 0; - padding: 10px 12px; + padding: 0; white-space: pre; overflow-x: auto; - /* Fullwidth grid does not need dual-width mono; any CJK font works */ font-family: + 'Cascadia Code', + 'JetBrains Mono', + Consolas, 'Microsoft YaHei', 'PingFang SC', - 'Noto Sans SC', - 'Segoe UI', - sans-serif; + monospace; font-size: 14px; line-height: 1.55; letter-spacing: 0; font-variant-ligatures: none; - background: rgba(26, 35, 48, 0.04); - border: 1px dashed rgba(26, 35, 48, 0.18); - border-radius: 8px; + background: transparent; + border: none; + border-radius: 0; + color: inherit; } :global(.emoji-code) { margin: 8px 0 12px; - padding: 10px 12px; - border: 1px solid rgba(26, 35, 48, 0.16); - border-radius: 8px; - background: rgba(26, 35, 48, 0.04); + padding: 0; + border: none; + border-radius: 0; + background: transparent; font-size: 13px; } :global(.emoji-code pre) { - margin: 8px 0 0; + margin: 0; + padding: 0; white-space: pre-wrap; word-break: break-word; font-family: 'Cascadia Code', 'JetBrains Mono', Consolas, + 'Microsoft YaHei', monospace; line-height: 1.55; + background: transparent; + border: none; + color: inherit; + } + + /* + * A2 · 极致:只优化字符排版(框线/层级/对齐), + * 预览禁止颜色与 CSS 装饰——复制到微信/小红书/抖音/X 等仍是纯字符。 + */ + &[data-theme='A2'] { + padding: 20px 22px 32px; + font-size: 15px; + line-height: 1.85; + letter-spacing: 0; + color: var(--ink); + /* 与微信一致:CJK 优先,全角框线才和汉字/emoji 同宽 */ + font-family: + 'Microsoft YaHei', + 'PingFang SC', + 'Noto Sans SC', + 'Cascadia Code', + Consolas, + monospace; + font-variant-ligatures: none; + + > :global(div) { + margin: 0 0 0.75em; + } + + :global(.emoji-h1) { + margin: 0.1em 0 1em; + line-height: 1.35; + white-space: pre; + font-weight: 400; + font-variant-ligatures: none; + letter-spacing: 0; + } + + :global(.emoji-h2) { + margin: 1.1em 0 0.55em; + line-height: 1.5; + white-space: pre-wrap; + font-weight: 400; + } + + :global(.emoji-h2-rule) { + display: inline; + opacity: 1; + color: inherit; + } + + :global(.emoji-h3) { + margin: 0.9em 0 0.4em; + font-weight: 400; + } + + :global(.emoji-h4) { + margin: 0.7em 0 0.3em; + font-weight: 400; + } + + :global(.emoji-hr) { + margin: 1.1em 0; + text-align: left; + letter-spacing: 0.06em; + color: inherit; + } + + :global(.emoji-quote) { + margin: 0.25em 0; + color: inherit; + } + + :global(.emoji-image) { + margin: 0.55em 0; + white-space: pre-wrap; + color: inherit; + } + + :global(.emoji-table pre), + :global(.emoji-code pre) { + /* 必须跟预览区同一套 CJK 字体:Cascadia 下 ─ 半角、汉字全角,右侧框线必断 */ + font-family: inherit; + font-size: 14px; + } + + :global(.emoji-code-a2 pre) { + white-space: pre; + overflow-x: auto; + font-size: 14px; + } + + :global(.emoji-footer) { + margin-top: 1.2em; + color: inherit; + } } } @@ -621,14 +1000,23 @@ min-height: 0; overflow: auto; background: - radial-gradient(ellipse 80% 40% at 50% 0%, rgba(13, 148, 136, 0.05), transparent 70%), - linear-gradient(180deg, #fcfdfd 0%, #f7fafb 100%); + radial-gradient( + ellipse 80% 36% at 50% 0%, + rgba(13, 148, 136, 0.04), + transparent 70% + ), + linear-gradient(180deg, #ffffff 0%, #f8fafb 100%); transition: background 220ms ease; + @include thin-scroll; } .articlePane[data-theme='B'] .articleScroll { background: - radial-gradient(ellipse 70% 36% at 50% 0%, rgba(14, 116, 144, 0.06), transparent 70%), + radial-gradient( + ellipse 70% 36% at 50% 0%, + rgba(14, 116, 144, 0.05), + transparent 70% + ), linear-gradient(180deg, #fbfdfe 0%, #f3f8fa 100%); } @@ -638,7 +1026,11 @@ .articlePane[data-theme='D'] .articleScroll { background: - radial-gradient(ellipse 80% 42% at 50% 0%, rgba(180, 83, 9, 0.06), transparent 68%), + radial-gradient( + ellipse 80% 42% at 50% 0%, + rgba(180, 83, 9, 0.05), + transparent 68% + ), linear-gradient(180deg, #fffdf9 0%, #faf6f0 100%); } @@ -920,7 +1312,6 @@ line-height: 1.7; } - /* B · 青简:书签感左侧强调 */ &[data-theme='B'] { :global(h1) { border-bottom: none; @@ -948,7 +1339,6 @@ } } - /* C · 精简:少装饰 */ &[data-theme='C'] { :global(h1), :global(h2) { @@ -1000,7 +1390,6 @@ } } - /* D · 聚焦:双线标题 + 要点感 */ &[data-theme='D'] { :global(h1) { border-bottom-width: 3px; @@ -1057,9 +1446,88 @@ animation: fadeIn 280ms ease; } +.emptyIcon { + width: 48px; + height: 48px; + margin-bottom: 14px; + border-radius: 12px; + position: relative; + background: var(--accent-soft); + border: 1px solid rgba(13, 148, 136, 0.18); + + &::before { + content: ''; + position: absolute; + inset: 14px 12px; + border: 2px solid var(--accent); + border-radius: 4px; + opacity: 0.7; + } + + &::after { + content: ''; + position: absolute; + width: 16px; + height: 2px; + background: var(--accent); + top: 22px; + left: 16px; + opacity: 0.55; + box-shadow: + 0 5px 0 var(--accent), + 0 10px 0 var(--accent); + } +} + +.emptyIconIm { + background: rgba(45, 212, 191, 0.12); + border-color: rgba(45, 212, 191, 0.28); + + &::before { + border-color: #0d9488; + border-radius: 50%; + inset: 12px; + } + + &::after { + width: 10px; + height: 10px; + border-radius: 50%; + top: 19px; + left: 19px; + box-shadow: none; + background: #0d9488; + opacity: 0.65; + } +} + +.emptyIconArticle { + background: rgba(148, 163, 184, 0.16); + border-color: rgba(148, 163, 184, 0.35); + + &::before { + border-color: #64748b; + border-left: none; + border-top: none; + border-radius: 0 0 4px 0; + inset: 14px 14px 14px 18px; + } + + &::after { + width: 12px; + height: 16px; + top: 14px; + left: 14px; + border-radius: 2px 2px 0 0; + background: #94a3b8; + opacity: 0.55; + box-shadow: none; + } +} + .emptyTitle { margin: 0 0 8px; - font-size: 18px; + font-size: 16px; font-weight: 600; color: var(--ink); } @@ -1068,13 +1536,13 @@ margin: 0; font-size: 13px; line-height: 1.7; - max-width: 280px; + max-width: 260px; } @keyframes riseIn { from { opacity: 0; - transform: translateY(8px); + transform: translateY(6px); } to { opacity: 1; @@ -1112,13 +1580,27 @@ max-height: none; } - .header { - flex-direction: column; - align-items: flex-start; + .titleBar { + height: auto; + min-height: var(--titlebar-height); + flex-wrap: wrap; + padding-bottom: 6px; + } + + .brandText { + flex-wrap: wrap; } .actions { width: 100%; justify-content: flex-start; + padding-left: 36px; } } + +/* macOS traffic lights sit in the title bar */ +:global(body.platform-darwin) .titleBar, +.app[data-platform='darwin'] .titleBar { + padding-left: 78px; + padding-right: 14px; +} diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 97653a8..6aa5c20 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -19,6 +19,7 @@ import type { MenuProps } from 'antd'; import { DEFAULT_FOOTER_TEXT, THEME_LIST, + ARTICLE_THEME_LIST, renderEmojiMarkdown, type ThemeId, } from './lib/emojiMarkdown'; @@ -91,7 +92,9 @@ function App() { [themeId], ); const articleTheme = useMemo( - () => THEME_LIST.find((t) => t.id === articleThemeId) ?? THEME_LIST[0], + () => + ARTICLE_THEME_LIST.find((t) => t.id === articleThemeId) ?? + ARTICLE_THEME_LIST[0], [articleThemeId], ); @@ -237,8 +240,9 @@ function App() { }, []); const applyArticleTheme = useCallback((next: ThemeId) => { + if (next === 'A2') return; setArticleThemeId(next); - const theme = THEME_LIST.find((item) => item.id === next); + const theme = ARTICLE_THEME_LIST.find((item) => item.id === next); message.success(`长文主题:${theme?.name ?? next}`); }, []); @@ -343,8 +347,11 @@ function App() { }, [copyPreview, copyArticleHtml, persistNow, clearContent]); const makeThemeItems = useCallback( - (onSelect: (id: ThemeId) => void): MenuProps['items'] => - THEME_LIST.map((theme) => ({ + ( + themes: typeof THEME_LIST, + onSelect: (id: ThemeId) => void, + ): MenuProps['items'] => + themes.map((theme) => ({ key: theme.id, label: (
@@ -357,8 +364,11 @@ function App() { [], ); - const plainThemeItems = makeThemeItems(applyPlainTheme); - const articleThemeItems = makeThemeItems(applyArticleTheme); + const plainThemeItems = makeThemeItems(THEME_LIST, applyPlainTheme); + const articleThemeItems = makeThemeItems( + ARTICLE_THEME_LIST, + applyArticleTheme, + ); const templateItems: MenuProps['items'] = TEMPLATES.map((item) => ({ key: item.id, @@ -378,46 +388,71 @@ function App() { token: { colorPrimary: '#0d9488', colorInfo: '#0d9488', - borderRadius: 10, + borderRadius: 8, + colorText: '#1a2330', + colorTextSecondary: '#64748b', + colorBorder: 'rgba(26, 35, 48, 0.12)', fontFamily: '"Segoe UI", "PingFang SC", "Noto Sans SC", "Microsoft YaHei", sans-serif', + controlHeight: 32, + controlHeightSM: 28, }, }} > -
-
+
+
-
- ✦ -
+

emojiTool

-

- 编辑 · 纯文本 · 长文 · mdemoji.com -

+

编辑 · 纯文本 · 长文

- - - +
+ + + +
- - - +
+ + + + +
- - - +
+ +
@@ -438,7 +473,12 @@ function App() { {snippet.label} ))} - + {hintText}
@@ -455,9 +495,17 @@ function App() { charCount={charCount} /> -
+
- 纯文本预览 +
+ 纯文本预览 + + IM + +
) : (
+

纯文本效果

- 面向微信公众号、评论区、聊天框等纯文本场景,复制后可直接粘贴。 + 面向微信、评论区、聊天框;复制后可直接粘贴。

)} @@ -509,7 +562,14 @@ function App() { data-theme={articleThemeId} >
- 长文渲染 +
+ 长文渲染 + + 长文 + +
) : (
+

长文预览

- 本栏可单独切换主题;点「复制」粘贴到富文本编辑器。 + 可单独切换主题;复制后粘贴到富文本编辑器。

)} diff --git a/src/renderer/components/EditorPane.tsx b/src/renderer/components/EditorPane.tsx index 330baac..3b91b87 100644 --- a/src/renderer/components/EditorPane.tsx +++ b/src/renderer/components/EditorPane.tsx @@ -475,6 +475,7 @@ const EditorPane = forwardRef(function EditorPane( {isMarkdown ? 'Markdown' : '普通编辑'} + 源码
- - onModeChange(value === 'plain' ? 'plain' : 'markdown') - } - options={[ - { label: 'MD', value: 'markdown' }, - { label: '普通', value: 'plain' }, - ]} - /> +
+ + onModeChange(value === 'plain' ? 'plain' : 'markdown') + } + options={[ + { label: 'MD', value: 'markdown' }, + { label: '普通', value: 'plain' }, + ]} + /> +
{charCount} 字
diff --git a/src/renderer/components/SettingsModal.module.scss b/src/renderer/components/SettingsModal.module.scss index 88e3350..651416c 100644 --- a/src/renderer/components/SettingsModal.module.scss +++ b/src/renderer/components/SettingsModal.module.scss @@ -1,7 +1,38 @@ .modal { + :global(.ant-modal-content) { + border-radius: 12px; + overflow: hidden; + box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12); + } + + :global(.ant-modal-header) { + padding: 16px 20px 12px; + border-bottom: 1px solid rgba(26, 35, 48, 0.08); + } + + :global(.ant-modal-title) { + font-weight: 600; + letter-spacing: -0.01em; + color: #1a2330; + } + :global(.ant-modal-body) { max-height: min(70vh, 560px); overflow: auto; + padding: 16px 20px 8px; + } + + :global(.ant-modal-footer) { + padding: 12px 20px 16px; + border-top: 1px solid rgba(26, 35, 48, 0.06); + } + + :global(.ant-tabs-nav) { + margin-bottom: 12px; + } + + :global(.ant-form-item) { + margin-bottom: 14px; } } @@ -16,5 +47,9 @@ margin: 8px 0 0; font-size: 12px; line-height: 1.6; - color: #5b6b7c; + color: #64748b; + padding: 8px 10px; + border-radius: 8px; + background: rgba(13, 148, 136, 0.06); + border: 1px solid rgba(13, 148, 136, 0.12); } diff --git a/src/renderer/components/TableModals.module.scss b/src/renderer/components/TableModals.module.scss index 815a782..22fa872 100644 --- a/src/renderer/components/TableModals.module.scss +++ b/src/renderer/components/TableModals.module.scss @@ -1,18 +1,36 @@ .insertModal { + :global(.ant-modal-content) { + border-radius: 12px; + overflow: hidden; + box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12); + } + + :global(.ant-modal-header) { + padding: 16px 20px 10px; + border-bottom: 1px solid rgba(26, 35, 48, 0.08); + } + :global(.ant-modal-title) { text-align: center; font-weight: 600; + letter-spacing: -0.01em; + color: #1a2330; } :global(.ant-modal-body) { - padding-top: 8px; + padding: 12px 20px 8px; + } + + :global(.ant-modal-footer) { + padding: 12px 20px 16px; + border-top: 1px solid rgba(26, 35, 48, 0.06); } } .insertBody { display: flex; flex-direction: column; - gap: 16px; + gap: 14px; padding: 4px 0 2px; } @@ -39,34 +57,55 @@ display: grid; gap: 6px; padding: 14px; - border-radius: 12px; - background: - linear-gradient(180deg, #f7fafb 0%, #eef3f5 100%); + border-radius: 10px; + background: linear-gradient(180deg, #f7fafb 0%, #eef3f5 100%); border: 1px solid rgba(26, 35, 48, 0.08); min-height: 120px; max-height: 220px; overflow: auto; + scrollbar-width: thin; } .gridCell { aspect-ratio: 1.6 / 1; min-height: 22px; border-radius: 4px; - border: 1px solid rgba(15, 118, 110, 0.28); - background: rgba(255, 255, 255, 0.85); - box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5); + border: 1px solid rgba(13, 148, 136, 0.28); + background: rgba(255, 255, 255, 0.9); + transition: border-color 140ms ease, background 140ms ease; } .hint { margin: 0; text-align: center; font-size: 12px; - color: #5b6b7c; + color: #64748b; } .editModal { + :global(.ant-modal-content) { + border-radius: 12px; + overflow: hidden; + box-shadow: 0 8px 32px rgba(26, 35, 48, 0.12); + } + + :global(.ant-modal-header) { + padding: 16px 20px 10px; + border-bottom: 1px solid rgba(26, 35, 48, 0.08); + } + + :global(.ant-modal-title) { + font-weight: 600; + color: #1a2330; + } + :global(.ant-modal-body) { - padding-top: 8px; + padding: 12px 20px 8px; + } + + :global(.ant-modal-footer) { + padding: 12px 20px 16px; + border-top: 1px solid rgba(26, 35, 48, 0.06); } } @@ -87,15 +126,16 @@ .toolLabel { font-size: 12px; - color: #5b6b7c; + color: #64748b; } .editScroll { overflow: auto; max-height: min(52vh, 420px); - border: 1px solid rgba(26, 35, 48, 0.1); - border-radius: 12px; + border: 1px solid rgba(26, 35, 48, 0.09); + border-radius: 10px; background: #fbfcfd; + scrollbar-width: thin; } .editTable { @@ -137,6 +177,7 @@ display: block; width: 100%; text-align: left; + transition: color 140ms ease; &:hover { color: #0d9488; @@ -170,16 +211,21 @@ border-radius: 6px; border: 1px solid rgba(26, 35, 48, 0.12); background: #fff; - color: #5b6b7c; + color: #64748b; font-size: 13px; line-height: 1; cursor: pointer; display: inline-grid; place-items: center; + transition: + color 140ms ease, + border-color 140ms ease, + background 140ms ease; &:hover:not(:disabled) { color: #0f766e; border-color: rgba(13, 148, 136, 0.4); + background: rgba(13, 148, 136, 0.06); } &:disabled { diff --git a/src/renderer/lib/emojiMarkdown.ts b/src/renderer/lib/emojiMarkdown.ts index c2c0bd6..4fa6919 100644 --- a/src/renderer/lib/emojiMarkdown.ts +++ b/src/renderer/lib/emojiMarkdown.ts @@ -15,11 +15,20 @@ import { export type { ThemeId } from './themes'; export { THEME_LIST, + ARTICLE_THEME_LIST, DEFAULT_THEME_ID, resolveTheme, isThemeId, + isArticleThemeId, } from './themes'; +/** Structural markers — Marked renders inner lists before outer list() runs */ +const LI_OPEN = '{{LI}}'; +const LI_CLOSE = '{{/LI}}'; +const LIST_OL_OPEN = '{{LIST:1}}'; +const LIST_UL_OPEN = '{{LIST:0}}'; +const LIST_CLOSE = '{{/LIST}}'; + function cleanUrl(href: string): string | null { try { return encodeURI(href).replace(/%25/g, '%'); @@ -30,14 +39,166 @@ function cleanUrl(href: string): string | null { function isTaskItem(theme: EmojiTheme, value: string): boolean { return ( - value.includes(`${theme.listSymbol}${theme.taskUnchecked}`) || - value.includes(`${theme.listSymbol}${theme.taskChecked}`) + value.includes(theme.taskUnchecked) || value.includes(theme.taskChecked) ); } +function findMatchingClose( + source: string, + from: number, + open: string, + close: string, +): number { + let depth = 1; + let i = from; + while (i < source.length) { + if (source.startsWith(open, i)) { + depth += 1; + i += open.length; + continue; + } + if (source.startsWith(close, i)) { + depth -= 1; + if (depth === 0) return i; + i += close.length; + continue; + } + i += 1; + } + return -1; +} + +function expandEmojiLists(input: string, theme: EmojiTheme): string { + const expandFrom = (source: string, depth: number): string => { + let out = ''; + let i = 0; + while (i < source.length) { + const ul = source.indexOf(LIST_UL_OPEN, i); + const ol = source.indexOf(LIST_OL_OPEN, i); + let start = -1; + let ordered = false; + let openLen = 0; + + if (ul === -1 && ol === -1) { + out += source.slice(i); + break; + } + if (ul === -1 || (ol !== -1 && ol < ul)) { + start = ol; + ordered = true; + openLen = LIST_OL_OPEN.length; + } else { + start = ul; + ordered = false; + openLen = LIST_UL_OPEN.length; + } + + out += source.slice(i, start); + const contentStart = start + openLen; + const end = findListClose(source, contentStart); + if (end < 0) { + out += source.slice(start); + break; + } + const content = source.slice(contentStart, end); + out += renderListContent(content, ordered, depth, theme, expandFrom); + i = end + LIST_CLOSE.length; + } + return out; + }; + + return expandFrom(input, 0); +} + +/** Match {{/LIST}} with nesting of either {{LIST:0}} or {{LIST:1}} */ +function findListClose(source: string, from: number): number { + let depth = 1; + let i = from; + while (i < source.length) { + if (source.startsWith(LIST_UL_OPEN, i) || source.startsWith(LIST_OL_OPEN, i)) { + depth += 1; + i += LIST_UL_OPEN.length; + continue; + } + if (source.startsWith(LIST_CLOSE, i)) { + depth -= 1; + if (depth === 0) return i; + i += LIST_CLOSE.length; + continue; + } + i += 1; + } + return -1; +} + +function extractListItems(content: string): string[] { + const items: string[] = []; + let i = 0; + while (i < content.length) { + const start = content.indexOf(LI_OPEN, i); + if (start === -1) break; + const contentStart = start + LI_OPEN.length; + const end = findMatchingClose(content, contentStart, LI_OPEN, LI_CLOSE); + if (end < 0) break; + items.push(content.slice(contentStart, end)); + i = end + LI_CLOSE.length; + } + return items; +} + +function renderListContent( + content: string, + ordered: boolean, + depth: number, + theme: EmojiTheme, + expandFrom: (source: string, depth: number) => string, +): string { + const items = extractListItems(content); + let orderedIndex = 0; + const indent = '\u3000'.repeat(depth); + const { listSymbol, nestPrefix } = theme; + + return items + .map((raw) => { + // Expand any nested lists inside this item first (correct depth) + const expanded = expandFrom(raw, depth + 1); + + // Nested list lines always use white-space:pre; plain
is paragraph wrap + const nestedBlocks: string[] = []; + const main = expanded + .replace(/
[\s\S]*?<\/div>/g, (block) => { + nestedBlocks.push(block); + return ''; + }) + .replace(/<\/?div>/gi, '') + .replace(//gi, '') + .replaceAll(listSymbol, '') + .trim(); + + const task = isTaskItem(theme, main); + let line: string; + + if (depth > 0) { + line = `
${indent}${nestPrefix} ${main}
`; + } else if (ordered) { + const num = + theme.orderedNumbers[orderedIndex] ?? `${orderedIndex + 1}.`; + orderedIndex += 1; + line = `
${num} ${main}
`; + } else if (task) { + // 任务列表只要 ✅/⬜,不要再叠一层列表符号 + line = `
${main}
`; + } else { + line = `
${listSymbol} ${main}
`; + } + + return `${line}${nestedBlocks.join('')}`; + }) + .join(''); +} + function createRenderer(theme: EmojiTheme): Renderer { const renderer = new Renderer(); - const { listSymbol } = theme; renderer.image = (href, _title, text) => { const cleanHref = cleanUrl(href || ''); @@ -47,39 +208,10 @@ function createRenderer(theme: EmojiTheme): Renderer { return theme.image(cleanHref, text || ''); }; - renderer.list = (body, ordered) => { - const type = ordered ? 'ol' : 'ul'; - const texts = body - .replace(/<\/?div>/g, '') - .split(//i) - .map((item) => item.trim()) - .filter((item) => item.length > 0); + renderer.listitem = (text) => `${LI_OPEN}${text}${LI_CLOSE}`; - let orderedIndex = 0; - - return texts - .map((value) => { - const task = isTaskItem(theme, value); - - if (value.includes(listSymbol)) { - let prefix: string; - if (type === 'ol') { - prefix = `${theme.orderedNumbers[orderedIndex] ?? `${orderedIndex + 1}.`} `; - orderedIndex += 1; - } else if (task) { - prefix = ''; - } else { - prefix = listSymbol; - } - return `
${prefix}${value.replace(listSymbol, '')}
`; - } - - return `
         ${theme.nestPrefix} ${value}
`; - }) - .join(''); - }; - - renderer.listitem = (text) => `${listSymbol}${text}
`; + renderer.list = (body, ordered) => + `${ordered ? LIST_OL_OPEN : LIST_UL_OPEN}${body}${LIST_CLOSE}`; renderer.checkbox = (checked) => checked ? theme.taskChecked : theme.taskUnchecked; @@ -120,7 +252,6 @@ function createRenderer(theme: EmojiTheme): Renderer { return lines.map((line) => theme.blockquote(line)).join(''); }; - // Plain-text tables for WeChat / IM paste (HTML borders do not survive copy) renderer.table = (header, body) => { const rows = parseMarkedTableRows(header, body); return formatPlainTable(rows, theme.tableLabel, theme.tableStyle); @@ -153,7 +284,7 @@ function getMarked(themeId: ThemeId): Marked { }); } -export const DEFAULT_FOOTER_TEXT = `➖➖➖➖➖ +export const DEFAULT_FOOTER_TEXT = `············ ©️ 本文使用🔗『mdemoji.com』 编辑`; function escapeHtml(text: string): string { @@ -180,7 +311,9 @@ export function renderEmojiMarkdown( const appendFooter = options?.appendFooter !== false; const footerText = options?.footerText ?? DEFAULT_FOOTER_TEXT; const themeId = options?.themeId ?? DEFAULT_THEME_ID; - const bodyHtml = getMarked(themeId).parse(source) as string; + const theme = resolveTheme(themeId); + const rawHtml = getMarked(themeId).parse(source) as string; + const bodyHtml = expandEmojiLists(rawHtml, theme); if (appendFooter && footerText.trim()) { return bodyHtml + formatFooterHtml(footerText); diff --git a/src/renderer/lib/plainTable.ts b/src/renderer/lib/plainTable.ts index e0e76ba..9469fc1 100644 --- a/src/renderer/lib/plainTable.ts +++ b/src/renderer/lib/plainTable.ts @@ -90,7 +90,7 @@ function toFullwidthCompat(text: string): string { return out; } -export type PlainTableStyle = 'box' | 'pipe' | 'dots'; +export type PlainTableStyle = 'box' | 'pipe' | 'dots' | 'frame'; function colWidths(matrix: string[][]): number[] { const colCount = matrix[0]?.length ?? 0; @@ -130,6 +130,31 @@ function buildFullwidthBox(matrix: string[][], widths: number[]): string[] { return lines; } +/** + * A2 线框表:只用全角 -|(与代码块同一套)。 + * 顶/底/表头分隔线纯 -(不用 | 接头,否则竖笔画会冒出横线)。 + */ +function buildFrameBox(matrix: string[][], widths: number[]): string[] { + const total = + widths.reduce((a, b) => a + b, 0) + (widths.length + 1) * 2; + const rule = FW_H.repeat(Math.max(1, total / 2)); + + const renderRow = (row: string[]) => + FW_V + + row.map((cell, col) => padEndFullwidth(cell, widths[col])).join(FW_V) + + FW_V; + + const lines: string[] = [rule]; + matrix.forEach((row, index) => { + lines.push(renderRow(row)); + if (index === 0 && matrix.length > 1) { + lines.push(rule); + } + }); + lines.push(rule); + return lines; +} + /** Pipe style: fullwidth cells, divider only under header (no outer top/bottom box) */ function buildPipeRows(matrix: string[][], widths: number[]): string[] { const renderRow = (row: string[]) => @@ -197,6 +222,8 @@ export function formatPlainTable( body = buildDotsRows(matrix, widths); } else if (style === 'pipe') { body = buildPipeRows(matrix, widths); + } else if (style === 'frame') { + body = buildFrameBox(matrix, widths); } else { body = buildFullwidthBox(matrix, widths); } diff --git a/src/renderer/lib/storage.ts b/src/renderer/lib/storage.ts index 15348f3..5df6692 100644 --- a/src/renderer/lib/storage.ts +++ b/src/renderer/lib/storage.ts @@ -1,6 +1,7 @@ import { DEFAULT_FOOTER_TEXT, DEFAULT_THEME_ID, + isArticleThemeId, isThemeId, type ThemeId, } from './emojiMarkdown'; @@ -42,9 +43,12 @@ export function loadDraft(): DraftState { const themeId: ThemeId = isThemeId(parsed.themeId) ? parsed.themeId : DEFAULT_THEME_ID; - const articleThemeId: ThemeId = isThemeId(parsed.articleThemeId) - ? parsed.articleThemeId - : themeId; + const rawArticle = parsed.articleThemeId; + const articleThemeId: ThemeId = isArticleThemeId(rawArticle) + ? rawArticle + : isArticleThemeId(themeId) + ? themeId + : DEFAULT_THEME_ID; const content = typeof parsed.content === 'string' ? parsed.content diff --git a/src/renderer/lib/templates.ts b/src/renderer/lib/templates.ts index 5bfade8..c264213 100644 --- a/src/renderer/lib/templates.ts +++ b/src/renderer/lib/templates.ts @@ -77,11 +77,6 @@ function hello(name) { } \`\`\` -\`\`\` -纯文本代码块 -第二行 -\`\`\` - ## 表格 | 语法 | 效果 | diff --git a/src/renderer/lib/themes.ts b/src/renderer/lib/themes.ts index d1d5e3c..abc5e01 100644 --- a/src/renderer/lib/themes.ts +++ b/src/renderer/lib/themes.ts @@ -1,6 +1,8 @@ -export type ThemeId = 'A' | 'B' | 'C' | 'D'; +import { displayWidth } from './plainTable'; -export type PlainTableStyle = 'box' | 'pipe' | 'dots'; +export type ThemeId = 'A' | 'A2' | 'B' | 'C' | 'D'; + +export type PlainTableStyle = 'box' | 'pipe' | 'dots' | 'frame'; export type EmojiTheme = { id: ThemeId; @@ -30,6 +32,19 @@ export type EmojiTheme = { fallbackOrdered: string; }; +function escapeCode(code: string): string { + return code + .replace(/&/g, '&') + .replace(//g, '>'); +} + +function repeatToDisplayWidth(ch: string, target: number): string { + const unit = Math.max(1, displayWidth(ch)); + const count = Math.max(1, Math.ceil(target / unit)); + return ch.repeat(count); +} + function frameTitleA(text: string): string { const padding = 2; const edgeChar = '─'; @@ -38,9 +53,40 @@ function frameTitleA(text: string): string { return `
╭${edgeLength}╮
📢 ${text}
╰${edgeLength}╯
`; } +/** + * 主题 B 一级标题书签框(保持原样) + */ function frameTitleB(text: string): string { - const line = '─'.repeat(Math.max(text.length + 4, 10)); - return `
┌${line}┐
│ 📌 ${text}
└${line}┘
`; + const body = `📌 ${text}`; + const width = Math.max(displayWidth(body), 10); + const line = '─'.repeat(width); + return `
┌${line}┐
│ ${body}
└${line}┘
`; +} + +/** + * A2 一级标题:沿用主题 B 线框 ┌─┐│└─┘,emoji 用 📋。 + */ +function frameTitleA2(text: string): string { + const body = `📋 ${text}`; + const width = Math.max(displayWidth(body), 10); + const line = '─'.repeat(width); + return `
┌${line}┐
│ ${body}
└${line}┘
`; +} + +/** A2 线条:等长、无 emoji,细线 / 虚线 */ +const A2_LINE_WIDTH = 16; + +function a2Line(style: 'title' | 'section'): string { + if (style === 'title') { + return repeatToDisplayWidth('─', A2_LINE_WIDTH); + } + return Array.from({ length: Math.ceil(A2_LINE_WIDTH / 2) }, () => '·').join( + ' ', + ); +} + +function businessHr(): string { + return `
${a2Line('section')}
\n`; } function frameTitleC(text: string): string { @@ -52,18 +98,28 @@ function frameTitleD(text: string): string { return `
╔${line}╗
║ 🎯 ${text}
╚${line}╝
`; } -function escapeCode(code: string): string { - return code - .replace(/&/g, '&') - .replace(//g, '>'); -} - function plainCodeBlock(title: string, code: string): string { const line = '────────'; return `
${title}\n${line}\n${escapeCode(code.replace(/\n$/, ''))}\n${line}
`; } +function plainCodeBlockA2(title: string, code: string): string { + const body = escapeCode(code.replace(/\n$/, '')); + const lines = body.split('\n'); + const head = `💻 ${title}`; + const maxW = Math.max( + displayWidth(head), + ...lines.map((line) => displayWidth(line)), + 12, + ); + const edge = repeatToDisplayWidth('─', maxW + 2); + return `
┌${edge}┐
+│ ${head}
+├${edge}┤
+${lines.map((line) => `│ ${line}`).join('\n')}
+└${edge}┘
`; +} + /** A · 经典 */ export const THEME_A: EmojiTheme = { id: 'A', @@ -90,7 +146,7 @@ export const THEME_A: EmojiTheme = { heading2: (text) => `
📝 ${text}
\n`, heading3: (text) => `
📎 ${text}
\n`, heading4: (text) => `
▪️ ${text}
\n`, - hr: '➖➖➖➖➖\n', + hr: '· · · · · · · ·\n', codespan: (text) => `『${text}』`, codeblock: (code, language) => plainCodeBlock(`📄 代码${language ? ` · ${language}` : ''}`, code), @@ -108,6 +164,57 @@ export const THEME_A: EmojiTheme = { fallbackOrdered: '🔹', }; +/** + * A2 · 商务正式(带色) + * 职场向 emoji 自带色彩:📋📌🔹✅1️⃣… + 双线框线。 + * 不用花朵/闪粉/颜文字;适合群通报、对外摘要、评论区正式发言。 + */ +export const THEME_A2: EmojiTheme = { + id: 'A2', + name: '主题 A2 · 商务', + shortName: 'A2 商务', + description: + '正式商务 + 职场 emoji 色彩:B 式线框、钉选/清单符号、彩色序号', + listSymbol: '🔹', + orderedNumbers: [ + '1️⃣', + '2️⃣', + '3️⃣', + '4️⃣', + '5️⃣', + '6️⃣', + '7️⃣', + '8️⃣', + '9️⃣', + '🔟', + ], + nestPrefix: '│', + taskChecked: '✅', + taskUnchecked: '⬜', + heading1: frameTitleA2, + heading2: (text) => { + const title = `📌 ${text}`; + return `
${title}
${a2Line('title')}
\n`; + }, + heading3: (text) => `
📎 ${text}
\n`, + heading4: (text) => `
▪️ ${text}
\n`, + hr: businessHr(), + codespan: (text) => `『${text}』`, + codeblock: (code, language) => + plainCodeBlockA2(language ? `代码 · ${language}` : '代码', code), + strong: (text) => `【${text}】`, + em: (text) => `〈${text}〉`, + del: (text) => `〚${text}〛`, + blockquote: (content) => + `
💬┃ ${content}
`, + tableLabel: '📊 表格', + tableStyle: 'frame', + link: (text, href) => + text === href ? `🔗 ${href}` : `🔗 ${text} → ${href}`, + image: () => '', + fallbackOrdered: '🔸', +}; + /** B · 青简:书签框 + 圆圈序号,行内代码同样用『』 */ export const THEME_B: EmojiTheme = { id: 'B', @@ -222,7 +329,7 @@ export const THEME_D: EmojiTheme = { heading2: (text) => `
🔹 ${text}
\n`, heading3: (text) => `
🔸 ${text}
\n`, heading4: (text) => `
▪ ${text}
\n`, - hr: '━━━━━━\n', + hr: '────────\n', codespan: (text) => `『${text}』`, codeblock: (code, language) => plainCodeBlock(`📋『${language || 'code'}』`, code), @@ -242,12 +349,23 @@ export const THEME_D: EmojiTheme = { export const THEMES: Record = { A: THEME_A, + A2: THEME_A2, B: THEME_B, C: THEME_C, D: THEME_D, }; +/** 纯文本预览可选主题(含 A2) */ export const THEME_LIST: EmojiTheme[] = [ + THEME_A, + THEME_A2, + THEME_B, + THEME_C, + THEME_D, +]; + +/** 长文预览主题(A2 仅用于纯文本) */ +export const ARTICLE_THEME_LIST: EmojiTheme[] = [ THEME_A, THEME_B, THEME_C, @@ -264,5 +382,11 @@ export function resolveTheme(id?: string | null): EmojiTheme { } export function isThemeId(id: unknown): id is ThemeId { + return ( + id === 'A' || id === 'A2' || id === 'B' || id === 'C' || id === 'D' + ); +} + +export function isArticleThemeId(id: unknown): id is Exclude { return id === 'A' || id === 'B' || id === 'C' || id === 'D'; }