@@ -3,42 +3,33 @@ import Logger from '../Logger';
33import { defaultPrefs } from '../Preferences' ;
44
55const {
6- saccadesInterval, fixationStrength, saccadesColor, saccadesStyle, fixationStemOpacity ,
6+ saccadesInterval, fixationStrength, saccadesColor, saccadesStyle, fixationEdgeOpacity ,
77} = {
88 ...defaultPrefs ,
99} ;
1010function writeInitialConfigsToDom ( ) {
11- document . body . setAttribute (
12- 'saccades-interval' ,
13- document . body . getAttribute ( 'saccades-interval' ) ?? saccadesInterval ,
14- ) ;
15- document . body . setAttribute (
16- 'fixation-strength' ,
17- document . body . getAttribute ( 'fixation-strength' ) ?? fixationStrength ,
18- ) ;
19- document . body . setAttribute (
20- 'saccades-color' ,
21- document . body . getAttribute ( 'saccades-color' ) ?? saccadesColor ,
22- ) ;
11+ setAttribute ( 'saccades-interval' , getAttribute ( 'saccades-interval' ) ?? saccadesInterval ) ;
12+ setAttribute ( 'fixation-strength' , getAttribute ( 'fixation-strength' ) ?? fixationStrength ) ;
13+ setAttribute ( 'saccades-color' , getAttribute ( 'saccades-color' ) ?? saccadesColor ) ;
2314
2415 // console.log(saccadesStyle);
2516 if ( / b o l d / i. test ( saccadesStyle ) ) {
2617 const [ , value ] = saccadesStyle . split ( '-' ) ;
27- const oldValue = document . body . style . getPropertyValue ( '--br-boldness' ) ;
18+ const oldValue = getProperty ( '--br-boldness' ) ;
2819 const nextValue = ! Number . isNaN ( oldValue ) && oldValue !== '' ? oldValue : value ;
29- document . body . style . setProperty ( '--br-boldness' , nextValue ) ;
20+ setProperty ( '--br-boldness' , nextValue ) ;
3021 }
3122
3223 if ( / l i n e / i. test ( saccadesStyle ) ) {
3324 const [ value ] = saccadesStyle . split ( '-' ) ;
34- const oldValue = document . body . style . getPropertyValue ( '--br-line-style' ) ;
25+ const oldValue = getProperty ( '--br-line-style' ) ;
3526 const nextValue = ! Number . isNaN ( oldValue ) && oldValue !== '' ? oldValue : value ;
36- document . body . style . setProperty ( '--br-line-style' , nextValue ) ;
27+ setProperty ( '--br-line-style' , nextValue ) ;
3728 }
3829
39- document . body . setAttribute (
40- 'fixation-stem -opacity' ,
41- document . body . getAttribute ( ' fixation-stem -opacity') ?? fixationStemOpacity ,
30+ setProperty (
31+ '-- fixation-edge -opacity' ,
32+ getProperty ( '-- fixation-edge -opacity') ?? ` ${ fixationEdgeOpacity } %` ,
4233 ) ;
4334}
4435
@@ -53,7 +44,8 @@ const stateTransitions = {
5344 [ '' , 1 ] ,
5445 [ 1 , 2 ] ,
5546 [ 2 , 3 ] ,
56- [ 3 , 1 ] ,
47+ [ 3 , 4 ] ,
48+ [ 4 , 1 ] ,
5749 ] ,
5850 'saccades-interval' : [
5951 [ null , 1 ] ,
@@ -72,12 +64,14 @@ const stateTransitions = {
7264 [ 'dark' , 'dark-100' ] ,
7365 [ 'dark-100' , '' ] ,
7466 ] ,
75- 'fixation-stem-opacity' : [
76- [ null , '100' ] ,
77- [ 0 , 100 ] ,
78- [ 100 , 80 ] ,
79- [ 80 , 40 ] ,
80- [ 40 , 0 ] ,
67+ '--fixation-edge-opacity' : [
68+ [ null , '25%' ] ,
69+ [ '' , '25%' ] ,
70+ [ '25%' , '50%' ] ,
71+ [ '50%' , '75%' ] ,
72+ [ '75%' , '100%' ] ,
73+ [ '80%' , '25%' ] ,
74+ [ '100%' , '25%' ] ,
8175 ] ,
8276} ;
8377
@@ -87,36 +81,50 @@ const stateTransitions = {
8781 * @returns {[targetState,nextState] }
8882 */
8983function getStateTransitionEntry ( stateTransitionKey , currentActiveState ) {
90- return stateTransitions [ stateTransitionKey ] . find ( ( [ state ] ) => `${ state } ` === `${ currentActiveState } ` ) ;
84+ return stateTransitions [ stateTransitionKey ] . find (
85+ ( [ state ] ) => `${ state } ` === `${ currentActiveState } ` ,
86+ ) ;
9187}
9288
93- function toggleStateEngine ( stateTransitionKey , /** @type {(property, value) } */ callback ) {
94- const currentActiveState = document . body . getAttribute ( stateTransitionKey ) ;
95- Logger . logInfo ( 'stateTransitionKey' , stateTransitionKey , 'currentActiveState' , currentActiveState , 'nextState' , stateTransitions [ stateTransitionKey ] ) ;
96-
97- let updateCallback ;
98-
99- if ( ! updateCallback ) {
100- updateCallback = ( attribute , value ) => document . body . setAttribute ( attribute , value ) ;
101- } else {
102- updateCallback = callback ;
103- }
89+ function toggleStateEngine (
90+ stateTransitionKey ,
91+ /** @type {(property, value) } */ callbackSetter = setAttribute ,
92+ /** @type {(identified) => string } */ callbackGetter = getAttribute ,
93+ ) {
94+ const currentActiveState = callbackGetter ( stateTransitionKey ) ;
10495
10596 const [ , nextState ] = getStateTransitionEntry ( stateTransitionKey , currentActiveState ) ;
10697
107- updateCallback ( stateTransitionKey , nextState ) ;
98+ Logger . logInfo (
99+ 'stateTransitionKey' ,
100+ stateTransitionKey ,
101+ 'currentActiveState' ,
102+ currentActiveState ,
103+ 'nextState' ,
104+ nextState ,
105+ stateTransitions [ stateTransitionKey ] ,
106+ ) ;
107+ callbackSetter ( stateTransitionKey , nextState ) ;
108108
109109 if ( document . body . getAttribute ( 'br-mode' ) !== 'on' ) {
110110 toggleReadingMode ( ) ;
111111 }
112112}
113113
114+ const setProperty = ( property , value ) => {
115+ Logger . logInfo ( { setProperty, property, value } ) ;
116+ document . body . style . setProperty ( property , value ) ;
117+ } ;
118+ const setAttribute = ( attribute , value ) => document . body . setAttribute ( attribute , value ) ;
119+ const getProperty = ( property ) => document . body . style . getPropertyValue ( property ) ;
120+ const getAttribute = ( attribute ) => document . body . getAttribute ( attribute ) ;
121+
114122const callableActions = {
115123 fireReadingToggle : toggleReadingMode ,
116124 fireFixationStrengthTransition : ( ) => toggleStateEngine ( 'fixation-strength' ) ,
117125 fireSaccadesIntervalTransition : ( ) => toggleStateEngine ( 'saccades-interval' ) ,
118126 fireSaccadesColorTransition : ( ) => toggleStateEngine ( 'saccades-color' ) ,
119- fireFixationStemOpacityTransition : ( ) => toggleStateEngine ( 'fixation-stem -opacity' ) ,
127+ firefixationEdgeOpacityTransition : ( ) => toggleStateEngine ( '-- fixation-edge -opacity' , setProperty , getProperty ) ,
120128} ;
121129
122130const actionToFire = 'ACTION_TO_FIRE' ;
0 commit comments