typography-controller 1.0.2 → 1.1.0
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 +20 -20
- package/README.md +137 -135
- package/dist/react/react-wrapper.js +314 -0
- package/dist/web/typography-controller.js +301 -0
- package/dist/web/typography-controller.umd.cjs +244 -0
- package/package.json +59 -52
- package/src/TypographyState.js +22 -0
- package/src/typography-controller.js +393 -293
- package/dist/index.html +0 -196
- package/dist/typography-controller.js +0 -206
- package/dist/typography-controller.umd.cjs +0 -155
package/LICENSE
CHANGED
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2026 Achuth Kamath
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in
|
|
13
|
-
all copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
-
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Achuth Kamath
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
|
13
|
+
all copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
20
|
+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
21
21
|
DEALINGS IN THE SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,135 +1,137 @@
|
|
|
1
|
-
# Typography Controller
|
|
2
|
-
|
|
3
|
-
A framework
|
|
4
|
-
font size, letter spacing, word spacing, line height, contrast, and font family.
|
|
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
|
-
|
|
1
|
+
# Typography Controller
|
|
2
|
+
|
|
3
|
+
A lightweight, framework‑agnostic Web Component that provides a beautiful, interactive typography control panel.
|
|
4
|
+
Adjust font size, letter spacing, word spacing, line height, contrast, and font family — all in real time.
|
|
5
|
+
|
|
6
|
+

