olum 0.5.0 → 0.5.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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright 2021 Eissa Saber
3
+ Copyright 2026 Eissa Saber
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/dist/olum.js CHANGED
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * @name Olum.js
3
- * @version 0.5.0
3
+ * @version 0.5.1
4
4
  * @copyright 2026
5
5
  * @author Eissa Saber
6
6
  * @license MIT
@@ -101,11 +101,11 @@ export default (function () {
101
101
  // user-supplied string (a todo title, a comment, anything) can't inject markup/scripts (XSS)
102
102
  // or visually break rendering when it contains <, >, &, or quotes.
103
103
  // - null/undefined render as "" (instead of the literal text "null"/"undefined").
104
- // - To render trusted HTML on purpose, opt out explicitly with `olum.raw(html)` (below);
104
+ // - To render trusted HTML on purpose, opt out explicitly with `olum.html(value)` (below);
105
105
  // esc() detects the marker it returns and passes the HTML through unescaped.
106
106
  esc(value) {
107
107
  if (value === null || value === undefined) return "";
108
- if (value && value.__olumRaw === true) return value.html; // explicit raw-HTML opt-in
108
+ if (value && value.__olumHtml === true) return value.html; // explicit raw-HTML opt-in
109
109
  return String(value)
110
110
  .replace(/&/g, "&amp;") // must run first so the entities below aren't double-escaped
111
111
  .replace(/</g, "&lt;")
@@ -114,10 +114,10 @@ export default (function () {
114
114
  .replace(/'/g, "&#39;");
115
115
  },
116
116
  // #2 opt-in escape hatch: mark a string as trusted raw HTML so `esc()` leaves it untouched.
117
- // Usage in a template: {olum.raw(props.richText)}. Use it ONLY on HTML you control or have
117
+ // Usage in a template: {olum.html(props.richText)}. Use it ONLY on HTML you control or have
118
118
  // already sanitized — this is the deliberate, greppable way to bypass auto-escaping.
119
- raw(html) {
120
- return { __olumRaw: true, html: html == null ? "" : String(html) };
119
+ html(value) {
120
+ return { __olumHtml: true, html: value == null ? "" : String(value) };
121
121
  },
122
122
  eventsHandler(el, nodes, compName, methodsRefObj) {
123
123
  function event(item, str, modifiers) {
package/dist/olum.min.js CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @name olum
3
- * @version 0.5.0
3
+ * @version 0.5.1
4
4
  * @copyright 2026
5
5
  * @author Eissa Saber
6
6
  * @license MIT
7
7
  */
8
- export default(()=>{var i={app:{},$emit(e,t){this.dispatchEvent(e,t)},dispatchEvent(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t}))},mkElm(e,t,o){e=document.createElement(e);return t&&o&&e.setAttribute("data-olum",JSON.stringify({compName:t,compId:o})),e},injectStyle(e,t){var o;t&&t.trim()&&(e="olum-style-"+e,document.getElementById(e)||((o=document.createElement("style")).id=e,o.textContent=t,document.head.appendChild(o)))},proxyHandler(e,r,t){function l(e){var t,o=0;if(0!==e.length)for(t=0;t<e.length;t++)o=(o<<5)-o+e.charCodeAt(t),o|=0;return o}return new Proxy(e,{get:function(e,t){return e[t]},set:function(e,t,o){var n;return"__olum__"!==t&&((n=e[t])!==o&&(e[t]=o,r&&r[t]&&"function"==typeof r[t]&&r[t](n,o),n=l((t={compName:e.__olum__.compName,compId:e.__olum__.compId}).compName+t.compId),t.hash=n,window.olum.$emit("updateOlumComp",t)),!0)},deleteProperty:function(e,t){if("__olum__"===t)return!1;delete e[t];t={compName:e.__olum__.compName,compId:e.__olum__.compId},e=l(t.compName+t.compId);return t.hash=e,window.olum.$emit("updateOlumComp",t),!0}})},proxyHandlerForStore(e,n){return new Proxy(e,{get:function(e,t){return n[t]},set:function(e,t,o){return e[t]=o,n[t]=o,!0},deleteProperty:function(e,t){return delete e[t],delete n[t],!0}})},clean(e){e=String(e).trim();return"null"===e?null:e},esc(e){return null==e?"":e&&!0===e.__olumRaw?e.html:String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")},raw(e){return{__olumRaw:!0,html:null==e?"":String(e)}},eventsHandler(e,t,o,a){t.forEach(e=>{var o=i.clean(e.getAttribute("data-o-event")),n=i.clean(e.getAttribute("data-o-event-mode")),n=n&&""!==n.trim()?n.split("."):[];if(o){var r=e,e=o,l=n,o=e.split("|")[0];let t=(e=e.split("|").slice(1).join()).split("&").map(e=>{var e=e.split("="),t=e[0];return{args:JSON.parse(e.slice(1).join("")),methodName:t}});e={once:!1,passive:!1,capture:!1},l&&l.length&&(l.includes("once")&&(e.once=!0),l.includes("passive")&&(e.passive=!0),l.includes("capture"))&&(e.capture=!0),r.addEventListener(o.slice(2),o=>{function e(){t.forEach(e=>{var t;a[e.methodName]?e.args.length?(-1!==(t=e.args.indexOf("$event"))&&e.args.splice(t,1,o),a[e.methodName](...e.args)):a[e.methodName](o):console.warn("olum: can't access the method")})}l&&l.length&&(l.includes("prevent")&&o.preventDefault(),l.includes("stop"))&&o.stopPropagation(),l&&l.length&&l.includes("self")&&o.target!==r||e()},e),r.removeAttribute("data-o-event"),r.removeAttribute("data-o-event-mode")}})},stylesHandler(e,t,o){t.forEach(e=>{var t=i.clean(e.getAttribute("data-o-style"));if(t){var t=JSON.parse(t),n=Object.keys(t);if(n.length){var r=t;t=n;let o="";t.forEach(e=>{var t=r[e];t&&(o+=e+": "+t+"; ")}),""!==(o=o.trim())&&e.setAttribute("style",o),e.removeAttribute("data-o-style")}}})},handleMarkup(t,o,e,n){e.setAttribute("data-child-of",t),e.setAttribute("data-o-"+o,"");var r=e.querySelectorAll("*");return r.forEach(e=>{e.setAttribute("data-child-of",t),e.setAttribute("data-o-"+o,"")}),this.eventsHandler(e,r,t,n),this.stylesHandler(e,r,t),e},isObj(e){return null!==e&&"object"==typeof e},isFullArr(e){return!!(this.isObj(e)&&Array.isArray(e)&&e.length)},isFullObj(e){return!!(this.isObj(e)&&Array.isArray(Object.keys(e))&&Object.keys(e).length)},createStore(e){let o={},n=[],r=(o[e.__OLUM__.compName]=e,e=>{this.isFullArr(e.__OLUM__.components)&&e.__OLUM__.components.forEach(e=>{var t=Object.keys(e)[0],e=e[t](),t=(o[t]||(o[t]=e),{name:t,children:e.__OLUM__.components.map(e=>Object.keys(e)[0])});n.push(t),this.isFullArr(t.children)&&r(e)})});return r(e),{store:o,map:n}},directOlums(t){return Array.prototype.slice.call(t.querySelectorAll("olum")).filter(e=>{e=e.parentElement&&e.parentElement.closest&&e.parentElement.closest("olum");return!e||!t.contains(e)})},buildTree(e,u,t){var o=e.__OLUM__.getElm;if(!o)return null;let n=this,c=window.olum.app.registry||(window.olum.app.registry={});return function a(e,i,t){e.__OLUM__.components&&Object.assign(c,e.__OLUM__.components);t=n.directOlums(t);let s={};t.forEach(t=>{var o=t.getAttribute("name"),r=c[o]||e.__OLUM__.components&&e.__OLUM__.components[o];if(r){var l=t.getAttribute("data-o-key");let e,n=(e=null!==l&&""!==l?i+">"+o+"@"+l:(s[o]=void 0===s[o]?0:s[o]+1,i+">"+o+"#"+s[o]),u[e]);n||(n=r(e),u[e]=n),n.parentCompName=i,l=t.getAttribute("data-o-props"),n.incomingProps=l?JSON.parse(decodeURIComponent(l)):{},r=t.getAttribute("data-o-props-src")||"",n.incomingPropSources={},r&&r.split("|").forEach(e=>{var t=(e=e.split(":"))[0],o=e[1],e=e[2];t&&o&&e&&(n.incomingPropSources[t]={kind:o,key:e})}),n.children=t.innerHTML.trim(),(l=n.__OLUM__.getElm)&&(l.setAttribute("data-o-if",t.getAttribute("if")?t.getAttribute("if"):"olum-no-condition"),t.replaceWith(l),a(n,e,l))}else console.warn("olum: couldn't find "+o+" Component while building the tree!")})}(e,t,o),o},getInnerNames(t){let n=[],r=window.olum.app.map;return r&&r.find(e=>{e.name==t&&e.children.forEach(e=>n.push(e))}),n.length&&function e(t){let o=n[t];r.forEach(e=>{e.name==o&&e.children.forEach(e=>n.push(e))}),t+1<=n.length&&e(t+1)}(0),n}};"undefined"!=typeof window&&(window.olum=i);class e{root=null;$(e){return this.root=document.querySelector(e),this}use(e){e=e();let{store:o,rootKey:n}=this.share(e);var t=window.olum.buildTree(e,o,n);if(!t)return console.warn("olum: couldn't build tree!");this.setupListeners(o),this.root.append(t),e.hooks.mounted&&e.hooks.mounted(),e.hooks.isMounted=!0,Object.keys(o).forEach(e=>{var t;e!==n&&(e=o[e])&&e.el&&(t=e.el.getAttribute("data-o-if"))&&["olum-no-condition","true"].includes(t)&&(e.hooks.mounted&&e.hooks.mounted(),e.hooks.isMounted=!0)})}getPath(e,t){var o=[];let n=e;for(;n&&n!==t;){var r=n.parentElement;if(!r)break;var l=Array.from(r.children).filter(e=>e.tagName===n.tagName);o.unshift({tag:n.tagName,index:l.indexOf(n)}),n=r}return o}findByPath(e,o){let n=e;for(let t of o){var r=Array.from(n.children).filter(e=>e.tagName===t.tag);if(!(n=r[t.index]))return null}return n}setupListeners(i){window.addEventListener("updateOlumComp",e=>{if(e&&e.detail&&e.detail.compName&&e.detail.compId&&e.detail.hash&&e.detail.hash===(e=>{var t,o=0;if(0!==e.length)for(t=0;t<e.length;t++)o=(o<<5)-o+e.charCodeAt(t),o|=0;return o})(e.detail.compName+e.detail.compId)){var o=i[e.detail.compName];if(o&&o.el&&document.body.contains(o.el)){let t=e.detail.compName;e=Object.keys(i).filter(e=>e!==t);let n={};e.forEach(e=>{var t=i[e];t&&(n[e]=t.hooks.isMounted)});var e=document.activeElement,r=e&&null!=e.selectionStart?e.selectionStart:null,l=e&&null!=e.selectionEnd?e.selectionEnd:null,e=e&&o.el.contains(e)?this.getPath(e,o.el):null,a=window.olum.buildTree(o,i,t);if(!a)return console.warn("olum: couldn't build tree!");o.el.replaceWith(a),e&&e.length&&(o=this.findByPath(a,e))&&(o.focus&&"function"==typeof o.focus&&o.focus(),null!==r)&&o.setSelectionRange&&"function"==typeof o.setSelectionRange&&o.setSelectionRange(r,l),Object.keys(i).filter(e=>e!==t).forEach(e=>{var t,o=i[e];o&&(t=document.body.contains(o.el),n[e]&&!t?o.hooks.unMounted&&!o.hooks.isUnMounted&&(o.hooks.unMounted(),o.hooks.isUnMounted=!0,o.hooks.isMounted=!1):!n[e]&&t&&o.hooks.mounted&&!o.hooks.isMounted&&(o.hooks.mounted(),o.hooks.isMounted=!0,o.hooks.isUnMounted=!1))})}}})}share(e){var t={},o=e.__OLUM__.compName;return t[o]=e,Object.assign(window.olum.app,{store:t,registry:{}}),{store:t,rootKey:o}}}return e})();
8
+ export default(()=>{var i={app:{},$emit(e,t){this.dispatchEvent(e,t)},dispatchEvent(e,t){window.dispatchEvent(new CustomEvent(e,{detail:t}))},mkElm(e,t,o){e=document.createElement(e);return t&&o&&e.setAttribute("data-olum",JSON.stringify({compName:t,compId:o})),e},injectStyle(e,t){var o;t&&t.trim()&&(e="olum-style-"+e,document.getElementById(e)||((o=document.createElement("style")).id=e,o.textContent=t,document.head.appendChild(o)))},proxyHandler(e,r,t){function l(e){var t,o=0;if(0!==e.length)for(t=0;t<e.length;t++)o=(o<<5)-o+e.charCodeAt(t),o|=0;return o}return new Proxy(e,{get:function(e,t){return e[t]},set:function(e,t,o){var n;return"__olum__"!==t&&((n=e[t])!==o&&(e[t]=o,r&&r[t]&&"function"==typeof r[t]&&r[t](n,o),n=l((t={compName:e.__olum__.compName,compId:e.__olum__.compId}).compName+t.compId),t.hash=n,window.olum.$emit("updateOlumComp",t)),!0)},deleteProperty:function(e,t){if("__olum__"===t)return!1;delete e[t];t={compName:e.__olum__.compName,compId:e.__olum__.compId},e=l(t.compName+t.compId);return t.hash=e,window.olum.$emit("updateOlumComp",t),!0}})},proxyHandlerForStore(e,n){return new Proxy(e,{get:function(e,t){return n[t]},set:function(e,t,o){return e[t]=o,n[t]=o,!0},deleteProperty:function(e,t){return delete e[t],delete n[t],!0}})},clean(e){e=String(e).trim();return"null"===e?null:e},esc(e){return null==e?"":e&&!0===e.__olumHtml?e.html:String(e).replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/'/g,"&#39;")},html(e){return{__olumHtml:!0,html:null==e?"":String(e)}},eventsHandler(e,t,o,a){t.forEach(e=>{var o=i.clean(e.getAttribute("data-o-event")),n=i.clean(e.getAttribute("data-o-event-mode")),n=n&&""!==n.trim()?n.split("."):[];if(o){var r=e,e=o,l=n,o=e.split("|")[0];let t=(e=e.split("|").slice(1).join()).split("&").map(e=>{var e=e.split("="),t=e[0];return{args:JSON.parse(e.slice(1).join("")),methodName:t}});e={once:!1,passive:!1,capture:!1},l&&l.length&&(l.includes("once")&&(e.once=!0),l.includes("passive")&&(e.passive=!0),l.includes("capture"))&&(e.capture=!0),r.addEventListener(o.slice(2),o=>{function e(){t.forEach(e=>{var t;a[e.methodName]?e.args.length?(-1!==(t=e.args.indexOf("$event"))&&e.args.splice(t,1,o),a[e.methodName](...e.args)):a[e.methodName](o):console.warn("olum: can't access the method")})}l&&l.length&&(l.includes("prevent")&&o.preventDefault(),l.includes("stop"))&&o.stopPropagation(),l&&l.length&&l.includes("self")&&o.target!==r||e()},e),r.removeAttribute("data-o-event"),r.removeAttribute("data-o-event-mode")}})},stylesHandler(e,t,o){t.forEach(e=>{var t=i.clean(e.getAttribute("data-o-style"));if(t){var t=JSON.parse(t),n=Object.keys(t);if(n.length){var r=t;t=n;let o="";t.forEach(e=>{var t=r[e];t&&(o+=e+": "+t+"; ")}),""!==(o=o.trim())&&e.setAttribute("style",o),e.removeAttribute("data-o-style")}}})},handleMarkup(t,o,e,n){e.setAttribute("data-child-of",t),e.setAttribute("data-o-"+o,"");var r=e.querySelectorAll("*");return r.forEach(e=>{e.setAttribute("data-child-of",t),e.setAttribute("data-o-"+o,"")}),this.eventsHandler(e,r,t,n),this.stylesHandler(e,r,t),e},isObj(e){return null!==e&&"object"==typeof e},isFullArr(e){return!!(this.isObj(e)&&Array.isArray(e)&&e.length)},isFullObj(e){return!!(this.isObj(e)&&Array.isArray(Object.keys(e))&&Object.keys(e).length)},createStore(e){let o={},n=[],r=(o[e.__OLUM__.compName]=e,e=>{this.isFullArr(e.__OLUM__.components)&&e.__OLUM__.components.forEach(e=>{var t=Object.keys(e)[0],e=e[t](),t=(o[t]||(o[t]=e),{name:t,children:e.__OLUM__.components.map(e=>Object.keys(e)[0])});n.push(t),this.isFullArr(t.children)&&r(e)})});return r(e),{store:o,map:n}},directOlums(t){return Array.prototype.slice.call(t.querySelectorAll("olum")).filter(e=>{e=e.parentElement&&e.parentElement.closest&&e.parentElement.closest("olum");return!e||!t.contains(e)})},buildTree(e,u,t){var o=e.__OLUM__.getElm;if(!o)return null;let n=this,c=window.olum.app.registry||(window.olum.app.registry={});return function a(e,i,t){e.__OLUM__.components&&Object.assign(c,e.__OLUM__.components);t=n.directOlums(t);let s={};t.forEach(t=>{var o=t.getAttribute("name"),r=c[o]||e.__OLUM__.components&&e.__OLUM__.components[o];if(r){var l=t.getAttribute("data-o-key");let e,n=(e=null!==l&&""!==l?i+">"+o+"@"+l:(s[o]=void 0===s[o]?0:s[o]+1,i+">"+o+"#"+s[o]),u[e]);n||(n=r(e),u[e]=n),n.parentCompName=i,l=t.getAttribute("data-o-props"),n.incomingProps=l?JSON.parse(decodeURIComponent(l)):{},r=t.getAttribute("data-o-props-src")||"",n.incomingPropSources={},r&&r.split("|").forEach(e=>{var t=(e=e.split(":"))[0],o=e[1],e=e[2];t&&o&&e&&(n.incomingPropSources[t]={kind:o,key:e})}),n.children=t.innerHTML.trim(),(l=n.__OLUM__.getElm)&&(l.setAttribute("data-o-if",t.getAttribute("if")?t.getAttribute("if"):"olum-no-condition"),t.replaceWith(l),a(n,e,l))}else console.warn("olum: couldn't find "+o+" Component while building the tree!")})}(e,t,o),o},getInnerNames(t){let n=[],r=window.olum.app.map;return r&&r.find(e=>{e.name==t&&e.children.forEach(e=>n.push(e))}),n.length&&function e(t){let o=n[t];r.forEach(e=>{e.name==o&&e.children.forEach(e=>n.push(e))}),t+1<=n.length&&e(t+1)}(0),n}};"undefined"!=typeof window&&(window.olum=i);class e{root=null;$(e){return this.root=document.querySelector(e),this}use(e){e=e();let{store:o,rootKey:n}=this.share(e);var t=window.olum.buildTree(e,o,n);if(!t)return console.warn("olum: couldn't build tree!");this.setupListeners(o),this.root.append(t),e.hooks.mounted&&e.hooks.mounted(),e.hooks.isMounted=!0,Object.keys(o).forEach(e=>{var t;e!==n&&(e=o[e])&&e.el&&(t=e.el.getAttribute("data-o-if"))&&["olum-no-condition","true"].includes(t)&&(e.hooks.mounted&&e.hooks.mounted(),e.hooks.isMounted=!0)})}getPath(e,t){var o=[];let n=e;for(;n&&n!==t;){var r=n.parentElement;if(!r)break;var l=Array.from(r.children).filter(e=>e.tagName===n.tagName);o.unshift({tag:n.tagName,index:l.indexOf(n)}),n=r}return o}findByPath(e,o){let n=e;for(let t of o){var r=Array.from(n.children).filter(e=>e.tagName===t.tag);if(!(n=r[t.index]))return null}return n}setupListeners(i){window.addEventListener("updateOlumComp",e=>{if(e&&e.detail&&e.detail.compName&&e.detail.compId&&e.detail.hash&&e.detail.hash===(e=>{var t,o=0;if(0!==e.length)for(t=0;t<e.length;t++)o=(o<<5)-o+e.charCodeAt(t),o|=0;return o})(e.detail.compName+e.detail.compId)){var o=i[e.detail.compName];if(o&&o.el&&document.body.contains(o.el)){let t=e.detail.compName;e=Object.keys(i).filter(e=>e!==t);let n={};e.forEach(e=>{var t=i[e];t&&(n[e]=t.hooks.isMounted)});var e=document.activeElement,r=e&&null!=e.selectionStart?e.selectionStart:null,l=e&&null!=e.selectionEnd?e.selectionEnd:null,e=e&&o.el.contains(e)?this.getPath(e,o.el):null,a=window.olum.buildTree(o,i,t);if(!a)return console.warn("olum: couldn't build tree!");o.el.replaceWith(a),e&&e.length&&(o=this.findByPath(a,e))&&(o.focus&&"function"==typeof o.focus&&o.focus(),null!==r)&&o.setSelectionRange&&"function"==typeof o.setSelectionRange&&o.setSelectionRange(r,l),Object.keys(i).filter(e=>e!==t).forEach(e=>{var t,o=i[e];o&&(t=document.body.contains(o.el),n[e]&&!t?o.hooks.unMounted&&!o.hooks.isUnMounted&&(o.hooks.unMounted(),o.hooks.isUnMounted=!0,o.hooks.isMounted=!1):!n[e]&&t&&o.hooks.mounted&&!o.hooks.isMounted&&(o.hooks.mounted(),o.hooks.isMounted=!0,o.hooks.isUnMounted=!1))})}}})}share(e){var t={},o=e.__OLUM__.compName;return t[o]=e,Object.assign(window.olum.app,{store:t,registry:{}}),{store:t,rootKey:o}}}return e})();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "olum",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "The VanillaJS developer’s platform.",
5
5
  "main": "dist/olum.js",
6
6
  "directories": {