solely 0.5.8 → 0.6.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 (145) hide show
  1. package/README.md +7 -6
  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/components/commands/drawer/index.cjs +1 -1
  7. package/dist/components/commands/drawer/index.js +1 -1
  8. package/dist/components/commands/drawer/style.css.cjs +1 -1
  9. package/dist/components/commands/drawer/style.css.js +1 -1
  10. package/dist/components/commands/message/index.cjs +1 -1
  11. package/dist/components/commands/message/index.js +1 -1
  12. package/dist/components/commands/modal/index.cjs +1 -1
  13. package/dist/components/commands/modal/index.js +1 -1
  14. package/dist/components/commands/modal/style.css.cjs +1 -1
  15. package/dist/components/commands/modal/style.css.js +1 -1
  16. package/dist/components/commands/popconfirm/index.cjs +1 -1
  17. package/dist/components/commands/popconfirm/index.js +1 -1
  18. package/dist/components/commands/tooltip/index.cjs +1 -1
  19. package/dist/components/commands/tooltip/index.js +1 -1
  20. package/dist/components/commands/utils.cjs +1 -1
  21. package/dist/components/commands/utils.js +1 -1
  22. package/dist/components/elements/alert/index.cjs +1 -1
  23. package/dist/components/elements/alert/index.html.cjs +1 -1
  24. package/dist/components/elements/alert/index.html.js +1 -1
  25. package/dist/components/elements/alert/index.js +1 -1
  26. package/dist/components/elements/backtop/index.cjs +1 -1
  27. package/dist/components/elements/backtop/index.html.cjs +1 -1
  28. package/dist/components/elements/backtop/index.html.js +1 -1
  29. package/dist/components/elements/backtop/index.js +1 -1
  30. package/dist/components/elements/breadcrumb/index.cjs +1 -1
  31. package/dist/components/elements/breadcrumb/index.html.cjs +1 -1
  32. package/dist/components/elements/breadcrumb/index.html.js +1 -1
  33. package/dist/components/elements/breadcrumb/index.js +1 -1
  34. package/dist/components/elements/button/index.cjs +1 -1
  35. package/dist/components/elements/button/index.html.cjs +1 -1
  36. package/dist/components/elements/button/index.html.js +1 -1
  37. package/dist/components/elements/button/index.js +1 -1
  38. package/dist/components/elements/card/index.html.cjs +1 -1
  39. package/dist/components/elements/card/index.html.js +1 -1
  40. package/dist/components/elements/checkbox/index.cjs +1 -1
  41. package/dist/components/elements/checkbox/index.html.cjs +1 -1
  42. package/dist/components/elements/checkbox/index.html.js +1 -1
  43. package/dist/components/elements/checkbox/index.js +1 -1
  44. package/dist/components/elements/coordinate-input/index.html.cjs +1 -1
  45. package/dist/components/elements/coordinate-input/index.html.js +1 -1
  46. package/dist/components/elements/coordinate-input/style.css.cjs +1 -1
  47. package/dist/components/elements/coordinate-input/style.css.js +1 -1
  48. package/dist/components/elements/fab/index.cjs +1 -1
  49. package/dist/components/elements/fab/index.html.cjs +1 -1
  50. package/dist/components/elements/fab/index.html.js +1 -1
  51. package/dist/components/elements/fab/index.js +1 -1
  52. package/dist/components/elements/icon/index.cjs +1 -1
  53. package/dist/components/elements/icon/index.d.ts +8 -0
  54. package/dist/components/elements/icon/index.html.cjs +1 -1
  55. package/dist/components/elements/icon/index.html.js +1 -1
  56. package/dist/components/elements/icon/index.js +1 -1
  57. package/dist/components/elements/input/index.cjs +1 -1
  58. package/dist/components/elements/input/index.html.cjs +1 -1
  59. package/dist/components/elements/input/index.html.js +1 -1
  60. package/dist/components/elements/input/index.js +1 -1
  61. package/dist/components/elements/not-found/index.html.cjs +1 -1
  62. package/dist/components/elements/not-found/index.html.js +1 -1
  63. package/dist/components/elements/not-found/style.css.cjs +1 -1
  64. package/dist/components/elements/not-found/style.css.js +1 -1
  65. package/dist/components/elements/pagination/index.html.cjs +1 -1
  66. package/dist/components/elements/pagination/index.html.js +1 -1
  67. package/dist/components/elements/pagination/style.css.cjs +1 -1
  68. package/dist/components/elements/pagination/style.css.js +1 -1
  69. package/dist/components/elements/radio/index.cjs +1 -1
  70. package/dist/components/elements/radio/index.html.cjs +1 -1
  71. package/dist/components/elements/radio/index.html.js +1 -1
  72. package/dist/components/elements/radio/index.js +1 -1
  73. package/dist/components/elements/rate/index.cjs +1 -1
  74. package/dist/components/elements/rate/index.html.cjs +1 -1
  75. package/dist/components/elements/rate/index.html.js +1 -1
  76. package/dist/components/elements/rate/index.js +1 -1
  77. package/dist/components/elements/select/index.cjs +1 -1
  78. package/dist/components/elements/select/index.html.cjs +1 -1
  79. package/dist/components/elements/select/index.html.js +1 -1
  80. package/dist/components/elements/select/index.js +1 -1
  81. package/dist/components/elements/slider/index.cjs +1 -1
  82. package/dist/components/elements/slider/index.html.cjs +1 -1
  83. package/dist/components/elements/slider/index.html.js +1 -1
  84. package/dist/components/elements/slider/index.js +1 -1
  85. package/dist/components/elements/steps/index.cjs +1 -1
  86. package/dist/components/elements/steps/index.html.cjs +1 -1
  87. package/dist/components/elements/steps/index.html.js +1 -1
  88. package/dist/components/elements/steps/index.js +1 -1
  89. package/dist/components/elements/switch/index.cjs +1 -1
  90. package/dist/components/elements/switch/index.html.cjs +1 -1
  91. package/dist/components/elements/switch/index.html.js +1 -1
  92. package/dist/components/elements/switch/index.js +1 -1
  93. package/dist/components/elements/table/index.html.cjs +1 -1
  94. package/dist/components/elements/table/index.html.js +1 -1
  95. package/dist/components/elements/tabs/index.html.cjs +1 -1
  96. package/dist/components/elements/tabs/index.html.js +1 -1
  97. package/dist/components/elements/tag/index.html.cjs +1 -1
  98. package/dist/components/elements/tag/index.html.js +1 -1
  99. package/dist/components/elements/timeline/index.cjs +1 -1
  100. package/dist/components/elements/timeline/index.js +1 -1
  101. package/dist/components/elements/tooltip/index.cjs +1 -1
  102. package/dist/components/elements/tooltip/index.html.cjs +1 -1
  103. package/dist/components/elements/tooltip/index.html.js +1 -1
  104. package/dist/components/elements/tooltip/index.js +1 -1
  105. package/dist/components/elements/tree/index.cjs +1 -1
  106. package/dist/components/elements/tree/index.d.ts +5 -0
  107. package/dist/components/elements/tree/index.html.cjs +1 -1
  108. package/dist/components/elements/tree/index.html.js +1 -1
  109. package/dist/components/elements/tree/index.js +1 -1
  110. package/dist/components/elements/upload/index.cjs +1 -1
  111. package/dist/components/elements/upload/index.html.cjs +1 -1
  112. package/dist/components/elements/upload/index.html.js +1 -1
  113. package/dist/components/elements/upload/index.js +1 -1
  114. package/dist/index.cjs +1 -1
  115. package/dist/index.js +1 -1
  116. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  117. package/dist/plugins/solely-vite-plugin.js +1 -1
  118. package/dist/router/core.cjs +1 -1
  119. package/dist/router/core.js +1 -1
  120. package/dist/router/router-link.cjs +1 -1
  121. package/dist/router/router-link.js +1 -1
  122. package/dist/router/router-view.cjs +1 -1
  123. package/dist/router/router-view.js +1 -1
  124. package/dist/runtime/component/base-element.cjs +1 -1
  125. package/dist/runtime/component/base-element.js +1 -1
  126. package/dist/runtime/component/decorators.cjs +1 -1
  127. package/dist/runtime/component/decorators.js +1 -1
  128. package/dist/runtime/reactivity/observe.cjs +1 -1
  129. package/dist/runtime/reactivity/observe.js +1 -1
  130. package/dist/runtime/renderer/renderIR.cjs +1 -1
  131. package/dist/runtime/renderer/renderIR.js +1 -1
  132. package/dist/shared/env.cjs +1 -1
  133. package/dist/shared/env.js +1 -1
  134. package/dist/shared/functions.d.ts +2 -2
  135. package/dist/shared/gen-function.cjs +1 -1
  136. package/dist/shared/gen-function.js +1 -1
  137. package/dist/shared/index.cjs +1 -1
  138. package/dist/shared/index.d.ts +1 -0
  139. package/dist/shared/index.js +1 -1
  140. package/dist/shared/svg-sanitize.cjs +1 -0
  141. package/dist/shared/svg-sanitize.d.ts +27 -0
  142. package/dist/shared/svg-sanitize.js +1 -0
  143. package/dist/shared/templateError.cjs +1 -1
  144. package/dist/shared/templateError.js +1 -1
  145. package/package.json +14 -12
