14 lines
39 KiB
JavaScript
14 lines
39 KiB
JavaScript
|
// Datastar v1.0.0-beta.7
|
||
|
var Ue=/🖕JS_DS🚀/.source,ie=Ue.slice(0,5),Ce=Ue.slice(4),O="datastar";var Be="Datastar-Request",he=300,je=1e3,Ke="type module",ve=!1,Je=!1,ze=!0,W={Morph:"morph",Inner:"inner",Outer:"outer",Prepend:"prepend",Append:"append",Before:"before",After:"after",UpsertAttributes:"upsertAttributes"},Ye=W.Morph,k={MergeFragments:"datastar-merge-fragments",MergeSignals:"datastar-merge-signals",RemoveFragments:"datastar-remove-fragments",RemoveSignals:"datastar-remove-signals",ExecuteScript:"datastar-execute-script"};var M=(r=>(r[r.Attribute=1]="Attribute",r[r.Watcher=2]="Watcher",r[r.Action=3]="Action",r))(M||{});var oe=`${O}-signals`;var j=t=>t.trim()==="true",se=t=>t.replace(/[A-Z]+(?![a-z])|[A-Z]/g,(e,n)=>(n?"-":"")+e.toLowerCase()),B=t=>se(t).replace(/-./g,e=>e[1].toUpperCase()),Le=t=>se(t).replace(/-/g,"_"),vn=t=>B(t).replace(/^./,e=>e[0].toUpperCase()),ye=t=>new Function(`return Object.assign({}, ${t})`)(),K=t=>t.startsWith("$")?t.slice(1):t,yn={kebab:se,snake:Le,pascal:vn};function V(t,e){for(let n of e.get("case")||[]){let r=yn[n];r&&(t=r(t))}return t}var bn="computed",Xe={type:1,name:bn,keyReq:1,valReq:1,onLoad:({key:t,mods:e,signals:n,genRX:r})=>{t=V(t,e);let i=r();n.setComputed(t,i)}};var Qe={type:1,name:"signals",removeOnLoad:()=>!0,onLoad:t=>{let{key:e,mods:n,signals:r,value:i,genRX:s}=t,l=n.has("ifmissing");if(e!==""){let u=V(e,n),g=i===""?i:s()();l?r.upsertIfMissing(u,g):r.setValue(u,g)}else{let u=ye(t.value);t.value=JSON.stringify(u);let T=s()();r.merge(T,l)}}};var Ze={type:1,name:"star",keyReq:2,valReq:2,onLoad:()=>{alert("YOU ARE PROBABLY OVERCOMPLICATING IT")}};var ae=class{#e=0;#n;constructor(e=O){this.#n=e}with(e){if(typeof e=="string")for(let n of e.split(""))this.with(n.charCodeAt(0));else this.#e=(this.#e<<5)-this.#e+e;return this}get value(){return this.#n+Math.abs(this.#e).toString(36)}};function be(t){if(t.id)return t.id;let e=new ae,n=t;for(;n;){if(n.id){e.with(n.id);break}let r=n?.parentNode;r?e.with([...r.children].indexOf(n)):e.with(n.tagName),n=r}return e.value}function le(t,e){if(!t||!(t instanceof HTMLElement||t instanceof SVGElement))return null;let n=t.dataset;if("starIgnore"in n)return null;"starIgnore__self"in n||e(t);let r=t.firstElementChild;for(;r;)le(r,e),r=r.nextElementSibling}function Se(t,e){return(...n)=>{setTimeout(()=>{t(...n)},e)}}function et(t,e,n=!1,r=!0){let i=-1,s=()=>i&&clearTimeout(i);return(...l)=>{s(),n&&!i&&t(...l),i=setTimeout(()=>{r&&t(...l),s()},e)}}function tt(t,e,n=!0,r=!1){let i=!1;return(...s)=>{i||(n&&t(...s),i=!0,setTimeout(()=>{i=!1,r&&t(...s)},e))}}var Sn="https://data-star.dev/errors";function Ie(t,e,n={}){let r=new Error;r.name=`${O} ${t} error`;let i=Le(e),s=new URLSearchParams({metadata:JSON.stringify(n)}).toString(),l=JSON.stringify(n,null,2);return r.message=`${e}
|
||
|
More info: ${Sn}/${t}/${i}?${s}
|
||
|
Context: ${l}`,r}function q(t,e,n={}){return Ie("internal",e,Object.assign({from:t},n))}function H(t,e,n={}){let r={plugin:{name:e.plugin.name,type:M[e.plugin.type]}};return Ie("init",t,Object.assign(r,n))}function N(t,e,n={}){let r={plugin:{name:e.plugin.name,type:M[e.plugin.type]},element:{id:e.el.id,tag:e.el.tagName},expression:{rawKey:e.rawKey,key:e.key,value:e.value,validSignals:e.signals.paths(),fnContent:e.fnContent}};return Ie("runtime",t,Object.assign(r,n))}var X="preact-signals",Tn=Symbol.for("preact-signals"),$=1,Q=2,ce=4,ee=8,Te=16,Z=32;function Ve(){Ae++}function Oe(){if(Ae>1){Ae--;return}let t,e=!1;for(;ue!==void 0;){let n=ue;for(ue=void 0,De++;n!==void 0;){let r=n._nextBatchedEffect;if(n._nextBatchedEffect=void 0,n._flags&=~Q,!(n._flags&ee)&&rt(n))try{n._callback()}catch(i){e||(t=i,e=!0)}n=r}}if(De=0,Ae--,e)throw t}var P;var ue,Ae=0,De=0,Ee=0;function nt(t){if(P===void 0)return;let e=t._node;if(e===void 0||e._target!==P)return e={_version:0,_source:t,_prevSource:P._sources,_nextSource:void 0,_target:P,_prevTarget:void 0,_nextTarget:void 0,_rollbackNode:e},P._sources!==void 0&&(P._sources._nextSource=e),P._sources=e,t._node=e,P._flags&Z&&t._subscribe(e),e;if(e._version===-1)return e._version=0,e._nextSource!==void 0&&(e._nextSource._prevSource=e._prevSource,e._prevSource!==void 0&&(e._prevSource._nextSource=e._nextSource),e._prevSource=P._sources,e._nextSource=void 0,P._sources._nextSource=e,P._sources=e),e}function L(t){this._value=t,this._version=0,this._node=void 0,this._targets=void 0}L.prototype.brand=Tn;L.prototype._refresh=()=>!0;L.prototype._subscribe=function(t){this._targets!==t&&t._prevTarget===void 0&&(t._nextTarget=this._targets,this._targets!==void 0&&(this._targets._prevTarget=t),this._targets=t)};L.prototype._unsubscribe=function(t){if(this._targets!==void 0){let e=t._prevTarget,n=t._nextTarget;e!==void 0&&(e._nextTarget=n,t._prevTarget=void 0),n!==void 0&&(n._prevTarget=e,t._nextTarget=void 0),t===this._targets&&(this._targets=n)}};L.prototype.subscribe=function(t){return _e(()=>{let e=this.value,n=P;P=void 0;try{t(e)}finally{P=n}})};L.prototype.valueOf=function(){return this.value};L.prototype.toString=function(){return`${this.value}`};L.prototype.toJSON=function(){return this.value};L.prototype.peek=function(){let t=P;P=void 0;try{return this.value}finally{P=t}};Object.defineProperty(L.prototype,"value",{get(){let t=nt(this);return t!==void 0&&(t._version=this._version),this._value},set(t){if(t!==this._value){if(De>100)throw q(X,"SignalCycleDetected");let e=this._value,n=t;this._value=t,this._version++,Ee++,Ve();try{for(let r=this._targets;r!==void 0;r=r._nextTarget)r._target._notify()}finally{Oe()}this?._onChange({old:e,revised:n})}}});function rt(t){for(let e=t._sources;e!==void 0;e=e._nextSource)if(e._source._version!==e._version||!e._source._refresh()||e._source._version!==e._version)return!0;return!1}function it(t){for(let e=t._sources;e!==void 0;e=e._nextSource){let n=e._source._node;if(n!==void 0&&(e._rollbackNode=n),e._source._node=e,e._version=-1,e._nextSource===void 0){t._sources=e;break}}}function ot(t){let e=t._sources,n;for(;e!==void 0;){let r=e._prevSource;e._version===-1?(e._source._unsubscribe(e),r!==void 0&&(r._nextSource=e._nextSource),e._nextSource!==void 0&&(e._nextSource._prevSource=r)):n=e,e._source._node=e._rollbackNode,e._rollbackNode!==void 0&&(e._rollbackNode=void 0),e=r}t._sources=n}function z(t){L.call(this,void 0),this._fn=t,this._sources=void 0,this._globalVersion=Ee-1,this._flags=ce}z.prototype=new L;z.prototype._refresh=function(){if(this._flags&=~Q,this._flags&$)return!1;if((this._flags&(ce|Z))===Z||(this._flags&=~ce,this._globalVersion===Ee))return!0;if(this._globalVersion=Ee,this._flags|=$,this._version>0&&!rt(this))return this._flags&=~$,!0;let t=P;try{it(this),P=this;let e=this._fn();(this._flags&Te||this._value!==e||this._version===0)&&(this._value=e,this._flags&=~Te,this._version++)}catch(e){this._value=e,this._flags|=Te,this._version++}return P=t,ot(this),this._flags&=~$,!0};z.prototype._subscribe=function(t){if(this._targets===void 0){this._flags|
|
||
|
`)}let l=new Map,u=new RegExp(`(?:${ie})(.*?)(?:${Ce})`,"gm");for(let S of r.matchAll(u)){let E=S[1],v=new ae("dsEscaped").with(E).value;l.set(v,E),r=r.replace(ie+E+Ce,v)}let g=/@(\w*)\(/gm,T=r.matchAll(g),b=new Set;for(let S of T)b.add(S[1]);let w=new RegExp(`@(${Object.keys(this.#r).join("|")})\\(`,"gm");r=r.replaceAll(w,"ctx.actions.$1.fn(ctx,");let y=e.signals.paths();if(y.length){let S=new RegExp(`\\$(${y.join("|")})(\\W|$)`,"gm");r=r.replaceAll(S,"ctx.signals.signal('$1').value$2")}for(let[S,E]of l)r=r.replace(S,E);let A=`return (()=> {
|
||
|
${r}
|
||
|
})()`;e.fnContent=A;try{let S=new Function("ctx",...n,A);return(...E)=>{try{return S(e,...E)}catch(v){throw N("ExecuteExpression",e,{error:v.message})}}}catch(S){throw N("GenerateExpression",e,{error:S.message})}}};var pt=new Re;pt.load(Ze,Qe,Xe);var Fe=pt;async function _n(t,e){let n=t.getReader(),r;for(;!(r=await n.read()).done;)e(r.value)}function xn(t){let e,n,r,i=!1;return function(l){e===void 0?(e=l,n=0,r=-1):e=wn(e,l);let u=e.length,g=0;for(;n<u;){i&&(e[n]===10&&(g=++n),i=!1);let T=-1;for(;n<u&&T===-1;++n)switch(e[n]){case 58:r===-1&&(r=n-g);break;case 13:i=!0;case 10:T=n;break}if(T===-1)break;t(e.subarray(g,T),r),g=n,r=-1}g===u?e=void 0:g!==0&&(e=e.subarray(g),n-=g)}}function Rn(t,e,n){let r=mt(),i=new TextDecoder;return function(l,u){if(l.length===0)n?.(r),r=mt();else if(u>0){let g=i.decode(l.subarray(0,u)),T=u+(l[u+1]===32?2:1),b=i.decode(l.subarray(T));switch(g){case"data":r.data=r.data?`${r.data}
|
||
|
${b}`:b;break;case"event":r.event=b;break;case"id":t(r.id=b);break;case"retry":{let w=Number.parseInt(b,10);Number.isNaN(w)||e(r.retry=w);break}}}}}function wn(t,e){let n=new Uint8Array(t.length+e.length);return n.set(t),n.set(e,t.length),n}function mt(){return{data:"",event:"",id:"",retry:void 0}}var Mn="text/event-stream",gt="last-event-id";function ht(t,e,{signal:n,headers:r,onopen:i,onmessage:s,onclose:l,onerror:u,openWhenHidden:g,fetch:T,retryInterval:b=1e3,retryScaler:w=2,retryMaxWaitMs:y=3e4,retryMaxCount:A=10,...S}){return new Promise((E,v)=>{let p=0,o={...r};o.accept||(o.accept=Mn);let d;function c(){d.abort(),document.hidden||_()}g||document.addEventListener("visibilitychange",c);let a=0;function h(){document.removeEventListener("visibilitychange",c),window.clearTimeout(a),d.abort()}n?.addEventListener("abort",()=>{h(),E()});let f=T??window.fetch,m=i??function(){};async function _(){d=new AbortController;try{let R=await f(e,{...S,headers:o,signal:d.signal});await m(R),await _n(R.body,xn(Rn(x=>{x?o[gt]=x:delete o[gt]},x=>{b=x},s))),l?.(),h(),E()}catch(R){if(!d.signal.aborted)try{let x=u?.(R)??b;window.clearTimeout(a),a=window.setTimeout(_,x),b*=w,b=Math.min(b,y),p++,p>=A?(h(),v(N("SseMaxRetries",t,{retryMaxCount:A}))):console.error(`Datastar failed to reach ${S.method}: ${e.toString()} retry in ${x}ms`)}catch(x){h(),v(x)}}}_()})}var ne=`${O}-sse`,He=`${O}-settling`,Y=`${O}-swapping`,we="started",Me="finished",vt="error",yt="retrying";function G(t,e){document.addEventListener(ne,n=>{if(n.detail.type!==t)return;let{argsRaw:r}=n.detail;e(r)})}function de(t,e){document.dispatchEvent(new CustomEvent(ne,{detail:{type:t,argsRaw:e}}))}var bt=t=>`${t}`.includes("text/event-stream"),U=async(t,e,n,r)=>{let{el:{id:i},el:s,signals:l}=t,{headers:u,contentType:g,includeLocal:T,selector:b,openWhenHidden:w,retryInterval:y,retryScaler:A,retryMaxWaitMs:S,retryMaxCount:E,abort:v}=Object.assign({headers:{},contentType:"json",includeLocal:!1,selector:null,openWhenHidden:!1,retryInterval:je,retryScaler:2,retryMaxWaitMs:3e4,retryMaxCount:10,abort:void 0},r),p=e.toLowerCase(),o=()=>{};try{if(de(we,{elId:i}),!n?.length)throw N("SseNoUrlProvided",t,{action:p});let d={};d[Be]=!0,g==="json"&&(d["Content-Type"]="application/json");let c=Object.assign({},d,u),a={method:e,headers:c,openWhenHidden:w,retryInterval:y,retryScaler:A,retryMaxWaitMs:S,retryMaxCount:E,signal:v,onopen:async m=>{if(m.status>=400){let _=m.status.toString();de(vt,{status:_})}},onmessage:m=>{if(!m.event.startsWith(O))return;let _=m.event,R={},x=m.data.split(`
|
||
|
`);for(let I of x){let D=I.indexOf(" "),Ge=I.slice(0,D),ge=R[Ge];ge||(ge=[],R[Ge]=ge);let hn=I.slice(D+1).trim();ge.push(hn)}let C={};for(let[I,D]of Object.entries(R))C[I]=D.join(`
|
||
|
`);de(_,C)},onerror:m=>{if(bt(m))throw N("InvalidContentType",t,{url:n});m&&(console.error(m.message),de(yt,{message:m.message}))}},h=new URL(n,window.location.origin),f=new URLSearchParams(h.search);if(g==="json"){let m=l.JSON(!1,!T);e==="GET"?f.set(O,m):a.body=m}else if(g==="form"){let m=b?document.querySelector(b):s.closest("form");if(m===null)throw b?N("SseFormNotFound",t,{action:p,selector:b}):N("SseClosestFormNotFound",t,{action:p});if(s!==m){let R=x=>x.preventDefault();m.addEventListener("submit",R),o=()=>m.removeEventListener("submit",R)}if(!m.checkValidity()){m.reportValidity(),o();return}let _=new FormData(m);if(e==="GET"){let R=new URLSearchParams(_);for(let[x,C]of R)f.set(x,C)}else a.body=_}else throw N("SseInvalidContentType",t,{action:p,contentType:g});h.search=f.toString();try{await ht(t,h.toString(),a)}catch(m){if(!bt(m))throw N("SseFetchFailed",t,{method:e,url:n,error:m})}}finally{de(Me,{elId:i}),o()}};var St={type:3,name:"delete",fn:async(t,e,n)=>U(t,"DELETE",e,{...n})};var Tt={type:3,name:"get",fn:async(t,e,n)=>U(t,"GET",e,{...n})};var At={type:3,name:"patch",fn:async(t,e,n)=>U(t,"PATCH",e,{...n})};var Et={type:3,name:"post",fn:async(t,e,n)=>U(t,"POST",e,{...n})};var _t={type:3,name:"put",fn:async(t,e,n)=>U(t,"PUT",e,{...n})};var xt={type:1,name:"indicator",keyReq:3,valReq:3,onLoad:({el:t,key:e,mods:n,signals:r,value:i})=>{let s=e?V(e,n):K(i),l=r.upsertIfMissing(s,!1),u=g=>{let{type:T,argsRaw:{elId:b}}=g.detail;if(b===t.id)switch(T){case we:l.value=!0;break;case Me:l.value=!1;break}};return document.addEventListener(ne,u),()=>{document.removeEventListener(ne,u)}}};var Rt={type:2,name:k.ExecuteScript,onGlobalInit:async t=>{G(k.ExecuteScript,({autoRemove:e=`${ze}`,attributes:n=Ke,script:r})=>{let i=j(e);if(!r?.length)throw H("NoScriptProvided",t);let s=document.createElement("script");for(let l of n.split(`
|
||
|
`)){let u=l.indexOf(" "),g=u?l.slice(0,u):l,T=u?l.slice(u):"";s.setAttribute(g.trim(),T.trim())}s.text=r,document.head.appendChild(s),i&&s.remove()})}};var pe=document,J=!!pe.startViewTransition;var wt=function(){"use strict";let t=()=>{},e={morphStyle:"outerHTML",callbacks:{beforeNodeAdded:t,afterNodeAdded:t,beforeNodeMorphed:t,afterNodeMorphed:t,beforeNodeRemoved:t,afterNodeRemoved:t,beforeAttributeUpdated:t},head:{style:"merge",shouldPreserve:y=>y.getAttribute("im-preserve")==="true",shouldReAppend:y=>y.getAttribute("im-re-append")==="true",shouldRemove:t,afterHeadMorphed:t},restoreFocus:!0};function n(y,A,S={}){y=b(y);let E=w(A),v=T(y,E,S),p=i(v,()=>u(v,y,E,o=>o.morphStyle==="innerHTML"?(s(o,y,E),Array.from(y.childNodes)):r(o,y,E)));return v.pantry.remove(),p}function r(y,A,S){let E=w(A),v=Array.from(E.childNodes),p=v.indexOf(A),o=v.length-(p+1);return s(y,E,S,A,A.nextSibling),v=Array.from(E.childNodes),v.slice(p,v.length-o)}function i(y,A){if(!y.config.restoreFocus)return A();let S=document.activeElement;if(!(S instanceof HTMLInputElement||S instanceof HTMLTextAreaElement))return A();let{id:E,selectionStart:v,selectionEnd:p}=S,o=A();return E&&E!==document.activeElement?.id&&(S=y.target.querySelector(`#${E}`),S?.focus()),S&&v&&p&&S.setSelectionRange(v,p),o}let s=function(){function y(c,a,h,f=null,m=null){a instanceof HTMLTemplateElement&&h instanceof HTMLTemplateElement&&(a=a.content,h=h.content),f||=a.firstChild;for(let _ of h.childNodes){if(f&&f!=m){let x=S(c,_,f,m);if(x){x!==f&&v(c,f,x),l(x,_,c),f=x.nextSibling;continue}}if(_ instanceof Element&&c.persistentIds.has(_.id)){let x=p(a,_.id,f,c);l(x,_,c),f=x.nextSibling;continue}let R=A(a,_,f,c);R&&(f=R.nextSibling)}for(;f&&f!=m;){let _=f;f=f.nextSibling,E(c,_)}}function A(c,a,h,f){if(f.callbacks.beforeNodeAdded(a)===!1)return null;if(f.idMap.has(a)&&a instanceof Element){let m=document.createElement(a.tagName);return c.insertBefore(m,h),l(m,a,f),f.callbacks.afterNodeAdded(m),m}else{let m=document.importNode(a,!0);return c.insertBefore(m,h),f.callbacks.afterNodeAdded(m),m}}let S=function(){function c(f,m,_,R){let x=null,C=m.nextSibling,I=0,D=_;for(;D&&D!=R;){if(h(D,m)){if(a(f,D,m))return D;x===null&&(f.idMap.has(D)||(x=D))}x===null&&C&&h(D,C)&&(I++,C=C.nextSibling,I>=2&&(x=void 0)),D=D.nextSibling}return x||null}function a(f,m,_){let R=f.idMap.get(m),x=f.idMap.get(_);if(!x||!R)return!1;for(let C of R)if(x.has(C))return!0;return!1}function h(f,m){let _=f,R=m;return _.nodeType===R.nodeType&&_.tagName===R.tagName&&(!_.id||_.id===R.id)}return c}();function E(c,a){if(c.idMap.has(a)&&a instanceof Element)d(c.pantry,a,null);else{if(c.callbacks.beforeNodeRemoved(a)===!1)return;a.parentNode?.removeChild(a),c.callbacks.afterNodeRemoved(a)}}function v(c,a,h){let f=a;for(;f&&f!==h;){let m=f;f=f.nextSibling,E(c,m)}return f}function p(c,a,h,f){let m=f.target.querySelector(`#${a}`)||f.pantry.querySelector(`#${a}`);return o(m,f),d(c,m,h),m}function o(c,a){let h=c.id;for(;c=c.parentNode;){let f=a.idMap.get(c);f&&(f.delete(h),f.size||a.idMap.delete(c))}}function d(c,a,h){if(c.moveBefore)try{c.moveBefore(a,h)}catch{c.insertBefore(a,h)}else c.insertBefore(a,h)}return y}(),l=function(){function y(o,d,c){return c.ignoreActive&&o===document.activeElement?null:(c.callbacks.beforeNodeMorphed(o,d)===!1||(o instanceof HTMLHeadElement&&c.head.ignore||(o instanceof HTMLHeadElement&&c.head.style!=="morph"?g(o,d,c):(A(o,d,c),p(o,c)||s(c,o,d))),c.callbacks.afterNodeMorphed(o,d)),o)}function A(o,d,c){let a=d.nodeType;if(a===1){let h=o,f=d,m=h.attributes,_=f.attributes;for(let R of _)v(R.name,h,"update",c)||h.getAttribute(R.name)!==R.value&&h.setAttribute(R.name,R.value);for(let R=m.length-1;0<=R;R--){let x=m[R];if(x&&!f.hasAttribute(x.name)){if(v(x.name,h,"remove",c))continue;h.removeAttribute(x.name)}}p(h,c)||S(h,f,c)}(a===8||a===3)&&o.nodeValue!==d.nodeValue&&(o.nodeValue=d.nodeValue)}function S(o,d,c){if(o instanceof HTMLInputElement&&d instanceof HTMLInputElement&&d.type!=="file"){let a=d.value,h=o.value;E(o,d,"checked",c),E(o,d,"disabled",c),d.hasAttribute("value")?h!==a&&(v("value",o,"update",
|
||
|
`).map(r=>r.trim());if(!n?.length)throw H("NoPathsProvided",t);t.signals.remove(...n)})}};var It={type:3,name:"clipboard",fn:(t,e)=>{if(!navigator.clipboard)throw N("ClipboardNotAvailable",t);navigator.clipboard.writeText(e)}};var Dt={type:1,name:"customValidity",keyReq:2,valReq:1,onLoad:t=>{let{el:e,genRX:n,effect:r}=t;if(!(e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement))throw N("CustomValidityInvalidElement",t);let i=n();return r(()=>{let s=i();if(typeof s!="string")throw N("CustomValidityInvalidExpression",t,{result:s});e.setCustomValidity(s)})}};var Vt="once",Ot="half",kt="full",Ft={type:1,name:"intersects",keyReq:2,mods:new Set([Vt,Ot,kt]),onLoad:({el:t,rawKey:e,mods:n,genRX:r})=>{let i={threshold:0};n.has(kt)?i.threshold=1:n.has(Ot)&&(i.threshold=.5);let s=r(),l=new IntersectionObserver(u=>{for(let g of u)g.isIntersecting&&(s(),n.has(Vt)&&(l.disconnect(),delete t.dataset[e]))},i);return l.observe(t),()=>l.disconnect()}};var Ht="session",Wt={type:1,name:"persist",mods:new Set([Ht]),onLoad:({key:t,effect:e,mods:n,signals:r,value:i})=>{t=V(t,n),t===""&&(t=O);let s=n.has(Ht)?sessionStorage:localStorage,l=i.split(/\s+/).filter(T=>T!=="");l=l.map(T=>K(T));let u=()=>{let T=s.getItem(t)||"{}",b=JSON.parse(T);r.merge(b)},g=()=>{let T;l.length?T=r.subset(...l):T=r.values(),s.setItem(t,JSON.stringify(T))};return u(),e(()=>{g()})}};var qt={type:1,name:"replaceUrl",keyReq:2,valReq:1,onLoad:({effect:t,genRX:e})=>{let n=e();return t(()=>{let r=n(),i=window.location.href,s=new URL(r,i).toString();window.history.replaceState({},"",s)})}};var Ne="smooth",We="instant",qe="auto",$t="hstart",Gt="hcenter",Ut="hend",Bt="hnearest",jt="vstart",Kt="vcenter",Jt="vend",zt="vnearest",Nn="focus",Pe="center",Yt="start",Xt="end",Qt="nearest",Zt={type:1,name:"scrollIntoView",keyReq:2,valReq:2,mods:new Set([Ne,We,qe,$t,Gt,Ut,Bt,jt,Kt,Jt,zt,Nn]),onLoad:t=>{let{el:e,mods:n,rawKey:r}=t;e.tabIndex||e.setAttribute("tabindex","0");let i={behavior:Ne,block:Pe,inline:Pe};if(n.has(Ne)&&(i.behavior=Ne),n.has(We)&&(i.behavior=We),n.has(qe)&&(i.behavior=qe),n.has($t)&&(i.inline=Yt),n.has(Gt)&&(i.inline=Pe),n.has(Ut)&&(i.inline=Xt),n.has(Bt)&&(i.inline=Qt),n.has(jt)&&(i.block=Yt),n.has(Kt)&&(i.block=Pe),n.has(Jt)&&(i.block=Xt),n.has(zt)&&(i.block=Qt),!(e instanceof HTMLElement||e instanceof SVGElement))throw N("ScrollIntoViewInvalidElement",t);return e.tabIndex||e.setAttribute("tabindex","0"),e.scrollIntoView(i),n.has("focus")&&e.focus(),delete e.dataset[r],()=>{}}};var en="none",tn="display",nn={type:1,name:"show",keyReq:2,valReq:1,onLoad:({el:{style:t},genRX:e,effect:n})=>{let r=e();return n(async()=>{r()?t.display===en&&t.removeProperty(tn):t.setProperty(tn,en)})}};var rn="view-transition",on={type:1,name:"viewTransition",keyReq:2,valReq:1,onGlobalInit(){let t=!1;for(let e of document.head.childNodes)e instanceof HTMLMetaElement&&e.name===rn&&(t=!0);if(!t){let e=document.createElement("meta");e.name=rn,e.content="same-origin",document.head.appendChild(e)}},onLoad:({effect:t,el:e,genRX:n})=>{if(!J){console.error("Browser does not support view transitions");return}let r=n();return t(()=>{let i=r();if(!i?.length)return;let s=e.style;s.viewTransitionName=i})}};var sn={type:1,name:"attr",valReq:1,onLoad:({el:t,key:e,effect:n,genRX:r})=>{let i=r();return e===""?n(async()=>{let s=i();for(let[l,u]of Object.entries(s))t.setAttribute(l,u)}):(e=se(e),n(async()=>{let s=!1;try{s=i()}catch{}let l;typeof s=="string"?l=s:l=JSON.stringify(s),!l||l==="false"||l==="null"||l==="undefined"?t.removeAttribute(e):t.setAttribute(e,l)}))}};var Pn=/^data:(?<mime>[^;]+);base64,(?<contents>.*)$/,an=["change","input","keydown"],ln={type:1,name:"bind",keyReq:3,valReq:3,onLoad:t=>{let{el:e,key:n,mods:r,signals:i,value:s,effect:l}=t,u=n?V(n,r):K(s),g=()=>{},T=()=>{},b=e.tagName.toLowerCase(),w="",y=b.includes("input"),A=e.getAttribute("type"),S=b.includes("checkbox")||y&&A==="checkbox";S&&(w=!1),y&&A==="number"&&(w=0);let v=b.includes("select"),p=b.includes("radio")||y&&A==="radio",o=y&&A==="file";p&&(e.getAttribute("name")?.length||e.setAtt
|
||
|
//# sourceMappingURL=datastar-1-0-0-beta-7-aebc4a389b667764.js.map
|