|
|
7
|
+
|
|
8
|
+
## 🚀 Features
|
|
9
|
+
|
|
10
|
+
- Font Size: Adjust the font size with a slider (range: 12-48px).
|
|
11
|
+
- Letter Spacing: Control the spacing between characters.
|
|
12
|
+
- Word Spacing: Adjust spacing between words.
|
|
13
|
+
- Line Height: Set the line height (1-3).
|
|
14
|
+
- Contrast: Apply a contrast filter (50-200%).
|
|
15
|
+
- Font Family: Choose from predefined fonts (Arial, Georgia, Courier New, Verdana).
|
|
16
|
+
- Framework‑agnostic — Works in HTML, React, Vue, Svelte, etc.
|
|
17
|
+
- Public API — getValues(), setValues(), setFeatures(), and change events.
|
|
18
|
+
- EAA - This component is designed with full EAA‑aligned accessibility practices, including keyboard navigation, ARIA labeling, and perceivable focus states.
|
|
19
|
+
|
|
20
|
+
## 📦 Installation
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
npm install typography-controller
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
## Usage
|
|
27
|
+
|
|
28
|
+
1. Import the component
|
|
29
|
+
|
|
30
|
+
```html
|
|
31
|
+
import "typography-controller/dist/typography-controller.js";
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
2. Add the `<typography-controller>` element to your HTML, specifying the target element via the `target` attribute:
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<h2 id="myText">This is the text to style.</h2>
|
|
38
|
+
<typography-controller target="#myText"></typography-controller>
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## 🌐 Using via CDN (no bundler)
|
|
42
|
+
|
|
43
|
+
```
|
|
44
|
+
<script type="module" src="https://unpkg.com/typography-controller/dist/typography-controller.js"></script>
|
|
45
|
+
|
|
46
|
+
<h2 id="demo">Hello World</h2>
|
|
47
|
+
<typography-controller target="#demo"></typography-controller>
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## 📚 JavaScript API
|
|
51
|
+
|
|
52
|
+
### Methods
|
|
53
|
+
| Method | Description | Parameters/Return |
|
|
54
|
+
|--------|-------------|-------------------|
|
|
55
|
+
| getValues() | Returns the current typography values as an object. | Returns: `{ fontSize: number, letterSpacing: number, wordSpacing: number, lineHeight: number, contrast: number, fontFamily: string }` |
|
|
56
|
+
| setValues(values) | Sets the typography values programmatically. | Parameters: `values` (object with keys like `fontSize`, `letterSpacing`, etc.) |
|
|
57
|
+
| setFeatures(features) | Enables or disables specific features (e.g., sliders). | Parameters: `features` (object with boolean keys like `letterSpacing: true`) |
|
|
58
|
+
|
|
59
|
+
### Events
|
|
60
|
+
| Event | Description | Detail |
|
|
61
|
+
|-------|-------------|--------|
|
|
62
|
+
| change | Fired whenever a value changes via the UI or API. | `event.detail`: Object containing updated values (same as `getValues()` return). |
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
Example
|
|
66
|
+
|
|
67
|
+
```
|
|
68
|
+
const controller = document.querySelector("typography-controller");
|
|
69
|
+
|
|
70
|
+
controller.addEventListener("change", (e) => {
|
|
71
|
+
console.log("Updated values:", e.detail);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
controller.setValues({
|
|
75
|
+
fontSize: 30,
|
|
76
|
+
letterSpacing: 2,
|
|
77
|
+
fontFamily: "Georgia"
|
|
78
|
+
});
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
## ⚛️ React Usage
|
|
82
|
+
|
|
83
|
+
Basic usage
|
|
84
|
+
```
|
|
85
|
+
import "typography-controller/dist/typography-controller.js";
|
|
86
|
+
|
|
87
|
+
export default function App() {
|
|
88
|
+
return (
|
|
89
|
+
<div>
|
|
90
|
+
<h2 id="demoText">Typography should feel like breathing space.</h2>
|
|
91
|
+
|
|
92
|
+
<typography-controller
|
|
93
|
+
target="#demoText"
|
|
94
|
+
hide-letter-spacing
|
|
95
|
+
onChange={(e) => console.log(e.detail)}
|
|
96
|
+
></typography-controller>
|
|
97
|
+
</div>
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Using JS API (setFeatures, setValues) with refs
|
|
103
|
+
```
|
|
104
|
+
import { useRef, useEffect } from "react";
|
|
105
|
+
import "typography-controller/dist/typography-controller.js";
|
|
106
|
+
|
|
107
|
+
export default function App() {
|
|
108
|
+
const ref = useRef();
|
|
109
|
+
|
|
110
|
+
useEffect(() => {
|
|
111
|
+
if (ref.current) {
|
|
112
|
+
ref.current.setFeatures({
|
|
113
|
+
letterSpacing: true,
|
|
114
|
+
wordSpacing: false,
|
|
115
|
+
lineHeight: true,
|
|
116
|
+
contrast: true
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
}, []);
|
|
120
|
+
|
|
121
|
+
return (
|
|
122
|
+
<>
|
|
123
|
+
<h2 id="demoText">Hello world</h2>
|
|
124
|
+
|
|
125
|
+
<typography-controller
|
|
126
|
+
ref={ref}
|
|
127
|
+
target="#demoText"
|
|
128
|
+
onChange={(e) => console.log(e.detail)}
|
|
129
|
+
></typography-controller>
|
|
130
|
+
</>
|
|
131
|
+
);
|
|
132
|
+
}
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
## License
|
|
136
|
+
|
|
137
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import { createComponent as a } from "@lit/react";
|
|
2
|
+
import o from "react";
|
|
3
|
+
let r = class extends HTMLElement {
|
|
4
|
+
constructor() {
|
|
5
|
+
super(), this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = `
|
|
6
|
+
<style>
|
|
7
|
+
:host {
|
|
8
|
+
display: block;
|
|
9
|
+
font-family: system-ui, sans-serif;
|
|
10
|
+
max-width: 420px;
|
|
11
|
+
padding: 18px 20px;
|
|
12
|
+
border-radius: 18px;
|
|
13
|
+
background: rgba(255, 255, 255, 0.65);
|
|
14
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
15
|
+
backdrop-filter: blur(14px);
|
|
16
|
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
|
|
17
|
+
color: #0f172a;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.header {
|
|
21
|
+
display: flex;
|
|
22
|
+
justify-content: space-between;
|
|
23
|
+
align-items: baseline;
|
|
24
|
+
margin-bottom: 14px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.title {
|
|
28
|
+
font-size: 14px;
|
|
29
|
+
font-weight: 600;
|
|
30
|
+
letter-spacing: 0.08em;
|
|
31
|
+
text-transform: uppercase;
|
|
32
|
+
color: #475569;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.badge {
|
|
36
|
+
font-size: 11px;
|
|
37
|
+
padding: 3px 8px;
|
|
38
|
+
border-radius: 999px;
|
|
39
|
+
background: rgba(59, 130, 246, 0.12);
|
|
40
|
+
color: #1d4ed8;
|
|
41
|
+
border: 1px solid rgba(59, 130, 246, 0.35);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.group {
|
|
45
|
+
margin-bottom: 14px;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
.label-row {
|
|
49
|
+
display: flex;
|
|
50
|
+
justify-content: space-between;
|
|
51
|
+
align-items: center;
|
|
52
|
+
margin-bottom: 6px;
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
label {
|
|
56
|
+
font-size: 12px;
|
|
57
|
+
font-weight: 600;
|
|
58
|
+
color: #0f172a;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.value {
|
|
62
|
+
font-size: 11px;
|
|
63
|
+
color: #64748b;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
input[type="range"] {
|
|
67
|
+
-webkit-appearance: none;
|
|
68
|
+
width: 100%;
|
|
69
|
+
height: 6px;
|
|
70
|
+
border-radius: 999px;
|
|
71
|
+
background: linear-gradient(90deg, #3b82f6, #60a5fa);
|
|
72
|
+
outline: none;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
input[type="range"]::-webkit-slider-thumb {
|
|
76
|
+
-webkit-appearance: none;
|
|
77
|
+
height: 18px;
|
|
78
|
+
width: 18px;
|
|
79
|
+
border-radius: 50%;
|
|
80
|
+
background: white;
|
|
81
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
82
|
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
|
83
|
+
cursor: pointer;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
select {
|
|
87
|
+
width: 100%;
|
|
88
|
+
padding: 6px 8px;
|
|
89
|
+
border-radius: 8px;
|
|
90
|
+
border: 1px solid rgba(148, 163, 184, 0.7);
|
|
91
|
+
background: rgba(255, 255, 255, 0.9);
|
|
92
|
+
font-size: 12px;
|
|
93
|
+
color: #0f172a;
|
|
94
|
+
outline: none;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
select:focus {
|
|
98
|
+
outline: none;
|
|
99
|
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
|
|
100
|
+
border-radius: 999px;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/* Highlight the track when focused */
|
|
104
|
+
input[type="range"]:focus {
|
|
105
|
+
outline: none;
|
|
106
|
+
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.35);
|
|
107
|
+
border-radius: 999px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/* Glow effect on the thumb when focused */
|
|
111
|
+
input[type="range"]:focus::-webkit-slider-thumb {
|
|
112
|
+
box-shadow:
|
|
113
|
+
0 0 0 4px rgba(37, 99, 235, 0.35),
|
|
114
|
+
0 4px 10px rgba(0, 0, 0, 0.25);
|
|
115
|
+
border-color: #2563eb;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
/* Firefox thumb focus */
|
|
119
|
+
input[type="range"]::-moz-range-thumb:focus {
|
|
120
|
+
box-shadow:
|
|
121
|
+
0 0 0 4px rgba(37, 99, 235, 0.35),
|
|
122
|
+
0 4px 10px rgba(0, 0, 0, 0.25);
|
|
123
|
+
border-color: #2563eb;
|
|
124
|
+
}
|
|
125
|
+
input[type="range"]:hover::-webkit-slider-thumb {
|
|
126
|
+
transform: scale(1.05);
|
|
127
|
+
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.25);
|
|
128
|
+
}
|
|
129
|
+
</style>
|
|
130
|
+
|
|
131
|
+
<div class="header">
|
|
132
|
+
<h2 class="title" id="controllerTitle">Typography Controls</h2>
|
|
133
|
+
<span class="badge">v1.0.0</span>
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<!-- Live region for announcements -->
|
|
137
|
+
<div aria-live="polite" class="sr-only" id="liveRegion"></div>
|
|
138
|
+
|
|
139
|
+
<div class="group" id="groupFontSize" role="group" aria-labelledby="labelFontSize">
|
|
140
|
+
<div class="label-row">
|
|
141
|
+
<label id="labelFontSize" for="fontSize">Font size</label>
|
|
142
|
+
<span class="value" id="fontSizeValue" aria-hidden="true"></span>
|
|
143
|
+
</div>
|
|
144
|
+
|
|
145
|
+
<input
|
|
146
|
+
type="range"
|
|
147
|
+
id="fontSize"
|
|
148
|
+
min="12"
|
|
149
|
+
max="60"
|
|
150
|
+
value="24"
|
|
151
|
+
aria-valuemin="12"
|
|
152
|
+
aria-valuemax="60"
|
|
153
|
+
aria-valuenow="24"
|
|
154
|
+
aria-labelledby="labelFontSize"
|
|
155
|
+
>
|
|
156
|
+
</div>
|
|
157
|
+
|
|
158
|
+
<div class="group" id="groupLetterSpacing" role="group" aria-labelledby="labelLetterSpacing">
|
|
159
|
+
<div class="label-row">
|
|
160
|
+
<label id="labelLetterSpacing" for="letterSpacing">Letter spacing</label>
|
|
161
|
+
<span class="value" id="letterSpacingValue" aria-hidden="true"></span>
|
|
162
|
+
</div>
|
|
163
|
+
|
|
164
|
+
<input
|
|
165
|
+
type="range"
|
|
166
|
+
id="letterSpacing"
|
|
167
|
+
min="0"
|
|
168
|
+
max="20"
|
|
169
|
+
value="0"
|
|
170
|
+
aria-valuemin="0"
|
|
171
|
+
aria-valuemax="20"
|
|
172
|
+
aria-valuenow="0"
|
|
173
|
+
aria-labelledby="labelLetterSpacing"
|
|
174
|
+
>
|
|
175
|
+
</div>
|
|
176
|
+
|
|
177
|
+
<div class="group" id="groupWordSpacing" role="group" aria-labelledby="labelWordSpacing">
|
|
178
|
+
<div class="label-row">
|
|
179
|
+
<label id="labelWordSpacing" for="wordSpacing">Word spacing</label>
|
|
180
|
+
<span class="value" id="wordSpacingValue" aria-hidden="true"></span>
|
|
181
|
+
</div>
|
|
182
|
+
|
|
183
|
+
<input
|
|
184
|
+
type="range"
|
|
185
|
+
id="wordSpacing"
|
|
186
|
+
min="0"
|
|
187
|
+
max="40"
|
|
188
|
+
value="0"
|
|
189
|
+
aria-valuemin="0"
|
|
190
|
+
aria-valuemax="40"
|
|
191
|
+
aria-valuenow="0"
|
|
192
|
+
aria-labelledby="labelWordSpacing"
|
|
193
|
+
>
|
|
194
|
+
</div>
|
|
195
|
+
|
|
196
|
+
<div class="group" id="groupLineHeight" role="group" aria-labelledby="labelLineHeight">
|
|
197
|
+
<div class="label-row">
|
|
198
|
+
<label id="labelLineHeight" for="lineHeight">Line height</label>
|
|
199
|
+
<span class="value" id="lineHeightValue" aria-hidden="true"></span>
|
|
200
|
+
</div>
|
|
201
|
+
|
|
202
|
+
<input
|
|
203
|
+
type="range"
|
|
204
|
+
id="lineHeight"
|
|
205
|
+
min="1"
|
|
206
|
+
max="3"
|
|
207
|
+
step="0.1"
|
|
208
|
+
value="1.5"
|
|
209
|
+
aria-valuemin="1"
|
|
210
|
+
aria-valuemax="3"
|
|
211
|
+
aria-valuenow="1.5"
|
|
212
|
+
aria-labelledby="labelLineHeight"
|
|
213
|
+
>
|
|
214
|
+
</div>
|
|
215
|
+
|
|
216
|
+
<div class="group" id="groupContrast" role="group" aria-labelledby="labelContrast">
|
|
217
|
+
<div class="label-row">
|
|
218
|
+
<label id="labelContrast" for="contrast">Contrast</label>
|
|
219
|
+
<span class="value" id="contrastValue" aria-hidden="true"></span>
|
|
220
|
+
</div>
|
|
221
|
+
|
|
222
|
+
<input
|
|
223
|
+
type="range"
|
|
224
|
+
id="contrast"
|
|
225
|
+
min="50"
|
|
226
|
+
max="200"
|
|
227
|
+
value="100"
|
|
228
|
+
aria-valuemin="50"
|
|
229
|
+
aria-valuemax="200"
|
|
230
|
+
aria-valuenow="100"
|
|
231
|
+
aria-labelledby="labelContrast"
|
|
232
|
+
>
|
|
233
|
+
</div>
|
|
234
|
+
|
|
235
|
+
<div class="group" id="groupFontFamily" role="group" aria-labelledby="labelFontFamily">
|
|
236
|
+
<div class="label-row">
|
|
237
|
+
<label id="labelFontFamily" for="fontFamily">Font family</label>
|
|
238
|
+
</div>
|
|
239
|
+
|
|
240
|
+
<select id="fontFamily" aria-labelledby="labelFontFamily">
|
|
241
|
+
<option value="system-ui, sans-serif">System</option>
|
|
242
|
+
<option value="Georgia, serif">Serif</option>
|
|
243
|
+
<option value="'Courier New', monospace">Monospace</option>
|
|
244
|
+
<option value="Verdana, sans-serif">Verdana</option>
|
|
245
|
+
<option value="inherit">Inherit</option>
|
|
246
|
+
</select>
|
|
247
|
+
</div>
|
|
248
|
+
`;
|
|
249
|
+
}
|
|
250
|
+
connectedCallback() {
|
|
251
|
+
this.targetSelector = this.getAttribute("target"), this.toggleGroup("#groupLetterSpacing", !this.hasAttribute("hide-letter-spacing")), this.toggleGroup("#groupWordSpacing", !this.hasAttribute("hide-word-spacing")), this.toggleGroup("#groupLineHeight", !this.hasAttribute("hide-line-height")), this.toggleGroup("#groupContrast", !this.hasAttribute("hide-contrast")), this.fontSize = this.shadowRoot.querySelector("#fontSize"), this.letterSpacing = this.shadowRoot.querySelector("#letterSpacing"), this.wordSpacing = this.shadowRoot.querySelector("#wordSpacing"), this.lineHeight = this.shadowRoot.querySelector("#lineHeight"), this.contrast = this.shadowRoot.querySelector("#contrast"), this.fontFamily = this.shadowRoot.querySelector("#fontFamily");
|
|
252
|
+
const e = this.targetElement;
|
|
253
|
+
if (e) {
|
|
254
|
+
const i = getComputedStyle(e).fontFamily;
|
|
255
|
+
this.fontFamily.value = i;
|
|
256
|
+
}
|
|
257
|
+
this.fontSizeValue = this.shadowRoot.querySelector("#fontSizeValue"), this.letterSpacingValue = this.shadowRoot.querySelector("#letterSpacingValue"), this.wordSpacingValue = this.shadowRoot.querySelector("#wordSpacingValue"), this.lineHeightValue = this.shadowRoot.querySelector("#lineHeightValue"), this.contrastValue = this.shadowRoot.querySelector("#contrastValue");
|
|
258
|
+
const t = () => {
|
|
259
|
+
this.update(), this.dispatchEvent(
|
|
260
|
+
new CustomEvent("change", {
|
|
261
|
+
detail: this.getValues(),
|
|
262
|
+
bubbles: !0,
|
|
263
|
+
composed: !0
|
|
264
|
+
})
|
|
265
|
+
);
|
|
266
|
+
};
|
|
267
|
+
this.fontSize.addEventListener("input", t), this.letterSpacing.addEventListener("input", t), this.wordSpacing.addEventListener("input", t), this.lineHeight.addEventListener("input", t), this.contrast.addEventListener("input", t), this.fontFamily.addEventListener("change", t), this.update();
|
|
268
|
+
}
|
|
269
|
+
toggleGroup(e, t) {
|
|
270
|
+
const i = this.shadowRoot.querySelector(e);
|
|
271
|
+
i && (i.style.display = t ? "block" : "none");
|
|
272
|
+
}
|
|
273
|
+
get targetElement() {
|
|
274
|
+
return document.querySelector(this.targetSelector);
|
|
275
|
+
}
|
|
276
|
+
update() {
|
|
277
|
+
const e = this.targetElement;
|
|
278
|
+
e && (e.style.fontSize = `${this.fontSize.value}px`, e.style.letterSpacing = `${this.letterSpacing.value}px`, e.style.wordSpacing = `${this.wordSpacing.value}px`, e.style.lineHeight = this.lineHeight.value, e.style.filter = `contrast(${this.contrast.value}%)`, e.style.fontFamily = this.fontFamily.value, this.fontSizeValue.textContent = `${this.fontSize.value}px`, this.letterSpacingValue.textContent = `${this.letterSpacing.value}px`, this.wordSpacingValue.textContent = `${this.wordSpacing.value}px`, this.lineHeightValue.textContent = this.lineHeight.value, this.contrastValue.textContent = `${this.contrast.value}%`);
|
|
279
|
+
}
|
|
280
|
+
getValues() {
|
|
281
|
+
return {
|
|
282
|
+
fontSize: Number(this.fontSize.value),
|
|
283
|
+
letterSpacing: Number(this.letterSpacing.value),
|
|
284
|
+
wordSpacing: Number(this.wordSpacing.value),
|
|
285
|
+
lineHeight: Number(this.lineHeight.value),
|
|
286
|
+
contrast: Number(this.contrast.value),
|
|
287
|
+
fontFamily: this.fontFamily.value
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
setValues(e = {}) {
|
|
291
|
+
if (e.fontSize !== void 0 && (this.fontSize.value = e.fontSize), e.letterSpacing !== void 0 && (this.letterSpacing.value = e.letterSpacing), e.wordSpacing !== void 0 && (this.wordSpacing.value = e.wordSpacing), e.lineHeight !== void 0 && (this.lineHeight.value = e.lineHeight), e.contrast !== void 0 && (this.contrast.value = e.contrast), e.fontFamily !== void 0)
|
|
292
|
+
if (e.fontFamily === "inherit" && target) {
|
|
293
|
+
const t = getComputedStyle(target).fontFamily;
|
|
294
|
+
this.fontFamily.value = t;
|
|
295
|
+
} else
|
|
296
|
+
this.fontFamily.value = e.fontFamily;
|
|
297
|
+
this.update();
|
|
298
|
+
}
|
|
299
|
+
setFeatures(e = {}) {
|
|
300
|
+
e.letterSpacing !== void 0 && (this.toggleGroup("#groupLetterSpacing", e.letterSpacing), e.letterSpacing ? this.removeAttribute("hide-letter-spacing") : this.setAttribute("hide-letter-spacing", "")), e.wordSpacing !== void 0 && (this.toggleGroup("#groupWordSpacing", e.wordSpacing), e.wordSpacing ? this.removeAttribute("hide-word-spacing") : this.setAttribute("hide-word-spacing", "")), e.lineHeight !== void 0 && (this.toggleGroup("#groupLineHeight", e.lineHeight), e.lineHeight ? this.removeAttribute("hide-line-height") : this.setAttribute("hide-line-height", "")), e.contrast !== void 0 && (this.toggleGroup("#groupContrast", e.contrast), e.contrast ? this.removeAttribute("hide-contrast") : this.setAttribute("hide-contrast", ""));
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
customElements.define("typography-controller", r);
|
|
304
|
+
const p = a({
|
|
305
|
+
react: o,
|
|
306
|
+
tagName: "typography-controller",
|
|
307
|
+
elementClass: customElements.get("typography-controller"),
|
|
308
|
+
events: {
|
|
309
|
+
onChange: "change"
|
|
310
|
+
}
|
|
311
|
+
});
|
|
312
|
+
export {
|
|
313
|
+
p as TypographyController
|
|
314
|
+
};
|