@litejs/ui 25.1.0 → 25.10.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/load.js CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  /*! litejs.com/MIT-LICENSE.txt */
3
3
 
4
- /* global location */
4
+ /* global document, location */
5
5
 
6
6
  // With initial congestion window set to 2 and 1452 bytes of data in a segment.
7
7
  // - 1 round trip to get 2904 bytes, Initial Window (IW) = 2
@@ -18,46 +18,43 @@
18
18
  // xhr("PUT", url).send(null) Works in all major browsers
19
19
 
20
20
 
21
- !function(window, Function) {
22
- var initTime = xhr._t = +new Date()
23
- , rewrite = {
21
+ !function(window) {
22
+ var rewrite = {
24
23
  //!{loadRewrite}
25
24
  }
26
- // Move setTimeout from window.prototype to window object for future patching in IE9.
27
- , setTimeout_ = window.setTimeout = setTimeout
28
- /*** debug ***/
29
- // Expose xhr._c for testing.
30
- , loaded = xhr._c = {}
31
- /*/
32
- , loaded = {}
33
- /**/
34
-
35
- /*** activex ***/
36
- // XMLHttpRequest in IE7-8 do not accept PATCH, use ActiveX.
37
- // IE disallows adding custom properties to ActiveX objects and read/write readystatechange after send().
38
- , XMLHttpRequest = +"\v1" && window.XMLHttpRequest || Function("return new ActiveXObject('Microsoft.XMLHTTP')")
25
+ /*** log ***/
26
+ , initTime = xhr._t = +new Date()
39
27
  /**/
28
+ // Expose xhr._c for testing.
29
+ , loaded = /*** debug ***/ xhr._c = /**/ {}
40
30
 
31
+ /*** ie9 ***/
32
+ , Fn = Function
33
+ , nop = Fn()
41
34
  , execScript =
42
35
  // IE5-10, Chrome1-12
43
36
  window.execScript ||
44
- /*** inject ***/
45
37
  // THANKS: Juriy Zaytsev - Global eval [http://perfectionkills.com/global-eval-what-are-the-options/]
46
38
  // In case of local execution `e('eval')` returns undefined
47
- Function("e,eval", "try{return e('eval')}catch(e){}")(eval) ||
48
- Function("a", "var d=document,b=d.body,s=d.createElement('script');s.text=a;b.removeChild(b.insertBefore(s,b.firstChild))")
49
- /*/
50
- eval
51
- /**/
52
- , nop = Function()
39
+ Fn("e,eval", "try{return e('eval')}catch(e){}")(eval) ||
40
+ Fn("a", "var d=document,b=d.body,s=d.createElement('script');s.text=a;b.appendChild(s)")
41
+
42
+ // Move setTimeout from window.prototype to window object for future patching in IE9.
43
+ , setTimeout_ = window.setTimeout = setTimeout
53
44
 
54
- /*** reuse ***/
55
45
  // XHR memory leak mitigation
56
46
  , xhrs = []
47
+
48
+ // XMLHttpRequest in IE7-8 do not accept PATCH, use ActiveX.
49
+ // IE disallows adding custom properties to ActiveX objects and read/write readystatechange after send().
50
+ , XMLHttpRequest = +"\v1" && window.XMLHttpRequest || Fn("return new ActiveXObject('Microsoft.XMLHTTP')")
51
+ /*/
52
+ , execScript = eval
53
+ , setTimeout_ = setTimeout
57
54
  /**/
58
55
 
56
+ /*** log ***/
59
57
  , unsentLog = xhr._l = []
60
- /*** onerror ***/
61
58
  , lastError
62
59
  , onerror = window.onerror = function(message, file, line, col, error) {
63
60
  // Do not send multiple copies of the same error.
@@ -68,26 +65,33 @@
68
65
  , col || (window.event || unsentLog).errorCharacter || "?"
69
66
  , message
70
67
  ].join(":")
71
- )) log("e", lastError, (error && (error.stack || error.stacktrace) || "-") + "\n" + location)
68
+ )) log("e", lastError, [error && (error.stack || error.stacktrace) || "-", "" + location])
69
+ }
70
+ , log = xhr.log = function(type, msg, extra) {
71
+ if (unsentLog.push([new Date() - initTime, type].concat(msg, extra || [])) < 2) sendLog()
72
+ function sendLog() {
73
+ setTimeout_(xhr.sendLog || sendLog, 1307)
74
+ }
72
75
  }
