uni-theme-select 1.0.3 → 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.
Files changed (3) hide show
  1. package/dist/index.js +102 -25
  2. package/dist/index.mjs +102 -25
  3. package/package.json +29 -29
package/dist/index.js CHANGED
@@ -121,8 +121,26 @@ var ThemeStore = class {
121
121
  };
122
122
  var themeStore = new ThemeStore();
123
123
 
124
- // src/coreFunctions.ts
125
- var colorFields = [
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" },
@@ -132,14 +150,16 @@ var colorFields = [
132
150
  { id: "secondary-button-border-color", label: "Secondary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
133
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: "text" },
153
+ { id: "font-family", label: "Font Family", defaultValue: "", type: "select", options: fontOptions, class: "font-family-input" },
136
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
156
  { id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text", class: "uni-text-input" },
139
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: "Primary Font Weight", defaultValue: "500", type: "text", class: "uni-text-input" }
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");
@@ -243,6 +263,9 @@ function injectStyles() {
243
263
  cursor: pointer;
244
264
  padding: 0;
245
265
  }
266
+ .font-family-input{
267
+ width: 100px;
268
+ }
246
269
  .uni-text-input{
247
270
  width: 50px;
248
271
  height: 19px;
@@ -282,8 +305,6 @@ function setTheme(name, customProps = {}) {
282
305
  function constructPanel(container) {
283
306
  const panel = document.createElement("div");
284
307
  panel.id = "uni-theme-panel";
285
- const title = document.createElement("h3");
286
- title.textContent = "Select Custom Theme";
287
308
  const selectThemes = document.createElement("select");
288
309
  selectThemes.id = "available-themes";
289
310
  selectThemes.innerHTML = `
@@ -291,35 +312,57 @@ function constructPanel(container) {
291
312
  <option value="beige">Beige</option>
292
313
  <option value="dark">Dark</option>
293
314
  <option value="light">Light</option>
315
+ <option value="custom">Custom</option>
294
316
  `;
295
- panel.appendChild(title);
296
317
  panel.appendChild(selectThemes);
297
- colorFields.forEach((field) => {
318
+ const customThemePanel = document.createElement("div");
319
+ customThemePanel.id = "csutom-theme-panel";
320
+ customThemePanel.style.display = "none";
321
+ const title = document.createElement("h3");
322
+ title.textContent = "Select Custom Theme";
323
+ customThemePanel.appendChild(title);
324
+ formFields.forEach((field) => {
298
325
  const group = document.createElement("div");
299
326
  group.className = "uni-input-group";
300
327
  const label = document.createElement("label");
301
328
  label.textContent = field.label;
302
- const input = document.createElement("input");
303
- input.type = field.type;
304
- input.name = field.id;
305
- input.className = `uni-input ${field.class}`;
306
- input.id = `uni-theme-${field.id}`;
307
- input.value = field.defaultValue;
308
329
  group.appendChild(label);
309
- group.appendChild(input);
310
- if (field.units && field.units.length > 0) {
311
- const inputUnits = document.createElement("select");
312
- inputUnits.disabled = true;
313
- field.units.forEach((unit) => {
314
- const option = document.createElement("option");
315
- option.value = unit;
316
- option.textContent = unit;
317
- inputUnits.appendChild(option);
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);
318
341
  });
319
- group.appendChild(inputUnits);
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
+ }
320
362
  }
321
- panel.appendChild(group);
363
+ customThemePanel.appendChild(group);
322
364
  });
365
+ panel.appendChild(customThemePanel);
323
366
  container.appendChild(panel);
324
367
  }
325
368
  function injectHTML(options = {}) {
@@ -360,8 +403,27 @@ function initThemeElements() {
360
403
  const props = themes.find((item) => item.name == selectedTheme);
361
404
  setTheme(selectedTheme, props == null ? void 0 : props.properties);
362
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
+ });
363
415
  return { themeToggler, themePanel };
364
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
+ };
365
427
 
366
428
  // src/themeManager.ts
367
429
  function getAvailableThemes() {
@@ -376,6 +438,21 @@ function loadSavedTheme() {
376
438
  } else {
377
439
  setTheme(parsed.name);
378
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
+ });
379
456
  }
380
457
  function mountToggleTheme(options = {}) {
381
458
  injectStyles();
package/dist/index.mjs CHANGED
@@ -81,8 +81,26 @@ var ThemeStore = class {
81
81
  };
82
82
  var themeStore = new ThemeStore();
83
83
 
84
- // src/coreFunctions.ts
85
- var colorFields = [
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" },
@@ -92,14 +110,16 @@ var colorFields = [
92
110
  { id: "secondary-button-border-color", label: "Secondary Button Border Color", defaultValue: "rgba(0, 0, 0, 0)", type: "text", class: "radius-50" },
93
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: "text" },
113
+ { id: "font-family", label: "Font Family", defaultValue: "", type: "select", options: fontOptions, class: "font-family-input" },
96
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
116
  { id: "primary-font-weight", label: "Primary Font Weight", defaultValue: "600", type: "text", class: "uni-text-input" },
99
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: "Primary Font Weight", defaultValue: "500", type: "text", class: "uni-text-input" }
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");
@@ -203,6 +223,9 @@ function injectStyles() {
203
223
  cursor: pointer;
204
224
  padding: 0;
205
225
  }
226
+ .font-family-input{
227
+ width: 100px;
228
+ }
206
229
  .uni-text-input{
207
230
  width: 50px;
208
231
  height: 19px;
@@ -242,8 +265,6 @@ function setTheme(name, customProps = {}) {
242
265
  function constructPanel(container) {
243
266
  const panel = document.createElement("div");
244
267
  panel.id = "uni-theme-panel";
245
- const title = document.createElement("h3");
246
- title.textContent = "Select Custom Theme";
247
268
  const selectThemes = document.createElement("select");
248
269
  selectThemes.id = "available-themes";
249
270
  selectThemes.innerHTML = `
@@ -251,35 +272,57 @@ function constructPanel(container) {
251
272
  <option value="beige">Beige</option>
252
273
  <option value="dark">Dark</option>
253
274
  <option value="light">Light</option>
275
+ <option value="custom">Custom</option>
254
276
  `;
255
- panel.appendChild(title);
256
277
  panel.appendChild(selectThemes);
257
- colorFields.forEach((field) => {
278
+ const customThemePanel = document.createElement("div");
279
+ customThemePanel.id = "csutom-theme-panel";
280
+ customThemePanel.style.display = "none";
281
+ const title = document.createElement("h3");
282
+ title.textContent = "Select Custom Theme";
283
+ customThemePanel.appendChild(title);
284
+ formFields.forEach((field) => {
258
285
  const group = document.createElement("div");
259
286
  group.className = "uni-input-group";
260
287
  const label = document.createElement("label");
261
288
  label.textContent = field.label;
262
- const input = document.createElement("input");
263
- input.type = field.type;
264
- input.name = field.id;
265
- input.className = `uni-input ${field.class}`;
266
- input.id = `uni-theme-${field.id}`;
267
- input.value = field.defaultValue;
268
289
  group.appendChild(label);
269
- group.appendChild(input);
270
- if (field.units && field.units.length > 0) {
271
- const inputUnits = document.createElement("select");
272
- inputUnits.disabled = true;
273
- field.units.forEach((unit) => {
274
- const option = document.createElement("option");
275
- option.value = unit;
276
- option.textContent = unit;
277
- inputUnits.appendChild(option);
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);
278
301
  });
279
- group.appendChild(inputUnits);
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
+ }
280
322
  }
281
- panel.appendChild(group);
323
+ customThemePanel.appendChild(group);
282
324
  });
325
+ panel.appendChild(customThemePanel);
283
326
  container.appendChild(panel);
284
327
  }
285
328
  function injectHTML(options = {}) {
@@ -320,8 +363,27 @@ function initThemeElements() {
320
363
  const props = themes.find((item) => item.name == selectedTheme);
321
364
  setTheme(selectedTheme, props == null ? void 0 : props.properties);
322
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
+ });
323
375
  return { themeToggler, themePanel };
324
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
+ };
325
387
 
326
388
  // src/themeManager.ts
327
389
  function getAvailableThemes() {
@@ -336,6 +398,21 @@ function loadSavedTheme() {
336
398
  } else {
337
399
  setTheme(parsed.name);
338
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
+ });
339
416
  }
340
417
  function mountToggleTheme(options = {}) {
341
418
  injectStyles();
package/package.json CHANGED
@@ -1,29 +1,29 @@
1
- {
2
- "name": "uni-theme-select",
3
- "version": "1.0.3",
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
+ }