/
Range.ts
237 lines (207 loc) · 4.26 KB
/
Range.ts
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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
import Node from '../node/Node';
import DocumentFragment from '../document-fragment/DocumentFragment';
import DOMRect from './DOMRect';
/**
* Range object.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Range
*/
export default class Range {
private _startContainer: Node = null;
private _endContainer: Node = null;
private _startOffset = -1;
private _endOffset = -1;
private _collapsed = false;
/**
* Returns collapsed.
*
* @returns "true" if collapsed.
*/
public get collapsed(): boolean {
return this._collapsed;
}
/**
* Returns common ancestor container.
*
* @returns Node.
*/
public get commonAncestorContainer(): Node {
return null;
}
/**
* Returns end container.
*
* @returns Node.
*/
public get endContainer(): Node {
return this._endContainer;
}
/**
* Returns start container.
*
* @returns Node.
*/
public get startContainer(): Node {
return this._startContainer;
}
/**
* Returns end offset.
*
* @returns Offset.
*/
public get endOffset(): number {
return this._endOffset;
}
/**
* Returns start offset.
*
* @returns Offset.
*/
public get startOffset(): number {
return this._startOffset;
}
/**
* Sets start.
*
* @param startNode Start node.
* @param startOffset Start offset.
*/
public setStart(startNode: Node, startOffset: number): void {
this._startContainer = startNode;
this._startOffset = startOffset;
}
/**
* Sets end.
*
* @param endNode End node.
* @param endOffset End offset.
*/
public setEnd(endNode: Node, endOffset: number): void {
this._endContainer = endNode;
this._endOffset = endOffset;
}
/**
* Sets start before.
*/
public setStartBefore(): void {}
/**
* Sets start after.
*/
public setStartAfter(): void {}
/**
* Sets end before.
*/
public setEndBefore(): void {}
/**
* Sets end after.
*/
public setEndAfter(): void {}
/**
* Selects a node.
*/
public selectNode(): void {}
/**
* Selects node content.
*/
public selectNodeContents(): void {}
/**
* Collapses the Range to one of its boundary points.
*/
public collapse(): void {
this._collapsed = true;
}
/**
* Removes the contents of a Range from the Document.
*/
public deleteContents(): void {}
/**
* Moves contents of a Range from the document tree into a DocumentFragment.
*/
public extractContents(): DocumentFragment {
return new DocumentFragment();
}
/**
* Insert a Node at the start of a Range.
*/
public insertNode(): void {}
/**
* Moves content of a Range into a new Node.
*/
public surroundContents(): void {}
/**
* Compares the boundary points of the Range with another Range.
*
* @returns "true" when equal.
*/
public compareBoundaryPoints(): boolean {
return false;
}
/**
* Clones the range.
*
* @returns Range.
*/
public cloneRange(): Range {
return new Range();
}
/**
* Releases the Range from use to improve performance.
*/
public detach(): void {}
/**
* Returns the text of the Range.
*
* @returns Text.
*/
public toString(): string {
return '';
}
/**
* Returns -1, 0, or 1 indicating whether the point occurs before, inside, or after the Range.
*
* @returns Number.
*/
public comparePoint(): number {
return 0;
}
/**
* Returns a DocumentFragment created from a given string of code.
*
* @returns Document fragment.
*/
public createContextualFragment(): DocumentFragment {
return new DocumentFragment();
}
/**
* Returns a DOMRect object which bounds the entire contents of the Range; this would be the union of all the rectangles returned by range.getClientRects().
*
* @returns DOM rect.
*/
public getBoundingClientRect(): DOMRect {
return new DOMRect();
}
/**
* Returns a list of DOMRect objects that aggregates the results of Element.getClientRects() for all the elements in the Range.
*
* @returns DOM rect.
*/
public getClientRects(): DOMRect {
return new DOMRect();
}
/**
* Returns a boolean indicating whether the given node intersects the Range.
*
* @returns "true" when intersecting.
*/
public intersectsNode(): boolean {
return false;
}
/**
* Returns a boolean indicating whether the given point is in the Range.
*
* @returns "true" when in range.
*/
public isPointInRange(): boolean {
return false;
}
}