73
- /*/
74
- , onerror = nop
75
76
  /**/
76
77
 
77
- xhr.log = log
78
- function log(type, msg, extra) {
79
- if (unsentLog.push([ new Date() - initTime, type, msg, extra ]) < 2) sendLog()
80
- }
81
78
 
82
- function sendLog() {
83
- setTimeout_(xhr.sendLog || sendLog, 1307)
79
+ /*** theme ***/
80
+ , ALT_THEME = "dark"
81
+ , matchMedia = window.matchMedia
82
+ , localStorage = window.localStorage
83
+ if (ALT_THEME == (
84
+ localStorage && localStorage.theme ||
85
+ matchMedia && matchMedia("(prefers-color-scheme:dark)").matches && ALT_THEME
86
+ )) {
87
+ document.documentElement.className = "is-" + ALT_THEME
84
88
  }
85
-
86
- // next === true is for sync call
89
+ /**/
87
90
 
88
91
  window.xhr = xhr
92
+ // next === true is for sync call
89
93
  function xhr(method, url, next, attr1, attr2) {
90
- var req = /*** reuse ***/ xhrs.pop() || /**/ new XMLHttpRequest()
94
+ var req = /*** ie9 ***/ xhrs.pop() || /**/ new XMLHttpRequest()
91
95
 
92
96
  // To be able to reuse the XHR object properly,
93
97
  // use the open method first and set onreadystatechange later.
@@ -160,9 +164,12 @@
160
164
  attr1,
161
165
  attr2
162
166
  )
167
+ /*** ie9 ***/
168
+ // ActiveXObject does not accept `null` for onreadystatechange
163
169
  req.onreadystatechange = next = nop
164
- /*** reuse ***/
165
170
  xhrs.push(req)
171
+ /*/
172
+ req.onreadystatechange = next = null
166
173
  /**/
167
174
  }
168
175
  }
@@ -193,7 +200,7 @@
193
200
 
194
201
  function cb(err, str, fileName, filePos) {
195
202
  loaded[fileName] = 2
196
- res[filePos] = err ? (onerror(err, fileName), "") : str
203
+ res[filePos] = err ? (/*** log ***/ onerror(err, fileName),/**/ "") : str
197
204
  exec()
198
205
  }
199
206
  function exec() {
@@ -211,14 +218,16 @@
211
218
  })
212
219
  }
213
220
  } catch(e) {
221
+ /*** log ***/
214
222
  onerror(e, files[pos])
223
+ /**/
215
224
  }
216
225
  res[pos] = ""
217
226
  }
218
227
  }
219
228
  if (res[pos] === "" || !files[pos]) {
220
229
  if (++pos < len) exec()
221
- /*** inject ***/
230
+ /*** ie9 ***/
222
231
  // inject can be async
223
232
  else if (pos === len && execScript !== eval) setTimeout_(exec, 1)
224
233
  /**/
@@ -237,5 +246,5 @@
237
246
  ])
238
247
  /**/
239
248
 
240
- }(this, Function) // jshint ignore:line
249
+ }(this) // jshint ignore:line
241
250
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@litejs/ui",
3
- "version": "25.1.0",
3
+ "version": "25.10.0",
4
4
  "description": "UI engine for LiteJS full-stack framework",
5
5
  "license": "MIT",
6
6
  "author": "Lauri Rooden <lauri@rooden.ee>",
@@ -15,15 +15,18 @@
15
15
  "main": "ui.js",
16
16
  "files": [
17
17
  "*.js",
18
+ "bin",
18
19
  "binding",
19
20
  "css",
20
21
  "el"
21
22
  ],
23
+ "bin": {
24
+ "lj-extract-lang": "./bin/extract-lang.js"
25
+ },
22
26
  "scripts": {
23
27
  "test": "lj t"
24
28
  },
