solely 0.4.21 → 0.5.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.
Files changed (43) hide show
  1. package/README.md +138 -38
  2. package/dist/compiler/ir/buildIR.cjs +1 -1
  3. package/dist/compiler/ir/buildIR.js +1 -1
  4. package/dist/compiler/parser/parser.cjs +1 -1
  5. package/dist/compiler/parser/parser.js +1 -1
  6. package/dist/index.cjs +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  9. package/dist/plugins/solely-vite-plugin.js +1 -1
  10. package/dist/runtime/component/base-element.cjs +1 -1
  11. package/dist/runtime/component/base-element.d.ts +6 -1
  12. package/dist/runtime/component/base-element.js +1 -1
  13. package/dist/runtime/component/decorators.cjs +1 -1
  14. package/dist/runtime/component/decorators.js +1 -1
  15. package/dist/runtime/index.cjs +1 -1
  16. package/dist/runtime/index.js +1 -1
  17. package/dist/runtime/reactivity/computed.cjs +1 -0
  18. package/dist/runtime/reactivity/computed.d.ts +36 -0
  19. package/dist/runtime/reactivity/computed.js +1 -0
  20. package/dist/runtime/reactivity/index.d.ts +6 -2
  21. package/dist/runtime/reactivity/observe.cjs +1 -1
  22. package/dist/runtime/reactivity/observe.d.ts +4 -32
  23. package/dist/runtime/reactivity/observe.js +1 -1
  24. package/dist/runtime/reactivity/watch.cjs +1 -0
  25. package/dist/runtime/reactivity/watch.d.ts +64 -0
  26. package/dist/runtime/reactivity/watch.js +1 -0
  27. package/dist/runtime/renderer/renderIR.cjs +1 -1
  28. package/dist/runtime/renderer/renderIR.d.ts +30 -20
  29. package/dist/runtime/renderer/renderIR.js +1 -1
  30. package/dist/shared/env.cjs +1 -1
  31. package/dist/shared/env.d.ts +2 -0
  32. package/dist/shared/env.js +1 -1
  33. package/dist/shared/index.cjs +1 -1
  34. package/dist/shared/index.js +1 -1
  35. package/dist/shared/is-object.d.ts +1 -1
  36. package/dist/types/ast.cjs +1 -1
  37. package/dist/types/ast.d.ts +1 -0
  38. package/dist/types/ast.js +1 -1
  39. package/dist/types/ir.d.ts +2 -0
  40. package/dist/types/lifecycle.cjs +1 -1
  41. package/dist/types/lifecycle.d.ts +1 -1
  42. package/dist/types/lifecycle.js +1 -1
  43. package/package.json +1 -1
