input-element-container.js 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
  7. return extendStatics(d, b);
  8. };
  9. return function (d, b) {
  10. if (typeof b !== "function" && b !== null)
  11. throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
  12. extendStatics(d, b);
  13. function __() { this.constructor = d; }
  14. d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
  15. };
  16. })();
  17. Object.defineProperty(exports, "__esModule", { value: true });
  18. exports.InputElementContainer = exports.INPUT_COLOR = exports.PASSWORD = exports.RADIO = exports.CHECKBOX = void 0;
  19. var element_container_1 = require("../element-container");
  20. var bounds_1 = require("../../css/layout/bounds");
  21. var CHECKBOX_BORDER_RADIUS = [
  22. {
  23. type: 15 /* DIMENSION_TOKEN */,
  24. flags: 0,
  25. unit: 'px',
  26. number: 3
  27. }
  28. ];
  29. var RADIO_BORDER_RADIUS = [
  30. {
  31. type: 16 /* 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(context, input) {
  56. var _this = _super.call(this, context, 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 =
  63. _this.styles.borderRightColor =
  64. _this.styles.borderBottomColor =
  65. _this.styles.borderLeftColor =
  66. 0xa5a5a5ff;
  67. _this.styles.borderTopWidth =
  68. _this.styles.borderRightWidth =
  69. _this.styles.borderBottomWidth =
  70. _this.styles.borderLeftWidth =
  71. 1;
  72. _this.styles.borderTopStyle =
  73. _this.styles.borderRightStyle =
  74. _this.styles.borderBottomStyle =
  75. _this.styles.borderLeftStyle =
  76. 1 /* SOLID */;
  77. _this.styles.backgroundClip = [0 /* BORDER_BOX */];
  78. _this.styles.backgroundOrigin = [0 /* BORDER_BOX */];
  79. _this.bounds = reformatInputBounds(_this.bounds);
  80. }
  81. switch (_this.type) {
  82. case exports.CHECKBOX:
  83. _this.styles.borderTopRightRadius =
  84. _this.styles.borderTopLeftRadius =
  85. _this.styles.borderBottomRightRadius =
  86. _this.styles.borderBottomLeftRadius =
  87. CHECKBOX_BORDER_RADIUS;
  88. break;
  89. case exports.RADIO:
  90. _this.styles.borderTopRightRadius =
  91. _this.styles.borderTopLeftRadius =
  92. _this.styles.borderBottomRightRadius =
  93. _this.styles.borderBottomLeftRadius =
  94. RADIO_BORDER_RADIUS;
  95. break;
  96. }
  97. return _this;
  98. }
  99. return InputElementContainer;
  100. }(element_container_1.ElementContainer));
  101. exports.InputElementContainer = InputElementContainer;
  102. //# sourceMappingURL=input-element-container.js.map