summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/css-fonts/animations/font-palette-interpolation.html
blob: 43e1368412e205c7ee22a326f3cfcb99a4f434e7 (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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
<!DOCTYPE html>
<meta charset="UTF-8">
<title>font-palette interpolation</title>
<link rel="help" href="https://www.w3.org/TR/css-fonts-4/#propdef-font-palette">
<meta name="assert" content="Font-palette should be animated smoothly.">

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/css/support/interpolation-testcommon.js"></script>
<style>
@font-palette-values --custom-palette {
  font-family: "Color font";
  base-palette: 0;
  override-colors: 1 #000000;
}

.container {
  font-palette: light;
}
.container2 {
  font-palette: dark;
}
.target {
  display: inline-block;
  font: 100px sans-serif;
  font-palette: normal;
}
.expected {
  color: green;
  margin-right: 30px;
}
</style>

<body>
<template id="target-template">
  <span class="container">
    <div class="target">TT</div>
  </span>
</template>

<span id="inv-container" class="container">
  <div id="inv-target" class="target">TT</div>
</span>
</body>

<script>

test_interpolation({
  property: 'font-palette',
  from: 'light',
  to: 'dark'
}, [
  {at: -2, expect: 'light'},
  {at: -0.25, expect: 'light'},
  {at: 0, expect: 'light'},
  {at: 0.3, expect: 'palette-mix(in oklab, light, dark 30%)'},
  {at: 0.6, expect: 'palette-mix(in oklab, light, dark 60%)'},
  {at: 1, expect: 'dark'},
  {at: 1.5, expect: 'dark'},
]);

test_interpolation({
  property: 'font-palette',
  from: 'initial',
  to: 'inherit'
}, [
  {at: -2, expect: 'normal'},
  {at: -0.25, expect: 'normal'},
  {at: 0, expect: 'normal'},
  {at: 0.3, expect: 'palette-mix(in oklab, normal, light 30%)'},
  {at: 0.6, expect: 'palette-mix(in oklab, normal, light 60%)'},
  {at: 1, expect: 'light'},
  {at: 1.5, expect: 'light'},
]);

test_interpolation({
  property: 'font-palette',
  from: '--custom-palette',
  to: 'normal'
}, [
  {at: -2, expect: '--custom-palette'},
  {at: -0.25, expect: '--custom-palette'},
  {at: 0, expect: '--custom-palette'},
  {at: 0.3, expect: 'palette-mix(in oklab, --custom-palette, normal 30%)'},
  {at: 0.6, expect: 'palette-mix(in oklab, --custom-palette, normal 60%)'},
  {at: 1, expect: 'normal'},
  {at: 1.5, expect: 'normal'},
]);

/* palette-mix function for the equal endpoints should be simplified. */
test_interpolation({
  property: 'font-palette',
  from: 'initial',
  to: 'normal'
}, [
  {at: -2, expect: 'normal'},
  {at: -0.25, expect: 'normal'},
  {at: 0, expect: 'normal'},
  {at: 0.3, expect: 'normal'},
  {at: 0.6, expect: 'normal'},
  {at: 1, expect: 'normal'},
  {at: 1.5, expect: 'normal'},
]);

test(t => {
  var container = document.getElementById('inv-container');
  var target = document.getElementById('inv-target');
  var anim = target.animate({ fontPalette: ['normal', 'inherit'] }, 1000);
  anim.pause();
  anim.currentTime = 500;
  assert_equals(getComputedStyle(target).fontPalette, 'palette-mix(in oklab, normal, light)');

  container.setAttribute('class', 'container2');
  assert_equals(getComputedStyle(target).fontPalette, 'palette-mix(in oklab, normal, dark)');
}, "An interpolation to inherit updates correctly on a parent style change.");

test(t => {
  var target = document.getElementById('inv-target');
  target.animate(
    { fontPalette: ['light', 'normal'] },
    {
      duration: 1000
    }
  );
  target.animate(
    { fontPalette: ['normal', 'dark'] },
    {
      duration: 1000,
      /* Should work like 'replace', since <Color> type is not additive,
         compare: https://drafts.csswg.org/css-values-4/#combine-colors. */
      composite: "add"
    }
  );
  document.getAnimations().forEach((animation) => {
    animation.pause();
    animation.currentTime = 500;
  });
  assert_equals(getComputedStyle(target).fontPalette,
                "palette-mix(in oklab, normal, dark)");
}, "Test additive animations");

</script>