@hpcc-js/common 3.7.2 → 3.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.
- package/LICENSE +43 -43
- package/README.md +59 -59
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.umd.cjs +1 -1
- package/dist/index.umd.cjs.map +1 -1
- package/package.json +5 -5
- package/src/CanvasWidget.ts +31 -31
- package/src/Class.ts +72 -72
- package/src/Database.ts +860 -860
- package/src/Entity.ts +235 -235
- package/src/EntityCard.ts +66 -66
- package/src/EntityPin.ts +103 -103
- package/src/EntityRect.css +15 -15
- package/src/EntityRect.ts +254 -254
- package/src/EntityVertex.ts +86 -86
- package/src/FAChar.css +2 -2
- package/src/FAChar.ts +89 -89
- package/src/HTMLWidget.ts +191 -191
- package/src/IList.ts +4 -4
- package/src/IMenu.ts +5 -5
- package/src/Icon.css +9 -9
- package/src/Icon.ts +176 -176
- package/src/Image.ts +104 -104
- package/src/List.css +12 -12
- package/src/List.ts +102 -102
- package/src/Menu.css +22 -22
- package/src/Menu.ts +139 -139
- package/src/Palette.ts +341 -341
- package/src/Platform.ts +125 -125
- package/src/ProgressBar.ts +115 -115
- package/src/PropertyExt.ts +770 -770
- package/src/ResizeSurface.css +38 -38
- package/src/ResizeSurface.ts +225 -225
- package/src/SVGWidget.ts +583 -583
- package/src/SVGZoomWidget.css +11 -11
- package/src/SVGZoomWidget.ts +427 -427
- package/src/Shape.css +3 -3
- package/src/Shape.ts +186 -186
- package/src/Surface.css +39 -39
- package/src/Surface.ts +364 -364
- package/src/Text.css +3 -3
- package/src/Text.ts +131 -131
- package/src/TextBox.css +3 -3
- package/src/TextBox.ts +183 -183
- package/src/TitleBar.css +114 -114
- package/src/TitleBar.ts +407 -407
- package/src/Transition.ts +45 -45
- package/src/Utility.ts +843 -843
- package/src/Widget.css +7 -7
- package/src/Widget.ts +731 -731
- package/src/WidgetArray.ts +15 -15
- package/src/__package__.ts +3 -3
- package/src/index.ts +55 -55
package/src/Text.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.common_Text {
|
|
2
|
-
fill: #000;
|
|
3
|
-
font-size: 12px;
|
|
1
|
+
.common_Text {
|
|
2
|
+
fill: #000;
|
|
3
|
+
font-size: 12px;
|
|
4
4
|
}
|
package/src/Text.ts
CHANGED
|
@@ -1,131 +1,131 @@
|
|
|
1
|
-
import { SVGWidget } from "./SVGWidget.ts";
|
|
2
|
-
|
|
3
|
-
import "../src/Text.css";
|
|
4
|
-
|
|
5
|
-
export class Text extends SVGWidget {
|
|
6
|
-
|
|
7
|
-
private _textElement;
|
|
8
|
-
|
|
9
|
-
constructor() {
|
|
10
|
-
super();
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
getBBox(refresh = false, round = false) {
|
|
14
|
-
const textParts = this.text().split("\n");
|
|
15
|
-
const lineHeight = this.fontSize() || 12;
|
|
16
|
-
const height = lineHeight * textParts.length;
|
|
17
|
-
const widths: number[] = textParts.map(line => {
|
|
18
|
-
return this.textSize(line, this.fontFamily() || "Verdana", lineHeight).width;
|
|
19
|
-
});
|
|
20
|
-
const width = Math.max(...widths);
|
|
21
|
-
const retVal = {
|
|
22
|
-
x: - width / 2,
|
|
23
|
-
y: - height / 2 - lineHeight / (this.fontFamily() === "FontAwesome" ? 4 : 6), // baseLine offset
|
|
24
|
-
width,
|
|
25
|
-
height
|
|
26
|
-
};
|
|
27
|
-
switch (this.anchor()) {
|
|
28
|
-
case "start":
|
|
29
|
-
retVal.x = 0;
|
|
30
|
-
break;
|
|
31
|
-
case "end":
|
|
32
|
-
retVal.x = -width;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
return retVal;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
enter(domNode, element) {
|
|
39
|
-
super.enter(domNode, element);
|
|
40
|
-
delete this._prevHash;
|
|
41
|
-
this._textElement = element.append("text")
|
|
42
|
-
.on("click", () => {
|
|
43
|
-
this.click();
|
|
44
|
-
})
|
|
45
|
-
.on("dblclick", () => {
|
|
46
|
-
this.dblclick();
|
|
47
|
-
})
|
|
48
|
-
;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
_prevHash;
|
|
52
|
-
update(domNode, element) {
|
|
53
|
-
super.update(domNode, element);
|
|
54
|
-
const hash = this.hashSum([], { width: this.width() });
|
|
55
|
-
if (this._prevHash !== hash) {
|
|
56
|
-
this._prevHash = hash;
|
|
57
|
-
|
|
58
|
-
const bbox = this.getBBox();
|
|
59
|
-
|
|
60
|
-
this._textElement
|
|
61
|
-
.style("font-size", this.fontSize())
|
|
62
|
-
.style("text-anchor", this.anchor())
|
|
63
|
-
.attr("transform", d => `rotate(${this.rotation()}) translate(0,${bbox.y})`)
|
|
64
|
-
;
|
|
65
|
-
|
|
66
|
-
const width = this.width();
|
|
67
|
-
const context = this;
|
|
68
|
-
const textParts = this.text().split("\n");
|
|
69
|
-
const textLine = this._textElement.selectAll("tspan").data(textParts);
|
|
70
|
-
textLine.enter().append("tspan")
|
|
71
|
-
.attr("class", function (_d, i) { return "tspan_" + i; })
|
|
72
|
-
.attr("dy", "1em")
|
|
73
|
-
.attr("x", "0")
|
|
74
|
-
.merge(textLine)
|
|
75
|
-
.style("font-family", this.fontFamily())
|
|
76
|
-
.style("fill", this.colorFill())
|
|
77
|
-
.style("stroke", this.colorStroke())
|
|
78
|
-
.text((d: string) => {
|
|
79
|
-
if (!width) return d;
|
|
80
|
-
let retVal = d;
|
|
81
|
-
const lineHeight = context.fontSize() || 12;
|
|
82
|
-
let clipPos = retVal.length - 1;
|
|
83
|
-
while (clipPos > -3 && this.textSize(retVal, this.fontFamily() || "Verdana", lineHeight).width > width) {
|
|
84
|
-
retVal = retVal.substr(0, --clipPos) + "...".substr(0, clipPos + 3);
|
|
85
|
-
}
|
|
86
|
-
return retVal;
|
|
87
|
-
})
|
|
88
|
-
;
|
|
89
|
-
textLine.exit()
|
|
90
|
-
.remove()
|
|
91
|
-
;
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
click() {
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
dblclick() {
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
Text.prototype._class += " common_Text";
|
|
103
|
-
|
|
104
|
-
export interface Text {
|
|
105
|
-
text(): string;
|
|
106
|
-
text(_: string): this;
|
|
107
|
-
fontFamily(): string;
|
|
108
|
-
fontFamily(_: string): this;
|
|
109
|
-
fontSize(): number;
|
|
110
|
-
fontSize(_: number): this;
|
|
111
|
-
anchor(): "start" | "middle" | "end";
|
|
112
|
-
anchor(_: "start" | "middle" | "end"): this;
|
|
113
|
-
colorFill(): string;
|
|
114
|
-
colorFill(_: string): this;
|
|
115
|
-
colorFill_default(): string;
|
|
116
|
-
colorFill_default(_: string): this;
|
|
117
|
-
colorStroke(): string;
|
|
118
|
-
colorStroke(_: string): this;
|
|
119
|
-
colorStroke_default(): string;
|
|
120
|
-
colorStroke_default(_: string): this;
|
|
121
|
-
rotation(): number;
|
|
122
|
-
rotation(_: number): Text;
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
Text.prototype.publish("text", "", "string", "Display Text", null, { tags: ["Basic"] });
|
|
126
|
-
Text.prototype.publish("fontFamily", null, "string", "Font Family", null, { tags: ["Intermediate"], optional: true });
|
|
127
|
-
Text.prototype.publish("fontSize", null, "number", "Font Size (pixels)", null, { tags: ["Intermediate"] });
|
|
128
|
-
Text.prototype.publish("anchor", "middle", "set", "Anchor Position", ["start", "middle", "end"], { tags: ["Intermediate"] });
|
|
129
|
-
Text.prototype.publish("colorFill", null, "html-color", "Fill Color", null, { tags: ["Basic"] });
|
|
130
|
-
Text.prototype.publish("colorStroke", null, "html-color", "Fill Color", null, { tags: ["Basic"] });
|
|
131
|
-
Text.prototype.publish("rotation", 0, "number", "Degrees of rotation", null, { tags: ["Basic"] });
|
|
1
|
+
import { SVGWidget } from "./SVGWidget.ts";
|
|
2
|
+
|
|
3
|
+
import "../src/Text.css";
|
|
4
|
+
|
|
5
|
+
export class Text extends SVGWidget {
|
|
6
|
+
|
|
7
|
+
private _textElement;
|
|
8
|
+
|
|
9
|
+
constructor() {
|
|
10
|
+
super();
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
getBBox(refresh = false, round = false) {
|
|
14
|
+
const textParts = this.text().split("\n");
|
|
15
|
+
const lineHeight = this.fontSize() || 12;
|
|
16
|
+
const height = lineHeight * textParts.length;
|
|
17
|
+
const widths: number[] = textParts.map(line => {
|
|
18
|
+
return this.textSize(line, this.fontFamily() || "Verdana", lineHeight).width;
|
|
19
|
+
});
|
|
20
|
+
const width = Math.max(...widths);
|
|
21
|
+
const retVal = {
|
|
22
|
+
x: - width / 2,
|
|
23
|
+
y: - height / 2 - lineHeight / (this.fontFamily() === "FontAwesome" ? 4 : 6), // baseLine offset
|
|
24
|
+
width,
|
|
25
|
+
height
|
|
26
|
+
};
|
|
27
|
+
switch (this.anchor()) {
|
|
28
|
+
case "start":
|
|
29
|
+
retVal.x = 0;
|
|
30
|
+
break;
|
|
31
|
+
case "end":
|
|
32
|
+
retVal.x = -width;
|
|
33
|
+
break;
|
|
34
|
+
}
|
|
35
|
+
return retVal;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
enter(domNode, element) {
|
|
39
|
+
super.enter(domNode, element);
|
|
40
|
+
delete this._prevHash;
|
|
41
|
+
this._textElement = element.append("text")
|
|
42
|
+
.on("click", () => {
|
|
43
|
+
this.click();
|
|
44
|
+
})
|
|
45
|
+
.on("dblclick", () => {
|
|
46
|
+
this.dblclick();
|
|
47
|
+
})
|
|
48
|
+
;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
_prevHash;
|
|
52
|
+
update(domNode, element) {
|
|
53
|
+
super.update(domNode, element);
|
|
54
|
+
const hash = this.hashSum([], { width: this.width() });
|
|
55
|
+
if (this._prevHash !== hash) {
|
|
56
|
+
this._prevHash = hash;
|
|
57
|
+
|
|
58
|
+
const bbox = this.getBBox();
|
|
59
|
+
|
|
60
|
+
this._textElement
|
|
61
|
+
.style("font-size", this.fontSize())
|
|
62
|
+
.style("text-anchor", this.anchor())
|
|
63
|
+
.attr("transform", d => `rotate(${this.rotation()}) translate(0,${bbox.y})`)
|
|
64
|
+
;
|
|
65
|
+
|
|
66
|
+
const width = this.width();
|
|
67
|
+
const context = this;
|
|
68
|
+
const textParts = this.text().split("\n");
|
|
69
|
+
const textLine = this._textElement.selectAll("tspan").data(textParts);
|
|
70
|
+
textLine.enter().append("tspan")
|
|
71
|
+
.attr("class", function (_d, i) { return "tspan_" + i; })
|
|
72
|
+
.attr("dy", "1em")
|
|
73
|
+
.attr("x", "0")
|
|
74
|
+
.merge(textLine)
|
|
75
|
+
.style("font-family", this.fontFamily())
|
|
76
|
+
.style("fill", this.colorFill())
|
|
77
|
+
.style("stroke", this.colorStroke())
|
|
78
|
+
.text((d: string) => {
|
|
79
|
+
if (!width) return d;
|
|
80
|
+
let retVal = d;
|
|
81
|
+
const lineHeight = context.fontSize() || 12;
|
|
82
|
+
let clipPos = retVal.length - 1;
|
|
83
|
+
while (clipPos > -3 && this.textSize(retVal, this.fontFamily() || "Verdana", lineHeight).width > width) {
|
|
84
|
+
retVal = retVal.substr(0, --clipPos) + "...".substr(0, clipPos + 3);
|
|
85
|
+
}
|
|
86
|
+
return retVal;
|
|
87
|
+
})
|
|
88
|
+
;
|
|
89
|
+
textLine.exit()
|
|
90
|
+
.remove()
|
|
91
|
+
;
|
|
92
|
+
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
click() {
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
dblclick() {
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
Text.prototype._class += " common_Text";
|
|
103
|
+
|
|
104
|
+
export interface Text {
|
|
105
|
+
text(): string;
|
|
106
|
+
text(_: string): this;
|
|
107
|
+
fontFamily(): string;
|
|
108
|
+
fontFamily(_: string): this;
|
|
109
|
+
fontSize(): number;
|
|
110
|
+
fontSize(_: number): this;
|
|
111
|
+
anchor(): "start" | "middle" | "end";
|
|
112
|
+
anchor(_: "start" | "middle" | "end"): this;
|
|
113
|
+
colorFill(): string;
|
|
114
|
+
colorFill(_: string): this;
|
|
115
|
+
colorFill_default(): string;
|
|
116
|
+
colorFill_default(_: string): this;
|
|
117
|
+
colorStroke(): string;
|
|
118
|
+
colorStroke(_: string): this;
|
|
119
|
+
colorStroke_default(): string;
|
|
120
|
+
colorStroke_default(_: string): this;
|
|
121
|
+
rotation(): number;
|
|
122
|
+
rotation(_: number): Text;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
Text.prototype.publish("text", "", "string", "Display Text", null, { tags: ["Basic"] });
|
|
126
|
+
Text.prototype.publish("fontFamily", null, "string", "Font Family", null, { tags: ["Intermediate"], optional: true });
|
|
127
|
+
Text.prototype.publish("fontSize", null, "number", "Font Size (pixels)", null, { tags: ["Intermediate"] });
|
|
128
|
+
Text.prototype.publish("anchor", "middle", "set", "Anchor Position", ["start", "middle", "end"], { tags: ["Intermediate"] });
|
|
129
|
+
Text.prototype.publish("colorFill", null, "html-color", "Fill Color", null, { tags: ["Basic"] });
|
|
130
|
+
Text.prototype.publish("colorStroke", null, "html-color", "Fill Color", null, { tags: ["Basic"] });
|
|
131
|
+
Text.prototype.publish("rotation", 0, "number", "Degrees of rotation", null, { tags: ["Basic"] });
|
package/src/TextBox.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
.common_TextBox .common_Shape {
|
|
2
|
-
fill: #dcf1ff;
|
|
3
|
-
stroke: #1f77b4;
|
|
1
|
+
.common_TextBox .common_Shape {
|
|
2
|
+
fill: #dcf1ff;
|
|
3
|
+
stroke: #1f77b4;
|
|
4
4
|
}
|
package/src/TextBox.ts
CHANGED
|
@@ -1,183 +1,183 @@
|
|
|
1
|
-
import { textColor } from "./Palette.ts";
|
|
2
|
-
import { Shape } from "./Shape.ts";
|
|
3
|
-
import { SVGWidget } from "./SVGWidget.ts";
|
|
4
|
-
import { Text } from "./Text.ts";
|
|
5
|
-
import { ISize } from "./Widget.ts";
|
|
6
|
-
|
|
7
|
-
import "../src/TextBox.css";
|
|
8
|
-
|
|
9
|
-
export class TextBox extends SVGWidget {
|
|
10
|
-
|
|
11
|
-
protected _shape: Shape;
|
|
12
|
-
protected _text: Text;
|
|
13
|
-
|
|
14
|
-
constructor() {
|
|
15
|
-
super();
|
|
16
|
-
|
|
17
|
-
this._shape = new Shape()
|
|
18
|
-
.shape("rect")
|
|
19
|
-
.on("click", () => {
|
|
20
|
-
this.click();
|
|
21
|
-
})
|
|
22
|
-
.on("dblclick", () => {
|
|
23
|
-
this.dblclick();
|
|
24
|
-
})
|
|
25
|
-
;
|
|
26
|
-
this._text = new Text()
|
|
27
|
-
.on("click", () => {
|
|
28
|
-
this.click();
|
|
29
|
-
})
|
|
30
|
-
.on("dblclick", () => {
|
|
31
|
-
this.dblclick();
|
|
32
|
-
})
|
|
33
|
-
;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
padding(_) {
|
|
37
|
-
this.paddingLeft(_);
|
|
38
|
-
this.paddingRight(_);
|
|
39
|
-
this.paddingTop(_);
|
|
40
|
-
this.paddingBottom(_);
|
|
41
|
-
return this;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
getTextX(width) {
|
|
45
|
-
switch (this.anchor()) {
|
|
46
|
-
case "start":
|
|
47
|
-
return -width / 2;
|
|
48
|
-
case "end":
|
|
49
|
-
return width / 2;
|
|
50
|
-
}
|
|
51
|
-
return 0;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
getBBox(refresh = false, round = false) {
|
|
55
|
-
const textBBox = this._text.getBBox(true);
|
|
56
|
-
const width = this.fixedSize() ? this.fixedSize().width : textBBox.width + this.paddingLeft() + this.paddingRight();
|
|
57
|
-
const height = this.fixedSize() ? this.fixedSize().height : textBBox.height + this.paddingTop() + this.paddingBottom();
|
|
58
|
-
return {
|
|
59
|
-
x: -width - 2,
|
|
60
|
-
y: -height - 2,
|
|
61
|
-
width,
|
|
62
|
-
height
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
enter(domNode, element) {
|
|
67
|
-
super.enter(domNode, element);
|
|
68
|
-
delete this._prevHash;
|
|
69
|
-
this._shape
|
|
70
|
-
.target(domNode)
|
|
71
|
-
.tooltip(this.tooltip())
|
|
72
|
-
;
|
|
73
|
-
this._text
|
|
74
|
-
.target(domNode)
|
|
75
|
-
;
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
_prevHash;
|
|
79
|
-
update(domNode, element) {
|
|
80
|
-
super.update(domNode, element);
|
|
81
|
-
const hash = this.hashSum();
|
|
82
|
-
if (this._prevHash !== hash) {
|
|
83
|
-
this._prevHash = hash;
|
|
84
|
-
|
|
85
|
-
const textBBox = this._text.getBBox(true);
|
|
86
|
-
const size = {
|
|
87
|
-
width: this.fixedSize() ? this.fixedSize().width : textBBox.width + this.paddingLeft() + this.paddingRight(),
|
|
88
|
-
height: this.fixedSize() ? this.fixedSize().height : textBBox.height + this.paddingTop() + this.paddingBottom()
|
|
89
|
-
};
|
|
90
|
-
|
|
91
|
-
this._shape
|
|
92
|
-
.width(size.width)
|
|
93
|
-
.height(size.height)
|
|
94
|
-
.render()
|
|
95
|
-
;
|
|
96
|
-
|
|
97
|
-
this._text
|
|
98
|
-
.x(this.getTextX(textBBox.width))
|
|
99
|
-
.colorFill_default(this._shape.colorFill_exists() ? textColor(this._shape.colorFill()) : undefined)
|
|
100
|
-
.render()
|
|
101
|
-
;
|
|
102
|
-
|
|
103
|
-
if (this.fixedSize()) {
|
|
104
|
-
switch (this.anchor()) {
|
|
105
|
-
case "start":
|
|
106
|
-
this._text
|
|
107
|
-
.x(-this.fixedSize().width / 2 + textBBox.width / 2 + (this.paddingLeft() + this.paddingRight()) / 2)
|
|
108
|
-
.render()
|
|
109
|
-
;
|
|
110
|
-
break;
|
|
111
|
-
case "end":
|
|
112
|
-
this._text
|
|
113
|
-
.x(this.fixedSize().width / 2 - textBBox.width / 2 - (this.paddingLeft() + this.paddingRight()) / 2)
|
|
114
|
-
.render()
|
|
115
|
-
;
|
|
116
|
-
break;
|
|
117
|
-
}
|
|
118
|
-
}
|
|
119
|
-
this._text.visible(textBBox.width <= size.width && textBBox.height <= size.height);
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
exit(domNode, element) {
|
|
124
|
-
this._shape
|
|
125
|
-
.target(null)
|
|
126
|
-
;
|
|
127
|
-
this._text
|
|
128
|
-
.target(null)
|
|
129
|
-
;
|
|
130
|
-
super.exit(domNode, element);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
click() {
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
dblclick() {
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
TextBox.prototype._class += " common_TextBox";
|
|
140
|
-
|
|
141
|
-
export interface TextBox {
|
|
142
|
-
text(): string;
|
|
143
|
-
text(_: string): this;
|
|
144
|
-
fontSize(): number;
|
|
145
|
-
fontSize(_: number): this;
|
|
146
|
-
shape_colorFill(): string;
|
|
147
|
-
shape_colorFill(_: string): this;
|
|
148
|
-
shape_colorStroke(): string;
|
|
149
|
-
shape_colorStroke(_: string): this;
|
|
150
|
-
text_colorFill(): string;
|
|
151
|
-
text_colorFill(_: string): this;
|
|
152
|
-
text_fontFamily(): string;
|
|
153
|
-
text_fontFamily(_: string): this;
|
|
154
|
-
paddingLeft(): number;
|
|
155
|
-
paddingLeft(_: number): this;
|
|
156
|
-
paddingRight(): number;
|
|
157
|
-
paddingRight(_: number): this;
|
|
158
|
-
paddingTop(): number;
|
|
159
|
-
paddingTop(_: number): this;
|
|
160
|
-
paddingBottom(): number;
|
|
161
|
-
paddingBottom(_: number): this;
|
|
162
|
-
anchor(): "start" | "middle" | "end";
|
|
163
|
-
anchor(_: "start" | "middle" | "end"): this;
|
|
164
|
-
fixedSize(): ISize;
|
|
165
|
-
fixedSize(_: ISize): this;
|
|
166
|
-
tooltip(): string;
|
|
167
|
-
tooltip(_: string): this;
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
TextBox.prototype.publishProxy("text", "_text");
|
|
171
|
-
TextBox.prototype.publishProxy("fontSize", "_text", "fontSize");
|
|
172
|
-
TextBox.prototype.publishProxy("shape_colorStroke", "_shape", "colorStroke");
|
|
173
|
-
TextBox.prototype.publishProxy("shape_colorFill", "_shape", "colorFill");
|
|
174
|
-
TextBox.prototype.publishProxy("text_colorFill", "_text", "colorFill");
|
|
175
|
-
TextBox.prototype.publishProxy("text_fontFamily", "_text", "fontFamily");
|
|
176
|
-
TextBox.prototype.publish("paddingLeft", 4, "number", "Left padding (in pixels)", null, { tags: ["Private"] });
|
|
177
|
-
TextBox.prototype.publish("paddingRight", 4, "number", "Right padding (in pixels)", null, { tags: ["Private"] });
|
|
178
|
-
TextBox.prototype.publish("paddingTop", 4, "number", "Top padding (in pixels)", null, { tags: ["Private"] });
|
|
179
|
-
TextBox.prototype.publish("paddingBottom", 4, "number", "Bottom padding (in pixels)", null, { tags: ["Private"] });
|
|
180
|
-
TextBox.prototype.publishProxy("anchor", "_text");
|
|
181
|
-
TextBox.prototype.publish("fixedSize", null);
|
|
182
|
-
|
|
183
|
-
TextBox.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|
|
1
|
+
import { textColor } from "./Palette.ts";
|
|
2
|
+
import { Shape } from "./Shape.ts";
|
|
3
|
+
import { SVGWidget } from "./SVGWidget.ts";
|
|
4
|
+
import { Text } from "./Text.ts";
|
|
5
|
+
import { ISize } from "./Widget.ts";
|
|
6
|
+
|
|
7
|
+
import "../src/TextBox.css";
|
|
8
|
+
|
|
9
|
+
export class TextBox extends SVGWidget {
|
|
10
|
+
|
|
11
|
+
protected _shape: Shape;
|
|
12
|
+
protected _text: Text;
|
|
13
|
+
|
|
14
|
+
constructor() {
|
|
15
|
+
super();
|
|
16
|
+
|
|
17
|
+
this._shape = new Shape()
|
|
18
|
+
.shape("rect")
|
|
19
|
+
.on("click", () => {
|
|
20
|
+
this.click();
|
|
21
|
+
})
|
|
22
|
+
.on("dblclick", () => {
|
|
23
|
+
this.dblclick();
|
|
24
|
+
})
|
|
25
|
+
;
|
|
26
|
+
this._text = new Text()
|
|
27
|
+
.on("click", () => {
|
|
28
|
+
this.click();
|
|
29
|
+
})
|
|
30
|
+
.on("dblclick", () => {
|
|
31
|
+
this.dblclick();
|
|
32
|
+
})
|
|
33
|
+
;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
padding(_) {
|
|
37
|
+
this.paddingLeft(_);
|
|
38
|
+
this.paddingRight(_);
|
|
39
|
+
this.paddingTop(_);
|
|
40
|
+
this.paddingBottom(_);
|
|
41
|
+
return this;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
getTextX(width) {
|
|
45
|
+
switch (this.anchor()) {
|
|
46
|
+
case "start":
|
|
47
|
+
return -width / 2;
|
|
48
|
+
case "end":
|
|
49
|
+
return width / 2;
|
|
50
|
+
}
|
|
51
|
+
return 0;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
getBBox(refresh = false, round = false) {
|
|
55
|
+
const textBBox = this._text.getBBox(true);
|
|
56
|
+
const width = this.fixedSize() ? this.fixedSize().width : textBBox.width + this.paddingLeft() + this.paddingRight();
|
|
57
|
+
const height = this.fixedSize() ? this.fixedSize().height : textBBox.height + this.paddingTop() + this.paddingBottom();
|
|
58
|
+
return {
|
|
59
|
+
x: -width - 2,
|
|
60
|
+
y: -height - 2,
|
|
61
|
+
width,
|
|
62
|
+
height
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
enter(domNode, element) {
|
|
67
|
+
super.enter(domNode, element);
|
|
68
|
+
delete this._prevHash;
|
|
69
|
+
this._shape
|
|
70
|
+
.target(domNode)
|
|
71
|
+
.tooltip(this.tooltip())
|
|
72
|
+
;
|
|
73
|
+
this._text
|
|
74
|
+
.target(domNode)
|
|
75
|
+
;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
_prevHash;
|
|
79
|
+
update(domNode, element) {
|
|
80
|
+
super.update(domNode, element);
|
|
81
|
+
const hash = this.hashSum();
|
|
82
|
+
if (this._prevHash !== hash) {
|
|
83
|
+
this._prevHash = hash;
|
|
84
|
+
|
|
85
|
+
const textBBox = this._text.getBBox(true);
|
|
86
|
+
const size = {
|
|
87
|
+
width: this.fixedSize() ? this.fixedSize().width : textBBox.width + this.paddingLeft() + this.paddingRight(),
|
|
88
|
+
height: this.fixedSize() ? this.fixedSize().height : textBBox.height + this.paddingTop() + this.paddingBottom()
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
this._shape
|
|
92
|
+
.width(size.width)
|
|
93
|
+
.height(size.height)
|
|
94
|
+
.render()
|
|
95
|
+
;
|
|
96
|
+
|
|
97
|
+
this._text
|
|
98
|
+
.x(this.getTextX(textBBox.width))
|
|
99
|
+
.colorFill_default(this._shape.colorFill_exists() ? textColor(this._shape.colorFill()) : undefined)
|
|
100
|
+
.render()
|
|
101
|
+
;
|
|
102
|
+
|
|
103
|
+
if (this.fixedSize()) {
|
|
104
|
+
switch (this.anchor()) {
|
|
105
|
+
case "start":
|
|
106
|
+
this._text
|
|
107
|
+
.x(-this.fixedSize().width / 2 + textBBox.width / 2 + (this.paddingLeft() + this.paddingRight()) / 2)
|
|
108
|
+
.render()
|
|
109
|
+
;
|
|
110
|
+
break;
|
|
111
|
+
case "end":
|
|
112
|
+
this._text
|
|
113
|
+
.x(this.fixedSize().width / 2 - textBBox.width / 2 - (this.paddingLeft() + this.paddingRight()) / 2)
|
|
114
|
+
.render()
|
|
115
|
+
;
|
|
116
|
+
break;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
this._text.visible(textBBox.width <= size.width && textBBox.height <= size.height);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
exit(domNode, element) {
|
|
124
|
+
this._shape
|
|
125
|
+
.target(null)
|
|
126
|
+
;
|
|
127
|
+
this._text
|
|
128
|
+
.target(null)
|
|
129
|
+
;
|
|
130
|
+
super.exit(domNode, element);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
click() {
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
dblclick() {
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
TextBox.prototype._class += " common_TextBox";
|
|
140
|
+
|
|
141
|
+
export interface TextBox {
|
|
142
|
+
text(): string;
|
|
143
|
+
text(_: string): this;
|
|
144
|
+
fontSize(): number;
|
|
145
|
+
fontSize(_: number): this;
|
|
146
|
+
shape_colorFill(): string;
|
|
147
|
+
shape_colorFill(_: string): this;
|
|
148
|
+
shape_colorStroke(): string;
|
|
149
|
+
shape_colorStroke(_: string): this;
|
|
150
|
+
text_colorFill(): string;
|
|
151
|
+
text_colorFill(_: string): this;
|
|
152
|
+
text_fontFamily(): string;
|
|
153
|
+
text_fontFamily(_: string): this;
|
|
154
|
+
paddingLeft(): number;
|
|
155
|
+
paddingLeft(_: number): this;
|
|
156
|
+
paddingRight(): number;
|
|
157
|
+
paddingRight(_: number): this;
|
|
158
|
+
paddingTop(): number;
|
|
159
|
+
paddingTop(_: number): this;
|
|
160
|
+
paddingBottom(): number;
|
|
161
|
+
paddingBottom(_: number): this;
|
|
162
|
+
anchor(): "start" | "middle" | "end";
|
|
163
|
+
anchor(_: "start" | "middle" | "end"): this;
|
|
164
|
+
fixedSize(): ISize;
|
|
165
|
+
fixedSize(_: ISize): this;
|
|
166
|
+
tooltip(): string;
|
|
167
|
+
tooltip(_: string): this;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
TextBox.prototype.publishProxy("text", "_text");
|
|
171
|
+
TextBox.prototype.publishProxy("fontSize", "_text", "fontSize");
|
|
172
|
+
TextBox.prototype.publishProxy("shape_colorStroke", "_shape", "colorStroke");
|
|
173
|
+
TextBox.prototype.publishProxy("shape_colorFill", "_shape", "colorFill");
|
|
174
|
+
TextBox.prototype.publishProxy("text_colorFill", "_text", "colorFill");
|
|
175
|
+
TextBox.prototype.publishProxy("text_fontFamily", "_text", "fontFamily");
|
|
176
|
+
TextBox.prototype.publish("paddingLeft", 4, "number", "Left padding (in pixels)", null, { tags: ["Private"] });
|
|
177
|
+
TextBox.prototype.publish("paddingRight", 4, "number", "Right padding (in pixels)", null, { tags: ["Private"] });
|
|
178
|
+
TextBox.prototype.publish("paddingTop", 4, "number", "Top padding (in pixels)", null, { tags: ["Private"] });
|
|
179
|
+
TextBox.prototype.publish("paddingBottom", 4, "number", "Bottom padding (in pixels)", null, { tags: ["Private"] });
|
|
180
|
+
TextBox.prototype.publishProxy("anchor", "_text");
|
|
181
|
+
TextBox.prototype.publish("fixedSize", null);
|
|
182
|
+
|
|
183
|
+
TextBox.prototype.publish("tooltip", "", "string", "Tooltip", null, { tags: ["Private"] });
|