Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

literaljs

Package Overview
Dependencies
Maintainers
1
Versions
69
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

literaljs - npm Package Compare versions

Comparing version 2.3.2 to 2.4.0

2

build/index.js

@@ -1,2 +0,2 @@

var e={},t=[],n=[],r=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?r(e[n],t):t.push(e[n]);return t},i=function(e,n){return window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var r=t.pop();return d(e,n,{oldState:r.oldState,newState:r.newState})})})},o=function(){var e=function(){return setTimeout(function(){for(var e;e=n.pop();)e()})};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},d=function(e,t,n){var r=u(t(),n.oldState),i=u(t(),n.newState);return p(e,i,r)},u=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=u(e.children[n],t);return e},a=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,u=Object.entries(e);d<u.length;d+=1){var v=u[d],f=v[0],l=v[1];if("text"===f&&o.appendChild(document.createTextNode(l)),"events"===f&&c(l,o,n,r),["children","element","text","events"].includes(f)||o.setAttribute(f,l),"children"===f)for(var s=0;s<l.length;s++)o.appendChild(a(l[s],{mount:n,initial:r}))}return o},c=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),v(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),v(e,n,r)},v=function(e,t,r){if(r){var i=function(e){return n.push(e)};t&&"mounted"===e.type&&i(e.action),t||"updated"!==e.type||i(e.action),l()}},f=function(e,t){if(e.events){if(Array.isArray(e.events))for(var r=0;r<e.events.length;r++)e.events[r].type===t&&n.push(e.events[r].action);else e.events.type===t&&n.push(e.events.action);l()}},l=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},s=function(t){return void 0===t&&(t=e),Object.assign({},t)},h=function(n){var r=s(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},p=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?(f(t,"mounted"),e.insertBefore(a(t),i)):void 0===n?(f(t,"mounted"),e.appendChild(a(t))):0===n&&g(e,i,t);else if(!t&&n)f(n,"unmounted"),e.removeChild(i);else if(t&&(_(i,t,n),E(e,i,t,n),t.children||n.children))for(var o=m(t.children,n.children),d=o.newChildren,u=o.oldChildren,c=0;c<y(d,u);c++)p(i,d[c],u[c],c)}},m=function(e,t){for(var n=[],r=[],i=0;i<y(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},y=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},E=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&g(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];if("element"===u||"text"===u)a!==c&&g(e,t,n);else if(!(["children","events","element","text"].includes(u)||c&&a===c))return f(n,"updated"),t.setAttribute(name,value)}},_=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(f(t,"updated"),e.removeAttribute(d))}},g=function(e,t,n){f(n,"mounted"),e.replaceChild(a(n,{mount:!1}),t)};module.exports={component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:s(r),getState:s,setState:h,props:e,methods:t({getState:s,setState:h})})}}},render:function(t,n,r){void 0===r&&(r={});var d=document.getElementById(n);e=Object.assign({},e,r),i(d,t);var c=u(t(),e),v=a(c,{initial:!0});d.appendChild(v),o()},h:function(e,t){for(var n=[],i=arguments.length-2;i-- >0;)n[i]=arguments[i+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:r(n,[])})}};
var e={},t=[],n=[];module.exports={component:function(n){void 0===n&&(n={});var r=n.methods;void 0===r&&(r=function(){});var i=n.render;return void 0===i&&(i=function(){}),function(n){return void 0===n&&(n={}),function(o){var d=function(t){return void 0===t&&(t=e),Object.assign({},t)},u=function(n){var r=d(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)};return i({state:d(o),getState:d,setState:u,props:n,methods:r({getState:d,setState:u})})}}},render:function(r,i,o){void 0===o&&(o={});var d=document.getElementById(i);function u(){var e;return setTimeout(function(){for(;e=n.pop();)e()})}function a(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=a(e.children[n],t);return e}function c(e,t){void 0===t&&(t={});var r=t.mount;void 0===r&&(r=!0);var i=t.initial;void 0===i&&(i=!1);var o=typeof e;if("object"!==o&&"boolean"!==o)return document.createTextNode(e);for(var d=document.createElement(e.element),u=0,a=Object.entries(e);u<a.length;u+=1){var l=a[u],f=l[0],s=l[1];if("text"===f&&d.appendChild(document.createTextNode(s)),"events"===f&&p(s,d,r,i),["children","element","text","events"].includes(f)||d.setAttribute(f,s),"children"===f)for(var h=0;h<s.length;h++)d.appendChild(c(s[h],{mount:r,initial:i}))}return d;function p(e,t,r,i){for(var o=0,d=Object.entries(e);o<d.length;o+=1){var u=d[o],a=u[0],c=u[1];["mounted","unmounted","updated"].includes(a)||t.addEventListener(a,c),l(a,c,r,i)}function l(e,t,r,i){i&&(r&&"mounted"===e&&n.push(t),r||"updated"!==e||n.push(t),v())}}}function v(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)}e=Object.assign({},e,o),window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var e=t.pop();return function e(t,r,i,o){if(void 0===o&&(o=0),t){var d=t.childNodes[o];if(!i&&r)!1===i?(t.insertBefore(c(r),d),p(r,"mounted")):void 0===i?(t.appendChild(c(r)),p(r,"mounted")):0===i&&h(t,d,r);else if(!r&&i)t.removeChild(d),p(i,"unmounted");else if(r&&(function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];t[d]||(e.removeAttribute(u),p(t,"updated"))}}(d,r,i),function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&h(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];"element"===u||"text"===u?a!==c&&h(e,t,n):["children","events","element","text"].includes(u)||c&&a===c||(t.setAttribute(name,value),p(n,"updated"))}}(t,d,r,i),r.children||i.children))for(var u=function(e,t){for(var n=[],r=[],i=0;i<s(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{nChildren:n,oChildren:r}}(r.children,i.children),a=u.nChildren,l=u.oChildren,f=0;f<s(a,l);f++)e(d,a[f],l[f],f)}function s(e,t){var n=e.length||0,r=t.length||0;return n>=r?n:r}function h(e,t,n){e.replaceChild(c(n,{mount:!1}),t),p(n,"mounted")}function p(e,t){if(e.events){for(var r=0,i=Object.entries(e.events);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];d===t&&n.push(u)}v()}}}(d,a(r(),e.newState),a(r(),e.oldState))})}),d.appendChild(c(a(r(),e),{initial:!0})),u(),window.addEventListener("__LITERAL_LIFECYCLE__",u)},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:function e(t,n){for(var r=0;r<t.length;r++)Array.isArray(t[r])?e(t[r],n):n.push(t[r]);return n}(n,[])})}};
//# sourceMappingURL=index.js.map

