@lmjs/core 2.3.1 → 2.4.1
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/build/bundle.js +1 -0
- package/dist/lumenjs-core.js +2 -0
- package/package.json +1 -1
- package/src/update-check.js +109 -0
package/build/bundle.js
CHANGED
|
@@ -117,6 +117,7 @@ function buildCommonTail() {
|
|
|
117
117
|
parts.push(stripComments(read('walk.js')));
|
|
118
118
|
parts.push(stripComments(read('_re.js')));
|
|
119
119
|
parts.push(stripComments(read('reactive.js')));
|
|
120
|
+
parts.push(stripComments(read('update-check.js')));
|
|
120
121
|
|
|
121
122
|
// ws.js's `_Live` class needs ReconnectingWebSocket — a genuine small
|
|
122
123
|
// vendor dependency (not jQuery-related, nothing to shim), vendored
|
package/dist/lumenjs-core.js
CHANGED
|
@@ -15,6 +15,8 @@ var cl=console.log;var LumenJS_HTML_SNIFF_RE=/([&][a-zA-Z]*[;]+)|<\/?[a-z][\s\S]
|
|
|
15
15
|
|
|
16
16
|
var _reactiveEngines=[];var _rxMoustache=/\{\s*\{\s*([\s\S]*?)\s*\}\s*\}/g;var _rxVoid={area:1,base:1,basefont:1,bgsound:1,br:1,col:1,command:1,embed:1,frame:1,hr:1,image:1,img:1,input:1,isindex:1,keygen:1,link:1,menuitem:1,meta:1,nextid:1,param:1,source:1,track:1,wbr:1};var _rxSkip={};"break case catch class const continue debugger default delete do else export extends finally for function if import in instanceof let new return super switch this throw try typeof var void while with yield await async of static get set null true false undefined NaN Infinity Object Function Boolean Symbol Error Number BigInt Math Date String RegExp Array Map Set WeakMap WeakSet Promise Reflect Proxy Intl JSON console window document navigator location localStorage sessionStorage fetch setTimeout clearTimeout setInterval clearInterval parseInt parseFloat isFinite isNaN encodeURI decodeURI encodeURIComponent decodeURIComponent escape unescape globalThis".split(" ").forEach(function(w){_rxSkip[w]=1});var _rxExprCache=new Map;function _rxKeepOneSpace(t){t=t.replace(/\s\s/gm," ");if(/\s\s/gm.test(t))return _rxKeepOneSpace(t);return t}function _rxClean(t){t=t.replace(/(\r?\n|\r)/gm,"");t=t.replace(/(\t)/gm,"");t=_rxKeepOneSpace(t);return t.replace(/^(?:\s*\t*\r*\n*\{*)+|(?:\s*\t*\r*\n*\})+$/g,"").trim()}function _rxIdents(src,out){var i=0,n=src.length,prev="";function skipTemplate(){i++;while(i<n){var c=src[i];if(c==="\\"){i+=2;continue}if(c==="`"){i++;return}if(c==="$"&&src[i+1]==="{"){i+=2;var depth=1,start=i;while(i<n&&depth){var d=src[i];if(d==="`"){var s=i;skipTemplate();continue}if(d==="{")depth++;else if(d==="}"){depth--;if(!depth)break}else if(d==="'"||d==='"'){var q=d;i++;while(i<n&&src[i]!==q){if(src[i]==="\\")i++;i++}}i++}_rxIdents(src.slice(start,i),out);i++;continue}i++}}while(i<n){var ch=src[i];if(ch==="'"||ch==='"'){i++;while(i<n&&src[i]!==ch){if(src[i]==="\\")i++;i++}i++;prev="s";continue}if(ch==="`"){skipTemplate();prev="s";continue}if(ch==="/"&&src[i+1]==="/"){while(i<n&&src[i]!=="\n")i++;continue}if(ch==="/"&&src[i+1]==="*"){var e=src.indexOf("*/",i+2);i=e<0?n:e+2;continue}if(/\s/.test(ch)){i++;continue}if(/[0-9]/.test(ch)){while(i<n&&/[\w.]/.test(src[i]))i++;prev="n";continue}if(/[A-Za-z_$]/.test(ch)){var st=i;while(i<n&&/[\w$]/.test(src[i]))i++;var id=src.slice(st,i);var j=i;while(j<n&&/\s/.test(src[j]))j++;var isKey=src[j]===":"&&(prev==="{"||prev===",");if(prev!=="."&&!isKey&&!_rxSkip[id]&&out.indexOf(id)===-1)out.push(id);prev="i";continue}prev=ch;i++}return out}function _rxExpr(mux){var hit=_rxExprCache.get(mux);if(hit)return hit;var rv=null;try{new Function(mux);rv=_rxIdents(mux,[])}catch(e){rv=null}if(_rxExprCache.size>2e3)_rxExprCache.clear();_rxExprCache.set(mux,rv);return rv}function _rxEscape(s){return s.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">")}function _rxMustaches(text,escapeStatic,rvSet){var found=[],m,last=0;_rxMoustache.lastIndex=0;while((m=_rxMoustache.exec(text))!=null){var mux=_rxClean(m[0]);var rvs=_rxExpr(mux);if(rvs)found.push({index:m.index,len:m[0].length,mux,rvs})}if(!found.length)return{content:escapeStatic?_rxEscape(text):text,mss:[]};var esc=escapeStatic?_rxEscape:function(s){return s};var content="",mss=[];for(var k=0;k<found.length;k++){var f=found[k];content+=esc(text.substring(last,f.index));var start=content.length;content+="{{"+f.mux+"}}";mss.push({mus:f.mux,jst:null,rvs:f.rvs.slice(),start,end:content.length});for(var r=0;r<f.rvs.length;r++)rvSet[f.rvs[r]]=1;last=f.index+f.len}content+=esc(text.substring(last));return{content,mss}}function _rxForX(val){var forX={js:"",as:{k:"",v:""},dx:""};val=val.trim();if(val.indexOf(";")>-1){var zxx=val.split(";");forX.dx=zxx[1].trim();val=zxx[0].trim()}if(val.indexOf(" as ")>-1){var arr2=val.split(" as ");var arr3=arr2[1].split(" ").join("").split(",");forX.as.k=arr3[0].trim();if(arr3.length>1)forX.as.v=arr3[1].trim();val=arr2[0].trim()}forX.js=val.trim();return forX}function _rxCompileNode(n,ptag,rvSet){if(n.nodeType===3){var t=n.nodeValue;var mm=_rxMustaches(t,ptag!=="style",rvSet);if(ptag==="textarea"&&mm.mss.length)mm=_rxMustaches(t,false,rvSet);return{type:"text",content:mm.content,mss:mm.mss,tag:ptag}}if(n.nodeType!==1)return null;var name=n.localName;if(name==="script")return null;var res={type:"tag",name,isV:!!_rxVoid[name],attrs:{},ax:{},evs:{},ex:{},children:[]};if(n.namespaceURI==="http://www.w3.org/2000/svg")res.svg=true;var attrs=n.attributes;for(var a=0;a<attrs.length;a++){var an=attrs[a].name,av=attrs[a].value;if(an===":else"){res.type="section";res.cond=""}else if(an===":if"||an===":else-if"){res.type="section";res.cond=av;_rxIdents(av,[]).forEach(function(id){rvSet[id]=1})}else if(an===":for"){res.type="sections";res.content=av;res.forX=_rxForX(av);if(res.forX.js)_rxIdents(res.forX.js,[]).forEach(function(id){rvSet[id]=1})}var ms=_rxMustaches(an.charAt(0)==="@"?av:av.replace(/`(\{\s*\{[\s\S]*?\}\s*\})`/g,"$1"),false,rvSet);if(an.charAt(0)==="@"){res.evs[an]=ms.content;if(ms.mss.length)res.ex[an]=ms.mss}else{res.attrs[an]=ms.content;if(ms.mss.length)res.ax[an]=ms.mss}}_rxOrderIfFor(res);if(!res.isV){var kids=n.childNodes;for(var c=0;c<kids.length;c++){var ch=_rxCompileNode(kids[c],name,rvSet);if(ch)res.children.push(ch)}if(name==="style"&&!res.children.length)res.children.push({type:"text",content:"",mss:[],tag:"style"})}return res}function _rxOrderIfFor(res){if(!res||!res.attrs||!res.forX||!Object.prototype.hasOwnProperty.call(res.attrs,":if"))return;var keys=Object.keys(res.attrs);var cond=String(res.attrs[":if"]);if(keys.indexOf(":if")<keys.indexOf(":for"))res.forX.js="("+cond+") ? ("+res.forX.js+") : []";else res.attrs[":for-if"]=res.attrs[":for-if"]?"("+res.attrs[":for-if"]+") && ("+cond+")":cond;res.type="sections";delete res.cond;delete res.attrs[":if"];if(res.ax)delete res.ax[":if"]}function _rxCompileHost(host){var rvSet={},hst=[],kids=host.childNodes;for(var i=0;i<kids.length;i++){var c=_rxCompileNode(kids[i],host.localName,rvSet);if(c)hst.push(c)}return{hst,reactiveVars:Object.keys(rvSet)}}async function _rxRender(host){host.classList.add("binded");var compiled=_rxCompileHost(host);var sub=null;for(var p=host.parentNode;p;p=p.parentNode){if(p.isSub===true){sub=p;break}}var _re=await renderHST(compiled,"reactive","section",void 0,null,["View"],sub?sub.vars:void 0,sub?sub.fns:void 0);_re._blankUnresolved=true;var bindEl=host.closest("[bind]");if(bindEl){String(bindEl.getAttribute("bind")||"").split(",").forEach(function(v){var parts=v.trim().split(" as ");if(parts.length===2&&parts[0].trim()&&parts[1].trim()){try{_re.vrs[parts[1].trim()]=_re.scopedEval(_re.reactiveVariables,parts[0].trim())}catch(e){}}})}host.textContent="";host.append.apply(host,_re._RealDOM);_re._rxHost=host;_reactiveEngines.push(_re);_re.renderAll("section")}function _updateReactiveEngines(varName){for(var i=_reactiveEngines.length-1;i>=0;i--){var re=_reactiveEngines[i];if(!re._rxHost||!re._rxHost.isConnected){_reactiveEngines.splice(i,1);continue}try{re.update(varName)}catch(e){cl(e)}}}(function(){if(typeof MutationObserver==="undefined"||typeof document==="undefined"||!document.documentElement)return;var pending=[],running=false;function consider(node){if(!node||node.nodeType!==1||node._ownerRe)return;if(node.hasAttribute("reactive"))pending.push(node);if(node.firstElementChild){var found=node.querySelectorAll("[reactive]");for(var i=0;i<found.length;i++)pending.push(found[i])}}async function drain(){if(running)return;running=true;var rendered=0;try{while(pending.length){var h=pending.shift();if(!h.isConnected||h._ownerRe||h.classList.contains("binded"))continue;try{await _rxRender(h);rendered++}catch(e){reportLumenError({stage:"reactive",error:e})}}}finally{running=false}if(rendered&&typeof globalWatch==="function"){try{globalWatch()}catch(e){reportLumenError({stage:"reactive",error:e})}}}new MutationObserver(function(records){for(var r=0;r<records.length;r++){var added=records[r].addedNodes;for(var k=0;k<added.length;k++)consider(added[k])}if(pending.length)drain()}).observe(document.documentElement,{childList:true,subtree:true});function scan(){consider(document.documentElement);if(pending.length)drain()}if(document.readyState==="loading")document.addEventListener("DOMContentLoaded",scan);else setTimeout(scan,0)})();
|
|
17
17
|
|
|
18
|
+
var LM_BUILD=(function(){try{var m=/\/js\/app\.(\d+)\.js/.exec(document.currentScript&&document.currentScript.src||(function(){var s=document.querySelectorAll('script[src*="/js/app."]');return s.length?s[s.length-1].src:""})());return m?parseInt(m[1],10):0}catch(e){return 0}})();var LM_VERSION=(function(){if(!LM_BUILD)return"dev";var d=new Date(LM_BUILD);var p=function(n){return(n<10?"0":"")+n};return d.getUTCFullYear()+"."+p(d.getUTCMonth()+1)+"."+p(d.getUTCDate())+"."+p(d.getUTCHours())+p(d.getUTCMinutes())})();var _lmUpdateShown=false;function _lmUpdateOpts(){var o=typeof appSettings!=="undefined"&&appSettings?appSettings.updateCheck:void 0;if(o===false)return null;return o&&typeof o==="object"?o:{}}function _lmShowUpdateBar(opts,latest){if(_lmUpdateShown)return;_lmUpdateShown=true;var reload=function(){location.reload()};if(typeof opts.onUpdate==="function"){try{opts.onUpdate({current:LM_BUILD,latest,reload})}catch(e){cl(e)}return}if(!document.getElementById("lm-update-style")){var st=document.createElement("style");st.id="lm-update-style";st.textContent=".lm-update-bar{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);z-index:100001;display:flex;align-items:center;gap:14px;max-width:calc(100vw - 32px);padding:10px 12px 10px 18px;background:var(--color-card-background,#1c1c1e);border:1px solid var(--color-border--dark,#333);border-radius:12px;box-shadow:0 16px 40px -10px rgba(0,0,0,.55);color:var(--color-text,#e8e8e8);font-size:13px;font-family:inherit}.lm-update-go{background:#e5484d;color:#fff;border:0;border-radius:8px;padding:6px 14px;font-weight:700;cursor:pointer;font-size:13px}.lm-update-x{background:none;border:0;color:#8a8a8a;font-size:18px;line-height:1;cursor:pointer;padding:2px 4px}.lm-update-x:hover{color:var(--color-text,#e8e8e8)}";document.head.appendChild(st)}var bar=document.createElement("div");bar.className="lm-update-bar";bar.setAttribute("role","status");var msg=document.createElement("span");msg.textContent=opts.message||"A new version is available.";var go=document.createElement("button");go.type="button";go.className="lm-update-go";go.textContent=opts.buttonText||"Reload";go.onclick=reload;var x=document.createElement("button");x.type="button";x.className="lm-update-x";x.setAttribute("aria-label","Dismiss");x.textContent="\xD7";x.onclick=function(){if(bar.parentNode)bar.parentNode.removeChild(bar)};bar.appendChild(msg);bar.appendChild(go);bar.appendChild(x);document.body.appendChild(bar)}function lmCheckForUpdate(){var opts=_lmUpdateOpts();if(!opts||!LM_BUILD||_lmUpdateShown||typeof fetch!=="function")return Promise.resolve(false);var url=opts.url||"/";return fetch(url+(url.indexOf("?")>-1?"&":"?")+"_v="+Date.now(),{cache:"no-store",credentials:"same-origin"}).then(function(r){return r.ok?r.text():""}).then(function(html){var m=/\/js\/app\.(\d+)\.js/.exec(html||"");var latest=m?parseInt(m[1],10):0;if(latest>LM_BUILD){_lmShowUpdateBar(opts,latest);return true}return false}).catch(function(){return false})}(function(){if(!LM_BUILD)return;document.addEventListener("visibilitychange",function(){if(document.visibilityState==="visible")lmCheckForUpdate()});setTimeout(function(){lmCheckForUpdate();var o=_lmUpdateOpts();var every=o&&o.interval>0?o.interval:5*60*1e3;if(o)setInterval(lmCheckForUpdate,every)},15e3)})();
|
|
19
|
+
|
|
18
20
|
!(function(a,b){"function"==typeof define&&define.amd?define([],b):"undefined"!=typeof module&&module.exports?module.exports=b():a.ReconnectingWebSocket=b()})(this,function(){function a(b,c,d){function l(a2,b2){var c2=document.createEvent("CustomEvent");return c2.initCustomEvent(a2,false,false,b2),c2}var e={debug:false,automaticOpen:true,reconnectInterval:1e3,maxReconnectInterval:3e4,reconnectDecay:1,timeoutInterval:3e3};d||(d={});for(var f in e)this[f]="undefined"!=typeof d[f]?d[f]:e[f];this.url=b,this.reconnectAttempts=0,this.readyState=WebSocket.CONNECTING,this.protocol=null;var h,g=this,i2=false,j=false,k=document.createElement("div");k.addEventListener("open",function(a2){g.onopen(a2)}),k.addEventListener("close",function(a2){g.onclose(a2)}),k.addEventListener("connecting",function(a2){g.onconnecting(a2)}),k.addEventListener("message",function(a2){g.onmessage(a2)}),k.addEventListener("error",function(a2){g.onerror(a2)}),this.addEventListener=k.addEventListener.bind(k),this.removeEventListener=k.removeEventListener.bind(k),this.dispatchEvent=k.dispatchEvent.bind(k),this.open=function(b2){try{h=new WebSocket(g.url,c||[]),b2||k.dispatchEvent(l("connecting")),(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","attempt-connect",g.url);var d2=h,e2=setTimeout(function(){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","connection-timeout",g.url),j=true,j=false;if(d2.readyState==1)d2.close()},g.timeoutInterval);h.onopen=function(){clearTimeout(e2),(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onopen",g.url),g.protocol=h.protocol,g.readyState=WebSocket.OPEN,g.reconnectAttempts=0;var d3=l("open");d3.isReconnect=b2,b2=false,k.dispatchEvent(d3)},h.onclose=function(c2){if(clearTimeout(e3),h=null,i2)g.readyState=WebSocket.CLOSED,k.dispatchEvent(l("close"));else{g.readyState=WebSocket.CONNECTING;var d3=l("connecting");d3.code=c2.code,d3.reason=c2.reason,d3.wasClean=c2.wasClean,k.dispatchEvent(d3),b2||j||((g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onclose",g.url),k.dispatchEvent(l("close")));var e3=g.reconnectInterval*Math.pow(g.reconnectDecay,g.reconnectAttempts);setTimeout(function(){g.reconnectAttempts++,g.open(true)},e3>g.maxReconnectInterval?g.maxReconnectInterval:e3)}},h.onmessage=function(b3){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onmessage",g.url,b3.data);var c2=l("message");c2.data=b3.data,k.dispatchEvent(c2)},h.onerror=function(b3){(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","onerror",g.url,b3),k.dispatchEvent(l("error"))}}catch(error){console.error("WebSocket connection error:",error)}},1==this.automaticOpen&&this.open(false),this.send=function(b2){if(h)return(g.debug||a.debugAll)&&console.debug("ReconnectingWebSocket","send",g.url,b2),h.send(b2);throw"INVALID_STATE_ERR : Pausing to reconnect websocket"},this.close=function(a2,b2){"undefined"==typeof a2&&(a2=1e3),i2=true,h&&h.close(a2,b2)},this.refresh=function(){h&&h.readyState==1&&h.close()}}return a.prototype.onopen=function(){},a.prototype.onclose=function(){},a.prototype.onconnecting=function(){},a.prototype.onmessage=function(){},a.prototype.onerror=function(){},a.debugAll=false,a.CONNECTING=WebSocket.CONNECTING,a.OPEN=WebSocket.OPEN,a.CLOSING=WebSocket.CLOSING,a.CLOSED=WebSocket.CLOSED,a});let _isTipped=false;var _debugMode=false;var _initialized=null;var _dbcrs={};var _dbcrsTime=200;var _tickTime=20;var _scW=0;var cl=console.log;if(!_vcData)var _vcData=void 0;if(!_beaTn)var _beaTn=void 0;var beas;var appSettings;var execEl="";var currentlyValidTags=new Array;var _upwrk=new WebWorker("_upw");var _csswrk=new WebWorker("_cssw");_csswrk.start();var _ups=[];(function(e,t2){typeof module!="undefined"&&module.exports?module.exports=t2():typeof define=="function"&&define.amd?define(t2):this[e]=t2()})("bea",function(){function p(e2,t3){for(var n3=0,i3=e2.length;n3<i3;++n3)if(!t3(e2[n3]))return r2;return 1}function d(e2,t3){p(e2,function(e3){return t3(e3),1})}function v(e2,t3,n3){function g(e3){return e3.call?e3():u[e3]}function y(){if(!--h2){u[o2]=1,s2&&s2();for(var e3 in f)p(e3.split("|"),g)&&!d(f[e3],g)&&(f[e3]=[])}}e2=e2[i2]?e2:[e2];var r3=t3&&t3.call,s2=r3?t3:n3,o2=r3?e2.join(""):t3,h2=e2.length;return setTimeout(function(){d(e2,function t4(e3,n4){if(e3===null)return y();/*!n &&
|
|
19
21
|
!/^https?:\/\//.test(e) &&
|
|
20
22
|
c &&
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lmjs/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.4.1",
|
|
4
4
|
"description": "LumenJS reactive core runtime — the reactive engine, HTML/JS AST compiler, realtime socket client, and delegated event listeners powering LumenJS applications.",
|
|
5
5
|
"files": [
|
|
6
6
|
"dist/",
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
// "A new version is available — Reload" for built apps (ported from console.roxyon.com, 2026-10-02).
|
|
2
|
+
// `lm build` fingerprints the bundle as /js/app.<ms-epoch>.js in index.html. The running page reads its own stamp
|
|
3
|
+
// from its <script src>, then periodically fetches a fresh index.html and compares: a newer stamp means a deploy
|
|
4
|
+
// happened since this tab loaded. Off under `lm serve` (the runtime is /js/lm.js there: no stamp).
|
|
5
|
+
//
|
|
6
|
+
// Reactor({ updateCheck: false }) turn it off
|
|
7
|
+
// Reactor({ updateCheck: {
|
|
8
|
+
// interval: 300000, ms between checks (also checks 15s after load and on tab focus)
|
|
9
|
+
// message: "A new version is available.",
|
|
10
|
+
// buttonText: "Reload",
|
|
11
|
+
// url: "/", page whose HTML carries the current stamp
|
|
12
|
+
// onUpdate: function (info) { ... } replaces the built-in bar: info = { current, latest, reload() }
|
|
13
|
+
// } })
|
|
14
|
+
// Globals: LM_BUILD (this page's stamp, 0 in dev), LM_VERSION ("YYYY.MM.DD.HHMM" UTC, "dev"), lmCheckForUpdate().
|
|
15
|
+
var LM_BUILD = (function () {
|
|
16
|
+
try {
|
|
17
|
+
var m = /\/js\/app\.(\d+)\.js/.exec(
|
|
18
|
+
(document.currentScript && document.currentScript.src) ||
|
|
19
|
+
(function () {
|
|
20
|
+
var s = document.querySelectorAll('script[src*="/js/app."]');
|
|
21
|
+
return s.length ? s[s.length - 1].src : '';
|
|
22
|
+
})()
|
|
23
|
+
);
|
|
24
|
+
return m ? parseInt(m[1], 10) : 0;
|
|
25
|
+
} catch (e) { return 0; }
|
|
26
|
+
})();
|
|
27
|
+
var LM_VERSION = (function () {
|
|
28
|
+
if (!LM_BUILD) return 'dev';
|
|
29
|
+
var d = new Date(LM_BUILD);
|
|
30
|
+
var p = function (n) { return (n < 10 ? '0' : '') + n; };
|
|
31
|
+
return d.getUTCFullYear() + '.' + p(d.getUTCMonth() + 1) + '.' + p(d.getUTCDate()) + '.' + p(d.getUTCHours()) + p(d.getUTCMinutes());
|
|
32
|
+
})();
|
|
33
|
+
|
|
34
|
+
var _lmUpdateShown = false;
|
|
35
|
+
|
|
36
|
+
function _lmUpdateOpts() {
|
|
37
|
+
var o = (typeof appSettings !== 'undefined' && appSettings) ? appSettings.updateCheck : undefined;
|
|
38
|
+
if (o === false) return null;
|
|
39
|
+
return (o && typeof o === 'object') ? o : {};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function _lmShowUpdateBar(opts, latest) {
|
|
43
|
+
if (_lmUpdateShown) return;
|
|
44
|
+
_lmUpdateShown = true;
|
|
45
|
+
var reload = function () { location.reload(); };
|
|
46
|
+
if (typeof opts.onUpdate === 'function') {
|
|
47
|
+
try { opts.onUpdate({ current: LM_BUILD, latest: latest, reload: reload }); } catch (e) { cl(e); }
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
if (!document.getElementById('lm-update-style')) {
|
|
51
|
+
var st = document.createElement('style');
|
|
52
|
+
st.id = 'lm-update-style';
|
|
53
|
+
st.textContent =
|
|
54
|
+
'.lm-update-bar{position:fixed;left:50%;bottom:22px;transform:translateX(-50%);z-index:100001;display:flex;' +
|
|
55
|
+
'align-items:center;gap:14px;max-width:calc(100vw - 32px);padding:10px 12px 10px 18px;' +
|
|
56
|
+
'background:var(--color-card-background,#1c1c1e);border:1px solid var(--color-border--dark,#333);border-radius:12px;' +
|
|
57
|
+
'box-shadow:0 16px 40px -10px rgba(0,0,0,.55);color:var(--color-text,#e8e8e8);font-size:13px;font-family:inherit}' +
|
|
58
|
+
'.lm-update-go{background:#e5484d;color:#fff;border:0;border-radius:8px;padding:6px 14px;font-weight:700;cursor:pointer;font-size:13px}' +
|
|
59
|
+
'.lm-update-x{background:none;border:0;color:#8a8a8a;font-size:18px;line-height:1;cursor:pointer;padding:2px 4px}' +
|
|
60
|
+
'.lm-update-x:hover{color:var(--color-text,#e8e8e8)}';
|
|
61
|
+
document.head.appendChild(st);
|
|
62
|
+
}
|
|
63
|
+
var bar = document.createElement('div');
|
|
64
|
+
bar.className = 'lm-update-bar';
|
|
65
|
+
bar.setAttribute('role', 'status');
|
|
66
|
+
var msg = document.createElement('span');
|
|
67
|
+
msg.textContent = opts.message || 'A new version is available.';
|
|
68
|
+
var go = document.createElement('button');
|
|
69
|
+
go.type = 'button';
|
|
70
|
+
go.className = 'lm-update-go';
|
|
71
|
+
go.textContent = opts.buttonText || 'Reload';
|
|
72
|
+
go.onclick = reload;
|
|
73
|
+
var x = document.createElement('button');
|
|
74
|
+
x.type = 'button';
|
|
75
|
+
x.className = 'lm-update-x';
|
|
76
|
+
x.setAttribute('aria-label', 'Dismiss');
|
|
77
|
+
x.textContent = '×';
|
|
78
|
+
x.onclick = function () { if (bar.parentNode) bar.parentNode.removeChild(bar); };
|
|
79
|
+
bar.appendChild(msg); bar.appendChild(go); bar.appendChild(x);
|
|
80
|
+
document.body.appendChild(bar);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function lmCheckForUpdate() {
|
|
84
|
+
var opts = _lmUpdateOpts();
|
|
85
|
+
if (!opts || !LM_BUILD || _lmUpdateShown || typeof fetch !== 'function') return Promise.resolve(false);
|
|
86
|
+
var url = opts.url || '/';
|
|
87
|
+
return fetch(url + (url.indexOf('?') > -1 ? '&' : '?') + '_v=' + Date.now(), { cache: 'no-store', credentials: 'same-origin' })
|
|
88
|
+
.then(function (r) { return r.ok ? r.text() : ''; })
|
|
89
|
+
.then(function (html) {
|
|
90
|
+
var m = /\/js\/app\.(\d+)\.js/.exec(html || '');
|
|
91
|
+
var latest = m ? parseInt(m[1], 10) : 0;
|
|
92
|
+
if (latest > LM_BUILD) { _lmShowUpdateBar(opts, latest); return true; }
|
|
93
|
+
return false;
|
|
94
|
+
})
|
|
95
|
+
.catch(function () { return false; });
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
(function () {
|
|
99
|
+
if (!LM_BUILD) return;
|
|
100
|
+
document.addEventListener('visibilitychange', function () {
|
|
101
|
+
if (document.visibilityState === 'visible') lmCheckForUpdate();
|
|
102
|
+
});
|
|
103
|
+
setTimeout(function () {
|
|
104
|
+
lmCheckForUpdate();
|
|
105
|
+
var o = _lmUpdateOpts();
|
|
106
|
+
var every = o && o.interval > 0 ? o.interval : 5 * 60 * 1000;
|
|
107
|
+
if (o) setInterval(lmCheckForUpdate, every);
|
|
108
|
+
}, 15000);
|
|
109
|
+
})();
|