@muze-labs/simplyflow 0.9.0 → 0.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +72 -16
- package/dist/simply.flow.js +458 -298
- package/dist/simply.flow.min.js +1 -1
- package/dist/simply.flow.min.js.map +4 -4
- package/package.json +29 -42
- package/src/action.mjs +1 -64
- package/src/app.mjs +1 -282
- package/src/behavior.mjs +1 -121
- package/src/bind-render.mjs +1 -0
- package/src/bind-transformers.mjs +1 -0
- package/src/bind.mjs +1 -522
- package/src/command.mjs +1 -225
- package/src/dom.mjs +1 -274
- package/src/highlight.mjs +1 -11
- package/src/include.mjs +1 -239
- package/src/{flow.mjs → index.mjs} +13 -13
- package/src/model.mjs +1 -290
- package/src/path.mjs +1 -47
- package/src/route.mjs +1 -418
- package/src/shortcut.mjs +1 -146
- package/src/state.mjs +1 -1347
- package/src/suggest.mjs +1 -68
- package/src/symbols.mjs +1 -9
- package/MUZE_ALIGNMENT.md +0 -118
- package/src/bind.render.mjs +0 -694
- package/src/bind.transformers.mjs +0 -25
package/dist/simply.flow.min.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
(()=>{var tn=Object.defineProperty;var Ee=(e,t)=>{for(var n in t)tn(e,n,{get:t[n],enumerable:!0})};var Oe={};Ee(Oe,{addTracer:()=>wn,batch:()=>E,clockEffect:()=>z,clone:()=>Le,createSignal:()=>N,destroy:()=>$,effect:()=>se,getSignal:()=>I,isSignal:()=>b,makeContext:()=>P,notifyGet:()=>S,notifySet:()=>M,raw:()=>k,registerSignal:()=>at,signal:()=>T,signals:()=>O,throttledEffect:()=>g,trace:()=>bn,untracked:()=>H});var h={ITERATE:Symbol.for("@simplyedit/simplyflow.iterate"),XRAY:Symbol.for("@simplyedit/simplyflow.xRay"),SIGNAL:Symbol.for("@simplyedit/simplyflow.Signal"),TEMPLATE:Symbol.for("@simplyedit/simplyflow.bindTemplate"),VALUE:Symbol.for("@simplyedit/simplyflow.bindValue"),LENGTH:"length",SIZE:"size"};var nn=new Set(["get","has"]),rn=new Set(["keys","values","entries","forEach",Symbol.iterator]),sn=new Set(["set","delete","clear"]),on=new Set(["add","delete","clear"]),an={entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}};function _(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function b(e){return!!(_(e)&&e[h.SIGNAL])}function k(e){return b(e)?e[h.XRAY]:e}function I(e){return b(e)?e:O.get(e)}function Z(e){return O.get(e)}function it(e,t){return e?.[t]}function cn(e,t,n){return e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?n.bind(e):n.bind(t)}function rt(e,t){let n=new Map;if(!Array.isArray(e)||t>=e.length)return n;for(let r=t;r<e.length;r++)Object.hasOwn(e,r)&&n.set(r,e[r]);return n}function ke(e,t,n,r=new Map){if(!(!Array.isArray(t)||n===t.length)){e.set(h.LENGTH,{was:n,now:t.length}),e.set(h.ITERATE,{});for(let[s,i]of r)e.set(String(s),{delete:!0,was:i,now:void 0})}}function ee(e,t){t.size&&M(e,t)}function ln(e,t,n,r){return(...s)=>{let i=e.length,a=r.apply(n,s);return i!==e.length&&M(n,P(h.LENGTH,{was:i,now:e.length})),a}}function fn(e,t,n,r,s){if(n==="set"){let[i,a]=r,c=t.has(i),o=t.get(i);return()=>{(!c||!Object.is(o,a))&&(e.set(i,{was:o,now:a}),e.set(h.ITERATE,{})),c||e.set(h.SIZE,{was:s,now:t.size})}}if(n==="delete"){let[i]=r,a=t.has(i),c=t.get(i);return()=>{a&&(e.set(i,{delete:!0,was:c,now:void 0}),e.set(h.SIZE,{was:s,now:t.size}),e.set(h.ITERATE,{}))}}if(n==="clear"){let i=s?Array.from(t.entries()):[];return()=>{if(i.length){for(let[a,c]of i)e.set(a,{delete:!0,was:c,now:void 0});e.set(h.SIZE,{was:s,now:t.size}),e.set(h.ITERATE,{})}}}return()=>{}}function un(e,t,n,r){return(...s)=>{nn.has(t)&&S(n,s[0]),rn.has(t)&&S(n,h.ITERATE);let i=e.size,a=new Map,c=sn.has(t)?fn(a,e,t,s,i):()=>{},o=r.apply(e,s);return c(),ee(n,a),o}}function hn(e,t,n,r,s){let[i]=r,a=n==="add"||n==="delete"?t.has(i):!1;return()=>{if(n==="clear"?s>0:t.size!==s||n==="delete"&&a){e.set(h.SIZE,{was:s,now:t.size});for(let o of Reflect.ownKeys(an))e.set(o,{})}}}function dn(e,t,n,r){return(...s)=>{let i=e.size,a=new Map,c=on.has(t)?hn(a,e,t,s,i):()=>{},o=r.apply(e,s);return c(),ee(n,a),o}}function pn(e,t,n,r,s){return Object.hasOwn(e,"value")&&!Object.is(n,s)||Object.hasOwn(e,"get")&&t?.get!==r?.get||Object.hasOwn(e,"set")&&t?.set!==r?.set}var mn={get(e,t,n){let r=it(e,t);return S(n,t),typeof r=="function"?Array.isArray(e)?ln(e,t,n,r):e instanceof Map?un(e,t,n,r):e instanceof Set?dn(e,t,n,r):cn(e,n,r):_(r)?T(r):r},set(e,t,n,r){let s=Object.hasOwn(e,t),i=Array.isArray(e)?e.length:void 0,a=t===h.LENGTH?rt(e,Number(n)):new Map,c=e[t];e[t]=n;let o=Object.hasOwn(e,t),l=e[t],f=new Map;return(!Object.is(c,l)||!s&&o)&&f.set(t,{was:c,now:l}),!s&&o&&f.set(h.ITERATE,{}),ke(f,e,i,a),ee(r,f),!0},has(e,t){let n=Z(e);return n&&S(n,t),Reflect.has(e,t)},deleteProperty(e,t){if(!Object.hasOwn(e,t))return!0;let r=e[t],s=Array.isArray(e)?e.length:void 0,i=Reflect.deleteProperty(e,t);if(!i)return i;let a=Z(e),c=P(t,{delete:!0,was:r,now:void 0});return c.set(h.ITERATE,{delete:!0,property:t}),ke(c,e,s),M(a,c),i},defineProperty(e,t,n){let r=Object.hasOwn(e,t),s=Object.getOwnPropertyDescriptor(e,t),i=e[t],a=Array.isArray(e)?e.length:void 0,c=t===h.LENGTH&&Object.hasOwn(n,"value")?rt(e,Number(n.value)):new Map,o=Reflect.defineProperty(e,t,n);if(!o)return o;let l=Object.hasOwn(e,t),f=Object.getOwnPropertyDescriptor(e,t),d=e[t],p=new Map;return!r&&l?(p.set(t,{was:i,now:d}),p.set(h.ITERATE,{})):r&&l&&(pn(n,s,i,f,d)&&p.set(t,{was:i,now:d}),s?.enumerable!==f?.enumerable&&p.set(h.ITERATE,{})),ke(p,e,a,c),ee(Z(e),p),o},ownKeys(e){let t=Z(e);return S(t,h.ITERATE),Reflect.ownKeys(e)}},O=new WeakMap;function ot(e,t){if(!_(e))throw new TypeError(`simplyflow/state: ${t}() expects an object, array, Map, Set, class instance, function, or DOM node; received ${typeof e}`)}function yn(e,t){if(!e||typeof e!="object")throw new TypeError(`simplyflow/state: ${t}() expects a Proxy handler object`)}function gn(e){return{...e,get(t,n,r){return n===h.XRAY?t:n===h.SIGNAL?!0:e.get?e.get(t,n,r):it(t,n)}}}function at(e,t){let n=k(e);if(ot(n,"registerSignal"),!b(t))throw new TypeError("simplyflow/state: registerSignal() expects a signal proxy");let r=O.get(n);if(r&&r!==t)throw new Error("simplyflow/state: registerSignal() target already has a different signal");return O.set(n,t),t}function N(e,t={},n){if(ot(e,"createSignal"),yn(t,"createSignal"),n!==void 0&&typeof n!="function")throw new TypeError("simplyflow/state: createSignal() expects init to be a function");if(b(e))return e;let r=I(e);if(r)return r;let s=new Proxy(e,gn(t));return at(e,s),n?.(e,s),s}function T(e={}){if(!_(e))throw new TypeError(`simplyflow/state: signal() expects an object, array, Map, Set, class instance, or function; received ${typeof e}`);return N(e,mn)}var ne=[],te=!1;function bn(e,t){if(typeof e=="function"){te=!0;try{return e()}finally{te=!1}}if(!b(e))throw new TypeError("simplyflow/state: trace() expects either a function or a signal");return Tn(e,t).map(n=>({effect:n.effectType,fn:n.effectFunction,signal:O.get(n.effectFunction)}))}function wn(e){if(!e||typeof e!="object")throw new TypeError("simplyflow/state: addTracer() expects a tracer object");if(!e.get&&!e.set)throw new Error('simplyflow/state: addTracer: missing "get" or "set" property in tracer');if(e.get&&typeof e.get!="function")throw new Error('simplyflow/state: addTracer: "get" is not a function');if(e.set&&typeof e.set!="function")throw new Error('simplyflow/state: addTracer: "set" is not a function');ne.push(e)}function ct(e,...t){for(let n of ne)n[e]?.(...t)}var Ae=new Set,X=0;function M(e,t=new Map){if(!b(e))throw new TypeError("simplyflow/state: notifySet() expects a signal as first argument");if(!(t instanceof Map))throw new TypeError("simplyflow/state: notifySet() expects context to be a Map; use makeContext()");let n=new Set;if(t.forEach((r,s)=>{for(let i of lt(e,s))En(i,s,r),n.add(i)}),!!n.size){if(X){for(let r of n)Ae.add(r);return}Te(n,e,t)}}function P(e,t){let n=new Map;if(e instanceof Map)return e.forEach((r,s)=>n.set(s,r)),n;if(e!==null&&typeof e=="object")for(let r of Reflect.ownKeys(e))n.set(r,e[r]);else n.set(e,t);return n}function En(e,t,n){e.context||(e.context=new Map),e.context.set(t,n),e.needsUpdate=!0}function kn(e){delete e.context,delete e.needsUpdate}function S(e,t){let n=w[w.length-1];!n||n.skipDependency?.(e,t)||(te&&ne.length&&ct("get",e,t),ft(e,t,n))}var U=new WeakMap,q=new WeakMap,An=new Set;function lt(e,t){return U.get(e)?.get(t)||An}function Tn(e,t){return Array.from(lt(e,t))}function ft(e,t,n){U.has(e)||U.set(e,new Map);let r=U.get(e);r.has(t)||r.set(t,new Set),r.get(t).add(n),q.has(n)||q.set(n,new Map);let s=q.get(n);s.has(t)||s.set(t,new Set),s.get(t).add(e)}function re(e){let t=q.get(e);t&&(t.forEach((n,r)=>{n.forEach(s=>{U.get(s)?.get(r)?.delete(e)})}),q.delete(e))}var w=[],F=[],Y=[],K=new WeakMap;function W(e,t){if(typeof e!="function")throw new TypeError(`simplyflow/state: ${t}() expects a function`)}function ut(e){if(F.includes(e))throw new Error("Recursive update() call",{cause:e})}function ve(e){let t=O.get(e);return t||(t=T({current:null}),O.set(e,t)),t}function ht(e,t){t instanceof Promise?t.then(n=>{e.current=n}):e.current=t}function dt(e,t,n,r,s=[e,w,Y]){if(Y.includes(t))throw new Error("Cyclical dependency in update() call",{cause:n});re(e),e.effectFunction=n,e.effectType=r,w.push(e),Y.push(t);let i;try{i=n(...s)}finally{w.pop(),Y.pop(),ht(t,i)}}function Te(e,t,n){let r=w[w.length-1];for(let s of e)s!==r&&s?.needsUpdate&&(s.scheduleClock?s.scheduleClock():(t&&te&&ne.length&&ct("set",t,n,s),s())),kn(s)}function se(e){W(e,"effect"),ut(e),F.push(e);let t=ve(e),n=function(){dt(n,t,e,se)};return n.fn=e,K.set(t,n),n(),t}function $(e){if(!b(e))throw new TypeError("simplyflow/state: destroy() expects an effect signal");let t=K.get(e);if(t){if(t.destroy?.(),re(t),t.fn){O.delete(t.fn);let n=F.findIndex(r=>r===t.fn);n!==-1&&F.splice(n,1)}K.delete(e)}}function E(e){W(e,"batch"),X++;let t;try{t=e()}finally{let n=()=>{X--,X||vn()};t instanceof Promise?t.then(n,n):n()}return t}function vn(){let e=Ae;Ae=new Set;let t=new Set,n=new Set;for(let r of e)r.scheduleClock?t.add(r):n.add(r);Te(t),Te(n)}function g(e,t){if(W(e,"throttledEffect"),!Number.isFinite(t)||t<0)throw new TypeError("simplyflow/state: throttledEffect() expects throttleTime to be a non-negative number");ut(e),F.push(e);let n=ve(e),r=0,s=!0,i=null,a=function(){let l=Date.now();if(r>l){s=!0,c();return}dt(a,n,e,g),s=!1,r=Date.now()+t,c()};function c(){if(i)return;let o=Math.max(0,r-Date.now());i=globalThis.setTimeout(()=>{i=null,s&&a()},o)}return a.fn=e,a.destroy=()=>{i&&(globalThis.clearTimeout(i),i=null),s=!1},K.set(n,a),a(),n}var J=new WeakMap;function st(e){return k(e).time}function Sn(e){if(!J.has(e)){let t={clock:e,effects:new Set,pending:new Set,time:st(e)};t.tick=function(){let r=st(e);if(r<=t.time)return;t.time=r;let s=Array.from(t.pending);t.pending.clear();for(let i of s)i.clockPending=!1,t.effects.has(i)&&i()},t.tick.effectFunction=t.tick,t.tick.effectType=z,ft(e,"time",t.tick),J.set(e,t)}return J.get(e)}function Ln(e){let t=e.clockQueue;t&&(t.pending.delete(e),t.effects.delete(e),t.effects.size||(re(t.tick),J.delete(t.clock)))}function z(e,t){if(W(e,"clockEffect"),!t||typeof t!="object"||typeof k(t).time!="number")throw new TypeError("simplyflow/state: clockEffect() expects a clock object with a numeric .time property");let n=b(t)?t:T(k(t)),r=ve(e),s=Sn(n),i=function(){re(i),i.effectFunction=e,i.effectType=z,w.push(i);let c;try{c=e(i,w)}finally{w.pop(),ht(r,c)}};return i.fn=e,i.clockQueue=s,i.skipDependency=(a,c)=>a===n&&c==="time",i.scheduleClock=()=>{i.clockPending||(i.clockPending=!0,s.pending.add(i))},i.destroy=()=>Ln(i),s.effects.add(i),K.set(r,i),i(),r}function H(e){W(e,"untracked");let t=w.length-1,n=w[t];w[t]=!1;try{return e()}finally{w[t]=n}}function On(e){if(typeof e=="boolean")return{deep:e};if(e===void 0)return{deep:!0};if(!e||typeof e!="object")throw new TypeError("simplyflow/state: clone() expects options to be a boolean or object");return{deep:e.deep!==!1}}function Mn(e){return e?.constructor?.name||Object.prototype.toString.call(e).slice(8,-1)}function Cn(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function jn(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Pn(e){if(typeof e!="string"||e==="")return!1;let t=Number(e);return Number.isInteger(t)&&t>=0&&String(t)===e}function Rn(e){return typeof e.toClone=="function"}function Se(e,t){throw new TypeError(`simplyflow/state: clone() cannot clone ${Mn(e)} at ${t}; add a toClone() method for custom objects`)}function v(e,t,n,r=()=>!1){let s=Object.getOwnPropertyDescriptors(e);for(let i of Reflect.ownKeys(s)){if(r(i)){delete s[i];continue}let a=s[i];Object.hasOwn(a,"value")||Se(e,String(i)),a.value=n(a.value,String(i))}return Object.defineProperties(t,s),t}function xn(e){return e.slice(0)}function In(e){let t=new SharedArrayBuffer(e.byteLength);return new Uint8Array(t).set(new Uint8Array(e)),t}function Nn(e,t,n){new Set([Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,typeof AggregateError>"u"?void 0:AggregateError]).has(e.constructor)||Se(e,n);let s=Object.hasOwn(e,"cause")?{cause:t(e.cause,"cause")}:void 0;if(typeof AggregateError<"u"&&e instanceof AggregateError){let i=Array.from(e.errors||[],(a,c)=>t(a,`errors.${c}`));return new AggregateError(i,e.message,s)}return new e.constructor(e.message,s)}function Le(e,t){let{deep:n}=On(t),r=new Map;function s(a,c){return n?i(a,c):k(a)}function i(a,c="value"){let o=k(a);if(!_(o))return o;if(r.has(o))return r.get(o);if(Rn(o)){let l=k(o.toClone());if(Object.is(l,o))throw new TypeError(`simplyflow/state: clone() toClone() returned the original object at ${c}`);return r.set(o,l),l}if(Array.isArray(o)){let l=new Array(o.length);return r.set(o,l),v(o,l,s,f=>f==="length")}if(Cn(o)){let l=Object.create(Object.getPrototypeOf(o));return r.set(o,l),v(o,l,s)}if(o instanceof Map){let l=new Map;return r.set(o,l),o.forEach((f,d)=>{l.set(s(d,"map key"),s(f,"map value"))}),v(o,l,s)}if(o instanceof Set){let l=new Set;return r.set(o,l),o.forEach(f=>l.add(s(f,"set value"))),v(o,l,s)}if(o instanceof Date){let l=new Date(o.getTime());return r.set(o,l),v(o,l,s)}if(o instanceof RegExp){let l=new RegExp(o.source,o.flags);return l.lastIndex=o.lastIndex,r.set(o,l),v(o,l,s,f=>f==="lastIndex")}if(o instanceof ArrayBuffer){let l=xn(o);return r.set(o,l),v(o,l,s)}if(typeof SharedArrayBuffer<"u"&&o instanceof SharedArrayBuffer){let l=In(o);return r.set(o,l),v(o,l,s)}if(o instanceof DataView){let l=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength),f=new DataView(l);return r.set(o,f),v(o,f,s)}if(jn(o)){let l=new o.constructor(o);return r.set(o,l),v(o,l,s,Pn)}if(typeof URL<"u"&&o instanceof URL){let l=new URL(o.href);return r.set(o,l),l}if(typeof URLSearchParams<"u"&&o instanceof URLSearchParams){let l=new URLSearchParams(o);return r.set(o,l),l}if(typeof File<"u"&&o instanceof File){let l=new File([o],o.name,{type:o.type,lastModified:o.lastModified});return r.set(o,l),l}if(typeof Blob<"u"&&o instanceof Blob){let l=o.slice(0,o.size,o.type);return r.set(o,l),l}if(o instanceof Error){let l=Nn(o,s,c);return r.set(o,l),v(o,l,s,f=>f==="message"||f==="cause"||f==="errors"||f==="stack")}if(typeof Node<"u"&&o instanceof Node&&typeof o.cloneNode=="function"){let l=o.cloneNode(n);return r.set(o,l),l}Se(o,c)}return i(e)}function pt(e,t){let n=e.value?.innerHTML;typeof e.value=="string"&&(n=e.value,e.value={innerHTML:n}),n&&(n=n.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'"),e.value.innerHTML=n),t(e)}function mt(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var je={};Ee(je,{findAttribute:()=>Bn,signal:()=>Me,trackDomField:()=>C,trackDomList:()=>Ce});var yt=new WeakMap,gt=new WeakMap,$n={get:(e,t,n)=>{let r=e?.[t];return S(n,t),typeof r=="function"?r.bind(e):r&&typeof r=="object"?T(r):r},set:(e,t,n,r)=>{let s=e[t];e[t]=n;let i=e[t];return Object.is(s,i)||M(r,P(t,{was:s,now:i})),!0},has:(e,t)=>{let n=I(e);return n&&S(n,t),Reflect.has(e,t)},ownKeys:e=>{let t=I(e);return t&&S(t,h.ITERATE),Reflect.ownKeys(e)}};function Me(e,t){if(b(e))return e;let n=I(e);return n||N(e,$n,(r,s)=>{Hn(r,s,t)})}function Hn(e,t,n){n||(n={characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0,childList:!0});let s=e.innerHTML,i=e.innerText;if(!gt.has(e)){let a=new MutationObserver((c,o)=>{let l={};for(let f of c)f.type==="attributes"?l[f.attributeName]=f.attributeOldValue:f.type==="subtree"||f.type==="characterData"?(e.innerHTML!=s&&(l.innerHTML=s,s=e.innerHTML),e.innerText!=i&&(l.innerText=i,i=e.innerText)):f.type==="childList"?(l.children={was:Array.from(e.children)},l.length=-1,e.innerHTML!=s&&(l.innerHTML=s,s=e.innerHTML),e.innerText!=i&&(l.innerText=i,i=e.innerText)):console.log("nothing to do for",e,f.type);for(let f in l)M(t,P(f,{was:l[f],now:e[f]}))});if(a.observe(e,n),gt.set(e,a),e.matches("input, textarea, select")){let c=e.value,o=e.checked,l=()=>{M(t,P("value",{was:c,now:e.value})),c=e.value,"checked"in e&&(M(t,P("checked",{was:o,now:e.checked})),o=e.checked)};e.addEventListener("change",l),e.matches("input, textarea")&&e.addEventListener("input",l)}}}function Ce(e){let t=this.getBindingPath(e);if(!t)throw new Error("Could not find binding path for element",{cause:e});let n=Me(e,{childList:!0});return g(()=>{let r=Array.from(n.children);H(()=>{E(()=>{let s=0,i=B(this.options.root,t),a=i.slice();for(let c of r)c.tagName!=="TEMPLATE"&&c.dataset.flowKey&&(c.dataset.flowKey!=s&&Pe(this.options.root,t+"."+s,a[c.dataset.flowKey]),s++);i.length>s&&(i.length=s)})})},50),n}function C(e,t,n,r="innerHTML",s){if(yt.has(e))return;let i=this.getBindingPath(e);if(!i)throw new Error("Could not find binding path for element",{cause:e});let a=Me(e);return yt.set(e,a),E(()=>{g(()=>{let c;if(s)for(let o of t)a[o];else c=a[r],n||(c=bt(a,...t));H(()=>{let o=B(this.options.root,i);s&&(c=s.call(this,a,o)),!(typeof c>"u")&&(n&&!Object.is(o,c)&&String(o)===c||Pe(this.options.root,i,c))})},50)}),a}function Bn(e,t){return e.closest("["+t+"]")?.getAttribute(t)}function R(e,t){return e.options.twoway||t.edit}function Et(e){if(e.templates?.length)Fn.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else this.options.renderers["*"]&&this.options.renderers["*"].call(this,e);return e}function kt(e){Array.isArray(e.value)||(e.value=[e.value]);let t=e.value.length;return e.templates?.length?Dn.call(this,e):console.error("No templates found in",e.element),e}function At(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?Un.call(this,e):console.error("No templates found in",e.element),e}function Vn(e){if(parseInt(e)==e)return!0}function Pe(e,t,n){E(()=>{let r=t.split("."),s=e,i;i=r.shift();let a=null,c=null,o=s;for(;i&&s;){if(o=s,i=decodeURIComponent(i),!(i=="0"&&!Array.isArray(s))){if(i==":key")throw new Error("setting key not yet supported");i==":value"||(Array.isArray(s)&&!Vn(i)&&typeof s[i]>"u"?(a=s[0],s=s[0][i]):(a=s,s=s[i]))}if(c=i,i=r.shift(),i&&!s){let l=parseInt(i);l>=0&&i===""+l?o[c]=[]:o[c]={},s=o[c]}}if(a&&c&&a[c]!==n)if(Array.isArray(n))a[c]=n;else if(n&&typeof n=="object"){s=a[c],s||(a[c]={},s=a[c]);for(let l in n)s[l]!==n[l]&&(s[l]=n[l])}else a[c]=n})}function Dn(e){let t=this.options.attribute,n=[t+"-field",t+"-edit",t+"-list",t+"-map",t+"-value-path"],r="["+n.join("],[")+"]",s=t+"-key",i=Array.from(e.element.querySelectorAll(":scope > ["+s+"]")),a=new Set,c=0;e.list=e.value;for(let o=0;o<e.value.length;o++){e.index=o;let l=e.list[o],f=Tt(i,a,c);if(!f){e.element.appendChild(this.applyTemplate(e));continue}let d=this.findTemplate(e.templates,l),u=f[h.VALUE]===l?f:vt(i,a,l,d,c+1);if(u){d!=u[h.TEMPLATE]?e.element.replaceChild(this.applyTemplate(e),u):(e.element.insertBefore(u,f),St(u,o,e.path,s,n,r),u[h.VALUE]=l),a.add(u),u===f&&c++;continue}e.element.insertBefore(this.applyTemplate(e),f)}for(let o of i)a.has(o)||o.remove();this.options.twoway&&Ce.call(this,e.element)}function Tt(e,t,n){for(;n<e.length;){let r=e[n];if(!t.has(r))return r;n++}}function vt(e,t,n,r,s){for(let i=s;i<e.length;i++){let a=e[i];if(!t.has(a)&&a[h.VALUE]===n&&a[h.TEMPLATE]===r)return a}}function St(e,t,n,r,s,i){let a=e.getAttribute(r),c=""+t;if(a===c)return;e.setAttribute(r,c);let o=n+"."+a,l=n+"."+c,f=Array.from(e.querySelectorAll(i));e.matches(i)&&f.unshift(e);for(let d of f)for(let p of s){let u=d.getAttribute(p);!u||u.substr(0,5)===":root"||(u===o?d.setAttribute(p,l):u.startsWith(o+".")&&d.setAttribute(p,l+u.substr(o.length)))}}function Un(e){let t=this.options.attribute,n=[t+"-field",t+"-edit",t+"-list",t+"-map",t+"-value-path"],r="["+n.join("],[")+"]",s=t+"-key",i=Array.from(e.element.querySelectorAll(":scope > ["+s+"]")),a=new Set,c=0;e.list=e.value;for(let o in e.list){e.index=o;let l=e.list[o],f=Tt(i,a,c);if(!f){e.element.appendChild(this.applyTemplate(e));continue}let d=this.findTemplate(e.templates,l),p;if(f.getAttribute(s)===o?p=f:p=qn(i,a,o,s)||vt(i,a,l,d,c),p){d!=p[h.TEMPLATE]?e.element.replaceChild(this.applyTemplate(e),p):(e.element.insertBefore(p,f),St(p,o,e.path,s,n,r),p[h.VALUE]=l),a.add(p),p===f&&c++;continue}e.element.insertBefore(this.applyTemplate(e),f)}for(let o of i)a.has(o)||o.remove()}function qn(e,t,n,r){let s=""+n;for(let i of e)if(!t.has(i)&&i.getAttribute(r)===s)return i}function Fn(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=Kn(e.element),t)if(n){if(t?.[h.TEMPLATE]!=n){let r=this.applyTemplate(e);e.element.replaceChild(r,t)}}else e.element.removeChild(t);else if(n){let r=this.applyTemplate(e);e.element.appendChild(r)}}function Kn(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function Re(e){let t=e.element,n=e.value;n&&typeof n=="object"&&!Array.isArray(n)&&(V(t,n,"title","id","className","value","checked"),n=n.value),typeof n>"u"&&(n=""),t.type=="checkbox"?t.checked=_n(t,n):t.type=="radio"?t.checked=j(t.value,n):j(t.value,n)||(t.value=""+n),R(this,e)&&(t.type=="checkbox"?C.call(this,e.element,["checked"],!0,"checked",Wn):t.type=="radio"?C.call(this,e.element,["checked"],!0,"checked",zn):C.call(this,e.element,["value"],!0,"value"))}function _n(e,t){return Array.isArray(t)?t.some(n=>j(e.value,n)):typeof t=="boolean"?t:j(e.value,t)}function Wn(e,t){if(Array.isArray(t)){let n=e.value,r=t.filter(s=>!j(s,n));return e.checked&&r.push(n),r}return typeof t=="boolean"?e.checked:e.checked&&j(e.value,t)?t:e.checked}function zn(e,t){if(e.checked)return e.value}function Lt(e){ie.call(this,e,"value")}function xe(e){let t=e.element,n=e.value;if(n===null&&(n=""),Array.isArray(n))for(let r of t.options)r.selected=n.some(s=>j(r.value,s)),r.selected?r.setAttribute("selected",!0):r.removeAttribute("selected");else if(typeof n!="object"){let r=Array.from(t.options).find(s=>j(s.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&Qn(t,n.options),typeof n.selected<"u"&&xe.call(this,Object.assign({},e,{value:n.selected})),V(t,n,"name","id","selectedIndex","className");R(this,e)&&(t.multiple?C.call(this,e.element,["value"],!0,"value",Gn):C.call(this,e.element,["value"],!0,"value"))}function Gn(e){let t=e.value;return Array.from(e.options).filter(n=>n.selected).map(n=>n.value)}function wt(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function Qn(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)wt(e,n);else if(t&&typeof t=="object")for(let n in t)wt(e,{text:t[n],value:n})}function Ot(e){ie.call(this,e,"target","href","name","newwindow","nofollow"),R(this,e)&&E(()=>{oe.call(this,e,["target","href","name","newwindow","nofollow"])})}function Mt(e){V(e.element,e.value,"title","alt","src","id"),R(this,e)&&E(()=>{oe.call(this,e,["title","alt","src","id"])})}function Ct(e){V(e.element,e.value,"title","src","id"),R(this,e)&&E(()=>{oe.call(this,e,["title","src","id"])})}function jt(e){V(e.element,e.value,"content","id"),R(this,e)&&E(()=>{oe.call(this,e,["content","id"])})}function ie(e,...t){let n=e.element,r=e.value,s=!1;if(typeof r<"u"&&r!==null){let a=""+r;(typeof r!="object"||a.substring(0,8)!="[object ")&&(r={innerHTML:r},s=!0)}let i=["innerHTML","title","id","className"].concat(t);V(n,r,...i),R(this,e)&&C.call(this,e.element,i,s)}function V(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||j(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function oe(e,t){C.call(this,e.element,t,!1)}function bt(e,...t){let n={};for(let r of t)switch(r){default:n[r]=e[r];break}return n}function j(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}var Ie=class{constructor(t){this.bindings=new Map;let n={escape_html:pt,fixed_content:mt},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[Et],list:[kt],map:[At]},renderers:{INPUT:Re,TEXTAREA:Re,BUTTON:Lt,SELECT:xe,A:Ot,IMG:Mt,IFRAME:Ct,META:jt,TEMPLATE:null,"*":ie},twoway:!1};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},r,t),t.transformers&&(this.options.transformers=Object.assign({},n,t?.transformers));let s=this.options.attribute,i=[s+"-field",s+"-edit",s+"-list",s+"-map"],a=s+"-transform",c=u=>{let m=i.find(y=>u.hasAttribute(y));return m||console.error("No matching attribute found",u,i),m},o=u=>{this.bindings.set(u,g(()=>{if(!u.isConnected){Ne(u,this.getBindingPath(u));let y=this.bindings.get(u);y&&($(y),this.bindings.delete(u));return}let m={templates:u.querySelectorAll(":scope > template"),attribute:c(u)};m.edit=m.attribute===this.options.attribute+"-edit",m.path=this.getBindingPath(u),m.value=B(this.options.root,m.path),m.element=u,Yn(u,m),l(m)},50))},l=u=>{let m;switch(u.attribute){case this.options.attribute+"-field":case this.options.attribute+"-edit":m=Array.from(this.options.render.field);break;case this.options.attribute+"-list":m=Array.from(this.options.render.list);break;case this.options.attribute+"-map":m=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",u)}u.element.hasAttribute(a)&&u.element.getAttribute(a).split(" ").filter(Boolean).forEach(A=>{this.options.transformers[A]?m.push(this.options.transformers[A]):console.warn("No transformer with name "+A+" configured",{cause:u.element})});let y;for(let A of m)y=((D,Jt)=>en=>Jt.call(this,en,D))(y,A);y(u)},f=u=>{for(let m of u)this.bindings.get(m)||o(m)},d=u=>{let m=`[${s}-field],[${s}-edit],[${s}-list],[${s}-map]`;for(let y of u)if(y.type=="childList"&&y.addedNodes){for(let A of y.addedNodes)if(A instanceof HTMLElement){let D=Array.from(A.querySelectorAll(m));A.matches(m)&&D.unshift(A),D.length&&f(D)}}};this.observer=new MutationObserver(u=>{d(u)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let p=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-edit],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");try{p.length&&f(p)}catch(u){throw this.destroy(),u}}applyTemplate(t){let n=t.path,r=t.parent,s=t.templates,i=t.list,a=t.index,c=i?i[a]:t.value,o=this.findTemplate(s,c);if(!o){let u=new DocumentFragment;return u.innerHTML="<!-- no matching template -->",u}let l=o.content.cloneNode(!0);if(!l.children?.length)return l;if(l.children.length>1)throw new Error("template must contain a single root node",{cause:o});let f=this.options.attribute,d=[f+"-field",f+"-edit",f+"-list",f+"-map"],p=l.querySelectorAll(`[${f}-field],[${f}-edit],[${f}-list],[${f}-map]`);for(let u of p){if(u.tagName=="TEMPLATE")continue;let m=d.find(A=>u.hasAttribute(A)),y=u.getAttribute(m);y=this.applyLinks(o.links,y),y.substring(0,6)==":root."?u.setAttribute(m,y.substring(6)):y==":value"&&a!=null?u.setAttribute(m,n+"."+a):a!=null?u.setAttribute(m,n+"."+a+"."+y):u.setAttribute(m,r+y)}return this.applyTemplateCommandValues(l,o.links,n,a),typeof a<"u"&&l.children[0].setAttribute(f+"-key",a),l.children[0][h.TEMPLATE]=o,l.children[0][h.VALUE]=c,l}applyTemplateCommandValues(t,n,r,s){let i=this.options.attribute+"-value",a=this.options.attribute+"-value-path",c="["+i+"]",o=Array.from(t.querySelectorAll(c));for(let l of o){let f=l.getAttribute(i);f=this.applyLinks(n,f);let d=Xn(f,r,s);d&&(Object.hasOwn(d,"path")?l.setAttribute(a,d.path):(l.setAttribute(i,d.value),l.removeAttribute(a)))}}parseLinks(t){let n={};t=t.split(";").map(r=>r.trim());for(let r of t)r=r.split("="),n[r[0].trim()]=r[1].trim();return n}applyLinks(t,n){for(let r in t){if(n.startsWith(r+"."))return t[r]+n.substr(r.length);if(n==r)return t[r]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-edit",this.options.attribute+"-list",this.options.attribute+"-map"];for(let r of n)if(t.hasAttribute(r))return t.getAttribute(r)}findTemplate(t,n){let r=c=>{let o=this.getBindingPath(c),l;o?o.substr(0,6)==":root."?l=B(this.options.root,o.substring(6)):l=B(n,o):l=n;let f=""+l,d=c.getAttribute(this.options.attribute+"-match");if(d){if(d===":empty"&&!l)return c;if(d===":notempty"&&l||f==d)return c}if(!d)return c},s=Array.from(t).find(r),i=null;s?.hasAttribute(this.options.attribute+"-link")&&(i=this.parseLinks(s.getAttribute(this.options.attribute+"-link")));let a=s?.getAttribute("rel");if(a){let c=document.querySelector("template#"+a);if(!c)throw new Error("Could not find template with id "+a);s=c}return s&&(s.links=i),s}destroy(){this.bindings.forEach((t,n)=>{Ne(n,this.getBindingPath(n)),$(t)}),this.bindings=new Map,this.observer.disconnect()}};function ae(e){return new Ie(e)}var x=new Map;function Yn(e,t){Ne(e),x.has(t.path)?x.get(t.path).push(t):x.set(t.path,[t])}function Ne(e,t){if(t){let n=x.get(t);n&&(n=n.filter(r=>r.element!==e),x.set(t,n));return}x.forEach((n,r)=>{n=n.filter(s=>s.element!==e),x.set(r,n)})}function Xn(e,t,n){return!e||e[0]!==":"?null:e===":key"?{value:""+n}:e===":value"?{path:Pt(t,n)}:e.startsWith(":value.")?{path:Rt(Pt(t,n),e.substring(6))}:e.startsWith(":root.")?{path:e.substring(6)}:null}function Pt(e,t){return typeof t>"u"?e:Rt(e,"."+t)}function Rt(e,t){return e?e+t:t.replace(/^\./,"")}function B(e,t){let n=t.split("."),r=e,s;s=n.shift();let i=null;for(;s&&r;)s=decodeURIComponent(s),s=="0"&&!Array.isArray(r)||(s==":key"?r=i:s==":value"||(Array.isArray(r)&&typeof r[s]>"u"&&r[0]?r=r[0][s]:r=r[s])),i=s,s=n.shift();return r}var xt={};Ee(xt,{columns:()=>De,filter:()=>Ve,model:()=>ce,paging:()=>Be,scroll:()=>Ue,sort:()=>He});var $e=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=T(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],r=t.call(this,n);if(!b(r))throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=r,this.effects.push(this.view)}};function ce(e){return new $e(e)}function He(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let s=this.state.options.sort,i=s.sortBy;if(!s.sortBy)return 0;let a=s.sortDirection||s.direction||"asc",c=a=="asc"?1:-1,o=a=="asc"?-1:1;return typeof n?.[i]>"u"?typeof r?.[i]>"u"?0:c:typeof r?.[i]>"u"||n[i]<r[i]?o:n[i]>r[i]?c:0}},e),g(()=>{let n=this.state.options.sort,r=n?.sortDirection||n?.direction;if(n?.sortBy&&r){let s=n.sortFn,i=k(n).sortFn||s;return t.current.toSorted((a,c)=>i.call(this,a,c))}return t.current},50)}}function Be(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),g(()=>E(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(t.current.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let r=(n.page-1)*n.pageSize,s=r+n.pageSize;return t.current.slice(r,s)}),50)}}function Ve(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,g(()=>{let n=this.state.options[e.name];if(n.enabled){let r=n.matches,s=k(n).matches||r;return t.current.filter(i=>s.call(this,i))}return t.current},50)}}function De(e={}){let t=e?.columns&&typeof e.columns=="object"?e.columns:e;if(!t||typeof t!="object"||Object.keys(t).length===0)throw new Error("columns requires options to be an object with at least one property");return function(n){return this.state.options.columns=t,g(()=>n.current.map(r=>{let s={};for(let i of Object.keys(this.state.options.columns))this.state.options.columns[i]?.hidden||(s[i]=r[i]??null);return s}),50)}}function Ue(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,r=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return r&&(n.container&&n.container.addEventListener("scroll",s=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),g(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),g(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let s=Math.min(n.offset,t.current.length-1),i=s+n.rowCount;return i>t.current.length&&(i=t.current.length,s=i-n.rowCount),t.current.slice(s,i)},50)}}var qe=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let r=n.content.cloneNode(!0);for(let s of r.childNodes){let i=s.cloneNode(!0);if(i.nodeType==document.ELEMENT_NODE&&(i.querySelectorAll("template").forEach(function(a){a.setAttribute("simply-render","")}),this.attributes))for(let a of this.attributes)a.name!="rel"&&i.setAttribute(a.name,a.value);this.parentNode.insertBefore(i,this)}this.parentNode.removeChild(this)}else(()=>{let s=new MutationObserver(()=>{n=document.getElementById(t),n&&(s.disconnect(),this.replaceWith(this))});s.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",qe);function L(e,t,{maxDistance:n=2,minLength:r=4}={}){if(e.length<r)return;let s,i=1/0;for(let a of t){let c=Jn(e,a,n);c<i&&(s=a,i=c)}return i<=n?s:void 0}function Jn(e,t,n=2){let r=n+1;if(Math.abs(e.length-t.length)>n)return r;let s=Array.from({length:t.length+1},(a,c)=>c),i=new Array(t.length+1);for(let a=1;a<=e.length;a++){i[0]=a;for(let c=1;c<=t.length;c++){let o=e[a-1]===t[c-1]?0:1;i[c]=Math.min(s[c]+1,i[c-1]+1,s[c-1]+o)}s.splice(0,s.length,...i)}return s[t.length]}function ue(e){return new fe(e)}var fe=class{constructor(t={}){this.options=t,this.baseURL=t.baseURL||"/",this.app=t.app||{},this.addMissingSlash=!!t.addMissingSlash,this.matchExact=!!t.matchExact,this.hijackLinks=!!t.hijackLinks,this.clear(),t.routes&&this.load(t.routes)}load(t){lr(t,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(t,n){let r={path:t,options:n};r=this.runListeners("match",r),t=r.path?r.path:t;let s;if(t)s=ir(t);else{let i=document.location.pathname+document.location.hash;this.has(i)?t=i:t=document.location.pathname,s=new URLSearchParams(document.location.search)}t=le(Fe(t),this.baseURL);for(let i of this.routeInfo){let a=i.pattern.match(t);if(this.addMissingSlash&&!a&&t&&t[t.length-1]!="/"){let c=t+"/";a=i.pattern.match(c),a&&(t=c,history.replaceState({},"",Nt(t,this.baseURL)))}if(a)return Object.assign(a,n),r.route=i,r.params=a,r=this.runListeners("call",r),a=r.params?r.params:a,r.searchParams=s,r.result=er(this.app,i,a,s),this.runListeners("finish",r),r.result}return!1}runListeners(t,n){if(!(!this.listeners[t]||!Object.keys(this.listeners[t])))return Object.keys(this.listeners[t]).forEach(r=>{if($t(r).match(Fe(n.path))){var i;for(let a of this.listeners[t][r])i=a.call(this.app,n),i&&(n=i)}}),n}handleEvents(){this.removeEvents();let t=()=>{this.match()},n=r=>{if(!r.ctrlKey&&r.which==1){for(var s=r.target;s&&s.tagName!="A";)s=s.parentElement;if(s&&s.pathname&&s.hostname==globalThis.location.hostname&&!s.link&&!s.dataset.simplyCommand){let i=[{match:s.hash,goto:s.hash},{match:s.pathname+s.hash,goto:s.pathname+s.search+s.hash},{match:s.pathname,goto:s.pathname+s.search}],a;do a=i.shift(),a.match=le(a.match,this.baseURL);while(i.length&&!this.has(a.match));if(this.has(a.match)){let c=this.runListeners("goto",{path:a.goto});if(c.path){let o=this.goto(c.path);if(!o||this.options.hijackLinks&&o!==!1)return r.preventDefault(),!1}}}}};globalThis.addEventListener("popstate",t),this.app.container.addEventListener("click",n),this.eventHandlers={container:this.app.container,popstateHandler:t,clickHandler:n}}removeEvents(){this.eventHandlers&&(globalThis.removeEventListener("popstate",this.eventHandlers.popstateHandler),this.eventHandlers.container.removeEventListener("click",this.eventHandlers.clickHandler),this.eventHandlers=void 0)}destroy(){this.removeEvents()}goto(t){return history.pushState({},"",Nt(t,this.baseURL)),this.match(t)}has(t){t=le(Fe(t),this.baseURL);for(let n of this.routeInfo)if(n.pattern.match(t))return!0;return!1}addListener(t,n,r){if(["goto","match","call","finish"].indexOf(t)==-1)throw new TypeError(`simplyflow/route: unknown listener type "${t}"`);this.listeners[t][n]||(this.listeners[t][n]=[]),this.listeners[t][n].push(r)}removeListener(t,n,r){if(["goto","match","call","finish"].indexOf(t)==-1)throw new TypeError(`simplyflow/route: unknown listener type "${t}"`);this.listeners[t][n]&&(this.listeners[t][n]=this.listeners[t][n].filter(s=>s!=r))}init(t){t.baseURL&&(this.baseURL=t.baseURL)}};function er(e,t,n,r){if(typeof t.action=="function")return t.action.call(e,n,r);if(typeof t.action=="string"){let s=e.actions?.[t.action];if(typeof s=="function")return s.call(e,tr(t,n,r));throw sr(t,e.actions)}throw new TypeError(`simplyflow/route: route "${t.path}" must use a function or action name`)}var It=new Set;function tr(e,t,n){let r=nr(n);for(let s of Object.keys(r))Object.hasOwn(t,s)&&rr(e,s);return Object.assign(r,t)}function nr(e){let t={};for(let[n,r]of e.entries())Object.hasOwn(t,n)?Array.isArray(t[n])?t[n].push(r):t[n]=[t[n],r]:t[n]=r;return t}function rr(e,t){let n=`${e.path}\0${t}`;It.has(n)||(It.add(n),console.warn(`simplyflow/route: query parameter "${t}" was ignored because route "${e.path}" already provides a route parameter with that name.`))}function sr(e,t){let n=L(e.action,Object.keys(t||{})),r=n?` Did you mean "${n}"?`:"";return new TypeError(`simplyflow/route: route "${e.path}" uses unknown action "${e.action}".${r}`)}function ir(e){let t=typeof e=="string"?e.indexOf("?"):-1;if(t===-1)return new URLSearchParams;let n=e.indexOf("#",t),r=n===-1?e.substring(t):e.substring(t,n);return new URLSearchParams(r)}function Fe(e){let t=typeof e=="string"?e.indexOf("?"):-1;if(t===-1)return e;let n=e.indexOf("#",t);return n===-1?e.substring(0,t):e.substring(0,t)+e.substring(n)}function le(e,t="/"){return(e.substring(0,t.length)==t||t[t.length-1]=="/"&&e.length==t.length-1&&e==t.substring(0,e.length))&&(e=e.substring(t.length)),e[0]!="/"&&(e="/"+e),e}function Nt(e,t){return e=le(e,t),t[t.length-1]==="/"&&e[0]==="/"&&(e=e.substring(1)),e[0]=="#"?e:t+e}function $t(e,t=!1){let n=[],r=or(e,t,n);return{path:e,params:n,regexp:r,match(s){let i=r.exec(s);if(!i)return null;let a={};return n.forEach((c,o)=>{a[c]=i[o+1]}),a}}}function or(e,t=!1,n=[]){if(e.includes(":*"))throw new TypeError(`simplyflow/route: route "${e}" uses the old wildcard syntax ":*". Use a named wildcard like ":path*" instead.`);let r=e[0]==="#"?"":"^",s=t?"$":"";return new RegExp(r+ar(e,n)+s)}function ar(e,t){let n="",r=0;for(;r<e.length;){if(e[r]===":"){let s=/^:([A-Za-z_][A-Za-z0-9_]*)(\*)?/.exec(e.substring(r));if(!s)throw new TypeError(`simplyflow/route: invalid route parameter in "${e}"`);t.push(s[1]),n+=s[2]?"(.*)":"([^/]+)",r+=s[0].length;continue}if(e[r]==="*"){n+=".*",r++;continue}n+=cr(e[r]),r++}return n}function cr(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function lr(e,t,n=!1){let r=Object.keys(e);for(let s of r)t.push({path:s,pattern:$t(s,n),action:e[s]});return t}var G={get(e,t){return typeof t!="string"?t:t?t.split(".").reduce(function(n,r){return n==null||!Reflect.has(Object(n),r)?null:n[r]},e):e},set:function(e,t,n){let r=G.get(e,G.parent(t));if(r==null)throw new TypeError(`simplyflow/path: cannot set "${t}" because its parent path does not exist`);r[G.pop(t)]=n},pop:function(e){return e.split(".").pop()},push:function(e,t){return(e?e+".":"")+t},parent:function(e){let t=e.split(".");return t.pop(),t.join(".")},parents:function(e,t){let n=[];for(;t;)t=G.parent(t),n.unshift(t);return n}},he=G;var _e=new WeakMap,fr=["commands","handlers","app","container"],We=class{constructor(t={}){t.app||(t.app={}),t.app.container||(t.app.container=document.body),this.app=t.app,this.$handlers=t.handlers||hr,t.commands&&Object.assign(this,t.commands);let n=s=>{let i=ur(s,this.$handlers,this.app);if(!i)return;if(!this[i.name]){Bt(this,i.name,i.source);return}if(this[i.name].call(t.app,i.source,i.value,s)!==!0)return s.preventDefault(),s.stopPropagation(),!1},r=t.app.container;r.addEventListener("click",n),r.addEventListener("submit",n),r.addEventListener("change",n),r.addEventListener("input",n),_e.set(this,{container:r,commandHandler:n})}call(t,n,r,s){if(!this[t]){Bt(this,t,n);return}return this[t].call(this.app,n,r,s)}appendHandler(t){this.$handlers.push(t)}prependHandler(t){this.$handlers.unshift(t)}};function de(e={}){return new We(e)}function Vt(e){let t=_e.get(e);t&&(t.container.removeEventListener("click",t.commandHandler),t.container.removeEventListener("submit",t.commandHandler),t.container.removeEventListener("change",t.commandHandler),t.container.removeEventListener("input",t.commandHandler),_e.delete(e))}function ur(e,t,n){var r=e.target.closest("[data-simply-command]");if(r){for(let s of t)if(r.matches(s.match))return s.check(r,e)?{name:r.dataset.simplyCommand,source:r,value:s.get(r,n)}:null}return null}function Ke(e,t){let n="simplyValuePath";return Object.hasOwn(e.dataset,n)?{found:!0,value:he.get(t?.data,e.dataset[n])}:Object.hasOwn(e.dataset,"simplyValue")?{found:!0,value:e.dataset.simplyValue}:{found:!1,value:void 0}}var hr=[{match:"input,select,textarea",get:function(e,t){let n=Ke(e,t);if(n.found)return n.value;if(e.tagName==="SELECT"&&e.multiple){let r=[];for(let s of e.options)s.selected&&r.push(s.value);return r}return e.value},check:function(e,t){return t.type=="change"||e.dataset.simplyImmediate&&t.type=="input"}},{match:"a,button",get:function(e,t){let n=Ke(e,t);return n.found?n.value:e.href||e.value},check:function(e,t){return t.type=="click"&&t.ctrlKey==!1&&t.button==0}},{match:"form",get:function(e){let t={};for(let n of Array.from(e.elements)){if(n.tagName=="INPUT"&&(n.type=="checkbox"||n.type=="radio")&&!n.checked)return;t[n.name]&&!Array.isArray(t[n.name])&&(t[n.name]=[t[n.name]]),Array.isArray(t[n.name])?t[n.name].push(n.value):t[n.name]=n.value}return t},check:function(e,t){return t.type=="submit"}},{match:"*",get:function(e,t){return Ke(e,t).value},check:function(e,t){return t.type=="click"&&t.ctrlKey==!1&&t.button==0}}],Ht=new WeakMap;function Bt(e,t,n){let r=Ht.get(e);if(r||(r=new Set,Ht.set(e,r)),r.has(t))return;r.add(t);let s=L(t,dr(e)),i=s?`. Did you mean "${s}"?`:"";n?console.warn(`simplyflow/command: unknown command "${t}"${i}`,{cause:n}):console.warn(`simplyflow/command: unknown command "${t}"${i}`)}function dr(e){return Object.keys(e).filter(t=>!t.startsWith("$")&&!fr.includes(t)&&typeof e[t]=="function")}var Dt=new WeakMap;function pe(e){if(e.app){let t={apply(r,s,i){try{let a=r(...i);return a instanceof Promise?a.catch(c=>e.app.onError.call(this,c,r)):a}catch(a){return e.app.onError.call(this,a,r)}}},n={get(r,s){if(!Object.hasOwn(r,s)){pr(r,s);return}return e.app.onError?new Proxy(r[s].bind(e.app),t):r[s].bind(e.app)}};return new Proxy(e.actions,n)}else return e}function pr(e,t){if(typeof t!="string")return;let n=Dt.get(e);if(n||(n=new Set,Dt.set(e,n)),n.has(t))return;n.add(t);let r=L(t,Object.keys(e)),s=r?`. Did you mean "${r}"?`:"";console.warn(`simplyflow/action: unknown action "${t}"${s}`)}var ze=new WeakMap,Ge=new WeakMap,Q=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),Qe=class{constructor(t={}){t.app||(t.app={}),t.app.container||(t.app.container=document.body),Object.assign(this,t.shortcuts);let n=s=>{let i=[],a=s.target.closest("[data-simply-shortcuts]");for(;a;)i.push(a.dataset.simplyShortcuts),a=a.parentNode.closest("[data-simply-shortcuts]");i[i.length-1]!="default"&&i.push("default");let c,o=["+","-"];for(let l of o){let f=Ut(s,l);for(let d in i){if(c=i[d],this[c]&&typeof this[c][f]=="function"&&!this[c][f].call(t.app,s)){s.preventDefault();return}if(typeof this[c+"."+f]=="function"&&!this[c+"."+f].call(t.app,s)){s.preventDefault();return}if(typeof this[f]=="function"&&!this[f].call(t.app,s)){s.preventDefault();return}}}},r=t.app.container;r.addEventListener("keydown",n),ze.set(this,{container:r,keyHandler:n})}};function Ut(e,t="+"){if(e.isComposing||e.keyCode===Q.Compose||e.defaultPrevented||!e.target)return;let n=[];return e.ctrlKey&&e.keyCode!=Q.Control&&n.push("Control"),e.metaKey&&e.keyCode!=Q.Meta&&n.push("Meta"),e.altKey&&e.keyCode!=Q.Alt&&n.push("Alt"),e.shiftKey&&e.keyCode!=Q.Shift&&n.push("Shift"),n.push(e.key.toLowerCase()),n.join(t)}function me(e={}){return new Qe(e)}function qt(e){let t=ze.get(e);t&&(t.container.removeEventListener("keydown",t.keyHandler),ze.delete(e))}function Ft(e={}){let t=e.container||e.app?.container||document.body,n=s=>{let i=["+","-"];for(let a of i){let o="[data-simply-accesskey='"+Ut(s,a)+"']",l=t.querySelectorAll(o);l.length&&l.forEach(function(f){f.click()})}};t.addEventListener("keydown",n);let r={};return Ge.set(r,{container:t,keyHandler:n}),r}function Kt(e){let t=Ge.get(e);t&&(t.container.removeEventListener("keydown",t.keyHandler),Ge.delete(e))}var _t="[data-simply-behavior]",Ye=class{constructor(t={}){this.app=t.app,this.container=t.container||document.body,this.behaviors=t.behaviors||{},this.active=new Set,this.cleanups=new WeakMap,this.unknown=new Set,this.observer=new MutationObserver(n=>this.handleChanges(n)),this.observer.observe(this.container,{subtree:!0,childList:!0});for(let n of Ze(this.container))this.start(n)}start(t){if(this.active.has(t))return;let n=t?.dataset?.simplyBehavior,r=this.behaviors[n];if(!n||typeof r!="function"){this.warnUnknown(n,t);return}this.active.add(t);let s=r.call(this.app||t,t);typeof s=="function"?this.cleanups.set(t,s):typeof s<"u"&&console.warn("simplyflow/behavior: behavior may only return a cleanup function",{cause:s})}stop(t){if(!this.active.has(t))return;this.active.delete(t);let n=this.cleanups.get(t);this.cleanups.delete(t),n&&n.call(this.app||t,t)}handleChanges(t){let n=[];for(let r of t)if(r.type==="childList"){for(let s of r.removedNodes)for(let i of Ze(s))this.stop(i);for(let s of r.addedNodes)n.push(...Ze(s))}for(let r of n)this.start(r)}warnUnknown(t,n){if(!t||this.unknown.has(t))return;this.unknown.add(t);let r=L(t,Object.keys(this.behaviors)),s=r?`. Did you mean "${r}"?`:"";console.warn(`simplyflow/behavior: unknown behavior "${t}"${s}`,{cause:n})}destroy(){this.observer.disconnect();for(let t of Array.from(this.active))this.stop(t)}};function ye(e={}){return new Ye(e)}function Ze(e){if(!e?.querySelectorAll)return[];let t=Array.from(e.querySelectorAll(_t));return e.matches?.(_t)&&t.unshift(e),t}function mr(e,t){let n=0;return function(...s){n||(n=globalThis.setTimeout(()=>{n=0,e.apply(this,s)},t))}}var yr=globalThis.requestIdleCallback?e=>{globalThis.requestIdleCallback(e,{timeout:500})}:globalThis.requestAnimationFrame||(e=>globalThis.setTimeout(e,0));function Wt(e,t,n){let r=new URL(e,t);return n&&r.searchParams.set("cb",n),r.href}function gr(e,t,n){let r=globalThis.document.createElement("script");for(let s of e.attributes)r.setAttribute(s.name,s.value);return r.removeAttribute("data-simply-location"),r.hasAttribute("src")?r.src=Wt(r.getAttribute("src"),t,n):r.textContent=e.textContent,r}function zt(e,t){t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t)}function br(e){return e.hasAttribute("src")&&!e.hasAttribute("async")}function wr(e,t){return new Promise(n=>{let r=()=>{e.removeEventListener("load",r),e.removeEventListener("error",r),n()};e.addEventListener("load",r),e.addEventListener("error",r),zt(e,t)})}function Er(e){let t='link[rel="simply-include"],link[rel="simply-include-once"]',n=Array.from(e.querySelectorAll(t));return e.matches?.(t)&&n.unshift(e),n}var ge=class{constructor(t={}){this.container=t.container||globalThis.document,this.cacheBuster=t.cacheBuster??be,this.included=Object.create(null),this.scriptLocations=[],this.destroyed=!1,this.handleChanges=mr(()=>{yr(()=>{this.destroyed||this.includeLinks(Er(this.container))})},10),t.observe!==!1&&(this.observer=new MutationObserver(this.handleChanges),this.observer.observe(this.container,{subtree:!0,childList:!0}),this.handleChanges())}async scripts(t,n){let r=t.slice();for(let s of r){if(this.destroyed)return;let i=gr(s,n,this.cacheBuster),a=this.scriptLocations[s.dataset.simplyLocation];if(!a?.parentNode)continue;br(i)?(i.async=!1,await wr(i,a)):zt(i,a)}}html(t,n){let r=globalThis.document.createRange().createContextualFragment(t),s=r.querySelectorAll('link[rel="stylesheet"],style');for(let c of s){let o=c.getAttribute("href");o&&(c.href=Wt(o,n.href,this.cacheBuster)),globalThis.document.head.appendChild(c)}let i=globalThis.document.createDocumentFragment(),a=r.querySelectorAll("script");if(a.length){for(let c of a){let o=globalThis.document.createComment(c.src||"inline script");c.parentNode.insertBefore(o,c),c.dataset.simplyLocation=this.scriptLocations.length,this.scriptLocations.push(o),i.appendChild(c)}globalThis.setTimeout(()=>{this.scripts(Array.from(i.children),n?n.href:globalThis.location.href)},10)}n.parentNode.insertBefore(r,n)}async includeLinks(t){let n=t.reduce((r,s)=>(s.rel==="simply-include-once"&&this.included[s.href]?s.parentNode.removeChild(s):(this.included[s.href]=!0,s.rel="simply-include-loading",r.push(s)),r),[]);for(let r of n)if(!(this.destroyed||!r.href))try{let s=await fetch(r.href);if(!s.ok){console.warn(`simplyflow/include: failed to load "${r.href}" (${s.status})`),r.rel="simply-include-error";continue}let i=await s.text();if(this.destroyed||!r.parentNode)continue;this.html(i,r),r.parentNode?.removeChild(r)}catch(s){console.warn(`simplyflow/include: failed to load "${r.href}"`,{cause:s}),r.rel="simply-include-error"}}destroy(){this.destroyed=!0,this.observer?.disconnect(),this.observer=void 0}};function we(e={}){return new ge(e)}var be=null,Xe=()=>new ge({container:globalThis.document,cacheBuster:be,observe:!1}),Gt={get cacheBuster(){return be},set cacheBuster(e){be=e},scripts:(e,t)=>Xe().scripts(e,t),html:(e,t)=>Xe().html(e,t),links:e=>Xe().includeLinks(Array.from(e))};var kr=["container","data","templates","styles","start","onError","components","behaviors","baseURL","commands","shortcuts","routes","actions"],et=class{constructor(t={}){if(t.components){let n={};Yt(n,t.components),tt(n,t),t=n}this.container=t.container||document.body,this.destroyed=!1,this.data=T(t.data||{}),this.start=t.start,this.onError=t.onError,this.components=t.components,this.baseURL=t.baseURL,Ar(this.container,t.templates),Tr(this.container,t.styles);for(let n of Object.keys(t))switch(n){case"container":case"data":case"templates":case"styles":case"start":case"onError":case"components":case"baseURL":break;case"commands":this.commands=de({app:this,container:this.container,commands:t.commands});break;case"shortcuts":this.shortcuts=me({app:this,shortcuts:t.shortcuts});break;case"behaviors":this.behaviors=ye({app:this,container:this.container,behaviors:t.behaviors});break;case"routes":this.routes=ue({app:this,routes:t.routes});break;case"actions":this.actions=pe({app:this,actions:t.actions});break;case"prototype":case"__proto__":break;default:vr(n),this[n]=t[n];break}this.binding=ae({root:this.data,container:this.container,attribute:"data-simply"}),this.includes=we({container:this.container}),this.accesskeys=Ft({app:this,container:this.container})}get app(){return this}destroy(){this.destroyed=!0,this.binding&&(this.binding.destroy(),this.binding=void 0),this.commands&&Vt(this.commands),this.shortcuts&&qt(this.shortcuts),this.accesskeys&&(Kt(this.accesskeys),this.accesskeys=void 0),this.routes&&(this.routes.destroy(),this.routes=void 0),this.behaviors&&(this.behaviors.destroy(),this.behaviors=void 0),this.includes&&(this.includes.destroy(),this.includes=void 0)}};function Ar(e,t){if(t)for(let n of Object.keys(t)){let r=document.createElement("div");r.innerHTML=t[n];let s=e.querySelector("template#"+n);s?s.content.replaceChildren(...r.children):(s=document.createElement("template"),s.id=n,s.content.append(...r.children),e.appendChild(s))}}function Tr(e,t){if(t)for(let n of Object.keys(t)){let r=e.querySelector("style#"+n+".css");r||(r=document.createElement("style"),r.id=n+".css",e.appendChild(r)),r.innerHTML=t[n]}}function vr(e){let t=L(e,kr);t&&console.warn(`simplyflow/app: unknown option "${e}". Did you mean "${t}"? The option was still added to the app as "app.${e}".`)}function Je(e){e.destroyed||e.routes&&(e.baseURL&&e.routes.init({baseURL:e.baseURL}),e.routes.handleEvents(),globalThis.setTimeout(()=>{e.destroyed||!e.routes||(e.routes.has(globalThis.location?.hash)?e.routes.match(globalThis.location.hash):e.routes.match(globalThis.location?.pathname+globalThis.location?.hash))}))}function Qt(e,t,n){if(e.onError)return e.onError.call(e,t,n);throw t}function Zt(e={}){let t=new et(e);if(!t.start)return Je(t),t;try{let n=t.start.call(t);n instanceof Promise?n.then(()=>Je(t)).catch(r=>Qt(t,r,t.start)):Je(t)}catch(n){Qt(t,n,t.start)}return t}function tt(e,t){for(let n of Object.keys(t))switch(typeof t[n]){case"object":if(!t[n])continue;e[n]?tt(e[n],t[n]):e[n]=t[n];break;default:e[n]=t[n]}}function Yt(e,t){for(let n of Object.keys(t)){let r=t[n];r.components&&Yt(e,r.components),e.components||(e.components={}),e.components[n]=r;for(let s of Object.keys(r))switch(s){case"start":case"onError":case"components":break;default:e[s]||(e[s]=Object.create(null)),tt(e[s],r[s]);break}}}function nt(e,...t){return t.map((r,s)=>`${e[s]}${r}`).join("")+e[e.length-1]}function Xt(e,...t){return nt(e,...t)}globalThis.simply||(globalThis.simply={});globalThis.html=nt;globalThis.css=Xt;var Sr=Object.assign(ce,{model:ce,sort:He,paging:Be,filter:Ve,columns:De,scroll:Ue});Object.assign(globalThis.simply,{app:Zt,bind:ae,model:Sr,state:Oe,signal:T,effect:se,batch:E,clone:Le,destroy:$,untracked:H,throttledEffect:g,clockEffect:z,createSignal:N,isSignal:b,raw:k,dom:je,behaviors:ye,actions:pe,commands:de,include:Gt,includes:we,shortcuts:me,path:he,routes:ue});delete globalThis.simply.advanced;var js=globalThis.simply;})();
|
|
1
|
+
(()=>{var sn=Object.defineProperty;var we=(e,t)=>{for(var n in t)sn(e,n,{get:t[n],enumerable:!0})};var Le={};we(Le,{addTracer:()=>vn,batch:()=>E,clockEffect:()=>_,clone:()=>Se,createSignal:()=>N,destroy:()=>H,effect:()=>re,getSignal:()=>I,isSignal:()=>b,makeContext:()=>C,notifyGet:()=>S,notifySet:()=>M,raw:()=>w,registerSignal:()=>ot,signal:()=>v,signals:()=>O,throttledEffect:()=>y,trace:()=>An,untracked:()=>$});var d={ITERATE:Symbol.for("@simplyedit/simplyflow.iterate"),XRAY:Symbol.for("@simplyedit/simplyflow.xRay"),SIGNAL:Symbol.for("@simplyedit/simplyflow.Signal"),TEMPLATE:Symbol.for("@simplyedit/simplyflow.bindTemplate"),VALUE:Symbol.for("@simplyedit/simplyflow.bindValue"),LENGTH:"length",SIZE:"size"};var on=new Set(["get","has"]),an=new Set(["keys","values","entries","forEach",Symbol.iterator]),cn=new Set(["set","delete","clear"]),ln=new Set(["add","delete","clear"]),un={entries:{},forEach:{},has:{},keys:{},values:{},[Symbol.iterator]:{}};function K(e){return e!==null&&(typeof e=="object"||typeof e=="function")}function b(e){return!!(K(e)&&e[d.SIGNAL])}function w(e){return b(e)?e[d.XRAY]:e}function I(e){return b(e)?e:O.get(e)}function Q(e){return O.get(e)}function st(e,t){return e?.[t]}function fn(e,t,n){return e instanceof HTMLElement||e instanceof Number||e instanceof String||e instanceof Boolean?n.bind(e):n.bind(t)}function nt(e,t){let n=new Map;if(!Array.isArray(e)||t>=e.length)return n;for(let r=t;r<e.length;r++)Object.hasOwn(e,r)&&n.set(r,e[r]);return n}function Ee(e,t,n,r=new Map){if(!(!Array.isArray(t)||n===t.length)){e.set(d.LENGTH,{was:n,now:t.length}),e.set(d.ITERATE,{});for(let[s,i]of r)e.set(String(s),{delete:!0,was:i,now:void 0})}}function J(e,t){t.size&&M(e,t)}function hn(e,t,n,r){return(...s)=>{let i=e.length,a=r.apply(n,s);return i!==e.length&&M(n,C(d.LENGTH,{was:i,now:e.length})),a}}function dn(e,t,n,r,s){if(n==="set"){let[i,a]=r,c=t.has(i),o=t.get(i);return()=>{(!c||!Object.is(o,a))&&(e.set(i,{was:o,now:a}),e.set(d.ITERATE,{})),c||e.set(d.SIZE,{was:s,now:t.size})}}if(n==="delete"){let[i]=r,a=t.has(i),c=t.get(i);return()=>{a&&(e.set(i,{delete:!0,was:c,now:void 0}),e.set(d.SIZE,{was:s,now:t.size}),e.set(d.ITERATE,{}))}}if(n==="clear"){let i=s?Array.from(t.entries()):[];return()=>{if(i.length){for(let[a,c]of i)e.set(a,{delete:!0,was:c,now:void 0});e.set(d.SIZE,{was:s,now:t.size}),e.set(d.ITERATE,{})}}}return()=>{}}function pn(e,t,n,r){return(...s)=>{on.has(t)&&S(n,s[0]),an.has(t)&&S(n,d.ITERATE);let i=e.size,a=new Map,c=cn.has(t)?dn(a,e,t,s,i):()=>{},o=r.apply(e,s);return c(),J(n,a),o}}function mn(e,t,n,r,s){let[i]=r,a=n==="add"||n==="delete"?t.has(i):!1;return()=>{if(n==="clear"?s>0:t.size!==s||n==="delete"&&a){e.set(d.SIZE,{was:s,now:t.size});for(let o of Reflect.ownKeys(un))e.set(o,{})}}}function yn(e,t,n,r){return(...s)=>{let i=e.size,a=new Map,c=ln.has(t)?mn(a,e,t,s,i):()=>{},o=r.apply(e,s);return c(),J(n,a),o}}function bn(e,t,n,r,s){return Object.hasOwn(e,"value")&&!Object.is(n,s)||Object.hasOwn(e,"get")&&t?.get!==r?.get||Object.hasOwn(e,"set")&&t?.set!==r?.set}var gn={get(e,t,n){let r=st(e,t);return S(n,t),typeof r=="function"?Array.isArray(e)?hn(e,t,n,r):e instanceof Map?pn(e,t,n,r):e instanceof Set?yn(e,t,n,r):fn(e,n,r):K(r)?v(r):r},set(e,t,n,r){let s=Object.hasOwn(e,t),i=Array.isArray(e)?e.length:void 0,a=t===d.LENGTH?nt(e,Number(n)):new Map,c=e[t];e[t]=n;let o=Object.hasOwn(e,t),l=e[t],u=new Map;return(!Object.is(c,l)||!s&&o)&&u.set(t,{was:c,now:l}),!s&&o&&u.set(d.ITERATE,{}),Ee(u,e,i,a),J(r,u),!0},has(e,t){let n=Q(e);return n&&S(n,t),Reflect.has(e,t)},deleteProperty(e,t){if(!Object.hasOwn(e,t))return!0;let r=e[t],s=Array.isArray(e)?e.length:void 0,i=Reflect.deleteProperty(e,t);if(!i)return i;let a=Q(e),c=C(t,{delete:!0,was:r,now:void 0});return c.set(d.ITERATE,{delete:!0,property:t}),Ee(c,e,s),M(a,c),i},defineProperty(e,t,n){let r=Object.hasOwn(e,t),s=Object.getOwnPropertyDescriptor(e,t),i=e[t],a=Array.isArray(e)?e.length:void 0,c=t===d.LENGTH&&Object.hasOwn(n,"value")?nt(e,Number(n.value)):new Map,o=Reflect.defineProperty(e,t,n);if(!o)return o;let l=Object.hasOwn(e,t),u=Object.getOwnPropertyDescriptor(e,t),p=e[t],f=new Map;return!r&&l?(f.set(t,{was:i,now:p}),f.set(d.ITERATE,{})):r&&l&&(bn(n,s,i,u,p)&&f.set(t,{was:i,now:p}),s?.enumerable!==u?.enumerable&&f.set(d.ITERATE,{})),Ee(f,e,a,c),J(Q(e),f),o},ownKeys(e){let t=Q(e);return S(t,d.ITERATE),Reflect.ownKeys(e)}},O=new WeakMap;function it(e,t){if(!K(e))throw new TypeError(`simplyflow/state: ${t}() expects an object, array, Map, Set, class instance, function, or DOM node; received ${typeof e}`)}function wn(e,t){if(!e||typeof e!="object")throw new TypeError(`simplyflow/state: ${t}() expects a Proxy handler object`)}function En(e){return{...e,get(t,n,r){return n===d.XRAY?t:n===d.SIGNAL?!0:e.get?e.get(t,n,r):st(t,n)}}}function ot(e,t){let n=w(e);if(it(n,"registerSignal"),!b(t))throw new TypeError("simplyflow/state: registerSignal() expects a signal proxy");let r=O.get(n);if(r&&r!==t)throw new Error("simplyflow/state: registerSignal() target already has a different signal");return O.set(n,t),t}function N(e,t={},n){if(it(e,"createSignal"),wn(t,"createSignal"),n!==void 0&&typeof n!="function")throw new TypeError("simplyflow/state: createSignal() expects init to be a function");if(b(e))return e;let r=I(e);if(r)return r;let s=new Proxy(e,En(t));return ot(e,s),n?.(e,s),s}function v(e={}){if(!K(e))throw new TypeError(`simplyflow/state: signal() expects an object, array, Map, Set, class instance, or function; received ${typeof e}`);return N(e,gn)}var te=[],ee=!1;function An(e,t){if(typeof e=="function"){ee=!0;try{return e()}finally{ee=!1}}if(!b(e))throw new TypeError("simplyflow/state: trace() expects either a function or a signal");return Ln(e,t).map(n=>({effect:n.effectType,fn:n.effectFunction,signal:O.get(n.effectFunction)}))}function vn(e){if(!e||typeof e!="object")throw new TypeError("simplyflow/state: addTracer() expects a tracer object");if(!e.get&&!e.set)throw new Error('simplyflow/state: addTracer: missing "get" or "set" property in tracer');if(e.get&&typeof e.get!="function")throw new Error('simplyflow/state: addTracer: "get" is not a function');if(e.set&&typeof e.set!="function")throw new Error('simplyflow/state: addTracer: "set" is not a function');te.push(e)}function at(e,...t){for(let n of te)n[e]?.(...t)}var Ae=new Set,X=0;function M(e,t=new Map){if(!b(e))throw new TypeError("simplyflow/state: notifySet() expects a signal as first argument");if(!(t instanceof Map))throw new TypeError("simplyflow/state: notifySet() expects context to be a Map; use makeContext()");let n=new Set;if(t.forEach((r,s)=>{for(let i of ct(e,s))kn(i,s,r),n.add(i)}),!!n.size){if(X){for(let r of n)Ae.add(r);return}ve(n,e,t)}}function C(e,t){let n=new Map;if(e instanceof Map)return e.forEach((r,s)=>n.set(s,r)),n;if(e!==null&&typeof e=="object")for(let r of Reflect.ownKeys(e))n.set(r,e[r]);else n.set(e,t);return n}function kn(e,t,n){e.context||(e.context=new Map),e.context.set(t,n),e.needsUpdate=!0}function Tn(e){delete e.context,delete e.needsUpdate}function S(e,t){let n=g[g.length-1];!n||n.skipDependency?.(e,t)||(ee&&te.length&&at("get",e,t),lt(e,t,n))}var U=new WeakMap,x=new WeakMap,Sn=new Set;function ct(e,t){return U.get(e)?.get(t)||Sn}function Ln(e,t){return Array.from(ct(e,t))}function lt(e,t,n){U.has(e)||U.set(e,new Map);let r=U.get(e);r.has(t)||r.set(t,new Set),r.get(t).add(n),x.has(n)||x.set(n,new Map);let s=x.get(n);s.has(t)||s.set(t,new Set),s.get(t).add(e)}function ne(e){let t=x.get(e);t&&(t.forEach((n,r)=>{n.forEach(s=>{U.get(s)?.get(r)?.delete(e)})}),x.delete(e))}var g=[],q=[],Z=[],F=new WeakMap;function W(e,t){if(typeof e!="function")throw new TypeError(`simplyflow/state: ${t}() expects a function`)}function ut(e){if(q.includes(e))throw new Error("Recursive update() call",{cause:e})}function ke(e){let t=O.get(e);return t||(t=v({current:null}),O.set(e,t)),t}function ft(e,t){t instanceof Promise?t.then(n=>{e.current=n}):e.current=t}function ht(e,t,n,r,s=[e,g,Z]){if(Z.includes(t))throw new Error("Cyclical dependency in update() call",{cause:n});ne(e),e.effectFunction=n,e.effectType=r,g.push(e),Z.push(t);let i;try{i=n(...s)}finally{g.pop(),Z.pop(),ft(t,i)}}function ve(e,t,n){let r=g[g.length-1];for(let s of e)s!==r&&s?.needsUpdate&&(s.scheduleClock?s.scheduleClock():(t&&ee&&te.length&&at("set",t,n,s),s())),Tn(s)}function re(e){W(e,"effect"),ut(e),q.push(e);let t=ke(e),n=function(){ht(n,t,e,re)};return n.fn=e,F.set(t,n),n(),t}function H(e){if(!b(e))throw new TypeError("simplyflow/state: destroy() expects an effect signal");let t=F.get(e);if(t){if(t.destroy?.(),ne(t),t.fn){O.delete(t.fn);let n=q.findIndex(r=>r===t.fn);n!==-1&&q.splice(n,1)}F.delete(e)}}function E(e){W(e,"batch"),X++;let t;try{t=e()}finally{let n=()=>{X--,X||On()};t instanceof Promise?t.then(n,n):n()}return t}function On(){let e=Ae;Ae=new Set;let t=new Set,n=new Set;for(let r of e)r.scheduleClock?t.add(r):n.add(r);ve(t),ve(n)}function y(e,t){if(W(e,"throttledEffect"),!Number.isFinite(t)||t<0)throw new TypeError("simplyflow/state: throttledEffect() expects throttleTime to be a non-negative number");ut(e),q.push(e);let n=ke(e),r=0,s=!0,i=null,a=function(){let l=Date.now();if(r>l){s=!0,c();return}ht(a,n,e,y),s=!1,r=Date.now()+t};function c(){if(i)return;let o=Math.max(0,r-Date.now());i=globalThis.setTimeout(()=>{i=null,s&&a()},o)}return a.fn=e,a.destroy=()=>{i&&(globalThis.clearTimeout(i),i=null),s=!1},F.set(n,a),a(),n}var Y=new WeakMap;function rt(e){return w(e).time}function Mn(e){if(!Y.has(e)){let t={clock:e,effects:new Set,pending:new Set,time:rt(e)};t.tick=function(){let r=rt(e);if(r<=t.time)return;t.time=r;let s=Array.from(t.pending);t.pending.clear();for(let i of s)i.clockPending=!1,t.effects.has(i)&&i()},t.tick.effectFunction=t.tick,t.tick.effectType=_,lt(e,"time",t.tick),Y.set(e,t)}return Y.get(e)}function jn(e){let t=e.clockQueue;t&&(t.pending.delete(e),t.effects.delete(e),t.effects.size||(ne(t.tick),Y.delete(t.clock)))}function _(e,t){if(W(e,"clockEffect"),!t||typeof t!="object"||typeof w(t).time!="number")throw new TypeError("simplyflow/state: clockEffect() expects a clock object with a numeric .time property");let n=b(t)?t:v(w(t)),r=ke(e),s=Mn(n),i=function(){ne(i),i.effectFunction=e,i.effectType=_,g.push(i);let c;try{c=e(i,g)}finally{g.pop(),ft(r,c)}};return i.fn=e,i.clockQueue=s,i.skipDependency=(a,c)=>a===n&&c==="time",i.scheduleClock=()=>{i.clockPending||(i.clockPending=!0,s.pending.add(i))},i.destroy=()=>jn(i),s.effects.add(i),F.set(r,i),i(),r}function $(e){W(e,"untracked");let t=g.length-1,n=g[t];g[t]=!1;try{return e()}finally{g[t]=n}}function Cn(e){if(typeof e=="boolean")return{deep:e};if(e===void 0)return{deep:!0};if(!e||typeof e!="object")throw new TypeError("simplyflow/state: clone() expects options to be a boolean or object");return{deep:e.deep!==!1}}function Pn(e){return e?.constructor?.name||Object.prototype.toString.call(e).slice(8,-1)}function Rn(e){let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null}function In(e){return ArrayBuffer.isView(e)&&!(e instanceof DataView)}function Nn(e){if(typeof e!="string"||e==="")return!1;let t=Number(e);return Number.isInteger(t)&&t>=0&&String(t)===e}function Hn(e){return typeof e.toClone=="function"}function Te(e,t){throw new TypeError(`simplyflow/state: clone() cannot clone ${Pn(e)} at ${t}; add a toClone() method for custom objects`)}function k(e,t,n,r=()=>!1){let s=Object.getOwnPropertyDescriptors(e);for(let i of Reflect.ownKeys(s)){if(r(i)){delete s[i];continue}let a=s[i];Object.hasOwn(a,"value")||Te(e,String(i)),a.value=n(a.value,String(i))}return Object.defineProperties(t,s),t}function $n(e){return e.slice(0)}function Vn(e){let t=new SharedArrayBuffer(e.byteLength);return new Uint8Array(t).set(new Uint8Array(e)),t}function Bn(e,t,n){new Set([Error,EvalError,RangeError,ReferenceError,SyntaxError,TypeError,URIError,typeof AggregateError>"u"?void 0:AggregateError]).has(e.constructor)||Te(e,n);let s=Object.hasOwn(e,"cause")?{cause:t(e.cause,"cause")}:void 0;if(typeof AggregateError<"u"&&e instanceof AggregateError){let i=Array.from(e.errors||[],(a,c)=>t(a,`errors.${c}`));return new AggregateError(i,e.message,s)}return new e.constructor(e.message,s)}function Se(e,t){let{deep:n}=Cn(t),r=new Map;function s(a,c){return n?i(a,c):w(a)}function i(a,c="value"){let o=w(a);if(!K(o))return o;if(r.has(o))return r.get(o);if(Hn(o)){let l=w(o.toClone());if(Object.is(l,o))throw new TypeError(`simplyflow/state: clone() toClone() returned the original object at ${c}`);return r.set(o,l),l}if(Array.isArray(o)){let l=new Array(o.length);return r.set(o,l),k(o,l,s,u=>u==="length")}if(Rn(o)){let l=Object.create(Object.getPrototypeOf(o));return r.set(o,l),k(o,l,s)}if(o instanceof Map){let l=new Map;return r.set(o,l),o.forEach((u,p)=>{l.set(s(p,"map key"),s(u,"map value"))}),k(o,l,s)}if(o instanceof Set){let l=new Set;return r.set(o,l),o.forEach(u=>l.add(s(u,"set value"))),k(o,l,s)}if(o instanceof Date){let l=new Date(o.getTime());return r.set(o,l),k(o,l,s)}if(o instanceof RegExp){let l=new RegExp(o.source,o.flags);return l.lastIndex=o.lastIndex,r.set(o,l),k(o,l,s,u=>u==="lastIndex")}if(o instanceof ArrayBuffer){let l=$n(o);return r.set(o,l),k(o,l,s)}if(typeof SharedArrayBuffer<"u"&&o instanceof SharedArrayBuffer){let l=Vn(o);return r.set(o,l),k(o,l,s)}if(o instanceof DataView){let l=o.buffer.slice(o.byteOffset,o.byteOffset+o.byteLength),u=new DataView(l);return r.set(o,u),k(o,u,s)}if(In(o)){let l=new o.constructor(o);return r.set(o,l),k(o,l,s,Nn)}if(typeof URL<"u"&&o instanceof URL){let l=new URL(o.href);return r.set(o,l),l}if(typeof URLSearchParams<"u"&&o instanceof URLSearchParams){let l=new URLSearchParams(o);return r.set(o,l),l}if(typeof File<"u"&&o instanceof File){let l=new File([o],o.name,{type:o.type,lastModified:o.lastModified});return r.set(o,l),l}if(typeof Blob<"u"&&o instanceof Blob){let l=o.slice(0,o.size,o.type);return r.set(o,l),l}if(o instanceof Error){let l=Bn(o,s,c);return r.set(o,l),k(o,l,s,u=>u==="message"||u==="cause"||u==="errors"||u==="stack")}if(typeof Node<"u"&&o instanceof Node&&typeof o.cloneNode=="function"){let l=o.cloneNode(n);return r.set(o,l),l}Te(o,c)}return i(e)}var Re={};we(Re,{findAttribute:()=>Jn,signal:()=>Pe,trackDomField:()=>T,trackDomList:()=>Ce});function P(e,t){return e.options.twoway||t.edit}function pt(e){if(e.templates?.length)Fn.call(this,e);else if(Object.hasOwnProperty.call(this.options.renderers,e.element.tagName)){let t=this.options.renderers[e.element.tagName];t&&t.call(this,e)}else this.options.renderers["*"]&&this.options.renderers["*"].call(this,e);return e}function mt(e){Array.isArray(e.value)||(e.value=[e.value]);let t=e.value.length;return e.templates?.length?Un.call(this,e):console.error("No templates found in",e.element),e}function yt(e){return typeof e.value!="object"||!e.value?console.error("Value is not an object.",e.element,e.path,e.value):e.templates?.length?xn.call(this,e):console.error("No templates found in",e.element),e}function Dn(e){if(parseInt(e)==e)return!0}function Oe(e,t,n,r={}){E(()=>{let s=t.split("."),i=e,a;a=s.shift();let c=null,o=null,l=i;for(;a&&i;){if(l=i,a=decodeURIComponent(a),!(a=="0"&&!Array.isArray(i))){if(a==":key")throw new Error("setting key not yet supported");a==":value"||(Array.isArray(i)&&!Dn(a)&&typeof i[a]>"u"?(c=i[0],i=i[0][a]):(c=i,i=i[a]))}if(o=a,a=s.shift(),a&&!i){let u=parseInt(a);u>=0&&a===""+u?l[o]=[]:l[o]={},i=l[o]}}if(c&&o&&r.replace)c[o]=n;else if(c&&o&&c[o]!==n)if(Array.isArray(n))c[o]=n;else if(n&&typeof n=="object"){i=c[o],i||(c[o]={},i=c[o]);for(let u in n)i[u]!==n[u]&&(i[u]=n[u])}else c[o]=n})}function Un(e){let t=this.options.attribute,n=[t+"-field",t+"-edit",t+"-list",t+"-map",t+"-value-path"],r="["+n.join("],[")+"]",s=t+"-key",i=Array.from(e.element.querySelectorAll(":scope > ["+s+"]")),a=new Set,c=0;e.list=e.value;for(let o=0;o<e.value.length;o++){e.index=o;let l=e.list[o],u=bt(i,a,c);if(!u){e.element.appendChild(this.applyTemplate(e));continue}let p=this.findTemplate(e.templates,l),h=u[d.VALUE]===l?u:gt(i,a,l,p,c+1);if(h){p!=h[d.TEMPLATE]?e.element.replaceChild(this.applyTemplate(e),h):(h!==u&&e.element.insertBefore(h,u),wt(h,o,e.path,s,n,r),h[d.VALUE]=l),a.add(h),h===u&&c++;continue}e.element.insertBefore(this.applyTemplate(e),u)}for(let o of i)a.has(o)||o.remove();this.options.twoway&&Ce.call(this,e.element)}function bt(e,t,n){for(;n<e.length;){let r=e[n];if(!t.has(r))return r;n++}}function gt(e,t,n,r,s){for(let i=s;i<e.length;i++){let a=e[i];if(!t.has(a)&&a[d.VALUE]===n&&a[d.TEMPLATE]===r)return a}}function wt(e,t,n,r,s,i){let a=e.getAttribute(r),c=""+t;if(a===c)return;e.setAttribute(r,c);let o=n+"."+a,l=n+"."+c,u=Array.from(e.querySelectorAll(i));e.matches(i)&&u.unshift(e);for(let p of u)for(let f of s){let h=p.getAttribute(f);!h||h.substr(0,5)===":root"||(h===o?p.setAttribute(f,l):h.startsWith(o+".")&&p.setAttribute(f,l+h.substr(o.length)))}}function xn(e){let t=this.options.attribute,n=[t+"-field",t+"-edit",t+"-list",t+"-map",t+"-value-path"],r="["+n.join("],[")+"]",s=t+"-key",i=Array.from(e.element.querySelectorAll(":scope > ["+s+"]")),a=new Set,c=0;e.list=e.value;for(let o in e.list){e.index=o;let l=e.list[o],u=bt(i,a,c);if(!u){e.element.appendChild(this.applyTemplate(e));continue}let p=this.findTemplate(e.templates,l),f;if(u.getAttribute(s)===o?f=u:f=qn(i,a,o,s)||gt(i,a,l,p,c),f){p!=f[d.TEMPLATE]?e.element.replaceChild(this.applyTemplate(e),f):(f!==u&&e.element.insertBefore(f,u),wt(f,o,e.path,s,n,r),f[d.VALUE]=l),a.add(f),f===u&&c++;continue}e.element.insertBefore(this.applyTemplate(e),u)}for(let o of i)a.has(o)||o.remove()}function qn(e,t,n,r){let s=""+n;for(let i of e)if(!t.has(i)&&i.getAttribute(r)===s)return i}function Fn(e){let t=e.element.querySelector(":scope > :not(template)"),n=this.findTemplate(e.templates,e.value);if(e.parent=Kn(e.element),t)if(n){if(t?.[d.TEMPLATE]!=n){let r=this.applyTemplate(e);e.element.replaceChild(r,t)}}else e.element.removeChild(t);else if(n){let r=this.applyTemplate(e);e.element.appendChild(r)}}function Kn(e,t){let n=e.parentElement?.closest(`[${t}-list],[${t}-map]`);return n?n.hasAttribute(`${t}-list`)?n.getAttribute(`${t}-list`)+".":n.getAttribute(`${t}-map`)+".":""}function Me(e){let t=e.element,n=e.value;n&&typeof n=="object"&&!Array.isArray(n)&&(V(t,n,"title","id","className","value","checked"),n=n.value),typeof n>"u"&&(n=""),t.type=="checkbox"?t.checked=Wn(t,n):t.type=="radio"?t.checked=j(t.value,n):j(t.value,n)||(t.value=""+n),P(this,e)&&(t.type=="checkbox"?T.call(this,e.element,["checked"],!0,"checked",_n,e):t.type=="radio"?T.call(this,e.element,["checked"],!0,"checked",zn,e):T.call(this,e.element,["value"],!0,"value",void 0,e))}function Wn(e,t){return Array.isArray(t)?t.some(n=>j(e.value,n)):typeof t=="boolean"?t:j(e.value,t)}function _n(e,t){if(Array.isArray(t)){let n=e.value,r=t.filter(s=>!j(s,n));return e.checked&&r.push(n),r}return typeof t=="boolean"?e.checked:e.checked&&j(e.value,t)?t:e.checked}function zn(e,t){if(e.checked)return e.value}function Et(e){se.call(this,e,"value")}function je(e){let t=e.element,n=e.value;if(n===null&&(n=""),Array.isArray(n))for(let r of t.options)r.selected=n.some(s=>j(r.value,s)),r.selected?r.setAttribute("selected",!0):r.removeAttribute("selected");else if(typeof n!="object"){let r=Array.from(t.options).find(s=>j(s.value,n));r&&(r.selected=!0,r.setAttribute("selected",!0))}else n.options&&Qn(t,n.options),typeof n.selected<"u"&&je.call(this,Object.assign({},e,{value:n.selected})),V(t,n,"name","id","selectedIndex","className");P(this,e)&&(t.multiple?T.call(this,e.element,["value"],!0,"value",Gn,e):T.call(this,e.element,["value"],!0,"value",void 0,e))}function Gn(e){let t=e.value;return Array.from(e.options).filter(n=>n.selected).map(n=>n.value)}function dt(e,t){t&&(typeof t!="object"?e.options.add(new Option(""+t)):t.text?e.options.add(new Option(t.text,t.value,t.defaultSelected,t.selected)):typeof t.value<"u"&&e.options.add(new Option(""+t.value,t.value,t.defaultSelected,t.selected)))}function Qn(e,t){if(e.innerHTML="",Array.isArray(t))for(let n of t)dt(e,n);else if(t&&typeof t=="object")for(let n in t)dt(e,{text:t[n],value:n})}function At(e){se.call(this,e,"target","href","name","newwindow","nofollow"),P(this,e)&&E(()=>{ie.call(this,e,["target","href","name","newwindow","nofollow"])})}function vt(e){V(e.element,e.value,"title","alt","src","id"),P(this,e)&&E(()=>{ie.call(this,e,["title","alt","src","id"])})}function kt(e){V(e.element,e.value,"title","src","id"),P(this,e)&&E(()=>{ie.call(this,e,["title","src","id"])})}function Tt(e){V(e.element,e.value,"content","id"),P(this,e)&&E(()=>{ie.call(this,e,["content","id"])})}function se(e,...t){let n=e.element,r=e.value,s=!1;if(typeof r<"u"&&r!==null){let a=""+r;(typeof r!="object"||a.substring(0,8)!="[object ")&&(r={innerHTML:r},s=!0)}let i=["innerHTML","title","id","className"].concat(t);V(n,r,...i),P(this,e)&&T.call(this,e.element,i,s,"innerHTML",void 0,e)}function V(e,t,...n){if(!(!t||typeof t!="object"))for(let r of n)typeof t[r]>"u"||j(e[r],t[r])||(t[r]===null?e[r]="":e[r]=""+t[r])}function ie(e,t){T.call(this,e.element,t,!1,"innerHTML",void 0,e)}function St(e,...t){let n={};for(let r of t)switch(r){default:n[r]=e[r];break}return n}function j(e,t){return e==":empty"&&!t||t==":empty"&&!e||""+e==""+t}var Lt=new WeakMap,Ot=new WeakMap,Xn={get:(e,t,n)=>{let r=e?.[t];return S(n,t),typeof r=="function"?r.bind(e):r&&typeof r=="object"?v(r):r},set:(e,t,n,r)=>{let s=e[t];e[t]=n;let i=e[t];return Object.is(s,i)||M(r,C(t,{was:s,now:i})),!0},has:(e,t)=>{let n=I(e);return n&&S(n,t),Reflect.has(e,t)},ownKeys:e=>{let t=I(e);return t&&S(t,d.ITERATE),Reflect.ownKeys(e)}};function Pe(e,t){if(b(e))return e;let n=I(e);return n||N(e,Xn,(r,s)=>{Yn(r,s,t)})}function Yn(e,t,n){n||(n={characterData:!0,subtree:!0,attributes:!0,attributesOldValue:!0,childList:!0});let s=e.innerHTML,i=e.innerText;if(!Ot.has(e)){let a=new MutationObserver((c,o)=>{let l={};for(let u of c)u.type==="attributes"?l[u.attributeName]=u.attributeOldValue:u.type==="subtree"||u.type==="characterData"?(e.innerHTML!=s&&(l.innerHTML=s,s=e.innerHTML),e.innerText!=i&&(l.innerText=i,i=e.innerText)):u.type==="childList"?(l.children={was:Array.from(e.children)},l.length=-1,e.innerHTML!=s&&(l.innerHTML=s,s=e.innerHTML),e.innerText!=i&&(l.innerText=i,i=e.innerText)):console.log("nothing to do for",e,u.type);for(let u in l)M(t,C(u,{was:l[u],now:e[u]}))});if(a.observe(e,n),Ot.set(e,a),e.matches("input, textarea, select")){let c=e.value,o=e.checked,l=()=>{M(t,C("value",{was:c,now:e.value})),c=e.value,"checked"in e&&(M(t,C("checked",{was:o,now:e.checked})),o=e.checked)};e.addEventListener("change",l),e.matches("input, textarea")&&e.addEventListener("input",l)}}}function Ce(e){let t=this.getBindingPath(e);if(!t)throw new Error("Could not find binding path for element",{cause:e});let n=Pe(e,{childList:!0});return y(()=>{let r=Array.from(n.children);$(()=>{E(()=>{let s=0,i=B(this.options.root,t),a=i.slice();for(let c of r)c.tagName!=="TEMPLATE"&&c.dataset.flowKey&&(c.dataset.flowKey!=s&&Oe(this.options.root,t+"."+s,a[c.dataset.flowKey]),s++);i.length>s&&(i.length=s)})})},50),n}function T(e,t,n,r="innerHTML",s,i){if(Lt.has(e))return;let a=this.getBindingPath(e);if(!a)throw new Error("Could not find binding path for element",{cause:e});let c=Pe(e);return Lt.set(e,c),E(()=>{y(()=>{let o;if(s)for(let l of t)c[l];else o=c[r],n||(o=St(c,...t));$(()=>{let l=B(this.options.root,a);s&&(o=s.call(this,c,l)),!(typeof o>"u")&&(o=this.extractValue?.(i,o,l)??o,!(typeof o>"u")&&(n&&!Object.is(l,o)&&String(l)===o||Oe(this.options.root,a,o,{replace:i?.replaceValue})))})},50)}),c}function Jn(e,t){return e.closest("["+t+"]")?.getAttribute(t)}var Pt={render(e,t){return typeof e.value!="string"||(er(e.element)?e.value={value:e.value}:e.value={innerHTML:tr(e.value)}),t(e)},extract(e,t){return typeof e.value=="string"?e.value=Mt(e.value):e.value&&typeof e.value=="object"&&(typeof e.value.innerHTML=="string"?e.value=Mt(e.value.innerHTML):typeof e.value.value=="string"&&(e.value=e.value.value)),t(e)}};function er(e){return e?.tagName==="INPUT"||e?.tagName==="TEXTAREA"}function tr(e){return String(e).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'")}function Mt(e){let t=document.createElement("textarea");return t.innerHTML=e,t.value}function Rt(e,t){typeof e.value=="string"?e.value={}:delete e.value?.innerHTML,t(e)}var It={render(e){let t=jt.call(this,e);return nr(e.element,e.value,t),e.edit&&T.call(this,e.element,t,!1,"innerHTML",()=>Ct(e.element,t),e),e},extract(e,t){let n=jt.call(this,e);return e.value=Ct(e.element,n),e.replaceValue=!0,t?t(e):e}};function jt(e){let t=this.options.attribute+"-attributes",n=e.element.getAttribute(t);return n?n.split(/[\s,]+/).filter(Boolean):e.value&&typeof e.value=="object"&&!Array.isArray(e.value)?Object.keys(e.value):e.currentValue&&typeof e.currentValue=="object"&&!Array.isArray(e.currentValue)?Object.keys(e.currentValue):[]}function nr(e,t,n){if(!(!n.length||!t||typeof t!="object"||Array.isArray(t)))for(let r of n){let s=t[r];typeof s>"u"||s===null?e.removeAttribute(r):e.getAttribute(r)!==""+s&&e.setAttribute(r,""+s)}}function Ct(e,t){let n={};for(let r of t)e.hasAttribute(r)&&(n[r]=e.getAttribute(r));return n}var Ie=class{constructor(t){this.bindings=new Map;let n={escape_html:Pt,fixed_content:Rt,attributes:It},r={container:document.body,attribute:"data-flow",transformers:n,render:{field:[pt],list:[mt],map:[yt]},renderers:{INPUT:Me,TEXTAREA:Me,BUTTON:Et,SELECT:je,A:At,IMG:vt,IFRAME:kt,META:Tt,TEMPLATE:null,"*":se},twoway:!1};if(!t?.root)throw new Error("bind needs at least options.root set");this.options=Object.assign({},r,t),t.transformers?this.options.transformers=Object.assign({},n,t?.transformers):this.options.transformers=n;let s=this.options.attribute,i=[s+"-field",s+"-edit",s+"-list",s+"-map"],a=f=>{let h=i.find(m=>f.hasAttribute(m));return h||console.error("No matching attribute found",f,i),h},c=f=>{this.bindings.set(f,y(()=>{if(!f.isConnected){Ne(f,this.getBindingPath(f));let m=this.bindings.get(f);m&&(H(m),this.bindings.delete(f));return}let h={templates:f.querySelectorAll(":scope > template"),attribute:a(f)};h.edit=h.attribute===this.options.attribute+"-edit",h.path=this.getBindingPath(f),h.value=B(this.options.root,h.path),h.element=f,rr(f,h),o(h)},50))},o=f=>{let h;switch(f.attribute){case this.options.attribute+"-field":case this.options.attribute+"-edit":h=Array.from(this.options.render.field);break;case this.options.attribute+"-list":h=Array.from(this.options.render.list);break;case this.options.attribute+"-map":h=Array.from(this.options.render.map);break;default:throw new Error("no valid context attribute specified",f)}h.push(...this.getNamedTransformers(f.element).map(m=>Nt(m,"render")).filter(Boolean)),Ht.call(this,h,f)},l=f=>{for(let h of f)this.bindings.get(h)||c(h)},u=f=>{let h=`[${s}-field],[${s}-edit],[${s}-list],[${s}-map]`;for(let m of f)if(m.type=="childList"&&m.addedNodes){for(let A of m.addedNodes)if(A instanceof HTMLElement){let D=Array.from(A.querySelectorAll(h));A.matches(h)&&D.unshift(A),D.length&&l(D)}}};this.observer=new MutationObserver(f=>{u(f)}),this.observer.observe(this.options.container,{subtree:!0,childList:!0});let p=this.options.container.querySelectorAll(":is(["+this.options.attribute+"-field],["+this.options.attribute+"-edit],["+this.options.attribute+"-list],["+this.options.attribute+"-map]):not(template)");try{p.length&&l(p)}catch(f){throw this.destroy(),f}}applyTemplate(t){let n=t.path,r=t.parent,s=t.templates,i=t.list,a=t.index,c=i?i[a]:t.value,o=this.findTemplate(s,c);if(!o){let h=new DocumentFragment;return h.innerHTML="<!-- no matching template -->",h}let l=o.content.cloneNode(!0);if(!l.children?.length)return l;if(l.children.length>1)throw new Error("template must contain a single root node",{cause:o});let u=this.options.attribute,p=[u+"-field",u+"-edit",u+"-list",u+"-map"],f=l.querySelectorAll(`[${u}-field],[${u}-edit],[${u}-list],[${u}-map]`);for(let h of f){if(h.tagName=="TEMPLATE")continue;let m=p.find(D=>h.hasAttribute(D)),A=h.getAttribute(m);A=this.applyLinks(o.links,A),A.substring(0,6)==":root."?h.setAttribute(m,A.substring(6)):A==":value"&&a!=null?h.setAttribute(m,n+"."+a):a!=null?h.setAttribute(m,n+"."+a+"."+A):h.setAttribute(m,r+A)}return this.applyTemplateCommandValues(l,o.links,n,a),typeof a<"u"&&l.children[0].setAttribute(u+"-key",a),l.children[0][d.TEMPLATE]=o,l.children[0][d.VALUE]=c,l}applyTemplateCommandValues(t,n,r,s){let i=this.options.attribute+"-value",a=this.options.attribute+"-value-path",c="["+i+"]",o=Array.from(t.querySelectorAll(c));for(let l of o){let u=l.getAttribute(i);u=this.applyLinks(n,u);let p=sr(u,r,s);p&&(Object.hasOwn(p,"path")?l.setAttribute(a,p.path):(l.setAttribute(i,p.value),l.removeAttribute(a)))}}parseLinks(t){let n={};t=t.split(";").map(r=>r.trim());for(let r of t)r=r.split("="),n[r[0].trim()]=r[1].trim();return n}applyLinks(t,n){for(let r in t){if(n.startsWith(r+"."))return t[r]+n.substr(r.length);if(n==r)return t[r]}return n}getBindingPath(t){let n=[this.options.attribute+"-field",this.options.attribute+"-edit",this.options.attribute+"-list",this.options.attribute+"-map"];for(let r of n)if(t.hasAttribute(r))return t.getAttribute(r)}getNamedTransformers(t){let n=this.options.attribute+"-transform";return t.hasAttribute(n)?t.getAttribute(n).split(" ").filter(Boolean).map(r=>{let s=this.options.transformers[r];return s||(console.warn("No transformer with name "+r+" configured",{cause:t}),null)}).filter(Boolean):[]}extractValue(t,n,r){if(!t?.element)return n;let s=this.getNamedTransformers(t.element).map(a=>Nt(a,"extract")).filter(Boolean).reverse();if(!s.length)return n;delete t.replaceValue;let i=Object.assign({},t,{value:n,currentValue:r,originalValue:r});return Ht.call(this,s,i),t.replaceValue=i.replaceValue,i.value}findTemplate(t,n){let r=c=>{let o=this.getBindingPath(c),l;o?o.substr(0,6)==":root."?l=B(this.options.root,o.substring(6)):l=B(n,o):l=n;let u=""+l,p=c.getAttribute(this.options.attribute+"-match");if(p){if(p===":empty"&&!l)return c;if(p===":notempty"&&l||u==p)return c}if(!p)return c},s=Array.from(t).find(r),i=null;s?.hasAttribute(this.options.attribute+"-link")&&(i=this.parseLinks(s.getAttribute(this.options.attribute+"-link")));let a=s?.getAttribute("rel");if(a){let c=document.querySelector("template#"+a);if(!c)throw new Error("Could not find template with id "+a);s=c}return s&&(s.links=i),s}destroy(){this.bindings.forEach((t,n)=>{Ne(n,this.getBindingPath(n)),H(t)}),this.bindings=new Map,this.observer.disconnect()}};function oe(e){return new Ie(e)}function Nt(e,t){return typeof e=="function"?t==="render"?e:null:e&&typeof e[t]=="function"?e[t]:null}function Ht(e,t){let n=r=>r;for(let r of e)n=((s,i)=>a=>i.call(this,a,s))(n,r);return n?.(t)}var R=new Map;function rr(e,t){Ne(e),R.has(t.path)?R.get(t.path).push(t):R.set(t.path,[t])}function Ne(e,t){if(t){let n=R.get(t);n&&(n=n.filter(r=>r.element!==e),R.set(t,n));return}R.forEach((n,r)=>{n=n.filter(s=>s.element!==e),R.set(r,n)})}function sr(e,t,n){return!e||e[0]!==":"?null:e===":key"?{value:""+n}:e===":value"?{path:$t(t,n)}:e.startsWith(":value.")?{path:Vt($t(t,n),e.substring(6))}:e.startsWith(":root.")?{path:e.substring(6)}:null}function $t(e,t){return typeof t>"u"?e:Vt(e,"."+t)}function Vt(e,t){return e?e+t:t.replace(/^\./,"")}function B(e,t){let n=t.split("."),r=e,s;s=n.shift();let i=null;for(;s&&r;)s=decodeURIComponent(s),s=="0"&&!Array.isArray(r)||(s==":key"?r=i:s==":value"||(Array.isArray(r)&&typeof r[s]>"u"&&r[0]?r=r[0][s]:r=r[s])),i=s,s=n.shift();return r}var Bt={};we(Bt,{columns:()=>De,filter:()=>Be,model:()=>ae,paging:()=>Ve,scroll:()=>Ue,sort:()=>$e});var He=class{constructor(t){if(!t)throw new Error("no options set");(t.data==null||typeof t.data[Symbol.iterator]!="function")&&console.warn("SimplyFlowModel: options.data is not iterable"),this.state=v(t),this.state.options||(this.state.options={}),this.effects=[{current:this.state.data}],this.view={current:this.state.data}}addEffect(t){if(!t||typeof t!="function")throw new Error("addEffect requires an effect function as its parameter",{cause:t});let n=this.effects[this.effects.length-1],r=t.call(this,n);if(!b(r))throw new Error("addEffect function parameter must return a Signal",{cause:t});this.view=r,this.effects.push(this.view)}};function ae(e){return new He(e)}function $e(e={}){return function(t){return this.state.options.sort=Object.assign({direction:"asc",sortBy:null,sortFn:(n,r)=>{let s=this.state.options.sort,i=s.sortBy;if(!s.sortBy)return 0;let a=s.sortDirection||s.direction||"asc",c=a=="asc"?1:-1,o=a=="asc"?-1:1;return typeof n?.[i]>"u"?typeof r?.[i]>"u"?0:c:typeof r?.[i]>"u"||n[i]<r[i]?o:n[i]>r[i]?c:0}},e),y(()=>{let n=this.state.options.sort,r=n?.sortDirection||n?.direction;if(n?.sortBy&&r){let s=n.sortFn,i=w(n).sortFn||s;return t.current.toSorted((a,c)=>i.call(this,a,c))}return t.current},50)}}function Ve(e={}){return function(t){return this.state.options.paging=Object.assign({page:1,pageSize:20,max:1},e),y(()=>E(()=>{let n=this.state.options.paging;n.pageSize||(n.pageSize=20),n.max=Math.ceil(t.current.length/n.pageSize),n.page=Math.max(1,Math.min(n.max,n.page));let r=(n.page-1)*n.pageSize,s=r+n.pageSize;return t.current.slice(r,s)}),50)}}function Be(e){if(!e?.name||typeof e.name!="string")throw new Error("filter requires options.name to be a string");if(!e.matches||typeof e.matches!="function")throw new Error("filter requires options.matches to be a function");return function(t){if(this.state.options[e.name])throw new Error("a filter with this name already exists on this model");return this.state.options[e.name]=e,y(()=>{let n=this.state.options[e.name];if(n.enabled){let r=n.matches,s=w(n).matches||r;return t.current.filter(i=>s.call(this,i))}return t.current},50)}}function De(e={}){let t=e?.columns&&typeof e.columns=="object"?e.columns:e;if(!t||typeof t!="object"||Object.keys(t).length===0)throw new Error("columns requires options to be an object with at least one property");return function(n){this.state.options.columns=t;let r=new WeakMap;return y(()=>{let s=[],i=new Set,a=this.state.options.columns;for(let c of Object.keys(a))a[c]?.visible!==!1&&(s.push(c),i.add(c));return n.current.map(c=>{let o=w(c),l=o&&typeof o=="object"?r.get(o):null;l||(l={},o&&typeof o=="object"&&r.set(o,l));for(let u of s){let p=c?.[u]??null;l[u]!==p&&(l[u]=p)}for(let u of Object.keys(l))i.has(u)||delete l[u];return l})},50)}}function Ue(e){return function(t){this.state.options.scroll=Object.assign({offset:0,rowHeight:26,rowCount:20,itemsPerRow:1,size:t.current.length},e);let n=this.state.options.scroll,r=n.scrollbar||n.container?.querySelector("[data-flow-scrollbar]");return r&&(n.container&&n.container.addEventListener("scroll",s=>{n.offset=Math.floor(n.container.scrollTop/(n.rowHeight*n.itemsPerRow))}),y(()=>{n.size=t.current.length*n.rowHeight,r.style.height=n.size+"px"},50)),y(()=>{n.container&&(n.rowCount=Math.ceil(n.container.getBoundingClientRect().height/n.rowHeight)),n.data=t.current;let s=Math.min(n.offset,t.current.length-1),i=s+n.rowCount;return i>t.current.length&&(i=t.current.length,s=i-n.rowCount),t.current.slice(s,i)},50)}}var xe=class extends HTMLElement{constructor(){super()}connectedCallback(){let t=this.getAttribute("rel"),n=document.getElementById(t);if(n){let r=n.content.cloneNode(!0);for(let s of r.childNodes){let i=s.cloneNode(!0);if(i.nodeType==document.ELEMENT_NODE&&(i.querySelectorAll("template").forEach(function(a){a.setAttribute("simply-render","")}),this.attributes))for(let a of this.attributes)a.name!="rel"&&i.setAttribute(a.name,a.value);this.parentNode.insertBefore(i,this)}this.parentNode.removeChild(this)}else(()=>{let s=new MutationObserver(()=>{n=document.getElementById(t),n&&(s.disconnect(),this.replaceWith(this))});s.observe(globalThis.document,{subtree:!0,childList:!0})})()}};customElements.get("simply-render")||customElements.define("simply-render",xe);function L(e,t,{maxDistance:n=2,minLength:r=4}={}){if(e.length<r)return;let s,i=1/0;for(let a of t){let c=ir(e,a,n);c<i&&(s=a,i=c)}return i<=n?s:void 0}function ir(e,t,n=2){let r=n+1;if(Math.abs(e.length-t.length)>n)return r;let s=Array.from({length:t.length+1},(a,c)=>c),i=new Array(t.length+1);for(let a=1;a<=e.length;a++){i[0]=a;for(let c=1;c<=t.length;c++){let o=e[a-1]===t[c-1]?0:1;i[c]=Math.min(s[c]+1,i[c-1]+1,s[c-1]+o)}s.splice(0,s.length,...i)}return s[t.length]}function ue(e){return new le(e)}var le=class{constructor(t={}){this.options=t,this.baseURL=t.baseURL||"/",this.app=t.app||{},this.addMissingSlash=!!t.addMissingSlash,this.matchExact=!!t.matchExact,this.hijackLinks=!!t.hijackLinks,this.clear(),t.routes&&this.load(t.routes)}load(t){mr(t,this.routeInfo,this.matchExact)}clear(){this.routeInfo=[],this.listeners={match:{},call:{},goto:{},finish:{}}}match(t,n){let r={path:t,options:n};r=this.runListeners("match",r),t=r.path?r.path:t;let s;if(t)s=fr(t);else{let i=document.location.pathname+document.location.hash;this.has(i)?t=i:t=document.location.pathname,s=new URLSearchParams(document.location.search)}t=ce(qe(t),this.baseURL);for(let i of this.routeInfo){let a=i.pattern.match(t);if(this.addMissingSlash&&!a&&t&&t[t.length-1]!="/"){let c=t+"/";a=i.pattern.match(c),a&&(t=c,history.replaceState({},"",Ut(t,this.baseURL)))}if(a)return Object.assign(a,n),r.route=i,r.params=a,r=this.runListeners("call",r),a=r.params?r.params:a,r.searchParams=s,r.result=or(this.app,i,a,s),this.runListeners("finish",r),r.result}return!1}runListeners(t,n){if(!(!this.listeners[t]||!Object.keys(this.listeners[t])))return Object.keys(this.listeners[t]).forEach(r=>{if(xt(r).match(qe(n.path))){var i;for(let a of this.listeners[t][r])i=a.call(this.app,n),i&&(n=i)}}),n}handleEvents(){this.removeEvents();let t=()=>{this.match()},n=r=>{if(!r.ctrlKey&&r.which==1){for(var s=r.target;s&&s.tagName!="A";)s=s.parentElement;if(s&&s.pathname&&s.hostname==globalThis.location.hostname&&!s.link&&!s.dataset.simplyCommand){let i=[{match:s.hash,goto:s.hash},{match:s.pathname+s.hash,goto:s.pathname+s.search+s.hash},{match:s.pathname,goto:s.pathname+s.search}],a;do a=i.shift(),a.match=ce(a.match,this.baseURL);while(i.length&&!this.has(a.match));if(this.has(a.match)){let c=this.runListeners("goto",{path:a.goto});if(c.path){let o=this.goto(c.path);if(!o||this.options.hijackLinks&&o!==!1)return r.preventDefault(),!1}}}}};globalThis.addEventListener("popstate",t),this.app.container.addEventListener("click",n),this.eventHandlers={container:this.app.container,popstateHandler:t,clickHandler:n}}removeEvents(){this.eventHandlers&&(globalThis.removeEventListener("popstate",this.eventHandlers.popstateHandler),this.eventHandlers.container.removeEventListener("click",this.eventHandlers.clickHandler),this.eventHandlers=void 0)}destroy(){this.removeEvents()}goto(t){return history.pushState({},"",Ut(t,this.baseURL)),this.match(t)}has(t){t=ce(qe(t),this.baseURL);for(let n of this.routeInfo)if(n.pattern.match(t))return!0;return!1}addListener(t,n,r){if(["goto","match","call","finish"].indexOf(t)==-1)throw new TypeError(`simplyflow/route: unknown listener type "${t}"`);this.listeners[t][n]||(this.listeners[t][n]=[]),this.listeners[t][n].push(r)}removeListener(t,n,r){if(["goto","match","call","finish"].indexOf(t)==-1)throw new TypeError(`simplyflow/route: unknown listener type "${t}"`);this.listeners[t][n]&&(this.listeners[t][n]=this.listeners[t][n].filter(s=>s!=r))}init(t){t.baseURL&&(this.baseURL=t.baseURL)}};function or(e,t,n,r){if(typeof t.action=="function")return t.action.call(e,n,r);if(typeof t.action=="string"){let s=e.actions?.[t.action];if(typeof s=="function")return s.call(e,ar(t,n,r));throw ur(t,e.actions)}throw new TypeError(`simplyflow/route: route "${t.path}" must use a function or action name`)}var Dt=new Set;function ar(e,t,n){let r=cr(n);for(let s of Object.keys(r))Object.hasOwn(t,s)&&lr(e,s);return Object.assign(r,t)}function cr(e){let t={};for(let[n,r]of e.entries())Object.hasOwn(t,n)?Array.isArray(t[n])?t[n].push(r):t[n]=[t[n],r]:t[n]=r;return t}function lr(e,t){let n=`${e.path}\0${t}`;Dt.has(n)||(Dt.add(n),console.warn(`simplyflow/route: query parameter "${t}" was ignored because route "${e.path}" already provides a route parameter with that name.`))}function ur(e,t){let n=L(e.action,Object.keys(t||{})),r=n?` Did you mean "${n}"?`:"";return new TypeError(`simplyflow/route: route "${e.path}" uses unknown action "${e.action}".${r}`)}function fr(e){let t=typeof e=="string"?e.indexOf("?"):-1;if(t===-1)return new URLSearchParams;let n=e.indexOf("#",t),r=n===-1?e.substring(t):e.substring(t,n);return new URLSearchParams(r)}function qe(e){let t=typeof e=="string"?e.indexOf("?"):-1;if(t===-1)return e;let n=e.indexOf("#",t);return n===-1?e.substring(0,t):e.substring(0,t)+e.substring(n)}function ce(e,t="/"){return(e.substring(0,t.length)==t||t[t.length-1]=="/"&&e.length==t.length-1&&e==t.substring(0,e.length))&&(e=e.substring(t.length)),e[0]!="/"&&(e="/"+e),e}function Ut(e,t){return e=ce(e,t),t[t.length-1]==="/"&&e[0]==="/"&&(e=e.substring(1)),e[0]=="#"?e:t+e}function xt(e,t=!1){let n=[],r=hr(e,t,n);return{path:e,params:n,regexp:r,match(s){let i=r.exec(s);if(!i)return null;let a={};return n.forEach((c,o)=>{a[c]=i[o+1]}),a}}}function hr(e,t=!1,n=[]){if(e.includes(":*"))throw new TypeError(`simplyflow/route: route "${e}" uses the old wildcard syntax ":*". Use a named wildcard like ":path*" instead.`);let r=e[0]==="#"?"":"^",s=t?"$":"";return new RegExp(r+dr(e,n)+s)}function dr(e,t){let n="",r=0;for(;r<e.length;){if(e[r]===":"){let s=/^:([A-Za-z_][A-Za-z0-9_]*)(\*)?/.exec(e.substring(r));if(!s)throw new TypeError(`simplyflow/route: invalid route parameter in "${e}"`);t.push(s[1]),n+=s[2]?"(.*)":"([^/]+)",r+=s[0].length;continue}if(e[r]==="*"){n+=".*",r++;continue}n+=pr(e[r]),r++}return n}function pr(e){return e.replace(/[\\^$.*+?()[\]{}|]/g,"\\$&")}function mr(e,t,n=!1){let r=Object.keys(e);for(let s of r)t.push({path:s,pattern:xt(s,n),action:e[s]});return t}var z={get(e,t){return typeof t!="string"?t:t?t.split(".").reduce(function(n,r){return n==null||!Reflect.has(Object(n),r)?null:n[r]},e):e},set:function(e,t,n){let r=z.get(e,z.parent(t));if(r==null)throw new TypeError(`simplyflow/path: cannot set "${t}" because its parent path does not exist`);r[z.pop(t)]=n},pop:function(e){return e.split(".").pop()},push:function(e,t){return(e?e+".":"")+t},parent:function(e){let t=e.split(".");return t.pop(),t.join(".")},parents:function(e,t){let n=[];for(;t;)t=z.parent(t),n.unshift(t);return n}},fe=z;var Ke=new WeakMap,yr=["commands","handlers","app","container"],We=class{constructor(t={}){t.app||(t.app={}),t.app.container||(t.app.container=document.body),this.app=t.app,this.$handlers=t.handlers||gr,t.commands&&Object.assign(this,t.commands);let n=s=>{let i=br(s,this.$handlers,this.app);if(!i)return;if(!this[i.name]){Ft(this,i.name,i.source);return}if(this[i.name].call(t.app,i.source,i.value,s)!==!0)return s.preventDefault(),s.stopPropagation(),!1},r=t.app.container;r.addEventListener("click",n),r.addEventListener("submit",n),r.addEventListener("change",n),r.addEventListener("input",n),Ke.set(this,{container:r,commandHandler:n})}call(t,n,r,s){if(!this[t]){Ft(this,t,n);return}return this[t].call(this.app,n,r,s)}appendHandler(t){this.$handlers.push(t)}prependHandler(t){this.$handlers.unshift(t)}};function he(e={}){return new We(e)}function Kt(e){let t=Ke.get(e);t&&(t.container.removeEventListener("click",t.commandHandler),t.container.removeEventListener("submit",t.commandHandler),t.container.removeEventListener("change",t.commandHandler),t.container.removeEventListener("input",t.commandHandler),Ke.delete(e))}function br(e,t,n){var r=e.target.closest("[data-simply-command]");if(r){for(let s of t)if(r.matches(s.match))return s.check(r,e)?{name:r.dataset.simplyCommand,source:r,value:s.get(r,n)}:null}return null}function Fe(e,t){let n="simplyValuePath";return Object.hasOwn(e.dataset,n)?{found:!0,value:fe.get(t?.data,e.dataset[n])}:Object.hasOwn(e.dataset,"simplyValue")?{found:!0,value:e.dataset.simplyValue}:{found:!1,value:void 0}}var gr=[{match:"input,select,textarea",get:function(e,t){let n=Fe(e,t);if(n.found)return n.value;if(e.tagName==="SELECT"&&e.multiple){let r=[];for(let s of e.options)s.selected&&r.push(s.value);return r}return e.value},check:function(e,t){return t.type=="change"||e.dataset.simplyImmediate&&t.type=="input"}},{match:"a,button",get:function(e,t){let n=Fe(e,t);return n.found?n.value:e.href||e.value},check:function(e,t){return t.type=="click"&&t.ctrlKey==!1&&t.button==0}},{match:"form",get:function(e){let t={};for(let n of Array.from(e.elements)){if(n.tagName=="INPUT"&&(n.type=="checkbox"||n.type=="radio")&&!n.checked)return;t[n.name]&&!Array.isArray(t[n.name])&&(t[n.name]=[t[n.name]]),Array.isArray(t[n.name])?t[n.name].push(n.value):t[n.name]=n.value}return t},check:function(e,t){return t.type=="submit"}},{match:"*",get:function(e,t){return Fe(e,t).value},check:function(e,t){return t.type=="click"&&t.ctrlKey==!1&&t.button==0}}],qt=new WeakMap;function Ft(e,t,n){let r=qt.get(e);if(r||(r=new Set,qt.set(e,r)),r.has(t))return;r.add(t);let s=L(t,wr(e)),i=s?`. Did you mean "${s}"?`:"";n?console.warn(`simplyflow/command: unknown command "${t}"${i}`,{cause:n}):console.warn(`simplyflow/command: unknown command "${t}"${i}`)}function wr(e){return Object.keys(e).filter(t=>!t.startsWith("$")&&!yr.includes(t)&&typeof e[t]=="function")}var Wt=new WeakMap;function de(e){if(e.app){let t={apply(r,s,i){try{let a=r(...i);return a instanceof Promise?a.catch(c=>e.app.onError.call(this,c,r)):a}catch(a){return e.app.onError.call(this,a,r)}}},n={get(r,s){if(!Object.hasOwn(r,s)){Er(r,s);return}return e.app.onError?new Proxy(r[s].bind(e.app),t):r[s].bind(e.app)}};return new Proxy(e.actions,n)}else return e}function Er(e,t){if(typeof t!="string")return;let n=Wt.get(e);if(n||(n=new Set,Wt.set(e,n)),n.has(t))return;n.add(t);let r=L(t,Object.keys(e)),s=r?`. Did you mean "${r}"?`:"";console.warn(`simplyflow/action: unknown action "${t}"${s}`)}var _e=new WeakMap,ze=new WeakMap,G=Object.freeze({Compose:229,Control:17,Meta:224,Alt:18,Shift:16}),Ge=class{constructor(t={}){t.app||(t.app={}),t.app.container||(t.app.container=document.body),Object.assign(this,t.shortcuts);let n=s=>{let i=[],a=s.target.closest("[data-simply-shortcuts]");for(;a;)i.push(a.dataset.simplyShortcuts),a=a.parentNode.closest("[data-simply-shortcuts]");i[i.length-1]!="default"&&i.push("default");let c,o=["+","-"];for(let l of o){let u=_t(s,l);for(let p in i){if(c=i[p],this[c]&&typeof this[c][u]=="function"&&!this[c][u].call(t.app,s)){s.preventDefault();return}if(typeof this[c+"."+u]=="function"&&!this[c+"."+u].call(t.app,s)){s.preventDefault();return}if(typeof this[u]=="function"&&!this[u].call(t.app,s)){s.preventDefault();return}}}},r=t.app.container;r.addEventListener("keydown",n),_e.set(this,{container:r,keyHandler:n})}};function _t(e,t="+"){if(e.isComposing||e.keyCode===G.Compose||e.defaultPrevented||!e.target)return;let n=[];return e.ctrlKey&&e.keyCode!=G.Control&&n.push("Control"),e.metaKey&&e.keyCode!=G.Meta&&n.push("Meta"),e.altKey&&e.keyCode!=G.Alt&&n.push("Alt"),e.shiftKey&&e.keyCode!=G.Shift&&n.push("Shift"),n.push(e.key.toLowerCase()),n.join(t)}function pe(e={}){return new Ge(e)}function zt(e){let t=_e.get(e);t&&(t.container.removeEventListener("keydown",t.keyHandler),_e.delete(e))}function Gt(e={}){let t=e.container||e.app?.container||document.body,n=s=>{let i=["+","-"];for(let a of i){let o="[data-simply-accesskey='"+_t(s,a)+"']",l=t.querySelectorAll(o);l.length&&l.forEach(function(u){u.click()})}};t.addEventListener("keydown",n);let r={};return ze.set(r,{container:t,keyHandler:n}),r}function Qt(e){let t=ze.get(e);t&&(t.container.removeEventListener("keydown",t.keyHandler),ze.delete(e))}var Zt="[data-simply-behavior]",Ze=class{constructor(t={}){this.app=t.app,this.container=t.container||document.body,this.behaviors=t.behaviors||{},this.active=new Set,this.cleanups=new WeakMap,this.unknown=new Set,this.observer=new MutationObserver(n=>this.handleChanges(n)),this.observer.observe(this.container,{subtree:!0,childList:!0});for(let n of Qe(this.container))this.start(n)}start(t){if(this.active.has(t))return;let n=t?.dataset?.simplyBehavior,r=this.behaviors[n];if(!n||typeof r!="function"){this.warnUnknown(n,t);return}this.active.add(t);let s=r.call(this.app||t,t);typeof s=="function"?this.cleanups.set(t,s):typeof s<"u"&&console.warn("simplyflow/behavior: behavior may only return a cleanup function",{cause:s})}stop(t){if(!this.active.has(t))return;this.active.delete(t);let n=this.cleanups.get(t);this.cleanups.delete(t),n&&n.call(this.app||t,t)}handleChanges(t){let n=[];for(let r of t)if(r.type==="childList"){for(let s of r.removedNodes)for(let i of Qe(s))this.stop(i);for(let s of r.addedNodes)n.push(...Qe(s))}for(let r of n)this.start(r)}warnUnknown(t,n){if(!t||this.unknown.has(t))return;this.unknown.add(t);let r=L(t,Object.keys(this.behaviors)),s=r?`. Did you mean "${r}"?`:"";console.warn(`simplyflow/behavior: unknown behavior "${t}"${s}`,{cause:n})}destroy(){this.observer.disconnect();for(let t of Array.from(this.active))this.stop(t)}};function me(e={}){return new Ze(e)}function Qe(e){if(!e?.querySelectorAll)return[];let t=Array.from(e.querySelectorAll(Zt));return e.matches?.(Zt)&&t.unshift(e),t}function Ar(e,t){let n=0;return function(...s){n||(n=globalThis.setTimeout(()=>{n=0,e.apply(this,s)},t))}}var vr=globalThis.requestIdleCallback?e=>{globalThis.requestIdleCallback(e,{timeout:500})}:globalThis.requestAnimationFrame||(e=>globalThis.setTimeout(e,0));function Xt(e,t,n){let r=new URL(e,t);return n&&r.searchParams.set("cb",n),r.href}function kr(e,t,n){let r=globalThis.document.createElement("script");for(let s of e.attributes)r.setAttribute(s.name,s.value);return r.removeAttribute("data-simply-location"),r.hasAttribute("src")?r.src=Xt(r.getAttribute("src"),t,n):r.textContent=e.textContent,r}function Yt(e,t){t.parentNode.insertBefore(e,t),t.parentNode.removeChild(t)}function Tr(e){return e.hasAttribute("src")&&!e.hasAttribute("async")}function Sr(e,t){return new Promise(n=>{let r=()=>{e.removeEventListener("load",r),e.removeEventListener("error",r),n()};e.addEventListener("load",r),e.addEventListener("error",r),Yt(e,t)})}function Lr(e){let t='link[rel="simply-include"],link[rel="simply-include-once"]',n=Array.from(e.querySelectorAll(t));return e.matches?.(t)&&n.unshift(e),n}var ye=class{constructor(t={}){this.container=t.container||globalThis.document,this.cacheBuster=t.cacheBuster??be,this.included=Object.create(null),this.scriptLocations=[],this.destroyed=!1,this.handleChanges=Ar(()=>{vr(()=>{this.destroyed||this.includeLinks(Lr(this.container))})},10),t.observe!==!1&&(this.observer=new MutationObserver(this.handleChanges),this.observer.observe(this.container,{subtree:!0,childList:!0}),this.handleChanges())}async scripts(t,n){let r=t.slice();for(let s of r){if(this.destroyed)return;let i=kr(s,n,this.cacheBuster),a=this.scriptLocations[s.dataset.simplyLocation];if(!a?.parentNode)continue;Tr(i)?(i.async=!1,await Sr(i,a)):Yt(i,a)}}html(t,n){let r=globalThis.document.createRange().createContextualFragment(t),s=r.querySelectorAll('link[rel="stylesheet"],style');for(let c of s){let o=c.getAttribute("href");o&&(c.href=Xt(o,n.href,this.cacheBuster)),globalThis.document.head.appendChild(c)}let i=globalThis.document.createDocumentFragment(),a=r.querySelectorAll("script");if(a.length){for(let c of a){let o=globalThis.document.createComment(c.src||"inline script");c.parentNode.insertBefore(o,c),c.dataset.simplyLocation=this.scriptLocations.length,this.scriptLocations.push(o),i.appendChild(c)}globalThis.setTimeout(()=>{this.scripts(Array.from(i.children),n?n.href:globalThis.location.href)},10)}n.parentNode.insertBefore(r,n)}async includeLinks(t){let n=t.reduce((r,s)=>(s.rel==="simply-include-once"&&this.included[s.href]?s.parentNode.removeChild(s):(this.included[s.href]=!0,s.rel="simply-include-loading",r.push(s)),r),[]);for(let r of n)if(!(this.destroyed||!r.href))try{let s=await fetch(r.href);if(!s.ok){console.warn(`simplyflow/include: failed to load "${r.href}" (${s.status})`),r.rel="simply-include-error";continue}let i=await s.text();if(this.destroyed||!r.parentNode)continue;this.html(i,r),r.parentNode?.removeChild(r)}catch(s){console.warn(`simplyflow/include: failed to load "${r.href}"`,{cause:s}),r.rel="simply-include-error"}}destroy(){this.destroyed=!0,this.observer?.disconnect(),this.observer=void 0}};function ge(e={}){return new ye(e)}var be=null,Xe=()=>new ye({container:globalThis.document,cacheBuster:be,observe:!1}),Jt={get cacheBuster(){return be},set cacheBuster(e){be=e},scripts:(e,t)=>Xe().scripts(e,t),html:(e,t)=>Xe().html(e,t),links:e=>Xe().includeLinks(Array.from(e))};var Or=["container","data","templates","styles","start","onError","components","behaviors","baseURL","commands","shortcuts","routes","actions","transformers"],Je=class{constructor(t={}){if(t.components){let n={};nn(n,t.components),et(n,t),t=n}this.container=t.container||document.body,this.destroyed=!1,this.data=v(t.data||{}),this.start=t.start,this.onError=t.onError,this.components=t.components,this.baseURL=t.baseURL,this.transformers=t.transformers,Mr(this.container,t.templates),jr(this.container,t.styles);for(let n of Object.keys(t))switch(n){case"container":case"data":case"templates":case"styles":case"start":case"onError":case"components":case"baseURL":case"transformers":break;case"commands":this.commands=he({app:this,container:this.container,commands:t.commands});break;case"shortcuts":this.shortcuts=pe({app:this,shortcuts:t.shortcuts});break;case"behaviors":this.behaviors=me({app:this,container:this.container,behaviors:t.behaviors});break;case"routes":this.routes=ue({app:this,routes:t.routes});break;case"actions":this.actions=de({app:this,actions:t.actions});break;case"prototype":case"__proto__":break;default:Cr(n),this[n]=t[n];break}this.binding=oe({root:this.data,container:this.container,attribute:"data-simply",transformers:this.transformers}),this.includes=ge({container:this.container}),this.accesskeys=Gt({app:this,container:this.container})}get app(){return this}destroy(){this.destroyed=!0,this.binding&&(this.binding.destroy(),this.binding=void 0),this.commands&&Kt(this.commands),this.shortcuts&&zt(this.shortcuts),this.accesskeys&&(Qt(this.accesskeys),this.accesskeys=void 0),this.routes&&(this.routes.destroy(),this.routes=void 0),this.behaviors&&(this.behaviors.destroy(),this.behaviors=void 0),this.includes&&(this.includes.destroy(),this.includes=void 0)}};function Mr(e,t){if(t)for(let n of Object.keys(t)){let r=document.createElement("div");r.innerHTML=t[n];let s=e.querySelector("template#"+n);s?s.content.replaceChildren(...r.children):(s=document.createElement("template"),s.id=n,s.content.append(...r.children),e.appendChild(s))}}function jr(e,t){if(t)for(let n of Object.keys(t)){let r=e.querySelector("style#"+n+".css");r||(r=document.createElement("style"),r.id=n+".css",e.appendChild(r)),r.innerHTML=t[n]}}function Cr(e){let t=L(e,Or);t&&console.warn(`simplyflow/app: unknown option "${e}". Did you mean "${t}"? The option was still added to the app as "app.${e}".`)}function Ye(e){e.destroyed||e.routes&&(e.baseURL&&e.routes.init({baseURL:e.baseURL}),e.routes.handleEvents(),globalThis.setTimeout(()=>{e.destroyed||!e.routes||(e.routes.has(globalThis.location?.hash)?e.routes.match(globalThis.location.hash):e.routes.match(globalThis.location?.pathname+globalThis.location?.hash))}))}function en(e,t,n){if(e.onError)return e.onError.call(e,t,n);throw t}function tn(e={}){let t=new Je(e);if(!t.start)return Ye(t),t;try{let n=t.start.call(t);n instanceof Promise?n.then(()=>Ye(t)).catch(r=>en(t,r,t.start)):Ye(t)}catch(n){en(t,n,t.start)}return t}function et(e,t){for(let n of Object.keys(t))switch(typeof t[n]){case"object":if(!t[n])continue;e[n]?et(e[n],t[n]):e[n]=t[n];break;default:e[n]=t[n]}}function nn(e,t){for(let n of Object.keys(t)){let r=t[n];r.components&&nn(e,r.components),e.components||(e.components={}),e.components[n]=r;for(let s of Object.keys(r))switch(s){case"start":case"onError":case"components":break;default:e[s]||(e[s]=Object.create(null)),et(e[s],r[s]);break}}}function tt(e,...t){return t.map((r,s)=>`${e[s]}${r}`).join("")+e[e.length-1]}function rn(e,...t){return tt(e,...t)}globalThis.simply||(globalThis.simply={});globalThis.html=tt;globalThis.css=rn;var Pr=Object.assign(ae,{model:ae,sort:$e,paging:Ve,filter:Be,columns:De,scroll:Ue});Object.assign(globalThis.simply,{app:tn,bind:oe,model:Pr,state:Le,signal:v,effect:re,batch:E,clone:Se,destroy:H,untracked:$,throttledEffect:y,clockEffect:_,createSignal:N,isSignal:b,raw:w,dom:Re,behaviors:me,actions:de,commands:he,include:Jt,includes:ge,shortcuts:pe,path:fe,routes:ue});delete globalThis.simply.advanced;var Hs=globalThis.simply;})();
|
|
2
2
|
//# sourceMappingURL=simply.flow.min.js.map
|