@@ -1,2 +0,2 @@

var e={},t=[],n=[],r=function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:i(n,[])})},i=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?i(e[n],t):t.push(e[n]);return t},o=function(t,n,r){void 0===r&&(r={});var i=document.getElementById(n);e=Object.assign({},e,r),d(i,t);var o=c(t(),e),a=v(o,{initial:!0});i.appendChild(a),u()},d=function(e,n){return window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var r=t.pop();return a(e,n,{oldState:r.oldState,newState:r.newState})})})},u=function(){var e=function(){return setTimeout(function(){for(var e;e=n.pop();)e()})};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},a=function(e,t,n){var r=c(t(),n.oldState),i=c(t(),n.newState);return E(e,i,r)},c=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=c(e.children[n],t);return e},v=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,u=Object.entries(e);d<u.length;d+=1){var a=u[d],c=a[0],l=a[1];if("text"===c&&o.appendChild(document.createTextNode(l)),"events"===c&&f(l,o,n,r),["children","element","text","events"].includes(c)||o.setAttribute(c,l),"children"===c)for(var s=0;s<l.length;s++)o.appendChild(v(l[s],{mount:n,initial:r}))}return o},f=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),l(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),l(e,n,r)},l=function(e,t,r){if(r){var i=function(e){return n.push(e)};t&&"mounted"===e.type&&i(e.action),t||"updated"!==e.type||i(e.action),h()}},s=function(e,t){if(e.events){if(Array.isArray(e.events))for(var r=0;r<e.events.length;r++)e.events[r].type===t&&n.push(e.events[r].action);else e.events.type===t&&n.push(e.events.action);h()}},h=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},p=function(t){return void 0===t&&(t=e),Object.assign({},t)},m=function(n){var r=p(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},y=function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:p(r),getState:p,setState:m,props:e,methods:t({getState:p,setState:m})})}}},E=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?(s(t,"mounted"),e.insertBefore(v(t),i)):void 0===n?(s(t,"mounted"),e.appendChild(v(t))):0===n&&A(e,i,t);else if(!t&&n)s(n,"unmounted"),e.removeChild(i);else if(t&&(w(i,t,n),L(e,i,t,n),t.children||n.children))for(var o=_(t.children,n.children),d=o.newChildren,u=o.oldChildren,a=0;a<g(d,u);a++)E(i,d[a],u[a],a)}},_=function(e,t){for(var n=[],r=[],i=0;i<g(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},g=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},L=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&A(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];if("element"===u||"text"===u)a!==c&&A(e,t,n);else if(!(["children","events","element","text"].includes(u)||c&&a===c))return s(n,"updated"),t.setAttribute(name,value)}},w=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(s(t,"updated"),e.removeAttribute(d))}},A=function(e,t,n){s(n,"mounted"),e.replaceChild(v(n,{mount:!1}),t)};export default{component:y,render:o,h:r};export{r as h,o as render,y as component};
var e={},t=[],n=[],r=function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:function e(t,n){for(var r=0;r<t.length;r++)Array.isArray(t[r])?e(t[r],n):n.push(t[r]);return n}(n,[])})},i=function(r,i,o){void 0===o&&(o={});var d=document.getElementById(i);function u(){var e;return setTimeout(function(){for(;e=n.pop();)e()})}function a(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=a(e.children[n],t);return e}function c(e,t){void 0===t&&(t={});var r=t.mount;void 0===r&&(r=!0);var i=t.initial;void 0===i&&(i=!1);var o=typeof e;if("object"!==o&&"boolean"!==o)return document.createTextNode(e);for(var d=document.createElement(e.element),u=0,a=Object.entries(e);u<a.length;u+=1){var f=a[u],l=f[0],s=f[1];if("text"===l&&d.appendChild(document.createTextNode(s)),"events"===l&&p(s,d,r,i),["children","element","text","events"].includes(l)||d.setAttribute(l,s),"children"===l)for(var h=0;h<s.length;h++)d.appendChild(c(s[h],{mount:r,initial:i}))}return d;function p(e,t,r,i){for(var o=0,d=Object.entries(e);o<d.length;o+=1){var u=d[o],a=u[0],c=u[1];["mounted","unmounted","updated"].includes(a)||t.addEventListener(a,c),f(a,c,r,i)}function f(e,t,r,i){i&&(r&&"mounted"===e&&n.push(t),r||"updated"!==e||n.push(t),v())}}}function v(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)}e=Object.assign({},e,o),window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var e=t.pop();return function e(t,r,i,o){void 0===o&&(o=0);if(!t)return;var d=t.childNodes[o];if(!i&&r)!1===i?(t.insertBefore(c(r),d),p(r,"mounted")):void 0===i?(t.appendChild(c(r)),p(r,"mounted")):0===i&&h(t,d,r);else if(!r&&i)t.removeChild(d),p(i,"unmounted");else if(r&&(function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];t[d]||(e.removeAttribute(u),p(t,"updated"))}}(d,r,i),function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&h(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];"element"===u||"text"===u?a!==c&&h(e,t,n):["children","events","element","text"].includes(u)||c&&a===c||(t.setAttribute(name,value),p(n,"updated"))}}(t,d,r,i),r.children||i.children))for(var u=function(e,t){for(var n=[],r=[],i=0;i<s(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{nChildren:n,oChildren:r}}(r.children,i.children),a=u.nChildren,f=u.oChildren,l=0;l<s(a,f);l++)e(d,a[l],f[l],l);function s(e,t){var n=e.length||0,r=t.length||0;return n>=r?n:r}function h(e,t,n){e.replaceChild(c(n,{mount:!1}),t),p(n,"mounted")}function p(e,t){if(e.events){for(var r=0,i=Object.entries(e.events);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];d===t&&n.push(u)}v()}}}(d,a(r(),e.newState),a(r(),e.oldState))})}),d.appendChild(c(a(r(),e),{initial:!0})),u(),window.addEventListener("__LITERAL_LIFECYCLE__",u)},o=function(n){void 0===n&&(n={});var r=n.methods;void 0===r&&(r=function(){});var i=n.render;return void 0===i&&(i=function(){}),function(n){return void 0===n&&(n={}),function(o){var d=function(t){return void 0===t&&(t=e),Object.assign({},t)},u=function(n){var r=d(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)};return i({state:d(o),getState:d,setState:u,props:n,methods:r({getState:d,setState:u})})}}};export default{component:o,render:i,h:r};export{r as h,i as render,o as component};
//# sourceMappingURL=index.m.js.map

