-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathcolumn.js
126 lines (106 loc) · 3.27 KB
/
column.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
"use strict";
module.exports = makeColumn;
function makeColumn(font, tengwa, tengwaNote) {
return new Column(font, tengwa, tengwaNote);
};
var Column = function (font, tengwa, tengwaNote) {
Object.defineProperty(this, "font", {
value: font,
writable: true,
configurable: true,
enumerable: false,
});
this.above = void 0;
this.tildeAbove = void 0;
this.tengwa = tengwa;
this.tildeBelow = void 0;
this.below = void 0;
this.following = void 0;
this.error = void 0;
this.aboveNote = void 0;
this.tildeAboveNote = void 0;
this.tengwaNote = tengwaNote;
this.tildeBelowNote = void 0;
this.belowNote = void 0;
this.followingNote = void 0;
this.hasVariant = false;
};
Column.prototype.canAddAbove = function (tehta, reversed) {
return (
!this.above && !!this.font.tehtaForTengwa(this.tengwa, tehta)
) || ( // flip it
!reversed && !this.below && this.reversed().canAddAbove(tehta, true)
);
};
Column.prototype.addAbove = function (above, aboveNote) {
if (!this.font.tehtaForTengwa(this.tengwa, above)) {
this.reverse();
}
this.above = above;
this.aboveNote = aboveNote;
return this;
};
Column.prototype.canAddBelow = function (tehta, reversed) {
return (
!this.below && !!this.font.tehtaForTengwa(this.tengwa, tehta)
) || ( // flip it
!reversed && !this.above && this.reversed().canAddBelow(tehta, true)
);
};
Column.prototype.addBelow = function (below, belowNote) {
if (!this.font.tehtaForTengwa(this.tengwa, below)) {
this.reverse();
}
this.below = below;
this.belowNote = belowNote;
return this;
};
Column.prototype.addTildeAbove = function (tildeAboveNote) {
this.tildeAbove = true;
this.tildeAboveNote = tildeAboveNote;
return this;
};
Column.prototype.addTildeBelow = function (tildeBelowNote) {
this.tildeBelow = true;
this.tildeBelowNote = tildeBelowNote;
return this;
};
Column.prototype.canAddFollowing = function (following) {
return !this.following && !!this.font.tehtaForTengwa(this.tengwa, following);
};
Column.prototype.addFollowing = function (following, followingNote) {
this.following = following;
this.followingNote = followingNote;
return this;
};
Column.prototype.reversed = function () {
return this.clone().reverse();
};
Column.prototype.clone = function () {
var column = new Column(this.font, this.tengwa);
if (this.above) column.addAbove(this.above, this.aboveNote);
if (this.below) column.addBelow(this.below, this.belowNote);
if (this.following) column.addFollowing(this.following, this.followingNote);
if (this.tildeBelow) column.addTildeBelow(this.tildeBelowNote);
if (this.tildeAbove) column.addTildeAbove(this.tildeAboveNote);
return column;
};
var reversed = {
"silme": "silme-nuquerna",
"esse": "esse-nuquerna",
"silme-nuquerna": "silme",
"esse-nuquerna": "esse"
};
Column.prototype.reverse = function () {
this.tengwa = reversed[this.tengwa] || this.tengwa;
return this;
};
Column.prototype.addError = function (error) {
this.errors = this.errors || [];
this.errors.push(error);
return this;
};
Column.prototype.varies = function () {
this.hasVariant = true;
return this;
};