25
29
  "devDependencies": {
26
- "@litejs/cli": "25.1.1",
27
- "@litejs/dom": "25.1.0"
30
+ "@litejs/cli": "25.5.0"
28
31
  }
29
32
  }
package/shim.js CHANGED
@@ -17,13 +17,14 @@
17
17
  /* c8 ignore start */
18
18
  !function(window, Date, Function, Infinity, P) {
19
19
 
20
- // Array#flat() - Chrome69, Edge79, Firefox62, Safari12
21
- // window.PointerEvent - Chrome55, Edge12, Firefox59, Safari13, IE11
22
- // navigator.sendBeacon - Chrome39, Edge14, Firefox31, Safari11.1
23
- // Object.fromEntries - Chrome73, Edge79, Firefox63, Safari12.1, Opera60, Node.js12.0.0
24
- // queueMicrotask - Chrome71, Edge79, Firefox69, Safari12.1
25
-
26
- var UNDEF, isArray, oKeys
20
+ // Array#flat() - Chrome69, Firefox62, Safari12
21
+ // window.PointerEvent - Chrome55, Firefox59, Safari13, IE11
22
+ // navigator.sendBeacon - Chrome39, Firefox31, Safari11.1
23
+ // Object.fromEntries - Chrome73, Firefox63, Safari12.1, Opera60, Node.js12.0.0
24
+ // queueMicrotask - Chrome71, Firefox69, Safari12.1
25
+ // "".at(), [].at() - Chrome92, Firefox90, Safari15.4
26
+
27
+ var UNDEF, canCapture, isArray, oKeys
27
28
  , O = window
28
29
  , patched = (window.xhr || window)._p = []
29
30
  , jsonRe = /[\x00-\x1f\x22\x5c]/g
@@ -35,7 +36,7 @@
35
36
  , IS_NODE = !window.document
36
37
  , document = patch("document", {body:{},documentElement:{}})
37
38
  , location = patch("location", {href:""})
38
- , navigator = patch("navigator")
39
+ , navigator = patch("navigator", {})
39
40
  /*/
40
41
  , document = window.document
41
42
  , IS_NODE = false
@@ -110,7 +111,8 @@
110
111
  patch(b, a, ie6789, isFn)
111
112
 
112
113
  // 20 fps is good enough
113
- patch("request" + (a = "AnimationFrame"), "return setTimeout(a,50)")
114
+ a = "AnimationFrame"
115
+ patch("request" + a, "return setTimeout(a,50)")
114
116
  // window.mozRequestAnimationFrame || // Firefox 4-23
115
117
  // window.webkitRequestAnimationFrame || // Chrome 10-24
116
118
  // window.msRequestAnimationFrame || // IE 10 PP2+
@@ -245,7 +247,7 @@
245
247
  }
246
248
 
247
249
  createStorage("session") // Chrome5, FF2, IE8, Safari4
248
- createStorage("local") // Chrome5, FF3.5, IE8, Safari4
250
+ createStorage("local") // Chrome5, FF3.5, IE8, Safari4, IE8
249
251
 
250
252
  // IE8 has console, however, the console object does not exist if the console is not opened.
251
253
  patch("console", {log: nop, error: nop})
@@ -285,15 +287,21 @@
285
287
  // https://bugzilla.mozilla.org/show_bug.cgi?id=666448
286
288
  patch("escape", "return X(a)", esc("a", 0) != "a", esc)
287
289
 
288
- // From Chrome23/Firefox21 parseInt parses leading-zero strings as decimal, not octal
290
+ // Since Chrome23/Firefox21 parseInt parses leading-zero strings as decimal, not octal
289
291
  b = patch("g:parseInt", "return X(a,(b>>>0)||(Y.test(''+a)?16:10))", _parseInt("08") !== 8, _parseInt, /^\s*[-+]?0[xX]/)
290
292
 
291
293
  O = Number
292
294
  patch("parseInt", b)
293
295
  patch("parseFloat", parseFloat)
294
296
  patch("isNaN", "return a!==a")
295
- patch("isInteger", "return X(a)&&Math.floor(a)===a", 0, patch("isFinite", "return typeof a==='number'&&isFinite(a)"))
296
- patch("isSafeInteger", "return a<=X", 0, patch("MAX_SAFE_INTEGER", 9007199254740991))
297
+ a = Math.pow
298
+ c = "_SAFE_INTEGER"
299
+ patch("EPSILON", a(2, -52))
300
+ patch(
301
+ "isSafeInteger", "return Y(a)&&a>=X&&a<=-X", 0,
302
+ patch("MIN" + c, -patch("MAX" + c, a(2, 53)-1)),
303
+ patch("isInteger", "return X(a)&&a%1===0", 0, patch("isFinite", "return typeof a==='number'&&isFinite(a)"))
304
+ )
297
305
 
298
306
  O = Date
299
307
  patch("now", "return+new Date")
@@ -384,8 +392,11 @@
384
392
  patch("flatMap", "return X.apply(t,A).flat()", 0, O.map)
385
393
  //patch("entries", "a=this;b=-1;return{next:function(){c=a.length<=++b;return{done:c,value:c?void 0:a[b]}}}")
386
394
 
395
+ a = "b=t.length;a=a<0?b+a|0:a|0;return a>=b||a<0?X:t"
396
+ patch("at", a + "[a]")
387
397
 
388
398
  O = String[P]
399
+ patch("s:at", a + ".charAt(a)")
389
400
  patch("endsWith", "return(a+='')===t.slice(-a.length)")
390
401
  patch("startsWith", "return t.lastIndexOf(a,0)===0")
391
402
  patch("trim", "return t.replace(/^\\s+|\\s+$/g,'')")
@@ -430,10 +441,21 @@
430
441
  , closest = patch("closest", walk.bind(window, "parentNode", 1))
431
442
  , matches = patch("matches", "return!!X(a)(t)", 0, selectorFn)
432
443
 
444
+ try {
445
+ O[a = "addEventListener"]("t", null, Object.defineProperties({}, {
446
+ capture: { get: function() { canCapture = 1 } }
447
+ }))
448
+ b = "removeEventListener"
449
+ c = "O.call(t,a,b,X(c)?!!c.capture:!!c)"
450
+ if (!canCapture) {
451
+ patch("c:" + a, c, 1, isObj)
452
+ patch("c:" + b, c, 1, isObj)
453
+ }
454
+ } catch(e){}
433
455
  // The addEventListener is supported in Internet Explorer from version 9.
434
456
  // https://developer.mozilla.org/en-US/docs/Web/Reference/Events/wheel
435
457
  // - IE8 always prevents the default of the mousewheel event.
436
- patch("addEventListener", "return(t.attachEvent('on'+a,b=X(t,a,b)),b)", 0, function(el, ev, fn) {
458
+ patch(a, "return(t.attachEvent('on'+a,b=X(t,a,b)),b)", 0, function(el, ev, fn) {
437
459
  return function() {
438
460
  var e = new Event(ev)
439
461
  if (e.clientX !== UNDEF) {
@@ -443,7 +465,8 @@
443
465
  fn.call(el, e)
444
466
  }
445
467
  })
446
- patch("removeEventListener", "t.detachEvent('on'+a,b)")
468
+ patch(b, "t.detachEvent('on'+a,b)")
469
+
447
470
 
448
471
  // Note: querySelector in IE8 supports only CSS 2.1 selectors
449
472
  patch((a = "querySelector"), (b = "return X(t,a,Y)"), ie678, find, 1)
@@ -515,6 +538,9 @@
515
538
  function isStr(value) {
516
539
  return typeof value === "string"
517
540
  }
541
+ function isObj(obj) {
542
+ return !!obj && obj.constructor === Object
543
+ }
518
544
  function nop() {}
519
545
 
520
546
  function patch(key_, src, force, arg1, arg2) {
@@ -522,7 +548,6 @@
522
548
  return !force && O[key] || (O[patched.push(key_), key] = (
523
549
  isStr(src) ?
524
550
  Function("o,O,P,S,F,X,Y", "return function(a,b,c){var t=this,A=arguments;" + src + "}")(hasOwn, O[key], P, patched.slice, force, arg1, arg2) :
525
- src === UNDEF ? {} :
526
551
  src
527
552
  ))
528
553
  }