summaryrefslogtreecommitdiff
path: root/frontend/app/views/tile/handles/tile.text.js
blob: c7479573217b41ba3409b9b26a8a154e1c370829 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import React from 'react'
import { generateTransform, unitsDimension, hexToRgb, pickCursor } from 'app/views/tile/tile.utils'
import Marquee from "react-fast-marquee"

import { isMobile } from 'app/utils'

const VERTICAL_MARQUEE_DIRECTION = {
  up: "left",
  down: "right",
}

export default function TileText({ tile, box, bounds, videoBounds, cursors, viewing, onMouseDown, onDoubleClick, onMouseEnter, onMouseLeave }) {
  if (!tile.settings.content) {
    return null
  }

  // console.log(tile)
  const style = {
    transform: generateTransform(tile, box, bounds, videoBounds),
    opacity: tile.settings.opacity,
  }
  // console.log(generateTransform(tile))
  let className = ['tile', tile.type].join(' ')

  let [cursorClass, cursorStyle] = pickCursor(tile, cursors, viewing)
  if (cursorClass) {
    className += " " + cursorClass
  }
  if (cursorStyle) {
    style.cursor = cursorStyle
  }

  let { font_size } = tile.settings
  if (isMobile) {
    font_size *= 0.75
  }

  let content = <span dangerouslySetInnerHTML={{ __html: tile.settings.content }} />
  className += ' ' + tile.settings.align
  style.width = unitsDimension(tile, 'width', bounds, videoBounds)
  style.height = unitsDimension(tile, 'height', bounds, videoBounds)
  style.fontFamily = tile.settings.font_family
  style.fontSize = font_size + 'px'
  style.lineHeight = 1.5
  style.fontWeight = (tile.settings.font_style || "").indexOf('bold') !== -1 ? 'bold' : 'normal'
  style.fontStyle = (tile.settings.font_style || "").indexOf('italic') !== -1 ? 'italic' : 'normal'
  style.backgroundColor = tile.settings.background_color || 'transparent'
  style.color = tile.settings.font_color || '#dddddd!important'

  if (tile.settings.is_marquee) {
    const verticalDirection = VERTICAL_MARQUEE_DIRECTION[tile.settings.marquee_direction]
    const direction = verticalDirection || tile.settings.marquee_direction || "left"
    const gradientColor = hexToRgb(tile.settings.marquee_gradient_color)
    let contentStyle = {}
    if (verticalDirection) {
      // style.top = 0
      style.width = "100vh"
      style.height = tile.settings.marquee_content_width + "px"
      style.transform += " rotate(90deg)"
      contentStyle.transform = "rotate(-90deg)"
      contentStyle.width = tile.settings.marquee_content_width + "px"
      // contentStyle.height = "100vh"
    } else {
      style.width = "100vw"
      style.height = style.fontSize + "px"
      contentStyle.width = (tile.settings.marquee_content_width || 200) + "px"
      contentStyle.height = (tile.settings.marquee_content_height || (parseInt(tile.settings.font_size) + 20)) + "px"
    }
    content = (
      <Marquee
        direction={direction}
        speed={tile.settings.marquee_speed || 1}
        gradient={!!tile.settings.marquee_gradient}
        gradientColor={gradientColor ? [gradientColor.r, gradientColor.g, gradientColor.b] : [0,0,0]}
      >
        <div style={contentStyle}>
          {content}
        </div>
      </Marquee>
    )
  }
  return (
    <div
      className={className}
      onMouseDown={onMouseDown}
      onDoubleClick={onDoubleClick}
      onMouseEnter={onMouseEnter}
      onMouseLeave={onMouseLeave}
      style={style}
    >
      {content}
    </div>
  )
}