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
@@ -1,255 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _class;
2
-
3
- var _chunkJS527FDVcjs = require('./chunk-JS527FDV.cjs');
4
-
5
- // src/collab/colors.ts
6
- var COLLAB_COLORS = [
7
- "#3370ff",
8
- "#f54a45",
9
- "#ff8800",
10
- "#00b578",
11
- "#7b61ff",
12
- "#e13edb",
13
- "#14c0ff",
14
- "#8f959e",
15
- "#d83931",
16
- "#2ea121"
17
- ];
18
- function collabColor(siteId, explicit) {
19
- if (explicit)
20
- return explicit;
21
- const i = Math.abs((siteId || 1) - 1) % COLLAB_COLORS.length;
22
- return COLLAB_COLORS[i];
23
- }
24
- function collabInitial(name, siteId) {
25
- const n = (name || "").trim();
26
- if (n) {
27
- const ch = n[0];
28
- return /[a-z]/i.test(ch) ? ch.toUpperCase() : ch;
29
- }
30
- return String(_nullishCoalesce(siteId, () => ( "?")));
31
- }
32
-
33
- // src/collab/client.ts
34
- function toWsUrl(url, room) {
35
- let u = url.replace(/\/+$/, "");
36
- if (u.startsWith("https://"))
37
- u = `wss://${u.slice(8)}`;
38
- else if (u.startsWith("http://"))
39
- u = `ws://${u.slice(7)}`;
40
- return `${u}/room/${encodeURIComponent(room)}`;
41
- }
42
- function retryDelay(attempt) {
43
- const base = Math.min(1e3 * 2 ** Math.min(attempt, 5), 3e4);
44
- const jitter = base * 0.5 * Math.random();
45
- return base * 0.75 + jitter;
46
- }
47
- var CollabClient = (_class = class {
48
-
49
-
50
- __init() {this.ws = null}
51
- __init2() {this.closed = false}
52
- __init3() {this.retry = 0}
53
- __init4() {this.reconnectTimer = null}
54
- __init5() {this.siteId = 0}
55
- __init6() {this.version = 0}
56
- __init7() {this.clientSeq = 0}
57
- __init8() {this.pending = []}
58
- __init9() {this.peers = /* @__PURE__ */ new Map()}
59
- __init10() {this.joined = false}
60
- constructor(cfg, handlers) {;_class.prototype.__init.call(this);_class.prototype.__init2.call(this);_class.prototype.__init3.call(this);_class.prototype.__init4.call(this);_class.prototype.__init5.call(this);_class.prototype.__init6.call(this);_class.prototype.__init7.call(this);_class.prototype.__init8.call(this);_class.prototype.__init9.call(this);_class.prototype.__init10.call(this);
61
- this.cfg = cfg;
62
- this.handlers = handlers;
63
- this.connect();
64
- }
65
- get peersList() {
66
- return [...this.peers.values()];
67
- }
68
- connect() {
69
- if (this.closed)
70
- return;
71
- _optionalChain([this, 'access', _ => _.handlers, 'access', _2 => _2.onStatus, 'optionalCall', _3 => _3("connecting")]);
72
- const url = toWsUrl(this.cfg.url, this.cfg.room);
73
- let ws;
74
- try {
75
- ws = new WebSocket(url);
76
- } catch (e) {
77
- _optionalChain([this, 'access', _4 => _4.handlers, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(e instanceof Error ? e.message : String(e))]);
78
- this.scheduleReconnect();
79
- return;
80
- }
81
- this.ws = ws;
82
- ws.onopen = () => {
83
- this.retry = 0;
84
- _optionalChain([this, 'access', _7 => _7.handlers, 'access', _8 => _8.onStatus, 'optionalCall', _9 => _9("open")]);
85
- this.send({
86
- type: "join",
87
- room: this.cfg.room,
88
- name: this.cfg.name,
89
- color: this.cfg.color,
90
- seed: this.cfg.seed
91
- });
92
- };
93
- ws.onclose = () => {
94
- this.joined = false;
95
- _optionalChain([this, 'access', _10 => _10.handlers, 'access', _11 => _11.onStatus, 'optionalCall', _12 => _12("closed")]);
96
- if (!this.closed)
97
- this.scheduleReconnect();
98
- };
99
- ws.onerror = () => {
100
- try {
101
- ws.close();
102
- } catch (e2) {
103
- }
104
- };
105
- ws.onmessage = (ev) => {
106
- try {
107
- const msg = JSON.parse(String(ev.data));
108
- this.onServer(msg);
109
- } catch (e3) {
110
- }
111
- };
112
- }
113
- scheduleReconnect() {
114
- if (this.reconnectTimer || this.closed)
115
- return;
116
- const delay = retryDelay(this.retry++);
117
- this.reconnectTimer = setTimeout(() => {
118
- this.reconnectTimer = null;
119
- this.connect();
120
- }, delay);
121
- }
122
- send(msg) {
123
- if (_optionalChain([this, 'access', _13 => _13.ws, 'optionalAccess', _14 => _14.readyState]) === WebSocket.OPEN)
124
- this.ws.send(JSON.stringify(msg));
125
- }
126
- onServer(msg) {
127
- switch (msg.type) {
128
- case "welcome": {
129
- this.siteId = msg.siteId;
130
- this.version = msg.version;
131
- this.pending = [];
132
- this.joined = true;
133
- if (!this.cfg.color)
134
- this.cfg.color = collabColor(msg.siteId);
135
- this.peers.clear();
136
- for (const p of msg.peers) {
137
- this.peers.set(p.siteId, {
138
- ...p,
139
- color: collabColor(p.siteId, p.color)
140
- });
141
- }
142
- _optionalChain([this, 'access', _15 => _15.handlers, 'access', _16 => _16.onWelcome, 'optionalCall', _17 => _17({
143
- siteId: msg.siteId,
144
- version: msg.version,
145
- name: this.cfg.name,
146
- color: this.cfg.color
147
- })]);
148
- this.handlers.onDoc(msg.doc, msg.version);
149
- _optionalChain([this, 'access', _18 => _18.handlers, 'access', _19 => _19.onPeers, 'optionalCall', _20 => _20(this.peersList)]);
150
- break;
151
- }
152
- case "resync": {
153
- this.version = msg.version;
154
- this.pending = [];
155
- this.handlers.onDoc(msg.doc, msg.version);
156
- break;
157
- }
158
- case "op": {
159
- if (!this.joined)
160
- return;
161
- if (msg.siteId === this.siteId) {
162
- if (msg.clientSeq != null)
163
- this.pending = this.pending.filter((p) => p.clientSeq > msg.clientSeq);
164
- this.version = msg.version;
165
- return;
166
- }
167
- const pendingAs = this.pending.map((p) => ({ siteId: this.siteId, steps: p.steps }));
168
- const { remote, pending: nextP } = _chunkJS527FDVcjs.transformRemoteAgainstPending.call(void 0,
169
- msg.steps,
170
- msg.siteId,
171
- pendingAs,
172
- this.siteId
173
- );
174
- this.pending = this.pending.map((p, i) => ({
175
- ...p,
176
- steps: _nullishCoalesce(_optionalChain([nextP, 'access', _21 => _21[i], 'optionalAccess', _22 => _22.steps]), () => ( p.steps))
177
- }));
178
- this.version = msg.version;
179
- if (remote.length)
180
- this.handlers.onRemote(remote);
181
- break;
182
- }
183
- case "presence": {
184
- const cur = _nullishCoalesce(this.peers.get(msg.siteId), () => ( { siteId: msg.siteId }));
185
- this.peers.set(msg.siteId, {
186
- ...cur,
187
- name: _nullishCoalesce(msg.name, () => ( cur.name)),
188
- color: collabColor(msg.siteId, _nullishCoalesce(msg.color, () => ( cur.color))),
189
- sel: msg.sel === void 0 ? cur.sel : msg.sel
190
- });
191
- _optionalChain([this, 'access', _23 => _23.handlers, 'access', _24 => _24.onPeers, 'optionalCall', _25 => _25(this.peersList)]);
192
- break;
193
- }
194
- case "peer-join": {
195
- this.peers.set(msg.siteId, {
196
- siteId: msg.siteId,
197
- name: msg.name,
198
- color: collabColor(msg.siteId, msg.color)
199
- });
200
- _optionalChain([this, 'access', _26 => _26.handlers, 'access', _27 => _27.onPeers, 'optionalCall', _28 => _28(this.peersList)]);
201
- break;
202
- }
203
- case "peer-leave": {
204
- this.peers.delete(msg.siteId);
205
- _optionalChain([this, 'access', _29 => _29.handlers, 'access', _30 => _30.onPeers, 'optionalCall', _31 => _31(this.peersList)]);
206
- break;
207
- }
208
- case "error":
209
- _optionalChain([this, 'access', _32 => _32.handlers, 'access', _33 => _33.onError, 'optionalCall', _34 => _34(msg.message)]);
210
- break;
211
- case "pong":
212
- break;
213
- }
214
- }
215
- /** 本地已 apply 的 steps 推上服务器 */
216
- push(steps) {
217
- if (!steps.length || !this.joined || this.siteId <= 0)
218
- return;
219
- const clientSeq = ++this.clientSeq;
220
- const baseVersion = this.version;
221
- this.pending.push({ clientSeq, baseVersion, steps });
222
- this.send({ type: "op", baseVersion, clientSeq, steps });
223
- }
224
- presence(sel) {
225
- if (!this.joined)
226
- return;
227
- this.send({
228
- type: "presence",
229
- name: this.cfg.name,
230
- color: _nullishCoalesce(this.cfg.color, () => ( collabColor(this.siteId))),
231
- sel
232
- });
233
- }
234
- close() {
235
- this.closed = true;
236
- if (this.reconnectTimer)
237
- clearTimeout(this.reconnectTimer);
238
- try {
239
- _optionalChain([this, 'access', _35 => _35.ws, 'optionalAccess', _36 => _36.close, 'call', _37 => _37()]);
240
- } catch (e4) {
241
- }
242
- this.ws = null;
243
- }
244
- }, _class);
245
- function connectCollab(cfg, handlers) {
246
- return new CollabClient(cfg, handlers);
247
- }
248
-
249
-
250
-
251
-
252
-
253
-
254
-
255
- exports.COLLAB_COLORS = COLLAB_COLORS; exports.collabColor = collabColor; exports.collabInitial = collabInitial; exports.CollabClient = CollabClient; exports.connectCollab = connectCollab;
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/tree/types.ts
2
- function isText(n) {
3
- return "text" in n;
4
- }
5
- function isElement(n) {
6
- return "children" in n;
7
- }
8
- function isInlineAtom(n) {
9
- return isElement(n) && (n.type === "mention" || n.type === "hard_break" || n.type === "math");
10
- }
11
-
12
-
13
-
14
-
15
-
16
- exports.isText = isText; exports.isElement = isElement; exports.isInlineAtom = isInlineAtom;
@@ -1,16 +0,0 @@
1
- // src/tree/types.ts
2
- function isText(n) {
3
- return "text" in n;
4
- }
5
- function isElement(n) {
6
- return "children" in n;
7
- }
8
- function isInlineAtom(n) {
9
- return isElement(n) && (n.type === "mention" || n.type === "hard_break" || n.type === "math");
10
- }
11
-
12
- export {
13
- isText,
14
- isElement,
15
- isInlineAtom
16
- };
@@ -1,220 +0,0 @@
1
- import {
2
- applyAll,
3
- checkTable,
4
- invertAll,
5
- validateAll
6
- } from "./chunk-MFYF2A6U.js";
7
- import {
8
- isElement,
9
- isInlineAtom,
10
- isText
11
- } from "./chunk-LA5SBCGQ.js";
12
-
13
- // src/tree/history.ts
14
- function init(doc, validate) {
15
- return { doc, past: [], future: [], validate };
16
- }
17
- function gate(h, next) {
18
- const v = h.validate?.(next);
19
- if (v)
20
- throw new Error(`[invariant] \u63D0\u4EA4\u4EA7\u751F\u975E\u6CD5 doc: ${v}`);
21
- }
22
- function commit(h, steps) {
23
- const inverse = invertAll(h.doc, steps);
24
- const next = applyAll(h.doc, steps);
25
- gate(h, next);
26
- return { ...h, doc: next, past: h.past.concat({ steps, inverse }), future: [] };
27
- }
28
- function amend(h, more) {
29
- if (more.length === 0)
30
- return h;
31
- if (h.past.length === 0)
32
- return commit(h, more);
33
- const last = h.past[h.past.length - 1];
34
- const before = applyAll(h.doc, last.inverse);
35
- const steps = last.steps.concat(more);
36
- const inverse = invertAll(before, steps);
37
- const next = applyAll(before, steps);
38
- gate(h, next);
39
- return {
40
- ...h,
41
- doc: next,
42
- past: h.past.slice(0, -1).concat({ steps, inverse }),
43
- future: []
44
- };
45
- }
46
- function undo(h) {
47
- const last = h.past[h.past.length - 1];
48
- if (!last)
49
- return h;
50
- const next = applyAll(h.doc, last.inverse);
51
- gate(h, next);
52
- return { ...h, doc: next, past: h.past.slice(0, -1), future: [last, ...h.future] };
53
- }
54
- function redo(h) {
55
- const next = h.future[0];
56
- if (!next)
57
- return h;
58
- const doc = applyAll(h.doc, next.steps);
59
- gate(h, doc);
60
- return { ...h, doc, past: h.past.concat(next), future: h.future.slice(1) };
61
- }
62
-
63
- // src/tree/invariants.ts
64
- function invariants(schema, doc) {
65
- const out = [];
66
- out.push(...validateAll(schema, doc));
67
- const ids = /* @__PURE__ */ new Map();
68
- walk(doc, [], schema, out, ids);
69
- return out;
70
- }
71
- function walk(node, path, schema, out, ids) {
72
- if (isText(node)) {
73
- return;
74
- }
75
- if (node.id !== void 0) {
76
- ids.set(node.id, (ids.get(node.id) ?? 0) + 1);
77
- if (ids.get(node.id) === 2) {
78
- out.push({ path, reason: `\u91CD\u590D id "${node.id}"` });
79
- }
80
- }
81
- const spec = schema.nodes[node.type];
82
- if (spec?.atom) {
83
- if (node.type === "image") {
84
- if (!node.attrs?.url)
85
- out.push({ path, reason: `[image] \u7F3A url` });
86
- return;
87
- }
88
- if (node.type === "mention") {
89
- if (!node.attrs?.id)
90
- out.push({ path, reason: `[mention] \u7F3A id` });
91
- return;
92
- }
93
- if (node.type === "math") {
94
- if (typeof node.attrs?.latex !== "string")
95
- out.push({ path, reason: `[math] \u7F3A latex` });
96
- return;
97
- }
98
- if (node.type === "embed") {
99
- if (!node.attrs?.kind)
100
- out.push({ path, reason: `[embed] \u7F3A kind` });
101
- if (!node.attrs?.src)
102
- out.push({ path, reason: `[embed] \u7F3A src` });
103
- return;
104
- }
105
- for (const reason of checkTable(node)) {
106
- out.push({ path, reason: `[table] ${reason}` });
107
- }
108
- return;
109
- }
110
- if (spec?.marks) {
111
- for (let i = 0; i < node.children.length; i++) {
112
- const child = node.children[i];
113
- if (isText(child) && child.marks) {
114
- for (const m of child.marks) {
115
- if (!spec.marks.includes(m.name)) {
116
- out.push({ path: path.concat(i), reason: `${node.type} \u4E0D\u5141\u8BB8 mark "${m.name}"` });
117
- }
118
- }
119
- }
120
- }
121
- }
122
- for (let i = 0; i < node.children.length; i++) {
123
- walk(node.children[i], path.concat(i), schema, out, ids);
124
- }
125
- }
126
- function firstViolation(vs) {
127
- if (vs.length === 0) {
128
- return null;
129
- }
130
- const v = vs[0];
131
- return `${v.path.join(",")}: ${v.reason}`;
132
- }
133
-
134
- // src/tree/toc.ts
135
- function headingText(node) {
136
- let out = "";
137
- for (const c of node.children) {
138
- if (isText(c))
139
- out += c.text;
140
- }
141
- return out;
142
- }
143
- function outline(doc) {
144
- const out = [];
145
- const walk2 = (node, path) => {
146
- if (isText(node))
147
- return;
148
- if (node.type === "heading") {
149
- const level = Math.min(Math.max(Number(node.attrs?.depth ?? 1), 1), 6);
150
- out.push({ level, text: headingText(node), path, id: node.id });
151
- return;
152
- }
153
- for (let i = 0; i < node.children.length; i++)
154
- walk2(node.children[i], path.concat(i));
155
- };
156
- walk2(doc, []);
157
- return out;
158
- }
159
-
160
- // src/tree/comments.ts
161
- function commentIdsInDoc(doc) {
162
- const ids = /* @__PURE__ */ new Set();
163
- const walk2 = (n) => {
164
- if (isText(n)) {
165
- for (const m of n.marks ?? []) {
166
- if (m.name === "comment" && m.attrs?.id != null)
167
- ids.add(String(m.attrs.id));
168
- }
169
- return;
170
- }
171
- if (isElement(n))
172
- for (const c of n.children)
173
- walk2(c);
174
- };
175
- walk2(doc);
176
- return ids;
177
- }
178
- function stripLeaf(leaf, id) {
179
- const rest = (leaf.marks ?? []).filter((m) => !(m.name === "comment" && String(m.attrs?.id) === id));
180
- return rest.length ? { ...leaf, marks: rest } : { text: leaf.text };
181
- }
182
- function stripCommentMarks(doc, id) {
183
- const steps = [];
184
- const walk2 = (node, path) => {
185
- if (node.children.every((c) => isText(c) || isInlineAtom(c))) {
186
- let changed = false;
187
- const children = node.children.map((c) => {
188
- if (!isText(c) || !c.marks?.some((m) => m.name === "comment" && String(m.attrs?.id) === id))
189
- return c;
190
- changed = true;
191
- return stripLeaf(c, id);
192
- });
193
- if (changed)
194
- steps.push({ kind: "replaceNode", path, node: { ...node, children } });
195
- return;
196
- }
197
- node.children.forEach((c, i) => {
198
- if (isElement(c))
199
- walk2(c, path.concat(i));
200
- });
201
- };
202
- doc.children.forEach((c, i) => {
203
- if (isElement(c))
204
- walk2(c, [i]);
205
- });
206
- return steps;
207
- }
208
-
209
- export {
210
- init,
211
- commit,
212
- amend,
213
- undo,
214
- redo,
215
- invariants,
216
- firstViolation,
217
- outline,
218
- commentIdsInDoc,
219
- stripCommentMarks
220
- };