stillmade-sdk 0.1.48 → 0.1.49
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.
|
@@ -6,7 +6,7 @@ var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=
|
|
|
6
6
|
`).replace(_i,``)}function yi(e,t,n){if(t=vi(t),vi(e)!==t&&n)throw Error(r(425))}function bi(){}var xi=null,Si=null;function Ci(e,t){return e===`textarea`||e===`noscript`||typeof t.children==`string`||typeof t.children==`number`||typeof t.dangerouslySetInnerHTML==`object`&&t.dangerouslySetInnerHTML!==null&&t.dangerouslySetInnerHTML.__html!=null}var wi=typeof setTimeout==`function`?setTimeout:void 0,Ti=typeof clearTimeout==`function`?clearTimeout:void 0,Ei=typeof Promise==`function`?Promise:void 0,Di=typeof queueMicrotask==`function`?queueMicrotask:Ei===void 0?wi:function(e){return Ei.resolve(null).then(e).catch(Oi)};function Oi(e){setTimeout(function(){throw e})}function ki(e,t){var n=t,r=0;do{var i=n.nextSibling;if(e.removeChild(n),i&&i.nodeType===8){if(n=i.data,n===`/$`){if(r===0){e.removeChild(i),dn(t);return}r--}else n!==`$`&&n!==`$?`&&n!==`$!`||r++}n=i}while(n);dn(t)}function Ai(e){for(;e!=null;e=e.nextSibling){var t=e.nodeType;if(t===1||t===3)break;if(t===8){if(t=e.data,t===`$`||t===`$!`||t===`$?`)break;if(t===`/$`)return null}}return e}function ji(e){e=e.previousSibling;for(var t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`$`||n===`$!`||n===`$?`){if(t===0)return e;t--}else n===`/$`&&t++}e=e.previousSibling}return null}var Mi=Math.random().toString(36).slice(2),Ni=`__reactFiber$`+Mi,Pi=`__reactProps$`+Mi,Fi=`__reactContainer$`+Mi,Ii=`__reactEvents$`+Mi,Li=`__reactListeners$`+Mi,U=`__reactHandles$`+Mi;function Ri(e){var t=e[Ni];if(t)return t;for(var n=e.parentNode;n;){if(t=n[Fi]||n[Ni]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=ji(e);e!==null;){if(n=e[Ni])return n;e=ji(e)}return t}e=n,n=e.parentNode}return null}function zi(e){return e=e[Ni]||e[Fi],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Bi(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(r(33))}function Vi(e){return e[Pi]||null}var Hi=[],Ui=-1;function Wi(e){return{current:e}}function Gi(e){0>Ui||(e.current=Hi[Ui],Hi[Ui]=null,Ui--)}function Ki(e,t){Ui++,Hi[Ui]=e.current,e.current=t}var qi={},W=Wi(qi),Ji=Wi(!1),Yi=qi;function Xi(e,t){var n=e.type.contextTypes;if(!n)return qi;var r=e.stateNode;if(r&&r.__reactInternalMemoizedUnmaskedChildContext===t)return r.__reactInternalMemoizedMaskedChildContext;var i={},a;for(a in n)i[a]=t[a];return r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=t,e.__reactInternalMemoizedMaskedChildContext=i),i}function Zi(e){return e=e.childContextTypes,e!=null}function Qi(){Gi(Ji),Gi(W)}function $i(e,t,n){if(W.current!==qi)throw Error(r(168));Ki(W,t),Ki(Ji,n)}function ea(e,t,n){var i=e.stateNode;if(t=t.childContextTypes,typeof i.getChildContext!=`function`)return n;for(var a in i=i.getChildContext(),i)if(!(a in t))throw Error(r(108,ae(e)||`Unknown`,a));return R({},n,i)}function ta(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||qi,Yi=W.current,Ki(W,e),Ki(Ji,Ji.current),!0}function na(e,t,n){var i=e.stateNode;if(!i)throw Error(r(169));n?(e=ea(e,t,Yi),i.__reactInternalMemoizedMergedChildContext=e,Gi(Ji),Gi(W),Ki(W,e)):Gi(Ji),Ki(Ji,n)}var ra=null,ia=!1,aa=!1;function oa(e){ra===null?ra=[e]:ra.push(e)}function sa(e){ia=!0,oa(e)}function ca(){if(!aa&&ra!==null){aa=!0;var e=0,t=Bt;try{var n=ra;for(Bt=1;e<n.length;e++){var r=n[e];do r=r(!0);while(r!==null)}ra=null,ia=!1}catch(t){throw ra!==null&&(ra=ra.slice(e+1)),dt(V,ca),t}finally{Bt=t,aa=!1}}return null}var la=[],ua=0,da=null,fa=0,pa=[],ma=0,ha=null,ga=1,_a=``;function va(e,t){la[ua++]=fa,la[ua++]=da,da=e,fa=t}function ya(e,t,n){pa[ma++]=ga,pa[ma++]=_a,pa[ma++]=ha,ha=e;var r=ga;e=_a;var i=32-wt(r)-1;r&=~(1<<i),n+=1;var a=32-wt(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,ga=1<<32-wt(t)+i|n<<i|r,_a=a+e}else ga=1<<a|n<<i|r,_a=e}function ba(e){e.return!==null&&(va(e,1),ya(e,1,0))}function xa(e){for(;e===da;)da=la[--ua],la[ua]=null,fa=la[--ua],la[ua]=null;for(;e===ha;)ha=pa[--ma],pa[ma]=null,_a=pa[--ma],pa[ma]=null,ga=pa[--ma],pa[ma]=null}var Sa=null,Ca=null,wa=!1,Ta=null;function Ea(e,t){var n=eu(5,null,null,0);n.elementType=`DELETED`,n.stateNode=t,n.return=e,t=e.deletions,t===null?(e.deletions=[n],e.flags|=16):t.push(n)}function Da(e,t){switch(e.tag){case 5:var n=e.type;return t=t.nodeType!==1||n.toLowerCase()!==t.nodeName.toLowerCase()?null:t,t!==null&&(e.stateNode=t,Sa=e,Ca=Ai(t.firstChild),!0);case 6:return t=e.pendingProps===``||t.nodeType!==3?null:t,t!==null&&(e.stateNode=t,Sa=e,Ca=null,!0);case 13:return t=t.nodeType===8?t:null,t!==null&&(n=ha===null?null:{id:ga,overflow:_a},e.memoizedState={dehydrated:t,treeContext:n,retryLane:1073741824},n=eu(18,null,null,0),n.stateNode=t,n.return=e,e.child=n,Sa=e,Ca=null,!0);default:return!1}}function Oa(e){return!!(e.mode&1)&&!(e.flags&128)}function ka(e){if(wa){var t=Ca;if(t){var n=t;if(!Da(e,t)){if(Oa(e))throw Error(r(418));t=Ai(n.nextSibling);var i=Sa;t&&Da(e,t)?Ea(i,n):(e.flags=e.flags&-4097|2,wa=!1,Sa=e)}}else{if(Oa(e))throw Error(r(418));e.flags=e.flags&-4097|2,wa=!1,Sa=e}}}function Aa(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Sa=e}function ja(e){if(e!==Sa)return!1;if(!wa)return Aa(e),wa=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!==`head`&&t!==`body`&&!Ci(e.type,e.memoizedProps)),t&&=Ca){if(Oa(e))throw Ma(),Error(r(418));for(;t;)Ea(e,t),t=Ai(t.nextSibling)}if(Aa(e),e.tag===13){if(e=e.memoizedState,e=e===null?null:e.dehydrated,!e)throw Error(r(317));a:{for(e=e.nextSibling,t=0;e;){if(e.nodeType===8){var n=e.data;if(n===`/$`){if(t===0){Ca=Ai(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}Ca=null}}else Ca=Sa?Ai(e.stateNode.nextSibling):null;return!0}function Ma(){for(var e=Ca;e;)e=Ai(e.nextSibling)}function Na(){Ca=Sa=null,wa=!1}function Pa(e){Ta===null?Ta=[e]:Ta.push(e)}var Fa=C.ReactCurrentBatchConfig;function Ia(e,t,n){if(e=n.ref,e!==null&&typeof e!=`function`&&typeof e!=`object`){if(n._owner){if(n=n._owner,n){if(n.tag!==1)throw Error(r(309));var i=n.stateNode}if(!i)throw Error(r(147,e));var a=i,o=``+e;return t!==null&&t.ref!==null&&typeof t.ref==`function`&&t.ref._stringRef===o?t.ref:(t=function(e){var t=a.refs;e===null?delete t[o]:t[o]=e},t._stringRef=o,t)}if(typeof e!=`string`)throw Error(r(284));if(!n._owner)throw Error(r(290,e))}return e}function La(e,t){throw e=Object.prototype.toString.call(t),Error(r(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e))}function Ra(e){var t=e._init;return t(e._payload)}function za(e){function t(t,n){if(e){var r=t.deletions;r===null?(t.deletions=[n],t.flags|=16):r.push(n)}}function n(n,r){if(!e)return null;for(;r!==null;)t(n,r),r=r.sibling;return null}function i(e,t){for(e=new Map;t!==null;)t.key===null?e.set(t.index,t):e.set(t.key,t),t=t.sibling;return e}function a(e,t){return e=ru(e,t),e.index=0,e.sibling=null,e}function o(t,n,r){return t.index=r,e?(r=t.alternate,r===null?(t.flags|=2,n):(r=r.index,r<n?(t.flags|=2,n):r)):(t.flags|=1048576,n)}function s(t){return e&&t.alternate===null&&(t.flags|=2),t}function c(e,t,n,r){return t===null||t.tag!==6?(t=su(n,e.mode,r),t.return=e,t):(t=a(t,n),t.return=e,t)}function l(e,t,n,r){var i=n.type;return i===E?d(e,t,n.props.children,r,n.key):t!==null&&(t.elementType===i||typeof i==`object`&&i&&i.$$typeof===F&&Ra(i)===t.type)?(r=a(t,n.props),r.ref=Ia(e,t,n),r.return=e,r):(r=iu(n.type,n.key,n.props,null,e.mode,r),r.ref=Ia(e,t,n),r.return=e,r)}function u(e,t,n,r){return t===null||t.tag!==4||t.stateNode.containerInfo!==n.containerInfo||t.stateNode.implementation!==n.implementation?(t=cu(n,e.mode,r),t.return=e,t):(t=a(t,n.children||[]),t.return=e,t)}function d(e,t,n,r,i){return t===null||t.tag!==7?(t=au(n,e.mode,r,i),t.return=e,t):(t=a(t,n),t.return=e,t)}function f(e,t,n){if(typeof t==`string`&&t!==``||typeof t==`number`)return t=su(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case w:return n=iu(t.type,t.key,t.props,null,e.mode,n),n.ref=Ia(e,null,t),n.return=e,n;case T:return t=cu(t,e.mode,n),t.return=e,t;case F:var r=t._init;return f(e,r(t._payload),n)}if(ve(t)||ee(t))return t=au(t,e.mode,n,null),t.return=e,t;La(e,t)}return null}function p(e,t,n,r){var i=t===null?null:t.key;if(typeof n==`string`&&n!==``||typeof n==`number`)return i===null?c(e,t,``+n,r):null;if(typeof n==`object`&&n){switch(n.$$typeof){case w:return n.key===i?l(e,t,n,r):null;case T:return n.key===i?u(e,t,n,r):null;case F:return i=n._init,p(e,t,i(n._payload),r)}if(ve(n)||ee(n))return i===null?d(e,t,n,r,null):null;La(e,n)}return null}function m(e,t,n,r,i){if(typeof r==`string`&&r!==``||typeof r==`number`)return e=e.get(n)||null,c(t,e,``+r,i);if(typeof r==`object`&&r){switch(r.$$typeof){case w:return e=e.get(r.key===null?n:r.key)||null,l(t,e,r,i);case T:return e=e.get(r.key===null?n:r.key)||null,u(t,e,r,i);case F:var a=r._init;return m(e,t,n,a(r._payload),i)}if(ve(r)||ee(r))return e=e.get(n)||null,d(t,e,r,i,null);La(t,r)}return null}function h(r,a,s,c){for(var l=null,u=null,d=a,h=a=0,g=null;d!==null&&h<s.length;h++){d.index>h?(g=d,d=null):g=d.sibling;var _=p(r,d,s[h],c);if(_===null){d===null&&(d=g);break}e&&d&&_.alternate===null&&t(r,d),a=o(_,a,h),u===null?l=_:u.sibling=_,u=_,d=g}if(h===s.length)return n(r,d),wa&&va(r,h),l;if(d===null){for(;h<s.length;h++)d=f(r,s[h],c),d!==null&&(a=o(d,a,h),u===null?l=d:u.sibling=d,u=d);return wa&&va(r,h),l}for(d=i(r,d);h<s.length;h++)g=m(d,r,h,s[h],c),g!==null&&(e&&g.alternate!==null&&d.delete(g.key===null?h:g.key),a=o(g,a,h),u===null?l=g:u.sibling=g,u=g);return e&&d.forEach(function(e){return t(r,e)}),wa&&va(r,h),l}function g(a,s,c,l){var u=ee(c);if(typeof u!=`function`)throw Error(r(150));if(c=u.call(c),c==null)throw Error(r(151));for(var d=u=null,h=s,g=s=0,_=null,v=c.next();h!==null&&!v.done;g++,v=c.next()){h.index>g?(_=h,h=null):_=h.sibling;var y=p(a,h,v.value,l);if(y===null){h===null&&(h=_);break}e&&h&&y.alternate===null&&t(a,h),s=o(y,s,g),d===null?u=y:d.sibling=y,d=y,h=_}if(v.done)return n(a,h),wa&&va(a,g),u;if(h===null){for(;!v.done;g++,v=c.next())v=f(a,v.value,l),v!==null&&(s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return wa&&va(a,g),u}for(h=i(a,h);!v.done;g++,v=c.next())v=m(h,a,g,v.value,l),v!==null&&(e&&v.alternate!==null&&h.delete(v.key===null?g:v.key),s=o(v,s,g),d===null?u=v:d.sibling=v,d=v);return e&&h.forEach(function(e){return t(a,e)}),wa&&va(a,g),u}function _(e,r,i,o){if(typeof i==`object`&&i&&i.type===E&&i.key===null&&(i=i.props.children),typeof i==`object`&&i){switch(i.$$typeof){case w:a:{for(var c=i.key,l=r;l!==null;){if(l.key===c){if(c=i.type,c===E){if(l.tag===7){n(e,l.sibling),r=a(l,i.props.children),r.return=e,e=r;break a}}else if(l.elementType===c||typeof c==`object`&&c&&c.$$typeof===F&&Ra(c)===l.type){n(e,l.sibling),r=a(l,i.props),r.ref=Ia(e,l,i),r.return=e,e=r;break a}n(e,l);break}t(e,l),l=l.sibling}i.type===E?(r=au(i.props.children,e.mode,o,i.key),r.return=e,e=r):(o=iu(i.type,i.key,i.props,null,e.mode,o),o.ref=Ia(e,r,i),o.return=e,e=o)}return s(e);case T:a:{for(l=i.key;r!==null;){if(r.key===l){if(r.tag===4&&r.stateNode.containerInfo===i.containerInfo&&r.stateNode.implementation===i.implementation){n(e,r.sibling),r=a(r,i.children||[]),r.return=e,e=r;break a}n(e,r);break}t(e,r),r=r.sibling}r=cu(i,e.mode,o),r.return=e,e=r}return s(e);case F:return l=i._init,_(e,r,l(i._payload),o)}if(ve(i))return h(e,r,i,o);if(ee(i))return g(e,r,i,o);La(e,i)}return typeof i==`string`&&i!==``||typeof i==`number`?(i=``+i,r!==null&&r.tag===6?(n(e,r.sibling),r=a(r,i),r.return=e,e=r):(n(e,r),r=su(i,e.mode,o),r.return=e,e=r),s(e)):n(e,r)}return _}var Ba=za(!0),Va=za(!1),Ha=Wi(null),Ua=null,Wa=null,Ga=null;function Ka(){Ga=Wa=Ua=null}function qa(e){var t=Ha.current;Gi(Ha),e._currentValue=t}function Ja(e,t,n){for(;e!==null;){var r=e.alternate;if((e.childLanes&t)===t?r!==null&&(r.childLanes&t)!==t&&(r.childLanes|=t):(e.childLanes|=t,r!==null&&(r.childLanes|=t)),e===n)break;e=e.return}}function Ya(e,t){Ua=e,Ga=Wa=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(zs=!0),e.firstContext=null)}function Xa(e){var t=e._currentValue;if(Ga!==e){if(e={context:e,memoizedValue:t,next:null},Wa===null){if(Ua===null)throw Error(r(308));Wa=e,Ua.dependencies={lanes:0,firstContext:e}}else Wa=Wa.next=e}return t}var Za=null;function Qa(e){Za===null?Za=[e]:Za.push(e)}function $a(e,t,n,r){var i=t.interleaved;return i===null?(n.next=n,Qa(t)):(n.next=i.next,i.next=n),t.interleaved=n,eo(e,r)}function eo(e,t){e.lanes|=t;var n=e.alternate;for(n!==null&&(n.lanes|=t),n=e,e=e.return;e!==null;)e.childLanes|=t,n=e.alternate,n!==null&&(n.childLanes|=t),n=e,e=e.return;return n.tag===3?n.stateNode:null}var to=!1;function no(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function ro(e,t){e=e.updateQueue,t.updateQueue===e&&(t.updateQueue={baseState:e.baseState,firstBaseUpdate:e.firstBaseUpdate,lastBaseUpdate:e.lastBaseUpdate,shared:e.shared,effects:e.effects})}function io(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function ao(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Yc&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,eo(e,n)}return i=r.interleaved,i===null?(t.next=t,Qa(r)):(t.next=i.next,i.next=t),r.interleaved=t,eo(e,n)}function oo(e,t,n){if(t=t.updateQueue,t!==null&&(t=t.shared,n&4194240)){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,zt(e,n)}}function so(e,t){var n=e.updateQueue,r=e.alternate;if(r!==null&&(r=r.updateQueue,n===r)){var i=null,a=null;if(n=n.firstBaseUpdate,n!==null){do{var o={eventTime:n.eventTime,lane:n.lane,tag:n.tag,payload:n.payload,callback:n.callback,next:null};a===null?i=a=o:a=a.next=o,n=n.next}while(n!==null);a===null?i=a=t:a=a.next=t}else i=a=t;n={baseState:r.baseState,firstBaseUpdate:i,lastBaseUpdate:a,shared:r.shared,effects:r.effects},e.updateQueue=n;return}e=n.lastBaseUpdate,e===null?n.firstBaseUpdate=t:e.next=t,n.lastBaseUpdate=t}function co(e,t,n,r){var i=e.updateQueue;to=!1;var a=i.firstBaseUpdate,o=i.lastBaseUpdate,s=i.shared.pending;if(s!==null){i.shared.pending=null;var c=s,l=c.next;c.next=null,o===null?a=l:o.next=l,o=c;var u=e.alternate;u!==null&&(u=u.updateQueue,s=u.lastBaseUpdate,s!==o&&(s===null?u.firstBaseUpdate=l:s.next=l,u.lastBaseUpdate=c))}if(a!==null){var d=i.baseState;o=0,u=l=c=null,s=a;do{var f=s.lane,p=s.eventTime;if((r&f)===f){u!==null&&(u=u.next={eventTime:p,lane:0,tag:s.tag,payload:s.payload,callback:s.callback,next:null});a:{var m=e,h=s;switch(f=t,p=n,h.tag){case 1:if(m=h.payload,typeof m==`function`){d=m.call(p,d,f);break a}d=m;break a;case 3:m.flags=m.flags&-65537|128;case 0:if(m=h.payload,f=typeof m==`function`?m.call(p,d,f):m,f==null)break a;d=R({},d,f);break a;case 2:to=!0}}s.callback!==null&&s.lane!==0&&(e.flags|=64,f=i.effects,f===null?i.effects=[s]:f.push(s))}else p={eventTime:p,lane:f,tag:s.tag,payload:s.payload,callback:s.callback,next:null},u===null?(l=u=p,c=d):u=u.next=p,o|=f;if(s=s.next,s===null){if(s=i.shared.pending,s===null)break;f=s,s=f.next,f.next=null,i.lastBaseUpdate=f,i.shared.pending=null}}while(1);if(u===null&&(c=d),i.baseState=c,i.firstBaseUpdate=l,i.lastBaseUpdate=u,t=i.shared.interleaved,t!==null){i=t;do o|=i.lane,i=i.next;while(i!==t)}else a===null&&(i.shared.lanes=0);rl|=o,e.lanes=o,e.memoizedState=d}}function lo(e,t,n){if(e=t.effects,t.effects=null,e!==null)for(t=0;t<e.length;t++){var i=e[t],a=i.callback;if(a!==null){if(i.callback=null,i=n,typeof a!=`function`)throw Error(r(191,a));a.call(i)}}}var uo={},fo=Wi(uo),po=Wi(uo),mo=Wi(uo);function ho(e){if(e===uo)throw Error(r(174));return e}function go(e,t){switch(Ki(mo,t),Ki(po,e),Ki(fo,uo),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Te(null,``);break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Te(t,e)}Gi(fo),Ki(fo,t)}function _o(){Gi(fo),Gi(po),Gi(mo)}function vo(e){ho(mo.current);var t=ho(fo.current),n=Te(t,e.type);t!==n&&(Ki(po,e),Ki(fo,n))}function yo(e){po.current===e&&(Gi(fo),Gi(po))}var bo=Wi(0);function xo(e){for(var t=e;t!==null;){if(t.tag===13){var n=t.memoizedState;if(n!==null&&(n=n.dehydrated,n===null||n.data===`$?`||n.data===`$!`))return t}else if(t.tag===19&&t.memoizedProps.revealOrder!==void 0){if(t.flags&128)return t}else if(t.child!==null){t.child.return=t,t=t.child;continue}if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return null;t=t.return}t.sibling.return=t.return,t=t.sibling}return null}var So=[];function Co(){for(var e=0;e<So.length;e++)So[e]._workInProgressVersionPrimary=null;So.length=0}var wo=C.ReactCurrentDispatcher,To=C.ReactCurrentBatchConfig,Eo=0,Do=null,Oo=null,ko=null,Ao=!1,jo=!1,Mo=0,No=0;function Po(){throw Error(r(321))}function Fo(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!Or(e[n],t[n]))return!1;return!0}function Io(e,t,n,i,a,o){if(Eo=o,Do=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,wo.current=e===null||e.memoizedState===null?ys:bs,e=n(i,a),jo){o=0;do{if(jo=!1,Mo=0,25<=o)throw Error(r(301));o+=1,ko=Oo=null,t.updateQueue=null,wo.current=xs,e=n(i,a)}while(jo)}if(wo.current=vs,t=Oo!==null&&Oo.next!==null,Eo=0,ko=Oo=Do=null,Ao=!1,t)throw Error(r(300));return e}function Lo(){var e=Mo!==0;return Mo=0,e}function Ro(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return ko===null?Do.memoizedState=ko=e:ko=ko.next=e,ko}function zo(){if(Oo===null){var e=Do.alternate;e=e===null?null:e.memoizedState}else e=Oo.next;var t=ko===null?Do.memoizedState:ko.next;if(t!==null)ko=t,Oo=e;else{if(e===null)throw Error(r(310));Oo=e,e={memoizedState:Oo.memoizedState,baseState:Oo.baseState,baseQueue:Oo.baseQueue,queue:Oo.queue,next:null},ko===null?Do.memoizedState=ko=e:ko=ko.next=e}return ko}function Bo(e,t){return typeof t==`function`?t(e):t}function Vo(e){var t=zo(),n=t.queue;if(n===null)throw Error(r(311));n.lastRenderedReducer=e;var i=Oo,a=i.baseQueue,o=n.pending;if(o!==null){if(a!==null){var s=a.next;a.next=o.next,o.next=s}i.baseQueue=a=o,n.pending=null}if(a!==null){o=a.next,i=i.baseState;var c=s=null,l=null,u=o;do{var d=u.lane;if((Eo&d)===d)l!==null&&(l=l.next={lane:0,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null}),i=u.hasEagerState?u.eagerState:e(i,u.action);else{var f={lane:d,action:u.action,hasEagerState:u.hasEagerState,eagerState:u.eagerState,next:null};l===null?(c=l=f,s=i):l=l.next=f,Do.lanes|=d,rl|=d}u=u.next}while(u!==null&&u!==o);l===null?s=i:l.next=c,Or(i,t.memoizedState)||(zs=!0),t.memoizedState=i,t.baseState=s,t.baseQueue=l,n.lastRenderedState=i}if(e=n.interleaved,e!==null){a=e;do o=a.lane,Do.lanes|=o,rl|=o,a=a.next;while(a!==e)}else a===null&&(n.lanes=0);return[t.memoizedState,n.dispatch]}function Ho(e){var t=zo(),n=t.queue;if(n===null)throw Error(r(311));n.lastRenderedReducer=e;var i=n.dispatch,a=n.pending,o=t.memoizedState;if(a!==null){n.pending=null;var s=a=a.next;do o=e(o,s.action),s=s.next;while(s!==a);Or(o,t.memoizedState)||(zs=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,i]}function Uo(){}function Wo(e,t){var n=Do,i=zo(),a=t(),o=!Or(i.memoizedState,a);if(o&&(i.memoizedState=a,zs=!0),i=i.queue,ns(qo.bind(null,n,i,e),[e]),i.getSnapshot!==t||o||ko!==null&&ko.memoizedState.tag&1){if(n.flags|=2048,Zo(9,Ko.bind(null,n,i,a,t),void 0,null),Xc===null)throw Error(r(349));Eo&30||Go(n,t,a)}return a}function Go(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=Do.updateQueue,t===null?(t={lastEffect:null,stores:null},Do.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function Ko(e,t,n,r){t.value=n,t.getSnapshot=r,Jo(t)&&Yo(e)}function qo(e,t,n){return n(function(){Jo(t)&&Yo(e)})}function Jo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!Or(e,n)}catch{return!0}}function Yo(e){var t=eo(e,1);t!==null&&Sl(t,e,1,-1)}function Xo(e){var t=Ro();return typeof e==`function`&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Bo,lastRenderedState:e},t.queue=e,e=e.dispatch=ms.bind(null,Do,e),[t.memoizedState,e]}function Zo(e,t,n,r){return e={tag:e,create:t,destroy:n,deps:r,next:null},t=Do.updateQueue,t===null?(t={lastEffect:null,stores:null},Do.updateQueue=t,t.lastEffect=e.next=e):(n=t.lastEffect,n===null?t.lastEffect=e.next=e:(r=n.next,n.next=e,e.next=r,t.lastEffect=e)),e}function Qo(){return zo().memoizedState}function $o(e,t,n,r){var i=Ro();Do.flags|=e,i.memoizedState=Zo(1|t,n,void 0,r===void 0?null:r)}function es(e,t,n,r){var i=zo();r=r===void 0?null:r;var a=void 0;if(Oo!==null){var o=Oo.memoizedState;if(a=o.destroy,r!==null&&Fo(r,o.deps)){i.memoizedState=Zo(t,n,a,r);return}}Do.flags|=e,i.memoizedState=Zo(1|t,n,a,r)}function ts(e,t){return $o(8390656,8,e,t)}function ns(e,t){return es(2048,8,e,t)}function rs(e,t){return es(4,2,e,t)}function is(e,t){return es(4,4,e,t)}function as(e,t){if(typeof t==`function`)return e=e(),t(e),function(){t(null)};if(t!=null)return e=e(),t.current=e,function(){t.current=null}}function os(e,t,n){return n=n==null?null:n.concat([e]),es(4,4,as.bind(null,t,e),n)}function ss(){}function cs(e,t){var n=zo();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&Fo(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function ls(e,t){var n=zo();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&Fo(t,r[1])?r[0]:(e=e(),n.memoizedState=[e,t],e)}function us(e,t,n){return Eo&21?(Or(n,t)||(n=Ft(),Do.lanes|=n,rl|=n,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,zs=!0),e.memoizedState=n)}function ds(e,t){var n=Bt;Bt=n!==0&&4>n?n:4,e(!0);var r=To.transition;To.transition={};try{e(!1),t()}finally{Bt=n,To.transition=r}}function fs(){return zo().memoizedState}function ps(e,t,n){var r=xl(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},hs(e))gs(t,n);else if(n=$a(e,t,n,r),n!==null){var i=bl();Sl(n,e,r,i),_s(n,t,r)}}function ms(e,t,n){var r=xl(e),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(hs(e))gs(t,i);else{var a=e.alternate;if(e.lanes===0&&(a===null||a.lanes===0)&&(a=t.lastRenderedReducer,a!==null))try{var o=t.lastRenderedState,s=a(o,n);if(i.hasEagerState=!0,i.eagerState=s,Or(s,o)){var c=t.interleaved;c===null?(i.next=i,Qa(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}n=$a(e,t,i,r),n!==null&&(i=bl(),Sl(n,e,r,i),_s(n,t,r))}}function hs(e){var t=e.alternate;return e===Do||t!==null&&t===Do}function gs(e,t){jo=Ao=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function _s(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,zt(e,n)}}var vs={readContext:Xa,useCallback:Po,useContext:Po,useEffect:Po,useImperativeHandle:Po,useInsertionEffect:Po,useLayoutEffect:Po,useMemo:Po,useReducer:Po,useRef:Po,useState:Po,useDebugValue:Po,useDeferredValue:Po,useTransition:Po,useMutableSource:Po,useSyncExternalStore:Po,useId:Po,unstable_isNewReconciler:!1},ys={readContext:Xa,useCallback:function(e,t){return Ro().memoizedState=[e,t===void 0?null:t],e},useContext:Xa,useEffect:ts,useImperativeHandle:function(e,t,n){return n=n==null?null:n.concat([e]),$o(4194308,4,as.bind(null,t,e),n)},useLayoutEffect:function(e,t){return $o(4194308,4,e,t)},useInsertionEffect:function(e,t){return $o(4,2,e,t)},useMemo:function(e,t){var n=Ro();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=Ro();return t=n===void 0?t:n(t),r.memoizedState=r.baseState=t,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:e,lastRenderedState:t},r.queue=e,e=e.dispatch=ps.bind(null,Do,e),[r.memoizedState,e]},useRef:function(e){var t=Ro();return e={current:e},t.memoizedState=e},useState:Xo,useDebugValue:ss,useDeferredValue:function(e){return Ro().memoizedState=e},useTransition:function(){var e=Xo(!1),t=e[0];return e=ds.bind(null,e[1]),Ro().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var i=Do,a=Ro();if(wa){if(n===void 0)throw Error(r(407));n=n()}else{if(n=t(),Xc===null)throw Error(r(349));Eo&30||Go(i,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,ts(qo.bind(null,i,o,e),[e]),i.flags|=2048,Zo(9,Ko.bind(null,i,o,n,t),void 0,null),n},useId:function(){var e=Ro(),t=Xc.identifierPrefix;if(wa){var n=_a,r=ga;n=(r&~(1<<32-wt(r)-1)).toString(32)+n,t=`:`+t+`R`+n,n=Mo++,0<n&&(t+=`H`+n.toString(32)),t+=`:`}else n=No++,t=`:`+t+`r`+n.toString(32)+`:`;return e.memoizedState=t},unstable_isNewReconciler:!1},bs={readContext:Xa,useCallback:cs,useContext:Xa,useEffect:ns,useImperativeHandle:os,useInsertionEffect:rs,useLayoutEffect:is,useMemo:ls,useReducer:Vo,useRef:Qo,useState:function(){return Vo(Bo)},useDebugValue:ss,useDeferredValue:function(e){return us(zo(),Oo.memoizedState,e)},useTransition:function(){return[Vo(Bo)[0],zo().memoizedState]},useMutableSource:Uo,useSyncExternalStore:Wo,useId:fs,unstable_isNewReconciler:!1},xs={readContext:Xa,useCallback:cs,useContext:Xa,useEffect:ns,useImperativeHandle:os,useInsertionEffect:rs,useLayoutEffect:is,useMemo:ls,useReducer:Ho,useRef:Qo,useState:function(){return Ho(Bo)},useDebugValue:ss,useDeferredValue:function(e){var t=zo();return Oo===null?t.memoizedState=e:us(t,Oo.memoizedState,e)},useTransition:function(){return[Ho(Bo)[0],zo().memoizedState]},useMutableSource:Uo,useSyncExternalStore:Wo,useId:fs,unstable_isNewReconciler:!1};function Ss(e,t){if(e&&e.defaultProps){for(var n in t=R({},t),e=e.defaultProps,e)t[n]===void 0&&(t[n]=e[n]);return t}return t}function Cs(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:R({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var ws={isMounted:function(e){return(e=e._reactInternals)?at(e)===e:!1},enqueueSetState:function(e,t,n){e=e._reactInternals;var r=bl(),i=xl(e),a=io(r,i);a.payload=t,n!=null&&(a.callback=n),t=ao(e,a,i),t!==null&&(Sl(t,e,i,r),oo(t,e,i))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=bl(),i=xl(e),a=io(r,i);a.tag=1,a.payload=t,n!=null&&(a.callback=n),t=ao(e,a,i),t!==null&&(Sl(t,e,i,r),oo(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=bl(),r=xl(e),i=io(n,r);i.tag=2,t!=null&&(i.callback=t),t=ao(e,i,r),t!==null&&(Sl(t,e,r,n),oo(t,e,r))}};function Ts(e,t,n,r,i,a,o){return e=e.stateNode,typeof e.shouldComponentUpdate==`function`?e.shouldComponentUpdate(r,a,o):t.prototype&&t.prototype.isPureReactComponent?!kr(n,r)||!kr(i,a):!0}function Es(e,t,n){var r=!1,i=qi,a=t.contextType;return typeof a==`object`&&a?a=Xa(a):(i=Zi(t)?Yi:W.current,r=t.contextTypes,a=(r=r!=null)?Xi(e,i):qi),t=new t(n,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=ws,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Ds(e,t,n,r){e=t.state,typeof t.componentWillReceiveProps==`function`&&t.componentWillReceiveProps(n,r),typeof t.UNSAFE_componentWillReceiveProps==`function`&&t.UNSAFE_componentWillReceiveProps(n,r),t.state!==e&&ws.enqueueReplaceState(t,t.state,null)}function Os(e,t,n,r){var i=e.stateNode;i.props=n,i.state=e.memoizedState,i.refs={},no(e);var a=t.contextType;typeof a==`object`&&a?i.context=Xa(a):(a=Zi(t)?Yi:W.current,i.context=Xi(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a==`function`&&(Cs(e,t,a,n),i.state=e.memoizedState),typeof t.getDerivedStateFromProps==`function`||typeof i.getSnapshotBeforeUpdate==`function`||typeof i.UNSAFE_componentWillMount!=`function`&&typeof i.componentWillMount!=`function`||(t=i.state,typeof i.componentWillMount==`function`&&i.componentWillMount(),typeof i.UNSAFE_componentWillMount==`function`&&i.UNSAFE_componentWillMount(),t!==i.state&&ws.enqueueReplaceState(i,i.state,null),co(e,n,i,r),i.state=e.memoizedState),typeof i.componentDidMount==`function`&&(e.flags|=4194308)}function ks(e,t){try{var n=``,r=t;do n+=re(r),r=r.return;while(r);var i=n}catch(e){i=`
|
|
7
7
|
Error generating stack: `+e.message+`
|
|
8
8
|
`+e.stack}return{value:e,source:t,stack:i,digest:null}}function As(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function js(e,t){try{console.error(t.value)}catch(e){setTimeout(function(){throw e})}}var Ms=typeof WeakMap==`function`?WeakMap:Map;function Ns(e,t,n){n=io(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){ul||(ul=!0,dl=r),js(e,t)},n}function Ps(e,t,n){n=io(-1,n),n.tag=3;var r=e.type.getDerivedStateFromError;if(typeof r==`function`){var i=t.value;n.payload=function(){return r(i)},n.callback=function(){js(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch==`function`&&(n.callback=function(){js(e,t),typeof r!=`function`&&(fl===null?fl=new Set([this]):fl.add(this));var n=t.stack;this.componentDidCatch(t.value,{componentStack:n===null?``:n})}),n}function Fs(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ms;var i=new Set;r.set(t,i)}else i=r.get(t),i===void 0&&(i=new Set,r.set(t,i));i.has(n)||(i.add(n),e=ql.bind(null,e,t,n),t.then(e,e))}function Is(e){do{var t;if((t=e.tag===13)&&(t=e.memoizedState,t=t===null||t.dehydrated!==null),t)return e;e=e.return}while(e!==null);return null}function Ls(e,t,n,r,i){return e.mode&1?(e.flags|=65536,e.lanes=i,e):(e===t?e.flags|=65536:(e.flags|=128,n.flags|=131072,n.flags&=-52805,n.tag===1&&(n.alternate===null?n.tag=17:(t=io(-1,1),t.tag=2,ao(n,t,1))),n.lanes|=1),e)}var Rs=C.ReactCurrentOwner,zs=!1;function Bs(e,t,n,r){t.child=e===null?Va(t,null,n,r):Ba(t,e.child,n,r)}function Vs(e,t,n,r,i){n=n.render;var a=t.ref;return Ya(t,i),r=Io(e,t,n,r,a,i),n=Lo(),e!==null&&!zs?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,sc(e,t,i)):(wa&&n&&ba(t),t.flags|=1,Bs(e,t,r,i),t.child)}function Hs(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!tu(a)&&a.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=a,Us(e,t,a,r,i)):(e=iu(n.type,null,r,t,t.mode,i),e.ref=t.ref,e.return=t,t.child=e)}if(a=e.child,(e.lanes&i)===0){var o=a.memoizedProps;if(n=n.compare,n=n===null?kr:n,n(o,r)&&e.ref===t.ref)return sc(e,t,i)}return t.flags|=1,e=ru(a,r),e.ref=t.ref,e.return=t,t.child=e}function Us(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(kr(a,r)&&e.ref===t.ref){if(zs=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(zs=!0);else return t.lanes=e.lanes,sc(e,t,i)}}return Ks(e,t,n,r,i)}function Ws(e,t,n){var r=t.pendingProps,i=r.children,a=e===null?null:e.memoizedState;if(r.mode===`hidden`){if(!(t.mode&1))t.memoizedState={baseLanes:0,cachePool:null,transitions:null},Ki(el,$c),$c|=n;else{if(!(n&1073741824))return e=a===null?n:a.baseLanes|n,t.lanes=t.childLanes=1073741824,t.memoizedState={baseLanes:e,cachePool:null,transitions:null},t.updateQueue=null,Ki(el,$c),$c|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a===null?n:a.baseLanes,Ki(el,$c),$c|=r}}else a===null?r=n:(r=a.baseLanes|n,t.memoizedState=null),Ki(el,$c),$c|=r;return Bs(e,t,i,n),t.child}function Gs(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function Ks(e,t,n,r,i){var a=Zi(n)?Yi:W.current;return a=Xi(t,a),Ya(t,i),n=Io(e,t,n,r,a,i),r=Lo(),e!==null&&!zs?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,sc(e,t,i)):(wa&&r&&ba(t),t.flags|=1,Bs(e,t,n,i),t.child)}function qs(e,t,n,r,i){if(Zi(n)){var a=!0;ta(t)}else a=!1;if(Ya(t,i),t.stateNode===null)oc(e,t),Es(t,n,r),Os(t,n,r,i),r=!0;else if(e===null){var o=t.stateNode,s=t.memoizedProps;o.props=s;var c=o.context,l=n.contextType;typeof l==`object`&&l?l=Xa(l):(l=Zi(n)?Yi:W.current,l=Xi(t,l));var u=n.getDerivedStateFromProps,d=typeof u==`function`||typeof o.getSnapshotBeforeUpdate==`function`;d||typeof o.UNSAFE_componentWillReceiveProps!=`function`&&typeof o.componentWillReceiveProps!=`function`||(s!==r||c!==l)&&Ds(t,o,r,l),to=!1;var f=t.memoizedState;o.state=f,co(t,r,o,i),c=t.memoizedState,s!==r||f!==c||Ji.current||to?(typeof u==`function`&&(Cs(t,n,u,r),c=t.memoizedState),(s=to||Ts(t,n,s,r,f,c,l))?(d||typeof o.UNSAFE_componentWillMount!=`function`&&typeof o.componentWillMount!=`function`||(typeof o.componentWillMount==`function`&&o.componentWillMount(),typeof o.UNSAFE_componentWillMount==`function`&&o.UNSAFE_componentWillMount()),typeof o.componentDidMount==`function`&&(t.flags|=4194308)):(typeof o.componentDidMount==`function`&&(t.flags|=4194308),t.memoizedProps=r,t.memoizedState=c),o.props=r,o.state=c,o.context=l,r=s):(typeof o.componentDidMount==`function`&&(t.flags|=4194308),r=!1)}else{o=t.stateNode,ro(e,t),s=t.memoizedProps,l=t.type===t.elementType?s:Ss(t.type,s),o.props=l,d=t.pendingProps,f=o.context,c=n.contextType,typeof c==`object`&&c?c=Xa(c):(c=Zi(n)?Yi:W.current,c=Xi(t,c));var p=n.getDerivedStateFromProps;(u=typeof p==`function`||typeof o.getSnapshotBeforeUpdate==`function`)||typeof o.UNSAFE_componentWillReceiveProps!=`function`&&typeof o.componentWillReceiveProps!=`function`||(s!==d||f!==c)&&Ds(t,o,r,c),to=!1,f=t.memoizedState,o.state=f,co(t,r,o,i);var m=t.memoizedState;s!==d||f!==m||Ji.current||to?(typeof p==`function`&&(Cs(t,n,p,r),m=t.memoizedState),(l=to||Ts(t,n,l,r,f,m,c)||!1)?(u||typeof o.UNSAFE_componentWillUpdate!=`function`&&typeof o.componentWillUpdate!=`function`||(typeof o.componentWillUpdate==`function`&&o.componentWillUpdate(r,m,c),typeof o.UNSAFE_componentWillUpdate==`function`&&o.UNSAFE_componentWillUpdate(r,m,c)),typeof o.componentDidUpdate==`function`&&(t.flags|=4),typeof o.getSnapshotBeforeUpdate==`function`&&(t.flags|=1024)):(typeof o.componentDidUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof o.getSnapshotBeforeUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),t.memoizedProps=r,t.memoizedState=m),o.props=r,o.state=m,o.context=c,r=l):(typeof o.componentDidUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=4),typeof o.getSnapshotBeforeUpdate!=`function`||s===e.memoizedProps&&f===e.memoizedState||(t.flags|=1024),r=!1)}return Js(e,t,n,r,a,i)}function Js(e,t,n,r,i,a){Gs(e,t);var o=!!(t.flags&128);if(!r&&!o)return i&&na(t,n,!1),sc(e,t,a);r=t.stateNode,Rs.current=t;var s=o&&typeof n.getDerivedStateFromError!=`function`?null:r.render();return t.flags|=1,e!==null&&o?(t.child=Ba(t,e.child,null,a),t.child=Ba(t,null,s,a)):Bs(e,t,s,a),t.memoizedState=r.state,i&&na(t,n,!0),t.child}function Ys(e){var t=e.stateNode;t.pendingContext?$i(e,t.pendingContext,t.pendingContext!==t.context):t.context&&$i(e,t.context,!1),go(e,t.containerInfo)}function Xs(e,t,n,r,i){return Na(),Pa(i),t.flags|=256,Bs(e,t,n,r),t.child}var Zs={dehydrated:null,treeContext:null,retryLane:0};function Qs(e){return{baseLanes:e,cachePool:null,transitions:null}}function $s(e,t,n){var r=t.pendingProps,i=bo.current,a=!1,o=!!(t.flags&128),s;if((s=o)||(s=e!==null&&e.memoizedState===null?!1:!!(i&2)),s?(a=!0,t.flags&=-129):(e===null||e.memoizedState!==null)&&(i|=1),Ki(bo,i&1),e===null)return ka(t),e=t.memoizedState,e!==null&&(e=e.dehydrated,e!==null)?(t.lanes=t.mode&1?e.data===`$!`?8:1073741824:1,null):(o=r.children,e=r.fallback,a?(r=t.mode,a=t.child,o={mode:`hidden`,children:o},!(r&1)&&a!==null?(a.childLanes=0,a.pendingProps=o):a=ou(o,r,0,null),e=au(e,r,n,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=Qs(n),t.memoizedState=Zs,e):ec(t,o));if(i=e.memoizedState,i!==null&&(s=i.dehydrated,s!==null))return nc(e,t,o,r,s,i,n);if(a){a=r.fallback,o=t.mode,i=e.child,s=i.sibling;var c={mode:`hidden`,children:r.children};return!(o&1)&&t.child!==i?(r=t.child,r.childLanes=0,r.pendingProps=c,t.deletions=null):(r=ru(i,c),r.subtreeFlags=i.subtreeFlags&14680064),s===null?(a=au(a,o,n,null),a.flags|=2):a=ru(s,a),a.return=t,r.return=t,r.sibling=a,t.child=r,r=a,a=t.child,o=e.child.memoizedState,o=o===null?Qs(n):{baseLanes:o.baseLanes|n,cachePool:null,transitions:o.transitions},a.memoizedState=o,a.childLanes=e.childLanes&~n,t.memoizedState=Zs,r}return a=e.child,e=a.sibling,r=ru(a,{mode:`visible`,children:r.children}),!(t.mode&1)&&(r.lanes=n),r.return=t,r.sibling=null,e!==null&&(n=t.deletions,n===null?(t.deletions=[e],t.flags|=16):n.push(e)),t.child=r,t.memoizedState=null,r}function ec(e,t){return t=ou({mode:`visible`,children:t},e.mode,0,null),t.return=e,e.child=t}function tc(e,t,n,r){return r!==null&&Pa(r),Ba(t,e.child,null,n),e=ec(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function nc(e,t,n,i,a,o,s){if(n)return t.flags&256?(t.flags&=-257,i=As(Error(r(422))),tc(e,t,s,i)):t.memoizedState===null?(o=i.fallback,a=t.mode,i=ou({mode:`visible`,children:i.children},a,0,null),o=au(o,a,s,null),o.flags|=2,i.return=t,o.return=t,i.sibling=o,t.child=i,t.mode&1&&Ba(t,e.child,null,s),t.child.memoizedState=Qs(s),t.memoizedState=Zs,o):(t.child=e.child,t.flags|=128,null);if(!(t.mode&1))return tc(e,t,s,null);if(a.data===`$!`){if(i=a.nextSibling&&a.nextSibling.dataset,i)var c=i.dgst;return i=c,o=Error(r(419)),i=As(o,i,void 0),tc(e,t,s,i)}if(c=(s&e.childLanes)!==0,zs||c){if(i=Xc,i!==null){switch(s&-s){case 4:a=2;break;case 16:a=8;break;case 64:case 128:case 256:case 512:case 1024:case 2048:case 4096:case 8192:case 16384:case 32768:case 65536:case 131072:case 262144:case 524288:case 1048576:case 2097152:case 4194304:case 8388608:case 16777216:case 33554432:case 67108864:a=32;break;case 536870912:a=268435456;break;default:a=0}a=(a&(i.suspendedLanes|s))===0?a:0,a!==0&&a!==o.retryLane&&(o.retryLane=a,eo(e,a),Sl(i,e,a,-1))}return Il(),i=As(Error(r(421))),tc(e,t,s,i)}return a.data===`$?`?(t.flags|=128,t.child=e.child,t=Yl.bind(null,e),a._reactRetry=t,null):(e=o.treeContext,Ca=Ai(a.nextSibling),Sa=t,wa=!0,Ta=null,e!==null&&(pa[ma++]=ga,pa[ma++]=_a,pa[ma++]=ha,ga=e.id,_a=e.overflow,ha=t),t=ec(t,i.children),t.flags|=4096,t)}function rc(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ja(e.return,t,n)}function ic(e,t,n,r,i){var a=e.memoizedState;a===null?e.memoizedState={isBackwards:t,rendering:null,renderingStartTime:0,last:r,tail:n,tailMode:i}:(a.isBackwards=t,a.rendering=null,a.renderingStartTime=0,a.last=r,a.tail=n,a.tailMode=i)}function ac(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Bs(e,t,r.children,n),r=bo.current,r&2)r=r&1|2,t.flags|=128;else{if(e!==null&&e.flags&128)a:for(e=t.child;e!==null;){if(e.tag===13)e.memoizedState!==null&&rc(e,n,t);else if(e.tag===19)rc(e,n,t);else if(e.child!==null){e.child.return=e,e=e.child;continue}if(e===t)break a;for(;e.sibling===null;){if(e.return===null||e.return===t)break a;e=e.return}e.sibling.return=e.return,e=e.sibling}r&=1}if(Ki(bo,r),!(t.mode&1))t.memoizedState=null;else switch(i){case`forwards`:for(n=t.child,i=null;n!==null;)e=n.alternate,e!==null&&xo(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),ic(t,!1,i,n,a);break;case`backwards`:for(n=null,i=t.child,t.child=null;i!==null;){if(e=i.alternate,e!==null&&xo(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}ic(t,!0,n,null,a);break;case`together`:ic(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function oc(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function sc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),rl|=t.lanes,(n&t.childLanes)===0)return null;if(e!==null&&t.child!==e.child)throw Error(r(153));if(t.child!==null){for(e=t.child,n=ru(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=ru(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function cc(e,t,n){switch(t.tag){case 3:Ys(t),Na();break;case 5:vo(t);break;case 1:Zi(t.type)&&ta(t);break;case 4:go(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;Ki(Ha,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(Ki(bo,bo.current&1),e=sc(e,t,n),e===null?null:e.sibling):$s(e,t,n):(Ki(bo,bo.current&1),t.flags|=128,null);Ki(bo,bo.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return ac(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),Ki(bo,bo.current),r)break;return null;case 22:case 23:return t.lanes=0,Ws(e,t,n)}return sc(e,t,n)}var lc=function(e,t){for(var n=t.child;n!==null;){if(n.tag===5||n.tag===6)e.appendChild(n.stateNode);else if(n.tag!==4&&n.child!==null){n.child.return=n,n=n.child;continue}if(n===t)break;for(;n.sibling===null;){if(n.return===null||n.return===t)return;n=n.return}n.sibling.return=n.return,n=n.sibling}},uc=function(e,t,n,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,ho(fo.current);var o=null;switch(n){case`input`:i=fe(e,i),r=fe(e,r),o=[];break;case`select`:i=R({},i,{value:void 0}),r=R({},r,{value:void 0}),o=[];break;case`textarea`:i=be(e,i),r=be(e,r),o=[];break;default:typeof i.onClick!=`function`&&typeof r.onClick==`function`&&(e.onclick=bi)}Pe(n,r);var s;for(u in n=null,i)if(!r.hasOwnProperty(u)&&i.hasOwnProperty(u)&&i[u]!=null){if(u===`style`){var c=i[u];for(s in c)c.hasOwnProperty(s)&&(n||={},n[s]=``)}else u!==`dangerouslySetInnerHTML`&&u!==`children`&&u!==`suppressContentEditableWarning`&&u!==`suppressHydrationWarning`&&u!==`autoFocus`&&(a.hasOwnProperty(u)?o||=[]:(o||=[]).push(u,null))}for(u in r){var l=r[u];if(c=i?.[u],r.hasOwnProperty(u)&&l!==c&&(l!=null||c!=null)){if(u===`style`){if(c){for(s in c)!c.hasOwnProperty(s)||l&&l.hasOwnProperty(s)||(n||={},n[s]=``);for(s in l)l.hasOwnProperty(s)&&c[s]!==l[s]&&(n||={},n[s]=l[s])}else n||(o||=[],o.push(u,n)),n=l}else u===`dangerouslySetInnerHTML`?(l=l?l.__html:void 0,c=c?c.__html:void 0,l!=null&&c!==l&&(o||=[]).push(u,l)):u===`children`?typeof l!=`string`&&typeof l!=`number`||(o||=[]).push(u,``+l):u!==`suppressContentEditableWarning`&&u!==`suppressHydrationWarning`&&(a.hasOwnProperty(u)?(l!=null&&u===`onScroll`&&oi(`scroll`,e),o||c===l||(o=[])):(o||=[]).push(u,l))}}n&&(o||=[]).push(`style`,n);var u=o;(t.updateQueue=u)&&(t.flags|=4)}},dc=function(e,t,n,r){n!==r&&(t.flags|=4)};function fc(e,t){if(!wa)switch(e.tailMode){case`hidden`:t=e.tail;for(var n=null;t!==null;)t.alternate!==null&&(n=t),t=t.sibling;n===null?e.tail=null:n.sibling=null;break;case`collapsed`:n=e.tail;for(var r=null;n!==null;)n.alternate!==null&&(r=n),n=n.sibling;r===null?t||e.tail===null?e.tail=null:e.tail.sibling=null:r.sibling=null}}function pc(e){var t=e.alternate!==null&&e.alternate.child===e.child,n=0,r=0;if(t)for(var i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags&14680064,r|=i.flags&14680064,i.return=e,i=i.sibling;else for(i=e.child;i!==null;)n|=i.lanes|i.childLanes,r|=i.subtreeFlags,r|=i.flags,i.return=e,i=i.sibling;return e.subtreeFlags|=r,e.childLanes=n,t}function mc(e,t,n){var i=t.pendingProps;switch(xa(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return pc(t),null;case 1:return Zi(t.type)&&Qi(),pc(t),null;case 3:return i=t.stateNode,_o(),Gi(Ji),Gi(W),Co(),i.pendingContext&&(i.context=i.pendingContext,i.pendingContext=null),(e===null||e.child===null)&&(ja(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ta!==null&&(El(Ta),Ta=null))),pc(t),null;case 5:yo(t);var o=ho(mo.current);if(n=t.type,e!==null&&t.stateNode!=null)uc(e,t,n,i,o),e.ref!==t.ref&&(t.flags|=512,t.flags|=2097152);else{if(!i){if(t.stateNode===null)throw Error(r(166));return pc(t),null}if(e=ho(fo.current),ja(t)){i=t.stateNode,n=t.type;var s=t.memoizedProps;switch(i[Ni]=t,i[Pi]=s,e=!!(t.mode&1),n){case`dialog`:oi(`cancel`,i),oi(`close`,i);break;case`iframe`:case`object`:case`embed`:oi(`load`,i);break;case`video`:case`audio`:for(o=0;o<ni.length;o++)oi(ni[o],i);break;case`source`:oi(`error`,i);break;case`img`:case`image`:case`link`:oi(`error`,i),oi(`load`,i);break;case`details`:oi(`toggle`,i);break;case`input`:pe(i,s),oi(`invalid`,i);break;case`select`:i._wrapperState={wasMultiple:!!s.multiple},oi(`invalid`,i);break;case`textarea`:xe(i,s),oi(`invalid`,i)}for(var c in Pe(n,s),o=null,s)if(s.hasOwnProperty(c)){var l=s[c];c===`children`?typeof l==`string`?i.textContent!==l&&(!0!==s.suppressHydrationWarning&&yi(i.textContent,l,e),o=[`children`,l]):typeof l==`number`&&i.textContent!==``+l&&(!0!==s.suppressHydrationWarning&&yi(i.textContent,l,e),o=[`children`,``+l]):a.hasOwnProperty(c)&&l!=null&&c===`onScroll`&&oi(`scroll`,i)}switch(n){case`input`:le(i),ge(i,s,!0);break;case`textarea`:le(i),Ce(i);break;case`select`:case`option`:break;default:typeof s.onClick==`function`&&(i.onclick=bi)}i=o,t.updateQueue=i,i!==null&&(t.flags|=4)}else{c=o.nodeType===9?o:o.ownerDocument,e===`http://www.w3.org/1999/xhtml`&&(e=we(n)),e===`http://www.w3.org/1999/xhtml`?n===`script`?(e=c.createElement(`div`),e.innerHTML=`<script><\/script>`,e=e.removeChild(e.firstChild)):typeof i.is==`string`?e=c.createElement(n,{is:i.is}):(e=c.createElement(n),n===`select`&&(c=e,i.multiple?c.multiple=!0:i.size&&(c.size=i.size))):e=c.createElementNS(e,n),e[Ni]=t,e[Pi]=i,lc(e,t,!1,!1),t.stateNode=e;a:{switch(c=Fe(n,i),n){case`dialog`:oi(`cancel`,e),oi(`close`,e),o=i;break;case`iframe`:case`object`:case`embed`:oi(`load`,e),o=i;break;case`video`:case`audio`:for(o=0;o<ni.length;o++)oi(ni[o],e);o=i;break;case`source`:oi(`error`,e),o=i;break;case`img`:case`image`:case`link`:oi(`error`,e),oi(`load`,e),o=i;break;case`details`:oi(`toggle`,e),o=i;break;case`input`:pe(e,i),o=fe(e,i),oi(`invalid`,e);break;case`option`:o=i;break;case`select`:e._wrapperState={wasMultiple:!!i.multiple},o=R({},i,{value:void 0}),oi(`invalid`,e);break;case`textarea`:xe(e,i),o=be(e,i),oi(`invalid`,e);break;default:o=i}for(s in Pe(n,o),l=o,l)if(l.hasOwnProperty(s)){var u=l[s];s===`style`?Me(e,u):s===`dangerouslySetInnerHTML`?(u=u?u.__html:void 0,u!=null&&De(e,u)):s===`children`?typeof u==`string`?(n!==`textarea`||u!==``)&&Oe(e,u):typeof u==`number`&&Oe(e,``+u):s!==`suppressContentEditableWarning`&&s!==`suppressHydrationWarning`&&s!==`autoFocus`&&(a.hasOwnProperty(s)?u!=null&&s===`onScroll`&&oi(`scroll`,e):u!=null&&S(e,s,u,c))}switch(n){case`input`:le(e),ge(e,i,!1);break;case`textarea`:le(e),Ce(e);break;case`option`:i.value!=null&&e.setAttribute(`value`,``+oe(i.value));break;case`select`:e.multiple=!!i.multiple,s=i.value,s==null?i.defaultValue!=null&&ye(e,!!i.multiple,i.defaultValue,!0):ye(e,!!i.multiple,s,!1);break;default:typeof o.onClick==`function`&&(e.onclick=bi)}switch(n){case`button`:case`input`:case`select`:case`textarea`:i=!!i.autoFocus;break a;case`img`:i=!0;break a;default:i=!1}}i&&(t.flags|=4)}t.ref!==null&&(t.flags|=512,t.flags|=2097152)}return pc(t),null;case 6:if(e&&t.stateNode!=null)dc(e,t,e.memoizedProps,i);else{if(typeof i!=`string`&&t.stateNode===null)throw Error(r(166));if(n=ho(mo.current),ho(fo.current),ja(t)){if(i=t.stateNode,n=t.memoizedProps,i[Ni]=t,(s=i.nodeValue!==n)&&(e=Sa,e!==null))switch(e.tag){case 3:yi(i.nodeValue,n,!!(e.mode&1));break;case 5:!0!==e.memoizedProps.suppressHydrationWarning&&yi(i.nodeValue,n,!!(e.mode&1))}s&&(t.flags|=4)}else i=(n.nodeType===9?n:n.ownerDocument).createTextNode(i),i[Ni]=t,t.stateNode=i}return pc(t),null;case 13:if(Gi(bo),i=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(wa&&Ca!==null&&t.mode&1&&!(t.flags&128))Ma(),Na(),t.flags|=98560,s=!1;else if(s=ja(t),i!==null&&i.dehydrated!==null){if(e===null){if(!s)throw Error(r(318));if(s=t.memoizedState,s=s===null?null:s.dehydrated,!s)throw Error(r(317));s[Ni]=t}else Na(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;pc(t),s=!1}else Ta!==null&&(El(Ta),Ta=null),s=!0;if(!s)return t.flags&65536?t:null}return t.flags&128?(t.lanes=n,t):(i=i!==null,i!==(e!==null&&e.memoizedState!==null)&&i&&(t.child.flags|=8192,t.mode&1&&(e===null||bo.current&1?tl===0&&(tl=3):Il())),t.updateQueue!==null&&(t.flags|=4),pc(t),null);case 4:return _o(),e===null&&li(t.stateNode.containerInfo),pc(t),null;case 10:return qa(t.type._context),pc(t),null;case 17:return Zi(t.type)&&Qi(),pc(t),null;case 19:if(Gi(bo),s=t.memoizedState,s===null)return pc(t),null;if(i=!!(t.flags&128),c=s.rendering,c===null){if(i)fc(s,!1);else{if(tl!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(c=xo(e),c!==null){for(t.flags|=128,fc(s,!1),i=c.updateQueue,i!==null&&(t.updateQueue=i,t.flags|=4),t.subtreeFlags=0,i=n,n=t.child;n!==null;)s=n,e=i,s.flags&=14680066,c=s.alternate,c===null?(s.childLanes=0,s.lanes=e,s.child=null,s.subtreeFlags=0,s.memoizedProps=null,s.memoizedState=null,s.updateQueue=null,s.dependencies=null,s.stateNode=null):(s.childLanes=c.childLanes,s.lanes=c.lanes,s.child=c.child,s.subtreeFlags=0,s.deletions=null,s.memoizedProps=c.memoizedProps,s.memoizedState=c.memoizedState,s.updateQueue=c.updateQueue,s.type=c.type,e=c.dependencies,s.dependencies=e===null?null:{lanes:e.lanes,firstContext:e.firstContext}),n=n.sibling;return Ki(bo,bo.current&1|2),t.child}e=e.sibling}s.tail!==null&&ht()>cl&&(t.flags|=128,i=!0,fc(s,!1),t.lanes=4194304)}}else{if(!i){if(e=xo(c),e!==null){if(t.flags|=128,i=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),fc(s,!0),s.tail===null&&s.tailMode===`hidden`&&!c.alternate&&!wa)return pc(t),null}else 2*ht()-s.renderingStartTime>cl&&n!==1073741824&&(t.flags|=128,i=!0,fc(s,!1),t.lanes=4194304)}s.isBackwards?(c.sibling=t.child,t.child=c):(n=s.last,n===null?t.child=c:n.sibling=c,s.last=c)}return s.tail===null?(pc(t),null):(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=ht(),t.sibling=null,n=bo.current,Ki(bo,i?n&1|2:n&1),t);case 22:case 23:return Ml(),i=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==i&&(t.flags|=8192),i&&t.mode&1?$c&1073741824&&(pc(t),t.subtreeFlags&6&&(t.flags|=8192)):pc(t),null;case 24:return null;case 25:return null}throw Error(r(156,t.tag))}function hc(e,t){switch(xa(t),t.tag){case 1:return Zi(t.type)&&Qi(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return _o(),Gi(Ji),Gi(W),Co(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return yo(t),null;case 13:if(Gi(bo),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(r(340));Na()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Gi(bo),null;case 4:return _o(),null;case 10:return qa(t.type._context),null;case 22:case 23:return Ml(),null;case 24:return null;default:return null}}var gc=!1,_c=!1,vc=typeof WeakSet==`function`?WeakSet:Set,yc=null;function bc(e,t){var n=e.ref;if(n!==null){if(typeof n==`function`)try{n(null)}catch(n){Kl(e,t,n)}else n.current=null}}function xc(e,t,n){try{n()}catch(n){Kl(e,t,n)}}var Sc=!1;function Cc(e,t){if(xi=pn,e=Nr(),Pr(e)){if(`selectionStart`in e)var n={start:e.selectionStart,end:e.selectionEnd};else a:{n=(n=e.ownerDocument)&&n.defaultView||window;var i=n.getSelection&&n.getSelection();if(i&&i.rangeCount!==0){n=i.anchorNode;var a=i.anchorOffset,o=i.focusNode;i=i.focusOffset;try{n.nodeType,o.nodeType}catch{n=null;break a}var s=0,c=-1,l=-1,u=0,d=0,f=e,p=null;b:for(;;){for(var m;f!==n||a!==0&&f.nodeType!==3||(c=s+a),f!==o||i!==0&&f.nodeType!==3||(l=s+i),f.nodeType===3&&(s+=f.nodeValue.length),(m=f.firstChild)!==null;)p=f,f=m;for(;;){if(f===e)break b;if(p===n&&++u===a&&(c=s),p===o&&++d===i&&(l=s),(m=f.nextSibling)!==null)break;f=p,p=f.parentNode}f=m}n=c===-1||l===-1?null:{start:c,end:l}}else n=null}n||={start:0,end:0}}else n=null;for(Si={focusedElem:e,selectionRange:n},pn=!1,yc=t;yc!==null;)if(t=yc,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,yc=e;else for(;yc!==null;){t=yc;try{var h=t.alternate;if(t.flags&1024)switch(t.tag){case 0:case 11:case 15:break;case 1:if(h!==null){var g=h.memoizedProps,_=h.memoizedState,v=t.stateNode;v.__reactInternalSnapshotBeforeUpdate=v.getSnapshotBeforeUpdate(t.elementType===t.type?g:Ss(t.type,g),_)}break;case 3:var y=t.stateNode.containerInfo;y.nodeType===1?y.textContent=``:y.nodeType===9&&y.documentElement&&y.removeChild(y.documentElement);break;case 5:case 6:case 4:case 17:break;default:throw Error(r(163))}}catch(e){Kl(t,t.return,e)}if(e=t.sibling,e!==null){e.return=t.return,yc=e;break}yc=t.return}return h=Sc,Sc=!1,h}function wc(e,t,n){var r=t.updateQueue;if(r=r===null?null:r.lastEffect,r!==null){var i=r=r.next;do{if((i.tag&e)===e){var a=i.destroy;i.destroy=void 0,a!==void 0&&xc(t,n,a)}i=i.next}while(i!==r)}}function Tc(e,t){if(t=t.updateQueue,t=t===null?null:t.lastEffect,t!==null){var n=t=t.next;do{if((n.tag&e)===e){var r=n.create;n.destroy=r()}n=n.next}while(n!==t)}}function Ec(e){var t=e.ref;if(t!==null){var n=e.stateNode;switch(e.tag){case 5:e=n;break;default:e=n}typeof t==`function`?t(e):t.current=e}}function Dc(e){var t=e.alternate;t!==null&&(e.alternate=null,Dc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Ni],delete t[Pi],delete t[Ii],delete t[Li],delete t[U])),e.stateNode=null,e.return=null,e.dependencies=null,e.memoizedProps=null,e.memoizedState=null,e.pendingProps=null,e.stateNode=null,e.updateQueue=null}function Oc(e){return e.tag===5||e.tag===3||e.tag===4}function kc(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||Oc(e.return))return null;e=e.return}for(e.sibling.return=e.return,e=e.sibling;e.tag!==5&&e.tag!==6&&e.tag!==18;){if(e.flags&2||e.child===null||e.tag===4)continue a;e.child.return=e,e=e.child}if(!(e.flags&2))return e.stateNode}}function Ac(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.nodeType===8?n.parentNode.insertBefore(e,t):n.insertBefore(e,t):(n.nodeType===8?(t=n.parentNode,t.insertBefore(e,n)):(t=n,t.appendChild(e)),n=n._reactRootContainer,n!=null||t.onclick!==null||(t.onclick=bi));else if(r!==4&&(e=e.child,e!==null))for(Ac(e,t,n),e=e.sibling;e!==null;)Ac(e,t,n),e=e.sibling}function jc(e,t,n){var r=e.tag;if(r===5||r===6)e=e.stateNode,t?n.insertBefore(e,t):n.appendChild(e);else if(r!==4&&(e=e.child,e!==null))for(jc(e,t,n),e=e.sibling;e!==null;)jc(e,t,n),e=e.sibling}var Mc=null,Nc=!1;function Pc(e,t,n){for(n=n.child;n!==null;)Fc(e,t,n),n=n.sibling}function Fc(e,t,n){if(St&&typeof St.onCommitFiberUnmount==`function`)try{St.onCommitFiberUnmount(xt,n)}catch{}switch(n.tag){case 5:_c||bc(n,t);case 6:var r=Mc,i=Nc;Mc=null,Pc(e,t,n),Mc=r,Nc=i,Mc!==null&&(Nc?(e=Mc,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Mc.removeChild(n.stateNode));break;case 18:Mc!==null&&(Nc?(e=Mc,n=n.stateNode,e.nodeType===8?ki(e.parentNode,n):e.nodeType===1&&ki(e,n),dn(e)):ki(Mc,n.stateNode));break;case 4:r=Mc,i=Nc,Mc=n.stateNode.containerInfo,Nc=!0,Pc(e,t,n),Mc=r,Nc=i;break;case 0:case 11:case 14:case 15:if(!_c&&(r=n.updateQueue,r!==null&&(r=r.lastEffect,r!==null))){i=r=r.next;do{var a=i,o=a.destroy;a=a.tag,o!==void 0&&(a&2||a&4)&&xc(n,t,o),i=i.next}while(i!==r)}Pc(e,t,n);break;case 1:if(!_c&&(bc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(e){Kl(n,t,e)}Pc(e,t,n);break;case 21:Pc(e,t,n);break;case 22:n.mode&1?(_c=(r=_c)||n.memoizedState!==null,Pc(e,t,n),_c=r):Pc(e,t,n);break;default:Pc(e,t,n)}}function Ic(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new vc),t.forEach(function(t){var r=Xl.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}}function Lc(e,t){var n=t.deletions;if(n!==null)for(var i=0;i<n.length;i++){var a=n[i];try{var o=e,s=t,c=s;a:for(;c!==null;){switch(c.tag){case 5:Mc=c.stateNode,Nc=!1;break a;case 3:Mc=c.stateNode.containerInfo,Nc=!0;break a;case 4:Mc=c.stateNode.containerInfo,Nc=!0;break a}c=c.return}if(Mc===null)throw Error(r(160));Fc(o,s,a),Mc=null,Nc=!1;var l=a.alternate;l!==null&&(l.return=null),a.return=null}catch(e){Kl(a,t,e)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)Rc(t,e),t=t.sibling}function Rc(e,t){var n=e.alternate,i=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Lc(t,e),zc(e),i&4){try{wc(3,e,e.return),Tc(3,e)}catch(t){Kl(e,e.return,t)}try{wc(5,e,e.return)}catch(t){Kl(e,e.return,t)}}break;case 1:Lc(t,e),zc(e),i&512&&n!==null&&bc(n,n.return);break;case 5:if(Lc(t,e),zc(e),i&512&&n!==null&&bc(n,n.return),e.flags&32){var a=e.stateNode;try{Oe(a,``)}catch(t){Kl(e,e.return,t)}}if(i&4&&(a=e.stateNode,a!=null)){var o=e.memoizedProps,s=n===null?o:n.memoizedProps,c=e.type,l=e.updateQueue;if(e.updateQueue=null,l!==null)try{c===`input`&&o.type===`radio`&&o.name!=null&&me(a,o),Fe(c,s);var u=Fe(c,o);for(s=0;s<l.length;s+=2){var d=l[s],f=l[s+1];d===`style`?Me(a,f):d===`dangerouslySetInnerHTML`?De(a,f):d===`children`?Oe(a,f):S(a,d,f,u)}switch(c){case`input`:he(a,o);break;case`textarea`:Se(a,o);break;case`select`:var p=a._wrapperState.wasMultiple;a._wrapperState.wasMultiple=!!o.multiple;var m=o.value;m==null?p!==!!o.multiple&&(o.defaultValue==null?ye(a,!!o.multiple,o.multiple?[]:``,!1):ye(a,!!o.multiple,o.defaultValue,!0)):ye(a,!!o.multiple,m,!1)}a[Pi]=o}catch(t){Kl(e,e.return,t)}}break;case 6:if(Lc(t,e),zc(e),i&4){if(e.stateNode===null)throw Error(r(162));a=e.stateNode,o=e.memoizedProps;try{a.nodeValue=o}catch(t){Kl(e,e.return,t)}}break;case 3:if(Lc(t,e),zc(e),i&4&&n!==null&&n.memoizedState.isDehydrated)try{dn(t.containerInfo)}catch(t){Kl(e,e.return,t)}break;case 4:Lc(t,e),zc(e);break;case 13:Lc(t,e),zc(e),a=e.child,a.flags&8192&&(o=a.memoizedState!==null,a.stateNode.isHidden=o,!o||a.alternate!==null&&a.alternate.memoizedState!==null||(G=ht())),i&4&&Ic(e);break;case 22:if(d=n!==null&&n.memoizedState!==null,e.mode&1?(_c=(u=_c)||d,Lc(t,e),_c=u):Lc(t,e),zc(e),i&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(yc=e,d=e.child;d!==null;){for(f=yc=d;yc!==null;){switch(p=yc,m=p.child,p.tag){case 0:case 11:case 14:case 15:wc(4,p,p.return);break;case 1:bc(p,p.return);var h=p.stateNode;if(typeof h.componentWillUnmount==`function`){i=p,n=p.return;try{t=i,h.props=t.memoizedProps,h.state=t.memoizedState,h.componentWillUnmount()}catch(e){Kl(i,n,e)}}break;case 5:bc(p,p.return);break;case 22:if(p.memoizedState!==null){Uc(f);continue}}m===null?Uc(f):(m.return=p,yc=m)}d=d.sibling}a:for(d=null,f=e;;){if(f.tag===5){if(d===null){d=f;try{a=f.stateNode,u?(o=a.style,typeof o.setProperty==`function`?o.setProperty(`display`,`none`,`important`):o.display=`none`):(c=f.stateNode,l=f.memoizedProps.style,s=l!=null&&l.hasOwnProperty(`display`)?l.display:null,c.style.display=je(`display`,s))}catch(t){Kl(e,e.return,t)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?``:f.memoizedProps}catch(t){Kl(e,e.return,t)}}else if((f.tag!==22&&f.tag!==23||f.memoizedState===null||f===e)&&f.child!==null){f.child.return=f,f=f.child;continue}if(f===e)break a;for(;f.sibling===null;){if(f.return===null||f.return===e)break a;d===f&&(d=null),f=f.return}d===f&&(d=null),f.sibling.return=f.return,f=f.sibling}}break;case 19:Lc(t,e),zc(e),i&4&&Ic(e);break;case 21:break;default:Lc(t,e),zc(e)}}function zc(e){var t=e.flags;if(t&2){try{a:{for(var n=e.return;n!==null;){if(Oc(n)){var i=n;break a}n=n.return}throw Error(r(160))}switch(i.tag){case 5:var a=i.stateNode;i.flags&32&&(Oe(a,``),i.flags&=-33),jc(e,kc(e),a);break;case 3:case 4:var o=i.stateNode.containerInfo;Ac(e,kc(e),o);break;default:throw Error(r(161))}}catch(t){Kl(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function Bc(e,t,n){yc=e,Vc(e,t,n)}function Vc(e,t,n){for(var r=!!(e.mode&1);yc!==null;){var i=yc,a=i.child;if(i.tag===22&&r){var o=i.memoizedState!==null||gc;if(!o){var s=i.alternate,c=s!==null&&s.memoizedState!==null||_c;s=gc;var l=_c;if(gc=o,(_c=c)&&!l)for(yc=i;yc!==null;)o=yc,c=o.child,o.tag===22&&o.memoizedState!==null||c===null?Wc(i):(c.return=o,yc=c);for(;a!==null;)yc=a,Vc(a,t,n),a=a.sibling;yc=i,gc=s,_c=l}Hc(e,t,n)}else i.subtreeFlags&8772&&a!==null?(a.return=i,yc=a):Hc(e,t,n)}}function Hc(e){for(;yc!==null;){var t=yc;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:_c||Tc(5,t);break;case 1:var i=t.stateNode;if(t.flags&4&&!_c){if(n===null)i.componentDidMount();else{var a=t.elementType===t.type?n.memoizedProps:Ss(t.type,n.memoizedProps);i.componentDidUpdate(a,n.memoizedState,i.__reactInternalSnapshotBeforeUpdate)}}var o=t.updateQueue;o!==null&&lo(t,o,i);break;case 3:var s=t.updateQueue;if(s!==null){if(n=null,t.child!==null)switch(t.child.tag){case 5:n=t.child.stateNode;break;case 1:n=t.child.stateNode}lo(t,s,n)}break;case 5:var c=t.stateNode;if(n===null&&t.flags&4){n=c;var l=t.memoizedProps;switch(t.type){case`button`:case`input`:case`select`:case`textarea`:l.autoFocus&&n.focus();break;case`img`:l.src&&(n.src=l.src)}}break;case 6:break;case 4:break;case 12:break;case 13:if(t.memoizedState===null){var u=t.alternate;if(u!==null){var d=u.memoizedState;if(d!==null){var f=d.dehydrated;f!==null&&dn(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(r(163))}_c||t.flags&512&&Ec(t)}catch(e){Kl(t,t.return,e)}}if(t===e){yc=null;break}if(n=t.sibling,n!==null){n.return=t.return,yc=n;break}yc=t.return}}function Uc(e){for(;yc!==null;){var t=yc;if(t===e){yc=null;break}var n=t.sibling;if(n!==null){n.return=t.return,yc=n;break}yc=t.return}}function Wc(e){for(;yc!==null;){var t=yc;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{Tc(4,t)}catch(e){Kl(t,n,e)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount==`function`){var i=t.return;try{r.componentDidMount()}catch(e){Kl(t,i,e)}}var a=t.return;try{Ec(t)}catch(e){Kl(t,a,e)}break;case 5:var o=t.return;try{Ec(t)}catch(e){Kl(t,o,e)}}}catch(e){Kl(t,t.return,e)}if(t===e){yc=null;break}var s=t.sibling;if(s!==null){s.return=t.return,yc=s;break}yc=t.return}}var Gc=Math.ceil,Kc=C.ReactCurrentDispatcher,qc=C.ReactCurrentOwner,Jc=C.ReactCurrentBatchConfig,Yc=0,Xc=null,Zc=null,Qc=0,$c=0,el=Wi(0),tl=0,nl=null,rl=0,il=0,al=0,ol=null,sl=null,G=0,cl=1/0,ll=null,ul=!1,dl=null,fl=null,pl=!1,ml=null,hl=0,gl=0,_l=null,vl=-1,yl=0;function bl(){return Yc&6?ht():vl===-1?vl=ht():vl}function xl(e){return e.mode&1?Yc&2&&Qc!==0?Qc&-Qc:Fa.transition===null?(e=Bt,e===0?(e=window.event,e=e===void 0?16:yn(e.type),e):e):(yl===0&&(yl=Ft()),yl):1}function Sl(e,t,n,i){if(50<gl)throw gl=0,_l=null,Error(r(185));Lt(e,n,i),(!(Yc&2)||e!==Xc)&&(e===Xc&&(!(Yc&2)&&(il|=n),tl===4&&Ol(e,Qc)),Cl(e,i),n===1&&Yc===0&&!(t.mode&1)&&(cl=ht()+500,ia&&ca()))}function Cl(e,t){var n=e.callbackNode;Nt(e,t);var r=jt(e,e===Xc?Qc:0);if(r===0)n!==null&&ft(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&ft(n),t===1)e.tag===0?sa(kl.bind(null,e)):oa(kl.bind(null,e)),Di(function(){!(Yc&6)&&ca()}),n=null;else{switch(Vt(r)){case 1:n=V;break;case 4:n=_t;break;case 16:n=vt;break;case 536870912:n=bt;break;default:n=vt}n=Ql(n,wl.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function wl(e,t){if(vl=-1,yl=0,Yc&6)throw Error(r(327));var n=e.callbackNode;if(Wl()&&e.callbackNode!==n)return null;var i=jt(e,e===Xc?Qc:0);if(i===0)return null;if(i&30||(i&e.expiredLanes)!==0||t)t=Ll(e,i);else{t=i;var a=Yc;Yc|=2;var o=Fl();(Xc!==e||Qc!==t)&&(ll=null,cl=ht()+500,Nl(e,t));do try{zl();break}catch(t){Pl(e,t)}while(1);Ka(),Kc.current=o,Yc=a,Zc===null?(Xc=null,Qc=0,t=tl):t=0}if(t!==0){if(t===2&&(a=Pt(e),a!==0&&(i=a,t=Tl(e,a))),t===1)throw n=nl,Nl(e,0),Ol(e,i),Cl(e,ht()),n;if(t===6)Ol(e,i);else{if(a=e.current.alternate,!(i&30)&&!Dl(a)&&(t=Ll(e,i),t===2&&(o=Pt(e),o!==0&&(i=o,t=Tl(e,o))),t===1))throw n=nl,Nl(e,0),Ol(e,i),Cl(e,ht()),n;switch(e.finishedWork=a,e.finishedLanes=i,t){case 0:case 1:throw Error(r(345));case 2:Hl(e,sl,ll);break;case 3:if(Ol(e,i),(i&130023424)===i&&(t=G+500-ht(),10<t)){if(jt(e,0)!==0)break;if(a=e.suspendedLanes,(a&i)!==i){bl(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=wi(Hl.bind(null,e,sl,ll),t);break}Hl(e,sl,ll);break;case 4:if(Ol(e,i),(i&4194240)===i)break;for(t=e.eventTimes,a=-1;0<i;){var s=31-wt(i);o=1<<s,s=t[s],s>a&&(a=s),i&=~o}if(i=a,i=ht()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*Gc(i/1960))-i,10<i){e.timeoutHandle=wi(Hl.bind(null,e,sl,ll),i);break}Hl(e,sl,ll);break;case 5:Hl(e,sl,ll);break;default:throw Error(r(329))}}}return Cl(e,ht()),e.callbackNode===n?wl.bind(null,e):null}function Tl(e,t){var n=ol;return e.current.memoizedState.isDehydrated&&(Nl(e,t).flags|=256),e=Ll(e,t),e!==2&&(t=sl,sl=n,t!==null&&El(t)),e}function El(e){sl===null?sl=e:sl.push.apply(sl,e)}function Dl(e){for(var t=e;;){if(t.flags&16384){var n=t.updateQueue;if(n!==null&&(n=n.stores,n!==null))for(var r=0;r<n.length;r++){var i=n[r],a=i.getSnapshot;i=i.value;try{if(!Or(a(),i))return!1}catch{return!1}}}if(n=t.child,t.subtreeFlags&16384&&n!==null)n.return=t,t=n;else{if(t===e)break;for(;t.sibling===null;){if(t.return===null||t.return===e)return!0;t=t.return}t.sibling.return=t.return,t=t.sibling}}return!0}function Ol(e,t){for(t&=~al,t&=~il,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-wt(t),r=1<<n;e[n]=-1,t&=~r}}function kl(e){if(Yc&6)throw Error(r(327));Wl();var t=jt(e,0);if(!(t&1))return Cl(e,ht()),null;var n=Ll(e,t);if(e.tag!==0&&n===2){var i=Pt(e);i!==0&&(t=i,n=Tl(e,i))}if(n===1)throw n=nl,Nl(e,0),Ol(e,t),Cl(e,ht()),n;if(n===6)throw Error(r(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Hl(e,sl,ll),Cl(e,ht()),null}function Al(e,t){var n=Yc;Yc|=1;try{return e(t)}finally{Yc=n,Yc===0&&(cl=ht()+500,ia&&ca())}}function jl(e){ml!==null&&ml.tag===0&&!(Yc&6)&&Wl();var t=Yc;Yc|=1;var n=Jc.transition,r=Bt;try{if(Jc.transition=null,Bt=1,e)return e()}finally{Bt=r,Jc.transition=n,Yc=t,!(Yc&6)&&ca()}}function Ml(){$c=el.current,Gi(el)}function Nl(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,Ti(n)),Zc!==null)for(n=Zc.return;n!==null;){var r=n;switch(xa(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&Qi();break;case 3:_o(),Gi(Ji),Gi(W),Co();break;case 5:yo(r);break;case 4:_o();break;case 13:Gi(bo);break;case 19:Gi(bo);break;case 10:qa(r.type._context);break;case 22:case 23:Ml()}n=n.return}if(Xc=e,Zc=e=ru(e.current,null),Qc=$c=t,tl=0,nl=null,al=il=rl=0,sl=ol=null,Za!==null){for(t=0;t<Za.length;t++)if(n=Za[t],r=n.interleaved,r!==null){n.interleaved=null;var i=r.next,a=n.pending;if(a!==null){var o=a.next;a.next=i,r.next=o}n.pending=r}Za=null}return e}function Pl(e,t){do{var n=Zc;try{if(Ka(),wo.current=vs,Ao){for(var i=Do.memoizedState;i!==null;){var a=i.queue;a!==null&&(a.pending=null),i=i.next}Ao=!1}if(Eo=0,ko=Oo=Do=null,jo=!1,Mo=0,qc.current=null,n===null||n.return===null){tl=1,nl=t,Zc=null;break}a:{var o=e,s=n.return,c=n,l=t;if(t=Qc,c.flags|=32768,typeof l==`object`&&l&&typeof l.then==`function`){var u=l,d=c,f=d.tag;if(!(d.mode&1)&&(f===0||f===11||f===15)){var p=d.alternate;p?(d.updateQueue=p.updateQueue,d.memoizedState=p.memoizedState,d.lanes=p.lanes):(d.updateQueue=null,d.memoizedState=null)}var m=Is(s);if(m!==null){m.flags&=-257,Ls(m,s,c,o,t),m.mode&1&&Fs(o,u,t),t=m,l=u;var h=t.updateQueue;if(h===null){var g=new Set;g.add(l),t.updateQueue=g}else h.add(l);break a}if(!(t&1)){Fs(o,u,t),Il();break a}l=Error(r(426))}else if(wa&&c.mode&1){var _=Is(s);if(_!==null){!(_.flags&65536)&&(_.flags|=256),Ls(_,s,c,o,t),Pa(ks(l,c));break a}}o=l=ks(l,c),tl!==4&&(tl=2),ol===null?ol=[o]:ol.push(o),o=s;do{switch(o.tag){case 3:o.flags|=65536,t&=-t,o.lanes|=t;var v=Ns(o,l,t);so(o,v);break a;case 1:c=l;var y=o.type,b=o.stateNode;if(!(o.flags&128)&&(typeof y.getDerivedStateFromError==`function`||b!==null&&typeof b.componentDidCatch==`function`&&(fl===null||!fl.has(b)))){o.flags|=65536,t&=-t,o.lanes|=t;var x=Ps(o,c,t);so(o,x);break a}}o=o.return}while(o!==null)}Vl(n)}catch(e){t=e,Zc===n&&n!==null&&(Zc=n=n.return);continue}break}while(1)}function Fl(){var e=Kc.current;return Kc.current=vs,e===null?vs:e}function Il(){(tl===0||tl===3||tl===2)&&(tl=4),Xc===null||!(rl&268435455)&&!(il&268435455)||Ol(Xc,Qc)}function Ll(e,t){var n=Yc;Yc|=2;var i=Fl();(Xc!==e||Qc!==t)&&(ll=null,Nl(e,t));do try{Rl();break}catch(t){Pl(e,t)}while(1);if(Ka(),Yc=n,Kc.current=i,Zc!==null)throw Error(r(261));return Xc=null,Qc=0,tl}function Rl(){for(;Zc!==null;)Bl(Zc)}function zl(){for(;Zc!==null&&!pt();)Bl(Zc)}function Bl(e){var t=Zl(e.alternate,e,$c);e.memoizedProps=e.pendingProps,t===null?Vl(e):Zc=t,qc.current=null}function Vl(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=hc(n,t),n!==null){n.flags&=32767,Zc=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{tl=6,Zc=null;return}}else if(n=mc(n,t,$c),n!==null){Zc=n;return}if(t=t.sibling,t!==null){Zc=t;return}Zc=t=e}while(t!==null);tl===0&&(tl=5)}function Hl(e,t,n){var r=Bt,i=Jc.transition;try{Jc.transition=null,Bt=1,Ul(e,t,n,r)}finally{Jc.transition=i,Bt=r}return null}function Ul(e,t,n,i){do Wl();while(ml!==null);if(Yc&6)throw Error(r(327));n=e.finishedWork;var a=e.finishedLanes;if(n===null)return null;if(e.finishedWork=null,e.finishedLanes=0,n===e.current)throw Error(r(177));e.callbackNode=null,e.callbackPriority=0;var o=n.lanes|n.childLanes;if(Rt(e,o),e===Xc&&(Zc=Xc=null,Qc=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||pl||(pl=!0,Ql(vt,function(){return Wl(),null})),o=!!(n.flags&15990),n.subtreeFlags&15990||o){o=Jc.transition,Jc.transition=null;var s=Bt;Bt=1;var c=Yc;Yc|=4,qc.current=null,Cc(e,n),Rc(n,e),Fr(Si),pn=!!xi,Si=xi=null,e.current=n,Bc(n,e,a),mt(),Yc=c,Bt=s,Jc.transition=o}else e.current=n;if(pl&&(pl=!1,ml=e,hl=a),o=e.pendingLanes,o===0&&(fl=null),Ct(n.stateNode,i),Cl(e,ht()),t!==null)for(i=e.onRecoverableError,n=0;n<t.length;n++)a=t[n],i(a.value,{componentStack:a.stack,digest:a.digest});if(ul)throw ul=!1,e=dl,dl=null,e;return hl&1&&e.tag!==0&&Wl(),o=e.pendingLanes,o&1?e===_l?gl++:(gl=0,_l=e):gl=0,ca(),null}function Wl(){if(ml!==null){var e=Vt(hl),t=Jc.transition,n=Bt;try{if(Jc.transition=null,Bt=16>e?16:e,ml===null)var i=!1;else{if(e=ml,ml=null,hl=0,Yc&6)throw Error(r(331));var a=Yc;for(Yc|=4,yc=e.current;yc!==null;){var o=yc,s=o.child;if(yc.flags&16){var c=o.deletions;if(c!==null){for(var l=0;l<c.length;l++){var u=c[l];for(yc=u;yc!==null;){var d=yc;switch(d.tag){case 0:case 11:case 15:wc(8,d,o)}var f=d.child;if(f!==null)f.return=d,yc=f;else for(;yc!==null;){d=yc;var p=d.sibling,m=d.return;if(Dc(d),d===u){yc=null;break}if(p!==null){p.return=m,yc=p;break}yc=m}}}var h=o.alternate;if(h!==null){var g=h.child;if(g!==null){h.child=null;do{var _=g.sibling;g.sibling=null,g=_}while(g!==null)}}yc=o}}if(o.subtreeFlags&2064&&s!==null)s.return=o,yc=s;else b:for(;yc!==null;){if(o=yc,o.flags&2048)switch(o.tag){case 0:case 11:case 15:wc(9,o,o.return)}var v=o.sibling;if(v!==null){v.return=o.return,yc=v;break b}yc=o.return}}var y=e.current;for(yc=y;yc!==null;){s=yc;var b=s.child;if(s.subtreeFlags&2064&&b!==null)b.return=s,yc=b;else b:for(s=y;yc!==null;){if(c=yc,c.flags&2048)try{switch(c.tag){case 0:case 11:case 15:Tc(9,c)}}catch(e){Kl(c,c.return,e)}if(c===s){yc=null;break b}var x=c.sibling;if(x!==null){x.return=c.return,yc=x;break b}yc=c.return}}if(Yc=a,ca(),St&&typeof St.onPostCommitFiberRoot==`function`)try{St.onPostCommitFiberRoot(xt,e)}catch{}i=!0}return i}finally{Bt=n,Jc.transition=t}}return!1}function Gl(e,t,n){t=ks(n,t),t=Ns(e,t,1),e=ao(e,t,1),t=bl(),e!==null&&(Lt(e,1,t),Cl(e,t))}function Kl(e,t,n){if(e.tag===3)Gl(e,e,n);else for(;t!==null;){if(t.tag===3){Gl(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(fl===null||!fl.has(r))){e=ks(n,e),e=Ps(t,e,1),t=ao(t,e,1),e=bl(),t!==null&&(Lt(t,1,e),Cl(t,e));break}}t=t.return}}function ql(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=bl(),e.pingedLanes|=e.suspendedLanes&n,Xc===e&&(Qc&n)===n&&(tl===4||tl===3&&(Qc&130023424)===Qc&&500>ht()-G?Nl(e,0):al|=n),Cl(e,t)}function Jl(e,t){t===0&&(e.mode&1?(t=kt,kt<<=1,!(kt&130023424)&&(kt=4194304)):t=1);var n=bl();e=eo(e,t),e!==null&&(Lt(e,t,n),Cl(e,n))}function Yl(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Jl(e,n)}function Xl(e,t){var n=0;switch(e.tag){case 13:var i=e.stateNode,a=e.memoizedState;a!==null&&(n=a.retryLane);break;case 19:i=e.stateNode;break;default:throw Error(r(314))}i!==null&&i.delete(t),Jl(e,n)}var Zl=function(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps||Ji.current)zs=!0;else{if((e.lanes&n)===0&&!(t.flags&128))return zs=!1,cc(e,t,n);zs=!!(e.flags&131072)}}else zs=!1,wa&&t.flags&1048576&&ya(t,fa,t.index);switch(t.lanes=0,t.tag){case 2:var i=t.type;oc(e,t),e=t.pendingProps;var a=Xi(t,W.current);Ya(t,n),a=Io(null,t,i,e,a,n);var o=Lo();return t.flags|=1,typeof a==`object`&&a&&typeof a.render==`function`&&a.$$typeof===void 0?(t.tag=1,t.memoizedState=null,t.updateQueue=null,Zi(i)?(o=!0,ta(t)):o=!1,t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,no(t),a.updater=ws,t.stateNode=a,a._reactInternals=t,Os(t,i,e,n),t=Js(null,t,i,!0,o,n)):(t.tag=0,wa&&o&&ba(t),Bs(null,t,a,n),t=t.child),t;case 16:i=t.elementType;a:{switch(oc(e,t),e=t.pendingProps,a=i._init,i=a(i._payload),t.type=i,a=t.tag=nu(i),e=Ss(i,e),a){case 0:t=Ks(null,t,i,e,n);break a;case 1:t=qs(null,t,i,e,n);break a;case 11:t=Vs(null,t,i,e,n);break a;case 14:t=Hs(null,t,i,Ss(i.type,e),n);break a}throw Error(r(306,i,``))}return t;case 0:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Ss(i,a),Ks(e,t,i,a,n);case 1:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Ss(i,a),qs(e,t,i,a,n);case 3:a:{if(Ys(t),e===null)throw Error(r(387));i=t.pendingProps,o=t.memoizedState,a=o.element,ro(e,t),co(t,i,null,n);var s=t.memoizedState;if(i=s.element,o.isDehydrated){if(o={element:i,isDehydrated:!1,cache:s.cache,pendingSuspenseBoundaries:s.pendingSuspenseBoundaries,transitions:s.transitions},t.updateQueue.baseState=o,t.memoizedState=o,t.flags&256){a=ks(Error(r(423)),t),t=Xs(e,t,i,n,a);break a}if(i!==a){a=ks(Error(r(424)),t),t=Xs(e,t,i,n,a);break a}for(Ca=Ai(t.stateNode.containerInfo.firstChild),Sa=t,wa=!0,Ta=null,n=Va(t,null,i,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Na(),i===a){t=sc(e,t,n);break a}Bs(e,t,i,n)}t=t.child}return t;case 5:return vo(t),e===null&&ka(t),i=t.type,a=t.pendingProps,o=e===null?null:e.memoizedProps,s=a.children,Ci(i,a)?s=null:o!==null&&Ci(i,o)&&(t.flags|=32),Gs(e,t),Bs(e,t,s,n),t.child;case 6:return e===null&&ka(t),null;case 13:return $s(e,t,n);case 4:return go(t,t.stateNode.containerInfo),i=t.pendingProps,e===null?t.child=Ba(t,null,i,n):Bs(e,t,i,n),t.child;case 11:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Ss(i,a),Vs(e,t,i,a,n);case 7:return Bs(e,t,t.pendingProps,n),t.child;case 8:return Bs(e,t,t.pendingProps.children,n),t.child;case 12:return Bs(e,t,t.pendingProps.children,n),t.child;case 10:a:{if(i=t.type._context,a=t.pendingProps,o=t.memoizedProps,s=a.value,Ki(Ha,i._currentValue),i._currentValue=s,o!==null){if(Or(o.value,s)){if(o.children===a.children&&!Ji.current){t=sc(e,t,n);break a}}else for(o=t.child,o!==null&&(o.return=t);o!==null;){var c=o.dependencies;if(c!==null){s=o.child;for(var l=c.firstContext;l!==null;){if(l.context===i){if(o.tag===1){l=io(-1,n&-n),l.tag=2;var u=o.updateQueue;if(u!==null){u=u.shared;var d=u.pending;d===null?l.next=l:(l.next=d.next,d.next=l),u.pending=l}}o.lanes|=n,l=o.alternate,l!==null&&(l.lanes|=n),Ja(o.return,n,t),c.lanes|=n;break}l=l.next}}else if(o.tag===10)s=o.type===t.type?null:o.child;else if(o.tag===18){if(s=o.return,s===null)throw Error(r(341));s.lanes|=n,c=s.alternate,c!==null&&(c.lanes|=n),Ja(s,n,t),s=o.sibling}else s=o.child;if(s!==null)s.return=o;else for(s=o;s!==null;){if(s===t){s=null;break}if(o=s.sibling,o!==null){o.return=s.return,s=o;break}s=s.return}o=s}}Bs(e,t,a.children,n),t=t.child}return t;case 9:return a=t.type,i=t.pendingProps.children,Ya(t,n),a=Xa(a),i=i(a),t.flags|=1,Bs(e,t,i,n),t.child;case 14:return i=t.type,a=Ss(i,t.pendingProps),a=Ss(i.type,a),Hs(e,t,i,a,n);case 15:return Us(e,t,t.type,t.pendingProps,n);case 17:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Ss(i,a),oc(e,t),t.tag=1,Zi(i)?(e=!0,ta(t)):e=!1,Ya(t,n),Es(t,i,a),Os(t,i,a,n),Js(null,t,i,!0,e,n);case 19:return ac(e,t,n);case 22:return Ws(e,t,n)}throw Error(r(156,t.tag))};function Ql(e,t){return dt(e,t)}function $l(e,t,n,r){this.tag=e,this.key=n,this.sibling=this.child=this.return=this.stateNode=this.type=this.elementType=null,this.index=0,this.ref=null,this.pendingProps=t,this.dependencies=this.memoizedState=this.updateQueue=this.memoizedProps=null,this.mode=r,this.subtreeFlags=this.flags=0,this.deletions=null,this.childLanes=this.lanes=0,this.alternate=null}function eu(e,t,n,r){return new $l(e,t,n,r)}function tu(e){return e=e.prototype,!(!e||!e.isReactComponent)}function nu(e){if(typeof e==`function`)return+!!tu(e);if(e!=null){if(e=e.$$typeof,e===j)return 11;if(e===P)return 14}return 2}function ru(e,t){var n=e.alternate;return n===null?(n=eu(e.tag,t,e.key,e.mode),n.elementType=e.elementType,n.type=e.type,n.stateNode=e.stateNode,n.alternate=e,e.alternate=n):(n.pendingProps=t,n.type=e.type,n.flags=0,n.subtreeFlags=0,n.deletions=null),n.flags=e.flags&14680064,n.childLanes=e.childLanes,n.lanes=e.lanes,n.child=e.child,n.memoizedProps=e.memoizedProps,n.memoizedState=e.memoizedState,n.updateQueue=e.updateQueue,t=e.dependencies,n.dependencies=t===null?null:{lanes:t.lanes,firstContext:t.firstContext},n.sibling=e.sibling,n.index=e.index,n.ref=e.ref,n}function iu(e,t,n,i,a,o){var s=2;if(i=e,typeof e==`function`)tu(e)&&(s=1);else if(typeof e==`string`)s=5;else a:switch(e){case E:return au(n.children,a,o,t);case D:s=8,a|=8;break;case O:return e=eu(12,n,t,a|2),e.elementType=O,e.lanes=o,e;case M:return e=eu(13,n,t,a),e.elementType=M,e.lanes=o,e;case N:return e=eu(19,n,t,a),e.elementType=N,e.lanes=o,e;case I:return ou(n,a,o,t);default:if(typeof e==`object`&&e)switch(e.$$typeof){case k:s=10;break a;case A:s=9;break a;case j:s=11;break a;case P:s=14;break a;case F:s=16,i=null;break a}throw Error(r(130,e==null?e:typeof e,``))}return t=eu(s,n,t,a),t.elementType=e,t.type=i,t.lanes=o,t}function au(e,t,n,r){return e=eu(7,e,r,t),e.lanes=n,e}function ou(e,t,n,r){return e=eu(22,e,r,t),e.elementType=I,e.lanes=n,e.stateNode={isHidden:!1},e}function su(e,t,n){return e=eu(6,e,null,t),e.lanes=n,e}function cu(e,t,n){return t=eu(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function lu(e,t,n,r,i){this.tag=t,this.containerInfo=e,this.finishedWork=this.pingCache=this.current=this.pendingChildren=null,this.timeoutHandle=-1,this.callbackNode=this.pendingContext=this.context=null,this.callbackPriority=0,this.eventTimes=It(0),this.expirationTimes=It(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=It(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function uu(e,t,n,r,i,a,o,s,c){return e=new lu(e,t,n,s,c),t===1?(t=1,!0===a&&(t|=8)):t=0,a=eu(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},no(a),e}function du(e,t,n){var r=3<arguments.length&&arguments[3]!==void 0?arguments[3]:null;return{$$typeof:T,key:r==null?null:``+r,children:e,containerInfo:t,implementation:n}}function fu(e){if(!e)return qi;e=e._reactInternals;a:{if(at(e)!==e||e.tag!==1)throw Error(r(170));var t=e;do{switch(t.tag){case 3:t=t.stateNode.context;break a;case 1:if(Zi(t.type)){t=t.stateNode.__reactInternalMemoizedMergedChildContext;break a}}t=t.return}while(t!==null);throw Error(r(171))}if(e.tag===1){var n=e.type;if(Zi(n))return ea(e,n,t)}return t}function pu(e,t,n,r,i,a,o,s,c){return e=uu(n,r,!0,e,i,a,o,s,c),e.context=fu(null),n=e.current,r=bl(),i=xl(n),a=io(r,i),a.callback=t??null,ao(n,a,i),e.current.lanes=i,Lt(e,i,r),Cl(e,r),e}function mu(e,t,n,r){var i=t.current,a=bl(),o=xl(i);return n=fu(n),t.context===null?t.context=n:t.pendingContext=n,t=io(a,o),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=ao(i,t,o),e!==null&&(Sl(e,i,o,a),oo(e,i,o)),o}function hu(e){if(e=e.current,!e.child)return null;switch(e.child.tag){case 5:return e.child.stateNode;default:return e.child.stateNode}}function gu(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function K(e,t){gu(e,t),(e=e.alternate)&&gu(e,t)}function _u(){return null}var vu=typeof reportError==`function`?reportError:function(e){console.error(e)};function yu(e){this._internalRoot=e}bu.prototype.render=yu.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(r(409));mu(e,t,null,null)},bu.prototype.unmount=yu.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;jl(function(){mu(null,e,null,null)}),t[Fi]=null}};function bu(e){this._internalRoot=e}bu.prototype.unstable_scheduleHydration=function(e){if(e){var t=Gt();e={blockedOn:null,target:e,priority:t};for(var n=0;n<en.length&&t!==0&&t<en[n].priority;n++);en.splice(n,0,e),n===0&&on(e)}};function xu(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Su(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==` react-mount-point-unstable `))}function Cu(){}function wu(e,t,n,r,i){if(i){if(typeof r==`function`){var a=r;r=function(){var e=hu(o);a.call(e)}}var o=pu(t,r,e,0,null,!1,!1,``,Cu);return e._reactRootContainer=o,e[Fi]=o.current,li(e.nodeType===8?e.parentNode:e),jl(),o}for(;i=e.lastChild;)e.removeChild(i);if(typeof r==`function`){var s=r;r=function(){var e=hu(c);s.call(e)}}var c=uu(e,0,!1,null,null,!1,!1,``,Cu);return e._reactRootContainer=c,e[Fi]=c.current,li(e.nodeType===8?e.parentNode:e),jl(function(){mu(t,c,n,r)}),c}function Tu(e,t,n,r,i){var a=n._reactRootContainer;if(a){var o=a;if(typeof i==`function`){var s=i;i=function(){var e=hu(o);s.call(e)}}mu(t,o,e,i)}else o=wu(n,t,e,i,r);return hu(o)}Ht=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=At(t.pendingLanes);n!==0&&(zt(t,n|1),Cl(t,ht()),!(Yc&6)&&(cl=ht()+500,ca()))}break;case 13:jl(function(){var t=eo(e,1);t!==null&&Sl(t,e,1,bl())}),K(e,1)}},Ut=function(e){if(e.tag===13){var t=eo(e,134217728);t!==null&&Sl(t,e,134217728,bl()),K(e,134217728)}},Wt=function(e){if(e.tag===13){var t=xl(e),n=eo(e,t);n!==null&&Sl(n,e,t,bl()),K(e,t)}},Gt=function(){return Bt},Kt=function(e,t){var n=Bt;try{return Bt=e,t()}finally{Bt=n}},Re=function(e,t,n){switch(t){case`input`:if(he(e,n),t=n.name,n.type===`radio`&&t!=null){for(n=e;n.parentNode;)n=n.parentNode;for(n=n.querySelectorAll(`input[name=`+JSON.stringify(``+t)+`][type="radio"]`),t=0;t<n.length;t++){var i=n[t];if(i!==e&&i.form===e.form){var a=Vi(i);if(!a)throw Error(r(90));ue(i),he(i,a)}}}break;case`textarea`:Se(e,n);break;case`select`:t=n.value,t!=null&&ye(e,!!n.multiple,t,!1)}},We=Al,Ge=jl;var Eu={usingClientEntryPoint:!1,Events:[zi,Bi,Vi,He,Ue,Al]},Du={findFiberByHostInstance:Ri,bundleType:0,version:`18.3.1`,rendererPackageName:`react-dom`},Ou={bundleType:Du.bundleType,version:Du.version,rendererPackageName:Du.rendererPackageName,rendererConfig:Du.rendererConfig,overrideHookState:null,overrideHookStateDeletePath:null,overrideHookStateRenamePath:null,overrideProps:null,overridePropsDeletePath:null,overridePropsRenamePath:null,setErrorHandler:null,setSuspenseHandler:null,scheduleUpdate:null,currentDispatcherRef:C.ReactCurrentDispatcher,findHostInstanceByFiber:function(e){return e=lt(e),e===null?null:e.stateNode},findFiberByHostInstance:Du.findFiberByHostInstance||_u,findHostInstancesForRefresh:null,scheduleRefresh:null,scheduleRoot:null,setRefreshHandler:null,getCurrentFiber:null,reconcilerVersion:`18.3.1-next-f1338f8080-20240426`};if(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__<`u`){var ku=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!ku.isDisabled&&ku.supportsFiber)try{xt=ku.inject(Ou),St=ku}catch{}}e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Eu,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!xu(t))throw Error(r(200));return du(e,t,null,n)},e.createRoot=function(e,t){if(!xu(e))throw Error(r(299));var n=!1,i=``,a=vu;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(i=t.identifierPrefix),t.onRecoverableError!==void 0&&(a=t.onRecoverableError)),t=uu(e,1,!1,null,null,n,!1,i,a),e[Fi]=t.current,li(e.nodeType===8?e.parentNode:e),new yu(t)},e.findDOMNode=function(e){if(e==null)return null;if(e.nodeType===1)return e;var t=e._reactInternals;if(t===void 0)throw typeof e.render==`function`?Error(r(188)):(e=Object.keys(e).join(`,`),Error(r(268,e)));return e=lt(t),e=e===null?null:e.stateNode,e},e.flushSync=function(e){return jl(e)},e.hydrate=function(e,t,n){if(!Su(t))throw Error(r(200));return Tu(null,e,t,!0,n)},e.hydrateRoot=function(e,t,n){if(!xu(e))throw Error(r(405));var i=n!=null&&n.hydratedSources||null,a=!1,o=``,s=vu;if(n!=null&&(!0===n.unstable_strictMode&&(a=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(s=n.onRecoverableError)),t=pu(t,null,e,1,n??null,a,!1,o,s),e[Fi]=t.current,li(e),i)for(e=0;e<i.length;e++)n=i[e],a=n._getVersion,a=a(n._source),t.mutableSourceEagerHydrationData==null?t.mutableSourceEagerHydrationData=[n,a]:t.mutableSourceEagerHydrationData.push(n,a);return new bu(t)},e.render=function(e,t,n){if(!Su(t))throw Error(r(200));return Tu(null,e,t,!1,n)},e.unmountComponentAtNode=function(e){if(!Su(e))throw Error(r(40));return e._reactRootContainer?(jl(function(){Tu(null,null,e,!1,function(){e._reactRootContainer=null,e[Fi]=null})}),!0):!1},e.unstable_batchedUpdates=Al,e.unstable_renderSubtreeIntoContainer=function(e,t,n,i){if(!Su(n))throw Error(r(200));if(e==null||e._reactInternals===void 0)throw Error(r(38));return Tu(e,t,n,!1,i)},e.version=`18.3.1-next-f1338f8080-20240426`})),g=s(((e,t)=>{function n(){if(!(typeof __REACT_DEVTOOLS_GLOBAL_HOOK__>`u`||typeof __REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE!=`function`))try{__REACT_DEVTOOLS_GLOBAL_HOOK__.checkDCE(n)}catch(e){console.error(e)}}n(),t.exports=h()})),_=s((e=>{var t=g();e.createRoot=t.createRoot,e.hydrateRoot=t.hydrateRoot})),v=u(f(),1),y=_();function b(e=void 0){if(!e)return``;let t;try{t=new URL(e)}catch{return``}return t.protocol!==`https:`||t.username||t.password||t.pathname!==`/`||t.search||t.hash?``:t.origin}var x=(e,t)=>`${b(t)}${e}`,S=`The Block’s sandbox did not start: this browser, or an extension in it, blocks the frame Blocks run in. Open StillMade in Chrome, Edge or Safari.`,C=(e=globalThis.navigator?.userAgent||``)=>/\bClaude\/\d/.test(e),w=(e=globalThis.navigator?.userAgent||``)=>C(e)?`The Claude app’s built-in browser blocks the frame Blocks run in. Open this page in Chrome, Edge or Safari.`:S;async function T(){throw Error(`App views run inside StillMade.`)}function E(e,t={}){return V(O.includes(e),`SHARED_WORK_OPERATION`,`Choose a declared shared-work operation.`),pt(t),V(_t(t)&&JSON.stringify(t).length<=131072,`SHARED_WORK_INPUT`,`Shared-work requests require bounded JSON arguments.`),{operation:e,args:structuredClone(t)}}function D(e,t,n,r){let i=0,a=new Map,o=new Set,s=new Set,c=()=>{for(let e of s)URL.revokeObjectURL(e);s.clear()};return addEventListener(`message`,n=>{let r=n.data;if(n.source!==parent||!r||r.channel!==e||r.session!==t||![`shared-work-result`,`shared-work-refresh`].includes(r.op))return;if(r.op===`shared-work-refresh`){c();for(let e of o)try{e()}catch{}return}let i=a.get(r.id);if(i){if(a.delete(r.id),r.error){i.reject(Error(r.error));return}if(i.media){if(!(r.media instanceof Blob)||!r.media.size||r.media.size>67108864||![`image`,`video`,`audio`].includes(r.kind)||!r.media.type.startsWith(r.kind+`/`)||s.size>=2){i.reject(Error(`The shared creative preview is invalid or its limit was reached.`));return}let e=URL.createObjectURL(r.media);s.add(e),i.resolve({url:e,kind:r.kind})}else i.resolve(r.result)}}),addEventListener(`message`,n=>{n.source===parent&&n.data?.channel===e&&n.data?.session===t&&n.data?.op===`dispose`&&c()}),{releaseSharedWorkMedia(e){s.delete(e)&&URL.revokeObjectURL(e)},previewSharedWorkMedia(o){if(!n||typeof o!=`string`||!/^[0-9a-f-]{36}$/i.test(o))return Promise.reject(Error(`Choose a permitted saved creative.`));if(a.size>=4||s.size>=2)return Promise.reject(Error(`Close a previous preview before opening another.`));let c=String(++i);return new Promise((n,i)=>{a.set(c,{resolve:n,reject:i,media:!0}),r({channel:e,session:t,op:`shared-work-media-request`,id:c,contributionId:o},`*`)})},onSharedWorkRefresh(e){if(typeof e!=`function`)throw Error(`Expected a callback.`);return o.add(e),()=>o.delete(e)},sharedWork(o,s={}){if(!n)return Promise.reject(Error(`This Block has no shared-work permission.`));if(![`list`,`accounts`,`grants`,`create`,`bind`,`read`,`update`,`creatives`,`contribute`,`grant`,`revoke`,`unlink`].includes(o)||!s||Array.isArray(s)||typeof s!=`object`||JSON.stringify(s).length>131072)return Promise.reject(Error(`Invalid shared-work request.`));if(a.size>=4)return Promise.reject(Error(`Wait for the current shared-work request.`));let c=String(++i);return new Promise((n,i)=>{a.set(c,{resolve:n,reject:i}),r({channel:e,session:t,op:`shared-work-request`,id:c,operation:o,args:s},`*`)})}}}var O,k=o((()=>{wt(),O=Object.freeze([`list`,`accounts`,`grants`,`create`,`bind`,`read`,`update`,`creatives`,`contribute`,`grant`,`revoke`,`unlink`])}));function A(e){if(typeof e!=`string`||e.length>4194304)return!1;if(/^\/api\/media\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/.test(e)||/^data:image\/(png|jpeg|webp|gif);base64,[a-z0-9+/=]+$/i.test(e))return!0;try{let t=new URL(e);return[`https:`,`blob:`,`sm-media:`].includes(t.protocol)&&!t.username&&!t.password}catch{return!1}}var j=o((()=>{}));function M(e){if(!F(e,[`schemaVersion`,`format`,`name`,`files`])||e.schemaVersion!==1||![`file`,`zip`].includes(e.format)||!I(e.name)||e.name.includes(`/`)||!Array.isArray(e.files)||!e.files.length||e.files.length>N.files||(e.format===`file`?e.files.length!==1||!L(e.name):!e.name.endsWith(`.zip`)))return!1;let t=new Set,n=0;return e.files.every(r=>{if(!P(r)||!I(r.path)||t.has(r.path.toLowerCase()))return!1;let i=r.path.toLowerCase();if([...t].some(e=>i.startsWith(e+`/`)||e.startsWith(i+`/`))||(t.add(i),e.format===`file`&&r.path!==e.name))return!1;if(F(r,[`path`,`text`])&&typeof r.text==`string`&&(L(r.path)||e.format===`zip`&&ee(r.path)))return n+=new TextEncoder().encode(r.text).length,n<=N.textBytes;if(e.format!==`zip`||!F(r,[`path`,`source`])||!R(r.path))return!1;let a=r.source;return P(a)&&A(a.url)&&[`image`,`video`,`audio`].includes(a.kind)&&[`assetId`,`versionId`,`url`].every(e=>typeof a[e]==`string`&&a[e].length>0&&a[e].length<=(e===`url`?8192:200))&&(a.role===void 0||typeof a.role==`string`&&a.role.length<=100)})}var N,P,F,I,L,ee,R,z=o((()=>{j(),N=Object.freeze({files:256,textBytes:3e6,pathLength:180}),P=e=>typeof e==`object`&&!!e&&!Array.isArray(e),F=(e,t)=>P(e)&&Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t)),I=e=>typeof e==`string`&&e.length<=N.pathLength&&/^[A-Za-z0-9_-][A-Za-z0-9_./-]*$/.test(e)&&e.split(`/`).every(e=>e&&![`.`,`..`,`__proto__`,`constructor`,`prototype`].includes(e)&&!e.endsWith(`.`)&&!/^(?:con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\.|$)/i.test(e)),L=e=>/\.(?:txt|md|json|csv|xml|fcpxml|srt|vtt)$/i.test(e),ee=e=>/\.(?:html?|css|[cm]?js|jsx|tsx?|vue|svelte|svg|map|ya?ml|toml|ini|py|[ch]|cc|cpp|hpp|rs|go|java|kt|swift|rb|sh|sql)$/i.test(e),R=e=>/\.(?:png|jpe?g|webp|gif|mp4|webm|mov|mp3|wav|ogg|m4a|flac|bin)$/i.test(e)}));function te(e,t,n){if(!e)throw new ne(t,n)}function B(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e))}var ne,re=o((()=>{ne=class extends Error{constructor(e,t,n=[]){super(t),this.name=`BlockError`,this.code=e,this.details=n}}}));function ie(){let e=e=>typeof e==`object`&&!!e&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),t=/^(string|text|number|integer|boolean|object|json)(\[\])?\??$/,n=new Set([`__proto__`,`prototype`,`constructor`]);function r(i,a=0){return a>40?!1:typeof i==`string`?t.test(i):Array.isArray(i)?i.length===1&&r(i[0],a+1):e(i)&&Object.entries(i).every(([e,t])=>!n.has(e)&&r(t,a+1))}function i(t,r,o=0){return o>40?!1:r==null?!0:Array.isArray(r)?r.length===1&&Array.isArray(t)&&t.every(e=>i(e,r[0],o+1)):typeof r==`string`?r.endsWith(`?`)?t===void 0||i(t,r.slice(0,-1),o+1):r.endsWith(`[]`)?Array.isArray(t)&&t.every(e=>i(e,r.slice(0,-2),o+1)):r===`string`||r===`text`?typeof t==`string`:r===`object`?e(t):r===`json`?a(t,o+1):r===`integer`?Number.isSafeInteger(t):r===`number`?typeof t==`number`&&Number.isFinite(t):r===`boolean`&&typeof t==`boolean`:e(r)&&e(t)&&Object.entries(r).every(([e,r])=>!n.has(e)&&i(Object.hasOwn(t,e)?t[e]:void 0,r,o+1))}function a(t,r){return r>40?!1:t===null||typeof t==`string`||typeof t==`boolean`?!0:typeof t==`number`?Number.isFinite(t):(e(t)||Array.isArray(t))&&Object.entries(t).every(([e,t])=>!n.has(e)&&a(t,r+1))}return{semanticSchemaValid:r,schemaMatches:i,validate:(e,t)=>{try{return r(t)&&a(e,0)&&i(e,t)}catch{return!1}}}}var ae,oe,se,ce=o((()=>{({semanticSchemaValid:ae,schemaMatches:oe}=ie()),Object.freeze([`upstream`,`project`,`adapter`,`chat`,`default`,`user`,`external`]),se=Object.freeze([`key`,`semantic`,`accepts`,`schema`,`sources`,`sensitivity`,`freshnessPolicy`,`cardinality`,`batchable`])})),le,ue=o((()=>{le=Object.freeze([Object.freeze({name:`narration_script`,parents:Object.freeze([`script`])}),Object.freeze({name:`sales_script`,parents:Object.freeze([`script`])}),Object.freeze({name:`timed_transcript`,parents:Object.freeze([`transcript`])}),Object.freeze({name:`product_image`,parents:Object.freeze([`image`])}),Object.freeze({name:`reference_image`,parents:Object.freeze([`image`])}),Object.freeze({name:`generated_image`,parents:Object.freeze([`image`,`source_image`])}),Object.freeze({name:`processed_image`,parents:Object.freeze([`image`,`source_image`])}),Object.freeze({name:`visual_description`,parents:Object.freeze([`plain_text`])}),Object.freeze({name:`transcript_text`,parents:Object.freeze([`plain_text`])}),Object.freeze({name:`editor_timeline`,parents:Object.freeze([`timeline`])}),Object.freeze({name:`legacy.timeline.updatededitor`,parents:Object.freeze([`timeline`])}),Object.freeze({name:`narration_audio`,parents:Object.freeze([`source_audio`])}),Object.freeze({name:`generated_video`,parents:Object.freeze([`source_video`])}),Object.freeze({name:`edited_video`,parents:Object.freeze([`source_video`])}),Object.freeze({name:`rendered_video`,parents:Object.freeze([`source_video`])}),Object.freeze({name:`rendered_audio`,parents:Object.freeze([`source_audio`])})]),new Map(le.map(e=>[e.name,e.parents]))})),de=o((()=>{ce()})),fe=o((()=>{Object.freeze(new Set(`sm.ai-decide@1.0.0,sm.ai-write@1.0.0,sm.board-editor.hosted@3.0.0,sm.board-editor@2.0.0,sm.board-editor@2.1.0,sm.board-editor@2.2.0,sm.board-editor@2.2.1,sm.board-editor@2.2.10,sm.board-editor@2.2.11,sm.board-editor@2.2.2,sm.board-editor@2.2.3,sm.board-editor@2.2.4,sm.board-editor@2.2.5,sm.board-editor@2.2.6,sm.board-editor@2.2.7,sm.board-editor@2.2.8,sm.board-editor@2.2.9,sm.board-editor@3.0.0,sm.captions@2.0.0,sm.character@2.0.0,sm.character@2.0.1,sm.compare@2.0.0,sm.compare@2.0.1,sm.compare@2.0.2,sm.connect-app@1.0.0,sm.contact-fields@1.0.0,sm.edit-assistant@2.0.0,sm.edit-assistant@2.0.1,sm.edit-assistant@2.0.2,sm.editor.hosted@3.0.0,sm.editor@2.0.0,sm.editor@2.1.0,sm.editor@2.2.0,sm.editor@2.2.1,sm.editor@2.2.10,sm.editor@2.2.11,sm.editor@2.2.12,sm.editor@2.2.2,sm.editor@2.2.3,sm.editor@2.2.4,sm.editor@2.2.5,sm.editor@2.2.6,sm.editor@2.2.7,sm.editor@2.2.8,sm.editor@2.2.9,sm.editor@3.0.0,sm.export-audio@2.0.0,sm.export-timeline@2.0.0,sm.export-video@2.0.0,sm.export-video@2.1.0,sm.final-edit@2.0.0,sm.final-edit@2.0.1,sm.final-edit@2.0.2,sm.generate-image@2.0.0,sm.generate-image@2.1.0,sm.generate-video@2.0.0,sm.generate-video@2.0.1,sm.grade@2.0.0,sm.grade@2.0.1,sm.grade@2.0.2,sm.import-media@2.0.0,sm.import-media@2.0.1,sm.import-media@2.0.2,sm.location@2.0.0,sm.location@2.0.1,sm.meta-creative@1.0.0,sm.motion-graphics@2.0.0,sm.panel-strip.hosted@3.0.0,sm.panel-strip@2.0.0,sm.panel-strip@2.1.0,sm.panel-strip@2.2.0,sm.panel-strip@2.3.0,sm.panel-strip@2.3.1,sm.panel-strip@2.3.2,sm.panel-strip@2.3.3,sm.panel-strip@2.3.4,sm.panel-strip@2.3.5,sm.panel-strip@2.3.6,sm.panel-strip@2.3.7,sm.panel-strip@2.4.0,sm.panel-strip@2.4.1,sm.panel-strip@2.4.2,sm.panel-strip@3.0.0,sm.photo-editor@1.0.0,sm.photo-notes@1.0.0,sm.photo-notes@1.1.0,sm.pipeline@2.0.0,sm.pipeline@2.1.0,sm.pipeline@2.2.0,sm.pipeline@2.2.1,sm.pipeline@2.2.2,sm.pipeline@2.2.3,sm.pipeline@2.2.4,sm.pipeline@2.2.5,sm.pipeline@2.2.6,sm.rough-cut@2.0.0,sm.rough-cut@2.0.1,sm.rough-cut@2.0.2,sm.score@2.0.0,sm.style@2.0.0,sm.style@2.0.1,sm.transition@2.0.0,sm.transition@2.0.1,sm.transition@2.0.2,sm.video-assets@2.0.0,sm.video-assets@2.1.0,sm.video-assets@2.1.1,sm.video-assets@2.1.2,sm.video-assets@2.1.3,sm.video-assets@2.1.4,sm.voiceover.hosted@3.0.0,sm.voiceover@2.0.0,sm.voiceover@2.1.0,sm.voiceover@2.1.1,sm.voiceover@2.1.2,sm.voiceover@2.1.3,sm.voiceover@2.1.4,sm.voiceover@2.1.5,sm.voiceover@2.1.6,sm.voiceover@3.0.0,sm.when@1.0.0,sm.when@1.1.0,sm.write-summary@1.0.0,stillmade.generate@1.0.0`.split(`,`)))}));function pe(e){return _e(e,[`schemaVersion`,`startMs`,`endMs`])&&e.schemaVersion===2&&typeof e.startMs==`number`&&Number.isFinite(e.startMs)&&e.startMs>=0&&typeof e.endMs==`number`&&Number.isFinite(e.endMs)&&e.endMs>=e.startMs&&e.endMs<=he}function me(e){return _e(e,[`schemaVersion`,`decision`])&&e.schemaVersion===2&&[`accepted`,`rejected`,`deferred`].includes(e.decision)}var he,ge,_e,ve=o((()=>{he=2**53-1,ge=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),_e=(e,t)=>ge(e)&&Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))})),ye=o((()=>{wt()})),be=o((()=>{wt(),ye(),Object.freeze({routes:16,operations:64,keyLength:80,declarationBytes:65536})})),xe,Se=o((()=>{xe=`(0|[1-9][0-9]{0,5})\\.(0|[1-9][0-9]{0,5})\\.(0|[1-9][0-9]{0,5})`,RegExp(`^`+xe+`$`),RegExp(`^(>=|<=|>|<|=)?`+xe+`$`)}));function Ce(e){return we(e)&&Object.keys(e).length===5&&e.schemaVersion===1&&typeof e.title==`string`&&e.title.trim().length>0&&e.title.length<=200&&Te.includes(e.field)&&we(e.before)&&e.before.schemaVersion===1&&we(e.after)&&e.after.schemaVersion===1}var we,Te,Ee=o((()=>{we=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Te=Object.freeze([`blueprint`,`shotPlan`,`panels`,`board`,`canvas`,`animation`,`editor`])}));function De(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length!==4||!Object.keys(e).every(e=>[`type`,`duration`,`soundOn`,`soundId`].includes(e)))return!1;let t=Oe.find(t=>t.type===e.type);return!!t&&Number.isFinite(e.duration)&&e.duration>=.1&&e.duration<=3&&typeof e.soundOn==`boolean`&&(t.sounds.length?t.sounds.includes(e.soundId):e.soundId===``)}var Oe,ke=o((()=>{Oe=Object.freeze([{type:`Cut`,sounds:[]},{type:`Fade`,sounds:[]},{type:`Cross dissolve`,sounds:[]},{type:`Shape wipe`,sounds:[`shape_sweep`,`shape_pop`]},{type:`Iris`,sounds:[`shape_sweep`,`shape_pop`]},{type:`Ink splat`,sounds:[`shape_sweep`,`shape_pop`]},{type:`Swirl`,sounds:[`whoosh`,`swirl_wind`]},{type:`Whip left`,sounds:[`whip_crack`,`whip_zip`]},{type:`Whip right`,sounds:[`whip_crack`,`whip_zip`]},{type:`Whip up`,sounds:[`whip_crack`,`whip_zip`]},{type:`Whip down`,sounds:[`whip_crack`,`whip_zip`]},{type:`Whip pan`,sounds:[`whip_crack`,`whip_zip`]},{type:`Slash`,sounds:[`shape_sweep`,`shape_pop`]},{type:`Shred`,sounds:[`shape_sweep`,`shape_pop`]},{type:`Morph`,sounds:[`morph_warp`,`morph_bloom`]},{type:`Dip to black`,sounds:[]},{type:`Dip to white`,sounds:[]},{type:`Push left`,sounds:[`push_slide`,`push_thump`]},{type:`Push right`,sounds:[`push_slide`,`push_thump`]},{type:`Push up`,sounds:[`push_slide`,`push_thump`]},{type:`Push down`,sounds:[`push_slide`,`push_thump`]},{type:`Zoom left`,sounds:[]},{type:`Zoom right`,sounds:[]},{type:`Zoom up`,sounds:[]},{type:`Zoom down`,sounds:[]}].map(e=>Object.freeze({...e,sounds:Object.freeze(e.sounds)})))}));function Ae(e){if(!je(e)||e.schemaVersion!==1||!Me(e.title)||!Me(e.timelineId)||!Array.isArray(e.commands)||!e.commands.length||e.commands.length>100||Object.keys(e).some(e=>![`schemaVersion`,`title`,`timelineId`,`commands`].includes(e)))return!1;let t=new Set;return e.commands.every(e=>{if(!je(e)||![`clips`,`audioItems`,`captions`].includes(e.collection)||!je(e.values)||!Fe(e,[`collection`,`operation`,`before`,`values`]))return!1;let n=e.values,r=e.operation===`caption.add`,i=r?n.id:e.before?.id,a=`${e.collection}:${i}`;return!Me(i)||t.has(a)?!1:(t.add(a),e.collection===`captions`?r?e.before===null&&Ve(n)&&Me(n.trackId)&&Re(n):!je(e.before)||!Re(e.before)?!1:e.operation===`caption.update`?Fe(n,[`text`,`start`,`end`])&&Re(n):e.operation===`remove`&&Fe(n,[]):!Object.hasOwn(Pe,e.operation)||!je(e.before)||!Ne(e.before.start,0,86400)||!Ne(e.before.duration,.001,86400)||!Fe(n,Pe[e.operation])?!1:e.operation===`transition`?e.collection===`clips`&&De(n):e.operation===`grade`?e.collection===`clips`&&Le(n):e.operation===`split`?Ne(n.at,0,86400)&&Me(n.newId)&&n.newId!==e.before.id:e.operation===`move`?Ne(n.start,0,86400):e.operation===`trim`?Ne(n.trimStart,0,86400)&&Ne(n.duration,.001,86400):e.operation===`volume`?Ne(n.volume,0,200):e.operation!==`mute`||typeof n.muted==`boolean`)})}var je,Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He=o((()=>{ke(),je=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Me=e=>typeof e==`string`&&e.length>0&&e.length<=200,Ne=(e,t,n)=>Number.isFinite(e)&&e>=t&&e<=n,Pe={move:[`start`],trim:[`trimStart`,`duration`],volume:[`volume`],mute:[`muted`],remove:[],split:[`at`,`newId`],grade:[`lut`,`color`],transition:[`type`,`duration`,`soundOn`,`soundId`]},Fe=(e,t)=>Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t)),Ie={brightness:[-100,100],contrast:[-100,100],saturation:[-100,100],temperature:[-100,100],sharpness:[-50,50],vignette:[0,100]},Le=e=>[`None`,`Cold`,`Warm`,`Desaturated`,`High Contrast`,`Filmic`,`Teal and Orange`].includes(e.lut)&&je(e.color)&&Fe(e.color,Object.keys(Ie))&&Object.entries(Ie).every(([t,[n,r]])=>Ne(e.color[t],n,r)),Re=e=>typeof e.text==`string`&&e.text.trim().length>0&&e.text.length<=5e3&&Ne(e.start,0,86400)&&Ne(e.end,0,86400)&&e.end-e.start>=.001,ze=[`id`,`trackId`,`text`,`start`,`end`],Be={font:e=>e===`Hanken Grotesk`,size:e=>Ne(e,8,200),color:e=>typeof e==`string`&&/^#[a-f0-9]{3}(?:[a-f0-9]{3})?$/i.test(e),highlightColor:e=>typeof e==`string`&&/^#[a-f0-9]{3}(?:[a-f0-9]{3})?$/i.test(e),background:e=>e===`none`||typeof e==`string`&&/^#[a-f0-9]{3}(?:[a-f0-9]{3})?$/i.test(e),backgroundOpacity:e=>Ne(e,0,100),backgroundPadding:e=>Ne(e,0,100),backgroundRadius:e=>Ne(e,0,100),position:e=>[`top left`,`top center`,`top right`,`middle left`,`middle center`,`middle right`,`bottom left`,`bottom center`,`bottom right`].includes(e),animation:e=>[`none`,`fade`].includes(e)},Ve=e=>!ze.every(t=>Object.hasOwn(e,t))||Object.keys(e).some(e=>!ze.includes(e)&&e!==`words`&&!Object.hasOwn(Be,e))||!Object.entries(Be).every(([t,n])=>!Object.hasOwn(e,t)||n(e[t]))?!1:!Object.hasOwn(e,`words`)||Array.isArray(e.words)&&e.words.length<=1e3&&e.words.every((t,n)=>je(t)&&Fe(t,[`text`,`start`,`end`])&&typeof t.text==`string`&&t.text.trim().length>0&&t.text.length<=5e3&&Ne(t.start,e.start,e.end)&&Ne(t.end,t.start,e.end)&&(n===0||t.start>=e.words[n-1].start))})),Ue,We=o((()=>{Ue=Object.freeze([`screen.capture`,`cursor.track`,`camera.capture`,`microphone.capture`,`clipboard.read`,`clipboard.write`,`media.pick`,`notifications.show`,`power.keep-awake`,`native.tools`,`folder.read`,`folder.write`])})),Ge=o((()=>{Object.freeze({"org.stillmade.PythonAdapter":Object.freeze({id:`org.stillmade.PythonAdapter`,adapterVersion:1,label:`Python connection`,actions:Object.freeze([`adapter.import`,`adapter.inspect`,`adapter.execute`,`adapter.describe`,`adapter.call`]),projectExtensions:Object.freeze([`py`])}),"org.natron.Natron":Object.freeze({id:`org.natron.Natron`,adapterVersion:1,label:`Natron`,actions:Object.freeze([`launch`,`project.import`,`project.open`,`project.render`]),projectExtensions:Object.freeze([`ntp`])})})}));function Ke(e){return $e(e)&&e.kind===`file`&&tt(e.assetId,512)&&tt(e.versionId,512)&&it.includes(e.mimeType)&&(e.url===void 0||tt(e.url,32768))&&(e.name===void 0||tt(e.name,nt.fileName))&&(e.bytes===void 0||Number.isSafeInteger(e.bytes)&&e.bytes>=0)}function qe(e){return $e(e)&&Object.keys(e).every(e=>[`schemaVersion`,`format`,`text`,`title`].includes(e))&&e.schemaVersion===1&&at.includes(e.format)&&typeof e.text==`string`&&e.text.length<=nt.documentText&&(e.title===void 0||typeof e.title==`string`&&e.title.length<=nt.documentTitle)}function Je(e){if(!$e(e)||!Object.keys(e).every(e=>[`schemaVersion`,`columns`,`rows`].includes(e))||e.schemaVersion!==void 0&&e.schemaVersion!==1)return!1;let{columns:t,rows:n}=e;if(!Array.isArray(t)||!t.length||t.length>nt.tableColumns||!Array.isArray(n)||n.length>nt.tableRows||!t.every(e=>typeof e==`string`&&e.trim().length>0&&e.length<=nt.columnName&&!et.has(e))||new Set(t).size!==t.length)return!1;let r=new Set(t),i=0;for(let e of n){if(!$e(e))return!1;for(let[t,n]of Object.entries(e))if(!r.has(t)||!ot(n)||++i>nt.tableCells)return!1}return!0}function Ye(e){if(typeof e!=`string`||!e.length||e.length>nt.url||/[\s\u0000-\u001f\u007f]/.test(e))return!1;let t;try{t=new URL(e)}catch{return!1}return[`http:`,`https:`].includes(t.protocol)&&t.hostname.length>0&&!t.username&&!t.password}function Xe(e){let t=typeof e==`string`?st.exec(e):null;if(!t)return!1;let[n,r,i,a=0,o=0,s=0,c=0,l=0]=t.slice(1).map(e=>e===void 0?void 0:Number(e)),u=[31,n%4==0&&(n%100!=0||n%400==0)?29:28,31,30,31,30,31,31,30,31,30,31][r-1];return r>=1&&r<=12&&i>=1&&i<=u&&a<=23&&o<=59&&s<=59&&c<=14&&l<=59}function Ze(e){return typeof e==`string`&&/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(e)}function Qe(e){if(!Je(e))throw Error(`Choose a valid table.`);return[e.columns.map(ct).join(`,`),...e.rows.map(t=>e.columns.map(e=>ct(t[e])).join(`,`))].join(`\r
|
|
9
|
-
`)}var $e,et,tt,nt,rt,it,at,ot,st,ct,lt=o((()=>{$e=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),et=new Set([`__proto__`,`prototype`,`constructor`]),tt=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,nt=Object.freeze({fileName:255,documentText:1e6,documentTitle:300,tableColumns:500,tableRows:1e5,tableCells:5e5,columnName:160,cellText:1e5,url:8192}),rt=Object.freeze({pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`}),it=Object.freeze([...new Set(Object.values(rt))]),at=Object.freeze([`markdown`,`plain`]),ot=e=>e===null||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)||typeof e==`string`&&e.length<=nt.cellText,st=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/,ct=e=>{let t=e==null?``:String(e);return/[",\r\n]/.test(t)?`"${t.replaceAll(`"`,`""`)}"`:t}})),ut=o((()=>{Object.freeze({origins:8,requestBytes:4194304,responseBytes:8388608,timeoutMs:3e4,redirects:3,headers:32,headerBytes:16384,urlLength:8192,requestsPerMinute:120,originRequestsPerMinute:3e3,keyLength:4096}),Object.freeze([`GET`,`HEAD`,`POST`,`PUT`,`PATCH`,`DELETE`]),Object.freeze([`bearer`,`header`,`query`,`oauth2`]),Object.freeze({sockets:4,messageBytes:1048576,runBytes:268435456,protocols:8})})),dt=o((()=>{Object.freeze([`media.saved`,`schedule`,`webhook`,`project.completed`,`provider`]),Object.freeze({triggers:4,labelLength:120,minEverySeconds:60,maxEverySeconds:31536e3}),Object.freeze([`recipe`,`javascript`,`capability`])})),ft=o((()=>{Object.freeze({features:24,id:48,label:40,does:160,asks:8,ask:80})}));function pt(e,t=0,n={nodes:0}){if(V(t<=40&&++n.nodes<=5e5,`LIMIT`,`Document exceeds complexity limit`),!(e===null||[`string`,`boolean`].includes(typeof e))){if(typeof e==`number`){V(Number.isFinite(e),`SCHEMA`,`Numbers must be finite`);return}V(Array.isArray(e)||_t(e),`SCHEMA`,`Only JSON data is accepted`);for(let[r,i]of Object.entries(e))V(!Ct.has(r),`SCHEMA`,`Forbidden field: ${r}`),pt(i,t+1,n)}}function mt(e){pt(e);let t=e=>Array.isArray(e)?e.map(t):_t(e)?Object.fromEntries(Object.keys(e).sort().map(n=>[n,t(e[n])])):e;return JSON.stringify(t(e))}async function ht(e){let t=new TextEncoder().encode(mt(e)),n=await globalThis.crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}function gt(e,t){if(typeof t==`object`&&t&&t.schema!=null&&!oe(e,t.schema))return!1;let n=typeof t==`string`?t:t.type;if(n===`object`)try{return pt(e),_t(e)}catch{return!1}if(n?.endsWith(`[]`))return Array.isArray(e)&&e.every(e=>gt(e,n.slice(0,-2)));if(n===`text`)return typeof e==`string`&&e.length<=1e6;if(n===`boolean`)return typeof e==`boolean`;if(n===`url`)return Ye(e);if(n===`date`)return Xe(e);if(n===`color`)return Ze(e);if(n===`file`)return Ke(e);if(n===`document`)return qe(e);if(n===`table`)try{return pt(e),Je(e)}catch{return!1}if(n===`number`||n===`integer`)return typeof e==`number`&&Number.isFinite(e)&&(n!==`integer`||Number.isInteger(e))&&(t.min==null||e>=t.min)&&(t.max==null||e<=t.max);if(n===`file-bundle`)try{return pt(e),M(e)}catch{return!1}if(n===`workspace-edit`)try{return pt(e),Ce(e)}catch{return!1}if(n===`timeline-edit`)try{return pt(e),Ae(e)}catch{return!1}if(n===`timeline-range`||n===`approval`)return _t(e)&&e.schemaVersion===1?!0:n===`timeline-range`?pe(e):me(e);if(n===`json`)try{return pt(e),!0}catch{return!1}return n===`image`&&_t(e)&&Array.isArray(e.data)?Number.isInteger(e.width)&&Number.isInteger(e.height)&&e.width>0&&e.height>0&&e.width*e.height<=1048576&&e.data.length===e.width*e.height*4&&e.data.every(e=>Number.isInteger(e)&&e>=0&&e<=255):[`image`,`video`,`audio`,`asset`].includes(n)?_t(e)&&typeof e.assetId==`string`&&typeof e.versionId==`string`&&(n===`asset`||e.kind===n):vt.includes(n)&&_t(e)&&e.schemaVersion===1}var V,_t,vt,yt,bt,xt,St,Ct,wt=o((()=>{k(),z(),re(),ce(),ue(),de(),fe(),ve(),be(),Se(),Ee(),He(),We(),Ge(),lt(),ut(),dt(),ft(),V=te,_t=B,Object.freeze([`type`,`required`,`default`,`min`,`max`,`description`,`role`,`primary`,`context`,`imageMode`,...se]),vt=Object.freeze(`text.number.integer.boolean.json.object.image.video.audio.asset.script.transcript.brief.bible.shot-plan.panel-document.board-document.scene-document.timeline.timeline-edit.file-bundle.workspace-edit.timeline-range.research.character.location.style.pipeline.approval.scene.shot.mask.depth.pose.metadata.project-context.file.document.table.url.date.color`.split(`.`)),Object.freeze([`final.render`,`stock.search`,`stock.select`,`stock.auto`,`gif.search`,`gif.save`,`presenter.generate`,`quality.analyze`,`image.generate`,`image.generate.batch`,`media.generate`,`youtube.upload`]),Object.freeze([`text`,`number`,`slider`,`checkbox`,`asset`,`select`,`multiselect`,`file`,`date`,`color`,`url`,`richtext`,`list`,`grid`]),Object.freeze([`gallery`,`before-after`,`table`,`document`,`chart`,`code`,`player`,`download`]),Object.freeze({file:[`file`,`file[]`],date:[`date`],color:[`color`],url:[`url`],richtext:[`document`,`text`],list:[`text[]`,`number[]`,`integer[]`,`url[]`,`date[]`,`color[]`],grid:[`table`]}),Object.freeze({gallery:[`image[]`],"before-after":[`image`],table:[`table`],document:[`document`,`text`],chart:[`table`,`number[]`,`integer[]`],code:[`text`,`json`,`object`],player:[`audio`,`video`,`audio[]`,`video[]`],download:[`file`,`file[]`,`file-bundle`]}),yt=Object.freeze({script:`script`,transcript:`transcript`,shots:`shot[]`,shotPlan:`shot-plan`,scenes:`scene[]`,characters:`character[]`,locations:`location[]`,styles:`style[]`,assets:`asset[]`,files:`file[]`,generations:`metadata[]`,versions:`metadata[]`,timeline:`timeline`,editor:`timeline`,canvas:`pipeline`,blueprint:`bible`,panels:`panel-document`,board:`board-document`,animation:`scene-document`,metadata:`metadata`}),bt=(e,t,n,r)=>Object.freeze({executor:e,mode:t,byok:n,summary:r}),xt=Object.freeze({"text.generate":bt(`capability-run`,`sync`,!0,`Exact model, account BYOK or credits, and explicit run review`),"audio.speech":bt(`capability-run`,`sync`,!0,`One short text/script input to measured audio in any StillMade catalog voice (Deepgram, ElevenLabs, OpenAI, Kokoro) with credits, or OpenAI with your key; playback review; accepted project recordings can be explicitly added to Editor audio`),"audio.transcribe":bt(`capability-run`,`sync`,!0,`One owner-scoped stored audio asset to reviewed text and ordered word timings with StillMade transcription on credits, or OpenAI Whisper with your key`),"audio.music":bt(`capability-run`,`sync`,!1,`One prompt to generated music (5–240 seconds) with StillMade credits and playback review`),"audio.sfx":bt(`capability-run`,`sync`,!1,`One prompt to a generated sound effect (0.5–22 seconds) with StillMade credits and playback review`),"image.generate":bt(`capability-run`,`sync`,!0,`One prompt and optional reference images to a stored PNG with any catalog image model and its settings; StillMade credits or account key, and actual image review`),"video.generate":bt(`capability-run`,`async`,!0,`One prompt and optional first/last frames to a measured stored video clip with any catalog video model and its settings; StillMade credits and actual video review`),"image.describe":bt(`capability-run`,`sync`,!0,`One to four owned images to bounded production notes; host-selected model/payment and actual description review`),"media.analyze":bt(`capability-run`,`sync`,!1,`One owned video (optionally one time range), image or up to four images to structured visual evidence: summary, timeline, observations, on-screen text and issues, with StillMade credits; detail "check" gives one to four photos a short answer each at one price per call`),"web.fetch":bt(`capability-run`,`sync`,!1,`One public web page read by the host and answered against the Block's instruction, with StillMade credits; no cookies, keys or private addresses`),"web.research":bt(`capability-run`,`sync`,!1,`One topic searched on the web and summarized with cited sources, with StillMade credits`),"timeline.propose":bt(`capability-run`,`sync`,!0,`Bounded typed context to strict timeline-edit JSON; host-selected model/payment, stale-before checks, preview and Apply`),"workspace.propose":bt(`capability-run`,`sync`,!0,`Bounded typed context to a strict workspace-edit proposal for one permitted workspace; preview and explicit Apply`),"connection.execute":bt(`connection`,`sync`,!1,`One reviewed action on a connected third-party app account through the host connection service; the Block never receives account credentials`)}),St=e=>Object.freeze(Object.entries(xt).filter(([,t])=>e(t)).map(([e])=>e)),St(()=>!0),St(e=>e.executor===`capability-run`),St(e=>e.executor===`capability-run`&&e.mode===`sync`),St(e=>e.byok),[...Object.keys(yt).map(e=>`context.${e}.read`)],Ct=new Set([`__proto__`,`prototype`,`constructor`])}));wt();var Tt=Object.freeze([`tasks`,`preview-task`,`apply-task`]);function Et(e,t={}){return V(Tt.includes(e),`CONNECTION_TASK`,`Choose a declared task operation.`),pt(t),V(_t(t)&&JSON.stringify(t).length<=32768,`CONNECTION_TASK`,`Use bounded task selection arguments.`),{operation:e,args:structuredClone(t)}}function Dt(e,t,n,r){let i=0,a=new Map;return addEventListener(`message`,n=>{let r=n.data;if(n.source!==parent||!r||r.channel!==e||r.session!==t||r.op!==`connected-app-result`)return;let i=a.get(r.id);i&&(a.delete(r.id),r.error?i.reject(Error(r.error)):i.resolve(r.result))}),{connectedApp(o,s={}){if(!n)return Promise.reject(Error(`This Block has no connected-app task contract.`));if(![`tasks`,`preview-task`,`apply-task`].includes(o)||!s||typeof s!=`object`||Array.isArray(s)||JSON.stringify(s).length>32768)return Promise.reject(Error(`Invalid task choice.`));if(a.size>=2)return Promise.reject(Error(`Wait for the current task choice.`));let c=String(++i);return new Promise((n,i)=>{a.set(c,{resolve:n,reject:i}),r({channel:e,session:t,op:`connected-app-request`,id:c,operation:o,args:s},`*`)})}}}function Ot(e,t,n,r){let i=new Set,a=new Set,o=new Set,s=(e,t)=>{if(typeof t!=`function`)throw TypeError(`Pass a function.`);return e.add(t),()=>{e.delete(t)}},c=e=>{typeof reportError==`function`&&reportError(e)},l=(e,...t)=>{for(let n of[...e])try{n(...t)}catch(e){c(e)}};return{live:Object.freeze({start:(e={})=>r(`live.start`,e),stop:()=>r(`live.stop`,{}),status:()=>r(`live.status`,{}),onFrame:e=>s(i,e),onAudio:e=>s(a,e),onEnd:e=>s(o,e)}),receive:r=>{if(r.op!==`live`)return!1;if(r.type===`frame`)try{l(i,r.bitmap,{index:r.index,timestamp:r.timestamp,width:r.width,height:r.height})}finally{try{r.bitmap?.close?.()}catch{}n({channel:e,session:t,op:`live-ack`},`*`)}else r.type===`audio`?l(a,r.samples,{index:r.index,timestamp:r.timestamp,sampleRate:r.sampleRate}):r.type===`ended`&&l(o,{reason:String(r.reason||`stopped`)});return!0},dispose(){i.clear(),a.clear(),o.clear()}}}function kt(e){let t=0,n=null,r=[],i=0,a=new Map,o=()=>{if(n||!r.length)return;let s=r.shift();n=s,Promise.resolve().then(()=>{if(s.generation!==t)throw Error(`Preview input changed`);return s.edge===void 0?e(s.kind,s.value):e(s.kind,s.value,{edge:s.edge})}).then(e=>{s.kind===`image`&&s.generation===t&&(a.delete(s.serialized),a.set(s.serialized,e),a.size>48&&a.delete(a.keys().next().value)),s.resolve(e)},s.reject).finally(()=>{n===s&&(n=null,i-=s.bytes,o())})};return{request(e,s,c){let l,u,d,f;try{if(![`image`,`media`].includes(e)||!s||Array.isArray(s)||typeof s!=`object`)throw Error(`Expected a bounded preview value`);if(d=c?.edge,d!==void 0&&(e!==`image`||!Number.isInteger(d)||d<64||d>2048))throw Error(`Ask for an image preview edge from 64 to 2048 pixels, as in StillMade.previewImage(photo, {edge: 2048}).`);if(f=JSON.stringify(s),l=d===void 0?f:`${f}@${d}`,u=new TextEncoder().encode(f).length,u>4194304)throw Error(`Expected a bounded preview value`)}catch(e){return Promise.reject(e)}if(e===`image`&&a.has(l))return Promise.resolve(a.get(l));let p=e===`image`&&[n,...r].find(t=>t?.kind===e&&t.serialized===l);if(p)return p.promise;if(r.length+ +!!n>=64||i+u>8388608)return Promise.reject(Error(`Too many queued previews. Wait for a preview to finish.`));let m={kind:e,value:JSON.parse(f),serialized:l,bytes:u,generation:t,edge:d};return m.promise=new Promise((e,t)=>{m.resolve=e,m.reject=t}),i+=u,r.push(m),o(),m.promise},reset(e=`Preview input changed`){t+=1;for(let t of[n,...r])t&&t.reject(Error(e));n=null,r=[],i=0}}}function At(){return null}function jt(){try{return typeof indexedDB<`u`&&indexedDB!==null}catch{return!1}}function Mt(){return Bt||(Bt=new Promise((e,t)=>{let n;try{n=indexedDB.open(Pt,Ft)}catch(e){t(e);return}n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(`cacheMeta`)||e.createObjectStore(It,{keyPath:`key`}),e.objectStoreNames.contains(`blobs`)||e.createObjectStore(Lt),e.objectStoreNames.contains(`handles`)||e.createObjectStore(Rt),e.objectStoreNames.contains(`deviceMedia`)||e.createObjectStore(zt,{keyPath:`id`})},n.onsuccess=()=>{let t=n.result;t.onversionchange=()=>{t.close(),Bt=null},e(t)},n.onerror=()=>t(n.error||Error(`indexedDB open failed`)),n.onblocked=()=>t(Error(`indexedDB blocked`))}),Bt.catch(()=>{Bt=null}),Bt)}function Nt(e,t,n){return Mt().then(r=>new Promise((i,a)=>{let o;try{o=r.transaction(e,t)}catch(e){a(e);return}let s;try{s=n(o.objectStore(e))}catch(e){a(e);return}o.oncomplete=()=>i(s?s.result:void 0),o.onerror=()=>a(o.error||Error(`idb tx error`)),o.onabort=()=>a(o.error||Error(`idb tx aborted`))}))}var Pt,Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt=o((()=>{Pt=`aivw_editor`,Ft=2,It=`cacheMeta`,Lt=`blobs`,Rt=`handles`,zt=`deviceMedia`,Bt=null,Vt=(e,t)=>Nt(e,`readonly`,e=>e.get(t)),Ht=e=>Nt(e,`readonly`,e=>e.getAll()),Ut=(e,t,n)=>Nt(e,`readwrite`,e=>n===void 0?e.put(t):e.put(t,n)),Wt=(e,t)=>Nt(e,`readwrite`,e=>e.delete(t))}));function Kt(){try{return typeof localStorage>`u`?null:JSON.parse(localStorage.getItem(qt)||`null`)?.user?.id||null}catch{return null}}var qt,Jt=o((()=>{qt=`ai-video-workflow-auth`}));function Yt(){let e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),t=new Uint32Array(64),n=new Uint8Array(64),r=0,i=0,a=(n,r)=>{for(let e=0;e<16;e++)t[e]=n[r+e*4]<<24|n[r+e*4+1]<<16|n[r+e*4+2]<<8|n[r+e*4+3];for(let e=16;e<64;e++){let n=Qt(t[e-15],7)^Qt(t[e-15],18)^t[e-15]>>>3,r=Qt(t[e-2],17)^Qt(t[e-2],19)^t[e-2]>>>10;t[e]=t[e-16]+n+t[e-7]+r>>>0}let i=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=e[5],u=e[6],d=e[7];for(let e=0;e<64;e++){let n=Qt(c,6)^Qt(c,11)^Qt(c,25),r=c&l^~c&u,f=d+n+r+Zt[e]+t[e]>>>0,p=(Qt(i,2)^Qt(i,13)^Qt(i,22))+(i&a^i&o^a&o)>>>0;d=u,u=l,l=c,c=s+f>>>0,s=o,o=a,a=i,i=f+p>>>0}e[0]=e[0]+i>>>0,e[1]=e[1]+a>>>0,e[2]=e[2]+o>>>0,e[3]=e[3]+s>>>0,e[4]=e[4]+c>>>0,e[5]=e[5]+l>>>0,e[6]=e[6]+u>>>0,e[7]=e[7]+d>>>0};return{update(e){let t=e instanceof Uint8Array?e:new Uint8Array(e);i+=t.length;let o=0;if(r){let e=Math.min(64-r,t.length);if(n.set(t.subarray(0,e),r),r+=e,o=e,r<64)return this;a(n,0),r=0}for(;o+64<=t.length;o+=64)a(t,o);return o<t.length&&(n.set(t.subarray(o),0),r=t.length-o),this},digest(){let t=i*8,o=new Uint8Array(r<56?64:128);o.set(n.subarray(0,r)),o[r]=128;let s=new DataView(o.buffer);s.setUint32(o.length-8,Math.floor(t/4294967296)),s.setUint32(o.length-4,t>>>0);for(let e=0;e<o.length;e+=64)a(o,e);return[...e].map(e=>e.toString(16).padStart(8,`0`)).join(``)}}}async function Xt(e,{subtleLimit:t=$t,signal:n}={}){if(e.size<=t&&typeof crypto?.subtle?.digest==`function`){let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer());return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}let r=Yt();for(let t=0;t<e.size;t+=en)n?.throwIfAborted?.(),r.update(new Uint8Array(await e.slice(t,t+en).arrayBuffer()));return r.digest()}var Zt,Qt,$t,en,tn=o((()=>{Zt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=(e,t)=>e>>>t|e<<32-t,$t=67108864,en=8388608}));function nn(){if(Nn!==void 0)return Nn;try{return Kt()||null}catch{return null}}async function rn(){if(jn!==void 0)return jn;try{jn=navigator?.storage?.getDirectory?await(await navigator.storage.getDirectory()).getDirectoryHandle(yn,{create:!0}):null}catch{jn=null}return jn}async function an(){if(!Mn){Mn=!0;try{await navigator?.storage?.persist?.()}catch{}}}async function on(e,t){let n=await rn();if(n){let r=await(await n.getFileHandle(t,{create:!0})).createWritable();return await r.write(e),await r.close(),`opfs`}return await Ut(Lt,e,`device:${t}`),`idb`}function sn(){try{window.dispatchEvent(new CustomEvent(An,{detail:{needed:kn.size}}))}catch{}}async function cn(e){let t=Rn(e);if(typeof t?.getFile!=`function`)throw Ln(`DEVICE_MEDIA_MOVED`,`This file is no longer linked on this computer.`);if(typeof t.queryPermission==`function`&&await t.queryPermission({mode:`read`})!==`granted`)throw kn.has(e.id)||(kn.set(e.id,t),sn()),Ln(`DEVICE_MEDIA_ACCESS`,`Allow StillMade to open this file on your computer again.`);let n;try{n=await t.getFile()}catch{throw Ln(`DEVICE_MEDIA_MOVED`,`This file was moved, renamed or deleted on this computer.`)}if(n.size!==e.bytes||e.lastModified&&n.lastModified!==e.lastModified)throw Ln(`DEVICE_MEDIA_CHANGED`,`This file changed on this computer after it was added.`);return n}async function ln(e){if(e.storage===`linked`)return cn(e);if(e.storage===`opfs`){let t=await rn();if(!t)throw Error(`Device storage is unavailable.`);return(await t.getFileHandle(e.versionId)).getFile()}let t=await Vt(Lt,`device:${e.versionId}`);if(!t)throw Error(`This media is not on this device.`);return t}function un(){return jt()&&typeof crypto?.subtle?.digest==`function`}async function dn(e,{kind:t,metadata:n={},role:r=`original`,links:i={},assetId:a=crypto.randomUUID(),signal:o,maxBytes:s=bn,handle:c=null}={}){if(!un())throw Error(`This browser cannot keep media on the device.`);if(!c&&e.size>s)throw Error(`Files over ${Math.round(s/1024/1024)>=1024?`${Math.round(s/1024/1024/1024*10)/10} GB`:`${Math.round(s/1024/1024)} MB`} stay where they are; use StillMade Desktop for larger media.`);o?.throwIfAborted?.(),await an();let l=await Fn(e,o);o?.throwIfAborted?.();let u=await Ht(zt).then(e=>e.find(e=>e.versionId===l&&e.kind===t)).catch(()=>null),d=c?`linked`:[`opfs`,`idb`].includes(u?.storage)?u.storage:await on(e,l);o?.throwIfAborted?.(),c&&On.set(l,c);let f={id:`${a}:${l}`,assetId:a,versionId:l,kind:t,role:r,name:String(e.name||``).slice(0,240),mimeType:e.type||n.mimeType||``,bytes:e.size,...zn(n,[`width`,`height`,`duration`]),storage:d,...c?{handle:c,lastModified:e.lastModified}:{},source:`local`,...i,...nn()?{owner:nn()}:{},cloud:{},createdAt:Date.now()};return await Ut(zt,f),f}async function fn(e){if(!e?.assetId||!e?.versionId)return null;let t=await Vt(`deviceMedia`,In(e)).catch(()=>null)||null;return t&&Pn(t)?t:null}async function pn(e,t=Bn.get(Cn(e))){if(!t)return null;let n=e=>fetch(t,{credentials:`omit`,redirect:`follow`,referrerPolicy:`no-referrer`,...e?{cache:e}:{}}),r;try{r=await n()}catch(e){if(!(e instanceof TypeError))return null;try{r=await n(`reload`)}catch{return null}}if(!r?.ok)return null;let i=await r.blob();return await Fn(i)===e.versionId?i:null}async function mn(e){let t=await fn(e);if(t)return ln(t);let n=await pn(e).catch(()=>null);if(!n)throw Error(`This media is not on this device.`);return n}async function hn(e){let t=In(e);if(En.has(t))return En.get(t);let n=URL.createObjectURL(await mn(e));return En.set(t,n),Dn.add(n),n}async function gn(e){let t=wn(e);if(!t)return null;try{return await hn(t)}catch{return null}}function _n(e,{role:t,name:n}={}){let r={kind:e.kind,assetId:e.assetId,versionId:e.versionId,url:Cn(e),source:`local`,name:n||e.name,mimeType:e.mimeType,bytes:e.bytes};for(let t of[`width`,`height`,`duration`])e[t]!==void 0&&e[t]!==null&&(r[t]=e[t]);return t&&(r.role=t),r}async function vn(){let e=(await Ht(zt).catch(()=>[])).filter(e=>e.storage!==`linked`),t=new Set,n=e.reduce((e,n)=>t.has(n.versionId)?e:(t.add(n.versionId),e+(n.bytes||0)),0),r=null;try{r=(await navigator.storage.estimate()).quota||null}catch{}return{files:t.size,bytes:n,quota:r}}var yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn=o((()=>{Gt(),Jt(),tn(),yn=`device-media`,bn=268435456,xn=`sm-media://device/`,Sn=/^sm-media:\/\/device\/([a-f0-9-]{36})\/([a-f0-9]{64})$/,Cn=e=>`${xn}${e.assetId}/${e.versionId}`,wn=e=>{let t=Sn.exec(String(e||``));return t?{assetId:t[1],versionId:t[2]}:null},Tn=e=>Sn.test(String(e||``)),En=new Map,Dn=new Set,On=new Map,kn=new Map,An=`stillmade:device-media-access`,Mn=!1,Pn=e=>{let t=nn();return!e?.owner||!t||e.owner===t},Fn=(e,t)=>Xt(e,{signal:t}),In=e=>`${e.assetId}:${e.versionId}`,Ln=(e,t)=>Object.assign(Error(t),{code:e}),Rn=e=>On.get(e.versionId)||e.handle,zn=(e,t)=>Object.fromEntries(t.filter(t=>e?.[t]!==void 0&&e[t]!==null).map(t=>[t,e[t]])),Bn=new Map}));Vn();var Hn=Object.freeze({bytes:25165824,timeoutMs:15e3}),Un=Object.freeze({image:[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],video:[`video/mp4`,`video/webm`,`video/ogg`,`video/quicktime`],audio:[`audio/mpeg`,`audio/mp3`,`audio/mp4`,`audio/aac`,`audio/ogg`,`audio/wav`,`audio/x-wav`,`audio/webm`,`audio/flac`]});function Wn(e){if(!e||!Un[e.kind]?.includes(e.blob?.type)||!(e.blob instanceof Blob)||!e.blob.size||!e.local&&e.blob.size>Hn.bytes)throw Error(`The host returned an unsupported or oversized media preview.`);return{kind:e.kind,blob:e.blob,...e.local===!0?{local:!0}:{}}}var Gn=/^\/api\/media\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/;async function Kn(e,{signal:t,check:n=()=>{}}={}){if(n(),Tn(e.url)){let t=wn(e.url),r=await fn(t);if(n(),!r)throw Error(`This media is not on this device. Open the project on the device that holds it.`);let i=await mn(t);n();let a=String(r.mimeType||i.type||``).split(`;`)[0].trim().toLowerCase();if(!Un[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);return Wn({kind:e.kind,blob:i.type===a?i:new Blob([i],{type:a}),local:!0})}let r=n=>fetch(e.url,{signal:t,credentials:`omit`,redirect:Gn.test(e.url)?`follow`:`error`,referrerPolicy:`no-referrer`,...n?{cache:n}:{}}),i;try{i=await r()}catch(a){if(a?.name===`AbortError`||!(a instanceof TypeError))throw a;n();try{i=await r(`no-store`)}catch(r){if(r?.name===`AbortError`||!(r instanceof TypeError))throw r;let a=Error(`This media could not reach StillMade. Check your connection and try again.`);if(!Gn.test(e.url))throw a;n();try{i=await fetch(e.url.replace(/^\/api\/media\//,`/api/media/bytes/`),{signal:t,credentials:`omit`,redirect:`error`,referrerPolicy:`no-referrer`,cache:`no-store`})}catch(e){throw e?.name===`AbortError`?e:a}if(i.status===413)throw Error(`This media is too large to preview here. Download it to play it.`)}}if(n(),!i.ok)throw Error(`This media could not be loaded. Upload a local copy to preview it.`);let a=(i.headers.get(`content-type`)||``).split(`;`)[0].trim().toLowerCase();if(!Un[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);if(Number(i.headers.get(`content-length`))>Hn.bytes)throw Error(`Preview media must be under 24 MB.`);if(!i.body?.getReader)throw Error(`Streaming media previews are unavailable in this browser.`);let o=i.body.getReader(),s=[],c=0;try{for(;;){if(n(),t?.aborted)throw new DOMException(`Media preview cancelled`,`AbortError`);let{done:e,value:r}=await o.read();if(n(),e)break;if(c+=r.byteLength,c>Hn.bytes)throw Error(`Preview media must be under 24 MB.`);s.push(r)}return Wn({kind:e.kind,blob:new Blob(s,{type:a})})}finally{await o.cancel().catch(()=>{}),o.releaseLock()}}var qn=new Set;function Jn(e){return qn.add(e),()=>qn.delete(e)}function Yn(e,t,n,r=null,i=[]){let a=new Map,o=[`text`,`search`,`email`,`tel`,`url`],s=new Set(i),c=new Map,l=new Set,u=new Map,d=!1,f={},p=(e,t,n)=>e?e.some(e=>e.value===String(n)):t.tagName!==`SELECT`||[...t.options].some(e=>e.value===String(n)),m=(e,t)=>{if(clearTimeout(t.timer),c.delete(e),d)return;let r;return r=Promise.resolve().then(()=>{if(!d)return t.callback()}).catch(t=>{u.set(e,t),n(t.message)}).finally(()=>l.delete(r)),l.add(r),r},h=(e,t)=>{if(d)throw Error(`This interface has closed; shared edits stopped.`);if(typeof e!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e))throw Error(`A shared edit key starts with a letter and holds only letters, digits, - and _ (up to 100 characters).`);if(typeof t!=`function`)throw Error(`Give scheduleSharedEdit a function to run.`);if(!c.has(e)&&c.size+l.size>=32||!u.has(e)&&u.size>=32)throw Error(`Too many scheduled shared edits`);u.delete(e);let n=c.get(e),r={callback:t,started:n?.started??Date.now(),timer:null};n&&clearTimeout(n.timer),r.timer=setTimeout(()=>m(e,r),Math.max(0,Math.min(150,500-(Date.now()-r.started)))),c.set(e,r)},g=(i,c)=>{if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(i)||a.has(i))throw Error(`Use one control per named shared field`);let l=e.getElementById(c),u=l?.tagName===`FIELDSET`?[...l.querySelectorAll(`input[type="radio"]`)]:null;if(!l||![`INPUT`,`TEXTAREA`,`SELECT`,`FIELDSET`].includes(l.tagName)||u&&!u.length||l.tagName===`INPUT`&&![`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`].includes(l.type))throw Error(`Bind an existing text, number, checkbox or select control, or a fieldset of radio buttons`);if(s.has(i)){let e=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),t=l.disabled,n=l.readOnly,r=l.getAttribute(`title`),s=l.getAttribute(`aria-readonly`),c=l.getAttribute(`aria-disabled`);e?(l.readOnly=!0,l.setAttribute(`aria-readonly`,`true`)):(l.disabled=!0,l.setAttribute(`aria-disabled`,`true`)),l.setAttribute(`title`,`Connected input. Change its source in Flow.`);let u={flush:async()=>{},status:()=>({dirty:!1,saving:!1,problem:null,canEdit:!1,composing:!1,interrupted:!1}),setDefault(){},dispose(){l.disabled=t,l.readOnly=n,r===null?l.removeAttribute(`title`):l.setAttribute(`title`,r),s===null?l.removeAttribute(`aria-readonly`):l.setAttribute(`aria-readonly`,s),c===null?l.removeAttribute(`aria-disabled`):l.setAttribute(`aria-disabled`,c),a.delete(i)}};return a.set(i,u),u.dispose}if(r&&(l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type))){let e=r.bind(i,l),t=e.dispose;return e.dispose=()=>{t(),a.delete(i)},a.set(i,e),e.dispose}let d=l.disabled,m={exists:!1},h,g=!1,_=!1,v=null,y=!1,b=!1,x=null,S=null,C=null,w=!1,T=!1,E,D=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),O=e=>{S=e,l.setCustomValidity(e.message),n(e.message)},k=()=>u.find(e=>e.checked)?.value??``,A=e=>{let n=u?k():l.type===`checkbox`?l.checked:l.value;if(u)for(let t of u)t.checked=t.value===String(e??``);else l.type===`checkbox`?l.checked=!!e:l.value!==String(e??``)&&(l.value=String(e??``));(u?k():l.type===`checkbox`?l.checked:l.value)!==n&&queueMicrotask(()=>{y||t.announce?.()})},j=()=>u?k():l.type===`checkbox`?l.checked:[`number`,`range`].includes(l.type)?l.valueAsNumber:l.value,M=Object.hasOwn(f,i)&&p(u,l,f[i])?f[i]:j(),N=()=>{if(clearTimeout(v),v=null,_)return x;if(y||w||!g||!b||S)return;let e=h;g=!1,C=null,_=!0;let n=!1;return x=Promise.resolve().then(()=>t.updateShared({[i]:e},{[i]:m})).then(()=>{m={exists:!0,value:e},l.setCustomValidity(``),!S&&g&&Object.is(h,e)&&(g=!1,C=null)},e=>{n=!0,g=!0,O(e)}).finally(()=>{_=!1,x=null,!y&&!n&&g&&h!==e&&P(),!y&&!g&&L(t.getShared())}),x},P=()=>{clearTimeout(v),v=setTimeout(N,Math.max(0,Math.min(150,500-(Date.now()-(C??Date.now())))))},F=()=>{!y&&D&&b&&!d&&(w=!0,clearTimeout(v),v=null)},I=e=>{if(y||!b||d)return;if(D&&e?.isComposing){F();return}if(w)return;let t=j();if(typeof t==`number`&&!Number.isFinite(t)){O(Error(`Enter a finite number`));return}E!==void 0&&Object.is(t,E)||(E=void 0,(S||!Object.is(t,g||_?h:m.exists?m.value:M))&&((S||C===null)&&(C=Date.now()),h=t,S=null,g=!0,P()))},L=e=>{y||(b=e.canEdit,l.disabled=d||!b,!b&&w&&(T=!0),!b&&(g||w)&&O(Error(`Editing access changed. Your unsaved draft has been preserved.`)),!(w||g||_||S)&&(m=Object.hasOwn(e.state,i)?{exists:!0,value:e.state[i]}:{exists:!1},A(m.exists?m.value:M)))},ee=t.onShared(L),R=()=>{if(!y&&w){if(w=!1,!b||T){T=!1,h=j(),E=h,g=!0,O(Error(`Editing access changed. Your unsaved draft has been preserved.`));return}I(),g&&!_&&!S?(C=Date.now(),P()):!g&&!_&&!S&&L(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let z=u?`focusout`:`blur`;l.addEventListener(`input`,I),l.addEventListener(`change`,I),l.addEventListener(z,N),l.addEventListener(`compositionstart`,F),l.addEventListener(`compositionend`,R);let te=()=>{y=!0,w=!1,clearTimeout(v),ee(),l.removeEventListener(`input`,I),l.removeEventListener(`change`,I),l.removeEventListener(z,N),l.removeEventListener(`compositionstart`,F),l.removeEventListener(`compositionend`,R),l.disabled=d,a.delete(i)};return a.set(i,{dispose:te,flush:N,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){M=e,L(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),te},_=new Map,v=new Map,y=new WeakSet,b=[`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`],x=/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/,S=/(?:password|secret|credential|authorization|cookie|token|api[_-]?key|private[_-]?key)/i,C=/^(?:current-password|new-password|one-time-code|cc-)/i,w=null,T=null,E=e=>{let t=_.get(e);if(t!==void 0){_.delete(e),v.delete(t);try{a.get(t)?.dispose()}catch{}a.delete(t)}},D=(t,n)=>{let r=e.getElementById(n);r&&_.has(r)&&E(r),v.has(t)&&E(v.get(t));let i=g(t,n);return r&&y.add(r),i},O=e=>{let t=e.getAttribute(`data-stillmade-share`)||e.getAttribute(`name`)||e.id||(e.tagName===`FIELDSET`?e.querySelector(`input[type="radio"][name]`)?.getAttribute(`name`):``)||``;return x.test(t)?t:null},k=e=>!e.isConnected||e.closest(`[data-stillmade-local]`)?!1:e.tagName===`FIELDSET`?!!e.querySelector(`input[type="radio"]`)&&!e.querySelector(`fieldset`):e.tagName===`INPUT`?b.includes(e.type):e.tagName===`TEXTAREA`||e.tagName===`SELECT`,A=t=>{if(y.has(t)||_.has(t)||!k(t))return;let n=O(t);if(!(!n||a.has(n)||a.size>=100)&&!(!t.hasAttribute(`data-stillmade-share`)&&(S.test(n)||S.test(t.getAttribute(`name`)||``)||S.test(t.id||``)||C.test(t.getAttribute(`autocomplete`)||``)))){if(!t.id){let r=`sm-shared-${n}`,i=1;for(;e.getElementById(r);)r=`sm-shared-${n}-${++i}`;t.id=r}else if(e.getElementById(t.id)!==t)return;try{g(n,t.id),_.set(t,n),v.set(n,t)}catch{a.delete(n)}}},j=()=>{if(T=null,!(d||M))try{for(let e of[..._.keys()])(!e.isConnected||e.closest(`[data-stillmade-local]`))&&E(e);for(let t of e.querySelectorAll(`input,textarea,select,fieldset`))A(t)}catch(e){n(e.message)}},M=!1,N=()=>{if(!M){M=!0,w?.disconnect(),w=null,T&&=(clearTimeout(T),null);for(let e of[..._.keys()])E(e)}},P=()=>{M||d||w||typeof MutationObserver!=`function`||!e.documentElement||(j(),w=new MutationObserver(()=>{!T&&!d&&(T=setTimeout(j,30))}),w.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`name`,`id`,`type`,`data-stillmade-local`,`data-stillmade-share`]}))};e.readyState===`loading`?e.addEventListener?.(`DOMContentLoaded`,P,{once:!0}):typeof setTimeout==`function`&&typeof MutationObserver==`function`&&setTimeout(P,0);let F=()=>{let t=[...e.querySelectorAll(`[data-stillmade-share]`)];if(t.length>100)throw Error(`Use at most 100 shared controls`);for(let n of t){let t=n.getAttribute(`data-stillmade-share`),r=n.id;if(typeof t!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(t)||typeof r!=`string`||!r||r.length>200||e.getElementById(r)!==n)throw Error(`Each data-stillmade-share control needs a unique ID and valid shared field name`);D(t,r)}return t.length},I=()=>{if(d)throw Error(`Block closed before edits could be flushed`);if([...a.values()].some(e=>e.status().composing))throw Error(`Finish composing text before leaving this Block or running an action.`);let e=[...a.values()].find(e=>e.status().interrupted);if(e)throw e.status().problem};return{bindShared:D,bindAnnotated:F,bindAutomatic:P,ownSharing:N,scheduleSharedEdit:h,flushAll:async()=>{if(d)throw Error(`Block closed before edits could be flushed`);for(let e=0;e<32;e++){if(d)throw Error(`Block closed before edits could be flushed`);I();let e=[...l];for(let[t,n]of[...c])e.push(m(t,n));for(let t of a.values())e.push(t.flush());if(await Promise.all(e),d)throw Error(`Block closed before edits could be flushed`);if(u.size)throw u.values().next().value;let t=!1;for(let e of a.values()){let n=e.status();if(n.problem)throw n.problem;if(n.composing)throw Error(`Finish composing text before leaving this Block or running an action.`);if(n.dirty&&!n.canEdit)throw Error(`Editing access changed. Your draft is not saved.`);t||=n.dirty||n.saving}if(!t&&!c.size&&!l.size)return{queued:!0}}throw Error(`Edits are still arriving. Finish editing before leaving this Block.`)},assertNoComposition:I,getBindingStatus:e=>a.get(e)?.status(),setSharedDefaults(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length>100||JSON.stringify(e).length>65536)throw Error(`Use bounded shared control defaults`);for(let[t,n]of Object.entries(e))a.get(t)?.setDefault(n)},useInputDefaults(e){let t=f;if(f={},e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))[`string`,`number`,`boolean`].includes(typeof n)&&(f[t]=n);for(let[e,n]of a)Object.hasOwn(f,e)&&!(Object.hasOwn(t,e)&&t[e]===f[e])&&n.setInputDefault(f[e])},dispose(){d=!0,w?.disconnect(),T&&clearTimeout(T);for(let e of c.values())clearTimeout(e.timer);c.clear();for(let e of[...a.values()])e.dispose()}}}var Xn='var StillMadeTextFrame=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=()=>new Map,n=e=>{let n=t();return e.forEach((e,t)=>{n.set(t,e)}),n},r=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},i=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},a=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},o=()=>new Set,s=e=>e[e.length-1],c=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},l=Array.from,u=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},d=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},f=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},p=Array.isArray;var m=class{constructor(){this._observers=t()}on(e,t){return r(this._observers,e,o).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,n){return l((this._observers.get(e)||t()).values()).forEach(e=>e(...n))}destroy(){this._observers=t()}};let h=Math.floor,g=Math.abs,_=(e,t)=>e<t?e:t,v=(e,t)=>e>t?e:t;Number.isNaN;let y=e=>e===0?1/e<0:e<0,b=2**53-1,x=-(2**53-1),S=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&h(e)===e);Number.isNaN,Number.parseInt;let C=String.fromCharCode;String.fromCodePoint,C(65535);let w=e=>e.toLowerCase(),T=/^\\s*/g,E=e=>e.replace(T,``),D=/([A-Z])/g,ee=(e,t)=>E(e.replace(D,e=>`${t}${w(e)}`)),O=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},k=typeof TextEncoder<`u`?new TextEncoder:null,A=k?e=>k.encode(e):O,j=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});j&&j.decode(new Uint8Array).length===1&&(j=null);let M=(e,t)=>f(t,()=>e).join(``);var N=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};let te=()=>new N,P=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},F=e=>{let t=new Uint8Array(P(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},ne=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(v(n,t)*2),e.cpos=0)},I=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},re=I,L=(e,t)=>{for(;t>127;)I(e,128|127&t),t=h(t/128);I(e,127&t)},ie=(e,t)=>{let n=y(t);for(n&&(t=-t),I(e,(t>63?128:0)|(n?64:0)|63&t),t=h(t/64);t>0;)I(e,(t>127?128:0)|127&t),t=h(t/128)},ae=new Uint8Array(3e4),oe=ae.length/3,se=k&&k.encodeInto?(e,t)=>{if(t.length<oe){let n=k.encodeInto(t,ae).written||0;L(e,n);for(let t=0;t<n;t++)I(e,ae[t])}else R(e,A(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;L(e,r);for(let t=0;t<r;t++)I(e,n.codePointAt(t))},ce=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=_(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(v(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},R=(e,t)=>{L(e,t.byteLength),ce(e,t)},le=(e,t)=>{ne(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},ue=(e,t)=>le(e,4).setFloat32(0,t,!1),de=(e,t)=>le(e,8).setFloat64(0,t,!1),fe=(e,t)=>le(e,8).setBigInt64(0,t,!1),pe=new DataView(new ArrayBuffer(4)),me=e=>(pe.setFloat32(0,e),pe.getFloat32(0)===e),he=(e,t)=>{switch(typeof t){case`string`:I(e,119),se(e,t);break;case`number`:S(t)&&g(t)<=2147483647?(I(e,125),ie(e,t)):me(t)?(I(e,124),ue(e,t)):(I(e,123),de(e,t));break;case`bigint`:I(e,122),fe(e,t);break;case`object`:if(t===null)I(e,126);else if(p(t)){I(e,117),L(e,t.length);for(let n=0;n<t.length;n++)he(e,t[n])}else if(t instanceof Uint8Array)I(e,116),R(e,t);else{I(e,118);let n=Object.keys(t);L(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];se(e,i),he(e,t[i])}}break;case`boolean`:I(e,t?120:121);break;default:I(e,127)}};var ge=class extends N{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&L(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};let _e=e=>{e.count>0&&(ie(e.encoder,e.count===1?e.s:-e.s),e.count>1&&L(e.encoder,e.count-2))};var ve=class{constructor(){this.encoder=new N,this.s=0,this.count=0}write(e){this.s===e?this.count++:(_e(this),this.count=1,this.s=e)}toUint8Array(){return _e(this),F(this.encoder)}};let ye=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);ie(e.encoder,t),e.count>1&&L(e.encoder,e.count-2)}};var be=class{constructor(){this.encoder=new N,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(ye(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return ye(this),F(this.encoder)}},xe=class{constructor(){this.sarr=[],this.s=``,this.lensE=new ve}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new N;return this.sarr.push(this.s),this.s=``,se(e,this.sarr.join(``)),ce(e,this.lensE.toUint8Array()),F(e)}};let Se=e=>Error(e),Ce=()=>{throw Se(`Method unimplemented`)},we=()=>{throw Se(`Unexpected case`)},Te=Se(`Unexpected end of array`),Ee=Se(`Integer out of Range`);var De=class{constructor(e){this.arr=e,this.pos=0}};let Oe=e=>new De(e),ke=e=>e.pos!==e.arr.length,Ae=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},je=e=>Ae(e,z(e)),Me=e=>e.arr[e.pos++],z=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>b)throw Ee}throw Te},Ne=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>b)throw Ee}throw Te},Pe=j?e=>j.decode(je(e)):e=>{let t=z(e);if(t===0)return``;{let n=String.fromCodePoint(Me(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Me(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Fe=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Ie=[e=>void 0,e=>null,Ne,e=>Fe(e,4).getFloat32(0,!1),e=>Fe(e,8).getFloat64(0,!1),e=>Fe(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Pe,e=>{let t=z(e),n={};for(let r=0;r<t;r++){let t=Pe(e);n[t]=Le(e)}return n},e=>{let t=z(e),n=[];for(let r=0;r<t;r++)n.push(Le(e));return n},je],Le=e=>Ie[127-Me(e)](e);var Re=class extends De{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=ke(this)?z(this)+1:-1),this.count--,this.s}},ze=class extends De{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ne(this);let e=y(this.s);this.count=1,e&&(this.s=-this.s,this.count=z(this)+2)}return this.count--,this.s}},Be=class extends De{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=Ne(this),t=e&1;this.diff=h(e/2),this.count=1,t&&(this.count=z(this)+2)}return this.s+=this.diff,this.count--,this.s}},Ve=class{constructor(e){this.decoder=new ze(e),this.str=Pe(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;let He=crypto.getRandomValues.bind(crypto),Ue=()=>He(new Uint32Array(1))[0],We=()=>`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^Ue()&15>>e/4).toString(16)),Ge=Date.now,Ke=e=>new Promise(e);Promise.all.bind(Promise);let qe=e=>e===void 0?null:e,Je=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Je=localStorage)}catch{}let Ye=Je,Xe=Symbol(`Equality`),Ze=(e,t)=>e===t||!!e?.[Xe]?.(t)||!1,Qe=e=>typeof e==`object`,$e=Object.assign,et=Object.keys,tt=(e,t)=>{for(let n in e)t(e[n],n)},nt=e=>et(e).length,rt=e=>{for(let t in e)return!1;return!0},it=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},at=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ot=(e,t)=>e===t||nt(e)===nt(t)&&it(e,(e,n)=>(e!==void 0||at(t,n))&&Ze(t[n],e)),st=Object.freeze,ct=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&ct(e[t])}return st(e)},lt=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&<(e,t,n+1)}},ut=e=>e,dt=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Xe]!=null)return e[Xe](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!dt(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(nt(e)!==nt(t))return!1;for(let n in e)if(!at(e,n)||!dt(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!dt(e[n],t[n]))return!1;break;default:return!1}return!0},ft=(e,t)=>t.includes(e),pt=typeof process<`u`&&process.release&&/node|io\\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`;typeof navigator<`u`&&/Mac/.test(navigator.platform);let mt,ht=[],gt=()=>{if(mt===void 0){if(pt){mt=t();let e=process.argv,n=null;for(let t=0;t<e.length;t++){let r=e[t];r[0]===`-`?(n!==null&&mt.set(n,``),n=r):n===null?ht.push(r):(mt.set(n,r),n=null)}n!==null&&mt.set(n,``)}else typeof location==`object`?(mt=t(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);mt.set(`--${ee(t,`-`)}`,n),mt.set(`-${ee(t,`-`)}`,n)}})):mt=t()}return mt},_t=e=>gt().has(e),vt=e=>qe(pt?process.env[e.toUpperCase().replaceAll(`-`,`_`)]:Ye.getItem(e)),yt=e=>_t(`--`+e)||vt(e)!==null,bt=yt(`production`),xt=pt&&ft(process.env.FORCE_COLOR,[`true`,`1`,`2`])||!_t(`--no-colors`)&&!yt(`no-color`)&&(!pt||process.stdout.isTTY)&&(!pt||_t(`--color`)||vt(`COLORTERM`)!==null||(vt(`TERM`)||``).includes(`color`)),St=e=>new Uint8Array(e),Ct=e=>{let t=St(e.byteLength);return t.set(e),t};var wt=class{constructor(e,t){this.left=e,this.right=t}};let Tt=(e,t)=>new wt(e,t),Et=e=>e.next()>=.5,Dt=(e,t,n)=>h(e.next()*(n+1-t)+t),Ot=(e,t,n)=>h(e.next()*(n+1-t)+t),kt=(e,t,n)=>Ot(e,t,n),At=e=>C(kt(e,97,122)),jt=(e,t=0,n=20)=>{let r=kt(e,t,n),i=``;for(let t=0;t<r;t++)i+=At(e);return i},Mt=(e,t)=>t[kt(e,0,t.length-1)],Nt=Symbol(`0schema`);var Pt=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(M(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn\'t match ${n.expected}. ${n.message}`)}return e.join(`\n`)}};let Ft=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Xe]?Ze(e,t):p(e)?u(e,e=>d(t,t=>Ft(e,t))):Qe(e)?it(e,(e,n)=>Ft(e,t[n])):!1;var B=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ft(t,n)}equals(e){return this.constructor===e.constructor&&dt(this.shape,e.shape)}[Nt](){return!0}[Xe](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Ce()}get nullable(){return pn(this,On)}get optional(){return new Wt(this)}cast(e){return Mn(e,this),e}expect(e){return Mn(e,this),e}},It=class extends B{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}};let V=(e,t=null)=>new It(e,t);V(It);var Lt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}};let H=e=>new Lt(e);V(Lt);var Rt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}};let zt=(...e)=>new Rt(e),Bt=V(Rt),Vt=RegExp.escape||(e=>e.replace(/[().|&,$^[\\]]/g,e=>`\\\\`+e)),Ht=e=>{if(Cn.check(e))return[Vt(e)];if(Bt.check(e))return e.shape.map(e=>e+``);if(Sn.check(e))return[`[+-]?\\\\d+.?\\\\d*`];if(wn.check(e))return[`.*`];if(mn.check(e))return e.shape.map(Ht).flat(1);we()};V(class extends B{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ht).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn\'t match string template.`),n}});let Ut=Symbol(`optional`);var Wt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Ut](){return!0}};let Gt=V(Wt);var Kt=class extends B{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Kt,V(Kt);var qt=class e extends B{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):it(this.shape,(n,r)=>{let i=this._isPartial&&!at(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}};let Jt=e=>new qt(e),Yt=V(qt),Xt=H(e=>e!=null&&(e.constructor===Object||e.constructor==null));var Zt=class extends B{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&it(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn\'t match schema`:`Value doesn\'t match value`),i&&this.shape.values.check(n,t)})}};let Qt=(e,t)=>new Zt(e,t),$t=V(Zt);var en=class extends B{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&it(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}};let tn=(...e)=>new en(e);V(en);var nn=class extends B{constructor(e){super(),this.shape=e.length===1?e[0]:new fn(e)}check(e,t){let n=p(e)&&u(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}};let rn=(...e)=>new nn(e),an=V(nn),on=H(e=>p(e));var sn=class extends B{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}};let cn=(e,t=null)=>new sn(e,t);V(sn);let ln=cn(B),un=V(class extends B{constructor(e){super(),this.len=e.length-1,this.args=tn(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),dn=H(e=>typeof e==`function`);V(class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=u(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var fn=class extends B{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=d(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}};let pn=(...e)=>e.findIndex(e=>mn.check(e))>=0?pn(...e.map(e=>jn(e)).map(e=>mn.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new fn(e),mn=V(fn),hn=()=>!0,gn=H(hn),_n=V(Lt,e=>e.shape===hn),vn=H(e=>typeof e==`bigint`),yn=H(e=>e===vn),bn=H(e=>typeof e==`symbol`);H(e=>e===bn);let xn=H(e=>typeof e==`number`),Sn=H(e=>e===xn),Cn=H(e=>typeof e==`string`),wn=H(e=>e===Cn),Tn=H(e=>typeof e==`boolean`),En=H(e=>e===Tn),Dn=zt(void 0);V(Rt,e=>e.shape.length===1&&e.shape[0]===void 0),zt(void 0);let On=zt(null),kn=V(Rt,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array),V(It,e=>e.shape===Uint8Array);let An=pn(xn,Cn,On,Dn,vn,Tn,bn);(()=>{let e=rn(gn),t=Qt(Cn,gn),n=pn(xn,Cn,On,Tn,e,t);return e.shape=n,t.shape.values=n,n})();let jn=e=>{if(ln.check(e))return e;if(Xt.check(e)){let t={};for(let n in e)t[n]=jn(e[n]);return Jt(t)}if(on.check(e))return pn(...e.map(jn));if(An.check(e))return zt(e);if(dn.check(e))return V(e);we()},Mn=bt?()=>{}:(e,t)=>{let n=new Pt;if(!t.check(e,n))throw Se(`Expected value to be of type ${t.constructor.name}.\\n${n.toString()}`)};var Nn=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:jn(e),h:t}),this}else(e){return this.if(gn,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Se(`Unhandled pattern`)}}};let Pn=(e=>new Nn(e))(gn).if(Sn,(e,t)=>Dt(t,x,b)).if(wn,(e,t)=>jt(t)).if(En,(e,t)=>Et(t)).if(yn,(e,t)=>BigInt(Dt(t,x,b))).if(mn,(e,t)=>Fn(t,Mt(t,e.shape))).if(Yt,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Gt.check(i)){if(Et(t))continue;i=i.shape}n[r]=Pn(i,t)}return n}).if(an,(e,t)=>{let n=[],r=Ot(t,0,42);for(let i=0;i<r;i++)n.push(Fn(t,e.shape));return n}).if(Bt,(e,t)=>Mt(t,e.shape)).if(kn,(e,t)=>null).if(un,(e,t)=>{let n=Fn(t,e.res);return()=>n}).if(_n,(e,t)=>Fn(t,Mt(t,[xn,Cn,On,Dn,vn,Tn,rn(xn),Qt(pn(`a`,`b`,`c`),xn)]))).if($t,(e,t)=>{let n={},r=Dt(t,0,3);for(let i=0;i<r;i++){let r=Fn(t,e.shape.keys);n[r]=Fn(t,e.shape.values)}return n}).done(),Fn=(e,t)=>Pn(jn(t),e),In=typeof document<`u`?document:{};H(e=>e.nodeType===Vn),typeof DOMParser<`u`&&new DOMParser,H(e=>e.nodeType===Rn),H(e=>e.nodeType===zn);let Ln=e=>i(e,(e,t)=>`${t}:${e};`).join(``),Rn=In.ELEMENT_NODE,zn=In.TEXT_NODE;In.CDATA_SECTION_NODE,In.COMMENT_NODE;let Bn=In.DOCUMENT_NODE;In.DOCUMENT_TYPE_NODE;let Vn=In.DOCUMENT_FRAGMENT_NODE;H(e=>e.nodeType===Bn);let Hn=Symbol,Un=Hn(),Wn=Hn(),Gn=Hn(),Kn=Hn(),qn=Hn(),Jn=Hn(),Yn=Hn(),Xn=Hn(),Zn=Hn(),Qn=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};Ge();let $n={[Un]:Tt(`font-weight`,`bold`),[Wn]:Tt(`font-weight`,`normal`),[Gn]:Tt(`color`,`blue`),[qn]:Tt(`color`,`green`),[Kn]:Tt(`color`,`grey`),[Jn]:Tt(`color`,`red`),[Yn]:Tt(`color`,`purple`),[Xn]:Tt(`color`,`orange`),[Zn]:Tt(`color`,`black`)},er=xt?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let n=[],r=[],i=t(),a=[],o=0;for(;o<e.length;o++){let t=e[o],a=$n[t];if(a!==void 0)i.set(a.left,a.right);else{if(t===void 0)break;if(t.constructor===String||t.constructor===Number){let e=Ln(i);o>0||e.length>0?(n.push(`%c`+t),r.push(e)):n.push(t)}else break}}for(o>0&&(a=r,a.unshift(n.join(``)));o<e.length;o++){let t=e[o];t instanceof Symbol||a.push(t)}return a}:Qn,tr=(...e)=>{console.log(...er(e)),rr.forEach(t=>t.print(e))},nr=(...e)=>{console.warn(...er(e)),e.unshift(Xn),rr.forEach(t=>t.print(e))},rr=o(),ir=e=>({[Symbol.iterator](){return this},next:e}),ar=(e,t)=>ir(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),or=(e,t)=>ir(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var sr=class{constructor(e,t){this.clock=e,this.len=t}},cr=class{constructor(){this.clients=new Map}};let lr=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])bi(e,i,o.clock,o.len,n)}}),ur=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=h((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},dr=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ur(n,t.clock)!==null},fr=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new sr(r.clock,v(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},pr=e=>{let t=new cr;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)c(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return fr(t),t},mr=(e,t,n,i)=>{r(e.clients,t,()=>[]).push(new sr(n,i))},hr=()=>new cr,gr=e=>{let t=hr();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new sr(i,a))}}r.length>0&&t.clients.set(n,r)}),t},_r=(e,t)=>{L(e.restEncoder,t.clients.size),l(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),L(e.restEncoder,t);let r=n.length;L(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},vr=e=>{let t=new cr,n=z(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();let n=z(e.restDecoder),i=z(e.restDecoder);if(i>0){let a=r(t.clients,n,()=>[]);for(let t=0;t<i;t++)a.push(new sr(e.readDsClock(),e.readDsLen()))}}return t},yr=(e,t,n)=>{let r=new cr,i=z(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=z(e.restDecoder),a=z(e.restDecoder),o=n.clients.get(i)||[],s=W(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&mr(r,i,s,a-s);let e=hi(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Mo(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Mo(t,c,a-c.id.clock)),c.delete(t))}else mr(r,i,n,a-n)}}if(r.clients.size>0){let e=new kr;return L(e.restEncoder,0),_r(e,r),e.toUint8Array()}return null},br=Ue;var xr=class e extends m{constructor({guid:e=We(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=br(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new fi,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ke(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Ke(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&K(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(l(this.subdocs).map(e=>e.guid))}transact(e,t=null){return K(this,e,t)}get(e,t=J){let n=r(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),i=n.constructor;if(t!==J&&i!==t){if(i===J){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Sa)}getText(e=``){return this.get(e,Ua)}getMap(e=``){return this.get(e,Ta)}getXmlElement(e=``){return this.get(e,Ja)}getXmlFragment(e=``){return this.get(e,Ka)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,l(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,K(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Sr=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return z(this.restDecoder)}readDsLen(){return z(this.restDecoder)}},Cr=class extends Sr{readLeftID(){return U(z(this.restDecoder),z(this.restDecoder))}readRightID(){return U(z(this.restDecoder),z(this.restDecoder))}readClient(){return z(this.restDecoder)}readInfo(){return Me(this.restDecoder)}readString(){return Pe(this.restDecoder)}readParentInfo(){return z(this.restDecoder)===1}readTypeRef(){return z(this.restDecoder)}readLen(){return z(this.restDecoder)}readAny(){return Le(this.restDecoder)}readBuf(){return Ct(je(this.restDecoder))}readJSON(){return JSON.parse(Pe(this.restDecoder))}readKey(){return Pe(this.restDecoder)}},wr=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=z(this.restDecoder),this.dsCurrVal}readDsLen(){let e=z(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Tr=class extends wr{constructor(e){super(e),this.keys=[],z(e),this.keyClockDecoder=new Be(je(e)),this.clientDecoder=new ze(je(e)),this.leftClockDecoder=new Be(je(e)),this.rightClockDecoder=new Be(je(e)),this.infoDecoder=new Re(je(e),Me),this.stringDecoder=new Ve(je(e)),this.parentInfoDecoder=new Re(je(e),Me),this.typeRefDecoder=new ze(je(e)),this.lenDecoder=new ze(je(e))}readLeftID(){return new Qr(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Qr(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Le(this.restDecoder)}readBuf(){return je(this.restDecoder)}readJSON(){return Le(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Er=class{constructor(){this.restEncoder=te()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){L(this.restEncoder,e)}writeDsLen(e){L(this.restEncoder,e)}},Dr=class extends Er{writeLeftID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeRightID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeClient(e){L(this.restEncoder,e)}writeInfo(e){re(this.restEncoder,e)}writeString(e){se(this.restEncoder,e)}writeParentInfo(e){L(this.restEncoder,+!!e)}writeTypeRef(e){L(this.restEncoder,e)}writeLen(e){L(this.restEncoder,e)}writeAny(e){he(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){se(this.restEncoder,JSON.stringify(e))}writeKey(e){se(this.restEncoder,e)}},Or=class{constructor(){this.restEncoder=te(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,L(this.restEncoder,t)}writeDsLen(e){e===0&&we(),L(this.restEncoder,e-1),this.dsCurrVal+=e}},kr=class extends Or{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new be,this.clientEncoder=new ve,this.leftClockEncoder=new be,this.rightClockEncoder=new be,this.infoEncoder=new ge(re),this.stringEncoder=new xe,this.parentInfoEncoder=new ge(re),this.typeRefEncoder=new ve,this.lenEncoder=new ve}toUint8Array(){let e=te();return L(e,0),R(e,this.keyClockEncoder.toUint8Array()),R(e,this.clientEncoder.toUint8Array()),R(e,this.leftClockEncoder.toUint8Array()),R(e,this.rightClockEncoder.toUint8Array()),R(e,F(this.infoEncoder)),R(e,this.stringEncoder.toUint8Array()),R(e,F(this.parentInfoEncoder)),R(e,this.typeRefEncoder.toUint8Array()),R(e,this.lenEncoder.toUint8Array()),ce(e,F(this.restEncoder)),F(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){he(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){he(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}};let Ar=(e,t,n,r)=>{r=v(r,t[0].id.clock);let i=hi(t,r);L(e.restEncoder,t.length-i),e.writeClient(n),L(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},jr=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{W(t,n)>e&&r.set(n,e)}),pi(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),L(e.restEncoder,r.size),l(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ar(e,t.clients.get(n),n,r)})},Mr=(e,n)=>{let r=t(),i=z(e.restDecoder);for(let t=0;t<i;t++){let t=z(e.restDecoder),i=Array(t),a=e.readClient(),o=z(e.restDecoder);r.set(a,{i:0,refs:i});for(let r=0;r<t;r++){let t=e.readInfo();switch(31&t){case 0:{let t=e.readLen();i[r]=new Y(U(a,o),t),o+=t;break}case 10:{let t=z(e.restDecoder);i[r]=new Lo(U(a,o),t),o+=t;break}default:{let s=!(t&192),c=new Z(U(a,o),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,s?e.readParentInfo()?n.get(e.readString()):e.readLeftID():null,s&&(t&32)==32?e.readString():null,Fo(e,t));i[r]=c,o+=c.length}}}}return r},Nr=(e,t,n)=>{let i=[],a=l(n.keys()).sort((e,t)=>e-t);if(a.length===0)return null;let o=()=>{if(a.length===0)return null;let e=n.get(a[a.length-1]);for(;e.refs.length===e.i;)if(a.pop(),a.length>0)e=n.get(a[a.length-1]);else return null;return e},s=o();if(s===null)return null;let c=new fi,u=new Map,d=(e,t)=>{let n=u.get(e);(n==null||n>t)&&u.set(e,t)},f=s.refs[s.i++],p=new Map,m=()=>{for(let e of i){let t=e.id.client,r=n.get(t);r?(r.i--,c.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):c.clients.set(t,[e]),a=a.filter(e=>e!==t)}i.length=0};for(;;){if(f.constructor!==Lo){let a=r(p,f.id.client,()=>W(t,f.id.client))-f.id.clock;if(a<0)i.push(f),d(f.id.client,f.id.clock-1),m();else{let r=f.getMissing(e,t);if(r!==null){i.push(f);let e=n.get(r)||{refs:[],i:0};if(e.refs.length===e.i)d(r,W(t,r)),m();else{f=e.refs[e.i++];continue}}else(a===0||a<f.length)&&(f.integrate(e,a),p.set(f.id.client,f.id.clock+f.length))}}if(i.length>0)f=i.pop();else if(s!==null&&s.i<s.refs.length)f=s.refs[s.i++];else{if(s=o(),s===null)break;f=s.refs[s.i++]}}if(c.clients.size>0){let e=new kr;return jr(e,c,new Map),L(e.restEncoder,0),{missing:u,update:e.toUint8Array()}}return null},Pr=(e,t)=>jr(e,t.doc.store,t.beforeState),Fr=(e,t,n,r=new Tr(e))=>K(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Mr(r,n),o=Nr(e,i,a),s=i.pendingStructs;if(s){for(let[e,n]of s.missing)if(n<W(i,e)){t=!0;break}if(o){for(let[e,t]of o.missing){let n=s.missing.get(e);(n==null||n>t)&&s.missing.set(e,t)}s.update=zi([s.update,o.update])}}else i.pendingStructs=o;let c=yr(r,e,i);if(i.pendingDs){let t=new Tr(Oe(i.pendingDs));z(t.restDecoder);let n=yr(t,e,i);i.pendingDs=c&&n?zi([c,n]):c||n}else i.pendingDs=c;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Ir(e.doc,t)}},n,!1),Ir=(e,t,n,r=Tr)=>{let i=Oe(t);Fr(i,e,n,new r(i))},Lr=(e,t,n)=>Ir(e,t,n,Cr),Rr=(e,t,n=new Map)=>{jr(e,t.store,n),_r(e,gr(t.store))},zr=(e,t=new Uint8Array([0]),n=new kr)=>{let r=Hr(t);Rr(n,e,r);let i=[n.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(Bi(e.store.pendingStructs.update,t)),i.length>1){if(n.constructor===Dr)return Li(i.map((e,t)=>t===0?e:Gi(e)));if(n.constructor===kr)return zi(i)}return i[0]},Br=(e,t)=>zr(e,t,new Dr),Vr=e=>{let t=new Map,n=z(e.restDecoder);for(let r=0;r<n;r++){let n=z(e.restDecoder),r=z(e.restDecoder);t.set(n,r)}return t},Hr=e=>Vr(new Sr(Oe(e))),Ur=(e,t)=>(L(e.restEncoder,t.size),l(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{L(e.restEncoder,t),L(e.restEncoder,n)}),e),Wr=(e,t)=>Ur(e,pi(t.store)),Gr=(e,t=new Or)=>(e instanceof Map?Ur(t,e):Wr(t,e),t.toUint8Array()),Kr=e=>Gr(e,new Er);var qr=class{constructor(){this.l=[]}};let Jr=()=>new qr,Yr=(e,t)=>e.l.push(t),Xr=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn\'t exist.`)},Zr=(e,t,n)=>lt(e.l,[t,n]);var Qr=class{constructor(e,t){this.client=e,this.clock=t}};let $r=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,U=(e,t)=>new Qr(e,t),ei=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw we()},ti=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};var ni=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ri=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}};let ii=(e,t,n=0)=>new ri(e,t,n),ai=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ei(e):r=U(e._item.id.client,e._item.id.clock),new ni(r,i,t,n)},oi=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ai(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ai(e,U(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ai(e,r.lastId,n);r=r.right}return ai(e,null,n)},si=(e,t)=>{let n=gi(e,t);return{item:n,diff:t.clock-n.id.clock}},ci=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(W(r,i.client)<=i.clock)return null;let e=n?Ao(r,i):si(r,i),t=e.item;if(!(t instanceof Z))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(W(r,a.client)<=a.clock)return null;let{item:e}=n?Ao(r,a):{item:gi(r,a)};if(e instanceof Z&&e.content instanceof Oo)c=e.content.type;else return null}else throw we();l=s>=0?c._length:0}return ii(c,l,e.assoc)};var li=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new li(e,t))(hr(),new Map);let ui=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!dr(t.ds,e.id),di=(e,t)=>{let n=r(e.meta,di,o),i=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<W(i,n)&&G(e,U(n,t))}),lr(e,t.ds,e=>{}),n.add(t))};var fi=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}};let pi=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},W=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},mi=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw we()}n.push(t)},hi=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=h(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=h((n+r)/2)}throw we()},gi=(e,t)=>{let n=e.clients.get(t.client);return n[hi(n,t.clock)]},_i=(e,t,n)=>{let r=hi(t,n),i=t[r];return i.id.clock<n&&i instanceof Z?(t.splice(r+1,0,Mo(e,i,n-i.id.clock)),r+1):r},G=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[_i(e,n,t.clock)]},vi=(e,t,n)=>{let r=t.clients.get(n.client),i=hi(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==Y&&r.splice(i+1,0,Mo(e,a,n.clock-a.id.clock+1)),a},yi=(e,t,n)=>{let r=e.clients.get(t.id.client);r[hi(r,t.id.clock)]=n},bi=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=_i(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&_i(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)};var xi=class{constructor(e,t,n){this.doc=e,this.deleteSet=new cr,this.beforeState=pi(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}};let Si=(e,t)=>t.deleteSet.clients.size===0&&!a(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(fr(t.deleteSet),Pr(e,t),_r(e,t.deleteSet),!0),Ci=(e,t,n)=>{let i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&r(e.changed,t,o).add(n)},wi=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Z&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},Ti=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=hi(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Z&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Ei=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=_(r.length-1,1+hi(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+wi(r,e)}})},Di=(e,t,n)=>{Ti(e,t,n),Ei(e,t)},Oi=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{fr(a),n.afterState=pi(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{Zr(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Ba(n)})}),lt(e,[])}finally{r.gc&&Ti(a,i,r.gcFilter),Ei(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=v(hi(e,r),1);for(let t=e.length-1;t>=n;)t-=1+wi(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=hi(r,n);a+1<r.length&&wi(r,a+1)>1||a>0&&wi(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(tr(Xn,Un,`[yjs] `,Wn,Jn,`Changed the client-id because another client seems to be using it.`),r.clientID=br()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Dr;Si(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new kr;Si(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Oi(e,t+1)}}},K=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new xi(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Oi(i,0)}}return o};var ki=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}};let Ai=(e,t,n)=>{lr(e,n.deletions,n=>{n instanceof Z&&t.scope.some(t=>t===e.doc||ti(t,n))&&jo(n,!1)})},ji=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;K(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;lr(n,o.insertions,e=>{if(e instanceof Z){if(e.redone!==null){let{item:t,diff:i}=Ao(r,e.id);i>0&&(t=G(n,U(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||ti(t,e))&&c.push(e)}}),lr(n,o.deletions,e=>{e instanceof Z&&a.some(t=>t===n.doc||ti(t,e))&&!dr(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Po(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o};var Mi=class extends m{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=p(e)?e[0].doc:e instanceof xr?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new cr;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&mr(i,n,r,a)});let a=Ge(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=pr([t.deletions,e.deleteSet]),t.insertions=pr([t.insertions,i])}else r.push(new ki(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),lr(e,e.deleteSet,t=>{t instanceof Z&&this.scope.some(n=>n===e.doc||ti(n,t))&&jo(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=p(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof J?e.doc!==this.doc:e!==this.doc)&&nr(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Ai(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Ai(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=ji(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=ji(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Ni(e){let t=z(e.restDecoder);for(let n=0;n<t;n++){let t=z(e.restDecoder),n=e.readClient(),r=z(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=z(e.restDecoder);yield new Lo(U(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Z(U(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Fo(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new Y(U(n,r),t),r+=t}}}}var Pi=class{constructor(e,t){this.gen=Ni(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===Lo);return this.curr}};let Fi=(e,t=Tr)=>{let n=[],r=new t(Oe(e)),i=new Pi(r,!1);for(let e=i.curr;e!==null;e=i.next())n.push(e);return{structs:n,ds:vr(r)}};var Ii=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}};let Li=e=>zi(e,Cr,Dr),Ri=(e,t)=>{if(e.constructor===Y){let{client:n,clock:r}=e.id;return new Y(U(n,r+t),e.length-t)}if(e.constructor===Lo){let{client:n,clock:r}=e.id;return new Lo(U(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Z(U(r,i+t),null,U(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},zi=(e,t=Tr,n=kr)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(Oe(e))),i=r.map(e=>new Pi(e,!0)),a=null,o=new n,s=new Ii(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Lo?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Hi(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock){if(a.struct.constructor===Lo)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Hi(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new Lo(U(t,a.struct.id.clock+a.struct.length),e),offset:0}}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===Lo?a.struct.length-=t:n=Ri(n,t)),a.struct.mergeWith(n)||(Hi(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==Lo;n=e.next())Hi(s,a.struct,a.offset),a={struct:n,offset:0}}a!==null&&(Hi(s,a.struct,a.offset),a=null),Ui(s);let c=r.map(e=>vr(e)),l=pr(c);return _r(o,l),o.toUint8Array()},Bi=(e,t,n=Tr,r=kr)=>{let i=Hr(t),a=new r,o=new Ii(a),s=new n(Oe(e)),c=new Pi(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===Lo){c.next();continue}if(e.id.clock+e.length>n)for(Hi(o,e,v(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Hi(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}Ui(o);let l=vr(s);return _r(a,l),a.toUint8Array()},Vi=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:F(e.encoder.restEncoder)}),e.encoder.restEncoder=te(),e.written=0)},Hi=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Vi(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),L(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ui=e=>{Vi(e);let t=e.encoder.restEncoder;L(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];L(t,r.written),ce(t,r.restEncoder)}},Wi=(e,t,n,r)=>{let i=new n(Oe(e)),a=new Pi(i,!1),o=new r,s=new Ii(o);for(let e=a.curr;e!==null;e=a.next())Hi(s,t(e),0);Ui(s);let c=vr(i);return _r(o,c),o.toUint8Array()},Gi=e=>Wi(e,ut,Tr,Dr),Ki=`You must not compute changes after the event-handler fired.`;var qi=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=Ji(this.currentTarget,this.target)}deletes(e){return dr(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Se(Ki);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=s(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=s(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=s(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Se(Ki);let t=this.target,n=o(),r=o(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}};let Ji=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},q=()=>{nr(`Invalid access: Add Yjs type to a document before reading data.`)},Yi=0;var Xi=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Yi++}};let Zi=e=>{e.timestamp=Yi++},Qi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Yi++},$i=(e,t,n)=>{if(e.length>=80){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Qi(r,t,n),r}{let r=new Xi(t,n);return e.push(r),r}},ea=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>g(t-e.index)<g(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Zi(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&g(n.index-i)<r.parent.length/80?(Qi(n,r,i),n):$i(e._searchMarker,r,i)},ta=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=v(t,i.index+n))}},na=(e,t,n)=>{let i=e,a=t.changedParentTypes;for(;r(a,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Zr(i._eH,n,t)};var J=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Jr(),this._dEH=Jr(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Ce()}clone(){throw Ce()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Yr(this._eH,e)}observeDeep(e){Yr(this._dEH,e)}unobserve(e){Xr(this._eH,e)}unobserveDeep(e){Xr(this._dEH,e)}toJSON(){}};let ra=(e,t,n)=>{e.doc??q(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},ia=e=>{e.doc??q();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},aa=(e,t)=>{let n=0,r=e._start;for(e.doc??q();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},oa=(e,t)=>{let n=[];return aa(e,(r,i)=>{n.push(t(r,i,e))}),n},sa=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},ca=(e,t)=>{e.doc??q();let n=ea(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},la=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new go(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new no(new Uint8Array(n))),i.integrate(e,0);break;case xr:i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new so(n)),i.integrate(e,0);break;default:if(n instanceof J)i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Oo(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},ua=()=>Se(`Length exceeded!`),da=(e,t,n,r)=>{if(n>t._length)throw ua();if(n===0)return t._searchMarker&&ta(t._searchMarker,n,r.length),la(e,t,null,r);let i=n,a=ea(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&G(e,U(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&ta(t._searchMarker,i,r.length),la(e,t,o,r)},fa=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return la(e,t,r,n)},pa=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=ea(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&G(e,U(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&G(e,U(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw ua();t._searchMarker&&ta(t._searchMarker,i,-a+r)},ma=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},ha=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new go([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new go([r]);break;case Uint8Array:s=new no(r);break;case xr:s=new so(r);break;default:if(r instanceof J)s=new Oo(r);else throw Error(`Unexpected content type`)}new Z(U(o,W(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},ga=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},_a=e=>{let t={};return e.doc??q(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},va=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted},ya=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&ui(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ba=e=>(e.doc??q(),ar(e._map.entries(),e=>!e[1].deleted));var xa=class extends qi{},Sa=class e extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._length}_callObserver(e,t){super._callObserver(e,t),na(this,e,new xa(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{da(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):K(this.doc,t=>{fa(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{pa(n,this,e,t)})}get(e){return ca(this,e)}toArray(){return ia(this)}slice(e=0,t=this.length){return ra(this,e,t)}toJSON(){return this.map(e=>e instanceof J?e.toJSON():e)}map(e){return oa(this,e)}forEach(e){aa(this,e)}[Symbol.iterator](){return sa(this)}_write(e){e.writeTypeRef(xo)}};let Ca=e=>new Sa;var wa=class extends qi{constructor(e,t,n){super(e,t),this.keysChanged=n}},Ta=class e extends J{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof J?e.clone():e)}),t}_callObserver(e,t){na(this,e,new wa(this,e,t))}toJSON(){this.doc??q();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof J?r.toJSON():r}}),e}get size(){return[...ba(this)].length}keys(){return or(ba(this),e=>e[0])}values(){return or(ba(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return or(ba(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??q(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):K(this.doc,t=>{ma(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):K(this.doc,n=>{ha(n,this,e,t)}),t}get(e){return ga(this,e)}has(e){return va(this,e)}clear(){this.doc===null?this._prelimContent.clear():K(this.doc,e=>{this.forEach(function(t,n,r){ma(e,r,n)})})}_write(e){e.writeTypeRef(So)}};let Ea=e=>new Ta,Da=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&ot(e,t);var Oa=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&we(),this.right.content.constructor){case X:this.right.deleted||Ma(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}};let ka=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case X:t.right.deleted||Ma(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&G(e,U(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length)}t.left=t.right,t.right=t.right.right}return t},Aa=(e,t,n,r)=>{let i=new Map,a=r?ea(t,n):null;if(a){let t=new Oa(a.p.left,a.p,a.index,i);return ka(e,t,n-a.index)}{let r=new Oa(null,t._start,0,i);return ka(e,r,n)}},ja=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===X&&Da(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Z(U(a,W(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new X(o,r));l.integrate(e,0),n.right=l,n.forward()})},Ma=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Na=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===X&&Da(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Pa=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Da(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Z(U(a,W(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new X(s,c)),n.right.integrate(e,0),n.forward()}}return o},Fa=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Na(n,i);let s=Pa(e,t,n,i),c=r.constructor===String?new vo(r):r instanceof J?new Oo(r):new lo(r),{left:l,right:u,index:d}=n;t._searchMarker&&ta(t._searchMarker,n.index,c.getLength()),u=new Z(U(o,W(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),ja(e,t,n,s)},Ia=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Na(n,i);let s=Pa(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===X));){if(!n.right.deleted)switch(n.right.content.constructor){case X:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Da(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&G(e,U(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`\n`;n.right=new Z(U(o,W(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new vo(i)),n.right.integrate(e,0),n.forward()}ja(e,t,n,s)},La=(e,n,r,i,a)=>{let o=n,s=t();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===X){let e=o.content;s.set(e.key,e)}o=o.right}let c=0,l=!1;for(;n!==o;){if(r===n&&(l=!0),!n.deleted){let t=n.content;switch(t.constructor){case X:{let{key:r,value:o}=t,u=i.get(r)??null;(s.get(r)!==t||u===o)&&(n.delete(e),c++,!l&&(a.get(r)??null)===o&&u!==o&&(u===null?a.delete(r):a.set(r,u))),!l&&!n.deleted&&Ma(a,t);break}}}n=n.right}return c},Ra=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===X){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},za=e=>{let r=0;return K(e.doc,i=>{let a=e._start,o=e._start,s=t(),c=n(s);for(;o;){if(o.deleted===!1)switch(o.content.constructor){case X:Ma(c,o.content);break;default:r+=La(i,a,o,s,c),s=n(c),a=o}o=o.right}}),r},Ba=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&bi(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===X&&e.constructor!==Y&&t.add(e.parent)})}K(n,n=>{lr(e,e.deleteSet,e=>{if(e instanceof Y||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===X?t.add(r):Ra(n,e)});for(let e of t)za(e)})},Va=(e,t,r)=>{let i=r,a=n(t.currentAttributes),o=t.right;for(;r>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Oo:case lo:case vo:r<t.right.length&&G(e,U(t.right.id.client,t.right.id.clock+r)),r-=t.right.length,t.right.delete(e)}t.forward()}o&&La(e,o,t.right,a,t.currentAttributes);let s=(t.left||t.right).parent;return s._searchMarker&&ta(s._searchMarker,t.index,-i+r),t};var Ha=class extends qi{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];K(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},rt(o)||(e.attributes=$e({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Oo:case lo:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case vo:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case X:{let{key:t,value:s}=i.content;if(this.adds(i)){if(!this.deletes(i)){let c=n.get(t)??null;Da(c,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Da(s,r.get(t)??null)?delete o[t]:o[t]=s)}}else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Da(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Da(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Ma(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Ua=class e extends J{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??q(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Ha(this,e,t);na(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??q();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===vo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):K(this.doc,n=>{let r=new Oa(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`\n`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Fa(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Va(n,r,a.delete):Ia(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??q();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(ui(s,e)||t!==void 0&&ui(s,t))switch(s.content.constructor){case vo:{let r=i.get(`ychange`);e!==void 0&&!ui(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!ui(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Oo:case lo:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case X:ui(s,e)&&(c(),Ma(i,s.content))}s=s.right}c()};return e||t?K(a,n=>{e&&di(n,e),t&&di(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):K(r,r=>{let i=Aa(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Fa(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):K(r,r=>{let i=Aa(r,this,e,!n);Fa(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):K(n,n=>{Va(n,Aa(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):K(r,r=>{let i=Aa(r,this,e,!1);i.right!==null&&Ia(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):K(this.doc,t=>{ma(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):K(this.doc,n=>{ha(n,this,e,t)})}getAttribute(e){return ga(this,e)}getAttributes(){return _a(this)}_write(e){e.writeTypeRef(Co)}};let Wa=e=>new Ua;var Ga=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??q()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Ja||t.constructor===Ka)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Ka=class e extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ga(this,e)}querySelector(e){e=e.toUpperCase();let t=new Ga(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),l(new Ga(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){na(this,e,new Xa(this,t,e))}toString(){return oa(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),aa(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{da(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)K(this.doc,n=>{let r=e&&e instanceof J?e._item:e;la(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw Se(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{pa(n,this,e,t)})}toArray(){return ia(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ca(this,e)}slice(e=0,t=this.length){return ra(this,e,t)}forEach(e){aa(this,e)}_write(e){e.writeTypeRef(To)}};let qa=e=>new Ka;var Ja=class e extends Ka{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return tt(n,(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):K(this.doc,t=>{ma(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):K(this.doc,n=>{ha(n,this,e,t)})}getAttribute(e){return ga(this,e)}hasAttribute(e){return va(this,e)}getAttributes(e){return e?ya(this,e):_a(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return aa(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(wo),e.writeKey(this.nodeName)}};let Ya=e=>new Ja(e.readKey());var Xa=class extends qi{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},Za=class e extends Ta{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Eo),e.writeKey(this.hookName)}};let Qa=e=>new Za(e.readKey());var $a=class e extends Ua{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Do)}};let eo=e=>new $a;var to=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Ce()}mergeWith(e){return!1}write(e,t,n){throw Ce()}integrate(e,t){throw Ce()}},Y=class extends to{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),mi(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},no=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}};let ro=e=>new no(e.readBuf());var io=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mr(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}};let ao=e=>new io(e.readLen()),oo=(e,t)=>new xr({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});var so=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(oo(this.doc.guid,this.opts))}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}};let co=e=>new so(oo(e.readString(),e.readAny()));var lo=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}};let uo=e=>new lo(e.readJSON());var X=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}};let fo=e=>new X(e.readKey(),e.readJSON());var po=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}};let mo=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new po(n)},ho=vt(`node_env`)===`development`;var go=class e{constructor(e){this.arr=e,ho&&ct(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}};let _o=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new go(n)};var vo=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}};let yo=e=>new vo(e.readString()),bo=[Ca,Ea,Wa,Ya,qa,Qa,eo],xo=0,So=1,Co=2,wo=3,To=4,Eo=5,Do=6;var Oo=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}};let ko=e=>new Oo(bo[e.readTypeRef()](e)),Ao=(e,t)=>{let n=t,r=0,i;do r>0&&(n=U(n.client,n.clock+r)),i=gi(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Z);return{item:i,diff:r}},jo=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Mo=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Z(U(r,i+n),t,U(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=U(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},No=(e,t)=>d(e,e=>dr(e.deletions,t)),Po=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return G(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Po(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=G(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:G(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:G(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||dr(r,d.right.id)||No(a.undoStack,d.right.id)||No(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=G(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=W(s,c),h=U(c,m),g=new Z(h,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=h,jo(g,!0),g.integrate(e,0),g};var Z=class e extends to{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=W(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=W(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Qr&&this.id.client!==this.parent.client&&this.parent.clock>=W(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=vi(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=G(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===Y||this.right&&this.right.constructor===Y)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Qr){let e=gi(n,this.parent);this.parent=e.constructor===Y?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=vi(e,e.doc.store,U(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),$r(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if($r(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(gi(e.doc.store,n.origin)))r.has(gi(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),mi(e.doc.store,this),this.content.integrate(e,this),Ci(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Y(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:U(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&$r(e.origin,this.lastId)&&this.right===e&&$r(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mr(e.deleteSet,this.id.client,this.id.clock,this.length),Ci(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw we();this.content.gc(e),t?yi(e,this,new Y(this.id,this.length)):this.content=new io(this.length)}write(e,t){let n=t>0?U(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ei(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Qr?(e.writeParentInfo(!1),e.writeLeftID(t)):we();i!==null&&e.writeString(i)}this.content.write(e,t)}};let Fo=(e,t)=>Io[t&31](e),Io=[()=>{we()},ao,mo,ro,yo,uo,fo,ko,_o,co,()=>{we()}];var Lo=class extends to{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){we()}write(e,t){e.writeInfo(10),L(e.restEncoder,this.length-t)}getMissing(e,t){return null}};let Ro=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},zo=`__ $YJS$ __`;Ro[zo]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ro[zo]=!0;let Q=Object.freeze({stateBytes:262144,updateBytes:32768,textLength:32768,clients:128,structs:16384,historyUnits:1048576,undoEntries:100,undoUnits:32768}),Bo=new TextEncoder,Vo=(e,t)=>{throw Object.assign(Error(t),{code:e})},$=(e,t,n)=>{e||Vo(t,n)},Ho=e=>Number.isSafeInteger(e)&&e>=0,Uo=e=>{$(typeof e==`string`,`SHARED_TEXT_INPUT`,`Shared text must be a string`),$(e.length<=Q.textLength,`SHARED_TEXT_LIMIT`,`Shared text exceeds its character limit`);for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){let n=e.charCodeAt(++t);$(n>=56320&&n<=57343,`SHARED_TEXT_INPUT`,`Shared text contains an incomplete Unicode character`)}else $(n<56320||n>57343,`SHARED_TEXT_INPUT`,`Shared text contains an incomplete Unicode character`)}return e};function Wo(e){$(e instanceof Uint8Array,`SHARED_TEXT_INPUT`,`Expected shared text bytes`);let t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));return btoa(t)}function Go(e,t=Q.updateBytes){$(typeof e==`string`&&e.length>0&&e.length<=4*Math.ceil(t/3),`SHARED_TEXT_LIMIT`,`Shared text data exceeds its byte limit`),$(e.length%4==0&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e),`SHARED_TEXT_INPUT`,`Expected canonical base64 shared text data`);let n=atob(e);$(n.length<=t,`SHARED_TEXT_LIMIT`,`Shared text data exceeds its byte limit`);let r=Uint8Array.from(n,e=>e.charCodeAt(0));return $(Wo(r)===e,`SHARED_TEXT_INPUT`,`Expected canonical base64 shared text data`),r}function Ko(e){let t;class n extends Cr{constructor(e){super(e),t=e}}let r=Fi(e,n);$(t.pos===e.length,`SHARED_TEXT_STATE`,`Shared text data contains trailing bytes`),$(r.structs.length<=Q.structs&&r.ds.clients.size<=Q.clients,`SHARED_TEXT_LIMIT`,`Shared text history exceeds its limit`);let i=0,a=0,o=new Map;for(let e of r.structs)$(Ho(e.id.client)&&Ho(e.id.clock)&&Ho(e.length)&&e.length>0,`SHARED_TEXT_STATE`,`Invalid shared text history`),$(!o.has(e.id.client)||e.id.clock>=o.get(e.id.client),`SHARED_TEXT_STATE`,`Shared text history overlaps itself`),o.set(e.id.client,e.id.clock+e.length),i+=e.length,$(e.id.clock+e.length<=Q.historyUnits&&i<=Q.historyUnits,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),e instanceof Z?($(e.parentSub===null&&(e.parent===null||typeof e.parent!=`string`||e.parent===`text`),`SHARED_TEXT_STATE`,`Shared text accepts only its plaintext field`),$(e.content instanceof vo||e.content instanceof io,`SHARED_TEXT_STATE`,`Shared text cannot contain formatting, embedded values or other shared types`),e.content instanceof vo&&Uo(e.content.str)):$(e instanceof Y,`SHARED_TEXT_STATE`,`Unsupported shared text history`);for(let[e,t]of r.ds.clients){$(Ho(e),`SHARED_TEXT_STATE`,`Invalid shared text deletion`),a+=t.length,$(a<=Q.structs,`SHARED_TEXT_LIMIT`,`Shared text deletion history exceeds its limit`);for(let e of t)$(Ho(e.clock)&&Ho(e.len)&&e.len>0&&e.clock+e.len<=Q.historyUnits,`SHARED_TEXT_STATE`,`Invalid shared text deletion`)}return r}function qo(e,t){let n=new Map;for(let e of t.structs){let t=n.get(e.id.client)||[];t.push(e),n.set(e.id.client,t)}let r=(t,r)=>{let i=e=>{if(!e)return;let t=0,n=e.length;for(;t<n;){let i=t+n>>>1;e[i].id.clock<=r?t=i+1:n=i}let i=e[t-1];return i&&r<i.id.clock+i.length?i:void 0};return i(e.store.clients.get(t))||i(n.get(t))},i=(e,t)=>{let n=r(e,t);if(n instanceof Z&&n.content instanceof vo){let e=t-n.id.clock,r=n.content.str;$($o(r,e),`SHARED_TEXT_STATE`,`Shared text update splits a Unicode character`)}};for(let e of t.structs)e instanceof Z&&(e.origin&&i(e.origin.client,e.origin.clock+1),e.rightOrigin&&i(e.rightOrigin.client,e.rightOrigin.clock));for(let[e,n]of t.ds.clients)for(let t of n)i(e,t.clock),i(e,t.clock+t.len)}function Jo(e){let t=e.getText(`text`);$(e.share.size===1&&e.share.get(`text`)===t&&t._map.size===0&&e.getSubdocs().size===0,`SHARED_TEXT_STATE`,`Shared text accepts only its plaintext field`),$(e.store.pendingStructs===null&&e.store.pendingDs===null,`SHARED_TEXT_STATE`,`Shared text update is missing earlier history`),$(e.store.clients.size<=Q.clients,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`);let n=0,r=0;for(let i of e.store.clients.values())for(let e of i)n++,r+=e.length,$(n<=Q.structs&&r<=Q.historyUnits,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),e instanceof Z?$(e.parent===t&&e.parentSub===null&&(e.content instanceof vo||e.content instanceof io),`SHARED_TEXT_STATE`,`Shared text contains unsupported history`):$(e instanceof Y,`SHARED_TEXT_STATE`,`Unsupported shared text history`);for(let e of t.toDelta())$(typeof e.insert==`string`&&e.attributes===void 0,`SHARED_TEXT_STATE`,`Shared text cannot contain formatting or embedded values`);return Uo(t.toString())}function Yo(e,t,n){let r=Go(t,n);qo(e,Ko(r)),Lr(e,r),Jo(e)}function Xo(e){let t=new xr;t.getText(`text`);try{return Yo(t,e,Q.stateBytes),t}catch(e){throw t.destroy(),e}}function Zo(e){let t=Jo(e),n=Br(e);return $(n.length<=Q.stateBytes,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),{state:Wo(n),value:t}}function Qo(e){try{return e()}catch(e){if(typeof e?.code==`string`&&e.code.startsWith(`SHARED_TEXT_`))throw e;Vo(`SHARED_TEXT_STATE`,`Invalid shared text data`)}}let $o=(e,t)=>Ho(t)&&t<=e.length&&!(t>0&&t<e.length&&e.charCodeAt(t-1)>=55296&&e.charCodeAt(t-1)<=56319&&e.charCodeAt(t)>=56320&&e.charCodeAt(t)<=57343),es=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ts({protocol:e,epoch:t,state:n}){$(e===1&&typeof t==`string`&&es.test(t),`SHARED_TEXT_INPUT`,`Expected a versioned shared text epoch`);let r=Qo(()=>Xo(n)),i=r.getText(`text`),a={},o={},s=new WeakMap,c=new Mi(i,{trackedOrigins:new Set([a]),captureTimeout:0}),l=!1,u=null,d=()=>{if($(!l,`SHARED_TEXT_CLOSED`,`Shared text session is closed`),u)throw u},f=e=>{throw u=e,e},p=(e=[])=>{let t=e=>[...e.deletions.clients.values()].reduce((e,t)=>e+t.reduce((e,t)=>e+t.len,0),0),n=[...c.undoStack,...c.redoStack].reduce((e,n)=>e+t(n),0);for(;c.undoStack.length+c.redoStack.length>Q.undoEntries||n>Q.undoUnits;){let r=(c.undoStack.length?c.undoStack:c.redoStack).shift();n-=t(r),e.push(r.deletions)}if(!e.length)return;let i=pr(e);r.transact(e=>{lr(e,i,e=>{e instanceof Z&&(e.keep=!1)});for(let t of[...c.undoStack,...c.redoStack])lr(e,t.deletions,e=>{e instanceof Z&&(e.keep=!0)});Di(i,r.store,()=>!0)},o)},m=e=>{d();let t=c.redoStack.map(e=>e.deletions);try{return r.transact(e,a),p(t),i.toString()}catch(e){return f(e)}},h=e=>{d();let t=c[e](),n;try{n=Uo(i.toString())}catch(n){throw t&&c[e===`undo`?`redo`:`undo`](),n}try{return p(),n}catch(e){return f(e)}};return Object.freeze({getValue(){return $(!l,`SHARED_TEXT_CLOSED`,`Shared text session is closed`),i.toString()},splice(e,t,n=``){d();let r=i.toString();return Uo(n),$(Ho(t)&&$o(r,e)&&$o(r,e+t),`SHARED_TEXT_INPUT`,`Choose complete characters within the shared text`),$(r.length-t+n.length<=Q.textLength&&Bo.encode(n).length+1024<=Q.updateBytes,`SHARED_TEXT_LIMIT`,`Shared text edit exceeds its limit`),!t&&!n?r:m(()=>{t&&i.delete(e,t),n&&i.insert(e,n)})},captureSelection(e,t=e,n=`none`){d();let r=i.toString();$($o(r,e)&&$o(r,t)&&e<=t&&[`none`,`forward`,`backward`].includes(n),`SHARED_TEXT_INPUT`,`Invalid shared text selection`);let a=Object.freeze({});return s.set(a,{start:oi(i,e),end:oi(i,t),direction:n}),a},resolveSelection(e){d(),$(e&&s.has(e),`SHARED_TEXT_INPUT`,`Selection belongs to another shared text session`);let t=s.get(e),n=ci(t.start,r),a=ci(t.end,r);return $(n?.type===i&&a?.type===i,`SHARED_TEXT_STATE`,`Shared text selection is unavailable`),{start:Math.min(n.index,a.index),end:Math.max(n.index,a.index),direction:t.direction}},receive(n){return d(),$(n?.protocol===e&&n.epoch===t,`SHARED_TEXT_STATE`,`Shared text epoch changed; retain the local draft and reopen explicitly`),Qo(()=>{let e=Xo(Wo(Br(r)));try{Yo(e,n.state,Q.stateBytes),Zo(e)}finally{e.destroy()}return Lr(r,Go(n.state,Q.stateBytes),o),i.toString()})},getUpdateSince(n){return d(),$(n?.protocol===e&&n.epoch===t,`SHARED_TEXT_STATE`,`Shared text epoch changed; retain the local draft and reopen explicitly`),Qo(()=>{let i=Xo(n.state);try{Zo(r);let n=Br(r,Kr(i));return $(n.length<=Q.updateBytes,`SHARED_TEXT_LIMIT`,`Shared text batch exceeds its limit`),{protocol:e,epoch:t,update:Wo(n)}}finally{i.destroy()}})},undo(){return h(`undo`)},redo(){return h(`redo`)},canUndo(){return!l&&c.undoStack.length>0},canRedo(){return!l&&c.redoStack.length>0},checkpoint(){return d(),Qo(()=>({protocol:e,epoch:t,...Zo(r)}))},dispose(){l||(l=!0,c.destroy(),r.destroy())}})}function ns(e,t,n,r=null,i=[]){let a=new Map,o=[`text`,`search`,`email`,`tel`,`url`],s=new Set(i),c=new Map,l=new Set,u=new Map,d=!1,f={},p=(e,t,n)=>e?e.some(e=>e.value===String(n)):t.tagName!==`SELECT`||[...t.options].some(e=>e.value===String(n)),m=(e,t)=>{if(clearTimeout(t.timer),c.delete(e),d)return;let r;return r=Promise.resolve().then(()=>{if(!d)return t.callback()}).catch(t=>{u.set(e,t),n(t.message)}).finally(()=>l.delete(r)),l.add(r),r},h=(e,t)=>{if(d)throw Error(`This interface has closed; shared edits stopped.`);if(typeof e!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e))throw Error(`A shared edit key starts with a letter and holds only letters, digits, - and _ (up to 100 characters).`);if(typeof t!=`function`)throw Error(`Give scheduleSharedEdit a function to run.`);if(!c.has(e)&&c.size+l.size>=32||!u.has(e)&&u.size>=32)throw Error(`Too many scheduled shared edits`);u.delete(e);let n=c.get(e),r={callback:t,started:n?.started??Date.now(),timer:null};n&&clearTimeout(n.timer),r.timer=setTimeout(()=>m(e,r),Math.max(0,Math.min(150,500-(Date.now()-r.started)))),c.set(e,r)},g=(i,c)=>{if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(i)||a.has(i))throw Error(`Use one control per named shared field`);let l=e.getElementById(c),u=l?.tagName===`FIELDSET`?[...l.querySelectorAll(`input[type="radio"]`)]:null;if(!l||![`INPUT`,`TEXTAREA`,`SELECT`,`FIELDSET`].includes(l.tagName)||u&&!u.length||l.tagName===`INPUT`&&![`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`].includes(l.type))throw Error(`Bind an existing text, number, checkbox or select control, or a fieldset of radio buttons`);if(s.has(i)){let e=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),t=l.disabled,n=l.readOnly,r=l.getAttribute(`title`),s=l.getAttribute(`aria-readonly`),c=l.getAttribute(`aria-disabled`);e?(l.readOnly=!0,l.setAttribute(`aria-readonly`,`true`)):(l.disabled=!0,l.setAttribute(`aria-disabled`,`true`)),l.setAttribute(`title`,`Connected input. Change its source in Flow.`);let u={flush:async()=>{},status:()=>({dirty:!1,saving:!1,problem:null,canEdit:!1,composing:!1,interrupted:!1}),setDefault(){},dispose(){l.disabled=t,l.readOnly=n,r===null?l.removeAttribute(`title`):l.setAttribute(`title`,r),s===null?l.removeAttribute(`aria-readonly`):l.setAttribute(`aria-readonly`,s),c===null?l.removeAttribute(`aria-disabled`):l.setAttribute(`aria-disabled`,c),a.delete(i)}};return a.set(i,u),u.dispose}if(r&&(l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type))){let e=r.bind(i,l),t=e.dispose;return e.dispose=()=>{t(),a.delete(i)},a.set(i,e),e.dispose}let d=l.disabled,m={exists:!1},h,g=!1,_=!1,v=null,y=!1,b=!1,x=null,S=null,C=null,w=!1,T=!1,E,D=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),ee=e=>{S=e,l.setCustomValidity(e.message),n(e.message)},O=()=>u.find(e=>e.checked)?.value??``,k=e=>{let n=u?O():l.type===`checkbox`?l.checked:l.value;if(u)for(let t of u)t.checked=t.value===String(e??``);else l.type===`checkbox`?l.checked=!!e:l.value!==String(e??``)&&(l.value=String(e??``));(u?O():l.type===`checkbox`?l.checked:l.value)!==n&&queueMicrotask(()=>{y||t.announce?.()})},A=()=>u?O():l.type===`checkbox`?l.checked:[`number`,`range`].includes(l.type)?l.valueAsNumber:l.value,j=Object.hasOwn(f,i)&&p(u,l,f[i])?f[i]:A(),M=()=>{if(clearTimeout(v),v=null,_)return x;if(y||w||!g||!b||S)return;let e=h;g=!1,C=null,_=!0;let n=!1;return x=Promise.resolve().then(()=>t.updateShared({[i]:e},{[i]:m})).then(()=>{m={exists:!0,value:e},l.setCustomValidity(``),!S&&g&&Object.is(h,e)&&(g=!1,C=null)},e=>{n=!0,g=!0,ee(e)}).finally(()=>{_=!1,x=null,!y&&!n&&g&&h!==e&&N(),!y&&!g&&F(t.getShared())}),x},N=()=>{clearTimeout(v),v=setTimeout(M,Math.max(0,Math.min(150,500-(Date.now()-(C??Date.now())))))},te=()=>{!y&&D&&b&&!d&&(w=!0,clearTimeout(v),v=null)},P=e=>{if(y||!b||d)return;if(D&&e?.isComposing){te();return}if(w)return;let t=A();if(typeof t==`number`&&!Number.isFinite(t)){ee(Error(`Enter a finite number`));return}E!==void 0&&Object.is(t,E)||(E=void 0,(S||!Object.is(t,g||_?h:m.exists?m.value:j))&&((S||C===null)&&(C=Date.now()),h=t,S=null,g=!0,N()))},F=e=>{y||(b=e.canEdit,l.disabled=d||!b,!b&&w&&(T=!0),!b&&(g||w)&&ee(Error(`Editing access changed. Your unsaved draft has been preserved.`)),!(w||g||_||S)&&(m=Object.hasOwn(e.state,i)?{exists:!0,value:e.state[i]}:{exists:!1},k(m.exists?m.value:j)))},ne=t.onShared(F),I=()=>{if(!y&&w){if(w=!1,!b||T){T=!1,h=A(),E=h,g=!0,ee(Error(`Editing access changed. Your unsaved draft has been preserved.`));return}P(),g&&!_&&!S?(C=Date.now(),N()):!g&&!_&&!S&&F(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let re=u?`focusout`:`blur`;l.addEventListener(`input`,P),l.addEventListener(`change`,P),l.addEventListener(re,M),l.addEventListener(`compositionstart`,te),l.addEventListener(`compositionend`,I);let L=()=>{y=!0,w=!1,clearTimeout(v),ne(),l.removeEventListener(`input`,P),l.removeEventListener(`change`,P),l.removeEventListener(re,M),l.removeEventListener(`compositionstart`,te),l.removeEventListener(`compositionend`,I),l.disabled=d,a.delete(i)};return a.set(i,{dispose:L,flush:M,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){j=e,F(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),L},_=new Map,v=new Map,y=new WeakSet,b=[`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`],x=/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/,S=/(?:password|secret|credential|authorization|cookie|token|api[_-]?key|private[_-]?key)/i,C=/^(?:current-password|new-password|one-time-code|cc-)/i,w=null,T=null,E=e=>{let t=_.get(e);if(t!==void 0){_.delete(e),v.delete(t);try{a.get(t)?.dispose()}catch{}a.delete(t)}},D=(t,n)=>{let r=e.getElementById(n);r&&_.has(r)&&E(r),v.has(t)&&E(v.get(t));let i=g(t,n);return r&&y.add(r),i},ee=e=>{let t=e.getAttribute(`data-stillmade-share`)||e.getAttribute(`name`)||e.id||(e.tagName===`FIELDSET`?e.querySelector(`input[type="radio"][name]`)?.getAttribute(`name`):``)||``;return x.test(t)?t:null},O=e=>!e.isConnected||e.closest(`[data-stillmade-local]`)?!1:e.tagName===`FIELDSET`?!!e.querySelector(`input[type="radio"]`)&&!e.querySelector(`fieldset`):e.tagName===`INPUT`?b.includes(e.type):e.tagName===`TEXTAREA`||e.tagName===`SELECT`,k=t=>{if(y.has(t)||_.has(t)||!O(t))return;let n=ee(t);if(!(!n||a.has(n)||a.size>=100)&&!(!t.hasAttribute(`data-stillmade-share`)&&(S.test(n)||S.test(t.getAttribute(`name`)||``)||S.test(t.id||``)||C.test(t.getAttribute(`autocomplete`)||``)))){if(!t.id){let r=`sm-shared-${n}`,i=1;for(;e.getElementById(r);)r=`sm-shared-${n}-${++i}`;t.id=r}else if(e.getElementById(t.id)!==t)return;try{g(n,t.id),_.set(t,n),v.set(n,t)}catch{a.delete(n)}}},A=()=>{if(T=null,!(d||j))try{for(let e of[..._.keys()])(!e.isConnected||e.closest(`[data-stillmade-local]`))&&E(e);for(let t of e.querySelectorAll(`input,textarea,select,fieldset`))k(t)}catch(e){n(e.message)}},j=!1,M=()=>{if(!j){j=!0,w?.disconnect(),w=null,T&&=(clearTimeout(T),null);for(let e of[..._.keys()])E(e)}},N=()=>{j||d||w||typeof MutationObserver!=`function`||!e.documentElement||(A(),w=new MutationObserver(()=>{!T&&!d&&(T=setTimeout(A,30))}),w.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`name`,`id`,`type`,`data-stillmade-local`,`data-stillmade-share`]}))};e.readyState===`loading`?e.addEventListener?.(`DOMContentLoaded`,N,{once:!0}):typeof setTimeout==`function`&&typeof MutationObserver==`function`&&setTimeout(N,0);let te=()=>{let t=[...e.querySelectorAll(`[data-stillmade-share]`)];if(t.length>100)throw Error(`Use at most 100 shared controls`);for(let n of t){let t=n.getAttribute(`data-stillmade-share`),r=n.id;if(typeof t!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(t)||typeof r!=`string`||!r||r.length>200||e.getElementById(r)!==n)throw Error(`Each data-stillmade-share control needs a unique ID and valid shared field name`);D(t,r)}return t.length},P=()=>{if(d)throw Error(`Block closed before edits could be flushed`);if([...a.values()].some(e=>e.status().composing))throw Error(`Finish composing text before leaving this Block or running an action.`);let e=[...a.values()].find(e=>e.status().interrupted);if(e)throw e.status().problem};return{bindShared:D,bindAnnotated:te,bindAutomatic:N,ownSharing:M,scheduleSharedEdit:h,flushAll:async()=>{if(d)throw Error(`Block closed before edits could be flushed`);for(let e=0;e<32;e++){if(d)throw Error(`Block closed before edits could be flushed`);P();let e=[...l];for(let[t,n]of[...c])e.push(m(t,n));for(let t of a.values())e.push(t.flush());if(await Promise.all(e),d)throw Error(`Block closed before edits could be flushed`);if(u.size)throw u.values().next().value;let t=!1;for(let e of a.values()){let n=e.status();if(n.problem)throw n.problem;if(n.composing)throw Error(`Finish composing text before leaving this Block or running an action.`);if(n.dirty&&!n.canEdit)throw Error(`Editing access changed. Your draft is not saved.`);t||=n.dirty||n.saving}if(!t&&!c.size&&!l.size)return{queued:!0}}throw Error(`Edits are still arriving. Finish editing before leaving this Block.`)},assertNoComposition:P,getBindingStatus:e=>a.get(e)?.status(),setSharedDefaults(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length>100||JSON.stringify(e).length>65536)throw Error(`Use bounded shared control defaults`);for(let[t,n]of Object.entries(e))a.get(t)?.setDefault(n)},useInputDefaults(e){let t=f;if(f={},e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))[`string`,`number`,`boolean`].includes(typeof n)&&(f[t]=n);for(let[e,n]of a)Object.hasOwn(f,e)&&!(Object.hasOwn(t,e)&&t[e]===f[e])&&n.setInputDefault(f[e])},dispose(){d=!0,w?.disconnect(),T&&clearTimeout(T);for(let e of c.values())clearTimeout(e.timer);c.clear();for(let e of[...a.values()])e.dispose()}}}function rs(e,t,n,r,i,a=null){let o=new Map,s=new Map,c=[],l=0,u=!1,d=``,f=()=>{if(u)return;let e=[...o.values()].map(e=>e.status()),t={count:e.length,dirty:e.filter(e=>e.dirty||e.composing||e.interrupted).length,pending:e.filter(e=>e.saving).length,readonly:e.filter(e=>!e.canEdit).length,error:e.find(e=>e.problem)?.problem.message?.slice(0,1e3)||null,retryable:e.some(e=>e.retryable)},n=JSON.stringify(t);n!==d&&(d=n,parent.postMessage({channel:r,session:i,op:`text-recovery-status`,status:t},`*`),a&&a.send({channel:r,session:i,op:`named-text-controls`,token:a.token,snapshot:[...o.values()].map(e=>e.nativeState?.()).filter(Boolean).slice(0,50)},`*`))},p=e=>Object.assign(Error(e?.message||String(e)),e?.code?{code:e.code}:{}),m=()=>{for(;!u&&s.size<4&&c.length;){let e=c.findIndex(e=>e.action!==`read`),t=c.splice(e<0?0:e,1)[0],n=String(++l);t.id=n,s.set(n,t),(a?.send||parent.postMessage.bind(parent))({channel:r,session:i,op:`text-request`,id:n,action:t.action,key:t.key,body:t.body,...t.nativeProof&&a?{nativeText:{token:a.token,callId:t.nativeProof.callId}}:{}},`*`)}},h=(e,t,n={},r=null)=>new Promise((i,a)=>{if(u||s.size+c.length>=128){a(Error(`Shared text is unavailable or busy. Your draft is retained.`));return}let o={action:e,key:t,body:n,nativeProof:r,resolve:i,reject:a,timer:null,id:null};o.timer=setTimeout(()=>{if(o.id)s.delete(o.id);else{let e=c.indexOf(o);e>=0&&c.splice(e,1)}a(Error(`Shared text acknowledgement timed out. Your draft is retained.`)),m()},3e4),c.push(o),m()}),g=e=>{let t=e.data;if(!(e.source!==parent||t?.channel!==r||t.session!==i||u)){if(t.op===`text-result`){let e=s.get(t.id);if(!e)return;s.delete(t.id),clearTimeout(e.timer),t.error?e.reject(p(t.error)):e.resolve(t.result),m()}else if(t.op===`text-refresh`)for(let e of o.values())e.refresh();else if(t.op===`text-retry`)for(let e of o.values())e.retry().catch(()=>{})}};addEventListener(`message`,g);let _=(r,i)=>{if(o.has(r)||o.size>=100)throw Error(`Use at most 100 distinct shared text controls.`);let s=new WeakMap,c=null,l=i.disabled,u=i.readOnly,d=i.value,m=`loading`,g=!1,_=null,v=null,y=null,b=null,x=!1,S=0,C=null,w=null,T=null,E=!1,D=!1,ee=!1,O=!1,k=null,A=null,j=null,M=t.getShared().canEdit===!0,N=i.value,te=()=>!!b&&!O&&!D&&M&&!/^(READ_ONLY|SHARED_TEXT_(SOURCE|EPOCH|CONFLICT|INPUT|LIMIT|STATE|UPDATE|PROTOCOL))$/.test(b.code||``),P=e=>{E||(b=p(e),D&&(O=!0),i.readOnly=!0,(x||O)&&(i.disabled=l),i.setCustomValidity(b.message),n(b.message),f())},F=()=>({start:i.selectionStart??0,end:i.selectionEnd??0,direction:i.selectionDirection||`none`}),ne=e=>{i.value!==e&&(i.value=e,queueMicrotask(()=>{E||t.announce?.()}))},I=t=>{if(N=v.getValue(),ne(N),t&&e.activeElement===i){let e=v.resolveSelection(t);i.setSelectionRange(e.start,e.end,e.direction)}},re=()=>{let e=F();return v.captureSelection(e.start,e.end,e.direction)},L=e=>{if(!E&&e){if(b||O){(!A||e.textRevision>=A.textRevision)&&(A=e);return}if(D){(!A||e.textRevision>=A.textRevision)&&(A=e);return}if(v&&i.value!==N)throw O=!0,x=!0,Error(`This control has an uncommitted draft. Copy it before reopening the Block.`);if(y&&e.epoch!==y.epoch)throw Object.assign(Error(`This shared text was reset. Copy your draft before reloading the Block.`),{code:`SHARED_TEXT_EPOCH`});if(!(y&&e.textRevision<y.textRevision)){if(y&&e.protocol===y.protocol&&e.sourceIdentity===y.sourceIdentity&&e.textRevision===y.textRevision&&e.state===y.state&&e.value===y.value){y=e;return}if(!v)v=ts(e),y=e,I();else{let t=re();v.receive(e),y=e,I(t)}m=`text`,i.disabled=l||!M,i.readOnly=u,i.setCustomValidity(``),f()}}},ie=()=>{m=`legacy`,i.disabled=l,i.readOnly=u,i.value=d,_=ns(e,t,n),_.bindShared(r,i.id),_.setSharedDefaults({[r]:d}),queueMicrotask(()=>{E||t.announce?.()})},ae=async(e=!1)=>E||!g||m===`legacy`||k||b?k:(k=(async()=>{let t=await h(`read`,r);if(E)return;if(t.unsupported){if(e)ie();else throw Error(`Shared text is no longer available. Your draft is retained.`);return}if(t.enabled){L(t.snapshot);return}if(!M){m=`waiting`,N=t.value,ne(t.value),i.disabled=!0;return}j={action:`initialize`,body:{protocol:1,requestId:crypto.randomUUID(),sourceIdentity:t.sourceIdentity}};let n=await h(j.action,r,j.body);j=null,E||L(n.snapshot)})().catch(P).finally(()=>{k=null,f()}),f(),k),oe=()=>{E||b||D||(T===null&&(T=Date.now()),clearTimeout(w),w=setTimeout(()=>{w=null,se().catch(()=>{})},Math.max(0,Math.min(200,600-(Date.now()-T)))))},se=async()=>{if(clearTimeout(w),w=null,_)return _.flushAll();if(k&&await k,b)throw b;if(E)throw Error(`Block closed before text was saved.`);if(!g||m===`loading`)throw Error(`Shared text is still loading. Wait before leaving this Block or running an action.`);if(D)throw Error(`Finish composing text before leaving this Block or running an action.`);if(v&&i.value!==N)throw O=!0,x=!0,P(Error(`This control has an uncommitted draft. Copy it before reopening the Block.`)),b;if(C){await C;return}if(!x)return;if(!M)throw Error(`Editing access changed. Your draft is retained.`);try{j={action:`update`,version:S,nativeProof:c?.version===S?{callId:c.callId}:null,body:{...v.getUpdateSince(y),requestId:crypto.randomUUID()}}}catch(e){throw P(e),e}x=!1,T=null;let e=j;C=h(e.action,r,e.body,e.nativeProof).then(t=>{E||(L(t.snapshot),!b&&!O&&(x=S!==e.version)),j=null}).catch(e=>{throw x=!0,P(e),e}).finally(()=>{C=null,x&&!b&&oe(),f()}),f(),await C},ce=e=>{if(m!==`text`||E||l||u||!M||O)return;if(e?.isComposing){R();return}if(D)return;if(b){i.value!==N&&(O=!0,x=!0,f());return}let t=i.value;if(t!==N)try{let n=0,r=N.length,i=t.length;for(;n<r&&n<i&&N[n]===t[n];)n++;for(n>0&&n<r&&/[\\uDC00-\\uDFFF]/.test(N[n])&&n--;r>n&&i>n&&N[r-1]===t[i-1];)r--,i--;r<N.length&&/[\\uDC00-\\uDFFF]/.test(N[r])&&(r++,i++),v.splice(n,r-n,t.slice(n,i)),N=v.getValue(),S++,c=s.has(e)?{version:S,callId:s.get(e)}:null,x=!0,oe(),f()}catch(e){O=!0,x=!0,P(e)}},R=()=>{m!==`text`||E||!M||l||u||b||(D=!0,clearTimeout(w),w=null,f())},le=()=>{if(D){if(D=!1,b||!M||ee){O=!0,x=!0,b||P(Error(`Editing access changed. Your composed draft is retained.`));return}if(ce(),A){let e=A;A=null;try{L(e)}catch(e){P(e)}}x&&oe(),f()}},ue=e=>{if(!(m!==`text`||D||b||!M||l||u||!(e.metaKey||e.ctrlKey)||e.altKey||![`z`,`y`].includes(e.key.toLowerCase()))){e.preventDefault();try{e.key.toLowerCase()===`y`||e.shiftKey?v.redo():v.undo(),I(),S++,x=!0,oe(),f()}catch(e){P(e)}}},de=()=>{m===`text`&&se().catch(()=>{})},fe=t.onShared(e=>{g=!0,M=e.canEdit===!0,m!==`legacy`&&(i.disabled=l||m!==`text`||!M,!M&&(x||D)&&(ee||=D,O=!0,P(Error(`Editing access changed. Your unsaved draft is retained.`))),o.has(r)&&m===`loading`&&ae(!0),f())});i.disabled=!0,i.addEventListener(`input`,ce),i.addEventListener(`change`,ce),i.addEventListener(`blur`,de),i.addEventListener(`keydown`,ue),i.addEventListener(`compositionstart`,R),i.addEventListener(`compositionend`,le);let pe=()=>{let e=String(i.value),t=i.hidden||i.closest(`[hidden]`)!==null;return{field:r,nodeId:i.id,type:i.tagName.toLowerCase()===`textarea`?`textarea`:i.type,value:e.slice(0,1e4),partial:e.length>1e4,disabled:i.disabled||l||u||t,ready:m===`text`&&!E&&!b&&!O&&!D&&!C&&!k&&!x&&!j&&M,identity:JSON.stringify([r,i.id,i.type,y?.protocol??null,y?.epoch??null,y?.sourceIdentity??null,y?.textRevision??null])}},me={nativeState:pe,async nativeEdit(e,t){let n=pe();if(!a||typeof t!=`string`||!/^\\d{1,9}$/.test(t)||!e||Object.keys(e).sort().join(`,`)!==`field,identity,previous,value`||e.field!==r||e.identity!==n.identity||n.partial||!n.ready||n.disabled||typeof e.previous!=`string`||e.previous!==n.value||typeof e.value!=`string`||e.value.length>1e4||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(r)||/password|credential|authorization|cookie|secret|token|api.?key/i.test(r)||!i.id||![`text`,`textarea`].includes(n.type))throw Error(`The original named text control changed or is unavailable.`);let o=new Event(`input`,{bubbles:!0});if(s.set(o,t),i.value=e.value,i.dispatchEvent(o),s.delete(o),i.value!==e.value||!x||D||O||b)throw Error(`The original text handler changed or refused this edit.`);let c=S;if(await se(),S!==c||i.value!==e.value||x||j||C||b)throw Error(`Original text changed while its acknowledgement was pending. Do not repeat the edit.`);return{value:i.value,identity:pe().identity}},flush:se,getValue:()=>i.value,status:()=>_?_.getBindingStatus(r):{dirty:x||!!j,saving:!!C||!!k,problem:b,canEdit:M,composing:D,interrupted:O,retryable:te()},setDefault(e){d=String(e??``),_&&_.setSharedDefaults({[r]:e})},refresh(){!b&&!E&&ae()},async retry(){if(!(E||C||k||!te())){if(b=null,i.setCustomValidity(``),j){let e=j;C=h(e.action,r,e.body,e.nativeProof).then(t=>{L(t.snapshot),e.action===`update`&&!b&&!O&&(x=S!==e.version),j=null}).catch(e=>{throw P(e),e}).finally(()=>{C=null,f()}),f(),await C}else await ae(m===`loading`);if(b)throw b;if(i.readOnly=u,A){let e=A;A=null;try{L(e)}catch(e){throw P(e),e}}x&&await se(),f()}},dispose(){E=!0,clearTimeout(w),fe(),_?.dispose(),v?.dispose(),o.delete(r),i.removeEventListener(`input`,ce),i.removeEventListener(`change`,ce),i.removeEventListener(`blur`,de),i.removeEventListener(`keydown`,ue),i.removeEventListener(`compositionstart`,R),i.removeEventListener(`compositionend`,le),i.disabled=l,i.readOnly=u,f()}};return o.set(r,me),g&&ae(!0),me},v=setInterval(()=>{for(let e of o.values())e.refresh()},15e3);return{bind:_,inspectNative(){return[...o.values()].map(e=>e.nativeState()).filter(e=>e.nodeId&&[`text`,`textarea`].includes(e.type)&&!/password|credential|authorization|cookie|secret|token|api.?key/i.test(e.field)).slice(0,50)},async dispatchNative(e,t){if(!e||typeof e.field!=`string`||!o.has(e.field))throw Error(`Inspect an existing original named text field.`);return o.get(e.field).nativeEdit(e,t)},getValues:()=>Object.fromEntries([...o].map(([e,t])=>[e,t.getValue()])),dispose(){u=!0,clearInterval(v),removeEventListener(`message`,g);for(let e of[...o.values()])e.dispose();for(let e of[...s.values(),...c])clearTimeout(e.timer),e.reject(Error(`Block closed before text was acknowledged.`));s.clear(),c.length=0}}}return e.installTextFrame=rs,e})({});',Zn=`(sharedAPI,onStatus)=>{const documentTools=(()=>{const BlockError=(class extends Error {
|
|
9
|
+
`)}var $e,et,tt,nt,rt,it,at,ot,st,ct,lt=o((()=>{$e=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),et=new Set([`__proto__`,`prototype`,`constructor`]),tt=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,nt=Object.freeze({fileName:255,documentText:1e6,documentTitle:300,tableColumns:500,tableRows:1e5,tableCells:5e5,columnName:160,cellText:1e5,url:8192}),rt=Object.freeze({pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`}),it=Object.freeze([...new Set(Object.values(rt))]),at=Object.freeze([`markdown`,`plain`]),ot=e=>e===null||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)||typeof e==`string`&&e.length<=nt.cellText,st=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/,ct=e=>{let t=e==null?``:String(e);return/[",\r\n]/.test(t)?`"${t.replaceAll(`"`,`""`)}"`:t}})),ut=o((()=>{Object.freeze({origins:8,requestBytes:4194304,responseBytes:8388608,timeoutMs:3e4,redirects:3,headers:32,headerBytes:16384,urlLength:8192,requestsPerMinute:120,originRequestsPerMinute:3e3,keyLength:4096}),Object.freeze([`GET`,`HEAD`,`POST`,`PUT`,`PATCH`,`DELETE`]),Object.freeze([`bearer`,`header`,`query`,`oauth2`]),Object.freeze({sockets:4,messageBytes:1048576,runBytes:268435456,protocols:8})})),dt=o((()=>{Object.freeze([`media.saved`,`schedule`,`webhook`,`project.completed`,`provider`]),Object.freeze({triggers:4,labelLength:120,minEverySeconds:60,maxEverySeconds:31536e3}),Object.freeze([`recipe`,`javascript`,`capability`])})),ft=o((()=>{Object.freeze({features:24,id:48,label:40,does:160,asks:8,ask:80})}));function pt(e,t=0,n={nodes:0}){if(V(t<=40&&++n.nodes<=5e5,`LIMIT`,`Document exceeds complexity limit`),!(e===null||[`string`,`boolean`].includes(typeof e))){if(typeof e==`number`){V(Number.isFinite(e),`SCHEMA`,`Numbers must be finite`);return}V(Array.isArray(e)||_t(e),`SCHEMA`,`Only JSON data is accepted`);for(let[r,i]of Object.entries(e))V(!Ct.has(r),`SCHEMA`,`Forbidden field: ${r}`),pt(i,t+1,n)}}function mt(e){pt(e);let t=e=>Array.isArray(e)?e.map(t):_t(e)?Object.fromEntries(Object.keys(e).sort().map(n=>[n,t(e[n])])):e;return JSON.stringify(t(e))}async function ht(e){let t=new TextEncoder().encode(mt(e)),n=await globalThis.crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n),e=>e.toString(16).padStart(2,`0`)).join(``)}function gt(e,t){if(typeof t==`object`&&t&&t.schema!=null&&!oe(e,t.schema))return!1;let n=typeof t==`string`?t:t.type;if(n===`object`)try{return pt(e),_t(e)}catch{return!1}if(n?.endsWith(`[]`))return Array.isArray(e)&&e.every(e=>gt(e,n.slice(0,-2)));if(n===`text`)return typeof e==`string`&&e.length<=1e6;if(n===`boolean`)return typeof e==`boolean`;if(n===`url`)return Ye(e);if(n===`date`)return Xe(e);if(n===`color`)return Ze(e);if(n===`file`)return Ke(e);if(n===`document`)return qe(e);if(n===`table`)try{return pt(e),Je(e)}catch{return!1}if(n===`number`||n===`integer`)return typeof e==`number`&&Number.isFinite(e)&&(n!==`integer`||Number.isInteger(e))&&(t.min==null||e>=t.min)&&(t.max==null||e<=t.max);if(n===`file-bundle`)try{return pt(e),M(e)}catch{return!1}if(n===`workspace-edit`)try{return pt(e),Ce(e)}catch{return!1}if(n===`timeline-edit`)try{return pt(e),Ae(e)}catch{return!1}if(n===`timeline-range`||n===`approval`)return _t(e)&&e.schemaVersion===1?!0:n===`timeline-range`?pe(e):me(e);if(n===`json`)try{return pt(e),!0}catch{return!1}return n===`image`&&_t(e)&&Array.isArray(e.data)?Number.isInteger(e.width)&&Number.isInteger(e.height)&&e.width>0&&e.height>0&&e.width*e.height<=1048576&&e.data.length===e.width*e.height*4&&e.data.every(e=>Number.isInteger(e)&&e>=0&&e<=255):[`image`,`video`,`audio`,`asset`].includes(n)?_t(e)&&typeof e.assetId==`string`&&typeof e.versionId==`string`&&(n===`asset`||e.kind===n):vt.includes(n)&&_t(e)&&e.schemaVersion===1}var V,_t,vt,yt,bt,xt,St,Ct,wt=o((()=>{k(),z(),re(),ce(),ue(),de(),fe(),ve(),be(),Se(),Ee(),He(),We(),Ge(),lt(),ut(),dt(),ft(),V=te,_t=B,Object.freeze([`type`,`required`,`default`,`min`,`max`,`description`,`role`,`primary`,`context`,`imageMode`,...se]),vt=Object.freeze(`text.number.integer.boolean.json.object.image.video.audio.asset.script.transcript.brief.bible.shot-plan.panel-document.board-document.scene-document.timeline.timeline-edit.file-bundle.workspace-edit.timeline-range.research.character.location.style.pipeline.approval.scene.shot.mask.depth.pose.metadata.project-context.file.document.table.url.date.color`.split(`.`)),Object.freeze([`final.render`,`stock.search`,`stock.select`,`stock.auto`,`gif.search`,`gif.save`,`presenter.generate`,`quality.analyze`,`image.generate`,`image.generate.batch`,`media.generate`,`youtube.upload`]),Object.freeze([`text`,`number`,`slider`,`checkbox`,`asset`,`select`,`multiselect`,`file`,`date`,`color`,`url`,`richtext`,`list`,`grid`]),Object.freeze([`gallery`,`before-after`,`table`,`document`,`chart`,`code`,`player`,`download`]),Object.freeze({file:[`file`,`file[]`],date:[`date`],color:[`color`],url:[`url`],richtext:[`document`,`text`],list:[`text[]`,`number[]`,`integer[]`,`url[]`,`date[]`,`color[]`],grid:[`table`]}),Object.freeze({gallery:[`image[]`],"before-after":[`image`],table:[`table`],document:[`document`,`text`],chart:[`table`,`number[]`,`integer[]`],code:[`text`,`json`,`object`],player:[`audio`,`video`,`audio[]`,`video[]`],download:[`file`,`file[]`,`file-bundle`]}),yt=Object.freeze({script:`script`,transcript:`transcript`,shots:`shot[]`,shotPlan:`shot-plan`,scenes:`scene[]`,characters:`character[]`,locations:`location[]`,styles:`style[]`,assets:`asset[]`,files:`file[]`,generations:`metadata[]`,versions:`metadata[]`,timeline:`timeline`,editor:`timeline`,canvas:`pipeline`,blueprint:`bible`,panels:`panel-document`,board:`board-document`,animation:`scene-document`,metadata:`metadata`}),bt=(e,t,n,r)=>Object.freeze({executor:e,mode:t,byok:n,summary:r}),xt=Object.freeze({"text.generate":bt(`capability-run`,`sync`,!0,`Exact model, account BYOK or credits, and explicit run review`),"audio.speech":bt(`capability-run`,`sync`,!0,`One short text/script input to measured audio in any StillMade catalog voice (Deepgram, ElevenLabs, OpenAI, Kokoro) with credits, or OpenAI with your key; playback review; accepted project recordings can be explicitly added to Editor audio`),"audio.transcribe":bt(`capability-run`,`sync`,!0,`One owner-scoped stored audio asset to reviewed text and ordered word timings with StillMade transcription on credits, or OpenAI Whisper with your key`),"audio.music":bt(`capability-run`,`sync`,!1,`One prompt to generated music (5–240 seconds) with StillMade credits and playback review`),"audio.sfx":bt(`capability-run`,`sync`,!1,`One prompt to a generated sound effect (0.5–22 seconds) with StillMade credits and playback review`),"image.generate":bt(`capability-run`,`sync`,!0,`One prompt and optional reference images to a stored PNG with any catalog image model and its settings; StillMade credits or account key, and actual image review`),"video.generate":bt(`capability-run`,`async`,!0,`One prompt and optional first/last frames to a measured stored video clip with any catalog video model and its settings; StillMade credits and actual video review`),"image.describe":bt(`capability-run`,`sync`,!0,`One to four owned images to bounded production notes; host-selected model/payment and actual description review`),"media.analyze":bt(`capability-run`,`sync`,!1,`One owned video (optionally one time range), image or up to four images to structured visual evidence: summary, timeline, observations, on-screen text and issues, with StillMade credits; detail "check" gives one to four photos a short answer each at one price per call`),"web.fetch":bt(`capability-run`,`sync`,!1,`One public web page read by the host and answered against the Block's instruction, with StillMade credits; no cookies, keys or private addresses`),"web.research":bt(`capability-run`,`sync`,!1,`One topic searched on the web and summarized with cited sources, with StillMade credits`),"timeline.propose":bt(`capability-run`,`sync`,!0,`Bounded typed context to strict timeline-edit JSON; host-selected model/payment, stale-before checks, preview and Apply`),"workspace.propose":bt(`capability-run`,`sync`,!0,`Bounded typed context to a strict workspace-edit proposal for one permitted workspace; preview and explicit Apply`),"connection.execute":bt(`connection`,`sync`,!1,`One reviewed action on a connected third-party app account through the host connection service; the Block never receives account credentials`)}),St=e=>Object.freeze(Object.entries(xt).filter(([,t])=>e(t)).map(([e])=>e)),St(()=>!0),St(e=>e.executor===`capability-run`),St(e=>e.executor===`capability-run`&&e.mode===`sync`),St(e=>e.byok),[...Object.keys(yt).map(e=>`context.${e}.read`)],Ct=new Set([`__proto__`,`prototype`,`constructor`])}));wt();var Tt=Object.freeze([`tasks`,`preview-task`,`apply-task`]);function Et(e,t={}){return V(Tt.includes(e),`CONNECTION_TASK`,`Choose a declared task operation.`),pt(t),V(_t(t)&&JSON.stringify(t).length<=32768,`CONNECTION_TASK`,`Use bounded task selection arguments.`),{operation:e,args:structuredClone(t)}}function Dt(e,t,n,r){let i=0,a=new Map;return addEventListener(`message`,n=>{let r=n.data;if(n.source!==parent||!r||r.channel!==e||r.session!==t||r.op!==`connected-app-result`)return;let i=a.get(r.id);i&&(a.delete(r.id),r.error?i.reject(Error(r.error)):i.resolve(r.result))}),{connectedApp(o,s={}){if(!n)return Promise.reject(Error(`This Block has no connected-app task contract.`));if(![`tasks`,`preview-task`,`apply-task`].includes(o)||!s||typeof s!=`object`||Array.isArray(s)||JSON.stringify(s).length>32768)return Promise.reject(Error(`Invalid task choice.`));if(a.size>=2)return Promise.reject(Error(`Wait for the current task choice.`));let c=String(++i);return new Promise((n,i)=>{a.set(c,{resolve:n,reject:i}),r({channel:e,session:t,op:`connected-app-request`,id:c,operation:o,args:s},`*`)})}}}function Ot(e,t,n,r){let i=new Set,a=new Set,o=new Set,s=(e,t)=>{if(typeof t!=`function`)throw TypeError(`Pass a function.`);return e.add(t),()=>{e.delete(t)}},c=e=>{typeof reportError==`function`&&reportError(e)},l=(e,...t)=>{for(let n of[...e])try{n(...t)}catch(e){c(e)}};return{live:Object.freeze({start:(e={})=>r(`live.start`,e),stop:()=>r(`live.stop`,{}),status:()=>r(`live.status`,{}),onFrame:e=>s(i,e),onAudio:e=>s(a,e),onEnd:e=>s(o,e)}),receive:r=>{if(r.op!==`live`)return!1;if(r.type===`frame`)try{l(i,r.bitmap,{index:r.index,timestamp:r.timestamp,width:r.width,height:r.height})}finally{try{r.bitmap?.close?.()}catch{}n({channel:e,session:t,op:`live-ack`},`*`)}else r.type===`audio`?l(a,r.samples,{index:r.index,timestamp:r.timestamp,sampleRate:r.sampleRate}):r.type===`ended`&&l(o,{reason:String(r.reason||`stopped`)});return!0},dispose(){i.clear(),a.clear(),o.clear()}}}function kt(e){let t=0,n=null,r=[],i=0,a=new Map,o=()=>{if(n||!r.length)return;let s=r.shift();n=s,Promise.resolve().then(()=>{if(s.generation!==t)throw Error(`Preview input changed`);return s.edge===void 0?e(s.kind,s.value):e(s.kind,s.value,{edge:s.edge})}).then(e=>{s.kind===`image`&&s.generation===t&&(a.delete(s.serialized),a.set(s.serialized,e),a.size>48&&a.delete(a.keys().next().value)),s.resolve(e)},s.reject).finally(()=>{n===s&&(n=null,i-=s.bytes,o())})};return{request(e,s,c){let l,u,d,f;try{if(![`image`,`media`].includes(e)||!s||Array.isArray(s)||typeof s!=`object`)throw Error(`Expected a bounded preview value`);if(d=c?.edge,d!==void 0&&(e!==`image`||!Number.isInteger(d)||d<64||d>2048))throw Error(`Ask for an image preview edge from 64 to 2048 pixels, as in StillMade.previewImage(photo, {edge: 2048}).`);if(f=JSON.stringify(s),l=d===void 0?f:`${f}@${d}`,u=new TextEncoder().encode(f).length,u>4194304)throw Error(`Expected a bounded preview value`)}catch(e){return Promise.reject(e)}if(e===`image`&&a.has(l))return Promise.resolve(a.get(l));let p=e===`image`&&[n,...r].find(t=>t?.kind===e&&t.serialized===l);if(p)return p.promise;if(r.length+ +!!n>=64||i+u>8388608)return Promise.reject(Error(`Too many queued previews. Wait for a preview to finish.`));let m={kind:e,value:JSON.parse(f),serialized:l,bytes:u,generation:t,edge:d};return m.promise=new Promise((e,t)=>{m.resolve=e,m.reject=t}),i+=u,r.push(m),o(),m.promise},reset(e=`Preview input changed`){t+=1;for(let t of[n,...r])t&&t.reject(Error(e));n=null,r=[],i=0}}}function At(){return null}function jt(){try{return typeof indexedDB<`u`&&indexedDB!==null}catch{return!1}}function Mt(){return Bt||(Bt=new Promise((e,t)=>{let n;try{n=indexedDB.open(Pt,Ft)}catch(e){t(e);return}n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(`cacheMeta`)||e.createObjectStore(It,{keyPath:`key`}),e.objectStoreNames.contains(`blobs`)||e.createObjectStore(Lt),e.objectStoreNames.contains(`handles`)||e.createObjectStore(Rt),e.objectStoreNames.contains(`deviceMedia`)||e.createObjectStore(zt,{keyPath:`id`})},n.onsuccess=()=>{let t=n.result;t.onversionchange=()=>{t.close(),Bt=null},e(t)},n.onerror=()=>t(n.error||Error(`indexedDB open failed`)),n.onblocked=()=>t(Error(`indexedDB blocked`))}),Bt.catch(()=>{Bt=null}),Bt)}function Nt(e,t,n){return Mt().then(r=>new Promise((i,a)=>{let o;try{o=r.transaction(e,t)}catch(e){a(e);return}let s;try{s=n(o.objectStore(e))}catch(e){a(e);return}o.oncomplete=()=>i(s?s.result:void 0),o.onerror=()=>a(o.error||Error(`idb tx error`)),o.onabort=()=>a(o.error||Error(`idb tx aborted`))}))}var Pt,Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt=o((()=>{Pt=`aivw_editor`,Ft=2,It=`cacheMeta`,Lt=`blobs`,Rt=`handles`,zt=`deviceMedia`,Bt=null,Vt=(e,t)=>Nt(e,`readonly`,e=>e.get(t)),Ht=e=>Nt(e,`readonly`,e=>e.getAll()),Ut=(e,t,n)=>Nt(e,`readwrite`,e=>n===void 0?e.put(t):e.put(t,n)),Wt=(e,t)=>Nt(e,`readwrite`,e=>e.delete(t))}));function Kt(){try{return typeof localStorage>`u`?null:JSON.parse(localStorage.getItem(qt)||`null`)?.user?.id||null}catch{return null}}var qt,Jt=o((()=>{qt=`ai-video-workflow-auth`}));function Yt(){let e=new Uint32Array([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),t=new Uint32Array(64),n=new Uint8Array(64),r=0,i=0,a=(n,r)=>{for(let e=0;e<16;e++)t[e]=n[r+e*4]<<24|n[r+e*4+1]<<16|n[r+e*4+2]<<8|n[r+e*4+3];for(let e=16;e<64;e++){let n=Qt(t[e-15],7)^Qt(t[e-15],18)^t[e-15]>>>3,r=Qt(t[e-2],17)^Qt(t[e-2],19)^t[e-2]>>>10;t[e]=t[e-16]+n+t[e-7]+r>>>0}let i=e[0],a=e[1],o=e[2],s=e[3],c=e[4],l=e[5],u=e[6],d=e[7];for(let e=0;e<64;e++){let n=Qt(c,6)^Qt(c,11)^Qt(c,25),r=c&l^~c&u,f=d+n+r+Zt[e]+t[e]>>>0,p=(Qt(i,2)^Qt(i,13)^Qt(i,22))+(i&a^i&o^a&o)>>>0;d=u,u=l,l=c,c=s+f>>>0,s=o,o=a,a=i,i=f+p>>>0}e[0]=e[0]+i>>>0,e[1]=e[1]+a>>>0,e[2]=e[2]+o>>>0,e[3]=e[3]+s>>>0,e[4]=e[4]+c>>>0,e[5]=e[5]+l>>>0,e[6]=e[6]+u>>>0,e[7]=e[7]+d>>>0};return{update(e){let t=e instanceof Uint8Array?e:new Uint8Array(e);i+=t.length;let o=0;if(r){let e=Math.min(64-r,t.length);if(n.set(t.subarray(0,e),r),r+=e,o=e,r<64)return this;a(n,0),r=0}for(;o+64<=t.length;o+=64)a(t,o);return o<t.length&&(n.set(t.subarray(o),0),r=t.length-o),this},digest(){let t=i*8,o=new Uint8Array(r<56?64:128);o.set(n.subarray(0,r)),o[r]=128;let s=new DataView(o.buffer);s.setUint32(o.length-8,Math.floor(t/4294967296)),s.setUint32(o.length-4,t>>>0);for(let e=0;e<o.length;e+=64)a(o,e);return[...e].map(e=>e.toString(16).padStart(8,`0`)).join(``)}}}async function Xt(e,{subtleLimit:t=$t,signal:n}={}){if(e.size<=t&&typeof crypto?.subtle?.digest==`function`){let t=await crypto.subtle.digest(`SHA-256`,await e.arrayBuffer());return[...new Uint8Array(t)].map(e=>e.toString(16).padStart(2,`0`)).join(``)}let r=Yt();for(let t=0;t<e.size;t+=en)n?.throwIfAborted?.(),r.update(new Uint8Array(await e.slice(t,t+en).arrayBuffer()));return r.digest()}var Zt,Qt,$t,en,tn=o((()=>{Zt=new Uint32Array([1116352408,1899447441,3049323471,3921009573,961987163,1508970993,2453635748,2870763221,3624381080,310598401,607225278,1426881987,1925078388,2162078206,2614888103,3248222580,3835390401,4022224774,264347078,604807628,770255983,1249150122,1555081692,1996064986,2554220882,2821834349,2952996808,3210313671,3336571891,3584528711,113926993,338241895,666307205,773529912,1294757372,1396182291,1695183700,1986661051,2177026350,2456956037,2730485921,2820302411,3259730800,3345764771,3516065817,3600352804,4094571909,275423344,430227734,506948616,659060556,883997877,958139571,1322822218,1537002063,1747873779,1955562222,2024104815,2227730452,2361852424,2428436474,2756734187,3204031479,3329325298]),Qt=(e,t)=>e>>>t|e<<32-t,$t=67108864,en=8388608}));function nn(){if(Nn!==void 0)return Nn;try{return Kt()||null}catch{return null}}async function rn(){if(jn!==void 0)return jn;try{jn=navigator?.storage?.getDirectory?await(await navigator.storage.getDirectory()).getDirectoryHandle(yn,{create:!0}):null}catch{jn=null}return jn}async function an(){if(!Mn){Mn=!0;try{await navigator?.storage?.persist?.()}catch{}}}async function on(e,t){let n=await rn();if(n){let r=await(await n.getFileHandle(t,{create:!0})).createWritable();return await r.write(e),await r.close(),`opfs`}return await Ut(Lt,e,`device:${t}`),`idb`}function sn(){try{window.dispatchEvent(new CustomEvent(An,{detail:{needed:kn.size}}))}catch{}}async function cn(e){let t=Rn(e);if(typeof t?.getFile!=`function`)throw Ln(`DEVICE_MEDIA_MOVED`,`This file is no longer linked on this computer.`);if(typeof t.queryPermission==`function`&&await t.queryPermission({mode:`read`})!==`granted`)throw kn.has(e.id)||(kn.set(e.id,t),sn()),Ln(`DEVICE_MEDIA_ACCESS`,`Allow StillMade to open this file on your computer again.`);let n;try{n=await t.getFile()}catch{throw Ln(`DEVICE_MEDIA_MOVED`,`This file was moved, renamed or deleted on this computer.`)}if(n.size!==e.bytes||e.lastModified&&n.lastModified!==e.lastModified)throw Ln(`DEVICE_MEDIA_CHANGED`,`This file changed on this computer after it was added.`);return n}async function ln(e){if(e.storage===`linked`)return cn(e);if(e.storage===`opfs`){let t=await rn();if(!t)throw Error(`Device storage is unavailable.`);return(await t.getFileHandle(e.versionId)).getFile()}let t=await Vt(Lt,`device:${e.versionId}`);if(!t)throw Error(`This media is not on this device.`);return t}function un(){return jt()&&typeof crypto?.subtle?.digest==`function`}async function dn(e,{kind:t,metadata:n={},role:r=`original`,links:i={},assetId:a=crypto.randomUUID(),signal:o,maxBytes:s=bn,handle:c=null}={}){if(!un())throw Error(`This browser cannot keep media on the device.`);if(!c&&e.size>s)throw Error(`Files over ${Math.round(s/1024/1024)>=1024?`${Math.round(s/1024/1024/1024*10)/10} GB`:`${Math.round(s/1024/1024)} MB`} stay where they are; use StillMade Desktop for larger media.`);o?.throwIfAborted?.(),await an();let l=await Fn(e,o);o?.throwIfAborted?.();let u=await Ht(zt).then(e=>e.find(e=>e.versionId===l&&e.kind===t)).catch(()=>null),d=c?`linked`:[`opfs`,`idb`].includes(u?.storage)?u.storage:await on(e,l);o?.throwIfAborted?.(),c&&On.set(l,c);let f={id:`${a}:${l}`,assetId:a,versionId:l,kind:t,role:r,name:String(e.name||``).slice(0,240),mimeType:e.type||n.mimeType||``,bytes:e.size,...zn(n,[`width`,`height`,`duration`]),storage:d,...c?{handle:c,lastModified:e.lastModified}:{},source:`local`,...i,...nn()?{owner:nn()}:{},cloud:{},createdAt:Date.now()};return await Ut(zt,f),f}async function fn(e){if(!e?.assetId||!e?.versionId)return null;let t=await Vt(`deviceMedia`,In(e)).catch(()=>null)||null;return t&&Pn(t)?t:null}async function pn(e,t=Bn.get(Cn(e))){if(!t)return null;let n=e=>fetch(t,{credentials:`omit`,redirect:`follow`,referrerPolicy:`no-referrer`,...e?{cache:e}:{}}),r;try{r=await n()}catch(e){if(!(e instanceof TypeError))return null;try{r=await n(`reload`)}catch{return null}}if(!r?.ok)return null;let i=await r.blob();return await Fn(i)===e.versionId?i:null}async function mn(e){let t=await fn(e);if(t)return ln(t);let n=await pn(e).catch(()=>null);if(!n)throw Error(`This media is not on this device.`);return n}async function hn(e){let t=In(e);if(En.has(t))return En.get(t);let n=URL.createObjectURL(await mn(e));return En.set(t,n),Dn.add(n),n}async function gn(e){let t=wn(e);if(!t)return null;try{return await hn(t)}catch{return null}}function _n(e,{role:t,name:n}={}){let r={kind:e.kind,assetId:e.assetId,versionId:e.versionId,url:Cn(e),source:`local`,name:n||e.name,mimeType:e.mimeType,bytes:e.bytes};for(let t of[`width`,`height`,`duration`])e[t]!==void 0&&e[t]!==null&&(r[t]=e[t]);return t&&(r.role=t),r}async function vn(){let e=(await Ht(zt).catch(()=>[])).filter(e=>e.storage!==`linked`),t=new Set,n=e.reduce((e,n)=>t.has(n.versionId)?e:(t.add(n.versionId),e+(n.bytes||0)),0),r=null;try{r=(await navigator.storage.estimate()).quota||null}catch{}return{files:t.size,bytes:n,quota:r}}var yn,bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn=o((()=>{Gt(),Jt(),tn(),yn=`device-media`,bn=268435456,xn=`sm-media://device/`,Sn=/^sm-media:\/\/device\/([a-f0-9-]{36})\/([a-f0-9]{64})$/,Cn=e=>`${xn}${e.assetId}/${e.versionId}`,wn=e=>{let t=Sn.exec(String(e||``));return t?{assetId:t[1],versionId:t[2]}:null},Tn=e=>Sn.test(String(e||``)),En=new Map,Dn=new Set,On=new Map,kn=new Map,An=`stillmade:device-media-access`,Mn=!1,Pn=e=>{let t=nn();return!e?.owner||!t||e.owner===t},Fn=(e,t)=>Xt(e,{signal:t}),In=e=>`${e.assetId}:${e.versionId}`,Ln=(e,t)=>Object.assign(Error(t),{code:e}),Rn=e=>On.get(e.versionId)||e.handle,zn=(e,t)=>Object.fromEntries(t.filter(t=>e?.[t]!==void 0&&e[t]!==null).map(t=>[t,e[t]])),Bn=new Map}));Vn();var Hn=Object.freeze({bytes:25165824,timeoutMs:15e3}),Un=Object.freeze({image:[`image/png`,`image/jpeg`,`image/webp`,`image/gif`],video:[`video/mp4`,`video/webm`,`video/ogg`,`video/quicktime`],audio:[`audio/mpeg`,`audio/mp3`,`audio/mp4`,`audio/aac`,`audio/ogg`,`audio/wav`,`audio/x-wav`,`audio/webm`,`audio/flac`]});function Wn(e){if(!e||!Un[e.kind]?.includes(e.blob?.type)||!(e.blob instanceof Blob)||!e.blob.size||!e.local&&e.blob.size>Hn.bytes)throw Error(`The host returned an unsupported or oversized media preview.`);return{kind:e.kind,blob:e.blob,...e.local===!0?{local:!0}:{}}}var Gn=/^\/api\/media\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/;async function Kn(e,{signal:t,check:n=()=>{}}={}){if(n(),Tn(e.url)){let t=wn(e.url),r=await fn(t);if(n(),!r)throw Error(`This media is not on this device. Open the project on the device that holds it.`);let i=await mn(t);n();let a=String(r.mimeType||i.type||``).split(`;`)[0].trim().toLowerCase();if(!Un[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);return Wn({kind:e.kind,blob:i.type===a?i:new Blob([i],{type:a}),local:!0})}let r=n=>fetch(e.url,{signal:t,credentials:`omit`,redirect:Gn.test(e.url)?`follow`:`error`,referrerPolicy:`no-referrer`,...n?{cache:n}:{}}),i;try{i=await r()}catch(a){if(a?.name===`AbortError`||!(a instanceof TypeError))throw a;n();try{i=await r(`no-store`)}catch(r){if(r?.name===`AbortError`||!(r instanceof TypeError))throw r;let a=Error(`This media could not reach StillMade. Check your connection and try again.`);if(!Gn.test(e.url))throw a;n();try{i=await fetch(e.url.replace(/^\/api\/media\//,`/api/media/bytes/`),{signal:t,credentials:`omit`,redirect:`error`,referrerPolicy:`no-referrer`,cache:`no-store`})}catch(e){throw e?.name===`AbortError`?e:a}if(i.status===413)throw Error(`This media is too large to preview here. Download it to play it.`)}}if(n(),!i.ok)throw Error(`This media could not be loaded. Upload a local copy to preview it.`);let a=(i.headers.get(`content-type`)||``).split(`;`)[0].trim().toLowerCase();if(!Un[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);if(Number(i.headers.get(`content-length`))>Hn.bytes)throw Error(`Preview media must be under 24 MB.`);if(!i.body?.getReader)throw Error(`Streaming media previews are unavailable in this browser.`);let o=i.body.getReader(),s=[],c=0;try{for(;;){if(n(),t?.aborted)throw new DOMException(`Media preview cancelled`,`AbortError`);let{done:e,value:r}=await o.read();if(n(),e)break;if(c+=r.byteLength,c>Hn.bytes)throw Error(`Preview media must be under 24 MB.`);s.push(r)}return Wn({kind:e.kind,blob:new Blob(s,{type:a})})}finally{await o.cancel().catch(()=>{}),o.releaseLock()}}var qn=new Set;function Jn(e){return qn.add(e),()=>qn.delete(e)}function Yn(e,t,n,r=null,i=[]){let a=new Map,o=[`text`,`search`,`email`,`tel`,`url`],s=new Set(i),c=new Map,l=new Set,u=new Map,d=!1,f={},p=(e,t,n)=>e?e.some(e=>e.value===String(n)):t.tagName!==`SELECT`||[...t.options].some(e=>e.value===String(n)),m=(e,t)=>{if(clearTimeout(t.timer),c.delete(e),d)return;let r;return r=Promise.resolve().then(()=>{if(!d)return t.callback()}).catch(t=>{u.set(e,t),n(t.message)}).finally(()=>l.delete(r)),l.add(r),r},h=(e,t)=>{if(d)throw Error(`This interface has closed; shared edits stopped.`);if(typeof e!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e))throw Error(`A shared edit key starts with a letter and holds only letters, digits, - and _ (up to 100 characters).`);if(typeof t!=`function`)throw Error(`Give scheduleSharedEdit a function to run.`);if(!c.has(e)&&c.size+l.size>=32||!u.has(e)&&u.size>=32)throw Error(`Too many scheduled shared edits`);u.delete(e);let n=c.get(e),r={callback:t,started:n?.started??Date.now(),timer:null};n&&clearTimeout(n.timer),r.timer=setTimeout(()=>m(e,r),Math.max(0,Math.min(150,500-(Date.now()-r.started)))),c.set(e,r)},g=(i,c)=>{if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(i)||a.has(i))throw Error(`Use one control per named shared field`);let l=e.getElementById(c),u=l?.tagName===`FIELDSET`?[...l.querySelectorAll(`input[type="radio"]`)]:null;if(!l||![`INPUT`,`TEXTAREA`,`SELECT`,`FIELDSET`].includes(l.tagName)||u&&!u.length||l.tagName===`INPUT`&&![`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`].includes(l.type))throw Error(`Bind an existing text, number, checkbox or select control, or a fieldset of radio buttons`);if(s.has(i)){let e=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),t=l.disabled,n=l.readOnly,r=l.getAttribute(`title`),s=l.getAttribute(`aria-readonly`),c=l.getAttribute(`aria-disabled`);e?(l.readOnly=!0,l.setAttribute(`aria-readonly`,`true`)):(l.disabled=!0,l.setAttribute(`aria-disabled`,`true`)),l.setAttribute(`title`,`Connected input. Change its source in Flow.`);let u={flush:async()=>{},status:()=>({dirty:!1,saving:!1,problem:null,canEdit:!1,composing:!1,interrupted:!1}),setDefault(){},dispose(){l.disabled=t,l.readOnly=n,r===null?l.removeAttribute(`title`):l.setAttribute(`title`,r),s===null?l.removeAttribute(`aria-readonly`):l.setAttribute(`aria-readonly`,s),c===null?l.removeAttribute(`aria-disabled`):l.setAttribute(`aria-disabled`,c),a.delete(i)}};return a.set(i,u),u.dispose}if(r&&(l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type))){let e=r.bind(i,l),t=e.dispose;return e.dispose=()=>{t(),a.delete(i)},a.set(i,e),e.dispose}let d=l.disabled,m={exists:!1},h,g=!1,_=!1,v=null,y=!1,b=!1,x=null,S=null,C=null,w=!1,T=!1,E,D=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),O=e=>{S=e,l.setCustomValidity(e.message),n(e.message)},k=()=>u.find(e=>e.checked)?.value??``,A=e=>{let n=u?k():l.type===`checkbox`?l.checked:l.value;if(u)for(let t of u)t.checked=t.value===String(e??``);else l.type===`checkbox`?l.checked=!!e:l.value!==String(e??``)&&(l.value=String(e??``));(u?k():l.type===`checkbox`?l.checked:l.value)!==n&&queueMicrotask(()=>{y||t.announce?.()})},j=()=>u?k():l.type===`checkbox`?l.checked:[`number`,`range`].includes(l.type)?l.valueAsNumber:l.value,M=Object.hasOwn(f,i)&&p(u,l,f[i])?f[i]:j(),N=()=>{if(clearTimeout(v),v=null,_)return x;if(y||w||!g||!b||S)return;let e=h;g=!1,C=null,_=!0;let n=!1;return x=Promise.resolve().then(()=>t.updateShared({[i]:e},{[i]:m})).then(()=>{m={exists:!0,value:e},l.setCustomValidity(``),!S&&g&&Object.is(h,e)&&(g=!1,C=null)},e=>{n=!0,g=!0,O(e)}).finally(()=>{_=!1,x=null,!y&&!n&&g&&h!==e&&P(),!y&&!g&&L(t.getShared())}),x},P=()=>{clearTimeout(v),v=setTimeout(N,Math.max(0,Math.min(150,500-(Date.now()-(C??Date.now())))))},F=()=>{!y&&D&&b&&!d&&(w=!0,clearTimeout(v),v=null)},I=e=>{if(y||!b||d)return;if(D&&e?.isComposing){F();return}if(w)return;let t=j();if(typeof t==`number`&&!Number.isFinite(t)){O(Error(`Enter a finite number`));return}E!==void 0&&Object.is(t,E)||(E=void 0,(S||!Object.is(t,g||_?h:m.exists?m.value:M))&&((S||C===null)&&(C=Date.now()),h=t,S=null,g=!0,P()))},L=e=>{y||(b=e.canEdit,l.disabled=d||!b,!b&&w&&(T=!0),!b&&(g||w)&&O(Error(`Editing access changed. Your unsaved draft has been preserved.`)),!(w||g||_||S)&&(m=Object.hasOwn(e.state,i)?{exists:!0,value:e.state[i]}:{exists:!1},A(m.exists?m.value:M)))},ee=t.onShared(L),R=()=>{if(!y&&w){if(w=!1,!b||T){T=!1,h=j(),E=h,g=!0,O(Error(`Editing access changed. Your unsaved draft has been preserved.`));return}I(),g&&!_&&!S?(C=Date.now(),P()):!g&&!_&&!S&&L(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let z=u?`focusout`:`blur`;l.addEventListener(`input`,I),l.addEventListener(`change`,I),l.addEventListener(z,N),l.addEventListener(`compositionstart`,F),l.addEventListener(`compositionend`,R);let te=()=>{y=!0,w=!1,clearTimeout(v),ee(),l.removeEventListener(`input`,I),l.removeEventListener(`change`,I),l.removeEventListener(z,N),l.removeEventListener(`compositionstart`,F),l.removeEventListener(`compositionend`,R),l.disabled=d,a.delete(i)};return a.set(i,{dispose:te,flush:N,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){M=e,L(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),te},_=new Map,v=new Map,y=new WeakSet,b=[`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`],x=/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/,S=/(?:password|secret|credential|authorization|cookie|token|api[_-]?key|private[_-]?key)/i,C=/^(?:current-password|new-password|one-time-code|cc-)/i,w=null,T=null,E=e=>{let t=_.get(e);if(t!==void 0){_.delete(e),v.delete(t);try{a.get(t)?.dispose()}catch{}a.delete(t)}},D=(t,n)=>{let r=e.getElementById(n);r&&_.has(r)&&E(r),v.has(t)&&E(v.get(t));let i=g(t,n);return r&&y.add(r),i},O=e=>{let t=e.getAttribute(`data-stillmade-share`)||e.getAttribute(`name`)||e.id||(e.tagName===`FIELDSET`?e.querySelector(`input[type="radio"][name]`)?.getAttribute(`name`):``)||``;return x.test(t)?t:null},k=e=>!e.isConnected||e.closest(`[data-stillmade-local]`)?!1:e.tagName===`FIELDSET`?!!e.querySelector(`input[type="radio"]`)&&!e.querySelector(`fieldset`):e.tagName===`INPUT`?b.includes(e.type):e.tagName===`TEXTAREA`||e.tagName===`SELECT`,A=t=>{if(y.has(t)||_.has(t)||!k(t))return;let n=O(t);if(!(!n||a.has(n)||a.size>=100)&&!(!t.hasAttribute(`data-stillmade-share`)&&(S.test(n)||S.test(t.getAttribute(`name`)||``)||S.test(t.id||``)||C.test(t.getAttribute(`autocomplete`)||``)))){if(!t.id){let r=`sm-shared-${n}`,i=1;for(;e.getElementById(r);)r=`sm-shared-${n}-${++i}`;t.id=r}else if(e.getElementById(t.id)!==t)return;try{g(n,t.id),_.set(t,n),v.set(n,t)}catch{a.delete(n)}}},j=()=>{if(T=null,!(d||M))try{for(let e of[..._.keys()])(!e.isConnected||e.closest(`[data-stillmade-local]`))&&E(e);for(let t of e.querySelectorAll(`input,textarea,select,fieldset`))A(t)}catch(e){n(e.message)}},M=!1,N=()=>{if(!M){M=!0,w?.disconnect(),w=null,T&&=(clearTimeout(T),null);for(let e of[..._.keys()])E(e)}},P=()=>{M||d||w||typeof MutationObserver!=`function`||!e.documentElement||(j(),w=new MutationObserver(()=>{!T&&!d&&(T=setTimeout(j,30))}),w.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`name`,`id`,`type`,`data-stillmade-local`,`data-stillmade-share`]}))};e.readyState===`loading`?e.addEventListener?.(`DOMContentLoaded`,P,{once:!0}):typeof setTimeout==`function`&&typeof MutationObserver==`function`&&setTimeout(P,0);let F=()=>{let t=[...e.querySelectorAll(`[data-stillmade-share]`)];if(t.length>100)throw Error(`Use at most 100 shared controls`);for(let n of t){let t=n.getAttribute(`data-stillmade-share`),r=n.id;if(typeof t!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(t)||typeof r!=`string`||!r||r.length>200||e.getElementById(r)!==n)throw Error(`Each data-stillmade-share control needs a unique ID and valid shared field name`);D(t,r)}return t.length},I=()=>{if(d)throw Error(`Block closed before edits could be flushed`);if([...a.values()].some(e=>e.status().composing))throw Error(`Finish composing text before leaving this Block or running an action.`);let e=[...a.values()].find(e=>e.status().interrupted);if(e)throw e.status().problem};return{bindShared:D,bindAnnotated:F,bindAutomatic:P,ownSharing:N,scheduleSharedEdit:h,flushAll:async()=>{if(d)throw Error(`Block closed before edits could be flushed`);for(let e=0;e<32;e++){if(d)throw Error(`Block closed before edits could be flushed`);I();let e=[...l];for(let[t,n]of[...c])e.push(m(t,n));for(let t of a.values())e.push(t.flush());if(await Promise.all(e),d)throw Error(`Block closed before edits could be flushed`);if(u.size)throw u.values().next().value;let t=!1;for(let e of a.values()){let n=e.status();if(n.problem)throw n.problem;if(n.composing)throw Error(`Finish composing text before leaving this Block or running an action.`);if(n.dirty&&!n.canEdit)throw Error(`Editing access changed. Your draft is not saved.`);t||=n.dirty||n.saving}if(!t&&!c.size&&!l.size)return{queued:!0}}throw Error(`Edits are still arriving. Finish editing before leaving this Block.`)},assertNoComposition:I,getBindingStatus:e=>a.get(e)?.status(),setSharedDefaults(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length>100||JSON.stringify(e).length>65536)throw Error(`Use bounded shared control defaults`);for(let[t,n]of Object.entries(e))a.get(t)?.setDefault(n)},useInputDefaults(e){let t=f;if(f={},e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))[`string`,`number`,`boolean`].includes(typeof n)&&(f[t]=n);for(let[e,n]of a)Object.hasOwn(f,e)&&!(Object.hasOwn(t,e)&&t[e]===f[e])&&n.setInputDefault(f[e])},dispose(){d=!0,w?.disconnect(),T&&clearTimeout(T);for(let e of c.values())clearTimeout(e.timer);c.clear();for(let e of[...a.values()])e.dispose()}}}var Xn='var StillMadeTextFrame=(function(e){Object.defineProperty(e,Symbol.toStringTag,{value:`Module`});let t=()=>new Map,n=e=>{let n=t();return e.forEach((e,t)=>{n.set(t,e)}),n},r=(e,t,n)=>{let r=e.get(t);return r===void 0&&e.set(t,r=n()),r},i=(e,t)=>{let n=[];for(let[r,i]of e)n.push(t(i,r));return n},a=(e,t)=>{for(let[n,r]of e)if(t(r,n))return!0;return!1},o=()=>new Set,s=e=>e[e.length-1],c=(e,t)=>{for(let n=0;n<t.length;n++)e.push(t[n])},l=Array.from,u=(e,t)=>{for(let n=0;n<e.length;n++)if(!t(e[n],n,e))return!1;return!0},d=(e,t)=>{for(let n=0;n<e.length;n++)if(t(e[n],n,e))return!0;return!1},f=(e,t)=>{let n=Array(e);for(let r=0;r<e;r++)n[r]=t(r,n);return n},p=Array.isArray;var m=class{constructor(){this._observers=t()}on(e,t){return r(this._observers,e,o).add(t),t}once(e,t){let n=(...r)=>{this.off(e,n),t(...r)};this.on(e,n)}off(e,t){let n=this._observers.get(e);n!==void 0&&(n.delete(t),n.size===0&&this._observers.delete(e))}emit(e,n){return l((this._observers.get(e)||t()).values()).forEach(e=>e(...n))}destroy(){this._observers=t()}};let h=Math.floor,g=Math.abs,_=(e,t)=>e<t?e:t,v=(e,t)=>e>t?e:t;Number.isNaN;let y=e=>e===0?1/e<0:e<0,b=2**53-1,x=-(2**53-1),S=Number.isInteger||(e=>typeof e==`number`&&isFinite(e)&&h(e)===e);Number.isNaN,Number.parseInt;let C=String.fromCharCode;String.fromCodePoint,C(65535);let w=e=>e.toLowerCase(),T=/^\\s*/g,E=e=>e.replace(T,``),D=/([A-Z])/g,ee=(e,t)=>E(e.replace(D,e=>`${t}${w(e)}`)),O=e=>{let t=unescape(encodeURIComponent(e)),n=t.length,r=new Uint8Array(n);for(let e=0;e<n;e++)r[e]=t.codePointAt(e);return r},k=typeof TextEncoder<`u`?new TextEncoder:null,A=k?e=>k.encode(e):O,j=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});j&&j.decode(new Uint8Array).length===1&&(j=null);let M=(e,t)=>f(t,()=>e).join(``);var N=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};let te=()=>new N,P=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},F=e=>{let t=new Uint8Array(P(e)),n=0;for(let r=0;r<e.bufs.length;r++){let i=e.bufs[r];t.set(i,n),n+=i.length}return t.set(new Uint8Array(e.cbuf.buffer,0,e.cpos),n),t},ne=(e,t)=>{let n=e.cbuf.length;n-e.cpos<t&&(e.bufs.push(new Uint8Array(e.cbuf.buffer,0,e.cpos)),e.cbuf=new Uint8Array(v(n,t)*2),e.cpos=0)},I=(e,t)=>{let n=e.cbuf.length;e.cpos===n&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(n*2),e.cpos=0),e.cbuf[e.cpos++]=t},re=I,L=(e,t)=>{for(;t>127;)I(e,128|127&t),t=h(t/128);I(e,127&t)},ie=(e,t)=>{let n=y(t);for(n&&(t=-t),I(e,(t>63?128:0)|(n?64:0)|63&t),t=h(t/64);t>0;)I(e,(t>127?128:0)|127&t),t=h(t/128)},ae=new Uint8Array(3e4),oe=ae.length/3,se=k&&k.encodeInto?(e,t)=>{if(t.length<oe){let n=k.encodeInto(t,ae).written||0;L(e,n);for(let t=0;t<n;t++)I(e,ae[t])}else R(e,A(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;L(e,r);for(let t=0;t<r;t++)I(e,n.codePointAt(t))},ce=(e,t)=>{let n=e.cbuf.length,r=e.cpos,i=_(n-r,t.length),a=t.length-i;e.cbuf.set(t.subarray(0,i),r),e.cpos+=i,a>0&&(e.bufs.push(e.cbuf),e.cbuf=new Uint8Array(v(n*2,a)),e.cbuf.set(t.subarray(i)),e.cpos=a)},R=(e,t)=>{L(e,t.byteLength),ce(e,t)},le=(e,t)=>{ne(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},ue=(e,t)=>le(e,4).setFloat32(0,t,!1),de=(e,t)=>le(e,8).setFloat64(0,t,!1),fe=(e,t)=>le(e,8).setBigInt64(0,t,!1),pe=new DataView(new ArrayBuffer(4)),me=e=>(pe.setFloat32(0,e),pe.getFloat32(0)===e),he=(e,t)=>{switch(typeof t){case`string`:I(e,119),se(e,t);break;case`number`:S(t)&&g(t)<=2147483647?(I(e,125),ie(e,t)):me(t)?(I(e,124),ue(e,t)):(I(e,123),de(e,t));break;case`bigint`:I(e,122),fe(e,t);break;case`object`:if(t===null)I(e,126);else if(p(t)){I(e,117),L(e,t.length);for(let n=0;n<t.length;n++)he(e,t[n])}else if(t instanceof Uint8Array)I(e,116),R(e,t);else{I(e,118);let n=Object.keys(t);L(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];se(e,i),he(e,t[i])}}break;case`boolean`:I(e,t?120:121);break;default:I(e,127)}};var ge=class extends N{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&L(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};let _e=e=>{e.count>0&&(ie(e.encoder,e.count===1?e.s:-e.s),e.count>1&&L(e.encoder,e.count-2))};var ve=class{constructor(){this.encoder=new N,this.s=0,this.count=0}write(e){this.s===e?this.count++:(_e(this),this.count=1,this.s=e)}toUint8Array(){return _e(this),F(this.encoder)}};let ye=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);ie(e.encoder,t),e.count>1&&L(e.encoder,e.count-2)}};var be=class{constructor(){this.encoder=new N,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(ye(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return ye(this),F(this.encoder)}},xe=class{constructor(){this.sarr=[],this.s=``,this.lensE=new ve}write(e){this.s+=e,this.s.length>19&&(this.sarr.push(this.s),this.s=``),this.lensE.write(e.length)}toUint8Array(){let e=new N;return this.sarr.push(this.s),this.s=``,se(e,this.sarr.join(``)),ce(e,this.lensE.toUint8Array()),F(e)}};let Se=e=>Error(e),Ce=()=>{throw Se(`Method unimplemented`)},we=()=>{throw Se(`Unexpected case`)},Te=Se(`Unexpected end of array`),Ee=Se(`Integer out of Range`);var De=class{constructor(e){this.arr=e,this.pos=0}};let Oe=e=>new De(e),ke=e=>e.pos!==e.arr.length,Ae=(e,t)=>{let n=new Uint8Array(e.arr.buffer,e.pos+e.arr.byteOffset,t);return e.pos+=t,n},je=e=>Ae(e,z(e)),Me=e=>e.arr[e.pos++],z=e=>{let t=0,n=1,r=e.arr.length;for(;e.pos<r;){let r=e.arr[e.pos++];if(t+=(r&127)*n,n*=128,r<128)return t;if(t>b)throw Ee}throw Te},Ne=e=>{let t=e.arr[e.pos++],n=t&63,r=64,i=(t&64)>0?-1:1;if(!(t&128))return i*n;let a=e.arr.length;for(;e.pos<a;){if(t=e.arr[e.pos++],n+=(t&127)*r,r*=128,t<128)return i*n;if(n>b)throw Ee}throw Te},Pe=j?e=>j.decode(je(e)):e=>{let t=z(e);if(t===0)return``;{let n=String.fromCodePoint(Me(e));if(--t<100)for(;t--;)n+=String.fromCodePoint(Me(e));else for(;t>0;){let r=t<1e4?t:1e4,i=e.arr.subarray(e.pos,e.pos+r);e.pos+=r,n+=String.fromCodePoint.apply(null,i),t-=r}return decodeURIComponent(escape(n))}},Fe=(e,t)=>{let n=new DataView(e.arr.buffer,e.arr.byteOffset+e.pos,t);return e.pos+=t,n},Ie=[e=>void 0,e=>null,Ne,e=>Fe(e,4).getFloat32(0,!1),e=>Fe(e,8).getFloat64(0,!1),e=>Fe(e,8).getBigInt64(0,!1),e=>!1,e=>!0,Pe,e=>{let t=z(e),n={};for(let r=0;r<t;r++){let t=Pe(e);n[t]=Le(e)}return n},e=>{let t=z(e),n=[];for(let r=0;r<t;r++)n.push(Le(e));return n},je],Le=e=>Ie[127-Me(e)](e);var Re=class extends De{constructor(e,t){super(e),this.reader=t,this.s=null,this.count=0}read(){return this.count===0&&(this.s=this.reader(this),this.count=ke(this)?z(this)+1:-1),this.count--,this.s}},ze=class extends De{constructor(e){super(e),this.s=0,this.count=0}read(){if(this.count===0){this.s=Ne(this);let e=y(this.s);this.count=1,e&&(this.s=-this.s,this.count=z(this)+2)}return this.count--,this.s}},Be=class extends De{constructor(e){super(e),this.s=0,this.count=0,this.diff=0}read(){if(this.count===0){let e=Ne(this),t=e&1;this.diff=h(e/2),this.count=1,t&&(this.count=z(this)+2)}return this.s+=this.diff,this.count--,this.s}},Ve=class{constructor(e){this.decoder=new ze(e),this.str=Pe(this.decoder),this.spos=0}read(){let e=this.spos+this.decoder.read(),t=this.str.slice(this.spos,e);return this.spos=e,t}};crypto.subtle;let He=crypto.getRandomValues.bind(crypto),Ue=()=>He(new Uint32Array(1))[0],We=()=>`10000000-1000-4000-8000-100000000000`.replace(/[018]/g,e=>(e^Ue()&15>>e/4).toString(16)),Ge=Date.now,Ke=e=>new Promise(e);Promise.all.bind(Promise);let qe=e=>e===void 0?null:e,Je=new class{constructor(){this.map=new Map}setItem(e,t){this.map.set(e,t)}getItem(e){return this.map.get(e)}};try{typeof localStorage<`u`&&localStorage&&(Je=localStorage)}catch{}let Ye=Je,Xe=Symbol(`Equality`),Ze=(e,t)=>e===t||!!e?.[Xe]?.(t)||!1,Qe=e=>typeof e==`object`,$e=Object.assign,et=Object.keys,tt=(e,t)=>{for(let n in e)t(e[n],n)},nt=e=>et(e).length,rt=e=>{for(let t in e)return!1;return!0},it=(e,t)=>{for(let n in e)if(!t(e[n],n))return!1;return!0},at=(e,t)=>Object.prototype.hasOwnProperty.call(e,t),ot=(e,t)=>e===t||nt(e)===nt(t)&&it(e,(e,n)=>(e!==void 0||at(t,n))&&Ze(t[n],e)),st=Object.freeze,ct=e=>{for(let t in e){let n=e[t];(typeof n==`object`||typeof n==`function`)&&ct(e[t])}return st(e)},lt=(e,t,n=0)=>{try{for(;n<e.length;n++)e[n](...t)}finally{n<e.length&<(e,t,n+1)}},ut=e=>e,dt=(e,t)=>{if(e===t)return!0;if(e==null||t==null||e.constructor!==t.constructor&&(e.constructor||Object)!==(t.constructor||Object))return!1;if(e[Xe]!=null)return e[Xe](t);switch(e.constructor){case ArrayBuffer:e=new Uint8Array(e),t=new Uint8Array(t);case Uint8Array:if(e.byteLength!==t.byteLength)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;break;case Set:if(e.size!==t.size)return!1;for(let n of e)if(!t.has(n))return!1;break;case Map:if(e.size!==t.size)return!1;for(let n of e.keys())if(!t.has(n)||!dt(e.get(n),t.get(n)))return!1;break;case void 0:case Object:if(nt(e)!==nt(t))return!1;for(let n in e)if(!at(e,n)||!dt(e[n],t[n]))return!1;break;case Array:if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(!dt(e[n],t[n]))return!1;break;default:return!1}return!0},ft=(e,t)=>t.includes(e),pt=typeof process<`u`&&process.release&&/node|io\\.js/.test(process.release.name)&&Object.prototype.toString.call(typeof process<`u`?process:0)===`[object process]`;typeof navigator<`u`&&/Mac/.test(navigator.platform);let mt,ht=[],gt=()=>{if(mt===void 0){if(pt){mt=t();let e=process.argv,n=null;for(let t=0;t<e.length;t++){let r=e[t];r[0]===`-`?(n!==null&&mt.set(n,``),n=r):n===null?ht.push(r):(mt.set(n,r),n=null)}n!==null&&mt.set(n,``)}else typeof location==`object`?(mt=t(),(location.search||`?`).slice(1).split(`&`).forEach(e=>{if(e.length!==0){let[t,n]=e.split(`=`);mt.set(`--${ee(t,`-`)}`,n),mt.set(`-${ee(t,`-`)}`,n)}})):mt=t()}return mt},_t=e=>gt().has(e),vt=e=>qe(pt?process.env[e.toUpperCase().replaceAll(`-`,`_`)]:Ye.getItem(e)),yt=e=>_t(`--`+e)||vt(e)!==null,bt=yt(`production`),xt=pt&&ft(process.env.FORCE_COLOR,[`true`,`1`,`2`])||!_t(`--no-colors`)&&!yt(`no-color`)&&(!pt||process.stdout.isTTY)&&(!pt||_t(`--color`)||vt(`COLORTERM`)!==null||(vt(`TERM`)||``).includes(`color`)),St=e=>new Uint8Array(e),Ct=e=>{let t=St(e.byteLength);return t.set(e),t};var wt=class{constructor(e,t){this.left=e,this.right=t}};let Tt=(e,t)=>new wt(e,t),Et=e=>e.next()>=.5,Dt=(e,t,n)=>h(e.next()*(n+1-t)+t),Ot=(e,t,n)=>h(e.next()*(n+1-t)+t),kt=(e,t,n)=>Ot(e,t,n),At=e=>C(kt(e,97,122)),jt=(e,t=0,n=20)=>{let r=kt(e,t,n),i=``;for(let t=0;t<r;t++)i+=At(e);return i},Mt=(e,t)=>t[kt(e,0,t.length-1)],Nt=Symbol(`0schema`);var Pt=class{constructor(){this._rerrs=[]}extend(e,t,n,r=null){this._rerrs.push({path:e,expected:t,has:n,message:r})}toString(){let e=[];for(let t=this._rerrs.length-1;t>0;t--){let n=this._rerrs[t];e.push(M(` `,(this._rerrs.length-t)*2)+`${n.path==null?``:`[${n.path}] `}${n.has} doesn\'t match ${n.expected}. ${n.message}`)}return e.join(`\n`)}};let Ft=(e,t)=>e===t?!0:e==null||t==null||e.constructor!==t.constructor?!1:e[Xe]?Ze(e,t):p(e)?u(e,e=>d(t,t=>Ft(e,t))):Qe(e)?it(e,(e,n)=>Ft(e,t[n])):!1;var B=class{static _dilutes=!1;extends(e){let[t,n]=[this.shape,e.shape];return this.constructor._dilutes&&([n,t]=[t,n]),Ft(t,n)}equals(e){return this.constructor===e.constructor&&dt(this.shape,e.shape)}[Nt](){return!0}[Xe](e){return this.equals(e)}validate(e){return this.check(e)}check(e,t){Ce()}get nullable(){return pn(this,On)}get optional(){return new Wt(this)}cast(e){return Mn(e,this),e}expect(e){return Mn(e,this),e}},It=class extends B{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t=void 0){let n=e?.constructor===this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name,e?.constructor===this.shape?`Check failed`:`Constructor match failed`),n}};let V=(e,t=null)=>new It(e,t);V(It);var Lt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape(e);return!n&&t?.extend(null,`custom prop`,e?.constructor.name,`failed to check custom prop`),n}};let H=e=>new Lt(e);V(Lt);var Rt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=this.shape.some(t=>t===e);return!n&&t?.extend(null,this.shape.join(` | `),e.toString()),n}};let zt=(...e)=>new Rt(e),Bt=V(Rt),Vt=RegExp.escape||(e=>e.replace(/[().|&,$^[\\]]/g,e=>`\\\\`+e)),Ht=e=>{if(Cn.check(e))return[Vt(e)];if(Bt.check(e))return e.shape.map(e=>e+``);if(Sn.check(e))return[`[+-]?\\\\d+.?\\\\d*`];if(wn.check(e))return[`.*`];if(mn.check(e))return e.shape.map(Ht).flat(1);we()};V(class extends B{constructor(e){super(),this.shape=e,this._r=RegExp(`^`+e.map(Ht).map(e=>`(${e.join(`|`)})`).join(``)+`$`)}check(e,t){let n=this._r.exec(e)!=null;return!n&&t?.extend(null,this._r.toString(),e.toString(),`String doesn\'t match string template.`),n}});let Ut=Symbol(`optional`);var Wt=class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=e===void 0||this.shape.check(e);return!n&&t?.extend(null,`undefined (optional)`,`()`),n}get[Ut](){return!0}};let Gt=V(Wt);var Kt=class extends B{check(e,t){return t?.extend(null,`never`,typeof e),!1}};new Kt,V(Kt);var qt=class e extends B{constructor(e,t=!1){super(),this.shape=e,this._isPartial=t}static _dilutes=!0;get partial(){return new e(this.shape,!0)}check(e,t){return e==null?(t?.extend(null,`object`,`null`),!1):it(this.shape,(n,r)=>{let i=this._isPartial&&!at(e,r)||n.check(e[r],t);return!i&&t?.extend(r.toString(),n.toString(),typeof e[r],`Object property does not match`),i})}};let Jt=e=>new qt(e),Yt=V(qt),Xt=H(e=>e!=null&&(e.constructor===Object||e.constructor==null));var Zt=class extends B{constructor(e,t){super(),this.shape={keys:e,values:t}}check(e,t){return e!=null&&it(e,(n,r)=>{let i=this.shape.keys.check(r,t);return!i&&t?.extend(r+``,`Record`,typeof e,i?`Key doesn\'t match schema`:`Value doesn\'t match value`),i&&this.shape.values.check(n,t)})}};let Qt=(e,t)=>new Zt(e,t),$t=V(Zt);var en=class extends B{constructor(e){super(),this.shape=e}check(e,t){return e!=null&&it(this.shape,(n,r)=>{let i=n.check(e[r],t);return!i&&t?.extend(r.toString(),`Tuple`,typeof n),i})}};let tn=(...e)=>new en(e);V(en);var nn=class extends B{constructor(e){super(),this.shape=e.length===1?e[0]:new fn(e)}check(e,t){let n=p(e)&&u(e,e=>this.shape.check(e));return!n&&t?.extend(null,`Array`,``),n}};let rn=(...e)=>new nn(e),an=V(nn),on=H(e=>p(e));var sn=class extends B{constructor(e,t){super(),this.shape=e,this._c=t}check(e,t){let n=e instanceof this.shape&&(this._c==null||this._c(e));return!n&&t?.extend(null,this.shape.name,e?.constructor.name),n}};let cn=(e,t=null)=>new sn(e,t);V(sn);let ln=cn(B),un=V(class extends B{constructor(e){super(),this.len=e.length-1,this.args=tn(...e.slice(-1)),this.res=e[this.len]}check(e,t){let n=e.constructor===Function&&e.length<=this.len;return!n&&t?.extend(null,`function`,typeof e),n}}),dn=H(e=>typeof e==`function`);V(class extends B{constructor(e){super(),this.shape=e}check(e,t){let n=u(this.shape,n=>n.check(e,t));return!n&&t?.extend(null,`Intersectinon`,typeof e),n}},e=>e.shape.length>0);var fn=class extends B{static _dilutes=!0;constructor(e){super(),this.shape=e}check(e,t){let n=d(this.shape,n=>n.check(e,t));return t?.extend(null,`Union`,typeof e),n}};let pn=(...e)=>e.findIndex(e=>mn.check(e))>=0?pn(...e.map(e=>jn(e)).map(e=>mn.check(e)?e.shape:[e]).flat(1)):e.length===1?e[0]:new fn(e),mn=V(fn),hn=()=>!0,gn=H(hn),_n=V(Lt,e=>e.shape===hn),vn=H(e=>typeof e==`bigint`),yn=H(e=>e===vn),bn=H(e=>typeof e==`symbol`);H(e=>e===bn);let xn=H(e=>typeof e==`number`),Sn=H(e=>e===xn),Cn=H(e=>typeof e==`string`),wn=H(e=>e===Cn),Tn=H(e=>typeof e==`boolean`),En=H(e=>e===Tn),Dn=zt(void 0);V(Rt,e=>e.shape.length===1&&e.shape[0]===void 0),zt(void 0);let On=zt(null),kn=V(Rt,e=>e.shape.length===1&&e.shape[0]===null);V(Uint8Array),V(It,e=>e.shape===Uint8Array);let An=pn(xn,Cn,On,Dn,vn,Tn,bn);(()=>{let e=rn(gn),t=Qt(Cn,gn),n=pn(xn,Cn,On,Tn,e,t);return e.shape=n,t.shape.values=n,n})();let jn=e=>{if(ln.check(e))return e;if(Xt.check(e)){let t={};for(let n in e)t[n]=jn(e[n]);return Jt(t)}if(on.check(e))return pn(...e.map(jn));if(An.check(e))return zt(e);if(dn.check(e))return V(e);we()},Mn=bt?()=>{}:(e,t)=>{let n=new Pt;if(!t.check(e,n))throw Se(`Expected value to be of type ${t.constructor.name}.\\n${n.toString()}`)};var Nn=class{constructor(e){this.patterns=[],this.$state=e}if(e,t){return this.patterns.push({if:jn(e),h:t}),this}else(e){return this.if(gn,e)}done(){return(e,t)=>{for(let n=0;n<this.patterns.length;n++){let r=this.patterns[n];if(r.if.check(e))return r.h(e,t)}throw Se(`Unhandled pattern`)}}};let Pn=(e=>new Nn(e))(gn).if(Sn,(e,t)=>Dt(t,x,b)).if(wn,(e,t)=>jt(t)).if(En,(e,t)=>Et(t)).if(yn,(e,t)=>BigInt(Dt(t,x,b))).if(mn,(e,t)=>Fn(t,Mt(t,e.shape))).if(Yt,(e,t)=>{let n={};for(let r in e.shape){let i=e.shape[r];if(Gt.check(i)){if(Et(t))continue;i=i.shape}n[r]=Pn(i,t)}return n}).if(an,(e,t)=>{let n=[],r=Ot(t,0,42);for(let i=0;i<r;i++)n.push(Fn(t,e.shape));return n}).if(Bt,(e,t)=>Mt(t,e.shape)).if(kn,(e,t)=>null).if(un,(e,t)=>{let n=Fn(t,e.res);return()=>n}).if(_n,(e,t)=>Fn(t,Mt(t,[xn,Cn,On,Dn,vn,Tn,rn(xn),Qt(pn(`a`,`b`,`c`),xn)]))).if($t,(e,t)=>{let n={},r=Dt(t,0,3);for(let i=0;i<r;i++){let r=Fn(t,e.shape.keys);n[r]=Fn(t,e.shape.values)}return n}).done(),Fn=(e,t)=>Pn(jn(t),e),In=typeof document<`u`?document:{};H(e=>e.nodeType===Vn),typeof DOMParser<`u`&&new DOMParser,H(e=>e.nodeType===Rn),H(e=>e.nodeType===zn);let Ln=e=>i(e,(e,t)=>`${t}:${e};`).join(``),Rn=In.ELEMENT_NODE,zn=In.TEXT_NODE;In.CDATA_SECTION_NODE,In.COMMENT_NODE;let Bn=In.DOCUMENT_NODE;In.DOCUMENT_TYPE_NODE;let Vn=In.DOCUMENT_FRAGMENT_NODE;H(e=>e.nodeType===Bn);let Hn=Symbol,Un=Hn(),Wn=Hn(),Gn=Hn(),Kn=Hn(),qn=Hn(),Jn=Hn(),Yn=Hn(),Xn=Hn(),Zn=Hn(),Qn=e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let t=[],n=[],r=0;for(;r<e.length;r++){let n=e[r];if(n===void 0)break;if(n.constructor===String||n.constructor===Number)t.push(n);else if(n.constructor===Object)break}for(r>0&&n.push(t.join(``));r<e.length;r++){let t=e[r];t instanceof Symbol||n.push(t)}return n};Ge();let $n={[Un]:Tt(`font-weight`,`bold`),[Wn]:Tt(`font-weight`,`normal`),[Gn]:Tt(`color`,`blue`),[qn]:Tt(`color`,`green`),[Kn]:Tt(`color`,`grey`),[Jn]:Tt(`color`,`red`),[Yn]:Tt(`color`,`purple`),[Xn]:Tt(`color`,`orange`),[Zn]:Tt(`color`,`black`)},er=xt?e=>{e.length===1&&e[0]?.constructor===Function&&(e=e[0]());let n=[],r=[],i=t(),a=[],o=0;for(;o<e.length;o++){let t=e[o],a=$n[t];if(a!==void 0)i.set(a.left,a.right);else{if(t===void 0)break;if(t.constructor===String||t.constructor===Number){let e=Ln(i);o>0||e.length>0?(n.push(`%c`+t),r.push(e)):n.push(t)}else break}}for(o>0&&(a=r,a.unshift(n.join(``)));o<e.length;o++){let t=e[o];t instanceof Symbol||a.push(t)}return a}:Qn,tr=(...e)=>{console.log(...er(e)),rr.forEach(t=>t.print(e))},nr=(...e)=>{console.warn(...er(e)),e.unshift(Xn),rr.forEach(t=>t.print(e))},rr=o(),ir=e=>({[Symbol.iterator](){return this},next:e}),ar=(e,t)=>ir(()=>{let n;do n=e.next();while(!n.done&&!t(n.value));return n}),or=(e,t)=>ir(()=>{let{done:n,value:r}=e.next();return{done:n,value:n?void 0:t(r)}});var sr=class{constructor(e,t){this.clock=e,this.len=t}},cr=class{constructor(){this.clients=new Map}};let lr=(e,t,n)=>t.clients.forEach((t,r)=>{let i=e.doc.store.clients.get(r);if(i!=null){let r=i[i.length-1],a=r.id.clock+r.length;for(let r=0,o=t[r];r<t.length&&o.clock<a;o=t[++r])bi(e,i,o.clock,o.len,n)}}),ur=(e,t)=>{let n=0,r=e.length-1;for(;n<=r;){let i=h((n+r)/2),a=e[i],o=a.clock;if(o<=t){if(t<o+a.len)return i;n=i+1}else r=i-1}return null},dr=(e,t)=>{let n=e.clients.get(t.client);return n!==void 0&&ur(n,t.clock)!==null},fr=e=>{e.clients.forEach(e=>{e.sort((e,t)=>e.clock-t.clock);let t,n;for(t=1,n=1;t<e.length;t++){let r=e[n-1],i=e[t];r.clock+r.len>=i.clock?e[n-1]=new sr(r.clock,v(r.len,i.clock+i.len-r.clock)):(n<t&&(e[n]=i),n++)}e.length=n})},pr=e=>{let t=new cr;for(let n=0;n<e.length;n++)e[n].clients.forEach((r,i)=>{if(!t.clients.has(i)){let a=r.slice();for(let t=n+1;t<e.length;t++)c(a,e[t].clients.get(i)||[]);t.clients.set(i,a)}});return fr(t),t},mr=(e,t,n,i)=>{r(e.clients,t,()=>[]).push(new sr(n,i))},hr=()=>new cr,gr=e=>{let t=hr();return e.clients.forEach((e,n)=>{let r=[];for(let t=0;t<e.length;t++){let n=e[t];if(n.deleted){let i=n.id.clock,a=n.length;if(t+1<e.length)for(let n=e[t+1];t+1<e.length&&n.deleted;n=e[++t+1])a+=n.length;r.push(new sr(i,a))}}r.length>0&&t.clients.set(n,r)}),t},_r=(e,t)=>{L(e.restEncoder,t.clients.size),l(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),L(e.restEncoder,t);let r=n.length;L(e.restEncoder,r);for(let t=0;t<r;t++){let r=n[t];e.writeDsClock(r.clock),e.writeDsLen(r.len)}})},vr=e=>{let t=new cr,n=z(e.restDecoder);for(let i=0;i<n;i++){e.resetDsCurVal();let n=z(e.restDecoder),i=z(e.restDecoder);if(i>0){let a=r(t.clients,n,()=>[]);for(let t=0;t<i;t++)a.push(new sr(e.readDsClock(),e.readDsLen()))}}return t},yr=(e,t,n)=>{let r=new cr,i=z(e.restDecoder);for(let a=0;a<i;a++){e.resetDsCurVal();let i=z(e.restDecoder),a=z(e.restDecoder),o=n.clients.get(i)||[],s=W(n,i);for(let n=0;n<a;n++){let n=e.readDsClock(),a=n+e.readDsLen();if(n<s){s<a&&mr(r,i,s,a-s);let e=hi(o,n),c=o[e];for(!c.deleted&&c.id.clock<n&&(o.splice(e+1,0,Mo(t,c,n-c.id.clock)),e++);e<o.length&&(c=o[e++],c.id.clock<a);)c.deleted||(a<c.id.clock+c.length&&o.splice(e,0,Mo(t,c,a-c.id.clock)),c.delete(t))}else mr(r,i,n,a-n)}}if(r.clients.size>0){let e=new kr;return L(e.restEncoder,0),_r(e,r),e.toUint8Array()}return null},br=Ue;var xr=class e extends m{constructor({guid:e=We(),collectionid:t=null,gc:n=!0,gcFilter:r=()=>!0,meta:i=null,autoLoad:a=!1,shouldLoad:o=!0}={}){super(),this.gc=n,this.gcFilter=r,this.clientID=br(),this.guid=e,this.collectionid=t,this.share=new Map,this.store=new fi,this._transaction=null,this._transactionCleanups=[],this.subdocs=new Set,this._item=null,this.shouldLoad=o,this.autoLoad=a,this.meta=i,this.isLoaded=!1,this.isSynced=!1,this.isDestroyed=!1,this.whenLoaded=Ke(e=>{this.on(`load`,()=>{this.isLoaded=!0,e(this)})});let s=()=>Ke(e=>{let t=n=>{(n===void 0||n===!0)&&(this.off(`sync`,t),e())};this.on(`sync`,t)});this.on(`sync`,e=>{e===!1&&this.isSynced&&(this.whenSynced=s()),this.isSynced=e===void 0||e===!0,this.isSynced&&!this.isLoaded&&this.emit(`load`,[this])}),this.whenSynced=s()}load(){let e=this._item;e!==null&&!this.shouldLoad&&K(e.parent.doc,e=>{e.subdocsLoaded.add(this)},null,!0),this.shouldLoad=!0}getSubdocs(){return this.subdocs}getSubdocGuids(){return new Set(l(this.subdocs).map(e=>e.guid))}transact(e,t=null){return K(this,e,t)}get(e,t=J){let n=r(this.share,e,()=>{let e=new t;return e._integrate(this,null),e}),i=n.constructor;if(t!==J&&i!==t){if(i===J){let r=new t;r._map=n._map,n._map.forEach(e=>{for(;e!==null;e=e.left)e.parent=r}),r._start=n._start;for(let e=r._start;e!==null;e=e.right)e.parent=r;return r._length=n._length,this.share.set(e,r),r._integrate(this,null),r}throw Error(`Type with the name ${e} has already been defined with a different constructor`)}return n}getArray(e=``){return this.get(e,Sa)}getText(e=``){return this.get(e,Ua)}getMap(e=``){return this.get(e,Ta)}getXmlElement(e=``){return this.get(e,Ja)}getXmlFragment(e=``){return this.get(e,Ka)}toJSON(){let e={};return this.share.forEach((t,n)=>{e[n]=t.toJSON()}),e}destroy(){this.isDestroyed=!0,l(this.subdocs).forEach(e=>e.destroy());let t=this._item;if(t!==null){this._item=null;let n=t.content;n.doc=new e({guid:this.guid,...n.opts,shouldLoad:!1}),n.doc._item=t,K(t.parent.doc,e=>{let r=n.doc;t.deleted||e.subdocsAdded.add(r),e.subdocsRemoved.add(this)},null,!0)}this.emit(`destroyed`,[!0]),this.emit(`destroy`,[this]),super.destroy()}},Sr=class{constructor(e){this.restDecoder=e}resetDsCurVal(){}readDsClock(){return z(this.restDecoder)}readDsLen(){return z(this.restDecoder)}},Cr=class extends Sr{readLeftID(){return U(z(this.restDecoder),z(this.restDecoder))}readRightID(){return U(z(this.restDecoder),z(this.restDecoder))}readClient(){return z(this.restDecoder)}readInfo(){return Me(this.restDecoder)}readString(){return Pe(this.restDecoder)}readParentInfo(){return z(this.restDecoder)===1}readTypeRef(){return z(this.restDecoder)}readLen(){return z(this.restDecoder)}readAny(){return Le(this.restDecoder)}readBuf(){return Ct(je(this.restDecoder))}readJSON(){return JSON.parse(Pe(this.restDecoder))}readKey(){return Pe(this.restDecoder)}},wr=class{constructor(e){this.dsCurrVal=0,this.restDecoder=e}resetDsCurVal(){this.dsCurrVal=0}readDsClock(){return this.dsCurrVal+=z(this.restDecoder),this.dsCurrVal}readDsLen(){let e=z(this.restDecoder)+1;return this.dsCurrVal+=e,e}},Tr=class extends wr{constructor(e){super(e),this.keys=[],z(e),this.keyClockDecoder=new Be(je(e)),this.clientDecoder=new ze(je(e)),this.leftClockDecoder=new Be(je(e)),this.rightClockDecoder=new Be(je(e)),this.infoDecoder=new Re(je(e),Me),this.stringDecoder=new Ve(je(e)),this.parentInfoDecoder=new Re(je(e),Me),this.typeRefDecoder=new ze(je(e)),this.lenDecoder=new ze(je(e))}readLeftID(){return new Qr(this.clientDecoder.read(),this.leftClockDecoder.read())}readRightID(){return new Qr(this.clientDecoder.read(),this.rightClockDecoder.read())}readClient(){return this.clientDecoder.read()}readInfo(){return this.infoDecoder.read()}readString(){return this.stringDecoder.read()}readParentInfo(){return this.parentInfoDecoder.read()===1}readTypeRef(){return this.typeRefDecoder.read()}readLen(){return this.lenDecoder.read()}readAny(){return Le(this.restDecoder)}readBuf(){return je(this.restDecoder)}readJSON(){return Le(this.restDecoder)}readKey(){let e=this.keyClockDecoder.read();if(e<this.keys.length)return this.keys[e];{let e=this.stringDecoder.read();return this.keys.push(e),e}}},Er=class{constructor(){this.restEncoder=te()}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){L(this.restEncoder,e)}writeDsLen(e){L(this.restEncoder,e)}},Dr=class extends Er{writeLeftID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeRightID(e){L(this.restEncoder,e.client),L(this.restEncoder,e.clock)}writeClient(e){L(this.restEncoder,e)}writeInfo(e){re(this.restEncoder,e)}writeString(e){se(this.restEncoder,e)}writeParentInfo(e){L(this.restEncoder,+!!e)}writeTypeRef(e){L(this.restEncoder,e)}writeLen(e){L(this.restEncoder,e)}writeAny(e){he(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){se(this.restEncoder,JSON.stringify(e))}writeKey(e){se(this.restEncoder,e)}},Or=class{constructor(){this.restEncoder=te(),this.dsCurrVal=0}toUint8Array(){return F(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,L(this.restEncoder,t)}writeDsLen(e){e===0&&we(),L(this.restEncoder,e-1),this.dsCurrVal+=e}},kr=class extends Or{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new be,this.clientEncoder=new ve,this.leftClockEncoder=new be,this.rightClockEncoder=new be,this.infoEncoder=new ge(re),this.stringEncoder=new xe,this.parentInfoEncoder=new ge(re),this.typeRefEncoder=new ve,this.lenEncoder=new ve}toUint8Array(){let e=te();return L(e,0),R(e,this.keyClockEncoder.toUint8Array()),R(e,this.clientEncoder.toUint8Array()),R(e,this.leftClockEncoder.toUint8Array()),R(e,this.rightClockEncoder.toUint8Array()),R(e,F(this.infoEncoder)),R(e,this.stringEncoder.toUint8Array()),R(e,F(this.parentInfoEncoder)),R(e,this.typeRefEncoder.toUint8Array()),R(e,this.lenEncoder.toUint8Array()),ce(e,F(this.restEncoder)),F(e)}writeLeftID(e){this.clientEncoder.write(e.client),this.leftClockEncoder.write(e.clock)}writeRightID(e){this.clientEncoder.write(e.client),this.rightClockEncoder.write(e.clock)}writeClient(e){this.clientEncoder.write(e)}writeInfo(e){this.infoEncoder.write(e)}writeString(e){this.stringEncoder.write(e)}writeParentInfo(e){this.parentInfoEncoder.write(+!!e)}writeTypeRef(e){this.typeRefEncoder.write(e)}writeLen(e){this.lenEncoder.write(e)}writeAny(e){he(this.restEncoder,e)}writeBuf(e){R(this.restEncoder,e)}writeJSON(e){he(this.restEncoder,e)}writeKey(e){let t=this.keyMap.get(e);t===void 0?(this.keyClockEncoder.write(this.keyClock++),this.stringEncoder.write(e)):this.keyClockEncoder.write(t)}};let Ar=(e,t,n,r)=>{r=v(r,t[0].id.clock);let i=hi(t,r);L(e.restEncoder,t.length-i),e.writeClient(n),L(e.restEncoder,r);let a=t[i];a.write(e,r-a.id.clock);for(let n=i+1;n<t.length;n++)t[n].write(e,0)},jr=(e,t,n)=>{let r=new Map;n.forEach((e,n)=>{W(t,n)>e&&r.set(n,e)}),pi(t).forEach((e,t)=>{n.has(t)||r.set(t,0)}),L(e.restEncoder,r.size),l(r.entries()).sort((e,t)=>t[0]-e[0]).forEach(([n,r])=>{Ar(e,t.clients.get(n),n,r)})},Mr=(e,n)=>{let r=t(),i=z(e.restDecoder);for(let t=0;t<i;t++){let t=z(e.restDecoder),i=Array(t),a=e.readClient(),o=z(e.restDecoder);r.set(a,{i:0,refs:i});for(let r=0;r<t;r++){let t=e.readInfo();switch(31&t){case 0:{let t=e.readLen();i[r]=new Y(U(a,o),t),o+=t;break}case 10:{let t=z(e.restDecoder);i[r]=new Lo(U(a,o),t),o+=t;break}default:{let s=!(t&192),c=new Z(U(a,o),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,s?e.readParentInfo()?n.get(e.readString()):e.readLeftID():null,s&&(t&32)==32?e.readString():null,Fo(e,t));i[r]=c,o+=c.length}}}}return r},Nr=(e,t,n)=>{let i=[],a=l(n.keys()).sort((e,t)=>e-t);if(a.length===0)return null;let o=()=>{if(a.length===0)return null;let e=n.get(a[a.length-1]);for(;e.refs.length===e.i;)if(a.pop(),a.length>0)e=n.get(a[a.length-1]);else return null;return e},s=o();if(s===null)return null;let c=new fi,u=new Map,d=(e,t)=>{let n=u.get(e);(n==null||n>t)&&u.set(e,t)},f=s.refs[s.i++],p=new Map,m=()=>{for(let e of i){let t=e.id.client,r=n.get(t);r?(r.i--,c.clients.set(t,r.refs.slice(r.i)),n.delete(t),r.i=0,r.refs=[]):c.clients.set(t,[e]),a=a.filter(e=>e!==t)}i.length=0};for(;;){if(f.constructor!==Lo){let a=r(p,f.id.client,()=>W(t,f.id.client))-f.id.clock;if(a<0)i.push(f),d(f.id.client,f.id.clock-1),m();else{let r=f.getMissing(e,t);if(r!==null){i.push(f);let e=n.get(r)||{refs:[],i:0};if(e.refs.length===e.i)d(r,W(t,r)),m();else{f=e.refs[e.i++];continue}}else(a===0||a<f.length)&&(f.integrate(e,a),p.set(f.id.client,f.id.clock+f.length))}}if(i.length>0)f=i.pop();else if(s!==null&&s.i<s.refs.length)f=s.refs[s.i++];else{if(s=o(),s===null)break;f=s.refs[s.i++]}}if(c.clients.size>0){let e=new kr;return jr(e,c,new Map),L(e.restEncoder,0),{missing:u,update:e.toUint8Array()}}return null},Pr=(e,t)=>jr(e,t.doc.store,t.beforeState),Fr=(e,t,n,r=new Tr(e))=>K(t,e=>{e.local=!1;let t=!1,n=e.doc,i=n.store,a=Mr(r,n),o=Nr(e,i,a),s=i.pendingStructs;if(s){for(let[e,n]of s.missing)if(n<W(i,e)){t=!0;break}if(o){for(let[e,t]of o.missing){let n=s.missing.get(e);(n==null||n>t)&&s.missing.set(e,t)}s.update=zi([s.update,o.update])}}else i.pendingStructs=o;let c=yr(r,e,i);if(i.pendingDs){let t=new Tr(Oe(i.pendingDs));z(t.restDecoder);let n=yr(t,e,i);i.pendingDs=c&&n?zi([c,n]):c||n}else i.pendingDs=c;if(t){let t=i.pendingStructs.update;i.pendingStructs=null,Ir(e.doc,t)}},n,!1),Ir=(e,t,n,r=Tr)=>{let i=Oe(t);Fr(i,e,n,new r(i))},Lr=(e,t,n)=>Ir(e,t,n,Cr),Rr=(e,t,n=new Map)=>{jr(e,t.store,n),_r(e,gr(t.store))},zr=(e,t=new Uint8Array([0]),n=new kr)=>{let r=Hr(t);Rr(n,e,r);let i=[n.toUint8Array()];if(e.store.pendingDs&&i.push(e.store.pendingDs),e.store.pendingStructs&&i.push(Bi(e.store.pendingStructs.update,t)),i.length>1){if(n.constructor===Dr)return Li(i.map((e,t)=>t===0?e:Gi(e)));if(n.constructor===kr)return zi(i)}return i[0]},Br=(e,t)=>zr(e,t,new Dr),Vr=e=>{let t=new Map,n=z(e.restDecoder);for(let r=0;r<n;r++){let n=z(e.restDecoder),r=z(e.restDecoder);t.set(n,r)}return t},Hr=e=>Vr(new Sr(Oe(e))),Ur=(e,t)=>(L(e.restEncoder,t.size),l(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{L(e.restEncoder,t),L(e.restEncoder,n)}),e),Wr=(e,t)=>Ur(e,pi(t.store)),Gr=(e,t=new Or)=>(e instanceof Map?Ur(t,e):Wr(t,e),t.toUint8Array()),Kr=e=>Gr(e,new Er);var qr=class{constructor(){this.l=[]}};let Jr=()=>new qr,Yr=(e,t)=>e.l.push(t),Xr=(e,t)=>{let n=e.l,r=n.length;e.l=n.filter(e=>t!==e),r===e.l.length&&console.error(`[yjs] Tried to remove event handler that doesn\'t exist.`)},Zr=(e,t,n)=>lt(e.l,[t,n]);var Qr=class{constructor(e,t){this.client=e,this.clock=t}};let $r=(e,t)=>e===t||e!==null&&t!==null&&e.client===t.client&&e.clock===t.clock,U=(e,t)=>new Qr(e,t),ei=e=>{for(let[t,n]of e.doc.share.entries())if(n===e)return t;throw we()},ti=(e,t)=>{for(;t!==null;){if(t.parent===e)return!0;t=t.parent._item}return!1};var ni=class{constructor(e,t,n,r=0){this.type=e,this.tname=t,this.item=n,this.assoc=r}},ri=class{constructor(e,t,n=0){this.type=e,this.index=t,this.assoc=n}};let ii=(e,t,n=0)=>new ri(e,t,n),ai=(e,t,n)=>{let r=null,i=null;return e._item===null?i=ei(e):r=U(e._item.id.client,e._item.id.clock),new ni(r,i,t,n)},oi=(e,t,n=0)=>{let r=e._start;if(n<0){if(t===0)return ai(e,null,n);t--}for(;r!==null;){if(!r.deleted&&r.countable){if(r.length>t)return ai(e,U(r.id.client,r.id.clock+t),n);t-=r.length}if(r.right===null&&n<0)return ai(e,r.lastId,n);r=r.right}return ai(e,null,n)},si=(e,t)=>{let n=gi(e,t);return{item:n,diff:t.clock-n.id.clock}},ci=(e,t,n=!0)=>{let r=t.store,i=e.item,a=e.type,o=e.tname,s=e.assoc,c=null,l=0;if(i!==null){if(W(r,i.client)<=i.clock)return null;let e=n?Ao(r,i):si(r,i),t=e.item;if(!(t instanceof Z))return null;if(c=t.parent,c._item===null||!c._item.deleted){l=t.deleted||!t.countable?0:e.diff+(s>=0?0:1);let n=t.left;for(;n!==null;)!n.deleted&&n.countable&&(l+=n.length),n=n.left}}else{if(o!==null)c=t.get(o);else if(a!==null){if(W(r,a.client)<=a.clock)return null;let{item:e}=n?Ao(r,a):{item:gi(r,a)};if(e instanceof Z&&e.content instanceof Oo)c=e.content.type;else return null}else throw we();l=s>=0?c._length:0}return ii(c,l,e.assoc)};var li=class{constructor(e,t){this.ds=e,this.sv=t}};((e,t)=>new li(e,t))(hr(),new Map);let ui=(e,t)=>t===void 0?!e.deleted:t.sv.has(e.id.client)&&(t.sv.get(e.id.client)||0)>e.id.clock&&!dr(t.ds,e.id),di=(e,t)=>{let n=r(e.meta,di,o),i=e.doc.store;n.has(t)||(t.sv.forEach((t,n)=>{t<W(i,n)&&G(e,U(n,t))}),lr(e,t.ds,e=>{}),n.add(t))};var fi=class{constructor(){this.clients=new Map,this.pendingStructs=null,this.pendingDs=null}};let pi=e=>{let t=new Map;return e.clients.forEach((e,n)=>{let r=e[e.length-1];t.set(n,r.id.clock+r.length)}),t},W=(e,t)=>{let n=e.clients.get(t);if(n===void 0)return 0;let r=n[n.length-1];return r.id.clock+r.length},mi=(e,t)=>{let n=e.clients.get(t.id.client);if(n===void 0)n=[],e.clients.set(t.id.client,n);else{let e=n[n.length-1];if(e.id.clock+e.length!==t.id.clock)throw we()}n.push(t)},hi=(e,t)=>{let n=0,r=e.length-1,i=e[r],a=i.id.clock;if(a===t)return r;let o=h(t/(a+i.length-1)*r);for(;n<=r;){if(i=e[o],a=i.id.clock,a<=t){if(t<a+i.length)return o;n=o+1}else r=o-1;o=h((n+r)/2)}throw we()},gi=(e,t)=>{let n=e.clients.get(t.client);return n[hi(n,t.clock)]},_i=(e,t,n)=>{let r=hi(t,n),i=t[r];return i.id.clock<n&&i instanceof Z?(t.splice(r+1,0,Mo(e,i,n-i.id.clock)),r+1):r},G=(e,t)=>{let n=e.doc.store.clients.get(t.client);return n[_i(e,n,t.clock)]},vi=(e,t,n)=>{let r=t.clients.get(n.client),i=hi(r,n.clock),a=r[i];return n.clock!==a.id.clock+a.length-1&&a.constructor!==Y&&r.splice(i+1,0,Mo(e,a,n.clock-a.id.clock+1)),a},yi=(e,t,n)=>{let r=e.clients.get(t.id.client);r[hi(r,t.id.clock)]=n},bi=(e,t,n,r,i)=>{if(r===0)return;let a=n+r,o=_i(e,t,n),s;do s=t[o++],a<s.id.clock+s.length&&_i(e,t,a),i(s);while(o<t.length&&t[o].id.clock<a)};var xi=class{constructor(e,t,n){this.doc=e,this.deleteSet=new cr,this.beforeState=pi(e.store),this.afterState=new Map,this.changed=new Map,this.changedParentTypes=new Map,this._mergeStructs=[],this.origin=t,this.meta=new Map,this.local=n,this.subdocsAdded=new Set,this.subdocsRemoved=new Set,this.subdocsLoaded=new Set,this._needFormattingCleanup=!1}};let Si=(e,t)=>t.deleteSet.clients.size===0&&!a(t.afterState,(e,n)=>t.beforeState.get(n)!==e)?!1:(fr(t.deleteSet),Pr(e,t),_r(e,t.deleteSet),!0),Ci=(e,t,n)=>{let i=t._item;(i===null||i.id.clock<(e.beforeState.get(i.id.client)||0)&&!i.deleted)&&r(e.changed,t,o).add(n)},wi=(e,t)=>{let n=e[t],r=e[t-1],i=t;for(;i>0;n=r,r=e[--i-1]){if(r.deleted===n.deleted&&r.constructor===n.constructor&&r.mergeWith(n)){n instanceof Z&&n.parentSub!==null&&n.parent._map.get(n.parentSub)===n&&n.parent._map.set(n.parentSub,r);continue}break}let a=t-i;return a&&e.splice(t+1-a,a),a},Ti=(e,t,n)=>{for(let[r,i]of e.clients.entries()){let e=t.clients.get(r);for(let r=i.length-1;r>=0;r--){let a=i[r],o=a.clock+a.len;for(let r=hi(e,a.clock),i=e[r];r<e.length&&i.id.clock<o;i=e[++r]){let i=e[r];if(a.clock+a.len<=i.id.clock)break;i instanceof Z&&i.deleted&&!i.keep&&n(i)&&i.gc(t,!1)}}}},Ei=(e,t)=>{e.clients.forEach((e,n)=>{let r=t.clients.get(n);for(let t=e.length-1;t>=0;t--){let n=e[t],i=_(r.length-1,1+hi(r,n.clock+n.len-1));for(let e=i,t=r[e];e>0&&t.id.clock>=n.clock;t=r[e])e-=1+wi(r,e)}})},Di=(e,t,n)=>{Ti(e,t,n),Ei(e,t)},Oi=(e,t)=>{if(t<e.length){let n=e[t],r=n.doc,i=r.store,a=n.deleteSet,o=n._mergeStructs;try{fr(a),n.afterState=pi(n.doc.store),r.emit(`beforeObserverCalls`,[n,r]);let e=[];n.changed.forEach((t,r)=>e.push(()=>{(r._item===null||!r._item.deleted)&&r._callObserver(n,t)})),e.push(()=>{n.changedParentTypes.forEach((t,r)=>{r._dEH.l.length>0&&(r._item===null||!r._item.deleted)&&(t=t.filter(e=>e.target._item===null||!e.target._item.deleted),t.forEach(e=>{e.currentTarget=r,e._path=null}),t.sort((e,t)=>e.path.length-t.path.length),e.push(()=>{Zr(r._dEH,t,n)}))}),e.push(()=>r.emit(`afterTransaction`,[n,r])),e.push(()=>{n._needFormattingCleanup&&Ba(n)})}),lt(e,[])}finally{r.gc&&Ti(a,i,r.gcFilter),Ei(a,i),n.afterState.forEach((e,t)=>{let r=n.beforeState.get(t)||0;if(r!==e){let e=i.clients.get(t),n=v(hi(e,r),1);for(let t=e.length-1;t>=n;)t-=1+wi(e,t)}});for(let e=o.length-1;e>=0;e--){let{client:t,clock:n}=o[e].id,r=i.clients.get(t),a=hi(r,n);a+1<r.length&&wi(r,a+1)>1||a>0&&wi(r,a)}if(!n.local&&n.afterState.get(r.clientID)!==n.beforeState.get(r.clientID)&&(tr(Xn,Un,`[yjs] `,Wn,Jn,`Changed the client-id because another client seems to be using it.`),r.clientID=br()),r.emit(`afterTransactionCleanup`,[n,r]),r._observers.has(`update`)){let e=new Dr;Si(e,n)&&r.emit(`update`,[e.toUint8Array(),n.origin,r,n])}if(r._observers.has(`updateV2`)){let e=new kr;Si(e,n)&&r.emit(`updateV2`,[e.toUint8Array(),n.origin,r,n])}let{subdocsAdded:s,subdocsLoaded:c,subdocsRemoved:l}=n;(s.size>0||l.size>0||c.size>0)&&(s.forEach(e=>{e.clientID=r.clientID,e.collectionid??=r.collectionid,r.subdocs.add(e)}),l.forEach(e=>r.subdocs.delete(e)),r.emit(`subdocs`,[{loaded:c,added:s,removed:l},r,n]),l.forEach(e=>e.destroy())),e.length<=t+1?(r._transactionCleanups=[],r.emit(`afterAllTransactions`,[r,e])):Oi(e,t+1)}}},K=(e,t,n=null,r=!0)=>{let i=e._transactionCleanups,a=!1,o=null;e._transaction===null&&(a=!0,e._transaction=new xi(e,n,r),i.push(e._transaction),i.length===1&&e.emit(`beforeAllTransactions`,[e]),e.emit(`beforeTransaction`,[e._transaction,e]));try{o=t(e._transaction)}finally{if(a){let t=e._transaction===i[0];e._transaction=null,t&&Oi(i,0)}}return o};var ki=class{constructor(e,t){this.insertions=t,this.deletions=e,this.meta=new Map}};let Ai=(e,t,n)=>{lr(e,n.deletions,n=>{n instanceof Z&&t.scope.some(t=>t===e.doc||ti(t,n))&&jo(n,!1)})},ji=(e,t,n)=>{let r=null,i=e.doc,a=e.scope;K(i,n=>{for(;t.length>0&&e.currStackItem===null;){let r=i.store,o=t.pop(),s=new Set,c=[],l=!1;lr(n,o.insertions,e=>{if(e instanceof Z){if(e.redone!==null){let{item:t,diff:i}=Ao(r,e.id);i>0&&(t=G(n,U(t.id.client,t.id.clock+i))),e=t}!e.deleted&&a.some(t=>t===n.doc||ti(t,e))&&c.push(e)}}),lr(n,o.deletions,e=>{e instanceof Z&&a.some(t=>t===n.doc||ti(t,e))&&!dr(o.insertions,e.id)&&s.add(e)}),s.forEach(t=>{l=Po(n,t,s,o.insertions,e.ignoreRemoteMapChanges,e)!==null||l});for(let t=c.length-1;t>=0;t--){let r=c[t];e.deleteFilter(r)&&(r.delete(n),l=!0)}e.currStackItem=l?o:null}n.changed.forEach((e,t)=>{e.has(null)&&t._searchMarker&&(t._searchMarker.length=0)}),r=n},e);let o=e.currStackItem;if(o!=null){let t=r.changedParentTypes;e.emit(`stack-item-popped`,[{stackItem:o,type:n,changedParentTypes:t,origin:e},e]),e.currStackItem=null}return o};var Mi=class extends m{constructor(e,{captureTimeout:t=500,captureTransaction:n=e=>!0,deleteFilter:r=()=>!0,trackedOrigins:i=new Set([null]),ignoreRemoteMapChanges:a=!1,doc:o=p(e)?e[0].doc:e instanceof xr?e:e.doc}={}){super(),this.scope=[],this.doc=o,this.addToScope(e),this.deleteFilter=r,i.add(this),this.trackedOrigins=i,this.captureTransaction=n,this.undoStack=[],this.redoStack=[],this.undoing=!1,this.redoing=!1,this.currStackItem=null,this.lastChange=0,this.ignoreRemoteMapChanges=a,this.captureTimeout=t,this.afterTransactionHandler=e=>{if(!this.captureTransaction(e)||!this.scope.some(t=>e.changedParentTypes.has(t)||t===this.doc)||!this.trackedOrigins.has(e.origin)&&(!e.origin||!this.trackedOrigins.has(e.origin.constructor)))return;let t=this.undoing,n=this.redoing,r=t?this.redoStack:this.undoStack;t?this.stopCapturing():n||this.clear(!1,!0);let i=new cr;e.afterState.forEach((t,n)=>{let r=e.beforeState.get(n)||0,a=t-r;a>0&&mr(i,n,r,a)});let a=Ge(),o=!1;if(this.lastChange>0&&a-this.lastChange<this.captureTimeout&&r.length>0&&!t&&!n){let t=r[r.length-1];t.deletions=pr([t.deletions,e.deleteSet]),t.insertions=pr([t.insertions,i])}else r.push(new ki(e.deleteSet,i)),o=!0;!t&&!n&&(this.lastChange=a),lr(e,e.deleteSet,t=>{t instanceof Z&&this.scope.some(n=>n===e.doc||ti(n,t))&&jo(t,!0)});let s=[{stackItem:r[r.length-1],origin:e.origin,type:t?`redo`:`undo`,changedParentTypes:e.changedParentTypes},this];o?this.emit(`stack-item-added`,s):this.emit(`stack-item-updated`,s)},this.destroy=this.destroy.bind(this),this.doc.on(`afterTransaction`,this.afterTransactionHandler),this.doc.on(`destroy`,this.destroy)}addToScope(e){let t=new Set(this.scope);e=p(e)?e:[e],e.forEach(e=>{t.has(e)||(t.add(e),(e instanceof J?e.doc!==this.doc:e!==this.doc)&&nr(`[yjs#509] Not same Y.Doc`),this.scope.push(e))})}addTrackedOrigin(e){this.trackedOrigins.add(e)}removeTrackedOrigin(e){this.trackedOrigins.delete(e)}clear(e=!0,t=!0){(e&&this.canUndo()||t&&this.canRedo())&&this.doc.transact(n=>{e&&(this.undoStack.forEach(e=>Ai(n,this,e)),this.undoStack=[]),t&&(this.redoStack.forEach(e=>Ai(n,this,e)),this.redoStack=[]),this.emit(`stack-cleared`,[{undoStackCleared:e,redoStackCleared:t}])})}stopCapturing(){this.lastChange=0}undo(){this.undoing=!0;let e;try{e=ji(this,this.undoStack,`undo`)}finally{this.undoing=!1}return e}redo(){this.redoing=!0;let e;try{e=ji(this,this.redoStack,`redo`)}finally{this.redoing=!1}return e}canUndo(){return this.undoStack.length>0}canRedo(){return this.redoStack.length>0}destroy(){this.trackedOrigins.delete(this),this.doc.off(`afterTransaction`,this.afterTransactionHandler),this.doc.off(`destroy`,this.destroy),super.destroy()}};function*Ni(e){let t=z(e.restDecoder);for(let n=0;n<t;n++){let t=z(e.restDecoder),n=e.readClient(),r=z(e.restDecoder);for(let i=0;i<t;i++){let t=e.readInfo();if(t===10){let t=z(e.restDecoder);yield new Lo(U(n,r),t),r+=t}else if(31&t){let i=!(t&192),a=new Z(U(n,r),null,(t&128)==128?e.readLeftID():null,null,(t&64)==64?e.readRightID():null,i?e.readParentInfo()?e.readString():e.readLeftID():null,i&&(t&32)==32?e.readString():null,Fo(e,t));yield a,r+=a.length}else{let t=e.readLen();yield new Y(U(n,r),t),r+=t}}}}var Pi=class{constructor(e,t){this.gen=Ni(e),this.curr=null,this.done=!1,this.filterSkips=t,this.next()}next(){do this.curr=this.gen.next().value||null;while(this.filterSkips&&this.curr!==null&&this.curr.constructor===Lo);return this.curr}};let Fi=(e,t=Tr)=>{let n=[],r=new t(Oe(e)),i=new Pi(r,!1);for(let e=i.curr;e!==null;e=i.next())n.push(e);return{structs:n,ds:vr(r)}};var Ii=class{constructor(e){this.currClient=0,this.startClock=0,this.written=0,this.encoder=e,this.clientStructs=[]}};let Li=e=>zi(e,Cr,Dr),Ri=(e,t)=>{if(e.constructor===Y){let{client:n,clock:r}=e.id;return new Y(U(n,r+t),e.length-t)}if(e.constructor===Lo){let{client:n,clock:r}=e.id;return new Lo(U(n,r+t),e.length-t)}{let n=e,{client:r,clock:i}=n.id;return new Z(U(r,i+t),null,U(r,i+t-1),null,n.rightOrigin,n.parent,n.parentSub,n.content.splice(t))}},zi=(e,t=Tr,n=kr)=>{if(e.length===1)return e[0];let r=e.map(e=>new t(Oe(e))),i=r.map(e=>new Pi(e,!0)),a=null,o=new n,s=new Ii(o);for(;i=i.filter(e=>e.curr!==null),i.sort((e,t)=>{if(e.curr.id.client===t.curr.id.client){let n=e.curr.id.clock-t.curr.id.clock;return n===0?e.curr.constructor===t.curr.constructor?0:e.curr.constructor===Lo?1:-1:n}return t.curr.id.client-e.curr.id.client}),i.length!==0;){let e=i[0],t=e.curr.id.client;if(a!==null){let n=e.curr,r=!1;for(;n!==null&&n.id.clock+n.length<=a.struct.id.clock+a.struct.length&&n.id.client>=a.struct.id.client;)n=e.next(),r=!0;if(n===null||n.id.client!==t||r&&n.id.clock>a.struct.id.clock+a.struct.length)continue;if(t!==a.struct.id.client)Hi(s,a.struct,a.offset),a={struct:n,offset:0},e.next();else if(a.struct.id.clock+a.struct.length<n.id.clock){if(a.struct.constructor===Lo)a.struct.length=n.id.clock+n.length-a.struct.id.clock;else{Hi(s,a.struct,a.offset);let e=n.id.clock-a.struct.id.clock-a.struct.length;a={struct:new Lo(U(t,a.struct.id.clock+a.struct.length),e),offset:0}}}else{let t=a.struct.id.clock+a.struct.length-n.id.clock;t>0&&(a.struct.constructor===Lo?a.struct.length-=t:n=Ri(n,t)),a.struct.mergeWith(n)||(Hi(s,a.struct,a.offset),a={struct:n,offset:0},e.next())}}else a={struct:e.curr,offset:0},e.next();for(let n=e.curr;n!==null&&n.id.client===t&&n.id.clock===a.struct.id.clock+a.struct.length&&n.constructor!==Lo;n=e.next())Hi(s,a.struct,a.offset),a={struct:n,offset:0}}a!==null&&(Hi(s,a.struct,a.offset),a=null),Ui(s);let c=r.map(e=>vr(e)),l=pr(c);return _r(o,l),o.toUint8Array()},Bi=(e,t,n=Tr,r=kr)=>{let i=Hr(t),a=new r,o=new Ii(a),s=new n(Oe(e)),c=new Pi(s,!1);for(;c.curr;){let e=c.curr,t=e.id.client,n=i.get(t)||0;if(c.curr.constructor===Lo){c.next();continue}if(e.id.clock+e.length>n)for(Hi(o,e,v(n-e.id.clock,0)),c.next();c.curr&&c.curr.id.client===t;)Hi(o,c.curr,0),c.next();else for(;c.curr&&c.curr.id.client===t&&c.curr.id.clock+c.curr.length<=n;)c.next()}Ui(o);let l=vr(s);return _r(a,l),a.toUint8Array()},Vi=e=>{e.written>0&&(e.clientStructs.push({written:e.written,restEncoder:F(e.encoder.restEncoder)}),e.encoder.restEncoder=te(),e.written=0)},Hi=(e,t,n)=>{e.written>0&&e.currClient!==t.id.client&&Vi(e),e.written===0&&(e.currClient=t.id.client,e.encoder.writeClient(t.id.client),L(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ui=e=>{Vi(e);let t=e.encoder.restEncoder;L(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];L(t,r.written),ce(t,r.restEncoder)}},Wi=(e,t,n,r)=>{let i=new n(Oe(e)),a=new Pi(i,!1),o=new r,s=new Ii(o);for(let e=a.curr;e!==null;e=a.next())Hi(s,t(e),0);Ui(s);let c=vr(i);return _r(o,c),o.toUint8Array()},Gi=e=>Wi(e,ut,Tr,Dr),Ki=`You must not compute changes after the event-handler fired.`;var qi=class{constructor(e,t){this.target=e,this.currentTarget=e,this.transaction=t,this._changes=null,this._keys=null,this._delta=null,this._path=null}get path(){return this._path||=Ji(this.currentTarget,this.target)}deletes(e){return dr(this.transaction.deleteSet,e.id)}get keys(){if(this._keys===null){if(this.transaction.doc._transactionCleanups.length===0)throw Se(Ki);let e=new Map,t=this.target;this.transaction.changed.get(t).forEach(n=>{if(n!==null){let r=t._map.get(n),i,a;if(this.adds(r)){let e=r.left;for(;e!==null&&this.adds(e);)e=e.left;if(this.deletes(r)){if(e!==null&&this.deletes(e))i=`delete`,a=s(e.content.getContent());else return}else e!==null&&this.deletes(e)?(i=`update`,a=s(e.content.getContent())):(i=`add`,a=void 0)}else if(this.deletes(r))i=`delete`,a=s(r.content.getContent());else return;e.set(n,{action:i,oldValue:a})}}),this._keys=e}return this._keys}get delta(){return this.changes.delta}adds(e){return e.id.clock>=(this.transaction.beforeState.get(e.id.client)||0)}get changes(){let e=this._changes;if(e===null){if(this.transaction.doc._transactionCleanups.length===0)throw Se(Ki);let t=this.target,n=o(),r=o(),i=[];if(e={added:n,deleted:r,delta:i,keys:this.keys},this.transaction.changed.get(t).has(null)){let e=null,a=()=>{e&&i.push(e)};for(let i=t._start;i!==null;i=i.right)i.deleted?this.deletes(i)&&!this.adds(i)&&((e===null||e.delete===void 0)&&(a(),e={delete:0}),e.delete+=i.length,r.add(i)):this.adds(i)?((e===null||e.insert===void 0)&&(a(),e={insert:[]}),e.insert=e.insert.concat(i.content.getContent()),n.add(i)):((e===null||e.retain===void 0)&&(a(),e={retain:0}),e.retain+=i.length);e!==null&&e.retain===void 0&&a()}this._changes=e}return e}};let Ji=(e,t)=>{let n=[];for(;t._item!==null&&t!==e;){if(t._item.parentSub!==null)n.unshift(t._item.parentSub);else{let e=0,r=t._item.parent._start;for(;r!==t._item&&r!==null;)!r.deleted&&r.countable&&(e+=r.length),r=r.right;n.unshift(e)}t=t._item.parent}return n},q=()=>{nr(`Invalid access: Add Yjs type to a document before reading data.`)},Yi=0;var Xi=class{constructor(e,t){e.marker=!0,this.p=e,this.index=t,this.timestamp=Yi++}};let Zi=e=>{e.timestamp=Yi++},Qi=(e,t,n)=>{e.p.marker=!1,e.p=t,t.marker=!0,e.index=n,e.timestamp=Yi++},$i=(e,t,n)=>{if(e.length>=80){let r=e.reduce((e,t)=>e.timestamp<t.timestamp?e:t);return Qi(r,t,n),r}{let r=new Xi(t,n);return e.push(r),r}},ea=(e,t)=>{if(e._start===null||t===0||e._searchMarker===null)return null;let n=e._searchMarker.length===0?null:e._searchMarker.reduce((e,n)=>g(t-e.index)<g(t-n.index)?e:n),r=e._start,i=0;for(n!==null&&(r=n.p,i=n.index,Zi(n));r.right!==null&&i<t;){if(!r.deleted&&r.countable){if(t<i+r.length)break;i+=r.length}r=r.right}for(;r.left!==null&&i>t;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);for(;r.left!==null&&r.left.id.client===r.id.client&&r.left.id.clock+r.left.length===r.id.clock;)r=r.left,!r.deleted&&r.countable&&(i-=r.length);return n!==null&&g(n.index-i)<r.parent.length/80?(Qi(n,r,i),n):$i(e._searchMarker,r,i)},ta=(e,t,n)=>{for(let r=e.length-1;r>=0;r--){let i=e[r];if(n>0){let t=i.p;for(t.marker=!1;t&&(t.deleted||!t.countable);)t=t.left,t&&!t.deleted&&t.countable&&(i.index-=t.length);if(t===null||t.marker===!0){e.splice(r,1);continue}i.p=t,t.marker=!0}(t<i.index||n>0&&t===i.index)&&(i.index=v(t,i.index+n))}},na=(e,t,n)=>{let i=e,a=t.changedParentTypes;for(;r(a,e,()=>[]).push(n),e._item!==null;)e=e._item.parent;Zr(i._eH,n,t)};var J=class{constructor(){this._item=null,this._map=new Map,this._start=null,this.doc=null,this._length=0,this._eH=Jr(),this._dEH=Jr(),this._searchMarker=null}get parent(){return this._item?this._item.parent:null}_integrate(e,t){this.doc=e,this._item=t}_copy(){throw Ce()}clone(){throw Ce()}_write(e){}get _first(){let e=this._start;for(;e!==null&&e.deleted;)e=e.right;return e}_callObserver(e,t){!e.local&&this._searchMarker&&(this._searchMarker.length=0)}observe(e){Yr(this._eH,e)}observeDeep(e){Yr(this._dEH,e)}unobserve(e){Xr(this._eH,e)}unobserveDeep(e){Xr(this._dEH,e)}toJSON(){}};let ra=(e,t,n)=>{e.doc??q(),t<0&&(t=e._length+t),n<0&&(n=e._length+n);let r=n-t,i=[],a=e._start;for(;a!==null&&r>0;){if(a.countable&&!a.deleted){let e=a.content.getContent();if(e.length<=t)t-=e.length;else{for(let n=t;n<e.length&&r>0;n++)i.push(e[n]),r--;t=0}}a=a.right}return i},ia=e=>{e.doc??q();let t=[],n=e._start;for(;n!==null;){if(n.countable&&!n.deleted){let e=n.content.getContent();for(let n=0;n<e.length;n++)t.push(e[n])}n=n.right}return t},aa=(e,t)=>{let n=0,r=e._start;for(e.doc??q();r!==null;){if(r.countable&&!r.deleted){let i=r.content.getContent();for(let r=0;r<i.length;r++)t(i[r],n++,e)}r=r.right}},oa=(e,t)=>{let n=[];return aa(e,(r,i)=>{n.push(t(r,i,e))}),n},sa=e=>{let t=e._start,n=null,r=0;return{[Symbol.iterator](){return this},next:()=>{if(n===null){for(;t!==null&&t.deleted;)t=t.right;if(t===null)return{done:!0,value:void 0};n=t.content.getContent(),r=0,t=t.right}let e=n[r++];return n.length<=r&&(n=null),{done:!1,value:e}}}},ca=(e,t)=>{e.doc??q();let n=ea(e,t),r=e._start;for(n!==null&&(r=n.p,t-=n.index);r!==null;r=r.right)if(!r.deleted&&r.countable){if(t<r.length)return r.content.getContent()[t];t-=r.length}},la=(e,t,n,r)=>{let i=n,a=e.doc,o=a.clientID,s=a.store,c=n===null?t._start:n.right,l=[],u=()=>{l.length>0&&(i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new go(l)),i.integrate(e,0),l=[])};r.forEach(n=>{if(n===null)l.push(n);else switch(n.constructor){case Number:case Object:case Boolean:case Array:case String:l.push(n);break;default:switch(u(),n.constructor){case Uint8Array:case ArrayBuffer:i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new no(new Uint8Array(n))),i.integrate(e,0);break;case xr:i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new so(n)),i.integrate(e,0);break;default:if(n instanceof J)i=new Z(U(o,W(s,o)),i,i&&i.lastId,c,c&&c.id,t,null,new Oo(n)),i.integrate(e,0);else throw Error(`Unexpected content type in insert operation`)}}}),u()},ua=()=>Se(`Length exceeded!`),da=(e,t,n,r)=>{if(n>t._length)throw ua();if(n===0)return t._searchMarker&&ta(t._searchMarker,n,r.length),la(e,t,null,r);let i=n,a=ea(t,n),o=t._start;for(a!==null&&(o=a.p,n-=a.index,n===0&&(o=o.prev,n+=o&&o.countable&&!o.deleted?o.length:0));o!==null;o=o.right)if(!o.deleted&&o.countable){if(n<=o.length){n<o.length&&G(e,U(o.id.client,o.id.clock+n));break}n-=o.length}return t._searchMarker&&ta(t._searchMarker,i,r.length),la(e,t,o,r)},fa=(e,t,n)=>{let r=(t._searchMarker||[]).reduce((e,t)=>t.index>e.index?t:e,{index:0,p:t._start}).p;if(r)for(;r.right;)r=r.right;return la(e,t,r,n)},pa=(e,t,n,r)=>{if(r===0)return;let i=n,a=r,o=ea(t,n),s=t._start;for(o!==null&&(s=o.p,n-=o.index);s!==null&&n>0;s=s.right)!s.deleted&&s.countable&&(n<s.length&&G(e,U(s.id.client,s.id.clock+n)),n-=s.length);for(;r>0&&s!==null;)s.deleted||(r<s.length&&G(e,U(s.id.client,s.id.clock+r)),s.delete(e),r-=s.length),s=s.right;if(r>0)throw ua();t._searchMarker&&ta(t._searchMarker,i,-a+r)},ma=(e,t,n)=>{let r=t._map.get(n);r!==void 0&&r.delete(e)},ha=(e,t,n,r)=>{let i=t._map.get(n)||null,a=e.doc,o=a.clientID,s;if(r==null)s=new go([r]);else switch(r.constructor){case Number:case Object:case Boolean:case Array:case String:case Date:case BigInt:s=new go([r]);break;case Uint8Array:s=new no(r);break;case xr:s=new so(r);break;default:if(r instanceof J)s=new Oo(r);else throw Error(`Unexpected content type`)}new Z(U(o,W(a.store,o)),i,i&&i.lastId,null,null,t,n,s).integrate(e,0)},ga=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted?n.content.getContent()[n.length-1]:void 0},_a=e=>{let t={};return e.doc??q(),e._map.forEach((e,n)=>{e.deleted||(t[n]=e.content.getContent()[e.length-1])}),t},va=(e,t)=>{e.doc??q();let n=e._map.get(t);return n!==void 0&&!n.deleted},ya=(e,t)=>{let n={};return e._map.forEach((e,r)=>{let i=e;for(;i!==null&&(!t.sv.has(i.id.client)||i.id.clock>=(t.sv.get(i.id.client)||0));)i=i.left;i!==null&&ui(i,t)&&(n[r]=i.content.getContent()[i.length-1])}),n},ba=e=>(e.doc??q(),ar(e._map.entries(),e=>!e[1].deleted));var xa=class extends qi{},Sa=class e extends J{constructor(){super(),this._prelimContent=[],this._searchMarker=[]}static from(t){let n=new e;return n.push(t),n}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._length}_callObserver(e,t){super._callObserver(e,t),na(this,e,new xa(this,e))}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{da(n,this,e,t)})}push(e){this.doc===null?this._prelimContent.push(...e):K(this.doc,t=>{fa(t,this,e)})}unshift(e){this.insert(0,e)}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{pa(n,this,e,t)})}get(e){return ca(this,e)}toArray(){return ia(this)}slice(e=0,t=this.length){return ra(this,e,t)}toJSON(){return this.map(e=>e instanceof J?e.toJSON():e)}map(e){return oa(this,e)}forEach(e){aa(this,e)}[Symbol.iterator](){return sa(this)}_write(e){e.writeTypeRef(xo)}};let Ca=e=>new Sa;var wa=class extends qi{constructor(e,t,n){super(e,t),this.keysChanged=n}},Ta=class e extends J{constructor(e){super(),this._prelimContent=null,this._prelimContent=e===void 0?new Map:new Map(e)}_integrate(e,t){super._integrate(e,t),this._prelimContent.forEach((e,t)=>{this.set(t,e)}),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return this.forEach((e,n)=>{t.set(n,e instanceof J?e.clone():e)}),t}_callObserver(e,t){na(this,e,new wa(this,e,t))}toJSON(){this.doc??q();let e={};return this._map.forEach((t,n)=>{if(!t.deleted){let r=t.content.getContent()[t.length-1];e[n]=r instanceof J?r.toJSON():r}}),e}get size(){return[...ba(this)].length}keys(){return or(ba(this),e=>e[0])}values(){return or(ba(this),e=>e[1].content.getContent()[e[1].length-1])}entries(){return or(ba(this),e=>[e[0],e[1].content.getContent()[e[1].length-1]])}forEach(e){this.doc??q(),this._map.forEach((t,n)=>{t.deleted||e(t.content.getContent()[t.length-1],n,this)})}[Symbol.iterator](){return this.entries()}delete(e){this.doc===null?this._prelimContent.delete(e):K(this.doc,t=>{ma(t,this,e)})}set(e,t){return this.doc===null?this._prelimContent.set(e,t):K(this.doc,n=>{ha(n,this,e,t)}),t}get(e){return ga(this,e)}has(e){return va(this,e)}clear(){this.doc===null?this._prelimContent.clear():K(this.doc,e=>{this.forEach(function(t,n,r){ma(e,r,n)})})}_write(e){e.writeTypeRef(So)}};let Ea=e=>new Ta,Da=(e,t)=>e===t||typeof e==`object`&&typeof t==`object`&&e&&t&&ot(e,t);var Oa=class{constructor(e,t,n,r){this.left=e,this.right=t,this.index=n,this.currentAttributes=r}forward(){switch(this.right===null&&we(),this.right.content.constructor){case X:this.right.deleted||Ma(this.currentAttributes,this.right.content);break;default:this.right.deleted||(this.index+=this.right.length)}this.left=this.right,this.right=this.right.right}};let ka=(e,t,n)=>{for(;t.right!==null&&n>0;){switch(t.right.content.constructor){case X:t.right.deleted||Ma(t.currentAttributes,t.right.content);break;default:t.right.deleted||(n<t.right.length&&G(e,U(t.right.id.client,t.right.id.clock+n)),t.index+=t.right.length,n-=t.right.length)}t.left=t.right,t.right=t.right.right}return t},Aa=(e,t,n,r)=>{let i=new Map,a=r?ea(t,n):null;if(a){let t=new Oa(a.p.left,a.p,a.index,i);return ka(e,t,n-a.index)}{let r=new Oa(null,t._start,0,i);return ka(e,r,n)}},ja=(e,t,n,r)=>{for(;n.right!==null&&(n.right.deleted===!0||n.right.content.constructor===X&&Da(r.get(n.right.content.key),n.right.content.value));)n.right.deleted||r.delete(n.right.content.key),n.forward();let i=e.doc,a=i.clientID;r.forEach((r,o)=>{let s=n.left,c=n.right,l=new Z(U(a,W(i.store,a)),s,s&&s.lastId,c,c&&c.id,t,null,new X(o,r));l.integrate(e,0),n.right=l,n.forward()})},Ma=(e,t)=>{let{key:n,value:r}=t;r===null?e.delete(n):e.set(n,r)},Na=(e,t)=>{for(;e.right!==null&&(e.right.deleted||e.right.content.constructor===X&&Da(t[e.right.content.key]??null,e.right.content.value));)e.forward()},Pa=(e,t,n,r)=>{let i=e.doc,a=i.clientID,o=new Map;for(let s in r){let c=r[s],l=n.currentAttributes.get(s)??null;if(!Da(l,c)){o.set(s,l);let{left:r,right:u}=n;n.right=new Z(U(a,W(i.store,a)),r,r&&r.lastId,u,u&&u.id,t,null,new X(s,c)),n.right.integrate(e,0),n.forward()}}return o},Fa=(e,t,n,r,i)=>{n.currentAttributes.forEach((e,t)=>{i[t]===void 0&&(i[t]=null)});let a=e.doc,o=a.clientID;Na(n,i);let s=Pa(e,t,n,i),c=r.constructor===String?new vo(r):r instanceof J?new Oo(r):new lo(r),{left:l,right:u,index:d}=n;t._searchMarker&&ta(t._searchMarker,n.index,c.getLength()),u=new Z(U(o,W(a.store,o)),l,l&&l.lastId,u,u&&u.id,t,null,c),u.integrate(e,0),n.right=u,n.index=d,n.forward(),ja(e,t,n,s)},Ia=(e,t,n,r,i)=>{let a=e.doc,o=a.clientID;Na(n,i);let s=Pa(e,t,n,i);iterationLoop:for(;n.right!==null&&(r>0||s.size>0&&(n.right.deleted||n.right.content.constructor===X));){if(!n.right.deleted)switch(n.right.content.constructor){case X:{let{key:t,value:a}=n.right.content,o=i[t];if(o!==void 0){if(Da(o,a))s.delete(t);else{if(r===0)break iterationLoop;s.set(t,a)}n.right.delete(e)}else n.currentAttributes.set(t,a);break}default:r<n.right.length&&G(e,U(n.right.id.client,n.right.id.clock+r)),r-=n.right.length}n.forward()}if(r>0){let i=``;for(;r>0;r--)i+=`\n`;n.right=new Z(U(o,W(a.store,o)),n.left,n.left&&n.left.lastId,n.right,n.right&&n.right.id,t,null,new vo(i)),n.right.integrate(e,0),n.forward()}ja(e,t,n,s)},La=(e,n,r,i,a)=>{let o=n,s=t();for(;o&&(!o.countable||o.deleted);){if(!o.deleted&&o.content.constructor===X){let e=o.content;s.set(e.key,e)}o=o.right}let c=0,l=!1;for(;n!==o;){if(r===n&&(l=!0),!n.deleted){let t=n.content;switch(t.constructor){case X:{let{key:r,value:o}=t,u=i.get(r)??null;(s.get(r)!==t||u===o)&&(n.delete(e),c++,!l&&(a.get(r)??null)===o&&u!==o&&(u===null?a.delete(r):a.set(r,u))),!l&&!n.deleted&&Ma(a,t);break}}}n=n.right}return c},Ra=(e,t)=>{for(;t&&t.right&&(t.right.deleted||!t.right.countable);)t=t.right;let n=new Set;for(;t&&(t.deleted||!t.countable);){if(!t.deleted&&t.content.constructor===X){let r=t.content.key;n.has(r)?t.delete(e):n.add(r)}t=t.left}},za=e=>{let r=0;return K(e.doc,i=>{let a=e._start,o=e._start,s=t(),c=n(s);for(;o;){if(o.deleted===!1)switch(o.content.constructor){case X:Ma(c,o.content);break;default:r+=La(i,a,o,s,c),s=n(c),a=o}o=o.right}}),r},Ba=e=>{let t=new Set,n=e.doc;for(let[r,i]of e.afterState.entries()){let a=e.beforeState.get(r)||0;i!==a&&bi(e,n.store.clients.get(r),a,i,e=>{!e.deleted&&e.content.constructor===X&&e.constructor!==Y&&t.add(e.parent)})}K(n,n=>{lr(e,e.deleteSet,e=>{if(e instanceof Y||!e.parent._hasFormatting||t.has(e.parent))return;let r=e.parent;e.content.constructor===X?t.add(r):Ra(n,e)});for(let e of t)za(e)})},Va=(e,t,r)=>{let i=r,a=n(t.currentAttributes),o=t.right;for(;r>0&&t.right!==null;){if(t.right.deleted===!1)switch(t.right.content.constructor){case Oo:case lo:case vo:r<t.right.length&&G(e,U(t.right.id.client,t.right.id.clock+r)),r-=t.right.length,t.right.delete(e)}t.forward()}o&&La(e,o,t.right,a,t.currentAttributes);let s=(t.left||t.right).parent;return s._searchMarker&&ta(s._searchMarker,t.index,-i+r),t};var Ha=class extends qi{constructor(e,t,n){super(e,t),this.childListChanged=!1,this.keysChanged=new Set,n.forEach(e=>{e===null?this.childListChanged=!0:this.keysChanged.add(e)})}get changes(){if(this._changes===null){let e={keys:this.keys,delta:this.delta,added:new Set,deleted:new Set};this._changes=e}return this._changes}get delta(){if(this._delta===null){let e=this.target.doc,t=[];K(e,e=>{let n=new Map,r=new Map,i=this.target._start,a=null,o={},s=``,c=0,l=0,u=()=>{if(a!==null){let e=null;switch(a){case`delete`:l>0&&(e={delete:l}),l=0;break;case`insert`:(typeof s==`object`||s.length>0)&&(e={insert:s},n.size>0&&(e.attributes={},n.forEach((t,n)=>{t!==null&&(e.attributes[n]=t)}))),s=``;break;case`retain`:c>0&&(e={retain:c},rt(o)||(e.attributes=$e({},o))),c=0}e&&t.push(e),a=null}};for(;i!==null;){switch(i.content.constructor){case Oo:case lo:this.adds(i)?this.deletes(i)||(u(),a=`insert`,s=i.content.getContent()[0],u()):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=1):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=1);break;case vo:this.adds(i)?this.deletes(i)||(a!==`insert`&&(u(),a=`insert`),s+=i.content.str):this.deletes(i)?(a!==`delete`&&(u(),a=`delete`),l+=i.length):i.deleted||(a!==`retain`&&(u(),a=`retain`),c+=i.length);break;case X:{let{key:t,value:s}=i.content;if(this.adds(i)){if(!this.deletes(i)){let c=n.get(t)??null;Da(c,s)?s!==null&&i.delete(e):(a===`retain`&&u(),Da(s,r.get(t)??null)?delete o[t]:o[t]=s)}}else if(this.deletes(i)){r.set(t,s);let e=n.get(t)??null;Da(e,s)||(a===`retain`&&u(),o[t]=e)}else if(!i.deleted){r.set(t,s);let n=o[t];n!==void 0&&(Da(n,s)?n!==null&&i.delete(e):(a===`retain`&&u(),s===null?delete o[t]:o[t]=s))}i.deleted||(a===`insert`&&u(),Ma(n,i.content));break}}i=i.right}for(u();t.length>0;){let e=t[t.length-1];if(e.retain!==void 0&&e.attributes===void 0)t.pop();else break}}),this._delta=t}return this._delta}},Ua=class e extends J{constructor(e){super(),this._pending=e===void 0?[]:[()=>this.insert(0,e)],this._searchMarker=[],this._hasFormatting=!1}get length(){return this.doc??q(),this._length}_integrate(e,t){super._integrate(e,t);try{this._pending.forEach(e=>e())}catch(e){console.error(e)}this._pending=null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}_callObserver(e,t){super._callObserver(e,t);let n=new Ha(this,e,t);na(this,e,n),!e.local&&this._hasFormatting&&(e._needFormattingCleanup=!0)}toString(){this.doc??q();let e=``,t=this._start;for(;t!==null;)!t.deleted&&t.countable&&t.content.constructor===vo&&(e+=t.content.str),t=t.right;return e}toJSON(){return this.toString()}applyDelta(e,{sanitize:t=!0}={}){this.doc===null?this._pending.push(()=>this.applyDelta(e)):K(this.doc,n=>{let r=new Oa(null,this._start,0,new Map);for(let i=0;i<e.length;i++){let a=e[i];if(a.insert!==void 0){let o=!t&&typeof a.insert==`string`&&i===e.length-1&&r.right===null&&a.insert.slice(-1)===`\n`?a.insert.slice(0,-1):a.insert;(typeof o!=`string`||o.length>0)&&Fa(n,this,r,o,a.attributes||{})}else a.retain===void 0?a.delete!==void 0&&Va(n,r,a.delete):Ia(n,this,r,a.retain,a.attributes||{})}})}toDelta(e,t,n){this.doc??q();let r=[],i=new Map,a=this.doc,o=``,s=this._start;function c(){if(o.length>0){let e={},t=!1;i.forEach((n,r)=>{t=!0,e[r]=n});let n={insert:o};t&&(n.attributes=e),r.push(n),o=``}}let l=()=>{for(;s!==null;){if(ui(s,e)||t!==void 0&&ui(s,t))switch(s.content.constructor){case vo:{let r=i.get(`ychange`);e!==void 0&&!ui(s,e)?(r===void 0||r.user!==s.id.client||r.type!==`removed`)&&(c(),i.set(`ychange`,n?n(`removed`,s.id):{type:`removed`})):t!==void 0&&!ui(s,t)?(r===void 0||r.user!==s.id.client||r.type!==`added`)&&(c(),i.set(`ychange`,n?n(`added`,s.id):{type:`added`})):r!==void 0&&(c(),i.delete(`ychange`)),o+=s.content.str;break}case Oo:case lo:{c();let e={insert:s.content.getContent()[0]};if(i.size>0){let t={};e.attributes=t,i.forEach((e,n)=>{t[n]=e})}r.push(e);break}case X:ui(s,e)&&(c(),Ma(i,s.content))}s=s.right}c()};return e||t?K(a,n=>{e&&di(n,e),t&&di(n,t),l()},`cleanup`):l(),r}insert(e,t,n){if(t.length<=0)return;let r=this.doc;r===null?this._pending.push(()=>this.insert(e,t,n)):K(r,r=>{let i=Aa(r,this,e,!n);n||(n={},i.currentAttributes.forEach((e,t)=>{n[t]=e})),Fa(r,this,i,t,n)})}insertEmbed(e,t,n){let r=this.doc;r===null?this._pending.push(()=>this.insertEmbed(e,t,n||{})):K(r,r=>{let i=Aa(r,this,e,!n);Fa(r,this,i,t,n||{})})}delete(e,t){if(t===0)return;let n=this.doc;n===null?this._pending.push(()=>this.delete(e,t)):K(n,n=>{Va(n,Aa(n,this,e,!0),t)})}format(e,t,n){if(t===0)return;let r=this.doc;r===null?this._pending.push(()=>this.format(e,t,n)):K(r,r=>{let i=Aa(r,this,e,!1);i.right!==null&&Ia(r,this,i,t,n)})}removeAttribute(e){this.doc===null?this._pending.push(()=>this.removeAttribute(e)):K(this.doc,t=>{ma(t,this,e)})}setAttribute(e,t){this.doc===null?this._pending.push(()=>this.setAttribute(e,t)):K(this.doc,n=>{ha(n,this,e,t)})}getAttribute(e){return ga(this,e)}getAttributes(){return _a(this)}_write(e){e.writeTypeRef(Co)}};let Wa=e=>new Ua;var Ga=class{constructor(e,t=()=>!0){this._filter=t,this._root=e,this._currentNode=e._start,this._firstCall=!0,e.doc??q()}[Symbol.iterator](){return this}next(){let e=this._currentNode,t=e&&e.content&&e.content.type;if(e!==null&&(!this._firstCall||e.deleted||!this._filter(t)))do if(t=e.content.type,!e.deleted&&(t.constructor===Ja||t.constructor===Ka)&&t._start!==null)e=t._start;else for(;e!==null;){let t=e.next;if(t!==null){e=t;break}e=e.parent===this._root?null:e.parent._item}while(e!==null&&(e.deleted||!this._filter(e.content.type)));return this._firstCall=!1,e===null?{value:void 0,done:!0}:(this._currentNode=e,{value:e.content.type,done:!1})}},Ka=class e extends J{constructor(){super(),this._prelimContent=[]}get firstChild(){let e=this._first;return e?e.content.getContent()[0]:null}_integrate(e,t){super._integrate(e,t),this.insert(0,this._prelimContent),this._prelimContent=null}_copy(){return new e}clone(){let t=new e;return t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}get length(){return this.doc??q(),this._prelimContent===null?this._length:this._prelimContent.length}createTreeWalker(e){return new Ga(this,e)}querySelector(e){e=e.toUpperCase();let t=new Ga(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e).next();return t.done?null:t.value}querySelectorAll(e){return e=e.toUpperCase(),l(new Ga(this,t=>t.nodeName&&t.nodeName.toUpperCase()===e))}_callObserver(e,t){na(this,e,new Xa(this,t,e))}toString(){return oa(this,e=>e.toString()).join(``)}toJSON(){return this.toString()}toDOM(e=document,t={},n){let r=e.createDocumentFragment();return n!==void 0&&n._createAssociation(r,this),aa(this,i=>{r.insertBefore(i.toDOM(e,t,n),null)}),r}insert(e,t){this.doc===null?this._prelimContent.splice(e,0,...t):K(this.doc,n=>{da(n,this,e,t)})}insertAfter(e,t){if(this.doc!==null)K(this.doc,n=>{let r=e&&e instanceof J?e._item:e;la(n,this,r,t)});else{let n=this._prelimContent,r=e===null?0:n.findIndex(t=>t===e)+1;if(r===0&&e!==null)throw Se(`Reference item not found`);n.splice(r,0,...t)}}delete(e,t=1){this.doc===null?this._prelimContent.splice(e,t):K(this.doc,n=>{pa(n,this,e,t)})}toArray(){return ia(this)}push(e){this.insert(this.length,e)}unshift(e){this.insert(0,e)}get(e){return ca(this,e)}slice(e=0,t=this.length){return ra(this,e,t)}forEach(e){aa(this,e)}_write(e){e.writeTypeRef(To)}};let qa=e=>new Ka;var Ja=class e extends Ka{constructor(e=`UNDEFINED`){super(),this.nodeName=e,this._prelimAttrs=new Map}get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_integrate(e,t){super._integrate(e,t),this._prelimAttrs.forEach((e,t)=>{this.setAttribute(t,e)}),this._prelimAttrs=null}_copy(){return new e(this.nodeName)}clone(){let t=new e(this.nodeName),n=this.getAttributes();return tt(n,(e,n)=>{t.setAttribute(n,e)}),t.insert(0,this.toArray().map(e=>e instanceof J?e.clone():e)),t}toString(){let e=this.getAttributes(),t=[],n=[];for(let t in e)n.push(t);n.sort();let r=n.length;for(let i=0;i<r;i++){let r=n[i];t.push(r+`="`+e[r]+`"`)}let i=this.nodeName.toLocaleLowerCase();return`<${i}${t.length>0?` `+t.join(` `):``}>${super.toString()}</${i}>`}removeAttribute(e){this.doc===null?this._prelimAttrs.delete(e):K(this.doc,t=>{ma(t,this,e)})}setAttribute(e,t){this.doc===null?this._prelimAttrs.set(e,t):K(this.doc,n=>{ha(n,this,e,t)})}getAttribute(e){return ga(this,e)}hasAttribute(e){return va(this,e)}getAttributes(e){return e?ya(this,e):_a(this)}toDOM(e=document,t={},n){let r=e.createElement(this.nodeName),i=this.getAttributes();for(let e in i){let t=i[e];typeof t==`string`&&r.setAttribute(e,t)}return aa(this,i=>{r.appendChild(i.toDOM(e,t,n))}),n!==void 0&&n._createAssociation(r,this),r}_write(e){e.writeTypeRef(wo),e.writeKey(this.nodeName)}};let Ya=e=>new Ja(e.readKey());var Xa=class extends qi{constructor(e,t,n){super(e,n),this.childListChanged=!1,this.attributesChanged=new Set,t.forEach(e=>{e===null?this.childListChanged=!0:this.attributesChanged.add(e)})}},Za=class e extends Ta{constructor(e){super(),this.hookName=e}_copy(){return new e(this.hookName)}clone(){let t=new e(this.hookName);return this.forEach((e,n)=>{t.set(n,e)}),t}toDOM(e=document,t={},n){let r=t[this.hookName],i;return i=r===void 0?document.createElement(this.hookName):r.createDom(this),i.setAttribute(`data-yjs-hook`,this.hookName),n!==void 0&&n._createAssociation(i,this),i}_write(e){e.writeTypeRef(Eo),e.writeKey(this.hookName)}};let Qa=e=>new Za(e.readKey());var $a=class e extends Ua{get nextSibling(){let e=this._item?this._item.next:null;return e?e.content.type:null}get prevSibling(){let e=this._item?this._item.prev:null;return e?e.content.type:null}_copy(){return new e}clone(){let t=new e;return t.applyDelta(this.toDelta()),t}toDOM(e=document,t,n){let r=e.createTextNode(this.toString());return n!==void 0&&n._createAssociation(r,this),r}toString(){return this.toDelta().map(e=>{let t=[];for(let n in e.attributes){let r=[];for(let t in e.attributes[n])r.push({key:t,value:e.attributes[n][t]});r.sort((e,t)=>e.key<t.key?-1:1),t.push({nodeName:n,attrs:r})}t.sort((e,t)=>e.nodeName<t.nodeName?-1:1);let n=``;for(let e=0;e<t.length;e++){let r=t[e];n+=`<${r.nodeName}`;for(let e=0;e<r.attrs.length;e++){let t=r.attrs[e];n+=` ${t.key}="${t.value}"`}n+=`>`}n+=e.insert;for(let e=t.length-1;e>=0;e--)n+=`</${t[e].nodeName}>`;return n}).join(``)}toJSON(){return this.toString()}_write(e){e.writeTypeRef(Do)}};let eo=e=>new $a;var to=class{constructor(e,t){this.id=e,this.length=t}get deleted(){throw Ce()}mergeWith(e){return!1}write(e,t,n){throw Ce()}integrate(e,t){throw Ce()}},Y=class extends to{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){t>0&&(this.id.clock+=t,this.length-=t),mi(e.doc.store,this)}write(e,t){e.writeInfo(0),e.writeLen(this.length-t)}getMissing(e,t){return null}},no=class e{constructor(e){this.content=e}getLength(){return 1}getContent(){return[this.content]}isCountable(){return!0}copy(){return new e(this.content)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeBuf(this.content)}getRef(){return 3}};let ro=e=>new no(e.readBuf());var io=class e{constructor(e){this.len=e}getLength(){return this.len}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.len)}splice(t){let n=new e(this.len-t);return this.len=t,n}mergeWith(e){return this.len+=e.len,!0}integrate(e,t){mr(e.deleteSet,t.id.client,t.id.clock,this.len),t.markDeleted()}delete(e){}gc(e){}write(e,t){e.writeLen(this.len-t)}getRef(){return 1}};let ao=e=>new io(e.readLen()),oo=(e,t)=>new xr({guid:e,...t,shouldLoad:t.shouldLoad||t.autoLoad||!1});var so=class e{constructor(e){e._item&&console.error(`This document was already integrated as a sub-document. You should create a second instance instead with the same guid.`),this.doc=e;let t={};this.opts=t,e.gc||(t.gc=!1),e.autoLoad&&(t.autoLoad=!0),e.meta!==null&&(t.meta=e.meta)}getLength(){return 1}getContent(){return[this.doc]}isCountable(){return!0}copy(){return new e(oo(this.doc.guid,this.opts))}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){this.doc._item=t,e.subdocsAdded.add(this.doc),this.doc.shouldLoad&&e.subdocsLoaded.add(this.doc)}delete(e){e.subdocsAdded.has(this.doc)?e.subdocsAdded.delete(this.doc):e.subdocsRemoved.add(this.doc)}gc(e){}write(e,t){e.writeString(this.doc.guid),e.writeAny(this.opts)}getRef(){return 9}};let co=e=>new so(oo(e.readString(),e.readAny()));var lo=class e{constructor(e){this.embed=e}getLength(){return 1}getContent(){return[this.embed]}isCountable(){return!0}copy(){return new e(this.embed)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeJSON(this.embed)}getRef(){return 5}};let uo=e=>new lo(e.readJSON());var X=class e{constructor(e,t){this.key=e,this.value=t}getLength(){return 1}getContent(){return[]}isCountable(){return!1}copy(){return new e(this.key,this.value)}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){let n=t.parent;n._searchMarker=null,n._hasFormatting=!0}delete(e){}gc(e){}write(e,t){e.writeKey(this.key),e.writeJSON(this.value)}getRef(){return 6}};let fo=e=>new X(e.readKey(),e.readJSON());var po=class e{constructor(e){this.arr=e}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeString(t===void 0?`undefined`:JSON.stringify(t))}}getRef(){return 2}};let mo=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++){let t=e.readString();t===`undefined`?n.push(void 0):n.push(JSON.parse(t))}return new po(n)},ho=vt(`node_env`)===`development`;var go=class e{constructor(e){this.arr=e,ho&&ct(e)}getLength(){return this.arr.length}getContent(){return this.arr}isCountable(){return!0}copy(){return new e(this.arr)}splice(t){let n=new e(this.arr.slice(t));return this.arr=this.arr.slice(0,t),n}mergeWith(e){return this.arr=this.arr.concat(e.arr),!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){let n=this.arr.length;e.writeLen(n-t);for(let r=t;r<n;r++){let t=this.arr[r];e.writeAny(t)}}getRef(){return 8}};let _o=e=>{let t=e.readLen(),n=[];for(let r=0;r<t;r++)n.push(e.readAny());return new go(n)};var vo=class e{constructor(e){this.str=e}getLength(){return this.str.length}getContent(){return this.str.split(``)}isCountable(){return!0}copy(){return new e(this.str)}splice(t){let n=new e(this.str.slice(t));this.str=this.str.slice(0,t);let r=this.str.charCodeAt(t-1);return r>=55296&&r<=56319&&(this.str=this.str.slice(0,t-1)+`�`,n.str=`�`+n.str.slice(1)),n}mergeWith(e){return this.str+=e.str,!0}integrate(e,t){}delete(e){}gc(e){}write(e,t){e.writeString(t===0?this.str:this.str.slice(t))}getRef(){return 4}};let yo=e=>new vo(e.readString()),bo=[Ca,Ea,Wa,Ya,qa,Qa,eo],xo=0,So=1,Co=2,wo=3,To=4,Eo=5,Do=6;var Oo=class e{constructor(e){this.type=e}getLength(){return 1}getContent(){return[this.type]}isCountable(){return!0}copy(){return new e(this.type._copy())}splice(e){throw Ce()}mergeWith(e){return!1}integrate(e,t){this.type._integrate(e.doc,t)}delete(e){let t=this.type._start;for(;t!==null;)t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e),t=t.right;this.type._map.forEach(t=>{t.deleted?t.id.clock<(e.beforeState.get(t.id.client)||0)&&e._mergeStructs.push(t):t.delete(e)}),e.changed.delete(this.type)}gc(e){let t=this.type._start;for(;t!==null;)t.gc(e,!0),t=t.right;this.type._start=null,this.type._map.forEach(t=>{for(;t!==null;)t.gc(e,!0),t=t.left}),this.type._map=new Map}write(e,t){this.type._write(e)}getRef(){return 7}};let ko=e=>new Oo(bo[e.readTypeRef()](e)),Ao=(e,t)=>{let n=t,r=0,i;do r>0&&(n=U(n.client,n.clock+r)),i=gi(e,n),r=n.clock-i.id.clock,n=i.redone;while(n!==null&&i instanceof Z);return{item:i,diff:r}},jo=(e,t)=>{for(;e!==null&&e.keep!==t;)e.keep=t,e=e.parent._item},Mo=(e,t,n)=>{let{client:r,clock:i}=t.id,a=new Z(U(r,i+n),t,U(r,i+n-1),t.right,t.rightOrigin,t.parent,t.parentSub,t.content.splice(n));return t.deleted&&a.markDeleted(),t.keep&&(a.keep=!0),t.redone!==null&&(a.redone=U(t.redone.client,t.redone.clock+n)),t.right=a,a.right!==null&&(a.right.left=a),e._mergeStructs.push(a),a.parentSub!==null&&a.right===null&&a.parent._map.set(a.parentSub,a),t.length=n,a},No=(e,t)=>d(e,e=>dr(e.deletions,t)),Po=(e,t,n,r,i,a)=>{let o=e.doc,s=o.store,c=o.clientID,l=t.redone;if(l!==null)return G(e,l);let u=t.parent._item,d=null,f;if(u!==null&&u.deleted===!0){if(u.redone===null&&(!n.has(u)||Po(e,u,n,r,i,a)===null))return null;for(;u.redone!==null;)u=G(e,u.redone)}let p=u===null?t.parent:u.content.type;if(t.parentSub===null){for(d=t.left,f=t;d!==null;){let t=d;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:G(e,t.redone);if(t!==null&&t.parent._item===u){d=t;break}d=d.left}for(;f!==null;){let t=f;for(;t!==null&&t.parent._item!==u;)t=t.redone===null?null:G(e,t.redone);if(t!==null&&t.parent._item===u){f=t;break}f=f.right}}else{if(f=null,t.right&&!i){for(d=t;d!==null&&d.right!==null&&(d.right.redone||dr(r,d.right.id)||No(a.undoStack,d.right.id)||No(a.redoStack,d.right.id));)for(d=d.right;d.redone;)d=G(e,d.redone);if(d&&d.right!==null)return null}else d=p._map.get(t.parentSub)||null;d!==null&&d.parent._item!==u&&(d=p._map.get(t.parentSub)||null)}let m=W(s,c),h=U(c,m),g=new Z(h,d,d&&d.lastId,f,f&&f.id,p,t.parentSub,t.content.copy());return t.redone=h,jo(g,!0),g.integrate(e,0),g};var Z=class e extends to{constructor(e,t,n,r,i,a,o,s){super(e,s.getLength()),this.origin=n,this.left=t,this.right=r,this.rightOrigin=i,this.parent=a,this.parentSub=o,this.redone=null,this.content=s,this.info=this.content.isCountable()?2:0}set marker(e){(this.info&8)>0!==e&&(this.info^=8)}get marker(){return(this.info&8)>0}get keep(){return(this.info&1)>0}set keep(e){this.keep!==e&&(this.info^=1)}get countable(){return(this.info&2)>0}get deleted(){return(this.info&4)>0}set deleted(e){this.deleted!==e&&(this.info^=4)}markDeleted(){this.info|=4}getMissing(t,n){if(this.origin&&this.origin.client!==this.id.client&&this.origin.clock>=W(n,this.origin.client))return this.origin.client;if(this.rightOrigin&&this.rightOrigin.client!==this.id.client&&this.rightOrigin.clock>=W(n,this.rightOrigin.client))return this.rightOrigin.client;if(this.parent&&this.parent.constructor===Qr&&this.id.client!==this.parent.client&&this.parent.clock>=W(n,this.parent.client))return this.parent.client;if(this.origin&&=(this.left=vi(t,n,this.origin),this.left.lastId),this.rightOrigin&&=(this.right=G(t,this.rightOrigin),this.right.id),this.left&&this.left.constructor===Y||this.right&&this.right.constructor===Y)this.parent=null;else if(!this.parent)this.left&&this.left.constructor===e?(this.parent=this.left.parent,this.parentSub=this.left.parentSub):this.right&&this.right.constructor===e&&(this.parent=this.right.parent,this.parentSub=this.right.parentSub);else if(this.parent.constructor===Qr){let e=gi(n,this.parent);this.parent=e.constructor===Y?null:e.content.type}return null}integrate(e,t){if(t>0&&(this.id.clock+=t,this.left=vi(e,e.doc.store,U(this.id.client,this.id.clock-1)),this.origin=this.left.lastId,this.content=this.content.splice(t),this.length-=t),this.parent){if(!this.left&&(!this.right||this.right.left!==null)||this.left&&this.left.right!==this.right){let t=this.left,n;if(t!==null)n=t.right;else if(this.parentSub!==null)for(n=this.parent._map.get(this.parentSub)||null;n!==null&&n.left!==null;)n=n.left;else n=this.parent._start;let r=new Set,i=new Set;for(;n!==null&&n!==this.right;){if(i.add(n),r.add(n),$r(this.origin,n.origin)){if(n.id.client<this.id.client)t=n,r.clear();else if($r(this.rightOrigin,n.rightOrigin))break}else if(n.origin!==null&&i.has(gi(e.doc.store,n.origin)))r.has(gi(e.doc.store,n.origin))||(t=n,r.clear());else break;n=n.right}this.left=t}if(this.left!==null){let e=this.left.right;this.right=e,this.left.right=this}else{let e;if(this.parentSub!==null)for(e=this.parent._map.get(this.parentSub)||null;e!==null&&e.left!==null;)e=e.left;else e=this.parent._start,this.parent._start=this;this.right=e}this.right===null?this.parentSub!==null&&(this.parent._map.set(this.parentSub,this),this.left!==null&&this.left.delete(e)):this.right.left=this,this.parentSub===null&&this.countable&&!this.deleted&&(this.parent._length+=this.length),mi(e.doc.store,this),this.content.integrate(e,this),Ci(e,this.parent,this.parentSub),(this.parent._item!==null&&this.parent._item.deleted||this.parentSub!==null&&this.right!==null)&&this.delete(e)}else new Y(this.id,this.length).integrate(e,0)}get next(){let e=this.right;for(;e!==null&&e.deleted;)e=e.right;return e}get prev(){let e=this.left;for(;e!==null&&e.deleted;)e=e.left;return e}get lastId(){return this.length===1?this.id:U(this.id.client,this.id.clock+this.length-1)}mergeWith(e){if(this.constructor===e.constructor&&$r(e.origin,this.lastId)&&this.right===e&&$r(this.rightOrigin,e.rightOrigin)&&this.id.client===e.id.client&&this.id.clock+this.length===e.id.clock&&this.deleted===e.deleted&&this.redone===null&&e.redone===null&&this.content.constructor===e.content.constructor&&this.content.mergeWith(e.content)){let t=this.parent._searchMarker;return t&&t.forEach(t=>{t.p===e&&(t.p=this,!this.deleted&&this.countable&&(t.index-=this.length))}),e.keep&&(this.keep=!0),this.right=e.right,this.right!==null&&(this.right.left=this),this.length+=e.length,!0}return!1}delete(e){if(!this.deleted){let t=this.parent;this.countable&&this.parentSub===null&&(t._length-=this.length),this.markDeleted(),mr(e.deleteSet,this.id.client,this.id.clock,this.length),Ci(e,t,this.parentSub),this.content.delete(e)}}gc(e,t){if(!this.deleted)throw we();this.content.gc(e),t?yi(e,this,new Y(this.id,this.length)):this.content=new io(this.length)}write(e,t){let n=t>0?U(this.id.client,this.id.clock+t-1):this.origin,r=this.rightOrigin,i=this.parentSub,a=this.content.getRef()&31|(n===null?0:128)|(r===null?0:64)|(i===null?0:32);if(e.writeInfo(a),n!==null&&e.writeLeftID(n),r!==null&&e.writeRightID(r),n===null&&r===null){let t=this.parent;if(t._item!==void 0){let n=t._item;if(n===null){let n=ei(t);e.writeParentInfo(!0),e.writeString(n)}else e.writeParentInfo(!1),e.writeLeftID(n.id)}else t.constructor===String?(e.writeParentInfo(!0),e.writeString(t)):t.constructor===Qr?(e.writeParentInfo(!1),e.writeLeftID(t)):we();i!==null&&e.writeString(i)}this.content.write(e,t)}};let Fo=(e,t)=>Io[t&31](e),Io=[()=>{we()},ao,mo,ro,yo,uo,fo,ko,_o,co,()=>{we()}];var Lo=class extends to{get deleted(){return!0}delete(){}mergeWith(e){return this.constructor===e.constructor&&(this.length+=e.length,!0)}integrate(e,t){we()}write(e,t){e.writeInfo(10),L(e.restEncoder,this.length-t)}getMissing(e,t){return null}};let Ro=typeof globalThis<`u`?globalThis:typeof window<`u`?window:typeof global<`u`?global:{},zo=`__ $YJS$ __`;Ro[zo]===!0&&console.error(`Yjs was already imported. This breaks constructor checks and will lead to issues! - https://github.com/yjs/yjs/issues/438`),Ro[zo]=!0;let Q=Object.freeze({stateBytes:262144,updateBytes:32768,textLength:32768,clients:128,structs:16384,historyUnits:1048576,undoEntries:100,undoUnits:32768}),Bo=new TextEncoder,Vo=(e,t)=>{throw Object.assign(Error(t),{code:e})},$=(e,t,n)=>{e||Vo(t,n)},Ho=e=>Number.isSafeInteger(e)&&e>=0,Uo=e=>{$(typeof e==`string`,`SHARED_TEXT_INPUT`,`Shared text must be a string`),$(e.length<=Q.textLength,`SHARED_TEXT_LIMIT`,`Shared text exceeds its character limit`);for(let t=0;t<e.length;t++){let n=e.charCodeAt(t);if(n>=55296&&n<=56319){let n=e.charCodeAt(++t);$(n>=56320&&n<=57343,`SHARED_TEXT_INPUT`,`Shared text contains an incomplete Unicode character`)}else $(n<56320||n>57343,`SHARED_TEXT_INPUT`,`Shared text contains an incomplete Unicode character`)}return e};function Wo(e){$(e instanceof Uint8Array,`SHARED_TEXT_INPUT`,`Expected shared text bytes`);let t=``;for(let n=0;n<e.length;n+=8192)t+=String.fromCharCode(...e.subarray(n,n+8192));return btoa(t)}function Go(e,t=Q.updateBytes){$(typeof e==`string`&&e.length>0&&e.length<=4*Math.ceil(t/3),`SHARED_TEXT_LIMIT`,`Shared text data exceeds its byte limit`),$(e.length%4==0&&/^(?:[A-Za-z0-9+/]{4})*(?:[A-Za-z0-9+/]{2}==|[A-Za-z0-9+/]{3}=)?$/.test(e),`SHARED_TEXT_INPUT`,`Expected canonical base64 shared text data`);let n=atob(e);$(n.length<=t,`SHARED_TEXT_LIMIT`,`Shared text data exceeds its byte limit`);let r=Uint8Array.from(n,e=>e.charCodeAt(0));return $(Wo(r)===e,`SHARED_TEXT_INPUT`,`Expected canonical base64 shared text data`),r}function Ko(e){let t;class n extends Cr{constructor(e){super(e),t=e}}let r=Fi(e,n);$(t.pos===e.length,`SHARED_TEXT_STATE`,`Shared text data contains trailing bytes`),$(r.structs.length<=Q.structs&&r.ds.clients.size<=Q.clients,`SHARED_TEXT_LIMIT`,`Shared text history exceeds its limit`);let i=0,a=0,o=new Map;for(let e of r.structs)$(Ho(e.id.client)&&Ho(e.id.clock)&&Ho(e.length)&&e.length>0,`SHARED_TEXT_STATE`,`Invalid shared text history`),$(!o.has(e.id.client)||e.id.clock>=o.get(e.id.client),`SHARED_TEXT_STATE`,`Shared text history overlaps itself`),o.set(e.id.client,e.id.clock+e.length),i+=e.length,$(e.id.clock+e.length<=Q.historyUnits&&i<=Q.historyUnits,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),e instanceof Z?($(e.parentSub===null&&(e.parent===null||typeof e.parent!=`string`||e.parent===`text`),`SHARED_TEXT_STATE`,`Shared text accepts only its plaintext field`),$(e.content instanceof vo||e.content instanceof io,`SHARED_TEXT_STATE`,`Shared text cannot contain formatting, embedded values or other shared types`),e.content instanceof vo&&Uo(e.content.str)):$(e instanceof Y,`SHARED_TEXT_STATE`,`Unsupported shared text history`);for(let[e,t]of r.ds.clients){$(Ho(e),`SHARED_TEXT_STATE`,`Invalid shared text deletion`),a+=t.length,$(a<=Q.structs,`SHARED_TEXT_LIMIT`,`Shared text deletion history exceeds its limit`);for(let e of t)$(Ho(e.clock)&&Ho(e.len)&&e.len>0&&e.clock+e.len<=Q.historyUnits,`SHARED_TEXT_STATE`,`Invalid shared text deletion`)}return r}function qo(e,t){let n=new Map;for(let e of t.structs){let t=n.get(e.id.client)||[];t.push(e),n.set(e.id.client,t)}let r=(t,r)=>{let i=e=>{if(!e)return;let t=0,n=e.length;for(;t<n;){let i=t+n>>>1;e[i].id.clock<=r?t=i+1:n=i}let i=e[t-1];return i&&r<i.id.clock+i.length?i:void 0};return i(e.store.clients.get(t))||i(n.get(t))},i=(e,t)=>{let n=r(e,t);if(n instanceof Z&&n.content instanceof vo){let e=t-n.id.clock,r=n.content.str;$($o(r,e),`SHARED_TEXT_STATE`,`Shared text update splits a Unicode character`)}};for(let e of t.structs)e instanceof Z&&(e.origin&&i(e.origin.client,e.origin.clock+1),e.rightOrigin&&i(e.rightOrigin.client,e.rightOrigin.clock));for(let[e,n]of t.ds.clients)for(let t of n)i(e,t.clock),i(e,t.clock+t.len)}function Jo(e){let t=e.getText(`text`);$(e.share.size===1&&e.share.get(`text`)===t&&t._map.size===0&&e.getSubdocs().size===0,`SHARED_TEXT_STATE`,`Shared text accepts only its plaintext field`),$(e.store.pendingStructs===null&&e.store.pendingDs===null,`SHARED_TEXT_STATE`,`Shared text update is missing earlier history`),$(e.store.clients.size<=Q.clients,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`);let n=0,r=0;for(let i of e.store.clients.values())for(let e of i)n++,r+=e.length,$(n<=Q.structs&&r<=Q.historyUnits,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),e instanceof Z?$(e.parent===t&&e.parentSub===null&&(e.content instanceof vo||e.content instanceof io),`SHARED_TEXT_STATE`,`Shared text contains unsupported history`):$(e instanceof Y,`SHARED_TEXT_STATE`,`Unsupported shared text history`);for(let e of t.toDelta())$(typeof e.insert==`string`&&e.attributes===void 0,`SHARED_TEXT_STATE`,`Shared text cannot contain formatting or embedded values`);return Uo(t.toString())}function Yo(e,t,n){let r=Go(t,n);qo(e,Ko(r)),Lr(e,r),Jo(e)}function Xo(e){let t=new xr;t.getText(`text`);try{return Yo(t,e,Q.stateBytes),t}catch(e){throw t.destroy(),e}}function Zo(e){let t=Jo(e),n=Br(e);return $(n.length<=Q.stateBytes,`SHARED_TEXT_LIMIT`,`Shared text history needs a new epoch`),{state:Wo(n),value:t}}function Qo(e){try{return e()}catch(e){if(typeof e?.code==`string`&&e.code.startsWith(`SHARED_TEXT_`))throw e;Vo(`SHARED_TEXT_STATE`,`Invalid shared text data`)}}let $o=(e,t)=>Ho(t)&&t<=e.length&&!(t>0&&t<e.length&&e.charCodeAt(t-1)>=55296&&e.charCodeAt(t-1)<=56319&&e.charCodeAt(t)>=56320&&e.charCodeAt(t)<=57343),es=/^[0-9a-f]{8}-[0-9a-f]{4}-[1-8][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$/i;function ts({protocol:e,epoch:t,state:n}){$(e===1&&typeof t==`string`&&es.test(t),`SHARED_TEXT_INPUT`,`Expected a versioned shared text epoch`);let r=Qo(()=>Xo(n)),i=r.getText(`text`),a={},o={},s=new WeakMap,c=new Mi(i,{trackedOrigins:new Set([a]),captureTimeout:0}),l=!1,u=null,d=()=>{if($(!l,`SHARED_TEXT_CLOSED`,`Shared text session is closed`),u)throw u},f=e=>{throw u=e,e},p=(e=[])=>{let t=e=>[...e.deletions.clients.values()].reduce((e,t)=>e+t.reduce((e,t)=>e+t.len,0),0),n=[...c.undoStack,...c.redoStack].reduce((e,n)=>e+t(n),0);for(;c.undoStack.length+c.redoStack.length>Q.undoEntries||n>Q.undoUnits;){let r=(c.undoStack.length?c.undoStack:c.redoStack).shift();n-=t(r),e.push(r.deletions)}if(!e.length)return;let i=pr(e);r.transact(e=>{lr(e,i,e=>{e instanceof Z&&(e.keep=!1)});for(let t of[...c.undoStack,...c.redoStack])lr(e,t.deletions,e=>{e instanceof Z&&(e.keep=!0)});Di(i,r.store,()=>!0)},o)},m=e=>{d();let t=c.redoStack.map(e=>e.deletions);try{return r.transact(e,a),p(t),i.toString()}catch(e){return f(e)}},h=e=>{d();let t=c[e](),n;try{n=Uo(i.toString())}catch(n){throw t&&c[e===`undo`?`redo`:`undo`](),n}try{return p(),n}catch(e){return f(e)}};return Object.freeze({getValue(){return $(!l,`SHARED_TEXT_CLOSED`,`Shared text session is closed`),i.toString()},splice(e,t,n=``){d();let r=i.toString();return Uo(n),$(Ho(t)&&$o(r,e)&&$o(r,e+t),`SHARED_TEXT_INPUT`,`Choose complete characters within the shared text`),$(r.length-t+n.length<=Q.textLength&&Bo.encode(n).length+1024<=Q.updateBytes,`SHARED_TEXT_LIMIT`,`Shared text edit exceeds its limit`),!t&&!n?r:m(()=>{t&&i.delete(e,t),n&&i.insert(e,n)})},captureSelection(e,t=e,n=`none`){d();let r=i.toString();$($o(r,e)&&$o(r,t)&&e<=t&&[`none`,`forward`,`backward`].includes(n),`SHARED_TEXT_INPUT`,`Invalid shared text selection`);let a=Object.freeze({});return s.set(a,{start:oi(i,e),end:oi(i,t),direction:n}),a},resolveSelection(e){d(),$(e&&s.has(e),`SHARED_TEXT_INPUT`,`Selection belongs to another shared text session`);let t=s.get(e),n=ci(t.start,r),a=ci(t.end,r);return $(n?.type===i&&a?.type===i,`SHARED_TEXT_STATE`,`Shared text selection is unavailable`),{start:Math.min(n.index,a.index),end:Math.max(n.index,a.index),direction:t.direction}},receive(n){return d(),$(n?.protocol===e&&n.epoch===t,`SHARED_TEXT_STATE`,`Shared text epoch changed; retain the local draft and reopen explicitly`),Qo(()=>{let e=Xo(Wo(Br(r)));try{Yo(e,n.state,Q.stateBytes),Zo(e)}finally{e.destroy()}return Lr(r,Go(n.state,Q.stateBytes),o),i.toString()})},getUpdateSince(n){return d(),$(n?.protocol===e&&n.epoch===t,`SHARED_TEXT_STATE`,`Shared text epoch changed; retain the local draft and reopen explicitly`),Qo(()=>{let i=Xo(n.state);try{Zo(r);let n=Br(r,Kr(i));return $(n.length<=Q.updateBytes,`SHARED_TEXT_LIMIT`,`Shared text batch exceeds its limit`),{protocol:e,epoch:t,update:Wo(n)}}finally{i.destroy()}})},undo(){return h(`undo`)},redo(){return h(`redo`)},canUndo(){return!l&&c.undoStack.length>0},canRedo(){return!l&&c.redoStack.length>0},checkpoint(){return d(),Qo(()=>({protocol:e,epoch:t,...Zo(r)}))},dispose(){l||(l=!0,c.destroy(),r.destroy())}})}function ns(e,t,n,r=null,i=[]){let a=new Map,o=[`text`,`search`,`email`,`tel`,`url`],s=new Set(i),c=new Map,l=new Set,u=new Map,d=!1,f={},p=(e,t,n)=>e?e.some(e=>e.value===String(n)):t.tagName!==`SELECT`||[...t.options].some(e=>e.value===String(n)),m=(e,t)=>{if(clearTimeout(t.timer),c.delete(e),d)return;let r;return r=Promise.resolve().then(()=>{if(!d)return t.callback()}).catch(t=>{u.set(e,t),n(t.message)}).finally(()=>l.delete(r)),l.add(r),r},h=(e,t)=>{if(d)throw Error(`This interface has closed; shared edits stopped.`);if(typeof e!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e))throw Error(`A shared edit key starts with a letter and holds only letters, digits, - and _ (up to 100 characters).`);if(typeof t!=`function`)throw Error(`Give scheduleSharedEdit a function to run.`);if(!c.has(e)&&c.size+l.size>=32||!u.has(e)&&u.size>=32)throw Error(`Too many scheduled shared edits`);u.delete(e);let n=c.get(e),r={callback:t,started:n?.started??Date.now(),timer:null};n&&clearTimeout(n.timer),r.timer=setTimeout(()=>m(e,r),Math.max(0,Math.min(150,500-(Date.now()-r.started)))),c.set(e,r)},g=(i,c)=>{if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(i)||a.has(i))throw Error(`Use one control per named shared field`);let l=e.getElementById(c),u=l?.tagName===`FIELDSET`?[...l.querySelectorAll(`input[type="radio"]`)]:null;if(!l||![`INPUT`,`TEXTAREA`,`SELECT`,`FIELDSET`].includes(l.tagName)||u&&!u.length||l.tagName===`INPUT`&&![`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`].includes(l.type))throw Error(`Bind an existing text, number, checkbox or select control, or a fieldset of radio buttons`);if(s.has(i)){let e=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),t=l.disabled,n=l.readOnly,r=l.getAttribute(`title`),s=l.getAttribute(`aria-readonly`),c=l.getAttribute(`aria-disabled`);e?(l.readOnly=!0,l.setAttribute(`aria-readonly`,`true`)):(l.disabled=!0,l.setAttribute(`aria-disabled`,`true`)),l.setAttribute(`title`,`Connected input. Change its source in Flow.`);let u={flush:async()=>{},status:()=>({dirty:!1,saving:!1,problem:null,canEdit:!1,composing:!1,interrupted:!1}),setDefault(){},dispose(){l.disabled=t,l.readOnly=n,r===null?l.removeAttribute(`title`):l.setAttribute(`title`,r),s===null?l.removeAttribute(`aria-readonly`):l.setAttribute(`aria-readonly`,s),c===null?l.removeAttribute(`aria-disabled`):l.setAttribute(`aria-disabled`,c),a.delete(i)}};return a.set(i,u),u.dispose}if(r&&(l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type))){let e=r.bind(i,l),t=e.dispose;return e.dispose=()=>{t(),a.delete(i)},a.set(i,e),e.dispose}let d=l.disabled,m={exists:!1},h,g=!1,_=!1,v=null,y=!1,b=!1,x=null,S=null,C=null,w=!1,T=!1,E,D=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),ee=e=>{S=e,l.setCustomValidity(e.message),n(e.message)},O=()=>u.find(e=>e.checked)?.value??``,k=e=>{let n=u?O():l.type===`checkbox`?l.checked:l.value;if(u)for(let t of u)t.checked=t.value===String(e??``);else l.type===`checkbox`?l.checked=!!e:l.value!==String(e??``)&&(l.value=String(e??``));(u?O():l.type===`checkbox`?l.checked:l.value)!==n&&queueMicrotask(()=>{y||t.announce?.()})},A=()=>u?O():l.type===`checkbox`?l.checked:[`number`,`range`].includes(l.type)?l.valueAsNumber:l.value,j=Object.hasOwn(f,i)&&p(u,l,f[i])?f[i]:A(),M=()=>{if(clearTimeout(v),v=null,_)return x;if(y||w||!g||!b||S)return;let e=h;g=!1,C=null,_=!0;let n=!1;return x=Promise.resolve().then(()=>t.updateShared({[i]:e},{[i]:m})).then(()=>{m={exists:!0,value:e},l.setCustomValidity(``),!S&&g&&Object.is(h,e)&&(g=!1,C=null)},e=>{n=!0,g=!0,ee(e)}).finally(()=>{_=!1,x=null,!y&&!n&&g&&h!==e&&N(),!y&&!g&&F(t.getShared())}),x},N=()=>{clearTimeout(v),v=setTimeout(M,Math.max(0,Math.min(150,500-(Date.now()-(C??Date.now())))))},te=()=>{!y&&D&&b&&!d&&(w=!0,clearTimeout(v),v=null)},P=e=>{if(y||!b||d)return;if(D&&e?.isComposing){te();return}if(w)return;let t=A();if(typeof t==`number`&&!Number.isFinite(t)){ee(Error(`Enter a finite number`));return}E!==void 0&&Object.is(t,E)||(E=void 0,(S||!Object.is(t,g||_?h:m.exists?m.value:j))&&((S||C===null)&&(C=Date.now()),h=t,S=null,g=!0,N()))},F=e=>{y||(b=e.canEdit,l.disabled=d||!b,!b&&w&&(T=!0),!b&&(g||w)&&ee(Error(`Editing access changed. Your unsaved draft has been preserved.`)),!(w||g||_||S)&&(m=Object.hasOwn(e.state,i)?{exists:!0,value:e.state[i]}:{exists:!1},k(m.exists?m.value:j)))},ne=t.onShared(F),I=()=>{if(!y&&w){if(w=!1,!b||T){T=!1,h=A(),E=h,g=!0,ee(Error(`Editing access changed. Your unsaved draft has been preserved.`));return}P(),g&&!_&&!S?(C=Date.now(),N()):!g&&!_&&!S&&F(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let re=u?`focusout`:`blur`;l.addEventListener(`input`,P),l.addEventListener(`change`,P),l.addEventListener(re,M),l.addEventListener(`compositionstart`,te),l.addEventListener(`compositionend`,I);let L=()=>{y=!0,w=!1,clearTimeout(v),ne(),l.removeEventListener(`input`,P),l.removeEventListener(`change`,P),l.removeEventListener(re,M),l.removeEventListener(`compositionstart`,te),l.removeEventListener(`compositionend`,I),l.disabled=d,a.delete(i)};return a.set(i,{dispose:L,flush:M,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){j=e,F(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),L},_=new Map,v=new Map,y=new WeakSet,b=[`text`,`search`,`email`,`tel`,`url`,`number`,`range`,`checkbox`,`color`],x=/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/,S=/(?:password|secret|credential|authorization|cookie|token|api[_-]?key|private[_-]?key)/i,C=/^(?:current-password|new-password|one-time-code|cc-)/i,w=null,T=null,E=e=>{let t=_.get(e);if(t!==void 0){_.delete(e),v.delete(t);try{a.get(t)?.dispose()}catch{}a.delete(t)}},D=(t,n)=>{let r=e.getElementById(n);r&&_.has(r)&&E(r),v.has(t)&&E(v.get(t));let i=g(t,n);return r&&y.add(r),i},ee=e=>{let t=e.getAttribute(`data-stillmade-share`)||e.getAttribute(`name`)||e.id||(e.tagName===`FIELDSET`?e.querySelector(`input[type="radio"][name]`)?.getAttribute(`name`):``)||``;return x.test(t)?t:null},O=e=>!e.isConnected||e.closest(`[data-stillmade-local]`)?!1:e.tagName===`FIELDSET`?!!e.querySelector(`input[type="radio"]`)&&!e.querySelector(`fieldset`):e.tagName===`INPUT`?b.includes(e.type):e.tagName===`TEXTAREA`||e.tagName===`SELECT`,k=t=>{if(y.has(t)||_.has(t)||!O(t))return;let n=ee(t);if(!(!n||a.has(n)||a.size>=100)&&!(!t.hasAttribute(`data-stillmade-share`)&&(S.test(n)||S.test(t.getAttribute(`name`)||``)||S.test(t.id||``)||C.test(t.getAttribute(`autocomplete`)||``)))){if(!t.id){let r=`sm-shared-${n}`,i=1;for(;e.getElementById(r);)r=`sm-shared-${n}-${++i}`;t.id=r}else if(e.getElementById(t.id)!==t)return;try{g(n,t.id),_.set(t,n),v.set(n,t)}catch{a.delete(n)}}},A=()=>{if(T=null,!(d||j))try{for(let e of[..._.keys()])(!e.isConnected||e.closest(`[data-stillmade-local]`))&&E(e);for(let t of e.querySelectorAll(`input,textarea,select,fieldset`))k(t)}catch(e){n(e.message)}},j=!1,M=()=>{if(!j){j=!0,w?.disconnect(),w=null,T&&=(clearTimeout(T),null);for(let e of[..._.keys()])E(e)}},N=()=>{j||d||w||typeof MutationObserver!=`function`||!e.documentElement||(A(),w=new MutationObserver(()=>{!T&&!d&&(T=setTimeout(A,30))}),w.observe(e.documentElement,{childList:!0,subtree:!0,attributes:!0,attributeFilter:[`name`,`id`,`type`,`data-stillmade-local`,`data-stillmade-share`]}))};e.readyState===`loading`?e.addEventListener?.(`DOMContentLoaded`,N,{once:!0}):typeof setTimeout==`function`&&typeof MutationObserver==`function`&&setTimeout(N,0);let te=()=>{let t=[...e.querySelectorAll(`[data-stillmade-share]`)];if(t.length>100)throw Error(`Use at most 100 shared controls`);for(let n of t){let t=n.getAttribute(`data-stillmade-share`),r=n.id;if(typeof t!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(t)||typeof r!=`string`||!r||r.length>200||e.getElementById(r)!==n)throw Error(`Each data-stillmade-share control needs a unique ID and valid shared field name`);D(t,r)}return t.length},P=()=>{if(d)throw Error(`Block closed before edits could be flushed`);if([...a.values()].some(e=>e.status().composing))throw Error(`Finish composing text before leaving this Block or running an action.`);let e=[...a.values()].find(e=>e.status().interrupted);if(e)throw e.status().problem};return{bindShared:D,bindAnnotated:te,bindAutomatic:N,ownSharing:M,scheduleSharedEdit:h,flushAll:async()=>{if(d)throw Error(`Block closed before edits could be flushed`);for(let e=0;e<32;e++){if(d)throw Error(`Block closed before edits could be flushed`);P();let e=[...l];for(let[t,n]of[...c])e.push(m(t,n));for(let t of a.values())e.push(t.flush());if(await Promise.all(e),d)throw Error(`Block closed before edits could be flushed`);if(u.size)throw u.values().next().value;let t=!1;for(let e of a.values()){let n=e.status();if(n.problem)throw n.problem;if(n.composing)throw Error(`Finish composing text before leaving this Block or running an action.`);if(n.dirty&&!n.canEdit)throw Error(`Editing access changed. Your draft is not saved.`);t||=n.dirty||n.saving}if(!t&&!c.size&&!l.size)return{queued:!0}}throw Error(`Edits are still arriving. Finish editing before leaving this Block.`)},assertNoComposition:P,getBindingStatus:e=>a.get(e)?.status(),setSharedDefaults(e){if(!e||typeof e!=`object`||Array.isArray(e)||Object.keys(e).length>100||JSON.stringify(e).length>65536)throw Error(`Use bounded shared control defaults`);for(let[t,n]of Object.entries(e))a.get(t)?.setDefault(n)},useInputDefaults(e){let t=f;if(f={},e&&typeof e==`object`&&!Array.isArray(e))for(let[t,n]of Object.entries(e))[`string`,`number`,`boolean`].includes(typeof n)&&(f[t]=n);for(let[e,n]of a)Object.hasOwn(f,e)&&!(Object.hasOwn(t,e)&&t[e]===f[e])&&n.setInputDefault(f[e])},dispose(){d=!0,w?.disconnect(),T&&clearTimeout(T);for(let e of c.values())clearTimeout(e.timer);c.clear();for(let e of[...a.values()])e.dispose()}}}function rs(e,t,n,r,i,a=null){let o=new Map,s=new Map,c=[],l=0,u=!1,d=``,f=()=>{if(u)return;let e=[...o.values()].map(e=>e.status()),t={count:e.length,dirty:e.filter(e=>e.dirty||e.composing||e.interrupted).length,pending:e.filter(e=>e.saving).length,readonly:e.filter(e=>!e.canEdit).length,error:e.find(e=>e.problem)?.problem.message?.slice(0,1e3)||null,retryable:e.some(e=>e.retryable)},n=JSON.stringify(t);n!==d&&(d=n,parent.postMessage({channel:r,session:i,op:`text-recovery-status`,status:t},`*`),a&&a.send({channel:r,session:i,op:`named-text-controls`,token:a.token,snapshot:[...o.values()].map(e=>e.nativeState?.()).filter(Boolean).slice(0,50)},`*`))},p=e=>Object.assign(Error(e?.message||String(e)),e?.code?{code:e.code}:{}),m=()=>{for(;!u&&s.size<4&&c.length;){let e=c.findIndex(e=>e.action!==`read`),t=c.splice(e<0?0:e,1)[0],n=String(++l);t.id=n,s.set(n,t),(a?.send||parent.postMessage.bind(parent))({channel:r,session:i,op:`text-request`,id:n,action:t.action,key:t.key,body:t.body,...t.nativeProof&&a?{nativeText:{token:a.token,callId:t.nativeProof.callId}}:{}},`*`)}},h=(e,t,n={},r=null)=>new Promise((i,a)=>{if(u||s.size+c.length>=128){a(Error(`Shared text is unavailable or busy. Your draft is retained.`));return}let o={action:e,key:t,body:n,nativeProof:r,resolve:i,reject:a,timer:null,id:null};o.timer=setTimeout(()=>{if(o.id)s.delete(o.id);else{let e=c.indexOf(o);e>=0&&c.splice(e,1)}a(Error(`Shared text acknowledgement timed out. Your draft is retained.`)),m()},3e4),c.push(o),m()}),g=e=>{let t=e.data;if(!(e.source!==parent||t?.channel!==r||t.session!==i||u)){if(t.op===`text-result`){let e=s.get(t.id);if(!e)return;s.delete(t.id),clearTimeout(e.timer),t.error?e.reject(p(t.error)):e.resolve(t.result),m()}else if(t.op===`text-refresh`)for(let e of o.values())e.refresh();else if(t.op===`text-retry`)for(let e of o.values())e.retry().catch(()=>{})}};addEventListener(`message`,g);let _=(r,i)=>{if(o.has(r)||o.size>=100)throw Error(`Use at most 100 distinct shared text controls.`);let s=new WeakMap,c=null,l=i.disabled,u=i.readOnly,d=i.value,m=`loading`,g=!1,_=null,v=null,y=null,b=null,x=!1,S=0,C=null,w=null,T=null,E=!1,D=!1,ee=!1,O=!1,k=null,A=null,j=null,M=t.getShared().canEdit===!0,N=i.value,te=()=>!!b&&!O&&!D&&M&&!/^(READ_ONLY|SHARED_TEXT_(SOURCE|EPOCH|CONFLICT|INPUT|LIMIT|STATE|UPDATE|PROTOCOL))$/.test(b.code||``),P=e=>{E||(b=p(e),D&&(O=!0),i.readOnly=!0,(x||O)&&(i.disabled=l),i.setCustomValidity(b.message),n(b.message),f())},F=()=>({start:i.selectionStart??0,end:i.selectionEnd??0,direction:i.selectionDirection||`none`}),ne=e=>{i.value!==e&&(i.value=e,queueMicrotask(()=>{E||t.announce?.()}))},I=t=>{if(N=v.getValue(),ne(N),t&&e.activeElement===i){let e=v.resolveSelection(t);i.setSelectionRange(e.start,e.end,e.direction)}},re=()=>{let e=F();return v.captureSelection(e.start,e.end,e.direction)},L=e=>{if(!E&&e){if(b||O){(!A||e.textRevision>=A.textRevision)&&(A=e);return}if(D){(!A||e.textRevision>=A.textRevision)&&(A=e);return}if(v&&i.value!==N)throw O=!0,x=!0,Error(`This control has an uncommitted draft. Copy it before reopening the Block.`);if(y&&e.epoch!==y.epoch)throw Object.assign(Error(`This shared text was reset. Copy your draft before reloading the Block.`),{code:`SHARED_TEXT_EPOCH`});if(!(y&&e.textRevision<y.textRevision)){if(y&&e.protocol===y.protocol&&e.sourceIdentity===y.sourceIdentity&&e.textRevision===y.textRevision&&e.state===y.state&&e.value===y.value){y=e;return}if(!v)v=ts(e),y=e,I();else{let t=re();v.receive(e),y=e,I(t)}m=`text`,i.disabled=l||!M,i.readOnly=u,i.setCustomValidity(``),f()}}},ie=()=>{m=`legacy`,i.disabled=l,i.readOnly=u,i.value=d,_=ns(e,t,n),_.ownSharing(),_.bindShared(r,i.id),_.setSharedDefaults({[r]:d}),queueMicrotask(()=>{E||t.announce?.()})},ae=async(e=!1)=>E||!g||m===`legacy`||k||b?k:(k=(async()=>{let t=await h(`read`,r);if(E)return;if(t.unsupported){if(e)ie();else throw Error(`Shared text is no longer available. Your draft is retained.`);return}if(t.enabled){L(t.snapshot);return}if(!M){m=`waiting`,N=t.value,ne(t.value),i.disabled=!0;return}j={action:`initialize`,body:{protocol:1,requestId:crypto.randomUUID(),sourceIdentity:t.sourceIdentity}};let n=await h(j.action,r,j.body);j=null,E||L(n.snapshot)})().catch(P).finally(()=>{k=null,f()}),f(),k),oe=()=>{E||b||D||(T===null&&(T=Date.now()),clearTimeout(w),w=setTimeout(()=>{w=null,se().catch(()=>{})},Math.max(0,Math.min(200,600-(Date.now()-T)))))},se=async()=>{if(clearTimeout(w),w=null,_)return _.flushAll();if(k&&await k,b)throw b;if(E)throw Error(`Block closed before text was saved.`);if(!g||m===`loading`)throw Error(`Shared text is still loading. Wait before leaving this Block or running an action.`);if(D)throw Error(`Finish composing text before leaving this Block or running an action.`);if(v&&i.value!==N)throw O=!0,x=!0,P(Error(`This control has an uncommitted draft. Copy it before reopening the Block.`)),b;if(C){await C;return}if(!x)return;if(!M)throw Error(`Editing access changed. Your draft is retained.`);try{j={action:`update`,version:S,nativeProof:c?.version===S?{callId:c.callId}:null,body:{...v.getUpdateSince(y),requestId:crypto.randomUUID()}}}catch(e){throw P(e),e}x=!1,T=null;let e=j;C=h(e.action,r,e.body,e.nativeProof).then(t=>{E||(L(t.snapshot),!b&&!O&&(x=S!==e.version)),j=null}).catch(e=>{throw x=!0,P(e),e}).finally(()=>{C=null,x&&!b&&oe(),f()}),f(),await C},ce=e=>{if(m!==`text`||E||l||u||!M||O)return;if(e?.isComposing){R();return}if(D)return;if(b){i.value!==N&&(O=!0,x=!0,f());return}let t=i.value;if(t!==N)try{let n=0,r=N.length,i=t.length;for(;n<r&&n<i&&N[n]===t[n];)n++;for(n>0&&n<r&&/[\\uDC00-\\uDFFF]/.test(N[n])&&n--;r>n&&i>n&&N[r-1]===t[i-1];)r--,i--;r<N.length&&/[\\uDC00-\\uDFFF]/.test(N[r])&&(r++,i++),v.splice(n,r-n,t.slice(n,i)),N=v.getValue(),S++,c=s.has(e)?{version:S,callId:s.get(e)}:null,x=!0,oe(),f()}catch(e){O=!0,x=!0,P(e)}},R=()=>{m!==`text`||E||!M||l||u||b||(D=!0,clearTimeout(w),w=null,f())},le=()=>{if(D){if(D=!1,b||!M||ee){O=!0,x=!0,b||P(Error(`Editing access changed. Your composed draft is retained.`));return}if(ce(),A){let e=A;A=null;try{L(e)}catch(e){P(e)}}x&&oe(),f()}},ue=e=>{if(!(m!==`text`||D||b||!M||l||u||!(e.metaKey||e.ctrlKey)||e.altKey||![`z`,`y`].includes(e.key.toLowerCase()))){e.preventDefault();try{e.key.toLowerCase()===`y`||e.shiftKey?v.redo():v.undo(),I(),S++,x=!0,oe(),f()}catch(e){P(e)}}},de=()=>{m===`text`&&se().catch(()=>{})},fe=t.onShared(e=>{g=!0,M=e.canEdit===!0,m!==`legacy`&&(i.disabled=l||m!==`text`||!M,!M&&(x||D)&&(ee||=D,O=!0,P(Error(`Editing access changed. Your unsaved draft is retained.`))),o.has(r)&&m===`loading`&&ae(!0),f())});i.disabled=!0,i.addEventListener(`input`,ce),i.addEventListener(`change`,ce),i.addEventListener(`blur`,de),i.addEventListener(`keydown`,ue),i.addEventListener(`compositionstart`,R),i.addEventListener(`compositionend`,le);let pe=()=>{let e=String(i.value),t=i.hidden||i.closest(`[hidden]`)!==null;return{field:r,nodeId:i.id,type:i.tagName.toLowerCase()===`textarea`?`textarea`:i.type,value:e.slice(0,1e4),partial:e.length>1e4,disabled:i.disabled||l||u||t,ready:m===`text`&&!E&&!b&&!O&&!D&&!C&&!k&&!x&&!j&&M,identity:JSON.stringify([r,i.id,i.type,y?.protocol??null,y?.epoch??null,y?.sourceIdentity??null,y?.textRevision??null])}},me={nativeState:pe,async nativeEdit(e,t){let n=pe();if(!a||typeof t!=`string`||!/^\\d{1,9}$/.test(t)||!e||Object.keys(e).sort().join(`,`)!==`field,identity,previous,value`||e.field!==r||e.identity!==n.identity||n.partial||!n.ready||n.disabled||typeof e.previous!=`string`||e.previous!==n.value||typeof e.value!=`string`||e.value.length>1e4||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(r)||/password|credential|authorization|cookie|secret|token|api.?key/i.test(r)||!i.id||![`text`,`textarea`].includes(n.type))throw Error(`The original named text control changed or is unavailable.`);let o=new Event(`input`,{bubbles:!0});if(s.set(o,t),i.value=e.value,i.dispatchEvent(o),s.delete(o),i.value!==e.value||!x||D||O||b)throw Error(`The original text handler changed or refused this edit.`);let c=S;if(await se(),S!==c||i.value!==e.value||x||j||C||b)throw Error(`Original text changed while its acknowledgement was pending. Do not repeat the edit.`);return{value:i.value,identity:pe().identity}},flush:se,getValue:()=>i.value,status:()=>_?_.getBindingStatus(r):{dirty:x||!!j,saving:!!C||!!k,problem:b,canEdit:M,composing:D,interrupted:O,retryable:te()},setDefault(e){d=String(e??``),_&&_.setSharedDefaults({[r]:e})},refresh(){!b&&!E&&ae()},async retry(){if(!(E||C||k||!te())){if(b=null,i.setCustomValidity(``),j){let e=j;C=h(e.action,r,e.body,e.nativeProof).then(t=>{L(t.snapshot),e.action===`update`&&!b&&!O&&(x=S!==e.version),j=null}).catch(e=>{throw P(e),e}).finally(()=>{C=null,f()}),f(),await C}else await ae(m===`loading`);if(b)throw b;if(i.readOnly=u,A){let e=A;A=null;try{L(e)}catch(e){throw P(e),e}}x&&await se(),f()}},dispose(){E=!0,clearTimeout(w),fe(),_?.dispose(),v?.dispose(),o.delete(r),i.removeEventListener(`input`,ce),i.removeEventListener(`change`,ce),i.removeEventListener(`blur`,de),i.removeEventListener(`keydown`,ue),i.removeEventListener(`compositionstart`,R),i.removeEventListener(`compositionend`,le),i.disabled=l,i.readOnly=u,f()}};return o.set(r,me),g&&ae(!0),me},v=setInterval(()=>{for(let e of o.values())e.refresh()},15e3);return{bind:_,inspectNative(){return[...o.values()].map(e=>e.nativeState()).filter(e=>e.nodeId&&[`text`,`textarea`].includes(e.type)&&!/password|credential|authorization|cookie|secret|token|api.?key/i.test(e.field)).slice(0,50)},async dispatchNative(e,t){if(!e||typeof e.field!=`string`||!o.has(e.field))throw Error(`Inspect an existing original named text field.`);return o.get(e.field).nativeEdit(e,t)},getValues:()=>Object.fromEntries([...o].map(([e,t])=>[e,t.getValue()])),dispose(){u=!0,clearInterval(v),removeEventListener(`message`,g);for(let e of[...o.values()])e.dispose();for(let e of[...s.values(),...c])clearTimeout(e.timer),e.reject(Error(`Block closed before text was acknowledged.`));s.clear(),c.length=0}}}return e.installTextFrame=rs,e})({});',Zn=`(sharedAPI,onStatus)=>{const documentTools=(()=>{const BlockError=(class extends Error {
|
|
10
10
|
constructor(code, message, details = []) {
|
|
11
11
|
super(message);
|
|
12
12
|
this.name = "BlockError";
|
|
@@ -1971,7 +1971,7 @@ label:has(> textarea) {
|
|
|
1971
1971
|
@media (prefers-reduced-motion:reduce){
|
|
1972
1972
|
.sm-player *,.sm-viewer,.sm-viewer *,.sm-expand-btn{transition:none!important;animation:none!important}
|
|
1973
1973
|
}
|
|
1974
|
-
`,wU=`sm.blockZoom.`;function TU(e,t){try{if(!e)return;t===`auto`?localStorage.removeItem(wU+e):localStorage.setItem(wU+e,String(t))}catch{}}function EU(e){if(!e)return 0;let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`)&&t.clientHeight>0)break;t=t.parentElement}let n=t&&t!==document.body?t.getBoundingClientRect():{top:0},r=t&&t!==document.body?t.clientHeight:innerHeight,i=e.getBoundingClientRect().top-n.top+(t&&t!==document.body?t.scrollTop:scrollY);return Math.max(280,Math.round(r-Math.min(i,r*.5)-24))}function DU(e){if(!e)return 0;let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`)&&t.clientHeight>0)break;t=t.parentElement}if(!t||t===document.body)return EU(e);let n=t.getBoundingClientRect(),r=t.scrollTop,i=e.getBoundingClientRect(),a=i.top-n.top+r,o=i.bottom-n.top+r,s=o;for(let e of t.children)/fixed|absolute/.test(getComputedStyle(e).position)||(s=Math.max(s,e.getBoundingClientRect().bottom-n.top+r));let c=s-o+(parseFloat(getComputedStyle(t).paddingBottom)||0);return Math.max(280,Math.round(t.clientHeight*.7),Math.floor(t.clientHeight-Math.min(a,t.clientHeight*.5)-c))}var OU=(e,t)=>Math.round(Math.min(cU,Math.max(sU,e+t))*100)/100,kU=(0,v.createContext)(null),AU=null,jU=new Set,MU=()=>AU;function NU(e){return jU.add(e),()=>jU.delete(e)}function PU(e,t,n){let r=globalThis.modernScreenshot;if(delete globalThis.modernScreenshot,!r)return;let i=!1,a=[],o=new WeakSet,s=e=>{if(e?.nodeType!==1||o.has(e))return;let t=e.getBoundingClientRect();t.width*t.height<400||t.height>900||(a.push({x:t.left,y:t.top,width:t.width,height:t.height}),a.length>40&&a.shift())},c=()=>{i||(i=!0,setTimeout(()=>{i=!1,n({channel:e,session:t,op:`view-changed`,rects:a.splice(0)},`*`)},100))},l=e=>e.type===`childList`&&[...e.addedNodes,...e.removedNodes].every(e=>o.has(e))||o.has(e.target);new MutationObserver(e=>{let t=e.filter(e=>!l(e));if(t.length){for(let e of t)if(e.type===`childList`)for(let t of e.addedNodes)s(t.nodeType===1?t:t.parentElement);else e.type===`characterData`&&s(e.target.parentElement);c()}}).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,characterData:!0});for(let e of[`input`,`change`,`scroll`])addEventListener(e,c,!0);addEventListener(`message`,async i=>{let a=i.data;if(i.source!==parent||!a||a.channel!==e||a.session!==t||a.op!==`capture-view`||typeof a.id!=`string`)return;let s=Math.max(0,Number(a.top)||0),c=Math.min(4e3,Math.max(1,Number(a.height)||innerHeight)),l=document.createElement(`div`);o.add(l);try{l.style.cssText=`all:initial;position:fixed;left:-99999px;top:0;visibility:hidden`;let i=l.attachShadow({mode:`closed`}),o=document.createElement(`div`);i.append(o),document.documentElement.append(l);let u=await r.createContext(document.body,{scale:2,width:innerWidth,height:c,timeout:4e3,features:{restoreScrollPosition:!0},filter:e=>e!==l&&!(/^(VIDEO|AUDIO)$/.test(e.tagName)&&(e.readyState<2||!e.getClientRects().length)),style:{margin:getComputedStyle(document.body).margin,overflow:`visible`,transform:`translateY(${-s}px)`}});u.sandbox={contentWindow:{document:{createElement:e=>document.createElement(e),createElementNS:(e,t)=>document.createElementNS(e,t),body:o},getComputedStyle:(e,t)=>getComputedStyle(e,t)},remove(){}};let d=await createImageBitmap(await r.domToCanvas(u));n({channel:e,session:t,op:`capture-view-result`,id:a.id,bitmap:d},`*`,[d])}catch(r){n({channel:e,session:t,op:`capture-view-result`,id:a.id,error:String(r?.message||r).slice(0,300)},`*`)}finally{l.remove()}})}wt();function FU(e){return V(Array.isArray(e)&&e.length>0&&e.length<=128&&e.every(e=>typeof e==`string`&&/^[a-f0-9]{64}$/.test(e)),`SCHEMA`,`Provide 1–128 exact source digests`),[...new Set(e)]}async function IU(e){pt(e);let t=e?.stages&&e.packages||[];return V(Array.isArray(t)&&t.length<128,`LIMIT`,`Too many packaged Blocks for execution review`),FU(await Promise.all([e,...t].map(e=>ht(e))))}async function LU(e){let t=await IU(e),n=new Set(t),r=e?.stages?e.packages||[]:[e],i=e=>{V(e&&typeof e.digest==`string`&&/^[a-f0-9]{64}$/.test(e.digest),`SCHEMA`,`Block lineage needs exact source digests`),n.add(e.digest),V(n.size<=128,`LIMIT`,`Block source and ancestry exceed the security review limit`)};for(let e of r){let t=e.manifest?.provenance;t?.remixedFrom!==void 0&&i(t.remixedFrom);let n=t?.remixAncestors??[];V(Array.isArray(n)&&n.length<=64,`SCHEMA`,`Block ancestry must contain at most 64 exact source references`),n.forEach(i);let r=e.portable?.lineage?.parents??[];V(Array.isArray(r)&&r.length<=16,`SCHEMA`,`Portable lineage must contain at most 16 exact source references`),r.forEach(i)}return FU([...n])}var RU=`stillmade.block-security.v1`,zU=new Map;function BU(e,t){let n=e?.revision||0,r=t.revision||0;return{revision:Math.max(n,r),published:t.published||e?.published===!0,revoked:n>r?e.revoked:n===r?t.revoked||e?.revoked===!0:t.revoked}}function VU(){try{let e=JSON.parse(globalThis.localStorage?.getItem(RU)||`{}`);for(let[t,n]of Object.entries(e))/^[a-f0-9]{64}$/.test(t)&&n&&typeof n.revoked==`boolean`&&typeof n.published==`boolean`&&Number.isInteger(n.revision)&&n.revision>=0&&zU.set(t,BU(zU.get(t),n))}catch{}return zU}function HU(e){let t=VU();for(let n of e){let e=t.get(n.digest);(n.revoked||n.published||e)&&t.set(n.digest,BU(e,n))}try{globalThis.localStorage?.setItem(RU,JSON.stringify(Object.fromEntries(t)))}catch{}}var UU=()=>Object.assign(Error(`This exact Block version has been quarantined by StillMade. Use a reviewed replacement.`),{code:`BLOCK_REVOKED`});async function WU(e,{signal:t}={}){let n=await LU(e),r=VU();if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});let i=new AbortController,a=()=>i.abort();t?.addEventListener(`abort`,a,{once:!0});let o=setTimeout(a,3e3),s;try{let e=await fetch(`/api/blocks/runtime-policy`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:{"Content-Type":`application/json`},body:JSON.stringify({digests:n}),signal:i.signal});if(!e.ok)throw Error(`Block security check unavailable`);if(s=await e.json(),!Array.isArray(s.digests)||s.digests.length!==n.length||new Set(s.digests.map(e=>e.digest)).size!==n.length||s.digests.some(e=>!n.includes(e.digest)||typeof e.revoked!=`boolean`||typeof e.published!=`boolean`||!Number.isInteger(e.revision)||e.revision<0))throw Error(`Invalid security response`);HU(s.digests)}catch{if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});if(n.some(e=>r.get(e)?.revoked))throw UU();if(n.some(e=>r.get(e)?.published))throw Object.assign(Error(`Reconnect to check the safety of this published Block before running it.`),{code:`REVOCATION_UNAVAILABLE`});return{checked:!1}}finally{clearTimeout(o),t?.removeEventListener(`abort`,a)}if(n.some(e=>VU().get(e)?.revoked))throw UU();return{checked:!0}}lt();var GU=(e,t)=>Object.freeze({kind:e,mimeType:t}),KU=Object.freeze({png:GU(`image`,`image/png`),jpg:GU(`image`,`image/jpeg`),jpeg:GU(`image`,`image/jpeg`),webp:GU(`image`,`image/webp`),gif:GU(`image`,`image/gif`),mp4:GU(`video`,`video/mp4`),mov:GU(`video`,`video/quicktime`),webm:GU(`video`,`video/webm`),mp3:GU(`audio`,`audio/mpeg`),wav:GU(`audio`,`audio/wav`),m4a:GU(`audio`,`audio/mp4`),aac:GU(`audio`,`audio/aac`),ogg:GU(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(rt).map(([e,t])=>[e,GU(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(KU).filter(([,e])=>e.kind!==`file`))),Object.freeze({"text/csv":[`application/vnd.ms-excel`,`text/x-csv`,`application/csv`],"text/markdown":[`text/x-markdown`,`text/plain`],"application/zip":[`application/x-zip-compressed`],"application/json":[`text/json`]}),Object.freeze([`image`,`video`,`audio`]);var qU=Object.freeze({png:`PNG`,jpg:`JPEG`,webp:`WebP`,gif:`GIF`,mp4:`MP4`,mov:`MOV`,webm:`WebM`,mp3:`MP3`,wav:`WAV`,m4a:`M4A`,aac:`AAC`,ogg:`OGG`,pdf:`PDF`,txt:`TXT`,csv:`CSV`,md:`Markdown`,json:`JSON`,zip:`ZIP`}),JU=e=>Object.entries(KU).filter(([t,n])=>e.includes(n.kind)&&qU[t]).map(([e])=>qU[e]),YU=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],XU=e=>YU([...new Set(JU(e))]);async function ZU(e,t,{guard:n,loadBytes:r}={}){let i=typeof t==`string`&&e?.files&&Object.hasOwn(e.files,t)?e.files[t]:null;if(!i||!FH(i))throw Object.assign(Error(`${String(t).slice(0,160)} is not one of this view's code files.`),{code:`VIEW`});if(typeof n!=`string`||!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n))throw Object.assign(Error(`Invalid interface guard`),{code:`VIEW`});let a=$U.get(i.sha256);if(!a)for(a=(async()=>{let n=await uH(e,t,await r(i.sha256)),a;try{a=new TextDecoder(`utf-8`,{fatal:!0}).decode(n)}catch{throw Object.assign(Error(`Code file ${t} is not UTF-8 text.`),{code:`VIEW`})}return vH(a,t,QU)})(),$U.set(i.sha256,a),a.catch(()=>$U.delete(i.sha256));$U.size>eW;)$U.delete($U.keys().next().value);return(await a).replaceAll(QU,n)}var QU,$U,eW,tW=o((()=>{dH(),QU=`__sm_code_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,$U=new Map,eW=48})),nW=c({loadViewAssets:()=>rW,loadViewCode:()=>iW});async function rW(e,{signal:t}={}){let n={};for(let[r,i]of Object.entries(e?.files||{})){if(FH(i))continue;let a=await uH(e,r,await oW(i.sha256,{signal:t}));n[r]={mediaType:i.mediaType,base64:aW(a)}}return n}function iW(e,t,{guard:n}={}){return ZU(e,t,{guard:n,loadBytes:oW})}var aW,oW,sW=o((()=>{dH(),IH(),tW(),aW=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},oW=async(e,{signal:t}={})=>{let n=await fetch(`/__dev/files/`+e,{signal:t});if(!n.ok)throw Error(`A view file is missing from the Block folder.`);return new Uint8Array(await n.arrayBuffer())}}));k(),IH(),wt(),bi();var cW=`stillmade.block.view.v1`,lW=5e3,uW=()=>globalThis.crypto.randomUUID(),dW=`*{box-sizing:border-box}html{container:stillmade-view/inline-size;overflow-wrap:anywhere}body{min-width:0;margin:0;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}h1,h2{font:200 italic clamp(26px,8cqi,32px)/1.1 var(--font-display);letter-spacing:var(--tr-display)}button,input,textarea,select,summary{font:inherit;color:inherit;max-width:100%}button:where(:not(.sm-add,.sm-tile-tools>*)),input,textarea,select{min-height:44px;border:1px solid var(--border-tok);border-radius:var(--r-3);padding:10px 14px;background:transparent}:where(details:not(.sm-hint))>summary{display:flex;align-items:center;min-height:44px;cursor:pointer}.sm-hint>summary{max-width:none}button:where(:not(.sm-add,.sm-tile-tools>*)){min-width:44px;cursor:pointer;border-radius:var(--r-pill);background:var(--fg);color:var(--bg)}button:disabled{opacity:.5;cursor:default}textarea{display:block;width:100%;min-height:120px}input[type=checkbox],input[type=radio]{width:20px;height:20px;min-height:0;padding:0;margin:0 8px 0 0;vertical-align:middle;accent-color:var(--fg)}input[type=range]{width:100%;min-height:32px;padding:0;border:0;accent-color:var(--fg)}img,video,canvas{max-width:100%}:focus-visible{outline:2px solid var(--signal);outline-offset:3px}@container stillmade-view (max-width:360px){body{padding:12px}button,input,textarea,select{font-size:16px}}`,fW=`*{box-sizing:border-box}html{overflow-wrap:anywhere}body{min-width:0;margin:0;padding:16px;overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}body:has(> [data-stillmade-layout="own"]){padding:0}`,pW=`:where(html[data-stillmade-center="1"])>:where(body)>:where(:not([data-stillmade-host])),:where(html[data-stillmade-center="2"])>:where(body)>:where(:not([data-stillmade-host]))>:where(*){margin-inline:auto}`,mW=`html[data-stillmade-pick],html[data-stillmade-pick] *{cursor:crosshair!important}html[data-stillmade-pick] [data-stillmade-media]{display:none!important}`,hW=Object.freeze({image:`image/png,image/jpeg,image/webp,image/gif`,video:`video/*`,audio:`audio/*,video/*`,asset:`image/png,image/jpeg,image/webp,image/gif,audio/*,video/*`,file:Object.entries(KU).filter(([,e])=>e.kind===`file`).map(([e])=>`.${e}`).join(`,`)}),gW=e=>e.filter(e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9_-]{0,99}$/.test(e)),_W=e=>`html[data-stillmade-readonly] [data-stillmade-add]${gW(e).map(e=>`,[data-stillmade-add="${e}"]`).join(``)}{display:none!important}html[data-stillmade-readonly] [data-stillmade-remove],html[data-stillmade-readonly] [data-stillmade-move]${gW(e).map(e=>`,[data-stillmade-remove="${e}"],[data-stillmade-move="${e}"]`).join(``)}{display:none!important}`;function vW(e,t){let n=typeof t==`string`&&_t(e?.inputs)&&Object.hasOwn(e.inputs,t)?e.inputs[t]:null;if(!_t(n))throw Error(`${JSON.stringify(String(t))} is not an input of this Block.`);let r=String(n.type||``),i=r.replace(/\[\]$/,``);if(!Object.hasOwn(hW,i))throw Error(`${JSON.stringify(t)} is a ${r} input. Only image, video, audio, asset and file inputs take added files.`);return{name:t,port:n,type:i,multiple:r.endsWith(`[]`),accept:hW[i]}}function yW(e,t){let n=Array.isArray(e)?e:[],r=e=>Number.isInteger(e)&&e>=0&&e<n.length;if(t?.op===`remove`&&r(t.index))return n.filter((e,n)=>n!==t.index);if(t?.op===`move`&&r(t.from)&&r(t.to)){let e=[...n],[r]=e.splice(t.from,1);return e.splice(t.to,0,r),e}throw Error(n.length?`Choose a file from 0 to ${n.length-1}.`:`This input has no files.`)}function bW({accept:e,multiple:t},n=globalThis.document){let r,i=new Promise(i=>{let a=n.createElement(`input`);a.type=`file`,a.accept=e,a.multiple=!!t,a.hidden=!0;let o=!1;r=e=>{o||(o=!0,a.remove(),i(e))},a.addEventListener(`change`,()=>r(Array.from(a.files||[])),{once:!0}),a.addEventListener(`cancel`,()=>r([]),{once:!0}),n.body.append(a),a.click()});return i.cancel=()=>r([]),i}var xW=e=>JSON.stringify(e).replace(/</g,`\\u003c`).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`);function SW(e){if(pt(e),new TextEncoder().encode(JSON.stringify(e)).length>xH.messageBytes)throw Error(`Preview data exceeds 4 MiB`);return structuredClone(e)}var CW=e=>_t(e)&&[`image`,`video`,`audio`].includes(e.kind)&&[`assetId`,`versionId`,`url`].every(t=>typeof e[t]==`string`&&e[t])?mt([e.kind,e.assetId,e.versionId,e.url]):``;function wW(e){let t=(0,v.useRef)({has:!1,original:null,signature:null,value:null});if(t.current.has&&Object.is(t.current.original,e))return t.current.value;let n=e===void 0?`undefined`:mt(e);return t.current.signature===n?t.current.original=e:t.current={has:!0,original:e,signature:n,value:e},t.current.value}function TW(e,t=[]){return Array.isArray(e)?(e.forEach(e=>TW(e,t)),t):_t(e)?CW(e)?(t.push(e),t):(Object.values(e).forEach(e=>TW(e,t)),t):t}var EW=e=>Array.isArray(e)?e.length>0&&e.every(EW):!!CW(e);function DW(e,t,n){if(!_t(e)||!Object.values(e).length||!Object.values(e).every(EW))throw Error(`Only complete saved media references can be chosen as outputs.`);let r=new Set(TW(t).map(CW));for(let t of TW(e))if(!r.has(CW(t))&&!n?.authorizesMedia(t))throw Error(`Choose media supplied by this workspace or recorded in this session.`);return SW(e)}function OW(e){let t=SW(e);if(!_t(t)||!gt(t,`image`))throw Error(`Choose a valid image supplied by this workspace.`);if(t.role!==void 0&&(typeof t.role!=`string`||!/^[a-z][a-z0-9_]{0,79}$/.test(t.role)))throw Error(`This image has an invalid semantic role.`);if(!Array.isArray(t.data)&&!([`assetId`,`versionId`,`url`].every(e=>typeof t[e]==`string`&&t[e].length>0)&&t.assetId.length<=512&&t.versionId.length<=512&&t.url.length<=32768))throw Error(`Keep the complete image reference supplied by this workspace.`);return t}function kW(e,t=xH.imagePreviewEdge){let n=()=>Error(`The host returned an invalid image preview.`),r=SW(e),i=_t(r)&&Object.keys(r).length===3&&[`url`,`width`,`height`].every(e=>Object.hasOwn(r,e))&&[`width`,`height`].every(e=>Number.isInteger(r[e])&&r[e]>0&&r[e]<=t),a=typeof r?.url==`string`&&/^data:image\/(png|jpeg);base64,[A-Za-z0-9+/]+={0,2}$/.exec(r.url)?.[1];if(!i||!a)throw n();let o=r.url.slice(a===`png`?22:23);if(o.length%4!=0)throw n();if(a===`png`){let e=atob(o.slice(0,44)),t=t=>e.charCodeAt(t),i=e=>t(e)*16777216+t(e+1)*65536+t(e+2)*256+t(e+3);if(e.length<33||![137,80,78,71,13,10,26,10].every((e,n)=>t(n)===e)||i(8)!==13||e.slice(12,16)!==`IHDR`||i(16)!==r.width||i(20)!==r.height)throw n();return r}let s=atob(o.slice(0,4096)),c=e=>s.charCodeAt(e),l=e=>c(e)*256+c(e+1);if(c(0)!==255||c(1)!==216)throw n();for(let e=2;e+9<s.length;){if(c(e)!==255)throw n();let t=c(e+1),i=l(e+2);if(t>=192&&t<=207&&![196,200,204].includes(t)){if(l(e+5)!==r.height||l(e+7)!==r.width)throw n();return r}if(i<2)throw n();e+=2+i}throw n()}var AW=()=>`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`;function jW(e,t,n=`light`,r=`package`,i=!1,a=[],o=null,s=!1,c=!1,{assets:l={},filming:u=null,inputTypes:d=null,frameGuard:f=null}={}){hH(e);let p=PH(e),m=r===`package`?e.appearance??`host`:r;m!==`original`&&!p&&WH(e,{appearance:`host`});let h=(m===`original`?e.css??``:e.themedCss??e.css??``)+`
|
|
1975
|
-
`+(p?``:KH),g=globalThis.crypto.randomUUID().replaceAll(`-`,``),_=`__sm_view_${g}`,v=f||AW(),y=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,b=`(()=>{"use strict";${p?`const codeNonce=document.currentScript.nonce;`:``}document.currentScript.remove();const session=${xW(t)},channel=${xW(cW)},send=parent.postMessage.bind(parent);let input={},ready=false,inputRevision=0,editRevision=0,sequence=0,pending=null,pendingAdopt=null,adoptSequence=0,pendingImage=null,imageSequence=0,pendingDesktop=null,desktopSequence=0,pendingAdd=null,addSequence=0,pendingChange=null,changeSequence=0,voiceSequence=0,pendingAllow=null,allowSequence=0;const pendingVoice=new Map(),voiceURLs=new Map();const addTypes=${xW(_t(d)?d:null)},addLocked=new Set(${xW(a.filter(e=>typeof e==`string`))});const addPortProblem=port=>{if(typeof port!=="string"||!port)return "Name the input to add files to, as in StillMade.addFiles('listingPhotos').";if(!addTypes)return "";if(!Object.hasOwn(addTypes,port))return JSON.stringify(port)+" is not an input of this Block. Name a declared image, video, audio, asset or file input.";if(!/^(image|video|audio|asset|file)(\\[\\])?$/.test(addTypes[port]))return JSON.stringify(port)+" is a "+addTypes[port]+" input. Only image, video, audio, asset and file inputs take added files.";return ""};const filesPortProblem=(port,call)=>{if(typeof port!=="string"||!port)return "Name the list input, as in StillMade."+call+"('listingPhotos', 0).";const problem=addPortProblem(port);if(problem)return problem;if(addTypes&&!addTypes[port].endsWith("[]"))return JSON.stringify(port)+" holds one file. StillMade."+call+" changes a list input; StillMade.addFiles replaces a single file.";return ""};const mediaURLs=new Set();const mintedImages=new Set();Object.defineProperty(globalThis,${xW(y)},{configurable:true,value:url=>mintedImages.has(url)});const clearMedia=()=>{for(const url of mediaURLs)URL.revokeObjectURL(url);mediaURLs.clear()};const listeners=new Set();let calls=0,started=0;const now=performance.now.bind(performance),resetTask=setTimeout.bind(globalThis);let gestureId=0,gestureAt=-Infinity;for(const type of ["pointerdown","keydown"])addEventListener(type,event=>{if(event.isTrusted){gestureId++;gestureAt=now();}},true);${p?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${LH.toString()})(channel,session,send,${xW({guardName:v,taskMs:OH.taskMs,assets:l})});const codeAPI=(${RH.toString()})(channel,session,send,codeNonce);`:`const codeAPI=null;Object.defineProperty(globalThis,${xW(_)},{configurable:true,value:()=>{if(calls===0){started=now();resetTask(()=>{calls=0},0)}if(++calls>10000||now()-started>50)throw Error("Interface is doing too much work. Move processing into the Block runtime.")}});addEventListener("message",event=>{if(event.isTrusted&&event.source===parent)calls=0},true);`}let controlEffects=0;let assisted=false,trackedCalls=new Set(),trackedFailure=null,controlOffset=0;const track=promise=>{if(assisted){trackedCalls.add(promise);promise.then(()=>trackedCalls.delete(promise),error=>{trackedFailure=error;trackedCalls.delete(promise)})}return promise};const controlSnapshot=(offset=controlOffset,automatic=true)=>{try{let snapshot;try{snapshot=dynamicUI.inspectControls({offset})}catch(error){if(!automatic||error.message!=="Choose a current control page"||!Number.isSafeInteger(offset)||offset<0)throw error;snapshot=dynamicUI.inspectControls({offset:0});}controlOffset=snapshot.offset;send({channel,session,op:"view-controls",snapshot},"*")}catch(error){send({channel,session,op:"view-controls-error",error:String(error.message).slice(0,1000)},"*")}};const dynamicUI=(${sr.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${or.toString()})(channel,session,${xW(ir)},sharedLifecycle);const textControls=${i?`(()=>{${Xn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${xW(o)},send});})()`:`null`};const sharedControls=(${Yn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${xW(a)});const {documentTools,sharedDocuments}=(${Zn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${kt.toString()})((kind,value,options)=>{if(kind==="media"){if(mediaURLs.size>=${p?OH.mediaPreviews:2})throw Error("Release a previous media preview before opening another");if(!["image","video","audio"].includes(value.kind))throw Error("Choose a picture, audio or video reference");}return new Promise((resolve,reject)=>{const id=String(++imageSequence);pendingImage={id,resolve,reject,media:kind==="media"};send({channel,session,op:kind==="media"?"preview-media":"preview-image",id,value,...(options?.edge?{edge:options.edge}:{})},"*")})});const connectionAPI=(${Dt.toString()})(${xW(cW)},${xW(t)},${c},send),workAPI=(${D.toString()})(${xW(cW)},${xW(t)},${s},send);const liveBridge=(${Ot.toString()})(${xW(cW)},${xW(t)},send,(operation,args)=>api.desktop(operation,args));const editFiles=(call,port,edit)=>{if(!ready)return Promise.reject(Error("Preview is loading"));const problem=filesPortProblem(port,call);if(problem)return Promise.reject(Object.assign(Error(problem),{code:"FILES_PORT"}));const files=Array.isArray(input[port])?input[port]:[],places=edit.op==="move"?[edit.from,edit.to]:[edit.index];if(!places.every(place=>Number.isInteger(place)&&place>=0&&place<files.length))return Promise.reject(Object.assign(Error(files.length?"Choose a file from 0 to "+(files.length-1)+" in StillMade."+call+".":JSON.stringify(port)+" has no files yet."),{code:"FILES_INDEX"}));if(addLocked.has(port))return Promise.reject(Error("This input comes from an earlier Step, so its files cannot be changed here."));if(assisted)return Promise.reject(Error("Only a person changes files. Chat cannot remove or move them."));if(!sharedAPI.getShared().canEdit)return Promise.reject(Error("You can view this project but not change its files."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Remove or move files from a click or key press in this screen."));if(pendingChange)return Promise.reject(Error("Files are already being changed."));if(edit.op==="move"&&edit.from===edit.to)return Promise.resolve({files:files.length});return new Promise((resolve,reject)=>{const id=String(++changeSequence);pendingChange={id,resolve,reject};send({channel,session,op:"change-files",id,port,edit,item:files[edit.op==="move"?edit.from:edit.index],gesture:{id:gestureId,age:now()-gestureAt}},"*")})};const api=Object.freeze({...connectionAPI,...workAPI,live:liveBridge.live,${p?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,loadCode:codeAPI.load,`:``}connectedApp(...args){controlEffects++;return track(connectionAPI.connectedApp(...args))},sharedWork(...args){controlEffects++;return track(workAPI.sharedWork(...args))},previewSharedWorkMedia(...args){controlEffects++;return track(workAPI.previewSharedWorkMedia(...args))},schemaFields:(${cr.toString()})(${JSON.stringify(a)}),...sharedAPI,...documentTools,updateShared(...args){sharedControls.ownSharing();return sharedAPI.updateShared(...args)},connectDocument(...args){sharedControls.ownSharing();return sharedDocuments.connectDocument(...args)},bindShared:sharedControls.bindShared,setSharedDefaults:sharedControls.setSharedDefaults,scheduleSharedEdit:sharedControls.scheduleSharedEdit,render:dynamicUI.render,onAction:dynamicUI.onAction,releaseMedia(url){if(mediaURLs.delete(url))URL.revokeObjectURL(url)},previewMedia(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("media",value))},desktop(operation,args={}){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingDesktop)return Promise.reject(Error("A desktop request is already pending"));if(typeof operation!=="string"||JSON.stringify(args).length>131072)return Promise.reject(Error("Invalid desktop request"));return track(new Promise((resolve,reject)=>{const id=String(++desktopSequence);pendingDesktop={id,resolve,reject};send({channel,session,op:"desktop",id,operation,args},"*")}))},get input(){return structuredClone(input)},onInput(fn){if(typeof fn!=="function")throw Error("Expected a function");listeners.add(fn);if(ready)fn(structuredClone(input));return()=>listeners.delete(fn)},useOutput(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingAdopt)return Promise.reject(Error("An output choice is already pending"));let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded output values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++adoptSequence);pendingAdopt={id,resolve,reject};send({channel,session,op:"use-output",id,outputs:values},"*")}))},addFiles(port){if(!ready)return Promise.reject(Error("Preview is loading"));const problem=addPortProblem(port);if(problem)return Promise.reject(Object.assign(Error(problem),{code:"ADD_FILES_PORT"}));if(addLocked.has(port))return Promise.reject(Error("This input comes from an earlier Step, so files cannot be added to it here."));if(assisted)return Promise.reject(Error("Only a person adds files. Chat cannot open a file picker."));if(!sharedAPI.getShared().canEdit)return Promise.reject(Error("You can view this project but not add files to it."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Add files from a click or key press in this screen."));if(pendingAdd)return Promise.reject(Error("Files are already being added."));return new Promise((resolve,reject)=>{const id=String(++addSequence);pendingAdd={id,resolve,reject};send({channel,session,op:"add-files",id,port,gesture:{id:gestureId,age:now()-gestureAt}},"*")})},removeFile(port,index){return editFiles("removeFile",port,{op:"remove",index})},moveFile(port,from,to){return editFiles("moveFile",port,{op:"move",from,to})},previewImage(value,options){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value,options))},allowSpending(request){if(!ready)return Promise.reject(Error("Preview is loading"));const credits=request?.credits,label=request?.label;if(!Number.isSafeInteger(credits)||credits<1||credits>${xH.allowanceCredits})return Promise.reject(Error("Name the total in whole credits, from 1 to ${xH.allowanceCredits}, as in StillMade.allowSpending({credits: 24, label: 'Build the panels'})."));if(typeof label!=="string"||!label.trim()||label.length>120)return Promise.reject(Error("Say what the credits are for, in up to 120 characters."));if(assisted)return Promise.reject(Error("Only a person approves spending. Chat cannot."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Ask from a click or key press in this screen."));if(pendingAllow)return Promise.reject(Error("A spending approval is already open."));return new Promise((resolve,reject)=>{const id=String(++allowSequence);pendingAllow={id,resolve,reject};send({channel,session,op:"allow-spending",id,credits,label:label.trim(),gesture:{id:gestureId,age:now()-gestureAt}},"*")})},previewVoice(voice){if(!ready)return Promise.reject(Error("Preview is loading"));if(typeof voice!=="string"||!/^[a-z0-9_-]{1,64}$/.test(voice))return Promise.reject(Error("Name a StillMade voice, as in StillMade.previewVoice('asteria')."));if(voiceURLs.has(voice))return Promise.resolve({url:voiceURLs.get(voice)});if(pendingVoice.size>=4)return Promise.reject(Error("Wait for the voice samples already loading."));return new Promise((resolve,reject)=>{const id=String(++voiceSequence);pendingVoice.set(id,{voice,resolve,reject});send({channel,session,op:"preview-voice",id,voice},"*")})},run(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pending)return Promise.reject(Error("A run is already in progress"));try{dynamicUI.assertCommitted();sharedControls.assertNoComposition();}catch(error){return Promise.reject(error);}let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded input values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++sequence),requested=JSON.parse(serialized),sourceRevision=inputRevision,localRevision=editRevision,call={id,resolve,reject,sent:false};pending=call;Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>{dynamicUI.assertCommitted();sharedControls.assertNoComposition();if(pending!==call||!ready)throw Error("Preview was closed before its edits were saved.");if(inputRevision!==sourceRevision||editRevision!==localRevision)throw Error("The input changed while edits were saving. Review it before running again.");const savedText=textControls?.getValues?.()||{};for(const [key,value] of Object.entries(savedText)){const captured=typeof requested[key]==="string"?requested[key]:typeof requested[key]?.text==="string"?requested[key].text:null;if(captured!==null&&captured!==value)throw Error("The input changed while shared text was saving. Review it before running again.");}if(!sharedAPI.getShared().canEdit)throw Error("Shared editing is unavailable or read only.");call.sent=true;send({channel,session,op:"run",id,input:requested,...(gestureId?{gesture:{id:gestureId,age:now()-gestureAt}}:{})},"*");}).catch(error=>{if(pending===call){pending=null;call.reject(error);}});}))}});Object.defineProperty(globalThis,"StillMade",{value:api,writable:false,configurable:false});sharedAPI.onShared(shared=>document.documentElement?.toggleAttribute("data-stillmade-readonly",!shared.canEdit));if(addTypes)for(const node of document.querySelectorAll("[data-stillmade-add],[data-stillmade-remove],[data-stillmade-move]")){const tool=node.hasAttribute("data-stillmade-add")?"":node.hasAttribute("data-stillmade-remove")?"removeFile":"moveFile",problem=tool?filesPortProblem(node.getAttribute(tool==="removeFile"?"data-stillmade-remove":"data-stillmade-move"),tool):addPortProblem(node.getAttribute("data-stillmade-add"));if(problem){send({channel,session,op:"interface-error",error:problem},"*");break;}}addEventListener("click",event=>{const node=event.isTrusted&&event.target&&typeof event.target.closest==="function"?event.target.closest("[data-stillmade-add]"):null;if(!node||node.disabled||node.getAttribute("aria-disabled")==="true")return;event.preventDefault();if(pendingAdd)return;node.setAttribute("aria-busy","true");api.addFiles(node.getAttribute("data-stillmade-add")).catch(error=>{if(error.code==="ADD_FILES_PORT")send({channel,session,op:"interface-error",error:String(error.message).slice(0,1000)},"*")}).finally(()=>node.removeAttribute("aria-busy"))});addEventListener("click",event=>{const node=event.isTrusted&&event.target&&typeof event.target.closest==="function"?event.target.closest("[data-stillmade-remove],[data-stillmade-move]"):null;if(!node||node.disabled||node.getAttribute("aria-disabled")==="true")return;event.preventDefault();if(pendingChange)return;const remove=node.hasAttribute("data-stillmade-remove"),place=name=>{const text=node.getAttribute(name);return text!==null&&/^[0-9]{1,6}$/.test(text)?Number(text):NaN},port=node.getAttribute(remove?"data-stillmade-remove":"data-stillmade-move");node.setAttribute("aria-busy","true");(remove?api.removeFile(port,place("data-index")):api.moveFile(port,place("data-index"),place("data-to"))).catch(error=>{if(error.code==="FILES_PORT")send({channel,session,op:"interface-error",error:String(error.message).slice(0,1000)},"*")}).finally(()=>node.removeAttribute("aria-busy"))});addEventListener("message",event=>{if(event.source!==parent||!event.data||event.data.channel!==channel||event.data.session!==session)return;const data=event.data;if(liveBridge.receive(data))return;if(data.op==="inspect-view-controls"){controlSnapshot(data.offset,false);return;}if(data.op==="locate-view-control"&&typeof data.id==="string"){let rect=null;try{rect=dynamicUI.locateControl(data.control)}catch{}send({channel,session,op:"view-control-rect",id:data.id,rect},"*");return;}if(data.op==="dispatch-named-text"&&typeof data.id==="string"){Promise.resolve().then(()=>textControls.dispatchNative(data.control,data.id)).then(()=>send({channel,session,op:"named-text-result",token:${xW(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${xW(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${xW(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${xW(o)},snapshot:textControls.inspectNative()},"*");return;}if(data.op==="dispatch-view-control"&&typeof data.id==="string"){if(assisted){send({channel,session,op:"view-control-result",id:data.id,error:"A declared control is already running"},"*");return;}assisted=true;trackedFailure=null;const controlDocumentSeal=sharedDocuments.captureControlSettlement(),controlSharedSeal=sharedLifecycle.captureControlState(),controlInputRevision=inputRevision,controlEffectRevision=controlEffects;const personalControlUnchanged=()=>controlDocumentSeal&&inputRevision===controlInputRevision&&controlEffects===controlEffectRevision&&JSON.stringify(sharedLifecycle.captureControlState())===JSON.stringify(controlSharedSeal)&&!controlSharedSeal.closed&&controlSharedSeal.ready&&!controlSharedSeal.pending&&!controlSharedSeal.queued&&!controlSharedSeal.failed&&sharedDocuments.unchangedControlSettlement(controlDocumentSeal);dynamicUI.dispatchControl(data.control,async()=>{for(let round=0;round<16;round++){await Promise.allSettled(Array.from(trackedCalls));await dynamicUI.flushAll();await sharedControls.flushAll();if(personalControlUnchanged())await sharedDocuments.settleControl(controlDocumentSeal);else await sharedDocuments.flushAll();await sharedLifecycle.flushSharedWrites();await new Promise(resolve=>setTimeout(resolve,0));if(trackedFailure)throw trackedFailure;if(!trackedCalls.size){if(controlDocumentSeal&&!personalControlUnchanged())await sharedDocuments.flushAll();dynamicUI.assertCommitted();sharedControls.assertNoComposition();return;}}throw Error("Declared action did not settle");}).then(()=>send({channel,session,op:"view-control-result",id:data.id},"*"),error=>send({channel,session,op:"view-control-result",id:data.id,error:String(error?.message||"Declared action failed").slice(0,1000)},"*")).finally(()=>{assisted=false;controlSnapshot()});return;}if(data.op==="flush-shared"&&typeof data.id==="string"){Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>dynamicUI.flushAll()).then(()=>sharedControls.assertNoComposition()).then(()=>send({channel,session,op:"flush-shared-result",id:data.id},"*"),error=>send({channel,session,op:"flush-shared-result",id:data.id,error:String(error?.message||"Pending edits could not be confirmed").slice(0,1000)},"*"));return;}if(data.op==="desktop-result"&&pendingDesktop&&data.id===pendingDesktop.id){const call=pendingDesktop;pendingDesktop=null;data.error?call.reject(Error(data.error)):call.resolve(data.result)}else if(data.op==="add-files-result"&&pendingAdd&&data.id===pendingAdd.id){const call=pendingAdd;pendingAdd=null;data.error?call.reject(Error(data.error)):call.resolve({added:Number.isInteger(data.added)&&data.added>=0?data.added:0})}else if(data.op==="change-files-result"&&pendingChange&&data.id===pendingChange.id){const call=pendingChange;pendingChange=null;data.error?call.reject(Error(data.error)):call.resolve({files:Number.isInteger(data.files)&&data.files>=0?data.files:0})}else if(data.op==="use-output-result"&&pendingAdopt&&data.id===pendingAdopt.id){const call=pendingAdopt;pendingAdopt=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="input"){inputRevision+=1;if(pending&&!pending.sent){pending.reject(Error("Preview input changed before its edits were saved."));pending=null;}clearMedia();previews.reset();if(pendingImage)pendingImage.reject(Error("Preview input changed"));pendingImage=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview input changed"));pendingAdopt=null;input=data.input;ready=true;try{sharedControls.useInputDefaults(input)}catch{}for(const fn of listeners)try{fn(structuredClone(input))}catch(error){send({channel,session,op:"interface-error",error:String(error?.message||"The Block interface could not display its input").slice(0,1000)},"*")}}else if(data.op==="result"&&pending?.sent&&data.id===pending.id){const call=pending;pending=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="preview-media-result"&&pendingImage?.media&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error)call.reject(Error(data.error));else{try{const url=URL.createObjectURL(data.preview.blob);mediaURLs.add(url);call.resolve({kind:data.preview.kind,url,mimeType:data.preview.blob.type,bytes:data.preview.blob.size,blob:data.preview.blob})}catch(error){call.reject(error)}}}else if(data.op==="code-result"&&codeAPI&&codeAPI.result(data)){}else if(data.op==="allow-spending-result"&&pendingAllow&&data.id===pendingAllow.id){const call=pendingAllow;pendingAllow=null;data.error?call.reject(Error(data.error)):call.resolve({allowed:data.allowed===true,credits:Number.isSafeInteger(data.credits)?data.credits:0})}else if(data.op==="preview-voice-result"&&pendingVoice.has(data.id)){const call=pendingVoice.get(data.id);pendingVoice.delete(data.id);if(data.error)call.reject(Error(data.error));else{try{const url=voiceURLs.get(call.voice)||URL.createObjectURL(data.blob);voiceURLs.set(call.voice,url);call.resolve({url})}catch(error){call.reject(error)}}}else if(data.op==="preview-image-result"&&pendingImage&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error){call.reject(Error(data.error));}else{const url=data.preview?.url;if(typeof url==="string"){mintedImages.delete(url);mintedImages.add(url);if(mintedImages.size>64)mintedImages.delete(mintedImages.values().next().value)}call.resolve(data.preview)}}else if(data.op==="dispose"){liveBridge.dispose();clearMedia();for(const url of voiceURLs.values())URL.revokeObjectURL(url);voiceURLs.clear();for(const call of pendingVoice.values())call.reject(Error("Block was closed"));pendingVoice.clear();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=null;if(pendingAllow)pendingAllow.reject(Error("Block was closed"));pendingAllow=null;if(pendingAdd)pendingAdd.reject(Error("Block was closed"));pendingAdd=null;if(pendingChange)pendingChange.reject(Error("Block was closed"));pendingChange=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview was reset"));pendingAdopt=null;if(pendingImage)pendingImage.reject(Error("Preview was reset"));pendingImage=null;if(pending)pending.reject(Error("Preview was reset"));pending=null;listeners.clear();ready=false}});addEventListener("input",()=>{editRevision+=1;},true);addEventListener("change",()=>{editRevision+=1;},true);addEventListener("compositionstart",()=>{editRevision+=1;},true);addEventListener("keydown",event=>{if(event.key==="Escape"&&!document.documentElement.hasAttribute("data-stillmade-stage"))send({channel,session,op:"escape"},"*")},true);addEventListener("click",event=>{if(event.target.closest?.("a,area"))event.preventDefault()},true);send({channel,session,op:"ready"},"*");})();`,x=p?`document.currentScript.remove();for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${bH(e.javascript||``,v)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${_})=>{"use strict";delete globalThis[${xW(_)}];for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${gH(e.javascript||``,_)}\n})(globalThis[${xW(_)}]);`.replace(/<\/script/gi,`<\\/script`);return`<!doctype html><html data-mode="${[`dark`,`white`].includes(n)?n:`light`}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${g}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${p?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${p?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${GH.replace(/@font-face\s*\{[^}]*\}/g,``)}${p?fW:dW}${qH}${p?``:pW}${(h||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${mW}${_W(a)}</style></head><body>${e.html}${u?`<script nonce="${g}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${g}">${b.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${g}">document.currentScript.remove();${u?`(${PU.toString()})(${xW(cW)},${xW(t)},parent.postMessage.bind(parent));`:``}(${aU.toString()})(${xW(cW)},${xW(t)});(${oU.toString()})(${xW(cW)},${xW(t)});(${fU.toString()})(${xW(cW)},${xW(t)},(${uU.toString()}),"auto",(${dU.toString()}),${!p});(${pU.toString()})(${xW(cW)},${xW(t)},(${mU.toString().replace(/<\/script/gi,`<\\/script`)})(),${xW(CU)},{minted:(()=>{const read=globalThis[${xW(y)}];delete globalThis[${xW(y)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${XH.toString()})(${xW(cW)},${xW(t)},((validateCursorAnchor)=>(${YH.toString()}))(${JH.toString()}));(${ZH.toString()})(${xW(cW)},${xW(t)},(${$H.toString()}));<\/script><script nonce="${g}">${x}<\/script></body></html>`}function MW({activity:e,declaresFolders:t,session:n}){let[r,i]=(0,v.useState)(!1),a=e?.folders||[],o=e?.entries||[];if(!t&&!o.length)return null;let s=r=>{r.currentTarget.open&&t&&!e&&n.current?.call(`folder.shared`).catch(()=>{})},c=async e=>{i(!0);try{await n.current?.call(`folder.forget`,{folder:e.id})}catch{}finally{i(!1)}};return(0,H.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,H.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,H.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,H.jsx)(`ul`,{children:o.map(e=>(0,H.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,H.jsx)(`p`,{children:`Nothing yet.`})]})}function NW({view:e,input:t={},sharedView:n=null,presenceKey:r=null,peers:i=[],actorId:a=null,onSharedChange:o,sharedText:s=null,sharedWork:c=null,connectedApp:l=null,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y,policyContent:b,policyParent:S,currentAppViewPolicy:D=null,title:O=`Block preview`,height:k=480,fitContent:A=!1,resetKey:j=0,theme:M,appearance:N=`package`,lockedInputKeys:P=[],agentContext:F=null}){let I=wW(e),L=wW(b),ee=wW(S),R=[`comfyui`,`capability`].includes(L?.manifest?.runtime)||!!L?.manifest?.desktopTools?.length||L?.manifest?.runtime===`module`&&!!L?.manifest?.permissions?.capabilities?.length,z=L?.capability?.operation===`image.generate`?9e5:36e4,te=(0,v.useRef)(null),B=(0,v.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y}),ne=(0,v.useRef)(t),[re,ie]=(0,v.useState)(``),[ae,oe]=(0,v.useState)(!1),[se,ce]=(0,v.useState)(0),le=(0,v.useRef)(null),ue=(0,v.useRef)(null),[de,fe]=(0,v.useState)(null),[pe,me]=(0,v.useState)(null),[he,ge]=(0,v.useState)(null),_e=L?.manifest?.id||null,[ve,ye]=(0,v.useState)(`auto`),[be,xe]=(0,v.useState)(null),Se=(0,v.useRef)(ve);Se.current=ve;let Ce=e=>{ye(e),TU(_e,e)},we=(0,v.useRef)(1);we.current=ve===`auto`?be?.zoom||1:ve;let Te=(0,v.useRef)(Ce);Te.current=Ce;let Ee=(0,v.useContext)(kU),De=(0,v.useRef)(Ee);De.current=Ee;let[Oe,ke]=(0,v.useState)(null),[Ae,je]=(0,v.useState)(null),[Me,Ne]=(0,v.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),Pe=(0,v.useRef)(`light`);Pe.current=[`dark`,`white`].includes(M||Me)?M||Me:`light`;let Fe=(0,v.useRef)(l);Fe.current=l;let Ie=(0,v.useRef)(c);Ie.current=c;let Le=(0,v.useRef)(s);Le.current=s;let Re=(0,v.useRef)(!1),[ze,Be]=(0,v.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),Ve=()=>{let e={enabled:!!Le.current,projectId:Le.current?.projectId??null,placementId:Le.current?.placementId??null};Be(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,v.useEffect)(()=>{Re.current||Ve()},[!!s,s?.projectId,s?.placementId]);let He=ze.enabled,Ue=ze.projectId,We=ze.placementId,Ge=!!Ae?.count&&!!(Ae.dirty||Ae.pending||Ae.error);(0,v.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Ne(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Ke=(0,v.useMemo)(()=>{try{let e=SW(t);return{value:e,signature:mt(e)}}catch(e){return{error:e.message}}},[t]);B.current={onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y},ne.current=Ke;let[qe,Je]=(0,v.useState)(null),Ye=D?qe?.handle===D&&qe.allowed:!L||qe?.content===L&&qe.parent===ee&&qe.allowed;(0,v.useEffect)(()=>{if(!L&&!D)return;let e=!0,t=new AbortController;return Je(null),(D?T(D,{signal:t.signal}):Promise.all([L,...ee?[ee]:[]].map(e=>WU(e,{signal:t.signal})))).then(()=>{e&&Je({handle:D,content:L,parent:ee,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&L&&hi(L,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(Je({handle:D,content:L,parent:ee,allowed:!1,error:t.message}),B.current.onError?.(t))}),()=>{e=!1,t.abort()}},[L,ee,D,se]);let Xe=PH(I)&&I.files?I.files:null,[Ze,Qe]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!Xe||!Ye){Qe(null);return}let e=!0,t=new AbortController;return Qe(null),Promise.resolve().then(()=>(hH(I),yi(()=>Promise.resolve().then(()=>(sW(),nW)),void 0))).then(({loadViewAssets:e})=>e(Xe,{signal:t.signal})).then(t=>{e&&Qe({files:Xe,assets:t})},t=>{e&&Qe({files:Xe,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[I,Xe,Ye]);let $e=Xe?Ze?.files===Xe?Ze:{loading:!0}:null,et=JSON.stringify([...new Set(P.filter(e=>typeof e==`string`))].sort()),tt=_t(L?.manifest?.inputs)?mt(Object.fromEntries(Object.entries(L.manifest.inputs).map(([e,t])=>[e,String(t?.type||``)]))):``,nt=[I,$e,j,N,se,a,r,R,z,A,He,Ue,We,et,tt,!!L?.manifest?.sharedWork,L?.capability?.operation],rt=(0,v.useRef)(null);if(!rt.current||nt.some((e,t)=>!Object.is(e,rt.current.inputs[t]))){let e;try{if($e?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if($e?.error)throw Error($e.error);let t=uW(),n=uW(),r=MU(),i=AW();e={session:t,nativeTextToken:n,codeGuard:i,filming:!!r,html:jW(I,t,Pe.current,N,He,JSON.parse(et),n,!!L?.manifest?.sharedWork,L?.capability?.operation===`connection.execute`,{assets:$e?.assets||{},filming:r,inputTypes:tt?JSON.parse(tt):null,frameGuard:i}),locked:JSON.parse(et)}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}rt.current={inputs:nt,document:e}}let it=rt.current.document,at=it?.session;(0,v.useEffect)(()=>{let e=te.current?.contentWindow;e&&at&&e.postMessage({channel:cW,session:at,op:`zoom-mode`,mode:ve},`*`)},[ve,at]);let ot=/\bdata-stillmade-layout\s*=\s*["']?own\b/.test(typeof I?.html==`string`?I.html:``);(0,v.useEffect)(()=>{if(!A||!at)return;let e=null,t=()=>{e=null;let t=te.current?.contentWindow,n=EU(te.current);t&&t.postMessage({channel:cW,session:at,op:`zoom-space`,height:n},`*`),ot&&te.current&&ge(Math.min(3e4,DU(te.current)))},n=()=>{clearTimeout(e),e=setTimeout(t,200)},r=null;if(ot&&te.current&&typeof ResizeObserver==`function`){r=new ResizeObserver(n);for(let e=te.current.parentElement;e&&e!==it.body;e=e.parentElement)r.observe(e)}let i=ot&&!ae?[300,1e3,2500].map(e=>setTimeout(t,e)):[];return addEventListener(`resize`,n),()=>{clearTimeout(e),i.forEach(clearTimeout),r?.disconnect(),removeEventListener(`resize`,n)}},[A,at,ot,ae]);let st=(0,v.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[it.session]),ct=(0,v.useRef)(n);ct.current=n??st;let lt=(0,v.useRef)(n==null);lt.current=n==null;let ut=(0,v.useRef)({session:null,count:0}),dt=(0,v.useRef)(null),ft=(0,v.useRef)(null),pt=(0,v.useRef)(null),gt=(0,v.useRef)(null),V=(0,v.useRef)(null),vt=(0,v.useRef)(null),yt=(0,v.useRef)(null);vt.current={key:r,peers:i,actorId:a};let bt=(0,v.useRef)(null),xt=(0,v.useRef)(null);xt.current={input:Ke.signature,error:Ke.error,view:I,policyContent:L,policyParent:ee,resetKey:j,appearance:N,policyReady:Ye};let St=(0,v.useRef)(null);St.current=mt([F?.projectId,F?.placementId,F?.sourceDigest,a].map(e=>e??null));let[Ct,wt]=(0,v.useState)(null),Tt=mt([At(),a,St.current,it.session,Ke.signature,Ye].map(e=>e??null));(0,v.useEffect)(()=>{let e=!0;if(wt(null),!F?.projectId||!F?.placementId||!F?.sourceDigest||Ke.error||!Ye||a!==At())return()=>{e=!1};let t=Tt;return ht(Ke.value).then(n=>{e&&wt({basis:t,value:{version:1,actorId:a,projectId:F.projectId,placementId:F.placementId,sourceDigest:F.sourceDigest,inputDigest:n}})},()=>{e&&wt(null)}),()=>{e=!1}},[Tt]),Ct?.basis===Tt&&Ct.value;let[Dt,Ot]=(0,v.useState)(null),kt=(0,v.useRef)(null),jt=(0,v.useRef)(null),[Mt,Nt]=(0,v.useState)(null),[Pt,Ft]=(0,v.useState)(!1),[It,Lt]=(0,v.useState)(!1),[Rt,zt]=(0,v.useState)(null);Rt&&Rt.actor===a&&Rt.runtimeActor===At()&&Rt.identity===St.current&&Rt.session===it.session&&Object.keys(Rt.authority).every(e=>Rt.authority[e]===xt.current[e])&&Rt.evidence,{...F},L?.manifest?.id,L?.manifest?.version,it.session,Ke.signature,ct.current?.canEdit,{...F},it.session,Ke.signature,ct.current?.canEdit,(0,v.useEffect)(()=>{if(Ot(null),Nt(null),Lt(!1),Ft(!1),zt(null),ie(``),ge(null),ke(null),je(null),it.error||it.loading||!Ye)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=[],p=0,m=0,h=new Set,g=-1/0,_=-1/0,v=e=>{e.isTrusted&&(g=Date.now())};globalThis.document.addEventListener(`pointerdown`,v,!0),globalThis.document.addEventListener(`keydown`,v,!0);let y,b=0,x=null,S=[],T=null,D=0,O=!1,k=0,j=new Set,M=0,N=null,P=0,ee=0,re=null,ae=0,se=PH(I),ce=null,de=()=>{ce&&globalThis.document.fullscreenElement!==ce&&(ce=null,_e({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,de);let pe=()=>{let t;return t=jz(L,{onStatus:n=>{e&&y===t&&fe(n)},onLive:(n,r)=>{e&&y===t?te.current?.contentWindow?.postMessage({channel:cW,session:it.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&y===t&&me(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};y=pe(),le.current=y,fe(null),me(null);let he=()=>{if(!e||!ct.current?.canEdit)return;let t=y;y=pe(),le.current=y,x=null,fe(null),Promise.resolve(t.close()).catch(()=>{})};ue.current=he;let _e=t=>{e&&te.current?.contentWindow?.postMessage({channel:cW,session:it.session,...t},`*`)},ve=null,ye=0,be=(e,t)=>{let n=ft.current,r=te.current,i=n?.parentElement;if(!n||!r||!i)return;let a=Math.max(0,t?.x??0),o=Math.max(0,t?.y??0),s=Math.min(r.clientWidth,(t?.x??0)+(t?.width??0)),c=Math.min(r.clientHeight,(t?.y??0)+(t?.height??0));if(!t||s<=a||c<=o){n.hidden=!0,delete n.dataset.control;return}let l=r.getBoundingClientRect(),u=i.getBoundingClientRect();n.style.transform=`translate(${l.left+r.clientLeft-u.left-i.clientLeft+a}px,${l.top+r.clientTop-u.top-i.clientTop+o}px)`,n.style.width=`${s-a}px`,n.style.height=`${c-o}px`,n.dataset.control=e,n.hidden=!1};be(null,null),pt.current=n=>{!e||!t||typeof n!=`string`||ve&&Date.now()-ve.at<1e3||(ve={id:`locate-`+ ++ye,control:n,at:Date.now()},_e({op:`locate-view-control`,id:ve.id,control:n}))};let Ce=new Map,Ee=new Set,Oe=0,Ae=!1,Me=(e,t)=>new Promise(n=>{let r=`film-`+ ++Oe,i=setTimeout(()=>{Ce.delete(r),n(null)},6e3);Ce.set(r,e=>{clearTimeout(i),Ce.delete(r),n(e)}),_e({op:e,id:r,...t})}),Ne=it.filming&&te.current?NU({element:te.current,placementId:F?.placementId||null,capture:e=>Me(`capture-view`,e),locate:e=>Me(`locate-view-control`,{control:e}),get drawn(){return Ae},onChange:e=>(Ee.add(e),()=>Ee.delete(e))}):null,ze=null,Be=null,Ge=0,Ke=!1,qe=a,Je=xt.current,Xe=St.current,Ze=(t,n)=>{if(!e||Ke||t?.signal?.aborted||At()!==qe||St.current!==Xe||Be&&ne.current.signature!==Be.inputIdentity||ze&&ne.current.signature!==ze.inputIdentity&&ne.current.signature!==n||Object.keys(Je).filter(e=>e!==`input`).some(e=>Je[e]!==xt.current[e]))throw Ke=!0,Lt(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Qe=e=>{if(!ze)return;let t=ze;ze=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Ft(!1),t.reject(e)};jt.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Ze(r),!t||ze)throw Error(`The declared interface is loading or busy.`);if(e===`dispatch-view-control`&&!r.taskFence)throw Error(`The declared interface requires its active project task.`);let s=String(++Ge),c=()=>{Ke=!0,Lt(!1),i?.abort(),Qe(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,z);ze={id:s,op:e,inputIdentity:ne.current.signature,offset:n.offset,context:r,resolve:a,reject:o,timer:l,abort:c},r.signal?.addEventListener(`abort`,c,{once:!0}),e===`dispatch-view-control`&&Ft(!0),_e({op:e,id:s,...n})}catch(e){o(e)}})},kt.current={request:(e,n)=>new Promise((r,i)=>{try{if(Ze(n),!t||ze||Be||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++Ge),o=()=>{Ke=!0,Lt(!1),Be?.id===a&&(Be=null,Ft(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,z);Be={id:a,field:e.field,inputIdentity:ne.current.signature,context:n,resolve:r,reject:i,timer:s,abort:o},n.signal?.addEventListener(`abort`,o,{once:!0}),Ft(!0),_e({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let $e=()=>{if(Ke)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return ze?.op===`dispatch-view-control`?(Ze(ze.context),ze.context):null},et=!1,tt=0,nt=[],rt=0,at=!1,st=0,ut=[],ht=0,Ct=0,wt=[],Tt=null,Dt=!1,Mt={projectId:Ue,placementId:We,actorId:a},Pt=()=>e&&Le.current?.projectId===Mt.projectId&&Le.current?.placementId===Mt.placementId,It=e=>({message:String(e?.message||`Shared text failed.`).slice(0,1e3),...typeof e?.code==`string`&&/^[A-Z][A-Z0-9_]{0,79}$/.test(e.code)?{code:e.code}:{}}),Rt=Le.current?.projectId&&a?Qn({projectId:Le.current.projectId,actorId:a,headers:$n,onChange:e=>{if(Pt()){if(e.kind===`revoked`){Dt=!0,_e({op:`shared-view`,value:{...ct.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||Tt===null&&(Tt=setTimeout(()=>{Tt=null,t&&Pt()&&!Dt&&_e({op:`text-refresh`})},100)))}}}):null,Bt=Ie.current?.projectId&&a?Qn({projectId:Ie.current.projectId,actorId:a,headers:$n,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(rt++,_e({op:`shared-work-refresh`}))}}):null,Vt=()=>{t&&_e({op:`theme`,mode:Pe.current})};yt.current=Vt;let Ht=`[]`,Ut=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=vt.current,i=!lt.current&&e&&localStorage.getItem(`stillmade:show-shared-cursors`)!==`false`?n.filter(t=>t.user_id!==r&&t.selection?.cursor?.visible&&t.selection.cursor.surface===e).slice(0,50).flatMap(e=>{let t=JH(e.selection.cursor.anchor);return t?[{id:String(e.session_id).slice(0,200),label:String(e.label||`Teammate`).slice(0,120),anchor:t}]:[]}):[],a=JSON.stringify(i);a!==Ht&&(Ht=a,_e({op:`peer-cursors`,peers:i}))};V.current=Ut,window.addEventListener(`stillmade:cursor-preferences`,Ut),window.addEventListener(`storage`,Ut);let Wt=null,Gt=()=>{let e=te.current;if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+e.clientLeft,y:t.top+e.clientTop,right:t.right,bottom:t.bottom}},Kt=()=>{Wt&&(Wt.bounds=Gt())},qt=()=>{Wt&&(Wt=null,window.removeEventListener(`scroll`,Kt,{capture:!0}),window.removeEventListener(`resize`,Kt))},Jt=n=>{let r=n.detail;e&&r?.root?.contains?.(te.current)&&(r.action===`start`&&t&&!Wt?(Wt={bounds:Gt()},window.addEventListener(`scroll`,Kt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Kt),_e({op:`pick-start`})):r.action===`stop`&&Wt&&(qt(),_e({op:`pick-stop`})))};window.addEventListener(QH.control,Jt);let Yt=e=>{ie(e),B.current.onError?.(Object.assign(Error(e),{shown:!0}))},Xt=()=>{e&&(clearInterval(N),re?.disconnect(),Promise.resolve(y?.call(`live.stop`)).catch(()=>{}),Yt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),te.current&&(te.current.src=`about:blank`))};dt.current=se?()=>{e&&(clearInterval(N),Promise.resolve(y?.call(`live.stop`)).catch(()=>{}),Yt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),te.current&&(te.current.src=`about:blank`))}:null;let Zt=()=>{if(typeof PerformanceObserver!=`function`||!PerformanceObserver.supportedEntryTypes?.includes(`longtask`))return;let e=[],t=e=>Array.from(e.attribution||[]).some(e=>e.containerType===`iframe`&&typeof e.containerSrc==`string`&&e.containerSrc.endsWith(`#${it.session}`));re=new PerformanceObserver(n=>{for(let r of n.getEntries()){if(!t(r))continue;let n=r.startTime+r.duration;if(e=e.filter(e=>e.end>n-5e3),e.push({end:n,duration:r.duration}),r.duration>=OH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Xt()}});try{re.observe({type:`longtask`})}catch{re=null}},Qt=()=>{P=Date.now(),N=setInterval(()=>{if(!e)return clearInterval(N);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-P>8e3)return Xt();_e({op:`ping`,id:String(++ee)})},2e3)};oe(!0);let $t=setTimeout(()=>{e&&!t&&(oe(!1),Yt(C()?w():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),te.current&&(te.current.src=`about:blank`))},C()?5e3:15e3),en=e=>{let t=o;t&&(zt(null),o=null,t.controller.abort(),e&&_e({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},tn=()=>{if(!t)return;let e=ne.current;if(e.error){en(`Preview input is unavailable.`),Yt(e.error);return}s!==e.signature&&(en(`Preview input changed. Use its current image.`),s=e.signature,_e({op:`input`,input:e.value}))};bt.current=tn;let nn=null,rn=!1,an=0,on=[],sn=null,cn=0,ln=null,un=Jn(()=>{if(lt.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(sn)return sn.promise;let n=String(++cn),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{sn?.id===n&&(sn=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return sn={id:n,promise:a,resolve:r,reject:i,timer:o},_e({op:`flush-shared`,id:n}),a}),dn=()=>{if(t&&ct.current)try{let e=SW(ct.current),t=mt(e);if(t===nn)return;nn=t,_e({op:`shared-view`,value:e})}catch(e){Yt(e.message)}};gt.current=dn;let fn=t=>{e&<.current&&(ct.current.outputs=t,dn())},pn=r=>{let s=r.data;if(se&&e&&_t(s)&&s.op===`navigated`&&s.channel===cW&&s.session===it.session&&(r.source===null||r.source===te.current?.contentWindow)){dt.current?.();return}if(!e||r.source!==te.current?.contentWindow||!_t(s)||s.channel!==cW||s.session!==it.session)return;if(s.op===`document-ready`){n||(n=!0,_e({op:`document`,html:it.html}));return}if(s.op===`view-changed`){Ae=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>_t(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of Ee)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&Ce.has(s.id)){let e=Ce.get(s.id),t=s.rect;if(!e){s.bitmap?.close?.();return}e(s.op===`capture-view-result`?s.bitmap instanceof ImageBitmap?s.bitmap:null:_t(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`zoom-key`){Te.current(s.step===`auto`?`auto`:OU(we.current,s.step===`bigger`?lU:-lU));return}if(s.op===`media-stage`){let e=te.current,t=globalThis.document;if(!e)return;if(s.on===!0){if(!t.fullscreenElement&&globalThis.navigator?.userActivation?.isActive&&t.activeElement===e&&typeof e.requestFullscreen==`function`){ce=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{ce=null})}catch{ce=null}}}else if(t.fullscreenElement===e){ce=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){xe(e=>{let t={supported:s.supported===!0,zoom:Number.isFinite(s.zoom)?s.zoom:1};return e&&e.supported===t.supported&&e.zoom===t.zoom?e:t});return}if(s.op===`ready`){t||(t=!0,oe(!1),clearTimeout($t),_e({op:`zoom-mode`,mode:Se.current}),A&&_e({op:`zoom-space`,height:EU(te.current)}),se&&(Qt(),Zt()),Vt(),tn(),dn(),Ut(),_e({op:`inspect-view-controls`,offset:0}),_e({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!sn||s.id!==sn.id)return;let e=sn;sn=null,clearTimeout(e.timer);let t=s.error||ln;t?e.reject(Error(String(t).slice(0,1e3))):e.resolve({queued:!0});return}if(s.op===`escape`){let e=Date.now();globalThis.document.activeElement===te.current&&e-M>=300&&(M=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){se&&typeof s.id==`string`&&(P=Date.now());return}if(s.op===`unresponsive`){se&&Xt();return}if(s.op===`interface-error`){Yt(String(s.error||`The Block interface could not display its input`).slice(0,1e3));return}if(s.op===`document-store-status`){let e=s.status;_t(e)&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=8)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&ke(e);return}if(s.op===`text-recovery-status`){let e=s.status;He&&_t(e)&&Object.keys(e).every(e=>[`count`,`dirty`,`pending`,`readonly`,`error`,`retryable`].includes(e))&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=100)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&typeof e.retryable==`boolean`&&je(e);return}if(!t)return;if(s.op===`pick-hover`){if(!Wt)return;let e=rU(s.hover),t=Wt.bounds,n=null;if(e&&t){let r=Math.max(t.x,e.rect.x+t.x),i=Math.max(t.y,e.rect.y+t.y),a=Math.min(t.right,e.rect.x+t.x+e.rect.width),o=Math.min(t.bottom,e.rect.y+t.y+e.rect.height);a>r&&o>i&&(n={...e,rect:{x:r,y:i,width:a-r,height:o-i},cursor:{x:e.cursor.x+t.x,y:e.cursor.y+t.y}})}window.dispatchEvent(new CustomEvent(QH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!Wt)return;qt();let e=s.op===`pick-result`?iU(s.target):null;e?window.dispatchEvent(new CustomEvent(QH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(QH.cancel));return}if(s.op===`named-text-controls`){if(s.token===it.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=SW(s.snapshot);e.every(e=>_t(e)&&typeof e.field==`string`&&typeof e.identity==`string`&&typeof e.value==`string`&&e.value.length<=1e4&&typeof e.partial==`boolean`&&typeof e.ready==`boolean`&&typeof e.disabled==`boolean`)&&Ot(e)}return}if(s.op===`named-text-result`){let e=Be;if(!e||s.id!==e.id||s.token!==it.nativeTextToken)return;try{if(Ze(e.context),s.error)throw Error(String(s.error).slice(0,1e3));e.resolve()}catch(t){e.reject(t)}finally{Be=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Ft(!1)}return}if(s.op===`view-controls`){try{let e=SW(s.snapshot);if(!_t(e)||!Number.isSafeInteger(e.revision)||!Number.isSafeInteger(e.total)||e.total<0||e.total>1e4||!Number.isSafeInteger(e.offset)||!Array.isArray(e.controls)||e.controls.length>20||e.controls.some(e=>!_t(e)||typeof e.id!=`string`||typeof e.identity!=`string`||typeof e.action!=`string`||typeof e.disabled!=`boolean`||typeof e.hidden!=`boolean`))throw Error(`Invalid declared interface controls.`);if(Nt(e),Lt(!Ke),ze?.op===`inspect-view-controls`&&e.offset===ze.offset){let e=ze;Ze(e.context),ze=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Qe(e)}return}if(s.op===`view-control-rect`){if(!ve||s.id!==ve.id)return;let{control:e}=ve,t=s.rect;ve=null,be(e,_t(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`view-controls-error`){Qe(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(ze?.op!==`dispatch-view-control`||s.id!==ze.id)return;let e=ze;try{if(Ze(e.context),s.error)throw Error(String(s.error).slice(0,1e3));ze=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Ft(!1),e.resolve()}catch(e){Qe(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=tt)return;tt=Number(s.id);let t=e=>_e({op:`connected-app-result`,id:s.id,...e}),n=Fe.current,r=xt.current;nt=nt.filter(e=>Date.now()-e<6e4);try{if(L?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Et(s.operation,SW(s.args));if(i.operation!==`tasks`&&!ct.current?.canEdit)throw Error(`This workspace is read only.`);if(et||nt.length>=30)throw Error(`Wait for the current task request.`);et=!0,nt.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Fe.current?.projectId||n.placementId!==Fe.current?.placementId||Object.keys(r).some(e=>r[e]!==xt.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:SW(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{et=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-media-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=st)return;st=Number(s.id);let t=Ie.current,n=xt.current,r=rt,i=e=>_e({op:`shared-work-result`,id:s.id,...e});try{if(!L?.manifest?.sharedWork||!L.manifest.permissions?.project?.includes(`work.shared`)||!t?.previewMedia||typeof s.contributionId!=`string`||!/^[0-9a-f-]{36}$/i.test(s.contributionId))throw Error(`Choose a permitted saved creative in this workspace.`);if(ut=ut.filter(e=>Date.now()-e<6e4),at||ut.length>=60)throw Error(`Wait for the current media preview.`);at=!0,ut.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==rt||Object.keys(n).some(e=>n[e]!==xt.current[e]))throw Error(`This workspace changed before the creative preview.`);if(!(t.media instanceof Blob)||!t.media.size||t.media.size>67108864||![`image`,`video`,`audio`].includes(t.kind)||!t.media.type.startsWith(t.kind+`/`))throw Error(`This preview exceeds the media limit.`);i(t)},e=>i({error:String(e.message||`Media preview failed.`).slice(0,1e3)})).catch(e=>i({error:String(e.message).slice(0,1e3)})).finally(()=>{at=!1})}catch(e){i({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=st)return;st=Number(s.id);let t=e=>_e({op:`shared-work-result`,id:s.id,...e}),n=Ie.current,r=xt.current,i=rt;ut=ut.filter(e=>Date.now()-e<6e4);try{if(!L?.manifest?.permissions?.project?.includes(`work.shared`)||!L.manifest.sharedWork||!n?.request)throw Error(`Shared work is unavailable in this preview. Open the saved Block in its project.`);let a=E(s.operation,SW(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!ct.current?.canEdit)throw Error(`This workspace is read only.`);if(at||ut.length>=60)throw Error(`Wait for the current shared-work request.`);at=!0,ut.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==Ie.current?.projectId||n.placementId!==Ie.current?.placementId||Object.keys(r).some(e=>r[e]!==xt.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==rt){if([`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation))throw Error(`Saved-work access changed. Read its current version.`);t({result:{saved:!0,refreshRequired:!0}});return}t({result:SW(o)})},e=>t({error:String(e.message||`Shared work failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{at=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`text-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=Ct)return;Ct=Number(s.id);let e=e=>_e({op:`text-result`,id:s.id,...e}),t=Le.current,n=ne.current.signature,r=xt.current;if(wt=wt.filter(e=>Date.now()-e<6e4),!He||!Pt()||!t||typeof t.request!=`function`||![`read`,`initialize`,`update`,`reset`].includes(s.action)||typeof s.key!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(s.key)||[`constructor`,`prototype`,`__proto__`].includes(s.key)){e({error:{message:`Shared text is unavailable for this field.`}});return}if(ht>=16||wt.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!Pt()||ne.current.error||ne.current.signature!==n||Object.keys(r).some(e=>r[e]!==xt.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(Dt||s.action!==`read`&&!ct.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=SW(s.body),!_t(a)||new TextEncoder().encode(JSON.stringify(a)).length>5e4||Object.keys(a).some(e=>![`protocol`,`requestId`,`sourceIdentity`,`epoch`,`textRevision`,`value`,`update`].includes(e)))throw Error(`Invalid shared text request.`)}catch(t){e({error:It(t)});return}ht++,wt.push(Date.now()),Promise.resolve().then(async()=>{if(i(),$e()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=Be,n;if(e&&s.action!==`read`){if(Ze(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==it.nativeTextToken||s.nativeText?.callId!==e.id)throw Error(`Unrelated text events cannot use this native task.`);n=e.context}else if(s.nativeText)throw Error(`The original text invocation is no longer current; do not replay.`);return await t.request(s.action,{...a,placementId:t.placementId,fieldKey:s.key},n)}catch(e){if(s.action===`read`&&e.code===`SHARED_TEXT_FIELD_UNSUPPORTED`&&typeof ct.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:SW(t)})}).catch(t=>e({error:It(t)})).finally(()=>{ht--});return}if(s.op===`cursor`){let e=s.cursor;if(_t(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=te.current?.getBoundingClientRect(),n=JH(e.anchor),r=vt.current.key;t&&window.dispatchEvent(new CustomEvent(`stillmade:sandbox-cursor`,{detail:{x:(t.left+e.x*t.width)/Math.max(1,window.innerWidth),y:(t.top+e.y*t.height)/Math.max(1,window.innerHeight),visible:e.visible!==!1,...n&&typeof r==`string`&&r.length>0&&r.length<=200&&!lt.current?{anchor:n,surface:r}:{}}}))}return}if(s.op===`shared-view-update`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=an)return;an=Number(s.id);let t=e=>{ln=e.error?String(e.error):null,_e({op:`shared-view-result`,id:s.id,...e})};if(on=on.filter(e=>Date.now()-e<6e4),rn||on.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!ct.current?.canEdit||!lt.current&&typeof B.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=SW(s.request),new TextEncoder().encode(JSON.stringify(n)).length>ir.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}rn=!0,on.push(Date.now()),Promise.resolve().then(()=>{if(!e||!ct.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if($e(),lt.current){ct.current.state=ar(ct.current.state,n),dn();return}let t=$e();return B.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{rn=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&De.current?.(s.height),A&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&ge(Math.max(280,Math.min(3e4,ot?DU(te.current):s.height)));return}if(s.op===`live-ack`){y?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=b)return;b=Number(s.id);let t=e=>_e({op:`desktop-result`,id:s.id,...e});if(S=S.filter(e=>Date.now()-e<6e4),x||S.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=SW(s.args||{}),JSON.stringify(n).length>131072||!_t(n))throw Error(`Desktop arguments exceed the limit`)}catch(e){t({error:e.message});return}let r=![`tool.status`,`storage.info`,`storage.list`,`storage.read`,`record.status`,`device.info`,`record.cancel`,`session.close`,`live.status`,`live.stop`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`].includes(s.operation)&&(s.operation!==`folder.pick`||s.args?.write===!0);if(r&&!ct.current?.canEdit){t({error:`Desktop changes are unavailable while this workspace is read only.`});return}if(s.operation===`record.cut`){let e=n?.source,r=CW(e),i=[];try{i=TW(ne.current?.value).map(CW)}catch{}if(!r||!(y.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:y};S.push(Date.now()),x=i,Promise.resolve().then(()=>{if(!e||i.native!==y||r&&!ct.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if($e()&&r)throw Error(`Assisted desktop mutations require a task-safe native interface; this control is unavailable.`);return i.native.call(s.operation,n,[`record.cut`,`folder.write`].includes(s.operation)?{received:(()=>{try{return TW(ne.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==y||r&&!ct.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:SW(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{x===i&&(x=null)});return}if(s.op===`add-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=D)return;D=Number(s.id);let t=e=>_e({op:`add-files-result`,id:s.id,...e});try{let n=vW(L?.manifest,s.port);if(!ct.current?.canEdit)throw Error(`You can view this project but not add files to it.`);if(it.locked.includes(n.name))throw Error(`This input comes from an earlier Step, so files cannot be added to it here.`);if($e())throw Error(`Only a person adds files. Chat cannot open a file picker.`);if(typeof B.current.onAddFiles!=`function`)throw Error(`Adding files is unavailable here.`);if(T)throw Error(`Files are already being added.`);let r=s.gesture,i=globalThis.navigator?.userActivation;if(!_t(r)||!Number.isInteger(r.id)||r.id<=0||j.has(r.id)||!Number.isFinite(r.age)||r.age<0||r.age>lW||i&&!i.isActive||globalThis.document.activeElement!==te.current)throw Error(`Add files from a click or key press in this screen.`);j.add(r.id);let a={picker:bW(n)};T=a,a.picker.then(t=>{if(!e||T!==a)throw Error(`This Block closed before the files were added.`);if(!t.length)return{added:0};if(!ct.current?.canEdit)throw Error(`You can view this project but not add files to it.`);return B.current.onAddFiles(n.name,t,n.port)}).then(e=>t({added:Number.isInteger(e?.added)&&e.added>=0?e.added:0}),e=>t({error:String(e?.message||`The files could not be added.`).slice(0,1e3)})).finally(()=>{T===a&&(T=null)})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`change-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=k)return;k=Number(s.id);let e=e=>_e({op:`change-files-result`,id:s.id,...e});try{let t=vW(L?.manifest,s.port);if(!t.multiple)throw Error(`${JSON.stringify(t.name)} holds one file. Only a list input's files are removed or moved.`);if(!ct.current?.canEdit)throw Error(`You can view this project but not change its files.`);if(it.locked.includes(t.name))throw Error(`This input comes from an earlier Step, so its files cannot be changed here.`);if($e())throw Error(`Only a person changes files. Chat cannot remove or move them.`);if(typeof B.current.onChangeFiles!=`function`)throw Error(`Changing files is unavailable here.`);if(O)throw Error(`Files are already being changed.`);let n=s.gesture,r=globalThis.navigator?.userActivation;if(!_t(n)||!Number.isInteger(n.id)||n.id<=0||j.has(n.id)||!Number.isFinite(n.age)||n.age<0||n.age>lW||r&&!r.isActive||globalThis.document.activeElement!==te.current)throw Error(`Remove or move files from a click or key press in this screen.`);let i=_t(s.edit)&&s.edit.op===`remove`?{op:`remove`,index:s.edit.index}:_t(s.edit)&&s.edit.op===`move`?{op:`move`,from:s.edit.from,to:s.edit.to}:null;if(!i)throw Error(`Remove or move one file.`);let a=ne.current.value?.[t.name];if(yW(a,i),mt(SW(s.item??null))!==mt(a[i.op===`move`?i.from:i.index]))throw Error(`These files changed. Look at them again, then try again.`);j.add(n.id),O=!0,Promise.resolve().then(()=>B.current.onChangeFiles(t.name,i,t.port)).then(t=>e({files:Number.isInteger(t?.files)&&t.files>=0?t.files:0}),t=>e({error:String(t?.message||`The files could not be changed.`).slice(0,1e3)})).finally(()=>{O=!1})}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`use-output`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let e=e=>_e({op:`use-output-result`,id:s.id,...e});try{if($e())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(se&&!ct.current?.canEdit)throw Error(`This workspace is read only.`);let t=SW(s.outputs),n=B.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);DW(t,ne.current.value,y),Promise.resolve(n(t)).then(t=>{let n=SW(t);fn(n),e({outputs:n})},t=>e({error:String(t?.message||`The media output could not be saved`).slice(0,1e3)}))}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`code`){if(!se||typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>_e({op:`code-result`,id:s.id,...e});if(++ae>OH.codeFiles*4){t({error:`This interface asked for its code files too many times.`});return}Promise.resolve().then(()=>yi(()=>Promise.resolve().then(()=>(sW(),nW)),void 0)).then(({loadViewCode:e})=>e(I.files,s.path,{guard:it.codeGuard})).then(n=>{e&&t({source:n})},n=>{e&&t({error:String(n?.message||`This code file could not be loaded.`).slice(0,1e3)})});return}if(s.op===`allow-spending`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>_e({op:`allow-spending-result`,id:s.id,...e}),n=_t(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=lW&&!h.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===te.current&&Date.now()-g>lW,r=B.current.onAllowSpending;if(!n){t({error:`Ask from a click or key press in this screen.`});return}if(typeof r!=`function`){t({error:`Spending approvals are for Steps in a project.`});return}if(!Number.isSafeInteger(s.credits)||s.credits<1||s.credits>xH.allowanceCredits||typeof s.label!=`string`||!s.label.trim()||s.label.length>120){t({error:`Name the total in whole credits and what it is for.`});return}h.add(s.gesture.id),Promise.resolve().then(()=>r({credits:s.credits,label:s.label.trim()})).then(n=>{e&&t({allowed:Number.isSafeInteger(n)&&n>0,credits:Number.isSafeInteger(n)?n:0})},n=>{e&&t({error:String(n?.message||`The approval did not open.`).slice(0,1e3)})});return}if(s.op===`preview-voice`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>_e({op:`preview-voice-result`,id:s.id,...e}),n=Date.now();if(f=f.filter(e=>n-e<6e4),f.length>=xH.voicePreviewsPerMinute){t({error:`Voice sample limit reached. Wait a minute before trying again.`});return}f.push(n);let r=B.current.onPreviewVoice;if(typeof r!=`function`||!(L?.manifest?.permissions?.capabilities||[]).includes(`audio.speech`)){t({error:`Voice samples are for Blocks that make speech (audio.speech).`});return}if(typeof s.voice!=`string`||!/^[a-z0-9_-]{1,64}$/.test(s.voice)){t({error:`Name a StillMade voice.`});return}Promise.resolve().then(()=>r(s.voice)).then(n=>{if(e){if(!(n instanceof Blob)||!/^audio\//.test(n.type))throw Error(`The voice sample could not be loaded.`);t({blob:n})}},n=>{e&&t({error:String(n?.message||`The voice sample could not be loaded.`).slice(0,1e3)})});return}if(s.op===`preview-image`||s.op===`preview-media`){let t=s.op===`preview-media`;if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=l)return;zt(null),l=Number(s.id);let n=e=>_e({op:t?`preview-media-result`:`preview-image-result`,id:s.id,...e}),r=Date.now();if(d=d.filter(e=>r-e<6e4),o&&en(),d.length>=xH.imagePreviewsPerMinute){++m<=3&&n({error:`Image preview limit reached. Wait a minute before trying again.`}),m===4&&(Yt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,en(),i?.abort(),te.current&&(te.current.src=`about:blank`));return}d.push(r);let c=t||s.edge===void 0?void 0:s.edge;if(c!==void 0&&!(Number.isInteger(c)&&c>=64&&c<=xH.imagePreviewMaxEdge)){n({error:`Ask for an image preview edge from 64 to ${xH.imagePreviewMaxEdge} pixels.`});return}let u;try{if(u=t?SW(s.value):OW(s.value),t&&(!_t(u)||![`image`,`video`,`audio`].includes(u.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof u[e]==`string`&&u[e].length>0&&u[e].length<=32768)))throw Error(`Keep the complete picture, audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let f=t&&y?.authorizesMedia?.(u)?(e,t)=>Kn(e,t):t?B.current.onPreviewMedia:B.current.onPreviewImage;if(typeof f!=`function`){n({error:t?`Audio/video preview is unavailable in this workspace.`:`Image preview is unavailable in this workspace. Choose an image with the host controls.`});return}let p=new AbortController,h=xt.current,g={controller:p,id:s.id,media:t};o=g;let _=St.current,v=a,b=At(),x=()=>{if(p.signal.aborted||b!==At()||_!==St.current||Object.keys(h).some(e=>h[e]!==xt.current[e]))throw Error(`Image preview input or workspace changed.`)},S=setTimeout(()=>{e&&o===g&&en(`Image preview timed out. Try a smaller image.`)},xH.imagePreviewMs);p.signal.addEventListener(`abort`,()=>clearTimeout(S),{once:!0}),Promise.resolve().then(()=>(x(),f(u,{signal:p.signal,...c?{edge:c}:{}}))).then(r=>{if(e&&!p.signal.aborted&&o===g){if(x(),t&&r?.kind!==u.kind)throw Error(`The host returned a different media kind.`);let e=t?Wn(r):kW(r,c);x(),typeof u.assetId==`string`&&u.assetId.length<=512&&typeof u.versionId==`string`&&u.versionId.length<=512&&zt({actor:v,runtimeActor:b,identity:_,session:it.session,authority:h,evidence:{assetId:u.assetId,versionId:u.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:e.url.startsWith(`data:image/jpeg`)?`image/jpeg`:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!p.signal.aborted&&o===g&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!p.signal.aborted&&o===g&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(S),o===g&&(o=null)});return}if(s.op!==`run`||typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=c)return;c=Number(s.id);let v=e=>_e({op:`result`,id:s.id,...e});if(se&&!ct.current?.canEdit){v({error:`Shared editing is unavailable or read only.`});return}let C=Date.now();if(u=u.filter(e=>C-e<6e4),i||u.length>=xH.runsPerMinute){++p<=3&&v({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),p===4&&(Yt(`Preview paused after too many requests. Reset it to continue.`),e=!1,en(),i?.abort(),te.current&&(te.current.src=`about:blank`));return}let w;try{if(!_t(s.input))throw Error(`Expected input values`);w=SW(s.input)}catch(e){v({error:e.message});return}u.push(C),ie(``);let N=new AbortController;i=N,Re.current=!0,ze?.context.signal?.addEventListener(`abort`,()=>N.abort(),{once:!0});let F=setTimeout(()=>{e&&i===N&&(N.abort(),i=null,v({error:R?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},R?z:15e3);N.signal.addEventListener(`abort`,()=>clearTimeout(F),{once:!0});let ee=ze?.op===`dispatch-view-control`?ze:null,re=ee?async e=>{if(ze!==ee||i!==N||N.signal.aborted||!_t(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||mt(e.taskFence)!==mt(ee.context.taskFence)||mt([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==Xe||mt(SW(e.beforeInput))!==ee.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=mt(SW(e.input));for(let e=0;e<25&&ne.current.signature!==t;e++)if(Ze(ee.context,t),await new Promise(e=>setTimeout(e,10)),ze!==ee||i!==N||N.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Ze(ee.context,t),ne.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);ee.inputIdentity=t}:void 0,le=_t(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=lW&&!h.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===te.current&&Date.now()-g>lW&&Date.now()-_>lW;le&&(h.add(s.gesture.id),_=Date.now()),Promise.resolve().then(()=>B.current.onRun(w,{...$e(),signal:N.signal,userActivated:le,...re?{onInputCommitted:re}:{},...L?.manifest?.desktopTools?.length?{nativeDesktopSession:y}:{}})).then(t=>{if(e&&!N.signal.aborted){if(!_t(t))throw Error(`Block execution must return named outputs`);let e=SW(t);fn(e),v({outputs:e})}},t=>{e&&!N.signal.aborted&&v({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!N.signal.aborted&&v({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(F),i===N&&(i=null),Re.current=!1,setTimeout(()=>{e&&!Re.current&&Ve()},250)})};return window.addEventListener(`message`,pn),()=>{T?.picker.cancel(),globalThis.document.removeEventListener(`fullscreenchange`,de),ce&&globalThis.document.fullscreenElement===ce&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),ce=null,pt.current=null,be(null,null),Ne?.();for(let e of[...Ce.values()])e(null);Be&&=(clearTimeout(Be.timer),Be.context.signal?.removeEventListener(`abort`,Be.abort),Be.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,v,!0),globalThis.document.removeEventListener(`keydown`,v,!0),kt.current=null,Qe(Error(`The declared interface was closed.`)),jt.current=null,Rt?.(),Bt?.(),clearTimeout(Tt),un(),sn&&=(clearTimeout(sn.timer),sn.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout($t),clearInterval(N),re?.disconnect(),_e({op:`dispose`}),e=!1,y.close(),le.current===y&&(le.current=null),ue.current===he&&(ue.current=null),en(),i?.abort(),Re.current=!1,window.removeEventListener(`message`,pn),window.removeEventListener(`stillmade:cursor-preferences`,Ut),window.removeEventListener(`storage`,Ut),window.removeEventListener(QH.control,Jt),qt(),V.current=null,bt.current=null,gt.current=null}},[it,Ye,R,z,A,r,a,Ue,We]),(0,v.useEffect)(()=>{bt.current?.()},[t]),(0,v.useEffect)(()=>{gt.current?.(),n?.canEdit===!1&&Promise.resolve(le.current?.close()).catch(()=>{})},[n,Ye]),(0,v.useEffect)(()=>{V.current?.()},[i,r,a,n]),(0,v.useEffect)(()=>{yt.current?.()},[M,Me]);let Bt=!!globalThis.stillmadeDesktop?.blockDesktop,Vt=de?.camera&&de?.microphone?`camera and microphone`:de?.camera?`camera`:`microphone`;return(0,H.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[de?.kind===`live`&&de.awaitingStart&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:`Ready to share your ${Vt} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:de.start,children:`Start ${Vt}`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>le.current?.close(),children:`Cancel`})]}),de?.kind===`live`&&de.active&&(0,H.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,H.jsx)(`strong`,{children:`${Vt[0].toUpperCase()}${Vt.slice(1)} on`}),(0,H.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:de.stop,children:`Turn off ${Vt}`})]}),de?.awaitingStart&&(de.kind===`folder`||de.kind===`folder-access`)&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:de.kind===`folder`?`This Block asks for a folder to ${de.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${de.folder} again for this Block.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:de.start,children:de.kind===`folder`?`Choose folder`:`Allow`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>de.cancel?de.cancel():le.current?.close(),children:`Cancel`})]}),de?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(de.kind)&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:de.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:de.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:de.microphone?`Ready to record your screen with your microphone. Choose your screen or window after pressing Start.`:`Ready to record. Choose your screen or window after pressing Start.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:de.start,children:de.kind===`camera`?`Start camera recording`:de.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>le.current?.close(),children:`Cancel`})]}),de?.active&&de.kind!==`live`&&(0,H.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,H.jsxs)(`strong`,{children:[de.ended?`Recording stopped`:`Recording`,` `,de.kind||`media`]}),(0,H.jsxs)(`span`,{children:[` · `,de.ended?de.message:Bt?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>le.current?.close(),children:Bt?`Cancel recording and revoke access`:`Discard recording`})]}),Bt&&de?.closed&&L?.manifest?.permissions?.desktop?.length>0&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:!Ye||!ct.current?.canEdit,onClick:()=>ue.current?.(),children:`Reopen desktop access`}),Bt&&!de?.closed&&!de?.active&&L?.manifest?.permissions?.desktop?.length>0&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>le.current?.close(),children:`Revoke this Block’s desktop access`}),it.loading?(0,H.jsx)(gr,{label:`Loading the interface…`}):it.error?(0,H.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,it.error]}):Ye?(0,H.jsxs)(H.Fragment,{children:[ae&&!re&&(0,H.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,H.jsx)(`iframe`,{ref:te,onLoad:()=>{ut.current.session!==it.session&&(ut.current={session:it.session,count:0}),++ut.current.count>2&&dt.current?.()},title:O,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${x(`/block-ui-sandbox.html`)}#${it.session}`,style:{width:`100%`,height:A&&he||k,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...re?{display:`none`}:{}}},it.session),(0,H.jsx)(`span`,{ref:ft,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}})]}):(0,H.jsx)(`p`,{role:qe?.error?`alert`:`status`,children:qe?.error||`Checking Block safety…`}),Oe?.count>0&&(Oe.error?(0,H.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:Oe.error}):Oe.dirty||Oe.pending?(0,H.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),Ae?.count>0&&(Ae.error||Ae.dirty||Ae.pending)?(0,H.jsxs)(`div`,{className:`bs-notice`,role:Ae.error?`alert`:`status`,children:[(0,H.jsx)(`p`,{children:Ae.error||`Saving shared text…`}),Ae.error&&(0,H.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),Ae.retryable&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:Ae.pending>0||!ct.current?.canEdit,onClick:()=>te.current?.contentWindow?.postMessage({channel:cW,session:it.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(re||qe?.error)&&(0,H.jsxs)(H.Fragment,{children:[re&&(0,H.jsx)(`p`,{role:`alert`,children:re}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:Ge,onClick:()=>{Ge||ce(e=>e+1)},children:`Reload`})]}),(0,H.jsx)(MW,{activity:pe,declaresFolders:(L?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:le})]})}lt();var PW=50,FW=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var IW=e=>e==null?``:typeof e==`number`?FW.format(e):String(e);function LW(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}function RW({value:e,label:t=`Table`}){let[n,r]=(0,v.useState)(0);if(!Je(e))return(0,H.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/PW)),a=Math.min(n,i-1),o=e.rows.slice(a*PW,a*PW+PW),s=e.columns.map(t=>e.rows.length>0&&e.rows.every(e=>e[t]===void 0||e[t]===null||typeof e[t]==`number`));return(0,H.jsxs)(`div`,{className:`bd-table`,children:[(0,H.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,H.jsxs)(`table`,{children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{children:e.columns.map(e=>(0,H.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,H.jsx)(`tbody`,{children:o.map((t,n)=>(0,H.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,H.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:IW(t[e])},e))},a*PW+n))})]})}),(0,H.jsxs)(`div`,{className:`bd-bar`,children:[(0,H.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>LW(new Blob([Qe(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}wt(),lt();var zW=new Set([`image`,`audio`,`video`]),BW=e=>zW.has(e?.kind)&&typeof e.url==`string`,VW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,HW=e=>{let t=String(e).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},UW=50,WW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),GW=e=>{if(!_t(e))return e;let t=WW(e);return t.length===1&&(Array.isArray(e[t[0]])||_t(e[t[0]]))?GW(e[t[0]]):e},KW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),qW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``);function JW(e){if(e.length<2||!e.every(e=>_t(e)&&WW(e).every(t=>KW(e[t]))))return null;let t=[...new Set(e.flatMap(WW))];if(!t.length||t.length>6)return null;let n={columns:t.map(HW),rows:e.map(e=>Object.fromEntries(WW(e).map(t=>[HW(t),typeof e[t]==`boolean`?qW(e[t]):e[t]])))};return Je(n)?n:null}function YW({value:e,renderMedia:t,depth:n=0}){let r=GW(e);if(KW(r))return(0,H.jsx)(`span`,{children:qW(r)});if(BW(r))return t?.(r)??null;if(Je(r))return(0,H.jsx)(RW,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,H.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(BW)&&JW(r);return e?(0,H.jsx)(RW,{value:e,label:`Results`}):n>=3?(0,H.jsx)(`span`,{children:VW(r.length,`item`)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,UW).map((e,r)=>(0,H.jsx)(`li`,{children:(0,H.jsx)(YW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>UW&&(0,H.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-UW,` more.`]})]})}if(!_t(r))return null;let i=WW(r);return i.length?n>=3?(0,H.jsx)(`span`,{children:VW(i.length,`detail`)}):(0,H.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,H.jsxs)(v.Fragment,{children:[(0,H.jsx)(`dt`,{children:HW(e)}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(YW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,H.jsx)(`span`,{className:`sm-data-none`,children:`None`})}var XW=[`M3 8V5a2 2 0 0 1 2-2h3M16 3h3a2 2 0 0 1 2 2v3M21 16v3a2 2 0 0 1-2 2h-3M8 21H5a2 2 0 0 1-2-2v-3`,`M6.5 12s2.2-3.8 5.5-3.8 5.5 3.8 5.5 3.8-2.2 3.8-5.5 3.8S6.5 12 6.5 12Z`],ZW={cx:12,cy:12,r:1.8},QW=[`M10.3 17.5H4.5a2 2 0 0 1-2-2v-10a2 2 0 0 1 2-2h13a2 2 0 0 1 2 2v7.7`,`M2.5 7h17M6 5.25h10`,`M6 9.5h4a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1Z`,`M5.3 14.2l2.2-2.4 1.6 1.5 1.1-1M13.5 10h3.5M13.5 12.3h2`,`M12 18s2-3.2 5.5-3.2S23 18 23 18s-2 3.2-5.5 3.2S12 18 12 18Z`],$W={cx:17.5,cy:18,r:1.3};function eG(e){switch(e){case`minus`:return(0,H.jsx)(`path`,{d:`M5 12h14`});case`messageCircle`:return(0,H.jsx)(`path`,{d:`M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8z`});case`arrowLeft`:return(0,H.jsx)(`path`,{d:`M20 12H4M11 5l-7 7 7 7`});case`link`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 .5l3-3a5 5 0 0 0-7-7l-2 2`}),(0,H.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7-.5l-3 3a5 5 0 0 0 7 7l2-2`})]});case`unlink`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`m18.8 12.3 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7`}),(0,H.jsx)(`path`,{d:`m5.2 11.7-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7`}),(0,H.jsx)(`path`,{d:`M8 2v3M2 8h3M16 19v3M19 16h3`})]});case`copy`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`9`,y:`9`,width:`12`,height:`12`,rx:`2`}),(0,H.jsx)(`path`,{d:`M15 9V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h4`})]});case`arrowUp`:return(0,H.jsx)(`path`,{d:`M12 20V4M5 11l7-7 7 7`});case`star`:return(0,H.jsx)(`path`,{d:`M12 3.5l2.6 5.3 5.9.9-4.25 4.15 1 5.85L12 16.95 6.75 19.7l1-5.85L3.5 9.7l5.9-.9z`});case`arrowUpRight`:return(0,H.jsx)(`path`,{d:`M7 17 17 7M8 7h9v9`});case`arrowDown`:return(0,H.jsx)(`path`,{d:`M12 4v16M5 13l7 7 7-7`});case`thumbsUp`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M7 10v11H3V10Z`}),(0,H.jsx)(`path`,{d:`M7 18c2 0 3 3 7 3h2.5a2 2 0 0 0 1.9-1.4l2.4-7A2 2 0 0 0 18.9 10H14l.7-3.5A3 3 0 0 0 11.8 3L7 10Z`})]});case`thumbsDown`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M7 14V3H3v11Z`}),(0,H.jsx)(`path`,{d:`M7 6c2 0 3-3 7-3h2.5a2 2 0 0 1 1.9 1.4l2.4 7a2 2 0 0 1-1.9 2.6H14l.7 3.5a3 3 0 0 1-2.9 3.5L7 14Z`})]});case`undo`:return(0,H.jsx)(`path`,{d:`M3 10h11a7 7 0 0 1 0 14M3 10l5-5M3 10l5 5`,transform:`translate(0 -3)`});case`redo`:return(0,H.jsx)(`path`,{d:`M21 7H10a7 7 0 0 0 0 14M21 7l-5-5M21 7l-5 5`});case`remix`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M5 5h5a5 5 0 0 1 5 5v9`}),(0,H.jsx)(`path`,{d:`m11 15 4 4 4-4`}),(0,H.jsx)(`path`,{d:`M5 19h2`}),(0,H.jsx)(`circle`,{cx:`5`,cy:`5`,r:`2`}),(0,H.jsx)(`circle`,{cx:`5`,cy:`19`,r:`2`})]});case`more`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,H.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]});case`palette`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`13.5`,cy:`6.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`17`,cy:`11`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`8.5`,cy:`7.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`6.5`,cy:`12.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`path`,{d:`M12 3a9 9 0 0 0 0 18c1 0 1.6-.8 1.6-1.6 0-.5-.2-.8-.4-1.1-.3-.3-.4-.6-.4-1.1A1.6 1.6 0 0 1 14.3 15h1.9A4.8 4.8 0 0 0 21 10.2C21 6 16.9 3 12 3Z`})]});case`lock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 8 0v4`})]});case`unlock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 7.9-1`})]});case`pushpin`:return(0,H.jsxs)(`g`,{transform:`rotate(35 12 12)`,children:[(0,H.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`}),(0,H.jsx)(`path`,{d:`M12 14v7`})]});case`pushpinFilled`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`M12 14v7`})]});case`pin`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 21s7-5.7 7-11a7 7 0 0 0-14 0c0 5.3 7 11 7 11Z`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`10`,r:`2.5`})]});case`user`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,H.jsx)(`path`,{d:`M5 21a7 7 0 0 1 14 0`})]});case`image`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,H.jsx)(`path`,{d:`m21 15-5-5L5 21`})]});case`imageOff`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M2 2l20 20`}),(0,H.jsx)(`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`}),(0,H.jsx)(`path`,{d:`M13.5 13.5 6 21`}),(0,H.jsx)(`path`,{d:`m18 12 3 3`}),(0,H.jsx)(`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`}),(0,H.jsx)(`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`})]});case`film`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4`})]});case`folder`:return(0,H.jsx)(`path`,{d:`M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z`});case`list`:return(0,H.jsx)(`path`,{d:`M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01`});case`grid`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1.5`})]});case`zap`:return(0,H.jsx)(`path`,{d:`M13 2 4 14h7l-1 8 9-12h-7Z`});case`plug`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 22v-5M9 8V2M15 8V2`}),(0,H.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});case`book`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,H.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2Z`})]});case`bookOpen`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 7v14`}),(0,H.jsx)(`path`,{d:`M3 5v14h6a3 3 0 0 1 3 3 3 3 0 0 1 3-3h6V5h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3Z`})]});case`input`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`}),(0,H.jsx)(`path`,{d:`m10 17 5-5-5-5`}),(0,H.jsx)(`path`,{d:`M15 12H3`})]});case`upload`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 16V4M7 9l5-5 5 5`}),(0,H.jsx)(`path`,{d:`M5 20h14`})]});case`download`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 4v12M7 11l5 5 5-5`}),(0,H.jsx)(`path`,{d:`M5 20h14`})]});case`save`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M5 3h11l3 3v15H5Z`}),(0,H.jsx)(`path`,{d:`M8 3v5h7M8 21v-7h8v7`})]});case`search`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,H.jsx)(`path`,{d:`m20 20-3.5-3.5`})]});case`magnet`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M6 4h4v8a2 2 0 0 0 4 0V4h4v8a6 6 0 0 1-12 0Z`}),(0,H.jsx)(`path`,{d:`M6 8h4M14 8h4`})]});case`bot`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`4`,y:`8`,width:`16`,height:`11`,rx:`2`}),(0,H.jsx)(`path`,{d:`M12 8V4M9 13h.01M15 13h.01M9 16h6`})]});case`note`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`4`,y:`3`,width:`16`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 8h8M8 12h8M8 16h5`})]});case`clock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`path`,{d:`M12 7v5l3 2`})]});case`calendar`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`5`,width:`18`,height:`16`,rx:`2`}),(0,H.jsx)(`path`,{d:`M16 3v4M8 3v4M3 10h18`})]});case`hourglass`:return(0,H.jsx)(`path`,{d:`M6 3h12M6 21h12M7 3c0 5 5 6 5 9s-5 4-5 9M17 3c0 5-5 6-5 9s5 4 5 9`});case`edit`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 20h9`}),(0,H.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`music`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M9 18V5l12-2v13`}),(0,H.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,H.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]});case`mic`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`}),(0,H.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,H.jsx)(`path`,{d:`M12 19v3`})]});case`target`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]});case`pointer`:return(0,H.jsx)(`path`,{d:`M4.5 3.5 20 10.4l-6.5 1.9a1.9 1.9 0 0 0-1.3 1.3L10.3 20z`,strokeLinejoin:`round`});case`sprout`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 21V9`}),(0,H.jsx)(`path`,{d:`M12 9C9 9 6 7 6 4c3 0 6 2 6 5ZM12 12c3 0 6-2 6-5-3 0-6 2-6 5Z`})]});case`hand`:return(0,H.jsx)(`path`,{d:`M8 13V5a1.5 1.5 0 0 1 3 0v6M11 11V4a1.5 1.5 0 0 1 3 0v7M14 11V6a1.5 1.5 0 0 1 3 0v8a6 6 0 0 1-6 6h-1a6 6 0 0 1-5.2-3l-2-3.5a1.5 1.5 0 0 1 2.6-1.5L8 14`});case`scissors`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,H.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.5`}),(0,H.jsx)(`path`,{d:`M8 8l12 8M8 16 20 8`})]});case`maximize`:return(0,H.jsx)(`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3M16 3h3a2 2 0 0 1 2 2v3M21 16v3a2 2 0 0 1-2 2h-3M3 16v3a2 2 0 0 0 2 2h3`});case`settings`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,H.jsx)(`path`,{d:`M19.4 15a1.6 1.6 0 0 0 .3 1.8 2 2 0 1 1-2.8 2.8 1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5 2 2 0 1 1-4 0 1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3 2 2 0 1 1-2.8-2.8 1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1 2 2 0 1 1 0-4 1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8 2 2 0 1 1 2.8-2.8 1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5 2 2 0 1 1 4 0 1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3 2 2 0 1 1 2.8 2.8 1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1 2 2 0 1 1 0 4 1.6 1.6 0 0 0-1.5 1Z`})]});case`scale`:return(0,H.jsx)(`path`,{d:`M12 3v18M7 21h10M6 7h12M6 7 3 14h6ZM18 7l-3 7h6ZM3 14a3 3 0 0 0 6 0M15 14a3 3 0 0 0 6 0`});case`checkbox`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`m8 12 3 3 5-6`})]});case`warning`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M10.3 4 2.6 17a2 2 0 0 0 1.7 3h15.4a2 2 0 0 0 1.7-3L13.7 4a2 2 0 0 0-3.4 0Z`}),(0,H.jsx)(`path`,{d:`M12 9v4M12 17h.01`})]});case`sparkle`:return(0,H.jsx)(`path`,{d:`M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z`});case`check`:return(0,H.jsx)(`path`,{d:`m5 12 5 5 9-10`});case`x`:return(0,H.jsx)(`path`,{d:`M6 6 18 18M18 6 6 18`});case`plus`:return(0,H.jsx)(`path`,{d:`M12 5v14M5 12h14`});case`refresh`:return(0,H.jsx)(`path`,{d:`M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M3 21v-5h5`});case`play`:return(0,H.jsx)(`path`,{d:`M7 4v16l13-8Z`});case`preview`:return(0,H.jsxs)(H.Fragment,{children:[XW.map(e=>(0,H.jsx)(`path`,{d:e},e)),(0,H.jsx)(`circle`,{...ZW})]});case`listingPreview`:return(0,H.jsxs)(H.Fragment,{children:[QW.map(e=>(0,H.jsx)(`path`,{d:e},e)),(0,H.jsx)(`circle`,{...$W})]});case`pause`:return(0,H.jsx)(`path`,{d:`M9 5v14M15 5v14`});case`playFilled`:return(0,H.jsx)(`path`,{d:`M7 4.6v14.8c0 .8.9 1.2 1.5.8l11.4-7.4a1 1 0 0 0 0-1.6L8.5 3.8C7.9 3.4 7 3.8 7 4.6Z`,fill:`currentColor`,stroke:`none`});case`pauseFilled`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`})]});case`volume2`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14`})]});case`volumeX`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`m22 9-6 6M16 9l6 6`})]});case`minimize`:return(0,H.jsx)(`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3M21 8h-3a2 2 0 0 1-2-2V3M3 16h3a2 2 0 0 1 2 2v3M16 21v-3a2 2 0 0 1 2-2h3`});case`stop`:return(0,H.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`});case`chevronRight`:return(0,H.jsx)(`path`,{d:`m9 6 6 6-6 6`});case`chevronLeft`:return(0,H.jsx)(`path`,{d:`m15 6-6 6 6 6`});case`chevronDown`:return(0,H.jsx)(`path`,{d:`m6 9 6 6 6-6`});case`trash`:return(0,H.jsx)(`path`,{d:`M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-13`});case`layers`:return(0,H.jsx)(`path`,{d:`m12 3 9 5-9 5-9-5Zm9 9-9 5-9-5m18 4-9 5-9-5`});case`type`:return(0,H.jsx)(`path`,{d:`M4 6V4h16v2M12 4v16M9 20h6`});case`home`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M3 10.5 12 3l9 7.5`}),(0,H.jsx)(`path`,{d:`M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5`}),(0,H.jsx)(`path`,{d:`M9 21v-6h6v6`})]});case`menu`:return(0,H.jsx)(`path`,{d:`M4 6h16M4 12h16M4 18h16`});case`logout`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,H.jsx)(`path`,{d:`M16 17l5-5-5-5`}),(0,H.jsx)(`path`,{d:`M21 12H9`})]});case`help`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`path`,{d:`M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3`}),(0,H.jsx)(`path`,{d:`M12 17h.01`})]});case`bug`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`m8 2 1.9 1.9M14.1 3.9 16 2`}),(0,H.jsx)(`path`,{d:`M9 7.1v-1a3 3 0 1 1 6 0v1`}),(0,H.jsx)(`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`}),(0,H.jsx)(`path`,{d:`M12 20v-9`}),(0,H.jsx)(`path`,{d:`M6.5 9C4.6 8.8 3 7.1 3 5M6 13H2M3 21c0-2.1 1.7-3.9 3.8-4M21 5c0 2.1-1.6 3.8-3.5 4M22 13h-4M17.2 17c2.1.1 3.8 1.9 3.8 4`})]});default:return null}}function tG({name:e,size:t=`1em`,style:n,className:r,strokeWidth:i=1.5}){let a=eG(e);return a?(0,H.jsx)(`svg`,{viewBox:`0 0 24 24`,width:t,height:t,fill:`none`,stroke:`currentColor`,strokeWidth:i,strokeLinecap:`round`,strokeLinejoin:`round`,className:r,style:{display:`inline-block`,verticalAlign:`-0.14em`,flexShrink:0,...n||{}},"aria-hidden":`true`,children:a}):null}function nG(e,t){let n=(0,v.useRef)(t),r=_U(e),[i,a]=(0,v.useState)(null);return n.current=t,(0,v.useEffect)(()=>{if(!r)return;let t=!0;return Promise.resolve().then(()=>n.current?.(e)).then(n=>{t&&a({src:e,url:n||null})},()=>{t&&a({src:e,url:null})}),()=>{t=!1}},[e,r]),r?i?.src===e?{url:i.url,missing:!i.url}:{url:null,missing:!1}:{url:e||null,missing:!1}}function rG({src:e,resolveUrl:t,label:n,"aria-label":r,fill:i=!1,className:a,style:o,onMissing:s,controls:c,playsInline:l,preload:u=`metadata`,...d}){let{url:f,missing:p}=nG(e,t),m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useRef)(s);return _.current=s,(0,v.useEffect)(()=>{if(p){_.current?.(e);return}let t=yU(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,H.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,H.jsx)(tG,{name:`imageOff`,size:24})}):(0,H.jsxs)(`div`,{ref:m,className:a?`sm-player ${a}`:`sm-player`,style:o,"data-mode":`dark`,"data-fill":i?``:void 0,tabIndex:0,role:`group`,"aria-label":n||r||`Video`,children:[(0,H.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,H.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var iG=e=>String(e).padStart(2,`0`),aG=/^(\d{4})-(\d{2})-(\d{2})$/,oG=/^([01]\d|2[0-3]):([0-5]\d)$/,sG=e=>{let t=aG.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},cG=e=>{let t=sG(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},lG=e=>{let{year:t,month:n,day:r}=sG(e);return new Date(Date.UTC(t,n-1,r))},uG=(e,t)=>{let n=lG(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},dG=(e,t)=>{let{year:n,month:r,day:i}=sG(e),a=new Date(Date.UTC(n,r-1+t,1)),o=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth()+1,0)).getUTCDate();return`${a.getUTCFullYear()}-${iG(a.getUTCMonth()+1)}-${iG(Math.min(i,o))}`},fG=/(?:time|when|start|schedule|post|send|publish|remind)/i,pG=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||fG.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),mG=e=>`${gG(e.slice(0,10))}${e[10]===`T`?` · ${_G(e.slice(11,16))}`:``}`;function hG({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${iG(t.getMonth()+1)}-${iG(t.getDate())}`}function gG(e,t=hG()){return lG(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function _G(e){let[t,n]=e.split(`:`).map(Number);return new Date(Date.UTC(2e3,0,1,t,n)).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,timeZone:`UTC`})}function vG(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${iG(Math.floor(n*e/60))}:${iG(n*e%60)}`)}function yG(e,t,n,r){return(0,v.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)};return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e]),n=>{n.key===`Escape`&&e&&(n.stopPropagation(),n.preventDefault(),t(!1),r.current?.focus())}}function bG({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Day`,placeholder:s=`Pick a day`,clearable:c=!1}){let[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null),p=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=yG(l,u,p,m),_=hG({utc:i}),y=cG(e)?e:null,b=e=>(!n||e>=n)&&(!r||e<=r),x=e=>n&&e<n?n:r&&e>r?r:e;(0,v.useEffect)(()=>{l&&d&&h.current?.querySelector(`[data-day="${d}"]`)?.focus()},[l,d]);let S=()=>{if(l){u(!1);return}f(x(y||_)),u(!0)},C=e=>{b(e)&&(t?.(e),u(!1),m.current?.focus())},w={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7},T=e=>{let t=null;if(w[e.key])t=uG(d,w[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=dG(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=lG(d).getUTCDay();t=uG(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(x(t)))},E=d||y||_,{year:D,month:O}=sG(E),k=`${D}-${iG(O)}-01`,A=new Date(Date.UTC(D,O,0)).getUTCDate(),j=lG(k).getUTCDay(),M=lG(k).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),N=uG(k,-1),P=dG(k,1),F=Array.from({length:A},(e,t)=>`${D}-${iG(O)}-${iG(t+1)}`);return(0,H.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,H.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${y?gG(y,_):`not chosen`}`,disabled:a,onClick:S,children:[(0,H.jsx)(tG,{name:`calendar`,size:16}),(0,H.jsx)(`span`,{children:y?gG(y,_):s}),(0,H.jsx)(tG,{name:`chevronDown`,size:13})]}),l&&(0,H.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,H.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,H.jsx)(`b`,{children:M}),(0,H.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,H.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&N<n,onClick:()=>f(x(dG(E,-1))),children:(0,H.jsx)(tG,{name:`chevronLeft`,size:16})}),(0,H.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&P>r,onClick:()=>f(x(dG(E,1))),children:(0,H.jsx)(tG,{name:`chevronRight`,size:16})})]})]}),(0,H.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:T,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,H.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),j>0&&(0,H.jsx)(`span`,{style:{gridColumn:`span ${j}`},"aria-hidden":`true`}),F.map(e=>(0,H.jsx)(`button`,{type:`button`,"data-day":e,tabIndex:e===d?0:-1,disabled:!b(e),"aria-pressed":e===y,"aria-current":e===_?`date`:void 0,"aria-label":lG(e).toLocaleDateString(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`,timeZone:`UTC`}),onClick:()=>C(e),children:Number(e.slice(8))},e))]}),c&&y&&(0,H.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function xG({value:e,onChange:t,min:n,step:r=30,disabled:i=!1,label:a=`Time`,placeholder:o=`Pick a time`}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(-1),d=(0,v.useRef)(null),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=(0,v.useId)(),h=yG(s,c,d,f),g=oG.test(e||``)?e:null,_=g&&!vG(r).includes(g)?[...vG(r),g].sort():vG(r),y=e=>!n||e>=n;(0,v.useEffect)(()=>{s&&(p.current?.focus(),p.current?.querySelector(`[data-active="true"]`)?.scrollIntoView?.({block:`nearest`}))},[s,l]);let b=()=>{if(s){c(!1);return}let e=_.indexOf(g);u(e>=0?e:Math.max(0,_.findIndex(y))),c(!0)},x=e=>{y(e)&&(t?.(e),c(!1),f.current?.focus())};return(0,H.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,H.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?_G(g):`not chosen`}`,disabled:i,onClick:b,children:[(0,H.jsx)(tG,{name:`clock`,size:16}),(0,H.jsx)(`span`,{children:g?_G(g):o}),(0,H.jsx)(tG,{name:`chevronDown`,size:13})]}),s&&(0,H.jsx)(`ul`,{className:`sm-when-pop sm-when-times`,role:`listbox`,ref:p,tabIndex:-1,"aria-label":`Pick a ${a.toLowerCase()}`,"aria-activedescendant":l>=0?`${m}-${l}`:void 0,onKeyDown:e=>{let t=t=>{let n=t,r=e.key===`ArrowUp`||e.key===`End`?-1:1;for(;n>=0&&n<_.length&&!y(_[n]);)n+=r;return n>=0&&n<_.length?n:l};if(e.key===`ArrowDown`)u(t(l+1));else if(e.key===`ArrowUp`)u(t(l-1));else if(e.key===`Home`)u(t(0));else if(e.key===`End`)u(t(_.length-1));else if(e.key===`Enter`||e.key===` `)_[l]&&x(_[l]);else return;e.preventDefault()},children:_.map((e,t)=>(0,H.jsx)(`li`,{id:`${m}-${t}`,role:`option`,"aria-selected":e===g,"aria-disabled":!y(e)||void 0,"data-active":t===l||void 0,onPointerDown:e=>e.preventDefault(),onClick:()=>x(e),children:_G(e)},e))})]})}function SG({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Date`,clearable:s=!1,defaultTime:c=`09:00`,step:l=30}){let u=cG(e?.slice(0,10))?e.slice(0,10):``,d=oG.test(e?.slice(11,16)||``)?e.slice(11,16):``,f=n?.slice(0,10)||void 0,p=f?n.slice(11,16):``,m=e=>e===f&&p?vG(l).find(e=>e>=p)||p:null;return(0,H.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,H.jsx)(bG,{value:u,onChange:e=>{if(!e){t?.(``);return}let n=m(e),r=d||c;n&&r<n&&(r=n),t?.(`${e}T${r}`)},min:f,max:r?.slice(0,10),utc:i,disabled:a,label:`${o} day`,clearable:s}),(0,H.jsx)(xG,{value:d,onChange:e=>t?.(`${u||f||hG({utc:i})}T${e}`),min:(u||f||hG({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}wt();var CG=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),wG=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),TG=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),EG=(e,{aspectRatios:t,resolutions:n=[],qualities:r=[],references:i=0,seed:a=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),qualities:Object.freeze(r),references:i,seed:a}),DG=(e,{aspectRatios:t=[],resolutions:n=[],durations:r,firstFrame:i=!0,lastFrame:a=!1,requiresFirstFrame:o=!1,seed:s=!1,nativeAudio:c=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),durations:Object.freeze(r),firstFrame:i,lastFrame:a,requiresFirstFrame:o,seed:s,nativeAudio:c});Object.freeze({"nano-banana-2":EG(`Nano Banana 2`,{aspectRatios:CG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":EG(`Nano Banana 2 Lite`,{aspectRatios:CG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":EG(`Nano Banana Pro`,{aspectRatios:CG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":EG(`GPT Image 2`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.5-flare":EG(`GPT Image 2.5 Flare`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.5-sunburst":EG(`GPT Image 2.5 Sunburst`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.6-flare":EG(`GPT Image 2.6 Flare`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.6-sunburst":EG(`GPT Image 2.6 Sunburst`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-1.5":EG(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":EG(`Kling Image V3`,{aspectRatios:[`21:9`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],resolutions:[`1K`,`2K`]}),"seedream-v4.5":EG(`Seedream 4.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`2K`,`4K`],seed:!0})}),Object.freeze({"seedance-2.0":DG(`Seedance 2.0`,{aspectRatios:wG,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:TG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":DG(`Seedance 2.0 Fast`,{aspectRatios:wG,resolutions:[`480p`,`720p`],durations:TG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":DG(`Seedance 2.0 Mini`,{aspectRatios:wG,resolutions:[`480p`,`720p`],durations:TG,lastFrame:!0,seed:!0,nativeAudio:!0}),"kling-v3-turbo":DG(`Kling 3.0 Turbo`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[5,10]}),"wan-2.6-flash":DG(`Wan 2.6 Flash`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[3,4,5],requiresFirstFrame:!0}),"veo-3.1-lite":DG(`Veo 3.1 Lite`,{aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[4,6,8],lastFrame:!0,nativeAudio:!0}),"vidu-q3-turbo":DG(`Vidu Q3 Turbo`,{durations:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],lastFrame:!0,nativeAudio:!0}),"wan-2.7":DG(`Wan 2.7`,{resolutions:[`720p`,`1080p`],durations:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],lastFrame:!0,requiresFirstFrame:!0,seed:!0})}),Object.freeze([`model`,`aspectRatio`,`resolution`,`quality`]),Object.freeze([`model`,`duration`,`resolution`,`aspectRatio`,`generateAudio`]),Object.freeze({references:8,negativePrompt:2e3,seed:2147483647}),Object.freeze([`wan-2.6-flash`,`veo-3.1-lite`,`seedance-2.0-mini`,`kling-v3-turbo`,`seedance-2.0-fast`,`seedance-2.0`]),Object.freeze({speech:Object.freeze({text:3800,defaultVoice:`asteria`,speed:Object.freeze({min:.25,max:4,default:1})}),music:Object.freeze({min:5,max:240,default:30}),sfx:Object.freeze({min:.5,max:22,default:4})});var OG=2399/11e4,kG=Object.freeze({video:3,build:3,media:4.5,other:3,chat:2}),AG=(e,t)=>Math.max(0,Number(e)||0)*kG[t]/OG,jG=(e,t)=>Math.max(1,Math.ceil(AG(e,t)-1e-9)),MG=`2026-11-05`,NG=`carried`;Object.freeze({"veo-3.1-lite":{usd:.05,resolution:{"720p":1,"1080p":1.6},provider:`Atlas`,checked:MG,source:`Atlas catalog list price $0.05/s; 1080p at $0.08/s, Google's Veo 3.1 Lite step`},"vidu-q3-turbo":{usd:.04,provider:`Atlas`,checked:MG,source:`Atlas catalog list price (we pay $0.034)`},"wan-2.6-flash":{usd:.025,provider:`Atlas`,checked:MG,source:`Atlas catalog list price (we pay $0.018)`},"wan-2.7":{usd:.17,provider:`Higgsfield, then Atlas`,checked:NG,source:`Atlas $0.10/s at 720p (checked); the 1.7x step to the 1080p we generate is carried from the old table`},"kling-v3-turbo":{usd:.112,provider:`Higgsfield, then Atlas`,checked:MG,source:`Atlas catalog list price (we pay $0.095); Higgsfield $0.056/s on promotion`},"seedance-2.0":{usd:.2,resolution:{"480p":1,"720p":1.3,"1080p":3.2,"4k":7.5},provider:`BytePlus Ark`,checked:NG,source:`Ark is priced per token and its price page does not load without an account; carried from the old table (verify against an Ark invoice)`},"seedance-2.0-fast":{usd:.09,resolution:{"480p":1,"720p":1.3},provider:`BytePlus Ark`,checked:NG,source:`carried from the old table (Atlas lists $0.09/s)`},"seedance-2.0-mini":{usd:.09,resolution:{"480p":1,"720p":1.3},provider:`BytePlus Ark`,checked:NG,source:`priced as Fast, carried from the old table (Atlas lists $0.056/s)`}}),Object.freeze({"seedance-2":`seedance-2.0`,"kling-3":`kling-v3-turbo`,"kling-v3-pro":`kling-v3-turbo`,"kling-v3-std":`kling-v3-turbo`,"kling-o3-std":`kling-v3-turbo`}),Object.freeze({"gpt-image-2":{quality:{low:{"1K":.006,"2K":.007,"4K":.012},medium:{"1K":.053,"2K":.056,"4K":.101},high:{"1K":.211,"2K":.222,"4K":.401}},referenceUsd:.02,provider:`OpenAI for square, fal then Atlas for other shapes`,checked:MG,source:`fal gpt-image-2 price table (dearest size in each class); OpenAI direct is $30 per million output tokens`},"gpt-image-2.5-flare":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-06`,source:`fal openai/gpt-image-2.5/flare price table; OpenAI rate card $30 per million output tokens`},"gpt-image-2.5-sunburst":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-06`,source:`fal openai/gpt-image-2.5/sunburst price table; OpenAI rate card $30 per million output tokens`},"gpt-image-2.6-flare":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-07`,source:`OpenAI and fal gpt-image-2.6 token rates ($30 per million output tokens); per-image price taken from 2.5 until published`},"gpt-image-2.6-sunburst":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-07`,source:`OpenAI and fal gpt-image-2.6 token rates ($30 per million output tokens); per-image price taken from 2.5 until published`},"gpt-image-1.5":{quality:{low:{"1K":.013},medium:{"1K":.051},high:{"1K":.2}},provider:`fal`,checked:MG,source:`fal price for a non-square image`},"nano-banana-2":{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:MG,source:`fal: $0.08 at 1K, 1.5x at 2K, 2x at 4K`},"nano-banana-2-lite":{usd:.048,provider:`fal`,checked:MG,source:`fal: $37.50 per million output tokens, one 1K image (about 1,290 tokens)`},"nano-banana-pro":{usd:.15,resolution:{"1K":1,"2K":1,"4K":2},provider:`fal`,checked:MG,source:`fal: $0.15, 4K at double`},"kling-image-v3":{usd:.028,provider:`fal`,checked:MG,source:`fal: $0.028 per image`},"seedream-v4.5":{usd:.04,provider:`fal`,checked:MG,source:`fal: $0.04 per image`},"flux-step":{usd:.02,provider:`fal`,checked:NG,source:`carried from the old table`},flux:{usd:.04,provider:`fal`,checked:NG,source:`carried from the old table`},ideogram:{usd:.08,provider:`fal`,checked:NG,source:`carried from the old table`},gemini:{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:MG,source:`served as Nano Banana 2`}}),Object.freeze({deepgram:{usdPer1kChars:.03,checked:MG,source:`Deepgram Aura-2 pay as you go`},openai:{usdPer1kChars:.015,checked:MG,source:`OpenAI tts-1, $15 per million characters`},elevenlabs:{usdPer1kChars:.04,checked:MG,source:`ElevenLabs API, Flash / Turbo`},kokoro:{usdPer1kChars:.02,checked:MG,source:`fal Kokoro`}}),Object.freeze({usdPerSecond:2e-4,checked:MG,source:`fal ACE-Step, per second of audio`}),Object.freeze({usdPerSecond:.002,checked:MG,source:`fal ElevenLabs sound effects v2, per second`});var PG=Object.freeze({"openai/gpt-5-mini":{input:.25,output:2},"google/gemini-2.5-flash":{input:.3,output:2.5},"anthropic/claude-haiku-5.5":{input:.1,output:.5},"anthropic/claude-sonnet-4":{input:3,output:15},"anthropic/claude-sonnet-4.5":{input:3,output:15},"anthropic/claude-sonnet-5.5":{input:2,output:10},"openai/gpt-5.4":{input:2.5,output:15},"google/gemini-2.5-pro":{input:1.25,output:10},"x-ai/grok-4.5":{input:2,output:6},"x-ai/grok-4.20":{input:1.25,output:2.5},"anthropic/claude-opus-4.1":{input:15,output:75},"anthropic/claude-opus-4.5":{input:5,output:25},"anthropic/claude-opus-4.8":{input:5,output:25},"openai/gpt-5.5":{input:5,output:30}}),FG=(e,t,n)=>{let r=PG[e];return r?(t*r.input+n*r.output)/1e6:null},IG=Object.freeze({input:2e3,output:1e3}),LG=Object.freeze({input:1e4,output:4096});function RG(e){let t=FG(e,IG.input,IG.output),n=FG(e,LG.input,LG.output);return t===null?null:Math.max(jG(t,`media`),Math.ceil(n/OG-1e-9))}var zG=(e,t,n,r,i={})=>Object.freeze({usd:e,tier:t,unit:n,source:r,checked:i.checked||NG,...i});Object.freeze({"media:analyze":zG(.02,`media`,`call`,`the vision provider caps a call at $0.02 (VISION_MAX_INITIAL_COST)`,{checked:MG}),"media:check":zG(.005,`media`,`call`,`four photos at most, $0.00125 each (MEDIA_CHECK_IMAGE_USD)`,{checked:MG}),"research:search":zG(.008,`media`,`search`,`Tavily basic search`,{checked:MG}),"research:summarize":zG(.01,`media`,`call`,`one Gemini Flash read of fetched pages`,{estimate:!0}),"transcribe:timestamp":zG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:upload":zG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:captions":zG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"connection:action":zG(.012,`other`,`action`,`a premium Composio tool call at the overage rate`,{checked:MG}),"automation:app-event":zG(.003,`other`,`event`,`Composio, per trigger event`,{checked:MG}),"automation:app-check":zG(3e-4,`other`,`check`,`Composio, per tool call`,{checked:MG}),llm:zG(.01,`other`,`call`,`a Standard model call`,{estimate:!0}),vision:zG(.01,`other`,`image`,`one vision read`,{estimate:!0}),"narrative:compile":zG(.06,`other`,`script`,`about ten Gemini Flash calls`,{estimate:!0}),"narrative:compile-research":zG(.1,`other`,`script`,`the compile plus three Tavily searches and a dossier`,{estimate:!0}),"narrative:learn-voice":zG(.01,`other`,`call`,`one extraction call`,{estimate:!0}),"roughcut:base":zG(.05,`other`,`run`,`segmentation and matching`,{estimate:!0}),"roughcut:per-min":zG(.015,`other`,`footage minute`,`Gemini Flash frame reads`,{estimate:!0}),"finaledit:base":zG(.06,`other`,`run`,`polish decisions`,{estimate:!0}),"finaledit:per-min":zG(.02,`other`,`video minute`,`Gemini Flash scan`,{estimate:!0}),"aomotion:base":zG(.06,`other`,`run`,`motion graphics pass`,{estimate:!0}),"aomotion:per-min":zG(.02,`other`,`video minute`,`motion graphics pass`,{estimate:!0}),"aomotion:base:opus":zG(.12,`other`,`run`,`motion graphics pass on Opus`,{estimate:!0}),"aomotion:per-min:opus":zG(.04,`other`,`video minute`,`motion graphics pass on Opus`,{estimate:!0}),motiongraphic:zG(.015,`other`,`graphic`,`one small call`,{estimate:!0}),"transcript:parse":zG(.005,`other`,`1,000 characters`,`Gemini Flash word timing`,{estimate:!0}),"vibe-edit":zG(.02,`other`,`turn`,`Flash region scan and decision`,{estimate:!0}),"canvas:context-connect":zG(.01,`other`,`run`,`one canvas read`,{estimate:!0}),"anim2:plan":zG(.03,`other`,`video`,`shot planning`,{estimate:!0}),"anim2:vibe":zG(.03,`other`,`turn`,`scene vibe turn`,{estimate:!0}),"anim2:qa":zG(.03,`other`,`frame`,`vision QA`,{estimate:!0}),"anim2:trigger":zG(.01,`other`,`scene`,`one Haiku call`,{estimate:!0}),"gif:plan":zG(.03,`other`,`pass`,`GIF planning`,{estimate:!0}),"canvas:plan":zG(.03,`other`,`pass`,`collage planning`,{estimate:!0}),"canvasChat:build":zG(.03,`other`,`build`,`canvas chat orchestration`,{estimate:!0}),"strip:plan":zG(.05,`other`,`pass`,`strip planning`,{estimate:!0}),"panel:qa":zG(.03,`other`,`pass`,`style-consistency vision pass`,{estimate:!0})}),Object.freeze({standard:.4,balanced:.85,reasoning:.5,premium:1.4}),Object.freeze({build:.1,chat:.005,other:.05}),Object.freeze(Object.fromEntries([`openai/gpt-5-mini`,`google/gemini-2.5-flash`,`anthropic/claude-sonnet-4`,`anthropic/claude-sonnet-4.5`,`openai/gpt-5.4`,`google/gemini-2.5-pro`,`x-ai/grok-4.5`,`x-ai/grok-4.20`,`anthropic/claude-opus-4.1`,`anthropic/claude-opus-4.5`,`anthropic/claude-opus-4.8`,`openai/gpt-5.5`].map(e=>[e,RG(e)])))[`anthropic/claude-sonnet-4.5`],wt();var BG=Object.freeze({googlesheets:`Google Sheets`,googledrive:`Google Drive`,googledocs:`Google Docs`,googlecalendar:`Google Calendar`,gmail:`Gmail`,youtube:`YouTube`,tiktok:`TikTok`,linkedin:`LinkedIn`,hubspot:`HubSpot`,github:`GitHub`,whatsapp:`WhatsApp`,"meta-ads":`Meta Ads`}),VG=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,HG=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),UG=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),WG=[[`send`,new Set([`send`,`reply`,`message`,`notify`,`email`,`forward`,`dm`,`invite`])],[`add`,new Set([`add`,`append`,`insert`,`create`,`new`,`log`,`save`,`record`,`upsert`,`write`,`import`,`book`,`schedule`])],[`update`,new Set([`update`,`edit`,`change`,`modify`,`patch`,`set`,`rename`,`move`,`replace`,`mark`])],[`remove`,new Set([`delete`,`remove`,`archive`,`trash`,`cancel`,`unsubscribe`])],[`upload`,new Set([`upload`])]],GG={post:[`Post to`,`Posting to`],send:[`Send to`,`Sending to`],add:[`Add to`,`Adding to`],update:[`Update in`,`Updating in`],remove:[`Remove from`,`Removing from`],upload:[`Upload to`,`Uploading to`],read:[`Get from`,`Getting from`]},KG=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),qG=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function JG(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=KG(e);return BG[n]||(n?qG(n):`the app`)}function YG(e){let t=String(e?.manifest?.name||``).split(` · `).slice(1).join(` `),n=String(e?.capability?.capabilityId||``).split(`:`).at(-1),r=KG(e).replace(/[-_.]/g,``).toLowerCase(),i=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,` `).trim().split(` `).filter(Boolean);return t.length>1&&t[0].replace(/[-_.]/g,``)===r&&t.shift(),t};for(let e of[i(t),i(n)]){let t=e.slice(0,3),n=t.find(e=>VG.test(e)||HG.has(e)||WG.some(([,t])=>t.has(e)));if(n&&VG.test(n))return`read`;if(e.some(e=>HG.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>UG.has(e)))return`post`;let r=n&&WG.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function XG(e){let t=JG(e),n=YG(e),[r,i]=GG[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var ZG=e=>XG(e).verbs,QG=Object.freeze({"text.generate":[`Write`,`Writing…`],"image.generate":[`Generate image`,`Generating image…`],"video.generate":[`Generate video`,`Generating video…`],"video.render":[`Make video`,`Making video…`],"audio.speech":[`Generate voiceover`,`Generating voiceover…`],"audio.transcribe":[`Transcribe`,`Transcribing…`],"image.describe":[`Describe`,`Describing…`],"audio.music":[`Generate music`,`Generating music…`],"audio.sfx":[`Generate sound`,`Generating sound…`],"web.fetch":[`Read page`,`Reading…`],"web.research":[`Research`,`Researching…`],"media.analyze":[`Analyze`,`Analyzing…`],"timeline.propose":[`Suggest edit`,`Suggesting…`],"workspace.propose":[`Suggest changes`,`Suggesting…`],"connection.execute":[`Send`,`Sending…`]}),$G=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase(),eK=new Set([`output`,`outputs`,`result`,`results`,`value`,`data`,`out`]),tK=new Set(`add.analyze.animate.build.check.clean.compose.convert.count.create.cut.describe.design.edit.export.extract.find.generate.get.import.make.merge.mix.narrate.pick.plan.post.publish.read.record.remove.render.research.resize.review.schedule.send.split.summarize.transcribe.translate.trim.write`.split(`.`));function nK(e){let t=e?.manifest;if(!t)return null;let n=String(t.name||``).trim(),r=n.split(/\s+/)[0].toLowerCase();if(tK.has(r)&&n.includes(` `))return[n,`Working…`];let i=Object.entries(t.outputs||{}).filter(([,e])=>!e?.context),[a,o]=i.find(([,e])=>e?.primary)||i[0]||[],s=a&&!eK.has($G(a))&&!/action/i.test(String(o?.type||``)),c=o?.label?$G(o.label):$G(s?a:n);return c?[`Make ${c}`,`Making ${c}…`]:null}function rK(e,t){let n=t?.manifest?.action,r=typeof n?.label==`string`?n.label.trim():``;return r?[r,n.running||QG[e]?.[1]||`Working…`]:e===`connection.execute`&&t?ZG(t):QG[e]||nK(t)||[`Make the result`,`Making the result…`]}var iK=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function aK(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||rK(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${iK(t.credits)}`:r||t?.credits===0?`${s} · ${iK(0)}`:s}var oK=new Set([`image`,`image[]`,`video`,`video[]`,`audio`,`audio[]`,`asset`,`asset[]`,`file`]),sK=3,cK=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();function lK(e){let t=String(e||``).trim();if(!t)return``;let n=(t.match(/^.+?[.!?](?=\s|$)/)||[t])[0].trim();return n.length<=160?n:``}function uK(e,{inputs:t,labels:n={},groups:r=[]}={}){let i=t||Object.entries(e?.inputs||{}).filter(([,e])=>!e?.context),a=i.length>0&&i.length<=sK&&!r.length,o=i.find(([,e])=>e?.required!==!1&&e?.primary)||i.find(([,e])=>e?.required!==!1)||i[0],s=o?cK(n[o[0]]||o[1]?.label||o[0]):``;return{focused:a,heading:s?`Add your ${s}`:String(e?.action?.label||e?.name||``).trim(),line:lK(e?.description),media:!!o&&oK.has(o[1]?.type)}}var dK=new Set([`text`,`script`,`transcript`,`brief`,`json`,`metadata`,`research`,`document`,`table`]),fK=e=>{let t=String(e||``).replace(/\[\]$/,``);return dK.has(t)?`text`:[`video`,`image`,`audio`].includes(t)?t:void 0},pK=/^\s*(\d+(?:\.\d+)?)\s*[:/x]\s*(\d+(?:\.\d+)?)\s*$/;function mK(e,{inputs:t={},aspectRatio:n}={}){let r=Object.entries(e?.outputs||{}).filter(([,e])=>!e?.context),i=(r.find(([,e])=>e?.primary)||r[0]||[])[1],a=fK(i?.type);if(a!==`video`&&a!==`image`)return{kind:a};let o=Object.keys(e?.inputs||{}).find(e=>/aspect/i.test(e)),s=[o&&t[o],o&&e.inputs[o]?.default,n].find(e=>pK.test(String(e||``))),c=pK.exec(String(s||``));return{kind:a,ratio:c?`${c[1]}/${c[2]}`:a===`video`?`16/9`:`1/1`}}function hK({kind:e,ratio:t,words:n=`Your result shows up here`}){return(0,H.jsxs)(`div`,{className:`sm-result-place`,"data-kind":e||`other`,children:[e===`text`&&(0,H.jsxs)(`span`,{className:`sm-result-lines`,"aria-hidden":`true`,children:[(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{})]}),(e===`video`||e===`image`)&&(0,H.jsx)(`span`,{className:`sm-result-frame`,style:{aspectRatio:t},"aria-hidden":`true`,children:(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":e})}),e===`audio`&&(0,H.jsxs)(`span`,{className:`sm-result-audio`,"aria-hidden":`true`,children:[(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`audio`}),(0,H.jsx)(`span`,{className:`sm-result-wave`,children:Array.from({length:24},(e,t)=>(0,H.jsx)(`i`,{},t))})]}),!e&&(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`spark`,"aria-hidden":`true`}),(0,H.jsx)(`p`,{children:n})]})}var gK=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),_K=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),vK=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),yK=e=>/^[aeiou]/i.test(e)?`an`:`a`;function bK(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=gK[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||_K.has(a)||a===i,s=XU(vK[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${yK(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${yK(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var xK=160,SK=/\blines\b|\b(?:per|each|every|own|by)\s+line\b|\bline\s+(?:per|for each)\b|\bparagraphs?\b|\bbullet(?:s|ed)?\b/i,CK=/\blists?\b/i,wK=/\bcomma/i;function TK(e,t,n){if(e?.type!==`text`)return!1;if(n?.multiline===!0||[t,e.default].some(e=>typeof e==`string`&&e.includes(`
|
|
1976
|
-
`)))return!0;let r=String(e.description||``);return SK.test(r)||CK.test(r)&&!wK.test(r)}function EK(e,t,n){if(e?.type!==`text`||TK(e,t,n)||t!=null&&(typeof t!=`string`||t.length>xK))return!1;let r=String(e.description||``),i=Number(/\bup to (\d+) characters\b/i.exec(r)?.[1]),a=Number.isSafeInteger(e.maxLength)?e.maxLength:i;return Number.isFinite(a)&&a>0&&a<=xK}var DK=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],OK=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],kK=new Set([`image`,`video`,`audio`,`file`]),AK={image:`image`,video:`film`,audio:`music`,file:`image`},jK=e=>{let t;try{t=JSON.parse(e)}catch{return String(e)}return Array.isArray(t)?t.map(e=>e?.message===`Unknown manifest field`?`This SDK does not know the Block’s “${e.path}” setting. Update the SDK, then restart the preview.`:`${e?.path?`${e.path}: `:``}${e?.message||`Something is wrong with the Block.`}`).join(` `):String(e)},MK={pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`},NK={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(MK).map(e=>`.${e}`).join(`,`)};async function PK(e,t){if(t===`image`){let t=await createImageBitmap(e),n={width:t.width,height:t.height};return t.close?.(),n}if(t!==`video`&&t!==`audio`)return{};let n=URL.createObjectURL(e),r=document.createElement(t);try{r.preload=`metadata`,r.src=n,await new Promise((e,t)=>{r.onloadedmetadata=e,r.onerror=()=>t(Error(`This file does not play in the browser.`)),setTimeout(e,8e3)});let e=Number.isFinite(r.duration)&&r.duration>0?Math.round(r.duration*1e3)/1e3:void 0;return t===`video`?{...r.videoWidth?{width:r.videoWidth,height:r.videoHeight}:{},...e?{duration:e}:{}}:e?{duration:e}:{}}finally{URL.revokeObjectURL(n)}}async function FK(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?MK[n]||e.type:e.type||`application/octet-stream`,i=await PK(e,t).catch(()=>({})),a=await fetch(`/__dev/files`,{method:`POST`,headers:{"Content-Type":r,"X-File-Name":encodeURIComponent(e.name)},body:e}),o=await a.json().catch(()=>({}));if(!a.ok||!o.url)throw Error(o.error||`The preview could not keep this file.`);return{kind:t,assetId:`picked-${o.url.split(`/`)[4]}`,versionId:`v1`,url:o.url,mimeType:r,bytes:e.size,name:e.name,...i}}async function IK(e,t,n,{pick:r=FK}={}){if(!t)throw Error(`This Block has no input named ${e}.`);let i=t.type.endsWith(`[]`),a=i?t.type.slice(0,-2):t.type,o=[];for(let e of i?n:n.slice(0,1))o.push(await r(e,a===`asset`?String(e.type).split(`/`)[0]:a));return{refs:o,apply:t=>({...t||{},[e]:i?[...Array.isArray(t?.[e])?t[e]:[],...o]:o[0]})}}function LK(e,t,n){for(let t of Object.keys(n||{}))if(!Object.hasOwn(e||{},t))throw Error(`Unknown input: ${t}`);return{...t||{},...n}}function RK({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=HW(e)}){let s=(0,v.useRef)(null),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),m=async e=>{if(e){l(!0),d(``);try{a(await FK(e,t.type))}catch(e){d(e.message)}finally{l(!1)}}},h=e=>{let t=e.target.files?.[0];e.target.value=``,m(t)},g=bK(e,t),_=(0,H.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:NK[t.type],onChange:h});return r&&!n?(0,H.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,H.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,H.jsxs)(`div`,{className:`dh-media-drop`,"data-over":f||void 0,onDragOver:e=>{e.preventDefault(),f||p(!0)},onDragLeave:()=>p(!1),onDrop:e=>{e.preventDefault(),p(!1),!i&&!c&&m(e.dataTransfer.files?.[0])},children:[(0,H.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,H.jsx)(`span`,{children:t.description}),(0,H.jsx)(`small`,{children:g.formats}),(0,H.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,H.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,H.jsxs)(`div`,{className:`dh-media`,children:[(0,H.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,H.jsx)(tG,{name:n?AK[t.type]:`plus`,size:16}),(0,H.jsx)(`span`,{children:c?`Adding…`:BK(n)||g.choose})]}),_,u&&(0,H.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):n&&typeof n==`object`?(0,H.jsxs)(`span`,{className:`dh-media-tiles`,title:`The example from the Block's tests`,children:[(0,H.jsx)(zK,{item:n,title:o}),(0,H.jsx)(`small`,{className:`dh-media-note`,children:`Example`})]}):(0,H.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,H.jsx)(tG,{name:AK[t.type],size:16}),(0,H.jsx)(`span`,{children:`Add one in the example`}),(0,H.jsx)(`small`,{children:`Example`})]})]})}function zK({item:e,title:t}){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(!1),a=BK(e)||t;if(!(typeof e?.url==`string`&&e.url.startsWith(`/api/media/`))||![`image`,`video`,`audio`].includes(e.kind))return(0,H.jsxs)(`span`,{className:`dh-media-tile`,title:a,children:[(0,H.jsx)(tG,{name:AK[e?.kind]||`image`,size:16}),(0,H.jsx)(`span`,{children:a})]});if(e.kind===`image`)return(0,H.jsx)(`span`,{className:`dh-thumb`,title:a,children:(0,H.jsx)(`img`,{src:e.url,alt:a,loading:`lazy`,decoding:`async`})});let o=()=>{let e=n.current;e&&(e.paused?e.play()?.catch?.(()=>{}):e.pause())},s={onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>i(!1)},c=(0,H.jsx)(`button`,{type:`button`,className:`dh-thumb-play`,"aria-label":`${r?`Pause`:`Play`} ${a}`,onClick:o,children:(0,H.jsx)(tG,{name:r?`pauseFilled`:`playFilled`,size:14})});return e.kind===`video`?(0,H.jsxs)(`span`,{className:`dh-thumb`,title:a,"data-playing":r||void 0,children:[(0,H.jsx)(`video`,{ref:n,src:e.url,preload:`metadata`,muted:!0,playsInline:!0,...s}),c]}):(0,H.jsxs)(`span`,{className:`dh-media-tile dh-media-sound`,title:a,children:[c,(0,H.jsx)(tG,{name:`music`,size:16}),(0,H.jsx)(`span`,{children:a}),(0,H.jsx)(`audio`,{ref:n,src:e.url,preload:`none`,...s})]})}var BK=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},VK=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},HK=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function UK(e,t=``){return(await fetch(`/__dev/run${t}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function WK(e,{signal:t,edge:n}={}){if(typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`))throw Error(`The local preview shows stand-in media and files mapped in tests/mocks.json.`);let r=await fetch(e.url,{signal:t});if(!r.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let i=await createImageBitmap(await r.blob()),a=n??512,o=Math.min(1,a/Math.max(i.width,i.height)),s=document.createElement(`canvas`);s.width=Math.max(1,Math.round(i.width*o)),s.height=Math.max(1,Math.round(i.height*o));let c=s.getContext(`2d`);c.drawImage(i,0,0,s.width,s.height),i.close?.();let l=s.toDataURL(`image/png`);return l.length>3145728&&a>512&&c.getImageData(0,0,s.width,s.height).data.every((e,t)=>t%4!=3||e===255)&&(l=s.toDataURL(`image/jpeg`,.92)),{url:l,width:s.width,height:s.height}}function GK(e,{signal:t}={}){return typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`)?Promise.reject(Error(`The local preview plays stand-in media and files mapped in tests/mocks.json.`)):Kn(e,{signal:t})}async function KK(e,{signal:t}={}){let n=await fetch(`/api/media/example/kitchen.wav`,{signal:t});if(!n.ok)throw Error(`The stand-in voice sample is not available.`);return new Blob([await n.arrayBuffer()],{type:`audio/wav`})}function qK({value:e}){let t=BK(e);if(!e.url.startsWith(`/api/media/`))return(0,H.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,H.jsx)(tG,{name:AK[e.kind],size:16}),(0,H.jsx)(`span`,{children:t||`Result`})]});let n=e.width>0&&e.height>0?`${e.width}/${e.height}`:null,r=n?{aspectRatio:n}:void 0;return(0,H.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,H.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,H.jsx)(rG,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,H.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,H.jsx)(`figcaption`,{children:t})]})}var JK=e=>(0,H.jsx)(qK,{value:e}),YK=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function XK({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||HW(e),[c,l]=(0,v.useState)(o);(0,v.useEffect)(()=>{l(o)},[o]);let u=`dh-input-${e}`,d=t.description||void 0,f=n?.control===`select`&&Array.isArray(n.options)?n.options:null,p=f?(0,H.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,H.jsxs)(`span`,{className:`dh-slider`,children:[(0,H.jsx)(`input`,{id:u,type:`range`,min:t.min,max:t.max,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(Number(e.target.value)),onPointerUp:()=>i(Number(c)),onKeyUp:()=>i(Number(c)),onBlur:()=>i(Number(c))}),(0,H.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,H.jsx)(`input`,{id:u,type:`checkbox`,checked:!!c,disabled:a,onChange:e=>{l(e.target.checked),i(e.target.checked)}}):[`number`,`integer`].includes(t.type)?(0,H.jsx)(`input`,{id:u,type:`number`,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{if(c===``)return i(void 0);let e=Number(c);Number.isFinite(e)&&i(e)}}):[`text`,`string`].includes(t.type)?!n?.control&&EK(t,o,n)?(0,H.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):(0,H.jsx)(`textarea`,{id:u,className:`dh-text`,rows:Math.min(16,Math.max(3,String(c).split(`
|
|
1977
|
-
`).length)),value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,H.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:pG(e,s,typeof o==`string`?o:``)?(0,H.jsx)(SG,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,H.jsx)(bG,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):YK.has(t.type)?(0,H.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,H.jsx)(zK,{item:e,title:`${s} ${t+1}`},t)),!(Array.isArray(o)?o.length:o)&&(0,H.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,H.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,H.jsxs)(`div`,{className:`dh-row`,children:[(0,H.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function ZK({value:e,onCommit:t,disabled:n}){let r=(0,v.useMemo)(()=>JSON.stringify(e,null,2),[e]),[i,a]=(0,v.useState)(r),[o,s]=(0,v.useState)(``);return(0,v.useEffect)(()=>{a(r),s(``)},[r]),(0,H.jsxs)(`div`,{className:`dh-input`,children:[(0,H.jsx)(`textarea`,{"aria-label":`Input JSON`,spellCheck:!1,rows:8,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:()=>{if(i!==r)try{let e=JSON.parse(i||`{}`);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`The input is one JSON object, keyed by input port.`);s(``),t(e)}catch(e){s(e.message)}}}),o&&(0,H.jsx)(`p`,{role:`alert`,children:o})]})}var QK=(0,v.memo)(function({entries:e,onClear:t}){let n=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[e]),(0,H.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,H.jsx)(`ol`,{ref:n,children:e.map(e=>(0,H.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,H.jsx)(`time`,{children:e.time}),(0,H.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,H.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,H.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),$K={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},eq={full:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,H.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,H.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,H.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}),dark:(0,H.jsx)(`path`,{d:`M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z`}),white:(0,H.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,H.jsx)(`path`,{d:`M9 3h6M10 3v6l-5 9a2 2 0 0 0 1.7 3h10.6a2 2 0 0 0 1.7-3l-5-9V3`}),done:(0,H.jsx)(`path`,{d:`M5 12.5l4.5 4.5L19 7`}),todo:(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8`,strokeDasharray:`3 3`}),problem:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`}),(0,H.jsx)(`path`,{d:`M12 7.5v5.5M12 16.4v.1`})]}),focus:(0,H.jsx)(`path`,{d:`M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5`}),unfocus:(0,H.jsx)(`path`,{d:`M9 4v5H4M20 9h-5V4M15 20v-5h5M4 15h5v5`})},tq=({name:e})=>(0,H.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:eq[e]});function nq(){let[e,t]=(0,v.useState)(()=>VK(`stillmade.dev.focus`,``)===`1`);(0,v.useEffect)(()=>{e?document.documentElement.dataset.focus=`true`:delete document.documentElement.dataset.focus,HK(`stillmade.dev.focus`,e?`1`:``)},[e]);let n=e?`Show the bars`:`Hide the bars`;return(0,H.jsx)(`button`,{type:`button`,className:`dh-focus-toggle`,"aria-pressed":e,"aria-label":n,title:n,onClick:()=>t(e=>!e),children:(0,H.jsx)(tq,{name:e?`unfocus`:`focus`})})}function rq(e,t){(0,v.useLayoutEffect)(()=>{let t=e.current,n=t?.closest(`.dh-main`);if(!t||!n)return;let r=0,i=()=>{r=0;let e=parseFloat(getComputedStyle(n).paddingTop)+parseFloat(getComputedStyle(n).paddingBottom),i=uU({width:t.parentElement.clientWidth,available:n.clientHeight-e,heightAt:e=>{t.style.zoom=e===1?``:String(e),t.style.flex=`none`,t.style.minHeight=`0`;let n=Math.ceil(t.getBoundingClientRect().height);return t.style.flex=``,t.style.minHeight=``,n},mode:`auto`});t.style.zoom=i===1?``:String(i)},a=()=>{r||=requestAnimationFrame(i)};i(),addEventListener(`resize`,a);let o=e=>{[`IMG`,`VIDEO`,`AUDIO`].includes(e.target?.tagName)&&a()};return t.addEventListener(`load`,o,!0),t.addEventListener(`loadedmetadata`,o,!0),()=>{cancelAnimationFrame(r),removeEventListener(`resize`,a),t.removeEventListener(`load`,o,!0),t.removeEventListener(`loadedmetadata`,o,!0),t.style.zoom=``}},t)}function iq({label:e,value:t,options:n,onChange:r}){return(0,H.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,H.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,H.jsx)(tq,{name:e})},e))})}var aq=140,oq=260,sq={"text.generate":`Write`,"image.generate":`Generate a picture`,"video.generate":`Generate a video`,"audio.speech":`Speak`,"audio.music":`Make music`,"audio.sfx":`Make a sound effect`,"audio.transcribe":`Transcribe`,"image.describe":`Describe a picture`,"media.analyze":`Look at the media`,"web.fetch":`Read a web page`,"web.research":`Research the web`,"timeline.render":`Render`,"audio.decode":`Decode audio`,"audio.extract":`Take out the audio`,"audio.normalize":`Even out the loudness`,"video.cut":`Cut the video`,"video.concat":`Join videos`,"video.resize":`Resize the video`,"image.thumbnail":`Take a still`,"image.compose":`Join pictures`,"document.text":`Read a document`,"files.read":`Read a file`,"files.write":`Save a file`,"net.fetch":`Call a web service`,"connections.call":`Use a connected app`,"actions.run":`Run an action`,"assets.create":`Add to the project`},cq=e=>sq[e.name]||sq[e.api]||e.name;function lq({on:e,label:t,onChange:n}){return(0,H.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,H.jsx)(`span`,{className:`dh-switch-track`,children:(0,H.jsx)(`span`,{className:`dh-switch-knob`})}),(0,H.jsx)(`span`,{children:t})]})}function uq({tabs:e,status:t,control:n,children:r,initial:i=null}){let[a,o]=(0,v.useState)(i),[s,c]=(0,v.useState)(()=>Number(VK(`stillmade.dev.dock`,``))||oq),l=(0,v.useRef)(null),u=e=>o(t=>t===e?null:e),d=e=>{a&&(l.current={y:e.clientY,height:s},e.currentTarget.setPointerCapture(e.pointerId))},f=e=>{let t=l.current;t&&c(Math.round(Math.max(aq,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},p=()=>{l.current&&(l.current=null,HK(`stillmade.dev.dock`,String(s)))},m=e.find(e=>e.key===a);return(0,H.jsxs)(`section`,{className:`dh-dock`,"data-open":m?`true`:`false`,style:m?{height:s}:void 0,"aria-label":`Run details`,children:[m&&(0,H.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:d,onPointerMove:f,onPointerUp:p,onPointerCancel:p}),(0,H.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,H.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":a===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>u(e.key),children:[e.label,e.alert&&(0,H.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,H.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,H.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":m?`Fold the panel`:`Open the panel`,title:m?`Fold the panel`:`Open the panel`,"aria-expanded":!!m,onClick:()=>o(t=>t?null:e[0].key),children:(0,H.jsx)(tG,{name:`chevronRight`,size:16})})]}),m&&(0,H.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${m.key}`,"aria-labelledby":`dh-tab-${m.key}`,children:r(m.key)})]})}function dq({item:e=null,extraTabs:t=[],badges:n=null,dockOpen:r=null}={}){let i=e?`?item=${encodeURIComponent(e)}`:``,[a,o]=(0,v.useState)({revision:0,content:null,problem:null,folder:``}),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(()=>VK(`stillmade.dev.theme`,`light`)),[d,f]=(0,v.useState)(()=>VK(`stillmade.dev.width`,`full`)),[p,m]=(0,v.useState)(0),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(``),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)({}),[A,j]=(0,v.useState)([]),[M,N]=(0,v.useState)({}),P=(0,v.useRef)({}),F=(0,v.useRef)(0),I=(0,v.useCallback)((e,t)=>j(n=>[...n.slice(-299),{id:++F.current,kind:e,label:$K[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),L=(0,v.useCallback)(async()=>{let e=await(await fetch(`/__dev/package${i}`,{cache:`no-store`})).json();return o(e),e},[i]);(0,v.useEffect)(()=>{let t=!0;L().then(e=>{t&&(g(t=>t??(e.content?.tests?.[0]?.input||{})),I(`reload`,`Previewing ${e.folder}`),e.problem&&I(`error`,jK(e.problem)))}).catch(e=>I(`error`,e.message));let n=new EventSource(`/__dev/events`);return n.addEventListener(`package`,async n=>{let r=JSON.parse(n.data);if(!(e&&r.item!==e))try{if(await L(),!t)return;c(e=>e+1),I(r.problem?`error`:`reload`,r.problem?`Reloaded with a problem: ${jK(r.problem)}`:`Reloaded after a change`)}catch(e){I(`error`,e.message)}}),n.addEventListener(`build`,t=>{let n=JSON.parse(t.data);e&&n.items&&!n.items.includes(e.slice(e.indexOf(`/`)+1))||(n.state===`running`?I(`build`,`Building: ${n.command||n.items.join(`, `)}`):n.state===`done`?I(`build`,`Build finished`):I(`error`,`Build failed${n.output?`\n${n.output}`:``}`))}),()=>{t=!1,n.close()}},[]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=l,HK(`stillmade.dev.theme`,l)},[l]),(0,v.useEffect)(()=>{HK(`stillmade.dev.width`,d)},[d]);let ee=a.content,R=ee?.manifest,z=ee?.tests||[],te=e=>{m(e),g(z[e]?.input||{})},B=(0,v.useCallback)(async(e,{signal:t}={})=>{I(`run`,`Run started`),x(!0),C(``);try{let n=await UK(e,i);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])I(`log`,e);for(let e of n.standIns||[])I(`stand-in`,`${e.api} ${e.name} (${e.source===`picked`?`your file`:e.source===`example`?`example file`:/mocks/.test(e.source)?`the Block's tests`:`recorded stand-in`})`);if(T({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw I(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return y(n.outputs),I(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(y(null),C(e?.message||`The run did not finish.`)),e}finally{x(!1)}},[I,i]),ne=(0,v.useCallback)(async e=>{let t=ar(P.current,e);P.current=t,N(t)},[]),re=()=>{P.current={},N({}),c(e=>e+1),I(`view`,`Shared state cleared`)},[ie,ae]=(0,v.useState)([]),oe=(0,v.useMemo)(()=>({state:M,outputs:{},made:ie,memory:null,canEdit:!0}),[M,ie]),se=(0,v.useCallback)(async e=>{y(e),I(`view`,`The view chose its outputs`)},[I]),ce=(0,v.useCallback)(async(e,t)=>{let n=a.content?.manifest?.inputs?.[e],{refs:r,apply:i}=await IK(e,n,t);return E&&kK.has(n.type)?k(t=>({...t,[e]:r[0]})):g(i),I(`view`,`Added ${r.length} ${r.length===1?`file`:`files`} to ${HW(e)}`),{added:r.length}},[a.content,E,I]),le=(0,v.useCallback)(async(e,t)=>{let n=yW(h?.[e],t);return g(t=>({...t,[e]:n})),I(`view`,`${t.op===`remove`?`Removed a file from`:`Moved a file in`} ${HW(e)}`),{files:n.length}},[h,I]),ue=(0,v.useCallback)(e=>I(`error`,String(e?.message||e)),[I]),de=(0,v.useMemo)(()=>{let e={...h||{}};if(E)for(let[t,n]of Object.entries(a.content?.manifest?.inputs||{}))kK.has(n.type)&&(O[t]?e[t]=O[t]:delete e[t]);return e},[h,E,O,a.content]),fe=(0,v.useCallback)(e=>g(t=>{if(!E)return e;let n={...e};for(let[e,r]of Object.entries(a.content?.manifest?.inputs||{}))kK.has(r.type)&&(t&&Object.hasOwn(t,e)?n[e]=t[e]:delete n[e]);return n}),[E,a.content]),pe=(0,v.useCallback)(async(e,t)=>{let n=LK(a.content?.manifest?.inputs,de,e);Object.keys(e).length&&fe({...h||{},...e});let r=await B(n,t),i=Object.values(r||{}).flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>e&&[`image`,`video`,`audio`].includes(e.kind)&&typeof e.url==`string`&&typeof e.assetId==`string`).map(({kind:e,assetId:t,versionId:n,url:r})=>({kind:e,assetId:t,versionId:n,url:r}));return i.length&&ae(e=>[...i,...e.filter(e=>!i.some(t=>t.url===e.url))].slice(0,400)),r},[a.content,de,h,fe,B]),me=OK.find(([e])=>e===d)?.[2],he=ee?.capability?.operation?[ee.capability.operation]:(R?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),ge=b?rK(he.length===1?he[0]:void 0,ee)[1]:aK(he.length===1?he[0]:void 0,{credits:0},{connector:ee}),_e=(0,v.useMemo)(()=>uK(R,{labels:Object.fromEntries((R?.ui||[]).filter(e=>e?.label).map(e=>[e.port,e.label])),groups:R?.uiLayout?.groups||[]}),[R]),ve=(0,v.useRef)(null);rq(ve,[ee,d,_,S,b]);let ye=_?Object.entries(R?.outputs||{}).filter(([e])=>_[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof _[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(_[e])?(0,H.jsx)(`p`,{className:`dh-date`,children:(0,H.jsx)(`time`,{dateTime:_[e],children:mG(_[e])})},e):(0,H.jsx)(YW,{value:_[e],renderMedia:JK},e)):null,be=b?`Running…`:w?w.failed?`Last run failed`:`Ran in ${w.ms} ms${w.calls.length?` · ${w.calls.length} ${w.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,xe=[...t,{key:`activity`,label:`Activity`,alert:A.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${w?.calls.length?` · ${w.calls.length}`:``}`},...ee?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsxs)(`header`,{className:`dh-bar`,children:[(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:R?.name||`Block preview`}),R&&(0,H.jsx)(`span`,{className:`dh-meta`,children:R.version}),n]}),(0,H.jsx)(`span`,{className:`dh-spacer`}),z.length>1&&(0,H.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,H.jsx)(tq,{name:`example`}),(0,H.jsx)(`select`,{"aria-label":`Example`,value:p,onChange:e=>te(Number(e.target.value)),children:z.map((e,t)=>(0,H.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,H.jsx)(iq,{label:`Width`,value:d,options:OK,onChange:f}),(0,H.jsx)(iq,{label:`Appearance`,value:l,options:DK,onChange:u}),(0,H.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>c(e=>e+1),children:(0,H.jsx)(tG,{name:`refresh`,size:16})})]}),a.problem&&(0,H.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:jK(a.problem)}),(0,H.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,H.jsx)(`div`,{className:`dh-frame`,style:me?{maxWidth:me}:void 0,children:ee?ee.view?(0,H.jsx)(NW,{view:ee.view,policyContent:ee,input:de,sharedView:oe,onSharedChange:ne,onRun:pe,onUseOutput:se,onAddFiles:ce,onChangeFiles:le,onPreviewImage:WK,onPreviewMedia:GK,onPreviewVoice:KK,onAllowSpending:async({credits:e,label:t})=>(console.info(`StillMade would ask to approve up to ${e} credits for "${t}". The SDK preview spends none.`),e),onError:ue,actorId:`dev-preview`,title:`${R.name} preview`,height:560,fitContent:!0},s):(0,H.jsxs)(`div`,{className:_e.focused?`dh-noview dh-focus`:`dh-noview`,ref:ve,children:[_e.focused&&(0,H.jsxs)(`header`,{className:`dh-intro`,children:[(0,H.jsx)(`h2`,{children:_e.heading}),_e.line&&(0,H.jsx)(`p`,{children:_e.line})]}),(0,H.jsx)(`div`,{className:`dh-form`,children:Object.entries(R.inputs||{}).map(([e,t])=>kK.has(t.type)?(0,H.jsx)(RK,{name:e,port:t,title:(R.ui||[]).find(t=>t?.port===e)?.label||HW(e),value:de[e],own:E,disabled:b,onPick:t=>k(n=>({...n,[e]:t}))},e):(0,H.jsx)(XK,{name:e,port:t,control:(R.ui||[]).find(t=>t?.port===e),value:de[e],disabled:b,onCommit:t=>g(n=>({...n,[e]:t}))},e))}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:b,onClick:()=>B(de).catch(()=>{}),children:ge}),S&&(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:S}),ye?(0,H.jsxs)(`div`,{className:`dh-results`,children:[(0,H.jsx)(`h2`,{children:`Result`}),ye]}):!S&&(0,H.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,H.jsx)(hK,{...mK(R,{inputs:de})})})]}):(0,H.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,H.jsx)(uq,{tabs:xe,status:be,initial:r,control:(0,H.jsx)(lq,{on:!E,label:`Example media`,onChange:e=>D(!e)}),children:e=>t.find(t=>t.key===e)?.render()??(e===`activity`?(0,H.jsx)(QK,{entries:A,onClear:()=>j([])}):e===`calls`?w?.calls.length?(0,H.jsx)(`ol`,{className:`dh-calls`,children:w.calls.map((e,t)=>(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:cq(e)}),(0,H.jsx)(`span`,{children:e.name}),(0,H.jsx)(`small`,{children:e.source===`picked`?`read from your file`:e.source===`example`?`read from a StillMade example file`:/mocks/.test(e.source)?`answered from the Block's tests`:`answered by a recorded stand-in`})]},t))}):(0,H.jsx)(`p`,{className:`dh-muted`,children:w?`The last run made no hosted or media calls.`:`Run the Block to see the calls it makes and what answered each one.`}):e===`result`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:re,children:`Clear shared state`})]}),S&&(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:S}),ye||!S&&(0,H.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:b||!ee,onClick:()=>B(de).catch(()=>{}),children:ge})]}),h&&(0,H.jsx)(ZK,{value:de,onCommit:fe,disabled:!ee}),_&&(0,H.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(_,null,2)})]}))})]})}var fq={block:`layers`,connector:`plug`,automation:`clock`,workflow:`list`},pq={block:`Block`,connector:`Connector`,automation:`Automation`,workflow:`Project Type`},mq={module:`Module`,javascript:`JavaScript`,recipe:`Recipe`,capability:`Hosted`,comfyui:`ComfyUI`,desktop:`Desktop`,"browser-application":`Application`},hq={ready:`Gate passed`,"needs-fix":`Needs a fix`,unchecked:`Not checked since it changed`,building:`Being built`},gq=e=>e.kind===`workflow`?`workflow`:e.blockKind||`block`,_q=e=>e.kind===`workflow`?`${e.automation?`Automation`:`Project Type`} · ${e.steps} ${e.steps===1?`Step`:`Steps`}`:[gq(e)===`block`?mq[e.runtime]||`Block`:pq[gq(e)],e.version].filter(Boolean).join(` · `);function vq({status:e}){return(0,H.jsx)(`span`,{className:`ws-dot ws-dot-${e}`,role:`img`,"aria-label":hq[e]||e,title:hq[e]||e})}function yq({templates:e,onAdded:t,onCancel:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`module`),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``);return(0,H.jsxs)(`form`,{className:`ws-new`,onSubmit:async e=>{if(e.preventDefault(),r.trim()){c(!0),u(``);try{let e=await fetch(`/__dev/new`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:r,template:a})}),n=await e.json();if(!e.ok)throw Error(n.error||`The Block could not be added.`);t(n.key)}catch(e){u(e.message)}finally{c(!1)}}},children:[(0,H.jsxs)(`label`,{className:`ws-field`,children:[(0,H.jsx)(`span`,{children:`Name`}),(0,H.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`price-drop-alert`,autoFocus:!0,disabled:s})]}),(0,H.jsxs)(`label`,{className:`ws-field`,children:[(0,H.jsx)(`span`,{children:`Start from`}),(0,H.jsx)(`select`,{value:a,onChange:e=>o(e.target.value),disabled:s,children:e.map(e=>(0,H.jsx)(`option`,{value:e.name,children:e.name},e.name))})]}),l&&(0,H.jsx)(`p`,{className:`ws-problem`,role:`alert`,children:l}),(0,H.jsxs)(`div`,{className:`ws-new-actions`,children:[(0,H.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,disabled:s||!r.trim(),children:s?`Adding`:`Add Block`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:n,children:`Cancel`})]})]})}function bq({data:e,selected:t,onSelect:n,folded:r,onFold:i,follow:a,onFollow:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)([]),d=()=>{r&&i(!1),c(!0),l.length||fetch(`/__dev/templates`).then(e=>e.json()).then(u).catch(()=>{})},f=e.items.filter(e=>e.kind===`block`),p=e.items.filter(e=>e.kind===`workflow`),m=e=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`ws-item`,"aria-current":t===e.key?`true`:void 0,onClick:()=>n(e.key),title:r?`${e.name}: ${hq[e.status]||``}`:void 0,children:[(0,H.jsx)(`span`,{className:`ws-kind`,children:(0,H.jsx)(tG,{name:fq[gq(e)],size:14})}),(0,H.jsxs)(`span`,{className:`ws-text`,children:[(0,H.jsx)(`b`,{children:e.name}),(0,H.jsx)(`small`,{children:_q(e)})]}),(0,H.jsx)(vq,{status:e.status})]})},e.key),h=`${f.length} ${f.length===1?`Block`:`Blocks`} · ${p.length} ${p.length===1?`workflow`:`workflows`}`;return(0,H.jsxs)(`aside`,{className:`ws-side`,"aria-label":`Workspace`,children:[(0,H.jsxs)(`div`,{className:`ws-head`,children:[(0,H.jsx)(`button`,{type:`button`,className:`dh-icon ws-fold`,"aria-label":r?`Open the list`:`Fold the list`,title:r?`Open the list`:`Fold the list`,"aria-expanded":!r,onClick:()=>i(!r),children:(0,H.jsx)(tG,{name:r?`chevronRight`:`chevronLeft`,size:16})}),(0,H.jsxs)(`div`,{className:`ws-title`,children:[(0,H.jsx)(`h1`,{children:e.name}),(0,H.jsx)(`small`,{children:h})]})]}),(0,H.jsxs)(`nav`,{className:`ws-list`,children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Blocks`}),f.length?(0,H.jsx)(`ul`,{children:f.map(m)}):(0,H.jsx)(`p`,{className:`ws-empty`,children:`No Blocks yet. Add one below, or ask your agent.`}),p.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Workflows`}),(0,H.jsx)(`ul`,{children:p.map(m)})]}),e.shared.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Shared code`}),(0,H.jsx)(`ul`,{children:(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`ws-item`,"aria-current":t===`shared`?`true`:void 0,onClick:()=>n(`shared`),title:r?`Shared code`:void 0,children:[(0,H.jsx)(`span`,{className:`ws-kind`,children:(0,H.jsx)(tG,{name:`folder`,size:14})}),(0,H.jsxs)(`span`,{className:`ws-text`,children:[(0,H.jsx)(`b`,{children:`shared/`}),(0,H.jsxs)(`small`,{children:[e.shared.length,` `,e.shared.length===1?`file`:`files`]})]}),(0,H.jsx)(`span`,{})]})})})]})]}),(0,H.jsxs)(`div`,{className:`ws-foot`,children:[s?(0,H.jsx)(yq,{templates:l.length?l:[{name:`module`}],onAdded:e=>{c(!1),n(e)},onCancel:()=>c(!1)}):(0,H.jsxs)(`button`,{type:`button`,className:`btn btn-ghost ws-add`,onClick:d,title:r?`New Block`:void 0,children:[(0,H.jsx)(tG,{name:`plus`,size:14}),(0,H.jsx)(`span`,{className:`ws-text`,children:`New Block`})]}),!s&&(0,H.jsxs)(`div`,{className:`ws-text ws-follow`,children:[(0,H.jsx)(lq,{on:a,label:`Follow the agent`,onChange:o}),(0,H.jsx)(`small`,{children:`Opens the Block your agent last saved.`})]})]})]})}function xq({item:e,onCheck:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(``),o=async()=>{r(!0),a(``);try{await t()}catch(e){a(e.message)}finally{r(!1)}},s=e.gate,c=s?.current;return(0,H.jsxs)(`div`,{className:`ws-checks`,children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsxs)(`span`,{className:`dh-muted`,children:[hq[e.status],`. The gate runs StillMade's readiness check on every Block that changed.`]}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:n,onClick:o,children:n?`Running the gate`:`Run the gate`})]}),(0,H.jsxs)(`ul`,{className:`ws-checklist`,children:[e.problem&&(0,H.jsxs)(`li`,{"data-state":`failed`,children:[(0,H.jsx)(tq,{name:`problem`}),(0,H.jsx)(`span`,{children:e.problem})]}),e.buildProblem&&(0,H.jsxs)(`li`,{"data-state":`failed`,children:[(0,H.jsx)(tq,{name:`problem`}),(0,H.jsxs)(`span`,{children:[`Build from `,e.source,` failed: `,e.buildProblem]})]}),e.source&&!e.buildProblem&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(tq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Built from `,e.source,e.shared.length?`, with shared/${e.shared.join(`, shared/`)}`:``]})]}),e.triggers?.length>0&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(tq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Runs on its own: `,e.triggers.join(`; `),`. Its owner turns it on for a Step in a project; here it runs when you press its button.`]})]}),e.apps?.length>0&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(tq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Uses `,e.apps.map(e=>e.replace(/^app:(openapi:)?/,``)).join(`, `),` with the account each person connects. Here `,e.apps.length===1?`it answers`:`they answer`,` from tests/mocks.json.`]})]}),e.checklist?.map(e=>(0,H.jsxs)(`li`,{"data-state":e.done?`done`:`todo`,children:[(0,H.jsx)(tq,{name:e.done?`done`:`todo`}),(0,H.jsx)(`span`,{children:e.label}),(0,H.jsx)(`small`,{children:e.done?`done`:`to do`})]},e.id)),(0,H.jsxs)(`li`,{"data-state":c?s.ok?`done`:`failed`:`waiting`,children:[(0,H.jsx)(tq,{name:c?s.ok?`done`:`problem`:`todo`}),(0,H.jsxs)(`span`,{children:[`Readiness gate`,c?`: ${s.status}`:s?`: changed since it last ran`:`: not run yet`]}),(0,H.jsx)(`small`,{children:s?.checkedAt?new Date(s.checkedAt).toLocaleTimeString():``})]}),c&&!s.ok&&s.failures.map((e,t)=>(0,H.jsx)(`li`,{className:`ws-failure`,children:e},t))]}),i&&(0,H.jsx)(`p`,{className:`ws-problem`,role:`alert`,children:i})]})}var Sq={completed:`Done`,skipped:`Skipped`,disabled:`Off in this workflow`,failed:`Failed`,blocked:`Waiting on an earlier Step`,"needs-project":`Runs only in a StillMade project`,"needs-context":`Needs project context`,"needs-sample":`Needs a sample input`,"needs-hosted-run":`Runs on credits in StillMade`,deferred:`Runs in StillMade`},Cq=e=>e===`completed`?`done`:e===`failed`?`failed`:e===`running`?`running`:e?`waiting`:`idle`;function wq({itemKey:e,revision:t,theme:n,setTheme:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null);(0,v.useEffect)(()=>{let t=!0;return fetch(`/__dev/workflow?item=${encodeURIComponent(e)}`,{cache:`no-store`}).then(e=>e.json()).then(e=>{t&&(a(e),p(t=>t??e.samples??{}))}).catch(e=>t&&a({problem:e.message})),()=>{t=!1}},[e,t]),(0,v.useEffect)(()=>{let t=new EventSource(`/__dev/events`);return t.addEventListener(`step`,t=>{let n=JSON.parse(t.data);n.item===e&&s(e=>({...e,[n.step.id]:n.step}))}),()=>t.close()},[e]);let m=async()=>{d(!0),s({}),l(null);try{let t=await(await fetch(`/__dev/workflow/run?item=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({inputs:f})})).json();l(t),t.results&&s(Object.fromEntries(t.results.map(e=>[e.id,e])))}catch(e){l({error:e.message})}finally{d(!1)}};if(!i)return(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsx)(`p`,{className:`dh-muted ws-pad`,role:`status`,children:`Loading the workflow`})});if(i.problem)return(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:i.problem})});let h=[...i.steps].reverse().find(e=>o[e.id]?.outputs),g=h&&o[h.id],_=c?.standIns||[],y=u?`Running the Steps…`:c?.error?`The run did not finish`:c?`Ran in ${c.ms} ms${_.length?` · ${_.length} ${_.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Runs on this computer with stand-ins`,b=[{key:`steps`,label:`Steps`},{key:`samples`,label:`Sample inputs`},{key:`connections`,label:`Connections · ${i.connections.length}`}],x=e=>i.steps.find(t=>t.id===e)?.label||e;return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsxs)(`header`,{className:`dh-bar`,children:[(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:i.name}),(0,H.jsxs)(`span`,{className:`dh-meta`,children:[i.automation?`Automation`:`Project Type`,` · `,i.version]})]}),(0,H.jsx)(`span`,{className:`dh-spacer`}),(0,H.jsx)(iq,{label:`Appearance`,value:n,options:DK,onChange:r}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:u,onClick:m,children:u?`Running the workflow`:i.automation?`Run once now · 0 credits`:`Run the workflow · 0 credits`})]}),(0,H.jsxs)(`main`,{className:`dh-main ws-flow`,"aria-label":`Workflow`,children:[(0,H.jsx)(`ol`,{className:`ws-steps`,children:i.steps.map((e,t)=>{let n=o[e.id],r=u&&!n?`running`:Cq(n?.status);return(0,H.jsxs)(`li`,{className:`ws-step`,"data-tone":r,children:[(0,H.jsxs)(`span`,{className:`ws-step-n`,children:[`Step `,t+1]}),(0,H.jsx)(`b`,{children:e.label}),(0,H.jsxs)(`span`,{className:`ws-ports`,children:[(0,H.jsxs)(`span`,{children:[`In: `,e.inputs.map(e=>e.name).join(`, `)||`nothing`]}),(0,H.jsxs)(`span`,{children:[`Out: `,e.outputs.map(e=>e.name).join(`, `)||`nothing`]})]}),(0,H.jsx)(`span`,{className:`ws-step-state`,children:r===`running`?`Waiting to run`:n?`${Sq[n.status]||n.status}${n.status===`failed`&&n.message?`: ${n.message}`:``}`:`Not run yet`})]},e.id)})}),(0,H.jsxs)(`section`,{className:`ws-outcome`,"aria-label":`Result`,children:[(0,H.jsx)(`div`,{className:`ws-outcome-main`,children:c?.error?(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:c.error}):g?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{children:h.label}),Object.entries(g.outputs).map(([e,t])=>(0,H.jsxs)(`div`,{className:`ws-output`,children:[(0,H.jsx)(`span`,{children:HW(e)}),(0,H.jsx)(YW,{value:t,renderMedia:JK})]},e))]}):(0,H.jsx)(`p`,{className:`dh-muted`,children:u?`Running…`:`Run the workflow to see what its last Step makes.`})}),(0,H.jsxs)(`aside`,{className:`ws-outcome-side`,children:[(0,H.jsx)(`h2`,{children:`What this run used`}),_.length?(0,H.jsx)(`ul`,{children:_.map((e,t)=>(0,H.jsxs)(`li`,{children:[e.api,` `,e.name,`: `,/mocks/.test(e.source)?`answered from the Block's tests`:`a recorded stand-in`]},t))}):(0,H.jsx)(`p`,{className:`dh-muted`,children:c?`No hosted calls.`:`Nothing yet.`}),(0,H.jsx)(`p`,{className:`ws-note`,children:`A stand-in run proves the Steps fit together. Real voices, pictures and video run only in StillMade, on credits.`}),i.automation&&(0,H.jsx)(`p`,{className:`ws-note`,children:`An automation. In a project its first Step waits for what is turned on on the Automation page: a schedule, an app event or a webhook. Here it runs once, as if started by hand.`})]})]})]}),(0,H.jsx)(uq,{tabs:b,status:y,children:t=>t===`steps`?(0,H.jsx)(`ol`,{className:`dh-calls`,children:i.steps.map(e=>{let t=o[e.id];return(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:e.label}),(0,H.jsx)(`span`,{children:e.folder?`blocks/${e.folder}`:`${e.blockId}@${e.version}`}),(0,H.jsxs)(`small`,{children:[t?Sq[t.status]||t.status:`Not run yet`,t?.message&&t.status!==`completed`?`: ${t.message}`:``]})]},e.id)})}):t===`samples`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`dh-section-head`,children:(0,H.jsxs)(`span`,{className:`dh-muted`,children:[`What each Step starts with, by Step id. Saved in workflows/`,e.split(`/`).pop(),`.samples.json, the run uses that file instead.`]})}),(0,H.jsx)(ZK,{value:f||{},onCommit:p,disabled:u})]}):(0,H.jsxs)(`ol`,{className:`dh-calls`,children:[i.connections.map((e,t)=>(0,H.jsxs)(`li`,{children:[(0,H.jsxs)(`strong`,{children:[x(e.from.stage),`: `,e.from.port]}),(0,H.jsxs)(`span`,{children:[`to `,x(e.to.stage),`: `,e.to.port]})]},t)),!i.connections.length&&(0,H.jsx)(`li`,{children:`No connections. Each Step takes only its own inputs.`})]})})]})}function Tq({data:e}){return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsx)(`header`,{className:`dh-bar`,children:(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:`Shared code`}),(0,H.jsx)(`span`,{className:`dh-meta`,children:`shared/`})]})}),(0,H.jsx)(`main`,{className:`dh-main`,children:(0,H.jsxs)(`div`,{className:`ws-shared`,children:[(0,H.jsx)(`p`,{className:`dh-muted`,children:`Module Blocks import these files from src/main.js. Building joins them into each Block, so every packed Block still stands alone.`}),(0,H.jsx)(`ul`,{className:`dh-calls`,children:e.shared.map(e=>(0,H.jsxs)(`li`,{children:[(0,H.jsxs)(`strong`,{children:[`shared/`,e.file]}),(0,H.jsx)(`small`,{children:e.usedBy.length?`Used by ${e.usedBy.join(`, `)}`:`Not used yet`})]},e.file))})]})})]})}var Eq=()=>{try{return decodeURIComponent(location.hash.slice(1))}catch{return``}};function Dq({initial:e}){let[t,n]=(0,v.useState)(e),[r,i]=(0,v.useState)(()=>{let t=Eq();return e.items.some(e=>e.key===t)||t===`shared`?t:e.items[0]?.key||``}),[a,o]=(0,v.useState)(()=>VK(`stillmade.dev.workspace.folded`,``)===`1`),[s,c]=(0,v.useState)(()=>VK(`stillmade.dev.workspace.follow`,`1`)===`1`),[l,u]=(0,v.useState)(()=>VK(`stillmade.dev.theme`,`light`)),[d,f]=(0,v.useState)(0),p=(0,v.useRef)(s);p.current=s;let m=(0,v.useCallback)(()=>fetch(`/__dev/workspace`,{cache:`no-store`}).then(e=>e.json()).then(e=>(n(e),e)),[]),h=(0,v.useCallback)(e=>{i(e);try{history.replaceState(null,``,`#${encodeURIComponent(e)}`)}catch{}},[]);(0,v.useEffect)(()=>{let e=new EventSource(`/__dev/events`);return e.addEventListener(`workspace`,e=>{let t=JSON.parse(e.data);m().then(e=>{t.focus&&p.current&&e.items.some(e=>e.key===t.focus)&&h(t.focus),f(e=>e+1)}).catch(()=>{})}),()=>e.close()},[m,h]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=l,HK(`stillmade.dev.theme`,l)},[l]),(0,v.useEffect)(()=>{HK(`stillmade.dev.workspace.folded`,a?`1`:``)},[a]),(0,v.useEffect)(()=>{HK(`stillmade.dev.workspace.follow`,s?`1`:``)},[s]);let g=t.items.find(e=>e.key===r),_=(0,v.useCallback)(async()=>{if(!(await fetch(`/__dev/check`,{method:`POST`})).ok)throw Error(`The gate could not run.`);await m()},[m]),y=(0,v.useMemo)(()=>g?.kind===`block`?[{key:`checks`,label:`Checks`,alert:g.status===`needs-fix`,render:()=>(0,H.jsx)(xq,{item:g,onCheck:_})}]:[],[g,_]),b=g?.kind===`block`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{className:`ws-chip`,children:pq[gq(g)]}),g.status!==`ready`&&(0,H.jsx)(`span`,{className:`ws-chip`,"data-status":g.status,children:hq[g.status]})]}):null;return(0,H.jsxs)(`div`,{className:`ws-page`,"data-folded":a?`true`:`false`,children:[(0,H.jsx)(bq,{data:t,selected:r,onSelect:h,folded:a,onFold:o,follow:s,onFollow:c}),(0,H.jsx)(`div`,{className:`ws-content`,children:!g&&r!==`shared`?(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsxs)(`div`,{className:`ws-pad`,children:[(0,H.jsx)(`h2`,{className:`ws-hello`,children:t.name}),(0,H.jsxs)(`p`,{className:`dh-muted`,children:[`Add a Block from the list, or ask your agent to run `,(0,H.jsx)(`code`,{children:`stillmade-block add <name>`}),`. It shows up here by itself.`]})]})}):r===`shared`?(0,H.jsx)(Tq,{data:t}):g.kind===`workflow`?(0,H.jsx)(wq,{itemKey:g.key,revision:d,theme:l,setTheme:u},g.key):(0,H.jsx)(dq,{item:g.key,extraTabs:y,badges:b,dockOpen:g.status===`ready`?null:`checks`},g.key)})]})}var Oq=(0,y.createRoot)(document.getElementById(`root`));fetch(`/__dev/workspace`,{cache:`no-store`}).then(e=>e.ok?e.json():null).catch(()=>null).then(e=>Oq.render((0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(nq,{}),e?(0,H.jsx)(Dq,{initial:e}):(0,H.jsx)(dq,{})]})));
|
|
1974
|
+
`,wU=`sm.blockZoom.`;function TU(e,t){try{if(!e)return;t===`auto`?localStorage.removeItem(wU+e):localStorage.setItem(wU+e,String(t))}catch{}}function EU(e){if(!e)return 0;let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`)&&t.clientHeight>0)break;t=t.parentElement}let n=t&&t!==document.body?t.getBoundingClientRect():{top:0},r=t&&t!==document.body?t.clientHeight:innerHeight,i=e.getBoundingClientRect().top-n.top+(t&&t!==document.body?t.scrollTop:scrollY);return Math.max(280,Math.round(r-Math.min(i,r*.5)-24))}function DU(e){if(!e)return 0;let t=e.parentElement;for(;t&&t!==document.body;){let e=getComputedStyle(t).overflowY;if((e===`auto`||e===`scroll`)&&t.clientHeight>0)break;t=t.parentElement}if(!t||t===document.body)return EU(e);let n=t.getBoundingClientRect(),r=t.scrollTop,i=e.getBoundingClientRect(),a=i.top-n.top+r,o=i.bottom-n.top+r,s=o;for(let e of t.children)/fixed|absolute/.test(getComputedStyle(e).position)||(s=Math.max(s,e.getBoundingClientRect().bottom-n.top+r));let c=s-o+(parseFloat(getComputedStyle(t).paddingBottom)||0);return Math.max(280,Math.round(t.clientHeight*.7),Math.floor(t.clientHeight-Math.min(a,t.clientHeight*.5)-c))}var OU=(e,t)=>Math.round(Math.min(cU,Math.max(sU,e+t))*100)/100,kU=(0,v.createContext)(null),AU=null,jU=new Set,MU=()=>AU;function NU(e){return jU.add(e),()=>jU.delete(e)}function PU(e,t,n){let r=globalThis.modernScreenshot;if(delete globalThis.modernScreenshot,!r)return;let i=!1,a=[],o=new WeakSet,s=e=>{if(e?.nodeType!==1||o.has(e))return;let t=e.getBoundingClientRect();t.width*t.height<400||t.height>900||(a.push({x:t.left,y:t.top,width:t.width,height:t.height}),a.length>40&&a.shift())},c=()=>{i||(i=!0,setTimeout(()=>{i=!1,n({channel:e,session:t,op:`view-changed`,rects:a.splice(0)},`*`)},100))},l=e=>e.type===`childList`&&[...e.addedNodes,...e.removedNodes].every(e=>o.has(e))||o.has(e.target);new MutationObserver(e=>{let t=e.filter(e=>!l(e));if(t.length){for(let e of t)if(e.type===`childList`)for(let t of e.addedNodes)s(t.nodeType===1?t:t.parentElement);else e.type===`characterData`&&s(e.target.parentElement);c()}}).observe(document.documentElement,{subtree:!0,childList:!0,attributes:!0,characterData:!0});for(let e of[`input`,`change`,`scroll`])addEventListener(e,c,!0);addEventListener(`message`,async i=>{let a=i.data;if(i.source!==parent||!a||a.channel!==e||a.session!==t||a.op!==`capture-view`||typeof a.id!=`string`)return;let s=Math.max(0,Number(a.top)||0),c=Math.min(4e3,Math.max(1,Number(a.height)||innerHeight)),l=document.createElement(`div`);o.add(l);try{l.style.cssText=`all:initial;position:fixed;left:-99999px;top:0;visibility:hidden`;let i=l.attachShadow({mode:`closed`}),o=document.createElement(`div`);i.append(o),document.documentElement.append(l);let u=await r.createContext(document.body,{scale:2,width:innerWidth,height:c,timeout:4e3,features:{restoreScrollPosition:!0},filter:e=>e!==l&&!(/^(VIDEO|AUDIO)$/.test(e.tagName)&&(e.readyState<2||!e.getClientRects().length)),style:{margin:getComputedStyle(document.body).margin,overflow:`visible`,transform:`translateY(${-s}px)`}});u.sandbox={contentWindow:{document:{createElement:e=>document.createElement(e),createElementNS:(e,t)=>document.createElementNS(e,t),body:o},getComputedStyle:(e,t)=>getComputedStyle(e,t)},remove(){}};let d=await createImageBitmap(await r.domToCanvas(u));n({channel:e,session:t,op:`capture-view-result`,id:a.id,bitmap:d},`*`,[d])}catch(r){n({channel:e,session:t,op:`capture-view-result`,id:a.id,error:String(r?.message||r).slice(0,300)},`*`)}finally{l.remove()}})}wt();function FU(e){return V(Array.isArray(e)&&e.length>0&&e.length<=128&&e.every(e=>typeof e==`string`&&/^[a-f0-9]{64}$/.test(e)),`SCHEMA`,`Provide 1–128 exact source digests`),[...new Set(e)]}async function IU(e){pt(e);let t=e?.stages&&e.packages||[];return V(Array.isArray(t)&&t.length<128,`LIMIT`,`Too many packaged Blocks for execution review`),FU(await Promise.all([e,...t].map(e=>ht(e))))}async function LU(e){let t=await IU(e),n=new Set(t),r=e?.stages?e.packages||[]:[e],i=e=>{V(e&&typeof e.digest==`string`&&/^[a-f0-9]{64}$/.test(e.digest),`SCHEMA`,`Block lineage needs exact source digests`),n.add(e.digest),V(n.size<=128,`LIMIT`,`Block source and ancestry exceed the security review limit`)};for(let e of r){let t=e.manifest?.provenance;t?.remixedFrom!==void 0&&i(t.remixedFrom);let n=t?.remixAncestors??[];V(Array.isArray(n)&&n.length<=64,`SCHEMA`,`Block ancestry must contain at most 64 exact source references`),n.forEach(i);let r=e.portable?.lineage?.parents??[];V(Array.isArray(r)&&r.length<=16,`SCHEMA`,`Portable lineage must contain at most 16 exact source references`),r.forEach(i)}return FU([...n])}var RU=`stillmade.block-security.v1`,zU=new Map;function BU(e,t){let n=e?.revision||0,r=t.revision||0;return{revision:Math.max(n,r),published:t.published||e?.published===!0,revoked:n>r?e.revoked:n===r?t.revoked||e?.revoked===!0:t.revoked}}function VU(){try{let e=JSON.parse(globalThis.localStorage?.getItem(RU)||`{}`);for(let[t,n]of Object.entries(e))/^[a-f0-9]{64}$/.test(t)&&n&&typeof n.revoked==`boolean`&&typeof n.published==`boolean`&&Number.isInteger(n.revision)&&n.revision>=0&&zU.set(t,BU(zU.get(t),n))}catch{}return zU}function HU(e){let t=VU();for(let n of e){let e=t.get(n.digest);(n.revoked||n.published||e)&&t.set(n.digest,BU(e,n))}try{globalThis.localStorage?.setItem(RU,JSON.stringify(Object.fromEntries(t)))}catch{}}var UU=()=>Object.assign(Error(`This exact Block version has been quarantined by StillMade. Use a reviewed replacement.`),{code:`BLOCK_REVOKED`});async function WU(e,{signal:t}={}){let n=await LU(e),r=VU();if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});let i=new AbortController,a=()=>i.abort();t?.addEventListener(`abort`,a,{once:!0});let o=setTimeout(a,3e3),s;try{let e=await fetch(`/api/blocks/runtime-policy`,{method:`POST`,credentials:`omit`,cache:`no-store`,headers:{"Content-Type":`application/json`},body:JSON.stringify({digests:n}),signal:i.signal});if(!e.ok)throw Error(`Block security check unavailable`);if(s=await e.json(),!Array.isArray(s.digests)||s.digests.length!==n.length||new Set(s.digests.map(e=>e.digest)).size!==n.length||s.digests.some(e=>!n.includes(e.digest)||typeof e.revoked!=`boolean`||typeof e.published!=`boolean`||!Number.isInteger(e.revision)||e.revision<0))throw Error(`Invalid security response`);HU(s.digests)}catch{if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});if(n.some(e=>r.get(e)?.revoked))throw UU();if(n.some(e=>r.get(e)?.published))throw Object.assign(Error(`Reconnect to check the safety of this published Block before running it.`),{code:`REVOCATION_UNAVAILABLE`});return{checked:!1}}finally{clearTimeout(o),t?.removeEventListener(`abort`,a)}if(n.some(e=>VU().get(e)?.revoked))throw UU();return{checked:!0}}lt();var GU=(e,t)=>Object.freeze({kind:e,mimeType:t}),KU=Object.freeze({png:GU(`image`,`image/png`),jpg:GU(`image`,`image/jpeg`),jpeg:GU(`image`,`image/jpeg`),webp:GU(`image`,`image/webp`),gif:GU(`image`,`image/gif`),mp4:GU(`video`,`video/mp4`),mov:GU(`video`,`video/quicktime`),webm:GU(`video`,`video/webm`),mp3:GU(`audio`,`audio/mpeg`),wav:GU(`audio`,`audio/wav`),m4a:GU(`audio`,`audio/mp4`),aac:GU(`audio`,`audio/aac`),ogg:GU(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(rt).map(([e,t])=>[e,GU(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(KU).filter(([,e])=>e.kind!==`file`))),Object.freeze({"text/csv":[`application/vnd.ms-excel`,`text/x-csv`,`application/csv`],"text/markdown":[`text/x-markdown`,`text/plain`],"application/zip":[`application/x-zip-compressed`],"application/json":[`text/json`]}),Object.freeze([`image`,`video`,`audio`]);var qU=Object.freeze({png:`PNG`,jpg:`JPEG`,webp:`WebP`,gif:`GIF`,mp4:`MP4`,mov:`MOV`,webm:`WebM`,mp3:`MP3`,wav:`WAV`,m4a:`M4A`,aac:`AAC`,ogg:`OGG`,pdf:`PDF`,txt:`TXT`,csv:`CSV`,md:`Markdown`,json:`JSON`,zip:`ZIP`}),JU=e=>Object.entries(KU).filter(([t,n])=>e.includes(n.kind)&&qU[t]).map(([e])=>qU[e]),YU=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],XU=e=>YU([...new Set(JU(e))]);async function ZU(e,t,{guard:n,loadBytes:r}={}){let i=typeof t==`string`&&e?.files&&Object.hasOwn(e.files,t)?e.files[t]:null;if(!i||!FH(i))throw Object.assign(Error(`${String(t).slice(0,160)} is not one of this view's code files.`),{code:`VIEW`});if(typeof n!=`string`||!/^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(n))throw Object.assign(Error(`Invalid interface guard`),{code:`VIEW`});let a=$U.get(i.sha256);if(!a)for(a=(async()=>{let n=await uH(e,t,await r(i.sha256)),a;try{a=new TextDecoder(`utf-8`,{fatal:!0}).decode(n)}catch{throw Object.assign(Error(`Code file ${t} is not UTF-8 text.`),{code:`VIEW`})}return vH(a,t,QU)})(),$U.set(i.sha256,a),a.catch(()=>$U.delete(i.sha256));$U.size>eW;)$U.delete($U.keys().next().value);return(await a).replaceAll(QU,n)}var QU,$U,eW,tW=o((()=>{dH(),QU=`__sm_code_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,$U=new Map,eW=48})),nW=c({loadViewAssets:()=>rW,loadViewCode:()=>iW});async function rW(e,{signal:t}={}){let n={};for(let[r,i]of Object.entries(e?.files||{})){if(FH(i))continue;let a=await uH(e,r,await oW(i.sha256,{signal:t}));n[r]={mediaType:i.mediaType,base64:aW(a)}}return n}function iW(e,t,{guard:n}={}){return ZU(e,t,{guard:n,loadBytes:oW})}var aW,oW,sW=o((()=>{dH(),IH(),tW(),aW=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)},oW=async(e,{signal:t}={})=>{let n=await fetch(`/__dev/files/`+e,{signal:t});if(!n.ok)throw Error(`A view file is missing from the Block folder.`);return new Uint8Array(await n.arrayBuffer())}}));k(),IH(),wt(),bi();var cW=`stillmade.block.view.v1`,lW=5e3,uW=()=>globalThis.crypto.randomUUID(),dW=`*{box-sizing:border-box}html{container:stillmade-view/inline-size;overflow-wrap:anywhere}body{min-width:0;margin:0;padding:max(16px,env(safe-area-inset-top)) max(16px,env(safe-area-inset-right)) max(16px,env(safe-area-inset-bottom)) max(16px,env(safe-area-inset-left));overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}h1,h2{font:200 italic clamp(26px,8cqi,32px)/1.1 var(--font-display);letter-spacing:var(--tr-display)}button,input,textarea,select,summary{font:inherit;color:inherit;max-width:100%}button:where(:not(.sm-add,.sm-tile-tools>*)),input,textarea,select{min-height:44px;border:1px solid var(--border-tok);border-radius:var(--r-3);padding:10px 14px;background:transparent}:where(details:not(.sm-hint))>summary{display:flex;align-items:center;min-height:44px;cursor:pointer}.sm-hint>summary{max-width:none}button:where(:not(.sm-add,.sm-tile-tools>*)){min-width:44px;cursor:pointer;border-radius:var(--r-pill);background:var(--fg);color:var(--bg)}button:disabled{opacity:.5;cursor:default}textarea{display:block;width:100%;min-height:120px}input[type=checkbox],input[type=radio]{width:20px;height:20px;min-height:0;padding:0;margin:0 8px 0 0;vertical-align:middle;accent-color:var(--fg)}input[type=range]{width:100%;min-height:32px;padding:0;border:0;accent-color:var(--fg)}img,video,canvas{max-width:100%}:focus-visible{outline:2px solid var(--signal);outline-offset:3px}@container stillmade-view (max-width:360px){body{padding:12px}button,input,textarea,select{font-size:16px}}`,fW=`*{box-sizing:border-box}html{overflow-wrap:anywhere}body{min-width:0;margin:0;padding:16px;overflow-x:hidden;background:var(--bg);color:var(--fg);font:16px/1.5 var(--font-body)}body:has(> [data-stillmade-layout="own"]){padding:0}`,pW=`:where(html[data-stillmade-center="1"])>:where(body)>:where(:not([data-stillmade-host])),:where(html[data-stillmade-center="2"])>:where(body)>:where(:not([data-stillmade-host]))>:where(*){margin-inline:auto}`,mW=`html[data-stillmade-pick],html[data-stillmade-pick] *{cursor:crosshair!important}html[data-stillmade-pick] [data-stillmade-media]{display:none!important}`,hW=Object.freeze({image:`image/png,image/jpeg,image/webp,image/gif`,video:`video/*`,audio:`audio/*,video/*`,asset:`image/png,image/jpeg,image/webp,image/gif,audio/*,video/*`,file:Object.entries(KU).filter(([,e])=>e.kind===`file`).map(([e])=>`.${e}`).join(`,`)}),gW=e=>e.filter(e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9_-]{0,99}$/.test(e)),_W=e=>`html[data-stillmade-readonly] [data-stillmade-add]${gW(e).map(e=>`,[data-stillmade-add="${e}"]`).join(``)}{display:none!important}html[data-stillmade-readonly] [data-stillmade-remove],html[data-stillmade-readonly] [data-stillmade-move]${gW(e).map(e=>`,[data-stillmade-remove="${e}"],[data-stillmade-move="${e}"]`).join(``)}{display:none!important}html[data-stillmade-readonly] [data-stillmade-action="run"]{display:none!important}`;function vW(e,t){let n=typeof t==`string`&&_t(e?.inputs)&&Object.hasOwn(e.inputs,t)?e.inputs[t]:null;if(!_t(n))throw Error(`${JSON.stringify(String(t))} is not an input of this Block.`);let r=String(n.type||``),i=r.replace(/\[\]$/,``);if(!Object.hasOwn(hW,i))throw Error(`${JSON.stringify(t)} is a ${r} input. Only image, video, audio, asset and file inputs take added files.`);return{name:t,port:n,type:i,multiple:r.endsWith(`[]`),accept:hW[i]}}function yW(e,t){let n=Array.isArray(e)?e:[],r=e=>Number.isInteger(e)&&e>=0&&e<n.length;if(t?.op===`remove`&&r(t.index))return n.filter((e,n)=>n!==t.index);if(t?.op===`move`&&r(t.from)&&r(t.to)){let e=[...n],[r]=e.splice(t.from,1);return e.splice(t.to,0,r),e}throw Error(n.length?`Choose a file from 0 to ${n.length-1}.`:`This input has no files.`)}function bW({accept:e,multiple:t},n=globalThis.document){let r,i=new Promise(i=>{let a=n.createElement(`input`);a.type=`file`,a.accept=e,a.multiple=!!t,a.hidden=!0;let o=!1;r=e=>{o||(o=!0,a.remove(),i(e))},a.addEventListener(`change`,()=>r(Array.from(a.files||[])),{once:!0}),a.addEventListener(`cancel`,()=>r([]),{once:!0}),n.body.append(a),a.click()});return i.cancel=()=>r([]),i}var xW=e=>JSON.stringify(e).replace(/</g,`\\u003c`).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`);function SW(e){if(pt(e),new TextEncoder().encode(JSON.stringify(e)).length>xH.messageBytes)throw Error(`Preview data exceeds 4 MiB`);return structuredClone(e)}var CW=e=>_t(e)&&[`image`,`video`,`audio`].includes(e.kind)&&[`assetId`,`versionId`,`url`].every(t=>typeof e[t]==`string`&&e[t])?mt([e.kind,e.assetId,e.versionId,e.url]):``;function wW(e){let t=(0,v.useRef)({has:!1,original:null,signature:null,value:null});if(t.current.has&&Object.is(t.current.original,e))return t.current.value;let n=e===void 0?`undefined`:mt(e);return t.current.signature===n?t.current.original=e:t.current={has:!0,original:e,signature:n,value:e},t.current.value}function TW(e,t=[]){return Array.isArray(e)?(e.forEach(e=>TW(e,t)),t):_t(e)?CW(e)?(t.push(e),t):(Object.values(e).forEach(e=>TW(e,t)),t):t}var EW=e=>Array.isArray(e)?e.length>0&&e.every(EW):!!CW(e);function DW(e,t,n){if(!_t(e)||!Object.values(e).length||!Object.values(e).every(EW))throw Error(`Only complete saved media references can be chosen as outputs.`);let r=new Set(TW(t).map(CW));for(let t of TW(e))if(!r.has(CW(t))&&!n?.authorizesMedia(t))throw Error(`Choose media supplied by this workspace or recorded in this session.`);return SW(e)}function OW(e){let t=SW(e);if(!_t(t)||!gt(t,`image`))throw Error(`Choose a valid image supplied by this workspace.`);if(t.role!==void 0&&(typeof t.role!=`string`||!/^[a-z][a-z0-9_]{0,79}$/.test(t.role)))throw Error(`This image has an invalid semantic role.`);if(!Array.isArray(t.data)&&!([`assetId`,`versionId`,`url`].every(e=>typeof t[e]==`string`&&t[e].length>0)&&t.assetId.length<=512&&t.versionId.length<=512&&t.url.length<=32768))throw Error(`Keep the complete image reference supplied by this workspace.`);return t}function kW(e,t=xH.imagePreviewEdge){let n=()=>Error(`The host returned an invalid image preview.`),r=SW(e),i=_t(r)&&Object.keys(r).length===3&&[`url`,`width`,`height`].every(e=>Object.hasOwn(r,e))&&[`width`,`height`].every(e=>Number.isInteger(r[e])&&r[e]>0&&r[e]<=t),a=typeof r?.url==`string`&&/^data:image\/(png|jpeg);base64,[A-Za-z0-9+/]+={0,2}$/.exec(r.url)?.[1];if(!i||!a)throw n();let o=r.url.slice(a===`png`?22:23);if(o.length%4!=0)throw n();if(a===`png`){let e=atob(o.slice(0,44)),t=t=>e.charCodeAt(t),i=e=>t(e)*16777216+t(e+1)*65536+t(e+2)*256+t(e+3);if(e.length<33||![137,80,78,71,13,10,26,10].every((e,n)=>t(n)===e)||i(8)!==13||e.slice(12,16)!==`IHDR`||i(16)!==r.width||i(20)!==r.height)throw n();return r}let s=atob(o.slice(0,4096)),c=e=>s.charCodeAt(e),l=e=>c(e)*256+c(e+1);if(c(0)!==255||c(1)!==216)throw n();for(let e=2;e+9<s.length;){if(c(e)!==255)throw n();let t=c(e+1),i=l(e+2);if(t>=192&&t<=207&&![196,200,204].includes(t)){if(l(e+5)!==r.height||l(e+7)!==r.width)throw n();return r}if(i<2)throw n();e+=2+i}throw n()}var AW=()=>`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`;function jW(e,t,n=`light`,r=`package`,i=!1,a=[],o=null,s=!1,c=!1,{assets:l={},filming:u=null,inputTypes:d=null,frameGuard:f=null}={}){hH(e);let p=PH(e),m=r===`package`?e.appearance??`host`:r;m!==`original`&&!p&&WH(e,{appearance:`host`});let h=(m===`original`?e.css??``:e.themedCss??e.css??``)+`
|
|
1975
|
+
`+(p?``:KH),g=globalThis.crypto.randomUUID().replaceAll(`-`,``),_=`__sm_view_${g}`,v=f||AW(),y=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,b=`(()=>{"use strict";${p?`const codeNonce=document.currentScript.nonce;`:``}document.currentScript.remove();const session=${xW(t)},channel=${xW(cW)},send=parent.postMessage.bind(parent);let input={},ready=false,inputRevision=0,editRevision=0,sequence=0,pending=null,pendingAdopt=null,adoptSequence=0,pendingImage=null,imageSequence=0,pendingDesktop=null,desktopSequence=0,pendingAdd=null,addSequence=0,pendingChange=null,changeSequence=0,voiceSequence=0,pendingAllow=null,allowSequence=0;const pendingVoice=new Map(),voiceURLs=new Map();const addTypes=${xW(_t(d)?d:null)},addLocked=new Set(${xW(a.filter(e=>typeof e==`string`))});const addPortProblem=port=>{if(typeof port!=="string"||!port)return "Name the input to add files to, as in StillMade.addFiles('listingPhotos').";if(!addTypes)return "";if(!Object.hasOwn(addTypes,port))return JSON.stringify(port)+" is not an input of this Block. Name a declared image, video, audio, asset or file input.";if(!/^(image|video|audio|asset|file)(\\[\\])?$/.test(addTypes[port]))return JSON.stringify(port)+" is a "+addTypes[port]+" input. Only image, video, audio, asset and file inputs take added files.";return ""};const filesPortProblem=(port,call)=>{if(typeof port!=="string"||!port)return "Name the list input, as in StillMade."+call+"('listingPhotos', 0).";const problem=addPortProblem(port);if(problem)return problem;if(addTypes&&!addTypes[port].endsWith("[]"))return JSON.stringify(port)+" holds one file. StillMade."+call+" changes a list input; StillMade.addFiles replaces a single file.";return ""};const mediaURLs=new Set();const mintedImages=new Set();Object.defineProperty(globalThis,${xW(y)},{configurable:true,value:url=>mintedImages.has(url)});const clearMedia=()=>{for(const url of mediaURLs)URL.revokeObjectURL(url);mediaURLs.clear()};const listeners=new Set();let calls=0,started=0;const now=performance.now.bind(performance),resetTask=setTimeout.bind(globalThis);let gestureId=0,gestureAt=-Infinity;for(const type of ["pointerdown","keydown"])addEventListener(type,event=>{if(event.isTrusted){gestureId++;gestureAt=now();}},true);${p?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${LH.toString()})(channel,session,send,${xW({guardName:v,taskMs:OH.taskMs,assets:l})});const codeAPI=(${RH.toString()})(channel,session,send,codeNonce);`:`const codeAPI=null;Object.defineProperty(globalThis,${xW(_)},{configurable:true,value:()=>{if(calls===0){started=now();resetTask(()=>{calls=0},0)}if(++calls>10000||now()-started>50)throw Error("Interface is doing too much work. Move processing into the Block runtime.")}});addEventListener("message",event=>{if(event.isTrusted&&event.source===parent)calls=0},true);`}let controlEffects=0;let assisted=false,trackedCalls=new Set(),trackedFailure=null,controlOffset=0;const track=promise=>{if(assisted){trackedCalls.add(promise);promise.then(()=>trackedCalls.delete(promise),error=>{trackedFailure=error;trackedCalls.delete(promise)})}return promise};const controlSnapshot=(offset=controlOffset,automatic=true)=>{try{let snapshot;try{snapshot=dynamicUI.inspectControls({offset})}catch(error){if(!automatic||error.message!=="Choose a current control page"||!Number.isSafeInteger(offset)||offset<0)throw error;snapshot=dynamicUI.inspectControls({offset:0});}controlOffset=snapshot.offset;send({channel,session,op:"view-controls",snapshot},"*")}catch(error){send({channel,session,op:"view-controls-error",error:String(error.message).slice(0,1000)},"*")}};const dynamicUI=(${sr.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${or.toString()})(channel,session,${xW(ir)},sharedLifecycle);const textControls=${i?`(()=>{${Xn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${xW(o)},send});})()`:`null`};const sharedControls=(${Yn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${xW(a)});const {documentTools,sharedDocuments}=(${Zn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${kt.toString()})((kind,value,options)=>{if(kind==="media"){if(mediaURLs.size>=${p?OH.mediaPreviews:2})throw Error("Release a previous media preview before opening another");if(!["image","video","audio"].includes(value.kind))throw Error("Choose a picture, audio or video reference");}return new Promise((resolve,reject)=>{const id=String(++imageSequence);pendingImage={id,resolve,reject,media:kind==="media"};send({channel,session,op:kind==="media"?"preview-media":"preview-image",id,value,...(options?.edge?{edge:options.edge}:{})},"*")})});const connectionAPI=(${Dt.toString()})(${xW(cW)},${xW(t)},${c},send),workAPI=(${D.toString()})(${xW(cW)},${xW(t)},${s},send);const liveBridge=(${Ot.toString()})(${xW(cW)},${xW(t)},send,(operation,args)=>api.desktop(operation,args));const editFiles=(call,port,edit)=>{if(!ready)return Promise.reject(Error("Preview is loading"));const problem=filesPortProblem(port,call);if(problem)return Promise.reject(Object.assign(Error(problem),{code:"FILES_PORT"}));const files=Array.isArray(input[port])?input[port]:[],places=edit.op==="move"?[edit.from,edit.to]:[edit.index];if(!places.every(place=>Number.isInteger(place)&&place>=0&&place<files.length))return Promise.reject(Object.assign(Error(files.length?"Choose a file from 0 to "+(files.length-1)+" in StillMade."+call+".":JSON.stringify(port)+" has no files yet."),{code:"FILES_INDEX"}));if(addLocked.has(port))return Promise.reject(Error("This input comes from an earlier Step, so its files cannot be changed here."));if(assisted)return Promise.reject(Error("Only a person changes files. Chat cannot remove or move them."));if(!sharedAPI.getShared().canEdit)return Promise.reject(Error("You can view this project but not change its files."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Remove or move files from a click or key press in this screen."));if(pendingChange)return Promise.reject(Error("Files are already being changed."));if(edit.op==="move"&&edit.from===edit.to)return Promise.resolve({files:files.length});return new Promise((resolve,reject)=>{const id=String(++changeSequence);pendingChange={id,resolve,reject};send({channel,session,op:"change-files",id,port,edit,item:files[edit.op==="move"?edit.from:edit.index],gesture:{id:gestureId,age:now()-gestureAt}},"*")})};const api=Object.freeze({...connectionAPI,...workAPI,live:liveBridge.live,${p?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,loadCode:codeAPI.load,`:``}connectedApp(...args){controlEffects++;return track(connectionAPI.connectedApp(...args))},sharedWork(...args){controlEffects++;return track(workAPI.sharedWork(...args))},previewSharedWorkMedia(...args){controlEffects++;return track(workAPI.previewSharedWorkMedia(...args))},schemaFields:(${cr.toString()})(${JSON.stringify(a)}),...sharedAPI,...documentTools,updateShared(...args){sharedControls.ownSharing();return sharedAPI.updateShared(...args)},connectDocument(...args){sharedControls.ownSharing();return sharedDocuments.connectDocument(...args)},bindShared:sharedControls.bindShared,setSharedDefaults:sharedControls.setSharedDefaults,scheduleSharedEdit:sharedControls.scheduleSharedEdit,render:dynamicUI.render,onAction:dynamicUI.onAction,releaseMedia(url){if(mediaURLs.delete(url))URL.revokeObjectURL(url)},previewMedia(value){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("media",value))},desktop(operation,args={}){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingDesktop)return Promise.reject(Error("A desktop request is already pending"));if(typeof operation!=="string"||JSON.stringify(args).length>131072)return Promise.reject(Error("Invalid desktop request"));return track(new Promise((resolve,reject)=>{const id=String(++desktopSequence);pendingDesktop={id,resolve,reject};send({channel,session,op:"desktop",id,operation,args},"*")}))},get input(){return structuredClone(input)},onInput(fn){if(typeof fn!=="function")throw Error("Expected a function");listeners.add(fn);if(ready)fn(structuredClone(input));return()=>listeners.delete(fn)},useOutput(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pendingAdopt)return Promise.reject(Error("An output choice is already pending"));let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded output values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++adoptSequence);pendingAdopt={id,resolve,reject};send({channel,session,op:"use-output",id,outputs:values},"*")}))},addFiles(port){if(!ready)return Promise.reject(Error("Preview is loading"));const problem=addPortProblem(port);if(problem)return Promise.reject(Object.assign(Error(problem),{code:"ADD_FILES_PORT"}));if(addLocked.has(port))return Promise.reject(Error("This input comes from an earlier Step, so files cannot be added to it here."));if(assisted)return Promise.reject(Error("Only a person adds files. Chat cannot open a file picker."));if(!sharedAPI.getShared().canEdit)return Promise.reject(Error("You can view this project but not add files to it."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Add files from a click or key press in this screen."));if(pendingAdd)return Promise.reject(Error("Files are already being added."));return new Promise((resolve,reject)=>{const id=String(++addSequence);pendingAdd={id,resolve,reject};send({channel,session,op:"add-files",id,port,gesture:{id:gestureId,age:now()-gestureAt}},"*")})},removeFile(port,index){return editFiles("removeFile",port,{op:"remove",index})},moveFile(port,from,to){return editFiles("moveFile",port,{op:"move",from,to})},previewImage(value,options){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value,options))},allowSpending(request){if(!ready)return Promise.reject(Error("Preview is loading"));const credits=request?.credits,label=request?.label;if(!Number.isSafeInteger(credits)||credits<1||credits>${xH.allowanceCredits})return Promise.reject(Error("Name the total in whole credits, from 1 to ${xH.allowanceCredits}, as in StillMade.allowSpending({credits: 24, label: 'Build the panels'})."));if(typeof label!=="string"||!label.trim()||label.length>120)return Promise.reject(Error("Say what the credits are for, in up to 120 characters."));if(assisted)return Promise.reject(Error("Only a person approves spending. Chat cannot."));if(!gestureId||now()-gestureAt>5000||navigator.userActivation&&!navigator.userActivation.isActive)return Promise.reject(Error("Ask from a click or key press in this screen."));if(pendingAllow)return Promise.reject(Error("A spending approval is already open."));return new Promise((resolve,reject)=>{const id=String(++allowSequence);pendingAllow={id,resolve,reject};send({channel,session,op:"allow-spending",id,credits,label:label.trim(),gesture:{id:gestureId,age:now()-gestureAt}},"*")})},previewVoice(voice){if(!ready)return Promise.reject(Error("Preview is loading"));if(typeof voice!=="string"||!/^[a-z0-9_-]{1,64}$/.test(voice))return Promise.reject(Error("Name a StillMade voice, as in StillMade.previewVoice('asteria')."));if(voiceURLs.has(voice))return Promise.resolve({url:voiceURLs.get(voice)});if(pendingVoice.size>=4)return Promise.reject(Error("Wait for the voice samples already loading."));return new Promise((resolve,reject)=>{const id=String(++voiceSequence);pendingVoice.set(id,{voice,resolve,reject});send({channel,session,op:"preview-voice",id,voice},"*")})},run(values){controlEffects++;if(!ready)return Promise.reject(Error("Preview is loading"));if(pending)return Promise.reject(Error("A run is already in progress"));try{dynamicUI.assertCommitted();sharedControls.assertNoComposition();}catch(error){return Promise.reject(error);}let serialized;try{serialized=JSON.stringify(values);if(!values||Array.isArray(values)||typeof values!=="object"||serialized.length>4194304)throw Error("Expected bounded input values")}catch(error){return Promise.reject(error)}return track(new Promise((resolve,reject)=>{const id=String(++sequence),requested=JSON.parse(serialized),sourceRevision=inputRevision,localRevision=editRevision,call={id,resolve,reject,sent:false};pending=call;Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>{dynamicUI.assertCommitted();sharedControls.assertNoComposition();if(pending!==call||!ready)throw Error("Preview was closed before its edits were saved.");if(inputRevision!==sourceRevision||editRevision!==localRevision)throw Error("The input changed while edits were saving. Review it before running again.");const savedText=textControls?.getValues?.()||{};for(const [key,value] of Object.entries(savedText)){const captured=typeof requested[key]==="string"?requested[key]:typeof requested[key]?.text==="string"?requested[key].text:null;if(captured!==null&&captured!==value)throw Error("The input changed while shared text was saving. Review it before running again.");}if(!sharedAPI.getShared().canEdit)throw Error("Shared editing is unavailable or read only.");call.sent=true;send({channel,session,op:"run",id,input:requested,...(gestureId?{gesture:{id:gestureId,age:now()-gestureAt}}:{})},"*");}).catch(error=>{if(pending===call){pending=null;call.reject(error);}});}))}});Object.defineProperty(globalThis,"StillMade",{value:api,writable:false,configurable:false});sharedAPI.onShared(shared=>document.documentElement?.toggleAttribute("data-stillmade-readonly",!shared.canEdit));if(addTypes)for(const node of document.querySelectorAll("[data-stillmade-add],[data-stillmade-remove],[data-stillmade-move]")){const tool=node.hasAttribute("data-stillmade-add")?"":node.hasAttribute("data-stillmade-remove")?"removeFile":"moveFile",problem=tool?filesPortProblem(node.getAttribute(tool==="removeFile"?"data-stillmade-remove":"data-stillmade-move"),tool):addPortProblem(node.getAttribute("data-stillmade-add"));if(problem){send({channel,session,op:"interface-error",error:problem},"*");break;}}addEventListener("click",event=>{const node=event.isTrusted&&event.target&&typeof event.target.closest==="function"?event.target.closest("[data-stillmade-add]"):null;if(!node||node.disabled||node.getAttribute("aria-disabled")==="true")return;event.preventDefault();if(pendingAdd)return;node.setAttribute("aria-busy","true");api.addFiles(node.getAttribute("data-stillmade-add")).catch(error=>{if(error.code==="ADD_FILES_PORT")send({channel,session,op:"interface-error",error:String(error.message).slice(0,1000)},"*")}).finally(()=>node.removeAttribute("aria-busy"))});addEventListener("click",event=>{const node=event.isTrusted&&event.target&&typeof event.target.closest==="function"?event.target.closest("[data-stillmade-remove],[data-stillmade-move]"):null;if(!node||node.disabled||node.getAttribute("aria-disabled")==="true")return;event.preventDefault();if(pendingChange)return;const remove=node.hasAttribute("data-stillmade-remove"),place=name=>{const text=node.getAttribute(name);return text!==null&&/^[0-9]{1,6}$/.test(text)?Number(text):NaN},port=node.getAttribute(remove?"data-stillmade-remove":"data-stillmade-move");node.setAttribute("aria-busy","true");(remove?api.removeFile(port,place("data-index")):api.moveFile(port,place("data-index"),place("data-to"))).catch(error=>{if(error.code==="FILES_PORT")send({channel,session,op:"interface-error",error:String(error.message).slice(0,1000)},"*")}).finally(()=>node.removeAttribute("aria-busy"))});addEventListener("message",event=>{if(event.source!==parent||!event.data||event.data.channel!==channel||event.data.session!==session)return;const data=event.data;if(liveBridge.receive(data))return;if(data.op==="inspect-view-controls"){controlSnapshot(data.offset,false);return;}if(data.op==="locate-view-control"&&typeof data.id==="string"){let rect=null;try{rect=dynamicUI.locateControl(data.control)}catch{}send({channel,session,op:"view-control-rect",id:data.id,rect},"*");return;}if(data.op==="dispatch-named-text"&&typeof data.id==="string"){Promise.resolve().then(()=>textControls.dispatchNative(data.control,data.id)).then(()=>send({channel,session,op:"named-text-result",token:${xW(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${xW(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${xW(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${xW(o)},snapshot:textControls.inspectNative()},"*");return;}if(data.op==="dispatch-view-control"&&typeof data.id==="string"){if(assisted){send({channel,session,op:"view-control-result",id:data.id,error:"A declared control is already running"},"*");return;}assisted=true;trackedFailure=null;const controlDocumentSeal=sharedDocuments.captureControlSettlement(),controlSharedSeal=sharedLifecycle.captureControlState(),controlInputRevision=inputRevision,controlEffectRevision=controlEffects;const personalControlUnchanged=()=>controlDocumentSeal&&inputRevision===controlInputRevision&&controlEffects===controlEffectRevision&&JSON.stringify(sharedLifecycle.captureControlState())===JSON.stringify(controlSharedSeal)&&!controlSharedSeal.closed&&controlSharedSeal.ready&&!controlSharedSeal.pending&&!controlSharedSeal.queued&&!controlSharedSeal.failed&&sharedDocuments.unchangedControlSettlement(controlDocumentSeal);dynamicUI.dispatchControl(data.control,async()=>{for(let round=0;round<16;round++){await Promise.allSettled(Array.from(trackedCalls));await dynamicUI.flushAll();await sharedControls.flushAll();if(personalControlUnchanged())await sharedDocuments.settleControl(controlDocumentSeal);else await sharedDocuments.flushAll();await sharedLifecycle.flushSharedWrites();await new Promise(resolve=>setTimeout(resolve,0));if(trackedFailure)throw trackedFailure;if(!trackedCalls.size){if(controlDocumentSeal&&!personalControlUnchanged())await sharedDocuments.flushAll();dynamicUI.assertCommitted();sharedControls.assertNoComposition();return;}}throw Error("Declared action did not settle");}).then(()=>send({channel,session,op:"view-control-result",id:data.id},"*"),error=>send({channel,session,op:"view-control-result",id:data.id,error:String(error?.message||"Declared action failed").slice(0,1000)},"*")).finally(()=>{assisted=false;controlSnapshot()});return;}if(data.op==="flush-shared"&&typeof data.id==="string"){Promise.resolve().then(()=>dynamicUI.flushAll()).then(()=>sharedControls.flushAll()).then(()=>sharedDocuments.flushAll()).then(()=>sharedLifecycle.flushSharedWrites()).then(()=>dynamicUI.flushAll()).then(()=>sharedControls.assertNoComposition()).then(()=>send({channel,session,op:"flush-shared-result",id:data.id},"*"),error=>send({channel,session,op:"flush-shared-result",id:data.id,error:String(error?.message||"Pending edits could not be confirmed").slice(0,1000)},"*"));return;}if(data.op==="desktop-result"&&pendingDesktop&&data.id===pendingDesktop.id){const call=pendingDesktop;pendingDesktop=null;data.error?call.reject(Error(data.error)):call.resolve(data.result)}else if(data.op==="add-files-result"&&pendingAdd&&data.id===pendingAdd.id){const call=pendingAdd;pendingAdd=null;data.error?call.reject(Error(data.error)):call.resolve({added:Number.isInteger(data.added)&&data.added>=0?data.added:0})}else if(data.op==="change-files-result"&&pendingChange&&data.id===pendingChange.id){const call=pendingChange;pendingChange=null;data.error?call.reject(Error(data.error)):call.resolve({files:Number.isInteger(data.files)&&data.files>=0?data.files:0})}else if(data.op==="use-output-result"&&pendingAdopt&&data.id===pendingAdopt.id){const call=pendingAdopt;pendingAdopt=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="input"){inputRevision+=1;if(pending&&!pending.sent){pending.reject(Error("Preview input changed before its edits were saved."));pending=null;}clearMedia();previews.reset();if(pendingImage)pendingImage.reject(Error("Preview input changed"));pendingImage=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview input changed"));pendingAdopt=null;input=data.input;ready=true;try{sharedControls.useInputDefaults(input)}catch{}for(const fn of listeners)try{fn(structuredClone(input))}catch(error){send({channel,session,op:"interface-error",error:String(error?.message||"The Block interface could not display its input").slice(0,1000)},"*")}}else if(data.op==="result"&&pending?.sent&&data.id===pending.id){const call=pending;pending=null;data.error?call.reject(Error(data.error)):call.resolve(data.outputs)}else if(data.op==="preview-media-result"&&pendingImage?.media&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error)call.reject(Error(data.error));else{try{const url=URL.createObjectURL(data.preview.blob);mediaURLs.add(url);call.resolve({kind:data.preview.kind,url,mimeType:data.preview.blob.type,bytes:data.preview.blob.size,blob:data.preview.blob})}catch(error){call.reject(error)}}}else if(data.op==="code-result"&&codeAPI&&codeAPI.result(data)){}else if(data.op==="allow-spending-result"&&pendingAllow&&data.id===pendingAllow.id){const call=pendingAllow;pendingAllow=null;data.error?call.reject(Error(data.error)):call.resolve({allowed:data.allowed===true,credits:Number.isSafeInteger(data.credits)?data.credits:0})}else if(data.op==="preview-voice-result"&&pendingVoice.has(data.id)){const call=pendingVoice.get(data.id);pendingVoice.delete(data.id);if(data.error)call.reject(Error(data.error));else{try{const url=voiceURLs.get(call.voice)||URL.createObjectURL(data.blob);voiceURLs.set(call.voice,url);call.resolve({url})}catch(error){call.reject(error)}}}else if(data.op==="preview-image-result"&&pendingImage&&data.id===pendingImage.id){const call=pendingImage;pendingImage=null;if(data.error){call.reject(Error(data.error));}else{const url=data.preview?.url;if(typeof url==="string"){mintedImages.delete(url);mintedImages.add(url);if(mintedImages.size>64)mintedImages.delete(mintedImages.values().next().value)}call.resolve(data.preview)}}else if(data.op==="dispose"){liveBridge.dispose();clearMedia();for(const url of voiceURLs.values())URL.revokeObjectURL(url);voiceURLs.clear();for(const call of pendingVoice.values())call.reject(Error("Block was closed"));pendingVoice.clear();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=null;if(pendingAllow)pendingAllow.reject(Error("Block was closed"));pendingAllow=null;if(pendingAdd)pendingAdd.reject(Error("Block was closed"));pendingAdd=null;if(pendingChange)pendingChange.reject(Error("Block was closed"));pendingChange=null;if(pendingAdopt)pendingAdopt.reject(Error("Preview was reset"));pendingAdopt=null;if(pendingImage)pendingImage.reject(Error("Preview was reset"));pendingImage=null;if(pending)pending.reject(Error("Preview was reset"));pending=null;listeners.clear();ready=false}});addEventListener("input",()=>{editRevision+=1;},true);addEventListener("change",()=>{editRevision+=1;},true);addEventListener("compositionstart",()=>{editRevision+=1;},true);addEventListener("keydown",event=>{if(event.key==="Escape"&&!document.documentElement.hasAttribute("data-stillmade-stage"))send({channel,session,op:"escape"},"*")},true);addEventListener("click",event=>{if(event.target.closest?.("a,area"))event.preventDefault()},true);send({channel,session,op:"ready"},"*");})();`,x=p?`document.currentScript.remove();for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${bH(e.javascript||``,v)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${_})=>{"use strict";delete globalThis[${xW(_)}];for(const node of document.querySelectorAll("[data-stillmade-share]")){if(!node.id||document.getElementById(node.id)!==node)throw Error("Each shared control needs a unique ID");StillMade.bindShared(node.getAttribute("data-stillmade-share"),node.id)}\n${gH(e.javascript||``,_)}\n})(globalThis[${xW(_)}]);`.replace(/<\/script/gi,`<\\/script`);return`<!doctype html><html data-mode="${[`dark`,`white`].includes(n)?n:`light`}"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1,viewport-fit=cover"><meta http-equiv="Content-Security-Policy" content="default-src 'none'; script-src 'nonce-${g}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${p?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${p?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${GH.replace(/@font-face\s*\{[^}]*\}/g,``)}${p?fW:dW}${qH}${p?``:pW}${(h||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${mW}${_W(a)}</style></head><body>${e.html}${u?`<script nonce="${g}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${g}">${b.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${g}">document.currentScript.remove();${u?`(${PU.toString()})(${xW(cW)},${xW(t)},parent.postMessage.bind(parent));`:``}(${aU.toString()})(${xW(cW)},${xW(t)});(${oU.toString()})(${xW(cW)},${xW(t)});(${fU.toString()})(${xW(cW)},${xW(t)},(${uU.toString()}),"auto",(${dU.toString()}),${!p});(${pU.toString()})(${xW(cW)},${xW(t)},(${mU.toString().replace(/<\/script/gi,`<\\/script`)})(),${xW(CU)},{minted:(()=>{const read=globalThis[${xW(y)}];delete globalThis[${xW(y)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${XH.toString()})(${xW(cW)},${xW(t)},((validateCursorAnchor)=>(${YH.toString()}))(${JH.toString()}));(${ZH.toString()})(${xW(cW)},${xW(t)},(${$H.toString()}));<\/script><script nonce="${g}">${x}<\/script></body></html>`}function MW({activity:e,declaresFolders:t,session:n}){let[r,i]=(0,v.useState)(!1),a=e?.folders||[],o=e?.entries||[];if(!t&&!o.length)return null;let s=r=>{r.currentTarget.open&&t&&!e&&n.current?.call(`folder.shared`).catch(()=>{})},c=async e=>{i(!0);try{await n.current?.call(`folder.forget`,{folder:e.id})}catch{}finally{i(!1)}};return(0,H.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,H.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,H.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,H.jsx)(`ul`,{children:o.map(e=>(0,H.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,H.jsx)(`p`,{children:`Nothing yet.`})]})}function NW({view:e,input:t={},sharedView:n=null,presenceKey:r=null,peers:i=[],actorId:a=null,onSharedChange:o,sharedText:s=null,sharedWork:c=null,connectedApp:l=null,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y,policyContent:b,policyParent:S,currentAppViewPolicy:D=null,title:O=`Block preview`,height:k=480,fitContent:A=!1,resetKey:j=0,theme:M,appearance:N=`package`,lockedInputKeys:P=[],agentContext:F=null}){let I=wW(e),L=wW(b),ee=wW(S),R=L?.manifest?.runtime===`module`&&L.manifest.permissions?.actions||[],z=[`comfyui`,`capability`].includes(L?.manifest?.runtime)||!!L?.manifest?.desktopTools?.length||L?.manifest?.runtime===`module`&&(!!L?.manifest?.permissions?.capabilities?.length||R.length>0),te=L?.capability?.operation===`image.generate`||R.includes(`media.generate`)?9e5:36e4,B=(0,v.useRef)(null),ne=(0,v.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y}),re=(0,v.useRef)(t),[ie,ae]=(0,v.useState)(``),[oe,se]=(0,v.useState)(!1),[ce,le]=(0,v.useState)(0),ue=(0,v.useRef)(null),de=(0,v.useRef)(null),[fe,pe]=(0,v.useState)(null),[me,he]=(0,v.useState)(null),[ge,_e]=(0,v.useState)(null),ve=L?.manifest?.id||null,[ye,be]=(0,v.useState)(`auto`),[xe,Se]=(0,v.useState)(null),Ce=(0,v.useRef)(ye);Ce.current=ye;let we=e=>{be(e),TU(ve,e)},Te=(0,v.useRef)(1);Te.current=ye===`auto`?xe?.zoom||1:ye;let Ee=(0,v.useRef)(we);Ee.current=we;let De=(0,v.useContext)(kU),Oe=(0,v.useRef)(De);Oe.current=De;let[ke,Ae]=(0,v.useState)(null),[je,Me]=(0,v.useState)(null),[Ne,Pe]=(0,v.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),Fe=(0,v.useRef)(`light`);Fe.current=[`dark`,`white`].includes(M||Ne)?M||Ne:`light`;let Ie=(0,v.useRef)(l);Ie.current=l;let Le=(0,v.useRef)(c);Le.current=c;let Re=(0,v.useRef)(s);Re.current=s;let ze=(0,v.useRef)(!1),[Be,Ve]=(0,v.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),He=()=>{let e={enabled:!!Re.current,projectId:Re.current?.projectId??null,placementId:Re.current?.placementId??null};Ve(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,v.useEffect)(()=>{ze.current||He()},[!!s,s?.projectId,s?.placementId]);let Ue=Be.enabled,We=Be.projectId,Ge=Be.placementId,Ke=!!je?.count&&!!(je.dirty||je.pending||je.error),qe=!!ie&&Ke&&ie===je.error;(0,v.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Pe(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Je=(0,v.useMemo)(()=>{try{let e=SW(t);return{value:e,signature:mt(e)}}catch(e){return{error:e.message}}},[t]);ne.current={onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onPreviewVoice:g,onAllowSpending:_,onError:y},re.current=Je;let[Ye,Xe]=(0,v.useState)(null),Ze=D?Ye?.handle===D&&Ye.allowed:!L||Ye?.content===L&&Ye.parent===ee&&Ye.allowed;(0,v.useEffect)(()=>{if(!L&&!D)return;let e=!0,t=new AbortController;return Xe(null),(D?T(D,{signal:t.signal}):Promise.all([L,...ee?[ee]:[]].map(e=>WU(e,{signal:t.signal})))).then(()=>{e&&Xe({handle:D,content:L,parent:ee,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&L&&hi(L,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(Xe({handle:D,content:L,parent:ee,allowed:!1,error:t.message}),ne.current.onError?.(t))}),()=>{e=!1,t.abort()}},[L,ee,D,ce]);let Qe=PH(I)&&I.files?I.files:null,[$e,et]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!Qe||!Ze){et(null);return}let e=!0,t=new AbortController;return et(null),Promise.resolve().then(()=>(hH(I),yi(()=>Promise.resolve().then(()=>(sW(),nW)),void 0))).then(({loadViewAssets:e})=>e(Qe,{signal:t.signal})).then(t=>{e&&et({files:Qe,assets:t})},t=>{e&&et({files:Qe,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[I,Qe,Ze]);let tt=Qe?$e?.files===Qe?$e:{loading:!0}:null,nt=JSON.stringify([...new Set(P.filter(e=>typeof e==`string`))].sort()),rt=_t(L?.manifest?.inputs)?mt(Object.fromEntries(Object.entries(L.manifest.inputs).map(([e,t])=>[e,String(t?.type||``)]))):``,it=[I,tt,j,N,ce,a,r,z,te,A,Ue,We,Ge,nt,rt,!!L?.manifest?.sharedWork,L?.capability?.operation],at=(0,v.useRef)(null);if(!at.current||it.some((e,t)=>!Object.is(e,at.current.inputs[t]))){let e;try{if(tt?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if(tt?.error)throw Error(tt.error);let t=uW(),n=uW(),r=MU(),i=AW();e={session:t,nativeTextToken:n,codeGuard:i,filming:!!r,html:jW(I,t,Fe.current,N,Ue,JSON.parse(nt),n,!!L?.manifest?.sharedWork,L?.capability?.operation===`connection.execute`,{assets:tt?.assets||{},filming:r,inputTypes:rt?JSON.parse(rt):null,frameGuard:i}),locked:JSON.parse(nt)}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}at.current={inputs:it,document:e}}let ot=at.current.document,st=ot?.session;(0,v.useEffect)(()=>{let e=B.current?.contentWindow;e&&st&&e.postMessage({channel:cW,session:st,op:`zoom-mode`,mode:ye},`*`)},[ye,st]);let ct=/\bdata-stillmade-layout\s*=\s*["']?own\b/.test(typeof I?.html==`string`?I.html:``);(0,v.useEffect)(()=>{if(!A||!st)return;let e=null,t=()=>{e=null;let t=B.current?.contentWindow,n=EU(B.current);t&&t.postMessage({channel:cW,session:st,op:`zoom-space`,height:n},`*`),ct&&B.current&&_e(Math.min(3e4,DU(B.current)))},n=()=>{clearTimeout(e),e=setTimeout(t,200)},r=null;if(ct&&B.current&&typeof ResizeObserver==`function`){r=new ResizeObserver(n);for(let e=B.current.parentElement;e&&e!==ot.body;e=e.parentElement)r.observe(e)}let i=ct&&!oe?[300,1e3,2500].map(e=>setTimeout(t,e)):[];return addEventListener(`resize`,n),()=>{clearTimeout(e),i.forEach(clearTimeout),r?.disconnect(),removeEventListener(`resize`,n)}},[A,st,ct,oe]);let lt=(0,v.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[ot.session]),ut=(0,v.useRef)(n);ut.current=n??lt;let dt=(0,v.useRef)(n==null);dt.current=n==null;let ft=(0,v.useRef)({session:null,count:0}),pt=(0,v.useRef)(null),gt=(0,v.useRef)(null),V=(0,v.useRef)(null),vt=(0,v.useRef)(null),yt=(0,v.useRef)(null),bt=(0,v.useRef)(null),xt=(0,v.useRef)(null);bt.current={key:r,peers:i,actorId:a};let St=(0,v.useRef)(null),Ct=(0,v.useRef)(null);Ct.current={input:Je.signature,error:Je.error,view:I,policyContent:L,policyParent:ee,resetKey:j,appearance:N,policyReady:Ze};let wt=(0,v.useRef)(null);wt.current=mt([F?.projectId,F?.placementId,F?.sourceDigest,a].map(e=>e??null));let[Tt,Dt]=(0,v.useState)(null),Ot=mt([At(),a,wt.current,ot.session,Je.signature,Ze].map(e=>e??null));(0,v.useEffect)(()=>{let e=!0;if(Dt(null),!F?.projectId||!F?.placementId||!F?.sourceDigest||Je.error||!Ze||a!==At())return()=>{e=!1};let t=Ot;return ht(Je.value).then(n=>{e&&Dt({basis:t,value:{version:1,actorId:a,projectId:F.projectId,placementId:F.placementId,sourceDigest:F.sourceDigest,inputDigest:n}})},()=>{e&&Dt(null)}),()=>{e=!1}},[Ot]),Tt?.basis===Ot&&Tt.value;let[kt,jt]=(0,v.useState)(null),Mt=(0,v.useRef)(null),Nt=(0,v.useRef)(null),[Pt,Ft]=(0,v.useState)(null),[It,Lt]=(0,v.useState)(!1),[Rt,zt]=(0,v.useState)(!1),[Bt,Vt]=(0,v.useState)(null);Bt&&Bt.actor===a&&Bt.runtimeActor===At()&&Bt.identity===wt.current&&Bt.session===ot.session&&Object.keys(Bt.authority).every(e=>Bt.authority[e]===Ct.current[e])&&Bt.evidence,{...F},L?.manifest?.id,L?.manifest?.version,ot.session,Je.signature,ut.current?.canEdit,{...F},ot.session,Je.signature,ut.current?.canEdit,(0,v.useEffect)(()=>{if(jt(null),Ft(null),zt(!1),Lt(!1),Vt(null),ae(``),_e(null),Ae(null),Me(null),ot.error||ot.loading||!Ze)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=[],p=0,m=0,h=new Set,g=-1/0,_=-1/0,v=e=>{e.isTrusted&&(g=Date.now())};globalThis.document.addEventListener(`pointerdown`,v,!0),globalThis.document.addEventListener(`keydown`,v,!0);let y,b=0,x=null,S=[],T=null,D=0,O=!1,k=0,j=new Set,M=0,N=null,P=0,ee=0,R=null,ie=0,oe=PH(I),ce=null,le=()=>{ce&&globalThis.document.fullscreenElement!==ce&&(ce=null,ge({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,le);let fe=()=>{let t;return t=jz(L,{onStatus:n=>{e&&y===t&&pe(n)},onLive:(n,r)=>{e&&y===t?B.current?.contentWindow?.postMessage({channel:cW,session:ot.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&y===t&&he(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};y=fe(),ue.current=y,pe(null),he(null);let me=()=>{if(!e||!ut.current?.canEdit)return;let t=y;y=fe(),ue.current=y,x=null,pe(null),Promise.resolve(t.close()).catch(()=>{})};de.current=me;let ge=t=>{e&&B.current?.contentWindow?.postMessage({channel:cW,session:ot.session,...t},`*`)},ve=null,ye=0,be=(e,t)=>{let n=gt.current,r=B.current,i=n?.parentElement;if(!n||!r||!i)return;let a=Math.max(0,t?.x??0),o=Math.max(0,t?.y??0),s=Math.min(r.clientWidth,(t?.x??0)+(t?.width??0)),c=Math.min(r.clientHeight,(t?.y??0)+(t?.height??0));if(!t||s<=a||c<=o){n.hidden=!0,delete n.dataset.control;return}let l=r.getBoundingClientRect(),u=i.getBoundingClientRect();n.style.transform=`translate(${l.left+r.clientLeft-u.left-i.clientLeft+a}px,${l.top+r.clientTop-u.top-i.clientTop+o}px)`,n.style.width=`${s-a}px`,n.style.height=`${c-o}px`,n.dataset.control=e,n.hidden=!1};be(null,null),V.current=n=>{!e||!t||typeof n!=`string`||ve&&Date.now()-ve.at<1e3||(ve={id:`locate-`+ ++ye,control:n,at:Date.now()},ge({op:`locate-view-control`,id:ve.id,control:n}))};let xe=new Map,we=new Set,De=0,ke=!1,je=(e,t)=>new Promise(n=>{let r=`film-`+ ++De,i=setTimeout(()=>{xe.delete(r),n(null)},6e3);xe.set(r,e=>{clearTimeout(i),xe.delete(r),n(e)}),ge({op:e,id:r,...t})}),Ne=ot.filming&&B.current?NU({element:B.current,placementId:F?.placementId||null,capture:e=>je(`capture-view`,e),locate:e=>je(`locate-view-control`,{control:e}),get drawn(){return ke},onChange:e=>(we.add(e),()=>we.delete(e))}):null,Pe=null,Be=null,Ve=0,Ke=!1,qe=a,Je=Ct.current,Ye=wt.current,Xe=(t,n)=>{if(!e||Ke||t?.signal?.aborted||At()!==qe||wt.current!==Ye||Be&&re.current.signature!==Be.inputIdentity||Pe&&re.current.signature!==Pe.inputIdentity&&re.current.signature!==n||Object.keys(Je).filter(e=>e!==`input`).some(e=>Je[e]!==Ct.current[e]))throw Ke=!0,zt(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Qe=e=>{if(!Pe)return;let t=Pe;Pe=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Lt(!1),t.reject(e)};Nt.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Xe(r),!t||Pe)throw Error(`The declared interface is loading or busy.`);if(e===`dispatch-view-control`&&!r.taskFence)throw Error(`The declared interface requires its active project task.`);let s=String(++Ve),c=()=>{Ke=!0,zt(!1),i?.abort(),Qe(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,te);Pe={id:s,op:e,inputIdentity:re.current.signature,offset:n.offset,context:r,resolve:a,reject:o,timer:l,abort:c},r.signal?.addEventListener(`abort`,c,{once:!0}),e===`dispatch-view-control`&&Lt(!0),ge({op:e,id:s,...n})}catch(e){o(e)}})},Mt.current={request:(e,n)=>new Promise((r,i)=>{try{if(Xe(n),!t||Pe||Be||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++Ve),o=()=>{Ke=!0,zt(!1),Be?.id===a&&(Be=null,Lt(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,te);Be={id:a,field:e.field,inputIdentity:re.current.signature,context:n,resolve:r,reject:i,timer:s,abort:o},n.signal?.addEventListener(`abort`,o,{once:!0}),Lt(!0),ge({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let $e=()=>{if(Ke)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return Pe?.op===`dispatch-view-control`?(Xe(Pe.context),Pe.context):null},et=!1,tt=0,nt=[],rt=0,it=!1,at=0,st=[],lt=0,ft=0,ht=[],Tt=null,Dt=!1,Ot={projectId:We,placementId:Ge,actorId:a},kt=()=>e&&Re.current?.projectId===Ot.projectId&&Re.current?.placementId===Ot.placementId,Pt=e=>({message:String(e?.message||`Shared text failed.`).slice(0,1e3),...typeof e?.code==`string`&&/^[A-Z][A-Z0-9_]{0,79}$/.test(e.code)?{code:e.code}:{}}),It=Re.current?.projectId&&a?Qn({projectId:Re.current.projectId,actorId:a,headers:$n,onChange:e=>{if(kt()){if(e.kind===`revoked`){Dt=!0,ge({op:`shared-view`,value:{...ut.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||Tt===null&&(Tt=setTimeout(()=>{Tt=null,t&&kt()&&!Dt&&ge({op:`text-refresh`})},100)))}}}):null,Rt=Le.current?.projectId&&a?Qn({projectId:Le.current.projectId,actorId:a,headers:$n,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(rt++,ge({op:`shared-work-refresh`}))}}):null,Bt=()=>{t&&ge({op:`theme`,mode:Fe.current})};xt.current=Bt;let Ht=`[]`,Ut=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=bt.current,i=!dt.current&&e&&localStorage.getItem(`stillmade:show-shared-cursors`)!==`false`?n.filter(t=>t.user_id!==r&&t.selection?.cursor?.visible&&t.selection.cursor.surface===e).slice(0,50).flatMap(e=>{let t=JH(e.selection.cursor.anchor);return t?[{id:String(e.session_id).slice(0,200),label:String(e.label||`Teammate`).slice(0,120),anchor:t}]:[]}):[],a=JSON.stringify(i);a!==Ht&&(Ht=a,ge({op:`peer-cursors`,peers:i}))};yt.current=Ut,window.addEventListener(`stillmade:cursor-preferences`,Ut),window.addEventListener(`storage`,Ut);let Wt=null,Gt=()=>{let e=B.current;if(!e)return null;let t=e.getBoundingClientRect();return{x:t.left+e.clientLeft,y:t.top+e.clientTop,right:t.right,bottom:t.bottom}},Kt=()=>{Wt&&(Wt.bounds=Gt())},qt=()=>{Wt&&(Wt=null,window.removeEventListener(`scroll`,Kt,{capture:!0}),window.removeEventListener(`resize`,Kt))},Jt=n=>{let r=n.detail;e&&r?.root?.contains?.(B.current)&&(r.action===`start`&&t&&!Wt?(Wt={bounds:Gt()},window.addEventListener(`scroll`,Kt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Kt),ge({op:`pick-start`})):r.action===`stop`&&Wt&&(qt(),ge({op:`pick-stop`})))};window.addEventListener(QH.control,Jt);let Yt=e=>{ae(e),ne.current.onError?.(Object.assign(Error(e),{shown:!0}))},Xt=()=>{e&&(clearInterval(N),R?.disconnect(),Promise.resolve(y?.call(`live.stop`)).catch(()=>{}),Yt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),B.current&&(B.current.src=`about:blank`))};pt.current=oe?()=>{e&&(clearInterval(N),Promise.resolve(y?.call(`live.stop`)).catch(()=>{}),Yt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),B.current&&(B.current.src=`about:blank`))}:null;let Zt=()=>{if(typeof PerformanceObserver!=`function`||!PerformanceObserver.supportedEntryTypes?.includes(`longtask`))return;let e=[],t=e=>Array.from(e.attribution||[]).some(e=>e.containerType===`iframe`&&typeof e.containerSrc==`string`&&e.containerSrc.endsWith(`#${ot.session}`));R=new PerformanceObserver(n=>{for(let r of n.getEntries()){if(!t(r))continue;let n=r.startTime+r.duration;if(e=e.filter(e=>e.end>n-5e3),e.push({end:n,duration:r.duration}),r.duration>=OH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Xt()}});try{R.observe({type:`longtask`})}catch{R=null}},Qt=()=>{P=Date.now(),N=setInterval(()=>{if(!e)return clearInterval(N);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-P>8e3)return Xt();ge({op:`ping`,id:String(++ee)})},2e3)};se(!0);let $t=setTimeout(()=>{e&&!t&&(se(!1),Yt(C()?w():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),B.current&&(B.current.src=`about:blank`))},C()?5e3:15e3),en=e=>{let t=o;t&&(Vt(null),o=null,t.controller.abort(),e&&ge({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},tn=()=>{if(!t)return;let e=re.current;if(e.error){en(`Preview input is unavailable.`),Yt(e.error);return}s!==e.signature&&(en(`Preview input changed. Use its current image.`),s=e.signature,ge({op:`input`,input:e.value}))};St.current=tn;let nn=null,rn=!1,an=0,on=[],sn=null,cn=0,ln=null,un=Jn(()=>{if(dt.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(sn)return sn.promise;let n=String(++cn),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{sn?.id===n&&(sn=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return sn={id:n,promise:a,resolve:r,reject:i,timer:o},ge({op:`flush-shared`,id:n}),a}),dn=()=>{if(t&&ut.current)try{let e=SW(ut.current),t=mt(e);if(t===nn)return;nn=t,ge({op:`shared-view`,value:e})}catch(e){Yt(e.message)}};vt.current=dn;let fn=t=>{e&&dt.current&&(ut.current.outputs=t,dn())},pn=r=>{let s=r.data;if(oe&&e&&_t(s)&&s.op===`navigated`&&s.channel===cW&&s.session===ot.session&&(r.source===null||r.source===B.current?.contentWindow)){pt.current?.();return}if(!e||r.source!==B.current?.contentWindow||!_t(s)||s.channel!==cW||s.session!==ot.session)return;if(s.op===`document-ready`){n||(n=!0,ge({op:`document`,html:ot.html}));return}if(s.op===`view-changed`){ke=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>_t(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of we)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&xe.has(s.id)){let e=xe.get(s.id),t=s.rect;if(!e){s.bitmap?.close?.();return}e(s.op===`capture-view-result`?s.bitmap instanceof ImageBitmap?s.bitmap:null:_t(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`zoom-key`){Ee.current(s.step===`auto`?`auto`:OU(Te.current,s.step===`bigger`?lU:-lU));return}if(s.op===`media-stage`){let e=B.current,t=globalThis.document;if(!e)return;if(s.on===!0){if(!t.fullscreenElement&&globalThis.navigator?.userActivation?.isActive&&t.activeElement===e&&typeof e.requestFullscreen==`function`){ce=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{ce=null})}catch{ce=null}}}else if(t.fullscreenElement===e){ce=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){Se(e=>{let t={supported:s.supported===!0,zoom:Number.isFinite(s.zoom)?s.zoom:1};return e&&e.supported===t.supported&&e.zoom===t.zoom?e:t});return}if(s.op===`ready`){t||(t=!0,se(!1),clearTimeout($t),ge({op:`zoom-mode`,mode:Ce.current}),A&&ge({op:`zoom-space`,height:EU(B.current)}),oe&&(Qt(),Zt()),Bt(),tn(),dn(),Ut(),ge({op:`inspect-view-controls`,offset:0}),ge({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!sn||s.id!==sn.id)return;let e=sn;sn=null,clearTimeout(e.timer);let t=s.error||ln;t?e.reject(Error(String(t).slice(0,1e3))):e.resolve({queued:!0});return}if(s.op===`escape`){let e=Date.now();globalThis.document.activeElement===B.current&&e-M>=300&&(M=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){oe&&typeof s.id==`string`&&(P=Date.now());return}if(s.op===`unresponsive`){oe&&Xt();return}if(s.op===`interface-error`){Yt(String(s.error||`The Block interface could not display its input`).slice(0,1e3));return}if(s.op===`document-store-status`){let e=s.status;_t(e)&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=8)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&Ae(e);return}if(s.op===`text-recovery-status`){let e=s.status;Ue&&_t(e)&&Object.keys(e).every(e=>[`count`,`dirty`,`pending`,`readonly`,`error`,`retryable`].includes(e))&&[`count`,`dirty`,`pending`,`readonly`].every(t=>Number.isInteger(e[t])&&e[t]>=0&&e[t]<=100)&&[`dirty`,`pending`,`readonly`].every(t=>e[t]<=e.count)&&(e.error===null||typeof e.error==`string`&&e.error.length<=1e3)&&typeof e.retryable==`boolean`&&Me(e);return}if(!t)return;if(s.op===`pick-hover`){if(!Wt)return;let e=rU(s.hover),t=Wt.bounds,n=null;if(e&&t){let r=Math.max(t.x,e.rect.x+t.x),i=Math.max(t.y,e.rect.y+t.y),a=Math.min(t.right,e.rect.x+t.x+e.rect.width),o=Math.min(t.bottom,e.rect.y+t.y+e.rect.height);a>r&&o>i&&(n={...e,rect:{x:r,y:i,width:a-r,height:o-i},cursor:{x:e.cursor.x+t.x,y:e.cursor.y+t.y}})}window.dispatchEvent(new CustomEvent(QH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!Wt)return;qt();let e=s.op===`pick-result`?iU(s.target):null;e?window.dispatchEvent(new CustomEvent(QH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(QH.cancel));return}if(s.op===`named-text-controls`){if(s.token===ot.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=SW(s.snapshot);e.every(e=>_t(e)&&typeof e.field==`string`&&typeof e.identity==`string`&&typeof e.value==`string`&&e.value.length<=1e4&&typeof e.partial==`boolean`&&typeof e.ready==`boolean`&&typeof e.disabled==`boolean`)&&jt(e)}return}if(s.op===`named-text-result`){let e=Be;if(!e||s.id!==e.id||s.token!==ot.nativeTextToken)return;try{if(Xe(e.context),s.error)throw Error(String(s.error).slice(0,1e3));e.resolve()}catch(t){e.reject(t)}finally{Be=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Lt(!1)}return}if(s.op===`view-controls`){try{let e=SW(s.snapshot);if(!_t(e)||!Number.isSafeInteger(e.revision)||!Number.isSafeInteger(e.total)||e.total<0||e.total>1e4||!Number.isSafeInteger(e.offset)||!Array.isArray(e.controls)||e.controls.length>20||e.controls.some(e=>!_t(e)||typeof e.id!=`string`||typeof e.identity!=`string`||typeof e.action!=`string`||typeof e.disabled!=`boolean`||typeof e.hidden!=`boolean`))throw Error(`Invalid declared interface controls.`);if(Ft(e),zt(!Ke),Pe?.op===`inspect-view-controls`&&e.offset===Pe.offset){let e=Pe;Xe(e.context),Pe=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Qe(e)}return}if(s.op===`view-control-rect`){if(!ve||s.id!==ve.id)return;let{control:e}=ve,t=s.rect;ve=null,be(e,_t(t)&&[`x`,`y`,`width`,`height`].every(e=>Number.isFinite(t[e]))&&t.width>0&&t.height>0?t:null);return}if(s.op===`view-controls-error`){Qe(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(Pe?.op!==`dispatch-view-control`||s.id!==Pe.id)return;let e=Pe;try{if(Xe(e.context),s.error)throw Error(String(s.error).slice(0,1e3));Pe=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Lt(!1),e.resolve()}catch(e){Qe(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=tt)return;tt=Number(s.id);let t=e=>ge({op:`connected-app-result`,id:s.id,...e}),n=Ie.current,r=Ct.current;nt=nt.filter(e=>Date.now()-e<6e4);try{if(L?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Et(s.operation,SW(s.args));if(i.operation!==`tasks`&&!ut.current?.canEdit)throw Error(`This workspace is read only.`);if(et||nt.length>=30)throw Error(`Wait for the current task request.`);et=!0,nt.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Ie.current?.projectId||n.placementId!==Ie.current?.placementId||Object.keys(r).some(e=>r[e]!==Ct.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:SW(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{et=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-media-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=at)return;at=Number(s.id);let t=Le.current,n=Ct.current,r=rt,i=e=>ge({op:`shared-work-result`,id:s.id,...e});try{if(!L?.manifest?.sharedWork||!L.manifest.permissions?.project?.includes(`work.shared`)||!t?.previewMedia||typeof s.contributionId!=`string`||!/^[0-9a-f-]{36}$/i.test(s.contributionId))throw Error(`Choose a permitted saved creative in this workspace.`);if(st=st.filter(e=>Date.now()-e<6e4),it||st.length>=60)throw Error(`Wait for the current media preview.`);it=!0,st.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==rt||Object.keys(n).some(e=>n[e]!==Ct.current[e]))throw Error(`This workspace changed before the creative preview.`);if(!(t.media instanceof Blob)||!t.media.size||t.media.size>67108864||![`image`,`video`,`audio`].includes(t.kind)||!t.media.type.startsWith(t.kind+`/`))throw Error(`This preview exceeds the media limit.`);i(t)},e=>i({error:String(e.message||`Media preview failed.`).slice(0,1e3)})).catch(e=>i({error:String(e.message).slice(0,1e3)})).finally(()=>{it=!1})}catch(e){i({error:String(e.message).slice(0,1e3)})}return}if(s.op===`shared-work-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=at)return;at=Number(s.id);let t=e=>ge({op:`shared-work-result`,id:s.id,...e}),n=Le.current,r=Ct.current,i=rt;st=st.filter(e=>Date.now()-e<6e4);try{if(!L?.manifest?.permissions?.project?.includes(`work.shared`)||!L.manifest.sharedWork||!n?.request)throw Error(`Shared work is unavailable in this preview. Open the saved Block in its project.`);let a=E(s.operation,SW(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!ut.current?.canEdit)throw Error(`This workspace is read only.`);if(it||st.length>=60)throw Error(`Wait for the current shared-work request.`);it=!0,st.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==Le.current?.projectId||n.placementId!==Le.current?.placementId||Object.keys(r).some(e=>r[e]!==Ct.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==rt){if([`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation))throw Error(`Saved-work access changed. Read its current version.`);t({result:{saved:!0,refreshRequired:!0}});return}t({result:SW(o)})},e=>t({error:String(e.message||`Shared work failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{it=!1})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`text-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=ft)return;ft=Number(s.id);let e=e=>ge({op:`text-result`,id:s.id,...e}),t=Re.current,n=re.current.signature,r=Ct.current;if(ht=ht.filter(e=>Date.now()-e<6e4),!Ue||!kt()||!t||typeof t.request!=`function`||![`read`,`initialize`,`update`,`reset`].includes(s.action)||typeof s.key!=`string`||!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(s.key)||[`constructor`,`prototype`,`__proto__`].includes(s.key)){e({error:{message:`Shared text is unavailable for this field.`}});return}if(lt>=16||ht.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!kt()||re.current.error||re.current.signature!==n||Object.keys(r).some(e=>r[e]!==Ct.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(Dt||s.action!==`read`&&!ut.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=SW(s.body),!_t(a)||new TextEncoder().encode(JSON.stringify(a)).length>5e4||Object.keys(a).some(e=>![`protocol`,`requestId`,`sourceIdentity`,`epoch`,`textRevision`,`value`,`update`].includes(e)))throw Error(`Invalid shared text request.`)}catch(t){e({error:Pt(t)});return}lt++,ht.push(Date.now()),Promise.resolve().then(async()=>{if(i(),$e()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=Be,n;if(e&&s.action!==`read`){if(Xe(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==ot.nativeTextToken||s.nativeText?.callId!==e.id)throw Error(`Unrelated text events cannot use this native task.`);n=e.context}else if(s.nativeText)throw Error(`The original text invocation is no longer current; do not replay.`);return await t.request(s.action,{...a,placementId:t.placementId,fieldKey:s.key},n)}catch(e){if(s.action===`read`&&e.code===`SHARED_TEXT_FIELD_UNSUPPORTED`&&typeof ut.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:SW(t)})}).catch(t=>e({error:Pt(t)})).finally(()=>{lt--});return}if(s.op===`cursor`){let e=s.cursor;if(_t(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=B.current?.getBoundingClientRect(),n=JH(e.anchor),r=bt.current.key;t&&window.dispatchEvent(new CustomEvent(`stillmade:sandbox-cursor`,{detail:{x:(t.left+e.x*t.width)/Math.max(1,window.innerWidth),y:(t.top+e.y*t.height)/Math.max(1,window.innerHeight),visible:e.visible!==!1,...n&&typeof r==`string`&&r.length>0&&r.length<=200&&!dt.current?{anchor:n,surface:r}:{}}}))}return}if(s.op===`shared-view-update`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=an)return;an=Number(s.id);let t=e=>{ln=e.error?String(e.error):null,ge({op:`shared-view-result`,id:s.id,...e})};if(on=on.filter(e=>Date.now()-e<6e4),rn||on.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!ut.current?.canEdit||!dt.current&&typeof ne.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=SW(s.request),new TextEncoder().encode(JSON.stringify(n)).length>ir.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}rn=!0,on.push(Date.now()),Promise.resolve().then(()=>{if(!e||!ut.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if($e(),dt.current){ut.current.state=ar(ut.current.state,n),dn();return}let t=$e();return ne.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{rn=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&Oe.current?.(s.height),A&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&_e(Math.max(280,Math.min(3e4,ct?DU(B.current):s.height)));return}if(s.op===`live-ack`){y?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=b)return;b=Number(s.id);let t=e=>ge({op:`desktop-result`,id:s.id,...e});if(S=S.filter(e=>Date.now()-e<6e4),x||S.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=SW(s.args||{}),JSON.stringify(n).length>131072||!_t(n))throw Error(`Desktop arguments exceed the limit`)}catch(e){t({error:e.message});return}let r=![`tool.status`,`storage.info`,`storage.list`,`storage.read`,`record.status`,`device.info`,`record.cancel`,`session.close`,`live.status`,`live.stop`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`].includes(s.operation)&&(s.operation!==`folder.pick`||s.args?.write===!0);if(r&&!ut.current?.canEdit){t({error:`Desktop changes are unavailable while this workspace is read only.`});return}if(s.operation===`record.cut`){let e=n?.source,r=CW(e),i=[];try{i=TW(re.current?.value).map(CW)}catch{}if(!r||!(y.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:y};S.push(Date.now()),x=i,Promise.resolve().then(()=>{if(!e||i.native!==y||r&&!ut.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if($e()&&r)throw Error(`Assisted desktop mutations require a task-safe native interface; this control is unavailable.`);return i.native.call(s.operation,n,[`record.cut`,`folder.write`].includes(s.operation)?{received:(()=>{try{return TW(re.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==y||r&&!ut.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:SW(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{x===i&&(x=null)});return}if(s.op===`add-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=D)return;D=Number(s.id);let t=e=>ge({op:`add-files-result`,id:s.id,...e});try{let n=vW(L?.manifest,s.port);if(!ut.current?.canEdit)throw Error(`You can view this project but not add files to it.`);if(ot.locked.includes(n.name))throw Error(`This input comes from an earlier Step, so files cannot be added to it here.`);if($e())throw Error(`Only a person adds files. Chat cannot open a file picker.`);if(typeof ne.current.onAddFiles!=`function`)throw Error(`Adding files is unavailable here.`);if(T)throw Error(`Files are already being added.`);let r=s.gesture,i=globalThis.navigator?.userActivation;if(!_t(r)||!Number.isInteger(r.id)||r.id<=0||j.has(r.id)||!Number.isFinite(r.age)||r.age<0||r.age>lW||i&&!i.isActive||globalThis.document.activeElement!==B.current)throw Error(`Add files from a click or key press in this screen.`);j.add(r.id);let a={picker:bW(n)};T=a,a.picker.then(t=>{if(!e||T!==a)throw Error(`This Block closed before the files were added.`);if(!t.length)return{added:0};if(!ut.current?.canEdit)throw Error(`You can view this project but not add files to it.`);return ne.current.onAddFiles(n.name,t,n.port)}).then(e=>t({added:Number.isInteger(e?.added)&&e.added>=0?e.added:0}),e=>t({error:String(e?.message||`The files could not be added.`).slice(0,1e3)})).finally(()=>{T===a&&(T=null)})}catch(e){t({error:String(e.message).slice(0,1e3)})}return}if(s.op===`change-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=k)return;k=Number(s.id);let e=e=>ge({op:`change-files-result`,id:s.id,...e});try{let t=vW(L?.manifest,s.port);if(!t.multiple)throw Error(`${JSON.stringify(t.name)} holds one file. Only a list input's files are removed or moved.`);if(!ut.current?.canEdit)throw Error(`You can view this project but not change its files.`);if(ot.locked.includes(t.name))throw Error(`This input comes from an earlier Step, so its files cannot be changed here.`);if($e())throw Error(`Only a person changes files. Chat cannot remove or move them.`);if(typeof ne.current.onChangeFiles!=`function`)throw Error(`Changing files is unavailable here.`);if(O)throw Error(`Files are already being changed.`);let n=s.gesture,r=globalThis.navigator?.userActivation;if(!_t(n)||!Number.isInteger(n.id)||n.id<=0||j.has(n.id)||!Number.isFinite(n.age)||n.age<0||n.age>lW||r&&!r.isActive||globalThis.document.activeElement!==B.current)throw Error(`Remove or move files from a click or key press in this screen.`);let i=_t(s.edit)&&s.edit.op===`remove`?{op:`remove`,index:s.edit.index}:_t(s.edit)&&s.edit.op===`move`?{op:`move`,from:s.edit.from,to:s.edit.to}:null;if(!i)throw Error(`Remove or move one file.`);let a=re.current.value?.[t.name];if(yW(a,i),mt(SW(s.item??null))!==mt(a[i.op===`move`?i.from:i.index]))throw Error(`These files changed. Look at them again, then try again.`);j.add(n.id),O=!0,Promise.resolve().then(()=>ne.current.onChangeFiles(t.name,i,t.port)).then(t=>e({files:Number.isInteger(t?.files)&&t.files>=0?t.files:0}),t=>e({error:String(t?.message||`The files could not be changed.`).slice(0,1e3)})).finally(()=>{O=!1})}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`use-output`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let e=e=>ge({op:`use-output-result`,id:s.id,...e});try{if($e())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(oe&&!ut.current?.canEdit)throw Error(`This workspace is read only.`);let t=SW(s.outputs),n=ne.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);DW(t,re.current.value,y),Promise.resolve(n(t)).then(t=>{let n=SW(t);fn(n),e({outputs:n})},t=>e({error:String(t?.message||`The media output could not be saved`).slice(0,1e3)}))}catch(t){e({error:String(t.message).slice(0,1e3)})}return}if(s.op===`code`){if(!oe||typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>ge({op:`code-result`,id:s.id,...e});if(++ie>OH.codeFiles*4){t({error:`This interface asked for its code files too many times.`});return}Promise.resolve().then(()=>yi(()=>Promise.resolve().then(()=>(sW(),nW)),void 0)).then(({loadViewCode:e})=>e(I.files,s.path,{guard:ot.codeGuard})).then(n=>{e&&t({source:n})},n=>{e&&t({error:String(n?.message||`This code file could not be loaded.`).slice(0,1e3)})});return}if(s.op===`allow-spending`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>ge({op:`allow-spending-result`,id:s.id,...e}),n=_t(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=lW&&!h.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===B.current&&Date.now()-g>lW,r=ne.current.onAllowSpending;if(!n){t({error:`Ask from a click or key press in this screen.`});return}if(typeof r!=`function`){t({error:`Spending approvals are for Steps in a project.`});return}if(!Number.isSafeInteger(s.credits)||s.credits<1||s.credits>xH.allowanceCredits||typeof s.label!=`string`||!s.label.trim()||s.label.length>120){t({error:`Name the total in whole credits and what it is for.`});return}h.add(s.gesture.id),Promise.resolve().then(()=>r({credits:s.credits,label:s.label.trim()})).then(n=>{e&&t({allowed:Number.isSafeInteger(n)&&n>0,credits:Number.isSafeInteger(n)?n:0})},n=>{e&&t({error:String(n?.message||`The approval did not open.`).slice(0,1e3)})});return}if(s.op===`preview-voice`){if(typeof s.id!=`string`||!/^[0-9]{1,9}$/.test(s.id))return;let t=e=>ge({op:`preview-voice-result`,id:s.id,...e}),n=Date.now();if(f=f.filter(e=>n-e<6e4),f.length>=xH.voicePreviewsPerMinute){t({error:`Voice sample limit reached. Wait a minute before trying again.`});return}f.push(n);let r=ne.current.onPreviewVoice;if(typeof r!=`function`||!(L?.manifest?.permissions?.capabilities||[]).includes(`audio.speech`)){t({error:`Voice samples are for Blocks that make speech (audio.speech).`});return}if(typeof s.voice!=`string`||!/^[a-z0-9_-]{1,64}$/.test(s.voice)){t({error:`Name a StillMade voice.`});return}Promise.resolve().then(()=>r(s.voice)).then(n=>{if(e){if(!(n instanceof Blob)||!/^audio\//.test(n.type))throw Error(`The voice sample could not be loaded.`);t({blob:n})}},n=>{e&&t({error:String(n?.message||`The voice sample could not be loaded.`).slice(0,1e3)})});return}if(s.op===`preview-image`||s.op===`preview-media`){let t=s.op===`preview-media`;if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=l)return;Vt(null),l=Number(s.id);let n=e=>ge({op:t?`preview-media-result`:`preview-image-result`,id:s.id,...e}),r=Date.now();if(d=d.filter(e=>r-e<6e4),o&&en(),d.length>=xH.imagePreviewsPerMinute){++m<=3&&n({error:`Image preview limit reached. Wait a minute before trying again.`}),m===4&&(Yt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,en(),i?.abort(),B.current&&(B.current.src=`about:blank`));return}d.push(r);let c=t||s.edge===void 0?void 0:s.edge;if(c!==void 0&&!(Number.isInteger(c)&&c>=64&&c<=xH.imagePreviewMaxEdge)){n({error:`Ask for an image preview edge from 64 to ${xH.imagePreviewMaxEdge} pixels.`});return}let u;try{if(u=t?SW(s.value):OW(s.value),t&&(!_t(u)||![`image`,`video`,`audio`].includes(u.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof u[e]==`string`&&u[e].length>0&&u[e].length<=32768)))throw Error(`Keep the complete picture, audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let f=t&&y?.authorizesMedia?.(u)?(e,t)=>Kn(e,t):t?ne.current.onPreviewMedia:ne.current.onPreviewImage;if(typeof f!=`function`){n({error:t?`Audio/video preview is unavailable in this workspace.`:`Image preview is unavailable in this workspace. Choose an image with the host controls.`});return}let p=new AbortController,h=Ct.current,g={controller:p,id:s.id,media:t};o=g;let _=wt.current,v=a,b=At(),x=()=>{if(p.signal.aborted||b!==At()||_!==wt.current||Object.keys(h).some(e=>h[e]!==Ct.current[e]))throw Error(`Image preview input or workspace changed.`)},S=setTimeout(()=>{e&&o===g&&en(`Image preview timed out. Try a smaller image.`)},xH.imagePreviewMs);p.signal.addEventListener(`abort`,()=>clearTimeout(S),{once:!0}),Promise.resolve().then(()=>(x(),f(u,{signal:p.signal,...c?{edge:c}:{}}))).then(r=>{if(e&&!p.signal.aborted&&o===g){if(x(),t&&r?.kind!==u.kind)throw Error(`The host returned a different media kind.`);let e=t?Wn(r):kW(r,c);x(),typeof u.assetId==`string`&&u.assetId.length<=512&&typeof u.versionId==`string`&&u.versionId.length<=512&&Vt({actor:v,runtimeActor:b,identity:_,session:ot.session,authority:h,evidence:{assetId:u.assetId,versionId:u.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:e.url.startsWith(`data:image/jpeg`)?`image/jpeg`:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!p.signal.aborted&&o===g&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!p.signal.aborted&&o===g&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(S),o===g&&(o=null)});return}if(s.op!==`run`||typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=c)return;c=Number(s.id);let v=e=>ge({op:`result`,id:s.id,...e});if(oe&&!ut.current?.canEdit){v({error:`Shared editing is unavailable or read only.`});return}let C=Date.now();if(u=u.filter(e=>C-e<6e4),i||u.length>=xH.runsPerMinute){++p<=3&&v({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),p===4&&(Yt(`Preview paused after too many requests. Reset it to continue.`),e=!1,en(),i?.abort(),B.current&&(B.current.src=`about:blank`));return}let w;try{if(!_t(s.input))throw Error(`Expected input values`);w=SW(s.input)}catch(e){v({error:e.message});return}u.push(C),ae(``);let N=new AbortController;i=N,ze.current=!0,Pe?.context.signal?.addEventListener(`abort`,()=>N.abort(),{once:!0});let F=setTimeout(()=>{e&&i===N&&(N.abort(),i=null,v({error:z?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},z?te:15e3);N.signal.addEventListener(`abort`,()=>clearTimeout(F),{once:!0});let ee=Pe?.op===`dispatch-view-control`?Pe:null,R=ee?async e=>{if(Pe!==ee||i!==N||N.signal.aborted||!_t(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||mt(e.taskFence)!==mt(ee.context.taskFence)||mt([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==Ye||mt(SW(e.beforeInput))!==ee.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=mt(SW(e.input));for(let e=0;e<25&&re.current.signature!==t;e++)if(Xe(ee.context,t),await new Promise(e=>setTimeout(e,10)),Pe!==ee||i!==N||N.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Xe(ee.context,t),re.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);ee.inputIdentity=t}:void 0,le=_t(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=lW&&!h.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===B.current&&Date.now()-g>lW&&Date.now()-_>lW;le&&(h.add(s.gesture.id),_=Date.now()),Promise.resolve().then(()=>ne.current.onRun(w,{...$e(),signal:N.signal,userActivated:le,...R?{onInputCommitted:R}:{},...L?.manifest?.desktopTools?.length?{nativeDesktopSession:y}:{}})).then(t=>{if(e&&!N.signal.aborted){if(!_t(t))throw Error(`Block execution must return named outputs`);let e=SW(t);fn(e),v({outputs:e})}},t=>{e&&!N.signal.aborted&&v({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!N.signal.aborted&&v({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(F),i===N&&(i=null),ze.current=!1,setTimeout(()=>{e&&!ze.current&&He()},250)})};return window.addEventListener(`message`,pn),()=>{T?.picker.cancel(),globalThis.document.removeEventListener(`fullscreenchange`,le),ce&&globalThis.document.fullscreenElement===ce&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),ce=null,V.current=null,be(null,null),Ne?.();for(let e of[...xe.values()])e(null);Be&&=(clearTimeout(Be.timer),Be.context.signal?.removeEventListener(`abort`,Be.abort),Be.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,v,!0),globalThis.document.removeEventListener(`keydown`,v,!0),Mt.current=null,Qe(Error(`The declared interface was closed.`)),Nt.current=null,It?.(),Rt?.(),clearTimeout(Tt),un(),sn&&=(clearTimeout(sn.timer),sn.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout($t),clearInterval(N),R?.disconnect(),ge({op:`dispose`}),e=!1,y.close(),ue.current===y&&(ue.current=null),de.current===me&&(de.current=null),en(),i?.abort(),ze.current=!1,window.removeEventListener(`message`,pn),window.removeEventListener(`stillmade:cursor-preferences`,Ut),window.removeEventListener(`storage`,Ut),window.removeEventListener(QH.control,Jt),qt(),yt.current=null,St.current=null,vt.current=null}},[ot,Ze,z,te,A,r,a,We,Ge]),(0,v.useEffect)(()=>{St.current?.()},[t]),(0,v.useEffect)(()=>{vt.current?.(),n?.canEdit===!1&&Promise.resolve(ue.current?.close()).catch(()=>{})},[n,Ze]),(0,v.useEffect)(()=>{yt.current?.()},[i,r,a,n]),(0,v.useEffect)(()=>{xt.current?.()},[M,Ne]);let Ht=!!globalThis.stillmadeDesktop?.blockDesktop,Ut=fe?.camera&&fe?.microphone?`camera and microphone`:fe?.camera?`camera`:`microphone`;return(0,H.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[fe?.kind===`live`&&fe.awaitingStart&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:`Ready to share your ${Ut} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:fe.start,children:`Start ${Ut}`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.current?.close(),children:`Cancel`})]}),fe?.kind===`live`&&fe.active&&(0,H.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,H.jsx)(`strong`,{children:`${Ut[0].toUpperCase()}${Ut.slice(1)} on`}),(0,H.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:fe.stop,children:`Turn off ${Ut}`})]}),fe?.awaitingStart&&(fe.kind===`folder`||fe.kind===`folder-access`)&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:fe.kind===`folder`?`This Block asks for a folder to ${fe.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${fe.folder} again for this Block.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:fe.start,children:fe.kind===`folder`?`Choose folder`:`Allow`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>fe.cancel?fe.cancel():ue.current?.close(),children:`Cancel`})]}),fe?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(fe.kind)&&(0,H.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,H.jsx)(`p`,{children:fe.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:fe.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:fe.microphone?`Ready to record your screen with your microphone. Choose your screen or window after pressing Start.`:`Ready to record. Choose your screen or window after pressing Start.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:fe.start,children:fe.kind===`camera`?`Start camera recording`:fe.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.current?.close(),children:`Cancel`})]}),fe?.active&&fe.kind!==`live`&&(0,H.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,H.jsxs)(`strong`,{children:[fe.ended?`Recording stopped`:`Recording`,` `,fe.kind||`media`]}),(0,H.jsxs)(`span`,{children:[` · `,fe.ended?fe.message:Ht?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.current?.close(),children:Ht?`Cancel recording and revoke access`:`Discard recording`})]}),Ht&&fe?.closed&&L?.manifest?.permissions?.desktop?.length>0&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:!Ze||!ut.current?.canEdit,onClick:()=>de.current?.(),children:`Reopen desktop access`}),Ht&&!fe?.closed&&!fe?.active&&L?.manifest?.permissions?.desktop?.length>0&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.current?.close(),children:`Revoke this Block’s desktop access`}),ot.loading?(0,H.jsx)(gr,{label:`Loading the interface…`}):ot.error?(0,H.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,ot.error]}):Ze?(0,H.jsxs)(H.Fragment,{children:[oe&&!ie&&(0,H.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,H.jsx)(`iframe`,{ref:B,onLoad:()=>{ft.current.session!==ot.session&&(ft.current={session:ot.session,count:0}),++ft.current.count>2&&pt.current?.()},title:O,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${x(`/block-ui-sandbox.html`)}#${ot.session}`,style:{width:`100%`,height:A&&ge||k,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...ie&&!qe?{display:`none`}:{}}},ot.session),(0,H.jsx)(`span`,{ref:gt,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}})]}):(0,H.jsx)(`p`,{role:Ye?.error?`alert`:`status`,children:Ye?.error||`Checking Block safety…`}),ke?.count>0&&(ke.error?(0,H.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:ke.error}):ke.dirty||ke.pending?(0,H.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),je?.count>0&&(je.error||je.dirty||je.pending)?(0,H.jsxs)(`div`,{className:`bs-notice`,role:je.error?`alert`:`status`,children:[(0,H.jsx)(`p`,{children:je.error||`Saving shared text…`}),je.error&&(0,H.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),je.retryable&&(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:je.pending>0||!ut.current?.canEdit,onClick:()=>B.current?.contentWindow?.postMessage({channel:cW,session:ot.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(ie||Ye?.error)&&(0,H.jsxs)(H.Fragment,{children:[ie&&!qe&&(0,H.jsx)(`p`,{role:`alert`,children:ie}),(0,H.jsx)(`button`,{type:`button`,className:`btn`,disabled:Ke,onClick:()=>{Ke||le(e=>e+1)},children:`Reload`})]}),(0,H.jsx)(MW,{activity:me,declaresFolders:(L?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:ue})]})}lt();var PW=50,FW=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var IW=e=>e==null?``:typeof e==`number`?FW.format(e):String(e);function LW(e,t){let n=URL.createObjectURL(e),r=document.createElement(`a`);r.href=n,r.download=t,document.body.append(r),r.click(),r.remove(),setTimeout(()=>URL.revokeObjectURL(n),1e4)}function RW({value:e,label:t=`Table`}){let[n,r]=(0,v.useState)(0);if(!Je(e))return(0,H.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/PW)),a=Math.min(n,i-1),o=e.rows.slice(a*PW,a*PW+PW),s=e.columns.map(t=>e.rows.length>0&&e.rows.every(e=>e[t]===void 0||e[t]===null||typeof e[t]==`number`));return(0,H.jsxs)(`div`,{className:`bd-table`,children:[(0,H.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,H.jsxs)(`table`,{children:[(0,H.jsx)(`thead`,{children:(0,H.jsx)(`tr`,{children:e.columns.map(e=>(0,H.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,H.jsx)(`tbody`,{children:o.map((t,n)=>(0,H.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,H.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:IW(t[e])},e))},a*PW+n))})]})}),(0,H.jsxs)(`div`,{className:`bd-bar`,children:[(0,H.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>LW(new Blob([Qe(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}wt(),lt();var zW=new Set([`image`,`audio`,`video`]),BW=e=>zW.has(e?.kind)&&typeof e.url==`string`,VW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,HW=e=>{let t=String(e).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();return t.charAt(0).toUpperCase()+t.slice(1)},UW=50,WW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),GW=e=>{if(!_t(e))return e;let t=WW(e);return t.length===1&&(Array.isArray(e[t[0]])||_t(e[t[0]]))?GW(e[t[0]]):e},KW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),qW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``),JW=e=>{let t=t=>/^start/i.test(t)?e.find(e=>/^end/i.test(e)&&e.slice(3).toLowerCase()===t.slice(5).toLowerCase()):void 0,n=new Set(e.map(t).filter(Boolean));return e.filter(e=>!n.has(e)).flatMap(e=>t(e)?[e,t(e)]:[e])};function YW(e){if(e.length<2||!e.every(e=>_t(e)&&WW(e).every(t=>KW(e[t]))))return null;let t=JW([...new Set(e.flatMap(WW))]);if(!t.length||t.length>6)return null;let n={columns:t.map(HW),rows:e.map(e=>Object.fromEntries(WW(e).map(t=>[HW(t),typeof e[t]==`boolean`?qW(e[t]):e[t]])))};return Je(n)?n:null}function XW({value:e,renderMedia:t,depth:n=0}){let r=GW(e);if(KW(r))return(0,H.jsx)(`span`,{children:qW(r)});if(BW(r))return t?.(r)??null;if(Je(r))return(0,H.jsx)(RW,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,H.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(BW)&&YW(r);return e?(0,H.jsx)(RW,{value:e,label:`Results`}):n>=3?(0,H.jsx)(`span`,{children:VW(r.length,`item`)}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,UW).map((e,r)=>(0,H.jsx)(`li`,{children:(0,H.jsx)(XW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>UW&&(0,H.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-UW,` more.`]})]})}if(!_t(r))return null;let i=WW(r);return i.length?n>=3?(0,H.jsx)(`span`,{children:VW(i.length,`detail`)}):(0,H.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,H.jsxs)(v.Fragment,{children:[(0,H.jsx)(`dt`,{children:HW(e)}),(0,H.jsx)(`dd`,{children:(0,H.jsx)(XW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,H.jsx)(`span`,{className:`sm-data-none`,children:`None`})}var ZW=[`M3 8V5a2 2 0 0 1 2-2h3M16 3h3a2 2 0 0 1 2 2v3M21 16v3a2 2 0 0 1-2 2h-3M8 21H5a2 2 0 0 1-2-2v-3`,`M6.5 12s2.2-3.8 5.5-3.8 5.5 3.8 5.5 3.8-2.2 3.8-5.5 3.8S6.5 12 6.5 12Z`],QW={cx:12,cy:12,r:1.8},$W=[`M10.3 17.5H4.5a2 2 0 0 1-2-2v-10a2 2 0 0 1 2-2h13a2 2 0 0 1 2 2v7.7`,`M2.5 7h17M6 5.25h10`,`M6 9.5h4a1 1 0 0 1 1 1v3a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1v-3a1 1 0 0 1 1-1Z`,`M5.3 14.2l2.2-2.4 1.6 1.5 1.1-1M13.5 10h3.5M13.5 12.3h2`,`M12 18s2-3.2 5.5-3.2S23 18 23 18s-2 3.2-5.5 3.2S12 18 12 18Z`],eG={cx:17.5,cy:18,r:1.3};function tG(e){switch(e){case`minus`:return(0,H.jsx)(`path`,{d:`M5 12h14`});case`messageCircle`:return(0,H.jsx)(`path`,{d:`M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8z`});case`arrowLeft`:return(0,H.jsx)(`path`,{d:`M20 12H4M11 5l-7 7 7 7`});case`link`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 .5l3-3a5 5 0 0 0-7-7l-2 2`}),(0,H.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7-.5l-3 3a5 5 0 0 0 7 7l2-2`})]});case`unlink`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`m18.8 12.3 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7`}),(0,H.jsx)(`path`,{d:`m5.2 11.7-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7`}),(0,H.jsx)(`path`,{d:`M8 2v3M2 8h3M16 19v3M19 16h3`})]});case`copy`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`9`,y:`9`,width:`12`,height:`12`,rx:`2`}),(0,H.jsx)(`path`,{d:`M15 9V5a2 2 0 0 0-2-2H5a2 2 0 0 0-2 2v8a2 2 0 0 0 2 2h4`})]});case`arrowUp`:return(0,H.jsx)(`path`,{d:`M12 20V4M5 11l7-7 7 7`});case`star`:return(0,H.jsx)(`path`,{d:`M12 3.5l2.6 5.3 5.9.9-4.25 4.15 1 5.85L12 16.95 6.75 19.7l1-5.85L3.5 9.7l5.9-.9z`});case`arrowUpRight`:return(0,H.jsx)(`path`,{d:`M7 17 17 7M8 7h9v9`});case`arrowDown`:return(0,H.jsx)(`path`,{d:`M12 4v16M5 13l7 7 7-7`});case`thumbsUp`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M7 10v11H3V10Z`}),(0,H.jsx)(`path`,{d:`M7 18c2 0 3 3 7 3h2.5a2 2 0 0 0 1.9-1.4l2.4-7A2 2 0 0 0 18.9 10H14l.7-3.5A3 3 0 0 0 11.8 3L7 10Z`})]});case`thumbsDown`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M7 14V3H3v11Z`}),(0,H.jsx)(`path`,{d:`M7 6c2 0 3-3 7-3h2.5a2 2 0 0 1 1.9 1.4l2.4 7a2 2 0 0 1-1.9 2.6H14l.7 3.5a3 3 0 0 1-2.9 3.5L7 14Z`})]});case`undo`:return(0,H.jsx)(`path`,{d:`M3 10h11a7 7 0 0 1 0 14M3 10l5-5M3 10l5 5`,transform:`translate(0 -3)`});case`redo`:return(0,H.jsx)(`path`,{d:`M21 7H10a7 7 0 0 0 0 14M21 7l-5-5M21 7l-5 5`});case`remix`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M5 5h5a5 5 0 0 1 5 5v9`}),(0,H.jsx)(`path`,{d:`m11 15 4 4 4-4`}),(0,H.jsx)(`path`,{d:`M5 19h2`}),(0,H.jsx)(`circle`,{cx:`5`,cy:`5`,r:`2`}),(0,H.jsx)(`circle`,{cx:`5`,cy:`19`,r:`2`})]});case`more`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,H.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]});case`palette`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`13.5`,cy:`6.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`17`,cy:`11`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`8.5`,cy:`7.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`circle`,{cx:`6.5`,cy:`12.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`path`,{d:`M12 3a9 9 0 0 0 0 18c1 0 1.6-.8 1.6-1.6 0-.5-.2-.8-.4-1.1-.3-.3-.4-.6-.4-1.1A1.6 1.6 0 0 1 14.3 15h1.9A4.8 4.8 0 0 0 21 10.2C21 6 16.9 3 12 3Z`})]});case`lock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 8 0v4`})]});case`unlock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 7.9-1`})]});case`pushpin`:return(0,H.jsxs)(`g`,{transform:`rotate(35 12 12)`,children:[(0,H.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`}),(0,H.jsx)(`path`,{d:`M12 14v7`})]});case`pushpinFilled`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`M12 14v7`})]});case`pin`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 21s7-5.7 7-11a7 7 0 0 0-14 0c0 5.3 7 11 7 11Z`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`10`,r:`2.5`})]});case`user`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,H.jsx)(`path`,{d:`M5 21a7 7 0 0 1 14 0`})]});case`image`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,H.jsx)(`path`,{d:`m21 15-5-5L5 21`})]});case`imageOff`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M2 2l20 20`}),(0,H.jsx)(`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`}),(0,H.jsx)(`path`,{d:`M13.5 13.5 6 21`}),(0,H.jsx)(`path`,{d:`m18 12 3 3`}),(0,H.jsx)(`path`,{d:`M3.59 3.59A1.99 1.99 0 0 0 3 5v14a2 2 0 0 0 2 2h14c.55 0 1.052-.22 1.41-.59`}),(0,H.jsx)(`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`})]});case`film`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4`})]});case`folder`:return(0,H.jsx)(`path`,{d:`M3 7a2 2 0 0 1 2-2h4l2 2h8a2 2 0 0 1 2 2v8a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2Z`});case`list`:return(0,H.jsx)(`path`,{d:`M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01`});case`grid`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1.5`}),(0,H.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1.5`})]});case`zap`:return(0,H.jsx)(`path`,{d:`M13 2 4 14h7l-1 8 9-12h-7Z`});case`plug`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 22v-5M9 8V2M15 8V2`}),(0,H.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});case`book`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,H.jsx)(`path`,{d:`M6.5 2H20v20H6.5A2.5 2.5 0 0 1 4 19.5v-15A2.5 2.5 0 0 1 6.5 2Z`})]});case`bookOpen`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 7v14`}),(0,H.jsx)(`path`,{d:`M3 5v14h6a3 3 0 0 1 3 3 3 3 0 0 1 3-3h6V5h-6a3 3 0 0 0-3 3 3 3 0 0 0-3-3Z`})]});case`input`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`}),(0,H.jsx)(`path`,{d:`m10 17 5-5-5-5`}),(0,H.jsx)(`path`,{d:`M15 12H3`})]});case`upload`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 16V4M7 9l5-5 5 5`}),(0,H.jsx)(`path`,{d:`M5 20h14`})]});case`download`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 4v12M7 11l5 5 5-5`}),(0,H.jsx)(`path`,{d:`M5 20h14`})]});case`save`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M5 3h11l3 3v15H5Z`}),(0,H.jsx)(`path`,{d:`M8 3v5h7M8 21v-7h8v7`})]});case`search`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,H.jsx)(`path`,{d:`m20 20-3.5-3.5`})]});case`magnet`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M6 4h4v8a2 2 0 0 0 4 0V4h4v8a6 6 0 0 1-12 0Z`}),(0,H.jsx)(`path`,{d:`M6 8h4M14 8h4`})]});case`bot`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`4`,y:`8`,width:`16`,height:`11`,rx:`2`}),(0,H.jsx)(`path`,{d:`M12 8V4M9 13h.01M15 13h.01M9 16h6`})]});case`note`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`4`,y:`3`,width:`16`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 8h8M8 12h8M8 16h5`})]});case`clock`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`path`,{d:`M12 7v5l3 2`})]});case`calendar`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`5`,width:`18`,height:`16`,rx:`2`}),(0,H.jsx)(`path`,{d:`M16 3v4M8 3v4M3 10h18`})]});case`hourglass`:return(0,H.jsx)(`path`,{d:`M6 3h12M6 21h12M7 3c0 5 5 6 5 9s-5 4-5 9M17 3c0 5-5 6-5 9s5 4 5 9`});case`edit`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 20h9`}),(0,H.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`music`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M9 18V5l12-2v13`}),(0,H.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,H.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]});case`mic`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`}),(0,H.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,H.jsx)(`path`,{d:`M12 19v3`})]});case`target`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]});case`pointer`:return(0,H.jsx)(`path`,{d:`M4.5 3.5 20 10.4l-6.5 1.9a1.9 1.9 0 0 0-1.3 1.3L10.3 20z`,strokeLinejoin:`round`});case`sprout`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M12 21V9`}),(0,H.jsx)(`path`,{d:`M12 9C9 9 6 7 6 4c3 0 6 2 6 5ZM12 12c3 0 6-2 6-5-3 0-6 2-6 5Z`})]});case`hand`:return(0,H.jsx)(`path`,{d:`M8 13V5a1.5 1.5 0 0 1 3 0v6M11 11V4a1.5 1.5 0 0 1 3 0v7M14 11V6a1.5 1.5 0 0 1 3 0v8a6 6 0 0 1-6 6h-1a6 6 0 0 1-5.2-3l-2-3.5a1.5 1.5 0 0 1 2.6-1.5L8 14`});case`scissors`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,H.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.5`}),(0,H.jsx)(`path`,{d:`M8 8l12 8M8 16 20 8`})]});case`maximize`:return(0,H.jsx)(`path`,{d:`M8 3H5a2 2 0 0 0-2 2v3M16 3h3a2 2 0 0 1 2 2v3M21 16v3a2 2 0 0 1-2 2h-3M3 16v3a2 2 0 0 0 2 2h3`});case`settings`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,H.jsx)(`path`,{d:`M19.4 15a1.6 1.6 0 0 0 .3 1.8 2 2 0 1 1-2.8 2.8 1.6 1.6 0 0 0-1.8-.3 1.6 1.6 0 0 0-1 1.5 2 2 0 1 1-4 0 1.6 1.6 0 0 0-1-1.5 1.6 1.6 0 0 0-1.8.3 2 2 0 1 1-2.8-2.8 1.6 1.6 0 0 0 .3-1.8 1.6 1.6 0 0 0-1.5-1 2 2 0 1 1 0-4 1.6 1.6 0 0 0 1.5-1 1.6 1.6 0 0 0-.3-1.8 2 2 0 1 1 2.8-2.8 1.6 1.6 0 0 0 1.8.3H9a1.6 1.6 0 0 0 1-1.5 2 2 0 1 1 4 0 1.6 1.6 0 0 0 1 1.5 1.6 1.6 0 0 0 1.8-.3 2 2 0 1 1 2.8 2.8 1.6 1.6 0 0 0-.3 1.8V9a1.6 1.6 0 0 0 1.5 1 2 2 0 1 1 0 4 1.6 1.6 0 0 0-1.5 1Z`})]});case`scale`:return(0,H.jsx)(`path`,{d:`M12 3v18M7 21h10M6 7h12M6 7 3 14h6ZM18 7l-3 7h6ZM3 14a3 3 0 0 0 6 0M15 14a3 3 0 0 0 6 0`});case`checkbox`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,H.jsx)(`path`,{d:`m8 12 3 3 5-6`})]});case`warning`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M10.3 4 2.6 17a2 2 0 0 0 1.7 3h15.4a2 2 0 0 0 1.7-3L13.7 4a2 2 0 0 0-3.4 0Z`}),(0,H.jsx)(`path`,{d:`M12 9v4M12 17h.01`})]});case`sparkle`:return(0,H.jsx)(`path`,{d:`M12 3l1.8 5.2L19 10l-5.2 1.8L12 17l-1.8-5.2L5 10l5.2-1.8Z`});case`check`:return(0,H.jsx)(`path`,{d:`m5 12 5 5 9-10`});case`x`:return(0,H.jsx)(`path`,{d:`M6 6 18 18M18 6 6 18`});case`plus`:return(0,H.jsx)(`path`,{d:`M12 5v14M5 12h14`});case`refresh`:return(0,H.jsx)(`path`,{d:`M3 12a9 9 0 0 1 15-6.7L21 8M21 3v5h-5M21 12a9 9 0 0 1-15 6.7L3 16M3 21v-5h5`});case`play`:return(0,H.jsx)(`path`,{d:`M7 4v16l13-8Z`});case`preview`:return(0,H.jsxs)(H.Fragment,{children:[ZW.map(e=>(0,H.jsx)(`path`,{d:e},e)),(0,H.jsx)(`circle`,{...QW})]});case`listingPreview`:return(0,H.jsxs)(H.Fragment,{children:[$W.map(e=>(0,H.jsx)(`path`,{d:e},e)),(0,H.jsx)(`circle`,{...eG})]});case`pause`:return(0,H.jsx)(`path`,{d:`M9 5v14M15 5v14`});case`playFilled`:return(0,H.jsx)(`path`,{d:`M7 4.6v14.8c0 .8.9 1.2 1.5.8l11.4-7.4a1 1 0 0 0 0-1.6L8.5 3.8C7.9 3.4 7 3.8 7 4.6Z`,fill:`currentColor`,stroke:`none`});case`pauseFilled`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`}),(0,H.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`})]});case`volume2`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14`})]});case`volumeX`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,H.jsx)(`path`,{d:`m22 9-6 6M16 9l6 6`})]});case`minimize`:return(0,H.jsx)(`path`,{d:`M8 3v3a2 2 0 0 1-2 2H3M21 8h-3a2 2 0 0 1-2-2V3M3 16h3a2 2 0 0 1 2 2v3M16 21v-3a2 2 0 0 1 2-2h3`});case`stop`:return(0,H.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`});case`chevronRight`:return(0,H.jsx)(`path`,{d:`m9 6 6 6-6 6`});case`chevronLeft`:return(0,H.jsx)(`path`,{d:`m15 6-6 6 6 6`});case`chevronDown`:return(0,H.jsx)(`path`,{d:`m6 9 6 6 6-6`});case`trash`:return(0,H.jsx)(`path`,{d:`M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M6 7l1 13a2 2 0 0 0 2 2h6a2 2 0 0 0 2-2l1-13`});case`layers`:return(0,H.jsx)(`path`,{d:`m12 3 9 5-9 5-9-5Zm9 9-9 5-9-5m18 4-9 5-9-5`});case`type`:return(0,H.jsx)(`path`,{d:`M4 6V4h16v2M12 4v16M9 20h6`});case`home`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M3 10.5 12 3l9 7.5`}),(0,H.jsx)(`path`,{d:`M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5`}),(0,H.jsx)(`path`,{d:`M9 21v-6h6v6`})]});case`menu`:return(0,H.jsx)(`path`,{d:`M4 6h16M4 12h16M4 18h16`});case`logout`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,H.jsx)(`path`,{d:`M16 17l5-5-5-5`}),(0,H.jsx)(`path`,{d:`M21 12H9`})]});case`help`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,H.jsx)(`path`,{d:`M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3`}),(0,H.jsx)(`path`,{d:`M12 17h.01`})]});case`bug`:return(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`path`,{d:`m8 2 1.9 1.9M14.1 3.9 16 2`}),(0,H.jsx)(`path`,{d:`M9 7.1v-1a3 3 0 1 1 6 0v1`}),(0,H.jsx)(`path`,{d:`M12 20c-3.3 0-6-2.7-6-6v-3a4 4 0 0 1 4-4h4a4 4 0 0 1 4 4v3c0 3.3-2.7 6-6 6`}),(0,H.jsx)(`path`,{d:`M12 20v-9`}),(0,H.jsx)(`path`,{d:`M6.5 9C4.6 8.8 3 7.1 3 5M6 13H2M3 21c0-2.1 1.7-3.9 3.8-4M21 5c0 2.1-1.6 3.8-3.5 4M22 13h-4M17.2 17c2.1.1 3.8 1.9 3.8 4`})]});default:return null}}function nG({name:e,size:t=`1em`,style:n,className:r,strokeWidth:i=1.5}){let a=tG(e);return a?(0,H.jsx)(`svg`,{viewBox:`0 0 24 24`,width:t,height:t,fill:`none`,stroke:`currentColor`,strokeWidth:i,strokeLinecap:`round`,strokeLinejoin:`round`,className:r,style:{display:`inline-block`,verticalAlign:`-0.14em`,flexShrink:0,...n||{}},"aria-hidden":`true`,children:a}):null}function rG(e,t){let n=(0,v.useRef)(t),r=_U(e),[i,a]=(0,v.useState)(null);return n.current=t,(0,v.useEffect)(()=>{if(!r)return;let t=!0;return Promise.resolve().then(()=>n.current?.(e)).then(n=>{t&&a({src:e,url:n||null})},()=>{t&&a({src:e,url:null})}),()=>{t=!1}},[e,r]),r?i?.src===e?{url:i.url,missing:!i.url}:{url:null,missing:!1}:{url:e||null,missing:!1}}function iG({src:e,resolveUrl:t,label:n,"aria-label":r,fill:i=!1,className:a,style:o,onMissing:s,controls:c,playsInline:l,preload:u=`metadata`,...d}){let{url:f,missing:p}=rG(e,t),m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=(0,v.useRef)(null),_=(0,v.useRef)(s);return _.current=s,(0,v.useEffect)(()=>{if(p){_.current?.(e);return}let t=yU(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,H.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,H.jsx)(nG,{name:`imageOff`,size:24})}):(0,H.jsxs)(`div`,{ref:m,className:a?`sm-player ${a}`:`sm-player`,style:o,"data-mode":`dark`,"data-fill":i?``:void 0,tabIndex:0,role:`group`,"aria-label":n||r||`Video`,children:[(0,H.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,H.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var aG=e=>String(e).padStart(2,`0`),oG=/^(\d{4})-(\d{2})-(\d{2})$/,sG=/^([01]\d|2[0-3]):([0-5]\d)$/,cG=e=>{let t=oG.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},lG=e=>{let t=cG(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},uG=e=>{let{year:t,month:n,day:r}=cG(e);return new Date(Date.UTC(t,n-1,r))},dG=(e,t)=>{let n=uG(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},fG=(e,t)=>{let{year:n,month:r,day:i}=cG(e),a=new Date(Date.UTC(n,r-1+t,1)),o=new Date(Date.UTC(a.getUTCFullYear(),a.getUTCMonth()+1,0)).getUTCDate();return`${a.getUTCFullYear()}-${aG(a.getUTCMonth()+1)}-${aG(Math.min(i,o))}`},pG=/(?:time|when|start|schedule|post|send|publish|remind)/i,mG=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||pG.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),hG=e=>`${_G(e.slice(0,10))}${e[10]===`T`?` · ${vG(e.slice(11,16))}`:``}`;function gG({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${aG(t.getMonth()+1)}-${aG(t.getDate())}`}function _G(e,t=gG()){return uG(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function vG(e){let[t,n]=e.split(`:`).map(Number);return new Date(Date.UTC(2e3,0,1,t,n)).toLocaleTimeString(void 0,{hour:`numeric`,minute:`2-digit`,timeZone:`UTC`})}function yG(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${aG(Math.floor(n*e/60))}:${aG(n*e%60)}`)}function bG(e,t,n,r){return(0,v.useEffect)(()=>{if(!e)return;let r=e=>{n.current?.contains(e.target)||t(!1)};return document.addEventListener(`pointerdown`,r),()=>document.removeEventListener(`pointerdown`,r)},[e]),n=>{n.key===`Escape`&&e&&(n.stopPropagation(),n.preventDefault(),t(!1),r.current?.focus())}}function xG({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Day`,placeholder:s=`Pick a day`,clearable:c=!1}){let[l,u]=(0,v.useState)(!1),[d,f]=(0,v.useState)(null),p=(0,v.useRef)(null),m=(0,v.useRef)(null),h=(0,v.useRef)(null),g=bG(l,u,p,m),_=gG({utc:i}),y=lG(e)?e:null,b=e=>(!n||e>=n)&&(!r||e<=r),x=e=>n&&e<n?n:r&&e>r?r:e;(0,v.useEffect)(()=>{l&&d&&h.current?.querySelector(`[data-day="${d}"]`)?.focus()},[l,d]);let S=()=>{if(l){u(!1);return}f(x(y||_)),u(!0)},C=e=>{b(e)&&(t?.(e),u(!1),m.current?.focus())},w={ArrowLeft:-1,ArrowRight:1,ArrowUp:-7,ArrowDown:7},T=e=>{let t=null;if(w[e.key])t=dG(d,w[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=fG(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=uG(d).getUTCDay();t=dG(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(x(t)))},E=d||y||_,{year:D,month:O}=cG(E),k=`${D}-${aG(O)}-01`,A=new Date(Date.UTC(D,O,0)).getUTCDate(),j=uG(k).getUTCDay(),M=uG(k).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),N=dG(k,-1),P=fG(k,1),F=Array.from({length:A},(e,t)=>`${D}-${aG(O)}-${aG(t+1)}`);return(0,H.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,H.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${y?_G(y,_):`not chosen`}`,disabled:a,onClick:S,children:[(0,H.jsx)(nG,{name:`calendar`,size:16}),(0,H.jsx)(`span`,{children:y?_G(y,_):s}),(0,H.jsx)(nG,{name:`chevronDown`,size:13})]}),l&&(0,H.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,H.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,H.jsx)(`b`,{children:M}),(0,H.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,H.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&N<n,onClick:()=>f(x(fG(E,-1))),children:(0,H.jsx)(nG,{name:`chevronLeft`,size:16})}),(0,H.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&P>r,onClick:()=>f(x(fG(E,1))),children:(0,H.jsx)(nG,{name:`chevronRight`,size:16})})]})]}),(0,H.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:T,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,H.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),j>0&&(0,H.jsx)(`span`,{style:{gridColumn:`span ${j}`},"aria-hidden":`true`}),F.map(e=>(0,H.jsx)(`button`,{type:`button`,"data-day":e,tabIndex:e===d?0:-1,disabled:!b(e),"aria-pressed":e===y,"aria-current":e===_?`date`:void 0,"aria-label":uG(e).toLocaleDateString(void 0,{weekday:`long`,month:`long`,day:`numeric`,year:`numeric`,timeZone:`UTC`}),onClick:()=>C(e),children:Number(e.slice(8))},e))]}),c&&y&&(0,H.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function SG({value:e,onChange:t,min:n,step:r=30,disabled:i=!1,label:a=`Time`,placeholder:o=`Pick a time`}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(-1),d=(0,v.useRef)(null),f=(0,v.useRef)(null),p=(0,v.useRef)(null),m=(0,v.useId)(),h=bG(s,c,d,f),g=sG.test(e||``)?e:null,_=g&&!yG(r).includes(g)?[...yG(r),g].sort():yG(r),y=e=>!n||e>=n;(0,v.useEffect)(()=>{s&&(p.current?.focus(),p.current?.querySelector(`[data-active="true"]`)?.scrollIntoView?.({block:`nearest`}))},[s,l]);let b=()=>{if(s){c(!1);return}let e=_.indexOf(g);u(e>=0?e:Math.max(0,_.findIndex(y))),c(!0)},x=e=>{y(e)&&(t?.(e),c(!1),f.current?.focus())};return(0,H.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,H.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?vG(g):`not chosen`}`,disabled:i,onClick:b,children:[(0,H.jsx)(nG,{name:`clock`,size:16}),(0,H.jsx)(`span`,{children:g?vG(g):o}),(0,H.jsx)(nG,{name:`chevronDown`,size:13})]}),s&&(0,H.jsx)(`ul`,{className:`sm-when-pop sm-when-times`,role:`listbox`,ref:p,tabIndex:-1,"aria-label":`Pick a ${a.toLowerCase()}`,"aria-activedescendant":l>=0?`${m}-${l}`:void 0,onKeyDown:e=>{let t=t=>{let n=t,r=e.key===`ArrowUp`||e.key===`End`?-1:1;for(;n>=0&&n<_.length&&!y(_[n]);)n+=r;return n>=0&&n<_.length?n:l};if(e.key===`ArrowDown`)u(t(l+1));else if(e.key===`ArrowUp`)u(t(l-1));else if(e.key===`Home`)u(t(0));else if(e.key===`End`)u(t(_.length-1));else if(e.key===`Enter`||e.key===` `)_[l]&&x(_[l]);else return;e.preventDefault()},children:_.map((e,t)=>(0,H.jsx)(`li`,{id:`${m}-${t}`,role:`option`,"aria-selected":e===g,"aria-disabled":!y(e)||void 0,"data-active":t===l||void 0,onPointerDown:e=>e.preventDefault(),onClick:()=>x(e),children:vG(e)},e))})]})}function CG({value:e,onChange:t,min:n,max:r,utc:i=!1,disabled:a=!1,label:o=`Date`,clearable:s=!1,defaultTime:c=`09:00`,step:l=30}){let u=lG(e?.slice(0,10))?e.slice(0,10):``,d=sG.test(e?.slice(11,16)||``)?e.slice(11,16):``,f=n?.slice(0,10)||void 0,p=f?n.slice(11,16):``,m=e=>e===f&&p?yG(l).find(e=>e>=p)||p:null;return(0,H.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,H.jsx)(xG,{value:u,onChange:e=>{if(!e){t?.(``);return}let n=m(e),r=d||c;n&&r<n&&(r=n),t?.(`${e}T${r}`)},min:f,max:r?.slice(0,10),utc:i,disabled:a,label:`${o} day`,clearable:s}),(0,H.jsx)(SG,{value:d,onChange:e=>t?.(`${u||f||gG({utc:i})}T${e}`),min:(u||f||gG({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}wt();var wG=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),TG=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),EG=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),DG=(e,{aspectRatios:t,resolutions:n=[],qualities:r=[],references:i=0,seed:a=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),qualities:Object.freeze(r),references:i,seed:a}),OG=(e,{aspectRatios:t=[],resolutions:n=[],durations:r,firstFrame:i=!0,lastFrame:a=!1,requiresFirstFrame:o=!1,seed:s=!1,nativeAudio:c=!1})=>Object.freeze({label:e,aspectRatios:Object.freeze(t),resolutions:Object.freeze(n),durations:Object.freeze(r),firstFrame:i,lastFrame:a,requiresFirstFrame:o,seed:s,nativeAudio:c});Object.freeze({"nano-banana-2":DG(`Nano Banana 2`,{aspectRatios:wG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":DG(`Nano Banana 2 Lite`,{aspectRatios:wG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":DG(`Nano Banana Pro`,{aspectRatios:wG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":DG(`GPT Image 2`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.5-flare":DG(`GPT Image 2.5 Flare`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.5-sunburst":DG(`GPT Image 2.5 Sunburst`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.6-flare":DG(`GPT Image 2.6 Flare`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-2.6-sunburst":DG(`GPT Image 2.6 Sunburst`,{aspectRatios:[`auto`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`1K`,`2K`,`4K`],qualities:[`low`,`medium`,`high`],references:8}),"gpt-image-1.5":DG(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":DG(`Kling Image V3`,{aspectRatios:[`21:9`,`16:9`,`9:16`,`1:1`,`4:3`,`3:4`,`3:2`,`2:3`],resolutions:[`1K`,`2K`]}),"seedream-v4.5":DG(`Seedream 4.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`2K`,`4K`],seed:!0})}),Object.freeze({"seedance-2.0":OG(`Seedance 2.0`,{aspectRatios:TG,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:EG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":OG(`Seedance 2.0 Fast`,{aspectRatios:TG,resolutions:[`480p`,`720p`],durations:EG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":OG(`Seedance 2.0 Mini`,{aspectRatios:TG,resolutions:[`480p`,`720p`],durations:EG,lastFrame:!0,seed:!0,nativeAudio:!0}),"kling-v3-turbo":OG(`Kling 3.0 Turbo`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[5,10]}),"wan-2.6-flash":OG(`Wan 2.6 Flash`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[3,4,5],requiresFirstFrame:!0}),"veo-3.1-lite":OG(`Veo 3.1 Lite`,{aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[4,6,8],lastFrame:!0,nativeAudio:!0}),"vidu-q3-turbo":OG(`Vidu Q3 Turbo`,{durations:[1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16],lastFrame:!0,nativeAudio:!0}),"wan-2.7":OG(`Wan 2.7`,{resolutions:[`720p`,`1080p`],durations:[2,3,4,5,6,7,8,9,10,11,12,13,14,15],lastFrame:!0,requiresFirstFrame:!0,seed:!0})}),Object.freeze([`model`,`aspectRatio`,`resolution`,`quality`]),Object.freeze([`model`,`duration`,`resolution`,`aspectRatio`,`generateAudio`]),Object.freeze({references:8,negativePrompt:2e3,seed:2147483647}),Object.freeze([`wan-2.6-flash`,`veo-3.1-lite`,`seedance-2.0-mini`,`kling-v3-turbo`,`seedance-2.0-fast`,`seedance-2.0`]),Object.freeze({speech:Object.freeze({text:3800,defaultVoice:`asteria`,speed:Object.freeze({min:.25,max:4,default:1})}),music:Object.freeze({min:5,max:240,default:30}),sfx:Object.freeze({min:.5,max:22,default:4})});var kG=2399/11e4,AG=Object.freeze({video:3,build:3,media:4.5,other:3,chat:2}),jG=(e,t)=>Math.max(0,Number(e)||0)*AG[t]/kG,MG=(e,t)=>Math.max(1,Math.ceil(jG(e,t)-1e-9)),NG=`2026-11-05`,PG=`carried`;Object.freeze({"veo-3.1-lite":{usd:.05,resolution:{"720p":1,"1080p":1.6},provider:`Atlas`,checked:NG,source:`Atlas catalog list price $0.05/s; 1080p at $0.08/s, Google's Veo 3.1 Lite step`},"vidu-q3-turbo":{usd:.04,provider:`Atlas`,checked:NG,source:`Atlas catalog list price (we pay $0.034)`},"wan-2.6-flash":{usd:.025,provider:`Atlas`,checked:NG,source:`Atlas catalog list price (we pay $0.018)`},"wan-2.7":{usd:.17,provider:`Higgsfield, then Atlas`,checked:PG,source:`Atlas $0.10/s at 720p (checked); the 1.7x step to the 1080p we generate is carried from the old table`},"kling-v3-turbo":{usd:.112,provider:`Higgsfield, then Atlas`,checked:NG,source:`Atlas catalog list price (we pay $0.095); Higgsfield $0.056/s on promotion`},"seedance-2.0":{usd:.2,resolution:{"480p":1,"720p":1.3,"1080p":3.2,"4k":7.5},provider:`BytePlus Ark`,checked:PG,source:`Ark is priced per token and its price page does not load without an account; carried from the old table (verify against an Ark invoice)`},"seedance-2.0-fast":{usd:.09,resolution:{"480p":1,"720p":1.3},provider:`BytePlus Ark`,checked:PG,source:`carried from the old table (Atlas lists $0.09/s)`},"seedance-2.0-mini":{usd:.09,resolution:{"480p":1,"720p":1.3},provider:`BytePlus Ark`,checked:PG,source:`priced as Fast, carried from the old table (Atlas lists $0.056/s)`}}),Object.freeze({"seedance-2":`seedance-2.0`,"kling-3":`kling-v3-turbo`,"kling-v3-pro":`kling-v3-turbo`,"kling-v3-std":`kling-v3-turbo`,"kling-o3-std":`kling-v3-turbo`}),Object.freeze({"gpt-image-2":{quality:{low:{"1K":.006,"2K":.007,"4K":.012},medium:{"1K":.053,"2K":.056,"4K":.101},high:{"1K":.211,"2K":.222,"4K":.401}},referenceUsd:.02,provider:`OpenAI for square, fal then Atlas for other shapes`,checked:NG,source:`fal gpt-image-2 price table (dearest size in each class); OpenAI direct is $30 per million output tokens`},"gpt-image-2.5-flare":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-06`,source:`fal openai/gpt-image-2.5/flare price table; OpenAI rate card $30 per million output tokens`},"gpt-image-2.5-sunburst":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-06`,source:`fal openai/gpt-image-2.5/sunburst price table; OpenAI rate card $30 per million output tokens`},"gpt-image-2.6-flare":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-07`,source:`OpenAI and fal gpt-image-2.6 token rates ($30 per million output tokens); per-image price taken from 2.5 until published`},"gpt-image-2.6-sunburst":{quality:{low:{"1K":.00588,"2K":.00615,"4K":.01113},medium:{"1K":.01317,"2K":.01434,"4K":.02595},high:{"1K":.05268,"2K":.05529,"4K":.10008}},referenceUsd:.02,provider:`OpenAI for square, fal for other shapes`,checked:`2026-11-07`,source:`OpenAI and fal gpt-image-2.6 token rates ($30 per million output tokens); per-image price taken from 2.5 until published`},"gpt-image-1.5":{quality:{low:{"1K":.013},medium:{"1K":.051},high:{"1K":.2}},provider:`fal`,checked:NG,source:`fal price for a non-square image`},"nano-banana-2":{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:NG,source:`fal: $0.08 at 1K, 1.5x at 2K, 2x at 4K`},"nano-banana-2-lite":{usd:.048,provider:`fal`,checked:NG,source:`fal: $37.50 per million output tokens, one 1K image (about 1,290 tokens)`},"nano-banana-pro":{usd:.15,resolution:{"1K":1,"2K":1,"4K":2},provider:`fal`,checked:NG,source:`fal: $0.15, 4K at double`},"kling-image-v3":{usd:.028,provider:`fal`,checked:NG,source:`fal: $0.028 per image`},"seedream-v4.5":{usd:.04,provider:`fal`,checked:NG,source:`fal: $0.04 per image`},"flux-step":{usd:.02,provider:`fal`,checked:PG,source:`carried from the old table`},flux:{usd:.04,provider:`fal`,checked:PG,source:`carried from the old table`},ideogram:{usd:.08,provider:`fal`,checked:PG,source:`carried from the old table`},gemini:{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:NG,source:`served as Nano Banana 2`}}),Object.freeze({deepgram:{usdPer1kChars:.03,checked:NG,source:`Deepgram Aura-2 pay as you go`},openai:{usdPer1kChars:.015,checked:NG,source:`OpenAI tts-1, $15 per million characters`},elevenlabs:{usdPer1kChars:.04,checked:NG,source:`ElevenLabs API, Flash / Turbo`},kokoro:{usdPer1kChars:.02,checked:NG,source:`fal Kokoro`}}),Object.freeze({usdPerSecond:2e-4,checked:NG,source:`fal ACE-Step, per second of audio`}),Object.freeze({usdPerSecond:.002,checked:NG,source:`fal ElevenLabs sound effects v2, per second`});var FG=Object.freeze({"openai/gpt-5-mini":{input:.25,output:2},"google/gemini-2.5-flash":{input:.3,output:2.5},"anthropic/claude-haiku-5.5":{input:.1,output:.5},"anthropic/claude-sonnet-4":{input:3,output:15},"anthropic/claude-sonnet-4.5":{input:3,output:15},"anthropic/claude-sonnet-5.5":{input:2,output:10},"openai/gpt-5.4":{input:2.5,output:15},"google/gemini-2.5-pro":{input:1.25,output:10},"x-ai/grok-4.5":{input:2,output:6},"x-ai/grok-4.20":{input:1.25,output:2.5},"anthropic/claude-opus-4.1":{input:15,output:75},"anthropic/claude-opus-4.5":{input:5,output:25},"anthropic/claude-opus-4.8":{input:5,output:25},"openai/gpt-5.5":{input:5,output:30}}),IG=(e,t,n)=>{let r=FG[e];return r?(t*r.input+n*r.output)/1e6:null},LG=Object.freeze({input:2e3,output:1e3}),RG=Object.freeze({input:1e4,output:4096});function zG(e){let t=IG(e,LG.input,LG.output),n=IG(e,RG.input,RG.output);return t===null?null:Math.max(MG(t,`media`),Math.ceil(n/kG-1e-9))}var BG=(e,t,n,r,i={})=>Object.freeze({usd:e,tier:t,unit:n,source:r,checked:i.checked||PG,...i});Object.freeze({"media:analyze":BG(.02,`media`,`call`,`the vision provider caps a call at $0.02 (VISION_MAX_INITIAL_COST)`,{checked:NG}),"media:check":BG(.005,`media`,`call`,`four photos at most, $0.00125 each (MEDIA_CHECK_IMAGE_USD)`,{checked:NG}),"research:search":BG(.008,`media`,`search`,`Tavily basic search`,{checked:NG}),"research:summarize":BG(.01,`media`,`call`,`one Gemini Flash read of fetched pages`,{estimate:!0}),"transcribe:timestamp":BG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:upload":BG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:captions":BG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"connection:action":BG(.012,`other`,`action`,`a premium Composio tool call at the overage rate`,{checked:NG}),"automation:app-event":BG(.003,`other`,`event`,`Composio, per trigger event`,{checked:NG}),"automation:app-check":BG(3e-4,`other`,`check`,`Composio, per tool call`,{checked:NG}),llm:BG(.01,`other`,`call`,`a Standard model call`,{estimate:!0}),vision:BG(.01,`other`,`image`,`one vision read`,{estimate:!0}),"narrative:compile":BG(.06,`other`,`script`,`about ten Gemini Flash calls`,{estimate:!0}),"narrative:compile-research":BG(.1,`other`,`script`,`the compile plus three Tavily searches and a dossier`,{estimate:!0}),"narrative:learn-voice":BG(.01,`other`,`call`,`one extraction call`,{estimate:!0}),"roughcut:base":BG(.05,`other`,`run`,`segmentation and matching`,{estimate:!0}),"roughcut:per-min":BG(.015,`other`,`footage minute`,`Gemini Flash frame reads`,{estimate:!0}),"finaledit:base":BG(.06,`other`,`run`,`polish decisions`,{estimate:!0}),"finaledit:per-min":BG(.02,`other`,`video minute`,`Gemini Flash scan`,{estimate:!0}),"aomotion:base":BG(.06,`other`,`run`,`motion graphics pass`,{estimate:!0}),"aomotion:per-min":BG(.02,`other`,`video minute`,`motion graphics pass`,{estimate:!0}),"aomotion:base:opus":BG(.12,`other`,`run`,`motion graphics pass on Opus`,{estimate:!0}),"aomotion:per-min:opus":BG(.04,`other`,`video minute`,`motion graphics pass on Opus`,{estimate:!0}),motiongraphic:BG(.015,`other`,`graphic`,`one small call`,{estimate:!0}),"transcript:parse":BG(.005,`other`,`1,000 characters`,`Gemini Flash word timing`,{estimate:!0}),"vibe-edit":BG(.02,`other`,`turn`,`Flash region scan and decision`,{estimate:!0}),"canvas:context-connect":BG(.01,`other`,`run`,`one canvas read`,{estimate:!0}),"anim2:plan":BG(.03,`other`,`video`,`shot planning`,{estimate:!0}),"anim2:vibe":BG(.03,`other`,`turn`,`scene vibe turn`,{estimate:!0}),"anim2:qa":BG(.03,`other`,`frame`,`vision QA`,{estimate:!0}),"anim2:trigger":BG(.01,`other`,`scene`,`one Haiku call`,{estimate:!0}),"gif:plan":BG(.03,`other`,`pass`,`GIF planning`,{estimate:!0}),"canvas:plan":BG(.03,`other`,`pass`,`collage planning`,{estimate:!0}),"canvasChat:build":BG(.03,`other`,`build`,`canvas chat orchestration`,{estimate:!0}),"strip:plan":BG(.05,`other`,`pass`,`strip planning`,{estimate:!0}),"panel:qa":BG(.03,`other`,`pass`,`style-consistency vision pass`,{estimate:!0})}),Object.freeze({standard:.4,balanced:.85,reasoning:.5,premium:1.4}),Object.freeze({build:.1,chat:.005,other:.05}),Object.freeze(Object.fromEntries([`openai/gpt-5-mini`,`google/gemini-2.5-flash`,`anthropic/claude-sonnet-4`,`anthropic/claude-sonnet-4.5`,`openai/gpt-5.4`,`google/gemini-2.5-pro`,`x-ai/grok-4.5`,`x-ai/grok-4.20`,`anthropic/claude-opus-4.1`,`anthropic/claude-opus-4.5`,`anthropic/claude-opus-4.8`,`openai/gpt-5.5`].map(e=>[e,zG(e)])))[`anthropic/claude-sonnet-4.5`],wt();var VG=Object.freeze({googlesheets:`Google Sheets`,googledrive:`Google Drive`,googledocs:`Google Docs`,googlecalendar:`Google Calendar`,gmail:`Gmail`,youtube:`YouTube`,tiktok:`TikTok`,linkedin:`LinkedIn`,hubspot:`HubSpot`,github:`GitHub`,whatsapp:`WhatsApp`,"meta-ads":`Meta Ads`}),HG=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,UG=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),WG=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),GG=[[`send`,new Set([`send`,`reply`,`message`,`notify`,`email`,`forward`,`dm`,`invite`])],[`add`,new Set([`add`,`append`,`insert`,`create`,`new`,`log`,`save`,`record`,`upsert`,`write`,`import`,`book`,`schedule`])],[`update`,new Set([`update`,`edit`,`change`,`modify`,`patch`,`set`,`rename`,`move`,`replace`,`mark`])],[`remove`,new Set([`delete`,`remove`,`archive`,`trash`,`cancel`,`unsubscribe`])],[`upload`,new Set([`upload`])]],KG={post:[`Post to`,`Posting to`],send:[`Send to`,`Sending to`],add:[`Add to`,`Adding to`],update:[`Update in`,`Updating in`],remove:[`Remove from`,`Removing from`],upload:[`Upload to`,`Uploading to`],read:[`Get from`,`Getting from`]},qG=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),JG=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function YG(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=qG(e);return VG[n]||(n?JG(n):`the app`)}function XG(e){let t=String(e?.manifest?.name||``).split(` · `).slice(1).join(` `),n=String(e?.capability?.capabilityId||``).split(`:`).at(-1),r=qG(e).replace(/[-_.]/g,``).toLowerCase(),i=e=>{let t=e.toLowerCase().replace(/[^a-z0-9]+/g,` `).trim().split(` `).filter(Boolean);return t.length>1&&t[0].replace(/[-_.]/g,``)===r&&t.shift(),t};for(let e of[i(t),i(n)]){let t=e.slice(0,3),n=t.find(e=>HG.test(e)||UG.has(e)||GG.some(([,t])=>t.has(e)));if(n&&HG.test(n))return`read`;if(e.some(e=>UG.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>WG.has(e)))return`post`;let r=n&&GG.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function ZG(e){let t=YG(e),n=XG(e),[r,i]=KG[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var QG=e=>ZG(e).verbs,$G=Object.freeze({"text.generate":[`Write`,`Writing…`],"image.generate":[`Generate image`,`Generating image…`],"video.generate":[`Generate video`,`Generating video…`],"video.render":[`Make video`,`Making video…`],"audio.speech":[`Generate voiceover`,`Generating voiceover…`],"audio.transcribe":[`Transcribe`,`Transcribing…`],"image.describe":[`Describe`,`Describing…`],"audio.music":[`Generate music`,`Generating music…`],"audio.sfx":[`Generate sound`,`Generating sound…`],"web.fetch":[`Read page`,`Reading…`],"web.research":[`Research`,`Researching…`],"media.analyze":[`Analyze`,`Analyzing…`],"timeline.propose":[`Suggest edit`,`Suggesting…`],"workspace.propose":[`Suggest changes`,`Suggesting…`],"connection.execute":[`Send`,`Sending…`]}),eK=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase(),tK=new Set([`output`,`outputs`,`result`,`results`,`value`,`data`,`out`]),nK=new Set(`add.analyze.animate.build.check.clean.compose.convert.count.create.cut.describe.design.edit.export.extract.find.generate.get.import.make.merge.mix.narrate.pick.plan.post.publish.read.record.remove.render.research.resize.review.schedule.send.split.summarize.transcribe.translate.trim.write`.split(`.`));function rK(e){let t=e?.manifest;if(!t)return null;let n=String(t.name||``).trim(),r=n.split(/\s+/)[0].toLowerCase();if(nK.has(r)&&n.includes(` `))return[n,`Working…`];let i=Object.entries(t.outputs||{}).filter(([,e])=>!e?.context),[a,o]=i.find(([,e])=>e?.primary)||i[0]||[],s=a&&!tK.has(eK(a))&&!/action/i.test(String(o?.type||``)),c=o?.label?eK(o.label):eK(s?a:n);return c?[`Make ${c}`,`Making ${c}…`]:null}function iK(e,t){let n=t?.manifest?.action,r=typeof n?.label==`string`?n.label.trim():``;return r?[r,n.running||$G[e]?.[1]||`Working…`]:e===`connection.execute`&&t?QG(t):$G[e]||rK(t)||[`Make the result`,`Making the result…`]}var aK=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function oK(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||iK(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${aK(t.credits)}`:r||t?.credits===0?`${s} · ${aK(0)}`:s}var sK=new Set([`image`,`image[]`,`video`,`video[]`,`audio`,`audio[]`,`asset`,`asset[]`,`file`]),cK=3,lK=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();function uK(e){let t=String(e||``).trim();if(!t)return``;let n=(t.match(/^.+?[.!?](?=\s|$)/)||[t])[0].trim();return n.length<=160?n:``}function dK(e,{inputs:t,labels:n={},groups:r=[]}={}){let i=t||Object.entries(e?.inputs||{}).filter(([,e])=>!e?.context),a=i.length>0&&i.length<=cK&&!r.length,o=i.find(([,e])=>e?.required!==!1&&e?.primary)||i.find(([,e])=>e?.required!==!1)||i[0],s=o?lK(n[o[0]]||o[1]?.label||o[0]):``;return{focused:a,heading:s?`Add your ${s}`:String(e?.action?.label||e?.name||``).trim(),line:uK(e?.description),media:!!o&&sK.has(o[1]?.type)}}var fK=new Set([`text`,`script`,`transcript`,`brief`,`json`,`metadata`,`research`,`document`,`table`]),pK=e=>{let t=String(e||``).replace(/\[\]$/,``);return fK.has(t)?`text`:[`video`,`image`,`audio`].includes(t)?t:void 0},mK=/^\s*(\d+(?:\.\d+)?)\s*[:/x]\s*(\d+(?:\.\d+)?)\s*$/;function hK(e,{inputs:t={},aspectRatio:n}={}){let r=Object.entries(e?.outputs||{}).filter(([,e])=>!e?.context),i=(r.find(([,e])=>e?.primary)||r[0]||[])[1],a=pK(i?.type);if(a!==`video`&&a!==`image`)return{kind:a};let o=Object.keys(e?.inputs||{}).find(e=>/aspect/i.test(e)),s=[o&&t[o],o&&e.inputs[o]?.default,n].find(e=>mK.test(String(e||``))),c=mK.exec(String(s||``));return{kind:a,ratio:c?`${c[1]}/${c[2]}`:a===`video`?`16/9`:`1/1`}}function gK({kind:e,ratio:t,words:n=`Your result shows up here`}){return(0,H.jsxs)(`div`,{className:`sm-result-place`,"data-kind":e||`other`,children:[e===`text`&&(0,H.jsxs)(`span`,{className:`sm-result-lines`,"aria-hidden":`true`,children:[(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{}),(0,H.jsx)(`i`,{})]}),(e===`video`||e===`image`)&&(0,H.jsx)(`span`,{className:`sm-result-frame`,style:{aspectRatio:t},"aria-hidden":`true`,children:(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":e})}),e===`audio`&&(0,H.jsxs)(`span`,{className:`sm-result-audio`,"aria-hidden":`true`,children:[(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`audio`}),(0,H.jsx)(`span`,{className:`sm-result-wave`,children:Array.from({length:24},(e,t)=>(0,H.jsx)(`i`,{},t))})]}),!e&&(0,H.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`spark`,"aria-hidden":`true`}),(0,H.jsx)(`p`,{children:n})]})}var _K=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),vK=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),yK=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),bK=e=>/^[aeiou]/i.test(e)?`an`:`a`;function xK(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=_K[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||vK.has(a)||a===i,s=XU(yK[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${bK(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${bK(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var SK=160,CK=/\blines\b|\b(?:per|each|every|own|by)\s+line\b|\bline\s+(?:per|for each)\b|\bparagraphs?\b|\bbullet(?:s|ed)?\b/i,wK=/\blists?\b/i,TK=/\bcomma/i;function EK(e,t,n){if(e?.type!==`text`)return!1;if(n?.multiline===!0||[t,e.default].some(e=>typeof e==`string`&&e.includes(`
|
|
1976
|
+
`)))return!0;let r=String(e.description||``);return CK.test(r)||wK.test(r)&&!TK.test(r)}function DK(e,t,n){if(e?.type!==`text`||EK(e,t,n)||t!=null&&(typeof t!=`string`||t.length>SK))return!1;let r=String(e.description||``),i=Number(/\bup to (\d+) characters\b/i.exec(r)?.[1]),a=Number.isSafeInteger(e.maxLength)?e.maxLength:i;return Number.isFinite(a)&&a>0&&a<=SK}var OK=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],kK=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],AK=new Set([`image`,`video`,`audio`,`file`]),jK={image:`image`,video:`film`,audio:`music`,file:`image`},MK=e=>{let t;try{t=JSON.parse(e)}catch{return String(e)}return Array.isArray(t)?t.map(e=>e?.message===`Unknown manifest field`?`This SDK does not know the Block’s “${e.path}” setting. Update the SDK, then restart the preview.`:`${e?.path?`${e.path}: `:``}${e?.message||`Something is wrong with the Block.`}`).join(` `):String(e)},NK={pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`},PK={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(NK).map(e=>`.${e}`).join(`,`)};async function FK(e,t){if(t===`image`){let t=await createImageBitmap(e),n={width:t.width,height:t.height};return t.close?.(),n}if(t!==`video`&&t!==`audio`)return{};let n=URL.createObjectURL(e),r=document.createElement(t);try{r.preload=`metadata`,r.src=n,await new Promise((e,t)=>{r.onloadedmetadata=e,r.onerror=()=>t(Error(`This file does not play in the browser.`)),setTimeout(e,8e3)});let e=Number.isFinite(r.duration)&&r.duration>0?Math.round(r.duration*1e3)/1e3:void 0;return t===`video`?{...r.videoWidth?{width:r.videoWidth,height:r.videoHeight}:{},...e?{duration:e}:{}}:e?{duration:e}:{}}finally{URL.revokeObjectURL(n)}}async function IK(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?NK[n]||e.type:e.type||`application/octet-stream`,i=await FK(e,t).catch(()=>({})),a=await fetch(`/__dev/files`,{method:`POST`,headers:{"Content-Type":r,"X-File-Name":encodeURIComponent(e.name)},body:e}),o=await a.json().catch(()=>({}));if(!a.ok||!o.url)throw Error(o.error||`The preview could not keep this file.`);return{kind:t,assetId:`picked-${o.url.split(`/`)[4]}`,versionId:`v1`,url:o.url,mimeType:r,bytes:e.size,name:e.name,...i}}async function LK(e,t,n,{pick:r=IK}={}){if(!t)throw Error(`This Block has no input named ${e}.`);let i=t.type.endsWith(`[]`),a=i?t.type.slice(0,-2):t.type,o=[];for(let e of i?n:n.slice(0,1))o.push(await r(e,a===`asset`?String(e.type).split(`/`)[0]:a));return{refs:o,apply:t=>({...t||{},[e]:i?[...Array.isArray(t?.[e])?t[e]:[],...o]:o[0]})}}function RK(e,t,n){for(let t of Object.keys(n||{}))if(!Object.hasOwn(e||{},t))throw Error(`Unknown input: ${t}`);return{...t||{},...n}}function zK({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=HW(e)}){let s=(0,v.useRef)(null),[c,l]=(0,v.useState)(!1),[u,d]=(0,v.useState)(``),[f,p]=(0,v.useState)(!1),m=async e=>{if(e){l(!0),d(``);try{a(await IK(e,t.type))}catch(e){d(e.message)}finally{l(!1)}}},h=e=>{let t=e.target.files?.[0];e.target.value=``,m(t)},g=xK(e,t),_=(0,H.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:PK[t.type],onChange:h});return r&&!n?(0,H.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,H.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,H.jsxs)(`div`,{className:`dh-media-drop`,"data-over":f||void 0,onDragOver:e=>{e.preventDefault(),f||p(!0)},onDragLeave:()=>p(!1),onDrop:e=>{e.preventDefault(),p(!1),!i&&!c&&m(e.dataTransfer.files?.[0])},children:[(0,H.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,H.jsx)(`span`,{children:t.description}),(0,H.jsx)(`small`,{children:g.formats}),(0,H.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,H.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,H.jsxs)(`div`,{className:`dh-media`,children:[(0,H.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,H.jsx)(nG,{name:n?jK[t.type]:`plus`,size:16}),(0,H.jsx)(`span`,{children:c?`Adding…`:VK(n)||g.choose})]}),_,u&&(0,H.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):n&&typeof n==`object`?(0,H.jsxs)(`span`,{className:`dh-media-tiles`,title:`The example from the Block's tests`,children:[(0,H.jsx)(BK,{item:n,title:o}),(0,H.jsx)(`small`,{className:`dh-media-note`,children:`Example`})]}):(0,H.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,H.jsx)(nG,{name:jK[t.type],size:16}),(0,H.jsx)(`span`,{children:`Add one in the example`}),(0,H.jsx)(`small`,{children:`Example`})]})]})}function BK({item:e,title:t}){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(!1),a=VK(e)||t;if(!(typeof e?.url==`string`&&e.url.startsWith(`/api/media/`))||![`image`,`video`,`audio`].includes(e.kind))return(0,H.jsxs)(`span`,{className:`dh-media-tile`,title:a,children:[(0,H.jsx)(nG,{name:jK[e?.kind]||`image`,size:16}),(0,H.jsx)(`span`,{children:a})]});if(e.kind===`image`)return(0,H.jsx)(`span`,{className:`dh-thumb`,title:a,children:(0,H.jsx)(`img`,{src:e.url,alt:a,loading:`lazy`,decoding:`async`})});let o=()=>{let e=n.current;e&&(e.paused?e.play()?.catch?.(()=>{}):e.pause())},s={onPlay:()=>i(!0),onPause:()=>i(!1),onEnded:()=>i(!1)},c=(0,H.jsx)(`button`,{type:`button`,className:`dh-thumb-play`,"aria-label":`${r?`Pause`:`Play`} ${a}`,onClick:o,children:(0,H.jsx)(nG,{name:r?`pauseFilled`:`playFilled`,size:14})});return e.kind===`video`?(0,H.jsxs)(`span`,{className:`dh-thumb`,title:a,"data-playing":r||void 0,children:[(0,H.jsx)(`video`,{ref:n,src:e.url,preload:`metadata`,muted:!0,playsInline:!0,...s}),c]}):(0,H.jsxs)(`span`,{className:`dh-media-tile dh-media-sound`,title:a,children:[c,(0,H.jsx)(nG,{name:`music`,size:16}),(0,H.jsx)(`span`,{children:a}),(0,H.jsx)(`audio`,{ref:n,src:e.url,preload:`none`,...s})]})}var VK=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},HK=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},UK=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function WK(e,t=``){return(await fetch(`/__dev/run${t}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function GK(e,{signal:t,edge:n}={}){if(typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`))throw Error(`The local preview shows stand-in media and files mapped in tests/mocks.json.`);let r=await fetch(e.url,{signal:t});if(!r.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let i=await createImageBitmap(await r.blob()),a=n??512,o=Math.min(1,a/Math.max(i.width,i.height)),s=document.createElement(`canvas`);s.width=Math.max(1,Math.round(i.width*o)),s.height=Math.max(1,Math.round(i.height*o));let c=s.getContext(`2d`);c.drawImage(i,0,0,s.width,s.height),i.close?.();let l=s.toDataURL(`image/png`);return l.length>3145728&&a>512&&c.getImageData(0,0,s.width,s.height).data.every((e,t)=>t%4!=3||e===255)&&(l=s.toDataURL(`image/jpeg`,.92)),{url:l,width:s.width,height:s.height}}function KK(e,{signal:t}={}){return typeof e?.url!=`string`||!e.url.startsWith(`/api/media/`)?Promise.reject(Error(`The local preview plays stand-in media and files mapped in tests/mocks.json.`)):Kn(e,{signal:t})}async function qK(e,{signal:t}={}){let n=await fetch(`/api/media/example/kitchen.wav`,{signal:t});if(!n.ok)throw Error(`The stand-in voice sample is not available.`);return new Blob([await n.arrayBuffer()],{type:`audio/wav`})}function JK({value:e}){let t=VK(e);if(!e.url.startsWith(`/api/media/`))return(0,H.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,H.jsx)(nG,{name:jK[e.kind],size:16}),(0,H.jsx)(`span`,{children:t||`Result`})]});let n=e.width>0&&e.height>0?`${e.width}/${e.height}`:null,r=n?{aspectRatio:n}:void 0;return(0,H.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,H.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,H.jsx)(iG,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,H.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,H.jsx)(`figcaption`,{children:t})]})}var YK=e=>(0,H.jsx)(JK,{value:e}),XK=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function ZK({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||HW(e),[c,l]=(0,v.useState)(o);(0,v.useEffect)(()=>{l(o)},[o]);let u=`dh-input-${e}`,d=t.description||void 0,f=n?.control===`select`&&Array.isArray(n.options)?n.options:null,p=f?(0,H.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,H.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,H.jsxs)(`span`,{className:`dh-slider`,children:[(0,H.jsx)(`input`,{id:u,type:`range`,min:t.min,max:t.max,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(Number(e.target.value)),onPointerUp:()=>i(Number(c)),onKeyUp:()=>i(Number(c)),onBlur:()=>i(Number(c))}),(0,H.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,H.jsx)(`input`,{id:u,type:`checkbox`,checked:!!c,disabled:a,onChange:e=>{l(e.target.checked),i(e.target.checked)}}):[`number`,`integer`].includes(t.type)?(0,H.jsx)(`input`,{id:u,type:`number`,step:t.type===`integer`?1:`any`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{if(c===``)return i(void 0);let e=Number(c);Number.isFinite(e)&&i(e)}}):[`text`,`string`].includes(t.type)?!n?.control&&DK(t,o,n)?(0,H.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):(0,H.jsx)(`textarea`,{id:u,className:`dh-text`,rows:Math.min(16,Math.max(3,String(c).split(`
|
|
1977
|
+
`).length)),value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,H.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:mG(e,s,typeof o==`string`?o:``)?(0,H.jsx)(CG,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,H.jsx)(xG,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):XK.has(t.type)?(0,H.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,H.jsx)(BK,{item:e,title:`${s} ${t+1}`},t)),!(Array.isArray(o)?o.length:o)&&(0,H.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,H.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,H.jsxs)(`div`,{className:`dh-row`,children:[(0,H.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function QK({value:e,onCommit:t,disabled:n}){let r=(0,v.useMemo)(()=>JSON.stringify(e,null,2),[e]),[i,a]=(0,v.useState)(r),[o,s]=(0,v.useState)(``);return(0,v.useEffect)(()=>{a(r),s(``)},[r]),(0,H.jsxs)(`div`,{className:`dh-input`,children:[(0,H.jsx)(`textarea`,{"aria-label":`Input JSON`,spellCheck:!1,rows:8,value:i,disabled:n,onChange:e=>a(e.target.value),onBlur:()=>{if(i!==r)try{let e=JSON.parse(i||`{}`);if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`The input is one JSON object, keyed by input port.`);s(``),t(e)}catch(e){s(e.message)}}}),o&&(0,H.jsx)(`p`,{role:`alert`,children:o})]})}var $K=(0,v.memo)(function({entries:e,onClear:t}){let n=(0,v.useRef)(null);return(0,v.useEffect)(()=>{let e=n.current;e&&(e.scrollTop=e.scrollHeight)},[e]),(0,H.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,H.jsx)(`ol`,{ref:n,children:e.map(e=>(0,H.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,H.jsx)(`time`,{children:e.time}),(0,H.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,H.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,H.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),eq={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},tq={full:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,H.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,H.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,H.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,H.jsx)(`path`,{d:`M12 2v2M12 20v2M4.9 4.9l1.4 1.4M17.7 17.7l1.4 1.4M2 12h2M20 12h2M4.9 19.1l1.4-1.4M17.7 6.3l1.4-1.4`})]}),dark:(0,H.jsx)(`path`,{d:`M20 14.5A8 8 0 1 1 9.5 4a6.5 6.5 0 0 0 10.5 10.5z`}),white:(0,H.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,H.jsx)(`path`,{d:`M9 3h6M10 3v6l-5 9a2 2 0 0 0 1.7 3h10.6a2 2 0 0 0 1.7-3l-5-9V3`}),done:(0,H.jsx)(`path`,{d:`M5 12.5l4.5 4.5L19 7`}),todo:(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8`,strokeDasharray:`3 3`}),problem:(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`circle`,{cx:`12`,cy:`12`,r:`8.5`}),(0,H.jsx)(`path`,{d:`M12 7.5v5.5M12 16.4v.1`})]}),focus:(0,H.jsx)(`path`,{d:`M4 9V4h5M15 4h5v5M20 15v5h-5M9 20H4v-5`}),unfocus:(0,H.jsx)(`path`,{d:`M9 4v5H4M20 9h-5V4M15 20v-5h5M4 15h5v5`})},nq=({name:e})=>(0,H.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:tq[e]});function rq(){let[e,t]=(0,v.useState)(()=>HK(`stillmade.dev.focus`,``)===`1`);(0,v.useEffect)(()=>{e?document.documentElement.dataset.focus=`true`:delete document.documentElement.dataset.focus,UK(`stillmade.dev.focus`,e?`1`:``)},[e]);let n=e?`Show the bars`:`Hide the bars`;return(0,H.jsx)(`button`,{type:`button`,className:`dh-focus-toggle`,"aria-pressed":e,"aria-label":n,title:n,onClick:()=>t(e=>!e),children:(0,H.jsx)(nq,{name:e?`unfocus`:`focus`})})}function iq(e,t){(0,v.useLayoutEffect)(()=>{let t=e.current,n=t?.closest(`.dh-main`);if(!t||!n)return;let r=0,i=()=>{r=0;let e=parseFloat(getComputedStyle(n).paddingTop)+parseFloat(getComputedStyle(n).paddingBottom),i=uU({width:t.parentElement.clientWidth,available:n.clientHeight-e,heightAt:e=>{t.style.zoom=e===1?``:String(e),t.style.flex=`none`,t.style.minHeight=`0`;let n=Math.ceil(t.getBoundingClientRect().height);return t.style.flex=``,t.style.minHeight=``,n},mode:`auto`});t.style.zoom=i===1?``:String(i)},a=()=>{r||=requestAnimationFrame(i)};i(),addEventListener(`resize`,a);let o=e=>{[`IMG`,`VIDEO`,`AUDIO`].includes(e.target?.tagName)&&a()};return t.addEventListener(`load`,o,!0),t.addEventListener(`loadedmetadata`,o,!0),()=>{cancelAnimationFrame(r),removeEventListener(`resize`,a),t.removeEventListener(`load`,o,!0),t.removeEventListener(`loadedmetadata`,o,!0),t.style.zoom=``}},t)}function aq({label:e,value:t,options:n,onChange:r}){return(0,H.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,H.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,H.jsx)(nq,{name:e})},e))})}var oq=140,sq=260,cq={"text.generate":`Write`,"image.generate":`Generate a picture`,"video.generate":`Generate a video`,"audio.speech":`Speak`,"audio.music":`Make music`,"audio.sfx":`Make a sound effect`,"audio.transcribe":`Transcribe`,"image.describe":`Describe a picture`,"media.analyze":`Look at the media`,"web.fetch":`Read a web page`,"web.research":`Research the web`,"timeline.render":`Render`,"audio.decode":`Decode audio`,"audio.extract":`Take out the audio`,"audio.normalize":`Even out the loudness`,"video.cut":`Cut the video`,"video.concat":`Join videos`,"video.resize":`Resize the video`,"image.thumbnail":`Take a still`,"image.compose":`Join pictures`,"document.text":`Read a document`,"files.read":`Read a file`,"files.write":`Save a file`,"net.fetch":`Call a web service`,"connections.call":`Use a connected app`,"actions.run":`Run an action`,"assets.create":`Add to the project`},lq=e=>cq[e.name]||cq[e.api]||e.name;function uq({on:e,label:t,onChange:n}){return(0,H.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,H.jsx)(`span`,{className:`dh-switch-track`,children:(0,H.jsx)(`span`,{className:`dh-switch-knob`})}),(0,H.jsx)(`span`,{children:t})]})}function dq({tabs:e,status:t,control:n,children:r,initial:i=null}){let[a,o]=(0,v.useState)(i),[s,c]=(0,v.useState)(()=>Number(HK(`stillmade.dev.dock`,``))||sq),l=(0,v.useRef)(null),u=e=>o(t=>t===e?null:e),d=e=>{a&&(l.current={y:e.clientY,height:s},e.currentTarget.setPointerCapture(e.pointerId))},f=e=>{let t=l.current;t&&c(Math.round(Math.max(oq,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},p=()=>{l.current&&(l.current=null,UK(`stillmade.dev.dock`,String(s)))},m=e.find(e=>e.key===a);return(0,H.jsxs)(`section`,{className:`dh-dock`,"data-open":m?`true`:`false`,style:m?{height:s}:void 0,"aria-label":`Run details`,children:[m&&(0,H.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:d,onPointerMove:f,onPointerUp:p,onPointerCancel:p}),(0,H.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,H.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":a===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>u(e.key),children:[e.label,e.alert&&(0,H.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,H.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,H.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":m?`Fold the panel`:`Open the panel`,title:m?`Fold the panel`:`Open the panel`,"aria-expanded":!!m,onClick:()=>o(t=>t?null:e[0].key),children:(0,H.jsx)(nG,{name:`chevronRight`,size:16})})]}),m&&(0,H.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${m.key}`,"aria-labelledby":`dh-tab-${m.key}`,children:r(m.key)})]})}function fq({item:e=null,extraTabs:t=[],badges:n=null,dockOpen:r=null}={}){let i=e?`?item=${encodeURIComponent(e)}`:``,[a,o]=(0,v.useState)({revision:0,content:null,problem:null,folder:``}),[s,c]=(0,v.useState)(0),[l,u]=(0,v.useState)(()=>HK(`stillmade.dev.theme`,`light`)),[d,f]=(0,v.useState)(()=>HK(`stillmade.dev.width`,`full`)),[p,m]=(0,v.useState)(0),[h,g]=(0,v.useState)(null),[_,y]=(0,v.useState)(null),[b,x]=(0,v.useState)(!1),[S,C]=(0,v.useState)(``),[w,T]=(0,v.useState)(null),[E,D]=(0,v.useState)(!1),[O,k]=(0,v.useState)({}),[A,j]=(0,v.useState)([]),[M,N]=(0,v.useState)({}),P=(0,v.useRef)({}),F=(0,v.useRef)(0),I=(0,v.useCallback)((e,t)=>j(n=>[...n.slice(-299),{id:++F.current,kind:e,label:eq[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),L=(0,v.useCallback)(async()=>{let e=await(await fetch(`/__dev/package${i}`,{cache:`no-store`})).json();return o(e),e},[i]);(0,v.useEffect)(()=>{let t=!0;L().then(e=>{t&&(g(t=>t??(e.content?.tests?.[0]?.input||{})),I(`reload`,`Previewing ${e.folder}`),e.problem&&I(`error`,MK(e.problem)))}).catch(e=>I(`error`,e.message));let n=new EventSource(`/__dev/events`);return n.addEventListener(`package`,async n=>{let r=JSON.parse(n.data);if(!(e&&r.item!==e))try{if(await L(),!t)return;c(e=>e+1),I(r.problem?`error`:`reload`,r.problem?`Reloaded with a problem: ${MK(r.problem)}`:`Reloaded after a change`)}catch(e){I(`error`,e.message)}}),n.addEventListener(`build`,t=>{let n=JSON.parse(t.data);e&&n.items&&!n.items.includes(e.slice(e.indexOf(`/`)+1))||(n.state===`running`?I(`build`,`Building: ${n.command||n.items.join(`, `)}`):n.state===`done`?I(`build`,`Build finished`):I(`error`,`Build failed${n.output?`\n${n.output}`:``}`))}),()=>{t=!1,n.close()}},[]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=l,UK(`stillmade.dev.theme`,l)},[l]),(0,v.useEffect)(()=>{UK(`stillmade.dev.width`,d)},[d]);let ee=a.content,R=ee?.manifest,z=ee?.tests||[],te=e=>{m(e),g(z[e]?.input||{})},B=(0,v.useCallback)(async(e,{signal:t}={})=>{I(`run`,`Run started`),x(!0),C(``);try{let n=await WK(e,i);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])I(`log`,e);for(let e of n.standIns||[])I(`stand-in`,`${e.api} ${e.name} (${e.source===`picked`?`your file`:e.source===`example`?`example file`:/mocks/.test(e.source)?`the Block's tests`:`recorded stand-in`})`);if(T({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw I(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return y(n.outputs),I(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(y(null),C(e?.message||`The run did not finish.`)),e}finally{x(!1)}},[I,i]),ne=(0,v.useCallback)(async e=>{let t=ar(P.current,e);P.current=t,N(t)},[]),re=()=>{P.current={},N({}),c(e=>e+1),I(`view`,`Shared state cleared`)},[ie,ae]=(0,v.useState)([]),oe=(0,v.useMemo)(()=>({state:M,outputs:{},made:ie,memory:null,canEdit:!0}),[M,ie]),se=(0,v.useCallback)(async e=>{y(e),I(`view`,`The view chose its outputs`)},[I]),ce=(0,v.useCallback)(async(e,t)=>{let n=a.content?.manifest?.inputs?.[e],{refs:r,apply:i}=await LK(e,n,t);return E&&AK.has(n.type)?k(t=>({...t,[e]:r[0]})):g(i),I(`view`,`Added ${r.length} ${r.length===1?`file`:`files`} to ${HW(e)}`),{added:r.length}},[a.content,E,I]),le=(0,v.useCallback)(async(e,t)=>{let n=yW(h?.[e],t);return g(t=>({...t,[e]:n})),I(`view`,`${t.op===`remove`?`Removed a file from`:`Moved a file in`} ${HW(e)}`),{files:n.length}},[h,I]),ue=(0,v.useCallback)(e=>I(`error`,String(e?.message||e)),[I]),de=(0,v.useMemo)(()=>{let e={...h||{}};if(E)for(let[t,n]of Object.entries(a.content?.manifest?.inputs||{}))AK.has(n.type)&&(O[t]?e[t]=O[t]:delete e[t]);return e},[h,E,O,a.content]),fe=(0,v.useCallback)(e=>g(t=>{if(!E)return e;let n={...e};for(let[e,r]of Object.entries(a.content?.manifest?.inputs||{}))AK.has(r.type)&&(t&&Object.hasOwn(t,e)?n[e]=t[e]:delete n[e]);return n}),[E,a.content]),pe=(0,v.useCallback)(async(e,t)=>{let n=RK(a.content?.manifest?.inputs,de,e);Object.keys(e).length&&fe({...h||{},...e});let r=await B(n,t),i=Object.values(r||{}).flatMap(e=>Array.isArray(e)?e:[e]).filter(e=>e&&[`image`,`video`,`audio`].includes(e.kind)&&typeof e.url==`string`&&typeof e.assetId==`string`).map(({kind:e,assetId:t,versionId:n,url:r})=>({kind:e,assetId:t,versionId:n,url:r}));return i.length&&ae(e=>[...i,...e.filter(e=>!i.some(t=>t.url===e.url))].slice(0,400)),r},[a.content,de,h,fe,B]),me=kK.find(([e])=>e===d)?.[2],he=ee?.capability?.operation?[ee.capability.operation]:(R?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),ge=b?iK(he.length===1?he[0]:void 0,ee)[1]:oK(he.length===1?he[0]:void 0,{credits:0},{connector:ee}),_e=(0,v.useMemo)(()=>dK(R,{labels:Object.fromEntries((R?.ui||[]).filter(e=>e?.label).map(e=>[e.port,e.label])),groups:R?.uiLayout?.groups||[]}),[R]),ve=(0,v.useRef)(null);iq(ve,[ee,d,_,S,b]);let ye=_?Object.entries(R?.outputs||{}).filter(([e])=>_[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof _[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(_[e])?(0,H.jsx)(`p`,{className:`dh-date`,children:(0,H.jsx)(`time`,{dateTime:_[e],children:hG(_[e])})},e):(0,H.jsx)(XW,{value:_[e],renderMedia:YK},e)):null,be=b?`Running…`:w?w.failed?`Last run failed`:`Ran in ${w.ms} ms${w.calls.length?` · ${w.calls.length} ${w.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,xe=[...t,{key:`activity`,label:`Activity`,alert:A.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${w?.calls.length?` · ${w.calls.length}`:``}`},...ee?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsxs)(`header`,{className:`dh-bar`,children:[(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:R?.name||`Block preview`}),R&&(0,H.jsx)(`span`,{className:`dh-meta`,children:R.version}),n]}),(0,H.jsx)(`span`,{className:`dh-spacer`}),z.length>1&&(0,H.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,H.jsx)(nq,{name:`example`}),(0,H.jsx)(`select`,{"aria-label":`Example`,value:p,onChange:e=>te(Number(e.target.value)),children:z.map((e,t)=>(0,H.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,H.jsx)(aq,{label:`Width`,value:d,options:kK,onChange:f}),(0,H.jsx)(aq,{label:`Appearance`,value:l,options:OK,onChange:u}),(0,H.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>c(e=>e+1),children:(0,H.jsx)(nG,{name:`refresh`,size:16})})]}),a.problem&&(0,H.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:MK(a.problem)}),(0,H.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,H.jsx)(`div`,{className:`dh-frame`,style:me?{maxWidth:me}:void 0,children:ee?ee.view?(0,H.jsx)(NW,{view:ee.view,policyContent:ee,input:de,sharedView:oe,onSharedChange:ne,onRun:pe,onUseOutput:se,onAddFiles:ce,onChangeFiles:le,onPreviewImage:GK,onPreviewMedia:KK,onPreviewVoice:qK,onAllowSpending:async({credits:e,label:t})=>(console.info(`StillMade would ask to approve up to ${e} credits for "${t}". The SDK preview spends none.`),e),onError:ue,actorId:`dev-preview`,title:`${R.name} preview`,height:560,fitContent:!0},s):(0,H.jsxs)(`div`,{className:_e.focused?`dh-noview dh-focus`:`dh-noview`,ref:ve,children:[_e.focused&&(0,H.jsxs)(`header`,{className:`dh-intro`,children:[(0,H.jsx)(`h2`,{children:_e.heading}),_e.line&&(0,H.jsx)(`p`,{children:_e.line})]}),(0,H.jsx)(`div`,{className:`dh-form`,children:Object.entries(R.inputs||{}).map(([e,t])=>AK.has(t.type)?(0,H.jsx)(zK,{name:e,port:t,title:(R.ui||[]).find(t=>t?.port===e)?.label||HW(e),value:de[e],own:E,disabled:b,onPick:t=>k(n=>({...n,[e]:t}))},e):(0,H.jsx)(ZK,{name:e,port:t,control:(R.ui||[]).find(t=>t?.port===e),value:de[e],disabled:b,onCommit:t=>g(n=>({...n,[e]:t}))},e))}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:b,onClick:()=>B(de).catch(()=>{}),children:ge}),S&&(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:S}),ye?(0,H.jsxs)(`div`,{className:`dh-results`,children:[(0,H.jsx)(`h2`,{children:`Result`}),ye]}):!S&&(0,H.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,H.jsx)(gK,{...hK(R,{inputs:de})})})]}):(0,H.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,H.jsx)(dq,{tabs:xe,status:be,initial:r,control:(0,H.jsx)(uq,{on:!E,label:`Example media`,onChange:e=>D(!e)}),children:e=>t.find(t=>t.key===e)?.render()??(e===`activity`?(0,H.jsx)($K,{entries:A,onClear:()=>j([])}):e===`calls`?w?.calls.length?(0,H.jsx)(`ol`,{className:`dh-calls`,children:w.calls.map((e,t)=>(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:lq(e)}),(0,H.jsx)(`span`,{children:e.name}),(0,H.jsx)(`small`,{children:e.source===`picked`?`read from your file`:e.source===`example`?`read from a StillMade example file`:/mocks/.test(e.source)?`answered from the Block's tests`:`answered by a recorded stand-in`})]},t))}):(0,H.jsx)(`p`,{className:`dh-muted`,children:w?`The last run made no hosted or media calls.`:`Run the Block to see the calls it makes and what answered each one.`}):e===`result`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:re,children:`Clear shared state`})]}),S&&(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:S}),ye||!S&&(0,H.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,H.jsxs)(H.Fragment,{children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:b||!ee,onClick:()=>B(de).catch(()=>{}),children:ge})]}),h&&(0,H.jsx)(QK,{value:de,onCommit:fe,disabled:!ee}),_&&(0,H.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(_,null,2)})]}))})]})}var pq={block:`layers`,connector:`plug`,automation:`clock`,workflow:`list`},mq={block:`Block`,connector:`Connector`,automation:`Automation`,workflow:`Project Type`},hq={module:`Module`,javascript:`JavaScript`,recipe:`Recipe`,capability:`Hosted`,comfyui:`ComfyUI`,desktop:`Desktop`,"browser-application":`Application`},gq={ready:`Gate passed`,"needs-fix":`Needs a fix`,unchecked:`Not checked since it changed`,building:`Being built`},_q=e=>e.kind===`workflow`?`workflow`:e.blockKind||`block`,vq=e=>e.kind===`workflow`?`${e.automation?`Automation`:`Project Type`} · ${e.steps} ${e.steps===1?`Step`:`Steps`}`:[_q(e)===`block`?hq[e.runtime]||`Block`:mq[_q(e)],e.version].filter(Boolean).join(` · `);function yq({status:e}){return(0,H.jsx)(`span`,{className:`ws-dot ws-dot-${e}`,role:`img`,"aria-label":gq[e]||e,title:gq[e]||e})}function bq({templates:e,onAdded:t,onCancel:n}){let[r,i]=(0,v.useState)(``),[a,o]=(0,v.useState)(`module`),[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)(``);return(0,H.jsxs)(`form`,{className:`ws-new`,onSubmit:async e=>{if(e.preventDefault(),r.trim()){c(!0),u(``);try{let e=await fetch(`/__dev/new`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({name:r,template:a})}),n=await e.json();if(!e.ok)throw Error(n.error||`The Block could not be added.`);t(n.key)}catch(e){u(e.message)}finally{c(!1)}}},children:[(0,H.jsxs)(`label`,{className:`ws-field`,children:[(0,H.jsx)(`span`,{children:`Name`}),(0,H.jsx)(`input`,{value:r,onChange:e=>i(e.target.value),placeholder:`price-drop-alert`,autoFocus:!0,disabled:s})]}),(0,H.jsxs)(`label`,{className:`ws-field`,children:[(0,H.jsx)(`span`,{children:`Start from`}),(0,H.jsx)(`select`,{value:a,onChange:e=>o(e.target.value),disabled:s,children:e.map(e=>(0,H.jsx)(`option`,{value:e.name,children:e.name},e.name))})]}),l&&(0,H.jsx)(`p`,{className:`ws-problem`,role:`alert`,children:l}),(0,H.jsxs)(`div`,{className:`ws-new-actions`,children:[(0,H.jsx)(`button`,{type:`submit`,className:`btn btn-primary`,disabled:s||!r.trim(),children:s?`Adding`:`Add Block`}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:n,children:`Cancel`})]})]})}function xq({data:e,selected:t,onSelect:n,folded:r,onFold:i,follow:a,onFollow:o}){let[s,c]=(0,v.useState)(!1),[l,u]=(0,v.useState)([]),d=()=>{r&&i(!1),c(!0),l.length||fetch(`/__dev/templates`).then(e=>e.json()).then(u).catch(()=>{})},f=e.items.filter(e=>e.kind===`block`),p=e.items.filter(e=>e.kind===`workflow`),m=e=>(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`ws-item`,"aria-current":t===e.key?`true`:void 0,onClick:()=>n(e.key),title:r?`${e.name}: ${gq[e.status]||``}`:void 0,children:[(0,H.jsx)(`span`,{className:`ws-kind`,children:(0,H.jsx)(nG,{name:pq[_q(e)],size:14})}),(0,H.jsxs)(`span`,{className:`ws-text`,children:[(0,H.jsx)(`b`,{children:e.name}),(0,H.jsx)(`small`,{children:vq(e)})]}),(0,H.jsx)(yq,{status:e.status})]})},e.key),h=`${f.length} ${f.length===1?`Block`:`Blocks`} · ${p.length} ${p.length===1?`workflow`:`workflows`}`;return(0,H.jsxs)(`aside`,{className:`ws-side`,"aria-label":`Workspace`,children:[(0,H.jsxs)(`div`,{className:`ws-head`,children:[(0,H.jsx)(`button`,{type:`button`,className:`dh-icon ws-fold`,"aria-label":r?`Open the list`:`Fold the list`,title:r?`Open the list`:`Fold the list`,"aria-expanded":!r,onClick:()=>i(!r),children:(0,H.jsx)(nG,{name:r?`chevronRight`:`chevronLeft`,size:16})}),(0,H.jsxs)(`div`,{className:`ws-title`,children:[(0,H.jsx)(`h1`,{children:e.name}),(0,H.jsx)(`small`,{children:h})]})]}),(0,H.jsxs)(`nav`,{className:`ws-list`,children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Blocks`}),f.length?(0,H.jsx)(`ul`,{children:f.map(m)}):(0,H.jsx)(`p`,{className:`ws-empty`,children:`No Blocks yet. Add one below, or ask your agent.`}),p.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Workflows`}),(0,H.jsx)(`ul`,{children:p.map(m)})]}),e.shared.length>0&&(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{className:`ws-group`,children:`Shared code`}),(0,H.jsx)(`ul`,{children:(0,H.jsx)(`li`,{children:(0,H.jsxs)(`button`,{type:`button`,className:`ws-item`,"aria-current":t===`shared`?`true`:void 0,onClick:()=>n(`shared`),title:r?`Shared code`:void 0,children:[(0,H.jsx)(`span`,{className:`ws-kind`,children:(0,H.jsx)(nG,{name:`folder`,size:14})}),(0,H.jsxs)(`span`,{className:`ws-text`,children:[(0,H.jsx)(`b`,{children:`shared/`}),(0,H.jsxs)(`small`,{children:[e.shared.length,` `,e.shared.length===1?`file`:`files`]})]}),(0,H.jsx)(`span`,{})]})})})]})]}),(0,H.jsxs)(`div`,{className:`ws-foot`,children:[s?(0,H.jsx)(bq,{templates:l.length?l:[{name:`module`}],onAdded:e=>{c(!1),n(e)},onCancel:()=>c(!1)}):(0,H.jsxs)(`button`,{type:`button`,className:`btn btn-ghost ws-add`,onClick:d,title:r?`New Block`:void 0,children:[(0,H.jsx)(nG,{name:`plus`,size:14}),(0,H.jsx)(`span`,{className:`ws-text`,children:`New Block`})]}),!s&&(0,H.jsxs)(`div`,{className:`ws-text ws-follow`,children:[(0,H.jsx)(uq,{on:a,label:`Follow the agent`,onChange:o}),(0,H.jsx)(`small`,{children:`Opens the Block your agent last saved.`})]})]})]})}function Sq({item:e,onCheck:t}){let[n,r]=(0,v.useState)(!1),[i,a]=(0,v.useState)(``),o=async()=>{r(!0),a(``);try{await t()}catch(e){a(e.message)}finally{r(!1)}},s=e.gate,c=s?.current;return(0,H.jsxs)(`div`,{className:`ws-checks`,children:[(0,H.jsxs)(`div`,{className:`dh-section-head`,children:[(0,H.jsxs)(`span`,{className:`dh-muted`,children:[gq[e.status],`. The gate runs StillMade's readiness check on every Block that changed.`]}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:n,onClick:o,children:n?`Running the gate`:`Run the gate`})]}),(0,H.jsxs)(`ul`,{className:`ws-checklist`,children:[e.problem&&(0,H.jsxs)(`li`,{"data-state":`failed`,children:[(0,H.jsx)(nq,{name:`problem`}),(0,H.jsx)(`span`,{children:e.problem})]}),e.buildProblem&&(0,H.jsxs)(`li`,{"data-state":`failed`,children:[(0,H.jsx)(nq,{name:`problem`}),(0,H.jsxs)(`span`,{children:[`Build from `,e.source,` failed: `,e.buildProblem]})]}),e.source&&!e.buildProblem&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(nq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Built from `,e.source,e.shared.length?`, with shared/${e.shared.join(`, shared/`)}`:``]})]}),e.triggers?.length>0&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(nq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Runs on its own: `,e.triggers.join(`; `),`. Its owner turns it on for a Step in a project; here it runs when you press its button.`]})]}),e.apps?.length>0&&(0,H.jsxs)(`li`,{"data-state":`done`,children:[(0,H.jsx)(nq,{name:`done`}),(0,H.jsxs)(`span`,{children:[`Uses `,e.apps.map(e=>e.replace(/^app:(openapi:)?/,``)).join(`, `),` with the account each person connects. Here `,e.apps.length===1?`it answers`:`they answer`,` from tests/mocks.json.`]})]}),e.checklist?.map(e=>(0,H.jsxs)(`li`,{"data-state":e.done?`done`:`todo`,children:[(0,H.jsx)(nq,{name:e.done?`done`:`todo`}),(0,H.jsx)(`span`,{children:e.label}),(0,H.jsx)(`small`,{children:e.done?`done`:`to do`})]},e.id)),(0,H.jsxs)(`li`,{"data-state":c?s.ok?`done`:`failed`:`waiting`,children:[(0,H.jsx)(nq,{name:c?s.ok?`done`:`problem`:`todo`}),(0,H.jsxs)(`span`,{children:[`Readiness gate`,c?`: ${s.status}`:s?`: changed since it last ran`:`: not run yet`]}),(0,H.jsx)(`small`,{children:s?.checkedAt?new Date(s.checkedAt).toLocaleTimeString():``})]}),c&&!s.ok&&s.failures.map((e,t)=>(0,H.jsx)(`li`,{className:`ws-failure`,children:e},t))]}),i&&(0,H.jsx)(`p`,{className:`ws-problem`,role:`alert`,children:i})]})}var Cq={completed:`Done`,skipped:`Skipped`,disabled:`Off in this workflow`,failed:`Failed`,blocked:`Waiting on an earlier Step`,"needs-project":`Runs only in a StillMade project`,"needs-context":`Needs project context`,"needs-sample":`Needs a sample input`,"needs-hosted-run":`Runs on credits in StillMade`,deferred:`Runs in StillMade`},wq=e=>e===`completed`?`done`:e===`failed`?`failed`:e===`running`?`running`:e?`waiting`:`idle`;function Tq({itemKey:e,revision:t,theme:n,setTheme:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)({}),[c,l]=(0,v.useState)(null),[u,d]=(0,v.useState)(!1),[f,p]=(0,v.useState)(null);(0,v.useEffect)(()=>{let t=!0;return fetch(`/__dev/workflow?item=${encodeURIComponent(e)}`,{cache:`no-store`}).then(e=>e.json()).then(e=>{t&&(a(e),p(t=>t??e.samples??{}))}).catch(e=>t&&a({problem:e.message})),()=>{t=!1}},[e,t]),(0,v.useEffect)(()=>{let t=new EventSource(`/__dev/events`);return t.addEventListener(`step`,t=>{let n=JSON.parse(t.data);n.item===e&&s(e=>({...e,[n.step.id]:n.step}))}),()=>t.close()},[e]);let m=async()=>{d(!0),s({}),l(null);try{let t=await(await fetch(`/__dev/workflow/run?item=${encodeURIComponent(e)}`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({inputs:f})})).json();l(t),t.results&&s(Object.fromEntries(t.results.map(e=>[e.id,e])))}catch(e){l({error:e.message})}finally{d(!1)}};if(!i)return(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsx)(`p`,{className:`dh-muted ws-pad`,role:`status`,children:`Loading the workflow`})});if(i.problem)return(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:i.problem})});let h=[...i.steps].reverse().find(e=>o[e.id]?.outputs),g=h&&o[h.id],_=c?.standIns||[],y=u?`Running the Steps…`:c?.error?`The run did not finish`:c?`Ran in ${c.ms} ms${_.length?` · ${_.length} ${_.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Runs on this computer with stand-ins`,b=[{key:`steps`,label:`Steps`},{key:`samples`,label:`Sample inputs`},{key:`connections`,label:`Connections · ${i.connections.length}`}],x=e=>i.steps.find(t=>t.id===e)?.label||e;return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsxs)(`header`,{className:`dh-bar`,children:[(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:i.name}),(0,H.jsxs)(`span`,{className:`dh-meta`,children:[i.automation?`Automation`:`Project Type`,` · `,i.version]})]}),(0,H.jsx)(`span`,{className:`dh-spacer`}),(0,H.jsx)(aq,{label:`Appearance`,value:n,options:OK,onChange:r}),(0,H.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:u,onClick:m,children:u?`Running the workflow`:i.automation?`Run once now · 0 credits`:`Run the workflow · 0 credits`})]}),(0,H.jsxs)(`main`,{className:`dh-main ws-flow`,"aria-label":`Workflow`,children:[(0,H.jsx)(`ol`,{className:`ws-steps`,children:i.steps.map((e,t)=>{let n=o[e.id],r=u&&!n?`running`:wq(n?.status);return(0,H.jsxs)(`li`,{className:`ws-step`,"data-tone":r,children:[(0,H.jsxs)(`span`,{className:`ws-step-n`,children:[`Step `,t+1]}),(0,H.jsx)(`b`,{children:e.label}),(0,H.jsxs)(`span`,{className:`ws-ports`,children:[(0,H.jsxs)(`span`,{children:[`In: `,e.inputs.map(e=>e.name).join(`, `)||`nothing`]}),(0,H.jsxs)(`span`,{children:[`Out: `,e.outputs.map(e=>e.name).join(`, `)||`nothing`]})]}),(0,H.jsx)(`span`,{className:`ws-step-state`,children:r===`running`?`Waiting to run`:n?`${Cq[n.status]||n.status}${n.status===`failed`&&n.message?`: ${n.message}`:``}`:`Not run yet`})]},e.id)})}),(0,H.jsxs)(`section`,{className:`ws-outcome`,"aria-label":`Result`,children:[(0,H.jsx)(`div`,{className:`ws-outcome-main`,children:c?.error?(0,H.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:c.error}):g?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`h2`,{children:h.label}),Object.entries(g.outputs).map(([e,t])=>(0,H.jsxs)(`div`,{className:`ws-output`,children:[(0,H.jsx)(`span`,{children:HW(e)}),(0,H.jsx)(XW,{value:t,renderMedia:YK})]},e))]}):(0,H.jsx)(`p`,{className:`dh-muted`,children:u?`Running…`:`Run the workflow to see what its last Step makes.`})}),(0,H.jsxs)(`aside`,{className:`ws-outcome-side`,children:[(0,H.jsx)(`h2`,{children:`What this run used`}),_.length?(0,H.jsx)(`ul`,{children:_.map((e,t)=>(0,H.jsxs)(`li`,{children:[e.api,` `,e.name,`: `,/mocks/.test(e.source)?`answered from the Block's tests`:`a recorded stand-in`]},t))}):(0,H.jsx)(`p`,{className:`dh-muted`,children:c?`No hosted calls.`:`Nothing yet.`}),(0,H.jsx)(`p`,{className:`ws-note`,children:`A stand-in run proves the Steps fit together. Real voices, pictures and video run only in StillMade, on credits.`}),i.automation&&(0,H.jsx)(`p`,{className:`ws-note`,children:`An automation. In a project its first Step waits for what is turned on on the Automation page: a schedule, an app event or a webhook. Here it runs once, as if started by hand.`})]})]})]}),(0,H.jsx)(dq,{tabs:b,status:y,children:t=>t===`steps`?(0,H.jsx)(`ol`,{className:`dh-calls`,children:i.steps.map(e=>{let t=o[e.id];return(0,H.jsxs)(`li`,{children:[(0,H.jsx)(`strong`,{children:e.label}),(0,H.jsx)(`span`,{children:e.folder?`blocks/${e.folder}`:`${e.blockId}@${e.version}`}),(0,H.jsxs)(`small`,{children:[t?Cq[t.status]||t.status:`Not run yet`,t?.message&&t.status!==`completed`?`: ${t.message}`:``]})]},e.id)})}):t===`samples`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`div`,{className:`dh-section-head`,children:(0,H.jsxs)(`span`,{className:`dh-muted`,children:[`What each Step starts with, by Step id. Saved in workflows/`,e.split(`/`).pop(),`.samples.json, the run uses that file instead.`]})}),(0,H.jsx)(QK,{value:f||{},onCommit:p,disabled:u})]}):(0,H.jsxs)(`ol`,{className:`dh-calls`,children:[i.connections.map((e,t)=>(0,H.jsxs)(`li`,{children:[(0,H.jsxs)(`strong`,{children:[x(e.from.stage),`: `,e.from.port]}),(0,H.jsxs)(`span`,{children:[`to `,x(e.to.stage),`: `,e.to.port]})]},t)),!i.connections.length&&(0,H.jsx)(`li`,{children:`No connections. Each Step takes only its own inputs.`})]})})]})}function Eq({data:e}){return(0,H.jsxs)(`div`,{className:`dh-page`,children:[(0,H.jsx)(`header`,{className:`dh-bar`,children:(0,H.jsxs)(`div`,{className:`dh-title`,children:[(0,H.jsx)(`h1`,{children:`Shared code`}),(0,H.jsx)(`span`,{className:`dh-meta`,children:`shared/`})]})}),(0,H.jsx)(`main`,{className:`dh-main`,children:(0,H.jsxs)(`div`,{className:`ws-shared`,children:[(0,H.jsx)(`p`,{className:`dh-muted`,children:`Module Blocks import these files from src/main.js. Building joins them into each Block, so every packed Block still stands alone.`}),(0,H.jsx)(`ul`,{className:`dh-calls`,children:e.shared.map(e=>(0,H.jsxs)(`li`,{children:[(0,H.jsxs)(`strong`,{children:[`shared/`,e.file]}),(0,H.jsx)(`small`,{children:e.usedBy.length?`Used by ${e.usedBy.join(`, `)}`:`Not used yet`})]},e.file))})]})})]})}var Dq=()=>{try{return decodeURIComponent(location.hash.slice(1))}catch{return``}};function Oq({initial:e}){let[t,n]=(0,v.useState)(e),[r,i]=(0,v.useState)(()=>{let t=Dq();return e.items.some(e=>e.key===t)||t===`shared`?t:e.items[0]?.key||``}),[a,o]=(0,v.useState)(()=>HK(`stillmade.dev.workspace.folded`,``)===`1`),[s,c]=(0,v.useState)(()=>HK(`stillmade.dev.workspace.follow`,`1`)===`1`),[l,u]=(0,v.useState)(()=>HK(`stillmade.dev.theme`,`light`)),[d,f]=(0,v.useState)(0),p=(0,v.useRef)(s);p.current=s;let m=(0,v.useCallback)(()=>fetch(`/__dev/workspace`,{cache:`no-store`}).then(e=>e.json()).then(e=>(n(e),e)),[]),h=(0,v.useCallback)(e=>{i(e);try{history.replaceState(null,``,`#${encodeURIComponent(e)}`)}catch{}},[]);(0,v.useEffect)(()=>{let e=new EventSource(`/__dev/events`);return e.addEventListener(`workspace`,e=>{let t=JSON.parse(e.data);m().then(e=>{t.focus&&p.current&&e.items.some(e=>e.key===t.focus)&&h(t.focus),f(e=>e+1)}).catch(()=>{})}),()=>e.close()},[m,h]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=l,UK(`stillmade.dev.theme`,l)},[l]),(0,v.useEffect)(()=>{UK(`stillmade.dev.workspace.folded`,a?`1`:``)},[a]),(0,v.useEffect)(()=>{UK(`stillmade.dev.workspace.follow`,s?`1`:``)},[s]);let g=t.items.find(e=>e.key===r),_=(0,v.useCallback)(async()=>{if(!(await fetch(`/__dev/check`,{method:`POST`})).ok)throw Error(`The gate could not run.`);await m()},[m]),y=(0,v.useMemo)(()=>g?.kind===`block`?[{key:`checks`,label:`Checks`,alert:g.status===`needs-fix`,render:()=>(0,H.jsx)(Sq,{item:g,onCheck:_})}]:[],[g,_]),b=g?.kind===`block`?(0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(`span`,{className:`ws-chip`,children:mq[_q(g)]}),g.status!==`ready`&&(0,H.jsx)(`span`,{className:`ws-chip`,"data-status":g.status,children:gq[g.status]})]}):null;return(0,H.jsxs)(`div`,{className:`ws-page`,"data-folded":a?`true`:`false`,children:[(0,H.jsx)(xq,{data:t,selected:r,onSelect:h,folded:a,onFold:o,follow:s,onFollow:c}),(0,H.jsx)(`div`,{className:`ws-content`,children:!g&&r!==`shared`?(0,H.jsx)(`div`,{className:`dh-page`,children:(0,H.jsxs)(`div`,{className:`ws-pad`,children:[(0,H.jsx)(`h2`,{className:`ws-hello`,children:t.name}),(0,H.jsxs)(`p`,{className:`dh-muted`,children:[`Add a Block from the list, or ask your agent to run `,(0,H.jsx)(`code`,{children:`stillmade-block add <name>`}),`. It shows up here by itself.`]})]})}):r===`shared`?(0,H.jsx)(Eq,{data:t}):g.kind===`workflow`?(0,H.jsx)(Tq,{itemKey:g.key,revision:d,theme:l,setTheme:u},g.key):(0,H.jsx)(fq,{item:g.key,extraTabs:y,badges:b,dockOpen:g.status===`ready`?null:`checks`},g.key)})]})}var kq=(0,y.createRoot)(document.getElementById(`root`));fetch(`/__dev/workspace`,{cache:`no-store`}).then(e=>e.ok?e.json():null).catch(()=>null).then(e=>kq.render((0,H.jsxs)(H.Fragment,{children:[(0,H.jsx)(rq,{}),e?(0,H.jsx)(Oq,{initial:e}):(0,H.jsx)(fq,{})]})));
|