@iyio/rtxt 0.7.0 → 0.7.5

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.
@@ -88,9 +88,8 @@ export const getDefaultRTxtTools = ({ fontFamilies, } = {}) => {
88
88
  innerHTML: 'clear',
89
89
  className: 'button-clear',
90
90
  onClick: () => {
91
- var _a, _b;
92
91
  const sel = editor.selection;
93
- const elem = (_a = editor.renderer) === null || _a === void 0 ? void 0 : _a.elem;
92
+ const elem = editor.renderer?.elem;
94
93
  if (!sel) {
95
94
  return;
96
95
  }
@@ -99,7 +98,7 @@ export const getDefaultRTxtTools = ({ fontFamilies, } = {}) => {
99
98
  for (const type of types) {
100
99
  editor.removeFromSelection(sel, type);
101
100
  }
102
- (_b = editor.renderer) === null || _b === void 0 ? void 0 : _b.render();
101
+ editor.renderer?.render();
103
102
  }
104
103
  if (elem) {
105
104
  selectRTxtSelection(sel, elem);
@@ -109,48 +108,39 @@ export const getDefaultRTxtTools = ({ fontFamilies, } = {}) => {
109
108
  },
110
109
  {
111
110
  types: [],
112
- render: (editor) => {
113
- var _a, _b;
114
- return createRTxtToolButton({
115
- editor,
116
- innerHTML: getRTxtIcon({ type: 'alignLeft', fill: (_b = (_a = editor.options.style) === null || _a === void 0 ? void 0 : _a.foregroundColor) !== null && _b !== void 0 ? _b : '#ffffff' }),
117
- onClick: () => {
118
- editor.setSelectedLineAlignment('start');
119
- }
120
- });
121
- },
111
+ render: (editor) => createRTxtToolButton({
112
+ editor,
113
+ innerHTML: getRTxtIcon({ type: 'alignLeft', fill: editor.options.style?.foregroundColor ?? '#ffffff' }),
114
+ onClick: () => {
115
+ editor.setSelectedLineAlignment('start');
116
+ }
117
+ }),
122
118
  isSelected: ({ editor }) => {
123
119
  return editor.getSelectedLines().some(l => !l.align || l.align === 'start');
124
120
  },
125
121
  },
126
122
  {
127
123
  types: [],
128
- render: (editor) => {
129
- var _a, _b;
130
- return createRTxtToolButton({
131
- editor,
132
- innerHTML: getRTxtIcon({ type: 'alignCenter', fill: (_b = (_a = editor.options.style) === null || _a === void 0 ? void 0 : _a.foregroundColor) !== null && _b !== void 0 ? _b : '#ffffff' }),
133
- onClick: () => {
134
- editor.setSelectedLineAlignment('center');
135
- }
136
- });
137
- },
124
+ render: (editor) => createRTxtToolButton({
125
+ editor,
126
+ innerHTML: getRTxtIcon({ type: 'alignCenter', fill: editor.options.style?.foregroundColor ?? '#ffffff' }),
127
+ onClick: () => {
128
+ editor.setSelectedLineAlignment('center');
129
+ }
130
+ }),
138
131
  isSelected: ({ editor }) => {
139
132
  return editor.getSelectedLines().some(l => l.align === 'center');
140
133
  },
141
134
  },
142
135
  {
143
136
  types: [],
144
- render: (editor) => {
145
- var _a, _b;
146
- return createRTxtToolButton({
147
- editor,
148
- innerHTML: getRTxtIcon({ type: 'alignRight', fill: (_b = (_a = editor.options.style) === null || _a === void 0 ? void 0 : _a.foregroundColor) !== null && _b !== void 0 ? _b : '#ffffff' }),
149
- onClick: () => {
150
- editor.setSelectedLineAlignment('end');
151
- },
152
- });
153
- },
137
+ render: (editor) => createRTxtToolButton({
138
+ editor,
139
+ innerHTML: getRTxtIcon({ type: 'alignRight', fill: editor.options.style?.foregroundColor ?? '#ffffff' }),
140
+ onClick: () => {
141
+ editor.setSelectedLineAlignment('end');
142
+ },
143
+ }),
154
144
  isSelected: ({ editor }) => {
155
145
  return editor.getSelectedLines().some(l => l.align === 'end');
156
146
  },
@@ -177,23 +167,19 @@ export const createRTxtFontFamilyTool = (families) => ({
177
167
  editor,
178
168
  options: [
179
169
  { clearType: 'f', label: 'default' },
180
- ...families.map(f => {
181
- var _a, _b;
182
- return ({
183
- clearType: 'f',
184
- type: 'f',
185
- label: f.label,
186
- atts: { font: f.family, ['font-class']: f.className },
187
- value: (_b = (_a = f.family) !== null && _a !== void 0 ? _a : f.className) !== null && _b !== void 0 ? _b : f.label,
188
- });
189
- })
170
+ ...families.map(f => ({
171
+ clearType: 'f',
172
+ type: 'f',
173
+ label: f.label,
174
+ atts: { font: f.family, ['font-class']: f.className },
175
+ value: f.family ?? f.className ?? f.label,
176
+ }))
190
177
  ]
191
178
  }),
192
179
  ],
193
180
  onSelectionChange: ({ toolElem, nodeAtCursor }) => {
194
- var _a, _b, _c, _d;
195
181
  if (toolElem instanceof HTMLSelectElement) {
196
- toolElem.value = (_d = (_b = (_a = nodeAtCursor === null || nodeAtCursor === void 0 ? void 0 : nodeAtCursor.atts) === null || _a === void 0 ? void 0 : _a['font']) !== null && _b !== void 0 ? _b : (_c = nodeAtCursor === null || nodeAtCursor === void 0 ? void 0 : nodeAtCursor.atts) === null || _c === void 0 ? void 0 : _c['font-class']) !== null && _d !== void 0 ? _d : '';
182
+ toolElem.value = nodeAtCursor?.atts?.['font'] ?? nodeAtCursor?.atts?.['font-class'] ?? '';
197
183
  }
198
184
  },
199
185
  });
@@ -1 +1 @@
1
- {"version":3,"file":"rtxt-tools.js","sourceRoot":"","sources":["../../../../../../packages/rtxt/src/lib/rtxt-tools.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,YAAY,CAAC;AACpE,OAAO,EAAsB,oBAAoB,EAAE,sBAAsB,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAG7I,MAAM,CAAC,MAAM,mBAAmB,GAAC,CAAC,EAC9B,YAAY,MACI,EAAE,EAAY,EAAE;IAEhC,MAAM,QAAQ,GAAwB;QAClC,CAAC,YAAY,CAAA,CAAC,CAAA,SAAS,CAAA,CAAC,CAAA,wBAAwB,CAAC,YAAY,CAAC;QAC9D;YACI,KAAK,EAAC,CAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,IAAI,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,EAAC,KAAK,CAAC;YACnD,MAAM,EAAC,MAAM,CAAA,EAAE,CAAA;gBACX,mBAAmB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AG,CAAqB,CAAC,CAAA,EAAE,CAAA,CAAC;oBACpC,SAAS,EAAC,GAAG;oBACb,IAAI,EAAC,GAAG;oBACR,KAAK,EAAC,CAAC,CAAC,KAAK;oBACb,IAAI,EAAC,EAAC,IAAI,EAAC,CAAC,CAAC,MAAM,EAAC,CAAC,YAAY,CAAC,EAAC,CAAC,CAAC,SAAS,EAAC;oBAC/C,KAAK,EAAC,CAAC,CAAC,MAAM,IAAE,CAAC,CAAC,SAAS,IAAE,CAAC,CAAC,KAAK;iBACvC,CAAC,CAAC;aACN;SACJ,CAAC;KACL;IACD,iBAAiB,EAAC,CAAC,EAAC,QAAQ,EAAC,YAAY,EAAC,EAAC,EAAE;QACzC,IAAG,QAAQ,YAAY,iBAAiB,EAAC,CAAC;YACtC,QAAQ,CAAC,KAAK,GAAC,YAAY,EAAE,IAAI,EAAE,CAAC,MAAM,CAAC,IAAE,YAAY,EAAE,IAAI,EAAE,CAAC,YAAY,CAAC,IAAE,EAAE,CAAC;QACxF,CAAC;IACL,CAAC;CACJ,CACA,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iyio/rtxt",
3
- "version": "0.7.0",
3
+ "version": "0.7.5",
4
4
  "sideEffects": false,
5
5
  "dependencies": {
6
6
  "date-fns": ">=2.29.3",
@@ -9,7 +9,7 @@
9
9
  "zod": ">=3.21.4"
10
10
  },
11
11
  "peerDependencies": {
12
- "@iyio/common": "^0.7.0"
12
+ "@iyio/common": "^0.7.5"
13
13
  },
14
14
  "main": "./src/index.js",
15
15
  "module": "./esm/src/index.js"
@@ -43,22 +43,18 @@ class RTxtEditor {
43
43
  get selectionSubject() { return this._selection; }
44
44
  get selection() { return this._selection.value; }
45
45
  constructor(options = {}) {
46
- var _a, _b, _c, _d, _e;
47
46
  this._renderer = new rxjs_1.BehaviorSubject(null);
48
47
  this._selection = new rxjs_1.BehaviorSubject(null);
49
48
  this._isDisposed = false;
50
49
  this.onInput = () => {
51
- var _a;
52
50
  this.syncElemToDoc();
53
- (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.queueExport();
51
+ this.renderer?.queueExport();
54
52
  };
55
53
  this.onFocus = () => {
56
- var _a, _b;
57
- (_b = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.elem) === null || _b === void 0 ? void 0 : _b.classList.add(`${this.renderer.classPrefix}focus`);
54
+ this.renderer?.elem?.classList.add(`${this.renderer.classPrefix}focus`);
58
55
  };
59
56
  this.onBlur = () => {
60
- var _a, _b;
61
- (_b = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.elem) === null || _b === void 0 ? void 0 : _b.classList.remove(`${this.renderer.classPrefix}focus`);
57
+ this.renderer?.elem?.classList.remove(`${this.renderer.classPrefix}focus`);
62
58
  };
63
59
  this.bodyMouseDown = (e) => {
64
60
  if (!this.menu || !(e.target instanceof Node)) {
@@ -69,23 +65,21 @@ class RTxtEditor {
69
65
  }
70
66
  };
71
67
  this.bodyMouseUp = () => {
72
- var _a;
73
- (_a = this.menu) === null || _a === void 0 ? void 0 : _a.classList.remove(`${this.classPrefix}disable-mouse`);
68
+ this.menu?.classList.remove(`${this.classPrefix}disable-mouse`);
74
69
  };
75
70
  this.onSelectionChange = () => {
76
- var _a;
77
71
  if (!this.renderer) {
78
72
  return;
79
73
  }
80
- const sel = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.getSelection();
74
+ const sel = globalThis.document?.getSelection();
81
75
  if (this.renderer.isEmpty ||
82
76
  !sel ||
83
77
  !sel.rangeCount ||
84
78
  !sel.anchorNode ||
85
79
  !sel.focusNode ||
86
80
  (sel.anchorNode === sel.focusNode && sel.anchorOffset === sel.focusOffset) ||
87
- !(0, common_1.isDomNodeDescendantOf)(sel === null || sel === void 0 ? void 0 : sel.anchorNode, this.renderer.elem, true) ||
88
- !(0, common_1.isDomNodeDescendantOf)(sel === null || sel === void 0 ? void 0 : sel.focusNode, this.renderer.elem, true)) {
81
+ !(0, common_1.isDomNodeDescendantOf)(sel?.anchorNode, this.renderer.elem, true) ||
82
+ !(0, common_1.isDomNodeDescendantOf)(sel?.focusNode, this.renderer.elem, true)) {
89
83
  if (!sel ||
90
84
  (!(0, common_1.isDomNodeDescendantOf)(sel.anchorNode, this.menu, false) &&
91
85
  !(0, common_1.isDomNodeDescendantOf)(sel.focusNode, this.menu, false))) {
@@ -118,37 +112,35 @@ class RTxtEditor {
118
112
  else if (renderer) {
119
113
  this.renderer = new RTxtRenderer_1.RTxtRenderer(renderer, true);
120
114
  }
121
- this.classPrefix = (_b = classPrefix !== null && classPrefix !== void 0 ? classPrefix : (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.options.classPrefix) !== null && _b !== void 0 ? _b : rtxt_types_1.defaultRTxtClassNamePrefix;
115
+ this.classPrefix = classPrefix ?? this.renderer?.options.classPrefix ?? rtxt_types_1.defaultRTxtClassNamePrefix;
122
116
  this.tools = tools;
123
117
  if (!useCustomStyleSheet) {
124
118
  (0, rtxt_style_editor_1.insertRTxtEditorStyleSheet)();
125
119
  }
126
- (_c = globalThis.document) === null || _c === void 0 ? void 0 : _c.addEventListener('selectionchange', this.onSelectionChange);
127
- (_d = globalThis.document) === null || _d === void 0 ? void 0 : _d.body.addEventListener('mousedown', this.bodyMouseDown);
128
- (_e = globalThis.document) === null || _e === void 0 ? void 0 : _e.body.addEventListener('mouseup', this.bodyMouseUp);
120
+ globalThis.document?.addEventListener('selectionchange', this.onSelectionChange);
121
+ globalThis.document?.body.addEventListener('mousedown', this.bodyMouseDown);
122
+ globalThis.document?.body.addEventListener('mouseup', this.bodyMouseUp);
129
123
  this.menu = this.renderMenu();
130
124
  }
131
125
  get isDisposed() { return this._isDisposed; }
132
126
  dispose() {
133
- var _a, _b, _c, _d;
134
127
  if (this._isDisposed) {
135
128
  return;
136
129
  }
137
130
  this._isDisposed = true;
138
- (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.removeEventListener('selectionchange', this.onSelectionChange);
139
- (_b = globalThis.document) === null || _b === void 0 ? void 0 : _b.body.removeEventListener('mousedown', this.bodyMouseDown);
140
- (_c = globalThis.document) === null || _c === void 0 ? void 0 : _c.body.removeEventListener('mouseup', this.bodyMouseUp);
141
- (_d = this.menu) === null || _d === void 0 ? void 0 : _d.remove();
131
+ globalThis.document?.removeEventListener('selectionchange', this.onSelectionChange);
132
+ globalThis.document?.body.removeEventListener('mousedown', this.bodyMouseDown);
133
+ globalThis.document?.body.removeEventListener('mouseup', this.bodyMouseUp);
134
+ this.menu?.remove();
142
135
  this.renderer = null;
143
136
  }
144
137
  deselectAllTools() {
145
- var _a, _b;
146
138
  const className = `${this.classPrefix}selected`;
147
139
  for (const group of this.toolElemGroupings) {
148
140
  for (const elem of group.elems) {
149
141
  elem.classList.remove(className);
150
142
  }
151
- (_b = (_a = group.tool).onSelectionChange) === null || _b === void 0 ? void 0 : _b.call(_a, {
143
+ group.tool.onSelectionChange?.({
152
144
  editor: this,
153
145
  selection: null,
154
146
  descriptors: [],
@@ -160,7 +152,6 @@ class RTxtEditor {
160
152
  }
161
153
  }
162
154
  setToolSelection(selection) {
163
- var _a, _b, _c, _d;
164
155
  if (!this.renderer) {
165
156
  this.deselectAllTools();
166
157
  return;
@@ -168,9 +159,9 @@ class RTxtEditor {
168
159
  const className = `${this.classPrefix}selected`;
169
160
  const singleAry = [''];
170
161
  const elemAtCursor = this.getElementAt(selection.cursorIndex);
171
- const styleAtCursor = elemAtCursor ? (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.getComputedStyle) === null || _b === void 0 ? void 0 : _b.call(_a, (0, rtxt_internal_1.getDeepestElem)(elemAtCursor)) : undefined;
172
- const colorAtCursor = (styleAtCursor === null || styleAtCursor === void 0 ? void 0 : styleAtCursor.color) ? (0, common_1.convertRgbToHex)(styleAtCursor.color) : undefined;
173
- const sizeAtCursor = styleAtCursor === null || styleAtCursor === void 0 ? void 0 : styleAtCursor.fontSize;
162
+ const styleAtCursor = elemAtCursor ? globalThis.window?.getComputedStyle?.((0, rtxt_internal_1.getDeepestElem)(elemAtCursor)) : undefined;
163
+ const colorAtCursor = styleAtCursor?.color ? (0, common_1.convertRgbToHex)(styleAtCursor.color) : undefined;
164
+ const sizeAtCursor = styleAtCursor?.fontSize;
174
165
  const nodeAtCursor = this.renderer.nodeLookup[selection.cursorIndex];
175
166
  for (const group of this.toolElemGroupings) {
176
167
  const types = [];
@@ -260,13 +251,12 @@ class RTxtEditor {
260
251
  }
261
252
  }
262
253
  }
263
- (_d = (_c = group.tool).onSelectionChange) === null || _d === void 0 ? void 0 : _d.call(_c, toolSel);
254
+ group.tool.onSelectionChange?.(toolSel);
264
255
  }
265
256
  }
266
257
  renderMenu() {
267
- var _a, _b, _c;
268
- const container = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.createElement('div');
269
- const menu = (_b = globalThis.document) === null || _b === void 0 ? void 0 : _b.createElement('div');
258
+ const container = globalThis.document?.createElement('div');
259
+ const menu = globalThis.document?.createElement('div');
270
260
  if (!container || !menu) {
271
261
  return null;
272
262
  }
@@ -293,7 +283,7 @@ class RTxtEditor {
293
283
  grouping.elems.push(elem);
294
284
  }
295
285
  }
296
- (_c = globalThis.document) === null || _c === void 0 ? void 0 : _c.body.appendChild(container);
286
+ globalThis.document?.body.appendChild(container);
297
287
  return container;
298
288
  }
299
289
  showMenu(left, top, bottom) {
@@ -326,7 +316,6 @@ class RTxtEditor {
326
316
  }
327
317
  }
328
318
  applyToSection(selection, nodeType, atts) {
329
- var _a, _b, _c;
330
319
  if (!this.renderer) {
331
320
  return;
332
321
  }
@@ -339,11 +328,11 @@ class RTxtEditor {
339
328
  }
340
329
  if (!node.t.includes(nodeType)) {
341
330
  const desc = this.renderer.descriptors[nodeType];
342
- if (desc === null || desc === void 0 ? void 0 : desc.group) {
331
+ if (desc?.group) {
343
332
  for (let i = 0; i < node.t.length; i++) {
344
- const otherDesc = this.renderer.descriptors[(_a = node.t[i]) !== null && _a !== void 0 ? _a : ''];
345
- if ((otherDesc === null || otherDesc === void 0 ? void 0 : otherDesc.group) === desc.group) {
346
- (_b = otherDesc.remove) === null || _b === void 0 ? void 0 : _b.call(otherDesc, node);
333
+ const otherDesc = this.renderer.descriptors[node.t[i] ?? ''];
334
+ if (otherDesc?.group === desc.group) {
335
+ otherDesc.remove?.(node);
347
336
  node.t.splice(i, 1);
348
337
  i--;
349
338
  }
@@ -364,10 +353,9 @@ class RTxtEditor {
364
353
  }
365
354
  }
366
355
  }
367
- (_c = this.renderer) === null || _c === void 0 ? void 0 : _c.queueExport();
356
+ this.renderer?.queueExport();
368
357
  }
369
358
  removeFromSelection(selection, nodeType) {
370
- var _a, _b;
371
359
  if (!this.renderer) {
372
360
  return;
373
361
  }
@@ -380,20 +368,19 @@ class RTxtEditor {
380
368
  }
381
369
  if ((0, common_1.aryRemoveItem)(node.t, nodeType)) {
382
370
  const desc = this.renderer.descriptors[nodeType];
383
- (_a = desc === null || desc === void 0 ? void 0 : desc.remove) === null || _a === void 0 ? void 0 : _a.call(desc, node);
371
+ desc?.remove?.(node);
384
372
  }
385
373
  }
386
- (_b = this.renderer) === null || _b === void 0 ? void 0 : _b.queueExport();
374
+ this.renderer?.queueExport();
387
375
  }
388
376
  someHaveNodeType(selection, nodeType) {
389
- var _a;
390
377
  for (const node of selection.nodes) {
391
378
  if (typeof node.t === 'string') {
392
379
  if (node.t === nodeType) {
393
380
  return true;
394
381
  }
395
382
  }
396
- else if ((_a = node.t) === null || _a === void 0 ? void 0 : _a.length) {
383
+ else if (node.t?.length) {
397
384
  if (node.t.includes(nodeType)) {
398
385
  return true;
399
386
  }
@@ -405,14 +392,13 @@ class RTxtEditor {
405
392
  return false;
406
393
  }
407
394
  allHaveNodeType(selection, nodeType) {
408
- var _a;
409
395
  for (const node of selection.nodes) {
410
396
  if (typeof node.t === 'string') {
411
397
  if (node.t !== nodeType) {
412
398
  return false;
413
399
  }
414
400
  }
415
- else if ((_a = node.t) === null || _a === void 0 ? void 0 : _a.length) {
401
+ else if (node.t?.length) {
416
402
  if (!node.t.includes(nodeType)) {
417
403
  return false;
418
404
  }
@@ -424,13 +410,12 @@ class RTxtEditor {
424
410
  return true;
425
411
  }
426
412
  syncElemToDoc() {
427
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k;
428
413
  if (!this.renderer) {
429
414
  return;
430
415
  }
431
416
  const startEmpty = this.renderer.isEmpty;
432
- const selection = (_a = globalThis.document) === null || _a === void 0 ? void 0 : _a.getSelection();
433
- const caretNode = (selection && (selection === null || selection === void 0 ? void 0 : selection.anchorNode) === (selection === null || selection === void 0 ? void 0 : selection.focusNode)) ? selection.anchorNode : null;
417
+ const selection = globalThis.document?.getSelection();
418
+ const caretNode = (selection && selection?.anchorNode === selection?.focusNode) ? selection.anchorNode : null;
434
419
  let setCaretElem = null;
435
420
  let reRender = false;
436
421
  const docElem = this.renderer.elem;
@@ -438,7 +423,7 @@ class RTxtEditor {
438
423
  return;
439
424
  }
440
425
  let hasChange = false;
441
- const lineElemType = (_b = this.renderer.options.lineElem) !== null && _b !== void 0 ? _b : rtxt_types_1.defaultRTxtLineElem;
426
+ const lineElemType = this.renderer.options.lineElem ?? rtxt_types_1.defaultRTxtLineElem;
442
427
  let lineIndex = 0;
443
428
  let nodeIndex = 0;
444
429
  let lastFormattedElem = null;
@@ -450,7 +435,7 @@ class RTxtEditor {
450
435
  if (!(lineElem instanceof Element)) {
451
436
  hasChange = true;
452
437
  reRender = true;
453
- const replaceWith = (_c = globalThis.document) === null || _c === void 0 ? void 0 : _c.createElement(lineElemType);
438
+ const replaceWith = globalThis.document?.createElement(lineElemType);
454
439
  if (replaceWith) {
455
440
  replaceWith.textContent = lineElem.textContent;
456
441
  docElem.insertBefore(replaceWith, lineElem);
@@ -462,7 +447,7 @@ class RTxtEditor {
462
447
  if (!lineIsNode) {
463
448
  hasChange = true;
464
449
  reRender = true;
465
- lineElem.innerHTML = `<${lineElemType}>${(0, common_1.escapeHtml)((_d = lineElem.textContent) !== null && _d !== void 0 ? _d : '')}</${lineElemType}>`;
450
+ lineElem.innerHTML = `<${lineElemType}>${(0, common_1.escapeHtml)(lineElem.textContent ?? '')}</${lineElemType}>`;
466
451
  }
467
452
  const lineAttValue = lineElem.getAttribute(rtxt_types_1.rTxtLineIndexAtt);
468
453
  if (!lineAttValue || lineAttValue !== lineIndex.toString()) {
@@ -475,7 +460,7 @@ class RTxtEditor {
475
460
  continue;
476
461
  }
477
462
  if (!(_elem instanceof Element)) {
478
- const replaceWith = (_e = globalThis.document) === null || _e === void 0 ? void 0 : _e.createElement(rtxt_types_1.defaultRTxtNodeType);
463
+ const replaceWith = globalThis.document?.createElement(rtxt_types_1.defaultRTxtNodeType);
479
464
  replaceWith.textContent = _elem.textContent;
480
465
  lineElem.insertBefore(replaceWith, _elem);
481
466
  _elem.remove();
@@ -503,7 +488,7 @@ class RTxtEditor {
503
488
  else if ((0, rtxt_internal_1.hasForeignElems)(elem)) {
504
489
  reRender = true;
505
490
  hasChange = true;
506
- elem.innerHTML = (0, common_1.escapeHtml)((_f = elem.textContent) !== null && _f !== void 0 ? _f : '');
491
+ elem.innerHTML = (0, common_1.escapeHtml)(elem.textContent ?? '');
507
492
  }
508
493
  const indexAttValue = elem.getAttribute(rtxt_types_1.rTxtIndexLookupAtt);
509
494
  if (!indexAttValue || indexAttValue !== nodeIndex.toString()) {
@@ -512,11 +497,11 @@ class RTxtEditor {
512
497
  }
513
498
  const hasFocus = caretNode ? true : false;
514
499
  const textNode = (0, rtxt_internal_1.getTextNode)(elem);
515
- if ((textNode === null || textNode === void 0 ? void 0 : textNode.textContent) && textNode.textContent.length !== 1 && Array.from(textNode.textContent).length !== 1) {
500
+ if (textNode?.textContent && textNode.textContent.length !== 1 && Array.from(textNode.textContent).length !== 1) {
516
501
  hasChange = true;
517
502
  //split
518
503
  const text = Array.from(textNode.textContent);
519
- textNode.textContent = (_g = text[0]) !== null && _g !== void 0 ? _g : null;
504
+ textNode.textContent = text[0] ?? null;
520
505
  const elemNode = (0, rtxt_internal_1.getNodeElem)(textNode);
521
506
  if (!elemNode) {
522
507
  break;
@@ -528,9 +513,9 @@ class RTxtEditor {
528
513
  nextNode.setAttribute(rtxt_types_1.rTxtIndexLookupAtt, nodeIndex.toString());
529
514
  const nextTextNode = (0, rtxt_internal_1.getTextNode)(nextNode);
530
515
  if (nextTextNode) {
531
- nextTextNode.textContent = char !== null && char !== void 0 ? char : null;
516
+ nextTextNode.textContent = char ?? null;
532
517
  }
533
- (_h = elemNode.parentElement) === null || _h === void 0 ? void 0 : _h.insertBefore(nextNode, insertBefore);
518
+ elemNode.parentElement?.insertBefore(nextNode, insertBefore);
534
519
  if (hasFocus) {
535
520
  setCaretElem = nextNode;
536
521
  }
@@ -551,7 +536,7 @@ class RTxtEditor {
551
536
  this.renderer.doc = doc;
552
537
  }
553
538
  if (reRender) {
554
- const caretIndex = setCaretElem === null || setCaretElem === void 0 ? void 0 : setCaretElem.getAttribute(rtxt_types_1.rTxtIndexLookupAtt);
539
+ const caretIndex = setCaretElem?.getAttribute(rtxt_types_1.rTxtIndexLookupAtt);
555
540
  this.renderer.render();
556
541
  if (caretIndex) {
557
542
  setCaretElem = docElem.querySelector(`[${rtxt_types_1.rTxtIndexLookupAtt}='${caretIndex}']`);
@@ -563,35 +548,32 @@ class RTxtEditor {
563
548
  this.renderer.focus();
564
549
  }
565
550
  else if (caretTo && selection) {
566
- selection.collapse(caretTo, ((_j = caretTo.textContent) === null || _j === void 0 ? void 0 : _j.length) || 1);
551
+ selection.collapse(caretTo, caretTo.textContent?.length || 1);
567
552
  }
568
553
  else if (selection) {
569
554
  const last = (0, rtxt_internal_1.getTextNode)(docElem, true, false);
570
555
  if (last) {
571
556
  selection.removeAllRanges();
572
- selection.collapse(last, (_k = last.textContent) === null || _k === void 0 ? void 0 : _k.length);
557
+ selection.collapse(last, last.textContent?.length);
573
558
  }
574
559
  }
575
560
  }
576
561
  getElementAt(index) {
577
- var _a, _b;
578
- const docElem = (_a = this.renderer) === null || _a === void 0 ? void 0 : _a.elem;
562
+ const docElem = this.renderer?.elem;
579
563
  if (!docElem) {
580
564
  return undefined;
581
565
  }
582
- return (_b = docElem.querySelector(`[${rtxt_types_1.rTxtIndexLookupAtt}='${index}']`)) !== null && _b !== void 0 ? _b : undefined;
566
+ return docElem.querySelector(`[${rtxt_types_1.rTxtIndexLookupAtt}='${index}']`) ?? undefined;
583
567
  }
584
568
  getStyleAt(index) {
585
- var _a, _b, _c;
586
569
  const elem = this.getElementAt(index);
587
570
  if (!elem) {
588
571
  return undefined;
589
572
  }
590
- return (_c = (_b = (_a = globalThis.window) === null || _a === void 0 ? void 0 : _a.getComputedStyle) === null || _b === void 0 ? void 0 : _b.call(_a, (0, rtxt_internal_1.getDeepestElem)(elem))) !== null && _c !== void 0 ? _c : undefined;
573
+ return globalThis.window?.getComputedStyle?.((0, rtxt_internal_1.getDeepestElem)(elem)) ?? undefined;
591
574
  }
592
575
  getCursorLine() {
593
- var _a;
594
- const node = (_a = this.selection) === null || _a === void 0 ? void 0 : _a.cursorNode;
576
+ const node = this.selection?.cursorNode;
595
577
  if (!node || !this.renderer) {
596
578
  return undefined;
597
579
  }
@@ -624,14 +606,12 @@ class RTxtEditor {
624
606
  }
625
607
  }
626
608
  queueRenderer(renderer) {
627
- var _a;
628
609
  this.rendererQueue.push(renderer);
629
- this.renderer = (_a = this.rendererQueue[this.rendererQueue.length - 1]) !== null && _a !== void 0 ? _a : null;
610
+ this.renderer = this.rendererQueue[this.rendererQueue.length - 1] ?? null;
630
611
  }
631
612
  dequeueRenderer(renderer) {
632
- var _a;
633
613
  if ((0, common_1.aryRemoveItem)(this.rendererQueue, renderer)) {
634
- this.renderer = (_a = this.rendererQueue[this.rendererQueue.length - 1]) !== null && _a !== void 0 ? _a : null;
614
+ this.renderer = this.rendererQueue[this.rendererQueue.length - 1] ?? null;
635
615
  }
636
616
  }
637
617
  }