@@ -1 +1 @@
1
- "use strict";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);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../types/ast.cjs"),n=require("../../shared/templateError.cjs"),i=require("../../shared/env.cjs"),o=require("./html-decode.cjs"),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 u(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 f(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?m(n.v):{};for(const o in i){const t=i[o];o.startsWith("--")?e.style.setProperty(o,t):e.style[o]=t}}const v=e=>!(!e||0===e.length||/\s/.test(e)&&(i.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function m(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.IS_DEV)try{return r?r.apply(this.scope,t):""}catch(a){return n.showTemplateError(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.default(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,u=!1;for(const d of t){const{k:t,f:f,d:v,v:m}=d;if(":class"===t){h=this.evalIR(f??-1,[s],d.__m),p=!0;continue}if(":style"===t){c=this.evalIR(f??-1,[s],d.__m),u=!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(f??-1,[e,r.loops],d.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],d.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],d.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],d.__m));continue}if("ref"===t&&m){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[m]=e;continue}const S=v?this.evalIR(f??-1,[s],d.__m):m??"";if(":"===N){const s=t.slice(1);"SELECT"===e.tagName&&l.has(s)?o.push(()=>g(e,s,S,a)):g(e,s,S,a)}else n||y(e,t,String(S))}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)v(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),u&&((e,t)=>{const s=d(e),n=m(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.ASTType.Element:{const s=this.createElement(e,t);u(s,e),f(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.ASTType.Text:return this.createText(e,n);case s.ASTType.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,v;const m=this.currentKey(),y=this.findEntry(m);let g;if(1!==e.s)if(y){g=y.node;let t=[];e.d&&(e.t===s.ASTType.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.ASTType.Element:g=this.createElement(e,t),u(g,e),f(g,e);const o=this.applyAttrs(g,e.a??[],n);t.appendChild(g),this.registerNode(m,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.ASTType.Text:g=this.createText(e,n),t.appendChild(g),this.registerNode(m,e,g,n);break;case s.ASTType.Comment:g=this.createComment(e,n),t.appendChild(g),this.registerNode(m,e,g,n);break;case s.ASTType.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.ASTType.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.ASTType.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.IS_DEV&&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.IS_DEV&&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==(v=o.parentNode)||v.insertBefore(e,o)}break}}break}}else y?g=y.node:(g=this.handleStaticSubtree(e,m,t,n),this.registerNode(m,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()}}exports.IRRenderer=N,exports.createRender=(e,t,s={})=>{const n=new N(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../types/ast.cjs"),t=require("../../shared/templateError.cjs"),s=require("../../shared/env.cjs"),n=require("./html-decode.cjs"),i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]),c=new WeakMap;function p(e){let t=c.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},c.set(e,t)),t}function l(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function d(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?u(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const f=e=>!(!e||0===e.length||/\s/.test(e)&&(s.IS_DEV&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function u(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.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 m(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function v(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void m(e,t,s);const o=e,h=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"!==h&&"TEXTAREA"!==h||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?m(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 y{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;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,n,i){const o=this.ir.fns[e-1];if(s.IS_DEV)try{return o?o.apply(this.scope,n):""}catch(r){return t.showTemplateError(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}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):n.default(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=c.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=p(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let c;r.loops=s;let l,d=!1,y=!1;for(const p of t){const{k:t,f:f,d:u,v:g}=p;if(":class"===t){c=this.evalIR(f??-1,[s],p.__m),d=!0;continue}if(":style"===t){l=this.evalIR(f??-1,[s],p.__m),y=!0;continue}if("class"===t||"style"===t)continue;const N=t[0];if("@"===N){const s=t.slice(1),i=p.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(f??-1,[e,r.loops],p.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],p.__m));continue}if("ref"===t&&g){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[g]=e;continue}const S=u?this.evalIR(f??-1,[s],p.__m):g??"";if(":"===N){const s=t.slice(1);"SELECT"===e.tagName&&h.has(s)?o.push(()=>v(e,s,S,a)):v(e,s,S,a)}else n||m(e,t,String(S))}return d&&((e,t)=>{const s=p(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)f(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,c),y&&((e,t)=>{const s=p(e),n=u(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,l),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(t,s,n){switch(t.t){case e.ASTType.Element:{const e=this.createElement(t,s);l(e,t),d(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.ASTType.Text:return this.createText(t,n);case e.ASTType.Comment:return this.createComment(t,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(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.ASTType.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.ASTType.Element:a=this.createElement(t,n),l(a,t),d(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.ASTType.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.ASTType.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.ASTType.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.ASTType.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.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=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),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=t,this.kaDepth++,s.IS_DEV&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const c=t+".0";if(this.prevNodeMap.get(c))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=h}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}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),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(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.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()}}exports.IRRenderer=y,exports.createRender=(e,t,s={})=>{const n=new y(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
@@ -1 +1 @@
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
+ import{ASTType as e}from"../../types/ast.js";import{showTemplateError as t}from"../../shared/templateError.js";import{IS_DEV as s}from"../../shared/env.js";import n from"./html-decode.js";const i=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g,o={xml:"http://www.w3.org/XML/1998/namespace",xlink:"http://www.w3.org/1999/xlink",xmlns:"http://www.w3.org/2000/xmlns/"},r={readonly:"readOnly",for:"htmlFor",tabindex:"tabIndex",contenteditable:"contentEditable",maxlength:"maxLength"},a=new Set(["data-","aria-","role","form"]),h=new Set(["value","selectedIndex"]),c=new WeakMap;function l(e){let t=c.get(e);return t||(t={loops:null,events:Object.create(null),prevClassObj:void 0,prevStyleObj:void 0},c.set(e,t)),t}function p(e,t){const s=t.a?.find(e=>"class"===e.k&&!e.d);s?.v&&e.setAttribute("class",s.v)}function d(e,t){if(!e.style)return;const s=t.a?.find(e=>"style"===e.k&&!e.d),n=s?u(s.v):{};for(const i in n){const t=n[i];i.startsWith("--")?e.style.setProperty(i,t):e.style[i]=t}}const f=e=>!(!e||0===e.length||/\s/.test(e)&&(s&&console.warn(`[Solely] Invalid class name "${e}" contains whitespace, will be ignored`),1));function u(e){const t={},s=[[e]];for(;s.length;){const[e,n]=s.pop()||[];if(e){if("string"==typeof e){let s;for(i.lastIndex=0;null!==(s=i.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 m(e,t,s){const n=null==s?"":String(s),i=t.indexOf(":");if(i>0){const s=t.slice(0,i),r=o[s];if(r)return void(e.getAttributeNS(r,t)!==n&&e.setAttributeNS(r,t,n))}e.getAttribute(t)!==n&&e.setAttribute(t,n)}function v(e,t,s,n){const i=r[t]||t;if(t.startsWith("data-")||t.startsWith("aria-")||a.has(t))return void m(e,t,s);const o=e,h=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"!==h&&"TEXTAREA"!==h||o.value!==s)if("boolean"!=typeof s)(n??(e instanceof SVGElement||void 0!==o.ownerSVGElement))&&!r[t]?m(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 y{constructor(e,t,s={}){this.ir=e,this.container=t,this.scope=s}ir;container;scope;nodeMap=new Map;prevNodeMap=new Map;pathStack=[];pathKey="";staticSubtreeCache=new Map;keepaliveCache=new Map;currentKaKey=null;kaDepth=0;isKaRestoring=!1;rafIds=new Set;keepaliveAccessCounter=0;maxKeepalive=20;renderedKaKeys=new Set;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,n,i){const o=this.ir.fns[e-1];if(s)try{return o?o.apply(this.scope,n):""}catch(r){return t(r.message||r.toString(),this.ir.m?.src||"",i,this.scope.tagName),""}return o?o.apply(this.scope,n):""}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):n(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=c.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=l(e),a=e instanceof SVGElement||void 0!==e.ownerSVGElement;let c;r.loops=s;let p,d=!1,y=!1;for(const l of t){const{k:t,f:f,d:u,v:g}=l;if(":class"===t){c=this.evalIR(f??-1,[s],l.__m),d=!0;continue}if(":style"===t){p=this.evalIR(f??-1,[s],l.__m),y=!0;continue}if("class"===t||"style"===t)continue;const N=t[0];if("@"===N){const s=t.slice(1),i=l.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(f??-1,[e,r.loops],l.__m);o[i].push(e)}continue}if("mounted"===t){n||i||this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],l.__m));continue}if("activated"===t){i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],l.__m));continue}if("deactivated"===t)continue;if("updated"===t){n&&!i&&this.scheduleRaf(()=>this.evalIR(f??-1,[e,s],l.__m));continue}if("ref"===t&&g){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[g]=e;continue}const k=u?this.evalIR(f??-1,[s],l.__m):g??"";if(":"===N){const s=t.slice(1);"SELECT"===e.tagName&&h.has(s)?o.push(()=>v(e,s,k,a)):v(e,s,k,a)}else n||m(e,t,String(k))}return d&&((e,t)=>{const s=l(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)f(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,c),y&&((e,t)=>{const s=l(e),n=u(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,p),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(t,s,n){switch(t.t){case e.Element:{const e=this.createElement(t,s);p(e,t),d(e,t);const i=this.applyAttrs(e,t.a??[],n);return t.c?.forEach(t=>{const s=this.createStaticSubtree(t,e,n);e.appendChild(s)}),i.forEach(e=>e()),e}case e.Text:return this.createText(t,n);case e.Comment:return this.createComment(t,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(t,n,i){const o=this.currentKey(),r=this.findEntry(o);let a;if(1!==t.s)if(r){a=r.node;let s=[];t.d&&(t.t===e.Element?s=this.applyAttrs(a,t.a??[],i,!0,this.isKaRestoring):this.updateNode(a,t,i)),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),s.forEach(e=>e())}else switch(t.t){case e.Element:a=this.createElement(t,n),p(a,t),d(a,t);const r=this.applyAttrs(a,t.a??[],i);n.appendChild(a),this.registerNode(o,t,a,i),t.c?.forEach((e,t)=>{this.pushPath(t),this.processNode(e,a,i),this.popPath()}),r.forEach(e=>e());break;case e.Text:a=this.createText(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.Comment:a=this.createComment(t,i),n.appendChild(a),this.registerNode(o,t,a,i);break;case e.For:{this.pushPath(-1);const s=this.currentKey();this.popPath();let o=this.findEntry(s)?.node;o||(o=document.createComment("for"),n.appendChild(o),this.registerNode(s,{t:e.Comment},o,i));const r=this.evalIR(t.f??-1,[i],t.__m)||[],a=document.createDocumentFragment();r.forEach((e,s)=>{const n=[...i,{itmVal:e,idxVal:s}];t.c?.forEach((e,t)=>{this.pushPath(s),this.pushPath(t),this.processNode(e,a,n),this.popPath(),this.popPath()})}),o.parentNode?.insertBefore(a,o);break}case e.Conditional:{this.pushPath(-1);const e=this.currentKey();this.popPath();let o=this.findEntry(e)?.node;o||(o=document.createComment("if"),n.appendChild(o),this.registerNode(e,{},o,i));for(let r=0;r<(t.b||[]).length;r++){const e=t.b?.[r];if(null===e.f||this.evalIR(e.f,[i],e.__m)){this.pushPath(r);const t=this.currentKey();if(this.popPath(),1===e.ka){this.renderedKaKeys.add(t);const a=this.keepaliveCache.get(t);if(a&&!a.active){o.parentNode?.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=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly."),e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),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=t,this.kaDepth++,s&&this.kaDepth>1&&console.warn("[Solely] Nested keepalive is not supported. Inner keepalive branches may not cache correctly.");const c=t+".0";if(this.prevNodeMap.get(c))e.c.forEach((e,t)=>{this.pushPath(r),this.pushPath(t),this.processNode(e,n,i),this.popPath(),this.popPath()});else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}this.kaDepth--,this.currentKaKey=h}}else{const t=document.createDocumentFragment();e.c.forEach((e,s)=>{this.pushPath(r),this.pushPath(s),this.processNode(e,t,i),this.popPath(),this.popPath()}),o.parentNode?.insertBefore(t,o)}break}}break}}else r?a=r.node:(a=this.handleStaticSubtree(t,o,n,i),this.registerNode(o,t,a,i))}evictKeepaliveIfNeeded(){let e=0;for(const[,n]of this.keepaliveCache.entries())n.active||e++;if(e<=this.maxKeepalive)return;let t=null,s=1/0;for(const[n,i]of this.keepaliveCache.entries())i.active||i.lastUsed<s&&(s=i.lastUsed,t=n);if(t){const e=this.keepaliveCache.get(t);for(const[,t]of e.entries){if(this.removeEventListenersFromNode(t.node),t.irNode.a){const e=t.irNode.a.find(e=>"unmounted"===e.k);e&&this.scheduleRaf(()=>{this.evalIR(e.f??-1,[t.node,t.loops],e.__m)})}t.node?.remove()}this.keepaliveCache.delete(t)}}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),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(){this.rafIds.forEach(e=>cancelAnimationFrame(e)),this.rafIds.clear();const e=e=>{for(const[,t]of e.entries())this.removeEventListenersFromNode(t.node)};e(this.nodeMap),e(this.prevNodeMap);for(const[,t]of this.keepaliveCache.entries())for(const[,e]of t.entries){if(this.removeEventListenersFromNode(e.node),e.irNode.a){const t=e.irNode.a.find(e=>"unmounted"===e.k);t&&this.evalIR(t.f??-1,[e.node,e.loops],t.__m)}e.node?.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 g=(e,t,s={})=>{const n=new y(e,t,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};export{y as IRRenderer,g 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,exports.SOLELY_VERSION="0.5.8";
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=(()=>{if("undefined"!=typeof window){if(window.location?.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(window.location?.hostname||""))})(),o=!e;exports.IS_DEV=e,exports.IS_PROD=o,exports.SOLELY_VERSION="0.6.0";
@@ -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,i="0.5.8";export{n as IS_DEV,o as IS_PROD,i as SOLELY_VERSION};
1
+ const n=(()=>{if("undefined"!=typeof window){if(window.location?.search.includes("debug"))return!0;const n=globalThis;if(!0===n.__DEBUG__||!0===n.__IS_DEV__)return!0}return!("undefined"==typeof window||!["localhost","127.0.0.1","0.0.0.0"].includes(window.location?.hostname||""))})(),o=!n,e="0.6.0";export{n as IS_DEV,o as IS_PROD,e as SOLELY_VERSION};
@@ -1,5 +1,5 @@
1
1
  /** 函数创建器类型 */
2
- export type FunctionCreator<TArgs extends any[], TReturn> = (...args: TArgs) => TReturn;
2
+ export type FunctionCreator<TArgs extends unknown[], TReturn> = (...args: TArgs) => TReturn;
3
3
  export declare function isCSPBlocked(): boolean;
4
4
  /**
5
5
  * 创建函数
@@ -7,4 +7,4 @@ export declare function isCSPBlocked(): boolean;
7
7
  * @param args 参数列表,最后一个元素是函数体
8
8
  * @returns 创建的函数
9
9
  */
10
- export declare function createFunction<TArgs extends any[]>(args: string[]): FunctionCreator<TArgs, any>;
10
+ export declare function createFunction<TArgs extends unknown[]>(args: string[]): FunctionCreator<TArgs, any>;
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./functions.cjs"),r=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;exports.genFunction=function(t,o,s){if(!(null==t?void 0:t.trim()))return()=>"";const{processed:i,error:l}=function(e,t){if(!(null==e?void 0:e.trim()))return{processed:""};if(r.test(e))return{processed:e,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===t)try{return{processed:e.replace(n,(e,r)=>`\${${r.trim()}}`)}}catch(o){return{processed:e,error:`Template parse error: ${o instanceof Error?o.message:String(o)}`}}return{processed:e}}(t,o);if(l)return function(){throw new Error(`[Compile Error] ${l} Original: ${t}`)};try{const r=function(e,r){switch(r){case"template":return`return \`${e}\`;`;case"expression":return`return (${e});`;case"handler":case"lifecycle":return(n=e).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(i,o),{loopValues:n,loopIndices:t}=function(e){return e.length?{loopValues:`var [${e.map(e=>e.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${e.map(e=>e.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),l=function(e,r,n,t){const o="lifecycle"===e?["el","loops"]:"handler"===e?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===e?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${t}\n ${r}\n `.replace(/^\s+|\s+$/gm,"");return o.push(s),o}(o,r,n,t);return e.createFunction(l)}catch(c){const e=c instanceof Error?c.message:String(c);return function(){throw new Error(`[Parse Error] ${e} Original: ${t}`)}}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./functions.cjs"),r=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;exports.genFunction=function(t,o,s){if(!t?.trim())return()=>"";const{processed:c,error:i}=function(e,t){if(!e?.trim())return{processed:""};if(r.test(e))return{processed:e,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===t)try{return{processed:e.replace(n,(e,r)=>`\${${r.trim()}}`)}}catch(o){return{processed:e,error:`Template parse error: ${o instanceof Error?o.message:String(o)}`}}return{processed:e}}(t,o);if(i)return function(){throw new Error(`[Compile Error] ${i} Original: ${t}`)};try{const r=function(e,r){switch(r){case"template":return`return \`${e}\`;`;case"expression":return`return (${e});`;case"handler":case"lifecycle":return(n=e).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(c,o),{loopValues:n,loopIndices:t}=function(e){return e.length?{loopValues:`var [${e.map(e=>e.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${e.map(e=>e.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),i=function(e,r,n,t){const o="lifecycle"===e?["el","loops"]:"handler"===e?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===e?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${t}\n ${r}\n `.replace(/^\s+|\s+$/gm,"");return o.push(s),o}(o,r,n,t);return e.createFunction(i)}catch(a){const e=a instanceof Error?a.message:String(a);return function(){throw new Error(`[Parse Error] ${e} Original: ${t}`)}}};
@@ -1 +1 @@
1
- import{createFunction as r}from"./functions.js";const e=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;function t(t,o,s){if(!(null==t?void 0:t.trim()))return()=>"";const{processed:l,error:i}=function(r,t){if(!(null==r?void 0:r.trim()))return{processed:""};if(e.test(r))return{processed:r,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===t)try{return{processed:r.replace(n,(r,e)=>`\${${e.trim()}}`)}}catch(o){return{processed:r,error:`Template parse error: ${o instanceof Error?o.message:String(o)}`}}return{processed:r}}(t,o);if(i)return function(){throw new Error(`[Compile Error] ${i} Original: ${t}`)};try{const e=function(r,e){switch(e){case"template":return`return \`${r}\`;`;case"expression":return`return (${r});`;case"handler":case"lifecycle":return(n=r).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(l,o),{loopValues:n,loopIndices:t}=function(r){return r.length?{loopValues:`var [${r.map(r=>r.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${r.map(r=>r.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),i=function(r,e,n,t){const o="lifecycle"===r?["el","loops"]:"handler"===r?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===r?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${t}\n ${e}\n `.replace(/^\s+|\s+$/gm,"");return o.push(s),o}(o,e,n,t);return r(i)}catch(a){const r=a instanceof Error?a.message:String(a);return function(){throw new Error(`[Parse Error] ${r} Original: ${t}`)}}}export{t as genFunction};
1
+ import{createFunction as r}from"./functions.js";const e=/\{\{\{\s*[\s\S]*?\s*\}\}\}/,n=/\{\{\s*([\s\S]*?)\s*\}\}/g;function t(t,o,s){if(!t?.trim())return()=>"";const{processed:i,error:a}=function(r,t){if(!r?.trim())return{processed:""};if(e.test(r))return{processed:r,error:"Illegal interpolation syntax: use {{ }} instead of {{{ }}}"};if("template"===t)try{return{processed:r.replace(n,(r,e)=>`\${${e.trim()}}`)}}catch(o){return{processed:r,error:`Template parse error: ${o instanceof Error?o.message:String(o)}`}}return{processed:r}}(t,o);if(a)return function(){throw new Error(`[Compile Error] ${a} Original: ${t}`)};try{const e=function(r,e){switch(e){case"template":return`return \`${r}\`;`;case"expression":return`return (${r});`;case"handler":case"lifecycle":return(n=r).endsWith(";")?n:n+";";default:return"return undefined;"}var n}(i,o),{loopValues:n,loopIndices:t}=function(r){return r.length?{loopValues:`var [${r.map(r=>r.i).join(", ")}] = loops.map(l => l.itmVal);`,loopIndices:`var [${r.map(r=>r.x).join(", ")}] = loops.map(l => l.idxVal);`}:{loopValues:"",loopIndices:""}}(s),a=function(r,e,n,t){const o="lifecycle"===r?["el","loops"]:"handler"===r?["event","loops"]:["loops"],s=`\n const { $data } = this;\n ${"handler"===r?"const { value, checked } = event?.target || {};":""}\n ${n}\n ${t}\n ${e}\n `.replace(/^\s+|\s+$/gm,"");return o.push(s),o}(o,e,n,t);return r(a)}catch(c){const r=c instanceof Error?c.message:String(c);return function(){throw new Error(`[Parse Error] ${r} Original: ${t}`)}}}export{t as genFunction};
@@ -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.SOLELY_VERSION=i.SOLELY_VERSION,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"),i=require("./url.cjs"),c=require("./env.cjs"),n=require("./case-convert.cjs"),a=require("./svg-sanitize.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=i.parseHashUrl,exports.IS_DEV=c.IS_DEV,exports.IS_PROD=c.IS_PROD,exports.SOLELY_VERSION=c.SOLELY_VERSION,exports.camelToKebab=n.camelToKebab,exports.sanitizeSvg=a.sanitizeSvg;
@@ -6,3 +6,4 @@ export * from './is-object';
6
6
  export * from './url';
7
7
  export * from './env';
8
8
  export * from './case-convert';
9
+ export * from './svg-sanitize';
@@ -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,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
+ import{showTemplateError as r}from"./templateError.js";import{genFunction as o}from"./gen-function.js";import{createFunction as t,isCSPBlocked as s}from"./functions.js";import{default as m}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";import{sanitizeSvg as a}from"./svg-sanitize.js";export{f as IS_DEV,n as IS_PROD,p as SOLELY_VERSION,j as camelToKebab,t as createFunction,o as genFunction,s as isCSPBlocked,e as isObject,m as listeners,i as parseHashUrl,a as sanitizeSvg,r as showTemplateError};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./env.cjs"),t=new Set(["svg","g","defs","symbol","use","switch","view","metadata","title","desc","style","a","path","rect","circle","ellipse","line","polyline","polygon","text","tspan","textpath","image","lineargradient","radialgradient","stop","pattern","solidcolor","clippath","mask","marker","filter","feblend","fecolormatrix","fecomponenttransfer","fecomposite","feconvolvematrix","fediffuselighting","fedisplacementmap","fedistantlight","fedropshadow","feflood","fefunca","fefuncb","fefuncg","fefuncr","fegaussianblur","feimage","femerge","femergenode","femorphology","feoffset","fepointlight","fespecularlighting","fespotlight","fetile","feturbulence","animate","animatemotion","animatetransform","set","mpath","discard"]),r=new Set(["set","animate","animatetransform","animatemotion"]),n=/^\s*(?:javascript|vbscript)\s*:/i,o=/^\s*data:(?!image\/)/i,s=new Set(["href","xlink:href","src","action","formaction"]),a=["to","values","from","by"],i=new Map;function f(e){const t=e.replace(/[\s-]+/g,"");return n.test(t)||o.test(t)}function l(e){const t=(e.getAttribute("attributeName")||"").toLowerCase();return!!t&&(!!t.startsWith("on")||!!s.has(t)&&a.some(t=>{const r=e.getAttribute(t);return null!==r&&f(r)}))}function c(e){for(const n of Array.from(e.children)){const e=n.tagName.toLowerCase();t.has(e)?r.has(e)&&l(n)?n.remove():c(n):n.remove()}for(const t of Array.from(e.attributes)){const r=t.name.toLowerCase();(r.startsWith("on")||s.has(r)&&f(t.value))&&e.removeAttribute(t.name)}}exports.sanitizeSvg=function(t){if(!t)return"";if("undefined"==typeof DOMParser)return"";const r=i.get(t);if(void 0!==r)return r;const n=function(t){const r=`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,n=(new DOMParser).parseFromString(r,"image/svg+xml");if(!n.querySelector("parsererror"))return c(n.documentElement),n.documentElement.innerHTML;e.IS_DEV&&console.warn("[Solely Icon] SVG XML 解析失败,回退 HTML 容错解析");const o=(new DOMParser).parseFromString(r,"text/html"),s=o.body?.firstElementChild;return s?(c(s),s.innerHTML):""}(t);if(i.size>=500){const e=i.size-500+1,t=i.keys();for(let r=0;r<e;r++){const e=t.next().value;if(void 0===e)break;i.delete(e)}}return i.set(t,n),n};
@@ -0,0 +1,27 @@
1
+ /**
2
+ * SVG 内容消毒工具
3
+ *
4
+ * 背景:icon 组件通过 `innerHTML` 注入 SVG 内容,内容来源包括
5
+ * 开发者注册的图标(registerIcon)和远程加载的 SVG Sprite(loadIconSprite)。
6
+ * 后者可能来自第三方源,恶意 SVG 可携带 SMIL 事件属性(onbegin/onend)、
7
+ * <script>、<foreignObject>、javascript: 链接等 XSS 载荷。
8
+ *
9
+ * 注意:通过 innerHTML 注入的 <script> 不会执行,但 SVG 的 SMIL 动画
10
+ * 事件属性(如 <animate onbegin="...">)在现代浏览器中仍会触发,
11
+ * 因此必须在注入前消毒。
12
+ *
13
+ * 设计取舍:不引入 DOMPurify 等运行时依赖(本项目零运行时依赖是核心卖点),
14
+ * 采用 DOMParser + 手写规则,覆盖:
15
+ * - 元素白名单:仅保留合法 SVG 元素,其余(script / foreignObject / HTML /
16
+ * MathML / 未知命名空间)一律移除
17
+ * - on* 事件属性(含 SMIL 的 onbegin/onend/onrepeat)
18
+ * - 危险协议 URL:javascript: / vbscript: / data:text/html
19
+ * - SMIL 动画写属性载荷:<set>/<animate> 等通过 attributeName 在运行时
20
+ * 写入 on*(无条件拦截)或 URL 属性(值携带危险协议时拦截)
21
+ */
22
+ /**
23
+ * 消毒 SVG 字符串,移除可执行载荷
24
+ * @param svg 原始 SVG 内容
25
+ * @returns 消毒后的 SVG 字符串;解析失败或环境无 DOMParser 时返回空串(安全兜底)
26
+ */
27
+ export declare function sanitizeSvg(svg: string): string;
@@ -0,0 +1 @@
1
+ import{IS_DEV as e}from"./env.js";const t=new Set(["svg","g","defs","symbol","use","switch","view","metadata","title","desc","style","a","path","rect","circle","ellipse","line","polyline","polygon","text","tspan","textpath","image","lineargradient","radialgradient","stop","pattern","solidcolor","clippath","mask","marker","filter","feblend","fecolormatrix","fecomponenttransfer","fecomposite","feconvolvematrix","fediffuselighting","fedisplacementmap","fedistantlight","fedropshadow","feflood","fefunca","fefuncb","fefuncg","fefuncr","fegaussianblur","feimage","femerge","femergenode","femorphology","feoffset","fepointlight","fespecularlighting","fespotlight","fetile","feturbulence","animate","animatemotion","animatetransform","set","mpath","discard"]),r=new Set(["set","animate","animatetransform","animatemotion"]),n=/^\s*(?:javascript|vbscript)\s*:/i,o=/^\s*data:(?!image\/)/i,a=new Set(["href","xlink:href","src","action","formaction"]),s=["to","values","from","by"],i=new Map;function f(e){const t=e.replace(/[\s-]+/g,"");return n.test(t)||o.test(t)}function l(e){const t=(e.getAttribute("attributeName")||"").toLowerCase();return!!t&&(!!t.startsWith("on")||!!a.has(t)&&s.some(t=>{const r=e.getAttribute(t);return null!==r&&f(r)}))}function m(t){if(!t)return"";if("undefined"==typeof DOMParser)return"";const r=i.get(t);if(void 0!==r)return r;const n=function(t){const r=`<svg xmlns="http://www.w3.org/2000/svg">${t}</svg>`,n=(new DOMParser).parseFromString(r,"image/svg+xml");if(!n.querySelector("parsererror"))return c(n.documentElement),n.documentElement.innerHTML;e&&console.warn("[Solely Icon] SVG XML 解析失败,回退 HTML 容错解析");const o=(new DOMParser).parseFromString(r,"text/html"),a=o.body?.firstElementChild;return a?(c(a),a.innerHTML):""}(t);if(i.size>=500){const e=i.size-500+1,t=i.keys();for(let r=0;r<e;r++){const e=t.next().value;if(void 0===e)break;i.delete(e)}}return i.set(t,n),n}function c(e){for(const n of Array.from(e.children)){const e=n.tagName.toLowerCase();t.has(e)?r.has(e)&&l(n)?n.remove():c(n):n.remove()}for(const t of Array.from(e.attributes)){const r=t.name.toLowerCase();(r.startsWith("on")||a.has(r)&&f(t.value))&&e.removeAttribute(t.name)}}export{m as sanitizeSvg};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o="#858585",n="#3c1e1e",e="#f8f8f2",t="#ff6b6b",l="#ff6b6b",c="#ffffff",r="#a0a0a0",i="#5ddcff";function s(o){let n=0;for(let e=0;e<o.length;){const t=o.codePointAt(e)??0;"\t"!==o[e]?(n+=t>=9472&&t<=9599||t>255?2:1,e+=t>65535?2:1):(n+=4,e++)}return n}function f(o,n={}){const{lineIndex:e=0,totalLines:t=1}=n,l=Math.max(1,Math.floor(o));return(t<=1||0===e?"^":"~").repeat(l)}exports.showTemplateError=function(a,d="",p,$="component"){var g;const h=`%c[Solely]%c Template Error in <${$}> → ${(null==a?void 0:a.message)??String(a)}`,u=[`color:${c};background:${l};padding:4px 10px;border-radius:6px;font-weight:bold;`,`color:${t};font-weight:bold;`];if(!d||!(null==p?void 0:p.loc)||p.loc.length<2)return console.error(h,...u),void((null==p?void 0:p.expr)&&console.info(`Expression: ${p.expr.trim()}`));const x=p.loc;let m=x[0]||0,b=x[1]||0;m|=0,b|=0,m<1&&(m=1),b<1&&(b=1);const S=d.split("\n");if(m>S.length)return void console.error(`[Solely] 行号 ${m} 超出范围`);const v=m-1,M=Math.max(0,v-3),w=Math.min(S.length-1,v+3),E=String(w+1).length,y=(null==(g=p.expr)?void 0:g.trim())??"",L=y?y.split("\n"):[],T=y?Math.max(...L.map(s)):0,k=L.length>1,C=`color:${o};`,I=`color:${t};font-weight:bold;`,P=`color:${o};`,j=`color:${e};background:${n};padding:0 4px;`,A=`color:${o};`,O=`color:${t};font-weight:bold;padding:0 4px;`;console.groupCollapsed(`${h} %c(Line:${m}, Col:${b})`,...u,`color:${o};font-weight:normal;`);for(let o=M;o<=w;o++){const n=S[o],e=String(o+1).padStart(E," ");if(o!==v){console.info(`%c${e} │%c ${n}`,C,P);continue}const t=s(n.slice(0,Math.max(0,b-1))),l=" ".repeat(E+3),c=e.padEnd(E," ");if(console.info(`%c${c} │%c ${n}`,I,j),k)for(let o=0;o<L.length;o++){const n=L[o],e=v+o;let c=0;if(0===o)c=t;else if(e<S.length){const o=S[e],n=o.search(/\S/);c=s(-1===n?o:o.slice(0,n))}const r=f(Math.max(1,s(n.trim())),{lineIndex:o,totalLines:L.length}),i=l+" ".repeat(c);if(0===o)console.info(`%c${i}%c${r}`,A,O);else if(e<S.length){const o=String(e+1).padEnd(E," "),n=S[e];console.info(`%c${o} │%c ${n}`,I,j),console.info(`%c${i}%c${r}`,A,O)}}else{const o=l+" ".repeat(t),n=f(T||1);console.info(`%c${o}%c${n}`,A,O)}}y&&console.info(`%cExpression:%c ${y}`,`color:${r};font-weight:bold;`,`color:${i};font-family:monospace;`),console.groupEnd()};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const o="#858585",n="#3c1e1e",e="#f8f8f2",t="#ff6b6b",c="#ff6b6b",l="#ffffff",r="#a0a0a0",i="#5ddcff";function s(o){let n=0;for(let e=0;e<o.length;){const t=o.codePointAt(e)??0;"\t"!==o[e]?(n+=t>=9472&&t<=9599||t>255?2:1,e+=t>65535?2:1):(n+=4,e++)}return n}function f(o,n={}){const{lineIndex:e=0,totalLines:t=1}=n,c=Math.max(1,Math.floor(o));return(t<=1||0===e?"^":"~").repeat(c)}exports.showTemplateError=function(a,p="",$,d="component"){const g=`%c[Solely]%c Template Error in <${d}> → ${a?.message??String(a)}`,h=[`color:${l};background:${c};padding:4px 10px;border-radius:6px;font-weight:bold;`,`color:${t};font-weight:bold;`];if(!p||!$?.loc||$.loc.length<2)return console.error(g,...h),void($?.expr&&console.info(`Expression: ${$.expr.trim()}`));const x=$.loc;let m=x[0]||0,u=x[1]||0;m|=0,u|=0,m<1&&(m=1),u<1&&(u=1);const b=p.split("\n");if(m>b.length)return void console.error(`[Solely] 行号 ${m} 超出范围`);const S=m-1,M=Math.max(0,S-3),w=Math.min(b.length-1,S+3),E=String(w+1).length,y=$.expr?.trim()??"",v=y?y.split("\n"):[],L=y?Math.max(...v.map(s)):0,T=v.length>1,k=`color:${o};`,C=`color:${t};font-weight:bold;`,I=`color:${o};`,P=`color:${e};background:${n};padding:0 4px;`,j=`color:${o};`,A=`color:${t};font-weight:bold;padding:0 4px;`;console.groupCollapsed(`${g} %c(Line:${m}, Col:${u})`,...h,`color:${o};font-weight:normal;`);for(let o=M;o<=w;o++){const n=b[o],e=String(o+1).padStart(E," ");if(o!==S){console.info(`%c${e} │%c ${n}`,k,I);continue}const t=s(n.slice(0,Math.max(0,u-1))),c=" ".repeat(E+3),l=e.padEnd(E," ");if(console.info(`%c${l} │%c ${n}`,C,P),T)for(let o=0;o<v.length;o++){const n=v[o],e=S+o;let l=0;if(0===o)l=t;else if(e<b.length){const o=b[e],n=o.search(/\S/);l=s(-1===n?o:o.slice(0,n))}const r=f(Math.max(1,s(n.trim())),{lineIndex:o,totalLines:v.length}),i=c+" ".repeat(l);if(0===o)console.info(`%c${i}%c${r}`,j,A);else if(e<b.length){const o=String(e+1).padEnd(E," "),n=b[e];console.info(`%c${o} │%c ${n}`,C,P),console.info(`%c${i}%c${r}`,j,A)}}else{const o=c+" ".repeat(t),n=f(L||1);console.info(`%c${o}%c${n}`,j,A)}}y&&console.info(`%cExpression:%c ${y}`,`color:${r};font-weight:bold;`,`color:${i};font-family:monospace;`),console.groupEnd()};
@@ -1 +1 @@
1
- const o="#858585",n="#3c1e1e",e="#f8f8f2",t="#ff6b6b",l="#ff6b6b",c="#ffffff",r="#a0a0a0",i="#5ddcff";function f(o){let n=0;for(let e=0;e<o.length;){const t=o.codePointAt(e)??0;"\t"!==o[e]?(n+=t>=9472&&t<=9599||t>255?2:1,e+=t>65535?2:1):(n+=4,e++)}return n}function s(o,n={}){const{lineIndex:e=0,totalLines:t=1}=n,l=Math.max(1,Math.floor(o));return(t<=1||0===e?"^":"~").repeat(l)}function a(a,d="",$,p="component"){var g;const h=`%c[Solely]%c Template Error in <${p}> → ${(null==a?void 0:a.message)??String(a)}`,x=[`color:${c};background:${l};padding:4px 10px;border-radius:6px;font-weight:bold;`,`color:${t};font-weight:bold;`];if(!d||!(null==$?void 0:$.loc)||$.loc.length<2)return console.error(h,...x),void((null==$?void 0:$.expr)&&console.info(`Expression: ${$.expr.trim()}`));const u=$.loc;let m=u[0]||0,b=u[1]||0;m|=0,b|=0,m<1&&(m=1),b<1&&(b=1);const S=d.split("\n");if(m>S.length)return void console.error(`[Solely] 行号 ${m} 超出范围`);const v=m-1,M=Math.max(0,v-3),w=Math.min(S.length-1,v+3),E=String(w+1).length,y=(null==(g=$.expr)?void 0:g.trim())??"",L=y?y.split("\n"):[],k=y?Math.max(...L.map(f)):0,C=L.length>1,I=`color:${o};`,A=`color:${t};font-weight:bold;`,P=`color:${o};`,T=`color:${e};background:${n};padding:0 4px;`,j=`color:${o};`,q=`color:${t};font-weight:bold;padding:0 4px;`;console.groupCollapsed(`${h} %c(Line:${m}, Col:${b})`,...x,`color:${o};font-weight:normal;`);for(let o=M;o<=w;o++){const n=S[o],e=String(o+1).padStart(E," ");if(o!==v){console.info(`%c${e} │%c ${n}`,I,P);continue}const t=f(n.slice(0,Math.max(0,b-1))),l=" ".repeat(E+3),c=e.padEnd(E," ");if(console.info(`%c${c} │%c ${n}`,A,T),C)for(let o=0;o<L.length;o++){const n=L[o],e=v+o;let c=0;if(0===o)c=t;else if(e<S.length){const o=S[e],n=o.search(/\S/);c=f(-1===n?o:o.slice(0,n))}const r=s(Math.max(1,f(n.trim())),{lineIndex:o,totalLines:L.length}),i=l+" ".repeat(c);if(0===o)console.info(`%c${i}%c${r}`,j,q);else if(e<S.length){const o=String(e+1).padEnd(E," "),n=S[e];console.info(`%c${o} │%c ${n}`,A,T),console.info(`%c${i}%c${r}`,j,q)}}else{const o=l+" ".repeat(t),n=s(k||1);console.info(`%c${o}%c${n}`,j,q)}}y&&console.info(`%cExpression:%c ${y}`,`color:${r};font-weight:bold;`,`color:${i};font-family:monospace;`),console.groupEnd()}export{a as showTemplateError};
1
+ const o="#858585",n="#3c1e1e",e="#f8f8f2",t="#ff6b6b",c="#ff6b6b",l="#ffffff",r="#a0a0a0",i="#5ddcff";function f(o){let n=0;for(let e=0;e<o.length;){const t=o.codePointAt(e)??0;"\t"!==o[e]?(n+=t>=9472&&t<=9599||t>255?2:1,e+=t>65535?2:1):(n+=4,e++)}return n}function s(o,n={}){const{lineIndex:e=0,totalLines:t=1}=n,c=Math.max(1,Math.floor(o));return(t<=1||0===e?"^":"~").repeat(c)}function a(a,$="",p,d="component"){const g=`%c[Solely]%c Template Error in <${d}> → ${a?.message??String(a)}`,h=[`color:${l};background:${c};padding:4px 10px;border-radius:6px;font-weight:bold;`,`color:${t};font-weight:bold;`];if(!$||!p?.loc||p.loc.length<2)return console.error(g,...h),void(p?.expr&&console.info(`Expression: ${p.expr.trim()}`));const x=p.loc;let m=x[0]||0,u=x[1]||0;m|=0,u|=0,m<1&&(m=1),u<1&&(u=1);const b=$.split("\n");if(m>b.length)return void console.error(`[Solely] 行号 ${m} 超出范围`);const S=m-1,M=Math.max(0,S-3),w=Math.min(b.length-1,S+3),E=String(w+1).length,y=p.expr?.trim()??"",L=y?y.split("\n"):[],k=y?Math.max(...L.map(f)):0,v=L.length>1,C=`color:${o};`,I=`color:${t};font-weight:bold;`,A=`color:${o};`,P=`color:${e};background:${n};padding:0 4px;`,T=`color:${o};`,j=`color:${t};font-weight:bold;padding:0 4px;`;console.groupCollapsed(`${g} %c(Line:${m}, Col:${u})`,...h,`color:${o};font-weight:normal;`);for(let o=M;o<=w;o++){const n=b[o],e=String(o+1).padStart(E," ");if(o!==S){console.info(`%c${e} │%c ${n}`,C,A);continue}const t=f(n.slice(0,Math.max(0,u-1))),c=" ".repeat(E+3),l=e.padEnd(E," ");if(console.info(`%c${l} │%c ${n}`,I,P),v)for(let o=0;o<L.length;o++){const n=L[o],e=S+o;let l=0;if(0===o)l=t;else if(e<b.length){const o=b[e],n=o.search(/\S/);l=f(-1===n?o:o.slice(0,n))}const r=s(Math.max(1,f(n.trim())),{lineIndex:o,totalLines:L.length}),i=c+" ".repeat(l);if(0===o)console.info(`%c${i}%c${r}`,T,j);else if(e<b.length){const o=String(e+1).padEnd(E," "),n=b[e];console.info(`%c${o} │%c ${n}`,I,P),console.info(`%c${i}%c${r}`,T,j)}}else{const o=c+" ".repeat(t),n=s(k||1);console.info(`%c${o}%c${n}`,T,j)}}y&&console.info(`%cExpression:%c ${y}`,`color:${r};font-weight:bold;`,`color:${i};font-family:monospace;`),console.groupEnd()}export{a as showTemplateError};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "solely",
3
3
  "private": false,
4
- "version": "0.5.8",
4
+ "version": "0.6.0",
5
5
  "description": "A lightweight TypeScript framework for building web components with compile-time optimizations",
6
6
  "type": "module",
7
7
  "sideEffects": [
@@ -200,7 +200,7 @@
200
200
  },
201
201
  "homepage": "https://github.com/solelyjs/solely#readme",
202
202
  "engines": {
203
- "node": ">=16.0.0"
203
+ "node": "^20.19.0 || >=22.12.0"
204
204
  },
205
205
  "scripts": {
206
206
  "dev": "vite",
@@ -215,8 +215,8 @@
215
215
  "test:ui": "vitest --ui",
216
216
  "test:coverage": "vitest --coverage",
217
217
  "typecheck": "tsc --noEmit",
218
- "lint": "eslint . --ext .ts,.tsx",
219
- "lint:fix": "eslint . --ext .ts,.tsx --fix",
218
+ "lint": "eslint .",
219
+ "lint:fix": "eslint . --fix",
220
220
  "format": "prettier --write \"src/**/*.{ts,tsx,js,json,md}\"",
221
221
  "format:check": "prettier --check \"src/**/*.{ts,tsx,js,json,md}\"",
222
222
  "clean": "rimraf dist",
@@ -230,18 +230,20 @@
230
230
  "magic-string": "^0.30.21"
231
231
  },
232
232
  "devDependencies": {
233
+ "@commitlint/cli": "^19.0.0",
234
+ "@commitlint/config-conventional": "^19.0.0",
235
+ "@eslint/js": "^9.39.4",
233
236
  "@rollup/plugin-strip": "^3.0.4",
234
237
  "@testing-library/dom": "^10.4.1",
235
238
  "@testing-library/user-event": "^14.6.1",
236
239
  "@types/node": "^22.10.2",
237
- "@commitlint/cli": "^19.0.0",
238
- "@commitlint/config-conventional": "^19.0.0",
239
- "@typescript-eslint/eslint-plugin": "^8.0.0",
240
- "@typescript-eslint/parser": "^8.0.0",
240
+ "@typescript-eslint/eslint-plugin": "^8.71.2",
241
+ "@typescript-eslint/parser": "^8.71.2",
241
242
  "@vitest/coverage-v8": "^3.2.4",
242
243
  "@vitest/ui": "^3.2.4",
243
244
  "cpx": "^1.5.0",
244
- "eslint": "^8.57.0",
245
+ "eslint": "^9.39.4",
246
+ "globals": "^16.5.0",
245
247
  "husky": "^9.0.0",
246
248
  "jsdom": "27.0.0",
247
249
  "lint-staged": "^15.0.0",
@@ -250,9 +252,9 @@
250
252
  "sass": "^1.83.0",
251
253
  "terser": "^5.44.0",
252
254
  "tsup": "^8.5.1",
253
- "typescript": "~5.6.2",
254
- "vite": "^5.4.10",
255
- "vite-plugin-dts": "^4.4.0",
255
+ "typescript": "^5.9.3",
256
+ "vite": "^7.3.7",
257
+ "vite-plugin-dts": "^4.5.4",
256
258
  "vitest": "^3.2.4"
257
259
  }
258
260
  }