markloom 0.5.1 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (73) hide show
  1. package/PACKAGES.md +26 -0
  2. package/README.md +20 -2
  3. package/collab.md +60 -13
  4. package/dist/ai/index.cjs +5 -4
  5. package/dist/ai/index.d.cts +5 -4
  6. package/dist/ai/index.d.ts +5 -4
  7. package/dist/ai/index.js +4 -3
  8. package/dist/ai/theme.css +66 -102
  9. package/dist/{chunk-ZMTLSFLO.js → chunk-4Q7PAR2T.js} +5746 -1341
  10. package/dist/chunk-75EJ4ARB.cjs +642 -0
  11. package/dist/{chunk-JS527FDV.cjs → chunk-BMPCVT3B.cjs} +47 -39
  12. package/dist/{chunk-RLTHVQNQ.js → chunk-EFYT2223.js} +47 -39
  13. package/dist/chunk-HXABDVLZ.cjs +297 -0
  14. package/dist/{chunk-YIFOGP2D.cjs → chunk-I2LDEVLA.cjs} +499 -102
  15. package/dist/chunk-MQLRZQZL.js +642 -0
  16. package/dist/chunk-OVHASRID.cjs +4279 -0
  17. package/dist/chunk-PCSVBPOR.cjs +40 -0
  18. package/dist/{chunk-FCH7LZFI.js → chunk-PSAXWBNM.js} +450 -53
  19. package/dist/chunk-PZRWTLLB.cjs +858 -0
  20. package/dist/chunk-QO7JEZDB.js +4279 -0
  21. package/dist/chunk-WSJUXPAG.js +40 -0
  22. package/dist/{chunk-VXM7Q6P5.cjs → chunk-Y4IXQFWL.cjs} +6026 -1621
  23. package/dist/chunk-YLVSMDIO.js +858 -0
  24. package/dist/chunk-ZL6WT6OY.js +297 -0
  25. package/dist/client-BvvyHjhh.d.ts +250 -0
  26. package/dist/client-Ciy7Fa_k.d.cts +250 -0
  27. package/dist/collab/index.cjs +17 -4
  28. package/dist/collab/index.d.cts +18 -7
  29. package/dist/collab/index.d.ts +18 -7
  30. package/dist/collab/index.js +19 -6
  31. package/dist/{controller-DQITsFhy.d.cts → controller-CHznEhAR.d.cts} +277 -26
  32. package/dist/{controller-BNuuUM3E.d.ts → controller-DLqI8_jm.d.ts} +277 -26
  33. package/dist/index.cjs +119 -7
  34. package/dist/index.d.cts +138 -6
  35. package/dist/index.d.ts +138 -6
  36. package/dist/index.js +130 -18
  37. package/dist/io/index.cjs +1412 -0
  38. package/dist/io/index.d.cts +33 -0
  39. package/dist/io/index.d.ts +33 -0
  40. package/dist/io/index.js +1412 -0
  41. package/dist/react/index.cjs +9 -8
  42. package/dist/react/index.d.cts +5 -4
  43. package/dist/react/index.d.ts +5 -4
  44. package/dist/react/index.js +8 -7
  45. package/dist/{rebase-batch-8rL_aXEE.d.ts → rebase-batch-CSnv8FKp.d.ts} +11 -9
  46. package/dist/{rebase-batch-bYnBJpRO.d.cts → rebase-batch-DO1ygkx9.d.cts} +11 -9
  47. package/dist/types-BkHlmUFL.d.cts +34 -0
  48. package/dist/types-BkHlmUFL.d.ts +34 -0
  49. package/dist/versions-DNFf8zVz.d.cts +51 -0
  50. package/dist/versions-DOkOyh2J.d.ts +51 -0
  51. package/dist/view/index.cjs +259 -17
  52. package/dist/view/index.d.cts +277 -12
  53. package/dist/view/index.d.ts +277 -12
  54. package/dist/view/index.js +256 -14
  55. package/dist/view/theme.css +2093 -1577
  56. package/dist/word-count-BPw9G2Bg.d.ts +130 -0
  57. package/dist/word-count-DNLn1h_t.d.cts +130 -0
  58. package/io.md +38 -0
  59. package/package.json +25 -4
  60. package/dist/chunk-4JSJAHTB.js +0 -255
  61. package/dist/chunk-4TMHVNL6.cjs +0 -2297
  62. package/dist/chunk-ALZ3A5CS.cjs +0 -255
  63. package/dist/chunk-GQ2HHRGI.cjs +0 -16
  64. package/dist/chunk-LA5SBCGQ.js +0 -16
  65. package/dist/chunk-LEYAQNJA.js +0 -220
  66. package/dist/chunk-MFYF2A6U.js +0 -2297
  67. package/dist/chunk-YXQDCW4Y.cjs +0 -220
  68. package/dist/client-6KiH4kGK.d.ts +0 -144
  69. package/dist/client-ZRZj2nkq.d.cts +0 -144
  70. package/dist/comments-DlExS6f-.d.cts +0 -43
  71. package/dist/comments-PhnR7Gkn.d.ts +0 -43
  72. package/dist/step-BrvHIK7O.d.cts +0 -65
  73. package/dist/step-BrvHIK7O.d.ts +0 -65
