typography-controller 1.1.0 → 1.2.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/dist/react/react-wrapper.js +50 -268
- package/dist/web/typography-controller.js +48 -266
- package/dist/web/typography-controller.umd.cjs +4 -244
- package/package.json +1 -1
- package/src/typography-controller.css +113 -0
- package/src/typography-controller.html +69 -0
- package/src/typography-controller.js +86 -253
|
@@ -1,261 +1,25 @@
|
|
|
1
1
|
import { createComponent as a } from "@lit/react";
|
|
2
|
-
import
|
|
2
|
+
import s from "react";
|
|
3
3
|
let r = class extends HTMLElement {
|
|
4
4
|
constructor() {
|
|
5
|
-
super(), this.attachShadow({ mode: "open" })
|
|
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
|
-
`;
|
|
5
|
+
super(), this.attachShadow({ mode: "open" });
|
|
249
6
|
}
|
|
250
|
-
connectedCallback() {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
7
|
+
async connectedCallback() {
|
|
8
|
+
const [t, i] = await Promise.all([
|
|
9
|
+
fetch("../src//typography-controller.html").then((o) => o.text()),
|
|
10
|
+
fetch("../src/typography-controller.css").then((o) => o.text())
|
|
11
|
+
]);
|
|
12
|
+
this.shadowRoot.innerHTML = `
|
|
13
|
+
<style>${i}</style>
|
|
14
|
+
${t}
|
|
15
|
+
`, 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.toggleGroup("#groupFamily", !this.hasAttribute("hide-font-family")), 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");
|
|
16
|
+
const n = this.targetElement;
|
|
17
|
+
if (n) {
|
|
18
|
+
const o = getComputedStyle(n).fontFamily;
|
|
19
|
+
this.fontFamily.value = o;
|
|
256
20
|
}
|
|
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
|
|
21
|
+
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"), this.applyRange(this.fontSize, "font-size-min", "font-size-max"), this.applyRange(this.letterSpacing, "letter-spacing-min", "letter-spacing-max"), this.applyRange(this.wordSpacing, "word-spacing-min", "word-spacing-max"), this.applyRange(this.lineHeight, "line-height-min", "line-height-max"), this.applyRange(this.contrast, "contrast-min", "contrast-max");
|
|
22
|
+
const e = () => {
|
|
259
23
|
this.update(), this.dispatchEvent(
|
|
260
24
|
new CustomEvent("change", {
|
|
261
25
|
detail: this.getValues(),
|
|
@@ -264,18 +28,18 @@ let r = class extends HTMLElement {
|
|
|
264
28
|
})
|
|
265
29
|
);
|
|
266
30
|
};
|
|
267
|
-
this.fontSize.addEventListener("input",
|
|
31
|
+
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.bindSlider(this.fontSize, this.fontSizeValue, "Font size"), this.bindSlider(this.letterSpacing, this.letterSpacingValue, "Letter spacing"), this.bindSlider(this.wordSpacing, this.wordSpacingValue, "Word spacing"), this.bindSlider(this.lineHeight, this.lineHeightValue, "Line height"), this.bindSlider(this.contrast, this.contrastValue, "Contrast"), this.update();
|
|
268
32
|
}
|
|
269
|
-
toggleGroup(
|
|
270
|
-
const
|
|
271
|
-
|
|
33
|
+
toggleGroup(t, i) {
|
|
34
|
+
const n = this.shadowRoot.querySelector(t);
|
|
35
|
+
n && (n.style.display = i ? "block" : "none");
|
|
272
36
|
}
|
|
273
37
|
get targetElement() {
|
|
274
38
|
return document.querySelector(this.targetSelector);
|
|
275
39
|
}
|
|
276
40
|
update() {
|
|
277
|
-
const
|
|
278
|
-
|
|
41
|
+
const t = this.targetElement;
|
|
42
|
+
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}%`);
|
|
279
43
|
}
|
|
280
44
|
getValues() {
|
|
281
45
|
return {
|
|
@@ -287,22 +51,40 @@ let r = class extends HTMLElement {
|
|
|
287
51
|
fontFamily: this.fontFamily.value
|
|
288
52
|
};
|
|
289
53
|
}
|
|
290
|
-
setValues(
|
|
291
|
-
if (
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
54
|
+
setValues(t = {}) {
|
|
55
|
+
if (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) {
|
|
56
|
+
const i = this.targetElement;
|
|
57
|
+
if (t.fontFamily === "inherit" && i) {
|
|
58
|
+
const n = getComputedStyle(i).fontFamily;
|
|
59
|
+
this.fontFamily.value = n;
|
|
295
60
|
} else
|
|
296
|
-
this.fontFamily.value =
|
|
61
|
+
this.fontFamily.value = t.fontFamily;
|
|
62
|
+
}
|
|
297
63
|
this.update();
|
|
298
64
|
}
|
|
299
|
-
setFeatures(
|
|
300
|
-
|
|
65
|
+
setFeatures(t = {}) {
|
|
66
|
+
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", "")), t.fontFamily !== void 0 && (this.toggleGroup("#groupFontFamily", t.fontFamily), t.fontFamily ? this.removeAttribute("hide-font-family") : this.setAttribute("hide-font-family", ""));
|
|
67
|
+
}
|
|
68
|
+
bindSlider(t, i, n) {
|
|
69
|
+
i.textContent = t.value, t.addEventListener("input", () => {
|
|
70
|
+
const e = t.value;
|
|
71
|
+
i.textContent = e, t.setAttribute("aria-valuenow", e), this.update(), this.dispatchEvent(
|
|
72
|
+
new CustomEvent("change", {
|
|
73
|
+
detail: this.getValues(),
|
|
74
|
+
bubbles: !0,
|
|
75
|
+
composed: !0
|
|
76
|
+
})
|
|
77
|
+
);
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
applyRange(t, i, n) {
|
|
81
|
+
const e = this.getAttribute(i), o = this.getAttribute(n);
|
|
82
|
+
e !== null && (t.min = e, t.setAttribute("aria-valuemin", e)), o !== null && (t.max = o, t.setAttribute("aria-valuemax", o));
|
|
301
83
|
}
|
|
302
84
|
};
|
|
303
85
|
customElements.define("typography-controller", r);
|
|
304
86
|
const p = a({
|
|
305
|
-
react:
|
|
87
|
+
react: s,
|
|
306
88
|
tagName: "typography-controller",
|
|
307
89
|
elementClass: customElements.get("typography-controller"),
|
|
308
90
|
events: {
|