版博士V2.0程序
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

1 год назад
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893
  1. "use strict";
  2. var __importDefault = (this && this.__importDefault) || function (mod) {
  3. return (mod && mod.__esModule) ? mod : { "default": mod };
  4. };
  5. Object.defineProperty(exports, "__esModule", { value: true });
  6. const HTMLElement_1 = __importDefault(require("../html-element/HTMLElement"));
  7. const ValidityState_1 = __importDefault(require("../validity-state/ValidityState"));
  8. const DOMException_1 = __importDefault(require("../../exception/DOMException"));
  9. const DOMExceptionNameEnum_1 = __importDefault(require("../../exception/DOMExceptionNameEnum"));
  10. const Event_1 = __importDefault(require("../../event/Event"));
  11. const HTMLInputElementValueSanitizer_1 = __importDefault(require("./HTMLInputElementValueSanitizer"));
  12. const HTMLInputElementSelectionModeEnum_1 = __importDefault(require("./HTMLInputElementSelectionModeEnum"));
  13. const HTMLInputElementSelectionDirectionEnum_1 = __importDefault(require("./HTMLInputElementSelectionDirectionEnum"));
  14. const HTMLInputElementValueStepping_1 = __importDefault(require("./HTMLInputElementValueStepping"));
  15. const FileList_1 = __importDefault(require("./FileList"));
  16. /**
  17. * HTML Input Element.
  18. *
  19. * Reference:
  20. * https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement.
  21. *
  22. * Used as reference for some of the logic (like selection range):
  23. * https://github.com/jsdom/jsdom/blob/master/lib/jsdom/living/nodes/nodes/HTMLInputElement-impl.js (MIT licensed).
  24. */
  25. class HTMLInputElement extends HTMLElement_1.default {
  26. constructor() {
  27. super(...arguments);
  28. // Related to parent form.
  29. this.formAction = '';
  30. this.formMethod = '';
  31. this.formNoValidate = false;
  32. // Any type of input
  33. this._value = null;
  34. this._height = 0;
  35. this._width = 0;
  36. // Type specific: checkbox/radio
  37. this.defaultChecked = false;
  38. // Type specific: file
  39. this.files = new FileList_1.default();
  40. // Events
  41. this.oninput = null;
  42. this.oninvalid = null;
  43. this.onselectionchange = null;
  44. // Type specific: text/password/search/tel/url/week/month
  45. this._selectionStart = null;
  46. this._selectionEnd = null;
  47. this._selectionDirection = HTMLInputElementSelectionDirectionEnum_1.default.none;
  48. this._validationMessage = '';
  49. }
  50. /**
  51. * Returns height.
  52. *
  53. * @returns Height.
  54. */
  55. get height() {
  56. return this._height;
  57. }
  58. /**
  59. * Sets height.
  60. *
  61. * @param height Height.
  62. */
  63. set height(height) {
  64. this._height = height;
  65. this.setAttributeNS(null, 'height', String(height));
  66. }
  67. /**
  68. * Returns width.
  69. *
  70. * @returns Width.
  71. */
  72. get width() {
  73. return this._width;
  74. }
  75. /**
  76. * Sets width.
  77. *
  78. * @param width Width.
  79. */
  80. set width(width) {
  81. this._width = width;
  82. this.setAttributeNS(null, 'width', String(width));
  83. }
  84. /**
  85. * Returns size.
  86. *
  87. * @returns Size.
  88. */
  89. get size() {
  90. const size = this.getAttributeNS(null, 'size');
  91. if (size !== null) {
  92. return parseInt(size);
  93. }
  94. return 20;
  95. }
  96. /**
  97. * Sets size.
  98. *
  99. * @param size Size.
  100. */
  101. set size(size) {
  102. this.setAttributeNS(null, 'size', String(size));
  103. }
  104. /**
  105. * Returns minlength.
  106. *
  107. * @returns Min length.
  108. */
  109. get minLength() {
  110. const minLength = this.getAttributeNS(null, 'minlength');
  111. if (minLength !== null) {
  112. return parseInt(minLength);
  113. }
  114. return -1;
  115. }
  116. /**
  117. * Sets minlength.
  118. *
  119. * @param minLength Min length.
  120. */
  121. set minLength(minlength) {
  122. this.setAttributeNS(null, 'minlength', String(minlength));
  123. }
  124. /**
  125. * Returns maxlength.
  126. *
  127. * @returns Max length.
  128. */
  129. get maxLength() {
  130. const maxLength = this.getAttributeNS(null, 'maxlength');
  131. if (maxLength !== null) {
  132. return parseInt(maxLength);
  133. }
  134. return -1;
  135. }
  136. /**
  137. * Sets maxlength.
  138. *
  139. * @param maxlength Max length.
  140. */
  141. set maxLength(maxLength) {
  142. this.setAttributeNS(null, 'maxlength', String(maxLength));
  143. }
  144. /**
  145. * Returns type.
  146. *
  147. * @returns Type. Defaults to "text".
  148. */
  149. get type() {
  150. return this.getAttributeNS(null, 'type') || 'text';
  151. }
  152. /**
  153. * Sets type.
  154. *
  155. * @param type Type.
  156. */
  157. set type(type) {
  158. this.setAttributeNS(null, 'type', type.toLowerCase());
  159. }
  160. /**
  161. * Returns name.
  162. *
  163. * @returns Name.
  164. */
  165. get name() {
  166. return this.getAttributeNS(null, 'name') || '';
  167. }
  168. /**
  169. * Sets name.
  170. *
  171. * @param name Name.
  172. */
  173. set name(name) {
  174. this.setAttributeNS(null, 'name', name);
  175. }
  176. /**
  177. * Returns alt.
  178. *
  179. * @returns Alt.
  180. */
  181. get alt() {
  182. return this.getAttributeNS(null, 'alt') || '';
  183. }
  184. /**
  185. * Sets alt.
  186. *
  187. * @param alt Alt.
  188. */
  189. set alt(alt) {
  190. this.setAttributeNS(null, 'alt', alt);
  191. }
  192. /**
  193. * Returns min.
  194. *
  195. * @returns Min.
  196. */
  197. get min() {
  198. return this.getAttributeNS(null, 'min') || '';
  199. }
  200. /**
  201. * Sets min.
  202. *
  203. * @param min Min.
  204. */
  205. set min(min) {
  206. this.setAttributeNS(null, 'min', min);
  207. }
  208. /**
  209. * Returns max.
  210. *
  211. * @returns Max.
  212. */
  213. get max() {
  214. return this.getAttributeNS(null, 'max') || '';
  215. }
  216. /**
  217. * Sets max.
  218. *
  219. * @param max Max.
  220. */
  221. set max(max) {
  222. this.setAttributeNS(null, 'max', max);
  223. }
  224. /**
  225. * Returns pattern.
  226. *
  227. * @returns Pattern.
  228. */
  229. get pattern() {
  230. return this.getAttributeNS(null, 'pattern') || '';
  231. }
  232. /**
  233. * Sets pattern.
  234. *
  235. * @param pattern Pattern.
  236. */
  237. set pattern(pattern) {
  238. this.setAttributeNS(null, 'pattern', pattern);
  239. }
  240. /**
  241. * Returns placeholder.
  242. *
  243. * @returns Placeholder.
  244. */
  245. get placeholder() {
  246. return this.getAttributeNS(null, 'placeholder') || '';
  247. }
  248. /**
  249. * Sets placeholder.
  250. *
  251. * @param placeholder Placeholder.
  252. */
  253. set placeholder(placeholder) {
  254. this.setAttributeNS(null, 'placeholder', placeholder);
  255. }
  256. /**
  257. * Returns step.
  258. *
  259. * @returns Step.
  260. */
  261. get step() {
  262. return this.getAttributeNS(null, 'step') || '';
  263. }
  264. /**
  265. * Sets step.
  266. *
  267. * @param step Step.
  268. */
  269. set step(step) {
  270. this.setAttributeNS(null, 'step', step);
  271. }
  272. /**
  273. * Returns inputmode.
  274. *
  275. * @returns Inputmode.
  276. */
  277. get inputmode() {
  278. return this.getAttributeNS(null, 'inputmode') || '';
  279. }
  280. /**
  281. * Sets inputmode.
  282. *
  283. * @param inputmode Inputmode.
  284. */
  285. set inputmode(inputmode) {
  286. this.setAttributeNS(null, 'inputmode', inputmode);
  287. }
  288. /**
  289. * Returns accept.
  290. *
  291. * @returns Accept.
  292. */
  293. get accept() {
  294. return this.getAttributeNS(null, 'accept') || '';
  295. }
  296. /**
  297. * Sets accept.
  298. *
  299. * @param accept Accept.
  300. */
  301. set accept(accept) {
  302. this.setAttributeNS(null, 'accept', accept);
  303. }
  304. /**
  305. * Returns allowdirs.
  306. *
  307. * @returns Allowdirs.
  308. */
  309. get allowdirs() {
  310. return this.getAttributeNS(null, 'allowdirs') || '';
  311. }
  312. /**
  313. * Sets allowdirs.
  314. *
  315. * @param allowdirs Allowdirs.
  316. */
  317. set allowdirs(allowdirs) {
  318. this.setAttributeNS(null, 'allowdirs', allowdirs);
  319. }
  320. /**
  321. * Returns autocomplete.
  322. *
  323. * @returns Autocomplete.
  324. */
  325. get autocomplete() {
  326. return this.getAttributeNS(null, 'autocomplete') || '';
  327. }
  328. /**
  329. * Sets autocomplete.
  330. *
  331. * @param autocomplete Autocomplete.
  332. */
  333. set autocomplete(autocomplete) {
  334. this.setAttributeNS(null, 'autocomplete', autocomplete);
  335. }
  336. /**
  337. * Returns src.
  338. *
  339. * @returns Src.
  340. */
  341. get src() {
  342. return this.getAttributeNS(null, 'src') || '';
  343. }
  344. /**
  345. * Sets src.
  346. *
  347. * @param src Src.
  348. */
  349. set src(src) {
  350. this.setAttributeNS(null, 'src', src);
  351. }
  352. /**
  353. * Returns defaultValue.
  354. *
  355. * @returns Defaultvalue.
  356. */
  357. get defaultValue() {
  358. return this.getAttributeNS(null, 'defaultvalue') || '';
  359. }
  360. /**
  361. * Sets defaultValue.
  362. *
  363. * @param defaultValue Defaultvalue.
  364. */
  365. set defaultValue(defaultValue) {
  366. this.setAttributeNS(null, 'defaultvalue', defaultValue);
  367. }
  368. /**
  369. * Returns read only.
  370. *
  371. * @returns Read only.
  372. */
  373. get readOnly() {
  374. return this.getAttributeNS(null, 'readonly') !== null;
  375. }
  376. /**
  377. * Sets read only.
  378. *
  379. * @param readOnly Read only.
  380. */
  381. set readOnly(readOnly) {
  382. if (!readOnly) {
  383. this.removeAttributeNS(null, 'readonly');
  384. }
  385. else {
  386. this.setAttributeNS(null, 'readonly', '');
  387. }
  388. }
  389. /**
  390. * Returns disabled.
  391. *
  392. * @returns Disabled.
  393. */
  394. get disabled() {
  395. return this.getAttributeNS(null, 'disabled') !== null;
  396. }
  397. /**
  398. * Sets disabled.
  399. *
  400. * @param disabled Disabled.
  401. */
  402. set disabled(disabled) {
  403. if (!disabled) {
  404. this.removeAttributeNS(null, 'disabled');
  405. }
  406. else {
  407. this.setAttributeNS(null, 'disabled', '');
  408. }
  409. }
  410. /**
  411. * Returns autofocus.
  412. *
  413. * @returns Autofocus.
  414. */
  415. get autofocus() {
  416. return this.getAttributeNS(null, 'autofocus') !== null;
  417. }
  418. /**
  419. * Sets autofocus.
  420. *
  421. * @param autofocus Autofocus.
  422. */
  423. set autofocus(autofocus) {
  424. if (!autofocus) {
  425. this.removeAttributeNS(null, 'autofocus');
  426. }
  427. else {
  428. this.setAttributeNS(null, 'autofocus', '');
  429. }
  430. }
  431. /**
  432. * Returns required.
  433. *
  434. * @returns Required.
  435. */
  436. get required() {
  437. return this.getAttributeNS(null, 'required') !== null;
  438. }
  439. /**
  440. * Sets required.
  441. *
  442. * @param required Required.
  443. */
  444. set required(required) {
  445. if (!required) {
  446. this.removeAttributeNS(null, 'required');
  447. }
  448. else {
  449. this.setAttributeNS(null, 'required', '');
  450. }
  451. }
  452. /**
  453. * Returns indeterminate.
  454. *
  455. * @returns Indeterminate.
  456. */
  457. get indeterminate() {
  458. return this.getAttributeNS(null, 'indeterminate') !== null;
  459. }
  460. /**
  461. * Sets indeterminate.
  462. *
  463. * @param indeterminate Indeterminate.
  464. */
  465. set indeterminate(indeterminate) {
  466. if (!indeterminate) {
  467. this.removeAttributeNS(null, 'indeterminate');
  468. }
  469. else {
  470. this.setAttributeNS(null, 'indeterminate', '');
  471. }
  472. }
  473. /**
  474. * Returns multiple.
  475. *
  476. * @returns Multiple.
  477. */
  478. get multiple() {
  479. return this.getAttributeNS(null, 'multiple') !== null;
  480. }
  481. /**
  482. * Sets multiple.
  483. *
  484. * @param multiple Multiple.
  485. */
  486. set multiple(multiple) {
  487. if (!multiple) {
  488. this.removeAttributeNS(null, 'multiple');
  489. }
  490. else {
  491. this.setAttributeNS(null, 'multiple', '');
  492. }
  493. }
  494. /**
  495. * Returns checked.
  496. *
  497. * @returns Checked.
  498. */
  499. get checked() {
  500. return this.getAttributeNS(null, 'checked') !== null;
  501. }
  502. /**
  503. * Sets checked.
  504. *
  505. * @param checked Checked.
  506. */
  507. set checked(checked) {
  508. if (!checked) {
  509. this.removeAttributeNS(null, 'checked');
  510. }
  511. else {
  512. this.setAttributeNS(null, 'checked', '');
  513. }
  514. }
  515. /**
  516. * Returns value.
  517. *
  518. * @returns Value.
  519. */
  520. get value() {
  521. switch (this.type) {
  522. case 'hidden':
  523. case 'submit':
  524. case 'image':
  525. case 'reset':
  526. case 'button':
  527. return this.getAttributeNS(null, 'value') || '';
  528. case 'checkbox':
  529. case 'radio':
  530. const attritube = this.getAttributeNS(null, 'value');
  531. return attritube !== null ? attritube : 'on';
  532. case 'file':
  533. return this.files.length > 0 ? '/fake/path/' + this.files[0].name : '';
  534. }
  535. if (this._value === null) {
  536. return this.getAttributeNS(null, 'value') || '';
  537. }
  538. return this._value;
  539. }
  540. /**
  541. * Sets value.
  542. *
  543. * @param value Value.
  544. */
  545. set value(value) {
  546. // The value maybe not string, so we need to convert it to string
  547. value = String(value);
  548. switch (this.type) {
  549. case 'hidden':
  550. case 'submit':
  551. case 'image':
  552. case 'reset':
  553. case 'button':
  554. case 'checkbox':
  555. case 'radio':
  556. this.setAttributeNS(null, 'value', value);
  557. break;
  558. case 'file':
  559. if (value !== '') {
  560. throw new DOMException_1.default('Input elements of type "file" may only programmatically set the value to empty string.', DOMExceptionNameEnum_1.default.invalidStateError);
  561. }
  562. break;
  563. default:
  564. const oldValue = this._value;
  565. this._value = HTMLInputElementValueSanitizer_1.default.sanitize(this, value);
  566. if (oldValue !== this._value) {
  567. this._selectionStart = this._value.length;
  568. this._selectionEnd = this._value.length;
  569. this._selectionDirection = HTMLInputElementSelectionDirectionEnum_1.default.none;
  570. }
  571. break;
  572. }
  573. }
  574. /**
  575. * Returns selection start.
  576. *
  577. * @returns Selection start.
  578. */
  579. get selectionStart() {
  580. if (!this._isSelectionSupported()) {
  581. return null;
  582. }
  583. if (this._selectionStart === null) {
  584. return this.value.length;
  585. }
  586. return this._selectionStart;
  587. }
  588. /**
  589. * Sets selection start.
  590. *
  591. * @param start Start.
  592. */
  593. set selectionStart(start) {
  594. if (!this._isSelectionSupported()) {
  595. throw new DOMException_1.default(`The input element's type (${this.type}) does not support selection.`, DOMExceptionNameEnum_1.default.invalidStateError);
  596. }
  597. this.setSelectionRange(start, Math.max(start, this.selectionEnd), this._selectionDirection);
  598. }
  599. /**
  600. * Returns selection end.
  601. *
  602. * @returns Selection end.
  603. */
  604. get selectionEnd() {
  605. if (!this._isSelectionSupported()) {
  606. return null;
  607. }
  608. if (this._selectionEnd === null) {
  609. return this.value.length;
  610. }
  611. return this._selectionEnd;
  612. }
  613. /**
  614. * Sets selection end.
  615. *
  616. * @param end End.
  617. */
  618. set selectionEnd(end) {
  619. if (!this._isSelectionSupported()) {
  620. throw new DOMException_1.default(`The input element's type (${this.type}) does not support selection.`, DOMExceptionNameEnum_1.default.invalidStateError);
  621. }
  622. this.setSelectionRange(this.selectionStart, end, this._selectionDirection);
  623. }
  624. /**
  625. * Returns selection direction.
  626. *
  627. * @returns Selection direction.
  628. */
  629. get selectionDirection() {
  630. if (!this._isSelectionSupported()) {
  631. return null;
  632. }
  633. return this._selectionDirection;
  634. }
  635. /**
  636. * Sets selection direction.
  637. *
  638. * @param direction Direction.
  639. */
  640. set selectionDirection(direction) {
  641. if (!this._isSelectionSupported()) {
  642. throw new DOMException_1.default(`The input element's type (${this.type}) does not support selection.`, DOMExceptionNameEnum_1.default.invalidStateError);
  643. }
  644. this.setSelectionRange(this._selectionStart, this._selectionEnd, direction);
  645. }
  646. /**
  647. * Returns the parent form element.
  648. *
  649. * @returns Form.
  650. */
  651. get form() {
  652. let parent = this.parentNode;
  653. while (parent && parent.tagName !== 'FORM') {
  654. parent = parent.parentNode;
  655. }
  656. return parent;
  657. }
  658. /**
  659. * Returns validity state.
  660. *
  661. * @returns Validity state.
  662. */
  663. get validity() {
  664. return new ValidityState_1.default(this);
  665. }
  666. /**
  667. * Returns "true" if it will validate.
  668. *
  669. * @returns "true" if it will validate.
  670. */
  671. get willValidate() {
  672. return (this.type !== 'hidden' &&
  673. this.type !== 'reset' &&
  674. this.type !== 'button' &&
  675. !this.disabled &&
  676. !this['readOnly']);
  677. }
  678. /**
  679. * Returns value as Date.
  680. *
  681. * @returns Date.
  682. */
  683. get valueAsDate() {
  684. return this.value ? new Date(this.value) : null;
  685. }
  686. /**
  687. * Returns value as number.
  688. *
  689. * @returns Number.
  690. */
  691. get valueAsNumber() {
  692. return this.value ? parseFloat(this.value) : NaN;
  693. }
  694. /**
  695. * Returns validation message.
  696. *
  697. * @returns Validation message.
  698. */
  699. get validationMessage() {
  700. return this._validationMessage;
  701. }
  702. /**
  703. * Sets validation message.
  704. *
  705. * @param message Message.
  706. */
  707. setCustomValidity(message) {
  708. this._validationMessage = String(message);
  709. }
  710. /**
  711. * Reports validity by dispatching an "invalid" event.
  712. */
  713. reportValidity() {
  714. if (this._validationMessage) {
  715. this.dispatchEvent(new Event_1.default('invalid', {
  716. bubbles: true,
  717. cancelable: true
  718. }));
  719. }
  720. }
  721. /**
  722. * Selects the text.
  723. */
  724. select() {
  725. if (!this._isSelectionSupported()) {
  726. return null;
  727. }
  728. this._selectionStart = 0;
  729. this._selectionEnd = this.value.length;
  730. this._selectionDirection = HTMLInputElementSelectionDirectionEnum_1.default.none;
  731. this.dispatchEvent(new Event_1.default('select', { bubbles: true, cancelable: true }));
  732. }
  733. /**
  734. * Set selection range.
  735. *
  736. * @param start Start.
  737. * @param end End.
  738. * @param [direction="none"] Direction.
  739. */
  740. setSelectionRange(start, end, direction = 'none') {
  741. if (!this._isSelectionSupported()) {
  742. throw new DOMException_1.default(`The input element's type (${this.type}) does not support selection.`, DOMExceptionNameEnum_1.default.invalidStateError);
  743. }
  744. this._selectionEnd = Math.min(end, this.value.length);
  745. this._selectionStart = Math.min(start, this._selectionEnd);
  746. this._selectionDirection =
  747. direction === HTMLInputElementSelectionDirectionEnum_1.default.forward ||
  748. direction === HTMLInputElementSelectionDirectionEnum_1.default.backward
  749. ? direction
  750. : HTMLInputElementSelectionDirectionEnum_1.default.none;
  751. this.dispatchEvent(new Event_1.default('select', { bubbles: true, cancelable: true }));
  752. }
  753. /**
  754. * Set range text.
  755. *
  756. * @param replacement Replacement.
  757. * @param [start] Start.
  758. * @param [end] End.
  759. * @param [direction] Direction.
  760. * @param selectionMode
  761. */
  762. setRangeText(replacement, start = null, end = null, selectionMode = HTMLInputElementSelectionModeEnum_1.default.preserve) {
  763. if (!this._isSelectionSupported()) {
  764. throw new DOMException_1.default(`The input element's type (${this.type}) does not support selection.`, DOMExceptionNameEnum_1.default.invalidStateError);
  765. }
  766. if (start === null) {
  767. start = this._selectionStart;
  768. }
  769. if (end === null) {
  770. end = this._selectionEnd;
  771. }
  772. if (start > end) {
  773. throw new DOMException_1.default('The index is not in the allowed range.', DOMExceptionNameEnum_1.default.invalidStateError);
  774. }
  775. start = Math.min(start, this.value.length);
  776. end = Math.min(end, this.value.length);
  777. const val = this.value;
  778. let selectionStart = this._selectionStart;
  779. let selectionEnd = this._selectionEnd;
  780. this.value = val.slice(0, start) + replacement + val.slice(end);
  781. const newEnd = start + this.value.length;
  782. switch (selectionMode) {
  783. case HTMLInputElementSelectionModeEnum_1.default.select:
  784. this.setSelectionRange(start, newEnd);
  785. break;
  786. case HTMLInputElementSelectionModeEnum_1.default.start:
  787. this.setSelectionRange(start, start);
  788. break;
  789. case HTMLInputElementSelectionModeEnum_1.default.end:
  790. this.setSelectionRange(newEnd, newEnd);
  791. break;
  792. default:
  793. const delta = replacement.length - (end - start);
  794. if (selectionStart > end) {
  795. selectionStart += delta;
  796. }
  797. else if (selectionStart > start) {
  798. selectionStart = start;
  799. }
  800. if (selectionEnd > end) {
  801. selectionEnd += delta;
  802. }
  803. else if (selectionEnd > start) {
  804. selectionEnd = newEnd;
  805. }
  806. this.setSelectionRange(selectionStart, selectionEnd);
  807. break;
  808. }
  809. }
  810. /**
  811. * Checks validity.
  812. *
  813. * @returns "true" if the field is valid.
  814. */
  815. checkValidity() {
  816. return true;
  817. }
  818. /**
  819. * Steps up.
  820. *
  821. * @param [increment] Increment.
  822. */
  823. stepUp(increment) {
  824. const newValue = HTMLInputElementValueStepping_1.default.step(this.type, this.value, 1, increment);
  825. if (newValue !== null) {
  826. this.value = newValue;
  827. }
  828. }
  829. /**
  830. * Steps down.
  831. *
  832. * @param [increment] Increment.
  833. */
  834. stepDown(increment) {
  835. const newValue = HTMLInputElementValueStepping_1.default.step(this.type, this.value, -1, increment);
  836. if (newValue !== null) {
  837. this.value = newValue;
  838. }
  839. }
  840. /**
  841. * Clones a node.
  842. *
  843. * @override
  844. * @param [deep=false] "true" to clone deep.
  845. * @returns Cloned node.
  846. */
  847. cloneNode(deep = false) {
  848. const clone = super.cloneNode(deep);
  849. clone.formAction = this.formAction;
  850. clone.formMethod = this.formMethod;
  851. clone.formNoValidate = this.formNoValidate;
  852. clone._value = this._value;
  853. clone._height = this._height;
  854. clone._width = this._width;
  855. clone.defaultChecked = this.defaultChecked;
  856. clone.files = this.files.slice();
  857. clone._selectionStart = this._selectionStart;
  858. clone._selectionEnd = this._selectionEnd;
  859. clone._selectionDirection = this._selectionDirection;
  860. return clone;
  861. }
  862. /**
  863. * Checks if private value is supported.
  864. *
  865. * @returns "true" if private value is supported.
  866. */
  867. // Private _isPrivateValueSupported(): boolean {
  868. // Return (
  869. // This.type !== 'hidden' &&
  870. // This.type !== 'submit' &&
  871. // This.type !== 'image' &&
  872. // This.type !== 'reset' &&
  873. // This.type !== 'button' &&
  874. // This.type !== 'checkbox' &&
  875. // This.type !== 'radio' &&
  876. // This.type !== 'file'
  877. // );
  878. // }
  879. /**
  880. * Checks is selection is supported.
  881. *
  882. * @returns "true" if selection is supported.
  883. */
  884. _isSelectionSupported() {
  885. return (this.type === 'text' ||
  886. this.type === 'search' ||
  887. this.type === 'url' ||
  888. this.type === 'tel' ||
  889. this.type === 'password');
  890. }
  891. }
  892. exports.default = HTMLInputElement;
  893. //# sourceMappingURL=HTMLInputElement.js.map