@b9g/revise 0.1.3 → 0.1.4

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.
@@ -0,0 +1,649 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/contentarea.ts
21
+ var contentarea_exports = {};
22
+ __export(contentarea_exports, {
23
+ ContentAreaElement: () => ContentAreaElement,
24
+ ContentEvent: () => ContentEvent
25
+ });
26
+ module.exports = __toCommonJS(contentarea_exports);
27
+ var import_edit = require("./edit.cjs");
28
+ var _cache = Symbol.for("ContentArea._cache");
29
+ var _observer = Symbol.for("ContentArea._observer");
30
+ var _onselectionchange = Symbol.for("ContentArea._onselectionchange");
31
+ var _value = Symbol.for("ContentArea._value");
32
+ var _selectionRange = Symbol.for("ContentArea._selectionRange");
33
+ var _staleValue = Symbol.for("ContentArea._staleValue");
34
+ var _staleSelectionRange = Symbol.for("ContentArea._slateSelectionRange");
35
+ var _compositionBuffer = Symbol.for("ContentArea._compositionBuffer");
36
+ var _compositionStartValue = Symbol.for("ContentArea._compositionStartValue");
37
+ var _compositionSelectionRange = Symbol.for(
38
+ "ContentArea._compositionSelectionRange"
39
+ );
40
+ var ContentAreaElement = class extends HTMLElement {
41
+ constructor() {
42
+ super();
43
+ this[_cache] = /* @__PURE__ */ new Map();
44
+ this[_observer] = new MutationObserver((records) => {
45
+ if (this[_compositionBuffer]) {
46
+ this[_compositionBuffer].push(...records);
47
+ }
48
+ validate(this, records);
49
+ });
50
+ this[_onselectionchange] = () => {
51
+ this[_selectionRange] = getSelectionRange(this);
52
+ };
53
+ this[_value] = "";
54
+ this[_selectionRange] = { start: 0, end: 0, direction: "none" };
55
+ this[_staleValue] = void 0;
56
+ this[_staleSelectionRange] = void 0;
57
+ this[_compositionBuffer] = void 0;
58
+ this[_compositionStartValue] = void 0;
59
+ this[_compositionSelectionRange] = void 0;
60
+ }
61
+ /******************************/
62
+ /*** Custom Element methods ***/
63
+ /******************************/
64
+ connectedCallback() {
65
+ this[_observer].observe(this, {
66
+ subtree: true,
67
+ childList: true,
68
+ characterData: true,
69
+ characterDataOldValue: true,
70
+ attributes: true,
71
+ attributeOldValue: true,
72
+ attributeFilter: [
73
+ "data-content"
74
+ // TODO: implement these attributes
75
+ //"data-contentbefore",
76
+ //"data-contentafter",
77
+ ]
78
+ });
79
+ document.addEventListener(
80
+ "selectionchange",
81
+ this[_onselectionchange],
82
+ // We use capture in an attempt to run before other event listeners.
83
+ true
84
+ );
85
+ validate(this);
86
+ this[_onselectionchange]();
87
+ let processCompositionTimeout;
88
+ this.addEventListener("compositionstart", () => {
89
+ clearTimeout(processCompositionTimeout);
90
+ if (processCompositionTimeout == null) {
91
+ this[_compositionBuffer] = [];
92
+ this[_compositionStartValue] = this[_value];
93
+ this[_compositionSelectionRange] = { ...this[_selectionRange] };
94
+ }
95
+ processCompositionTimeout = void 0;
96
+ });
97
+ const processComposition = () => {
98
+ if (this[_compositionBuffer] && this[_compositionBuffer].length > 0 && this[_compositionStartValue] !== void 0 && this[_compositionSelectionRange] !== void 0) {
99
+ const edit = import_edit.Edit.diff(
100
+ this[_compositionStartValue],
101
+ this[_value],
102
+ this[_compositionSelectionRange].start
103
+ );
104
+ const ev = new ContentEvent("contentchange", {
105
+ detail: { edit, source: null, mutations: this[_compositionBuffer] }
106
+ });
107
+ this.dispatchEvent(ev);
108
+ this[_staleValue] = void 0;
109
+ this[_staleSelectionRange] = void 0;
110
+ }
111
+ this[_compositionBuffer] = void 0;
112
+ this[_compositionStartValue] = void 0;
113
+ this[_compositionSelectionRange] = void 0;
114
+ processCompositionTimeout = void 0;
115
+ };
116
+ this.addEventListener("compositionend", () => {
117
+ clearTimeout(processCompositionTimeout);
118
+ processCompositionTimeout = setTimeout(processComposition);
119
+ });
120
+ this.addEventListener("blur", () => {
121
+ clearTimeout(processCompositionTimeout);
122
+ processComposition();
123
+ });
124
+ this.addEventListener("keydown", (e) => {
125
+ if (e.key === "Escape" && this[_compositionBuffer]) {
126
+ clearTimeout(processCompositionTimeout);
127
+ processComposition();
128
+ }
129
+ });
130
+ }
131
+ disconnectedCallback() {
132
+ this[_cache].clear();
133
+ this[_value] = "";
134
+ this[_observer].disconnect();
135
+ if (document) {
136
+ document.removeEventListener(
137
+ "selectionchange",
138
+ this[_onselectionchange],
139
+ true
140
+ );
141
+ }
142
+ }
143
+ get value() {
144
+ validate(this);
145
+ return this[_staleValue] == null ? this[_value] : this[_staleValue];
146
+ }
147
+ get selectionStart() {
148
+ validate(this);
149
+ const range = this[_staleSelectionRange] || this[_selectionRange];
150
+ return range.start;
151
+ }
152
+ set selectionStart(start) {
153
+ validate(this);
154
+ const { end, direction } = getSelectionRange(this);
155
+ setSelectionRange(this, { start, end, direction });
156
+ }
157
+ get selectionEnd() {
158
+ validate(this);
159
+ const range = this[_staleSelectionRange] || this[_selectionRange];
160
+ return range.end;
161
+ }
162
+ set selectionEnd(end) {
163
+ validate(this);
164
+ const { start, direction } = getSelectionRange(this);
165
+ setSelectionRange(this, { start, end, direction });
166
+ }
167
+ get selectionDirection() {
168
+ validate(this);
169
+ const range = this[_staleSelectionRange] || this[_selectionRange];
170
+ return range.direction;
171
+ }
172
+ set selectionDirection(direction) {
173
+ validate(this);
174
+ const { start, end } = getSelectionRange(this);
175
+ setSelectionRange(this, { start, end, direction });
176
+ }
177
+ getSelectionRange() {
178
+ validate(this);
179
+ const range = this[_staleSelectionRange] || this[_selectionRange];
180
+ return { ...range };
181
+ }
182
+ setSelectionRange(start, end, direction = "none") {
183
+ validate(this);
184
+ setSelectionRange(this, { start, end, direction });
185
+ }
186
+ indexAt(node, offset) {
187
+ validate(this);
188
+ return indexAt(this, node, offset);
189
+ }
190
+ nodeOffsetAt(index) {
191
+ validate(this);
192
+ return nodeOffsetAt(this, index);
193
+ }
194
+ source(source) {
195
+ return validate(this, this[_observer].takeRecords(), source);
196
+ }
197
+ };
198
+ var PreventDefaultSource = Symbol.for("ContentArea.PreventDefaultSource");
199
+ var ContentEvent = class extends CustomEvent {
200
+ constructor(typeArg, eventInit) {
201
+ super(typeArg, { bubbles: true, ...eventInit });
202
+ }
203
+ preventDefault() {
204
+ if (this.defaultPrevented) {
205
+ return;
206
+ }
207
+ super.preventDefault();
208
+ const area = this.target;
209
+ area[_staleValue] = area[_value];
210
+ area[_staleSelectionRange] = area[_selectionRange];
211
+ const records = this.detail.mutations;
212
+ for (let i = records.length - 1; i >= 0; i--) {
213
+ const record = records[i];
214
+ switch (record.type) {
215
+ case "childList": {
216
+ for (let j = 0; j < record.addedNodes.length; j++) {
217
+ const node = record.addedNodes[j];
218
+ if (node.parentNode) {
219
+ node.parentNode.removeChild(node);
220
+ }
221
+ }
222
+ for (let j = 0; j < record.removedNodes.length; j++) {
223
+ const node = record.removedNodes[j];
224
+ record.target.insertBefore(node, record.nextSibling);
225
+ }
226
+ break;
227
+ }
228
+ case "characterData": {
229
+ if (record.oldValue !== null) {
230
+ record.target.data = record.oldValue;
231
+ }
232
+ break;
233
+ }
234
+ case "attributes": {
235
+ if (record.oldValue === null) {
236
+ record.target.removeAttribute(record.attributeName);
237
+ } else {
238
+ record.target.setAttribute(
239
+ record.attributeName,
240
+ record.oldValue
241
+ );
242
+ }
243
+ break;
244
+ }
245
+ }
246
+ }
247
+ const records1 = area[_observer].takeRecords();
248
+ validate(area, records1, PreventDefaultSource);
249
+ }
250
+ };
251
+ var IS_OLD = 1 << 0;
252
+ var IS_VALID = 1 << 1;
253
+ var IS_BLOCKLIKE = 1 << 2;
254
+ var PREPENDS_NEWLINE = 1 << 3;
255
+ var APPENDS_NEWLINE = 1 << 4;
256
+ var NodeInfo = class {
257
+ constructor(offset) {
258
+ this.f = 0;
259
+ this.offset = offset;
260
+ this.length = 0;
261
+ }
262
+ };
263
+ function validate(_this, records = _this[_observer].takeRecords(), source = null) {
264
+ if (typeof _this !== "object" || _this[_cache] == null) {
265
+ throw new TypeError("this is not a ContentAreaElement");
266
+ } else if (!document.contains(_this)) {
267
+ throw new Error(
268
+ "ContentArea cannot be read before it is inserted into the DOM"
269
+ );
270
+ }
271
+ if (!invalidate(_this, records)) {
272
+ return false;
273
+ }
274
+ const oldValue = _this[_value];
275
+ const edit = diff(_this, oldValue, _this[_selectionRange].start);
276
+ _this[_value] = edit.apply(oldValue);
277
+ _this[_selectionRange] = getSelectionRange(_this);
278
+ if (source !== PreventDefaultSource && !_this[_compositionBuffer]) {
279
+ const ev = new ContentEvent("contentchange", {
280
+ detail: { edit, source, mutations: records }
281
+ });
282
+ _this.dispatchEvent(ev);
283
+ _this[_staleValue] = void 0;
284
+ _this[_staleSelectionRange] = void 0;
285
+ }
286
+ return true;
287
+ }
288
+ function invalidate(_this, records) {
289
+ const cache = _this[_cache];
290
+ if (!cache.get(_this)) {
291
+ return true;
292
+ }
293
+ let invalid = false;
294
+ for (let i = 0; i < records.length; i++) {
295
+ const record = records[i];
296
+ for (let j = 0; j < record.addedNodes.length; j++) {
297
+ const addedNode = record.addedNodes[j];
298
+ clear(addedNode, cache);
299
+ }
300
+ for (let j = 0; j < record.removedNodes.length; j++) {
301
+ clear(record.removedNodes[j], cache);
302
+ }
303
+ let node = record.target;
304
+ if (node === _this) {
305
+ invalid = true;
306
+ continue;
307
+ } else if (!_this.contains(node)) {
308
+ clear(node, cache);
309
+ continue;
310
+ }
311
+ for (; node !== _this; node = node.parentNode) {
312
+ if (!cache.has(node)) {
313
+ break;
314
+ }
315
+ const nodeInfo = cache.get(node);
316
+ if (nodeInfo) {
317
+ nodeInfo.f &= ~IS_VALID;
318
+ }
319
+ invalid = true;
320
+ }
321
+ }
322
+ if (invalid) {
323
+ const nodeInfo = cache.get(_this);
324
+ nodeInfo.f &= ~IS_VALID;
325
+ }
326
+ return invalid;
327
+ }
328
+ function clear(parent, cache) {
329
+ const walker = document.createTreeWalker(
330
+ parent,
331
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT
332
+ );
333
+ for (let node = parent; node !== null; node = walker.nextNode()) {
334
+ cache.delete(node);
335
+ }
336
+ }
337
+ var NEWLINE = "\n";
338
+ function diff(_this, oldValue, oldSelectionStart) {
339
+ const walker = document.createTreeWalker(
340
+ _this,
341
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT
342
+ );
343
+ const cache = _this[_cache];
344
+ const stack = [];
345
+ let nodeInfo;
346
+ let value = "";
347
+ for (let node = _this, descending = true, offset = 0, oldIndex = 0, oldIndexRelative = 0, hasNewline = false; ; node = walker.currentNode) {
348
+ if (descending) {
349
+ nodeInfo = cache.get(node);
350
+ if (nodeInfo === void 0) {
351
+ cache.set(node, nodeInfo = new NodeInfo(offset));
352
+ if (isBlocklikeElement(node)) {
353
+ nodeInfo.f |= IS_BLOCKLIKE;
354
+ }
355
+ } else {
356
+ const expectedOffset = oldIndex - oldIndexRelative;
357
+ const deleteLength = nodeInfo.offset - expectedOffset;
358
+ if (deleteLength < 0) {
359
+ throw new Error("cache offset error");
360
+ } else if (deleteLength > 0) {
361
+ oldIndex += deleteLength;
362
+ }
363
+ nodeInfo.offset = offset;
364
+ }
365
+ if (offset && !hasNewline && nodeInfo.f & IS_BLOCKLIKE) {
366
+ hasNewline = true;
367
+ offset += NEWLINE.length;
368
+ value += NEWLINE;
369
+ if (nodeInfo.f & PREPENDS_NEWLINE) {
370
+ oldIndex += NEWLINE.length;
371
+ }
372
+ nodeInfo.f |= PREPENDS_NEWLINE;
373
+ } else {
374
+ if (nodeInfo.f & PREPENDS_NEWLINE) {
375
+ oldIndex += NEWLINE.length;
376
+ }
377
+ nodeInfo.f &= ~PREPENDS_NEWLINE;
378
+ }
379
+ descending = false;
380
+ if (nodeInfo.f & IS_VALID) {
381
+ if (nodeInfo.length) {
382
+ value += oldValue.slice(oldIndex, oldIndex + nodeInfo.length);
383
+ oldIndex += nodeInfo.length;
384
+ offset += nodeInfo.length;
385
+ hasNewline = oldValue.slice(Math.max(0, oldIndex - NEWLINE.length), oldIndex) === NEWLINE;
386
+ }
387
+ } else if (node.nodeType === Node.TEXT_NODE) {
388
+ const text = node.data;
389
+ if (text.length) {
390
+ value += text;
391
+ offset += text.length;
392
+ hasNewline = text.endsWith(NEWLINE);
393
+ }
394
+ if (nodeInfo.f & IS_OLD) {
395
+ oldIndex += nodeInfo.length;
396
+ }
397
+ } else if (node.hasAttribute("data-content")) {
398
+ const text = node.getAttribute("data-content") || "";
399
+ if (text.length) {
400
+ value += text;
401
+ offset += text.length;
402
+ hasNewline = text.endsWith(NEWLINE);
403
+ }
404
+ if (nodeInfo.f & IS_OLD) {
405
+ oldIndex += nodeInfo.length;
406
+ }
407
+ } else if (node.nodeName === "BR") {
408
+ value += NEWLINE;
409
+ offset += NEWLINE.length;
410
+ hasNewline = true;
411
+ if (nodeInfo.f & IS_OLD) {
412
+ oldIndex += nodeInfo.length;
413
+ }
414
+ } else {
415
+ descending = !!walker.firstChild();
416
+ if (descending) {
417
+ stack.push({ nodeInfo, oldIndexRelative });
418
+ offset = 0;
419
+ oldIndexRelative = oldIndex;
420
+ }
421
+ }
422
+ } else {
423
+ if (!stack.length) {
424
+ throw new Error("Stack is empty");
425
+ }
426
+ if (nodeInfo.f & PREPENDS_NEWLINE) {
427
+ offset += NEWLINE.length;
428
+ }
429
+ ({ nodeInfo, oldIndexRelative } = stack.pop());
430
+ offset = nodeInfo.offset + offset;
431
+ }
432
+ if (!descending) {
433
+ if (!(nodeInfo.f & IS_VALID)) {
434
+ if (!hasNewline && nodeInfo.f & IS_BLOCKLIKE) {
435
+ value += NEWLINE;
436
+ offset += NEWLINE.length;
437
+ hasNewline = true;
438
+ nodeInfo.f |= APPENDS_NEWLINE;
439
+ } else {
440
+ nodeInfo.f &= ~APPENDS_NEWLINE;
441
+ }
442
+ nodeInfo.length = offset - nodeInfo.offset;
443
+ nodeInfo.f |= IS_VALID;
444
+ }
445
+ nodeInfo.f |= IS_OLD;
446
+ descending = !!walker.nextSibling();
447
+ if (!descending) {
448
+ if (walker.currentNode === _this) {
449
+ break;
450
+ }
451
+ walker.parentNode();
452
+ }
453
+ }
454
+ if (oldIndex > oldValue.length) {
455
+ throw new Error("cache length error");
456
+ }
457
+ }
458
+ const selectionStart = getSelectionRange(_this).start;
459
+ return import_edit.Edit.diff(
460
+ oldValue,
461
+ value,
462
+ Math.min(oldSelectionStart, selectionStart)
463
+ );
464
+ }
465
+ var BLOCKLIKE_DISPLAYS = /* @__PURE__ */ new Set([
466
+ "block",
467
+ "flex",
468
+ "grid",
469
+ "flow-root",
470
+ "list-item",
471
+ "table",
472
+ "table-row-group",
473
+ "table-header-group",
474
+ "table-footer-group",
475
+ "table-row",
476
+ "table-caption"
477
+ ]);
478
+ function isBlocklikeElement(node) {
479
+ return node.nodeType === Node.ELEMENT_NODE && BLOCKLIKE_DISPLAYS.has(
480
+ // handle two-value display syntax like `display: block flex`
481
+ getComputedStyle(node).display.split(" ")[0]
482
+ );
483
+ }
484
+ function indexAt(_this, node, offset) {
485
+ const cache = _this[_cache];
486
+ if (node == null || !_this.contains(node)) {
487
+ return -1;
488
+ }
489
+ if (!cache.has(node)) {
490
+ offset = 0;
491
+ while (!cache.has(node)) {
492
+ node = node.parentNode;
493
+ }
494
+ }
495
+ let index;
496
+ if (node.nodeType === Node.TEXT_NODE) {
497
+ const nodeInfo = cache.get(node);
498
+ index = offset + nodeInfo.offset;
499
+ node = node.parentNode;
500
+ } else {
501
+ if (offset <= 0) {
502
+ index = 0;
503
+ } else if (offset >= node.childNodes.length) {
504
+ const nodeInfo = cache.get(node);
505
+ index = nodeInfo.f & APPENDS_NEWLINE ? nodeInfo.length - NEWLINE.length : nodeInfo.length;
506
+ } else {
507
+ let child = node.childNodes[offset];
508
+ while (child !== null && !cache.has(child)) {
509
+ child = child.previousSibling;
510
+ }
511
+ if (child === null) {
512
+ index = 0;
513
+ } else {
514
+ node = child;
515
+ const nodeInfo = cache.get(node);
516
+ index = nodeInfo.f & PREPENDS_NEWLINE ? -1 : 0;
517
+ }
518
+ }
519
+ }
520
+ for (; node !== _this; node = node.parentNode) {
521
+ const nodeInfo = cache.get(node);
522
+ index += nodeInfo.offset;
523
+ if (nodeInfo.f & PREPENDS_NEWLINE) {
524
+ index += NEWLINE.length;
525
+ }
526
+ }
527
+ return index;
528
+ }
529
+ function nodeOffsetAt(_this, index) {
530
+ if (index < 0) {
531
+ return [null, 0];
532
+ }
533
+ const [node, offset] = findNodeOffset(_this, index);
534
+ if (node && node.nodeName === "BR") {
535
+ return nodeOffsetFromChild(node);
536
+ }
537
+ return [node, offset];
538
+ }
539
+ function findNodeOffset(_this, index) {
540
+ const cache = _this[_cache];
541
+ const walker = document.createTreeWalker(
542
+ _this,
543
+ NodeFilter.SHOW_TEXT | NodeFilter.SHOW_ELEMENT
544
+ );
545
+ for (let node2 = _this; node2 !== null; ) {
546
+ const nodeInfo = cache.get(node2);
547
+ if (nodeInfo == null) {
548
+ return nodeOffsetFromChild(node2, index > 0);
549
+ }
550
+ if (nodeInfo.f & PREPENDS_NEWLINE) {
551
+ index -= 1;
552
+ }
553
+ if (index === nodeInfo.length && node2.nodeType === Node.TEXT_NODE) {
554
+ return [node2, node2.data.length];
555
+ } else if (index >= nodeInfo.length) {
556
+ index -= nodeInfo.length;
557
+ const nextSibling = walker.nextSibling();
558
+ if (nextSibling === null) {
559
+ if (node2 === _this) {
560
+ return [node2, getNodeLength(node2)];
561
+ }
562
+ return nodeOffsetFromChild(walker.currentNode, true);
563
+ }
564
+ node2 = nextSibling;
565
+ } else {
566
+ if (node2.nodeType === Node.ELEMENT_NODE && node2.hasAttribute("data-content")) {
567
+ return nodeOffsetFromChild(node2, index > 0);
568
+ }
569
+ const firstChild = walker.firstChild();
570
+ if (firstChild === null) {
571
+ const offset = node2.nodeType === Node.TEXT_NODE ? index : index > 0 ? 1 : 0;
572
+ return [node2, offset];
573
+ } else {
574
+ node2 = firstChild;
575
+ }
576
+ }
577
+ }
578
+ const node = walker.currentNode;
579
+ return [node, getNodeLength(node)];
580
+ }
581
+ function getNodeLength(node) {
582
+ if (node.nodeType === Node.TEXT_NODE) {
583
+ return node.data.length;
584
+ }
585
+ return node.childNodes.length;
586
+ }
587
+ function nodeOffsetFromChild(node, after = false) {
588
+ const parentNode = node.parentNode;
589
+ if (parentNode === null) {
590
+ return [null, 0];
591
+ }
592
+ let offset = Array.from(parentNode.childNodes).indexOf(node);
593
+ if (after) {
594
+ offset++;
595
+ }
596
+ return [parentNode, offset];
597
+ }
598
+ function getSelectionRange(_this) {
599
+ const selection = document.getSelection();
600
+ if (!selection) {
601
+ return { start: 0, end: 0, direction: "none" };
602
+ }
603
+ const { focusNode, focusOffset, anchorNode, anchorOffset, isCollapsed } = selection;
604
+ const focus = Math.max(0, indexAt(_this, focusNode, focusOffset));
605
+ const anchor = isCollapsed ? focus : Math.max(0, indexAt(_this, anchorNode, anchorOffset));
606
+ return {
607
+ start: Math.min(focus, anchor),
608
+ end: Math.max(focus, anchor),
609
+ direction: focus < anchor ? "backward" : focus > anchor ? "forward" : "none"
610
+ };
611
+ }
612
+ function setSelectionRange(_this, { start, end, direction }) {
613
+ const selection = document.getSelection();
614
+ if (!selection) {
615
+ return;
616
+ }
617
+ start = Math.max(0, start || 0);
618
+ end = Math.max(0, end || 0);
619
+ if (end < start) {
620
+ start = end;
621
+ }
622
+ const [focus, anchor] = direction === "backward" ? [start, end] : [end, start];
623
+ if (focus === anchor) {
624
+ const [node, offset] = nodeOffsetAt(_this, focus);
625
+ selection.collapse(node, offset);
626
+ } else {
627
+ const [anchorNode, anchorOffset] = nodeOffsetAt(_this, anchor);
628
+ const [focusNode, focusOffset] = nodeOffsetAt(_this, focus);
629
+ if (anchorNode === null && focusNode === null) {
630
+ selection.collapse(null);
631
+ } else if (anchorNode === null) {
632
+ selection.collapse(focusNode, focusOffset);
633
+ } else if (focusNode === null) {
634
+ selection.collapse(anchorNode, anchorOffset);
635
+ } else {
636
+ selection.setBaseAndExtent(
637
+ anchorNode,
638
+ anchorOffset,
639
+ focusNode,
640
+ focusOffset
641
+ );
642
+ }
643
+ }
644
+ }
645
+ // Annotate the CommonJS export names for ESM import in node:
646
+ 0 && (module.exports = {
647
+ ContentAreaElement,
648
+ ContentEvent
649
+ });