@@ -1 +1 @@
1
- var t=Object.defineProperty,e=(e,s,o)=>((e,s,o)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:o}):e[s]=o)(e,"symbol"!=typeof s?s+"":s,o);import{ASTType as s}from"../../types/ast.js";import{showTemplateError as o}from"../../shared/templateError.js";import{IS_DEV as n}from"../../shared/env.js";import r from"./html-decode.js";const i=Symbol("solely.irCtx"),a=Symbol("solely.irEvents"),c=Symbol("solely.prevClassObj"),l=Symbol("solely.prevStyleObj"),h={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},p={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},d=new Set(["data-","aria-","role","form"]),u=new Set(["value","selectedIndex"]);function f(t,e){var s;const o=null==(s=e.a)?void 0:s.find(t=>"class"===t.k&&!t.d);(null==o?void 0:o.v)&&t.setAttribute("class",o.v)}function m(t,e){var s;if(!t.style)return;const o=null==(s=e.a)?void 0:s.find(t=>"style"===t.k&&!t.d),n=o?y(o.v):{};for(const r in n){const e=n[r];r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e}}const v=t=>!(!t||0===t.length||/\s/.test(t)&&(n&&console.warn(`[Solely] Invalid class name "${t}" contains whitespace, will be ignored`),1));function y(t){const e={},s=[[t]];for(;s.length;){const[t,o]=s.pop()||[];if(t){if("string"==typeof t){const s=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let o;for(;null!==(o=s.exec(t));){const t=o[1].trim(),s=o[2].trim();t&&s&&(e[t]=s)}continue}if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push([t[e]]);else if("object"==typeof t)for(const n in t){const r=t[n];if(null==r)continue;const i=o?`${o}-${n}`:n;"object"!=typeof r||Array.isArray(r)?e[i]=String(r):s.push([r,i])}}}return e}function S(t,e,s){const o=null==s?"":String(s),n=e.indexOf(":");if(n>0){const s=e.slice(0,n),r=h[s];if(r)return void(t.getAttributeNS(r,e)!==o&&t.setAttributeNS(r,e,o))}t.getAttribute(e)!==o&&t.setAttribute(e,o)}function b(t,e,s,o){const n=p[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||d.has(e))return void S(t,e,s);const r=t,i=r.tagName;if(null!=s){if("src"===n||"href"===n){const e=String(s);if(r[n]===e||t.getAttribute(n)===e)return}if("value"!==n||"INPUT"!==i&&"TEXTAREA"!==i||r.value!==s)if("boolean"!=typeof s)(o??(t instanceof SVGElement||void 0!==r.ownerSVGElement))&&!p[e]?S(t,e,s):r[n]!==s&&(r[n]=s);else{if(r[n]===s)return;r[n]=s}}else if("boolean"==typeof r[n])!1!==r[n]&&(r[n]=!1);else{const s=r[n];""!==s&&void 0!==s&&(r[n]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class g{constructor(t,s,o={}){e(this,"nodeMap",new Map),e(this,"prevNodeMap",new Map),e(this,"pathStack",[]),e(this,"staticSubtreeCache",new Map),this.ir=t,this.container=s,this.scope=o}evalIR(t,e,s){var r;const i=this.ir.fns[t-1];if(n)try{return i?i.apply(this.scope,e):""}catch(a){return o(a.message||a.toString(),(null==(r=this.ir.m)?void 0:r.src)||"",s,this.scope.tagName),""}return i?i.apply(this.scope,e):""}createElement(t,e){const s=t.g??"";return e instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(t,e){const s=t.d?this.evalIR(t.f??-1,[e],t.__m):r(t.x||"");return document.createTextNode(s)}createComment(t,e){const s=t.d?this.evalIR(t.f??-1,[e],t.__m):t.x||"";return document.createComment(s)}applyAttrs(t,e,s,o=!1){const n=[],r=t,h=t instanceof SVGElement||void 0!==r.ownerSVGElement;let p;r[i]||(r[i]={loops:null}),r[i].loops=s,r[a]||(r[a]=Object.create(null));let d,f=!1,m=!1;for(const c of e){const{k:e,f:l,d:v,v:y}=c;if(":class"===e){p=this.evalIR(l??-1,[s],c.__m),f=!0;continue}if(":style"===e){d=this.evalIR(l??-1,[s],c.__m),m=!0;continue}if("class"===e||"style"===e)continue;const g=e[0];if("@"===g){const s=e.slice(1),n=c.r??"user";let h=r[a][s];if(h||(h=r[a][s]={model:[],user:[]},t.addEventListener(s,t=>{for(const e of h.model)e(t);for(const e of h.user)e(t)})),!o){const t=t=>this.evalIR(l??-1,[t,r[i].loops],c.__m);h[n].push(t)}continue}if("mounted"===e){o||requestAnimationFrame(()=>this.evalIR(l??-1,[t,s],c.__m));continue}if("updated"===e){o&&requestAnimationFrame(()=>this.evalIR(l??-1,[t,s],c.__m));continue}if("ref"===e&&y){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[y]=t;continue}const N=v?this.evalIR(l??-1,[s],c.__m):y??"";if(":"===g){const s=e.slice(1);"SELECT"===t.tagName&&u.has(s)?n.push(()=>b(t,s,N,h)):b(t,s,N,h)}else o||S(t,e,String(N))}return f&&((t,e)=>{const s=t,o=s[c],n=function(t){const e={},s=[t];for(;s.length;){const t=s.pop();if(t)if("string"==typeof t){const s=t.split(" ");for(let t=0;t<s.length;t++){const o=s[t].trim();o&&(e[o]=!0)}}else if(Array.isArray(t))for(let e=t.length-1;e>=0;e--)s.push(t[e]);else if("object"==typeof t)for(const s in t)t[s]&&(e[s]=!0)}return e}(e),r={};for(const a in n)v(a)&&(r[a]=n[a]);if(!o){for(const e in r)t.classList.add(e);return void(s[c]=r)}let i=!1;for(const a in o)r[a]||(t.classList.remove(a),i=!0);for(const a in r)o[a]||(t.classList.add(a),i=!0);i&&(s[c]=r)})(t,p),m&&((t,e)=>{const s=t,o=y(e),n=s[l];if(!n){for(const e in o){const s=o[e];e.startsWith("--")?t.style.setProperty(e,s):t.style[e]=s}return void(s[l]=o)}let r=!1;for(const i in n)i in o||(i.startsWith("--")?t.style.removeProperty(i):t.style[i]="",r=!0);for(const i in o){const e=o[i];e!==n[i]&&(i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e,r=!0)}r&&(s[l]=o)})(t,d),n}updateNode(t,e,s){const o=e.d?this.evalIR(e.f??-1,[s],e.__m):e.x||"";e.d&&t.textContent!==o&&(t.textContent=o)}createStaticSubtree(t,e,o){var n;switch(t.t){case s.Element:{const s=this.createElement(t,e);f(s,t),m(s,t);const r=this.applyAttrs(s,t.a??[],o);return null==(n=t.c)||n.forEach(t=>{const e=this.createStaticSubtree(t,s,o);s.appendChild(e)}),r.forEach(t=>t()),s}case s.Text:return this.createText(t,o);case s.Comment:return this.createComment(t,o);default:return document.createComment("unknown")}}handleStaticSubtree(t,e,s,o){const n=this.staticSubtreeCache.get(e);if(n){const t=n.cloneNode(!0);return s.appendChild(t),t}const r=this.createStaticSubtree(t,s,o);return s.appendChild(r),this.staticSubtreeCache.set(e,r.cloneNode(!0)),r}currentKey(){return this.pathStack.join(".")}findEntry(t){let e=this.nodeMap.get(t);return e||(e=this.prevNodeMap.get(t),e&&(this.prevNodeMap.delete(t),this.nodeMap.set(t,e))),e}irToNode(t,e,s,o){this.pathStack.push(e),this.processNode(t,s,o),this.pathStack.pop()}processNode(t,e,o){var n,r,i,a,c,l,h;const p=this.currentKey(),d=this.findEntry(p);let u;if(1!==t.s)if(d){u=d.node;let e=[];t.d&&(t.t===s.Element?e=this.applyAttrs(u,t.a??[],o,!0):this.updateNode(u,t,o)),null==(n=t.c)||n.forEach((t,e)=>{this.pathStack.push(e),this.processNode(t,u,o),this.pathStack.pop()}),e.forEach(t=>t())}else switch(t.t){case s.Element:u=this.createElement(t,e),f(u,t),m(u,t);const n=this.applyAttrs(u,t.a??[],o);e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:o}),null==(r=t.c)||r.forEach((t,e)=>{this.pathStack.push(e),this.processNode(t,u,o),this.pathStack.pop()}),n.forEach(t=>t());break;case s.Text:u=this.createText(t,o),e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:o});break;case s.Comment:u=this.createComment(t,o),e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:o});break;case s.For:{this.pathStack.push(-1);const n=this.currentKey();this.pathStack.pop();let r=null==(i=this.findEntry(n))?void 0:i.node;r||(r=document.createComment("for"),e.appendChild(r),this.nodeMap.set(n,{irNode:{t:s.Comment},node:r,loops:o}));const c=this.evalIR(t.f??-1,[o],t.__m)||[],l=document.createDocumentFragment();c.forEach((e,s)=>{var n;const r=[...o,{itmVal:e,idxVal:s}];null==(n=t.c)||n.forEach((t,e)=>{this.pathStack.push(s,e),this.processNode(t,l,r),this.pathStack.pop(),this.pathStack.pop()})}),null==(a=r.parentNode)||a.insertBefore(l,r);break}case s.Conditional:{this.pathStack.push(-1);const s=this.currentKey();this.pathStack.pop();let n=null==(c=this.findEntry(s))?void 0:c.node;n||(n=document.createComment("if"),e.appendChild(n),this.nodeMap.set(s,{irNode:{},node:n,loops:o}));for(let e=0;e<(t.b||[]).length;e++){const s=null==(l=t.b)?void 0:l[e];if(null===s.f||this.evalIR(s.f,[o],s.__m)){const t=document.createDocumentFragment();s.c.forEach((s,n)=>{this.pathStack.push(e,n),this.processNode(s,t,o),this.pathStack.pop(),this.pathStack.pop()}),null==(h=n.parentNode)||h.insertBefore(t,n);break}}break}}else d?u=d.node:(u=this.handleStaticSubtree(t,p,e,o),this.nodeMap.set(p,{irNode:t,node:u,loops:o}))}cleanupOldNodes(){const t=this.prevNodeMap;for(const[,e]of t.entries()){const{irNode:t,node:s,loops:o}=e;if(t.a){const e=t.a.find(t=>"unmounted"===t.k);e&&requestAnimationFrame(()=>{this.evalIR(e.f??-1,[s,o],e.__m)});const n=t.a.find(t=>"ref"===t.k);n&&n.v&&delete this.scope.$refs[n.v]}null==s||s.remove()}t.clear()}mount(){this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,this.container,[])}),this.cleanupOldNodes()}update(){this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.ir.n.forEach((t,e)=>{this.irToNode(t,e,this.container,[])}),this.cleanupOldNodes()}destroy(){this.container.innerHTML="",this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear()}}const N=(t,e,s={})=>{const o=new g(t,e,s);return o.mount(),{update:()=>o.update(),destroy:()=>o.destroy()}};export{g as IRRenderer,N as createRender};
1
+ var e=Object.defineProperty,t=(t,s,n)=>((t,s,n)=>s in t?e(t,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[s]=n)(t,"symbol"!=typeof s?s+"":s,n);import{ASTType as s}from"../../types/ast.js";import{showTemplateError as n}from"../../shared/templateError.js";import{IS_DEV as i}from"../../shared/env.js";import o from"./html-decode.js";const r=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,a={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},h={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},c=new Set(["data-","aria-","role","form"]),l=new Set(["value","selectedIndex"]),p=new WeakMap;function d(e){let t=p.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},p.set(e,t)),t}function f(e,t){var s;const n=null==(s=t.a)?void 0:s.find(e=>"class"===e.k&&!e.d);(null==n?void 0:n.v)&&e.setAttribute("class",n.v)}function u(e,t){var s;if(!e.style)return;const n=null==(s=t.a)?void 0:s.find(e=>"style"===e.k&&!e.d),i=n?v(n.v):{};for(const o in i){const t=i[o];o.startsWith("--")?e.style.setProperty(o,t):e.style[o]=t}}const m=e=>!(!e||0===e.length||/\s/.test(e)&&(i&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function v(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(r.lastIndex=0;null!==(s=r.exec(e));){const e=s[1].trim(),n=s[2].trim();e&&n&&(t[e]=n)}continue}if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push([e[t]]);else if("object"==typeof e){const i=e;for(const e in i){const o=i[e];if(null==o)continue;const r=n?`${n}-${e}`:e;"object"!=typeof o||Array.isArray(o)?t[r]=String(o):s.push([o,r])}}}}return t}function y(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),o=a[s];if(o)return void(e.getAttributeNS(o,t)!==n&&e.setAttributeNS(o,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function g(e,t,s,n){const i=h[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||c.has(t))return void y(e,t,s);const o=e,r=o.tagName;if(null!=s){if("src"===i||"href"===i){const t=String(s);if(o[i]===t||e.getAttribute(i)===t)return}if("value"!==i||"INPUT"!==r&&"TEXTAREA"!==r||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!h[t]?y(e,t,s):o[i]!==s&&(o[i]=s);else{if(o[i]===s)return;o[i]=s}}else if("boolean"==typeof o[i])!1!==o[i]&&(o[i]=!1);else{const s=o[i];""!==s&&void 0!==s&&(o[i]=""),e.hasAttribute(t)&&e.removeAttribute(t)}}class N{constructor(e,s,n={}){t(this,"nodeMap",new Map),t(this,"prevNodeMap",new Map),t(this,"pathStack",[]),t(this,"pathKey",""),t(this,"staticSubtreeCache",new Map),t(this,"keepaliveCache",new Map),t(this,"currentKaKey",null),t(this,"kaDepth",0),t(this,"isKaRestoring",!1),t(this,"rafIds",new Set),t(this,"keepaliveAccessCounter",0),t(this,"maxKeepalive",20),t(this,"renderedKaKeys",new Set),this.ir=e,this.container=s,this.scope=n}scheduleRaf(e){const t=requestAnimationFrame(()=>{this.rafIds.delete(t),e()});return this.rafIds.add(t),t}pushPath(e){this.pathStack.push(e),this.pathKey=this.pathStack.join(".")}popPath(){this.pathStack.pop(),this.pathKey=this.pathStack.join(".")}evalIR(e,t,s){var o;const r=this.ir.fns[e-1];if(i)try{return r?r.apply(this.scope,t):""}catch(a){return n(a.message||a.toString(),(null==(o=this.ir.m)?void 0:o.src)||"",s,this.scope.tagName),""}return r?r.apply(this.scope,t):""}createElement(e,t){const s=e.g??"";return t instanceof SVGElement||"svg"===s?document.createElementNS("http://www.w3.org/2000/svg",s):document.createElement(s)}createText(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):o(e.x||"");return document.createTextNode(s)}createComment(e,t){const s=e.d?this.evalIR(e.f??-1,[t],e.__m):e.x||"";return document.createComment(s)}removeEventListenersFromNode(e){const t=p.get(e);if(t)for(const[s,n]of Object.entries(t.events))n.listener&&e.removeEventListener(s,n.listener)}applyAttrs(e,t,s,n=!1,i=!1){const o=[],r=d(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let h;r.loops=s;let c,p=!1,f=!1;for(const d of t){const{k:t,f:u,d:m,v:v}=d;if(":class"===t){h=this.evalIR(u??-1,[s],d.__m),p=!0;continue}if(":style"===t){c=this.evalIR(u??-1,[s],d.__m),f=!0;continue}if("class"===t||"style"===t)continue;const N=t[0];if("@"===N){const s=t.slice(1),i=d.r??"user";let o=r.events[s];if(!o){o={model:[],user:[],listener:null};const t=e=>{for(const t of o.model)t(e);for(const t of o.user)t(e)};o.listener=t,e.addEventListener(s,t),r.events[s]=o}if(!n){const e=e=>this.evalIR(u??-1,[e,r.loops],d.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],d.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],d.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(u??-1,[e,s],d.__m));continue}if("ref"===t&&v){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[v]=e;continue}const k=m?this.evalIR(u??-1,[s],d.__m):v??"";if(":"===N){const s=t.slice(1);"SELECT"===e.tagName&&l.has(s)?o.push(()=>g(e,s,k,a)):g(e,s,k,a)}else n||y(e,t,String(k))}return p&&((e,t)=>{const s=d(e),n=s.prevClassObj,i=function(e){const t={},s=[e];for(;s.length;){const e=s.pop();if(e)if("string"==typeof e){const s=e.split(" ");for(let e=0;e<s.length;e++){const n=s[e].trim();n&&(t[n]=!0)}}else if(Array.isArray(e))for(let t=e.length-1;t>=0;t--)s.push(e[t]);else if("object"==typeof e){const s=e;for(const e in s)s[e]&&(t[e]=!0)}}return t}(t),o={};for(const h in i)m(h)&&(o[h]=i[h]);if(!n){const t=[];for(const e in o)t.push(e);return t.length&&e.classList.add(...t),void(s.prevClassObj=o)}const r=[],a=[];for(const h in n)o[h]||a.push(h);for(const h in o)n[h]||r.push(h);(r.length||a.length)&&(r.length&&e.classList.add(...r),a.length&&e.classList.remove(...a),s.prevClassObj=o)})(e,h),f&&((e,t)=>{const s=d(e),n=v(t),i=s.prevStyleObj;if(!i){for(const t in n){const s=n[t];t.startsWith("--")?e.style.setProperty(t,s):e.style[t]=s}return void(s.prevStyleObj=n)}let o=!1;for(const r in i)r in n||(r.startsWith("--")?e.style.removeProperty(r):e.style[r]="",o=!0);for(const r in n){const t=n[r];t!==i[r]&&(r.startsWith("--")?e.style.setProperty(r,t):e.style[r]=t,o=!0)}o&&(s.prevStyleObj=n)})(e,c),o}updateNode(e,t,s){const n=t.d?this.evalIR(t.f??-1,[s],t.__m):t.x||"";t.d&&e.textContent!==n&&(e.textContent=n)}createStaticSubtree(e,t,n){var i;switch(e.t){case s.Element:{const s=this.createElement(e,t);f(s,e),u(s,e);const o=this.applyAttrs(s,e.a??[],n);return null==(i=e.c)||i.forEach(e=>{const t=this.createStaticSubtree(e,s,n);s.appendChild(t)}),o.forEach(e=>e()),s}case s.Text:return this.createText(e,n);case s.Comment:return this.createComment(e,n);default:return document.createComment("unknown")}}handleStaticSubtree(e,t,s,n){const i=this.staticSubtreeCache.get(t);if(i){const e=i.cloneNode(!0);return s.appendChild(e),e}const o=this.createStaticSubtree(e,s,n);return s.appendChild(o),this.staticSubtreeCache.set(t,o.cloneNode(!0)),o}currentKey(){return this.pathKey}findEntry(e){let t=this.nodeMap.get(e);return t||(t=this.prevNodeMap.get(e),t&&(this.prevNodeMap.delete(e),this.nodeMap.set(e,t))),t}registerNode(e,t,s,n){const i=this.currentKaKey?{irNode:t,node:s,loops:n,kaKey:this.currentKaKey}:{irNode:t,node:s,loops:n};this.nodeMap.set(e,i)}processNode(e,t,n){var o,r,a,h,c,l,p,d,m;const v=this.currentKey(),y=this.findEntry(v);let g;if(1!==e.s)if(y){g=y.node;let t=[];e.d&&(e.t===s.Element?t=this.applyAttrs(g,e.a??[],n,!0,this.isKaRestoring):this.updateNode(g,e,n)),null==(o=e.c)||o.forEach((e,t)=>{this.pushPath(t),this.processNode(e,g,n),this.popPath()}),t.forEach(e=>e())}else switch(e.t){case s.Element:g=this.createElement(e,t),f(g,e),u(g,e);const o=this.applyAttrs(g,e.a??[],n);t.appendChild(g),this.registerNode(v,e,g,n),null==(r=e.c)||r.forEach((e,t)=>{this.pushPath(t),this.processNode(e,g,n),this.popPath()}),o.forEach(e=>e());break;case s.Text:g=this.createText(e,n),t.appendChild(g),this.registerNode(v,e,g,n);break;case s.Comment:g=this.createComment(e,n),t.appendChild(g),this.registerNode(v,e,g,n);break;case s.For:{this.pushPath(-1);const i=this.currentKey();this.popPath();let o=null==(a=this.findEntry(i))?void 0:a.node;o||(o=document.createComment("for"),t.appendChild(o),this.registerNode(i,{t:s.Comment},o,n));const r=this.evalIR(e.f??-1,[n],e.__m)||[],c=document.createDocumentFragment();r.forEach((t,s)=>{var i;const o=[...n,{itmVal:t,idxVal:s}];null==(i=e.c)||i.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,c,o),this.popPath(),this.popPath()})}),null==(h=o.parentNode)||h.insertBefore(c,o);break}case s.Conditional:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=null==(c=this.findEntry(s))?void 0:c.node;o||(o=document.createComment("if"),t.appendChild(o),this.registerNode(s,{},o,n));for(let r=0;r<(e.b||[]).length;r++){const s=null==(l=e.b)?void 0:l[r];if(null===s.f||this.evalIR(s.f,[n],s.__m)){this.pushPath(r);const e=this.currentKey();if(this.popPath(),1===s.ka){this.renderedKaKeys.add(e);const a=this.keepaliveCache.get(e);if(a&&!a.active){null==(p=o.parentNode)||p.insertBefore(a.fragment,o);for(const[e,t]of a.entries)this.prevNodeMap.set(e,t);a.active=!0,a.lastUsed=++this.keepaliveAccessCounter;const h=this.isKaRestoring;this.isKaRestoring=!0;const c=this.currentKaKey;this.currentKaKey=e,this.kaDepth++,i&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),s.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,n),this.popPath(),this.popPath()}),this.kaDepth--,this.currentKaKey=c,this.isKaRestoring=h}else{a&&a.active&&(a.lastUsed=++this.keepaliveAccessCounter);const h=this.currentKaKey;this.currentKaKey=e,this.kaDepth++,i&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const c=e+".0";if(this.prevNodeMap.get(c))s.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,n),this.popPath(),this.popPath()});else{const e=document.createDocumentFragment();s.c.forEach((t,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(t,e,n),this.popPath(),this.popPath()}),null==(d=o.parentNode)||d.insertBefore(e,o)}this.kaDepth--,this.currentKaKey=h}}else{const e=document.createDocumentFragment();s.c.forEach((t,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(t,e,n),this.popPath(),this.popPath()}),null==(m=o.parentNode)||m.insertBefore(e,o)}break}}break}}else y?g=y.node:(g=this.handleStaticSubtree(e,v,t,n),this.registerNode(v,e,g,n))}evictKeepaliveIfNeeded(){var e;let t=0;for(const[,i]of this.keepaliveCache.entries())i.active||t++;if(t<=this.maxKeepalive)return;let s=null,n=1/0;for(const[i,o]of this.keepaliveCache.entries())o.active||o.lastUsed<n&&(n=o.lastUsed,s=i);if(s){const t=this.keepaliveCache.get(s);for(const[,s]of t.entries){if(this.removeEventListenersFromNode(s.node),s.irNode.a){const e=s.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[s.node,s.loops],e.__m)})}null==(e=s.node)||e.remove()}this.keepaliveCache.delete(s)}}cleanupOldNodes(){const e=this.prevNodeMap,t=new Map;for(const[s,n]of e.entries()){const{irNode:e,node:i,loops:o}=n,r=n.kaKey&&this.renderedKaKeys.has(n.kaKey);if(e.a){if(n.kaKey&&!r){const t=e.a.find(e=>"deactivated"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}else{const t=e.a.find(e=>"unmounted"===e.k);t&&this.scheduleRaf(()=>this.evalIR(t.f??-1,[i,o],t.__m))}const t=e.a.find(e=>"ref"===e.k);t&&t.v&&delete this.scope.$refs[t.v]}if(n.kaKey&&!r&&i.parentNode){let e=t.get(n.kaKey);e||(e={fragment:document.createDocumentFragment(),entries:[]},t.set(n.kaKey,e));const o=n.kaKey.split(".").length;s.split(".").length===o+1&&e.fragment.appendChild(i),e.entries.push([s,n])}else this.removeEventListenersFromNode(i),null==i||i.remove()}for(const[s,n]of t.entries()){const e=this.keepaliveCache.get(s);e&&e.active?(e.fragment=n.fragment,e.entries=n.entries,e.active=!1,e.lastUsed=++this.keepaliveAccessCounter):e||this.keepaliveCache.set(s,{fragment:n.fragment,entries:n.entries,lastUsed:++this.keepaliveAccessCounter,active:!1})}this.evictKeepaliveIfNeeded(),e.clear()}mount(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}update(){this.renderedKaKeys.clear(),this.prevNodeMap=this.nodeMap,this.nodeMap=new Map,this.pathStack.length=0,this.pathKey="",this.ir.n.forEach((e,t)=>{this.irToNode(e,t,this.container,[])}),this.cleanupOldNodes()}destroy(){var e;this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const t=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};t(this.nodeMap),t(this.prevNodeMap);for(const[,s]of this.keepaliveCache.entries())for(const[,t]of s.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.evalIR(e.f??-1,[t.node,t.loops],e.__m)}null==(e=t.node)||e.remove()}this.container.innerHTML="",this.scope.$refs={},this.nodeMap.clear(),this.prevNodeMap.clear(),this.staticSubtreeCache.clear(),this.keepaliveCache.clear(),this.renderedKaKeys.clear()}irToNode(e,t,s,n){this.pushPath(t),this.processNode(e,s,n),this.popPath()}}const k=(e,t,s={})=>{const n=new N(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{N as IRRenderer,k as createRender};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(()=>{var o,e;if("undefined"!=typeof window){if(null==(o=window.location)?void 0:o.search.includes("debug"))return!0;const e=globalThis;if(!0===e.__DEBUG__||!0===e.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(e=window.location)?void 0:e.hostname)||""))})(),e=!o;exports.IS_DEV=o,exports.IS_PROD=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o=(()=>{var o,e;if("undefined"!=typeof window){if(null==(o=window.location)?void 0:o.search.includes("debug"))return!0;const e=globalThis;if(!0===e.__DEBUG__||!0===e.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(e=window.location)?void 0:e.hostname)||""))})(),e=!o;exports.IS_DEV=o,exports.IS_PROD=e,exports.SOLELY_VERSION="0.5.0";
@@ -2,3 +2,5 @@
2
2
  export declare const IS_DEV: boolean;
