@rexllins/zi 0.0.2

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/README.md ADDED
File without changes
package/dist/zi.cjs.js ADDED
@@ -0,0 +1,2 @@
1
+ "use strict";Object.defineProperty(exports,"__esModule",{value:!0});const t=t=>"function"==typeof t,e=()=>{};function n(...t){"undefined"!=typeof globalThis&&globalThis.Zi?.config?.debug&&console.warn("[Zi]",...t)}var s=Object.freeze({__proto__:null,_isObject:t=>null!==t&&"object"==typeof t,_isFn:t,_noop:e,warn:n,log:function(...t){"undefined"!=typeof globalThis&&globalThis.Zi?.config?.debug&&console.log("[Zi]",...t)}});class o{constructor(){this.subs=new Set}depend(){const t=r.currentEffect;t&&this.subs.add(t)}notify(){this.subs.forEach(t=>{try{t()}catch(t){n("Effect error",t)}})}}class r{constructor(){this.targetMap=new WeakMap}static currentEffect=null;_depFor(t,e){let n=this.targetMap.get(t);return n||this.targetMap.set(t,n=new Map),n.has(e)||n.set(e,new o),n.get(e)}reactive(t){if(!t||"object"!=typeof t||t.__isReactive)return t;const e=this;return new Proxy(t,{get(t,n,s){if("__isReactive"===n)return!0;const o=Reflect.get(t,n,s);return e._depFor(t,n).depend(),o&&"object"==typeof o?e.reactive(o):o},set(t,n,s,o){const r=t[n],i=Reflect.set(t,n,s,o);return r!==s&&e._depFor(t,n).notify(),i},deleteProperty(t,n){const s=Reflect.deleteProperty(t,n);return e._depFor(t,n).notify(),s}})}effect(t,{lazy:e=!1}={}){const n=()=>{r.currentEffect=n;try{return t()}finally{r.currentEffect=null}};return e||n(),n}computed(t){let e,n=!0;const s=this.effect(()=>{e=t(),n=!1},{lazy:!0});return{get value(){if(n){r.currentEffect=s;try{e=t()}finally{r.currentEffect=null}n=!1}return e}}}watch(t,e){let n;return this.effect(()=>{const s=t();e(s,n),n=s})}}const i=new r;class c{constructor(t={}){this.state=i.reactive(t),this._modules={}}registerModule(t,e){if(this._modules[t])throw new Error(`Module ${t} exists`);const n=i.reactive(e);return this._modules[t]=n,this.state[t]=n,n}patch(t){t(this.state)}getModule(t){return this._modules[t]}}function a(t,e={}){try{const n=t.trim();if(/^[\w.$\[\]]+$/.test(n))return n.split(".").reduce((t,e)=>null==t?void 0:t[e.trim()],e);const s=new Proxy(e,{get:(t,e)=>e in t?t[e]:void 0,has:()=>!0});return Function("scoped","with(scoped){return ("+t+");}")(s)}catch(e){return void n("Eval error",t,e)}}function h(t,e,n){const s=e&&e.state||{},o=e&&e.props||{};return a(t,Object.assign({},s,o,n||{}))}function u(t,e,s){try{const n=e.state||{},o=t.split(".");let r=n;for(let t=0;t<o.length-1;t++){const e=o[t].trim();e in r||(r[e]={}),r=r[e]}r[o[o.length-1].trim()]=s}catch(e){n("Assign error",t,e)}}function l(t){const e=document.createElement("template");return e.innerHTML=t.trim(),e.content}function p(t){const e=[],n=t=>{e.push(t),t.childNodes&&t.childNodes.forEach(t=>n(t))};return t.childNodes.forEach(t=>n(t)),e}const d={"z-if":(t,e,n,s)=>{i.effect(()=>{const o=!!h(e,n,s);t.__zi_hidden=!o,t.style.display=o?"":"none"})},"z-show":(t,e,n,s)=>{i.effect(()=>{t.style.display=h(e,n,s)?"":"none"})},"z-text":(t,e,n,s)=>{i.effect(()=>{t.textContent=h(e,n,s)||""})},"z-html":(t,e,n,s)=>{i.effect(()=>{t.innerHTML=h(e,n,s)||""})},"z-model":(t,e,n)=>{i.effect(()=>{const s=h(e,n);"checkbox"===t.type?t.checked=!!s:t.value!==s&&(t.value=s||"")});const s=s=>{"checkbox"===t.type?u(e,n,t.checked):u(e,n,t.value)};t.addEventListener("input",s),t.addEventListener("change",s)},"z-for":(t,e,s)=>{const o=t.parentNode,r=document.createComment("z-for");o.replaceChild(r,t);const c=e.match(/^(?:\(([^)]+)\)|([^\s]+))\s+in\s+(.+)$/);if(!c)return n("Invalid z-for",e);const a=(c[1]||c[2]).split(",").map(t=>t.trim()),u=c[3].trim(),l={};i.effect(()=>{(h(u,s)||[]).forEach((e,n)=>{const i=e&&e.id||n;let c=l[i];if(!c){c=t.cloneNode(!0),l[i]=c;const h=Object.assign({},s.getContext(),{[a[0]]:e,[a[1]||"$index"]:n});f(c,s,h),o.insertBefore(c,r.nextSibling)}})})}};function f(e,s,o){if(3===e.nodeType){const t=e.nodeValue;return void(/{{/.test(t)&&i.effect(()=>{e.nodeValue=function(t,e={}){return t.replace(/{{\s*([^}]+)\s*}}/g,(t,s)=>{try{const t=a(s,e);return null==t?"":String(t)}catch(t){return n("Mustache eval",s,t),""}})}(t,o?Object.assign({},s.getContext(),o):s.getContext())}))}1===e.nodeType&&(Array.from(e.attributes||[]).forEach(r=>{if(r.name.startsWith("@")){const i=r.name.slice(1),c=r.value.trim();e.addEventListener(i,e=>{const r=s.methods&&s.methods[c];if(t(r))return r.call(s,e,s);try{Function("event","state","props","ctx","with(state){with(props){with(ctx||{}){"+c+"}}}")(e,s.state,s.props,o||{})}catch(t){n("Inline handler",c,t)}})}}),Array.from(e.attributes||[]).forEach(t=>{if(t.name.startsWith("z-")){const r=s._dirRegistry[t.name]||d[t.name];if(r)try{r(e,t.value,s,o)}catch(e){n("Directive",t.name,e)}else n("Unknown directive",t.name)}}),e.__zi_hidden||Array.from(e.childNodes).forEach(t=>f(t,s,o)))}class m{constructor({template:t="",state:n={},props:s={},methods:o={},onInit:r=e,onMount:c=e,onDestroy:a=e,directives:h={}}={}){this.template=t,this.state=i.reactive(n),this.props=s,this.methods=o,this.onInit=r,this.onMount=c,this.onDestroy=a,this.directives=h,this._dirRegistry=Object.assign({},h),this.el=null,this.mounted=!1}getContext(){return Object.assign({},this.state,this.props)}_resolveTemplate(){if(!this.template)return"";if("string"==typeof this.template&&this.template.startsWith("#")){const t=document.querySelector(this.template);if(!t)throw new Error("Template selector not found: "+this.template);return t.innerHTML}return"string"==typeof this.template?this.template:this.template instanceof HTMLElement?this.template.innerHTML:""}mount(t){this.onInit();const e="string"==typeof t?document.querySelector(t):t;if(!e)throw new Error("Mount not found");this.el=e,this._render(),this.mounted=!0,this.onMount()}unmount(){this.onDestroy(),this.el&&(this.el.innerHTML=""),this.mounted=!1}_render(){const t=l(this._resolveTemplate());p(t).forEach(t=>f(t,this)),this.el.innerHTML="",this.el.appendChild(t)}}class g{constructor({base:t="",headers:e={},fetchImpl:n=fetch}={}){this.base=t.replace(/\/$/,""),this.headers={...e},this.fetch=n}_url(t){return t.startsWith("http")?t:`${this.base}/${t.replace(/^\//,"")}`}async request(t,e,{params:n,body:s,headers:o}={}){const r=this._url(e)+(n?"?"+new URLSearchParams(n):""),i={method:t,headers:{...this.headers,...o||{}}};s&&((i.headers["Content-Type"]||"").includes("application/json")?i.body=JSON.stringify(s):i.body=s);const c=await this.fetch(r,i);if(!c.ok)throw new Error(`HTTP ${c.status}: ${c.statusText}`);return(c.headers.get("content-type")||"").includes("application/json")?c.json():c.text()}get(t,e){return this.request("GET",t,e)}post(t,e){return this.request("POST",t,e)}put(t,e){return this.request("PUT",t,e)}del(t,e){return this.request("DELETE",t,e)}}class y{constructor(t=[],{mode:e="hash",root:n=document.body,notFound:s=null}={}){this.routes=t,this.mode=e,this.root=n,this.current=null,this._cached=[],this._notFound=s,this._onHashChange=this._onHashChange.bind(this),this._compileRoutes()}_compileRoutes(){this._cached=this.routes.map(t=>{const e=[],n=new RegExp("^"+t.path.replace(/:([\w_]+)/g,(t,n)=>(e.push(n),"([^/]+)"))+"$");return{route:t,rx:n,keys:e}})}_match(t){for(const e of this._cached){const n=t.match(e.rx);if(n){const t={};return e.keys.forEach((e,s)=>t[e]=n[s+1]),{route:e.route,params:t}}}return null}_onHashChange(){const t=location.hash.replace(/^#/,"")||"/",e=this._match(t);this._renderRoute(e,t)}_mountComponent(t,e){this.current&&this.current.unmount&&this.current.unmount();const n=this.root;if("function"==typeof t){const s=t({params:e,router:this});s instanceof m?(s.props=Object.assign({},s.props,{$routeParams:e}),s.mount(n),this.current=s):"string"==typeof s?(n.innerHTML=s,this.current={unmount(){n.innerHTML=""}}):s instanceof HTMLElement&&(n.innerHTML="",n.appendChild(s),this.current={unmount(){n.innerHTML=""}})}else t instanceof m?(t.props=Object.assign({},t.props,{$routeParams:e}),t.mount(n),this.current=t):"string"==typeof t&&(n.innerHTML=t,this.current={unmount(){n.innerHTML=""}})}_renderRoute(t,e){if(!t){if(this._notFound){const t=this._notFound();this._mountComponent(t,{})}else n("Route not found",e);return}const{route:s,params:o}=t,r="function"==typeof s.component?s.component({params:o,router:this}):s.component;this._mountComponent(r,o)}init(t){this.root="string"==typeof t?document.querySelector(t):t||document.body,window.addEventListener("hashchange",this._onHashChange),this._onHashChange()}navigate(t){location.hash=t}}class _{constructor({root:t="#app",store:e=null,api:n=null}={}){if(this.root="string"==typeof t?document.querySelector(t):t,!this.root)throw new Error("Root not found");this.store=e||new c({}),this.api=n||new g({}),this.router=null,this.plugins=[]}use(e,n){t(e)?(e({app:this,store:this.store,api:this.api}),this.plugins.push(e)):e&&e.install&&(e.install(this,n),this.plugins.push(e))}mountComponent(t){if(!(t instanceof m))throw new Error("mountComponent expects Component");t.mount(this.root)}useRouter(t){this.router=t}}const w={Reactive:i,Store:c,Component:m,API:g,Router:y,App:_,Directives:d,createFragmentFromHTML:l,processNode:f,flattenNodes:p,...s},b=Object.assign({config:{debug:!0}},w,{createApp:t=>new _(t),createComponent:t=>new m(t),createStore:t=>new c(t),createAPI:t=>new g(t)});"undefined"!=typeof window&&(window.Zi=b),exports.API=g,exports.App=_,exports.Component=m,exports.Directives=d,exports.Reactive=i,exports.Router=y,exports.Store=c,exports.createFragmentFromHTML=l,exports.default=b,exports.flattenNodes=p,exports.processNode=f;
2
+ //# sourceMappingURL=zi.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zi.cjs.js","sources":["../src/utils.js","../src/reactive.js","../src/store.js","../src/eval.js","../src/dom.js","../src/component.js","../src/api.js","../src/router.js","../src/app.js","../src/index.js"],"sourcesContent":["// src/utils.js\r\nexport const _isObject = v => v !== null && typeof v === 'object';\r\nexport const _isFn = v => typeof v === 'function';\r\nexport const _noop = () => { };\r\n\r\nexport function warn(...args) {\r\n if (typeof globalThis !== 'undefined' && globalThis.Zi?.config?.debug) {\r\n console.warn('[Zi]', ...args);\r\n }\r\n}\r\nexport function log(...args) {\r\n if (typeof globalThis !== 'undefined' && globalThis.Zi?.config?.debug) {\r\n console.log('[Zi]', ...args);\r\n }\r\n}\r\n","// src/reactive.js\r\nimport { warn } from './utils.js';\r\n\r\nexport class Dep {\r\n constructor() { this.subs = new Set(); }\r\n depend() { const eff = ReactiveSystem.currentEffect; if (eff) this.subs.add(eff); }\r\n notify() { this.subs.forEach(fn => { try { fn(); } catch (e) { warn('Effect error', e); } }); }\r\n}\r\n\r\nexport class ReactiveSystem {\r\n constructor() { this.targetMap = new WeakMap(); }\r\n static currentEffect = null;\r\n\r\n _depFor(target, key) {\r\n let depsMap = this.targetMap.get(target);\r\n if (!depsMap) this.targetMap.set(target, depsMap = new Map());\r\n if (!depsMap.has(key)) depsMap.set(key, new Dep());\r\n return depsMap.get(key);\r\n }\r\n\r\n reactive(obj) {\r\n if (!obj || typeof obj !== 'object' || obj.__isReactive) return obj;\r\n const self = this;\r\n return new Proxy(obj, {\r\n get(target, key, receiver) {\r\n if (key === '__isReactive') return true;\r\n const res = Reflect.get(target, key, receiver);\r\n self._depFor(target, key).depend();\r\n return (res && typeof res === 'object') ? self.reactive(res) : res;\r\n },\r\n set(target, key, val, receiver) {\r\n const old = target[key];\r\n const res = Reflect.set(target, key, val, receiver);\r\n if (old !== val) self._depFor(target, key).notify();\r\n return res;\r\n },\r\n deleteProperty(target, key) {\r\n const res = Reflect.deleteProperty(target, key);\r\n self._depFor(target, key).notify();\r\n return res;\r\n }\r\n });\r\n }\r\n\r\n effect(fn, { lazy = false } = {}) {\r\n const runner = () => { ReactiveSystem.currentEffect = runner; try { return fn(); } finally { ReactiveSystem.currentEffect = null; } };\r\n if (!lazy) runner();\r\n return runner;\r\n }\r\n\r\n computed(getter) {\r\n let cache, dirty = true;\r\n const runner = this.effect(() => { cache = getter(); dirty = false; }, { lazy: true });\r\n return {\r\n get value() {\r\n if (dirty) {\r\n ReactiveSystem.currentEffect = runner;\r\n try { cache = getter(); } finally { ReactiveSystem.currentEffect = null; }\r\n dirty = false;\r\n }\r\n return cache;\r\n }\r\n };\r\n }\r\n\r\n watch(getter, cb) {\r\n let old;\r\n return this.effect(() => { const val = getter(); cb(val, old); old = val; });\r\n }\r\n}\r\n\r\nexport const Reactive = new ReactiveSystem();\r\n","// src/store.js\r\nimport { Reactive } from './reactive.js';\r\n\r\nexport class Store {\r\n constructor(initial = {}) {\r\n this.state = Reactive.reactive(initial);\r\n this._modules = {};\r\n }\r\n\r\n registerModule(name, stateObj) {\r\n if (this._modules[name]) throw new Error(`Module ${name} exists`);\r\n const mod = Reactive.reactive(stateObj);\r\n this._modules[name] = mod;\r\n this.state[name] = mod;\r\n return mod;\r\n }\r\n\r\n patch(fn) { fn(this.state); }\r\n\r\n getModule(name) { return this._modules[name]; }\r\n}\r\n","// src/eval.js\r\nimport { warn } from './utils.js';\r\n\r\n/**\r\n * Evaluate expression in a given scope object.\r\n *\r\n * scope is plain object of variables.\r\n */\r\nexport function evaluateInScope(expr, scope = {}) {\r\n try {\r\n const trimmed = expr.trim();\r\n if (/^[\\w.$\\[\\]]+$/.test(trimmed)) {\r\n return trimmed.split('.').reduce((a, k) => (a == null ? undefined : a[k.trim()]), scope);\r\n }\r\n const proxy = new Proxy(scope, { get(t, k) { return k in t ? t[k] : undefined; }, has() { return true; } });\r\n return Function('scoped', 'with(scoped){return (' + expr + ');}')(proxy);\r\n } catch (e) {\r\n warn('Eval error', expr, e);\r\n return undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Evaluate expression in context of component (cmp)\r\n * cmp expected to have state and props.\r\n */\r\nexport function evaluateExpr(expr, cmp, ctx) {\r\n const state = (cmp && cmp.state) || {};\r\n const props = (cmp && cmp.props) || {};\r\n const scoped = Object.assign({}, state, props, ctx || {});\r\n return evaluateInScope(expr, scoped);\r\n}\r\n\r\n/**\r\n * Assign to dot-path inside component.state\r\n */\r\nexport function assignExpr(expr, cmp, value) {\r\n try {\r\n const state = cmp.state || {};\r\n const parts = expr.split('.');\r\n let target = state;\r\n for (let i = 0; i < parts.length - 1; i++) {\r\n const k = parts[i].trim();\r\n if (!(k in target)) target[k] = {};\r\n target = target[k];\r\n }\r\n target[parts[parts.length - 1].trim()] = value;\r\n } catch (e) {\r\n warn('Assign error', expr, e);\r\n }\r\n}\r\n\r\n/**\r\n * Simple mustache parser that uses evaluateInScope for expressions\r\n */\r\nexport function parseMustache(template, scope = {}) {\r\n return template.replace(/{{\\s*([^}]+)\\s*}}/g, (_, expr) => {\r\n try {\r\n const val = evaluateInScope(expr, scope);\r\n return val == null ? '' : String(val);\r\n } catch (e) {\r\n warn('Mustache eval', expr, e);\r\n return '';\r\n }\r\n });\r\n}\r\n","// src/dom.js\r\nimport { evaluateExpr, assignExpr, parseMustache } from './eval.js';\r\nimport { Reactive } from './reactive.js';\r\nimport { warn, _isFn } from './utils.js';\r\n\r\n/** DOM helpers */\r\nexport function createFragmentFromHTML(html) {\r\n const template = document.createElement('template');\r\n template.innerHTML = html.trim();\r\n return template.content;\r\n}\r\n\r\nexport function flattenNodes(root) {\r\n const out = [];\r\n const walk = node => {\r\n out.push(node);\r\n node.childNodes && node.childNodes.forEach(child => walk(child));\r\n };\r\n root.childNodes.forEach(n => walk(n));\r\n return out;\r\n}\r\n\r\n/** Directives object (z-if, z-show, z-text, etc.) */\r\nexport const Directives = {\r\n 'z-if': (el, expr, cmp, ctx) => {\r\n const apply = () => {\r\n const val = !!evaluateExpr(expr, cmp, ctx);\r\n el.__zi_hidden = !val;\r\n el.style.display = val ? '' : 'none';\r\n };\r\n Reactive.effect(apply);\r\n },\r\n 'z-show': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.style.display = evaluateExpr(expr, cmp, ctx) ? '' : 'none';\r\n });\r\n },\r\n 'z-text': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.textContent = (evaluateExpr(expr, cmp, ctx) || '');\r\n });\r\n },\r\n 'z-html': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.innerHTML = (evaluateExpr(expr, cmp, ctx) || '');\r\n });\r\n },\r\n 'z-model': (el, expr, cmp) => {\r\n const setEl = () => {\r\n const v = evaluateExpr(expr, cmp);\r\n if (el.type === 'checkbox') el.checked = !!v;\r\n else if (el.value !== v) el.value = v || '';\r\n };\r\n Reactive.effect(setEl);\r\n const handler = e => {\r\n if (el.type === 'checkbox') assignExpr(expr, cmp, el.checked);\r\n else assignExpr(expr, cmp, el.value);\r\n };\r\n el.addEventListener('input', handler);\r\n el.addEventListener('change', handler);\r\n },\r\n 'z-for': (el, expr, cmp) => {\r\n const parent = el.parentNode;\r\n const marker = document.createComment('z-for');\r\n parent.replaceChild(marker, el);\r\n const m = expr.match(/^(?:\\(([^)]+)\\)|([^\\s]+))\\s+in\\s+(.+)$/);\r\n if (!m) return warn('Invalid z-for', expr);\r\n const aliases = (m[1] || m[2]).split(',').map(s => s.trim());\r\n const sourceExpr = m[3].trim();\r\n const keyed = {};\r\n const render = () => {\r\n const list = evaluateExpr(sourceExpr, cmp) || [];\r\n // naive keyed reuse\r\n list.forEach((item, idx) => {\r\n const key = (item && item.id) || idx;\r\n let clone = keyed[key];\r\n if (!clone) {\r\n clone = el.cloneNode(true);\r\n keyed[key] = clone;\r\n const local = Object.assign({}, cmp.getContext(), { [aliases[0]]: item, [aliases[1] || '$index']: idx });\r\n processNode(clone, cmp, local);\r\n parent.insertBefore(clone, marker.nextSibling);\r\n }\r\n });\r\n };\r\n Reactive.effect(render);\r\n }\r\n};\r\n\r\n/**\r\n * processNode: walk a node fragment and attach directives & event handlers\r\n *\r\n * node - DOM node\r\n *\r\n * cmp - Component instance\r\n *\r\n * ctx - optional local context (for z-for items)\r\n */\r\nexport function processNode(node, cmp, ctx) {\r\n if (node.nodeType === 3) {\r\n const o = node.nodeValue;\r\n if (/{{/.test(o)) {\r\n Reactive.effect(() => {\r\n node.nodeValue = parseMustache(o, ctx ? Object.assign({}, cmp.getContext(), ctx) : cmp.getContext());\r\n });\r\n }\r\n return;\r\n }\r\n if (node.nodeType !== 1) return;\r\n\r\n Array.from(node.attributes || []).forEach(attr => {\r\n if (attr.name.startsWith('@')) {\r\n const evt = attr.name.slice(1);\r\n const h = attr.value.trim();\r\n node.addEventListener(evt, e => {\r\n const m = cmp.methods && cmp.methods[h];\r\n if (_isFn(m)) return m.call(cmp, e, cmp);\r\n try {\r\n Function('event', 'state', 'props', 'ctx', 'with(state){with(props){with(ctx||{}){' + h + '}}}')(e, cmp.state, cmp.props, ctx || {});\r\n } catch (err) {\r\n warn('Inline handler', h, err);\r\n }\r\n });\r\n }\r\n });\r\n\r\n Array.from(node.attributes || []).forEach(attr => {\r\n if (attr.name.startsWith('z-')) {\r\n const h = cmp._dirRegistry[attr.name] || Directives[attr.name];\r\n if (h) {\r\n try { h(node, attr.value, cmp, ctx); } catch (e) { warn('Directive', attr.name, e); }\r\n } else warn('Unknown directive', attr.name);\r\n }\r\n });\r\n\r\n if (node.__zi_hidden) return;\r\n Array.from(node.childNodes).forEach(c => processNode(c, cmp, ctx));\r\n}\r\n","// src/component.js\r\nimport { Reactive } from './reactive.js';\r\nimport { createFragmentFromHTML, flattenNodes, processNode } from './dom.js';\r\nimport { _noop } from './utils.js';\r\n\r\nexport class Component {\r\n constructor({ template = '', state = {}, props = {}, methods = {}, onInit = _noop, onMount = _noop, onDestroy = _noop, directives = {} } = {}) {\r\n this.template = template;\r\n this.state = Reactive.reactive(state);\r\n this.props = props;\r\n this.methods = methods;\r\n this.onInit = onInit;\r\n this.onMount = onMount;\r\n this.onDestroy = onDestroy;\r\n this.directives = directives;\r\n this._dirRegistry = Object.assign({}, directives); // will be merged by indexing code\r\n this.el = null;\r\n this.mounted = false;\r\n }\r\n\r\n getContext() { return Object.assign({}, this.state, this.props); }\r\n\r\n _resolveTemplate() {\r\n if (!this.template) return '';\r\n if (typeof this.template === 'string' && this.template.startsWith('#')) {\r\n const el = document.querySelector(this.template);\r\n if (!el) throw new Error('Template selector not found: ' + this.template);\r\n return el.innerHTML;\r\n }\r\n if (typeof this.template === 'string') return this.template;\r\n if (this.template instanceof HTMLElement) return this.template.innerHTML;\r\n return '';\r\n }\r\n\r\n mount(sel) {\r\n this.onInit();\r\n const mountEl = (typeof sel === 'string') ? document.querySelector(sel) : sel;\r\n if (!mountEl) throw new Error('Mount not found');\r\n this.el = mountEl;\r\n this._render();\r\n this.mounted = true;\r\n this.onMount();\r\n }\r\n\r\n unmount() {\r\n this.onDestroy();\r\n if (this.el) this.el.innerHTML = '';\r\n this.mounted = false;\r\n }\r\n\r\n _render() {\r\n const raw = this._resolveTemplate();\r\n const frag = createFragmentFromHTML(raw);\r\n // allow directives registry (local override) to be considered in processNode; for simplicity assume processNode uses cmp._dirRegistry\r\n flattenNodes(frag).forEach(n => processNode(n, this));\r\n this.el.innerHTML = '';\r\n this.el.appendChild(frag);\r\n }\r\n}\r\n","// src/api.js\r\nexport class API {\r\n constructor({ base = '', headers = {}, fetchImpl = fetch } = {}) {\r\n this.base = base.replace(/\\/$/, '');\r\n this.headers = { ...headers };\r\n this.fetch = fetchImpl;\r\n }\r\n\r\n _url(path) { return path.startsWith('http') ? path : `${this.base}/${path.replace(/^\\//, '')}`; }\r\n\r\n async request(method, path, { params, body, headers } = {}) {\r\n const url = this._url(path) + (params ? '?' + new URLSearchParams(params) : '');\r\n const opts = { method, headers: { ...this.headers, ...(headers || {}) } };\r\n if (body) {\r\n if ((opts.headers['Content-Type'] || '').includes('application/json')) opts.body = JSON.stringify(body);\r\n else opts.body = body;\r\n }\r\n const res = await this.fetch(url, opts);\r\n if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);\r\n const ct = res.headers.get('content-type') || '';\r\n return ct.includes('application/json') ? res.json() : res.text();\r\n }\r\n\r\n get(p, o) { return this.request('GET', p, o); }\r\n post(p, o) { return this.request('POST', p, o); }\r\n put(p, o) { return this.request('PUT', p, o); }\r\n del(p, o) { return this.request('DELETE', p, o); }\r\n}\r\n","// src/router.js\r\nimport { warn } from './utils.js';\r\nimport { Component } from './component.js';\r\n\r\nexport class Router {\r\n constructor(routes = [], { mode = 'hash', root = document.body, notFound = null } = {}) {\r\n this.routes = routes;\r\n this.mode = mode;\r\n this.root = root;\r\n this.current = null;\r\n this._cached = [];\r\n this._notFound = notFound;\r\n this._onHashChange = this._onHashChange.bind(this);\r\n this._compileRoutes();\r\n }\r\n\r\n _compileRoutes() {\r\n this._cached = this.routes.map(r => {\r\n const keys = [];\r\n const rx = new RegExp('^' + r.path.replace(/:([\\w_]+)/g, (_, k) => { keys.push(k); return '([^/]+)'; }) + '$');\r\n return { route: r, rx, keys };\r\n });\r\n }\r\n\r\n _match(path) {\r\n for (const e of this._cached) {\r\n const m = path.match(e.rx);\r\n if (m) {\r\n const p = {};\r\n e.keys.forEach((k, i) => p[k] = m[i + 1]);\r\n return { route: e.route, params: p };\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n _onHashChange() {\r\n const hash = location.hash.replace(/^#/, '') || '/';\r\n const matched = this._match(hash);\r\n this._renderRoute(matched, hash);\r\n }\r\n\r\n _mountComponent(comp, params) {\r\n if (this.current && this.current.unmount) this.current.unmount();\r\n const mp = this.root;\r\n if (typeof comp === 'function') {\r\n const inst = comp({ params, router: this });\r\n if (inst instanceof Component) {\r\n inst.props = Object.assign({}, inst.props, { $routeParams: params });\r\n inst.mount(mp);\r\n this.current = inst;\r\n } else if (typeof inst === 'string') {\r\n mp.innerHTML = inst;\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n } else if (inst instanceof HTMLElement) {\r\n mp.innerHTML = '';\r\n mp.appendChild(inst);\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n }\r\n } else if (comp instanceof Component) {\r\n comp.props = Object.assign({}, comp.props, { $routeParams: params });\r\n comp.mount(mp);\r\n this.current = comp;\r\n } else if (typeof comp === 'string') {\r\n mp.innerHTML = comp;\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n }\r\n }\r\n\r\n _renderRoute(matched, path) {\r\n if (!matched) {\r\n if (this._notFound) {\r\n const c = this._notFound();\r\n this._mountComponent(c, {});\r\n } else warn('Route not found', path);\r\n return;\r\n }\r\n const { route, params } = matched;\r\n const comp = (typeof route.component === 'function' ? route.component({ params, router: this }) : route.component);\r\n this._mountComponent(comp, params);\r\n }\r\n\r\n init(sel) {\r\n this.root = typeof sel === 'string' ? document.querySelector(sel) : (sel || document.body);\r\n window.addEventListener('hashchange', this._onHashChange);\r\n this._onHashChange();\r\n }\r\n\r\n navigate(path) { location.hash = path; }\r\n}\r\n","// src/app.js\r\nimport { Store } from './store.js';\r\nimport { API } from './api.js';\r\nimport { Router } from './router.js';\r\nimport { Component } from './component.js';\r\nimport { _isFn } from './utils.js';\r\n\r\nexport class App {\r\n constructor({ root = '#app', store = null, api = null } = {}) {\r\n this.root = (typeof root === 'string') ? document.querySelector(root) : root;\r\n if (!this.root) throw new Error('Root not found');\r\n this.store = store || new Store({});\r\n this.api = api || new API({});\r\n this.router = null;\r\n this.plugins = [];\r\n }\r\n\r\n use(plugin, options) {\r\n if (_isFn(plugin)) {\r\n plugin({ app: this, store: this.store, api: this.api });\r\n this.plugins.push(plugin);\r\n } else if (plugin && plugin.install) {\r\n plugin.install(this, options);\r\n this.plugins.push(plugin);\r\n }\r\n }\r\n\r\n mountComponent(c) {\r\n if (!(c instanceof Component)) throw new Error('mountComponent expects Component');\r\n c.mount(this.root);\r\n }\r\n\r\n useRouter(r) { this.router = r; }\r\n}\r\n","// src/index.js\r\nimport { Reactive } from './reactive.js';\r\nimport { Store } from './store.js';\r\nimport { Component } from './component.js';\r\nimport { API } from './api.js';\r\nimport { Router } from './router.js';\r\nimport { App } from './app.js';\r\nimport { Directives, createFragmentFromHTML, processNode, flattenNodes } from './dom.js';\r\nimport * as utils from './utils.js';\r\n\r\nconst ZiFramework = { Reactive, Store, Component, API, Router, App, Directives, createFragmentFromHTML, processNode, flattenNodes, ...utils };\r\nconst Zi = Object.assign({ config: { debug: true } }, ZiFramework, {\r\n createApp: o => new App(o),\r\n createComponent: o => new Component(o),\r\n createStore: i => new Store(i),\r\n createAPI: o => new API(o)\r\n});\r\n\r\nif (typeof window !== 'undefined') window.Zi = Zi;\r\n\r\nexport {\r\n Reactive, Store, Component, API, Router, App, Directives,\r\n createFragmentFromHTML, processNode, flattenNodes,\r\n Zi as default\r\n};\r\n"],"names":["_isFn","v","_noop","warn","args","globalThis","Zi","config","debug","console","log","Dep","constructor","this","subs","Set","depend","eff","ReactiveSystem","currentEffect","add","notify","forEach","fn","e","targetMap","WeakMap","static","_depFor","target","key","depsMap","get","set","Map","has","reactive","obj","__isReactive","self","Proxy","receiver","res","Reflect","val","old","deleteProperty","effect","lazy","runner","computed","getter","cache","dirty","value","watch","cb","Reactive","Store","initial","state","_modules","registerModule","name","stateObj","Error","mod","patch","getModule","evaluateInScope","expr","scope","trimmed","trim","test","split","reduce","a","k","undefined","proxy","t","Function","evaluateExpr","cmp","ctx","props","Object","assign","assignExpr","parts","i","length","createFragmentFromHTML","html","template","document","createElement","innerHTML","content","flattenNodes","root","out","walk","node","push","childNodes","child","n","Directives","el","__zi_hidden","style","display","textContent","type","checked","handler","addEventListener","parent","parentNode","marker","createComment","replaceChild","m","match","aliases","map","s","sourceExpr","keyed","item","idx","id","clone","cloneNode","local","getContext","processNode","insertBefore","nextSibling","nodeType","o","nodeValue","replace","_","String","parseMustache","Array","from","attributes","attr","startsWith","evt","slice","h","methods","call","err","_dirRegistry","c","Component","onInit","onMount","onDestroy","directives","mounted","_resolveTemplate","querySelector","HTMLElement","mount","sel","mountEl","_render","unmount","frag","appendChild","API","base","headers","fetchImpl","fetch","_url","path","request","method","params","body","url","URLSearchParams","opts","includes","JSON","stringify","ok","status","statusText","json","text","p","post","put","del","Router","routes","mode","notFound","current","_cached","_notFound","_onHashChange","bind","_compileRoutes","r","keys","rx","RegExp","route","_match","hash","location","matched","_renderRoute","_mountComponent","comp","mp","inst","router","$routeParams","component","init","window","navigate","App","store","api","plugins","use","plugin","options","app","install","mountComponent","useRouter","ZiFramework","utils","createApp","createComponent","createStore","createAPI"],"mappings":"oEACO,MACMA,EAAQC,GAAkB,mBAANA,EACpBC,EAAQ,OAEd,SAASC,KAAQC,GACM,oBAAfC,YAA8BA,WAAWC,IAAIC,QAAQC,OAC5DC,QAAQN,KAAK,UAAWC,EAEhC,+CARyBH,GAAW,OAANA,GAA2B,iBAANA,6BAS5C,YAAgBG,GACO,oBAAfC,YAA8BA,WAAWC,IAAIC,QAAQC,OAC5DC,QAAQC,IAAI,UAAWN,EAE/B,ICXO,MAAMO,EACT,WAAAC,GAAgBC,KAAKC,KAAO,IAAIC,GAAQ,CACxC,MAAAC,GAAW,MAAMC,EAAMC,EAAeC,cAAmBF,GAAKJ,KAAKC,KAAKM,IAAIH,EAAO,CACnF,MAAAI,GAAWR,KAAKC,KAAKQ,QAAQC,IAAQ,IAAMA,GAAO,CAAC,MAAOC,GAAKrB,EAAK,eAAgBqB,EAAG,GAAQ,EAG5F,MAAMN,EACT,WAAAN,GAAgBC,KAAKY,UAAY,IAAIC,OAAY,CACjDC,qBAAuB,KAEvB,OAAAC,CAAQC,EAAQC,GACZ,IAAIC,EAAUlB,KAAKY,UAAUO,IAAIH,GAGjC,OAFKE,GAASlB,KAAKY,UAAUQ,IAAIJ,EAAQE,EAAU,IAAIG,KAClDH,EAAQI,IAAIL,IAAMC,EAAQE,IAAIH,EAAK,IAAInB,GACrCoB,EAAQC,IAAIF,EACtB,CAED,QAAAM,CAASC,GACL,IAAKA,GAAsB,iBAARA,GAAoBA,EAAIC,aAAc,OAAOD,EAChE,MAAME,EAAO1B,KACb,OAAO,IAAI2B,MAAMH,EAAK,CAClB,GAAAL,CAAIH,EAAQC,EAAKW,GACb,GAAY,iBAARX,EAAwB,OAAO,EACnC,MAAMY,EAAMC,QAAQX,IAAIH,EA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G,GAAK,IAAI2F,EAAI3F,GACxByG,gBAAiBzG,GAAK,IAAImB,EAAUnB,GACpC0G,YAAa7J,GAAK,IAAIjC,EAAMiC,GAC5B8J,UAAW3G,GAAK,IAAImC,EAAInC,KAGN,oBAAXyF,SAAwBA,OAAOjO,GAAKA"}
package/dist/zi.js ADDED
@@ -0,0 +1,2 @@
1
+ const t=t=>"function"==typeof t,e=()=>{};function n(...t){"undefined"!=typeof globalThis&&globalThis.Zi?.config?.debug&&console.warn("[Zi]",...t)}var s=Object.freeze({__proto__:null,_isObject:t=>null!==t&&"object"==typeof t,_isFn:t,_noop:e,warn:n,log:function(...t){"undefined"!=typeof globalThis&&globalThis.Zi?.config?.debug&&console.log("[Zi]",...t)}});class o{constructor(){this.subs=new Set}depend(){const t=r.currentEffect;t&&this.subs.add(t)}notify(){this.subs.forEach(t=>{try{t()}catch(t){n("Effect error",t)}})}}class r{constructor(){this.targetMap=new WeakMap}static currentEffect=null;_depFor(t,e){let n=this.targetMap.get(t);return n||this.targetMap.set(t,n=new Map),n.has(e)||n.set(e,new o),n.get(e)}reactive(t){if(!t||"object"!=typeof t||t.__isReactive)return t;const e=this;return new Proxy(t,{get(t,n,s){if("__isReactive"===n)return!0;const o=Reflect.get(t,n,s);return e._depFor(t,n).depend(),o&&"object"==typeof o?e.reactive(o):o},set(t,n,s,o){const r=t[n],i=Reflect.set(t,n,s,o);return r!==s&&e._depFor(t,n).notify(),i},deleteProperty(t,n){const s=Reflect.deleteProperty(t,n);return e._depFor(t,n).notify(),s}})}effect(t,{lazy:e=!1}={}){const n=()=>{r.currentEffect=n;try{return t()}finally{r.currentEffect=null}};return e||n(),n}computed(t){let e,n=!0;const s=this.effect(()=>{e=t(),n=!1},{lazy:!0});return{get value(){if(n){r.currentEffect=s;try{e=t()}finally{r.currentEffect=null}n=!1}return e}}}watch(t,e){let n;return this.effect(()=>{const s=t();e(s,n),n=s})}}const i=new r;class c{constructor(t={}){this.state=i.reactive(t),this._modules={}}registerModule(t,e){if(this._modules[t])throw new Error(`Module ${t} exists`);const n=i.reactive(e);return this._modules[t]=n,this.state[t]=n,n}patch(t){t(this.state)}getModule(t){return this._modules[t]}}function a(t,e={}){try{const n=t.trim();if(/^[\w.$\[\]]+$/.test(n))return n.split(".").reduce((t,e)=>null==t?void 0:t[e.trim()],e);const s=new Proxy(e,{get:(t,e)=>e in t?t[e]:void 0,has:()=>!0});return Function("scoped","with(scoped){return ("+t+");}")(s)}catch(e){return void n("Eval error",t,e)}}function h(t,e,n){const s=e&&e.state||{},o=e&&e.props||{};return a(t,Object.assign({},s,o,n||{}))}function u(t,e,s){try{const n=e.state||{},o=t.split(".");let r=n;for(let t=0;t<o.length-1;t++){const e=o[t].trim();e in r||(r[e]={}),r=r[e]}r[o[o.length-1].trim()]=s}catch(e){n("Assign error",t,e)}}function l(t){const e=document.createElement("template");return e.innerHTML=t.trim(),e.content}function p(t){const e=[],n=t=>{e.push(t),t.childNodes&&t.childNodes.forEach(t=>n(t))};return t.childNodes.forEach(t=>n(t)),e}const d={"z-if":(t,e,n,s)=>{i.effect(()=>{const o=!!h(e,n,s);t.__zi_hidden=!o,t.style.display=o?"":"none"})},"z-show":(t,e,n,s)=>{i.effect(()=>{t.style.display=h(e,n,s)?"":"none"})},"z-text":(t,e,n,s)=>{i.effect(()=>{t.textContent=h(e,n,s)||""})},"z-html":(t,e,n,s)=>{i.effect(()=>{t.innerHTML=h(e,n,s)||""})},"z-model":(t,e,n)=>{i.effect(()=>{const s=h(e,n);"checkbox"===t.type?t.checked=!!s:t.value!==s&&(t.value=s||"")});const s=s=>{"checkbox"===t.type?u(e,n,t.checked):u(e,n,t.value)};t.addEventListener("input",s),t.addEventListener("change",s)},"z-for":(t,e,s)=>{const o=t.parentNode,r=document.createComment("z-for");o.replaceChild(r,t);const c=e.match(/^(?:\(([^)]+)\)|([^\s]+))\s+in\s+(.+)$/);if(!c)return n("Invalid z-for",e);const a=(c[1]||c[2]).split(",").map(t=>t.trim()),u=c[3].trim(),l={};i.effect(()=>{(h(u,s)||[]).forEach((e,n)=>{const i=e&&e.id||n;let c=l[i];if(!c){c=t.cloneNode(!0),l[i]=c;const h=Object.assign({},s.getContext(),{[a[0]]:e,[a[1]||"$index"]:n});f(c,s,h),o.insertBefore(c,r.nextSibling)}})})}};function f(e,s,o){if(3===e.nodeType){const t=e.nodeValue;return void(/{{/.test(t)&&i.effect(()=>{e.nodeValue=function(t,e={}){return t.replace(/{{\s*([^}]+)\s*}}/g,(t,s)=>{try{const t=a(s,e);return null==t?"":String(t)}catch(t){return n("Mustache eval",s,t),""}})}(t,o?Object.assign({},s.getContext(),o):s.getContext())}))}1===e.nodeType&&(Array.from(e.attributes||[]).forEach(r=>{if(r.name.startsWith("@")){const i=r.name.slice(1),c=r.value.trim();e.addEventListener(i,e=>{const r=s.methods&&s.methods[c];if(t(r))return r.call(s,e,s);try{Function("event","state","props","ctx","with(state){with(props){with(ctx||{}){"+c+"}}}")(e,s.state,s.props,o||{})}catch(t){n("Inline handler",c,t)}})}}),Array.from(e.attributes||[]).forEach(t=>{if(t.name.startsWith("z-")){const r=s._dirRegistry[t.name]||d[t.name];if(r)try{r(e,t.value,s,o)}catch(e){n("Directive",t.name,e)}else n("Unknown directive",t.name)}}),e.__zi_hidden||Array.from(e.childNodes).forEach(t=>f(t,s,o)))}class m{constructor({template:t="",state:n={},props:s={},methods:o={},onInit:r=e,onMount:c=e,onDestroy:a=e,directives:h={}}={}){this.template=t,this.state=i.reactive(n),this.props=s,this.methods=o,this.onInit=r,this.onMount=c,this.onDestroy=a,this.directives=h,this._dirRegistry=Object.assign({},h),this.el=null,this.mounted=!1}getContext(){return Object.assign({},this.state,this.props)}_resolveTemplate(){if(!this.template)return"";if("string"==typeof this.template&&this.template.startsWith("#")){const t=document.querySelector(this.template);if(!t)throw new Error("Template selector not found: "+this.template);return t.innerHTML}return"string"==typeof this.template?this.template:this.template instanceof HTMLElement?this.template.innerHTML:""}mount(t){this.onInit();const e="string"==typeof t?document.querySelector(t):t;if(!e)throw new Error("Mount not found");this.el=e,this._render(),this.mounted=!0,this.onMount()}unmount(){this.onDestroy(),this.el&&(this.el.innerHTML=""),this.mounted=!1}_render(){const t=l(this._resolveTemplate());p(t).forEach(t=>f(t,this)),this.el.innerHTML="",this.el.appendChild(t)}}class g{constructor({base:t="",headers:e={},fetchImpl:n=fetch}={}){this.base=t.replace(/\/$/,""),this.headers={...e},this.fetch=n}_url(t){return t.startsWith("http")?t:`${this.base}/${t.replace(/^\//,"")}`}async request(t,e,{params:n,body:s,headers:o}={}){const r=this._url(e)+(n?"?"+new URLSearchParams(n):""),i={method:t,headers:{...this.headers,...o||{}}};s&&((i.headers["Content-Type"]||"").includes("application/json")?i.body=JSON.stringify(s):i.body=s);const c=await this.fetch(r,i);if(!c.ok)throw new Error(`HTTP ${c.status}: ${c.statusText}`);return(c.headers.get("content-type")||"").includes("application/json")?c.json():c.text()}get(t,e){return this.request("GET",t,e)}post(t,e){return this.request("POST",t,e)}put(t,e){return this.request("PUT",t,e)}del(t,e){return this.request("DELETE",t,e)}}class y{constructor(t=[],{mode:e="hash",root:n=document.body,notFound:s=null}={}){this.routes=t,this.mode=e,this.root=n,this.current=null,this._cached=[],this._notFound=s,this._onHashChange=this._onHashChange.bind(this),this._compileRoutes()}_compileRoutes(){this._cached=this.routes.map(t=>{const e=[],n=new RegExp("^"+t.path.replace(/:([\w_]+)/g,(t,n)=>(e.push(n),"([^/]+)"))+"$");return{route:t,rx:n,keys:e}})}_match(t){for(const e of this._cached){const n=t.match(e.rx);if(n){const t={};return e.keys.forEach((e,s)=>t[e]=n[s+1]),{route:e.route,params:t}}}return null}_onHashChange(){const t=location.hash.replace(/^#/,"")||"/",e=this._match(t);this._renderRoute(e,t)}_mountComponent(t,e){this.current&&this.current.unmount&&this.current.unmount();const n=this.root;if("function"==typeof t){const s=t({params:e,router:this});s instanceof m?(s.props=Object.assign({},s.props,{$routeParams:e}),s.mount(n),this.current=s):"string"==typeof s?(n.innerHTML=s,this.current={unmount(){n.innerHTML=""}}):s instanceof HTMLElement&&(n.innerHTML="",n.appendChild(s),this.current={unmount(){n.innerHTML=""}})}else t instanceof m?(t.props=Object.assign({},t.props,{$routeParams:e}),t.mount(n),this.current=t):"string"==typeof t&&(n.innerHTML=t,this.current={unmount(){n.innerHTML=""}})}_renderRoute(t,e){if(!t){if(this._notFound){const t=this._notFound();this._mountComponent(t,{})}else n("Route not found",e);return}const{route:s,params:o}=t,r="function"==typeof s.component?s.component({params:o,router:this}):s.component;this._mountComponent(r,o)}init(t){this.root="string"==typeof t?document.querySelector(t):t||document.body,window.addEventListener("hashchange",this._onHashChange),this._onHashChange()}navigate(t){location.hash=t}}class _{constructor({root:t="#app",store:e=null,api:n=null}={}){if(this.root="string"==typeof t?document.querySelector(t):t,!this.root)throw new Error("Root not found");this.store=e||new c({}),this.api=n||new g({}),this.router=null,this.plugins=[]}use(e,n){t(e)?(e({app:this,store:this.store,api:this.api}),this.plugins.push(e)):e&&e.install&&(e.install(this,n),this.plugins.push(e))}mountComponent(t){if(!(t instanceof m))throw new Error("mountComponent expects Component");t.mount(this.root)}useRouter(t){this.router=t}}const w={Reactive:i,Store:c,Component:m,API:g,Router:y,App:_,Directives:d,createFragmentFromHTML:l,processNode:f,flattenNodes:p,...s},b=Object.assign({config:{debug:!0}},w,{createApp:t=>new _(t),createComponent:t=>new m(t),createStore:t=>new c(t),createAPI:t=>new g(t)});"undefined"!=typeof window&&(window.Zi=b);export{g as API,_ as App,m as Component,d as Directives,i as Reactive,y as Router,c as Store,l as createFragmentFromHTML,b as default,p as flattenNodes,f as processNode};
2
+ //# sourceMappingURL=zi.js.map
package/dist/zi.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"file":"zi.js","sources":["../src/utils.js","../src/reactive.js","../src/store.js","../src/eval.js","../src/dom.js","../src/component.js","../src/api.js","../src/router.js","../src/app.js","../src/index.js"],"sourcesContent":["// src/utils.js\r\nexport const _isObject = v => v !== null && typeof v === 'object';\r\nexport const _isFn = v => typeof v === 'function';\r\nexport const _noop = () => { };\r\n\r\nexport function warn(...args) {\r\n if (typeof globalThis !== 'undefined' && globalThis.Zi?.config?.debug) {\r\n console.warn('[Zi]', ...args);\r\n }\r\n}\r\nexport function log(...args) {\r\n if (typeof globalThis !== 'undefined' && globalThis.Zi?.config?.debug) {\r\n console.log('[Zi]', ...args);\r\n }\r\n}\r\n","// src/reactive.js\r\nimport { warn } from './utils.js';\r\n\r\nexport class Dep {\r\n constructor() { this.subs = new Set(); }\r\n depend() { const eff = ReactiveSystem.currentEffect; if (eff) this.subs.add(eff); }\r\n notify() { this.subs.forEach(fn => { try { fn(); } catch (e) { warn('Effect error', e); } }); }\r\n}\r\n\r\nexport class ReactiveSystem {\r\n constructor() { this.targetMap = new WeakMap(); }\r\n static currentEffect = null;\r\n\r\n _depFor(target, key) {\r\n let depsMap = this.targetMap.get(target);\r\n if (!depsMap) this.targetMap.set(target, depsMap = new Map());\r\n if (!depsMap.has(key)) depsMap.set(key, new Dep());\r\n return depsMap.get(key);\r\n }\r\n\r\n reactive(obj) {\r\n if (!obj || typeof obj !== 'object' || obj.__isReactive) return obj;\r\n const self = this;\r\n return new Proxy(obj, {\r\n get(target, key, receiver) {\r\n if (key === '__isReactive') return true;\r\n const res = Reflect.get(target, key, receiver);\r\n self._depFor(target, key).depend();\r\n return (res && typeof res === 'object') ? self.reactive(res) : res;\r\n },\r\n set(target, key, val, receiver) {\r\n const old = target[key];\r\n const res = Reflect.set(target, key, val, receiver);\r\n if (old !== val) self._depFor(target, key).notify();\r\n return res;\r\n },\r\n deleteProperty(target, key) {\r\n const res = Reflect.deleteProperty(target, key);\r\n self._depFor(target, key).notify();\r\n return res;\r\n }\r\n });\r\n }\r\n\r\n effect(fn, { lazy = false } = {}) {\r\n const runner = () => { ReactiveSystem.currentEffect = runner; try { return fn(); } finally { ReactiveSystem.currentEffect = null; } };\r\n if (!lazy) runner();\r\n return runner;\r\n }\r\n\r\n computed(getter) {\r\n let cache, dirty = true;\r\n const runner = this.effect(() => { cache = getter(); dirty = false; }, { lazy: true });\r\n return {\r\n get value() {\r\n if (dirty) {\r\n ReactiveSystem.currentEffect = runner;\r\n try { cache = getter(); } finally { ReactiveSystem.currentEffect = null; }\r\n dirty = false;\r\n }\r\n return cache;\r\n }\r\n };\r\n }\r\n\r\n watch(getter, cb) {\r\n let old;\r\n return this.effect(() => { const val = getter(); cb(val, old); old = val; });\r\n }\r\n}\r\n\r\nexport const Reactive = new ReactiveSystem();\r\n","// src/store.js\r\nimport { Reactive } from './reactive.js';\r\n\r\nexport class Store {\r\n constructor(initial = {}) {\r\n this.state = Reactive.reactive(initial);\r\n this._modules = {};\r\n }\r\n\r\n registerModule(name, stateObj) {\r\n if (this._modules[name]) throw new Error(`Module ${name} exists`);\r\n const mod = Reactive.reactive(stateObj);\r\n this._modules[name] = mod;\r\n this.state[name] = mod;\r\n return mod;\r\n }\r\n\r\n patch(fn) { fn(this.state); }\r\n\r\n getModule(name) { return this._modules[name]; }\r\n}\r\n","// src/eval.js\r\nimport { warn } from './utils.js';\r\n\r\n/**\r\n * Evaluate expression in a given scope object.\r\n *\r\n * scope is plain object of variables.\r\n */\r\nexport function evaluateInScope(expr, scope = {}) {\r\n try {\r\n const trimmed = expr.trim();\r\n if (/^[\\w.$\\[\\]]+$/.test(trimmed)) {\r\n return trimmed.split('.').reduce((a, k) => (a == null ? undefined : a[k.trim()]), scope);\r\n }\r\n const proxy = new Proxy(scope, { get(t, k) { return k in t ? t[k] : undefined; }, has() { return true; } });\r\n return Function('scoped', 'with(scoped){return (' + expr + ');}')(proxy);\r\n } catch (e) {\r\n warn('Eval error', expr, e);\r\n return undefined;\r\n }\r\n}\r\n\r\n/**\r\n * Evaluate expression in context of component (cmp)\r\n * cmp expected to have state and props.\r\n */\r\nexport function evaluateExpr(expr, cmp, ctx) {\r\n const state = (cmp && cmp.state) || {};\r\n const props = (cmp && cmp.props) || {};\r\n const scoped = Object.assign({}, state, props, ctx || {});\r\n return evaluateInScope(expr, scoped);\r\n}\r\n\r\n/**\r\n * Assign to dot-path inside component.state\r\n */\r\nexport function assignExpr(expr, cmp, value) {\r\n try {\r\n const state = cmp.state || {};\r\n const parts = expr.split('.');\r\n let target = state;\r\n for (let i = 0; i < parts.length - 1; i++) {\r\n const k = parts[i].trim();\r\n if (!(k in target)) target[k] = {};\r\n target = target[k];\r\n }\r\n target[parts[parts.length - 1].trim()] = value;\r\n } catch (e) {\r\n warn('Assign error', expr, e);\r\n }\r\n}\r\n\r\n/**\r\n * Simple mustache parser that uses evaluateInScope for expressions\r\n */\r\nexport function parseMustache(template, scope = {}) {\r\n return template.replace(/{{\\s*([^}]+)\\s*}}/g, (_, expr) => {\r\n try {\r\n const val = evaluateInScope(expr, scope);\r\n return val == null ? '' : String(val);\r\n } catch (e) {\r\n warn('Mustache eval', expr, e);\r\n return '';\r\n }\r\n });\r\n}\r\n","// src/dom.js\r\nimport { evaluateExpr, assignExpr, parseMustache } from './eval.js';\r\nimport { Reactive } from './reactive.js';\r\nimport { warn, _isFn } from './utils.js';\r\n\r\n/** DOM helpers */\r\nexport function createFragmentFromHTML(html) {\r\n const template = document.createElement('template');\r\n template.innerHTML = html.trim();\r\n return template.content;\r\n}\r\n\r\nexport function flattenNodes(root) {\r\n const out = [];\r\n const walk = node => {\r\n out.push(node);\r\n node.childNodes && node.childNodes.forEach(child => walk(child));\r\n };\r\n root.childNodes.forEach(n => walk(n));\r\n return out;\r\n}\r\n\r\n/** Directives object (z-if, z-show, z-text, etc.) */\r\nexport const Directives = {\r\n 'z-if': (el, expr, cmp, ctx) => {\r\n const apply = () => {\r\n const val = !!evaluateExpr(expr, cmp, ctx);\r\n el.__zi_hidden = !val;\r\n el.style.display = val ? '' : 'none';\r\n };\r\n Reactive.effect(apply);\r\n },\r\n 'z-show': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.style.display = evaluateExpr(expr, cmp, ctx) ? '' : 'none';\r\n });\r\n },\r\n 'z-text': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.textContent = (evaluateExpr(expr, cmp, ctx) || '');\r\n });\r\n },\r\n 'z-html': (el, expr, cmp, ctx) => {\r\n Reactive.effect(() => {\r\n el.innerHTML = (evaluateExpr(expr, cmp, ctx) || '');\r\n });\r\n },\r\n 'z-model': (el, expr, cmp) => {\r\n const setEl = () => {\r\n const v = evaluateExpr(expr, cmp);\r\n if (el.type === 'checkbox') el.checked = !!v;\r\n else if (el.value !== v) el.value = v || '';\r\n };\r\n Reactive.effect(setEl);\r\n const handler = e => {\r\n if (el.type === 'checkbox') assignExpr(expr, cmp, el.checked);\r\n else assignExpr(expr, cmp, el.value);\r\n };\r\n el.addEventListener('input', handler);\r\n el.addEventListener('change', handler);\r\n },\r\n 'z-for': (el, expr, cmp) => {\r\n const parent = el.parentNode;\r\n const marker = document.createComment('z-for');\r\n parent.replaceChild(marker, el);\r\n const m = expr.match(/^(?:\\(([^)]+)\\)|([^\\s]+))\\s+in\\s+(.+)$/);\r\n if (!m) return warn('Invalid z-for', expr);\r\n const aliases = (m[1] || m[2]).split(',').map(s => s.trim());\r\n const sourceExpr = m[3].trim();\r\n const keyed = {};\r\n const render = () => {\r\n const list = evaluateExpr(sourceExpr, cmp) || [];\r\n // naive keyed reuse\r\n list.forEach((item, idx) => {\r\n const key = (item && item.id) || idx;\r\n let clone = keyed[key];\r\n if (!clone) {\r\n clone = el.cloneNode(true);\r\n keyed[key] = clone;\r\n const local = Object.assign({}, cmp.getContext(), { [aliases[0]]: item, [aliases[1] || '$index']: idx });\r\n processNode(clone, cmp, local);\r\n parent.insertBefore(clone, marker.nextSibling);\r\n }\r\n });\r\n };\r\n Reactive.effect(render);\r\n }\r\n};\r\n\r\n/**\r\n * processNode: walk a node fragment and attach directives & event handlers\r\n *\r\n * node - DOM node\r\n *\r\n * cmp - Component instance\r\n *\r\n * ctx - optional local context (for z-for items)\r\n */\r\nexport function processNode(node, cmp, ctx) {\r\n if (node.nodeType === 3) {\r\n const o = node.nodeValue;\r\n if (/{{/.test(o)) {\r\n Reactive.effect(() => {\r\n node.nodeValue = parseMustache(o, ctx ? Object.assign({}, cmp.getContext(), ctx) : cmp.getContext());\r\n });\r\n }\r\n return;\r\n }\r\n if (node.nodeType !== 1) return;\r\n\r\n Array.from(node.attributes || []).forEach(attr => {\r\n if (attr.name.startsWith('@')) {\r\n const evt = attr.name.slice(1);\r\n const h = attr.value.trim();\r\n node.addEventListener(evt, e => {\r\n const m = cmp.methods && cmp.methods[h];\r\n if (_isFn(m)) return m.call(cmp, e, cmp);\r\n try {\r\n Function('event', 'state', 'props', 'ctx', 'with(state){with(props){with(ctx||{}){' + h + '}}}')(e, cmp.state, cmp.props, ctx || {});\r\n } catch (err) {\r\n warn('Inline handler', h, err);\r\n }\r\n });\r\n }\r\n });\r\n\r\n Array.from(node.attributes || []).forEach(attr => {\r\n if (attr.name.startsWith('z-')) {\r\n const h = cmp._dirRegistry[attr.name] || Directives[attr.name];\r\n if (h) {\r\n try { h(node, attr.value, cmp, ctx); } catch (e) { warn('Directive', attr.name, e); }\r\n } else warn('Unknown directive', attr.name);\r\n }\r\n });\r\n\r\n if (node.__zi_hidden) return;\r\n Array.from(node.childNodes).forEach(c => processNode(c, cmp, ctx));\r\n}\r\n","// src/component.js\r\nimport { Reactive } from './reactive.js';\r\nimport { createFragmentFromHTML, flattenNodes, processNode } from './dom.js';\r\nimport { _noop } from './utils.js';\r\n\r\nexport class Component {\r\n constructor({ template = '', state = {}, props = {}, methods = {}, onInit = _noop, onMount = _noop, onDestroy = _noop, directives = {} } = {}) {\r\n this.template = template;\r\n this.state = Reactive.reactive(state);\r\n this.props = props;\r\n this.methods = methods;\r\n this.onInit = onInit;\r\n this.onMount = onMount;\r\n this.onDestroy = onDestroy;\r\n this.directives = directives;\r\n this._dirRegistry = Object.assign({}, directives); // will be merged by indexing code\r\n this.el = null;\r\n this.mounted = false;\r\n }\r\n\r\n getContext() { return Object.assign({}, this.state, this.props); }\r\n\r\n _resolveTemplate() {\r\n if (!this.template) return '';\r\n if (typeof this.template === 'string' && this.template.startsWith('#')) {\r\n const el = document.querySelector(this.template);\r\n if (!el) throw new Error('Template selector not found: ' + this.template);\r\n return el.innerHTML;\r\n }\r\n if (typeof this.template === 'string') return this.template;\r\n if (this.template instanceof HTMLElement) return this.template.innerHTML;\r\n return '';\r\n }\r\n\r\n mount(sel) {\r\n this.onInit();\r\n const mountEl = (typeof sel === 'string') ? document.querySelector(sel) : sel;\r\n if (!mountEl) throw new Error('Mount not found');\r\n this.el = mountEl;\r\n this._render();\r\n this.mounted = true;\r\n this.onMount();\r\n }\r\n\r\n unmount() {\r\n this.onDestroy();\r\n if (this.el) this.el.innerHTML = '';\r\n this.mounted = false;\r\n }\r\n\r\n _render() {\r\n const raw = this._resolveTemplate();\r\n const frag = createFragmentFromHTML(raw);\r\n // allow directives registry (local override) to be considered in processNode; for simplicity assume processNode uses cmp._dirRegistry\r\n flattenNodes(frag).forEach(n => processNode(n, this));\r\n this.el.innerHTML = '';\r\n this.el.appendChild(frag);\r\n }\r\n}\r\n","// src/api.js\r\nexport class API {\r\n constructor({ base = '', headers = {}, fetchImpl = fetch } = {}) {\r\n this.base = base.replace(/\\/$/, '');\r\n this.headers = { ...headers };\r\n this.fetch = fetchImpl;\r\n }\r\n\r\n _url(path) { return path.startsWith('http') ? path : `${this.base}/${path.replace(/^\\//, '')}`; }\r\n\r\n async request(method, path, { params, body, headers } = {}) {\r\n const url = this._url(path) + (params ? '?' + new URLSearchParams(params) : '');\r\n const opts = { method, headers: { ...this.headers, ...(headers || {}) } };\r\n if (body) {\r\n if ((opts.headers['Content-Type'] || '').includes('application/json')) opts.body = JSON.stringify(body);\r\n else opts.body = body;\r\n }\r\n const res = await this.fetch(url, opts);\r\n if (!res.ok) throw new Error(`HTTP ${res.status}: ${res.statusText}`);\r\n const ct = res.headers.get('content-type') || '';\r\n return ct.includes('application/json') ? res.json() : res.text();\r\n }\r\n\r\n get(p, o) { return this.request('GET', p, o); }\r\n post(p, o) { return this.request('POST', p, o); }\r\n put(p, o) { return this.request('PUT', p, o); }\r\n del(p, o) { return this.request('DELETE', p, o); }\r\n}\r\n","// src/router.js\r\nimport { warn } from './utils.js';\r\nimport { Component } from './component.js';\r\n\r\nexport class Router {\r\n constructor(routes = [], { mode = 'hash', root = document.body, notFound = null } = {}) {\r\n this.routes = routes;\r\n this.mode = mode;\r\n this.root = root;\r\n this.current = null;\r\n this._cached = [];\r\n this._notFound = notFound;\r\n this._onHashChange = this._onHashChange.bind(this);\r\n this._compileRoutes();\r\n }\r\n\r\n _compileRoutes() {\r\n this._cached = this.routes.map(r => {\r\n const keys = [];\r\n const rx = new RegExp('^' + r.path.replace(/:([\\w_]+)/g, (_, k) => { keys.push(k); return '([^/]+)'; }) + '$');\r\n return { route: r, rx, keys };\r\n });\r\n }\r\n\r\n _match(path) {\r\n for (const e of this._cached) {\r\n const m = path.match(e.rx);\r\n if (m) {\r\n const p = {};\r\n e.keys.forEach((k, i) => p[k] = m[i + 1]);\r\n return { route: e.route, params: p };\r\n }\r\n }\r\n return null;\r\n }\r\n\r\n _onHashChange() {\r\n const hash = location.hash.replace(/^#/, '') || '/';\r\n const matched = this._match(hash);\r\n this._renderRoute(matched, hash);\r\n }\r\n\r\n _mountComponent(comp, params) {\r\n if (this.current && this.current.unmount) this.current.unmount();\r\n const mp = this.root;\r\n if (typeof comp === 'function') {\r\n const inst = comp({ params, router: this });\r\n if (inst instanceof Component) {\r\n inst.props = Object.assign({}, inst.props, { $routeParams: params });\r\n inst.mount(mp);\r\n this.current = inst;\r\n } else if (typeof inst === 'string') {\r\n mp.innerHTML = inst;\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n } else if (inst instanceof HTMLElement) {\r\n mp.innerHTML = '';\r\n mp.appendChild(inst);\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n }\r\n } else if (comp instanceof Component) {\r\n comp.props = Object.assign({}, comp.props, { $routeParams: params });\r\n comp.mount(mp);\r\n this.current = comp;\r\n } else if (typeof comp === 'string') {\r\n mp.innerHTML = comp;\r\n this.current = { unmount() { mp.innerHTML = ''; } };\r\n }\r\n }\r\n\r\n _renderRoute(matched, path) {\r\n if (!matched) {\r\n if (this._notFound) {\r\n const c = this._notFound();\r\n this._mountComponent(c, {});\r\n } else warn('Route not found', path);\r\n return;\r\n }\r\n const { route, params } = matched;\r\n const comp = (typeof route.component === 'function' ? route.component({ params, router: this }) : route.component);\r\n this._mountComponent(comp, params);\r\n }\r\n\r\n init(sel) {\r\n this.root = typeof sel === 'string' ? document.querySelector(sel) : (sel || document.body);\r\n window.addEventListener('hashchange', this._onHashChange);\r\n this._onHashChange();\r\n }\r\n\r\n navigate(path) { location.hash = path; }\r\n}\r\n","// src/app.js\r\nimport { Store } from './store.js';\r\nimport { API } from './api.js';\r\nimport { Router } from './router.js';\r\nimport { Component } from './component.js';\r\nimport { _isFn } from './utils.js';\r\n\r\nexport class App {\r\n constructor({ root = '#app', store = null, api = null } = {}) {\r\n this.root = (typeof root === 'string') ? document.querySelector(root) : root;\r\n if (!this.root) throw new Error('Root not found');\r\n this.store = store || new Store({});\r\n this.api = api || new API({});\r\n this.router = null;\r\n this.plugins = [];\r\n }\r\n\r\n use(plugin, options) {\r\n if (_isFn(plugin)) {\r\n plugin({ app: this, store: this.store, api: this.api });\r\n this.plugins.push(plugin);\r\n } else if (plugin && plugin.install) {\r\n plugin.install(this, options);\r\n this.plugins.push(plugin);\r\n }\r\n }\r\n\r\n mountComponent(c) {\r\n if (!(c instanceof Component)) throw new Error('mountComponent expects Component');\r\n c.mount(this.root);\r\n }\r\n\r\n useRouter(r) { this.router = r; }\r\n}\r\n","// src/index.js\r\nimport { Reactive } from './reactive.js';\r\nimport { Store } from './store.js';\r\nimport { Component } from './component.js';\r\nimport { API } from './api.js';\r\nimport { Router } from './router.js';\r\nimport { App } from './app.js';\r\nimport { Directives, createFragmentFromHTML, processNode, flattenNodes } from './dom.js';\r\nimport * as utils from './utils.js';\r\n\r\nconst ZiFramework = { Reactive, Store, Component, API, Router, App, Directives, createFragmentFromHTML, processNode, flattenNodes, ...utils };\r\nconst Zi = Object.assign({ config: { debug: true } }, ZiFramework, {\r\n createApp: o => new App(o),\r\n createComponent: o => new Component(o),\r\n createStore: i => new Store(i),\r\n createAPI: o => new API(o)\r\n});\r\n\r\nif (typeof window !== 'undefined') window.Zi = Zi;\r\n\r\nexport {\r\n Reactive, Store, Component, API, Router, App, Directives,\r\n createFragmentFromHTML, processNode, flattenNodes,\r\n Zi as default\r\n};\r\n"],"names":["_isFn","v","_noop","warn","args","globalThis","Zi","config","debug","console","log","Dep","constructor","this","subs","Set","depend","eff","ReactiveSystem","currentEffect","add","notify","forEach","fn","e","targetMap","WeakMap","static","_depFor","target","key","depsMap","get","set","Map","has","reactive","obj","__isReactive","self","Proxy","receiver","res","Reflect","val","old","deleteProperty","effect","lazy","runner","computed","getter","cache","dirty","value","watch","cb","Reactive","Store","initial","state","_modules","registerModule","name","stateObj","Error","mod","patch","getModule","evaluateInScope","expr","scope","trimmed","trim","test","split","reduce","a","k","undefined","proxy","t","Function","evaluateExpr","cmp","ctx","props","Object","assign","assignExpr","parts","i","length","createFragmentFromHTML","html","template","document","createElement","innerHTML","content","flattenNodes","root","out","walk","node","push","childNodes","child","n","Directives","el","__zi_hidden","style","display","textContent","type","checked","handler","addEventListener","parent","parentNode","marker","createComment","replaceChild","m","match","aliases","map","s","sourceExpr","keyed","item","idx","id","clone","cloneNode","local","getContext","processNode","insertBefore","nextSibling","nodeType","o","nodeValue","replace","_","String","parseMustache","Array","from","attributes","attr","startsWith","evt","slice","h","methods","call","err","_dirRegistry","c","Component","onInit","onMount","onDestroy","directives","mounted","_resolveTemplate","querySelector","HTMLElement","mount","sel","mountEl","_render","unmount","frag","appendChild","API","base","headers","fetchImpl","fetch","_url","path","request","method","params","body","url","URLSearchParams","opts","includes","JSON","stringify","ok","status","statusText","json","text","p","post","put","del","Router","routes","mode","notFound","current","_cached","_notFound","_onHashChange","bind","_compileRoutes","r","keys","rx","RegExp","route","_match","hash","location","matched","_renderRoute","_mountComponent","comp","mp","inst","router","$routeParams","component","init","window","navigate","App","store","api","plugins","use","plugin","options","app","install","mountComponent","useRouter","ZiFramework","utils","createApp","createComponent","createStore","createAPI"],"mappings":"AACO,MACMA,EAAQC,GAAkB,mBAANA,EACpBC,EAAQ,OAEd,SAASC,KAAQC,GACM,oBAAfC,YAA8BA,WAAWC,IAAIC,QAAQC,OAC5DC,QAAQN,KAAK,UAAWC,EAEhC,+CARyBH,GAAW,OAANA,GAA2B,iBAANA,6BAS5C,YAAgBG,GACO,oBAAfC,YAA8BA,WAAWC,IAAIC,QAAQC,OAC5DC,QAAQC,IAAI,UAAWN,EAE/B,ICXO,MAAMO,EACT,WAAAC,GAAgBC,KAAKC,KAAO,IAAIC,GAAQ,CACxC,MAAAC,GAAW,MAAMC,EAAMC,EAAeC,cAAmBF,GAAKJ,KAAKC,KAAKM,IAAIH,EAAO,CACnF,MAAAI,GAAWR,KAAKC,KAAKQ,QAAQC,IAAQ,IAAMA,GAAO,CAAC,MAAOC,GAAKrB,EAAK,eAAgBqB,EAAG,GAAQ,EAG5F,MAAMN,EACT,WAAAN,GAAgBC,KAAKY,UAAY,IAAIC,OAAY,CACjDC,qBAAuB,KAEvB,OAAAC,CAAQC,EAAQC,GACZ,IAAIC,EAAUlB,KAAKY,UAAUO,IAAIH,GAGjC,OAFKE,GAASlB,KAAKY,UAAUQ,IAAIJ,EAAQE,EAAU,IAAIG,KAClDH,EAAQI,IAAIL,IAAMC,EAAQE,IAAIH,EAAK,IAAInB,GACrCoB,EAAQC,IAAIF,EACtB,CAED,QAAAM,CAASC,GACL,IAAKA,GAAsB,iBAARA,GAAoBA,EAAIC,aAAc,OAAOD,EAChE,MAAME,EAAO1B,KACb,OAAO,IAAI2B,MAAMH,EAAK,CAClB,GAAAL,CAAIH,EAAQC,EAAKW,GACb,GAAY,iBAARX,EAAwB,OAAO,EACnC,MAAMY,EAAMC,QAAQX,IAAIH,EAA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,GAAK,IAAI2F,EAAI3F,GACxByG,gBAAiBzG,GAAK,IAAImB,EAAUnB,GACpC0G,YAAa7J,GAAK,IAAIjC,EAAMiC,GAC5B8J,UAAW3G,GAAK,IAAImC,EAAInC,KAGN,oBAAXyF,SAAwBA,OAAOjO,GAAKA"}
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@rexllins/zi",
3
+ "version": "0.0.2",
4
+ "description": "Reactive frontend framework",
5
+ "main": "dist/zi.cjs.js",
6
+ "module": "dist/zi.js",
7
+ "type": "module",
8
+ "engines": {
9
+ "node": ">=18"
10
+ },
11
+ "types": "types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/zi.js",
15
+ "require": "./dist/zi.cjs.js",
16
+ "types": "./types/index.d.ts"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist",
21
+ "types"
22
+ ],
23
+ "bin": {
24
+ "zi": "./bin/zi.js"
25
+ },
26
+ "scripts": {
27
+ "build": "rollup -c",
28
+ "build:watch": "rollup -c -w"
29
+ },
30
+ "keywords": [
31
+ "framework",
32
+ "reactive",
33
+ "frontend",
34
+ "javascript"
35
+ ],
36
+ "author": "Rexllins",
37
+ "license": "MIT",
38
+ "devDependencies": {
39
+ "@rollup/plugin-commonjs": "^29.0.0",
40
+ "@rollup/plugin-node-resolve": "^16.0.3",
41
+ "@rollup/plugin-terser": "^0.4.4",
42
+ "rollup": "^2.79.2",
43
+ "rollup-plugin-terser": "^7.0.2"
44
+ }
45
+ }
@@ -0,0 +1,169 @@
1
+ // types/index.d.ts
2
+ declare module '@rexllins/zi' {
3
+ /* =====================
4
+ Reactive System
5
+ ===================== */
6
+ export type EffectRunner = () => any;
7
+
8
+ export type Ref<T> = { value: T };
9
+
10
+ export interface ComputedRef<T> { readonly value: T }
11
+
12
+ export class ReactiveSystem {
13
+ static currentEffect: EffectRunner | null;
14
+
15
+ reactive<T extends object>(obj: T): T;
16
+ ref<T>(value: T): Ref<T>;
17
+ computed<T>(getter: () => T): ComputedRef<T>;
18
+ effect(fn: () => void, options?: { lazy?: boolean }): EffectRunner;
19
+ watch<T>(getter: () => T, cb: (val: T, oldVal: T) => void): EffectRunner;
20
+ }
21
+
22
+ export const Reactive: ReactiveSystem;
23
+
24
+ /* =====================
25
+ Store
26
+ ===================== */
27
+ export class Store<S extends Record<string, any> = {}> {
28
+ state: S;
29
+ private _modules: Record<string, any>;
30
+ constructor(initial?: S);
31
+ registerModule<K extends string, M extends object>(
32
+ name: K,
33
+ mod: M
34
+ ): Store<S & { [P in K]: M }>;
35
+ patch(fn: (state: S) => void): void;
36
+ getModule<K extends keyof S>(name: K): S[K];
37
+ }
38
+
39
+ /* =====================
40
+ API Helper
41
+ ===================== */
42
+ export interface APIRequestOptions {
43
+ params?: Record<string, any>;
44
+ body?: any;
45
+ headers?: Record<string, string>;
46
+ }
47
+
48
+ export class API {
49
+ constructor(options?: { base?: string; headers?: Record<string, string>; fetchImpl?: typeof fetch });
50
+ get<T = any>(url: string, options?: APIRequestOptions): Promise<T>;
51
+ post<T = any>(url: string, options?: APIRequestOptions): Promise<T>;
52
+ put<T = any>(url: string, options?: APIRequestOptions): Promise<T>;
53
+ del<T = any>(url: string, options?: APIRequestOptions): Promise<T>;
54
+ }
55
+
56
+ /* =====================
57
+ Component
58
+ ===================== */
59
+ export type ComponentMethods = Record<string, (...args: any[]) => any>;
60
+
61
+ export interface ComponentOptions<
62
+ S extends Record<string, any> = {},
63
+ P extends Record<string, any> = {},
64
+ M extends ComponentMethods = {}
65
+ > {
66
+ template?: string | HTMLElement;
67
+ state?: S;
68
+ props?: P;
69
+ methods?: M;
70
+ onInit?: () => void;
71
+ onMount?: () => void;
72
+ onDestroy?: () => void;
73
+ directives?: Record<string, Function>;
74
+ }
75
+
76
+ export class Component<
77
+ S extends Record<string, any> = {},
78
+ P extends Record<string, any> = {},
79
+ M extends ComponentMethods = {}
80
+ > {
81
+ state: S;
82
+ props: P;
83
+ methods: M;
84
+ template: string | HTMLElement;
85
+ el: HTMLElement | null;
86
+ mounted: boolean;
87
+ directives: Record<string, Function>;
88
+
89
+ constructor(options?: ComponentOptions<S, P, M>);
90
+ getContext(): S & P;
91
+ mount(sel: string | HTMLElement): void;
92
+ unmount(): void;
93
+ }
94
+
95
+ /* =====================
96
+ Directives
97
+ ===================== */
98
+ export type ZForContext<Item = any> = { $item: Item; $index: number };
99
+
100
+ export interface Directives {
101
+ 'z-if': (el: HTMLElement, expr: string, cmp: Component, ctx?: Record<string, any>) => void;
102
+ 'z-show': (el: HTMLElement, expr: string, cmp: Component, ctx?: Record<string, any>) => void;
103
+ 'z-text': (el: HTMLElement, expr: string, cmp: Component, ctx?: Record<string, any>) => void;
104
+ 'z-html': (el: HTMLElement, expr: string, cmp: Component, ctx?: Record<string, any>) => void;
105
+ 'z-model': <T extends Record<string, any>>(el: HTMLInputElement, expr: string, cmp: Component<any, T>) => void;
106
+ 'z-for': (el: HTMLElement, expr: string, cmp: Component<any, any>) => void;
107
+ }
108
+
109
+ export const Directives: Directives;
110
+
111
+ /* =====================
112
+ Router
113
+ ===================== */
114
+ export interface RouteRecord<Params extends Record<string, string> = {}> {
115
+ path: string;
116
+ component: Component | string | ((opts: { params: Params; router: Router }) => Component | string | HTMLElement);
117
+ }
118
+
119
+ export interface RouterOptions {
120
+ mode?: 'hash' | 'history';
121
+ root?: HTMLElement;
122
+ notFound?: () => Component | string | HTMLElement;
123
+ }
124
+
125
+ export class Router {
126
+ constructor(routes: RouteRecord[], options?: RouterOptions);
127
+ init(rootSelector?: string | HTMLElement): void;
128
+ navigate(path: string): void;
129
+ }
130
+
131
+ /* =====================
132
+ App & Plugin System
133
+ ===================== */
134
+ export type PluginFn<S extends Record<string, any> = {}> = (ctx: { app: App<S>; store: Store<S>; api: API; Reactive: ReactiveSystem }) => void;
135
+
136
+ export class App<S extends Record<string, any> = {}> {
137
+ root: HTMLElement;
138
+ store: Store<S>;
139
+ api: API;
140
+ router: Router | null;
141
+ plugins: any[];
142
+
143
+ constructor(options?: { root?: string | HTMLElement; store?: Store<S>; api?: API });
144
+
145
+ use(plugin: PluginFn<S>): void;
146
+ mountComponent<C extends Component>(c: C): void;
147
+ useRouter(r: Router): void;
148
+ }
149
+
150
+ /* =====================
151
+ Helper creators
152
+ ===================== */
153
+ export const Zi: {
154
+ config: { debug: boolean };
155
+ Reactive: ReactiveSystem;
156
+ Store: typeof Store;
157
+ Component: typeof Component;
158
+ API: typeof API;
159
+ Router: typeof Router;
160
+ App: typeof App;
161
+ Directives: Directives;
162
+ createApp: <S extends Record<string, any> = {}>(opts?: { root?: string | HTMLElement; store?: Store<S>; api?: API }) => App<S>;
163
+ createComponent: <S extends Record<string, any> = {}, P extends Record<string, any> = {}, M extends ComponentMethods = {}>(opts?: ComponentOptions<S, P, M>) => Component<S, P, M>;
164
+ createStore: <S extends Record<string, any> = {}>(init?: S) => Store<S>;
165
+ createAPI: (opts?: { base?: string; headers?: Record<string, string>; fetchImpl?: typeof fetch }) => API;
166
+ };
167
+
168
+ export default Zi;
169
+ }