package/PACKAGES.md ADDED
@@ -0,0 +1,26 @@
1
+ # markloom 包矩阵(O(1) 交付)
2
+
3
+ > 用户心智只到 import / 一个 options 字段。扩展点是作者工具,不是默认交付。
4
+
5
+ ## 已立
6
+
7
+ | 入口 | 开关 | 能力 |
8
+ |---|---|---|
9
+ | `markloom` | — | 树 · Step · MD · find/replace · history · versions · suggest 纯函数 |
10
+ | `markloom/view` | 默认 kit | 编辑器 + 装饰层 |
11
+ | `markloom/view` | `search: true` | **查找替换** · Cmd/Ctrl+F |
12
+ | `markloom/view` | `versions: true` | **命名版本** · Cmd/Ctrl+Shift+S · 协作时上行房间 |
13
+ | `markloom/view` | `suggest: true` | **修订** · 跟踪插入/退格标删 · accept/reject · ⌘⇧G |
14
+ | `markloom/view` | `comments: {}` | 批注侧栏 |
15
+ | `markloom/view` | `toc: true` | 目录 |
16
+ | `markloom/ai` | `ai: {…}` | 流式写作 · draft 事务 |
17
+ | `markloom/collab` | `collab: { url, room, token? }` | OT + presence · 鉴权 · 心跳 · resync · **版本侧信道** |
18
+ | `markloom/io` | `import` | **DOCX 进/出** · store+deflate · 图 data URL / `docToDocxAsync` 拉远程 |
19
+ | `markloom/react` | peer react | React 壳 |
20
+
21
+ ## 律
22
+
23
+ 1. **不 import = 不存在**(体积与概念)
24
+ 2. **import + 一字段 = 开箱**(禁止拼装手册当主路径)
25
+ 3. **不占新节点类型**(M1=16 已满;企业能力走侧信道 / Step / 纯读)
26
+ 4. **内核基础层不拆**(IME / 输入守卫 / map)
package/README.md CHANGED
@@ -2,6 +2,8 @@
2
2
 
3
3
  **The loom for Markdown** — rich text that stays honest with MD, and that AI can write into without a second model.
4
4
 