3
3
  /** 是否为生产环境 */
4
4
  export declare const IS_PROD: boolean;
5
+ /** Solely 框架版本号(编译时从 package.json 注入) */
6
+ export declare const SOLELY_VERSION: string;
@@ -1 +1 @@
1
- const n=(()=>{var n,o;if("undefined"!=typeof window){if(null==(n=window.location)?void 0:n.search.includes("debug"))return!0;const o=globalThis;if(!0===o.__DEBUG__||!0===o.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(o=window.location)?void 0:o.hostname)||""))})(),o=!n;export{n as IS_DEV,o as IS_PROD};
1
+ const n=(()=>{var n,o;if("undefined"!=typeof window){if(null==(n=window.location)?void 0:n.search.includes("debug"))return!0;const o=globalThis;if(!0===o.__DEBUG__||!0===o.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes((null==(o=window.location)?void 0:o.hostname)||""))})(),o=!n,i="0.5.0";export{n as IS_DEV,o as IS_PROD,i as SOLELY_VERSION};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./templateError.cjs"),r=require("./gen-function.cjs"),s=require("./functions.cjs"),t=require("./event-listeners.cjs"),o=require("./is-object.cjs"),c=require("./url.cjs"),i=require("./env.cjs"),n=require("./case-convert.cjs");exports.showTemplateError=e.showTemplateError,exports.genFunction=r.genFunction,exports.createFunction=s.createFunction,exports.isCSPBlocked=s.isCSPBlocked,exports.listeners=t.default,exports.isObject=o.isObject,exports.parseHashUrl=c.parseHashUrl,exports.IS_DEV=i.IS_DEV,exports.IS_PROD=i.IS_PROD,exports.camelToKebab=n.camelToKebab;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./templateError.cjs"),r=require("./gen-function.cjs"),s=require("./functions.cjs"),t=require("./event-listeners.cjs"),o=require("./is-object.cjs"),c=require("./url.cjs"),i=require("./env.cjs"),n=require("./case-convert.cjs");exports.showTemplateError=e.showTemplateError,exports.genFunction=r.genFunction,exports.createFunction=s.createFunction,exports.isCSPBlocked=s.isCSPBlocked,exports.listeners=t.default,exports.isObject=o.isObject,exports.parseHashUrl=c.parseHashUrl,exports.IS_DEV=i.IS_DEV,exports.IS_PROD=i.IS_PROD,exports.SOLELY_VERSION=i.SOLELY_VERSION,exports.camelToKebab=n.camelToKebab;
@@ -1 +1 @@
1
- import{showTemplateError as r}from"./templateError.js";import{genFunction as o}from"./gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./functions.js";import{default as s}from"./event-listeners.js";import{isObject as e}from"./is-object.js";import{parseHashUrl as i}from"./url.js";import{IS_DEV as f,IS_PROD as n}from"./env.js";import{camelToKebab as p}from"./case-convert.js";export{f as IS_DEV,n as IS_PROD,p as camelToKebab,t as createFunction,o as genFunction,m as isCSPBlocked,e as isObject,s as listeners,i as parseHashUrl,r as showTemplateError};
1
+ import{showTemplateError as r}from"./templateError.js";import{genFunction as o}from"./gen-function.js";import{createFunction as t,isCSPBlocked as m}from"./functions.js";import{default as s}from"./event-listeners.js";import{isObject as e}from"./is-object.js";import{parseHashUrl as i}from"./url.js";import{IS_DEV as f,IS_PROD as n,SOLELY_VERSION as p}from"./env.js";import{camelToKebab as j}from"./case-convert.js";export{f as IS_DEV,n as IS_PROD,p as SOLELY_VERSION,j as camelToKebab,t as createFunction,o as genFunction,m as isCSPBlocked,e as isObject,s as listeners,i as parseHashUrl,r as showTemplateError};
@@ -1 +1 @@
1
- export declare const isObject: (value: unknown) => boolean;
1
+ export declare const isObject: (value: unknown) => value is object;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Other=99]="Other",e))(e||{});exports.ASTType=e;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Show=8]="Show",e[e.Other=99]="Other",e))(e||{});exports.ASTType=e;
@@ -29,6 +29,7 @@ export declare enum ASTType {
29
29
  Else = 5,
30
30
  For = 6,
31
31
  Conditional = 7,// if-elseif-else 结构
32
+ Show = 8,// show 显隐控制(不销毁 DOM,仅切换 display)
32
33
  Other = 99
33
34
  }
