input-element-container.js 3.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. "use strict";
  2. var __extends = (this && this.__extends) || (function () {
  3. var extendStatics = function (d, b) {
  4. extendStatics = Object.setPrototypeOf ||
  5. ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
  6. function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. extendStatics(d, b);
  11. function __() { this.constructor = d; }
  12. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  13. };
  14. })();
  15. Object.defineProperty(exports, "__esModule", { value: true });
  16. var element_container_1 = require("../element-container");
  17. var border_style_1 = require("../../css/property-descriptors/border-style");
  18. var background_clip_1 = require("../../css/property-descriptors/background-clip");
  19. var tokenizer_1 = require("../../css/syntax/tokenizer");
  20. var bounds_1 = require("../../css/layout/bounds");
  21. var CHECKBOX_BORDER_RADIUS = [
  22. {
  23. type: tokenizer_1.TokenType.DIMENSION_TOKEN,
  24. flags: 0,
  25. unit: 'px',
  26. number: 3
  27. }
  28. ];
  29. var RADIO_BORDER_RADIUS = [
  30. {
  31. type: tokenizer_1.TokenType.PERCENTAGE_TOKEN,
  32. flags: 0,
  33. number: 50
  34. }
  35. ];
  36. var reformatInputBounds = function (bounds) {
  37. if (bounds.width > bounds.height) {
  38. return new bounds_1.Bounds(bounds.left + (bounds.width - bounds.height) / 2, bounds.top, bounds.height, bounds.height);
  39. }
  40. else if (bounds.width < bounds.height) {
  41. return new bounds_1.Bounds(bounds.left, bounds.top + (bounds.height - bounds.width) / 2, bounds.width, bounds.width);
  42. }
  43. return bounds;
  44. };
  45. var getInputValue = function (node) {
  46. var value = node.type === exports.PASSWORD ? new Array(node.value.length + 1).join('\u2022') : node.value;
  47. return value.length === 0 ? node.placeholder || '' : value;
  48. };
  49. exports.CHECKBOX = 'checkbox';
  50. exports.RADIO = 'radio';
  51. exports.PASSWORD = 'password';
  52. exports.INPUT_COLOR = 0x2a2a2aff;
  53. var InputElementContainer = /** @class */ (function (_super) {
  54. __extends(InputElementContainer, _super);
  55. function InputElementContainer(input) {
  56. var _this = _super.call(this, input) || this;
  57. _this.type = input.type.toLowerCase();
  58. _this.checked = input.checked;
  59. _this.value = getInputValue(input);
  60. if (_this.type === exports.CHECKBOX || _this.type === exports.RADIO) {
  61. _this.styles.backgroundColor = 0xdededeff;
  62. _this.styles.borderTopColor = _this.styles.borderRightColor = _this.styles.borderBottomColor = _this.styles.borderLeftColor = 0xa5a5a5ff;
  63. _this.styles.borderTopWidth = _this.styles.borderRightWidth = _this.styles.borderBottomWidth = _this.styles.borderLeftWidth = 1;
  64. _this.styles.borderTopStyle = _this.styles.borderRightStyle = _this.styles.borderBottomStyle = _this.styles.borderLeftStyle =
  65. border_style_1.BORDER_STYLE.SOLID;
  66. _this.styles.backgroundClip = [background_clip_1.BACKGROUND_CLIP.BORDER_BOX];
  67. _this.styles.backgroundOrigin = [0 /* BORDER_BOX */];
  68. _this.bounds = reformatInputBounds(_this.bounds);
  69. }
  70. switch (_this.type) {
  71. case exports.CHECKBOX:
  72. _this.styles.borderTopRightRadius = _this.styles.borderTopLeftRadius = _this.styles.borderBottomRightRadius = _this.styles.borderBottomLeftRadius = CHECKBOX_BORDER_RADIUS;
  73. break;
  74. case exports.RADIO:
  75. _this.styles.borderTopRightRadius = _this.styles.borderTopLeftRadius = _this.styles.borderBottomRightRadius = _this.styles.borderBottomLeftRadius = RADIO_BORDER_RADIUS;
  76. break;
  77. }
  78. return _this;
  79. }
  80. return InputElementContainer;
  81. }(element_container_1.ElementContainer));
  82. exports.InputElementContainer = InputElementContainer;
  83. //# sourceMappingURL=input-element-container.js.map