access-settings 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +120 -0
- package/dist/index.js +373 -0
- package/dist/index.min.js +196 -0
- package/example/index.html +161 -0
- package/example/styles.css +61 -0
- package/package.json +29 -0
- package/src/createState.js +34 -0
- package/src/globalStyles.js +24 -0
- package/src/index.js +104 -0
- package/src/languages.json +18 -0
- package/src/preferences.js +66 -0
- package/src/style.js +107 -0
- package/src/template.js +52 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import { createState } from "./createState.js";
|
|
2
|
+
|
|
3
|
+
const root = document.documentElement;
|
|
4
|
+
|
|
5
|
+
function getInitialFontSize() {
|
|
6
|
+
let fontSize = getComputedStyle(root).fontSize;
|
|
7
|
+
return Number.parseInt(fontSize);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function getInitialLineHeight() {
|
|
11
|
+
let lineHeight = getComputedStyle(root).lineHeight;
|
|
12
|
+
return Number.parseInt(lineHeight) / getInitialFontSize();
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const initialPrefs = {
|
|
16
|
+
dyslexicFont : false,
|
|
17
|
+
invertedColors : false,
|
|
18
|
+
contraste : 100,
|
|
19
|
+
fontSize : getInitialFontSize(),
|
|
20
|
+
lineHeight : getInitialLineHeight()
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const { state : preferences, onStateChange, offStateChange } = createState(initialPrefs);
|
|
24
|
+
|
|
25
|
+
onStateChange((prop, value) => {
|
|
26
|
+
switch (prop) {
|
|
27
|
+
case "dyslexicFont":
|
|
28
|
+
if (value) root.classList.add("dyslexic");
|
|
29
|
+
else root.classList.remove("dyslexic");
|
|
30
|
+
break;
|
|
31
|
+
case "invertedColors":
|
|
32
|
+
if (value) root.classList.add("invertedColors");
|
|
33
|
+
else root.classList.remove("invertedColors");
|
|
34
|
+
break;
|
|
35
|
+
case "fontSize":
|
|
36
|
+
root.style.fontSize = value + "px";
|
|
37
|
+
break;
|
|
38
|
+
case "lineHeight":
|
|
39
|
+
root.style.lineHeight = value;
|
|
40
|
+
break;
|
|
41
|
+
}
|
|
42
|
+
})
|
|
43
|
+
|
|
44
|
+
const defaultPrefs = { ...initialPrefs };
|
|
45
|
+
|
|
46
|
+
export function resetPrefs() {
|
|
47
|
+
for (let key in defaultPrefs) {
|
|
48
|
+
preferences[key] = defaultPrefs[key];
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const STORAGE_NAME = "preferences"
|
|
53
|
+
|
|
54
|
+
onStateChange(() => {
|
|
55
|
+
localStorage.setItem(STORAGE_NAME, JSON.stringify(preferences));
|
|
56
|
+
})
|
|
57
|
+
|
|
58
|
+
const storedData = localStorage.getItem(STORAGE_NAME);
|
|
59
|
+
|
|
60
|
+
if (storedData) {
|
|
61
|
+
const data = JSON.parse(storedData);
|
|
62
|
+
|
|
63
|
+
for (let key in data) {
|
|
64
|
+
preferences[key] = data[key];
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/style.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
export const style = `
|
|
2
|
+
:host {
|
|
3
|
+
font-size:18px;
|
|
4
|
+
line-height:1.5;
|
|
5
|
+
position:fixed;
|
|
6
|
+
top:3px;
|
|
7
|
+
right:5px;
|
|
8
|
+
}
|
|
9
|
+
:host([side="left"]) {
|
|
10
|
+
right:unset;
|
|
11
|
+
left:5px;
|
|
12
|
+
details {
|
|
13
|
+
align-items: flex-start;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
:host([all]), :host([dyslexic-font]) {
|
|
17
|
+
form .field[part=dyslexic-font] {
|
|
18
|
+
display:block;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
:host([all]), :host([invert-colors]) {
|
|
22
|
+
form .field[part=invert-colors] {
|
|
23
|
+
display:block;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
:host([all]), :host([font-size]) {
|
|
27
|
+
form .field[part=font-size] {
|
|
28
|
+
display:block;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
:host([all]), :host([line-height]) {
|
|
32
|
+
form .field[part=line-height] {
|
|
33
|
+
display:block;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
:host([rounded]) ::slotted([slot=icon]), :host([rounded]) #default-icon {
|
|
37
|
+
border-radius:50%;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
details {
|
|
41
|
+
display:flex;
|
|
42
|
+
flex-direction:column;
|
|
43
|
+
align-items:flex-end;
|
|
44
|
+
|
|
45
|
+
summary {
|
|
46
|
+
cursor:pointer;
|
|
47
|
+
display:flex;
|
|
48
|
+
align-items:center;
|
|
49
|
+
|
|
50
|
+
#default-icon {
|
|
51
|
+
border:1px solid #ccc;
|
|
52
|
+
background-color:#ddd;
|
|
53
|
+
border-radius:5px;
|
|
54
|
+
width:40px;
|
|
55
|
+
height:40px;
|
|
56
|
+
&:hover {
|
|
57
|
+
background-color:#e1e1e1;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
::slotted([slot=icon]) {
|
|
61
|
+
border:1px solid #ccc;
|
|
62
|
+
background-color:#ddd;
|
|
63
|
+
border-radius:5px;
|
|
64
|
+
padding:0 8px;
|
|
65
|
+
font-size:30px;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
form {
|
|
70
|
+
font-size:1em;
|
|
71
|
+
border:1px solid #ccc;
|
|
72
|
+
color:#222;
|
|
73
|
+
background-color:#fafafa;
|
|
74
|
+
line-height:2.5;
|
|
75
|
+
text-align: left;
|
|
76
|
+
border-radius:5px;
|
|
77
|
+
|
|
78
|
+
.field, ::slotted([slot=option]) {
|
|
79
|
+
padding: 0 25px 0 15px;
|
|
80
|
+
display:block;
|
|
81
|
+
&:hover {
|
|
82
|
+
background-color:#eee;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.field {
|
|
87
|
+
display:none;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
input {
|
|
91
|
+
font-size:1em;
|
|
92
|
+
font-family:unset;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
input[type=number] {
|
|
96
|
+
width:5ch;
|
|
97
|
+
border:1px solid #ccc;
|
|
98
|
+
border-radius:5px;
|
|
99
|
+
padding:3px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
[part=buttons] {
|
|
103
|
+
text-align:center;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
`
|
package/src/template.js
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { style } from "./style.js"
|
|
2
|
+
|
|
3
|
+
export const template = document.createElement('template');
|
|
4
|
+
|
|
5
|
+
template.innerHTML = `
|
|
6
|
+
<style>${style}</style>
|
|
7
|
+
<details part="details">
|
|
8
|
+
<summary part="summary" aria-label="accessibility settings">
|
|
9
|
+
<slot name="icon">
|
|
10
|
+
<svg viewBox="0 0 389.9 389.6" part="icon" id="default-icon">
|
|
11
|
+
<circle fill="none" cx="250.6" cy="146.4" r="35.7" transform="matrix(.160226 -.98708 .98708 .160226 6.75 311.71)"></circle>
|
|
12
|
+
<path d="M191.4 130.7c-23.693 0-42.9-19.207-42.9-42.9s19.207-42.9 42.9-42.9 42.9 19.207 42.9 42.9a42.89 42.89 0 0 1-42.9
|
|
13
|
+
42.9zm0-71.5c-13.69-.038-25.498 9.605-28.197 23.026a28.68 28.68 0 0 0 17.105 32.135c12.641 5.256 27.234.846 34.848-10.531A28.68
|
|
14
|
+
28.68 0 0 0 211.6 67.6a29.06 29.06 0 0 0-20.2-8.4zm52.5 278.6a21.46 21.46 0 0 1-19.5-12.6l-33.1-80.3-32.7 80.1a21.41 21.41 0 0
|
|
15
|
+
1-37.1 4.1 21.57 21.57 0 0 1-2.1-21.5l34.4-87.5a26.63 26.63 0 0 0 1.9-10.4v-16.4a7.09 7.09 0 0 0-6.5-7.1l-60.6-5.5c-11.791
|
|
16
|
+
-.911-20.611-11.209-19.7-23s11.209-20.611 23-19.7l75.1 6.7a97.18 97.18 0 0 0 7.7.3h33.4a99.08 99.08 0 0 0 7.7-.3l75-6.7h.1c11.791
|
|
17
|
+
-.911 22.089 7.909 23 19.7s-7.909 22.089-19.7 23l-60.5 5.5a7.09 7.09 0 0 0-6.5 7.1v16.4a28.29 28.29 0 0 0 2 10.4l34.5 87.9a21.36
|
|
18
|
+
21.36 0 0 1-1.8 20.2 22.06 22.06 0 0 1-18 9.6zm-52.5-107.1a14.11 14.11 0 0 1 13.1 8.8l33 80.1a7.62 7.62 0 0 0 3.9 3.6 7.13 7.13
|
|
19
|
+
0 0 0 9-9.6l-34.6-88.3a42.14 42.14 0 0 1-3-15.7v-16.4c-.054-11.101 8.438-20.376 19.5-21.3l60.6-5.5a7 7 0 0 0 4.9-2.4 6.61 6.61
|
|
20
|
+
0 0 0 1.7-5.2 7 7 0 0 0-7.6-6.6l-74.9 6.7a88.33 88.33 0 0 1-8.9.4h-33.4a87 87 0 0 1-8.9-.4l-75-6.7a7.12 7.12 0 0 0-1 14.2l60.7
|
|
21
|
+
5.5c11.062.924 19.554 10.199 19.5 21.3v16.4a42.14 42.14 0 0 1-3 15.7l-34.5 87.9a7.09 7.09 0 0 0 .3 7.3 7.19 7.19 0 0 0 6.6 3.2
|
|
22
|
+
7 7 0 0 0 5.9-4.3l32.9-79.9a14 14 0 0 1 13.2-8.8z">
|
|
23
|
+
</path>
|
|
24
|
+
</svg>
|
|
25
|
+
</slot>
|
|
26
|
+
</summary>
|
|
27
|
+
<form part="form">
|
|
28
|
+
<div class="field" part="dyslexic-font">
|
|
29
|
+
<input type="checkbox" id="dyslexic-font">
|
|
30
|
+
<label for="dyslexic-font">Police dyslexie</label>
|
|
31
|
+
</div>
|
|
32
|
+
<div class="field" part="invert-colors">
|
|
33
|
+
<input type="checkbox" id="inverted-colors">
|
|
34
|
+
<label for="inverted-colors">Couleurs inversées</label>
|
|
35
|
+
</div>
|
|
36
|
+
<div class="field" part="font-size">
|
|
37
|
+
<input type="number" id="font-size">
|
|
38
|
+
<label for="font-size">Taille de police</label>
|
|
39
|
+
</div>
|
|
40
|
+
<div class="field" part="line-height">
|
|
41
|
+
<input type="number" id="line-height" step="0.1">
|
|
42
|
+
<label for="line-height">Interligne</label>
|
|
43
|
+
</div>
|
|
44
|
+
<slot name="option"></slot>
|
|
45
|
+
<div part="buttons">
|
|
46
|
+
<input type="button" id="reset" value="Réinitialiser"/>
|
|
47
|
+
<input type="button" id="close" value="Terminer"/>
|
|
48
|
+
</div>
|
|
49
|
+
</form>
|
|
50
|
+
</details>
|
|
51
|
+
`;
|
|
52
|
+
|