@cat-of-summer/st-script 1.0.2 → 1.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,19 +9,19 @@ two flavours per module:
9
9
 
10
10
  | Module | Global / element | Notes |
11
11
  | --------------------- | ------------------- | ------------------------------------------------ |
12
- | `st_modal` | `window.st_modal` | Modal windows. |
12
+ | `st_modal` | `window.Modal` | Modal windows. |
13
13
  | `st_typograf` | `window.st_typograf`| Typography fixer. |
14
- | `st_cookie` | `window.st_cookie` | Cookie helpers. |
14
+ | `st_cookie` | `window.Cookie` | Cookie helpers. |
15
15
  | `st_system` | `window.st_system` | Utilities (`merge`, `generate_*`). |
16
16
  | `st_observer` | `window.st_observer`| IntersectionObserver wrapper. |
17
- | `toggle` | `window.toggle` | State toggler (accordions, switches, hover-menus).|
18
- | `select` | `window.select` | Custom `<select>` dropdown (hooks, multiple, hover).|
19
- | `st_mask` | `window.st_mask` | Input masks. |
20
- | `uploader` | `window.uploader` | File uploader. |
17
+ | `toggle` | `window.Toggle` | State toggler (accordions, switches, hover-menus).|
18
+ | `select` | `window.Select` | Custom `<select>` dropdown (hooks, multiple, hover).|
19
+ | `mask` | `window.Mask` | Input masks (телефон, дата, карта, ИНН, …). |
20
+ | `uploader` | `window.Uploader` | File uploader. |
21
21
  | `st_validator` | `window.st_validator`| Form/field validation. |
22
22
  | `st_button_widget` | `window.st_button_widget`| Floating button widget. |
23
23
  | `st_links_widget` | `window.st_links_widget`| Links widget. |
24
- | `loader` | `window.loader` | Ajax list loader (cards: подгрузка/фильтр/сортировка) via `Core.fetch`. |
24
+ | `loader` | `window.Loader` | Ajax list loader (cards: подгрузка/фильтр/сортировка) via `Core.fetch`. |
25
25
  | `st_app` | `<st-app>` element | **Web Component** — `<script defer>` only (self-registers). |
26
26
  | `st_app/form` | `window.form` | Form app **config object** — register with `App.create(form)`; no `st_app` bundled. |
27
27
 
