This repository has been archived by the owner on Sep 27, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
retrov.min.js
1 lines (1 loc) · 2.63 KB
/
retrov.min.js
1
!function(){var e=[];function t(e,t,c,f){var l=e.childNodes[f];if(void 0!==c)if(!1!==c.t){if("["===c.t)return 0===c.c.length?void e.replaceChildren(n("array")):void i(e,t&&t.c?t.c:[],c.c);void 0!==t?t.t===c.t?c.t&&"!"!==c.t&&function(e,t,r){if(!e)return void console.error("No DOM element here to update from Old:",t," to New:",r);if('"'===r.t)return void(e.data=r.text);if("<"===r.t)return;Object.keys(r.p).forEach(function(n){"style"!==n?"value"!==n&&"checked"!==n?r.p[n]!==t.p[n]&&(e[n]=r.p[n]):e[n]=r.p[n]:o(e,t,r)}),i(e,t.c,r.c)}(l,t,c):l.replaceWith(r(c)):e.appendChild(r(c))}else void 0===t&&e.append(n("false"));else e.removeChild(l)}function r(t){if('"'===t.t)return document.createTextNode(t.text);if(null===t.t)return n("null");if(!1===t.t)return n("false");if("!"===t.t)return n("undefined");if("<"===t.t)return i=t.html,(c=document.createElement("div")).innerHTML=i,c.childNodes[0];var i,c;try{var f=document.createElement(t.t)}catch(e){throw e instanceof DOMException&&console.error("RetroV: Bad element name: ",t.t),e}return Object.keys(t.p).forEach(function(r){"style"!==r?"for"!==r?"oncreate"!==r||"function"!=typeof t.p[r]?f[r]=t.p[r]:e.push({el:f,fn:t.p[r]}):f.htmlFor=t.p.for:o(f,{},t)}),t.c.forEach(function(e){f.append(r(e))}),f}function n(e){return document.createComment("RV:"+e+"-placeholder")}function o(e,t,r){var n=t.p&&t.p.style?t.p.style:{};Object.keys(r.p.style).forEach(function(t){r.p.style[t]!=n[t]&&(e.style[t]=r.p.style[t])})}function i(e,r,n){if(r.length>n.length)for(var o=r.length-1;o>=0;o--)t(e,r[o],n[o],o);else for(o=0;o<n.length;o++)t(e,r[o],n[o],o)}function c(e){if("string"==typeof e||"number"==typeof e)return{t:'"',text:e};if(Array.isArray(e)&&"string"!=typeof e[0])return{t:"[",c:e.map(c)};if(Array.isArray(e)&&"string"==typeof e[0]&&"<"===e[0][0])return{t:"<",html:e};if(null===e)return{t:null};if(!1===e)return{t:!1};if(void 0===e)return{t:"!"};if(Array.isArray(e)&&"string"==typeof e[0]){var t=1,r={};e[1]&&"object"==typeof e[1]&&!Array.isArray(e[1])&&(void 0!==(r=e[1]).class&&(r.className=r.class,delete r.class),void 0!==r.for&&(r.htmlFor=r.for,delete r.for),t=2);var n=e[0],o=[],i=n.split("."),f=i.shift();return 0===f.length&&(f="div"),i.forEach(function(e){o.push(e)}),o.length>0&&(r.className=r.className?r.className+" "+o.join(" "):o.join(" ")),{t:f,p:r,c:function e(t){var r=[];t.forEach(function(t){Array.isArray(t)&&"string"!=typeof t[0]?e(t).forEach(function(e){r.push(e)}):r.push(c(t))});return r}(e.slice(t))}}console.error("RetroV: make_obj() cannot handle this:",e)}window.RV={render:function(r,n){var o,i=c(n);r.rv_old_v?o=r.rv_old_v:r.replaceChildren(),r.rv_old_v=i,t(r,o,i,0),e.forEach(function(e){e.fn(e.el)}),cc=[]}}}();