modern-text 1.10.4 → 1.10.6
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.
|
@@ -70,6 +70,7 @@ class TextEditor extends HTMLElement {
|
|
|
70
70
|
set text(newText) {
|
|
71
71
|
if (newText) {
|
|
72
72
|
this._text?.off("update", this._update);
|
|
73
|
+
this.reset();
|
|
73
74
|
newText.on("update", this._update);
|
|
74
75
|
this._text = newText;
|
|
75
76
|
this._setTextInput(this.getPlaintext());
|
|
@@ -555,6 +556,7 @@ class TextEditor extends HTMLElement {
|
|
|
555
556
|
selectAll() {
|
|
556
557
|
this._textarea.focus();
|
|
557
558
|
this._textarea.select();
|
|
559
|
+
this._updateSelectionByDom();
|
|
558
560
|
}
|
|
559
561
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
560
562
|
this[name] = newValue;
|
|
@@ -570,53 +572,51 @@ class TextEditor extends HTMLElement {
|
|
|
570
572
|
);
|
|
571
573
|
}
|
|
572
574
|
_renderSelectRange() {
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
h: char.height
|
|
589
|
-
});
|
|
575
|
+
const isVertical = this.text.isVertical;
|
|
576
|
+
const boxesGroupsMap = {};
|
|
577
|
+
this._selectedChars.forEach((char) => {
|
|
578
|
+
if (char.isLastSelected) {
|
|
579
|
+
return;
|
|
580
|
+
}
|
|
581
|
+
const key = isVertical ? char.left : char.top;
|
|
582
|
+
if (!boxesGroupsMap[key]) {
|
|
583
|
+
boxesGroupsMap[key] = [];
|
|
584
|
+
}
|
|
585
|
+
boxesGroupsMap[key].push({
|
|
586
|
+
x: char.left - this.text.glyphBox.left,
|
|
587
|
+
y: char.top - this.text.glyphBox.top,
|
|
588
|
+
w: char.width,
|
|
589
|
+
h: char.height
|
|
590
590
|
});
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
const min = {
|
|
607
|
-
x: Math.min(...boxes.map((v) => v.x)),
|
|
608
|
-
y: Math.min(...boxes.map((v) => v.y))
|
|
609
|
-
};
|
|
610
|
-
const max = {
|
|
611
|
-
x: Math.max(...boxes.map((v) => v.x + v.w)),
|
|
612
|
-
y: Math.max(...boxes.map((v) => v.y + v.h))
|
|
613
|
-
};
|
|
614
|
-
element.style.width = `${max.x - min.x}px`;
|
|
615
|
-
element.style.height = `${max.y - min.y}px`;
|
|
616
|
-
element.style.transform = `translate(${min.x}px, ${min.y}px)`;
|
|
591
|
+
});
|
|
592
|
+
const boxesGroups = Object.values(boxesGroupsMap);
|
|
593
|
+
const sourceLen = this._selection.children.length;
|
|
594
|
+
const targetLen = boxesGroups.length;
|
|
595
|
+
const len = Math.max(sourceLen, targetLen);
|
|
596
|
+
const deleted = [];
|
|
597
|
+
for (let i = 0; i < len; i++) {
|
|
598
|
+
let element = this._selection.children.item(i);
|
|
599
|
+
const boxes = boxesGroups[i];
|
|
600
|
+
if (!boxes) {
|
|
601
|
+
deleted.push(element);
|
|
602
|
+
continue;
|
|
603
|
+
} else if (!element) {
|
|
604
|
+
element = document.createElement("div");
|
|
605
|
+
this._selection.append(element);
|
|
617
606
|
}
|
|
618
|
-
|
|
607
|
+
const min = {
|
|
608
|
+
x: Math.min(...boxes.map((v) => v.x)),
|
|
609
|
+
y: Math.min(...boxes.map((v) => v.y))
|
|
610
|
+
};
|
|
611
|
+
const max = {
|
|
612
|
+
x: Math.max(...boxes.map((v) => v.x + v.w)),
|
|
613
|
+
y: Math.max(...boxes.map((v) => v.y + v.h))
|
|
614
|
+
};
|
|
615
|
+
element.style.width = `${max.x - min.x}px`;
|
|
616
|
+
element.style.height = `${max.y - min.y}px`;
|
|
617
|
+
element.style.transform = `translate(${min.x}px, ${min.y}px)`;
|
|
619
618
|
}
|
|
619
|
+
deleted.forEach((el) => el?.remove());
|
|
620
620
|
}
|
|
621
621
|
_renderCursor() {
|
|
622
622
|
if (this._showCursor && this._cursorPosition && this._selectedChars.length === 0) {
|
|
@@ -636,6 +636,9 @@ class TextEditor extends HTMLElement {
|
|
|
636
636
|
}
|
|
637
637
|
this._timer = setTimeout(() => this._cursor.classList.add("blink"), 500);
|
|
638
638
|
}
|
|
639
|
+
reset() {
|
|
640
|
+
this.selection = [];
|
|
641
|
+
}
|
|
639
642
|
}
|
|
640
643
|
__decorateClass([
|
|
641
644
|
modernIdoc.property({ fallback: 0 })
|
|
@@ -68,6 +68,7 @@ class TextEditor extends HTMLElement {
|
|
|
68
68
|
set text(newText) {
|
|
69
69
|
if (newText) {
|
|
70
70
|
this._text?.off("update", this._update);
|
|
71
|
+
this.reset();
|
|
71
72
|
newText.on("update", this._update);
|
|
72
73
|
this._text = newText;
|
|
73
74
|
this._setTextInput(this.getPlaintext());
|
|
@@ -553,6 +554,7 @@ class TextEditor extends HTMLElement {
|
|
|
553
554
|
selectAll() {
|
|
554
555
|
this._textarea.focus();
|
|
555
556
|
this._textarea.select();
|
|
557
|
+
this._updateSelectionByDom();
|
|
556
558
|
}
|
|
557
559
|
attributeChangedCallback(name, _oldValue, newValue) {
|
|
558
560
|
this[name] = newValue;
|
|
@@ -568,53 +570,51 @@ class TextEditor extends HTMLElement {
|
|
|
568
570
|
);
|
|
569
571
|
}
|
|
570
572
|
_renderSelectRange() {
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
h: char.height
|
|
587
|
-
});
|
|
573
|
+
const isVertical = this.text.isVertical;
|
|
574
|
+
const boxesGroupsMap = {};
|
|
575
|
+
this._selectedChars.forEach((char) => {
|
|
576
|
+
if (char.isLastSelected) {
|
|
577
|
+
return;
|
|
578
|
+
}
|
|
579
|
+
const key = isVertical ? char.left : char.top;
|
|
580
|
+
if (!boxesGroupsMap[key]) {
|
|
581
|
+
boxesGroupsMap[key] = [];
|
|
582
|
+
}
|
|
583
|
+
boxesGroupsMap[key].push({
|
|
584
|
+
x: char.left - this.text.glyphBox.left,
|
|
585
|
+
y: char.top - this.text.glyphBox.top,
|
|
586
|
+
w: char.width,
|
|
587
|
+
h: char.height
|
|
588
588
|
});
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
const min = {
|
|
605
|
-
x: Math.min(...boxes.map((v) => v.x)),
|
|
606
|
-
y: Math.min(...boxes.map((v) => v.y))
|
|
607
|
-
};
|
|
608
|
-
const max = {
|
|
609
|
-
x: Math.max(...boxes.map((v) => v.x + v.w)),
|
|
610
|
-
y: Math.max(...boxes.map((v) => v.y + v.h))
|
|
611
|
-
};
|
|
612
|
-
element.style.width = `${max.x - min.x}px`;
|
|
613
|
-
element.style.height = `${max.y - min.y}px`;
|
|
614
|
-
element.style.transform = `translate(${min.x}px, ${min.y}px)`;
|
|
589
|
+
});
|
|
590
|
+
const boxesGroups = Object.values(boxesGroupsMap);
|
|
591
|
+
const sourceLen = this._selection.children.length;
|
|
592
|
+
const targetLen = boxesGroups.length;
|
|
593
|
+
const len = Math.max(sourceLen, targetLen);
|
|
594
|
+
const deleted = [];
|
|
595
|
+
for (let i = 0; i < len; i++) {
|
|
596
|
+
let element = this._selection.children.item(i);
|
|
597
|
+
const boxes = boxesGroups[i];
|
|
598
|
+
if (!boxes) {
|
|
599
|
+
deleted.push(element);
|
|
600
|
+
continue;
|
|
601
|
+
} else if (!element) {
|
|
602
|
+
element = document.createElement("div");
|
|
603
|
+
this._selection.append(element);
|
|
615
604
|
}
|
|
616
|
-
|
|
605
|
+
const min = {
|
|
606
|
+
x: Math.min(...boxes.map((v) => v.x)),
|
|
607
|
+
y: Math.min(...boxes.map((v) => v.y))
|
|
608
|
+
};
|
|
609
|
+
const max = {
|
|
610
|
+
x: Math.max(...boxes.map((v) => v.x + v.w)),
|
|
611
|
+
y: Math.max(...boxes.map((v) => v.y + v.h))
|
|
612
|
+
};
|
|
613
|
+
element.style.width = `${max.x - min.x}px`;
|
|
614
|
+
element.style.height = `${max.y - min.y}px`;
|
|
615
|
+
element.style.transform = `translate(${min.x}px, ${min.y}px)`;
|
|
617
616
|
}
|
|
617
|
+
deleted.forEach((el) => el?.remove());
|
|
618
618
|
}
|
|
619
619
|
_renderCursor() {
|
|
620
620
|
if (this._showCursor && this._cursorPosition && this._selectedChars.length === 0) {
|
|
@@ -634,6 +634,9 @@ class TextEditor extends HTMLElement {
|
|
|
634
634
|
}
|
|
635
635
|
this._timer = setTimeout(() => this._cursor.classList.add("blink"), 500);
|
|
636
636
|
}
|
|
637
|
+
reset() {
|
|
638
|
+
this.selection = [];
|
|
639
|
+
}
|
|
637
640
|
}
|
|
638
641
|
__decorateClass([
|
|
639
642
|
property({ fallback: 0 })
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "modern-text",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "1.10.
|
|
4
|
+
"version": "1.10.6",
|
|
5
5
|
"packageManager": "pnpm@10.18.1",
|
|
6
6
|
"description": "Measure and render text in a way that describes the DOM.",
|
|
7
7
|
"author": "wxm",
|
|
@@ -56,18 +56,18 @@
|
|
|
56
56
|
"dependencies": {
|
|
57
57
|
"diff": "^8.0.2",
|
|
58
58
|
"modern-font": "^0.4.4",
|
|
59
|
-
"modern-idoc": "^0.10.
|
|
60
|
-
"modern-path2d": "^1.4.
|
|
59
|
+
"modern-idoc": "^0.10.8",
|
|
60
|
+
"modern-path2d": "^1.4.16"
|
|
61
61
|
},
|
|
62
62
|
"devDependencies": {
|
|
63
|
-
"@antfu/eslint-config": "^6.
|
|
64
|
-
"@types/node": "^
|
|
65
|
-
"bumpp": "^10.3.
|
|
63
|
+
"@antfu/eslint-config": "^6.7.3",
|
|
64
|
+
"@types/node": "^25.0.3",
|
|
65
|
+
"bumpp": "^10.3.2",
|
|
66
66
|
"conventional-changelog-cli": "^5.0.0",
|
|
67
|
-
"eslint": "^9.39.
|
|
67
|
+
"eslint": "^9.39.2",
|
|
68
68
|
"typescript": "^5.9.3",
|
|
69
69
|
"unbuild": "^3.6.1",
|
|
70
|
-
"vite": "^7.
|
|
71
|
-
"vitest": "^4.0.
|
|
70
|
+
"vite": "^7.3.0",
|
|
71
|
+
"vitest": "^4.0.16"
|
|
72
72
|
}
|
|
73
73
|
}
|