34
35
  /** AST 节点 */
package/dist/types/ast.js CHANGED
@@ -1 +1 @@
1
- var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Other=99]="Other",e))(e||{});export{e as ASTType};
1
+ var e=(e=>(e[e.Element=0]="Element",e[e.Text=1]="Text",e[e.Comment=2]="Comment",e[e.If=3]="If",e[e.ElseIf=4]="ElseIf",e[e.Else=5]="Else",e[e.For=6]="For",e[e.Conditional=7]="Conditional",e[e.Show=8]="Show",e[e.Other=99]="Other",e))(e||{});export{e as ASTType};
@@ -40,6 +40,8 @@ export interface IRBranch {
40
40
  c: IRNode[];
41
41
  /** attributes 属性数组,支持 <if class="red" cond={...}> */
42
42
  a?: IRAttr[];
43
+ /** keepalive 是否缓存分支(条件不满足时隐藏而非销毁) */
44
+ ka?: 1;
43
45
  /** __meta 调试元信息 */
44
46
  __m?: Meta;
45
47
  }
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={onMounted:"mounted",onUpdated:"updated",onUnmounted:"unmounted"};exports.LIFECYCLE_ATTRS_MAP=e,exports.isLifecycleKind=function(e){return"mounted"===e||"updated"===e||"unmounted"===e},exports.mapAttrKeyToLifecycleKind=function(t){return e[t]??null};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t={onMounted:"mounted",onUpdated:"updated",onUnmounted:"unmounted",onActivated:"activated",onDeactivated:"deactivated"};exports.LIFECYCLE_ATTRS_MAP=t,exports.isLifecycleKind=function(t){return"mounted"===t||"updated"===t||"unmounted"===t||"activated"===t||"deactivated"===t},exports.mapAttrKeyToLifecycleKind=function(e){return t[e]??null};
@@ -1,5 +1,5 @@
1
1
  /** 生命周期类型 */
