quoin-editor 0.4.2 → 1.0.1

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 (231) hide show
  1. package/CHANGELOG.md +251 -0
  2. package/MIGRATION.md +233 -0
  3. package/README.md +78 -716
  4. package/dist/ai.cjs +1148 -0
  5. package/dist/ai.cjs.map +1 -0
  6. package/dist/ai.d.cts +68 -0
  7. package/dist/ai.d.ts +68 -0
  8. package/dist/ai.js +1148 -0
  9. package/dist/ai.js.map +1 -0
  10. package/dist/catalogue.cjs +59 -0
  11. package/dist/catalogue.cjs.map +1 -0
  12. package/dist/catalogue.d.cts +39 -0
  13. package/dist/catalogue.d.ts +39 -0
  14. package/dist/catalogue.js +59 -0
  15. package/dist/catalogue.js.map +1 -0
  16. package/dist/chunk-26Q4LSIU.js +100 -0
  17. package/dist/chunk-26Q4LSIU.js.map +1 -0
  18. package/dist/chunk-56C7GCKO.cjs +1385 -0
  19. package/dist/chunk-56C7GCKO.cjs.map +1 -0
  20. package/dist/chunk-5M4QG3ZC.cjs +3303 -0
  21. package/dist/chunk-5M4QG3ZC.cjs.map +1 -0
  22. package/dist/chunk-5R3ISX4A.cjs +6643 -0
  23. package/dist/chunk-5R3ISX4A.cjs.map +1 -0
  24. package/dist/chunk-62WKUAQY.js +3335 -0
  25. package/dist/chunk-62WKUAQY.js.map +1 -0
  26. package/dist/chunk-6LMS5J3Y.js +320 -0
  27. package/dist/chunk-6LMS5J3Y.js.map +1 -0
  28. package/dist/chunk-6PKVJZQV.cjs +100 -0
  29. package/dist/chunk-6PKVJZQV.cjs.map +1 -0
  30. package/dist/chunk-6YSGUAVW.js +376 -0
  31. package/dist/chunk-6YSGUAVW.js.map +1 -0
  32. package/dist/chunk-75C6PX2L.cjs +239 -0
  33. package/dist/chunk-75C6PX2L.cjs.map +1 -0
  34. package/dist/chunk-A4IJSJKL.js +598 -0
  35. package/dist/chunk-A4IJSJKL.js.map +1 -0
  36. package/dist/chunk-BTBHHBVR.cjs +3335 -0
  37. package/dist/chunk-BTBHHBVR.cjs.map +1 -0
  38. package/dist/chunk-CLTHD5GO.cjs +34 -0
  39. package/dist/chunk-CLTHD5GO.cjs.map +1 -0
  40. package/dist/chunk-EH5KXQXY.cjs +62 -0
  41. package/dist/chunk-EH5KXQXY.cjs.map +1 -0
  42. package/dist/chunk-ESMAW4NK.cjs +184 -0
  43. package/dist/chunk-ESMAW4NK.cjs.map +1 -0
  44. package/dist/chunk-EYFCOV3T.cjs +30 -0
  45. package/dist/chunk-EYFCOV3T.cjs.map +1 -0
  46. package/dist/chunk-F5V3IEEE.cjs +326 -0
  47. package/dist/chunk-F5V3IEEE.cjs.map +1 -0
  48. package/dist/chunk-GPIDU3GN.js +239 -0
  49. package/dist/chunk-GPIDU3GN.js.map +1 -0
  50. package/dist/chunk-HOIDJEVI.cjs +4063 -0
  51. package/dist/chunk-HOIDJEVI.cjs.map +1 -0
  52. package/dist/chunk-JJ3RASQS.cjs +706 -0
  53. package/dist/chunk-JJ3RASQS.cjs.map +1 -0
  54. package/dist/chunk-LE3F7WIP.js +6643 -0
  55. package/dist/chunk-LE3F7WIP.js.map +1 -0
  56. package/dist/chunk-LE5XMIFJ.cjs +14 -0
  57. package/dist/chunk-LE5XMIFJ.cjs.map +1 -0
  58. package/dist/chunk-LMAEPFTX.js +30 -0
  59. package/dist/chunk-LMAEPFTX.js.map +1 -0
  60. package/dist/chunk-LV6EYPJO.js +34 -0
  61. package/dist/chunk-LV6EYPJO.js.map +1 -0
  62. package/dist/chunk-MLRAVUFG.cjs +376 -0
  63. package/dist/chunk-MLRAVUFG.cjs.map +1 -0
  64. package/dist/chunk-MQUCCSWG.js +14 -0
  65. package/dist/chunk-MQUCCSWG.js.map +1 -0
  66. package/dist/chunk-O4Z2WMFF.js +62 -0
  67. package/dist/chunk-O4Z2WMFF.js.map +1 -0
  68. package/dist/chunk-OCCKQHCY.js +25 -0
  69. package/dist/chunk-OCCKQHCY.js.map +1 -0
  70. package/dist/chunk-PGSS4IOS.js +706 -0
  71. package/dist/chunk-PGSS4IOS.js.map +1 -0
  72. package/dist/chunk-PIWRSX7U.js +562 -0
  73. package/dist/chunk-PIWRSX7U.js.map +1 -0
  74. package/dist/chunk-PX6LZMH4.cjs +598 -0
  75. package/dist/chunk-PX6LZMH4.cjs.map +1 -0
  76. package/dist/chunk-QXG3HWDS.js +184 -0
  77. package/dist/chunk-QXG3HWDS.js.map +1 -0
  78. package/dist/chunk-RQW3P3GH.js +504 -0
  79. package/dist/chunk-RQW3P3GH.js.map +1 -0
  80. package/dist/chunk-SSIRYUCK.js +3303 -0
  81. package/dist/chunk-SSIRYUCK.js.map +1 -0
  82. package/dist/chunk-UBNG5YCG.js +326 -0
  83. package/dist/chunk-UBNG5YCG.js.map +1 -0
  84. package/dist/chunk-UCXLRRWY.js +1385 -0
  85. package/dist/chunk-UCXLRRWY.js.map +1 -0
  86. package/dist/chunk-UDAVVEFC.cjs +562 -0
  87. package/dist/chunk-UDAVVEFC.cjs.map +1 -0
  88. package/dist/chunk-UPSLDTLT.js +4063 -0
  89. package/dist/chunk-UPSLDTLT.js.map +1 -0
  90. package/dist/chunk-UWNZG2SD.cjs +25 -0
  91. package/dist/chunk-UWNZG2SD.cjs.map +1 -0
  92. package/dist/chunk-V3KLMSRO.cjs +504 -0
  93. package/dist/chunk-V3KLMSRO.cjs.map +1 -0
  94. package/dist/chunk-VACTAZWS.cjs +249 -0
  95. package/dist/chunk-VACTAZWS.cjs.map +1 -0
  96. package/dist/chunk-WMN6566P.js +249 -0
  97. package/dist/chunk-WMN6566P.js.map +1 -0
  98. package/dist/chunk-XX5FTPJR.cjs +320 -0
  99. package/dist/chunk-XX5FTPJR.cjs.map +1 -0
  100. package/dist/comments.cjs +1008 -0
  101. package/dist/comments.cjs.map +1 -0
  102. package/dist/comments.d.cts +93 -0
  103. package/dist/comments.d.ts +93 -0
  104. package/dist/comments.js +1008 -0
  105. package/dist/comments.js.map +1 -0
  106. package/dist/diff.cjs +346 -0
  107. package/dist/diff.cjs.map +1 -0
  108. package/dist/diff.d.cts +67 -0
  109. package/dist/diff.d.ts +67 -0
  110. package/dist/diff.js +346 -0
  111. package/dist/diff.js.map +1 -0
  112. package/dist/docx.cjs +874 -0
  113. package/dist/docx.cjs.map +1 -0
  114. package/dist/docx.d.cts +33 -0
  115. package/dist/docx.d.ts +33 -0
  116. package/dist/docx.js +874 -0
  117. package/dist/docx.js.map +1 -0
  118. package/dist/embed-provider-jXwlRmnp.d.cts +19 -0
  119. package/dist/embed-provider-jXwlRmnp.d.ts +19 -0
  120. package/dist/embed.cjs +17 -0
  121. package/dist/embed.cjs.map +1 -0
  122. package/dist/embed.d.cts +56 -0
  123. package/dist/embed.d.ts +56 -0
  124. package/dist/embed.js +17 -0
  125. package/dist/embed.js.map +1 -0
  126. package/dist/emoji-data.cjs +1968 -0
  127. package/dist/emoji-data.cjs.map +1 -0
  128. package/dist/emoji-data.js +1968 -0
  129. package/dist/emoji-data.js.map +1 -0
  130. package/dist/emoji-extension-CmPlRssm.d.ts +46 -0
  131. package/dist/emoji-extension-zJ6F7hW8.d.cts +46 -0
  132. package/dist/emoji.cjs +18 -0
  133. package/dist/emoji.cjs.map +1 -0
  134. package/dist/emoji.d.cts +31 -0
  135. package/dist/emoji.d.ts +31 -0
  136. package/dist/emoji.js +18 -0
  137. package/dist/emoji.js.map +1 -0
  138. package/dist/engine.cjs +119 -0
  139. package/dist/engine.cjs.map +1 -0
  140. package/dist/engine.d.cts +144 -0
  141. package/dist/engine.d.ts +144 -0
  142. package/dist/engine.js +119 -0
  143. package/dist/engine.js.map +1 -0
  144. package/dist/find-extension-BcRyE9K4.d.cts +41 -0
  145. package/dist/find-extension-CmFehyul.d.ts +41 -0
  146. package/dist/find.cjs +20 -0
  147. package/dist/find.cjs.map +1 -0
  148. package/dist/find.d.cts +44 -0
  149. package/dist/find.d.ts +44 -0
  150. package/dist/find.js +20 -0
  151. package/dist/find.js.map +1 -0
  152. package/dist/headless.cjs +151 -518
  153. package/dist/headless.cjs.map +1 -1
  154. package/dist/headless.d.cts +102 -69
  155. package/dist/headless.d.ts +102 -69
  156. package/dist/headless.js +149 -467
  157. package/dist/headless.js.map +1 -1
  158. package/dist/index-CFPmCee4.d.cts +68 -0
  159. package/dist/index-DiCGV60d.d.ts +68 -0
  160. package/dist/index.cjs +183 -2753
  161. package/dist/index.cjs.map +1 -1
  162. package/dist/index.d.cts +345 -253
  163. package/dist/index.d.ts +345 -253
  164. package/dist/index.js +168 -2696
  165. package/dist/index.js.map +1 -1
  166. package/dist/math.cjs +18 -0
  167. package/dist/math.cjs.map +1 -0
  168. package/dist/math.d.cts +49 -0
  169. package/dist/math.d.ts +49 -0
  170. package/dist/math.js +18 -0
  171. package/dist/math.js.map +1 -0
  172. package/dist/mention.cjs +18 -0
  173. package/dist/mention.cjs.map +1 -0
  174. package/dist/mention.d.cts +50 -0
  175. package/dist/mention.d.ts +50 -0
  176. package/dist/mention.js +18 -0
  177. package/dist/mention.js.map +1 -0
  178. package/dist/presence.cjs +562 -0
  179. package/dist/presence.cjs.map +1 -0
  180. package/dist/presence.d.cts +30 -0
  181. package/dist/presence.d.ts +30 -0
  182. package/dist/presence.js +562 -0
  183. package/dist/presence.js.map +1 -0
  184. package/dist/registry-CWBOSAHm.d.cts +121 -0
  185. package/dist/registry-CWBOSAHm.d.ts +121 -0
  186. package/dist/stats-extension-DisOEbbI.d.ts +40 -0
  187. package/dist/stats-extension-Dt1lgP3m.d.cts +40 -0
  188. package/dist/stats.cjs +19 -0
  189. package/dist/stats.cjs.map +1 -0
  190. package/dist/stats.d.cts +19 -0
  191. package/dist/stats.d.ts +19 -0
  192. package/dist/stats.js +19 -0
  193. package/dist/stats.js.map +1 -0
  194. package/dist/styles.css +1 -1
  195. package/dist/table-extension-BTMJnT7J.d.ts +57 -0
  196. package/dist/table-extension-DxZz3jqp.d.cts +57 -0
  197. package/dist/table.cjs +50 -0
  198. package/dist/table.cjs.map +1 -0
  199. package/dist/table.d.cts +57 -0
  200. package/dist/table.d.ts +57 -0
  201. package/dist/table.js +50 -0
  202. package/dist/table.js.map +1 -0
  203. package/dist/to-html-C5t7xyaM.d.ts +21 -0
  204. package/dist/to-html-CNCITCln.d.cts +21 -0
  205. package/dist/toc-extension-CR9U-l6j.d.ts +25 -0
  206. package/dist/toc-extension-DGHywOBv.d.cts +25 -0
  207. package/dist/toc.cjs +18 -0
  208. package/dist/toc.cjs.map +1 -0
  209. package/dist/toc.d.cts +24 -0
  210. package/dist/toc.d.ts +24 -0
  211. package/dist/toc.js +18 -0
  212. package/dist/toc.js.map +1 -0
  213. package/dist/types-C6_QkXzy.d.ts +358 -0
  214. package/dist/types-CJ7Gq3GX.d.cts +358 -0
  215. package/dist/types-DULc8wwg.d.cts +120 -0
  216. package/dist/types-DULc8wwg.d.ts +120 -0
  217. package/dist/view-controller-BD1KwYfE.d.cts +105 -0
  218. package/dist/view-controller-y4cb60ue.d.ts +105 -0
  219. package/dist/view.cjs +23 -0
  220. package/dist/view.cjs.map +1 -0
  221. package/dist/view.d.cts +40 -0
  222. package/dist/view.d.ts +40 -0
  223. package/dist/view.js +23 -0
  224. package/dist/view.js.map +1 -0
  225. package/dist/yjs.cjs +864 -0
  226. package/dist/yjs.cjs.map +1 -0
  227. package/dist/yjs.d.cts +22 -0
  228. package/dist/yjs.d.ts +22 -0
  229. package/dist/yjs.js +864 -0
  230. package/dist/yjs.js.map +1 -0
  231. package/package.json +217 -18