@@ -1,2 +0,2 @@

!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.literaljs=t()}(this,function(){var e={},t=[],n=[],r=function(e,t){t=void 0===t?[]:t;for(var n=0;n<e.length;n++)Array.isArray(e[n])?r(e[n],t):t.push(e[n]);return t},i=function(e,n){return window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var r=t.pop();return d(e,n,{oldState:r.oldState,newState:r.newState})})})},o=function(){var e=function(){return setTimeout(function(){for(var e;e=n.pop();)e()})};e(),window.addEventListener("__LITERAL_LIFECYCLE__",e)},d=function(e,t,n){var r=u(t(),n.oldState),i=u(t(),n.newState);return p(e,i,r)},u=function(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=u(e.children[n],t);return e},a=function(e,t){void 0===t&&(t={});var n=t.mount;void 0===n&&(n=!0);var r=t.initial;void 0===r&&(r=!1);var i=typeof e;if("object"!==i&&"boolean"!==i)return document.createTextNode(e);for(var o=document.createElement(e.element),d=0,u=Object.entries(e);d<u.length;d+=1){var f=u[d],l=f[0],v=f[1];if("text"===l&&o.appendChild(document.createTextNode(v)),"events"===l&&c(v,o,n,r),["children","element","text","events"].includes(l)||o.setAttribute(l,v),"children"===l)for(var s=0;s<v.length;s++)o.appendChild(a(v[s],{mount:n,initial:r}))}return o},c=function(e,t,n,r){var i=["mounted","unmounted","updated"];if(Array.isArray(e))for(var o=0;o<e.length;o++)i.includes(e[o].type)||t.addEventListener(e[o].type,e[o].action),f(e[o],n,r);else i.includes(e.type)||t.addEventListener(e.type,e.action),f(e,n,r)},f=function(e,t,r){if(r){var i=function(e){return n.push(e)};t&&"mounted"===e.type&&i(e.action),t||"updated"!==e.type||i(e.action),v()}},l=function(e,t){if(e.events){if(Array.isArray(e.events))for(var r=0;r<e.events.length;r++)e.events[r].type===t&&n.push(e.events[r].action);else e.events.type===t&&n.push(e.events.action);v()}},v=function(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)},s=function(t){return void 0===t&&(t=e),Object.assign({},t)},h=function(n){var r=s(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)},p=function(e,t,n,r){if(void 0===r&&(r=0),e){var i=e.childNodes[r];if(!n&&t)!1===n?(l(t,"mounted"),e.insertBefore(a(t),i)):void 0===n?(l(t,"mounted"),e.appendChild(a(t))):0===n&&g(e,i,t);else if(!t&&n)l(n,"unmounted"),e.removeChild(i);else if(t&&(_(i,t,n),E(e,i,t,n),t.children||n.children))for(var o=m(t.children,n.children),d=o.newChildren,u=o.oldChildren,c=0;c<y(d,u);c++)p(i,d[c],u[c],c)}},m=function(e,t){for(var n=[],r=[],i=0;i<y(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{newChildren:n,oldChildren:r}},y=function(e,t){var n=e.length,r=t.length;return n>=r?n:r},E=function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&g(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];if("element"===u||"text"===u)a!==c&&g(e,t,n);else if(!(["children","events","element","text"].includes(u)||c&&a===c))return l(n,"updated"),t.setAttribute(name,value)}},_=function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[1];t[o[0]]||(l(t,"updated"),e.removeAttribute(d))}},g=function(e,t,n){l(n,"mounted"),e.replaceChild(a(n,{mount:!1}),t)};return{component:function(e){void 0===e&&(e={});var t=e.methods;void 0===t&&(t=function(){});var n=e.render;return void 0===n&&(n=function(){}),function(e){return void 0===e&&(e={}),function(r){return n({state:s(r),getState:s,setState:h,props:e,methods:t({getState:s,setState:h})})}}},render:function(t,n,r){void 0===r&&(r={});var d=document.getElementById(n);e=Object.assign({},e,r),i(d,t);var c=u(t(),e),f=a(c,{initial:!0});d.appendChild(f),o()},h:function(e,t){for(var n=[],i=arguments.length-2;i-- >0;)n[i]=arguments[i+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:r(n,[])})}}});
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.literaljs=t()}(this,function(){var e={},t=[],n=[];return{component:function(n){void 0===n&&(n={});var r=n.methods;void 0===r&&(r=function(){});var i=n.render;return void 0===i&&(i=function(){}),function(n){return void 0===n&&(n={}),function(o){var d=function(t){return void 0===t&&(t=e),Object.assign({},t)},u=function(n){var r=d(),i={oldState:r,nextState:Object.assign({},r,n)};e=i.nextState,t.push(i);var o=new Event("__LITERAL_UPDATE__");return window.dispatchEvent(o)};return i({state:d(o),getState:d,setState:u,props:n,methods:r({getState:d,setState:u})})}}},render:function(r,i,o){void 0===o&&(o={});var d=document.getElementById(i);function u(){var e;return setTimeout(function(){for(;e=n.pop();)e()})}function a(e,t){if((e="function"==typeof e?e(t):e).children)for(var n=0;n<e.children.length;n++)e.children[n]=a(e.children[n],t);return e}function c(e,t){void 0===t&&(t={});var r=t.mount;void 0===r&&(r=!0);var i=t.initial;void 0===i&&(i=!1);var o=typeof e;if("object"!==o&&"boolean"!==o)return document.createTextNode(e);for(var d=document.createElement(e.element),u=0,a=Object.entries(e);u<a.length;u+=1){var l=a[u],v=l[0],s=l[1];if("text"===v&&d.appendChild(document.createTextNode(s)),"events"===v&&p(s,d,r,i),["children","element","text","events"].includes(v)||d.setAttribute(v,s),"children"===v)for(var h=0;h<s.length;h++)d.appendChild(c(s[h],{mount:r,initial:i}))}return d;function p(e,t,r,i){for(var o=0,d=Object.entries(e);o<d.length;o+=1){var u=d[o],a=u[0],c=u[1];["mounted","unmounted","updated"].includes(a)||t.addEventListener(a,c),l(a,c,r,i)}function l(e,t,r,i){i&&(r&&"mounted"===e&&n.push(t),r||"updated"!==e||n.push(t),f())}}}function f(){var e=new Event("__LITERAL_LIFECYCLE__");return window.dispatchEvent(e)}e=Object.assign({},e,o),window.addEventListener("__LITERAL_UPDATE__",function(){return setTimeout(function(){var e=t.pop();return function e(t,r,i,o){if(void 0===o&&(o=0),t){var d=t.childNodes[o];if(!i&&r)!1===i?(t.insertBefore(c(r),d),p(r,"mounted")):void 0===i?(t.appendChild(c(r)),p(r,"mounted")):0===i&&h(t,d,r);else if(!r&&i)t.removeChild(d),p(i,"unmounted");else if(r&&(function(e,t,n){for(var r=0,i=Object.entries(n);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];t[d]||(e.removeAttribute(u),p(t,"updated"))}}(d,r,i),function(e,t,n,r){"object"==typeof n&&"object"==typeof r||n!==r&&h(e,t,n);for(var i=0,o=Object.entries(n);i<o.length;i+=1){var d=o[i],u=d[0],a=d[1],c=r[u];"element"===u||"text"===u?a!==c&&h(e,t,n):["children","events","element","text"].includes(u)||c&&a===c||(t.setAttribute(name,value),p(n,"updated"))}}(t,d,r,i),r.children||i.children))for(var u=function(e,t){for(var n=[],r=[],i=0;i<s(e,t);i++)!1===e[i]&&!1===t[i]||(n.push(e[i]),r.push(t[i]));return{nChildren:n,oChildren:r}}(r.children,i.children),a=u.nChildren,l=u.oChildren,v=0;v<s(a,l);v++)e(d,a[v],l[v],v)}function s(e,t){var n=e.length||0,r=t.length||0;return n>=r?n:r}function h(e,t,n){e.replaceChild(c(n,{mount:!1}),t),p(n,"mounted")}function p(e,t){if(e.events){for(var r=0,i=Object.entries(e.events);r<i.length;r+=1){var o=i[r],d=o[0],u=o[1];d===t&&n.push(u)}f()}}}(d,a(r(),e.newState),a(r(),e.oldState))})}),d.appendChild(c(a(r(),e),{initial:!0})),u(),window.addEventListener("__LITERAL_LIFECYCLE__",u)},h:function(e,t){for(var n=[],r=arguments.length-2;r-- >0;)n[r]=arguments[r+2];return"function"==typeof e?e:Object.assign({},{element:e},t,{children:function e(t,n){for(var r=0;r<t.length;r++)Array.isArray(t[r])?e(t[r],n):n.push(t[r]);return n}(n,[])})}}});
//# sourceMappingURL=index.umd.js.map
{
"name": "literaljs",
"version": "2.3.2",
"version": "2.4.0",
"description": "~1kb JavaScript library for building user interfaces.",

@@ -5,0 +5,0 @@ "main": "build/index.js",

@@ -8,5 +8,5 @@ # LiteralJS

Build output to build:
1.51 kB: index.js
1.53 kB: index.m.js
1.56 kB: index.umd.js
1.42 kB: index.js
1.44 kB: index.m.js
1.47 kB: index.umd.js
```

@@ -16,6 +16,6 @@ ### [Features and stuff](#features)

- **Small**: Only around 1kb in size.
- **Fast**: Current and previous vDOM are diffed against each other for performant updates and rendering.
- **Fast**: Current and previous vDOM data is diffed instead of the actual DOM for performant updates and rendering.
- **Virtual DOM**: Diffing occurs on state update for more efficient DOM updates.
- **Flexible Syntax**: Freedom to use JSX, Hyperscript, or Object syntax.
- **Lifecycle Methods**: All DOM elements have the ability to trigger `mounted`, `updated, and `unmounted` lifecycle functions.
- **Lifecycle Methods**: All DOM elements have the ability to trigger `mounted`, `updated`, and `unmounted` lifecycle functions.
- **One Global Store**: One source of truth which makes other state management libraries less of a need.

@@ -93,7 +93,3 @@

This is the Count: {state.count}
<button
events={{
type: 'click',
action: () => setState({ count: getState().count + 1 })
}}>
<button events={{ click: () => setState({ count: getState().count + 1 }) }}>
Click Me!

@@ -116,10 +112,6 @@ </button>

text: `This is the Count: ${state.count}`
}, [
h('button', {
events: {
type: 'click',
action: () => setState({ count: getState().count + 1 })
}
})
]
},
h('button', {
events: { click: () => setState({ count: getState().count + 1 }) }
})
);

