@cat-of-summer/st-script 1.5.0 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app/datepicker.min.js +3 -3
- package/dist/app/datepicker.min.js.map +3 -3
- package/dist/app/form.min.js +1 -1
- package/dist/app/form.min.js.map +3 -3
- package/dist/app.esm.min.js +1 -1
- package/dist/app.esm.min.js.map +3 -3
- package/dist/app.min.js +1 -1
- package/dist/app.min.js.map +3 -3
- package/dist/core.esm.min.js +1 -1
- package/dist/core.esm.min.js.map +3 -3
- package/dist/core.min.js +1 -1
- package/dist/core.min.js.map +3 -3
- package/dist/loader.esm.min.js +1 -1
- package/dist/loader.esm.min.js.map +3 -3
- package/dist/loader.min.js +1 -1
- package/dist/loader.min.js.map +3 -3
- package/dist/mask.esm.min.js +1 -1
- package/dist/mask.esm.min.js.map +3 -3
- package/dist/mask.min.js +1 -1
- package/dist/mask.min.js.map +3 -3
- package/dist/modal.esm.min.js +1 -1
- package/dist/modal.esm.min.js.map +3 -3
- package/dist/modal.min.js +1 -1
- package/dist/modal.min.js.map +3 -3
- package/dist/observer.esm.min.js +1 -1
- package/dist/observer.esm.min.js.map +3 -3
- package/dist/observer.min.js +1 -1
- package/dist/observer.min.js.map +3 -3
- package/dist/route.esm.min.js.map +2 -2
- package/dist/route.min.js +1 -1
- package/dist/route.min.js.map +2 -2
- package/dist/select.esm.min.js +1 -1
- package/dist/select.esm.min.js.map +3 -3
- package/dist/select.min.js +1 -1
- package/dist/select.min.js.map +3 -3
- package/dist/shape.esm.min.js +1 -1
- package/dist/shape.esm.min.js.map +3 -3
- package/dist/shape.min.js +1 -1
- package/dist/shape.min.js.map +3 -3
- package/dist/toggle.esm.min.js +1 -1
- package/dist/toggle.esm.min.js.map +3 -3
- package/dist/toggle.min.js +1 -1
- package/dist/toggle.min.js.map +3 -3
- package/dist/typograf.esm.min.js +1 -1
- package/dist/typograf.esm.min.js.map +3 -3
- package/dist/typograf.min.js +1 -1
- package/dist/typograf.min.js.map +3 -3
- package/dist/uploader.esm.min.js +1 -1
- package/dist/uploader.esm.min.js.map +3 -3
- package/dist/uploader.min.js +1 -1
- package/dist/uploader.min.js.map +3 -3
- package/dist/validator.esm.min.js +1 -1
- package/dist/validator.esm.min.js.map +3 -3
- package/dist/validator.min.js +1 -1
- package/dist/validator.min.js.map +3 -3
- package/docs/README.md +59 -5
- package/docs/src/app/index.js.md +91 -7
- package/docs/src/core/index.js.md +51 -5
- package/docs/src/loader/index.js.md +2 -1
- package/docs/src/mask/index.js.md +2 -1
- package/docs/src/modal/index.js.md +14 -2
- package/docs/src/observer/index.js.md +2 -2
- package/docs/src/select/index.js.md +1 -1
- package/docs/src/shape/index.js.md +2 -1
- package/docs/src/toggle/index.js.md +53 -21
- package/docs/src/typograf/index.js.md +2 -2
- package/docs/src/uploader/index.js.md +2 -1
- package/docs/src/validator/index.js.md +2 -1
- package/package.json +1 -1
- package/src/_traits/hasInstanceSymbol.js +14 -1
- package/src/app/index.js +102 -15
- package/src/core/index.js +83 -13
- package/src/loader/index.js +13 -3
- package/src/mask/index.js +21 -2
- package/src/modal/index.js +16 -6
- package/src/observer/index.js +3 -3
- package/src/select/index.js +24 -4
- package/src/shape/index.js +9 -0
- package/src/toggle/index.js +85 -28
- package/src/typograf/index.js +3 -3
- package/src/uploader/index.js +32 -9
- package/src/validator/index.js +20 -2
package/dist/app.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var App=(()=>{var j=Object.defineProperty;var L=Object.getOwnPropertyDescriptor;var C=Object.getOwnPropertyNames;var k=Object.prototype.hasOwnProperty;var $=(f,e)=>{for(var t in e)j(f,t,{get:e[t],enumerable:!0})},W=(f,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let s of C(e))!k.call(f,s)&&s!==t&&j(f,s,{get:()=>e[s],enumerable:!(i=L(e,s))||i.enumerable});return f};var R=f=>W(j({},"__esModule",{value:!0}),f);var V={};$(V,{default:()=>N});var N=class f extends HTMLElement{static#_=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#ee=new Set(["checked","selected","value"]);static#v=new Map;static#c=new Set;static#$=new WeakMap;static#W=new WeakMap;static#p={};static helpers(e={}){return Object.assign(f.#p,e),f.#p}static toRaw(e){return f.#A(e)}static snapshot(e,t=new WeakMap){if(e=f.#A(e),e===null||typeof e!="object")return e;if(t.has(e))return t.get(e);let i=Object.getPrototypeOf(e);if(Array.isArray(e)){let r=[];return t.set(e,r),e.forEach(l=>r.push(f.snapshot(l,t))),r}if(i!==Object.prototype&&i!==null)return e;let s={};t.set(e,s);for(let r of Object.keys(e))s[r]=f.snapshot(e[r],t);return s}static create(e){let{app:t,setup:i=()=>{},template:s="",events:r={}}=e;if(f.#v.has(t))throw new Error(`Application "${t}" already exists!`);f.#v.set(t,{setup:i,template:s,events:r,config:e}),f.#c.forEach(l=>{l.#i!==!0&&l.#Z()})}static extend(e,t={}){let i=f.#v.get(e);if(!i)throw new Error(`Application "${e}" not found!`);let s=i.config,r=Object.defineProperties({},{...Object.getOwnPropertyDescriptors(s),...Object.getOwnPropertyDescriptors(t)});return(s.events||t.events)&&(r.events={...s.events,...t.events}),(s.helpers||t.helpers)&&(r.helpers={...s.helpers,...t.helpers}),f.create(r)}#i=!1;#d="";#R=!1;#s=new Map;#u=null;#o=new Set;#y=!1;#e=[];#r=null;#te=new Map;#l=null;#t=[];#E=new Set;#S=!1;#V=[];#I=new Map;#a=new Map;#D=0;#B="";#T=!1;#H=!1;#w={};#b=new WeakMap;constructor(){super(),f.#c.add(this)}#N(e){!e||!e.length||e.forEach(t=>{if(t.type==="event"&&t.element&&t.handler)setTimeout(()=>t.element.removeEventListener(t.eventName,t.handler));else if(t.type==="model"&&t.element&&t.handler){let i=t.element.tagName==="SELECT"?"change":"input";setTimeout(()=>t.element.removeEventListener(i,t.handler))}else t.type==="attrSync"&&t.unwatch&&t.unwatch();t.dispose?.(),t.effect&&(this.#J(t.effect),this.#o.delete(t.effect),this.#se(t.effect))})}#J(e){this.#s.forEach((t,i)=>{t.delete(e),t.size===0&&this.#s.delete(i)})}#ie(e,t){for(let i=t;i;i=Object.getPrototypeOf(i)){let s=this.#b.get(i);s||this.#b.set(i,s=new Set),s.add(e)}}#se(e){for(let t=e.ctx;t;t=Object.getPrototypeOf(t))this.#b.get(t)?.delete(e)}get template(){return this.#d}get attrs(){return{get:e=>this.getAttribute(e),set:(e,t)=>this.setAttribute(e,t),remove:e=>this.removeAttribute(e),has:e=>this.hasAttribute(e),toggle:(e,t)=>this.toggleAttribute(e,t),keys:()=>Array.from(this.attributes).map(e=>e.name),entries:()=>Array.from(this.attributes).map(e=>[e.name,e.value])}}addEventListener(e,t,i){if((e==="setup"||e==="rendered")&&this.#R){queueMicrotask(()=>{let s=new CustomEvent(e);typeof t=="function"?t.call(this,s):t?.handleEvent?.(s)});return}super.addEventListener(e,t,i)}dispatchEvent(e,t=null,i={}){if(typeof e=="string"){let s=new CustomEvent(e,{cancelable:!0,...i,detail:t});return super.dispatchEvent(s)}return super.dispatchEvent(e)}applyTemplate(e=""){let t=e||this.#d;if(this.#H=!0,this.#B=t,this.#N(this.#e),this.#e=[],this.innerHTML="",t){let s=document.createElement("template");s.innerHTML=t.trim();let r=s.content.cloneNode(!0);this.#Y(r),this.#re(r)}let i=++this.#D;new Promise(s=>{let r=null,l,n=()=>{clearTimeout(r),r=setTimeout(()=>{l.disconnect(),this.#k(Array.from(this.children)).then(s)},0)};l=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&n()}),l.observe(this,{childList:!0}),n()}).then(()=>{i===this.#D&&(this.#R=!0,this.dispatchEvent("rendered"))})}#re(e){HTMLElement.prototype.appendChild.call(this,e)}clone(e={}){let t=this.attrs.get("app");return f.extend(t,e)}watch(e,t,i={}){if(typeof t!="function")return()=>{};let{deep:s=!1,immediate:r=!1}=i;if(typeof e=="string"&&e.endsWith("()")){let l=e.slice(0,-2),n=this[l];if(typeof n!="function")return()=>{};let h=this.#a.get(l);if(!h){h={original:n,handlers:[]},this.#a.set(l,h);let o=(...u)=>{let c=n.apply(this,u),p=d=>{for(let y of[...h.handlers])y.callback(u,d,y.unwatch)};return c instanceof Promise?c.then(d=>(p(d),d)):(p(c),c)};this[l]=o}let a=()=>{let o=h.handlers.findIndex(u=>u.unwatch===a);o!==-1&&h.handlers.splice(o,1),h.handlers.length===0&&(this[l]=h.original,this.#a.delete(l))};return h.handlers.push({callback:t,unwatch:a}),a}if(typeof e=="string"){let l=e,n=()=>{let a=this.#t.findIndex(o=>o.unwatch===n);a!==-1&&this.#t.splice(a,1)},h={type:"key",key:l,callback:t,deep:s,immediate:r,lastValue:void 0,unwatch:n};if(this.#t.push(h),r){let a=this.#z(l);h.lastValue=s&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,t(a,void 0,n)}return n}if(typeof e=="function"){let l=e,n,h={type:"getter",getter:l,callback:t,deep:s,lastValue:n,effect:null,unwatch:null};this.#t.push(h);let a=()=>{let c=this.#t.indexOf(h);c!==-1&&this.#t.splice(c,1),h.effect&&(this.#s.forEach((p,d)=>{p.delete(h.effect),p.size===0&&this.#s.delete(d)}),this.#o.delete(h.effect))};h.unwatch=a;let o=()=>{let c=l.call(this);if(s?!this.#P(c,n):c!==n){let d=n;n=s&&c!==null&&typeof c=="object"?JSON.parse(JSON.stringify(c)):c,t(c,d,h.unwatch)}},u=this.#n(o);return h.effect=u,a}return()=>{}}unwatch(){[...this.#t].forEach(e=>e.unwatch()),this.#a.forEach(e=>{[...e.handlers].forEach(t=>t.unwatch())})}hasWatchers(){let e=0;return this.#a.forEach(t=>{e+=t.handlers.length}),this.#t.length+e}watched(e,t,i={}){if(typeof e=="string"&&e.endsWith("()")){let s=e.slice(0,-2),r=this.#a.get(s);r&&[...r.handlers].forEach(l=>l.unwatch())}else typeof e=="string"?this.#t.filter(s=>s.type==="key"&&s.key===e).forEach(s=>s.unwatch()):typeof e=="function"&&this.#t.filter(s=>s.type==="getter"&&s.getter===e).forEach(s=>s.unwatch());return this.watch(e,t,i)}#x(e){this.#u&&(this.#s.has(e)||this.#s.set(e,new Set),this.#s.get(e).add(this.#u))}#f(e){this.#E.add(e);let t=this.#s.get(e);if(t&&t.forEach(s=>this.#o.add(s)),this.#y){this.#S=!0;return}this.#y=!0;let i=()=>{this.#o.forEach(l=>{try{l()}catch(n){console.error("Effect execution error:",n)}}),this.#o.clear();let s=Array.from(this.#E),r=new Set;for(let l of s)for(let n of this.#t){if(n.type!=="key")continue;(n.key===l||n.deep&&(l===n.key||l.startsWith(n.key+".")))&&r.add(n)}for(let l of r){if(l.type!=="key")continue;let n=this.#z(l.key);if(!(l.deep?!this.#P(n,l.lastValue):n!==l.lastValue))continue;let a=l.lastValue;l.lastValue=l.deep&&n!==null&&typeof n=="object"?JSON.parse(JSON.stringify(n)):n;try{l.callback(n,a,l.unwatch)}catch(o){console.error("Watcher callback error:",o)}}this.#E.clear(),this.#y=!1,this.#S?(this.#S=!1,this.#y=!0,Promise.resolve().then(i)):this.#V.splice(0).forEach(l=>l())};Promise.resolve().then(i)}nextTick(){return this.#y?new Promise(e=>this.#V.push(e)):Promise.resolve()}#z(e){return e.split(".").reduce((t,i)=>t?.[i],this)}#P(e,t){if(Object.is(e,t))return!0;if(e===null||t===null||typeof e!="object"||typeof t!="object")return!1;let i=Object.keys(e),s=Object.keys(t);if(i.length!==s.length)return!1;for(let r of i)if(!s.includes(r)||!this.#P(e[r],t[r]))return!1;return!0}static#A(e){return e!==null&&typeof e=="object"?e.__raw??e:e}#F=new WeakMap;#m(e,t=[]){if(e===null||typeof e!="object"||e.__isReactive)return e;let i=t.join("."),s=this.#F.get(e);if(s||this.#F.set(e,s=new Map),s.has(i))return s.get(i);let r=this,l=new Proxy(e,{get(n,h,a){if(h==="__isReactive")return!0;if(h==="__raw")return n;let o=typeof h=="symbol"?"<symbol>":h,u=[...t,o].join(".");r.#x(u);let c=Reflect.get(n,h,a);return c!==null&&typeof c=="object"&&!c.__isReactive?r.#m(c,[...t,o]):c},set(n,h,a,o){if(n[h]===a)return!0;let c=Reflect.set(n,h,a,o),p=typeof h=="symbol"?"<symbol>":h,d=[...t,p].join(".");if(r.#f(d),Array.isArray(n)&&(h==="length"||!isNaN(h))){let y=t.join(".");y&&r.#f(y)}return c},deleteProperty(n,h){let a=Reflect.deleteProperty(n,h),o=typeof h=="symbol"?"<symbol>":h,u=[...t,o].join(".");return r.#f(u),a}});return s.set(i,l),l}#q(e,t){let i=this;return new Proxy(e,{apply(s,r,l){let n=Reflect.apply(s,i,l);return i.#u?n:n instanceof Promise?n.then(h=>(i.#f(t),h)):(i.#f(t),n)}})}#n(e){let t=this.#r,i=()=>{let s=this.#u;this.#u=i;try{t?this.#g(t,e):e()}finally{this.#u=s}};return t&&(i.ctx=t,this.#ie(i,t)),i(),i}static#K=new Map;static#M(e){let t=f.#K.get(e);return t||(t=new Function("$s","$event","$__v",`with($s) { ${e} }`),f.#K.set(e,t)),t}#le=null;get#L(){return this.#le??=new Proxy(this,{has:(e,t)=>typeof t=="string"&&(t in e||t in this.#w||t in f.#p),get:(e,t)=>{if(t===Symbol.unscopables)return;if(typeof t=="string"&&!(t in e)){if(t in this.#w)return this.#w[t];if(t in f.#p)return f.#p[t]}let i=Reflect.get(e,t);return this.#ne(t,i),typeof i=="function"&&!Object.hasOwn(e,t)?i.bind(e):i},set:(e,t,i)=>Reflect.set(e,t,i)})}#U=new Set;#ne(e,t){if(typeof e!="string"||typeof t=="function"||this.#U.has(e)||this.#r&&e in this.#r)return;let i=Object.getOwnPropertyDescriptor(this,e);!i||!("value"in i)||(this.#U.add(e),console.warn(`<st-app app="${this.getAttribute("app")??""}">: \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u043E "${e}" \u043D\u0435 \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D\u043E \u0432 \u043A\u043E\u043D\u0444\u0438\u0433\u0435 \u0438 \u043D\u0435 \u0440\u0435\u0430\u043A\u0442\u0438\u0432\u043D\u043E`))}#h(e){try{return f.#M(`return (${e});`).call(this,this.#L)}catch(t){console.warn("Expression evaluation error:",e,t);return}}#X(e,t=null){try{return f.#M(e).call(this,this.#L,t)}catch(i){console.error("Statement execution error:",e,i)}}#G(e,t){try{f.#M(`${e} = $__v;`).call(this,this.#L,null,t)}catch(i){console.error("Model binding error:",e,i)}}#he(e){let t=e.nodeValue,i=[],s=[],r=0,l=/\{\{(.+?)\}\}/g,n;for(;(n=l.exec(t))!==null;){n.index>r&&i.push(t.substring(r,n.index));let a=n[1].trim();i.push(null),s.push({index:i.length-1,expr:a}),r=l.lastIndex}r<t.length&&i.push(t.substring(r));let h=this.#n(()=>{s.forEach(({index:a,expr:o})=>{let u=this.#h(o);i[a]=u==null?"":String(u)}),e.nodeValue=i.join("")});this.#e.push({type:"text",node:e,effect:h})}#ae(e,t){let[i,...s]=t.name.slice(1).split("."),r=s.includes("self"),l=t.value,n=this.#r,h=a=>{r&&a.target!==e||(n?this.#g(n,()=>this.#X(l,a)):this.#X(l,a))};e.addEventListener(i,h),this.#e.push({type:"event",element:e,eventName:i,handler:h})}#oe(e,t){let i=t.value,s=this.#n(()=>{let r=this.#h(i);e.innerHTML=r==null?"":String(r)});this.#e.push({type:"html",element:e,effect:s})}#fe(e,t){let i=t.value,s=this.#n(()=>{this.#h(i)?e.style.display="":e.style.display="none"});this.#e.push({type:"show",element:e,effect:s})}#ue(e,t){let i=t.value,s=new Set;f.#W.set(e,s);let r=this.#n(()=>{let l=this.#h(i),n=new Set,h=a=>String(a).split(/\s+/).filter(Boolean).forEach(o=>n.add(o));Array.isArray(l)?l.forEach(a=>a&&h(a)):l&&typeof l=="object"?Object.entries(l).forEach(([a,o])=>o&&h(a)):l&&h(l),s.forEach(a=>n.has(a)||e.classList.remove(a)),n.forEach(a=>e.classList.add(a)),s.clear(),n.forEach(a=>s.add(a))});this.#e.push({type:"class",element:e,effect:r})}#ce(e,t){let i=t.value,s=this.#n(()=>{let h=this.#h(i);if(e.tagName==="INPUT"&&e.type==="checkbox")e.checked=!!h;else if(e.tagName==="INPUT"&&e.type==="radio")e.checked=e.value===h;else if(e.tagName==="SELECT"){let a=()=>{e.value=h};f.#$.set(e,a),a(),queueMicrotask(a)}else e.value=h??""}),r=this.#r,l=e.tagName==="SELECT"?"change":"input",n=h=>{let a;e.type==="checkbox"?a=e.checked:e.type==="number"||e.type==="range"?a=e.value===""?null:e.valueAsNumber:a=e.value,r?this.#g(r,()=>this.#G(i,a)):this.#G(i,a)};e.addEventListener(l,n),this.#e.push({type:"model",element:e,effect:s,handler:n})}#pe(e,t){let i=t.value,s=document.createComment(`if: ${i}`);e.parentNode.insertBefore(s,e),e.removeAttribute(t.name);let r=[{expr:i,template:e.cloneNode(!0)}],l=e.nextElementSibling;for(;l;)if(l.hasAttribute("#else-if")){let o=l.getAttribute("#else-if");l.removeAttribute("#else-if"),r.push({expr:o,template:l.cloneNode(!0)});let u=l.nextElementSibling;l.remove(),l=u}else if(l.hasAttribute("#else")){l.removeAttribute("#else"),r.push({expr:"true",template:l.cloneNode(!0)}),l.remove();break}else break;e.remove();let n={branch:null,node:null,bindings:[]},h=()=>{n.node?.remove(),this.#N(n.bindings),n.node=null,n.bindings=[]},a=this.#n(()=>{let o=r.find(c=>this.#h(c.expr))??null;if(n.branch===o||(h(),n.branch=o,!o))return;let u=o.template.cloneNode(!0);s.parentNode.insertBefore(u,s.nextSibling),n.bindings=this.#Q(()=>this.#C(u)),n.node=u});this.#e.push({type:"conditional",placeholder:s,effect:a,dispose:h})}#Q(e){let t=this.#e.length;return e(),this.#e.splice(t)}#de(e){return Object.assign(Object.create(this.#r??null),e)}#g(e,t){let i={};for(let r in e)i[r]=this[r],this[r]=e[r];let s=this.#r;this.#r=e;try{return t()}finally{this.#r=s;for(let r of Object.keys(i))i[r]!==void 0?this[r]=i[r]:delete this[r]}}#ye(e,t){Object.assign(e.ctx,t);let i=[...this.#b.get(e.ctx)??[]];i.forEach(s=>this.#J(s)),i.forEach(s=>{this.#b.get(e.ctx)?.has(s)&&s()})}#be(e,t){let i=t.value,s=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!s){console.error("Invalid for syntax:",i);return}let r=s[1],l=s[2],n=e.getAttribute("#key");e.removeAttribute(t.name),e.removeAttribute("#key");let h=document.createComment(`for: ${i}`);e.parentNode.insertBefore(h,e);let a=e.cloneNode(!0);e.remove();let o=new Map,u=p=>{p.node.remove(),this.#N(p.bindings)},c=this.#n(()=>{let p=this.#h(l),d=[];Array.isArray(p)?d=p.map((b,m)=>({value:b,key:void 0,index:m})):p!==null&&typeof p=="object"&&(d=Object.entries(p).map(([b,m],v)=>({value:m,key:b,index:v})));let y=new Map,w=[];d.forEach(({value:b,key:m,index:v})=>{let A={[r]:b,$index:v};m!==void 0&&(A.$key=m);let O=this.#de(A),E=n?this.#g(O,()=>this.#h(n)):Symbol();n&&y.has(E)&&console.warn("Duplicate #key in #for:",i,E);let g=o.get(E);if(g&&f.#A(g.value)===f.#A(b)){o.delete(E),(g.value!==b||g.index!==v||g.key!==m)&&(Object.assign(g,{value:b,index:v,key:m}),this.#ye(g,A)),y.set(E,g),w.push(g);return}let T=a.cloneNode(!0),M=this.#g(O,()=>this.#Q(()=>this.#C(T))),P={node:T,bindings:M,value:b,index:v,key:m,ctx:O};y.set(E,P),w.push(P)}),o.forEach(u),o=y;let x=h;for(let b=w.length-1;b>=0;b--){let m=w[b].node;m.nextSibling!==x&&h.parentNode.insertBefore(m,x),x=m}let S=h.parentNode?.closest?.("select");S&&f.#$.get(S)?.()});this.#e.push({type:"loop",anchor:h,template:a,effect:c,dispose:()=>{o.forEach(u),o.clear()}})}#me(e,t){let i=t.name,s=t.value,r=[],l=[],n=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(s))!==null;){a.index>n&&r.push(s.substring(n,a.index));let u=a[1].trim();r.push(null),l.push({index:r.length-1,expr:u}),n=h.lastIndex}n<s.length&&r.push(s.substring(n));let o=this.#n(()=>{l.forEach(({index:p,expr:d})=>{let y=this.#h(d);r[p]=y==null?"":String(y)});let u=r.join(""),c=f.#ee.has(i)&&i in e&&(i!=="value"||e.tagName==="INPUT");if(f.#_.has(i)){let p=u===""||u==="false"||u==="0"||u==="null"||u==="undefined"||!u;p?e.removeAttribute(i):e.setAttribute(i,""),c&&(e[i]=!p)}else e.setAttribute(i,u),i==="class"&&f.#W.get(e)?.forEach(p=>e.classList.add(p)),c&&e.value!==u&&(e.value=u)});this.#e.push({type:"attribute",element:e,attrName:i,effect:o})}#ge(e){let t=Array.from(e.attributes),i=t.find(r=>r.name==="#pre"||r.name==="#if"||r.name==="#for");if(i?.name==="#pre")return e.removeAttribute("#pre"),!0;if(i?.name==="#if")return this.#pe(e,i),!0;if(i?.name==="#for")return this.#be(e,i),!0;let s=!1;for(let r of t)r.name==="#html"?(this.#oe(e,r),e.removeAttribute(r.name),s=!0):r.name==="#class"?(this.#ue(e,r),e.removeAttribute(r.name)):r.name==="#show"?(this.#fe(e,r),e.removeAttribute(r.name)):r.name==="#model"?(this.#ce(e,r),e.removeAttribute(r.name)):r.name==="#once"?e.removeAttribute(r.name):r.name.startsWith("@")?(this.#ae(e,r),e.removeAttribute(r.name)):/\{\{.+?\}\}/.test(r.value)&&this.#me(e,r);return s}#C(e){if(e.nodeType===Node.ELEMENT_NODE){let t=this.#ge(e);if(e.localName==="st-app")return;!t&&(e.parentNode||e.childNodes.length>0)&&this.#Y(e)}else e.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(e.nodeValue)&&this.#he(e)}#Y(e){for(let t of Array.from(e.childNodes))t.parentNode===e&&this.#C(t)}#Z(){let e=this.attrs.get("app"),t=f.#v.get(e);if(t){this.addEventListener("setup",t.setup),Object.entries(t.events).forEach(([l,n])=>this.addEventListener(l,n)),this.#d=t.template;let i=t.config;this.#w=i.helpers??{};let s=Object.getOwnPropertyDescriptors(i),r=new Set(["app","setup","template","events","helpers"]);Object.entries(s).forEach(([l,n])=>{if(!r.has(l)){if(n.get){let h=n.get;this.#te.set(l,h),Object.defineProperty(this,l,{get(){return this.#x(l),h.call(this)},enumerable:n.enumerable,configurable:!0})}else if(n.value!==void 0){let h=n.value;h!==null&&this.#I.set(l,typeof h=="object"?"json":typeof h);let a=h;typeof h=="object"&&h!==null?a=this.#m(h,[l]):typeof h=="function"&&(a=this.#q(h,l)),Object.defineProperty(this,l,{get(){return this.#x(l),a},set(o){a!==o&&(typeof o=="object"&&o!==null?a=this.#m(o,[l]):a=o,this.#f(l))},enumerable:!0,configurable:!0})}}}),typeof this.#i=="function"&&this.#i(),this.#i=!0}else this.attrs.get("app")||(typeof this.#i=="function"&&this.#i(),this.#i=!0)}async#k(e){await Promise.all(e.map(t=>new Promise(i=>{let s=null,r=()=>{clearTimeout(s),s=setTimeout(()=>{l.disconnect(),this.#k(Array.from(t.children)).then(i)},0)},l=new MutationObserver(n=>{n.some(h=>h.type==="childList")&&r()});l.observe(t,{childList:!0}),r()})))}#O(e){return e==null?"":e===!0?"true":e===!1?"false":typeof e=="number"?String(e):typeof e=="object"?JSON.stringify(e):String(e)}#ve(e,t){if(e==="")return t&&t!=="string"?null:"";switch(t){case"string":return e;case"number":{let i=Number(e);return Number.isNaN(i)?e:i}case"boolean":return!["false","0","null","undefined"].includes(e);case"json":try{return JSON.parse(e)}catch{return e}}if(e==="true")return!0;if(e==="false")return!1;if(/^-?\d+(\.\d+)?$/.test(e))return Number(e);try{return JSON.parse(e)}catch{return e}}#j(e,t=!1){if(!e.startsWith(":"))return;let[i,s]=e.replace(/^:+/,"").split(".");i=i.replace(/-([a-z])/g,(h,a)=>a.toUpperCase());let r=this.getAttribute(e);if(r===null)return;let l=Object.getOwnPropertyDescriptor(this,i),n;if(r===""&&t&&l&&(l.get||l.value!==void 0)){n=this[i];let h=this.#O(n);r!==h&&this.setAttribute(e,h),l=null}else{if(l&&l.set===void 0&&l.writable===!1||l&&l.get!==void 0&&l.set===void 0||l&&this.#O(this[i])===r)return;n=this.#ve(r,s??this.#I.get(i))}if(!l||!l.set){let h=n;typeof n=="object"&&n!==null?h=this.#m(n,[i]):typeof n=="function"&&(h=this.#q(n,i));let a=e;if(Object.defineProperty(this,i,{get(){return this.#x(i),h},set(o){if(h!==o){typeof o=="object"&&o!==null?h=this.#m(o,[i]):h=o,this.#f(i);let u=this.#O(o);this.getAttribute(a)!==u&&this.setAttribute(a,u)}},enumerable:!0,configurable:!0}),typeof n=="object"&&n!==null){let o=this.watch(i,()=>{let u=this[i],c=this.#O(u);this.getAttribute(e)!==c&&this.setAttribute(e,c)},{deep:!0});this.#e.push({type:"attrSync",unwatch:o})}}else this[i]=n}attributeChangedCallback(e,t,i){e.startsWith(":")&&e!=="app"&&t!==i&&this.#i===!0&&this.#j(e)}connectedCallback(){if(f.#c.add(this),this.#i===!0){this.#T&&(this.#T=!1,this.applyTemplate(this.#B)),this.#l||(this.#l=new MutationObserver(t=>{for(let i of t)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#j(i.attributeName)}),this.#l.observe(this,{attributes:!0}));return}let e=this.parentElement?.closest("st-app");if(e&&!e.#H){f.#c.delete(this);return}this.#Z(),Promise.all([new Promise(t=>{if(this.#i===!0)return t();this.#i=t}),new Promise(t=>{let i=null,s=()=>{clearTimeout(i),i=setTimeout(()=>{r.disconnect(),this.#k(Array.from(this.children)).then(t)},0)},r=new MutationObserver(l=>{l.some(n=>n.type==="childList")&&s()});r.observe(this,{childList:!0}),s()})]).then(()=>{this.dispatchEvent("setup");for(let i of this.attrs.keys())i.startsWith(":")&&this.#j(i,!0);let t=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(s=>s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE&&s.textContent.trim()!=="")&&(this.#d?(this.applyTemplate(this.innerHTML),t=!0):this.#d=this.innerHTML),t||this.applyTemplate(),this.#i===!0&&!this.#l&&(this.#l=new MutationObserver(i=>{for(let s of i)s.type==="attributes"&&s.attributeName&&s.attributeName.startsWith(":")&&s.attributeName!=="app"&&this.#j(s.attributeName)}),this.#l.observe(this,{attributes:!0}))})}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.#Ee()})}#Ee(){this.#T=!0,this.#l&&(this.#l.disconnect(),this.#l=null),this.#N(this.#e),this.#e=[];for(let e of this.#t)e.type==="getter"&&e.effect&&(this.#s.forEach((t,i)=>{t.delete(e.effect),t.size===0&&this.#s.delete(i)}),this.#o.delete(e.effect));this.#t=[],this.#a.forEach((e,t)=>{this[t]=e.original}),this.#a.clear(),this.#E.clear(),this.#s.clear(),this.#o.clear(),f.#c.delete(this)}toggleAttribute(e,...t){return t.length<=1&&(t[0]===void 0||typeof t[0]=="boolean")?super.toggleAttribute(e,...t):this.cycleAttribute(e,...t)}cycleAttribute(e,t="",i=""){let s=this.getAttribute(e);this[t==""&&i==""&&(s||this.hasAttribute(e))?"removeAttribute":"setAttribute"](e,s!=t?t:i)}static{customElements.define("st-app",this)}};return R(V);})();
|
|
1
|
+
var App=(()=>{var T=Object.defineProperty;var k=Object.getOwnPropertyDescriptor;var $=Object.getOwnPropertyNames;var W=Object.prototype.hasOwnProperty;var R=(f,t)=>{for(var e in t)T(f,e,{get:t[e],enumerable:!0})},I=(f,t,e,i)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of $(t))!W.call(f,s)&&s!==e&&T(f,s,{get:()=>t[s],enumerable:!(i=k(t,s))||i.enumerable});return f};var D=f=>I(T({},"__esModule",{value:!0}),f);var V={};R(V,{default:()=>x});var x=class f extends HTMLElement{static#R=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#I=new Set(["checked","selected","value"]);static#E=new Map;static#c=new Set;static#D=new WeakMap;static#V=new WeakMap;static#p={};static helpers(t={}){return Object.assign(f.#p,t),f.#p}static toRaw(t){return f.#g(t)}static snapshot(t,e=new WeakMap){if(t=f.#g(t),t===null||typeof t!="object")return t;if(e.has(t))return e.get(t);let i=Object.getPrototypeOf(t);if(Array.isArray(t)){let r=[];return e.set(t,r),t.forEach(l=>r.push(f.snapshot(l,e))),r}if(i!==Object.prototype&&i!==null)return t;let s={};e.set(t,s);for(let r of Object.keys(t))s[r]=f.snapshot(t[r],e);return s}static#B={setup:["function","\u0444\u0443\u043D\u043A\u0446\u0438\u044F"],template:["string","\u0441\u0442\u0440\u043E\u043A\u0430"],events:["object","\u043E\u0431\u0440\u0430\u0431\u043E\u0442\u0447\u0438\u043A\u0438 { \u0438\u043C\u044F: \u0444\u0443\u043D\u043A\u0446\u0438\u044F }"],helpers:["object","\u043E\u0431\u044A\u0435\u043A\u0442 { \u0438\u043C\u044F: \u0437\u043D\u0430\u0447\u0435\u043D\u0438\u0435 }"]};static#H(t){for(let[e,[i,s]]of Object.entries(f.#B)){let r=t[e];if(r===void 0||typeof r===i&&!Array.isArray(r)&&r!==null)continue;let l=Array.isArray(r)?"\u043C\u0430\u0441\u0441\u0438\u0432":r===null?"null":typeof r;throw new TypeError(`App.create("${t.app}"): "${e}" - ${s}, \u043F\u043E\u043B\u0443\u0447\u0435\u043D ${l}. \u0415\u0441\u043B\u0438 \u044D\u0442\u043E \u0434\u0430\u043D\u043D\u044B\u0435, \u043F\u0435\u0440\u0435\u0438\u043C\u0435\u043D\u0443\u0439\u0442\u0435 \u043F\u043E\u043B\u0435`)}}static create(t){let{app:e,setup:i=()=>{},template:s="",events:r={}}=t;if(f.#H(t),f.#E.has(e))throw new Error(`Application "${e}" already exists!`);f.#E.set(e,{setup:i,template:s,events:r,config:t}),f.#c.forEach(l=>{l.#i!==!0&&l.#st()})}static extend(t,e={}){let i=f.#E.get(t);if(!i)throw new Error(`Application "${t}" not found!`);f.#H(e);let s=i.config,r=Object.defineProperties({},{...Object.getOwnPropertyDescriptors(s),...Object.getOwnPropertyDescriptors(e)});return(s.events||e.events)&&(r.events={...s.events,...e.events}),(s.helpers||e.helpers)&&(r.helpers={...s.helpers,...e.helpers}),f.create(r)}#i=!1;#d="";#j=!1;#s=new Map;#u=null;#a=new Set;#y=!1;#t=[];#n=null;#rt=new Map;#h=null;#e=[];#w=new Set;#T=!1;#J=[];#P=!1;#z=new Map;#o=new Map;#F=0;#q="";#L=!1;#U=!1;#A={};#b=new WeakMap;constructor(){super(),f.#c.add(this)}#x(t){!t||!t.length||t.forEach(e=>{if(e.type==="event"&&e.element&&e.handler)setTimeout(()=>e.element.removeEventListener(e.eventName,e.handler));else if(e.type==="model"&&e.element&&e.handler){let i=e.element.tagName==="SELECT"?"change":"input";setTimeout(()=>e.element.removeEventListener(i,e.handler))}else e.type==="attrSync"&&e.unwatch&&e.unwatch();e.dispose?.(),e.effect&&(this.#K(e.effect),this.#a.delete(e.effect),this.#nt(e.effect))})}#K(t){this.#s.forEach((e,i)=>{e.delete(t),e.size===0&&this.#s.delete(i)})}#lt(t,e){for(let i=e;i;i=Object.getPrototypeOf(i)){let s=this.#b.get(i);s||this.#b.set(i,s=new Set),s.add(t)}}#nt(t){for(let e=t.ctx;e;e=Object.getPrototypeOf(e))this.#b.get(e)?.delete(t)}get template(){return this.#d}get attrs(){return{get:t=>this.getAttribute(t),set:(t,e)=>this.setAttribute(t,e),remove:t=>this.removeAttribute(t),has:t=>this.hasAttribute(t),toggle:(t,e)=>this.toggleAttribute(t,e),keys:()=>Array.from(this.attributes).map(t=>t.name),entries:()=>Array.from(this.attributes).map(t=>[t.name,t.value])}}addEventListener(t,e,i){if((t==="setup"||t==="rendered")&&this.#j){queueMicrotask(()=>{let s=new CustomEvent(t);typeof e=="function"?e.call(this,s):e?.handleEvent?.(s)});return}super.addEventListener(t,e,i)}dispatchEvent(t,e=null,i={}){if(typeof t=="string"){let s=new CustomEvent(t,{cancelable:!0,...i,detail:e});return super.dispatchEvent(s)}return super.dispatchEvent(t)}applyTemplate(t=""){let e=t||this.#d;if(this.#U=!0,this.#q=e,this.#x(this.#t),this.#t=[],this.innerHTML="",e){let s=document.createElement("template");s.innerHTML=e.trim();let r=s.content.cloneNode(!0);this.#it(r),this.#ht(r)}let i=++this.#F;new Promise(s=>{let r=null,l,n=()=>{clearTimeout(r),r=setTimeout(()=>{l.disconnect(),this.#W(Array.from(this.children)).then(s)},0)};l=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&n()}),l.observe(this,{childList:!0}),n()}).then(()=>{i===this.#F&&(this.#j=!0,this.dispatchEvent("rendered"))})}#ht(t){HTMLElement.prototype.appendChild.call(this,t)}clone(t={}){let e=this.attrs.get("app");return f.extend(e,t)}watch(t,e,i={}){if(typeof e!="function")return()=>{};let{deep:s=!1,immediate:r=!1}=i;if(typeof t=="string"&&t.endsWith("()")){let l=t.slice(0,-2),n=this[l];if(typeof n!="function")return()=>{};let h=this.#o.get(l);if(!h){h={original:n,handlers:[]},this.#o.set(l,h);let o=(...u)=>{let c=n.apply(this,u),p=d=>{for(let y of[...h.handlers])y.callback(u,d,y.unwatch)};return c instanceof Promise?c.then(d=>(p(d),d)):(p(c),c)};this[l]=o}let a=()=>{let o=h.handlers.findIndex(u=>u.unwatch===a);o!==-1&&h.handlers.splice(o,1),h.handlers.length===0&&(this[l]=h.original,this.#o.delete(l))};return h.handlers.push({callback:e,unwatch:a}),a}if(typeof t=="string"){let l=t,n=()=>{let a=this.#e.findIndex(o=>o.unwatch===n);a!==-1&&this.#e.splice(a,1)},h={type:"key",key:l,callback:e,deep:s,immediate:r,lastValue:void 0,unwatch:n};if(this.#e.push(h),r){let a=this.#X(l);h.lastValue=s&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,e(a,void 0,n)}return n}if(typeof t=="function"){let l=t,n,h={type:"getter",getter:l,callback:e,deep:s,lastValue:n,effect:null,unwatch:null};this.#e.push(h);let a=()=>{let c=this.#e.indexOf(h);c!==-1&&this.#e.splice(c,1),h.effect&&(this.#s.forEach((p,d)=>{p.delete(h.effect),p.size===0&&this.#s.delete(d)}),this.#a.delete(h.effect))};h.unwatch=a;let o=()=>{let c=l.call(this);if(s?!this.#M(c,n):c!==n){let d=n;n=s&&c!==null&&typeof c=="object"?JSON.parse(JSON.stringify(c)):c,e(c,d,h.unwatch)}},u=this.#l(o);return h.effect=u,a}return()=>{}}unwatch(){[...this.#e].forEach(t=>t.unwatch()),this.#o.forEach(t=>{[...t.handlers].forEach(e=>e.unwatch())})}hasWatchers(){let t=0;return this.#o.forEach(e=>{t+=e.handlers.length}),this.#e.length+t}watched(t,e,i={}){if(typeof t=="string"&&t.endsWith("()")){let s=t.slice(0,-2),r=this.#o.get(s);r&&[...r.handlers].forEach(l=>l.unwatch())}else typeof t=="string"?this.#e.filter(s=>s.type==="key"&&s.key===t).forEach(s=>s.unwatch()):typeof t=="function"&&this.#e.filter(s=>s.type==="getter"&&s.getter===t).forEach(s=>s.unwatch());return this.watch(t,e,i)}#N(t){this.#u&&(this.#s.has(t)||this.#s.set(t,new Set),this.#s.get(t).add(this.#u))}#f(t){this.#w.add(t);let e=this.#s.get(t);if(e&&e.forEach(s=>this.#a.add(s)),this.#y){this.#T=!0;return}this.#y=!0;let i=()=>{this.#P||=this.#a.size>0,this.#a.forEach(l=>{try{l()}catch(n){console.error("Effect execution error:",n)}}),this.#a.clear();let s=Array.from(this.#w),r=new Set;for(let l of s)for(let n of this.#e){if(n.type!=="key")continue;(n.key===l||n.deep&&(l===n.key||l.startsWith(n.key+".")))&&r.add(n)}for(let l of r){if(l.type!=="key")continue;let n=this.#X(l.key);if(!(l.deep?!this.#M(n,l.lastValue):n!==l.lastValue))continue;let a=l.lastValue;l.lastValue=l.deep&&n!==null&&typeof n=="object"?JSON.parse(JSON.stringify(n)):n;try{l.callback(n,a,l.unwatch)}catch(o){console.error("Watcher callback error:",o)}}this.#w.clear(),this.#y=!1,this.#T?(this.#T=!1,this.#y=!0,Promise.resolve().then(i)):(this.#J.splice(0).forEach(l=>l()),this.#P&&this.#j&&this.dispatchEvent("updated"),this.#P=!1)};Promise.resolve().then(i)}nextTick(){return this.#y?new Promise(t=>this.#J.push(t)):Promise.resolve()}#X(t){return t.split(".").reduce((e,i)=>e?.[i],this)}#M(t,e){if(Object.is(t,e))return!0;if(t===null||e===null||typeof t!="object"||typeof e!="object")return!1;let i=Object.keys(t),s=Object.keys(e);if(i.length!==s.length)return!1;for(let r of i)if(!s.includes(r)||!this.#M(t[r],e[r]))return!1;return!0}static#g(t){return t!==null&&typeof t=="object"?t.__raw??t:t}#G=new WeakMap;#m(t,e=[]){if(t===null||typeof t!="object"||t.__isReactive)return t;let i=e.join("."),s=this.#G.get(t);if(s||this.#G.set(t,s=new Map),s.has(i))return s.get(i);let r=this,l=new Proxy(t,{get(n,h,a){if(h==="__isReactive")return!0;if(h==="__raw")return n;let o=typeof h=="symbol"?"<symbol>":h,u=[...e,o].join(".");r.#N(u);let c=Reflect.get(n,h,a);return c!==null&&typeof c=="object"&&!c.__isReactive?r.#m(c,[...e,o]):c},set(n,h,a,o){if(n[h]===a)return!0;let c=Reflect.set(n,h,a,o),p=typeof h=="symbol"?"<symbol>":h,d=[...e,p].join(".");if(r.#f(d),Array.isArray(n)&&(h==="length"||!isNaN(h))){let y=e.join(".");y&&r.#f(y)}return c},deleteProperty(n,h){let a=Reflect.deleteProperty(n,h),o=typeof h=="symbol"?"<symbol>":h,u=[...e,o].join(".");return r.#f(u),a}});return s.set(i,l),l}#Q(t,e){let i=this;return new Proxy(t,{apply(s,r,l){let n=Reflect.apply(s,i,l);return i.#u?n:n instanceof Promise?n.then(h=>(i.#f(e),h)):(i.#f(e),n)}})}#l(t){let e=this.#n,i=()=>{let s=this.#u;this.#u=i;try{e?this.#v(e,t):t()}finally{this.#u=s}};return e&&(i.ctx=e,this.#lt(i,e)),i(),i}static#Y=new Map;static#C(t){let e=f.#Y.get(t);return e||(e=new Function("$s","$event","$__v",`with($s) { ${t} }`),f.#Y.set(t,e)),e}#at=null;get#k(){return this.#at??=new Proxy(this,{has:(t,e)=>typeof e=="string"&&(e in t||e in this.#A||e in f.#p),get:(t,e)=>{if(e===Symbol.unscopables)return;if(typeof e=="string"&&!(e in t)){if(e in this.#A)return this.#A[e];if(e in f.#p)return f.#p[e]}let i=Reflect.get(t,e);return this.#ot(e,i),typeof i=="function"&&!Object.hasOwn(t,e)?i.bind(t):i},set:(t,e,i)=>Reflect.set(t,e,i)})}#Z=new Set;#ot(t,e){if(typeof t!="string"||typeof e=="function"||this.#Z.has(t)||this.#n&&t in this.#n)return;let i=Object.getOwnPropertyDescriptor(this,t);if(!i||!("value"in i))return;this.#Z.add(t);let s=t in f.#B||t==="app"?"\u0437\u0430\u043D\u044F\u0442\u043E \u043E\u043F\u0446\u0438\u0435\u0439 App.create, \u043F\u0435\u0440\u0435\u0438\u043C\u0435\u043D\u0443\u0439\u0442\u0435 \u0435\u0433\u043E":"\u043D\u0435 \u043E\u0431\u044A\u044F\u0432\u043B\u0435\u043D\u043E \u0432 \u043A\u043E\u043D\u0444\u0438\u0433\u0435";console.warn(`<st-app app="${this.getAttribute("app")??""}">: \u0441\u0432\u043E\u0439\u0441\u0442\u0432\u043E "${t}" ${s} \u0438 \u043D\u0435 \u0440\u0435\u0430\u043A\u0442\u0438\u0432\u043D\u043E`)}#r(t){try{return f.#C(`return (${t});`).call(this,this.#k)}catch(e){console.warn("Expression evaluation error:",t,e);return}}#_(t,e=null){try{return f.#C(t).call(this,this.#k,e)}catch(i){console.error("Statement execution error:",t,i)}}#tt(t,e){try{f.#C(`${t} = $__v;`).call(this,this.#k,null,e)}catch(i){console.error("Model binding error:",t,i)}}#ft(t){let e=t.nodeValue,i=[],s=[],r=0,l=/\{\{(.+?)\}\}/g,n;for(;(n=l.exec(e))!==null;){n.index>r&&i.push(e.substring(r,n.index));let a=n[1].trim();i.push(null),s.push({index:i.length-1,expr:a}),r=l.lastIndex}r<e.length&&i.push(e.substring(r));let h=this.#l(()=>{s.forEach(({index:a,expr:o})=>{let u=this.#r(o);i[a]=u==null?"":String(u)}),t.nodeValue=i.join("")});this.#t.push({type:"text",node:t,effect:h})}#ut(t,e){let[i,...s]=e.name.slice(1).split("."),r=s.includes("self"),l=e.value,n=this.#n,h=a=>{r&&a.target!==t||(n?this.#v(n,()=>this.#_(l,a)):this.#_(l,a))};t.addEventListener(i,h),this.#t.push({type:"event",element:t,eventName:i,handler:h})}#ct(t,e){let i=e.value,s=this.#l(()=>{let r=this.#r(i);t.innerHTML=r==null?"":String(r)});this.#t.push({type:"html",element:t,effect:s})}#pt(t,e){let i=e.value,s=this.#l(()=>{this.#r(i)?t.style.display="":t.style.display="none"});this.#t.push({type:"show",element:t,effect:s})}#dt(t,e){let i=e.value,s=new Set;f.#V.set(t,s);let r=this.#l(()=>{let l=this.#r(i),n=new Set,h=a=>String(a).split(/\s+/).filter(Boolean).forEach(o=>n.add(o));Array.isArray(l)?l.forEach(a=>a&&h(a)):l&&typeof l=="object"?Object.entries(l).forEach(([a,o])=>o&&h(a)):l&&h(l),s.forEach(a=>n.has(a)||t.classList.remove(a)),n.forEach(a=>t.classList.add(a)),s.clear(),n.forEach(a=>s.add(a))});this.#t.push({type:"class",element:t,effect:r})}#yt(t,e){let i=e.name.slice(6),s=e.value,r=new Set,l=(h,a)=>{let o=f.#I.has(h)&&h in t&&(h!=="value"||t.tagName==="INPUT");f.#R.has(h)?(t.toggleAttribute(h,!!a),o&&(t[h]=!!a)):a==null?t.removeAttribute(h):(t.setAttribute(h,a=String(a)),o&&t.value!==a&&(t.value=a))},n=this.#l(()=>{let h=this.#r(s),a=i?{[i]:h}:h&&typeof h=="object"?h:{};r.forEach(o=>o in a||l(o,null)),r=new Set(Object.keys(a)),r.forEach(o=>l(o,a[o]))});this.#t.push({type:"attrs",element:t,effect:n})}#bt(t,e){let i=e.value,s=this.#l(()=>{let a=this.#r(i);if(t.tagName==="INPUT"&&t.type==="checkbox")t.checked=Array.isArray(a)?a.some(o=>String(o)===t.value):!!a;else if(t.tagName==="INPUT"&&t.type==="radio")t.checked=t.value===a;else if(t.tagName==="SELECT"){let o=t.multiple&&Array.isArray(a)?a.map(String):[],u=t.multiple?()=>{for(let c of t.options)c.selected=o.includes(c.value)}:()=>{t.value=a};f.#D.set(t,u),u(),queueMicrotask(u)}else t.value=a??""}),r=this.#n,l=t.tagName==="SELECT"?"change":"input",n=()=>{if(t.type==="checkbox"){let a=this.#r(i);return Array.isArray(a)?(a=a.filter(o=>String(o)!==t.value),t.checked?[...a,t.value]:a):t.checked}return t.type==="number"||t.type==="range"?t.value===""?null:t.valueAsNumber:t.tagName==="SELECT"&&t.multiple?Array.from(t.selectedOptions,a=>a.value):t.value},h=()=>{r?this.#v(r,()=>this.#tt(i,n())):this.#tt(i,n())};t.addEventListener(l,h),this.#t.push({type:"model",element:t,effect:s,handler:h})}#gt(t,e){let i=e.value,s=document.createComment(`if: ${i}`);t.parentNode.insertBefore(s,t),t.removeAttribute(e.name);let r=[{expr:i,template:t.cloneNode(!0)}],l=t.nextElementSibling;for(;l;)if(l.hasAttribute("#else-if")){let o=l.getAttribute("#else-if");l.removeAttribute("#else-if"),r.push({expr:o,template:l.cloneNode(!0)});let u=l.nextElementSibling;l.remove(),l=u}else if(l.hasAttribute("#else")){l.removeAttribute("#else"),r.push({expr:"true",template:l.cloneNode(!0)}),l.remove();break}else break;t.remove();let n={branch:null,node:null,bindings:[]},h=()=>{n.node?.remove(),this.#x(n.bindings),n.node=null,n.bindings=[]},a=this.#l(()=>{let o=r.find(c=>this.#r(c.expr))??null;if(n.branch===o||(h(),n.branch=o,!o))return;let u=o.template.cloneNode(!0);s.parentNode.insertBefore(u,s.nextSibling),n.bindings=this.#et(()=>this.#$(u)),n.node=u});this.#t.push({type:"conditional",placeholder:s,effect:a,dispose:h})}#et(t){let e=this.#t.length;return t(),this.#t.splice(e)}#mt(t){return Object.assign(Object.create(this.#n??null),t)}#v(t,e){let i={};for(let r in t)i[r]=this[r],this[r]=t[r];let s=this.#n;this.#n=t;try{return e()}finally{this.#n=s;for(let r of Object.keys(i))i[r]!==void 0?this[r]=i[r]:delete this[r]}}#vt(t,e){Object.assign(t.ctx,e);let i=[...this.#b.get(t.ctx)??[]];i.forEach(s=>this.#K(s)),i.forEach(s=>{this.#b.get(t.ctx)?.has(s)&&s()})}#Et(t,e){let i=e.value,s=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!s){console.error("Invalid for syntax:",i);return}let r=s[1],l=s[2],n=t.getAttribute("#key");t.removeAttribute(e.name),t.removeAttribute("#key");let h=document.createComment(`for: ${i}`);t.parentNode.insertBefore(h,t);let a=t.cloneNode(!0);t.remove();let o=new Map,u=p=>{p.node.remove(),this.#x(p.bindings)},c=this.#l(()=>{let p=this.#r(l),d=[];Array.isArray(p)?d=p.map((b,g)=>({value:b,key:void 0,index:g})):p!==null&&typeof p=="object"&&(d=Object.entries(p).map(([b,g],E)=>({value:g,key:b,index:E})));let y=new Map,A=[];d.forEach(({value:b,key:g,index:E})=>{let S={[r]:b,$index:E};g!==void 0&&(S.$key=g);let j=this.#mt(S),w=n?f.#g(this.#v(j,()=>this.#r(n))):Symbol();n&&y.has(w)&&console.warn("Duplicate #key in #for:",i,w);let m=o.get(w);if(m&&f.#g(m.value)===f.#g(b)){o.delete(w),(m.value!==b||m.index!==E||m.key!==g)&&(Object.assign(m,{value:b,index:E,key:g}),this.#vt(m,S)),y.set(w,m),A.push(m);return}let L=a.cloneNode(!0),C=this.#v(j,()=>this.#et(()=>this.#$(L))),M={node:L,bindings:C,value:b,index:E,key:g,ctx:j};y.set(w,M),A.push(M)}),o.forEach(u),o=y;let v=h.parentNode.contains(document.activeElement)?document.activeElement:null,N=null;try{N=v&&[v.selectionStart,v.selectionEnd,v.selectionDirection]}catch{}let O=h;for(let b=A.length-1;b>=0;b--){let g=A[b].node;g.nextSibling!==O&&h.parentNode.insertBefore(g,O),O=g}if(v?.isConnected&&document.activeElement!==v){v.focus({preventScroll:!0});try{N?.[0]!=null&&v.setSelectionRange(...N)}catch{}}let P=h.parentNode?.closest?.("select");P&&f.#D.get(P)?.()});this.#t.push({type:"loop",anchor:h,template:a,effect:c,dispose:()=>{o.forEach(u),o.clear()}})}#wt(t,e){let i=e.name,s=e.value,r=[],l=[],n=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(s))!==null;){a.index>n&&r.push(s.substring(n,a.index));let u=a[1].trim();r.push(null),l.push({index:r.length-1,expr:u}),n=h.lastIndex}n<s.length&&r.push(s.substring(n));let o=this.#l(()=>{l.forEach(({index:p,expr:d})=>{let y=this.#r(d);r[p]=y==null?"":String(y)});let u=r.join(""),c=f.#I.has(i)&&i in t&&(i!=="value"||t.tagName==="INPUT");if(f.#R.has(i)){let p=u===""||u==="false"||u==="0"||u==="null"||u==="undefined"||!u;p?t.removeAttribute(i):t.setAttribute(i,""),c&&(t[i]=!p)}else t.setAttribute(i,u),i==="class"&&f.#V.get(t)?.forEach(p=>t.classList.add(p)),c&&t.value!==u&&(t.value=u)});this.#t.push({type:"attribute",element:t,attrName:i,effect:o})}#At(t){let e=Array.from(t.attributes),i=e.find(r=>r.name==="#pre"||r.name==="#if"||r.name==="#for");if(i?.name==="#pre")return t.removeAttribute("#pre"),!0;if(i?.name==="#if")return this.#gt(t,i),!0;if(i?.name==="#for")return this.#Et(t,i),!0;let s=!1;for(let r of e)r.name==="#html"?(this.#ct(t,r),t.removeAttribute(r.name),s=!0):r.name==="#class"?(this.#dt(t,r),t.removeAttribute(r.name)):r.name==="#attr"||r.name.startsWith("#attr.")?(this.#yt(t,r),t.removeAttribute(r.name)):r.name==="#show"?(this.#pt(t,r),t.removeAttribute(r.name)):r.name==="#model"?(this.#bt(t,r),t.removeAttribute(r.name)):r.name==="#once"?t.removeAttribute(r.name):r.name.startsWith("@")?(this.#ut(t,r),t.removeAttribute(r.name)):/\{\{.+?\}\}/.test(r.value)&&this.#wt(t,r);return s}#$(t){if(t.nodeType===Node.ELEMENT_NODE){let e=this.#At(t);if(t.localName==="st-app")return;!e&&(t.parentNode||t.childNodes.length>0)&&this.#it(t)}else t.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(t.nodeValue)&&this.#ft(t)}#it(t){for(let e of Array.from(t.childNodes))e.parentNode===t&&this.#$(e)}#st(){let t=this.attrs.get("app"),e=f.#E.get(t);if(e){this.addEventListener("setup",e.setup),Object.entries(e.events).forEach(([l,n])=>this.addEventListener(l,n)),this.#d=e.template;let i=e.config;this.#A=i.helpers??{};let s=Object.getOwnPropertyDescriptors(i),r=new Set(["app","setup","template","events","helpers"]);Object.entries(s).forEach(([l,n])=>{if(!r.has(l)){if(n.get){let h=n.get;this.#rt.set(l,h),Object.defineProperty(this,l,{get(){return this.#N(l),h.call(this)},enumerable:n.enumerable,configurable:!0})}else if(n.value!==void 0){let h=n.value;h!==null&&this.#z.set(l,typeof h=="object"?"json":typeof h);let a=h;typeof h=="object"&&h!==null?a=this.#m(h,[l]):typeof h=="function"&&(a=this.#Q(h,l)),Object.defineProperty(this,l,{get(){return this.#N(l),a},set(o){a!==o&&(typeof o=="object"&&o!==null?a=this.#m(o,[l]):a=o,this.#f(l))},enumerable:!0,configurable:!0})}}}),typeof this.#i=="function"&&this.#i(),this.#i=!0}else this.attrs.get("app")||(typeof this.#i=="function"&&this.#i(),this.#i=!0)}async#W(t){await Promise.all(t.map(e=>new Promise(i=>{let s=null,r=()=>{clearTimeout(s),s=setTimeout(()=>{l.disconnect(),this.#W(Array.from(e.children)).then(i)},0)},l=new MutationObserver(n=>{n.some(h=>h.type==="childList")&&r()});l.observe(e,{childList:!0}),r()})))}#O(t){return t==null?"":t===!0?"true":t===!1?"false":typeof t=="number"?String(t):typeof t=="object"?JSON.stringify(t):String(t)}#xt(t,e){if(t==="")return e&&e!=="string"?null:"";switch(e){case"string":return t;case"number":{let i=Number(t);return Number.isNaN(i)?t:i}case"boolean":return!["false","0","null","undefined"].includes(t);case"json":try{return JSON.parse(t)}catch{return t}}if(t==="true")return!0;if(t==="false")return!1;if(/^-?\d+(\.\d+)?$/.test(t))return Number(t);try{return JSON.parse(t)}catch{return t}}#S(t,e=!1){if(!t.startsWith(":"))return;let[i,s]=t.replace(/^:+/,"").split(".");i=i.replace(/-([a-z])/g,(h,a)=>a.toUpperCase());let r=this.getAttribute(t);if(r===null)return;let l=Object.getOwnPropertyDescriptor(this,i),n;if(r===""&&e&&l&&(l.get||l.value!==void 0)){n=this[i];let h=this.#O(n);r!==h&&this.setAttribute(t,h),l=null}else{if(l&&l.set===void 0&&l.writable===!1||l&&l.get!==void 0&&l.set===void 0||l&&this.#O(this[i])===r)return;n=this.#xt(r,s??this.#z.get(i))}if(!l||!l.set){let h=n;typeof n=="object"&&n!==null?h=this.#m(n,[i]):typeof n=="function"&&(h=this.#Q(n,i));let a=t;if(Object.defineProperty(this,i,{get(){return this.#N(i),h},set(o){if(h!==o){typeof o=="object"&&o!==null?h=this.#m(o,[i]):h=o,this.#f(i);let u=this.#O(o);this.getAttribute(a)!==u&&this.setAttribute(a,u)}},enumerable:!0,configurable:!0}),typeof n=="object"&&n!==null){let o=this.watch(i,()=>{let u=this[i],c=this.#O(u);this.getAttribute(t)!==c&&this.setAttribute(t,c)},{deep:!0});this.#t.push({type:"attrSync",unwatch:o})}}else this[i]=n}attributeChangedCallback(t,e,i){t.startsWith(":")&&t!=="app"&&e!==i&&this.#i===!0&&this.#S(t)}connectedCallback(){if(f.#c.add(this),this.#i===!0){this.#L&&(this.#L=!1,this.applyTemplate(this.#q)),this.#h||(this.#h=new MutationObserver(e=>{for(let i of e)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#S(i.attributeName)}),this.#h.observe(this,{attributes:!0}));return}let t=this.parentElement?.closest("st-app");if(t&&!t.#U){f.#c.delete(this);return}this.#st(),Promise.all([new Promise(e=>{if(this.#i===!0)return e();this.#i=e}),new Promise(e=>{let i=null,s=()=>{clearTimeout(i),i=setTimeout(()=>{r.disconnect(),this.#W(Array.from(this.children)).then(e)},0)},r=new MutationObserver(l=>{l.some(n=>n.type==="childList")&&s()});r.observe(this,{childList:!0}),s()})]).then(()=>{this.dispatchEvent("setup");for(let i of this.attrs.keys())i.startsWith(":")&&this.#S(i,!0);let e=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(s=>s.nodeType===Node.ELEMENT_NODE||s.nodeType===Node.TEXT_NODE&&s.textContent.trim()!=="")&&(this.#d?(this.applyTemplate(this.innerHTML),e=!0):this.#d=this.innerHTML),e||this.applyTemplate(),this.#i===!0&&!this.#h&&(this.#h=new MutationObserver(i=>{for(let s of i)s.type==="attributes"&&s.attributeName&&s.attributeName.startsWith(":")&&s.attributeName!=="app"&&this.#S(s.attributeName)}),this.#h.observe(this,{attributes:!0}))})}disconnectedCallback(){queueMicrotask(()=>{this.isConnected||this.#Nt()})}#Nt(){this.#L=!0,this.#h&&(this.#h.disconnect(),this.#h=null),this.#x(this.#t),this.#t=[];for(let t of this.#e)t.type==="getter"&&t.effect&&(this.#s.forEach((e,i)=>{e.delete(t.effect),e.size===0&&this.#s.delete(i)}),this.#a.delete(t.effect));this.#e=[],this.#o.forEach((t,e)=>{this[e]=t.original}),this.#o.clear(),this.#w.clear(),this.#s.clear(),this.#a.clear(),f.#c.delete(this)}toggleAttribute(t,...e){return e.length<=1&&(e[0]===void 0||typeof e[0]=="boolean")?super.toggleAttribute(t,...e):this.cycleAttribute(t,...e)}cycleAttribute(t,e="",i=""){let s=this.getAttribute(t);this[e==""&&i==""&&(s||this.hasAttribute(t))?"removeAttribute":"setAttribute"](t,s!=e?e:i)}static{customElements.define("st-app",this)}};return D(V);})();
|
|
2
2
|
if(typeof App!=="undefined"&&App&&App.default)globalThis.App=App.default;
|