stillmade-sdk 0.1.45 → 0.1.47

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(vi,``)}function bi(e,t,n){if(t=yi(t),yi(e)!==t&&n)throw Error(r(425))}function xi(){}var Si=null,Ci=null;function wi(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 Ti=typeof setTimeout==`function`?setTimeout:void 0,Ei=typeof clearTimeout==`function`?clearTimeout:void 0,Di=typeof Promise==`function`?Promise:void 0,Oi=typeof queueMicrotask==`function`?queueMicrotask:Di===void 0?Ti:function(e){return Di.resolve(null).then(e).catch(ki)};function ki(e){setTimeout(function(){throw e})}function Ai(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),fn(t);return}r--}else n!==`$`&&n!==`$?`&&n!==`$!`||r++}n=i}while(n);fn(t)}function ji(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 Mi(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 Ni=Math.random().toString(36).slice(2),Pi=`__reactFiber$`+Ni,Fi=`__reactProps$`+Ni,Ii=`__reactContainer$`+Ni,Li=`__reactEvents$`+Ni,Ri=`__reactListeners$`+Ni,H=`__reactHandles$`+Ni;function zi(e){var t=e[Pi];if(t)return t;for(var n=e.parentNode;n;){if(t=n[Ii]||n[Pi]){if(n=t.alternate,t.child!==null||n!==null&&n.child!==null)for(e=Mi(e);e!==null;){if(n=e[Pi])return n;e=Mi(e)}return t}e=n,n=e.parentNode}return null}function Bi(e){return e=e[Pi]||e[Ii],!e||e.tag!==5&&e.tag!==6&&e.tag!==13&&e.tag!==3?null:e}function Vi(e){if(e.tag===5||e.tag===6)return e.stateNode;throw Error(r(33))}function Hi(e){return e[Fi]||null}var Ui=[],Wi=-1;function Gi(e){return{current:e}}function Ki(e){0>Wi||(e.current=Ui[Wi],Ui[Wi]=null,Wi--)}function qi(e,t){Wi++,Ui[Wi]=e.current,e.current=t}var Ji={},U=Gi(Ji),Yi=Gi(!1),Xi=Ji;function Zi(e,t){var n=e.type.contextTypes;if(!n)return Ji;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 Qi(e){return e=e.childContextTypes,e!=null}function $i(){Ki(Yi),Ki(U)}function ea(e,t,n){if(U.current!==Ji)throw Error(r(168));qi(U,t),qi(Yi,n)}function ta(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,oe(e)||`Unknown`,a));return L({},n,i)}function na(e){return e=(e=e.stateNode)&&e.__reactInternalMemoizedMergedChildContext||Ji,Xi=U.current,qi(U,e),qi(Yi,Yi.current),!0}function ra(e,t,n){var i=e.stateNode;if(!i)throw Error(r(169));n?(e=ta(e,t,Xi),i.__reactInternalMemoizedMergedChildContext=e,Ki(Yi),Ki(U),qi(U,e)):Ki(Yi),qi(Yi,n)}var ia=null,aa=!1,oa=!1;function sa(e){ia===null?ia=[e]:ia.push(e)}function ca(e){aa=!0,sa(e)}function la(){if(!oa&&ia!==null){oa=!0;var e=0,t=Vt;try{var n=ia;for(Vt=1;e<n.length;e++){var r=n[e];do r=r(!0);while(r!==null)}ia=null,aa=!1}catch(t){throw ia!==null&&(ia=ia.slice(e+1)),ft(B,la),t}finally{Vt=t,oa=!1}}return null}var ua=[],da=0,fa=null,pa=0,ma=[],ha=0,ga=null,_a=1,va=``;function ya(e,t){ua[da++]=pa,ua[da++]=fa,fa=e,pa=t}function ba(e,t,n){ma[ha++]=_a,ma[ha++]=va,ma[ha++]=ga,ga=e;var r=_a;e=va;var i=32-Tt(r)-1;r&=~(1<<i),n+=1;var a=32-Tt(t)+i;if(30<a){var o=i-i%5;a=(r&(1<<o)-1).toString(32),r>>=o,i-=o,_a=1<<32-Tt(t)+i|n<<i|r,va=a+e}else _a=1<<a|n<<i|r,va=e}function xa(e){e.return!==null&&(ya(e,1),ba(e,1,0))}function Sa(e){for(;e===fa;)fa=ua[--da],ua[da]=null,pa=ua[--da],ua[da]=null;for(;e===ga;)ga=ma[--ha],ma[ha]=null,va=ma[--ha],ma[ha]=null,_a=ma[--ha],ma[ha]=null}var Ca=null,wa=null,Ta=!1,Ea=null;function Da(e,t){var n=tu(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 Oa(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,Ca=e,wa=ji(t.firstChild),!0);case 6:return t=e.pendingProps===``||t.nodeType!==3?null:t,t!==null&&(e.stateNode=t,Ca=e,wa=null,!0);case 13:return t=t.nodeType===8?t:null,t!==null&&(n=ga===null?null:{id:_a,overflow:va},e.memoizedState={dehydrated:t,treeContext:n,retryLane:1073741824},n=tu(18,null,null,0),n.stateNode=t,n.return=e,e.child=n,Ca=e,wa=null,!0);default:return!1}}function ka(e){return!!(e.mode&1)&&!(e.flags&128)}function Aa(e){if(Ta){var t=wa;if(t){var n=t;if(!Oa(e,t)){if(ka(e))throw Error(r(418));t=ji(n.nextSibling);var i=Ca;t&&Oa(e,t)?Da(i,n):(e.flags=e.flags&-4097|2,Ta=!1,Ca=e)}}else{if(ka(e))throw Error(r(418));e.flags=e.flags&-4097|2,Ta=!1,Ca=e}}}function ja(e){for(e=e.return;e!==null&&e.tag!==5&&e.tag!==3&&e.tag!==13;)e=e.return;Ca=e}function Ma(e){if(e!==Ca)return!1;if(!Ta)return ja(e),Ta=!0,!1;var t;if((t=e.tag!==3)&&!(t=e.tag!==5)&&(t=e.type,t=t!==`head`&&t!==`body`&&!wi(e.type,e.memoizedProps)),t&&=wa){if(ka(e))throw Na(),Error(r(418));for(;t;)Da(e,t),t=ji(t.nextSibling)}if(ja(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){wa=ji(e.nextSibling);break a}t--}else n!==`$`&&n!==`$!`&&n!==`$?`||t++}e=e.nextSibling}wa=null}}else wa=Ca?ji(e.stateNode.nextSibling):null;return!0}function Na(){for(var e=wa;e;)e=ji(e.nextSibling)}function Pa(){wa=Ca=null,Ta=!1}function Fa(e){Ea===null?Ea=[e]:Ea.push(e)}var Ia=C.ReactCurrentBatchConfig;function La(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 Ra(e,t){throw e=Object.prototype.toString.call(t),Error(r(31,e===`[object Object]`?`object with keys {`+Object.keys(t).join(`, `)+`}`:e))}function za(e){var t=e._init;return t(e._payload)}function Ba(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=iu(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=cu(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&&za(i)===t.type)?(r=a(t,n.props),r.ref=La(e,t,n),r.return=e,r):(r=au(n.type,n.key,n.props,null,e.mode,r),r.ref=La(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=lu(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=ou(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=cu(``+t,e.mode,n),t.return=e,t;if(typeof t==`object`&&t){switch(t.$$typeof){case w:return n=au(t.type,t.key,t.props,null,e.mode,n),n.ref=La(e,null,t),n.return=e,n;case T:return t=lu(t,e.mode,n),t.return=e,t;case F:var r=t._init;return f(e,r(t._payload),n)}if(ye(t)||te(t))return t=ou(t,e.mode,n,null),t.return=e,t;Ra(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(ye(n)||te(n))return i===null?d(e,t,n,r,null):null;Ra(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(ye(r)||te(r))return e=e.get(n)||null,d(t,e,r,i,null);Ra(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),Ta&&ya(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 Ta&&ya(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)}),Ta&&ya(r,h),l}function g(a,s,c,l){var u=te(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),Ta&&ya(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 Ta&&ya(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)}),Ta&&ya(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&&za(c)===l.type){n(e,l.sibling),r=a(l,i.props),r.ref=La(e,l,i),r.return=e,e=r;break a}n(e,l);break}t(e,l),l=l.sibling}i.type===E?(r=ou(i.props.children,e.mode,o,i.key),r.return=e,e=r):(o=au(i.type,i.key,i.props,null,e.mode,o),o.ref=La(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=lu(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(ye(i))return h(e,r,i,o);if(te(i))return g(e,r,i,o);Ra(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=cu(i,e.mode,o),r.return=e,e=r),s(e)):n(e,r)}return _}var Va=Ba(!0),Ha=Ba(!1),Ua=Gi(null),Wa=null,Ga=null,Ka=null;function qa(){Ka=Ga=Wa=null}function Ja(e){var t=Ua.current;Ki(Ua),e._currentValue=t}function Ya(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 Xa(e,t){Wa=e,Ka=Ga=null,e=e.dependencies,e!==null&&e.firstContext!==null&&((e.lanes&t)!==0&&(Bs=!0),e.firstContext=null)}function Za(e){var t=e._currentValue;if(Ka!==e){if(e={context:e,memoizedValue:t,next:null},Ga===null){if(Wa===null)throw Error(r(308));Ga=e,Wa.dependencies={lanes:0,firstContext:e}}else Ga=Ga.next=e}return t}var Qa=null;function $a(e){Qa===null?Qa=[e]:Qa.push(e)}function eo(e,t,n,r){var i=t.interleaved;return i===null?(n.next=n,$a(t)):(n.next=i.next,i.next=n),t.interleaved=n,to(e,r)}function to(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 no=!1;function ro(e){e.updateQueue={baseState:e.memoizedState,firstBaseUpdate:null,lastBaseUpdate:null,shared:{pending:null,interleaved:null,lanes:0},effects:null}}function io(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 ao(e,t){return{eventTime:e,lane:t,tag:0,payload:null,callback:null,next:null}}function oo(e,t,n){var r=e.updateQueue;if(r===null)return null;if(r=r.shared,Xc&2){var i=r.pending;return i===null?t.next=t:(t.next=i.next,i.next=t),r.pending=t,to(e,n)}return i=r.interleaved,i===null?(t.next=t,$a(r)):(t.next=i.next,i.next=t),r.interleaved=t,to(e,n)}function so(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,Bt(e,n)}}function co(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 lo(e,t,n,r){var i=e.updateQueue;no=!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=L({},d,f);break a;case 2:no=!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);il|=o,e.lanes=o,e.memoizedState=d}}function uo(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 fo={},po=Gi(fo),mo=Gi(fo),ho=Gi(fo);function go(e){if(e===fo)throw Error(r(174));return e}function _o(e,t){switch(qi(ho,t),qi(mo,e),qi(po,fo),e=t.nodeType,e){case 9:case 11:t=(t=t.documentElement)?t.namespaceURI:Ee(null,``);break;default:e=e===8?t.parentNode:t,t=e.namespaceURI||null,e=e.tagName,t=Ee(t,e)}Ki(po),qi(po,t)}function vo(){Ki(po),Ki(mo),Ki(ho)}function yo(e){go(ho.current);var t=go(po.current),n=Ee(t,e.type);t!==n&&(qi(mo,e),qi(po,n))}function bo(e){mo.current===e&&(Ki(po),Ki(mo))}var xo=Gi(0);function So(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 Co=[];function wo(){for(var e=0;e<Co.length;e++)Co[e]._workInProgressVersionPrimary=null;Co.length=0}var To=C.ReactCurrentDispatcher,Eo=C.ReactCurrentBatchConfig,Do=0,Oo=null,ko=null,Ao=null,jo=!1,Mo=!1,No=0,Po=0;function Fo(){throw Error(r(321))}function Io(e,t){if(t===null)return!1;for(var n=0;n<t.length&&n<e.length;n++)if(!kr(e[n],t[n]))return!1;return!0}function Lo(e,t,n,i,a,o){if(Do=o,Oo=t,t.memoizedState=null,t.updateQueue=null,t.lanes=0,To.current=e===null||e.memoizedState===null?bs:xs,e=n(i,a),Mo){o=0;do{if(Mo=!1,No=0,25<=o)throw Error(r(301));o+=1,Ao=ko=null,t.updateQueue=null,To.current=Ss,e=n(i,a)}while(Mo)}if(To.current=ys,t=ko!==null&&ko.next!==null,Do=0,Ao=ko=Oo=null,jo=!1,t)throw Error(r(300));return e}function Ro(){var e=No!==0;return No=0,e}function zo(){var e={memoizedState:null,baseState:null,baseQueue:null,queue:null,next:null};return Ao===null?Oo.memoizedState=Ao=e:Ao=Ao.next=e,Ao}function Bo(){if(ko===null){var e=Oo.alternate;e=e===null?null:e.memoizedState}else e=ko.next;var t=Ao===null?Oo.memoizedState:Ao.next;if(t!==null)Ao=t,ko=e;else{if(e===null)throw Error(r(310));ko=e,e={memoizedState:ko.memoizedState,baseState:ko.baseState,baseQueue:ko.baseQueue,queue:ko.queue,next:null},Ao===null?Oo.memoizedState=Ao=e:Ao=Ao.next=e}return Ao}function Vo(e,t){return typeof t==`function`?t(e):t}function Ho(e){var t=Bo(),n=t.queue;if(n===null)throw Error(r(311));n.lastRenderedReducer=e;var i=ko,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((Do&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,Oo.lanes|=d,il|=d}u=u.next}while(u!==null&&u!==o);l===null?s=i:l.next=c,kr(i,t.memoizedState)||(Bs=!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,Oo.lanes|=o,il|=o,a=a.next;while(a!==e)}else a===null&&(n.lanes=0);return[t.memoizedState,n.dispatch]}function Uo(e){var t=Bo(),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);kr(o,t.memoizedState)||(Bs=!0),t.memoizedState=o,t.baseQueue===null&&(t.baseState=o),n.lastRenderedState=o}return[o,i]}function Wo(){}function Go(e,t){var n=Oo,i=Bo(),a=t(),o=!kr(i.memoizedState,a);if(o&&(i.memoizedState=a,Bs=!0),i=i.queue,rs(Jo.bind(null,n,i,e),[e]),i.getSnapshot!==t||o||Ao!==null&&Ao.memoizedState.tag&1){if(n.flags|=2048,Qo(9,qo.bind(null,n,i,a,t),void 0,null),Zc===null)throw Error(r(349));Do&30||Ko(n,t,a)}return a}function Ko(e,t,n){e.flags|=16384,e={getSnapshot:t,value:n},t=Oo.updateQueue,t===null?(t={lastEffect:null,stores:null},Oo.updateQueue=t,t.stores=[e]):(n=t.stores,n===null?t.stores=[e]:n.push(e))}function qo(e,t,n,r){t.value=n,t.getSnapshot=r,Yo(t)&&Xo(e)}function Jo(e,t,n){return n(function(){Yo(t)&&Xo(e)})}function Yo(e){var t=e.getSnapshot;e=e.value;try{var n=t();return!kr(e,n)}catch{return!0}}function Xo(e){var t=to(e,1);t!==null&&Cl(t,e,1,-1)}function Zo(e){var t=zo();return typeof e==`function`&&(e=e()),t.memoizedState=t.baseState=e,e={pending:null,interleaved:null,lanes:0,dispatch:null,lastRenderedReducer:Vo,lastRenderedState:e},t.queue=e,e=e.dispatch=hs.bind(null,Oo,e),[t.memoizedState,e]}function Qo(e,t,n,r){return e={tag:e,create:t,destroy:n,deps:r,next:null},t=Oo.updateQueue,t===null?(t={lastEffect:null,stores:null},Oo.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 $o(){return Bo().memoizedState}function es(e,t,n,r){var i=zo();Oo.flags|=e,i.memoizedState=Qo(1|t,n,void 0,r===void 0?null:r)}function ts(e,t,n,r){var i=Bo();r=r===void 0?null:r;var a=void 0;if(ko!==null){var o=ko.memoizedState;if(a=o.destroy,r!==null&&Io(r,o.deps)){i.memoizedState=Qo(t,n,a,r);return}}Oo.flags|=e,i.memoizedState=Qo(1|t,n,a,r)}function ns(e,t){return es(8390656,8,e,t)}function rs(e,t){return ts(2048,8,e,t)}function is(e,t){return ts(4,2,e,t)}function as(e,t){return ts(4,4,e,t)}function os(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 ss(e,t,n){return n=n==null?null:n.concat([e]),ts(4,4,os.bind(null,t,e),n)}function cs(){}function ls(e,t){var n=Bo();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&Io(t,r[1])?r[0]:(n.memoizedState=[e,t],e)}function us(e,t){var n=Bo();t=t===void 0?null:t;var r=n.memoizedState;return r!==null&&t!==null&&Io(t,r[1])?r[0]:(e=e(),n.memoizedState=[e,t],e)}function ds(e,t,n){return Do&21?(kr(n,t)||(n=It(),Oo.lanes|=n,il|=n,e.baseState=!0),t):(e.baseState&&(e.baseState=!1,Bs=!0),e.memoizedState=n)}function fs(e,t){var n=Vt;Vt=n!==0&&4>n?n:4,e(!0);var r=Eo.transition;Eo.transition={};try{e(!1),t()}finally{Vt=n,Eo.transition=r}}function ps(){return Bo().memoizedState}function ms(e,t,n){var r=Sl(e);if(n={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null},gs(e))_s(t,n);else if(n=eo(e,t,n,r),n!==null){var i=xl();Cl(n,e,r,i),vs(n,t,r)}}function hs(e,t,n){var r=Sl(e),i={lane:r,action:n,hasEagerState:!1,eagerState:null,next:null};if(gs(e))_s(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,kr(s,o)){var c=t.interleaved;c===null?(i.next=i,$a(t)):(i.next=c.next,c.next=i),t.interleaved=i;return}}catch{}n=eo(e,t,i,r),n!==null&&(i=xl(),Cl(n,e,r,i),vs(n,t,r))}}function gs(e){var t=e.alternate;return e===Oo||t!==null&&t===Oo}function _s(e,t){Mo=jo=!0;var n=e.pending;n===null?t.next=t:(t.next=n.next,n.next=t),e.pending=t}function vs(e,t,n){if(n&4194240){var r=t.lanes;r&=e.pendingLanes,n|=r,t.lanes=n,Bt(e,n)}}var ys={readContext:Za,useCallback:Fo,useContext:Fo,useEffect:Fo,useImperativeHandle:Fo,useInsertionEffect:Fo,useLayoutEffect:Fo,useMemo:Fo,useReducer:Fo,useRef:Fo,useState:Fo,useDebugValue:Fo,useDeferredValue:Fo,useTransition:Fo,useMutableSource:Fo,useSyncExternalStore:Fo,useId:Fo,unstable_isNewReconciler:!1},bs={readContext:Za,useCallback:function(e,t){return zo().memoizedState=[e,t===void 0?null:t],e},useContext:Za,useEffect:ns,useImperativeHandle:function(e,t,n){return n=n==null?null:n.concat([e]),es(4194308,4,os.bind(null,t,e),n)},useLayoutEffect:function(e,t){return es(4194308,4,e,t)},useInsertionEffect:function(e,t){return es(4,2,e,t)},useMemo:function(e,t){var n=zo();return t=t===void 0?null:t,e=e(),n.memoizedState=[e,t],e},useReducer:function(e,t,n){var r=zo();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=ms.bind(null,Oo,e),[r.memoizedState,e]},useRef:function(e){var t=zo();return e={current:e},t.memoizedState=e},useState:Zo,useDebugValue:cs,useDeferredValue:function(e){return zo().memoizedState=e},useTransition:function(){var e=Zo(!1),t=e[0];return e=fs.bind(null,e[1]),zo().memoizedState=e,[t,e]},useMutableSource:function(){},useSyncExternalStore:function(e,t,n){var i=Oo,a=zo();if(Ta){if(n===void 0)throw Error(r(407));n=n()}else{if(n=t(),Zc===null)throw Error(r(349));Do&30||Ko(i,t,n)}a.memoizedState=n;var o={value:n,getSnapshot:t};return a.queue=o,ns(Jo.bind(null,i,o,e),[e]),i.flags|=2048,Qo(9,qo.bind(null,i,o,n,t),void 0,null),n},useId:function(){var e=zo(),t=Zc.identifierPrefix;if(Ta){var n=va,r=_a;n=(r&~(1<<32-Tt(r)-1)).toString(32)+n,t=`:`+t+`R`+n,n=No++,0<n&&(t+=`H`+n.toString(32)),t+=`:`}else n=Po++,t=`:`+t+`r`+n.toString(32)+`:`;return e.memoizedState=t},unstable_isNewReconciler:!1},xs={readContext:Za,useCallback:ls,useContext:Za,useEffect:rs,useImperativeHandle:ss,useInsertionEffect:is,useLayoutEffect:as,useMemo:us,useReducer:Ho,useRef:$o,useState:function(){return Ho(Vo)},useDebugValue:cs,useDeferredValue:function(e){return ds(Bo(),ko.memoizedState,e)},useTransition:function(){return[Ho(Vo)[0],Bo().memoizedState]},useMutableSource:Wo,useSyncExternalStore:Go,useId:ps,unstable_isNewReconciler:!1},Ss={readContext:Za,useCallback:ls,useContext:Za,useEffect:rs,useImperativeHandle:ss,useInsertionEffect:is,useLayoutEffect:as,useMemo:us,useReducer:Uo,useRef:$o,useState:function(){return Uo(Vo)},useDebugValue:cs,useDeferredValue:function(e){var t=Bo();return ko===null?t.memoizedState=e:ds(t,ko.memoizedState,e)},useTransition:function(){return[Uo(Vo)[0],Bo().memoizedState]},useMutableSource:Wo,useSyncExternalStore:Go,useId:ps,unstable_isNewReconciler:!1};function Cs(e,t){if(e&&e.defaultProps){for(var n in t=L({},t),e=e.defaultProps,e)t[n]===void 0&&(t[n]=e[n]);return t}return t}function ws(e,t,n,r){t=e.memoizedState,n=n(r,t),n=n==null?t:L({},t,n),e.memoizedState=n,e.lanes===0&&(e.updateQueue.baseState=n)}var Ts={isMounted:function(e){return(e=e._reactInternals)?ot(e)===e:!1},enqueueSetState:function(e,t,n){e=e._reactInternals;var r=xl(),i=Sl(e),a=ao(r,i);a.payload=t,n!=null&&(a.callback=n),t=oo(e,a,i),t!==null&&(Cl(t,e,i,r),so(t,e,i))},enqueueReplaceState:function(e,t,n){e=e._reactInternals;var r=xl(),i=Sl(e),a=ao(r,i);a.tag=1,a.payload=t,n!=null&&(a.callback=n),t=oo(e,a,i),t!==null&&(Cl(t,e,i,r),so(t,e,i))},enqueueForceUpdate:function(e,t){e=e._reactInternals;var n=xl(),r=Sl(e),i=ao(n,r);i.tag=2,t!=null&&(i.callback=t),t=oo(e,i,r),t!==null&&(Cl(t,e,r,n),so(t,e,r))}};function Es(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?!Ar(n,r)||!Ar(i,a):!0}function Ds(e,t,n){var r=!1,i=Ji,a=t.contextType;return typeof a==`object`&&a?a=Za(a):(i=Qi(t)?Xi:U.current,r=t.contextTypes,a=(r=r!=null)?Zi(e,i):Ji),t=new t(n,a),e.memoizedState=t.state!==null&&t.state!==void 0?t.state:null,t.updater=Ts,e.stateNode=t,t._reactInternals=e,r&&(e=e.stateNode,e.__reactInternalMemoizedUnmaskedChildContext=i,e.__reactInternalMemoizedMaskedChildContext=a),t}function Os(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&&Ts.enqueueReplaceState(t,t.state,null)}function ks(e,t,n,r){var i=e.stateNode;i.props=n,i.state=e.memoizedState,i.refs={},ro(e);var a=t.contextType;typeof a==`object`&&a?i.context=Za(a):(a=Qi(t)?Xi:U.current,i.context=Zi(e,a)),i.state=e.memoizedState,a=t.getDerivedStateFromProps,typeof a==`function`&&(ws(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&&Ts.enqueueReplaceState(i,i.state,null),lo(e,n,i,r),i.state=e.memoizedState),typeof i.componentDidMount==`function`&&(e.flags|=4194308)}function As(e,t){try{var n=``,r=t;do n+=ie(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 js(e,t,n){return{value:e,source:null,stack:n??null,digest:t??null}}function Ms(e,t){try{console.error(t.value)}catch(e){setTimeout(function(){throw e})}}var Ns=typeof WeakMap==`function`?WeakMap:Map;function Ps(e,t,n){n=ao(-1,n),n.tag=3,n.payload={element:null};var r=t.value;return n.callback=function(){dl||(dl=!0,fl=r),Ms(e,t)},n}function Fs(e,t,n){n=ao(-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(){Ms(e,t)}}var a=e.stateNode;return a!==null&&typeof a.componentDidCatch==`function`&&(n.callback=function(){Ms(e,t),typeof r!=`function`&&(pl===null?pl=new Set([this]):pl.add(this));var n=t.stack;this.componentDidCatch(t.value,{componentStack:n===null?``:n})}),n}function Is(e,t,n){var r=e.pingCache;if(r===null){r=e.pingCache=new Ns;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=Jl.bind(null,e,t,n),t.then(e,e))}function Ls(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 Rs(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=ao(-1,1),t.tag=2,oo(n,t,1))),n.lanes|=1),e)}var zs=C.ReactCurrentOwner,Bs=!1;function Vs(e,t,n,r){t.child=e===null?Ha(t,null,n,r):Va(t,e.child,n,r)}function Hs(e,t,n,r,i){n=n.render;var a=t.ref;return Xa(t,i),r=Lo(e,t,n,r,a,i),n=Ro(),e!==null&&!Bs?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,cc(e,t,i)):(Ta&&n&&xa(t),t.flags|=1,Vs(e,t,r,i),t.child)}function Us(e,t,n,r,i){if(e===null){var a=n.type;return typeof a==`function`&&!nu(a)&&a.defaultProps===void 0&&n.compare===null&&n.defaultProps===void 0?(t.tag=15,t.type=a,Ws(e,t,a,r,i)):(e=au(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?Ar:n,n(o,r)&&e.ref===t.ref)return cc(e,t,i)}return t.flags|=1,e=iu(a,r),e.ref=t.ref,e.return=t,t.child=e}function Ws(e,t,n,r,i){if(e!==null){var a=e.memoizedProps;if(Ar(a,r)&&e.ref===t.ref){if(Bs=!1,t.pendingProps=r=a,(e.lanes&i)!==0)e.flags&131072&&(Bs=!0);else return t.lanes=e.lanes,cc(e,t,i)}}return qs(e,t,n,r,i)}function Gs(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},qi(tl,el),el|=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,qi(tl,el),el|=e,null;t.memoizedState={baseLanes:0,cachePool:null,transitions:null},r=a===null?n:a.baseLanes,qi(tl,el),el|=r}}else a===null?r=n:(r=a.baseLanes|n,t.memoizedState=null),qi(tl,el),el|=r;return Vs(e,t,i,n),t.child}function Ks(e,t){var n=t.ref;(e===null&&n!==null||e!==null&&e.ref!==n)&&(t.flags|=512,t.flags|=2097152)}function qs(e,t,n,r,i){var a=Qi(n)?Xi:U.current;return a=Zi(t,a),Xa(t,i),n=Lo(e,t,n,r,a,i),r=Ro(),e!==null&&!Bs?(t.updateQueue=e.updateQueue,t.flags&=-2053,e.lanes&=~i,cc(e,t,i)):(Ta&&r&&xa(t),t.flags|=1,Vs(e,t,n,i),t.child)}function Js(e,t,n,r,i){if(Qi(n)){var a=!0;na(t)}else a=!1;if(Xa(t,i),t.stateNode===null)sc(e,t),Ds(t,n,r),ks(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=Za(l):(l=Qi(n)?Xi:U.current,l=Zi(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)&&Os(t,o,r,l),no=!1;var f=t.memoizedState;o.state=f,lo(t,r,o,i),c=t.memoizedState,s!==r||f!==c||Yi.current||no?(typeof u==`function`&&(ws(t,n,u,r),c=t.memoizedState),(s=no||Es(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,io(e,t),s=t.memoizedProps,l=t.type===t.elementType?s:Cs(t.type,s),o.props=l,d=t.pendingProps,f=o.context,c=n.contextType,typeof c==`object`&&c?c=Za(c):(c=Qi(n)?Xi:U.current,c=Zi(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)&&Os(t,o,r,c),no=!1,f=t.memoizedState,o.state=f,lo(t,r,o,i);var m=t.memoizedState;s!==d||f!==m||Yi.current||no?(typeof p==`function`&&(ws(t,n,p,r),m=t.memoizedState),(l=no||Es(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 Ys(e,t,n,r,a,i)}function Ys(e,t,n,r,i,a){Ks(e,t);var o=!!(t.flags&128);if(!r&&!o)return i&&ra(t,n,!1),cc(e,t,a);r=t.stateNode,zs.current=t;var s=o&&typeof n.getDerivedStateFromError!=`function`?null:r.render();return t.flags|=1,e!==null&&o?(t.child=Va(t,e.child,null,a),t.child=Va(t,null,s,a)):Vs(e,t,s,a),t.memoizedState=r.state,i&&ra(t,n,!0),t.child}function Xs(e){var t=e.stateNode;t.pendingContext?ea(e,t.pendingContext,t.pendingContext!==t.context):t.context&&ea(e,t.context,!1),_o(e,t.containerInfo)}function Zs(e,t,n,r,i){return Pa(),Fa(i),t.flags|=256,Vs(e,t,n,r),t.child}var Qs={dehydrated:null,treeContext:null,retryLane:0};function $s(e){return{baseLanes:e,cachePool:null,transitions:null}}function ec(e,t,n){var r=t.pendingProps,i=xo.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),qi(xo,i&1),e===null)return Aa(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=su(o,r,0,null),e=ou(e,r,n,null),a.return=t,e.return=t,a.sibling=e,t.child=a,t.child.memoizedState=$s(n),t.memoizedState=Qs,e):tc(t,o));if(i=e.memoizedState,i!==null&&(s=i.dehydrated,s!==null))return rc(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=iu(i,c),r.subtreeFlags=i.subtreeFlags&14680064),s===null?(a=ou(a,o,n,null),a.flags|=2):a=iu(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?$s(n):{baseLanes:o.baseLanes|n,cachePool:null,transitions:o.transitions},a.memoizedState=o,a.childLanes=e.childLanes&~n,t.memoizedState=Qs,r}return a=e.child,e=a.sibling,r=iu(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 tc(e,t){return t=su({mode:`visible`,children:t},e.mode,0,null),t.return=e,e.child=t}function nc(e,t,n,r){return r!==null&&Fa(r),Va(t,e.child,null,n),e=tc(t,t.pendingProps.children),e.flags|=2,t.memoizedState=null,e}function rc(e,t,n,i,a,o,s){if(n)return t.flags&256?(t.flags&=-257,i=js(Error(r(422))),nc(e,t,s,i)):t.memoizedState===null?(o=i.fallback,a=t.mode,i=su({mode:`visible`,children:i.children},a,0,null),o=ou(o,a,s,null),o.flags|=2,i.return=t,o.return=t,i.sibling=o,t.child=i,t.mode&1&&Va(t,e.child,null,s),t.child.memoizedState=$s(s),t.memoizedState=Qs,o):(t.child=e.child,t.flags|=128,null);if(!(t.mode&1))return nc(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=js(o,i,void 0),nc(e,t,s,i)}if(c=(s&e.childLanes)!==0,Bs||c){if(i=Zc,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,to(e,a),Cl(i,e,a,-1))}return Ll(),i=js(Error(r(421))),nc(e,t,s,i)}return a.data===`$?`?(t.flags|=128,t.child=e.child,t=Xl.bind(null,e),a._reactRetry=t,null):(e=o.treeContext,wa=ji(a.nextSibling),Ca=t,Ta=!0,Ea=null,e!==null&&(ma[ha++]=_a,ma[ha++]=va,ma[ha++]=ga,_a=e.id,va=e.overflow,ga=t),t=tc(t,i.children),t.flags|=4096,t)}function ic(e,t,n){e.lanes|=t;var r=e.alternate;r!==null&&(r.lanes|=t),Ya(e.return,t,n)}function ac(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 oc(e,t,n){var r=t.pendingProps,i=r.revealOrder,a=r.tail;if(Vs(e,t,r.children,n),r=xo.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&&ic(e,n,t);else if(e.tag===19)ic(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(qi(xo,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&&So(e)===null&&(i=n),n=n.sibling;n=i,n===null?(i=t.child,t.child=null):(i=n.sibling,n.sibling=null),ac(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&&So(e)===null){t.child=i;break}e=i.sibling,i.sibling=n,n=i,i=e}ac(t,!0,n,null,a);break;case`together`:ac(t,!1,null,null,void 0);break;default:t.memoizedState=null}return t.child}function sc(e,t){!(t.mode&1)&&e!==null&&(e.alternate=null,t.alternate=null,t.flags|=2)}function cc(e,t,n){if(e!==null&&(t.dependencies=e.dependencies),il|=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=iu(e,e.pendingProps),t.child=n,n.return=t;e.sibling!==null;)e=e.sibling,n=n.sibling=iu(e,e.pendingProps),n.return=t;n.sibling=null}return t.child}function lc(e,t,n){switch(t.tag){case 3:Xs(t),Pa();break;case 5:yo(t);break;case 1:Qi(t.type)&&na(t);break;case 4:_o(t,t.stateNode.containerInfo);break;case 10:var r=t.type._context,i=t.memoizedProps.value;qi(Ua,r._currentValue),r._currentValue=i;break;case 13:if(r=t.memoizedState,r!==null)return r.dehydrated===null?(n&t.child.childLanes)===0?(qi(xo,xo.current&1),e=cc(e,t,n),e===null?null:e.sibling):ec(e,t,n):(qi(xo,xo.current&1),t.flags|=128,null);qi(xo,xo.current&1);break;case 19:if(r=(n&t.childLanes)!==0,e.flags&128){if(r)return oc(e,t,n);t.flags|=128}if(i=t.memoizedState,i!==null&&(i.rendering=null,i.tail=null,i.lastEffect=null),qi(xo,xo.current),r)break;return null;case 22:case 23:return t.lanes=0,Gs(e,t,n)}return cc(e,t,n)}var uc=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}},dc=function(e,t,n,r){var i=e.memoizedProps;if(i!==r){e=t.stateNode,go(po.current);var o=null;switch(n){case`input`:i=pe(e,i),r=pe(e,r),o=[];break;case`select`:i=L({},i,{value:void 0}),r=L({},r,{value:void 0}),o=[];break;case`textarea`:i=xe(e,i),r=xe(e,r),o=[];break;default:typeof i.onClick!=`function`&&typeof r.onClick==`function`&&(e.onclick=xi)}Fe(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`&&si(`scroll`,e),o||c===l||(o=[])):(o||=[]).push(u,l))}}n&&(o||=[]).push(`style`,n);var u=o;(t.updateQueue=u)&&(t.flags|=4)}},fc=function(e,t,n,r){n!==r&&(t.flags|=4)};function pc(e,t){if(!Ta)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 mc(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 hc(e,t,n){var i=t.pendingProps;switch(Sa(t),t.tag){case 2:case 16:case 15:case 0:case 11:case 7:case 8:case 12:case 9:case 14:return mc(t),null;case 1:return Qi(t.type)&&$i(),mc(t),null;case 3:return i=t.stateNode,vo(),Ki(Yi),Ki(U),wo(),i.pendingContext&&(i.context=i.pendingContext,i.pendingContext=null),(e===null||e.child===null)&&(Ma(t)?t.flags|=4:e===null||e.memoizedState.isDehydrated&&!(t.flags&256)||(t.flags|=1024,Ea!==null&&(Dl(Ea),Ea=null))),mc(t),null;case 5:bo(t);var o=go(ho.current);if(n=t.type,e!==null&&t.stateNode!=null)dc(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 mc(t),null}if(e=go(po.current),Ma(t)){i=t.stateNode,n=t.type;var s=t.memoizedProps;switch(i[Pi]=t,i[Fi]=s,e=!!(t.mode&1),n){case`dialog`:si(`cancel`,i),si(`close`,i);break;case`iframe`:case`object`:case`embed`:si(`load`,i);break;case`video`:case`audio`:for(o=0;o<ri.length;o++)si(ri[o],i);break;case`source`:si(`error`,i);break;case`img`:case`image`:case`link`:si(`error`,i),si(`load`,i);break;case`details`:si(`toggle`,i);break;case`input`:me(i,s),si(`invalid`,i);break;case`select`:i._wrapperState={wasMultiple:!!s.multiple},si(`invalid`,i);break;case`textarea`:Se(i,s),si(`invalid`,i)}for(var c in Fe(n,s),o=null,s)if(s.hasOwnProperty(c)){var l=s[c];c===`children`?typeof l==`string`?i.textContent!==l&&(!0!==s.suppressHydrationWarning&&bi(i.textContent,l,e),o=[`children`,l]):typeof l==`number`&&i.textContent!==``+l&&(!0!==s.suppressHydrationWarning&&bi(i.textContent,l,e),o=[`children`,``+l]):a.hasOwnProperty(c)&&l!=null&&c===`onScroll`&&si(`scroll`,i)}switch(n){case`input`:ue(i),_e(i,s,!0);break;case`textarea`:ue(i),we(i);break;case`select`:case`option`:break;default:typeof s.onClick==`function`&&(i.onclick=xi)}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=Te(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[Pi]=t,e[Fi]=i,uc(e,t,!1,!1),t.stateNode=e;a:{switch(c=Ie(n,i),n){case`dialog`:si(`cancel`,e),si(`close`,e),o=i;break;case`iframe`:case`object`:case`embed`:si(`load`,e),o=i;break;case`video`:case`audio`:for(o=0;o<ri.length;o++)si(ri[o],e);o=i;break;case`source`:si(`error`,e),o=i;break;case`img`:case`image`:case`link`:si(`error`,e),si(`load`,e),o=i;break;case`details`:si(`toggle`,e),o=i;break;case`input`:me(e,i),o=pe(e,i),si(`invalid`,e);break;case`option`:o=i;break;case`select`:e._wrapperState={wasMultiple:!!i.multiple},o=L({},i,{value:void 0}),si(`invalid`,e);break;case`textarea`:Se(e,i),o=xe(e,i),si(`invalid`,e);break;default:o=i}for(s in Fe(n,o),l=o,l)if(l.hasOwnProperty(s)){var u=l[s];s===`style`?Ne(e,u):s===`dangerouslySetInnerHTML`?(u=u?u.__html:void 0,u!=null&&Oe(e,u)):s===`children`?typeof u==`string`?(n!==`textarea`||u!==``)&&ke(e,u):typeof u==`number`&&ke(e,``+u):s!==`suppressContentEditableWarning`&&s!==`suppressHydrationWarning`&&s!==`autoFocus`&&(a.hasOwnProperty(s)?u!=null&&s===`onScroll`&&si(`scroll`,e):u!=null&&S(e,s,u,c))}switch(n){case`input`:ue(e),_e(e,i,!1);break;case`textarea`:ue(e),we(e);break;case`option`:i.value!=null&&e.setAttribute(`value`,``+se(i.value));break;case`select`:e.multiple=!!i.multiple,s=i.value,s==null?i.defaultValue!=null&&be(e,!!i.multiple,i.defaultValue,!0):be(e,!!i.multiple,s,!1);break;default:typeof o.onClick==`function`&&(e.onclick=xi)}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 mc(t),null;case 6:if(e&&t.stateNode!=null)fc(e,t,e.memoizedProps,i);else{if(typeof i!=`string`&&t.stateNode===null)throw Error(r(166));if(n=go(ho.current),go(po.current),Ma(t)){if(i=t.stateNode,n=t.memoizedProps,i[Pi]=t,(s=i.nodeValue!==n)&&(e=Ca,e!==null))switch(e.tag){case 3:bi(i.nodeValue,n,!!(e.mode&1));break;case 5:!0!==e.memoizedProps.suppressHydrationWarning&&bi(i.nodeValue,n,!!(e.mode&1))}s&&(t.flags|=4)}else i=(n.nodeType===9?n:n.ownerDocument).createTextNode(i),i[Pi]=t,t.stateNode=i}return mc(t),null;case 13:if(Ki(xo),i=t.memoizedState,e===null||e.memoizedState!==null&&e.memoizedState.dehydrated!==null){if(Ta&&wa!==null&&t.mode&1&&!(t.flags&128))Na(),Pa(),t.flags|=98560,s=!1;else if(s=Ma(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[Pi]=t}else Pa(),!(t.flags&128)&&(t.memoizedState=null),t.flags|=4;mc(t),s=!1}else Ea!==null&&(Dl(Ea),Ea=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||xo.current&1?nl===0&&(nl=3):Ll())),t.updateQueue!==null&&(t.flags|=4),mc(t),null);case 4:return vo(),e===null&&ui(t.stateNode.containerInfo),mc(t),null;case 10:return Ja(t.type._context),mc(t),null;case 17:return Qi(t.type)&&$i(),mc(t),null;case 19:if(Ki(xo),s=t.memoizedState,s===null)return mc(t),null;if(i=!!(t.flags&128),c=s.rendering,c===null){if(i)pc(s,!1);else{if(nl!==0||e!==null&&e.flags&128)for(e=t.child;e!==null;){if(c=So(e),c!==null){for(t.flags|=128,pc(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 qi(xo,xo.current&1|2),t.child}e=e.sibling}s.tail!==null&&gt()>ll&&(t.flags|=128,i=!0,pc(s,!1),t.lanes=4194304)}}else{if(!i){if(e=So(c),e!==null){if(t.flags|=128,i=!0,n=e.updateQueue,n!==null&&(t.updateQueue=n,t.flags|=4),pc(s,!0),s.tail===null&&s.tailMode===`hidden`&&!c.alternate&&!Ta)return mc(t),null}else 2*gt()-s.renderingStartTime>ll&&n!==1073741824&&(t.flags|=128,i=!0,pc(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?(mc(t),null):(t=s.tail,s.rendering=t,s.tail=t.sibling,s.renderingStartTime=gt(),t.sibling=null,n=xo.current,qi(xo,i?n&1|2:n&1),t);case 22:case 23:return Nl(),i=t.memoizedState!==null,e!==null&&e.memoizedState!==null!==i&&(t.flags|=8192),i&&t.mode&1?el&1073741824&&(mc(t),t.subtreeFlags&6&&(t.flags|=8192)):mc(t),null;case 24:return null;case 25:return null}throw Error(r(156,t.tag))}function gc(e,t){switch(Sa(t),t.tag){case 1:return Qi(t.type)&&$i(),e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 3:return vo(),Ki(Yi),Ki(U),wo(),e=t.flags,e&65536&&!(e&128)?(t.flags=e&-65537|128,t):null;case 5:return bo(t),null;case 13:if(Ki(xo),e=t.memoizedState,e!==null&&e.dehydrated!==null){if(t.alternate===null)throw Error(r(340));Pa()}return e=t.flags,e&65536?(t.flags=e&-65537|128,t):null;case 19:return Ki(xo),null;case 4:return vo(),null;case 10:return Ja(t.type._context),null;case 22:case 23:return Nl(),null;case 24:return null;default:return null}}var _c=!1,vc=!1,yc=typeof WeakSet==`function`?WeakSet:Set,bc=null;function xc(e,t){var n=e.ref;if(n!==null){if(typeof n==`function`)try{n(null)}catch(n){ql(e,t,n)}else n.current=null}}function Sc(e,t,n){try{n()}catch(n){ql(e,t,n)}}var Cc=!1;function wc(e,t){if(Si=mn,e=Pr(),Fr(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(Ci={focusedElem:e,selectionRange:n},mn=!1,bc=t;bc!==null;)if(t=bc,e=t.child,t.subtreeFlags&1028&&e!==null)e.return=t,bc=e;else for(;bc!==null;){t=bc;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:Cs(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){ql(t,t.return,e)}if(e=t.sibling,e!==null){e.return=t.return,bc=e;break}bc=t.return}return h=Cc,Cc=!1,h}function Tc(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&&Sc(t,n,a)}i=i.next}while(i!==r)}}function Ec(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 Dc(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 Oc(e){var t=e.alternate;t!==null&&(e.alternate=null,Oc(t)),e.child=null,e.deletions=null,e.sibling=null,e.tag===5&&(t=e.stateNode,t!==null&&(delete t[Pi],delete t[Fi],delete t[Li],delete t[Ri],delete t[H])),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 kc(e){return e.tag===5||e.tag===3||e.tag===4}function Ac(e){a:for(;;){for(;e.sibling===null;){if(e.return===null||kc(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 jc(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=xi));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}function Mc(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(Mc(e,t,n),e=e.sibling;e!==null;)Mc(e,t,n),e=e.sibling}var Nc=null,Pc=!1;function Fc(e,t,n){for(n=n.child;n!==null;)Ic(e,t,n),n=n.sibling}function Ic(e,t,n){if(Ct&&typeof Ct.onCommitFiberUnmount==`function`)try{Ct.onCommitFiberUnmount(St,n)}catch{}switch(n.tag){case 5:vc||xc(n,t);case 6:var r=Nc,i=Pc;Nc=null,Fc(e,t,n),Nc=r,Pc=i,Nc!==null&&(Pc?(e=Nc,n=n.stateNode,e.nodeType===8?e.parentNode.removeChild(n):e.removeChild(n)):Nc.removeChild(n.stateNode));break;case 18:Nc!==null&&(Pc?(e=Nc,n=n.stateNode,e.nodeType===8?Ai(e.parentNode,n):e.nodeType===1&&Ai(e,n),fn(e)):Ai(Nc,n.stateNode));break;case 4:r=Nc,i=Pc,Nc=n.stateNode.containerInfo,Pc=!0,Fc(e,t,n),Nc=r,Pc=i;break;case 0:case 11:case 14:case 15:if(!vc&&(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)&&Sc(n,t,o),i=i.next}while(i!==r)}Fc(e,t,n);break;case 1:if(!vc&&(xc(n,t),r=n.stateNode,typeof r.componentWillUnmount==`function`))try{r.props=n.memoizedProps,r.state=n.memoizedState,r.componentWillUnmount()}catch(e){ql(n,t,e)}Fc(e,t,n);break;case 21:Fc(e,t,n);break;case 22:n.mode&1?(vc=(r=vc)||n.memoizedState!==null,Fc(e,t,n),vc=r):Fc(e,t,n);break;default:Fc(e,t,n)}}function Lc(e){var t=e.updateQueue;if(t!==null){e.updateQueue=null;var n=e.stateNode;n===null&&(n=e.stateNode=new yc),t.forEach(function(t){var r=Zl.bind(null,e,t);n.has(t)||(n.add(t),t.then(r,r))})}}function Rc(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:Nc=c.stateNode,Pc=!1;break a;case 3:Nc=c.stateNode.containerInfo,Pc=!0;break a;case 4:Nc=c.stateNode.containerInfo,Pc=!0;break a}c=c.return}if(Nc===null)throw Error(r(160));Ic(o,s,a),Nc=null,Pc=!1;var l=a.alternate;l!==null&&(l.return=null),a.return=null}catch(e){ql(a,t,e)}}if(t.subtreeFlags&12854)for(t=t.child;t!==null;)zc(t,e),t=t.sibling}function zc(e,t){var n=e.alternate,i=e.flags;switch(e.tag){case 0:case 11:case 14:case 15:if(Rc(t,e),Bc(e),i&4){try{Tc(3,e,e.return),Ec(3,e)}catch(t){ql(e,e.return,t)}try{Tc(5,e,e.return)}catch(t){ql(e,e.return,t)}}break;case 1:Rc(t,e),Bc(e),i&512&&n!==null&&xc(n,n.return);break;case 5:if(Rc(t,e),Bc(e),i&512&&n!==null&&xc(n,n.return),e.flags&32){var a=e.stateNode;try{ke(a,``)}catch(t){ql(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&&he(a,o),Ie(c,s);var u=Ie(c,o);for(s=0;s<l.length;s+=2){var d=l[s],f=l[s+1];d===`style`?Ne(a,f):d===`dangerouslySetInnerHTML`?Oe(a,f):d===`children`?ke(a,f):S(a,d,f,u)}switch(c){case`input`:ge(a,o);break;case`textarea`:Ce(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?be(a,!!o.multiple,o.multiple?[]:``,!1):be(a,!!o.multiple,o.defaultValue,!0)):be(a,!!o.multiple,m,!1)}a[Fi]=o}catch(t){ql(e,e.return,t)}}break;case 6:if(Rc(t,e),Bc(e),i&4){if(e.stateNode===null)throw Error(r(162));a=e.stateNode,o=e.memoizedProps;try{a.nodeValue=o}catch(t){ql(e,e.return,t)}}break;case 3:if(Rc(t,e),Bc(e),i&4&&n!==null&&n.memoizedState.isDehydrated)try{fn(t.containerInfo)}catch(t){ql(e,e.return,t)}break;case 4:Rc(t,e),Bc(e);break;case 13:Rc(t,e),Bc(e),a=e.child,a.flags&8192&&(o=a.memoizedState!==null,a.stateNode.isHidden=o,!o||a.alternate!==null&&a.alternate.memoizedState!==null||(W=gt())),i&4&&Lc(e);break;case 22:if(d=n!==null&&n.memoizedState!==null,e.mode&1?(vc=(u=vc)||d,Rc(t,e),vc=u):Rc(t,e),Bc(e),i&8192){if(u=e.memoizedState!==null,(e.stateNode.isHidden=u)&&!d&&e.mode&1)for(bc=e,d=e.child;d!==null;){for(f=bc=d;bc!==null;){switch(p=bc,m=p.child,p.tag){case 0:case 11:case 14:case 15:Tc(4,p,p.return);break;case 1:xc(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){ql(i,n,e)}}break;case 5:xc(p,p.return);break;case 22:if(p.memoizedState!==null){Wc(f);continue}}m===null?Wc(f):(m.return=p,bc=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=Me(`display`,s))}catch(t){ql(e,e.return,t)}}}else if(f.tag===6){if(d===null)try{f.stateNode.nodeValue=u?``:f.memoizedProps}catch(t){ql(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:Rc(t,e),Bc(e),i&4&&Lc(e);break;case 21:break;default:Rc(t,e),Bc(e)}}function Bc(e){var t=e.flags;if(t&2){try{a:{for(var n=e.return;n!==null;){if(kc(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&&(ke(a,``),i.flags&=-33),Mc(e,Ac(e),a);break;case 3:case 4:var o=i.stateNode.containerInfo;jc(e,Ac(e),o);break;default:throw Error(r(161))}}catch(t){ql(e,e.return,t)}e.flags&=-3}t&4096&&(e.flags&=-4097)}function Vc(e,t,n){bc=e,Hc(e,t,n)}function Hc(e,t,n){for(var r=!!(e.mode&1);bc!==null;){var i=bc,a=i.child;if(i.tag===22&&r){var o=i.memoizedState!==null||_c;if(!o){var s=i.alternate,c=s!==null&&s.memoizedState!==null||vc;s=_c;var l=vc;if(_c=o,(vc=c)&&!l)for(bc=i;bc!==null;)o=bc,c=o.child,o.tag===22&&o.memoizedState!==null||c===null?Gc(i):(c.return=o,bc=c);for(;a!==null;)bc=a,Hc(a,t,n),a=a.sibling;bc=i,_c=s,vc=l}Uc(e,t,n)}else i.subtreeFlags&8772&&a!==null?(a.return=i,bc=a):Uc(e,t,n)}}function Uc(e){for(;bc!==null;){var t=bc;if(t.flags&8772){var n=t.alternate;try{if(t.flags&8772)switch(t.tag){case 0:case 11:case 15:vc||Ec(5,t);break;case 1:var i=t.stateNode;if(t.flags&4&&!vc){if(n===null)i.componentDidMount();else{var a=t.elementType===t.type?n.memoizedProps:Cs(t.type,n.memoizedProps);i.componentDidUpdate(a,n.memoizedState,i.__reactInternalSnapshotBeforeUpdate)}}var o=t.updateQueue;o!==null&&uo(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}uo(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&&fn(f)}}}break;case 19:case 17:case 21:case 22:case 23:case 25:break;default:throw Error(r(163))}vc||t.flags&512&&Dc(t)}catch(e){ql(t,t.return,e)}}if(t===e){bc=null;break}if(n=t.sibling,n!==null){n.return=t.return,bc=n;break}bc=t.return}}function Wc(e){for(;bc!==null;){var t=bc;if(t===e){bc=null;break}var n=t.sibling;if(n!==null){n.return=t.return,bc=n;break}bc=t.return}}function Gc(e){for(;bc!==null;){var t=bc;try{switch(t.tag){case 0:case 11:case 15:var n=t.return;try{Ec(4,t)}catch(e){ql(t,n,e)}break;case 1:var r=t.stateNode;if(typeof r.componentDidMount==`function`){var i=t.return;try{r.componentDidMount()}catch(e){ql(t,i,e)}}var a=t.return;try{Dc(t)}catch(e){ql(t,a,e)}break;case 5:var o=t.return;try{Dc(t)}catch(e){ql(t,o,e)}}}catch(e){ql(t,t.return,e)}if(t===e){bc=null;break}var s=t.sibling;if(s!==null){s.return=t.return,bc=s;break}bc=t.return}}var Kc=Math.ceil,qc=C.ReactCurrentDispatcher,Jc=C.ReactCurrentOwner,Yc=C.ReactCurrentBatchConfig,Xc=0,Zc=null,Qc=null,$c=0,el=0,tl=Gi(0),nl=0,rl=null,il=0,al=0,ol=0,sl=null,cl=null,W=0,ll=1/0,ul=null,dl=!1,fl=null,pl=null,ml=!1,hl=null,gl=0,_l=0,vl=null,yl=-1,bl=0;function xl(){return Xc&6?gt():yl===-1?yl=gt():yl}function Sl(e){return e.mode&1?Xc&2&&$c!==0?$c&-$c:Ia.transition===null?(e=Vt,e===0?(e=window.event,e=e===void 0?16:bn(e.type),e):e):(bl===0&&(bl=It()),bl):1}function Cl(e,t,n,i){if(50<_l)throw _l=0,vl=null,Error(r(185));Rt(e,n,i),(!(Xc&2)||e!==Zc)&&(e===Zc&&(!(Xc&2)&&(al|=n),nl===4&&kl(e,$c)),wl(e,i),n===1&&Xc===0&&!(t.mode&1)&&(ll=gt()+500,aa&&la()))}function wl(e,t){var n=e.callbackNode;Pt(e,t);var r=Mt(e,e===Zc?$c:0);if(r===0)n!==null&&pt(n),e.callbackNode=null,e.callbackPriority=0;else if(t=r&-r,e.callbackPriority!==t){if(n!=null&&pt(n),t===1)e.tag===0?ca(Al.bind(null,e)):sa(Al.bind(null,e)),Oi(function(){!(Xc&6)&&la()}),n=null;else{switch(Ht(r)){case 1:n=B;break;case 4:n=vt;break;case 16:n=yt;break;case 536870912:n=xt;break;default:n=yt}n=$l(n,Tl.bind(null,e))}e.callbackPriority=t,e.callbackNode=n}}function Tl(e,t){if(yl=-1,bl=0,Xc&6)throw Error(r(327));var n=e.callbackNode;if(Gl()&&e.callbackNode!==n)return null;var i=Mt(e,e===Zc?$c:0);if(i===0)return null;if(i&30||(i&e.expiredLanes)!==0||t)t=Rl(e,i);else{t=i;var a=Xc;Xc|=2;var o=Il();(Zc!==e||$c!==t)&&(ul=null,ll=gt()+500,Pl(e,t));do try{Bl();break}catch(t){Fl(e,t)}while(1);qa(),qc.current=o,Xc=a,Qc===null?(Zc=null,$c=0,t=nl):t=0}if(t!==0){if(t===2&&(a=Ft(e),a!==0&&(i=a,t=El(e,a))),t===1)throw n=rl,Pl(e,0),kl(e,i),wl(e,gt()),n;if(t===6)kl(e,i);else{if(a=e.current.alternate,!(i&30)&&!Ol(a)&&(t=Rl(e,i),t===2&&(o=Ft(e),o!==0&&(i=o,t=El(e,o))),t===1))throw n=rl,Pl(e,0),kl(e,i),wl(e,gt()),n;switch(e.finishedWork=a,e.finishedLanes=i,t){case 0:case 1:throw Error(r(345));case 2:Ul(e,cl,ul);break;case 3:if(kl(e,i),(i&130023424)===i&&(t=W+500-gt(),10<t)){if(Mt(e,0)!==0)break;if(a=e.suspendedLanes,(a&i)!==i){xl(),e.pingedLanes|=e.suspendedLanes&a;break}e.timeoutHandle=Ti(Ul.bind(null,e,cl,ul),t);break}Ul(e,cl,ul);break;case 4:if(kl(e,i),(i&4194240)===i)break;for(t=e.eventTimes,a=-1;0<i;){var s=31-Tt(i);o=1<<s,s=t[s],s>a&&(a=s),i&=~o}if(i=a,i=gt()-i,i=(120>i?120:480>i?480:1080>i?1080:1920>i?1920:3e3>i?3e3:4320>i?4320:1960*Kc(i/1960))-i,10<i){e.timeoutHandle=Ti(Ul.bind(null,e,cl,ul),i);break}Ul(e,cl,ul);break;case 5:Ul(e,cl,ul);break;default:throw Error(r(329))}}}return wl(e,gt()),e.callbackNode===n?Tl.bind(null,e):null}function El(e,t){var n=sl;return e.current.memoizedState.isDehydrated&&(Pl(e,t).flags|=256),e=Rl(e,t),e!==2&&(t=cl,cl=n,t!==null&&Dl(t)),e}function Dl(e){cl===null?cl=e:cl.push.apply(cl,e)}function Ol(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(!kr(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 kl(e,t){for(t&=~ol,t&=~al,e.suspendedLanes|=t,e.pingedLanes&=~t,e=e.expirationTimes;0<t;){var n=31-Tt(t),r=1<<n;e[n]=-1,t&=~r}}function Al(e){if(Xc&6)throw Error(r(327));Gl();var t=Mt(e,0);if(!(t&1))return wl(e,gt()),null;var n=Rl(e,t);if(e.tag!==0&&n===2){var i=Ft(e);i!==0&&(t=i,n=El(e,i))}if(n===1)throw n=rl,Pl(e,0),kl(e,t),wl(e,gt()),n;if(n===6)throw Error(r(345));return e.finishedWork=e.current.alternate,e.finishedLanes=t,Ul(e,cl,ul),wl(e,gt()),null}function jl(e,t){var n=Xc;Xc|=1;try{return e(t)}finally{Xc=n,Xc===0&&(ll=gt()+500,aa&&la())}}function Ml(e){hl!==null&&hl.tag===0&&!(Xc&6)&&Gl();var t=Xc;Xc|=1;var n=Yc.transition,r=Vt;try{if(Yc.transition=null,Vt=1,e)return e()}finally{Vt=r,Yc.transition=n,Xc=t,!(Xc&6)&&la()}}function Nl(){el=tl.current,Ki(tl)}function Pl(e,t){e.finishedWork=null,e.finishedLanes=0;var n=e.timeoutHandle;if(n!==-1&&(e.timeoutHandle=-1,Ei(n)),Qc!==null)for(n=Qc.return;n!==null;){var r=n;switch(Sa(r),r.tag){case 1:r=r.type.childContextTypes,r!=null&&$i();break;case 3:vo(),Ki(Yi),Ki(U),wo();break;case 5:bo(r);break;case 4:vo();break;case 13:Ki(xo);break;case 19:Ki(xo);break;case 10:Ja(r.type._context);break;case 22:case 23:Nl()}n=n.return}if(Zc=e,Qc=e=iu(e.current,null),$c=el=t,nl=0,rl=null,ol=al=il=0,cl=sl=null,Qa!==null){for(t=0;t<Qa.length;t++)if(n=Qa[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}Qa=null}return e}function Fl(e,t){do{var n=Qc;try{if(qa(),To.current=ys,jo){for(var i=Oo.memoizedState;i!==null;){var a=i.queue;a!==null&&(a.pending=null),i=i.next}jo=!1}if(Do=0,Ao=ko=Oo=null,Mo=!1,No=0,Jc.current=null,n===null||n.return===null){nl=1,rl=t,Qc=null;break}a:{var o=e,s=n.return,c=n,l=t;if(t=$c,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=Ls(s);if(m!==null){m.flags&=-257,Rs(m,s,c,o,t),m.mode&1&&Is(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)){Is(o,u,t),Ll();break a}l=Error(r(426))}else if(Ta&&c.mode&1){var _=Ls(s);if(_!==null){!(_.flags&65536)&&(_.flags|=256),Rs(_,s,c,o,t),Fa(As(l,c));break a}}o=l=As(l,c),nl!==4&&(nl=2),sl===null?sl=[o]:sl.push(o),o=s;do{switch(o.tag){case 3:o.flags|=65536,t&=-t,o.lanes|=t;var v=Ps(o,l,t);co(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`&&(pl===null||!pl.has(b)))){o.flags|=65536,t&=-t,o.lanes|=t;var x=Fs(o,c,t);co(o,x);break a}}o=o.return}while(o!==null)}Hl(n)}catch(e){t=e,Qc===n&&n!==null&&(Qc=n=n.return);continue}break}while(1)}function Il(){var e=qc.current;return qc.current=ys,e===null?ys:e}function Ll(){(nl===0||nl===3||nl===2)&&(nl=4),Zc===null||!(il&268435455)&&!(al&268435455)||kl(Zc,$c)}function Rl(e,t){var n=Xc;Xc|=2;var i=Il();(Zc!==e||$c!==t)&&(ul=null,Pl(e,t));do try{zl();break}catch(t){Fl(e,t)}while(1);if(qa(),Xc=n,qc.current=i,Qc!==null)throw Error(r(261));return Zc=null,$c=0,nl}function zl(){for(;Qc!==null;)Vl(Qc)}function Bl(){for(;Qc!==null&&!mt();)Vl(Qc)}function Vl(e){var t=Ql(e.alternate,e,el);e.memoizedProps=e.pendingProps,t===null?Hl(e):Qc=t,Jc.current=null}function Hl(e){var t=e;do{var n=t.alternate;if(e=t.return,t.flags&32768){if(n=gc(n,t),n!==null){n.flags&=32767,Qc=n;return}if(e!==null)e.flags|=32768,e.subtreeFlags=0,e.deletions=null;else{nl=6,Qc=null;return}}else if(n=hc(n,t,el),n!==null){Qc=n;return}if(t=t.sibling,t!==null){Qc=t;return}Qc=t=e}while(t!==null);nl===0&&(nl=5)}function Ul(e,t,n){var r=Vt,i=Yc.transition;try{Yc.transition=null,Vt=1,Wl(e,t,n,r)}finally{Yc.transition=i,Vt=r}return null}function Wl(e,t,n,i){do Gl();while(hl!==null);if(Xc&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(zt(e,o),e===Zc&&(Qc=Zc=null,$c=0),!(n.subtreeFlags&2064)&&!(n.flags&2064)||ml||(ml=!0,$l(yt,function(){return Gl(),null})),o=!!(n.flags&15990),n.subtreeFlags&15990||o){o=Yc.transition,Yc.transition=null;var s=Vt;Vt=1;var c=Xc;Xc|=4,Jc.current=null,wc(e,n),zc(n,e),Ir(Ci),mn=!!Si,Ci=Si=null,e.current=n,Vc(n,e,a),ht(),Xc=c,Vt=s,Yc.transition=o}else e.current=n;if(ml&&(ml=!1,hl=e,gl=a),o=e.pendingLanes,o===0&&(pl=null),wt(n.stateNode,i),wl(e,gt()),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(dl)throw dl=!1,e=fl,fl=null,e;return gl&1&&e.tag!==0&&Gl(),o=e.pendingLanes,o&1?e===vl?_l++:(_l=0,vl=e):_l=0,la(),null}function Gl(){if(hl!==null){var e=Ht(gl),t=Yc.transition,n=Vt;try{if(Yc.transition=null,Vt=16>e?16:e,hl===null)var i=!1;else{if(e=hl,hl=null,gl=0,Xc&6)throw Error(r(331));var a=Xc;for(Xc|=4,bc=e.current;bc!==null;){var o=bc,s=o.child;if(bc.flags&16){var c=o.deletions;if(c!==null){for(var l=0;l<c.length;l++){var u=c[l];for(bc=u;bc!==null;){var d=bc;switch(d.tag){case 0:case 11:case 15:Tc(8,d,o)}var f=d.child;if(f!==null)f.return=d,bc=f;else for(;bc!==null;){d=bc;var p=d.sibling,m=d.return;if(Oc(d),d===u){bc=null;break}if(p!==null){p.return=m,bc=p;break}bc=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)}}bc=o}}if(o.subtreeFlags&2064&&s!==null)s.return=o,bc=s;else b:for(;bc!==null;){if(o=bc,o.flags&2048)switch(o.tag){case 0:case 11:case 15:Tc(9,o,o.return)}var v=o.sibling;if(v!==null){v.return=o.return,bc=v;break b}bc=o.return}}var y=e.current;for(bc=y;bc!==null;){s=bc;var b=s.child;if(s.subtreeFlags&2064&&b!==null)b.return=s,bc=b;else b:for(s=y;bc!==null;){if(c=bc,c.flags&2048)try{switch(c.tag){case 0:case 11:case 15:Ec(9,c)}}catch(e){ql(c,c.return,e)}if(c===s){bc=null;break b}var x=c.sibling;if(x!==null){x.return=c.return,bc=x;break b}bc=c.return}}if(Xc=a,la(),Ct&&typeof Ct.onPostCommitFiberRoot==`function`)try{Ct.onPostCommitFiberRoot(St,e)}catch{}i=!0}return i}finally{Vt=n,Yc.transition=t}}return!1}function Kl(e,t,n){t=As(n,t),t=Ps(e,t,1),e=oo(e,t,1),t=xl(),e!==null&&(Rt(e,1,t),wl(e,t))}function ql(e,t,n){if(e.tag===3)Kl(e,e,n);else for(;t!==null;){if(t.tag===3){Kl(t,e,n);break}if(t.tag===1){var r=t.stateNode;if(typeof t.type.getDerivedStateFromError==`function`||typeof r.componentDidCatch==`function`&&(pl===null||!pl.has(r))){e=As(n,e),e=Fs(t,e,1),t=oo(t,e,1),e=xl(),t!==null&&(Rt(t,1,e),wl(t,e));break}}t=t.return}}function Jl(e,t,n){var r=e.pingCache;r!==null&&r.delete(t),t=xl(),e.pingedLanes|=e.suspendedLanes&n,Zc===e&&($c&n)===n&&(nl===4||nl===3&&($c&130023424)===$c&&500>gt()-W?Pl(e,0):ol|=n),wl(e,t)}function Yl(e,t){t===0&&(e.mode&1?(t=At,At<<=1,!(At&130023424)&&(At=4194304)):t=1);var n=xl();e=to(e,t),e!==null&&(Rt(e,t,n),wl(e,n))}function Xl(e){var t=e.memoizedState,n=0;t!==null&&(n=t.retryLane),Yl(e,n)}function Zl(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),Yl(e,n)}var Ql=function(e,t,n){if(e!==null){if(e.memoizedProps!==t.pendingProps||Yi.current)Bs=!0;else{if((e.lanes&n)===0&&!(t.flags&128))return Bs=!1,lc(e,t,n);Bs=!!(e.flags&131072)}}else Bs=!1,Ta&&t.flags&1048576&&ba(t,pa,t.index);switch(t.lanes=0,t.tag){case 2:var i=t.type;sc(e,t),e=t.pendingProps;var a=Zi(t,U.current);Xa(t,n),a=Lo(null,t,i,e,a,n);var o=Ro();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,Qi(i)?(o=!0,na(t)):o=!1,t.memoizedState=a.state!==null&&a.state!==void 0?a.state:null,ro(t),a.updater=Ts,t.stateNode=a,a._reactInternals=t,ks(t,i,e,n),t=Ys(null,t,i,!0,o,n)):(t.tag=0,Ta&&o&&xa(t),Vs(null,t,a,n),t=t.child),t;case 16:i=t.elementType;a:{switch(sc(e,t),e=t.pendingProps,a=i._init,i=a(i._payload),t.type=i,a=t.tag=ru(i),e=Cs(i,e),a){case 0:t=qs(null,t,i,e,n);break a;case 1:t=Js(null,t,i,e,n);break a;case 11:t=Hs(null,t,i,e,n);break a;case 14:t=Us(null,t,i,Cs(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:Cs(i,a),qs(e,t,i,a,n);case 1:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Cs(i,a),Js(e,t,i,a,n);case 3:a:{if(Xs(t),e===null)throw Error(r(387));i=t.pendingProps,o=t.memoizedState,a=o.element,io(e,t),lo(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=As(Error(r(423)),t),t=Zs(e,t,i,n,a);break a}if(i!==a){a=As(Error(r(424)),t),t=Zs(e,t,i,n,a);break a}for(wa=ji(t.stateNode.containerInfo.firstChild),Ca=t,Ta=!0,Ea=null,n=Ha(t,null,i,n),t.child=n;n;)n.flags=n.flags&-3|4096,n=n.sibling}else{if(Pa(),i===a){t=cc(e,t,n);break a}Vs(e,t,i,n)}t=t.child}return t;case 5:return yo(t),e===null&&Aa(t),i=t.type,a=t.pendingProps,o=e===null?null:e.memoizedProps,s=a.children,wi(i,a)?s=null:o!==null&&wi(i,o)&&(t.flags|=32),Ks(e,t),Vs(e,t,s,n),t.child;case 6:return e===null&&Aa(t),null;case 13:return ec(e,t,n);case 4:return _o(t,t.stateNode.containerInfo),i=t.pendingProps,e===null?t.child=Va(t,null,i,n):Vs(e,t,i,n),t.child;case 11:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Cs(i,a),Hs(e,t,i,a,n);case 7:return Vs(e,t,t.pendingProps,n),t.child;case 8:return Vs(e,t,t.pendingProps.children,n),t.child;case 12:return Vs(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,qi(Ua,i._currentValue),i._currentValue=s,o!==null){if(kr(o.value,s)){if(o.children===a.children&&!Yi.current){t=cc(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=ao(-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),Ya(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),Ya(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}}Vs(e,t,a.children,n),t=t.child}return t;case 9:return a=t.type,i=t.pendingProps.children,Xa(t,n),a=Za(a),i=i(a),t.flags|=1,Vs(e,t,i,n),t.child;case 14:return i=t.type,a=Cs(i,t.pendingProps),a=Cs(i.type,a),Us(e,t,i,a,n);case 15:return Ws(e,t,t.type,t.pendingProps,n);case 17:return i=t.type,a=t.pendingProps,a=t.elementType===i?a:Cs(i,a),sc(e,t),t.tag=1,Qi(i)?(e=!0,na(t)):e=!1,Xa(t,n),Ds(t,i,a),ks(t,i,a,n),Ys(null,t,i,!0,e,n);case 19:return oc(e,t,n);case 22:return Gs(e,t,n)}throw Error(r(156,t.tag))};function $l(e,t){return ft(e,t)}function eu(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 tu(e,t,n,r){return new eu(e,t,n,r)}function nu(e){return e=e.prototype,!(!e||!e.isReactComponent)}function ru(e){if(typeof e==`function`)return+!!nu(e);if(e!=null){if(e=e.$$typeof,e===j)return 11;if(e===P)return 14}return 2}function iu(e,t){var n=e.alternate;return n===null?(n=tu(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 au(e,t,n,i,a,o){var s=2;if(i=e,typeof e==`function`)nu(e)&&(s=1);else if(typeof e==`string`)s=5;else a:switch(e){case E:return ou(n.children,a,o,t);case D:s=8,a|=8;break;case O:return e=tu(12,n,t,a|2),e.elementType=O,e.lanes=o,e;case M:return e=tu(13,n,t,a),e.elementType=M,e.lanes=o,e;case N:return e=tu(19,n,t,a),e.elementType=N,e.lanes=o,e;case I:return su(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=tu(s,n,t,a),t.elementType=e,t.type=i,t.lanes=o,t}function ou(e,t,n,r){return e=tu(7,e,r,t),e.lanes=n,e}function su(e,t,n,r){return e=tu(22,e,r,t),e.elementType=I,e.lanes=n,e.stateNode={isHidden:!1},e}function cu(e,t,n){return e=tu(6,e,null,t),e.lanes=n,e}function lu(e,t,n){return t=tu(4,e.children===null?[]:e.children,e.key,t),t.lanes=n,t.stateNode={containerInfo:e.containerInfo,pendingChildren:null,implementation:e.implementation},t}function uu(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=Lt(0),this.expirationTimes=Lt(-1),this.entangledLanes=this.finishedLanes=this.mutableReadLanes=this.expiredLanes=this.pingedLanes=this.suspendedLanes=this.pendingLanes=0,this.entanglements=Lt(0),this.identifierPrefix=r,this.onRecoverableError=i,this.mutableSourceEagerHydrationData=null}function du(e,t,n,r,i,a,o,s,c){return e=new uu(e,t,n,s,c),t===1?(t=1,!0===a&&(t|=8)):t=0,a=tu(3,null,null,t),e.current=a,a.stateNode=e,a.memoizedState={element:r,isDehydrated:n,cache:null,transitions:null,pendingSuspenseBoundaries:null},ro(a),e}function fu(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 pu(e){if(!e)return Ji;e=e._reactInternals;a:{if(ot(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(Qi(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(Qi(n))return ta(e,n,t)}return t}function mu(e,t,n,r,i,a,o,s,c){return e=du(n,r,!0,e,i,a,o,s,c),e.context=pu(null),n=e.current,r=xl(),i=Sl(n),a=ao(r,i),a.callback=t??null,oo(n,a,i),e.current.lanes=i,Rt(e,i,r),wl(e,r),e}function hu(e,t,n,r){var i=t.current,a=xl(),o=Sl(i);return n=pu(n),t.context===null?t.context=n:t.pendingContext=n,t=ao(a,o),t.payload={element:e},r=r===void 0?null:r,r!==null&&(t.callback=r),e=oo(i,t,o),e!==null&&(Cl(e,i,o,a),so(e,i,o)),o}function gu(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 _u(e,t){if(e=e.memoizedState,e!==null&&e.dehydrated!==null){var n=e.retryLane;e.retryLane=n!==0&&n<t?n:t}}function G(e,t){_u(e,t),(e=e.alternate)&&_u(e,t)}function vu(){return null}var yu=typeof reportError==`function`?reportError:function(e){console.error(e)};function bu(e){this._internalRoot=e}xu.prototype.render=bu.prototype.render=function(e){var t=this._internalRoot;if(t===null)throw Error(r(409));hu(e,t,null,null)},xu.prototype.unmount=bu.prototype.unmount=function(){var e=this._internalRoot;if(e!==null){this._internalRoot=null;var t=e.containerInfo;Ml(function(){hu(null,e,null,null)}),t[Ii]=null}};function xu(e){this._internalRoot=e}xu.prototype.unstable_scheduleHydration=function(e){if(e){var t=Kt();e={blockedOn:null,target:e,priority:t};for(var n=0;n<tn.length&&t!==0&&t<tn[n].priority;n++);tn.splice(n,0,e),n===0&&sn(e)}};function Su(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11)}function Cu(e){return!(!e||e.nodeType!==1&&e.nodeType!==9&&e.nodeType!==11&&(e.nodeType!==8||e.nodeValue!==` react-mount-point-unstable `))}function wu(){}function Tu(e,t,n,r,i){if(i){if(typeof r==`function`){var a=r;r=function(){var e=gu(o);a.call(e)}}var o=mu(t,r,e,0,null,!1,!1,``,wu);return e._reactRootContainer=o,e[Ii]=o.current,ui(e.nodeType===8?e.parentNode:e),Ml(),o}for(;i=e.lastChild;)e.removeChild(i);if(typeof r==`function`){var s=r;r=function(){var e=gu(c);s.call(e)}}var c=du(e,0,!1,null,null,!1,!1,``,wu);return e._reactRootContainer=c,e[Ii]=c.current,ui(e.nodeType===8?e.parentNode:e),Ml(function(){hu(t,c,n,r)}),c}function Eu(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=gu(o);s.call(e)}}hu(t,o,e,i)}else o=Tu(n,t,e,i,r);return gu(o)}Ut=function(e){switch(e.tag){case 3:var t=e.stateNode;if(t.current.memoizedState.isDehydrated){var n=jt(t.pendingLanes);n!==0&&(Bt(t,n|1),wl(t,gt()),!(Xc&6)&&(ll=gt()+500,la()))}break;case 13:Ml(function(){var t=to(e,1);t!==null&&Cl(t,e,1,xl())}),G(e,1)}},Wt=function(e){if(e.tag===13){var t=to(e,134217728);t!==null&&Cl(t,e,134217728,xl()),G(e,134217728)}},Gt=function(e){if(e.tag===13){var t=Sl(e),n=to(e,t);n!==null&&Cl(n,e,t,xl()),G(e,t)}},Kt=function(){return Vt},qt=function(e,t){var n=Vt;try{return Vt=e,t()}finally{Vt=n}},ze=function(e,t,n){switch(t){case`input`:if(ge(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=Hi(i);if(!a)throw Error(r(90));de(i),ge(i,a)}}}break;case`textarea`:Ce(e,n);break;case`select`:t=n.value,t!=null&&be(e,!!n.multiple,t,!1)}},Ge=jl,Ke=Ml;var Du={usingClientEntryPoint:!1,Events:[Bi,Vi,Hi,Ue,We,jl]},Ou={findFiberByHostInstance:zi,bundleType:0,version:`18.3.1`,rendererPackageName:`react-dom`},ku={bundleType:Ou.bundleType,version:Ou.version,rendererPackageName:Ou.rendererPackageName,rendererConfig:Ou.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=ut(e),e===null?null:e.stateNode},findFiberByHostInstance:Ou.findFiberByHostInstance||vu,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 Au=__REACT_DEVTOOLS_GLOBAL_HOOK__;if(!Au.isDisabled&&Au.supportsFiber)try{St=Au.inject(ku),Ct=Au}catch{}}e.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED=Du,e.createPortal=function(e,t){var n=2<arguments.length&&arguments[2]!==void 0?arguments[2]:null;if(!Su(t))throw Error(r(200));return fu(e,t,null,n)},e.createRoot=function(e,t){if(!Su(e))throw Error(r(299));var n=!1,i=``,a=yu;return t!=null&&(!0===t.unstable_strictMode&&(n=!0),t.identifierPrefix!==void 0&&(i=t.identifierPrefix),t.onRecoverableError!==void 0&&(a=t.onRecoverableError)),t=du(e,1,!1,null,null,n,!1,i,a),e[Ii]=t.current,ui(e.nodeType===8?e.parentNode:e),new bu(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=ut(t),e=e===null?null:e.stateNode,e},e.flushSync=function(e){return Ml(e)},e.hydrate=function(e,t,n){if(!Cu(t))throw Error(r(200));return Eu(null,e,t,!0,n)},e.hydrateRoot=function(e,t,n){if(!Su(e))throw Error(r(405));var i=n!=null&&n.hydratedSources||null,a=!1,o=``,s=yu;if(n!=null&&(!0===n.unstable_strictMode&&(a=!0),n.identifierPrefix!==void 0&&(o=n.identifierPrefix),n.onRecoverableError!==void 0&&(s=n.onRecoverableError)),t=mu(t,null,e,1,n??null,a,!1,o,s),e[Ii]=t.current,ui(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 xu(t)},e.render=function(e,t,n){if(!Cu(t))throw Error(r(200));return Eu(null,e,t,!1,n)},e.unmountComponentAtNode=function(e){if(!Cu(e))throw Error(r(40));return e._reactRootContainer?(Ml(function(){Eu(null,null,e,!1,function(){e._reactRootContainer=null,e[Ii]=null})}),!0):!1},e.unstable_batchedUpdates=jl,e.unstable_renderSubtreeIntoContainer=function(e,t,n,i){if(!Cu(n))throw Error(r(200));if(e==null||e._reactInternals===void 0)throw Error(r(38));return Eu(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 B(O.includes(e),`SHARED_WORK_OPERATION`,`Choose a declared shared-work operation.`),mt(t),B(vt(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((()=>{Tt(),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||!ee(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`&&(ee(r.path)||e.format===`zip`&&te(r.path)))return n+=new TextEncoder().encode(r.text).length,n<=N.textBytes;if(e.format!==`zip`||!F(r,[`path`,`source`])||!L(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,ee,te,L,R=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)),ee=e=>/\.(?:txt|md|json|csv|xml|fcpxml|srt|vtt)$/i.test(e),te=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),L=e=>/\.(?:png|jpe?g|webp|gif|mp4|webm|mov|mp3|wav|ogg|m4a|flac|bin)$/i.test(e)}));function ne(e,t,n){if(!e)throw new re(t,n)}function z(e){return!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e))}var re,ie=o((()=>{re=class extends Error{constructor(e,t,n=[]){super(t),this.name=`BlockError`,this.code=e,this.details=n}}}));function ae(){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 oe,se,ce,le=o((()=>{({semanticSchemaValid:oe,schemaMatches:se}=ae()),Object.freeze([`upstream`,`project`,`adapter`,`chat`,`default`,`user`,`external`]),ce=Object.freeze([`key`,`semantic`,`accepts`,`schema`,`sources`,`sensitivity`,`freshnessPolicy`,`cardinality`,`batchable`])})),ue,de=o((()=>{ue=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(ue.map(e=>[e.name,e.parents]))})),fe=o((()=>{le()})),pe=o((()=>{Object.freeze(new Set(`sm.ai-decide@1.0.0,sm.ai-write@1.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.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@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.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@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.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@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.when@1.0.0,sm.when@1.1.0,sm.write-summary@1.0.0,stillmade.generate@1.0.0`.split(`,`)))}));function me(e){return ve(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<=ge}function he(e){return ve(e,[`schemaVersion`,`decision`])&&e.schemaVersion===2&&[`accepted`,`rejected`,`deferred`].includes(e.decision)}var ge,_e,ve,ye=o((()=>{ge=2**53-1,_e=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),ve=(e,t)=>_e(e)&&Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t))})),be=o((()=>{Tt()})),xe=o((()=>{Tt(),be(),Object.freeze({routes:16,operations:64,keyLength:80,declarationBytes:65536})})),Se,Ce=o((()=>{Se=`(0|[1-9][0-9]{0,5})\\.(0|[1-9][0-9]{0,5})\\.(0|[1-9][0-9]{0,5})`,RegExp(`^`+Se+`$`),RegExp(`^(>=|<=|>|<|=)?`+Se+`$`)}));function we(e){return Te(e)&&Object.keys(e).length===5&&e.schemaVersion===1&&typeof e.title==`string`&&e.title.trim().length>0&&e.title.length<=200&&Ee.includes(e.field)&&Te(e.before)&&e.before.schemaVersion===1&&Te(e.after)&&e.after.schemaVersion===1}var Te,Ee,De=o((()=>{Te=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ee=Object.freeze([`blueprint`,`shotPlan`,`panels`,`board`,`canvas`,`animation`,`editor`])}));function Oe(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=ke.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 ke,Ae=o((()=>{ke=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 je(e){if(!Me(e)||e.schemaVersion!==1||!Ne(e.title)||!Ne(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(!Me(e)||![`clips`,`audioItems`,`captions`].includes(e.collection)||!Me(e.values)||!Ie(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!Ne(i)||t.has(a)?!1:(t.add(a),e.collection===`captions`?r?e.before===null&&He(n)&&Ne(n.trackId)&&ze(n):!Me(e.before)||!ze(e.before)?!1:e.operation===`caption.update`?Ie(n,[`text`,`start`,`end`])&&ze(n):e.operation===`remove`&&Ie(n,[]):!Object.hasOwn(Fe,e.operation)||!Me(e.before)||!Pe(e.before.start,0,86400)||!Pe(e.before.duration,.001,86400)||!Ie(n,Fe[e.operation])?!1:e.operation===`transition`?e.collection===`clips`&&Oe(n):e.operation===`grade`?e.collection===`clips`&&Re(n):e.operation===`split`?Pe(n.at,0,86400)&&Ne(n.newId)&&n.newId!==e.before.id:e.operation===`move`?Pe(n.start,0,86400):e.operation===`trim`?Pe(n.trimStart,0,86400)&&Pe(n.duration,.001,86400):e.operation===`volume`?Pe(n.volume,0,200):e.operation!==`mute`||typeof n.muted==`boolean`)})}var Me,Ne,Pe,Fe,Ie,Le,Re,ze,Be,Ve,He,Ue=o((()=>{Ae(),Me=e=>typeof e==`object`&&!!e&&!Array.isArray(e),Ne=e=>typeof e==`string`&&e.length>0&&e.length<=200,Pe=(e,t,n)=>Number.isFinite(e)&&e>=t&&e<=n,Fe={move:[`start`],trim:[`trimStart`,`duration`],volume:[`volume`],mute:[`muted`],remove:[],split:[`at`,`newId`],grade:[`lut`,`color`],transition:[`type`,`duration`,`soundOn`,`soundId`]},Ie=(e,t)=>Object.keys(e).length===t.length&&t.every(t=>Object.hasOwn(e,t)),Le={brightness:[-100,100],contrast:[-100,100],saturation:[-100,100],temperature:[-100,100],sharpness:[-50,50],vignette:[0,100]},Re=e=>[`None`,`Cold`,`Warm`,`Desaturated`,`High Contrast`,`Filmic`,`Teal and Orange`].includes(e.lut)&&Me(e.color)&&Ie(e.color,Object.keys(Le))&&Object.entries(Le).every(([t,[n,r]])=>Pe(e.color[t],n,r)),ze=e=>typeof e.text==`string`&&e.text.trim().length>0&&e.text.length<=5e3&&Pe(e.start,0,86400)&&Pe(e.end,0,86400)&&e.end-e.start>=.001,Be=[`id`,`trackId`,`text`,`start`,`end`],Ve={font:e=>e===`Hanken Grotesk`,size:e=>Pe(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=>Pe(e,0,100),backgroundPadding:e=>Pe(e,0,100),backgroundRadius:e=>Pe(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)},He=e=>!Be.every(t=>Object.hasOwn(e,t))||Object.keys(e).some(e=>!Be.includes(e)&&e!==`words`&&!Object.hasOwn(Ve,e))||!Object.entries(Ve).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)=>Me(t)&&Ie(t,[`text`,`start`,`end`])&&typeof t.text==`string`&&t.text.trim().length>0&&t.text.length<=5e3&&Pe(t.start,e.start,e.end)&&Pe(t.end,t.start,e.end)&&(n===0||t.start>=e.words[n-1].start))})),We,Ge=o((()=>{We=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`])})),Ke=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 qe(e){return et(e)&&e.kind===`file`&&nt(e.assetId,512)&&nt(e.versionId,512)&&at.includes(e.mimeType)&&(e.url===void 0||nt(e.url,32768))&&(e.name===void 0||nt(e.name,rt.fileName))&&(e.bytes===void 0||Number.isSafeInteger(e.bytes)&&e.bytes>=0)}function Je(e){return et(e)&&Object.keys(e).every(e=>[`schemaVersion`,`format`,`text`,`title`].includes(e))&&e.schemaVersion===1&&ot.includes(e.format)&&typeof e.text==`string`&&e.text.length<=rt.documentText&&(e.title===void 0||typeof e.title==`string`&&e.title.length<=rt.documentTitle)}function Ye(e){if(!et(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>rt.tableColumns||!Array.isArray(n)||n.length>rt.tableRows||!t.every(e=>typeof e==`string`&&e.trim().length>0&&e.length<=rt.columnName&&!tt.has(e))||new Set(t).size!==t.length)return!1;let r=new Set(t),i=0;for(let e of n){if(!et(e))return!1;for(let[t,n]of Object.entries(e))if(!r.has(t)||!st(n)||++i>rt.tableCells)return!1}return!0}function Xe(e){if(typeof e!=`string`||!e.length||e.length>rt.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 Ze(e){let t=typeof e==`string`?ct.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 Qe(e){return typeof e==`string`&&/^#[0-9a-fA-F]{6}(?:[0-9a-fA-F]{2})?$/.test(e)}function $e(e){if(!Ye(e))throw Error(`Choose a valid table.`);return[e.columns.map(lt).join(`,`),...e.rows.map(t=>e.columns.map(e=>lt(t[e])).join(`,`))].join(`\r
9
- `)}var et,tt,nt,rt,it,at,ot,st,ct,lt,ut=o((()=>{et=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),tt=new Set([`__proto__`,`prototype`,`constructor`]),nt=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,rt=Object.freeze({fileName:255,documentText:1e6,documentTitle:300,tableColumns:500,tableRows:1e5,tableCells:5e5,columnName:160,cellText:1e5,url:8192}),it=Object.freeze({pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`}),at=Object.freeze([...new Set(Object.values(it))]),ot=Object.freeze([`markdown`,`plain`]),st=e=>e===null||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)||typeof e==`string`&&e.length<=rt.cellText,ct=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/,lt=e=>{let t=e==null?``:String(e);return/[",\r\n]/.test(t)?`"${t.replaceAll(`"`,`""`)}"`:t}})),dt=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})})),ft=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`])})),pt=o((()=>{Object.freeze({features:24,id:48,label:40,does:160,asks:8,ask:80})}));function mt(e,t=0,n={nodes:0}){if(B(t<=40&&++n.nodes<=5e5,`LIMIT`,`Document exceeds complexity limit`),!(e===null||[`string`,`boolean`].includes(typeof e))){if(typeof e==`number`){B(Number.isFinite(e),`SCHEMA`,`Numbers must be finite`);return}B(Array.isArray(e)||vt(e),`SCHEMA`,`Only JSON data is accepted`);for(let[r,i]of Object.entries(e))B(!wt.has(r),`SCHEMA`,`Forbidden field: ${r}`),mt(i,t+1,n)}}function ht(e){mt(e);let t=e=>Array.isArray(e)?e.map(t):vt(e)?Object.fromEntries(Object.keys(e).sort().map(n=>[n,t(e[n])])):e;return JSON.stringify(t(e))}async function gt(e){let t=new TextEncoder().encode(ht(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 _t(e,t){if(typeof t==`object`&&t&&t.schema!=null&&!se(e,t.schema))return!1;let n=typeof t==`string`?t:t.type;if(n===`object`)try{return mt(e),vt(e)}catch{return!1}if(n?.endsWith(`[]`))return Array.isArray(e)&&e.every(e=>_t(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 Xe(e);if(n===`date`)return Ze(e);if(n===`color`)return Qe(e);if(n===`file`)return qe(e);if(n===`document`)return Je(e);if(n===`table`)try{return mt(e),Ye(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 mt(e),M(e)}catch{return!1}if(n===`workspace-edit`)try{return mt(e),we(e)}catch{return!1}if(n===`timeline-edit`)try{return mt(e),je(e)}catch{return!1}if(n===`timeline-range`||n===`approval`)return vt(e)&&e.schemaVersion===1?!0:n===`timeline-range`?me(e):he(e);if(n===`json`)try{return mt(e),!0}catch{return!1}return n===`image`&&vt(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)?vt(e)&&typeof e.assetId==`string`&&typeof e.versionId==`string`&&(n===`asset`||e.kind===n):yt.includes(n)&&vt(e)&&e.schemaVersion===1}var B,vt,yt,bt,xt,St,Ct,wt,Tt=o((()=>{k(),R(),ie(),le(),de(),fe(),pe(),ye(),xe(),Ce(),De(),Ue(),Ge(),Ke(),ut(),dt(),ft(),pt(),B=ne,vt=z,Object.freeze([`type`,`required`,`default`,`min`,`max`,`description`,`role`,`primary`,`context`,`imageMode`,...ce]),yt=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`,`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`]}),bt=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`}),xt=(e,t,n,r)=>Object.freeze({executor:e,mode:t,byok:n,summary:r}),St=Object.freeze({"text.generate":xt(`capability-run`,`sync`,!0,`Exact model, account BYOK or credits, and explicit run review`),"audio.speech":xt(`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":xt(`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":xt(`capability-run`,`sync`,!1,`One prompt to generated music (5–240 seconds) with StillMade credits and playback review`),"audio.sfx":xt(`capability-run`,`sync`,!1,`One prompt to a generated sound effect (0.5–22 seconds) with StillMade credits and playback review`),"image.generate":xt(`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":xt(`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":xt(`capability-run`,`sync`,!0,`One to four owned images to bounded production notes; host-selected model/payment and actual description review`),"media.analyze":xt(`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":xt(`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":xt(`capability-run`,`sync`,!1,`One topic searched on the web and summarized with cited sources, with StillMade credits`),"timeline.propose":xt(`capability-run`,`sync`,!0,`Bounded typed context to strict timeline-edit JSON; host-selected model/payment, stale-before checks, preview and Apply`),"workspace.propose":xt(`capability-run`,`sync`,!0,`Bounded typed context to a strict workspace-edit proposal for one permitted workspace; preview and explicit Apply`),"connection.execute":xt(`connection`,`sync`,!1,`One reviewed action on a connected third-party app account through the host connection service; the Block never receives account credentials`)}),Ct=e=>Object.freeze(Object.entries(St).filter(([,t])=>e(t)).map(([e])=>e)),Ct(()=>!0),Ct(e=>e.executor===`capability-run`),Ct(e=>e.executor===`capability-run`&&e.mode===`sync`),Ct(e=>e.byok),[...Object.keys(bt).map(e=>`context.${e}.read`)],wt=new Set([`__proto__`,`prototype`,`constructor`])}));Tt();var Et=Object.freeze([`tasks`,`preview-task`,`apply-task`]);function Dt(e,t={}){return B(Et.includes(e),`CONNECTION_TASK`,`Choose a declared task operation.`),mt(t),B(vt(t)&&JSON.stringify(t).length<=32768,`CONNECTION_TASK`,`Use bounded task selection arguments.`),{operation:e,args:structuredClone(t)}}function Ot(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 kt(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 At(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 e(s.kind,s.value)}).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){let c,l;try{if(![`image`,`media`].includes(e)||!s||Array.isArray(s)||typeof s!=`object`||(c=JSON.stringify(s),l=new TextEncoder().encode(c).length,l>4194304))throw Error(`Expected a bounded preview value`)}catch(e){return Promise.reject(e)}if(e===`image`&&a.has(c))return Promise.resolve(a.get(c));let u=e===`image`&&[n,...r].find(t=>t?.kind===e&&t.serialized===c);if(u)return u.promise;if(r.length+ +!!n>=16||i+l>8388608)return Promise.reject(Error(`Too many queued previews. Wait for a preview to finish.`));let d={kind:e,value:JSON.parse(c),serialized:c,bytes:l,generation:t};return d.promise=new Promise((e,t)=>{d.resolve=e,d.reject=t}),i+=l,r.push(d),o(),d.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 jt(){return null}function Mt(){try{return typeof indexedDB<`u`&&indexedDB!==null}catch{return!1}}function Nt(){return Vt||(Vt=new Promise((e,t)=>{let n;try{n=indexedDB.open(Ft,It)}catch(e){t(e);return}n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(`cacheMeta`)||e.createObjectStore(Lt,{keyPath:`key`}),e.objectStoreNames.contains(`blobs`)||e.createObjectStore(Rt),e.objectStoreNames.contains(`handles`)||e.createObjectStore(zt),e.objectStoreNames.contains(`deviceMedia`)||e.createObjectStore(Bt,{keyPath:`id`})},n.onsuccess=()=>{let t=n.result;t.onversionchange=()=>{t.close(),Vt=null},e(t)},n.onerror=()=>t(n.error||Error(`indexedDB open failed`)),n.onblocked=()=>t(Error(`indexedDB blocked`))}),Vt.catch(()=>{Vt=null}),Vt)}function Pt(e,t,n){return Nt().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 Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt,Kt=o((()=>{Ft=`aivw_editor`,It=2,Lt=`cacheMeta`,Rt=`blobs`,zt=`handles`,Bt=`deviceMedia`,Vt=null,Ht=(e,t)=>Pt(e,`readonly`,e=>e.get(t)),Ut=e=>Pt(e,`readonly`,e=>e.getAll()),Wt=(e,t,n)=>Pt(e,`readwrite`,e=>n===void 0?e.put(t):e.put(t,n)),Gt=(e,t)=>Pt(e,`readwrite`,e=>e.delete(t))}));function qt(){try{return typeof localStorage>`u`?null:JSON.parse(localStorage.getItem(Jt)||`null`)?.user?.id||null}catch{return null}}var Jt,Yt=o((()=>{Jt=`ai-video-workflow-auth`}));function Xt(){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=$t(t[e-15],7)^$t(t[e-15],18)^t[e-15]>>>3,r=$t(t[e-2],17)^$t(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=$t(c,6)^$t(c,11)^$t(c,25),r=c&l^~c&u,f=d+n+r+Qt[e]+t[e]>>>0,p=($t(i,2)^$t(i,13)^$t(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 Zt(e,{subtleLimit:t=en,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=Xt();for(let t=0;t<e.size;t+=tn)n?.throwIfAborted?.(),r.update(new Uint8Array(await e.slice(t,t+tn).arrayBuffer()));return r.digest()}var Qt,$t,en,tn,nn=o((()=>{Qt=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]),$t=(e,t)=>e>>>t|e<<32-t,en=67108864,tn=8388608}));function rn(){if(Pn!==void 0)return Pn;try{return qt()||null}catch{return null}}async function an(){if(Mn!==void 0)return Mn;try{Mn=navigator?.storage?.getDirectory?await(await navigator.storage.getDirectory()).getDirectoryHandle(bn,{create:!0}):null}catch{Mn=null}return Mn}async function on(){if(!Nn){Nn=!0;try{await navigator?.storage?.persist?.()}catch{}}}async function sn(e,t){let n=await an();if(n){let r=await(await n.getFileHandle(t,{create:!0})).createWritable();return await r.write(e),await r.close(),`opfs`}return await Wt(Rt,e,`device:${t}`),`idb`}function cn(){try{window.dispatchEvent(new CustomEvent(jn,{detail:{needed:An.size}}))}catch{}}async function ln(e){let t=zn(e);if(typeof t?.getFile!=`function`)throw Rn(`DEVICE_MEDIA_MOVED`,`This file is no longer linked on this computer.`);if(typeof t.queryPermission==`function`&&await t.queryPermission({mode:`read`})!==`granted`)throw An.has(e.id)||(An.set(e.id,t),cn()),Rn(`DEVICE_MEDIA_ACCESS`,`Allow StillMade to open this file on your computer again.`);let n;try{n=await t.getFile()}catch{throw Rn(`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 Rn(`DEVICE_MEDIA_CHANGED`,`This file changed on this computer after it was added.`);return n}async function un(e){if(e.storage===`linked`)return ln(e);if(e.storage===`opfs`){let t=await an();if(!t)throw Error(`Device storage is unavailable.`);return(await t.getFileHandle(e.versionId)).getFile()}let t=await Ht(Rt,`device:${e.versionId}`);if(!t)throw Error(`This media is not on this device.`);return t}function dn(){return Mt()&&typeof crypto?.subtle?.digest==`function`}async function fn(e,{kind:t,metadata:n={},role:r=`original`,links:i={},assetId:a=crypto.randomUUID(),signal:o,maxBytes:s=xn,handle:c=null}={}){if(!dn())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 on();let l=await In(e,o);o?.throwIfAborted?.();let u=await Ut(Bt).then(e=>e.find(e=>e.versionId===l&&e.kind===t)).catch(()=>null),d=c?`linked`:[`opfs`,`idb`].includes(u?.storage)?u.storage:await sn(e,l);o?.throwIfAborted?.(),c&&kn.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,...Bn(n,[`width`,`height`,`duration`]),storage:d,...c?{handle:c,lastModified:e.lastModified}:{},source:`local`,...i,...rn()?{owner:rn()}:{},cloud:{},createdAt:Date.now()};return await Wt(Bt,f),f}async function pn(e){if(!e?.assetId||!e?.versionId)return null;let t=await Ht(`deviceMedia`,Ln(e)).catch(()=>null)||null;return t&&Fn(t)?t:null}async function mn(e,t=Vn.get(wn(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 In(i)===e.versionId?i:null}async function hn(e){let t=await pn(e);if(t)return un(t);let n=await mn(e).catch(()=>null);if(!n)throw Error(`This media is not on this device.`);return n}async function gn(e){let t=Ln(e);if(Dn.has(t))return Dn.get(t);let n=URL.createObjectURL(await hn(e));return Dn.set(t,n),On.add(n),n}async function _n(e){let t=Tn(e);if(!t)return null;try{return await gn(t)}catch{return null}}function vn(e,{role:t,name:n}={}){let r={kind:e.kind,assetId:e.assetId,versionId:e.versionId,url:wn(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 yn(){let e=(await Ut(Bt).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 bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn,Hn=o((()=>{Kt(),Yt(),nn(),bn=`device-media`,xn=268435456,Sn=`sm-media://device/`,Cn=/^sm-media:\/\/device\/([a-f0-9-]{36})\/([a-f0-9]{64})$/,wn=e=>`${Sn}${e.assetId}/${e.versionId}`,Tn=e=>{let t=Cn.exec(String(e||``));return t?{assetId:t[1],versionId:t[2]}:null},En=e=>Cn.test(String(e||``)),Dn=new Map,On=new Set,kn=new Map,An=new Map,jn=`stillmade:device-media-access`,Nn=!1,Fn=e=>{let t=rn();return!e?.owner||!t||e.owner===t},In=(e,t)=>Zt(e,{signal:t}),Ln=e=>`${e.assetId}:${e.versionId}`,Rn=(e,t)=>Object.assign(Error(t),{code:e}),zn=e=>kn.get(e.versionId)||e.handle,Bn=(e,t)=>Object.fromEntries(t.filter(t=>e?.[t]!==void 0&&e[t]!==null).map(t=>[t,e[t]])),Vn=new Map}));Hn();var Un=Object.freeze({bytes:25165824,timeoutMs:15e3}),Wn=Object.freeze({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 Gn(e){if(!e||!Wn[e.kind]?.includes(e.blob?.type)||!(e.blob instanceof Blob)||!e.blob.size||!e.local&&e.blob.size>Un.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 Kn=/^\/api\/media\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/;async function qn(e,{signal:t,check:n=()=>{}}={}){if(n(),En(e.url)){let t=Tn(e.url),r=await pn(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 hn(t);n();let a=String(r.mimeType||i.type||``).split(`;`)[0].trim().toLowerCase();if(!Wn[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);return Gn({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:Kn.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(!Kn.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(!Wn[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);if(Number(i.headers.get(`content-length`))>Un.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>Un.bytes)throw Error(`Preview media must be under 24 MB.`);s.push(r)}return Gn({kind:e.kind,blob:new Blob(s,{type:a})})}finally{await o.cancel().catch(()=>{}),o.releaseLock()}}var Jn=new Set;function Yn(e){return Jn.add(e),()=>Jn.delete(e)}function Xn(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&&ee(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()))},ee=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)))},te=t.onShared(ee),L=()=>{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&&ee(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let R=u?`focusout`:`blur`;l.addEventListener(`input`,I),l.addEventListener(`change`,I),l.addEventListener(R,N),l.addEventListener(`compositionstart`,F),l.addEventListener(`compositionend`,L);let ne=()=>{y=!0,w=!1,clearTimeout(v),te(),l.removeEventListener(`input`,I),l.removeEventListener(`change`,I),l.removeEventListener(R,N),l.removeEventListener(`compositionstart`,F),l.removeEventListener(`compositionend`,L),l.disabled=d,a.delete(i)};return a.set(i,{dispose:ne,flush:N,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){M=e,ee(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),ne},_=()=>{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`);g(t,r)}return t.length},v=()=>{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:g,bindAnnotated:_,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`);v();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:v,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;for(let e of c.values())clearTimeout(e.timer);c.clear();for(let e of[...a.values()])e.dispose()}}}var Zn='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(),ee=/^\\s*/g,T=e=>e.replace(ee,``),E=/([A-Z])/g,te=(e,t)=>T(e.replace(E,e=>`${t}${w(e)}`)),D=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},O=typeof TextEncoder<`u`?new TextEncoder:null,k=O?e=>O.encode(e):D,A=typeof TextDecoder>`u`?null:new TextDecoder(`utf-8`,{fatal:!0,ignoreBOM:!0});A&&A.decode(new Uint8Array).length===1&&(A=null);let j=(e,t)=>f(t,()=>e).join(``);var M=class{constructor(){this.cpos=0,this.cbuf=new Uint8Array(100),this.bufs=[]}};let ne=()=>new M,N=e=>{let t=e.cpos;for(let n=0;n<e.bufs.length;n++)t+=e.bufs[n].length;return t},P=e=>{let t=new Uint8Array(N(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},re=(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)},F=(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},ie=F,I=(e,t)=>{for(;t>127;)F(e,128|127&t),t=h(t/128);F(e,127&t)},ae=(e,t)=>{let n=y(t);for(n&&(t=-t),F(e,(t>63?128:0)|(n?64:0)|63&t),t=h(t/64);t>0;)F(e,(t>127?128:0)|127&t),t=h(t/128)},oe=new Uint8Array(3e4),se=oe.length/3,ce=O&&O.encodeInto?(e,t)=>{if(t.length<se){let n=O.encodeInto(t,oe).written||0;I(e,n);for(let t=0;t<n;t++)F(e,oe[t])}else L(e,k(t))}:(e,t)=>{let n=unescape(encodeURIComponent(t)),r=n.length;I(e,r);for(let t=0;t<r;t++)F(e,n.codePointAt(t))},le=(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)},L=(e,t)=>{I(e,t.byteLength),le(e,t)},ue=(e,t)=>{re(e,t);let n=new DataView(e.cbuf.buffer,e.cpos,t);return e.cpos+=t,n},de=(e,t)=>ue(e,4).setFloat32(0,t,!1),fe=(e,t)=>ue(e,8).setFloat64(0,t,!1),pe=(e,t)=>ue(e,8).setBigInt64(0,t,!1),me=new DataView(new ArrayBuffer(4)),he=e=>(me.setFloat32(0,e),me.getFloat32(0)===e),ge=(e,t)=>{switch(typeof t){case`string`:F(e,119),ce(e,t);break;case`number`:S(t)&&g(t)<=2147483647?(F(e,125),ae(e,t)):he(t)?(F(e,124),de(e,t)):(F(e,123),fe(e,t));break;case`bigint`:F(e,122),pe(e,t);break;case`object`:if(t===null)F(e,126);else if(p(t)){F(e,117),I(e,t.length);for(let n=0;n<t.length;n++)ge(e,t[n])}else if(t instanceof Uint8Array)F(e,116),L(e,t);else{F(e,118);let n=Object.keys(t);I(e,n.length);for(let r=0;r<n.length;r++){let i=n[r];ce(e,i),ge(e,t[i])}}break;case`boolean`:F(e,t?120:121);break;default:F(e,127)}};var _e=class extends M{constructor(e){super(),this.w=e,this.s=null,this.count=0}write(e){this.s===e?this.count++:(this.count>0&&I(this,this.count-1),this.count=1,this.w(this,e),this.s=e)}};let ve=e=>{e.count>0&&(ae(e.encoder,e.count===1?e.s:-e.s),e.count>1&&I(e.encoder,e.count-2))};var ye=class{constructor(){this.encoder=new M,this.s=0,this.count=0}write(e){this.s===e?this.count++:(ve(this),this.count=1,this.s=e)}toUint8Array(){return ve(this),P(this.encoder)}};let be=e=>{if(e.count>0){let t=e.diff*2+(e.count===1?0:1);ae(e.encoder,t),e.count>1&&I(e.encoder,e.count-2)}};var xe=class{constructor(){this.encoder=new M,this.s=0,this.count=0,this.diff=0}write(e){this.diff===e-this.s?(this.s=e,this.count++):(be(this),this.count=1,this.diff=e-this.s,this.s=e)}toUint8Array(){return be(this),P(this.encoder)}},Se=class{constructor(){this.sarr=[],this.s=``,this.lensE=new ye}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 M;return this.sarr.push(this.s),this.s=``,ce(e,this.sarr.join(``)),le(e,this.lensE.toUint8Array()),P(e)}};let Ce=e=>Error(e),we=()=>{throw Ce(`Method unimplemented`)},R=()=>{throw Ce(`Unexpected case`)},Te=Ce(`Unexpected end of array`),Ee=Ce(`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=A?e=>A.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&&lt(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(`--${te(t,`-`)}`,n),mt.set(`-${te(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(j(` `,(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){we()}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);R()};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);R()},Mn=bt?()=>{}:(e,t)=>{let n=new Pt;if(!t.check(e,n))throw Ce(`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 Ce(`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)=>{I(e.restEncoder,t.clients.size),l(t.clients.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{e.resetDsCurVal(),I(e.restEncoder,t);let r=n.length;I(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 I(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=ne()}toUint8Array(){return P(this.restEncoder)}resetDsCurVal(){}writeDsClock(e){I(this.restEncoder,e)}writeDsLen(e){I(this.restEncoder,e)}},Dr=class extends Er{writeLeftID(e){I(this.restEncoder,e.client),I(this.restEncoder,e.clock)}writeRightID(e){I(this.restEncoder,e.client),I(this.restEncoder,e.clock)}writeClient(e){I(this.restEncoder,e)}writeInfo(e){ie(this.restEncoder,e)}writeString(e){ce(this.restEncoder,e)}writeParentInfo(e){I(this.restEncoder,+!!e)}writeTypeRef(e){I(this.restEncoder,e)}writeLen(e){I(this.restEncoder,e)}writeAny(e){ge(this.restEncoder,e)}writeBuf(e){L(this.restEncoder,e)}writeJSON(e){ce(this.restEncoder,JSON.stringify(e))}writeKey(e){ce(this.restEncoder,e)}},Or=class{constructor(){this.restEncoder=ne(),this.dsCurrVal=0}toUint8Array(){return P(this.restEncoder)}resetDsCurVal(){this.dsCurrVal=0}writeDsClock(e){let t=e-this.dsCurrVal;this.dsCurrVal=e,I(this.restEncoder,t)}writeDsLen(e){e===0&&R(),I(this.restEncoder,e-1),this.dsCurrVal+=e}},kr=class extends Or{constructor(){super(),this.keyMap=new Map,this.keyClock=0,this.keyClockEncoder=new xe,this.clientEncoder=new ye,this.leftClockEncoder=new xe,this.rightClockEncoder=new xe,this.infoEncoder=new _e(ie),this.stringEncoder=new Se,this.parentInfoEncoder=new _e(ie),this.typeRefEncoder=new ye,this.lenEncoder=new ye}toUint8Array(){let e=ne();return I(e,0),L(e,this.keyClockEncoder.toUint8Array()),L(e,this.clientEncoder.toUint8Array()),L(e,this.leftClockEncoder.toUint8Array()),L(e,this.rightClockEncoder.toUint8Array()),L(e,P(this.infoEncoder)),L(e,this.stringEncoder.toUint8Array()),L(e,P(this.parentInfoEncoder)),L(e,this.typeRefEncoder.toUint8Array()),L(e,this.lenEncoder.toUint8Array()),le(e,P(this.restEncoder)),P(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){ge(this.restEncoder,e)}writeBuf(e){L(this.restEncoder,e)}writeJSON(e){ge(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);I(e.restEncoder,t.length-i),e.writeClient(n),I(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)}),I(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),I(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)=>(I(e.restEncoder,t.size),l(t.entries()).sort((e,t)=>t[0]-e[0]).forEach(([t,n])=>{I(e.restEncoder,t),I(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 R()},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 R();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 R()}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 R()},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:P(e.encoder.restEncoder)}),e.encoder.restEncoder=ne(),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),I(e.encoder.restEncoder,t.id.clock+n)),t.write(e.encoder,n),e.written++},Ui=e=>{Vi(e);let t=e.encoder.restEncoder;I(t,e.clientStructs.length);for(let n=0;n<e.clientStructs.length;n++){let r=e.clientStructs[n];I(t,r.written),le(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 Ce(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 Ce(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 we()}clone(){throw we()}_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=()=>Ce(`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&&R(),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 Ce(`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 we()}mergeWith(e){return!1}write(e,t,n){throw we()}integrate(e,t){throw we()}},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 we()}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 we()}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 we()}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 we()}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 we()}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 R();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)):R();i!==null&&e.writeString(i)}this.content.write(e,t)}};let Fo=(e,t)=>Io[t&31](e),Io=[()=>{R()},ao,mo,ro,yo,uo,fo,ko,_o,co,()=>{R()}];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){R()}write(e,t){e.writeInfo(10),I(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,ee=!1,T,E=l.tagName===`TEXTAREA`||l.tagName===`INPUT`&&o.includes(l.type),te=e=>{S=e,l.setCustomValidity(e.message),n(e.message)},D=()=>u.find(e=>e.checked)?.value??``,O=e=>{let n=u?D():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?D():l.type===`checkbox`?l.checked:l.value)!==n&&queueMicrotask(()=>{y||t.announce?.()})},k=()=>u?D():l.type===`checkbox`?l.checked:[`number`,`range`].includes(l.type)?l.valueAsNumber:l.value,A=Object.hasOwn(f,i)&&p(u,l,f[i])?f[i]:k(),j=()=>{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,te(e)}).finally(()=>{_=!1,x=null,!y&&!n&&g&&h!==e&&M(),!y&&!g&&P(t.getShared())}),x},M=()=>{clearTimeout(v),v=setTimeout(j,Math.max(0,Math.min(150,500-(Date.now()-(C??Date.now())))))},ne=()=>{!y&&E&&b&&!d&&(w=!0,clearTimeout(v),v=null)},N=e=>{if(y||!b||d)return;if(E&&e?.isComposing){ne();return}if(w)return;let t=k();if(typeof t==`number`&&!Number.isFinite(t)){te(Error(`Enter a finite number`));return}T!==void 0&&Object.is(t,T)||(T=void 0,(S||!Object.is(t,g||_?h:m.exists?m.value:A))&&((S||C===null)&&(C=Date.now()),h=t,S=null,g=!0,M()))},P=e=>{y||(b=e.canEdit,l.disabled=d||!b,!b&&w&&(ee=!0),!b&&(g||w)&&te(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},O(m.exists?m.value:A)))},re=t.onShared(P),F=()=>{if(!y&&w){if(w=!1,!b||ee){ee=!1,h=k(),T=h,g=!0,te(Error(`Editing access changed. Your unsaved draft has been preserved.`));return}N(),g&&!_&&!S?(C=Date.now(),M()):!g&&!_&&!S&&P(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let ie=u?`focusout`:`blur`;l.addEventListener(`input`,N),l.addEventListener(`change`,N),l.addEventListener(ie,j),l.addEventListener(`compositionstart`,ne),l.addEventListener(`compositionend`,F);let I=()=>{y=!0,w=!1,clearTimeout(v),re(),l.removeEventListener(`input`,N),l.removeEventListener(`change`,N),l.removeEventListener(ie,j),l.removeEventListener(`compositionstart`,ne),l.removeEventListener(`compositionend`,F),l.disabled=d,a.delete(i)};return a.set(i,{dispose:I,flush:j,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:T!==void 0}},setDefault(e){A=e,P(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),I},_=()=>{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`);g(t,r)}return t.length},v=()=>{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:g,bindAnnotated:_,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`);v();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:v,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;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,ee=null,T=!1,E=!1,te=!1,D=!1,O=null,k=null,A=null,j=t.getShared().canEdit===!0,M=i.value,ne=()=>!!b&&!D&&!E&&j&&!/^(READ_ONLY|SHARED_TEXT_(SOURCE|EPOCH|CONFLICT|INPUT|LIMIT|STATE|UPDATE|PROTOCOL))$/.test(b.code||``),N=e=>{T||(b=p(e),E&&(D=!0),i.readOnly=!0,(x||D)&&(i.disabled=l),i.setCustomValidity(b.message),n(b.message),f())},P=()=>({start:i.selectionStart??0,end:i.selectionEnd??0,direction:i.selectionDirection||`none`}),re=e=>{i.value!==e&&(i.value=e,queueMicrotask(()=>{T||t.announce?.()}))},F=t=>{if(M=v.getValue(),re(M),t&&e.activeElement===i){let e=v.resolveSelection(t);i.setSelectionRange(e.start,e.end,e.direction)}},ie=()=>{let e=P();return v.captureSelection(e.start,e.end,e.direction)},I=e=>{if(!T&&e){if(b||D){(!k||e.textRevision>=k.textRevision)&&(k=e);return}if(E){(!k||e.textRevision>=k.textRevision)&&(k=e);return}if(v&&i.value!==M)throw D=!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,F();else{let t=ie();v.receive(e),y=e,F(t)}m=`text`,i.disabled=l||!j,i.readOnly=u,i.setCustomValidity(``),f()}}},ae=()=>{m=`legacy`,i.disabled=l,i.readOnly=u,i.value=d,_=ns(e,t,n),_.bindShared(r,i.id),_.setSharedDefaults({[r]:d}),queueMicrotask(()=>{T||t.announce?.()})},oe=async(e=!1)=>T||!g||m===`legacy`||O||b?O:(O=(async()=>{let t=await h(`read`,r);if(T)return;if(t.unsupported){if(e)ae();else throw Error(`Shared text is no longer available. Your draft is retained.`);return}if(t.enabled){I(t.snapshot);return}if(!j){m=`waiting`,M=t.value,re(t.value),i.disabled=!0;return}A={action:`initialize`,body:{protocol:1,requestId:crypto.randomUUID(),sourceIdentity:t.sourceIdentity}};let n=await h(A.action,r,A.body);A=null,T||I(n.snapshot)})().catch(N).finally(()=>{O=null,f()}),f(),O),se=()=>{T||b||E||(ee===null&&(ee=Date.now()),clearTimeout(w),w=setTimeout(()=>{w=null,ce().catch(()=>{})},Math.max(0,Math.min(200,600-(Date.now()-ee)))))},ce=async()=>{if(clearTimeout(w),w=null,_)return _.flushAll();if(O&&await O,b)throw b;if(T)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(E)throw Error(`Finish composing text before leaving this Block or running an action.`);if(v&&i.value!==M)throw D=!0,x=!0,N(Error(`This control has an uncommitted draft. Copy it before reopening the Block.`)),b;if(C){await C;return}if(!x)return;if(!j)throw Error(`Editing access changed. Your draft is retained.`);try{A={action:`update`,version:S,nativeProof:c?.version===S?{callId:c.callId}:null,body:{...v.getUpdateSince(y),requestId:crypto.randomUUID()}}}catch(e){throw N(e),e}x=!1,ee=null;let e=A;C=h(e.action,r,e.body,e.nativeProof).then(t=>{T||(I(t.snapshot),!b&&!D&&(x=S!==e.version)),A=null}).catch(e=>{throw x=!0,N(e),e}).finally(()=>{C=null,x&&!b&&se(),f()}),f(),await C},le=e=>{if(m!==`text`||T||l||u||!j||D)return;if(e?.isComposing){L();return}if(E)return;if(b){i.value!==M&&(D=!0,x=!0,f());return}let t=i.value;if(t!==M)try{let n=0,r=M.length,i=t.length;for(;n<r&&n<i&&M[n]===t[n];)n++;for(n>0&&n<r&&/[\\uDC00-\\uDFFF]/.test(M[n])&&n--;r>n&&i>n&&M[r-1]===t[i-1];)r--,i--;r<M.length&&/[\\uDC00-\\uDFFF]/.test(M[r])&&(r++,i++),v.splice(n,r-n,t.slice(n,i)),M=v.getValue(),S++,c=s.has(e)?{version:S,callId:s.get(e)}:null,x=!0,se(),f()}catch(e){D=!0,x=!0,N(e)}},L=()=>{m!==`text`||T||!j||l||u||b||(E=!0,clearTimeout(w),w=null,f())},ue=()=>{if(E){if(E=!1,b||!j||te){D=!0,x=!0,b||N(Error(`Editing access changed. Your composed draft is retained.`));return}if(le(),k){let e=k;k=null;try{I(e)}catch(e){N(e)}}x&&se(),f()}},de=e=>{if(!(m!==`text`||E||b||!j||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(),F(),S++,x=!0,se(),f()}catch(e){N(e)}}},fe=()=>{m===`text`&&ce().catch(()=>{})},pe=t.onShared(e=>{g=!0,j=e.canEdit===!0,m!==`legacy`&&(i.disabled=l||m!==`text`||!j,!j&&(x||E)&&(te||=E,D=!0,N(Error(`Editing access changed. Your unsaved draft is retained.`))),o.has(r)&&m===`loading`&&oe(!0),f())});i.disabled=!0,i.addEventListener(`input`,le),i.addEventListener(`change`,le),i.addEventListener(`blur`,fe),i.addEventListener(`keydown`,de),i.addEventListener(`compositionstart`,L),i.addEventListener(`compositionend`,ue);let me=()=>{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`&&!T&&!b&&!D&&!E&&!C&&!O&&!x&&!A&&j,identity:JSON.stringify([r,i.id,i.type,y?.protocol??null,y?.epoch??null,y?.sourceIdentity??null,y?.textRevision??null])}},he={nativeState:me,async nativeEdit(e,t){let n=me();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||E||D||b)throw Error(`The original text handler changed or refused this edit.`);let c=S;if(await ce(),S!==c||i.value!==e.value||x||A||C||b)throw Error(`Original text changed while its acknowledgement was pending. Do not repeat the edit.`);return{value:i.value,identity:me().identity}},flush:ce,getValue:()=>i.value,status:()=>_?_.getBindingStatus(r):{dirty:x||!!A,saving:!!C||!!O,problem:b,canEdit:j,composing:E,interrupted:D,retryable:ne()},setDefault(e){d=String(e??``),_&&_.setSharedDefaults({[r]:e})},refresh(){!b&&!T&&oe()},async retry(){if(!(T||C||O||!ne())){if(b=null,i.setCustomValidity(``),A){let e=A;C=h(e.action,r,e.body,e.nativeProof).then(t=>{I(t.snapshot),e.action===`update`&&!b&&!D&&(x=S!==e.version),A=null}).catch(e=>{throw N(e),e}).finally(()=>{C=null,f()}),f(),await C}else await oe(m===`loading`);if(b)throw b;if(i.readOnly=u,k){let e=k;k=null;try{I(e)}catch(e){throw N(e),e}}x&&await ce(),f()}},dispose(){T=!0,clearTimeout(w),pe(),_?.dispose(),v?.dispose(),o.delete(r),i.removeEventListener(`input`,le),i.removeEventListener(`change`,le),i.removeEventListener(`blur`,fe),i.removeEventListener(`keydown`,de),i.removeEventListener(`compositionstart`,L),i.removeEventListener(`compositionend`,ue),i.disabled=l,i.readOnly=u,f()}};return o.set(r,he),g&&oe(!0),he},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})({});',Qn=`(sharedAPI,onStatus)=>{const documentTools=(()=>{const BlockError=(class extends Error {
9
+ `)}var et,tt,nt,rt,it,at,ot,st,ct,lt,ut=o((()=>{et=e=>!!e&&typeof e==`object`&&!Array.isArray(e)&&[Object.prototype,null].includes(Object.getPrototypeOf(e)),tt=new Set([`__proto__`,`prototype`,`constructor`]),nt=(e,t)=>typeof e==`string`&&e.length>0&&e.length<=t,rt=Object.freeze({fileName:255,documentText:1e6,documentTitle:300,tableColumns:500,tableRows:1e5,tableCells:5e5,columnName:160,cellText:1e5,url:8192}),it=Object.freeze({pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`}),at=Object.freeze([...new Set(Object.values(it))]),ot=Object.freeze([`markdown`,`plain`]),st=e=>e===null||typeof e==`boolean`||typeof e==`number`&&Number.isFinite(e)||typeof e==`string`&&e.length<=rt.cellText,ct=/^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.\d{1,3})?)?(?:Z|[+-](\d{2}):(\d{2}))?)?$/,lt=e=>{let t=e==null?``:String(e);return/[",\r\n]/.test(t)?`"${t.replaceAll(`"`,`""`)}"`:t}})),dt=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})})),ft=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`])})),pt=o((()=>{Object.freeze({features:24,id:48,label:40,does:160,asks:8,ask:80})}));function mt(e,t=0,n={nodes:0}){if(B(t<=40&&++n.nodes<=5e5,`LIMIT`,`Document exceeds complexity limit`),!(e===null||[`string`,`boolean`].includes(typeof e))){if(typeof e==`number`){B(Number.isFinite(e),`SCHEMA`,`Numbers must be finite`);return}B(Array.isArray(e)||vt(e),`SCHEMA`,`Only JSON data is accepted`);for(let[r,i]of Object.entries(e))B(!wt.has(r),`SCHEMA`,`Forbidden field: ${r}`),mt(i,t+1,n)}}function ht(e){mt(e);let t=e=>Array.isArray(e)?e.map(t):vt(e)?Object.fromEntries(Object.keys(e).sort().map(n=>[n,t(e[n])])):e;return JSON.stringify(t(e))}async function gt(e){let t=new TextEncoder().encode(ht(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 _t(e,t){if(typeof t==`object`&&t&&t.schema!=null&&!se(e,t.schema))return!1;let n=typeof t==`string`?t:t.type;if(n===`object`)try{return mt(e),vt(e)}catch{return!1}if(n?.endsWith(`[]`))return Array.isArray(e)&&e.every(e=>_t(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 Xe(e);if(n===`date`)return Ze(e);if(n===`color`)return Qe(e);if(n===`file`)return qe(e);if(n===`document`)return Je(e);if(n===`table`)try{return mt(e),Ye(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 mt(e),M(e)}catch{return!1}if(n===`workspace-edit`)try{return mt(e),we(e)}catch{return!1}if(n===`timeline-edit`)try{return mt(e),je(e)}catch{return!1}if(n===`timeline-range`||n===`approval`)return vt(e)&&e.schemaVersion===1?!0:n===`timeline-range`?me(e):he(e);if(n===`json`)try{return mt(e),!0}catch{return!1}return n===`image`&&vt(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)?vt(e)&&typeof e.assetId==`string`&&typeof e.versionId==`string`&&(n===`asset`||e.kind===n):yt.includes(n)&&vt(e)&&e.schemaVersion===1}var B,vt,yt,bt,xt,St,Ct,wt,Tt=o((()=>{k(),R(),ie(),le(),de(),fe(),pe(),ye(),xe(),Ce(),De(),Ue(),Ge(),Ke(),ut(),dt(),ft(),pt(),B=ne,vt=z,Object.freeze([`type`,`required`,`default`,`min`,`max`,`description`,`role`,`primary`,`context`,`imageMode`,...ce]),yt=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`,`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`]}),bt=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`}),xt=(e,t,n,r)=>Object.freeze({executor:e,mode:t,byok:n,summary:r}),St=Object.freeze({"text.generate":xt(`capability-run`,`sync`,!0,`Exact model, account BYOK or credits, and explicit run review`),"audio.speech":xt(`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":xt(`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":xt(`capability-run`,`sync`,!1,`One prompt to generated music (5–240 seconds) with StillMade credits and playback review`),"audio.sfx":xt(`capability-run`,`sync`,!1,`One prompt to a generated sound effect (0.5–22 seconds) with StillMade credits and playback review`),"image.generate":xt(`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":xt(`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":xt(`capability-run`,`sync`,!0,`One to four owned images to bounded production notes; host-selected model/payment and actual description review`),"media.analyze":xt(`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":xt(`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":xt(`capability-run`,`sync`,!1,`One topic searched on the web and summarized with cited sources, with StillMade credits`),"timeline.propose":xt(`capability-run`,`sync`,!0,`Bounded typed context to strict timeline-edit JSON; host-selected model/payment, stale-before checks, preview and Apply`),"workspace.propose":xt(`capability-run`,`sync`,!0,`Bounded typed context to a strict workspace-edit proposal for one permitted workspace; preview and explicit Apply`),"connection.execute":xt(`connection`,`sync`,!1,`One reviewed action on a connected third-party app account through the host connection service; the Block never receives account credentials`)}),Ct=e=>Object.freeze(Object.entries(St).filter(([,t])=>e(t)).map(([e])=>e)),Ct(()=>!0),Ct(e=>e.executor===`capability-run`),Ct(e=>e.executor===`capability-run`&&e.mode===`sync`),Ct(e=>e.byok),[...Object.keys(bt).map(e=>`context.${e}.read`)],wt=new Set([`__proto__`,`prototype`,`constructor`])}));Tt();var Et=Object.freeze([`tasks`,`preview-task`,`apply-task`]);function Dt(e,t={}){return B(Et.includes(e),`CONNECTION_TASK`,`Choose a declared task operation.`),mt(t),B(vt(t)&&JSON.stringify(t).length<=32768,`CONNECTION_TASK`,`Use bounded task selection arguments.`),{operation:e,args:structuredClone(t)}}function Ot(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 kt(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 At(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 e(s.kind,s.value)}).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){let c,l;try{if(![`image`,`media`].includes(e)||!s||Array.isArray(s)||typeof s!=`object`||(c=JSON.stringify(s),l=new TextEncoder().encode(c).length,l>4194304))throw Error(`Expected a bounded preview value`)}catch(e){return Promise.reject(e)}if(e===`image`&&a.has(c))return Promise.resolve(a.get(c));let u=e===`image`&&[n,...r].find(t=>t?.kind===e&&t.serialized===c);if(u)return u.promise;if(r.length+ +!!n>=16||i+l>8388608)return Promise.reject(Error(`Too many queued previews. Wait for a preview to finish.`));let d={kind:e,value:JSON.parse(c),serialized:c,bytes:l,generation:t};return d.promise=new Promise((e,t)=>{d.resolve=e,d.reject=t}),i+=l,r.push(d),o(),d.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 jt(){return null}function Mt(){try{return typeof indexedDB<`u`&&indexedDB!==null}catch{return!1}}function Nt(){return Vt||(Vt=new Promise((e,t)=>{let n;try{n=indexedDB.open(Ft,It)}catch(e){t(e);return}n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(`cacheMeta`)||e.createObjectStore(Lt,{keyPath:`key`}),e.objectStoreNames.contains(`blobs`)||e.createObjectStore(Rt),e.objectStoreNames.contains(`handles`)||e.createObjectStore(zt),e.objectStoreNames.contains(`deviceMedia`)||e.createObjectStore(Bt,{keyPath:`id`})},n.onsuccess=()=>{let t=n.result;t.onversionchange=()=>{t.close(),Vt=null},e(t)},n.onerror=()=>t(n.error||Error(`indexedDB open failed`)),n.onblocked=()=>t(Error(`indexedDB blocked`))}),Vt.catch(()=>{Vt=null}),Vt)}function Pt(e,t,n){return Nt().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 Ft,It,Lt,Rt,zt,Bt,Vt,Ht,Ut,Wt,Gt,Kt=o((()=>{Ft=`aivw_editor`,It=2,Lt=`cacheMeta`,Rt=`blobs`,zt=`handles`,Bt=`deviceMedia`,Vt=null,Ht=(e,t)=>Pt(e,`readonly`,e=>e.get(t)),Ut=e=>Pt(e,`readonly`,e=>e.getAll()),Wt=(e,t,n)=>Pt(e,`readwrite`,e=>n===void 0?e.put(t):e.put(t,n)),Gt=(e,t)=>Pt(e,`readwrite`,e=>e.delete(t))}));function qt(){try{return typeof localStorage>`u`?null:JSON.parse(localStorage.getItem(Jt)||`null`)?.user?.id||null}catch{return null}}var Jt,Yt=o((()=>{Jt=`ai-video-workflow-auth`}));function Xt(){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=$t(t[e-15],7)^$t(t[e-15],18)^t[e-15]>>>3,r=$t(t[e-2],17)^$t(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=$t(c,6)^$t(c,11)^$t(c,25),r=c&l^~c&u,f=d+n+r+Qt[e]+t[e]>>>0,p=($t(i,2)^$t(i,13)^$t(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 Zt(e,{subtleLimit:t=en,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=Xt();for(let t=0;t<e.size;t+=tn)n?.throwIfAborted?.(),r.update(new Uint8Array(await e.slice(t,t+tn).arrayBuffer()));return r.digest()}var Qt,$t,en,tn,nn=o((()=>{Qt=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]),$t=(e,t)=>e>>>t|e<<32-t,en=67108864,tn=8388608}));function rn(){if(Pn!==void 0)return Pn;try{return qt()||null}catch{return null}}async function an(){if(Mn!==void 0)return Mn;try{Mn=navigator?.storage?.getDirectory?await(await navigator.storage.getDirectory()).getDirectoryHandle(bn,{create:!0}):null}catch{Mn=null}return Mn}async function on(){if(!Nn){Nn=!0;try{await navigator?.storage?.persist?.()}catch{}}}async function sn(e,t){let n=await an();if(n){let r=await(await n.getFileHandle(t,{create:!0})).createWritable();return await r.write(e),await r.close(),`opfs`}return await Wt(Rt,e,`device:${t}`),`idb`}function cn(){try{window.dispatchEvent(new CustomEvent(jn,{detail:{needed:An.size}}))}catch{}}async function ln(e){let t=zn(e);if(typeof t?.getFile!=`function`)throw Rn(`DEVICE_MEDIA_MOVED`,`This file is no longer linked on this computer.`);if(typeof t.queryPermission==`function`&&await t.queryPermission({mode:`read`})!==`granted`)throw An.has(e.id)||(An.set(e.id,t),cn()),Rn(`DEVICE_MEDIA_ACCESS`,`Allow StillMade to open this file on your computer again.`);let n;try{n=await t.getFile()}catch{throw Rn(`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 Rn(`DEVICE_MEDIA_CHANGED`,`This file changed on this computer after it was added.`);return n}async function un(e){if(e.storage===`linked`)return ln(e);if(e.storage===`opfs`){let t=await an();if(!t)throw Error(`Device storage is unavailable.`);return(await t.getFileHandle(e.versionId)).getFile()}let t=await Ht(Rt,`device:${e.versionId}`);if(!t)throw Error(`This media is not on this device.`);return t}function dn(){return Mt()&&typeof crypto?.subtle?.digest==`function`}async function fn(e,{kind:t,metadata:n={},role:r=`original`,links:i={},assetId:a=crypto.randomUUID(),signal:o,maxBytes:s=xn,handle:c=null}={}){if(!dn())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 on();let l=await In(e,o);o?.throwIfAborted?.();let u=await Ut(Bt).then(e=>e.find(e=>e.versionId===l&&e.kind===t)).catch(()=>null),d=c?`linked`:[`opfs`,`idb`].includes(u?.storage)?u.storage:await sn(e,l);o?.throwIfAborted?.(),c&&kn.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,...Bn(n,[`width`,`height`,`duration`]),storage:d,...c?{handle:c,lastModified:e.lastModified}:{},source:`local`,...i,...rn()?{owner:rn()}:{},cloud:{},createdAt:Date.now()};return await Wt(Bt,f),f}async function pn(e){if(!e?.assetId||!e?.versionId)return null;let t=await Ht(`deviceMedia`,Ln(e)).catch(()=>null)||null;return t&&Fn(t)?t:null}async function mn(e,t=Vn.get(wn(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 In(i)===e.versionId?i:null}async function hn(e){let t=await pn(e);if(t)return un(t);let n=await mn(e).catch(()=>null);if(!n)throw Error(`This media is not on this device.`);return n}async function gn(e){let t=Ln(e);if(Dn.has(t))return Dn.get(t);let n=URL.createObjectURL(await hn(e));return Dn.set(t,n),On.add(n),n}async function _n(e){let t=Tn(e);if(!t)return null;try{return await gn(t)}catch{return null}}function vn(e,{role:t,name:n}={}){let r={kind:e.kind,assetId:e.assetId,versionId:e.versionId,url:wn(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 yn(){let e=(await Ut(Bt).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 bn,xn,Sn,Cn,wn,Tn,En,Dn,On,kn,An,jn,Mn,Nn,Pn,Fn,In,Ln,Rn,zn,Bn,Vn,Hn=o((()=>{Kt(),Yt(),nn(),bn=`device-media`,xn=268435456,Sn=`sm-media://device/`,Cn=/^sm-media:\/\/device\/([a-f0-9-]{36})\/([a-f0-9]{64})$/,wn=e=>`${Sn}${e.assetId}/${e.versionId}`,Tn=e=>{let t=Cn.exec(String(e||``));return t?{assetId:t[1],versionId:t[2]}:null},En=e=>Cn.test(String(e||``)),Dn=new Map,On=new Set,kn=new Map,An=new Map,jn=`stillmade:device-media-access`,Nn=!1,Fn=e=>{let t=rn();return!e?.owner||!t||e.owner===t},In=(e,t)=>Zt(e,{signal:t}),Ln=e=>`${e.assetId}:${e.versionId}`,Rn=(e,t)=>Object.assign(Error(t),{code:e}),zn=e=>kn.get(e.versionId)||e.handle,Bn=(e,t)=>Object.fromEntries(t.filter(t=>e?.[t]!==void 0&&e[t]!==null).map(t=>[t,e[t]])),Vn=new Map}));Hn();var Un=Object.freeze({bytes:25165824,timeoutMs:15e3}),Wn=Object.freeze({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 Gn(e){if(!e||!Wn[e.kind]?.includes(e.blob?.type)||!(e.blob instanceof Blob)||!e.blob.size||!e.local&&e.blob.size>Un.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 Kn=/^\/api\/media\/[A-Za-z0-9_-]+\/[A-Za-z0-9_-][A-Za-z0-9._-]*$/;async function qn(e,{signal:t,check:n=()=>{}}={}){if(n(),En(e.url)){let t=Tn(e.url),r=await pn(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 hn(t);n();let a=String(r.mimeType||i.type||``).split(`;`)[0].trim().toLowerCase();if(!Wn[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);return Gn({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:Kn.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(!Kn.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(!Wn[e.kind]?.includes(a))throw Error(`Choose a supported audio or video file.`);if(Number(i.headers.get(`content-length`))>Un.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>Un.bytes)throw Error(`Preview media must be under 24 MB.`);s.push(r)}return Gn({kind:e.kind,blob:new Blob(s,{type:a})})}finally{await o.cancel().catch(()=>{}),o.releaseLock()}}var Jn=new Set;function Yn(e){return Jn.add(e),()=>Jn.delete(e)}function Xn(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&&ee(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()))},ee=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)))},te=t.onShared(ee),L=()=>{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&&ee(t.getShared())}};l.disabled=d||!t.getShared().canEdit;let R=u?`focusout`:`blur`;l.addEventListener(`input`,I),l.addEventListener(`change`,I),l.addEventListener(R,N),l.addEventListener(`compositionstart`,F),l.addEventListener(`compositionend`,L);let ne=()=>{y=!0,w=!1,clearTimeout(v),te(),l.removeEventListener(`input`,I),l.removeEventListener(`change`,I),l.removeEventListener(R,N),l.removeEventListener(`compositionstart`,F),l.removeEventListener(`compositionend`,L),l.disabled=d,a.delete(i)};return a.set(i,{dispose:ne,flush:N,status(){return{dirty:g,saving:_,problem:S,canEdit:b,composing:w,interrupted:E!==void 0}},setDefault(e){M=e,ee(t.getShared())},setInputDefault(e){p(u,l,e)&&this.setDefault(e)}}),ne},_=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 Zn='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&&lt(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})({});',Qn=`(sharedAPI,onStatus)=>{const documentTools=(()=>{const BlockError=(class extends Error {
10
10
  constructor(code, message, details = []) {
11
11
  super(message);
12
12
  this.name = "BlockError";
@@ -1084,7 +1084,7 @@ Error generating stack: `+e.message+`
1084
1084
  entries.clear();
1085
1085
  }
1086
1086
  });
1087
- })(createStore,sharedAPI,onStatus);})(documentTools,sharedAPI,onStatus);return {documentTools,sharedDocuments}}`;function $n(){return()=>{}}function er(){return{}}Tt();function tr({assert:e,plain:t,safeDocument:n,stableStringify:r}){let i=(e,t)=>{if(e===t)return!0;if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>i(e,t[n]));let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&i(e[n],t[n]))},a=(e,t)=>e.exists===t.exists&&(!e.exists||i(e.value,t.value)),o=(e,t)=>Object.hasOwn(e,t)?{exists:!0,value:e[t]}:{exists:!1},s=e=>Array.isArray(e)&&e.every(e=>t(e)&&typeof e.id==`string`)&&new Set(e.map(e=>e.id)).size===e.length;function c(e,n,r){let i=[];if(t(e)&&t(n))for(let l of new Set([...Object.keys(e),...Object.keys(n)])){let u=o(e,l),d=o(n,l);a(u,d)||(!(r.length===0&&[`projectType`,`semanticContext`].includes(l))&&u.exists&&d.exists&&(t(u.value)&&t(d.value)||s(u.value)&&s(d.value))?i.push(...c(u.value,d.value,[...r,l])):i.push({path:[...r,l],before:u,after:d}))}else if(s(e)&&s(n)){let t=new Map(e.map(e=>[e.id,e])),a=new Map(n.map(e=>[e.id,e]));for(let e of new Set([...t.keys(),...a.keys()]))t.has(e)&&a.has(e)?i.push(...c(t.get(e),a.get(e),[...r,{id:e}])):i.push({path:[...r,{id:e}],before:t.has(e)?{exists:!0,value:t.get(e)}:{exists:!1},after:a.has(e)?{exists:!0,value:a.get(e)}:{exists:!1}});let o=[...e.filter(e=>a.has(e.id)).map(e=>e.id),...n.filter(e=>!t.has(e.id)).map(e=>e.id)];JSON.stringify(o)!==JSON.stringify(n.map(e=>e.id))&&i.push({path:r,before:{exists:!0,value:n.map(e=>t.get(e.id)||e)},after:{exists:!0,value:n},order:n.map(e=>e.id),expectedOrder:e.map(e=>e.id)})}return i}function l(e,t,r=[]){return n(e),n(t),c(e,t,r)}function u(n,r){let i=n;for(let n of r.slice(0,-1))t(n)?(e(Array.isArray(i),`CONFLICT`,`Collection removed`),i=i.find(e=>e?.id===n.id)):(e(i&&Object.hasOwn(i,n),`CONFLICT`,`Parent removed`),i=i[n]),e(i&&typeof i==`object`,`CONFLICT`,`Parent removed`);let a=r.at(-1);if(t(a)){e(Array.isArray(i),`CONFLICT`,`Collection removed`);let t=i.findIndex(e=>e?.id===a.id);return{parent:i,key:t,state:t<0?{exists:!1}:{exists:!0,value:i[t]},collection:!0,id:a.id}}return e(t(i),`CONFLICT`,`Parent removed`),{parent:i,key:a,state:o(i,a),collection:!1}}function d(r,i){n(r),n(i),e(Array.isArray(i)&&i.length<=2e3,`LIMIT`,`Too many operations`);let o=structuredClone(r);for(let n of i){e(Array.isArray(n.path)&&n.path.length>0&&n.path.length<=30&&n.path.every(e=>typeof e==`string`&&e.length>0&&![`__proto__`,`constructor`,`prototype`].includes(e)||t(e)&&typeof e.id==`string`&&Object.keys(e).length===1),`PATCH`,`Invalid operation path`),e(t(n.before)&&t(n.after)&&typeof n.before.exists==`boolean`&&typeof n.after.exists==`boolean`,`PATCH`,`Expected before/after preconditions`),e(!(n.path.at(-1)===`id`&&t(n.path.at(-2))),`PATCH`,`Collection identity is immutable`);let r=u(o,n.path);if(n.order){e(Array.isArray(r.state.value)&&Array.isArray(n.order)&&Array.isArray(n.expectedOrder),`PATCH`,`Invalid order operation`);let t=r.state.value,i=new Set(n.expectedOrder);e(new Set(n.order).size===n.order.length&&n.order.every(e=>typeof e==`string`&&t.some(t=>t.id===e)),`PATCH`,`Invalid order IDs`);let a=new Set(n.order);if(JSON.stringify(t.filter(e=>a.has(e.id)).map(e=>e.id))===JSON.stringify(n.order))continue;e(t.filter(e=>i.has(e.id)).map(e=>e.id).join(`\0`)===n.expectedOrder.filter(e=>t.some(t=>t.id===e)).join(`\0`),`CONFLICT`,`Collection order changed`),r.parent[r.key]=[...n.order.map(e=>t.find(t=>t.id===e)),...t.filter(e=>!a.has(e.id))];continue}e(a(r.state,n.before)||a(r.state,n.after),`CONFLICT`,`Concurrent change at ${n.path.map(e=>typeof e==`string`?e:e.id).join(`.`)}`),!a(r.state,n.after)&&(r.collection?n.after.exists?(e(n.after.value?.id===r.id,`PATCH`,`Collection ID mismatch`),r.key<0?r.parent.push(structuredClone(n.after.value)):r.parent[r.key]=structuredClone(n.after.value)):r.parent.splice(r.key,1):n.after.exists?r.parent[r.key]=structuredClone(n.after.value):delete r.parent[r.key])}return o}return Object.freeze({isKeyed:s,diffDocument:l,applyOperations:d})}var{isKeyed:nr,diffDocument:rr,applyOperations:ir}=tr({assert:B,plain:vt,safeDocument:mt,stableStringify:ht});Tt();var ar=Object.freeze({stateBytes:393216,requestBytes:8e5,pendingBytes:2097152});function or(e={},t){mt(t),B(new TextEncoder().encode(JSON.stringify(t)).length<=ar.requestBytes,`VIEW_STATE`,`Shared edit exceeds 800,000 bytes`),B(vt(e)&&vt(t)&&vt(t.values)&&vt(t.before),`VIEW_STATE`,`Expected a shared view patch`);let n=Object.keys(t.values);B(t.merge===void 0||typeof t.merge==`boolean`,`VIEW_STATE`,`Invalid structured merge option`);let r={...e};B(n.length>0&&n.length<=100&&n.every(e=>/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)),`VIEW_STATE`,`Use bounded named view fields`);for(let i of n){let n=t.before[i];B(vt(n)&&typeof n.exists==`boolean`,`VIEW_STATE`,`Missing field precondition`);let a=Object.hasOwn(e,i);if(t.merge&&n.exists&&a&&vt(n.value)&&vt(t.values[i])&&vt(e[i])){let a=rr({value:n.value},{value:t.values[i]});r[i]=ir({value:e[i]},a).value;continue}B(a===n.exists&&(!a||ht(e[i])===ht(n.value))||a&&ht(e[i])===ht(t.values[i]),`CONFLICT`,`This field changed. Read the shared state before applying your edit.`),r[i]=structuredClone(t.values[i])}return B(new TextEncoder().encode(JSON.stringify(r)).length<=ar.stateBytes,`VIEW_STATE`,`Shared view state exceeds 384 KiB`),r}function sr(e,t,n=ar,r={}){let i={state:{},outputs:{},memory:null,canEdit:!1},a=!1,o=0,s=null,c=!1,l=[],u=0,d=0,f=new Set,p=new Map,m=null,h=null,g=null,_=(e,t)=>{t=Error(String(t?.message||`Shared edit failed`).slice(0,1e3));let n=e&&typeof e==`object`&&!Array.isArray(e)?Object.keys(e):[];if(!n.length){m=t;return}for(let e of n){if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)){m=t;continue}if(p.size>=100&&!p.has(e)){m=Error(`Too many unresolved shared fields. Reopen the Block to recover.`);break}p.set(e,t)}},v=()=>{h&&g===null&&(g=setTimeout(()=>{if(g=null,!h||s||l.length)return;let e=h;h=null;let t=c?Error(`Block closed`):m||p.values().next().value;t?e.reject(t):e.resolve({queued:!0})},0))};r.captureControlState=()=>({attempts:u,snapshotVersion:d,closed:c,ready:a,pending:!!s,queued:l.length,failed:!!m||p.size>0}),r.flushSharedWrites=()=>{if(h)return h.promise;let e,t,n=new Promise((n,r)=>{e=n,t=r});return h={promise:n,resolve:e,reject:t},v(),n};let y=()=>{for(let e of f)try{e(structuredClone(i))}catch{}},b=e=>{let t=Error(e);s&&=(clearTimeout(s.timer),_(s.values,t),s.reject(t),null);for(let e of l.splice(0))_(e.values,t),e.reject(t);v()},x=()=>{if(s||!l.length||c)return;if(!a||!i.canEdit){b(`Shared editing is unavailable or read only`);return}s=l.shift();let n=s;n.timer=setTimeout(()=>{c=!0,a=!1,i={...i,canEdit:!1},b(`Shared edit acknowledgement timed out. Reopen the Block to recover.`),y()},15e3),parent.postMessage({channel:e,session:t,op:`shared-view-update`,id:n.id,request:{values:n.values,before:n.before,...n.merge?{merge:!0}:{}}},`*`)};addEventListener(`message`,n=>{let r=n.data;if(!c&&n.source===parent&&r&&r.channel===e&&r.session===t){if(r.op===`shared-view`)d++,i=r.value,a=!0,i.canEdit||b(`Shared editing is unavailable or read only`),y(),x();else if(r.op===`shared-view-result`&&s?.id===r.id){let e=s;if(clearTimeout(e.timer),s=null,r.error){let t=Error(r.error);_(e.values,t),e.reject(t),b(`A previous edit failed. Read the shared state before trying again.`)}else{let t={...i.state};for(let n of Object.keys(e.values)){let r=e.before[n];Object.hasOwn(t,n)===r.exists&&(!r.exists||JSON.stringify(t[n])===JSON.stringify(r.value))&&(t[n]=e.values[n])}i={...i,state:t};for(let t of Object.keys(e.values))p.delete(t);e.resolve({queued:!0}),y()}x(),v()}else r.op===`dispose`&&(c=!0,a=!1,f.clear(),b(`Block closed`))}});let S={getShared(){return structuredClone(i)},onShared(e){if(typeof e!=`function`)throw Error(`Expected a function`);return f.add(e),a&&e(structuredClone(i)),()=>f.delete(e)},updateShared(e,t,r){u++;let d=t=>(_(e,t),v(),Promise.reject(t));if(c||!a||!i.canEdit)return d(Error(`Shared editing is unavailable or read only`));if(l.length>=32)return d(Error(`Too many pending shared edits. Wait for synchronization.`));let f={},p=!1,m=0;try{if(r!==void 0){if(!r||typeof r!=`object`||Array.isArray(r)||Object.keys(r).some(e=>e!==`merge`)||typeof r.merge!=`boolean`)throw Error(`Expected a structured merge option`);if(p=r.merge,p&&t===void 0)throw Error(`Structured edits require the exact base preconditions`)}if(!e||Array.isArray(e)||typeof e!=`object`||new TextEncoder().encode(JSON.stringify(e)).length>n.stateBytes)throw Error(`Expected bounded view fields`);e=structuredClone(e);let a=Object.keys(e);if(!a.length||a.length>100||a.some(e=>!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)))throw Error(`Use bounded named view fields`);let o={...i.state,...s?.values};for(let e of l)Object.assign(o,e.values);for(let e of a)f[e]=Object.hasOwn(o,e)?{exists:!0,value:structuredClone(o[e])}:{exists:!1};if(t!==void 0){if(!t||Array.isArray(t)||typeof t!=`object`)throw Error(`Expected field preconditions`);f=structuredClone(t);for(let e of a)if(!f[e]||typeof f[e].exists!=`boolean`)throw Error(`Missing field precondition`)}if(m=new TextEncoder().encode(JSON.stringify({values:e,before:f,...p?{merge:!0}:{}})).length,m>n.requestBytes)throw Error(`Shared edit exceeds 800,000 bytes`);if(m+(s?.bytes||0)+l.reduce((e,t)=>e+t.bytes,0)>n.pendingBytes)throw Error(`Pending shared edits exceed 2 MiB. Wait for synchronization.`)}catch(e){return d(e)}return new Promise((t,n)=>{l.push({id:String(++o),resolve:t,reject:n,values:e,before:f,merge:p,bytes:m}),x()})}};return Object.defineProperty(S,"announce",{value:()=>{a&&!c&&y()}}),S}function cr(e,t=()=>{},n=()=>{}){let r=new Set(`div.section.article.header.footer.p.span.strong.em.i.small.h1.h2.h3.h4.label.button.input.textarea.select.option.ul.ol.li.table.thead.tbody.tr.th.td.details.summary.output.progress.img`.split(`.`)),i=new Set([`DIV`,`SPAN`,`SECTION`,`ARTICLE`,`MAIN`,`ASIDE`,`UL`,`OL`,`TBODY`]),a=new Set([`tag`,`text`,`children`,`id`,`className`,`action`,`value`,`type`,`checked`,`disabled`,`placeholder`,`min`,`max`,`step`,`label`]),o=new Set,s=new WeakMap,c=new WeakMap,l=new Map,u=new Map,d=!1,f=0,p=0,m=!1,h=new Set,g=()=>{try{n()}catch{}},_=globalThis.setTimeout?.bind(globalThis),v=globalThis.clearTimeout?.bind(globalThis),y=_&&v?e.defaultView?.MutationObserver:null,b=new Set([`file`,`password`,`hidden`,`submit`,`reset`,`image`,`button`]),x=e=>{let t=``;for(let n of e.childNodes)n.nodeType===3?t+=n.nodeValue:n.nodeType===1&&!n.matches(`input,select,textarea,button`)&&(t+=` `+n.textContent);return t},S=t=>{let n=t.getAttribute(`aria-label`)||``,r=t.getAttribute(`aria-labelledby`);return!n&&r&&(n=r.split(/\s+/).map(t=>e.getElementById(t)?.textContent||``).join(` `)),!n&&t.labels?.length&&(n=x(t.labels[0])),!n.trim()&&t.tagName===`BUTTON`&&(n=t.textContent||``),String(n.trim()?n:t.getAttribute(`title`)||``).replace(/\s+/g,` `).trim().slice(0,240)},C=e=>{let t=s.get(e);return t&&!t.plain||e.closest(`[data-stillmade-share],[data-stillmade-local]`)?!1:e.tagName===`BUTTON`?e.hasAttribute(`data-stillmade-action`):e.tagName===`INPUT`&&b.has(e.type)?!1:e.hasAttribute(`data-stillmade-action`)||!!S(e)},w=()=>{let t=[];for(let n of e.querySelectorAll(`button,input,select,textarea`)){if(t.length>=200)break;C(n)&&(s.has(n)||s.set(n,{plain:!0,event:n.tagName===`BUTTON`?`click`:n.tagName===`SELECT`||[`checkbox`,`radio`].includes(n.type)?`change`:`input`,root:e.documentElement,handle:`view-control-`+String(++p)}),t.push(n))}return t},T=e=>{let t=s.get(e);return t.plain?String(e.getAttribute(`data-stillmade-action`)||e.id||e.getAttribute(`name`)||S(e)).slice(0,120):t.action},E=(e,t)=>{if(!e)throw Error(t)},D=(e,t=1e4)=>(E(typeof e==`string`&&e.length<=t,`Dynamic control text exceeds its limit`),e),O=e=>e.tagName===`TEXTAREA`||e.tagName===`INPUT`&&e.type===`text`,k=(e,t,n)=>{let r=s.get(e);if(m||d||!r?.action||r.event!==n||!t.contains(e)||e.disabled)return;let i={action:r.action,value:e.value,checked:e.checked===!0,event:n};for(let e of o)try{Promise.resolve(e({...i})).then(g,()=>{})}catch{}},A=(e,t,n=e.value)=>{if(d||!t.contains(e)||e.disabled||!O(e))return;let r=c.get(e),i=s.get(e),a={composing:!0,cancelled:!1,action:i?.action,event:i?.event,type:e.type,declared:i?.declared,initialValue:n,conflict:r?.conflict===!0,problem:r?.problem,suppress:null};c.set(e,a),l.set(e,t)},j=(e,n,r,i)=>{if(!r.conflict){r.conflict=!0,r.problem=i,u.set(e,n);try{t(i)}catch{}}},M=e=>{for(let t of l.keys())(t===e||e.contains?.(t))&&(c.get(t).cancelled=!0,l.delete(t));for(let t of u.keys())(t===e||e.contains?.(t))&&u.delete(t)},N=(t,n)=>{D(t,120);let o=e.getElementById(t);E(o&&i.has(o.tagName),`Choose an existing container for dynamic controls`),E(Array.isArray(n)&&JSON.stringify(n).length<=262144,`Dynamic controls exceed 256 KiB`);let u=0,d=new Set,_=(n,i)=>{E(++u<=1e3&&i<=12,`Dynamic controls exceed 1000 elements or 12 levels`),E(n&&typeof n==`object`&&!Array.isArray(n)&&Object.keys(n).every(e=>a.has(e)),`Unsupported dynamic control field`),E(r.has(n.tag),`Unsupported dynamic control tag`);let f=e.createElement(n.tag);if(n.id!==void 0){let r=D(n.id,120),i=e.getElementById(r);E(r&&r!==t&&!d.has(r)&&(!i||o.contains(i)),`Dynamic control IDs must be unique`),d.add(r),f.id=r}n.className!==void 0&&(f.className=D(n.className,240)),n.text!==void 0&&(f.textContent=D(n.text)),n.label!==void 0&&f.setAttribute(`aria-label`,D(n.label,240)),n.type!==void 0&&(E(n.tag===`input`&&[`text`,`number`,`range`,`checkbox`,`radio`,`color`].includes(n.type),`Unsupported dynamic input type`),f.type=n.type);for(let e of[`checked`,`disabled`])n[e]!==void 0&&(E(typeof n[e]==`boolean`,`Control flags must be boolean`),f[e]=n[e]);for(let e of[`min`,`max`,`step`])n[e]!==void 0&&(E(typeof n[e]==`string`||typeof n[e]==`number`&&Number.isFinite(n[e]),`Control values must be text or finite numbers`),f[e]=D(String(n[e]),1e4));if(n.placeholder!==void 0&&(f.placeholder=D(n.placeholder,240)),n.tag===`button`&&(f.type=`button`),n.children!==void 0){E(Array.isArray(n.children)&&n.text===void 0,`Use children or text for a control`);for(let e of n.children)f.appendChild(_(e,i+1))}if(n.value!==void 0&&(E(typeof n.value==`string`||typeof n.value==`number`&&Number.isFinite(n.value),`Control values must be text or finite numbers`),f.value=D(String(n.value),1e4)),n.action!==void 0){let e=D(n.action,120);E(e&&[`button`,`input`,`textarea`,`select`].includes(n.tag),`Actions belong to interactive controls`)}if([`button`,`input`,`textarea`,`select`].includes(n.tag)){let e=n.tag===`button`?`click`:[`checkbox`,`radio`].includes(n.type)||n.tag===`select`?`change`:`input`;s.set(f,{action:n.action,event:e,declared:f.value,declaredDisabled:f.disabled,root:o,handle:`view-control-`+String(++p)});for(let e of[`click`,`input`,`change`])f.addEventListener(e,t=>{let n=c.get(f);if(e===`input`&&t.isComposing){n?.composing||A(f,o,s.get(f)?.declared??f.value);return}if(!(n?.composing||n?.conflict)){if(e===`input`&&n?.suppress!==null&&n?.suppress!==void 0){let e=f.value===n.suppress;if(n.suppress=null,e)return}k(f,o,e)}});(n.tag===`input`||n.tag===`textarea`)&&(f.addEventListener(`compositionstart`,()=>A(f,o)),f.addEventListener(`compositionend`,()=>{let e=c.get(f);if(!e?.composing)return;e.composing=!1,e.suppress=f.value,l.delete(f);let t=s.get(f);!e.cancelled&&!e.conflict&&f.value!==e.initialValue&&O(f)&&e.type===f.type&&e.action===t?.action&&e.event===t?.event&&k(f,o,`input`),e.suppress=f.value}))}return f},v=e.createDocumentFragment();for(let e of n)v.appendChild(_(e,0));E(e.querySelectorAll(`*`).length-o.querySelectorAll(`*`).length+u<=5e3,`This interface exceeds 5000 elements`);let y=e.activeElement,b=y&&o.contains(y)&&typeof y.selectionStart==`number`?{start:y.selectionStart,end:y.selectionEnd,direction:y.selectionDirection}:null,x=(e,t)=>{let n=Array.from(e.childNodes),r=new Set,i=new Map(n.filter(e=>e.nodeType===1&&e.id).map(e=>[e.id,e]));Array.from(t.childNodes).forEach((t,a)=>{let l=t.nodeType===1?t.id:``,u=l?i.get(l):n[a];if(!u||r.has(u)||u.nodeType!==t.nodeType||u.nodeName!==t.nodeName||u.nodeType===1&&u.id!==l)u=t;else if(u.nodeType===3)u.nodeValue!==t.nodeValue&&(u.nodeValue=t.nodeValue);else{let e=`value`in t?t.value:void 0,n=c.get(u),r=s.get(t);n?.composing&&(t.disabled&&j(u,o,n,`Editing access changed while you were composing. Your local draft is retained here. Review it before reopening this Block.`),t.disabled||n.action!==r?.action||n.event!==r?.event||n.type!==t.type?n.cancelled=!0:!n.cancelled&&e!==n.declared&&j(u,o,n,`Text changed elsewhere while you were composing. Your local draft is retained here. Copy it before reopening this Block to review the shared version.`));for(let e of[`id`,`class`,`aria-label`,`type`,`min`,`max`,`step`,`placeholder`]){let n=t.getAttribute(e);n===null?u.removeAttribute(e):u.getAttribute(e)!==n&&u.setAttribute(e,n)}x(u,t),`disabled`in t&&(u.disabled=t.disabled),`checked`in t&&(u.checked=t.checked),e!==void 0&&u.value!==e&&!n?.composing&&!n?.conflict&&(u.value=e),s.has(t)&&s.set(u,s.get(t))}r.add(u);let d=e.childNodes[a];d!==u&&e.insertBefore(u,d||null)});for(let t of n)!r.has(t)&&t.parentNode===e&&(M(t),t.remove())};x(o,v),h.add(o),f++,m&&R(!0),g(),y&&o.contains(y)&&!y.disabled&&!c.get(y)?.composing&&(e.activeElement!==y&&y.focus({preventScroll:!0}),b&&typeof y.selectionStart==`number`&&typeof y.setSelectionRange==`function`&&y.setSelectionRange(b.start,b.end,b.direction))},P=()=>{E(!d,`Dynamic controls are closed`);let e=[...u].find(([e,t])=>t.contains(e)&&e.isConnected);if(e)throw Error(c.get(e[0]).problem);E(![...l].some(([e,t])=>t.contains(e)&&e.isConnected&&!e.disabled),`Finish composing text before continuing.`)},F=()=>{let e=new Set,t=[];for(let n of h)if(n.isConnected)for(let r of n.querySelectorAll(`button,input,textarea,select`)){let i=s.get(r);i?.action&&i.root===n&&!e.has(r)&&(e.add(r),t.push(r))}for(let n of w())e.has(n)||(e.add(n),t.push(n));return t},I=t=>{for(let n=t;n;n=n.parentElement){if(n.hidden)return!0;let t=e.defaultView?.getComputedStyle(n);if(t?.display===`none`||[`hidden`,`collapse`].includes(t?.visibility)||t?.opacity===`0`)return!0}return!1},ee=e=>s.get(e)?.plain?S(e)||T(e)||`Control`:String(e.getAttribute(`aria-label`)||e.textContent||e.placeholder||`Control`).slice(0,240),te=e=>e.tagName===`SELECT`?Array.from(e.options).map(e=>({value:e.value,label:e.textContent})):null,L=e=>{let t=s.get(e);return JSON.stringify({action:T(e),event:t.event,root:t.root.id,tag:e.tagName,type:e.type,value:e.value,checked:e.checked,disabled:e.disabled,hidden:I(e),label:ee(e),choices:te(e)})},R=e=>{for(let t of F())s.get(t).plain||(t.disabled=e||s.get(t).declaredDisabled)},ne=null,z=null,re=()=>w().map(e=>s.get(e).handle+(e.disabled?`:off`:``)+(I(e)?`:hidden`:``)).join(`,`),ie=()=>{if(z=null,d||ne===null)return;let e;try{e=re()}catch{return}e!==ne&&(ne=e,f++,g())},ae=y?new y(()=>{z===null&&!d&&(z=_(ie,250))}):null;return ae?.observe(e.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`disabled`,`hidden`,`class`,`data-stillmade-action`,`aria-label`]}),Object.freeze({render:N,inspectControls:({offset:e=0,limit:t=20}={})=>{E(!d,`Dynamic controls are closed`),E(Number.isSafeInteger(e)&&e>=0&&Number.isSafeInteger(t)&&t>=1&&t<=20,`Choose a bounded control page`);let n=F();return ne=re(),E(e<=n.length,`Choose a current control page`),{revision:f,total:n.length,offset:e,nextOffset:e+t<n.length?e+t:null,controls:n.slice(e,e+t).map(e=>{let t=s.get(e),n=String(e.value??``);return{id:t.handle,action:T(e),label:ee(e),tag:e.tagName.toLowerCase(),type:e.type,event:t.event,disabled:e.disabled,hidden:I(e),value:n.slice(0,240),valuePartial:n.length>240,...typeof e.checked==`boolean`?{checked:e.checked}:{},...e.tagName===`SELECT`?{choices:te(e).slice(0,40),choicesPartial:e.options.length>40}:{},identity:L(e)}})}},dispatchControl:async(t,n=async()=>{})=>{E(!m,`A declared control is already running`),P(),E(t&&typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).every(e=>[`id`,`revision`,`identity`,`value`,`checked`].includes(e))&&typeof t.id==`string`&&t.revision===f&&typeof t.identity==`string`,`The declared control changed`);let r=F().find(e=>s.get(e).handle===t.id),i=r&&s.get(r);E(r&&L(r)===t.identity,`The declared control changed`),E(!r.disabled&&!I(r),`This declared control is unavailable`),E(i.plain||o.size>0,`This declared control has no native handler`),r.tagName===`BUTTON`?E(!Object.hasOwn(t,`value`)&&!Object.hasOwn(t,`checked`),`Buttons take no input value`):[`checkbox`,`radio`].includes(r.type)?(E(typeof t.checked==`boolean`&&!Object.hasOwn(t,`value`),`Choose a checkbox value`),r.checked=t.checked):(E((typeof t.value==`string`&&t.value.length<=1e4||typeof t.value==`number`&&Number.isFinite(t.value))&&!Object.hasOwn(t,`checked`),`Choose a bounded control value`),r.tagName===`SELECT`&&E(Array.from(r.options).some(e=>e.value===String(t.value)),`Choose a declared option`),r.value=String(t.value));let a={action:i.action,value:r.value,checked:r.checked,event:i.event};if(m=!0,R(!0),i.plain)try{if(r.tagName===`BUTTON`)r.click();else for(let t of[`input`,`change`])r.dispatchEvent(new e.defaultView.Event(t,{bubbles:!0}));return E(!d,`Dynamic controls are closed`),await n(),E(!d,`Dynamic controls are closed`),{settled:!0}}finally{m=!1,R(!1),g()}try{let e=[];for(let t of o)try{e.push(Promise.resolve(t({...a})))}catch(t){e.push(Promise.reject(t))}let t=await Promise.allSettled(e);E(!d,`Dynamic controls are closed`),await n(),E(!d,`Dynamic controls are closed`);let r=t.find(e=>e.status===`rejected`);if(r)throw r.reason;return{settled:!0}}finally{m=!1,R(!1),g()}},locateControl:e=>{E(!d,`Dynamic controls are closed`);let t=F().find(t=>s.get(t).handle===e);if(!t||I(t))return null;let n=t.getBoundingClientRect();return{x:n.left,y:n.top,width:n.width,height:n.height}},onAction(e){return E(typeof e==`function`&&o.size<16,`Register at most 16 action listeners`),o.add(e),()=>o.delete(e)},assertCommitted:P,async flushAll(){return P(),{queued:!0}},dispose(){d=!0,ae?.disconnect(),z!==null&&v?.(z),h.clear();for(let e of l.keys())c.get(e).cancelled=!0;l.clear(),u.clear(),o.clear()}})}function lr(e=[]){let t=new Set([`__proto__`,`prototype`,`constructor`]),n=new Set(e);function r(e,n=0,i={nodes:0}){if(n>32||++i.nodes>5e4)throw Error(`Field data exceeds its complexity limit.`);if(!(e===null||[`string`,`boolean`].includes(typeof e))&&!(typeof e==`number`&&Number.isFinite(e))){if(!e||typeof e!=`object`||!Array.isArray(e)&&![Object.prototype,null].includes(Object.getPrototypeOf(e)))throw Error(`Fields accept plain JSON only.`);if(Object.getOwnPropertySymbols(e).length)throw Error(`Fields accept JSON keys only.`);for(let a of Object.getOwnPropertyNames(e)){if(Array.isArray(e)&&a===`length`)continue;let o=Object.getOwnPropertyDescriptor(e,a);if(t.has(a)||!o||!o.enumerable||!Object.hasOwn(o,`value`))throw Error(`Unsafe field data.`);r(o.value,n+1,i)}}}let i=e=>{r(e);let t=JSON.stringify(e);if(t.length>2097152)throw Error(`Field data exceeds 2 MiB.`);return JSON.parse(t)},a=e=>{if(!Array.isArray(e)||e.length<1||e.length>12||e.some(e=>typeof e!=`string`&&!Number.isSafeInteger(e)||typeof e==`string`&&(t.has(e)||e.length>240)||typeof e==`number`&&(e<0||e>1e4)))throw Error(`Choose a safe field path.`)};function o(e,t){a(t),r(e);let n=e;for(let e of t){if(!n||typeof n!=`object`||!Object.hasOwn(n,e))return;n=n[e]}return n===void 0?void 0:i(n)}function s(e,t,n){a(t);let o=i(e);r(n);let s=o;for(let e=0;e<t.length-1;e++){let n=t[e];(!Object.hasOwn(s,n)||s[n]===null||typeof s[n]!=`object`)&&(s[n]=typeof t[e+1]==`number`?[]:{}),s=s[n]}return s[t.at(-1)]=i(n),o}function c(e){return Object.hasOwn(e,`default`)?i(e.default):Array.isArray(e.enum)&&e.enum.length?i(e.enum[0]):e.type===`object`?{}:e.type===`array`?[]:e.type===`boolean`?!1:[`integer`,`number`].includes(e.type)?Math.max(e.minimum||0,0):``}function l(e){let t=typeof e==`string`?e.replace(/\s+/g,` `).trim():``;if(!t)return``;let[n,r]=t.split(/(?<=[.!?])\s+(?=[A-Z])/),i=r&&n.length+r.length<280?n+` `+r:n;return i.length>280?i.slice(0,279).trimEnd()+`…`:i}function u(e,t,i,{canEdit:a=!0,busy:o=!1,more:s=[],hide:c=[]}={}){r(e),r(t),r(i);let u=0,d=[],f=[],p=(e,t,n)=>{let r=`field-${f.length}`;return f.push({id:r,kind:e,path:t,s:n}),r},m=(e,t)=>({tag:`section`,...e.type===`object`&&e.properties||e.type===`array`?{}:{className:`sm-field`},children:t});function h(e,t,r,i,s,c){if(++u>150||c>5)return[{tag:`p`,text:`This task needs a custom interface for its remaining fields.`}];let d=String(i).slice(0,240)+(s?` *`:``),g=l(e.description),_=[g?{tag:`div`,className:`sm-label`,children:[{tag:`label`,text:d},{tag:`details`,className:`sm-hint`,children:[{tag:`summary`,label:`About `+String(i).slice(0,200)},{tag:`p`,text:g}]}]}:{tag:`label`,text:d}],v=o||!a||n.has(t[0]);if(e.type===`object`&&e.properties)for(let n of Object.keys(e.properties))_.push(m(e.properties[n],h(e.properties[n],t.concat(n),r?.[n],e.properties[n].title||n,(e.required||[]).includes(n),c+1)));else if(e.type===`array`){let n=Array.isArray(r)?r:[];n.slice(0,20).forEach((n,r)=>_.push({tag:`section`,className:`connection-array`,children:h(e.items||{},t.concat(r),n,`Item `+(r+1),!0,c+1).concat([{tag:`button`,text:`Remove item`,action:p(`remove`,t.concat(r),e),disabled:v}])})),n.length>20&&_.push({tag:`p`,text:`Showing 20 items. All selected items remain in this input.`}),_.push({tag:`button`,text:`Add item`,action:p(`add`,t,e),disabled:v||n.length>=20})}else Array.isArray(e.enum)&&e.enum.length&&e.enum.every(e=>typeof e==`string`)?_.push({tag:`select`,id:`control-${f.length}`,value:r===void 0?``:String(r),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240),children:[{tag:`option`,value:``,text:`Choose…`},...e.enum.slice(0,100).map(e=>({tag:`option`,value:e,text:e}))]}):e.type===`boolean`?_.push({tag:`input`,id:`control-${f.length}`,type:`checkbox`,checked:r===!0,action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240)}):[`integer`,`number`].includes(e.type)?_.push({tag:`input`,id:`control-${f.length}`,type:`number`,value:r===void 0?``:String(r),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240),...e.minimum===void 0?{}:{min:e.minimum},...e.maximum===void 0?{}:{max:e.maximum},step:e.type===`integer`?1:`any`}):e.type===`string`||!e.type?_.push({tag:`textarea`,id:`control-${f.length}`,value:r===void 0?``:String(r).slice(0,1e4),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240)}):_.push({tag:`p`,text:`Select a compatible upstream value for this field.`});return _}let g=[];for(let[n,r]of Object.entries(t)){let t=e.properties?.[r];if(!t)throw Error(`Choose a schema-declared input.`);let a=(e.required||[]).includes(r);if(!a&&Array.isArray(c)&&c.includes(r))continue;let o=m(t,h(t,[n],i[n],t.title||r,a,0));(Array.isArray(s)&&s.includes(r)&&!a?g:d).push(o)}return g.length&&d.push({tag:`details`,className:`sm-more`,children:[{tag:`summary`,text:`More options · ${g.length}`},...g]}),{tree:d,actions:f}}function d(e,t,i){r(t),r(i);let a=t.find(e=>e.id===i.action);if(!a)throw Error(`The field changed. Read its current controls.`);if(n.has(a.path[0]))throw Error(`This input is connected. Change its source in Flow.`);if(a.kind===`add`){let t=o(e,a.path)||[];if(!Array.isArray(t)||t.length>=20)throw Error(`Use at most 20 locally edited items.`);return s(e,a.path,[...t,c(a.s.items||{})])}if(a.kind===`remove`){let t=a.path.slice(0,-1),n=o(e,t);if(!Array.isArray(n))throw Error(`The list changed.`);return s(e,t,n.filter((e,t)=>t!==a.path.at(-1)))}let l=a.s.type===`boolean`?i.checked:[`integer`,`number`].includes(a.s.type)?i.value===``?NaN:Number(i.value):i.value;if(typeof l==`number`&&(!Number.isFinite(l)||a.s.type===`integer`&&!Number.isSafeInteger(l)))throw Error(`Enter a valid number.`);return s(e,a.path,l)}function f(e,t,a){let o=i(e);r(t),r(a);for(let e of Object.keys(a))!n.has(e)&&Object.hasOwn(t,e)&&(o[e]=i(t[e]));return o}function p(e,t,a){r(e),r(t),r(a);let o={},s={};for(let r of Object.keys(a))!n.has(r)&&Object.hasOwn(e,r)&&JSON.stringify(e[r])!==JSON.stringify(t[r])&&(o[r]=i(e[r]),s[r]=Object.hasOwn(t,r)?{exists:!0,value:i(t[r])}:{exists:!1});if(JSON.stringify(o).length>393216)throw Error(`Saved task fields exceed 384 KiB. Use an upstream source for larger data.`);return{patch:o,before:s,changed:Object.keys(o).length>0}}function m(e,{maximumFields:t=20}={}){if(e=i(e),!Number.isSafeInteger(t)||t<1||t>100)throw Error(`Use a bounded result preview.`);let n=6e3,r=!1,a=e=>{let t=String(e).replaceAll(`_`,` `).slice(0,120);return t.charAt(0).toUpperCase()+t.slice(1)},o=e=>{let t=e==null?`—`:typeof e==`boolean`?e?`Yes`:`No`:String(e);return t.length>500?t.slice(0,500)+`…`:t},s=e=>typeof e==`object`&&!!e&&!Array.isArray(e),c=(e,t)=>(n--,{tag:e,...t}),l=e=>`${e.length} ${e.length===1?`item`:`items`}${e.length>50?`, showing the first 50`:``}`,u=(e,t)=>{if(n<=0||t>5)return r=!0,c(`p`,{text:`…`});if(typeof e!=`object`||!e)return c(`p`,{text:o(e)});if(Array.isArray(e)){if(!e.length)return c(`p`,{text:`No items`});let n=e.slice(0,50);if(e.length>50&&(r=!0),n.every(s)){let t=[...new Set(n.flatMap(e=>Object.keys(e)))],i=t.slice(0,12);t.length>12&&(r=!0);let s=e=>typeof e==`object`&&e?Array.isArray(e)?e.map(s).join(`, `):Object.values(e).map(s).join(`: `):o(e),u=e=>{let t=s(e);return t.length>200?t.slice(0,200)+`…`:t};return c(`div`,{className:`connection-table`,children:[c(`small`,{text:l(e)}),c(`table`,{children:[c(`thead`,{children:[c(`tr`,{children:i.map(e=>c(`th`,{text:a(e)}))})]}),c(`tbody`,{children:n.map(e=>c(`tr`,{children:i.map(t=>c(`td`,{text:u(e[t])}))}))})]})]})}return c(`div`,{children:[c(`small`,{text:l(e)}),c(`ul`,{children:n.map(e=>c(`li`,{children:[u(e,t+1)]}))})]})}let i=Object.entries(e),d=i.filter(([,e])=>typeof e!=`object`||!e),f=i.filter(([,e])=>typeof e==`object`&&!!e),p=[];d.length&&p.push(c(`table`,{className:`connection-fields`,children:[c(`tbody`,{children:d.map(([e,t])=>c(`tr`,{children:[c(`th`,{text:a(e)}),c(`td`,{text:o(t)})]}))})]}));for(let[e,n]of f)p.push(t===0?c(`section`,{children:[c(`h4`,{text:a(e)}),u(n,t+1)]}):c(`details`,{children:[c(`summary`,{text:a(e)}),u(n,t+1)]}));return p.length||p.push(c(`p`,{text:`No fields`})),c(`div`,{children:p})};return[{tag:`h3`,text:`Result`},u(e,0),...r?[{tag:`small`,text:`Preview is bounded. The saved result retains its complete permitted data.`}]:[]]}function h(e){if(typeof e!=`string`||!/^[A-Z]{3}$/.test(e))throw Error(`Choose a three-letter currency code.`);return new Intl.NumberFormat(`en`,{style:`currency`,currency:e}).resolvedOptions().maximumFractionDigits}function g(e,t){let n=h(t),r=String(e).split(`.`);if(r.length>2||!/^\d+$/.test(r[0])||r[1]!==void 0&&(!/^\d+$/.test(r[1])||r[1].length>n))throw Error(`Enter a budget using this currency’s supported decimal places.`);let i=Number(r[0])*10**n+Number((r[1]||``).padEnd(n,`0`));if(!Number.isSafeInteger(i)||i<=0)throw Error(`Enter a positive supported budget.`);return i}function _(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`Use an exact saved budget.`);return new Intl.NumberFormat(void 0,{style:`currency`,currency:t}).format(e/10**h(t))}return Object.freeze({read:o,set:s,controls:u,change:d,fromState:f,edits:p,preview:m,currencyDigits:h,minorUnits:g,formatMoney:_})}function ur(){let e=Math.PI*2,t=Math.PI/180,n=3.5,r=(e,t=0,n=1)=>Math.max(t,Math.min(n,e)),i=(e,t,n)=>e+(t-e)*n,a=e=>e-Math.floor(e),o=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,s=e=>o(r(e/.3))*o(r((1-e)/.3)),c=(e,t,n)=>[i(e[0],t[0],n),i(e[1],t[1],n)],l=(e,n,r=50,i=50)=>{let a=(-90+60*e)*t;return[r+n*Math.cos(a),i+n*Math.sin(a)]},u=(e,t)=>{let n=a(e)*6,r=Math.floor(n);return c(l(r,t),l(r+1,t),n-r)},d=(e,t)=>{let n=t?[...e,e[0]]:e,r=[0];for(let e=1;e<n.length;e++)r.push(r[e-1]+Math.hypot(n[e][0]-n[e-1][0],n[e][1]-n[e-1][1]));let i=r[r.length-1];return e=>{let t=a(e)*i,o=1;for(;o<r.length-1&&r[o]<t;)o++;return c(n[o-1],n[o],(t-r[o-1])/(r[o]-r[o-1]||1))}},f=e=>{let t=[];for(let n=0;n<720;n++)t.push(e(n/720));let n=d(t,!0);return[...Array(200)].map((e,t)=>n(t/200))},p=f(e=>u(e,36)),m=[0,1,2,3,4,5].map(e=>l(e,36)),h=[m[0],m[1],m[2],m[3],m[4],m[5],m[0],[50,50],m[2],m[3],m[4],[50,50]],g=[0,1,2].map(e=>l(e*2,40,50,54)),_=[[f(t=>[50+36*Math.sin(e*t),50-36*Math.cos(e*t)]),2,!1],[f(d(h,!0)),1,!1],[f(d(g,!0)),2,!0],[f(t=>[50+40*Math.sin(e*t),50-20*Math.sin(2*e*t)]),1,!0],[f(t=>[50+36*Math.sin(3*e*t),50-36*Math.cos(2*e*t)]),1,!1],[f(t=>{let n=e*t;return[50+26*Math.sin(n)+12*Math.sin(-5*n),50-26*Math.cos(n)-12*Math.cos(-5*n)]}),1,!0],[e=>p.map(t=>{let n=t[0]-50,r=t[1]-50,i=1+.16*Math.sin(6*Math.atan2(n,-r)-e*8);return[50+n*i,50+r*i]}),2,!1]],v=e=>{let t=_.length*n,i=a(e/t)*t,l=Math.min(_.length-1,Math.floor(i/n)),u=r((i-l*n)/n),[d,f,m]=_[l],h=typeof d==`function`?d(e):d,g=s(u),v=p.map((e,t)=>c(e,h[t],g)),y=e=>{let t=a(e)*200,n=Math.floor(t)%200;return c(v[n],v[(n+1)%200],t-Math.floor(t))},b=22+8*g,x=(e*40+100*f*o(u))%100,S=x+50*g*!!m;return{d:`M`+v.map(e=>e[0].toFixed(2)+` `+e[1].toFixed(2)).join(`L`)+`Z`,len:b,offsets:[x,S],heads:[y((x+b)/100),y((S+b)/100)]}},y=(e,t)=>{let[n,r,i,a,o]=e;n.setAttribute(`d`,t.d),[r,i].forEach((e,n)=>{e.setAttribute(`d`,t.d),e.setAttribute(`stroke-dasharray`,`${t.len} ${100-t.len}`),e.setAttribute(`stroke-dashoffset`,String(-t.offsets[n]))}),[a,o].forEach((e,n)=>{e.setAttribute(`cx`,t.heads[n][0].toFixed(2)),e.setAttribute(`cy`,t.heads[n][1].toFixed(2))})};return{frame:v,paint:y,run:e=>{let t=e?[...e.querySelectorAll(`.sm-trace-track,.sm-trace-dash,.sm-trace-head`)]:[];if(t.length<5||(y(t,v(0)),window.matchMedia&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches))return;let n=performance.now();requestAnimationFrame(function r(i){e.isConnected&&(y(t,v((i-n)/1e3)),requestAnimationFrame(r))})}}}var dr=s((e=>{var t=f(),n=Symbol.for(`react.element`),r=Symbol.for(`react.fragment`),i=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var s,c={},l=null,u=null;for(s in r!==void 0&&(l=``+r),t.key!==void 0&&(l=``+t.key),t.ref!==void 0&&(u=t.ref),t)i.call(t,s)&&!o.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)c[s]===void 0&&(c[s]=t[s]);return{$$typeof:n,type:e,key:l,ref:u,props:c,_owner:a.current}}e.Fragment=r,e.jsx=s,e.jsxs=s})),fr=s(((e,t)=>{t.exports=dr()})),V=fr(),{frame:pr,paint:mr}=ur(),hr=pr;function gr({size:e=20,paused:t=!1,className:n=``}){let r=(0,v.useRef)([]),i=(0,v.useRef)(0),a=e=>t=>{r.current[e]=t};return(0,v.useEffect)(()=>{let e=[...r.current];if(e.length<5||e.some(e=>!e))return;let n=t||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;if(mr(e,hr(i.current)),n)return;let a=performance.now()-i.current*1e3,o=requestAnimationFrame(function t(n){i.current=(n-a)/1e3,mr(e,hr(i.current)),o=requestAnimationFrame(t)});return()=>cancelAnimationFrame(o)},[t]),(0,V.jsxs)(`svg`,{className:`sm-trace-loader${n?` ${n}`:``}`,width:e,height:e,viewBox:`0 0 100 100`,"aria-hidden":`true`,focusable:`false`,children:[(0,V.jsx)(`path`,{ref:a(0),className:`sm-trace-track`,fill:`none`,strokeWidth:`3`,strokeLinejoin:`round`,strokeLinecap:`round`}),(0,V.jsx)(`path`,{ref:a(1),className:`sm-trace-dash`,fill:`none`,strokeWidth:`5`,strokeLinejoin:`round`,strokeLinecap:`round`,pathLength:`100`}),(0,V.jsx)(`path`,{ref:a(2),className:`sm-trace-dash`,fill:`none`,strokeWidth:`5`,strokeLinejoin:`round`,strokeLinecap:`round`,pathLength:`100`}),(0,V.jsx)(`circle`,{ref:a(3),className:`sm-trace-head`,r:`5.5`}),(0,V.jsx)(`circle`,{ref:a(4),className:`sm-trace-head`,r:`5.5`})]})}function _r({label:e=`Loading`,fill:t=!1}){return(0,V.jsxs)(`div`,{className:`sm-loading-screen${t?` is-fill`:``}`,role:`status`,children:[(0,V.jsx)(gr,{size:96,className:`sm-loading-trace`}),(0,V.jsx)(`span`,{className:`sm-sr`,children:e})]})}function vr(e,t,n=!1){if(t>=e.length)return null;let r=e[t];if(r===0)return null;let i=1,a=128;for(;!(r&a);)if(i++,a>>=1,i>8)return null;if(t+i>e.length)return null;let o=n?r:r&a-1,s=(r&a-1)==a-1;for(let n=1;n<i;n++)o=o*256+e[t+n],e[t+n]!==255&&(s=!1);return{value:o,length:i,unknown:!n&&s}}function yr(e,t){let n=vr(e,t,!0);if(!n)return null;let r=vr(e,t+n.length);if(!r)return null;let i=t+n.length+r.length;return{id:n.value,idLength:n.length,sizeLength:r.length,size:r.unknown?null:r.value,dataOffset:i,end:r.unknown?null:i+r.value}}function br(e,t){let n=new Uint8Array(t),r=e;for(let e=t-1;e>0;e--)n[e]=r%256,r=Math.floor(r/256);return n[0]=r|256>>t,n}function xr(e){let t=yr(e,0);if(!t||t.id!==Tr.ebml||t.end===null)return null;let n=yr(e,t.end);if(!n||n.id!==Tr.segment)return null;let r=n.dataOffset,i=n.end===null?e.length:Math.min(e.length,n.end);for(;r<i;){let t=yr(e,r);if(!t||t.end===null)return null;if(t.id===Tr.info){if(t.end>e.length)return null;let r=Dr,a=null,o=t.dataOffset;for(;o<t.end;){let n=yr(e,o);if(!n||n.end===null||n.end>t.end)return null;n.id===Tr.timecodeScale&&(r=kr(e,n.dataOffset,n.size)),n.id===Tr.duration&&[4,8].includes(n.size)&&(a={offset:n.dataOffset,length:n.size,value:Or(e,n.dataOffset,n.size)}),o=n.end}let s=t.end<i?yr(e,t.end):null;return{segment:n,info:t,timecodeScale:r,duration:a,voidAfter:s&&s.id===Tr.voidElement&&s.end!==null?s:null}}r=t.end}return null}function Sr(e,t){let n=xr(e);if(!n||!(t>0))return null;let r=t*Dr/n.timecodeScale;if(n.duration){let t=e.slice(),i=new DataView(t.buffer,t.byteOffset+n.duration.offset,n.duration.length);return n.duration.length===4?i.setFloat32(0,r):i.setFloat64(0,r),t}let i=new Uint8Array(11);i.set([68,137,136]),new DataView(i.buffer,3,8).setFloat64(0,r);let{info:a}=n,o=e.subarray(a.dataOffset,a.end),s=o.length+i.length;if(s>=2**(7*a.sizeLength)-1)return null;let c=i.length,l=[e.subarray(0,a.dataOffset-a.sizeLength),br(s,a.sizeLength),o,i],u=n.voidAfter;if(u){let t=u.end-(u.dataOffset-u.sizeLength-u.idLength);if(t===c)return Cr([...l,e.subarray(u.end)]);let n=t-c-u.idLength-u.sizeLength;if(n>=0&&n<2**(7*u.sizeLength)-1)return Cr([...l,new Uint8Array([Tr.voidElement]),br(n,u.sizeLength),new Uint8Array(n),e.subarray(u.end)])}let d=Cr([...l,e.subarray(a.end)]);if(n.segment.end!==null){let e=n.segment.size+c;if(e>=2**(7*n.segment.sizeLength)-1)return null;d.set(br(e,n.segment.sizeLength),n.segment.dataOffset-n.segment.sizeLength)}return d}function Cr(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}async function wr(e,t){if(!/^(?:video|audio)\/webm/i.test(e?.type||``)||!(t>0))return e;try{let n=new Uint8Array(await e.slice(0,Er).arrayBuffer()),r=xr(n);if(!r)return e;let i=r.voidAfter?r.voidAfter.end:r.info.end,a=Sr(n.subarray(0,i),t);return a?new Blob([a,e.slice(i)],{type:e.type}):e}catch{return e}}var Tr,Er,Dr,Or,kr,Ar=o((()=>{Tr={ebml:440786851,segment:408125543,info:357149030,timecodeScale:2807729,duration:17545,voidElement:236},Er=1048576,Dr=1e6,Or=(e,t,n)=>{let r=new DataView(e.buffer,e.byteOffset+t,n);return n===4?r.getFloat32(0):r.getFloat64(0)},kr=(e,t,n)=>{let r=0;for(let i=0;i<n;i++)r=r*256+e[t+i];return r}}));function jr(e,{isTypeSupported:t,canPlayType:n}={}){let r=Fr[e===`microphone`?`audio`:`video`].filter(e=>{try{return t?.(e)===!0}catch{return!1}});return r.find(e=>{try{return!!n?.(e)}catch{return!1}})||r[0]}function Mr({width:e,height:t,frameRate:n}={}){let r=(Number(e)||1920)*(Number(t)||1080),i=Ir.find(([e])=>r>=e)[1];return Math.round(i*((Number(n)||30)>=50?1.5:1))}function Nr({resolution:e=`1080p`,frameRate:t=30}={}){let n=Rr[e]===void 0?Rr[`1080p`]:Rr[e];return{frameRate:{ideal:t,max:60},...n?{width:{max:n.width},height:{max:n.height}}:{}}}function Pr({platform:e=`browser`,bitsPerSecond:t,quota:n=null,used:r=0}={}){let i=zr[e]||zr.browser,a=Number.isFinite(n)&&n>0?Math.min(i.bytes,Math.max(0,n-(Number(r)||0))):i.bytes,o=t>0?Math.floor(a*8/t):i.seconds;return{seconds:Math.max(0,Math.min(i.seconds,o)),bytes:a}}var Fr,Ir,Lr,Rr,zr,Br,Vr=o((()=>{Fr=Object.freeze({video:Object.freeze([`video/webm;codecs=h264`,`video/webm;codecs=vp9`,`video/webm`,`video/webm;codecs=vp8`,`video/mp4;codecs=avc1.42E01E`,`video/mp4`]),audio:Object.freeze([`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`])}),Ir=Object.freeze([[8294400,24e6],[3686400,14e6],[2073600,8e6],[0,5e6]]),Lr=Object.freeze({voice:128e3,system:192e3}),Rr=Object.freeze({"1080p":{width:1920,height:1080},source:null}),zr=Object.freeze({browser:Object.freeze({seconds:1800,bytes:2147483648}),desktop:Object.freeze({seconds:14400,bytes:1/0}),legacyDesktop:Object.freeze({seconds:1800,bytes:134217728})}),Br=(e,t,n=Date.now())=>`${e}-recording-${new Date(n).toISOString().replace(/[:.]/g,`-`).slice(0,19)}.${/mp4/.test(t||``)?`mp4`:/ogg/.test(t||``)?`ogg`:`webm`}`}));Ar(),Vr();var Hr=Object.freeze({fps:Object.freeze({min:1,max:30,default:15}),width:Object.freeze({min:160,max:1280,default:640}),sampleRate:Object.freeze({min:8e3,max:48e3,default:16e3}),inFlightFrames:2,audioChunk:4096,seconds:3600}),Ur=(e,{min:t,max:n,default:r},i)=>{if(e==null)return r;let a=Number(e);if(!Number.isInteger(a)||a<t||a>n)throw Error(`live.start ${i} is a whole number from ${t} to ${n}.`);return a};function Wr(e={}){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`live.start takes {camera, microphone, fps, width, sampleRate}.`);let t=e.camera===!0,n=e.microphone===!0;if(!t&&!n)throw Error(`live.start needs camera: true, microphone: true or both.`);return{camera:t,microphone:n,fps:Ur(e.fps,Hr.fps,`fps`),width:Ur(e.width,Hr.width,`width`),sampleRate:Ur(e.sampleRate,Hr.sampleRate,`sampleRate`)}}var Gr=e=>{try{for(let t of e?.getTracks?.()||[])t.stop()}catch{}},Kr=e=>Math.max(2,Math.round(e/2)*2);function qr(e,{camera:t,microphone:n,fps:r,width:i,sampleRate:a,onFrame:o=()=>{},onAudio:s=()=>{},onEnded:c=()=>{},seconds:l=Hr.seconds,now:u=()=>performance.now(),doc:d=globalThis.document,toBitmap:f=(...e)=>globalThis.createImageBitmap(...e),AudioContextClass:p=globalThis.AudioContext||globalThis.webkitAudioContext}){let m=u(),h={camera:!!t,microphone:!!n,fps:r,width:0,height:0,sampleRate:0},g=!1,_=Hr.inFlightFrames,v=0,y=0,b=null,x=!1,S=null,C=null,w=null,T=null,E=setTimeout(()=>D(`time`),l*1e3),D=(t=`stopped`)=>{if(!g){g=!0,clearTimeout(b),clearTimeout(E);try{w&&(w.onaudioprocess=null),T?.disconnect?.(),w?.disconnect?.()}catch{}try{C?.close?.()}catch{}if(S){try{S.pause()}catch{}S.srcObject=null}Gr(e),c(t)}};for(let t of e?.getTracks?.()||[])t.addEventListener?.(`ended`,()=>D(`ended`));let O=()=>{let e=S?.videoWidth||0,t=S?.videoHeight||0;if(!e||!t)return null;let n=Kr(Math.min(i,e));return{width:n,height:Kr(n*t/e)}},k=async()=>{if(b=null,g)return;let e=O();if(_>0&&!x&&e&&S.readyState>=2){x=!0,_--;try{let t=await f(S,{resizeWidth:e.width,resizeHeight:e.height,resizeQuality:`low`});g?t.close?.():(h.width=e.width,h.height=e.height,o(t,{index:v++,timestamp:Math.round(u()-m),width:e.width,height:e.height}))}catch{_++}finally{x=!1}}g||(b=setTimeout(k,1e3/r))};return{ready:(async()=>{try{if(t){if(S=d.createElement(`video`),S.muted=!0,S.playsInline=!0,S.srcObject=e,await S.play(),g)return h;let t=O();t&&(h.width=t.width,h.height=t.height),b=setTimeout(k,0)}if(n){if(typeof p!=`function`)throw Error(`This browser cannot read the microphone live.`);try{C=new p({sampleRate:a}),T=C.createMediaStreamSource(e)}catch{try{C?.close?.()}catch{}C=new p,T=C.createMediaStreamSource(e)}w=C.createScriptProcessor(Hr.audioChunk,1,1),w.onaudioprocess=e=>{g||s(new Float32Array(e.inputBuffer.getChannelData(0)),{index:y++,timestamp:Math.round(u()-m),sampleRate:C.sampleRate})},T.connect(w),w.connect(C.destination),await C.resume?.().catch?.(()=>{}),h.sampleRate=C.sampleRate}return h}catch(e){throw D(`error`),e}})(),info:h,ack(){!g&&_<Hr.inFlightFrames&&_++},stop:D,get stopped(){return g}}}var Jr=Object.freeze({folders:4,entries:1e3,textBytes:1048576,pathLength:1024,depth:32}),Yr=Object.freeze([`folder.pick`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`,`folder.write`]);Object.freeze([`folder.shared`,`folder.list`,`folder.read`]);var Xr=/^[^\0/\\:*?"<>|]{1,255}$/,Zr=/^(con|prn|aux|nul|com\d|lpt\d)(\..*)?$/i,Qr=e=>{throw Error(e)},$r=e=>e.startsWith(`.`),ei=`Hidden files and folders are not shared with Blocks.`,ti=new Set(`png.jpg.jpeg.gif.webp.avif.bmp.tif.tiff.heic.heif.exr.dpx.tga.psd.mp4.mov.webm.mkv.avi.m4v.mxf.mts.mp3.wav.m4a.aac.ogg.oga.opus.flac.aif.aiff.txt.srt.vtt.ass.ssa.sbv.csv.tsv.edl.otio.cube.pdf`.split(`.`)),ni=/^(cmakelists|requirements|constraints|llms)([.-][^.]*)?\.txt$/i,ri=/\.(app|bundle|framework|plugin|kext|appex|xpc|prefpane|saver|workflow|action|service|component|qlgenerator|mdimporter)$/i;function ii(e){let t=e.at(-1),n=t.lastIndexOf(`.`);if(e.slice(0,-1).some(e=>ri.test(e))||ni.test(t))return!1;let r=n>0?t.slice(n+1):``;return/^[a-z0-9]+$/i.test(r)&&ti.has(r.toLowerCase())||/^[^.].*\.stillmade\.json$/.test(t)}var ai=e=>`A Block cannot create or replace ${e}: folder.write writes media, subtitles, plain text, tables and <name>.stillmade.json only.`;function oi(e){if(e===void 0||e===``)return[];(typeof e!=`string`||e.length>Jr.pathLength)&&Qr(`Name a file by its path inside the folder, like photos/cover.png.`);let t=e.split(`/`);return(t.length>Jr.depth||t.some(e=>!Xr.test(e)||e===`.`||e===`..`||e!==e.trim()||e.endsWith(`.`)||Zr.test(e)||/~\d/.test(e)))&&Qr(`${e} is not a path inside the chosen folder.`),t.some($r)&&Qr(ei),t}function si(e){return e.filter(e=>!$r(e.name)).sort((e,t)=>e.kind===t.kind?e.name.localeCompare(t.name):e.kind===`folder`?-1:1)}Kt();var ci=()=>typeof globalThis.showDirectoryPicker==`function`,li=e=>`blockFolders:${e}`,ui=(e,t)=>{throw Object.assign(Error(e),t?{code:t}:{})},di=e=>[`SecurityError`,`NotAllowedError`].includes(e?.name)&&!/abort|cancel/i.test(e?.message||``);async function fi(e){/^[a-f0-9]{64}$/.test(e||``)&&await Gt(zt,li(e))}async function pi(e,t){try{return await e.getDirectoryHandle(t),`folder`}catch(e){if(e?.name===`TypeMismatchError`)return`file`}try{return await e.getFileHandle(t),`file`}catch(e){if(e?.name===`TypeMismatchError`)return`folder`}return null}function mi({key:e,digest:t,name:n=`this Block`,permissions:r=[],askToStart:i,importMedia:a,mediaBlob:o,pick:s=e=>globalThis.showDirectoryPicker(e)}){let c=null,l=async()=>{if(c)return c;c=new Map;let n=e?await Ht(zt,li(e)).catch(()=>null):null;if(n&&n.digest!==t)return await fi(e),c;for(let e of n?.folders||[])e?.handle&&typeof e.id==`string`&&c.set(e.id,e);return c},u=async()=>{if(!e)return;let n=[...c.values()].slice(0,Jr.folders);n.length?await Wt(zt,{digest:t,folders:n},li(e)):await fi(e)},d=async e=>{let t={mode:e.write?`readwrite`:`read`};if(await e.handle.queryPermission?.(t)===`granted`)return;let n;try{n=await e.handle.requestPermission(t)}catch(r){if(!di(r)||!i)throw r;await i({kind:`folder-access`,folder:e.name,write:e.write}),n=await e.handle.requestPermission(t)}n!==`granted`&&ui(`StillMade cannot use ${e.name} until you allow it.`,`FOLDER_ACCESS`)},f=async(e,{write:t=!1}={})=>{let n=typeof e==`string`?(await l()).get(e):null;return n||ui(`Choose a folder first; this one is not shared with this Block.`),t&&!n.write&&ui(`This folder was shared for reading only.`),await d(n),n},p=async(e,t,{create:n=!1}={})=>{let r=e;for(let e of t)try{r=await r.getDirectoryHandle(e,{create:n})}catch(e){if(e?.name===`TypeMismatchError`&&ui(`That path is not a folder.`),e?.name===`NotFoundError`)return null;throw e}return r},m=()=>({folders:[...c.values()].map(({id:e,name:t,write:n})=>({id:e,name:t,write:n}))});return{async invoke(e,t={}){if(Yr.includes(e)||ui(`Unknown folder operation`),await l(),e===`folder.shared`)return m();if(e===`folder.forget`)return c.delete(t.folder)||ui(`That folder is not shared with this Block.`),await u(),{forgotten:!0};if(e===`folder.pick`){let e=t.write===!0;e&&!r.includes(`folder.write`)&&ui(`This Block did not ask to change files.`),c.size>=Jr.folders&&ui(`A Block can use at most ${Jr.folders} folders. Forget one first.`);let a={mode:e?`readwrite`:`read`,id:`stillmade-block-folder`},o;try{o=await s(a)}catch(t){if(t?.name===`AbortError`&&ui(`No folder was chosen.`),!di(t)||!i)throw t;await i({kind:`folder`,write:e,name:n});try{o=await s(a)}catch(e){throw e?.name===`AbortError`&&ui(`No folder was chosen.`),e}}$r(o.name)&&ui(e?`Choose a folder that is not hidden for a Block to change.`:ei),e&&await pi(o,`.git`)&&ui(`Choose a folder outside a code repository for a Block to change.`);let l=null;for(let e of c.values())await e.handle.isSameEntry?.(o)&&(l=e);let d={id:l?.id||crypto.randomUUID(),name:o.name,write:e,handle:o,chosenAt:Date.now()};return c.set(d.id,d),await u(),{folder:{id:d.id,name:d.name,write:e}}}let d=await f(t.folder,{write:e===`folder.write`}),h=oi(t.path);if(e===`folder.list`){let e=await p(d.handle,h);e||ui(`That folder does not exist inside the chosen folder.`);let t=[],n=0;for await(let[r,i]of e.entries()){if(++n>Jr.entries)break;if(!$r(r)){if(i.kind===`directory`)t.push({name:r,kind:`folder`,size:0,modified:null});else{let e=await i.getFile().catch(()=>null);e&&t.push({name:r,kind:`file`,size:e.size,modified:new Date(e.lastModified).toISOString()})}}}return{entries:si(t),truncated:n>Jr.entries}}h.length||ui(`Name a file inside the folder.`);let g=h.slice(0,-1),_=h.at(-1);if(e===`folder.read`){let e=await p(d.handle,g),n;try{n=e&&await e.getFileHandle(_)}catch{n=null}n||ui(`That file does not exist in the chosen folder.`);let r=await n.getFile();return t.as===`media`?{asset:await a(r,n),size:r.size}:(r.size>Jr.textBytes&&ui(`Read files up to 1 MB as text, or media files as media.`),{text:await r.text(),size:r.size})}ii(h)||ui(ai(_));let v;typeof t.text==`string`?(new TextEncoder().encode(t.text).byteLength>Jr.textBytes&&ui(`Write at most 1 MB of text at a time.`),v=t.text):t.asset&&typeof t.asset.assetId==`string`?(v=await o(t.asset).catch(()=>null),v||ui(`Write media this Block saved or received on this device.`)):ui(`folder.write takes text or a saved asset.`);let y=d.handle;await pi(y,`.git`)&&ui(`This Block cannot change files inside a code repository.`);for(let e of g)await pi(y,e)===`file`&&ui(`That path is not a folder.`),y=await y.getDirectoryHandle(e,{create:!0}),await pi(y,`.git`)&&ui(`This Block cannot change files inside a code repository.`);let b=await pi(y,_);b===`folder`&&ui(`A folder already has that name.`),b&&t.replace!==!0&&ui(`That file exists. Pass replace: true to replace it.`);let x=await(await y.getFileHandle(_,{create:!0})).createWritable({keepExistingData:!1});try{await x.write(v),await x.close()}catch(e){throw await x.abort?.().catch(()=>{}),e}return{written:h.join(`/`),replaced:!!b}}}}Tt(),Yt();async function hi(e,t=`preview`){let n=String(t||`preview`),r=/(^|:)preview$/.test(n),i=[`stillmade-block-access/1`,qt()||`anonymous`,n,e?.manifest?.id||``,r?await gt(e):``].join(`|`),a=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(i)));return Array.from(a,e=>e.toString(16).padStart(2,`0`)).join(``)}async function gi(e,t,{bridge:n=globalThis.stillmadeDesktop?.blockDesktop}={}){let r=await hi(e,t);await Promise.all([n?.forgetRemembered?.(r).catch(()=>{}),fi(r).catch(()=>{})])}var _i,vi,yi,bi,xi=o((()=>{_i=`modulepreload`,vi=function(e){return`/`+e},yi={},bi=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=vi(t,n),t=s(t),t in yi)return;yi[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:_i,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})}}));function Si(e){return B(e?.version===1&&Ci.every(t=>e[t]!==void 0&&(typeof e[t]==`function`||[`toast`,`presenterHost`,`upgradeReasons`].includes(t))),`HOST_SERVICES`,`Shared native UI requires version 1 of its declared runtime host.`),e}var Ci,wi=o((()=>{Tt(),Ci=Object.freeze(`loadMediaBlob.loadMediaArrayBuffer.resolveDesktopMediaUrl.isMissing.runFinalEdit.runStructureEdit.runMotionGraphics.transcribeAudio.useTier.requestUpgrade.upgradeReasons.confirm.alert.toast.HelpHint.downloadUrlLocally.extensionFromUrl.safeDownloadName.proxiedMediaUrl.uploadReferenceImage.getAllAssets.addAsset.recordAssets.listProjects.loadProject.stockGrid.stockSelect.useIsMobileUI.desktopBridge.authHeaders.useCanvas.useCanvasWriteAccess.generateReference.fetchStyleOptions.fetchStyleFromUploads.generateReferenceSheet.useReferenceExtraction.findExtractedViews.addLibraryItem.getLibraryItems.useThumb.planAllows.tagAsset.runLlmText.CanvasCommitInput.cachedObjectUrlIfPresent.presenterHost`.split(`.`))}));function Ti(e){return Di=Object.freeze(Si(e)),Di}function Ei(){if(!Di)throw Object.assign(Error(`Shared native runtime host is unavailable.`),{code:`HOST_SERVICES`});return Di}var Di,Oi=o((()=>{wi(),Di=null}));async function ki(){if(typeof VideoEncoder>`u`)return null;for(let e of Fi)try{let{supported:t}=await VideoEncoder.isConfigSupported({codec:e,width:Ii.width,height:Ii.height,framerate:Ii.framerate,bitrate:Ii.bitrate});if(t)return e}catch{}return null}async function Ai(e){if(!e)return null;try{let{supported:t}=await VideoEncoder.isConfigSupported({codec:e,width:Ii.width,height:Ii.height,framerate:Ii.framerate,bitrate:Ii.bitrate,hardwareAcceleration:`prefer-hardware`});return t?`prefer-hardware`:`no-preference`}catch{return`no-preference`}}async function ji(){if(typeof AudioEncoder>`u`)return!1;try{let{supported:e}=await AudioEncoder.isConfigSupported({codec:`mp4a.40.2`,sampleRate:44100,numberOfChannels:2,bitrate:192e3});return!!e}catch{return!1}}function Mi(){try{let e=typeof OffscreenCanvas<`u`?new OffscreenCanvas(2,2):typeof document<`u`?document.createElement(`canvas`):null;if(!e)return!1;let t=e.getContext(`2d`);if(!t||!(`filter`in t))return!1;t.filter=`blur(1px)`;let n=t.filter===`blur(1px)`;return t.filter=`none`,n}catch{return!1}}function Ni(){try{return typeof OffscreenCanvas>`u`?!1:!!new OffscreenCanvas(2,2).getContext(`2d`)}catch{return!1}}async function Pi(){let e=[],t=typeof globalThis<`u`&&globalThis.crossOriginIsolated===!0,n=typeof SharedArrayBuffer<`u`,[r,i]=await Promise.all([ki(),ji()]),a=await Ai(r),o=Ni(),s=Mi(),c=!!r&&o&&s;r||e.push(`No supported H.264 VideoEncoder config.`),o||e.push(`OffscreenCanvas 2D unavailable.`),s||e.push(`Canvas2D ctx.filter unsupported (color/LUT would be wrong) — routing to wasm.`),c&&!i&&e.push(`No AAC AudioEncoder — audio will be encoded via ffmpeg.wasm, video via WebCodecs.`);let l=t;t||e.push(`Not crossOriginIsolated — multi-threaded ffmpeg.wasm core unavailable (check COOP/COEP headers).`);let u=`none`;return c?u=`webcodecs`:l&&(u=`wasm`),{strategy:u,videoCodec:r,hardwareAcceleration:a,audioViaWebCodecs:c&&i,offscreenCanvas:o,canvasFilter:s,crossOriginIsolated:t,sharedArrayBuffer:n,notes:e}}var Fi,Ii,Li=o((()=>{Fi=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],Ii={width:1920,height:1080,framerate:24,bitrate:1e7}})),Ri,H,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,U,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,ls,us,ds,fs,ps,ms,hs,gs,_s,vs,ys,bs,xs,Ss,Cs,ws,Ts,Es,Ds,Os,ks=o((()=>{Ri=(e,t,n)=>{if(!t.has(e))throw TypeError(`Cannot `+n)},H=(e,t,n)=>(Ri(e,t,`read from private field`),n?n.call(e):t.get(e)),zi=(e,t,n)=>{if(t.has(e))throw TypeError(`Cannot add the same private member more than once`);t instanceof WeakSet?t.add(e):t.set(e,n)},Bi=(e,t,n,r)=>(Ri(e,t,`write to private field`),r?r.call(e,n):t.set(e,n),n),Vi=(e,t,n,r)=>({set _(r){Bi(e,t,r,n)},get _(){return H(e,t,r)}}),Hi=(e,t,n)=>(Ri(e,t,`access private method`),n),Ui=new Uint8Array(8),Wi=new DataView(Ui.buffer),Gi=e=>[(e%256+256)%256],Ki=e=>(Wi.setUint16(0,e,!1),[Ui[0],Ui[1]]),qi=e=>(Wi.setInt16(0,e,!1),[Ui[0],Ui[1]]),Ji=e=>(Wi.setUint32(0,e,!1),[Ui[1],Ui[2],Ui[3]]),U=e=>(Wi.setUint32(0,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),Yi=e=>(Wi.setInt32(0,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),Xi=e=>(Wi.setUint32(0,Math.floor(e/2**32),!1),Wi.setUint32(4,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3],Ui[4],Ui[5],Ui[6],Ui[7]]),Zi=e=>(Wi.setInt16(0,256*e,!1),[Ui[0],Ui[1]]),Qi=e=>(Wi.setInt32(0,2**16*e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),$i=e=>(Wi.setInt32(0,2**30*e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),ea=(e,t=!1)=>{let n=Array(e.length).fill(null).map((t,n)=>e.charCodeAt(n));return t&&n.push(0),n},ta=e=>e&&e[e.length-1],na=e=>{let t;for(let n of e)(!t||n.presentationTimestamp>t.presentationTimestamp)&&(t=n);return t},ra=(e,t,n=!0)=>{let r=e*t;return n?Math.round(r):r},ia=e=>{let t=Math.PI/180*e,n=Math.cos(t),r=Math.sin(t);return[n,r,0,-r,n,0,0,0,1]},aa=ia(0),oa=e=>[Qi(e[0]),Qi(e[1]),$i(e[2]),Qi(e[3]),Qi(e[4]),$i(e[5]),Qi(e[6]),Qi(e[7]),$i(e[8])],sa=e=>!e||typeof e!=`object`?e:Array.isArray(e)?e.map(sa):Object.fromEntries(Object.entries(e).map(([e,t])=>[e,sa(t)])),ca=e=>e>=0&&e<2**32,la=(e,t,n)=>({type:e,contents:t&&new Uint8Array(t.flat(10)),children:n}),ua=(e,t,n,r,i)=>la(e,[Gi(t),Ji(n),r??[]],i),da=e=>e.fragmented?la(`ftyp`,[ea(`iso5`),U(512),ea(`iso5`),ea(`iso6`),ea(`mp41`)]):la(`ftyp`,[ea(`isom`),U(512),ea(`isom`),e.holdsAvc?ea(`avc1`):[],ea(`mp41`)]),fa=e=>({type:`mdat`,largeSize:e}),pa=e=>({type:`free`,size:e}),ma=(e,t,n=!1)=>la(`moov`,null,[ha(t,e),...e.map(e=>ga(e,t)),n?qa(e):null]),ha=(e,t)=>{let n=ra(Math.max(0,...t.filter(e=>e.samples.length>0).map(e=>{let t=na(e.samples);return t.presentationTimestamp+t.duration})),Vo),r=Math.max(...t.map(e=>e.id))+1,i=!ca(e)||!ca(n),a=i?Xi:U;return ua(`mvhd`,+i,0,[a(e),a(e),U(Vo),a(n),Qi(1),Zi(1),Array(10).fill(0),oa(aa),Array(24).fill(0),U(r)])},ga=(e,t)=>la(`trak`,null,[_a(e,t),va(e,t)]),_a=(e,t)=>{let n=na(e.samples),r=ra(n?n.presentationTimestamp+n.duration:0,Vo),i=!ca(t)||!ca(r),a=i?Xi:U,o;return o=e.info.type===`video`?typeof e.info.rotation==`number`?ia(e.info.rotation):e.info.rotation:aa,ua(`tkhd`,+i,3,[a(t),a(t),U(e.id),U(0),a(r),Array(8).fill(0),Ki(0),Ki(0),Zi(+(e.info.type===`audio`)),Ki(0),oa(o),Qi(e.info.type===`video`?e.info.width:0),Qi(e.info.type===`video`?e.info.height:0)])},va=(e,t)=>la(`mdia`,null,[ya(e,t),ba(e.info.type===`video`?`vide`:`soun`),xa(e)]),ya=(e,t)=>{let n=na(e.samples),r=ra(n?n.presentationTimestamp+n.duration:0,e.timescale),i=!ca(t)||!ca(r),a=i?Xi:U;return ua(`mdhd`,+i,0,[a(t),a(t),U(e.timescale),a(r),Ki(21956),Ki(0)])},ba=e=>ua(`hdlr`,0,0,[ea(`mhlr`),ea(e),U(0),U(0),U(0),ea(`mp4-muxer-hdlr`,!0)]),xa=e=>la(`minf`,null,[e.info.type===`video`?Sa():Ca(),wa(),Da(e)]),Sa=()=>ua(`vmhd`,0,1,[Ki(0),Ki(0),Ki(0),Ki(0)]),Ca=()=>ua(`smhd`,0,0,[Ki(0),Ki(0)]),wa=()=>la(`dinf`,null,[Ta()]),Ta=()=>ua(`dref`,0,0,[U(1)],[Ea()]),Ea=()=>ua(`url `,0,1),Da=e=>{let t=e.compositionTimeOffsetTable.length>1||e.compositionTimeOffsetTable.some(e=>e.sampleCompositionTimeOffset!==0);return la(`stbl`,null,[Oa(e),Va(e),Ha(e),Ua(e),Wa(e),Ga(e),t?Ka(e):null])},Oa=e=>ua(`stsd`,0,0,[U(1)],[e.info.type===`video`?ka(ao[e.info.codec],e):Ra(so[e.info.codec],e)]),ka=(e,t)=>la(e,[[,,,,,,].fill(0),Ki(1),Ki(0),Ki(0),Array(12).fill(0),Ki(t.info.width),Ki(t.info.height),U(4718592),U(4718592),U(0),Ki(1),Array(32).fill(0),Ki(24),qi(65535)],[oo[t.info.codec](t),t.info.decoderConfig.colorSpace?Na(t):null]),Aa={bt709:1,bt470bg:5,smpte170m:6},ja={bt709:1,smpte170m:6,"iec61966-2-1":13},Ma={rgb:0,bt709:1,bt470bg:5,smpte170m:6},Na=e=>la(`colr`,[ea(`nclx`),Ki(Aa[e.info.decoderConfig.colorSpace.primaries]),Ki(ja[e.info.decoderConfig.colorSpace.transfer]),Ki(Ma[e.info.decoderConfig.colorSpace.matrix]),Gi(!!e.info.decoderConfig.colorSpace.fullRange<<7)]),Pa=e=>e.info.decoderConfig&&la(`avcC`,[...new Uint8Array(e.info.decoderConfig.description)]),Fa=e=>e.info.decoderConfig&&la(`hvcC`,[...new Uint8Array(e.info.decoderConfig.description)]),Ia=e=>{if(!e.info.decoderConfig)return null;let t=e.info.decoderConfig;if(!t.colorSpace)throw Error(`'colorSpace' is required in the decoder config for VP9.`);let n=t.codec.split(`.`),r=Number(n[1]),i=Number(n[2]),a=(Number(n[3])<<4)+0+Number(t.colorSpace.fullRange);return ua(`vpcC`,1,0,[Gi(r),Gi(i),Gi(a),Gi(2),Gi(2),Gi(2),Ki(0)])},La=()=>la(`av1C`,[129,0,0,0]),Ra=(e,t)=>la(e,[[,,,,,,].fill(0),Ki(1),Ki(0),Ki(0),U(0),Ki(t.info.numberOfChannels),Ki(16),Ki(0),Ki(0),Qi(t.info.sampleRate)],[co[t.info.codec](t)]),za=e=>{let t=new Uint8Array(e.info.decoderConfig.description);return ua(`esds`,0,0,[U(58753152),Gi(32+t.byteLength),Ki(1),Gi(0),U(75530368),Gi(18+t.byteLength),Gi(64),Gi(21),Ji(0),U(130071),U(130071),U(92307584),Gi(t.byteLength),...t,U(109084800),Gi(1),Gi(2)])},Ba=e=>{let t=3840,n=0,r=e.info.decoderConfig?.description;if(r){if(r.byteLength<18)throw TypeError(`Invalid decoder description provided for Opus; must be at least 18 bytes long.`);let e=ArrayBuffer.isView(r)?new DataView(r.buffer,r.byteOffset,r.byteLength):new DataView(r);t=e.getUint16(10,!0),n=e.getInt16(14,!0)}return la(`dOps`,[Gi(0),Gi(e.info.numberOfChannels),Ki(t),U(e.info.sampleRate),Zi(n),Gi(0)])},Va=e=>ua(`stts`,0,0,[U(e.timeToSampleTable.length),e.timeToSampleTable.map(e=>[U(e.sampleCount),U(e.sampleDelta)])]),Ha=e=>{if(e.samples.every(e=>e.type===`key`))return null;let t=[...e.samples.entries()].filter(([,e])=>e.type===`key`);return ua(`stss`,0,0,[U(t.length),t.map(([e])=>U(e+1))])},Ua=e=>ua(`stsc`,0,0,[U(e.compactlyCodedChunkTable.length),e.compactlyCodedChunkTable.map(e=>[U(e.firstChunk),U(e.samplesPerChunk),U(1)])]),Wa=e=>ua(`stsz`,0,0,[U(0),U(e.samples.length),e.samples.map(e=>U(e.size))]),Ga=e=>e.finalizedChunks.length>0&&ta(e.finalizedChunks).offset>=2**32?ua(`co64`,0,0,[U(e.finalizedChunks.length),e.finalizedChunks.map(e=>Xi(e.offset))]):ua(`stco`,0,0,[U(e.finalizedChunks.length),e.finalizedChunks.map(e=>U(e.offset))]),Ka=e=>ua(`ctts`,0,0,[U(e.compositionTimeOffsetTable.length),e.compositionTimeOffsetTable.map(e=>[U(e.sampleCount),U(e.sampleCompositionTimeOffset)])]),qa=e=>la(`mvex`,null,e.map(Ja)),Ja=e=>ua(`trex`,0,0,[U(e.id),U(1),U(0),U(0),U(0)]),Ya=(e,t)=>la(`moof`,null,[Xa(e),...t.map(Qa)]),Xa=e=>ua(`mfhd`,0,0,[U(e)]),Za=e=>{let t=0,n=0,r=e.type===`delta`;return n|=+r,t|=r?1:2,t<<24|n<<16|0},Qa=e=>la(`traf`,null,[$a(e),eo(e),to(e)]),$a=e=>{let t=0;t|=8,t|=16,t|=32,t|=131072;let n=e.currentChunk.samples[1]??e.currentChunk.samples[0],r={duration:n.timescaleUnitsToNextSample,size:n.size,flags:Za(n)};return ua(`tfhd`,0,t,[U(e.id),U(r.duration),U(r.size),U(r.flags)])},eo=e=>ua(`tfdt`,1,0,[Xi(ra(e.currentChunk.startTimestamp,e.timescale))]),to=e=>{let t=e.currentChunk.samples.map(e=>e.timescaleUnitsToNextSample),n=e.currentChunk.samples.map(e=>e.size),r=e.currentChunk.samples.map(Za),i=e.currentChunk.samples.map(t=>ra(t.presentationTimestamp-t.decodeTimestamp,e.timescale)),a=new Set(t),o=new Set(n),s=new Set(r),c=new Set(i),l=s.size===2&&r[0]!==r[1],u=a.size>1,d=o.size>1,f=!l&&s.size>1,p=c.size>1||[...c].some(e=>e!==0),m=0;return m|=1,m|=4*l,m|=256*u,m|=512*d,m|=1024*f,m|=2048*p,ua(`trun`,1,m,[U(e.currentChunk.samples.length),U(e.currentChunk.offset-e.currentChunk.moofOffset||0),l?U(r[0]):[],e.currentChunk.samples.map((e,a)=>[u?U(t[a]):[],d?U(n[a]):[],f?U(r[a]):[],p?Yi(i[a]):[]])])},no=e=>la(`mfra`,null,[...e.map(ro),io()]),ro=(e,t)=>ua(`tfra`,1,0,[U(e.id),U(63),U(e.finalizedChunks.length),e.finalizedChunks.map(n=>[Xi(ra(n.startTimestamp,e.timescale)),Xi(n.moofOffset),U(t+1),U(1),U(1)])]),io=()=>ua(`mfro`,0,0,[U(0)]),ao={avc:`avc1`,hevc:`hvc1`,vp9:`vp09`,av1:`av01`},oo={avc:Pa,hevc:Fa,vp9:Ia,av1:La},so={aac:`mp4a`,opus:`Opus`},co={aac:za,opus:Ba},lo=class{},uo=class extends lo{constructor(){super(...arguments),this.buffer=null}},fo=class extends lo{constructor(e){if(super(),this.options=e,typeof e!=`object`)throw TypeError(`StreamTarget requires an options object to be passed to its constructor.`);if(e.onData){if(typeof e.onData!=`function`)throw TypeError(`options.onData, when provided, must be a function.`);if(e.onData.length<2)throw TypeError(`options.onData, when provided, must be a function that takes in at least two arguments (data and position). Ignoring the position argument, which specifies the byte offset at which the data is to be written, can lead to broken outputs.`)}if(e.chunked!==void 0&&typeof e.chunked!=`boolean`)throw TypeError(`options.chunked, when provided, must be a boolean.`);if(e.chunkSize!==void 0&&(!Number.isInteger(e.chunkSize)||e.chunkSize<1024))throw TypeError(`options.chunkSize, when provided, must be an integer and not smaller than 1024.`)}},po=class extends lo{constructor(e,t){if(super(),this.stream=e,this.options=t,!(e instanceof FileSystemWritableFileStream))throw TypeError(`FileSystemWritableFileStreamTarget requires a FileSystemWritableFileStream instance.`);if(t!==void 0&&typeof t!=`object`)throw TypeError(`FileSystemWritableFileStreamTarget's options, when provided, must be an object.`);if(t&&t.chunkSize!==void 0&&(!Number.isInteger(t.chunkSize)||t.chunkSize<=0))throw TypeError(`options.chunkSize, when provided, must be a positive integer`)}},go=class{constructor(){this.pos=0,zi(this,mo,new Uint8Array(8)),zi(this,ho,new DataView(H(this,mo).buffer)),this.offsets=new WeakMap}seek(e){this.pos=e}writeU32(e){H(this,ho).setUint32(0,e,!1),this.write(H(this,mo).subarray(0,4))}writeU64(e){H(this,ho).setUint32(0,Math.floor(e/2**32),!1),H(this,ho).setUint32(4,e,!1),this.write(H(this,mo).subarray(0,8))}writeAscii(e){for(let t=0;t<e.length;t++)H(this,ho).setUint8(t%8,e.charCodeAt(t)),t%8==7&&this.write(H(this,mo));e.length%8!=0&&this.write(H(this,mo).subarray(0,e.length%8))}writeBox(e){if(this.offsets.set(e,this.pos),e.contents&&!e.children)this.writeBoxHeader(e,e.size??e.contents.byteLength+8),this.write(e.contents);else{let t=this.pos;if(this.writeBoxHeader(e,0),e.contents&&this.write(e.contents),e.children)for(let t of e.children)t&&this.writeBox(t);let n=this.pos,r=e.size??n-t;this.seek(t),this.writeBoxHeader(e,r),this.seek(n)}}writeBoxHeader(e,t){this.writeU32(e.largeSize?1:t),this.writeAscii(e.type),e.largeSize&&this.writeU64(t)}measureBoxHeader(e){return 8+(e.largeSize?8:0)}patchBox(e){let t=this.pos;this.seek(this.offsets.get(e)),this.writeBox(e),this.seek(t)}measureBox(e){if(e.contents&&!e.children)return this.measureBoxHeader(e)+e.contents.byteLength;{let t=this.measureBoxHeader(e);if(e.contents&&(t+=e.contents.byteLength),e.children)for(let n of e.children)n&&(t+=this.measureBox(n));return t}}},mo=new WeakMap,ho=new WeakMap,Co=class extends go{constructor(e){super(),zi(this,xo),zi(this,_o,void 0),zi(this,vo,new ArrayBuffer(2**16)),zi(this,yo,new Uint8Array(H(this,vo))),zi(this,bo,0),Bi(this,_o,e)}write(e){Hi(this,xo,So).call(this,this.pos+e.byteLength),H(this,yo).set(e,this.pos),this.pos+=e.byteLength,Bi(this,bo,Math.max(H(this,bo),this.pos))}finalize(){Hi(this,xo,So).call(this,this.pos),H(this,_o).buffer=H(this,vo).slice(0,Math.max(H(this,bo),this.pos))}},_o=new WeakMap,vo=new WeakMap,yo=new WeakMap,bo=new WeakMap,xo=new WeakSet,So=function(e){let t=H(this,vo).byteLength;for(;t<e;)t*=2;if(t===H(this,vo).byteLength)return;let n=new ArrayBuffer(t),r=new Uint8Array(n);r.set(H(this,yo),0),Bi(this,vo,n),Bi(this,yo,r)},wo=2**24,To=2,zo=class extends go{constructor(e){super(),zi(this,jo),zi(this,No),zi(this,Fo),zi(this,Lo),zi(this,Eo,void 0),zi(this,Do,[]),zi(this,Oo,void 0),zi(this,ko,void 0),zi(this,Ao,[]),Bi(this,Eo,e),Bi(this,Oo,e.options?.chunked??!1),Bi(this,ko,e.options?.chunkSize??wo)}write(e){H(this,Do).push({data:e.slice(),start:this.pos}),this.pos+=e.byteLength}flush(){if(H(this,Do).length===0)return;let e=[],t=[...H(this,Do)].sort((e,t)=>e.start-t.start);e.push({start:t[0].start,size:t[0].data.byteLength});for(let n=1;n<t.length;n++){let r=e[e.length-1],i=t[n];i.start<=r.start+r.size?r.size=Math.max(r.size,i.start+i.data.byteLength-r.start):e.push({start:i.start,size:i.data.byteLength})}for(let t of e){t.data=new Uint8Array(t.size);for(let e of H(this,Do))t.start<=e.start&&e.start<t.start+t.size&&t.data.set(e.data,e.start-t.start);H(this,Oo)?(Hi(this,jo,Mo).call(this,t.data,t.start),Hi(this,Lo,Ro).call(this)):H(this,Eo).options.onData?.(t.data,t.start)}H(this,Do).length=0}finalize(){H(this,Oo)&&Hi(this,Lo,Ro).call(this,!0)}},Eo=new WeakMap,Do=new WeakMap,Oo=new WeakMap,ko=new WeakMap,Ao=new WeakMap,jo=new WeakSet,Mo=function(e,t){let n=H(this,Ao).findIndex(e=>e.start<=t&&t<e.start+H(this,ko));n===-1&&(n=Hi(this,Fo,Io).call(this,t));let r=H(this,Ao)[n],i=t-r.start,a=e.subarray(0,Math.min(H(this,ko)-i,e.byteLength));r.data.set(a,i);let o={start:i,end:i+a.byteLength};if(Hi(this,No,Po).call(this,r,o),r.written[0].start===0&&r.written[0].end===H(this,ko)&&(r.shouldFlush=!0),H(this,Ao).length>To){for(let e=0;e<H(this,Ao).length-1;e++)H(this,Ao)[e].shouldFlush=!0;Hi(this,Lo,Ro).call(this)}a.byteLength<e.byteLength&&Hi(this,jo,Mo).call(this,e.subarray(a.byteLength),t+a.byteLength)},No=new WeakSet,Po=function(e,t){let n=0,r=e.written.length-1,i=-1;for(;n<=r;){let a=Math.floor(n+(r-n+1)/2);e.written[a].start<=t.start?(n=a+1,i=a):r=a-1}for(e.written.splice(i+1,0,t),(i===-1||e.written[i].end<t.start)&&i++;i<e.written.length-1&&e.written[i].end>=e.written[i+1].start;)e.written[i].end=Math.max(e.written[i].end,e.written[i+1].end),e.written.splice(i+1,1)},Fo=new WeakSet,Io=function(e){let t={start:Math.floor(e/H(this,ko))*H(this,ko),data:new Uint8Array(H(this,ko)),written:[],shouldFlush:!1};return H(this,Ao).push(t),H(this,Ao).sort((e,t)=>e.start-t.start),H(this,Ao).indexOf(t)},Lo=new WeakSet,Ro=function(e=!1){for(let t=0;t<H(this,Ao).length;t++){let n=H(this,Ao)[t];if(n.shouldFlush||e){for(let e of n.written)H(this,Eo).options.onData?.(n.data.subarray(e.start,e.end),n.start+e.start);H(this,Ao).splice(t--,1)}}},Bo=class extends zo{constructor(e){super(new fo({onData:(t,n)=>e.stream.write({type:`write`,data:t,position:n}),chunked:!0,chunkSize:e.options?.chunkSize}))}},Vo=1e3,Ho=[`avc`,`hevc`,`vp9`,`av1`],Uo=[`aac`,`opus`],Wo=2082844800,Go=[`strict`,`offset`,`cross-track-offset`],Os=class{constructor(e){if(zi(this,is),zi(this,os),zi(this,cs),zi(this,us),zi(this,fs),zi(this,ms),zi(this,gs),zi(this,vs),zi(this,bs),zi(this,Ss),zi(this,ws),zi(this,Es),zi(this,Ko,void 0),zi(this,qo,void 0),zi(this,Jo,void 0),zi(this,Yo,void 0),zi(this,Xo,null),zi(this,Zo,null),zi(this,Qo,Math.floor(Date.now()/1e3)+Wo),zi(this,$o,[]),zi(this,es,1),zi(this,ts,[]),zi(this,ns,[]),zi(this,rs,!1),Hi(this,is,as).call(this,e),e.video=sa(e.video),e.audio=sa(e.audio),e.fastStart=sa(e.fastStart),this.target=e.target,Bi(this,Ko,{firstTimestampBehavior:`strict`,...e}),e.target instanceof uo)Bi(this,qo,new Co(e.target));else if(e.target instanceof fo)Bi(this,qo,new zo(e.target));else if(e.target instanceof po)Bi(this,qo,new Bo(e.target));else throw Error(`Invalid target: ${e.target}`);Hi(this,us,ds).call(this),Hi(this,os,ss).call(this)}addVideoChunk(e,t,n,r){if(!(e instanceof EncodedVideoChunk))throw TypeError(`addVideoChunk's first argument (sample) must be of type EncodedVideoChunk.`);if(t&&typeof t!=`object`)throw TypeError(`addVideoChunk's second argument (meta), when provided, must be an object.`);if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`addVideoChunk's third argument (timestamp), when provided, must be a non-negative real number.`);if(r!==void 0&&!Number.isFinite(r))throw TypeError(`addVideoChunk's fourth argument (compositionTimeOffset), when provided, must be a real number.`);let i=new Uint8Array(e.byteLength);e.copyTo(i),this.addVideoChunkRaw(i,e.type,n??e.timestamp,e.duration,t,r)}addVideoChunkRaw(e,t,n,r,i,a){if(!(e instanceof Uint8Array))throw TypeError(`addVideoChunkRaw's first argument (data) must be an instance of Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`addVideoChunkRaw's second argument (type) must be either 'key' or 'delta'.`);if(!Number.isFinite(n)||n<0)throw TypeError(`addVideoChunkRaw's third argument (timestamp) must be a non-negative real number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`addVideoChunkRaw's fourth argument (duration) must be a non-negative real number.`);if(i&&typeof i!=`object`)throw TypeError(`addVideoChunkRaw's fifth argument (meta), when provided, must be an object.`);if(a!==void 0&&!Number.isFinite(a))throw TypeError(`addVideoChunkRaw's sixth argument (compositionTimeOffset), when provided, must be a real number.`);if(Hi(this,Es,Ds).call(this),!H(this,Ko).video)throw Error(`No video track declared.`);if(typeof H(this,Ko).fastStart==`object`&&H(this,Xo).samples.length===H(this,Ko).fastStart.expectedVideoChunks)throw Error(`Cannot add more video chunks than specified in 'fastStart' (${H(this,Ko).fastStart.expectedVideoChunks}).`);let o=Hi(this,ms,hs).call(this,H(this,Xo),e,t,n,r,i,a);if(H(this,Ko).fastStart===`fragmented`&&H(this,Zo)){for(;H(this,ns).length>0&&H(this,ns)[0].decodeTimestamp<=o.decodeTimestamp;){let e=H(this,ns).shift();Hi(this,gs,_s).call(this,H(this,Zo),e)}o.decodeTimestamp<=H(this,Zo).lastDecodeTimestamp?Hi(this,gs,_s).call(this,H(this,Xo),o):H(this,ts).push(o)}else Hi(this,gs,_s).call(this,H(this,Xo),o)}addAudioChunk(e,t,n){if(!(e instanceof EncodedAudioChunk))throw TypeError(`addAudioChunk's first argument (sample) must be of type EncodedAudioChunk.`);if(t&&typeof t!=`object`)throw TypeError(`addAudioChunk's second argument (meta), when provided, must be an object.`);if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`addAudioChunk's third argument (timestamp), when provided, must be a non-negative real number.`);let r=new Uint8Array(e.byteLength);e.copyTo(r),this.addAudioChunkRaw(r,e.type,n??e.timestamp,e.duration,t)}addAudioChunkRaw(e,t,n,r,i){if(!(e instanceof Uint8Array))throw TypeError(`addAudioChunkRaw's first argument (data) must be an instance of Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`addAudioChunkRaw's second argument (type) must be either 'key' or 'delta'.`);if(!Number.isFinite(n)||n<0)throw TypeError(`addAudioChunkRaw's third argument (timestamp) must be a non-negative real number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`addAudioChunkRaw's fourth argument (duration) must be a non-negative real number.`);if(i&&typeof i!=`object`)throw TypeError(`addAudioChunkRaw's fifth argument (meta), when provided, must be an object.`);if(Hi(this,Es,Ds).call(this),!H(this,Ko).audio)throw Error(`No audio track declared.`);if(typeof H(this,Ko).fastStart==`object`&&H(this,Zo).samples.length===H(this,Ko).fastStart.expectedAudioChunks)throw Error(`Cannot add more audio chunks than specified in 'fastStart' (${H(this,Ko).fastStart.expectedAudioChunks}).`);let a=Hi(this,ms,hs).call(this,H(this,Zo),e,t,n,r,i);if(H(this,Ko).fastStart===`fragmented`&&H(this,Xo)){for(;H(this,ts).length>0&&H(this,ts)[0].decodeTimestamp<=a.decodeTimestamp;){let e=H(this,ts).shift();Hi(this,gs,_s).call(this,H(this,Xo),e)}a.decodeTimestamp<=H(this,Xo).lastDecodeTimestamp?Hi(this,gs,_s).call(this,H(this,Zo),a):H(this,ns).push(a)}else Hi(this,gs,_s).call(this,H(this,Zo),a)}finalize(){if(H(this,rs))throw Error(`Cannot finalize a muxer more than once.`);if(H(this,Ko).fastStart===`fragmented`){for(let e of H(this,ts))Hi(this,gs,_s).call(this,H(this,Xo),e);for(let e of H(this,ns))Hi(this,gs,_s).call(this,H(this,Zo),e);Hi(this,Ss,Cs).call(this,!1)}else H(this,Xo)&&Hi(this,bs,xs).call(this,H(this,Xo)),H(this,Zo)&&Hi(this,bs,xs).call(this,H(this,Zo));let e=[H(this,Xo),H(this,Zo)].filter(Boolean);if(H(this,Ko).fastStart===`in-memory`){let t;for(let n=0;n<2;n++){let n=ma(e,H(this,Qo)),r=H(this,qo).measureBox(n);t=H(this,qo).measureBox(H(this,Yo));let i=H(this,qo).pos+r+t;for(let e of H(this,$o)){e.offset=i;for(let{data:n}of e.samples)i+=n.byteLength,t+=n.byteLength}if(i<2**32)break;t>=2**32&&(H(this,Yo).largeSize=!0)}let n=ma(e,H(this,Qo));H(this,qo).writeBox(n),H(this,Yo).size=t,H(this,qo).writeBox(H(this,Yo));for(let e of H(this,$o))for(let t of e.samples)H(this,qo).write(t.data),t.data=null}else if(H(this,Ko).fastStart===`fragmented`){let t=H(this,qo).pos,n=no(e);H(this,qo).writeBox(n);let r=H(this,qo).pos-t;H(this,qo).seek(H(this,qo).pos-4),H(this,qo).writeU32(r)}else{let t=H(this,qo).offsets.get(H(this,Yo)),n=H(this,qo).pos-t;H(this,Yo).size=n,H(this,Yo).largeSize=n>=2**32,H(this,qo).patchBox(H(this,Yo));let r=ma(e,H(this,Qo));if(typeof H(this,Ko).fastStart==`object`){H(this,qo).seek(H(this,Jo)),H(this,qo).writeBox(r);let e=t-H(this,qo).pos;H(this,qo).writeBox(pa(e))}else H(this,qo).writeBox(r)}Hi(this,ws,Ts).call(this),H(this,qo).finalize(),Bi(this,rs,!0)}},Ko=new WeakMap,qo=new WeakMap,Jo=new WeakMap,Yo=new WeakMap,Xo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap,$o=new WeakMap,es=new WeakMap,ts=new WeakMap,ns=new WeakMap,rs=new WeakMap,is=new WeakSet,as=function(e){if(typeof e!=`object`)throw TypeError(`The muxer requires an options object to be passed to its constructor.`);if(!(e.target instanceof lo))throw TypeError(`The target must be provided and an instance of Target.`);if(e.video){if(!Ho.includes(e.video.codec))throw TypeError(`Unsupported video codec: ${e.video.codec}`);if(!Number.isInteger(e.video.width)||e.video.width<=0)throw TypeError(`Invalid video width: ${e.video.width}. Must be a positive integer.`);if(!Number.isInteger(e.video.height)||e.video.height<=0)throw TypeError(`Invalid video height: ${e.video.height}. Must be a positive integer.`);let t=e.video.rotation;if(typeof t==`number`&&![0,90,180,270].includes(t))throw TypeError(`Invalid video rotation: ${t}. Has to be 0, 90, 180 or 270.`);if(Array.isArray(t)&&(t.length!==9||t.some(e=>typeof e!=`number`)))throw TypeError(`Invalid video transformation matrix: ${t.join()}`);if(e.video.frameRate!==void 0&&(!Number.isInteger(e.video.frameRate)||e.video.frameRate<=0))throw TypeError(`Invalid video frame rate: ${e.video.frameRate}. Must be a positive integer.`)}if(e.audio){if(!Uo.includes(e.audio.codec))throw TypeError(`Unsupported audio codec: ${e.audio.codec}`);if(!Number.isInteger(e.audio.numberOfChannels)||e.audio.numberOfChannels<=0)throw TypeError(`Invalid number of audio channels: ${e.audio.numberOfChannels}. Must be a positive integer.`);if(!Number.isInteger(e.audio.sampleRate)||e.audio.sampleRate<=0)throw TypeError(`Invalid audio sample rate: ${e.audio.sampleRate}. Must be a positive integer.`)}if(e.firstTimestampBehavior&&!Go.includes(e.firstTimestampBehavior))throw TypeError(`Invalid first timestamp behavior: ${e.firstTimestampBehavior}`);if(typeof e.fastStart==`object`){if(e.video){if(e.fastStart.expectedVideoChunks===void 0)throw TypeError(`'fastStart' is an object but is missing property 'expectedVideoChunks'.`);if(!Number.isInteger(e.fastStart.expectedVideoChunks)||e.fastStart.expectedVideoChunks<0)throw TypeError(`'expectedVideoChunks' must be a non-negative integer.`)}if(e.audio){if(e.fastStart.expectedAudioChunks===void 0)throw TypeError(`'fastStart' is an object but is missing property 'expectedAudioChunks'.`);if(!Number.isInteger(e.fastStart.expectedAudioChunks)||e.fastStart.expectedAudioChunks<0)throw TypeError(`'expectedAudioChunks' must be a non-negative integer.`)}}else if(![!1,`in-memory`,`fragmented`].includes(e.fastStart))throw TypeError(`'fastStart' option must be false, 'in-memory', 'fragmented' or an object.`);if(e.minFragmentDuration!==void 0&&(!Number.isFinite(e.minFragmentDuration)||e.minFragmentDuration<0))throw TypeError(`'minFragmentDuration' must be a non-negative number.`)},os=new WeakSet,ss=function(){if(H(this,qo).writeBox(da({holdsAvc:H(this,Ko).video?.codec===`avc`,fragmented:H(this,Ko).fastStart===`fragmented`})),Bi(this,Jo,H(this,qo).pos),H(this,Ko).fastStart===`in-memory`)Bi(this,Yo,fa(!1));else if(H(this,Ko).fastStart!==`fragmented`){if(typeof H(this,Ko).fastStart==`object`){let e=Hi(this,cs,ls).call(this);H(this,qo).seek(H(this,qo).pos+e)}Bi(this,Yo,fa(!0)),H(this,qo).writeBox(H(this,Yo))}Hi(this,ws,Ts).call(this)},cs=new WeakSet,ls=function(){if(typeof H(this,Ko).fastStart!=`object`)return;let e=0,t=[H(this,Ko).fastStart.expectedVideoChunks,H(this,Ko).fastStart.expectedAudioChunks];for(let n of t)n&&(e+=8*Math.ceil(2/3*n),e+=4*n,e+=12*Math.ceil(2/3*n),e+=4*n,e+=8*n);return e+=4096,e},us=new WeakSet,ds=function(){if(H(this,Ko).video&&Bi(this,Xo,{id:1,info:{type:`video`,codec:H(this,Ko).video.codec,width:H(this,Ko).video.width,height:H(this,Ko).video.height,rotation:H(this,Ko).video.rotation??0,decoderConfig:null},timescale:H(this,Ko).video.frameRate??57600,samples:[],finalizedChunks:[],currentChunk:null,firstDecodeTimestamp:void 0,lastDecodeTimestamp:-1,timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,compactlyCodedChunkTable:[]}),H(this,Ko).audio&&(Bi(this,Zo,{id:H(this,Ko).video?2:1,info:{type:`audio`,codec:H(this,Ko).audio.codec,numberOfChannels:H(this,Ko).audio.numberOfChannels,sampleRate:H(this,Ko).audio.sampleRate,decoderConfig:null},timescale:H(this,Ko).audio.sampleRate,samples:[],finalizedChunks:[],currentChunk:null,firstDecodeTimestamp:void 0,lastDecodeTimestamp:-1,timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,compactlyCodedChunkTable:[]}),H(this,Ko).audio.codec===`aac`)){let e=Hi(this,fs,ps).call(this,2,H(this,Ko).audio.sampleRate,H(this,Ko).audio.numberOfChannels);H(this,Zo).info.decoderConfig={codec:H(this,Ko).audio.codec,description:e,numberOfChannels:H(this,Ko).audio.numberOfChannels,sampleRate:H(this,Ko).audio.sampleRate}}},fs=new WeakSet,ps=function(e,t,n){let r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350].indexOf(t),i=n,a=``;a+=e.toString(2).padStart(5,`0`),a+=r.toString(2).padStart(4,`0`),r===15&&(a+=t.toString(2).padStart(24,`0`)),a+=i.toString(2).padStart(4,`0`);let o=Math.ceil(a.length/8)*8;a=a.padEnd(o,`0`);let s=new Uint8Array(a.length/8);for(let e=0;e<a.length;e+=8)s[e/8]=parseInt(a.slice(e,e+8),2);return s},ms=new WeakSet,hs=function(e,t,n,r,i,a,o){let s=r/1e6,c=(r-(o??0))/1e6,l=i/1e6,u=Hi(this,vs,ys).call(this,s,c,e);return s=u.presentationTimestamp,c=u.decodeTimestamp,a?.decoderConfig&&(e.info.decoderConfig===null?e.info.decoderConfig=a.decoderConfig:Object.assign(e.info.decoderConfig,a.decoderConfig)),{presentationTimestamp:s,decodeTimestamp:c,duration:l,data:t,size:t.byteLength,type:n,timescaleUnitsToNextSample:ra(l,e.timescale)}},gs=new WeakSet,_s=function(e,t){H(this,Ko).fastStart!==`fragmented`&&e.samples.push(t);let n=ra(t.presentationTimestamp-t.decodeTimestamp,e.timescale);if(e.lastTimescaleUnits!==null){let r=ra(t.decodeTimestamp,e.timescale,!1),i=Math.round(r-e.lastTimescaleUnits);if(e.lastTimescaleUnits+=i,e.lastSample.timescaleUnitsToNextSample=i,H(this,Ko).fastStart!==`fragmented`){let t=ta(e.timeToSampleTable);t.sampleCount===1?(t.sampleDelta=i,t.sampleCount++):t.sampleDelta===i?t.sampleCount++:(t.sampleCount--,e.timeToSampleTable.push({sampleCount:2,sampleDelta:i}));let r=ta(e.compositionTimeOffsetTable);r.sampleCompositionTimeOffset===n?r.sampleCount++:e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:n})}}else e.lastTimescaleUnits=0,H(this,Ko).fastStart!==`fragmented`&&(e.timeToSampleTable.push({sampleCount:1,sampleDelta:ra(t.duration,e.timescale)}),e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:n}));e.lastSample=t;let r=!1;if(!e.currentChunk)r=!0;else{let n=t.presentationTimestamp-e.currentChunk.startTimestamp;if(H(this,Ko).fastStart===`fragmented`){let i=H(this,Xo)??H(this,Zo),a=H(this,Ko).minFragmentDuration??1;e===i&&t.type===`key`&&n>=a&&(r=!0,Hi(this,Ss,Cs).call(this))}else r=n>=.5}r&&(e.currentChunk&&Hi(this,bs,xs).call(this,e),e.currentChunk={startTimestamp:t.presentationTimestamp,samples:[]}),e.currentChunk.samples.push(t)},vs=new WeakSet,ys=function(e,t,n){let r=H(this,Ko).firstTimestampBehavior===`strict`,i=n.lastDecodeTimestamp===-1;if(r&&i&&t!==0)throw Error(`The first chunk for your media track must have a timestamp of 0 (received DTS=${t}).Non-zero first timestamps are often caused by directly piping frames or audio data from a MediaStreamTrack into the encoder. Their timestamps are typically relative to the age of thedocument, which is probably what you want.
1087
+ })(createStore,sharedAPI,onStatus);})(documentTools,sharedAPI,onStatus);return {documentTools,sharedDocuments}}`;function $n(){return()=>{}}function er(){return{}}Tt();function tr({assert:e,plain:t,safeDocument:n,stableStringify:r}){let i=(e,t)=>{if(e===t)return!0;if(e===null||t===null||typeof e!=`object`||typeof t!=`object`)return!1;if(Array.isArray(e)||Array.isArray(t))return Array.isArray(e)&&Array.isArray(t)&&e.length===t.length&&e.every((e,n)=>i(e,t[n]));let n=Object.keys(e);return n.length===Object.keys(t).length&&n.every(n=>Object.hasOwn(t,n)&&i(e[n],t[n]))},a=(e,t)=>e.exists===t.exists&&(!e.exists||i(e.value,t.value)),o=(e,t)=>Object.hasOwn(e,t)?{exists:!0,value:e[t]}:{exists:!1},s=e=>Array.isArray(e)&&e.every(e=>t(e)&&typeof e.id==`string`)&&new Set(e.map(e=>e.id)).size===e.length;function c(e,n,r){let i=[];if(t(e)&&t(n))for(let l of new Set([...Object.keys(e),...Object.keys(n)])){let u=o(e,l),d=o(n,l);a(u,d)||(!(r.length===0&&[`projectType`,`semanticContext`].includes(l))&&u.exists&&d.exists&&(t(u.value)&&t(d.value)||s(u.value)&&s(d.value))?i.push(...c(u.value,d.value,[...r,l])):i.push({path:[...r,l],before:u,after:d}))}else if(s(e)&&s(n)){let t=new Map(e.map(e=>[e.id,e])),a=new Map(n.map(e=>[e.id,e]));for(let e of new Set([...t.keys(),...a.keys()]))t.has(e)&&a.has(e)?i.push(...c(t.get(e),a.get(e),[...r,{id:e}])):i.push({path:[...r,{id:e}],before:t.has(e)?{exists:!0,value:t.get(e)}:{exists:!1},after:a.has(e)?{exists:!0,value:a.get(e)}:{exists:!1}});let o=[...e.filter(e=>a.has(e.id)).map(e=>e.id),...n.filter(e=>!t.has(e.id)).map(e=>e.id)];JSON.stringify(o)!==JSON.stringify(n.map(e=>e.id))&&i.push({path:r,before:{exists:!0,value:n.map(e=>t.get(e.id)||e)},after:{exists:!0,value:n},order:n.map(e=>e.id),expectedOrder:e.map(e=>e.id)})}return i}function l(e,t,r=[]){return n(e),n(t),c(e,t,r)}function u(n,r){let i=n;for(let n of r.slice(0,-1))t(n)?(e(Array.isArray(i),`CONFLICT`,`Collection removed`),i=i.find(e=>e?.id===n.id)):(e(i&&Object.hasOwn(i,n),`CONFLICT`,`Parent removed`),i=i[n]),e(i&&typeof i==`object`,`CONFLICT`,`Parent removed`);let a=r.at(-1);if(t(a)){e(Array.isArray(i),`CONFLICT`,`Collection removed`);let t=i.findIndex(e=>e?.id===a.id);return{parent:i,key:t,state:t<0?{exists:!1}:{exists:!0,value:i[t]},collection:!0,id:a.id}}return e(t(i),`CONFLICT`,`Parent removed`),{parent:i,key:a,state:o(i,a),collection:!1}}function d(r,i){n(r),n(i),e(Array.isArray(i)&&i.length<=2e3,`LIMIT`,`Too many operations`);let o=structuredClone(r);for(let n of i){e(Array.isArray(n.path)&&n.path.length>0&&n.path.length<=30&&n.path.every(e=>typeof e==`string`&&e.length>0&&![`__proto__`,`constructor`,`prototype`].includes(e)||t(e)&&typeof e.id==`string`&&Object.keys(e).length===1),`PATCH`,`Invalid operation path`),e(t(n.before)&&t(n.after)&&typeof n.before.exists==`boolean`&&typeof n.after.exists==`boolean`,`PATCH`,`Expected before/after preconditions`),e(!(n.path.at(-1)===`id`&&t(n.path.at(-2))),`PATCH`,`Collection identity is immutable`);let r=u(o,n.path);if(n.order){e(Array.isArray(r.state.value)&&Array.isArray(n.order)&&Array.isArray(n.expectedOrder),`PATCH`,`Invalid order operation`);let t=r.state.value,i=new Set(n.expectedOrder);e(new Set(n.order).size===n.order.length&&n.order.every(e=>typeof e==`string`&&t.some(t=>t.id===e)),`PATCH`,`Invalid order IDs`);let a=new Set(n.order);if(JSON.stringify(t.filter(e=>a.has(e.id)).map(e=>e.id))===JSON.stringify(n.order))continue;e(t.filter(e=>i.has(e.id)).map(e=>e.id).join(`\0`)===n.expectedOrder.filter(e=>t.some(t=>t.id===e)).join(`\0`),`CONFLICT`,`Collection order changed`),r.parent[r.key]=[...n.order.map(e=>t.find(t=>t.id===e)),...t.filter(e=>!a.has(e.id))];continue}e(a(r.state,n.before)||a(r.state,n.after),`CONFLICT`,`Concurrent change at ${n.path.map(e=>typeof e==`string`?e:e.id).join(`.`)}`),!a(r.state,n.after)&&(r.collection?n.after.exists?(e(n.after.value?.id===r.id,`PATCH`,`Collection ID mismatch`),r.key<0?r.parent.push(structuredClone(n.after.value)):r.parent[r.key]=structuredClone(n.after.value)):r.parent.splice(r.key,1):n.after.exists?r.parent[r.key]=structuredClone(n.after.value):delete r.parent[r.key])}return o}return Object.freeze({isKeyed:s,diffDocument:l,applyOperations:d})}var{isKeyed:nr,diffDocument:rr,applyOperations:ir}=tr({assert:B,plain:vt,safeDocument:mt,stableStringify:ht});Tt();var ar=Object.freeze({stateBytes:393216,requestBytes:8e5,pendingBytes:2097152});function or(e={},t){mt(t),B(new TextEncoder().encode(JSON.stringify(t)).length<=ar.requestBytes,`VIEW_STATE`,`Shared edit exceeds 800,000 bytes`),B(vt(e)&&vt(t)&&vt(t.values)&&vt(t.before),`VIEW_STATE`,`Expected a shared view patch`);let n=Object.keys(t.values);B(t.merge===void 0||typeof t.merge==`boolean`,`VIEW_STATE`,`Invalid structured merge option`);let r={...e};B(n.length>0&&n.length<=100&&n.every(e=>/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)),`VIEW_STATE`,`Use bounded named view fields`);for(let i of n){let n=t.before[i];B(vt(n)&&typeof n.exists==`boolean`,`VIEW_STATE`,`Missing field precondition`);let a=Object.hasOwn(e,i);if(t.merge&&n.exists&&a&&vt(n.value)&&vt(t.values[i])&&vt(e[i])){let a=rr({value:n.value},{value:t.values[i]});r[i]=ir({value:e[i]},a).value;continue}B(a===n.exists&&(!a||ht(e[i])===ht(n.value))||a&&ht(e[i])===ht(t.values[i]),`CONFLICT`,`This field changed. Read the shared state before applying your edit.`),r[i]=structuredClone(t.values[i])}return B(new TextEncoder().encode(JSON.stringify(r)).length<=ar.stateBytes,`VIEW_STATE`,`Shared view state exceeds 384 KiB`),r}function sr(e,t,n=ar,r={}){let i={state:{},outputs:{},memory:null,canEdit:!1},a=!1,o=0,s=null,c=!1,l=[],u=0,d=0,f=new Set,p=new Map,m=null,h=null,g=null,_=(e,t)=>{t=Error(String(t?.message||`Shared edit failed`).slice(0,1e3));let n=e&&typeof e==`object`&&!Array.isArray(e)?Object.keys(e):[];if(!n.length){m=t;return}for(let e of n){if(!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)){m=t;continue}if(p.size>=100&&!p.has(e)){m=Error(`Too many unresolved shared fields. Reopen the Block to recover.`);break}p.set(e,t)}},v=()=>{h&&g===null&&(g=setTimeout(()=>{if(g=null,!h||s||l.length)return;let e=h;h=null;let t=c?Error(`Block closed`):m||p.values().next().value;t?e.reject(t):e.resolve({queued:!0})},0))};r.captureControlState=()=>({attempts:u,snapshotVersion:d,closed:c,ready:a,pending:!!s,queued:l.length,failed:!!m||p.size>0}),r.flushSharedWrites=()=>{if(h)return h.promise;let e,t,n=new Promise((n,r)=>{e=n,t=r});return h={promise:n,resolve:e,reject:t},v(),n};let y=()=>{for(let e of f)try{e(structuredClone(i))}catch{}},b=e=>{let t=Error(e);s&&=(clearTimeout(s.timer),_(s.values,t),s.reject(t),null);for(let e of l.splice(0))_(e.values,t),e.reject(t);v()},x=()=>{if(s||!l.length||c)return;if(!a||!i.canEdit){b(`Shared editing is unavailable or read only`);return}s=l.shift();let n=s;n.timer=setTimeout(()=>{c=!0,a=!1,i={...i,canEdit:!1},b(`Shared edit acknowledgement timed out. Reopen the Block to recover.`),y()},15e3),parent.postMessage({channel:e,session:t,op:`shared-view-update`,id:n.id,request:{values:n.values,before:n.before,...n.merge?{merge:!0}:{}}},`*`)};addEventListener(`message`,n=>{let r=n.data;if(!c&&n.source===parent&&r&&r.channel===e&&r.session===t){if(r.op===`shared-view`)d++,i=r.value,a=!0,i.canEdit||b(`Shared editing is unavailable or read only`),y(),x();else if(r.op===`shared-view-result`&&s?.id===r.id){let e=s;if(clearTimeout(e.timer),s=null,r.error){let t=Error(r.error);_(e.values,t),e.reject(t),b(`A previous edit failed. Read the shared state before trying again.`)}else{let t={...i.state};for(let n of Object.keys(e.values)){let r=e.before[n];Object.hasOwn(t,n)===r.exists&&(!r.exists||JSON.stringify(t[n])===JSON.stringify(r.value))&&(t[n]=e.values[n])}i={...i,state:t};for(let t of Object.keys(e.values))p.delete(t);e.resolve({queued:!0}),y()}x(),v()}else r.op===`dispose`&&(c=!0,a=!1,f.clear(),b(`Block closed`))}});let S={getShared(){return structuredClone(i)},onShared(e){if(typeof e!=`function`)throw Error(`Expected a function`);return f.add(e),a&&e(structuredClone(i)),()=>f.delete(e)},updateShared(e,t,r){u++;let d=t=>(_(e,t),v(),Promise.reject(t));if(c||!a||!i.canEdit)return d(Error(`Shared editing is unavailable or read only`));if(l.length>=32)return d(Error(`Too many pending shared edits. Wait for synchronization.`));let f={},p=!1,m=0;try{if(r!==void 0){if(!r||typeof r!=`object`||Array.isArray(r)||Object.keys(r).some(e=>e!==`merge`)||typeof r.merge!=`boolean`)throw Error(`Expected a structured merge option`);if(p=r.merge,p&&t===void 0)throw Error(`Structured edits require the exact base preconditions`)}if(!e||Array.isArray(e)||typeof e!=`object`||new TextEncoder().encode(JSON.stringify(e)).length>n.stateBytes)throw Error(`Expected bounded view fields`);e=structuredClone(e);let a=Object.keys(e);if(!a.length||a.length>100||a.some(e=>!/^[a-zA-Z][a-zA-Z0-9_-]{0,99}$/.test(e)))throw Error(`Use bounded named view fields`);let o={...i.state,...s?.values};for(let e of l)Object.assign(o,e.values);for(let e of a)f[e]=Object.hasOwn(o,e)?{exists:!0,value:structuredClone(o[e])}:{exists:!1};if(t!==void 0){if(!t||Array.isArray(t)||typeof t!=`object`)throw Error(`Expected field preconditions`);f=structuredClone(t);for(let e of a)if(!f[e]||typeof f[e].exists!=`boolean`)throw Error(`Missing field precondition`)}if(m=new TextEncoder().encode(JSON.stringify({values:e,before:f,...p?{merge:!0}:{}})).length,m>n.requestBytes)throw Error(`Shared edit exceeds 800,000 bytes`);if(m+(s?.bytes||0)+l.reduce((e,t)=>e+t.bytes,0)>n.pendingBytes)throw Error(`Pending shared edits exceed 2 MiB. Wait for synchronization.`)}catch(e){return d(e)}return new Promise((t,n)=>{l.push({id:String(++o),resolve:t,reject:n,values:e,before:f,merge:p,bytes:m}),x()})}};return Object.defineProperty(S,"announce",{value:()=>{a&&!c&&y()}}),S}function cr(e,t=()=>{},n=()=>{}){let r=new Set(`div.section.article.header.footer.p.span.strong.em.i.small.h1.h2.h3.h4.label.button.input.textarea.select.option.ul.ol.li.table.thead.tbody.tr.th.td.details.summary.output.progress.img`.split(`.`)),i=new Set([`DIV`,`SPAN`,`SECTION`,`ARTICLE`,`MAIN`,`ASIDE`,`UL`,`OL`,`TBODY`]),a=new Set([`tag`,`text`,`children`,`id`,`className`,`action`,`value`,`type`,`checked`,`disabled`,`placeholder`,`min`,`max`,`step`,`label`]),o=new Set,s=new WeakMap,c=new WeakMap,l=new Map,u=new Map,d=!1,f=0,p=0,m=!1,h=new Set,g=()=>{try{n()}catch{}},_=[`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`],v=e=>typeof e==`string`&&/^\s*preview\s*$/i.test(e),y=(t,n)=>{let r=`http://www.w3.org/2000/svg`,i=e.createElementNS(r,`svg`);for(let[e,t]of[[`viewBox`,`0 0 24 24`],[`width`,`20`],[`height`,`20`],[`fill`,`none`],[`stroke`,`currentColor`],[`stroke-width`,`1.5`],[`stroke-linecap`,`round`],[`stroke-linejoin`,`round`],[`aria-hidden`,`true`]])i.setAttribute(e,t);for(let t of _){let n=e.createElementNS(r,`path`);n.setAttribute(`d`,t),i.appendChild(n)}let a=e.createElementNS(r,`circle`);for(let[e,t]of[[`cx`,`12`],[`cy`,`12`],[`r`,`1.8`]])a.setAttribute(e,t);i.appendChild(a),t.textContent=``,t.appendChild(i),t.setAttribute(`data-icon-action`,`true`),t.setAttribute(`aria-label`,n||`Preview`),t.setAttribute(`title`,n||`Preview`)},b=()=>{if(!d)for(let t of e.querySelectorAll(`button`))!t.children.length&&v(t.textContent)&&y(t,t.getAttribute(`aria-label`))};e.readyState===`loading`?e.addEventListener(`DOMContentLoaded`,b,{once:!0}):b();let x=globalThis.setTimeout?.bind(globalThis),S=globalThis.clearTimeout?.bind(globalThis),C=x&&S?e.defaultView?.MutationObserver:null,w=new Set([`file`,`password`,`hidden`,`submit`,`reset`,`image`,`button`]),T=e=>{let t=``;for(let n of e.childNodes)n.nodeType===3?t+=n.nodeValue:n.nodeType===1&&!n.matches(`input,select,textarea,button`)&&(t+=` `+n.textContent);return t},E=t=>{let n=t.getAttribute(`aria-label`)||``,r=t.getAttribute(`aria-labelledby`);return!n&&r&&(n=r.split(/\s+/).map(t=>e.getElementById(t)?.textContent||``).join(` `)),!n&&t.labels?.length&&(n=T(t.labels[0])),!n.trim()&&t.tagName===`BUTTON`&&(n=t.textContent||``),String(n.trim()?n:t.getAttribute(`title`)||``).replace(/\s+/g,` `).trim().slice(0,240)},D=e=>{let t=s.get(e);return t&&!t.plain||e.closest(`[data-stillmade-share],[data-stillmade-local]`)?!1:e.tagName===`BUTTON`?e.hasAttribute(`data-stillmade-action`):e.tagName===`INPUT`&&w.has(e.type)?!1:e.hasAttribute(`data-stillmade-action`)||!!E(e)},O=()=>{let t=[];for(let n of e.querySelectorAll(`button,input,select,textarea`)){if(t.length>=200)break;D(n)&&(s.has(n)||s.set(n,{plain:!0,event:n.tagName===`BUTTON`?`click`:n.tagName===`SELECT`||[`checkbox`,`radio`].includes(n.type)?`change`:`input`,root:e.documentElement,handle:`view-control-`+String(++p)}),t.push(n))}return t},k=e=>{let t=s.get(e);return t.plain?String(e.getAttribute(`data-stillmade-action`)||e.id||e.getAttribute(`name`)||E(e)).slice(0,120):t.action},A=(e,t)=>{if(!e)throw Error(t)},j=(e,t=1e4)=>(A(typeof e==`string`&&e.length<=t,`Dynamic control text exceeds its limit`),e),M=e=>e.tagName===`TEXTAREA`||e.tagName===`INPUT`&&e.type===`text`,N=(e,t,n)=>{let r=s.get(e);if(m||d||!r?.action||r.event!==n||!t.contains(e)||e.disabled)return;let i={action:r.action,value:e.value,checked:e.checked===!0,event:n};for(let e of o)try{Promise.resolve(e({...i})).then(g,()=>{})}catch{}},P=(e,t,n=e.value)=>{if(d||!t.contains(e)||e.disabled||!M(e))return;let r=c.get(e),i=s.get(e),a={composing:!0,cancelled:!1,action:i?.action,event:i?.event,type:e.type,declared:i?.declared,initialValue:n,conflict:r?.conflict===!0,problem:r?.problem,suppress:null};c.set(e,a),l.set(e,t)},F=(e,n,r,i)=>{if(!r.conflict){r.conflict=!0,r.problem=i,u.set(e,n);try{t(i)}catch{}}},I=e=>{for(let t of l.keys())(t===e||e.contains?.(t))&&(c.get(t).cancelled=!0,l.delete(t));for(let t of u.keys())(t===e||e.contains?.(t))&&u.delete(t)},ee=(t,n)=>{j(t,120);let o=e.getElementById(t);A(o&&i.has(o.tagName),`Choose an existing container for dynamic controls`),A(Array.isArray(n)&&JSON.stringify(n).length<=262144,`Dynamic controls exceed 256 KiB`);let u=0,d=new Set,_=(n,i)=>{A(++u<=1e3&&i<=12,`Dynamic controls exceed 1000 elements or 12 levels`),A(n&&typeof n==`object`&&!Array.isArray(n)&&Object.keys(n).every(e=>a.has(e)),`Unsupported dynamic control field`),A(r.has(n.tag),`Unsupported dynamic control tag`);let f=e.createElement(n.tag);if(n.id!==void 0){let r=j(n.id,120),i=e.getElementById(r);A(r&&r!==t&&!d.has(r)&&(!i||o.contains(i)),`Dynamic control IDs must be unique`),d.add(r),f.id=r}n.className!==void 0&&(f.className=j(n.className,240)),n.text!==void 0&&(f.textContent=j(n.text)),n.label!==void 0&&f.setAttribute(`aria-label`,j(n.label,240)),n.tag===`button`&&v(n.text)&&y(f,n.label),n.type!==void 0&&(A(n.tag===`input`&&[`text`,`number`,`range`,`checkbox`,`radio`,`color`].includes(n.type),`Unsupported dynamic input type`),f.type=n.type);for(let e of[`checked`,`disabled`])n[e]!==void 0&&(A(typeof n[e]==`boolean`,`Control flags must be boolean`),f[e]=n[e]);for(let e of[`min`,`max`,`step`])n[e]!==void 0&&(A(typeof n[e]==`string`||typeof n[e]==`number`&&Number.isFinite(n[e]),`Control values must be text or finite numbers`),f[e]=j(String(n[e]),1e4));if(n.placeholder!==void 0&&(f.placeholder=j(n.placeholder,240)),n.tag===`button`&&(f.type=`button`),n.children!==void 0){A(Array.isArray(n.children)&&n.text===void 0,`Use children or text for a control`);for(let e of n.children)f.appendChild(_(e,i+1))}if(n.value!==void 0&&(A(typeof n.value==`string`||typeof n.value==`number`&&Number.isFinite(n.value),`Control values must be text or finite numbers`),f.value=j(String(n.value),1e4)),n.action!==void 0){let e=j(n.action,120);A(e&&[`button`,`input`,`textarea`,`select`].includes(n.tag),`Actions belong to interactive controls`)}if([`button`,`input`,`textarea`,`select`].includes(n.tag)){let e=n.tag===`button`?`click`:[`checkbox`,`radio`].includes(n.type)||n.tag===`select`?`change`:`input`;s.set(f,{action:n.action,event:e,declared:f.value,declaredDisabled:f.disabled,root:o,handle:`view-control-`+String(++p)});for(let e of[`click`,`input`,`change`])f.addEventListener(e,t=>{let n=c.get(f);if(e===`input`&&t.isComposing){n?.composing||P(f,o,s.get(f)?.declared??f.value);return}if(!(n?.composing||n?.conflict)){if(e===`input`&&n?.suppress!==null&&n?.suppress!==void 0){let e=f.value===n.suppress;if(n.suppress=null,e)return}N(f,o,e)}});(n.tag===`input`||n.tag===`textarea`)&&(f.addEventListener(`compositionstart`,()=>P(f,o)),f.addEventListener(`compositionend`,()=>{let e=c.get(f);if(!e?.composing)return;e.composing=!1,e.suppress=f.value,l.delete(f);let t=s.get(f);!e.cancelled&&!e.conflict&&f.value!==e.initialValue&&M(f)&&e.type===f.type&&e.action===t?.action&&e.event===t?.event&&N(f,o,`input`),e.suppress=f.value}))}return f},b=e.createDocumentFragment();for(let e of n)b.appendChild(_(e,0));A(e.querySelectorAll(`*`).length-o.querySelectorAll(`*`).length+u<=5e3,`This interface exceeds 5000 elements`);let x=e.activeElement,S=x&&o.contains(x)&&typeof x.selectionStart==`number`?{start:x.selectionStart,end:x.selectionEnd,direction:x.selectionDirection}:null,C=(e,t)=>{let n=Array.from(e.childNodes),r=new Set,i=new Map(n.filter(e=>e.nodeType===1&&e.id).map(e=>[e.id,e]));Array.from(t.childNodes).forEach((t,a)=>{let l=t.nodeType===1?t.id:``,u=l?i.get(l):n[a];if(!u||r.has(u)||u.nodeType!==t.nodeType||u.nodeName!==t.nodeName||u.nodeType===1&&u.id!==l)u=t;else if(u.nodeType===3)u.nodeValue!==t.nodeValue&&(u.nodeValue=t.nodeValue);else{let e=`value`in t?t.value:void 0,n=c.get(u),r=s.get(t);n?.composing&&(t.disabled&&F(u,o,n,`Editing access changed while you were composing. Your local draft is retained here. Review it before reopening this Block.`),t.disabled||n.action!==r?.action||n.event!==r?.event||n.type!==t.type?n.cancelled=!0:!n.cancelled&&e!==n.declared&&F(u,o,n,`Text changed elsewhere while you were composing. Your local draft is retained here. Copy it before reopening this Block to review the shared version.`));let i=t.hasAttribute(`data-icon-action`)||u.hasAttribute(`data-icon-action`);for(let e of[`id`,`class`,`aria-label`,`type`,`min`,`max`,`step`,`placeholder`,...i?[`data-icon-action`,`title`]:[]]){let n=t.getAttribute(e);n===null?u.removeAttribute(e):u.getAttribute(e)!==n&&u.setAttribute(e,n)}C(u,t),`disabled`in t&&(u.disabled=t.disabled),`checked`in t&&(u.checked=t.checked),e!==void 0&&u.value!==e&&!n?.composing&&!n?.conflict&&(u.value=e),s.has(t)&&s.set(u,s.get(t))}r.add(u);let d=e.childNodes[a];d!==u&&e.insertBefore(u,d||null)});for(let t of n)!r.has(t)&&t.parentNode===e&&(I(t),t.remove())};C(o,b),h.add(o),f++,m&&ie(!0),g(),x&&o.contains(x)&&!x.disabled&&!c.get(x)?.composing&&(e.activeElement!==x&&x.focus({preventScroll:!0}),S&&typeof x.selectionStart==`number`&&typeof x.setSelectionRange==`function`&&x.setSelectionRange(S.start,S.end,S.direction))},te=()=>{A(!d,`Dynamic controls are closed`);let e=[...u].find(([e,t])=>t.contains(e)&&e.isConnected);if(e)throw Error(c.get(e[0]).problem);A(![...l].some(([e,t])=>t.contains(e)&&e.isConnected&&!e.disabled),`Finish composing text before continuing.`)},L=()=>{let e=new Set,t=[];for(let n of h)if(n.isConnected)for(let r of n.querySelectorAll(`button,input,textarea,select`)){let i=s.get(r);i?.action&&i.root===n&&!e.has(r)&&(e.add(r),t.push(r))}for(let n of O())e.has(n)||(e.add(n),t.push(n));return t},R=t=>{for(let n=t;n;n=n.parentElement){if(n.hidden)return!0;let t=e.defaultView?.getComputedStyle(n);if(t?.display===`none`||[`hidden`,`collapse`].includes(t?.visibility)||t?.opacity===`0`)return!0}return!1},ne=e=>s.get(e)?.plain?E(e)||k(e)||`Control`:String(e.getAttribute(`aria-label`)||e.textContent||e.placeholder||`Control`).slice(0,240),z=e=>e.tagName===`SELECT`?Array.from(e.options).map(e=>({value:e.value,label:e.textContent})):null,re=e=>{let t=s.get(e);return JSON.stringify({action:k(e),event:t.event,root:t.root.id,tag:e.tagName,type:e.type,value:e.value,checked:e.checked,disabled:e.disabled,hidden:R(e),label:ne(e),choices:z(e)})},ie=e=>{for(let t of L())s.get(t).plain||(t.disabled=e||s.get(t).declaredDisabled)},ae=null,oe=null,se=()=>O().map(e=>s.get(e).handle+(e.disabled?`:off`:``)+(R(e)?`:hidden`:``)).join(`,`),ce=()=>{if(oe=null,d||ae===null)return;let e;try{e=se()}catch{return}e!==ae&&(ae=e,f++,g())},le=C?new C(()=>{oe===null&&!d&&(oe=x(ce,250))}):null;return le?.observe(e.documentElement,{subtree:!0,childList:!0,attributes:!0,attributeFilter:[`disabled`,`hidden`,`class`,`data-stillmade-action`,`aria-label`]}),Object.freeze({render:ee,inspectControls:({offset:e=0,limit:t=20}={})=>{A(!d,`Dynamic controls are closed`),A(Number.isSafeInteger(e)&&e>=0&&Number.isSafeInteger(t)&&t>=1&&t<=20,`Choose a bounded control page`);let n=L();return ae=se(),A(e<=n.length,`Choose a current control page`),{revision:f,total:n.length,offset:e,nextOffset:e+t<n.length?e+t:null,controls:n.slice(e,e+t).map(e=>{let t=s.get(e),n=String(e.value??``);return{id:t.handle,action:k(e),label:ne(e),tag:e.tagName.toLowerCase(),type:e.type,event:t.event,disabled:e.disabled,hidden:R(e),value:n.slice(0,240),valuePartial:n.length>240,...typeof e.checked==`boolean`?{checked:e.checked}:{},...e.tagName===`SELECT`?{choices:z(e).slice(0,40),choicesPartial:e.options.length>40}:{},identity:re(e)}})}},dispatchControl:async(t,n=async()=>{})=>{A(!m,`A declared control is already running`),te(),A(t&&typeof t==`object`&&!Array.isArray(t)&&Object.keys(t).every(e=>[`id`,`revision`,`identity`,`value`,`checked`].includes(e))&&typeof t.id==`string`&&t.revision===f&&typeof t.identity==`string`,`The declared control changed`);let r=L().find(e=>s.get(e).handle===t.id),i=r&&s.get(r);A(r&&re(r)===t.identity,`The declared control changed`),A(!r.disabled&&!R(r),`This declared control is unavailable`),A(i.plain||o.size>0,`This declared control has no native handler`),r.tagName===`BUTTON`?A(!Object.hasOwn(t,`value`)&&!Object.hasOwn(t,`checked`),`Buttons take no input value`):[`checkbox`,`radio`].includes(r.type)?(A(typeof t.checked==`boolean`&&!Object.hasOwn(t,`value`),`Choose a checkbox value`),r.checked=t.checked):(A((typeof t.value==`string`&&t.value.length<=1e4||typeof t.value==`number`&&Number.isFinite(t.value))&&!Object.hasOwn(t,`checked`),`Choose a bounded control value`),r.tagName===`SELECT`&&A(Array.from(r.options).some(e=>e.value===String(t.value)),`Choose a declared option`),r.value=String(t.value));let a={action:i.action,value:r.value,checked:r.checked,event:i.event};if(m=!0,ie(!0),i.plain)try{if(r.tagName===`BUTTON`)r.click();else for(let t of[`input`,`change`])r.dispatchEvent(new e.defaultView.Event(t,{bubbles:!0}));return A(!d,`Dynamic controls are closed`),await n(),A(!d,`Dynamic controls are closed`),{settled:!0}}finally{m=!1,ie(!1),g()}try{let e=[];for(let t of o)try{e.push(Promise.resolve(t({...a})))}catch(t){e.push(Promise.reject(t))}let t=await Promise.allSettled(e);A(!d,`Dynamic controls are closed`),await n(),A(!d,`Dynamic controls are closed`);let r=t.find(e=>e.status===`rejected`);if(r)throw r.reason;return{settled:!0}}finally{m=!1,ie(!1),g()}},locateControl:e=>{A(!d,`Dynamic controls are closed`);let t=L().find(t=>s.get(t).handle===e);if(!t||R(t))return null;let n=t.getBoundingClientRect();return{x:n.left,y:n.top,width:n.width,height:n.height}},onAction(e){return A(typeof e==`function`&&o.size<16,`Register at most 16 action listeners`),o.add(e),()=>o.delete(e)},assertCommitted:te,async flushAll(){return te(),{queued:!0}},dispose(){d=!0,le?.disconnect(),oe!==null&&S?.(oe),h.clear();for(let e of l.keys())c.get(e).cancelled=!0;l.clear(),u.clear(),o.clear()}})}function lr(e=[]){let t=new Set([`__proto__`,`prototype`,`constructor`]),n=new Set(e);function r(e,n=0,i={nodes:0}){if(n>32||++i.nodes>5e4)throw Error(`Field data exceeds its complexity limit.`);if(!(e===null||[`string`,`boolean`].includes(typeof e))&&!(typeof e==`number`&&Number.isFinite(e))){if(!e||typeof e!=`object`||!Array.isArray(e)&&![Object.prototype,null].includes(Object.getPrototypeOf(e)))throw Error(`Fields accept plain JSON only.`);if(Object.getOwnPropertySymbols(e).length)throw Error(`Fields accept JSON keys only.`);for(let a of Object.getOwnPropertyNames(e)){if(Array.isArray(e)&&a===`length`)continue;let o=Object.getOwnPropertyDescriptor(e,a);if(t.has(a)||!o||!o.enumerable||!Object.hasOwn(o,`value`))throw Error(`Unsafe field data.`);r(o.value,n+1,i)}}}let i=e=>{r(e);let t=JSON.stringify(e);if(t.length>2097152)throw Error(`Field data exceeds 2 MiB.`);return JSON.parse(t)},a=e=>{if(!Array.isArray(e)||e.length<1||e.length>12||e.some(e=>typeof e!=`string`&&!Number.isSafeInteger(e)||typeof e==`string`&&(t.has(e)||e.length>240)||typeof e==`number`&&(e<0||e>1e4)))throw Error(`Choose a safe field path.`)};function o(e,t){a(t),r(e);let n=e;for(let e of t){if(!n||typeof n!=`object`||!Object.hasOwn(n,e))return;n=n[e]}return n===void 0?void 0:i(n)}function s(e,t,n){a(t);let o=i(e);r(n);let s=o;for(let e=0;e<t.length-1;e++){let n=t[e];(!Object.hasOwn(s,n)||s[n]===null||typeof s[n]!=`object`)&&(s[n]=typeof t[e+1]==`number`?[]:{}),s=s[n]}return s[t.at(-1)]=i(n),o}function c(e){return Object.hasOwn(e,`default`)?i(e.default):Array.isArray(e.enum)&&e.enum.length?i(e.enum[0]):e.type===`object`?{}:e.type===`array`?[]:e.type===`boolean`?!1:[`integer`,`number`].includes(e.type)?Math.max(e.minimum||0,0):``}function l(e){let t=typeof e==`string`?e.replace(/\s+/g,` `).trim():``;if(!t)return``;let[n,r]=t.split(/(?<=[.!?])\s+(?=[A-Z])/),i=r&&n.length+r.length<280?n+` `+r:n;return i.length>280?i.slice(0,279).trimEnd()+`…`:i}function u(e,t,i,{canEdit:a=!0,busy:o=!1,more:s=[],hide:c=[]}={}){r(e),r(t),r(i);let u=0,d=[],f=[],p=(e,t,n)=>{let r=`field-${f.length}`;return f.push({id:r,kind:e,path:t,s:n}),r},m=(e,t)=>({tag:`section`,...e.type===`object`&&e.properties||e.type===`array`?{}:{className:`sm-field`},children:t});function h(e,t,r,i,s,c){if(++u>150||c>5)return[{tag:`p`,text:`This task needs a custom interface for its remaining fields.`}];let d=String(i).slice(0,240)+(s?` *`:``),g=l(e.description),_=[g?{tag:`div`,className:`sm-label`,children:[{tag:`label`,text:d},{tag:`details`,className:`sm-hint`,children:[{tag:`summary`,label:`About `+String(i).slice(0,200)},{tag:`p`,text:g}]}]}:{tag:`label`,text:d}],v=o||!a||n.has(t[0]);if(e.type===`object`&&e.properties)for(let n of Object.keys(e.properties))_.push(m(e.properties[n],h(e.properties[n],t.concat(n),r?.[n],e.properties[n].title||n,(e.required||[]).includes(n),c+1)));else if(e.type===`array`){let n=Array.isArray(r)?r:[];n.slice(0,20).forEach((n,r)=>_.push({tag:`section`,className:`connection-array`,children:h(e.items||{},t.concat(r),n,`Item `+(r+1),!0,c+1).concat([{tag:`button`,text:`Remove item`,action:p(`remove`,t.concat(r),e),disabled:v}])})),n.length>20&&_.push({tag:`p`,text:`Showing 20 items. All selected items remain in this input.`}),_.push({tag:`button`,text:`Add item`,action:p(`add`,t,e),disabled:v||n.length>=20})}else Array.isArray(e.enum)&&e.enum.length&&e.enum.every(e=>typeof e==`string`)?_.push({tag:`select`,id:`control-${f.length}`,value:r===void 0?``:String(r),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240),children:[{tag:`option`,value:``,text:`Choose…`},...e.enum.slice(0,100).map(e=>({tag:`option`,value:e,text:e}))]}):e.type===`boolean`?_.push({tag:`input`,id:`control-${f.length}`,type:`checkbox`,checked:r===!0,action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240)}):[`integer`,`number`].includes(e.type)?_.push({tag:`input`,id:`control-${f.length}`,type:`number`,value:r===void 0?``:String(r),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240),...e.minimum===void 0?{}:{min:e.minimum},...e.maximum===void 0?{}:{max:e.maximum},step:e.type===`integer`?1:`any`}):e.type===`string`||!e.type?_.push({tag:`textarea`,id:`control-${f.length}`,value:r===void 0?``:String(r).slice(0,1e4),action:p(`edit`,t,e),disabled:v,label:String(i).slice(0,240)}):_.push({tag:`p`,text:`Select a compatible upstream value for this field.`});return _}let g=[];for(let[n,r]of Object.entries(t)){let t=e.properties?.[r];if(!t)throw Error(`Choose a schema-declared input.`);let a=(e.required||[]).includes(r);if(!a&&Array.isArray(c)&&c.includes(r))continue;let o=m(t,h(t,[n],i[n],t.title||r,a,0));(Array.isArray(s)&&s.includes(r)&&!a?g:d).push(o)}return g.length&&d.push({tag:`details`,className:`sm-more`,children:[{tag:`summary`,text:`More options · ${g.length}`},...g]}),{tree:d,actions:f}}function d(e,t,i){r(t),r(i);let a=t.find(e=>e.id===i.action);if(!a)throw Error(`The field changed. Read its current controls.`);if(n.has(a.path[0]))throw Error(`This input is connected. Change its source in Flow.`);if(a.kind===`add`){let t=o(e,a.path)||[];if(!Array.isArray(t)||t.length>=20)throw Error(`Use at most 20 locally edited items.`);return s(e,a.path,[...t,c(a.s.items||{})])}if(a.kind===`remove`){let t=a.path.slice(0,-1),n=o(e,t);if(!Array.isArray(n))throw Error(`The list changed.`);return s(e,t,n.filter((e,t)=>t!==a.path.at(-1)))}let l=a.s.type===`boolean`?i.checked:[`integer`,`number`].includes(a.s.type)?i.value===``?NaN:Number(i.value):i.value;if(typeof l==`number`&&(!Number.isFinite(l)||a.s.type===`integer`&&!Number.isSafeInteger(l)))throw Error(`Enter a valid number.`);return s(e,a.path,l)}function f(e,t,a){let o=i(e);r(t),r(a);for(let e of Object.keys(a))!n.has(e)&&Object.hasOwn(t,e)&&(o[e]=i(t[e]));return o}function p(e,t,a){r(e),r(t),r(a);let o={},s={};for(let r of Object.keys(a))!n.has(r)&&Object.hasOwn(e,r)&&JSON.stringify(e[r])!==JSON.stringify(t[r])&&(o[r]=i(e[r]),s[r]=Object.hasOwn(t,r)?{exists:!0,value:i(t[r])}:{exists:!1});if(JSON.stringify(o).length>393216)throw Error(`Saved task fields exceed 384 KiB. Use an upstream source for larger data.`);return{patch:o,before:s,changed:Object.keys(o).length>0}}function m(e,{maximumFields:t=20}={}){if(e=i(e),!Number.isSafeInteger(t)||t<1||t>100)throw Error(`Use a bounded result preview.`);let n=6e3,r=!1,a=e=>{let t=String(e).replaceAll(`_`,` `).slice(0,120);return t.charAt(0).toUpperCase()+t.slice(1)},o=e=>{let t=e==null?`—`:typeof e==`boolean`?e?`Yes`:`No`:String(e);return t.length>500?t.slice(0,500)+`…`:t},s=e=>typeof e==`object`&&!!e&&!Array.isArray(e),c=(e,t)=>(n--,{tag:e,...t}),l=e=>`${e.length} ${e.length===1?`item`:`items`}${e.length>50?`, showing the first 50`:``}`,u=(e,t)=>{if(n<=0||t>5)return r=!0,c(`p`,{text:`…`});if(typeof e!=`object`||!e)return c(`p`,{text:o(e)});if(Array.isArray(e)){if(!e.length)return c(`p`,{text:`No items`});let n=e.slice(0,50);if(e.length>50&&(r=!0),n.every(s)){let t=[...new Set(n.flatMap(e=>Object.keys(e)))],i=t.slice(0,12);t.length>12&&(r=!0);let s=e=>typeof e==`object`&&e?Array.isArray(e)?e.map(s).join(`, `):Object.values(e).map(s).join(`: `):o(e),u=e=>{let t=s(e);return t.length>200?t.slice(0,200)+`…`:t};return c(`div`,{className:`connection-table`,children:[c(`small`,{text:l(e)}),c(`table`,{children:[c(`thead`,{children:[c(`tr`,{children:i.map(e=>c(`th`,{text:a(e)}))})]}),c(`tbody`,{children:n.map(e=>c(`tr`,{children:i.map(t=>c(`td`,{text:u(e[t])}))}))})]})]})}return c(`div`,{children:[c(`small`,{text:l(e)}),c(`ul`,{children:n.map(e=>c(`li`,{children:[u(e,t+1)]}))})]})}let i=Object.entries(e),d=i.filter(([,e])=>typeof e!=`object`||!e),f=i.filter(([,e])=>typeof e==`object`&&!!e),p=[];d.length&&p.push(c(`table`,{className:`connection-fields`,children:[c(`tbody`,{children:d.map(([e,t])=>c(`tr`,{children:[c(`th`,{text:a(e)}),c(`td`,{text:o(t)})]}))})]}));for(let[e,n]of f)p.push(t===0?c(`section`,{children:[c(`h4`,{text:a(e)}),u(n,t+1)]}):c(`details`,{children:[c(`summary`,{text:a(e)}),u(n,t+1)]}));return p.length||p.push(c(`p`,{text:`No fields`})),c(`div`,{children:p})};return[{tag:`h3`,text:`Result`},u(e,0),...r?[{tag:`small`,text:`Preview is bounded. The saved result retains its complete permitted data.`}]:[]]}function h(e){if(typeof e!=`string`||!/^[A-Z]{3}$/.test(e))throw Error(`Choose a three-letter currency code.`);return new Intl.NumberFormat(`en`,{style:`currency`,currency:e}).resolvedOptions().maximumFractionDigits}function g(e,t){let n=h(t),r=String(e).split(`.`);if(r.length>2||!/^\d+$/.test(r[0])||r[1]!==void 0&&(!/^\d+$/.test(r[1])||r[1].length>n))throw Error(`Enter a budget using this currency’s supported decimal places.`);let i=Number(r[0])*10**n+Number((r[1]||``).padEnd(n,`0`));if(!Number.isSafeInteger(i)||i<=0)throw Error(`Enter a positive supported budget.`);return i}function _(e,t){if(!Number.isSafeInteger(e)||e<0)throw Error(`Use an exact saved budget.`);return new Intl.NumberFormat(void 0,{style:`currency`,currency:t}).format(e/10**h(t))}return Object.freeze({read:o,set:s,controls:u,change:d,fromState:f,edits:p,preview:m,currencyDigits:h,minorUnits:g,formatMoney:_})}function ur(){let e=Math.PI*2,t=Math.PI/180,n=3.5,r=(e,t=0,n=1)=>Math.max(t,Math.min(n,e)),i=(e,t,n)=>e+(t-e)*n,a=e=>e-Math.floor(e),o=e=>e<.5?4*e*e*e:1-(-2*e+2)**3/2,s=e=>o(r(e/.3))*o(r((1-e)/.3)),c=(e,t,n)=>[i(e[0],t[0],n),i(e[1],t[1],n)],l=(e,n,r=50,i=50)=>{let a=(-90+60*e)*t;return[r+n*Math.cos(a),i+n*Math.sin(a)]},u=(e,t)=>{let n=a(e)*6,r=Math.floor(n);return c(l(r,t),l(r+1,t),n-r)},d=(e,t)=>{let n=t?[...e,e[0]]:e,r=[0];for(let e=1;e<n.length;e++)r.push(r[e-1]+Math.hypot(n[e][0]-n[e-1][0],n[e][1]-n[e-1][1]));let i=r[r.length-1];return e=>{let t=a(e)*i,o=1;for(;o<r.length-1&&r[o]<t;)o++;return c(n[o-1],n[o],(t-r[o-1])/(r[o]-r[o-1]||1))}},f=e=>{let t=[];for(let n=0;n<720;n++)t.push(e(n/720));let n=d(t,!0);return[...Array(200)].map((e,t)=>n(t/200))},p=f(e=>u(e,36)),m=[0,1,2,3,4,5].map(e=>l(e,36)),h=[m[0],m[1],m[2],m[3],m[4],m[5],m[0],[50,50],m[2],m[3],m[4],[50,50]],g=[0,1,2].map(e=>l(e*2,40,50,54)),_=[[f(t=>[50+36*Math.sin(e*t),50-36*Math.cos(e*t)]),2,!1],[f(d(h,!0)),1,!1],[f(d(g,!0)),2,!0],[f(t=>[50+40*Math.sin(e*t),50-20*Math.sin(2*e*t)]),1,!0],[f(t=>[50+36*Math.sin(3*e*t),50-36*Math.cos(2*e*t)]),1,!1],[f(t=>{let n=e*t;return[50+26*Math.sin(n)+12*Math.sin(-5*n),50-26*Math.cos(n)-12*Math.cos(-5*n)]}),1,!0],[e=>p.map(t=>{let n=t[0]-50,r=t[1]-50,i=1+.16*Math.sin(6*Math.atan2(n,-r)-e*8);return[50+n*i,50+r*i]}),2,!1]],v=e=>{let t=_.length*n,i=a(e/t)*t,l=Math.min(_.length-1,Math.floor(i/n)),u=r((i-l*n)/n),[d,f,m]=_[l],h=typeof d==`function`?d(e):d,g=s(u),v=p.map((e,t)=>c(e,h[t],g)),y=e=>{let t=a(e)*200,n=Math.floor(t)%200;return c(v[n],v[(n+1)%200],t-Math.floor(t))},b=22+8*g,x=(e*40+100*f*o(u))%100,S=x+50*g*!!m;return{d:`M`+v.map(e=>e[0].toFixed(2)+` `+e[1].toFixed(2)).join(`L`)+`Z`,len:b,offsets:[x,S],heads:[y((x+b)/100),y((S+b)/100)]}},y=(e,t)=>{let[n,r,i,a,o]=e;n.setAttribute(`d`,t.d),[r,i].forEach((e,n)=>{e.setAttribute(`d`,t.d),e.setAttribute(`stroke-dasharray`,`${t.len} ${100-t.len}`),e.setAttribute(`stroke-dashoffset`,String(-t.offsets[n]))}),[a,o].forEach((e,n)=>{e.setAttribute(`cx`,t.heads[n][0].toFixed(2)),e.setAttribute(`cy`,t.heads[n][1].toFixed(2))})};return{frame:v,paint:y,run:e=>{let t=e?[...e.querySelectorAll(`.sm-trace-track,.sm-trace-dash,.sm-trace-head`)]:[];if(t.length<5||(y(t,v(0)),window.matchMedia&&window.matchMedia(`(prefers-reduced-motion: reduce)`).matches))return;let n=performance.now();requestAnimationFrame(function r(i){e.isConnected&&(y(t,v((i-n)/1e3)),requestAnimationFrame(r))})}}}var dr=s((e=>{var t=f(),n=Symbol.for(`react.element`),r=Symbol.for(`react.fragment`),i=Object.prototype.hasOwnProperty,a=t.__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED.ReactCurrentOwner,o={key:!0,ref:!0,__self:!0,__source:!0};function s(e,t,r){var s,c={},l=null,u=null;for(s in r!==void 0&&(l=``+r),t.key!==void 0&&(l=``+t.key),t.ref!==void 0&&(u=t.ref),t)i.call(t,s)&&!o.hasOwnProperty(s)&&(c[s]=t[s]);if(e&&e.defaultProps)for(s in t=e.defaultProps,t)c[s]===void 0&&(c[s]=t[s]);return{$$typeof:n,type:e,key:l,ref:u,props:c,_owner:a.current}}e.Fragment=r,e.jsx=s,e.jsxs=s})),fr=s(((e,t)=>{t.exports=dr()})),V=fr(),{frame:pr,paint:mr}=ur(),hr=pr;function gr({size:e=20,paused:t=!1,className:n=``}){let r=(0,v.useRef)([]),i=(0,v.useRef)(0),a=e=>t=>{r.current[e]=t};return(0,v.useEffect)(()=>{let e=[...r.current];if(e.length<5||e.some(e=>!e))return;let n=t||window.matchMedia?.(`(prefers-reduced-motion: reduce)`).matches;if(mr(e,hr(i.current)),n)return;let a=performance.now()-i.current*1e3,o=requestAnimationFrame(function t(n){i.current=(n-a)/1e3,mr(e,hr(i.current)),o=requestAnimationFrame(t)});return()=>cancelAnimationFrame(o)},[t]),(0,V.jsxs)(`svg`,{className:`sm-trace-loader${n?` ${n}`:``}`,width:e,height:e,viewBox:`0 0 100 100`,"aria-hidden":`true`,focusable:`false`,children:[(0,V.jsx)(`path`,{ref:a(0),className:`sm-trace-track`,fill:`none`,strokeWidth:`3`,strokeLinejoin:`round`,strokeLinecap:`round`}),(0,V.jsx)(`path`,{ref:a(1),className:`sm-trace-dash`,fill:`none`,strokeWidth:`5`,strokeLinejoin:`round`,strokeLinecap:`round`,pathLength:`100`}),(0,V.jsx)(`path`,{ref:a(2),className:`sm-trace-dash`,fill:`none`,strokeWidth:`5`,strokeLinejoin:`round`,strokeLinecap:`round`,pathLength:`100`}),(0,V.jsx)(`circle`,{ref:a(3),className:`sm-trace-head`,r:`5.5`}),(0,V.jsx)(`circle`,{ref:a(4),className:`sm-trace-head`,r:`5.5`})]})}function _r({label:e=`Loading`,fill:t=!1}){return(0,V.jsxs)(`div`,{className:`sm-loading-screen${t?` is-fill`:``}`,role:`status`,children:[(0,V.jsx)(gr,{size:96,className:`sm-loading-trace`}),(0,V.jsx)(`span`,{className:`sm-sr`,children:e})]})}function vr(e,t,n=!1){if(t>=e.length)return null;let r=e[t];if(r===0)return null;let i=1,a=128;for(;!(r&a);)if(i++,a>>=1,i>8)return null;if(t+i>e.length)return null;let o=n?r:r&a-1,s=(r&a-1)==a-1;for(let n=1;n<i;n++)o=o*256+e[t+n],e[t+n]!==255&&(s=!1);return{value:o,length:i,unknown:!n&&s}}function yr(e,t){let n=vr(e,t,!0);if(!n)return null;let r=vr(e,t+n.length);if(!r)return null;let i=t+n.length+r.length;return{id:n.value,idLength:n.length,sizeLength:r.length,size:r.unknown?null:r.value,dataOffset:i,end:r.unknown?null:i+r.value}}function br(e,t){let n=new Uint8Array(t),r=e;for(let e=t-1;e>0;e--)n[e]=r%256,r=Math.floor(r/256);return n[0]=r|256>>t,n}function xr(e){let t=yr(e,0);if(!t||t.id!==Tr.ebml||t.end===null)return null;let n=yr(e,t.end);if(!n||n.id!==Tr.segment)return null;let r=n.dataOffset,i=n.end===null?e.length:Math.min(e.length,n.end);for(;r<i;){let t=yr(e,r);if(!t||t.end===null)return null;if(t.id===Tr.info){if(t.end>e.length)return null;let r=Dr,a=null,o=t.dataOffset;for(;o<t.end;){let n=yr(e,o);if(!n||n.end===null||n.end>t.end)return null;n.id===Tr.timecodeScale&&(r=kr(e,n.dataOffset,n.size)),n.id===Tr.duration&&[4,8].includes(n.size)&&(a={offset:n.dataOffset,length:n.size,value:Or(e,n.dataOffset,n.size)}),o=n.end}let s=t.end<i?yr(e,t.end):null;return{segment:n,info:t,timecodeScale:r,duration:a,voidAfter:s&&s.id===Tr.voidElement&&s.end!==null?s:null}}r=t.end}return null}function Sr(e,t){let n=xr(e);if(!n||!(t>0))return null;let r=t*Dr/n.timecodeScale;if(n.duration){let t=e.slice(),i=new DataView(t.buffer,t.byteOffset+n.duration.offset,n.duration.length);return n.duration.length===4?i.setFloat32(0,r):i.setFloat64(0,r),t}let i=new Uint8Array(11);i.set([68,137,136]),new DataView(i.buffer,3,8).setFloat64(0,r);let{info:a}=n,o=e.subarray(a.dataOffset,a.end),s=o.length+i.length;if(s>=2**(7*a.sizeLength)-1)return null;let c=i.length,l=[e.subarray(0,a.dataOffset-a.sizeLength),br(s,a.sizeLength),o,i],u=n.voidAfter;if(u){let t=u.end-(u.dataOffset-u.sizeLength-u.idLength);if(t===c)return Cr([...l,e.subarray(u.end)]);let n=t-c-u.idLength-u.sizeLength;if(n>=0&&n<2**(7*u.sizeLength)-1)return Cr([...l,new Uint8Array([Tr.voidElement]),br(n,u.sizeLength),new Uint8Array(n),e.subarray(u.end)])}let d=Cr([...l,e.subarray(a.end)]);if(n.segment.end!==null){let e=n.segment.size+c;if(e>=2**(7*n.segment.sizeLength)-1)return null;d.set(br(e,n.segment.sizeLength),n.segment.dataOffset-n.segment.sizeLength)}return d}function Cr(e){let t=new Uint8Array(e.reduce((e,t)=>e+t.length,0)),n=0;for(let r of e)t.set(r,n),n+=r.length;return t}async function wr(e,t){if(!/^(?:video|audio)\/webm/i.test(e?.type||``)||!(t>0))return e;try{let n=new Uint8Array(await e.slice(0,Er).arrayBuffer()),r=xr(n);if(!r)return e;let i=r.voidAfter?r.voidAfter.end:r.info.end,a=Sr(n.subarray(0,i),t);return a?new Blob([a,e.slice(i)],{type:e.type}):e}catch{return e}}var Tr,Er,Dr,Or,kr,Ar=o((()=>{Tr={ebml:440786851,segment:408125543,info:357149030,timecodeScale:2807729,duration:17545,voidElement:236},Er=1048576,Dr=1e6,Or=(e,t,n)=>{let r=new DataView(e.buffer,e.byteOffset+t,n);return n===4?r.getFloat32(0):r.getFloat64(0)},kr=(e,t,n)=>{let r=0;for(let i=0;i<n;i++)r=r*256+e[t+i];return r}}));function jr(e,{isTypeSupported:t,canPlayType:n}={}){let r=Fr[e===`microphone`?`audio`:`video`].filter(e=>{try{return t?.(e)===!0}catch{return!1}});return r.find(e=>{try{return!!n?.(e)}catch{return!1}})||r[0]}function Mr({width:e,height:t,frameRate:n}={}){let r=(Number(e)||1920)*(Number(t)||1080),i=Ir.find(([e])=>r>=e)[1];return Math.round(i*((Number(n)||30)>=50?1.5:1))}function Nr({resolution:e=`1080p`,frameRate:t=30}={}){let n=Rr[e]===void 0?Rr[`1080p`]:Rr[e];return{frameRate:{ideal:t,max:60},...n?{width:{max:n.width},height:{max:n.height}}:{}}}function Pr({platform:e=`browser`,bitsPerSecond:t,quota:n=null,used:r=0}={}){let i=zr[e]||zr.browser,a=Number.isFinite(n)&&n>0?Math.min(i.bytes,Math.max(0,n-(Number(r)||0))):i.bytes,o=t>0?Math.floor(a*8/t):i.seconds;return{seconds:Math.max(0,Math.min(i.seconds,o)),bytes:a}}var Fr,Ir,Lr,Rr,zr,Br,Vr=o((()=>{Fr=Object.freeze({video:Object.freeze([`video/webm;codecs=h264`,`video/webm;codecs=vp9`,`video/webm`,`video/webm;codecs=vp8`,`video/mp4;codecs=avc1.42E01E`,`video/mp4`]),audio:Object.freeze([`audio/webm;codecs=opus`,`audio/webm`,`audio/mp4`,`audio/ogg;codecs=opus`])}),Ir=Object.freeze([[8294400,24e6],[3686400,14e6],[2073600,8e6],[0,5e6]]),Lr=Object.freeze({voice:128e3,system:192e3}),Rr=Object.freeze({"1080p":{width:1920,height:1080},source:null}),zr=Object.freeze({browser:Object.freeze({seconds:1800,bytes:2147483648}),desktop:Object.freeze({seconds:14400,bytes:1/0}),legacyDesktop:Object.freeze({seconds:1800,bytes:134217728})}),Br=(e,t,n=Date.now())=>`${e}-recording-${new Date(n).toISOString().replace(/[:.]/g,`-`).slice(0,19)}.${/mp4/.test(t||``)?`mp4`:/ogg/.test(t||``)?`ogg`:`webm`}`}));Ar(),Vr();var Hr=Object.freeze({fps:Object.freeze({min:1,max:30,default:15}),width:Object.freeze({min:160,max:1280,default:640}),sampleRate:Object.freeze({min:8e3,max:48e3,default:16e3}),inFlightFrames:2,audioChunk:4096,seconds:3600}),Ur=(e,{min:t,max:n,default:r},i)=>{if(e==null)return r;let a=Number(e);if(!Number.isInteger(a)||a<t||a>n)throw Error(`live.start ${i} is a whole number from ${t} to ${n}.`);return a};function Wr(e={}){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`live.start takes {camera, microphone, fps, width, sampleRate}.`);let t=e.camera===!0,n=e.microphone===!0;if(!t&&!n)throw Error(`live.start needs camera: true, microphone: true or both.`);return{camera:t,microphone:n,fps:Ur(e.fps,Hr.fps,`fps`),width:Ur(e.width,Hr.width,`width`),sampleRate:Ur(e.sampleRate,Hr.sampleRate,`sampleRate`)}}var Gr=e=>{try{for(let t of e?.getTracks?.()||[])t.stop()}catch{}},Kr=e=>Math.max(2,Math.round(e/2)*2);function qr(e,{camera:t,microphone:n,fps:r,width:i,sampleRate:a,onFrame:o=()=>{},onAudio:s=()=>{},onEnded:c=()=>{},seconds:l=Hr.seconds,now:u=()=>performance.now(),doc:d=globalThis.document,toBitmap:f=(...e)=>globalThis.createImageBitmap(...e),AudioContextClass:p=globalThis.AudioContext||globalThis.webkitAudioContext}){let m=u(),h={camera:!!t,microphone:!!n,fps:r,width:0,height:0,sampleRate:0},g=!1,_=Hr.inFlightFrames,v=0,y=0,b=null,x=!1,S=null,C=null,w=null,T=null,E=setTimeout(()=>D(`time`),l*1e3),D=(t=`stopped`)=>{if(!g){g=!0,clearTimeout(b),clearTimeout(E);try{w&&(w.onaudioprocess=null),T?.disconnect?.(),w?.disconnect?.()}catch{}try{C?.close?.()}catch{}if(S){try{S.pause()}catch{}S.srcObject=null}Gr(e),c(t)}};for(let t of e?.getTracks?.()||[])t.addEventListener?.(`ended`,()=>D(`ended`));let O=()=>{let e=S?.videoWidth||0,t=S?.videoHeight||0;if(!e||!t)return null;let n=Kr(Math.min(i,e));return{width:n,height:Kr(n*t/e)}},k=async()=>{if(b=null,g)return;let e=O();if(_>0&&!x&&e&&S.readyState>=2){x=!0,_--;try{let t=await f(S,{resizeWidth:e.width,resizeHeight:e.height,resizeQuality:`low`});g?t.close?.():(h.width=e.width,h.height=e.height,o(t,{index:v++,timestamp:Math.round(u()-m),width:e.width,height:e.height}))}catch{_++}finally{x=!1}}g||(b=setTimeout(k,1e3/r))};return{ready:(async()=>{try{if(t){if(S=d.createElement(`video`),S.muted=!0,S.playsInline=!0,S.srcObject=e,await S.play(),g)return h;let t=O();t&&(h.width=t.width,h.height=t.height),b=setTimeout(k,0)}if(n){if(typeof p!=`function`)throw Error(`This browser cannot read the microphone live.`);try{C=new p({sampleRate:a}),T=C.createMediaStreamSource(e)}catch{try{C?.close?.()}catch{}C=new p,T=C.createMediaStreamSource(e)}w=C.createScriptProcessor(Hr.audioChunk,1,1),w.onaudioprocess=e=>{g||s(new Float32Array(e.inputBuffer.getChannelData(0)),{index:y++,timestamp:Math.round(u()-m),sampleRate:C.sampleRate})},T.connect(w),w.connect(C.destination),await C.resume?.().catch?.(()=>{}),h.sampleRate=C.sampleRate}return h}catch(e){throw D(`error`),e}})(),info:h,ack(){!g&&_<Hr.inFlightFrames&&_++},stop:D,get stopped(){return g}}}var Jr=Object.freeze({folders:4,entries:1e3,textBytes:1048576,pathLength:1024,depth:32}),Yr=Object.freeze([`folder.pick`,`folder.shared`,`folder.forget`,`folder.list`,`folder.read`,`folder.write`]);Object.freeze([`folder.shared`,`folder.list`,`folder.read`]);var Xr=/^[^\0/\\:*?"<>|]{1,255}$/,Zr=/^(con|prn|aux|nul|com\d|lpt\d)(\..*)?$/i,Qr=e=>{throw Error(e)},$r=e=>e.startsWith(`.`),ei=`Hidden files and folders are not shared with Blocks.`,ti=new Set(`png.jpg.jpeg.gif.webp.avif.bmp.tif.tiff.heic.heif.exr.dpx.tga.psd.mp4.mov.webm.mkv.avi.m4v.mxf.mts.mp3.wav.m4a.aac.ogg.oga.opus.flac.aif.aiff.txt.srt.vtt.ass.ssa.sbv.csv.tsv.edl.otio.cube.pdf`.split(`.`)),ni=/^(cmakelists|requirements|constraints|llms)([.-][^.]*)?\.txt$/i,ri=/\.(app|bundle|framework|plugin|kext|appex|xpc|prefpane|saver|workflow|action|service|component|qlgenerator|mdimporter)$/i;function ii(e){let t=e.at(-1),n=t.lastIndexOf(`.`);if(e.slice(0,-1).some(e=>ri.test(e))||ni.test(t))return!1;let r=n>0?t.slice(n+1):``;return/^[a-z0-9]+$/i.test(r)&&ti.has(r.toLowerCase())||/^[^.].*\.stillmade\.json$/.test(t)}var ai=e=>`A Block cannot create or replace ${e}: folder.write writes media, subtitles, plain text, tables and <name>.stillmade.json only.`;function oi(e){if(e===void 0||e===``)return[];(typeof e!=`string`||e.length>Jr.pathLength)&&Qr(`Name a file by its path inside the folder, like photos/cover.png.`);let t=e.split(`/`);return(t.length>Jr.depth||t.some(e=>!Xr.test(e)||e===`.`||e===`..`||e!==e.trim()||e.endsWith(`.`)||Zr.test(e)||/~\d/.test(e)))&&Qr(`${e} is not a path inside the chosen folder.`),t.some($r)&&Qr(ei),t}function si(e){return e.filter(e=>!$r(e.name)).sort((e,t)=>e.kind===t.kind?e.name.localeCompare(t.name):e.kind===`folder`?-1:1)}Kt();var ci=()=>typeof globalThis.showDirectoryPicker==`function`,li=e=>`blockFolders:${e}`,ui=(e,t)=>{throw Object.assign(Error(e),t?{code:t}:{})},di=e=>[`SecurityError`,`NotAllowedError`].includes(e?.name)&&!/abort|cancel/i.test(e?.message||``);async function fi(e){/^[a-f0-9]{64}$/.test(e||``)&&await Gt(zt,li(e))}async function pi(e,t){try{return await e.getDirectoryHandle(t),`folder`}catch(e){if(e?.name===`TypeMismatchError`)return`file`}try{return await e.getFileHandle(t),`file`}catch(e){if(e?.name===`TypeMismatchError`)return`folder`}return null}function mi({key:e,digest:t,name:n=`this Block`,permissions:r=[],askToStart:i,importMedia:a,mediaBlob:o,pick:s=e=>globalThis.showDirectoryPicker(e)}){let c=null,l=async()=>{if(c)return c;c=new Map;let n=e?await Ht(zt,li(e)).catch(()=>null):null;if(n&&n.digest!==t)return await fi(e),c;for(let e of n?.folders||[])e?.handle&&typeof e.id==`string`&&c.set(e.id,e);return c},u=async()=>{if(!e)return;let n=[...c.values()].slice(0,Jr.folders);n.length?await Wt(zt,{digest:t,folders:n},li(e)):await fi(e)},d=async e=>{let t={mode:e.write?`readwrite`:`read`};if(await e.handle.queryPermission?.(t)===`granted`)return;let n;try{n=await e.handle.requestPermission(t)}catch(r){if(!di(r)||!i)throw r;await i({kind:`folder-access`,folder:e.name,write:e.write}),n=await e.handle.requestPermission(t)}n!==`granted`&&ui(`StillMade cannot use ${e.name} until you allow it.`,`FOLDER_ACCESS`)},f=async(e,{write:t=!1}={})=>{let n=typeof e==`string`?(await l()).get(e):null;return n||ui(`Choose a folder first; this one is not shared with this Block.`),t&&!n.write&&ui(`This folder was shared for reading only.`),await d(n),n},p=async(e,t,{create:n=!1}={})=>{let r=e;for(let e of t)try{r=await r.getDirectoryHandle(e,{create:n})}catch(e){if(e?.name===`TypeMismatchError`&&ui(`That path is not a folder.`),e?.name===`NotFoundError`)return null;throw e}return r},m=()=>({folders:[...c.values()].map(({id:e,name:t,write:n})=>({id:e,name:t,write:n}))});return{async invoke(e,t={}){if(Yr.includes(e)||ui(`Unknown folder operation`),await l(),e===`folder.shared`)return m();if(e===`folder.forget`)return c.delete(t.folder)||ui(`That folder is not shared with this Block.`),await u(),{forgotten:!0};if(e===`folder.pick`){let e=t.write===!0;e&&!r.includes(`folder.write`)&&ui(`This Block did not ask to change files.`),c.size>=Jr.folders&&ui(`A Block can use at most ${Jr.folders} folders. Forget one first.`);let a={mode:e?`readwrite`:`read`,id:`stillmade-block-folder`},o;try{o=await s(a)}catch(t){if(t?.name===`AbortError`&&ui(`No folder was chosen.`),!di(t)||!i)throw t;await i({kind:`folder`,write:e,name:n});try{o=await s(a)}catch(e){throw e?.name===`AbortError`&&ui(`No folder was chosen.`),e}}$r(o.name)&&ui(e?`Choose a folder that is not hidden for a Block to change.`:ei),e&&await pi(o,`.git`)&&ui(`Choose a folder outside a code repository for a Block to change.`);let l=null;for(let e of c.values())await e.handle.isSameEntry?.(o)&&(l=e);let d={id:l?.id||crypto.randomUUID(),name:o.name,write:e,handle:o,chosenAt:Date.now()};return c.set(d.id,d),await u(),{folder:{id:d.id,name:d.name,write:e}}}let d=await f(t.folder,{write:e===`folder.write`}),h=oi(t.path);if(e===`folder.list`){let e=await p(d.handle,h);e||ui(`That folder does not exist inside the chosen folder.`);let t=[],n=0;for await(let[r,i]of e.entries()){if(++n>Jr.entries)break;if(!$r(r)){if(i.kind===`directory`)t.push({name:r,kind:`folder`,size:0,modified:null});else{let e=await i.getFile().catch(()=>null);e&&t.push({name:r,kind:`file`,size:e.size,modified:new Date(e.lastModified).toISOString()})}}}return{entries:si(t),truncated:n>Jr.entries}}h.length||ui(`Name a file inside the folder.`);let g=h.slice(0,-1),_=h.at(-1);if(e===`folder.read`){let e=await p(d.handle,g),n;try{n=e&&await e.getFileHandle(_)}catch{n=null}n||ui(`That file does not exist in the chosen folder.`);let r=await n.getFile();return t.as===`media`?{asset:await a(r,n),size:r.size}:(r.size>Jr.textBytes&&ui(`Read files up to 1 MB as text, or media files as media.`),{text:await r.text(),size:r.size})}ii(h)||ui(ai(_));let v;typeof t.text==`string`?(new TextEncoder().encode(t.text).byteLength>Jr.textBytes&&ui(`Write at most 1 MB of text at a time.`),v=t.text):t.asset&&typeof t.asset.assetId==`string`?(v=await o(t.asset).catch(()=>null),v||ui(`Write media this Block saved or received on this device.`)):ui(`folder.write takes text or a saved asset.`);let y=d.handle;await pi(y,`.git`)&&ui(`This Block cannot change files inside a code repository.`);for(let e of g)await pi(y,e)===`file`&&ui(`That path is not a folder.`),y=await y.getDirectoryHandle(e,{create:!0}),await pi(y,`.git`)&&ui(`This Block cannot change files inside a code repository.`);let b=await pi(y,_);b===`folder`&&ui(`A folder already has that name.`),b&&t.replace!==!0&&ui(`That file exists. Pass replace: true to replace it.`);let x=await(await y.getFileHandle(_,{create:!0})).createWritable({keepExistingData:!1});try{await x.write(v),await x.close()}catch(e){throw await x.abort?.().catch(()=>{}),e}return{written:h.join(`/`),replaced:!!b}}}}Tt(),Yt();async function hi(e,t=`preview`){let n=String(t||`preview`),r=/(^|:)preview$/.test(n),i=[`stillmade-block-access/1`,qt()||`anonymous`,n,e?.manifest?.id||``,r?await gt(e):``].join(`|`),a=new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(i)));return Array.from(a,e=>e.toString(16).padStart(2,`0`)).join(``)}async function gi(e,t,{bridge:n=globalThis.stillmadeDesktop?.blockDesktop}={}){let r=await hi(e,t);await Promise.all([n?.forgetRemembered?.(r).catch(()=>{}),fi(r).catch(()=>{})])}var _i,vi,yi,bi,xi=o((()=>{_i=`modulepreload`,vi=function(e){return`/`+e},yi={},bi=function(e,t,n){let r=Promise.resolve();if(t&&t.length>0){let e=document.getElementsByTagName(`link`),i=document.querySelector(`meta[property=csp-nonce]`),a=i?.nonce||i?.getAttribute(`nonce`);function o(e){return Promise.all(e.map(e=>Promise.resolve(e).then(e=>({status:`fulfilled`,value:e}),e=>({status:`rejected`,reason:e}))))}function s(e){return import.meta.resolve?import.meta.resolve(e):new URL(e,import.meta.url).href}r=o(t.map(t=>{if(t=vi(t,n),t=s(t),t in yi)return;yi[t]=!0;let r=t.endsWith(`.css`);for(let n=e.length-1;n>=0;n--){let i=e[n];if(i.href===t&&(!r||i.rel===`stylesheet`))return}let i=document.createElement(`link`);if(i.rel=r?`stylesheet`:_i,r||(i.as=`script`),i.crossOrigin=``,i.href=t,a&&i.setAttribute(`nonce`,a),document.head.appendChild(i),r)return new Promise((e,n)=>{i.addEventListener(`load`,e),i.addEventListener(`error`,()=>n(Error(`Unable to preload CSS for ${t}`)))})}).filter(e=>e!==void 0))}function i(e){let t=new Event(`vite:preloadError`,{cancelable:!0});if(t.payload=e,window.dispatchEvent(t),!t.defaultPrevented)throw e}return r.then(t=>{for(let e of t||[])e.status===`rejected`&&i(e.reason);return e().catch(i)})}}));function Si(e){return B(e?.version===1&&Ci.every(t=>e[t]!==void 0&&(typeof e[t]==`function`||[`toast`,`presenterHost`,`upgradeReasons`].includes(t))),`HOST_SERVICES`,`Shared native UI requires version 1 of its declared runtime host.`),e}var Ci,wi=o((()=>{Tt(),Ci=Object.freeze(`loadMediaBlob.loadMediaArrayBuffer.resolveDesktopMediaUrl.isMissing.runFinalEdit.runStructureEdit.runMotionGraphics.transcribeAudio.useTier.requestUpgrade.upgradeReasons.confirm.alert.toast.HelpHint.downloadUrlLocally.extensionFromUrl.safeDownloadName.proxiedMediaUrl.uploadReferenceImage.getAllAssets.addAsset.recordAssets.listProjects.loadProject.stockGrid.stockSelect.useIsMobileUI.desktopBridge.authHeaders.useCanvas.useCanvasWriteAccess.generateReference.fetchStyleOptions.fetchStyleFromUploads.generateReferenceSheet.useReferenceExtraction.findExtractedViews.addLibraryItem.getLibraryItems.useThumb.planAllows.tagAsset.runLlmText.CanvasCommitInput.cachedObjectUrlIfPresent.presenterHost`.split(`.`))}));function Ti(e){return Di=Object.freeze(Si(e)),Di}function Ei(){if(!Di)throw Object.assign(Error(`Shared native runtime host is unavailable.`),{code:`HOST_SERVICES`});return Di}var Di,Oi=o((()=>{wi(),Di=null}));async function ki(){if(typeof VideoEncoder>`u`)return null;for(let e of Fi)try{let{supported:t}=await VideoEncoder.isConfigSupported({codec:e,width:Ii.width,height:Ii.height,framerate:Ii.framerate,bitrate:Ii.bitrate});if(t)return e}catch{}return null}async function Ai(e){if(!e)return null;try{let{supported:t}=await VideoEncoder.isConfigSupported({codec:e,width:Ii.width,height:Ii.height,framerate:Ii.framerate,bitrate:Ii.bitrate,hardwareAcceleration:`prefer-hardware`});return t?`prefer-hardware`:`no-preference`}catch{return`no-preference`}}async function ji(){if(typeof AudioEncoder>`u`)return!1;try{let{supported:e}=await AudioEncoder.isConfigSupported({codec:`mp4a.40.2`,sampleRate:44100,numberOfChannels:2,bitrate:192e3});return!!e}catch{return!1}}function Mi(){try{let e=typeof OffscreenCanvas<`u`?new OffscreenCanvas(2,2):typeof document<`u`?document.createElement(`canvas`):null;if(!e)return!1;let t=e.getContext(`2d`);if(!t||!(`filter`in t))return!1;t.filter=`blur(1px)`;let n=t.filter===`blur(1px)`;return t.filter=`none`,n}catch{return!1}}function Ni(){try{return typeof OffscreenCanvas>`u`?!1:!!new OffscreenCanvas(2,2).getContext(`2d`)}catch{return!1}}async function Pi(){let e=[],t=typeof globalThis<`u`&&globalThis.crossOriginIsolated===!0,n=typeof SharedArrayBuffer<`u`,[r,i]=await Promise.all([ki(),ji()]),a=await Ai(r),o=Ni(),s=Mi(),c=!!r&&o&&s;r||e.push(`No supported H.264 VideoEncoder config.`),o||e.push(`OffscreenCanvas 2D unavailable.`),s||e.push(`Canvas2D ctx.filter unsupported (color/LUT would be wrong) — routing to wasm.`),c&&!i&&e.push(`No AAC AudioEncoder — audio will be encoded via ffmpeg.wasm, video via WebCodecs.`);let l=t;t||e.push(`Not crossOriginIsolated — multi-threaded ffmpeg.wasm core unavailable (check COOP/COEP headers).`);let u=`none`;return c?u=`webcodecs`:l&&(u=`wasm`),{strategy:u,videoCodec:r,hardwareAcceleration:a,audioViaWebCodecs:c&&i,offscreenCanvas:o,canvasFilter:s,crossOriginIsolated:t,sharedArrayBuffer:n,notes:e}}var Fi,Ii,Li=o((()=>{Fi=[`avc1.640028`,`avc1.4d0028`,`avc1.42e028`],Ii={width:1920,height:1080,framerate:24,bitrate:1e7}})),Ri,H,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,U,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa,pa,ma,ha,ga,_a,va,ya,ba,xa,Sa,Ca,wa,Ta,Ea,Da,Oa,ka,Aa,ja,Ma,Na,Pa,Fa,Ia,La,Ra,za,Ba,Va,Ha,Ua,Wa,Ga,Ka,qa,Ja,Ya,Xa,Za,Qa,$a,eo,to,no,ro,io,ao,oo,so,co,lo,uo,fo,po,mo,ho,go,_o,vo,yo,bo,xo,So,Co,wo,To,Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo,$o,es,ts,ns,rs,is,as,os,ss,cs,ls,us,ds,fs,ps,ms,hs,gs,_s,vs,ys,bs,xs,Ss,Cs,ws,Ts,Es,Ds,Os,ks=o((()=>{Ri=(e,t,n)=>{if(!t.has(e))throw TypeError(`Cannot `+n)},H=(e,t,n)=>(Ri(e,t,`read from private field`),n?n.call(e):t.get(e)),zi=(e,t,n)=>{if(t.has(e))throw TypeError(`Cannot add the same private member more than once`);t instanceof WeakSet?t.add(e):t.set(e,n)},Bi=(e,t,n,r)=>(Ri(e,t,`write to private field`),r?r.call(e,n):t.set(e,n),n),Vi=(e,t,n,r)=>({set _(r){Bi(e,t,r,n)},get _(){return H(e,t,r)}}),Hi=(e,t,n)=>(Ri(e,t,`access private method`),n),Ui=new Uint8Array(8),Wi=new DataView(Ui.buffer),Gi=e=>[(e%256+256)%256],Ki=e=>(Wi.setUint16(0,e,!1),[Ui[0],Ui[1]]),qi=e=>(Wi.setInt16(0,e,!1),[Ui[0],Ui[1]]),Ji=e=>(Wi.setUint32(0,e,!1),[Ui[1],Ui[2],Ui[3]]),U=e=>(Wi.setUint32(0,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),Yi=e=>(Wi.setInt32(0,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),Xi=e=>(Wi.setUint32(0,Math.floor(e/2**32),!1),Wi.setUint32(4,e,!1),[Ui[0],Ui[1],Ui[2],Ui[3],Ui[4],Ui[5],Ui[6],Ui[7]]),Zi=e=>(Wi.setInt16(0,256*e,!1),[Ui[0],Ui[1]]),Qi=e=>(Wi.setInt32(0,2**16*e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),$i=e=>(Wi.setInt32(0,2**30*e,!1),[Ui[0],Ui[1],Ui[2],Ui[3]]),ea=(e,t=!1)=>{let n=Array(e.length).fill(null).map((t,n)=>e.charCodeAt(n));return t&&n.push(0),n},ta=e=>e&&e[e.length-1],na=e=>{let t;for(let n of e)(!t||n.presentationTimestamp>t.presentationTimestamp)&&(t=n);return t},ra=(e,t,n=!0)=>{let r=e*t;return n?Math.round(r):r},ia=e=>{let t=Math.PI/180*e,n=Math.cos(t),r=Math.sin(t);return[n,r,0,-r,n,0,0,0,1]},aa=ia(0),oa=e=>[Qi(e[0]),Qi(e[1]),$i(e[2]),Qi(e[3]),Qi(e[4]),$i(e[5]),Qi(e[6]),Qi(e[7]),$i(e[8])],sa=e=>!e||typeof e!=`object`?e:Array.isArray(e)?e.map(sa):Object.fromEntries(Object.entries(e).map(([e,t])=>[e,sa(t)])),ca=e=>e>=0&&e<2**32,la=(e,t,n)=>({type:e,contents:t&&new Uint8Array(t.flat(10)),children:n}),ua=(e,t,n,r,i)=>la(e,[Gi(t),Ji(n),r??[]],i),da=e=>e.fragmented?la(`ftyp`,[ea(`iso5`),U(512),ea(`iso5`),ea(`iso6`),ea(`mp41`)]):la(`ftyp`,[ea(`isom`),U(512),ea(`isom`),e.holdsAvc?ea(`avc1`):[],ea(`mp41`)]),fa=e=>({type:`mdat`,largeSize:e}),pa=e=>({type:`free`,size:e}),ma=(e,t,n=!1)=>la(`moov`,null,[ha(t,e),...e.map(e=>ga(e,t)),n?qa(e):null]),ha=(e,t)=>{let n=ra(Math.max(0,...t.filter(e=>e.samples.length>0).map(e=>{let t=na(e.samples);return t.presentationTimestamp+t.duration})),Vo),r=Math.max(...t.map(e=>e.id))+1,i=!ca(e)||!ca(n),a=i?Xi:U;return ua(`mvhd`,+i,0,[a(e),a(e),U(Vo),a(n),Qi(1),Zi(1),Array(10).fill(0),oa(aa),Array(24).fill(0),U(r)])},ga=(e,t)=>la(`trak`,null,[_a(e,t),va(e,t)]),_a=(e,t)=>{let n=na(e.samples),r=ra(n?n.presentationTimestamp+n.duration:0,Vo),i=!ca(t)||!ca(r),a=i?Xi:U,o;return o=e.info.type===`video`?typeof e.info.rotation==`number`?ia(e.info.rotation):e.info.rotation:aa,ua(`tkhd`,+i,3,[a(t),a(t),U(e.id),U(0),a(r),Array(8).fill(0),Ki(0),Ki(0),Zi(+(e.info.type===`audio`)),Ki(0),oa(o),Qi(e.info.type===`video`?e.info.width:0),Qi(e.info.type===`video`?e.info.height:0)])},va=(e,t)=>la(`mdia`,null,[ya(e,t),ba(e.info.type===`video`?`vide`:`soun`),xa(e)]),ya=(e,t)=>{let n=na(e.samples),r=ra(n?n.presentationTimestamp+n.duration:0,e.timescale),i=!ca(t)||!ca(r),a=i?Xi:U;return ua(`mdhd`,+i,0,[a(t),a(t),U(e.timescale),a(r),Ki(21956),Ki(0)])},ba=e=>ua(`hdlr`,0,0,[ea(`mhlr`),ea(e),U(0),U(0),U(0),ea(`mp4-muxer-hdlr`,!0)]),xa=e=>la(`minf`,null,[e.info.type===`video`?Sa():Ca(),wa(),Da(e)]),Sa=()=>ua(`vmhd`,0,1,[Ki(0),Ki(0),Ki(0),Ki(0)]),Ca=()=>ua(`smhd`,0,0,[Ki(0),Ki(0)]),wa=()=>la(`dinf`,null,[Ta()]),Ta=()=>ua(`dref`,0,0,[U(1)],[Ea()]),Ea=()=>ua(`url `,0,1),Da=e=>{let t=e.compositionTimeOffsetTable.length>1||e.compositionTimeOffsetTable.some(e=>e.sampleCompositionTimeOffset!==0);return la(`stbl`,null,[Oa(e),Va(e),Ha(e),Ua(e),Wa(e),Ga(e),t?Ka(e):null])},Oa=e=>ua(`stsd`,0,0,[U(1)],[e.info.type===`video`?ka(ao[e.info.codec],e):Ra(so[e.info.codec],e)]),ka=(e,t)=>la(e,[[,,,,,,].fill(0),Ki(1),Ki(0),Ki(0),Array(12).fill(0),Ki(t.info.width),Ki(t.info.height),U(4718592),U(4718592),U(0),Ki(1),Array(32).fill(0),Ki(24),qi(65535)],[oo[t.info.codec](t),t.info.decoderConfig.colorSpace?Na(t):null]),Aa={bt709:1,bt470bg:5,smpte170m:6},ja={bt709:1,smpte170m:6,"iec61966-2-1":13},Ma={rgb:0,bt709:1,bt470bg:5,smpte170m:6},Na=e=>la(`colr`,[ea(`nclx`),Ki(Aa[e.info.decoderConfig.colorSpace.primaries]),Ki(ja[e.info.decoderConfig.colorSpace.transfer]),Ki(Ma[e.info.decoderConfig.colorSpace.matrix]),Gi(!!e.info.decoderConfig.colorSpace.fullRange<<7)]),Pa=e=>e.info.decoderConfig&&la(`avcC`,[...new Uint8Array(e.info.decoderConfig.description)]),Fa=e=>e.info.decoderConfig&&la(`hvcC`,[...new Uint8Array(e.info.decoderConfig.description)]),Ia=e=>{if(!e.info.decoderConfig)return null;let t=e.info.decoderConfig;if(!t.colorSpace)throw Error(`'colorSpace' is required in the decoder config for VP9.`);let n=t.codec.split(`.`),r=Number(n[1]),i=Number(n[2]),a=(Number(n[3])<<4)+0+Number(t.colorSpace.fullRange);return ua(`vpcC`,1,0,[Gi(r),Gi(i),Gi(a),Gi(2),Gi(2),Gi(2),Ki(0)])},La=()=>la(`av1C`,[129,0,0,0]),Ra=(e,t)=>la(e,[[,,,,,,].fill(0),Ki(1),Ki(0),Ki(0),U(0),Ki(t.info.numberOfChannels),Ki(16),Ki(0),Ki(0),Qi(t.info.sampleRate)],[co[t.info.codec](t)]),za=e=>{let t=new Uint8Array(e.info.decoderConfig.description);return ua(`esds`,0,0,[U(58753152),Gi(32+t.byteLength),Ki(1),Gi(0),U(75530368),Gi(18+t.byteLength),Gi(64),Gi(21),Ji(0),U(130071),U(130071),U(92307584),Gi(t.byteLength),...t,U(109084800),Gi(1),Gi(2)])},Ba=e=>{let t=3840,n=0,r=e.info.decoderConfig?.description;if(r){if(r.byteLength<18)throw TypeError(`Invalid decoder description provided for Opus; must be at least 18 bytes long.`);let e=ArrayBuffer.isView(r)?new DataView(r.buffer,r.byteOffset,r.byteLength):new DataView(r);t=e.getUint16(10,!0),n=e.getInt16(14,!0)}return la(`dOps`,[Gi(0),Gi(e.info.numberOfChannels),Ki(t),U(e.info.sampleRate),Zi(n),Gi(0)])},Va=e=>ua(`stts`,0,0,[U(e.timeToSampleTable.length),e.timeToSampleTable.map(e=>[U(e.sampleCount),U(e.sampleDelta)])]),Ha=e=>{if(e.samples.every(e=>e.type===`key`))return null;let t=[...e.samples.entries()].filter(([,e])=>e.type===`key`);return ua(`stss`,0,0,[U(t.length),t.map(([e])=>U(e+1))])},Ua=e=>ua(`stsc`,0,0,[U(e.compactlyCodedChunkTable.length),e.compactlyCodedChunkTable.map(e=>[U(e.firstChunk),U(e.samplesPerChunk),U(1)])]),Wa=e=>ua(`stsz`,0,0,[U(0),U(e.samples.length),e.samples.map(e=>U(e.size))]),Ga=e=>e.finalizedChunks.length>0&&ta(e.finalizedChunks).offset>=2**32?ua(`co64`,0,0,[U(e.finalizedChunks.length),e.finalizedChunks.map(e=>Xi(e.offset))]):ua(`stco`,0,0,[U(e.finalizedChunks.length),e.finalizedChunks.map(e=>U(e.offset))]),Ka=e=>ua(`ctts`,0,0,[U(e.compositionTimeOffsetTable.length),e.compositionTimeOffsetTable.map(e=>[U(e.sampleCount),U(e.sampleCompositionTimeOffset)])]),qa=e=>la(`mvex`,null,e.map(Ja)),Ja=e=>ua(`trex`,0,0,[U(e.id),U(1),U(0),U(0),U(0)]),Ya=(e,t)=>la(`moof`,null,[Xa(e),...t.map(Qa)]),Xa=e=>ua(`mfhd`,0,0,[U(e)]),Za=e=>{let t=0,n=0,r=e.type===`delta`;return n|=+r,t|=r?1:2,t<<24|n<<16|0},Qa=e=>la(`traf`,null,[$a(e),eo(e),to(e)]),$a=e=>{let t=0;t|=8,t|=16,t|=32,t|=131072;let n=e.currentChunk.samples[1]??e.currentChunk.samples[0],r={duration:n.timescaleUnitsToNextSample,size:n.size,flags:Za(n)};return ua(`tfhd`,0,t,[U(e.id),U(r.duration),U(r.size),U(r.flags)])},eo=e=>ua(`tfdt`,1,0,[Xi(ra(e.currentChunk.startTimestamp,e.timescale))]),to=e=>{let t=e.currentChunk.samples.map(e=>e.timescaleUnitsToNextSample),n=e.currentChunk.samples.map(e=>e.size),r=e.currentChunk.samples.map(Za),i=e.currentChunk.samples.map(t=>ra(t.presentationTimestamp-t.decodeTimestamp,e.timescale)),a=new Set(t),o=new Set(n),s=new Set(r),c=new Set(i),l=s.size===2&&r[0]!==r[1],u=a.size>1,d=o.size>1,f=!l&&s.size>1,p=c.size>1||[...c].some(e=>e!==0),m=0;return m|=1,m|=4*l,m|=256*u,m|=512*d,m|=1024*f,m|=2048*p,ua(`trun`,1,m,[U(e.currentChunk.samples.length),U(e.currentChunk.offset-e.currentChunk.moofOffset||0),l?U(r[0]):[],e.currentChunk.samples.map((e,a)=>[u?U(t[a]):[],d?U(n[a]):[],f?U(r[a]):[],p?Yi(i[a]):[]])])},no=e=>la(`mfra`,null,[...e.map(ro),io()]),ro=(e,t)=>ua(`tfra`,1,0,[U(e.id),U(63),U(e.finalizedChunks.length),e.finalizedChunks.map(n=>[Xi(ra(n.startTimestamp,e.timescale)),Xi(n.moofOffset),U(t+1),U(1),U(1)])]),io=()=>ua(`mfro`,0,0,[U(0)]),ao={avc:`avc1`,hevc:`hvc1`,vp9:`vp09`,av1:`av01`},oo={avc:Pa,hevc:Fa,vp9:Ia,av1:La},so={aac:`mp4a`,opus:`Opus`},co={aac:za,opus:Ba},lo=class{},uo=class extends lo{constructor(){super(...arguments),this.buffer=null}},fo=class extends lo{constructor(e){if(super(),this.options=e,typeof e!=`object`)throw TypeError(`StreamTarget requires an options object to be passed to its constructor.`);if(e.onData){if(typeof e.onData!=`function`)throw TypeError(`options.onData, when provided, must be a function.`);if(e.onData.length<2)throw TypeError(`options.onData, when provided, must be a function that takes in at least two arguments (data and position). Ignoring the position argument, which specifies the byte offset at which the data is to be written, can lead to broken outputs.`)}if(e.chunked!==void 0&&typeof e.chunked!=`boolean`)throw TypeError(`options.chunked, when provided, must be a boolean.`);if(e.chunkSize!==void 0&&(!Number.isInteger(e.chunkSize)||e.chunkSize<1024))throw TypeError(`options.chunkSize, when provided, must be an integer and not smaller than 1024.`)}},po=class extends lo{constructor(e,t){if(super(),this.stream=e,this.options=t,!(e instanceof FileSystemWritableFileStream))throw TypeError(`FileSystemWritableFileStreamTarget requires a FileSystemWritableFileStream instance.`);if(t!==void 0&&typeof t!=`object`)throw TypeError(`FileSystemWritableFileStreamTarget's options, when provided, must be an object.`);if(t&&t.chunkSize!==void 0&&(!Number.isInteger(t.chunkSize)||t.chunkSize<=0))throw TypeError(`options.chunkSize, when provided, must be a positive integer`)}},go=class{constructor(){this.pos=0,zi(this,mo,new Uint8Array(8)),zi(this,ho,new DataView(H(this,mo).buffer)),this.offsets=new WeakMap}seek(e){this.pos=e}writeU32(e){H(this,ho).setUint32(0,e,!1),this.write(H(this,mo).subarray(0,4))}writeU64(e){H(this,ho).setUint32(0,Math.floor(e/2**32),!1),H(this,ho).setUint32(4,e,!1),this.write(H(this,mo).subarray(0,8))}writeAscii(e){for(let t=0;t<e.length;t++)H(this,ho).setUint8(t%8,e.charCodeAt(t)),t%8==7&&this.write(H(this,mo));e.length%8!=0&&this.write(H(this,mo).subarray(0,e.length%8))}writeBox(e){if(this.offsets.set(e,this.pos),e.contents&&!e.children)this.writeBoxHeader(e,e.size??e.contents.byteLength+8),this.write(e.contents);else{let t=this.pos;if(this.writeBoxHeader(e,0),e.contents&&this.write(e.contents),e.children)for(let t of e.children)t&&this.writeBox(t);let n=this.pos,r=e.size??n-t;this.seek(t),this.writeBoxHeader(e,r),this.seek(n)}}writeBoxHeader(e,t){this.writeU32(e.largeSize?1:t),this.writeAscii(e.type),e.largeSize&&this.writeU64(t)}measureBoxHeader(e){return 8+(e.largeSize?8:0)}patchBox(e){let t=this.pos;this.seek(this.offsets.get(e)),this.writeBox(e),this.seek(t)}measureBox(e){if(e.contents&&!e.children)return this.measureBoxHeader(e)+e.contents.byteLength;{let t=this.measureBoxHeader(e);if(e.contents&&(t+=e.contents.byteLength),e.children)for(let n of e.children)n&&(t+=this.measureBox(n));return t}}},mo=new WeakMap,ho=new WeakMap,Co=class extends go{constructor(e){super(),zi(this,xo),zi(this,_o,void 0),zi(this,vo,new ArrayBuffer(2**16)),zi(this,yo,new Uint8Array(H(this,vo))),zi(this,bo,0),Bi(this,_o,e)}write(e){Hi(this,xo,So).call(this,this.pos+e.byteLength),H(this,yo).set(e,this.pos),this.pos+=e.byteLength,Bi(this,bo,Math.max(H(this,bo),this.pos))}finalize(){Hi(this,xo,So).call(this,this.pos),H(this,_o).buffer=H(this,vo).slice(0,Math.max(H(this,bo),this.pos))}},_o=new WeakMap,vo=new WeakMap,yo=new WeakMap,bo=new WeakMap,xo=new WeakSet,So=function(e){let t=H(this,vo).byteLength;for(;t<e;)t*=2;if(t===H(this,vo).byteLength)return;let n=new ArrayBuffer(t),r=new Uint8Array(n);r.set(H(this,yo),0),Bi(this,vo,n),Bi(this,yo,r)},wo=2**24,To=2,zo=class extends go{constructor(e){super(),zi(this,jo),zi(this,No),zi(this,Fo),zi(this,Lo),zi(this,Eo,void 0),zi(this,Do,[]),zi(this,Oo,void 0),zi(this,ko,void 0),zi(this,Ao,[]),Bi(this,Eo,e),Bi(this,Oo,e.options?.chunked??!1),Bi(this,ko,e.options?.chunkSize??wo)}write(e){H(this,Do).push({data:e.slice(),start:this.pos}),this.pos+=e.byteLength}flush(){if(H(this,Do).length===0)return;let e=[],t=[...H(this,Do)].sort((e,t)=>e.start-t.start);e.push({start:t[0].start,size:t[0].data.byteLength});for(let n=1;n<t.length;n++){let r=e[e.length-1],i=t[n];i.start<=r.start+r.size?r.size=Math.max(r.size,i.start+i.data.byteLength-r.start):e.push({start:i.start,size:i.data.byteLength})}for(let t of e){t.data=new Uint8Array(t.size);for(let e of H(this,Do))t.start<=e.start&&e.start<t.start+t.size&&t.data.set(e.data,e.start-t.start);H(this,Oo)?(Hi(this,jo,Mo).call(this,t.data,t.start),Hi(this,Lo,Ro).call(this)):H(this,Eo).options.onData?.(t.data,t.start)}H(this,Do).length=0}finalize(){H(this,Oo)&&Hi(this,Lo,Ro).call(this,!0)}},Eo=new WeakMap,Do=new WeakMap,Oo=new WeakMap,ko=new WeakMap,Ao=new WeakMap,jo=new WeakSet,Mo=function(e,t){let n=H(this,Ao).findIndex(e=>e.start<=t&&t<e.start+H(this,ko));n===-1&&(n=Hi(this,Fo,Io).call(this,t));let r=H(this,Ao)[n],i=t-r.start,a=e.subarray(0,Math.min(H(this,ko)-i,e.byteLength));r.data.set(a,i);let o={start:i,end:i+a.byteLength};if(Hi(this,No,Po).call(this,r,o),r.written[0].start===0&&r.written[0].end===H(this,ko)&&(r.shouldFlush=!0),H(this,Ao).length>To){for(let e=0;e<H(this,Ao).length-1;e++)H(this,Ao)[e].shouldFlush=!0;Hi(this,Lo,Ro).call(this)}a.byteLength<e.byteLength&&Hi(this,jo,Mo).call(this,e.subarray(a.byteLength),t+a.byteLength)},No=new WeakSet,Po=function(e,t){let n=0,r=e.written.length-1,i=-1;for(;n<=r;){let a=Math.floor(n+(r-n+1)/2);e.written[a].start<=t.start?(n=a+1,i=a):r=a-1}for(e.written.splice(i+1,0,t),(i===-1||e.written[i].end<t.start)&&i++;i<e.written.length-1&&e.written[i].end>=e.written[i+1].start;)e.written[i].end=Math.max(e.written[i].end,e.written[i+1].end),e.written.splice(i+1,1)},Fo=new WeakSet,Io=function(e){let t={start:Math.floor(e/H(this,ko))*H(this,ko),data:new Uint8Array(H(this,ko)),written:[],shouldFlush:!1};return H(this,Ao).push(t),H(this,Ao).sort((e,t)=>e.start-t.start),H(this,Ao).indexOf(t)},Lo=new WeakSet,Ro=function(e=!1){for(let t=0;t<H(this,Ao).length;t++){let n=H(this,Ao)[t];if(n.shouldFlush||e){for(let e of n.written)H(this,Eo).options.onData?.(n.data.subarray(e.start,e.end),n.start+e.start);H(this,Ao).splice(t--,1)}}},Bo=class extends zo{constructor(e){super(new fo({onData:(t,n)=>e.stream.write({type:`write`,data:t,position:n}),chunked:!0,chunkSize:e.options?.chunkSize}))}},Vo=1e3,Ho=[`avc`,`hevc`,`vp9`,`av1`],Uo=[`aac`,`opus`],Wo=2082844800,Go=[`strict`,`offset`,`cross-track-offset`],Os=class{constructor(e){if(zi(this,is),zi(this,os),zi(this,cs),zi(this,us),zi(this,fs),zi(this,ms),zi(this,gs),zi(this,vs),zi(this,bs),zi(this,Ss),zi(this,ws),zi(this,Es),zi(this,Ko,void 0),zi(this,qo,void 0),zi(this,Jo,void 0),zi(this,Yo,void 0),zi(this,Xo,null),zi(this,Zo,null),zi(this,Qo,Math.floor(Date.now()/1e3)+Wo),zi(this,$o,[]),zi(this,es,1),zi(this,ts,[]),zi(this,ns,[]),zi(this,rs,!1),Hi(this,is,as).call(this,e),e.video=sa(e.video),e.audio=sa(e.audio),e.fastStart=sa(e.fastStart),this.target=e.target,Bi(this,Ko,{firstTimestampBehavior:`strict`,...e}),e.target instanceof uo)Bi(this,qo,new Co(e.target));else if(e.target instanceof fo)Bi(this,qo,new zo(e.target));else if(e.target instanceof po)Bi(this,qo,new Bo(e.target));else throw Error(`Invalid target: ${e.target}`);Hi(this,us,ds).call(this),Hi(this,os,ss).call(this)}addVideoChunk(e,t,n,r){if(!(e instanceof EncodedVideoChunk))throw TypeError(`addVideoChunk's first argument (sample) must be of type EncodedVideoChunk.`);if(t&&typeof t!=`object`)throw TypeError(`addVideoChunk's second argument (meta), when provided, must be an object.`);if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`addVideoChunk's third argument (timestamp), when provided, must be a non-negative real number.`);if(r!==void 0&&!Number.isFinite(r))throw TypeError(`addVideoChunk's fourth argument (compositionTimeOffset), when provided, must be a real number.`);let i=new Uint8Array(e.byteLength);e.copyTo(i),this.addVideoChunkRaw(i,e.type,n??e.timestamp,e.duration,t,r)}addVideoChunkRaw(e,t,n,r,i,a){if(!(e instanceof Uint8Array))throw TypeError(`addVideoChunkRaw's first argument (data) must be an instance of Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`addVideoChunkRaw's second argument (type) must be either 'key' or 'delta'.`);if(!Number.isFinite(n)||n<0)throw TypeError(`addVideoChunkRaw's third argument (timestamp) must be a non-negative real number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`addVideoChunkRaw's fourth argument (duration) must be a non-negative real number.`);if(i&&typeof i!=`object`)throw TypeError(`addVideoChunkRaw's fifth argument (meta), when provided, must be an object.`);if(a!==void 0&&!Number.isFinite(a))throw TypeError(`addVideoChunkRaw's sixth argument (compositionTimeOffset), when provided, must be a real number.`);if(Hi(this,Es,Ds).call(this),!H(this,Ko).video)throw Error(`No video track declared.`);if(typeof H(this,Ko).fastStart==`object`&&H(this,Xo).samples.length===H(this,Ko).fastStart.expectedVideoChunks)throw Error(`Cannot add more video chunks than specified in 'fastStart' (${H(this,Ko).fastStart.expectedVideoChunks}).`);let o=Hi(this,ms,hs).call(this,H(this,Xo),e,t,n,r,i,a);if(H(this,Ko).fastStart===`fragmented`&&H(this,Zo)){for(;H(this,ns).length>0&&H(this,ns)[0].decodeTimestamp<=o.decodeTimestamp;){let e=H(this,ns).shift();Hi(this,gs,_s).call(this,H(this,Zo),e)}o.decodeTimestamp<=H(this,Zo).lastDecodeTimestamp?Hi(this,gs,_s).call(this,H(this,Xo),o):H(this,ts).push(o)}else Hi(this,gs,_s).call(this,H(this,Xo),o)}addAudioChunk(e,t,n){if(!(e instanceof EncodedAudioChunk))throw TypeError(`addAudioChunk's first argument (sample) must be of type EncodedAudioChunk.`);if(t&&typeof t!=`object`)throw TypeError(`addAudioChunk's second argument (meta), when provided, must be an object.`);if(n!==void 0&&(!Number.isFinite(n)||n<0))throw TypeError(`addAudioChunk's third argument (timestamp), when provided, must be a non-negative real number.`);let r=new Uint8Array(e.byteLength);e.copyTo(r),this.addAudioChunkRaw(r,e.type,n??e.timestamp,e.duration,t)}addAudioChunkRaw(e,t,n,r,i){if(!(e instanceof Uint8Array))throw TypeError(`addAudioChunkRaw's first argument (data) must be an instance of Uint8Array.`);if(t!==`key`&&t!==`delta`)throw TypeError(`addAudioChunkRaw's second argument (type) must be either 'key' or 'delta'.`);if(!Number.isFinite(n)||n<0)throw TypeError(`addAudioChunkRaw's third argument (timestamp) must be a non-negative real number.`);if(!Number.isFinite(r)||r<0)throw TypeError(`addAudioChunkRaw's fourth argument (duration) must be a non-negative real number.`);if(i&&typeof i!=`object`)throw TypeError(`addAudioChunkRaw's fifth argument (meta), when provided, must be an object.`);if(Hi(this,Es,Ds).call(this),!H(this,Ko).audio)throw Error(`No audio track declared.`);if(typeof H(this,Ko).fastStart==`object`&&H(this,Zo).samples.length===H(this,Ko).fastStart.expectedAudioChunks)throw Error(`Cannot add more audio chunks than specified in 'fastStart' (${H(this,Ko).fastStart.expectedAudioChunks}).`);let a=Hi(this,ms,hs).call(this,H(this,Zo),e,t,n,r,i);if(H(this,Ko).fastStart===`fragmented`&&H(this,Xo)){for(;H(this,ts).length>0&&H(this,ts)[0].decodeTimestamp<=a.decodeTimestamp;){let e=H(this,ts).shift();Hi(this,gs,_s).call(this,H(this,Xo),e)}a.decodeTimestamp<=H(this,Xo).lastDecodeTimestamp?Hi(this,gs,_s).call(this,H(this,Zo),a):H(this,ns).push(a)}else Hi(this,gs,_s).call(this,H(this,Zo),a)}finalize(){if(H(this,rs))throw Error(`Cannot finalize a muxer more than once.`);if(H(this,Ko).fastStart===`fragmented`){for(let e of H(this,ts))Hi(this,gs,_s).call(this,H(this,Xo),e);for(let e of H(this,ns))Hi(this,gs,_s).call(this,H(this,Zo),e);Hi(this,Ss,Cs).call(this,!1)}else H(this,Xo)&&Hi(this,bs,xs).call(this,H(this,Xo)),H(this,Zo)&&Hi(this,bs,xs).call(this,H(this,Zo));let e=[H(this,Xo),H(this,Zo)].filter(Boolean);if(H(this,Ko).fastStart===`in-memory`){let t;for(let n=0;n<2;n++){let n=ma(e,H(this,Qo)),r=H(this,qo).measureBox(n);t=H(this,qo).measureBox(H(this,Yo));let i=H(this,qo).pos+r+t;for(let e of H(this,$o)){e.offset=i;for(let{data:n}of e.samples)i+=n.byteLength,t+=n.byteLength}if(i<2**32)break;t>=2**32&&(H(this,Yo).largeSize=!0)}let n=ma(e,H(this,Qo));H(this,qo).writeBox(n),H(this,Yo).size=t,H(this,qo).writeBox(H(this,Yo));for(let e of H(this,$o))for(let t of e.samples)H(this,qo).write(t.data),t.data=null}else if(H(this,Ko).fastStart===`fragmented`){let t=H(this,qo).pos,n=no(e);H(this,qo).writeBox(n);let r=H(this,qo).pos-t;H(this,qo).seek(H(this,qo).pos-4),H(this,qo).writeU32(r)}else{let t=H(this,qo).offsets.get(H(this,Yo)),n=H(this,qo).pos-t;H(this,Yo).size=n,H(this,Yo).largeSize=n>=2**32,H(this,qo).patchBox(H(this,Yo));let r=ma(e,H(this,Qo));if(typeof H(this,Ko).fastStart==`object`){H(this,qo).seek(H(this,Jo)),H(this,qo).writeBox(r);let e=t-H(this,qo).pos;H(this,qo).writeBox(pa(e))}else H(this,qo).writeBox(r)}Hi(this,ws,Ts).call(this),H(this,qo).finalize(),Bi(this,rs,!0)}},Ko=new WeakMap,qo=new WeakMap,Jo=new WeakMap,Yo=new WeakMap,Xo=new WeakMap,Zo=new WeakMap,Qo=new WeakMap,$o=new WeakMap,es=new WeakMap,ts=new WeakMap,ns=new WeakMap,rs=new WeakMap,is=new WeakSet,as=function(e){if(typeof e!=`object`)throw TypeError(`The muxer requires an options object to be passed to its constructor.`);if(!(e.target instanceof lo))throw TypeError(`The target must be provided and an instance of Target.`);if(e.video){if(!Ho.includes(e.video.codec))throw TypeError(`Unsupported video codec: ${e.video.codec}`);if(!Number.isInteger(e.video.width)||e.video.width<=0)throw TypeError(`Invalid video width: ${e.video.width}. Must be a positive integer.`);if(!Number.isInteger(e.video.height)||e.video.height<=0)throw TypeError(`Invalid video height: ${e.video.height}. Must be a positive integer.`);let t=e.video.rotation;if(typeof t==`number`&&![0,90,180,270].includes(t))throw TypeError(`Invalid video rotation: ${t}. Has to be 0, 90, 180 or 270.`);if(Array.isArray(t)&&(t.length!==9||t.some(e=>typeof e!=`number`)))throw TypeError(`Invalid video transformation matrix: ${t.join()}`);if(e.video.frameRate!==void 0&&(!Number.isInteger(e.video.frameRate)||e.video.frameRate<=0))throw TypeError(`Invalid video frame rate: ${e.video.frameRate}. Must be a positive integer.`)}if(e.audio){if(!Uo.includes(e.audio.codec))throw TypeError(`Unsupported audio codec: ${e.audio.codec}`);if(!Number.isInteger(e.audio.numberOfChannels)||e.audio.numberOfChannels<=0)throw TypeError(`Invalid number of audio channels: ${e.audio.numberOfChannels}. Must be a positive integer.`);if(!Number.isInteger(e.audio.sampleRate)||e.audio.sampleRate<=0)throw TypeError(`Invalid audio sample rate: ${e.audio.sampleRate}. Must be a positive integer.`)}if(e.firstTimestampBehavior&&!Go.includes(e.firstTimestampBehavior))throw TypeError(`Invalid first timestamp behavior: ${e.firstTimestampBehavior}`);if(typeof e.fastStart==`object`){if(e.video){if(e.fastStart.expectedVideoChunks===void 0)throw TypeError(`'fastStart' is an object but is missing property 'expectedVideoChunks'.`);if(!Number.isInteger(e.fastStart.expectedVideoChunks)||e.fastStart.expectedVideoChunks<0)throw TypeError(`'expectedVideoChunks' must be a non-negative integer.`)}if(e.audio){if(e.fastStart.expectedAudioChunks===void 0)throw TypeError(`'fastStart' is an object but is missing property 'expectedAudioChunks'.`);if(!Number.isInteger(e.fastStart.expectedAudioChunks)||e.fastStart.expectedAudioChunks<0)throw TypeError(`'expectedAudioChunks' must be a non-negative integer.`)}}else if(![!1,`in-memory`,`fragmented`].includes(e.fastStart))throw TypeError(`'fastStart' option must be false, 'in-memory', 'fragmented' or an object.`);if(e.minFragmentDuration!==void 0&&(!Number.isFinite(e.minFragmentDuration)||e.minFragmentDuration<0))throw TypeError(`'minFragmentDuration' must be a non-negative number.`)},os=new WeakSet,ss=function(){if(H(this,qo).writeBox(da({holdsAvc:H(this,Ko).video?.codec===`avc`,fragmented:H(this,Ko).fastStart===`fragmented`})),Bi(this,Jo,H(this,qo).pos),H(this,Ko).fastStart===`in-memory`)Bi(this,Yo,fa(!1));else if(H(this,Ko).fastStart!==`fragmented`){if(typeof H(this,Ko).fastStart==`object`){let e=Hi(this,cs,ls).call(this);H(this,qo).seek(H(this,qo).pos+e)}Bi(this,Yo,fa(!0)),H(this,qo).writeBox(H(this,Yo))}Hi(this,ws,Ts).call(this)},cs=new WeakSet,ls=function(){if(typeof H(this,Ko).fastStart!=`object`)return;let e=0,t=[H(this,Ko).fastStart.expectedVideoChunks,H(this,Ko).fastStart.expectedAudioChunks];for(let n of t)n&&(e+=8*Math.ceil(2/3*n),e+=4*n,e+=12*Math.ceil(2/3*n),e+=4*n,e+=8*n);return e+=4096,e},us=new WeakSet,ds=function(){if(H(this,Ko).video&&Bi(this,Xo,{id:1,info:{type:`video`,codec:H(this,Ko).video.codec,width:H(this,Ko).video.width,height:H(this,Ko).video.height,rotation:H(this,Ko).video.rotation??0,decoderConfig:null},timescale:H(this,Ko).video.frameRate??57600,samples:[],finalizedChunks:[],currentChunk:null,firstDecodeTimestamp:void 0,lastDecodeTimestamp:-1,timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,compactlyCodedChunkTable:[]}),H(this,Ko).audio&&(Bi(this,Zo,{id:H(this,Ko).video?2:1,info:{type:`audio`,codec:H(this,Ko).audio.codec,numberOfChannels:H(this,Ko).audio.numberOfChannels,sampleRate:H(this,Ko).audio.sampleRate,decoderConfig:null},timescale:H(this,Ko).audio.sampleRate,samples:[],finalizedChunks:[],currentChunk:null,firstDecodeTimestamp:void 0,lastDecodeTimestamp:-1,timeToSampleTable:[],compositionTimeOffsetTable:[],lastTimescaleUnits:null,lastSample:null,compactlyCodedChunkTable:[]}),H(this,Ko).audio.codec===`aac`)){let e=Hi(this,fs,ps).call(this,2,H(this,Ko).audio.sampleRate,H(this,Ko).audio.numberOfChannels);H(this,Zo).info.decoderConfig={codec:H(this,Ko).audio.codec,description:e,numberOfChannels:H(this,Ko).audio.numberOfChannels,sampleRate:H(this,Ko).audio.sampleRate}}},fs=new WeakSet,ps=function(e,t,n){let r=[96e3,88200,64e3,48e3,44100,32e3,24e3,22050,16e3,12e3,11025,8e3,7350].indexOf(t),i=n,a=``;a+=e.toString(2).padStart(5,`0`),a+=r.toString(2).padStart(4,`0`),r===15&&(a+=t.toString(2).padStart(24,`0`)),a+=i.toString(2).padStart(4,`0`);let o=Math.ceil(a.length/8)*8;a=a.padEnd(o,`0`);let s=new Uint8Array(a.length/8);for(let e=0;e<a.length;e+=8)s[e/8]=parseInt(a.slice(e,e+8),2);return s},ms=new WeakSet,hs=function(e,t,n,r,i,a,o){let s=r/1e6,c=(r-(o??0))/1e6,l=i/1e6,u=Hi(this,vs,ys).call(this,s,c,e);return s=u.presentationTimestamp,c=u.decodeTimestamp,a?.decoderConfig&&(e.info.decoderConfig===null?e.info.decoderConfig=a.decoderConfig:Object.assign(e.info.decoderConfig,a.decoderConfig)),{presentationTimestamp:s,decodeTimestamp:c,duration:l,data:t,size:t.byteLength,type:n,timescaleUnitsToNextSample:ra(l,e.timescale)}},gs=new WeakSet,_s=function(e,t){H(this,Ko).fastStart!==`fragmented`&&e.samples.push(t);let n=ra(t.presentationTimestamp-t.decodeTimestamp,e.timescale);if(e.lastTimescaleUnits!==null){let r=ra(t.decodeTimestamp,e.timescale,!1),i=Math.round(r-e.lastTimescaleUnits);if(e.lastTimescaleUnits+=i,e.lastSample.timescaleUnitsToNextSample=i,H(this,Ko).fastStart!==`fragmented`){let t=ta(e.timeToSampleTable);t.sampleCount===1?(t.sampleDelta=i,t.sampleCount++):t.sampleDelta===i?t.sampleCount++:(t.sampleCount--,e.timeToSampleTable.push({sampleCount:2,sampleDelta:i}));let r=ta(e.compositionTimeOffsetTable);r.sampleCompositionTimeOffset===n?r.sampleCount++:e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:n})}}else e.lastTimescaleUnits=0,H(this,Ko).fastStart!==`fragmented`&&(e.timeToSampleTable.push({sampleCount:1,sampleDelta:ra(t.duration,e.timescale)}),e.compositionTimeOffsetTable.push({sampleCount:1,sampleCompositionTimeOffset:n}));e.lastSample=t;let r=!1;if(!e.currentChunk)r=!0;else{let n=t.presentationTimestamp-e.currentChunk.startTimestamp;if(H(this,Ko).fastStart===`fragmented`){let i=H(this,Xo)??H(this,Zo),a=H(this,Ko).minFragmentDuration??1;e===i&&t.type===`key`&&n>=a&&(r=!0,Hi(this,Ss,Cs).call(this))}else r=n>=.5}r&&(e.currentChunk&&Hi(this,bs,xs).call(this,e),e.currentChunk={startTimestamp:t.presentationTimestamp,samples:[]}),e.currentChunk.samples.push(t)},vs=new WeakSet,ys=function(e,t,n){let r=H(this,Ko).firstTimestampBehavior===`strict`,i=n.lastDecodeTimestamp===-1;if(r&&i&&t!==0)throw Error(`The first chunk for your media track must have a timestamp of 0 (received DTS=${t}).Non-zero first timestamps are often caused by directly piping frames or audio data from a MediaStreamTrack into the encoder. Their timestamps are typically relative to the age of thedocument, which is probably what you want.
1088
1088
 
1089
1089
  If you want to offset all timestamps of a track such that the first one is zero, set firstTimestampBehavior: 'offset' in the options.
1090
1090
  `);if(H(this,Ko).firstTimestampBehavior===`offset`||H(this,Ko).firstTimestampBehavior===`cross-track-offset`){n.firstDecodeTimestamp===void 0&&(n.firstDecodeTimestamp=t);let r;r=H(this,Ko).firstTimestampBehavior===`offset`?n.firstDecodeTimestamp:Math.min(H(this,Xo)?.firstDecodeTimestamp??1/0,H(this,Zo)?.firstDecodeTimestamp??1/0),t-=r,e-=r}if(t<n.lastDecodeTimestamp)throw Error(`Timestamps must be monotonically increasing (DTS went from ${n.lastDecodeTimestamp*1e6} to ${t*1e6}).`);return n.lastDecodeTimestamp=t,{presentationTimestamp:e,decodeTimestamp:t}},bs=new WeakSet,xs=function(e){if(H(this,Ko).fastStart===`fragmented`)throw Error(`Can't finalize individual chunks if 'fastStart' is set to 'fragmented'.`);if(e.currentChunk){if(e.finalizedChunks.push(e.currentChunk),H(this,$o).push(e.currentChunk),(e.compactlyCodedChunkTable.length===0||ta(e.compactlyCodedChunkTable).samplesPerChunk!==e.currentChunk.samples.length)&&e.compactlyCodedChunkTable.push({firstChunk:e.finalizedChunks.length,samplesPerChunk:e.currentChunk.samples.length}),H(this,Ko).fastStart===`in-memory`){e.currentChunk.offset=0;return}e.currentChunk.offset=H(this,qo).pos;for(let t of e.currentChunk.samples)H(this,qo).write(t.data),t.data=null;Hi(this,ws,Ts).call(this)}},Ss=new WeakSet,Cs=function(e=!0){if(H(this,Ko).fastStart!==`fragmented`)throw Error(`Can't finalize a fragment unless 'fastStart' is set to 'fragmented'.`);let t=[H(this,Xo),H(this,Zo)].filter(e=>e&&e.currentChunk);if(t.length===0)return;let n=Vi(this,es)._++;if(n===1){let e=ma(t,H(this,Qo),!0);H(this,qo).writeBox(e)}let r=H(this,qo).pos,i=Ya(n,t);H(this,qo).writeBox(i);{let e=fa(!1),n=0;for(let e of t)for(let t of e.currentChunk.samples)n+=t.size;let r=H(this,qo).measureBox(e)+n;r>=2**32&&(e.largeSize=!0,r=H(this,qo).measureBox(e)+n),e.size=r,H(this,qo).writeBox(e)}for(let e of t){e.currentChunk.offset=H(this,qo).pos,e.currentChunk.moofOffset=r;for(let t of e.currentChunk.samples)H(this,qo).write(t.data),t.data=null}let a=H(this,qo).pos;H(this,qo).seek(H(this,qo).offsets.get(i));let o=Ya(n,t);H(this,qo).writeBox(o),H(this,qo).seek(a);for(let e of t)e.finalizedChunks.push(e.currentChunk),H(this,$o).push(e.currentChunk),e.currentChunk=null;e&&Hi(this,ws,Ts).call(this)},ws=new WeakSet,Ts=function(){H(this,qo)instanceof zo&&H(this,qo).flush()},Es=new WeakSet,Ds=function(){if(H(this,rs))throw Error(`Cannot add new video or audio chunks after the file has been finalized.`)}}));function As({width:e,height:t,fps:n,audio:r=null,expected:i=null}){let a=new uo,o=new Os({target:a,fastStart:i?{expectedVideoChunks:i.video,...r?{expectedAudioChunks:i.audio}:{}}:`in-memory`,video:{codec:`avc`,width:e,height:t,frameRate:n},...r?{audio:{codec:r.codec||`aac`,numberOfChannels:r.channels,sampleRate:r.sampleRate}}:{}});return{addVideoChunk:(e,t)=>o.addVideoChunk(e,t),addAudioChunk:(e,t)=>o.addAudioChunk(e,t),finalize(){return o.finalize(),new Blob([a.buffer],{type:`video/mp4`})}}}var js=o((()=>{ks()}));function Ms({codec:e,width:t,height:n,fps:r,bitrate:i,onChunk:a,hardwareAcceleration:o=`prefer-hardware`}){let s=null,c=new VideoEncoder({output:(e,t)=>a(e,t),error:e=>{s=e}});c.configure({codec:e,width:t,height:n,framerate:r,bitrate:i,latencyMode:`realtime`,hardwareAcceleration:o});let l=Math.round(1e6/r);return{async encodeFrame(e,t,n=!1){if(s)throw s;for(;c.encodeQueueSize>8;)await new Promise(e=>setTimeout(e,2));let r=new VideoFrame(e,{timestamp:t,duration:l});c.encode(r,{keyFrame:n}),r.close()},async finish(){if(await c.flush(),c.close(),s)throw s},close(){try{c.state!==`closed`&&c.close()}catch{}}}}var Ns=o((()=>{})),Ps=c({Mp3Encoder:()=>bd,WavHeader:()=>xd,default:()=>jc});function Fs(e){return new Int8Array(e)}function Is(e){return new Int16Array(e)}function Ls(e){return new Int32Array(e)}function Rs(e){return new Float32Array(e)}function zs(e){return new Float64Array(e)}function Bs(e){if(e.length==1)return Rs(e[0]);var t=e[0];e=e.slice(1);for(var n=[],r=0;r<t;r++)n.push(Bs(e));return n}function Vs(e){if(e.length==1)return Ls(e[0]);var t=e[0];e=e.slice(1);for(var n=[],r=0;r<t;r++)n.push(Vs(e));return n}function Hs(e){if(e.length==1)return Is(e[0]);var t=e[0];e=e.slice(1);for(var n=[],r=0;r<t;r++)n.push(Hs(e));return n}function Us(e){if(e.length==1)return Array(e[0]);var t=e[0];e=e.slice(1);for(var n=[],r=0;r<t;r++)n.push(Us(e));return n}function Ws(e){this.ordinal=e}function Gs(e){this.ordinal=e}function Ks(){if(zc)return Rc;zc=1;var e=Lc,t=e.System,n=e.Util,r=e.Arrays,i=e.new_float,a=Xs();function o(){var e=[-.1482523854003001,32.308141959636465,296.40344946382766,883.1344870032432,11113.947376231741,1057.2713659324597,305.7402417275812,30.825928907280012,3.8533188138216365,59.42900443849514,709.5899960123345,5281.91112291017,-5829.66483675846,-817.6293103748613,-76.91656988279972,-4.594269939176596,.9063471690191471,.1960342806591213,-.15466694054279598,34.324387823855965,301.8067566458425,817.599602898885,11573.795901679885,1181.2520595540152,321.59731579894424,31.232021761053772,3.7107095756221318,53.650946155329365,684.167428119626,5224.56624370173,-6366.391851890084,-908.9766368219582,-89.83068876699639,-5.411397422890401,.8206787908286602,.3901806440322567,-.16070888947830023,36.147034243915876,304.11815768187864,732.7429163887613,11989.60988270091,1300.012278487897,335.28490093152146,31.48816102859945,3.373875931311736,47.232241542899175,652.7371796173471,5132.414255594984,-6909.087078780055,-1001.9990371107289,-103.62185754286375,-6.104916304710272,.7416505462720353,.5805693545089249,-.16636367662261495,37.751650073343995,303.01103387567713,627.9747488785183,12358.763425278165,1412.2779918482834,346.7496836825721,31.598286663170416,3.1598635433980946,40.57878626349686,616.1671130880391,5007.833007176154,-7454.040671756168,-1095.7960341867115,-118.24411666465777,-6.818469345853504,.6681786379192989,.7653668647301797,-.1716176790982088,39.11551877123304,298.3413246578966,503.5259106886539,12679.589408408976,1516.5821921214542,355.9850766329023,31.395241710249053,2.9164211881972335,33.79716964664243,574.8943997801362,4853.234992253242,-7997.57021486075,-1189.7624067269965,-133.6444792601766,-7.7202770609839915,.5993769336819237,.9427934736519954,-.17645823955292173,40.21879108166477,289.9982036694474,359.3226160751053,12950.259102786438,1612.1013903507662,362.85067106591504,31.045922092242872,2.822222032597987,26.988862316190684,529.8996541764288,4671.371946949588,-8535.899136645805,-1282.5898586244496,-149.58553632943463,-8.643494270763135,.5345111359507916,1.111140466039205,-.36174739330527045,41.04429910497807,277.5463268268618,195.6386023135583,13169.43812144731,1697.6433561479398,367.40983966190305,30.557037410382826,2.531473372857427,20.070154905927314,481.50208566532336,4464.970341588308,-9065.36882077239,-1373.62841526722,-166.1660487028118,-9.58289321133207,.4729647758913199,1.268786568327291,-.36970682634889585,41.393213350082036,261.2935935556502,12.935476055240873,13336.131683328815,1772.508612059496,369.76534388639965,29.751323653701338,2.4023193045459172,13.304795348228817,430.5615775526625,4237.0568611071185,-9581.931701634761,-1461.6913552409758,-183.12733958476446,-10.718010163869403,.41421356237309503,1.414213562373095,-.37677560326535325,41.619486213528496,241.05423794991074,-187.94665032361226,13450.063605744153,1836.153896465782,369.4908799925761,29.001847876923147,2.0714759319987186,6.779591200894186,377.7767837205709,3990.386575512536,-10081.709459700915,-1545.947424837898,-200.3762958015653,-11.864482073055006,.3578057213145241,1.546020906725474,-.3829366947518991,41.1516456456653,216.47684307105183,-406.1569483347166,13511.136535077321,1887.8076599260432,367.3025214564151,28.136213436723654,1.913880671464418,.3829366947518991,323.85365704338597,3728.1472257487526,-10561.233882199509,-1625.2025997821418,-217.62525175416,-13.015432208941645,.3033466836073424,1.66293922460509,-.5822628872992417,40.35639251440489,188.20071124269245,-640.2706748618148,13519.21490106562,1927.6022433578062,362.8197642637487,26.968821921868447,1.7463817695935329,-5.62650678237171,269.3016715297017,3453.386536448852,-11016.145278780888,-1698.6569643425091,-234.7658734267683,-14.16351421663124,.2504869601913055,1.76384252869671,-.5887180101749253,39.23429103868072,155.76096234403798,-889.2492977967378,13475.470561874661,1955.0535223723712,356.4450994756727,25.894952980042156,1.5695032905781554,-11.181939564328772,214.80884394039484,3169.1640829158237,-11443.321309975563,-1765.1588461316153,-251.68908574481912,-15.49755935939164,.198912367379658,1.847759065022573,-.7912582233652842,37.39369355329111,119.699486012458,-1151.0956593239027,13380.446257078214,1970.3952110853447,348.01959814116185,24.731487364283044,1.3850130831637748,-16.421408865300393,161.05030052864092,2878.3322807850063,-11838.991423510031,-1823.985884688674,-268.2854986386903,-16.81724543849939,.1483359875383474,1.913880671464418,-.7960642926861912,35.2322109610459,80.01928065061526,-1424.0212633405113,13235.794061869668,1973.804052543835,337.9908651258184,23.289159354463873,1.3934255946442087,-21.099669467133474,108.48348407242611,2583.700758091299,-12199.726194855148,-1874.2780658979746,-284.2467154529415,-18.11369784385905,.09849140335716425,1.961570560806461,-.998795456205172,32.56307803611191,36.958364584370486,-1706.075448829146,13043.287458812016,1965.3831106103316,326.43182772364605,22.175018750622293,1.198638339011324,-25.371248002043963,57.53505923036915,2288.41886619975,-12522.674544337233,-1914.8400385312243,-299.26241273417224,-19.37805630698734,.04912684976946725,1.990369453344394,.035780907*n.SQRT2*.5/2384e-9,.017876148*n.SQRT2*.5/2384e-9,.003134727*n.SQRT2*.5/2384e-9,.002457142*n.SQRT2*.5/2384e-9,971317e-9*n.SQRT2*.5/2384e-9,218868e-9*n.SQRT2*.5/2384e-9,101566e-9*n.SQRT2*.5/2384e-9,13828e-9*n.SQRT2*.5/2384e-9,12804.797818791945,1945.5515939597317,313.4244966442953,20.801593959731544,1995.1556208053692,9.000838926174497,-29.20218120805369],o=12,s=36,c=[[2382191739347913e-28,6423305872147834e-28,9400849094049688e-28,1122435026096556e-27,1183840321267481e-27,1122435026096556e-27,940084909404969e-27,6423305872147839e-28,2382191739347918e-28,5456116108943412e-27,4878985199565852e-27,4240448995017367e-27,3559909094758252e-27,2858043359288075e-27,2156177623817898e-27,1475637723558783e-27,8371015190102974e-28,2599706096327376e-28,-5456116108943412e-27,-4878985199565852e-27,-4240448995017367e-27,-3559909094758252e-27,-2858043359288076e-27,-2156177623817898e-27,-1475637723558783e-27,-8371015190102975e-28,-2599706096327376e-28,-2382191739347923e-28,-6423305872147843e-28,-9400849094049696e-28,-1122435026096556e-27,-1183840321267481e-27,-1122435026096556e-27,-9400849094049694e-28,-642330587214784e-27,-2382191739347918e-28],[2382191739347913e-28,6423305872147834e-28,9400849094049688e-28,1122435026096556e-27,1183840321267481e-27,1122435026096556e-27,9400849094049688e-28,6423305872147841e-28,2382191739347918e-28,5456116108943413e-27,4878985199565852e-27,4240448995017367e-27,3559909094758253e-27,2858043359288075e-27,2156177623817898e-27,1475637723558782e-27,8371015190102975e-28,2599706096327376e-28,-5461314069809755e-27,-4921085770524055e-27,-4343405037091838e-27,-3732668368707687e-27,-3093523840190885e-27,-2430835727329465e-27,-1734679010007751e-27,-974825365660928e-27,-2797435120168326e-28,0,0,0,0,0,0,-2283748241799531e-28,-4037858874020686e-28,-2146547464825323e-28],[.1316524975873958,.414213562373095,.7673269879789602,1.091308501069271,1.303225372841206,1.56968557711749,1.920982126971166,2.414213562373094,3.171594802363212,4.510708503662055,7.595754112725146,22.90376554843115,.984807753012208,.6427876096865394,.3420201433256688,.9396926207859084,-.1736481776669303,-.7660444431189779,.8660254037844387,.5,-.5144957554275265,-.4717319685649723,-.3133774542039019,-.1819131996109812,-.09457419252642064,-.04096558288530405,-.01419856857247115,-.003699974673760037,.8574929257125442,.8817419973177052,.9496286491027329,.9833145924917901,.9955178160675857,.9991605581781475,.999899195244447,.9999931550702802],[0,0,0,0,0,0,2283748241799531e-28,4037858874020686e-28,2146547464825323e-28,5461314069809755e-27,4921085770524055e-27,4343405037091838e-27,3732668368707687e-27,3093523840190885e-27,2430835727329466e-27,1734679010007751e-27,974825365660928e-27,2797435120168326e-28,-5456116108943413e-27,-4878985199565852e-27,-4240448995017367e-27,-3559909094758253e-27,-2858043359288075e-27,-2156177623817898e-27,-1475637723558782e-27,-8371015190102975e-28,-2599706096327376e-28,-2382191739347913e-28,-6423305872147834e-28,-9400849094049688e-28,-1122435026096556e-27,-1183840321267481e-27,-1122435026096556e-27,-9400849094049688e-28,-6423305872147841e-28,-2382191739347918e-28]],l=c[a.SHORT_TYPE],u=c[a.SHORT_TYPE],d=c[a.SHORT_TYPE],f=c[a.SHORT_TYPE],p=[0,1,16,17,8,9,24,25,4,5,20,21,12,13,28,29,2,3,18,19,10,11,26,27,6,7,22,23,14,15,30,31];function m(t,r,i){for(var a=10,o=r+238-14-286,s=-15;s<0;s++){var c=e[a+-10],l=t[o+-224]*c,u=t[r+224]*c;c=e[a+-9],l+=t[o+-160]*c,u+=t[r+160]*c,c=e[a+-8],l+=t[o+-96]*c,u+=t[r+96]*c,c=e[a+-7],l+=t[o+-32]*c,u+=t[r+32]*c,c=e[a+-6],l+=t[o+32]*c,u+=t[r+-32]*c,c=e[a+-5],l+=t[o+96]*c,u+=t[r+-96]*c,c=e[a+-4],l+=t[o+160]*c,u+=t[r+-160]*c,c=e[a+-3],l+=t[o+224]*c,u+=t[r+-224]*c,c=e[a+-2],l+=t[r+-256]*c,u-=t[o+256]*c,c=e[a+-1],l+=t[r+-192]*c,u-=t[o+192]*c,c=e[a+0],l+=t[r+-128]*c,u-=t[o+128]*c,c=e[a+1],l+=t[r+-64]*c,u-=t[o+64]*c,c=e[a+2],l+=t[r+0]*c,u-=t[o+0]*c,c=e[a+3],l+=t[r+64]*c,u-=t[o+-64]*c,c=e[a+4],l+=t[r+128]*c,u-=t[o+-128]*c,c=e[a+5],l+=t[r+192]*c,u-=t[o+-192]*c,l*=e[a+6],c=u-l,i[30+s*2]=u+l,i[31+s*2]=e[a+7]*c,a+=18,r--,o++}var l,u=t[r+-16]*e[a+-10],d,f;l=t[r+-32]*e[a+-2],u+=(t[r+-48]-t[r+16])*e[a+-9],l+=t[r+-96]*e[a+-1],u+=(t[r+-80]+t[r+48])*e[a+-8],l+=t[r+-160]*e[a+0],u+=(t[r+-112]-t[r+80])*e[a+-7],l+=t[r+-224]*e[a+1],u+=(t[r+-144]+t[r+112])*e[a+-6],l-=t[r+32]*e[a+2],u+=(t[r+-176]-t[r+144])*e[a+-5],l-=t[r+96]*e[a+3],u+=(t[r+-208]+t[r+176])*e[a+-4],l-=t[r+160]*e[a+4],u+=(t[r+-240]-t[r+208])*e[a+-3],l-=t[r+224],d=l-u,f=l+u,u=i[14],l=i[15]-u,i[31]=f+u,i[30]=d+l,i[15]=d-l,i[14]=f-u;var p=i[28]-i[0];i[0]+=i[28],i[28]=p*e[a+-36+7],p=i[29]-i[1],i[1]+=i[29],i[29]=p*e[a+-36+7],p=i[26]-i[2],i[2]+=i[26],i[26]=p*e[a+-72+7],p=i[27]-i[3],i[3]+=i[27],i[27]=p*e[a+-72+7],p=i[24]-i[4],i[4]+=i[24],i[24]=p*e[a+-108+7],p=i[25]-i[5],i[5]+=i[25],i[25]=p*e[a+-108+7],p=i[22]-i[6],i[6]+=i[22],i[22]=p*n.SQRT2,p=i[23]-i[7],i[7]+=i[23],i[23]=p*n.SQRT2-i[7],i[7]-=i[6],i[22]-=i[7],i[23]-=i[22],p=i[6],i[6]=i[31]-p,i[31]+=p,p=i[7],i[7]=i[30]-p,i[30]+=p,p=i[22],i[22]=i[15]-p,i[15]+=p,p=i[23],i[23]=i[14]-p,i[14]+=p,p=i[20]-i[8],i[8]+=i[20],i[20]=p*e[a+-180+7],p=i[21]-i[9],i[9]+=i[21],i[21]=p*e[a+-180+7],p=i[18]-i[10],i[10]+=i[18],i[18]=p*e[a+-216+7],p=i[19]-i[11],i[11]+=i[19],i[19]=p*e[a+-216+7],p=i[16]-i[12],i[12]+=i[16],i[16]=p*e[a+-252+7],p=i[17]-i[13],i[13]+=i[17],i[17]=p*e[a+-252+7],p=-i[20]+i[24],i[20]+=i[24],i[24]=p*e[a+-216+7],p=-i[21]+i[25],i[21]+=i[25],i[25]=p*e[a+-216+7],p=i[4]-i[8],i[4]+=i[8],i[8]=p*e[a+-216+7],p=i[5]-i[9],i[5]+=i[9],i[9]=p*e[a+-216+7],p=i[0]-i[12],i[0]+=i[12],i[12]=p*e[a+-72+7],p=i[1]-i[13],i[1]+=i[13],i[13]=p*e[a+-72+7],p=i[16]-i[28],i[16]+=i[28],i[28]=p*e[a+-72+7],p=-i[17]+i[29],i[17]+=i[29],i[29]=p*e[a+-72+7],p=n.SQRT2*(i[2]-i[10]),i[2]+=i[10],i[10]=p,p=n.SQRT2*(i[3]-i[11]),i[3]+=i[11],i[11]=p,p=n.SQRT2*(-i[18]+i[26]),i[18]+=i[26],i[26]=p-i[18],p=n.SQRT2*(-i[19]+i[27]),i[19]+=i[27],i[27]=p-i[19],p=i[2],i[19]-=i[3],i[3]-=p,i[2]=i[31]-p,i[31]+=p,p=i[3],i[11]-=i[19],i[18]-=p,i[3]=i[30]-p,i[30]+=p,p=i[18],i[27]-=i[11],i[19]-=p,i[18]=i[15]-p,i[15]+=p,p=i[19],i[10]-=p,i[19]=i[14]-p,i[14]+=p,p=i[10],i[11]-=p,i[10]=i[23]-p,i[23]+=p,p=i[11],i[26]-=p,i[11]=i[22]-p,i[22]+=p,p=i[26],i[27]-=p,i[26]=i[7]-p,i[7]+=p,p=i[27],i[27]=i[6]-p,i[6]+=p,p=n.SQRT2*(i[0]-i[4]),i[0]+=i[4],i[4]=p,p=n.SQRT2*(i[1]-i[5]),i[1]+=i[5],i[5]=p,p=n.SQRT2*(i[16]-i[20]),i[16]+=i[20],i[20]=p,p=n.SQRT2*(i[17]-i[21]),i[17]+=i[21],i[21]=p,p=-n.SQRT2*(i[8]-i[12]),i[8]+=i[12],i[12]=p-i[8],p=-n.SQRT2*(i[9]-i[13]),i[9]+=i[13],i[13]=p-i[9],p=-n.SQRT2*(i[25]-i[29]),i[25]+=i[29],i[29]=p-i[25],p=-n.SQRT2*(i[24]+i[28]),i[24]-=i[28],i[28]=p-i[24],p=i[24]-i[16],i[24]=p,p=i[20]-p,i[20]=p,p=i[28]-p,i[28]=p,p=i[25]-i[17],i[25]=p,p=i[21]-p,i[21]=p,p=i[29]-p,i[29]=p,p=i[17]-i[1],i[17]=p,p=i[9]-p,i[9]=p,p=i[25]-p,i[25]=p,p=i[5]-p,i[5]=p,p=i[21]-p,i[21]=p,p=i[13]-p,i[13]=p,p=i[29]-p,i[29]=p,p=i[1]-i[0],i[1]=p,p=i[16]-p,i[16]=p,p=i[17]-p,i[17]=p,p=i[8]-p,i[8]=p,p=i[9]-p,i[9]=p,p=i[24]-p,i[24]=p,p=i[25]-p,i[25]=p,p=i[4]-p,i[4]=p,p=i[5]-p,i[5]=p,p=i[20]-p,i[20]=p,p=i[21]-p,i[21]=p,p=i[12]-p,i[12]=p,p=i[13]-p,i[13]=p,p=i[28]-p,i[28]=p,p=i[29]-p,i[29]=p,p=i[0],i[0]+=i[31],i[31]-=p,p=i[1],i[1]+=i[30],i[30]-=p,p=i[16],i[16]+=i[15],i[15]-=p,p=i[17],i[17]+=i[14],i[14]-=p,p=i[8],i[8]+=i[23],i[23]-=p,p=i[9],i[9]+=i[22],i[22]-=p,p=i[24],i[24]+=i[7],i[7]-=p,p=i[25],i[25]+=i[6],i[6]-=p,p=i[4],i[4]+=i[27],i[27]-=p,p=i[5],i[5]+=i[26],i[26]-=p,p=i[20],i[20]+=i[11],i[11]-=p,p=i[21],i[21]+=i[10],i[10]-=p,p=i[12],i[12]+=i[19],i[19]-=p,p=i[13],i[13]+=i[18],i[18]-=p,p=i[28],i[28]+=i[3],i[3]-=p,p=i[29],i[29]+=i[2],i[2]-=p}function h(e,t){for(var n=0;n<3;n++){var r,i,o,s=e[t+6]*c[a.SHORT_TYPE][0]-e[t+15],l,u;r=e[t+0]*c[a.SHORT_TYPE][2]-e[t+9],i=s+r,o=s-r,s=e[t+15]*c[a.SHORT_TYPE][0]+e[t+6],r=e[t+9]*c[a.SHORT_TYPE][2]+e[t+0],l=s+r,u=-s+r,r=(e[t+3]*c[a.SHORT_TYPE][1]-e[t+12])*2069978111953089e-26,s=(e[t+12]*c[a.SHORT_TYPE][1]+e[t+3])*2069978111953089e-26,e[t+0]=i*190752519173728e-25+r,e[t+15]=-l*190752519173728e-25+s,o=o*.8660254037844387*1907525191737281e-26,l=l*.5*1907525191737281e-26+s,e[t+3]=o-l,e[t+6]=o+l,i=i*.5*1907525191737281e-26-r,u=u*.8660254037844387*1907525191737281e-26,e[t+9]=i+u,e[t+12]=i-u,t++}}function g(e,t,n){var r,i,a=n[17]-n[9],o,s=n[15]-n[11],c=n[14]-n[12],l=n[0]+n[8],d=n[1]+n[7],f=n[2]+n[6],p=n[3]+n[5];e[t+17]=l+f-p-(d-n[4]),i=(l+f-p)*u[19]+(d-n[4]),r=(a-s-c)*u[18],e[t+5]=r+i,e[t+6]=r-i,o=(n[16]-n[10])*u[18],d=d*u[19]+n[4],r=a*u[12]+o+s*u[13]+c*u[14],i=-l*u[16]+d-f*u[17]+p*u[15],e[t+1]=r+i,e[t+2]=r-i,r=a*u[13]-o-s*u[14]+c*u[12],i=-l*u[17]+d-f*u[15]+p*u[16],e[t+9]=r+i,e[t+10]=r-i,r=a*u[14]-o+s*u[12]-c*u[13],i=l*u[15]-d+f*u[16]-p*u[17],e[t+13]=r+i,e[t+14]=r-i;var m=n[8]-n[0],h,g=n[6]-n[2],_=n[5]-n[3],v=n[17]+n[9],y=n[16]+n[10],b=n[15]+n[11],x=n[14]+n[12];e[t+0]=v+b+x+(y+n[13]),r=(v+b+x)*u[19]-(y+n[13]),i=(m-g+_)*u[18],e[t+11]=r+i,e[t+12]=r-i,h=(n[7]-n[1])*u[18],y=n[13]-y*u[19],r=v*u[15]-y+b*u[16]+x*u[17],i=m*u[14]+h+g*u[12]+_*u[13],e[t+3]=r+i,e[t+4]=r-i,r=-v*u[17]+y-b*u[15]-x*u[16],i=m*u[13]+h-g*u[14]-_*u[12],e[t+7]=r+i,e[t+8]=r-i,r=-v*u[16]+y-b*u[17]-x*u[15],i=m*u[12]-h+g*u[13]-_*u[14],e[t+15]=r+i,e[t+16]=r-i}this.mdct_sub48=function(e,n,u){for(var _=n,v=286,y=0;y<e.channels_out;y++){for(var b=0;b<e.mode_gr;b++){for(var x,S=e.l3_side.tt[b][y],C=S.xr,w=0,T=e.sb_sample[y][1-b],E=0,D=0;D<9;D++)for(m(_,v,T[E]),m(_,v+32,T[E+1]),E+=2,v+=64,x=1;x<32;x+=2)T[E-1][x]*=-1;for(x=0;x<32;x++,w+=18){var O=S.block_type,k=e.sb_sample[y][b],A=e.sb_sample[y][1-b];if(S.mixed_block_flag!=0&&x<2&&(O=0),e.amp_filter[x]<1e-12)r.fill(C,w+0,w+18,0);else{if(e.amp_filter[x]<1)for(var D=0;D<18;D++)A[D][p[x]]*=e.amp_filter[x];if(O==a.SHORT_TYPE){for(var D=-o/4;D<0;D++){var j=c[a.SHORT_TYPE][D+3];C[w+D*3+9]=k[9+D][p[x]]*j-k[8-D][p[x]],C[w+D*3+18]=k[14-D][p[x]]*j+k[15+D][p[x]],C[w+D*3+10]=k[15+D][p[x]]*j-k[14-D][p[x]],C[w+D*3+19]=A[2-D][p[x]]*j+A[3+D][p[x]],C[w+D*3+11]=A[3+D][p[x]]*j-A[2-D][p[x]],C[w+D*3+20]=A[8-D][p[x]]*j+A[9+D][p[x]]}h(C,w)}else{for(var M=i(18),D=-s/4;D<0;D++){var N=c[O][D+27]*A[D+9][p[x]]+c[O][D+36]*A[8-D][p[x]],P=c[O][D+9]*k[D+9][p[x]]-c[O][D+18]*k[8-D][p[x]];M[D+9]=N-P*l[3+D+9],M[D+18]=N*l[3+D+9]+P}g(C,w,M)}}if(O!=a.SHORT_TYPE&&x!=0)for(var D=7;D>=0;--D){var F=C[w+D]*d[20+D]+C[w+-1-D]*f[28+D],I=C[w+D]*f[28+D]-C[w+-1-D]*d[20+D];C[w+-1-D]=F,C[w+D]=I}}}if(_=u,v=286,e.mode_gr==1)for(var ee=0;ee<18;ee++)t.arraycopy(e.sb_sample[y][1][ee],0,e.sb_sample[y][0][ee],0,32)}}}return Rc=o,Rc}function qs(){if(Vc)return Bc;Vc=1;var e=Xs(),t=Lc,n=t.System,r=t.new_float,i=t.new_float_n;function a(){this.l=r(e.SBMAX_l),this.s=i([e.SBMAX_s,3]);var t=this;this.assign=function(r){n.arraycopy(r.l,0,t.l,0,e.SBMAX_l);for(var i=0;i<e.SBMAX_s;i++)for(var a=0;a<3;a++)t.s[i][a]=r.s[i][a]}}return Bc=a,Bc}function Js(){if(Uc)return Hc;Uc=1;var e=qs();function t(){this.thm=new e,this.en=new e}return Hc=t,Hc}function Ys(e){var t=e;this.ordinal=function(){return t}}function Xs(){if(Kc)return Gc;Kc=1;var e=Lc,t=e.System,n=e.VbrMode,r=e.new_array_n,i=e.new_float,a=e.new_float_n,o=e.new_int,s=e.assert;c.ENCDELAY=576,c.POSTDELAY=1152,c.MDCTDELAY=48,c.FFTOFFSET=224+c.MDCTDELAY,c.DECDELAY=528,c.SBLIMIT=32,c.CBANDS=64,c.SBPSY_l=21,c.SBPSY_s=12,c.SBMAX_l=22,c.SBMAX_s=13,c.PSFB21=6,c.PSFB12=6,c.BLKSIZE=1024,c.HBLKSIZE=c.BLKSIZE/2+1,c.BLKSIZE_s=256,c.HBLKSIZE_s=c.BLKSIZE_s/2+1,c.NORM_TYPE=0,c.START_TYPE=1,c.SHORT_TYPE=2,c.STOP_TYPE=3,c.MPG_MD_LR_LR=0,c.MPG_MD_LR_I=1,c.MPG_MD_MS_LR=2,c.MPG_MD_MS_I=3,c.fircoef=[-.1039435,-.1892065,-.0432472*5,-.155915,3898045e-23,.0467745*5,.50455,.756825,.187098*5];function c(){var e=Ks(),l=Js(),u=Wc,d=c.FFTOFFSET,f=c.MPG_MD_MS_LR,p=null;this.psy=null;var m=null,h=null,g=null;this.setModules=function(e,t,n,r){p=e,this.psy=t,m=t,h=r,g=n};var _=new e;function v(e){var t,n;if(e.ATH.useAdjust==0){e.ATH.adjust=1;return}if(n=e.loudness_sq[0][0],t=e.loudness_sq[1][0],e.channels_out==2?(n+=e.loudness_sq[0][1],t+=e.loudness_sq[1][1]):(n+=n,t+=t),e.mode_gr==2&&(n=Math.max(n,t)),n*=.5,n*=e.ATH.aaSensitivityP,n>.03125)e.ATH.adjust>=1?e.ATH.adjust=1:e.ATH.adjust<e.ATH.adjustLimit&&(e.ATH.adjust=e.ATH.adjustLimit),e.ATH.adjustLimit=1;else{var r=31.98*n+625e-6;e.ATH.adjust>=r?(e.ATH.adjust*=r*.075+.925,e.ATH.adjust<r&&(e.ATH.adjust=r)):e.ATH.adjustLimit>=r?e.ATH.adjust=r:e.ATH.adjust<e.ATH.adjustLimit&&(e.ATH.adjust=e.ATH.adjustLimit),e.ATH.adjustLimit=r}}function y(e){var t,n;for(s(0<=e.bitrate_index&&e.bitrate_index<16),s(0<=e.mode_ext&&e.mode_ext<4),e.bitrate_stereoMode_Hist[e.bitrate_index][4]++,e.bitrate_stereoMode_Hist[15][4]++,e.channels_out==2&&(e.bitrate_stereoMode_Hist[e.bitrate_index][e.mode_ext]++,e.bitrate_stereoMode_Hist[15][e.mode_ext]++),t=0;t<e.mode_gr;++t)for(n=0;n<e.channels_out;++n){var r=e.l3_side.tt[t][n].block_type|0;e.l3_side.tt[t][n].mixed_block_flag!=0&&(r=4),e.bitrate_blockType_Hist[e.bitrate_index][r]++,e.bitrate_blockType_Hist[e.bitrate_index][5]++,e.bitrate_blockType_Hist[15][r]++,e.bitrate_blockType_Hist[15][5]++}}function b(e,t){var n=e.internal_flags,r,a;if(n.lame_encode_frame_init==0){var o,l,u=i(2014),d=i(2014);for(n.lame_encode_frame_init=1,o=0,l=0;o<286+576*(1+n.mode_gr);++o)o<576*n.mode_gr?(u[o]=0,n.channels_out==2&&(d[o]=0)):(u[o]=t[0][l],n.channels_out==2&&(d[o]=t[1][l]),++l);for(a=0;a<n.mode_gr;a++)for(r=0;r<n.channels_out;r++)n.l3_side.tt[a][r].block_type=c.SHORT_TYPE;_.mdct_sub48(n,u,d),s(576>=c.FFTOFFSET),s(n.mf_size>=c.BLKSIZE+e.framesize-c.FFTOFFSET),s(n.mf_size>=512+e.framesize-32)}}this.lame_encode_mp3_frame=function(e,i,s,x,S,C){var w,T=r([2,2]);T[0][0]=new l,T[0][1]=new l,T[1][0]=new l,T[1][1]=new l;var E=r([2,2]);E[0][0]=new l,E[0][1]=new l,E[1][0]=new l,E[1][1]=new l;var D,O=[null,null],k=e.internal_flags,A=a([2,4]),j=[.5,.5],M=[[0,0],[0,0]],N=[[0,0],[0,0]],P,F,I;if(O[0]=i,O[1]=s,k.lame_encode_frame_init==0&&b(e,O),k.padding=0,(k.slot_lag-=k.frac_SpF)<0&&(k.slot_lag+=e.out_samplerate,k.padding=1),k.psymodel!=0){var ee,te=[null,null],L=0,R=o(2);for(I=0;I<k.mode_gr;I++){for(F=0;F<k.channels_out;F++)te[F]=O[F],L=576+I*576-c.FFTOFFSET;if(ee=e.VBR==n.vbr_mtrh||e.VBR==n.vbr_mt?m.L3psycho_anal_vbr(e,te,L,I,T,E,M[I],N[I],A[I],R):m.L3psycho_anal_ns(e,te,L,I,T,E,M[I],N[I],A[I],R),ee!=0)return-4;for(e.mode==u.JOINT_STEREO&&(j[I]=A[I][2]+A[I][3],j[I]>0&&(j[I]=A[I][3]/j[I])),F=0;F<k.channels_out;F++){var ne=k.l3_side.tt[I][F];ne.block_type=R[F],ne.mixed_block_flag=0}}}else for(I=0;I<k.mode_gr;I++)for(F=0;F<k.channels_out;F++)k.l3_side.tt[I][F].block_type=c.NORM_TYPE,k.l3_side.tt[I][F].mixed_block_flag=0,N[I][F]=M[I][F]=700;if(v(k),_.mdct_sub48(k,O[0],O[1]),k.mode_ext=c.MPG_MD_LR_LR,e.force_ms)k.mode_ext=c.MPG_MD_MS_LR;else if(e.mode==u.JOINT_STEREO){var z=0,re=0;for(I=0;I<k.mode_gr;I++)for(F=0;F<k.channels_out;F++)z+=N[I][F],re+=M[I][F];if(z<=1*re){var ie=k.l3_side.tt[0],ae=k.l3_side.tt[k.mode_gr-1];ie[0].block_type==ie[1].block_type&&ae[0].block_type==ae[1].block_type&&(k.mode_ext=c.MPG_MD_MS_LR)}}if(k.mode_ext==f?(D=E,P=N):(D=T,P=M),e.analysis&&k.pinfo!=null)for(I=0;I<k.mode_gr;I++)for(F=0;F<k.channels_out;F++)k.pinfo.ms_ratio[I]=k.ms_ratio[I],k.pinfo.ms_ener_ratio[I]=j[I],k.pinfo.blocktype[I][F]=k.l3_side.tt[I][F].block_type,k.pinfo.pe[I][F]=P[I][F],t.arraycopy(k.l3_side.tt[I][F].xr,0,k.pinfo.xr[I][F],0,576),k.mode_ext==f&&(k.pinfo.ers[I][F]=k.pinfo.ers[I][F+2],t.arraycopy(k.pinfo.energy[I][F+2],0,k.pinfo.energy[I][F],0,k.pinfo.energy[I][F].length));if(e.VBR==n.vbr_off||e.VBR==n.vbr_abr){for(var oe=0,se;oe<18;oe++)k.nsPsy.pefirbuf[oe]=k.nsPsy.pefirbuf[oe+1];for(se=0,I=0;I<k.mode_gr;I++)for(F=0;F<k.channels_out;F++)se+=P[I][F];for(k.nsPsy.pefirbuf[18]=se,se=k.nsPsy.pefirbuf[9],oe=0;oe<9;oe++)se+=(k.nsPsy.pefirbuf[oe]+k.nsPsy.pefirbuf[18-oe])*c.fircoef[oe];for(se=3350*k.mode_gr*k.channels_out/se,I=0;I<k.mode_gr;I++)for(F=0;F<k.channels_out;F++)P[I][F]*=se}if(k.iteration_loop.iteration_loop(e,P,j,D),p.format_bitstream(e),w=p.copy_buffer(k,x,S,C,1),e.bWriteVbrTag&&h.addVbrFrame(e),e.analysis&&k.pinfo!=null){for(F=0;F<k.channels_out;F++){for(var ce=0;ce<d;ce++)k.pinfo.pcmdata[F][ce]=k.pinfo.pcmdata[F][ce+e.framesize];for(ce=d;ce<1600;ce++)k.pinfo.pcmdata[F][ce]=O[F][ce-d]}g.set_frame_pinfo(e,D)}return y(k),w}}return Gc=c,Gc}function Zs(){var e=Yc(Xc.BLKSIZE),t=Yc(Xc.BLKSIZE_s/2),n=[.9238795325112867,.3826834323650898,.9951847266721969,.0980171403295606,.9996988186962042,.02454122852291229,.9999811752826011,.006135884649154475];function r(e,t,r){var i=0,a,o,s;r<<=1;var c=t+r;a=4;do{var l,u,d,f,p,m,h=a>>1;f=a,p=a<<1,m=p+f,a=p<<1,o=t,s=o+h;do{var g,_=e[o+0]-e[o+f],v,y;g=e[o+0]+e[o+f],y=e[o+p]-e[o+m],v=e[o+p]+e[o+m],e[o+p]=g-v,e[o+0]=g+v,e[o+m]=_-y,e[o+f]=_+y,_=e[s+0]-e[s+f],g=e[s+0]+e[s+f],y=Jc.SQRT2*e[s+m],v=Jc.SQRT2*e[s+p],e[s+p]=g-v,e[s+0]=g+v,e[s+m]=_-y,e[s+f]=_+y,s+=a,o+=a}while(o<c);for(u=n[i+0],l=n[i+1],d=1;d<h;d++){var b=1-2*l*l,x=2*l*u;o=t+d,s=t+f-d;do{var S,C=x*e[o+f]-b*e[s+f],w,g,_,T,v,E,y,D;S=b*e[o+f]+x*e[s+f],_=e[o+0]-S,g=e[o+0]+S,T=e[s+0]-C,w=e[s+0]+C,C=x*e[o+m]-b*e[s+m],S=b*e[o+m]+x*e[s+m],y=e[o+p]-S,v=e[o+p]+S,D=e[s+p]-C,E=e[s+p]+C,C=l*v-u*D,S=u*v+l*D,e[o+p]=g-S,e[o+0]=g+S,e[s+m]=T-C,e[s+f]=T+C,C=u*E-l*y,S=l*E+u*y,e[s+p]=w-S,e[s+0]=w+S,e[o+m]=_-C,e[o+f]=_+C,s+=a,o+=a}while(o<c);b=u,u=b*n[i+0]-l*n[i+1],l=b*n[i+1]+l*n[i+0]}i+=2}while(a<r)}var i=[0,128,64,192,32,160,96,224,16,144,80,208,48,176,112,240,8,136,72,200,40,168,104,232,24,152,88,216,56,184,120,248,4,132,68,196,36,164,100,228,20,148,84,212,52,180,116,244,12,140,76,204,44,172,108,236,28,156,92,220,60,188,124,252,2,130,66,194,34,162,98,226,18,146,82,210,50,178,114,242,10,138,74,202,42,170,106,234,26,154,90,218,58,186,122,250,6,134,70,198,38,166,102,230,22,150,86,214,54,182,118,246,14,142,78,206,46,174,110,238,30,158,94,222,62,190,126,254];this.fft_short=function(e,n,a,o,s){for(var c=0;c<3;c++){var l=Xc.BLKSIZE_s/2,u=65535&192*(c+1),d=Xc.BLKSIZE_s/8-1;do{var f,p,m,h,g,_=i[d<<2]&255;f=t[_]*o[a][s+_+u],g=t[127-_]*o[a][s+_+u+128],p=f-g,f+=g,m=t[_+64]*o[a][s+_+u+64],g=t[63-_]*o[a][s+_+u+192],h=m-g,m+=g,l-=4,n[c][l+0]=f+m,n[c][l+2]=f-m,n[c][l+1]=p+h,n[c][l+3]=p-h,f=t[_+1]*o[a][s+_+u+1],g=t[126-_]*o[a][s+_+u+129],p=f-g,f+=g,m=t[_+65]*o[a][s+_+u+65],g=t[62-_]*o[a][s+_+u+193],h=m-g,m+=g,n[c][l+Xc.BLKSIZE_s/2+0]=f+m,n[c][l+Xc.BLKSIZE_s/2+2]=f-m,n[c][l+Xc.BLKSIZE_s/2+1]=p+h,n[c][l+Xc.BLKSIZE_s/2+3]=p-h}while(--d>=0);r(n[c],l,Xc.BLKSIZE_s/2)}},this.fft_long=function(t,n,a,o,s){var c=Xc.BLKSIZE/8-1,l=Xc.BLKSIZE/2;do{var u,d,f,p,m,h=i[c]&255;u=e[h]*o[a][s+h],m=e[h+512]*o[a][s+h+512],d=u-m,u+=m,f=e[h+256]*o[a][s+h+256],m=e[h+768]*o[a][s+h+768],p=f-m,f+=m,l-=4,n[l+0]=u+f,n[l+2]=u-f,n[l+1]=d+p,n[l+3]=d-p,u=e[h+1]*o[a][s+h+1],m=e[h+513]*o[a][s+h+513],d=u-m,u+=m,f=e[h+257]*o[a][s+h+257],m=e[h+769]*o[a][s+h+769],p=f-m,f+=m,n[l+Xc.BLKSIZE/2+0]=u+f,n[l+Xc.BLKSIZE/2+2]=u-f,n[l+Xc.BLKSIZE/2+1]=d+p,n[l+Xc.BLKSIZE/2+3]=d-p}while(--c>=0);r(n,l,Xc.BLKSIZE/2)},this.init_fft=function(n){for(var r=0;r<Xc.BLKSIZE;r++)e[r]=.42-.5*Math.cos(2*Math.PI*(r+.5)/Xc.BLKSIZE)+.08*Math.cos(4*Math.PI*(r+.5)/Xc.BLKSIZE);for(var r=0;r<Xc.BLKSIZE_s/2;r++)t[r]=.5*(1-Math.cos(2*Math.PI*(r+.5)/Xc.BLKSIZE_s))}}function Qs(){var e=Wc,t=new cl,n=2.302585092994046,r=2,i=16,a=2,o=16,s=.34,c=1/217621504/(W.BLKSIZE/2),l=.01,u=.8,d=.6,f=.3,p=3.5,m=21,h=.2302585093;function g(e,t){for(var n=0,r=0;r<W.BLKSIZE/2;++r)n+=e[r]*t.ATH.eql_w[r];return n*=c,n}function _(e,n,r,i,a,o,s,c,l,u,d){var f=e.internal_flags;if(l<2)t.fft_long(f,i[a],l,u,d),t.fft_short(f,o[s],l,u,d);else if(l==2){for(var p=W.BLKSIZE-1;p>=0;--p){var m=i[a+0][p],h=i[a+1][p];i[a+0][p]=(m+h)*nl.SQRT2*.5,i[a+1][p]=(m-h)*nl.SQRT2*.5}for(var _=2;_>=0;--_)for(var p=W.BLKSIZE_s-1;p>=0;--p){var m=o[s+0][_][p],h=o[s+1][_][p];o[s+0][_][p]=(m+h)*nl.SQRT2*.5,o[s+1][_][p]=(m-h)*nl.SQRT2*.5}}n[0]=i[a+0][0],n[0]*=n[0];for(var p=W.BLKSIZE/2-1;p>=0;--p){var v=i[a+0][W.BLKSIZE/2-p],y=i[a+0][W.BLKSIZE/2+p];n[W.BLKSIZE/2-p]=(v*v+y*y)*.5}for(var _=2;_>=0;--_){r[_][0]=o[s+0][_][0],r[_][0]*=r[_][0];for(var p=W.BLKSIZE_s/2-1;p>=0;--p){var v=o[s+0][_][W.BLKSIZE_s/2-p],y=o[s+0][_][W.BLKSIZE_s/2+p];r[_][W.BLKSIZE_s/2-p]=(v*v+y*y)*.5}}for(var b=0,p=11;p<W.HBLKSIZE;p++)b+=n[p];if(f.tot_ener[l]=b,e.analysis){for(var p=0;p<W.HBLKSIZE;p++)f.pinfo.energy[c][l][p]=f.pinfo.energy_save[l][p],f.pinfo.energy_save[l][p]=n[p];f.pinfo.pe[c][l]=f.pe[l]}e.athaa_loudapprox==2&&l<2&&(f.loudness_sq[c][l]=f.loudness_sq_save[l],f.loudness_sq_save[l]=g(n,f))}var v=8,y=23,b=15,x,S,C,w=[1,.79433,.63096,.63096,.63096,.63096,.63096,.25119,.11749];function T(){x=10**((v+1)/16),S=10**((y+1)/16),C=10**(b/10)}var E=[3.3246*3.3246,3.23837*3.23837,9.9500500969,9.0247369744,8.1854926609,7.0440875649,2.46209*2.46209,2.284*2.284,4.4892710641,1.96552*1.96552,1.82335*1.82335,1.69146*1.69146,2.4621061921,2.1508568964,1.37074*1.37074,1.31036*1.31036,1.5691069696,1.4555939904,1.16203*1.16203,1.2715945225,1.09428*1.09428,1.0659*1.0659,1.0779838276,1.0382591025,1],D=[1.7782755904,1.35879*1.35879,1.38454*1.38454,1.39497*1.39497,1.40548*1.40548,1.3537*1.3537,1.6999465924,1.22321*1.22321,1.3169398564,1],O=[5.5396212496,2.29259*2.29259,4.9868695969,2.12675*2.12675,2.02545*2.02545,1.87894*1.87894,1.74303*1.74303,1.61695*1.61695,2.2499700001,1.39148*1.39148,1.29083*1.29083,1.19746*1.19746,1.2339655056,1.0779838276];function k(e,t,n,r,i,a){var o;if(t>e){if(t<e*S)o=t/e;else return e+t}else{if(e>=t*S)return e+t;o=e/t}if(e+=t,r+3<=6){if(o>=x)return e;var s=0|nl.FAST_LOG10_X(o,16);return e*D[s]}var s=0|nl.FAST_LOG10_X(o,16);if(t=a==0?i.ATH.cb_l[n]*i.ATH.adjust:i.ATH.cb_s[n]*i.ATH.adjust,e<C*t){if(e>t){var c=1,l;return s<=13&&(c=O[s]),l=nl.FAST_LOG10_X(e/t,10/15),e*((E[s]-c)*l+c)}return s>13?e:e*O[s]}return e*E[s]}var A=[1.7782755904,1.35879*1.35879,1.38454*1.38454,1.39497*1.39497,1.40548*1.40548,1.3537*1.3537,1.6999465924,1.22321*1.22321,1.3169398564,1];function j(e,t,n){var r;if(e<0&&(e=0),t<0&&(t=0),e<=0)return t;if(t<=0)return e;if(r=t>e?t/e:e/t,-2<=n&&n<=2){if(r>=x)return e+t;var i=0|nl.FAST_LOG10_X(r,16);return(e+t)*A[i]}return r<S?e+t:(e<t&&(e=t),e)}function M(e,t){var n=e.internal_flags;if(n.channels_out>1){for(var r=0;r<W.SBMAX_l;r++){var i=n.thm[0].l[r],a=n.thm[1].l[r];n.thm[0].l[r]+=a*t,n.thm[1].l[r]+=i*t}for(var r=0;r<W.SBMAX_s;r++)for(var o=0;o<3;o++){var i=n.thm[0].s[r][o],a=n.thm[1].s[r][o];n.thm[0].s[r][o]+=a*t,n.thm[1].s[r][o]+=i*t}}}function N(e){for(var t=0;t<W.SBMAX_l;t++)if(!(e.thm[0].l[t]>1.58*e.thm[1].l[t]||e.thm[1].l[t]>1.58*e.thm[0].l[t])){var n=e.mld_l[t]*e.en[3].l[t],r=Math.max(e.thm[2].l[t],Math.min(e.thm[3].l[t],n));n=e.mld_l[t]*e.en[2].l[t];var i=Math.max(e.thm[3].l[t],Math.min(e.thm[2].l[t],n));e.thm[2].l[t]=r,e.thm[3].l[t]=i}for(var t=0;t<W.SBMAX_s;t++)for(var a=0;a<3;a++)if(!(e.thm[0].s[t][a]>1.58*e.thm[1].s[t][a]||e.thm[1].s[t][a]>1.58*e.thm[0].s[t][a])){var n=e.mld_s[t]*e.en[3].s[t][a],r=Math.max(e.thm[2].s[t][a],Math.min(e.thm[3].s[t][a],n));n=e.mld_s[t]*e.en[2].s[t][a];var i=Math.max(e.thm[3].s[t][a],Math.min(e.thm[2].s[t][a],n));e.thm[2].s[t][a]=r,e.thm[3].s[t][a]=i}}function P(e,t,n){var r=t,i=10**n;t*=2,r*=2;for(var a=0;a<W.SBMAX_l;a++){var o,s,c,l=e.ATH.cb_l[e.bm_l[a]]*i;if(o=Math.min(Math.max(e.thm[0].l[a],l),Math.max(e.thm[1].l[a],l)),s=Math.max(e.thm[2].l[a],l),c=Math.max(e.thm[3].l[a],l),o*t<s+c){var u=o*r/(s+c);s*=u,c*=u}e.thm[2].l[a]=Math.min(s,e.thm[2].l[a]),e.thm[3].l[a]=Math.min(c,e.thm[3].l[a])}i*=W.BLKSIZE_s/W.BLKSIZE;for(var a=0;a<W.SBMAX_s;a++)for(var d=0;d<3;d++){var o,s,c,l=e.ATH.cb_s[e.bm_s[a]]*i;if(o=Math.min(Math.max(e.thm[0].s[a][d],l),Math.max(e.thm[1].s[a][d],l)),s=Math.max(e.thm[2].s[a][d],l),c=Math.max(e.thm[3].s[a][d],l),o*t<s+c){var u=o*t/(s+c);s*=u,c*=u}e.thm[2].s[a][d]=Math.min(e.thm[2].s[a][d],s),e.thm[3].s[a][d]=Math.min(e.thm[3].s[a][d],c)}}function F(e,t,n,r,i){var a,o,s=0,c=0;for(a=o=0;a<W.SBMAX_s;++o,++a){for(var l=e.bo_s[a],u=e.npart_s,d=l<u?l:u;o<d;)sl(t[o]>=0),sl(n[o]>=0),s+=t[o],c+=n[o],o++;if(e.en[r].s[a][i]=s,e.thm[r].s[a][i]=c,o>=u){++a;break}sl(t[o]>=0),sl(n[o]>=0);var f=e.PSY.bo_s_weight[a],p=1-f;s=f*t[o],c=f*n[o],e.en[r].s[a][i]+=s,e.thm[r].s[a][i]+=c,s=p*t[o],c=p*n[o]}for(;a<W.SBMAX_s;++a)e.en[r].s[a][i]=0,e.thm[r].s[a][i]=0}function I(e,t,n,r){var i,a,o=0,s=0;for(i=a=0;i<W.SBMAX_l;++a,++i){for(var c=e.bo_l[i],l=e.npart_l,u=c<l?c:l;a<u;)sl(t[a]>=0),sl(n[a]>=0),o+=t[a],s+=n[a],a++;if(e.en[r].l[i]=o,e.thm[r].l[i]=s,a>=l){++i;break}sl(t[a]>=0),sl(n[a]>=0);var d=e.PSY.bo_l_weight[i],f=1-d;o=d*t[a],s=d*n[a],e.en[r].l[i]+=o,e.thm[r].l[i]+=s,o=f*t[a],s=f*n[a]}for(;i<W.SBMAX_l;++i)e.en[r].l[i]=0,e.thm[r].l[i]=0}function ee(e,t,n,r,i,s){for(var c=e.internal_flags,l,u=l=0;u<c.npart_s;++u){for(var d=0,f=c.numlines_s[u],p=0;p<f;++p,++l){var m=t[s][l];d+=m}n[u]=d}for(sl(u==c.npart_s),l=u=0;u<c.npart_s;u++){var h=c.s3ind_s[u][0],g=c.s3_ss[l++]*n[h];for(++h;h<=c.s3ind_s[u][1];)g+=c.s3_ss[l]*n[h],++l,++h;var _=a*c.nb_s1[i][u];if(r[u]=Math.min(g,_),c.blocktype_old[i&1]==W.SHORT_TYPE){var _=o*c.nb_s2[i][u],v=r[u];r[u]=Math.min(_,v)}c.nb_s2[i][u]=c.nb_s1[i][u],c.nb_s1[i][u]=g,sl(r[u]>=0)}for(;u<=W.CBANDS;++u)n[u]=0,r[u]=0}function te(e,t,n,r){var i=e.internal_flags;e.short_blocks==tl.short_block_coupled&&(t[0]==0||t[1]==0)&&(t[0]=t[1]=0);for(var a=0;a<i.channels_out;a++)r[a]=W.NORM_TYPE,e.short_blocks==tl.short_block_dispensed&&(t[a]=1),e.short_blocks==tl.short_block_forced&&(t[a]=0),t[a]==0?(r[a]=W.SHORT_TYPE,i.blocktype_old[a]==W.NORM_TYPE&&(i.blocktype_old[a]=W.START_TYPE),i.blocktype_old[a]==W.STOP_TYPE&&(i.blocktype_old[a]=W.SHORT_TYPE)):(sl(i.blocktype_old[a]!=W.START_TYPE),i.blocktype_old[a]==W.SHORT_TYPE&&(r[a]=W.STOP_TYPE)),n[a]=i.blocktype_old[a],i.blocktype_old[a]=r[a]}function L(e,t,n){return n>=1?e:n<=0?t:t>0?(e/t)**+n*t:0}var R=[11.8,13.6,17.2,32,46.5,51.3,57.5,67.1,71.5,84.6,97.6,130];function ne(e,t){for(var r=309.07,i=0;i<W.SBMAX_s-1;i++)for(var a=0;a<3;a++){var o=e.thm.s[i][a];if(o>0){var s=o*t,c=e.en.s[i][a];c>s&&(c>s*1e10?r+=R[i]*(10*n):r+=R[i]*nl.FAST_LOG10(c/s))}}return r}var z=[6.8,5.8,5.8,6.4,6.5,9.9,12.1,14.4,15,18.9,21.6,26.9,34.2,40.2,46.8,56.5,60.7,73.9,85.7,93.4,126.1];function re(e,t){for(var r=281.0575,i=0;i<W.SBMAX_l-1;i++){var a=e.thm.l[i];if(a>0){var o=a*t,s=e.en.l[i];s>o&&(s>o*1e10?r+=z[i]*(10*n):r+=z[i]*nl.FAST_LOG10(s/o))}}return r}function ie(e,t,n,r,i){for(var a=o=0,o;a<e.npart_l;++a){for(var s=0,c=0,l=0;l<e.numlines_l[a];++l,++o){var u=t[o];s+=u,c<u&&(c=u)}n[a]=s,r[a]=c,i[a]=s*e.rnumlines_l[a],sl(e.rnumlines_l[a]>=0),sl(n[a]>=0),sl(r[a]>=0),sl(i[a]>=0)}}function ae(e,t,n,r){var i=w.length-1,a=0,o=n[a]+n[a+1];if(o>0){var s=t[a];s<t[a+1]&&(s=t[a+1]),sl(e.numlines_l[a]+e.numlines_l[a+1]-1>0),o=20*(s*2-o)/(o*(e.numlines_l[a]+e.numlines_l[a+1]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;for(a=1;a<e.npart_l-1;a++)if(o=n[a-1]+n[a]+n[a+1],o>0){var s=t[a-1];s<t[a]&&(s=t[a]),s<t[a+1]&&(s=t[a+1]),sl(e.numlines_l[a-1]+e.numlines_l[a]+e.numlines_l[a+1]-1>0),o=20*(s*3-o)/(o*(e.numlines_l[a-1]+e.numlines_l[a]+e.numlines_l[a+1]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;if(sl(a==e.npart_l-1),o=n[a-1]+n[a],o>0){var s=t[a-1];s<t[a]&&(s=t[a]),sl(e.numlines_l[a-1]+e.numlines_l[a]-1>0),o=20*(s*2-o)/(o*(e.numlines_l[a-1]+e.numlines_l[a]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;sl(a==e.npart_l-1)}var oe=[-1730326e-23,-.01703172,-1349528e-23,.0418072,-673278e-22,-.0876324,-30835e-21,.1863476,-1104424e-22,-.627638];this.L3psycho_anal_ns=function(t,n,a,o,s,c,l,p,h,g){var v=t.internal_flags,y=al([2,W.BLKSIZE]),b=al([2,3,W.BLKSIZE_s]),x=il(W.CBANDS+1),S=il(W.CBANDS+1),C=il(W.CBANDS+2),T=ol(2),E=ol(2),D,O,A,j,R,z,se,ce,le=al([2,576]),ue,de=ol(W.CBANDS+2),fe=ol(W.CBANDS+2);for(rl.fill(fe,0),D=v.channels_out,t.mode==e.JOINT_STEREO&&(D=4),ue=t.VBR==$c.vbr_off?v.ResvMax==0?0:v.ResvSize/v.ResvMax*.5:t.VBR==$c.vbr_rh||t.VBR==$c.vbr_mtrh||t.VBR==$c.vbr_mt?.6:1,O=0;O<v.channels_out;O++){var pe=n[O],me=a+576-350-m+192;for(j=0;j<576;j++){var he=pe[me+j+10],ge=0;for(R=0;R<(m-1)/2-1;R+=2)he+=oe[R]*(pe[me+j+R]+pe[me+j+m-R]),ge+=oe[R+1]*(pe[me+j+R+1]+pe[me+j+m-R-1]);le[O][j]=he+ge}s[o][O].en.assign(v.en[O]),s[o][O].thm.assign(v.thm[O]),D>2&&(c[o][O].en.assign(v.en[O+2]),c[o][O].thm.assign(v.thm[O+2]))}for(O=0;O<D;O++){var _e,ve,ye=il(12),be=[0,0,0,0],xe=il(12),Se=1,Ce,we=il(W.CBANDS),Te=il(W.CBANDS),Ee=[0,0,0,0],De=il(W.HBLKSIZE),Oe=al([3,W.HBLKSIZE_s]);for(sl(v.npart_s<=W.CBANDS),sl(v.npart_l<=W.CBANDS),j=0;j<3;j++)ye[j]=v.nsPsy.last_en_subshort[O][j+6],sl(v.nsPsy.last_en_subshort[O][j+4]>0),xe[j]=ye[j]/v.nsPsy.last_en_subshort[O][j+4],be[0]+=ye[j];if(O==2)for(j=0;j<576;j++){var ke=le[0][j],Ae=le[1][j];le[0][j]=ke+Ae,le[1][j]=ke-Ae}var je=le[O&1],Me=0;for(j=0;j<9;j++){for(var Ne=Me+64,Pe=1;Me<Ne;Me++)Pe<Math.abs(je[Me])&&(Pe=Math.abs(je[Me]));v.nsPsy.last_en_subshort[O][j]=ye[j+3]=Pe,be[1+j/3]+=Pe,Pe>ye[j+3-2]?(sl(ye[j+3-2]>0),Pe/=ye[j+3-2]):Pe=ye[j+3-2]>Pe*10?ye[j+3-2]/(Pe*10):0,xe[j+3]=Pe}if(t.analysis){var Fe=xe[0];for(j=1;j<12;j++)Fe<xe[j]&&(Fe=xe[j]);v.pinfo.ers[o][O]=v.pinfo.ers_save[O],v.pinfo.ers_save[O]=Fe}for(Ce=O==3?v.nsPsy.attackthre_s:v.nsPsy.attackthre,j=0;j<12;j++)Ee[j/3]==0&&xe[j]>Ce&&(Ee[j/3]=j%3+1);for(j=1;j<4;j++){var Ie;be[j-1]>be[j]?(sl(be[j]>0),Ie=be[j-1]/be[j]):(sl(be[j-1]>0),Ie=be[j]/be[j-1]),Ie<1.7&&(Ee[j]=0,j==1&&(Ee[0]=0))}for(Ee[0]!=0&&v.nsPsy.lastAttacks[O]!=0&&(Ee[0]=0),(v.nsPsy.lastAttacks[O]==3||Ee[0]+Ee[1]+Ee[2]+Ee[3]!=0)&&(Se=0,Ee[1]!=0&&Ee[0]!=0&&(Ee[1]=0),Ee[2]!=0&&Ee[1]!=0&&(Ee[2]=0),Ee[3]!=0&&Ee[2]!=0&&(Ee[3]=0)),O<2?E[O]=Se:Se==0&&(E[0]=E[1]=0),h[O]=v.tot_ener[O],ve=b,_e=y,_(t,De,Oe,_e,O&1,ve,O&1,o,O,n,a),ie(v,De,x,we,Te),ae(v,we,Te,de),ce=0;ce<3;ce++){var Le,Re;for(ee(t,Oe,S,C,O,ce),F(v,S,C,O,ce),se=0;se<W.SBMAX_s;se++){if(Re=v.thm[O].s[se][ce],Re*=u,Ee[ce]>=2||Ee[ce+1]==1){var ze=ce==0?2:ce-1,Pe=L(v.thm[O].s[se][ze],Re,d*ue);Re=Math.min(Re,Pe)}if(Ee[ce]==1){var ze=ce==0?2:ce-1,Pe=L(v.thm[O].s[se][ze],Re,f*ue);Re=Math.min(Re,Pe)}else if(ce!=0&&Ee[ce-1]==3||ce==0&&v.nsPsy.lastAttacks[O]==3){var ze=ce==2?0:ce+1,Pe=L(v.thm[O].s[se][ze],Re,f*ue);Re=Math.min(Re,Pe)}Le=ye[ce*3+3]+ye[ce*3+4]+ye[ce*3+5],ye[ce*3+5]*6<Le&&(Re*=.5,ye[ce*3+4]*6<Le&&(Re*=.5)),v.thm[O].s[se][ce]=Re}}for(v.nsPsy.lastAttacks[O]=Ee[2],z=0,A=0;A<v.npart_l;A++){for(var Be=v.s3ind[A][0],Ve=x[Be]*w[de[Be]],He=v.s3_ll[z++]*Ve;++Be<=v.s3ind[A][1];)Ve=x[Be]*w[de[Be]],He=k(He,v.s3_ll[z++]*Ve,Be,Be-A,v,0);He*=.158489319246111,v.blocktype_old[O&1]==W.SHORT_TYPE?C[A]=He:C[A]=L(Math.min(He,Math.min(r*v.nb_1[O][A],i*v.nb_2[O][A])),He,ue),v.nb_2[O][A]=v.nb_1[O][A],v.nb_1[O][A]=He}for(;A<=W.CBANDS;++A)x[A]=0,C[A]=0;I(v,x,C,O)}if((t.mode==e.STEREO||t.mode==e.JOINT_STEREO)&&t.interChRatio>0&&M(t,t.interChRatio),t.mode==e.JOINT_STEREO){var Ue;N(v),Ue=t.msfix,Math.abs(Ue)>0&&P(v,Ue,t.ATHlower*v.ATH.adjust)}for(te(t,E,g,T),O=0;O<D;O++){var We,Ge=0,Ke,qe;O>1?(We=p,Ge=-2,Ke=W.NORM_TYPE,(g[0]==W.SHORT_TYPE||g[1]==W.SHORT_TYPE)&&(Ke=W.SHORT_TYPE),qe=c[o][O-2]):(We=l,Ge=0,Ke=g[O],qe=s[o][O]),Ke==W.SHORT_TYPE?We[Ge+O]=ne(qe,v.masking_lower):We[Ge+O]=re(qe,v.masking_lower),t.analysis&&(v.pinfo.pe[o][O]=We[Ge+O])}return 0};function se(e,n,r,i,a,o,s,c){var l=e.internal_flags;if(i<2)t.fft_long(l,s[c],i,n,r);else if(i==2)for(var u=W.BLKSIZE-1;u>=0;--u){var d=s[c+0][u],f=s[c+1][u];s[c+0][u]=(d+f)*nl.SQRT2*.5,s[c+1][u]=(d-f)*nl.SQRT2*.5}o[0]=s[c+0][0],o[0]*=o[0];for(var u=W.BLKSIZE/2-1;u>=0;--u){var p=s[c+0][W.BLKSIZE/2-u],m=s[c+0][W.BLKSIZE/2+u];o[W.BLKSIZE/2-u]=(p*p+m*m)*.5}for(var h=0,u=11;u<W.HBLKSIZE;u++)h+=o[u];if(l.tot_ener[i]=h,e.analysis){for(var u=0;u<W.HBLKSIZE;u++)l.pinfo.energy[a][i][u]=l.pinfo.energy_save[i][u],l.pinfo.energy_save[i][u]=o[u];l.pinfo.pe[a][i]=l.pe[i]}}function ce(e,n,r,i,a,o,s,c){var l=e.internal_flags;if(a==0&&i<2&&t.fft_short(l,s[c],i,n,r),i==2)for(var u=W.BLKSIZE_s-1;u>=0;--u){var d=s[c+0][a][u],f=s[c+1][a][u];s[c+0][a][u]=(d+f)*nl.SQRT2*.5,s[c+1][a][u]=(d-f)*nl.SQRT2*.5}o[a][0]=s[c+0][a][0],o[a][0]*=o[a][0];for(var u=W.BLKSIZE_s/2-1;u>=0;--u){var p=s[c+0][a][W.BLKSIZE_s/2-u],m=s[c+0][a][W.BLKSIZE_s/2+u];o[a][W.BLKSIZE_s/2-u]=(p*p+m*m)*.5}}function le(e,t,n,r){var i=e.internal_flags;e.athaa_loudapprox==2&&n<2&&(i.loudness_sq[t][n]=i.loudness_sq_save[n],i.loudness_sq_save[n]=g(r,i))}var ue=[-1730326e-23,-.01703172,-1349528e-23,.0418072,-673278e-22,-.0876324,-30835e-21,.1863476,-1104424e-22,-.627638];function de(t,n,r,i,a,o,s,c,l,u){for(var d=al([2,576]),f=t.internal_flags,p=f.channels_out,h=t.mode==e.JOINT_STEREO?4:p,g=0;g<p;g++){firbuf=n[g];for(var _=r+576-350-m+192,v=0;v<576;v++){for(var y=firbuf[_+v+10],b=0,x=0;x<(m-1)/2-1;x+=2)y+=ue[x]*(firbuf[_+v+x]+firbuf[_+v+m-x]),b+=ue[x+1]*(firbuf[_+v+x+1]+firbuf[_+v+m-x-1]);d[g][v]=y+b}a[i][g].en.assign(f.en[g]),a[i][g].thm.assign(f.thm[g]),h>2&&(o[i][g].en.assign(f.en[g+2]),o[i][g].thm.assign(f.thm[g+2]))}for(var g=0;g<h;g++){var S=il(12),C=il(12),w=[0,0,0,0],T=d[g&1],E=0,D=g==3?f.nsPsy.attackthre_s:f.nsPsy.attackthre,O=1;if(g==2)for(var v=0,x=576;x>0;++v,--x){var k=d[0][v],A=d[1][v];d[0][v]=k+A,d[1][v]=k-A}for(var v=0;v<3;v++)C[v]=f.nsPsy.last_en_subshort[g][v+6],sl(f.nsPsy.last_en_subshort[g][v+4]>0),S[v]=C[v]/f.nsPsy.last_en_subshort[g][v+4],w[0]+=C[v];for(var v=0;v<9;v++){for(var j=E+64,M=1;E<j;E++)M<Math.abs(T[E])&&(M=Math.abs(T[E]));f.nsPsy.last_en_subshort[g][v]=C[v+3]=M,w[1+v/3]+=M,M>C[v+3-2]?(sl(C[v+3-2]>0),M/=C[v+3-2]):M=C[v+3-2]>M*10?C[v+3-2]/(M*10):0,S[v+3]=M}for(var v=0;v<3;++v){var N=C[v*3+3]+C[v*3+4]+C[v*3+5],P=1;C[v*3+5]*6<N&&(P*=.5,C[v*3+4]*6<N&&(P*=.5)),c[g][v]=P}if(t.analysis){for(var F=S[0],v=1;v<12;v++)F<S[v]&&(F=S[v]);f.pinfo.ers[i][g]=f.pinfo.ers_save[g],f.pinfo.ers_save[g]=F}for(var v=0;v<12;v++)l[g][v/3]==0&&S[v]>D&&(l[g][v/3]=v%3+1);for(var v=1;v<4;v++){var I=w[v-1],ee=w[v];Math.max(I,ee)<4e4&&I<1.7*ee&&ee<1.7*I&&(v==1&&l[g][0]<=l[g][v]&&(l[g][0]=0),l[g][v]=0)}l[g][0]<=f.nsPsy.lastAttacks[g]&&(l[g][0]=0),(f.nsPsy.lastAttacks[g]==3||l[g][0]+l[g][1]+l[g][2]+l[g][3]!=0)&&(O=0,l[g][1]!=0&&l[g][0]!=0&&(l[g][1]=0),l[g][2]!=0&&l[g][1]!=0&&(l[g][2]=0),l[g][3]!=0&&l[g][2]!=0&&(l[g][3]=0)),g<2?u[g]=O:O==0&&(u[0]=u[1]=0),s[g]=f.tot_ener[g]}}function fe(e,t,n){if(n==0)for(var r=0;r<e.npart_s;r++)e.nb_s2[t][r]=e.nb_s1[t][r],e.nb_s1[t][r]=0}function pe(e,t){for(var n=0;n<e.npart_l;n++)e.nb_2[t][n]=e.nb_1[t][n],e.nb_1[t][n]=0}function me(e,t,n,r){var i=w.length-1,a=0,o=n[a]+n[a+1];if(o>0){var s=t[a];s<t[a+1]&&(s=t[a+1]),sl(e.numlines_s[a]+e.numlines_s[a+1]-1>0),o=20*(s*2-o)/(o*(e.numlines_s[a]+e.numlines_s[a+1]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;for(a=1;a<e.npart_s-1;a++)if(o=n[a-1]+n[a]+n[a+1],sl(a+1<e.npart_s),o>0){var s=t[a-1];s<t[a]&&(s=t[a]),s<t[a+1]&&(s=t[a+1]),sl(e.numlines_s[a-1]+e.numlines_s[a]+e.numlines_s[a+1]-1>0),o=20*(s*3-o)/(o*(e.numlines_s[a-1]+e.numlines_s[a]+e.numlines_s[a+1]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;if(sl(a==e.npart_s-1),o=n[a-1]+n[a],o>0){var s=t[a-1];s<t[a]&&(s=t[a]),sl(e.numlines_s[a-1]+e.numlines_s[a]-1>0),o=20*(s*2-o)/(o*(e.numlines_s[a-1]+e.numlines_s[a]-1));var c=0|o;c>i&&(c=i),r[a]=c}else r[a]=0;sl(a==e.npart_s-1)}function he(e,t,n,r,i,a){var o=e.internal_flags,s=new float[W.CBANDS],c=il(W.CBANDS),l,u,d,f=new int[W.CBANDS];for(d=u=0;d<o.npart_s;++d){var p=0,m=0,h=o.numlines_s[d];for(l=0;l<h;++l,++u){var g=t[a][u];p+=g,m<g&&(m=g)}n[d]=p,s[d]=m,c[d]=p/h,sl(c[d]>=0)}for(sl(d==o.npart_s);d<W.CBANDS;++d)s[d]=0,c[d]=0;for(me(o,s,c,f),u=d=0;d<o.npart_s;d++){var _=o.s3ind_s[d][0],v=o.s3ind_s[d][1],y=f[_],b=1,x,S=o.s3_ss[u]*n[_]*w[f[_]],C;for(++u,++_;_<=v;)y+=f[_],b+=1,x=o.s3_ss[u]*n[_]*w[f[_]],S=j(S,x,_-d),++u,++_;y=(1+2*y)/(2*b),C=w[y]*.5,S*=C,r[d]=S,o.nb_s2[i][d]=o.nb_s1[i][d],o.nb_s1[i][d]=S,x=s[d],x*=o.minval_s[d],x*=C,r[d]>x&&(r[d]=x),o.masking_lower>1&&(r[d]*=o.masking_lower),r[d]>n[d]&&(r[d]=n[d]),o.masking_lower<1&&(r[d]*=o.masking_lower),sl(r[d]>=0)}for(;d<W.CBANDS;++d)n[d]=0,r[d]=0}function ge(e,t,n,a,o){var s=il(W.CBANDS),c=il(W.CBANDS),l=ol(W.CBANDS+2),u;ie(e,t,n,s,c),ae(e,s,c,l);var d=0;for(u=0;u<e.npart_l;u++){var p,m,h,g,_=e.s3ind[u][0],v=e.s3ind[u][1],y=0,b=0;for(y=l[_],b+=1,m=e.s3_ll[d]*n[_]*w[l[_]],++d,++_;_<=v;)y+=l[_],b+=1,p=e.s3_ll[d]*n[_]*w[l[_]],g=j(m,p,_-u),m=g,++d,++_;if(y=(1+2*y)/(2*b),h=w[y]*.5,m*=h,e.blocktype_old[o&1]==W.SHORT_TYPE){var x=r*e.nb_1[o][u];x>0?a[u]=Math.min(m,x):a[u]=Math.min(m,n[u]*f)}else{var S=i*e.nb_2[o][u],C=r*e.nb_1[o][u],x;S<=0&&(S=m),C<=0&&(C=m),x=e.blocktype_old[o&1]==W.NORM_TYPE?Math.min(C,S):C,a[u]=Math.min(m,x)}e.nb_2[o][u]=e.nb_1[o][u],e.nb_1[o][u]=m,p=s[u],p*=e.minval_l[u],p*=h,a[u]>p&&(a[u]=p),e.masking_lower>1&&(a[u]*=e.masking_lower),a[u]>n[u]&&(a[u]=n[u]),e.masking_lower<1&&(a[u]*=e.masking_lower),sl(a[u]>=0)}for(;u<W.CBANDS;++u)n[u]=0,a[u]=0}function _e(e,t){var n=e.internal_flags;e.short_blocks==tl.short_block_coupled&&(t[0]==0||t[1]==0)&&(t[0]=t[1]=0);for(var r=0;r<n.channels_out;r++)e.short_blocks==tl.short_block_dispensed&&(t[r]=1),e.short_blocks==tl.short_block_forced&&(t[r]=0)}function ve(e,t,n){for(var r=e.internal_flags,i=0;i<r.channels_out;i++){var a=W.NORM_TYPE;t[i]==0?(a=W.SHORT_TYPE,r.blocktype_old[i]==W.NORM_TYPE&&(r.blocktype_old[i]=W.START_TYPE),r.blocktype_old[i]==W.STOP_TYPE&&(r.blocktype_old[i]=W.SHORT_TYPE)):(sl(r.blocktype_old[i]!=W.START_TYPE),r.blocktype_old[i]==W.SHORT_TYPE&&(a=W.STOP_TYPE)),n[i]=r.blocktype_old[i],r.blocktype_old[i]=a}}function ye(e,t,n,r,i,a,o){for(var s=a*2,c=a>0?10**i:1,l,u,d=0;d<o;++d){var f=e[2][d],p=e[3][d],m=t[0][d],h=t[1][d],g=t[2][d],_=t[3][d];if(m<=1.58*h&&h<=1.58*m){var v=n[d]*p,y=n[d]*f;u=Math.max(g,Math.min(_,v)),l=Math.max(_,Math.min(g,y))}else u=g,l=_;if(a>0){var b,x,S=r[d]*c;if(b=Math.min(Math.max(m,S),Math.max(h,S)),g=Math.max(u,S),_=Math.max(l,S),x=g+_,x>0&&b*s<x){var C=b*s/x;g*=C,_*=C}u=Math.min(g,u),l=Math.min(_,l)}u>f&&(u=f),l>p&&(l=p),t[2][d]=u,t[3][d]=l}}this.L3psycho_anal_vbr=function(t,n,r,i,a,o,s,c,l,p){var m=t.internal_flags,h,g,_=il(W.HBLKSIZE),v=al([3,W.HBLKSIZE_s]),y=al([2,W.BLKSIZE]),b=al([2,3,W.BLKSIZE_s]),x=al([4,W.CBANDS]),S=al([4,W.CBANDS]),C=al([4,3]),w=.6,T=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,0]],E=ol(2),D=t.mode==e.JOINT_STEREO?4:m.channels_out;de(t,n,r,i,a,o,l,C,T,E),_e(t,E);for(var O=0;O<D;O++){var k=O&1;h=y,se(t,n,r,O,i,_,h,k),le(t,i,O,_),E[k]==0?pe(m,O):ge(m,_,x[O],S[O],O)}E[0]+E[1]==2&&t.mode==e.JOINT_STEREO&&ye(x,S,m.mld_cb_l,m.ATH.cb_l,t.ATHlower*m.ATH.adjust,t.msfix,m.npart_l);for(var O=0;O<D;O++){var k=O&1;E[k]!=0&&I(m,x[O],S[O],O)}for(var A=0;A<3;A++){for(var O=0;O<D;++O){var k=O&1;E[k]==0?(g=b,ce(t,n,r,O,A,v,g,k),he(t,v,x[O],S[O],O,A)):fe(m,O,A)}E[0]+E[1]==0&&t.mode==e.JOINT_STEREO&&ye(x,S,m.mld_cb_s,m.ATH.cb_s,t.ATHlower*m.ATH.adjust,t.msfix,m.npart_s);for(var O=0;O<D;++O){var k=O&1;E[k]==0&&F(m,x[O],S[O],O,A)}}for(var O=0;O<D;O++){var k=O&1;if(E[k]==0)for(var j=0;j<W.SBMAX_s;j++){for(var M=il(3),A=0;A<3;A++){var N=m.thm[O].s[j][A];if(N*=u,T[O][A]>=2||T[O][A+1]==1){var P=A==0?2:A-1,ee=L(m.thm[O].s[j][P],N,d*w);N=Math.min(N,ee)}else if(T[O][A]==1){var P=A==0?2:A-1,ee=L(m.thm[O].s[j][P],N,f*w);N=Math.min(N,ee)}else if(A!=0&&T[O][A-1]==3||A==0&&m.nsPsy.lastAttacks[O]==3){var P=A==2?0:A+1,ee=L(m.thm[O].s[j][P],N,f*w);N=Math.min(N,ee)}N*=C[O][A],M[A]=N}for(var A=0;A<3;A++)m.thm[O].s[j][A]=M[A]}}for(var O=0;O<D;O++)m.nsPsy.lastAttacks[O]=T[O][2];ve(t,E,p);for(var O=0;O<D;O++){var te,R,z,ie;O>1?(te=c,R=-2,z=W.NORM_TYPE,(p[0]==W.SHORT_TYPE||p[1]==W.SHORT_TYPE)&&(z=W.SHORT_TYPE),ie=o[i][O-2]):(te=s,R=0,z=p[O],ie=a[i][O]),z==W.SHORT_TYPE?te[R+O]=ne(ie,m.masking_lower):te[R+O]=re(ie,m.masking_lower),t.analysis&&(m.pinfo.pe[i][O]=te[R+O])}return 0};function be(e,t){var n=e,r=n>=0?-n*27:n*t;return r<=-72?0:Math.exp(r*h)}function xe(e){var t=0,n=0,r=0,i,a;for(r=0;be(r,e)>1e-20;--r);for(i=r,a=0;Math.abs(a-i)>1e-12;)r=(a+i)/2,be(r,e)>0?a=r:i=r;t=i;var r=0,i,a;for(r=0;be(r,e)>1e-20;r+=1);for(i=0,a=r;Math.abs(a-i)>1e-12;)r=(a+i)/2,be(r,e)>0?i=r:a=r;n=a;for(var o=0,s=1e3,c=0;c<=s;++c){var r=t+c*(n-t)/s,l=be(r,e);o+=l}return(s+1)/(o*(n-t))}function Se(e){var t=e,n,r,i;return t*=t>=0?3:1.5,t>=.5&&t<=2.5?(i=t-.5,n=8*(i*i-2*i)):n=0,t+=.474,r=15.811389+7.5*t-17.5*Math.sqrt(1+t*t),r<=-60?0:(t=Math.exp((n+r)*h),t/=.6609193,t)}function Ce(e){return e<0&&(e=0),e*=.001,13*Math.atan(.76*e)+3.5*Math.atan(e*e/56.25)}function we(e,t,n,r,i,a,o,c,l,u,d,f){var p=il(W.CBANDS+1),m=c/(f>15?1152:384),h=ol(W.HBLKSIZE),g;c/=l;var _=0,v=0;for(g=0;g<W.CBANDS;g++){var y=Ce(c*_),b;for(p[g]=c*_,b=_;Ce(c*b)-y<s&&b<=l/2;b++);for(e[g]=b-_,v=g+1;_<b;)sl(_<W.HBLKSIZE),h[_++]=g;if(_>l/2){_=l/2,++g;break}}sl(g<W.CBANDS),p[g]=c*_;for(var x=0;x<f;x++){var S,C,w=u[x],T=u[x+1],E;S=0|Math.floor(.5+d*(w-.5)),S<0&&(S=0),C=0|Math.floor(.5+d*(T-.5)),C>l/2&&(C=l/2),n[x]=(h[S]+h[C])/2,t[x]=h[C];var D=m*T;o[x]=(D-p[t[x]])/(p[t[x]+1]-p[t[x]]),o[x]<0?o[x]=0:o[x]>1&&(o[x]=1),E=Ce(c*u[x]*d),E=Math.min(E,15.5)/15.5,a[x]=10**(1.25*(1-Math.cos(Math.PI*E))-2.5)}_=0;for(var O=0;O<v;O++){var k=e[O],y=Ce(c*_),A=Ce(c*(_+k-1));r[O]=.5*(y+A),y=Ce(c*(_-.5)),A=Ce(c*(_+k-.5)),i[O]=A-y,_+=k}return v}function Te(e,t,n,r,i,a){var o=al([W.CBANDS,W.CBANDS]),s,c=0;if(a)for(var l=0;l<t;l++)for(s=0;s<t;s++){var u=Se(n[l]-n[s])*r[s];o[l][s]=u*i[l]}else for(s=0;s<t;s++)for(var d=15+Math.min(21/n[s],12),f=xe(d),l=0;l<t;l++){var u=f*be(n[l]-n[s],d)*r[s];o[l][s]=u*i[l]}for(var l=0;l<t;l++){for(s=0;s<t&&!(o[l][s]>0);s++);for(e[l][0]=s,s=t-1;s>0&&!(o[l][s]>0);s--);e[l][1]=s,c+=e[l][1]-e[l][0]+1}for(var p=il(c),m=0,l=0;l<t;l++)for(s=e[l][0];s<=e[l][1];s++)p[m++]=o[l][s];return p}function Ee(e){var t=Ce(e);return t=Math.min(t,15.5)/15.5,10**(1.25*(1-Math.cos(Math.PI*t))-2.5)}this.psymodel_init=function(e){var r=e.internal_flags,i,a=!0,o=13,s=24,c=0,u=0,d=-8.25,f=-4.5,m=il(W.CBANDS),h=il(W.CBANDS),g=il(W.CBANDS),_=e.out_samplerate;switch(e.experimentalZ){default:case 0:a=!0;break;case 1:a=e.VBR!=$c.vbr_mtrh&&e.VBR!=$c.vbr_mt;break;case 2:a=!1;break;case 3:o=8,c=-1.75,u=-.0125,d=-8.25,f=-2.25}for(r.ms_ener_ratio_old=.25,r.blocktype_old[0]=r.blocktype_old[1]=W.NORM_TYPE,i=0;i<4;++i){for(var v=0;v<W.CBANDS;++v)r.nb_1[i][v]=0x56bc75e2d63100000,r.nb_2[i][v]=0x56bc75e2d63100000,r.nb_s1[i][v]=r.nb_s2[i][v]=1;for(var y=0;y<W.SBMAX_l;y++)r.en[i].l[y]=0x56bc75e2d63100000,r.thm[i].l[y]=0x56bc75e2d63100000;for(var v=0;v<3;++v){for(var y=0;y<W.SBMAX_s;y++)r.en[i].s[y][v]=0x56bc75e2d63100000,r.thm[i].s[y][v]=0x56bc75e2d63100000;r.nsPsy.lastAttacks[i]=0}for(var v=0;v<9;v++)r.nsPsy.last_en_subshort[i][v]=10}for(r.loudness_sq_save[0]=r.loudness_sq_save[1]=0,r.npart_l=we(r.numlines_l,r.bo_l,r.bm_l,m,h,r.mld_l,r.PSY.bo_l_weight,_,W.BLKSIZE,r.scalefac_band.l,W.BLKSIZE/1152,W.SBMAX_l),sl(r.npart_l<W.CBANDS),i=0;i<r.npart_l;i++){var b=c;m[i]>=o&&(b=u*(m[i]-o)/(s-o)+c*(s-m[i])/(s-o)),g[i]=10**(b/10),r.numlines_l[i]>0?r.rnumlines_l[i]=1/r.numlines_l[i]:r.rnumlines_l[i]=0}r.s3_ll=Te(r.s3ind,r.npart_l,m,h,g,a);var v=0;for(i=0;i<r.npart_l;i++){for(var x=el.MAX_VALUE,S=0;S<r.numlines_l[i];S++,v++){var C=_*v/(1e3*W.BLKSIZE),w=this.ATHformula(C*1e3,e)-20;w=10**(.1*w),w*=r.numlines_l[i],x>w&&(x=w)}r.ATH.cb_l[i]=x,x=-20+m[i]*20/10,x>6&&(x=100),x<-15&&(x=-15),x-=8,r.minval_l[i]=10**(x/10)*r.numlines_l[i]}for(r.npart_s=we(r.numlines_s,r.bo_s,r.bm_s,m,h,r.mld_s,r.PSY.bo_s_weight,_,W.BLKSIZE_s,r.scalefac_band.s,W.BLKSIZE_s/384,W.SBMAX_s),sl(r.npart_s<W.CBANDS),v=0,i=0;i<r.npart_s;i++){var x,b=d;m[i]>=o&&(b=f*(m[i]-o)/(s-o)+d*(s-m[i])/(s-o)),g[i]=10**(b/10),x=el.MAX_VALUE;for(var S=0;S<r.numlines_s[i];S++,v++){var C=_*v/(1e3*W.BLKSIZE_s),w=this.ATHformula(C*1e3,e)-20;w=10**(.1*w),w*=r.numlines_s[i],x>w&&(x=w)}r.ATH.cb_s[i]=x,x=-7+m[i]*7/12,m[i]>12&&(x*=1+Math.log(1+x)*3.1),m[i]<12&&(x*=1+Math.log(1-x)*2.3),x<-15&&(x=-15),x-=8,r.minval_s[i]=10**(x/10)*r.numlines_s[i]}r.s3_ss=Te(r.s3ind_s,r.npart_s,m,h,g,a),T(),t.init_fft(r),r.decay=Math.exp(-1*n/(l*_/192));var E=p;e.exp_nspsytune&2&&(E=1),Math.abs(e.msfix)>0&&(E=e.msfix),e.msfix=E;for(var D=0;D<r.npart_l;D++)r.s3ind[D][1]>r.npart_l-1&&(r.s3ind[D][1]=r.npart_l-1);var O=576*r.mode_gr/_;if(r.ATH.decay=10**(-12/10*O),r.ATH.adjust=.01,r.ATH.adjustLimit=1,sl(r.bo_l[W.SBMAX_l-1]<=r.npart_l),sl(r.bo_s[W.SBMAX_s-1]<=r.npart_s),e.ATHtype!=-1){var C,k=e.out_samplerate/W.BLKSIZE,A=0;for(C=0,i=0;i<W.BLKSIZE/2;++i)C+=k,r.ATH.eql_w[i]=1/10**(this.ATHformula(C,e)/10),A+=r.ATH.eql_w[i];for(A=1/A,i=W.BLKSIZE/2;--i>=0;)r.ATH.eql_w[i]*=A}for(var D=v=0;D<r.npart_s;++D)for(i=0;i<r.numlines_s[D];++i)++v;for(var D=v=0;D<r.npart_l;++D)for(i=0;i<r.numlines_l[D];++i)++v;for(v=0,i=0;i<r.npart_l;i++){var C=_*(v+r.numlines_l[i]/2)/(1*W.BLKSIZE);r.mld_cb_l[i]=Ee(C),v+=r.numlines_l[i]}for(;i<W.CBANDS;++i)r.mld_cb_l[i]=1;for(v=0,i=0;i<r.npart_s;i++){var C=_*(v+r.numlines_s[i]/2)/(1*W.BLKSIZE_s);r.mld_cb_s[i]=Ee(C),v+=r.numlines_s[i]}for(;i<W.CBANDS;++i)r.mld_cb_s[i]=1;return 0};function De(e,t){return e<-.3&&(e=3410),e/=1e3,e=Math.max(.1,e),3.64*e**-.8-6.8*Math.exp(-.6*(e-3.4)**2)+6*Math.exp(-.15*(e-8.7)**2)+(.6+.04*t)*.001*e**4}this.ATHformula=function(e,t){var n;switch(t.ATHtype){case 0:n=De(e,9);break;case 1:n=De(e,-1);break;case 2:n=De(e,0);break;case 3:n=De(e,1)+6;break;case 4:n=De(e,t.ATHcurve);break;default:n=De(e,0)}return n}}function $s(){this.class_id=0,this.num_samples=0,this.num_channels=0,this.in_samplerate=0,this.out_samplerate=0,this.scale=0,this.scale_left=0,this.scale_right=0,this.analysis=!1,this.bWriteVbrTag=!1,this.decode_only=!1,this.quality=0,this.mode=ul.STEREO,this.force_ms=!1,this.free_format=!1,this.findReplayGain=!1,this.decode_on_the_fly=!1,this.write_id3tag_automatic=!1,this.brate=0,this.compression_ratio=0,this.copyright=0,this.original=0,this.extension=0,this.emphasis=0,this.error_protection=0,this.strict_ISO=!1,this.disable_reservoir=!1,this.quant_comp=0,this.quant_comp_short=0,this.experimentalY=!1,this.experimentalZ=0,this.exp_nspsytune=0,this.preset=0,this.VBR=null,this.VBR_q_frac=0,this.VBR_q=0,this.VBR_mean_bitrate_kbps=0,this.VBR_min_bitrate_kbps=0,this.VBR_max_bitrate_kbps=0,this.VBR_hard_min=0,this.lowpassfreq=0,this.highpassfreq=0,this.lowpasswidth=0,this.highpasswidth=0,this.maskingadjust=0,this.maskingadjust_short=0,this.ATHonly=!1,this.ATHshort=!1,this.noATH=!1,this.ATHtype=0,this.ATHcurve=0,this.ATHlower=0,this.athaa_type=0,this.athaa_loudapprox=0,this.athaa_sensitivity=0,this.short_blocks=null,this.useTemporal=!1,this.interChRatio=0,this.msfix=0,this.tune=!1,this.tune_value_a=0,this.version=0,this.encoder_delay=0,this.encoder_padding=0,this.framesize=0,this.frameNum=0,this.lame_allocated_gfp=0,this.internal_flags=null}function ec(){this.xr=gl(576),this.l3_enc=_l(576),this.scalefac=_l(vl.SFBMAX),this.xrpow_max=0,this.part2_3_length=0,this.big_values=0,this.count1=0,this.global_gain=0,this.scalefac_compress=0,this.block_type=0,this.mixed_block_flag=0,this.table_select=_l(3),this.subblock_gain=_l(4),this.region0_count=0,this.region1_count=0,this.preflag=0,this.scalefac_scale=0,this.count1table_select=0,this.part2_length=0,this.sfb_lmax=0,this.sfb_smin=0,this.psy_lmax=0,this.sfbmax=0,this.psymax=0,this.sfbdivide=0,this.width=_l(vl.SFBMAX),this.window=_l(vl.SFBMAX),this.count1bits=0,this.sfb_partition_table=null,this.slen=_l(4),this.max_nonzero_coeff=0;var e=this;function t(e){return new Int32Array(e)}function n(e){return new Float32Array(e)}this.assign=function(r){e.xr=n(r.xr),e.l3_enc=t(r.l3_enc),e.scalefac=t(r.scalefac),e.xrpow_max=r.xrpow_max,e.part2_3_length=r.part2_3_length,e.big_values=r.big_values,e.count1=r.count1,e.global_gain=r.global_gain,e.scalefac_compress=r.scalefac_compress,e.block_type=r.block_type,e.mixed_block_flag=r.mixed_block_flag,e.table_select=t(r.table_select),e.subblock_gain=t(r.subblock_gain),e.region0_count=r.region0_count,e.region1_count=r.region1_count,e.preflag=r.preflag,e.scalefac_scale=r.scalefac_scale,e.count1table_select=r.count1table_select,e.part2_length=r.part2_length,e.sfb_lmax=r.sfb_lmax,e.sfb_smin=r.sfb_smin,e.psy_lmax=r.psy_lmax,e.sfbmax=r.sfbmax,e.psymax=r.psymax,e.sfbdivide=r.sfbdivide,e.width=t(r.width),e.window=t(r.window),e.count1bits=r.count1bits,e.sfb_partition_table=r.sfb_partition_table.slice(0),e.slen=t(r.slen),e.max_nonzero_coeff=r.max_nonzero_coeff}}function tc(){this.tt=[[null,null],[null,null]],this.main_data_begin=0,this.private_bits=0,this.resvDrain_pre=0,this.resvDrain_post=0,this.scfsi=[bl(4),bl(4)];for(var e=0;e<2;e++)for(var t=0;t<2;t++)this.tt[e][t]=new xl}function nc(e,t,n,r){this.l=Tl(1+El.SBMAX_l),this.s=Tl(1+El.SBMAX_s),this.psfb21=Tl(1+El.PSFB21),this.psfb12=Tl(1+El.PSFB12);var i=this.l,a=this.s;arguments.length==4&&(this.arrL=arguments[0],this.arrS=arguments[1],this.arr21=arguments[2],this.arr12=arguments[3],wl.arraycopy(this.arrL,0,i,0,Math.min(this.arrL.length,this.l.length)),wl.arraycopy(this.arrS,0,a,0,Math.min(this.arrS.length,this.s.length)),wl.arraycopy(this.arr21,0,this.psfb21,0,Math.min(this.arr21.length,this.psfb21.length)),wl.arraycopy(this.arr12,0,this.psfb12,0,Math.min(this.arr12.length,this.psfb12.length)))}function rc(){this.last_en_subshort=Al([4,9]),this.lastAttacks=jl(4),this.pefirbuf=kl(19),this.longfact=kl(Ml.SBMAX_l),this.shortfact=kl(Ml.SBMAX_s),this.attackthre=0,this.attackthre_s=0}function ic(){this.sum=0,this.seen=0,this.want=0,this.pos=0,this.size=0,this.bag=null,this.nVbrNumFrames=0,this.nBytesWritten=0,this.TotalFrameSize=0}function ac(){this.Class_ID=0,this.lame_encode_frame_init=0,this.iteration_init_init=0,this.fill_buffer_resample_init=0,this.mfbuf=zl([2,ac.MFSIZE]),this.mode_gr=0,this.channels_in=0,this.channels_out=0,this.resample_ratio=0,this.mf_samples_to_encode=0,this.mf_size=0,this.VBR_min_bitrate=0,this.VBR_max_bitrate=0,this.bitrate_index=0,this.samplerate_index=0,this.mode_ext=0,this.lowpass1=0,this.lowpass2=0,this.highpass1=0,this.highpass2=0,this.noise_shaping=0,this.noise_shaping_amp=0,this.substep_shaping=0,this.psymodel=0,this.noise_shaping_stop=0,this.subblock_gain=0,this.use_best_huffman=0,this.full_outer_loop=0,this.l3_side=new Hl,this.ms_ratio=Rl(2),this.padding=0,this.frac_SpF=0,this.slot_lag=0,this.tag_spec=null,this.nMusicCRC=0,this.OldValue=Bl(2),this.CurrentStep=Bl(2),this.masking_lower=0,this.bv_scf=Bl(576),this.pseudohalf=Bl(Jl.SFBMAX),this.sfb21_extra=!1,this.inbuf_old=[,,],this.blackfilt=Array(2*ac.BPC+1),this.itime=Ll(2),this.sideinfo_len=0,this.sb_sample=zl([2,2,18,ql.SBLIMIT]),this.amp_filter=Rl(32);function e(){this.write_timing=0,this.ptr=0,this.buf=Il(40)}this.header=Array(ac.MAX_HEADER_BUF),this.h_ptr=0,this.w_ptr=0,this.ancillary_flag=0,this.ResvSize=0,this.ResvMax=0,this.scalefac_band=new Ul,this.minval_l=Rl(ql.CBANDS),this.minval_s=Rl(ql.CBANDS),this.nb_1=zl([4,ql.CBANDS]),this.nb_2=zl([4,ql.CBANDS]),this.nb_s1=zl([4,ql.CBANDS]),this.nb_s2=zl([4,ql.CBANDS]),this.s3_ss=null,this.s3_ll=null,this.decay=0,this.thm=[,,,,],this.en=[,,,,],this.tot_ener=Rl(4),this.loudness_sq=zl([2,2]),this.loudness_sq_save=Rl(2),this.mld_l=Rl(ql.SBMAX_l),this.mld_s=Rl(ql.SBMAX_s),this.bm_l=Bl(ql.SBMAX_l),this.bo_l=Bl(ql.SBMAX_l),this.bm_s=Bl(ql.SBMAX_s),this.bo_s=Bl(ql.SBMAX_s),this.npart_l=0,this.npart_s=0,this.s3ind=Vl([ql.CBANDS,2]),this.s3ind_s=Vl([ql.CBANDS,2]),this.numlines_s=Bl(ql.CBANDS),this.numlines_l=Bl(ql.CBANDS),this.rnumlines_l=Rl(ql.CBANDS),this.mld_cb_l=Rl(ql.CBANDS),this.mld_cb_s=Rl(ql.CBANDS),this.numlines_s_num1=0,this.numlines_l_num1=0,this.pe=Rl(4),this.ms_ratio_s_old=0,this.ms_ratio_l_old=0,this.ms_ener_ratio_old=0,this.blocktype_old=Bl(2),this.nsPsy=new Wl,this.VBR_seek_table=new Gl,this.ATH=null,this.PSY=null,this.nogap_total=0,this.nogap_current=0,this.decode_on_the_fly=!0,this.findReplayGain=!0,this.findPeakSample=!0,this.PeakSample=0,this.RadioGain=0,this.AudiophileGain=0,this.rgdata=null,this.noclipGainChange=0,this.noclipScale=0,this.bitrate_stereoMode_Hist=Vl([16,5]),this.bitrate_blockType_Hist=Vl([16,6]),this.pinfo=null,this.hip=null,this.in_buffer_nsamples=0,this.in_buffer_0=null,this.in_buffer_1=null,this.iteration_loop=null;for(var t=0;t<this.en.length;t++)this.en[t]=new Kl;for(var t=0;t<this.thm.length;t++)this.thm[t]=new Kl;for(var t=0;t<this.header.length;t++)this.header[t]=new e}function oc(){this.useAdjust=0,this.aaSensitivityP=0,this.adjust=0,this.adjustLimit=0,this.decay=0,this.floor=0,this.l=Xl(Zl.SBMAX_l),this.s=Xl(Zl.SBMAX_s),this.psfb21=Xl(Zl.PSFB21),this.psfb12=Xl(Zl.PSFB12),this.cb_l=Xl(Zl.CBANDS),this.cb_s=Xl(Zl.CBANDS),this.eql_w=Xl(Zl.BLKSIZE/2)}function sc(){var e=sc.RMS_WINDOW_TIME_NUMERATOR,t=sc.RMS_WINDOW_TIME_DENOMINATOR,n=[[.038575994352,-3.84664617118067,-.02160367184185,7.81501653005538,-.00123395316851,-11.34170355132042,-9291677959e-14,13.05504219327545,-.01655260341619,-12.28759895145294,.02161526843274,9.4829380631979,-.02074045215285,-5.87257861775999,.00594298065125,2.75465861874613,.00306428023191,-.86984376593551,.00012025322027,.13919314567432,.00288463683916],[.0541865640643,-3.47845948550071,-.02911007808948,6.36317777566148,-.00848709379851,-8.54751527471874,-.00851165645469,9.4769360780128,-.00834990904936,-8.81498681370155,.02245293253339,6.85401540936998,-.02596338512915,-4.39470996079559,.01624864962975,2.19611684890774,-.00240879051584,-.75104302451432,.00674613682247,.13149317958808,-.00187763777362],[.15457299681924,-2.37898834973084,-.09331049056315,2.84868151156327,-.06247880153653,-2.64577170229825,.02163541888798,2.23697657451713,-.05588393329856,-1.67148153367602,.04781476674921,1.00595954808547,.00222312597743,-.45953458054983,.03174092540049,.16378164858596,-.01390589421898,-.05032077717131,.00651420667831,.0234789740702,-.00881362733839],[.30296907319327,-1.61273165137247,-.22613988682123,1.0797749225997,-.08587323730772,-.2565625775407,.03282930172664,-.1627671912044,-.00915702933434,-.22638893773906,-.02364141202522,.39120800788284,-.00584456039913,-.22138138954925,.06276101321749,.04500235387352,-828086748e-14,.02005851806501,.00205861885564,.00302439095741,-.02950134983287],[.33642304856132,-1.49858979367799,-.2557224142557,.87350271418188,-.11828570177555,.12205022308084,.11921148675203,-.80774944671438,-.07834489609479,.47854794562326,-.0046997791438,-.12453458140019,-.0058950022444,-.04067510197014,.05724228140351,.08333755284107,.00832043980773,-.04237348025746,-.0163538138454,.02977207319925,-.0176017656815],[.4491525660845,-.62820619233671,-.14351757464547,.29661783706366,-.22784394429749,-.372563729424,-.01419140100551,.00213767857124,.04078262797139,-.42029820170918,-.12398163381748,.22199650564824,.04097565135648,.00613424350682,.10478503600251,.06747620744683,-.01863887810927,.05784820375801,-.03193428438915,.03222754072173,.00541907748707],[.56619470757641,-1.04800335126349,-.75464456939302,.29156311971249,.1624213774223,-.26806001042947,.16744243493672,.00819999645858,-.18901604199609,.45054734505008,.3093178284183,-.33032403314006,-.27562961986224,.0673936833311,.00647310677246,-.04784254229033,.08647503780351,.01639907836189,-.0378898455484,.01807364323573,-.00588215443421],[.58100494960553,-.51035327095184,-.53174909058578,-.31863563325245,-.14289799034253,-.20256413484477,.17520704835522,.1472815413433,.02377945217615,.38952639978999,.15558449135573,-.23313271880868,-.25344790059353,-.05246019024463,.01628462406333,-.02505961724053,.06920467763959,.02442357316099,-.03721611395801,.01818801111503,-.00749618797172],[.53648789255105,-.2504987195602,-.42163034350696,-.43193942311114,-.00275953611929,-.03424681017675,.04267842219415,-.04678328784242,-.10214864179676,.26408300200955,.14590772289388,.15113130533216,-.02459864859345,-.17556493366449,-.11202315195388,-.18823009262115,-.04060034127,.05477720428674,.0478866554818,.0470440968812,-.02217936801134]],r=[[.98621192462708,-1.97223372919527,-1.97242384925416,.97261396931306,.98621192462708],[.98500175787242,-1.96977855582618,-1.97000351574484,.9702284756635,.98500175787242],[.97938932735214,-1.95835380975398,-1.95877865470428,.95920349965459,.97938932735214],[.97531843204928,-1.95002759149878,-1.95063686409857,.95124613669835,.97531843204928],[.97316523498161,-1.94561023566527,-1.94633046996323,.94705070426118,.97316523498161],[.96454515552826,-1.92783286977036,-1.92909031105652,.93034775234268,.96454515552826],[.96009142950541,-1.91858953033784,-1.92018285901082,.92177618768381,.96009142950541],[.95856916599601,-1.9154210807478,-1.91713833199203,.91885558323625,.95856916599601],[.94597685600279,-1.88903307939452,-1.89195371200558,.89487434461664,.94597685600279]];function i(e,t,n,r,i,a){for(;i--!=0;)n[r]=1e-10+e[t+0]*a[0]-n[r-1]*a[1]+e[t-1]*a[2]-n[r-2]*a[3]+e[t-2]*a[4]-n[r-3]*a[5]+e[t-3]*a[6]-n[r-4]*a[7]+e[t-4]*a[8]-n[r-5]*a[9]+e[t-5]*a[10]-n[r-6]*a[11]+e[t-6]*a[12]-n[r-7]*a[13]+e[t-7]*a[14]-n[r-8]*a[15]+e[t-8]*a[16]-n[r-9]*a[17]+e[t-9]*a[18]-n[r-10]*a[19]+e[t-10]*a[20],++r,++t}function a(e,t,n,r,i,a){for(;i--!=0;)n[r]=e[t+0]*a[0]-n[r-1]*a[1]+e[t-1]*a[2]-n[r-2]*a[3]+e[t-2]*a[4],++r,++t}function o(n,r){for(var i=0;i<MAX_ORDER;i++)n.linprebuf[i]=n.lstepbuf[i]=n.loutbuf[i]=n.rinprebuf[i]=n.rstepbuf[i]=n.routbuf[i]=0;switch(0|r){case 48e3:n.reqindex=0;break;case 44100:n.reqindex=1;break;case 32e3:n.reqindex=2;break;case 24e3:n.reqindex=3;break;case 22050:n.reqindex=4;break;case 16e3:n.reqindex=5;break;case 12e3:n.reqindex=6;break;case 11025:n.reqindex=7;break;case 8e3:n.reqindex=8;break;default:return INIT_GAIN_ANALYSIS_ERROR}return n.sampleWindow=0|(r*e+t-1)/t,n.lsum=0,n.rsum=0,n.totsamp=0,tu.ill(n.A,0),INIT_GAIN_ANALYSIS_OK}this.InitGainAnalysis=function(e,t){return o(e,t)==INIT_GAIN_ANALYSIS_OK?(e.linpre=MAX_ORDER,e.rinpre=MAX_ORDER,e.lstep=MAX_ORDER,e.rstep=MAX_ORDER,e.lout=MAX_ORDER,e.rout=MAX_ORDER,tu.fill(e.B,0),INIT_GAIN_ANALYSIS_OK):INIT_GAIN_ANALYSIS_ERROR};function s(e){return e*e}this.AnalyzeSamples=function(e,t,o,c,l,u,d){var f,p,m,h,g,_,v;if(u==0)return GAIN_ANALYSIS_OK;switch(v=0,g=u,d){case 1:c=t,l=o;break;case 2:break;default:return GAIN_ANALYSIS_ERROR}for(u<MAX_ORDER?(eu.arraycopy(t,o,e.linprebuf,MAX_ORDER,u),eu.arraycopy(c,l,e.rinprebuf,MAX_ORDER,u)):(eu.arraycopy(t,o,e.linprebuf,MAX_ORDER,MAX_ORDER),eu.arraycopy(c,l,e.rinprebuf,MAX_ORDER,MAX_ORDER));g>0;){_=g>e.sampleWindow-e.totsamp?e.sampleWindow-e.totsamp:g,v<MAX_ORDER?(f=e.linpre+v,p=e.linprebuf,m=e.rinpre+v,h=e.rinprebuf,_>MAX_ORDER-v&&(_=MAX_ORDER-v)):(f=o+v,p=t,m=l+v,h=c),i(p,f,e.lstepbuf,e.lstep+e.totsamp,_,n[e.reqindex]),i(h,m,e.rstepbuf,e.rstep+e.totsamp,_,n[e.reqindex]),a(e.lstepbuf,e.lstep+e.totsamp,e.loutbuf,e.lout+e.totsamp,_,r[e.reqindex]),a(e.rstepbuf,e.rstep+e.totsamp,e.routbuf,e.rout+e.totsamp,_,r[e.reqindex]),f=e.lout+e.totsamp,p=e.loutbuf,m=e.rout+e.totsamp,h=e.routbuf;for(var y=_%8;y--!=0;)e.lsum+=s(p[f++]),e.rsum+=s(h[m++]);for(y=_/8;y--!=0;)e.lsum+=s(p[f+0])+s(p[f+1])+s(p[f+2])+s(p[f+3])+s(p[f+4])+s(p[f+5])+s(p[f+6])+s(p[f+7]),f+=8,e.rsum+=s(h[m+0])+s(h[m+1])+s(h[m+2])+s(h[m+3])+s(h[m+4])+s(h[m+5])+s(h[m+6])+s(h[m+7]),m+=8;if(g-=_,v+=_,e.totsamp+=_,e.totsamp==e.sampleWindow){var b=sc.STEPS_per_dB*10*Math.log10((e.lsum+e.rsum)/e.totsamp*.5+1e-37),x=b<=0?0:0|b;x>=e.A.length&&(x=e.A.length-1),e.A[x]++,e.lsum=e.rsum=0,eu.arraycopy(e.loutbuf,e.totsamp,e.loutbuf,0,MAX_ORDER),eu.arraycopy(e.routbuf,e.totsamp,e.routbuf,0,MAX_ORDER),eu.arraycopy(e.lstepbuf,e.totsamp,e.lstepbuf,0,MAX_ORDER),eu.arraycopy(e.rstepbuf,e.totsamp,e.rstepbuf,0,MAX_ORDER),e.totsamp=0}if(e.totsamp>e.sampleWindow)return GAIN_ANALYSIS_ERROR}return u<MAX_ORDER?(eu.arraycopy(e.linprebuf,u,e.linprebuf,0,MAX_ORDER-u),eu.arraycopy(e.rinprebuf,u,e.rinprebuf,0,MAX_ORDER-u),eu.arraycopy(t,o,e.linprebuf,MAX_ORDER-u,u),eu.arraycopy(c,l,e.rinprebuf,MAX_ORDER-u,u)):(eu.arraycopy(t,o+u-MAX_ORDER,e.linprebuf,0,MAX_ORDER),eu.arraycopy(c,l+u-MAX_ORDER,e.rinprebuf,0,MAX_ORDER)),GAIN_ANALYSIS_OK};function c(e,t){var n,r=0;for(n=0;n<t;n++)r+=e[n];if(r==0)return GAIN_NOT_ENOUGH_SAMPLES;var i=0|Math.ceil(r*.050000000000000044);for(n=t;n-->0&&!((i-=e[n])<=0););return 64.82-n/sc.STEPS_per_dB}this.GetTitleGain=function(e){for(var t=c(e.A,e.A.length),n=0;n<e.A.length;n++)e.B[n]+=e.A[n],e.A[n]=0;for(var n=0;n<MAX_ORDER;n++)e.linprebuf[n]=e.lstepbuf[n]=e.loutbuf[n]=e.rinprebuf[n]=e.rstepbuf[n]=e.routbuf[n]=0;return e.totsamp=0,e.lsum=e.rsum=0,t}}function cc(){this.linprebuf=iu(ou.MAX_ORDER*2),this.linpre=0,this.lstepbuf=iu(ou.MAX_SAMPLES_PER_WINDOW+ou.MAX_ORDER),this.lstep=0,this.loutbuf=iu(ou.MAX_SAMPLES_PER_WINDOW+ou.MAX_ORDER),this.lout=0,this.rinprebuf=iu(ou.MAX_ORDER*2),this.rinpre=0,this.rstepbuf=iu(ou.MAX_SAMPLES_PER_WINDOW+ou.MAX_ORDER),this.rstep=0,this.routbuf=iu(ou.MAX_SAMPLES_PER_WINDOW+ou.MAX_ORDER),this.rout=0,this.sampleWindow=0,this.totsamp=0,this.lsum=0,this.rsum=0,this.freqindex=0,this.first=0,this.A=au(0|ou.STEPS_per_dB*ou.MAX_dB),this.B=au(0|ou.STEPS_per_dB*ou.MAX_dB)}function lc(e){this.bits=e}function uc(e){var t=e;this.quantize=t,this.iteration_loop=function(e,t,n,r){var i=e.internal_flags,a=uu(hu.SFBMAX),o=uu(576),s=du(2),c=0,l,u=i.l3_side,d=new pu(c);this.quantize.rv.ResvFrameBegin(e,d),c=d.bits;for(var f=0;f<i.mode_gr;f++){l=this.quantize.qupvt.on_pe(e,t,s,c,f,f),i.mode_ext==mu.MPG_MD_MS_LR&&(this.quantize.ms_convert(i.l3_side,f),this.quantize.qupvt.reduce_side(s,n[f],c,l));for(var p=0;p<i.channels_out;p++){var m,h,g=u.tt[f][p];g.block_type==mu.SHORT_TYPE?(m=0,h=i.PSY.mask_adjust_short-m):(m=0,h=i.PSY.mask_adjust-m),i.masking_lower=10**(h*.1),this.quantize.init_outer_loop(i,g),this.quantize.init_xrpow(i,g,o)&&(this.quantize.qupvt.calc_xmin(e,r[f][p],g,a),this.quantize.outer_loop(e,g,a,o,p,s[p])),this.quantize.iteration_finish_one(i,f,p),fu(g.part2_3_length<=gu.MAX_BITS_PER_CHANNEL),fu(g.part2_3_length<=s[p])}}this.quantize.rv.ResvFrameEnd(i,c)}}function dc(e,t,n,r){this.xlen=e,this.linmax=t,this.table=n,this.hlen=r}function fc(){if(bu)return yu;bu=1;var e=Dl,t=Lc,n=t.VbrMode,r=t.Float,i=t.Util,a=t.new_float,o=t.new_int,s=t.assert,c=Xs(),l=cu,u=Yl;d.Q_MAX=257,d.Q_MAX2=116,d.LARGE_BITS=1e5,d.IXMAX_VAL=8206;function d(){var t=mc(),f=null,p=null,m=null;this.setModules=function(e,t,n){f=e,p=t,m=n};function h(e){return s(0<=e+d.Q_MAX2&&e<d.Q_MAX),S[e+d.Q_MAX2]}this.IPOW20=function(e){return s(0<=e&&e<d.Q_MAX),C[e]};var g=2220446049250313e-31,_=d.IXMAX_VAL+2,v=d.Q_MAX,y=d.Q_MAX2;d.LARGE_BITS;var b=100;this.nr_of_sfb_block=[[[6,5,5,5],[9,9,9,9],[6,9,9,9]],[[6,5,7,3],[9,9,12,6],[6,9,12,6]],[[11,10,0,0],[18,18,0,0],[15,18,0,0]],[[7,7,7,0],[12,12,12,0],[6,15,12,0]],[[6,6,6,3],[12,9,9,6],[6,12,9,6]],[[8,8,5,0],[15,12,9,0],[6,18,9,0]]];var x=[0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,2,2,3,3,3,2,0];this.pretab=x,this.sfBandIndex=[new e([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,24,32,42,56,74,100,132,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,6,12,18,24,30,36,44,54,66,80,96,114,136,162,194,232,278,332,394,464,540,576],[0,4,8,12,18,26,36,48,62,80,104,136,180,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,4,8,12,16,20,24,30,36,44,52,62,74,90,110,134,162,196,238,288,342,418,576],[0,4,8,12,16,22,30,40,52,66,84,106,136,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,4,8,12,16,20,24,30,36,42,50,60,72,88,106,128,156,190,230,276,330,384,576],[0,4,8,12,16,22,28,38,50,64,80,100,126,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,4,8,12,16,20,24,30,36,44,54,66,82,102,126,156,194,240,296,364,448,550,576],[0,4,8,12,16,22,30,42,58,78,104,138,180,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,6,12,18,24,30,36,44,54,66,80,96,116,140,168,200,238,284,336,396,464,522,576],[0,4,8,12,18,26,36,48,62,80,104,134,174,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0]),new e([0,12,24,36,48,60,72,88,108,132,160,192,232,280,336,400,476,566,568,570,572,574,576],[0,8,16,24,36,52,72,96,124,160,162,164,166,192],[0,0,0,0,0,0,0],[0,0,0,0,0,0,0])];var S=a(v+y+1),C=a(v),w=a(_),T=a(_);this.adj43=T;function E(e,t){var n=m.ATHformula(t,e);return n-=b,n=10**(n/10+e.ATHlower),n}function D(e){for(var t=e.internal_flags.ATH.l,n=e.internal_flags.ATH.psfb21,i=e.internal_flags.ATH.s,a=e.internal_flags.ATH.psfb12,o=e.internal_flags,s=e.out_samplerate,l=0;l<c.SBMAX_l;l++){var u=o.scalefac_band.l[l],d=o.scalefac_band.l[l+1];t[l]=r.MAX_VALUE;for(var f=u;f<d;f++){var p=f*s/1152,m=E(e,p);t[l]=Math.min(t[l],m)}}for(var l=0;l<c.PSFB21;l++){var u=o.scalefac_band.psfb21[l],d=o.scalefac_band.psfb21[l+1];n[l]=r.MAX_VALUE;for(var f=u;f<d;f++){var p=f*s/1152,m=E(e,p);n[l]=Math.min(n[l],m)}}for(var l=0;l<c.SBMAX_s;l++){var u=o.scalefac_band.s[l],d=o.scalefac_band.s[l+1];i[l]=r.MAX_VALUE;for(var f=u;f<d;f++){var p=f*s/384,m=E(e,p);i[l]=Math.min(i[l],m)}i[l]*=o.scalefac_band.s[l+1]-o.scalefac_band.s[l]}for(var l=0;l<c.PSFB12;l++){var u=o.scalefac_band.psfb12[l],d=o.scalefac_band.psfb12[l+1];a[l]=r.MAX_VALUE;for(var f=u;f<d;f++){var p=f*s/384,m=E(e,p);a[l]=Math.min(a[l],m)}a[l]*=o.scalefac_band.s[13]-o.scalefac_band.s[12]}if(e.noATH){for(var l=0;l<c.SBMAX_l;l++)t[l]=1e-20;for(var l=0;l<c.PSFB21;l++)n[l]=1e-20;for(var l=0;l<c.SBMAX_s;l++)i[l]=1e-20;for(var l=0;l<c.PSFB12;l++)a[l]=1e-20}o.ATH.floor=10*Math.log10(E(e,-1))}this.iteration_init=function(e){var t=e.internal_flags,n=t.l3_side,r;if(t.iteration_init_init==0){for(t.iteration_init_init=1,n.main_data_begin=0,D(e),w[0]=0,r=1;r<_;r++)w[r]=r**(4/3);for(r=0;r<_-1;r++)T[r]=r+1-(.5*(w[r]+w[r+1]))**.75;for(T[r]=.5,r=0;r<v;r++)C[r]=2**((r-210)*-.1875);for(r=0;r<=v+y;r++)S[r]=2**((r-210-y)*.25);f.huffman_init(t);var i,a,o,s;for(r=e.exp_nspsytune>>2&63,r>=32&&(r-=64),i=10**(r/4/10),r=e.exp_nspsytune>>8&63,r>=32&&(r-=64),a=10**(r/4/10),r=e.exp_nspsytune>>14&63,r>=32&&(r-=64),o=10**(r/4/10),r=e.exp_nspsytune>>20&63,r>=32&&(r-=64),s=o*10**(r/4/10),r=0;r<c.SBMAX_l;r++){var l=r<=6?i:r<=13?a:r<=20?o:s;t.nsPsy.longfact[r]=l}for(r=0;r<c.SBMAX_s;r++){var l=r<=5?i:r<=10?a:r<=11?o:s;t.nsPsy.shortfact[r]=l}}},this.on_pe=function(e,t,n,r,i,a){var s=e.internal_flags,c=0,d,f=o(2),m,h=new l(c),g=p.ResvMaxBits(e,r,h,a);c=h.bits;var _=c+g;for(_>u.MAX_BITS_PER_GRANULE&&(_=u.MAX_BITS_PER_GRANULE),d=0,m=0;m<s.channels_out;++m)n[m]=Math.min(u.MAX_BITS_PER_CHANNEL,c/s.channels_out),f[m]=0|n[m]*t[i][m]/700-n[m],f[m]>r*3/4&&(f[m]=r*3/4),f[m]<0&&(f[m]=0),f[m]+n[m]>u.MAX_BITS_PER_CHANNEL&&(f[m]=Math.max(0,u.MAX_BITS_PER_CHANNEL-n[m])),d+=f[m];if(d>g)for(m=0;m<s.channels_out;++m)f[m]=g*f[m]/d;for(m=0;m<s.channels_out;++m)n[m]+=f[m],g-=f[m];for(d=0,m=0;m<s.channels_out;++m)d+=n[m];if(d>u.MAX_BITS_PER_GRANULE){var v=0;for(m=0;m<s.channels_out;++m)n[m]*=u.MAX_BITS_PER_GRANULE,n[m]/=d,v+=n[m]}return _},this.reduce_side=function(e,t,n,r){s(e[0]+e[1]<=u.MAX_BITS_PER_GRANULE);var i=.33*(.5-t)/.5;i<0&&(i=0),i>.5&&(i=.5);var a=0|i*.5*(e[0]+e[1]);a>u.MAX_BITS_PER_CHANNEL-e[0]&&(a=u.MAX_BITS_PER_CHANNEL-e[0]),a<0&&(a=0),e[1]>=125&&(e[1]-a>125?(e[0]<n&&(e[0]+=a),e[1]-=a):(e[0]+=e[1]-125,e[1]=125)),a=e[0]+e[1],a>r&&(e[0]=r*e[0]/a,e[1]=r*e[1]/a),s(e[0]<=u.MAX_BITS_PER_CHANNEL),s(e[1]<=u.MAX_BITS_PER_CHANNEL),s(e[0]+e[1]<=u.MAX_BITS_PER_GRANULE)},this.athAdjust=function(e,t,n){var r=90.30873362,a=94.82444863,o=i.FAST_LOG10_X(t,10),s=e*e,c=0;return o-=n,s>1e-20&&(c=1+i.FAST_LOG10_X(s,10/r)),c<0&&(c=0),o*=c,o+=n+r-a,10**(.1*o)},this.calc_xmin=function(e,r,i,a){var o=0,s=e.internal_flags,l,u=0,d=0,f=s.ATH,p=i.xr,m=+(e.VBR==n.vbr_mtrh),h=s.masking_lower;for((e.VBR==n.vbr_mtrh||e.VBR==n.vbr_mt)&&(h=1),l=0;l<i.psy_lmax;l++){var _,v=e.VBR==n.vbr_rh||e.VBR==n.vbr_mtrh?athAdjust(f.adjust,f.l[l],f.floor):f.adjust*f.l[l],y,b,x=i.width[l],S;y=v/x,b=g,S=x>>1,_=0;do{var C=p[u]*p[u],w;_+=C,b+=C<y?C:y,u++,w=p[u]*p[u],_+=w,b+=w<y?w:y,u++}while(--S>0);if(_>v&&d++,l==c.SBPSY_l){var T=v*s.nsPsy.longfact[l];b<T&&(b=T)}if(m!=0&&(v=b),!e.ATHonly){var E=r.en.l[l];if(E>0){var T=_*r.thm.l[l]*h/E;m!=0&&(T*=s.nsPsy.longfact[l]),v<T&&(v=T)}}m==0?a[o++]=v*s.nsPsy.longfact[l]:a[o++]=v}var D=575;if(i.block_type!=c.SHORT_TYPE)for(var O=576;O--!=0&&t.EQ(p[O],0);)D=O;i.max_nonzero_coeff=D;for(var k=i.sfb_smin;l<i.psymax;k++,l+=3){var x,A,j=e.VBR==n.vbr_rh||e.VBR==n.vbr_mtrh?athAdjust(f.adjust,f.s[k],f.floor):f.adjust*f.s[k];for(x=i.width[l],A=0;A<3;A++){var _=0,v,y,b,S=x>>1;y=j/x,b=g;do{var C=p[u]*p[u],w;_+=C,b+=C<y?C:y,u++,w=p[u]*p[u],_+=w,b+=w<y?w:y,u++}while(--S>0);if(_>j&&d++,k==c.SBPSY_s){var T=j*s.nsPsy.shortfact[k];b<T&&(b=T)}if(v=m==0?j:b,!e.ATHonly&&!e.ATHshort){var E=r.en.s[k][A];if(E>0){var T=_*r.thm.s[k][A]*h/E;m!=0&&(T*=s.nsPsy.shortfact[k]),v<T&&(v=T)}}m==0?a[o++]=v*s.nsPsy.shortfact[k]:a[o++]=v}e.useTemporal&&(a[o-3]>a[o-3+1]&&(a[o-3+1]+=(a[o-3]-a[o-3+1])*s.decay),a[o-3+1]>a[o-3+2]&&(a[o-3+2]+=(a[o-3+1]-a[o-3+2])*s.decay))}return d};function O(e){this.s=e}this.calc_noise_core=function(e,t,n,r){var i=0,o=t.s,s=e.l3_enc;if(o>e.count1)for(;n--!=0;){var c=e.xr[o];o++,i+=c*c,c=e.xr[o],o++,i+=c*c}else if(o>e.big_values){var l=a(2);for(l[0]=0,l[1]=r;n--!=0;){var c=Math.abs(e.xr[o])-l[s[o]];o++,i+=c*c,c=Math.abs(e.xr[o])-l[s[o]],o++,i+=c*c}}else for(;n--!=0;){var c=Math.abs(e.xr[o])-w[s[o]]*r;o++,i+=c*c,c=Math.abs(e.xr[o])-w[s[o]]*r,o++,i+=c*c}return t.s=o,i},this.calc_noise=function(e,t,n,r,a){var o=0,s=0,c,l,u=0,d=0,f=0,p=-20,m=0,g=e.scalefac,_=0;for(r.over_SSD=0,c=0;c<e.psymax;c++){var v=e.global_gain-(g[_++]+(e.preflag==0?0:x[c])<<e.scalefac_scale+1)-e.subblock_gain[e.window[c]]*8,y=0;if(a!=null&&a.step[c]==v)y=a.noise[c],m+=e.width[c],n[o++]=y/t[s++],y=a.noise_log[c];else{var b=h(v);if(l=e.width[c]>>1,m+e.width[c]>e.max_nonzero_coeff){var S=e.max_nonzero_coeff-m+1;l=S>0?S>>1:0}var C=new O(m);y=this.calc_noise_core(e,C,l,b),m=C.s,a!=null&&(a.step[c]=v,a.noise[c]=y),y=n[o++]=y/t[s++],y=i.FAST_LOG10(Math.max(y,1e-20)),a!=null&&(a.noise_log[c]=y)}if(a!=null&&(a.global_gain=e.global_gain),f+=y,y>0){var w=Math.max(0|y*10+.5,1);r.over_SSD+=w*w,u++,d+=y}p=Math.max(p,y)}return r.over_count=u,r.tot_noise=f,r.over_noise=d,r.max_noise=p,u},this.set_pinfo=function(e,t,n,r,i){var o=e.internal_flags,l,u,d,f,p,m=t.scalefac_scale==0?.5:1,h=t.scalefac,g=a(L3Side.SFBMAX),_=a(L3Side.SFBMAX),v=new CalcNoiseResult;calc_xmin(e,n,t,g),calc_noise(t,g,_,v,null);var y=0;for(u=t.sfb_lmax,t.block_type!=c.SHORT_TYPE&&t.mixed_block_flag==0&&(u=22),l=0;l<u;l++){var b=o.scalefac_band.l[l],S=o.scalefac_band.l[l+1],C=S-b;for(f=0;y<S;y++)f+=t.xr[y]*t.xr[y];f/=C,p=0x38d7ea4c68000,o.pinfo.en[r][i][l]=p*f,o.pinfo.xfsf[r][i][l]=p*g[l]*_[l]/C,n.en.l[l]>0&&!e.ATHonly?f/=n.en.l[l]:f=0,o.pinfo.thr[r][i][l]=p*Math.max(f*n.thm.l[l],o.ATH.l[l]),o.pinfo.LAMEsfb[r][i][l]=0,t.preflag!=0&&l>=11&&(o.pinfo.LAMEsfb[r][i][l]=-m*x[l]),l<c.SBPSY_l&&(s(h[l]>=0),o.pinfo.LAMEsfb[r][i][l]-=m*h[l])}if(t.block_type==c.SHORT_TYPE)for(u=l,l=t.sfb_smin;l<c.SBMAX_s;l++)for(var b=o.scalefac_band.s[l],S=o.scalefac_band.s[l+1],C=S-b,w=0;w<3;w++){for(f=0,d=b;d<S;d++)f+=t.xr[y]*t.xr[y],y++;f=Math.max(f/C,1e-20),p=0x38d7ea4c68000,o.pinfo.en_s[r][i][3*l+w]=p*f,o.pinfo.xfsf_s[r][i][3*l+w]=p*g[u]*_[u]/C,n.en.s[l][w]>0?f/=n.en.s[l][w]:f=0,(e.ATHonly||e.ATHshort)&&(f=0),o.pinfo.thr_s[r][i][3*l+w]=p*Math.max(f*n.thm.s[l][w],o.ATH.s[l]),o.pinfo.LAMEsfb_s[r][i][3*l+w]=-2*t.subblock_gain[w],l<c.SBPSY_s&&(o.pinfo.LAMEsfb_s[r][i][3*l+w]-=m*h[u]),u++}o.pinfo.LAMEqss[r][i]=t.global_gain,o.pinfo.LAMEmainbits[r][i]=t.part2_3_length+t.part2_length,o.pinfo.LAMEsfbits[r][i]=t.part2_length,o.pinfo.over[r][i]=v.over_count,o.pinfo.max_noise[r][i]=v.max_noise*10,o.pinfo.over_noise[r][i]=v.over_noise*10,o.pinfo.tot_noise[r][i]=v.tot_noise*10,o.pinfo.over_SSD[r][i]=v.over_SSD}}return yu=d,yu}function pc(){if(Su)return xu;Su=1;var e=Lc,t=e.System,n=e.Arrays,r=e.new_int,i=e.assert,a=Xs(),o=vu,s=yl,c=fc();function l(){var e=null;this.qupvt=null,this.setModules=function(t){this.qupvt=t,e=t};function u(e){this.bits=0|e}var d=[[0,0],[0,0],[0,0],[0,0],[0,0],[0,1],[1,1],[1,1],[1,2],[2,2],[2,3],[2,3],[3,4],[3,4],[3,4],[4,5],[4,5],[4,6],[5,6],[5,6],[5,7],[6,7],[6,7]];function f(e,t,n,r,i,a){var o=.5946/t;for(e>>=1;e--!=0;)i[a++]=o>n[r++]?0:1,i[a++]=o>n[r++]?0:1}function p(t,n,r,i,a,o){t>>=1;var s=t%2;for(t>>=1;t--!=0;){var c=r[i++]*n,l=r[i++]*n,u,d,f=0|c,p,m,h;u=r[i++]*n,p=0|l,d=r[i++]*n,m=0|u,c+=e.adj43[f],h=0|d,l+=e.adj43[p],a[o++]=0|c,u+=e.adj43[m],a[o++]=0|l,d+=e.adj43[h],a[o++]=0|u,a[o++]=0|d}if(s!=0){var c=r[i++]*n,l=r[i++]*n,f=0|c,p=0|l;c+=e.adj43[f],l+=e.adj43[p],a[o++]=0|c,a[o++]=0|l}}function m(t,r,o,s,c){var l,u,d=0,m,h=0,g=0,_=0,v=r,y=0,b=v,x=0,S=t,C=0;for(m=c!=null&&s.global_gain==c.global_gain,u=s.block_type==a.SHORT_TYPE?38:21,l=0;l<=u;l++){var w=-1;if((m||s.block_type==a.NORM_TYPE)&&(w=s.global_gain-(s.scalefac[l]+(s.preflag==0?0:e.pretab[l])<<s.scalefac_scale+1)-s.subblock_gain[s.window[l]]*8),i(s.width[l]>=0),m&&c.step[l]==w)h!=0&&(p(h,o,S,C,b,x),h=0),g!=0&&(f(g,o,S,C,b,x),g=0);else{var T=s.width[l];if(d+s.width[l]>s.max_nonzero_coeff){var E=s.max_nonzero_coeff-d+1;n.fill(r,s.max_nonzero_coeff,576,0),T=E,T<0&&(T=0),l=u+1}if(h==0&&g==0&&(b=v,x=y,S=t,C=_),c!=null&&c.sfb_count1>0&&l>=c.sfb_count1&&c.step[l]>0&&w>=c.step[l]?(h!=0&&(p(h,o,S,C,b,x),h=0,b=v,x=y,S=t,C=_),g+=T):(g!=0&&(f(g,o,S,C,b,x),g=0,b=v,x=y,S=t,C=_),h+=T),T<=0){g!=0&&(f(g,o,S,C,b,x),g=0),h!=0&&(p(h,o,S,C,b,x),h=0);break}}l<=u&&(y+=s.width[l],_+=s.width[l],d+=s.width[l])}h!=0&&(p(h,o,S,C,b,x),h=0),g!=0&&(f(g,o,S,C,b,x),g=0)}function h(e,t,n){var r=0,i=0;do{var a=e[t++],o=e[t++];r<a&&(r=a),i<o&&(i=o)}while(t<n);return r<i&&(r=i),r}function g(e,t,n,r,i,a){var s=o.ht[r].xlen*65536+o.ht[i].xlen,c=0,l;do{var u=e[t++],d=e[t++];u!=0&&(u>14&&(u=15,c+=s),u*=16),d!=0&&(d>14&&(d=15,c+=s),u+=d),c+=o.largetbl[u]}while(t<n);return l=c&65535,c>>=16,c>l&&(c=l,r=i),a.bits+=c,r}function _(e,t,n,r){var i=0,a=o.ht[1].hlen;do{var s=e[t+0]*2+e[t+1];t+=2,i+=a[s]}while(t<n);return r.bits+=i,1}function v(e,t,n,r,i){var a=0,s,c=o.ht[r].xlen,l=r==2?o.table23:o.table56;do{var u=e[t+0]*c+e[t+1];t+=2,a+=l[u]}while(t<n);return s=a&65535,a>>=16,a>s&&(a=s,r++),i.bits+=a,r}function y(e,t,n,r,i){var a=0,s=0,c=0,l=o.ht[r].xlen,u=o.ht[r].hlen,d=o.ht[r+1].hlen,f=o.ht[r+2].hlen;do{var p=e[t+0]*l+e[t+1];t+=2,a+=u[p],s+=d[p],c+=f[p]}while(t<n);var m=r;return a>s&&(a=s,m++),a>c&&(a=c,m=r+2),i.bits+=a,m}var b=[1,2,5,7,7,10,10,13,13,13,13,13,13,13,13];function x(e,t,n,r){var i=h(e,t,n);switch(i){case 0:return i;case 1:return _(e,t,n,r);case 2:case 3:return v(e,t,n,b[i-1],r);case 4:case 5:case 6:case 7:case 8:case 9:case 10:case 11:case 12:case 13:case 14:case 15:return y(e,t,n,b[i-1],r);default:if(i>c.IXMAX_VAL)return r.bits=c.LARGE_BITS,-1;i-=15;for(var a=24;a<32&&!(o.ht[a].linmax>=i);a++);for(var s=a-8;s<24&&!(o.ht[s].linmax>=i);s++);return g(e,t,n,s,a,r)}}this.noquant_count_bits=function(e,t,n){var r=t.l3_enc,s=Math.min(576,t.max_nonzero_coeff+2>>1<<1);for(n!=null&&(n.sfb_count1=0);s>1&&!(r[s-1]|r[s-2]);s-=2);t.count1=s;for(var c=0,l=0;s>3;s-=4){var d;if(((r[s-1]|r[s-2]|r[s-3]|r[s-4])&2147483647)>1)break;d=((r[s-4]*2+r[s-3])*2+r[s-2])*2+r[s-1],c+=o.t32l[d],l+=o.t33l[d]}var f=c;if(t.count1table_select=0,c>l&&(f=l,t.count1table_select=1),t.count1bits=f,t.big_values=s,s==0)return f;if(t.block_type==a.SHORT_TYPE)c=3*e.scalefac_band.s[3],c>t.big_values&&(c=t.big_values),l=t.big_values;else if(t.block_type==a.NORM_TYPE){if(c=t.region0_count=e.bv_scf[s-2],l=t.region1_count=e.bv_scf[s-1],i(c+l+2<a.SBPSY_l),l=e.scalefac_band.l[c+l+2],c=e.scalefac_band.l[c+1],l<s){var p=new u(f);t.table_select[2]=x(r,l,s,p),f=p.bits}}else t.region0_count=7,t.region1_count=a.SBMAX_l-1-7-1,c=e.scalefac_band.l[8],l=s,c>l&&(c=l);if(c=Math.min(c,s),l=Math.min(l,s),0<c){var p=new u(f);t.table_select[0]=x(r,0,c,p),f=p.bits}if(c<l){var p=new u(f);t.table_select[1]=x(r,c,l,p),f=p.bits}if(e.use_best_huffman==2&&(t.part2_3_length=f,best_huffman_divide(e,t),f=t.part2_3_length),n!=null&&t.block_type==a.NORM_TYPE){for(var m=0;e.scalefac_band.l[m]<t.big_values;)m++;n.sfb_count1=m}return f},this.count_bits=function(t,n,r,i){var a=r.l3_enc,o=c.IXMAX_VAL/e.IPOW20(r.global_gain);if(r.xrpow_max>o)return c.LARGE_BITS;if(m(n,a,e.IPOW20(r.global_gain),r,i),t.substep_shaping&2)for(var s=0,l=r.global_gain+r.scalefac_scale,u=.634521682242439/e.IPOW20(l),d=0;d<r.sfbmax;d++){var f=r.width[d];if(t.pseudohalf[d]==0)s+=f;else{var p=s;for(s+=f;p<s;++p)a[p]=n[p]>=u?a[p]:0}}return this.noquant_count_bits(t,r,i)};function S(e,t,n,r,i,a,o){for(var s=t.big_values,l=0;l<=22;l++)r[l]=c.LARGE_BITS;for(var l=0;l<16;l++){var d=e.scalefac_band.l[l+1];if(d>=s)break;var f=0,p=new u(f),m=x(n,0,d,p);f=p.bits;for(var h=0;h<8;h++){var g=e.scalefac_band.l[l+h+2];if(g>=s)break;var _=f;p=new u(_);var v=x(n,d,g,p);_=p.bits,r[l+h]>_&&(r[l+h]=_,i[l+h]=l,a[l+h]=m,o[l+h]=v)}}}function C(e,t,n,r,i,o,s,c){for(var l=t.big_values,d=2;d<a.SBMAX_l+1;d++){var f=e.scalefac_band.l[d];if(f>=l)break;var p=i[d-2]+t.count1bits;if(n.part2_3_length<=p)break;var m=new u(p),h=x(r,f,l,m);p=m.bits,!(n.part2_3_length<=p)&&(n.assign(t),n.part2_3_length=p,n.region0_count=o[d-2],n.region1_count=d-2-o[d-2],n.table_select[0]=s[d-2],n.table_select[1]=c[d-2],n.table_select[2]=h)}}this.best_huffman_divide=function(e,t){var n=new s,i=t.l3_enc,c=r(23),l=r(23),d=r(23),f=r(23);if(t.block_type!=a.SHORT_TYPE||e.mode_gr!=1){n.assign(t),t.block_type==a.NORM_TYPE&&(S(e,t,i,c,l,d,f),C(e,n,t,i,c,l,d,f));var p=n.big_values;if(!(p==0||(i[p-2]|i[p-1])>1)&&(p=t.count1+2,!(p>576))){n.assign(t),n.count1=p;for(var m=0,h=0;p>n.big_values;p-=4){var g=((i[p-4]*2+i[p-3])*2+i[p-2])*2+i[p-1];m+=o.t32l[g],h+=o.t33l[g]}if(n.big_values=p,n.count1table_select=0,m>h&&(m=h,n.count1table_select=1),n.count1bits=m,n.block_type==a.NORM_TYPE)C(e,n,t,i,c,l,d,f);else{if(n.part2_3_length=m,m=e.scalefac_band.l[8],m>p&&(m=p),m>0){var _=new u(n.part2_3_length);n.table_select[0]=x(i,0,m,_),n.part2_3_length=_.bits}if(p>m){var _=new u(n.part2_3_length);n.table_select[1]=x(i,m,p,_),n.part2_3_length=_.bits}t.part2_3_length>n.part2_3_length&&t.assign(n)}}}};var w=[1,1,1,1,8,2,2,2,4,4,4,8,8,8,16,16],T=[1,2,4,8,1,2,4,8,2,4,8,2,4,8,4,8],E=[0,0,0,0,3,1,1,1,2,2,2,3,3,3,4,4],D=[0,1,2,3,0,1,2,3,1,2,3,1,2,3,2,3];l.slen1_tab=E,l.slen2_tab=D;function O(e,t){for(var n,r=t.tt[1][e],i=t.tt[0][e],s=0;s<o.scfsi_band.length-1;s++){for(n=o.scfsi_band[s];n<o.scfsi_band[s+1]&&!(i.scalefac[n]!=r.scalefac[n]&&r.scalefac[n]>=0);n++);if(n==o.scfsi_band[s+1]){for(n=o.scfsi_band[s];n<o.scfsi_band[s+1];n++)r.scalefac[n]=-1;t.scfsi[e][s]=1}}var c=0,l=0;for(n=0;n<11;n++)r.scalefac[n]!=-1&&(l++,c<r.scalefac[n]&&(c=r.scalefac[n]));for(var u=0,d=0;n<a.SBPSY_l;n++)r.scalefac[n]!=-1&&(d++,u<r.scalefac[n]&&(u=r.scalefac[n]));for(var s=0;s<16;s++)if(c<w[s]&&u<T[s]){var f=E[s]*l+D[s]*d;r.part2_length>f&&(r.part2_length=f,r.scalefac_compress=s)}}this.best_scalefac_store=function(t,n,r,i){var o=i.tt[n][r],s,c,l,u,d=0;for(l=0,s=0;s<o.sfbmax;s++){var f=o.width[s];for(l+=f,u=-f;u<0&&o.l3_enc[u+l]==0;u++);u==0&&(o.scalefac[s]=d=-2)}if(o.scalefac_scale==0&&o.preflag==0){var p=0;for(s=0;s<o.sfbmax;s++)o.scalefac[s]>0&&(p|=o.scalefac[s]);if(!(p&1)&&p!=0){for(s=0;s<o.sfbmax;s++)o.scalefac[s]>0&&(o.scalefac[s]>>=1);o.scalefac_scale=d=1}}if(o.preflag==0&&o.block_type!=a.SHORT_TYPE&&t.mode_gr==2){for(s=11;s<a.SBPSY_l&&!(o.scalefac[s]<e.pretab[s]&&o.scalefac[s]!=-2);s++);if(s==a.SBPSY_l){for(s=11;s<a.SBPSY_l;s++)o.scalefac[s]>0&&(o.scalefac[s]-=e.pretab[s]);o.preflag=d=1}}for(c=0;c<4;c++)i.scfsi[r][c]=0;for(t.mode_gr==2&&n==1&&i.tt[0][r].block_type!=a.SHORT_TYPE&&i.tt[1][r].block_type!=a.SHORT_TYPE&&(O(r,i),d=0),s=0;s<o.sfbmax;s++)o.scalefac[s]==-2&&(o.scalefac[s]=0);d!=0&&(t.mode_gr==2?this.scale_bitcount(o):this.scale_bitcount_lsf(t,o))};function k(e,t){for(var n=0;n<t;++n)if(e[n]<0)return!1;return!0}var A=[0,18,36,54,54,36,54,72,54,72,90,72,90,108,108,126],j=[0,18,36,54,51,35,53,71,52,70,88,69,87,105,104,122],M=[0,10,20,30,33,21,31,41,32,42,52,43,53,63,64,74];this.scale_bitcount=function(t){var n,r,o=0,s=0,l,u=t.scalefac;if(i(k(u,t.sfbmax)),t.block_type==a.SHORT_TYPE)l=A,t.mixed_block_flag!=0&&(l=j);else if(l=M,t.preflag==0){for(r=11;r<a.SBPSY_l&&!(u[r]<e.pretab[r]);r++);if(r==a.SBPSY_l)for(t.preflag=1,r=11;r<a.SBPSY_l;r++)u[r]-=e.pretab[r]}for(r=0;r<t.sfbdivide;r++)o<u[r]&&(o=u[r]);for(;r<t.sfbmax;r++)s<u[r]&&(s=u[r]);for(t.part2_length=c.LARGE_BITS,n=0;n<16;n++)o<w[n]&&s<T[n]&&t.part2_length>l[n]&&(t.part2_length=l[n],t.scalefac_compress=n);return t.part2_length==c.LARGE_BITS};var N=[[15,15,7,7],[15,15,7,0],[7,3,0,0],[15,31,31,0],[7,7,7,0],[3,3,0,0]];this.scale_bitcount_lsf=function(n,o){var s,c,l,u,d,f,p,m,h=r(4),g=o.scalefac;for(s=o.preflag==0?0:2,p=0;p<4;p++)h[p]=0;if(o.block_type==a.SHORT_TYPE){c=1;var _=e.nr_of_sfb_block[s][c];for(m=0,l=0;l<4;l++)for(u=_[l]/3,p=0;p<u;p++,m++)for(d=0;d<3;d++)g[m*3+d]>h[l]&&(h[l]=g[m*3+d])}else{c=0;var _=e.nr_of_sfb_block[s][c];for(m=0,l=0;l<4;l++)for(u=_[l],p=0;p<u;p++,m++)g[m]>h[l]&&(h[l]=g[m])}for(f=!1,l=0;l<4;l++)h[l]>N[s][l]&&(f=!0);if(!f){var v,y,b,x;for(o.sfb_partition_table=e.nr_of_sfb_block[s][c],l=0;l<4;l++)o.slen[l]=P[h[l]];switch(v=o.slen[0],y=o.slen[1],b=o.slen[2],x=o.slen[3],s){case 0:o.scalefac_compress=(v*5+y<<4)+(b<<2)+x;break;case 1:o.scalefac_compress=400+(v*5+y<<2)+b;break;case 2:o.scalefac_compress=500+v*3+y;break;default:t.err.printf(`intensity stereo not implemented yet
@@ -1435,18 +1435,19 @@ Defaulting to 2020, but this will stop working in the future.`)),t.ecmaVersion=1
1435
1435
  }
1436
1436
 
1437
1437
  /* Bare icon controls: visible glyph, generous invisible target, no circular chrome. */
1438
- button[data-icon-action="true"] {
1438
+ button[data-icon-action="true"],a[data-icon-action="true"] {
1439
1439
  display:inline-flex !important; align-items:center !important; justify-content:center !important;
1440
1440
  min-width:36px !important; min-height:36px !important; padding:8px !important;
1441
1441
  border:0 !important; border-radius:0 !important; background:transparent !important;
1442
1442
  box-shadow:none !important; color:var(--text-secondary, var(--fg)) !important;
1443
- flex-shrink:0; line-height:1; cursor:pointer;
1443
+ flex-shrink:0; line-height:1; cursor:pointer; text-decoration:none !important;
1444
1444
  }
1445
- button[data-icon-action="true"]:hover:not(:disabled) {color:var(--text-primary, var(--fg)) !important;}
1446
- button[data-icon-action="true"]:focus-visible {outline:2px solid var(--signal) !important;outline-offset:2px;}
1447
- button[data-icon-action="true"]:disabled {opacity:.4 !important;cursor:not-allowed;}
1448
- button[data-icon-action="true"][aria-pressed="true"] {color:var(--text-primary, var(--fg)) !important;text-decoration:underline;text-underline-offset:5px;}
1449
- @media (pointer:coarse) {button[data-icon-action="true"] {min-width:44px !important;min-height:44px !important;}}
1445
+ button[data-icon-action="true"]:hover:not(:disabled),a[data-icon-action="true"]:hover:not(:disabled) {color:var(--text-primary, var(--fg)) !important;}
1446
+ button[data-icon-action="true"]:focus-visible,a[data-icon-action="true"]:focus-visible {outline:2px solid var(--signal) !important;outline-offset:2px;}
1447
+ button[data-icon-action="true"]:disabled,a[data-icon-action="true"]:disabled {opacity:.4 !important;cursor:not-allowed;}
1448
+ button[data-icon-action="true"][aria-pressed="true"],a[data-icon-action="true"][aria-pressed="true"] {color:var(--text-primary, var(--fg)) !important;text-decoration:underline;text-underline-offset:5px;}
1449
+ a[data-icon-action="true"] {flex:0 0 auto !important;align-self:center;} /* an icon link never stretches into a bar */
1450
+ @media (pointer:coarse) {button[data-icon-action="true"],a[data-icon-action="true"] {min-width:44px !important;min-height:44px !important;}}
1450
1451
  `,zH=`/* Shared containment for creator-authored form rows, including installed pins.
1451
1452
  This is host presentation only; it does not alter a Block's source or inputs. */
1452
1453
  :where(section, div, fieldset, form):has(> label + label) {
@@ -1531,7 +1532,7 @@ label:has(> textarea) {
1531
1532
  }
1532
1533
 
1533
1534
  /* ---------- The stage: the object being made gets the main surface ---------- */
1534
- :where(.sm-stage){position:relative;display:grid;place-items:center;min-height:220px;padding:var(--s-3,12px);border-radius:var(--r-3,8px);background:var(--bg-inset);overflow:hidden}
1535
+ :where(.sm-stage){position:relative;display:grid;place-items:center;align-content:center;min-height:220px;padding:var(--s-3,12px);border-radius:var(--r-3,8px);background:var(--bg-inset);overflow:hidden}
1535
1536
  :where(.sm-stage:is([data-ratio="16:9"],[data-ratio="16/9"])){aspect-ratio:16/9;min-height:0}
1536
1537
  :where(.sm-stage:is([data-ratio="9:16"],[data-ratio="9/16"])){aspect-ratio:9/16;min-height:0;max-height:70vh;justify-self:center;width:auto;height:min(70vh,640px)}
1537
1538
  :where(.sm-stage:is([data-ratio="1:1"],[data-ratio="1/1"])){aspect-ratio:1;min-height:0}
@@ -1539,6 +1540,14 @@ label:has(> textarea) {
1539
1540
  :where(.sm-stage[data-fill]) > :where(img,video,canvas){width:100%;height:100%;object-fit:cover}
1540
1541
  /* A picture the view has not filled yet draws nothing, never a broken-image icon (November 3, 2026). */
1541
1542
  :where(.sm-stage) :where(img:not([src]),img[src=""]){display:none}
1543
+ /* November 4, 2026 (owner: "make that the rule for the SDK"): what a stage shows sits in its middle as one group, a caption
1544
+ with its picture, and several results fill the stage's width as one row instead of leaving empty columns. A Block that
1545
+ lays itself out (data-stillmade-layout="own") keeps its own placement. */
1546
+ :where(.sm-stage) > :where(.sm-gallery){width:100%;grid-template-columns:repeat(auto-fit,minmax(min(100%,var(--sm-tile,140px)),1fr))}
1547
+ :where(.sm-stage) > :where(.sm-gallery:not(:has(> :nth-child(5)))){grid-template-columns:none;grid-auto-flow:column;grid-auto-columns:minmax(0,1fr)}
1548
+ :where(.sm-stage) > :where(figcaption,small,.sm-caption){justify-self:center;text-align:center}
1549
+ :where([data-stillmade-layout="own"]) :where(.sm-stage){align-content:normal}
1550
+ :where([data-stillmade-layout="own"]) :where(.sm-stage) > :where(.sm-gallery){width:auto;grid-template-columns:repeat(auto-fill,minmax(min(100%,var(--sm-tile,140px)),1fr));grid-auto-flow:row}
1542
1551
 
1543
1552
  /* ---------- Empty state: a picture and a few words, never a paragraph ---------- */
1544
1553
  :where(.sm-empty){display:grid;justify-items:center;gap:var(--s-3,12px);padding:var(--s-5,24px) var(--s-4,16px);text-align:center;color:var(--fg-muted)}
@@ -1937,7 +1946,7 @@ label:has(> textarea) {
1937
1946
  @media (prefers-reduced-motion:reduce){
1938
1947
  .sm-player *,.sm-viewer,.sm-viewer *,.sm-expand-btn{transition:none!important;animation:none!important}
1939
1948
  }
1940
- `;function _U(e){switch(e){case`minus`:return(0,V.jsx)(`path`,{d:`M5 12h14`});case`messageCircle`:return(0,V.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,V.jsx)(`path`,{d:`M20 12H4M11 5l-7 7 7 7`});case`link`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 .5l3-3a5 5 0 0 0-7-7l-2 2`}),(0,V.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7-.5l-3 3a5 5 0 0 0 7 7l2-2`})]});case`unlink`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`m18.8 12.3 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7`}),(0,V.jsx)(`path`,{d:`m5.2 11.7-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7`}),(0,V.jsx)(`path`,{d:`M8 2v3M2 8h3M16 19v3M19 16h3`})]});case`copy`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`9`,y:`9`,width:`12`,height:`12`,rx:`2`}),(0,V.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,V.jsx)(`path`,{d:`M12 20V4M5 11l7-7 7 7`});case`star`:return(0,V.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,V.jsx)(`path`,{d:`M7 17 17 7M8 7h9v9`});case`arrowDown`:return(0,V.jsx)(`path`,{d:`M12 4v16M5 13l7 7 7-7`});case`thumbsUp`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M7 10v11H3V10Z`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M7 14V3H3v11Z`}),(0,V.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,V.jsx)(`path`,{d:`M3 10h11a7 7 0 0 1 0 14M3 10l5-5M3 10l5 5`,transform:`translate(0 -3)`});case`redo`:return(0,V.jsx)(`path`,{d:`M21 7H10a7 7 0 0 0 0 14M21 7l-5-5M21 7l-5 5`});case`remix`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M5 5h5a5 5 0 0 1 5 5v9`}),(0,V.jsx)(`path`,{d:`m11 15 4 4 4-4`}),(0,V.jsx)(`path`,{d:`M5 19h2`}),(0,V.jsx)(`circle`,{cx:`5`,cy:`5`,r:`2`}),(0,V.jsx)(`circle`,{cx:`5`,cy:`19`,r:`2`})]});case`more`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,V.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]});case`palette`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`13.5`,cy:`6.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`17`,cy:`11`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`8.5`,cy:`7.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`6.5`,cy:`12.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 8 0v4`})]});case`unlock`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 7.9-1`})]});case`pushpin`:return(0,V.jsxs)(`g`,{transform:`rotate(35 12 12)`,children:[(0,V.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`}),(0,V.jsx)(`path`,{d:`M12 14v7`})]});case`pushpinFilled`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`M12 14v7`})]});case`pin`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 21s7-5.7 7-11a7 7 0 0 0-14 0c0 5.3 7 11 7 11Z`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`10`,r:`2.5`})]});case`user`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,V.jsx)(`path`,{d:`M5 21a7 7 0 0 1 14 0`})]});case`image`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,V.jsx)(`path`,{d:`m21 15-5-5L5 21`})]});case`imageOff`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M2 2l20 20`}),(0,V.jsx)(`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`}),(0,V.jsx)(`path`,{d:`M13.5 13.5 6 21`}),(0,V.jsx)(`path`,{d:`m18 12 3 3`}),(0,V.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,V.jsx)(`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`})]});case`film`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4`})]});case`folder`:return(0,V.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,V.jsx)(`path`,{d:`M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01`});case`grid`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1.5`})]});case`zap`:return(0,V.jsx)(`path`,{d:`M13 2 4 14h7l-1 8 9-12h-7Z`});case`plug`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 22v-5M9 8V2M15 8V2`}),(0,V.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});case`book`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 7v14`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`}),(0,V.jsx)(`path`,{d:`m10 17 5-5-5-5`}),(0,V.jsx)(`path`,{d:`M15 12H3`})]});case`upload`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 16V4M7 9l5-5 5 5`}),(0,V.jsx)(`path`,{d:`M5 20h14`})]});case`download`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 4v12M7 11l5 5 5-5`}),(0,V.jsx)(`path`,{d:`M5 20h14`})]});case`save`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M5 3h11l3 3v15H5Z`}),(0,V.jsx)(`path`,{d:`M8 3v5h7M8 21v-7h8v7`})]});case`search`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,V.jsx)(`path`,{d:`m20 20-3.5-3.5`})]});case`magnet`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M6 4h4v8a2 2 0 0 0 4 0V4h4v8a6 6 0 0 1-12 0Z`}),(0,V.jsx)(`path`,{d:`M6 8h4M14 8h4`})]});case`bot`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`4`,y:`8`,width:`16`,height:`11`,rx:`2`}),(0,V.jsx)(`path`,{d:`M12 8V4M9 13h.01M15 13h.01M9 16h6`})]});case`note`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`4`,y:`3`,width:`16`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 8h8M8 12h8M8 16h5`})]});case`clock`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`path`,{d:`M12 7v5l3 2`})]});case`calendar`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`5`,width:`18`,height:`16`,rx:`2`}),(0,V.jsx)(`path`,{d:`M16 3v4M8 3v4M3 10h18`})]});case`hourglass`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 20h9`}),(0,V.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`music`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M9 18V5l12-2v13`}),(0,V.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,V.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]});case`mic`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`}),(0,V.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,V.jsx)(`path`,{d:`M12 19v3`})]});case`target`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]});case`pointer`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 21V9`}),(0,V.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,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,V.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.5`}),(0,V.jsx)(`path`,{d:`M8 8l12 8M8 16 20 8`})]});case`maximize`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,V.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,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`m8 12 3 3 5-6`})]});case`warning`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.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,V.jsx)(`path`,{d:`M12 9v4M12 17h.01`})]});case`sparkle`:return(0,V.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,V.jsx)(`path`,{d:`m5 12 5 5 9-10`});case`x`:return(0,V.jsx)(`path`,{d:`M6 6 18 18M18 6 6 18`});case`plus`:return(0,V.jsx)(`path`,{d:`M12 5v14M5 12h14`});case`refresh`:return(0,V.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,V.jsx)(`path`,{d:`M7 4v16l13-8Z`});case`pause`:return(0,V.jsx)(`path`,{d:`M9 5v14M15 5v14`});case`playFilled`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`})]});case`volume2`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14`})]});case`volumeX`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`m22 9-6 6M16 9l6 6`})]});case`minimize`:return(0,V.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,V.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`});case`chevronRight`:return(0,V.jsx)(`path`,{d:`m9 6 6 6-6 6`});case`chevronLeft`:return(0,V.jsx)(`path`,{d:`m15 6-6 6 6 6`});case`chevronDown`:return(0,V.jsx)(`path`,{d:`m6 9 6 6 6-6`});case`trash`:return(0,V.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,V.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,V.jsx)(`path`,{d:`M4 6V4h16v2M12 4v16M9 20h6`});case`home`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M3 10.5 12 3l9 7.5`}),(0,V.jsx)(`path`,{d:`M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5`}),(0,V.jsx)(`path`,{d:`M9 21v-6h6v6`})]});case`menu`:return(0,V.jsx)(`path`,{d:`M4 6h16M4 12h16M4 18h16`});case`logout`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,V.jsx)(`path`,{d:`M16 17l5-5-5-5`}),(0,V.jsx)(`path`,{d:`M21 12H9`})]});case`help`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`path`,{d:`M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3`}),(0,V.jsx)(`path`,{d:`M12 17h.01`})]});case`bug`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`m8 2 1.9 1.9M14.1 3.9 16 2`}),(0,V.jsx)(`path`,{d:`M9 7.1v-1a3 3 0 1 1 6 0v1`}),(0,V.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,V.jsx)(`path`,{d:`M12 20v-9`}),(0,V.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 vU({name:e,size:t=`1em`,style:n,className:r,strokeWidth:i=1.5}){let a=_U(e);return a?(0,V.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}var yU=`sm.blockZoom.`;function bU(e){try{let t=e?localStorage.getItem(yU+e):null,n=Number(t);return t&&t!==`auto`&&Number.isFinite(n)?n:`auto`}catch{return`auto`}}function xU(e,t){try{if(!e)return;t===`auto`?localStorage.removeItem(yU+e):localStorage.setItem(yU+e,String(t))}catch{}}function SU(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))}var CU=(e,t)=>Math.round(Math.min(tU,Math.max(eU,e+t))*100)/100;function wU({zoom:e=1,mode:t=`auto`,onChange:n}){let r=t===`auto`?e:t,i=e=>n(CU(r,e));return(0,V.jsxs)(`div`,{className:`block-zoom-control`,role:`group`,"aria-label":`Block size`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(-nU),disabled:r<=eU,"aria-label":`Smaller`,title:`Smaller`,"data-icon-action":`true`,children:(0,V.jsx)(vU,{name:`minus`,size:14})}),(0,V.jsx)(`button`,{type:`button`,className:`block-zoom-mode`,onClick:()=>n(`auto`),"aria-pressed":t===`auto`,title:t===`auto`?`Sized to fit automatically`:`Size automatically`,children:t===`auto`?`Auto · ${Math.round(e*100)}%`:`${Math.round(r*100)}%`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(nU),disabled:r>=tU,"aria-label":`Bigger`,title:`Bigger`,"data-icon-action":`true`,children:(0,V.jsx)(vU,{name:`plus`,size:14})})]})}var TU=(0,v.createContext)(null),EU=null,DU=new Set,OU=()=>EU;function kU(e){return DU.add(e),()=>DU.delete(e)}function AU(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()}})}Tt();function jU(e){return B(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 MU(e){mt(e);let t=e?.stages&&e.packages||[];return B(Array.isArray(t)&&t.length<128,`LIMIT`,`Too many packaged Blocks for execution review`),jU(await Promise.all([e,...t].map(e=>gt(e))))}async function NU(e){let t=await MU(e),n=new Set(t),r=e?.stages?e.packages||[]:[e],i=e=>{B(e&&typeof e.digest==`string`&&/^[a-f0-9]{64}$/.test(e.digest),`SCHEMA`,`Block lineage needs exact source digests`),n.add(e.digest),B(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??[];B(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??[];B(Array.isArray(r)&&r.length<=16,`SCHEMA`,`Portable lineage must contain at most 16 exact source references`),r.forEach(i)}return jU([...n])}var PU=`stillmade.block-security.v1`,FU=new Map;function IU(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 LU(){try{let e=JSON.parse(globalThis.localStorage?.getItem(PU)||`{}`);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&&FU.set(t,IU(FU.get(t),n))}catch{}return FU}function RU(e){let t=LU();for(let n of e){let e=t.get(n.digest);(n.revoked||n.published||e)&&t.set(n.digest,IU(e,n))}try{globalThis.localStorage?.setItem(PU,JSON.stringify(Object.fromEntries(t)))}catch{}}var zU=()=>Object.assign(Error(`This exact Block version has been quarantined by StillMade. Use a reviewed replacement.`),{code:`BLOCK_REVOKED`});async function BU(e,{signal:t}={}){let n=await NU(e),r=LU();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`);RU(s.digests)}catch{if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});if(n.some(e=>r.get(e)?.revoked))throw zU();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=>LU().get(e)?.revoked))throw zU();return{checked:!0}}ut();var VU=(e,t)=>Object.freeze({kind:e,mimeType:t}),HU=Object.freeze({png:VU(`image`,`image/png`),jpg:VU(`image`,`image/jpeg`),jpeg:VU(`image`,`image/jpeg`),webp:VU(`image`,`image/webp`),gif:VU(`image`,`image/gif`),mp4:VU(`video`,`video/mp4`),mov:VU(`video`,`video/quicktime`),webm:VU(`video`,`video/webm`),mp3:VU(`audio`,`audio/mpeg`),wav:VU(`audio`,`audio/wav`),m4a:VU(`audio`,`audio/mp4`),aac:VU(`audio`,`audio/aac`),ogg:VU(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(it).map(([e,t])=>[e,VU(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(HU).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 UU=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`}),WU=e=>Object.entries(HU).filter(([t,n])=>e.includes(n.kind)&&UU[t]).map(([e])=>UU[e]),GU=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],KU=e=>GU([...new Set(WU(e))]),qU=c({loadViewAssets:()=>JU});async function JU(e,{signal:t}={}){let n={};for(let[r,i]of Object.entries(e?.files||{})){let a=await fetch(`/__dev/files/`+i.sha256,{signal:t});if(!a.ok)throw Error(r+` is missing from the Block folder.`);let o=await cH(e,r,new Uint8Array(await a.arrayBuffer()));n[r]={mediaType:i.mediaType,base64:YU(o)}}return n}var YU,XU=o((()=>{lH(),YU=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}}));k(),Tt(),xi();var ZU=`stillmade.block.view.v1`,QU=5e3,$U=()=>globalThis.crypto.randomUUID(),eW=`*{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}}`,tW=`*{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)}`,nW=`: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}`,rW=`html[data-stillmade-pick],html[data-stillmade-pick] *{cursor:crosshair!important}html[data-stillmade-pick] [data-stillmade-media]{display:none!important}`,iW=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(HU).filter(([,e])=>e.kind===`file`).map(([e])=>`.${e}`).join(`,`)}),aW=e=>e.filter(e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9_-]{0,99}$/.test(e)),oW=e=>`html[data-stillmade-readonly] [data-stillmade-add]${aW(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]${aW(e).map(e=>`,[data-stillmade-remove="${e}"],[data-stillmade-move="${e}"]`).join(``)}{display:none!important}`;function sW(e,t){let n=typeof t==`string`&&vt(e?.inputs)&&Object.hasOwn(e.inputs,t)?e.inputs[t]:null;if(!vt(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(iW,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:iW[i]}}function cW(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 lW({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 uW=e=>JSON.stringify(e).replace(/</g,`\\u003c`).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`);function dW(e){if(mt(e),new TextEncoder().encode(JSON.stringify(e)).length>uH.messageBytes)throw Error(`Preview data exceeds 4 MiB`);return structuredClone(e)}var fW=e=>vt(e)&&[`image`,`video`,`audio`].includes(e.kind)&&[`assetId`,`versionId`,`url`].every(t=>typeof e[t]==`string`&&e[t])?ht([e.kind,e.assetId,e.versionId,e.url]):``;function pW(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`:ht(e);return t.current.signature===n?t.current.original=e:t.current={has:!0,original:e,signature:n,value:e},t.current.value}function mW(e,t=[]){return Array.isArray(e)?(e.forEach(e=>mW(e,t)),t):vt(e)?fW(e)?(t.push(e),t):(Object.values(e).forEach(e=>mW(e,t)),t):t}var hW=e=>Array.isArray(e)?e.length>0&&e.every(hW):!!fW(e);function gW(e,t,n){if(!vt(e)||!Object.values(e).length||!Object.values(e).every(hW))throw Error(`Only complete saved media references can be chosen as outputs.`);let r=new Set(mW(t).map(fW));for(let t of mW(e))if(!r.has(fW(t))&&!n?.authorizesMedia(t))throw Error(`Choose media supplied by this workspace or recorded in this session.`);return dW(e)}function _W(e){let t=dW(e);if(!vt(t)||!_t(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 vW(e){let t=dW(e);if(!(vt(t)&&Object.keys(t).length===3&&[`url`,`width`,`height`].every(e=>Object.hasOwn(t,e))&&[`width`,`height`].every(e=>Number.isInteger(t[e])&&t[e]>0&&t[e]<=uH.imagePreviewEdge))||typeof t.url!=`string`||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(t.url))throw Error(`The host returned an invalid image preview.`);let n=t.url.slice(22);if(n.length%4!=0)throw Error(`The host returned an invalid image preview.`);let r=atob(n.slice(0,44)),i=e=>r.charCodeAt(e),a=e=>i(e)*16777216+i(e+1)*65536+i(e+2)*256+i(e+3);if(r.length<33||![137,80,78,71,13,10,26,10].every((e,t)=>i(t)===e)||a(8)!==13||r.slice(12,16)!==`IHDR`||a(16)!==t.width||a(20)!==t.height)throw Error(`The host returned an invalid image preview.`);return t}function yW(e,t,n=`light`,r=`package`,i=!1,a=[],o=null,s=!1,c=!1,{assets:l={},filming:u=null,inputTypes:d=null}={}){bH(e);let f=DH(e),p=r===`package`?e.appearance??`host`:r;p!==`original`&&!f&&LH(e,{appearance:`host`});let m=(p===`original`?e.css??``:e.themedCss??e.css??``)+`
1941
- `+(f?``:zH),h=globalThis.crypto.randomUUID().replaceAll(`-`,``),g=`__sm_view_${h}`,_=`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,v=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,y=`(()=>{"use strict";document.currentScript.remove();const session=${uW(t)},channel=${uW(ZU)},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;const addTypes=${uW(vt(d)?d:null)},addLocked=new Set(${uW(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,${uW(v)},{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);${f?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${jH.toString()})(channel,session,send,${uW({guardName:_,taskMs:SH.taskMs,assets:l})});`:`Object.defineProperty(globalThis,${uW(g)},{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=(${cr.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${sr.toString()})(channel,session,${uW(ar)},sharedLifecycle);const textControls=${i?`(()=>{${Zn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${uW(o)},send});})()`:`null`};const sharedControls=(${Xn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${uW(a)});const {documentTools,sharedDocuments}=(${Qn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${At.toString()})((kind,value)=>{if(kind==="media"){if(mediaURLs.size>=2)throw Error("Release a previous media preview before opening another");if(!["video","audio"].includes(value.kind))throw Error("Choose an 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},"*")})});const connectionAPI=(${Ot.toString()})(${uW(ZU)},${uW(t)},${c},send),workAPI=(${D.toString()})(${uW(ZU)},${uW(t)},${s},send);const liveBridge=(${kt.toString()})(${uW(ZU)},${uW(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,${f?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,`:``}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:(${lr.toString()})(${JSON.stringify(a)}),...sharedAPI,...documentTools,connectDocument:sharedDocuments.connectDocument,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){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value))},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:${uW(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${uW(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${uW(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${uW(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})}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();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=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"},"*");})();`,b=f?`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${AH(e.javascript||``,_)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${g})=>{"use strict";delete globalThis[${uW(g)}];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${xH(e.javascript||``,g)}\n})(globalThis[${uW(g)}]);`.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-${h}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${f?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${f?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${RH.replace(/@font-face\s*\{[^}]*\}/g,``)}${f?tW:eW}${BH}${f?``:nW}${(m||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${rW}${oW(a)}</style></head><body>${e.html}${u?`<script nonce="${h}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${h}">${y.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${h}">document.currentScript.remove();${u?`(${AU.toString()})(${uW(ZU)},${uW(t)},parent.postMessage.bind(parent));`:``}(${QH.toString()})(${uW(ZU)},${uW(t)});(${$H.toString()})(${uW(ZU)},${uW(t)});(${aU.toString()})(${uW(ZU)},${uW(t)},(${rU.toString()}),"auto",(${iU.toString()}),${!f});(${oU.toString()})(${uW(ZU)},${uW(t)},(${sU.toString().replace(/<\/script/gi,`<\\/script`)})(),${uW(gU)},{minted:(()=>{const read=globalThis[${uW(v)}];delete globalThis[${uW(v)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${UH.toString()})(${uW(ZU)},${uW(t)},((validateCursorAnchor)=>(${HH.toString()}))(${VH.toString()}));(${WH.toString()})(${uW(ZU)},${uW(t)},(${KH.toString()}));<\/script><script nonce="${h}">${b}<\/script></body></html>`}function bW({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,V.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,V.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,V.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,V.jsx)(`ul`,{children:o.map(e=>(0,V.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,V.jsx)(`p`,{children:`Nothing yet.`})]})}function xW({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,onError:g,policyContent:_,policyParent:y,currentAppViewPolicy:b=null,title:S=`Block preview`,height:D=480,fitContent:O=!1,resetKey:k=0,theme:A,appearance:j=`package`,lockedInputKeys:M=[],agentContext:N=null}){let P=pW(e),F=pW(_),I=pW(y),ee=[`comfyui`,`capability`].includes(F?.manifest?.runtime)||!!F?.manifest?.desktopTools?.length||F?.manifest?.runtime===`module`&&!!F?.manifest?.permissions?.capabilities?.length,te=F?.capability?.operation===`image.generate`?9e5:36e4,L=(0,v.useRef)(null),R=(0,v.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onError:g}),ne=(0,v.useRef)(t),[z,re]=(0,v.useState)(``),[ie,ae]=(0,v.useState)(!1),[oe,se]=(0,v.useState)(0),ce=(0,v.useRef)(null),le=(0,v.useRef)(null),[ue,de]=(0,v.useState)(null),[fe,pe]=(0,v.useState)(null),[me,he]=(0,v.useState)(null),ge=F?.manifest?.id||null,[_e,ve]=(0,v.useState)(()=>bU(ge)),[ye,be]=(0,v.useState)(null),xe=(0,v.useRef)(_e);xe.current=_e;let Se=e=>{ve(e),xU(ge,e)},Ce=(0,v.useRef)(1);Ce.current=_e===`auto`?ye?.zoom||1:_e;let we=(0,v.useRef)(Se);we.current=Se;let Te=(0,v.useContext)(TU),Ee=(0,v.useRef)(Te);Ee.current=Te;let[De,Oe]=(0,v.useState)(null),[ke,Ae]=(0,v.useState)(null),[je,Me]=(0,v.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),Ne=(0,v.useRef)(`light`);Ne.current=[`dark`,`white`].includes(A||je)?A||je:`light`;let Pe=(0,v.useRef)(l);Pe.current=l;let Fe=(0,v.useRef)(c);Fe.current=c;let Ie=(0,v.useRef)(s);Ie.current=s;let Le=(0,v.useRef)(!1),[Re,ze]=(0,v.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),Be=()=>{let e={enabled:!!Ie.current,projectId:Ie.current?.projectId??null,placementId:Ie.current?.placementId??null};ze(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,v.useEffect)(()=>{Le.current||Be()},[!!s,s?.projectId,s?.placementId]);let Ve=Re.enabled,He=Re.projectId,Ue=Re.placementId,We=!!ke?.count&&!!(ke.dirty||ke.pending||ke.error);(0,v.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Me(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Ge=(0,v.useMemo)(()=>{try{let e=dW(t);return{value:e,signature:ht(e)}}catch(e){return{error:e.message}}},[t]);R.current={onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onError:g},ne.current=Ge;let[Ke,qe]=(0,v.useState)(null),Je=b?Ke?.handle===b&&Ke.allowed:!F||Ke?.content===F&&Ke.parent===I&&Ke.allowed;(0,v.useEffect)(()=>{if(!F&&!b)return;let e=!0,t=new AbortController;return qe(null),(b?T(b,{signal:t.signal}):Promise.all([F,...I?[I]:[]].map(e=>BU(e,{signal:t.signal})))).then(()=>{e&&qe({handle:b,content:F,parent:I,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&F&&gi(F,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(qe({handle:b,content:F,parent:I,allowed:!1,error:t.message}),R.current.onError?.(t))}),()=>{e=!1,t.abort()}},[F,I,b,oe]);let Ye=DH(P)&&P.files?P.files:null,[Xe,Ze]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!Ye||!Je){Ze(null);return}let e=!0,t=new AbortController;return Ze(null),Promise.resolve().then(()=>(bH(P),bi(()=>Promise.resolve().then(()=>(XU(),qU)),void 0))).then(({loadViewAssets:e})=>e(Ye,{signal:t.signal})).then(t=>{e&&Ze({files:Ye,assets:t})},t=>{e&&Ze({files:Ye,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[P,Ye,Je]);let Qe=Ye?Xe?.files===Ye?Xe:{loading:!0}:null,$e=JSON.stringify([...new Set(M.filter(e=>typeof e==`string`))].sort()),et=vt(F?.manifest?.inputs)?ht(Object.fromEntries(Object.entries(F.manifest.inputs).map(([e,t])=>[e,String(t?.type||``)]))):``,tt=[P,Qe,k,j,oe,a,r,ee,te,O,Ve,He,Ue,$e,et,!!F?.manifest?.sharedWork,F?.capability?.operation],nt=(0,v.useRef)(null);if(!nt.current||tt.some((e,t)=>!Object.is(e,nt.current.inputs[t]))){let e;try{if(Qe?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if(Qe?.error)throw Error(Qe.error);let t=$U(),n=$U(),r=OU();e={session:t,nativeTextToken:n,filming:!!r,html:yW(P,t,Ne.current,j,Ve,JSON.parse($e),n,!!F?.manifest?.sharedWork,F?.capability?.operation===`connection.execute`,{assets:Qe?.assets||{},filming:r,inputTypes:et?JSON.parse(et):null}),locked:JSON.parse($e)}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}nt.current={inputs:tt,document:e}}let rt=nt.current.document,it=rt?.session;(0,v.useEffect)(()=>{let e=L.current?.contentWindow;e&&it&&e.postMessage({channel:ZU,session:it,op:`zoom-mode`,mode:_e},`*`)},[_e,it]),(0,v.useEffect)(()=>{if(!O||!it)return;let e=null,t=()=>{e=null;let t=L.current?.contentWindow;t&&t.postMessage({channel:ZU,session:it,op:`zoom-space`,height:SU(L.current)},`*`)},n=()=>{clearTimeout(e),e=setTimeout(t,200)};return addEventListener(`resize`,n),()=>{clearTimeout(e),removeEventListener(`resize`,n)}},[O,it]);let at=(0,v.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[rt.session]),ot=(0,v.useRef)(n);ot.current=n??at;let st=(0,v.useRef)(n==null);st.current=n==null;let ct=(0,v.useRef)({session:null,count:0}),lt=(0,v.useRef)(null),ut=(0,v.useRef)(null),dt=(0,v.useRef)(null),ft=(0,v.useRef)(null),pt=(0,v.useRef)(null),mt=(0,v.useRef)(null),_t=(0,v.useRef)(null);mt.current={key:r,peers:i,actorId:a};let B=(0,v.useRef)(null),yt=(0,v.useRef)(null);yt.current={input:Ge.signature,error:Ge.error,view:P,policyContent:F,policyParent:I,resetKey:k,appearance:j,policyReady:Je};let bt=(0,v.useRef)(null);bt.current=ht([N?.projectId,N?.placementId,N?.sourceDigest,a].map(e=>e??null));let[xt,St]=(0,v.useState)(null),Ct=ht([jt(),a,bt.current,rt.session,Ge.signature,Je].map(e=>e??null));(0,v.useEffect)(()=>{let e=!0;if(St(null),!N?.projectId||!N?.placementId||!N?.sourceDigest||Ge.error||!Je||a!==jt())return()=>{e=!1};let t=Ct;return gt(Ge.value).then(n=>{e&&St({basis:t,value:{version:1,actorId:a,projectId:N.projectId,placementId:N.placementId,sourceDigest:N.sourceDigest,inputDigest:n}})},()=>{e&&St(null)}),()=>{e=!1}},[Ct]),xt?.basis===Ct&&xt.value;let[wt,Tt]=(0,v.useState)(null),Et=(0,v.useRef)(null),Ot=(0,v.useRef)(null),[kt,At]=(0,v.useState)(null),[Mt,Nt]=(0,v.useState)(!1),[Pt,Ft]=(0,v.useState)(!1),[It,Lt]=(0,v.useState)(null);It&&It.actor===a&&It.runtimeActor===jt()&&It.identity===bt.current&&It.session===rt.session&&Object.keys(It.authority).every(e=>It.authority[e]===yt.current[e])&&It.evidence,{...N},F?.manifest?.id,F?.manifest?.version,rt.session,Ge.signature,ot.current?.canEdit,{...N},rt.session,Ge.signature,ot.current?.canEdit,(0,v.useEffect)(()=>{if(Tt(null),At(null),Ft(!1),Nt(!1),Lt(null),re(``),he(null),Oe(null),Ae(null),rt.error||rt.loading||!Je)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=0,p=0,m=new Set,h=-1/0,g=-1/0,_=e=>{e.isTrusted&&(h=Date.now())};globalThis.document.addEventListener(`pointerdown`,_,!0),globalThis.document.addEventListener(`keydown`,_,!0);let v,y=0,b=null,x=[],S=null,T=0,D=!1,k=0,A=new Set,j=0,M=null,I=0,z=0,ie=null,oe=DH(P),se=null,ue=()=>{se&&globalThis.document.fullscreenElement!==se&&(se=null,ge({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,ue);let fe=()=>{let t;return t=jz(F,{onStatus:n=>{e&&v===t&&de(n)},onLive:(n,r)=>{e&&v===t?L.current?.contentWindow?.postMessage({channel:ZU,session:rt.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&v===t&&pe(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};v=fe(),ce.current=v,de(null),pe(null);let me=()=>{if(!e||!ot.current?.canEdit)return;let t=v;v=fe(),ce.current=v,b=null,de(null),Promise.resolve(t.close()).catch(()=>{})};le.current=me;let ge=t=>{e&&L.current?.contentWindow?.postMessage({channel:ZU,session:rt.session,...t},`*`)},_e=null,ve=0,ye=(e,t)=>{let n=ut.current,r=L.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};ye(null,null),dt.current=n=>{!e||!t||typeof n!=`string`||_e&&Date.now()-_e.at<1e3||(_e={id:`locate-`+ ++ve,control:n,at:Date.now()},ge({op:`locate-view-control`,id:_e.id,control:n}))};let Se=new Map,Te=new Set,De=0,ke=!1,je=(e,t)=>new Promise(n=>{let r=`film-`+ ++De,i=setTimeout(()=>{Se.delete(r),n(null)},6e3);Se.set(r,e=>{clearTimeout(i),Se.delete(r),n(e)}),ge({op:e,id:r,...t})}),Me=rt.filming&&L.current?kU({element:L.current,placementId:N?.placementId||null,capture:e=>je(`capture-view`,e),locate:e=>je(`locate-view-control`,{control:e}),get drawn(){return ke},onChange:e=>(Te.add(e),()=>Te.delete(e))}):null,Re=null,ze=null,We=0,Ge=!1,Ke=a,qe=yt.current,Ye=bt.current,Xe=(t,n)=>{if(!e||Ge||t?.signal?.aborted||jt()!==Ke||bt.current!==Ye||ze&&ne.current.signature!==ze.inputIdentity||Re&&ne.current.signature!==Re.inputIdentity&&ne.current.signature!==n||Object.keys(qe).filter(e=>e!==`input`).some(e=>qe[e]!==yt.current[e]))throw Ge=!0,Ft(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Ze=e=>{if(!Re)return;let t=Re;Re=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Nt(!1),t.reject(e)};Ot.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Xe(r),!t||Re)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(++We),c=()=>{Ge=!0,Ft(!1),i?.abort(),Ze(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,te);Re={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`&&Nt(!0),ge({op:e,id:s,...n})}catch(e){o(e)}})},Et.current={request:(e,n)=>new Promise((r,i)=>{try{if(Xe(n),!t||Re||ze||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++We),o=()=>{Ge=!0,Ft(!1),ze?.id===a&&(ze=null,Nt(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,te);ze={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}),Nt(!0),ge({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let Qe=()=>{if(Ge)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return Re?.op===`dispatch-view-control`?(Xe(Re.context),Re.context):null},$e=!1,et=0,tt=[],nt=0,it=!1,at=0,ct=[],gt=0,xt=0,St=[],Ct=null,wt=!1,kt={projectId:He,placementId:Ue,actorId:a},Mt=()=>e&&Ie.current?.projectId===kt.projectId&&Ie.current?.placementId===kt.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=Ie.current?.projectId&&a?$n({projectId:Ie.current.projectId,actorId:a,headers:er,onChange:e=>{if(Mt()){if(e.kind===`revoked`){wt=!0,ge({op:`shared-view`,value:{...ot.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||Ct===null&&(Ct=setTimeout(()=>{Ct=null,t&&Mt()&&!wt&&ge({op:`text-refresh`})},100)))}}}):null,Rt=Fe.current?.projectId&&a?$n({projectId:Fe.current.projectId,actorId:a,headers:er,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(nt++,ge({op:`shared-work-refresh`}))}}):null,zt=()=>{t&&ge({op:`theme`,mode:Ne.current})};_t.current=zt;let Bt=`[]`,Vt=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=mt.current,i=!st.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=VH(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!==Bt&&(Bt=a,ge({op:`peer-cursors`,peers:i}))};pt.current=Vt,window.addEventListener(`stillmade:cursor-preferences`,Vt),window.addEventListener(`storage`,Vt);let Ht=null,Ut=()=>{let e=L.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}},Wt=()=>{Ht&&(Ht.bounds=Ut())},Gt=()=>{Ht&&(Ht=null,window.removeEventListener(`scroll`,Wt,{capture:!0}),window.removeEventListener(`resize`,Wt))},Kt=n=>{let r=n.detail;e&&r?.root?.contains?.(L.current)&&(r.action===`start`&&t&&!Ht?(Ht={bounds:Ut()},window.addEventListener(`scroll`,Wt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Wt),ge({op:`pick-start`})):r.action===`stop`&&Ht&&(Gt(),ge({op:`pick-stop`})))};window.addEventListener(GH.control,Kt);let qt=e=>{re(e),R.current.onError?.(Object.assign(Error(e),{shown:!0}))},Jt=()=>{e&&(clearInterval(M),ie?.disconnect(),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),qt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))};lt.current=oe?()=>{e&&(clearInterval(M),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),qt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))}:null;let Yt=()=>{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(`#${rt.session}`));ie=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>=SH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Jt()}});try{ie.observe({type:`longtask`})}catch{ie=null}},Xt=()=>{I=Date.now(),M=setInterval(()=>{if(!e)return clearInterval(M);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-I>8e3)return Jt();ge({op:`ping`,id:String(++z)})},2e3)};ae(!0);let Zt=setTimeout(()=>{e&&!t&&(ae(!1),qt(C()?w():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))},C()?5e3:15e3),Qt=e=>{let t=o;t&&(Lt(null),o=null,t.controller.abort(),e&&ge({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},$t=()=>{if(!t)return;let e=ne.current;if(e.error){Qt(`Preview input is unavailable.`),qt(e.error);return}s!==e.signature&&(Qt(`Preview input changed. Use its current image.`),s=e.signature,ge({op:`input`,input:e.value}))};B.current=$t;let en=null,tn=!1,nn=0,rn=[],an=null,on=0,sn=null,cn=Yn(()=>{if(st.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(an)return an.promise;let n=String(++on),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{an?.id===n&&(an=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return an={id:n,promise:a,resolve:r,reject:i,timer:o},ge({op:`flush-shared`,id:n}),a}),ln=()=>{if(t&&ot.current)try{let e=dW(ot.current),t=ht(e);if(t===en)return;en=t,ge({op:`shared-view`,value:e})}catch(e){qt(e.message)}};ft.current=ln;let un=t=>{e&&st.current&&(ot.current.outputs=t,ln())},dn=r=>{let s=r.data;if(oe&&e&&vt(s)&&s.op===`navigated`&&s.channel===ZU&&s.session===rt.session&&(r.source===null||r.source===L.current?.contentWindow)){lt.current?.();return}if(!e||r.source!==L.current?.contentWindow||!vt(s)||s.channel!==ZU||s.session!==rt.session)return;if(s.op===`document-ready`){n||(n=!0,ge({op:`document`,html:rt.html}));return}if(s.op===`view-changed`){ke=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>vt(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of Te)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&Se.has(s.id)){let e=Se.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:vt(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`){we.current(s.step===`auto`?`auto`:CU(Ce.current,s.step===`bigger`?nU:-nU));return}if(s.op===`media-stage`){let e=L.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`){se=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{se=null})}catch{se=null}}}else if(t.fullscreenElement===e){se=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){be(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,ae(!1),clearTimeout(Zt),ge({op:`zoom-mode`,mode:xe.current}),O&&ge({op:`zoom-space`,height:SU(L.current)}),oe&&(Xt(),Yt()),zt(),$t(),ln(),Vt(),ge({op:`inspect-view-controls`,offset:0}),ge({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!an||s.id!==an.id)return;let e=an;an=null,clearTimeout(e.timer);let t=s.error||sn;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===L.current&&e-j>=300&&(j=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){oe&&typeof s.id==`string`&&(I=Date.now());return}if(s.op===`unresponsive`){oe&&Jt();return}if(s.op===`interface-error`){qt(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;vt(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)&&Oe(e);return}if(s.op===`text-recovery-status`){let e=s.status;Ve&&vt(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`&&Ae(e);return}if(!t)return;if(s.op===`pick-hover`){if(!Ht)return;let e=XH(s.hover),t=Ht.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(GH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!Ht)return;Gt();let e=s.op===`pick-result`?ZH(s.target):null;e?window.dispatchEvent(new CustomEvent(GH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(GH.cancel));return}if(s.op===`named-text-controls`){if(s.token===rt.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=dW(s.snapshot);e.every(e=>vt(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`)&&Tt(e)}return}if(s.op===`named-text-result`){let e=ze;if(!e||s.id!==e.id||s.token!==rt.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{ze=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Nt(!1)}return}if(s.op===`view-controls`){try{let e=dW(s.snapshot);if(!vt(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=>!vt(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(At(e),Ft(!Ge),Re?.op===`inspect-view-controls`&&e.offset===Re.offset){let e=Re;Xe(e.context),Re=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Ze(e)}return}if(s.op===`view-control-rect`){if(!_e||s.id!==_e.id)return;let{control:e}=_e,t=s.rect;_e=null,ye(e,vt(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`){Ze(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(Re?.op!==`dispatch-view-control`||s.id!==Re.id)return;let e=Re;try{if(Xe(e.context),s.error)throw Error(String(s.error).slice(0,1e3));Re=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Nt(!1),e.resolve()}catch(e){Ze(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=et)return;et=Number(s.id);let t=e=>ge({op:`connected-app-result`,id:s.id,...e}),n=Pe.current,r=yt.current;tt=tt.filter(e=>Date.now()-e<6e4);try{if(F?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Dt(s.operation,dW(s.args));if(i.operation!==`tasks`&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);if($e||tt.length>=30)throw Error(`Wait for the current task request.`);$e=!0,tt.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Pe.current?.projectId||n.placementId!==Pe.current?.placementId||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:dW(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{$e=!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=Fe.current,n=yt.current,r=nt,i=e=>ge({op:`shared-work-result`,id:s.id,...e});try{if(!F?.manifest?.sharedWork||!F.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(ct=ct.filter(e=>Date.now()-e<6e4),it||ct.length>=60)throw Error(`Wait for the current media preview.`);it=!0,ct.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==nt||Object.keys(n).some(e=>n[e]!==yt.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=Fe.current,r=yt.current,i=nt;ct=ct.filter(e=>Date.now()-e<6e4);try{if(!F?.manifest?.permissions?.project?.includes(`work.shared`)||!F.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,dW(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);if(it||ct.length>=60)throw Error(`Wait for the current shared-work request.`);it=!0,ct.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==Fe.current?.projectId||n.placementId!==Fe.current?.placementId||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==nt){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:dW(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)<=xt)return;xt=Number(s.id);let e=e=>ge({op:`text-result`,id:s.id,...e}),t=Ie.current,n=ne.current.signature,r=yt.current;if(St=St.filter(e=>Date.now()-e<6e4),!Ve||!Mt()||!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(gt>=16||St.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!Mt()||ne.current.error||ne.current.signature!==n||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(wt||s.action!==`read`&&!ot.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=dW(s.body),!vt(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}gt++,St.push(Date.now()),Promise.resolve().then(async()=>{if(i(),Qe()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=ze,n;if(e&&s.action!==`read`){if(Xe(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==rt.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 ot.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:dW(t)})}).catch(t=>e({error:Pt(t)})).finally(()=>{gt--});return}if(s.op===`cursor`){let e=s.cursor;if(vt(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=L.current?.getBoundingClientRect(),n=VH(e.anchor),r=mt.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&&!st.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)<=nn)return;nn=Number(s.id);let t=e=>{sn=e.error?String(e.error):null,ge({op:`shared-view-result`,id:s.id,...e})};if(rn=rn.filter(e=>Date.now()-e<6e4),tn||rn.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!ot.current?.canEdit||!st.current&&typeof R.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=dW(s.request),new TextEncoder().encode(JSON.stringify(n)).length>ar.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}tn=!0,rn.push(Date.now()),Promise.resolve().then(()=>{if(!e||!ot.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if(Qe(),st.current){ot.current.state=or(ot.current.state,n),ln();return}let t=Qe();return R.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{tn=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&Ee.current?.(s.height),O&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&he(Math.max(280,Math.min(3e4,s.height)));return}if(s.op===`live-ack`){v?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=y)return;y=Number(s.id);let t=e=>ge({op:`desktop-result`,id:s.id,...e});if(x=x.filter(e=>Date.now()-e<6e4),b||x.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=dW(s.args||{}),JSON.stringify(n).length>131072||!vt(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&&!ot.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=fW(e),i=[];try{i=mW(ne.current?.value).map(fW)}catch{}if(!r||!(v.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:v};x.push(Date.now()),b=i,Promise.resolve().then(()=>{if(!e||i.native!==v||r&&!ot.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if(Qe()&&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 mW(ne.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==v||r&&!ot.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:dW(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{b===i&&(b=null)});return}if(s.op===`add-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=T)return;T=Number(s.id);let t=e=>ge({op:`add-files-result`,id:s.id,...e});try{let n=sW(F?.manifest,s.port);if(!ot.current?.canEdit)throw Error(`You can view this project but not add files to it.`);if(rt.locked.includes(n.name))throw Error(`This input comes from an earlier Step, so files cannot be added to it here.`);if(Qe())throw Error(`Only a person adds files. Chat cannot open a file picker.`);if(typeof R.current.onAddFiles!=`function`)throw Error(`Adding files is unavailable here.`);if(S)throw Error(`Files are already being added.`);let r=s.gesture,i=globalThis.navigator?.userActivation;if(!vt(r)||!Number.isInteger(r.id)||r.id<=0||A.has(r.id)||!Number.isFinite(r.age)||r.age<0||r.age>QU||i&&!i.isActive||globalThis.document.activeElement!==L.current)throw Error(`Add files from a click or key press in this screen.`);A.add(r.id);let a={picker:lW(n)};S=a,a.picker.then(t=>{if(!e||S!==a)throw Error(`This Block closed before the files were added.`);if(!t.length)return{added:0};if(!ot.current?.canEdit)throw Error(`You can view this project but not add files to it.`);return R.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(()=>{S===a&&(S=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=sW(F?.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(!ot.current?.canEdit)throw Error(`You can view this project but not change its files.`);if(rt.locked.includes(t.name))throw Error(`This input comes from an earlier Step, so its files cannot be changed here.`);if(Qe())throw Error(`Only a person changes files. Chat cannot remove or move them.`);if(typeof R.current.onChangeFiles!=`function`)throw Error(`Changing files is unavailable here.`);if(D)throw Error(`Files are already being changed.`);let n=s.gesture,r=globalThis.navigator?.userActivation;if(!vt(n)||!Number.isInteger(n.id)||n.id<=0||A.has(n.id)||!Number.isFinite(n.age)||n.age<0||n.age>QU||r&&!r.isActive||globalThis.document.activeElement!==L.current)throw Error(`Remove or move files from a click or key press in this screen.`);let i=vt(s.edit)&&s.edit.op===`remove`?{op:`remove`,index:s.edit.index}:vt(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(cW(a,i),ht(dW(s.item??null))!==ht(a[i.op===`move`?i.from:i.index]))throw Error(`These files changed. Look at them again, then try again.`);A.add(n.id),D=!0,Promise.resolve().then(()=>R.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(()=>{D=!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(Qe())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(oe&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);let t=dW(s.outputs),n=R.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);gW(t,ne.current.value,v),Promise.resolve(n(t)).then(t=>{let n=dW(t);un(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===`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;Lt(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&&Qt(),d.length>=uH.imagePreviewsPerMinute){++p<=3&&n({error:`Image preview limit reached. Wait a minute before trying again.`}),p===4&&(qt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,Qt(),i?.abort(),L.current&&(L.current.src=`about:blank`));return}d.push(r);let c;try{if(c=t?dW(s.value):_W(s.value),t&&(!vt(c)||![`video`,`audio`].includes(c.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof c[e]==`string`&&c[e].length>0&&c[e].length<=32768)))throw Error(`Keep the complete audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let u=t&&v?.authorizesMedia?.(c)?(e,t)=>qn(e,t):t?R.current.onPreviewMedia:R.current.onPreviewImage;if(typeof u!=`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 f=new AbortController,m=yt.current,h={controller:f,id:s.id,media:t};o=h;let g=bt.current,_=a,y=jt(),b=()=>{if(f.signal.aborted||y!==jt()||g!==bt.current||Object.keys(m).some(e=>m[e]!==yt.current[e]))throw Error(`Image preview input or workspace changed.`)},x=setTimeout(()=>{e&&o===h&&Qt(`Image preview timed out. Try a smaller image.`)},uH.imagePreviewMs);f.signal.addEventListener(`abort`,()=>clearTimeout(x),{once:!0}),Promise.resolve().then(()=>(b(),u(c,{signal:f.signal}))).then(r=>{if(e&&!f.signal.aborted&&o===h){if(b(),t&&r?.kind!==c.kind)throw Error(`The host returned a different media kind.`);let e=t?Gn(r):vW(r);b(),typeof c.assetId==`string`&&c.assetId.length<=512&&typeof c.versionId==`string`&&c.versionId.length<=512&&Lt({actor:_,runtimeActor:y,identity:g,session:rt.session,authority:m,evidence:{assetId:c.assetId,versionId:c.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(x),o===h&&(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 _=e=>ge({op:`result`,id:s.id,...e});if(oe&&!ot.current?.canEdit){_({error:`Shared editing is unavailable or read only.`});return}let C=Date.now();if(u=u.filter(e=>C-e<6e4),i||u.length>=uH.runsPerMinute){++f<=3&&_({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),f===4&&(qt(`Preview paused after too many requests. Reset it to continue.`),e=!1,Qt(),i?.abort(),L.current&&(L.current.src=`about:blank`));return}let w;try{if(!vt(s.input))throw Error(`Expected input values`);w=dW(s.input)}catch(e){_({error:e.message});return}u.push(C),re(``);let M=new AbortController;i=M,Le.current=!0,Re?.context.signal?.addEventListener(`abort`,()=>M.abort(),{once:!0});let N=setTimeout(()=>{e&&i===M&&(M.abort(),i=null,_({error:ee?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},ee?te:15e3);M.signal.addEventListener(`abort`,()=>clearTimeout(N),{once:!0});let P=Re?.op===`dispatch-view-control`?Re:null,z=P?async e=>{if(Re!==P||i!==M||M.signal.aborted||!vt(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||ht(e.taskFence)!==ht(P.context.taskFence)||ht([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==Ye||ht(dW(e.beforeInput))!==P.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=ht(dW(e.input));for(let e=0;e<25&&ne.current.signature!==t;e++)if(Xe(P.context,t),await new Promise(e=>setTimeout(e,10)),Re!==P||i!==M||M.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Xe(P.context,t),ne.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);P.inputIdentity=t}:void 0,ie=vt(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=QU&&!m.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===L.current&&Date.now()-h>QU&&Date.now()-g>QU;ie&&(m.add(s.gesture.id),g=Date.now()),Promise.resolve().then(()=>R.current.onRun(w,{...Qe(),signal:M.signal,userActivated:ie,...z?{onInputCommitted:z}:{},...F?.manifest?.desktopTools?.length?{nativeDesktopSession:v}:{}})).then(t=>{if(e&&!M.signal.aborted){if(!vt(t))throw Error(`Block execution must return named outputs`);let e=dW(t);un(e),_({outputs:e})}},t=>{e&&!M.signal.aborted&&_({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!M.signal.aborted&&_({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(N),i===M&&(i=null),Le.current=!1,setTimeout(()=>{e&&!Le.current&&Be()},250)})};return window.addEventListener(`message`,dn),()=>{S?.picker.cancel(),globalThis.document.removeEventListener(`fullscreenchange`,ue),se&&globalThis.document.fullscreenElement===se&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),se=null,dt.current=null,ye(null,null),Me?.();for(let e of[...Se.values()])e(null);ze&&=(clearTimeout(ze.timer),ze.context.signal?.removeEventListener(`abort`,ze.abort),ze.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,_,!0),globalThis.document.removeEventListener(`keydown`,_,!0),Et.current=null,Ze(Error(`The declared interface was closed.`)),Ot.current=null,It?.(),Rt?.(),clearTimeout(Ct),cn(),an&&=(clearTimeout(an.timer),an.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout(Zt),clearInterval(M),ie?.disconnect(),ge({op:`dispose`}),e=!1,v.close(),ce.current===v&&(ce.current=null),le.current===me&&(le.current=null),Qt(),i?.abort(),Le.current=!1,window.removeEventListener(`message`,dn),window.removeEventListener(`stillmade:cursor-preferences`,Vt),window.removeEventListener(`storage`,Vt),window.removeEventListener(GH.control,Kt),Gt(),pt.current=null,B.current=null,ft.current=null}},[rt,Je,ee,te,O,r,a,He,Ue]),(0,v.useEffect)(()=>{B.current?.()},[t]),(0,v.useEffect)(()=>{ft.current?.(),n?.canEdit===!1&&Promise.resolve(ce.current?.close()).catch(()=>{})},[n,Je]),(0,v.useEffect)(()=>{pt.current?.()},[i,r,a,n]),(0,v.useEffect)(()=>{_t.current?.()},[A,je]);let Rt=!!globalThis.stillmadeDesktop?.blockDesktop,zt=ue?.camera&&ue?.microphone?`camera and microphone`:ue?.camera?`camera`:`microphone`;return(0,V.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[ue?.kind===`live`&&ue.awaitingStart&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:`Ready to share your ${zt} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:`Start ${zt}`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Cancel`})]}),ue?.kind===`live`&&ue.active&&(0,V.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,V.jsx)(`strong`,{children:`${zt[0].toUpperCase()}${zt.slice(1)} on`}),(0,V.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.stop,children:`Turn off ${zt}`})]}),ue?.awaitingStart&&(ue.kind===`folder`||ue.kind===`folder-access`)&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:ue.kind===`folder`?`This Block asks for a folder to ${ue.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${ue.folder} again for this Block.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:ue.kind===`folder`?`Choose folder`:`Allow`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.cancel?ue.cancel():ce.current?.close(),children:`Cancel`})]}),ue?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(ue.kind)&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:ue.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:ue.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:ue.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,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:ue.kind===`camera`?`Start camera recording`:ue.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Cancel`})]}),ue?.active&&ue.kind!==`live`&&(0,V.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,V.jsxs)(`strong`,{children:[ue.ended?`Recording stopped`:`Recording`,` `,ue.kind||`media`]}),(0,V.jsxs)(`span`,{children:[` · `,ue.ended?ue.message:Rt?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:Rt?`Cancel recording and revoke access`:`Discard recording`})]}),Rt&&ue?.closed&&F?.manifest?.permissions?.desktop?.length>0&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:!Je||!ot.current?.canEdit,onClick:()=>le.current?.(),children:`Reopen desktop access`}),Rt&&!ue?.closed&&!ue?.active&&F?.manifest?.permissions?.desktop?.length>0&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Revoke this Block’s desktop access`}),rt.loading?(0,V.jsx)(_r,{label:`Loading the interface…`}):rt.error?(0,V.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,rt.error]}):Je?(0,V.jsxs)(V.Fragment,{children:[ie&&!z&&(0,V.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,V.jsx)(`iframe`,{ref:L,onLoad:()=>{ct.current.session!==rt.session&&(ct.current={session:rt.session,count:0}),++ct.current.count>2&&lt.current?.()},title:S,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${x(`/block-ui-sandbox.html`)}#${rt.session}`,style:{width:`100%`,height:O&&me||D,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...z?{display:`none`}:{}}},rt.session),(0,V.jsx)(`span`,{ref:ut,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}}),ye?.supported&&!z&&(0,V.jsx)(wU,{zoom:ye.zoom,mode:_e,onChange:Se})]}):(0,V.jsx)(`p`,{role:Ke?.error?`alert`:`status`,children:Ke?.error||`Checking Block safety…`}),De?.count>0&&(De.error?(0,V.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:De.error}):De.dirty||De.pending?(0,V.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),ke?.count>0&&(ke.error||ke.dirty||ke.pending)?(0,V.jsxs)(`div`,{className:`bs-notice`,role:ke.error?`alert`:`status`,children:[(0,V.jsx)(`p`,{children:ke.error||`Saving shared text…`}),ke.error&&(0,V.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),ke.retryable&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:ke.pending>0||!ot.current?.canEdit,onClick:()=>L.current?.contentWindow?.postMessage({channel:ZU,session:rt.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(z||Ke?.error)&&(0,V.jsxs)(V.Fragment,{children:[z&&(0,V.jsx)(`p`,{role:`alert`,children:z}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:We,onClick:()=>{We||se(e=>e+1)},children:`Reload`})]}),(0,V.jsx)(bW,{activity:fe,declaresFolders:(F?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:ce})]})}ut();var SW=50,CW=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var wW=e=>e==null?``:typeof e==`number`?CW.format(e):String(e);function TW(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 EW({value:e,label:t=`Table`}){let[n,r]=(0,v.useState)(0);if(!Ye(e))return(0,V.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/SW)),a=Math.min(n,i-1),o=e.rows.slice(a*SW,a*SW+SW),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,V.jsxs)(`div`,{className:`bd-table`,children:[(0,V.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,V.jsxs)(`table`,{children:[(0,V.jsx)(`thead`,{children:(0,V.jsx)(`tr`,{children:e.columns.map(e=>(0,V.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,V.jsx)(`tbody`,{children:o.map((t,n)=>(0,V.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,V.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:wW(t[e])},e))},a*SW+n))})]})}),(0,V.jsxs)(`div`,{className:`bd-bar`,children:[(0,V.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>TW(new Blob([$e(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}Tt(),ut();var DW=new Set([`image`,`audio`,`video`]),OW=e=>DW.has(e?.kind)&&typeof e.url==`string`,kW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,AW=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)},jW=50,MW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),NW=e=>{if(!vt(e))return e;let t=MW(e);return t.length===1&&(Array.isArray(e[t[0]])||vt(e[t[0]]))?NW(e[t[0]]):e},PW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),FW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``);function IW(e){if(e.length<2||!e.every(e=>vt(e)&&MW(e).every(t=>PW(e[t]))))return null;let t=[...new Set(e.flatMap(MW))];if(!t.length||t.length>6)return null;let n={columns:t.map(AW),rows:e.map(e=>Object.fromEntries(MW(e).map(t=>[AW(t),typeof e[t]==`boolean`?FW(e[t]):e[t]])))};return Ye(n)?n:null}function LW({value:e,renderMedia:t,depth:n=0}){let r=NW(e);if(PW(r))return(0,V.jsx)(`span`,{children:FW(r)});if(OW(r))return t?.(r)??null;if(Ye(r))return(0,V.jsx)(EW,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,V.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(OW)&&IW(r);return e?(0,V.jsx)(EW,{value:e,label:`Results`}):n>=3?(0,V.jsx)(`span`,{children:kW(r.length,`item`)}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,jW).map((e,r)=>(0,V.jsx)(`li`,{children:(0,V.jsx)(LW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>jW&&(0,V.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-jW,` more.`]})]})}if(!vt(r))return null;let i=MW(r);return i.length?n>=3?(0,V.jsx)(`span`,{children:kW(i.length,`detail`)}):(0,V.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,V.jsxs)(v.Fragment,{children:[(0,V.jsx)(`dt`,{children:AW(e)}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(LW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,V.jsx)(`span`,{className:`sm-data-none`,children:`None`})}function RW(e,t){let n=(0,v.useRef)(t),r=uU(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 zW({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}=RW(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=fU(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,V.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,V.jsx)(vU,{name:`imageOff`,size:24})}):(0,V.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,V.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,V.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var BW=e=>String(e).padStart(2,`0`),VW=/^(\d{4})-(\d{2})-(\d{2})$/,HW=/^([01]\d|2[0-3]):([0-5]\d)$/,UW=e=>{let t=VW.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},WW=e=>{let t=UW(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},GW=e=>{let{year:t,month:n,day:r}=UW(e);return new Date(Date.UTC(t,n-1,r))},KW=(e,t)=>{let n=GW(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},qW=(e,t)=>{let{year:n,month:r,day:i}=UW(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()}-${BW(a.getUTCMonth()+1)}-${BW(Math.min(i,o))}`},JW=/(?:time|when|start|schedule|post|send|publish|remind)/i,YW=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||JW.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),XW=e=>`${QW(e.slice(0,10))}${e[10]===`T`?` · ${$W(e.slice(11,16))}`:``}`;function ZW({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${BW(t.getMonth()+1)}-${BW(t.getDate())}`}function QW(e,t=ZW()){return GW(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function $W(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 eG(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${BW(Math.floor(n*e/60))}:${BW(n*e%60)}`)}function tG(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 nG({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=tG(l,u,p,m),_=ZW({utc:i}),y=WW(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=KW(d,w[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=qW(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=GW(d).getUTCDay();t=KW(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(x(t)))},E=d||y||_,{year:D,month:O}=UW(E),k=`${D}-${BW(O)}-01`,A=new Date(Date.UTC(D,O,0)).getUTCDate(),j=GW(k).getUTCDay(),M=GW(k).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),N=KW(k,-1),P=qW(k,1),F=Array.from({length:A},(e,t)=>`${D}-${BW(O)}-${BW(t+1)}`);return(0,V.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,V.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${y?QW(y,_):`not chosen`}`,disabled:a,onClick:S,children:[(0,V.jsx)(vU,{name:`calendar`,size:16}),(0,V.jsx)(`span`,{children:y?QW(y,_):s}),(0,V.jsx)(vU,{name:`chevronDown`,size:13})]}),l&&(0,V.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,V.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,V.jsx)(`b`,{children:M}),(0,V.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,V.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&N<n,onClick:()=>f(x(qW(E,-1))),children:(0,V.jsx)(vU,{name:`chevronLeft`,size:16})}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&P>r,onClick:()=>f(x(qW(E,1))),children:(0,V.jsx)(vU,{name:`chevronRight`,size:16})})]})]}),(0,V.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:T,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,V.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),j>0&&(0,V.jsx)(`span`,{style:{gridColumn:`span ${j}`},"aria-hidden":`true`}),F.map(e=>(0,V.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":GW(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,V.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function rG({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=tG(s,c,d,f),g=HW.test(e||``)?e:null,_=g&&!eG(r).includes(g)?[...eG(r),g].sort():eG(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,V.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,V.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?$W(g):`not chosen`}`,disabled:i,onClick:b,children:[(0,V.jsx)(vU,{name:`clock`,size:16}),(0,V.jsx)(`span`,{children:g?$W(g):o}),(0,V.jsx)(vU,{name:`chevronDown`,size:13})]}),s&&(0,V.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,V.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:$W(e)},e))})]})}function iG({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=WW(e?.slice(0,10))?e.slice(0,10):``,d=HW.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?eG(l).find(e=>e>=p)||p:null;return(0,V.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,V.jsx)(nG,{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,V.jsx)(rG,{value:d,onChange:e=>t?.(`${u||f||ZW({utc:i})}T${e}`),min:(u||f||ZW({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}Tt();var aG=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),oG=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),sG=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),cG=(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}),lG=(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":cG(`Nano Banana 2`,{aspectRatios:aG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":cG(`Nano Banana 2 Lite`,{aspectRatios:aG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":cG(`Nano Banana Pro`,{aspectRatios:aG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":cG(`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-1.5":cG(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":cG(`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":cG(`Seedream 4.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`,`4:3`,`3:4`],resolutions:[`2K`,`4K`],seed:!0})}),Object.freeze({"seedance-2.0":lG(`Seedance 2.0`,{aspectRatios:oG,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:sG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":lG(`Seedance 2.0 Fast`,{aspectRatios:oG,resolutions:[`480p`,`720p`],durations:sG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":lG(`Seedance 2.0 Mini`,{aspectRatios:oG,resolutions:[`480p`,`720p`],durations:sG,lastFrame:!0,seed:!0,nativeAudio:!0}),"kling-v3-turbo":lG(`Kling 3.0 Turbo`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[5,10]}),"wan-2.6-flash":lG(`Wan 2.6 Flash`,{aspectRatios:[`16:9`,`9:16`,`1:1`],durations:[3,4,5],requiresFirstFrame:!0}),"veo-3.1-lite":lG(`Veo 3.1 Lite`,{aspectRatios:[`16:9`,`9:16`],resolutions:[`720p`,`1080p`],durations:[4,6,8],lastFrame:!0,nativeAudio:!0}),"vidu-q3-turbo":lG(`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":lG(`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})}),Tt();var uG=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`}),dG=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,fG=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),pG=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),mG=[[`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`])]],hG={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`]},gG=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),_G=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function vG(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=gG(e);return uG[n]||(n?_G(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=gG(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=>dG.test(e)||fG.has(e)||mG.some(([,t])=>t.has(e)));if(n&&dG.test(n))return`read`;if(e.some(e=>fG.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>pG.has(e)))return`post`;let r=n&&mG.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function bG(e){let t=vG(e),n=yG(e),[r,i]=hG[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var xG=e=>bG(e).verbs,SG=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…`]}),CG=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase(),wG=new Set([`output`,`outputs`,`result`,`results`,`value`,`data`,`out`]),TG=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 EG(e){let t=e?.manifest;if(!t)return null;let n=String(t.name||``).trim(),r=n.split(/\s+/)[0].toLowerCase();if(TG.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&&!wG.has(CG(a))&&!/action/i.test(String(o?.type||``)),c=o?.label?CG(o.label):CG(s?a:n);return c?[`Make ${c}`,`Making ${c}…`]:null}function DG(e,t){let n=t?.manifest?.action,r=typeof n?.label==`string`?n.label.trim():``;return r?[r,n.running||SG[e]?.[1]||`Working…`]:e===`connection.execute`&&t?xG(t):SG[e]||EG(t)||[`Make the result`,`Making the result…`]}var OG=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function kG(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||DG(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${OG(t.credits)}`:r||t?.credits===0?`${s} · ${OG(0)}`:s}var AG=new Set([`image`,`image[]`,`video`,`video[]`,`audio`,`audio[]`,`asset`,`asset[]`,`file`]),jG=3,MG=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();function NG(e){let t=String(e||``).trim();if(!t)return``;let n=(t.match(/^.+?[.!?](?=\s|$)/)||[t])[0].trim();return n.length<=160?n:``}function PG(e,{inputs:t,labels:n={},groups:r=[]}={}){let i=t||Object.entries(e?.inputs||{}).filter(([,e])=>!e?.context),a=i.length>0&&i.length<=jG&&!r.length,o=i.find(([,e])=>e?.required!==!1&&e?.primary)||i.find(([,e])=>e?.required!==!1)||i[0],s=o?MG(n[o[0]]||o[1]?.label||o[0]):``;return{focused:a,heading:s?`Add your ${s}`:String(e?.action?.label||e?.name||``).trim(),line:NG(e?.description),media:!!o&&AG.has(o[1]?.type)}}var FG=new Set([`text`,`script`,`transcript`,`brief`,`json`,`metadata`,`research`,`document`,`table`]),IG=e=>{let t=String(e||``).replace(/\[\]$/,``);return FG.has(t)?`text`:[`video`,`image`,`audio`].includes(t)?t:void 0},LG=/^\s*(\d+(?:\.\d+)?)\s*[:/x]\s*(\d+(?:\.\d+)?)\s*$/;function RG(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=IG(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=>LG.test(String(e||``))),c=LG.exec(String(s||``));return{kind:a,ratio:c?`${c[1]}/${c[2]}`:a===`video`?`16/9`:`1/1`}}function zG({kind:e,ratio:t,words:n=`Your result shows up here`}){return(0,V.jsxs)(`div`,{className:`sm-result-place`,"data-kind":e||`other`,children:[e===`text`&&(0,V.jsxs)(`span`,{className:`sm-result-lines`,"aria-hidden":`true`,children:[(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{})]}),(e===`video`||e===`image`)&&(0,V.jsx)(`span`,{className:`sm-result-frame`,style:{aspectRatio:t},"aria-hidden":`true`,children:(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":e})}),e===`audio`&&(0,V.jsxs)(`span`,{className:`sm-result-audio`,"aria-hidden":`true`,children:[(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`audio`}),(0,V.jsx)(`span`,{className:`sm-result-wave`,children:Array.from({length:24},(e,t)=>(0,V.jsx)(`i`,{},t))})]}),!e&&(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`spark`,"aria-hidden":`true`}),(0,V.jsx)(`p`,{children:n})]})}var BG=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),VG=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),HG=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),UG=e=>/^[aeiou]/i.test(e)?`an`:`a`;function WG(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=BG[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||VG.has(a)||a===i,s=KU(HG[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${UG(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${UG(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var GG=160,KG=/\blines\b|\b(?:per|each|every|own|by)\s+line\b|\bline\s+(?:per|for each)\b|\bparagraphs?\b|\bbullet(?:s|ed)?\b/i,qG=/\blists?\b/i,JG=/\bcomma/i;function YG(e,t,n){if(e?.type!==`text`)return!1;if(n?.multiline===!0||[t,e.default].some(e=>typeof e==`string`&&e.includes(`
1942
- `)))return!0;let r=String(e.description||``);return KG.test(r)||qG.test(r)&&!JG.test(r)}function XG(e,t,n){if(e?.type!==`text`||YG(e,t,n)||t!=null&&(typeof t!=`string`||t.length>GG))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<=GG}var ZG=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],QG=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],$G=new Set([`image`,`video`,`audio`,`file`]),eK={image:`image`,video:`film`,audio:`music`,file:`image`},tK=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`},rK={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(nK).map(e=>`.${e}`).join(`,`)};async function iK(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 aK(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?nK[n]||e.type:e.type||`application/octet-stream`,i=await iK(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 oK(e,t,n,{pick:r=aK}={}){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 sK(e,t,n){for(let t of Object.keys(n||{}))if(!Object.hasOwn(e||{},t))throw Error(`Unknown input: ${t}`);return{...t||{},...n}}function cK({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=AW(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 aK(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=WG(e,t),_=(0,V.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:rK[t.type],onChange:h});return r&&!n?(0,V.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,V.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,V.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,V.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,V.jsx)(`span`,{children:t.description}),(0,V.jsx)(`small`,{children:g.formats}),(0,V.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,V.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,V.jsxs)(`div`,{className:`dh-media`,children:[(0,V.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,V.jsx)(vU,{name:n?eK[t.type]:`plus`,size:16}),(0,V.jsx)(`span`,{children:c?`Adding…`:uK(n)||g.choose})]}),_,u&&(0,V.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):n&&typeof n==`object`?(0,V.jsxs)(`span`,{className:`dh-media-tiles`,title:`The example from the Block's tests`,children:[(0,V.jsx)(lK,{item:n,title:o}),(0,V.jsx)(`small`,{className:`dh-media-note`,children:`Example`})]}):(0,V.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,V.jsx)(vU,{name:eK[t.type],size:16}),(0,V.jsx)(`span`,{children:`Add one in the example`}),(0,V.jsx)(`small`,{children:`Example`})]})]})}function lK({item:e,title:t}){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(!1),a=uK(e)||t;if(!(typeof e?.url==`string`&&e.url.startsWith(`/api/media/`))||![`image`,`video`,`audio`].includes(e.kind))return(0,V.jsxs)(`span`,{className:`dh-media-tile`,title:a,children:[(0,V.jsx)(vU,{name:eK[e?.kind]||`image`,size:16}),(0,V.jsx)(`span`,{children:a})]});if(e.kind===`image`)return(0,V.jsx)(`span`,{className:`dh-thumb`,title:a,children:(0,V.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,V.jsx)(`button`,{type:`button`,className:`dh-thumb-play`,"aria-label":`${r?`Pause`:`Play`} ${a}`,onClick:o,children:(0,V.jsx)(vU,{name:r?`pauseFilled`:`playFilled`,size:14})});return e.kind===`video`?(0,V.jsxs)(`span`,{className:`dh-thumb`,title:a,"data-playing":r||void 0,children:[(0,V.jsx)(`video`,{ref:n,src:e.url,preload:`metadata`,muted:!0,playsInline:!0,...s}),c]}):(0,V.jsxs)(`span`,{className:`dh-media-tile dh-media-sound`,title:a,children:[c,(0,V.jsx)(vU,{name:`music`,size:16}),(0,V.jsx)(`span`,{children:a}),(0,V.jsx)(`audio`,{ref:n,src:e.url,preload:`none`,...s})]})}var uK=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},dK=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},fK=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function pK(e){return(await fetch(`/__dev/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function mK(e,{signal:t}={}){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 n=await fetch(e.url,{signal:t});if(!n.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let r=await createImageBitmap(await n.blob()),i=Math.min(1,512/Math.max(r.width,r.height)),a=document.createElement(`canvas`);return a.width=Math.max(1,Math.round(r.width*i)),a.height=Math.max(1,Math.round(r.height*i)),a.getContext(`2d`).drawImage(r,0,0,a.width,a.height),r.close?.(),{url:a.toDataURL(`image/png`),width:a.width,height:a.height}}function hK(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.`)):qn(e,{signal:t})}function gK({value:e}){let t=uK(e);if(!e.url.startsWith(`/api/media/`))return(0,V.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,V.jsx)(vU,{name:eK[e.kind],size:16}),(0,V.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,V.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,V.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,V.jsx)(zW,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,V.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,V.jsx)(`figcaption`,{children:t})]})}var _K=e=>(0,V.jsx)(gK,{value:e}),vK=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function yK({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||AW(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,V.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,V.jsxs)(`span`,{className:`dh-slider`,children:[(0,V.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,V.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,V.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,V.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&&XG(t,o,n)?(0,V.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):(0,V.jsx)(`textarea`,{id:u,className:`dh-text`,rows:Math.min(16,Math.max(3,String(c).split(`
1943
- `).length)),value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,V.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:YW(e,s,typeof o==`string`?o:``)?(0,V.jsx)(iG,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,V.jsx)(nG,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):vK.has(t.type)?(0,V.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,V.jsx)(lK,{item:e,title:`${s} ${t+1}`},t)),!(Array.isArray(o)?o.length:o)&&(0,V.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,V.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,V.jsxs)(`div`,{className:`dh-row`,children:[(0,V.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function bK({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,V.jsxs)(`div`,{className:`dh-input`,children:[(0,V.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,V.jsx)(`p`,{role:`alert`,children:o})]})}var xK=(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,V.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,V.jsx)(`ol`,{ref:n,children:e.map(e=>(0,V.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,V.jsx)(`time`,{children:e.time}),(0,V.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,V.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,V.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),SK={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},CK={full:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,V.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,V.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,V.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,V.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,V.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,V.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`})},wK=({name:e})=>(0,V.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:CK[e]});function TK(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=rU({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 EK({label:e,value:t,options:n,onChange:r}){return(0,V.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,V.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,V.jsx)(wK,{name:e})},e))})}var DK=140,OK=260,kK={"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`},AK=e=>kK[e.name]||kK[e.api]||e.name;function jK({on:e,label:t,onChange:n}){return(0,V.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,V.jsx)(`span`,{className:`dh-switch-track`,children:(0,V.jsx)(`span`,{className:`dh-switch-knob`})}),(0,V.jsx)(`span`,{children:t})]})}function MK({tabs:e,status:t,control:n,children:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(()=>Number(dK(`stillmade.dev.dock`,``))||OK),c=(0,v.useRef)(null),l=e=>a(t=>t===e?null:e),u=e=>{i&&(c.current={y:e.clientY,height:o},e.currentTarget.setPointerCapture(e.pointerId))},d=e=>{let t=c.current;t&&s(Math.round(Math.max(DK,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},f=()=>{c.current&&(c.current=null,fK(`stillmade.dev.dock`,String(o)))},p=e.find(e=>e.key===i);return(0,V.jsxs)(`section`,{className:`dh-dock`,"data-open":p?`true`:`false`,style:p?{height:o}:void 0,"aria-label":`Run details`,children:[p&&(0,V.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f}),(0,V.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,V.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":i===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>l(e.key),children:[e.label,e.alert&&(0,V.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,V.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,V.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":p?`Fold the panel`:`Open the panel`,title:p?`Fold the panel`:`Open the panel`,"aria-expanded":!!p,onClick:()=>a(t=>t?null:e[0].key),children:(0,V.jsx)(vU,{name:`chevronRight`,size:16})})]}),p&&(0,V.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${p.key}`,"aria-labelledby":`dh-tab-${p.key}`,children:r(p.key)})]})}function NK(){let[e,t]=(0,v.useState)({revision:0,content:null,problem:null,folder:``}),[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(()=>dK(`stillmade.dev.theme`,`light`)),[o,s]=(0,v.useState)(()=>dK(`stillmade.dev.width`,`full`)),[c,l]=(0,v.useState)(0),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)({}),[T,E]=(0,v.useState)([]),[D,O]=(0,v.useState)({}),k=(0,v.useRef)({}),A=(0,v.useRef)(0),j=(0,v.useCallback)((e,t)=>E(n=>[...n.slice(-299),{id:++A.current,kind:e,label:SK[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),M=(0,v.useCallback)(async()=>{let e=await(await fetch(`/__dev/package`,{cache:`no-store`})).json();return t(e),e},[]);(0,v.useEffect)(()=>{let e=!0;M().then(t=>{e&&(d(e=>e??(t.content?.tests?.[0]?.input||{})),j(`reload`,`Previewing ${t.folder}`),t.problem&&j(`error`,tK(t.problem)))}).catch(e=>j(`error`,e.message));let t=new EventSource(`/__dev/events`);return t.addEventListener(`package`,async t=>{let n=JSON.parse(t.data);try{if(await M(),!e)return;r(e=>e+1),j(n.problem?`error`:`reload`,n.problem?`Reloaded with a problem: ${tK(n.problem)}`:`Reloaded after a change`)}catch(e){j(`error`,e.message)}}),t.addEventListener(`build`,e=>{let t=JSON.parse(e.data);t.state===`running`?j(`build`,`Building: ${t.command}`):t.state===`done`?j(`build`,`Build finished`):j(`error`,`Build failed${t.output?`\n${t.output}`:``}`)}),()=>{e=!1,t.close()}},[]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=i,fK(`stillmade.dev.theme`,i)},[i]),(0,v.useEffect)(()=>{fK(`stillmade.dev.width`,o)},[o]);let N=e.content,P=N?.manifest,F=N?.tests||[],I=e=>{l(e),d(F[e]?.input||{})},ee=(0,v.useCallback)(async(e,{signal:t}={})=>{j(`run`,`Run started`),h(!0),_(``);try{let n=await pK(e);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])j(`log`,e);for(let e of n.standIns||[])j(`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(b({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw j(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return p(n.outputs),j(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(p(null),_(e?.message||`The run did not finish.`)),e}finally{h(!1)}},[j]),te=(0,v.useCallback)(async e=>{let t=or(k.current,e);k.current=t,O(t)},[]),L=()=>{k.current={},O({}),r(e=>e+1),j(`view`,`Shared state cleared`)},R=(0,v.useMemo)(()=>({state:D,outputs:{},memory:null,canEdit:!0}),[D]),ne=(0,v.useCallback)(async e=>{p(e),j(`view`,`The view chose its outputs`)},[j]),z=(0,v.useCallback)(async(t,n)=>{let r=e.content?.manifest?.inputs?.[t],{refs:i,apply:a}=await oK(t,r,n);return x&&$G.has(r.type)?w(e=>({...e,[t]:i[0]})):d(a),j(`view`,`Added ${i.length} ${i.length===1?`file`:`files`} to ${AW(t)}`),{added:i.length}},[e.content,x,j]),re=(0,v.useCallback)(async(e,t)=>{let n=cW(u?.[e],t);return d(t=>({...t,[e]:n})),j(`view`,`${t.op===`remove`?`Removed a file from`:`Moved a file in`} ${AW(e)}`),{files:n.length}},[u,j]),ie=(0,v.useCallback)(e=>j(`error`,String(e?.message||e)),[j]),ae=(0,v.useMemo)(()=>{let t={...u||{}};if(x)for(let[n,r]of Object.entries(e.content?.manifest?.inputs||{}))$G.has(r.type)&&(C[n]?t[n]=C[n]:delete t[n]);return t},[u,x,C,e.content]),oe=(0,v.useCallback)(t=>d(n=>{if(!x)return t;let r={...t};for(let[t,i]of Object.entries(e.content?.manifest?.inputs||{}))$G.has(i.type)&&(n&&Object.hasOwn(n,t)?r[t]=n[t]:delete r[t]);return r}),[x,e.content]),se=(0,v.useCallback)(async(t,n)=>{let r=sK(e.content?.manifest?.inputs,ae,t);return Object.keys(t).length&&oe({...u||{},...t}),ee(r,n)},[e.content,ae,u,oe,ee]),ce=QG.find(([e])=>e===o)?.[2],le=N?.capability?.operation?[N.capability.operation]:(P?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),ue=m?DG(le.length===1?le[0]:void 0,N)[1]:kG(le.length===1?le[0]:void 0,{credits:0},{connector:N}),de=(0,v.useMemo)(()=>PG(P,{labels:Object.fromEntries((P?.ui||[]).filter(e=>e?.label).map(e=>[e.port,e.label])),groups:P?.uiLayout?.groups||[]}),[P]),fe=(0,v.useRef)(null);TK(fe,[N,o,f,g,m]);let pe=f?Object.entries(P?.outputs||{}).filter(([e])=>f[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof f[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(f[e])?(0,V.jsx)(`p`,{className:`dh-date`,children:(0,V.jsx)(`time`,{dateTime:f[e],children:XW(f[e])})},e):(0,V.jsx)(LW,{value:f[e],renderMedia:_K},e)):null,me=m?`Running…`:y?y.failed?`Last run failed`:`Ran in ${y.ms} ms${y.calls.length?` · ${y.calls.length} ${y.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,he=[{key:`activity`,label:`Activity`,alert:T.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${y?.calls.length?` · ${y.calls.length}`:``}`},...N?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,V.jsxs)(`div`,{className:`dh-page`,children:[(0,V.jsxs)(`header`,{className:`dh-bar`,children:[(0,V.jsxs)(`div`,{className:`dh-title`,children:[(0,V.jsx)(`h1`,{children:P?.name||`Block preview`}),P&&(0,V.jsx)(`span`,{className:`dh-meta`,children:P.version})]}),(0,V.jsx)(`span`,{className:`dh-spacer`}),F.length>1&&(0,V.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,V.jsx)(wK,{name:`example`}),(0,V.jsx)(`select`,{"aria-label":`Example`,value:c,onChange:e=>I(Number(e.target.value)),children:F.map((e,t)=>(0,V.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,V.jsx)(EK,{label:`Width`,value:o,options:QG,onChange:s}),(0,V.jsx)(EK,{label:`Appearance`,value:i,options:ZG,onChange:a}),(0,V.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>r(e=>e+1),children:(0,V.jsx)(vU,{name:`refresh`,size:16})})]}),e.problem&&(0,V.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:tK(e.problem)}),(0,V.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,V.jsx)(`div`,{className:`dh-frame`,style:ce?{maxWidth:ce}:void 0,children:N?N.view?(0,V.jsx)(xW,{view:N.view,policyContent:N,input:ae,sharedView:R,onSharedChange:te,onRun:se,onUseOutput:ne,onAddFiles:z,onChangeFiles:re,onPreviewImage:mK,onPreviewMedia:hK,onError:ie,actorId:`dev-preview`,title:`${P.name} preview`,height:560,fitContent:!0},n):(0,V.jsxs)(`div`,{className:de.focused?`dh-noview dh-focus`:`dh-noview`,ref:fe,children:[de.focused&&(0,V.jsxs)(`header`,{className:`dh-intro`,children:[(0,V.jsx)(`h2`,{children:de.heading}),de.line&&(0,V.jsx)(`p`,{children:de.line})]}),(0,V.jsx)(`div`,{className:`dh-form`,children:Object.entries(P.inputs||{}).map(([e,t])=>$G.has(t.type)?(0,V.jsx)(cK,{name:e,port:t,title:(P.ui||[]).find(t=>t?.port===e)?.label||AW(e),value:ae[e],own:x,disabled:m,onPick:t=>w(n=>({...n,[e]:t}))},e):(0,V.jsx)(yK,{name:e,port:t,control:(P.ui||[]).find(t=>t?.port===e),value:ae[e],disabled:m,onCommit:t=>d(n=>({...n,[e]:t}))},e))}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:m,onClick:()=>ee(ae).catch(()=>{}),children:ue}),g&&(0,V.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),pe?(0,V.jsxs)(`div`,{className:`dh-results`,children:[(0,V.jsx)(`h2`,{children:`Result`}),pe]}):!g&&(0,V.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,V.jsx)(zG,{...RG(P,{inputs:ae})})})]}):(0,V.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,V.jsx)(MK,{tabs:he,status:me,control:(0,V.jsx)(jK,{on:!x,label:`Example media`,onChange:e=>S(!e)}),children:e=>e===`activity`?(0,V.jsx)(xK,{entries:T,onClear:()=>E([])}):e===`calls`?y?.calls.length?(0,V.jsx)(`ol`,{className:`dh-calls`,children:y.calls.map((e,t)=>(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`strong`,{children:AK(e)}),(0,V.jsx)(`span`,{children:e.name}),(0,V.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,V.jsx)(`p`,{className:`dh-muted`,children:y?`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,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:L,children:`Clear shared state`})]}),g&&(0,V.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),pe||!g&&(0,V.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:m||!N,onClick:()=>ee(ae).catch(()=>{}),children:ue})]}),u&&(0,V.jsx)(bK,{value:ae,onCommit:oe,disabled:!N}),f&&(0,V.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(f,null,2)})]})})]})}(0,y.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(NK,{}));
1949
+ `,_U=[`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`],vU={cx:12,cy:12,r:1.8};function yU(e){switch(e){case`minus`:return(0,V.jsx)(`path`,{d:`M5 12h14`});case`messageCircle`:return(0,V.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,V.jsx)(`path`,{d:`M20 12H4M11 5l-7 7 7 7`});case`link`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M10 13a5 5 0 0 0 7 .5l3-3a5 5 0 0 0-7-7l-2 2`}),(0,V.jsx)(`path`,{d:`M14 11a5 5 0 0 0-7-.5l-3 3a5 5 0 0 0 7 7l2-2`})]});case`unlink`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`m18.8 12.3 1.7-1.7a5 5 0 0 0-7.1-7.1l-1.7 1.7`}),(0,V.jsx)(`path`,{d:`m5.2 11.7-1.7 1.7a5 5 0 0 0 7.1 7.1l1.7-1.7`}),(0,V.jsx)(`path`,{d:`M8 2v3M2 8h3M16 19v3M19 16h3`})]});case`copy`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`9`,y:`9`,width:`12`,height:`12`,rx:`2`}),(0,V.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,V.jsx)(`path`,{d:`M12 20V4M5 11l7-7 7 7`});case`star`:return(0,V.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,V.jsx)(`path`,{d:`M7 17 17 7M8 7h9v9`});case`arrowDown`:return(0,V.jsx)(`path`,{d:`M12 4v16M5 13l7 7 7-7`});case`thumbsUp`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M7 10v11H3V10Z`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M7 14V3H3v11Z`}),(0,V.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,V.jsx)(`path`,{d:`M3 10h11a7 7 0 0 1 0 14M3 10l5-5M3 10l5 5`,transform:`translate(0 -3)`});case`redo`:return(0,V.jsx)(`path`,{d:`M21 7H10a7 7 0 0 0 0 14M21 7l-5-5M21 7l-5 5`});case`remix`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M5 5h5a5 5 0 0 1 5 5v9`}),(0,V.jsx)(`path`,{d:`m11 15 4 4 4-4`}),(0,V.jsx)(`path`,{d:`M5 19h2`}),(0,V.jsx)(`circle`,{cx:`5`,cy:`5`,r:`2`}),(0,V.jsx)(`circle`,{cx:`5`,cy:`19`,r:`2`})]});case`more`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`5`,cy:`12`,r:`1`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`}),(0,V.jsx)(`circle`,{cx:`19`,cy:`12`,r:`1`})]});case`palette`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`13.5`,cy:`6.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`17`,cy:`11`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`8.5`,cy:`7.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`circle`,{cx:`6.5`,cy:`12.5`,r:`.6`,fill:`currentColor`,stroke:`none`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 8 0v4`})]});case`unlock`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`11`,width:`14`,height:`10`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 11V7a4 4 0 0 1 7.9-1`})]});case`pushpin`:return(0,V.jsxs)(`g`,{transform:`rotate(35 12 12)`,children:[(0,V.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`}),(0,V.jsx)(`path`,{d:`M12 14v7`})]});case`pushpinFilled`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M8 3h8l-1 6 3 3v2H6v-2l3-3Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`M12 14v7`})]});case`pin`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 21s7-5.7 7-11a7 7 0 0 0-14 0c0 5.3 7 11 7 11Z`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`10`,r:`2.5`})]});case`user`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`8`,r:`4`}),(0,V.jsx)(`path`,{d:`M5 21a7 7 0 0 1 14 0`})]});case`image`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`circle`,{cx:`8.5`,cy:`8.5`,r:`1.5`}),(0,V.jsx)(`path`,{d:`m21 15-5-5L5 21`})]});case`imageOff`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M2 2l20 20`}),(0,V.jsx)(`path`,{d:`M10.41 10.41a2 2 0 1 1-2.83-2.83`}),(0,V.jsx)(`path`,{d:`M13.5 13.5 6 21`}),(0,V.jsx)(`path`,{d:`m18 12 3 3`}),(0,V.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,V.jsx)(`path`,{d:`M21 15V5a2 2 0 0 0-2-2H9`})]});case`film`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`M7 3v18M17 3v18M3 8h4M3 16h4M17 8h4M17 16h4`})]});case`folder`:return(0,V.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,V.jsx)(`path`,{d:`M9 6h12M9 12h12M9 18h12M4 6h.01M4 12h.01M4 18h.01`});case`grid`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`14`,y:`3`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`3`,y:`14`,width:`7`,height:`7`,rx:`1.5`}),(0,V.jsx)(`rect`,{x:`14`,y:`14`,width:`7`,height:`7`,rx:`1.5`})]});case`zap`:return(0,V.jsx)(`path`,{d:`M13 2 4 14h7l-1 8 9-12h-7Z`});case`plug`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 22v-5M9 8V2M15 8V2`}),(0,V.jsx)(`path`,{d:`M18 8v5a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V8Z`})]});case`book`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M4 19.5A2.5 2.5 0 0 1 6.5 17H20`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 7v14`}),(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M15 3h4a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2h-4`}),(0,V.jsx)(`path`,{d:`m10 17 5-5-5-5`}),(0,V.jsx)(`path`,{d:`M15 12H3`})]});case`upload`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 16V4M7 9l5-5 5 5`}),(0,V.jsx)(`path`,{d:`M5 20h14`})]});case`download`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 4v12M7 11l5 5 5-5`}),(0,V.jsx)(`path`,{d:`M5 20h14`})]});case`save`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M5 3h11l3 3v15H5Z`}),(0,V.jsx)(`path`,{d:`M8 3v5h7M8 21v-7h8v7`})]});case`search`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`11`,cy:`11`,r:`7`}),(0,V.jsx)(`path`,{d:`m20 20-3.5-3.5`})]});case`magnet`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M6 4h4v8a2 2 0 0 0 4 0V4h4v8a6 6 0 0 1-12 0Z`}),(0,V.jsx)(`path`,{d:`M6 8h4M14 8h4`})]});case`bot`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`4`,y:`8`,width:`16`,height:`11`,rx:`2`}),(0,V.jsx)(`path`,{d:`M12 8V4M9 13h.01M15 13h.01M9 16h6`})]});case`note`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`4`,y:`3`,width:`16`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 8h8M8 12h8M8 16h5`})]});case`clock`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`path`,{d:`M12 7v5l3 2`})]});case`calendar`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`5`,width:`18`,height:`16`,rx:`2`}),(0,V.jsx)(`path`,{d:`M16 3v4M8 3v4M3 10h18`})]});case`hourglass`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 20h9`}),(0,V.jsx)(`path`,{d:`M16.5 3.5a2.1 2.1 0 0 1 3 3L7 19l-4 1 1-4Z`})]});case`music`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M9 18V5l12-2v13`}),(0,V.jsx)(`circle`,{cx:`6`,cy:`18`,r:`3`}),(0,V.jsx)(`circle`,{cx:`18`,cy:`16`,r:`3`})]});case`mic`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`9`,y:`2`,width:`6`,height:`13`,rx:`3`}),(0,V.jsx)(`path`,{d:`M19 10v2a7 7 0 0 1-14 0v-2`}),(0,V.jsx)(`path`,{d:`M12 19v3`})]});case`target`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`5`}),(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`1`,fill:`currentColor`,stroke:`none`})]});case`pointer`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M12 21V9`}),(0,V.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,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`6`,cy:`6`,r:`2.5`}),(0,V.jsx)(`circle`,{cx:`6`,cy:`18`,r:`2.5`}),(0,V.jsx)(`path`,{d:`M8 8l12 8M8 16 20 8`})]});case`maximize`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`3`}),(0,V.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,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`3`,width:`18`,height:`18`,rx:`2`}),(0,V.jsx)(`path`,{d:`m8 12 3 3 5-6`})]});case`warning`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.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,V.jsx)(`path`,{d:`M12 9v4M12 17h.01`})]});case`sparkle`:return(0,V.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,V.jsx)(`path`,{d:`m5 12 5 5 9-10`});case`x`:return(0,V.jsx)(`path`,{d:`M6 6 18 18M18 6 6 18`});case`plus`:return(0,V.jsx)(`path`,{d:`M12 5v14M5 12h14`});case`refresh`:return(0,V.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,V.jsx)(`path`,{d:`M7 4v16l13-8Z`});case`preview`:return(0,V.jsxs)(V.Fragment,{children:[_U.map(e=>(0,V.jsx)(`path`,{d:e},e)),(0,V.jsx)(`circle`,{...vU})]});case`pause`:return(0,V.jsx)(`path`,{d:`M9 5v14M15 5v14`});case`playFilled`:return(0,V.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,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`6`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`}),(0,V.jsx)(`rect`,{x:`14`,y:`4.5`,width:`4`,height:`15`,rx:`1`,fill:`currentColor`,stroke:`none`})]});case`volume2`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`M15.5 8.5a5 5 0 0 1 0 7M19 5a10 10 0 0 1 0 14`})]});case`volumeX`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M11 5 6 9H2v6h4l5 4V5Z`,fill:`currentColor`}),(0,V.jsx)(`path`,{d:`m22 9-6 6M16 9l6 6`})]});case`minimize`:return(0,V.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,V.jsx)(`rect`,{x:`6`,y:`6`,width:`12`,height:`12`,rx:`2`});case`chevronRight`:return(0,V.jsx)(`path`,{d:`m9 6 6 6-6 6`});case`chevronLeft`:return(0,V.jsx)(`path`,{d:`m15 6-6 6 6 6`});case`chevronDown`:return(0,V.jsx)(`path`,{d:`m6 9 6 6 6-6`});case`trash`:return(0,V.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,V.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,V.jsx)(`path`,{d:`M4 6V4h16v2M12 4v16M9 20h6`});case`home`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M3 10.5 12 3l9 7.5`}),(0,V.jsx)(`path`,{d:`M5 9.5V20a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1V9.5`}),(0,V.jsx)(`path`,{d:`M9 21v-6h6v6`})]});case`menu`:return(0,V.jsx)(`path`,{d:`M4 6h16M4 12h16M4 18h16`});case`logout`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`M9 21H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h4`}),(0,V.jsx)(`path`,{d:`M16 17l5-5-5-5`}),(0,V.jsx)(`path`,{d:`M21 12H9`})]});case`help`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`9`}),(0,V.jsx)(`path`,{d:`M9.1 9a3 3 0 0 1 5.8 1c0 2-3 3-3 3`}),(0,V.jsx)(`path`,{d:`M12 17h.01`})]});case`bug`:return(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`path`,{d:`m8 2 1.9 1.9M14.1 3.9 16 2`}),(0,V.jsx)(`path`,{d:`M9 7.1v-1a3 3 0 1 1 6 0v1`}),(0,V.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,V.jsx)(`path`,{d:`M12 20v-9`}),(0,V.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 bU({name:e,size:t=`1em`,style:n,className:r,strokeWidth:i=1.5}){let a=yU(e);return a?(0,V.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}var xU=`sm.blockZoom.`;function SU(e){try{let t=e?localStorage.getItem(xU+e):null,n=Number(t);return t&&t!==`auto`&&Number.isFinite(n)?n:`auto`}catch{return`auto`}}function CU(e,t){try{if(!e)return;t===`auto`?localStorage.removeItem(xU+e):localStorage.setItem(xU+e,String(t))}catch{}}function wU(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))}var TU=(e,t)=>Math.round(Math.min(tU,Math.max(eU,e+t))*100)/100;function EU({zoom:e=1,mode:t=`auto`,onChange:n}){let r=t===`auto`?e:t,i=e=>n(TU(r,e));return(0,V.jsxs)(`div`,{className:`block-zoom-control`,role:`group`,"aria-label":`Block size`,children:[(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(-nU),disabled:r<=eU,"aria-label":`Smaller`,title:`Smaller`,"data-icon-action":`true`,children:(0,V.jsx)(bU,{name:`minus`,size:14})}),(0,V.jsx)(`button`,{type:`button`,className:`block-zoom-mode`,onClick:()=>n(`auto`),"aria-pressed":t===`auto`,title:t===`auto`?`Sized to fit automatically`:`Size automatically`,children:t===`auto`?`Auto · ${Math.round(e*100)}%`:`${Math.round(r*100)}%`}),(0,V.jsx)(`button`,{type:`button`,onClick:()=>i(nU),disabled:r>=tU,"aria-label":`Bigger`,title:`Bigger`,"data-icon-action":`true`,children:(0,V.jsx)(bU,{name:`plus`,size:14})})]})}var DU=(0,v.createContext)(null),OU=null,kU=new Set,AU=()=>OU;function jU(e){return kU.add(e),()=>kU.delete(e)}function MU(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()}})}Tt();function NU(e){return B(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 PU(e){mt(e);let t=e?.stages&&e.packages||[];return B(Array.isArray(t)&&t.length<128,`LIMIT`,`Too many packaged Blocks for execution review`),NU(await Promise.all([e,...t].map(e=>gt(e))))}async function FU(e){let t=await PU(e),n=new Set(t),r=e?.stages?e.packages||[]:[e],i=e=>{B(e&&typeof e.digest==`string`&&/^[a-f0-9]{64}$/.test(e.digest),`SCHEMA`,`Block lineage needs exact source digests`),n.add(e.digest),B(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??[];B(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??[];B(Array.isArray(r)&&r.length<=16,`SCHEMA`,`Portable lineage must contain at most 16 exact source references`),r.forEach(i)}return NU([...n])}var IU=`stillmade.block-security.v1`,LU=new Map;function RU(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 zU(){try{let e=JSON.parse(globalThis.localStorage?.getItem(IU)||`{}`);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&&LU.set(t,RU(LU.get(t),n))}catch{}return LU}function BU(e){let t=zU();for(let n of e){let e=t.get(n.digest);(n.revoked||n.published||e)&&t.set(n.digest,RU(e,n))}try{globalThis.localStorage?.setItem(IU,JSON.stringify(Object.fromEntries(t)))}catch{}}var VU=()=>Object.assign(Error(`This exact Block version has been quarantined by StillMade. Use a reviewed replacement.`),{code:`BLOCK_REVOKED`});async function HU(e,{signal:t}={}){let n=await FU(e),r=zU();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`);BU(s.digests)}catch{if(t?.aborted)throw Object.assign(Error(`Cancelled`),{code:`CANCELLED`});if(n.some(e=>r.get(e)?.revoked))throw VU();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=>zU().get(e)?.revoked))throw VU();return{checked:!0}}ut();var UU=(e,t)=>Object.freeze({kind:e,mimeType:t}),WU=Object.freeze({png:UU(`image`,`image/png`),jpg:UU(`image`,`image/jpeg`),jpeg:UU(`image`,`image/jpeg`),webp:UU(`image`,`image/webp`),gif:UU(`image`,`image/gif`),mp4:UU(`video`,`video/mp4`),mov:UU(`video`,`video/quicktime`),webm:UU(`video`,`video/webm`),mp3:UU(`audio`,`audio/mpeg`),wav:UU(`audio`,`audio/wav`),m4a:UU(`audio`,`audio/mp4`),aac:UU(`audio`,`audio/aac`),ogg:UU(`audio`,`audio/ogg`),...Object.fromEntries(Object.entries(it).map(([e,t])=>[e,UU(`file`,t)]))});Object.freeze(Object.fromEntries(Object.entries(WU).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 GU=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`}),KU=e=>Object.entries(WU).filter(([t,n])=>e.includes(n.kind)&&GU[t]).map(([e])=>GU[e]),qU=e=>e.length>1?`${e.slice(0,-1).join(`, `)}, or ${e.at(-1)}`:e[0],JU=e=>qU([...new Set(KU(e))]),YU=c({loadViewAssets:()=>XU});async function XU(e,{signal:t}={}){let n={};for(let[r,i]of Object.entries(e?.files||{})){let a=await fetch(`/__dev/files/`+i.sha256,{signal:t});if(!a.ok)throw Error(r+` is missing from the Block folder.`);let o=await cH(e,r,new Uint8Array(await a.arrayBuffer()));n[r]={mediaType:i.mediaType,base64:ZU(o)}}return n}var ZU,QU=o((()=>{lH(),ZU=e=>{let t=``;for(let n=0;n<e.length;n+=32768)t+=String.fromCharCode(...e.subarray(n,n+32768));return btoa(t)}}));k(),Tt(),xi();var $U=`stillmade.block.view.v1`,eW=5e3,tW=()=>globalThis.crypto.randomUUID(),nW=`*{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}}`,rW=`*{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)}`,iW=`: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}`,aW=`html[data-stillmade-pick],html[data-stillmade-pick] *{cursor:crosshair!important}html[data-stillmade-pick] [data-stillmade-media]{display:none!important}`,oW=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(WU).filter(([,e])=>e.kind===`file`).map(([e])=>`.${e}`).join(`,`)}),sW=e=>e.filter(e=>typeof e==`string`&&/^[A-Za-z][A-Za-z0-9_-]{0,99}$/.test(e)),cW=e=>`html[data-stillmade-readonly] [data-stillmade-add]${sW(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]${sW(e).map(e=>`,[data-stillmade-remove="${e}"],[data-stillmade-move="${e}"]`).join(``)}{display:none!important}`;function lW(e,t){let n=typeof t==`string`&&vt(e?.inputs)&&Object.hasOwn(e.inputs,t)?e.inputs[t]:null;if(!vt(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(oW,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:oW[i]}}function uW(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 dW({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 fW=e=>JSON.stringify(e).replace(/</g,`\\u003c`).replace(/\u2028/g,`\\u2028`).replace(/\u2029/g,`\\u2029`);function pW(e){if(mt(e),new TextEncoder().encode(JSON.stringify(e)).length>uH.messageBytes)throw Error(`Preview data exceeds 4 MiB`);return structuredClone(e)}var mW=e=>vt(e)&&[`image`,`video`,`audio`].includes(e.kind)&&[`assetId`,`versionId`,`url`].every(t=>typeof e[t]==`string`&&e[t])?ht([e.kind,e.assetId,e.versionId,e.url]):``;function hW(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`:ht(e);return t.current.signature===n?t.current.original=e:t.current={has:!0,original:e,signature:n,value:e},t.current.value}function gW(e,t=[]){return Array.isArray(e)?(e.forEach(e=>gW(e,t)),t):vt(e)?mW(e)?(t.push(e),t):(Object.values(e).forEach(e=>gW(e,t)),t):t}var _W=e=>Array.isArray(e)?e.length>0&&e.every(_W):!!mW(e);function vW(e,t,n){if(!vt(e)||!Object.values(e).length||!Object.values(e).every(_W))throw Error(`Only complete saved media references can be chosen as outputs.`);let r=new Set(gW(t).map(mW));for(let t of gW(e))if(!r.has(mW(t))&&!n?.authorizesMedia(t))throw Error(`Choose media supplied by this workspace or recorded in this session.`);return pW(e)}function yW(e){let t=pW(e);if(!vt(t)||!_t(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 bW(e){let t=pW(e);if(!(vt(t)&&Object.keys(t).length===3&&[`url`,`width`,`height`].every(e=>Object.hasOwn(t,e))&&[`width`,`height`].every(e=>Number.isInteger(t[e])&&t[e]>0&&t[e]<=uH.imagePreviewEdge))||typeof t.url!=`string`||!/^data:image\/png;base64,[A-Za-z0-9+/]+={0,2}$/.test(t.url))throw Error(`The host returned an invalid image preview.`);let n=t.url.slice(22);if(n.length%4!=0)throw Error(`The host returned an invalid image preview.`);let r=atob(n.slice(0,44)),i=e=>r.charCodeAt(e),a=e=>i(e)*16777216+i(e+1)*65536+i(e+2)*256+i(e+3);if(r.length<33||![137,80,78,71,13,10,26,10].every((e,t)=>i(t)===e)||a(8)!==13||r.slice(12,16)!==`IHDR`||a(16)!==t.width||a(20)!==t.height)throw Error(`The host returned an invalid image preview.`);return t}function xW(e,t,n=`light`,r=`package`,i=!1,a=[],o=null,s=!1,c=!1,{assets:l={},filming:u=null,inputTypes:d=null}={}){bH(e);let f=DH(e),p=r===`package`?e.appearance??`host`:r;p!==`original`&&!f&&LH(e,{appearance:`host`});let m=(p===`original`?e.css??``:e.themedCss??e.css??``)+`
1950
+ `+(f?``:zH),h=globalThis.crypto.randomUUID().replaceAll(`-`,``),g=`__sm_view_${h}`,_=`__sm_guard_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,v=`__sm_media_${globalThis.crypto.randomUUID().replaceAll(`-`,``)}`,y=`(()=>{"use strict";document.currentScript.remove();const session=${fW(t)},channel=${fW($U)},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;const addTypes=${fW(vt(d)?d:null)},addLocked=new Set(${fW(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,${fW(v)},{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);${f?`for(const meta of document.querySelectorAll("meta[http-equiv]"))meta.remove();const frameRuntime=(${jH.toString()})(channel,session,send,${fW({guardName:_,taskMs:SH.taskMs,assets:l})});`:`Object.defineProperty(globalThis,${fW(g)},{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=(${cr.toString()})(document,error=>send({channel,session,op:"interface-error",error},"*"),()=>Promise.resolve().then(controlSnapshot));const sharedLifecycle={};const sharedAPI=(${sr.toString()})(channel,session,${fW(ar)},sharedLifecycle);const textControls=${i?`(()=>{${Zn};return StillMadeTextFrame.installTextFrame(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),channel,session,{token:${fW(o)},send});})()`:`null`};const sharedControls=(${Xn.toString()})(document,sharedAPI,error=>send({channel,session,op:"interface-error",error},"*"),textControls,${fW(a)});const {documentTools,sharedDocuments}=(${Qn})(sharedAPI,status=>send({channel,session,op:"document-store-status",status},"*"));const previews=(${At.toString()})((kind,value)=>{if(kind==="media"){if(mediaURLs.size>=2)throw Error("Release a previous media preview before opening another");if(!["video","audio"].includes(value.kind))throw Error("Choose an 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},"*")})});const connectionAPI=(${Ot.toString()})(${fW($U)},${fW(t)},${c},send),workAPI=(${D.toString()})(${fW($U)},${fW(t)},${s},send);const liveBridge=(${kt.toString()})(${fW($U)},${fW(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,${f?`asset:frameRuntime.asset,assetBytes:frameRuntime.assetBytes,`:``}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:(${lr.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){if(!ready)return Promise.reject(Error("Preview is loading"));return track(previews.request("image",value))},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:${fW(o)},id:data.id},"*"),error=>send({channel,session,op:"named-text-result",token:${fW(o)},id:data.id,error:String(error.message).slice(0,1000)},"*")).finally(()=>send({channel,session,op:"named-text-controls",token:${fW(o)},snapshot:textControls.inspectNative()},"*"));return;}if(data.op==="inspect-named-text"){if(textControls)send({channel,session,op:"named-text-controls",token:${fW(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})}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();previews.reset("Preview was reset");dynamicUI.dispose();sharedControls.dispose();textControls?.dispose();sharedDocuments.dispose();if(pendingDesktop)pendingDesktop.reject(Error("Block was closed"));pendingDesktop=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"},"*");})();`,b=f?`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${AH(e.javascript||``,_)}`.replace(/<\/script/gi,`<\\/script`):`document.currentScript.remove();((${g})=>{"use strict";delete globalThis[${fW(g)}];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${xH(e.javascript||``,g)}\n})(globalThis[${fW(g)}]);`.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-${h}'; style-src 'unsafe-inline'; img-src data: blob:; media-src data: blob:;${f?` font-src data: blob:;`:``} connect-src 'none'; frame-src 'none'; worker-src ${f?`blob:`:`'none'`}; object-src 'none'; base-uri 'none'; form-action 'none';"><meta name="referrer" content="no-referrer"><style>${RH.replace(/@font-face\s*\{[^}]*\}/g,``)}${f?rW:nW}${BH}${f?``:iW}${(m||``).replace(/<\/style/gi,`<\\/style`)}@media(pointer:coarse){input,textarea,select{font-size:16px!important}}${aW}${cW(a)}</style></head><body>${e.html}${u?`<script nonce="${h}">document.currentScript.remove();${u.replace(/<\/script/gi,`<\\/script`)}<\/script>`:``}<script nonce="${h}">${y.replace(/<\/script/gi,`<\\/script`)}<\/script><script nonce="${h}">document.currentScript.remove();${u?`(${MU.toString()})(${fW($U)},${fW(t)},parent.postMessage.bind(parent));`:``}(${QH.toString()})(${fW($U)},${fW(t)});(${$H.toString()})(${fW($U)},${fW(t)});(${aU.toString()})(${fW($U)},${fW(t)},(${rU.toString()}),"auto",(${iU.toString()}),${!f});(${oU.toString()})(${fW($U)},${fW(t)},(${sU.toString().replace(/<\/script/gi,`<\\/script`)})(),${fW(gU)},{minted:(()=>{const read=globalThis[${fW(v)}];delete globalThis[${fW(v)}];return typeof read==="function"?read:()=>false;})(),filming:${u?`true`:`false`}});(${UH.toString()})(${fW($U)},${fW(t)},((validateCursorAnchor)=>(${HH.toString()}))(${VH.toString()}));(${WH.toString()})(${fW($U)},${fW(t)},(${KH.toString()}));<\/script><script nonce="${h}">${b}<\/script></body></html>`}function SW({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,V.jsxs)(`details`,{className:`bs-block-activity`,onToggle:s,children:[(0,V.jsx)(`summary`,{children:`What this Block did`}),a.length>0&&(0,V.jsx)(`ul`,{className:`bs-block-activity-folders`,children:a.map(e=>(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`span`,{children:`${e.write?`Reads and changes`:`Reads`} files in ${e.name}`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:r,onClick:()=>c(e),children:`Stop sharing`})]},e.id))}),o.length?(0,V.jsx)(`ul`,{children:o.map(e=>(0,V.jsxs)(`li`,{children:[e.text,e.count>1?` (${e.count} times)`:``]},`${e.at}:${e.text}`))}):(0,V.jsx)(`p`,{children:`Nothing yet.`})]})}function CW({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,onError:g,policyContent:_,policyParent:y,currentAppViewPolicy:b=null,title:S=`Block preview`,height:D=480,fitContent:O=!1,resetKey:k=0,theme:A,appearance:j=`package`,lockedInputKeys:M=[],agentContext:N=null}){let P=hW(e),F=hW(_),I=hW(y),ee=[`comfyui`,`capability`].includes(F?.manifest?.runtime)||!!F?.manifest?.desktopTools?.length||F?.manifest?.runtime===`module`&&!!F?.manifest?.permissions?.capabilities?.length,te=F?.capability?.operation===`image.generate`?9e5:36e4,L=(0,v.useRef)(null),R=(0,v.useRef)({onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onError:g}),ne=(0,v.useRef)(t),[z,re]=(0,v.useState)(``),[ie,ae]=(0,v.useState)(!1),[oe,se]=(0,v.useState)(0),ce=(0,v.useRef)(null),le=(0,v.useRef)(null),[ue,de]=(0,v.useState)(null),[fe,pe]=(0,v.useState)(null),[me,he]=(0,v.useState)(null),ge=F?.manifest?.id||null,[_e,ve]=(0,v.useState)(()=>SU(ge)),[ye,be]=(0,v.useState)(null),xe=(0,v.useRef)(_e);xe.current=_e;let Se=e=>{ve(e),CU(ge,e)},Ce=(0,v.useRef)(1);Ce.current=_e===`auto`?ye?.zoom||1:_e;let we=(0,v.useRef)(Se);we.current=Se;let Te=(0,v.useContext)(DU),Ee=(0,v.useRef)(Te);Ee.current=Te;let[De,Oe]=(0,v.useState)(null),[ke,Ae]=(0,v.useState)(null),[je,Me]=(0,v.useState)(()=>globalThis.document?.documentElement?.dataset.mode||`light`),Ne=(0,v.useRef)(`light`);Ne.current=[`dark`,`white`].includes(A||je)?A||je:`light`;let Pe=(0,v.useRef)(l);Pe.current=l;let Fe=(0,v.useRef)(c);Fe.current=c;let Ie=(0,v.useRef)(s);Ie.current=s;let Le=(0,v.useRef)(!1),[Re,ze]=(0,v.useState)(()=>({enabled:!!s,projectId:s?.projectId??null,placementId:s?.placementId??null})),Be=()=>{let e={enabled:!!Ie.current,projectId:Ie.current?.projectId??null,placementId:Ie.current?.placementId??null};ze(t=>t.enabled===e.enabled&&t.projectId===e.projectId&&t.placementId===e.placementId?t:e)};(0,v.useEffect)(()=>{Le.current||Be()},[!!s,s?.projectId,s?.placementId]);let Ve=Re.enabled,He=Re.projectId,Ue=Re.placementId,We=!!ke?.count&&!!(ke.dirty||ke.pending||ke.error);(0,v.useEffect)(()=>{let e=globalThis.document.documentElement,t=new MutationObserver(()=>Me(e.dataset.mode||`light`));return t.observe(e,{attributes:!0,attributeFilter:[`data-mode`]}),()=>t.disconnect()},[]);let Ge=(0,v.useMemo)(()=>{try{let e=pW(t);return{value:e,signature:ht(e)}}catch(e){return{error:e.message}}},[t]);R.current={onSharedChange:o,onRun:u,onUseOutput:d,onAddFiles:f,onChangeFiles:p,onPreviewImage:m,onPreviewMedia:h,onError:g},ne.current=Ge;let[Ke,qe]=(0,v.useState)(null),Je=b?Ke?.handle===b&&Ke.allowed:!F||Ke?.content===F&&Ke.parent===I&&Ke.allowed;(0,v.useEffect)(()=>{if(!F&&!b)return;let e=!0,t=new AbortController;return qe(null),(b?T(b,{signal:t.signal}):Promise.all([F,...I?[I]:[]].map(e=>HU(e,{signal:t.signal})))).then(()=>{e&&qe({handle:b,content:F,parent:I,allowed:!0})},t=>{t?.code===`BLOCK_REVOKED`&&F&&gi(F,`${a||`anonymous`}:${r||`preview`}`).catch(()=>{}),e&&(qe({handle:b,content:F,parent:I,allowed:!1,error:t.message}),R.current.onError?.(t))}),()=>{e=!1,t.abort()}},[F,I,b,oe]);let Ye=DH(P)&&P.files?P.files:null,[Xe,Ze]=(0,v.useState)(null);(0,v.useEffect)(()=>{if(!Ye||!Je){Ze(null);return}let e=!0,t=new AbortController;return Ze(null),Promise.resolve().then(()=>(bH(P),bi(()=>Promise.resolve().then(()=>(QU(),YU)),void 0))).then(({loadViewAssets:e})=>e(Ye,{signal:t.signal})).then(t=>{e&&Ze({files:Ye,assets:t})},t=>{e&&Ze({files:Ye,error:String(t?.message||`The interface files could not be loaded.`)})}),()=>{e=!1,t.abort()}},[P,Ye,Je]);let Qe=Ye?Xe?.files===Ye?Xe:{loading:!0}:null,$e=JSON.stringify([...new Set(M.filter(e=>typeof e==`string`))].sort()),et=vt(F?.manifest?.inputs)?ht(Object.fromEntries(Object.entries(F.manifest.inputs).map(([e,t])=>[e,String(t?.type||``)]))):``,tt=[P,Qe,k,j,oe,a,r,ee,te,O,Ve,He,Ue,$e,et,!!F?.manifest?.sharedWork,F?.capability?.operation],nt=(0,v.useRef)(null);if(!nt.current||tt.some((e,t)=>!Object.is(e,nt.current.inputs[t]))){let e;try{if(Qe?.loading)throw Object.assign(Error(`Loading the interface files.`),{loading:!0});if(Qe?.error)throw Error(Qe.error);let t=tW(),n=tW(),r=AU();e={session:t,nativeTextToken:n,filming:!!r,html:xW(P,t,Ne.current,j,Ve,JSON.parse($e),n,!!F?.manifest?.sharedWork,F?.capability?.operation===`connection.execute`,{assets:Qe?.assets||{},filming:r,inputTypes:et?JSON.parse(et):null}),locked:JSON.parse($e)}}catch(t){e=t.loading?{loading:!0}:{error:t.message}}nt.current={inputs:tt,document:e}}let rt=nt.current.document,it=rt?.session;(0,v.useEffect)(()=>{let e=L.current?.contentWindow;e&&it&&e.postMessage({channel:$U,session:it,op:`zoom-mode`,mode:_e},`*`)},[_e,it]),(0,v.useEffect)(()=>{if(!O||!it)return;let e=null,t=()=>{e=null;let t=L.current?.contentWindow;t&&t.postMessage({channel:$U,session:it,op:`zoom-space`,height:wU(L.current)},`*`)},n=()=>{clearTimeout(e),e=setTimeout(t,200)};return addEventListener(`resize`,n),()=>{clearTimeout(e),removeEventListener(`resize`,n)}},[O,it]);let at=(0,v.useMemo)(()=>({state:{},outputs:{},memory:null,canEdit:!0,localOnly:!0}),[rt.session]),ot=(0,v.useRef)(n);ot.current=n??at;let st=(0,v.useRef)(n==null);st.current=n==null;let ct=(0,v.useRef)({session:null,count:0}),lt=(0,v.useRef)(null),ut=(0,v.useRef)(null),dt=(0,v.useRef)(null),ft=(0,v.useRef)(null),pt=(0,v.useRef)(null),mt=(0,v.useRef)(null),_t=(0,v.useRef)(null);mt.current={key:r,peers:i,actorId:a};let B=(0,v.useRef)(null),yt=(0,v.useRef)(null);yt.current={input:Ge.signature,error:Ge.error,view:P,policyContent:F,policyParent:I,resetKey:k,appearance:j,policyReady:Je};let bt=(0,v.useRef)(null);bt.current=ht([N?.projectId,N?.placementId,N?.sourceDigest,a].map(e=>e??null));let[xt,St]=(0,v.useState)(null),Ct=ht([jt(),a,bt.current,rt.session,Ge.signature,Je].map(e=>e??null));(0,v.useEffect)(()=>{let e=!0;if(St(null),!N?.projectId||!N?.placementId||!N?.sourceDigest||Ge.error||!Je||a!==jt())return()=>{e=!1};let t=Ct;return gt(Ge.value).then(n=>{e&&St({basis:t,value:{version:1,actorId:a,projectId:N.projectId,placementId:N.placementId,sourceDigest:N.sourceDigest,inputDigest:n}})},()=>{e&&St(null)}),()=>{e=!1}},[Ct]),xt?.basis===Ct&&xt.value;let[wt,Tt]=(0,v.useState)(null),Et=(0,v.useRef)(null),Ot=(0,v.useRef)(null),[kt,At]=(0,v.useState)(null),[Mt,Nt]=(0,v.useState)(!1),[Pt,Ft]=(0,v.useState)(!1),[It,Lt]=(0,v.useState)(null);It&&It.actor===a&&It.runtimeActor===jt()&&It.identity===bt.current&&It.session===rt.session&&Object.keys(It.authority).every(e=>It.authority[e]===yt.current[e])&&It.evidence,{...N},F?.manifest?.id,F?.manifest?.version,rt.session,Ge.signature,ot.current?.canEdit,{...N},rt.session,Ge.signature,ot.current?.canEdit,(0,v.useEffect)(()=>{if(Tt(null),At(null),Ft(!1),Nt(!1),Lt(null),re(``),he(null),Oe(null),Ae(null),rt.error||rt.loading||!Je)return;let e=!0,t=!1,n=!1,i=null,o=null,s=null,c=0,l=0,u=[],d=[],f=0,p=0,m=new Set,h=-1/0,g=-1/0,_=e=>{e.isTrusted&&(h=Date.now())};globalThis.document.addEventListener(`pointerdown`,_,!0),globalThis.document.addEventListener(`keydown`,_,!0);let v,y=0,b=null,x=[],S=null,T=0,D=!1,k=0,A=new Set,j=0,M=null,I=0,z=0,ie=null,oe=DH(P),se=null,ue=()=>{se&&globalThis.document.fullscreenElement!==se&&(se=null,ge({op:`media-stage-end`}))};globalThis.document.addEventListener(`fullscreenchange`,ue);let fe=()=>{let t;return t=jz(F,{onStatus:n=>{e&&v===t&&de(n)},onLive:(n,r)=>{e&&v===t?L.current?.contentWindow?.postMessage({channel:$U,session:rt.session,op:`live`,...n},`*`,r):n.bitmap?.close?.()},onActivity:n=>{e&&v===t&&pe(n)},storageScope:`${a||`anonymous`}:${r||`preview`}`}),t};v=fe(),ce.current=v,de(null),pe(null);let me=()=>{if(!e||!ot.current?.canEdit)return;let t=v;v=fe(),ce.current=v,b=null,de(null),Promise.resolve(t.close()).catch(()=>{})};le.current=me;let ge=t=>{e&&L.current?.contentWindow?.postMessage({channel:$U,session:rt.session,...t},`*`)},_e=null,ve=0,ye=(e,t)=>{let n=ut.current,r=L.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};ye(null,null),dt.current=n=>{!e||!t||typeof n!=`string`||_e&&Date.now()-_e.at<1e3||(_e={id:`locate-`+ ++ve,control:n,at:Date.now()},ge({op:`locate-view-control`,id:_e.id,control:n}))};let Se=new Map,Te=new Set,De=0,ke=!1,je=(e,t)=>new Promise(n=>{let r=`film-`+ ++De,i=setTimeout(()=>{Se.delete(r),n(null)},6e3);Se.set(r,e=>{clearTimeout(i),Se.delete(r),n(e)}),ge({op:e,id:r,...t})}),Me=rt.filming&&L.current?jU({element:L.current,placementId:N?.placementId||null,capture:e=>je(`capture-view`,e),locate:e=>je(`locate-view-control`,{control:e}),get drawn(){return ke},onChange:e=>(Te.add(e),()=>Te.delete(e))}):null,Re=null,ze=null,We=0,Ge=!1,Ke=a,qe=yt.current,Ye=bt.current,Xe=(t,n)=>{if(!e||Ge||t?.signal?.aborted||jt()!==Ke||bt.current!==Ye||ze&&ne.current.signature!==ze.inputIdentity||Re&&ne.current.signature!==Re.inputIdentity&&ne.current.signature!==n||Object.keys(qe).filter(e=>e!==`input`).some(e=>qe[e]!==yt.current[e]))throw Ge=!0,Ft(!1),Error(`The declared interface source, account or task changed. Reload the preview before further assisted edits.`)},Ze=e=>{if(!Re)return;let t=Re;Re=null,clearTimeout(t.timer),t.context?.signal?.removeEventListener(`abort`,t.abort),Nt(!1),t.reject(e)};Ot.current={request:(e,n,r={})=>new Promise((a,o)=>{try{if(Xe(r),!t||Re)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(++We),c=()=>{Ge=!0,Ft(!1),i?.abort(),Ze(Error(`Declared action stopped; reload the preview before more assisted edits.`))},l=setTimeout(c,te);Re={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`&&Nt(!0),ge({op:e,id:s,...n})}catch(e){o(e)}})},Et.current={request:(e,n)=>new Promise((r,i)=>{try{if(Xe(n),!t||Re||ze||!n.taskFence||n.signal?.aborted)throw Error(`The original text requires its idle current task.`);let a=String(++We),o=()=>{Ge=!0,Ft(!1),ze?.id===a&&(ze=null,Nt(!1),i(Error(`Original text stopped; retain its pending request.`)))},s=setTimeout(o,te);ze={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}),Nt(!0),ge({op:`dispatch-named-text`,id:a,control:e})}catch(e){i(e)}})};let Qe=()=>{if(Ge)throw Error(`This previous assisted interface is no longer writable. Reload it to recover.`);return Re?.op===`dispatch-view-control`?(Xe(Re.context),Re.context):null},$e=!1,et=0,tt=[],nt=0,it=!1,at=0,ct=[],gt=0,xt=0,St=[],Ct=null,wt=!1,kt={projectId:He,placementId:Ue,actorId:a},Mt=()=>e&&Ie.current?.projectId===kt.projectId&&Ie.current?.placementId===kt.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=Ie.current?.projectId&&a?$n({projectId:Ie.current.projectId,actorId:a,headers:er,onChange:e=>{if(Mt()){if(e.kind===`revoked`){wt=!0,ge({op:`shared-view`,value:{...ot.current,canEdit:!1}});return}[`text`,`document`,`resync`].includes(e.kind)&&(e.scope&&e.scope!==`canvas`||Ct===null&&(Ct=setTimeout(()=>{Ct=null,t&&Mt()&&!wt&&ge({op:`text-refresh`})},100)))}}}):null,Rt=Fe.current?.projectId&&a?$n({projectId:Fe.current.projectId,actorId:a,headers:er,onChange:e=>{t&&[`document`,`resync`,`revoked`,`connection-access`].includes(e.kind)&&(nt++,ge({op:`shared-work-refresh`}))}}):null,zt=()=>{t&&ge({op:`theme`,mode:Ne.current})};_t.current=zt;let Bt=`[]`,Vt=()=>{if(!t)return;let{key:e,peers:n,actorId:r}=mt.current,i=!st.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=VH(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!==Bt&&(Bt=a,ge({op:`peer-cursors`,peers:i}))};pt.current=Vt,window.addEventListener(`stillmade:cursor-preferences`,Vt),window.addEventListener(`storage`,Vt);let Ht=null,Ut=()=>{let e=L.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}},Wt=()=>{Ht&&(Ht.bounds=Ut())},Gt=()=>{Ht&&(Ht=null,window.removeEventListener(`scroll`,Wt,{capture:!0}),window.removeEventListener(`resize`,Wt))},Kt=n=>{let r=n.detail;e&&r?.root?.contains?.(L.current)&&(r.action===`start`&&t&&!Ht?(Ht={bounds:Ut()},window.addEventListener(`scroll`,Wt,{passive:!0,capture:!0}),window.addEventListener(`resize`,Wt),ge({op:`pick-start`})):r.action===`stop`&&Ht&&(Gt(),ge({op:`pick-stop`})))};window.addEventListener(GH.control,Kt);let qt=e=>{re(e),R.current.onError?.(Object.assign(Error(e),{shown:!0}))},Jt=()=>{e&&(clearInterval(M),ie?.disconnect(),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),qt(`This interface stopped responding and was closed. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))};lt.current=oe?()=>{e&&(clearInterval(M),Promise.resolve(v?.call(`live.stop`)).catch(()=>{}),qt(`This interface tried to leave its frame and was closed. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))}:null;let Yt=()=>{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(`#${rt.session}`));ie=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>=SH.longTaskMs||e.reduce((e,t)=>e+t.duration,0)>=3500)return Jt()}});try{ie.observe({type:`longtask`})}catch{ie=null}},Xt=()=>{I=Date.now(),M=setInterval(()=>{if(!e)return clearInterval(M);if(globalThis.document.visibilityState!==`hidden`&&Date.now()-I>8e3)return Jt();ge({op:`ping`,id:String(++z)})},2e3)};ae(!0);let Zt=setTimeout(()=>{e&&!t&&(ae(!1),qt(C()?w():`This Block could not start. Reload it to try again.`),e=!1,i?.abort(),L.current&&(L.current.src=`about:blank`))},C()?5e3:15e3),Qt=e=>{let t=o;t&&(Lt(null),o=null,t.controller.abort(),e&&ge({op:t.media?`preview-media-result`:`preview-image-result`,id:t.id,error:e}))},$t=()=>{if(!t)return;let e=ne.current;if(e.error){Qt(`Preview input is unavailable.`),qt(e.error);return}s!==e.signature&&(Qt(`Preview input changed. Use its current image.`),s=e.signature,ge({op:`input`,input:e.value}))};B.current=$t;let en=null,tn=!1,nn=0,rn=[],an=null,on=0,sn=null,cn=Yn(()=>{if(st.current||!t)return Promise.resolve();if(!e)return Promise.reject(Error(`The Block interface is unavailable. Its latest edits could not be checked.`));if(an)return an.promise;let n=String(++on),r,i,a=new Promise((e,t)=>{r=e,i=t}),o=setTimeout(()=>{an?.id===n&&(an=null,i(Error(`The Block did not confirm its pending edits. Stay here to recover the draft.`)))},17e3);return an={id:n,promise:a,resolve:r,reject:i,timer:o},ge({op:`flush-shared`,id:n}),a}),ln=()=>{if(t&&ot.current)try{let e=pW(ot.current),t=ht(e);if(t===en)return;en=t,ge({op:`shared-view`,value:e})}catch(e){qt(e.message)}};ft.current=ln;let un=t=>{e&&st.current&&(ot.current.outputs=t,ln())},dn=r=>{let s=r.data;if(oe&&e&&vt(s)&&s.op===`navigated`&&s.channel===$U&&s.session===rt.session&&(r.source===null||r.source===L.current?.contentWindow)){lt.current?.();return}if(!e||r.source!==L.current?.contentWindow||!vt(s)||s.channel!==$U||s.session!==rt.session)return;if(s.op===`document-ready`){n||(n=!0,ge({op:`document`,html:rt.html}));return}if(s.op===`view-changed`){ke=!0;let e=Array.isArray(s.rects)?s.rects.slice(0,40).filter(e=>vt(e)&&[`x`,`y`,`width`,`height`].every(t=>Number.isFinite(e[t]))):[];for(let t of Te)t(e);return}if(s.op===`capture-view-result`||s.op===`view-control-rect`&&Se.has(s.id)){let e=Se.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:vt(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`){we.current(s.step===`auto`?`auto`:TU(Ce.current,s.step===`bigger`?nU:-nU));return}if(s.op===`media-stage`){let e=L.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`){se=e;try{Promise.resolve(e.requestFullscreen()).catch(()=>{se=null})}catch{se=null}}}else if(t.fullscreenElement===e){se=null;try{Promise.resolve(t.exitFullscreen?.()).catch(()=>{})}catch{}}return}if(s.op===`zoom-state`){be(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,ae(!1),clearTimeout(Zt),ge({op:`zoom-mode`,mode:xe.current}),O&&ge({op:`zoom-space`,height:wU(L.current)}),oe&&(Xt(),Yt()),zt(),$t(),ln(),Vt(),ge({op:`inspect-view-controls`,offset:0}),ge({op:`inspect-named-text`}));return}if(s.op===`flush-shared-result`){if(!an||s.id!==an.id)return;let e=an;an=null,clearTimeout(e.timer);let t=s.error||sn;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===L.current&&e-j>=300&&(j=e,window.dispatchEvent(new KeyboardEvent(`keydown`,{key:`Escape`,bubbles:!0})));return}if(s.op===`pong`){oe&&typeof s.id==`string`&&(I=Date.now());return}if(s.op===`unresponsive`){oe&&Jt();return}if(s.op===`interface-error`){qt(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;vt(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)&&Oe(e);return}if(s.op===`text-recovery-status`){let e=s.status;Ve&&vt(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`&&Ae(e);return}if(!t)return;if(s.op===`pick-hover`){if(!Ht)return;let e=XH(s.hover),t=Ht.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(GH.hover,{detail:{hover:n}}));return}if(s.op===`pick-result`||s.op===`pick-cancel`){if(!Ht)return;Gt();let e=s.op===`pick-result`?ZH(s.target):null;e?window.dispatchEvent(new CustomEvent(GH.result,{detail:{target:e}})):window.dispatchEvent(new CustomEvent(GH.cancel));return}if(s.op===`named-text-controls`){if(s.token===rt.nativeTextToken&&Array.isArray(s.snapshot)&&s.snapshot.length<=50){let e=pW(s.snapshot);e.every(e=>vt(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`)&&Tt(e)}return}if(s.op===`named-text-result`){let e=ze;if(!e||s.id!==e.id||s.token!==rt.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{ze=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Nt(!1)}return}if(s.op===`view-controls`){try{let e=pW(s.snapshot);if(!vt(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=>!vt(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(At(e),Ft(!Ge),Re?.op===`inspect-view-controls`&&e.offset===Re.offset){let e=Re;Xe(e.context),Re=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),e.resolve()}}catch(e){Ze(e)}return}if(s.op===`view-control-rect`){if(!_e||s.id!==_e.id)return;let{control:e}=_e,t=s.rect;_e=null,ye(e,vt(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`){Ze(Error(String(s.error||`Declared controls are unavailable.`).slice(0,1e3)));return}if(s.op===`view-control-result`){if(Re?.op!==`dispatch-view-control`||s.id!==Re.id)return;let e=Re;try{if(Xe(e.context),s.error)throw Error(String(s.error).slice(0,1e3));Re=null,clearTimeout(e.timer),e.context.signal?.removeEventListener(`abort`,e.abort),Nt(!1),e.resolve()}catch(e){Ze(e)}return}if(s.op===`connected-app-request`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=et)return;et=Number(s.id);let t=e=>ge({op:`connected-app-result`,id:s.id,...e}),n=Pe.current,r=yt.current;tt=tt.filter(e=>Date.now()-e<6e4);try{if(F?.capability?.operation!==`connection.execute`||!n?.request)throw Error(`Open the saved connected Block to choose its task.`);let i=Dt(s.operation,pW(s.args));if(i.operation!==`tasks`&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);if($e||tt.length>=30)throw Error(`Wait for the current task request.`);$e=!0,tt.push(Date.now()),Promise.resolve().then(()=>n.request(i.operation,i.args)).then(i=>{if(!e||n.projectId!==Pe.current?.projectId||n.placementId!==Pe.current?.placementId||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`The installed app changed. Open its current workspace.`);t({result:pW(i)})},e=>t({error:String(e.message||`Task selection failed.`).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{$e=!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=Fe.current,n=yt.current,r=nt,i=e=>ge({op:`shared-work-result`,id:s.id,...e});try{if(!F?.manifest?.sharedWork||!F.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(ct=ct.filter(e=>Date.now()-e<6e4),it||ct.length>=60)throw Error(`Wait for the current media preview.`);it=!0,ct.push(Date.now()),Promise.resolve().then(()=>t.previewMedia(s.contributionId,{signal:AbortSignal.timeout(3e4)})).then(t=>{if(!e||r!==nt||Object.keys(n).some(e=>n[e]!==yt.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=Fe.current,r=yt.current,i=nt;ct=ct.filter(e=>Date.now()-e<6e4);try{if(!F?.manifest?.permissions?.project?.includes(`work.shared`)||!F.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,pW(s.args));if(![`read`,`list`,`accounts`,`grants`,`creatives`].includes(a.operation)&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);if(it||ct.length>=60)throw Error(`Wait for the current shared-work request.`);it=!0,ct.push(Date.now()),Promise.resolve().then(()=>n.request(a.operation,a.args)).then(o=>{if(!e||n.projectId!==Fe.current?.projectId||n.placementId!==Fe.current?.placementId||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`This Block changed before the shared-work response. Reopen its current version.`);if(i!==nt){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:pW(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)<=xt)return;xt=Number(s.id);let e=e=>ge({op:`text-result`,id:s.id,...e}),t=Ie.current,n=ne.current.signature,r=yt.current;if(St=St.filter(e=>Date.now()-e<6e4),!Ve||!Mt()||!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(gt>=16||St.length>=1200){e({error:{message:`Shared text requests are arriving too quickly. Your draft is retained.`}});return}let i=()=>{if(!Mt()||ne.current.error||ne.current.signature!==n||Object.keys(r).some(e=>r[e]!==yt.current[e]))throw Error(`Shared text input or workspace changed. Your draft is retained.`);if(wt||s.action!==`read`&&!ot.current?.canEdit)throw Object.assign(Error(`Shared text is read only.`),{code:`READ_ONLY`})},a;try{if(i(),a=pW(s.body),!vt(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}gt++,St.push(Date.now()),Promise.resolve().then(async()=>{if(i(),Qe()&&s.action!==`read`)throw Error(`Assisted shared-text writes require a task-safe native commit interface; this control is unavailable.`);try{let e=ze,n;if(e&&s.action!==`read`){if(Xe(e.context),s.action!==`update`||s.key!==e.field||s.nativeText?.token!==rt.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 ot.current?.state?.[s.key]!=`string`)return{unsupported:!0};throw e}}).then(t=>{i(),e({result:pW(t)})}).catch(t=>e({error:Pt(t)})).finally(()=>{gt--});return}if(s.op===`cursor`){let e=s.cursor;if(vt(e)&&Number.isFinite(e.x)&&Number.isFinite(e.y)&&e.x>=0&&e.x<=1&&e.y>=0&&e.y<=1){let t=L.current?.getBoundingClientRect(),n=VH(e.anchor),r=mt.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&&!st.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)<=nn)return;nn=Number(s.id);let t=e=>{sn=e.error?String(e.error):null,ge({op:`shared-view-result`,id:s.id,...e})};if(rn=rn.filter(e=>Date.now()-e<6e4),tn||rn.length>=240){t({error:`Shared edits are arriving too quickly. Wait and retry.`});return}if(!ot.current?.canEdit||!st.current&&typeof R.current.onSharedChange!=`function`){t({error:`Shared editing is unavailable or read only.`});return}let n;try{if(n=pW(s.request),new TextEncoder().encode(JSON.stringify(n)).length>ar.requestBytes)throw Error(`Shared edit exceeds the limit`)}catch(e){t({error:e.message});return}tn=!0,rn.push(Date.now()),Promise.resolve().then(()=>{if(!e||!ot.current?.canEdit)throw Error(`Shared editing is unavailable or read only.`);if(Qe(),st.current){ot.current.state=or(ot.current.state,n),ln();return}let t=Qe();return R.current.onSharedChange(n,t||void 0)}).then(()=>t({queued:!0}),e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{tn=!1});return}if(s.op===`content-size`){Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&Ee.current?.(s.height),O&&Number.isInteger(s.height)&&s.height>0&&s.height<=1e5&&he(Math.max(280,Math.min(3e4,s.height)));return}if(s.op===`live-ack`){v?.liveAck?.();return}if(s.op===`desktop`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=y)return;y=Number(s.id);let t=e=>ge({op:`desktop-result`,id:s.id,...e});if(x=x.filter(e=>Date.now()-e<6e4),b||x.length>=120){t({error:`Too many desktop requests. Wait before trying again.`});return}let n;try{if(n=pW(s.args||{}),JSON.stringify(n).length>131072||!vt(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&&!ot.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=mW(e),i=[];try{i=gW(ne.current?.value).map(mW)}catch{}if(!r||!(v.authorizesMedia(e)||i.includes(r))){t({error:`Cut a video this Block received or recorded in this session.`});return}}let i={native:v};x.push(Date.now()),b=i,Promise.resolve().then(()=>{if(!e||i.native!==v||r&&!ot.current?.canEdit)throw Error(`Desktop access or edit permission changed before this request.`);if(Qe()&&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 gW(ne.current?.value)}catch{return[]}})()}:void 0)}).then(n=>{if(!e||i.native!==v||r&&!ot.current?.canEdit)throw Error(`Desktop access or edit permission changed before this result could be used.`);t({result:pW(n)})},e=>t({error:String(e.message).slice(0,1e3)})).catch(e=>t({error:String(e.message).slice(0,1e3)})).finally(()=>{b===i&&(b=null)});return}if(s.op===`add-files`){if(typeof s.id!=`string`||!/^\d{1,9}$/.test(s.id)||Number(s.id)<=T)return;T=Number(s.id);let t=e=>ge({op:`add-files-result`,id:s.id,...e});try{let n=lW(F?.manifest,s.port);if(!ot.current?.canEdit)throw Error(`You can view this project but not add files to it.`);if(rt.locked.includes(n.name))throw Error(`This input comes from an earlier Step, so files cannot be added to it here.`);if(Qe())throw Error(`Only a person adds files. Chat cannot open a file picker.`);if(typeof R.current.onAddFiles!=`function`)throw Error(`Adding files is unavailable here.`);if(S)throw Error(`Files are already being added.`);let r=s.gesture,i=globalThis.navigator?.userActivation;if(!vt(r)||!Number.isInteger(r.id)||r.id<=0||A.has(r.id)||!Number.isFinite(r.age)||r.age<0||r.age>eW||i&&!i.isActive||globalThis.document.activeElement!==L.current)throw Error(`Add files from a click or key press in this screen.`);A.add(r.id);let a={picker:dW(n)};S=a,a.picker.then(t=>{if(!e||S!==a)throw Error(`This Block closed before the files were added.`);if(!t.length)return{added:0};if(!ot.current?.canEdit)throw Error(`You can view this project but not add files to it.`);return R.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(()=>{S===a&&(S=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=lW(F?.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(!ot.current?.canEdit)throw Error(`You can view this project but not change its files.`);if(rt.locked.includes(t.name))throw Error(`This input comes from an earlier Step, so its files cannot be changed here.`);if(Qe())throw Error(`Only a person changes files. Chat cannot remove or move them.`);if(typeof R.current.onChangeFiles!=`function`)throw Error(`Changing files is unavailable here.`);if(D)throw Error(`Files are already being changed.`);let n=s.gesture,r=globalThis.navigator?.userActivation;if(!vt(n)||!Number.isInteger(n.id)||n.id<=0||A.has(n.id)||!Number.isFinite(n.age)||n.age<0||n.age>eW||r&&!r.isActive||globalThis.document.activeElement!==L.current)throw Error(`Remove or move files from a click or key press in this screen.`);let i=vt(s.edit)&&s.edit.op===`remove`?{op:`remove`,index:s.edit.index}:vt(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(uW(a,i),ht(pW(s.item??null))!==ht(a[i.op===`move`?i.from:i.index]))throw Error(`These files changed. Look at them again, then try again.`);A.add(n.id),D=!0,Promise.resolve().then(()=>R.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(()=>{D=!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(Qe())throw Error(`Assisted media adoption requires a task-safe native commit interface; this control is unavailable.`);if(oe&&!ot.current?.canEdit)throw Error(`This workspace is read only.`);let t=pW(s.outputs),n=R.current.onUseOutput;if(typeof n!=`function`)throw Error(`Choosing an existing media output is unavailable in this workspace.`);vW(t,ne.current.value,v),Promise.resolve(n(t)).then(t=>{let n=pW(t);un(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===`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;Lt(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&&Qt(),d.length>=uH.imagePreviewsPerMinute){++p<=3&&n({error:`Image preview limit reached. Wait a minute before trying again.`}),p===4&&(qt(`Preview paused after too many image requests. Reset it to continue.`),e=!1,Qt(),i?.abort(),L.current&&(L.current.src=`about:blank`));return}d.push(r);let c;try{if(c=t?pW(s.value):yW(s.value),t&&(!vt(c)||![`video`,`audio`].includes(c.kind)||![`assetId`,`versionId`,`url`].every(e=>typeof c[e]==`string`&&c[e].length>0&&c[e].length<=32768)))throw Error(`Keep the complete audio or video reference supplied by this workspace.`)}catch(e){n({error:e.message});return}let u=t&&v?.authorizesMedia?.(c)?(e,t)=>qn(e,t):t?R.current.onPreviewMedia:R.current.onPreviewImage;if(typeof u!=`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 f=new AbortController,m=yt.current,h={controller:f,id:s.id,media:t};o=h;let g=bt.current,_=a,y=jt(),b=()=>{if(f.signal.aborted||y!==jt()||g!==bt.current||Object.keys(m).some(e=>m[e]!==yt.current[e]))throw Error(`Image preview input or workspace changed.`)},x=setTimeout(()=>{e&&o===h&&Qt(`Image preview timed out. Try a smaller image.`)},uH.imagePreviewMs);f.signal.addEventListener(`abort`,()=>clearTimeout(x),{once:!0}),Promise.resolve().then(()=>(b(),u(c,{signal:f.signal}))).then(r=>{if(e&&!f.signal.aborted&&o===h){if(b(),t&&r?.kind!==c.kind)throw Error(`The host returned a different media kind.`);let e=t?Gn(r):bW(r);b(),typeof c.assetId==`string`&&c.assetId.length<=512&&typeof c.versionId==`string`&&c.versionId.length<=512&&Lt({actor:_,runtimeActor:y,identity:g,session:rt.session,authority:m,evidence:{assetId:c.assetId,versionId:c.versionId,kind:t?e.kind:`image`,mime:t?e.blob.type:`image/png`,...t?{byteLength:e.blob.size}:{width:e.width,height:e.height},status:`broker-loaded`}}),n({preview:e})}},t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).catch(t=>{e&&!f.signal.aborted&&o===h&&n({error:String(t?.message||`This image could not be previewed`).slice(0,1e3)})}).finally(()=>{clearTimeout(x),o===h&&(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 _=e=>ge({op:`result`,id:s.id,...e});if(oe&&!ot.current?.canEdit){_({error:`Shared editing is unavailable or read only.`});return}let C=Date.now();if(u=u.filter(e=>C-e<6e4),i||u.length>=uH.runsPerMinute){++f<=3&&_({error:i?`A run is already in progress`:`Preview run limit reached. Wait a minute before trying again.`}),f===4&&(qt(`Preview paused after too many requests. Reset it to continue.`),e=!1,Qt(),i?.abort(),L.current&&(L.current.src=`about:blank`));return}let w;try{if(!vt(s.input))throw Error(`Expected input values`);w=pW(s.input)}catch(e){_({error:e.message});return}u.push(C),re(``);let M=new AbortController;i=M,Le.current=!0,Re?.context.signal?.addEventListener(`abort`,()=>M.abort(),{once:!0});let N=setTimeout(()=>{e&&i===M&&(M.abort(),i=null,_({error:ee?`Preview confirmation or execution timed out. Cancellation was requested; the backend may still be finishing.`:`Preview execution timed out. Try a smaller input.`}))},ee?te:15e3);M.signal.addEventListener(`abort`,()=>clearTimeout(N),{once:!0});let P=Re?.op===`dispatch-view-control`?Re:null,z=P?async e=>{if(Re!==P||i!==M||M.signal.aborted||!vt(e)||e.receipt?.status!==`completed`||e.receipt.saved!==!0||ht(e.taskFence)!==ht(P.context.taskFence)||ht([e.projectId,e.placementId,e.sourceDigest,e.actorId])!==Ye||ht(pW(e.beforeInput))!==P.inputIdentity)throw Error(`The native input commit does not match this active declared action.`);let t=ht(pW(e.input));for(let e=0;e<25&&ne.current.signature!==t;e++)if(Xe(P.context,t),await new Promise(e=>setTimeout(e,10)),Re!==P||i!==M||M.signal.aborted)throw Error(`The native input commit was stopped before its render.`);if(Xe(P.context,t),ne.current.signature!==t)throw Error(`The native input commit does not match the current rendered inputs.`);P.inputIdentity=t}:void 0,ie=vt(s.gesture)&&Number.isInteger(s.gesture.id)&&s.gesture.id>0&&Number.isFinite(s.gesture.age)&&s.gesture.age>=0&&s.gesture.age<=eW&&!m.has(s.gesture.id)&&!!globalThis.navigator?.userActivation?.isActive&&globalThis.document.activeElement===L.current&&Date.now()-h>eW&&Date.now()-g>eW;ie&&(m.add(s.gesture.id),g=Date.now()),Promise.resolve().then(()=>R.current.onRun(w,{...Qe(),signal:M.signal,userActivated:ie,...z?{onInputCommitted:z}:{},...F?.manifest?.desktopTools?.length?{nativeDesktopSession:v}:{}})).then(t=>{if(e&&!M.signal.aborted){if(!vt(t))throw Error(`Block execution must return named outputs`);let e=pW(t);un(e),_({outputs:e})}},t=>{e&&!M.signal.aborted&&_({error:String(t?.message||`The Block could not run`).slice(0,1e3)})}).catch(t=>{e&&!M.signal.aborted&&_({error:String(t.message).slice(0,1e3)})}).finally(()=>{clearTimeout(N),i===M&&(i=null),Le.current=!1,setTimeout(()=>{e&&!Le.current&&Be()},250)})};return window.addEventListener(`message`,dn),()=>{S?.picker.cancel(),globalThis.document.removeEventListener(`fullscreenchange`,ue),se&&globalThis.document.fullscreenElement===se&&Promise.resolve(globalThis.document.exitFullscreen?.()).catch(()=>{}),se=null,dt.current=null,ye(null,null),Me?.();for(let e of[...Se.values()])e(null);ze&&=(clearTimeout(ze.timer),ze.context.signal?.removeEventListener(`abort`,ze.abort),ze.reject(Error(`Original text closed; retain its pending request.`)),null),globalThis.document.removeEventListener(`pointerdown`,_,!0),globalThis.document.removeEventListener(`keydown`,_,!0),Et.current=null,Ze(Error(`The declared interface was closed.`)),Ot.current=null,It?.(),Rt?.(),clearTimeout(Ct),cn(),an&&=(clearTimeout(an.timer),an.reject(Error(`Block closed before pending edits were confirmed.`)),null),clearTimeout(Zt),clearInterval(M),ie?.disconnect(),ge({op:`dispose`}),e=!1,v.close(),ce.current===v&&(ce.current=null),le.current===me&&(le.current=null),Qt(),i?.abort(),Le.current=!1,window.removeEventListener(`message`,dn),window.removeEventListener(`stillmade:cursor-preferences`,Vt),window.removeEventListener(`storage`,Vt),window.removeEventListener(GH.control,Kt),Gt(),pt.current=null,B.current=null,ft.current=null}},[rt,Je,ee,te,O,r,a,He,Ue]),(0,v.useEffect)(()=>{B.current?.()},[t]),(0,v.useEffect)(()=>{ft.current?.(),n?.canEdit===!1&&Promise.resolve(ce.current?.close()).catch(()=>{})},[n,Je]),(0,v.useEffect)(()=>{pt.current?.()},[i,r,a,n]),(0,v.useEffect)(()=>{_t.current?.()},[A,je]);let Rt=!!globalThis.stillmadeDesktop?.blockDesktop,zt=ue?.camera&&ue?.microphone?`camera and microphone`:ue?.camera?`camera`:`microphone`;return(0,V.jsxs)(`div`,{className:`bs-sandbox-ui`,style:{position:`relative`},children:[ue?.kind===`live`&&ue.awaitingStart&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:`Ready to share your ${zt} live with this Block. It receives nothing until you press Start, and nothing is saved.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:`Start ${zt}`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Cancel`})]}),ue?.kind===`live`&&ue.active&&(0,V.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,V.jsx)(`strong`,{children:`${zt[0].toUpperCase()}${zt.slice(1)} on`}),(0,V.jsx)(`span`,{children:` · Shared live with this Block. Nothing is saved.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.stop,children:`Turn off ${zt}`})]}),ue?.awaitingStart&&(ue.kind===`folder`||ue.kind===`folder-access`)&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:ue.kind===`folder`?`This Block asks for a folder to ${ue.write?`read and change`:`read`}. It reaches only the folder you choose.`:`Allow StillMade to use ${ue.folder} again for this Block.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:ue.kind===`folder`?`Choose folder`:`Allow`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ue.cancel?ue.cancel():ce.current?.close(),children:`Cancel`})]}),ue?.awaitingStart&&![`live`,`folder`,`folder-access`].includes(ue.kind)&&(0,V.jsxs)(`div`,{className:`bs-notice`,role:`status`,children:[(0,V.jsx)(`p`,{children:ue.kind===`camera`?`Ready to record your camera. This Block records only after you press Start.`:ue.kind===`microphone`?`Ready to record your microphone. This Block records only after you press Start.`:ue.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,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:ue.start,children:ue.kind===`camera`?`Start camera recording`:ue.kind===`microphone`?`Start microphone recording`:`Start screen recording`}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Cancel`})]}),ue?.active&&ue.kind!==`live`&&(0,V.jsxs)(`div`,{role:`status`,className:`bs-notice`,children:[(0,V.jsxs)(`strong`,{children:[ue.ended?`Recording stopped`:`Recording`,` `,ue.kind||`media`]}),(0,V.jsxs)(`span`,{children:[` · `,ue.ended?ue.message:Rt?`This Block has temporary desktop access.`:`Recording runs in StillMade, outside the Block.`]}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:Rt?`Cancel recording and revoke access`:`Discard recording`})]}),Rt&&ue?.closed&&F?.manifest?.permissions?.desktop?.length>0&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:!Je||!ot.current?.canEdit,onClick:()=>le.current?.(),children:`Reopen desktop access`}),Rt&&!ue?.closed&&!ue?.active&&F?.manifest?.permissions?.desktop?.length>0&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,onClick:()=>ce.current?.close(),children:`Revoke this Block’s desktop access`}),rt.loading?(0,V.jsx)(_r,{label:`Loading the interface…`}):rt.error?(0,V.jsxs)(`p`,{role:`alert`,children:[`This interface cannot be previewed: `,rt.error]}):Je?(0,V.jsxs)(V.Fragment,{children:[ie&&!z&&(0,V.jsx)(`p`,{className:`sm-status`,"data-state":`loading`,role:`status`,children:`Opening this Block…`}),(0,V.jsx)(`iframe`,{ref:L,onLoad:()=>{ct.current.session!==rt.session&&(ct.current={session:rt.session,count:0}),++ct.current.count>2&&lt.current?.()},title:S,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,src:`${x(`/block-ui-sandbox.html`)}#${rt.session}`,style:{width:`100%`,height:O&&me||D,minHeight:280,border:`1px solid var(--border-tok)`,borderRadius:`var(--r-3)`,background:`var(--bg)`,...z?{display:`none`}:{}}},rt.session),(0,V.jsx)(`span`,{ref:ut,hidden:!0,"aria-hidden":`true`,"data-agent-control-anchor":``,style:{position:`absolute`,left:0,top:0,pointerEvents:`none`}}),ye?.supported&&!z&&(0,V.jsx)(EU,{zoom:ye.zoom,mode:_e,onChange:Se})]}):(0,V.jsx)(`p`,{role:Ke?.error?`alert`:`status`,children:Ke?.error||`Checking Block safety…`}),De?.count>0&&(De.error?(0,V.jsx)(`p`,{role:`alert`,className:`bs-notice`,children:De.error}):De.dirty||De.pending?(0,V.jsx)(`p`,{role:`status`,className:`bs-notice`,children:`Sharing changes…`}):null),ke?.count>0&&(ke.error||ke.dirty||ke.pending)?(0,V.jsxs)(`div`,{className:`bs-notice`,role:ke.error?`alert`:`status`,children:[(0,V.jsx)(`p`,{children:ke.error||`Saving shared text…`}),ke.error&&(0,V.jsx)(`p`,{children:`Your text is retained here. Copy it before leaving; reloading cannot safely recover an unacknowledged draft.`}),ke.retryable&&(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:ke.pending>0||!ot.current?.canEdit,onClick:()=>L.current?.contentWindow?.postMessage({channel:$U,session:rt.session,op:`text-retry`},`*`),children:`Retry save`})]}):null,(z||Ke?.error)&&(0,V.jsxs)(V.Fragment,{children:[z&&(0,V.jsx)(`p`,{role:`alert`,children:z}),(0,V.jsx)(`button`,{type:`button`,className:`btn`,disabled:We,onClick:()=>{We||se(e=>e+1)},children:`Reload`})]}),(0,V.jsx)(SW,{activity:fe,declaresFolders:(F?.manifest?.permissions?.desktop||[]).includes(`folder.read`),session:ce})]})}ut();var wW=50,TW=new Intl.NumberFormat(void 0,{maximumFractionDigits:4});new Intl.NumberFormat(void 0,{maximumFractionDigits:1});var EW=e=>e==null?``:typeof e==`number`?TW.format(e):String(e);function DW(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 OW({value:e,label:t=`Table`}){let[n,r]=(0,v.useState)(0);if(!Ye(e))return(0,V.jsx)(`p`,{role:`alert`,children:`This result is not a valid table.`});let i=Math.max(1,Math.ceil(e.rows.length/wW)),a=Math.min(n,i-1),o=e.rows.slice(a*wW,a*wW+wW),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,V.jsxs)(`div`,{className:`bd-table`,children:[(0,V.jsx)(`div`,{className:`bd-table-scroll`,tabIndex:0,role:`region`,"aria-label":`${t}, ${e.rows.length} rows`,children:(0,V.jsxs)(`table`,{children:[(0,V.jsx)(`thead`,{children:(0,V.jsx)(`tr`,{children:e.columns.map(e=>(0,V.jsx)(`th`,{scope:`col`,children:e},e))})}),(0,V.jsx)(`tbody`,{children:o.map((t,n)=>(0,V.jsx)(`tr`,{children:e.columns.map((e,n)=>(0,V.jsx)(`td`,{className:s[n]?`bd-number`:void 0,children:EW(t[e])},e))},a*wW+n))})]})}),(0,V.jsxs)(`div`,{className:`bd-bar`,children:[(0,V.jsxs)(`span`,{children:[e.rows.length,` `,e.rows.length===1?`row`:`rows`,i>1?` · page ${a+1} of ${i}`:``]}),i>1&&(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a===0,onClick:()=>r(a-1),children:`Previous`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,disabled:a>=i-1,onClick:()=>r(a+1),children:`Next`})]}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-secondary`,onClick:()=>DW(new Blob([$e(e)],{type:`text/csv`}),`${t.replace(/[^\w-]+/g,`-`).toLowerCase()||`table`}.csv`),children:`Download CSV`})]})]})}Tt(),ut();var kW=new Set([`image`,`audio`,`video`]),AW=e=>kW.has(e?.kind)&&typeof e.url==`string`,jW=(e,t,n=`${t}s`)=>`${e} ${e===1?t:n}`,MW=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)},NW=50,PW=e=>Object.keys(e).filter(t=>t!==`schemaVersion`&&e[t]!==void 0&&e[t]!==null&&e[t]!==``),FW=e=>{if(!vt(e))return e;let t=PW(e);return t.length===1&&(Array.isArray(e[t[0]])||vt(e[t[0]]))?FW(e[t[0]]):e},IW=e=>e===null||[`string`,`number`,`boolean`].includes(typeof e),LW=e=>typeof e==`boolean`?e?`Yes`:`No`:String(e??``);function RW(e){if(e.length<2||!e.every(e=>vt(e)&&PW(e).every(t=>IW(e[t]))))return null;let t=[...new Set(e.flatMap(PW))];if(!t.length||t.length>6)return null;let n={columns:t.map(MW),rows:e.map(e=>Object.fromEntries(PW(e).map(t=>[MW(t),typeof e[t]==`boolean`?LW(e[t]):e[t]])))};return Ye(n)?n:null}function zW({value:e,renderMedia:t,depth:n=0}){let r=FW(e);if(IW(r))return(0,V.jsx)(`span`,{children:LW(r)});if(AW(r))return t?.(r)??null;if(Ye(r))return(0,V.jsx)(OW,{value:r,label:`Results`});if(Array.isArray(r)){if(!r.length)return(0,V.jsx)(`span`,{className:`sm-data-none`,children:`None`});let e=n<2&&!r.some(AW)&&RW(r);return e?(0,V.jsx)(OW,{value:e,label:`Results`}):n>=3?(0,V.jsx)(`span`,{children:jW(r.length,`item`)}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`ul`,{className:`sm-data-list`,children:r.slice(0,NW).map((e,r)=>(0,V.jsx)(`li`,{children:(0,V.jsx)(zW,{value:e,renderMedia:t,depth:n+1})},r))}),r.length>NW&&(0,V.jsxs)(`p`,{className:`sm-data-none`,children:[`And `,r.length-NW,` more.`]})]})}if(!vt(r))return null;let i=PW(r);return i.length?n>=3?(0,V.jsx)(`span`,{children:jW(i.length,`detail`)}):(0,V.jsx)(`dl`,{className:`sm-data-record`,children:i.map(e=>(0,V.jsxs)(v.Fragment,{children:[(0,V.jsx)(`dt`,{children:MW(e)}),(0,V.jsx)(`dd`,{children:(0,V.jsx)(zW,{value:r[e],renderMedia:t,depth:n+1})})]},e))}):(0,V.jsx)(`span`,{className:`sm-data-none`,children:`None`})}function BW(e,t){let n=(0,v.useRef)(t),r=uU(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 VW({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}=BW(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=fU(g.current,{root:m.current,ui:h.current});return()=>t?.destroy()},[p]),p?(0,V.jsx)(`span`,{role:`img`,className:a?`sm-player-off ${a}`:`sm-player-off`,"aria-label":`On another device`,title:`On another device`,children:(0,V.jsx)(bU,{name:`imageOff`,size:24})}):(0,V.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,V.jsx)(`video`,{ref:g,src:f||void 0,preload:u,playsInline:!0,...d}),(0,V.jsx)(`div`,{ref:h,className:`sm-player-ui`})]})}var HW=e=>String(e).padStart(2,`0`),UW=/^(\d{4})-(\d{2})-(\d{2})$/,WW=/^([01]\d|2[0-3]):([0-5]\d)$/,GW=e=>{let t=UW.exec(e||``);return t?{year:+t[1],month:+t[2],day:+t[3]}:null},KW=e=>{let t=GW(e);return!!t&&new Date(Date.UTC(t.year,t.month-1,t.day)).toISOString().slice(0,10)===e},qW=e=>{let{year:t,month:n,day:r}=GW(e);return new Date(Date.UTC(t,n-1,r))},JW=(e,t)=>{let n=qW(e);return n.setUTCDate(n.getUTCDate()+t),n.toISOString().slice(0,10)},YW=(e,t)=>{let{year:n,month:r,day:i}=GW(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()}-${HW(a.getUTCMonth()+1)}-${HW(Math.min(i,o))}`},XW=/(?:time|when|start|schedule|post|send|publish|remind)/i,ZW=(e,t,n)=>typeof n==`string`&&n.includes(`T`)||XW.test(e||``)||/(?:At|_at)$/.test(e||``)||/\b(?:time|when|starts?|at)\b/i.test(t||``),QW=e=>`${eG(e.slice(0,10))}${e[10]===`T`?` · ${tG(e.slice(11,16))}`:``}`;function $W({utc:e=!1,now:t=new Date}={}){return e?t.toISOString().slice(0,10):`${t.getFullYear()}-${HW(t.getMonth()+1)}-${HW(t.getDate())}`}function eG(e,t=$W()){return qW(e).toLocaleDateString(void 0,{weekday:`short`,month:`short`,day:`numeric`,...e.slice(0,4)===t.slice(0,4)?{}:{year:`numeric`},timeZone:`UTC`})}function tG(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 nG(e=30){return Array.from({length:Math.floor(1440/e)},(t,n)=>`${HW(Math.floor(n*e/60))}:${HW(n*e%60)}`)}function rG(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 iG({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=rG(l,u,p,m),_=$W({utc:i}),y=KW(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=JW(d,w[e.key]);else if(e.key===`PageUp`||e.key===`PageDown`)t=YW(d,e.key===`PageUp`?-1:1);else if(e.key===`Home`||e.key===`End`){let n=qW(d).getUTCDay();t=JW(d,e.key===`Home`?-n:6-n)}t!==null&&(e.preventDefault(),f(x(t)))},E=d||y||_,{year:D,month:O}=GW(E),k=`${D}-${HW(O)}-01`,A=new Date(Date.UTC(D,O,0)).getUTCDate(),j=qW(k).getUTCDay(),M=qW(k).toLocaleDateString(void 0,{month:`long`,year:`numeric`,timeZone:`UTC`}),N=JW(k,-1),P=YW(k,1),F=Array.from({length:A},(e,t)=>`${D}-${HW(O)}-${HW(t+1)}`);return(0,V.jsxs)(`span`,{className:`sm-when-pick`,ref:p,onKeyDown:g,children:[(0,V.jsxs)(`button`,{type:`button`,ref:m,className:`sm-when-button`,"aria-haspopup":`dialog`,"aria-expanded":l,"aria-label":`${o}: ${y?eG(y,_):`not chosen`}`,disabled:a,onClick:S,children:[(0,V.jsx)(bU,{name:`calendar`,size:16}),(0,V.jsx)(`span`,{children:y?eG(y,_):s}),(0,V.jsx)(bU,{name:`chevronDown`,size:13})]}),l&&(0,V.jsxs)(`div`,{className:`sm-when-pop sm-when-calendar`,role:`dialog`,"aria-label":`Pick a ${o.toLowerCase()}`,children:[(0,V.jsxs)(`div`,{className:`sm-when-cal-head`,children:[(0,V.jsx)(`b`,{children:M}),(0,V.jsxs)(`span`,{className:`sm-when-cal-nav`,children:[(0,V.jsx)(`button`,{type:`button`,"aria-label":`Previous month`,title:`Previous month`,disabled:!!n&&N<n,onClick:()=>f(x(YW(E,-1))),children:(0,V.jsx)(bU,{name:`chevronLeft`,size:16})}),(0,V.jsx)(`button`,{type:`button`,"aria-label":`Next month`,title:`Next month`,disabled:!!r&&P>r,onClick:()=>f(x(YW(E,1))),children:(0,V.jsx)(bU,{name:`chevronRight`,size:16})})]})]}),(0,V.jsxs)(`div`,{className:`sm-when-cal-grid`,ref:h,onKeyDown:T,children:[[`S`,`M`,`T`,`W`,`T`,`F`,`S`].map((e,t)=>(0,V.jsx)(`i`,{"aria-hidden":`true`,children:e},t)),j>0&&(0,V.jsx)(`span`,{style:{gridColumn:`span ${j}`},"aria-hidden":`true`}),F.map(e=>(0,V.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":qW(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,V.jsx)(`button`,{type:`button`,className:`sm-quiet sm-when-clear`,onClick:()=>{t?.(``),u(!1),m.current?.focus()},children:`Clear`})]})]})}function aG({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=rG(s,c,d,f),g=WW.test(e||``)?e:null,_=g&&!nG(r).includes(g)?[...nG(r),g].sort():nG(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,V.jsxs)(`span`,{className:`sm-when-pick`,ref:d,onKeyDown:h,children:[(0,V.jsxs)(`button`,{type:`button`,ref:f,className:`sm-when-button`,"aria-haspopup":`listbox`,"aria-expanded":s,"aria-label":`${a}: ${g?tG(g):`not chosen`}`,disabled:i,onClick:b,children:[(0,V.jsx)(bU,{name:`clock`,size:16}),(0,V.jsx)(`span`,{children:g?tG(g):o}),(0,V.jsx)(bU,{name:`chevronDown`,size:13})]}),s&&(0,V.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,V.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:tG(e)},e))})]})}function oG({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=KW(e?.slice(0,10))?e.slice(0,10):``,d=WW.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?nG(l).find(e=>e>=p)||p:null;return(0,V.jsxs)(`span`,{className:`sm-when-pickers`,children:[(0,V.jsx)(iG,{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,V.jsx)(aG,{value:d,onChange:e=>t?.(`${u||f||$W({utc:i})}T${e}`),min:(u||f||$W({utc:i}))===f&&p||void 0,step:l,disabled:a,label:`${o} time`})]})}Tt();var sG=Object.freeze([`auto`,`21:9`,`16:9`,`3:2`,`4:3`,`1:1`,`4:5`,`3:4`,`2:3`,`9:16`]),cG=Object.freeze([`auto`,`21:9`,`16:9`,`4:3`,`1:1`,`3:4`,`9:16`]),lG=Object.freeze([4,5,6,7,8,9,10,11,12,13,14,15]),uG=(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":uG(`Nano Banana 2`,{aspectRatios:sG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-2-lite":uG(`Nano Banana 2 Lite`,{aspectRatios:sG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"nano-banana-pro":uG(`Nano Banana Pro`,{aspectRatios:sG,resolutions:[`1K`,`2K`,`4K`],references:8,seed:!0}),"gpt-image-2":uG(`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-1.5":uG(`GPT-Image 1.5`,{aspectRatios:[`16:9`,`9:16`,`1:1`],qualities:[`low`,`medium`,`high`]}),"kling-image-v3":uG(`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":uG(`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:cG,resolutions:[`480p`,`720p`,`1080p`,`4k`],durations:lG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-fast":dG(`Seedance 2.0 Fast`,{aspectRatios:cG,resolutions:[`480p`,`720p`],durations:lG,lastFrame:!0,seed:!0,nativeAudio:!0}),"seedance-2.0-mini":dG(`Seedance 2.0 Mini`,{aspectRatios:cG,resolutions:[`480p`,`720p`],durations:lG,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 fG=2399/11e4,pG=Object.freeze({video:3,build:3,media:4.5,other:3,chat:2}),mG=(e,t)=>Math.max(0,Number(e)||0)*pG[t]/fG,hG=(e,t)=>Math.max(1,Math.ceil(mG(e,t)-1e-9)),gG=`2026-11-05`,_G=`carried`;Object.freeze({"veo-3.1-lite":{usd:.05,resolution:{"720p":1,"1080p":1.6},provider:`Atlas`,checked:gG,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:gG,source:`Atlas catalog list price (we pay $0.034)`},"wan-2.6-flash":{usd:.025,provider:`Atlas`,checked:gG,source:`Atlas catalog list price (we pay $0.018)`},"wan-2.7":{usd:.17,provider:`Higgsfield, then Atlas`,checked:_G,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:gG,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:_G,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:_G,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:_G,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:gG,source:`fal gpt-image-2 price table (dearest size in each class); OpenAI direct is $30 per million output tokens`},"gpt-image-1.5":{quality:{low:{"1K":.013},medium:{"1K":.051},high:{"1K":.2}},provider:`fal`,checked:gG,source:`fal price for a non-square image`},"nano-banana-2":{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:gG,source:`fal: $0.08 at 1K, 1.5x at 2K, 2x at 4K`},"nano-banana-2-lite":{usd:.048,provider:`fal`,checked:gG,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:gG,source:`fal: $0.15, 4K at double`},"kling-image-v3":{usd:.028,provider:`fal`,checked:gG,source:`fal: $0.028 per image`},"seedream-v4.5":{usd:.04,provider:`fal`,checked:gG,source:`fal: $0.04 per image`},"flux-step":{usd:.02,provider:`fal`,checked:_G,source:`carried from the old table`},flux:{usd:.04,provider:`fal`,checked:_G,source:`carried from the old table`},ideogram:{usd:.08,provider:`fal`,checked:_G,source:`carried from the old table`},gemini:{usd:.08,resolution:{"1K":1,"2K":1.5,"4K":2},provider:`fal`,checked:gG,source:`served as Nano Banana 2`}}),Object.freeze({deepgram:{usdPer1kChars:.03,checked:gG,source:`Deepgram Aura-2 pay as you go`},openai:{usdPer1kChars:.015,checked:gG,source:`OpenAI tts-1, $15 per million characters`},elevenlabs:{usdPer1kChars:.04,checked:gG,source:`ElevenLabs API, Flash / Turbo`},kokoro:{usdPer1kChars:.02,checked:gG,source:`fal Kokoro`}}),Object.freeze({usdPerSecond:2e-4,checked:gG,source:`fal ACE-Step, per second of audio`}),Object.freeze({usdPerSecond:.002,checked:gG,source:`fal ElevenLabs sound effects v2, per second`});var vG=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}}),yG=(e,t,n)=>{let r=vG[e];return r?(t*r.input+n*r.output)/1e6:null},bG=Object.freeze({input:2e3,output:1e3}),xG=Object.freeze({input:1e4,output:4096});function SG(e){let t=yG(e,bG.input,bG.output),n=yG(e,xG.input,xG.output);return t===null?null:Math.max(hG(t,`media`),Math.ceil(n/fG-1e-9))}var CG=(e,t,n,r,i={})=>Object.freeze({usd:e,tier:t,unit:n,source:r,checked:i.checked||_G,...i});Object.freeze({"media:analyze":CG(.02,`media`,`call`,`the vision provider caps a call at $0.02 (VISION_MAX_INITIAL_COST)`,{checked:gG}),"media:check":CG(.005,`media`,`call`,`four photos at most, $0.00125 each (MEDIA_CHECK_IMAGE_USD)`,{checked:gG}),"research:search":CG(.008,`media`,`search`,`Tavily basic search`,{checked:gG}),"research:summarize":CG(.01,`media`,`call`,`one Gemini Flash read of fetched pages`,{estimate:!0}),"transcribe:timestamp":CG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:upload":CG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"transcribe:captions":CG(.01,`media`,`run`,`fal Whisper word timing`,{estimate:!0}),"connection:action":CG(.012,`other`,`action`,`a premium Composio tool call at the overage rate`,{checked:gG}),"automation:app-event":CG(.003,`other`,`event`,`Composio, per trigger event`,{checked:gG}),"automation:app-check":CG(3e-4,`other`,`check`,`Composio, per tool call`,{checked:gG}),llm:CG(.01,`other`,`call`,`a Standard model call`,{estimate:!0}),vision:CG(.01,`other`,`image`,`one vision read`,{estimate:!0}),"narrative:compile":CG(.06,`other`,`script`,`about ten Gemini Flash calls`,{estimate:!0}),"narrative:compile-research":CG(.1,`other`,`script`,`the compile plus three Tavily searches and a dossier`,{estimate:!0}),"narrative:learn-voice":CG(.01,`other`,`call`,`one extraction call`,{estimate:!0}),"roughcut:base":CG(.05,`other`,`run`,`segmentation and matching`,{estimate:!0}),"roughcut:per-min":CG(.015,`other`,`footage minute`,`Gemini Flash frame reads`,{estimate:!0}),"finaledit:base":CG(.06,`other`,`run`,`polish decisions`,{estimate:!0}),"finaledit:per-min":CG(.02,`other`,`video minute`,`Gemini Flash scan`,{estimate:!0}),"aomotion:base":CG(.06,`other`,`run`,`motion graphics pass`,{estimate:!0}),"aomotion:per-min":CG(.02,`other`,`video minute`,`motion graphics pass`,{estimate:!0}),"aomotion:base:opus":CG(.12,`other`,`run`,`motion graphics pass on Opus`,{estimate:!0}),"aomotion:per-min:opus":CG(.04,`other`,`video minute`,`motion graphics pass on Opus`,{estimate:!0}),motiongraphic:CG(.015,`other`,`graphic`,`one small call`,{estimate:!0}),"transcript:parse":CG(.005,`other`,`1,000 characters`,`Gemini Flash word timing`,{estimate:!0}),"vibe-edit":CG(.02,`other`,`turn`,`Flash region scan and decision`,{estimate:!0}),"canvas:context-connect":CG(.01,`other`,`run`,`one canvas read`,{estimate:!0}),"anim2:plan":CG(.03,`other`,`video`,`shot planning`,{estimate:!0}),"anim2:vibe":CG(.03,`other`,`turn`,`scene vibe turn`,{estimate:!0}),"anim2:qa":CG(.03,`other`,`frame`,`vision QA`,{estimate:!0}),"anim2:trigger":CG(.01,`other`,`scene`,`one Haiku call`,{estimate:!0}),"gif:plan":CG(.03,`other`,`pass`,`GIF planning`,{estimate:!0}),"canvas:plan":CG(.03,`other`,`pass`,`collage planning`,{estimate:!0}),"canvasChat:build":CG(.03,`other`,`build`,`canvas chat orchestration`,{estimate:!0}),"strip:plan":CG(.05,`other`,`pass`,`strip planning`,{estimate:!0}),"panel:qa":CG(.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,SG(e)])))[`anthropic/claude-sonnet-4.5`],Tt();var wG=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`}),TG=/^(fetch|list|get|search|find|read|retrieve|query|download|lookup|look|check|watch|count|export)$/,EG=new Set([`post`,`posts`,`publish`,`tweet`,`reel`,`reels`,`story`,`stories`,`carousel`,`pin`]),DG=new Set([`video`,`videos`,`photo`,`photos`,`image`,`images`,`media`]),OG=[[`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`]},AG=e=>String(e?.capability?.appId||``).replace(/^app:/,``).replace(/^composio:/,``),jG=e=>e.replace(/[-_.]+/g,` `).trim().replace(/\b\w/g,e=>e.toUpperCase());function MG(e){let t=String(e?.manifest?.name||``).split(` · `);if(t.length>1&&t[0].trim())return t[0].trim();let n=AG(e);return wG[n]||(n?jG(n):`the app`)}function NG(e){let t=String(e?.manifest?.name||``).split(` · `).slice(1).join(` `),n=String(e?.capability?.capabilityId||``).split(`:`).at(-1),r=AG(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=>TG.test(e)||EG.has(e)||OG.some(([,t])=>t.has(e)));if(n&&TG.test(n))return`read`;if(e.some(e=>EG.has(e))||t.some(e=>[`create`,`upload`,`share`].includes(e))&&e.some(e=>DG.has(e)))return`post`;let r=n&&OG.find(([,e])=>e.has(n));if(r)return r[0]}return`send`}function PG(e){let t=MG(e),n=NG(e),[r,i]=kG[n];return{app:t,kind:n,verbs:[`${r} ${t}`,`${i} ${t}…`],canPostLater:n===`post`}}var FG=e=>PG(e).verbs,IG=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…`]}),LG=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase(),RG=new Set([`output`,`outputs`,`result`,`results`,`value`,`data`,`out`]),zG=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 BG(e){let t=e?.manifest;if(!t)return null;let n=String(t.name||``).trim(),r=n.split(/\s+/)[0].toLowerCase();if(zG.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&&!RG.has(LG(a))&&!/action/i.test(String(o?.type||``)),c=o?.label?LG(o.label):LG(s?a:n);return c?[`Make ${c}`,`Making ${c}…`]:null}function VG(e,t){let n=t?.manifest?.action,r=typeof n?.label==`string`?n.label.trim():``;return r?[r,n.running||IG[e]?.[1]||`Working…`]:e===`connection.execute`&&t?FG(t):IG[e]||BG(t)||[`Make the result`,`Making the result…`]}var HG=e=>`${e.toLocaleString()} credit${e===1?``:`s`}`;function UG(e,t,{again:n=!1,free:r=!1,verb:i,connector:a}={}){let o=i||VG(e,a)[0],s=n?`${o} again`:o;return t?.byok?`${s} · your key`:Number.isSafeInteger(t?.credits)&&t.credits>0?`${s} · ${HG(t.credits)}`:r||t?.credits===0?`${s} · ${HG(0)}`:s}var WG=new Set([`image`,`image[]`,`video`,`video[]`,`audio`,`audio[]`,`asset`,`asset[]`,`file`]),GG=3,KG=e=>String(e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_-]+/g,` `).trim().toLowerCase();function qG(e){let t=String(e||``).trim();if(!t)return``;let n=(t.match(/^.+?[.!?](?=\s|$)/)||[t])[0].trim();return n.length<=160?n:``}function JG(e,{inputs:t,labels:n={},groups:r=[]}={}){let i=t||Object.entries(e?.inputs||{}).filter(([,e])=>!e?.context),a=i.length>0&&i.length<=GG&&!r.length,o=i.find(([,e])=>e?.required!==!1&&e?.primary)||i.find(([,e])=>e?.required!==!1)||i[0],s=o?KG(n[o[0]]||o[1]?.label||o[0]):``;return{focused:a,heading:s?`Add your ${s}`:String(e?.action?.label||e?.name||``).trim(),line:qG(e?.description),media:!!o&&WG.has(o[1]?.type)}}var YG=new Set([`text`,`script`,`transcript`,`brief`,`json`,`metadata`,`research`,`document`,`table`]),XG=e=>{let t=String(e||``).replace(/\[\]$/,``);return YG.has(t)?`text`:[`video`,`image`,`audio`].includes(t)?t:void 0},ZG=/^\s*(\d+(?:\.\d+)?)\s*[:/x]\s*(\d+(?:\.\d+)?)\s*$/;function QG(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=XG(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=>ZG.test(String(e||``))),c=ZG.exec(String(s||``));return{kind:a,ratio:c?`${c[1]}/${c[2]}`:a===`video`?`16/9`:`1/1`}}function $G({kind:e,ratio:t,words:n=`Your result shows up here`}){return(0,V.jsxs)(`div`,{className:`sm-result-place`,"data-kind":e||`other`,children:[e===`text`&&(0,V.jsxs)(`span`,{className:`sm-result-lines`,"aria-hidden":`true`,children:[(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{}),(0,V.jsx)(`i`,{})]}),(e===`video`||e===`image`)&&(0,V.jsx)(`span`,{className:`sm-result-frame`,style:{aspectRatio:t},"aria-hidden":`true`,children:(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":e})}),e===`audio`&&(0,V.jsxs)(`span`,{className:`sm-result-audio`,"aria-hidden":`true`,children:[(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`audio`}),(0,V.jsx)(`span`,{className:`sm-result-wave`,children:Array.from({length:24},(e,t)=>(0,V.jsx)(`i`,{},t))})]}),!e&&(0,V.jsx)(`span`,{className:`sm-glyph`,"data-glyph":`spark`,"aria-hidden":`true`}),(0,V.jsx)(`p`,{children:n})]})}var eK=Object.freeze({video:`video`,image:`image`,audio:`audio file`,file:`file`,asset:`file`}),tK=new Set([`video`,`videos`,`image`,`images`,`photo`,`photos`,`picture`,`audio`,`sound`,`file`,`files`,`media`,`asset`,`input`,`upload`,`source`]),nK=Object.freeze({video:[`video`],image:[`image`],audio:[`audio`],file:[`file`],asset:[`image`,`video`,`audio`]}),rK=e=>/^[aeiou]/i.test(e)?`an`:`a`;function iK(e,t={},{label:n}={}){let r=String(n||e||``).replace(/([a-z0-9])([A-Z])/g,`$1 $2`).replace(/[_\-.]+/g,` `).trim(),i=eK[t.type]||`file`,a=r.split(/\s+/).map(e=>/^[A-Z0-9]{2,}$/.test(e)?e:e.toLowerCase()).join(` `),o=!a||tK.has(a)||a===i,s=JU(nK[t.type]||[`file`]);return{title:o?i.charAt(0).toUpperCase()+i.slice(1):a.charAt(0).toUpperCase()+a.slice(1),drop:o?`Drop ${rK(i)} ${i} here`:`Drop your ${a} here`,choose:`Choose ${rK(i)} ${i}`,formats:t.type===`audio`?`${s}, or a video for its sound`:s}}var aK=160,oK=/\blines\b|\b(?:per|each|every|own|by)\s+line\b|\bline\s+(?:per|for each)\b|\bparagraphs?\b|\bbullet(?:s|ed)?\b/i,sK=/\blists?\b/i,cK=/\bcomma/i;function lK(e,t,n){if(e?.type!==`text`)return!1;if(n?.multiline===!0||[t,e.default].some(e=>typeof e==`string`&&e.includes(`
1951
+ `)))return!0;let r=String(e.description||``);return oK.test(r)||sK.test(r)&&!cK.test(r)}function uK(e,t,n){if(e?.type!==`text`||lK(e,t,n)||t!=null&&(typeof t!=`string`||t.length>aK))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<=aK}var dK=[[`light`,`Light`],[`dark`,`Dark`],[`white`,`White`]],fK=[[`full`,`Full width`,null],[`tablet`,`Tablet`,768],[`phone`,`Phone`,390]],pK=new Set([`image`,`video`,`audio`,`file`]),mK={image:`image`,video:`film`,audio:`music`,file:`image`},hK=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)},gK={pdf:`application/pdf`,txt:`text/plain`,csv:`text/csv`,md:`text/markdown`,json:`application/json`,zip:`application/zip`},_K={image:`image/*`,video:`video/*`,audio:`audio/*`,file:Object.keys(gK).map(e=>`.${e}`).join(`,`)};async function vK(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 yK(e,t){let n=e.name.split(`.`).pop().toLowerCase(),r=t===`file`?gK[n]||e.type:e.type||`application/octet-stream`,i=await vK(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 bK(e,t,n,{pick:r=yK}={}){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 xK(e,t,n){for(let t of Object.keys(n||{}))if(!Object.hasOwn(e||{},t))throw Error(`Unknown input: ${t}`);return{...t||{},...n}}function SK({name:e,port:t,value:n,own:r,disabled:i,onPick:a,title:o=MW(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 yK(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=iK(e,t),_=(0,V.jsx)(`input`,{ref:s,type:`file`,hidden:!0,accept:_K[t.type],onChange:h});return r&&!n?(0,V.jsxs)(`div`,{className:`dh-media dh-media-empty`,children:[(0,V.jsx)(`span`,{className:`dh-media-label`,children:o}),(0,V.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,V.jsx)(`strong`,{children:c?`Adding…`:g.drop}),t.description&&(0,V.jsx)(`span`,{children:t.description}),(0,V.jsx)(`small`,{children:g.formats}),(0,V.jsx)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:g.choose}),_,u&&(0,V.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]})]}):(0,V.jsxs)(`div`,{className:`dh-media`,children:[(0,V.jsx)(`span`,{className:`dh-media-label`,children:o}),r?(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`button`,{type:`button`,className:`dh-media-tile dh-media-pick`,disabled:i||c,onClick:()=>s.current?.click(),children:[(0,V.jsx)(bU,{name:n?mK[t.type]:`plus`,size:16}),(0,V.jsx)(`span`,{children:c?`Adding…`:wK(n)||g.choose})]}),_,u&&(0,V.jsx)(`span`,{className:`dh-media-problem`,role:`alert`,children:u})]}):n&&typeof n==`object`?(0,V.jsxs)(`span`,{className:`dh-media-tiles`,title:`The example from the Block's tests`,children:[(0,V.jsx)(CK,{item:n,title:o}),(0,V.jsx)(`small`,{className:`dh-media-note`,children:`Example`})]}):(0,V.jsxs)(`span`,{className:`dh-media-tile`,title:`The example from the Block's tests`,children:[(0,V.jsx)(bU,{name:mK[t.type],size:16}),(0,V.jsx)(`span`,{children:`Add one in the example`}),(0,V.jsx)(`small`,{children:`Example`})]})]})}function CK({item:e,title:t}){let n=(0,v.useRef)(null),[r,i]=(0,v.useState)(!1),a=wK(e)||t;if(!(typeof e?.url==`string`&&e.url.startsWith(`/api/media/`))||![`image`,`video`,`audio`].includes(e.kind))return(0,V.jsxs)(`span`,{className:`dh-media-tile`,title:a,children:[(0,V.jsx)(bU,{name:mK[e?.kind]||`image`,size:16}),(0,V.jsx)(`span`,{children:a})]});if(e.kind===`image`)return(0,V.jsx)(`span`,{className:`dh-thumb`,title:a,children:(0,V.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,V.jsx)(`button`,{type:`button`,className:`dh-thumb-play`,"aria-label":`${r?`Pause`:`Play`} ${a}`,onClick:o,children:(0,V.jsx)(bU,{name:r?`pauseFilled`:`playFilled`,size:14})});return e.kind===`video`?(0,V.jsxs)(`span`,{className:`dh-thumb`,title:a,"data-playing":r||void 0,children:[(0,V.jsx)(`video`,{ref:n,src:e.url,preload:`metadata`,muted:!0,playsInline:!0,...s}),c]}):(0,V.jsxs)(`span`,{className:`dh-media-tile dh-media-sound`,title:a,children:[c,(0,V.jsx)(bU,{name:`music`,size:16}),(0,V.jsx)(`span`,{children:a}),(0,V.jsx)(`audio`,{ref:n,src:e.url,preload:`none`,...s})]})}var wK=e=>{let t=(typeof e?.url==`string`?e.url:``).split(/[?#]/)[0].split(`/`).pop();return e?.name||(t?decodeURIComponent(t):``)},TK=(e,t)=>{try{return localStorage.getItem(e)||t}catch{return t}},EK=(e,t)=>{try{localStorage.setItem(e,t)}catch{}};async function DK(e){return(await fetch(`/__dev/run`,{method:`POST`,headers:{"Content-Type":`application/json`},body:JSON.stringify({input:e})})).json()}async function OK(e,{signal:t}={}){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 n=await fetch(e.url,{signal:t});if(!n.ok)throw Error(`This image is not available in the local preview. Map it to a file under files in tests/mocks.json.`);let r=await createImageBitmap(await n.blob()),i=Math.min(1,512/Math.max(r.width,r.height)),a=document.createElement(`canvas`);return a.width=Math.max(1,Math.round(r.width*i)),a.height=Math.max(1,Math.round(r.height*i)),a.getContext(`2d`).drawImage(r,0,0,a.width,a.height),r.close?.(),{url:a.toDataURL(`image/png`),width:a.width,height:a.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.`)):qn(e,{signal:t})}function AK({value:e}){let t=wK(e);if(!e.url.startsWith(`/api/media/`))return(0,V.jsxs)(`span`,{className:`dh-media-tile`,children:[(0,V.jsx)(bU,{name:mK[e.kind],size:16}),(0,V.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,V.jsxs)(`figure`,{className:`dh-result-media`,children:[e.kind===`image`?(0,V.jsx)(`img`,{src:e.url,alt:t,style:r}):e.kind===`video`?(0,V.jsx)(VW,{src:e.url,preload:`metadata`,style:n?{"--dh-shape":n}:void 0}):(0,V.jsx)(`audio`,{src:e.url,controls:!0,preload:`metadata`}),t&&(0,V.jsx)(`figcaption`,{children:t})]})}var jK=e=>(0,V.jsx)(AK,{value:e}),MK=new Set([`image[]`,`video[]`,`audio[]`,`asset`,`asset[]`,`file[]`]);function NK({name:e,port:t,control:n,value:r,onCommit:i,disabled:a}){let o=r??t.default??(t.type!==`boolean`&&``),s=n?.label||MW(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,V.jsx)(`select`,{id:u,value:c,disabled:a,onChange:e=>{l(e.target.value),i(e.target.value)},children:f.map(e=>(0,V.jsx)(`option`,{value:e,children:e},e))}):n?.control===`slider`&&[`number`,`integer`].includes(t.type)&&Number.isFinite(t.min)&&Number.isFinite(t.max)?(0,V.jsxs)(`span`,{className:`dh-slider`,children:[(0,V.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,V.jsx)(`output`,{htmlFor:u,children:c})]}):t.type===`boolean`?(0,V.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,V.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&&uK(t,o,n)?(0,V.jsx)(`input`,{id:u,type:`text`,value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):(0,V.jsx)(`textarea`,{id:u,className:`dh-text`,rows:Math.min(16,Math.max(3,String(c).split(`
1952
+ `).length)),value:c,disabled:a,onChange:e=>l(e.target.value),onBlur:()=>{c!==o&&i(c)}}):t.type===`date`?(0,V.jsx)(`span`,{id:u,role:`group`,"aria-label":s,children:ZW(e,s,typeof o==`string`?o:``)?(0,V.jsx)(oG,{value:typeof o==`string`?o:``,onChange:e=>i(e||void 0),disabled:a,label:s}):(0,V.jsx)(iG,{value:typeof o==`string`?o.slice(0,10):``,onChange:e=>i(e||void 0),disabled:a,label:s,clearable:!t.required})}):MK.has(t.type)?(0,V.jsxs)(`span`,{className:`dh-media-tiles`,children:[(Array.isArray(o)?o:o?[o]:[]).filter(e=>e&&typeof e==`object`).map((e,t)=>(0,V.jsx)(CK,{item:e,title:`${s} ${t+1}`},t)),!(Array.isArray(o)?o.length:o)&&(0,V.jsx)(`span`,{className:`dh-muted`,children:`None in this example`})]}):(0,V.jsx)(`span`,{className:`dh-muted`,children:`Set in the example input`});return(0,V.jsxs)(`div`,{className:`dh-row`,children:[(0,V.jsx)(`label`,{htmlFor:u,title:d,children:s}),p]})}function PK({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,V.jsxs)(`div`,{className:`dh-input`,children:[(0,V.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,V.jsx)(`p`,{role:`alert`,children:o})]})}var FK=(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,V.jsxs)(`section`,{className:`dh-console`,"aria-label":`Console`,children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`Reloads, runs, logs, stand-ins and errors, newest last.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:t,disabled:!e.length,children:`Clear`})]}),(0,V.jsx)(`ol`,{ref:n,children:e.map(e=>(0,V.jsxs)(`li`,{className:`dh-entry dh-${e.kind}`,children:[(0,V.jsx)(`time`,{children:e.time}),(0,V.jsx)(`span`,{className:`dh-kind`,children:e.label}),(0,V.jsx)(`pre`,{children:e.text})]},e.id))}),!e.length&&(0,V.jsx)(`p`,{className:`dh-muted`,children:`Runs, logs, stand-ins, reloads and errors appear here.`})]})}),IK={run:`Run`,log:`Log`,"stand-in":`Stand-in`,reload:`Reload`,build:`Build`,error:`Error`,view:`View`},LK={full:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`3`,y:`4`,width:`18`,height:`12`,rx:`2`}),(0,V.jsx)(`path`,{d:`M8 20h8M12 16v4`})]}),tablet:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`5`,y:`2`,width:`14`,height:`20`,rx:`2`}),(0,V.jsx)(`path`,{d:`M11 18h2`})]}),phone:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`rect`,{x:`7`,y:`2`,width:`10`,height:`20`,rx:`2`}),(0,V.jsx)(`path`,{d:`M11 18h2`})]}),light:(0,V.jsxs)(V.Fragment,{children:[(0,V.jsx)(`circle`,{cx:`12`,cy:`12`,r:`4`}),(0,V.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,V.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,V.jsx)(`rect`,{x:`4`,y:`4`,width:`16`,height:`16`,rx:`3`}),example:(0,V.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`})},RK=({name:e})=>(0,V.jsx)(`svg`,{className:`dh-glyph`,viewBox:`0 0 24 24`,"aria-hidden":`true`,children:LK[e]});function zK(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=rU({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 BK({label:e,value:t,options:n,onChange:r}){return(0,V.jsx)(`div`,{className:`dh-seg`,role:`radiogroup`,"aria-label":e,children:n.map(([e,n])=>(0,V.jsx)(`button`,{type:`button`,role:`radio`,"aria-checked":t===e,"aria-label":n,title:n,onClick:()=>r(e),children:(0,V.jsx)(RK,{name:e})},e))})}var VK=140,HK=260,UK={"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`},WK=e=>UK[e.name]||UK[e.api]||e.name;function GK({on:e,label:t,onChange:n}){return(0,V.jsxs)(`button`,{type:`button`,role:`switch`,"aria-checked":e,className:`dh-switch`,onClick:()=>n(!e),children:[(0,V.jsx)(`span`,{className:`dh-switch-track`,children:(0,V.jsx)(`span`,{className:`dh-switch-knob`})}),(0,V.jsx)(`span`,{children:t})]})}function KK({tabs:e,status:t,control:n,children:r}){let[i,a]=(0,v.useState)(null),[o,s]=(0,v.useState)(()=>Number(TK(`stillmade.dev.dock`,``))||HK),c=(0,v.useRef)(null),l=e=>a(t=>t===e?null:e),u=e=>{i&&(c.current={y:e.clientY,height:o},e.currentTarget.setPointerCapture(e.pointerId))},d=e=>{let t=c.current;t&&s(Math.round(Math.max(VK,Math.min(window.innerHeight*.75,t.height+t.y-e.clientY))))},f=()=>{c.current&&(c.current=null,EK(`stillmade.dev.dock`,String(o)))},p=e.find(e=>e.key===i);return(0,V.jsxs)(`section`,{className:`dh-dock`,"data-open":p?`true`:`false`,style:p?{height:o}:void 0,"aria-label":`Run details`,children:[p&&(0,V.jsx)(`div`,{className:`dh-dock-grip`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Drag to resize`,onPointerDown:u,onPointerMove:d,onPointerUp:f,onPointerCancel:f}),(0,V.jsxs)(`div`,{className:`dh-tabs`,role:`tablist`,"aria-label":`Run details`,children:[e.map(e=>(0,V.jsxs)(`button`,{type:`button`,role:`tab`,id:`dh-tab-${e.key}`,"aria-selected":i===e.key,"aria-controls":`dh-tabpanel-${e.key}`,onClick:()=>l(e.key),children:[e.label,e.alert&&(0,V.jsx)(`span`,{className:`dh-alert`,"aria-label":`has a problem`})]},e.key)),(0,V.jsx)(`span`,{className:`dh-tabs-status`,role:`status`,children:t}),n,(0,V.jsx)(`button`,{type:`button`,className:`dh-icon dh-fold`,"aria-label":p?`Fold the panel`:`Open the panel`,title:p?`Fold the panel`:`Open the panel`,"aria-expanded":!!p,onClick:()=>a(t=>t?null:e[0].key),children:(0,V.jsx)(bU,{name:`chevronRight`,size:16})})]}),p&&(0,V.jsx)(`div`,{className:`dh-tabpanel`,role:`tabpanel`,id:`dh-tabpanel-${p.key}`,"aria-labelledby":`dh-tab-${p.key}`,children:r(p.key)})]})}function qK(){let[e,t]=(0,v.useState)({revision:0,content:null,problem:null,folder:``}),[n,r]=(0,v.useState)(0),[i,a]=(0,v.useState)(()=>TK(`stillmade.dev.theme`,`light`)),[o,s]=(0,v.useState)(()=>TK(`stillmade.dev.width`,`full`)),[c,l]=(0,v.useState)(0),[u,d]=(0,v.useState)(null),[f,p]=(0,v.useState)(null),[m,h]=(0,v.useState)(!1),[g,_]=(0,v.useState)(``),[y,b]=(0,v.useState)(null),[x,S]=(0,v.useState)(!1),[C,w]=(0,v.useState)({}),[T,E]=(0,v.useState)([]),[D,O]=(0,v.useState)({}),k=(0,v.useRef)({}),A=(0,v.useRef)(0),j=(0,v.useCallback)((e,t)=>E(n=>[...n.slice(-299),{id:++A.current,kind:e,label:IK[e]||e,time:new Date().toLocaleTimeString(),text:String(t)}]),[]),M=(0,v.useCallback)(async()=>{let e=await(await fetch(`/__dev/package`,{cache:`no-store`})).json();return t(e),e},[]);(0,v.useEffect)(()=>{let e=!0;M().then(t=>{e&&(d(e=>e??(t.content?.tests?.[0]?.input||{})),j(`reload`,`Previewing ${t.folder}`),t.problem&&j(`error`,hK(t.problem)))}).catch(e=>j(`error`,e.message));let t=new EventSource(`/__dev/events`);return t.addEventListener(`package`,async t=>{let n=JSON.parse(t.data);try{if(await M(),!e)return;r(e=>e+1),j(n.problem?`error`:`reload`,n.problem?`Reloaded with a problem: ${hK(n.problem)}`:`Reloaded after a change`)}catch(e){j(`error`,e.message)}}),t.addEventListener(`build`,e=>{let t=JSON.parse(e.data);t.state===`running`?j(`build`,`Building: ${t.command}`):t.state===`done`?j(`build`,`Build finished`):j(`error`,`Build failed${t.output?`\n${t.output}`:``}`)}),()=>{e=!1,t.close()}},[]),(0,v.useEffect)(()=>{document.documentElement.dataset.mode=i,EK(`stillmade.dev.theme`,i)},[i]),(0,v.useEffect)(()=>{EK(`stillmade.dev.width`,o)},[o]);let N=e.content,P=N?.manifest,F=N?.tests||[],I=e=>{l(e),d(F[e]?.input||{})},ee=(0,v.useCallback)(async(e,{signal:t}={})=>{j(`run`,`Run started`),h(!0),_(``);try{let n=await DK(e);if(t?.aborted)throw Object.assign(Error(`Run cancelled`),{code:`CANCELLED`});for(let e of n.logs||[])j(`log`,e);for(let e of n.standIns||[])j(`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(b({ms:n.ms,calls:n.standIns||[],failed:!!n.error}),n.error)throw j(`error`,`${n.error}${n.code?` (${n.code})`:``}`),Object.assign(Error(n.error),{code:n.code});return p(n.outputs),j(`run`,`Finished in ${n.ms} ms`),n.outputs}catch(e){throw e?.code!==`CANCELLED`&&(p(null),_(e?.message||`The run did not finish.`)),e}finally{h(!1)}},[j]),te=(0,v.useCallback)(async e=>{let t=or(k.current,e);k.current=t,O(t)},[]),L=()=>{k.current={},O({}),r(e=>e+1),j(`view`,`Shared state cleared`)},R=(0,v.useMemo)(()=>({state:D,outputs:{},memory:null,canEdit:!0}),[D]),ne=(0,v.useCallback)(async e=>{p(e),j(`view`,`The view chose its outputs`)},[j]),z=(0,v.useCallback)(async(t,n)=>{let r=e.content?.manifest?.inputs?.[t],{refs:i,apply:a}=await bK(t,r,n);return x&&pK.has(r.type)?w(e=>({...e,[t]:i[0]})):d(a),j(`view`,`Added ${i.length} ${i.length===1?`file`:`files`} to ${MW(t)}`),{added:i.length}},[e.content,x,j]),re=(0,v.useCallback)(async(e,t)=>{let n=uW(u?.[e],t);return d(t=>({...t,[e]:n})),j(`view`,`${t.op===`remove`?`Removed a file from`:`Moved a file in`} ${MW(e)}`),{files:n.length}},[u,j]),ie=(0,v.useCallback)(e=>j(`error`,String(e?.message||e)),[j]),ae=(0,v.useMemo)(()=>{let t={...u||{}};if(x)for(let[n,r]of Object.entries(e.content?.manifest?.inputs||{}))pK.has(r.type)&&(C[n]?t[n]=C[n]:delete t[n]);return t},[u,x,C,e.content]),oe=(0,v.useCallback)(t=>d(n=>{if(!x)return t;let r={...t};for(let[t,i]of Object.entries(e.content?.manifest?.inputs||{}))pK.has(i.type)&&(n&&Object.hasOwn(n,t)?r[t]=n[t]:delete r[t]);return r}),[x,e.content]),se=(0,v.useCallback)(async(t,n)=>{let r=xK(e.content?.manifest?.inputs,ae,t);return Object.keys(t).length&&oe({...u||{},...t}),ee(r,n)},[e.content,ae,u,oe,ee]),ce=fK.find(([e])=>e===o)?.[2],le=N?.capability?.operation?[N.capability.operation]:(P?.permissions?.capabilities||[]).filter(e=>![`connection.execute`,`comfyui.execute`].includes(e)),ue=m?VG(le.length===1?le[0]:void 0,N)[1]:UG(le.length===1?le[0]:void 0,{credits:0},{connector:N}),de=(0,v.useMemo)(()=>JG(P,{labels:Object.fromEntries((P?.ui||[]).filter(e=>e?.label).map(e=>[e.port,e.label])),groups:P?.uiLayout?.groups||[]}),[P]),fe=(0,v.useRef)(null);zK(fe,[N,o,f,g,m]);let pe=f?Object.entries(P?.outputs||{}).filter(([e])=>f[e]!==void 0).map(([e,t])=>t?.type===`date`&&typeof f[e]==`string`&&/^\d{4}-\d{2}-\d{2}/.test(f[e])?(0,V.jsx)(`p`,{className:`dh-date`,children:(0,V.jsx)(`time`,{dateTime:f[e],children:QW(f[e])})},e):(0,V.jsx)(zW,{value:f[e],renderMedia:jK},e)):null,me=m?`Running…`:y?y.failed?`Last run failed`:`Ran in ${y.ms} ms${y.calls.length?` · ${y.calls.length} ${y.calls.length===1?`call`:`calls`} answered by stand-ins`:``}`:`Reloads when you save`,he=[{key:`activity`,label:`Activity`,alert:T.some(e=>e.kind===`error`)},{key:`calls`,label:`Calls${y?.calls.length?` · ${y.calls.length}`:``}`},...N?.view?[{key:`result`,label:`Result`}]:[],{key:`input`,label:`Input data`}];return(0,V.jsxs)(`div`,{className:`dh-page`,children:[(0,V.jsxs)(`header`,{className:`dh-bar`,children:[(0,V.jsxs)(`div`,{className:`dh-title`,children:[(0,V.jsx)(`h1`,{children:P?.name||`Block preview`}),P&&(0,V.jsx)(`span`,{className:`dh-meta`,children:P.version})]}),(0,V.jsx)(`span`,{className:`dh-spacer`}),F.length>1&&(0,V.jsxs)(`label`,{className:`dh-picker`,title:`Example input`,children:[(0,V.jsx)(RK,{name:`example`}),(0,V.jsx)(`select`,{"aria-label":`Example`,value:c,onChange:e=>I(Number(e.target.value)),children:F.map((e,t)=>(0,V.jsx)(`option`,{value:t,children:e.name},t))})]}),(0,V.jsx)(BK,{label:`Width`,value:o,options:fK,onChange:s}),(0,V.jsx)(BK,{label:`Appearance`,value:i,options:dK,onChange:a}),(0,V.jsx)(`button`,{type:`button`,className:`dh-icon`,"aria-label":`Reload the Block`,title:`Reload the Block`,onClick:()=>r(e=>e+1),children:(0,V.jsx)(bU,{name:`refresh`,size:16})})]}),e.problem&&(0,V.jsx)(`p`,{className:`dh-problem`,role:`alert`,children:hK(e.problem)}),(0,V.jsx)(`main`,{className:`dh-main`,"aria-label":`Preview`,children:(0,V.jsx)(`div`,{className:`dh-frame`,style:ce?{maxWidth:ce}:void 0,children:N?N.view?(0,V.jsx)(CW,{view:N.view,policyContent:N,input:ae,sharedView:R,onSharedChange:te,onRun:se,onUseOutput:ne,onAddFiles:z,onChangeFiles:re,onPreviewImage:OK,onPreviewMedia:kK,onError:ie,actorId:`dev-preview`,title:`${P.name} preview`,height:560,fitContent:!0},n):(0,V.jsxs)(`div`,{className:de.focused?`dh-noview dh-focus`:`dh-noview`,ref:fe,children:[de.focused&&(0,V.jsxs)(`header`,{className:`dh-intro`,children:[(0,V.jsx)(`h2`,{children:de.heading}),de.line&&(0,V.jsx)(`p`,{children:de.line})]}),(0,V.jsx)(`div`,{className:`dh-form`,children:Object.entries(P.inputs||{}).map(([e,t])=>pK.has(t.type)?(0,V.jsx)(SK,{name:e,port:t,title:(P.ui||[]).find(t=>t?.port===e)?.label||MW(e),value:ae[e],own:x,disabled:m,onPick:t=>w(n=>({...n,[e]:t}))},e):(0,V.jsx)(NK,{name:e,port:t,control:(P.ui||[]).find(t=>t?.port===e),value:ae[e],disabled:m,onCommit:t=>d(n=>({...n,[e]:t}))},e))}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-primary`,disabled:m,onClick:()=>ee(ae).catch(()=>{}),children:ue}),g&&(0,V.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),pe?(0,V.jsxs)(`div`,{className:`dh-results`,children:[(0,V.jsx)(`h2`,{children:`Result`}),pe]}):!g&&(0,V.jsx)(`div`,{className:`dh-results dh-results-empty`,children:(0,V.jsx)($G,{...QG(P,{inputs:ae})})})]}):(0,V.jsx)(`p`,{className:`dh-muted`,role:`status`,children:`Loading the Block`})})}),(0,V.jsx)(KK,{tabs:he,status:me,control:(0,V.jsx)(GK,{on:!x,label:`Example media`,onChange:e=>S(!e)}),children:e=>e===`activity`?(0,V.jsx)(FK,{entries:T,onClear:()=>E([])}):e===`calls`?y?.calls.length?(0,V.jsx)(`ol`,{className:`dh-calls`,children:y.calls.map((e,t)=>(0,V.jsxs)(`li`,{children:[(0,V.jsx)(`strong`,{children:WK(e)}),(0,V.jsx)(`span`,{children:e.name}),(0,V.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,V.jsx)(`p`,{className:`dh-muted`,children:y?`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,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`What the Block's view returned.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,onClick:L,children:`Clear shared state`})]}),g&&(0,V.jsx)(`p`,{className:`dh-run-problem`,role:`alert`,children:g}),pe||!g&&(0,V.jsx)(`p`,{className:`dh-muted`,children:`Nothing has run yet.`})]}):(0,V.jsxs)(V.Fragment,{children:[(0,V.jsxs)(`div`,{className:`dh-section-head`,children:[(0,V.jsx)(`span`,{className:`dh-muted`,children:`The exact input the Block runs with, for values the controls cannot set.`}),(0,V.jsx)(`button`,{type:`button`,className:`btn btn-ghost`,disabled:m||!N,onClick:()=>ee(ae).catch(()=>{}),children:ue})]}),u&&(0,V.jsx)(PK,{value:ae,onCommit:oe,disabled:!N}),f&&(0,V.jsx)(`pre`,{className:`dh-json`,children:JSON.stringify(f,null,2)})]})})]})}(0,y.createRoot)(document.getElementById(`root`)).render((0,V.jsx)(qK,{}));