solely 0.4.20 → 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 (46) 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/components/elements/select/index.cjs +1 -1
  7. package/dist/components/elements/select/index.d.ts +1 -5
  8. package/dist/components/elements/select/index.js +1 -1
  9. package/dist/index.cjs +1 -1
  10. package/dist/index.js +1 -1
  11. package/dist/plugins/solely-vite-plugin.cjs +1 -1
  12. package/dist/plugins/solely-vite-plugin.js +1 -1
  13. package/dist/runtime/component/base-element.cjs +1 -1
  14. package/dist/runtime/component/base-element.d.ts +6 -1
  15. package/dist/runtime/component/base-element.js +1 -1
  16. package/dist/runtime/component/decorators.cjs +1 -1
  17. package/dist/runtime/component/decorators.js +1 -1
  18. package/dist/runtime/index.cjs +1 -1
  19. package/dist/runtime/index.js +1 -1
  20. package/dist/runtime/reactivity/computed.cjs +1 -0
  21. package/dist/runtime/reactivity/computed.d.ts +36 -0
  22. package/dist/runtime/reactivity/computed.js +1 -0
  23. package/dist/runtime/reactivity/index.d.ts +6 -2
  24. package/dist/runtime/reactivity/observe.cjs +1 -1
  25. package/dist/runtime/reactivity/observe.d.ts +4 -32
  26. package/dist/runtime/reactivity/observe.js +1 -1
  27. package/dist/runtime/reactivity/watch.cjs +1 -0
  28. package/dist/runtime/reactivity/watch.d.ts +64 -0
  29. package/dist/runtime/reactivity/watch.js +1 -0
  30. package/dist/runtime/renderer/renderIR.cjs +1 -1
  31. package/dist/runtime/renderer/renderIR.d.ts +30 -20
  32. package/dist/runtime/renderer/renderIR.js +1 -1
  33. package/dist/shared/env.cjs +1 -1
  34. package/dist/shared/env.d.ts +2 -0
  35. package/dist/shared/env.js +1 -1
  36. package/dist/shared/index.cjs +1 -1
  37. package/dist/shared/index.js +1 -1
  38. package/dist/shared/is-object.d.ts +1 -1
  39. package/dist/types/ast.cjs +1 -1
  40. package/dist/types/ast.d.ts +1 -0
  41. package/dist/types/ast.js +1 -1
  42. package/dist/types/ir.d.ts +2 -0
  43. package/dist/types/lifecycle.cjs +1 -1
  44. package/dist/types/lifecycle.d.ts +1 -1
  45. package/dist/types/lifecycle.js +1 -1
  46. package/package.json +1 -1
