uni-theme-select 1.0.1 → 1.0.3

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 +145 -33
  2. package/dist/index.mjs +145 -33
  3. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -67,9 +67,22 @@ var themes = [
67
67
  {
68
68
  name: "custom",
69
69
  properties: {
70
+ "primary-button-text-color": "",
71
+ "primary-button-color": "",
72
+ "primary-button-border-color": "",
73
+ "primary-button-border-radius": "",
74
+ "secondary-button-text-color": "",
75
+ "secondary-button-color": "",
76
+ "secondary-button-border-color": "",
77
+ "secondary-button-border-radius": "",
70
78
  "bg-color": "",
71
- "text-color": "",
72
- "primary-color": ""
79
+ "font-family": "",
80
+ "primary-font-color": "",
81
+ "primary-font-size": "",
82
+ "primary-font-weight": "",
83
+ "secondary-font-color": "",
84
+ "secondary-font-weight": "",
85
+ "secondary-font-size": ""
73
86
  }
74
87
  }
75
88
  ];
@@ -77,12 +90,55 @@ var themes = [
77
90
  // src/coreFunctions.ts
78
91
  var import_coloris = require("@melloware/coloris/dist/coloris.css");
79
92
  var import_coloris2 = __toESM(require("@melloware/coloris"));
93
+
94
+ // src/store.ts
95
+ var ThemeStore = class {
96
+ constructor() {
97
+ this.currentTheme = "custom";
98
+ this.themeProps = {};
99
+ this.listeners = [];
100
+ }
101
+ setTheme(themeName, themeProps) {
102
+ this.currentTheme = themeName;
103
+ this.themeProps = themeProps;
104
+ this.notify();
105
+ }
106
+ getTheme() {
107
+ return {
108
+ themeName: this.currentTheme,
109
+ properties: this.themeProps
110
+ };
111
+ }
112
+ subscribe(listener) {
113
+ this.listeners.push(listener);
114
+ return () => {
115
+ this.listeners = this.listeners.filter((l) => l !== listener);
116
+ };
117
+ }
118
+ notify() {
119
+ this.listeners.forEach((listener) => listener(this.currentTheme, this.themeProps));
120
+ }
121
+ };
122
+ var themeStore = new ThemeStore();
123
+
124
+ // src/coreFunctions.ts
80
125
  var colorFields = [
81
- { id: "bgColor", label: "Background" },
82
- { id: "primaryColor", label: "Primary" },
83
- { id: "secondaryColor", label: "Secondary" },
84
- { id: "borderColor", label: "Border Color" },
85
- { id: "textColor", label: "Text Color" }
126
+ { id: "bg-color", label: "Background Color", defaultValue: "#fff", type: "text", class: "radius-50" },
127
+ { id: "primary-button-color", label: "Primary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
128
+ { 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: "number", class: "uni-text-input", units: ["px", "%", "em"] },
130
+ { id: "primary-button-text-color", label: "Primary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
131
+ { id: "secondary-button-color", label: "Secondary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
132
+ { 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: "number", class: "uni-text-input", units: ["px", "%", "em"] },
134
+ { 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" },
136
+ { id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
137
+ { 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", class: "uni-text-input" },
139
+ { id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
140
+ { 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" }
86
142
  ];
87
143
  function injectStyles() {
88
144
  if (document.getElementById("uni-theme-style")) return;
@@ -134,11 +190,13 @@ function injectStyles() {
134
190
  box-shadow: -4px 0 12px rgba(0,0,0,0.2);
135
191
  transition: right 0.3s ease;
136
192
  z-index: 9999;
193
+ overflow: auto
137
194
  }
138
195
 
139
196
  #uni-theme-root.opened #uni-theme-panel{
140
197
  right: 0;
141
- max-height: 500px;
198
+ overflow: scroll;
199
+ max-height: 600px;
142
200
  }
143
201
 
144
202
  #uni-theme-root.opened #uni-theme-toggle{
@@ -163,62 +221,103 @@ function injectStyles() {
163
221
  .clr-field{
164
222
  margin: 5px 0
165
223
  }
166
- .uni-color-group {
224
+ .uni-input-group {
167
225
  display: flex;
168
226
  align-items: center;
169
227
  justify-content: space-between;
170
228
  margin-bottom: 14px;
171
229
  gap: 12px;
230
+ text-align: left;
172
231
  }
173
232
 
174
- .uni-color-group label {
175
- font-size: 18px;
233
+ .uni-input-group label {
234
+ font-size: 14px;
176
235
  font-weight: 500;
177
- color: var(--text-color, #333);
236
+ color: #333;
178
237
  }
179
238
 
180
- .uni-color-input {
181
- width: 36px;
182
- height: 36px;
183
- border-radius: 50%;
239
+ .uni-input {
240
+ width: 30px;
241
+ height: 30px;
184
242
  border: 2px solid #ddd;
185
243
  cursor: pointer;
186
244
  padding: 0;
187
245
  }
246
+ .uni-text-input{
247
+ width: 50px;
248
+ height: 19px;
249
+ }
250
+ .radius-50{
251
+ border-radius:50%
252
+ }
188
253
 
189
254
  `;
190
255
  document.head.appendChild(style);
191
256
  }
192
- function setTheme(name, themeProps = {}) {
193
- const theme = name === "custom" ? { name, properties: themeProps } : themes.find((t) => t.name === name);
194
- if (!theme) {
195
- console.warn(`Theme "${name}" not found`);
196
- return;
257
+ function setTheme(name, customProps = {}) {
258
+ let themeProps = {};
259
+ if (name == "custom" && customProps) {
260
+ themeProps = customProps;
261
+ } else {
262
+ const theme = themes.find((t) => t.name === name);
263
+ if (!theme) {
264
+ console.warn(`Theme "${name}" not found`);
265
+ return;
266
+ }
267
+ themeProps = theme.properties;
197
268
  }
198
269
  const root = document.documentElement;
199
- Object.entries(theme.properties).forEach(([key, value]) => {
270
+ Object.entries(themeProps).forEach(([key, value]) => {
200
271
  root.style.setProperty(`--${key}`, value);
201
272
  });
202
- localStorage.setItem("uts-theme", name);
273
+ localStorage.setItem(
274
+ "uts-theme",
275
+ JSON.stringify({
276
+ name,
277
+ properties: themeProps
278
+ })
279
+ );
280
+ themeStore.setTheme(name, themeProps);
203
281
  }
204
282
  function constructPanel(container) {
205
283
  const panel = document.createElement("div");
206
284
  panel.id = "uni-theme-panel";
207
285
  const title = document.createElement("h3");
208
286
  title.textContent = "Select Custom Theme";
287
+ const selectThemes = document.createElement("select");
288
+ selectThemes.id = "available-themes";
289
+ selectThemes.innerHTML = `
290
+ <option value="">Select theme</option>
291
+ <option value="beige">Beige</option>
292
+ <option value="dark">Dark</option>
293
+ <option value="light">Light</option>
294
+ `;
209
295
  panel.appendChild(title);
296
+ panel.appendChild(selectThemes);
210
297
  colorFields.forEach((field) => {
211
298
  const group = document.createElement("div");
212
- group.className = "uni-color-group";
299
+ group.className = "uni-input-group";
213
300
  const label = document.createElement("label");
214
301
  label.textContent = field.label;
215
302
  const input = document.createElement("input");
216
- input.type = "text";
217
- input.className = "uni-color-input";
303
+ input.type = field.type;
304
+ input.name = field.id;
305
+ input.className = `uni-input ${field.class}`;
218
306
  input.id = `uni-theme-${field.id}`;
219
- input.value = "#000";
307
+ input.value = field.defaultValue;
220
308
  group.appendChild(label);
221
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);
318
+ });
319
+ group.appendChild(inputUnits);
320
+ }
222
321
  panel.appendChild(group);
223
322
  });
224
323
  container.appendChild(panel);
@@ -240,18 +339,27 @@ function initThemeElements() {
240
339
  const themeToggler = document.getElementById("uni-theme-toggle");
241
340
  const themePanel = document.getElementById("uni-theme-panel");
242
341
  import_coloris2.default.init();
243
- document.querySelectorAll(".uni-color-input").forEach((input) => {
244
- console.log(input.className);
342
+ document.querySelectorAll(".uni-input").forEach((input) => {
245
343
  (0, import_coloris2.default)({
246
- el: `.${input.className}`,
344
+ el: `.uni-input.radius-50`,
247
345
  alpha: true,
248
346
  format: "hex"
249
347
  });
250
348
  input.addEventListener("input", (e) => {
251
349
  const target = e.target;
252
- target.style.background = target.value;
350
+ const currentTheme = themeStore.getTheme();
351
+ currentTheme.properties[target.name] = target.value;
352
+ console.log(currentTheme);
353
+ setTheme(currentTheme.themeName, currentTheme.properties);
253
354
  });
254
355
  });
356
+ const availableThemes = document.getElementById("available-themes");
357
+ availableThemes == null ? void 0 : availableThemes.addEventListener("change", (e) => {
358
+ var _a;
359
+ const selectedTheme = (_a = e.target) == null ? void 0 : _a.value;
360
+ const props = themes.find((item) => item.name == selectedTheme);
361
+ setTheme(selectedTheme, props == null ? void 0 : props.properties);
362
+ });
255
363
  return { themeToggler, themePanel };
256
364
  }
257
365
 
@@ -261,8 +369,12 @@ function getAvailableThemes() {
261
369
  }
262
370
  function loadSavedTheme() {
263
371
  const saved = localStorage.getItem("uts-theme");
264
- if (saved) {
265
- setTheme(saved);
372
+ if (!saved) return;
373
+ const parsed = JSON.parse(saved);
374
+ if (parsed.name == "custom") {
375
+ setTheme(parsed.name, parsed.properties);
376
+ } else {
377
+ setTheme(parsed.name);
266
378
  }
267
379
  }
268
380
  function mountToggleTheme(options = {}) {
package/dist/index.mjs CHANGED
@@ -27,9 +27,22 @@ var themes = [
27
27
  {
28
28
  name: "custom",
29
29
  properties: {
30
+ "primary-button-text-color": "",
31
+ "primary-button-color": "",
32
+ "primary-button-border-color": "",
33
+ "primary-button-border-radius": "",
34
+ "secondary-button-text-color": "",
35
+ "secondary-button-color": "",
36
+ "secondary-button-border-color": "",
37
+ "secondary-button-border-radius": "",
30
38
  "bg-color": "",
31
- "text-color": "",
32
- "primary-color": ""
39
+ "font-family": "",
40
+ "primary-font-color": "",
41
+ "primary-font-size": "",
42
+ "primary-font-weight": "",
43
+ "secondary-font-color": "",
44
+ "secondary-font-weight": "",
45
+ "secondary-font-size": ""
33
46
  }
34
47
  }
35
48
  ];
@@ -37,12 +50,55 @@ var themes = [
37
50
  // src/coreFunctions.ts
38
51
  import "@melloware/coloris/dist/coloris.css";
39
52
  import Coloris from "@melloware/coloris";
53
+
54
+ // src/store.ts
55
+ var ThemeStore = class {
56
+ constructor() {
57
+ this.currentTheme = "custom";
58
+ this.themeProps = {};
59
+ this.listeners = [];
60
+ }
61
+ setTheme(themeName, themeProps) {
62
+ this.currentTheme = themeName;
63
+ this.themeProps = themeProps;
64
+ this.notify();
65
+ }
66
+ getTheme() {
67
+ return {
68
+ themeName: this.currentTheme,
69
+ properties: this.themeProps
70
+ };
71
+ }
72
+ subscribe(listener) {
73
+ this.listeners.push(listener);
74
+ return () => {
75
+ this.listeners = this.listeners.filter((l) => l !== listener);
76
+ };
77
+ }
78
+ notify() {
79
+ this.listeners.forEach((listener) => listener(this.currentTheme, this.themeProps));
80
+ }
81
+ };
82
+ var themeStore = new ThemeStore();
83
+
84
+ // src/coreFunctions.ts
40
85
  var colorFields = [
41
- { id: "bgColor", label: "Background" },
42
- { id: "primaryColor", label: "Primary" },
43
- { id: "secondaryColor", label: "Secondary" },
44
- { id: "borderColor", label: "Border Color" },
45
- { id: "textColor", label: "Text Color" }
86
+ { id: "bg-color", label: "Background Color", defaultValue: "#fff", type: "text", class: "radius-50" },
87
+ { id: "primary-button-color", label: "Primary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
88
+ { 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: "number", class: "uni-text-input", units: ["px", "%", "em"] },
90
+ { id: "primary-button-text-color", label: "Primary Button Text Color", defaultValue: "#000", type: "text", class: "radius-50" },
91
+ { id: "secondary-button-color", label: "Secondary Button Color", defaultValue: "rgb(174, 174, 174)", type: "text", class: "radius-50" },
92
+ { 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: "number", class: "uni-text-input", units: ["px", "%", "em"] },
94
+ { 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" },
96
+ { id: "primary-font-size", label: "Primary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
97
+ { 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", class: "uni-text-input" },
99
+ { id: "secondary-font-size", label: "Secondary Font Size", defaultValue: "14", type: "number", class: "uni-text-input", units: ["px", "%", "em"] },
100
+ { 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" }
46
102
  ];
47
103
  function injectStyles() {
48
104
  if (document.getElementById("uni-theme-style")) return;
@@ -94,11 +150,13 @@ function injectStyles() {
94
150
  box-shadow: -4px 0 12px rgba(0,0,0,0.2);
95
151
  transition: right 0.3s ease;
96
152
  z-index: 9999;
153
+ overflow: auto
97
154
  }
98
155
 
99
156
  #uni-theme-root.opened #uni-theme-panel{
100
157
  right: 0;
101
- max-height: 500px;
158
+ overflow: scroll;
159
+ max-height: 600px;
102
160
  }
103
161
 
104
162
  #uni-theme-root.opened #uni-theme-toggle{
@@ -123,62 +181,103 @@ function injectStyles() {
123
181
  .clr-field{
124
182
  margin: 5px 0
125
183
  }
126
- .uni-color-group {
184
+ .uni-input-group {
127
185
  display: flex;
128
186
  align-items: center;
129
187
  justify-content: space-between;
130
188
  margin-bottom: 14px;
131
189
  gap: 12px;
190
+ text-align: left;
132
191
  }
133
192
 
134
- .uni-color-group label {
135
- font-size: 18px;
193
+ .uni-input-group label {
194
+ font-size: 14px;
136
195
  font-weight: 500;
137
- color: var(--text-color, #333);
196
+ color: #333;
138
197
  }
139
198
 
140
- .uni-color-input {
141
- width: 36px;
142
- height: 36px;
143
- border-radius: 50%;
199
+ .uni-input {
200
+ width: 30px;
201
+ height: 30px;
144
202
  border: 2px solid #ddd;
145
203
  cursor: pointer;
146
204
  padding: 0;
147
205
  }
206
+ .uni-text-input{
207
+ width: 50px;
208
+ height: 19px;
209
+ }
210
+ .radius-50{
211
+ border-radius:50%
212
+ }
148
213
 
149
214
  `;
150
215
  document.head.appendChild(style);
151
216
  }
152
- function setTheme(name, themeProps = {}) {
153
- const theme = name === "custom" ? { name, properties: themeProps } : themes.find((t) => t.name === name);
154
- if (!theme) {
155
- console.warn(`Theme "${name}" not found`);
156
- return;
217
+ function setTheme(name, customProps = {}) {
218
+ let themeProps = {};
219
+ if (name == "custom" && customProps) {
220
+ themeProps = customProps;
221
+ } else {
222
+ const theme = themes.find((t) => t.name === name);
223
+ if (!theme) {
224
+ console.warn(`Theme "${name}" not found`);
225
+ return;
226
+ }
227
+ themeProps = theme.properties;
157
228
  }
158
229
  const root = document.documentElement;
159
- Object.entries(theme.properties).forEach(([key, value]) => {
230
+ Object.entries(themeProps).forEach(([key, value]) => {
160
231
  root.style.setProperty(`--${key}`, value);
161
232
  });
162
- localStorage.setItem("uts-theme", name);
233
+ localStorage.setItem(
234
+ "uts-theme",
235
+ JSON.stringify({
236
+ name,
237
+ properties: themeProps
238
+ })
239
+ );
240
+ themeStore.setTheme(name, themeProps);
163
241
  }
164
242
  function constructPanel(container) {
165
243
  const panel = document.createElement("div");
166
244
  panel.id = "uni-theme-panel";
167
245
  const title = document.createElement("h3");
168
246
  title.textContent = "Select Custom Theme";
247
+ const selectThemes = document.createElement("select");
248
+ selectThemes.id = "available-themes";
249
+ selectThemes.innerHTML = `
250
+ <option value="">Select theme</option>
251
+ <option value="beige">Beige</option>
252
+ <option value="dark">Dark</option>
253
+ <option value="light">Light</option>
254
+ `;
169
255
  panel.appendChild(title);
256
+ panel.appendChild(selectThemes);
170
257
  colorFields.forEach((field) => {
171
258
  const group = document.createElement("div");
172
- group.className = "uni-color-group";
259
+ group.className = "uni-input-group";
173
260
  const label = document.createElement("label");
174
261
  label.textContent = field.label;
175
262
  const input = document.createElement("input");
176
- input.type = "text";
177
- input.className = "uni-color-input";
263
+ input.type = field.type;
264
+ input.name = field.id;
265
+ input.className = `uni-input ${field.class}`;
178
266
  input.id = `uni-theme-${field.id}`;
179
- input.value = "#000";
267
+ input.value = field.defaultValue;
180
268
  group.appendChild(label);
181
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);
278
+ });
279
+ group.appendChild(inputUnits);
280
+ }
182
281
  panel.appendChild(group);
183
282
  });
184
283
  container.appendChild(panel);
@@ -200,18 +299,27 @@ function initThemeElements() {
200
299
  const themeToggler = document.getElementById("uni-theme-toggle");
201
300
  const themePanel = document.getElementById("uni-theme-panel");
202
301
  Coloris.init();
203
- document.querySelectorAll(".uni-color-input").forEach((input) => {
204
- console.log(input.className);
302
+ document.querySelectorAll(".uni-input").forEach((input) => {
205
303
  Coloris({
206
- el: `.${input.className}`,
304
+ el: `.uni-input.radius-50`,
207
305
  alpha: true,
208
306
  format: "hex"
209
307
  });
210
308
  input.addEventListener("input", (e) => {
211
309
  const target = e.target;
212
- target.style.background = target.value;
310
+ const currentTheme = themeStore.getTheme();
311
+ currentTheme.properties[target.name] = target.value;
312
+ console.log(currentTheme);
313
+ setTheme(currentTheme.themeName, currentTheme.properties);
213
314
  });
214
315
  });
316
+ const availableThemes = document.getElementById("available-themes");
317
+ availableThemes == null ? void 0 : availableThemes.addEventListener("change", (e) => {
318
+ var _a;
319
+ const selectedTheme = (_a = e.target) == null ? void 0 : _a.value;
320
+ const props = themes.find((item) => item.name == selectedTheme);
321
+ setTheme(selectedTheme, props == null ? void 0 : props.properties);
322
+ });
215
323
  return { themeToggler, themePanel };
216
324
  }
217
325
 
@@ -221,8 +329,12 @@ function getAvailableThemes() {
221
329
  }
222
330
  function loadSavedTheme() {
223
331
  const saved = localStorage.getItem("uts-theme");
224
- if (saved) {
225
- setTheme(saved);
332
+ if (!saved) return;
333
+ const parsed = JSON.parse(saved);
334
+ if (parsed.name == "custom") {
335
+ setTheme(parsed.name, parsed.properties);
336
+ } else {
337
+ setTheme(parsed.name);
226
338
  }
227
339
  }
228
340
  function mountToggleTheme(options = {}) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "uni-theme-select",
3
- "version": "1.0.01",
3
+ "version": "1.0.3",
4
4
  "description": "Framework-agnostic theme switcher",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",