Skip to content

Commit 22bb553

Browse files
authored
[refactor] improve theme accent hue cycle
1 parent b47f134 commit 22bb553

File tree

8 files changed

+126
-37
lines changed

8 files changed

+126
-37
lines changed

‎src/css/animation.css‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,88 @@
1+
@keyframes rainbow-variables{
2+
0%,100%{
3+
--theme-accent:var(--theme-accent-r),var(--theme-accent-g),var(--theme-accent-b);
4+
--theme-accent-accessible-threshold:0.5;
5+
--theme-accent-accessible-r:calc(var(--theme-accent-r) *0.50);
6+
--theme-accent-accessible-g:calc(var(--theme-accent-g) *0.60);
7+
--theme-accent-accessible-b:calc(var(--theme-accent-b) *0.20);
8+
--theme-accent-accessible-sum:calc(var(--theme-accent-accessible-r) +var(--theme-accent-accessible-g) +var(--theme-accent-accessible-b));
9+
--theme-accent-accessible-perceived-lightness:calc(var(--theme-accent-accessible-sum) /255);
10+
--theme-accent-accessible-color:0,0%,calc((var(--theme-accent-accessible-perceived-lightness) -var(--theme-accent-accessible-threshold)) *-10000000%);
11+
}
12+
13+
0%{
14+
--theme-accent-r:255;
15+
--theme-accent-g:0;
16+
--theme-accent-b:0;
17+
}
18+
19+
16.666666666666668%{
20+
--theme-accent-r:255;
21+
--theme-accent-g:255;
22+
--theme-accent-b:0;
23+
}
24+
25+
33.333333333333336%{
26+
--theme-accent-r:0;
27+
--theme-accent-g:255;
28+
--theme-accent-b:0;
29+
}
30+
31+
50%{
32+
--theme-accent-r:0;
33+
--theme-accent-g:255;
34+
--theme-accent-b:255;
35+
}
36+
37+
66.66666666666667%{
38+
--theme-accent-r:0;
39+
--theme-accent-g:0;
40+
--theme-accent-b:255;
41+
}
42+
43+
83.33333333333334%{
44+
--theme-accent-r:255;
45+
--theme-accent-g:0;
46+
--theme-accent-b:255;
47+
}
48+
49+
100%{
50+
--theme-accent-r:255;
51+
--theme-accent-g:0;
52+
--theme-accent-b:0;
53+
}
54+
}
55+
56+
@keyframes rainbow{
57+
0%{
58+
background-color:hsl(0,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
59+
}
60+
61+
16.666666666666668%{
62+
background-color:hsl(60,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
63+
}
64+
65+
33.333333333333336%{
66+
background-color:hsl(120,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
67+
}
68+
69+
50%{
70+
background-color:hsl(180,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
71+
}
72+
73+
66.66666666666667%{
74+
background-color:hsl(240,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
75+
}
76+
77+
83.33333333333334%{
78+
background-color:hsl(300,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
79+
}
80+
81+
100%{
82+
background-color:hsl(360,calc(var(--theme-accent-s) *1%),calc(var(--theme-accent-l) *1%));
83+
}
84+
}
85+
186
@keyframes appear{
287
0%{
388
opacity:0;

‎src/css/link.css‎

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -639,17 +639,14 @@
639639
transition: color var(--layout-timing-extra-fast);
640640
}
641641

642-
.is-theme-accent-cycle .link-display-letter{
643-
transition: none;
644-
}
645-
646642
.link-display-icon{
647643
font-weight:400;
648644
font-style: normal;
649645
color:rgb(var(--theme-accent));
650646
transition: color var(--layout-timing-extra-fast);
651647
}
652648

649+
.is-theme-accent-cycle .link-display-letter,
653650
.is-theme-accent-cycle .link-display-icon{
654651
transition: none;
655652
}
@@ -842,31 +839,31 @@
842839
}
843840

844841
.link-control-item{
845-
color:rgb(var(--theme-accent-text));
842+
color:hsl(var(--theme-accent-accessible-color));
846843
}
847844

848845
.link-control-item:focus,
849846
.link-control-item:hover{
850-
color:rgb(var(--theme-accent-text));
851-
background-color:rgba(0,0,0,0.2);
847+
color:hsl(var(--theme-accent-accessible-color));
848+
background-color:hsla(var(--theme-accent-accessible-color),0.2);
852849
}
853850

854851
.link-control-item.disabled:focus,
855852
.link-control-item.disabled:hover,
856853
.link-control-item:disabled:focus,
857854
.link-control-item:disabled:hover{
858-
color:rgba(var(--theme-accent-text),0.25);
855+
color:hsla(var(--theme-accent-accessible-color),0.25);
859856
background-color: transparent;
860857
}
861858

862859
.link-control-item:active{
863-
color:rgb(var(--theme-accent-text));
864-
background-color:rgba(0,0,0,0.1);
860+
color:hsl(var(--theme-accent-accessible-color));
861+
background-color:hsla(var(--theme-accent-accessible-color),0.1);
865862
}
866863

867864
.link-control-item.disabled,
868865
.link-control-item:disabled{
869-
color:rgb(var(--theme-accent-text),0.25);
866+
color:hsla(var(--theme-accent-accessible-color),0.25);
870867
}
871868

872869
.is-link-orientation-top.is-link-style-list .link-control-item:nth-child(1){
@@ -961,10 +958,7 @@
961958
white-space: nowrap;
962959
overflow: hidden;
963960
text-overflow: ellipsis;
964-
}
965-
966-
.link-url-text{
967-
color:rgb(var(--theme-accent-text));
961+
color:hsl(var(--theme-accent-accessible-color));
968962
}
969963

970964
.is-edit.is-link-item-url-show .link-item:focus .link-panel-front,

‎src/css/variables.css‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,17 @@
11
:root{
22
/* theme */
33
--theme-root-font-size:14px;
4-
--theme-accent:250,130,0;
5-
--theme-accent-text:var(--theme-black);
4+
--theme-accent-r:250;
5+
--theme-accent-g:130;
6+
--theme-accent-b:0;
7+
--theme-accent:var(--theme-accent-r),var(--theme-accent-g),var(--theme-accent-b);
8+
--theme-accent-accessible-threshold:0.5;
9+
--theme-accent-accessible-r:calc(var(--theme-accent-r) *0.50);
10+
--theme-accent-accessible-g:calc(var(--theme-accent-g) *0.60);
11+
--theme-accent-accessible-b:calc(var(--theme-accent-b) *0.20);
12+
--theme-accent-accessible-sum:calc(var(--theme-accent-accessible-r) +var(--theme-accent-accessible-g) +var(--theme-accent-accessible-b));
13+
--theme-accent-accessible-perceived-lightness:calc(var(--theme-accent-accessible-sum) /255);
14+
--theme-accent-accessible-color:0,0%,calc((var(--theme-accent-accessible-perceived-lightness) -var(--theme-accent-accessible-threshold)) *-10000000%);
615
--theme-radius:0.2rem;
716
--theme-font-display-name:"Fjalla One", sans-serif;
817
--theme-font-display-weight:400;

‎src/html/menu/content/theme/accent.html‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ <h1 class="menu-item-header-text">Accent</h1>
7070
</div>
7171
</div>
7272
<divclass="form-helper">
73-
<pclass="control-theme-accent-cycle-helper form-helper-item">A small delay and small step in Accent hue change may cause performance issues.</p>
73+
<pclass="control-theme-accent-cycle-helper form-helper-item">Take casre as a small delay in Accent hue change may cause performance issues.</p>
7474
</div>
7575
<divclass="form-helper">
7676
<pclass="control-theme-accent-cycle-helper form-helper-item">Auto change Accent hue will not work when the Accent colour is a grey or black.</p>

‎src/js/control.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5599,8 +5599,8 @@ var control = (function(){
55995599
type: "button",
56005600
func: function(){
56015601
mod.default("theme.accent.cycle.step");
5602-
render.update.control.header();
5603-
render.update.control.menu();
5602+
theme.bind.accent.cycle.remove();
5603+
theme.bind.accent.cycle.add();
56045604
render.update.control.header();
56055605
render.update.control.menu();
56065606
}

‎src/js/link.js‎

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,18 @@ var link = (function(){
722722
if(stagedLink.link.accent.override){
723723
linkItemOptions.attr.push({
724724
key: "style",
725-
value: "--theme-accent: "+stagedLink.link.accent.color.r+", "+stagedLink.link.accent.color.g+", "+stagedLink.link.accent.color.b+""
725+
value: "--theme-accent-r: "+stagedLink.link.accent.color.r+""+
726+
"--theme-accent-g: "+stagedLink.link.accent.color.g+""+
727+
"--theme-accent-b: "+stagedLink.link.accent.color.b+""+
728+
"--theme-accent: var(--theme-accent-r), var(--theme-accent-g), var(--theme-accent-b);"+
729+
"--theme-accent-accessible-threshold: 0.5;"+
730+
"--theme-accent-accessible-r: calc(var(--theme-accent-r) * 0.50);"+
731+
"--theme-accent-accessible-g: calc(var(--theme-accent-g) * 0.60);"+
732+
"--theme-accent-accessible-b: calc(var(--theme-accent-b) * 0.20);"+
733+
"--theme-accent-accessible-sum: calc(var(--theme-accent-accessible-r) + var(--theme-accent-accessible-g) + var(--theme-accent-accessible-b));"+
734+
"--theme-accent-accessible-perceived-lightness: calc(var(--theme-accent-accessible-sum) / 255);"+
735+
"--theme-accent-accessible-color: 0, 0%, calc((var(--theme-accent-accessible-perceived-lightness) - var(--theme-accent-accessible-threshold)) * -10000000%);"
726736
});
727-
if(invert(stagedLink.link.accent.color,true)=="#000000"){
728-
linkItemOptions.attr[1].value=linkItemOptions.attr[1].value+" --theme-accent-text: var(--theme-black);"
729-
}elseif(invert(stagedLink.link.accent.color,true)=="#ffffff"){
730-
linkItemOptions.attr[1].value=linkItemOptions.attr[1].value+" --theme-accent-text: var(--theme-white);"
731-
};
732737
};
733738
varlinkItem=helper.makeNode(linkItemOptions);
734739
varlinkPanelFrontOptions={

‎src/js/state.js‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ var state = (function(){
266266
},
267267
cycle: {
268268
active: false,
269-
speed: 150,
269+
speed: 300,
270270
step: 10
271271
}
272272
},
@@ -436,7 +436,7 @@ var state = (function(){
436436
b: 255
437437
},
438438
cycle: {
439-
speed: 150,
439+
speed: 300,
440440
step: 10
441441
}
442442
},

‎src/js/theme.js‎

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ var theme = (function(){
4747
},
4848
add: function(){
4949
_timerAccentCycle=setInterval(function(){
50-
theme.accent.cycle();
50+
accent.cycle();
5151
control.render.update.control.header(control.mod.header[5]);
5252
control.render.update.control.menu(control.mod.menu.controls.theme.accent[0]);
5353
control.render.update.control.menu(control.mod.menu.controls.theme.accent[1]);
@@ -1452,14 +1452,10 @@ var theme = (function(){
14521452
render.accent={
14531453
color: function(){
14541454
varhtml=helper.e("html");
1455-
varcolor=state.get.current().theme.accent.rgb;
1456-
html.style.setProperty("--theme-accent",color.r+", "+color.g+", "+color.b);
1457-
html.style.removeProperty("--theme-accent-text");
1458-
if(invert(state.get.current().theme.accent.rgb,true)=="#000000"){
1459-
html.style.setProperty("--theme-accent-text","var(--theme-black)");
1460-
}elseif(invert(state.get.current().theme.accent.rgb,true)=="#ffffff"){
1461-
html.style.setProperty("--theme-accent-text","var(--theme-white)");
1462-
};
1455+
varrgb=state.get.current().theme.accent.rgb;
1456+
html.style.setProperty("--theme-accent-r",rgb.r);
1457+
html.style.setProperty("--theme-accent-g",rgb.g);
1458+
html.style.setProperty("--theme-accent-b",rgb.b);
14631459
}
14641460
};
14651461

0 commit comments

Comments
(0)