@litejs/ui 26.8.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.
- package/el/toggle-theme.ui +38 -0
- package/load.js +5 -7
- package/package.json +2 -2
- package/ui.js +49 -27
|
@@ -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
|
-
,
|
|
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 (
|
|
87
|
-
|
|
88
|
-
|
|
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.
|
|
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.
|
|
30
|
+
"@litejs/cli": "26.10.0"
|
|
31
31
|
}
|
|
32
32
|
}
|
package/ui.js
CHANGED
|
@@ -15,7 +15,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
15
15
|
window.El = El
|
|
16
16
|
asEmitter(window.LiteJS = LiteJS)
|
|
17
17
|
|
|
18
|
-
var UNDEF, parser,
|
|
18
|
+
var UNDEF, parser, styleNode
|
|
19
19
|
, NUL = null
|
|
20
20
|
// THIS will be `undefined` in strict mode and `window` in sloppy mode
|
|
21
21
|
, THIS = this
|
|
@@ -85,7 +85,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
85
85
|
, i = 0
|
|
86
86
|
, type = el.type
|
|
87
87
|
, opts = el.options
|
|
88
|
-
,
|
|
88
|
+
, isRadio = type === "radio"
|
|
89
|
+
, checkbox = type === "checkbox" || isRadio
|
|
89
90
|
|
|
90
91
|
if (el.tagName === "FORM") {
|
|
91
92
|
// Disabled controls do not receive focus,
|
|
@@ -118,7 +119,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
118
119
|
} else if (el.val) {
|
|
119
120
|
el.val(val)
|
|
120
121
|
} else if (checkbox) {
|
|
121
|
-
el.checked = !!val
|
|
122
|
+
el.checked = isRadio ? el.value == val : !!val
|
|
122
123
|
} else {
|
|
123
124
|
el.value = val
|
|
124
125
|
}
|
|
@@ -139,8 +140,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
139
140
|
el = value > -1 && opts[value] || el
|
|
140
141
|
}
|
|
141
142
|
|
|
142
|
-
return checkbox && !el.checked ?
|
|
143
|
-
(type === "radio" ? UNDEF : NUL) :
|
|
143
|
+
return checkbox && !el.checked ? (isRadio ? UNDEF : NUL) :
|
|
144
144
|
el.valObject !== UNDEF ? el.valObject : el.value
|
|
145
145
|
|
|
146
146
|
function replacer(_, _key, offset) {
|
|
@@ -181,6 +181,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
181
181
|
, fixEv = Event.fixEv || (Event.fixEv = {})
|
|
182
182
|
, fixFn = Event.fixFn || (Event.fixFn = {})
|
|
183
183
|
|
|
184
|
+
, base = find(html, "base")
|
|
185
|
+
, pushBase = (base = base && base.href) && (LiteJS.push = replace(/.+?:\/\/[^/]+|[^\/]*$/g, "", base))
|
|
186
|
+
|
|
184
187
|
/*** markup ***/
|
|
185
188
|
, blockRe = /^(?:(=+|>| -| \d+\.) ([\s\S]+))/
|
|
186
189
|
, tags = {
|
|
@@ -270,6 +273,19 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
270
273
|
}
|
|
271
274
|
/**/
|
|
272
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
|
+
|
|
273
289
|
xhr.css = injectCss
|
|
274
290
|
xhr.ui = function(src) {
|
|
275
291
|
sources.push(src)
|
|
@@ -608,7 +624,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
608
624
|
console.log("Outside view defined elements are rendered immediately into UI")
|
|
609
625
|
/**/
|
|
610
626
|
}
|
|
611
|
-
if (parent.
|
|
627
|
+
if (parent.I) {
|
|
612
628
|
histStart(viewShow)
|
|
613
629
|
}
|
|
614
630
|
|
|
@@ -616,7 +632,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
616
632
|
if (offset && all === indent) return
|
|
617
633
|
|
|
618
634
|
for (q = indent.length; q <= stack[0]; ) {
|
|
619
|
-
if ((offset = parent.
|
|
635
|
+
if ((offset = parent.P)) {
|
|
620
636
|
if (offset.c && !offset.e.childNodes[0]) break
|
|
621
637
|
offset.d(offset)
|
|
622
638
|
}
|
|
@@ -626,8 +642,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
626
642
|
if (op === "@") {
|
|
627
643
|
text = replace(/([\w,.]+)[!:]?/, /^\w+!/.test(text) ? "one!'$1'," : "on!'$1',", text)
|
|
628
644
|
}
|
|
629
|
-
if (parent.
|
|
630
|
-
parent.
|
|
645
|
+
if (parent.R) {
|
|
646
|
+
parent.T += "\n" + all
|
|
631
647
|
} else if (plugin || mapStart && (sel = "map")) {
|
|
632
648
|
if (plugins[sel]) {
|
|
633
649
|
parentStack.push(parent)
|
|
@@ -678,7 +694,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
678
694
|
// .n name .x parent view name .u parent DOM element
|
|
679
695
|
// .e container el .d done callback .c saved elCache (for %el/%view)
|
|
680
696
|
// When proto is a function, plugin accumulates raw text:
|
|
681
|
-
// .
|
|
697
|
+
// .R raw handler .T accumulated text .o original op+text .s separator
|
|
682
698
|
function addPlugin(name, proto, expectContent) {
|
|
683
699
|
plugins[name] = Plugin
|
|
684
700
|
function Plugin(parent, op, sep) {
|
|
@@ -687,9 +703,9 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
687
703
|
plugin.n = arr[0] // name
|
|
688
704
|
plugin.x = arr[1] // View parent
|
|
689
705
|
plugin.u = parent
|
|
690
|
-
if (plugin.
|
|
691
|
-
plugin.
|
|
692
|
-
plugin.
|
|
706
|
+
if (plugin.R) {
|
|
707
|
+
plugin.T = ""
|
|
708
|
+
plugin.P = plugin.e = plugin
|
|
693
709
|
plugin.o = op
|
|
694
710
|
plugin.s = sep
|
|
695
711
|
} else {
|
|
@@ -697,10 +713,10 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
697
713
|
elCache = create(plugin.c = elCache)
|
|
698
714
|
}
|
|
699
715
|
plugin.e = El(name === "svg" ? name : "div")
|
|
700
|
-
plugin.e.
|
|
716
|
+
plugin.e.P = plugin
|
|
701
717
|
}
|
|
702
718
|
}
|
|
703
|
-
assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.
|
|
719
|
+
assign(Plugin.prototype, isFn(proto) ? { d: Function("p", "p.R(p.o+p.T)"), R: proto } : proto)
|
|
704
720
|
}
|
|
705
721
|
function usePluginContent(plugin) {
|
|
706
722
|
var el = plugin.e
|
|
@@ -715,12 +731,12 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
715
731
|
child._s = el._s
|
|
716
732
|
}
|
|
717
733
|
if (plugin.c) elCache = plugin.c
|
|
718
|
-
el.
|
|
734
|
+
el.P = plugin.e = plugin.u = UNDEF
|
|
719
735
|
return child
|
|
720
736
|
}
|
|
721
737
|
|
|
722
738
|
addPlugin("ui", {
|
|
723
|
-
d: Function("p", "p.u.
|
|
739
|
+
d: Function("p", "p.u.I=1")
|
|
724
740
|
})
|
|
725
741
|
plugins.start = plugins.ui
|
|
726
742
|
addPlugin("slot", {
|
|
@@ -739,7 +755,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
739
755
|
addPlugin("def", viewDef)
|
|
740
756
|
addPlugin("js", viewEval)
|
|
741
757
|
addPlugin("each", function() {
|
|
742
|
-
var txt = this.
|
|
758
|
+
var txt = this.T
|
|
743
759
|
each(this.o, function(param) {
|
|
744
760
|
viewParse(replace(/{key}/g, param, txt))
|
|
745
761
|
})
|
|
@@ -1047,9 +1063,16 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1047
1063
|
LiteJS.go = setUrl
|
|
1048
1064
|
var histLast
|
|
1049
1065
|
, hashFallback = getUrl()
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1066
|
+
if (pushBase) {
|
|
1067
|
+
bindingsOn(body, "click", function(e, el) {
|
|
1068
|
+
if (
|
|
1069
|
+
!(e.defaultPrevented || e.button || e.ctrlKey || e.metaKey || e.altKey || e.shiftKey || getAttr(el, "target") || el.href.indexOf(base)) &&
|
|
1070
|
+
getAttr(el, "download") == NUL
|
|
1071
|
+
) {
|
|
1072
|
+
eventStop(e)
|
|
1073
|
+
setUrl(el.href.slice(base.length))
|
|
1074
|
+
}
|
|
1075
|
+
}, "a[href]")
|
|
1053
1076
|
}
|
|
1054
1077
|
// Chrome and Safari emit a popstate event on page load, Firefox doesn't.
|
|
1055
1078
|
// Firing popstate after onload is as designed.
|
|
@@ -1062,7 +1085,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1062
1085
|
}
|
|
1063
1086
|
function getUrl() {
|
|
1064
1087
|
return replace(/^[#\/\!]+|[\s\/]+$/g, "",
|
|
1065
|
-
pushBase ? location.pathname.slice(pushBase.length) :
|
|
1088
|
+
pushBase && hashFallback !== UNDEF ? location.pathname.slice(pushBase.length) :
|
|
1066
1089
|
// NOTE: in Firefox location.hash is decoded; in Safari location.pathname is decoded
|
|
1067
1090
|
location.href.split("#")[1] || "")
|
|
1068
1091
|
}
|
|
@@ -1169,7 +1192,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1169
1192
|
},
|
|
1170
1193
|
el: function(el, tag, fallback) {
|
|
1171
1194
|
tag = elCache[tag] ? tag : fallback
|
|
1172
|
-
if (el._el !== tag) {
|
|
1195
|
+
if (tag && el._el !== tag) {
|
|
1173
1196
|
var child = El(tag)
|
|
1174
1197
|
, tmp = child._elb = el._el ? el._elb : el._b
|
|
1175
1198
|
if (tmp) appendBind(child, tmp, ";", "^")
|
|
@@ -1723,8 +1746,8 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1723
1746
|
function moveTwo(e) {
|
|
1724
1747
|
touches[ touches[0].pointerId == e.pointerId ? 0 : 1] = e
|
|
1725
1748
|
var diff
|
|
1726
|
-
, x =
|
|
1727
|
-
, y =
|
|
1749
|
+
, x = touches[0].clientX - touches[1].clientX
|
|
1750
|
+
, y = touches[0].clientY - touches[1].clientY
|
|
1728
1751
|
, dist = Math.sqrt(x*x + y*y) | 0
|
|
1729
1752
|
, angle = Math.atan2(y, x)
|
|
1730
1753
|
|
|
@@ -1863,8 +1886,7 @@ console.log("LiteJS is in debug mode and that's fine for production")
|
|
|
1863
1886
|
}
|
|
1864
1887
|
function injectCss(cssText) {
|
|
1865
1888
|
if (!styleNode) {
|
|
1866
|
-
// Safari and IE6-8 requires dynamically created
|
|
1867
|
-
// <style> elements to be inserted into the <head>
|
|
1889
|
+
// Safari and IE6-8 requires dynamically created <style> elements to be in <head>
|
|
1868
1890
|
append(find(html, "head"), styleNode = El("style"))
|
|
1869
1891
|
}
|
|
1870
1892
|
if (styleNode.styleSheet) styleNode.styleSheet.cssText += cssText
|