版博士V2.0程序
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 

219 行
5.8 KiB

  1. import IDocument from '../nodes/document/IDocument';
  2. import INode from '../nodes/node/INode';
  3. import Range from '../range/Range';
  4. /**
  5. * Selection.
  6. *
  7. * Based on logic from:
  8. * https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/selection/Selection-impl.js
  9. *
  10. * Reference:
  11. * https://developer.mozilla.org/en-US/docs/Web/API/Selection.
  12. */
  13. export default class Selection {
  14. private readonly _ownerDocument;
  15. private _range;
  16. private _direction;
  17. /**
  18. * Constructor.
  19. *
  20. * @param ownerDocument Owner document.
  21. */
  22. constructor(ownerDocument: IDocument);
  23. /**
  24. * Returns range count.
  25. *
  26. * @see https://w3c.github.io/selection-api/#dom-selection-rangecount
  27. * @returns Range count.
  28. */
  29. get rangeCount(): number;
  30. /**
  31. * Returns collapsed state.
  32. *
  33. * @see https://w3c.github.io/selection-api/#dom-selection-iscollapsed
  34. * @returns "true" if collapsed.
  35. */
  36. get isCollapsed(): boolean;
  37. /**
  38. * Returns type.
  39. *
  40. * @see https://w3c.github.io/selection-api/#dom-selection-type
  41. * @returns Type.
  42. */
  43. get type(): string;
  44. /**
  45. * Returns anchor node.
  46. *
  47. * @see https://w3c.github.io/selection-api/#dom-selection-anchornode
  48. * @returns Node.
  49. */
  50. get anchorNode(): INode;
  51. /**
  52. * Returns anchor offset.
  53. *
  54. * @see https://w3c.github.io/selection-api/#dom-selection-anchoroffset
  55. * @returns Node.
  56. */
  57. get anchorOffset(): number;
  58. /**
  59. * Returns anchor node.
  60. *
  61. * @deprecated
  62. * @alias anchorNode
  63. * @returns Node.
  64. */
  65. get baseNode(): INode;
  66. /**
  67. * Returns anchor offset.
  68. *
  69. * @deprecated
  70. * @alias anchorOffset
  71. * @returns Node.
  72. */
  73. get baseOffset(): number;
  74. /**
  75. * Returns focus node.
  76. *
  77. * @see https://w3c.github.io/selection-api/#dom-selection-focusnode
  78. * @returns Node.
  79. */
  80. get focusNode(): INode;
  81. /**
  82. * Returns focus offset.
  83. *
  84. * @see https://w3c.github.io/selection-api/#dom-selection-focusoffset
  85. * @returns Node.
  86. */
  87. get focusOffset(): number;
  88. /**
  89. * Returns focus node.
  90. *
  91. * @deprecated
  92. * @alias focusNode
  93. * @returns Node.
  94. */
  95. get extentNode(): INode;
  96. /**
  97. * Returns focus offset.
  98. *
  99. * @deprecated
  100. * @alias focusOffset
  101. * @returns Node.
  102. */
  103. get extentOffset(): number;
  104. /**
  105. * Adds a range.
  106. *
  107. * @see https://w3c.github.io/selection-api/#dom-selection-addrange
  108. * @param newRange Range.
  109. */
  110. addRange(newRange: Range): void;
  111. /**
  112. * Returns Range.
  113. *
  114. * @see https://w3c.github.io/selection-api/#dom-selection-getrangeat
  115. * @param index Index.
  116. * @returns Range.
  117. */
  118. getRangeAt(index: number): Range;
  119. /**
  120. * Removes a range from a selection.
  121. *
  122. * @see https://w3c.github.io/selection-api/#dom-selection-removerange
  123. * @param range Range.
  124. */
  125. removeRange(range: Range): void;
  126. /**
  127. * Removes all ranges.
  128. */
  129. removeAllRanges(): void;
  130. /**
  131. * Removes all ranges.
  132. *
  133. * @alias removeAllRanges()
  134. */
  135. empty(): void;
  136. /**
  137. * Collapses the current selection to a single point.
  138. *
  139. * @see https://w3c.github.io/selection-api/#dom-selection-collapse
  140. * @param node Node.
  141. * @param offset Offset.
  142. */
  143. collapse(node: INode, offset: number): void;
  144. /**
  145. * Collapses the current selection to a single point.
  146. *
  147. * @see https://w3c.github.io/selection-api/#dom-selection-setposition
  148. * @alias collapse()
  149. * @param node Node.
  150. * @param offset Offset.
  151. */
  152. setPosition(node: INode, offset: number): void;
  153. /**
  154. * Collapses the selection to the end.
  155. *
  156. * @see https://w3c.github.io/selection-api/#dom-selection-collapsetoend
  157. */
  158. collapseToEnd(): void;
  159. /**
  160. * Collapses the selection to the start.
  161. *
  162. * @see https://w3c.github.io/selection-api/#dom-selection-collapsetostart
  163. */
  164. collapseToStart(): void;
  165. /**
  166. * Indicates whether a specified node is part of the selection.
  167. *
  168. * @see https://w3c.github.io/selection-api/#dom-selection-containsnode
  169. * @param node Node.
  170. * @param [allowPartialContainment] Set to "true" to allow partial containment.
  171. * @returns Always returns "true" for now.
  172. */
  173. containsNode(node: INode, allowPartialContainment?: boolean): boolean;
  174. /**
  175. * Deletes the selected text from the document's DOM.
  176. *
  177. * @see https://w3c.github.io/selection-api/#dom-selection-deletefromdocument
  178. */
  179. deleteFromDocument(): void;
  180. /**
  181. * Moves the focus of the selection to a specified point.
  182. *
  183. * @see https://w3c.github.io/selection-api/#dom-selection-extend
  184. * @param node Node.
  185. * @param offset Offset.
  186. */
  187. extend(node: INode, offset: number): void;
  188. /**
  189. * Selects all children.
  190. *
  191. * @see https://w3c.github.io/selection-api/#dom-selection-selectallchildren
  192. * @param node
  193. * @param _parentNode Parent node.
  194. */
  195. selectAllChildren(node: INode): void;
  196. /**
  197. * Sets the selection to be a range including all or parts of two specified DOM nodes, and any content located between them.
  198. *
  199. * @see https://w3c.github.io/selection-api/#dom-selection-setbaseandextent
  200. * @param anchorNode Anchor node.
  201. * @param anchorOffset Anchor offset.
  202. * @param focusNode Focus node.
  203. * @param focusOffset Focus offset.
  204. */
  205. setBaseAndExtent(anchorNode: INode, anchorOffset: number, focusNode: INode, focusOffset: number): void;
  206. /**
  207. * Returns string currently being represented by the selection object.
  208. *
  209. * @returns Selection as string.
  210. */
  211. toString(): string;
  212. /**
  213. * Sets the current range.
  214. *
  215. * @param range Range.
  216. */
  217. protected _associateRange(range: Range): void;
  218. }