summaryrefslogtreecommitdiff
path: root/node_modules/socket.io/examples/chat/public/stylesheets/mixins.styl
blob: fb5644cc5faf50798c5f7a0a4ec9b40796147cb1 (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
95
96
border-radius(n)
  -webkit-border-radius n
  -moz-border-radius n
  border-radius n

// replace str with val

replace(expr, str, val)
  expr = clone(expr)
  for e, i in expr
    if str == e
      expr[i] = val
  expr

// normalize gradient point (webkit)

grad-point(pos)
  if length(pos) == 1
    return left pos if pos in (top bottom)
    return pos top if pos in (left right)
  else if pos[0] in (top bottom)
    pos[1] pos[0]
  else
    pos

// implicit color stop position

pos-in-stops(i, stops)
  len = length(stops)
  if len - 1 == i
    100%
  else if i
    unit(i / len * 100, '%')
  else
    0%

// normalize color stops
//   - (color pos) -> (pos color)
//   - (color) -> (implied-pos color)

normalize-stops(stops)
  stops = clone(stops)
  for stop, i in stops
    if length(stop) == 1
      color = stop[0]
      stop[0] = pos-in-stops(i, stops)
      stop[1] = color
    else if typeof(stop[1]) == 'unit'
      pos = stop[1]
      stop[1] = stop[0]
      stop[0] = pos
  stops

// join color stops with the given translation function

join-stops(stops, translate)
  str = ''
  len = length(stops)
  for stop, i in stops
    str += ', ' if i
    pos = stop[0]
    color = stop[1]
    str += translate(color, pos)
  unquote(str)

// webkit translation function

webkit-stop(color, pos)
  s('color-stop(%d, %s)', pos / 100, color)

// mozilla translation function

moz-stop(color, pos)
  s('%s %s', color, pos)

// create a linear gradient with the given start
// position, followed by color stops

linear-gradient(start, stops...)
  error('color stops required') unless length(stops)
  prop = current-property[0]
  val = current-property[1]
  stops = normalize-stops(stops)

  // webkit
  end = grad-point(opposite-position(start))
  webkit = s('-webkit-gradient(linear, %s, %s, %s)', grad-point(start), end, join-stops(stops, webkit-stop))
  add-property(prop, replace(val, '__CALL__', webkit))

  // moz
  stops = join-stops(stops, moz-stop)
  moz = s('-moz-linear-gradient(%s, %s)', start, stops)
  add-property(prop, replace(val, '__CALL__', moz))

  // literal
  s('linear-gradient(%s, %s)', start, stops)