vrembem 4.0.0-next.15 → 4.0.0-next.16

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/dev/index.umd.cjs CHANGED
@@ -195,7 +195,12 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
195
195
  function getPrefix() {
196
196
  return getComputedStyle(document.body).getPropertyValue("--vb-prefix").trim();
197
197
  }
198
- function cssVar(property, el = document.body) {
198
+ function cssVar(property, options) {
199
+ const settings = {
200
+ fallback: null,
201
+ element: document.body,
202
+ ...options
203
+ };
199
204
  if (property.slice(0, 2) !== "--") {
200
205
  const prefixValue = getPrefix();
201
206
  if (prefixValue) {
@@ -203,11 +208,15 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
203
208
  }
204
209
  property = `--${property}`;
205
210
  }
206
- const cssValue = getComputedStyle(el).getPropertyValue(property).trim();
211
+ const cssValue = getComputedStyle(settings.element).getPropertyValue(property).trim();
207
212
  if (cssValue) {
208
213
  return cssValue;
209
214
  } else {
210
- throw new Error(`CSS variable "${property}" was not found!`);
215
+ if (settings.fallback) {
216
+ return settings.fallback;
217
+ } else {
218
+ throw new Error(`CSS variable "${property}" was not found!`);
219
+ }
211
220
  }
212
221
  }
213
222
  function getConfig$1(el, dataConfig) {
@@ -251,10 +260,77 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
251
260
  }
252
261
  return returnRef;
253
262
  }
263
+ function themeStore(options) {
264
+ const settings = {
265
+ prefix: cssVar("prefix-themes", { fallback: "vb-theme-" }),
266
+ themes: ["root", "light", "dark"],
267
+ storeKey: "VB:Profile"
268
+ };
269
+ for (const [key] of Object.entries(settings)) {
270
+ if (options && options[key]) {
271
+ settings[key] = options[key];
272
+ }
273
+ }
274
+ const callbacks = {
275
+ onInit() {
276
+ },
277
+ onChange() {
278
+ }
279
+ };
280
+ for (const [key] of Object.entries(callbacks)) {
281
+ if (options && options[key]) {
282
+ callbacks[key] = options[key];
283
+ }
284
+ }
285
+ const profile = localStore(settings.storeKey);
286
+ const api = {
287
+ // Store our settings in the API.
288
+ settings,
289
+ // Actions.
290
+ add(value) {
291
+ settings.themes.push(value);
292
+ },
293
+ remove(value) {
294
+ const index2 = settings.themes.indexOf(value);
295
+ ~index2 && settings.themes.splice(index2, 1);
296
+ },
297
+ callback(name) {
298
+ callbacks[name].call(this);
299
+ },
300
+ // Getters.
301
+ get class() {
302
+ return `${settings.prefix}${this.theme}`;
303
+ },
304
+ get classes() {
305
+ return settings.themes.map((theme) => `${settings.prefix}${theme}`);
306
+ },
307
+ get themes() {
308
+ return settings.themes;
309
+ },
310
+ // Setup the theme get and set methods.
311
+ get theme() {
312
+ return profile.get("theme") || "root";
313
+ },
314
+ set theme(value) {
315
+ if (settings.themes.includes(value)) {
316
+ if (this.theme != value) {
317
+ profile.set("theme", value);
318
+ document.documentElement.classList.remove(...this.classes);
319
+ document.documentElement.classList.add(`${settings.prefix}${value}`);
320
+ this.callback("onChange");
321
+ }
322
+ } else {
323
+ console.error(`Not a valid theme value: "${value}"`);
324
+ }
325
+ }
326
+ };
327
+ api.callback("onInit");
328
+ return api;
329
+ }
254
330
  function transition(el, from, to, duration = "transition-duration") {
255
331
  return new Promise((resolve) => {
256
332
  if (typeof duration === "string") {
257
- const cssValue = cssVar(duration, el);
333
+ const cssValue = cssVar(duration, { element: el });
258
334
  const ms = cssValue.includes("ms") ? true : false;
259
335
  duration = parseFloat(cssValue) * (ms ? 1 : 1e3);
260
336
  }
@@ -307,6 +383,7 @@ var __privateSet = (obj, member, value, setter) => (__accessCheck(obj, member, "
307
383
  getPrefix,
308
384
  localStore,
309
385
  teleport,
386
+ themeStore,
310
387
  transition,
311
388
  updateGlobalState
312
389
  }, Symbol.toStringTag, { value: "Module" }));