typography-controller 1.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 +135 -0
- package/dist/index.html +196 -0
- package/dist/typography-controller.js +206 -0
- package/dist/typography-controller.umd.cjs +155 -0
- package/package.json +52 -0
- package/src/typography-controller.js +294 -0
package/LICENSE
ADDED
|
@@ -0,0 +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
|
|
21
|
+
DEALINGS IN THE SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# Typography Controller
|
|
2
|
+
|
|
3
|
+
A framework-agnostic Web Component that provides a beautiful typography control panel:
|
|
4
|
+
font size, letter spacing, word spacing, line height, contrast, and font family.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- Font Size: Adjust the font size with a slider (range: 12-48px)
|
|
10
|
+
- Letter Spacing: Control the spacing between characters
|
|
11
|
+
- Word Spacing: Adjust spacing between words
|
|
12
|
+
- Line Height: Set the line height (1-3)
|
|
13
|
+
- Contrast: Apply a contrast filter (50-200%)
|
|
14
|
+
- Font Family: Choose from predefined fonts (Arial, Georgia, Courier New, Verdana)
|
|
15
|
+
|
|
16
|
+

|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
1. Include the `typography-controller.js` script in your HTML file:
|
|
21
|
+
|
|
22
|
+
```html
|
|
23
|
+
<script src="typography-controller.js"></script>
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
2. Add the `<typography-controller>` element to your HTML, specifying the target element via the `target` attribute:
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<typography-controller target="#myText"></typography-controller>
|
|
30
|
+
<div id="myText">This is the text to style.</div>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
The controller will automatically apply the selected styles to the target element.
|
|
34
|
+
|
|
35
|
+
## API
|
|
36
|
+
|
|
37
|
+
### Methods
|
|
38
|
+
|
|
39
|
+
- `getValues()`: Returns an object with current values.
|
|
40
|
+
- `setValues(values)`: Sets the values from an object.
|
|
41
|
+
|
|
42
|
+
### Events
|
|
43
|
+
|
|
44
|
+
- `change`: Fired when any control changes, with `detail` containing the current values.
|
|
45
|
+
|
|
46
|
+
### JavaScript API Usage
|
|
47
|
+
|
|
48
|
+
```javascript
|
|
49
|
+
const controller = document.querySelector("typography-controller");
|
|
50
|
+
|
|
51
|
+
controller.addEventListener("change", (e) => {
|
|
52
|
+
console.log("Updated values:", e.detail);
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
controller.setValues({
|
|
56
|
+
fontSize: 30,
|
|
57
|
+
letterSpacing: 2,
|
|
58
|
+
fontFamily: "Georgia"
|
|
59
|
+
});
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Example
|
|
63
|
+
|
|
64
|
+
See `index.html` for a complete example.
|
|
65
|
+
|
|
66
|
+
### Quick note on bundling (Vite/Rollup)
|
|
67
|
+
|
|
68
|
+
You can start without bundling (just `src/` + `demo/`), then later add:
|
|
69
|
+
|
|
70
|
+
- `vite.config.js` or `rollup.config.js` to build `src/typography-controller.js` into `dist/typography-controller.js`
|
|
71
|
+
- `package.json` with `"module": "dist/typography-controller.js"`
|
|
72
|
+
|
|
73
|
+
If you want, next step we can wire up a minimal Vite config and `package.json` ready for `npm publish`.
|
|
74
|
+
|
|
75
|
+
### React usage
|
|
76
|
+
|
|
77
|
+
```
|
|
78
|
+
import { TypographyController } from "./react-wrapper/TypographyController";
|
|
79
|
+
|
|
80
|
+
export default function App() {
|
|
81
|
+
return (
|
|
82
|
+
<div>
|
|
83
|
+
<h2 id="demoText">Typography should feel like breathing space.</h2>
|
|
84
|
+
|
|
85
|
+
<TypographyController
|
|
86
|
+
target="#demoText"
|
|
87
|
+
hide-letter-spacing
|
|
88
|
+
onChange={(e) => console.log(e.detail)}
|
|
89
|
+
/>
|
|
90
|
+
</div>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### Support JS API (setFeatures, setValues) in React
|
|
97
|
+
|
|
98
|
+
React reference
|
|
99
|
+
```
|
|
100
|
+
import { useRef, useEffect } from "react";
|
|
101
|
+
import { TypographyController } from "./react-wrapper/TypographyController";
|
|
102
|
+
|
|
103
|
+
export default function App() {
|
|
104
|
+
const ref = useRef();
|
|
105
|
+
|
|
106
|
+
useEffect(() => {
|
|
107
|
+
if (ref.current) {
|
|
108
|
+
ref.current.setFeatures({
|
|
109
|
+
letterSpacing: true,
|
|
110
|
+
wordSpacing: false,
|
|
111
|
+
lineHeight: true,
|
|
112
|
+
contrast: true
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, []);
|
|
116
|
+
|
|
117
|
+
return (
|
|
118
|
+
<>
|
|
119
|
+
<h2 id="demoText">Hello world</h2>
|
|
120
|
+
|
|
121
|
+
<TypographyController
|
|
122
|
+
ref={ref}
|
|
123
|
+
target="#demoText"
|
|
124
|
+
onChange={(e) => console.log(e.detail)}
|
|
125
|
+
/>
|
|
126
|
+
</>
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.
|
package/dist/index.html
ADDED
|
@@ -0,0 +1,196 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
|
|
4
|
+
<head>
|
|
5
|
+
<meta charset="UTF-8" />
|
|
6
|
+
<title>Typography Controller Demo</title>
|
|
7
|
+
|
|
8
|
+
<style>
|
|
9
|
+
body {
|
|
10
|
+
margin: 0;
|
|
11
|
+
min-height: 100vh;
|
|
12
|
+
display: flex;
|
|
13
|
+
align-items: center;
|
|
14
|
+
justify-content: center;
|
|
15
|
+
background: linear-gradient(135deg, #dbeafe, #eff6ff);
|
|
16
|
+
color: #1e293b;
|
|
17
|
+
font-family: system-ui, sans-serif;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
.page-layout {
|
|
21
|
+
display: grid;
|
|
22
|
+
grid-template-columns: 1fr 420px;
|
|
23
|
+
gap: 32px;
|
|
24
|
+
padding: 40px;
|
|
25
|
+
min-height: 100vh;
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/* LEFT PANEL */
|
|
30
|
+
.left-panel {
|
|
31
|
+
display: flex;
|
|
32
|
+
align-items: top;
|
|
33
|
+
justify-content: center;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.preview {
|
|
37
|
+
padding: 28px 32px;
|
|
38
|
+
border-radius: 18px;
|
|
39
|
+
background: rgba(255, 255, 255, 0.7);
|
|
40
|
+
backdrop-filter: blur(12px);
|
|
41
|
+
box-shadow: 0 8px 30px rgba(0, 0, 0, 0.08);
|
|
42
|
+
max-width: 600px;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
#demoText {
|
|
46
|
+
margin: 0;
|
|
47
|
+
color: #0f172a;
|
|
48
|
+
font-size: 32px;
|
|
49
|
+
line-height: 1.4;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/* RIGHT PANEL */
|
|
53
|
+
.right-panel {
|
|
54
|
+
display: grid;
|
|
55
|
+
grid-template-rows: auto 1fr;
|
|
56
|
+
gap: 20px;
|
|
57
|
+
position: fixed;
|
|
58
|
+
right:0;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/* TOGGLE CHIPS */
|
|
62
|
+
.feature-toggles {
|
|
63
|
+
padding: 16px;
|
|
64
|
+
border-radius: 16px;
|
|
65
|
+
background: rgba(255, 255, 255, 0.65);
|
|
66
|
+
backdrop-filter: blur(10px);
|
|
67
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
68
|
+
box-shadow: 0 4px 20px rgba(0, 0, 0, 0.06);
|
|
69
|
+
display: flex;
|
|
70
|
+
flex-wrap: wrap;
|
|
71
|
+
gap: 10px;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
.toggle-title {
|
|
75
|
+
width: 100%;
|
|
76
|
+
font-size: 13px;
|
|
77
|
+
font-weight: 600;
|
|
78
|
+
color: #475569;
|
|
79
|
+
margin-bottom: 4px;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
.chip {
|
|
83
|
+
padding: 8px 14px;
|
|
84
|
+
border-radius: 20px;
|
|
85
|
+
font-size: 13px;
|
|
86
|
+
cursor: pointer;
|
|
87
|
+
user-select: none;
|
|
88
|
+
background: #e2e8f0;
|
|
89
|
+
color: #1e293b;
|
|
90
|
+
border: 1px solid #cbd5e1;
|
|
91
|
+
transition: all 0.2s ease;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
.chip.active {
|
|
95
|
+
background: #3b82f6;
|
|
96
|
+
color: white;
|
|
97
|
+
border-color: #2563eb;
|
|
98
|
+
box-shadow: 0 2px 6px rgba(37, 99, 235, 0.35);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/* CONTROLLER */
|
|
102
|
+
.controller-wrapper {
|
|
103
|
+
padding: 0;
|
|
104
|
+
display: flex;
|
|
105
|
+
align-items: flex-start;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
@media (max-width: 800px) {
|
|
110
|
+
.layout {
|
|
111
|
+
grid-template-columns: 1fr;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
</style>
|
|
115
|
+
</head>
|
|
116
|
+
|
|
117
|
+
<body>
|
|
118
|
+
<div class="page-layout">
|
|
119
|
+
|
|
120
|
+
<!-- LEFT SIDE: TEXT PREVIEW -->
|
|
121
|
+
<div class="left-panel">
|
|
122
|
+
<div class="preview">
|
|
123
|
+
<h2 id="demoText">
|
|
124
|
+
Typography should feel like breathing space, not noise.
|
|
125
|
+
</h2>
|
|
126
|
+
</div>
|
|
127
|
+
</div>
|
|
128
|
+
|
|
129
|
+
<!-- RIGHT SIDE: TOGGLES + CONTROLLER -->
|
|
130
|
+
<div class="right-panel">
|
|
131
|
+
|
|
132
|
+
<!-- TOP: FEATURE TOGGLE CHIPS -->
|
|
133
|
+
<div class="feature-toggles">
|
|
134
|
+
<div class="toggle-title">Toggle Features</div>
|
|
135
|
+
<div class="chip" id="chipLetter">Letter Spacing</div>
|
|
136
|
+
<div class="chip" id="chipWord">Word Spacing</div>
|
|
137
|
+
<div class="chip" id="chipLine">Line Height</div>
|
|
138
|
+
<div class="chip" id="chipContrast">Contrast</div>
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<!-- BOTTOM: TYPOGRAPHY CONTROLLER -->
|
|
142
|
+
<div class="controller-wrapper">
|
|
143
|
+
<typography-controller target="#demoText"></typography-controller>
|
|
144
|
+
|
|
145
|
+
</div>
|
|
146
|
+
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
<script>
|
|
150
|
+
customElements.whenDefined("typography-controller").then(() => {
|
|
151
|
+
const controller = document.querySelector("typography-controller");
|
|
152
|
+
|
|
153
|
+
const chips = {
|
|
154
|
+
letterSpacing: document.getElementById("chipLetter"),
|
|
155
|
+
wordSpacing: document.getElementById("chipWord"),
|
|
156
|
+
lineHeight: document.getElementById("chipLine"),
|
|
157
|
+
contrast: document.getElementById("chipContrast")
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const state = {
|
|
161
|
+
letterSpacing: true,
|
|
162
|
+
wordSpacing: true,
|
|
163
|
+
lineHeight: true,
|
|
164
|
+
contrast: true
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
controller.setFeatures(state);
|
|
168
|
+
|
|
169
|
+
function toggleFeature(key) {
|
|
170
|
+
state[key] = !state[key];
|
|
171
|
+
controller.setFeatures({ [key]: state[key] });
|
|
172
|
+
|
|
173
|
+
if (state[key]) chips[key].classList.add("active");
|
|
174
|
+
else chips[key].classList.remove("active");
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
chips.letterSpacing.onclick = () => toggleFeature("letterSpacing");
|
|
178
|
+
chips.wordSpacing.onclick = () => toggleFeature("wordSpacing");
|
|
179
|
+
chips.lineHeight.onclick = () => toggleFeature("lineHeight");
|
|
180
|
+
chips.contrast.onclick = () => toggleFeature("contrast");
|
|
181
|
+
|
|
182
|
+
// Initialize chips visually
|
|
183
|
+
Object.keys(state).forEach(key => {
|
|
184
|
+
if (state[key]) chips[key].classList.add("active");
|
|
185
|
+
else chips[key].classList.remove("active");
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
</script>
|
|
189
|
+
|
|
190
|
+
|
|
191
|
+
<script type="module" src="./typography-controller.js"></script>
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
</body>
|
|
195
|
+
|
|
196
|
+
</html>
|
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
class o extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super(), this.attachShadow({ mode: "open" }), this.shadowRoot.innerHTML = `
|
|
4
|
+
<style>
|
|
5
|
+
:host {
|
|
6
|
+
display: block;
|
|
7
|
+
font-family: system-ui, sans-serif;
|
|
8
|
+
max-width: 420px;
|
|
9
|
+
padding: 18px 20px;
|
|
10
|
+
border-radius: 18px;
|
|
11
|
+
background: rgba(255, 255, 255, 0.65);
|
|
12
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
13
|
+
backdrop-filter: blur(14px);
|
|
14
|
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
|
|
15
|
+
color: #0f172a;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
.header {
|
|
19
|
+
display: flex;
|
|
20
|
+
justify-content: space-between;
|
|
21
|
+
align-items: baseline;
|
|
22
|
+
margin-bottom: 14px;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.title {
|
|
26
|
+
font-size: 14px;
|
|
27
|
+
font-weight: 600;
|
|
28
|
+
letter-spacing: 0.08em;
|
|
29
|
+
text-transform: uppercase;
|
|
30
|
+
color: #475569;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
.badge {
|
|
34
|
+
font-size: 11px;
|
|
35
|
+
padding: 3px 8px;
|
|
36
|
+
border-radius: 999px;
|
|
37
|
+
background: rgba(59, 130, 246, 0.12);
|
|
38
|
+
color: #1d4ed8;
|
|
39
|
+
border: 1px solid rgba(59, 130, 246, 0.35);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
.group {
|
|
43
|
+
margin-bottom: 14px;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
.label-row {
|
|
47
|
+
display: flex;
|
|
48
|
+
justify-content: space-between;
|
|
49
|
+
align-items: center;
|
|
50
|
+
margin-bottom: 6px;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
label {
|
|
54
|
+
font-size: 12px;
|
|
55
|
+
font-weight: 600;
|
|
56
|
+
color: #0f172a;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
.value {
|
|
60
|
+
font-size: 11px;
|
|
61
|
+
color: #64748b;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
input[type="range"] {
|
|
65
|
+
-webkit-appearance: none;
|
|
66
|
+
width: 100%;
|
|
67
|
+
height: 6px;
|
|
68
|
+
border-radius: 999px;
|
|
69
|
+
background: linear-gradient(90deg, #3b82f6, #60a5fa);
|
|
70
|
+
outline: none;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
input[type="range"]::-webkit-slider-thumb {
|
|
74
|
+
-webkit-appearance: none;
|
|
75
|
+
height: 18px;
|
|
76
|
+
width: 18px;
|
|
77
|
+
border-radius: 50%;
|
|
78
|
+
background: white;
|
|
79
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
80
|
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
|
81
|
+
cursor: pointer;
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
select {
|
|
85
|
+
width: 100%;
|
|
86
|
+
padding: 6px 8px;
|
|
87
|
+
border-radius: 8px;
|
|
88
|
+
border: 1px solid rgba(148, 163, 184, 0.7);
|
|
89
|
+
background: rgba(255, 255, 255, 0.9);
|
|
90
|
+
font-size: 12px;
|
|
91
|
+
color: #0f172a;
|
|
92
|
+
outline: none;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
select:focus {
|
|
96
|
+
border-color: #2563eb;
|
|
97
|
+
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
|
|
98
|
+
}
|
|
99
|
+
</style>
|
|
100
|
+
|
|
101
|
+
<div class="header">
|
|
102
|
+
<div class="title">Typography Controls</div>
|
|
103
|
+
<div class="badge">Web Component</div>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<div class="group" id="groupFontSize">
|
|
107
|
+
<div class="label-row">
|
|
108
|
+
<label for="fontSize">Font size</label>
|
|
109
|
+
<span class="value" id="fontSizeValue"></span>
|
|
110
|
+
</div>
|
|
111
|
+
<input type="range" id="fontSize" min="12" max="60" value="24">
|
|
112
|
+
</div>
|
|
113
|
+
|
|
114
|
+
<div class="group" id="groupLetterSpacing">
|
|
115
|
+
<div class="label-row">
|
|
116
|
+
<label for="letterSpacing">Letter spacing</label>
|
|
117
|
+
<span class="value" id="letterSpacingValue"></span>
|
|
118
|
+
</div>
|
|
119
|
+
<input type="range" id="letterSpacing" min="0" max="20" value="0">
|
|
120
|
+
</div>
|
|
121
|
+
|
|
122
|
+
<div class="group" id="groupWordSpacing">
|
|
123
|
+
<div class="label-row">
|
|
124
|
+
<label for="wordSpacing">Word spacing</label>
|
|
125
|
+
<span class="value" id="wordSpacingValue"></span>
|
|
126
|
+
</div>
|
|
127
|
+
<input type="range" id="wordSpacing" min="0" max="40" value="0">
|
|
128
|
+
</div>
|
|
129
|
+
|
|
130
|
+
<div class="group" id="groupLineHeight">
|
|
131
|
+
<div class="label-row">
|
|
132
|
+
<label for="lineHeight">Line height</label>
|
|
133
|
+
<span class="value" id="lineHeightValue"></span>
|
|
134
|
+
</div>
|
|
135
|
+
<input type="range" id="lineHeight" min="1" max="3" step="0.1" value="1.5">
|
|
136
|
+
</div>
|
|
137
|
+
|
|
138
|
+
<div class="group" id="groupContrast">
|
|
139
|
+
<div class="label-row">
|
|
140
|
+
<label for="contrast">Contrast</label>
|
|
141
|
+
<span class="value" id="contrastValue"></span>
|
|
142
|
+
</div>
|
|
143
|
+
<input type="range" id="contrast" min="50" max="200" value="100">
|
|
144
|
+
</div>
|
|
145
|
+
|
|
146
|
+
<div class="group" id="groupFontFamily">
|
|
147
|
+
<div class="label-row">
|
|
148
|
+
<label for="fontFamily">Font family</label>
|
|
149
|
+
</div>
|
|
150
|
+
<select id="fontFamily">
|
|
151
|
+
<option value="system-ui, sans-serif">System</option>
|
|
152
|
+
<option value="Georgia, serif">Serif</option>
|
|
153
|
+
<option value="'Courier New', monospace">Monospace</option>
|
|
154
|
+
<option value="Verdana, sans-serif">Verdana</option>
|
|
155
|
+
</select>
|
|
156
|
+
</div>
|
|
157
|
+
`;
|
|
158
|
+
}
|
|
159
|
+
connectedCallback() {
|
|
160
|
+
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");
|
|
161
|
+
const t = this.targetElement;
|
|
162
|
+
if (t) {
|
|
163
|
+
const i = getComputedStyle(t).fontFamily;
|
|
164
|
+
this.fontFamily.value = i;
|
|
165
|
+
}
|
|
166
|
+
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");
|
|
167
|
+
const e = () => {
|
|
168
|
+
this.update(), this.dispatchEvent(
|
|
169
|
+
new CustomEvent("change", {
|
|
170
|
+
detail: this.getValues(),
|
|
171
|
+
bubbles: !0,
|
|
172
|
+
composed: !0
|
|
173
|
+
})
|
|
174
|
+
);
|
|
175
|
+
};
|
|
176
|
+
this.fontSize.addEventListener("input", e), this.letterSpacing.addEventListener("input", e), this.wordSpacing.addEventListener("input", e), this.lineHeight.addEventListener("input", e), this.contrast.addEventListener("input", e), this.fontFamily.addEventListener("change", e), this.update();
|
|
177
|
+
}
|
|
178
|
+
toggleGroup(t, e) {
|
|
179
|
+
const i = this.shadowRoot.querySelector(t);
|
|
180
|
+
i && (i.style.display = e ? "block" : "none");
|
|
181
|
+
}
|
|
182
|
+
get targetElement() {
|
|
183
|
+
return document.querySelector(this.targetSelector);
|
|
184
|
+
}
|
|
185
|
+
update() {
|
|
186
|
+
const t = this.targetElement;
|
|
187
|
+
t && (t.style.fontSize = `${this.fontSize.value}px`, t.style.letterSpacing = `${this.letterSpacing.value}px`, t.style.wordSpacing = `${this.wordSpacing.value}px`, t.style.lineHeight = this.lineHeight.value, t.style.filter = `contrast(${this.contrast.value}%)`, t.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}%`);
|
|
188
|
+
}
|
|
189
|
+
getValues() {
|
|
190
|
+
return {
|
|
191
|
+
fontSize: Number(this.fontSize.value),
|
|
192
|
+
letterSpacing: Number(this.letterSpacing.value),
|
|
193
|
+
wordSpacing: Number(this.wordSpacing.value),
|
|
194
|
+
lineHeight: Number(this.lineHeight.value),
|
|
195
|
+
contrast: Number(this.contrast.value),
|
|
196
|
+
fontFamily: this.fontFamily.value
|
|
197
|
+
};
|
|
198
|
+
}
|
|
199
|
+
setValues(t = {}) {
|
|
200
|
+
t.fontSize !== void 0 && (this.fontSize.value = t.fontSize), t.letterSpacing !== void 0 && (this.letterSpacing.value = t.letterSpacing), t.wordSpacing !== void 0 && (this.wordSpacing.value = t.wordSpacing), t.lineHeight !== void 0 && (this.lineHeight.value = t.lineHeight), t.contrast !== void 0 && (this.contrast.value = t.contrast), t.fontFamily !== void 0 && (this.fontFamily.value = t.fontFamily), this.update();
|
|
201
|
+
}
|
|
202
|
+
setFeatures(t = {}) {
|
|
203
|
+
t.letterSpacing !== void 0 && (this.toggleGroup("#groupLetterSpacing", t.letterSpacing), t.letterSpacing ? this.removeAttribute("hide-letter-spacing") : this.setAttribute("hide-letter-spacing", "")), t.wordSpacing !== void 0 && (this.toggleGroup("#groupWordSpacing", t.wordSpacing), t.wordSpacing ? this.removeAttribute("hide-word-spacing") : this.setAttribute("hide-word-spacing", "")), t.lineHeight !== void 0 && (this.toggleGroup("#groupLineHeight", t.lineHeight), t.lineHeight ? this.removeAttribute("hide-line-height") : this.setAttribute("hide-line-height", "")), t.contrast !== void 0 && (this.toggleGroup("#groupContrast", t.contrast), t.contrast ? this.removeAttribute("hide-contrast") : this.setAttribute("hide-contrast", ""));
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
customElements.define("typography-controller", o);
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
(function(i){typeof define=="function"&&define.amd?define(i):i()})(function(){"use strict";class i extends HTMLElement{constructor(){super(),this.attachShadow({mode:"open"}),this.shadowRoot.innerHTML=`
|
|
2
|
+
<style>
|
|
3
|
+
:host {
|
|
4
|
+
display: block;
|
|
5
|
+
font-family: system-ui, sans-serif;
|
|
6
|
+
max-width: 420px;
|
|
7
|
+
padding: 18px 20px;
|
|
8
|
+
border-radius: 18px;
|
|
9
|
+
background: rgba(255, 255, 255, 0.65);
|
|
10
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
11
|
+
backdrop-filter: blur(14px);
|
|
12
|
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
|
|
13
|
+
color: #0f172a;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
.header {
|
|
17
|
+
display: flex;
|
|
18
|
+
justify-content: space-between;
|
|
19
|
+
align-items: baseline;
|
|
20
|
+
margin-bottom: 14px;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.title {
|
|
24
|
+
font-size: 14px;
|
|
25
|
+
font-weight: 600;
|
|
26
|
+
letter-spacing: 0.08em;
|
|
27
|
+
text-transform: uppercase;
|
|
28
|
+
color: #475569;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
.badge {
|
|
32
|
+
font-size: 11px;
|
|
33
|
+
padding: 3px 8px;
|
|
34
|
+
border-radius: 999px;
|
|
35
|
+
background: rgba(59, 130, 246, 0.12);
|
|
36
|
+
color: #1d4ed8;
|
|
37
|
+
border: 1px solid rgba(59, 130, 246, 0.35);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
.group {
|
|
41
|
+
margin-bottom: 14px;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
.label-row {
|
|
45
|
+
display: flex;
|
|
46
|
+
justify-content: space-between;
|
|
47
|
+
align-items: center;
|
|
48
|
+
margin-bottom: 6px;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
label {
|
|
52
|
+
font-size: 12px;
|
|
53
|
+
font-weight: 600;
|
|
54
|
+
color: #0f172a;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.value {
|
|
58
|
+
font-size: 11px;
|
|
59
|
+
color: #64748b;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
input[type="range"] {
|
|
63
|
+
-webkit-appearance: none;
|
|
64
|
+
width: 100%;
|
|
65
|
+
height: 6px;
|
|
66
|
+
border-radius: 999px;
|
|
67
|
+
background: linear-gradient(90deg, #3b82f6, #60a5fa);
|
|
68
|
+
outline: none;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
input[type="range"]::-webkit-slider-thumb {
|
|
72
|
+
-webkit-appearance: none;
|
|
73
|
+
height: 18px;
|
|
74
|
+
width: 18px;
|
|
75
|
+
border-radius: 50%;
|
|
76
|
+
background: white;
|
|
77
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
78
|
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
|
79
|
+
cursor: pointer;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
select {
|
|
83
|
+
width: 100%;
|
|
84
|
+
padding: 6px 8px;
|
|
85
|
+
border-radius: 8px;
|
|
86
|
+
border: 1px solid rgba(148, 163, 184, 0.7);
|
|
87
|
+
background: rgba(255, 255, 255, 0.9);
|
|
88
|
+
font-size: 12px;
|
|
89
|
+
color: #0f172a;
|
|
90
|
+
outline: none;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
select:focus {
|
|
94
|
+
border-color: #2563eb;
|
|
95
|
+
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
|
|
96
|
+
}
|
|
97
|
+
</style>
|
|
98
|
+
|
|
99
|
+
<div class="header">
|
|
100
|
+
<div class="title">Typography Controls</div>
|
|
101
|
+
<div class="badge">Web Component</div>
|
|
102
|
+
</div>
|
|
103
|
+
|
|
104
|
+
<div class="group" id="groupFontSize">
|
|
105
|
+
<div class="label-row">
|
|
106
|
+
<label for="fontSize">Font size</label>
|
|
107
|
+
<span class="value" id="fontSizeValue"></span>
|
|
108
|
+
</div>
|
|
109
|
+
<input type="range" id="fontSize" min="12" max="60" value="24">
|
|
110
|
+
</div>
|
|
111
|
+
|
|
112
|
+
<div class="group" id="groupLetterSpacing">
|
|
113
|
+
<div class="label-row">
|
|
114
|
+
<label for="letterSpacing">Letter spacing</label>
|
|
115
|
+
<span class="value" id="letterSpacingValue"></span>
|
|
116
|
+
</div>
|
|
117
|
+
<input type="range" id="letterSpacing" min="0" max="20" value="0">
|
|
118
|
+
</div>
|
|
119
|
+
|
|
120
|
+
<div class="group" id="groupWordSpacing">
|
|
121
|
+
<div class="label-row">
|
|
122
|
+
<label for="wordSpacing">Word spacing</label>
|
|
123
|
+
<span class="value" id="wordSpacingValue"></span>
|
|
124
|
+
</div>
|
|
125
|
+
<input type="range" id="wordSpacing" min="0" max="40" value="0">
|
|
126
|
+
</div>
|
|
127
|
+
|
|
128
|
+
<div class="group" id="groupLineHeight">
|
|
129
|
+
<div class="label-row">
|
|
130
|
+
<label for="lineHeight">Line height</label>
|
|
131
|
+
<span class="value" id="lineHeightValue"></span>
|
|
132
|
+
</div>
|
|
133
|
+
<input type="range" id="lineHeight" min="1" max="3" step="0.1" value="1.5">
|
|
134
|
+
</div>
|
|
135
|
+
|
|
136
|
+
<div class="group" id="groupContrast">
|
|
137
|
+
<div class="label-row">
|
|
138
|
+
<label for="contrast">Contrast</label>
|
|
139
|
+
<span class="value" id="contrastValue"></span>
|
|
140
|
+
</div>
|
|
141
|
+
<input type="range" id="contrast" min="50" max="200" value="100">
|
|
142
|
+
</div>
|
|
143
|
+
|
|
144
|
+
<div class="group" id="groupFontFamily">
|
|
145
|
+
<div class="label-row">
|
|
146
|
+
<label for="fontFamily">Font family</label>
|
|
147
|
+
</div>
|
|
148
|
+
<select id="fontFamily">
|
|
149
|
+
<option value="system-ui, sans-serif">System</option>
|
|
150
|
+
<option value="Georgia, serif">Serif</option>
|
|
151
|
+
<option value="'Courier New', monospace">Monospace</option>
|
|
152
|
+
<option value="Verdana, sans-serif">Verdana</option>
|
|
153
|
+
</select>
|
|
154
|
+
</div>
|
|
155
|
+
`}connectedCallback(){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");const t=this.targetElement;if(t){const o=getComputedStyle(t).fontFamily;this.fontFamily.value=o}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");const e=()=>{this.update(),this.dispatchEvent(new CustomEvent("change",{detail:this.getValues(),bubbles:!0,composed:!0}))};this.fontSize.addEventListener("input",e),this.letterSpacing.addEventListener("input",e),this.wordSpacing.addEventListener("input",e),this.lineHeight.addEventListener("input",e),this.contrast.addEventListener("input",e),this.fontFamily.addEventListener("change",e),this.update()}toggleGroup(t,e){const o=this.shadowRoot.querySelector(t);o&&(o.style.display=e?"block":"none")}get targetElement(){return document.querySelector(this.targetSelector)}update(){const t=this.targetElement;t&&(t.style.fontSize=`${this.fontSize.value}px`,t.style.letterSpacing=`${this.letterSpacing.value}px`,t.style.wordSpacing=`${this.wordSpacing.value}px`,t.style.lineHeight=this.lineHeight.value,t.style.filter=`contrast(${this.contrast.value}%)`,t.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}%`)}getValues(){return{fontSize:Number(this.fontSize.value),letterSpacing:Number(this.letterSpacing.value),wordSpacing:Number(this.wordSpacing.value),lineHeight:Number(this.lineHeight.value),contrast:Number(this.contrast.value),fontFamily:this.fontFamily.value}}setValues(t={}){t.fontSize!==void 0&&(this.fontSize.value=t.fontSize),t.letterSpacing!==void 0&&(this.letterSpacing.value=t.letterSpacing),t.wordSpacing!==void 0&&(this.wordSpacing.value=t.wordSpacing),t.lineHeight!==void 0&&(this.lineHeight.value=t.lineHeight),t.contrast!==void 0&&(this.contrast.value=t.contrast),t.fontFamily!==void 0&&(this.fontFamily.value=t.fontFamily),this.update()}setFeatures(t={}){t.letterSpacing!==void 0&&(this.toggleGroup("#groupLetterSpacing",t.letterSpacing),t.letterSpacing?this.removeAttribute("hide-letter-spacing"):this.setAttribute("hide-letter-spacing","")),t.wordSpacing!==void 0&&(this.toggleGroup("#groupWordSpacing",t.wordSpacing),t.wordSpacing?this.removeAttribute("hide-word-spacing"):this.setAttribute("hide-word-spacing","")),t.lineHeight!==void 0&&(this.toggleGroup("#groupLineHeight",t.lineHeight),t.lineHeight?this.removeAttribute("hide-line-height"):this.setAttribute("hide-line-height","")),t.contrast!==void 0&&(this.toggleGroup("#groupContrast",t.contrast),t.contrast?this.removeAttribute("hide-contrast"):this.setAttribute("hide-contrast",""))}}customElements.define("typography-controller",i)});
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "typography-controller",
|
|
3
|
+
"version": "1.0.1",
|
|
4
|
+
"description": "A framework-agnostic Web Component that provides a beautiful typography control panel with sliders for font size, letter spacing, word spacing, line height, contrast, and font family.",
|
|
5
|
+
"author": "Achuth Kamath",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"main": "dist/typography-controller.js",
|
|
9
|
+
"module": "dist/typography-controller.js",
|
|
10
|
+
"source": "src/typography-controller.js",
|
|
11
|
+
"exports": {
|
|
12
|
+
".": "./dist/typography-controller.js",
|
|
13
|
+
"./react": "./dist/react-wrapper.js"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"src",
|
|
18
|
+
"README.md",
|
|
19
|
+
"LICENSE"
|
|
20
|
+
],
|
|
21
|
+
"scripts": {
|
|
22
|
+
"dev": "vite",
|
|
23
|
+
"build": "vite build",
|
|
24
|
+
"preview": "vite preview"
|
|
25
|
+
},
|
|
26
|
+
"keywords": [
|
|
27
|
+
"web-components",
|
|
28
|
+
"custom-elements",
|
|
29
|
+
"typography",
|
|
30
|
+
"ui",
|
|
31
|
+
"ui-library",
|
|
32
|
+
"accessibility",
|
|
33
|
+
"design-system",
|
|
34
|
+
"frontend",
|
|
35
|
+
"javascript"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://github.com/achuthkamath/typography-controller",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "https://github.com/achuthkamath/typography-controller.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/achuthkamath/typography-controller/issues"
|
|
44
|
+
},
|
|
45
|
+
"devDependencies": {
|
|
46
|
+
"@vitejs/plugin-react": "^5.1.2",
|
|
47
|
+
"vite": "^5.4.21"
|
|
48
|
+
},
|
|
49
|
+
"dependencies": {
|
|
50
|
+
"user": "^0.0.0"
|
|
51
|
+
}
|
|
52
|
+
}
|
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
class TypographyController extends HTMLElement {
|
|
2
|
+
constructor() {
|
|
3
|
+
super();
|
|
4
|
+
this.attachShadow({ mode: "open" });
|
|
5
|
+
|
|
6
|
+
this.shadowRoot.innerHTML = `
|
|
7
|
+
<style>
|
|
8
|
+
:host {
|
|
9
|
+
display: block;
|
|
10
|
+
font-family: system-ui, sans-serif;
|
|
11
|
+
max-width: 420px;
|
|
12
|
+
padding: 18px 20px;
|
|
13
|
+
border-radius: 18px;
|
|
14
|
+
background: rgba(255, 255, 255, 0.65);
|
|
15
|
+
border: 1px solid rgba(0, 0, 0, 0.08);
|
|
16
|
+
backdrop-filter: blur(14px);
|
|
17
|
+
box-shadow: 0 8px 25px rgba(0, 0, 0, 0.08);
|
|
18
|
+
color: #0f172a;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.header {
|
|
22
|
+
display: flex;
|
|
23
|
+
justify-content: space-between;
|
|
24
|
+
align-items: baseline;
|
|
25
|
+
margin-bottom: 14px;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
.title {
|
|
29
|
+
font-size: 14px;
|
|
30
|
+
font-weight: 600;
|
|
31
|
+
letter-spacing: 0.08em;
|
|
32
|
+
text-transform: uppercase;
|
|
33
|
+
color: #475569;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
.badge {
|
|
37
|
+
font-size: 11px;
|
|
38
|
+
padding: 3px 8px;
|
|
39
|
+
border-radius: 999px;
|
|
40
|
+
background: rgba(59, 130, 246, 0.12);
|
|
41
|
+
color: #1d4ed8;
|
|
42
|
+
border: 1px solid rgba(59, 130, 246, 0.35);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
.group {
|
|
46
|
+
margin-bottom: 14px;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
.label-row {
|
|
50
|
+
display: flex;
|
|
51
|
+
justify-content: space-between;
|
|
52
|
+
align-items: center;
|
|
53
|
+
margin-bottom: 6px;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
label {
|
|
57
|
+
font-size: 12px;
|
|
58
|
+
font-weight: 600;
|
|
59
|
+
color: #0f172a;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
.value {
|
|
63
|
+
font-size: 11px;
|
|
64
|
+
color: #64748b;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
input[type="range"] {
|
|
68
|
+
-webkit-appearance: none;
|
|
69
|
+
width: 100%;
|
|
70
|
+
height: 6px;
|
|
71
|
+
border-radius: 999px;
|
|
72
|
+
background: linear-gradient(90deg, #3b82f6, #60a5fa);
|
|
73
|
+
outline: none;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
input[type="range"]::-webkit-slider-thumb {
|
|
77
|
+
-webkit-appearance: none;
|
|
78
|
+
height: 18px;
|
|
79
|
+
width: 18px;
|
|
80
|
+
border-radius: 50%;
|
|
81
|
+
background: white;
|
|
82
|
+
border: 1px solid rgba(0, 0, 0, 0.15);
|
|
83
|
+
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.15);
|
|
84
|
+
cursor: pointer;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
select {
|
|
88
|
+
width: 100%;
|
|
89
|
+
padding: 6px 8px;
|
|
90
|
+
border-radius: 8px;
|
|
91
|
+
border: 1px solid rgba(148, 163, 184, 0.7);
|
|
92
|
+
background: rgba(255, 255, 255, 0.9);
|
|
93
|
+
font-size: 12px;
|
|
94
|
+
color: #0f172a;
|
|
95
|
+
outline: none;
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
select:focus {
|
|
99
|
+
border-color: #2563eb;
|
|
100
|
+
box-shadow: 0 0 0 1px rgba(37, 99, 235, 0.4);
|
|
101
|
+
}
|
|
102
|
+
</style>
|
|
103
|
+
|
|
104
|
+
<div class="header">
|
|
105
|
+
<div class="title">Typography Controls</div>
|
|
106
|
+
<div class="badge">Web Component</div>
|
|
107
|
+
</div>
|
|
108
|
+
|
|
109
|
+
<div class="group" id="groupFontSize">
|
|
110
|
+
<div class="label-row">
|
|
111
|
+
<label for="fontSize">Font size</label>
|
|
112
|
+
<span class="value" id="fontSizeValue"></span>
|
|
113
|
+
</div>
|
|
114
|
+
<input type="range" id="fontSize" min="12" max="60" value="24">
|
|
115
|
+
</div>
|
|
116
|
+
|
|
117
|
+
<div class="group" id="groupLetterSpacing">
|
|
118
|
+
<div class="label-row">
|
|
119
|
+
<label for="letterSpacing">Letter spacing</label>
|
|
120
|
+
<span class="value" id="letterSpacingValue"></span>
|
|
121
|
+
</div>
|
|
122
|
+
<input type="range" id="letterSpacing" min="0" max="20" value="0">
|
|
123
|
+
</div>
|
|
124
|
+
|
|
125
|
+
<div class="group" id="groupWordSpacing">
|
|
126
|
+
<div class="label-row">
|
|
127
|
+
<label for="wordSpacing">Word spacing</label>
|
|
128
|
+
<span class="value" id="wordSpacingValue"></span>
|
|
129
|
+
</div>
|
|
130
|
+
<input type="range" id="wordSpacing" min="0" max="40" value="0">
|
|
131
|
+
</div>
|
|
132
|
+
|
|
133
|
+
<div class="group" id="groupLineHeight">
|
|
134
|
+
<div class="label-row">
|
|
135
|
+
<label for="lineHeight">Line height</label>
|
|
136
|
+
<span class="value" id="lineHeightValue"></span>
|
|
137
|
+
</div>
|
|
138
|
+
<input type="range" id="lineHeight" min="1" max="3" step="0.1" value="1.5">
|
|
139
|
+
</div>
|
|
140
|
+
|
|
141
|
+
<div class="group" id="groupContrast">
|
|
142
|
+
<div class="label-row">
|
|
143
|
+
<label for="contrast">Contrast</label>
|
|
144
|
+
<span class="value" id="contrastValue"></span>
|
|
145
|
+
</div>
|
|
146
|
+
<input type="range" id="contrast" min="50" max="200" value="100">
|
|
147
|
+
</div>
|
|
148
|
+
|
|
149
|
+
<div class="group" id="groupFontFamily">
|
|
150
|
+
<div class="label-row">
|
|
151
|
+
<label for="fontFamily">Font family</label>
|
|
152
|
+
</div>
|
|
153
|
+
<select id="fontFamily">
|
|
154
|
+
<option value="system-ui, sans-serif">System</option>
|
|
155
|
+
<option value="Georgia, serif">Serif</option>
|
|
156
|
+
<option value="'Courier New', monospace">Monospace</option>
|
|
157
|
+
<option value="Verdana, sans-serif">Verdana</option>
|
|
158
|
+
</select>
|
|
159
|
+
</div>
|
|
160
|
+
`;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
connectedCallback() {
|
|
164
|
+
this.targetSelector = this.getAttribute("target");
|
|
165
|
+
|
|
166
|
+
// Read attributes for initial hiding
|
|
167
|
+
this.toggleGroup("#groupLetterSpacing", !this.hasAttribute("hide-letter-spacing"));
|
|
168
|
+
this.toggleGroup("#groupWordSpacing", !this.hasAttribute("hide-word-spacing"));
|
|
169
|
+
this.toggleGroup("#groupLineHeight", !this.hasAttribute("hide-line-height"));
|
|
170
|
+
this.toggleGroup("#groupContrast", !this.hasAttribute("hide-contrast"));
|
|
171
|
+
|
|
172
|
+
// Query elements
|
|
173
|
+
this.fontSize = this.shadowRoot.querySelector("#fontSize");
|
|
174
|
+
this.letterSpacing = this.shadowRoot.querySelector("#letterSpacing");
|
|
175
|
+
this.wordSpacing = this.shadowRoot.querySelector("#wordSpacing");
|
|
176
|
+
this.lineHeight = this.shadowRoot.querySelector("#lineHeight");
|
|
177
|
+
this.contrast = this.shadowRoot.querySelector("#contrast");
|
|
178
|
+
this.fontFamily = this.shadowRoot.querySelector("#fontFamily");
|
|
179
|
+
// ⭐ Auto‑detect the user's current font family
|
|
180
|
+
const target = this.targetElement;
|
|
181
|
+
if (target) {
|
|
182
|
+
const computed = getComputedStyle(target).fontFamily;
|
|
183
|
+
this.fontFamily.value = computed;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
this.fontSizeValue = this.shadowRoot.querySelector("#fontSizeValue");
|
|
188
|
+
this.letterSpacingValue = this.shadowRoot.querySelector("#letterSpacingValue");
|
|
189
|
+
this.wordSpacingValue = this.shadowRoot.querySelector("#wordSpacingValue");
|
|
190
|
+
this.lineHeightValue = this.shadowRoot.querySelector("#lineHeightValue");
|
|
191
|
+
this.contrastValue = this.shadowRoot.querySelector("#contrastValue");
|
|
192
|
+
|
|
193
|
+
const updateAndEmit = () => {
|
|
194
|
+
this.update();
|
|
195
|
+
this.dispatchEvent(
|
|
196
|
+
new CustomEvent("change", {
|
|
197
|
+
detail: this.getValues(),
|
|
198
|
+
bubbles: true,
|
|
199
|
+
composed: true
|
|
200
|
+
})
|
|
201
|
+
);
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
this.fontSize.addEventListener("input", updateAndEmit);
|
|
205
|
+
this.letterSpacing.addEventListener("input", updateAndEmit);
|
|
206
|
+
this.wordSpacing.addEventListener("input", updateAndEmit);
|
|
207
|
+
this.lineHeight.addEventListener("input", updateAndEmit);
|
|
208
|
+
this.contrast.addEventListener("input", updateAndEmit);
|
|
209
|
+
this.fontFamily.addEventListener("change", updateAndEmit);
|
|
210
|
+
|
|
211
|
+
this.update();
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
toggleGroup(id, show) {
|
|
215
|
+
const el = this.shadowRoot.querySelector(id);
|
|
216
|
+
if (el) el.style.display = show ? "block" : "none";
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
get targetElement() {
|
|
220
|
+
return document.querySelector(this.targetSelector);
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
update() {
|
|
224
|
+
const target = this.targetElement;
|
|
225
|
+
if (!target) return;
|
|
226
|
+
|
|
227
|
+
target.style.fontSize = `${this.fontSize.value}px`;
|
|
228
|
+
target.style.letterSpacing = `${this.letterSpacing.value}px`;
|
|
229
|
+
target.style.wordSpacing = `${this.wordSpacing.value}px`;
|
|
230
|
+
target.style.lineHeight = this.lineHeight.value;
|
|
231
|
+
target.style.filter = `contrast(${this.contrast.value}%)`;
|
|
232
|
+
target.style.fontFamily = this.fontFamily.value;
|
|
233
|
+
|
|
234
|
+
this.fontSizeValue.textContent = `${this.fontSize.value}px`;
|
|
235
|
+
this.letterSpacingValue.textContent = `${this.letterSpacing.value}px`;
|
|
236
|
+
this.wordSpacingValue.textContent = `${this.wordSpacing.value}px`;
|
|
237
|
+
this.lineHeightValue.textContent = this.lineHeight.value;
|
|
238
|
+
this.contrastValue.textContent = `${this.contrast.value}%`;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
getValues() {
|
|
242
|
+
return {
|
|
243
|
+
fontSize: Number(this.fontSize.value),
|
|
244
|
+
letterSpacing: Number(this.letterSpacing.value),
|
|
245
|
+
wordSpacing: Number(this.wordSpacing.value),
|
|
246
|
+
lineHeight: Number(this.lineHeight.value),
|
|
247
|
+
contrast: Number(this.contrast.value),
|
|
248
|
+
fontFamily: this.fontFamily.value
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
setValues(values = {}) {
|
|
253
|
+
if (values.fontSize !== undefined) this.fontSize.value = values.fontSize;
|
|
254
|
+
if (values.letterSpacing !== undefined) this.letterSpacing.value = values.letterSpacing;
|
|
255
|
+
if (values.wordSpacing !== undefined) this.wordSpacing.value = values.wordSpacing;
|
|
256
|
+
if (values.lineHeight !== undefined) this.lineHeight.value = values.lineHeight;
|
|
257
|
+
if (values.contrast !== undefined) this.contrast.value = values.contrast;
|
|
258
|
+
if (values.fontFamily !== undefined) this.fontFamily.value = values.fontFamily;
|
|
259
|
+
|
|
260
|
+
this.update();
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
setFeatures(features = {}) {
|
|
264
|
+
if (features.letterSpacing !== undefined) {
|
|
265
|
+
this.toggleGroup("#groupLetterSpacing", features.letterSpacing);
|
|
266
|
+
features.letterSpacing
|
|
267
|
+
? this.removeAttribute("hide-letter-spacing")
|
|
268
|
+
: this.setAttribute("hide-letter-spacing", "");
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
if (features.wordSpacing !== undefined) {
|
|
272
|
+
this.toggleGroup("#groupWordSpacing", features.wordSpacing);
|
|
273
|
+
features.wordSpacing
|
|
274
|
+
? this.removeAttribute("hide-word-spacing")
|
|
275
|
+
: this.setAttribute("hide-word-spacing", "");
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
if (features.lineHeight !== undefined) {
|
|
279
|
+
this.toggleGroup("#groupLineHeight", features.lineHeight);
|
|
280
|
+
features.lineHeight
|
|
281
|
+
? this.removeAttribute("hide-line-height")
|
|
282
|
+
: this.setAttribute("hide-line-height", "");
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
if (features.contrast !== undefined) {
|
|
286
|
+
this.toggleGroup("#groupContrast", features.contrast);
|
|
287
|
+
features.contrast
|
|
288
|
+
? this.removeAttribute("hide-contrast")
|
|
289
|
+
: this.setAttribute("hide-contrast", "");
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
customElements.define("typography-controller", TypographyController);
|