uni-theme-select 1.0.2 → 1.0.4
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/index.js +130 -29
- package/dist/index.mjs +130 -29
- package/package.json +29 -29
package/dist/index.js
CHANGED
|
@@ -121,25 +121,45 @@ var ThemeStore = class {
|
|
|
121
121
|
};
|
|
122
122
|
var themeStore = new ThemeStore();
|
|
123
123
|
|
|
124
|
-
// src/
|
|
125
|
-
var
|
|
124
|
+
// src/constants.ts
|
|
125
|
+
var fontOptions = [
|
|
126
|
+
// Modern Sans
|
|
127
|
+
{ name: "Inter", value: "'Inter', sans-serif" },
|
|
128
|
+
{ name: "Space Grotesk", value: "'Space Grotesk', sans-serif" },
|
|
129
|
+
{ name: "Manrope", value: "'Manrope', sans-serif" },
|
|
130
|
+
// Serif
|
|
131
|
+
{ name: "Merriweather", value: "'Merriweather', serif" },
|
|
132
|
+
{ name: "Libre Baskerville", value: "'Libre Baskerville', serif" },
|
|
133
|
+
{ name: "Cormorant Garamond", value: "'Cormorant Garamond', serif" },
|
|
134
|
+
// Slab
|
|
135
|
+
{ name: "Roboto Slab", value: "'Roboto Slab', serif" },
|
|
136
|
+
{ name: "Arvo", value: "'Arvo', serif" },
|
|
137
|
+
// Display / Branding
|
|
138
|
+
{ name: "Abril Fatface", value: "'Abril Fatface', cursive" },
|
|
139
|
+
{ name: "Righteous", value: "'Righteous', cursive" },
|
|
140
|
+
{ name: "Fantasy", value: "fantasy" },
|
|
141
|
+
{ name: "Monospace", value: "monospace" }
|
|
142
|
+
];
|
|
143
|
+
var formFields = [
|
|
126
144
|
{ id: "bg-color", label: "Background Color", defaultValue: "#fff", type: "text", class: "radius-50" },
|
|
127
145
|
{ id: "primary-button-color", label: "Primary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
|
|
128
146
|
{ id: "primary-button-border-color", label: "Primary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
|
|
129
|
-
{ id: "primary-button-border-radius", label: "Primary Button Border Radius", defaultValue: "0", type: "text", units: ["px", "%", "em"] },
|
|
147
|
+
{ id: "primary-button-border-radius", label: "Primary Button Border Radius", defaultValue: "0", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
130
148
|
{ id: "primary-button-text-color", label: "Primary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
131
149
|
{ id: "secondary-button-color", label: "Secondary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
|
|
132
150
|
{ id: "secondary-button-border-color", label: "Secondary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
|
|
133
|
-
{ id: "secondary-button-border-radius", label: "Secondary Button Border Radius", defaultValue: "0", type: "text", units: ["px", "%", "em"] },
|
|
151
|
+
{ id: "secondary-button-border-radius", label: "Secondary Button Border Radius", defaultValue: "0", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
134
152
|
{ id: "secondary-button-text-color", label: "Secondary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
135
|
-
{ id: "font-family", label: "Font Family", defaultValue: "", type: "
|
|
136
|
-
{ id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "text", units: ["px", "%", "em"] },
|
|
153
|
+
{ id: "font-family", label: "Font Family", defaultValue: "", type: "select", options: fontOptions, class: "font-family-input" },
|
|
154
|
+
{ id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
137
155
|
{ id: "primary-font-color", label: "Primary Font Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
138
|
-
{ id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text" },
|
|
139
|
-
{ id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "text", units: ["px", "%", "em"] },
|
|
156
|
+
{ id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text", class: "uni-text-input" },
|
|
157
|
+
{ id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
140
158
|
{ id: "secondary-font-color", label: "Secondary Font Color", defaultValue: "#ccc", type: "text", class: "radius-50" },
|
|
141
|
-
{ id: "secondary-font-weight", label: "
|
|
159
|
+
{ id: "secondary-font-weight", label: "Secondary Font Weight", defaultValue: "500", type: "text", class: "uni-text-input" }
|
|
142
160
|
];
|
|
161
|
+
|
|
162
|
+
// src/coreFunctions.ts
|
|
143
163
|
function injectStyles() {
|
|
144
164
|
if (document.getElementById("uni-theme-style")) return;
|
|
145
165
|
const style = document.createElement("style");
|
|
@@ -195,6 +215,8 @@ function injectStyles() {
|
|
|
195
215
|
|
|
196
216
|
#uni-theme-root.opened #uni-theme-panel{
|
|
197
217
|
right: 0;
|
|
218
|
+
overflow: scroll;
|
|
219
|
+
max-height: 600px;
|
|
198
220
|
}
|
|
199
221
|
|
|
200
222
|
#uni-theme-root.opened #uni-theme-toggle{
|
|
@@ -225,6 +247,7 @@ function injectStyles() {
|
|
|
225
247
|
justify-content: space-between;
|
|
226
248
|
margin-bottom: 14px;
|
|
227
249
|
gap: 12px;
|
|
250
|
+
text-align: left;
|
|
228
251
|
}
|
|
229
252
|
|
|
230
253
|
.uni-input-group label {
|
|
@@ -234,12 +257,19 @@ function injectStyles() {
|
|
|
234
257
|
}
|
|
235
258
|
|
|
236
259
|
.uni-input {
|
|
237
|
-
width:
|
|
238
|
-
height:
|
|
260
|
+
width: 30px;
|
|
261
|
+
height: 30px;
|
|
239
262
|
border: 2px solid #ddd;
|
|
240
263
|
cursor: pointer;
|
|
241
264
|
padding: 0;
|
|
242
265
|
}
|
|
266
|
+
.font-family-input{
|
|
267
|
+
width: 100px;
|
|
268
|
+
}
|
|
269
|
+
.uni-text-input{
|
|
270
|
+
width: 50px;
|
|
271
|
+
height: 19px;
|
|
272
|
+
}
|
|
243
273
|
.radius-50{
|
|
244
274
|
border-radius:50%
|
|
245
275
|
}
|
|
@@ -275,34 +305,64 @@ function setTheme(name, customProps = {}) {
|
|
|
275
305
|
function constructPanel(container) {
|
|
276
306
|
const panel = document.createElement("div");
|
|
277
307
|
panel.id = "uni-theme-panel";
|
|
308
|
+
const selectThemes = document.createElement("select");
|
|
309
|
+
selectThemes.id = "available-themes";
|
|
310
|
+
selectThemes.innerHTML = `
|
|
311
|
+
<option value="">Select theme</option>
|
|
312
|
+
<option value="beige">Beige</option>
|
|
313
|
+
<option value="dark">Dark</option>
|
|
314
|
+
<option value="light">Light</option>
|
|
315
|
+
<option value="custom">Custom</option>
|
|
316
|
+
`;
|
|
317
|
+
panel.appendChild(selectThemes);
|
|
318
|
+
const customThemePanel = document.createElement("div");
|
|
319
|
+
customThemePanel.id = "csutom-theme-panel";
|
|
320
|
+
customThemePanel.style.display = "none";
|
|
278
321
|
const title = document.createElement("h3");
|
|
279
322
|
title.textContent = "Select Custom Theme";
|
|
280
|
-
|
|
281
|
-
|
|
323
|
+
customThemePanel.appendChild(title);
|
|
324
|
+
formFields.forEach((field) => {
|
|
282
325
|
const group = document.createElement("div");
|
|
283
326
|
group.className = "uni-input-group";
|
|
284
327
|
const label = document.createElement("label");
|
|
285
328
|
label.textContent = field.label;
|
|
286
|
-
const input = document.createElement("input");
|
|
287
|
-
input.type = field.type;
|
|
288
|
-
input.name = field.id;
|
|
289
|
-
input.className = `uni-input ${field.class}`;
|
|
290
|
-
input.id = `uni-theme-${field.id}`;
|
|
291
|
-
input.value = field.defaultValue;
|
|
292
329
|
group.appendChild(label);
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
330
|
+
if (field.options && field.options.length > 0) {
|
|
331
|
+
const inputSelect = document.createElement("select");
|
|
332
|
+
inputSelect.name = field.id;
|
|
333
|
+
inputSelect.className = `uni-input ${field.class}`;
|
|
334
|
+
inputSelect.id = `uni-theme-${field.id}`;
|
|
335
|
+
inputSelect.value = field.defaultValue;
|
|
336
|
+
field.options.forEach((option) => {
|
|
337
|
+
const op = document.createElement("option");
|
|
338
|
+
op.value = option.value;
|
|
339
|
+
op.textContent = option.name;
|
|
340
|
+
inputSelect.appendChild(op);
|
|
301
341
|
});
|
|
302
|
-
group.appendChild(
|
|
342
|
+
group.appendChild(inputSelect);
|
|
343
|
+
} else {
|
|
344
|
+
const input = document.createElement("input");
|
|
345
|
+
input.type = field.type;
|
|
346
|
+
input.name = field.id;
|
|
347
|
+
input.className = `uni-input ${field.class}`;
|
|
348
|
+
input.id = `uni-theme-${field.id}`;
|
|
349
|
+
input.value = field.defaultValue;
|
|
350
|
+
group.appendChild(input);
|
|
351
|
+
if (field.units && field.units.length > 0) {
|
|
352
|
+
const inputUnits = document.createElement("select");
|
|
353
|
+
inputUnits.disabled = true;
|
|
354
|
+
field.units.forEach((unit) => {
|
|
355
|
+
const option = document.createElement("option");
|
|
356
|
+
option.value = unit;
|
|
357
|
+
option.textContent = unit;
|
|
358
|
+
inputUnits.appendChild(option);
|
|
359
|
+
});
|
|
360
|
+
group.appendChild(inputUnits);
|
|
361
|
+
}
|
|
303
362
|
}
|
|
304
|
-
|
|
363
|
+
customThemePanel.appendChild(group);
|
|
305
364
|
});
|
|
365
|
+
panel.appendChild(customThemePanel);
|
|
306
366
|
container.appendChild(panel);
|
|
307
367
|
}
|
|
308
368
|
function injectHTML(options = {}) {
|
|
@@ -336,8 +396,34 @@ function initThemeElements() {
|
|
|
336
396
|
setTheme(currentTheme.themeName, currentTheme.properties);
|
|
337
397
|
});
|
|
338
398
|
});
|
|
399
|
+
const availableThemes = document.getElementById("available-themes");
|
|
400
|
+
availableThemes == null ? void 0 : availableThemes.addEventListener("change", (e) => {
|
|
401
|
+
var _a;
|
|
402
|
+
const selectedTheme = (_a = e.target) == null ? void 0 : _a.value;
|
|
403
|
+
const props = themes.find((item) => item.name == selectedTheme);
|
|
404
|
+
setTheme(selectedTheme, props == null ? void 0 : props.properties);
|
|
405
|
+
});
|
|
406
|
+
const fontSelect = document.getElementById("uni-theme-font-family");
|
|
407
|
+
fontSelect == null ? void 0 : fontSelect.addEventListener("change", (e) => {
|
|
408
|
+
var _a;
|
|
409
|
+
const selectedFont = (_a = e.target) == null ? void 0 : _a.value;
|
|
410
|
+
if (!selectedFont) return;
|
|
411
|
+
loadGoogleFonts(selectedFont);
|
|
412
|
+
document.body.style.fontFamily = selectedFont;
|
|
413
|
+
localStorage.setItem("selectFont", selectedFont);
|
|
414
|
+
});
|
|
339
415
|
return { themeToggler, themePanel };
|
|
340
416
|
}
|
|
417
|
+
var loadGoogleFonts = (font) => {
|
|
418
|
+
const linkId = "dynamic-font-link";
|
|
419
|
+
const existingLink = document.getElementById(linkId);
|
|
420
|
+
if (existingLink) existingLink.remove();
|
|
421
|
+
const linkHTML = document.createElement("link");
|
|
422
|
+
linkHTML.id = linkId;
|
|
423
|
+
linkHTML.rel = "stylesheet";
|
|
424
|
+
linkHTML.href = `https://fonts.googleapis.com/css2/?faimly=${font.replace(/ /g, "+")}wght@400;500;600;700&display=swap`;
|
|
425
|
+
document.head.appendChild(linkHTML);
|
|
426
|
+
};
|
|
341
427
|
|
|
342
428
|
// src/themeManager.ts
|
|
343
429
|
function getAvailableThemes() {
|
|
@@ -352,6 +438,21 @@ function loadSavedTheme() {
|
|
|
352
438
|
} else {
|
|
353
439
|
setTheme(parsed.name);
|
|
354
440
|
}
|
|
441
|
+
window.addEventListener("DOMContentLoaded", () => {
|
|
442
|
+
const savedFont = localStorage.getItem("selectedFont");
|
|
443
|
+
if (savedFont) {
|
|
444
|
+
loadGoogleFonts(savedFont);
|
|
445
|
+
const fontObj = fontOptions.find((f) => f.name === savedFont);
|
|
446
|
+
if (fontObj) {
|
|
447
|
+
document.body.style.fontFamily = fontObj.value;
|
|
448
|
+
const fontSelector = document.querySelector(
|
|
449
|
+
"#uni-theme-font-family"
|
|
450
|
+
);
|
|
451
|
+
if (!fontSelector) return;
|
|
452
|
+
fontSelector.value = fontObj.value;
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
});
|
|
355
456
|
}
|
|
356
457
|
function mountToggleTheme(options = {}) {
|
|
357
458
|
injectStyles();
|
package/dist/index.mjs
CHANGED
|
@@ -81,25 +81,45 @@ var ThemeStore = class {
|
|
|
81
81
|
};
|
|
82
82
|
var themeStore = new ThemeStore();
|
|
83
83
|
|
|
84
|
-
// src/
|
|
85
|
-
var
|
|
84
|
+
// src/constants.ts
|
|
85
|
+
var fontOptions = [
|
|
86
|
+
// Modern Sans
|
|
87
|
+
{ name: "Inter", value: "'Inter', sans-serif" },
|
|
88
|
+
{ name: "Space Grotesk", value: "'Space Grotesk', sans-serif" },
|
|
89
|
+
{ name: "Manrope", value: "'Manrope', sans-serif" },
|
|
90
|
+
// Serif
|
|
91
|
+
{ name: "Merriweather", value: "'Merriweather', serif" },
|
|
92
|
+
{ name: "Libre Baskerville", value: "'Libre Baskerville', serif" },
|
|
93
|
+
{ name: "Cormorant Garamond", value: "'Cormorant Garamond', serif" },
|
|
94
|
+
// Slab
|
|
95
|
+
{ name: "Roboto Slab", value: "'Roboto Slab', serif" },
|
|
96
|
+
{ name: "Arvo", value: "'Arvo', serif" },
|
|
97
|
+
// Display / Branding
|
|
98
|
+
{ name: "Abril Fatface", value: "'Abril Fatface', cursive" },
|
|
99
|
+
{ name: "Righteous", value: "'Righteous', cursive" },
|
|
100
|
+
{ name: "Fantasy", value: "fantasy" },
|
|
101
|
+
{ name: "Monospace", value: "monospace" }
|
|
102
|
+
];
|
|
103
|
+
var formFields = [
|
|
86
104
|
{ id: "bg-color", label: "Background Color", defaultValue: "#fff", type: "text", class: "radius-50" },
|
|
87
105
|
{ id: "primary-button-color", label: "Primary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
|
|
88
106
|
{ id: "primary-button-border-color", label: "Primary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
|
|
89
|
-
{ id: "primary-button-border-radius", label: "Primary Button Border Radius", defaultValue: "0", type: "text", units: ["px", "%", "em"] },
|
|
107
|
+
{ id: "primary-button-border-radius", label: "Primary Button Border Radius", defaultValue: "0", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
90
108
|
{ id: "primary-button-text-color", label: "Primary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
91
109
|
{ id: "secondary-button-color", label: "Secondary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
|
|
92
110
|
{ id: "secondary-button-border-color", label: "Secondary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
|
|
93
|
-
{ id: "secondary-button-border-radius", label: "Secondary Button Border Radius", defaultValue: "0", type: "text", units: ["px", "%", "em"] },
|
|
111
|
+
{ id: "secondary-button-border-radius", label: "Secondary Button Border Radius", defaultValue: "0", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
94
112
|
{ id: "secondary-button-text-color", label: "Secondary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
95
|
-
{ id: "font-family", label: "Font Family", defaultValue: "", type: "
|
|
96
|
-
{ id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "text", units: ["px", "%", "em"] },
|
|
113
|
+
{ id: "font-family", label: "Font Family", defaultValue: "", type: "select", options: fontOptions, class: "font-family-input" },
|
|
114
|
+
{ id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
97
115
|
{ id: "primary-font-color", label: "Primary Font Color", defaultValue: "#000", type: "text", class: "radius-50" },
|
|
98
|
-
{ id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text" },
|
|
99
|
-
{ id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "text", units: ["px", "%", "em"] },
|
|
116
|
+
{ id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text", class: "uni-text-input" },
|
|
117
|
+
{ id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
|
|
100
118
|
{ id: "secondary-font-color", label: "Secondary Font Color", defaultValue: "#ccc", type: "text", class: "radius-50" },
|
|
101
|
-
{ id: "secondary-font-weight", label: "
|
|
119
|
+
{ id: "secondary-font-weight", label: "Secondary Font Weight", defaultValue: "500", type: "text", class: "uni-text-input" }
|
|
102
120
|
];
|
|
121
|
+
|
|
122
|
+
// src/coreFunctions.ts
|
|
103
123
|
function injectStyles() {
|
|
104
124
|
if (document.getElementById("uni-theme-style")) return;
|
|
105
125
|
const style = document.createElement("style");
|
|
@@ -155,6 +175,8 @@ function injectStyles() {
|
|
|
155
175
|
|
|
156
176
|
#uni-theme-root.opened #uni-theme-panel{
|
|
157
177
|
right: 0;
|
|
178
|
+
overflow: scroll;
|
|
179
|
+
max-height: 600px;
|
|
158
180
|
}
|
|
159
181
|
|
|
160
182
|
#uni-theme-root.opened #uni-theme-toggle{
|
|
@@ -185,6 +207,7 @@ function injectStyles() {
|
|
|
185
207
|
justify-content: space-between;
|
|
186
208
|
margin-bottom: 14px;
|
|
187
209
|
gap: 12px;
|
|
210
|
+
text-align: left;
|
|
188
211
|
}
|
|
189
212
|
|
|
190
213
|
.uni-input-group label {
|
|
@@ -194,12 +217,19 @@ function injectStyles() {
|
|
|
194
217
|
}
|
|
195
218
|
|
|
196
219
|
.uni-input {
|
|
197
|
-
width:
|
|
198
|
-
height:
|
|
220
|
+
width: 30px;
|
|
221
|
+
height: 30px;
|
|
199
222
|
border: 2px solid #ddd;
|
|
200
223
|
cursor: pointer;
|
|
201
224
|
padding: 0;
|
|
202
225
|
}
|
|
226
|
+
.font-family-input{
|
|
227
|
+
width: 100px;
|
|
228
|
+
}
|
|
229
|
+
.uni-text-input{
|
|
230
|
+
width: 50px;
|
|
231
|
+
height: 19px;
|
|
232
|
+
}
|
|
203
233
|
.radius-50{
|
|
204
234
|
border-radius:50%
|
|
205
235
|
}
|
|
@@ -235,34 +265,64 @@ function setTheme(name, customProps = {}) {
|
|
|
235
265
|
function constructPanel(container) {
|
|
236
266
|
const panel = document.createElement("div");
|
|
237
267
|
panel.id = "uni-theme-panel";
|
|
268
|
+
const selectThemes = document.createElement("select");
|
|
269
|
+
selectThemes.id = "available-themes";
|
|
270
|
+
selectThemes.innerHTML = `
|
|
271
|
+
<option value="">Select theme</option>
|
|
272
|
+
<option value="beige">Beige</option>
|
|
273
|
+
<option value="dark">Dark</option>
|
|
274
|
+
<option value="light">Light</option>
|
|
275
|
+
<option value="custom">Custom</option>
|
|
276
|
+
`;
|
|
277
|
+
panel.appendChild(selectThemes);
|
|
278
|
+
const customThemePanel = document.createElement("div");
|
|
279
|
+
customThemePanel.id = "csutom-theme-panel";
|
|
280
|
+
customThemePanel.style.display = "none";
|
|
238
281
|
const title = document.createElement("h3");
|
|
239
282
|
title.textContent = "Select Custom Theme";
|
|
240
|
-
|
|
241
|
-
|
|
283
|
+
customThemePanel.appendChild(title);
|
|
284
|
+
formFields.forEach((field) => {
|
|
242
285
|
const group = document.createElement("div");
|
|
243
286
|
group.className = "uni-input-group";
|
|
244
287
|
const label = document.createElement("label");
|
|
245
288
|
label.textContent = field.label;
|
|
246
|
-
const input = document.createElement("input");
|
|
247
|
-
input.type = field.type;
|
|
248
|
-
input.name = field.id;
|
|
249
|
-
input.className = `uni-input ${field.class}`;
|
|
250
|
-
input.id = `uni-theme-${field.id}`;
|
|
251
|
-
input.value = field.defaultValue;
|
|
252
289
|
group.appendChild(label);
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
290
|
+
if (field.options && field.options.length > 0) {
|
|
291
|
+
const inputSelect = document.createElement("select");
|
|
292
|
+
inputSelect.name = field.id;
|
|
293
|
+
inputSelect.className = `uni-input ${field.class}`;
|
|
294
|
+
inputSelect.id = `uni-theme-${field.id}`;
|
|
295
|
+
inputSelect.value = field.defaultValue;
|
|
296
|
+
field.options.forEach((option) => {
|
|
297
|
+
const op = document.createElement("option");
|
|
298
|
+
op.value = option.value;
|
|
299
|
+
op.textContent = option.name;
|
|
300
|
+
inputSelect.appendChild(op);
|
|
261
301
|
});
|
|
262
|
-
group.appendChild(
|
|
302
|
+
group.appendChild(inputSelect);
|
|
303
|
+
} else {
|
|
304
|
+
const input = document.createElement("input");
|
|
305
|
+
input.type = field.type;
|
|
306
|
+
input.name = field.id;
|
|
307
|
+
input.className = `uni-input ${field.class}`;
|
|
308
|
+
input.id = `uni-theme-${field.id}`;
|
|
309
|
+
input.value = field.defaultValue;
|
|
310
|
+
group.appendChild(input);
|
|
311
|
+
if (field.units && field.units.length > 0) {
|
|
312
|
+
const inputUnits = document.createElement("select");
|
|
313
|
+
inputUnits.disabled = true;
|
|
314
|
+
field.units.forEach((unit) => {
|
|
315
|
+
const option = document.createElement("option");
|
|
316
|
+
option.value = unit;
|
|
317
|
+
option.textContent = unit;
|
|
318
|
+
inputUnits.appendChild(option);
|
|
319
|
+
});
|
|
320
|
+
group.appendChild(inputUnits);
|
|
321
|
+
}
|
|
263
322
|
}
|
|
264
|
-
|
|
323
|
+
customThemePanel.appendChild(group);
|
|
265
324
|
});
|
|
325
|
+
panel.appendChild(customThemePanel);
|
|
266
326
|
container.appendChild(panel);
|
|
267
327
|
}
|
|
268
328
|
function injectHTML(options = {}) {
|
|
@@ -296,8 +356,34 @@ function initThemeElements() {
|
|
|
296
356
|
setTheme(currentTheme.themeName, currentTheme.properties);
|
|
297
357
|
});
|
|
298
358
|
});
|
|
359
|
+
const availableThemes = document.getElementById("available-themes");
|
|
360
|
+
availableThemes == null ? void 0 : availableThemes.addEventListener("change", (e) => {
|
|
361
|
+
var _a;
|
|
362
|
+
const selectedTheme = (_a = e.target) == null ? void 0 : _a.value;
|
|
363
|
+
const props = themes.find((item) => item.name == selectedTheme);
|
|
364
|
+
setTheme(selectedTheme, props == null ? void 0 : props.properties);
|
|
365
|
+
});
|
|
366
|
+
const fontSelect = document.getElementById("uni-theme-font-family");
|
|
367
|
+
fontSelect == null ? void 0 : fontSelect.addEventListener("change", (e) => {
|
|
368
|
+
var _a;
|
|
369
|
+
const selectedFont = (_a = e.target) == null ? void 0 : _a.value;
|
|
370
|
+
if (!selectedFont) return;
|
|
371
|
+
loadGoogleFonts(selectedFont);
|
|
372
|
+
document.body.style.fontFamily = selectedFont;
|
|
373
|
+
localStorage.setItem("selectFont", selectedFont);
|
|
374
|
+
});
|
|
299
375
|
return { themeToggler, themePanel };
|
|
300
376
|
}
|
|
377
|
+
var loadGoogleFonts = (font) => {
|
|
378
|
+
const linkId = "dynamic-font-link";
|
|
379
|
+
const existingLink = document.getElementById(linkId);
|
|
380
|
+
if (existingLink) existingLink.remove();
|
|
381
|
+
const linkHTML = document.createElement("link");
|
|
382
|
+
linkHTML.id = linkId;
|
|
383
|
+
linkHTML.rel = "stylesheet";
|
|
384
|
+
linkHTML.href = `https://fonts.googleapis.com/css2/?faimly=${font.replace(/ /g, "+")}wght@400;500;600;700&display=swap`;
|
|
385
|
+
document.head.appendChild(linkHTML);
|
|
386
|
+
};
|
|
301
387
|
|
|
302
388
|
// src/themeManager.ts
|
|
303
389
|
function getAvailableThemes() {
|
|
@@ -312,6 +398,21 @@ function loadSavedTheme() {
|
|
|
312
398
|
} else {
|
|
313
399
|
setTheme(parsed.name);
|
|
314
400
|
}
|
|
401
|
+
window.addEventListener("DOMContentLoaded", () => {
|
|
402
|
+
const savedFont = localStorage.getItem("selectedFont");
|
|
403
|
+
if (savedFont) {
|
|
404
|
+
loadGoogleFonts(savedFont);
|
|
405
|
+
const fontObj = fontOptions.find((f) => f.name === savedFont);
|
|
406
|
+
if (fontObj) {
|
|
407
|
+
document.body.style.fontFamily = fontObj.value;
|
|
408
|
+
const fontSelector = document.querySelector(
|
|
409
|
+
"#uni-theme-font-family"
|
|
410
|
+
);
|
|
411
|
+
if (!fontSelector) return;
|
|
412
|
+
fontSelector.value = fontObj.value;
|
|
413
|
+
}
|
|
414
|
+
}
|
|
415
|
+
});
|
|
315
416
|
}
|
|
316
417
|
function mountToggleTheme(options = {}) {
|
|
317
418
|
injectStyles();
|
package/package.json
CHANGED
|
@@ -1,29 +1,29 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "uni-theme-select",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "Framework-agnostic theme switcher",
|
|
5
|
-
"main": "dist/index.js",
|
|
6
|
-
"module": "dist/index.mjs",
|
|
7
|
-
"types": "dist/index.d.ts",
|
|
8
|
-
"files": [
|
|
9
|
-
"dist"
|
|
10
|
-
],
|
|
11
|
-
"scripts": {
|
|
12
|
-
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
13
|
-
"dev": "tsup src/index.ts --format cjs,esm --watch --dts"
|
|
14
|
-
},
|
|
15
|
-
"keywords": [
|
|
16
|
-
"theme",
|
|
17
|
-
"dark-mode",
|
|
18
|
-
"css-variables"
|
|
19
|
-
],
|
|
20
|
-
"author": "sri_manohari",
|
|
21
|
-
"license": "ISC",
|
|
22
|
-
"devDependencies": {
|
|
23
|
-
"tsup": "^8.5.1",
|
|
24
|
-
"typescript": "^5.9.3"
|
|
25
|
-
},
|
|
26
|
-
"dependencies": {
|
|
27
|
-
"@melloware/coloris": "^0.25.0"
|
|
28
|
-
}
|
|
29
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "uni-theme-select",
|
|
3
|
+
"version": "1.0.4",
|
|
4
|
+
"description": "Framework-agnostic theme switcher",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"files": [
|
|
9
|
+
"dist"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsup src/index.ts --format cjs,esm --dts",
|
|
13
|
+
"dev": "tsup src/index.ts --format cjs,esm --watch --dts"
|
|
14
|
+
},
|
|
15
|
+
"keywords": [
|
|
16
|
+
"theme",
|
|
17
|
+
"dark-mode",
|
|
18
|
+
"css-variables"
|
|
19
|
+
],
|
|
20
|
+
"author": "sri_manohari",
|
|
21
|
+
"license": "ISC",
|
|
22
|
+
"devDependencies": {
|
|
23
|
+
"tsup": "^8.5.1",
|
|
24
|
+
"typescript": "^5.9.3"
|
|
25
|
+
},
|
|
26
|
+
"dependencies": {
|
|
27
|
+
"@melloware/coloris": "^0.25.0"
|
|
28
|
+
}
|
|
29
|
+
}
|