The frontend/UI server, written in JS using the MarkoJS library
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

50 lines
1.1 KiB

6 years ago
  1. module.exports = class {
  2. onCreate(input) {
  3. this.state = {
  4. src: input.src,
  5. orientation: "portrait",
  6. style: {
  7. filter: `opacity(${input.opacity || 0.20})`
  8. }
  9. }
  10. }
  11. onInput(input) {
  12. if (input.src != this.state.src) {
  13. this.updateOrientation()
  14. }
  15. if (input.opacity != this.state.opacity) {
  16. this.state.style.filter = `opacity(${input.opacity || 0.20})`
  17. }
  18. }
  19. onMount() {
  20. this.updateOrientation()
  21. }
  22. updateOrientation() {
  23. const image = this.getEl("image", 0)
  24. if (image.complete && typeof(image.naturalHeight) !== 'undefined' && image.naturalHeight !== 0) {
  25. const width = image.naturalWidth
  26. const height = image.naturalHeight
  27. this.setLandscape(width > (height * 1.50))
  28. } else {
  29. image.onload = () => {
  30. const width = image.naturalWidth
  31. const height = image.naturalHeight
  32. this.setLandscape(width > (height * 1.50))
  33. }
  34. }
  35. }
  36. setLandscape(value) {
  37. const orientation = value ? "landscape" : "portrait"
  38. if (orientation !== this.state.orientation) {
  39. this.state.orientation = orientation
  40. }
  41. }
  42. }