@@ -1 +1 @@
1
- var m=class{static merge(...e){let s=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&(Object.getPrototypeOf(t)??Object.prototype)===Object.prototype,n=(t,o)=>{if(typeof t=="function"&&typeof o=="function")return(...a)=>n(t(...a),o(...a));if(!(Array.isArray(t)&&Array.isArray(o)||s(t)&&s(o)))return o;let d=Array.isArray(t)?t.slice():{...t};for(let[a,u]of Object.entries(o))d[a]=a in d?n(d[a],u):u;return d};return e.reduce(n,{})}static generate_unique_prefix(e){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},[...Array(e.length)].map(s=>e.characters[Math.random()*e.characters.length|0]).join("")}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let s={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},n,t,o,d=!1,a=new Promise((i,c)=>(t=i,o=c)),u=(i,c)=>{for(let h of s[i])if(h)try{h(c)}catch(f){console.error(`st_ajax: ${i} error`,f)}},l={then:(i,c)=>a.then(i,c),catch:i=>a.catch(i),finally:i=>a.finally(i),abort:()=>n?.abort()};for(let i of Object.keys(s))l[i]=c=>(s[i].push(c),l);let p=i=>{if(d)return;d=!0;let c=i instanceof XMLHttpRequest?{status:i.status,status_text:i.statusText,response:i.responseText,request:i}:{status:void 0,status_text:"",response:i};u("onFailed",c),o(c)};return queueMicrotask(()=>{try{let i=e.url,c=e.method,h;if(u("beforeSend",e),e.data instanceof FormData?h=e.data:e.data instanceof HTMLFormElement?(i=i||e.data.getAttribute("action"),c=c||e.data.getAttribute("method"),h=new FormData(e.data)):h=e.data,i=i||window.location.href,c=c?c.toUpperCase():"GET",h&&typeof h=="object")if(c=="GET"){let f=h instanceof FormData?new URLSearchParams(h).toString():Object.entries(h).map(([y,b])=>`${encodeURIComponent(y)}=${encodeURIComponent(b)}`).join("&");f&&(i+=(/\?.+=/.test(i)?"&":"?")+f),h=null}else h instanceof FormData||(h=JSON.stringify(e.data),Object.keys(e.headers).some(f=>f.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(n=new XMLHttpRequest,e.response_type)try{n.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(n.timeout=e.timeout),n.onerror=n.ontimeout=()=>p(n),n.onreadystatechange=()=>{if(n.readyState!==4)return;let f;if(n.status>=200&&n.status<300){if(n.responseType)f=n.response;else{let y=n.getResponseHeader("Content-Type")||e.response_type||"";if(y.includes("/json"))try{f=JSON.parse(n.responseText)}catch{f=n.responseText}else y.includes("/xml")?f=new DOMParser().parseFromString(n.responseText,"application/xml"):y.includes("/html")?f=new DOMParser().parseFromString(n.responseText,"text/html"):f=n.responseText}u("onSuccess",{data:f,request:n}),d=!0,t({data:f,request:n})}else p(n);u("onComplete",{data:f,request:n})},n.open(c,i,!0);for(let f in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,f))try{n.setRequestHeader(f,e.headers[f])}catch{}n.send(h),u("onSend",{detail:e})}catch(i){p(i)}}),l}};var E={app:"form",action:null,method:null,headers:null,validators:{},validate(r){this.validators={...this.validators,...r}},configure(r){let e=this;e.addEventListener("setup",()=>{if(r.validate&&e.validate(r.validate),r.form)for(let[s,n]of Object.entries(r.form))e.addEventListener(`form:${s}`,n);if(r.field)for(let[s,n]of Object.entries(r.field))e.addEventListener(`field:${s}`,n)}),r.setup&&(e.form?queueMicrotask(r.setup.bind(e)):e.addEventListener("rendered",r.setup.bind(e),{once:!0}))},setup(){this._validators=new WeakMap},events:{rendered:function(){let r=this;if(!(r._form=r.querySelector("form")))return console.error("form: <form> not found");r.form.querySelector("input[type=file]")&&(r.form.enctype="multipart/form-data"),r.action&&(r.form.action=r.action),r.method&&(r.form.method=r.method),r.form.app=r,r.form.addEventListener("input",e=>{let s=e.target;s.name&&(r._validators.has(s)&&s.setCustomValidity(""),r.dispatchEvent("field:input",{field:s,name:s.name,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0}))}),r.form.addEventListener("focus",e=>{let s=e.target;s.name&&r.dispatchEvent("field:focus",{field:s,name:s.name,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0})},!0),r.form.addEventListener("invalid",e=>{let s=e.target;r.dispatchEvent("field:invalid",{field:s,name:s.name||s.id||null,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0})||e.preventDefault()},!0),r.form.addEventListener("submit",e=>{e.preventDefault(),r._submit()}),r.watch("validators",e=>{if(r.form)for(let[s,n]of Object.entries(e))r.fields(s).forEach(t=>{if(r._validators.set(t,n),t.__validatorPatched)return;t.__validatorPatched=!0;let o=t.checkValidity.bind(t),d=t.reportValidity.bind(t);t.checkValidity=()=>{let a=r._validators.get(t);if(a){let u=a(t);t.setCustomValidity(u||"")}return o()},t.reportValidity=()=>(t.checkValidity(),d())})},{immediate:!0})}},get form(){return this._form},fields(r=null){return r?r.includes(" ")||r.includes("#")||r.includes(".")||r.includes("[")||r.includes(">")||r.includes(":")?this.form.querySelectorAll(r):this.form.querySelectorAll(`[name="${CSS.escape(r)}"]`):Array.from(this.form.elements)},field(r){let e=this.fields(r);return e.length?e[0]:null},appendField(r,e,s={}){let{tag:n="input",...t}=s,o=this.field(r);if(o){Object.assign(o,{...t,value:e});return}o=document.createElement(n),Object.assign(o,{type:"hidden",...t,name:r,value:e}),this.form.appendChild(o)},removeField(r){let e=this.field(r);if(!e)return;let s=e.id||r,n=this.form.querySelector(`label[for="${s}"]`)||e.closest("label");n&&n.remove(),e.remove()},resetField(r){let e=Array.from(this.fields(r));if(!e.length)return;let s=e.every(o=>o.type==="checkbox"),n=e.every(o=>o.type==="radio"),t=e.every(o=>o.type==="file");s||n?e.forEach(o=>{o.checked=!1}):t?e.forEach(o=>{o.value=""}):e.length===1&&e[0].multiple?Array.from(e[0].options).forEach(o=>{o.selected=!1}):e[0].value=""},reset(){this.form.reset(),this.dispatchEvent("form:reset")},fill(r){let e=this,s=(n,t)=>{let o=d=>{let a=new DataTransfer;a.items.add(d),n.files=a.files};if(t instanceof File){o(t);return}if(typeof t=="string"&&t.startsWith("data:")){let[d,a]=t.split(","),u=d.match(/:(.*?);/)?.[1]||"application/octet-stream",l=atob(a),p=new Uint8Array(l.length);for(let c=0;c<l.length;c++)p[c]=l.charCodeAt(c);let i=new Blob([p],{type:u});o(new File([i],"file",{type:u}));return}if(typeof t=="string"){let d=t.split("/").pop().split("?")[0]||"file";fetch(t).then(a=>a.blob()).then(a=>o(new File([a],d,{type:a.type}))).catch(()=>{})}};for(let[n,t]of Object.entries(r)){let o=Array.from(e.fields(n));if(!o.length)continue;let d=o.every(l=>l.type==="file"),a=o.every(l=>l.type==="checkbox"),u=o.every(l=>l.type==="radio");if(d){let l=Array.isArray(t)?t:[t];o.forEach((p,i)=>{let c=l[i]!==void 0?l[i]:l[0];c!=null&&s(p,c)})}else if(a)o.forEach(l=>{typeof t=="boolean"?l.checked=t:Array.isArray(t)?l.checked=t.map(String).includes(l.value):l.checked=String(l.value)===String(t)});else if(u)o.forEach(l=>{l.checked=String(l.value)===String(t)});else if(o.length===1&&o[0].multiple&&Array.isArray(t)){let l=o[0];Array.from(l.options).forEach(p=>{p.selected=t.map(String).includes(p.value)})}else Array.isArray(t)?o.forEach((l,p)=>{t[p]!==void 0&&(l.value=t[p])}):o[0].value=t??""}},hide(){this.style.display="none"},show(){this.style.display=""},_submit(){let r=this,e=r.form,s=r.fields();s.forEach(t=>{r._validators.has(t)&&t.setCustomValidity("")}),s.forEach(t=>{if(!r._validators.has(t))return;let o=r._validators.get(t)(t);t.setCustomValidity(o||"")});let n={};if(s.forEach(t=>{if(!t.validity.valid){let o=t.name||t.id||null;o&&(n[o]=t.validationMessage)}}),Object.keys(n).length){r.dispatchEvent("form:invalid",{errors:n},{bubbles:!0})&&e.reportValidity();return}r._send()},_send(){let r=this,e=r.form,s={url:r.action||e.getAttribute("action")||window.location.href,method:r.method||e.getAttribute("method")||"GET",headers:r.headers||{},data:new FormData(e)};r.dispatchEvent("form:before_send",s,{bubbles:!0});let n=!1;m.fetch(s).onSend(({detail:t})=>{r.dispatchEvent("form:send",{detail:t},{bubbles:!0})}).onSuccess(({data:t,request:o})=>{if(t&&typeof t=="object"&&t.redirect){n=!0;let d=r.dispatchEvent("form:redirect",{url:t.redirect,data:t,request:o},{bubbles:!0});r.dispatchEvent("form:complete",{data:t,request:o},{bubbles:!0}),d&&(window.location.href=t.redirect);return}r.dispatchEvent("form:success",{data:t,request:o},{bubbles:!0})}).onFailed(t=>{r.dispatchEvent("form:failed",t,{bubbles:!0})}).onComplete(({data:t,request:o})=>{n||r.dispatchEvent("form:complete",{data:t,request:o},{bubbles:!0})})}};export{E as default};
1
+ var m=class{static merge(...e){let o=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&(Object.getPrototypeOf(t)??Object.prototype)===Object.prototype,n=(t,s)=>{if(typeof t=="function"&&typeof s=="function")return(...a)=>n(t(...a),s(...a));if(!(Array.isArray(t)&&Array.isArray(s)||o(t)&&o(s)))return s;let d=Array.isArray(t)?t.slice():{...t};for(let[a,u]of Object.entries(s))d[a]=a in d?n(d[a],u):u;return d};return e.reduce(n,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),o=>e.characters[o%e.characters.length]).join("")}static uuid(e=7){let o=crypto.getRandomValues(new Uint8Array(16));if(e===4)o[6]=o[6]&15|64;else{for(let t=0;t<6;t++)o[t]=Number(BigInt(Date.now())>>BigInt(40-t*8)&0xffn);o[6]=o[6]&15|112}o[8]=o[8]&63|128;let n=Array.from(o,t=>t.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let o={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},n,t,s,d=!1,a=new Promise((i,c)=>(t=i,s=c)),u=(i,c)=>{for(let h of o[i])if(h)try{h(c)}catch(f){console.error(`st_ajax: ${i} error`,f)}},l={then:(i,c)=>a.then(i,c),catch:i=>a.catch(i),finally:i=>a.finally(i),abort:()=>n?.abort()};for(let i of Object.keys(o))l[i]=c=>(o[i].push(c),l);let y=i=>{if(d)return;d=!0;let c=i instanceof XMLHttpRequest?{status:i.status,status_text:i.statusText,response:i.responseText,request:i}:{status:void 0,status_text:"",response:i};u("onFailed",c),s(c)};return queueMicrotask(()=>{try{let i=e.url,c=e.method,h;if(u("beforeSend",e),e.data instanceof FormData?h=e.data:e.data instanceof HTMLFormElement?(i=i||e.data.getAttribute("action"),c=c||e.data.getAttribute("method"),h=new FormData(e.data)):h=e.data,i=i||window.location.href,c=c?c.toUpperCase():"GET",h&&typeof h=="object")if(c=="GET"){let f=h instanceof FormData?new URLSearchParams(h).toString():Object.entries(h).map(([p,b])=>`${encodeURIComponent(p)}=${encodeURIComponent(b)}`).join("&");f&&(i+=(/\?.+=/.test(i)?"&":"?")+f),h=null}else h instanceof FormData||(h=JSON.stringify(e.data),Object.keys(e.headers).some(f=>f.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(n=new XMLHttpRequest,e.response_type)try{n.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(n.timeout=e.timeout),n.onerror=n.ontimeout=()=>y(n),n.onreadystatechange=()=>{if(n.readyState!==4)return;let f;if(n.status>=200&&n.status<300){if(n.responseType)f=n.response;else{let p=n.getResponseHeader("Content-Type")||e.response_type||"";if(p.includes("/json"))try{f=JSON.parse(n.responseText)}catch{f=n.responseText}else p.includes("/xml")?f=new DOMParser().parseFromString(n.responseText,"application/xml"):p.includes("/html")?f=new DOMParser().parseFromString(n.responseText,"text/html"):f=n.responseText}u("onSuccess",{data:f,request:n}),d=!0,t({data:f,request:n})}else y(n);u("onComplete",{data:f,request:n})},n.open(c,i,!0);for(let f in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,f))try{n.setRequestHeader(f,e.headers[f])}catch{}n.send(h),u("onSend",{detail:e})}catch(i){y(i)}}),l}};var E={app:"form",action:null,method:null,headers:null,validators:{},validate(r){this.validators={...this.validators,...r}},configure(r){let e=this;e.addEventListener("setup",()=>{if(r.validate&&e.validate(r.validate),r.form)for(let[o,n]of Object.entries(r.form))e.addEventListener(`form:${o}`,n);if(r.field)for(let[o,n]of Object.entries(r.field))e.addEventListener(`field:${o}`,n)}),r.setup&&(e.form?queueMicrotask(r.setup.bind(e)):e.addEventListener("rendered",r.setup.bind(e),{once:!0}))},setup(){this._validators=new WeakMap},events:{rendered:function(){let r=this;if(!(r._form=r.querySelector("form")))return console.error("form: <form> not found");r.form.querySelector("input[type=file]")&&(r.form.enctype="multipart/form-data"),r.action&&(r.form.action=r.action),r.method&&(r.form.method=r.method),r.form.app=r,r.form.addEventListener("input",e=>{let o=e.target;o.name&&(r._validators.has(o)&&o.setCustomValidity(""),r.dispatchEvent("field:input",{field:o,name:o.name,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0}))}),r.form.addEventListener("focus",e=>{let o=e.target;o.name&&r.dispatchEvent("field:focus",{field:o,name:o.name,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0})},!0),r.form.addEventListener("invalid",e=>{let o=e.target;r.dispatchEvent("field:invalid",{field:o,name:o.name||o.id||null,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0})||e.preventDefault()},!0),r.form.addEventListener("submit",e=>{e.preventDefault(),r._submit()}),r.watch("validators",e=>{if(r.form)for(let[o,n]of Object.entries(e))r.fields(o).forEach(t=>{if(r._validators.set(t,n),t.__validatorPatched)return;t.__validatorPatched=!0;let s=t.checkValidity.bind(t),d=t.reportValidity.bind(t);t.checkValidity=()=>{let a=r._validators.get(t);if(a){let u=a(t);t.setCustomValidity(u||"")}return s()},t.reportValidity=()=>(t.checkValidity(),d())})},{immediate:!0})}},get form(){return this._form},fields(r=null){return r?r.includes(" ")||r.includes("#")||r.includes(".")||r.includes("[")||r.includes(">")||r.includes(":")?this.form.querySelectorAll(r):this.form.querySelectorAll(`[name="${CSS.escape(r)}"]`):Array.from(this.form.elements)},field(r){let e=this.fields(r);return e.length?e[0]:null},appendField(r,e,o={}){let{tag:n="input",...t}=o,s=this.field(r);if(s){Object.assign(s,{...t,value:e});return}s=document.createElement(n),Object.assign(s,{type:"hidden",...t,name:r,value:e}),this.form.appendChild(s)},removeField(r){let e=this.field(r);if(!e)return;let o=e.id||r,n=this.form.querySelector(`label[for="${o}"]`)||e.closest("label");n&&n.remove(),e.remove()},resetField(r){let e=Array.from(this.fields(r));if(!e.length)return;let o=e.every(s=>s.type==="checkbox"),n=e.every(s=>s.type==="radio"),t=e.every(s=>s.type==="file");o||n?e.forEach(s=>{s.checked=!1}):t?e.forEach(s=>{s.value=""}):e.length===1&&e[0].multiple?Array.from(e[0].options).forEach(s=>{s.selected=!1}):e[0].value=""},reset(){this.form.reset(),this.dispatchEvent("form:reset")},fill(r){let e=this,o=(n,t)=>{let s=d=>{let a=new DataTransfer;a.items.add(d),n.files=a.files};if(t instanceof File){s(t);return}if(typeof t=="string"&&t.startsWith("data:")){let[d,a]=t.split(","),u=d.match(/:(.*?);/)?.[1]||"application/octet-stream",l=atob(a),y=new Uint8Array(l.length);for(let c=0;c<l.length;c++)y[c]=l.charCodeAt(c);let i=new Blob([y],{type:u});s(new File([i],"file",{type:u}));return}if(typeof t=="string"){let d=t.split("/").pop().split("?")[0]||"file";fetch(t).then(a=>a.blob()).then(a=>s(new File([a],d,{type:a.type}))).catch(()=>{})}};for(let[n,t]of Object.entries(r)){let s=Array.from(e.fields(n));if(!s.length)continue;let d=s.every(l=>l.type==="file"),a=s.every(l=>l.type==="checkbox"),u=s.every(l=>l.type==="radio");if(d){let l=Array.isArray(t)?t:[t];s.forEach((y,i)=>{let c=l[i]!==void 0?l[i]:l[0];c!=null&&o(y,c)})}else if(a)s.forEach(l=>{typeof t=="boolean"?l.checked=t:Array.isArray(t)?l.checked=t.map(String).includes(l.value):l.checked=String(l.value)===String(t)});else if(u)s.forEach(l=>{l.checked=String(l.value)===String(t)});else if(s.length===1&&s[0].multiple&&Array.isArray(t)){let l=s[0];Array.from(l.options).forEach(y=>{y.selected=t.map(String).includes(y.value)})}else Array.isArray(t)?s.forEach((l,y)=>{t[y]!==void 0&&(l.value=t[y])}):s[0].value=t??""}},hide(){this.style.display="none"},show(){this.style.display=""},_submit(){let r=this,e=r.form,o=r.fields();o.forEach(t=>{r._validators.has(t)&&t.setCustomValidity("")}),o.forEach(t=>{if(!r._validators.has(t))return;let s=r._validators.get(t)(t);t.setCustomValidity(s||"")});let n={};if(o.forEach(t=>{if(!t.validity.valid){let s=t.name||t.id||null;s&&(n[s]=t.validationMessage)}}),Object.keys(n).length){r.dispatchEvent("form:invalid",{errors:n},{bubbles:!0})&&e.reportValidity();return}r._send()},_send(){let r=this,e=r.form,o={url:r.action||e.getAttribute("action")||window.location.href,method:r.method||e.getAttribute("method")||"GET",headers:r.headers||{},data:new FormData(e)};r.dispatchEvent("form:before_send",o,{bubbles:!0});let n=!1;m.fetch(o).onSend(({detail:t})=>{r.dispatchEvent("form:send",{detail:t},{bubbles:!0})}).onSuccess(({data:t,request:s})=>{if(t&&typeof t=="object"&&t.redirect){n=!0;let d=r.dispatchEvent("form:redirect",{url:t.redirect,data:t,request:s},{bubbles:!0});r.dispatchEvent("form:complete",{data:t,request:s},{bubbles:!0}),d&&(window.location.href=t.redirect);return}r.dispatchEvent("form:success",{data:t,request:s},{bubbles:!0})}).onFailed(t=>{r.dispatchEvent("form:failed",t,{bubbles:!0})}).onComplete(({data:t,request:s})=>{n||r.dispatchEvent("form:complete",{data:t,request:s},{bubbles:!0})})}};export{E as default};
@@ -1,2 +1,2 @@
1
- var form=(()=>{var b=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var A=(r,e)=>{for(var s in e)b(r,s,{get:e[s],enumerable:!0})},S=(r,e,s,o)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of E(e))!_.call(r,t)&&t!==s&&b(r,t,{get:()=>e[t],enumerable:!(o=g(e,t))||o.enumerable});return r};var k=r=>S(b({},"__esModule",{value:!0}),r);var j={};A(j,{default:()=>F});var m=class{static merge(...e){let s=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&(Object.getPrototypeOf(t)??Object.prototype)===Object.prototype,o=(t,n)=>{if(typeof t=="function"&&typeof n=="function")return(...a)=>o(t(...a),n(...a));if(!(Array.isArray(t)&&Array.isArray(n)||s(t)&&s(n)))return n;let d=Array.isArray(t)?t.slice():{...t};for(let[a,u]of Object.entries(n))d[a]=a in d?o(d[a],u):u;return d};return e.reduce(o,{})}static generate_unique_prefix(e){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},[...Array(e.length)].map(s=>e.characters[Math.random()*e.characters.length|0]).join("")}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let s={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},o,t,n,d=!1,a=new Promise((i,c)=>(t=i,n=c)),u=(i,c)=>{for(let h of s[i])if(h)try{h(c)}catch(f){console.error(`st_ajax: ${i} error`,f)}},l={then:(i,c)=>a.then(i,c),catch:i=>a.catch(i),finally:i=>a.finally(i),abort:()=>o?.abort()};for(let i of Object.keys(s))l[i]=c=>(s[i].push(c),l);let p=i=>{if(d)return;d=!0;let c=i instanceof XMLHttpRequest?{status:i.status,status_text:i.statusText,response:i.responseText,request:i}:{status:void 0,status_text:"",response:i};u("onFailed",c),n(c)};return queueMicrotask(()=>{try{let i=e.url,c=e.method,h;if(u("beforeSend",e),e.data instanceof FormData?h=e.data:e.data instanceof HTMLFormElement?(i=i||e.data.getAttribute("action"),c=c||e.data.getAttribute("method"),h=new FormData(e.data)):h=e.data,i=i||window.location.href,c=c?c.toUpperCase():"GET",h&&typeof h=="object")if(c=="GET"){let f=h instanceof FormData?new URLSearchParams(h).toString():Object.entries(h).map(([y,v])=>`${encodeURIComponent(y)}=${encodeURIComponent(v)}`).join("&");f&&(i+=(/\?.+=/.test(i)?"&":"?")+f),h=null}else h instanceof FormData||(h=JSON.stringify(e.data),Object.keys(e.headers).some(f=>f.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(o=new XMLHttpRequest,e.response_type)try{o.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(o.timeout=e.timeout),o.onerror=o.ontimeout=()=>p(o),o.onreadystatechange=()=>{if(o.readyState!==4)return;let f;if(o.status>=200&&o.status<300){if(o.responseType)f=o.response;else{let y=o.getResponseHeader("Content-Type")||e.response_type||"";if(y.includes("/json"))try{f=JSON.parse(o.responseText)}catch{f=o.responseText}else y.includes("/xml")?f=new DOMParser().parseFromString(o.responseText,"application/xml"):y.includes("/html")?f=new DOMParser().parseFromString(o.responseText,"text/html"):f=o.responseText}u("onSuccess",{data:f,request:o}),d=!0,t({data:f,request:o})}else p(o);u("onComplete",{data:f,request:o})},o.open(c,i,!0);for(let f in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,f))try{o.setRequestHeader(f,e.headers[f])}catch{}o.send(h),u("onSend",{detail:e})}catch(i){p(i)}}),l}};var F={app:"form",action:null,method:null,headers:null,validators:{},validate(r){this.validators={...this.validators,...r}},configure(r){let e=this;e.addEventListener("setup",()=>{if(r.validate&&e.validate(r.validate),r.form)for(let[s,o]of Object.entries(r.form))e.addEventListener(`form:${s}`,o);if(r.field)for(let[s,o]of Object.entries(r.field))e.addEventListener(`field:${s}`,o)}),r.setup&&(e.form?queueMicrotask(r.setup.bind(e)):e.addEventListener("rendered",r.setup.bind(e),{once:!0}))},setup(){this._validators=new WeakMap},events:{rendered:function(){let r=this;if(!(r._form=r.querySelector("form")))return console.error("form: <form> not found");r.form.querySelector("input[type=file]")&&(r.form.enctype="multipart/form-data"),r.action&&(r.form.action=r.action),r.method&&(r.form.method=r.method),r.form.app=r,r.form.addEventListener("input",e=>{let s=e.target;s.name&&(r._validators.has(s)&&s.setCustomValidity(""),r.dispatchEvent("field:input",{field:s,name:s.name,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0}))}),r.form.addEventListener("focus",e=>{let s=e.target;s.name&&r.dispatchEvent("field:focus",{field:s,name:s.name,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0})},!0),r.form.addEventListener("invalid",e=>{let s=e.target;r.dispatchEvent("field:invalid",{field:s,name:s.name||s.id||null,value:s.type==="checkbox"?s.checked:s.value},{bubbles:!0})||e.preventDefault()},!0),r.form.addEventListener("submit",e=>{e.preventDefault(),r._submit()}),r.watch("validators",e=>{if(r.form)for(let[s,o]of Object.entries(e))r.fields(s).forEach(t=>{if(r._validators.set(t,o),t.__validatorPatched)return;t.__validatorPatched=!0;let n=t.checkValidity.bind(t),d=t.reportValidity.bind(t);t.checkValidity=()=>{let a=r._validators.get(t);if(a){let u=a(t);t.setCustomValidity(u||"")}return n()},t.reportValidity=()=>(t.checkValidity(),d())})},{immediate:!0})}},get form(){return this._form},fields(r=null){return r?r.includes(" ")||r.includes("#")||r.includes(".")||r.includes("[")||r.includes(">")||r.includes(":")?this.form.querySelectorAll(r):this.form.querySelectorAll(`[name="${CSS.escape(r)}"]`):Array.from(this.form.elements)},field(r){let e=this.fields(r);return e.length?e[0]:null},appendField(r,e,s={}){let{tag:o="input",...t}=s,n=this.field(r);if(n){Object.assign(n,{...t,value:e});return}n=document.createElement(o),Object.assign(n,{type:"hidden",...t,name:r,value:e}),this.form.appendChild(n)},removeField(r){let e=this.field(r);if(!e)return;let s=e.id||r,o=this.form.querySelector(`label[for="${s}"]`)||e.closest("label");o&&o.remove(),e.remove()},resetField(r){let e=Array.from(this.fields(r));if(!e.length)return;let s=e.every(n=>n.type==="checkbox"),o=e.every(n=>n.type==="radio"),t=e.every(n=>n.type==="file");s||o?e.forEach(n=>{n.checked=!1}):t?e.forEach(n=>{n.value=""}):e.length===1&&e[0].multiple?Array.from(e[0].options).forEach(n=>{n.selected=!1}):e[0].value=""},reset(){this.form.reset(),this.dispatchEvent("form:reset")},fill(r){let e=this,s=(o,t)=>{let n=d=>{let a=new DataTransfer;a.items.add(d),o.files=a.files};if(t instanceof File){n(t);return}if(typeof t=="string"&&t.startsWith("data:")){let[d,a]=t.split(","),u=d.match(/:(.*?);/)?.[1]||"application/octet-stream",l=atob(a),p=new Uint8Array(l.length);for(let c=0;c<l.length;c++)p[c]=l.charCodeAt(c);let i=new Blob([p],{type:u});n(new File([i],"file",{type:u}));return}if(typeof t=="string"){let d=t.split("/").pop().split("?")[0]||"file";fetch(t).then(a=>a.blob()).then(a=>n(new File([a],d,{type:a.type}))).catch(()=>{})}};for(let[o,t]of Object.entries(r)){let n=Array.from(e.fields(o));if(!n.length)continue;let d=n.every(l=>l.type==="file"),a=n.every(l=>l.type==="checkbox"),u=n.every(l=>l.type==="radio");if(d){let l=Array.isArray(t)?t:[t];n.forEach((p,i)=>{let c=l[i]!==void 0?l[i]:l[0];c!=null&&s(p,c)})}else if(a)n.forEach(l=>{typeof t=="boolean"?l.checked=t:Array.isArray(t)?l.checked=t.map(String).includes(l.value):l.checked=String(l.value)===String(t)});else if(u)n.forEach(l=>{l.checked=String(l.value)===String(t)});else if(n.length===1&&n[0].multiple&&Array.isArray(t)){let l=n[0];Array.from(l.options).forEach(p=>{p.selected=t.map(String).includes(p.value)})}else Array.isArray(t)?n.forEach((l,p)=>{t[p]!==void 0&&(l.value=t[p])}):n[0].value=t??""}},hide(){this.style.display="none"},show(){this.style.display=""},_submit(){let r=this,e=r.form,s=r.fields();s.forEach(t=>{r._validators.has(t)&&t.setCustomValidity("")}),s.forEach(t=>{if(!r._validators.has(t))return;let n=r._validators.get(t)(t);t.setCustomValidity(n||"")});let o={};if(s.forEach(t=>{if(!t.validity.valid){let n=t.name||t.id||null;n&&(o[n]=t.validationMessage)}}),Object.keys(o).length){r.dispatchEvent("form:invalid",{errors:o},{bubbles:!0})&&e.reportValidity();return}r._send()},_send(){let r=this,e=r.form,s={url:r.action||e.getAttribute("action")||window.location.href,method:r.method||e.getAttribute("method")||"GET",headers:r.headers||{},data:new FormData(e)};r.dispatchEvent("form:before_send",s,{bubbles:!0});let o=!1;m.fetch(s).onSend(({detail:t})=>{r.dispatchEvent("form:send",{detail:t},{bubbles:!0})}).onSuccess(({data:t,request:n})=>{if(t&&typeof t=="object"&&t.redirect){o=!0;let d=r.dispatchEvent("form:redirect",{url:t.redirect,data:t,request:n},{bubbles:!0});r.dispatchEvent("form:complete",{data:t,request:n},{bubbles:!0}),d&&(window.location.href=t.redirect);return}r.dispatchEvent("form:success",{data:t,request:n},{bubbles:!0})}).onFailed(t=>{r.dispatchEvent("form:failed",t,{bubbles:!0})}).onComplete(({data:t,request:n})=>{o||r.dispatchEvent("form:complete",{data:t,request:n},{bubbles:!0})})}};return k(j);})();
2
- if(typeof form!=="undefined"&&form&&form.default)globalThis.form=form.default;
1
+ var Form=(()=>{var b=Object.defineProperty;var g=Object.getOwnPropertyDescriptor;var E=Object.getOwnPropertyNames;var A=Object.prototype.hasOwnProperty;var S=(r,e)=>{for(var o in e)b(r,o,{get:e[o],enumerable:!0})},x=(r,e,o,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of E(e))!A.call(r,t)&&t!==o&&b(r,t,{get:()=>e[t],enumerable:!(n=g(e,t))||n.enumerable});return r};var _=r=>x(b({},"__esModule",{value:!0}),r);var w={};S(w,{default:()=>k});var m=class{static merge(...e){let o=t=>t!==null&&typeof t=="object"&&!Array.isArray(t)&&(Object.getPrototypeOf(t)??Object.prototype)===Object.prototype,n=(t,s)=>{if(typeof t=="function"&&typeof s=="function")return(...a)=>n(t(...a),s(...a));if(!(Array.isArray(t)&&Array.isArray(s)||o(t)&&o(s)))return s;let d=Array.isArray(t)?t.slice():{...t};for(let[a,u]of Object.entries(s))d[a]=a in d?n(d[a],u):u;return d};return e.reduce(n,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),o=>e.characters[o%e.characters.length]).join("")}static uuid(e=7){let o=crypto.getRandomValues(new Uint8Array(16));if(e===4)o[6]=o[6]&15|64;else{for(let t=0;t<6;t++)o[t]=Number(BigInt(Date.now())>>BigInt(40-t*8)&0xffn);o[6]=o[6]&15|112}o[8]=o[8]&63|128;let n=Array.from(o,t=>t.toString(16).padStart(2,"0")).join("");return`${n.slice(0,8)}-${n.slice(8,12)}-${n.slice(12,16)}-${n.slice(16,20)}-${n.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let o={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},n,t,s,d=!1,a=new Promise((i,c)=>(t=i,s=c)),u=(i,c)=>{for(let h of o[i])if(h)try{h(c)}catch(f){console.error(`st_ajax: ${i} error`,f)}},l={then:(i,c)=>a.then(i,c),catch:i=>a.catch(i),finally:i=>a.finally(i),abort:()=>n?.abort()};for(let i of Object.keys(o))l[i]=c=>(o[i].push(c),l);let y=i=>{if(d)return;d=!0;let c=i instanceof XMLHttpRequest?{status:i.status,status_text:i.statusText,response:i.responseText,request:i}:{status:void 0,status_text:"",response:i};u("onFailed",c),s(c)};return queueMicrotask(()=>{try{let i=e.url,c=e.method,h;if(u("beforeSend",e),e.data instanceof FormData?h=e.data:e.data instanceof HTMLFormElement?(i=i||e.data.getAttribute("action"),c=c||e.data.getAttribute("method"),h=new FormData(e.data)):h=e.data,i=i||window.location.href,c=c?c.toUpperCase():"GET",h&&typeof h=="object")if(c=="GET"){let f=h instanceof FormData?new URLSearchParams(h).toString():Object.entries(h).map(([p,v])=>`${encodeURIComponent(p)}=${encodeURIComponent(v)}`).join("&");f&&(i+=(/\?.+=/.test(i)?"&":"?")+f),h=null}else h instanceof FormData||(h=JSON.stringify(e.data),Object.keys(e.headers).some(f=>f.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(n=new XMLHttpRequest,e.response_type)try{n.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(n.timeout=e.timeout),n.onerror=n.ontimeout=()=>y(n),n.onreadystatechange=()=>{if(n.readyState!==4)return;let f;if(n.status>=200&&n.status<300){if(n.responseType)f=n.response;else{let p=n.getResponseHeader("Content-Type")||e.response_type||"";if(p.includes("/json"))try{f=JSON.parse(n.responseText)}catch{f=n.responseText}else p.includes("/xml")?f=new DOMParser().parseFromString(n.responseText,"application/xml"):p.includes("/html")?f=new DOMParser().parseFromString(n.responseText,"text/html"):f=n.responseText}u("onSuccess",{data:f,request:n}),d=!0,t({data:f,request:n})}else y(n);u("onComplete",{data:f,request:n})},n.open(c,i,!0);for(let f in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,f))try{n.setRequestHeader(f,e.headers[f])}catch{}n.send(h),u("onSend",{detail:e})}catch(i){y(i)}}),l}};var k={app:"form",action:null,method:null,headers:null,validators:{},validate(r){this.validators={...this.validators,...r}},configure(r){let e=this;e.addEventListener("setup",()=>{if(r.validate&&e.validate(r.validate),r.form)for(let[o,n]of Object.entries(r.form))e.addEventListener(`form:${o}`,n);if(r.field)for(let[o,n]of Object.entries(r.field))e.addEventListener(`field:${o}`,n)}),r.setup&&(e.form?queueMicrotask(r.setup.bind(e)):e.addEventListener("rendered",r.setup.bind(e),{once:!0}))},setup(){this._validators=new WeakMap},events:{rendered:function(){let r=this;if(!(r._form=r.querySelector("form")))return console.error("form: <form> not found");r.form.querySelector("input[type=file]")&&(r.form.enctype="multipart/form-data"),r.action&&(r.form.action=r.action),r.method&&(r.form.method=r.method),r.form.app=r,r.form.addEventListener("input",e=>{let o=e.target;o.name&&(r._validators.has(o)&&o.setCustomValidity(""),r.dispatchEvent("field:input",{field:o,name:o.name,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0}))}),r.form.addEventListener("focus",e=>{let o=e.target;o.name&&r.dispatchEvent("field:focus",{field:o,name:o.name,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0})},!0),r.form.addEventListener("invalid",e=>{let o=e.target;r.dispatchEvent("field:invalid",{field:o,name:o.name||o.id||null,value:o.type==="checkbox"?o.checked:o.value},{bubbles:!0})||e.preventDefault()},!0),r.form.addEventListener("submit",e=>{e.preventDefault(),r._submit()}),r.watch("validators",e=>{if(r.form)for(let[o,n]of Object.entries(e))r.fields(o).forEach(t=>{if(r._validators.set(t,n),t.__validatorPatched)return;t.__validatorPatched=!0;let s=t.checkValidity.bind(t),d=t.reportValidity.bind(t);t.checkValidity=()=>{let a=r._validators.get(t);if(a){let u=a(t);t.setCustomValidity(u||"")}return s()},t.reportValidity=()=>(t.checkValidity(),d())})},{immediate:!0})}},get form(){return this._form},fields(r=null){return r?r.includes(" ")||r.includes("#")||r.includes(".")||r.includes("[")||r.includes(">")||r.includes(":")?this.form.querySelectorAll(r):this.form.querySelectorAll(`[name="${CSS.escape(r)}"]`):Array.from(this.form.elements)},field(r){let e=this.fields(r);return e.length?e[0]:null},appendField(r,e,o={}){let{tag:n="input",...t}=o,s=this.field(r);if(s){Object.assign(s,{...t,value:e});return}s=document.createElement(n),Object.assign(s,{type:"hidden",...t,name:r,value:e}),this.form.appendChild(s)},removeField(r){let e=this.field(r);if(!e)return;let o=e.id||r,n=this.form.querySelector(`label[for="${o}"]`)||e.closest("label");n&&n.remove(),e.remove()},resetField(r){let e=Array.from(this.fields(r));if(!e.length)return;let o=e.every(s=>s.type==="checkbox"),n=e.every(s=>s.type==="radio"),t=e.every(s=>s.type==="file");o||n?e.forEach(s=>{s.checked=!1}):t?e.forEach(s=>{s.value=""}):e.length===1&&e[0].multiple?Array.from(e[0].options).forEach(s=>{s.selected=!1}):e[0].value=""},reset(){this.form.reset(),this.dispatchEvent("form:reset")},fill(r){let e=this,o=(n,t)=>{let s=d=>{let a=new DataTransfer;a.items.add(d),n.files=a.files};if(t instanceof File){s(t);return}if(typeof t=="string"&&t.startsWith("data:")){let[d,a]=t.split(","),u=d.match(/:(.*?);/)?.[1]||"application/octet-stream",l=atob(a),y=new Uint8Array(l.length);for(let c=0;c<l.length;c++)y[c]=l.charCodeAt(c);let i=new Blob([y],{type:u});s(new File([i],"file",{type:u}));return}if(typeof t=="string"){let d=t.split("/").pop().split("?")[0]||"file";fetch(t).then(a=>a.blob()).then(a=>s(new File([a],d,{type:a.type}))).catch(()=>{})}};for(let[n,t]of Object.entries(r)){let s=Array.from(e.fields(n));if(!s.length)continue;let d=s.every(l=>l.type==="file"),a=s.every(l=>l.type==="checkbox"),u=s.every(l=>l.type==="radio");if(d){let l=Array.isArray(t)?t:[t];s.forEach((y,i)=>{let c=l[i]!==void 0?l[i]:l[0];c!=null&&o(y,c)})}else if(a)s.forEach(l=>{typeof t=="boolean"?l.checked=t:Array.isArray(t)?l.checked=t.map(String).includes(l.value):l.checked=String(l.value)===String(t)});else if(u)s.forEach(l=>{l.checked=String(l.value)===String(t)});else if(s.length===1&&s[0].multiple&&Array.isArray(t)){let l=s[0];Array.from(l.options).forEach(y=>{y.selected=t.map(String).includes(y.value)})}else Array.isArray(t)?s.forEach((l,y)=>{t[y]!==void 0&&(l.value=t[y])}):s[0].value=t??""}},hide(){this.style.display="none"},show(){this.style.display=""},_submit(){let r=this,e=r.form,o=r.fields();o.forEach(t=>{r._validators.has(t)&&t.setCustomValidity("")}),o.forEach(t=>{if(!r._validators.has(t))return;let s=r._validators.get(t)(t);t.setCustomValidity(s||"")});let n={};if(o.forEach(t=>{if(!t.validity.valid){let s=t.name||t.id||null;s&&(n[s]=t.validationMessage)}}),Object.keys(n).length){r.dispatchEvent("form:invalid",{errors:n},{bubbles:!0})&&e.reportValidity();return}r._send()},_send(){let r=this,e=r.form,o={url:r.action||e.getAttribute("action")||window.location.href,method:r.method||e.getAttribute("method")||"GET",headers:r.headers||{},data:new FormData(e)};r.dispatchEvent("form:before_send",o,{bubbles:!0});let n=!1;m.fetch(o).onSend(({detail:t})=>{r.dispatchEvent("form:send",{detail:t},{bubbles:!0})}).onSuccess(({data:t,request:s})=>{if(t&&typeof t=="object"&&t.redirect){n=!0;let d=r.dispatchEvent("form:redirect",{url:t.redirect,data:t,request:s},{bubbles:!0});r.dispatchEvent("form:complete",{data:t,request:s},{bubbles:!0}),d&&(window.location.href=t.redirect);return}r.dispatchEvent("form:success",{data:t,request:s},{bubbles:!0})}).onFailed(t=>{r.dispatchEvent("form:failed",t,{bubbles:!0})}).onComplete(({data:t,request:s})=>{n||r.dispatchEvent("form:complete",{data:t,request:s},{bubbles:!0})})}};return _(w);})();
2
+ if(typeof Form!=="undefined"&&Form&&Form.default)globalThis.Form=Form.default;
package/dist/app.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var app=(()=>{var E=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var P=(c,e)=>{for(var t in e)E(c,t,{get:e[t],enumerable:!0})},C=(c,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!L.call(c,r)&&r!==t&&E(c,r,{get:()=>e[r],enumerable:!(i=T(e,r))||i.enumerable});return c};var M=c=>C(E({},"__esModule",{value:!0}),c);var $={};P($,{default:()=>g});var g=class c extends HTMLElement{static#C=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#d=new Map;static#p=new Set;static create(e){let{app:t,setup:i=()=>{},template:r="",events:l={}}=e;if(c.#d.has(t))throw new Error(`Application "${t}" already exists!`);c.#d.set(t,{setup:i,template:r,events:l,config:e}),c.#p.forEach(s=>{s.#i!==!0&&s.#P()})}static extend(e,t={}){let i=c.#d.get(e);if(!i)throw new Error(`Application "${e}" not found!`);let r=i.config,l={...r,...t};return(r.events||t.events)&&(l.events={...r.events,...t.events}),c.create(l)}#i=!1;#u="";#S=!1;#s=new Map;#y=null;#h=new Set;#m=!1;#e=[];#r=null;#M=new Map;#l=null;#t=[];#b=new Set;#x=!1;#n=new Map;#k=0;constructor(){super(),c.#p.add(this)}#g(e){!e||!e.length||e.forEach(t=>{if(t.type==="event"&&t.element&&t.handler)t.element.removeEventListener(t.eventName,t.handler);else if(t.type==="model"&&t.element&&t.handler){let i=t.element.tagName==="SELECT"?"change":"input";t.element.removeEventListener(i,t.handler)}else t.type==="attrSync"&&t.unwatch&&t.unwatch();t.effect&&(this.#s.forEach((i,r)=>{i.delete(t.effect),i.size===0&&this.#s.delete(r)}),this.#h.delete(t.effect))})}get template(){return this.#u}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.#S){queueMicrotask(()=>t(new CustomEvent(e)));return}super.addEventListener(e,t,i)}dispatchEvent(e,t=null,i={}){if(typeof e=="string"){let r=new CustomEvent(e,{cancelable:!0,...i,detail:t});return super.dispatchEvent(r)}return super.dispatchEvent(e)}applyTemplate(e=""){let t=e||this.#u;if(this.#g(this.#e),this.#e=[],this.innerHTML="",t){let r=document.createElement("template");r.innerHTML=t.trim();let l=r.content.cloneNode(!0);Array.from(l.childNodes).forEach(s=>this.#E(s)),this.#$(l)}let i=++this.#k;new Promise(r=>{let l=null,s,n=()=>{clearTimeout(l),l=setTimeout(()=>{s.disconnect(),this.#A(Array.from(this.children)).then(r)},0)};s=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&n()}),s.observe(this,{childList:!0}),n()}).then(()=>{i===this.#k&&(this.#S=!0,this.dispatchEvent("rendered"))})}#$(e){HTMLElement.prototype.appendChild.call(this,e)}clone(e={}){let t=this.attrs.get("app");return c.extend(t,e)}watch(e,t,i={}){if(typeof t!="function")return()=>{};let{deep:r=!1,immediate:l=!1}=i;if(typeof e=="string"&&e.endsWith("()")){let s=e.slice(0,-2),n=this[s];if(typeof n!="function")return()=>{};let h=this.#n.get(s);if(!h){h={original:n,handlers:[]},this.#n.set(s,h);let f=(...o)=>{let u=n.apply(this,o),d=p=>{for(let y of[...h.handlers])y.callback(o,p,y.unwatch)};return u instanceof Promise?u.then(p=>(d(p),p)):(d(u),u)};this[s]=f}let a=()=>{let f=h.handlers.findIndex(o=>o.unwatch===a);f!==-1&&h.handlers.splice(f,1),h.handlers.length===0&&(this[s]=h.original,this.#n.delete(s))};return h.handlers.push({callback:t,unwatch:a}),a}if(typeof e=="string"){let s=e,n=()=>{let a=this.#t.findIndex(f=>f.unwatch===n);a!==-1&&this.#t.splice(a,1)},h={type:"key",key:s,callback:t,deep:r,immediate:l,lastValue:void 0,unwatch:n};if(this.#t.push(h),l){let a=this.#T(s);h.lastValue=r&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,t(a,void 0,n)}return n}if(typeof e=="function"){let s=e,n,h={type:"getter",getter:s,callback:t,deep:r,lastValue:n,effect:null,unwatch:null};this.#t.push(h);let a=()=>{let u=this.#t.indexOf(h);u!==-1&&this.#t.splice(u,1),h.effect&&(this.#s.forEach((d,p)=>{d.delete(h.effect),d.size===0&&this.#s.delete(p)}),this.#h.delete(h.effect))};h.unwatch=a;let f=()=>{let u=s.call(this);if(r?!this.#N(u,n):u!==n){let p=n;n=r&&u!==null&&typeof u=="object"?JSON.parse(JSON.stringify(u)):u,t(u,p,h.unwatch)}},o=this.#f(f);return h.effect=o,a}return()=>{}}unwatch(){[...this.#t].forEach(e=>e.unwatch()),this.#n.forEach(e=>{[...e.handlers].forEach(t=>t.unwatch())})}hasWatchers(){let e=0;return this.#n.forEach(t=>{e+=t.handlers.length}),this.#t.length+e}watched(e,t,i={}){if(typeof e=="string"&&e.endsWith("()")){let r=e.slice(0,-2),l=this.#n.get(r);l&&[...l.handlers].forEach(s=>s.unwatch())}else typeof e=="string"?this.#t.filter(r=>r.type==="key"&&r.key===e).forEach(r=>r.unwatch()):typeof e=="function"&&this.#t.filter(r=>r.type==="getter"&&r.getter===e).forEach(r=>r.unwatch());return this.watch(e,t,i)}#v(e){this.#y&&(this.#s.has(e)||this.#s.set(e,new Set),this.#s.get(e).add(this.#y))}#a(e){this.#b.add(e);let t=this.#s.get(e);if(t&&t.forEach(r=>this.#h.add(r)),this.#m){this.#x=!0;return}this.#m=!0;let i=()=>{this.#h.forEach(s=>{try{s()}catch(n){console.error("Effect execution error:",n)}}),this.#h.clear();let r=Array.from(this.#b),l=new Set;for(let s of r)for(let n of this.#t){if(n.type!=="key")continue;(n.key===s||n.deep&&(s===n.key||s.startsWith(n.key+".")))&&l.add(n)}for(let s of l){if(s.type!=="key")continue;let n=this.#T(s.key);if(!(s.deep?!this.#N(n,s.lastValue):n!==s.lastValue))continue;let a=s.lastValue;s.lastValue=s.deep&&n!==null&&typeof n=="object"?JSON.parse(JSON.stringify(n)):n,s.callback(n,a,s.unwatch)}this.#b.clear(),this.#m=!1,this.#x&&(this.#x=!1,this.#m=!0,Promise.resolve().then(i))};Promise.resolve().then(i)}#T(e){return e.split(".").reduce((t,i)=>t?.[i],this)}#N(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),r=Object.keys(t);if(i.length!==r.length)return!1;for(let l of i)if(!r.includes(l)||!this.#N(e[l],t[l]))return!1;return!0}#c(e,t=[]){if(e===null||typeof e!="object"||e.__isReactive)return e;let i=this;return new Proxy(e,{get(l,s,n){if(s==="__isReactive")return!0;let h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");i.#v(a);let f=Reflect.get(l,s,n);return f!==null&&typeof f=="object"&&!f.__isReactive?i.#c(f,[...t,h]):f},set(l,s,n,h){if(l[s]===n)return!0;let f=Reflect.set(l,s,n,h),o=typeof s=="symbol"?"<symbol>":s,u=[...t,o].join(".");if(i.#a(u),Array.isArray(l)&&(s==="length"||!isNaN(s))){let d=t.join(".");d&&i.#a(d)}return f},deleteProperty(l,s){let n=Reflect.deleteProperty(l,s),h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");return i.#a(a),n}})}#j(e,t){let i=this;return new Proxy(e,{apply(r,l,s){let n=Reflect.apply(r,i,s);return n instanceof Promise?n.then(h=>(i.#a(t),h)):(i.#a(t),n)}})}#f(e){let t=this.#r?{...this.#r}:null,i=()=>{let r=null;if(t){r={};for(let l of Object.keys(t))r[l]=this[l],this[l]=t[l]}this.#y=i;try{e()}finally{if(this.#y=null,r)for(let l of Object.keys(r))r[l]!==void 0?this[l]=r[l]:delete this[l]}};return i(),i}#o(e){try{return new Function("$event",`with(this) { return (${e}); }`).call(this)}catch(t){console.warn("Expression evaluation error:",e,t);return}}#L(e,t=null){try{return new Function("$event",`with(this) { ${e} }`).call(this,t)}catch(i){console.error("Statement execution error:",e,i)}}#V(e){let t=e.nodeValue,i=[],r=[],l=0,s=/\{\{(.+?)\}\}/g,n;for(;(n=s.exec(t))!==null;){n.index>l&&i.push(t.substring(l,n.index));let a=n[1].trim();i.push(null),r.push({index:i.length-1,expr:a}),l=s.lastIndex}l<t.length&&i.push(t.substring(l));let h=this.#f(()=>{r.forEach(({index:a,expr:f})=>{let o=this.#o(f);i[a]=o==null?"":String(o)}),e.nodeValue=i.join("")});this.#e.push({type:"text",node:e,effect:h})}#I(e,t){let i=t.name.slice(1),r=t.value,l=this.#r?{...this.#r}:null,s=n=>{if(l){let h={};for(let a of Object.keys(l))h[a]=this[a],this[a]=l[a];this.#L(r,n);for(let a of Object.keys(h))h[a]!==void 0?this[a]=h[a]:delete this[a]}else this.#L(r,n)};e.addEventListener(i,s),this.#e.push({type:"event",element:e,eventName:i,handler:s})}#B(e,t){let i=t.value,r=this.#f(()=>{this.#o(i)?e.style.display="":e.style.display="none"});this.#e.push({type:"show",element:e,effect:r})}#R(e,t){let i=t.value,r=this.#f(()=>{let h=this.#o(i);e.tagName==="INPUT"&&e.type==="checkbox"?e.checked=!!h:e.tagName==="INPUT"&&e.type==="radio"?e.checked=e.value===h:e.tagName==="SELECT"?e.value=h:e.value=h??""}),l=this.#r?{...this.#r}:null,s=e.tagName==="SELECT"?"change":"input",n=h=>{let a;if(e.type==="checkbox"?a=e.checked:e.type==="number"||e.type==="range"?a=e.valueAsNumber:a=e.value,l){let f={};for(let o of Object.keys(l))f[o]=this[o],this[o]=l[o];try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(o){console.error("Model binding error:",i,o)}for(let o of Object.keys(f))f[o]!==void 0?this[o]=f[o]:delete this[o]}else try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(f){console.error("Model binding error:",i,f)}};e.addEventListener(s,n),this.#e.push({type:"model",element:e,effect:r,handler:n})}#W(e,t){let i=t.value,r=document.createComment(`if: ${i}`);e.parentNode.insertBefore(r,e);let l=[{expr:i,element:e,bindings:[],processed:!1}],s=e.nextElementSibling;for(;s;)if(s.hasAttribute("#else-if")){let a=s.getAttribute("#else-if");l.push({expr:a,element:s,bindings:[],processed:!1}),s.removeAttribute("#else-if");let f=s.nextElementSibling;s.remove(),s=f}else if(s.hasAttribute("#else")){l.push({expr:"true",element:s,bindings:[],processed:!1}),s.removeAttribute("#else"),s.remove();break}else break;e.removeAttribute(t.name),e.remove();let n=null,h=this.#f(()=>{let a=null;for(let f of l)if(this.#o(f.expr)){a=f;break}if(n!==a){if(n&&(n.element&&n.element.parentNode&&n.element.remove(),this.#g(n.bindings),n.bindings=[]),a&&(r.parentNode.insertBefore(a.element,r.nextSibling),!a.processed)){let f=this.#e.length;this.#E(a.element),a.bindings=this.#e.slice(f),a.processed=!0}n=a}});this.#e.push({type:"conditional",placeholder:r,chain:l,effect:h})}#F(e,t){let i=t.value,r=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!r){console.error("Invalid for syntax:",i);return}let l=r[1],s=r[2],n=e.parentNode,h=e.nextSibling;e.removeAttribute(t.name);let a=e.cloneNode(!0);e.remove();let f=[],o=this.#f(()=>{let u=this.#o(s);f.forEach(y=>{y.node&&y.node.parentNode&&y.node.remove(),this.#g(y.bindings)}),f=[];let d;if(Array.isArray(u))d=u.map((y,m)=>({value:y,key:void 0,index:m}));else if(u!==null&&typeof u=="object")d=Object.entries(u).map(([y,m],b)=>({value:m,key:y,index:b}));else return;if(d.length===0)return;let p=document.createDocumentFragment();d.forEach(({value:y,key:m,index:b})=>{let v=a.cloneNode(!0),w=this[l],x=this.$index,N=this.$key;this[l]=y,this.$index=b,m!==void 0&&(this.$key=m);let A=this.#r,O={...A,[l]:y,$index:b};m!==void 0&&(O.$key=m),this.#r=O;let S=this.#e.length;this.#E(v);let k=this.#e.slice(S);this.#r=A,w!==void 0?this[l]=w:delete this[l],x!==void 0?this.$index=x:delete this.$index,N!==void 0?this.$key=N:delete this.$key,p.appendChild(v),f.push({node:v,bindings:k})}),n.insertBefore(p,h)});this.#e.push({type:"loop",parent:n,nextSibling:h,template:a,effect:o})}#D(e,t){let i=t.name,r=t.value,l=[],s=[],n=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(r))!==null;){a.index>n&&l.push(r.substring(n,a.index));let o=a[1].trim();l.push(null),s.push({index:l.length-1,expr:o}),n=h.lastIndex}n<r.length&&l.push(r.substring(n));let f=this.#f(()=>{s.forEach(({index:u,expr:d})=>{let p=this.#o(d);l[u]=p==null?"":String(p)});let o=l.join("");c.#C.has(i)?o===""||o==="false"||o==="0"||o==="null"||o==="undefined"||!o?e.removeAttribute(i):e.setAttribute(i,""):e.setAttribute(i,o)});this.#e.push({type:"attribute",element:e,attrName:i,effect:f})}#J(e){let t=Array.from(e.attributes);for(let i of t){if(i.name==="#if")return this.#W(e,i),e.removeAttribute(i.name),!0;if(i.name==="#for")return this.#F(e,i),e.removeAttribute(i.name),!0;if(i.name==="#show")this.#B(e,i),e.removeAttribute(i.name);else if(i.name==="#model")this.#R(e,i),e.removeAttribute(i.name);else if(i.name==="#once")e.removeAttribute(i.name);else{if(i.name==="#pre")return e.removeAttribute(i.name),!0;i.name.startsWith("@")?(this.#I(e,i),e.removeAttribute(i.name)):/\{\{.+?\}\}/.test(i.value)&&this.#D(e,i)}}return!1}#E(e){if(e.nodeType===Node.ELEMENT_NODE){let t=this.#J(e);if(e.localName==="st-app")return;!t&&(e.parentNode||e.childNodes.length>0)&&Array.from(e.childNodes).forEach(i=>this.#E(i))}else e.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(e.nodeValue)&&this.#V(e)}#P(){let e=this.attrs.get("app"),t=c.#d.get(e);if(t){this.addEventListener("setup",t.setup),Object.entries(t.events).forEach(([s,n])=>this.addEventListener(s,n)),this.#u=t.template;let i=t.config,r=Object.getOwnPropertyDescriptors(i),l=new Set(["app","setup","template","events"]);Object.entries(r).forEach(([s,n])=>{if(!l.has(s)){if(n.get){let h=n.get;this.#M.set(s,h),Object.defineProperty(this,s,{get(){return this.#v(s),h.call(this)},enumerable:n.enumerable,configurable:!0})}else if(n.value!==void 0){let h=n.value,a=h;typeof h=="object"&&h!==null?a=this.#c(h,[s]):typeof h=="function"&&(a=this.#j(h,s)),Object.defineProperty(this,s,{get(){return this.#v(s),a},set(f){a!==f&&(typeof f=="object"&&f!==null?a=this.#c(f,[s]):a=f,this.#a(s))},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#A(e){await Promise.all(e.map(t=>new Promise(i=>{let r=null,l=()=>{clearTimeout(r),r=setTimeout(()=>{s.disconnect(),this.#A(Array.from(t.children)).then(i)},0)},s=new MutationObserver(n=>{n.some(h=>h.type==="childList")&&l()});s.observe(t,{childList:!0}),l()})))}#O(e){return e==null?"":e===!0?"true":e===!1?"false":typeof e=="number"?String(e):typeof e=="object"?JSON.stringify(e):String(e)}#w(e){if(!e.startsWith(":")||e==="app")return;let t=e.replace(/^:+/,""),i=this.getAttribute(e),r=Object.getOwnPropertyDescriptor(this,t),l=i;if(!i&&r&&(r.get||r.value!==void 0)){let s=this[t],n=this.#O(s);this.getAttribute(e)!==n&&this.setAttribute(e,n),l=s,r=null}if(!(r&&r.set===void 0&&r.writable===!1)&&!(r&&r.get!==void 0&&r.set===void 0)){if(i)if(i==="true")l=!0;else if(i==="false")l=!1;else if(/^-?\d+(\.\d+)?$/.test(i))l=Number(i);else try{l=JSON.parse(i)}catch{l=i}if(!r||!r.set){let s=l;typeof l=="object"&&l!==null?s=this.#c(l,[t]):typeof l=="function"&&(s=this.#j(l,t));let n=e;if(Object.defineProperty(this,t,{get(){return this.#v(t),s},set(h){if(s!==h){typeof h=="object"&&h!==null?s=this.#c(h,[t]):s=h,this.#a(t);let a=this.#O(h);this.getAttribute(n)!==a&&this.setAttribute(n,a)}},enumerable:!0,configurable:!0}),typeof l=="object"&&l!==null){let h=this.watch(t,()=>{let a=this[t],f=this.#O(a);this.getAttribute(e)!==f&&this.setAttribute(e,f)},{deep:!0});this.#e.push({type:"attrSync",unwatch:h})}}else this[t]=l}}attributeChangedCallback(e,t,i){e.startsWith(":")&&e!=="app"&&t!==i&&this.#i===!0&&this.#w(e)}connectedCallback(){if(c.#p.add(this),this.#i===!0){this.#l||(this.#l=new MutationObserver(e=>{for(let t of e)t.type==="attributes"&&t.attributeName&&t.attributeName.startsWith(":")&&t.attributeName!=="app"&&this.#w(t.attributeName)}),this.#l.observe(this,{attributes:!0}));return}this.#P(),Promise.all([new Promise(e=>{if(this.#i===!0)return e();this.#i=e}),new Promise(e=>{let t=null,i=()=>{clearTimeout(t),t=setTimeout(()=>{r.disconnect(),this.#A(Array.from(this.children)).then(e)},0)},r=new MutationObserver(l=>{l.some(s=>s.type==="childList")&&i()});r.observe(this,{childList:!0}),i()})]).then(()=>{this.dispatchEvent("setup");for(let t of this.attrs.keys())!t.startsWith(":")||t==="app"||this.#w(t);let e=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(i=>i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE&&i.textContent.trim()!=="")&&(this.#u?(this.applyTemplate(this.innerHTML),e=!0):this.#u=this.innerHTML),e||this.applyTemplate(),this.#i===!0&&!this.#l&&(this.#l=new MutationObserver(t=>{for(let i of t)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#w(i.attributeName)}),this.#l.observe(this,{attributes:!0}))})}disconnectedCallback(){this.#l&&(this.#l.disconnect(),this.#l=null),this.#g(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.#h.delete(e.effect));this.#t=[],this.#n.forEach((e,t)=>{this[t]=e.original}),this.#n.clear(),this.#b.clear(),this.#s.clear(),this.#h.clear(),c.#p.delete(this)}toggleAttribute(e,t="",i=""){let r=this.getAttribute(e);this[t==""&&i==""&&(r||this.hasAttribute(e))?"removeAttribute":"setAttribute"](e,r!=t?t:i)}static{customElements.define("st-app",this)}};return M($);})();
2
- if(typeof app!=="undefined"&&app&&app.default)globalThis.app=app.default;
1
+ var App=(()=>{var E=Object.defineProperty;var T=Object.getOwnPropertyDescriptor;var j=Object.getOwnPropertyNames;var L=Object.prototype.hasOwnProperty;var P=(c,e)=>{for(var t in e)E(c,t,{get:e[t],enumerable:!0})},C=(c,e,t,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of j(e))!L.call(c,r)&&r!==t&&E(c,r,{get:()=>e[r],enumerable:!(i=T(e,r))||i.enumerable});return c};var M=c=>C(E({},"__esModule",{value:!0}),c);var $={};P($,{default:()=>g});var g=class c extends HTMLElement{static#C=new Set(["disabled","checked","readonly","required","selected","hidden","open","autofocus"]);static#d=new Map;static#p=new Set;static create(e){let{app:t,setup:i=()=>{},template:r="",events:l={}}=e;if(c.#d.has(t))throw new Error(`Application "${t}" already exists!`);c.#d.set(t,{setup:i,template:r,events:l,config:e}),c.#p.forEach(s=>{s.#i!==!0&&s.#P()})}static extend(e,t={}){let i=c.#d.get(e);if(!i)throw new Error(`Application "${e}" not found!`);let r=i.config,l={...r,...t};return(r.events||t.events)&&(l.events={...r.events,...t.events}),c.create(l)}#i=!1;#u="";#S=!1;#s=new Map;#y=null;#h=new Set;#m=!1;#e=[];#r=null;#M=new Map;#l=null;#t=[];#b=new Set;#x=!1;#n=new Map;#k=0;constructor(){super(),c.#p.add(this)}#g(e){!e||!e.length||e.forEach(t=>{if(t.type==="event"&&t.element&&t.handler)t.element.removeEventListener(t.eventName,t.handler);else if(t.type==="model"&&t.element&&t.handler){let i=t.element.tagName==="SELECT"?"change":"input";t.element.removeEventListener(i,t.handler)}else t.type==="attrSync"&&t.unwatch&&t.unwatch();t.effect&&(this.#s.forEach((i,r)=>{i.delete(t.effect),i.size===0&&this.#s.delete(r)}),this.#h.delete(t.effect))})}get template(){return this.#u}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.#S){queueMicrotask(()=>t(new CustomEvent(e)));return}super.addEventListener(e,t,i)}dispatchEvent(e,t=null,i={}){if(typeof e=="string"){let r=new CustomEvent(e,{cancelable:!0,...i,detail:t});return super.dispatchEvent(r)}return super.dispatchEvent(e)}applyTemplate(e=""){let t=e||this.#u;if(this.#g(this.#e),this.#e=[],this.innerHTML="",t){let r=document.createElement("template");r.innerHTML=t.trim();let l=r.content.cloneNode(!0);Array.from(l.childNodes).forEach(s=>this.#E(s)),this.#$(l)}let i=++this.#k;new Promise(r=>{let l=null,s,n=()=>{clearTimeout(l),l=setTimeout(()=>{s.disconnect(),this.#A(Array.from(this.children)).then(r)},0)};s=new MutationObserver(h=>{h.some(a=>a.type==="childList")&&n()}),s.observe(this,{childList:!0}),n()}).then(()=>{i===this.#k&&(this.#S=!0,this.dispatchEvent("rendered"))})}#$(e){HTMLElement.prototype.appendChild.call(this,e)}clone(e={}){let t=this.attrs.get("app");return c.extend(t,e)}watch(e,t,i={}){if(typeof t!="function")return()=>{};let{deep:r=!1,immediate:l=!1}=i;if(typeof e=="string"&&e.endsWith("()")){let s=e.slice(0,-2),n=this[s];if(typeof n!="function")return()=>{};let h=this.#n.get(s);if(!h){h={original:n,handlers:[]},this.#n.set(s,h);let f=(...o)=>{let u=n.apply(this,o),d=p=>{for(let y of[...h.handlers])y.callback(o,p,y.unwatch)};return u instanceof Promise?u.then(p=>(d(p),p)):(d(u),u)};this[s]=f}let a=()=>{let f=h.handlers.findIndex(o=>o.unwatch===a);f!==-1&&h.handlers.splice(f,1),h.handlers.length===0&&(this[s]=h.original,this.#n.delete(s))};return h.handlers.push({callback:t,unwatch:a}),a}if(typeof e=="string"){let s=e,n=()=>{let a=this.#t.findIndex(f=>f.unwatch===n);a!==-1&&this.#t.splice(a,1)},h={type:"key",key:s,callback:t,deep:r,immediate:l,lastValue:void 0,unwatch:n};if(this.#t.push(h),l){let a=this.#T(s);h.lastValue=r&&a!==null&&typeof a=="object"?JSON.parse(JSON.stringify(a)):a,t(a,void 0,n)}return n}if(typeof e=="function"){let s=e,n,h={type:"getter",getter:s,callback:t,deep:r,lastValue:n,effect:null,unwatch:null};this.#t.push(h);let a=()=>{let u=this.#t.indexOf(h);u!==-1&&this.#t.splice(u,1),h.effect&&(this.#s.forEach((d,p)=>{d.delete(h.effect),d.size===0&&this.#s.delete(p)}),this.#h.delete(h.effect))};h.unwatch=a;let f=()=>{let u=s.call(this);if(r?!this.#N(u,n):u!==n){let p=n;n=r&&u!==null&&typeof u=="object"?JSON.parse(JSON.stringify(u)):u,t(u,p,h.unwatch)}},o=this.#f(f);return h.effect=o,a}return()=>{}}unwatch(){[...this.#t].forEach(e=>e.unwatch()),this.#n.forEach(e=>{[...e.handlers].forEach(t=>t.unwatch())})}hasWatchers(){let e=0;return this.#n.forEach(t=>{e+=t.handlers.length}),this.#t.length+e}watched(e,t,i={}){if(typeof e=="string"&&e.endsWith("()")){let r=e.slice(0,-2),l=this.#n.get(r);l&&[...l.handlers].forEach(s=>s.unwatch())}else typeof e=="string"?this.#t.filter(r=>r.type==="key"&&r.key===e).forEach(r=>r.unwatch()):typeof e=="function"&&this.#t.filter(r=>r.type==="getter"&&r.getter===e).forEach(r=>r.unwatch());return this.watch(e,t,i)}#v(e){this.#y&&(this.#s.has(e)||this.#s.set(e,new Set),this.#s.get(e).add(this.#y))}#a(e){this.#b.add(e);let t=this.#s.get(e);if(t&&t.forEach(r=>this.#h.add(r)),this.#m){this.#x=!0;return}this.#m=!0;let i=()=>{this.#h.forEach(s=>{try{s()}catch(n){console.error("Effect execution error:",n)}}),this.#h.clear();let r=Array.from(this.#b),l=new Set;for(let s of r)for(let n of this.#t){if(n.type!=="key")continue;(n.key===s||n.deep&&(s===n.key||s.startsWith(n.key+".")))&&l.add(n)}for(let s of l){if(s.type!=="key")continue;let n=this.#T(s.key);if(!(s.deep?!this.#N(n,s.lastValue):n!==s.lastValue))continue;let a=s.lastValue;s.lastValue=s.deep&&n!==null&&typeof n=="object"?JSON.parse(JSON.stringify(n)):n,s.callback(n,a,s.unwatch)}this.#b.clear(),this.#m=!1,this.#x&&(this.#x=!1,this.#m=!0,Promise.resolve().then(i))};Promise.resolve().then(i)}#T(e){return e.split(".").reduce((t,i)=>t?.[i],this)}#N(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),r=Object.keys(t);if(i.length!==r.length)return!1;for(let l of i)if(!r.includes(l)||!this.#N(e[l],t[l]))return!1;return!0}#c(e,t=[]){if(e===null||typeof e!="object"||e.__isReactive)return e;let i=this;return new Proxy(e,{get(l,s,n){if(s==="__isReactive")return!0;let h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");i.#v(a);let f=Reflect.get(l,s,n);return f!==null&&typeof f=="object"&&!f.__isReactive?i.#c(f,[...t,h]):f},set(l,s,n,h){if(l[s]===n)return!0;let f=Reflect.set(l,s,n,h),o=typeof s=="symbol"?"<symbol>":s,u=[...t,o].join(".");if(i.#a(u),Array.isArray(l)&&(s==="length"||!isNaN(s))){let d=t.join(".");d&&i.#a(d)}return f},deleteProperty(l,s){let n=Reflect.deleteProperty(l,s),h=typeof s=="symbol"?"<symbol>":s,a=[...t,h].join(".");return i.#a(a),n}})}#j(e,t){let i=this;return new Proxy(e,{apply(r,l,s){let n=Reflect.apply(r,i,s);return n instanceof Promise?n.then(h=>(i.#a(t),h)):(i.#a(t),n)}})}#f(e){let t=this.#r?{...this.#r}:null,i=()=>{let r=null;if(t){r={};for(let l of Object.keys(t))r[l]=this[l],this[l]=t[l]}this.#y=i;try{e()}finally{if(this.#y=null,r)for(let l of Object.keys(r))r[l]!==void 0?this[l]=r[l]:delete this[l]}};return i(),i}#o(e){try{return new Function("$event",`with(this) { return (${e}); }`).call(this)}catch(t){console.warn("Expression evaluation error:",e,t);return}}#L(e,t=null){try{return new Function("$event",`with(this) { ${e} }`).call(this,t)}catch(i){console.error("Statement execution error:",e,i)}}#V(e){let t=e.nodeValue,i=[],r=[],l=0,s=/\{\{(.+?)\}\}/g,n;for(;(n=s.exec(t))!==null;){n.index>l&&i.push(t.substring(l,n.index));let a=n[1].trim();i.push(null),r.push({index:i.length-1,expr:a}),l=s.lastIndex}l<t.length&&i.push(t.substring(l));let h=this.#f(()=>{r.forEach(({index:a,expr:f})=>{let o=this.#o(f);i[a]=o==null?"":String(o)}),e.nodeValue=i.join("")});this.#e.push({type:"text",node:e,effect:h})}#I(e,t){let i=t.name.slice(1),r=t.value,l=this.#r?{...this.#r}:null,s=n=>{if(l){let h={};for(let a of Object.keys(l))h[a]=this[a],this[a]=l[a];this.#L(r,n);for(let a of Object.keys(h))h[a]!==void 0?this[a]=h[a]:delete this[a]}else this.#L(r,n)};e.addEventListener(i,s),this.#e.push({type:"event",element:e,eventName:i,handler:s})}#B(e,t){let i=t.value,r=this.#f(()=>{this.#o(i)?e.style.display="":e.style.display="none"});this.#e.push({type:"show",element:e,effect:r})}#R(e,t){let i=t.value,r=this.#f(()=>{let h=this.#o(i);e.tagName==="INPUT"&&e.type==="checkbox"?e.checked=!!h:e.tagName==="INPUT"&&e.type==="radio"?e.checked=e.value===h:e.tagName==="SELECT"?e.value=h:e.value=h??""}),l=this.#r?{...this.#r}:null,s=e.tagName==="SELECT"?"change":"input",n=h=>{let a;if(e.type==="checkbox"?a=e.checked:e.type==="number"||e.type==="range"?a=e.valueAsNumber:a=e.value,l){let f={};for(let o of Object.keys(l))f[o]=this[o],this[o]=l[o];try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(o){console.error("Model binding error:",i,o)}for(let o of Object.keys(f))f[o]!==void 0?this[o]=f[o]:delete this[o]}else try{new Function("value",`with(this) { ${i} = value; }`).call(this,a)}catch(f){console.error("Model binding error:",i,f)}};e.addEventListener(s,n),this.#e.push({type:"model",element:e,effect:r,handler:n})}#W(e,t){let i=t.value,r=document.createComment(`if: ${i}`);e.parentNode.insertBefore(r,e);let l=[{expr:i,element:e,bindings:[],processed:!1}],s=e.nextElementSibling;for(;s;)if(s.hasAttribute("#else-if")){let a=s.getAttribute("#else-if");l.push({expr:a,element:s,bindings:[],processed:!1}),s.removeAttribute("#else-if");let f=s.nextElementSibling;s.remove(),s=f}else if(s.hasAttribute("#else")){l.push({expr:"true",element:s,bindings:[],processed:!1}),s.removeAttribute("#else"),s.remove();break}else break;e.removeAttribute(t.name),e.remove();let n=null,h=this.#f(()=>{let a=null;for(let f of l)if(this.#o(f.expr)){a=f;break}if(n!==a){if(n&&(n.element&&n.element.parentNode&&n.element.remove(),this.#g(n.bindings),n.bindings=[]),a&&(r.parentNode.insertBefore(a.element,r.nextSibling),!a.processed)){let f=this.#e.length;this.#E(a.element),a.bindings=this.#e.slice(f),a.processed=!0}n=a}});this.#e.push({type:"conditional",placeholder:r,chain:l,effect:h})}#F(e,t){let i=t.value,r=i.match(/^\s*(\w+)\s+in\s+(.+)$/);if(!r){console.error("Invalid for syntax:",i);return}let l=r[1],s=r[2],n=e.parentNode,h=e.nextSibling;e.removeAttribute(t.name);let a=e.cloneNode(!0);e.remove();let f=[],o=this.#f(()=>{let u=this.#o(s);f.forEach(y=>{y.node&&y.node.parentNode&&y.node.remove(),this.#g(y.bindings)}),f=[];let d;if(Array.isArray(u))d=u.map((y,m)=>({value:y,key:void 0,index:m}));else if(u!==null&&typeof u=="object")d=Object.entries(u).map(([y,m],b)=>({value:m,key:y,index:b}));else return;if(d.length===0)return;let p=document.createDocumentFragment();d.forEach(({value:y,key:m,index:b})=>{let v=a.cloneNode(!0),w=this[l],x=this.$index,N=this.$key;this[l]=y,this.$index=b,m!==void 0&&(this.$key=m);let A=this.#r,O={...A,[l]:y,$index:b};m!==void 0&&(O.$key=m),this.#r=O;let S=this.#e.length;this.#E(v);let k=this.#e.slice(S);this.#r=A,w!==void 0?this[l]=w:delete this[l],x!==void 0?this.$index=x:delete this.$index,N!==void 0?this.$key=N:delete this.$key,p.appendChild(v),f.push({node:v,bindings:k})}),n.insertBefore(p,h)});this.#e.push({type:"loop",parent:n,nextSibling:h,template:a,effect:o})}#D(e,t){let i=t.name,r=t.value,l=[],s=[],n=0,h=/\{\{(.+?)\}\}/g,a;for(;(a=h.exec(r))!==null;){a.index>n&&l.push(r.substring(n,a.index));let o=a[1].trim();l.push(null),s.push({index:l.length-1,expr:o}),n=h.lastIndex}n<r.length&&l.push(r.substring(n));let f=this.#f(()=>{s.forEach(({index:u,expr:d})=>{let p=this.#o(d);l[u]=p==null?"":String(p)});let o=l.join("");c.#C.has(i)?o===""||o==="false"||o==="0"||o==="null"||o==="undefined"||!o?e.removeAttribute(i):e.setAttribute(i,""):e.setAttribute(i,o)});this.#e.push({type:"attribute",element:e,attrName:i,effect:f})}#J(e){let t=Array.from(e.attributes);for(let i of t){if(i.name==="#if")return this.#W(e,i),e.removeAttribute(i.name),!0;if(i.name==="#for")return this.#F(e,i),e.removeAttribute(i.name),!0;if(i.name==="#show")this.#B(e,i),e.removeAttribute(i.name);else if(i.name==="#model")this.#R(e,i),e.removeAttribute(i.name);else if(i.name==="#once")e.removeAttribute(i.name);else{if(i.name==="#pre")return e.removeAttribute(i.name),!0;i.name.startsWith("@")?(this.#I(e,i),e.removeAttribute(i.name)):/\{\{.+?\}\}/.test(i.value)&&this.#D(e,i)}}return!1}#E(e){if(e.nodeType===Node.ELEMENT_NODE){let t=this.#J(e);if(e.localName==="st-app")return;!t&&(e.parentNode||e.childNodes.length>0)&&Array.from(e.childNodes).forEach(i=>this.#E(i))}else e.nodeType===Node.TEXT_NODE&&/\{\{.+?\}\}/.test(e.nodeValue)&&this.#V(e)}#P(){let e=this.attrs.get("app"),t=c.#d.get(e);if(t){this.addEventListener("setup",t.setup),Object.entries(t.events).forEach(([s,n])=>this.addEventListener(s,n)),this.#u=t.template;let i=t.config,r=Object.getOwnPropertyDescriptors(i),l=new Set(["app","setup","template","events"]);Object.entries(r).forEach(([s,n])=>{if(!l.has(s)){if(n.get){let h=n.get;this.#M.set(s,h),Object.defineProperty(this,s,{get(){return this.#v(s),h.call(this)},enumerable:n.enumerable,configurable:!0})}else if(n.value!==void 0){let h=n.value,a=h;typeof h=="object"&&h!==null?a=this.#c(h,[s]):typeof h=="function"&&(a=this.#j(h,s)),Object.defineProperty(this,s,{get(){return this.#v(s),a},set(f){a!==f&&(typeof f=="object"&&f!==null?a=this.#c(f,[s]):a=f,this.#a(s))},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#A(e){await Promise.all(e.map(t=>new Promise(i=>{let r=null,l=()=>{clearTimeout(r),r=setTimeout(()=>{s.disconnect(),this.#A(Array.from(t.children)).then(i)},0)},s=new MutationObserver(n=>{n.some(h=>h.type==="childList")&&l()});s.observe(t,{childList:!0}),l()})))}#O(e){return e==null?"":e===!0?"true":e===!1?"false":typeof e=="number"?String(e):typeof e=="object"?JSON.stringify(e):String(e)}#w(e){if(!e.startsWith(":")||e==="app")return;let t=e.replace(/^:+/,""),i=this.getAttribute(e),r=Object.getOwnPropertyDescriptor(this,t),l=i;if(!i&&r&&(r.get||r.value!==void 0)){let s=this[t],n=this.#O(s);this.getAttribute(e)!==n&&this.setAttribute(e,n),l=s,r=null}if(!(r&&r.set===void 0&&r.writable===!1)&&!(r&&r.get!==void 0&&r.set===void 0)){if(i)if(i==="true")l=!0;else if(i==="false")l=!1;else if(/^-?\d+(\.\d+)?$/.test(i))l=Number(i);else try{l=JSON.parse(i)}catch{l=i}if(!r||!r.set){let s=l;typeof l=="object"&&l!==null?s=this.#c(l,[t]):typeof l=="function"&&(s=this.#j(l,t));let n=e;if(Object.defineProperty(this,t,{get(){return this.#v(t),s},set(h){if(s!==h){typeof h=="object"&&h!==null?s=this.#c(h,[t]):s=h,this.#a(t);let a=this.#O(h);this.getAttribute(n)!==a&&this.setAttribute(n,a)}},enumerable:!0,configurable:!0}),typeof l=="object"&&l!==null){let h=this.watch(t,()=>{let a=this[t],f=this.#O(a);this.getAttribute(e)!==f&&this.setAttribute(e,f)},{deep:!0});this.#e.push({type:"attrSync",unwatch:h})}}else this[t]=l}}attributeChangedCallback(e,t,i){e.startsWith(":")&&e!=="app"&&t!==i&&this.#i===!0&&this.#w(e)}connectedCallback(){if(c.#p.add(this),this.#i===!0){this.#l||(this.#l=new MutationObserver(e=>{for(let t of e)t.type==="attributes"&&t.attributeName&&t.attributeName.startsWith(":")&&t.attributeName!=="app"&&this.#w(t.attributeName)}),this.#l.observe(this,{attributes:!0}));return}this.#P(),Promise.all([new Promise(e=>{if(this.#i===!0)return e();this.#i=e}),new Promise(e=>{let t=null,i=()=>{clearTimeout(t),t=setTimeout(()=>{r.disconnect(),this.#A(Array.from(this.children)).then(e)},0)},r=new MutationObserver(l=>{l.some(s=>s.type==="childList")&&i()});r.observe(this,{childList:!0}),i()})]).then(()=>{this.dispatchEvent("setup");for(let t of this.attrs.keys())!t.startsWith(":")||t==="app"||this.#w(t);let e=!1;this.childNodes.length>0&&Array.from(this.childNodes).some(i=>i.nodeType===Node.ELEMENT_NODE||i.nodeType===Node.TEXT_NODE&&i.textContent.trim()!=="")&&(this.#u?(this.applyTemplate(this.innerHTML),e=!0):this.#u=this.innerHTML),e||this.applyTemplate(),this.#i===!0&&!this.#l&&(this.#l=new MutationObserver(t=>{for(let i of t)i.type==="attributes"&&i.attributeName&&i.attributeName.startsWith(":")&&i.attributeName!=="app"&&this.#w(i.attributeName)}),this.#l.observe(this,{attributes:!0}))})}disconnectedCallback(){this.#l&&(this.#l.disconnect(),this.#l=null),this.#g(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.#h.delete(e.effect));this.#t=[],this.#n.forEach((e,t)=>{this[t]=e.original}),this.#n.clear(),this.#b.clear(),this.#s.clear(),this.#h.clear(),c.#p.delete(this)}toggleAttribute(e,t="",i=""){let r=this.getAttribute(e);this[t==""&&i==""&&(r||this.hasAttribute(e))?"removeAttribute":"setAttribute"](e,r!=t?t:i)}static{customElements.define("st-app",this)}};return M($);})();
2
+ if(typeof App!=="undefined"&&App&&App.default)globalThis.App=App.default;
@@ -1,2 +1,2 @@
1
- var cookie=(()=>{var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var f=(o,t)=>{for(var i in t)r(o,i,{get:t[i],enumerable:!0})},h=(o,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!a.call(o,n)&&n!==i&&r(o,n,{get:()=>t[n],enumerable:!(e=s(t,n))||e.enumerable});return o};var v=o=>h(r({},"__esModule",{value:!0}),o);var y={};f(y,{default:()=>c});var c=class o{static set(t,i,e={}){if(e={path:"/",expires:3600,...e},!(e.expires instanceof Date)){let n=e.expires;e.expires=new Date(typeof n=="number"?Date.now()+n*1e3:Date.parse(n)||Date.parse(n.replace(/-/g,"/")))}document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(i)+"; expires="+e.expires.toUTCString()+"; path="+e.path+(e.domain?"; domain="+e.domain:"")+(e.secure?"; secure":"")+(e.sameSite?"; samesite="+e.sameSite:"")}static get(t){t=encodeURIComponent(t);let i=document.cookie.split(";");for(let e=0;e<i.length;e++){let n=i[e].trim();if(n.startsWith(t+"=")){let l=decodeURIComponent(n.substring(t.length+1));try{return JSON.parse(l)}catch{return l}}}return null}static delete(t,i={}){o.set(t,"",{expires:0,...i})}static callback(t,i,e={}){e={interval:0,delay:0,value:!0,...e};let n=setInterval(()=>{o.get(t)===null&&(o.set(t,e.value,e),setTimeout(()=>{i(t)},e.delay*1e3)),e.interval||clearInterval(n)},e.interval*1e3)}static consent(t){t={content:"<div><span>\u042D\u0442\u043E\u0442 \u0441\u0430\u0439\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442 \u0444\u0430\u0439\u043B\u044B cookies \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044B \u0441\u0431\u043E\u0440\u0430 \u0442\u0435\u0445\u043D\u0438\u0447\u0435\u0441\u043A\u0438\u0445 \u0434\u0430\u043D\u043D\u044B\u0445 \u043F\u043E\u0441\u0435\u0442\u0438\u0442\u0435\u043B\u0435\u0439 (\u0434\u0430\u043D\u043D\u044B\u0435 \u043E\u0431 IP-\u0430\u0434\u0440\u0435\u0441\u0435, \u043C\u0435\u0441\u0442\u043E\u043F\u043E\u043B\u043E\u0436\u0435\u043D\u0438\u0438 \u0438 \u0442.\u0434.) \u0434\u043B\u044F \u043E\u0431\u0435\u0441\u043F\u0435\u0447\u0435\u043D\u0438\u044F \u0440\u0430\u0431\u043E\u0442\u043E\u0441\u043F\u043E\u0441\u043E\u0431\u043D\u043E\u0441\u0442\u0438 \u0438 \u0443\u043B\u0443\u0447\u0448\u0435\u043D\u0438\u044F \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043E\u0431\u0441\u043B\u0443\u0436\u0438\u0432\u0430\u043D\u0438\u044F.</span><div><button action='accept'>\u041F\u0440\u0438\u043D\u044F\u0442\u044C</button><button action='decline'>\u041E\u0442\u043A\u043B\u043E\u043D\u0438\u0442\u044C</button></div></div>",container:"body",location:"bottom",zIndex:1e3,name:"cookie_consent",interval:5,...t};let i=document.createElement("container");if(t.container=="body"&&Object.assign(i.style,{position:"absolute",overflow:"hidden",width:"max-content",height:"max-content",maxWidth:"100vw",maxHeight:"100vh",zIndex:t.zIndex,transition:"inherit",pointerEvents:"all",display:"none",...(()=>{let e=(t.location||"").toLowerCase().split(/\s+/),n={top:e.includes("top")?0:e.includes("bottom")?void 0:"50%",bottom:e.includes("bottom")?0:void 0,left:e.includes("left")?0:e.includes("right")?void 0:"50%",right:e.includes("right")?0:void 0},l=n.left==="50%"?"translateX(-50%)":"",d=n.top==="50%"?"translateY(-50%)":"";return(l||d)&&(n.transform=`${l} ${d}`.trim()),n})()}),document.querySelector(t.container).append(i),!(t.content instanceof Element)){let e=t.content;t.content=e.trim().startsWith("<")?new DOMParser().parseFromString(e,"text/html").body.firstElementChild:document.querySelector(e)??(()=>{throw new Error("\u0421\u0435\u043B\u0435\u043A\u0442\u043E\u0440 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D")})()}i.append(t.content),o.callback(t.name,e=>{["accept","decline"].forEach(n=>{i.querySelectorAll(`[action=${n}]`).forEach(l=>{l.addEventListener("click",d=>{o.set(t.name,n=="accept",t),i.style.display="none"})})}),i.style.display=""},{...t,value:null})}};return v(y);})();
2
- if(typeof cookie!=="undefined"&&cookie&&cookie.default)globalThis.cookie=cookie.default;
1
+ var Cookie=(()=>{var r=Object.defineProperty;var s=Object.getOwnPropertyDescriptor;var u=Object.getOwnPropertyNames;var a=Object.prototype.hasOwnProperty;var f=(o,t)=>{for(var i in t)r(o,i,{get:t[i],enumerable:!0})},h=(o,t,i,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of u(t))!a.call(o,n)&&n!==i&&r(o,n,{get:()=>t[n],enumerable:!(e=s(t,n))||e.enumerable});return o};var v=o=>h(r({},"__esModule",{value:!0}),o);var y={};f(y,{default:()=>c});var c=class o{static set(t,i,e={}){if(e={path:"/",expires:3600,...e},!(e.expires instanceof Date)){let n=e.expires;e.expires=new Date(typeof n=="number"?Date.now()+n*1e3:Date.parse(n)||Date.parse(n.replace(/-/g,"/")))}document.cookie=encodeURIComponent(t)+"="+encodeURIComponent(i)+"; expires="+e.expires.toUTCString()+"; path="+e.path+(e.domain?"; domain="+e.domain:"")+(e.secure?"; secure":"")+(e.sameSite?"; samesite="+e.sameSite:"")}static get(t){t=encodeURIComponent(t);let i=document.cookie.split(";");for(let e=0;e<i.length;e++){let n=i[e].trim();if(n.startsWith(t+"=")){let l=decodeURIComponent(n.substring(t.length+1));try{return JSON.parse(l)}catch{return l}}}return null}static delete(t,i={}){o.set(t,"",{expires:0,...i})}static callback(t,i,e={}){e={interval:0,delay:0,value:!0,...e};let n=setInterval(()=>{o.get(t)===null&&(o.set(t,e.value,e),setTimeout(()=>{i(t)},e.delay*1e3)),e.interval||clearInterval(n)},e.interval*1e3)}static consent(t){t={content:"<div><span>\u042D\u0442\u043E\u0442 \u0441\u0430\u0439\u0442 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0435\u0442 \u0444\u0430\u0439\u043B\u044B cookies \u0438 \u0441\u0435\u0440\u0432\u0438\u0441\u044B \u0441\u0431\u043E\u0440\u0430 \u0442\u0435\u0445\u043D\u0438\u0447\u0435\u0441\u043A\u0438\u0445 \u0434\u0430\u043D\u043D\u044B\u0445 \u043F\u043E\u0441\u0435\u0442\u0438\u0442\u0435\u043B\u0435\u0439 (\u0434\u0430\u043D\u043D\u044B\u0435 \u043E\u0431 IP-\u0430\u0434\u0440\u0435\u0441\u0435, \u043C\u0435\u0441\u0442\u043E\u043F\u043E\u043B\u043E\u0436\u0435\u043D\u0438\u0438 \u0438 \u0442.\u0434.) \u0434\u043B\u044F \u043E\u0431\u0435\u0441\u043F\u0435\u0447\u0435\u043D\u0438\u044F \u0440\u0430\u0431\u043E\u0442\u043E\u0441\u043F\u043E\u0441\u043E\u0431\u043D\u043E\u0441\u0442\u0438 \u0438 \u0443\u043B\u0443\u0447\u0448\u0435\u043D\u0438\u044F \u043A\u0430\u0447\u0435\u0441\u0442\u0432\u0430 \u043E\u0431\u0441\u043B\u0443\u0436\u0438\u0432\u0430\u043D\u0438\u044F.</span><div><button action='accept'>\u041F\u0440\u0438\u043D\u044F\u0442\u044C</button><button action='decline'>\u041E\u0442\u043A\u043B\u043E\u043D\u0438\u0442\u044C</button></div></div>",container:"body",location:"bottom",zIndex:1e3,name:"cookie_consent",interval:5,...t};let i=document.createElement("container");if(t.container=="body"&&Object.assign(i.style,{position:"absolute",overflow:"hidden",width:"max-content",height:"max-content",maxWidth:"100vw",maxHeight:"100vh",zIndex:t.zIndex,transition:"inherit",pointerEvents:"all",display:"none",...(()=>{let e=(t.location||"").toLowerCase().split(/\s+/),n={top:e.includes("top")?0:e.includes("bottom")?void 0:"50%",bottom:e.includes("bottom")?0:void 0,left:e.includes("left")?0:e.includes("right")?void 0:"50%",right:e.includes("right")?0:void 0},l=n.left==="50%"?"translateX(-50%)":"",d=n.top==="50%"?"translateY(-50%)":"";return(l||d)&&(n.transform=`${l} ${d}`.trim()),n})()}),document.querySelector(t.container).append(i),!(t.content instanceof Element)){let e=t.content;t.content=e.trim().startsWith("<")?new DOMParser().parseFromString(e,"text/html").body.firstElementChild:document.querySelector(e)??(()=>{throw new Error("\u0421\u0435\u043B\u0435\u043A\u0442\u043E\u0440 \u043D\u0435 \u043D\u0430\u0439\u0434\u0435\u043D")})()}i.append(t.content),o.callback(t.name,e=>{["accept","decline"].forEach(n=>{i.querySelectorAll(`[action=${n}]`).forEach(l=>{l.addEventListener("click",d=>{o.set(t.name,n=="accept",t),i.style.display="none"})})}),i.style.display=""},{...t,value:null})}};return v(y);})();
2
+ if(typeof Cookie!=="undefined"&&Cookie&&Cookie.default)globalThis.Cookie=Cookie.default;
@@ -1 +1 @@
1
- var p=class{static merge(...e){let d=s=>s!==null&&typeof s=="object"&&!Array.isArray(s)&&(Object.getPrototypeOf(s)??Object.prototype)===Object.prototype,t=(s,u)=>{if(typeof s=="function"&&typeof u=="function")return(...c)=>t(s(...c),u(...c));if(!(Array.isArray(s)&&Array.isArray(u)||d(s)&&d(u)))return u;let l=Array.isArray(s)?s.slice():{...s};for(let[c,f]of Object.entries(u))l[c]=c in l?t(l[c],f):f;return l};return e.reduce(t,{})}static generate_unique_prefix(e){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},[...Array(e.length)].map(d=>e.characters[Math.random()*e.characters.length|0]).join("")}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let d={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,s,u,l=!1,c=new Promise((o,r)=>(s=o,u=r)),f=(o,r)=>{for(let i of d[o])if(i)try{i(r)}catch(n){console.error(`st_ajax: ${o} error`,n)}},y={then:(o,r)=>c.then(o,r),catch:o=>c.catch(o),finally:o=>c.finally(o),abort:()=>t?.abort()};for(let o of Object.keys(d))y[o]=r=>(d[o].push(r),y);let h=o=>{if(l)return;l=!0;let r=o instanceof XMLHttpRequest?{status:o.status,status_text:o.statusText,response:o.responseText,request:o}:{status:void 0,status_text:"",response:o};f("onFailed",r),u(r)};return queueMicrotask(()=>{try{let o=e.url,r=e.method,i;if(f("beforeSend",e),e.data instanceof FormData?i=e.data:e.data instanceof HTMLFormElement?(o=o||e.data.getAttribute("action"),r=r||e.data.getAttribute("method"),i=new FormData(e.data)):i=e.data,o=o||window.location.href,r=r?r.toUpperCase():"GET",i&&typeof i=="object")if(r=="GET"){let n=i instanceof FormData?new URLSearchParams(i).toString():Object.entries(i).map(([a,b])=>`${encodeURIComponent(a)}=${encodeURIComponent(b)}`).join("&");n&&(o+=(/\?.+=/.test(o)?"&":"?")+n),i=null}else i instanceof FormData||(i=JSON.stringify(e.data),Object.keys(e.headers).some(n=>n.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>h(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let n;if(t.status>=200&&t.status<300){if(t.responseType)n=t.response;else{let a=t.getResponseHeader("Content-Type")||e.response_type||"";if(a.includes("/json"))try{n=JSON.parse(t.responseText)}catch{n=t.responseText}else a.includes("/xml")?n=new DOMParser().parseFromString(t.responseText,"application/xml"):a.includes("/html")?n=new DOMParser().parseFromString(t.responseText,"text/html"):n=t.responseText}f("onSuccess",{data:n,request:t}),l=!0,s({data:n,request:t})}else h(t);f("onComplete",{data:n,request:t})},t.open(r,o,!0);for(let n in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,n))try{t.setRequestHeader(n,e.headers[n])}catch{}t.send(i),f("onSend",{detail:e})}catch(o){h(o)}}),y}};export{p as default};
1
+ var p=class{static merge(...e){let i=n=>n!==null&&typeof n=="object"&&!Array.isArray(n)&&(Object.getPrototypeOf(n)??Object.prototype)===Object.prototype,t=(n,u)=>{if(typeof n=="function"&&typeof u=="function")return(...l)=>t(n(...l),u(...l));if(!(Array.isArray(n)&&Array.isArray(u)||i(n)&&i(u)))return u;let f=Array.isArray(n)?n.slice():{...n};for(let[l,d]of Object.entries(u))f[l]=l in f?t(f[l],d):d;return f};return e.reduce(t,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),i=>e.characters[i%e.characters.length]).join("")}static uuid(e=7){let i=crypto.getRandomValues(new Uint8Array(16));if(e===4)i[6]=i[6]&15|64;else{for(let n=0;n<6;n++)i[n]=Number(BigInt(Date.now())>>BigInt(40-n*8)&0xffn);i[6]=i[6]&15|112}i[8]=i[8]&63|128;let t=Array.from(i,n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let i={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,n,u,f=!1,l=new Promise((o,s)=>(n=o,u=s)),d=(o,s)=>{for(let c of i[o])if(c)try{c(s)}catch(r){console.error(`st_ajax: ${o} error`,r)}},y={then:(o,s)=>l.then(o,s),catch:o=>l.catch(o),finally:o=>l.finally(o),abort:()=>t?.abort()};for(let o of Object.keys(i))y[o]=s=>(i[o].push(s),y);let h=o=>{if(f)return;f=!0;let s=o instanceof XMLHttpRequest?{status:o.status,status_text:o.statusText,response:o.responseText,request:o}:{status:void 0,status_text:"",response:o};d("onFailed",s),u(s)};return queueMicrotask(()=>{try{let o=e.url,s=e.method,c;if(d("beforeSend",e),e.data instanceof FormData?c=e.data:e.data instanceof HTMLFormElement?(o=o||e.data.getAttribute("action"),s=s||e.data.getAttribute("method"),c=new FormData(e.data)):c=e.data,o=o||window.location.href,s=s?s.toUpperCase():"GET",c&&typeof c=="object")if(s=="GET"){let r=c instanceof FormData?new URLSearchParams(c).toString():Object.entries(c).map(([a,x])=>`${encodeURIComponent(a)}=${encodeURIComponent(x)}`).join("&");r&&(o+=(/\?.+=/.test(o)?"&":"?")+r),c=null}else c instanceof FormData||(c=JSON.stringify(e.data),Object.keys(e.headers).some(r=>r.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>h(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let r;if(t.status>=200&&t.status<300){if(t.responseType)r=t.response;else{let a=t.getResponseHeader("Content-Type")||e.response_type||"";if(a.includes("/json"))try{r=JSON.parse(t.responseText)}catch{r=t.responseText}else a.includes("/xml")?r=new DOMParser().parseFromString(t.responseText,"application/xml"):a.includes("/html")?r=new DOMParser().parseFromString(t.responseText,"text/html"):r=t.responseText}d("onSuccess",{data:r,request:t}),f=!0,n({data:r,request:t})}else h(t);d("onComplete",{data:r,request:t})},t.open(s,o,!0);for(let r in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,r))try{t.setRequestHeader(r,e.headers[r])}catch{}t.send(c),d("onSend",{detail:e})}catch(o){h(o)}}),y}};export{p as default};
package/dist/core.min.js CHANGED
@@ -1,2 +1,2 @@
1
- var core=(()=>{var g=Object.defineProperty;var x=Object.getOwnPropertyDescriptor;var T=Object.getOwnPropertyNames;var _=Object.prototype.hasOwnProperty;var O=(f,e)=>{for(var c in e)g(f,c,{get:e[c],enumerable:!0})},A=(f,e,c,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of T(e))!_.call(f,n)&&n!==c&&g(f,n,{get:()=>e[n],enumerable:!(t=x(e,n))||t.enumerable});return f};var S=f=>A(g({},"__esModule",{value:!0}),f);var F={};O(F,{default:()=>h});var h=class{static merge(...e){let c=n=>n!==null&&typeof n=="object"&&!Array.isArray(n)&&(Object.getPrototypeOf(n)??Object.prototype)===Object.prototype,t=(n,l)=>{if(typeof n=="function"&&typeof l=="function")return(...u)=>t(n(...u),l(...u));if(!(Array.isArray(n)&&Array.isArray(l)||c(n)&&c(l)))return l;let d=Array.isArray(n)?n.slice():{...n};for(let[u,a]of Object.entries(l))d[u]=u in d?t(d[u],a):a;return d};return e.reduce(t,{})}static generate_unique_prefix(e){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},[...Array(e.length)].map(c=>e.characters[Math.random()*e.characters.length|0]).join("")}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let c={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,n,l,d=!1,u=new Promise((o,s)=>(n=o,l=s)),a=(o,s)=>{for(let i of c[o])if(i)try{i(s)}catch(r){console.error(`st_ajax: ${o} error`,r)}},p={then:(o,s)=>u.then(o,s),catch:o=>u.catch(o),finally:o=>u.finally(o),abort:()=>t?.abort()};for(let o of Object.keys(c))p[o]=s=>(c[o].push(s),p);let b=o=>{if(d)return;d=!0;let s=o instanceof XMLHttpRequest?{status:o.status,status_text:o.statusText,response:o.responseText,request:o}:{status:void 0,status_text:"",response:o};a("onFailed",s),l(s)};return queueMicrotask(()=>{try{let o=e.url,s=e.method,i;if(a("beforeSend",e),e.data instanceof FormData?i=e.data:e.data instanceof HTMLFormElement?(o=o||e.data.getAttribute("action"),s=s||e.data.getAttribute("method"),i=new FormData(e.data)):i=e.data,o=o||window.location.href,s=s?s.toUpperCase():"GET",i&&typeof i=="object")if(s=="GET"){let r=i instanceof FormData?new URLSearchParams(i).toString():Object.entries(i).map(([y,j])=>`${encodeURIComponent(y)}=${encodeURIComponent(j)}`).join("&");r&&(o+=(/\?.+=/.test(o)?"&":"?")+r),i=null}else i instanceof FormData||(i=JSON.stringify(e.data),Object.keys(e.headers).some(r=>r.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>b(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let r;if(t.status>=200&&t.status<300){if(t.responseType)r=t.response;else{let y=t.getResponseHeader("Content-Type")||e.response_type||"";if(y.includes("/json"))try{r=JSON.parse(t.responseText)}catch{r=t.responseText}else y.includes("/xml")?r=new DOMParser().parseFromString(t.responseText,"application/xml"):y.includes("/html")?r=new DOMParser().parseFromString(t.responseText,"text/html"):r=t.responseText}a("onSuccess",{data:r,request:t}),d=!0,n({data:r,request:t})}else b(t);a("onComplete",{data:r,request:t})},t.open(s,o,!0);for(let r in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,r))try{t.setRequestHeader(r,e.headers[r])}catch{}t.send(i),a("onSend",{detail:e})}catch(o){b(o)}}),p}};return S(F);})();
2
- if(typeof core!=="undefined"&&core&&core.default)globalThis.core=core.default;
1
+ var Core=(()=>{var g=Object.defineProperty;var j=Object.getOwnPropertyDescriptor;var A=Object.getOwnPropertyNames;var S=Object.prototype.hasOwnProperty;var T=(f,e)=>{for(var r in e)g(f,r,{get:e[r],enumerable:!0})},w=(f,e,r,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let n of A(e))!S.call(f,n)&&n!==r&&g(f,n,{get:()=>e[n],enumerable:!(t=j(e,n))||t.enumerable});return f};var O=f=>w(g({},"__esModule",{value:!0}),f);var F={};T(F,{default:()=>h});var h=class{static merge(...e){let r=n=>n!==null&&typeof n=="object"&&!Array.isArray(n)&&(Object.getPrototypeOf(n)??Object.prototype)===Object.prototype,t=(n,u)=>{if(typeof n=="function"&&typeof u=="function")return(...l)=>t(n(...l),u(...l));if(!(Array.isArray(n)&&Array.isArray(u)||r(n)&&r(u)))return u;let d=Array.isArray(n)?n.slice():{...n};for(let[l,a]of Object.entries(u))d[l]=l in d?t(d[l],a):a;return d};return e.reduce(t,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),r=>e.characters[r%e.characters.length]).join("")}static uuid(e=7){let r=crypto.getRandomValues(new Uint8Array(16));if(e===4)r[6]=r[6]&15|64;else{for(let n=0;n<6;n++)r[n]=Number(BigInt(Date.now())>>BigInt(40-n*8)&0xffn);r[6]=r[6]&15|112}r[8]=r[8]&63|128;let t=Array.from(r,n=>n.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let r={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,n,u,d=!1,l=new Promise((o,i)=>(n=o,u=i)),a=(o,i)=>{for(let c of r[o])if(c)try{c(i)}catch(s){console.error(`st_ajax: ${o} error`,s)}},p={then:(o,i)=>l.then(o,i),catch:o=>l.catch(o),finally:o=>l.finally(o),abort:()=>t?.abort()};for(let o of Object.keys(r))p[o]=i=>(r[o].push(i),p);let x=o=>{if(d)return;d=!0;let i=o instanceof XMLHttpRequest?{status:o.status,status_text:o.statusText,response:o.responseText,request:o}:{status:void 0,status_text:"",response:o};a("onFailed",i),u(i)};return queueMicrotask(()=>{try{let o=e.url,i=e.method,c;if(a("beforeSend",e),e.data instanceof FormData?c=e.data:e.data instanceof HTMLFormElement?(o=o||e.data.getAttribute("action"),i=i||e.data.getAttribute("method"),c=new FormData(e.data)):c=e.data,o=o||window.location.href,i=i?i.toUpperCase():"GET",c&&typeof c=="object")if(i=="GET"){let s=c instanceof FormData?new URLSearchParams(c).toString():Object.entries(c).map(([y,b])=>`${encodeURIComponent(y)}=${encodeURIComponent(b)}`).join("&");s&&(o+=(/\?.+=/.test(o)?"&":"?")+s),c=null}else c instanceof FormData||(c=JSON.stringify(e.data),Object.keys(e.headers).some(s=>s.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>x(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let s;if(t.status>=200&&t.status<300){if(t.responseType)s=t.response;else{let y=t.getResponseHeader("Content-Type")||e.response_type||"";if(y.includes("/json"))try{s=JSON.parse(t.responseText)}catch{s=t.responseText}else y.includes("/xml")?s=new DOMParser().parseFromString(t.responseText,"application/xml"):y.includes("/html")?s=new DOMParser().parseFromString(t.responseText,"text/html"):s=t.responseText}a("onSuccess",{data:s,request:t}),d=!0,n({data:s,request:t})}else x(t);a("onComplete",{data:s,request:t})},t.open(i,o,!0);for(let s in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,s))try{t.setRequestHeader(s,e.headers[s])}catch{}t.send(c),a("onSend",{detail:e})}catch(o){x(o)}}),p}};return O(F);})();
2
+ if(typeof Core!=="undefined"&&Core&&Core.default)globalThis.Core=Core.default;
@@ -1 +1 @@
1
- var x=Symbol(),_=h=>{try{return h instanceof Element?h:document.querySelector(h)}catch{return}};var S=h=>_(h)?.[x],O=(h,t)=>(h&&(h[x]=t),h);var b=class{static merge(...t){let i=r=>r!==null&&typeof r=="object"&&!Array.isArray(r)&&(Object.getPrototypeOf(r)??Object.prototype)===Object.prototype,e=(r,o)=>{if(typeof r=="function"&&typeof o=="function")return(...u)=>e(r(...u),o(...u));if(!(Array.isArray(r)&&Array.isArray(o)||i(r)&&i(o)))return o;let a=Array.isArray(r)?r.slice():{...r};for(let[u,c]of Object.entries(o))a[u]=u in a?e(a[u],c):c;return a};return t.reduce(e,{})}static generate_unique_prefix(t){return t={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...t},[...Array(t.length)].map(i=>t.characters[Math.random()*t.characters.length|0]).join("")}static fetch(t){t instanceof HTMLFormElement&&(t={url:t.getAttribute("action")||"",method:t.getAttribute("method")||"",data:new FormData(t)}),t={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...t};let i={beforeSend:[t.before_send],onSend:[t.on_send],onSuccess:[t.on_success],onComplete:[t.on_complete],onFailed:[t.on_failed]},e,r,o,a=!1,u=new Promise((n,l)=>(r=n,o=l)),c=(n,l)=>{for(let f of i[n])if(f)try{f(l)}catch(s){console.error(`st_ajax: ${n} error`,s)}},d={then:(n,l)=>u.then(n,l),catch:n=>u.catch(n),finally:n=>u.finally(n),abort:()=>e?.abort()};for(let n of Object.keys(i))d[n]=l=>(i[n].push(l),d);let y=n=>{if(a)return;a=!0;let l=n instanceof XMLHttpRequest?{status:n.status,status_text:n.statusText,response:n.responseText,request:n}:{status:void 0,status_text:"",response:n};c("onFailed",l),o(l)};return queueMicrotask(()=>{try{let n=t.url,l=t.method,f;if(c("beforeSend",t),t.data instanceof FormData?f=t.data:t.data instanceof HTMLFormElement?(n=n||t.data.getAttribute("action"),l=l||t.data.getAttribute("method"),f=new FormData(t.data)):f=t.data,n=n||window.location.href,l=l?l.toUpperCase():"GET",f&&typeof f=="object")if(l=="GET"){let s=f instanceof FormData?new URLSearchParams(f).toString():Object.entries(f).map(([p,m])=>`${encodeURIComponent(p)}=${encodeURIComponent(m)}`).join("&");s&&(n+=(/\?.+=/.test(n)?"&":"?")+s),f=null}else f instanceof FormData||(f=JSON.stringify(t.data),Object.keys(t.headers).some(s=>s.toLowerCase()=="content-type")||(t.headers["Content-Type"]="application/json"));if(e=new XMLHttpRequest,t.response_type)try{e.responseType=t.response_type}catch{}t.timeout>0&&Number.isFinite(t.timeout)&&(e.timeout=t.timeout),e.onerror=e.ontimeout=()=>y(e),e.onreadystatechange=()=>{if(e.readyState!==4)return;let s;if(e.status>=200&&e.status<300){if(e.responseType)s=e.response;else{let p=e.getResponseHeader("Content-Type")||t.response_type||"";if(p.includes("/json"))try{s=JSON.parse(e.responseText)}catch{s=e.responseText}else p.includes("/xml")?s=new DOMParser().parseFromString(e.responseText,"application/xml"):p.includes("/html")?s=new DOMParser().parseFromString(e.responseText,"text/html"):s=e.responseText}c("onSuccess",{data:s,request:e}),a=!0,r({data:s,request:e})}else y(e);c("onComplete",{data:s,request:e})},e.open(l,n,!0);for(let s in t.headers)if(Object.prototype.hasOwnProperty.call(t.headers,s))try{e.setRequestHeader(s,t.headers[s])}catch{}e.send(f),c("onSend",{detail:t})}catch(n){y(n)}}),d}};var g=class h{#t={};#e=null;static find=S;static HOOKS=["before_load","on_load","before_paste","on_paste","on_failed","on_complete","before_init","on_init"];static html(t,...i){let e=Array.isArray(t)?t.reduce((r,o,a)=>r+i[a-1]+o):t;return new DOMParser().parseFromString(e,"text/html").body.firstElementChild}get params(){let t={};for(let[i,e]of Object.entries(this.#t))typeof e!="function"&&i!="formats"&&(t[i]=e);return t}get loading(){return!!this.#e}html=h.html;clone(t={}){return new h({...this.#t,...t,formats:{...this.#t.formats,...t.formats},parent:this})}constructor(t){this.#t={target:null,source:null,mode:"append",multiple:!0,allow_interrupt:!1,formats:{},render(i){return i},before_load:()=>{},on_load:()=>{},before_paste:()=>{},on_paste:()=>{},on_failed:()=>{},on_complete:()=>{},before_init:()=>{},on_init:()=>{},...t},this.#t.before_init.call(this,this.#t),this.target=_(this.#t.target),this.target&&O(this.target,this),this.#t.on_init.call(this,this.#t)}#n(t){return t instanceof Document?"html":typeof t=="string"?"text":"json"}#o(t){let i=this.#t,e=i.formats?.[t]??{},r={};for(let o of new Set([...Object.keys(i),...Object.keys(e)])){if(o=="formats")continue;let a=i[o],u=e[o],c;o in e&&o in i&&h.HOOKS.includes(o)&&typeof a=="function"&&typeof u=="function"?c=o=="on_load"?(d,y,n)=>{let l=a.call(this,d,y,n)??y;return u.call(this,d,l,n)??l}:(...d)=>{a.apply(this,d),u.apply(this,d)}:c=o in e?u:a,r[o]=typeof c=="function"?c.bind(this):c}return r}#r(t,i,e){if(e=="html"){let r=t.body??t.documentElement??t;return i.source?i.multiple?[...r.querySelectorAll(i.source)]:r.querySelector(i.source):i.multiple?[...r.children]:r.firstElementChild}return e=="json"&&i.source?i.source.split(".").reduce((r,o)=>r?.[o],t):t}load(t={}){let{mode:i,...e}=typeof t=="string"?{url:t}:t;if(this.#e){if(!this.#t.allow_interrupt)return this;this.#e.abort()}this.target?.setAttribute("state","loading"),this.#t.before_load.call(this,e);let r=b.fetch(e).onSuccess(({data:o,request:a})=>{let u=this.#n(o),c=this.#o(u),d=this.#r(o,c,u);d=c.on_load(o,d,a)??d;let y=[],n=c.multiple?d?.length??0:1;for(let s=0;s<n;s++){let p=c.multiple?d?.[s]:d,m=c.render(p,s);m instanceof Node&&y.push(m)}c.before_paste(y);let l=document.createDocumentFragment();y.forEach(s=>l.append(s));let f=i??c.mode;this.target&&(f=="replace"?this.target.replaceChildren(l):f=="prepend"?this.target.prepend(l):this.target.append(l)),c.on_paste(y,o)}).onFailed(o=>this.#t.on_failed.call(this,o)).onComplete(o=>this.#t.on_complete.call(this,o));return r.finally(()=>{this.#e===r&&(this.#e=null,this.target?.setAttribute("state","loaded"))}),this.#e=r,this}abort(){return this.#e?.abort(),this}};export{g as default};
1
+ var x=Symbol(),w=Symbol(),g=h=>{try{return h instanceof Element?h:document.querySelector(h)}catch{return}};var S=h=>g(h)?.[x],j=(h,e)=>(h&&(h[x]=e),h);var m=class{static merge(...e){let n=o=>o!==null&&typeof o=="object"&&!Array.isArray(o)&&(Object.getPrototypeOf(o)??Object.prototype)===Object.prototype,t=(o,i)=>{if(typeof o=="function"&&typeof i=="function")return(...u)=>t(o(...u),i(...u));if(!(Array.isArray(o)&&Array.isArray(i)||n(o)&&n(i)))return i;let a=Array.isArray(o)?o.slice():{...o};for(let[u,c]of Object.entries(i))a[u]=u in a?t(a[u],c):c;return a};return e.reduce(t,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),n=>e.characters[n%e.characters.length]).join("")}static uuid(e=7){let n=crypto.getRandomValues(new Uint8Array(16));if(e===4)n[6]=n[6]&15|64;else{for(let o=0;o<6;o++)n[o]=Number(BigInt(Date.now())>>BigInt(40-o*8)&0xffn);n[6]=n[6]&15|112}n[8]=n[8]&63|128;let t=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let n={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,o,i,a=!1,u=new Promise((r,l)=>(o=r,i=l)),c=(r,l)=>{for(let f of n[r])if(f)try{f(l)}catch(s){console.error(`st_ajax: ${r} error`,s)}},d={then:(r,l)=>u.then(r,l),catch:r=>u.catch(r),finally:r=>u.finally(r),abort:()=>t?.abort()};for(let r of Object.keys(n))d[r]=l=>(n[r].push(l),d);let y=r=>{if(a)return;a=!0;let l=r instanceof XMLHttpRequest?{status:r.status,status_text:r.statusText,response:r.responseText,request:r}:{status:void 0,status_text:"",response:r};c("onFailed",l),i(l)};return queueMicrotask(()=>{try{let r=e.url,l=e.method,f;if(c("beforeSend",e),e.data instanceof FormData?f=e.data:e.data instanceof HTMLFormElement?(r=r||e.data.getAttribute("action"),l=l||e.data.getAttribute("method"),f=new FormData(e.data)):f=e.data,r=r||window.location.href,l=l?l.toUpperCase():"GET",f&&typeof f=="object")if(l=="GET"){let s=f instanceof FormData?new URLSearchParams(f).toString():Object.entries(f).map(([p,b])=>`${encodeURIComponent(p)}=${encodeURIComponent(b)}`).join("&");s&&(r+=(/\?.+=/.test(r)?"&":"?")+s),f=null}else f instanceof FormData||(f=JSON.stringify(e.data),Object.keys(e.headers).some(s=>s.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>y(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let s;if(t.status>=200&&t.status<300){if(t.responseType)s=t.response;else{let p=t.getResponseHeader("Content-Type")||e.response_type||"";if(p.includes("/json"))try{s=JSON.parse(t.responseText)}catch{s=t.responseText}else p.includes("/xml")?s=new DOMParser().parseFromString(t.responseText,"application/xml"):p.includes("/html")?s=new DOMParser().parseFromString(t.responseText,"text/html"):s=t.responseText}c("onSuccess",{data:s,request:t}),a=!0,o({data:s,request:t})}else y(t);c("onComplete",{data:s,request:t})},t.open(l,r,!0);for(let s in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,s))try{t.setRequestHeader(s,e.headers[s])}catch{}t.send(f),c("onSend",{detail:e})}catch(r){y(r)}}),d}};var _=class h{#e={};#t=null;static find=S;static HOOKS=["before_load","on_load","before_paste","on_paste","on_failed","on_complete","before_init","on_init"];static html(e,...n){let t=Array.isArray(e)?e.reduce((o,i,a)=>o+n[a-1]+i):e;return new DOMParser().parseFromString(t,"text/html").body.firstElementChild}get params(){let e={};for(let[n,t]of Object.entries(this.#e))typeof t!="function"&&n!="formats"&&(e[n]=t);return e}get loading(){return!!this.#t}html=h.html;clone(e={}){return new h({...this.#e,...e,formats:{...this.#e.formats,...e.formats},parent:this})}constructor(e){this.#e={target:null,source:null,mode:"append",multiple:!0,allow_interrupt:!1,formats:{},render(n){return n},before_load:()=>{},on_load:()=>{},before_paste:()=>{},on_paste:()=>{},on_failed:()=>{},on_complete:()=>{},before_init:()=>{},on_init:()=>{},...e},this.#e.before_init.call(this,this.#e),this.target=g(this.#e.target),this.target&&j(this.target,this),this.#e.on_init.call(this,this.#e)}#n(e){return e instanceof Document?"html":typeof e=="string"?"text":"json"}#o(e){let n=this.#e,t=n.formats?.[e]??{},o={};for(let i of new Set([...Object.keys(n),...Object.keys(t)])){if(i=="formats")continue;let a=n[i],u=t[i],c;i in t&&i in n&&h.HOOKS.includes(i)&&typeof a=="function"&&typeof u=="function"?c=i=="on_load"?(d,y,r)=>{let l=a.call(this,d,y,r)??y;return u.call(this,d,l,r)??l}:(...d)=>{a.apply(this,d),u.apply(this,d)}:c=i in t?u:a,o[i]=typeof c=="function"?c.bind(this):c}return o}#r(e,n,t){if(t=="html"){let o=e.body??e.documentElement??e;return n.source?n.multiple?[...o.querySelectorAll(n.source)]:o.querySelector(n.source):n.multiple?[...o.children]:o.firstElementChild}return t=="json"&&n.source?n.source.split(".").reduce((o,i)=>o?.[i],e):e}load(e={}){let{mode:n,...t}=typeof e=="string"?{url:e}:e;if(this.#t){if(!this.#e.allow_interrupt)return this;this.#t.abort()}this.target?.setAttribute("state","loading"),this.#e.before_load.call(this,t);let o=m.fetch(t).onSuccess(({data:i,request:a})=>{let u=this.#n(i),c=this.#o(u),d=this.#r(i,c,u);d=c.on_load(i,d,a)??d;let y=[],r=c.multiple?d?.length??0:1;for(let s=0;s<r;s++){let p=c.multiple?d?.[s]:d,b=c.render(p,s);b instanceof Node&&y.push(b)}c.before_paste(y);let l=document.createDocumentFragment();y.forEach(s=>l.append(s));let f=n??c.mode;this.target&&(f=="replace"?this.target.replaceChildren(l):f=="prepend"?this.target.prepend(l):this.target.append(l)),c.on_paste(y,i)}).onFailed(i=>this.#e.on_failed.call(this,i)).onComplete(i=>this.#e.on_complete.call(this,i));return o.finally(()=>{this.#t===o&&(this.#t=null,this.target?.setAttribute("state","loaded"))}),this.#t=o,this}abort(){return this.#t?.abort(),this}};export{_ as default};
@@ -1,2 +1,2 @@
1
- var loader=(()=>{var g=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var w=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var F=(u,t)=>{for(var r in t)g(u,r,{get:t[r],enumerable:!0})},q=(u,t,r,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of w(t))!T.call(u,n)&&n!==r&&g(u,n,{get:()=>t[n],enumerable:!(e=A(t,n))||e.enumerable});return u};var C=u=>q(g({},"__esModule",{value:!0}),u);var M={};F(M,{default:()=>_});var S=Symbol(),x=u=>{try{return u instanceof Element?u:document.querySelector(u)}catch{return}};var O=u=>x(u)?.[S],j=(u,t)=>(u&&(u[S]=t),u);var b=class{static merge(...t){let r=n=>n!==null&&typeof n=="object"&&!Array.isArray(n)&&(Object.getPrototypeOf(n)??Object.prototype)===Object.prototype,e=(n,i)=>{if(typeof n=="function"&&typeof i=="function")return(...f)=>e(n(...f),i(...f));if(!(Array.isArray(n)&&Array.isArray(i)||r(n)&&r(i)))return i;let d=Array.isArray(n)?n.slice():{...n};for(let[f,c]of Object.entries(i))d[f]=f in d?e(d[f],c):c;return d};return t.reduce(e,{})}static generate_unique_prefix(t){return t={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...t},[...Array(t.length)].map(r=>t.characters[Math.random()*t.characters.length|0]).join("")}static fetch(t){t instanceof HTMLFormElement&&(t={url:t.getAttribute("action")||"",method:t.getAttribute("method")||"",data:new FormData(t)}),t={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...t};let r={beforeSend:[t.before_send],onSend:[t.on_send],onSuccess:[t.on_success],onComplete:[t.on_complete],onFailed:[t.on_failed]},e,n,i,d=!1,f=new Promise((o,l)=>(n=o,i=l)),c=(o,l)=>{for(let a of r[o])if(a)try{a(l)}catch(s){console.error(`st_ajax: ${o} error`,s)}},h={then:(o,l)=>f.then(o,l),catch:o=>f.catch(o),finally:o=>f.finally(o),abort:()=>e?.abort()};for(let o of Object.keys(r))h[o]=l=>(r[o].push(l),h);let y=o=>{if(d)return;d=!0;let l=o instanceof XMLHttpRequest?{status:o.status,status_text:o.statusText,response:o.responseText,request:o}:{status:void 0,status_text:"",response:o};c("onFailed",l),i(l)};return queueMicrotask(()=>{try{let o=t.url,l=t.method,a;if(c("beforeSend",t),t.data instanceof FormData?a=t.data:t.data instanceof HTMLFormElement?(o=o||t.data.getAttribute("action"),l=l||t.data.getAttribute("method"),a=new FormData(t.data)):a=t.data,o=o||window.location.href,l=l?l.toUpperCase():"GET",a&&typeof a=="object")if(l=="GET"){let s=a instanceof FormData?new URLSearchParams(a).toString():Object.entries(a).map(([p,m])=>`${encodeURIComponent(p)}=${encodeURIComponent(m)}`).join("&");s&&(o+=(/\?.+=/.test(o)?"&":"?")+s),a=null}else a instanceof FormData||(a=JSON.stringify(t.data),Object.keys(t.headers).some(s=>s.toLowerCase()=="content-type")||(t.headers["Content-Type"]="application/json"));if(e=new XMLHttpRequest,t.response_type)try{e.responseType=t.response_type}catch{}t.timeout>0&&Number.isFinite(t.timeout)&&(e.timeout=t.timeout),e.onerror=e.ontimeout=()=>y(e),e.onreadystatechange=()=>{if(e.readyState!==4)return;let s;if(e.status>=200&&e.status<300){if(e.responseType)s=e.response;else{let p=e.getResponseHeader("Content-Type")||t.response_type||"";if(p.includes("/json"))try{s=JSON.parse(e.responseText)}catch{s=e.responseText}else p.includes("/xml")?s=new DOMParser().parseFromString(e.responseText,"application/xml"):p.includes("/html")?s=new DOMParser().parseFromString(e.responseText,"text/html"):s=e.responseText}c("onSuccess",{data:s,request:e}),d=!0,n({data:s,request:e})}else y(e);c("onComplete",{data:s,request:e})},e.open(l,o,!0);for(let s in t.headers)if(Object.prototype.hasOwnProperty.call(t.headers,s))try{e.setRequestHeader(s,t.headers[s])}catch{}e.send(a),c("onSend",{detail:t})}catch(o){y(o)}}),h}};var _=class u{#t={};#e=null;static find=O;static HOOKS=["before_load","on_load","before_paste","on_paste","on_failed","on_complete","before_init","on_init"];static html(t,...r){let e=Array.isArray(t)?t.reduce((n,i,d)=>n+r[d-1]+i):t;return new DOMParser().parseFromString(e,"text/html").body.firstElementChild}get params(){let t={};for(let[r,e]of Object.entries(this.#t))typeof e!="function"&&r!="formats"&&(t[r]=e);return t}get loading(){return!!this.#e}html=u.html;clone(t={}){return new u({...this.#t,...t,formats:{...this.#t.formats,...t.formats},parent:this})}constructor(t){this.#t={target:null,source:null,mode:"append",multiple:!0,allow_interrupt:!1,formats:{},render(r){return r},before_load:()=>{},on_load:()=>{},before_paste:()=>{},on_paste:()=>{},on_failed:()=>{},on_complete:()=>{},before_init:()=>{},on_init:()=>{},...t},this.#t.before_init.call(this,this.#t),this.target=x(this.#t.target),this.target&&j(this.target,this),this.#t.on_init.call(this,this.#t)}#n(t){return t instanceof Document?"html":typeof t=="string"?"text":"json"}#o(t){let r=this.#t,e=r.formats?.[t]??{},n={};for(let i of new Set([...Object.keys(r),...Object.keys(e)])){if(i=="formats")continue;let d=r[i],f=e[i],c;i in e&&i in r&&u.HOOKS.includes(i)&&typeof d=="function"&&typeof f=="function"?c=i=="on_load"?(h,y,o)=>{let l=d.call(this,h,y,o)??y;return f.call(this,h,l,o)??l}:(...h)=>{d.apply(this,h),f.apply(this,h)}:c=i in e?f:d,n[i]=typeof c=="function"?c.bind(this):c}return n}#r(t,r,e){if(e=="html"){let n=t.body??t.documentElement??t;return r.source?r.multiple?[...n.querySelectorAll(r.source)]:n.querySelector(r.source):r.multiple?[...n.children]:n.firstElementChild}return e=="json"&&r.source?r.source.split(".").reduce((n,i)=>n?.[i],t):t}load(t={}){let{mode:r,...e}=typeof t=="string"?{url:t}:t;if(this.#e){if(!this.#t.allow_interrupt)return this;this.#e.abort()}this.target?.setAttribute("state","loading"),this.#t.before_load.call(this,e);let n=b.fetch(e).onSuccess(({data:i,request:d})=>{let f=this.#n(i),c=this.#o(f),h=this.#r(i,c,f);h=c.on_load(i,h,d)??h;let y=[],o=c.multiple?h?.length??0:1;for(let s=0;s<o;s++){let p=c.multiple?h?.[s]:h,m=c.render(p,s);m instanceof Node&&y.push(m)}c.before_paste(y);let l=document.createDocumentFragment();y.forEach(s=>l.append(s));let a=r??c.mode;this.target&&(a=="replace"?this.target.replaceChildren(l):a=="prepend"?this.target.prepend(l):this.target.append(l)),c.on_paste(y,i)}).onFailed(i=>this.#t.on_failed.call(this,i)).onComplete(i=>this.#t.on_complete.call(this,i));return n.finally(()=>{this.#e===n&&(this.#e=null,this.target?.setAttribute("state","loaded"))}),this.#e=n,this}abort(){return this.#e?.abort(),this}};return C(M);})();
2
- if(typeof loader!=="undefined"&&loader&&loader.default)globalThis.loader=loader.default;
1
+ var Loader=(()=>{var _=Object.defineProperty;var A=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var T=Object.prototype.hasOwnProperty;var F=(u,e)=>{for(var n in e)_(u,n,{get:e[n],enumerable:!0})},C=(u,e,n,t)=>{if(e&&typeof e=="object"||typeof e=="function")for(let o of O(e))!T.call(u,o)&&o!==n&&_(u,o,{get:()=>e[o],enumerable:!(t=A(e,o))||t.enumerable});return u};var q=u=>C(_({},"__esModule",{value:!0}),u);var D={};F(D,{default:()=>g});var S=Symbol(),M=Symbol(),x=u=>{try{return u instanceof Element?u:document.querySelector(u)}catch{return}};var j=u=>x(u)?.[S],w=(u,e)=>(u&&(u[S]=e),u);var m=class{static merge(...e){let n=o=>o!==null&&typeof o=="object"&&!Array.isArray(o)&&(Object.getPrototypeOf(o)??Object.prototype)===Object.prototype,t=(o,i)=>{if(typeof o=="function"&&typeof i=="function")return(...f)=>t(o(...f),i(...f));if(!(Array.isArray(o)&&Array.isArray(i)||n(o)&&n(i)))return i;let d=Array.isArray(o)?o.slice():{...o};for(let[f,c]of Object.entries(i))d[f]=f in d?t(d[f],c):c;return d};return e.reduce(t,{})}static getRandomChars(e={}){return e={characters:"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789",length:16,...e},Array.from(crypto.getRandomValues(new Uint8Array(e.length)),n=>e.characters[n%e.characters.length]).join("")}static uuid(e=7){let n=crypto.getRandomValues(new Uint8Array(16));if(e===4)n[6]=n[6]&15|64;else{for(let o=0;o<6;o++)n[o]=Number(BigInt(Date.now())>>BigInt(40-o*8)&0xffn);n[6]=n[6]&15|112}n[8]=n[8]&63|128;let t=Array.from(n,o=>o.toString(16).padStart(2,"0")).join("");return`${t.slice(0,8)}-${t.slice(8,12)}-${t.slice(12,16)}-${t.slice(16,20)}-${t.slice(20)}`}static fetch(e){e instanceof HTMLFormElement&&(e={url:e.getAttribute("action")||"",method:e.getAttribute("method")||"",data:new FormData(e)}),e={url:"",method:"",data:null,headers:{},timeout:0,response_type:"",...e};let n={beforeSend:[e.before_send],onSend:[e.on_send],onSuccess:[e.on_success],onComplete:[e.on_complete],onFailed:[e.on_failed]},t,o,i,d=!1,f=new Promise((r,l)=>(o=r,i=l)),c=(r,l)=>{for(let a of n[r])if(a)try{a(l)}catch(s){console.error(`st_ajax: ${r} error`,s)}},h={then:(r,l)=>f.then(r,l),catch:r=>f.catch(r),finally:r=>f.finally(r),abort:()=>t?.abort()};for(let r of Object.keys(n))h[r]=l=>(n[r].push(l),h);let y=r=>{if(d)return;d=!0;let l=r instanceof XMLHttpRequest?{status:r.status,status_text:r.statusText,response:r.responseText,request:r}:{status:void 0,status_text:"",response:r};c("onFailed",l),i(l)};return queueMicrotask(()=>{try{let r=e.url,l=e.method,a;if(c("beforeSend",e),e.data instanceof FormData?a=e.data:e.data instanceof HTMLFormElement?(r=r||e.data.getAttribute("action"),l=l||e.data.getAttribute("method"),a=new FormData(e.data)):a=e.data,r=r||window.location.href,l=l?l.toUpperCase():"GET",a&&typeof a=="object")if(l=="GET"){let s=a instanceof FormData?new URLSearchParams(a).toString():Object.entries(a).map(([p,b])=>`${encodeURIComponent(p)}=${encodeURIComponent(b)}`).join("&");s&&(r+=(/\?.+=/.test(r)?"&":"?")+s),a=null}else a instanceof FormData||(a=JSON.stringify(e.data),Object.keys(e.headers).some(s=>s.toLowerCase()=="content-type")||(e.headers["Content-Type"]="application/json"));if(t=new XMLHttpRequest,e.response_type)try{t.responseType=e.response_type}catch{}e.timeout>0&&Number.isFinite(e.timeout)&&(t.timeout=e.timeout),t.onerror=t.ontimeout=()=>y(t),t.onreadystatechange=()=>{if(t.readyState!==4)return;let s;if(t.status>=200&&t.status<300){if(t.responseType)s=t.response;else{let p=t.getResponseHeader("Content-Type")||e.response_type||"";if(p.includes("/json"))try{s=JSON.parse(t.responseText)}catch{s=t.responseText}else p.includes("/xml")?s=new DOMParser().parseFromString(t.responseText,"application/xml"):p.includes("/html")?s=new DOMParser().parseFromString(t.responseText,"text/html"):s=t.responseText}c("onSuccess",{data:s,request:t}),d=!0,o({data:s,request:t})}else y(t);c("onComplete",{data:s,request:t})},t.open(l,r,!0);for(let s in e.headers)if(Object.prototype.hasOwnProperty.call(e.headers,s))try{t.setRequestHeader(s,e.headers[s])}catch{}t.send(a),c("onSend",{detail:e})}catch(r){y(r)}}),h}};var g=class u{#e={};#t=null;static find=j;static HOOKS=["before_load","on_load","before_paste","on_paste","on_failed","on_complete","before_init","on_init"];static html(e,...n){let t=Array.isArray(e)?e.reduce((o,i,d)=>o+n[d-1]+i):e;return new DOMParser().parseFromString(t,"text/html").body.firstElementChild}get params(){let e={};for(let[n,t]of Object.entries(this.#e))typeof t!="function"&&n!="formats"&&(e[n]=t);return e}get loading(){return!!this.#t}html=u.html;clone(e={}){return new u({...this.#e,...e,formats:{...this.#e.formats,...e.formats},parent:this})}constructor(e){this.#e={target:null,source:null,mode:"append",multiple:!0,allow_interrupt:!1,formats:{},render(n){return n},before_load:()=>{},on_load:()=>{},before_paste:()=>{},on_paste:()=>{},on_failed:()=>{},on_complete:()=>{},before_init:()=>{},on_init:()=>{},...e},this.#e.before_init.call(this,this.#e),this.target=x(this.#e.target),this.target&&w(this.target,this),this.#e.on_init.call(this,this.#e)}#n(e){return e instanceof Document?"html":typeof e=="string"?"text":"json"}#o(e){let n=this.#e,t=n.formats?.[e]??{},o={};for(let i of new Set([...Object.keys(n),...Object.keys(t)])){if(i=="formats")continue;let d=n[i],f=t[i],c;i in t&&i in n&&u.HOOKS.includes(i)&&typeof d=="function"&&typeof f=="function"?c=i=="on_load"?(h,y,r)=>{let l=d.call(this,h,y,r)??y;return f.call(this,h,l,r)??l}:(...h)=>{d.apply(this,h),f.apply(this,h)}:c=i in t?f:d,o[i]=typeof c=="function"?c.bind(this):c}return o}#r(e,n,t){if(t=="html"){let o=e.body??e.documentElement??e;return n.source?n.multiple?[...o.querySelectorAll(n.source)]:o.querySelector(n.source):n.multiple?[...o.children]:o.firstElementChild}return t=="json"&&n.source?n.source.split(".").reduce((o,i)=>o?.[i],e):e}load(e={}){let{mode:n,...t}=typeof e=="string"?{url:e}:e;if(this.#t){if(!this.#e.allow_interrupt)return this;this.#t.abort()}this.target?.setAttribute("state","loading"),this.#e.before_load.call(this,t);let o=m.fetch(t).onSuccess(({data:i,request:d})=>{let f=this.#n(i),c=this.#o(f),h=this.#r(i,c,f);h=c.on_load(i,h,d)??h;let y=[],r=c.multiple?h?.length??0:1;for(let s=0;s<r;s++){let p=c.multiple?h?.[s]:h,b=c.render(p,s);b instanceof Node&&y.push(b)}c.before_paste(y);let l=document.createDocumentFragment();y.forEach(s=>l.append(s));let a=n??c.mode;this.target&&(a=="replace"?this.target.replaceChildren(l):a=="prepend"?this.target.prepend(l):this.target.append(l)),c.on_paste(y,i)}).onFailed(i=>this.#e.on_failed.call(this,i)).onComplete(i=>this.#e.on_complete.call(this,i));return o.finally(()=>{this.#t===o&&(this.#t=null,this.target?.setAttribute("state","loaded"))}),this.#t=o,this}abort(){return this.#t?.abort(),this}};return q(D);})();
2
+ if(typeof Loader!=="undefined"&&Loader&&Loader.default)globalThis.Loader=Loader.default;
@@ -0,0 +1 @@
1
+ var R=Symbol(),F=Symbol(),S=n=>{try{return n instanceof Element?n:document.querySelector(n)}catch{return}},E=n=>{if(n==null)return[];if(n instanceof Element)return[n];if(n instanceof NodeList||n instanceof HTMLCollection)return[...n];if(Array.isArray(n))return n.flatMap(E);try{return[...document.querySelectorAll(n)]}catch{return[]}},M=n=>S(n)?.[R],T=(n,e)=>(n&&(n[R]=e),n),I=(n,e)=>{if(!n)return n;let t=n[F]??=new Set;for(let[r,i]of Object.entries(e)){if(r in n&&!t.has(r)){console.warn(`\u0418\u043C\u044F "${r}" \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442\u043E \u043D\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0435 \u2014 \u043C\u0435\u0442\u043E\u0434 \u043D\u0435 \u043E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u043D`,n);continue}Object.defineProperty(n,r,{value:i,writable:!0,configurable:!0,enumerable:!1}),t.add(r)}return n};var O=class n{static#m={0:/^[0-9]$/,a:/^\p{L}$/u,"*":/^[^\n]$/};static#L=["target","mask"];static#A=["text","search","tel","url","password"];static#g=e=>e.replace(/\\(.)/g,"$1");static#y=e=>e.global?new RegExp(e.source,e.flags.replace("g","")):e;static#o(e,t){let r=e[t],i=r=="{"?"}":"]",l=0;for(let s=t;s<e.length;s++){let a=e[s];if(a=="\\"){s++;continue}if(r=="["&&a=="{"){if((s=n.#o(e,s))<0)return-1}else if(a==r)l++;else if(a==i&&--l==0)return s}return-1}static#w(e,t){let r=0,i=-1;for(let l=0;l<e.length;l++){if(e[l]=="\\"){l++;continue}e[l]=="{"||e[l]=="["?r++:e[l]=="}"||e[l]=="]"?r--:r==0&&e.startsWith(t,l)&&(i=l)}return i}static#M(e){let t=()=>(console.warn("\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0431\u043B\u043E\u043A \u043C\u0430\u0441\u043A\u0438",`{${e}}`),[...`{${e}}`].map(l=>({type:"literal",char:l}))),r=n.#w(e,";");if(r>0){let l=e.slice(r+1);if(/^(\d+|\d*-\d*)$/.test(l)&&l!="-"){let[s,a]=/^\d+$/.test(l)?[+l,+l]:l.split("-").map((o,h)=>o===""?h?1/0:0:+o);return a<s?t():[{type:"repeat",children:n.compile(e.slice(0,r)),min:s,max:a}]}}if(e[0]=="{"&&e.at(-1)=="}")try{return[{type:"slot",test:new RegExp(`^(?:${e.slice(1,-1)})$`,"u")}]}catch{return t()}let i=n.#w(e,"=>");if(i>0){let l=n.#g(e.slice(0,i)),s=n.#g(e.slice(i+2));return l.length!=1||!s?t():[{type:"transform",from:l,to:s}]}return t()}static compile(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],l;i=="\\"?t.push({type:"literal",char:e[++r]??"\\"}):i=="["&&(l=n.#o(e,r))>=0?(t.push({type:"optional",children:n.compile(e.slice(r+1,l))}),r=l):i=="{"&&(l=n.#o(e,r))>=0?(t.push(...n.#M(e.slice(r+1,l))),r=l):t.push(n.#m[i]?{type:"slot",test:n.#m[i]}:{type:"literal",char:i})}return t}static#b(e){return e.every(t=>t.type=="literal"||t.type=="slot"||t.type=="repeat"&&t.min==t.max&&n.#b(t.children))}static build(e,t={}){if(e&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof RegExp)&&e.pattern==null&&e.filter==null)return Object.entries(e).flatMap(([i,l])=>n.build(l,t).map(s=>({...s,key:i})));let r=(Array.isArray(e)?e:[e]).map(i=>{if(typeof i=="function")return{fn:i,base:t};i instanceof RegExp&&(i={filter:i}),typeof i=="string"&&(i={pattern:i});let l=i.pattern!=null?n.compile(i.pattern):[{type:"repeat",min:0,max:i.max_length??1/0,greedy:!0,children:[{type:"slot",test:n.#y(i.filter)}]}];return{nodes:l,fixed:i.pattern!=null&&n.#b(l),valid:i.valid?n.#y(i.valid):i.filter?/./:null,filler:i.filler??t.filler,before_char:i.before_char??t.before_char,before_slot:i.before_slot??t.before_slot}});return r.forEach((i,l)=>i.key??=l),r}static#k(e,t){let r=e.filler??"_";return r[t]??r[r.length-1]??"_"}static#v(e,t,r){let i=[...String(t??"")];return e.before_char?i.flatMap(l=>{let s=e.before_char(r?.input,{char:l});return s===!1||s===""||s===null?[]:typeof s=="string"?[...s]:[l]}):i}static#O(e,t,r){return e.type=="slot"?e.test.test(t):e.type=="transform"?e.from===t||r.input.slice(r.ip,r.ip+e.to.length).join("")===e.to:e.type=="repeat"?n.#n(e.children,t,r):!1}static#n(e,t,r,i){for(let l of e){if(l.type=="literal"){if(!i&&l.char===t)return!0;continue}if(l.type=="optional"||l.type=="repeat"&&l.min==0){if(n.#n(l.children,t,r,i))return!0;continue}return n.#O(l,t,r)}return i?e.some(l=>l.type=="literal"&&l.char===t):!1}static#a(e,t,r,i="char",l=null){e.units.push({kind:i,ordinal:l,stream_start:e.stream.length,stream_end:e.stream.length+t.length,fmt_start:e.formatted.length,fmt_end:e.formatted.length+r.length}),e.stream+=t,i=="char"&&(e.raw+=t),l!=null&&(e.cells[l]=i=="char"?t:null),e.formatted+=r}static#s(e){e.stop_fmt<0&&(e.stop_fmt=e.formatted.length+e.tail.length)}static#i(e,t,r){for(let i=0;i<e.length;i++){let l=e[i];if(l.type=="literal")t.done?t.ph+=l.char:t.ip<t.input.length?t.input[t.ip]===l.char?(t.ip++,t.consumed++,n.#a(t,l.char,l.char,"literal")):t.formatted+=l.char:t.tail+=l.char;else if(l.type=="slot"){let s=t.ordinal++,a=n.#k(r,s);if(t.done){t.ph_slots.push({fmt:t.formatted.length+t.tail.length+t.ph.length,node:l}),t.ph+=a;continue}let o=!1;for(;;){if(t.ip>=t.input.length){t.complete=!1,t.done=!0,n.#s(t),t.ph_slots.push({fmt:t.formatted.length+t.tail.length,node:l}),t.ph+=a;break}let h=t.input[t.ip];if(l.test.test(h)){if(r.before_slot&&!o){let u=r.before_slot(t.ctx?.input,{char:h,slot:s,cells:t.cells,raw:t.raw,node:l});if(u===!1){t.ip++;continue}if(typeof u=="string"&&u!==h){t.input.splice(t.ip,1,...u),o=!0;continue}}n.#a(t,h,h,"char",s)}else if(h===a)t.complete=!1,n.#a(t,h,h,"hole",s);else{t.ip++;continue}t.ip++,t.consumed++;break}}else if(l.type=="transform"){if(t.done){t.ph+=l.to;continue}for(;;){if(t.ip>=t.input.length){t.complete=!1,t.done=!0,n.#s(t),t.ph+=l.to;break}if(t.input.slice(t.ip,t.ip+l.to.length).join("")===l.to)t.ip+=l.to.length,t.consumed+=l.to.length;else if(t.input[t.ip]===l.from)t.ip++,t.consumed++;else{t.ip++;continue}n.#a(t,l.to,l.to);break}}else if(l.type=="repeat"){if(t.done){for(let a=0;a<l.min;a++)n.#i(l.children,t,r);continue}let s=0;for(;s<l.max;){if(t.ip>=t.input.length){if(s<l.min){t.complete=!1,t.done=!0,n.#s(t);for(let o=s;o<l.min;o++)n.#i(l.children,t,r)}else n.#s(t);break}if(!n.#n(l.children,t.input[t.ip],t)){if(!l.greedy&&s>=l.min)break;t.ip++;continue}let a=t.ip;if(n.#i(l.children,t,r),t.done){for(let o=s+1;o<l.min;o++)n.#i(l.children,t,r);break}if(t.ip===a)break;s++}}else if(l.type=="optional"){if(t.done)continue;let s=e.slice(i+1),a=!1;for(;t.ip<t.input.length;){let o=t.input[t.ip];if(n.#n(l.children,o,t,!0)){a=!0,n.#i(l.children,t,r);break}if(n.#n(s,o,t))break;t.ip++}!a&&t.ip>=t.input.length&&n.#s(t)}}}static run(e,t,r){let i={input:n.#v(e,t,r),ctx:r,ip:0,stream:"",raw:"",formatted:"",tail:"",ph:"",ph_slots:[],units:[],cells:[],consumed:0,ordinal:0,complete:!0,done:!1,stop_fmt:-1};return n.#i(e.nodes,i,e),i.stop_fmt<0&&(i.stop_fmt=i.formatted.length),e.valid&&(i.complete=i.complete&&e.valid.test(i.raw)),{stream:i.stream,raw:i.raw,formatted:i.formatted,tail:i.tail,ph:i.ph,ph_slots:i.ph_slots,complete:i.complete,consumed:i.consumed,units:i.units,cells:i.cells,stop_fmt:i.stop_fmt}}static run_all(e,t,r={}){let i=[];r={...r,stream:String(t??"")};for(let s of e)s.fn?i.push(...n.build(s.fn(r),s.base).map(a=>({...a,key:s.key??a.key}))):i.push(s);let l=null;for(let s of i){let a=n.run(s,t,r);(!l||a.consumed>l.result.consumed||a.consumed==l.result.consumed&&a.complete&&!l.result.complete)&&(l={result:a,def:s,mask_id:s.key})}return l}static render(e,t){return t=="always"?e.formatted+e.tail+e.ph:t===!1?e.formatted:e.formatted+e.tail}static caret_for(e,t){for(let r of e.units)if(r.kind!="literal"&&(t<=r.stream_start||t<r.stream_end))return r.fmt_start;return e.stop_fmt}static#x(e){let t=n.run(e,""),r=0;return t.slots=t.ph_slots,t.parts=t.slots.map((i,l)=>l&&i.fmt>t.slots[l-1].fmt+1?++r:r),t.template=n.render(t,"always"),t}#e={};#E={};#f=null;#t=new WeakMap;#r=[];static find=M;get params(){return this.#e}get value(){return this.#r.map(e=>e.value)}clone(e){return new n({...this.#e,...this.#E,...e,parent:this})}constructor(e){e={target:"input[mask]",mask:null,filler:"_",placeholder:!0,flow:!0,rewrite:!1,caret:!0,before_init:()=>{},on_init:()=>{},before_char:()=>{},before_slot:()=>{},before_input:()=>{},on_input:()=>{},before_paste:()=>{},on_paste:()=>{},on_accept:()=>{},on_complete:()=>{},on_incomplete:()=>{},on_mask_change:()=>{},...e};for(let[t,r]of Object.entries(e))typeof r=="function"&&!n.#L.includes(t)?(this[t]=r.bind(this),this.#E[t]=r):this.#e[t]=r;this.before_init(this.#e),this.#e.mask!=null&&(this.#f=n.build(this.#e.mask,this.#h()));for(let t of E(this.#e.target))this.#$(t);this.on_init(this.#e)}raw(e=this.#u()){return this.#t.get(S(e))?.result?.raw??""}state(e=this.#u()){let t=S(e),r=this.#t.get(t);return r?.result?this.#p(t,r):null}set(e,t){arguments.length<2&&([e,t]=[this.#u(),e]);for(let r of E(e))this.#t.has(r)&&this.#l(r,String(t??""),{prefix:String(t??"")})}clear(e=this.#r){this.set(e,"")}#u(){if(this.#r.length!=1)throw new Error(`Mask: \u043C\u0430\u0441\u043A\u0430 \u043F\u0440\u0438\u0432\u044F\u0437\u0430\u043D\u0430 \u043A ${this.#r.length} \u043F\u043E\u043B\u044F\u043C \u2014 \u0443\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u043E\u043B\u0435 \u044F\u0432\u043D\u043E`);return this.#r[0]}set_mask(e,t=null){let r=n.build(e,this.#h());t||(this.#f=r);for(let i of t?E(t):this.#r){let l=this.#t.get(i);l&&(l.defs=r,l.run=null,this.#l(i,l.stream,{}))}}#h(){return{filler:this.#e.filler,before_char:this.before_char,before_slot:this.before_slot}}#$(e){if(M(e))throw new Error("\u041C\u0430\u0441\u043A\u0430 \u0443\u0436\u0435 \u043F\u0440\u0438\u0432\u044F\u0437\u0430\u043D\u0430 \u043A \u044D\u0442\u043E\u043C\u0443 \u043F\u043E\u043B\u044E");T(e,this),n.#A.includes(e.type)||console.warn(`Mask: \u043F\u043E\u043B\u0435 type="${e.type}" \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u043A\u0430\u0440\u0435\u0442\u043A\u043E\u0439 \u2014 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 type="text" \u0438\u043B\u0438 "tel"`,e);let t=this.#f??(e.getAttribute("mask")?n.build(e.getAttribute("mask"),this.#h()):null);if(!t){console.warn("Mask: \u0434\u043B\u044F \u043F\u043E\u043B\u044F \u043D\u0435 \u0437\u0430\u0434\u0430\u043D\u0430 \u043C\u0430\u0441\u043A\u0430 (\u043D\u0438 \u0432 params.mask, \u043D\u0438 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 mask)",e);return}let r={defs:t,def:null,stream:"",result:null,mask_id:null,rendered:"",run:null,composing:!1,handled:!1};this.#t.set(e,r),this.#r.push(e),I(e,{raw:()=>this.raw(e),state:()=>this.state(e),set:s=>this.set(e,s),clear:()=>this.clear(e),set_mask:s=>this.set_mask(s,e)});let i=()=>this.#e.caret=="hide"&&e.style.setProperty("caret-color","transparent","important");if(i(),e.addEventListener("beforeinput",s=>this.#j(e,s)),this.#e.caret!==!0){let s=()=>this.#I(e);for(let a of["selectionchange","click","keyup","select"])e.addEventListener(a,s)}let l=()=>{if(r.handled){r.handled=!1;return}r.composing||this.#d(e)};e.addEventListener("input",l),e.addEventListener("change",l),e.addEventListener("compositionstart",()=>r.composing=!0),e.addEventListener("compositionend",()=>{r.composing=!1,this.#d(e)}),e.addEventListener("focus",()=>{i(),this.#l(e,r.stream,{prefix:r.stream,silent:!0})}),e.addEventListener("blur",()=>{r.run=null,this.#l(e,r.stream,{silent:!0})}),e.closest("form")?.addEventListener("reset",()=>queueMicrotask(()=>this.#d(e))),this.#l(e,e.value,{silent:!0})}#j(e,t){let r=this.#t.get(e),i=t.inputType??"insertText";if(t.isComposing||i=="insertCompositionText"||i=="deleteCompositionText"){r.composing=!0;return}if(i=="historyUndo"||i=="historyRedo")return;let l=e.selectionStart??0,s=e.selectionEnd??l;this.#e.caret!==!0&&r.result&&!(l==0&&s==e.value.length)&&(l=s=this.#_(e,r,l)),t.preventDefault(),r.handled=!0;let a=i.startsWith("delete"),o="";if(!a){if(i=="insertLineBreak"||i=="insertParagraph")return;if(o=t.data??t.dataTransfer?.getData("text/plain")??"",i=="insertFromPaste"){let h=this.before_paste(e,o);if(h===!1)return;typeof h=="string"&&(o=h)}}this.before_input(e,{type:i,insert:o,start:l,end:s})!==!1&&(this.#e.placeholder=="always"&&r.def?.fixed?this.#T(e,i,l,s,a?"":o):this.#R(e,l,s,a?"":o,i),i=="insertFromPaste"&&this.on_paste(e,this.#p(e,r)))}#R(e,t,r,i,l){let s=this.#t.get(e),a=s.result?.units??[],o,h,u;if(t!=r){let p=a.filter(y=>y.fmt_start<r&&y.fmt_end>t);o=p.length?p[0].stream_start:this.#S(a,t),h=p.length?p.at(-1).stream_end:o}else if(!l.startsWith("delete"))o=h=this.#S(a,t);else{if(l.includes("Forward"))u=a.find(p=>p.fmt_end>t&&p.kind!="literal")??a.find(p=>p.fmt_end>t);else{let p;for(let y of a)y.fmt_start<t&&(y.kind=="literal"?p=y:u=y);u??=p}if(!u)return;o=u.stream_start,h=u.stream_end}let d=s.stream.slice(0,o)+i;this.#l(e,d+s.stream.slice(h),{prefix:d})}#T(e,t,r,i,l){let s=this.#t.get(e),a=s.def,o=a.layout??=n.#x(a),h=o.slots,u=o.parts,d=h.length,p=this.#e.flow,y=this.#e.rewrite,g=Array.from({length:d},(c,m)=>s.result?.cells?.[m]??null),_=c=>{let m=h.findIndex(A=>A.fmt>=c);return m<0?d:m},$=c=>o.template.slice(h[c-1].fmt+1,h[c].fmt),f,b=null,w=null;if(r!=i){f=_(r);for(let c=f;c<d&&h[c].fmt<i;c++)g[c]=null;s.run=null}else if(!l&&t.startsWith("delete")){if(t.includes("Forward")){if((f=_(r))>=d)return;let c=u[f];for(;f<d&&g[f]==null;)f++;if(f>=d||!p&&u[f]!=c)return}else{let c=-1;for(let m=0;m<d;m++)h[m].fmt<r&&(c=m);if(c<0)return;for(f=c;f>=0&&g[f]==null;)f--;if(f<0||!p&&(u[f]!=u[c]||r>h[c].fmt+1))return}g[f]=null}else if(f=_(r),f>=d&&(f=g.indexOf(null))<0&&(f=d),b=this.#c(o,f,r),y){let c=b??u[Math.min(f,d-1)];(s.run?.part!==c||s.run.k!==f||u[f]!==c)&&(w=c)}b??=f<d?u[f]:null;let v=null;for(let c of n.#v(a,l,{input:e})){if(f>=d){if(w==null)break;f=u.indexOf(w)}if(!p&&u[f]!=b){if($(f).includes(c)){b=u[f],v=f,w=y?u[f]:null;continue}if(w==null)continue;f=u.indexOf(w)}if(!h[f].node.test.test(c)){let m=u.lastIndexOf(u[f]);m+1<d&&$(m+1).includes(c)&&(f=m+1,b=u[f],v=f,w=y?u[f]:null);continue}if(w!=null){for(let m=0;m<d;m++)u[m]==w&&(g[m]=null);f=u.indexOf(w),b=w,w=null}g[f++]=c}let C=g.reduce((c,m,A)=>m!=null?A:c,-1),j=g.slice(0,C+1).map((c,m)=>c??n.#k(a,m)).join(""),k=Math.min(n.run(a,j.slice(0,f),{input:e}).stream.length,d),x=k<d?h[k].fmt:h[d-1].fmt+1;!p&&l&&k>0&&k<d&&u[k]!=u[k-1]&&(x=h[k-1].fmt+1),v!=null&&f==v&&(x=h[v].fmt);let L=_(x);s.run=v!=null?null:{part:this.#c(o,L,x)??u[Math.min(L,d-1)],k:L},this.#l(e,j,{caret_fmt:x})}#I(e){let t=this.#t.get(e);if(document.activeElement!==e||!t?.result)return;let r=e.selectionStart,i=e.selectionEnd;if(r==null)return;if(r!==i){(r!=0||i!=e.value.length)&&e.setSelectionRange(0,e.value.length);return}if(r===t.caret)return;let l=this.#_(e,t,r);r!==l&&e.setSelectionRange(l,l),t.caret=l}#_(e,t,r){let i=t.def;if(this.#e.placeholder=="always"&&i?.fixed&&!this.#e.flow){let l=i.layout??=n.#x(i),{slots:s,parts:a}=l,o=s.findIndex(p=>p.fmt>=r);o<0&&(o=s.length-1);let h=this.#c(l,o,r)??a[o],u=a.indexOf(h),d=a.lastIndexOf(h);for(let p=u;p<=d;p++)if(t.result.cells?.[p]==null)return s[p].fmt;return s[d].fmt+1}return Math.min(t.result.stop_fmt,e.value.length)}#c(e,t,r){let{slots:i,parts:l}=e;return!this.#e.flow&&t>0&&t<i.length&&l[t]!=l[t-1]&&r==i[t-1].fmt+1?l[t-1]:null}#S(e,t){let r=0;for(let i of e)(i.fmt_end<=t||i.fmt_start<t)&&(r=i.stream_end);return r}#d(e){let t=this.#t.get(e);if(e.value===t.rendered)return;t.run=null;let r=e.selectionStart??e.value.length;this.#l(e,e.value,{prefix:e.value.slice(0,r)})}#l(e,t,{prefix:r=null,caret_fmt:i=null,silent:l=!1}={}){let s=this.#t.get(e),a=n.run_all(s.defs,t,{raw:s.result?.raw??"",value:e.value,input:e});if(!a)return;let{result:o,def:h,mask_id:u}=a,d=this.#C(e,o);e.value!==d&&(e.value=d),s.rendered=d,i==null&&r!=null&&document.activeElement===e&&(i=n.caret_for(o,n.run(h,r,{input:e}).stream.length)),i!=null&&document.activeElement===e&&(i=Math.min(i,d.length),e.setSelectionRange(i,i),s.caret=i);let p=s.result,y=s.mask_id;if(s.result=o,s.stream=o.stream,s.def=h,s.mask_id=u,e.setAttribute("mask_id",u),e.setAttribute("progress",o.raw.length),e.setAttribute("is_complete",o.complete),l)return;let g=this.#p(e,s);this.on_input(e,g),o.raw!==(p?.raw??"")&&this.on_accept(e,g),o.complete&&!p?.complete&&this.on_complete(e,g),!o.complete&&p?.complete&&this.on_incomplete(e,g),p&&u!==y&&this.on_mask_change(e,g)}#C(e,t){return t.stream?n.render(t,this.#e.placeholder):document.activeElement!==e?"":this.#e.placeholder=="always"?n.render(t,"always"):this.#e.placeholder==!1?"":n.render(t,!0)}#p(e,t){return{raw:t.result?.raw??"",formatted:e.value,complete:t.result?.complete??!1,mask_id:t.mask_id,progress:t.result?.raw.length??0}}};export{O as default};
@@ -0,0 +1,2 @@
1
+ var Mask=(()=>{var O=Object.defineProperty;var P=Object.getOwnPropertyDescriptor;var W=Object.getOwnPropertyNames;var q=Object.prototype.hasOwnProperty;var B=(n,e)=>{for(var t in e)O(n,t,{get:e[t],enumerable:!0})},D=(n,e,t,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of W(e))!q.call(n,i)&&i!==t&&O(n,i,{get:()=>e[i],enumerable:!(r=P(e,i))||r.enumerable});return n};var N=n=>D(O({},"__esModule",{value:!0}),n);var H={};B(H,{default:()=>L});var T=Symbol(),G=Symbol(),S=n=>{try{return n instanceof Element?n:document.querySelector(n)}catch{return}},E=n=>{if(n==null)return[];if(n instanceof Element)return[n];if(n instanceof NodeList||n instanceof HTMLCollection)return[...n];if(Array.isArray(n))return n.flatMap(E);try{return[...document.querySelectorAll(n)]}catch{return[]}},$=n=>S(n)?.[T],I=(n,e)=>(n&&(n[T]=e),n),C=(n,e)=>{if(!n)return n;let t=n[G]??=new Set;for(let[r,i]of Object.entries(e)){if(r in n&&!t.has(r)){console.warn(`\u0418\u043C\u044F "${r}" \u0443\u0436\u0435 \u0437\u0430\u043D\u044F\u0442\u043E \u043D\u0430 \u044D\u043B\u0435\u043C\u0435\u043D\u0442\u0435 \u2014 \u043C\u0435\u0442\u043E\u0434 \u043D\u0435 \u043E\u043F\u0443\u0431\u043B\u0438\u043A\u043E\u0432\u0430\u043D`,n);continue}Object.defineProperty(n,r,{value:i,writable:!0,configurable:!0,enumerable:!1}),t.add(r)}return n};var L=class n{static#m={0:/^[0-9]$/,a:/^\p{L}$/u,"*":/^[^\n]$/};static#L=["target","mask"];static#A=["text","search","tel","url","password"];static#g=e=>e.replace(/\\(.)/g,"$1");static#y=e=>e.global?new RegExp(e.source,e.flags.replace("g","")):e;static#o(e,t){let r=e[t],i=r=="{"?"}":"]",l=0;for(let s=t;s<e.length;s++){let a=e[s];if(a=="\\"){s++;continue}if(r=="["&&a=="{"){if((s=n.#o(e,s))<0)return-1}else if(a==r)l++;else if(a==i&&--l==0)return s}return-1}static#w(e,t){let r=0,i=-1;for(let l=0;l<e.length;l++){if(e[l]=="\\"){l++;continue}e[l]=="{"||e[l]=="["?r++:e[l]=="}"||e[l]=="]"?r--:r==0&&e.startsWith(t,l)&&(i=l)}return i}static#M(e){let t=()=>(console.warn("\u041D\u0435\u043A\u043E\u0440\u0440\u0435\u043A\u0442\u043D\u044B\u0439 \u0431\u043B\u043E\u043A \u043C\u0430\u0441\u043A\u0438",`{${e}}`),[...`{${e}}`].map(l=>({type:"literal",char:l}))),r=n.#w(e,";");if(r>0){let l=e.slice(r+1);if(/^(\d+|\d*-\d*)$/.test(l)&&l!="-"){let[s,a]=/^\d+$/.test(l)?[+l,+l]:l.split("-").map((o,h)=>o===""?h?1/0:0:+o);return a<s?t():[{type:"repeat",children:n.compile(e.slice(0,r)),min:s,max:a}]}}if(e[0]=="{"&&e.at(-1)=="}")try{return[{type:"slot",test:new RegExp(`^(?:${e.slice(1,-1)})$`,"u")}]}catch{return t()}let i=n.#w(e,"=>");if(i>0){let l=n.#g(e.slice(0,i)),s=n.#g(e.slice(i+2));return l.length!=1||!s?t():[{type:"transform",from:l,to:s}]}return t()}static compile(e){let t=[];for(let r=0;r<e.length;r++){let i=e[r],l;i=="\\"?t.push({type:"literal",char:e[++r]??"\\"}):i=="["&&(l=n.#o(e,r))>=0?(t.push({type:"optional",children:n.compile(e.slice(r+1,l))}),r=l):i=="{"&&(l=n.#o(e,r))>=0?(t.push(...n.#M(e.slice(r+1,l))),r=l):t.push(n.#m[i]?{type:"slot",test:n.#m[i]}:{type:"literal",char:i})}return t}static#b(e){return e.every(t=>t.type=="literal"||t.type=="slot"||t.type=="repeat"&&t.min==t.max&&n.#b(t.children))}static build(e,t={}){if(e&&typeof e=="object"&&!Array.isArray(e)&&!(e instanceof RegExp)&&e.pattern==null&&e.filter==null)return Object.entries(e).flatMap(([i,l])=>n.build(l,t).map(s=>({...s,key:i})));let r=(Array.isArray(e)?e:[e]).map(i=>{if(typeof i=="function")return{fn:i,base:t};i instanceof RegExp&&(i={filter:i}),typeof i=="string"&&(i={pattern:i});let l=i.pattern!=null?n.compile(i.pattern):[{type:"repeat",min:0,max:i.max_length??1/0,greedy:!0,children:[{type:"slot",test:n.#y(i.filter)}]}];return{nodes:l,fixed:i.pattern!=null&&n.#b(l),valid:i.valid?n.#y(i.valid):i.filter?/./:null,filler:i.filler??t.filler,before_char:i.before_char??t.before_char,before_slot:i.before_slot??t.before_slot}});return r.forEach((i,l)=>i.key??=l),r}static#k(e,t){let r=e.filler??"_";return r[t]??r[r.length-1]??"_"}static#v(e,t,r){let i=[...String(t??"")];return e.before_char?i.flatMap(l=>{let s=e.before_char(r?.input,{char:l});return s===!1||s===""||s===null?[]:typeof s=="string"?[...s]:[l]}):i}static#O(e,t,r){return e.type=="slot"?e.test.test(t):e.type=="transform"?e.from===t||r.input.slice(r.ip,r.ip+e.to.length).join("")===e.to:e.type=="repeat"?n.#n(e.children,t,r):!1}static#n(e,t,r,i){for(let l of e){if(l.type=="literal"){if(!i&&l.char===t)return!0;continue}if(l.type=="optional"||l.type=="repeat"&&l.min==0){if(n.#n(l.children,t,r,i))return!0;continue}return n.#O(l,t,r)}return i?e.some(l=>l.type=="literal"&&l.char===t):!1}static#a(e,t,r,i="char",l=null){e.units.push({kind:i,ordinal:l,stream_start:e.stream.length,stream_end:e.stream.length+t.length,fmt_start:e.formatted.length,fmt_end:e.formatted.length+r.length}),e.stream+=t,i=="char"&&(e.raw+=t),l!=null&&(e.cells[l]=i=="char"?t:null),e.formatted+=r}static#s(e){e.stop_fmt<0&&(e.stop_fmt=e.formatted.length+e.tail.length)}static#i(e,t,r){for(let i=0;i<e.length;i++){let l=e[i];if(l.type=="literal")t.done?t.ph+=l.char:t.ip<t.input.length?t.input[t.ip]===l.char?(t.ip++,t.consumed++,n.#a(t,l.char,l.char,"literal")):t.formatted+=l.char:t.tail+=l.char;else if(l.type=="slot"){let s=t.ordinal++,a=n.#k(r,s);if(t.done){t.ph_slots.push({fmt:t.formatted.length+t.tail.length+t.ph.length,node:l}),t.ph+=a;continue}let o=!1;for(;;){if(t.ip>=t.input.length){t.complete=!1,t.done=!0,n.#s(t),t.ph_slots.push({fmt:t.formatted.length+t.tail.length,node:l}),t.ph+=a;break}let h=t.input[t.ip];if(l.test.test(h)){if(r.before_slot&&!o){let u=r.before_slot(t.ctx?.input,{char:h,slot:s,cells:t.cells,raw:t.raw,node:l});if(u===!1){t.ip++;continue}if(typeof u=="string"&&u!==h){t.input.splice(t.ip,1,...u),o=!0;continue}}n.#a(t,h,h,"char",s)}else if(h===a)t.complete=!1,n.#a(t,h,h,"hole",s);else{t.ip++;continue}t.ip++,t.consumed++;break}}else if(l.type=="transform"){if(t.done){t.ph+=l.to;continue}for(;;){if(t.ip>=t.input.length){t.complete=!1,t.done=!0,n.#s(t),t.ph+=l.to;break}if(t.input.slice(t.ip,t.ip+l.to.length).join("")===l.to)t.ip+=l.to.length,t.consumed+=l.to.length;else if(t.input[t.ip]===l.from)t.ip++,t.consumed++;else{t.ip++;continue}n.#a(t,l.to,l.to);break}}else if(l.type=="repeat"){if(t.done){for(let a=0;a<l.min;a++)n.#i(l.children,t,r);continue}let s=0;for(;s<l.max;){if(t.ip>=t.input.length){if(s<l.min){t.complete=!1,t.done=!0,n.#s(t);for(let o=s;o<l.min;o++)n.#i(l.children,t,r)}else n.#s(t);break}if(!n.#n(l.children,t.input[t.ip],t)){if(!l.greedy&&s>=l.min)break;t.ip++;continue}let a=t.ip;if(n.#i(l.children,t,r),t.done){for(let o=s+1;o<l.min;o++)n.#i(l.children,t,r);break}if(t.ip===a)break;s++}}else if(l.type=="optional"){if(t.done)continue;let s=e.slice(i+1),a=!1;for(;t.ip<t.input.length;){let o=t.input[t.ip];if(n.#n(l.children,o,t,!0)){a=!0,n.#i(l.children,t,r);break}if(n.#n(s,o,t))break;t.ip++}!a&&t.ip>=t.input.length&&n.#s(t)}}}static run(e,t,r){let i={input:n.#v(e,t,r),ctx:r,ip:0,stream:"",raw:"",formatted:"",tail:"",ph:"",ph_slots:[],units:[],cells:[],consumed:0,ordinal:0,complete:!0,done:!1,stop_fmt:-1};return n.#i(e.nodes,i,e),i.stop_fmt<0&&(i.stop_fmt=i.formatted.length),e.valid&&(i.complete=i.complete&&e.valid.test(i.raw)),{stream:i.stream,raw:i.raw,formatted:i.formatted,tail:i.tail,ph:i.ph,ph_slots:i.ph_slots,complete:i.complete,consumed:i.consumed,units:i.units,cells:i.cells,stop_fmt:i.stop_fmt}}static run_all(e,t,r={}){let i=[];r={...r,stream:String(t??"")};for(let s of e)s.fn?i.push(...n.build(s.fn(r),s.base).map(a=>({...a,key:s.key??a.key}))):i.push(s);let l=null;for(let s of i){let a=n.run(s,t,r);(!l||a.consumed>l.result.consumed||a.consumed==l.result.consumed&&a.complete&&!l.result.complete)&&(l={result:a,def:s,mask_id:s.key})}return l}static render(e,t){return t=="always"?e.formatted+e.tail+e.ph:t===!1?e.formatted:e.formatted+e.tail}static caret_for(e,t){for(let r of e.units)if(r.kind!="literal"&&(t<=r.stream_start||t<r.stream_end))return r.fmt_start;return e.stop_fmt}static#x(e){let t=n.run(e,""),r=0;return t.slots=t.ph_slots,t.parts=t.slots.map((i,l)=>l&&i.fmt>t.slots[l-1].fmt+1?++r:r),t.template=n.render(t,"always"),t}#e={};#E={};#f=null;#t=new WeakMap;#r=[];static find=$;get params(){return this.#e}get value(){return this.#r.map(e=>e.value)}clone(e){return new n({...this.#e,...this.#E,...e,parent:this})}constructor(e){e={target:"input[mask]",mask:null,filler:"_",placeholder:!0,flow:!0,rewrite:!1,caret:!0,before_init:()=>{},on_init:()=>{},before_char:()=>{},before_slot:()=>{},before_input:()=>{},on_input:()=>{},before_paste:()=>{},on_paste:()=>{},on_accept:()=>{},on_complete:()=>{},on_incomplete:()=>{},on_mask_change:()=>{},...e};for(let[t,r]of Object.entries(e))typeof r=="function"&&!n.#L.includes(t)?(this[t]=r.bind(this),this.#E[t]=r):this.#e[t]=r;this.before_init(this.#e),this.#e.mask!=null&&(this.#f=n.build(this.#e.mask,this.#h()));for(let t of E(this.#e.target))this.#$(t);this.on_init(this.#e)}raw(e=this.#u()){return this.#t.get(S(e))?.result?.raw??""}state(e=this.#u()){let t=S(e),r=this.#t.get(t);return r?.result?this.#p(t,r):null}set(e,t){arguments.length<2&&([e,t]=[this.#u(),e]);for(let r of E(e))this.#t.has(r)&&this.#l(r,String(t??""),{prefix:String(t??"")})}clear(e=this.#r){this.set(e,"")}#u(){if(this.#r.length!=1)throw new Error(`Mask: \u043C\u0430\u0441\u043A\u0430 \u043F\u0440\u0438\u0432\u044F\u0437\u0430\u043D\u0430 \u043A ${this.#r.length} \u043F\u043E\u043B\u044F\u043C \u2014 \u0443\u043A\u0430\u0436\u0438\u0442\u0435 \u043F\u043E\u043B\u0435 \u044F\u0432\u043D\u043E`);return this.#r[0]}set_mask(e,t=null){let r=n.build(e,this.#h());t||(this.#f=r);for(let i of t?E(t):this.#r){let l=this.#t.get(i);l&&(l.defs=r,l.run=null,this.#l(i,l.stream,{}))}}#h(){return{filler:this.#e.filler,before_char:this.before_char,before_slot:this.before_slot}}#$(e){if($(e))throw new Error("\u041C\u0430\u0441\u043A\u0430 \u0443\u0436\u0435 \u043F\u0440\u0438\u0432\u044F\u0437\u0430\u043D\u0430 \u043A \u044D\u0442\u043E\u043C\u0443 \u043F\u043E\u043B\u044E");I(e,this),n.#A.includes(e.type)||console.warn(`Mask: \u043F\u043E\u043B\u0435 type="${e.type}" \u043D\u0435 \u043F\u043E\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u0442 \u0443\u043F\u0440\u0430\u0432\u043B\u0435\u043D\u0438\u0435 \u043A\u0430\u0440\u0435\u0442\u043A\u043E\u0439 \u2014 \u0438\u0441\u043F\u043E\u043B\u044C\u0437\u0443\u0439\u0442\u0435 type="text" \u0438\u043B\u0438 "tel"`,e);let t=this.#f??(e.getAttribute("mask")?n.build(e.getAttribute("mask"),this.#h()):null);if(!t){console.warn("Mask: \u0434\u043B\u044F \u043F\u043E\u043B\u044F \u043D\u0435 \u0437\u0430\u0434\u0430\u043D\u0430 \u043C\u0430\u0441\u043A\u0430 (\u043D\u0438 \u0432 params.mask, \u043D\u0438 \u0432 \u0430\u0442\u0440\u0438\u0431\u0443\u0442\u0435 mask)",e);return}let r={defs:t,def:null,stream:"",result:null,mask_id:null,rendered:"",run:null,composing:!1,handled:!1};this.#t.set(e,r),this.#r.push(e),C(e,{raw:()=>this.raw(e),state:()=>this.state(e),set:s=>this.set(e,s),clear:()=>this.clear(e),set_mask:s=>this.set_mask(s,e)});let i=()=>this.#e.caret=="hide"&&e.style.setProperty("caret-color","transparent","important");if(i(),e.addEventListener("beforeinput",s=>this.#j(e,s)),this.#e.caret!==!0){let s=()=>this.#I(e);for(let a of["selectionchange","click","keyup","select"])e.addEventListener(a,s)}let l=()=>{if(r.handled){r.handled=!1;return}r.composing||this.#d(e)};e.addEventListener("input",l),e.addEventListener("change",l),e.addEventListener("compositionstart",()=>r.composing=!0),e.addEventListener("compositionend",()=>{r.composing=!1,this.#d(e)}),e.addEventListener("focus",()=>{i(),this.#l(e,r.stream,{prefix:r.stream,silent:!0})}),e.addEventListener("blur",()=>{r.run=null,this.#l(e,r.stream,{silent:!0})}),e.closest("form")?.addEventListener("reset",()=>queueMicrotask(()=>this.#d(e))),this.#l(e,e.value,{silent:!0})}#j(e,t){let r=this.#t.get(e),i=t.inputType??"insertText";if(t.isComposing||i=="insertCompositionText"||i=="deleteCompositionText"){r.composing=!0;return}if(i=="historyUndo"||i=="historyRedo")return;let l=e.selectionStart??0,s=e.selectionEnd??l;this.#e.caret!==!0&&r.result&&!(l==0&&s==e.value.length)&&(l=s=this.#_(e,r,l)),t.preventDefault(),r.handled=!0;let a=i.startsWith("delete"),o="";if(!a){if(i=="insertLineBreak"||i=="insertParagraph")return;if(o=t.data??t.dataTransfer?.getData("text/plain")??"",i=="insertFromPaste"){let h=this.before_paste(e,o);if(h===!1)return;typeof h=="string"&&(o=h)}}this.before_input(e,{type:i,insert:o,start:l,end:s})!==!1&&(this.#e.placeholder=="always"&&r.def?.fixed?this.#T(e,i,l,s,a?"":o):this.#R(e,l,s,a?"":o,i),i=="insertFromPaste"&&this.on_paste(e,this.#p(e,r)))}#R(e,t,r,i,l){let s=this.#t.get(e),a=s.result?.units??[],o,h,u;if(t!=r){let p=a.filter(y=>y.fmt_start<r&&y.fmt_end>t);o=p.length?p[0].stream_start:this.#S(a,t),h=p.length?p.at(-1).stream_end:o}else if(!l.startsWith("delete"))o=h=this.#S(a,t);else{if(l.includes("Forward"))u=a.find(p=>p.fmt_end>t&&p.kind!="literal")??a.find(p=>p.fmt_end>t);else{let p;for(let y of a)y.fmt_start<t&&(y.kind=="literal"?p=y:u=y);u??=p}if(!u)return;o=u.stream_start,h=u.stream_end}let d=s.stream.slice(0,o)+i;this.#l(e,d+s.stream.slice(h),{prefix:d})}#T(e,t,r,i,l){let s=this.#t.get(e),a=s.def,o=a.layout??=n.#x(a),h=o.slots,u=o.parts,d=h.length,p=this.#e.flow,y=this.#e.rewrite,g=Array.from({length:d},(c,m)=>s.result?.cells?.[m]??null),_=c=>{let m=h.findIndex(M=>M.fmt>=c);return m<0?d:m},j=c=>o.template.slice(h[c-1].fmt+1,h[c].fmt),f,b=null,w=null;if(r!=i){f=_(r);for(let c=f;c<d&&h[c].fmt<i;c++)g[c]=null;s.run=null}else if(!l&&t.startsWith("delete")){if(t.includes("Forward")){if((f=_(r))>=d)return;let c=u[f];for(;f<d&&g[f]==null;)f++;if(f>=d||!p&&u[f]!=c)return}else{let c=-1;for(let m=0;m<d;m++)h[m].fmt<r&&(c=m);if(c<0)return;for(f=c;f>=0&&g[f]==null;)f--;if(f<0||!p&&(u[f]!=u[c]||r>h[c].fmt+1))return}g[f]=null}else if(f=_(r),f>=d&&(f=g.indexOf(null))<0&&(f=d),b=this.#c(o,f,r),y){let c=b??u[Math.min(f,d-1)];(s.run?.part!==c||s.run.k!==f||u[f]!==c)&&(w=c)}b??=f<d?u[f]:null;let v=null;for(let c of n.#v(a,l,{input:e})){if(f>=d){if(w==null)break;f=u.indexOf(w)}if(!p&&u[f]!=b){if(j(f).includes(c)){b=u[f],v=f,w=y?u[f]:null;continue}if(w==null)continue;f=u.indexOf(w)}if(!h[f].node.test.test(c)){let m=u.lastIndexOf(u[f]);m+1<d&&j(m+1).includes(c)&&(f=m+1,b=u[f],v=f,w=y?u[f]:null);continue}if(w!=null){for(let m=0;m<d;m++)u[m]==w&&(g[m]=null);f=u.indexOf(w),b=w,w=null}g[f++]=c}let F=g.reduce((c,m,M)=>m!=null?M:c,-1),R=g.slice(0,F+1).map((c,m)=>c??n.#k(a,m)).join(""),k=Math.min(n.run(a,R.slice(0,f),{input:e}).stream.length,d),x=k<d?h[k].fmt:h[d-1].fmt+1;!p&&l&&k>0&&k<d&&u[k]!=u[k-1]&&(x=h[k-1].fmt+1),v!=null&&f==v&&(x=h[v].fmt);let A=_(x);s.run=v!=null?null:{part:this.#c(o,A,x)??u[Math.min(A,d-1)],k:A},this.#l(e,R,{caret_fmt:x})}#I(e){let t=this.#t.get(e);if(document.activeElement!==e||!t?.result)return;let r=e.selectionStart,i=e.selectionEnd;if(r==null)return;if(r!==i){(r!=0||i!=e.value.length)&&e.setSelectionRange(0,e.value.length);return}if(r===t.caret)return;let l=this.#_(e,t,r);r!==l&&e.setSelectionRange(l,l),t.caret=l}#_(e,t,r){let i=t.def;if(this.#e.placeholder=="always"&&i?.fixed&&!this.#e.flow){let l=i.layout??=n.#x(i),{slots:s,parts:a}=l,o=s.findIndex(p=>p.fmt>=r);o<0&&(o=s.length-1);let h=this.#c(l,o,r)??a[o],u=a.indexOf(h),d=a.lastIndexOf(h);for(let p=u;p<=d;p++)if(t.result.cells?.[p]==null)return s[p].fmt;return s[d].fmt+1}return Math.min(t.result.stop_fmt,e.value.length)}#c(e,t,r){let{slots:i,parts:l}=e;return!this.#e.flow&&t>0&&t<i.length&&l[t]!=l[t-1]&&r==i[t-1].fmt+1?l[t-1]:null}#S(e,t){let r=0;for(let i of e)(i.fmt_end<=t||i.fmt_start<t)&&(r=i.stream_end);return r}#d(e){let t=this.#t.get(e);if(e.value===t.rendered)return;t.run=null;let r=e.selectionStart??e.value.length;this.#l(e,e.value,{prefix:e.value.slice(0,r)})}#l(e,t,{prefix:r=null,caret_fmt:i=null,silent:l=!1}={}){let s=this.#t.get(e),a=n.run_all(s.defs,t,{raw:s.result?.raw??"",value:e.value,input:e});if(!a)return;let{result:o,def:h,mask_id:u}=a,d=this.#C(e,o);e.value!==d&&(e.value=d),s.rendered=d,i==null&&r!=null&&document.activeElement===e&&(i=n.caret_for(o,n.run(h,r,{input:e}).stream.length)),i!=null&&document.activeElement===e&&(i=Math.min(i,d.length),e.setSelectionRange(i,i),s.caret=i);let p=s.result,y=s.mask_id;if(s.result=o,s.stream=o.stream,s.def=h,s.mask_id=u,e.setAttribute("mask_id",u),e.setAttribute("progress",o.raw.length),e.setAttribute("is_complete",o.complete),l)return;let g=this.#p(e,s);this.on_input(e,g),o.raw!==(p?.raw??"")&&this.on_accept(e,g),o.complete&&!p?.complete&&this.on_complete(e,g),!o.complete&&p?.complete&&this.on_incomplete(e,g),p&&u!==y&&this.on_mask_change(e,g)}#C(e,t){return t.stream?n.render(t,this.#e.placeholder):document.activeElement!==e?"":this.#e.placeholder=="always"?n.render(t,"always"):this.#e.placeholder==!1?"":n.render(t,!0)}#p(e,t){return{raw:t.result?.raw??"",formatted:e.value,complete:t.result?.complete??!1,mask_id:t.mask_id,progress:t.result?.raw.length??0}}};return N(H);})();
2
+ if(typeof Mask!=="undefined"&&Mask&&Mask.default)globalThis.Mask=Mask.default;
@@ -1 +1 @@
1
- var u=Symbol(),h=i=>{try{return i instanceof Element?i:document.querySelector(i)}catch{return}};var f=i=>h(i)?.[u],l=(i,n)=>(i&&(i[u]=n),i);var a=class i{modal;overlay;area;container;content;#t={};#i={};#e="hidden";static find=f;get state(){return this.#e}get params(){return this.#t}clone(n){let o=this.content.cloneNode(!0);return o.id=n.id??(o.id||"modal").replace(/#+$/,"")+(n.suffix??"_copy"),new i({...this.#t,...this.#i,content:o,...n,parent:this})}constructor(n){n={zIndex:1e3,duration:0,container:"body",overlay:!0,overlay_shading:.5,overlay_blur:"5px",overlay_scroll_lock:!0,content:"<div></div>",location:"center center",trigger:null,close_by_overlay:!0,close_by_esc:!0,auto_close:-1,allow_interrupt:!1,before_show:()=>{},on_show:()=>{},before_hide:()=>{},on_hide:()=>{},before_init:()=>{},on_init:()=>{},...n};let o,e,c;for(let[t,r]of Object.entries(n))typeof r=="function"?(this[t]=r.bind(this),this.#i[t]=r):this.#t[t]=r;this.before_init(this.#t),this.modal=document.createElement("modal"),l(this.modal,this),Object.assign(this.modal.style,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",zIndex:this.#t.zIndex,transition:`all ${this.#t.duration}s`,pointerEvents:"none",display:"none",overflow:"hidden"}),this.modal.setAttribute("state","hidden");try{h(this.#t.container).append(this.modal)}catch{throw new Error("\u041D\u0435\u0443\u0434\u0430\u0447\u043D\u0430\u044F \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043C\u043E\u0434\u0430\u043B\u044C\u043D\u043E\u0435 \u043E\u043A\u043D\u043E \u0432 \u0443\u043A\u0430\u0437\u0430\u043D\u043D\u044B\u0439 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440")}this.#t.overlay&&(this.overlay=document.createElement("modal-overlay"),l(this.overlay,this),Object.assign(this.overlay.style,{position:"absolute",top:"0",left:"0",right:"0",bottom:"0",backgroundColor:`rgba(0, 0, 0, ${this.#t.overlay_shading})`,backdropFilter:`blur(${this.#t.overlay_blur})`,zIndex:++this.#t.zIndex,transition:"inherit"}),this.modal.append(this.overlay));let s=(this.#t.location||"").toLowerCase().split(/\s+/);this.area=document.createElement("modal-area"),l(this.area,this),Object.assign(this.area.style,{position:"absolute",top:"0",left:"0",right:"0",bottom:"0",overflowY:"auto",overflowX:"clip",display:"flex",alignItems:"flex-start",justifyContent:s.includes("left")?"flex-start":s.includes("right")?"flex-end":"center",zIndex:++this.#t.zIndex,pointerEvents:"all",transition:"inherit"}),this.modal.append(this.area),this.#t.close_by_overlay&&this.area.addEventListener("click",t=>{this.container.contains(t.target)||this.hide(t)}),this.container=document.createElement("modal-container"),l(this.container,this),Object.assign(this.container.style,{position:"relative",flexShrink:"0",width:"max-content",height:"max-content",maxWidth:"100vw",zIndex:++this.#t.zIndex,transition:"inherit",pointerEvents:"all",marginTop:s.includes("top")?"0":"auto",marginBottom:s.includes("bottom")?"0":"auto",marginLeft:s.includes("left")?"0":"auto",marginRight:s.includes("right")?"0":"auto"}),this.area.append(this.container);try{this.content=h(this.#t.content)??new DOMParser().parseFromString(this.#t.content,"text/html").body.firstElementChild}catch{throw new Error("\u041D\u0435\u0443\u0434\u0430\u0447\u043D\u0430\u044F \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043F\u0435\u0440\u0435\u0434\u0430\u043D\u043D\u044B\u0439 \u043A\u043E\u043D\u0442\u0435\u043D\u0442 \u0432 \u043C\u043E\u0434\u0430\u043B\u044C\u043D\u043E\u0435 \u043E\u043A\u043D\u043E")}this.container.append(this.content),l(this.content,this),this.content.style.transition="inherit",this.content.querySelectorAll('[action="close"]').forEach(t=>{t.addEventListener("click",()=>this.hide())});let d=t=>{t.before_func(t.data),clearTimeout(o),this.modal.style.display="flex",requestAnimationFrame(()=>{this.#e=t.process,this.modal.setAttribute("state",this.#e),requestAnimationFrame(()=>{o=setTimeout(()=>{this.#e=t.final,this.modal.setAttribute("state",this.#e),t.hide&&(this.modal.style.display="none"),t.after_func(t.data)},this.#t.duration*1e3)})})};this.show=(t=null)=>{(this.#e=="hidden"||this.#t.allow_interrupt&&this.#e=="hiding")&&(d({before_func:this.before_show,after_func:this.on_show,process:"showing",final:"shown",hide:!1,data:t}),this.#t.overlay_scroll_lock&&this.overlay&&(c=document.documentElement.style.scrollBehavior,e=document.body.style,e={position:e.position,top:e.top,left:e.left,width:e.width,scroll_Y:window.scrollY||document.documentElement.scrollTop,scroll_X:window.scrollX||document.documentElement.scrollLeft},document.documentElement.style.scrollBehavior="unset",Object.assign(document.body.style,{position:"fixed",width:"100vw",top:`-${e.scroll_Y}px`,left:`-${e.scroll_X}px`})),this.#t.auto_close>0&&(clearTimeout(o),o=setTimeout(()=>{this.hide()},this.#t.auto_close*1e3)))},this.hide=(t=null)=>{(this.#e=="shown"||this.#t.allow_interrupt&&this.#e=="showing")&&(d({before_func:this.before_hide,after_func:this.on_hide,process:"hiding",final:"hidden",hide:!0,data:t}),clearTimeout(o),o=setTimeout(()=>{e&&(Object.assign(document.body.style,e),window.scrollTo(e.scroll_X,e.scroll_Y)),c!=null&&(document.documentElement.style.scrollBehavior=c)},this.#t.duration*1e3))},this.#t.close_by_esc&&document.addEventListener("keydown",t=>{(t.code==="Escape"||t.keyCode===27)&&this.hide(t)}),this.#t.trigger&&document.querySelectorAll(this.#t.trigger).forEach(t=>{t.addEventListener("click",()=>this.show(t))}),this.on_init(this.#t)}};export{a as default};
1
+ var u=Symbol(),m=Symbol(),c=i=>{try{return i instanceof Element?i:document.querySelector(i)}catch{return}};var f=i=>c(i)?.[u],r=(i,n)=>(i&&(i[u]=n),i);var a=class i{modal;overlay;area;container;content;#t={};#i={};#e="hidden";static find=f;get state(){return this.#e}get params(){return this.#t}clone(n){let o=this.content.cloneNode(!0);return o.id=n.id??(o.id||"modal").replace(/#+$/,"")+(n.suffix??"_copy"),new i({...this.#t,...this.#i,content:o,...n,parent:this})}constructor(n){n={zIndex:1e3,duration:0,container:"body",overlay:!0,overlay_shading:.5,overlay_blur:"5px",overlay_scroll_lock:!0,content:"<div></div>",location:"center center",trigger:null,close_by_overlay:!0,close_by_esc:!0,auto_close:-1,allow_interrupt:!1,before_show:()=>{},on_show:()=>{},before_hide:()=>{},on_hide:()=>{},before_init:()=>{},on_init:()=>{},...n};let o,e,h;for(let[t,l]of Object.entries(n))typeof l=="function"?(this[t]=l.bind(this),this.#i[t]=l):this.#t[t]=l;this.before_init(this.#t),this.modal=document.createElement("modal"),r(this.modal,this),Object.assign(this.modal.style,{position:"fixed",top:"0",left:"0",right:"0",bottom:"0",zIndex:this.#t.zIndex,transition:`all ${this.#t.duration}s`,pointerEvents:"none",display:"none",overflow:"hidden"}),this.modal.setAttribute("state","hidden");try{c(this.#t.container).append(this.modal)}catch{throw new Error("\u041D\u0435\u0443\u0434\u0430\u0447\u043D\u0430\u044F \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043C\u043E\u0434\u0430\u043B\u044C\u043D\u043E\u0435 \u043E\u043A\u043D\u043E \u0432 \u0443\u043A\u0430\u0437\u0430\u043D\u043D\u044B\u0439 \u043A\u043E\u043D\u0442\u0435\u0439\u043D\u0435\u0440")}this.#t.overlay&&(this.overlay=document.createElement("modal-overlay"),r(this.overlay,this),Object.assign(this.overlay.style,{position:"absolute",top:"0",left:"0",right:"0",bottom:"0",backgroundColor:`rgba(0, 0, 0, ${this.#t.overlay_shading})`,backdropFilter:`blur(${this.#t.overlay_blur})`,zIndex:++this.#t.zIndex,transition:"inherit"}),this.modal.append(this.overlay));let s=(this.#t.location||"").toLowerCase().split(/\s+/);this.area=document.createElement("modal-area"),r(this.area,this),Object.assign(this.area.style,{position:"absolute",top:"0",left:"0",right:"0",bottom:"0",overflowY:"auto",overflowX:"clip",display:"flex",alignItems:"flex-start",justifyContent:s.includes("left")?"flex-start":s.includes("right")?"flex-end":"center",zIndex:++this.#t.zIndex,pointerEvents:"all",transition:"inherit"}),this.modal.append(this.area),this.#t.close_by_overlay&&this.area.addEventListener("click",t=>{this.container.contains(t.target)||this.hide(t)}),this.container=document.createElement("modal-container"),r(this.container,this),Object.assign(this.container.style,{position:"relative",flexShrink:"0",width:"max-content",height:"max-content",maxWidth:"100vw",zIndex:++this.#t.zIndex,transition:"inherit",pointerEvents:"all",marginTop:s.includes("top")?"0":"auto",marginBottom:s.includes("bottom")?"0":"auto",marginLeft:s.includes("left")?"0":"auto",marginRight:s.includes("right")?"0":"auto"}),this.area.append(this.container);try{this.content=c(this.#t.content)??new DOMParser().parseFromString(this.#t.content,"text/html").body.firstElementChild}catch{throw new Error("\u041D\u0435\u0443\u0434\u0430\u0447\u043D\u0430\u044F \u043F\u043E\u043F\u044B\u0442\u043A\u0430 \u0432\u0441\u0442\u0430\u0432\u0438\u0442\u044C \u043F\u0435\u0440\u0435\u0434\u0430\u043D\u043D\u044B\u0439 \u043A\u043E\u043D\u0442\u0435\u043D\u0442 \u0432 \u043C\u043E\u0434\u0430\u043B\u044C\u043D\u043E\u0435 \u043E\u043A\u043D\u043E")}this.container.append(this.content),r(this.content,this),this.content.style.transition="inherit",this.content.querySelectorAll('[action="close"]').forEach(t=>{t.addEventListener("click",()=>this.hide())});let d=t=>{t.before_func(t.data),clearTimeout(o),this.modal.style.display="flex",requestAnimationFrame(()=>{this.#e=t.process,this.modal.setAttribute("state",this.#e),requestAnimationFrame(()=>{o=setTimeout(()=>{this.#e=t.final,this.modal.setAttribute("state",this.#e),t.hide&&(this.modal.style.display="none"),t.after_func(t.data)},this.#t.duration*1e3)})})};this.show=(t=null)=>{(this.#e=="hidden"||this.#t.allow_interrupt&&this.#e=="hiding")&&(d({before_func:this.before_show,after_func:this.on_show,process:"showing",final:"shown",hide:!1,data:t}),this.#t.overlay_scroll_lock&&this.overlay&&(h=document.documentElement.style.scrollBehavior,e=document.body.style,e={position:e.position,top:e.top,left:e.left,width:e.width,scroll_Y:window.scrollY||document.documentElement.scrollTop,scroll_X:window.scrollX||document.documentElement.scrollLeft},document.documentElement.style.scrollBehavior="unset",Object.assign(document.body.style,{position:"fixed",width:"100vw",top:`-${e.scroll_Y}px`,left:`-${e.scroll_X}px`})),this.#t.auto_close>0&&(clearTimeout(o),o=setTimeout(()=>{this.hide()},this.#t.auto_close*1e3)))},this.hide=(t=null)=>{(this.#e=="shown"||this.#t.allow_interrupt&&this.#e=="showing")&&(d({before_func:this.before_hide,after_func:this.on_hide,process:"hiding",final:"hidden",hide:!0,data:t}),clearTimeout(o),o=setTimeout(()=>{e&&(Object.assign(document.body.style,e),window.scrollTo(e.scroll_X,e.scroll_Y)),h!=null&&(document.documentElement.style.scrollBehavior=h)},this.#t.duration*1e3))},this.#t.close_by_esc&&document.addEventListener("keydown",t=>{(t.code==="Escape"||t.keyCode===27)&&this.hide(t)}),this.#t.trigger&&document.querySelectorAll(this.#t.trigger).forEach(t=>{t.addEventListener("click",()=>this.show(t))}),this.on_init(this.#t)}};export{a as default};