@@ -143,6 +135,3 @@ });

text: 'Click Me!',
events: {
type: 'click',
action: () => setState({ count: getState().count + 1 })
}
events: { click: () => setState({ count: getState().count + 1 }) }
}

@@ -207,9 +196,4 @@ ]

}),
render: ({ state, getState, setState, methods: { increase }}) => (
<button
events={{
type: 'click',
action: () => increase()
}}
>
render: ({ state, methods: { increase }}) => (
<button events={{ click: increase }}>
Current Count: {state.count}

@@ -232,3 +216,3 @@ </button>

Event Objects need a `type` and `action` which are [explained here](#events).
Event Objects need a key which is a DOM event name and function as a value. The events in LiteralJS are [explained here](#events).

@@ -243,9 +227,4 @@ Anything can be considered acceptable as attributes and any keys that work with [LiteralJS Object Markup Syntax](#object-markup-syntax) also work in LiteralJS JSX markup.

}),
render: ({ state, getState, setState, methods: { increase }}) => (
<button
events={{
type: 'click',
action: () => increase()
}}
>
render: ({ state, methods: { increase }}) => (
<button events={{ click: () => increase() }}>
Current Count: {state.count}

@@ -263,14 +242,8 @@ </button>

}),
render: ({ state, getState, setState, methods: { increase }}) => (
render: ({ state, methods: { increase }}) => (
<button
events={[
{
type: 'mounted',
action: () => console.log('Button Mounted')
},
{
type: 'click',
action: () => increase()
}
]}
events={{
mounted: () => console.log('Button Mounted'),
click: () => increase()
}}
>

@@ -284,3 +257,3 @@ Current Count: {state.count}

#### [Object Markup Syntax](#object-markup-syntax)
Object Markup is currently written with Objects with the following specified keys or strings:
Object Markup is currently written with Objects with the following specified keys or strings and more not listed:

@@ -394,7 +367,7 @@ - [`element`](#element-key)*

The `events` key in the `render` function markup accepts either an Array of events or a single event Object.
The `events` key in the `render` function markup accepts either an Object.
An event object has two keys:
- `type` (Event Name)
- `action` (Function To Trigger)
An event object consists of the `key` of the event name and the `value` of a function to trigger:
- Key: Event Name
- Value: Function To Trigger

@@ -408,22 +381,6 @@ Example:

text: 'Click Me!',
events: [
{
type: 'click'
action: () => console.log('Hello World!')
}
]
events: { click: () => console.log('Hello World!') }
})
});
// Output in Console: Hello World!
// OR
component({
render: () => ({
element: 'button',
text: 'Click Me!',
events: {
type: 'click'
action: () => console.log('Hello World!')
}
})
});
```

@@ -444,16 +401,7 @@

text: 'I have a life!',
events: [
{
type: 'mounted'
action: () => console.log('I\'m on the page!')
},
{
type: 'updated'
action: () => console.log('I\'m updated!')
},
{
type: 'unmounted'
action: () => console.log('I\'m off the page!')
}
]
events: {
mounted: () => console.log('I\'m on the page!'),
updated: () => console.log('I\'m updated!'),
unmounted: () => console.log('I\'m off the page!')
}
})

@@ -464,3 +412,3 @@ });

#### Other Keys Not Listed
Other keys are also accepted in a DOM object, such as `data` and other custom keys.
Other typical keys are also accepted in a DOM object, such as `data`, `href`, and other custom keys depending on the `element`.

@@ -477,23 +425,23 @@ #### Properties

### `state`
### `state` (Object)
The `state` property is an Object of the current state and should only be used within markup and not functions or events.
### `getState`
### `getState` (Function -> Object)
The `getState` function of the `component`s `render` method will allow you to access the global store of your application within functions and events.
### `setState`
### `setState` (Function)
The `setState` function of the `component`s `render` method accepts an object which will allow you to set new values for particular pieces of state in the global store
### `props`
### `props` (Object)
The `props` object of the `component`s `render method can contain any number of data types and functions. The only `component` that cannot contain `props` is the root `component` that is passed to the `Literal.render` method.
### `methods`
### `methods` (Object -> Functions)
The `methods` object allow you to access other functions defined directly in the `component`. You can use this as a way to organize other pieces of logic and keep the `render` function much cleaner.
## render
## render (Function)

@@ -504,5 +452,5 @@ The `Literal.render` function is responsible for parsing the AST that is provided with `component`s, injecting the generated markup into the specific DOM node, diffing any new changes based on state, and setting the default application state.

- The root component.
- The root `component`.
- The String `id` of the DOM node to inject generated markup with.
- (Optional) The default state as an Object
- (Optional) The default state as an Object.

@@ -509,0 +457,0 @@ **Example:**

@@ -16,4 +16,3 @@ import { render, component, h } from '../src';

events: {
type: 'click',
action: () => setState({ show: !getState().show })
click: () => setState({ show: !getState().show })
}

@@ -26,4 +25,3 @@ },

events: {
type: 'mounted',
action: () => {
mounted: () => {
setState({ count: getState().count + 1 });

@@ -49,40 +47,37 @@ expect(getState().count).toBe(2);

// test('Lifecycle unmounted works with getState and setState', done => {
// const Comp2 = component({
// render: ({ state, getState, setState }) =>
// h(
// 'button',
// {
// id: 'button',
// events: {
// type: 'click',
// action: () => setState({ show: !getState().show })
// }
// },
// state.show &&
// h(
// 'span',
// {
// test('Lifecycle unmounted works with getState and setState', done => {
// const Comp2 = component({
// render: ({ state, getState, setState }) =>
// h(
// 'button',
// {
// id: 'button',
// events: {
// mounted: () => setState({ show: !getState().show })
// }
// },
// state.show &&
// h('span', {
// events: {
// type: 'unmounted',
// action: () => {
// unmounted: () => {
// console.log('UNMOUNTED!');
// setState({ count: getState().count + 1 });
// expect(getState().count).toBe(2);
// expect(getState().count).toBe('2');
// done();
// }
// }
// },
// 'Hello World'
// )
// )
// });
// }),
// h('span', { id: 'count' }, state.count)
// )
// });
// const Comp = component({
// render: ({ state }) => h('div', { class: 'container' }, Comp2())
// });
// const Comp = component({
// render: ({ state }) => h('div', { class: 'container' }, Comp2())
// });
// render(Comp, 'root', { show: true, count: 1 });
// render(Comp, 'root', { show: true, count: 1 });
// document.getElementById('button').click();
// });
// document.getElementById('button').click();
// // expect(document.getElementById('count').innerHTML).toBe('2');
// });
});

@@ -87,4 +87,3 @@ import { render, component, h } from '../src';

events: {
type: 'click',
action: () => {
click: () => {
increment();

@@ -117,4 +116,3 @@ expect(getState().count).toBe(2);

events: {
type: 'click',
action: () => {
click: () => {
setState({ count: getState().count + 1 });

@@ -121,0 +119,0 @@ expect(getState().count).toBe(2);

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc