SayLeftRight.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. /// <reference path="../Say.ts" />
  2. class SayLeftRight extends Say {
  3. private left : Say = new Say();
  4. private right : Say = new Say();
  5. public constructor () {
  6. super();
  7. }
  8. public addLeft (...objs : Array<Say | OneOf | Object | Printable | string | number | String | ((say : Say) => string)>) {
  9. this.left.add(...objs);
  10. }
  11. public addRight (...objs : Array<Say | OneOf | Object | Printable | string | number | String | ((say : Say) => string)>) {
  12. this.right.add(...objs);
  13. }
  14. public async getPureElements () : Promise<Array<Element | Text>> {
  15. if (this.left.sequence.length == 0) {
  16. return await this.right.getPureElements();
  17. } else if (this.right.sequence.length == 0) {
  18. return await this.left.getPureElements();
  19. }
  20. let mainDiv = document.createElement("div");
  21. mainDiv.classList.add("horFlex");
  22. let left = document.createElement("div");
  23. left.classList.add("horFlexColumn");
  24. mainDiv.appendChild(left);
  25. let right = document.createElement("div");
  26. right.classList.add("horFlexColumn");
  27. mainDiv.appendChild(right);
  28. await this.left.getPureElements().then(value => {
  29. value.forEach(element => {
  30. left.appendChild(element);
  31. })
  32. });
  33. await this.right.getPureElements().then(value => {
  34. value.forEach(element => {
  35. right.appendChild(element);
  36. })
  37. });
  38. return [mainDiv];
  39. }
  40. }