cmswift 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/cmswift.js CHANGED
@@ -41,7 +41,7 @@
41
41
  CMSwift.uiSizes = ["xxs", "xs", "sm", "md", "lg", "xl", "xxl", "xxxl"];
42
42
  CMSwift.uiColors = ["primary", "secondary", "success", "warning", "danger", "info", "light", "dark"];
43
43
  CMSwift.meta = CMSwift.meta || {
44
- version: "1.0.2",
44
+ version: "1.0.4",
45
45
  policy: {
46
46
  sourceOfTruth: "docs/reference/core.md",
47
47
  syncRule: "Quando cambia un modulo core, aggiornare sia questo meta sia docs/reference/core.md."
@@ -5020,12 +5020,147 @@ _.dynamic = function (renderFn) {
5020
5020
  window.$router = CMSwift.router;
5021
5021
  }
5022
5022
  // alias per compatibilità
5023
- CMSwift.signal = CMSwift.reactive.signal;
5024
- CMSwift.effect = CMSwift.reactive.effect;
5025
- CMSwift.computed = CMSwift.reactive.computed;
5026
- CMSwift.untracked = CMSwift.reactive.untracked;
5027
- CMSwift.batch = CMSwift.reactive.batch;
5028
- })();
5023
+ CMSwift.signal = CMSwift.reactive.signal;
5024
+ CMSwift.effect = CMSwift.reactive.effect;
5025
+ CMSwift.computed = CMSwift.reactive.computed;
5026
+ CMSwift.untracked = CMSwift.reactive.untracked;
5027
+ CMSwift.batch = CMSwift.reactive.batch;
5028
+
5029
+ function normalizeThemeName(theme) {
5030
+ if (theme == null) return null;
5031
+ const value = String(theme).trim();
5032
+ return value || null;
5033
+ }
5034
+
5035
+ function normalizeThemeList(input) {
5036
+ const values = Array.isArray(input)
5037
+ ? input
5038
+ : typeof input === "string"
5039
+ ? input.split(",")
5040
+ : [];
5041
+ const out = [];
5042
+ const seen = new Set();
5043
+ for (const item of values) {
5044
+ const value = normalizeThemeName(item);
5045
+ if (!value || seen.has(value)) continue;
5046
+ seen.add(value);
5047
+ out.push(value);
5048
+ }
5049
+ return out;
5050
+ }
5051
+
5052
+ function getThemeRoot() {
5053
+ if (typeof document !== "undefined" && document.documentElement) {
5054
+ return document.documentElement;
5055
+ }
5056
+ return CMSwift.dom?.q ? CMSwift.dom.q("html") : null;
5057
+ }
5058
+
5059
+ function getThemeStorage() {
5060
+ try {
5061
+ return typeof globalThis !== "undefined" ? globalThis.localStorage || null : null;
5062
+ } catch (_error) {
5063
+ return null;
5064
+ }
5065
+ }
5066
+
5067
+ function getThemeStorageKey() {
5068
+ return normalizeThemeName(CMSwift.theme?.storageKey) || "cmswift:theme";
5069
+ }
5070
+
5071
+ function readSavedTheme() {
5072
+ const storage = getThemeStorage();
5073
+ if (!storage) return null;
5074
+ try {
5075
+ return normalizeThemeName(storage.getItem(getThemeStorageKey()));
5076
+ } catch (_error) {
5077
+ return null;
5078
+ }
5079
+ }
5080
+
5081
+ function writeSavedTheme(theme) {
5082
+ const storage = getThemeStorage();
5083
+ if (!storage) return;
5084
+ try {
5085
+ if (theme == null) {
5086
+ storage.removeItem(getThemeStorageKey());
5087
+ } else {
5088
+ storage.setItem(getThemeStorageKey(), theme);
5089
+ }
5090
+ } catch (_error) { }
5091
+ }
5092
+
5093
+ function resolveThemeList(themes) {
5094
+ const html = getThemeRoot();
5095
+ const candidates = [
5096
+ themes,
5097
+ CMSwift.theme?.themes,
5098
+ CMSwift.config?.themes,
5099
+ typeof globalThis !== "undefined" ? globalThis.CMSwift_setting?.themes : null,
5100
+ typeof globalThis !== "undefined" ? globalThis.CMSwift_setting?.themeList : null,
5101
+ html?.getAttribute?.("data-themes"),
5102
+ ];
5103
+
5104
+ for (const candidate of candidates) {
5105
+ const list = normalizeThemeList(candidate);
5106
+ if (list.length) return list;
5107
+ }
5108
+ return [];
5109
+ }
5110
+
5111
+ CMSwift.theme = CMSwift.theme || {};
5112
+ CMSwift.theme.storageKey = getThemeStorageKey();
5113
+ if (!normalizeThemeList(CMSwift.theme.themes).length) {
5114
+ CMSwift.theme.themes = resolveThemeList();
5115
+ }
5116
+
5117
+ CMSwift.setTheme = function (theme, opts = {}) {
5118
+ const value = normalizeThemeName(theme);
5119
+ const html = getThemeRoot();
5120
+ if (html) {
5121
+ if (value == null) html.removeAttribute("data-theme");
5122
+ else html.setAttribute("data-theme", value);
5123
+ }
5124
+ if (opts.persist !== false) writeSavedTheme(value);
5125
+ return html;
5126
+ };
5127
+
5128
+ CMSwift.getTheme = function (opts = {}) {
5129
+ const html = getThemeRoot();
5130
+ const current = normalizeThemeName(html?.getAttribute?.("data-theme"));
5131
+ if (current) return current;
5132
+
5133
+ if (opts.storage === false) return null;
5134
+
5135
+ const saved = readSavedTheme();
5136
+ if (saved && html && opts.sync !== false) {
5137
+ html.setAttribute("data-theme", saved);
5138
+ }
5139
+ return saved;
5140
+ };
5141
+
5142
+ CMSwift.toggleTheme = function (themes, opts = {}) {
5143
+ const list = resolveThemeList(themes);
5144
+ const activeList = list.length
5145
+ ? list
5146
+ : normalizeThemeList([CMSwift.getTheme({ sync: false }), "light", "dark"]);
5147
+ const current = CMSwift.getTheme({ sync: false });
5148
+ const fallback = normalizeThemeName(opts.fallback) || activeList[0] || "light";
5149
+ const currentIndex = current ? activeList.indexOf(current) : -1;
5150
+ const nextTheme = currentIndex >= 0
5151
+ ? activeList[(currentIndex + 1) % activeList.length]
5152
+ : fallback;
5153
+
5154
+ CMSwift.theme.themes = activeList.slice();
5155
+ CMSwift.setTheme(nextTheme, opts);
5156
+ return nextTheme;
5157
+ };
5158
+
5159
+ const bootTheme = readSavedTheme();
5160
+ if (bootTheme) {
5161
+ CMSwift.setTheme(bootTheme, { persist: false });
5162
+ }
5163
+ })();
5029
5164
 
5030
5165
 
5031
5166
  // ===============================