5
+ **Site:** [markloom-www.pages.dev](https://markloom-www.pages.dev) · [Docs](https://markloom-www.pages.dev/docs/)
6
+
5
7
  Most editors pick one: a nice WYSIWYG that mangled MD on export, or a MD source that never becomes a real structured tree. Product teams re-glue paste, IME, undo, and AI cards. Agents stream text into a DOM they don’t own.
6
8
 
7
9
  markloom is one document model: a **schema-constrained tree**, **reversible Steps**, **Markdown as an isomorphic projection** (not “export later”), and an optional **AI transaction** on real blocks. Kernel without DOM; view when you need an editor.
@@ -52,10 +54,11 @@ One options field: `/ai`, format bar, real draft blocks, accept / undo — same
52
54
  ### 5. Use the piece you need
53
55
 
54
56
  ```
55
- markloom tree, Steps, history, MD, appendText / diffById
56
- markloom/view editor + view/theme.css
57
+ markloom tree, Steps, history, MD, search/versions/suggest pure fns
58
+ markloom/view editor + view/theme.css (search / versions / suggest / …)
57
59
  markloom/ai AI controller + stream helper + ai/theme.css
58
60
  markloom/collab realtime OT client (pair with worker/)
61
+ markloom/io DOCX import/export (docToDocx / docxToDoc)
59
62
  markloom/react optional React wrapper (peer react, optional)
60
63
  ```
61
64
 
@@ -108,6 +111,21 @@ new Editor(el, doc, {
108
111
  })
109
112
  ```
110
113
 
114
+ **Enterprise O(1)** (import + one option; no assembly manual):
115
+
116
+ ```ts
117
+ new Editor(el, doc, {
118
+ search: true, // ⌘F find/replace
119
+ versions: true, // ⌘⇧S named snapshots (collab syncs when connected)
120
+ suggest: true, // ⌘⇧G track changes
121
+ collab: { url, room, token: 'optional-shared-secret' },
122
+ })
123
+
124
+ import { docToDocx, docxToDoc } from 'markloom/io'
125
+ const bytes = docToDocx(ed.doc)
126
+ const back = docxToDoc(bytes)
127
+ ```
128
+
111
129
  ## Why this stack
112
130
 
113
131
 
package/collab.md CHANGED
@@ -1,6 +1,6 @@
1
- # Collaboration
1
+ # Local-first collaboration
2
2
 
3
- Real-time multiplayer via **centralized OT** (markloom `rebase` / `makeBias`) and a **Cloudflare Worker** Durable Object room (same WebSocket pattern as the chat repo: `acceptWebSocket` + fan-out).
3
+ The local document is primary. WebSocket synchronization is optional transport: editing never waits for a connection, unacknowledged Steps stay in the local replica, and reconnect replays them through the server's persisted OT log.
4
4
 
5
5
  ## Client (copy-paste)
6
6
 
@@ -13,22 +13,46 @@ npm i markloom
13
13
  import { Editor } from 'markloom/view'
14
14
  import 'markloom/view/theme.css'
15
15
 
16
- new Editor(el, doc, {
16
+ const ed = new Editor(el, loaded?.doc ?? doc, {
17
17
  collab: {
18
18
  url: 'ws://127.0.0.1:8787', // or wss://your-worker.workers.dev
19
19
  room: 'demo-room',
20
20
  name: 'Alice',
21
+ replica: loaded?.replica,
22
+ // bootstrap: 'remote', // 仅“把已有远端房间导入新本地副本”时显式开启
23
+ onState: state => save(state), // one atomic record: { doc, replica }
24
+ // token: 'secret', // when worker COLLAB_TOKEN is set
25
+ // token: () => fetchToken(), // async ok
26
+ // onStatus: s => …, // connecting | open | closed | resyncing | conflict | auth-error
27
+ // onResync: v => …, // server forced snapshot
28
+ // onConflict: c => …, // c.remote is never applied implicitly
21
29
  },
22
30
  })
23
31
  ```
24
32
 
25
- That is enough: local edits upload as Steps; remote Steps apply through OT. No extension list.
33
+ Persist the value delivered by `onState` as one atomic record. It fires only after both the document and replica transition are complete, including local edits, remote ops, acknowledgements, reconnects, and resyncs. `replica` contains the stable client identity, confirmed server version, monotonic sequence, and every unacknowledged Step. A fresh document may omit it; a restored local document must pass it back.
26
34
 
27
- **Presence (built-in, Feishu-style):** top-right avatar stack (self + peers) and colored remote carets with name labels. Colors auto-assign by `siteId` unless you set `color`. No extra config.
35
+ Remote state is never the implicit authority. Joining an existing room without replica metadata enters `conflict`; set `bootstrap: 'remote'` only for the explicit “import this remote room as a new local replica” action. A newly created room is seeded from the local document without this flag.
36
+
37
+ Local edits always commit and enter `replica.pending`, including while connecting, disconnected, in an auth failure, or in a sync conflict. The client sends one pending batch at a time and removes it only after an explicit acknowledgement.
38
+
39
+ **Presence (built-in, Feishu-style):** status dot + top-right avatar stack (self + peers) and colored remote carets with name labels. Colors auto-assign by `siteId` unless you set `color`. No extra config.
40
+
41
+ **Production hooks**
42
+
43
+ | Field | Role |
44
+ |-------|------|
45
+ | `token` / `() => token` | Join auth; worker rejects if `COLLAB_TOKEN` set and mismatch → `auth-error` (no reconnect storm) |
46
+ | `replica` / `onState` | Restore and atomically persist `{ doc, replica }` |
47
+ | `bootstrap: 'remote'` | Explicit one-time import of an existing remote room into a new local replica |
48
+ | `onStatus` | `connecting` · `open` · `closed` · `resyncing` · `conflict` · `auth-error` |
49
+ | `onResync` | Snapshot applies only with no pending local changes; otherwise status becomes `conflict` |
50
+ | `onConflict` | Inspect the reason and complete remote snapshot; call `ed.collab.acceptRemote()` only for an explicit discard-local action |
51
+ | heartbeat | Client ping 20s; no pong 45s → reconnect |
28
52
 
29
53
  Optional: `color`, `name`, `seed` (empty room init; default = constructor `doc`).
30
54
 
31
- Programmatic: `ed.collab` → `CollabClient` (`peersList`, `close()`).
55
+ Programmatic: `ed.collab` → `CollabClient` (`peersList`, `status`, `close()`).
32
56
 
33
57
  ## Worker
34
58
 
@@ -39,7 +63,7 @@ bun run dev # wrangler dev → ws://127.0.0.1:8787
39
63
  ```
40
64
 
41
65
  - `GET /room/:id` + WebSocket upgrade → one Durable Object per room name
42
- - Snapshot persisted in DO storage; op log in memory (stale base → `resync`)
66
+ - Snapshot, complete op log, and last acknowledged sequence per client are persisted in DO storage; joins and rebases range-read only the log suffix after their base version
43
67
 
44
68
  Deploy: `bun run deploy` (Cloudflare account + `wrangler login`).
45
69
 
@@ -47,17 +71,39 @@ Deploy: `bun run deploy` (Cloudflare account + `wrangler login`).
47
71
 
48
72
  | Direction | Types |
49
73
  |-----------|--------|
50
- | C→S | `join`, `op`, `presence`, `ping` |
51
- | S→C | `welcome`, `op`, `presence`, `peer-join` / `peer-leave`, `resync`, `error` |
74
+ | C→S | `join` (`clientId`, confirmed `version`), `op` (`clientId`, `clientSeq`), `presence`, `ping`, `version-save`, `version-remove` |
75
+ | S→C | `welcome` (incremental `ops`, `ackedSeq`, `versions?`), `op`, `presence`, `peer-join` / `peer-leave`, `resync`, structured `error` (`code`, `message`), `versions` |
76
+
77
+ Named versions are a **side channel** (not OT steps): save/remove broadcast the full room list; `welcome` seeds late joiners. Enable with `versions: true` on the Editor — collab auto-uploads on save.
52
78
 
53
79
  See `src/collab/protocol.ts`.
54
80
 
81
+ ## Write paths (abstraction)
82
+
83
+ Exactly **two** ways the doc changes under collab:
84
+
85
+ | Path | API | Undo stack | Network |
86
+ |------|-----|------------|---------|
87
+ | **local** | `dispatch` / `dispatchStream` / `undo` / `redo` | `commit` / `amend` / pop | append pending; send when online |
88
+ | **foreign** | `applyRemote` → `applyForeign` | OT-map only, **never push** | inbound `op` |
89
+
90
+ Decorations (slash, table, bubble, …) only call `host.dispatch` → local.
91
+ No third path mutates `history.doc`.
92
+
93
+ ## Undo / redo (per-person)
94
+
95
+ - **Local stack only**: remote ops use `applyForeign` — update the doc and OT-map your stack, but **never push remote onto `past`**.
96
+ - Multi-step commits / inverses use **sequential** OT (`transformSeqThroughOne`), not per-step independent map.
97
+ - **Cmd+Z** undoes *your* last commit; inverse is broadcast as a normal op.
98
+ - Foreign batches are applied **as sent** (gap steps already included by the author).
99
+
55
100
  ## Limits (honest)
56
101
 
57
- - **TP2** (reordered remote undo chains) not proven; server serializes commits so common concurrent typing is covered by TP1 + central order.
58
- - Local **undo** interleaved with remote may need a later resync.
59
- - No auth: room id is the capability.
60
- - Presence is on the wire; rich multi-caret chrome is optional product UI.
102
+ - **TP2** (reordered remote undo chains) not proven; server serializes commits so common concurrent typing is covered by TP1 + central order.
103
+ - A rebase/apply failure with local pending becomes an explicit `conflict`. The local document and pending queue are retained; a snapshot never silently overwrites them.
104
+ - A conflict exposes its complete remote snapshot at `ed.collab.conflict`. `acceptRemote()` is the explicit destructive resolution; keeping local means closing this client and opening a new room, while manual merge starts from the two exposed documents.
105
+ - Pathological OT corner cases may still `resync`; room id alone is weak capability — set `COLLAB_TOKEN` + client `token` for shared-secret auth.
106
+ - Presence multi-caret chrome is built-in; further product UI is optional.
61
107
 
62
108
  ## Lab
63
109
 
@@ -67,4 +113,5 @@ cd worker && bun run dev
67
113
  # terminal 2
68
114
  cd .. && bun run lab
69
115
  # open two windows: http://localhost:5181/?room=demo
116
+ # with auth: wrangler vars COLLAB_TOKEN=secret → ?room=demo&token=secret
70
117
  ```
package/dist/ai/index.cjs CHANGED
@@ -6,9 +6,10 @@
6
6
 
7
7
 
8
8
 
9
- var _chunkYIFOGP2Dcjs = require('../chunk-YIFOGP2D.cjs');
10
- require('../chunk-4TMHVNL6.cjs');
11
- require('../chunk-GQ2HHRGI.cjs');
9
+ var _chunkI2LDEVLAcjs = require('../chunk-I2LDEVLA.cjs');
10
+ require('../chunk-OVHASRID.cjs');
11
+ require('../chunk-HXABDVLZ.cjs');
12
+ require('../chunk-PCSVBPOR.cjs');
12
13
 
13
14
 
14
15
 
@@ -17,4 +18,4 @@ require('../chunk-GQ2HHRGI.cjs');
17
18
 
18
19
 
19
20
 
20
- exports.MarkloomAi = _chunkYIFOGP2Dcjs.MarkloomAi; exports.aiInstructionFromQuery = _chunkYIFOGP2Dcjs.aiInstructionFromQuery; exports.blockPlainText = _chunkYIFOGP2Dcjs.blockPlainText; exports.createAiStream = _chunkYIFOGP2Dcjs.createAiStream; exports.focusBlockId = _chunkYIFOGP2Dcjs.focusBlockId; exports.precedingPlainText = _chunkYIFOGP2Dcjs.precedingPlainText; exports.startAiWrite = _chunkYIFOGP2Dcjs.startAiWrite;
21
+ exports.MarkloomAi = _chunkI2LDEVLAcjs.MarkloomAi; exports.aiInstructionFromQuery = _chunkI2LDEVLAcjs.aiInstructionFromQuery; exports.blockPlainText = _chunkI2LDEVLAcjs.blockPlainText; exports.createAiStream = _chunkI2LDEVLAcjs.createAiStream; exports.focusBlockId = _chunkI2LDEVLAcjs.focusBlockId; exports.precedingPlainText = _chunkI2LDEVLAcjs.precedingPlainText; exports.startAiWrite = _chunkI2LDEVLAcjs.startAiWrite;
@@ -1,8 +1,9 @@
1
- export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-DQITsFhy.cjs';
2
- import { E as ElementNode } from '../step-BrvHIK7O.cjs';
1
+ export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-CHznEhAR.cjs';
2
+ import { E as ElementNode } from '../types-BkHlmUFL.cjs';
3
+ import '../versions-DNFf8zVz.cjs';
3
4
  import 'preact';
4
- import '../comments-DlExS6f-.cjs';
5
- import '../client-ZRZj2nkq.cjs';
5
+ import '../word-count-DNLn1h_t.cjs';
6
+ import '../client-Ciy7Fa_k.cjs';
6
7
 
7
8
  /** 顶层块 [0, blockIdx) 纯文本拼接(作 /ai 上下文) */
8
9
  declare function precedingPlainText(doc: ElementNode, blockIdx: number): string;
@@ -1,8 +1,9 @@
1
- export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-BNuuUM3E.js';
2
- import { E as ElementNode } from '../step-BrvHIK7O.js';
1
+ export { A as AiConfig, a as AiPromptMode, b as AiProvider, c as AiStreamFn, d as AiStreamInput, e as AiWriteMode, f as AiWriteSession, M as MarkloomAi, g as MarkloomAiOpts, h as blockPlainText, i as createAiStream, j as focusBlockId, s as startAiWrite } from '../controller-DLqI8_jm.js';
2
+ import { E as ElementNode } from '../types-BkHlmUFL.js';
3
+ import '../versions-DOkOyh2J.js';
3
4
  import 'preact';
4
- import '../comments-PhnR7Gkn.js';
5
- import '../client-6KiH4kGK.js';
5
+ import '../word-count-BPw9G2Bg.js';
6
+ import '../client-BvvyHjhh.js';
6
7
 
7
8
  /** 顶层块 [0, blockIdx) 纯文本拼接(作 /ai 上下文) */
8
9
  declare function precedingPlainText(doc: ElementNode, blockIdx: number): string;
package/dist/ai/index.js CHANGED
@@ -6,9 +6,10 @@ import {
6
6
  focusBlockId,
7
7
  precedingPlainText,
8
8
  startAiWrite
9
- } from "../chunk-FCH7LZFI.js";
10
- import "../chunk-MFYF2A6U.js";
11
- import "../chunk-LA5SBCGQ.js";
9
+ } from "../chunk-PSAXWBNM.js";
10
+ import "../chunk-QO7JEZDB.js";
11
+ import "../chunk-ZL6WT6OY.js";
12
+ import "../chunk-WSJUXPAG.js";
12
13
  export {
13
14
  MarkloomAi,
14
15
  aiInstructionFromQuery,
package/dist/ai/theme.css CHANGED
@@ -1,4 +1,6 @@
1
- /* markloom/ai — 飞书式无边框;生成结果是正文流里的真段落,确认前 opacity 淡化 */
1
+ /* markloom/ai — 飞书式无边框;生成结果是正文流里的真段落,确认前 opacity 淡化
2
+ Converted toward Tailwind @apply. Residual: CSS vars, @keyframes, ::after stream caret,
3
+ data-status bg colors, prefers-reduced-motion, html.dark dual path. */
2
4
 
3
5
  .markloom-doc .markloom-ai-block {
4
6
  --ai-blue: #3370ff;
@@ -8,14 +10,8 @@
8
10
  --ai-sub: #646a73;
9
11
  --ai-hover: #eff0f1;
10
12
  --ai-fill: #f5f6f7;
11
- position: relative;
12
- margin: 0.5rem 0 0.25rem;
13
- padding: 10px 12px 8px;
14
- border: 0;
15
- border-radius: 8px;
13
+ @apply relative my-2 mb-1 px-3 pt-2.5 pb-2 border-0 rounded-lg outline-none shadow-none;
16
14
  background: var(--ai-fill);
17
- box-shadow: none;
18
- outline: none;
19
15
  animation: markloom-ai-in 0.14s ease-out;
20
16
  }
21
17
  .markloom-doc .markloom-ai-block[data-status='loading'] {
@@ -38,30 +34,17 @@
38
34
 
39
35
  /* ── header ── */
40
36
  .markloom-doc .markloom-ai-block-hd {
41
- display: flex;
42
- align-items: center;
43
- justify-content: space-between;
44
- gap: 8px;
45
- padding: 0 0 2px;
46
- user-select: none;
37
+ @apply flex items-center justify-between gap-2 pb-0.5 pt-0 px-0 select-none;
47
38
  }
48
39
  .markloom-doc .markloom-ai-block-brand {
49
- display: inline-flex;
50
- align-items: center;
51
- gap: 6px;
52
- min-width: 0;
40
+ @apply inline-flex items-center gap-1.5 min-w-0;
53
41
  }
54
42
  .markloom-doc .markloom-ai-block-ico {
55
- display: inline-flex;
56
- align-items: center;
57
- justify-content: center;
58
- width: 20px;
59
- height: 20px;
43
+ @apply inline-flex items-center justify-center w-5 h-5 shrink-0;
60
44
  color: var(--ai-blue);
61
- flex: none;
62
45
  }
63
46
  .markloom-doc .markloom-ai-block-svg {
64
- display: block;
47
+ @apply block;
65
48
  stroke-width: 1.75;
66
49
  }
67
50
  .markloom-doc .markloom-ai-block-title {
@@ -69,10 +52,7 @@
69
52
  color: var(--ai-blue);
70
53
  }
71
54
  .markloom-doc .markloom-ai-block-badge {
72
- display: inline-flex;
73
- align-items: center;
74
- gap: 4px;
75
- margin-left: 2px;
55
+ @apply inline-flex items-center gap-1 ml-0.5;
76
56
  font: 400 12px/1.2 system-ui, sans-serif;
77
57
  color: var(--ai-muted);
78
58
  }
@@ -80,32 +60,22 @@
80
60
  .markloom-doc .markloom-ai-block-badge-error { color: #f54a45; }
81
61
 
82
62
  .markloom-doc .markloom-ai-block-seed {
83
- display: flex;
84
- align-items: baseline;
85
- gap: 8px;
86
- margin: 6px 0 0;
87
- max-height: 1.4em;
88
- overflow: hidden;
63
+ @apply flex items-baseline gap-2 mt-1.5 mb-0 max-h-[1.4em] overflow-hidden;
89
64
  }
90
65
  .markloom-doc .markloom-ai-block-seed-lab {
91
- flex: none;
66
+ @apply shrink-0;
92
67
  font: 400 12px/1.4 system-ui, sans-serif;
93
68
  color: var(--ai-muted);
94
69
  }
95
70
  .markloom-doc .markloom-ai-block-seed-txt {
71
+ @apply overflow-hidden text-ellipsis whitespace-nowrap min-w-0;
96
72
  font: 400 12px/1.4 system-ui, sans-serif;
97
73
  color: var(--ai-sub);
98
- overflow: hidden;
99
- text-overflow: ellipsis;
100
- white-space: nowrap;
101
- min-width: 0;
102
74
  }
103
75
 
104
76
  /* 指令 */
105
77
  .markloom-doc .markloom-ai-block > p.markloom-ai-prompt {
106
- margin: 6px 0 4px;
107
- padding: 4px 0;
108
- min-height: 1.5em;
78
+ @apply my-1.5 mt-1.5 mb-1 py-1 min-h-[1.5em];
109
79
  border: 0 !important;
110
80
  background: transparent !important;
111
81
  box-shadow: none !important;
@@ -113,8 +83,7 @@
113
83
  color: var(--ai-text);
114
84
  }
115
85
  .markloom-doc .markloom-ai-block[data-status='loading'] > p.markloom-ai-prompt {
116
- opacity: 0.5;
117
- pointer-events: none;
86
+ @apply opacity-50 pointer-events-none;
118
87
  }
119
88
  .markloom-doc .markloom-ai-block > p.markloom-ai-prompt[data-placeholder]::before {
120
89
  content: attr(data-placeholder);
@@ -124,25 +93,21 @@
124
93
 
125
94
  /*
126
95
  * 生成结果 = 文档顶层真块(段/标题/列表/代码/引用…)。
127
- * 确认前 opacity 淡化;确认后去掉 data-ai-draft。
96
+ * 确认前轻微淡化(别太虚);确认后去掉 data-ai-draft。
128
97
  */
129
98
  .markloom-doc > [data-ai-draft],
130
99
  .markloom-doc [data-ai-draft].markloom-ai-draft {
131
- opacity: 0.5;
100
+ @apply opacity-[0.88];
132
101
  transition: opacity 0.18s ease;
133
102
  }
134
- /* 列表/引用整体淡化时子元素别再叠一层 */
135
103
  .markloom-doc [data-ai-draft] [data-ai-draft] {
136
- opacity: 1;
104
+ @apply opacity-100;
137
105
  }
138
- /* 流式末段光标(物化前的源码段) */
106
+ /* 流式末段光标 */
139
107
  .markloom-doc > p[data-ai-draft][data-ai-stream]::after,
140
108
  .markloom-doc p[data-ai-draft][data-ai-stream]::after {
141
109
  content: '';
142
- display: inline-block;
143
- width: 2px;
144
- height: 1em;
145
- margin-left: 2px;
110
+ @apply inline-block w-0.5 h-[1em] ml-0.5;
146
111
  background: #3370ff;
147
112
  vertical-align: text-bottom;
148
113
  animation: markloom-ai-caret 0.9s steps(1) infinite;
@@ -152,66 +117,37 @@
152
117
  }
153
118
 
154
119
  .markloom-doc .markloom-ai-block-err {
155
- margin: 4px 0 0;
120
+ @apply mt-1 mb-0;
156
121
  font: 400 13px/1.45 system-ui, sans-serif;
157
122
  color: #f54a45;
158
123
  }
159
124
 
160
125
  /* footer */
161
126
  .markloom-doc .markloom-ai-block-ft {
162
- display: flex;
163
- align-items: center;
164
- justify-content: space-between;
165
- gap: 10px;
166
- padding: 6px 0 0;
167
- min-height: 32px;
127
+ @apply flex items-center justify-between gap-2.5 pt-1.5 pb-0 px-0 min-h-8;
168
128
  }
169
129
  .markloom-doc .markloom-ai-block-hint {
170
- display: inline-flex;
171
- align-items: center;
172
- flex-wrap: wrap;
173
- gap: 3px;
130
+ @apply inline-flex items-center flex-wrap gap-[3px] min-w-0;
174
131
  font: 400 12px/1.3 system-ui, sans-serif;
175
132
  color: var(--ai-muted);
176
- min-width: 0;
177
133
  }
178
134
  .markloom-doc .markloom-ai-block-hint.is-error { color: #f54a45; }
179
135
  .markloom-doc .markloom-ai-block-loading { color: var(--ai-blue); }
180
- .markloom-doc .markloom-ai-dot { opacity: 0.4; margin: 0 1px; }
136
+ .markloom-doc .markloom-ai-dot { @apply opacity-40 mx-px; }
181
137
  .markloom-doc .markloom-ai-kbd {
182
- display: inline-flex;
183
- align-items: center;
184
- justify-content: center;
185
- min-width: 1.2em;
186
- height: 16px;
187
- padding: 0 4px;
188
- border: 0;
189
- border-radius: 3px;
138
+ @apply inline-flex items-center justify-center min-w-[1.2em] h-4 px-1 border-0 rounded-sm;
190
139
  background: rgba(31, 35, 41, 0.06);
191
140
  font: 500 10px/1 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
192
141
  color: var(--ai-sub);
193
142
  }
194
143
 
195
144
  .markloom-doc .markloom-ai-block-acts {
196
- display: inline-flex;
197
- align-items: center;
198
- gap: 2px;
199
- margin-left: auto;
200
- flex: none;
145
+ @apply inline-flex items-center gap-0.5 ml-auto shrink-0;
201
146
  }
202
147
  .markloom-doc .markloom-ai-block-btn {
203
- display: inline-flex;
204
- align-items: center;
205
- justify-content: center;
206
- height: 28px;
207
- padding: 0 10px;
208
- border: 0;
209
- border-radius: 6px;
210
- background: transparent;
148
+ @apply inline-flex items-center justify-center h-7 px-2.5 border-0 rounded-md bg-transparent cursor-pointer select-none;
211
149
  font: 500 13px/1 system-ui, -apple-system, 'Segoe UI', sans-serif;
212
150
  color: var(--ai-sub);
213
- cursor: pointer;
214
- user-select: none;
215
151
  transition: background 0.1s ease, color 0.1s ease;
216
152
  }
217
153
  .markloom-doc .markloom-ai-block-btn:hover {
@@ -219,19 +155,16 @@
219
155
  color: var(--ai-text);
220
156
  }
221
157
  .markloom-doc .markloom-ai-block-btn-icon {
222
- width: 28px;
223
- padding: 0;
224
- font-size: 16px;
225
- font-weight: 400;
158
+ @apply w-7 p-0 text-base font-normal;
226
159
  color: var(--ai-muted);
227
160
  }
228
161
  .markloom-doc .markloom-ai-block-btn-ghost,
229
162
  .markloom-doc .markloom-ai-block-btn-soft {
230
- background: transparent;
163
+ @apply bg-transparent;
231
164
  color: var(--ai-sub);
232
165
  }
233
166
  .markloom-doc .markloom-ai-block-btn-primary {
234
- background: transparent;
167
+ @apply bg-transparent;
235
168
  color: var(--ai-blue);
236
169
  }
237
170
  .markloom-doc .markloom-ai-block-btn-primary:hover {
@@ -240,14 +173,10 @@
240
173
  }
241
174
 
242
175
  .markloom-doc .markloom-ai-spin {
243
- display: inline-block;
244
- width: 12px;
245
- height: 12px;
176
+ @apply inline-block w-3 h-3 rounded-full shrink-0;
246
177
  border: 1.5px solid currentColor;
247
178
  border-right-color: transparent;
248
- border-radius: 50%;
249
179
  animation: markloom-ai-spin 0.7s linear infinite;
250
- flex: none;
251
180
  vertical-align: -1px;
252
181
  }
253
182
  @keyframes markloom-ai-spin {
@@ -285,7 +214,7 @@
285
214
  }
286
215
  .markloom-doc > [data-ai-draft],
287
216
  .markloom-doc [data-ai-draft].markloom-ai-draft {
288
- opacity: 0.55;
217
+ opacity: 0.9;
289
218
  }
290
219
  .markloom-doc p[data-ai-draft][data-ai-stream]::after {
291
220
  background: #7aafff;
@@ -302,3 +231,38 @@
302
231
  color: #ff8a85;
303
232
  }
304
233
  }
234
+ html.dark .markloom-doc .markloom-ai-block {
235
+ --ai-blue: #7aafff;
236
+ --ai-blue-soft: rgba(122, 175, 255, 0.12);
237
+ --ai-muted: rgba(255, 255, 255, 0.4);
238
+ --ai-text: rgba(255, 255, 255, 0.9);
239
+ --ai-sub: rgba(255, 255, 255, 0.6);
240
+ --ai-hover: rgba(255, 255, 255, 0.08);
241
+ --ai-fill: rgba(255, 255, 255, 0.06);
242
+ background: var(--ai-fill);
243
+ }
244
+ html.dark .markloom-doc .markloom-ai-block[data-status='loading'],
245
+ html.dark .markloom-doc .markloom-ai-block:focus-within {
246
+ background: rgba(122, 175, 255, 0.08);
247
+ }
248
+ html.dark .markloom-doc .markloom-ai-block[data-status='error'] {
249
+ background: rgba(245, 74, 69, 0.1);
250
+ }
251
+ html.dark .markloom-doc > [data-ai-draft],
252
+ html.dark .markloom-doc [data-ai-draft].markloom-ai-draft {
253
+ opacity: 0.9;
254
+ }
255
+ html.dark .markloom-doc p[data-ai-draft][data-ai-stream]::after {
256
+ background: #7aafff;
257
+ }
258
+ html.dark .markloom-doc .markloom-ai-kbd {
259
+ background: rgba(255, 255, 255, 0.08);
260
+ }
261
+ html.dark .markloom-doc .markloom-ai-block-btn-primary:hover {
262
+ background: var(--ai-blue-soft);
263
+ }
264
+ html.dark .markloom-doc .markloom-ai-block-err,
265
+ html.dark .markloom-doc .markloom-ai-block-hint.is-error,
266
+ html.dark .markloom-doc .markloom-ai-block-badge-error {
267
+ color: #ff8a85;
268
+ }