@@ -1 +1 @@
1
- import n from"magic-string";import{parseHtml as e}from"../compiler/parser/parser.js";import{buildIR as o}from"../compiler/ir/buildIR.js";const r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function p(n,r="anonymous"){const p=e(n);return o(p,{filename:r,source:n})}function t(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function i(e,o,r){const p=new n(e),t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return p.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${t}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:p.toString(),map:p.generateMap({source:o,includeContent:!r})}}function l(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(e,r){if(!t(r,o.include)||t(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const t=p(e,r),i=function(e,o,r,p){const t=new n(o);t.remove(0,o.length),p||(t.append("\n// ============================================\n"),t.append("// Solely Precompiled Template\n"),t.append(`// Compiled at: ${(new Date).toISOString()}\n`),t.append("// ============================================\n\n")),t.append("const __SOLELY_IR__ = {\n"),t.append(" t: 'root',\n"),t.append(` v: '${e.v}',\n\n`),p||t.append(" // 编译后的函数数组\n"),t.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),i=o===e.fns.length-1;p||t.append(` // Function ${o+1}\n`),t.append(` ${r}${i?"":","}\n`)}),t.append(" ],\n\n");const i=n=>{const e={t:n.t,d:n.d};return void 0!==n.s&&(e.s=n.s),void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!p&&n.__m&&(e.__m={...n.__m}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r,...!p&&n.__m&&{__m:{...n.__m}}}))),n.c&&(e.c=n.c.map(i)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(i),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...!p&&n.__m&&{__m:{...n.__m}}}})),e},l=e.n.map(i);return p||t.append(" // IR 节点树\n"),t.append(` n: ${JSON.stringify(l,null,p?0:2)},\n\n`),p||t.append(" // 编译统计\n"),t.append(` s: ${JSON.stringify(e.s)},\n\n`),p||(t.append(" // 元数据\n"),t.append(` m: ${JSON.stringify(e.m)}\n`)),t.append("};\n\n"),p||t.append("// 导出 IR 对象\n"),t.append("export default __SOLELY_IR__;\n"),t.append("export { __SOLELY_IR__ };\n\n"),p||t.append("// 同时导出模板字符串(向后兼容)\n"),t.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:t.toString(),map:t.generateMap({source:r,includeContent:!p,hires:!p})}}(t,e,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",t.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const n=i(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(l){const n=`[Solely] Error processing ${r}: ${l instanceof Error?l.message:String(l)}`;console.error(n),console.warn(`[Solely] Falling back to raw template for: ${r}`);const p=i(e,r,!!o.minify);return{code:p.code,map:o.sourceMap?p.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(t(n,o.include)&&!t(n,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${n}`),e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=l);export{p as compileTemplate,l as solelyVitePlugin};
1
+ import n from"magic-string";import{parseHtml as e}from"../compiler/parser/parser.js";import{buildIR as o}from"../compiler/ir/buildIR.js";const r={precompile:!0,sourceMap:!0,minify:!1,include:[/\.html(?:\?|$)/],exclude:/node_modules/,debug:!1};function p(n,r="anonymous"){const p=e(n);return o(p,{filename:r,source:n})}function t(n,e){return(Array.isArray(e)?e:[e]).some(e=>"string"==typeof e?n.includes(e):e.test(n))}function i(e,o,r){const p=new n(e),t=e.replace(/\\/g,"\\\\").replace(/`/g,"\\`").replace(/\$/g,"\\$");return p.overwrite(0,e.length,`\nconst __SOLELY_TEMPLATE__ = \`${t}\`;\n\nexport default __SOLELY_TEMPLATE__;\nexport { __SOLELY_TEMPLATE__ };\n`),{code:p.toString(),map:p.generateMap({source:o,includeContent:!r})}}function a(e={}){const o={...r,...e};return{name:"solely-vite-plugin",enforce:"pre",configResolved(n){o.debug&&console.info("[Solely] Plugin initialized with options:",o)},transform(e,r){if(!t(r,o.include)||t(r,o.exclude))return null;if(!r.includes(".html?solely"))return null;try{if(o.debug&&console.info(`[Solely] Processing: ${r}`),o.precompile){const t=p(e,r),i=function(e,o,r,p){const t=new n(o);t.remove(0,o.length),p||(t.append("\n// ============================================\n"),t.append("// Solely Precompiled Template\n"),t.append(`// Compiled at: ${(new Date).toISOString()}\n`),t.append("// ============================================\n\n")),t.append("const __SOLELY_IR__ = {\n"),t.append(" t: 'root',\n"),t.append(` v: '${e.v}',\n\n`),p||t.append(" // 编译后的函数数组\n"),t.append(" fns: [\n"),e.fns.forEach((n,o)=>{const r="string"==typeof n?n:n.toString(),i=o===e.fns.length-1;p||t.append(` // Function ${o+1}\n`),t.append(` ${r}${i?"":","}\n`)}),t.append(" ],\n\n");const i=n=>{const e={t:n.t,d:n.d};return void 0!==n.s&&(e.s=n.s),void 0!==n.g&&(e.g=n.g),void 0!==n.x&&(e.x=n.x),void 0!==n.f&&(e.f=n.f),void 0!==n.i&&(e.i=n.i),void 0!==n.n&&(e.n=n.n),!p&&n.__m&&(e.__m={...n.__m}),n.a&&(e.a=n.a.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r,...!p&&n.__m&&{__m:{...n.__m}}}))),n.c&&(e.c=n.c.map(i)),n.b&&(e.b=n.b.map(n=>{var e;return{f:n.f,c:n.c.map(i),a:null==(e=n.a)?void 0:e.map(n=>({k:n.k,v:n.v,f:n.f,d:n.d,r:n.r})),...void 0!==n.ka&&{ka:n.ka},...!p&&n.__m&&{__m:{...n.__m}}}})),e},a=e.n.map(i);return p||t.append(" // IR 节点树\n"),t.append(` n: ${JSON.stringify(a,null,p?0:2)},\n\n`),p||t.append(" // 编译统计\n"),t.append(` s: ${JSON.stringify(e.s)},\n\n`),p||(t.append(" // 元数据\n"),t.append(` m: ${JSON.stringify(e.m)}\n`)),t.append("};\n\n"),p||t.append("// 导出 IR 对象\n"),t.append("export default __SOLELY_IR__;\n"),t.append("export { __SOLELY_IR__ };\n\n"),p||t.append("// 同时导出模板字符串(向后兼容)\n"),t.append("export const __SOLELY_TEMPLATE__ = '';\n"),{code:t.toString(),map:t.generateMap({source:r,includeContent:!p,hires:!p})}}(t,e,r,!!o.minify);return o.debug&&(console.info(`[Solely] Compiled IR for: ${r}`),console.info("[Solely] Stats:",t.s)),{code:i.code,map:o.sourceMap?i.map:null}}{const n=i(e,r,!!o.minify);return{code:n.code,map:o.sourceMap?n.map:null}}}catch(a){const n=`[Solely] Error processing ${r}: ${a instanceof Error?a.message:String(a)}`;console.error(n),console.warn(`[Solely] Falling back to raw template for: ${r}`);const p=i(e,r,!!o.minify);return{code:p.code,map:o.sourceMap?p.map:null}}},handleHotUpdate({file:n,server:e,modules:r}){if(t(n,o.include)&&!t(n,o.exclude))return o.debug&&console.info(`[Solely] HMR triggered for: ${n}`),e.ws.send({type:"full-reload",path:"*"}),r}}}"undefined"!=typeof window&&(window.__SOLELY_VITE_PLUGIN__=a);export{p as compileTemplate,a as solelyVitePlugin};
@@ -1 +1 @@
1
- "use strict";var t,e,s,i,a,n,o,r,h,c,l,u,d,p,f,b,m,y,v,w,g,M,S,O,k,$,j=Object.defineProperty,C=t=>{throw TypeError(t)},W=(t,e,s)=>e.has(t)||C("Cannot "+s),A=(t,e,s)=>(W(t,e,"read from private field"),s?s.call(t):e.get(t)),E=(t,e,s)=>e.has(t)?C("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),N=(t,e,s,i)=>(W(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),D=(t,e,s)=>(W(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const P=require("../../shared/is-object.cjs"),q=require("../../shared/env.cjs"),U=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),_=require("../renderer/renderIR.cjs"),x=Symbol.for("solely.manifest"),L=class y extends HTMLElement{constructor(p={}){var b,y;super(),E(this,f),((t,e,s)=>{e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(y="$refs")?y+"":y,{}),E(this,t),E(this,e),E(this,s),E(this,i),E(this,a),E(this,n),E(this,o,!1),E(this,r,!1),E(this,h,!1),E(this,c,!1),E(this,l,!1),E(this,u,!1),E(this,d,!1);const w=this.constructor;N(this,t,w[x]||{tagName:"base-element"});const g=A(this,t);N(this,a,(null==(b=g.shadowDOM)?void 0:b.use)?this.attachShadow({mode:g.shadowDOM.mode||"open"}):this),D(this,f,m).call(this,p),D(this,f,v).call(this,g),queueMicrotask(()=>D(this,f,$).call(this))}static get observedAttributes(){const t=this[x];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return A(this,i)}set $data(t){var e;P.isObject(t)||(t={}),t!==A(this,i)&&(null==(e=A(this,n))||e.call(this),D(this,f,m).call(this,t),D(this,f,g).call(this),D(this,f,S).call(this))}refresh(){D(this,f,S).call(this)}connectedCallback(){var i;N(this,l,!0);const n=A(this,t);if(D(this,f,$).call(this),(n.className||n.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),D(this,f,k).call(this),n.attributeMap&&P.isObject(this.$data)){D(this,f,g).call(this);for(const[t,e]of n.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=D(this,f,M).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}D(this,f,b).call(this),A(this,s)&&!A(this,e)&&N(this,e,_.createRender(A(this,s),A(this,a),this)),A(this,u)&&(N(this,u,!1),D(this,f,S).call(this)),this.mounted(),null==(i=this.onInit)||i.call(this)}disconnectedCallback(){var e,s;N(this,l,!1);const i=A(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${i.tagName}`,e=A(y,p).get(t)||0;e<=1?(null==(s=document.head.querySelector(`#${t}`))||s.remove(),A(y,p).delete(t)):A(y,p).set(t,e-1)}this.unmounted()}attributeChangedCallback(e,s,i){var a;if(s===i||!P.isObject(this.$data))return;const n=null==(a=A(this,t).attributeMap)?void 0:a.get(e);if(!n)return;const o=n.name,r=this.$data[o],c=D(this,f,M).call(this,i,n.default??r,n.type);this.$data[o]=c,N(this,h,!0),this.attributeChanged(e,r,c)}emit(t,e,s){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(q.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(q.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,n=new WeakMap,o=new WeakMap,r=new WeakMap,h=new WeakMap,c=new WeakMap,l=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakSet,b=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=new Set(["$data","$refs","constructor","onInit","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","refresh"]),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const n of t){if(s.has(n))continue;if(e.some(t=>n.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,n);if(!t||!("value"in t))continue;const a=t.value,o=i.get(n);(null==o?void 0:o.set)&&(delete this[n],this[n]=a)}},m=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,n=A(this,t),o=String(i),r=null==(s=n.propMap)?void 0:s.get(o);(null==r?void 0:r.reflect)&&D(this,f,y).call(this,r,a)}this.emit("dataChange",{...e}),D(this,f,S).call(this)});N(this,i,s),N(this,n,a)},y=function(t,e){const s=U.camelToKebab(t.name);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}},v=function(t){t.ir&&N(this,s,t.ir)},w=function(){const e=A(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;const e=Object.getOwnPropertyDescriptor(this.constructor.prototype,t.name);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},g=function(){A(this,d)||(N(this,d,!0),D(this,f,w).call(this))},M=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=t.replace(/'/g,'"'),i=JSON.parse(s);return Array.isArray(i)?i:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},S=function(){A(this,l)?!A(this,r)&&A(this,e)&&(N(this,r,!0),queueMicrotask(()=>{N(this,r,!1),D(this,f,O).call(this)})):N(this,u,!0)},O=function(){if(!A(this,o)&&A(this,l)){N(this,o,!0);try{A(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),A(this,e).update(),this.updated(),A(this,h)&&(this.afterAttributesUpdate(),N(this,h,!1))}finally{N(this,o,!1)}}},k=function(){var e;const s=A(this,t);if(!s.styles)return;const i=A(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return}const n=i instanceof ShadowRoot?i:document.head,o=`solely-style-${s.tagName}`,r=!(null==(e=s.shadowDOM)?void 0:e.use);if(!n.querySelector(`#${o}`)){const t=document.createElement("style");t.id=o,t.textContent=s.styles,n.appendChild(t)}if(r){const t=A(L,p).get(o)||0;A(L,p).set(o,t+1)}},$=function(){A(this,c)||(N(this,c,!0),this.created())},E(L,p,new Map),(()=>{if(q.IS_DEV&&"undefined"!=typeof customElements){const t=customElements.define,e=new WeakSet;customElements.define=function(s,i,a){if(L.isPrototypeOf(i)&&!e.has(i)){e.add(i);const t=i.prototype,a=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const e of a)t[e]!==L.prototype[e]&&console.error(`[${s}] 禁止重写 ${e}(),请使用框架钩子`)}return t.call(this,s,i,a)}}})();let T=L;exports.default=T;
1
+ "use strict";var t,e,s,i,a,r,n,o,h,l,c,u,d,p,f,b,m,y,v,w,g,S,M,O,$,k,j,W,C,N,A,E=Object.defineProperty,P=t=>{throw TypeError(t)},L=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(L(t,e,"read from private field"),s?s.call(t):e.get(t)),q=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),U=(t,e,s,i)=>(L(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),_=(t,e,s)=>(L(t,e,"access private method"),s);Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const R=require("../../shared/is-object.cjs"),T=require("../../shared/env.cjs"),x=require("../../shared/case-convert.cjs"),I=require("../reactivity/observe.cjs"),V=require("../renderer/renderIR.cjs"),H=Symbol.for("solely.manifest"),J=class extends HTMLElement{constructor(m={}){var y,w;super(),q(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),q(this,t),q(this,e),q(this,s),q(this,i),q(this,a),q(this,r),q(this,n,!1),q(this,o,!1),q(this,h,!1),q(this,l,!1),q(this,c,!1),q(this,u,!1),q(this,d,!1),q(this,p,new Set),q(this,f,!1),q(this,b,!1);const S=this.constructor;U(this,t,S[H]||{tagName:"base-element"});const O=D(this,t);U(this,a,(null==(y=O.shadowDOM)?void 0:y.use)?this.attachShadow({mode:O.shadowDOM.mode||"open"}):this),_(this,v,g).call(this,m),_(this,v,M).call(this,O),queueMicrotask(()=>_(this,v,A).call(this))}static get observedAttributes(){const t=this[H];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;R.isObject(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),_(this,v,g).call(this,t),_(this,v,$).call(this),_(this,v,j).call(this))}refresh(){_(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);U(this,c,!0);const i=D(this,t);if(_(this,v,A).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),_(this,v,C).call(this),i.attributeMap&&R.isObject(this.$data)){_(this,v,$).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=_(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}_(this,v,w).call(this),D(this,s)&&!D(this,e)&&U(this,e,V.createRender(D(this,s),D(this,a),this)),D(this,u)&&(U(this,u,!1),_(this,v,j).call(this)),this.mounted()}disconnectedCallback(){U(this,c,!1),D(this,f)||_(this,v,N).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!R.isObject(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const n=r.name,o=this.$data[n],l=_(this,v,k).call(this,i,r.default??o,r.type);o!==l&&(U(this,h,!0),this.$data[n]=l,this.attributeChanged(e,o,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(T.IS_DEV&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(U(this,f,!0),U(this,c,!1),_(this,v,N).call(this),null==(t=D(this,e))||t.destroy(),U(this,e,void 0),null==(s=D(this,r))||s.call(this),U(this,r,void 0))}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,n=new WeakMap,o=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(J,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,n=i.get(r);(null==n?void 0:n.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=I.observe(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),n=String(i),o=null==(s=r.propMap)?void 0:s.get(n);(null==o?void 0:o.reflect)&&_(this,v,S).call(this,o,a)}this.emit("dataChange",{...e}),_(this,v,j).call(this)});U(this,i,s),U(this,r,a)},S=function(t,e){const s=x.camelToKebab(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}}finally{D(this,p).delete(s)}},M=function(t){t.ir&&U(this,s,t.ir)},O=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},$=function(){D(this,d)||(U(this,d,!0),_(this,v,O).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,o)&&D(this,e)&&(U(this,o,!0),queueMicrotask(()=>{D(this,f)||(U(this,o,!1),_(this,v,W).call(this))})):U(this,u,!0))},W=function(){var t;if(!D(this,f)&&!D(this,n)&&D(this,c)){U(this,n,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),U(this,h,!1))}finally{U(this,n,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void U(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,n=`solely-style-${T.SOLELY_VERSION}-${s.tagName}`,o=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(n):n.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=n,t.textContent=s.styles,r.appendChild(t)}if(o){const t=D(J,m).get(n)||0;D(J,m).set(n,t+1),U(this,b,!0)}},N=function(){var e,s;if(!D(this,b))return;U(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${T.SOLELY_VERSION}-${i.tagName}`,e=D(J,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(J,m).delete(t)}else D(J,m).set(t,e-1)}},A=function(){D(this,l)||(U(this,l,!0),this.created())},q(J,m,new Map),q(J,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let F=J;exports.default=F;
@@ -31,7 +31,12 @@ declare class BaseElement<TData extends object = Record<string, unknown>, TRefs
31
31
  * @param message - 错误信息
32
32
  */
33
33
  protected error(condition: boolean, message: string): void;
34
- onInit(): void | Promise<void>;
34
+ /**
35
+ * 显式销毁组件,清理 renderer 等资源。
36
+ * 适用于确认组件不再 reconnect 的场景。
37
+ * 调用后如需重新使用组件,需重新创建实例。
38
+ */
39
+ dispose(): void;
35
40
  created(): void;
36
41
  mounted(): void;
37
42
  beforeUpdate(): void;
@@ -1 +1 @@
1
- var t,e,s,i,a,o,n,r,h,l,c,u,d,f,p,b,m,y,v,w,g,M,k,$,O,S,j=Object.defineProperty,C=t=>{throw TypeError(t)},W=(t,e,s)=>e.has(t)||C("Cannot "+s),A=(t,e,s)=>(W(t,e,"read from private field"),s?s.call(t):e.get(t)),N=(t,e,s)=>e.has(t)?C("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),E=(t,e,s,i)=>(W(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),P=(t,e,s)=>(W(t,e,"access private method"),s);import{isObject as U}from"../../shared/is-object.js";import{IS_DEV as D}from"../../shared/env.js";import{camelToKebab as L}from"../../shared/case-convert.js";import{observe as q}from"../reactivity/observe.js";import{createRender as x}from"../renderer/renderIR.js";const I=Symbol.for("solely.manifest"),J=class y extends HTMLElement{constructor(f={}){var b,y;super(),N(this,p),((t,e,s)=>{e in t?j(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(y="$refs")?y+"":y,{}),N(this,t),N(this,e),N(this,s),N(this,i),N(this,a),N(this,o),N(this,n,!1),N(this,r,!1),N(this,h,!1),N(this,l,!1),N(this,c,!1),N(this,u,!1),N(this,d,!1);const w=this.constructor;E(this,t,w[I]||{tagName:"base-element"});const g=A(this,t);E(this,a,(null==(b=g.shadowDOM)?void 0:b.use)?this.attachShadow({mode:g.shadowDOM.mode||"open"}):this),P(this,p,m).call(this,f),P(this,p,v).call(this,g),queueMicrotask(()=>P(this,p,S).call(this))}static get observedAttributes(){const t=this[I];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return A(this,i)}set $data(t){var e;U(t)||(t={}),t!==A(this,i)&&(null==(e=A(this,o))||e.call(this),P(this,p,m).call(this,t),P(this,p,g).call(this),P(this,p,k).call(this))}refresh(){P(this,p,k).call(this)}connectedCallback(){var i;E(this,c,!0);const o=A(this,t);if(P(this,p,S).call(this),(o.className||o.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),P(this,p,O).call(this),o.attributeMap&&U(this.$data)){P(this,p,g).call(this);for(const[t,e]of o.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=P(this,p,M).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}P(this,p,b).call(this),A(this,s)&&!A(this,e)&&E(this,e,x(A(this,s),A(this,a),this)),A(this,u)&&(E(this,u,!1),P(this,p,k).call(this)),this.mounted(),null==(i=this.onInit)||i.call(this)}disconnectedCallback(){var e,s;E(this,c,!1);const i=A(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${i.tagName}`,e=A(y,f).get(t)||0;e<=1?(null==(s=document.head.querySelector(`#${t}`))||s.remove(),A(y,f).delete(t)):A(y,f).set(t,e-1)}this.unmounted()}attributeChangedCallback(e,s,i){var a;if(s===i||!U(this.$data))return;const o=null==(a=A(this,t).attributeMap)?void 0:a.get(e);if(!o)return;const n=o.name,r=this.$data[n],l=P(this,p,M).call(this,i,o.default??r,o.type);this.$data[n]=l,E(this,h,!0),this.attributeChanged(e,r,l)}emit(t,e,s){this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(D&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(D&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}onInit(){}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,o=new WeakMap,n=new WeakMap,r=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,u=new WeakMap,d=new WeakMap,f=new WeakMap,p=new WeakSet,b=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=new Set(["$data","$refs","constructor","onInit","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","refresh"]),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const o of t){if(s.has(o))continue;if(e.some(t=>o.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,o);if(!t||!("value"in t))continue;const a=t.value,n=i.get(o);(null==n?void 0:n.set)&&(delete this[o],this[o]=a)}},m=function(e){const{proxy:s,dispose:a}=q(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,o=A(this,t),n=String(i),r=null==(s=o.propMap)?void 0:s.get(n);(null==r?void 0:r.reflect)&&P(this,p,y).call(this,r,a)}this.emit("dataChange",{...e}),P(this,p,k).call(this)});E(this,i,s),E(this,o,a)},y=function(t,e){const s=L(t.name);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}},v=function(t){t.ir&&E(this,s,t.ir)},w=function(){const e=A(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;const e=Object.getOwnPropertyDescriptor(this.constructor.prototype,t.name);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},g=function(){A(this,d)||(E(this,d,!0),P(this,p,w).call(this))},M=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=t.replace(/'/g,'"'),i=JSON.parse(s);return Array.isArray(i)?i:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},k=function(){A(this,c)?!A(this,r)&&A(this,e)&&(E(this,r,!0),queueMicrotask(()=>{E(this,r,!1),P(this,p,$).call(this)})):E(this,u,!0)},$=function(){if(!A(this,n)&&A(this,c)){E(this,n,!0);try{A(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),A(this,e).update(),this.updated(),A(this,h)&&(this.afterAttributesUpdate(),E(this,h,!1))}finally{E(this,n,!1)}}},O=function(){var e;const s=A(this,t);if(!s.styles)return;const i=A(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return}const o=i instanceof ShadowRoot?i:document.head,n=`solely-style-${s.tagName}`,r=!(null==(e=s.shadowDOM)?void 0:e.use);if(!o.querySelector(`#${n}`)){const t=document.createElement("style");t.id=n,t.textContent=s.styles,o.appendChild(t)}if(r){const t=A(J,f).get(n)||0;A(J,f).set(n,t+1)}},S=function(){A(this,l)||(E(this,l,!0),this.created())},N(J,f,new Map),(()=>{if(D&&"undefined"!=typeof customElements){const t=customElements.define,e=new WeakSet;customElements.define=function(s,i,a){if(J.isPrototypeOf(i)&&!e.has(i)){e.add(i);const t=i.prototype,a=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const e of a)t[e]!==J.prototype[e]&&console.error(`[${s}] 禁止重写 ${e}(),请使用框架钩子`)}return t.call(this,s,i,a)}}})();let R=J;export{R as default};
1
+ var t,e,s,i,a,r,o,n,h,l,c,d,u,p,f,b,m,y,v,w,g,M,S,$,O,k,j,W,C,A,N,E=Object.defineProperty,P=t=>{throw TypeError(t)},U=(t,e,s)=>e.has(t)||P("Cannot "+s),D=(t,e,s)=>(U(t,e,"read from private field"),s?s.call(t):e.get(t)),L=(t,e,s)=>e.has(t)?P("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(t):e.set(t,s),q=(t,e,s,i)=>(U(t,e,"write to private field"),i?i.call(t,s):e.set(t,s),s),x=(t,e,s)=>(U(t,e,"access private method"),s);import{isObject as T}from"../../shared/is-object.js";import{SOLELY_VERSION as H,IS_DEV as J}from"../../shared/env.js";import{camelToKebab as R}from"../../shared/case-convert.js";import{observe as F}from"../reactivity/observe.js";import{createRender as I}from"../renderer/renderIR.js";const V=Symbol.for("solely.manifest"),_=class extends HTMLElement{constructor(m={}){var y,w;super(),L(this,v),((t,e,s)=>{e in t?E(t,e,{enumerable:!0,configurable:!0,writable:!0,value:s}):t[e]=s})(this,"symbol"!=typeof(w="$refs")?w+"":w,{}),L(this,t),L(this,e),L(this,s),L(this,i),L(this,a),L(this,r),L(this,o,!1),L(this,n,!1),L(this,h,!1),L(this,l,!1),L(this,c,!1),L(this,d,!1),L(this,u,!1),L(this,p,new Set),L(this,f,!1),L(this,b,!1);const M=this.constructor;q(this,t,M[V]||{tagName:"base-element"});const $=D(this,t);q(this,a,(null==(y=$.shadowDOM)?void 0:y.use)?this.attachShadow({mode:$.shadowDOM.mode||"open"}):this),x(this,v,g).call(this,m),x(this,v,S).call(this,$),queueMicrotask(()=>x(this,v,N).call(this))}static get observedAttributes(){const t=this[V];return(null==t?void 0:t.attributeMap)?Array.from(t.attributeMap.keys()):[]}get $data(){return D(this,i)}set $data(t){var e;T(t)||(t={}),t!==D(this,i)&&(null==(e=D(this,r))||e.call(this),x(this,v,g).call(this,t),x(this,v,O).call(this),x(this,v,j).call(this))}refresh(){x(this,v,j).call(this)}connectedCallback(){if(D(this,f))throw new Error(`[Solely] <${this.tagName.toLowerCase()}> has been disposed and cannot be reconnected.`);q(this,c,!0);const i=D(this,t);if(x(this,v,N).call(this),(i.className||i.tagName||"").split(" ").forEach(t=>t&&this.classList.add(t)),x(this,v,C).call(this),i.attributeMap&&T(this.$data)){x(this,v,O).call(this);for(const[t,e]of i.attributeMap){const s=e.name;if(this.hasAttribute(t)){const i=this.getAttribute(t),a=x(this,v,k).call(this,i,e.default,e.type);this.$data[s]=a}else"default"in e&&void 0===this.$data[s]&&(this.$data[s]=e.default,"boolean"===e.type&&!0===e.default&&this.setAttribute(t,""))}}x(this,v,w).call(this),D(this,s)&&!D(this,e)&&q(this,e,I(D(this,s),D(this,a),this)),D(this,d)&&(q(this,d,!1),x(this,v,j).call(this)),this.mounted()}disconnectedCallback(){q(this,c,!1),D(this,f)||x(this,v,A).call(this),this.unmounted()}attributeChangedCallback(e,s,i){var a;if(D(this,f)||s===i||!T(this.$data))return;if(D(this,p).has(e))return;const r=null==(a=D(this,t).attributeMap)?void 0:a.get(e);if(!r)return;const o=r.name,n=this.$data[o],l=x(this,v,k).call(this,i,r.default??n,r.type);n!==l&&(q(this,h,!0),this.$data[o]=l,this.attributeChanged(e,n,l))}emit(t,e,s){D(this,f)||this.dispatchEvent(new CustomEvent(t,{bubbles:!0,composed:!0,detail:e,...s}))}emitNative(t,e){D(this,f)||this.dispatchEvent(new Event(t,{bubbles:!0,composed:!0,...e}))}warn(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.warn(`[${t}] ${e}`)}}error(t,e){if(J&&t){const t=this.tagName.toLowerCase();console.error(`[${t}] ${e}`)}}dispose(){var t,s;D(this,f)||(q(this,f,!0),q(this,c,!1),x(this,v,A).call(this),null==(t=D(this,e))||t.destroy(),q(this,e,void 0),null==(s=D(this,r))||s.call(this),q(this,r,void 0))}created(){}mounted(){}beforeUpdate(){}updated(){}unmounted(){}attributeChanged(t,e,s){}beforeAttributesUpdate(){}afterAttributesUpdate(){}};t=new WeakMap,e=new WeakMap,s=new WeakMap,i=new WeakMap,a=new WeakMap,r=new WeakMap,o=new WeakMap,n=new WeakMap,h=new WeakMap,l=new WeakMap,c=new WeakMap,d=new WeakMap,u=new WeakMap,p=new WeakMap,f=new WeakMap,b=new WeakMap,m=new WeakMap,y=new WeakMap,v=new WeakSet,w=function(){const t=Object.getOwnPropertyNames(this),e=["#","_"],s=D(_,y),i=new Map;let a=Object.getPrototypeOf(this);for(;a&&a!==HTMLElement.prototype;){const t=Object.getOwnPropertyDescriptors(a);for(const[e,s]of Object.entries(t))s.set&&!i.has(e)&&i.set(e,s);a=Object.getPrototypeOf(a)}for(const r of t){if(s.has(r))continue;if(e.some(t=>r.startsWith(t)))continue;const t=Object.getOwnPropertyDescriptor(this,r);if(!t||!("value"in t))continue;const a=t.value,o=i.get(r);(null==o?void 0:o.set)&&(delete this[r],this[r]=a)}},g=function(e){const{proxy:s,dispose:a}=F(e,e=>{var s;if("set"===e.type){const{key:i,newValue:a}=e,r=D(this,t),o=String(i),n=null==(s=r.propMap)?void 0:s.get(o);(null==n?void 0:n.reflect)&&x(this,v,M).call(this,n,a)}this.emit("dataChange",{...e}),x(this,v,j).call(this)});q(this,i,s),q(this,r,a)},M=function(t,e){const s=R(t.name);D(this,p).add(s);try{if(null==e)return void this.removeAttribute(s);if("boolean"===t.type)e?this.setAttribute(s,""):this.removeAttribute(s);else{const t="object"==typeof e?JSON.stringify(e):String(e);this.setAttribute(s,t)}}finally{D(this,p).delete(s)}},S=function(t){t.ir&&q(this,s,t.ir)},$=function(){const e=D(this,t);if(e.attributeMap)for(const[,t]of e.attributeMap){if(!1===t.reactive)continue;let e,s=Object.getPrototypeOf(this);for(;s&&s!==HTMLElement.prototype&&(e=Object.getOwnPropertyDescriptor(s,t.name),!e);)s=Object.getPrototypeOf(s);if(!(null==e?void 0:e.get)&&!(null==e?void 0:e.set)){const e=Object.getOwnPropertyDescriptor(this,t.name);e&&"value"in e&&(this.$data[t.name]=e.value,delete this[t.name]),Object.defineProperty(this,t.name,{get:()=>this.$data[t.name],set:e=>{this.$data[t.name]=e},configurable:!0,enumerable:!0})}}},O=function(){D(this,u)||(q(this,u,!0),x(this,v,$).call(this))},k=function(t,e,s){if(null===t)return"boolean"!==s&&e;switch(s){case"boolean":return!0;case"number":{const s=Number(t);return isNaN(s)?e:s}case"object":try{return JSON.parse(t)}catch(i){return console.error(`[Solely] Failed to parse object value: "${t}", using default value.`,i),e}case"array":try{const s=JSON.parse(t);return Array.isArray(s)?s:e}catch(i){return console.error(`[Solely] Failed to parse array value: "${t}", using default value.`,i),e}default:return t}},j=function(){D(this,f)||(D(this,c)?!D(this,n)&&D(this,e)&&(q(this,n,!0),queueMicrotask(()=>{D(this,f)||(q(this,n,!1),x(this,v,W).call(this))})):q(this,d,!0))},W=function(){var t;if(!D(this,f)&&!D(this,o)&&D(this,c)){q(this,o,!0);try{D(this,h)&&this.beforeAttributesUpdate(),this.beforeUpdate(),null==(t=D(this,e))||t.update(),this.updated(),D(this,h)&&(this.afterAttributesUpdate(),q(this,h,!1))}finally{q(this,o,!1)}}},C=function(){var e;const s=D(this,t);if(!s.styles)return;const i=D(this,a);if(s.sheet&&i instanceof ShadowRoot&&"adoptedStyleSheets"in i){if(!i.adoptedStyleSheets.includes(s.sheet)){const t=Array.from(i.adoptedStyleSheets);t.push(s.sheet),i.adoptedStyleSheets=t}return void q(this,b,!0)}const r=i instanceof ShadowRoot?i:document.head,o=`solely-style-${H}-${s.tagName}`,n=!(null==(e=s.shadowDOM)?void 0:e.use),h="undefined"!=typeof CSS&&CSS.escape?CSS.escape(o):o.replace(/([.#:[\]()!])/g,"\\$1");if(!r.querySelector(`#${h}`)){const t=document.createElement("style");t.id=o,t.textContent=s.styles,r.appendChild(t)}if(n){const t=D(_,m).get(o)||0;D(_,m).set(o,t+1),q(this,b,!0)}},A=function(){var e,s;if(!D(this,b))return;q(this,b,!1);const i=D(this,t);if(!(null==(e=i.shadowDOM)?void 0:e.use)&&i.styles){const t=`solely-style-${H}-${i.tagName}`,e=D(_,m).get(t)||0;if(e<=1){const e=CSS.escape(t);null==(s=document.head.querySelector(`#${e}`))||s.remove(),D(_,m).delete(t)}else D(_,m).set(t,e-1)}},N=function(){D(this,l)||(q(this,l,!0),this.created())},L(_,m,new Map),L(_,y,new Set(["$data","$refs","constructor","created","mounted","beforeUpdate","updated","unmounted","attributeChanged","beforeAttributesUpdate","afterAttributesUpdate","emit","emitNative","refresh","dispose","warn","error"]));let z=_;export{z as default};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/env.cjs"),t=require("../../shared/case-convert.cjs"),r=require("../../compiler/parser/parser.cjs"),n=require("../../compiler/ir/buildIR.cjs"),o=Symbol.for("solely.manifest");exports.CustomElement=s=>{const l=s,a="undefined"!=typeof window&&"undefined"!=typeof customElements;return s=>{const{tagName:i}=l;if(a&&!(s.prototype instanceof HTMLElement)&&s!==HTMLElement)throw new TypeError(`[Solely] CustomElement decorator can only be applied to classes extending HTMLElement.\nReceived: ${s.name||"anonymous class"}`);if(a&&customElements.get(i))return e.IS_DEV&&console.warn(`[Solely] 标签名称 "${i}" 已经被注册,跳过重复定义。`),s[o]=l,s;if("string"!=typeof l.template||l.ir){if(l.template&&!l.ir)if("object"==typeof l.template&&null!==l.template){const t=l.template;"root"===t.t&&Array.isArray(t.fns)&&Array.isArray(t.n)?(l.ir=t,e.IS_DEV&&console.info(`[Solely] Using precompiled IR for <${i}> | Nodes: ${t.n.length} | Fns: ${t.fns.length}`)):console.error(`[Manifest Error] <${i}>: 提供的 template 不是有效的 IRRoot 对象。\n期望: { t: "root", fns: [], n: [] }\n实际: ${JSON.stringify(Object.keys(t))}`)}else console.error(`[Manifest Error] <${i}>: template 类型无效。\n期望: string 或 IRRoot 对象\n实际: ${typeof l.template}`)}else if(l.template.trim())try{const e=r.parseHtml(l.template);l.ir=n.buildIR(e,{source:l.template,filename:i})}catch(p){const t=p instanceof Error?p:new Error(String(p));console.error(`[Compiler Error] <${i}>: 模板编译失败\n错误: ${t.message}\n模板长度: ${l.template.length} 字符`,e.IS_DEV?t.stack:"")}else e.IS_DEV&&console.warn(`[Solely] <${i}>: 模板为空字符串`);if(a&&l.styles&&!l.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(l.styles),l.sheet=e)}catch{e.IS_DEV&&console.warn(`[Solely] <${i}>: CSSStyleSheet 不可用,将使用 style 标签回退方案`)}if(l.props&&!l.attributeMap){const e=new Map,r=new Map;l.props.forEach(n=>{const o="string"==typeof n?{name:n}:n,s=t.camelToKebab(o.name),l=o.name,a={...o,name:l};e.set(s,a),r.set(l,a)}),l.attributeMap=e,l.propMap=r}class c extends s{}return c[o]=l,a&&customElements.define(i,c),c}};
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/env.cjs"),t=require("../../shared/case-convert.cjs"),o=require("../../compiler/parser/parser.cjs"),r=require("../../compiler/ir/buildIR.cjs"),n=Symbol.for("solely.manifest");exports.CustomElement=s=>{const l=s,a="undefined"!=typeof window&&"undefined"!=typeof customElements;return s=>{const{tagName:c}=l;if(a&&!(s.prototype instanceof HTMLElement)&&s!==HTMLElement)throw new TypeError(`[Solely] CustomElement decorator can only be applied to classes extending HTMLElement.\nReceived: ${s.name||"anonymous class"}`);if(a&&customElements.get(c))return e.IS_DEV&&console.warn(`[Solely] 标签名称 "${c}" 已经被注册,跳过重复定义。`),s[n]=l,s;if("string"!=typeof l.template||l.ir){if(l.template&&!l.ir)if("object"==typeof l.template&&null!==l.template){const t=l.template;"root"===t.t&&Array.isArray(t.fns)&&Array.isArray(t.n)?(l.ir=t,e.IS_DEV&&console.info(`[Solely] Using precompiled IR for <${c}> | Nodes: ${t.n.length} | Fns: ${t.fns.length}`)):console.error(`[Manifest Error] <${c}>: 提供的 template 不是有效的 IRRoot 对象。\n期望: { t: "root", fns: [], n: [] }\n实际: ${JSON.stringify(Object.keys(t))}`)}else console.error(`[Manifest Error] <${c}>: template 类型无效。\n期望: string 或 IRRoot 对象\n实际: ${typeof l.template}`)}else if(l.template.trim())try{const e=o.parseHtml(l.template);l.ir=r.buildIR(e,{source:l.template,filename:c})}catch(p){const t=p instanceof Error?p:new Error(String(p));console.error(`[Compiler Error] <${c}>: 模板编译失败\n错误: ${t.message}\n模板长度: ${l.template.length} 字符`,e.IS_DEV?t.stack:"")}else e.IS_DEV&&console.warn(`[Solely] <${c}>: 模板为空字符串`);if(a&&l.styles&&!l.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(l.styles),l.sheet=e)}catch{e.IS_DEV&&console.warn(`[Solely] <${c}>: CSSStyleSheet 不可用,将使用 style 标签回退方案`)}if(l.props&&!l.attributeMap){const e=new Map,o=new Map;l.props.forEach(r=>{const n="string"==typeof r?{name:r}:r,s=t.camelToKebab(n.name),l=n.name,a={...n,name:l};e.set(s,a),o.set(l,a)}),l.attributeMap=e,l.propMap=o}class i extends s{}if(i[n]=l,a){if(e.IS_DEV){const e=s.prototype,t=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const o of t)Object.prototype.hasOwnProperty.call(e,o)&&console.error(`[${c}] 禁止重写 ${o}(),请使用框架钩子`)}customElements.define(c,i)}return i}};
@@ -1 +1 @@
1
- import{IS_DEV as e}from"../../shared/env.js";import{camelToKebab as t}from"../../shared/case-convert.js";import{parseHtml as o}from"../../compiler/parser/parser.js";import{buildIR as r}from"../../compiler/ir/buildIR.js";const n=Symbol.for("solely.manifest"),s=s=>{const l=s,a="undefined"!=typeof window&&"undefined"!=typeof customElements;return s=>{const{tagName:i}=l;if(a&&!(s.prototype instanceof HTMLElement)&&s!==HTMLElement)throw new TypeError(`[Solely] CustomElement decorator can only be applied to classes extending HTMLElement.\nReceived: ${s.name||"anonymous class"}`);if(a&&customElements.get(i))return e&&console.warn(`[Solely] 标签名称 "${i}" 已经被注册,跳过重复定义。`),s[n]=l,s;if("string"!=typeof l.template||l.ir){if(l.template&&!l.ir)if("object"==typeof l.template&&null!==l.template){const t=l.template;"root"===t.t&&Array.isArray(t.fns)&&Array.isArray(t.n)?(l.ir=t,e&&console.info(`[Solely] Using precompiled IR for <${i}> | Nodes: ${t.n.length} | Fns: ${t.fns.length}`)):console.error(`[Manifest Error] <${i}>: 提供的 template 不是有效的 IRRoot 对象。\n期望: { t: "root", fns: [], n: [] }\n实际: ${JSON.stringify(Object.keys(t))}`)}else console.error(`[Manifest Error] <${i}>: template 类型无效。\n期望: string 或 IRRoot 对象\n实际: ${typeof l.template}`)}else if(l.template.trim())try{const e=o(l.template);l.ir=r(e,{source:l.template,filename:i})}catch(m){const t=m instanceof Error?m:new Error(String(m));console.error(`[Compiler Error] <${i}>: 模板编译失败\n错误: ${t.message}\n模板长度: ${l.template.length} 字符`,e?t.stack:"")}else e&&console.warn(`[Solely] <${i}>: 模板为空字符串`);if(a&&l.styles&&!l.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(l.styles),l.sheet=e)}catch{e&&console.warn(`[Solely] <${i}>: CSSStyleSheet 不可用,将使用 style 标签回退方案`)}if(l.props&&!l.attributeMap){const e=new Map,o=new Map;l.props.forEach(r=>{const n="string"==typeof r?{name:r}:r,s=t(n.name),l=n.name,a={...n,name:l};e.set(s,a),o.set(l,a)}),l.attributeMap=e,l.propMap=o}class p extends s{}return p[n]=l,a&&customElements.define(i,p),p}};export{s as CustomElement};
1
+ import{IS_DEV as e}from"../../shared/env.js";import{camelToKebab as t}from"../../shared/case-convert.js";import{parseHtml as o}from"../../compiler/parser/parser.js";import{buildIR as r}from"../../compiler/ir/buildIR.js";const n=Symbol.for("solely.manifest"),s=s=>{const l=s,a="undefined"!=typeof window&&"undefined"!=typeof customElements;return s=>{const{tagName:c}=l;if(a&&!(s.prototype instanceof HTMLElement)&&s!==HTMLElement)throw new TypeError(`[Solely] CustomElement decorator can only be applied to classes extending HTMLElement.\nReceived: ${s.name||"anonymous class"}`);if(a&&customElements.get(c))return e&&console.warn(`[Solely] 标签名称 "${c}" 已经被注册,跳过重复定义。`),s[n]=l,s;if("string"!=typeof l.template||l.ir){if(l.template&&!l.ir)if("object"==typeof l.template&&null!==l.template){const t=l.template;"root"===t.t&&Array.isArray(t.fns)&&Array.isArray(t.n)?(l.ir=t,e&&console.info(`[Solely] Using precompiled IR for <${c}> | Nodes: ${t.n.length} | Fns: ${t.fns.length}`)):console.error(`[Manifest Error] <${c}>: 提供的 template 不是有效的 IRRoot 对象。\n期望: { t: "root", fns: [], n: [] }\n实际: ${JSON.stringify(Object.keys(t))}`)}else console.error(`[Manifest Error] <${c}>: template 类型无效。\n期望: string 或 IRRoot 对象\n实际: ${typeof l.template}`)}else if(l.template.trim())try{const e=o(l.template);l.ir=r(e,{source:l.template,filename:c})}catch(p){const t=p instanceof Error?p:new Error(String(p));console.error(`[Compiler Error] <${c}>: 模板编译失败\n错误: ${t.message}\n模板长度: ${l.template.length} 字符`,e?t.stack:"")}else e&&console.warn(`[Solely] <${c}>: 模板为空字符串`);if(a&&l.styles&&!l.sheet&&"CSSStyleSheet"in window)try{const e=new CSSStyleSheet;"function"==typeof e.replaceSync&&(e.replaceSync(l.styles),l.sheet=e)}catch{e&&console.warn(`[Solely] <${c}>: CSSStyleSheet 不可用,将使用 style 标签回退方案`)}if(l.props&&!l.attributeMap){const e=new Map,o=new Map;l.props.forEach(r=>{const n="string"==typeof r?{name:r}:r,s=t(n.name),l=n.name,a={...n,name:l};e.set(s,a),o.set(l,a)}),l.attributeMap=e,l.propMap=o}class i extends s{}if(i[n]=l,a){if(e){const e=s.prototype,t=["connectedCallback","disconnectedCallback","attributeChangedCallback"];for(const o of t)Object.prototype.hasOwnProperty.call(e,o)&&console.error(`[${c}] 禁止重写 ${o}(),请使用框架钩子`)}customElements.define(c,i)}return i}};export{s as CustomElement};
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./component/base-element.cjs"),r=require("./renderer/html-decode.cjs"),t=require("./component/decorators.cjs"),o=require("./renderer/renderIR.cjs"),s=require("./reactivity/observe.cjs");exports.BaseElement=e.default,exports.htmlDecode=r.default,exports.CustomElement=t.CustomElement,exports.IRRenderer=o.IRRenderer,exports.createRender=o.createRender,exports.isProxy=s.isProxy,exports.observe=s.observe,exports.toRaw=s.toRaw;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./component/base-element.cjs"),r=require("./renderer/html-decode.cjs"),t=require("./component/decorators.cjs"),o=require("./renderer/renderIR.cjs"),s=require("./reactivity/computed.cjs"),c=require("./reactivity/observe.cjs"),a=require("./reactivity/watch.cjs");exports.BaseElement=e.default,exports.htmlDecode=r.default,exports.CustomElement=t.CustomElement,exports.IRRenderer=o.IRRenderer,exports.createRender=o.createRender,exports.computed=s.computed,exports.isProxy=c.isProxy,exports.observe=c.observe,exports.toProxy=c.toProxy,exports.toRaw=c.toRaw,exports.watch=a.watch,exports.watchGetter=a.watchGetter;
@@ -1 +1 @@
1
- import{default as e}from"./component/base-element.js";import{default as r}from"./renderer/html-decode.js";import{CustomElement as o}from"./component/decorators.js";import{IRRenderer as t,createRender as m}from"./renderer/renderIR.js";import{isProxy as s,observe as a,toRaw as d}from"./reactivity/observe.js";export{e as BaseElement,o as CustomElement,t as IRRenderer,m as createRender,r as htmlDecode,s as isProxy,a as observe,d as toRaw};
1
+ import{default as e}from"./component/base-element.js";import{default as r}from"./renderer/html-decode.js";import{CustomElement as o}from"./component/decorators.js";import{IRRenderer as t,createRender as m}from"./renderer/renderIR.js";import{computed as s}from"./reactivity/computed.js";import{isProxy as a,observe as i,toProxy as p,toRaw as c}from"./reactivity/observe.js";import{watch as d,watchGetter as f}from"./reactivity/watch.js";export{e as BaseElement,o as CustomElement,t as IRRenderer,s as computed,m as createRender,r as htmlDecode,a as isProxy,i as observe,p as toProxy,c as toRaw,d as watch,f as watchGetter};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./observe.cjs");exports.computed=function(o,r,s={}){let t,n=!0,c=!1;const i=[],p=()=>{n=!0};for(const d of o){const o=e.toProxy(d);if(!e.isProxy(o))throw new Error("[solely] computed: sources 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const r=e.observe(o,p,{deepCompare:s.deepCompare});i.push(r)}return{get:()=>(c||n&&(t=r(),n=!1),t),invalidate:()=>{n=!0},dispose:()=>{if(!c){c=!0;for(const e of i)e.dispose();i.length=0,t=void 0}}}};
@@ -0,0 +1,36 @@
1
+ import { ReactiveSource } from './observe';
2
+ /** computed 选项 */
3
+ export interface ComputedOptions {
4
+ /** 是否启用深度比较,默认 false */
5
+ deepCompare?: boolean;
6
+ }
7
+ /** computed 返回值 */
8
+ export interface ComputedReturn<T> {
9
+ /** 获取当前计算值 */
10
+ get: () => T;
11
+ /** 手动标记为脏,下次读取时重新计算 */
12
+ invalidate: () => void;
13
+ /** 销毁计算属性,停止追踪依赖 */
14
+ dispose: () => void;
15
+ }
16
+ /**
17
+ * 创建计算属性
18
+ *
19
+ * 接受一个或多个响应式代理对象(或 observe 返回值)作为依赖源,以及一个计算函数。
20
+ * 当任意依赖源发生变化时,标记为脏,下次读取时重新计算(惰性求值)。
21
+ *
22
+ * @param sources 依赖的响应式代理对象或 observe 返回值数组
23
+ * @param getter 计算函数
24
+ * @param options 选项
25
+ * @returns 计算属性控制对象
26
+ *
27
+ * @example
28
+ * ```ts
29
+ * const obs = observe({ a: 1, b: 2 }, () => {});
30
+ * const sum = computed([obs], () => obs.proxy.a + obs.proxy.b);
31
+ * console.log(sum.get()); // 3
32
+ * obs.proxy.a = 10;
33
+ * console.log(sum.get()); // 12
34
+ * ```
35
+ */
36
+ export declare function computed<T>(sources: ReactiveSource[], getter: () => T, options?: ComputedOptions): ComputedReturn<T>;
@@ -0,0 +1 @@
1
+ import{toProxy as o,isProxy as e,observe as r}from"./observe.js";function s(s,t,n={}){let p,i=!0,c=!1;const f=[],d=()=>{i=!0};for(const l of s){const s=o(l);if(!e(s))throw new Error("[solely] computed: sources 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const t=r(s,d,{deepCompare:n.deepCompare});f.push(t)}return{get:()=>(c||i&&(p=t(),i=!1),p),invalidate:()=>{i=!0},dispose:()=>{if(!c){c=!0;for(const o of f)o.dispose();f.length=0,p=void 0}}}}export{s as computed};
@@ -1,2 +1,6 @@
1
- export { observe, toRaw, isProxy } from './observe';
2
- export type { ChangeItem, ObserveOptions, ObserveReturn, PathKey, ChangePayload } from './observe';
1
+ export { observe, toRaw, isProxy, toProxy } from './observe';
2
+ export type { ChangeItem, ObserveOptions, ObserveReturn, PathKey, ChangePayload, ReactiveSource } from './observe';
3
+ export { computed } from './computed';
4
+ export type { ComputedOptions, ComputedReturn } from './computed';
5
+ export { watch, watchGetter } from './watch';
6
+ export type { WatchOptions, WatchReturn } from './watch';
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/is-object.cjs"),t=require("../../shared/env.cjs"),r=Symbol("solely.raw"),n=new WeakMap,i=new WeakMap,o=new WeakMap,s=new WeakMap,a=new WeakMap;function l(e){if(e&&"object"==typeof e){const t=e[r];if(t)return t}return e}const c=e=>!(!e||"object"!=typeof e)&&(e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request);function u(e){return!(!e||!e[r])}const f=(e,t,r=new WeakMap,n=0)=>{if(n>10)return e===t;if(e===t)return!0;if(null==e||null==t)return e===t;if("object"!=typeof e||"object"!=typeof t)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;if(r.has(e))return r.get(e)===t;if(r.set(e,t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!f(e[i],t[i],r,n+1))return!1;return!0}const i=Reflect.ownKeys(e);if(i.length!==Reflect.ownKeys(t).length)return!1;for(const o of i){if(!Reflect.has(t,o))return!1;const i=e[o],s=t[o];if(!f(i,s,r,n+1))return!1}return!0},p=(e,t)=>{if(0===t.length)return!0;const r=e.map(String).join(".");return t.some(e=>e.test(r))},y=(e,t)=>{const r=(e=>{const t=[];let r=e;for(;r;){const e=o.get(r);if(!e||null==e.key)break;t.unshift(e.key),r=e.parent}return t})(e);let i=e,s=0;for(;i;){const e=n.get(i);if(e){const n=r.slice(r.length-s);e.forEach(e=>{if(!e.active)return;if(!p(n,e.filterRegexes))return;const r={...t,path:n};e.throttle>0?(e.pending.push(r),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([r]):e.callback(r)})}const a=o.get(i);i=(null==a?void 0:a.parent)||null,s++}};exports.isProxy=u,exports.observe=function(p,d,h={}){const{throttle:g=0,onBatch:b,immediate:m=!1,deepCompare:w=!1}=h,v={callback:d,onBatch:b,throttle:g,filterRegexes:(Array.isArray(h.filter)?h.filter:h.filter?[h.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=e.replace(/\./g,"\\.").replace(/\*\*/g,"(.+)").replace(/\*/g,"[^.]+").replace(/\[\d+\]/g,"\\[\\d+\\]");return new RegExp(`^${t}$`)}),pending:[],timer:null,active:!0},A=(n,p,d)=>{if(!Object.isExtensible(n))return n;if(c(n))return n;if(n[r])return n;const h=i.get(n);if(h)return h;const g=new Proxy(n,{get(t,n,i){if(n===r)return t;if(Array.isArray(t)){const e=s.get(g);if(e&&Object.prototype.hasOwnProperty.call(e,n))return Reflect.get(e,n,i)}const o=Reflect.get(t,n,i);return"symbol"==typeof n?o:e.isObject(o)&&!c(o)?A(o,g,n):o},set(e,r,n,i){if(!v.active)return t.IS_DEV&&console.warn("[Solely] Cannot set property on a disposed reactive object"),!0;const o=e[r];if(w?f(o,n):o===n)return!0;const s=Reflect.set(e,r,n,i);return 0===(a.get(g)||0)&&(Array.isArray(o)&&Array.isArray(n)?y(g,{type:"array-replace",oldValue:o,newValue:n}):y(g,{type:"set",key:r,newValue:n,oldValue:o})),s},deleteProperty(e,r){if(!v.active)return t.IS_DEV&&console.warn("[Solely] Cannot delete property on a disposed reactive object"),!0;if(!Reflect.has(e,r))return!1;const n=e[r],i=Reflect.deleteProperty(e,r),o=a.get(g)||0;return i&&0===o&&y(g,{type:"delete",key:r,oldValue:n}),i}});return i.set(n,g),o.set(g,{parent:p,key:d}),Array.isArray(n)&&s.set(g,((e,t,r)=>{const n={};return["push","pop","shift","unshift","splice"].forEach(i=>{n[i]=function(...n){if(!t)return;const o=a.get(t)||0;a.set(t,o+1);const s=e[i].apply(e,n);if(a.set(t,o),"push"===i)r(t,{type:"array-push",index:e.length-n.length,values:n});else if("unshift"===i)r(t,{type:"array-push",index:0,values:n});else if("pop"===i)r(t,{type:"array-splice",index:e.length,deleteCount:1,insert:[]});else if("shift"===i)r(t,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===i){const[e,i,...o]=n;r(t,{type:"array-splice",index:e,deleteCount:i,insert:o})}return s}}),["sort","reverse","fill","copyWithin"].forEach(i=>{n[i]=function(...n){if(!t)return;const o=a.get(t)||0;a.set(t,o+1);const s=e[i].apply(e,n);return a.set(t,o),r(t,{type:"array-reset",method:i}),s}}),["indexOf","lastIndexOf","includes"].forEach(t=>{n[t]=function(r,...n){let i=e[t].apply(e,[r,...n]);return-1!==i&&!1!==i||!u(r)||(i=e[t].apply(e,[l(r),...n])),i}}),n})(n,g,y)),g},k=A(p,null,null);let x=n.get(k);if(x||(x=new Set,n.set(k,x)),x.add(v),m){const t=(r,n,i=new WeakSet)=>{e.isObject(r)&&!i.has(r)&&(i.add(r),Reflect.ownKeys(r).forEach(o=>{const s=r[o];e.isObject(s)&&i.has(s)||(y(n,{type:"set",key:o,newValue:s,oldValue:void 0}),e.isObject(s)&&t(s,A(s,n,o),i))}))};t(p,k)}return{proxy:k,unobserve:()=>{v.active=!1,v.pending=[],v.timer&&(clearTimeout(v.timer),v.timer=null);const e=n.get(k);e&&e.delete(v)},resume:()=>{if(v.active)return;v.active=!0;let e=n.get(k);e||(e=new Set,n.set(k,e)),e.has(v)||e.add(v)},dispose:()=>{v.active=!1,v.pending=[],v.timer&&(clearTimeout(v.timer),v.timer=null);const e=n.get(k);e&&e.delete(v),v.callback=()=>{},v.onBatch=void 0}}},exports.toRaw=l;
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("../../shared/is-object.cjs"),t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,i=new WeakMap,o=new WeakMap,s=new WeakMap;function c(e,t,n){l(e,t);let r=o.get(e);r||(r=new Map,o.set(e,r)),r.set(t,n);let i=s.get(n);i||(i=[],s.set(n,i)),i.some(n=>n.parentRef.deref()===e&&n.key===t)||i.push({parentRef:new WeakRef(e),key:t})}function l(e,t){const n=o.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const i=s.get(r);if(i){const n=i.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function a(t,n){const r=o.get(n);if(r)for(const e of r.keys())l(n,e);for(let i=0;i<t.length;i++){const r=t[i];e.isObject(r)&&!p(r)&&c(n,String(i),w(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request};function y(e){return!(!e||!e[t])}const h=new Map,g=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},d=(e,t)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!d(e[n],t[n]))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(const i of n){if(!Reflect.has(t,i))return!1;if(!d(e[i],t[i]))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&"set"===t.type&&d(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},v=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let i=0;for(;i<n.length;){const{node:e,relativePath:o,visited:c}=n[i++],l=r.get(e);l&&l.forEach(e=>{if(!e.active)return;let n=o;if("set"===t.type||"delete"===t.type?n=[...o,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...o,String(t.index)]),!g(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const a=s.get(e);if(a)for(let t=a.length-1;t>=0;t--){const e=a[t],r=e.parentRef.deref();if(!r){a.splice(t,1);continue}if(c.has(r))continue;const i=new Set(c);i.add(r),n.push({node:r,relativePath:[e.key,...o],visited:i})}}},R={};["push","pop","shift","unshift","splice"].forEach(t=>{R[t]=function(...n){const r=this,o=f(r),s=i.get(r)||0;i.set(r,s+1);try{const i=o.length,s=o[t].apply(o,n);if("push"===t){const t=o.length-n.length;for(let i=0;i<n.length;i++){const n=o[t+i];e.isObject(n)&&!p(n)&&c(r,String(t+i),w(n))}v(r,{type:"array-push",index:t,values:n})}else if("pop"===t)l(r,String(i-1)),v(r,{type:"array-splice",index:i-1,deleteCount:1,insert:[]});else if(a(o,r),"unshift"===t)v(r,{type:"array-push",index:0,values:n});else if("shift"===t)v(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...i]=n;v(r,{type:"array-splice",index:e,deleteCount:t,insert:i})}return s}finally{i.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{R[e]=function(...t){const n=this,r=f(n),o=i.get(n)||0;i.set(n,o+1);try{const i=r[e].apply(r,t);return a(r,n),v(n,{type:"array-reset",method:e}),i}finally{i.set(n,o)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{R[e]=function(t,...n){const r=f(this);let i=r[e].apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=r[e].apply(r,[f(t),...n])),i}});const j={get(n,r,i){var s;if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(R,r))return Reflect.get(R,r,i);const l=Reflect.get(n,r,i);if("symbol"==typeof r)return l;if(e.isObject(l)&&!p(l)){const e=w(l);return(null==(s=o.get(i))?void 0:s.get(r))!==e&&c(i,r,e),e}return l},set(t,n,r,o){const s=Reflect.get(t,n,o);if(Object.is(s,r))return!0;const a=Reflect.set(t,n,r,o);return!!a&&(e.isObject(r)&&!p(r)?c(o,n,w(r)):l(o,n),0===(i.get(o)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(r)?v(o,{type:"array-replace",oldValue:s,newValue:r}):v(o,{type:"set",key:n,newValue:r,oldValue:s})),a)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),o=Reflect.deleteProperty(e,t);if(o){const o=n.get(e);o&&(l(o,t),0===(i.get(o)||0)&&v(o,{type:"delete",key:t,oldValue:r}))}return o}};function w(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const i=new Proxy(e,j);return n.set(e,i),i}exports.isProxy=y,exports.observe=function(t,n,i={}){const{throttle:o=0,onBatch:s,immediate:c=!1,deepCompare:l}=i,a={callback:n,onBatch:s,throttle:o,filterRegexes:(Array.isArray(i.filter)?i.filter:i.filter?[i.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=h.get(e);if(t)return t;let n="";for(let c=0;c<e.length;c++){const t=e[c];"*"===t&&"*"===e[c+1]?(n+="**",c++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),i=[];for(let c=0;c<r.length;c++){const e=r[c];"**"===e?1===r.length?i.push(".*"):0===c?i.push("(?:[^.]+\\.)*"):i.push("(?:\\.[^.]+)*"):"*"===e?i.push("[^.]+"):i.push(e)}let o="^";for(let c=0;c<i.length;c++)if(o+=i[c],c<i.length-1){const e=i[c],t=i[c+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;o+="\\."}o+="$";const s=new RegExp(o);return h.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:l},u=w(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(a),c){const n=[...y],r=(t,i,o=[],s=new WeakSet)=>{e.isObject(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(c=>{const l=Reflect.get(t,c);if(e.isObject(l)&&s.has(l))return;const a=Reflect.get(i,c),f=[...o,c];n.forEach(e=>{g(f,e.filterRegexes)&&b(e,{type:"set",key:c,newValue:l,oldValue:void 0,path:f})}),e.isObject(l)&&!p(l)&&r(l,a,f,s)}))};r(f(t),u)}const d=()=>{const e=r.get(u);e&&(e.delete(a),0===e.size&&r.delete(u)),a.pending=[],a.timer&&(clearTimeout(a.timer),a.timer=null)};return{proxy:u,unobserve:()=>{a.active&&(a.active=!1,d())},resume:()=>{a.active||(a.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(a)})())},dispose:()=>{if(!a.active)return a.callback=()=>{},void(a.onBatch=void 0);a.active=!1,d(),a.callback=()=>{},a.onBatch=void 0}}},exports.toProxy=function(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e},exports.toRaw=f;
@@ -1,6 +1,4 @@
1
- /** 路径键类型 - 用于表示对象路径的字符串或符号 */
2
1
  export type PathKey = string | symbol;
3
- /** 变更项的原始载荷 */
4
2
  export type ChangePayload = {
5
3
  type: 'set';
6
4
  key: PathKey;
@@ -27,51 +25,25 @@ export type ChangePayload = {
27
25
  type: 'array-reset';
28
26
  method: string;
29
27
  };
30
- /** 完整的变更对象 */
31
28
  export type ChangeItem = ChangePayload & {
32
29
  path: PathKey[];
33
30
  };
34
- /** 观察选项配置 */
35
31
  export interface ObserveOptions {
36
- /** 节流延迟时间(毫秒),默认 0 表示不节流 */
37
32
  throttle?: number;
38
- /** 批量变更回调,在 throttle 触发时调用 */
39
33
  onBatch?: (changes: ChangeItem[]) => void;
40
- /** 是否立即触发一次所有属性的变更通知 */
41
34
  immediate?: boolean;
42
- /** 路径过滤器,支持通配符 * 和 ** */
43
35
  filter?: string | string[];
44
- /** 是否启用深度比较 */
36
+ /** 是否启用深度比较,默认 false */
45
37
  deepCompare?: boolean;
46
38
  }
47
- /** 观察返回值 */
48
39
  export interface ObserveReturn<T> {
49
- /** 响应式代理对象 */
50
40
  proxy: T;
51
- /** 暂停观察,可以调用 resume 恢复 */
52
41
  unobserve: () => void;
53
- /** 恢复观察 */
54
42
  resume: () => void;
55
- /** 彻底销毁,释放所有资源,不可恢复 */
56
43
  dispose: () => void;
57
44
  }
58
- /**
59
- * 将 Proxy 还原为原始对象
60
- * @param observed 观察对象
61
- * @returns 原始对象
62
- */
63
45
  export declare function toRaw<T>(observed: T): T;
64
- /**
65
- * 检查一个值是否为响应式代理对象
66
- * @param value 要检查的值
67
- * @returns 如果是代理对象返回 true,否则返回 false
68
- */
69
- export declare function isProxy(value: any): boolean;
70
- /**
71
- * 创建响应式观察对象
72
- * @param value 要观察的目标对象
73
- * @param callback 变更回调函数
74
- * @param options 观察选项配置
75
- * @returns 观察控制对象,包含代理对象和控制方法
76
- */
46
+ export declare function isProxy(value: unknown): boolean;
47
+ export type ReactiveSource<T extends object = object> = T | ObserveReturn<T>;
48
+ export declare function toProxy<T extends object = object>(source: ReactiveSource<T>): T;
77
49
  export declare function observe<T extends object>(value: T, callback: (change: ChangeItem) => void, options?: ObserveOptions): ObserveReturn<T>;
@@ -1 +1 @@
1
- import{isObject as e}from"../../shared/is-object.js";import{IS_DEV as t}from"../../shared/env.js";const r=Symbol("solely.raw"),n=new WeakMap,i=new WeakMap,o=new WeakMap,a=new WeakMap,s=new WeakMap;function l(e){if(e&&"object"==typeof e){const t=e[r];if(t)return t}return e}const c=e=>!(!e||"object"!=typeof e)&&(e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request);function f(e){return!(!e||!e[r])}const u=(e,t,r=new WeakMap,n=0)=>{if(n>10)return e===t;if(e===t)return!0;if(null==e||null==t)return e===t;if("object"!=typeof e||"object"!=typeof t)return e===t;if(Array.isArray(e)!==Array.isArray(t))return!1;if(r.has(e))return r.get(e)===t;if(r.set(e,t),Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!u(e[i],t[i],r,n+1))return!1;return!0}const i=Reflect.ownKeys(e);if(i.length!==Reflect.ownKeys(t).length)return!1;for(const o of i){if(!Reflect.has(t,o))return!1;const i=e[o],a=t[o];if(!u(i,a,r,n+1))return!1}return!0},p=(e,t)=>{if(0===t.length)return!0;const r=e.map(String).join(".");return t.some(e=>e.test(r))},y=(e,t)=>{const r=(e=>{const t=[];let r=e;for(;r;){const e=o.get(r);if(!e||null==e.key)break;t.unshift(e.key),r=e.parent}return t})(e);let i=e,a=0;for(;i;){const e=n.get(i);if(e){const n=r.slice(r.length-a);e.forEach(e=>{if(!e.active)return;if(!p(n,e.filterRegexes))return;const r={...t,path:n};e.throttle>0?(e.pending.push(r),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([r]):e.callback(r)})}const s=o.get(i);i=(null==s?void 0:s.parent)||null,a++}};function h(p,h,d={}){const{throttle:g=0,onBatch:m,immediate:w=!1,deepCompare:b=!1}=d,v={callback:h,onBatch:m,throttle:g,filterRegexes:(Array.isArray(d.filter)?d.filter:d.filter?[d.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=e.replace(/\./g,"\\.").replace(/\*\*/g,"(.+)").replace(/\*/g,"[^.]+").replace(/\[\d+\]/g,"\\[\\d+\\]");return new RegExp(`^${t}$`)}),pending:[],timer:null,active:!0},A=(n,p,h)=>{if(!Object.isExtensible(n))return n;if(c(n))return n;if(n[r])return n;const d=i.get(n);if(d)return d;const g=new Proxy(n,{get(t,n,i){if(n===r)return t;if(Array.isArray(t)){const e=a.get(g);if(e&&Object.prototype.hasOwnProperty.call(e,n))return Reflect.get(e,n,i)}const o=Reflect.get(t,n,i);return"symbol"==typeof n?o:e(o)&&!c(o)?A(o,g,n):o},set(e,r,n,i){if(!v.active)return t&&console.warn("[Solely] Cannot set property on a disposed reactive object"),!0;const o=e[r];if(b?u(o,n):o===n)return!0;const a=Reflect.set(e,r,n,i);return 0===(s.get(g)||0)&&(Array.isArray(o)&&Array.isArray(n)?y(g,{type:"array-replace",oldValue:o,newValue:n}):y(g,{type:"set",key:r,newValue:n,oldValue:o})),a},deleteProperty(e,r){if(!v.active)return t&&console.warn("[Solely] Cannot delete property on a disposed reactive object"),!0;if(!Reflect.has(e,r))return!1;const n=e[r],i=Reflect.deleteProperty(e,r),o=s.get(g)||0;return i&&0===o&&y(g,{type:"delete",key:r,oldValue:n}),i}});return i.set(n,g),o.set(g,{parent:p,key:h}),Array.isArray(n)&&a.set(g,((e,t,r)=>{const n={};return["push","pop","shift","unshift","splice"].forEach(i=>{n[i]=function(...n){if(!t)return;const o=s.get(t)||0;s.set(t,o+1);const a=e[i].apply(e,n);if(s.set(t,o),"push"===i)r(t,{type:"array-push",index:e.length-n.length,values:n});else if("unshift"===i)r(t,{type:"array-push",index:0,values:n});else if("pop"===i)r(t,{type:"array-splice",index:e.length,deleteCount:1,insert:[]});else if("shift"===i)r(t,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===i){const[e,i,...o]=n;r(t,{type:"array-splice",index:e,deleteCount:i,insert:o})}return a}}),["sort","reverse","fill","copyWithin"].forEach(i=>{n[i]=function(...n){if(!t)return;const o=s.get(t)||0;s.set(t,o+1);const a=e[i].apply(e,n);return s.set(t,o),r(t,{type:"array-reset",method:i}),a}}),["indexOf","lastIndexOf","includes"].forEach(t=>{n[t]=function(r,...n){let i=e[t].apply(e,[r,...n]);return-1!==i&&!1!==i||!f(r)||(i=e[t].apply(e,[l(r),...n])),i}}),n})(n,g,y)),g},k=A(p,null,null);let x=n.get(k);if(x||(x=new Set,n.set(k,x)),x.add(v),w){const t=(r,n,i=new WeakSet)=>{e(r)&&!i.has(r)&&(i.add(r),Reflect.ownKeys(r).forEach(o=>{const a=r[o];e(a)&&i.has(a)||(y(n,{type:"set",key:o,newValue:a,oldValue:void 0}),e(a)&&t(a,A(a,n,o),i))}))};t(p,k)}return{proxy:k,unobserve:()=>{v.active=!1,v.pending=[],v.timer&&(clearTimeout(v.timer),v.timer=null);const e=n.get(k);e&&e.delete(v)},resume:()=>{if(v.active)return;v.active=!0;let e=n.get(k);e||(e=new Set,n.set(k,e)),e.has(v)||e.add(v)},dispose:()=>{v.active=!1,v.pending=[],v.timer&&(clearTimeout(v.timer),v.timer=null);const e=n.get(k);e&&e.delete(v),v.callback=()=>{},v.onBatch=void 0}}}export{f as isProxy,h as observe,l as toRaw};
1
+ import{isObject as e}from"../../shared/is-object.js";const t=Symbol("solely.raw"),n=new WeakMap,r=new WeakMap,i=new WeakMap,o=new WeakMap,s=new WeakMap;function l(e,t,n){c(e,t);let r=o.get(e);r||(r=new Map,o.set(e,r)),r.set(t,n);let i=s.get(n);i||(i=[],s.set(n,i)),i.some(n=>n.parentRef.deref()===e&&n.key===t)||i.push({parentRef:new WeakRef(e),key:t})}function c(e,t){const n=o.get(e);if(!n)return;const r=n.get(t);if(!r)return;n.delete(t);const i=s.get(r);if(i){const n=i.filter(n=>{const r=n.parentRef.deref();return void 0!==r&&!(r===e&&n.key===t)});0===n.length?s.delete(r):s.set(r,n)}}function a(t,n){const r=o.get(n);if(r)for(const e of r.keys())c(n,e);for(let i=0;i<t.length;i++){const r=t[i];e(r)&&!p(r)&&l(n,String(i),k(r))}}function f(e){if(e&&"object"==typeof e){const n=e[t];if(n)return n}return e}const u=Object.prototype.toString,p=e=>{if(!e||"object"!=typeof e)return!1;const t=u.call(e);return"[object Date]"===t||"[object RegExp]"===t||"[object Map]"===t||"[object Set]"===t||e instanceof File||e instanceof Blob||e instanceof FormData||e instanceof ArrayBuffer||e instanceof Response||e instanceof Request};function y(e){return!(!e||!e[t])}function h(e){return e&&"object"==typeof e&&"proxy"in e?e.proxy:e}const g=new Map,d=(e,t)=>{if(0===t.length)return!0;const n=e.map(String);for(let r=n.length;r>0;r--){const e=n.slice(0,r).join(".");if(t.some(t=>t.test(e)))return!0}return!1},v=(e,t)=>{if(Object.is(e,t))return!0;if("object"!=typeof e||null===e||"object"!=typeof t||null===t)return!1;if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!v(e[n],t[n]))return!1;return!0}if(Array.isArray(e)!==Array.isArray(t))return!1;const n=Reflect.ownKeys(e),r=Reflect.ownKeys(t);if(n.length!==r.length)return!1;for(const i of n){if(!Reflect.has(t,i))return!1;if(!v(e[i],t[i]))return!1}return!0},b=(e,t)=>{e.active&&(e.deepCompare&&"set"===t.type&&v(t.oldValue,t.newValue)||(e.throttle>0?(e.pending.push(t),e.timer||(e.timer=setTimeout(()=>{if(!e.active)return;const t=[...e.pending];e.pending=[],e.timer=null,t.length>0&&(e.onBatch?e.onBatch(t):e.callback(t[t.length-1]))},e.throttle))):e.onBatch?e.onBatch([t]):e.callback(t)))},m=(e,t)=>{const n=[{node:e,relativePath:[],visited:new Set([e])}];let i=0;for(;i<n.length;){const{node:e,relativePath:o,visited:l}=n[i++],c=r.get(e);c&&c.forEach(e=>{if(!e.active)return;let n=o;if("set"===t.type||"delete"===t.type?n=[...o,t.key]:"array-push"!==t.type&&"array-splice"!==t.type||(n=[...o,String(t.index)]),!d(n,e.filterRegexes))return;const r={...t,path:n};b(e,r)});const a=s.get(e);if(a)for(let t=a.length-1;t>=0;t--){const e=a[t],r=e.parentRef.deref();if(!r){a.splice(t,1);continue}if(l.has(r))continue;const i=new Set(l);i.add(r),n.push({node:r,relativePath:[e.key,...o],visited:i})}}},R={};["push","pop","shift","unshift","splice"].forEach(t=>{R[t]=function(...n){const r=this,o=f(r),s=i.get(r)||0;i.set(r,s+1);try{const i=o.length,s=o[t].apply(o,n);if("push"===t){const t=o.length-n.length;for(let i=0;i<n.length;i++){const n=o[t+i];e(n)&&!p(n)&&l(r,String(t+i),k(n))}m(r,{type:"array-push",index:t,values:n})}else if("pop"===t)c(r,String(i-1)),m(r,{type:"array-splice",index:i-1,deleteCount:1,insert:[]});else if(a(o,r),"unshift"===t)m(r,{type:"array-push",index:0,values:n});else if("shift"===t)m(r,{type:"array-splice",index:0,deleteCount:1,insert:[]});else if("splice"===t){const[e,t,...i]=n;m(r,{type:"array-splice",index:e,deleteCount:t,insert:i})}return s}finally{i.set(r,s)}}}),["sort","reverse","fill","copyWithin"].forEach(e=>{R[e]=function(...t){const n=this,r=f(n),o=i.get(n)||0;i.set(n,o+1);try{const i=r[e].apply(r,t);return a(r,n),m(n,{type:"array-reset",method:e}),i}finally{i.set(n,o)}}}),["indexOf","lastIndexOf","includes"].forEach(e=>{R[e]=function(t,...n){const r=f(this);let i=r[e].apply(r,[t,...n]);return-1!==i&&!1!==i||!y(t)||(i=r[e].apply(r,[f(t),...n])),i}});const w={get(n,r,i){var s;if(r===t)return n;if(Array.isArray(n)&&Object.prototype.hasOwnProperty.call(R,r))return Reflect.get(R,r,i);const c=Reflect.get(n,r,i);if("symbol"==typeof r)return c;if(e(c)&&!p(c)){const e=k(c);return(null==(s=o.get(i))?void 0:s.get(r))!==e&&l(i,r,e),e}return c},set(t,n,r,o){const s=Reflect.get(t,n,o);if(Object.is(s,r))return!0;const a=Reflect.set(t,n,r,o);return!!a&&(e(r)&&!p(r)?l(o,n,k(r)):c(o,n),0===(i.get(o)||0)&&(!Array.isArray(t)&&Array.isArray(s)&&Array.isArray(r)?m(o,{type:"array-replace",oldValue:s,newValue:r}):m(o,{type:"set",key:n,newValue:r,oldValue:s})),a)},deleteProperty(e,t){if(!Reflect.has(e,t))return!1;const r=Reflect.get(e,t),o=Reflect.deleteProperty(e,t);if(o){const o=n.get(e);o&&(c(o,t),0===(i.get(o)||0)&&m(o,{type:"delete",key:t,oldValue:r}))}return o}};function k(e){if(!Object.isExtensible(e))return e;if(p(e))return e;if(e[t])return e;const r=n.get(e);if(r)return r;const i=new Proxy(e,w);return n.set(e,i),i}function x(t,n,i={}){const{throttle:o=0,onBatch:s,immediate:l=!1,deepCompare:c}=i,a={callback:n,onBatch:s,throttle:o,filterRegexes:(Array.isArray(i.filter)?i.filter:i.filter?[i.filter]:[]).map(e=>{if(""===e)return/^.*$/;const t=g.get(e);if(t)return t;let n="";for(let l=0;l<e.length;l++){const t=e[l];"*"===t&&"*"===e[l+1]?(n+="**",l++):"*"===t?n+="*":"."===t?n+=".":/[.*+?^${}()|[\]\\]/.test(t)?n+="\\"+t:n+=t}const r=n.split("."),i=[];for(let l=0;l<r.length;l++){const e=r[l];"**"===e?1===r.length?i.push(".*"):0===l?i.push("(?:[^.]+\\.)*"):i.push("(?:\\.[^.]+)*"):"*"===e?i.push("[^.]+"):i.push(e)}let o="^";for(let l=0;l<i.length;l++)if(o+=i[l],l<i.length-1){const e=i[l],t=i[l+1];if(e.endsWith("\\.)*"))continue;if(t.startsWith("(?:\\."))continue;o+="\\."}o+="$";const s=new RegExp(o);return g.set(e,s),s}),pending:[],timer:null,active:!0,deepCompare:c},u=k(t);let y=r.get(u);if(y||(y=new Set,r.set(u,y)),y.add(a),l){const n=[...y],r=(t,i,o=[],s=new WeakSet)=>{e(t)&&!s.has(t)&&(s.add(t),Reflect.ownKeys(t).forEach(l=>{const c=Reflect.get(t,l);if(e(c)&&s.has(c))return;const a=Reflect.get(i,l),f=[...o,l];n.forEach(e=>{d(f,e.filterRegexes)&&b(e,{type:"set",key:l,newValue:c,oldValue:void 0,path:f})}),e(c)&&!p(c)&&r(c,a,f,s)}))};r(f(t),u)}const h=()=>{const e=r.get(u);e&&(e.delete(a),0===e.size&&r.delete(u)),a.pending=[],a.timer&&(clearTimeout(a.timer),a.timer=null)};return{proxy:u,unobserve:()=>{a.active&&(a.active=!1,h())},resume:()=>{a.active||(a.active=!0,(()=>{let e=r.get(u);e||(e=new Set,r.set(u,e)),e.add(a)})())},dispose:()=>{if(!a.active)return a.callback=()=>{},void(a.onBatch=void 0);a.active=!1,h(),a.callback=()=>{},a.onBatch=void 0}}}export{y as isProxy,x as observe,h as toProxy,f as toRaw};
@@ -0,0 +1 @@
1
+ "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./observe.cjs");exports.watch=function(o,r,t={}){const s=e.toProxy(o);if(!e.isProxy(s))throw new Error("[solely] watch: source 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const n=e.observe(s,r,{deepCompare:t.deepCompare,throttle:t.throttle,immediate:t.immediate});return{dispose:()=>n.dispose(),pause:()=>n.unobserve(),resume:()=>n.resume()}},exports.watchGetter=function(o,r,t,s={}){let n,i=!1;const c=[],u=()=>{if(i)return;const e=r();e!==n&&(t(e,n),n=e)};for(const p of o){const o=e.toProxy(p);if(!e.isProxy(o))throw new Error("[solely] watchGetter: sources 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const r=e.observe(o,u,{deepCompare:s.deepCompare,throttle:s.throttle});c.push(r)}return s.immediate&&(n=r(),t(n,void 0)),{dispose:()=>{if(!i){i=!0;for(const e of c)e.dispose();c.length=0}},pause:()=>{for(const e of c)e.unobserve()},resume:()=>{for(const e of c)e.resume()}}};
@@ -0,0 +1,64 @@
1
+ import { ChangeItem, ReactiveSource } from './observe';
2
+ /** watch 选项 */
3
+ export interface WatchOptions {
4
+ /** 是否启用深度比较,默认 false */
5
+ deepCompare?: boolean;
6
+ /** 是否立即执行一次回调,默认 false */
7
+ immediate?: boolean;
8
+ /** 节流延迟时间(毫秒),默认 0 表示不节流 */
9
+ throttle?: number;
10
+ }
11
+ /** watch 返回值 */
12
+ export interface WatchReturn {
13
+ /** 停止侦听 */
14
+ dispose: () => void;
15
+ /** 暂停侦听 */
16
+ pause: () => void;
17
+ /** 恢复侦听 */
18
+ resume: () => void;
19
+ }
20
+ /**
21
+ * 侦听响应式代理对象的变化
22
+ *
23
+ * observe 的便捷封装:给已有的响应式对象追加观察者,不返回 proxy。
24
+ * 接受 observe() 返回值或 proxy 对象。
25
+ *
26
+ * @param source observe 返回值 或 响应式代理对象
27
+ * @param callback 变更回调函数
28
+ * @param options 选项
29
+ * @returns 侦听控制对象
30
+ *
31
+ * @example
32
+ * ```ts
33
+ * // 方式1:传入 observe 返回值
34
+ * const obs = observe({ count: 0 }, () => {});
35
+ * watch(obs, (change) => console.log('changed:', change));
36
+ *
37
+ * // 方式2:传入 proxy(如组件中的 $data)
38
+ * watch(this.$data, (change) => console.log('changed:', change));
39
+ * ```
40
+ */
41
+ export declare function watch<T extends object = object>(source: ReactiveSource<T>, callback: (change: ChangeItem) => void, options?: WatchOptions): WatchReturn;
42
+ /**
43
+ * 侦听一个 getter 函数的返回值变化
44
+ *
45
+ * 当 getter 中访问的响应式数据变化时,重新计算 getter 并比较新旧值,
46
+ * 如果值发生变化则执行回调。
47
+ *
48
+ * @param sources 依赖的响应式代理对象数组
49
+ * @param getter 计算函数
50
+ * @param callback 值变化回调
51
+ * @param options 选项
52
+ * @returns 侦听控制对象
53
+ *
54
+ * @example
55
+ * ```ts
56
+ * const { proxy } = observe({ a: 1, b: 2 }, () => {});
57
+ * const watcher = watchGetter(
58
+ * [proxy],
59
+ * () => proxy.a + proxy.b,
60
+ * (newVal, oldVal) => console.log(`${oldVal} -> ${newVal}`)
61
+ * );
62
+ * ```
63
+ */
64
+ export declare function watchGetter<T>(sources: ReactiveSource[], getter: () => T, callback: (newValue: T, oldValue: T | undefined) => void, options?: WatchOptions): WatchReturn;
@@ -0,0 +1 @@
1
+ import{toProxy as e,isProxy as o,observe as r}from"./observe.js";function t(t,s,n={}){const i=e(t);if(!o(i))throw new Error("[solely] watch: source 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const p=r(i,s,{deepCompare:n.deepCompare,throttle:n.throttle,immediate:n.immediate});return{dispose:()=>p.dispose(),pause:()=>p.unobserve(),resume:()=>p.resume()}}function s(t,s,n,i={}){let p,c=!1;const m=[],u=()=>{if(c)return;const e=s();e!==p&&(n(e,p),p=e)};for(const f of t){const t=e(f);if(!o(t))throw new Error("[solely] watchGetter: sources 必须是响应式代理对象或 observe 返回值,请先调用 observe()");const s=r(t,u,{deepCompare:i.deepCompare,throttle:i.throttle});m.push(s)}return i.immediate&&(p=s(),n(p,void 0)),{dispose:()=>{if(!c){c=!0;for(const e of m)e.dispose();m.length=0}},pause:()=>{for(const e of m)e.unobserve()},resume:()=>{for(const e of m)e.resume()}}}export{t as watch,s as watchGetter};
@@ -1 +1 @@
1
- "use strict";var t=Object.defineProperty,e=(e,s,n)=>((e,s,n)=>s in e?t(e,s,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[s]=n)(e,"symbol"!=typeof s?s+"":s,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const s=require("../../types/ast.cjs"),n=require("../../shared/templateError.cjs"),o=require("../../shared/env.cjs"),r=require("./html-decode.cjs"),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 n=null==(s=e.a)?void 0:s.find(t=>"class"===t.k&&!t.d);(null==n?void 0:n.v)&&t.setAttribute("class",n.v)}function m(t,e){var s;if(!t.style)return;const n=null==(s=e.a)?void 0:s.find(t=>"style"===t.k&&!t.d),o=n?S(n.v):{};for(const r in o){const e=o[r];r.startsWith("--")?t.style.setProperty(r,e):t.style[r]=e}}const y=t=>!(!t||0===t.length||/\s/.test(t)&&(o.IS_DEV&&console.warn(`[Solely] Invalid class name "${t}" contains whitespace, will be ignored`),1));function S(t){const e={},s=[[t]];for(;s.length;){const[t,n]=s.pop()||[];if(t){if("string"==typeof t){const s=/([^:;]+)\s*:\s*([^;]*\(.*?\)[^;]*|[^;]+)/g;let n;for(;null!==(n=s.exec(t));){const t=n[1].trim(),s=n[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 o in t){const r=t[o];if(null==r)continue;const i=n?`${n}-${o}`:o;"object"!=typeof r||Array.isArray(r)?e[i]=String(r):s.push([r,i])}}}return e}function v(t,e,s){const n=null==s?"":String(s),o=e.indexOf(":");if(o>0){const s=e.slice(0,o),r=h[s];if(r)return void(t.getAttributeNS(r,e)!==n&&t.setAttributeNS(r,e,n))}t.getAttribute(e)!==n&&t.setAttribute(e,n)}function b(t,e,s,n){const o=p[e]||e;if(e.startsWith("data-")||e.startsWith("aria-")||d.has(e))return void v(t,e,s);const r=t,i=r.tagName;if(null!=s){if("src"===o||"href"===o){const e=String(s);if(r[o]===e||t.getAttribute(o)===e)return}if("value"!==o||"INPUT"!==i&&"TEXTAREA"!==i||r.value!==s)if("boolean"!=typeof s)(n??(t instanceof SVGElement||void 0!==r.ownerSVGElement))&&!p[e]?v(t,e,s):r[o]!==s&&(r[o]=s);else{if(r[o]===s)return;r[o]=s}}else if("boolean"==typeof r[o])!1!==r[o]&&(r[o]=!1);else{const s=r[o];""!==s&&void 0!==s&&(r[o]=""),t.hasAttribute(e)&&t.removeAttribute(e)}}class g{constructor(t,s,n={}){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=n}evalIR(t,e,s){var r;const i=this.ir.fns[t-1];if(o.IS_DEV)try{return i?i.apply(this.scope,e):""}catch(a){return n.showTemplateError(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.default(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,n=!1){const o=[],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:y,v:S}=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),o=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)})),!n){const t=t=>this.evalIR(l??-1,[t,r[i].loops],c.__m);h[o].push(t)}continue}if("mounted"===e){n||requestAnimationFrame(()=>this.evalIR(l??-1,[t,s],c.__m));continue}if("updated"===e){n&&requestAnimationFrame(()=>this.evalIR(l??-1,[t,s],c.__m));continue}if("ref"===e&&S){this.scope.$refs=this.scope.$refs||{},this.scope.$refs[S]=t;continue}const N=y?this.evalIR(l??-1,[s],c.__m):S??"";if(":"===g){const s=e.slice(1);"SELECT"===t.tagName&&u.has(s)?o.push(()=>b(t,s,N,h)):b(t,s,N,h)}else n||v(t,e,String(N))}return f&&((t,e)=>{const s=t,n=s[c],o=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 n=s[t].trim();n&&(e[n]=!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 o)y(a)&&(r[a]=o[a]);if(!n){for(const e in r)t.classList.add(e);return void(s[c]=r)}let i=!1;for(const a in n)r[a]||(t.classList.remove(a),i=!0);for(const a in r)n[a]||(t.classList.add(a),i=!0);i&&(s[c]=r)})(t,p),m&&((t,e)=>{const s=t,n=S(e),o=s[l];if(!o){for(const e in n){const s=n[e];e.startsWith("--")?t.style.setProperty(e,s):t.style[e]=s}return void(s[l]=n)}let r=!1;for(const i in o)i in n||(i.startsWith("--")?t.style.removeProperty(i):t.style[i]="",r=!0);for(const i in n){const e=n[i];e!==o[i]&&(i.startsWith("--")?t.style.setProperty(i,e):t.style[i]=e,r=!0)}r&&(s[l]=n)})(t,d),o}updateNode(t,e,s){const n=e.d?this.evalIR(e.f??-1,[s],e.__m):e.x||"";e.d&&t.textContent!==n&&(t.textContent=n)}createStaticSubtree(t,e,n){var o;switch(t.t){case s.ASTType.Element:{const s=this.createElement(t,e);f(s,t),m(s,t);const r=this.applyAttrs(s,t.a??[],n);return null==(o=t.c)||o.forEach(t=>{const e=this.createStaticSubtree(t,s,n);s.appendChild(e)}),r.forEach(t=>t()),s}case s.ASTType.Text:return this.createText(t,n);case s.ASTType.Comment:return this.createComment(t,n);default:return document.createComment("unknown")}}handleStaticSubtree(t,e,s,n){const o=this.staticSubtreeCache.get(e);if(o){const t=o.cloneNode(!0);return s.appendChild(t),t}const r=this.createStaticSubtree(t,s,n);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,n){this.pathStack.push(e),this.processNode(t,s,n),this.pathStack.pop()}processNode(t,e,n){var o,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.ASTType.Element?e=this.applyAttrs(u,t.a??[],n,!0):this.updateNode(u,t,n)),null==(o=t.c)||o.forEach((t,e)=>{this.pathStack.push(e),this.processNode(t,u,n),this.pathStack.pop()}),e.forEach(t=>t())}else switch(t.t){case s.ASTType.Element:u=this.createElement(t,e),f(u,t),m(u,t);const o=this.applyAttrs(u,t.a??[],n);e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:n}),null==(r=t.c)||r.forEach((t,e)=>{this.pathStack.push(e),this.processNode(t,u,n),this.pathStack.pop()}),o.forEach(t=>t());break;case s.ASTType.Text:u=this.createText(t,n),e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:n});break;case s.ASTType.Comment:u=this.createComment(t,n),e.appendChild(u),this.nodeMap.set(p,{irNode:t,node:u,loops:n});break;case s.ASTType.For:{this.pathStack.push(-1);const o=this.currentKey();this.pathStack.pop();let r=null==(i=this.findEntry(o))?void 0:i.node;r||(r=document.createComment("for"),e.appendChild(r),this.nodeMap.set(o,{irNode:{t:s.ASTType.Comment},node:r,loops:n}));const c=this.evalIR(t.f??-1,[n],t.__m)||[],l=document.createDocumentFragment();c.forEach((e,s)=>{var o;const r=[...n,{itmVal:e,idxVal:s}];null==(o=t.c)||o.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.ASTType.Conditional:{this.pathStack.push(-1);const s=this.currentKey();this.pathStack.pop();let o=null==(c=this.findEntry(s))?void 0:c.node;o||(o=document.createComment("if"),e.appendChild(o),this.nodeMap.set(s,{irNode:{},node:o,loops:n}));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,[n],s.__m)){const t=document.createDocumentFragment();s.c.forEach((s,o)=>{this.pathStack.push(e,o),this.processNode(s,t,n),this.pathStack.pop(),this.pathStack.pop()}),null==(h=o.parentNode)||h.insertBefore(t,o);break}}break}}else d?u=d.node:(u=this.handleStaticSubtree(t,p,e,n),this.nodeMap.set(p,{irNode:t,node:u,loops:n}))}cleanupOldNodes(){const t=this.prevNodeMap;for(const[,e]of t.entries()){const{irNode:t,node:s,loops:n}=e;if(t.a){const e=t.a.find(t=>"unmounted"===t.k);e&&requestAnimationFrame(()=>{this.evalIR(e.f??-1,[s,n],e.__m)});const o=t.a.find(t=>"ref"===t.k);o&&o.v&&delete this.scope.$refs[o.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()}}exports.IRRenderer=g,exports.createRender=(t,e,s={})=>{const n=new g(t,e,s);return n.mount(),{update:()=>n.update(),destroy:()=>n.destroy()}};
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()}};