size.js 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. class size {
  2. _value;
  3. constructor(value) {
  4. this.value = value;
  5. }
  6. set value(content) {
  7. if (typeof(content) !== "number") {
  8. throw "Size must be numeric.";
  9. }
  10. this._value = content;
  11. }
  12. get value() {
  13. return this._value;
  14. }
  15. get _unit() {
  16. throw "This getter is abstract.";
  17. }
  18. get as_css() {
  19. return this._value.toString() + this._unit;
  20. }
  21. }
  22. class percent extends size {
  23. get _unit() {
  24. return "%";
  25. }
  26. }
  27. class pixel extends size {
  28. get _unit() {
  29. return "px";
  30. }
  31. }
  32. class emunit extends size {
  33. get _unit() {
  34. return "em";
  35. }
  36. }
  37. class width_percent extends size {
  38. get _unit() {
  39. return "wv";
  40. }
  41. }
  42. class height_percent extends size {
  43. get _unit() {
  44. return "hv";
  45. }
  46. }
  47. class auto extends size {
  48. get _unit() {
  49. return "";
  50. }
  51. constructor() {
  52. super(0);
  53. }
  54. set _value(content) {
  55. throw "Auto have no value.";
  56. }
  57. get _value() {
  58. throw "Auto have no value.";
  59. }
  60. get as_css() {
  61. return "auto";
  62. }
  63. }
  64. export { size, percent, pixel, emunit, width_percent, height_percent, auto };