@rcarls/rc-textarea 0.6.0 → 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.
@@ -1,15 +1,15 @@
1
- import { css as Lt, LitElement as st, html as Tt } from "lit";
2
- import { property as b, query as tt } from "lit/decorators.js";
3
- import { NativeChildController as kt } from "@rcarls/rc-common";
4
- var d = /* @__PURE__ */ ((n) => (n[n.TYPE = 3] = "TYPE", n[n.LEVEL = 12] = "LEVEL", n[n.ATTRIBUTE = 13] = "ATTRIBUTE", n[n.BLOT = 14] = "BLOT", n[n.INLINE = 7] = "INLINE", n[n.BLOCK = 11] = "BLOCK", n[n.BLOCK_BLOT = 10] = "BLOCK_BLOT", n[n.INLINE_BLOT = 6] = "INLINE_BLOT", n[n.BLOCK_ATTRIBUTE = 9] = "BLOCK_ATTRIBUTE", n[n.INLINE_ATTRIBUTE = 5] = "INLINE_ATTRIBUTE", n[n.ANY = 15] = "ANY", n))(d || {});
5
- class T {
1
+ import { css as Ut, LitElement as ct, html as Vt } from "lit";
2
+ import { property as N, query as rt } from "lit/decorators.js";
3
+ import { NativeChildController as qt, FlowController as Wt, LocaleController as Kt, resolveFlow as V, numberFormat as Gt, cssZoom as jt, logicalRect as ht, isPhysicalReversed as Xt } from "@rcarls/rc-common";
4
+ var p = /* @__PURE__ */ ((r) => (r[r.TYPE = 3] = "TYPE", r[r.LEVEL = 12] = "LEVEL", r[r.ATTRIBUTE = 13] = "ATTRIBUTE", r[r.BLOT = 14] = "BLOT", r[r.INLINE = 7] = "INLINE", r[r.BLOCK = 11] = "BLOCK", r[r.BLOCK_BLOT = 10] = "BLOCK_BLOT", r[r.INLINE_BLOT = 6] = "INLINE_BLOT", r[r.BLOCK_ATTRIBUTE = 9] = "BLOCK_ATTRIBUTE", r[r.INLINE_ATTRIBUTE = 5] = "INLINE_ATTRIBUTE", r[r.ANY = 15] = "ANY", r))(p || {});
5
+ class D {
6
6
  constructor(t, e, s = {}) {
7
7
  this.attrName = t, this.keyName = e;
8
- const i = d.TYPE & d.ATTRIBUTE;
8
+ const i = p.TYPE & p.ATTRIBUTE;
9
9
  this.scope = s.scope != null ? (
10
10
  // Ignore type bits, force attribute bit
11
- s.scope & d.LEVEL | i
12
- ) : d.ATTRIBUTE, s.whitelist != null && (this.whitelist = s.whitelist);
11
+ s.scope & p.LEVEL | i
12
+ ) : p.ATTRIBUTE, s.whitelist != null && (this.whitelist = s.whitelist);
13
13
  }
14
14
  static keys(t) {
15
15
  return Array.from(t.attributes).map((e) => e.name);
@@ -28,12 +28,12 @@ class T {
28
28
  return this.canAdd(t, e) && e ? e : "";
29
29
  }
30
30
  }
31
- class O extends Error {
31
+ class T extends Error {
32
32
  constructor(t) {
33
33
  t = "[Parchment] " + t, super(t), this.message = t, this.name = this.constructor.name;
34
34
  }
35
35
  }
36
- const ut = class X {
36
+ const Et = class tt {
37
37
  constructor() {
38
38
  this.attributes = {}, this.classes = {}, this.tags = {}, this.types = {};
39
39
  }
@@ -56,40 +56,40 @@ const ut = class X {
56
56
  create(t, e, s) {
57
57
  const i = this.query(e);
58
58
  if (i == null)
59
- throw new O(`Unable to create ${e} blot`);
60
- const r = i, o = (
59
+ throw new T(`Unable to create ${e} blot`);
60
+ const n = i, o = (
61
61
  // @ts-expect-error Fix me later
62
- e instanceof Node || e.nodeType === Node.TEXT_NODE ? e : r.create(s)
63
- ), a = new r(t, o, s);
64
- return X.blots.set(a.domNode, a), a;
62
+ e instanceof Node || e.nodeType === Node.TEXT_NODE ? e : n.create(s)
63
+ ), a = new n(t, o, s);
64
+ return tt.blots.set(a.domNode, a), a;
65
65
  }
66
66
  find(t, e = !1) {
67
- return X.find(t, e);
67
+ return tt.find(t, e);
68
68
  }
69
- query(t, e = d.ANY) {
69
+ query(t, e = p.ANY) {
70
70
  let s;
71
- return typeof t == "string" ? s = this.types[t] || this.attributes[t] : t instanceof Text || t.nodeType === Node.TEXT_NODE ? s = this.types.text : typeof t == "number" ? t & d.LEVEL & d.BLOCK ? s = this.types.block : t & d.LEVEL & d.INLINE && (s = this.types.inline) : t instanceof Element && ((t.getAttribute("class") || "").split(/\s+/).some((i) => (s = this.classes[i], !!s)), s = s || this.tags[t.tagName]), s == null ? null : "scope" in s && e & d.LEVEL & s.scope && e & d.TYPE & s.scope ? s : null;
71
+ return typeof t == "string" ? s = this.types[t] || this.attributes[t] : t instanceof Text || t.nodeType === Node.TEXT_NODE ? s = this.types.text : typeof t == "number" ? t & p.LEVEL & p.BLOCK ? s = this.types.block : t & p.LEVEL & p.INLINE && (s = this.types.inline) : t instanceof Element && ((t.getAttribute("class") || "").split(/\s+/).some((i) => (s = this.classes[i], !!s)), s = s || this.tags[t.tagName]), s == null ? null : "scope" in s && e & p.LEVEL & s.scope && e & p.TYPE & s.scope ? s : null;
72
72
  }
73
73
  register(...t) {
74
74
  return t.map((e) => {
75
75
  const s = "blotName" in e, i = "attrName" in e;
76
76
  if (!s && !i)
77
- throw new O("Invalid definition");
77
+ throw new T("Invalid definition");
78
78
  if (s && e.blotName === "abstract")
79
- throw new O("Cannot register abstract class");
80
- const r = s ? e.blotName : i ? e.attrName : void 0;
81
- return this.types[r] = e, i ? typeof e.keyName == "string" && (this.attributes[e.keyName] = e) : s && (e.className && (this.classes[e.className] = e), e.tagName && (Array.isArray(e.tagName) ? e.tagName = e.tagName.map((o) => o.toUpperCase()) : e.tagName = e.tagName.toUpperCase(), (Array.isArray(e.tagName) ? e.tagName : [e.tagName]).forEach((o) => {
79
+ throw new T("Cannot register abstract class");
80
+ const n = s ? e.blotName : i ? e.attrName : void 0;
81
+ return this.types[n] = e, i ? typeof e.keyName == "string" && (this.attributes[e.keyName] = e) : s && (e.className && (this.classes[e.className] = e), e.tagName && (Array.isArray(e.tagName) ? e.tagName = e.tagName.map((o) => o.toUpperCase()) : e.tagName = e.tagName.toUpperCase(), (Array.isArray(e.tagName) ? e.tagName : [e.tagName]).forEach((o) => {
82
82
  (this.tags[o] == null || e.className == null) && (this.tags[o] = e);
83
83
  }))), e;
84
84
  });
85
85
  }
86
86
  };
87
- ut.blots = /* @__PURE__ */ new WeakMap();
88
- let z = ut;
89
- function it(n, t) {
90
- return (n.getAttribute("class") || "").split(/\s+/).filter((e) => e.indexOf(`${t}-`) === 0);
87
+ Et.blots = /* @__PURE__ */ new WeakMap();
88
+ let q = Et;
89
+ function ut(r, t) {
90
+ return (r.getAttribute("class") || "").split(/\s+/).filter((e) => e.indexOf(`${t}-`) === 0);
91
91
  }
92
- class Bt extends T {
92
+ class Yt extends D {
93
93
  static keys(t) {
94
94
  return (t.getAttribute("class") || "").split(/\s+/).map((e) => e.split("-").slice(0, -1).join("-"));
95
95
  }
@@ -97,37 +97,37 @@ class Bt extends T {
97
97
  return this.canAdd(t, e) ? (this.remove(t), t.classList.add(`${this.keyName}-${e}`), !0) : !1;
98
98
  }
99
99
  remove(t) {
100
- it(t, this.keyName).forEach((e) => {
100
+ ut(t, this.keyName).forEach((e) => {
101
101
  t.classList.remove(e);
102
102
  }), t.classList.length === 0 && t.removeAttribute("class");
103
103
  }
104
104
  value(t) {
105
- const e = (it(t, this.keyName)[0] || "").slice(this.keyName.length + 1);
105
+ const e = (ut(t, this.keyName)[0] || "").slice(this.keyName.length + 1);
106
106
  return this.canAdd(t, e) ? e : "";
107
107
  }
108
108
  }
109
- const Dt = Bt;
110
- function F(n) {
111
- const t = n.split("-"), e = t.slice(1).map((s) => s[0].toUpperCase() + s.slice(1)).join("");
109
+ const Zt = Yt;
110
+ function Z(r) {
111
+ const t = r.split("-"), e = t.slice(1).map((s) => s[0].toUpperCase() + s.slice(1)).join("");
112
112
  return t[0] + e;
113
113
  }
114
- class It extends T {
114
+ class Jt extends D {
115
115
  static keys(t) {
116
116
  return (t.getAttribute("style") || "").split(";").map((e) => e.split(":")[0].trim());
117
117
  }
118
118
  add(t, e) {
119
- return this.canAdd(t, e) ? (t.style[F(this.keyName)] = e, !0) : !1;
119
+ return this.canAdd(t, e) ? (t.style[Z(this.keyName)] = e, !0) : !1;
120
120
  }
121
121
  remove(t) {
122
- t.style[F(this.keyName)] = "", t.getAttribute("style") || t.removeAttribute("style");
122
+ t.style[Z(this.keyName)] = "", t.getAttribute("style") || t.removeAttribute("style");
123
123
  }
124
124
  value(t) {
125
- const e = t.style[F(this.keyName)];
125
+ const e = t.style[Z(this.keyName)];
126
126
  return this.canAdd(t, e) ? e : "";
127
127
  }
128
128
  }
129
- const Rt = It;
130
- class $t {
129
+ const Qt = Jt;
130
+ class te {
131
131
  constructor(t) {
132
132
  this.attributes = {}, this.domNode = t, this.build();
133
133
  }
@@ -136,13 +136,13 @@ class $t {
136
136
  }
137
137
  build() {
138
138
  this.attributes = {};
139
- const t = z.find(this.domNode);
139
+ const t = q.find(this.domNode);
140
140
  if (t == null)
141
141
  return;
142
- const e = T.keys(this.domNode), s = Dt.keys(this.domNode), i = Rt.keys(this.domNode);
143
- e.concat(s).concat(i).forEach((r) => {
144
- const o = t.scroll.query(r, d.ATTRIBUTE);
145
- o instanceof T && (this.attributes[o.attrName] = o);
142
+ const e = D.keys(this.domNode), s = Zt.keys(this.domNode), i = Qt.keys(this.domNode);
143
+ e.concat(s).concat(i).forEach((n) => {
144
+ const o = t.scroll.query(n, p.ATTRIBUTE);
145
+ o instanceof D && (this.attributes[o.attrName] = o);
146
146
  });
147
147
  }
148
148
  copy(t) {
@@ -163,13 +163,13 @@ class $t {
163
163
  );
164
164
  }
165
165
  }
166
- const dt = $t, ft = class {
166
+ const Ct = te, At = class {
167
167
  constructor(t, e) {
168
- this.scroll = t, this.domNode = e, z.blots.set(e, this), this.prev = null, this.next = null;
168
+ this.scroll = t, this.domNode = e, q.blots.set(e, this), this.prev = null, this.next = null;
169
169
  }
170
170
  static create(t) {
171
171
  if (this.tagName == null)
172
- throw new O("Blot definition missing tagName");
172
+ throw new T("Blot definition missing tagName");
173
173
  let e, s;
174
174
  return Array.isArray(this.tagName) ? (typeof t == "string" ? (s = t.toUpperCase(), parseInt(s, 10).toString() === s && (s = parseInt(s, 10))) : typeof t == "number" && (s = t), typeof s == "number" ? e = document.createElement(this.tagName[s - 1]) : s && this.tagName.indexOf(s) > -1 ? e = document.createElement(s) : e = document.createElement(this.tagName[0])) : e = document.createElement(this.tagName), this.className && e.classList.add(this.className), e;
175
175
  }
@@ -184,23 +184,23 @@ const dt = $t, ft = class {
184
184
  return this.scroll.create(t);
185
185
  }
186
186
  detach() {
187
- this.parent != null && this.parent.removeChild(this), z.blots.delete(this.domNode);
187
+ this.parent != null && this.parent.removeChild(this), q.blots.delete(this.domNode);
188
188
  }
189
189
  deleteAt(t, e) {
190
190
  this.isolate(t, e).remove();
191
191
  }
192
192
  formatAt(t, e, s, i) {
193
- const r = this.isolate(t, e);
194
- if (this.scroll.query(s, d.BLOT) != null && i)
195
- r.wrap(s, i);
196
- else if (this.scroll.query(s, d.ATTRIBUTE) != null) {
193
+ const n = this.isolate(t, e);
194
+ if (this.scroll.query(s, p.BLOT) != null && i)
195
+ n.wrap(s, i);
196
+ else if (this.scroll.query(s, p.ATTRIBUTE) != null) {
197
197
  const o = this.scroll.create(this.statics.scope);
198
- r.wrap(o), o.format(s, i);
198
+ n.wrap(o), o.format(s, i);
199
199
  }
200
200
  }
201
201
  insertAt(t, e, s) {
202
- const i = s == null ? this.scroll.create("text", e) : this.scroll.create(e, s), r = this.split(t);
203
- this.parent.insertBefore(i, r || void 0);
202
+ const i = s == null ? this.scroll.create("text", e) : this.scroll.create(e, s), n = this.split(t);
203
+ this.parent.insertBefore(i, n || void 0);
204
204
  }
205
205
  isolate(t, e) {
206
206
  const s = this.split(t);
@@ -232,13 +232,13 @@ const dt = $t, ft = class {
232
232
  wrap(t, e) {
233
233
  const s = typeof t == "string" ? this.scroll.create(t, e) : t;
234
234
  if (this.parent != null && this.parent.insertBefore(s, this.next || void 0), typeof s.appendChild != "function")
235
- throw new O(`Cannot wrap ${t}`);
235
+ throw new T(`Cannot wrap ${t}`);
236
236
  return s.appendChild(this), s;
237
237
  }
238
238
  };
239
- ft.blotName = "abstract";
240
- let pt = ft;
241
- const mt = class extends pt {
239
+ At.blotName = "abstract";
240
+ let Ot = At;
241
+ const Lt = class extends Ot {
242
242
  /**
243
243
  * Returns the value represented by domNode if it is this Blot's type
244
244
  * No checking that domNode can represent this Blot type is required so
@@ -273,10 +273,10 @@ const mt = class extends pt {
273
273
  };
274
274
  }
275
275
  };
276
- mt.scope = d.INLINE_BLOT;
277
- let Pt = mt;
278
- const q = Pt;
279
- class Mt {
276
+ Lt.scope = p.INLINE_BLOT;
277
+ let ee = Lt;
278
+ const X = ee;
279
+ class se {
280
280
  constructor() {
281
281
  this.head = null, this.tail = null, this.length = 0;
282
282
  }
@@ -338,10 +338,10 @@ class Mt {
338
338
  const s = this.iterator();
339
339
  let i = s();
340
340
  for (; i; ) {
341
- const r = i.length();
342
- if (t < r || e && t === r && (i.next == null || i.next.length() !== 0))
341
+ const n = i.length();
342
+ if (t < n || e && t === n && (i.next == null || i.next.length() !== 0))
343
343
  return [i, t];
344
- t -= r, i = s();
344
+ t -= n, i = s();
345
345
  }
346
346
  return [null, 0];
347
347
  }
@@ -354,17 +354,17 @@ class Mt {
354
354
  forEachAt(t, e, s) {
355
355
  if (e <= 0)
356
356
  return;
357
- const [i, r] = this.find(t);
358
- let o = t - r;
357
+ const [i, n] = this.find(t);
358
+ let o = t - n;
359
359
  const a = this.iterator(i);
360
360
  let l = a();
361
361
  for (; l && o < t + e; ) {
362
- const h = l.length();
362
+ const c = l.length();
363
363
  t > o ? s(
364
364
  l,
365
365
  t - o,
366
- Math.min(e, o + h - t)
367
- ) : s(l, 0, Math.min(h, t + e - o)), o += h, l = a();
366
+ Math.min(e, o + c - t)
367
+ ) : s(l, 0, Math.min(c, t + e - o)), o += c, l = a();
368
368
  }
369
369
  }
370
370
  map(t) {
@@ -378,20 +378,20 @@ class Mt {
378
378
  return e;
379
379
  }
380
380
  }
381
- function rt(n, t) {
382
- const e = t.find(n);
381
+ function dt(r, t) {
382
+ const e = t.find(r);
383
383
  if (e)
384
384
  return e;
385
385
  try {
386
- return t.create(n);
386
+ return t.create(r);
387
387
  } catch {
388
- const s = t.create(d.INLINE);
389
- return Array.from(n.childNodes).forEach((i) => {
388
+ const s = t.create(p.INLINE);
389
+ return Array.from(r.childNodes).forEach((i) => {
390
390
  s.domNode.appendChild(i);
391
- }), n.parentNode && n.parentNode.replaceChild(s.domNode, n), s.attach(), s;
391
+ }), r.parentNode && r.parentNode.replaceChild(s.domNode, r), s.attach(), s;
392
392
  }
393
393
  }
394
- const gt = class N extends pt {
394
+ const St = class x extends Ot {
395
395
  constructor(t, e) {
396
396
  super(t, e), this.uiNode = null, this.build();
397
397
  }
@@ -404,18 +404,18 @@ const gt = class N extends pt {
404
404
  });
405
405
  }
406
406
  attachUI(t) {
407
- this.uiNode != null && this.uiNode.remove(), this.uiNode = t, N.uiClass && this.uiNode.classList.add(N.uiClass), this.uiNode.setAttribute("contenteditable", "false"), this.domNode.insertBefore(this.uiNode, this.domNode.firstChild);
407
+ this.uiNode != null && this.uiNode.remove(), this.uiNode = t, x.uiClass && this.uiNode.classList.add(x.uiClass), this.uiNode.setAttribute("contenteditable", "false"), this.domNode.insertBefore(this.uiNode, this.domNode.firstChild);
408
408
  }
409
409
  /**
410
410
  * Called during construction, should fill its own children LinkedList.
411
411
  */
412
412
  build() {
413
- this.children = new Mt(), Array.from(this.domNode.childNodes).filter((t) => t !== this.uiNode).reverse().forEach((t) => {
413
+ this.children = new se(), Array.from(this.domNode.childNodes).filter((t) => t !== this.uiNode).reverse().forEach((t) => {
414
414
  try {
415
- const e = rt(t, this.scroll);
415
+ const e = dt(t, this.scroll);
416
416
  this.insertBefore(e, this.children.head || void 0);
417
417
  } catch (e) {
418
- if (e instanceof O)
418
+ if (e instanceof T)
419
419
  return;
420
420
  throw e;
421
421
  }
@@ -424,23 +424,23 @@ const gt = class N extends pt {
424
424
  deleteAt(t, e) {
425
425
  if (t === 0 && e === this.length())
426
426
  return this.remove();
427
- this.children.forEachAt(t, e, (s, i, r) => {
428
- s.deleteAt(i, r);
427
+ this.children.forEachAt(t, e, (s, i, n) => {
428
+ s.deleteAt(i, n);
429
429
  });
430
430
  }
431
431
  descendant(t, e = 0) {
432
432
  const [s, i] = this.children.find(e);
433
- return t.blotName == null && t(s) || t.blotName != null && s instanceof t ? [s, i] : s instanceof N ? s.descendant(t, i) : [null, -1];
433
+ return t.blotName == null && t(s) || t.blotName != null && s instanceof t ? [s, i] : s instanceof x ? s.descendant(t, i) : [null, -1];
434
434
  }
435
435
  descendants(t, e = 0, s = Number.MAX_VALUE) {
436
- let i = [], r = s;
436
+ let i = [], n = s;
437
437
  return this.children.forEachAt(
438
438
  e,
439
439
  s,
440
440
  (o, a, l) => {
441
- (t.blotName == null && t(o) || t.blotName != null && o instanceof t) && i.push(o), o instanceof N && (i = i.concat(
442
- o.descendants(t, a, r)
443
- )), r -= l;
441
+ (t.blotName == null && t(o) || t.blotName != null && o instanceof t) && i.push(o), o instanceof x && (i = i.concat(
442
+ o.descendants(t, a, n)
443
+ )), n -= l;
444
444
  }
445
445
  ), i;
446
446
  }
@@ -454,18 +454,18 @@ const gt = class N extends pt {
454
454
  this.children.forEach((e) => {
455
455
  t || this.statics.allowedChildren.some(
456
456
  (s) => e instanceof s
457
- ) || (e.statics.scope === d.BLOCK_BLOT ? (e.next != null && this.splitAfter(e), e.prev != null && this.splitAfter(e.prev), e.parent.unwrap(), t = !0) : e instanceof N ? e.unwrap() : e.remove());
457
+ ) || (e.statics.scope === p.BLOCK_BLOT ? (e.next != null && this.splitAfter(e), e.prev != null && this.splitAfter(e.prev), e.parent.unwrap(), t = !0) : e instanceof x ? e.unwrap() : e.remove());
458
458
  });
459
459
  }
460
460
  formatAt(t, e, s, i) {
461
- this.children.forEachAt(t, e, (r, o, a) => {
462
- r.formatAt(o, a, s, i);
461
+ this.children.forEachAt(t, e, (n, o, a) => {
462
+ n.formatAt(o, a, s, i);
463
463
  });
464
464
  }
465
465
  insertAt(t, e, s) {
466
- const [i, r] = this.children.find(t);
466
+ const [i, n] = this.children.find(t);
467
467
  if (i)
468
- i.insertAt(r, e, s);
468
+ i.insertAt(n, e, s);
469
469
  else {
470
470
  const o = s == null ? this.scroll.create("text", e) : this.scroll.create(e, s);
471
471
  this.appendChild(o);
@@ -493,15 +493,15 @@ const gt = class N extends pt {
493
493
  this.remove();
494
494
  }
495
495
  path(t, e = !1) {
496
- const [s, i] = this.children.find(t, e), r = [[this, t]];
497
- return s instanceof N ? r.concat(s.path(i, e)) : (s != null && r.push([s, i]), r);
496
+ const [s, i] = this.children.find(t, e), n = [[this, t]];
497
+ return s instanceof x ? n.concat(s.path(i, e)) : (s != null && n.push([s, i]), n);
498
498
  }
499
499
  removeChild(t) {
500
500
  this.children.remove(t);
501
501
  }
502
502
  replaceWith(t, e) {
503
503
  const s = typeof t == "string" ? this.scroll.create(t, e) : t;
504
- return s instanceof N && this.moveChildren(s), super.replaceWith(s);
504
+ return s instanceof x && this.moveChildren(s), super.replaceWith(s);
505
505
  }
506
506
  split(t, e = !1) {
507
507
  if (!e) {
@@ -511,8 +511,8 @@ const gt = class N extends pt {
511
511
  return this.next;
512
512
  }
513
513
  const s = this.clone();
514
- return this.parent && this.parent.insertBefore(s, this.next || void 0), this.children.forEachAt(t, this.length(), (i, r, o) => {
515
- const a = i.split(r, e);
514
+ return this.parent && this.parent.insertBefore(s, this.next || void 0), this.children.forEachAt(t, this.length(), (i, n, o) => {
515
+ const a = i.split(n, e);
516
516
  a != null && s.appendChild(a);
517
517
  }), s;
518
518
  }
@@ -527,39 +527,39 @@ const gt = class N extends pt {
527
527
  }
528
528
  update(t, e) {
529
529
  const s = [], i = [];
530
- t.forEach((r) => {
531
- r.target === this.domNode && r.type === "childList" && (s.push(...r.addedNodes), i.push(...r.removedNodes));
532
- }), i.forEach((r) => {
533
- if (r.parentNode != null && // @ts-expect-error Fix me later
534
- r.tagName !== "IFRAME" && document.body.compareDocumentPosition(r) & Node.DOCUMENT_POSITION_CONTAINED_BY)
530
+ t.forEach((n) => {
531
+ n.target === this.domNode && n.type === "childList" && (s.push(...n.addedNodes), i.push(...n.removedNodes));
532
+ }), i.forEach((n) => {
533
+ if (n.parentNode != null && // @ts-expect-error Fix me later
534
+ n.tagName !== "IFRAME" && document.body.compareDocumentPosition(n) & Node.DOCUMENT_POSITION_CONTAINED_BY)
535
535
  return;
536
- const o = this.scroll.find(r);
536
+ const o = this.scroll.find(n);
537
537
  o != null && (o.domNode.parentNode == null || o.domNode.parentNode === this.domNode) && o.detach();
538
- }), s.filter((r) => r.parentNode === this.domNode && r !== this.uiNode).sort((r, o) => r === o ? 0 : r.compareDocumentPosition(o) & Node.DOCUMENT_POSITION_FOLLOWING ? 1 : -1).forEach((r) => {
538
+ }), s.filter((n) => n.parentNode === this.domNode && n !== this.uiNode).sort((n, o) => n === o ? 0 : n.compareDocumentPosition(o) & Node.DOCUMENT_POSITION_FOLLOWING ? 1 : -1).forEach((n) => {
539
539
  let o = null;
540
- r.nextSibling != null && (o = this.scroll.find(r.nextSibling));
541
- const a = rt(r, this.scroll);
540
+ n.nextSibling != null && (o = this.scroll.find(n.nextSibling));
541
+ const a = dt(n, this.scroll);
542
542
  (a.next !== o || a.next == null) && (a.parent != null && a.parent.removeChild(this), this.insertBefore(a, o || void 0));
543
543
  }), this.enforceAllowedChildren();
544
544
  }
545
545
  };
546
- gt.uiClass = "";
547
- let zt = gt;
548
- const L = zt;
549
- function Ut(n, t) {
550
- if (Object.keys(n).length !== Object.keys(t).length)
546
+ St.uiClass = "";
547
+ let ie = St;
548
+ const B = ie;
549
+ function ne(r, t) {
550
+ if (Object.keys(r).length !== Object.keys(t).length)
551
551
  return !1;
552
- for (const e in n)
553
- if (n[e] !== t[e])
552
+ for (const e in r)
553
+ if (r[e] !== t[e])
554
554
  return !1;
555
555
  return !0;
556
556
  }
557
- const E = class C extends L {
557
+ const O = class L extends B {
558
558
  static create(t) {
559
559
  return super.create(t);
560
560
  }
561
561
  static formats(t, e) {
562
- const s = e.query(C.blotName);
562
+ const s = e.query(L.blotName);
563
563
  if (!(s != null && t.tagName === s.tagName)) {
564
564
  if (typeof this.tagName == "string")
565
565
  return !0;
@@ -568,18 +568,18 @@ const E = class C extends L {
568
568
  }
569
569
  }
570
570
  constructor(t, e) {
571
- super(t, e), this.attributes = new dt(this.domNode);
571
+ super(t, e), this.attributes = new Ct(this.domNode);
572
572
  }
573
573
  format(t, e) {
574
574
  if (t === this.statics.blotName && !e)
575
575
  this.children.forEach((s) => {
576
- s instanceof C || (s = s.wrap(C.blotName, !0)), this.attributes.copy(s);
576
+ s instanceof L || (s = s.wrap(L.blotName, !0)), this.attributes.copy(s);
577
577
  }), this.unwrap();
578
578
  else {
579
- const s = this.scroll.query(t, d.INLINE);
579
+ const s = this.scroll.query(t, p.INLINE);
580
580
  if (s == null)
581
581
  return;
582
- s instanceof T ? this.attributes.attribute(s, e) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e);
582
+ s instanceof D ? this.attributes.attribute(s, e) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e);
583
583
  }
584
584
  }
585
585
  formats() {
@@ -587,7 +587,7 @@ const E = class C extends L {
587
587
  return e != null && (t[this.statics.blotName] = e), t;
588
588
  }
589
589
  formatAt(t, e, s, i) {
590
- this.formats()[s] != null || this.scroll.query(s, d.ATTRIBUTE) ? this.isolate(t, e).format(s, i) : super.formatAt(t, e, s, i);
590
+ this.formats()[s] != null || this.scroll.query(s, p.ATTRIBUTE) ? this.isolate(t, e).format(s, i) : super.formatAt(t, e, s, i);
591
591
  }
592
592
  optimize(t) {
593
593
  super.optimize(t);
@@ -595,7 +595,7 @@ const E = class C extends L {
595
595
  if (Object.keys(e).length === 0)
596
596
  return this.unwrap();
597
597
  const s = this.next;
598
- s instanceof C && s.prev === this && Ut(e, s.formats()) && (s.moveChildren(this), s.remove());
598
+ s instanceof L && s.prev === this && ne(e, s.formats()) && (s.moveChildren(this), s.remove());
599
599
  }
600
600
  replaceWith(t, e) {
601
601
  const s = super.replaceWith(t, e);
@@ -608,17 +608,17 @@ const E = class C extends L {
608
608
  }
609
609
  wrap(t, e) {
610
610
  const s = super.wrap(t, e);
611
- return s instanceof C && this.attributes.move(s), s;
611
+ return s instanceof L && this.attributes.move(s), s;
612
612
  }
613
613
  };
614
- E.allowedChildren = [E, q], E.blotName = "inline", E.scope = d.INLINE_BLOT, E.tagName = "SPAN";
615
- let Ht = E;
616
- const _t = Ht, A = class Y extends L {
614
+ O.allowedChildren = [O, X], O.blotName = "inline", O.scope = p.INLINE_BLOT, O.tagName = "SPAN";
615
+ let re = O;
616
+ const kt = re, S = class et extends B {
617
617
  static create(t) {
618
618
  return super.create(t);
619
619
  }
620
620
  static formats(t, e) {
621
- const s = e.query(Y.blotName);
621
+ const s = e.query(et.blotName);
622
622
  if (!(s != null && t.tagName === s.tagName)) {
623
623
  if (typeof this.tagName == "string")
624
624
  return !0;
@@ -627,27 +627,27 @@ const _t = Ht, A = class Y extends L {
627
627
  }
628
628
  }
629
629
  constructor(t, e) {
630
- super(t, e), this.attributes = new dt(this.domNode);
630
+ super(t, e), this.attributes = new Ct(this.domNode);
631
631
  }
632
632
  format(t, e) {
633
- const s = this.scroll.query(t, d.BLOCK);
634
- s != null && (s instanceof T ? this.attributes.attribute(s, e) : t === this.statics.blotName && !e ? this.replaceWith(Y.blotName) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e));
633
+ const s = this.scroll.query(t, p.BLOCK);
634
+ s != null && (s instanceof D ? this.attributes.attribute(s, e) : t === this.statics.blotName && !e ? this.replaceWith(et.blotName) : e && (t !== this.statics.blotName || this.formats()[t] !== e) && this.replaceWith(t, e));
635
635
  }
636
636
  formats() {
637
637
  const t = this.attributes.values(), e = this.statics.formats(this.domNode, this.scroll);
638
638
  return e != null && (t[this.statics.blotName] = e), t;
639
639
  }
640
640
  formatAt(t, e, s, i) {
641
- this.scroll.query(s, d.BLOCK) != null ? this.format(s, i) : super.formatAt(t, e, s, i);
641
+ this.scroll.query(s, p.BLOCK) != null ? this.format(s, i) : super.formatAt(t, e, s, i);
642
642
  }
643
643
  insertAt(t, e, s) {
644
- if (s == null || this.scroll.query(e, d.INLINE) != null)
644
+ if (s == null || this.scroll.query(e, p.INLINE) != null)
645
645
  super.insertAt(t, e, s);
646
646
  else {
647
647
  const i = this.split(t);
648
648
  if (i != null) {
649
- const r = this.scroll.create(e, s);
650
- i.parent.insertBefore(r, i);
649
+ const n = this.scroll.create(e, s);
650
+ i.parent.insertBefore(n, i);
651
651
  } else
652
652
  throw new Error("Attempt to insertAt after block boundaries");
653
653
  }
@@ -662,13 +662,13 @@ const _t = Ht, A = class Y extends L {
662
662
  ) && this.attributes.build();
663
663
  }
664
664
  };
665
- A.blotName = "block", A.scope = d.BLOCK_BLOT, A.tagName = "P", A.allowedChildren = [
666
- _t,
667
- A,
668
- q
665
+ S.blotName = "block", S.scope = p.BLOCK_BLOT, S.tagName = "P", S.allowedChildren = [
666
+ kt,
667
+ S,
668
+ X
669
669
  ];
670
- let Kt = A;
671
- const Z = Kt, J = class extends L {
670
+ let oe = S;
671
+ const st = oe, it = class extends B {
672
672
  checkMerge() {
673
673
  return this.next !== null && this.next.statics.blotName === this.statics.blotName;
674
674
  }
@@ -685,10 +685,10 @@ const Z = Kt, J = class extends L {
685
685
  super.optimize(t), this.children.length > 0 && this.next != null && this.checkMerge() && (this.next.moveChildren(this), this.next.remove());
686
686
  }
687
687
  };
688
- J.blotName = "container", J.scope = d.BLOCK_BLOT;
689
- let Vt = J;
690
- const qt = Vt;
691
- class Wt extends q {
688
+ it.blotName = "container", it.scope = p.BLOCK_BLOT;
689
+ let ae = it;
690
+ const le = ae;
691
+ class ce extends X {
692
692
  static formats(t, e) {
693
693
  }
694
694
  format(t, e) {
@@ -701,17 +701,17 @@ class Wt extends q {
701
701
  return this.statics.formats(this.domNode, this.scroll);
702
702
  }
703
703
  }
704
- const Ft = Wt, Gt = {
704
+ const he = ce, ue = {
705
705
  attributes: !0,
706
706
  characterData: !0,
707
707
  characterDataOldValue: !0,
708
708
  childList: !0,
709
709
  subtree: !0
710
- }, jt = 100, S = class extends L {
710
+ }, de = 100, k = class extends B {
711
711
  constructor(t, e) {
712
712
  super(null, e), this.registry = t, this.scroll = this, this.build(), this.observer = new MutationObserver((s) => {
713
713
  this.update(s);
714
- }), this.observer.observe(this.domNode, Gt), this.attach();
714
+ }), this.observer.observe(this.domNode, ue), this.attach();
715
715
  }
716
716
  create(t, e) {
717
717
  return this.registry.create(this, t, e);
@@ -720,7 +720,7 @@ const Ft = Wt, Gt = {
720
720
  const s = this.registry.find(t, e);
721
721
  return s ? s.scroll === this ? s : e ? this.find(s.scroll.domNode.parentNode, !0) : null : null;
722
722
  }
723
- query(t, e = d.ANY) {
723
+ query(t, e = p.ANY) {
724
724
  return this.registry.query(t, e);
725
725
  }
726
726
  register(...t) {
@@ -749,23 +749,23 @@ const Ft = Wt, Gt = {
749
749
  let i = Array.from(this.observer.takeRecords());
750
750
  for (; i.length > 0; )
751
751
  t.push(i.pop());
752
- const r = (l, h = !0) => {
753
- l == null || l === this || l.domNode.parentNode != null && (s.has(l.domNode) || s.set(l.domNode, []), h && r(l.parent));
752
+ const n = (l, c = !0) => {
753
+ l == null || l === this || l.domNode.parentNode != null && (s.has(l.domNode) || s.set(l.domNode, []), c && n(l.parent));
754
754
  }, o = (l) => {
755
- s.has(l.domNode) && (l instanceof L && l.children.forEach(o), s.delete(l.domNode), l.optimize(e));
755
+ s.has(l.domNode) && (l instanceof B && l.children.forEach(o), s.delete(l.domNode), l.optimize(e));
756
756
  };
757
757
  let a = t;
758
758
  for (let l = 0; a.length > 0; l += 1) {
759
- if (l >= jt)
759
+ if (l >= de)
760
760
  throw new Error("[Parchment] Maximum optimize iterations reached");
761
- for (a.forEach((h) => {
762
- const c = this.find(h.target, !0);
763
- c != null && (c.domNode === h.target && (h.type === "childList" ? (r(this.find(h.previousSibling, !1)), Array.from(h.addedNodes).forEach((f) => {
764
- const g = this.find(f, !1);
765
- r(g, !1), g instanceof L && g.children.forEach((u) => {
766
- r(u, !1);
761
+ for (a.forEach((c) => {
762
+ const h = this.find(c.target, !0);
763
+ h != null && (h.domNode === c.target && (c.type === "childList" ? (n(this.find(c.previousSibling, !1)), Array.from(c.addedNodes).forEach((u) => {
764
+ const d = this.find(u, !1);
765
+ n(d, !1), d instanceof B && d.children.forEach((f) => {
766
+ n(f, !1);
767
767
  });
768
- })) : h.type === "attributes" && r(c.prev)), r(c));
768
+ })) : c.type === "attributes" && n(h.prev)), n(h));
769
769
  }), this.children.forEach(o), a = Array.from(this.observer.takeRecords()), i = a.slice(); i.length > 0; )
770
770
  t.push(i.pop());
771
771
  }
@@ -774,16 +774,16 @@ const Ft = Wt, Gt = {
774
774
  t = t || this.observer.takeRecords();
775
775
  const s = /* @__PURE__ */ new WeakMap();
776
776
  t.map((i) => {
777
- const r = this.find(i.target, !0);
778
- return r == null ? null : s.has(r.domNode) ? (s.get(r.domNode).push(i), null) : (s.set(r.domNode, [i]), r);
777
+ const n = this.find(i.target, !0);
778
+ return n == null ? null : s.has(n.domNode) ? (s.get(n.domNode).push(i), null) : (s.set(n.domNode, [i]), n);
779
779
  }).forEach((i) => {
780
780
  i != null && i !== this && s.has(i.domNode) && i.update(s.get(i.domNode) || [], e);
781
781
  }), e.mutationsMap = s, s.has(this.domNode) && super.update(s.get(this.domNode), e), this.optimize(t, e);
782
782
  }
783
783
  };
784
- S.blotName = "scroll", S.defaultChild = Z, S.allowedChildren = [Z, qt], S.scope = d.BLOCK_BLOT, S.tagName = "DIV";
785
- let Xt = S;
786
- const Yt = Xt, nt = class vt extends q {
784
+ k.blotName = "scroll", k.defaultChild = st, k.allowedChildren = [st, le], k.scope = p.BLOCK_BLOT, k.tagName = "DIV";
785
+ let fe = k;
786
+ const pe = fe, ft = class Tt extends X {
787
787
  static create(t) {
788
788
  return document.createTextNode(t);
789
789
  }
@@ -806,7 +806,7 @@ const Yt = Xt, nt = class vt extends q {
806
806
  return this.text.length;
807
807
  }
808
808
  optimize(t) {
809
- super.optimize(t), this.text = this.statics.value(this.domNode), this.text.length === 0 ? this.remove() : this.next instanceof vt && this.next.prev === this && (this.insertAt(this.length(), this.next.value()), this.next.remove());
809
+ super.optimize(t), this.text = this.statics.value(this.domNode), this.text.length === 0 ? this.remove() : this.next instanceof Tt && this.next.prev === this && (this.insertAt(this.length(), this.next.value()), this.next.remove());
810
810
  }
811
811
  position(t, e = !1) {
812
812
  return [this.domNode, t];
@@ -828,8 +828,8 @@ const Yt = Xt, nt = class vt extends q {
828
828
  return this.text;
829
829
  }
830
830
  };
831
- nt.blotName = "text", nt.scope = d.INLINE_BLOT;
832
- const et = class et extends Yt {
831
+ ft.blotName = "text", ft.scope = p.INLINE_BLOT;
832
+ const ot = class ot extends pe {
833
833
  constructor(t, e) {
834
834
  super(t, e), this.observer.disconnect();
835
835
  }
@@ -839,88 +839,95 @@ const et = class et extends Yt {
839
839
  optimize(t, e) {
840
840
  }
841
841
  };
842
- et.blotName = "rc-scroll";
843
- let Q = et;
844
- const B = class B extends Z {
842
+ ot.blotName = "rc-scroll";
843
+ let nt = ot;
844
+ const P = class P extends st {
845
845
  };
846
- B.blotName = "rc-block", B.tagName = "DIV", B.className = "line";
847
- let U = B;
848
- const D = class D extends _t {
846
+ P.blotName = "rc-block", P.tagName = "DIV", P.className = "line";
847
+ let W = P;
848
+ const M = class M extends kt {
849
849
  static create(t) {
850
850
  const e = super.create();
851
- return t && Zt(e, t), e;
851
+ return t && ge(e, t), e;
852
852
  }
853
853
  };
854
- D.blotName = "rc-inline", D.tagName = "SPAN", D.className = "mark";
855
- let H = D;
856
- function Zt(n, t) {
854
+ M.blotName = "rc-inline", M.tagName = "SPAN", M.className = "mark";
855
+ let K = M;
856
+ function ge(r, t) {
857
857
  if (t.className)
858
858
  for (const e of t.className.split(/\s+/).filter(Boolean))
859
- n.classList.add(e);
860
- t.bold && (n.style.fontWeight = "bold"), t.italic && (n.style.fontStyle = "italic"), t.color && (n.style.color = t.color), t.background && (n.style.backgroundColor = t.background), t.underline && (n.style.textDecoration = `${t.underline} underline`, t.underlineColor && (n.style.textDecorationColor = t.underlineColor));
859
+ r.classList.add(e);
860
+ t.bold && (r.style.fontWeight = "bold"), t.italic && (r.style.fontStyle = "italic"), t.color && (r.style.color = t.color), t.background && (r.style.backgroundColor = t.background), t.underline && (r.style.textDecoration = `${t.underline} underline`, t.underlineColor && (r.style.textDecorationColor = t.underlineColor));
861
861
  }
862
- const I = class I extends Ft {
862
+ const z = class z extends he {
863
863
  static create() {
864
864
  const t = super.create();
865
865
  return t.contentEditable = "false", t.setAttribute("aria-hidden", "true"), t;
866
866
  }
867
867
  };
868
- I.blotName = "rc-widget", I.tagName = "SPAN", I.className = "widget";
869
- let K = I;
870
- function Jt() {
871
- const n = new z();
872
- return n.register(U, H, K), n;
868
+ z.blotName = "rc-widget", z.tagName = "SPAN", z.className = "widget";
869
+ let G = z;
870
+ function me() {
871
+ const r = new q();
872
+ return r.register(W, K, G), r;
873
873
  }
874
- function Qt(n, t, e, s, i) {
874
+ function _e(r, t, e, s, i) {
875
875
  if (t.length === 0) {
876
- n.appendChild(document.createElement("br"));
876
+ r.appendChild(document.createElement("br"));
877
+ for (const a of i)
878
+ r.appendChild(I(a));
877
879
  return;
878
880
  }
879
- const r = /* @__PURE__ */ new Set([0, t.length]);
881
+ const n = /* @__PURE__ */ new Set([0, t.length]);
880
882
  for (const a of s)
881
- r.add(Math.max(0, a.from - e)), r.add(Math.min(t.length, a.to - e));
883
+ n.add(Math.max(0, a.from - e)), n.add(Math.min(t.length, a.to - e));
882
884
  for (const a of i) {
883
885
  const l = a.offset - e;
884
- l >= 0 && l <= t.length && r.add(l);
885
- }
886
- const o = [...r].sort((a, l) => a - l);
887
- for (let a = 0; a < o.length - 1; a++) {
888
- const l = o[a], h = o[a + 1];
889
- for (const u of i)
890
- u.offset - e === l && (u.side ?? "before") === "before" && n.appendChild(G(u));
891
- const c = t.slice(l, h);
892
- if (!c)
886
+ l >= 0 && l <= t.length && n.add(l);
887
+ }
888
+ const o = [...n].sort((a, l) => a - l);
889
+ for (const a of i)
890
+ a.offset === e && a.side === "after" && r.appendChild(I(a));
891
+ for (const [a, l] of o.entries()) {
892
+ const c = o[a + 1];
893
+ if (c === void 0)
894
+ break;
895
+ for (const f of i)
896
+ f.offset - e === l && (f.side ?? "before") === "before" && r.appendChild(I(f));
897
+ const h = t.slice(l, c);
898
+ if (!h)
893
899
  continue;
894
- let f, g = 1 / 0;
895
- for (const u of s) {
896
- const m = u.from - e, p = u.to - e;
897
- if (m <= l && p >= h) {
898
- const k = p - m;
899
- k < g && (g = k, f = u);
900
+ let u, d = 1 / 0;
901
+ for (const f of s) {
902
+ const m = f.from - e, w = f.to - e;
903
+ if (m <= l && w >= c) {
904
+ const C = w - m;
905
+ C < d && (d = C, u = f);
900
906
  }
901
907
  }
902
- if (f) {
903
- const u = H.create(f);
904
- if (f.attributes)
905
- for (const [m, p] of Object.entries(f.attributes))
906
- u.setAttribute(m, p);
907
- u.appendChild(document.createTextNode(c)), n.appendChild(u);
908
+ if (u) {
909
+ const f = K.create(u);
910
+ if (u.attributes)
911
+ for (const [m, w] of Object.entries(u.attributes))
912
+ f.setAttribute(m, w);
913
+ f.appendChild(document.createTextNode(h)), r.appendChild(f);
908
914
  } else
909
- n.appendChild(document.createTextNode(c));
910
- for (const u of i)
911
- u.offset - e === h && u.side === "after" && n.appendChild(G(u));
915
+ r.appendChild(document.createTextNode(h));
916
+ for (const f of i)
917
+ f.offset - e === c && f.side === "after" && r.appendChild(I(f));
912
918
  }
913
919
  for (const a of i)
914
- a.offset - e === t.length && (a.side ?? "before") === "before" && n.appendChild(G(a));
920
+ a.offset - e === t.length && (a.side ?? "before") === "before" && r.appendChild(I(a));
915
921
  }
916
- function G(n) {
917
- const t = K.create();
918
- return t.appendChild(n.create()), t;
922
+ function I(r) {
923
+ const t = G.create();
924
+ return r.accessible && t.removeAttribute("aria-hidden"), r.layout && t.classList.add(`widget--${r.layout}`), t.appendChild(r.create()), t;
919
925
  }
920
- class te {
926
+ class be {
921
927
  constructor(t) {
922
- const e = Jt();
923
- this.scroll = new Q(e, t);
928
+ this.lineSignatures = /* @__PURE__ */ new WeakMap();
929
+ const e = me();
930
+ this.scroll = new nt(e, t);
924
931
  }
925
932
  /**
926
933
  * Rebuild the document tree.
@@ -930,50 +937,66 @@ class te {
930
937
  */
931
938
  build(t, e) {
932
939
  const s = this.scroll.domNode, i = t.split(`
933
- `), r = Array.from(s.querySelectorAll(".line")), o = /* @__PURE__ */ new Map(), a = [], l = [];
934
- for (const c of e)
935
- if (c.type === "line") {
936
- const f = o.get(c.line) ?? [];
937
- f.push(c), o.set(c.line, f);
938
- } else c.type === "mark" ? a.push(c) : l.push(c);
939
- a.sort((c, f) => c.from - f.from || c.to - f.to), l.sort((c, f) => c.offset - f.offset);
940
+ `), n = Array.from(s.querySelectorAll(".line")), o = /* @__PURE__ */ new Map(), a = [], l = [], c = /* @__PURE__ */ new Set();
941
+ for (const u of e)
942
+ if (u.type === "line") {
943
+ const d = o.get(u.line) ?? [];
944
+ d.push(u), o.set(u.line, d);
945
+ } else if (u.type === "mark")
946
+ a.push(u);
947
+ else if (u.type === "widget")
948
+ l.push(u);
949
+ else
950
+ for (let d = Math.max(2, u.fromLine); d <= u.toLine && d <= i.length; d++)
951
+ c.add(d);
952
+ a.sort((u, d) => u.from - d.from || u.to - d.to), l.sort((u, d) => u.offset - d.offset);
940
953
  let h = 0;
941
- for (let c = 0; c < i.length; c++) {
942
- const f = i[c], g = c + 1, u = h, m = u + f.length;
943
- let p;
944
- if (c < r.length) {
945
- for (p = r[c]; p.attributes.length > 0; )
946
- p.removeAttribute(p.attributes[0].name);
947
- for (p.className = "line"; p.firstChild; )
948
- p.removeChild(p.firstChild);
954
+ for (const [u, d] of i.entries()) {
955
+ const f = u + 1, m = h, w = m + d.length, C = o.get(f) ?? [], at = a.filter((g) => g.from < w && g.to > m), R = l.filter((g) => g.offset >= m && g.offset <= w), lt = c.has(f), H = R.length > 0 && R.every((g) => g.key) ? JSON.stringify([
956
+ d,
957
+ lt,
958
+ [...C, ...at, ...R].map(
959
+ ({ id: g, ...y }) => y.type === "line" ? { ...y, gutterContent: void 0 } : y
960
+ )
961
+ ]) : void 0, $ = n[u];
962
+ if ($ && H && this.lineSignatures.get($) === H && Bt($) === d) {
963
+ h += d.length + 1;
964
+ continue;
965
+ }
966
+ let _;
967
+ if ($) {
968
+ _ = $;
969
+ for (const g of _.getAttributeNames())
970
+ _.removeAttribute(g);
971
+ for (_.className = "line"; _.firstChild; )
972
+ _.removeChild(_.firstChild);
949
973
  } else
950
- p = U.create(), s.appendChild(p);
951
- const k = o.get(g) ?? [];
952
- for (const _ of k) {
953
- if (_.className)
954
- for (const x of _.className.split(/\s+/).filter(Boolean))
955
- p.classList.add(x);
956
- if (_.attributes)
957
- for (const [x, w] of Object.entries(_.attributes))
958
- p.setAttribute(x, w);
974
+ _ = W.create(), s.appendChild(_);
975
+ lt && (_.hidden = !0);
976
+ for (const g of C) {
977
+ if (g.className)
978
+ for (const y of g.className.split(/\s+/).filter(Boolean))
979
+ _.classList.add(y);
980
+ if (g.attributes)
981
+ for (const [y, A] of Object.entries(g.attributes))
982
+ _.setAttribute(y, A);
959
983
  }
960
- const St = a.filter((_) => _.from < m && _.to > u), Ot = l.filter((_) => _.offset >= u && _.offset <= m);
961
- Qt(p, f, u, St, Ot);
962
- const W = k.filter((_) => _.message);
963
- if (W.length > 0) {
964
- const _ = W.map((w) => w.message).join(" · "), x = [
984
+ _e(_, d, m, at, R), R.some((g) => g.layout === "trailing") && _.classList.add("line--trailing-widget"), H ? this.lineSignatures.set(_, H) : this.lineSignatures.delete(_);
985
+ const Y = C.filter((g) => g.message);
986
+ if (Y.length > 0) {
987
+ const g = Y.map((A) => A.message).join(" · "), y = [
965
988
  ...new Set(
966
- W.flatMap(
967
- (w) => w.messageClassName ? w.messageClassName.split(/\s+/).filter(Boolean) : []
989
+ Y.flatMap(
990
+ (A) => A.messageClassName ? A.messageClassName.split(/\s+/).filter(Boolean) : []
968
991
  )
969
992
  )
970
993
  ];
971
- p.dataset.message = _, p.title = _, x.length > 0 && (p.dataset.messageClass = x.join(" "));
994
+ _.dataset.message = g, _.title = g, y.length > 0 && (_.dataset.messageClass = y.join(" "));
972
995
  }
973
- h += f.length + 1;
996
+ h += d.length + 1;
974
997
  }
975
998
  for (; s.children.length > i.length; )
976
- s.removeChild(s.lastChild);
999
+ s.lastChild?.remove();
977
1000
  }
978
1001
  destroy() {
979
1002
  const t = this.scroll.domNode;
@@ -981,30 +1004,30 @@ class te {
981
1004
  t.removeChild(t.firstChild);
982
1005
  }
983
1006
  }
984
- function ee(n) {
985
- const t = Array.from(n.querySelectorAll(".line"));
986
- return t.length > 0 ? t.map((e) => se(e)).join(`
987
- `) : bt(n);
1007
+ function J(r) {
1008
+ const t = Array.from(r.querySelectorAll(".line"));
1009
+ return t.length > 0 ? t.map((e) => Bt(e)).join(`
1010
+ `) : Rt(r);
988
1011
  }
989
- function se(n) {
1012
+ function Bt(r) {
990
1013
  let t = "";
991
- for (const e of n.childNodes)
992
- t += yt(e);
1014
+ for (const e of r.childNodes)
1015
+ t += Dt(e);
993
1016
  return t;
994
1017
  }
995
- function yt(n) {
996
- if (n.nodeType === Node.TEXT_NODE)
997
- return n.data;
998
- if (!(n instanceof Element) || n.classList.contains("widget") || n.classList.contains("line-message") || n.tagName === "BR")
1018
+ function Dt(r) {
1019
+ if (r.nodeType === Node.TEXT_NODE)
1020
+ return r.data;
1021
+ if (!(r instanceof Element) || r.classList.contains("widget") || r.classList.contains("line-message") || r.tagName === "BR")
999
1022
  return "";
1000
1023
  let t = "";
1001
- for (const e of n.childNodes)
1002
- t += yt(e);
1024
+ for (const e of r.childNodes)
1025
+ t += Dt(e);
1003
1026
  return t;
1004
1027
  }
1005
- function bt(n) {
1028
+ function Rt(r) {
1006
1029
  let t = "", e = !0;
1007
- for (const s of n.childNodes)
1030
+ for (const s of r.childNodes)
1008
1031
  if (s.nodeType === Node.TEXT_NODE)
1009
1032
  t += s.data;
1010
1033
  else if (s instanceof HTMLElement) {
@@ -1016,52 +1039,53 @@ function bt(n) {
1016
1039
  if (s.classList.contains("widget"))
1017
1040
  continue;
1018
1041
  (s.tagName === "DIV" || s.tagName === "P") && !e && (t += `
1019
- `), e = !1, t += bt(s);
1042
+ `), e = !1, t += Rt(s);
1020
1043
  }
1021
1044
  return t;
1022
1045
  }
1023
- function R(n) {
1024
- if (n.nodeType === Node.TEXT_NODE)
1025
- return n.length;
1026
- if (!(n instanceof Element) || n.classList.contains("widget") || n.tagName === "BR")
1046
+ function F(r) {
1047
+ if (r.nodeType === Node.TEXT_NODE)
1048
+ return r.length;
1049
+ if (!(r instanceof Element) || r.classList.contains("widget") || r.tagName === "BR")
1027
1050
  return 0;
1028
1051
  let t = 0;
1029
- for (const e of n.childNodes)
1030
- t += R(e);
1052
+ for (const e of r.childNodes)
1053
+ t += F(e);
1031
1054
  return t;
1032
1055
  }
1033
- function $(n, t, e) {
1034
- const s = Array.from(n.querySelectorAll(".line"));
1056
+ function pt(r, t, e) {
1057
+ const s = Array.from(r.querySelectorAll(".line"));
1035
1058
  let i = 0;
1036
- for (let r = 0; r < s.length; r++) {
1037
- r > 0 && i++;
1038
- const o = s[r], a = Nt(o, t, e, i);
1059
+ for (const [n, o] of s.entries()) {
1060
+ if (n > 0 && i++, t === r && r.childNodes[e] === o)
1061
+ return i;
1062
+ const a = $t(o, t, e, i);
1039
1063
  if (a.found)
1040
1064
  return a.offset;
1041
- i += R(o);
1065
+ i += F(o);
1042
1066
  }
1043
1067
  return i;
1044
1068
  }
1045
- function Nt(n, t, e, s) {
1046
- if (n === t) {
1047
- if (n.nodeType === Node.TEXT_NODE)
1069
+ function $t(r, t, e, s) {
1070
+ if (r === t) {
1071
+ if (r.nodeType === Node.TEXT_NODE)
1048
1072
  return { found: !0, offset: s + e };
1049
- const i = Array.from(n.childNodes);
1050
- let r = s;
1051
- for (let o = 0; o < e && o < i.length; o++)
1052
- r += R(i[o]);
1053
- return { found: !0, offset: r };
1054
- }
1055
- if (n.nodeType === Node.TEXT_NODE)
1056
- return { found: !1, offset: s + n.length };
1057
- if (n instanceof Element) {
1058
- if (n.classList.contains("widget"))
1073
+ const i = Array.from(r.childNodes);
1074
+ let n = s;
1075
+ for (const o of i.slice(0, e))
1076
+ n += F(o);
1077
+ return { found: !0, offset: n };
1078
+ }
1079
+ if (r.nodeType === Node.TEXT_NODE)
1080
+ return { found: !1, offset: s + r.length };
1081
+ if (r instanceof Element) {
1082
+ if (r.classList.contains("widget"))
1059
1083
  return { found: !1, offset: s };
1060
- if (n.tagName === "BR")
1084
+ if (r.tagName === "BR")
1061
1085
  return { found: !1, offset: s };
1062
1086
  let i = s;
1063
- for (const r of n.childNodes) {
1064
- const o = Nt(r, t, e, i);
1087
+ for (const n of r.childNodes) {
1088
+ const o = $t(n, t, e, i);
1065
1089
  if (o.found)
1066
1090
  return o;
1067
1091
  i = o.offset;
@@ -1070,176 +1094,195 @@ function Nt(n, t, e, s) {
1070
1094
  }
1071
1095
  return { found: !1, offset: s };
1072
1096
  }
1073
- function ot(n, t) {
1074
- const e = Array.from(n.querySelectorAll(".line"));
1097
+ function gt(r, t) {
1098
+ const e = Array.from(r.querySelectorAll(".line"));
1075
1099
  let s = t;
1076
- for (let r = 0; r < e.length; r++) {
1077
- if (r > 0) {
1100
+ for (const [n, o] of e.entries()) {
1101
+ if (n > 0) {
1078
1102
  if (s === 0)
1079
- return { node: e[r], offset: 0 };
1103
+ return { node: o, offset: 0 };
1080
1104
  s--;
1081
1105
  }
1082
- const o = e[r], a = R(o);
1106
+ const a = F(o);
1083
1107
  if (s <= a) {
1084
- const l = xt(o, s);
1108
+ const l = It(o, s);
1085
1109
  return l || { node: o, offset: o.childNodes.length };
1086
1110
  }
1087
1111
  s -= a;
1088
1112
  }
1089
1113
  const i = e[e.length - 1];
1090
- return i ? { node: i, offset: i.childNodes.length } : { node: n, offset: n.childNodes.length };
1114
+ return i ? { node: i, offset: i.childNodes.length } : { node: r, offset: r.childNodes.length };
1091
1115
  }
1092
- function xt(n, t) {
1093
- if (n.nodeType === Node.TEXT_NODE) {
1094
- const e = n;
1116
+ function It(r, t) {
1117
+ if (r.nodeType === Node.TEXT_NODE) {
1118
+ const e = r;
1095
1119
  return t <= e.length ? { node: e, offset: t } : null;
1096
1120
  }
1097
- if (n instanceof Element) {
1098
- if (n.classList.contains("widget") || n.tagName === "BR")
1121
+ if (r instanceof Element) {
1122
+ if (r.classList.contains("widget") || r.tagName === "BR")
1099
1123
  return null;
1100
1124
  let e = 0;
1101
- for (const s of n.childNodes) {
1102
- const i = R(s);
1125
+ for (const s of r.childNodes) {
1126
+ const i = F(s);
1103
1127
  if (t <= i) {
1104
- const r = xt(s, t);
1105
- return r || { node: n, offset: e + 1 };
1128
+ const n = It(s, t);
1129
+ return n || { node: r, offset: e + 1 };
1106
1130
  }
1107
1131
  t -= i, e++;
1108
1132
  }
1109
1133
  }
1110
1134
  return null;
1111
1135
  }
1112
- function P(n) {
1113
- const t = n.getRootNode(), e = t.getSelection, s = e?.call(t) ?? window.getSelection();
1114
- if (!s || s.rangeCount === 0)
1136
+ function mt(r, t) {
1137
+ if (!t || t.rangeCount === 0 || !t.anchorNode || !t.focusNode)
1115
1138
  return null;
1116
- const i = s.getRangeAt(0);
1117
- if (n.contains(i.commonAncestorContainer))
1118
- return {
1119
- anchorOffset: $(n, i.startContainer, i.startOffset),
1120
- focusOffset: $(n, i.endContainer, i.endOffset)
1121
- };
1122
- if (!e && t instanceof ShadowRoot && typeof s.getComposedRanges == "function") {
1123
- const [r] = s.getComposedRanges({ shadowRoots: [t] });
1124
- if (r && n.contains(r.startContainer) && n.contains(r.endContainer))
1125
- return {
1126
- anchorOffset: $(
1127
- n,
1128
- r.startContainer,
1129
- r.startOffset
1130
- ),
1131
- focusOffset: $(n, r.endContainer, r.endOffset)
1132
- };
1133
- }
1134
- return null;
1139
+ const e = t.getRangeAt(0);
1140
+ return !r.contains(e.commonAncestorContainer) || !r.contains(t.anchorNode) || !r.contains(t.focusNode) ? null : {
1141
+ $anchorNode: t.anchorNode,
1142
+ anchorOffset: t.anchorOffset,
1143
+ $focusNode: t.focusNode,
1144
+ focusOffset: t.focusOffset
1145
+ };
1146
+ }
1147
+ function Pt(r) {
1148
+ const t = r.getRootNode(), e = t.getSelection, s = mt(
1149
+ r,
1150
+ e?.call(t) ?? null
1151
+ );
1152
+ if (s)
1153
+ return s;
1154
+ const i = window.getSelection(), n = mt(r, i);
1155
+ if (n)
1156
+ return n;
1157
+ if (!(t instanceof ShadowRoot))
1158
+ return null;
1159
+ const [o] = i?.getComposedRanges?.({
1160
+ shadowRoots: [t]
1161
+ }) ?? [];
1162
+ return !o || !r.contains(o.startContainer) || !r.contains(o.endContainer) ? null : {
1163
+ $anchorNode: o.startContainer,
1164
+ anchorOffset: o.startOffset,
1165
+ $focusNode: o.endContainer,
1166
+ focusOffset: o.endOffset
1167
+ };
1168
+ }
1169
+ function ve(r) {
1170
+ return Pt(r)?.$focusNode ?? null;
1171
+ }
1172
+ function E(r) {
1173
+ const t = Pt(r);
1174
+ return t ? {
1175
+ anchorOffset: pt(r, t.$anchorNode, t.anchorOffset),
1176
+ focusOffset: pt(r, t.$focusNode, t.focusOffset)
1177
+ } : null;
1135
1178
  }
1136
- function ie(n, t) {
1137
- const e = ot(n, t.anchorOffset), s = ot(n, t.focusOffset);
1179
+ function ye(r, t) {
1180
+ const e = gt(r, t.anchorOffset), s = gt(r, t.focusOffset);
1138
1181
  if (!(!e || !s))
1139
1182
  try {
1140
1183
  const i = window.getSelection();
1141
1184
  if (!i)
1142
1185
  return;
1143
- const r = document.createRange();
1144
- r.setStart(e.node, e.offset), r.setEnd(s.node, s.offset), i.removeAllRanges(), i.addRange(r);
1186
+ const n = document.createRange();
1187
+ n.setStart(e.node, e.offset), n.setEnd(s.node, s.offset), i.removeAllRanges(), i.addRange(n);
1145
1188
  } catch {
1146
1189
  }
1147
1190
  }
1148
- function M() {
1191
+ function U() {
1149
1192
  return crypto.randomUUID();
1150
1193
  }
1151
- function wt(n, t) {
1194
+ function Mt(r, t) {
1152
1195
  let e = 0;
1153
- for (; e < n.length && e < t.length && n[e] === t[e]; )
1196
+ for (; e < r.length && e < t.length && r[e] === t[e]; )
1154
1197
  e++;
1155
- let s = n.length, i = t.length;
1156
- for (; s > e && i > e && n[s - 1] === t[i - 1]; )
1198
+ let s = r.length, i = t.length;
1199
+ for (; s > e && i > e && r[s - 1] === t[i - 1]; )
1157
1200
  s--, i--;
1158
1201
  return { start: e, removed: s - e, inserted: i - e };
1159
1202
  }
1160
- function at(n, t, e) {
1203
+ function _t(r, t, e) {
1161
1204
  const s = e.start + e.removed, i = e.inserted - e.removed;
1162
1205
  if (t <= e.start)
1163
- return { from: n, to: t };
1164
- if (n >= s)
1165
- return { from: n + i, to: t + i };
1166
- const r = Math.min(n, e.start), o = Math.max(
1206
+ return { from: r, to: t };
1207
+ if (r >= s)
1208
+ return { from: r + i, to: t + i };
1209
+ const n = Math.min(r, e.start), o = Math.max(
1167
1210
  t > s ? t + i : e.start + e.inserted,
1168
1211
  e.start + e.inserted
1169
1212
  );
1170
- return r >= o ? null : { from: r, to: o };
1213
+ return n >= o ? null : { from: n, to: o };
1171
1214
  }
1172
- function re(n, t) {
1215
+ function Ne(r, t) {
1173
1216
  let e = 0;
1174
- for (let s = 0; s < t && s < n.length; s++)
1175
- n[s] === `
1217
+ for (let s = 0; s < t && s < r.length; s++)
1218
+ r[s] === `
1176
1219
  ` && e++;
1177
1220
  return e;
1178
1221
  }
1179
- function ne(n, t, e) {
1180
- const s = wt(t, e), i = s.start + s.removed, r = t.slice(s.start, i), o = e.slice(s.start, s.start + s.inserted), a = (r.match(/\n/g) ?? []).length, h = (o.match(/\n/g) ?? []).length - a, c = re(t, s.start) + 1, f = c + a, g = [];
1181
- for (const u of n)
1182
- if (u.type === "mark") {
1183
- const m = at(u.from, u.to, s);
1184
- m && g.push({ ...u, from: m.from, to: m.to });
1185
- } else if (u.type === "line")
1186
- u.line < c ? g.push(u) : u.line <= f || g.push({ ...u, line: u.line + h });
1187
- else {
1188
- const m = at(u.offset, u.offset + 1, s);
1189
- m && g.push({ ...u, offset: m.from });
1222
+ function xe(r, t, e) {
1223
+ const s = Mt(t, e), i = s.start + s.removed, n = t.slice(s.start, i), o = e.slice(s.start, s.start + s.inserted), a = (n.match(/\n/g) ?? []).length, c = (o.match(/\n/g) ?? []).length - a, h = Ne(t, s.start) + 1, u = h + a, d = [];
1224
+ for (const f of r)
1225
+ if (f.type === "mark") {
1226
+ const m = _t(f.from, f.to, s);
1227
+ m && d.push({ ...f, from: m.from, to: m.to });
1228
+ } else if (f.type === "line")
1229
+ f.line < h ? d.push(f) : f.line <= u || d.push({ ...f, line: f.line + c });
1230
+ else if (f.type === "widget") {
1231
+ const m = _t(f.offset, f.offset + 1, s);
1232
+ m && d.push({ ...f, offset: m.from });
1190
1233
  }
1191
- return g;
1234
+ return d;
1192
1235
  }
1193
- function oe(n, t) {
1194
- if (n.length === 0)
1236
+ function we(r, t) {
1237
+ if (r.length === 0)
1195
1238
  return !1;
1196
1239
  const e = Math.max(t.removed, t.inserted);
1197
- return e > 50 && e > n.length * 0.5;
1240
+ return e > 50 && e > r.length * 0.5;
1198
1241
  }
1199
- function j(n, t, e) {
1200
- const s = wt(t, e);
1201
- return oe(t, s) ? [] : ne(n, t, e);
1242
+ function Q(r, t, e) {
1243
+ const s = Mt(t, e);
1244
+ return we(t, s) ? [] : xe(r, t, e);
1202
1245
  }
1203
- function lt(n, t) {
1246
+ function bt(r, t) {
1204
1247
  const e = crypto.randomUUID();
1205
- return n.set(e, { ...t, id: e }), e;
1248
+ return r.set(e, { ...t, id: e }), e;
1206
1249
  }
1207
- function ae(n, t) {
1208
- n.clear();
1250
+ function Ee(r, t) {
1251
+ r.clear();
1209
1252
  for (const e of t) {
1210
1253
  const s = crypto.randomUUID();
1211
- n.set(s, { ...e, id: s });
1254
+ r.set(s, { ...e, id: s });
1212
1255
  }
1213
1256
  }
1214
- function le(n, t) {
1257
+ function Ce(r, t) {
1215
1258
  const e = [], s = [];
1216
1259
  for (const i of t) {
1217
- let r = i.pattern.flags.includes("g") ? i.pattern.flags : i.pattern.flags + "g";
1218
- i.captureGroups && !r.includes("d") && (r += "d");
1219
- const o = new RegExp(i.pattern.source, r);
1260
+ let n = i.pattern.flags.includes("g") ? i.pattern.flags : i.pattern.flags + "g";
1261
+ i.captureGroups && !n.includes("d") && (n += "d");
1262
+ const o = new RegExp(i.pattern.source, n);
1220
1263
  let a;
1221
- for (; (a = o.exec(n)) !== null; ) {
1264
+ for (; (a = o.exec(r)) !== null; ) {
1222
1265
  if (a[0].length === 0) {
1223
1266
  o.lastIndex++;
1224
1267
  continue;
1225
1268
  }
1226
1269
  const l = a.index;
1227
1270
  if (i.captureGroups) {
1228
- const h = a.indices?.groups;
1229
- if (h)
1230
- for (const [c, f] of Object.entries(i.captureGroups)) {
1231
- const g = h[c];
1232
- if (g === void 0)
1271
+ const c = a.indices?.groups;
1272
+ if (c)
1273
+ for (const [h, u] of Object.entries(i.captureGroups)) {
1274
+ const d = c[h];
1275
+ if (d === void 0)
1233
1276
  continue;
1234
- const [u, m] = g;
1235
- e.push({ type: "mark", from: u, to: m, ...f });
1277
+ const [f, m] = d;
1278
+ e.push({ type: "mark", from: f, to: m, ...u });
1236
1279
  }
1237
1280
  } else {
1238
- const h = l + a[0].length;
1281
+ const c = l + a[0].length;
1239
1282
  e.push({
1240
1283
  type: "mark",
1241
1284
  from: l,
1242
- to: h,
1285
+ to: c,
1243
1286
  className: i.className,
1244
1287
  bold: i.bold,
1245
1288
  italic: i.italic,
@@ -1251,241 +1294,150 @@ function le(n, t) {
1251
1294
  });
1252
1295
  }
1253
1296
  if (i.createLineDecoration) {
1254
- const h = i.createLineDecoration(a);
1255
- if (h) {
1256
- const c = n.slice(0, l).split(`
1297
+ const c = i.createLineDecoration(a);
1298
+ if (c) {
1299
+ const h = r.slice(0, l).split(`
1257
1300
  `).length;
1258
- s.push({ type: "line", line: c, ...h });
1301
+ s.push({ type: "line", line: h, ...c });
1259
1302
  }
1260
1303
  }
1261
1304
  }
1262
1305
  }
1263
1306
  return { markDecorations: e, lineDecorations: s };
1264
1307
  }
1265
- const ce = Lt`
1266
- :host {
1267
- display: block;
1268
- box-sizing: border-box;
1269
- min-inline-size: 0;
1270
- color-scheme: inherit;
1271
- }
1272
-
1273
- :host([hidden]) {
1274
- display: none;
1275
- }
1276
-
1277
- #root {
1278
- display: flex;
1279
- align-items: stretch;
1280
- border: var(--rc-textarea-border, 1px solid ButtonBorder);
1281
- border-radius: var(--rc-textarea-border-radius, 2px);
1282
- background: var(--rc-textarea-background, Field);
1283
- color: var(--rc-textarea-color, var(--rc-text, FieldText));
1284
- overflow: hidden;
1285
- min-height: var(--_rc-textarea-min-height, auto);
1286
- }
1287
-
1288
- #gutter {
1289
- display: none;
1290
- flex-shrink: 0;
1291
- background: var(--rc-textarea-gutter-bg, Canvas);
1292
- color: var(--rc-textarea-gutter-color, GrayText);
1293
- border-right: var(--rc-textarea-gutter-border, 1px solid ButtonBorder);
1294
- overflow: hidden;
1295
- user-select: none;
1296
- }
1297
-
1298
- :host([line-numbers]) #gutter,
1299
- :host([gutter]) #gutter {
1300
- display: block;
1301
- }
1302
-
1303
- #gutter-cells {
1304
- padding: var(--rc-textarea-padding, 0.5em);
1305
- padding-inline-end: var(--rc-textarea-gutter-padding-inline-end, 0.75em);
1306
- font-family: var(--rc-textarea-gutter-font-family, var(--rc-textarea-font-family, monospace));
1307
- font-size: var(--rc-textarea-font-size, 1em);
1308
- line-height: var(--rc-textarea-line-height, 1.5);
1309
- text-align: right;
1310
- min-width: 2.5ch;
1311
- }
1312
-
1313
- .gutter-cell {
1314
- display: block;
1315
- white-space: pre;
1316
- }
1317
-
1318
- .gutter-cell--active {
1319
- color: var(--rc-textarea-color, var(--rc-text, FieldText));
1320
- }
1321
-
1322
- #editor-area {
1323
- position: relative;
1324
- flex: 1;
1325
- min-width: 0;
1326
- overflow: hidden;
1327
- }
1328
-
1329
- #editor {
1330
- position: relative;
1331
- z-index: 1;
1332
- width: 100%;
1333
- min-height: 100%;
1334
- box-sizing: border-box;
1335
- padding: var(--rc-textarea-padding, 0.5em);
1336
- font-family: var(--rc-textarea-font-family, monospace);
1337
- font-size: var(--rc-textarea-font-size, 1em);
1338
- line-height: var(--rc-textarea-line-height, 1.5);
1339
- color: var(--rc-textarea-color, var(--rc-text, FieldText));
1340
- caret-color: var(--rc-textarea-caret-color, var(--rc-textarea-color, FieldText));
1341
- background: transparent;
1342
- outline: none;
1343
- overflow: auto;
1344
- resize: none;
1345
- white-space: pre;
1346
- word-break: normal;
1347
- overflow-wrap: normal;
1348
- tab-size: 4;
1349
- word-break: normal;
1350
- /* Prevent contenteditable from injecting <div> wrappers on Enter in some browsers */
1351
- -webkit-user-modify: read-write-plaintext-only;
1352
- }
1353
-
1354
- :host([word-wrap]) #editor {
1355
- white-space: pre-wrap;
1356
- overflow-wrap: break-word;
1357
- word-break: normal;
1358
- }
1359
-
1360
- :host([auto-grow]) #editor {
1361
- overflow: visible;
1362
- height: auto;
1363
- }
1364
-
1365
- :host([auto-grow]) #root {
1366
- height: auto;
1367
- }
1368
-
1369
- :host([read-only]) #root {
1370
- border: none;
1371
- background: transparent;
1372
- border-radius: 0;
1373
- }
1374
-
1375
- :host([read-only]) #editor {
1376
- cursor: default;
1377
- padding: 0;
1378
- -webkit-user-modify: read-only;
1379
- }
1380
-
1381
- /* Focus ring on the root when editor is focused */
1382
- #root:has(#editor:focus) {
1383
- outline: var(--rc-textarea-focus-outline, 2px solid Highlight);
1384
- outline-offset: -1px;
1385
- }
1386
-
1387
- /* Slotted textarea is hidden on host upgrade */
1388
- ::slotted(textarea) {
1389
- position: absolute !important;
1390
- width: 1px !important;
1391
- height: 1px !important;
1392
- padding: 0 !important;
1393
- margin: -1px !important;
1394
- overflow: hidden !important;
1395
- clip: rect(0, 0, 0, 0) !important;
1396
- border: 0 !important;
1397
- opacity: 0 !important;
1398
- pointer-events: none !important;
1399
- }
1400
-
1401
- .line {
1402
- position: relative;
1403
- display: block;
1404
- }
1405
-
1406
- /* Active line highlight — opt-in via CSS custom property. */
1407
- .line--active {
1408
- background: var(--rc-textarea-active-line-bg, transparent);
1409
- }
1410
-
1411
- /* Error-lens -style end-of-line diagnostic message */
1412
- .line[data-message]::after {
1413
- content: attr(data-message);
1414
- display: inline;
1415
- margin-left: 4ch;
1416
- white-space: nowrap;
1417
- pointer-events: none;
1418
- font-size: 0.875em;
1419
- opacity: 0.8;
1420
- font-style: italic;
1308
+ const Ae = Ut`.widget.widget--block{white-space:normal;display:block}.line--trailing-widget{min-block-size:var(--rc-textarea-trailing-size,2.5em);padding-inline-end:var(--rc-textarea-trailing-size,2.5em);position:relative}.widget--trailing{inline-size:var(--rc-textarea-trailing-size,2.5em);white-space:normal;position:absolute;inset-block-start:0;inset-inline-end:0}.fold-action-trigger{box-sizing:border-box;cursor:pointer;block-size:1lh;inline-size:100%;color:inherit;font:inherit;background:0 0;border:0;padding:0}.gutter-cell{position:relative}.gutter-cell>.fold-action-trigger:before,.gutter-cell>:not(.fold-action-group) .fold-action-trigger:before{content:"";position:absolute;inset:0}.fold-action-group,.fold-action-single{vertical-align:top;align-items:center;display:inline-flex}.fold-action-group .fold-action-trigger{min-inline-size:24px}.widget--trailing .fold-action-trigger{min-block-size:var(--rc-textarea-trailing-size,2.5em)}.widget--block [hidden]{display:none}:host{box-sizing:border-box;min-inline-size:0;color-scheme:inherit;display:block}:host([hidden]){display:none}#root{border:var(--rc-textarea-border,1px solid ButtonBorder);border-radius:var(--rc-textarea-border-radius,2px);background:var(--rc-textarea-background,Field);color:var(--rc-textarea-color,var(--rc-field-text,FieldText));min-height:var(--_rc-textarea-min-height,auto);align-items:stretch;display:flex;overflow:hidden}#gutter{background:var(--rc-textarea-gutter-bg,Canvas);color:var(--rc-textarea-gutter-color,GrayText);border-inline-end:var(--rc-textarea-gutter-border,1px solid ButtonBorder);user-select:none;flex-shrink:0;display:none;overflow:hidden}:host([line-numbers]) #gutter,:host([gutter]) #gutter{display:block}#gutter-cells{box-sizing:border-box;padding-block:var(--rc-textarea-padding-block,.5em);padding-inline:var(--rc-textarea-padding-inline,.5em) var(--rc-textarea-gutter-padding-inline-end,.75em);font-family:var(--rc-textarea-gutter-font-family,var(--rc-textarea-font-family,monospace));font-size:var(--rc-textarea-font-size,1em);line-height:var(--rc-textarea-line-height,1.5);text-align:end;min-inline-size:var(--rc-textarea-gutter-min-inline-size,24px)}.gutter-cell{min-inline-size:var(--rc-textarea-gutter-min-inline-size,24px);white-space:pre;display:block}.gutter-cell[hidden],.line[hidden]{display:none}.gutter-cell-composite{align-items:center;gap:var(--rc-textarea-gutter-content-gap,.25em);display:inline-flex}.gutter-cell-number{font-variant-numeric:tabular-nums}.gutter-cell-content{align-items:center;display:inline-flex}.gutter-cell--active{isolation:isolate;color:var(--rc-textarea-color,var(--rc-field-text,FieldText));position:relative}.gutter-cell--active:before{content:"";z-index:-1;background:var(--rc-textarea-active-line-bg,transparent);pointer-events:none;position:absolute;inset-block:0;inset-inline-start:calc(-1 * var(--rc-textarea-padding-inline,.5em));inset-inline-end:calc(-1 * var(--rc-textarea-gutter-padding-inline-end,.75em))}#editor-area{flex:1;min-width:0;position:relative;overflow:hidden}#editor{z-index:1;box-sizing:border-box;width:100%;min-height:100%;padding-block:var(--rc-textarea-padding-block,.5em);padding-inline:var(--rc-textarea-padding-inline,.5em);font-family:var(--rc-textarea-font-family,monospace);font-size:var(--rc-textarea-font-size,1em);line-height:var(--rc-textarea-line-height,1.5);color:var(--rc-textarea-color,var(--rc-field-text,FieldText));caret-color:var(--rc-textarea-caret-color,var(--rc-textarea-color,FieldText));resize:none;white-space:pre;word-break:normal;overflow-wrap:normal;tab-size:4;word-break:normal;-webkit-user-modify:read-write-plaintext-only;background:0 0;outline:none;position:relative;overflow:auto}:host([word-wrap]) #editor{white-space:pre-wrap;overflow-wrap:break-word;word-break:normal}:host([auto-grow]) #editor{height:auto;overflow:visible}:host([auto-grow]) #root{height:auto}:host([data-readonly]) #editor{-webkit-user-modify:read-only}#root:has(#editor:focus){outline:var(--rc-textarea-focus-outline,2px solid Highlight);outline-offset:-1px}::slotted(textarea){clip:rect(0, 0, 0, 0)!important;opacity:0!important;pointer-events:none!important;border:0!important;width:1px!important;height:1px!important;margin:-1px!important;padding:0!important;position:absolute!important;overflow:hidden!important}.line{display:block;position:relative}:host(:not([word-wrap])) .line{inline-size:max-content;min-inline-size:100%}.line--active{isolation:isolate}.line--active:before{content:"";z-index:-1;inset-block:0;inset-inline:calc(-1 * var(--rc-textarea-padding-inline,.5em));background:var(--rc-textarea-active-line-bg,transparent);pointer-events:none;position:absolute}.line[data-message]:after{content:attr(data-message);white-space:nowrap;pointer-events:none;opacity:.8;unicode-bidi:isolate;margin-inline-start:4ch;font-size:.875em;font-style:italic;display:inline}:host([line-direction=auto]) .line:not(.line--neutral){unicode-bidi:plaintext}.mark{border-radius:2px}.widget{user-select:none;cursor:default;vertical-align:middle;unicode-bidi:isolate;display:inline-block}`;
1309
+ var Oe = Object.defineProperty, Le = Object.getOwnPropertyDescriptor, v = (r, t, e, s) => {
1310
+ for (var i = s > 1 ? void 0 : s ? Le(t, e) : t, n = r.length - 1, o; n >= 0; n--)
1311
+ (o = r[n]) && (i = (s ? o(t, e, i) : o(i)) || i);
1312
+ return s && i && Oe(t, e, i), i;
1313
+ };
1314
+ function Se(r, t) {
1315
+ const e = r.split(`
1316
+ `), s = [];
1317
+ let i = 0;
1318
+ for (const n of e)
1319
+ s.push(i), i += n.length + 1;
1320
+ return t.flatMap((n) => n.fromLine < 2 || n.toLine < n.fromLine || n.toLine > e.length ? [] : [
1321
+ {
1322
+ from: s[n.fromLine - 1],
1323
+ to: s[n.toLine - 1] + e[n.toLine - 1].length,
1324
+ anchorEnd: s[n.fromLine - 2] + e[n.fromLine - 2].length,
1325
+ reveal: n.reveal
1326
+ }
1327
+ ]);
1328
+ }
1329
+ const ke = 100, Te = /[\p{L}\u061C\u200E\u200F]/u, Be = /[\u0590-\u08FF\uFB1D-\uFDFF\uFE70-\uFEFF\u061C\u200F\u{10800}-\u{10FFF}\u{1E800}-\u{1EFFF}]/u, De = /[\p{L}\p{N}]/u, vt = /[\p{L}\p{M}\p{N}_]/u;
1330
+ function yt(r) {
1331
+ let t = 0;
1332
+ for (const e of r) {
1333
+ if ("⁦⁧⁨".includes(e)) {
1334
+ t += 1;
1335
+ continue;
1336
+ }
1337
+ if (e === "⁩") {
1338
+ t = Math.max(0, t - 1);
1339
+ continue;
1340
+ }
1341
+ if (t === 0 && Te.test(e))
1342
+ return Be.test(e) ? "rtl" : "ltr";
1421
1343
  }
1422
-
1423
- .mark {
1424
- border-radius: 2px;
1344
+ return null;
1345
+ }
1346
+ const Nt = /* @__PURE__ */ new Map();
1347
+ function Re(r) {
1348
+ let t = Nt.get(r);
1349
+ if (t === void 0) {
1350
+ if (typeof Intl.Segmenter != "function")
1351
+ t = null;
1352
+ else
1353
+ try {
1354
+ t = new Intl.Segmenter(r || void 0, { granularity: "word" });
1355
+ } catch {
1356
+ t = new Intl.Segmenter(void 0, { granularity: "word" });
1357
+ }
1358
+ Nt.set(r, t);
1425
1359
  }
1426
-
1427
- .widget {
1428
- display: inline-block;
1429
- user-select: none;
1430
- cursor: default;
1431
- vertical-align: middle;
1360
+ return t;
1361
+ }
1362
+ function $e(r, t, e) {
1363
+ const s = Re(e);
1364
+ if (!s) {
1365
+ let n = t, o = t;
1366
+ for (; n > 0 && vt.test(r.charAt(n - 1)); )
1367
+ n--;
1368
+ for (; o < r.length && vt.test(r.charAt(o)); )
1369
+ o++;
1370
+ return n === o ? null : { from: n, to: o };
1371
+ }
1372
+ const i = s.segment(r);
1373
+ for (const n of [t, t - 1]) {
1374
+ if (n < 0 || n >= r.length)
1375
+ continue;
1376
+ const o = i.containing(n);
1377
+ if (o && De.test(o.segment))
1378
+ return { from: o.index, to: o.index + o.segment.length };
1432
1379
  }
1433
- `;
1434
- var he = Object.defineProperty, ue = Object.getOwnPropertyDescriptor, y = (n, t, e, s) => {
1435
- for (var i = s > 1 ? void 0 : s ? ue(t, e) : t, r = n.length - 1, o; r >= 0; r--)
1436
- (o = n[r]) && (i = (s ? o(t, e, i) : o(i)) || i);
1437
- return s && i && he(t, e, i), i;
1438
- };
1439
- const de = 100;
1440
- function ct(n) {
1380
+ return null;
1381
+ }
1382
+ function xt(r) {
1441
1383
  const t = document.createElement("div");
1442
- t.innerHTML = n;
1384
+ t.innerHTML = r;
1443
1385
  const e = [];
1444
1386
  let s = 0;
1445
- function i(r) {
1446
- if (r.nodeType === Node.TEXT_NODE) {
1447
- s += r.length;
1387
+ function i(n) {
1388
+ if (n.nodeType === Node.TEXT_NODE) {
1389
+ s += n.length;
1448
1390
  return;
1449
1391
  }
1450
- if (!(r instanceof HTMLElement))
1392
+ if (!(n instanceof HTMLElement))
1451
1393
  return;
1452
- const o = r.tagName === "SPAN" && r.className, a = s;
1453
- for (const l of r.childNodes)
1394
+ const o = n.tagName === "SPAN" && n.className, a = s;
1395
+ for (const l of n.childNodes)
1454
1396
  i(l);
1455
1397
  o && s > a && e.push({
1456
1398
  type: "mark",
1457
1399
  from: a,
1458
1400
  to: s,
1459
- className: r.className
1401
+ className: n.className
1460
1402
  });
1461
1403
  }
1462
- for (const r of t.childNodes)
1463
- i(r);
1404
+ for (const n of t.childNodes)
1405
+ i(n);
1464
1406
  return e;
1465
1407
  }
1466
- const V = class V extends st {
1408
+ const j = class j extends ct {
1467
1409
  constructor() {
1468
- super(...arguments), this.lineNumbers = !1, this.gutter = !1, this.wordWrap = !1, this.autoGrow = !1, this.readOnly = !1, this._value = "", this._initialValueResolved = !1, this._valueSetByHost = !1, this._document = null, this._$textareaRef = null, this._textareaController = new kt(this, {
1410
+ super(...arguments), this.lineNumbers = !1, this.gutter = !1, this.wordWrap = !1, this.autoGrow = !1, this.lineDirection = "base", this._readOnly = !1, this._textareaAttributeObserver = null, this._value = "", this._initialValueResolved = !1, this._valueSetByHost = !1, this._document = null, this._$textareaRef = null, this._textareaController = new qt(this, {
1469
1411
  selector: ":scope > textarea",
1470
1412
  observe: !0,
1471
1413
  onChange: (t, e) => this._setupTextarea(t, e),
1472
1414
  onMissing: () => {
1473
1415
  }
1474
- }), this._pluginDecorations = /* @__PURE__ */ new Map(), this._patternDecorations = [], this._externalDecorations = [], this._patterns = /* @__PURE__ */ new Map(), this._plugin = null, this._pluginProperty = null, this._pluginApi = null, this._pluginSeq = 0, this._pluginSheets = /* @__PURE__ */ new Set(), this._savedSelection = null, this._rafHandle = null, this._composing = !1, this._isRendering = !1, this._$activeLine = null, this._cursorCallbacks = /* @__PURE__ */ new Set(), this._docSelectionChangeHandler = () => {
1416
+ }), this._flowController = new Wt(this), this._localeController = new Kt(this, {
1417
+ onChange: () => this._scheduleRender()
1418
+ }), this._pluginDecorations = /* @__PURE__ */ new Map(), this._patternDecorations = [], this._externalDecorations = [], this._patterns = /* @__PURE__ */ new Map(), this._plugin = null, this._pluginProperty = null, this._pluginApi = null, this._pluginSeq = 0, this._pluginSheets = /* @__PURE__ */ new Set(), this._savedSelection = null, this._rafHandle = null, this._composing = !1, this._contentAttributesPendingRender = !1, this._tabMovesFocus = !1, this._isRendering = !1, this._$activeLine = null, this._cursorCallbacks = /* @__PURE__ */ new Set(), this._docSelectionChangeHandler = () => {
1475
1419
  document.activeElement === this && this._onSelectionChange();
1476
- }, this._undoStack = [], this._undoIndex = -1, this._resizeObserver = null, this._gutterLabels = [], this._onTextareaInvalid = () => {
1420
+ }, this._undoStack = [], this._undoIndex = -1, this._resizeObserver = null, this._gutterBlockAxis = null, this._gutterLabels = [], this._accessibleGutterLines = /* @__PURE__ */ new Set(), this._foldedRanges = [], this._foldBounds = [], this._hiddenGutterLines = /* @__PURE__ */ new Set(), this._onTextareaInvalid = () => {
1477
1421
  this._$editor && this._$editor.setAttribute("aria-invalid", "true");
1478
1422
  }, this._onInputEvent = () => {
1479
1423
  this._composing || this._onInput();
1480
1424
  }, this._onBeforeInput = (t) => {
1481
- !this._composing && !t.isComposing && (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") && (t.preventDefault(), this._insertText(`
1425
+ if (!(this.readOnly || this._isWidgetEvent(t))) {
1426
+ if (this._revealFoldForEdit(t.inputType)) {
1427
+ t.preventDefault();
1428
+ return;
1429
+ }
1430
+ !this._composing && !t.isComposing && (t.inputType === "insertParagraph" || t.inputType === "insertLineBreak") && (t.preventDefault(), this._insertText(`
1482
1431
  `));
1432
+ }
1483
1433
  }, this._onSelectionChange = () => {
1484
1434
  if (!this._$editor)
1485
1435
  return;
1486
- const t = P(this._$editor);
1436
+ const t = E(this._$editor);
1487
1437
  if (t) {
1488
- this._savedSelection = t, this.dispatchEvent(
1438
+ if (this._savedSelection = t, t.anchorOffset === t.focusOffset && this._revealFoldAtOffset(t.focusOffset))
1439
+ return;
1440
+ this.dispatchEvent(
1489
1441
  new CustomEvent("rc-textarea-select", {
1490
1442
  bubbles: !0,
1491
1443
  composed: !0,
@@ -1500,23 +1452,43 @@ const V = class V extends st {
1500
1452
  i(e, s);
1501
1453
  }
1502
1454
  }, this._onKeyDown = (t) => {
1455
+ if (this.readOnly || this._isWidgetEvent(t))
1456
+ return;
1503
1457
  if (t.key === "Enter" && !this._composing && !t.isComposing) {
1504
- t.preventDefault(), this._insertText(`
1458
+ if (t.preventDefault(), this._revealFoldForEdit("insertParagraph"))
1459
+ return;
1460
+ this._insertText(`
1505
1461
  `);
1506
1462
  return;
1507
1463
  }
1508
- if (t.key === "Tab" && !t.ctrlKey && !t.metaKey && !t.altKey) {
1464
+ if (t.key === "Escape") {
1465
+ this._tabMovesFocus = !0;
1466
+ return;
1467
+ }
1468
+ const e = this._tabMovesFocus;
1469
+ if (this._tabMovesFocus = !1, t.key === "Tab" && !t.shiftKey && !t.ctrlKey && !t.metaKey && !t.altKey) {
1470
+ if (e || this._$editor?.querySelector(".widget:not([aria-hidden])"))
1471
+ return;
1509
1472
  t.preventDefault(), this._insertText(" ");
1510
1473
  return;
1511
1474
  }
1512
- const e = (t.ctrlKey || t.metaKey) && t.key === "z" && !t.shiftKey, s = (t.ctrlKey || t.metaKey) && t.key === "y" || (t.ctrlKey || t.metaKey) && t.shiftKey && t.key === "z";
1513
- if (e) {
1475
+ const s = (t.ctrlKey || t.metaKey) && t.key === "z" && !t.shiftKey, i = (t.ctrlKey || t.metaKey) && t.key === "y" || (t.ctrlKey || t.metaKey) && t.shiftKey && t.key === "z";
1476
+ if (s) {
1514
1477
  t.preventDefault(), this._undo();
1515
1478
  return;
1516
1479
  }
1517
- s && (t.preventDefault(), this._redo());
1480
+ i && (t.preventDefault(), this._redo());
1481
+ }, this._onCopy = (t) => {
1482
+ if (!this._$editor || this._isWidgetEvent(t) || !t.clipboardData || !this._$editor.querySelector(".widget") && this._foldedRanges.length === 0)
1483
+ return;
1484
+ const e = E(this._$editor);
1485
+ if (!e || e.anchorOffset === e.focusOffset)
1486
+ return;
1487
+ const s = Math.min(e.anchorOffset, e.focusOffset), i = Math.max(e.anchorOffset, e.focusOffset);
1488
+ t.clipboardData.setData("text/plain", J(this._$editor).slice(s, i)), t.preventDefault(), t.type === "cut" && !this.readOnly && this._insertText("");
1518
1489
  }, this._onPaste = (t) => {
1519
- t.preventDefault();
1490
+ if (this.readOnly || this._isWidgetEvent(t) || (t.preventDefault(), this._revealFoldForEdit("insertFromPaste")))
1491
+ return;
1520
1492
  const e = t.clipboardData?.getData("text/plain") ?? "";
1521
1493
  if (!e)
1522
1494
  return;
@@ -1526,6 +1498,13 @@ const V = class V extends st {
1526
1498
  this._insertText(s);
1527
1499
  };
1528
1500
  }
1501
+ /**
1502
+ * Whether the slotted `<textarea>` is `readonly`. The native control is the
1503
+ * source of truth; set `readonly` on it to change this state.
1504
+ */
1505
+ get readOnly() {
1506
+ return this._readOnly;
1507
+ }
1529
1508
  get plugin() {
1530
1509
  return this._pluginProperty;
1531
1510
  }
@@ -1556,20 +1535,88 @@ const V = class V extends st {
1556
1535
  }
1557
1536
  connectedCallback() {
1558
1537
  super.connectedCallback(), this._pluginProperty && !this._plugin && this.usePlugin(this._pluginProperty), document.addEventListener("selectionchange", this._docSelectionChangeHandler);
1538
+ const t = this._$textareaRef?.deref();
1539
+ t && (this._observeTextarea(t), this._syncReadOnly(), this._syncContentAttributes());
1559
1540
  }
1560
1541
  disconnectedCallback() {
1561
- super.disconnectedCallback(), document.removeEventListener("selectionchange", this._docSelectionChangeHandler), this._plugin?.destroy?.(), this._plugin = null, this._pluginApi = null, this._clearPluginSheets(), this._cursorCallbacks.clear(), this._resizeObserver?.disconnect(), this._$textareaRef?.deref()?.removeEventListener("invalid", this._onTextareaInvalid), this._rafHandle !== null && (cancelAnimationFrame(this._rafHandle), this._rafHandle = null);
1542
+ super.disconnectedCallback(), document.removeEventListener("selectionchange", this._docSelectionChangeHandler), this._plugin?.destroy?.(), this._plugin = null, this._pluginApi = null, this._clearPluginSheets(), this._cursorCallbacks.clear(), this._resizeObserver?.disconnect(), this._textareaAttributeObserver?.disconnect(), this._$textareaRef?.deref()?.removeEventListener("invalid", this._onTextareaInvalid), this._rafHandle !== null && (cancelAnimationFrame(this._rafHandle), this._rafHandle = null);
1562
1543
  }
1563
1544
  firstUpdated() {
1564
- this._$editor && (this._document = new te(this._$editor), this._bindEditorEvents(this._$editor), this._syncLabel()), this._resizeObserver = new ResizeObserver(() => {
1545
+ this._$editor && (this._document = new be(this._$editor), this._bindEditorEvents(this._$editor), this._syncLabel()), this._resizeObserver = new ResizeObserver(() => {
1565
1546
  this._syncGutter(), this._syncGutterHeights();
1566
- }), this._resizeObserver.observe(this), this._scheduleRender();
1547
+ }), this._resizeObserver.observe(this), this._syncReadOnly(), this._syncContentAttributes(), this._scheduleRender();
1567
1548
  }
1568
1549
  updated(t) {
1569
- t.has("readOnly") && (this._$editor && (this._$editor.contentEditable = this.readOnly ? "false" : "true"), this._syncGutterHeights(), this._textareaController.sync());
1550
+ (t.has("lineNumbers") || t.has("gutter") || t.has("lineDirection")) && this._scheduleRender(), this._syncContentDirection();
1551
+ }
1552
+ _observeTextarea(t) {
1553
+ this._textareaAttributeObserver ??= new MutationObserver((e) => {
1554
+ this._syncReadOnly(), this._syncContentAttributes(), e.some((s) => s.attributeName === "lang" || s.attributeName === "dir") && (this._composing ? this._contentAttributesPendingRender = !0 : this._scheduleRender());
1555
+ }), this._textareaAttributeObserver.disconnect(), this._textareaAttributeObserver.observe(t, {
1556
+ attributes: !0,
1557
+ attributeFilter: ["readonly", "lang", "dir", "spellcheck"]
1558
+ });
1559
+ }
1560
+ /**
1561
+ * Mirror the native textarea's content attributes onto the editor. `lang`
1562
+ * picks glyphs, the spelling dictionary and word boundaries; `spellcheck`
1563
+ * stays off unless the textarea sets it. The host's own `lang` is the
1564
+ * interface language and is never copied.
1565
+ */
1566
+ _syncContentAttributes() {
1567
+ if (!this._$editor)
1568
+ return;
1569
+ const t = this._$textareaRef?.deref(), e = t?.getAttribute("lang") ?? null;
1570
+ e === null ? this._$editor.removeAttribute("lang") : this._$editor.getAttribute("lang") !== e && this._$editor.setAttribute("lang", e), this._$editor.spellcheck = t?.hasAttribute("spellcheck") ? t.spellcheck : !1, this._syncContentDirection();
1571
+ }
1572
+ /**
1573
+ * Set the editor's base direction from the textarea's `dir`. `auto` reads
1574
+ * the native control's directionality, including its LTR neutral fallback;
1575
+ * without `dir` the editor inherits. Composition keeps the current direction
1576
+ * so the IME session isn't disturbed.
1577
+ */
1578
+ _syncContentDirection() {
1579
+ if (!this._$editor || this._composing)
1580
+ return;
1581
+ const t = this._$textareaRef?.deref(), e = t?.getAttribute("dir")?.toLowerCase();
1582
+ let s = null;
1583
+ e === "ltr" || e === "rtl" ? s = e : e === "auto" && t && (s = t.matches(":dir(rtl)") ? "rtl" : "ltr"), s === null ? this._$editor.removeAttribute("dir") : this._$editor.getAttribute("dir") !== s && this._$editor.setAttribute("dir", s);
1584
+ }
1585
+ /** The textarea's `lang`, or `''` when it sets none. */
1586
+ _contentLang() {
1587
+ return this._$textareaRef?.deref()?.getAttribute("lang") ?? "";
1588
+ }
1589
+ /** The editor's resolved base direction. */
1590
+ _contentDirection() {
1591
+ return V(this._$editor ?? this).rtl ? "rtl" : "ltr";
1592
+ }
1593
+ /**
1594
+ * Mark lines with no strong character so `line-direction="auto"` holds them
1595
+ * to the base direction. Reads the model value, which composition text
1596
+ * doesn't reach until `compositionend`, so a composing line keeps its mark.
1597
+ */
1598
+ _syncLineDirections(t) {
1599
+ if (!this._$editor)
1600
+ return;
1601
+ const e = this.lineDirection === "auto", s = t.split(`
1602
+ `), i = this._$editor.querySelectorAll(":scope > .line");
1603
+ for (const [n, o] of i.entries())
1604
+ o.classList.toggle(
1605
+ "line--neutral",
1606
+ e && yt(s[n] ?? "") === null
1607
+ );
1608
+ }
1609
+ /**
1610
+ * Mirror the native textarea's `readonly` attribute: the editor stays a
1611
+ * focusable, selectable textbox that announces `aria-readonly`, and edits
1612
+ * are blocked by the existing input guards.
1613
+ */
1614
+ _syncReadOnly() {
1615
+ const t = this._$textareaRef?.deref()?.readOnly ?? !1, e = t !== this._readOnly;
1616
+ this._readOnly = t, this.toggleAttribute("data-readonly", t), this._$editor && (this._$editor.contentEditable = t ? "false" : "true", t ? (this._$editor.setAttribute("aria-readonly", "true"), this._$editor.tabIndex = 0) : (this._$editor.removeAttribute("aria-readonly"), this._$editor.removeAttribute("tabindex"))), e && this._scheduleRender(), this._$editor && V(this._$editor).block !== this._gutterBlockAxis && this._syncGutterHeights();
1570
1617
  }
1571
1618
  render() {
1572
- return Tt`
1619
+ return Vt`
1573
1620
  <div id="root" part="root">
1574
1621
  <div id="gutter" part="gutter" aria-hidden="true">
1575
1622
  <div id="gutter-cells" part="gutter-cells"></div>
@@ -1579,7 +1626,7 @@ const V = class V extends st {
1579
1626
  <div
1580
1627
  id="editor"
1581
1628
  part="editor"
1582
- contenteditable=${this.readOnly ? "false" : "true"}
1629
+ contenteditable=${this._readOnly ? "false" : "true"}
1583
1630
  role="textbox"
1584
1631
  aria-multiline="true"
1585
1632
  spellcheck="false"
@@ -1596,8 +1643,8 @@ const V = class V extends st {
1596
1643
  this._textareaController.sync();
1597
1644
  }
1598
1645
  _setupTextarea(t, e) {
1599
- if (e && e !== t && e.removeEventListener("invalid", this._onTextareaInvalid), !t) {
1600
- this._$textareaRef = null;
1646
+ if (e && e !== t && e.removeEventListener("invalid", this._onTextareaInvalid), this._textareaAttributeObserver?.disconnect(), !t) {
1647
+ this._$textareaRef = null, this._syncReadOnly(), this._syncContentAttributes(), this._scheduleRender();
1601
1648
  return;
1602
1649
  }
1603
1650
  if (this._$textareaRef = new WeakRef(t), Object.assign(t.style, {
@@ -1617,14 +1664,14 @@ const V = class V extends st {
1617
1664
  const s = t.getAttribute("placeholder");
1618
1665
  s && this._$editor.setAttribute("aria-placeholder", s);
1619
1666
  }
1620
- this._initialValueResolved ? t.value = this._value : (this._value = t.value, this._initialValueResolved = !0), t.addEventListener("invalid", this._onTextareaInvalid), this._syncTypography(t), this._scheduleRender();
1667
+ this._initialValueResolved ? t.value = this._value : (this._value = t.value, this._initialValueResolved = !0), t.addEventListener("invalid", this._onTextareaInvalid), this._observeTextarea(t), this._syncReadOnly(), this._syncContentAttributes(), this._syncTypography(t), this._scheduleRender();
1621
1668
  }
1622
1669
  _bindEditorEvents(t) {
1623
1670
  t.addEventListener("compositionstart", () => {
1624
1671
  this._composing = !0;
1625
1672
  }), t.addEventListener("compositionend", () => {
1626
- this._composing = !1, this._onInput();
1627
- }), t.addEventListener("beforeinput", this._onBeforeInput), t.addEventListener("input", this._onInputEvent), t.addEventListener("keydown", this._onKeyDown), t.addEventListener("paste", this._onPaste), t.addEventListener("focus", () => {
1673
+ this._composing = !1, this._onInput(), this._contentAttributesPendingRender && (this._contentAttributesPendingRender = !1, this._syncContentDirection(), this._scheduleRender());
1674
+ }), t.addEventListener("beforeinput", this._onBeforeInput), t.addEventListener("input", this._onInputEvent), t.addEventListener("keydown", this._onKeyDown), t.addEventListener("paste", this._onPaste), t.addEventListener("copy", this._onCopy), t.addEventListener("cut", this._onCopy), t.addEventListener("focus", () => {
1628
1675
  this.dispatchEvent(
1629
1676
  new CustomEvent("rc-textarea-focus", {
1630
1677
  bubbles: !0,
@@ -1632,7 +1679,7 @@ const V = class V extends st {
1632
1679
  })
1633
1680
  );
1634
1681
  }), t.addEventListener("blur", () => {
1635
- this.dispatchEvent(
1682
+ this._tabMovesFocus = !1, this.dispatchEvent(
1636
1683
  new CustomEvent("rc-textarea-blur", {
1637
1684
  bubbles: !0,
1638
1685
  composed: !0
@@ -1640,21 +1687,41 @@ const V = class V extends st {
1640
1687
  ), this._$activeLine?.classList.remove("line--active"), this._$activeLine = null;
1641
1688
  });
1642
1689
  }
1690
+ _revealFoldAtOffset(t) {
1691
+ for (const e of this._foldBounds)
1692
+ if (t >= e.from && t <= e.to)
1693
+ return e.reveal(), !0;
1694
+ return !1;
1695
+ }
1696
+ _revealFoldForEdit(t) {
1697
+ if (!this._$editor)
1698
+ return !1;
1699
+ const e = E(this._$editor) ?? this._savedSelection;
1700
+ if (!e)
1701
+ return !1;
1702
+ const s = Math.min(e.anchorOffset, e.focusOffset), i = Math.max(e.anchorOffset, e.focusOffset);
1703
+ for (const n of this._foldBounds) {
1704
+ const o = s < n.to && i > n.from, a = s === i && s >= n.from && s <= n.to, l = s === i && (t.endsWith("Forward") && s === n.anchorEnd || t.endsWith("Backward") && s === n.to + 1), c = s === i && s === n.anchorEnd && (t === "insertParagraph" || t === "insertLineBreak" || t === "insertFromPaste");
1705
+ if (o || a || l || c)
1706
+ return n.reveal(), !0;
1707
+ }
1708
+ return !1;
1709
+ }
1643
1710
  _onInput() {
1644
1711
  if (!this._$editor)
1645
1712
  return;
1646
- const t = ee(this._$editor);
1713
+ const t = J(this._$editor);
1647
1714
  if (t === this._value)
1648
1715
  return;
1649
- const e = this._value, s = this._savedSelection, i = j(
1716
+ const e = this._value, s = this._savedSelection, i = Q(
1650
1717
  [...this._pluginDecorations.values()],
1651
1718
  e,
1652
1719
  t
1653
1720
  );
1654
1721
  this._pluginDecorations.clear();
1655
- for (const r of i)
1656
- this._pluginDecorations.set(r.id, r);
1657
- this._value = t, this._syncTextareaValue(!0), this._savedSelection = P(this._$editor), this._undoStack.length === 0 && (this._undoStack.push({
1722
+ for (const n of i)
1723
+ this._pluginDecorations.set(n.id, n);
1724
+ this._value = t, this._syncTextareaValue(!0), this._savedSelection = E(this._$editor), this._undoStack.length === 0 && (this._undoStack.push({
1658
1725
  value: e,
1659
1726
  anchorOffset: s?.anchorOffset ?? 0,
1660
1727
  focusOffset: s?.focusOffset ?? 0
@@ -1663,19 +1730,15 @@ const V = class V extends st {
1663
1730
  _updateActiveLine() {
1664
1731
  if (!this._$editor)
1665
1732
  return;
1666
- const t = this.shadowRoot.getSelection?.() ?? window.getSelection();
1667
- let e = null;
1668
- if (t?.focusNode && this._$editor.contains(t.focusNode)) {
1669
- let s = t.focusNode;
1670
- for (; s && s !== this._$editor; ) {
1671
- if (s instanceof HTMLElement && s.classList.contains("line")) {
1672
- e = s;
1673
- break;
1674
- }
1675
- s = s.parentNode;
1733
+ let t = null, e = ve(this._$editor);
1734
+ for (; e && e !== this._$editor; ) {
1735
+ if (e instanceof HTMLElement && e.classList.contains("line")) {
1736
+ t = e;
1737
+ break;
1676
1738
  }
1739
+ e = e.parentNode;
1677
1740
  }
1678
- e !== this._$activeLine && (this._$activeLine?.classList.remove("line--active"), this._$activeLine = e, this._$activeLine?.classList.add("line--active"), this._updateActiveGutterCell());
1741
+ t !== this._$activeLine && (this._$activeLine?.classList.remove("line--active"), this._$activeLine = t, this._$activeLine?.classList.add("line--active"), this._updateActiveGutterCell());
1679
1742
  }
1680
1743
  _updateActiveGutterCell() {
1681
1744
  if (!this._$gutterCells)
@@ -1693,23 +1756,26 @@ const V = class V extends st {
1693
1756
  }
1694
1757
  }
1695
1758
  }
1759
+ _isWidgetEvent(t) {
1760
+ return t.composedPath().some((e) => e instanceof HTMLElement && e.classList.contains("widget"));
1761
+ }
1696
1762
  _insertText(t) {
1697
1763
  if (this._$editor) {
1698
1764
  if (t.includes(`
1699
- `)) {
1700
- const e = P(this._$editor) ?? this._savedSelection, s = Math.min(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), i = Math.max(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), r = this._value, o = r.slice(0, s) + t + r.slice(i), a = s + t.length, l = j(
1765
+ `) || t === "") {
1766
+ const e = E(this._$editor) ?? this._savedSelection, s = Math.min(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), i = Math.max(e?.anchorOffset ?? 0, e?.focusOffset ?? 0), n = this._value, o = n.slice(0, s) + t + n.slice(i), a = s + t.length, l = Q(
1701
1767
  [...this._pluginDecorations.values()],
1702
- r,
1768
+ n,
1703
1769
  o
1704
1770
  );
1705
1771
  this._pluginDecorations.clear();
1706
- for (const h of l)
1707
- this._pluginDecorations.set(h.id, h);
1772
+ for (const c of l)
1773
+ this._pluginDecorations.set(c.id, c);
1708
1774
  this._value = o, this._syncTextareaValue(!0), this._savedSelection = {
1709
1775
  anchorOffset: a,
1710
1776
  focusOffset: a
1711
1777
  }, this._undoStack.length === 0 && (this._undoStack.push({
1712
- value: r,
1778
+ value: n,
1713
1779
  anchorOffset: e?.anchorOffset ?? 0,
1714
1780
  focusOffset: e?.focusOffset ?? 0
1715
1781
  }), this._undoIndex = 0), this._pushUndo(this._savedSelection), this._dispatchChange(o), this._scheduleRender();
@@ -1730,17 +1796,17 @@ const V = class V extends st {
1730
1796
  wrapSelection(t, e) {
1731
1797
  if (!this._$editor)
1732
1798
  return;
1733
- const s = P(this._$editor) ?? this._savedSelection;
1799
+ const s = E(this._$editor) ?? this._savedSelection;
1734
1800
  if (!s || s.anchorOffset === s.focusOffset)
1735
1801
  return;
1736
- const i = Math.min(s.anchorOffset, s.focusOffset), r = Math.max(s.anchorOffset, s.focusOffset), o = this._value.slice(i, r), a = this._value, l = a.slice(0, i) + t + o + e + a.slice(r), h = j(
1802
+ const i = Math.min(s.anchorOffset, s.focusOffset), n = Math.max(s.anchorOffset, s.focusOffset), o = this._value.slice(i, n), a = this._value, l = a.slice(0, i) + t + o + e + a.slice(n), c = Q(
1737
1803
  [...this._pluginDecorations.values()],
1738
1804
  a,
1739
1805
  l
1740
1806
  );
1741
1807
  this._pluginDecorations.clear();
1742
- for (const c of h)
1743
- this._pluginDecorations.set(c.id, c);
1808
+ for (const h of c)
1809
+ this._pluginDecorations.set(h.id, h);
1744
1810
  this._value = l, this._syncTextareaValue(!0), this._savedSelection = {
1745
1811
  anchorOffset: i + t.length,
1746
1812
  focusOffset: i + t.length + o.length
@@ -1763,13 +1829,15 @@ const V = class V extends st {
1763
1829
  anchorOffset: t?.anchorOffset ?? 0,
1764
1830
  focusOffset: t?.focusOffset ?? 0
1765
1831
  };
1766
- this._undoStack = this._undoStack.slice(0, this._undoIndex + 1), this._undoStack.push(e), this._undoStack.length > de && this._undoStack.shift(), this._undoIndex = this._undoStack.length - 1;
1832
+ this._undoStack = this._undoStack.slice(0, this._undoIndex + 1), this._undoStack.push(e), this._undoStack.length > ke && this._undoStack.shift(), this._undoIndex = this._undoStack.length - 1;
1767
1833
  }
1768
1834
  _undo() {
1769
- this._undoIndex <= 0 || (this._undoIndex--, this._applyUndoEntry(this._undoStack[this._undoIndex]));
1835
+ const t = this._undoStack[this._undoIndex - 1];
1836
+ t && (this._undoIndex--, this._applyUndoEntry(t));
1770
1837
  }
1771
1838
  _redo() {
1772
- this._undoIndex >= this._undoStack.length - 1 || (this._undoIndex++, this._applyUndoEntry(this._undoStack[this._undoIndex]));
1839
+ const t = this._undoStack[this._undoIndex + 1];
1840
+ t && (this._undoIndex++, this._applyUndoEntry(t));
1773
1841
  }
1774
1842
  _applyUndoEntry(t) {
1775
1843
  this._value = t.value, this._savedSelection = {
@@ -1824,17 +1892,28 @@ const V = class V extends st {
1824
1892
  return null;
1825
1893
  }
1826
1894
  },
1895
+ get contentDirection() {
1896
+ return t._contentDirection();
1897
+ },
1898
+ get contentLang() {
1899
+ return t._contentLang();
1900
+ },
1901
+ lineDirection(e) {
1902
+ const s = t._value.split(`
1903
+ `)[e - 1];
1904
+ return (t.lineDirection === "auto" && s !== void 0 ? yt(s) : null) ?? t._contentDirection();
1905
+ },
1827
1906
  getWordAtCursor() {
1828
1907
  const e = t._savedSelection?.focusOffset ?? 0, s = t._value;
1829
1908
  if (!s)
1830
1909
  return null;
1831
- let i = e;
1832
- for (; i > 0 && /\w/.test(s[i - 1]); )
1833
- i--;
1834
- let r = e;
1835
- for (; r < s.length && /\w/.test(s[r]); )
1836
- r++;
1837
- return i === r ? null : { word: s.slice(i, r), from: i, to: r };
1910
+ const i = s.lastIndexOf(`
1911
+ `, e - 1) + 1, n = s.indexOf(`
1912
+ `, e), o = s.slice(i, n === -1 ? void 0 : n), a = $e(o, e - i, t._contentLang());
1913
+ if (!a)
1914
+ return null;
1915
+ const l = i + a.from, c = i + a.to;
1916
+ return { word: s.slice(l, c), from: l, to: c };
1838
1917
  },
1839
1918
  onCursorMove(e) {
1840
1919
  return t._cursorCallbacks.add(e), () => {
@@ -1842,7 +1921,7 @@ const V = class V extends st {
1842
1921
  };
1843
1922
  },
1844
1923
  addDecoration(e) {
1845
- return lt(t._pluginDecorations, e);
1924
+ return bt(t._pluginDecorations, e);
1846
1925
  },
1847
1926
  removeDecoration(e) {
1848
1927
  t._pluginDecorations.delete(e);
@@ -1851,7 +1930,7 @@ const V = class V extends st {
1851
1930
  t._pluginDecorations.clear();
1852
1931
  },
1853
1932
  setDecorations(e) {
1854
- ae(t._pluginDecorations, e);
1933
+ Ee(t._pluginDecorations, e);
1855
1934
  },
1856
1935
  getDecorations() {
1857
1936
  return [...t._pluginDecorations.values()];
@@ -1872,16 +1951,16 @@ const V = class V extends st {
1872
1951
  )), t._pluginSheets.delete(e);
1873
1952
  },
1874
1953
  parseDecorationsFromHtml(e) {
1875
- return ct(e);
1954
+ return xt(e);
1876
1955
  },
1877
1956
  decorationsFromTokens(e, s) {
1878
1957
  const i = [];
1879
- for (const r of e) {
1880
- const o = s[r.type];
1958
+ for (const n of e) {
1959
+ const o = s[n.type];
1881
1960
  o && i.push({
1882
1961
  type: "mark",
1883
- from: r.from,
1884
- to: r.to,
1962
+ from: n.from,
1963
+ to: n.to,
1885
1964
  ...o
1886
1965
  });
1887
1966
  }
@@ -1916,7 +1995,7 @@ const V = class V extends st {
1916
1995
  * editor.removePattern(id);
1917
1996
  */
1918
1997
  addPattern(t) {
1919
- const e = M();
1998
+ const e = U();
1920
1999
  return this._patterns.set(e, { ...t, id: e }), this._scheduleRender(), e;
1921
2000
  }
1922
2001
  /** Remove a previously registered pattern by the ID returned from `addPattern`. */
@@ -1940,39 +2019,59 @@ const V = class V extends st {
1940
2019
  try {
1941
2020
  let e = this._value;
1942
2021
  if (this._plugin && this._pluginApi && this._plugin.transform && this.readOnly) {
1943
- const o = this._plugin.transform(this._value, this._pluginApi);
1944
- typeof o == "string" && (e = o);
2022
+ const l = this._plugin.transform(this._value, this._pluginApi);
2023
+ typeof l == "string" && (e = l);
1945
2024
  }
1946
- const { markDecorations: s, lineDecorations: i } = le(
2025
+ const { markDecorations: s, lineDecorations: i } = Ce(
1947
2026
  e,
1948
2027
  [...this._patterns.values()]
1949
2028
  );
1950
2029
  if (this._patternDecorations = [
1951
- ...s.map((o) => ({ ...o, id: M() })),
1952
- ...i.map((o) => ({ ...o, id: M() }))
2030
+ ...s.map((l) => ({ ...l, id: U() })),
2031
+ ...i.map((l) => ({ ...l, id: U() }))
1953
2032
  ], this._plugin && this._pluginApi) {
1954
- const o = this._pluginApi;
1955
- if (this._plugin.update && (await this._plugin.update(e, o), t !== this._pluginSeq))
2033
+ const l = this._pluginApi;
2034
+ if (this._plugin.update && (await this._plugin.update(e, l), t !== this._pluginSeq))
1956
2035
  return;
1957
2036
  if (this._plugin.highlight) {
1958
- const a = await this._plugin.highlight(e, o);
2037
+ const c = await this._plugin.highlight(e, l);
1959
2038
  if (t !== this._pluginSeq)
1960
2039
  return;
1961
- if (typeof a == "string") {
1962
- const l = ct(a);
1963
- for (const h of l)
1964
- lt(this._pluginDecorations, h);
2040
+ if (typeof c == "string") {
2041
+ const h = xt(c);
2042
+ for (const u of h)
2043
+ bt(this._pluginDecorations, u);
1965
2044
  }
1966
2045
  }
1967
2046
  }
1968
- const r = [
2047
+ const n = [
1969
2048
  ...this._pluginDecorations.values(),
1970
2049
  ...this._patternDecorations,
1971
- ...this._externalDecorations.map((o) => ({ ...o, id: M() }))
2050
+ ...this._externalDecorations.map((l) => ({ ...l, id: U() }))
1972
2051
  ];
1973
- if (!this._$editor)
2052
+ if (this._foldedRanges = n.filter(
2053
+ (l) => l.type === "fold"
2054
+ ), this._foldBounds = Se(e, this._foldedRanges), this._hiddenGutterLines = new Set(
2055
+ this._foldedRanges.flatMap(
2056
+ (l) => Array.from(
2057
+ { length: Math.max(0, l.toLine - l.fromLine + 1) },
2058
+ (c, h) => l.fromLine + h
2059
+ )
2060
+ )
2061
+ ), !this._$editor)
1974
2062
  return;
1975
- this._document.build(e, r), this._savedSelection && ie(this._$editor, this._savedSelection), this._$activeLine = null, this._updateActiveLine(), this._syncGutter(this._computeGutterLabels(r, e)), this._syncGutterHeights();
2063
+ const o = this.shadowRoot?.activeElement;
2064
+ let a = J(this._$editor) === e ? E(this._$editor) ?? this._savedSelection : this._savedSelection;
2065
+ if (a?.anchorOffset === a?.focusOffset) {
2066
+ const l = a?.focusOffset, c = this._foldBounds.filter(
2067
+ (h) => l !== void 0 && l >= h.from && l <= h.to
2068
+ );
2069
+ if (c.length > 0) {
2070
+ const h = Math.min(...c.map((u) => u.anchorEnd));
2071
+ a = { anchorOffset: h, focusOffset: h }, this._savedSelection = a;
2072
+ }
2073
+ }
2074
+ this._syncContentDirection(), this._document.build(e, n), this._syncLineDirections(e), o instanceof HTMLElement && o !== this._$editor && o.isConnected && this.shadowRoot?.activeElement !== o && o.focus({ preventScroll: !0 }), a && this.shadowRoot?.activeElement === this._$editor && ye(this._$editor, a), this._$activeLine = null, this._updateActiveLine(), this._syncGutter(this._computeGutterLabels(n, e)), this._syncGutterHeights();
1976
2075
  } finally {
1977
2076
  this._isRendering = !1;
1978
2077
  }
@@ -1988,43 +2087,52 @@ const V = class V extends st {
1988
2087
  */
1989
2088
  _computeGutterLabels(t, e = this._value) {
1990
2089
  const s = e.split(`
1991
- `), i = /* @__PURE__ */ new Map();
1992
- for (const r of t)
1993
- r.type === "line" && r.gutterContent !== void 0 && i.set(r.line, r.gutterContent);
1994
- return s.map((r, o) => {
1995
- const a = o + 1;
1996
- return i.has(a) ? i.get(a) : this.lineNumbers ? String(a) : null;
2090
+ `), i = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
2091
+ for (const l of t)
2092
+ l.type === "line" && l.gutterContent !== void 0 && (i.set(l.line, l.gutterContent), l.gutterAccessible ? n.add(l.line) : n.delete(l.line), l.gutterLineNumber ? o.add(l.line) : o.delete(l.line));
2093
+ this._accessibleGutterLines = n;
2094
+ const a = Gt(this._localeController.locale, { useGrouping: !1 });
2095
+ return s.map((l, c) => {
2096
+ const h = c + 1, u = i.get(h);
2097
+ return u !== void 0 ? this.lineNumbers && o.has(h) && u !== null ? { number: a.format(h), content: u } : u : this.lineNumbers ? a.format(h) : null;
1997
2098
  });
1998
2099
  }
1999
2100
  /**
2000
- * Synchronize the pixel height of each gutter cell to match the
2101
+ * Synchronize the block size of each gutter cell to match the
2001
2102
  * corresponding `.line` element in the editor.
2002
2103
  *
2003
- * In non-word-wrap mode the gutter uses a uniform `line-height` mirrored
2004
- * from the editor's first line. In word-wrap mode each cell gets an explicit
2005
- * `height` so wrapped lines stay vertically aligned with their gutter label.
2006
- * Also copies the editor's computed `paddingTop`/`paddingBottom` to the
2104
+ * In non-word-wrap mode without block widgets the gutter uses a uniform
2105
+ * line height. Wrapped lines and block widgets use per-line heights instead.
2106
+ * Also copies the editor's computed block padding to the
2007
2107
  * gutter to compensate for browser UA overrides on contenteditable.
2008
2108
  */
2009
2109
  _syncGutterHeights() {
2010
2110
  if (!this._$gutterCells || !this._$editor)
2011
2111
  return;
2012
- const t = getComputedStyle(this._$editor), e = t.paddingTop, s = t.paddingBottom;
2013
- this._$gutterCells.style.paddingTop !== e && (this._$gutterCells.style.paddingTop = e), this._$gutterCells.style.paddingBottom !== s && (this._$gutterCells.style.paddingBottom = s);
2014
- const i = this._$editor.querySelectorAll(".line"), r = this._$gutterCells.children;
2015
- if (!this.wordWrap) {
2112
+ const t = getComputedStyle(this._$editor), e = t.paddingBlockStart, s = t.paddingBlockEnd;
2113
+ this._$gutterCells.style.paddingBlockStart !== e && (this._$gutterCells.style.paddingBlockStart = e), this._$gutterCells.style.paddingBlockEnd !== s && (this._$gutterCells.style.paddingBlockEnd = s);
2114
+ const i = this._$editor.querySelectorAll(".line"), n = this._$gutterCells.children, o = V(this._$editor), a = this._$editor.getBoundingClientRect(), l = jt(this._$gutterCells);
2115
+ if (this._gutterBlockAxis = o.block, !this.wordWrap && !this._$editor.querySelector(".widget--block")) {
2016
2116
  if (i.length > 0) {
2017
- const o = `${i[0].getBoundingClientRect().height}px`;
2018
- this._$gutterCells.style.lineHeight !== o && (this._$gutterCells.style.lineHeight = o);
2117
+ const h = `${ht(
2118
+ i[0].getBoundingClientRect(),
2119
+ a,
2120
+ o
2121
+ ).blockSize / l}px`;
2122
+ this._$gutterCells.style.lineHeight !== h && (this._$gutterCells.style.lineHeight = h);
2019
2123
  }
2020
- for (let o = 0; o < r.length; o++)
2021
- r[o].style.height = "";
2124
+ for (let c = 0; c < n.length; c++)
2125
+ n[c].style.blockSize = "";
2022
2126
  return;
2023
2127
  }
2024
2128
  this._$gutterCells.style.lineHeight && (this._$gutterCells.style.lineHeight = "");
2025
- for (let o = 0; o < i.length && o < r.length; o++) {
2026
- const l = `${i[o].getBoundingClientRect().height}px`, h = r[o];
2027
- h.style.height !== l && (h.style.height = l);
2129
+ for (let c = 0; c < i.length && c < n.length; c++) {
2130
+ const u = `${ht(
2131
+ i.item(c).getBoundingClientRect(),
2132
+ a,
2133
+ o
2134
+ ).blockSize / l}px`, d = n[c];
2135
+ d.style.blockSize !== u && (d.style.blockSize = u);
2028
2136
  }
2029
2137
  }
2030
2138
  /**
@@ -2037,16 +2145,29 @@ const V = class V extends st {
2037
2145
  if (!this.lineNumbers && !this.gutter || !this._$gutterCells)
2038
2146
  return;
2039
2147
  t !== void 0 && (this._gutterLabels = t);
2040
- const e = this._gutterLabels;
2041
- for (; this._$gutterCells.children.length < e.length; ) {
2042
- const s = document.createElement("span");
2043
- s.className = "gutter-cell", this._$gutterCells.appendChild(s);
2148
+ const e = this._gutterLabels, s = this._$gutterCells.parentElement;
2149
+ for (this._accessibleGutterLines.size > 0 ? s?.removeAttribute("aria-hidden") : s?.setAttribute("aria-hidden", "true"); this._$gutterCells.children.length < e.length; ) {
2150
+ const i = document.createElement("span");
2151
+ i.className = "gutter-cell", this._$gutterCells.appendChild(i);
2044
2152
  }
2045
2153
  for (; this._$gutterCells.children.length > e.length; )
2046
- this._$gutterCells.removeChild(this._$gutterCells.lastChild);
2047
- for (let s = 0; s < e.length; s++) {
2048
- const i = e[s] ?? "", r = this._$gutterCells.children[s];
2049
- r.textContent !== i && (r.textContent = i);
2154
+ this._$gutterCells.lastChild?.remove();
2155
+ for (let i = 0; i < e.length; i++) {
2156
+ const n = e[i] ?? "", o = this._$gutterCells.children[i];
2157
+ if (o.setAttribute("aria-hidden", String(!this._accessibleGutterLines.has(i + 1))), o.hidden = this._hiddenGutterLines.has(i + 1), typeof n == "object" && n !== null && !(n instanceof HTMLElement)) {
2158
+ let a = o.firstElementChild;
2159
+ if (!a?.classList.contains("gutter-cell-composite")) {
2160
+ a = document.createElement("span"), a.className = "gutter-cell-composite";
2161
+ const h = document.createElement("span");
2162
+ h.className = "gutter-cell-number";
2163
+ const u = document.createElement("span");
2164
+ u.className = "gutter-cell-content", a.append(h, u), o.replaceChildren(a);
2165
+ }
2166
+ const l = a.querySelector(":scope > .gutter-cell-number"), c = a.querySelector(":scope > .gutter-cell-content");
2167
+ if (!l || !c)
2168
+ continue;
2169
+ l.textContent !== n.number && (l.textContent = n.number), n.content instanceof HTMLElement ? c.firstChild !== n.content && c.replaceChildren(n.content) : (c.textContent !== n.content || c.firstElementChild) && (c.textContent = n.content);
2170
+ } else n instanceof HTMLElement ? o.firstChild !== n && o.replaceChildren(n) : (o.textContent !== n || o.firstElementChild) && (o.textContent = n);
2050
2171
  }
2051
2172
  }
2052
2173
  _syncLabel() {
@@ -2082,9 +2203,9 @@ const V = class V extends st {
2082
2203
  "tabSize"
2083
2204
  ];
2084
2205
  if (!window.getComputedStyle(this).getPropertyValue("--rc-textarea-font-family"))
2085
- for (const r of s) {
2086
- const o = e[r];
2087
- o && typeof o == "string" && (this._$editor.style[r] = o);
2206
+ for (const n of s) {
2207
+ const o = e[n];
2208
+ o && typeof o == "string" && (this._$editor.style[n] = o);
2088
2209
  }
2089
2210
  }
2090
2211
  _syncTextareaValue(t = !1) {
@@ -2101,86 +2222,87 @@ const V = class V extends st {
2101
2222
  );
2102
2223
  }
2103
2224
  };
2104
- V.styles = ce, V.shadowRootOptions = {
2105
- ...st.shadowRootOptions,
2225
+ j.styles = Ae, j.shadowRootOptions = {
2226
+ ...ct.shadowRootOptions,
2106
2227
  delegatesFocus: !0
2107
2228
  };
2108
- let v = V;
2109
- y([
2110
- b({ type: Boolean, attribute: "line-numbers", reflect: !0 })
2111
- ], v.prototype, "lineNumbers", 2);
2112
- y([
2113
- b({ type: Boolean, attribute: "gutter", reflect: !0 })
2114
- ], v.prototype, "gutter", 2);
2115
- y([
2116
- b({ type: Boolean, attribute: "word-wrap", reflect: !0 })
2117
- ], v.prototype, "wordWrap", 2);
2118
- y([
2119
- b({ type: Boolean, attribute: "auto-grow", reflect: !0 })
2120
- ], v.prototype, "autoGrow", 2);
2121
- y([
2122
- b({ type: Boolean, attribute: "read-only", reflect: !0 })
2123
- ], v.prototype, "readOnly", 2);
2124
- y([
2125
- b({ attribute: !1 })
2126
- ], v.prototype, "plugin", 1);
2127
- y([
2128
- b({ attribute: !1 })
2129
- ], v.prototype, "decorations", 1);
2130
- y([
2131
- tt("#editor")
2132
- ], v.prototype, "_$editor", 2);
2133
- y([
2134
- tt("#gutter-cells")
2135
- ], v.prototype, "_$gutterCells", 2);
2136
- y([
2137
- tt("slot")
2138
- ], v.prototype, "_$slot", 2);
2139
- y([
2140
- b({ type: String })
2141
- ], v.prototype, "value", 1);
2142
- y([
2143
- b({ type: String, attribute: "default-value" })
2144
- ], v.prototype, "defaultValue", 1);
2145
- function we(n, t = {}) {
2229
+ let b = j;
2230
+ v([
2231
+ N({ type: Boolean, attribute: "line-numbers", reflect: !0 })
2232
+ ], b.prototype, "lineNumbers", 2);
2233
+ v([
2234
+ N({ type: Boolean, attribute: "gutter", reflect: !0 })
2235
+ ], b.prototype, "gutter", 2);
2236
+ v([
2237
+ N({ type: Boolean, attribute: "word-wrap", reflect: !0 })
2238
+ ], b.prototype, "wordWrap", 2);
2239
+ v([
2240
+ N({ type: Boolean, attribute: "auto-grow", reflect: !0 })
2241
+ ], b.prototype, "autoGrow", 2);
2242
+ v([
2243
+ N({ attribute: "line-direction", reflect: !0 })
2244
+ ], b.prototype, "lineDirection", 2);
2245
+ v([
2246
+ N({ attribute: !1 })
2247
+ ], b.prototype, "plugin", 1);
2248
+ v([
2249
+ N({ attribute: !1 })
2250
+ ], b.prototype, "decorations", 1);
2251
+ v([
2252
+ rt("#editor")
2253
+ ], b.prototype, "_$editor", 2);
2254
+ v([
2255
+ rt("#gutter-cells")
2256
+ ], b.prototype, "_$gutterCells", 2);
2257
+ v([
2258
+ rt("slot")
2259
+ ], b.prototype, "_$slot", 2);
2260
+ v([
2261
+ N({ type: String })
2262
+ ], b.prototype, "value", 1);
2263
+ v([
2264
+ N({ type: String, attribute: "default-value" })
2265
+ ], b.prototype, "defaultValue", 1);
2266
+ function Ke(r, t = {}) {
2146
2267
  const e = [];
2147
2268
  return {
2148
2269
  mount(s) {
2149
- n.styles && s.adoptStyleSheet(n.styles);
2270
+ r.styles && s.adoptStyleSheet(r.styles);
2150
2271
  for (const i of t.watch ?? []) {
2151
- const r = i(() => s.scheduleUpdate());
2152
- r && e.push(r);
2272
+ const n = i(() => s.scheduleUpdate());
2273
+ n && e.push(n);
2153
2274
  }
2154
2275
  },
2155
2276
  destroy() {
2156
- for (const s of e) s();
2277
+ for (const s of e)
2278
+ s();
2157
2279
  e.length = 0;
2158
2280
  },
2159
2281
  update(s, i) {
2160
- const r = s.split(`
2282
+ const n = s.split(`
2161
2283
  `), o = [];
2162
2284
  let a = 0;
2163
- for (let l = 0; l < r.length; l++) {
2164
- const h = r[l];
2165
- for (const c of n.decorateLine(h, l))
2166
- c.type === "mark" ? o.push({
2167
- ...c,
2168
- from: a + c.from,
2169
- to: a + c.to
2170
- }) : o.push(c);
2171
- a += h.length + 1;
2285
+ for (let l = 0; l < n.length; l++) {
2286
+ const c = n[l];
2287
+ for (const h of r.decorateLine(c, l))
2288
+ h.type === "mark" ? o.push({
2289
+ ...h,
2290
+ from: a + h.from,
2291
+ to: a + h.to
2292
+ }) : o.push(h);
2293
+ a += c.length + 1;
2172
2294
  }
2173
2295
  t.extraDecorations && o.push(...t.extraDecorations(s)), i.setDecorations(o);
2174
2296
  }
2175
2297
  };
2176
2298
  }
2177
- const Et = new CSSStyleSheet();
2178
- Et.replaceSync(`
2299
+ const zt = new CSSStyleSheet();
2300
+ zt.replaceSync(`
2179
2301
  .rc-line-actions {
2180
2302
  display: inline-flex;
2181
2303
  align-items: center;
2182
2304
  gap: var(--rc-line-actions-gap, 2px);
2183
- margin-left: var(--rc-line-actions-margin-start, 6px);
2305
+ margin-inline-start: var(--rc-line-actions-margin-start, 6px);
2184
2306
  vertical-align: middle;
2185
2307
  }
2186
2308
  .rc-line-action-btn {
@@ -2205,7 +2327,7 @@ Et.replaceSync(`
2205
2327
  color: var(--rc-line-action-hover-color, inherit);
2206
2328
  }
2207
2329
  `);
2208
- const ht = "rc-line-actions-popover-style", fe = `
2330
+ const wt = "rc-line-actions-popover-style", Ie = `
2209
2331
  .rc-line-actions-popover {
2210
2332
  position: fixed;
2211
2333
  z-index: 9999;
@@ -2241,9 +2363,9 @@ const ht = "rc-line-actions-popover-style", fe = `
2241
2363
  background: var(--rc-line-action-hover-bg, ButtonFace);
2242
2364
  }
2243
2365
  `;
2244
- class Ct {
2366
+ class Ft {
2245
2367
  constructor(t, e) {
2246
- this._popover = null, this._lastActionsKey = "", this._api = t, this._options = e ?? {}, t.adoptStyleSheet(Et), this._blurHandler = () => this._hidePopover(), t.host.addEventListener("rc-textarea-blur", this._blurHandler);
2368
+ this._popover = null, this._lastActionsKey = "", this._api = t, this._options = e ?? {}, t.adoptStyleSheet(zt), this._blurHandler = () => this._hidePopover(), t.host.addEventListener("rc-textarea-blur", this._blurHandler);
2247
2369
  }
2248
2370
  /**
2249
2371
  * Call from plugin's `update()`. Pass the line index, its actions, the full
@@ -2259,17 +2381,17 @@ class Ct {
2259
2381
  return e.length === 0 ? this._hidePopover() : this._showPopover(e), [];
2260
2382
  if (this._hidePopover(), e.length === 0)
2261
2383
  return [];
2262
- const r = Ct._lineEndOffset(s, t), o = [...e], a = {
2384
+ const n = Ft._lineEndOffset(s, t), o = [...e], a = {
2263
2385
  renderButton: this._options.renderButton,
2264
2386
  createIcon: this._options.createIcon
2265
2387
  };
2266
2388
  return [
2267
2389
  {
2268
2390
  type: "widget",
2269
- offset: r,
2391
+ offset: n,
2270
2392
  side: "after",
2271
2393
  create() {
2272
- return pe(o, a);
2394
+ return Pe(o, a);
2273
2395
  }
2274
2396
  }
2275
2397
  ];
@@ -2288,10 +2410,10 @@ class Ct {
2288
2410
  return this.getDecorations(i, o, e, "popover");
2289
2411
  }
2290
2412
  this._hidePopover();
2291
- const r = [];
2413
+ const n = [];
2292
2414
  for (const [o, a] of t)
2293
- a.length > 0 && r.push(...this.getDecorations(o, a, e, "inline"));
2294
- return r;
2415
+ a.length > 0 && n.push(...this.getDecorations(o, a, e, "inline"));
2416
+ return n;
2295
2417
  }
2296
2418
  /** Remove the floating panel and detach all listeners. Call from plugin `destroy()`. */
2297
2419
  destroy() {
@@ -2310,17 +2432,17 @@ class Ct {
2310
2432
  const s = t.split(`
2311
2433
  `);
2312
2434
  let i = 0;
2313
- for (let r = 0; r < e && r < s.length; r++)
2314
- i += s[r].length + 1;
2315
- return e < s.length && (i += s[e].length), i;
2435
+ for (const n of s.slice(0, e))
2436
+ i += n.length + 1;
2437
+ return i + (s[e]?.length ?? 0);
2316
2438
  }
2317
2439
  _showPopover(t) {
2318
2440
  const e = t.map((s) => s.id).join(",");
2319
- if (!document.getElementById(ht)) {
2441
+ if (!document.getElementById(wt)) {
2320
2442
  const s = document.createElement("style");
2321
- s.id = ht, s.textContent = fe, document.head.appendChild(s);
2443
+ s.id = wt, s.textContent = Ie, document.head.appendChild(s);
2322
2444
  }
2323
- this._popover || (this._popover = document.createElement("div"), this._popover.className = "rc-line-actions-popover", this._popover.addEventListener("mousedown", (s) => s.preventDefault()), document.body.appendChild(this._popover)), e !== this._lastActionsKey && (this._lastActionsKey = e, this._popover.innerHTML = "", me(this._popover, t, this._options)), this._positionPopover();
2445
+ this._popover || (this._popover = document.createElement("div"), this._popover.className = "rc-line-actions-popover", this._popover.addEventListener("mousedown", (s) => s.preventDefault()), document.body.appendChild(this._popover)), e !== this._lastActionsKey && (this._lastActionsKey = e, this._popover.innerHTML = "", Me(this._popover, t, this._options)), this._positionPopover();
2324
2446
  }
2325
2447
  _positionPopover() {
2326
2448
  if (!this._popover)
@@ -2328,40 +2450,40 @@ class Ct {
2328
2450
  const t = this._api.getCursorRect(), e = this._api.host.getBoundingClientRect(), s = this._popover.offsetHeight || 32;
2329
2451
  let i;
2330
2452
  t ? (i = t.bottom + 4, i + s > window.innerHeight && (i = t.top - s - 4)) : i = e.bottom + 4;
2331
- const r = this._popover.offsetWidth || 120;
2332
- let o = e.left;
2333
- o = Math.min(o, window.innerWidth - r - 8), o = Math.max(o, 8), this._popover.style.top = `${i}px`, this._popover.style.left = `${o}px`;
2453
+ const n = this._popover.offsetWidth || 120;
2454
+ let a = Xt("x", V(this._api.host)) ? e.right - n : e.left;
2455
+ a = Math.min(a, window.innerWidth - n - 8), a = Math.max(a, 8), this._popover.style.top = `${i}px`, this._popover.style.left = `${a}px`;
2334
2456
  }
2335
2457
  _hidePopover() {
2336
2458
  this._popover && (this._popover.remove(), this._popover = null, this._lastActionsKey = "");
2337
2459
  }
2338
2460
  }
2339
- function At(n, t) {
2461
+ function Ht(r, t) {
2340
2462
  const e = document.createElement("button");
2341
- if (e.className = "rc-line-action-btn", e.type = "button", e.setAttribute("title", n.label), t.renderButton)
2342
- t.renderButton(n, e);
2343
- else if (n.iconName) {
2344
- const s = t.createIcon?.(n.iconName) ?? null;
2345
- s ? (e.setAttribute("aria-label", n.label), e.appendChild(s)) : (e.dataset.icon = n.iconName, e.setAttribute("aria-label", n.label));
2463
+ if (e.className = "rc-line-action-btn", e.type = "button", e.setAttribute("title", r.label), t.renderButton)
2464
+ t.renderButton(r, e);
2465
+ else if (r.iconName) {
2466
+ const s = t.createIcon?.(r.iconName) ?? null;
2467
+ s ? (e.setAttribute("aria-label", r.label), e.appendChild(s)) : (e.dataset.icon = r.iconName, e.setAttribute("aria-label", r.label));
2346
2468
  } else
2347
- e.textContent = n.label;
2348
- return e.addEventListener("mousedown", (s) => s.preventDefault()), e.addEventListener("click", () => n.onClick()), e;
2469
+ e.textContent = r.label;
2470
+ return e.addEventListener("mousedown", (s) => s.preventDefault()), e.addEventListener("click", () => r.onClick()), e;
2349
2471
  }
2350
- function pe(n, t) {
2472
+ function Pe(r, t) {
2351
2473
  const e = document.createElement("span");
2352
2474
  e.className = "rc-line-actions";
2353
- for (const s of n)
2354
- e.appendChild(At(s, t));
2475
+ for (const s of r)
2476
+ e.appendChild(Ht(s, t));
2355
2477
  return e;
2356
2478
  }
2357
- function me(n, t, e) {
2479
+ function Me(r, t, e) {
2358
2480
  for (const s of t)
2359
- n.appendChild(At(s, e));
2481
+ r.appendChild(Ht(s, e));
2360
2482
  }
2361
2483
  export {
2362
- Ct as L,
2363
- v as R,
2364
- we as c,
2365
- le as m
2484
+ Ft as L,
2485
+ b as R,
2486
+ Ke as c,
2487
+ Ce as m
2366
2488
  };
2367
- //# sourceMappingURL=line-actions-controller-BcsnmSPS.js.map
2489
+ //# sourceMappingURL=line-actions-controller-DUdXQxMA.js.map