@litejs/ui 26.10.0 → 26.11.0

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.
@@ -0,0 +1,38 @@
1
+
2
+ %css
3
+ .Toggle {
4
+ width: 60px;
5
+ }
6
+ .Toggle:before {
7
+ content: "☀️ 🌙";
8
+ display: block;
9
+ filter: grayscale(1);
10
+ }
11
+ .Toggle:after {
12
+ background: #eee;
13
+ border-radius: 16px;
14
+ box-shadow: inset 0 0 3px #222;
15
+ content: "☀️";
16
+ display: block;
17
+ position: absolute;
18
+ top: 0;
19
+ transform: rotate(-360deg);
20
+ transition: all .6s;
21
+ width: 32px;
22
+ }
23
+ .theme-dark .Toggle:after {
24
+ background: #333;
25
+ box-shadow: inset 0 0 3px #eee;
26
+ content: "🌙";
27
+ margin-left: 28px;
28
+ transform: rotate(-20deg);
29
+ }
30
+
31
+
32
+ %el Toggle-theme
33
+ button.Toggle.reset
34
+ @click function(e){
35
+ LiteJS.theme("-")
36
+ if (e.pageX) El.blur()
37
+ }
38
+
package/load.js CHANGED
@@ -79,15 +79,13 @@
79
79
 
80
80
  /*** theme ***/
81
81
  , savedTheme
82
- , ALT_THEME = "dark"
82
+ , preferDark = xhr._d = (preferDark = window.matchMedia) && preferDark("(prefers-color-scheme:dark)")
83
83
  try {
84
84
  savedTheme = window.localStorage.theme
85
- } catch(e){}
86
- if (ALT_THEME == (
87
- savedTheme ||
88
- (savedTheme = window.matchMedia) && savedTheme("(prefers-color-scheme:dark)").matches && ALT_THEME
89
- )) {
90
- document.documentElement.className = "is-" + ALT_THEME
85
+ } catch(e) {}
86
+ if (savedTheme || (savedTheme = preferDark && preferDark.matches && "dark")) {
87
+ // load overwrite HTML element class, no default classes there
88
+ document.documentElement.className = "theme-" + (xhr._s = savedTheme)
91
89
  }
92
90
  /**/
93
91
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/ui",
3
- "version": "26.10.0",
3
+ "version": "26.11.0",
4
4
  "description": "UI engine for LiteJS full-stack framework",
5
5
  "license": "MIT",
6
6
  "author": "Lauri Rooden <lauri@rooden.ee>",
@@ -27,6 +27,6 @@
27
27
  "test": "lj t test/index.js"
28
28
  },
29
29
  "devDependencies": {
30
- "@litejs/cli": "26.8.0"
30
+ "@litejs/cli": "26.10.0"
31
31
  }
32
32
  }
package/ui.js CHANGED
@@ -273,6 +273,19 @@ console.log("LiteJS is in debug mode and that's fine for production")
273
273
  }
274
274
  /**/
275
275
 
276
+ /*** theme ***/
277
+ // Single fn to listen "(prefers-color-scheme:dark)" and localStorage.theme change
278
+ // and to set manually LiteJS.theme( "-"=toggle dark/light | ""=system | "anyName"=class theme-anyName )
279
+ addEvent(window, "storage", LiteJS.theme = (xhr._d || addEvent).onchange = function(e) {
280
+ if (!e.key || e.key == "theme") {
281
+ if (isStr(e)) localStorage.theme = e != "-" ? e : xhr._s == "dark" ? "light" : "dark"
282
+ bindingsCss(html, "transition", "all .6s", 0, 999)
283
+ cls(html, "theme-" + xhr._s, 0)
284
+ cls(html, "theme-" + (xhr._s = localStorage.theme || xhr._d && xhr._d.matches && "dark"), xhr._s)
285
+ }
286
+ })
287
+ /**/
288
+
276
289
  xhr.css = injectCss
277
290
  xhr.ui = function(src) {
278
291
  sources.push(src)
@@ -1179,7 +1192,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
1179
1192
  },
1180
1193
  el: function(el, tag, fallback) {
1181
1194
  tag = elCache[tag] ? tag : fallback
1182
- if (el._el !== tag) {
1195
+ if (tag && el._el !== tag) {
1183
1196
  var child = El(tag)
1184
1197
  , tmp = child._elb = el._el ? el._elb : el._b
1185
1198
  if (tmp) appendBind(child, tmp, ";", "^")