SColor.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. exports.SColor = void 0;
  4. var lib_1 = require("@persagy-web/base/lib");
  5. var SColor = (function () {
  6. function SColor(r, g, b, a) {
  7. this._value = 0xff;
  8. if (r == undefined) {
  9. this._value = 0xff;
  10. }
  11. else if (typeof r == "string") {
  12. this.value = r;
  13. }
  14. else if (r instanceof SColor) {
  15. this._value = r._value;
  16. }
  17. else if (a == undefined) {
  18. this.setRgb(r, g, b);
  19. }
  20. else {
  21. this.setRgba(r, g, b, a);
  22. }
  23. }
  24. SColor.rgb = function (r, g, b) {
  25. return new SColor(r, g, b);
  26. };
  27. SColor.rgba = function (r, g, b, a) {
  28. return new SColor(r, g, b, a);
  29. };
  30. Object.defineProperty(SColor.prototype, "red", {
  31. get: function () {
  32. return (this._value >> 24) & 0xff;
  33. },
  34. set: function (v) {
  35. var r = (Math.floor(v) & 0xff) << 24;
  36. this._value = (this._value & 0x00ffffff) | r;
  37. },
  38. enumerable: false,
  39. configurable: true
  40. });
  41. Object.defineProperty(SColor.prototype, "green", {
  42. get: function () {
  43. return (this._value >> 16) & 0xff;
  44. },
  45. set: function (v) {
  46. var r = (Math.floor(v) & 0xff) << 16;
  47. this._value = (this._value & 0xff00ffff) | r;
  48. },
  49. enumerable: false,
  50. configurable: true
  51. });
  52. Object.defineProperty(SColor.prototype, "blue", {
  53. get: function () {
  54. return (this._value >> 8) & 0xff;
  55. },
  56. set: function (v) {
  57. var r = (Math.floor(v) & 0xff) << 8;
  58. this._value = (this._value & 0xffff00ff) | r;
  59. },
  60. enumerable: false,
  61. configurable: true
  62. });
  63. Object.defineProperty(SColor.prototype, "alpha", {
  64. get: function () {
  65. return this._value & 0xff;
  66. },
  67. set: function (v) {
  68. var r = Math.floor(v) & 0xff;
  69. this._value = (this._value & 0xffffff00) | r;
  70. },
  71. enumerable: false,
  72. configurable: true
  73. });
  74. Object.defineProperty(SColor.prototype, "value", {
  75. get: function () {
  76. return "#" + lib_1.SStringUtil.num2Hex(this._value, 8);
  77. },
  78. set: function (v) {
  79. if (v.substr(0, 1) != "#") {
  80. return;
  81. }
  82. this._value = parseInt(v.substr(1), 16);
  83. if (v.length == 7) {
  84. this._value = (this._value << 8) + 0xff;
  85. }
  86. },
  87. enumerable: false,
  88. configurable: true
  89. });
  90. SColor.prototype.setRgb = function (r, g, b) {
  91. this._value =
  92. (r << 24) +
  93. (g << 16) +
  94. (b << 8) +
  95. 0xff;
  96. };
  97. SColor.prototype.setRgba = function (r, g, b, a) {
  98. this._value =
  99. (r << 24) +
  100. (g << 16) +
  101. (b << 8) +
  102. a;
  103. };
  104. SColor.Transparent = new SColor("#00000000");
  105. SColor.Black = new SColor("#000000");
  106. SColor.DarkBlue = new SColor("#000080");
  107. SColor.Blue = new SColor("#0000FF");
  108. SColor.DarkGreen = new SColor("#008000");
  109. SColor.Green = new SColor("#00FF00");
  110. SColor.DarkCyan = new SColor("#008080");
  111. SColor.Cyan = new SColor("#00FFFF");
  112. SColor.DarkRed = new SColor("#800000");
  113. SColor.Red = new SColor("#FF0000");
  114. SColor.DarkMagenta = new SColor("#800080");
  115. SColor.Magenta = new SColor("#FF00FF");
  116. SColor.DarkYellow = new SColor("#808000");
  117. SColor.Yellow = new SColor("#FFFF00");
  118. SColor.White = new SColor("#FFFFFF");
  119. SColor.DarkGray = new SColor("#808080");
  120. SColor.Gray = new SColor("#A0A0A0");
  121. SColor.LightGray = new SColor("#C0C0C0");
  122. return SColor;
  123. }());
  124. exports.SColor = SColor;