@litejs/ui 26.2.1 → 26.4.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/README.md +2 -1
- package/css/anim.css +14 -2
- package/css/base.css +4 -0
- package/css/global.css +6 -0
- package/el/dialog.ui +97 -98
- package/el/gallery.ui +187 -0
- package/el/material.ui +0 -274
- package/el/menu.ui +213 -0
- package/el/ripple.ui +56 -0
- package/el/{Slider.ui → slider.ui} +84 -72
- package/el/sortable.ui +85 -0
- package/load.js +3 -3
- package/package.json +2 -2
- package/ui.js +280 -140
package/README.md
CHANGED
|
@@ -16,7 +16,8 @@ used on heavy-traffic websites since 2006.
|
|
|
16
16
|
Works seamlessly in ESM projects too.
|
|
17
17
|
- No transpiling/compiling/bundling headache, just write working code.
|
|
18
18
|
|
|
19
|
-
Includes templates, view routing, data binding, i18n, keyboard shortcuts,
|
|
19
|
+
Includes templates, view routing, data binding, i18n, keyboard shortcuts,
|
|
20
|
+
touch gestures, FLIP animations.
|
|
20
21
|
|
|
21
22
|
For usage instructions, see [Quick-Start](https://github.com/litejs/litejs/wiki/Quick-Start) guide
|
|
22
23
|
and [wiki](https://github.com/litejs/ui/wiki).
|
package/css/anim.css
CHANGED
|
@@ -3,11 +3,23 @@
|
|
|
3
3
|
.anim,
|
|
4
4
|
.anim:after,
|
|
5
5
|
.anim:before {
|
|
6
|
-
transition: all .
|
|
6
|
+
transition: all .35s;
|
|
7
7
|
|
|
8
8
|
/* Trigger GPU acceleration. Remove first flicker on iphone. */
|
|
9
9
|
transform: translate3d(0, 0, 0);
|
|
10
10
|
|
|
11
|
-
perspective:
|
|
11
|
+
perspective: 1000px;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
.flip {
|
|
15
|
+
transform-origin: 0 0;
|
|
16
|
+
transition: transform .4s, width .4s, height .4s, opacity .4s;
|
|
17
|
+
}
|
|
18
|
+
.is-lifted {
|
|
19
|
+
animation: .4s lift;
|
|
20
|
+
z-index: 3;
|
|
21
|
+
}
|
|
22
|
+
@keyframes lift {
|
|
23
|
+
70% { scale: 1.06; box-shadow: 0 5px 20px rgba(0, 0, 0, .8); }
|
|
12
24
|
}
|
|
13
25
|
|
package/css/base.css
CHANGED
package/css/global.css
CHANGED
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
min-height: 100%;
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
.no,
|
|
15
|
+
.no-empty:empty,
|
|
16
|
+
.sm .no-sm,
|
|
17
|
+
.md .no-md,
|
|
18
|
+
.lg .no-lg,
|
|
14
19
|
.sm .sm-hide,
|
|
15
20
|
.md .md-hide,
|
|
16
21
|
.lg .lg-hide,
|
|
@@ -19,6 +24,7 @@
|
|
|
19
24
|
display: none !important;
|
|
20
25
|
visibility: hidden;
|
|
21
26
|
}
|
|
27
|
+
.op0,
|
|
22
28
|
.transparent {
|
|
23
29
|
opacity: 0 !important;
|
|
24
30
|
filter: alpha(opacity=0) !important;
|
package/el/dialog.ui
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
|
|
2
2
|
%css
|
|
3
3
|
.Modal {
|
|
4
|
-
|
|
4
|
+
overflow: auto;
|
|
5
|
+
overscroll-behavior: contain;
|
|
6
|
+
z-index: 8;
|
|
5
7
|
}
|
|
6
8
|
.Modal-bg {
|
|
7
|
-
|
|
8
|
-
position: static;
|
|
9
|
-
background-color: rgba(0, 0, 0, .6);
|
|
9
|
+
background-color: rgba(0, 0, 0, .8);
|
|
10
10
|
}
|
|
11
11
|
.Modal-content {
|
|
12
|
-
position: absolute;
|
|
13
12
|
left: 0;
|
|
14
13
|
right: 0;
|
|
15
14
|
margin: 0 auto;
|
|
@@ -59,110 +58,110 @@
|
|
|
59
58
|
// { "action": "no", "title": "No", "icon": "images/no.png" }
|
|
60
59
|
// ]
|
|
61
60
|
%js
|
|
62
|
-
$ui.on("modal", function(title, opts
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
61
|
+
$ui.on("modal", function(title, opts) {
|
|
62
|
+
var a
|
|
63
|
+
, i = 0
|
|
64
|
+
, doc = document
|
|
65
|
+
, oldFocus = doc.activeElement
|
|
66
|
+
, modal = El("Modal")
|
|
67
|
+
, scope = El.scope(modal, opts && opts.modalContent || modal, typeof opts === "string" ? { body: opts } : opts)
|
|
68
|
+
, el = scope.modalContent || El("Dialog.Modal-content.Modal--blur.abs")
|
|
69
|
+
, kbMap = {
|
|
70
|
+
bubble: 1, input: 1,
|
|
71
|
+
tab: setFocus,
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
,
|
|
70
|
-
,
|
|
71
|
-
,
|
|
72
|
-
|
|
73
|
-
, body = document.body
|
|
74
|
-
, blurEl = $(scope.blur) || $ui.root.lastChild
|
|
75
|
-
scope.title = title || "Confirm?"
|
|
73
|
+
, body = doc.body
|
|
74
|
+
, scrollEl = doc.scrollingElement || doc.documentElement
|
|
75
|
+
, vibrate = scope.vibrate && navigator.vibrate
|
|
76
|
+
, sound = scope.sound && window.Audio && new Audio(scope.sound)
|
|
77
|
+
scope.title = title
|
|
76
78
|
if (!scope.actions) scope.actions = [
|
|
77
|
-
{
|
|
79
|
+
{ title: "Close", key: "esc" }
|
|
78
80
|
]
|
|
79
|
-
for (
|
|
80
|
-
if (typeof a
|
|
81
|
-
if (a.key) kbMap[a.key] = resolve.bind(el,
|
|
81
|
+
for (; (a = scope.actions[i++]); ) {
|
|
82
|
+
if (typeof a === "string") a = scope.actions[i - 1] = { title: a, action: a }
|
|
83
|
+
if (a.key) kbMap[a.key] = resolve.bind(el, a.action)
|
|
82
84
|
}
|
|
83
|
-
El.
|
|
84
|
-
|
|
85
|
-
El.append(
|
|
86
|
-
El.
|
|
87
|
-
El.
|
|
88
|
-
if (
|
|
89
|
-
|
|
90
|
-
kbMap.backspace = kbMap.del = kbMap.num = numpad
|
|
85
|
+
El.append(modal, el)
|
|
86
|
+
if (scope.el) El.append(el, El(scope.el))
|
|
87
|
+
El.append(body, modal)
|
|
88
|
+
El.render(modal)
|
|
89
|
+
El.addKb(kbMap, modal)
|
|
90
|
+
if (El.closest(doc.activeElement, 'form') !== el) {
|
|
91
|
+
setFocus()
|
|
91
92
|
}
|
|
92
|
-
El.
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
code += num
|
|
110
|
-
if (num == "CLEAR" || num == "del" || num == "backspace") code = ""
|
|
111
|
-
El.md($(".js-body", el), code.replace(/./g, "•") || opts.body)
|
|
112
|
-
if (typeof scope.code == "number" && code.length == scope.code && id && !sent) next(sent = code, id, resolve, reject)
|
|
113
|
-
}
|
|
114
|
-
function resolve(e, key) {
|
|
115
|
-
if (el) {
|
|
116
|
-
var action = key || El.get(this, "data-action")
|
|
117
|
-
, result = {
|
|
118
|
-
code: code,
|
|
119
|
-
input: El.val($(".js-input", el)),
|
|
120
|
-
inputMd: El.val($(".js-inputMd", el)),
|
|
121
|
-
select: El.val($(".js-select", el))
|
|
122
|
-
}
|
|
123
|
-
El.kill(mm, "transparent")
|
|
124
|
-
El.cls(blurEl, "Modal--blur", el = false)
|
|
125
|
-
if (action && next) {
|
|
126
|
-
if (typeof next === "function") next(action, result)
|
|
127
|
-
else if (typeof next[action] === "function") next[action](result)
|
|
128
|
-
else if (next[action]) $ui.emit(next[action], result)
|
|
129
|
-
}
|
|
130
|
-
if (vibrate) navigator.vibrate(0)
|
|
93
|
+
El.on(el, "click", function(e, btn) {
|
|
94
|
+
resolve(El.get(btn, "data-action"), e)
|
|
95
|
+
}, "[data-action]")
|
|
96
|
+
El.cls(el, "Modal--blur",!1,1)
|
|
97
|
+
$ui.emit("modalOpen", scope)
|
|
98
|
+
$ui.one("show", function() { resolve() })
|
|
99
|
+
El.on(modal.firstChild, "click", resolve)
|
|
100
|
+
if (vibrate) vibrate(scope.vibrate)
|
|
101
|
+
if (sound) sound.play()
|
|
102
|
+
El.cls(scrollEl, "no-scroll")
|
|
103
|
+
function resolve(action, e) {
|
|
104
|
+
if (modal) {
|
|
105
|
+
El.stop(e)
|
|
106
|
+
if (scope.beforeKill) scope.beforeKill(modal)
|
|
107
|
+
El.kill(modal, "transparent", 1)
|
|
108
|
+
El.cls(scrollEl, "no-scroll", 0)
|
|
109
|
+
if (vibrate) vibrate(0)
|
|
131
110
|
if (sound) sound.pause()
|
|
111
|
+
modal = null
|
|
112
|
+
if (action) {
|
|
113
|
+
$ui.emit(scope.event || "modal:" + action, El.val(el), scope)
|
|
114
|
+
}
|
|
115
|
+
$ui.emit("modalClose", scope)
|
|
116
|
+
if (oldFocus) oldFocus.focus()
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
function setFocus(e) {
|
|
120
|
+
El.stop(e)
|
|
121
|
+
var items = $$("a[href],button,input,select,textarea,[tabindex]", modal)
|
|
122
|
+
, len = items.length
|
|
123
|
+
, tries = len
|
|
124
|
+
, pos = items.indexOf(doc.activeElement)
|
|
125
|
+
for (; tries--; ) {
|
|
126
|
+
pos += e && e.shiftKey ? -1 : 1
|
|
127
|
+
if (pos < 0) pos = len - 1
|
|
128
|
+
else if (pos >= len) pos = 0
|
|
129
|
+
items[pos].focus()
|
|
130
|
+
if (doc.activeElement === items[pos]) return
|
|
132
131
|
}
|
|
133
132
|
}
|
|
134
|
-
scope.resolve = resolve
|
|
135
|
-
$ui.emit("modal:open", scope)
|
|
136
133
|
})
|
|
137
134
|
|
|
138
|
-
%el
|
|
139
|
-
.
|
|
140
|
-
@click ".btn", function(){}
|
|
141
|
-
;each! "num",[1,2,3,4,5,6,7,8,9,"CLEAR",0]
|
|
142
|
-
.col.w4>.btn {num}
|
|
143
|
-
|
|
144
|
-
%js
|
|
145
|
-
$ui.on("showDialog", function(e, el, dialog) {
|
|
146
|
-
console.log("showDialog", El.scope(el), arguments)
|
|
147
|
-
El.kill(dialog)
|
|
148
|
-
})
|
|
135
|
+
%el Modal
|
|
136
|
+
.Modal.fix.max.anim>.Modal-bg.abs.max.anim.op0;cls!'op0',0,1
|
|
149
137
|
|
|
150
138
|
%el Dialog
|
|
151
|
-
.Dialog.grid.p2.anim
|
|
152
|
-
.col
|
|
153
|
-
.col
|
|
139
|
+
form.Dialog.grid.p2.anim[action="javascript:"][method=POST][role=dialog]
|
|
140
|
+
.col>h1 ;txt title
|
|
141
|
+
.col ;if body; d body
|
|
142
|
+
%slot
|
|
143
|
+
.col.group
|
|
144
|
+
button.btn.js-action
|
|
145
|
+
;each! 'action',actions
|
|
146
|
+
;set! "data-action", action.action||"-"
|
|
147
|
+
;txt _(action.title)
|
|
148
|
+
;cls! "w" + (12/actions.length)
|
|
149
|
+
;cls! action.action && "is-" + action.action, action.action
|
|
150
|
+
|
|
151
|
+
%el Dialog-input
|
|
152
|
+
.col
|
|
153
|
+
input[type=hidden][name=hi]
|
|
154
|
+
input.field[name=value][type=text][placeholder="Enter value"]
|
|
155
|
+
|
|
156
|
+
%el Dialog-numpad
|
|
157
|
+
.grid.p1.js-numpad
|
|
158
|
+
@click function(e,b,n,v){$s.in.value=(v=$s.in.value,n=b[El.T])>-1?v+n:n=='DEL'?v.slice(0,-1):'',$s.in.focus()},'.btn'
|
|
159
|
+
;kb!{num:function(e,b,n){$s.in.value=(n)>-1?$s.in.value+n:''},del:function(e,b,n){$s.in.value=$s.in.value.slice(0,-1)}}
|
|
154
160
|
.col
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
;class! "is-" + action.action, action.action
|
|
161
|
+
input[type=hidden][name=hi]
|
|
162
|
+
input[name=code] ;ref!'in';focus
|
|
163
|
+
.col.w4
|
|
164
|
+
;each! "num",[1,2,3,4,5,6,7,8,9,"CLEAR",0,"DEL"]
|
|
165
|
+
button.btn.w12[type=button]
|
|
166
|
+
;txt!num
|
|
162
167
|
|
|
163
|
-
%el Modal
|
|
164
|
-
.Modal.max.fix.anim
|
|
165
|
-
.Modal-bg.max.abs
|
|
166
|
-
.Modal-content.Modal--blur.grid.p2.anim
|
|
167
|
-
;cls! "Modal--blur",!1,1
|
|
168
|
-
%slot
|
package/el/gallery.ui
ADDED
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
|
|
2
|
+
%css
|
|
3
|
+
.Gallery {
|
|
4
|
+
display: grid;
|
|
5
|
+
place-items: center;
|
|
6
|
+
}
|
|
7
|
+
.Gallery-img {
|
|
8
|
+
grid-area: 1 / 1;
|
|
9
|
+
max-width: 90%;
|
|
10
|
+
max-height: 90%;
|
|
11
|
+
object-fit: contain;
|
|
12
|
+
opacity: 0;
|
|
13
|
+
transition: opacity .3s;
|
|
14
|
+
}
|
|
15
|
+
.Gallery-img.is-active {
|
|
16
|
+
opacity: 1;
|
|
17
|
+
}
|
|
18
|
+
.Gallery-nav {
|
|
19
|
+
grid-area: 1 / 1;
|
|
20
|
+
position: relative;
|
|
21
|
+
width: 100%;
|
|
22
|
+
height: 100%;
|
|
23
|
+
z-index: 1;
|
|
24
|
+
}
|
|
25
|
+
.Gallery-nav > button {
|
|
26
|
+
position: absolute;
|
|
27
|
+
top: 50%;
|
|
28
|
+
transform: translateY(-50%);
|
|
29
|
+
background: none;
|
|
30
|
+
border: none;
|
|
31
|
+
color: #fff;
|
|
32
|
+
font-size: 2em;
|
|
33
|
+
cursor: pointer;
|
|
34
|
+
opacity: .5;
|
|
35
|
+
padding: .5em;
|
|
36
|
+
}
|
|
37
|
+
.Gallery-nav > button:hover {
|
|
38
|
+
opacity: 1;
|
|
39
|
+
}
|
|
40
|
+
.Gallery-nav--prev {
|
|
41
|
+
left: 0;
|
|
42
|
+
}
|
|
43
|
+
.Gallery-nav--next {
|
|
44
|
+
right: 0;
|
|
45
|
+
}
|
|
46
|
+
.Gallery-counter {
|
|
47
|
+
position: absolute;
|
|
48
|
+
bottom: 1em;
|
|
49
|
+
left: 50%;
|
|
50
|
+
transform: translateX(-50%);
|
|
51
|
+
color: #fff;
|
|
52
|
+
opacity: .7;
|
|
53
|
+
z-index: 2;
|
|
54
|
+
}
|
|
55
|
+
.Gallery-anim {
|
|
56
|
+
transition: transform .3s ease;
|
|
57
|
+
transform-origin: 0 0;
|
|
58
|
+
}
|
|
59
|
+
.ImageGrid {
|
|
60
|
+
display: grid;
|
|
61
|
+
grid-template-columns: 2fr 1fr;
|
|
62
|
+
grid-template-rows: repeat(3, 1fr);
|
|
63
|
+
gap: 2px;
|
|
64
|
+
cursor: pointer;
|
|
65
|
+
max-width: 600px;
|
|
66
|
+
}
|
|
67
|
+
.ImageGrid-frame {
|
|
68
|
+
overflow: hidden;
|
|
69
|
+
position: relative;
|
|
70
|
+
transform-origin: 0 0;
|
|
71
|
+
}
|
|
72
|
+
.ImageGrid-anim {
|
|
73
|
+
transform-origin: 0 0;
|
|
74
|
+
}
|
|
75
|
+
.ImageGrid-frame:first-child {
|
|
76
|
+
grid-row: 1 / -1;
|
|
77
|
+
}
|
|
78
|
+
.ImageGrid-frame>img {
|
|
79
|
+
width: 100%;
|
|
80
|
+
height: 100%;
|
|
81
|
+
object-fit: cover;
|
|
82
|
+
display: block;
|
|
83
|
+
}
|
|
84
|
+
.ImageGrid-count {
|
|
85
|
+
position: absolute;
|
|
86
|
+
bottom: 2px;
|
|
87
|
+
right: 2px;
|
|
88
|
+
background: rgba(0, 0, 0, .6);
|
|
89
|
+
color: #fff;
|
|
90
|
+
font-size: 1.5em;
|
|
91
|
+
font-weight: 700;
|
|
92
|
+
border-radius: 20px;
|
|
93
|
+
border: 1px solid #999;
|
|
94
|
+
z-index: 2;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
%js
|
|
98
|
+
$d.initGalleryImages = function(el) {
|
|
99
|
+
for (var images = $$("img[src]", el), i = images.length, arr = []; i--; ) arr[i] = images[i].src
|
|
100
|
+
images.kill()
|
|
101
|
+
return arr
|
|
102
|
+
}
|
|
103
|
+
$ui.on("flipToFirst", function toFirst(ev, el) {
|
|
104
|
+
var parent = el.parentNode
|
|
105
|
+
, first = parent.firstChild
|
|
106
|
+
if (el !== first) {
|
|
107
|
+
El.stop(ev)
|
|
108
|
+
El.flip(parent, 0, function() {
|
|
109
|
+
El.append(parent, el, first)
|
|
110
|
+
}, {scale:1})
|
|
111
|
+
El.cls(el, "is-lifted", toFirst._prev, 1, -1)
|
|
112
|
+
toFirst._prev = el
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
$ui.on("gallery", function(ev, thumb) {
|
|
116
|
+
var preview = El.closest(thumb, ".ImageGrid")
|
|
117
|
+
if (!preview) return
|
|
118
|
+
var images = El.scope(preview).images
|
|
119
|
+
, current = +El.get(thumb, "data-index") || 0
|
|
120
|
+
, el = El("Gallery")
|
|
121
|
+
, img1 = el.querySelector(".Gallery-img")
|
|
122
|
+
, img2 = img1.nextSibling
|
|
123
|
+
, counter = el.querySelector(".Gallery-counter")
|
|
124
|
+
, activeImg = img1
|
|
125
|
+
, thumbImg = thumb.querySelector("img") || thumb
|
|
126
|
+
, scope = El.scope(el, el, {
|
|
127
|
+
images: images,
|
|
128
|
+
nav: function(e, btn) {
|
|
129
|
+
El.stop(e)
|
|
130
|
+
show(current + (El.matches(btn, ".Gallery-nav--prev") ? -1 : 1))
|
|
131
|
+
},
|
|
132
|
+
flipIn: function() {
|
|
133
|
+
El.morph(thumbImg, activeImg, { anim: "Gallery-anim", scale:1 })
|
|
134
|
+
},
|
|
135
|
+
beforeKill: function() {
|
|
136
|
+
var thumbs = $$("[data-index]", preview)
|
|
137
|
+
, target = thumbs[current] || thumbs.pop()
|
|
138
|
+
if (target) {
|
|
139
|
+
El.morph(activeImg, target, { scale:1 })
|
|
140
|
+
El.css(target, "z-index", 10, 0, -2)
|
|
141
|
+
El.kill(activeImg)
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
})
|
|
145
|
+
show(current, 1)
|
|
146
|
+
$ui.emit("modal", "", {
|
|
147
|
+
modalContent: el,
|
|
148
|
+
actions: [{ title: "Close", key: "esc" }]
|
|
149
|
+
})
|
|
150
|
+
activeImg.src = thumbImg.src
|
|
151
|
+
function show(idx, initial) {
|
|
152
|
+
current = scope.current = ((idx % images.length) + images.length) % images.length
|
|
153
|
+
var nextImg = activeImg === img1 ? img2 : img1
|
|
154
|
+
if (initial && activeImg.src === images[current]) return
|
|
155
|
+
nextImg.src = images[current]
|
|
156
|
+
nextImg.onload = function() {
|
|
157
|
+
El.cls(nextImg, "is-active", activeImg)
|
|
158
|
+
activeImg = nextImg
|
|
159
|
+
}
|
|
160
|
+
El.render(el)
|
|
161
|
+
}
|
|
162
|
+
})
|
|
163
|
+
|
|
164
|
+
%el Gallery
|
|
165
|
+
.Gallery.abs.max
|
|
166
|
+
img.Gallery-img
|
|
167
|
+
@load!flipIn
|
|
168
|
+
img.Gallery-img
|
|
169
|
+
.Gallery-nav
|
|
170
|
+
;if images.length > 1
|
|
171
|
+
@tap nav,"button"
|
|
172
|
+
button.Gallery-nav--prev[aria-label=Previous] ;txt! "\u276E"
|
|
173
|
+
button.Gallery-nav--next[aria-label=Next] ;txt! "\u276F"
|
|
174
|
+
.Gallery-counter
|
|
175
|
+
;txt (current+1)+" / "+images.length
|
|
176
|
+
|
|
177
|
+
%el ImageGrid
|
|
178
|
+
.ImageGrid.rel
|
|
179
|
+
;$s!{images:initGalleryImages($el)}
|
|
180
|
+
.ImageGrid-frame[data-index=0]
|
|
181
|
+
img ;src!images[0]
|
|
182
|
+
.ImageGrid-frame
|
|
183
|
+
;each! "src", images.slice(1, 4)
|
|
184
|
+
;data-index!$i+1
|
|
185
|
+
img ;src!src
|
|
186
|
+
.ImageGrid-count.p02 ;if images.length > 4
|
|
187
|
+
;txt '+' + (images.length - 4)
|