package/dist/yjs.cjs ADDED
@@ -0,0 +1,864 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } 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; }
2
+
3
+
4
+
5
+
6
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+
27
+
28
+
29
+
30
+
31
+
32
+
33
+
34
+ var _chunkMLRAVUFGcjs = require('./chunk-MLRAVUFG.cjs');
35
+
36
+
37
+
38
+
39
+
40
+
41
+
42
+
43
+
44
+
45
+
46
+
47
+
48
+ var _chunkHOIDJEVIcjs = require('./chunk-HOIDJEVI.cjs');
49
+
50
+
51
+ var _chunkXX5FTPJRcjs = require('./chunk-XX5FTPJR.cjs');
52
+
53
+
54
+
55
+
56
+
57
+
58
+
59
+
60
+ var _chunkBTBHHBVRcjs = require('./chunk-BTBHHBVR.cjs');
61
+
62
+ // src/yjs/read-shared.ts
63
+ var _yjs = require('yjs'); var Y = _interopRequireWildcard(_yjs); var Y2 = _interopRequireWildcard(_yjs); var Y3 = _interopRequireWildcard(_yjs);
64
+
65
+ // src/yjs/required-regions.ts
66
+ var noRequiredRegions = () => [];
67
+ function requiredRegions(schema) {
68
+ const known = /* @__PURE__ */ new Map();
69
+ return (type) => {
70
+ let names = known.get(type);
71
+ if (names === void 0) {
72
+ const spec = schema.blocks.get(type);
73
+ names = _optionalChain([spec, 'optionalAccess', _2 => _2.flow]) === "text" ? Object.keys(spec.initial().regions) : [];
74
+ known.set(type, names);
75
+ }
76
+ return names;
77
+ };
78
+ }
79
+
80
+ // src/yjs/read-shared.ts
81
+ function reader(required) {
82
+ const spans = [_chunkMLRAVUFGcjs.emptySpan.call(void 0, )];
83
+ const entries = /* @__PURE__ */ new Map();
84
+ const markers = /* @__PURE__ */ new Map();
85
+ const order = [];
86
+ const held2 = /* @__PURE__ */ new Map();
87
+ const strays = [];
88
+ let span = spans[0];
89
+ let entry = null;
90
+ let open = null;
91
+ let stray = null;
92
+ let clean = true;
93
+ const segFor = (region2, host, at, ops = []) => {
94
+ const seg = { host, region: region2, at, length: 0 };
95
+ host.segs.push(seg);
96
+ held2.set(seg, ops);
97
+ return seg;
98
+ };
99
+ const opened = (region2) => {
100
+ const seg = segFor(region2, span, span.length + 1);
101
+ region2.segs.push(seg);
102
+ return seg;
103
+ };
104
+ function content(op, length) {
105
+ if (open !== null) {
106
+ open.length += length;
107
+ held2.get(open).push(op);
108
+ } else if (span.index === 0 || span.entry !== null) {
109
+ clean = false;
110
+ if (stray === null) {
111
+ stray = { host: span, at: span.length, length: 0, ops: [], after: _nullishCoalesce(order[order.length - 1], () => ( null)) };
112
+ strays.push(stray);
113
+ }
114
+ stray.length += length;
115
+ stray.ops.push(op);
116
+ }
117
+ }
118
+ function marker(map) {
119
+ span = _chunkMLRAVUFGcjs.emptySpan.call(void 0, );
120
+ span.index = spans.length;
121
+ spans.push(span);
122
+ [open, stray] = [null, null];
123
+ const fields = _chunkMLRAVUFGcjs.readMarker.call(void 0, map);
124
+ const kept = fields !== null && !entries.has(fields.id);
125
+ entry = kept ? { id: fields.id, map, span, regions: [], copies: [] } : null;
126
+ if (entry !== null) {
127
+ span.entry = entry;
128
+ entries.set(entry.id, entry);
129
+ markers.set(entry, fields);
130
+ } else {
131
+ clean = false;
132
+ if (fields !== null) {
133
+ span.copyOf = entries.get(fields.id);
134
+ span.copyOf.copies.push(span);
135
+ }
136
+ }
137
+ }
138
+ function embed(value) {
139
+ let name = _chunkMLRAVUFGcjs.regionNameOf.call(void 0, value);
140
+ stray = null;
141
+ const missing = (one) => !entry.regions.some((region2) => region2.name === one);
142
+ if (name !== null && entry !== null) {
143
+ const needed = required(markers.get(entry).type);
144
+ if (needed.length > 0 && !needed.includes(name)) {
145
+ clean = false;
146
+ name = _nullishCoalesce(needed.find(missing), () => ( null));
147
+ }
148
+ if (name !== null && missing(name)) {
149
+ const region2 = { name, entry, segs: [] };
150
+ entry.regions.push(region2);
151
+ order.push(region2);
152
+ open = opened(region2);
153
+ return;
154
+ }
155
+ }
156
+ clean = false;
157
+ if (open !== null) open = opened(open.region);
158
+ }
159
+ return {
160
+ read(op) {
161
+ const { insert } = op;
162
+ if (typeof insert === "string" || _chunkMLRAVUFGcjs.isAtomEmbed.call(void 0, insert)) {
163
+ const length = typeof insert === "string" ? insert.length : 1;
164
+ content(op, length);
165
+ span.length += length;
166
+ return;
167
+ }
168
+ if (insert instanceof Y.Map) marker(insert);
169
+ else embed(insert);
170
+ span.length += 1;
171
+ },
172
+ finish() {
173
+ const leading = [];
174
+ const read = [];
175
+ let unread = false;
176
+ for (const { host, at, length, ops, after } of strays) {
177
+ const region2 = _nullishCoalesce(after, () => ( order[0]));
178
+ unread ||= region2 === void 0;
179
+ if (region2 === void 0) continue;
180
+ const seg = segFor(region2, host, at, ops);
181
+ seg.length = length;
182
+ read.push(seg);
183
+ if (after === null) leading.push(seg);
184
+ else region2.segs.push(seg);
185
+ }
186
+ _optionalChain([order, 'access', _3 => _3[0], 'optionalAccess', _4 => _4.segs, 'access', _5 => _5.unshift, 'call', _6 => _6(...leading)]);
187
+ const blocks = [...entries.values()].map((kept) => {
188
+ const { type, indent, attrs } = markers.get(kept);
189
+ for (const name of required(type)) {
190
+ if (!kept.regions.some((region2) => region2.name === name)) kept.regions.push({ name, entry: kept, segs: [] });
191
+ }
192
+ const inline = (segs) => _chunkMLRAVUFGcjs.inlineOfOps.call(void 0, segs.flatMap((seg) => held2.get(seg)));
193
+ const regions = kept.regions.map(({ name, segs }) => [name, inline(segs)]);
194
+ return { id: kept.id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _7 => _7.toJSON, 'call', _8 => _8()]), () => ( {})), regions: Object.fromEntries(regions) };
195
+ });
196
+ const layout = _chunkMLRAVUFGcjs.createLayout.call(void 0, spans, entries, clean, { read, leading: new Set(leading), unread });
197
+ return { doc: _chunkBTBHHBVRcjs.createDoc.call(void 0, blocks), layout };
198
+ }
199
+ };
200
+ }
201
+ function readShared(text2, required = noRequiredRegions) {
202
+ const read = reader(required);
203
+ for (const op of text2.toDelta()) read.read(op);
204
+ return read.finish();
205
+ }
206
+
207
+ // src/yjs/shared.ts
208
+ function reread(shared) {
209
+ shared.layout = readShared(shared.text, shared.required).layout;
210
+ shared.stale = true;
211
+ }
212
+ function insertContent(shared, region2, offset, inline) {
213
+ if (inline.length === 0) return;
214
+ if (region2.segs.length === 0) return openRegion(shared, region2, inline);
215
+ const { seg, rel } = _chunkMLRAVUFGcjs.pointOf.call(void 0, region2, offset);
216
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, shared.text, _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, inline);
217
+ _chunkMLRAVUFGcjs.grow.call(void 0, shared.layout, seg, rel, _chunkBTBHHBVRcjs.inlineLength.call(void 0, inline));
218
+ }
219
+ function deleteContent(shared, region2, from, to) {
220
+ for (const { seg, rel, length } of _chunkMLRAVUFGcjs.piecesOf.call(void 0, region2, from, to).reverse()) {
221
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, shared.text, _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length);
222
+ _chunkMLRAVUFGcjs.grow.call(void 0, shared.layout, seg, rel, -length);
223
+ }
224
+ }
225
+ function formatContent(shared, region2, from, to, attributes) {
226
+ for (const { seg, rel, length } of _chunkMLRAVUFGcjs.piecesOf.call(void 0, region2, from, to)) {
227
+ shared.text.format(_chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, seg.host) + rel, length, attributes);
228
+ }
229
+ }
230
+ function openRegion(shared, { name, entry }, inline) {
231
+ const at = _chunkMLRAVUFGcjs.spanStart.call(void 0, shared.layout, entry.span) + entry.span.length;
232
+ shared.text.insertEmbed(at, _chunkMLRAVUFGcjs.regionStart.call(void 0, name), {});
233
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, shared.text, at + 1, inline);
234
+ reread(shared);
235
+ }
236
+
237
+ // src/yjs/inline-span.ts
238
+ var units = (inline) => inline.flatMap(
239
+ (node) => node.kind === "text" ? Array.from({ length: node.text.length }, (_, i) => _chunkBTBHHBVRcjs.text.call(void 0, node.text[i], node.marks)) : [node]
240
+ );
241
+ function changedSpan(before, after) {
242
+ const a = units(before);
243
+ const b = units(after);
244
+ let start = 0;
245
+ while (start < a.length && start < b.length && _chunkBTBHHBVRcjs.equalNode.call(void 0, a[start], b[start])) start += 1;
246
+ let end = 0;
247
+ const shared = Math.min(a.length, b.length) - start;
248
+ while (end < shared && _chunkBTBHHBVRcjs.equalNode.call(void 0, a[a.length - 1 - end], b[b.length - 1 - end])) end += 1;
249
+ return { from: start, to: _chunkBTBHHBVRcjs.inlineLength.call(void 0, before) - end, slice: _chunkBTBHHBVRcjs.sliceInline.call(void 0, after, start, _chunkBTBHHBVRcjs.inlineLength.call(void 0, after) - end) };
250
+ }
251
+
252
+ // src/yjs/plain.ts
253
+ function isPlain({ span, regions }) {
254
+ if (span.segs.length !== regions.length) return false;
255
+ let end = 1;
256
+ for (const { segs } of regions) {
257
+ if (segs.length !== 1 || segs[0].host !== span || segs[0].at !== end + 1) return false;
258
+ end = segs[0].at + segs[0].length;
259
+ }
260
+ return span.length === end;
261
+ }
262
+ function rewritten(entry, block, map = entry.map) {
263
+ const next = _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, map);
264
+ next.copies.push(...entry.copies);
265
+ for (const copy of next.copies) copy.copyOf = next;
266
+ return next;
267
+ }
268
+ function crossesStray(layout, index) {
269
+ const { read, leading, unread } = layout.strays;
270
+ return unread || read.some((seg) => {
271
+ const region2 = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, seg.region.entry.span);
272
+ return leading.has(seg) ? index <= region2 : region2 < index && index <= _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, seg.host);
273
+ });
274
+ }
275
+
276
+ // src/yjs/write-blocks.ts
277
+ function insertBlocks(shared, next, blocks) {
278
+ const { layout, text: text2 } = shared;
279
+ const span = next === null ? null : layout.entries.get(next).span;
280
+ const index = span === null ? layout.spans.length : _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span);
281
+ const crosses = blocks.some((block) => Object.keys(block.regions).length > 0) && crossesStray(layout, index);
282
+ const maps = _chunkMLRAVUFGcjs.writeBlocks.call(void 0, text2, span === null ? _chunkMLRAVUFGcjs.textLength.call(void 0, layout) : _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span), blocks);
283
+ if (crosses) reread(shared);
284
+ else _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, index, 0, blocks.map((block, i) => _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, maps[i])));
285
+ }
286
+ function ownParts(entry, span) {
287
+ const parts = [];
288
+ let at = 0;
289
+ const foreign = span.segs.filter((seg) => seg.region.entry !== entry).sort((a, b) => a.at - b.at);
290
+ for (const seg of foreign) {
291
+ if (seg.at > at) parts.push([at, seg.at - at]);
292
+ at = seg.at + seg.length;
293
+ }
294
+ if (span.length > at) parts.push([at, span.length - at]);
295
+ return parts;
296
+ }
297
+ function dropSpans(shared, spans) {
298
+ const { layout, text: text2 } = shared;
299
+ for (const span of [...spans].sort((a, b) => _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, b) - _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, a))) {
300
+ const at = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span);
301
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span), span.length);
302
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, at, 1, []);
303
+ }
304
+ }
305
+ function unreadBefore(layout, span) {
306
+ const before = [];
307
+ for (let at = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, span) - 1; at > 0 && layout.spans[at].entry === null; at--) {
308
+ before.push(layout.spans[at]);
309
+ }
310
+ return before;
311
+ }
312
+ function removeBlock(shared, id) {
313
+ const { layout, text: text2 } = shared;
314
+ const entry = layout.entries.get(id);
315
+ const unread = [...entry.copies, ...unreadBefore(layout, entry.span)];
316
+ if (isPlain(entry)) return dropSpans(shared, [.../* @__PURE__ */ new Set([entry.span, ...unread])]);
317
+ dropSpans(shared, [...new Set(unread)]);
318
+ const ranges = [];
319
+ const start = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, entry.span);
320
+ ranges.push(...ownParts(entry, entry.span).map(([at, length]) => [start + at, length]));
321
+ for (const seg of entry.regions.flatMap((region2) => region2.segs)) {
322
+ if (seg.host !== entry.span) ranges.push([_chunkMLRAVUFGcjs.spanStart.call(void 0, layout, seg.host) + seg.at, seg.length]);
323
+ }
324
+ for (const [at, length] of ranges.sort((a, b) => b[0] - a[0])) if (length > 0) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, length);
325
+ reread(shared);
326
+ }
327
+
328
+ // src/yjs/sync-block.ts
329
+ function syncAttrs(map, before, after) {
330
+ const current = _chunkMLRAVUFGcjs.attrsMap.call(void 0, map, after);
331
+ if (current === null) return;
332
+ const kept = new Map(_chunkMLRAVUFGcjs.definedEntries.call(void 0, after));
333
+ for (const key of [...current.keys()]) if (!kept.has(key)) current.delete(key);
334
+ for (const [key, value] of kept) if (!_chunkXX5FTPJRcjs.sameValue.call(void 0, before[key], value)) current.set(key, value);
335
+ }
336
+ function keptNames(before, after) {
337
+ const kept = /* @__PURE__ */ new Set();
338
+ let from = 0;
339
+ for (const name of after) {
340
+ const at = before.indexOf(name, from);
341
+ if (at < 0) continue;
342
+ kept.add(name);
343
+ from = at + 1;
344
+ }
345
+ return kept;
346
+ }
347
+ function syncRegions(shared, entry, before, after) {
348
+ const { text: text2, layout } = shared;
349
+ const names = Object.keys(after.regions);
350
+ const queue = entry.regions.map(({ name }) => [name, before.regions[name]]);
351
+ const kept = keptNames(queue.map(([name]) => name), names);
352
+ let at = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, entry.span) + 1;
353
+ const dropGone = () => {
354
+ while (queue.length > 0 && !kept.has(queue[0][0])) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 1 + _chunkBTBHHBVRcjs.inlineLength.call(void 0, queue.shift()[1]));
355
+ };
356
+ for (const name of names) {
357
+ dropGone();
358
+ const inline = after.regions[name];
359
+ if (kept.has(name)) {
360
+ const { from, to, slice } = changedSpan(queue.shift()[1], inline);
361
+ if (to > from) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + 1 + from, to - from);
362
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, text2, at + 1 + from, slice);
363
+ } else {
364
+ text2.insertEmbed(at, _chunkMLRAVUFGcjs.regionStart.call(void 0, name), {});
365
+ _chunkMLRAVUFGcjs.insertInline.call(void 0, text2, at + 1, inline);
366
+ }
367
+ at += 1 + _chunkBTBHHBVRcjs.inlineLength.call(void 0, inline);
368
+ }
369
+ dropGone();
370
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, entry.span), 1, [rewritten(entry, after)]);
371
+ }
372
+ function syncBlock(shared, before, after, next) {
373
+ if (before === after) return;
374
+ const entry = shared.layout.entries.get(before.id);
375
+ const plain = isPlain(entry);
376
+ if (!plain && !_chunkXX5FTPJRcjs.sameValue.call(void 0, Object.keys(before.regions), Object.keys(after.regions))) {
377
+ removeBlock(shared, before.id);
378
+ insertBlocks(shared, next, [after]);
379
+ return;
380
+ }
381
+ if (before.type !== after.type) entry.map.set("type", after.type);
382
+ if (before.indent !== after.indent) entry.map.set("indent", after.indent);
383
+ syncAttrs(entry.map, before.attrs, after.attrs);
384
+ if (plain) {
385
+ const gains = Object.keys(before.regions).length === 0 && Object.keys(after.regions).length > 0;
386
+ const crosses = gains && crossesStray(shared.layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, shared.layout, entry.span));
387
+ syncRegions(shared, entry, before, after);
388
+ if (crosses) reread(shared);
389
+ return;
390
+ }
391
+ for (const name of entry.regions.map((region2) => region2.name)) {
392
+ const [was, now] = [before.regions[name], after.regions[name]];
393
+ if (_chunkBTBHHBVRcjs.equalInline.call(void 0, was, now)) continue;
394
+ const { from, to, slice } = changedSpan(was, now);
395
+ const region2 = _chunkMLRAVUFGcjs.regionOf.call(void 0, shared.layout, before.id, name);
396
+ deleteContent(shared, region2, from, to);
397
+ insertContent(shared, region2, from, slice);
398
+ }
399
+ }
400
+
401
+ // src/yjs/sync-docs.ts
402
+ function syncDocs(shared, before, after) {
403
+ const order = before.blocks.map((block) => block.id);
404
+ for (const id of [...order]) {
405
+ if (after.index.has(id)) continue;
406
+ removeBlock(shared, id);
407
+ order.splice(order.indexOf(id), 1);
408
+ }
409
+ after.blocks.forEach((block, i) => {
410
+ if (order[i] === block.id) {
411
+ syncBlock(shared, before.blocks[before.index.get(block.id)], block, _nullishCoalesce(order[i + 1], () => ( null)));
412
+ return;
413
+ }
414
+ const at = order.indexOf(block.id, i);
415
+ if (at > i) {
416
+ removeBlock(shared, block.id);
417
+ order.splice(at, 1);
418
+ }
419
+ insertBlocks(shared, _nullishCoalesce(order[i], () => ( null)), [block]);
420
+ order.splice(i, 0, block.id);
421
+ });
422
+ }
423
+
424
+ // src/yjs/split-join.ts
425
+ var held = (region2) => region2 !== void 0 && region2.segs.length > 0;
426
+ function writeSplit(shared, after, { block, region: region2, offset, created }) {
427
+ const { layout, text: text2 } = shared;
428
+ const entry = layout.entries.get(block);
429
+ const tail = _chunkBTBHHBVRcjs.blockById.call(void 0, after, created.id);
430
+ const last = entry.regions[entry.regions.length - 1];
431
+ if (!held(last) || last.name !== region2 || Object.keys(tail.regions).at(-1) !== created.region) return false;
432
+ const { seg, rel } = _chunkMLRAVUFGcjs.pointOf.call(void 0, last, offset);
433
+ const map = _chunkMLRAVUFGcjs.markerOf.call(void 0, tail);
434
+ _chunkMLRAVUFGcjs.writeBlock.call(void 0, text2, _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, seg.host) + rel, tail, map, created.region);
435
+ if (!isPlain(entry)) {
436
+ reread(shared);
437
+ return true;
438
+ }
439
+ const head = rewritten(entry, _chunkBTBHHBVRcjs.blockById.call(void 0, after, block));
440
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, entry.span), 1, [head, _chunkMLRAVUFGcjs.cleanEntry.call(void 0, tail, map)]);
441
+ return true;
442
+ }
443
+ function writeJoin(shared, after, join2) {
444
+ const { target, targetRegion, source, sourceRegion } = join2;
445
+ const { layout, text: text2 } = shared;
446
+ const [into, from] = [target, source].map((id) => layout.entries.get(id));
447
+ const [end, start] = [into.regions.at(-1), from.regions[0]];
448
+ if (!held(end) || !held(start) || end.name !== targetRegion || start.name !== sourceRegion) return false;
449
+ const between = layout.spans.slice(_chunkMLRAVUFGcjs.indexOf.call(void 0, layout, into.span) + 1, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, from.span));
450
+ dropSpans(shared, [...from.copies, ...between]);
451
+ const at = _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, from.span);
452
+ if (!isPlain(into) || !isPlain(from)) {
453
+ const own = start.segs.find((seg) => seg.host === from.span);
454
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + own.at - 1, 1);
455
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 1);
456
+ reread(shared);
457
+ return true;
458
+ }
459
+ const index = _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, into.span);
460
+ const moved = from.regions[0].segs[0].length;
461
+ const rest = from.span.length - 2 - moved;
462
+ if (rest > 0) _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at + 2 + moved, rest);
463
+ _chunkMLRAVUFGcjs.deleteText.call(void 0, text2, at, 2);
464
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, index, 2, [rewritten(into, _chunkBTBHHBVRcjs.blockById.call(void 0, after, target))]);
465
+ return true;
466
+ }
467
+
468
+ // src/yjs/local-to-yjs.ts
469
+ var region = ({ shared, params }) => _chunkMLRAVUFGcjs.regionOf.call(void 0, shared.layout, params.block, params.region);
470
+ var following = (doc, id) => _nullishCoalesce(_optionalChain([doc, 'access', _9 => _9.blocks, 'access', _10 => _10[doc.index.get(id) + 1], 'optionalAccess', _11 => _11.id]), () => ( null));
471
+ function replaceInline(context) {
472
+ const { from, to, slice } = context.params;
473
+ const target = region(context);
474
+ deleteContent(context.shared, target, from, to);
475
+ insertContent(context.shared, target, from, slice);
476
+ }
477
+ function format(context, keys) {
478
+ const { block, region: name, from, to } = context.params;
479
+ if (to === from) return;
480
+ const inline = _chunkBTBHHBVRcjs.blockById.call(void 0, context.before, block).regions[name];
481
+ formatContent(context.shared, region(context), from, to, keys(_chunkBTBHHBVRcjs.sliceInline.call(void 0, inline, from, to)));
482
+ }
483
+ function removedKeys(mark, inline) {
484
+ if (typeof mark !== "string") return { [_chunkMLRAVUFGcjs.markAttribute.call(void 0, mark)[0]]: null };
485
+ const marks = inline.flatMap((node) => node.marks.filter((candidate) => candidate.type === mark));
486
+ return Object.fromEntries(marks.map((found) => [_chunkMLRAVUFGcjs.markAttribute.call(void 0, found)[0], null]));
487
+ }
488
+ function setAttrs({ shared, after, params }) {
489
+ const id = params.block;
490
+ const { map } = shared.layout.entries.get(id);
491
+ const next = _chunkBTBHHBVRcjs.blockById.call(void 0, after, id).attrs;
492
+ const attrs = _chunkMLRAVUFGcjs.attrsMap.call(void 0, map, next);
493
+ if (attrs === null) return;
494
+ for (const key of Object.keys(params.patch)) {
495
+ if (next[key] === void 0) attrs.delete(key);
496
+ else attrs.set(key, next[key]);
497
+ }
498
+ }
499
+ function moveBlocks({ shared, before, after, params }) {
500
+ const { from, count, to } = params;
501
+ if (count === 0 || from === to) return;
502
+ const moved = before.blocks.slice(from, from + count);
503
+ for (const block of moved) removeBlock(shared, block.id);
504
+ insertBlocks(shared, _nullishCoalesce(_optionalChain([after, 'access', _12 => _12.blocks, 'access', _13 => _13[to + count], 'optionalAccess', _14 => _14.id]), () => ( null)), moved);
505
+ }
506
+ var WRITERS = {
507
+ replaceInline,
508
+ addMark: (context) => format(context, () => Object.fromEntries([_chunkMLRAVUFGcjs.markAttribute.call(void 0, context.params.mark)])),
509
+ removeMark: (context) => format(context, (inline) => removedKeys(context.params.mark, inline)),
510
+ setAttrs,
511
+ setIndent: ({ shared, params }) => shared.layout.entries.get(params.block).map.set("indent", params.indent),
512
+ insertBlocks: ({ shared, before, params }) => insertBlocks(shared, _nullishCoalesce(_optionalChain([before, 'access', _15 => _15.blocks, 'access', _16 => _16[params.index], 'optionalAccess', _17 => _17.id]), () => ( null)), params.blocks),
513
+ removeBlocks: ({ shared, before, params }) => {
514
+ const { index, count } = params;
515
+ for (const block of before.blocks.slice(index, index + count)) removeBlock(shared, block.id);
516
+ },
517
+ moveBlocks,
518
+ splitBlock: (context) => {
519
+ if (!writeSplit(context.shared, context.after, context.params)) {
520
+ syncDocs(context.shared, context.before, context.after);
521
+ }
522
+ },
523
+ joinBlocks: (context) => {
524
+ if (!writeJoin(context.shared, context.after, context.params)) {
525
+ syncDocs(context.shared, context.before, context.after);
526
+ }
527
+ },
528
+ replaceBlock: ({ shared, before, params }) => {
529
+ const block = params.block;
530
+ syncBlock(shared, _chunkBTBHHBVRcjs.blockById.call(void 0, before, block.id), block, following(before, block.id));
531
+ }
532
+ };
533
+ function writeLocalSteps(shared, steps, docs) {
534
+ steps.forEach((step, i) => {
535
+ const [before, after] = [docs[i], docs[i + 1]];
536
+ const writer = WRITERS[step.stepType];
537
+ if (writer === void 0) syncDocs(shared, before, after);
538
+ else writer({ shared, before, after, params: step.toJSON() });
539
+ });
540
+ }
541
+
542
+ // src/yjs/seed.ts
543
+ function seedOrLoad(editor, text2, { origin, seed, required }) {
544
+ const { blocks } = editor.state.doc;
545
+ if (text2.length === 0 && seed === "if-empty") {
546
+ let maps = [];
547
+ text2.doc.transact(() => maps = _chunkMLRAVUFGcjs.writeBlocks.call(void 0, text2, 0, blocks), origin);
548
+ const entries = blocks.map((block, i) => _chunkMLRAVUFGcjs.cleanEntry.call(void 0, block, maps[i]));
549
+ const spans = [_chunkMLRAVUFGcjs.emptySpan.call(void 0, ), ...entries.map((entry) => entry.span)];
550
+ return _chunkMLRAVUFGcjs.createLayout.call(void 0, spans, new Map(entries.map((entry) => [entry.id, entry])), true);
551
+ }
552
+ const { doc, layout } = readShared(text2, required);
553
+ if (!_chunkHOIDJEVIcjs.sameDoc.call(void 0, doc, editor.state.doc)) _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, doc)]);
554
+ return layout;
555
+ }
556
+
557
+ // src/yjs/read-split-join.ts
558
+
559
+ var bare = (op) => op === void 0 || op.attributes === void 0;
560
+ function split(layout, delta, required) {
561
+ const [at, ops] = _optionalChain([delta, 'access', _18 => _18[0], 'optionalAccess', _19 => _19.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
562
+ const map = _optionalChain([ops, 'access', _20 => _20[0], 'optionalAccess', _21 => _21.insert]);
563
+ const name = _chunkMLRAVUFGcjs.regionNameOf.call(void 0, _optionalChain([ops, 'access', _22 => _22[1], 'optionalAccess', _23 => _23.insert]));
564
+ if (ops.length !== 2 || !(map instanceof Y2.Map) || name === null || !bare(delta[0])) return null;
565
+ const marker = _chunkMLRAVUFGcjs.readMarker.call(void 0, map);
566
+ const span = _chunkMLRAVUFGcjs.spanAt.call(void 0, layout, at);
567
+ if (span.entry === null || !isPlain(span.entry)) return null;
568
+ const region2 = span.entry.regions.at(-1);
569
+ const seg = _optionalChain([region2, 'optionalAccess', _24 => _24.segs, 'access', _25 => _25[0]]);
570
+ const rel = at - _chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span);
571
+ if (marker === null || layout.entries.has(marker.id) || seg === void 0) return null;
572
+ if (rel < seg.at || rel > seg.at + seg.length) return null;
573
+ if (required(marker.type).some((needed) => needed !== name)) return null;
574
+ const { id, type, indent, attrs } = marker;
575
+ const created = { id, type, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _26 => _26.toJSON, 'call', _27 => _27()]), () => ( {})), region: name, regions: {} };
576
+ return { step: _chunkHOIDJEVIcjs.splitBlockStep.call(void 0, span.entry.id, region2.name, _chunkMLRAVUFGcjs.offsetIn.call(void 0, seg, rel), created), map };
577
+ }
578
+ function join(layout, delta) {
579
+ const [at, ops] = _optionalChain([delta, 'access', _28 => _28[0], 'optionalAccess', _29 => _29.retain]) === void 0 ? [0, delta] : [delta[0].retain, delta.slice(1)];
580
+ if (ops.length !== 1 || ops[0].delete !== 2 || !bare(delta[0])) return null;
581
+ const span = _chunkMLRAVUFGcjs.spanAt.call(void 0, layout, at, true);
582
+ const source = span.entry;
583
+ const target = _nullishCoalesce(_optionalChain([layout, 'access', _30 => _30.spans, 'access', _31 => _31[span.index - 1], 'optionalAccess', _32 => _32.entry]), () => ( null));
584
+ if (_chunkMLRAVUFGcjs.spanStart.call(void 0, layout, span) !== at || source === null || target === null) return null;
585
+ if (source.regions.length !== 1 || target.regions.length === 0 || source.copies.length > 0) return null;
586
+ if (!isPlain(source) || !isPlain(target)) return null;
587
+ return _chunkHOIDJEVIcjs.joinBlocksStep.call(void 0, target.id, target.regions.at(-1).name, source.id, source.regions[0].name);
588
+ }
589
+ function splitOrJoin(layout, delta, doc, required) {
590
+ const found = split(layout, delta, required);
591
+ const step = _nullishCoalesce(_optionalChain([found, 'optionalAccess', _33 => _33.step]), () => ( join(layout, delta)));
592
+ if (step === null) return null;
593
+ const after = step.apply(doc).doc;
594
+ const { block, target, created } = step.toJSON();
595
+ const kept = layout.entries.get(_nullishCoalesce(block, () => ( target)));
596
+ const entries = [rewritten(kept, _chunkBTBHHBVRcjs.blockById.call(void 0, after, kept.id))];
597
+ if (found !== null) entries.push(_chunkMLRAVUFGcjs.cleanEntry.call(void 0, _chunkBTBHHBVRcjs.blockById.call(void 0, after, created.id), found.map));
598
+ _chunkMLRAVUFGcjs.placeEntries.call(void 0, layout, _chunkMLRAVUFGcjs.indexOf.call(void 0, layout, kept.span), found === null ? 2 : 1, entries);
599
+ return step;
600
+ }
601
+
602
+ // src/yjs/yjs-to-steps.ts
603
+ var REREAD = new Error("reread");
604
+ function markerSteps(shared, event, doc) {
605
+ const target = event.target;
606
+ const marker = target.parent === shared.text ? target : target.parent;
607
+ const fields = _chunkMLRAVUFGcjs.readMarker.call(void 0, marker);
608
+ const block = fields === null ? void 0 : _chunkBTBHHBVRcjs.blockById.call(void 0, doc, fields.id);
609
+ if (block === void 0 || _optionalChain([shared, 'access', _34 => _34.layout, 'access', _35 => _35.entries, 'access', _36 => _36.get, 'call', _37 => _37(block.id), 'optionalAccess', _38 => _38.map]) !== marker) return [];
610
+ const keys = [...event.keysChanged];
611
+ if (target !== marker) {
612
+ if (fields.attrs !== target) return [];
613
+ return [_chunkHOIDJEVIcjs.setAttrsStep.call(void 0, block.id, Object.fromEntries(keys.map((key) => [key, target.get(key)])))];
614
+ }
615
+ if (keys.includes("id") || keys.includes("type")) throw REREAD;
616
+ const { indent, attrs } = fields;
617
+ if (keys.every((key) => key === "indent")) return [_chunkHOIDJEVIcjs.setIndentStep.call(void 0, block.id, indent)];
618
+ return [_chunkHOIDJEVIcjs.replaceBlockStep.call(void 0, { ...block, indent, attrs: _nullishCoalesce(_optionalChain([attrs, 'optionalAccess', _39 => _39.toJSON, 'call', _40 => _40()]), () => ( {})) })];
619
+ }
620
+ function contentSteps(shared, events, doc) {
621
+ const textEvent = events.find((event) => event.target === shared.text);
622
+ const delta = _nullishCoalesce(_optionalChain([textEvent, 'optionalAccess', _41 => _41.delta]), () => ( []));
623
+ const structure = splitOrJoin(shared.layout, delta, doc, shared.required);
624
+ const steps = structure === null ? _chunkMLRAVUFGcjs.textSteps.call(void 0, shared.layout, delta) : [structure];
625
+ if (steps === null) throw REREAD;
626
+ let current = steps.reduce((changed, step) => step.apply(changed).doc, doc);
627
+ for (const event of events) {
628
+ if (event === textEvent) continue;
629
+ for (const step of markerSteps(shared, event, current)) {
630
+ current = step.apply(current).doc;
631
+ steps.push(step);
632
+ }
633
+ }
634
+ return steps;
635
+ }
636
+ function readRemote(shared, events, doc) {
637
+ try {
638
+ return { steps: contentSteps(shared, events, doc), structural: false };
639
+ } catch (error) {
640
+ const read = readShared(shared.text, shared.required);
641
+ shared.layout = read.layout;
642
+ const blocks = read.doc.blocks.map((block) => {
643
+ const held2 = _chunkBTBHHBVRcjs.blockById.call(void 0, doc, block.id);
644
+ return held2 !== void 0 && _chunkXX5FTPJRcjs.sameValue.call(void 0, held2, block) ? held2 : block;
645
+ });
646
+ const next = _chunkBTBHHBVRcjs.createDoc.call(void 0, blocks);
647
+ const failed = error === REREAD ? void 0 : error;
648
+ return { steps: _chunkHOIDJEVIcjs.sameDoc.call(void 0, next, doc) ? [] : [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, next)], structural: true, failed };
649
+ }
650
+ }
651
+
652
+ // src/yjs/binding.ts
653
+ function bind(editor, text2, options) {
654
+ const { origins, seed, onError } = options;
655
+ const doc = text2.doc;
656
+ const required = requiredRegions(editor.state.schema);
657
+ const layout = seedOrLoad(editor, text2, { origin: origins.local, seed, required });
658
+ const history = options.history();
659
+ const shared = { text: text2, layout, stale: false, required };
660
+ const ours = (origin) => origin === origins.local || origin === origins.untracked;
661
+ let held2 = null;
662
+ const written = /* @__PURE__ */ new WeakSet();
663
+ const hold = (transaction) => {
664
+ if (!ours(transaction.origin)) held2 = _chunkMLRAVUFGcjs.holdSelection.call(void 0, text2, shared.layout, editor.state.selection);
665
+ };
666
+ const observer = (events, transaction) => {
667
+ if (ours(transaction.origin)) return;
668
+ const { steps, structural, failed } = readRemote(shared, events, editor.state.doc);
669
+ if (steps.length > 0 && transaction.origin !== history.manager) {
670
+ _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, steps, structural ? _chunkMLRAVUFGcjs.restoreSelection.call(void 0, text2, shared.layout, held2) : null);
671
+ } else if (steps.length > 0) {
672
+ const tr = _chunkMLRAVUFGcjs.sharedChange.call(void 0, editor, steps, history.hint(), "history");
673
+ written.add(tr);
674
+ editor.dispatch(tr);
675
+ }
676
+ if (failed) onError(failed);
677
+ };
678
+ const settle = () => {
679
+ shared.stale = false;
680
+ const read = readShared(text2, required);
681
+ shared.layout = read.layout;
682
+ if (!_chunkHOIDJEVIcjs.sameDoc.call(void 0, read.doc, editor.state.doc)) _chunkMLRAVUFGcjs.applyRemote.call(void 0, editor, [_chunkHOIDJEVIcjs.replaceDocStep.call(void 0, read.doc)]);
683
+ };
684
+ doc.on("beforeTransaction", hold);
685
+ text2.observeDeep(observer);
686
+ return {
687
+ editor,
688
+ shared,
689
+ local(tr) {
690
+ if (written.has(tr)) return;
691
+ history.record(tr);
692
+ if (!tr.docChanged) return;
693
+ const docs = [...tr.docs, tr.doc];
694
+ const origin = tr.addToHistory ? origins.local : origins.untracked;
695
+ doc.transact(() => writeLocalSteps(shared, tr.steps, docs), origin);
696
+ if (shared.stale) settle();
697
+ },
698
+ travel: (direction) => history.travel(direction, editor),
699
+ stop() {
700
+ doc.off("beforeTransaction", hold);
701
+ text2.unobserveDeep(observer);
702
+ }
703
+ };
704
+ }
705
+
706
+ // src/yjs/undo-history.ts
707
+
708
+ var GROUP_DELAY = 500;
709
+ var SELECTION = "selection";
710
+ function undoHistory(text2, origin) {
711
+ const manager = new Y3.UndoManager(text2, { trackedOrigins: /* @__PURE__ */ new Set([origin]), captureTimeout: Infinity });
712
+ let group = null;
713
+ let time = 0;
714
+ let before = null;
715
+ let hint = null;
716
+ manager.on("stack-item-added", ({ stackItem }) => stackItem.meta.set(SELECTION, before));
717
+ return {
718
+ manager,
719
+ record(tr) {
720
+ if (!tr.docChanged) {
721
+ if (tr.getMeta("closeHistory") === true) group = null;
722
+ return;
723
+ }
724
+ const next = _chunkHOIDJEVIcjs.groupOf.call(void 0, tr);
725
+ if (next === null || next !== group || tr.time - time >= GROUP_DELAY) manager.stopCapturing();
726
+ group = next;
727
+ time = tr.time;
728
+ before = tr.before.selection;
729
+ },
730
+ travel(direction, editor) {
731
+ const stack = direction === "undo" ? manager.undoStack : manager.redoStack;
732
+ const item = stack.at(-1);
733
+ if (item === void 0) return false;
734
+ hint = _nullishCoalesce(item.meta.get(SELECTION), () => ( null));
735
+ before = editor.state.selection;
736
+ group = null;
737
+ try {
738
+ return (direction === "undo" ? manager.undo() : manager.redo()) !== null;
739
+ } finally {
740
+ hint = null;
741
+ }
742
+ },
743
+ hint: () => hint
744
+ };
745
+ }
746
+
747
+ // src/yjs/index.ts
748
+ function yjsCollaboration(options) {
749
+ const { doc, field = "quoin", awareness, user, seed = "if-empty" } = options;
750
+ const onError = _nullishCoalesce(options.onError, () => ( ((error) => console.error(error))));
751
+ const text2 = doc.getText(field);
752
+ const origins = { local: { user }, untracked: {} };
753
+ let history;
754
+ let binding = null;
755
+ let disconnects = 0;
756
+ const collaboration = {
757
+ doc,
758
+ text: text2,
759
+ awareness,
760
+ user,
761
+ origin: origins.local,
762
+ connect(editor) {
763
+ if (binding !== null) {
764
+ onError(new Error("A Yjs collaboration connects one editor at a time; this editor stays unconnected."));
765
+ return () => void 0;
766
+ }
767
+ const current = bind(editor, text2, {
768
+ origins,
769
+ seed,
770
+ onError,
771
+ history: () => history ??= undoHistory(text2, origins.local)
772
+ });
773
+ binding = current;
774
+ return () => {
775
+ current.stop();
776
+ if (binding === current) binding = null;
777
+ const at = ++disconnects;
778
+ setTimeout(() => {
779
+ if (binding !== null || at !== disconnects) return;
780
+ _optionalChain([history, 'optionalAccess', _42 => _42.manager, 'access', _43 => _43.destroy, 'call', _44 => _44()]);
781
+ history = void 0;
782
+ }, 16);
783
+ };
784
+ },
785
+ onLocalTransaction: (tr, state) => {
786
+ if (_optionalChain([binding, 'optionalAccess', _45 => _45.editor, 'access', _46 => _46.state]) === state) binding.local(tr);
787
+ },
788
+ history: {
789
+ undo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _47 => _47.travel, 'call', _48 => _48("undo")]), () => ( false)),
790
+ redo: () => _nullishCoalesce(_optionalChain([binding, 'optionalAccess', _49 => _49.travel, 'call', _50 => _50("redo")]), () => ( false)),
791
+ canUndo: () => binding !== null && history.manager.canUndo(),
792
+ canRedo: () => binding !== null && history.manager.canRedo()
793
+ }
794
+ };
795
+ _chunkMLRAVUFGcjs.holdBinding.call(void 0, collaboration, () => binding);
796
+ return collaboration;
797
+ }
798
+
799
+ // src/engine/collab/collaboration-link.ts
800
+ var linkKey = _chunkHOIDJEVIcjs.createPluginKey.call(void 0, "collaborationLink");
801
+ var linkPlugin = {
802
+ key: linkKey,
803
+ init: () => ({ mounts: 0, disconnect: null, warned: false }),
804
+ apply: (_tr, link) => link
805
+ };
806
+ var linkOf = (state) => _chunkHOIDJEVIcjs.getPluginState.call(void 0, state, linkKey);
807
+
808
+ // src/engine/collab/warn-host-blocks.ts
809
+ function warnHostBlocks() {
810
+ if (typeof process !== "undefined" && _optionalChain([process, 'optionalAccess', _51 => _51.env, 'optionalAccess', _52 => _52.NODE_ENV]) === "production") return;
811
+ console.warn(
812
+ "Quoin: blocks were supplied to a collaborative editor and ignored, since the shared document holds its content. Supply its starting blocks once and keep the ones it emits."
813
+ );
814
+ }
815
+
816
+ // src/engine/collab/collaboration-extension.ts
817
+ var providerKey = _chunkHOIDJEVIcjs.createPluginKey.call(void 0, _chunkHOIDJEVIcjs.HISTORY_PROVIDER);
818
+ function providing(history) {
819
+ const provider = {
820
+ undo: (dryRun) => dryRun ? history.canUndo() : history.undo(),
821
+ redo: (dryRun) => dryRun ? history.canRedo() : history.redo()
822
+ };
823
+ return { key: providerKey, init: () => provider, apply: (_tr, value) => value };
824
+ }
825
+ function collaborationExtension(adapter) {
826
+ const { history } = adapter;
827
+ return _chunkHOIDJEVIcjs.defineExtension.call(void 0, {
828
+ name: "collaboration",
829
+ plugins: history === void 0 ? [linkPlugin] : [linkPlugin, providing(history)],
830
+ onMount(editor) {
831
+ const link = linkOf(editor.state);
832
+ link.mounts += 1;
833
+ if (link.mounts === 1) {
834
+ try {
835
+ link.disconnect = adapter.connect(editor);
836
+ } catch (error) {
837
+ link.mounts = 0;
838
+ throw error;
839
+ }
840
+ }
841
+ return () => {
842
+ link.mounts -= 1;
843
+ if (link.mounts === 0) _optionalChain([link, 'access', _53 => _53.disconnect, 'optionalCall', _54 => _54()]);
844
+ };
845
+ },
846
+ onTransaction(tr, state) {
847
+ const local = tr.origin !== "remote" && tr.origin !== "reconcile";
848
+ if (local && linkOf(state).mounts > 0) adapter.onLocalTransaction(tr, state);
849
+ },
850
+ filterHostBlocks(_blocks, state) {
851
+ const link = linkOf(state);
852
+ if (link.mounts === 0) return true;
853
+ if (!link.warned) warnHostBlocks();
854
+ link.warned = true;
855
+ return false;
856
+ }
857
+ });
858
+ }
859
+
860
+
861
+
862
+
863
+ exports.applyRemote = _chunkMLRAVUFGcjs.applyRemote; exports.collaborationExtension = collaborationExtension; exports.yjsCollaboration = yjsCollaboration;
864
+ //# sourceMappingURL=yjs.cjs.map