2
- export type LifecycleKind = 'mounted' | 'updated' | 'unmounted';
2
+ export type LifecycleKind = 'mounted' | 'updated' | 'unmounted' | 'activated' | 'deactivated';
3
3
  /** 生命周期属性映射表 */
4
4
  export declare const LIFECYCLE_ATTRS_MAP: Record<string, LifecycleKind>;
5
5
  /**
@@ -1 +1 @@
1
- const n={onMounted:"mounted",onUpdated:"updated",onUnmounted:"unmounted"};function t(t){return n[t]??null}function u(n){return"mounted"===n||"updated"===n||"unmounted"===n}export{n as LIFECYCLE_ATTRS_MAP,u as isLifecycleKind,t as mapAttrKeyToLifecycleKind};
1
+ const t={onMounted:"mounted",onUpdated:"updated",onUnmounted:"unmounted",onActivated:"activated",onDeactivated:"deactivated"};function n(n){return t[n]??null}function e(t){return"mounted"===t||"updated"===t||"unmounted"===t||"activated"===t||"deactivated"===t}export{t as LIFECYCLE_ATTRS_MAP,e as isLifecycleKind,n as mapAttrKeyToLifecycleKind};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.4.21",
4
+ "version": "0.5.0",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
7
  "sideEffects": false,