ladrillosjs 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, Daniel Rubio
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,10 @@
1
+ # LadrillosJS
2
+
3
+ <img src="./LadrillosJS.png" alt="LadrillosJS" width="400"/>
4
+
5
+ A lightweight, zero-dependency web component framework for building modular web applications.
6
+
7
+ ## Getting Starting with samples
8
+
9
+ 1. `npm install`
10
+ 2. `npm run dev`
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./main-Dju_Az3Y.js");exports.ladrillos=e.ladrillos;
@@ -0,0 +1,4 @@
1
+ import { a as o } from "./main-oMNAxRMg.mjs";
2
+ export {
3
+ o as ladrillos
4
+ };
@@ -0,0 +1 @@
1
+ (function(o,e){typeof exports=="object"&&typeof module!="undefined"?e(exports):typeof define=="function"&&define.amd?define(["exports"],e):(o=typeof globalThis!="undefined"?globalThis:o||self,e(o.ladrillosjs={}))})(this,function(o){"use strict";var $=Object.defineProperty;var R=(o,e,d)=>e in o?$(o,e,{enumerable:!0,configurable:!0,writable:!0,value:d}):o[e]=d;var C=(o,e,d)=>R(o,typeof e!="symbol"?e+"":e,d);var T=(o,e,d)=>new Promise((w,E)=>{var S=s=>{try{r(d.next(s))}catch(t){E(t)}},y=s=>{try{r(d.throw(s))}catch(t){E(t)}},r=s=>s.done?w(s.value):Promise.resolve(s.value).then(S,y);r((d=d.apply(o,e)).next())});const e={log(s,...t){},error(s,...t){console.error(s,...t)},warn(s,...t){}},r=class r{constructor(){this.components={},this._cache=new Map}registerComponent(t,c,h=!0){return T(this,null,function*(){if(this.components[t]){e.log(`Component ${t} already registered, skipping.`);return}try{let l=this._cache.get(c);l||(l=yield(yield fetch(c)).text(),this._cache.set(c,l));const m=l.replace(r._SCRIPT_ALL,"").replace(r._STYLE_ALL,""),b=document.createElement("template");b.innerHTML=m;const f=r._SCRIPT_ONE.exec(l),g=r._STYLE_ONE.exec(l);this.components[t]={tagName:t,template:b,script:(f==null?void 0:f[1].trim())||"",style:(g==null?void 0:g[1].trim())||""},this._defineWebComponent(t,h),e.log(`Component ${t} registered successfully`)}catch(l){e.error(`Failed to register component ${t}:`,l)}})}_defineWebComponent(t,c){return T(this,null,function*(){const{defineWebComponent:h}=yield Promise.resolve().then(()=>y);h(this.components[t],c)})}};C(r,"_SCRIPT_ALL",/<script>([\s\S]*?)<\/script>/g),C(r,"_STYLE_ALL",/<style>([\s\S]*?)<\/style>/g),C(r,"_SCRIPT_ONE",/<script>([\s\S]*?)<\/script>/),C(r,"_STYLE_ONE",/<style>([\s\S]*?)<\/style>/);let d=r;const w=new d;function E(s,t={}){return new Proxy(t,{set(c,h,l){const m=c[h];return c[h]=l,m!==l&&!s._initializing&&s._update(),!0},get(c,h){return c[h]}})}const y=Object.freeze(Object.defineProperty({__proto__:null,defineWebComponent:(s,t)=>{if(!s){e.error("Component is not defined or invalid.");return}if(customElements.get(s.tagName)){e.warn(`Component ${s.tagName} is already defined.`);return}const{tagName:c,template:h,script:l,style:m}=s,f=(N=>{const n=/{(.*?)}/g,a=new Set;let i;for(;(i=n.exec(N.innerHTML))!==null;)a.add(i[1].trim().toLowerCase());return Array.from(a)})(h),g=l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g,"state.$1 =").replace(/function\s+([\w$]+)\s*\(/g,"state.$1 = function ("),x=l?new Function("state",`with(state){${g}}`):()=>{};class L extends HTMLElement{constructor(){super(),t&&this.attachShadow({mode:"open"}),this.state={},this.styleElement=document.createElement("style"),this.styleElement.textContent=m||""}connectedCallback(){const n=h.content.cloneNode(!0);this.state=E(this,{}),this._initializing=!0;try{x.call(this,this.state)}catch(a){console.error("Error initializing component script:",a)}finally{this._initializing=!1}this._processTemplate(n),this.shadowRoot?(this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(n)):(this.appendChild(this.styleElement),this.appendChild(n))}_processTemplate(n){this._getAllTextNodes(n).forEach(i=>{const p=i.textContent;p.includes("{")&&p.includes("}")&&(i.textContent=p.replace(/{([^}]+)}/g,(_,u)=>this.state[u]!==void 0?this.state[u]:this.hasAttribute(u)?this.getAttribute(u):_))}),n.querySelectorAll("*[onclick]").forEach(i=>{const p=i.getAttribute("onclick").match(/{\s*([\w$]+)\(\)\s*}/);if(!p)return;const _=p[1];i.removeAttribute("onclick"),i.addEventListener("click",()=>{const u=this.state[_];if(typeof u=="function")try{u()}catch(A){console.error(`Error in handler ${_}:`,A)}})})}_getAllTextNodes(n){const a=[],i=document.createTreeWalker(n,NodeFilter.SHOW_TEXT,null,!1);let p;for(;p=i.nextNode();)a.push(p);return a}_update(){const n=h.content.cloneNode(!0);this._processTemplate(n),this.shadowRoot?(this.shadowRoot.innerHTML="",this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(n)):(this.innerHTML="",this.appendChild(this.styleElement),this.appendChild(n))}static get observedAttributes(){return f}attributeChangedCallback(n,a,i){a!==i&&(this.state[n]=i)}emit(n,a){const i=a!=null?a:this.state;this.dispatchEvent(new CustomEvent(n,{detail:i,bubbles:!0}))}}customElements.define(c,L),e.log(`Web component defined: <${c}></${c}>`)}},Symbol.toStringTag,{value:"Module"}));o.ladrillos=w,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
@@ -0,0 +1 @@
1
+ "use strict";var S=Object.defineProperty;var T=(s,e,t)=>e in s?S(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var a=(s,e,t)=>T(s,typeof e!="symbol"?e+"":e,t);var _=(s,e,t)=>new Promise((i,c)=>{var m=r=>{try{n(t.next(r))}catch(p){c(p)}},g=r=>{try{n(t.throw(r))}catch(p){c(p)}},n=r=>r.done?i(r.value):Promise.resolve(r.value).then(m,g);n((t=t.apply(s,e)).next())});const l={log(s,...e){},error(s,...e){console.error(s,...e)},warn(s,...e){}},o=class o{constructor(){this.components={},this._cache=new Map}registerComponent(e,t,i=!0){return _(this,null,function*(){if(this.components[e]){l.log(`Component ${e} already registered, skipping.`);return}try{let c=this._cache.get(t);c||(c=yield(yield fetch(t)).text(),this._cache.set(t,c));const m=c.replace(o._SCRIPT_ALL,"").replace(o._STYLE_ALL,""),g=document.createElement("template");g.innerHTML=m;const n=o._SCRIPT_ONE.exec(c),r=o._STYLE_ONE.exec(c);this.components[e]={tagName:e,template:g,script:(n==null?void 0:n[1].trim())||"",style:(r==null?void 0:r[1].trim())||""},this._defineWebComponent(e,i),l.log(`Component ${e} registered successfully`)}catch(c){l.error(`Failed to register component ${e}:`,c)}})}_defineWebComponent(e,t){return _(this,null,function*(){const{defineWebComponent:i}=yield Promise.resolve().then(()=>require("./webcomponent-Mp1_EAq9.js"));i(this.components[e],t)})}};a(o,"_SCRIPT_ALL",/<script>([\s\S]*?)<\/script>/g),a(o,"_STYLE_ALL",/<style>([\s\S]*?)<\/style>/g),a(o,"_SCRIPT_ONE",/<script>([\s\S]*?)<\/script>/),a(o,"_STYLE_ONE",/<style>([\s\S]*?)<\/style>/);let h=o;const u=new h;exports.ladrillos=u;exports.logger=l;
@@ -0,0 +1,94 @@
1
+ var h = Object.defineProperty;
2
+ var T = (s, e, t) => e in s ? h(s, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : s[e] = t;
3
+ var a = (s, e, t) => T(s, typeof e != "symbol" ? e + "" : e, t);
4
+ var m = (s, e, t) => new Promise((i, c) => {
5
+ var l = (r) => {
6
+ try {
7
+ n(t.next(r));
8
+ } catch (g) {
9
+ c(g);
10
+ }
11
+ }, p = (r) => {
12
+ try {
13
+ n(t.throw(r));
14
+ } catch (g) {
15
+ c(g);
16
+ }
17
+ }, n = (r) => r.done ? i(r.value) : Promise.resolve(r.value).then(l, p);
18
+ n((t = t.apply(s, e)).next());
19
+ });
20
+ const _ = {
21
+ /**
22
+ * Log a message only in development mode
23
+ * @param {string} message - The message to log
24
+ * @param {any[]} args - Additional arguments to log
25
+ */
26
+ log(s, ...e) {
27
+ },
28
+ /**
29
+ * Log an error (always logs in both dev and production)
30
+ * @param {string} message - The error message
31
+ * @param {any[]} args - Additional arguments to log
32
+ */
33
+ error(s, ...e) {
34
+ console.error(s, ...e);
35
+ },
36
+ /**
37
+ * Log a warning only in development mode
38
+ * @param {string} message - The warning message
39
+ * @param {any[]} args - Additional arguments to log
40
+ */
41
+ warn(s, ...e) {
42
+ }
43
+ }, o = class o {
44
+ constructor() {
45
+ this.components = {}, this._cache = /* @__PURE__ */ new Map();
46
+ }
47
+ /**
48
+ * @param {string} name
49
+ * @param {string} path
50
+ * @param {boolean} [useShadowDOM=true]
51
+ * @returns {Promise<void>}
52
+ */
53
+ registerComponent(e, t, i = !0) {
54
+ return m(this, null, function* () {
55
+ if (this.components[e]) {
56
+ _.log(`Component ${e} already registered, skipping.`);
57
+ return;
58
+ }
59
+ try {
60
+ let c = this._cache.get(t);
61
+ c || (c = yield (yield fetch(t)).text(), this._cache.set(t, c));
62
+ const l = c.replace(o._SCRIPT_ALL, "").replace(o._STYLE_ALL, ""), p = document.createElement("template");
63
+ p.innerHTML = l;
64
+ const n = o._SCRIPT_ONE.exec(c), r = o._STYLE_ONE.exec(c);
65
+ this.components[e] = {
66
+ tagName: e,
67
+ template: p,
68
+ script: (n == null ? void 0 : n[1].trim()) || "",
69
+ style: (r == null ? void 0 : r[1].trim()) || ""
70
+ }, this._defineWebComponent(e, i), _.log(`Component ${e} registered successfully`);
71
+ } catch (c) {
72
+ _.error(`Failed to register component ${e}:`, c);
73
+ }
74
+ });
75
+ }
76
+ /**
77
+ * @private
78
+ * @param {string} name
79
+ * @param {boolean} useShadowDOM
80
+ */
81
+ _defineWebComponent(e, t) {
82
+ return m(this, null, function* () {
83
+ const { defineWebComponent: i } = yield import("./webcomponent-BsA_Nb1m.mjs");
84
+ i(this.components[e], t);
85
+ });
86
+ }
87
+ };
88
+ a(o, "_SCRIPT_ALL", /<script>([\s\S]*?)<\/script>/g), a(o, "_STYLE_ALL", /<style>([\s\S]*?)<\/style>/g), a(o, "_SCRIPT_ONE", /<script>([\s\S]*?)<\/script>/), a(o, "_STYLE_ONE", /<style>([\s\S]*?)<\/style>/);
89
+ let S = o;
90
+ const E = new S();
91
+ export {
92
+ E as a,
93
+ _ as l
94
+ };
@@ -0,0 +1,107 @@
1
+ import { l as u } from "./main-oMNAxRMg.mjs";
2
+ function E(r, h = {}) {
3
+ return new Proxy(h, {
4
+ set(i, o, l) {
5
+ const d = i[o];
6
+ return i[o] = l, d !== l && !r._initializing && r._update(), !0;
7
+ },
8
+ get(i, o) {
9
+ return i[o];
10
+ }
11
+ });
12
+ }
13
+ const N = (r, h) => {
14
+ if (!r) {
15
+ u.error("Component is not defined or invalid.");
16
+ return;
17
+ }
18
+ if (customElements.get(r.tagName)) {
19
+ u.warn(`Component ${r.tagName} is already defined.`);
20
+ return;
21
+ }
22
+ const { tagName: i, template: o, script: l, style: d } = r, m = ((p) => {
23
+ const t = /{(.*?)}/g, n = /* @__PURE__ */ new Set();
24
+ let e;
25
+ for (; (e = t.exec(p.innerHTML)) !== null; )
26
+ n.add(e[1].trim().toLowerCase());
27
+ return Array.from(n);
28
+ })(o), f = l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g, "state.$1 =").replace(/function\s+([\w$]+)\s*\(/g, "state.$1 = function ("), g = l ? new Function("state", `with(state){${f}}`) : () => {
29
+ };
30
+ class C extends HTMLElement {
31
+ constructor() {
32
+ super(), h && this.attachShadow({ mode: "open" }), this.state = {}, this.styleElement = document.createElement("style"), this.styleElement.textContent = d || "";
33
+ }
34
+ // Called when the element is first added to the DOM
35
+ connectedCallback() {
36
+ const t = o.content.cloneNode(!0);
37
+ this.state = E(this, {}), this._initializing = !0;
38
+ try {
39
+ g.call(this, this.state);
40
+ } catch (n) {
41
+ console.error("Error initializing component script:", n);
42
+ } finally {
43
+ this._initializing = !1;
44
+ }
45
+ this._processTemplate(t), this.shadowRoot ? (this.shadowRoot.appendChild(this.styleElement), this.shadowRoot.appendChild(t)) : (this.appendChild(this.styleElement), this.appendChild(t));
46
+ }
47
+ _processTemplate(t) {
48
+ this._getAllTextNodes(t).forEach((e) => {
49
+ const s = e.textContent;
50
+ s.includes("{") && s.includes("}") && (e.textContent = s.replace(/{([^}]+)}/g, (c, a) => this.state[a] !== void 0 ? this.state[a] : this.hasAttribute(a) ? this.getAttribute(a) : c));
51
+ }), t.querySelectorAll("*[onclick]").forEach((e) => {
52
+ const s = e.getAttribute("onclick").match(/{\s*([\w$]+)\(\)\s*}/);
53
+ if (!s) return;
54
+ const c = s[1];
55
+ e.removeAttribute("onclick"), e.addEventListener("click", () => {
56
+ const a = this.state[c];
57
+ if (typeof a == "function")
58
+ try {
59
+ a();
60
+ } catch (w) {
61
+ console.error(`Error in handler ${c}:`, w);
62
+ }
63
+ });
64
+ });
65
+ }
66
+ _getAllTextNodes(t) {
67
+ const n = [], e = document.createTreeWalker(
68
+ t,
69
+ NodeFilter.SHOW_TEXT,
70
+ null,
71
+ !1
72
+ );
73
+ let s;
74
+ for (; s = e.nextNode(); )
75
+ n.push(s);
76
+ return n;
77
+ }
78
+ _update() {
79
+ const t = o.content.cloneNode(!0);
80
+ this._processTemplate(t), this.shadowRoot ? (this.shadowRoot.innerHTML = "", this.shadowRoot.appendChild(this.styleElement), this.shadowRoot.appendChild(t)) : (this.innerHTML = "", this.appendChild(this.styleElement), this.appendChild(t));
81
+ }
82
+ // Called when the element is removed from the DOM
83
+ // disconnectedCallback() {
84
+ // logger.log("disconnectedCallback", this);
85
+ // }
86
+ // property
87
+ static get observedAttributes() {
88
+ return m;
89
+ }
90
+ attributeChangedCallback(t, n, e) {
91
+ n !== e && (this.state[t] = e);
92
+ }
93
+ emit(t, n) {
94
+ const e = n != null ? n : this.state;
95
+ this.dispatchEvent(
96
+ new CustomEvent(t, {
97
+ detail: e,
98
+ bubbles: !0
99
+ })
100
+ );
101
+ }
102
+ }
103
+ customElements.define(i, C), u.log(`Web component defined: <${i}></${i}>`);
104
+ };
105
+ export {
106
+ N as defineWebComponent
107
+ };
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const u=require("./main-Dju_Az3Y.js");function E(r,d={}){return new Proxy(d,{set(i,o,l){const h=i[o];return i[o]=l,h!==l&&!r._initializing&&r._update(),!0},get(i,o){return i[o]}})}const b=(r,d)=>{if(!r){u.logger.error("Component is not defined or invalid.");return}if(customElements.get(r.tagName)){u.logger.warn(`Component ${r.tagName} is already defined.`);return}const{tagName:i,template:o,script:l,style:h}=r,m=(p=>{const t=/{(.*?)}/g,n=new Set;let e;for(;(e=t.exec(p.innerHTML))!==null;)n.add(e[1].trim().toLowerCase());return Array.from(n)})(o),f=l.replace(/\b(?:const|let|var)\s+([\w$]+)\s*=/g,"state.$1 =").replace(/function\s+([\w$]+)\s*\(/g,"state.$1 = function ("),g=l?new Function("state",`with(state){${f}}`):()=>{};class C extends HTMLElement{constructor(){super(),d&&this.attachShadow({mode:"open"}),this.state={},this.styleElement=document.createElement("style"),this.styleElement.textContent=h||""}connectedCallback(){const t=o.content.cloneNode(!0);this.state=E(this,{}),this._initializing=!0;try{g.call(this,this.state)}catch(n){console.error("Error initializing component script:",n)}finally{this._initializing=!1}this._processTemplate(t),this.shadowRoot?(this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.appendChild(this.styleElement),this.appendChild(t))}_processTemplate(t){this._getAllTextNodes(t).forEach(e=>{const s=e.textContent;s.includes("{")&&s.includes("}")&&(e.textContent=s.replace(/{([^}]+)}/g,(c,a)=>this.state[a]!==void 0?this.state[a]:this.hasAttribute(a)?this.getAttribute(a):c))}),t.querySelectorAll("*[onclick]").forEach(e=>{const s=e.getAttribute("onclick").match(/{\s*([\w$]+)\(\)\s*}/);if(!s)return;const c=s[1];e.removeAttribute("onclick"),e.addEventListener("click",()=>{const a=this.state[c];if(typeof a=="function")try{a()}catch(w){console.error(`Error in handler ${c}:`,w)}})})}_getAllTextNodes(t){const n=[],e=document.createTreeWalker(t,NodeFilter.SHOW_TEXT,null,!1);let s;for(;s=e.nextNode();)n.push(s);return n}_update(){const t=o.content.cloneNode(!0);this._processTemplate(t),this.shadowRoot?(this.shadowRoot.innerHTML="",this.shadowRoot.appendChild(this.styleElement),this.shadowRoot.appendChild(t)):(this.innerHTML="",this.appendChild(this.styleElement),this.appendChild(t))}static get observedAttributes(){return m}attributeChangedCallback(t,n,e){n!==e&&(this.state[t]=e)}emit(t,n){const e=n!=null?n:this.state;this.dispatchEvent(new CustomEvent(t,{detail:e,bubbles:!0}))}}customElements.define(i,C),u.logger.log(`Web component defined: <${i}></${i}>`)};exports.defineWebComponent=b;
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "ladrillosjs",
3
+ "version": "0.1.0",
4
+ "description": "A lightweight, zero-dependency web component framework for building modular web applications.",
5
+ "files": [
6
+ "dist"
7
+ ],
8
+ "main": "./dist/ladrillosjs.cjs.js",
9
+ "module": "./dist/ladrillosjs.es.js",
10
+ "browser": "./dist/ladrillosjs.umd.js",
11
+ "exports": {
12
+ ".": {
13
+ "import": "./dist/ladrillosjs.es.js",
14
+ "require": "./dist/ladrillosjs.cjs.js",
15
+ "browser": "./dist/ladrillosjs.umd.js"
16
+ }
17
+ },
18
+ "scripts": {
19
+ "prepare": "npm run build",
20
+ "dev": "vite",
21
+ "build": "vite build",
22
+ "preview": "vite preview"
23
+ },
24
+ "keywords": [],
25
+ "author": "Daniel Rubio",
26
+ "license": "MIT",
27
+ "devDependencies": {
28
+ "vite": "^6.2.5"
29
+ }
30
+ }