@banou/social 0.0.0-stage → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +382 -2
- package/build/index.js +429 -0
- package/dist/index.d.mts +336 -0
- package/dist/index.mjs +284 -0
- package/dist/names.d.mts +14 -0
- package/dist/names.mjs +55 -0
- package/package.json +67 -4
package/build/index.js
ADDED
|
@@ -0,0 +1,429 @@
|
|
|
1
|
+
var e=(e,t)=>()=>(t||(e((t={exports:{}}).exports,t),e=null),t.exports),t=Object.defineProperty,n=(e,n)=>{let r={};for(var i in e)t(r,i,{get:e[i],enumerable:!0});return n||t(r,Symbol.toStringTag,{value:`Module`}),r},r=`autoplay.fullscreen.picture-in-picture.encrypted-media.screen-wake-lock.speaker-selection.captured-surface-control.camera.microphone.display-capture.geolocation.midi.usb.serial.hid.bluetooth.gamepad.keyboard-map.xr-spatial-tracking.accelerometer.gyroscope.magnetometer.ambient-light-sensor.compute-pressure.clipboard-read.clipboard-write.storage-access.window-management.local-fonts.idle-detection.web-share.sync-xhr.unload.payment.publickey-credentials-get.publickey-credentials-create.otp-credentials.identity-credentials-get.digital-credentials-get.local-network.local-network-access.loopback-network`.split(`.`),i=()=>{try{let e=globalThis.document?.featurePolicy?.features?.();return e===void 0?void 0:new Set(e)}catch{return}},a=(e=!0,t=i())=>[...r,...e?[`cross-origin-isolated`]:[]].filter(e=>t===void 0||t.has(e)).join(`; `),o=`https://fkn.app`,s=e=>`${o}/api${e?`?coi=1`:``}`;`${JSON.stringify(r)}${JSON.stringify(s(!0))}${JSON.stringify(s(!1))}`;var c=((e,t,n,r)=>{if(r?.signal?.aborted)return()=>{};let i=()=>e.addEventListener(t,n,r);i();let a=typeof MutationObserver>`u`?void 0:new MutationObserver(i);return a?.observe(e.window===e?e.document:e,{childList:!0}),r?.signal?.addEventListener(`abort`,()=>a?.disconnect(),{once:!0}),()=>{a?.disconnect(),e.removeEventListener(t,n,r)}}),l=typeof window<`u`||typeof self<`u`,u=Object.defineProperty,d=(e,t)=>{let n={};for(var r in e)u(n,r,{get:e[r],enumerable:!0});return t||u(n,Symbol.toStringTag,{value:`Module`}),n},f=`__OSRA_KEY__`,p=`__OSRA_DEFAULT_KEY__`,m=`__OSRA_BOX__`,h=()=>globalThis.browser??globalThis.chrome,g=()=>h()?.runtime,_=(e,t)=>I(e)&&e.__OSRA_KEY__===t,v=(e,t)=>{if(e){if(e.aborted){t();return}e.addEventListener(`abort`,t,{once:!0})}},y=({listener:e,transport:t,remoteName:n,key:r=p,origin:i=`*`,unregisterSignal:a})=>{if(a?.aborted)return;let o=pe(t)?t.receive:t;if(typeof o==`function`){let t=o((t,i)=>{a?.aborted||_(t,r)&&(n&&t.name!==n||e(t,i))});typeof t==`function`&&v(a,t);return}if(ee(o)||te(o)||re(o)||ie(o)){let t=(t,i)=>{let o=(t,a)=>{_(t,r)&&(n&&t.name!==n||e(t,{port:i,sender:a}))};t.addListener(o),v(a,()=>t.removeListener(o))};if(ee(o))t(o.onMessage);else if(re(o)){let e=e=>t(e.onMessage,e);o.addListener(e),v(a,()=>o.removeListener(e))}else ie(o)?t(o):t(o.onMessage);return}let s=P(o)?o.port:o,c=i!==`*`&&B(o),l=t=>{let a=t.data;if(typeof a==`string`)try{a=JSON.parse(a)}catch{return}_(a,r)&&(n&&a.name!==n||c&&t.origin&&t.origin!==i||e(a,{receiveTransport:o,source:t.source,origin:t.origin}))};s.addEventListener(`message`,l),s instanceof MessagePort&&s.start(),v(a,()=>s.removeEventListener(`message`,l))},b=new WeakSet,x=e=>String(e?.message??e).includes(`disconnected port`),S=(e,t,n=`*`,r=[])=>{let i=pe(e)?e.emit:e;if(typeof i==`function`)i(t,r);else if(B(i))i.postMessage(t,n,r);else if(te(i)){if(b.has(i))return;try{i.postMessage(t)}catch(e){if(!x(e))throw e;b.add(i)}}else if(ee(i))i.sendMessage(t)?.catch?.(e=>{if(!String(e?.message).includes(`Receiving end does not exist`))throw e});else if(k(i)){let e=JSON.stringify(t);i.readyState===WebSocket.CONNECTING?i.addEventListener(`open`,()=>i.send(e),{once:!0}):i.send(e)}else P(i)?i.port.postMessage(t,r):i.postMessage(t,r)},C=globalThis.Float16Array,w={Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float16Array:C,Float32Array,Float64Array,BigInt64Array,BigUint64Array},T=Object.values(w),E=e=>{let t=e.constructor.name;if(t in w)return t;for(let[t,n]of Object.entries(w))if(n&&e instanceof n)return t;throw Error(`Unknown typed array type`)},D=e=>{let t=w[e];if(!t)throw Error(`Unknown typed array type`);return t},O=e=>L(e,T),k=e=>e instanceof WebSocket,A=e=>!!globalThis.ServiceWorkerContainer&&e instanceof ServiceWorkerContainer,j=e=>!!globalThis.ServiceWorker&&e instanceof ServiceWorker,M=e=>!!globalThis.Worker&&e instanceof Worker,N=e=>{let t=globalThis.DedicatedWorkerGlobalScope;return!!t&&e instanceof t},P=e=>!!globalThis.SharedWorker&&e instanceof SharedWorker,F=e=>e instanceof MessagePort,I=e=>!!e&&typeof e==`object`&&`__OSRA_KEY__`in e&&!!e.__OSRA_KEY__,L=(e,t)=>{if(e===null||typeof e!=`object`&&typeof e!=`function`)return!1;for(let n of t)if(n&&e instanceof n)return!0;return!1},R=e=>L(e,[globalThis.SharedArrayBuffer]),z=e=>L(e,[globalThis.ArrayBuffer,globalThis.MessagePort,globalThis.ReadableStream,globalThis.WritableStream,globalThis.TransformStream,globalThis.ImageBitmap,globalThis.OffscreenCanvas,globalThis.AudioData,globalThis.VideoFrame,globalThis.MediaSourceHandle,globalThis.MediaStreamTrack,globalThis.MIDIAccess,globalThis.RTCDataChannel,globalThis.WebTransportReceiveStream,globalThis.WebTransportSendStream]),ee=e=>{let t=g();return t?e===t:!1},te=(e,t=!1)=>!e||typeof e!=`object`||B(e)||!(`name`in e)||!(`disconnect`in e)||!(`postMessage`in e)?!1:!t||`sender`in e&&`onMessage`in e&&`onDisconnect`in e,ne=e=>!!e&&typeof e==`object`&&!B(e)&&`addListener`in e&&`hasListener`in e&&`removeListener`in e,re=e=>{let t=g();return t?e===t.onConnect||e===t.onConnectExternal:!1},ie=e=>ne(e),B=e=>{if(!e||typeof e!=`object`)return!1;try{return`window`in e&&e.window===e}catch{try{return`closed`in e&&typeof e.closed==`boolean`&&`close`in e&&typeof e.close==`function`}catch{return!1}}},ae=e=>k(e)||te(e)||ee(e),oe=e=>k(e)||te(e)||re(e)||ie(e)||ee(e),se=e=>!!e&&typeof e==`object`&&!B(e)&&`isJson`in e&&e.isJson===!0||ae(e)||oe(e),ce=e=>B(e)||ae(e)||j(e)||M(e)||N(e)||P(e)||F(e)||de(e),le=e=>B(e)||oe(e)||A(e)||M(e)||N(e)||P(e)||F(e)||fe(e),ue=e=>{if(!e||typeof e!=`object`||B(e))return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},de=e=>!ue(e)||!(`emit`in e)?!1:ce(e.emit)||typeof e.emit==`function`,fe=e=>!ue(e)||!(`receive`in e)?!1:le(e.receive)||typeof e.receive==`function`,pe=e=>de(e)||fe(e),me=()=>globalThis.Buffer,he=32768,ge=e=>{let t=e.toBase64;if(typeof t==`function`)return t.call(e);let n=me();if(n)return n.from(e).toString(`base64`);let r=``;for(let t=0;t<e.length;t+=he)r+=String.fromCharCode(...e.subarray(t,t+he));return btoa(r)},_e=e=>{let t=Uint8Array.fromBase64;if(typeof t==`function`)return t(e);let n=me();if(n)return new Uint8Array(n.from(e,`base64`));let r=atob(e),i=new Uint8Array(r.length);for(let e=0;e<r.length;e++)i[e]=r.charCodeAt(e);return i},V={[m]:`revivable`},ve=e=>!!e&&typeof e==`object`&&`__OSRA_BOX__`in e&&e.__OSRA_BOX__===`revivable`,ye=(e,t)=>se(t.transport)?{base64Buffer:ge(new Uint8Array(e))}:{arrayBuffer:e},be=e=>`arrayBuffer`in e?e.arrayBuffer:_e(e.base64Buffer).buffer,xe=d({box:()=>we,isType:()=>Ce,objectsOnly:()=>!0,revive:()=>Te,type:()=>Se}),Se=`arrayBuffer`,Ce=e=>e instanceof ArrayBuffer,we=(e,t)=>({...V,type:Se,...ye(e,t)}),Te=(e,t)=>be(e),Ee=d({box:()=>ke,isType:()=>Oe,objectsOnly:()=>!0,revive:()=>Ae,type:()=>De}),De=`date`,Oe=e=>e instanceof Date,ke=(e,t)=>({...V,type:De,ISOString:e.toISOString()}),Ae=(e,t)=>new Date(e.ISOString),je=d({box:()=>Pe,isType:()=>Ne,objectsOnly:()=>!0,revive:()=>Fe,type:()=>Me}),Me=`headers`,Ne=e=>e instanceof Headers,Pe=(e,t)=>({...V,type:Me,entries:[...e.entries()]}),Fe=(e,t)=>new Headers(e.entries),Ie=d({box:()=>Be,isType:()=>ze,objectsOnly:()=>!0,revive:()=>Ve,type:()=>Le}),Le=`error`,Re={Error,TypeError,RangeError,SyntaxError,ReferenceError,EvalError,URIError},ze=e=>e instanceof Error,Be=(e,t)=>{let n=`cause`in e&&e.cause!==void 0,r=typeof AggregateError<`u`&&e instanceof AggregateError,i=typeof DOMException<`u`&&e instanceof DOMException;return{...V,type:Le,name:e.name,message:e.message,stack:e.stack||e.toString(),...n?{cause:oi(e.cause,t)}:{},...r?{errors:oi(e.errors,t)}:{},...i?{isDOMException:!0}:{}}},Ve=(e,t)=>{let n=e.cause===void 0?void 0:ci(e.cause,t),r=n===void 0?void 0:{cause:n};if(e.isDOMException&&typeof DOMException<`u`){let t=new DOMException(e.message,e.name);if(e.stack)try{Object.defineProperty(t,"stack",{value:e.stack,configurable:!0})}catch{}return t}let i;if(e.errors!==void 0&&typeof AggregateError<`u`)i=AggregateError(ci(e.errors,t),e.message,r);else{let t=Re[e.name]??Error;i=r===void 0?new t(e.message):new t(e.message,r)}return e.name&&i.name!==e.name&&(i.name=e.name),e.stack&&(i.stack=e.stack),i},He=d({box:()=>Ge,isType:()=>We,objectsOnly:()=>!0,revive:()=>Ke,type:()=>Ue}),Ue=`typedArray`,We=O,Ge=(e,t)=>{let n=e.byteOffset===0&&e.byteLength===e.buffer.byteLength?e.buffer:e.buffer.slice(e.byteOffset,e.byteOffset+e.byteLength);return{...V,type:Ue,typedArrayType:E(e),...ye(n,t)}},Ke=(e,t)=>new(D(e.typedArrayType))(be(e)),qe=new WeakMap,Je=new WeakSet,Ye=(e,t)=>{if(Je.has(e))return t(),()=>{};let n=qe.get(e);return n||qe.set(e,n=new Set),n.add(t),()=>n.delete(t)},Xe=e=>Je.has(e),Ze=e=>{if(Je.has(e))return;Je.add(e);let t=qe.get(e);if(t){qe.delete(e);for(let e of t)try{e()}catch{}}},Qe=d({box:()=>ut,forceTransfer:()=>st,isInTransfer:()=>ot,isType:()=>lt,objectsOnly:()=>!0,outsideTransfer:()=>ct,revive:()=>dt,transfer:()=>it,type:()=>$e}),$e=`transfer`,et=Symbol.for(`osra.transfer`),tt=e=>typeof e==`object`&&!!e,nt=e=>tt(e)&&et in e&&e[et]===!0,rt=e=>tt(e)?ArrayBuffer.isView(e)?!0:L(e,[globalThis.ArrayBuffer,globalThis.MessagePort,globalThis.ReadableStream,globalThis.WritableStream,globalThis.TransformStream,globalThis.Request,globalThis.Response,globalThis.ImageBitmap,globalThis.OffscreenCanvas,globalThis.VideoFrame,globalThis.AudioData]):!1,it=e=>rt(e)?{[et]:!0,value:e}:e,at=0,ot=()=>at>0,st=e=>tt(e)&&!nt(e)?{[et]:!0,value:e}:e,ct=e=>{let t=at;at=0;try{return e()}finally{at=t}},lt=e=>nt(e),ut=(e,t)=>{at++;try{return{...V,type:$e,inner:oi(e.value,t),degraded:se(t.transport)}}finally{at--}},dt=(e,t)=>ci(e.inner,t),ft=e=>L(e,[globalThis.MessagePort,globalThis.ReadableStream,globalThis.WritableStream,globalThis.TransformStream,globalThis.OffscreenCanvas,globalThis.MediaSourceHandle,globalThis.MediaStreamTrack,globalThis.MIDIAccess,globalThis.RTCDataChannel,globalThis.WebTransportReceiveStream,globalThis.WebTransportSendStream]),pt=e=>ve(e)&&e.type===`transfer`,mt=e=>{let t=[],n=new WeakSet,r=(e,i)=>{if(e&&typeof e==`object`&&!n.has(e)&&(n.add(e),!R(e))){if(pt(e)){r(e.inner,i||!e.degraded);return}if(ft(e)){t.push(e);return}if(z(e)){i&&t.push(e);return}if(ArrayBuffer.isView(e)){i&&e instanceof DataView&&!R(e.buffer)&&!n.has(e.buffer)&&(n.add(e.buffer),t.push(e.buffer));return}if(Array.isArray(e)){for(let t of e)r(t,i);return}for(let t of Object.values(e))r(t,i)}};return r(e,!1),t},ht=class{_listeners=new Map;addEventListener(e,t,n){if(!t)return;let r=this._listeners.get(e);r||(r=new Map,this._listeners.set(e,r)),r.has(t)||r.set(t,typeof n==`object`&&!!n?.once)}removeEventListener(e,t,n){t&&this._listeners.get(e)?.delete(t)}_peer;_queue=[];_started=!1;_closed=!1;_onClose;_onmessage=null;get onmessage(){return this._onmessage}set onmessage(e){this._onmessage=e,e!==null&&this.start()}onmessageerror=null;dispatchEvent(e){e.type===`message`?this._onmessage?.call(this,e):e.type===`messageerror`&&this.onmessageerror?.call(this,e);let t=this._listeners.get(e.type);if(t)for(let[n,r]of[...t])r&&t.delete(n),typeof n==`function`?n.call(this,e):n.handleEvent(e);return!0}postMessage(e,t){let n=this._peer;n&&!n._closed&&queueMicrotask(()=>{if(n._closed)return;let t=new MessageEvent(`message`,{data:e});n._started?n.dispatchEvent(t):n._queue.push(t)})}start(){if(!this._started){this._started=!0;for(let e of this._queue.splice(0))this.dispatchEvent(e)}}close(){if(this._closed)return;this._closed=!0,this._queue.length=0,this._onClose?.();let e=this._peer;e&&!e._closed&&queueMicrotask(()=>{e._closed||e.dispatchEvent(new Event(`close`))})}},gt=class{port1;port2;constructor(){let e=new ht,t=new ht;e._peer=t,t._peer=e,this.port1=e,this.port2=t}},_t=new FinalizationRegistry(e=>{try{e()}catch{}}),vt=(e,t)=>{let n={};return _t.register(e,t,n),()=>_t.unregister(n)},yt=d({box:()=>Vt,createRevivableChannel:()=>Kt,init:()=>jt,isType:()=>Mt,markPortsShipped:()=>Wt,objectsOnly:()=>!0,postPreBoxed:()=>zt,revive:()=>Ht,type:()=>bt}),bt=`messagePort`,xt=2048,St=128,Ct=1024,wt=new WeakMap,Tt=e=>{let t=wt.get(e);if(!t)throw Error(`osra message-port: connection state missing; did init() run?`);return t},Et=(e,t)=>{let n=e.ports.get(t);return n||(n={nextSeq:0,buffer:new Map,outSeq:0},e.ports.set(t,n),e.pendingPorts++),n},Dt=(e,t)=>{let n=e.ports.get(t);if(n&&!n.handler&&e.pendingPorts--,e.ports.delete(t),e.tombstones.size>=St){let t=e.tombstones.values().next().value;t!==void 0&&e.tombstones.delete(t)}e.tombstones.add(t)},Ot=e=>{if(e.handler)for(let t=e.buffer.get(e.nextSeq);t!==void 0;t=e.buffer.get(e.nextSeq))e.buffer.delete(e.nextSeq),e.nextSeq++,e.handler(t)},kt=(e,t)=>Et(Tt(e),t).outSeq++,At=(e,t,n)=>{let r=Tt(e);if(r.tombstones.has(t)){setTimeout(()=>n({type:`message-port-close`,remoteUuid:e.remoteUuid,portId:t}));return}let i=Et(r,t);i.handler||r.pendingPorts--,i.handler=n,Ot(i)},jt=e=>{let t={ports:new Map,tombstones:new Set,pendingPorts:0};wt.set(e,t),e.eventTarget.addEventListener(`message`,({detail:n})=>{if(n.type!==`message`&&n.type!==`message-port-close`||t.tombstones.has(n.portId))return;let r=t.ports.get(n.portId);if(n.seq===void 0){r?.handler?.(n);return}if(!r){if(t.pendingPorts>=Ct)return;r=Et(t,n.portId)}if(!(n.seq<r.nextSeq)){if(r.buffer.size>=xt&&!(n.seq===r.nextSeq&&r.handler)){r.buffer.clear(),Dt(t,n.portId),r.handler?.({type:`message-port-close`,remoteUuid:e.remoteUuid,portId:n.portId});return}r.buffer.set(n.seq,n),Ot(r)}}),Ye(e,()=>{for(let[n,r]of[...t.ports])r.handler?.({type:`message-port-close`,remoteUuid:e.remoteUuid,portId:n});t.ports.clear(),t.tombstones.clear(),t.pendingPorts=0})},Mt=e=>e instanceof MessagePort||e instanceof ht,Nt=(e,t)=>{try{let n=Tt(e).ports.get(t);e.sendMessage({type:`message-port-close`,remoteUuid:e.remoteUuid,portId:t,seq:n?n.outSeq++:0})}catch{}},Pt=(e,t,n)=>{if(n){e.postMessage(t);return}let r=mt(t);e.postMessage(t,r),Wt(r)},Ft=(e,t,n,r)=>{let i;try{i=ci(e,t)}catch(e){r(),globalThis.reportError?.(e);return}n(i)},It=(e,t,n)=>()=>{let r=e.deref();r&&Nt(r,n);let i=t.deref();i&&Dt(i,n)},Lt=new WeakSet,Rt=e=>e!==null&&(typeof e==`object`||typeof e==`function`),zt=(e,t,n)=>{Rt(t)&&Lt.add(t),e.postMessage(t,n??[])},Bt=(e,t)=>Rt(e)&&Lt.delete(e)?e:ct(()=>oi(e,t)),Vt=(e,t,n)=>{let r=e instanceof ht;if(!r&&!se(t.transport))return{...V,type:bt,port:e,...n?.autoBox?{autoBox:!0}:{}};let i=Tt(t),a=e,o=globalThis.crypto.randomUUID(),s=new WeakRef(a),c=new WeakRef(t),l=new WeakRef(i),u=!1,d=()=>{if(u)return;u=!0;let e=l.deref();e&&Dt(e,o),m?.();let t=s.deref();t?.removeEventListener(`message`,p),t instanceof ht&&(t._onClose=void 0)},f=e=>{if(e.type===`message-port-close`){d(),a.dispatchEvent(new Event(`close`)),a.close();return}Ft(e.data,t,e=>Pt(a,e,!1),()=>{})};function p({data:e}){t.sendMessage({type:`message`,remoteUuid:t.remoteUuid,data:Bt(e,t),portId:o,seq:kt(t,o)})}let m=vt(a,It(c,l,o));return a.addEventListener(`message`,p),a.start(),a instanceof ht&&(a._onClose=()=>{u||(Nt(t,o),d())}),At(t,o,f),{...V,type:bt,portId:o,synthetic:r}},Ht=(e,t)=>`port`in e?(Wt([e.port]),e.autoBox?Gt(e.port,t):e.port):qt(e.portId,t,e.synthetic),Ut=new WeakMap,Wt=e=>{for(let t of e){let e=Ut.get(t);if(e){Ut.delete(t),e.shipped=!0;for(let t of e.pending.splice(0))t()}}},Gt=(e,t,n)=>{let r=new EventTarget,i=({data:e})=>{Ft(e,t,e=>r.dispatchEvent(new MessageEvent(`message`,{data:e})),()=>r.dispatchEvent(new Event(`messageerror`)))},a=()=>{r.dispatchEvent(new Event(`messageerror`))},o=()=>{r.dispatchEvent(new Event(`close`))};e.addEventListener(`message`,i),e.addEventListener(`messageerror`,a),e.addEventListener(`close`,o),r.postMessage=(r,i)=>{let a=ct(()=>oi(r,t)),o=mt(a),s=Array.isArray(i)?i:[],c=s.length?[...o,...s]:o,l=()=>{e.postMessage(a,c),Wt(c)};if(n&&!n.shipped){n.pending.push(l);return}l()},r.start=()=>e.start();let s=()=>{e.removeEventListener(`message`,i),e.removeEventListener(`messageerror`,a),e.removeEventListener(`close`,o),e.close()};return r.close=()=>{if(n&&!n.shipped){n.pending.push(s);return}s()},r},Kt=e=>{if(se(e.transport)){let{port1:t,port2:n}=new gt;return{localPort:t,boxedRemote:Vt(n,e)}}let{port1:t,port2:n}=new MessageChannel,r={shipped:!1,pending:[]};return Ut.set(n,r),{localPort:Gt(t,e,r),boxedRemote:Vt(n,e,{autoBox:!0})}},qt=(e,t,n)=>{let r=Tt(t),{port1:i,port2:a}=n?new gt:new MessageChannel,o=new WeakRef(i),s=new WeakRef(a),c=!1,l=!1;i instanceof ht||i.addEventListener(`close`,e=>{l&&e.stopImmediatePropagation()});let u=()=>{if(c)return;c=!0,Dt(r,e);let t=s.deref();t?.removeEventListener(`message`,f),t?.close(),p?.()},d=e=>{if(e.type===`message-port-close`){u();let e=o.deref();e?.dispatchEvent(new Event(`close`)),l=!0,e?.close();return}if(!o.deref()){u();return}let r=s.deref();r&&Ft(e.data,t,e=>Pt(r,e,n),()=>o.deref()?.dispatchEvent(new Event(`messageerror`)))},f=({data:n})=>{t.sendMessage({type:`message`,remoteUuid:t.remoteUuid,data:Bt(n,t),portId:e,seq:kt(t,e)})},p=vt(i,()=>{Nt(t,e),u()});return i instanceof ht&&(i._onClose=()=>{c||(Nt(t,e),u())}),a.addEventListener(`message`,f),a.start(),At(t,e,d),i},Jt=d({box:()=>$t,isType:()=>Qt,objectsOnly:()=>!0,revive:()=>en,type:()=>Yt}),Yt=`promise`,Xt=e=>e instanceof Promise,Zt=new Set,Qt=e=>e instanceof Promise,$t=(e,t)=>{if(!Xt(e))throw TypeError(`Expected Promise`);let{localPort:n,boxedRemote:r}=Kt(t),i=e=>{n.postMessage(e),n.close()};return e.then(e=>i({type:`resolve`,data:e})).catch(e=>i({type:`reject`,error:e})),{...V,type:Yt,port:r}},en=(e,t)=>{let n=Ht(e.port,t);Zt.add(n);let r=`portId`in e.port;return new Promise((e,i)=>{let a,o=()=>{n.close(),Zt.delete(n),a?.()};if(r&&Xe(t)){i(Error(`osra: connection closed`)),o();return}a=r?Ye(t,()=>{i(Error(`osra: connection closed`)),o()}):void 0,n.addEventListener(`message`,({data:t})=>{t.type===`resolve`?e(t.data):i(t.error),o()},{once:!0}),n.start()})},tn=d({box:()=>sn,isType:()=>on,objectsOnly:()=>!0,revive:()=>cn,type:()=>nn}),nn=`function`,rn=new Set,an=e=>{e instanceof ReadableStream?e.locked||e.cancel(Error(`osra: connection closed`)).catch(()=>{}):typeof WritableStream<`u`&&e instanceof WritableStream&&(e.locked||e.abort(Error(`osra: connection closed`)).catch(()=>{}))},on=e=>typeof e==`function`,sn=(e,t)=>{let{port1:n,port2:r}=new gt;return n.addEventListener(`message`,({data:n})=>{let[r,i]=n;(async()=>{let n;try{n={type:`return`,value:await e(...i)}}catch(e){n={type:`throw`,error:e}}if(Xe(t)){n.type===`return`&&an(n.value);try{r.close()}catch{}return}let a=(()=>{try{return oi(n,t)}catch(e){return oi({type:`throw`,error:e},t)}})();zt(r,a),queueMicrotask(()=>{try{r.close()}catch{}})})()}),n.start(),{...V,type:nn,port:Vt(r,t)}},cn=(e,t)=>{let n=Ht(e.port,t);return((...e)=>new Promise((r,i)=>{if(Xe(t)){i(Error(`osra: connection closed`));return}let{port1:a,port2:o}=new gt;rn.add(a);let s,c=()=>{a.close(),rn.delete(a),s?.()};s=Ye(t,()=>{i(Error(`osra: connection closed`)),c()}),a.addEventListener(`message`,({data:e})=>{let t=e;t.type===`return`?r(t.value):i(t.error),c()},{once:!0}),a.start();let l=ct(()=>oi([o,e],t));zt(n,l)}))},ln=d({MAX_CREDIT_WINDOW:()=>64,box:()=>hn,isType:()=>dn,objectsOnly:()=>!0,revive:()=>yn,type:()=>un}),un=`readableStream`,dn=e=>e instanceof ReadableStream,fn=2,pn=8,mn=4194304,hn=(e,t)=>{let{localPort:n,boxedRemote:r}=Kt(t),i=e.getReader(),a=ot(),o=0,s=!1,c=!1,l=e=>{c=!0;try{n.postMessage(e)}catch{}n.close()},u=async()=>{if(!(s||c)){for(s=!0;o>0;){let e;try{e=await i.read()}catch(e){c||l({type:`error`,error:e});return}if(c)return;if(e.done){l({type:`end`});return}o--;let t=a?st(e.value):e.value;try{n.postMessage({type:`chunk`,value:t})}catch(e){l({type:`error`,error:e}),i.cancel(e).catch(()=>{});return}}s=!1}};return n.addEventListener(`message`,({data:e})=>{e instanceof Promise||!(`type`in e)||(e.type===`pull`?n.postMessage(i.read()):e.type===`credit`?(o+=e.n,u()):e.type===`cancel`&&(c=!0,i.cancel(e.reason).catch(()=>{}),n.close()))}),n.addEventListener(`close`,()=>{c||(c=!0,i.cancel(Error(`osra: connection closed`)).catch(()=>{}))},{once:!0}),n.start(),{...V,type:un,credit:!0,port:r}},gn=e=>ArrayBuffer.isView(e)||e instanceof ArrayBuffer?e.byteLength:typeof e==`string`?e.length*2:typeof Blob<`u`&&e instanceof Blob?e.size:void 0,_n=e=>{let t=!1,n=0,r,i=[],a=!1,o=!1,s,c,l=()=>r===void 0?pn:Math.max(fn,Math.min(64,Math.floor(mn/r))),u=()=>{let t=l(),r=n+i.length;if(r>t/2)return;let a=t-r;n+=a,e.postMessage({type:`credit`,n:a})},d=()=>{t=!0,queueMicrotask(()=>e.close())},f=e=>{if(o=!0,s=e,!c||i.length)return;let t=c;c=void 0,d(),t.reject(e)};return new ReadableStream({start:()=>{e.addEventListener(`message`,({data:o})=>{if(!(o instanceof Promise||!(`type`in o))){if(o.type===`chunk`){if(t)return;if(n<=0){i.length=0,f(Error(`osra: stream exceeded its credit window`)),queueMicrotask(()=>e.close());return}n--;let a=gn(o.value);if(a!==void 0&&(r=r===void 0?a:r*.875+a*.125),c){let e=c;c=void 0,e.controller.enqueue(o.value),e.resolve()}else i.push(o.value)}else if(o.type===`end`){if(t||(a=!0,!c||i.length))return;let e=c;c=void 0,d(),e.controller.close(),e.resolve()}else if(o.type===`error`){if(t)return;f(o.error)}}}),e.addEventListener(`messageerror`,()=>{t||f(Error(`osra: a chunk failed to deserialize on this platform`))}),e.addEventListener(`close`,()=>{t||a||o||f(Error(`osra: connection closed`))},{once:!0})},pull:e=>{if(!t){if(i.length){e.enqueue(i.shift()),!a&&!o&&u();return}if(o)return d(),Promise.reject(s);if(a){d(),e.close();return}return u(),new Promise((t,n)=>{c={controller:e,resolve:t,reject:n}})}},cancel:n=>{t=!0,i.length=0;let r=c;c=void 0,r?.resolve(),e.postMessage({type:`cancel`,reason:n}),queueMicrotask(()=>e.close())}})},vn=e=>{let t=!1;return new ReadableStream({start:n=>{e.addEventListener(`messageerror`,()=>{if(!t){t=!0;try{n.error(Error(`osra: a chunk failed to deserialize on this platform`))}catch{}queueMicrotask(()=>e.close())}}),e.addEventListener(`close`,()=>{if(!t){t=!0;try{n.error(Error(`osra: connection closed`))}catch{}}},{once:!0})},pull:n=>new Promise((r,i)=>{e.addEventListener(`message`,({data:a})=>{a instanceof Promise&&a.then(i=>{i.done?(t=!0,n.close(),e.postMessage({type:`cancel`}),queueMicrotask(()=>e.close())):n.enqueue(i.value),r()}).catch(e=>{t=!0,i(e)})},{once:!0}),e.postMessage({type:`pull`})}),cancel:n=>{t=!0,e.postMessage({type:`cancel`,reason:n}),queueMicrotask(()=>e.close())}})},yn=(e,t)=>{let n=Ht(e.port,t);return n.start(),e.credit?_n(n):vn(n)},bn=d({box:()=>Cn,isType:()=>Sn,objectsOnly:()=>!0,revive:()=>wn,type:()=>xn}),xn=`writableStream`,Sn=e=>e instanceof WritableStream,Cn=(e,t)=>{let{localPort:n,boxedRemote:r}=Kt(t),i=e.getWriter(),a=!1,o=(e,t)=>e.then(()=>n.postMessage({type:`ack`})).catch(e=>n.postMessage({type:`err`,error:e?.message??String(e)})).then(()=>{t&&(a=!0,queueMicrotask(()=>n.close()))});return n.addEventListener(`message`,({data:e})=>{e&&typeof e==`object`&&`type`in e&&(e.type===`write`?o(i.write(e.chunk),!1):e.type===`close`?o(i.close(),!0):e.type===`abort`&&o(i.abort(e.reason),!0))}),n.addEventListener(`messageerror`,()=>{n.postMessage({type:`err`,error:`osra: a chunk failed to deserialize on this platform`})}),n.addEventListener(`close`,()=>{a||(a=!0,i.abort(Error(`osra: connection closed`)).catch(()=>{}))},{once:!0}),n.start(),{...V,type:xn,port:r,...ot()?{transferChunks:!0}:{}}},wn=(e,t)=>{let n=Ht(e.port,t);n.start();let r=new Set,i=!1;n.addEventListener(`close`,()=>{i=!0;let e=Error(`osra: connection closed`);for(let t of[...r])t(e);r.clear()},{once:!0});let a=Promise.resolve(),o=e=>{let t=a.then(()=>new Promise((t,a)=>{if(i){a(Error(`osra: connection closed`));return}let o=e=>{r.delete(a),e()};r.add(a),n.addEventListener(`message`,({data:e})=>{e&&typeof e==`object`&&`type`in e&&(e.type===`ack`?o(t):e.type===`err`&&o(()=>a(Error(e.error))))},{once:!0}),n.postMessage(e)}));return a=t.catch(()=>{}),t},s=e.transferChunks===!0;return new WritableStream({write:e=>o({type:`write`,chunk:s?st(e):e}),close:()=>o({type:`close`}),abort:e=>o({type:`abort`,reason:e})})},Tn=d({box:()=>kn,isType:()=>Dn,objectsOnly:()=>!0,revive:()=>An,type:()=>En}),En=`abortSignal`,Dn=e=>e instanceof AbortSignal,On=new WeakMap,kn=(e,t)=>{if(e.aborted)return{...V,type:En,aborted:!0,reason:oi(e.reason,t)};let{localPort:n,boxedRemote:r}=Kt(t),i=()=>{n.postMessage({type:`abort`,reason:e.reason}),n.close(),a()},a=Ye(t,()=>{e.removeEventListener(`abort`,i),n.close()});return e.addEventListener(`abort`,i,{once:!0}),{...V,type:En,aborted:!1,reason:void 0,port:r}},An=(e,t)=>{let n=new AbortController;if(e.aborted||e.port===void 0)return n.abort(ci(e.reason,t)),n.signal;let r=Ht(e.port,t);return On.set(n.signal,r),r.start(),r.addEventListener(`message`,({data:e})=>{e.type===`abort`&&(n.abort(ci(e.reason,t)),On.delete(n.signal),r.close())}),n.signal},jn=d({box:()=>Pn,isType:()=>Nn,objectsOnly:()=>!0,revive:()=>Fn,type:()=>Mn}),Mn=`response`,Nn=e=>e instanceof Response,Pn=(e,t)=>({...V,type:Mn,status:e.status,statusText:e.statusText,headers:Pe(e.headers,t),body:e.body?hn(e.body,t):null,url:e.url,redirected:e.redirected}),Fn=(e,t)=>{if(e.status===0)return Response.error();let n=Fe(e.headers,t),r=e.body?yn(e.body,t):null,i=e.status===101||e.status===204||e.status===205||e.status===304;r&&i&&r.cancel().catch(()=>{});let a=new Response(i?null:r,{status:e.status,statusText:e.statusText,headers:n});return e.url&&Object.defineProperty(a,"url",{value:e.url,configurable:!0}),e.redirected&&Object.defineProperty(a,"redirected",{value:!0,configurable:!0}),a},In=d({box:()=>zn,isType:()=>Rn,objectsOnly:()=>!0,revive:()=>Bn,type:()=>Ln}),Ln=`request`,Rn=e=>e instanceof Request,zn=(e,t)=>({...V,type:Ln,method:e.method,url:e.url,headers:Pe(e.headers,t),body:e.body?hn(e.body,t):null,credentials:e.credentials,cache:e.cache,mode:e.mode,redirect:e.redirect,referrer:e.referrer,referrerPolicy:e.referrerPolicy,integrity:e.integrity,keepalive:e.keepalive,signal:kn(e.signal,t)}),Bn=(e,t)=>{let n=Fe(e.headers,t),r={method:e.method,headers:n,credentials:e.credentials,cache:e.cache,redirect:e.redirect,referrer:e.referrer,referrerPolicy:e.referrerPolicy,integrity:e.integrity,keepalive:e.keepalive,signal:An(e.signal,t)};return e.mode!==`navigate`&&(r.mode=e.mode),e.body&&(r.body=yn(e.body,t),r.duplex=`half`),new Request(e.url,r)},Vn=d({box:()=>$n,boxByReference:()=>er,identity:()=>qn,isType:()=>Xn,objectsOnly:()=>!0,revive:()=>tr,type:()=>Hn}),Hn=`identity`,Un=e=>e!==null&&(typeof e==`object`||typeof e==`function`),Wn=e=>{if(e===null)return!1;let t=typeof e;return t===`object`||t===`function`||t===`symbol`&&Symbol.keyFor(e)===void 0},Gn=new WeakMap,Kn=e=>{let t=Gn.get(e);if(t!==void 0)return t;let n=globalThis.crypto.randomUUID();return Gn.set(e,n),n},qn=e=>(Un(e)&&Kn(e),e),Jn=new WeakMap,Yn=e=>{let t=Jn.get(e);if(t)return t;let n=new Map,r={idToLocal:n,pins:new Map,aliasIds:new WeakMap,disposeRegistry:new FinalizationRegistry(t=>{if(n.delete(t),!Xe(e))try{e.sendMessage({type:`identity-dispose`,remoteUuid:e.remoteUuid,id:t})}catch{}})};return Jn.set(e,r),e.eventTarget.addEventListener(`message`,({detail:e})=>{e?.type===`identity-dispose`&&(r.pins.delete(e.id),r.idToLocal.delete(e.id))}),Ye(e,()=>{r.pins.clear(),r.idToLocal.clear()}),r},Xn=e=>Un(e)&&Gn.has(e),Zn=(e,t)=>{let n=t.aliasIds.get(e);if(n!==void 0)return n;let r=Kn(e),i=t.idToLocal.get(r);if(i===void 0||i.deref()===e)return r;let a=globalThis.crypto.randomUUID();return t.aliasIds.set(e,a),a},Qn=(e,t,n)=>{let r=Zn(e,n);if(n.idToLocal.has(r))return{...V,type:Hn,id:r};let i=t();return n.idToLocal.set(r,new WeakRef(e)),n.disposeRegistry.register(e,r,e),ei(()=>{},()=>{n.idToLocal.delete(r),n.disposeRegistry.unregister(e)}),{...V,type:Hn,id:r,inner:i}},$n=(e,t)=>{let n=Yn(t),r=()=>si(e,t,Hn);return Wn(e)?Qn(e,r,n):{...V,type:Hn,id:globalThis.crypto.randomUUID(),inner:r()}},er=(e,t,n)=>Qn(e,()=>t,Yn(n)),tr=(e,t)=>{let n=Yn(t);if(n.pins.has(e.id))return n.pins.get(e.id);let r=n.idToLocal.get(e.id)?.deref();if(r!==void 0)return r;if(!(`inner`in e)||e.inner===void 0){try{t.sendMessage({type:`identity-dispose`,remoteUuid:t.remoteUuid,id:e.id})}catch{}throw Error(`osra identity: received id=${e.id} with no inner payload and nothing local to resolve it to`)}let i=ci(e.inner,t);return n.pins.set(e.id,i),Wn(i)&&(Gn.has(i)||Gn.set(i,e.id),n.idToLocal.set(e.id,new WeakRef(i))),i},nr=d({box:()=>ir,isType:()=>rr,objectsOnly:()=>!0,revive:()=>ar,type:()=>`map`}),rr=e=>e instanceof Map,ir=(e,t)=>({...V,type:`map`,entries:Array.from(e,([e,n])=>[oi(e,t),oi(n,t)])}),ar=(e,t)=>new Map(e.entries.map(([e,n])=>[ci(e,t),ci(n,t)])),or=d({box:()=>cr,isType:()=>sr,objectsOnly:()=>!0,revive:()=>lr,type:()=>`set`}),sr=e=>e instanceof Set,cr=(e,t)=>({...V,type:`set`,values:Array.from(e,e=>oi(e,t))}),lr=(e,t)=>new Set(e.values.map(e=>ci(e,t))),ur=d({box:()=>pr,isType:()=>fr,revive:()=>mr,type:()=>dr}),dr=`bigint`,fr=e=>typeof e==`bigint`,pr=(e,t)=>({...V,type:dr,value:e.toString()}),mr=(e,t)=>BigInt(e.value),hr=d({box:()=>vr,isType:()=>_r,objectsOnly:()=>!0,revive:()=>yr,type:()=>gr}),gr=`event`,_r=e=>e instanceof Event,vr=(e,t)=>({...V,type:gr,eventType:e.type,bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed,...e instanceof CustomEvent?{detail:oi(e.detail,t)}:{}}),yr=(e,t)=>{let n={bubbles:e.bubbles,cancelable:e.cancelable,composed:e.composed};return`detail`in e?new CustomEvent(e.eventType,{...n,detail:ci(e.detail,t)}):new Event(e.eventType,n)},br=d({box:()=>Cr,isType:()=>Sr,objectsOnly:()=>!0,revive:()=>Dr,type:()=>xr}),xr=`eventTarget`,Sr=e=>e instanceof EventTarget,Cr=(e,t)=>{let n=[],r=e=>typeof e==`boolean`?e:!!e?.capture;return{...V,type:xr,addListener:sn((t,i,a)=>{n.push({eventType:t,listener:i,capture:r(a)}),e.addEventListener(t,i,a)},t),removeListener:sn((t,i,a)=>{let o=r(a),s=n.findIndex(e=>e.eventType===t&&e.listener===i&&e.capture===o);s!==-1&&n.splice(s,1),e.removeEventListener(t,i,a)},t),removeAllListeners:sn(()=>{for(let{eventType:t,listener:r,capture:i}of n.splice(0))e.removeEventListener(t,r,{capture:i})},t)}},wr=new WeakMap,Tr=e=>{if(typeof e==`function`)return e;let t=wr.get(e);return t||wr.set(e,t=t=>e.handleEvent(t)),t},Er=(e,t,n,r)=>e.find(e=>e.eventType===t&&e.listener===n&&e.capture===r),Dr=(e,t)=>{let n=cn(e.addListener,t),r=cn(e.removeListener,t),i=cn(e.removeAllListeners,t),a=new EventTarget,o=[],s=e=>{let t=o.indexOf(e);t!==-1&&o.splice(t,1)};return Object.defineProperty(a,"addEventListener",{value:(e,t,r)=>{if(t===null)return;let i=Tr(t),a=typeof r==`boolean`?r:!!r?.capture;if(Er(o,e,i,a))return;let c=typeof r==`object`&&r?.once?e=>(s(l),i(e)):i,l={eventType:e,listener:i,capture:a,wire:c};o.push(l),(typeof r==`object`?r?.signal:void 0)?.addEventListener(`abort`,()=>s(l),{once:!0}),n(e,qn(c),r).catch(()=>{})}}),Object.defineProperty(a,"removeEventListener",{value:(e,t,n)=>{if(t===null)return;let i=Tr(t),a=typeof n==`boolean`?n:!!n?.capture,c=Er(o,e,i,a);c&&(s(c),r(e,qn(c.wire),{capture:a}).catch(()=>{}))}}),vt(a,()=>{i().catch(()=>{})}),a},Or=d({box:()=>jr,isType:()=>Ar,revive:()=>Mr,type:()=>kr}),kr=`symbol`,Ar=e=>typeof e==`symbol`,jr=(e,t)=>{let n=Symbol.keyFor(e);return n===void 0?er(e,{...V,type:kr,description:e.description},t):{...V,type:kr,registryKey:n}},Mr=(e,t)=>`registryKey`in e?Symbol.for(e.registryKey):Symbol(e.description),Nr=d({box:()=>Ir,isType:()=>Fr,objectsOnly:()=>!0,revive:()=>Lr,type:()=>Pr}),Pr=`asyncIterator`,Fr=e=>!e||typeof e!=`object`||typeof ReadableStream<`u`&&e instanceof ReadableStream?!1:typeof e[Symbol.asyncIterator]==`function`,Ir=(e,t)=>{let n=e[Symbol.asyncIterator]();return{...V,type:Pr,next:sn((e=>n.next(e)),t),return:sn((e=>n.return?.(e)??Promise.resolve({done:!0,value:e})),t),throw:sn((e=>n.throw?.(e)??Promise.reject(e)),t)}},Lr=(e,t)=>{let n=cn(e.next,t),r=cn(e.return,t),i=cn(e.throw,t),a={next:(...e)=>n(...e),return:e=>r(e),throw:e=>i(e),[Symbol.asyncIterator]:()=>a};return a},Rr=[globalThis.File,globalThis.FileList,globalThis.RegExp,globalThis.DataView,globalThis.ImageData,globalThis.FormData,globalThis.DOMException,globalThis.DOMMatrix,globalThis.DOMMatrixReadOnly,globalThis.DOMPoint,globalThis.DOMPointReadOnly,globalThis.DOMQuad,globalThis.DOMRect,globalThis.DOMRectReadOnly,globalThis.CryptoKey,globalThis.FileSystemHandle,globalThis.FileSystemFileHandle,globalThis.FileSystemDirectoryHandle,globalThis.RTCCertificate],zr=[globalThis.CropTarget,globalThis.EncodedAudioChunk,globalThis.EncodedVideoChunk,globalThis.FencedFrameConfig,globalThis.GPUCompilationInfo,globalThis.GPUCompilationMessage,globalThis.GPUPipelineError,globalThis.RTCEncodedAudioFrame,globalThis.RTCEncodedVideoFrame,globalThis.WebTransportError],Br={type:`clonable`,capableOnly:!0,objectsOnly:!0,isType:e=>L(e,Rr)||L(e,zr),box:(e,t)=>e,revive:(e,t)=>e},Vr=[globalThis.ImageBitmap,globalThis.OffscreenCanvas,globalThis.WritableStream,globalThis.TransformStream,globalThis.MediaStreamTrack,globalThis.RTCDataChannel],Hr=[globalThis.AudioData,globalThis.VideoFrame,globalThis.MediaSourceHandle,globalThis.MIDIAccess,globalThis.WebTransportReceiveStream,globalThis.WebTransportSendStream],Ur={type:`transferable`,capableOnly:!0,objectsOnly:!0,isType:e=>L(e,Vr)||L(e,Hr),box:(e,t)=>e,revive:(e,t)=>e},Wr={type:`blob`,capableOnly:!0,objectsOnly:!0,isType:e=>typeof Blob<`u`&&e instanceof Blob,box:(e,t)=>{if(se(t.transport))throw TypeError(`osra: Blob is only supported on structured-clone transports, send an ArrayBuffer or Uint8Array instead`);return e},revive:(e,t)=>e},Gr=e=>{if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t===Object.prototype||t===null},Kr=[Qe,Vn,xe,Ee,je,Ie,He,Jt,tn,yt,ln,bn,Tn,jn,In,nr,or,ur,Or,hr,Nr,{type:`nonFiniteNumber`,isType:e=>typeof e==`number`&&!Number.isFinite(e),box:(e,t)=>se(t.transport)?{...V,type:`nonFiniteNumber`,value:String(e)}:e,revive:(e,t)=>Number(e.value)},{type:`undefined`,isType:e=>e===void 0,box:(e,t)=>se(t.transport)?{...V,type:`undefined`}:e,revive:(e,t)=>void 0},Br,Ur,Wr,br,{type:`unclonable`,objectsOnly:!0,isType:e=>{if(typeof e!=`object`||!e||Array.isArray(e)||Gr(e))return!1;try{return structuredClone(e),!1}catch{return!0}},box:(e,t)=>({...V,type:`unclonable`}),revive:(e,t)=>({})}],qr=(e,t)=>t.find(t=>t.type===e.type),Jr=e=>!!e&&typeof e==`object`&&Object.getPrototypeOf(e)===Object.prototype,Yr=(e,t)=>Array.isArray(e)?e.map(e=>t(e)):Jr(e)?Object.fromEntries(Object.entries(e).map(([e,n])=>[e,t(n)])):e,Xr=new WeakSet,Zr=new WeakSet,Qr=0,$r=[],ei=(e,t)=>{if(Qr===0){e();return}$r.push({commit:e,rollback:t})},ti=e=>{let t=$r;$r=[];for(let n of t)try{e?n.rollback():n.commit()}catch{}},ni=e=>e!==null&&(typeof e==`object`||typeof e==`function`),ri=new WeakMap,ii=e=>{let t=ri.get(e);if(t)return t;let n=e.filter(e=>!e.objectsOnly);return ri.set(e,n),n},ai=(e,t,n)=>{let r=(e===null||typeof e!=`object`&&typeof e!=`function`?ii(t.revivableModules):t.revivableModules).find(t=>t.type!==n&&t.isType(e));return r?r.box(e,t):Yr(e,e=>oi(e,t))},oi=(e,t)=>{if(ve(e))return e;let n=ni(e);if(n){if(Xr.has(e))throw TypeError(`osra: cannot serialize a circular structure - break the cycle or send the container by reference`);Xr.add(e)}Qr++;let r=!0;try{let n=ai(e,t);return r=!1,n}finally{n&&Xr.delete(e),Qr--,Qr===0&&ti(r)}},si=(e,t,n)=>ai(e,t,n),ci=(e,t)=>{let n=ni(e);if(n){if(Zr.has(e))throw TypeError(`osra: cannot revive a circular structure`);Zr.add(e)}try{if(ve(e)){let n=qr(e,t.revivableModules);if(n)return n.revive(e,t)}return Yr(e,e=>ci(e,t))}finally{n&&Zr.delete(e)}},li=d({init:()=>fi,startBidirectionalConnection:()=>di,type:()=>ui}),ui=`bidirectional`,di=({transport:e,value:t,remoteUuid:n,eventTarget:r,send:i,revivableModules:a})=>{let o={transport:e,remoteUuid:n,sendMessage:i,eventTarget:r,revivableModules:a};for(let e of a)e.init?.(o);let{promise:s,resolve:c}=Promise.withResolvers();return r.addEventListener(`message`,function e({detail:t}){t.type===`init`&&(c(t.data),r.removeEventListener(`message`,e))}),i({type:`init`,remoteUuid:n,data:oi(t,o)}),{revivableContext:o,remoteValue:s.then(e=>ci(e,o))}},fi=e=>{if(!(ce(e.transport)&&le(e.transport)))return;if(e.protocolEventTarget.addEventListener(`message`,({detail:{message:t,peer:n}})=>{if(t.type===`announce`){if(!t.remoteUuid){e.sendMessage({type:`announce`,remoteUuid:t.uuid});return}if(t.remoteUuid!==e.getUuid()||e.connectionContexts.has(t.uuid))return;e.sendMessage({type:`announce`,remoteUuid:t.uuid});let r=e.createConnectionEventTarget(),i={...n(),abort:()=>e.abortConnection(t.uuid)},a;try{let n=e.valueFor(i);if(e.claimPendingAbort(t.uuid)){e.sendMessage({type:`close`,remoteUuid:t.uuid});return}a=di({transport:e.transport,value:n,remoteUuid:t.uuid,eventTarget:r,send:t=>e.sendMessage(t),revivableModules:e.revivableModules})}catch(n){e.sendMessage({type:`close`,remoteUuid:t.uuid}),e.rejectRemoteValue(n);return}let o={type:`bidirectional`,eventTarget:r,connection:a};e.connectionContexts.set(t.uuid,o),o.connection.remoteValue.then(t=>e.addConnection(i,t),t=>e.rejectRemoteValue(t));return}if(t.type===`close`){if(t.remoteUuid!==e.getUuid())return;let n=e.connectionContexts.get(t.uuid);if(!n)return;e.connectionContexts.delete(t.uuid),Ze(n.connection.revivableContext),e.rejectRemoteValue(Error(`osra: peer closed the connection`));return}if(t.remoteUuid!==e.getUuid())return;let r=e.connectionContexts.get(t.uuid);r&&r.eventTarget.dispatchEvent(new CustomEvent(`message`,{detail:t}))}),e.presetRemoteUuid!==void 0){let t=e.presetRemoteUuid,n=e.createConnectionEventTarget(),r,i;try{i={abort:()=>e.abortConnection(t)};let a=e.valueFor(i);if(e.claimPendingAbort(t)){e.sendMessage({type:`close`,remoteUuid:t});return}r=di({transport:e.transport,value:a,remoteUuid:e.presetRemoteUuid,eventTarget:n,send:t=>e.sendMessage(t),revivableModules:e.revivableModules})}catch(n){e.sendMessage({type:`close`,remoteUuid:t}),e.rejectRemoteValue(n);return}let a={type:`bidirectional`,eventTarget:n,connection:r};e.connectionContexts.set(e.presetRemoteUuid,a),a.connection.remoteValue.then(t=>e.addConnection(i,t),t=>e.rejectRemoteValue(t));return}let t=50,n,r=()=>{if(!(e.unregisterSignal?.aborted||e.connectionContexts.size>0)){try{e.sendMessage({type:`announce`},`*`)}catch{}n=setTimeout(r,t),t=Math.min(t*2,1e3)}};e.unregisterSignal?.addEventListener(`abort`,()=>clearTimeout(n),{once:!0}),r()},pi=()=>new EventTarget,mi=e=>{let t=pe(e),n=t?e.emit:e,r=t?e.receive:e;return{isJson:t&&`isJson`in e&&e.isJson!==void 0?e.isJson:n!==void 0&&se(n)||r!==void 0&&se(r),...n===void 0?{}:{emit:n},...r===void 0?{}:{receive:r}}},hi=e=>e?e(Kr):Kr,gi=32,_i=()=>{let e=[],t=new Set,n=!1,r=()=>({value:void 0,done:!0});return{push:r=>{if(!n){if(t.size===0){e.push(r),e.length>gi&&e.shift();return}for(let e of t){let t=e.wake;if(t){e.wake=void 0,t({value:r,done:!1});continue}e.buffered.push(r)}}},close:()=>{n=!0;for(let e of t){let t=e.wake;e.wake=void 0,t?.(r())}},iterate:()=>{let i={buffered:[...e]};t.add(i);let a=!1;return{[Symbol.asyncIterator](){return this},next:()=>{if(a)return Promise.resolve(r());let e=i.buffered.shift();return e?Promise.resolve({value:e,done:!1}):n?Promise.resolve(r()):new Promise(e=>{i.wake=e})},return:()=>{a=!0,t.delete(i);let e=i.wake;return i.wake=void 0,e?.(r()),Promise.resolve(r())}}}}},vi=(e,t,n)=>{let r=e.then(n);r.catch(()=>{});let i=()=>{let e=t.iterate();return{[Symbol.asyncIterator](){return this},next:()=>e.next().then(e=>e.done?{value:void 0,done:!0}:{value:n(e.value),done:!1}),return:()=>e.return?.()??Promise.resolve({value:void 0,done:!0})}};return Object.assign(r,{[Symbol.asyncIterator]:i})},yi=Symbol.for(`osra.context`),bi=e=>typeof e==`object`&&!!e&&yi in e,xi=[li],Si=(e,{transport:t,name:n,remoteName:r,key:i=p,origin:a=`*`,unregisterSignal:o,revivableModules:s,uuid:c,remoteUuid:l,connection:u=({value:e})=>e})=>{let d=u,m=mi(t);if(!(ce(m)&&le(m))){let e=_i();e.close();let t=Promise.reject(Error(`osra: transport must be able to both emit and receive to establish a connection; pass a bidirectional platform transport or a custom { emit, receive } pair`));return t.catch(()=>{}),vi(t,e,d)}let h=hi(s),g=new Map,_=new Set,v=_i(),{promise:b,resolve:x,reject:C}=Promise.withResolvers();b.catch(()=>{});let w=c??globalThis.crypto.randomUUID(),T=(e,t=a)=>{let r={[f]:i,name:n,uuid:w,...e},o=mt(r);S(m,r,t,o),Wt(o)},E=(e,t)=>{o?.aborted||T(e,t)},D=pi(),O={transport:m,valueFor:t=>bi(e)?e[yi](t):e,revivableModules:h,connectionContexts:g,getUuid:()=>w,presetRemoteUuid:l,sendMessage:E,protocolEventTarget:D,rejectRemoteValue:C,abortConnection:e=>{let t=g.get(e);if(!t){_.add(e);return}g.delete(e),T({type:`close`,remoteUuid:e}),Ze(t.connection.revivableContext),C(Error(`osra: connection aborted`))},claimPendingAbort:e=>_.delete(e),addConnection:(e,t)=>{let n={value:t,context:e};x(n),v.push(n)},createConnectionEventTarget:pi,unregisterSignal:o};if(y({listener:(e,t)=>{e.uuid!==w&&D.dispatchEvent(new CustomEvent(`message`,{detail:{message:e,peer:()=>({...t.origin?{origin:t.origin}:{},...t.source?{source:t.source}:{},...t.port?{port:t.port}:{},...t.sender?{sender:t.sender}:{}})}}))},transport:m,remoteName:r,key:i,origin:a,unregisterSignal:o}),o?.aborted)return C(o.reason),v.close(),vi(b,v,d);o?.addEventListener(`abort`,()=>{for(let[e,t]of g)T({type:`close`,remoteUuid:e}),Ze(t.connection.revivableContext);g.clear(),v.close(),C(o.reason)},{once:!0});for(let e of xi)e.init(O);return vi(b,v,d)},Ci=(e,t)=>Si(e,t),wi=1e4,Ti=16,Ei=e=>{let t;try{t=e.contentWindow}catch{return!0}if(!t)return!0;try{let e=t.location.href;return e!==``&&e!==`about:blank`}catch{return!0}},Di=(e,t=wi)=>new Promise(n=>{if(Ei(e))return n();let r=()=>{clearInterval(i),clearTimeout(a),e.removeEventListener(`load`,r),n()},i=setInterval(()=>{Ei(e)&&r()},Ti),a=setTimeout(r,t);e.addEventListener(`load`,r)}),Oi=5e3,ki=9e4,Ai=(e,t,n)=>{let r=1,i,a=e.ownerDocument.defaultView,o=()=>{clearTimeout(i),d?.(),e.removeEventListener(`load`,u)},s=()=>{if(e.isConnected){if(r>=4)return o(),console.error(`FKN @fkn/lib: ${t} did not load in ${r} tries; reload the page`);r+=1,e.contentWindow?.location.replace(t),l(ki)}},l=e=>{clearTimeout(i),i=setTimeout(s,e)},u=()=>l(Oi),d=a?c(a,`message`,t=>{t.source===e.contentWindow&&t.origin===n&&o()}):void 0;if(e.addEventListener(`load`,u),Ei(e))return l(Oi);i=setTimeout(()=>Ei(e)?l(8e4):s(),wi)},ji=(e,t)=>({receive:n=>c(e.ownerDocument.defaultView,`message`,e=>{e.origin===t&&n(e.data,{source:e.source,origin:t})}),emit:(n,r)=>e.contentWindow?.postMessage(n,t,r)}),Mi=32,Ni=8,Pi=120,Fi=(e,t)=>typeof CSS<`u`&&typeof CSS?.supports==`function`&&CSS.supports(e,t),Ii=Fi(`clip-path`,`path('M0 0H1V1H0Z')`),Li=Fi(`clip-path`,`polygon(nonzero, 0px 0px, 1px 0px, 1px 1px)`),Ri=`light dark`,zi=e=>{let t=e.style;t.setProperty(`display`,`block`,`important`),t.setProperty(`position`,`fixed`,`important`),t.setProperty(`top`,`0`,`important`),t.setProperty(`left`,`0`,`important`),t.setProperty(`width`,`100%`,`important`),t.setProperty(`height`,`100%`,`important`),t.setProperty(`border`,`none`,`important`),t.setProperty(`padding`,`0`,`important`),t.setProperty(`box-sizing`,`border-box`,`important`),t.setProperty(`clip-path`,`inset(100%)`,`important`),t.setProperty(`background`,`transparent`),t.setProperty(`color-scheme`,Ri),t.setProperty(`z-index`,`2147483647`),e.setAttribute(`title`,`FKN`)},Bi=({x:e,y:t,width:n,height:r,radius:i})=>{if(!i)return`M${e} ${t}h${n}v${r}h${-n}Z`;let a=Math.min(n,r)/2,[o,s,c,l]=i.map(e=>Math.max(0,Math.min(e,a)));return`M${e+o} ${t}h${n-o-s}a${s} ${s} 0 0 1 ${s} ${s}v${r-s-c}a${c} ${c} 0 0 1 ${-c} ${c}h${-(n-c-l)}a${l} ${l} 0 0 1 ${-l} ${-l}v${-(r-l-o)}a${o} ${o} 0 0 1 ${o} ${-o}Z`},Vi=()=>Ii&&Li,Hi=({x:e,y:t,width:n,height:r})=>[[e,t],[e+n,t],[e+n,t+r],[e,t+r],[e,t]],Ui=e=>{let t=e[0];if(!t)return[];let n=Hi(t)[0],r=[];return e.forEach((t,i)=>{r.push(...Hi(t)),i>0&&i<e.length-1&&r.push(n)}),r},Wi=e=>`polygon(nonzero, ${Ui(e).map(([e,t])=>`${e}px ${t}px`).join(`, `)})`,Gi=({x:e,y:t,width:n,height:r,radius:i},a)=>{let o=`${t}px ${a.width-e-n}px ${a.height-t-r}px ${e}px`;return i?`inset(${o} round ${i.map(e=>`${e}px`).join(` `)})`:`inset(${o})`},Ki=(e,t,n)=>{if(t)return`none`;if(e.length===0)return`inset(100%)`;let r=e.length===1?e[0]:void 0;return r?Gi(r,n):Li&&e.length<=5&&!e.some(e=>e.radius)?Wi(e):`path('${e.map(Bi).join(``)}')`},qi=e=>{if(e.length<2)return null;let t=Math.min(...e.map(e=>e.x)),n=Math.min(...e.map(e=>e.y));return{x:t,y:n,width:Math.max(...e.map(e=>e.x+e.width))-t,height:Math.max(...e.map(e=>e.y+e.height))-n}},Ji=(e,t,n)=>t>=e.x&&t<e.x+e.width&&n>=e.y&&n<e.y+e.height,Yi=16,Xi=(e,t,n)=>t===1?e*Yi:t===2?e*n:e,Zi=(e,t,n,r,i)=>{let a=t?r:0,o=n?i:0;return a||o?{target:e,left:a,top:o}:null},Qi=(e,t,n)=>{let r=document.documentElement,i=getComputedStyle(r),a=i.overflowX===`visible`&&i.overflowY===`visible`&&document.body?document.body:r;for(let r of e){if(r===a)break;if(!(r instanceof Element))continue;let e=getComputedStyle(r),i=Zi(r,/auto|scroll/.test(e.overflowX)&&r.scrollWidth>r.clientWidth,/auto|scroll/.test(e.overflowY)&&r.scrollHeight>r.clientHeight,t,n);if(i)return i;if(e.position===`fixed`&&!r.offsetParent)break}let o=document.scrollingElement,s=a===r?i:getComputedStyle(a);return o&&Zi(o,!/hidden|clip/.test(s.overflowX),!/hidden|clip/.test(s.overflowY),t,n)},$i=null,ea=null,ta=e=>({width:e.offsetWidth||window.innerWidth,height:e.offsetHeight||window.innerHeight}),na=e=>{if(!ea||!$i||!Ji(ea,e.clientX,e.clientY))return;let t=document.fullscreenElement;if(t&&!t.contains($i))return;let n=e.composedPath(),r=n.find(e=>e instanceof Element&&e.matches(`:is(:modal, :popover-open)`));if(r&&!r.contains($i))return;let i=Qi(n,Xi(e.deltaX,e.deltaMode,window.innerWidth),Xi(e.deltaY,e.deltaMode,window.innerHeight));i&&(i.target.scrollBy({left:i.left,top:i.top,behavior:`instant`}),e.cancelable&&e.preventDefault())},ra,ia=e=>{ea=e,e?ra??=c(window,`wheel`,na,{capture:!0,passive:!1}):(ra?.(),ra=void 0)},aa=0,oa=null,sa=e=>{let t=document.documentElement;if(!t||e===aa&&(e===0||t===oa))return;aa=e,oa=t;let n=t.style;e>0?(n.setProperty(`margin-top`,`${e}px`,`important`),n.setProperty(`--fkn-inset-top`,`${e}px`)):(n.removeProperty(`margin-top`),n.removeProperty(`--fkn-inset-top`))},ca=(e,t)=>{t?(e.removeAttribute(`tabindex`),e.removeAttribute(`aria-hidden`)):(e.setAttribute(`tabindex`,`-1`),e.setAttribute(`aria-hidden`,`true`))},la=(e,{modal:t,rects:n,inset:r},i)=>{if(sa(r),!Ii){let r=t||n.length>0;ca(e,r),e.style.setProperty(`pointer-events`,r?`auto`:`none`,`important`),e.style.setProperty(`visibility`,r?`visible`:`hidden`,`important`);return}let a=Ki(n,t,i),o=a===`none`||Fi(`clip-path`,a)?a:`inset(100%)`;e.style.setProperty(`clip-path`,o,`important`),ca(e,o!==`inset(100%)`),ia(t||o!==a?null:qi(n))},ua=e=>{if(typeof e!=`object`||!e)return 0;let{top:t}=e;return typeof t!=`number`||!Number.isFinite(t)||t<=0?0:Math.min(Math.round(t),Pi)},da=e=>{if(Array.isArray(e)&&e.length===4&&e.every(e=>typeof e==`number`&&Number.isFinite(e)&&e>=0))return e.some(e=>e>0)?e:void 0},fa=(e,t)=>{if(typeof e!=`object`||!e)return null;let{x:n,y:r,width:i,height:a}=e;if(![n,r,i,a].every(e=>typeof e==`number`&&Number.isFinite(e)))return null;let o=t.width,s=t.height,c=Math.max(0,Math.min(Math.round(n),o)),l=Math.max(0,Math.min(Math.round(r),s)),u=Math.max(c,Math.min(Math.round(n+i),o)),d=Math.max(l,Math.min(Math.round(r+a),s)),f=da(e.radius);return{x:c,y:l,width:u-c,height:d-l,...f?{radius:f}:{}}},pa={"not-rendered":`this page is not painting it at all, so it or an ancestor is display:none, or the frame was moved out of the layout`,clipped:`it is clipped away or positioned outside the viewport`,"not-shown":`it is rendered but would not be seen, so either something is drawn over it, or it or an ancestor has opacity below 1, visibility:hidden, or a filter`},ma=e=>Array.isArray(e)?e.slice(0,Ni).flatMap(e=>{if(typeof e!=`object`||!e)return[];let{kind:t,cause:n,level:r}=e;return typeof t!=`string`||t.length>40||typeof n!=`string`||!(n in pa)||r!==`full`&&r!==`liveness`?[]:[{kind:t,cause:n,level:r}]}):[],ha=new Set,ga=e=>{for(let{kind:t,cause:n,level:r}of e)ha.has(t)||(ha.add(t),console.error(`[FKN] The FKN ${JSON.stringify(t)} is not visible on this page: ${pa[n]}. Nobody using this page can see or answer it.
|
|
2
|
+
@fkn/lib draws its UI inside <iframe title="FKN"> and sets display, position, top, left, width, height, border, padding, box-sizing, clip-path and z-index on that element. Leave those as they are, then check for an ancestor with opacity, visibility, display or a clipping transform, and for an element stacked above it.`+(r===`liveness`?`
|
|
3
|
+
This browser reports limited detail, so the cause above is a best guess.`:``)))},_a=(e,t)=>{if(typeof e!=`object`||!e)return null;let n=e,r=(Array.isArray(n.rects)?n.rects.slice(0,Mi):[]).map(e=>fa(e,t)).filter(e=>e!==null&&e.width>0&&e.height>0);return{modal:n.modal===!0,rects:r,hidden:ma(n.hidden),inset:ua(n.inset)}},va=()=>$i!==null,ya=null,ba=null,xa=()=>{if(!$i||ya===null)return;let e=ta($i),t=_a(ya,e);t&&la($i,t,e)},Sa=e=>{typeof ResizeObserver<`u`&&(ba??=new ResizeObserver(xa),ba.disconnect(),ba.observe(e))},Ca=e=>{zi(e),la(e,{modal:!1,rects:[],hidden:[],inset:0},ta(e)),$i=e,Sa(e)},wa=e=>{if(!$i)return;let t=ta($i),n=_a(e,t);n&&(ya=e,la($i,n,t),ga(n.hidden))},Ta=`https://fkn.app`,Ea=typeof globalThis<`u`&&globalThis.document?globalThis.document:void 0,Da=typeof globalThis<`u`&&globalThis.crossOriginIsolated===!0,Oa=s(Da),ka=`fkn-api-port`,Aa=`fkn-api-port-ack`,ja=2e3,Ma=()=>{if(!Ea||typeof window>`u`||window.parent===window)return Promise.resolve(void 0);let e;try{e=window.parent}catch{return Promise.resolve(void 0)}let t=new MessageChannel;return new Promise(n=>{let r=e=>{if(clearTimeout(a),t.port1.removeEventListener(`message`,i),!e)try{t.port1.close()}catch{}n(e)},i=e=>{e.data?.type===Aa&&r(t.port1)},a=setTimeout(()=>r(void 0),ja);t.port1.addEventListener(`message`,i),t.port1.start();try{e.postMessage({type:ka},Ta,[t.port2])}catch{r(void 0)}})},Na,Pa=e=>e.querySelector(`iframe[src="${Oa}"]`),Fa=async e=>{for(;!e.body;)await new Promise(t=>{let n=new MutationObserver(()=>{n.disconnect(),t()});n.observe(e,{childList:!0,subtree:!0})})},Ia=async e=>{let t=Pa(e);if(t||=(await Fa(e),Pa(e)),t)Na=t;else{let t=e.createElement(`iframe`);t.setAttribute(`allow`,a(Da)),t.src=Oa,e.body.appendChild(t),Na=t}return Ai(Na,Oa,Ta),Ca(Na),Na},La=(async()=>{if(!Ea)return;let e=await Ma();if(e)return{receive:e,emit:e};let t=await Ia(Ea);return await Di(t),t.contentWindow?ji(t,Ta):void 0})(),Ra=(e,{boundRetired:t=e=>e}={})=>{let n,r=0,i=!1,a=()=>{},o=()=>new Promise(e=>{a=e}),s=o(),c=s,l=new Set,u=new Set,d=0,f=0,p=()=>{let e=[...u];u.clear();let t=Error(`FKN: the broker was replaced while this call was pending; retry it`);for(let n of e)try{n(t)}catch{}};(async()=>{for await(let t of e){let e=++r;n={remote:t,epoch:e};let i=a;s=o(),i(t),p();for(let n of[...l])try{n(t,e)}catch{}}})().catch(()=>{});let m=async(e,r)=>{let a=n?.remote??await(i?t(s):s);for(let t of e.slice(0,-1))a=a[t];let o=a[e[e.length-1]??``];d=Date.now(),f+=1;let c=()=>{},l=new Promise((e,t)=>{c=t});u.add(c);try{return await Promise.race([Promise.resolve(o.apply(a,r)),l])}finally{--f,u.delete(c),d=Date.now()}},h=new Map,g=e=>{let t=e.join(`\0`),r=h.get(t);if(r)return r;let i=new Proxy(function(){},{get:(t,r)=>{if(typeof r!=`string`||r===`then`)return;let i=n;if(i){let t=i.remote;for(let n of e)t=t?.[n];if(t?.[r]===void 0)return}return g([...e,r])},apply:(t,n,r)=>m(e,r)});return h.set(t,i),i};return{facade:g([]),first:c.then(()=>{}),current:()=>n,onEpoch:e=>{if(l.add(e),n)try{e(n.remote,n.epoch)}catch{}return()=>{l.delete(e)}},lastCall:()=>d,inFlight:()=>f,routable:()=>n?Promise.resolve():s.then(()=>{}),retire:()=>{i=!0,n=void 0,p()}}},za=!1,Ba=new Set,Va=()=>za,Ha=e=>{Ba.add(e)},Ua=e=>`fkn-relayed-worker-${e}`,Wa=e=>new Promise(t=>{let n=globalThis.navigator?.locks;if(!n)return t();n.request(Ua(e),()=>(t(),new Promise(()=>{}))).catch(()=>t())}),Ga=async()=>{if(typeof window<`u`)return La;if(typeof self<`u`)return{receive:self,emit:self}},Ka=`fkn-api`,qa=`fkn-api-window`,Ja={async*[Symbol.asyncIterator](){let e=await Ga();if(!e)await new Promise(()=>{});else{if(!Va()){let t=new AbortController;Ha(()=>t.abort());let n=crypto.randomUUID();typeof window>`u`&&await Wa(n);for await(let r of Ci({},{key:Ka,transport:e,unregisterSignal:t.signal,uuid:n})){if(t.signal.aborted)break;yield r}}yield*Ci({},{key:qa,transport:e})}}},Ya=!1,Xa=Ga().then(e=>new Promise(t=>{if(!e)return;let n=new AbortController;y({transport:e,key:Ka,unregisterSignal:n.signal,listener:()=>{n.abort(),Ya=!0,t()}})})),Za=Ra(Ja,{boundRetired:e=>Promise.race([e,Xa.then(()=>ao(e,()=>new ro))])});Ha(()=>Za.retire());var Qa=class extends Error{constructor(e,t){super(t===void 0?`@fkn/lib: no FKN broker in this realm (it has no window and no self, as in Node.js), so ${e} could not be requested`:`@fkn/lib: no broker connection within ${t}ms, so ${e} could not be requested`),this.name=`BrokerUnreachableError`}},$a=l?Promise.race([Za.first,new Promise(e=>Ha(e))]).then(()=>Za.facade):Promise.reject(new Qa(`a broker call`));$a.catch(()=>{});var eo=8e3,to=1e3,no=!1,ro=class extends Error{constructor(){super(`FKN @fkn/lib: this page relays its FKN channel to a worker, and the FKN page it reached predates a channel of the page's own; reload`),this.name=`OwnChannelUnavailableError`}},io=e=>new Promise((t,n)=>setTimeout(()=>n(e))),ao=(e,t)=>{if(no&&!Ya)return io(t(eo));let n=no?to:eo;return Promise.race([e,new Promise((e,r)=>setTimeout(()=>{no=!0,r(t(n))},n))])},oo=e=>l?Va()?ao(Za.routable().then(()=>Za.facade),t=>Ya?new ro:new Qa(e,t)):ao($a,t=>new Qa(e,t)):io(new Qa(e));Ha(()=>{Xa.then(()=>{let e=setTimeout(()=>console.error(new ro),eo);Za.routable().then(()=>clearTimeout(e))})});var so=Za.onEpoch,co=Za.current;Za.lastCall,Za.inFlight,so(e=>{va()&&e.overlay.setHost(wa,{exactClips:Vi(),colorScheme:Ri}).catch(()=>{})});var lo=0,uo=new Set,fo=2e3,po=null,mo=e=>{let t=e?.switched!==!1;t&&(lo+=1,po&&=(clearTimeout(po.timer),null));for(let e of[...uo])try{e({switched:t})}catch{}},ho=!1,go=0,_o=()=>{let e=co();e&&go!==e.epoch&&(go=e.epoch,Promise.resolve(e.remote.account.onChange(mo)).catch(()=>{go===e.epoch&&(go=0)}))},vo=()=>{!ho&&l&&(ho=!0,so(_o))},yo=()=>lo,bo=e=>(uo.add(e),vo(),()=>{uo.delete(e)}),xo=e=>{if(e!==lo||po?.generation===e)return;let t=setTimeout(()=>{po?.timer===t&&(po=null,lo===e&&mo({switched:!0}))},fo);po={generation:e,timer:t}},So=async()=>typeof window>`u`?!1:(await $a).account.login(location.origin).catch(()=>!1),Co=async()=>{if(typeof window>`u`)return null;let e=await $a.then(e=>e.account.info()).catch(()=>null);return e?{name:e.name,image:e.image,premium:e.premium,premiumUntil:e.premiumUntil?Date.parse(e.premiumUntil):null}:null},wo=async e=>l?bo(e):()=>{},To=`FKN_STORAGE_NOT_FOUND`,Eo=`FKN_ACCOUNT_CHANGED`,Do=`FKN_ACCOUNT_PIN_UNSUPPORTED`,Oo=n({StorageAccountChangedError:()=>Mo,StorageAccountPinUnsupportedError:()=>No,StorageLockedError:()=>ko,StorageNotFoundError:()=>Ao,availability:()=>$o,available:()=>Jo,captureAccount:()=>Lo,encryption:()=>ss,isAccountChanged:()=>Po,isInvalidPin:()=>Fo,isNotFound:()=>jo,knownPin:()=>Uo,list:()=>es,pinFor:()=>Wo,quota:()=>ts,readFile:()=>ns,readFileSealed:()=>is,remove:()=>os,unlock:()=>cs,writeFile:()=>as}),ko=class extends Error{code=`FKN_E2E_LOCKED`;constructor(){super(`storage locked: connect the app again to open encrypted data`)}},Ao=class extends Error{code=To;constructor(e=`storage: no object at that path`){super(e)}},jo=e=>e?.code===To,Mo=class extends Error{code=Eo;constructor(e=`storage: the signed-in account changed, so this call was not made`){super(e)}},No=class extends Error{code=Do;constructor(e=`storage: the FKN broker cannot pin calls to an account yet, so nothing was sent`){super(e)}},Po=e=>e?.code===`FKN_ACCOUNT_CHANGED`||e instanceof Error&&e.message.startsWith(`fkn:account-changed`),Fo=e=>e instanceof Error&&e.message.startsWith(`fkn:account-pin-invalid`),Io=e=>{throw e instanceof Error&&e.message.startsWith(`fkn:e2e-locked`)?new ko:jo(e)?new Ao(e.message):Po(e)?new Mo:e instanceof Error&&e.message.startsWith(`fkn:account-pin-unsupported`)?new No:e instanceof Error&&(/^not found$/i.test(e.message)||/\(404\)$/.test(e.message))?new Ao(e.message):e},Lo=()=>(vo(),{generation:yo()}),Ro=new Map,zo=null,Bo=e=>typeof e?.accountPin==`function`,Vo=(e,t)=>{let n=Promise.resolve(t.accountPin()).then(t=>{if(typeof t!=`string`||!t)throw Error(`storage: the broker answered no account pin`);return yo()===e&&Ro.set(e,t),t});return zo={generation:e,pin:n},n.catch(()=>{zo?.pin===n&&(zo=null)}),n},Ho=async(e,t)=>{let n=Ro.get(e.generation);if(n!==void 0)return n;if(e.generation!==yo())throw new Mo;let r=await(zo?.generation===e.generation?zo.pin:Vo(e.generation,t)).catch(Io);if(e.generation!==yo())throw new Mo;return r},Uo=e=>Ro.get(e.generation),Wo=async e=>{let t=(await $a).cloud.fs;if(!Bo(t))throw new No;return Ho(e,t)},Go=e=>{for(let[t,n]of Ro)if(n===e)return t},Ko=e=>e?.pin??Lo(),qo=async(e,t)=>{let n=(await $a).cloud.fs;if(!Bo(n))throw new No;let r=`pin`in e?e.pin:await Ho(e,n);if(!Bo(n))throw new No;return t(n,{accountPin:r}).catch(t=>{if(Po(t)){let t=`generation`in e?e.generation:Go(r);t!==void 0&&xo(t)}return Io(t)})},Jo=()=>$a.then(e=>e.cloud.fs.available()).catch(()=>!1),Yo=8e3,Xo=1e3,Zo=!1,Qo=async()=>{let e=(await $a).cloud.fs;return typeof e.availability==`function`?e.availability():await e.available()?`connected`:`disconnected`},$o=async()=>{let e=Zo?Xo:Yo,t=await new Promise(t=>{let n=setTimeout(()=>t(`timeout`),e);Qo().then(e=>{clearTimeout(n),t(e)},()=>{clearTimeout(n),t(`unknown`)})});return t===`timeout`?(Zo=!0,`unknown`):(Zo=!1,t)},es=e=>qo(Ko(e),(e,t)=>e.list(t)),ts=()=>$a.then(e=>e.cloud.fs.quota()),ns=async(e,t)=>{let n=await qo(Ko(t),(t,n)=>t.readFile(e,n));return new Blob([n])},rs=e=>{if(e===null||!Number.isFinite(e))return null;let t=new Date(e);return Number.isNaN(t.getTime())?null:t.toISOString()},is=async(e,t)=>qo(Ko(t),async(t,n)=>{let r=t;if(typeof r.readFileSealed!=`function`)return{data:await t.readFile(e,n),sealedAt:null};let i=await r.readFileSealed(e,n);return{data:i.bytes,sealedAt:rs(i.sealedAt)}}),as=async(e,t,n)=>{let r=Ko(n),i=t instanceof Blob?new Uint8Array(await t.arrayBuffer()):t;await qo(r,(t,r)=>t.writeFile(e,i,n?.contentType??null,r))},os=async(e,t)=>{await qo(Ko(t),(t,n)=>t.remove(e,n))},ss=()=>$a.then(e=>e.cloud.fs.encryption()),cs=()=>$a.then(e=>e.cloud.fs.unlock()),ls=new Map,us=new Set,ds=e=>{ls.set(e,(ls.get(e)??0)+1);let t=!1;return()=>{t||(t=!0,ls.set(e,Math.max(0,(ls.get(e)??1)-1)))}},fs=(e,t)=>{us.add({kind:e,probe:t})},ps=e(((e,t)=>{t.exports={}}))(),ms={json:`application/json`,txt:`text/plain`,html:`text/html`,htm:`text/html`,css:`text/css`,js:`text/javascript`,mjs:`text/javascript`,xml:`application/xml`,csv:`text/csv`,md:`text/markdown`,svg:`image/svg+xml`,png:`image/png`,jpg:`image/jpeg`,jpeg:`image/jpeg`,gif:`image/gif`,webp:`image/webp`,pdf:`application/pdf`,wasm:`application/wasm`},hs=(e,t)=>{if(t)return t;let n=e.split(`/`).pop()??``,r=n.lastIndexOf(`.`);if(!(r<=0))return ms[n.slice(r+1).toLowerCase()]},gs=(e,t)=>({size:e,mtimeMs:t,mtime:new Date(t),atimeMs:t,ctimeMs:t,mode:420,isFile:()=>!0,isDirectory:()=>!1,isSymbolicLink:()=>!1}),_s=(e=0)=>({size:0,mtimeMs:e,mtime:new Date(e),atimeMs:e,ctimeMs:e,mode:493,isFile:()=>!1,isDirectory:()=>!0,isSymbolicLink:()=>!1}),H=(e,t,n)=>{let r=Error(`${e}: ${{ENOENT:`no such file or directory`,EEXIST:`file already exists`,ENOTDIR:`not a directory`,EISDIR:`illegal operation on a directory`,ENOTEMPTY:`directory not empty`,ERR_FS_EISDIR:`is a directory`,EROFS:`read-only file system, as @fkn/lib keeps no files in Node.js`}[e]??e}, ${n} '${t}'`);return r.code=e,r.path=t,r.syscall=n,r},vs=e=>{let t=[];for(let n of e.split(`/`))n&&n!==`.`&&(n===`..`?t.pop():t.push(n));return t.join(`/`)},ys=e=>e.split(`/`).slice(0,-1).join(`/`),U=e=>typeof e==`string`?e:e instanceof URL?decodeURIComponent(e.pathname):e.toString(),bs=e=>typeof e==`string`?e:e?.encoding??void 0,xs=e=>typeof e==`object`?e?.contentType:void 0,Ss=e=>typeof e==`object`&&!!e?.recursive,Cs=(e,t)=>{let n=bs(t);return n?ps.Buffer.from(e).toString(n):ps.Buffer.from(e)},ws=(e,t)=>{if(typeof e==`string`)return new Uint8Array(ps.Buffer.from(e,bs(t)??`utf8`));if(e instanceof Uint8Array)return e.slice();if(e instanceof ArrayBuffer)return new Uint8Array(e).slice();if(ArrayBuffer.isView(e))return new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice();throw TypeError(`The "data" argument must be of type string, Buffer, TypedArray, or DataView`)},Ts=e=>{let t=new Map([[``,{kind:`dir`,mtimeMs:0}]]),n=new Map,r=new Map,i=()=>e.captureAccount?{pin:e.captureAccount()}:{};fs(`unsaved files`,()=>n.size>0||r.size>0);let a=new Set,o=()=>Date.now(),s=e=>{if(!e)return;let n=e.split(`/`),r=``;for(let e of n){r=r?`${r}/${e}`:e;let n=t.get(r);if(!n)t.set(r,{kind:`dir`,mtimeMs:o()});else if(n.kind===`file`)throw H(`ENOTDIR`,r,`mkdir`)}},u,d=0,f=async()=>{let c=i(),l=await e.list(c).catch(()=>[]),u=new Set,f=!1;for(let i of l){let l=vs(i.path);if(u.add(l),!r.has(l)&&(!n.has(l)||a.has(l)))try{let u=await(await e.readFile(i.path,c)).arrayBuffer();if(r.has(l)||n.has(l)&&!a.has(l))continue;s(ys(l));let d=Date.parse(i.updatedAt??``);t.set(l,{kind:`file`,data:new Uint8Array(u),mtimeMs:Number.isFinite(d)?d:o(),contentType:i.contentType??void 0}),a.delete(l),n.delete(l)}catch{f=!0,a.add(l)}}for(let e of a)u.has(e)||a.delete(e);d=f?Date.now():0},p=()=>(u&&(d===0||Date.now()-d<5e3)||(u=f()),u),m=async()=>{u=void 0,d=0,await p()},h=async()=>{let i=[...n].map(async([r,i])=>{if(a.has(r))return;let o=t.get(r);if(o?.kind!==`file`){n.delete(r);return}let s=o.data,c=hs(r,o.contentType);try{await e.writeFile(r,s,c?{contentType:c,...i}:i);let a=t.get(r);a?.kind===`file`&&a.data===s&&n.delete(r)}catch{}}),o=[...r].map(async([t,n])=>{try{await e.remove(t,n),r.get(t)===n&&r.delete(t)}catch{}});await Promise.all([...i,...o])},g,_=()=>{g||=setTimeout(()=>{g=void 0,h().catch(()=>{})},250)};typeof window<`u`&&(c(window,`pagehide`,()=>{h().catch(()=>{})}),c(document,`visibilitychange`,()=>{document.visibilityState===`hidden`&&h().catch(()=>{})}));let v=e=>e.kind===`file`?gs(e.data.byteLength,e.mtimeMs):_s(e.mtimeMs),y=e=>Object.assign(Error(`storage: ${e} exists but could not be read, retry once its scope is available`),{code:`FKN_E2E_LOCKED`}),b=e=>{let n=vs(e);return t.has(n)||a.has(n)},x=e=>{let n=vs(e),r=t.get(n);if(!r)throw a.has(n)?y(e):H(`ENOENT`,e,`stat`);return v(r)},S=e=>{let n=vs(e),r=t.get(n);if(!r)throw a.has(n)?y(e):H(`ENOENT`,e,`open`);if(r.kind===`dir`)throw H(`EISDIR`,e,`read`);return r.data},C=(e,t)=>{let n=new Uint8Array(e.byteLength+t.byteLength);return n.set(e,0),n.set(t,e.byteLength),n},w=(e,c,u,d)=>{let f=vs(e);if(!f)throw H(`EISDIR`,e,`open`);if(!l)throw H(`EROFS`,e,`open`);if(a.has(f))throw y(e);let p=t.get(f);if(p?.kind===`dir`)throw H(`EISDIR`,e,`open`);s(ys(f));let m=u&&p?.kind===`file`?C(p.data,c):c;t.set(f,{kind:`file`,data:m,mtimeMs:o(),contentType:d??(p?.kind===`file`?p.contentType:void 0)}),n.set(f,i()),r.delete(f),_()},T=(e,n)=>{let r=vs(e);if(r){if(!l)throw H(`EROFS`,e,`mkdir`);if(t.has(r)){if(n)return;throw H(`EEXIST`,e,`mkdir`)}if(!n&&!t.has(ys(r)))throw H(`ENOENT`,e,`mkdir`);s(r)}},E=e=>{let n=vs(e),r=t.get(n);if(!r)throw H(`ENOENT`,e,`scandir`);if(r.kind===`file`)throw H(`ENOTDIR`,e,`scandir`);let i=n?`${n}/`:``,o=new Set;for(let e of[...t.keys(),...a]){if(!e||!e.startsWith(i))continue;let t=e.slice(i.length);t&&o.add(t.split(`/`)[0])}return[...o]},D=(e,{op:o,recursive:s,force:c})=>{let l=i(),u=vs(e),d=t.get(u);if(!d&&a.has(u)){if(o===`rmdir`)throw H(`ENOTDIR`,e,`rmdir`);a.delete(u),n.delete(u),r.set(u,l),_();return}if(!d){if(c||o===`rmdir`&&s)return;throw H(`ENOENT`,e,o===`rmdir`?`rmdir`:`unlink`)}if(o===`unlink`&&d.kind===`dir`)throw H(`EISDIR`,e,`unlink`);if(o===`rmdir`&&d.kind===`file`)throw H(`ENOTDIR`,e,`rmdir`);if(o===`rm`&&d.kind===`dir`&&!s)throw H(`ERR_FS_EISDIR`,e,`rm`);let f=`${u}/`,p=[...t.keys()].filter(e=>e.startsWith(f));if(p.length&&!s)throw H(`ENOTEMPTY`,e,`rmdir`);for(let e of[u,...p]){let i=t.get(e);t.delete(e),i?.kind===`file`&&(n.delete(e),r.set(e,l))}_()};return{mount:p,remount:m,flush:h,exists:b,stat:x,readFile:S,writeFile:w,mkdir:T,readdir:E,remove:D,rename:(e,o)=>{let c=i(),l=vs(e),u=vs(o);if(!l)throw H(`EBUSY`,e,`rename`);if(u===l||u.startsWith(`${l}/`))throw H(`EINVAL`,e,`rename`);if(a.has(l))throw y(e);if(a.has(u))throw y(o);let d=t.get(l);if(!d)throw H(`ENOENT`,e,`rename`);let f=t.get(u);if(f){if(f.kind!==d.kind)throw H(d.kind===`dir`?`ENOTDIR`:`EISDIR`,o,`rename`);D(u,{op:`rm`,recursive:!0,force:!0})}s(ys(u));let p=`${l}/`,m=[l,...[...t.keys()].filter(e=>e.startsWith(p))];for(let e of m){let i=u+e.slice(l.length),a=t.get(e);t.set(i,a),t.delete(e),a.kind===`file`&&(n.set(i,c),r.delete(i),n.delete(e),r.set(e,c))}_()}}},Es=(e,t)=>typeof e==`function`?e:t,Ds=e=>typeof e==`function`?void 0:e,Os=(e,t)=>{e.then(e=>t(null,e),e=>t(e))},ks=e=>{let t=Ts(e),n=(e,n)=>Cs(t.readFile(U(e)),n),r=(e,n,r)=>t.writeFile(U(e),ws(n,r),!1,xs(r)),i=(e,n,r)=>t.writeFile(U(e),ws(n,r),!0,xs(r)),a=e=>t.exists(U(e)),o=e=>t.stat(U(e)),s=e=>t.readdir(U(e)),c=(e,n)=>t.mkdir(U(e),Ss(n)),l=(e,n)=>t.remove(U(e),{op:`rm`,...n}),u=(e,n)=>t.remove(U(e),{op:`rmdir`,...n}),d=e=>t.remove(U(e),{op:`unlink`}),f=(e,n)=>t.rename(U(e),U(n)),p=(e,n)=>{t.mount().finally(()=>{let t;try{t=e()}catch(e){n(e);return}n(null,t)})},m=e=>t.mount().then(()=>e());return{available:e.available,readFileSync:n,writeFileSync:r,appendFileSync:i,existsSync:a,statSync:o,lstatSync:o,readdirSync:s,mkdirSync:c,rmSync:l,rmdirSync:u,unlinkSync:d,renameSync:f,readFile:(e,n,r)=>p(()=>Cs(t.readFile(U(e)),Ds(n)),Es(n,r)),writeFile:(e,n,r,i)=>p(()=>t.writeFile(U(e),ws(n,Ds(r)),!1,xs(Ds(r))),Es(r,i)),appendFile:(e,n,r,i)=>p(()=>t.writeFile(U(e),ws(n,Ds(r)),!0,xs(Ds(r))),Es(r,i)),stat:(e,n)=>p(()=>t.stat(U(e)),n),readdir:(e,n,r)=>p(()=>t.readdir(U(e)),Es(n,r)),mkdir:(e,n,r)=>p(()=>t.mkdir(U(e),Ss(Ds(n))),Es(n,r)),rm:(e,n,r)=>p(()=>t.remove(U(e),{op:`rm`,...Ds(n)}),Es(n,r)),unlink:(e,n)=>p(()=>t.remove(U(e),{op:`unlink`}),n),rename:(e,n,r)=>p(()=>t.rename(U(e),U(n)),r),exists:(e,n)=>{t.mount().finally(()=>n(t.exists(U(e))))},promises:{readFile:(e,n)=>m(()=>Cs(t.readFile(U(e)),n)),writeFile:(e,n,r)=>m(()=>t.writeFile(U(e),ws(n,r),!1,xs(r))),appendFile:(e,n,r)=>m(()=>t.writeFile(U(e),ws(n,r),!0,xs(r))),stat:e=>m(()=>t.stat(U(e))),lstat:e=>m(()=>t.stat(U(e))),readdir:e=>m(()=>t.readdir(U(e))),mkdir:(e,n)=>m(()=>t.mkdir(U(e),Ss(n))),rm:(e,n)=>m(()=>t.remove(U(e),{op:`rm`,...n})),rmdir:(e,n)=>m(()=>t.remove(U(e),{op:`rmdir`,...n})),unlink:e=>m(()=>t.remove(U(e),{op:`unlink`})),rename:(e,n)=>m(()=>t.rename(U(e),U(n))),access:e=>m(()=>{if(!t.exists(U(e)))throw H(`ENOENT`,U(e),`access`)})},mount:t.mount,flush:t.flush,remount:t.remount}},As=e=>{let t=()=>e.captureAccount?{pin:e.captureAccount()}:{},n=async(t,n)=>{let r=await e.readFile(U(t));return Cs(new Uint8Array(await r.arrayBuffer()),n)},r=async(t,n,r)=>{let i=U(t),a=hs(i,xs(r));await e.writeFile(i,ws(n,r),a?{contentType:a}:void 0)},i=t=>e.remove(U(t)),a=async(n,r)=>{let i=t(),a=vs(U(n)),o=vs(U(r));if(a===o)return;let s=await e.readFile(a,i);await e.writeFile(o,s,i),await e.remove(a,i)},o=async t=>{let n=vs(U(t)),r=n?`${n}/`:``,i=new Set;for(let t of await e.list()){let e=vs(t.path);if(r&&!e.startsWith(r))continue;let n=e.slice(r.length);n&&i.add(n.split(`/`)[0])}return[...i]},s=async(e,t)=>{},c=async(n,r)=>{let i=t(),a=vs(U(n));if(!r?.recursive){await e.remove(U(n),i);return}let o=`${a}/`,s=await e.list(i);await Promise.all(s.filter(e=>{let t=vs(e.path);return t===a||t.startsWith(o)}).map(t=>e.remove(t.path,i).catch(()=>{})))},l=async t=>{let n=vs(U(t)),r=await e.list(),i=r.find(e=>vs(e.path)===n);if(i){let e=Date.parse(i.updatedAt??``);return gs(i.size,Number.isFinite(e)?e:0)}if(r.some(e=>vs(e.path).startsWith(`${n}/`)))return _s();throw H(`ENOENT`,U(t),`stat`)},u={readFile:n,writeFile:r,unlink:i,rename:a,readdir:o,mkdir:s,rm:c,rmdir:c,stat:l,lstat:l,access:async e=>{await l(e)}};return{available:e.available,promises:u,readFile:(e,t,r)=>Os(n(e,Ds(t)),Es(t,r)),writeFile:(e,t,n,i)=>Os(r(e,t,Ds(n)),Es(n,i)),unlink:(e,t)=>Os(i(e),t),rename:(e,t,n)=>Os(a(e,t),n),readdir:(e,t,n)=>Os(o(e),Es(t,n)),mkdir:(e,t,n)=>Os(s(),Es(t,n)),rm:(e,t,n)=>Os(c(e,Ds(t)),Es(t,n)),stat:(e,t)=>Os(l(e),t)}};function js(e,t){return t.memfs?ks(e):As(e)}var{available:Ms,readFile:Ns,writeFile:Ps,unlink:Fs,rename:Is,readdir:Ls,mkdir:Rs,rm:zs,stat:Bs,promises:Vs}=js(Oo,{memfs:!1}),Hs=()=>es(),Us=e=>is(e),Ws=`fkn-packages-connection`,Gs=`https://fkn.app`,Ks=3e4,qs=(e,t)=>Object.assign(Error(t),{code:e}),Js=async()=>{if(!l)throw qs(`unavailable`,`packages: no FKN transport in this realm - use relayWorker to bridge workers`);return $a},Ys=(e,t,n)=>Ci(e??{},{transport:t,key:Ws,unregisterSignal:n}),Xs=async(e,t,n={})=>{let{signal:r,closed:i}=n;if(r?.aborted)throw qs(`unavailable`,`packages.connect: aborted before connecting`);let a=new AbortController;r&&r.addEventListener(`abort`,()=>a.abort(r.reason),{once:!0});let o=new AbortController,s=new Promise((e,n)=>{let a=setTimeout(()=>n(qs(`timeout`,`packages.connect: the package did not complete the connection`)),Ks);o.signal.addEventListener(`abort`,()=>clearTimeout(a),{once:!0}),t.addEventListener(`message`,e=>{if(e.data?.type===`fkn-packages-nack`){let t=e.data.message;n(qs(`unavailable`,typeof t==`string`&&t?t:`packages.connect: the package refused the connection`))}},{signal:o.signal}),t.start(),r&&r.addEventListener(`abort`,()=>n(qs(`unavailable`,`packages.connect: aborted before connecting`)),{once:!0,signal:o.signal}),i?.then(()=>n(qs(`unavailable`,`packages.connect: the package closed before connecting`)))});try{return await Promise.race([Ys(e,t,a.signal),s])}catch(e){a.abort(e);try{t.close()}catch{}throw e}finally{o.abort()}},Zs=async(e,t)=>{let{packages:n}=await Js(),r=t?.temporary?n.installTemporary:n.install;if(!r)throw qs(`unsupported`,`packages.install: this fkn.app cannot install a package temporarily`);let i=await r(e,t);if(`error`in i)throw qs(i.error,i.message);return`declined`in i?null:i.installed},Qs=({x:e,y:t,width:n,height:r})=>({x:Math.round(e),y:Math.round(t),width:Math.round(n),height:Math.round(r)}),$s=(e,t)=>{let n=Math.max(e.x,t.x),r=Math.max(e.y,t.y);return{x:n,y:r,width:Math.max(0,Math.min(e.x+e.width,t.x+t.width)-n),height:Math.max(0,Math.min(e.y+e.height,t.y+t.height)-r)}},ec=(e,t)=>{let n=t;for(let t=e.parentElement;t;t=t.parentElement){let e=getComputedStyle(t);if((e.overflowX!==`visible`||e.overflowY!==`visible`)&&(n=$s(n,Qs(t.getBoundingClientRect())),n.width===0||n.height===0))break}return n},tc=e=>{let t=getComputedStyle(e),n=[t.borderTopLeftRadius,t.borderTopRightRadius,t.borderBottomRightRadius,t.borderBottomLeftRadius];if(n.some(e=>e.includes(`%`)||e.includes(` `)))return;let r=n.map(e=>{let t=Number.parseFloat(e);return Number.isFinite(t)&&t>0?t:0});return r.some(e=>e>0)?r:void 0},nc=(e,t)=>{if(!e)return!1;let n=(e,t)=>e===t||!!e&&!!t&&e.x===t.x&&e.y===t.y&&e.width===t.width&&e.height===t.height;return n(e.rect,t.rect)&&n(e.clip,t.clip)&&((e,t)=>e===t||!!e&&!!t&&e.every((e,n)=>e===t[n]))(e.radius,t.radius)},rc=new Map;fs(`package view`,()=>rc.size>0);var ic=async(e,t)=>{let n=rc.get(e);if(n){for(let e of n)t&&e.element!==t||(e.stop(),n.delete(e));if(n.size>0)return;rc.delete(e)}let r=await(await Js()).packages.hide(e);if(`error`in r)throw qs(r.error,r.message)},ac=async(e,t)=>{let{element:n,rect:r}=t;if(!n&&!r)throw qs(`invalid`,`packages.show: pass an element or a rect`);let i=(await Js()).packages,a=()=>{if(!n)return{rect:Qs(r)};let e=Qs(n.getBoundingClientRect());return{rect:e,clip:ec(n,e),radius:tc(n)}},o=!0,s,c=0,l=async t=>{s=t;let n=await i.show(e,t);if(`error`in n)throw o=!1,qs(n.error,n.message)};await l(a());let u=()=>{if(!o)return;let e=a();nc(s,e)||l(e).catch(()=>{}),c=requestAnimationFrame(u)};n&&(c=requestAnimationFrame(u));let d={element:n,stop:()=>{o=!1,cancelAnimationFrame(c)}},f=rc.get(e)??new Set;return f.add(d),rc.set(e,f),{hide:()=>{ic(e,n).catch(()=>{})},refresh:()=>{if(!o)return;let e=a();nc(s,e)||l(e).catch(()=>{})}}},oc=async(e,t={})=>ic(e,t.element),sc=(async(e,t={})=>{let n=await(await Js()).packages.connect(e,{protocol:t.protocol,...t.path===void 0?{}:{path:t.path}});if(`error`in n)throw qs(n.error,n.message);let r=ds(`package connection`),i=co()?.epoch??0,a=so((e,t)=>{t!==i&&(r(),a())});Promise.resolve(n.closed).then(()=>{r(),a()},()=>{r(),a()});let{port:o,closed:s}=n;if(t.raw)return{closed:s,port:o};let c=await Xs(t.payload,o,{signal:t.signal,closed:s});return t.signal&&t.signal.addEventListener(`abort`,()=>{try{o.postMessage({type:`fkn-packages-disconnect`})}catch{}},{once:!0}),{remote:c,closed:s,port:o}}),cc=null,lc=!1,uc=new Set,dc=[],fc=new Map,pc=!1,mc=!1,hc=e=>{let t=fc.get(e);t&&(fc.delete(e),t())},gc=(e,t)=>{try{e.postMessage({type:`fkn-packages-nack`,message:t})}catch{}try{e.close()}catch{}},_c=async(e,t)=>{let{port:n,...r}=e;e.port.addEventListener(`message`,t=>{t.data?.type===`fkn-packages-disconnect`&&hc(e.port)});let i;try{i=await t.createPayload(r)}catch(t){throw gc(e.port,t instanceof Error?t.message:`the package failed to produce a connection`),t}let a=new Promise(t=>fc.set(e.port,t)),o=await Ys(i,e.port);t.handler?.({...r,remote:o,closed:a,port:e.port})},vc=()=>{pc||typeof window>`u`||window.parent===window||(pc=!0,c(window,`message`,e=>{if(e.source!==window.parent)return;let t=e.data;if(t?.type===`fkn-packages-port`){let n=e.ports[0];if(!n)return;let r={port:n,from:typeof t.from==`string`?t.from:``,brokered:e.origin===Gs,protocol:typeof t.protocol==`string`?t.protocol:null,uri:typeof t.uri==`string`?t.uri:``,name:typeof t.name==`string`?t.name:``,version:typeof t.version==`string`?t.version:``};cc?_c(r,cc).catch(e=>console.warn(`packages.onConnect:`,e)):dc.push(r)}if(t?.type===`fkn-packages-close`)for(let e of[...fc.keys()])hc(e);if(t?.type===`fkn-packages-visibility`){lc=t.visible===!0;for(let e of uc)try{e(lc)}catch{}}}))},yc=()=>{mc||typeof window>`u`||window.parent===window||(mc=!0,window.parent.postMessage({type:`fkn-packages-ready`},`*`))},bc=(e,t)=>{if(typeof window>`u`)return{unsubscribe:()=>{}};vc();let n={createPayload:e,handler:t};for(cc=n,yc();dc.length&&cc===n;)_c(dc.shift(),n).catch(e=>console.warn(`packages.onConnect:`,e));return{unsubscribe:()=>{cc===n&&(cc=null)}}},xc=e=>{if(typeof window>`u`)return{unsubscribe:()=>{}};vc(),uc.add(e);try{e(lc)}catch{}return{unsubscribe:()=>{uc.delete(e)}}},Sc={default:6048e5,min:6e4,max:31536e6},Cc={notAFile:{code:`invalid`,message:`storage: the data is not a Blob or a ReadableStream`},badSize:{code:`invalid`,message:`storage: a stream needs the size it will deliver, a whole number of bytes`},shortStream:{code:`invalid`,message:`storage: the stream did not deliver the size it declared`},tooLarge:{code:`invalid`,message:`storage: the file is too large to store`},badKey:{code:`invalid`,message:`storage: the key is not 32 bytes base64url`},badUrl:{code:`invalid`,message:`storage: the url does not name a stored object`},badLimit:{code:`invalid`,message:`storage: the limit is out of range`},badCursor:{code:`invalid`,message:`storage: the cursor is not one list answered`},notFound:{code:`not-found`,message:`storage: no object at this url`},integrity:{code:`integrity`,message:`storage: the object does not match its key`},needsAccount:{code:`denied`,message:`storage: storing needs an account`},notCreator:{code:`denied`,message:`storage: only the app that stored the object can delete it`},quota:{code:`quota`,message:`storage: storage quota exceeded`},tooMany:{code:`too-many`,message:`storage: too many stored objects`},tooManyThisHour:{code:`too-many`,message:`storage: too many objects stored this hour, try again later`},accountChanged:{code:`account-changed`,message:`storage: the signed-in account changed`},unavailable:{code:`unavailable`,message:`storage: storage is unavailable`}},wc={wrongKey:`rooms: wrong room key`,inviteNoKey:`rooms: the invite carries no key`,badName:`rooms: the name is not one a room can have`,badKeyOption:`rooms: the key is not 32 bytes base64url`,noSuchMember:`rooms: no such member`,noSuchMessage:`rooms: no such message`,roomFull:`rooms: the room is full`,tooManyConnections:`rooms: too many connections`,tooManyBlocks:`rooms: too many blocks`,tooManyClaims:`rooms: too many claims`,mailboxFull:`rooms: the mailbox is full`,outOfStorage:`rooms: the owner is out of storage`,outOfQuota:`rooms: out of daily bandwidth`,blocked:`rooms: you are blocked from this room`,cannotSend:`rooms: you cannot send here`,permissionDenied:`rooms: permission denied`,notOwner:`rooms: not the room owner`,ownerNotRemovable:`rooms: the owner cannot be removed`,ownerKeepsEvery:`rooms: the owner keeps every permission`,removeYourself:`rooms: you cannot remove yourself`,needsAccount:`rooms: claiming needs an account`,nameClaimed:`rooms: the name is claimed`,notClaimed:`rooms: the room is not claimed`,noMailbox:`rooms: the room keeps no messages`,badLimit:`rooms: the limit is out of range`,badDescription:`rooms: the description is not one a claim can carry`,notClaimer:`rooms: only the app that claimed the room can describe it`,notReleaser:`rooms: only the app that claimed the room can release it`,notClaimingApp:`rooms: only the app that claimed the room can change it`,badTemporary:`rooms: the temporary duration is not one a claim can carry`,notTemporaryClaimer:`rooms: only the app that claimed the room can set when it expires`,temporaryUnavailable:`rooms: temporary claims are not available`,mailboxUnavailable:`rooms: the mailbox switch is not available`,guestUnavailable:`rooms: guest joins are not available`,schemasUnavailable:`rooms: room schemas are not available`,bytesUnavailable:`rooms: binary messages are not available`,badSchema:`rooms: the schema is not one a room can take`,newerSchema:`rooms: the room holds a newer schema`,noSchema:`rooms: the room has no schema`,misfit:`rooms: the message does not fit the room's schema`,ownerSends:`rooms: only the owner sends this type`,accountSends:`rooms: sending this needs an account`,perAccount:`rooms: you have as many of these here as the room allows`,tooFast:`rooms: sending too fast`,tooLarge:`rooms: the message is too large`,unavailable:`rooms: rooms are unavailable`,notEnabled:`rooms: rooms are not available`,alreadyJoined:`rooms: already joined`,notJoined:`rooms: not joined`,malformed:`rooms: malformed frame`,ended:`rooms: the room has ended`},W=(e,t)=>Object.assign(Error(t),{code:e}),Tc=e=>e instanceof Error&&typeof e.code==`string`,Ec={send:!0,receive:!0,maxMessageBytes:262144},Dc=2048,Oc=()=>({messages:0,bytes:0,cap:5e8,archived:!1}),kc=async()=>{if(!l)return;let e=(await oo(`a room`).catch(()=>void 0))?.rooms;return typeof e?.open==`function`?e:void 0},Ac=()=>{throw W(`unavailable`,wc.unavailable)},jc=e=>e===`blocked`?`blocked`:e===`not-found`?`ended`:`unavailable`,Mc=e=>{if(e!==void 0&&e!==!1)return e===!0?Sc.default:typeof e!=`number`||!Number.isInteger(e)?null:e>=Sc.min&&e<=Sc.max?e:null},Nc=(e,t)=>{let n=t?e?.guest:e;return typeof n?.join==`function`?n:void 0},Pc=e=>{let t;try{t=JSON.stringify(e)}catch{}let n=t===void 0?void 0:JSON.parse(t),r=typeof n==`object`&&!!n&&!Array.isArray(n)&&typeof n.type==`string`;if(t===void 0||!r||t.length>Dc)throw W(`invalid`,wc.misfit);return t},Fc=e=>{let t;try{t=JSON.parse(JSON.stringify(e))}catch{}if(typeof t!=`object`||!t||Array.isArray(t))throw W(`invalid`,wc.badSchema);return t},Ic=e=>e?.schema===void 0?e:{...e,schema:Fc(e.schema)},Lc=e=>{if(e.schemas!==!0)throw W(`unavailable`,wc.schemasUnavailable);return e},Rc=e=>{if(e.bytes!==!0)throw W(`unavailable`,wc.bytesUnavailable);return e},zc=e=>{if(typeof e==`string`)return e;try{return ArrayBuffer.isView(e)?new Uint8Array(e.buffer,e.byteOffset,e.byteLength).slice():(Reflect.get(ArrayBuffer.prototype,`byteLength`,e),new Uint8Array(e).slice())}catch{throw W(`invalid`,wc.malformed)}},Bc=(e,t,n)=>{let r=typeof t==`string`?e:Rc(e);return n===void 0?r:Lc(r)},Vc=e=>{let t=e?.guest;if(t!==void 0&&typeof t!=`boolean`)throw W(`invalid`,wc.malformed);return t===!0},Hc=async(e,t)=>{let n=e.invite,r=e,i=0,a=e.self,o=e.owner,s=e.claimed,c=e.mailbox,l=0,u=await e.defaults().catch(()=>Ec),d=e.schemas===!0?await Promise.resolve(e.schema()).catch(()=>null):null,f=0,p=!1,m=new Set,h=new Set,g=ds(`room`),_=()=>{},v=()=>{},y=new Promise(e=>{v=e}),b=e=>{let t=[...h];h.clear();for(let n of t)try{n(e)}catch{}},x=e=>{p||(p=!0,_(),m.clear(),g(),b(W(`closed`,wc.ended)),v({reason:e}))},S=e=>{if(p)return;let t=e;if(t.type===`defaults`&&(u=t.defaults),t.type===`schema`&&(f+=1,d=t.schema),t.type===`message`||t.type===`edited`){let e={...t.message,envelope:t.message.envelope??null};t=t.type===`message`?{...t,message:e}:{type:`edited`,message:e}}if(t.type===`permissions`&&t.id===a.id&&(a={id:a.id,permissions:t.permissions,maxMessageBytes:t.maxMessageBytes}),t.type===`claim`){l+=1;let e=t.claimed&&t.mailbox!==!1;t={type:`claim`,claimed:t.claimed,owner:t.owner,mailbox:e},s=t.claimed,o=t.owner,c=e?Oc():null}for(let e of[...m])try{e(t)}catch{}},C=(e,t)=>{Promise.resolve(e.on(S)).catch(()=>{}),Promise.resolve(e.closed).then(e=>{t===i&&x(e.reason)},()=>{})},w=async(e,l)=>{let f=Nc(e,t);if(!f)return x(`unavailable`);let m=await f.join(n).catch(()=>void 0);if(p||l!==i)return;if(!m)return x(`unavailable`);if(`error`in m)return x(jc(m.error));if(m.self.id!==a.id)return Promise.resolve(m.leave()).catch(()=>{}),x(`unavailable`);r=m,a=m.self,o=m.owner,s=m.claimed,c=m.mailbox,C(m,l);let h=await m.defaults().catch(()=>void 0);if(h&&!p&&l===i&&(u=h),m.schemas!==!0)return;let g=await Promise.resolve(m.schema()).catch(()=>void 0);g!==void 0&&!p&&l===i&&(d=g)};_=so((e,t)=>{let n=i;i=t,!(p||n===0||n===t)&&(b(W(`unavailable`,wc.unavailable)),w(e.rooms,t))}),C(e,i);let T=async e=>{if(p)throw W(`closed`,wc.ended);let t=()=>{},n=new Promise((e,n)=>{t=n});h.add(t);try{return await Promise.race([Promise.resolve(e(r)),n])}catch(e){throw Tc(e)?e:W(`unavailable`,wc.unavailable)}finally{h.delete(t)}},E=async e=>{let t=await T(e);if(`error`in t)throw W(t.error,t.message)},D=async e=>{let t=await T(e);if(typeof t==`object`&&t&&`error`in t)throw W(t.error,t.message);return t};return{id:e.id,name:e.name,key:e.key,invite:n,get self(){return a},get owner(){return o},get claimed(){return s},get mailbox(){return c},defaults:()=>u,members:()=>T(e=>e.members()),schema:()=>d,send:async(e,t)=>{let n=zc(e);if(t===void 0)return E(e=>Bc(e,n,void 0).send(n));let r=Pc(t);return E(e=>Bc(e,n,r).send(n,r))},edit:async(e,t,n)=>{let r=zc(t);if(n===void 0)return E(t=>Bc(t,r,void 0).edit(e,r));let i=Pc(n);return E(t=>Bc(t,r,i).edit(e,r,i))},setSchema:async e=>{let t=Fc(e),n=f;await E(e=>Lc(e).setSchema(t)),f===n&&(d=t)},delete:(e,t)=>E(n=>n.delete(e,t)),backlog:(e,t)=>D(n=>n.backlog(e,t)),setDefault:(e,t)=>E(n=>n.setDefault(e,t)),limit:(e,t)=>E(n=>n.limit(e,t)),grant:(e,t)=>E(n=>n.grant(e,t)),revoke:(e,t)=>E(n=>n.revoke(e,t)),remove:e=>E(t=>t.remove(e)),block:e=>E(t=>t.block(e)),unblock:e=>E(t=>t.unblock(e)),claim:async e=>{let t=e?.description;if(t!==void 0&&typeof t!=`string`)throw W(`invalid`,wc.badDescription);let n=Mc(e?.temporary);if(n===null)throw W(`invalid`,wc.badTemporary);let r=e?.mailbox;if(r!==void 0&&typeof r!=`boolean`)throw W(`invalid`,wc.malformed);let i={...t===void 0?{}:{description:t},...n===void 0?{}:{temporary:n},...r===void 0?{}:{mailbox:r}};return Object.keys(i).length===0?E(e=>e.claim()):E(e=>{if(n!==void 0&&e.temporaryClaims!==!0)throw W(`unavailable`,wc.temporaryUnavailable);if(r===!1&&e.mailboxSwitch!==!0)throw W(`unavailable`,wc.mailboxUnavailable);return e.claim(i)})},setMailbox:async e=>{if(typeof e!=`boolean`)throw W(`invalid`,wc.malformed);let t=l;await E(t=>{if(t.mailboxSwitch!==!0)throw W(`unavailable`,wc.mailboxUnavailable);return t.setMailbox(e)}),l===t&&(e?c===null&&(c=Oc()):c=null)},release:()=>E(e=>e.release()),usage:async()=>{let e=await D(e=>e.usage());return c=e,e},on:async e=>p?()=>{}:(m.add(e),()=>{m.delete(e)}),leave:async()=>{await Promise.resolve(r.leave()).catch(()=>{}),x(`left`)},closed:y}},Uc=async(e,t,n)=>{let r=await kc();if(!r)throw W(`unavailable`,wc.unavailable);let i=Nc(r,e);if(!i)throw W(`unavailable`,wc.guestUnavailable);let a=await n(i).catch(Ac);if(`error`in a)throw W(a.error,a.message);if(t?.schema!==void 0&&a.schemas!==!0)throw await Promise.resolve(a.leave()).catch(()=>{}),W(`unavailable`,wc.schemasUnavailable);return Hc(a,e)},Wc=async(e,t)=>{if(typeof e!=`string`||e.length===0||e.length>72)throw W(`invalid`,wc.badName);let n=Vc(t),r=Ic(t);return Uc(n,r,t=>t.open(e,r))},Gc=async e=>{let t=Vc(e),n=Ic(e);return Uc(t,n,e=>e.create(n))},Kc=async(e,t)=>{let n=typeof e==`string`?e.indexOf(`.`):-1;if(n<=0||n===e.length-1)throw W(`invalid`,wc.inviteNoKey);return Uc(Vc(t),void 0,n=>n.join(e,t))},qc=e=>{if(!e)return{signal:void 0,release:()=>{}};let t=new AbortController,n=()=>t.abort(e.reason);return e.aborted?n():e.addEventListener(`abort`,n,{once:!0}),{signal:t.signal,release:()=>{e.removeEventListener(`abort`,n),t.abort()}}},Jc=new Map(Object.values(Cc).map(({code:e,message:t})=>[t,e])),Yc=new Set(Jc.values()),Xc=(e,t)=>Object.assign(Error(t),{code:e}),Zc=e=>Xc(Cc[e].code,Cc[e].message),Qc=e=>e instanceof Error&&Yc.has(e.code),$c=e=>{if(Qc(e))return e;let t=e instanceof Error?e.message:``,n=Jc.get(t);return n?Xc(n,t):Zc(`unavailable`)},el=async()=>{if(!l)return;let e=(await oo(`storage`).catch(()=>void 0))?.storage;return typeof e?.put==`function`?e:void 0},tl=()=>{throw Zc(`unavailable`)},nl=e=>typeof e==`object`&&!!e&&typeof e.error==`string`&&typeof e.message==`string`,rl=(e,t,n)=>{throw e.error===`aborted`?t?.reason??new DOMException(`The operation was aborted.`,`AbortError`):(e.error===`account-changed`&&n&&xo(n.generation),Yc.has(e.error)?Xc(e.error,e.message):Zc(`unavailable`))},il=async e=>{try{return await Wo(e)}catch(e){throw Po(e)?Zc(`accountChanged`):e instanceof Error&&/not connected|not signed in/i.test(e.message)?Zc(`needsAccount`):Zc(`unavailable`)}},al=async(e,t)=>{if(!e)return t();let{signal:n,release:r}=qc(e);try{return await Promise.race([t(n),new Promise((t,r)=>n.addEventListener(`abort`,()=>r(e.reason),{once:!0}))])}finally{r()}},ol=async(e,t={})=>{let n=Lo(),{signal:r,onProgress:i,key:a}=t;r?.throwIfAborted();let o=typeof Blob<`u`&&e instanceof Blob,s=typeof ReadableStream<`u`&&e instanceof ReadableStream;if(!o&&!s)throw Zc(`notAFile`);let c=o?e.size:t.size;if(typeof c!=`number`||!Number.isSafeInteger(c)||c<0||o&&t.size!==void 0&&t.size!==c)throw Zc(`badSize`);let l=await el();if(!l)throw Zc(`unavailable`);let u=await il(n);r?.throwIfAborted();let d=await al(r,t=>Promise.resolve(l.put(e,{size:c,...a===void 0?{}:{key:a},accountPin:u,...t?{signal:t}:{},...typeof i==`function`?{onProgress:e=>{try{i(e)}catch{}}}:{}})).catch(tl));return nl(d)?rl(d,r,n):d},sl=(e,t,n)=>{let r=(t,n)=>{if(t===void 0)return n;let r=Math.trunc(Number.isFinite(t)?t:t>0?e:-e);return r<0?Math.max(e+r,0):Math.min(r,e)},i=r(t,0);return{from:i,to:Math.max(i,r(n,e))}},cl=async(e,t,n={})=>{if(typeof e!=`string`)throw Zc(`badUrl`);if(typeof t!=`string`)throw Zc(`badKey`);let{signal:r}=n;r?.throwIfAborted();let i=async()=>{let n=await el();if(!n)throw Zc(`unavailable`);let i=co()?.epoch,a=await al(r,r=>Promise.resolve(n.get(e,t,r?{signal:r}:void 0)).catch(tl));return nl(a)?rl(a,r):{handle:a,epoch:i}},a=await i(),o=async()=>{let e=co()?.epoch;return a.epoch!==void 0&&e!==void 0&&e!==a.epoch&&(a=await i()),a.handle},s=e=>{if(!r)return()=>{};let t=()=>{e.cancel(r.reason).catch(()=>{})};return r.aborted?t():r.addEventListener(`abort`,t,{once:!0}),()=>r.removeEventListener(`abort`,t)},c=(e,t)=>{let n,i=()=>{};return new ReadableStream({pull:async a=>{try{if(!n){r?.throwIfAborted();let a=await o(),c=await Promise.resolve(a.read(e,t)).catch(tl);if(nl(c))return rl(c);n=c.getReader(),i=s(n)}let{value:c,done:l}=await n.read();r?.throwIfAborted(),l?(i(),a.close()):a.enqueue(c)}catch(e){throw i(),r?.aborted?(n?.cancel(r.reason).catch(()=>{}),r.reason):$c(e)}},cancel:e=>(i(),n?.cancel(e))},{highWaterMark:0})},l=(e,t)=>({size:t-e,stream:()=>c(e,t),arrayBuffer:async()=>{let n=new Uint8Array(t-e),r=c(e,t).getReader(),i=0;for(;;){let{value:e,done:t}=await r.read();if(t)break;n.set(e,i),i+=e.length}return n.buffer},slice:(n,r)=>{let i=sl(t-e,n,r);return l(e+i.from,e+i.to)}});return l(0,a.handle.size)},ll=async(e={})=>{let t=Lo(),n=await el();if(!n)throw Zc(`unavailable`);let r=await il(t),{limit:i,cursor:a}=e,o=await Promise.resolve(n.list({accountPin:r,...i===void 0?{}:{limit:i},...a===void 0?{}:{cursor:a}})).catch(tl);return nl(o)?rl(o,void 0,t):o},ul=async e=>{let t=Lo();if(typeof e!=`string`)throw Zc(`badUrl`);let n=await el();if(!n)throw Zc(`unavailable`);let r=await il(t),i=await Promise.resolve(n.delete(e,{accountPin:r})).catch(tl);nl(i)&&rl(i,void 0,t)},G,dl,fl,pl,ml,hl,gl,_l,vl,yl,bl=Symbol.for(`pv`),xl={},Sl=[],Cl=/^m(i|n|o|s|text|space)$/,wl=Array.isArray,Tl=Sl.slice,El=Object.assign;function Dl(e){e&&e.parentNode&&e.remove()}function Ol(e,t,n,r,i){var a={type:e,props:t,key:n,ref:r,__k:null,__:null,__b:0,__e:null,__c:null,constructor:bl,__v:i||++dl,__i:-1,__u:0};return!i&&G.vnode&&G.vnode(a),a}function K(e){return e.children}function kl(e,t){this.props=e,this.context=t,this.__g=0}function Al(e,t){if(t==null)return e.__&&Al(e.__,e.__i+1);for(var n;t<e.__k.length;t++)if((n=e.__k[t])&&n.__e)return n.__e;return typeof e.type!=`function`||e.props.__P?null:Al(e)}function jl(e){var t,n=e.__v,r=n.__e,i=[],a=[],o=e.__P;o&&((t=El({constructor:bl},n)).__v=n.__v+1,G.vnode&&G.vnode(t),Ul(o,t,n,e.__n,o.namespaceURI,32&n.__u?[r]:null,i,r||Al(n),32&n.__u,a),t.__v=n.__v,t.__.__k[t.__i]=t,Kl(i,t,a),n.__=n.__e=null,t.__e!=r&&Ml(t))}function Ml(e){if((e=e.__)&&e.__c&&!e.props.__P)return e.__e=null,e.__k.some(function(t){return t&&(e.__e=t.__e)}),Ml(e)}function Nl(e){(8&e.__g||(e.__g|=8,fl.push(e),ml++))&&pl==G.debounceRendering||((pl=G.debounceRendering)||queueMicrotask)(Pl)}function Pl(){try{for(var e,t=1;fl.length;)fl.length>t&&fl.sort(hl),e=fl.shift(),t=fl.length,8&e.__g&&jl(e)}finally{(ml=fl.length)&&(pl||queueMicrotask)(Pl)}}function Fl(e,t,n,r,i,a,o,s,c,l,u){var d,f,p,m,h,g,_=r.__k||Sl,v=t.length;for(c=Il(n,t,_,c,v),d=0;d<v;d++)(p=n.__k[d])!=null&&(f=~p.__i&&_[p.__i]||xl,p.__i=d,g=Ul(e,p,f,i,a,o,s,c,l,u),m=p.__e,(f.ref!=p.ref||8&f.__u)&&(f.ref&&Jl(f.ref,null,p,f),p.ref&&u.push(p.ref,p.__c||m,p)),h||=m,4&p.__u?(c=Ll(p,c,e,!f.__v),f.__e&&(f.__e=null)):typeof p.type==`function`&&g!==void 0?c=g:m&&(c=m.nextSibling),p.__u&=-21);return n.__e=h,c}function Il(e,t,n,r,i){var a,o,s,c,l,u,d,f,p,m=n.length,h=m,g=0,_=0,v=e.__k=Array(i);for(a=0;a<i;a++)(o=t[a])!=null&&typeof o!=`boolean`&&typeof o!=`function`?(typeof o!=`object`||o.constructor===String?o=v[a]=Ol(null,o):wl(o)?o=v[a]=Ol(K,{children:o}):o.constructor===bl&&o.__b?o=v[a]=Ol(o.type,o.props,o.key,o.ref,o.__v):v[a]=o,c=a+g,o.__=e,o.__b=e.__b+1,s=null,~(l=o.__i=zl(o,n,c,h))&&(h--,(s=n[l])&&(s.__u|=2)),s&&s.__v?(o.__u|=16,l==c-1?g--:l==c+1?g++:l!=c&&(l>c?g--:g++,_=1)):(~l||(i>m?g--:i<m&&g++),typeof o.type!=`function`&&(o.__u|=4))):v[a]=null;if(_){for(u=[],d=[],a=0;a<i;a++)if((o=v[a])&&16&o.__u){for(g=0,f=u.length;g<f;)u[p=g+f>>1]<o.__i?g=p+1:f=p;u[g]=o.__i,d[a]=g+1}for(g=u.length;a--;)d[a]&&(d[a]==g?g--:v[a].__u|=4)}if(h)for(a=0;a<m;a++)!(s=n[a])||2&s.__u||(s.__e==r&&(r=Al(s)),Yl(s,s));return r}function Ll(e,t,n,r){var i,a,o,s;if(typeof e.type==`function`){if(e.props.__P)return t;if(i=e.__k)for(a=0;a<i.length;a++)i[a]&&(i[a].__=e,t=Ll(i[a],t,n,!1));return t}for(t&&!t.parentNode&&(t=Al(e))&&!t.parentNode&&(t=null),o=e.__e,s=t;s&&s.nodeType==8;)s=s.nextSibling;for(o!=s&&(!r&&n.moveBefore&&o.parentNode?n.moveBefore(o,t):n.insertBefore(o,t||null)),t=o;(t&&=t.nextSibling)&&t.nodeType==8&&!t.data.startsWith(`$s`););return t}function Rl(e,t){return t||=[],e!=null&&typeof e!=`boolean`&&(wl(e)?e.some(function(e){Rl(e,t)}):t.push(e)),t}function zl(e,t,n,r){var i,a=e.key,o=e.type,s=t[n],c=s&&!(2&s.__u);if(s===null&&a==null||c&&a==s.key&&o==s.type)return n;if(r>+!!c){for(i=n-1;i>=0;i--)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i;for(i=n+1;i<t.length;i++)if((s=t[i])&&!(2&s.__u)&&a==s.key&&o==s.type)return i}return-1}function Bl(e,t,n){n??=``,t[0]==`-`?e.setProperty(t,n):e[t]=n}function Vl(e,t,n,r,i){var a,o;if(t==`style`){if(typeof n==`string`)e.style.cssText=n;else{if(typeof r==`string`&&(e.style.cssText=r=``),r)for(t in r)n&&t in n||Bl(e.style,t);if(n)for(t in n)r&&n[t]==r[t]||Bl(e.style,t,n[t])}}else if(t[0]==`o`&&t[1]==`n`)typeof n!=`function`&&(n=null),typeof r!=`function`&&(r=null),(e.__e||={})[t]=n,n&&r||(o=yl[t]||(yl[t]=Hl(t)),(e.__a||={})[t]=vl,a=t!=(t=t.replace(_l,`$1`)),(t=t.slice(2))[0]<`a`&&(t=t.toLowerCase()),n?e.addEventListener(t,o,a):e.removeEventListener(t,o,a));else{if(i==`http://www.w3.org/2000/svg`)t=t.replace(/xlink(H|:h)/,`h`).replace(/sName$/,`s`);else if(t!=`width`&&t!=`height`&&t!=`href`&&t!=`list`&&t!=`form`&&t!=`tabIndex`&&t!=`download`&&t!=`rowSpan`&&t!=`colSpan`&&t!=`role`&&t!=`popover`&&t in e)try{e[t]=n??``;return}catch{}if(typeof n==`function`)return;n==null||!1===n&&t[4]!=`-`?e.removeAttribute(t):e.setAttribute(t,t==`popover`&&n==1?``:n)}}function Hl(e){return function(t){var n=this.__e;if(n){if(n=n[e],t[gl]==null)t[gl]=vl++;else if(t[gl]<this.__a[e])return;return n(G.event?G.event(t):t)}}}function Ul(e,t,n,r,i,a,o,s,c,l){var u,d,f,p,m,h,g,_,v,y,b,x,S,C,w,T,E,D,O=t.type;if(t.constructor!==bl)return null;128&n.__u&&(c=32&n.__u,u=n.__c.__z)&&(t.__u|=c,d=a=[],u.nodeType==8?s=Wl(u,a):a.push(u),s=a[0]||s),(u=G.__b)&&u(t);n:if(typeof O==`function`){f=o.length;try{if(_=t.props,v=(u=O.prototype)&&u.render,y=(u=O.contextType)&&r[u.__c],b=u?y?y.props.value:u.__:r,(p=n.__c)?(t.__c=p,2&p.__g&&(p.__g|=1)):(v?t.__c=p=new O(_,b):(t.__c=p=new kl(_,b),p.constructor=O,p.render=Xl),y&&y.sub(p),p.state||(p.state={}),p.__n=r,p.__g|=8,p.__h=[],p.__k=[]),v&&(p.__s||(p.__s=p.state),O.getDerivedStateFromProps&&(p.__s==p.state&&(p.__s=El({},p.__s)),El(p.__s,O.getDerivedStateFromProps(_,p.__s)))),m=p.props,h=p.state,p.__v=t,n.__c){if(_!==m&&v&&!O.getDerivedStateFromProps&&p.componentWillReceiveProps&&p.componentWillReceiveProps(_,b),t.__v==n.__v&&!(8&p.__g)||!(4&p.__g)&&p.shouldComponentUpdate&&!1===p.shouldComponentUpdate(_,p.__s,b)){t.__v!=n.__v&&(p.props=_,p.state=p.__s,p.__g&=-9),t.__e=n.__e,t.__k=n.__k,t.__k.some(function(e){e&&(e.__=t)}),Sl.push.apply(p.__h,p.__k),p.__k=[],p.__h.length&&o.push(p),s=Al(n);break n}p.componentWillUpdate&&p.componentWillUpdate(_,p.__s,b),v&&p.componentDidUpdate&&p.__h.push(function(){p.componentDidUpdate(m,h,g)})}else v&&!O.getDerivedStateFromProps&&p.componentWillMount&&p.componentWillMount(),v&&p.componentDidMount&&p.__h.push(p.componentDidMount);p.context=b,p.props=_,p.__P=e,p.__g&=-5,x=G.__r,S=v?25:0;do p.__g&=-9,x&&x(t),u=p.render(p.props,p.state=p.__s,p.context);while(8&p.__g&&++S<25);v&&(Sl.push.apply(p.__h,p.__k),p.__k=[]),p.state=p.__s,p.getChildContext&&(r=El({},r,p.getChildContext())),v&&n.__c&&p.getSnapshotBeforeUpdate&&(g=p.getSnapshotBeforeUpdate(m,h)),C=u&&u.type===K&&u.key==null?u.props.children:u,_.__P&&(u=s,i=(e=_.__P).namespaceURI,c=a=null,n.props&&n.props.__P!=e&&(n.__k.some(function(e){e&&Yl(e,e)}),n.__k=null),s=n.__k?Al(n,0):null),s=Fl(e,wl(C)?C:[C],t,n,r,i,a,o,s,c,l),_.__P&&(t.__e=null,s=u),t.__u&=-161,d&&d.some(Dl),p.__h.length&&o.push(p),1&p.__g&&(p.__g&=-4)}catch(e){if(o.length=f,t.__v=null,c||a){if(e&&e.then){if(t.__u|=128|c,a){for(~(E=a.indexOf(s||void 0))||(E=a.length);(D=a[E-1])&&D.nodeType==8;)E--;for(;E<a.length;E++)if(D=a[E]){if(a[E]=null,w){if(D==T)break}else{if(D.nodeType!=8)break;D.data.startsWith(`$s`)&&(T=Wl(w=D))}}}if(!w){for(;s&&s.nodeType==8&&s.nextSibling;)s=s.nextSibling;w=s}(u=Wl(w=t.__c.__z||(t.__c.__z=w)))?(t.__e=w,s=u):t.__e=s,s&&=s.nextSibling}else a&&a.some(Dl)}else t.__e=n.__e;t.__k||=n.__k||[],e&&e.then||Gl(t),G.__e(e,t,n)}}else s=t.__e=ql(n.__e,t,n,r,i,a,o,c,l,e);return(u=G.diffed)&&u(t),s}function Wl(e,t){if(e&&e.nodeType==8&&e.data.startsWith(`$s`))for(var n=1;e=e.nextSibling;){if(e.nodeType==8){if(e.data.startsWith(`$s`))n++;else if(e.data.startsWith(`/$s`)&&!--n)return e}t&&t.push(e)}}function Gl(e){e&&(e.__c&&(e.__c.__g|=4),e.__k&&e.__k.some(Gl))}function Kl(e,t,n){for(var r=0;r<n.length;)Jl(n[r++],n[r++],n[r++]);G.__c&&G.__c(t,e),e.some(function(t){try{e=t.__h,t.__h=[],e.some(function(e){e.call(t)})}catch(e){G.__e(e,t.__v)}})}function ql(e,t,n,r,i,a,o,s,c,l){var u,d,f,p,m,h,g,_,v=n.props||xl,y=t.props,b=t.type;if(b==`svg`?i=`http://www.w3.org/2000/svg`:b==`math`?i=`http://www.w3.org/1998/Math/MathML`:i||=`http://www.w3.org/1999/xhtml`,a){for(u=0;u<a.length;u++)if((m=a[u])&&(b?m.localName==b:m.nodeType==3)){e=m,a[u]=null;break}}if(!e){if(_=l.ownerDocument||document,!b)return _.createTextNode(y);e=_.createElementNS(i,b,y.is?y:l),s&&=(G.__m&&G.__m(t,a),!1),a=null}if(b){if(l=b==`template`&&e.content||e,a=b==`textarea`&&y.defaultValue!=null?null:a&&Tl.call(l.childNodes),!s&&a)for(v={},u=0;u<e.attributes.length;u++)v[(m=e.attributes[u]).name]=m.value;for(u in v)m=v[u],u==`dangerouslySetInnerHTML`?f=m:u==`children`||u in y||u==`value`&&`defaultValue`in y||u==`checked`&&`defaultChecked`in y||Vl(e,u,null,m,i);for(u in y)m=y[u],u==`children`?p=m:u==`dangerouslySetInnerHTML`?d=m:u==`value`?h=m:u==`checked`?g=m:s&&typeof m!=`function`||v[u]===m||Vl(e,u,m,v[u],i);d?(s||f&&(d.__html==f.__html||d.__html==e.innerHTML)||(e.innerHTML=d.__html),t.__k=[]):(f&&(e.textContent=``),(b==`foreignObject`||i==`http://www.w3.org/1998/Math/MathML`&&Cl.test(b))&&(i=`http://www.w3.org/1999/xhtml`),Fl(l,wl(p)?p:[p],t,n,r,i,a,o,a?a[0]:n.__k&&Al(n,0),s,c),a&&a.some(Dl)),s&&b!=`textarea`||(u=`value`,b==`progress`&&h==null?e.removeAttribute(u):h==null||h===e[u]&&(b!=`progress`||h)||Vl(e,u,h,v[u],i),u=`checked`,g!=null&&g!=e[u]&&Vl(e,u,g,v[u],i))}else v===y||s&&e.data==y||(e.data=y);return e}function Jl(e,t,n,r){try{typeof e==`function`?t?t.__x=e(t)||1:(r&&=r.__c||r.__e)&&(t=r.__x)&&(r.__x=null,typeof t==`function`?t():e(null)):e.current=t}catch(e){G.__e(e,n)}}function Yl(e,t,n){var r,i,a,o;if(G.unmount&&G.unmount(e),!(r=e.ref)||r.current&&r.current!=e.__e||Jl(r,null,t,e),r=e.__c){if(r.componentWillUnmount)try{r.componentWillUnmount()}catch(e){G.__e(e,t)}r.__P=r.__n=null}if(r=e.__k)for(o=0;o<r.length;o++)r[o]&&Yl(r[o],t,typeof e.type!=`function`||n&&!e.props.__P);!n&&(r=e.__c)&&(r=r.__z)&&(i=Wl(r,a=[]))&&(r==e.__e&&a.some(Dl),Dl(i),Dl(r)),n||Dl(e.__e),e.__e=e.__c=e.__=null}function Xl(e,t,n){return this.constructor(e,n)}function Zl(e,t){var n,r,i,a;G.__&&G.__(e,t),t.nodeType==9&&(t=t.documentElement),r=(n=e&&32&e.__u)?null:t.__k,t.__k=Ol(K,{children:[e]}),i=[],a=[],Ul(t,t.__k,r||xl,xl,t.namespaceURI,r?null:t.firstChild?Tl.call(t.childNodes):null,i,r?r.__e:t.firstChild,n,a),Kl(i,t.__k,a),t.__k.props.children=null}G={__e:function(e,t,n,r){for(var i,a,o;t=t.__;)if((i=t.__c)&&!(1&i.__g)){i.__g|=4;try{if((o=(a=i.constructor)&&a.getDerivedStateFromError)&&i.setState(a.getDerivedStateFromError(e)),i.componentDidCatch&&(i.componentDidCatch(e,r||{}),o=1),o&&8&i.__g)return void(i.__g|=2)}catch(t){e=t}}throw ml=0,e}},dl=0,kl.prototype.setState=function(e,t){var n=this.__s;n&&n!=this.state||(n=this.__s=El({},this.state)),typeof e==`function`&&(e=e(El({},n),this.props)),e&&(El(n,e),this.__v&&(t&&this.__k.push(t),Nl(this)))},kl.prototype.forceUpdate=function(e){this.__v&&(this.__g|=4,e&&this.__h.push(e),Nl(this))},kl.prototype.render=K,fl=[],ml=0,hl=function(e,t){return e.__v.__b-t.__v.__b},gl=Symbol(),_l=/(PointerCapture)$|Capture$/i,vl=0,yl={};var Ql,$l,eu,tu,nu=Object.is,ru=0,iu=[],au=[],ou=G,su=ou.__b,cu=ou.__r,lu=ou.diffed,uu=ou.__c,du=ou.unmount,fu=ou.__;function pu(e,t){ou.__h&&ou.__h($l,e,ru||t),ru=0;var n=$l.__H||($l.__H={__:[],__h:[]});return e>=n.__.length&&n.__.push({}),n.__[e]}function q(e){return ru=1,mu(Eu,e)}function mu(e,t,n){var r=pu(Ql++,2);if(r.t=e,!r.__c&&(r.__=[n?n(t):Eu(void 0,t),function(e){var t=(r.__N||r.__)[0],n=r.t(t,e);nu(t,n)||(r.__N=[n,r.__[1]],r.__c.setState({}))}],r.__c=$l,!$l.__f)){$l.__f=!0;var i=$l.shouldComponentUpdate;$l.shouldComponentUpdate=function(e,t,n){var r=this.__H;if(!r)return!0;var a=!1,o=this.props!=e;if(r.__.some(function(e){e.__N&&(a=!0,nu(e.__[0],e.__N[0])||(o=!0))}),i){var s=i.call(this,e,t,n);return a?s||o:s}return!a||o}}return r.__}function hu(e,t){var n=pu(Ql++,3);!ou.__s&&Tu(n.__H,t)&&(n.__P=!0,n.__=e,n.u=t,$l.__H.__h.push(n))}function gu(e,t){var n=pu(Ql++,4);!ou.__s&&Tu(n.__H,t)&&(n.__P=!1,n.__=e,n.u=t,$l.__h.push(n))}function J(e){return ru=5,_u(function(){return{current:e}},[])}function _u(e,t){var n=pu(Ql++,7);return Tu(n.__H,t)&&(n.__=e(),n.__H=t),n.__}function vu(e,t){return ru=8,_u(function(){return e},t)}function yu(){var e;do{for(;e=au.shift();)try{Cu(e)}catch(t){ou.__e(t,{__:(e=e.__P)&&e.__v})}for(;e=iu.shift();){var t=e.__H;if(e.__P&&t)try{t.__h.some(Cu),t.__h.some(wu),t.__h=[]}catch(n){t.__h=[],ou.__e(n,e.__v)}}}while(au.length)}ou.__b=function(e){$l=null,su&&su(e)},ou.__=function(e,t){e&&t.__k&&t.__k.__m&&(e.__m=t.__k.__m),fu&&fu(e,t)},ou.__r=function(e){cu&&cu(e),Ql=0;var t=($l=e.__c).__H;t&&(eu==$l?$l.__h=[]:(t.__h.some(Cu),t.__h.some(wu),Ql=0),t.__h=[],t.__.some(function(e){e.__N&&(e.__=e.__N),e.u=e.__N=void 0})),eu=$l},ou.diffed=function(e){lu&&lu(e);var t=e.__c;t&&t.__H&&(t.__H.__h.length&&Su(iu.push(t)),t.__H.__.some(function(e){e.u&&(e.__H=e.u)})),eu=$l=null},ou.__c=function(e,t){t.some(function(e){try{e.__h.some(Cu),e.__h=e.__h.filter(function(e){return!e.__||wu(e)})}catch(t){e.__h=[function(){throw t}]}}),uu&&uu(e,t)},ou.unmount=function(e){du&&du(e);var t,n,r=e.__c;r&&r.__H&&(r.__H.__.some(function(r){try{if(r.__P&&r.__c){if(n===void 0){for(n=e.__;n&&(!n.__c||!n.__c.__P);)n=n.__;n&&=n.__c}r.__P=n,Su(au.push(r))}else Cu(r)}catch(e){t=e}}),r.__H=void 0,t&&ou.__e(t,r.__v))};var bu=typeof requestAnimationFrame==`function`;function xu(e){var t,n=function(){clearTimeout(r),bu&&cancelAnimationFrame(t),setTimeout(e)},r=setTimeout(n,35);bu&&(t=requestAnimationFrame(n))}function Su(e){e!=1&&tu==ou.requestAnimationFrame||((tu=ou.requestAnimationFrame)||xu)(yu)}function Cu(e){var t=$l,n=e.__c;typeof n==`function`&&(e.__c=void 0,n()),$l=t}function wu(e){var t=$l;e.__c=e.__(),$l=t}function Tu(e,t){return!e||e.length!=t.length||t.some(function(t,n){return!nu(t,e[n])})}function Eu(e,t){return typeof t==`function`?t(e):t}var Du=Object.assign,Ou=/^(-|f[lo].*[^se]$|g.{5,}[^ps]$|z|o[pr]|(W.{5})?[lL]i.*(t|mp)$|an|(bo|s).{4}Im|sca|m.{6}[ds]|ta|c.*[st]$|wido|ini|asp|fill|st)/,ku=Symbol.for(`react.element`),Au=/^(?:accent|alignment|arabic|baseline|cap|clip(?!PathU)|color|dominant|fill|flood|font|glyph(?!R)|horiz|image(?!S)|letter|lighting|marker(?!H|W|U)|overline|paint|pointer|shape|stop|strikethrough|stroke|text(?!L)|transform|underline|unicode|units|v|vector|vert|word|writing|x(?!C))[A-Z]/,ju=/[A-Z0-9]/g,Mu=typeof document<`u`,Nu=function(e){return/fil|che|rad/.test(e)};function Pu(e,t,n){return t.__k??(t.textContent=``),Zl(e,t),typeof n==`function`&&n(),e?e.__c:null}kl.prototype.isReactComponent=!0,[`componentWillMount`,`componentWillReceiveProps`,`componentWillUpdate`].forEach(function(e){Object.defineProperty(kl.prototype,e,{configurable:!0,get:function(){return this[`UNSAFE_`+e]},set:function(t){Object.defineProperty(this,e,{configurable:!0,writable:!0,value:t})}})});var Fu=G.event;G.event=function(e){return Fu&&(e=Fu(e)),e.persist=function(){},e.isPropagationStopped=function(){return this.cancelBubble},e.isDefaultPrevented=function(){return this.defaultPrevented},e.nativeEvent=e};var Iu={configurable:!0,get:function(){return this.class}},Lu=G.vnode;G.vnode=function(e){if(typeof e.type==`string`)(function(e){var t=e.props,n=e.type,r={},i=n.indexOf(`-`)==-1;for(var a in t){var o=t[a];if(!(a==`value`&&`defaultValue`in t&&o==null||Mu&&a==`children`&&n==`noscript`||a==`class`||a==`className`)){if(a==`style`&&o&&o.constructor==Object){var s=void 0;for(var c in o)typeof o[c]!=`number`||Ou.test(c)||(s||=o=Du({},o),o[c]+=`px`)}else if(a==`defaultValue`&&`value`in t&&t.value==null)a=`value`;else if(a==`download`&&!0===o)o=``;else if(a==`translate`&&o===`no`)o=!1;else if(a[0]==`o`&&a[1]==`n`){var l=a.toLowerCase();l==`ondoubleclick`?a=`ondblclick`:l!=`onchange`||n!=`input`&&n!=`textarea`||Nu(t.type)?l==`onfocus`?a=`onfocusin`:l==`onblur`&&(a=`onfocusout`):l=a=`oninput`,l==`oninput`&&r[a=l]&&(a=`oninputCapture`)}else i&&Au.test(a)?a=a.replace(ju,`-$&`).toLowerCase():o===null&&(o=void 0);r[a]=o}}if(n==`select`){var u=r.defaultValue==null?r.multiple&&Array.isArray(r.value)?r.value:null:r.defaultValue;u!=null&&(r.value=Rl(t.children).forEach(function(e){e.props.selected=r.multiple?u.indexOf(e.props.value)!=-1:u==e.props.value}))}t.class&&!t.className?(r.class=t.class,Object.defineProperty(r,"className",Iu)):t.className&&(r.class=r.className=t.className),e.props=r})(e);else if(typeof e.type==`function`&&(`ref`in e.props&&`prototype`in e.type&&e.type.prototype.render&&(e.ref=e.props.ref,delete e.props.ref),e.type.defaultProps)){var t=Du({},e.props);for(var n in e.type.defaultProps)t[n]===void 0&&(t[n]=e.type.defaultProps[n]);e.props=t}e.ref&&!(`ref`in e.props)&&Object.defineProperty(e.props,"ref",{value:e.ref,configurable:!0,writable:!0}),e.$$typeof=ku,Lu&&Lu(e)};function Ru(e){return!!e.__k&&(Zl(null,e),!0)}function zu(e){return{render:function(t){Pu(t,e)},unmount:function(){Ru(e)}}}var Bu={BASE_URL:`/`,DEV:!1,MODE:`production`,PROD:!0,SSR:!1},Vu=Bu.VITE_SOCIAL_SITE??`https://social.fkn.app`,Hu=Bu.VITE_SOCIAL_PACKAGE??`https:social.fkn.app`;Bu.VITE_FKN_ORIGIN;var Uu=BigInt(2**32-1),Wu=BigInt(32);function Gu(e,t=!1){return t?{h:Number(e&Uu),l:Number(e>>Wu&Uu)}:{h:Number(e>>Wu&Uu)|0,l:Number(e&Uu)|0}}function Ku(e,t=!1){let n=e.length,r=new Uint32Array(n),i=new Uint32Array(n);for(let a=0;a<n;a++){let{h:n,l:o}=Gu(e[a],t);[r[a],i[a]]=[n,o]}return[r,i]}var qu=e=>e/2**32|0,Ju=e=>e>>>0;function Yu(e,t,n,r){let i=qu(n),a=Ju(n);e.setUint32(t,r?a:i,r),e.setUint32(t+4,r?i:a,r)}var Xu=(e,t,n)=>e>>>n,Zu=(e,t,n)=>e<<32-n|t>>>n,Qu=(e,t,n)=>e>>>n|t<<32-n,$u=(e,t,n)=>e<<32-n|t>>>n,ed=(e,t,n)=>e<<64-n|t>>>n-32,td=(e,t,n)=>e>>>n-32|t<<64-n;function nd(e,t,n,r){let i=(t>>>0)+(r>>>0);return{h:e+n+(i/2**32|0)|0,l:i|0}}var rd=(e,t,n)=>(e>>>0)+(t>>>0)+(n>>>0),id=(e,t,n,r)=>t+n+r+(e/2**32|0)|0,ad=(e,t,n,r)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0),od=(e,t,n,r,i)=>t+n+r+i+(e/2**32|0)|0,sd=(e,t,n,r,i)=>(e>>>0)+(t>>>0)+(n>>>0)+(r>>>0)+(i>>>0),cd=(e,t,n,r,i,a)=>t+n+r+i+a+(e/2**32|0)|0;function ld(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var ud=e=>e?`"${e}" `:``;function dd(e,t=``){if(typeof e!=`number`)throw TypeError(ud(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(ud(t)+`expected integer >= 0, got `+e);return e}function fd(e,t,n=``){if(ld(e)&&(t===void 0||e.length===t))return e;t!==void 0&&dd(t,`length`);let r=ld(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=ud(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}function pd(e){if(typeof e!=`function`||typeof e.create!=`function`)throw TypeError(`expected hash wrapped by utils.createHasher`);if(dd(e.outputLen),dd(e.blockLen),e.outputLen<1||e.blockLen<1)throw Error(`hash blockLen / outputLen must be >= 1`)}var md=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError((t===`object`?``:`"${t}" `)+`expected object, got type=`+typeof e)},hd=(e,t)=>{md(e,t);let n=Object.getPrototypeOf(e);if(n!==Object.prototype&&n!==null)throw TypeError(`"${t}" expected plain object`);if(Object.hasOwn(e,`__proto__`))throw TypeError(`"${t}.__proto__" is not allowed`)};function gd(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function _d(e,t){fd(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function vd(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function yd(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}function bd(e,t){return e<<32-t|e>>>t}var xd=typeof Uint8Array.from([]).toHex==`function`&&typeof Uint8Array.fromHex==`function`,Sd=Array.from({length:256},(e,t)=>t.toString(16).padStart(2,`0`));function Cd(e){if(fd(e),xd)return e.toHex();let t=``;for(let n=0;n<e.length;n++)t+=Sd[e[n]];return t}function wd(e){return e>=48&&e<=57?e-48:e>=65&&e<=70?e-55:e>=97&&e<=102?e-87:void 0}function Td(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);if(xd)try{return Uint8Array.fromHex(e)}catch(e){throw e instanceof SyntaxError?RangeError(e.message):e}let t=e.length,n=t/2;if(t%2)throw RangeError(`hex string expected, got unpadded hex of length `+t);let r=new Uint8Array(n);for(let t=0,i=0;t<n;t++,i+=2){let n=wd(e.charCodeAt(i)),a=wd(e.charCodeAt(i+1));if(n===void 0||a===void 0){let t=e[i]+e[i+1];throw RangeError(`hex string expected, got non-hex character "`+t+`" at index `+i)}r[t]=n*16+a}return r}function Ed(...e){let t=0;for(let n=0;n<e.length;n++){let r=e[n];fd(r),t+=r.length}let n=new Uint8Array(t);for(let t=0,r=0;t<e.length;t++){let i=e[t];n.set(i,r),r+=i.length}return n}function Dd(e,t,n=`opts`){return hd(e,`defaults`),t!==void 0&&hd(t,n),Object.assign(Object.create(null),e,t)}function Od(e,t={}){if(typeof e!=`function`)throw TypeError(`"hashCons" expected function, got type=`+typeof e);t=Dd({},t,`info`);let n=(t,n)=>e(n).update(t).digest(),r=e(void 0);return n.outputLen=r.outputLen,n.blockLen=r.blockLen,n.canXOF=r.canXOF,n.create=t=>e(t),Object.assign(n,t),Object.freeze(n)}function kd(e=32){dd(e,`bytesLength`);let t=typeof globalThis==`object`?globalThis.crypto:null;if(typeof t?.getRandomValues!=`function`)throw Error(`crypto.getRandomValues must be defined`);if(e>65536)throw RangeError(`"bytesLength" expected <= 65536, got ${e}`);return t.getRandomValues(new Uint8Array(e))}var Ad=e=>({oid:Uint8Array.from([6,9,96,134,72,1,101,3,4,2,e])});function jd(e,t,n){return e&t^~e&n}function Md(e,t,n){return e&t^e&n^t&n}var Nd=class{blockLen;outputLen;canXOF=!1;padOffset;isLE;buffer;view;finished=!1;length=0;pos=0;destroyed=!1;constructor(e,t,n,r){this.blockLen=e,this.outputLen=t,this.padOffset=n,this.isLE=r,this.buffer=new Uint8Array(e),this.view=yd(this.buffer)}update(e){gd(this),fd(e);let{view:t,buffer:n,blockLen:r}=this,i=e.length,a=!1;for(let o=0;o<i;){let s=Math.min(r-this.pos,i-o);if(s===r){let t=yd(e);for(;r<=i-o;o+=r)this.process(t,o);a=!0;continue}n.set(o===0&&s===i?e:e.subarray(o,o+s),this.pos),this.pos+=s,o+=s,this.pos===r&&(this.process(t,0),this.pos=0,a=!0)}return this.length+=e.length,a&&this.roundClean(),this}digestInto(e){gd(this),_d(e,this),this.finished=!0;let{buffer:t,view:n,blockLen:r,isLE:i}=this,{pos:a}=this;t[a++]=128,t.fill(0,a),this.padOffset>r-a&&(this.process(n,0),t.fill(0)),Yu(n,r-8,this.length*8,i),this.process(n,0),this.roundClean();let o=e===t?n:yd(e),s=this.outputLen,c=s/4,l=this.get();if(s%4||c>l.length)throw Error(`invalid outputLen`);for(let e=0;e<c;e++)o.setUint32(4*e,l[e],i)}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}_cloneIntoMeta(e){let{buffer:t,length:n,finished:r,destroyed:i,pos:a}=this;return e.destroyed=i,e.finished=r,e.length=n,e.pos=a,a&&e.buffer.set(t),e}clone(){return this._cloneInto()}},Pd=Uint32Array.from([1779033703,3144134277,1013904242,2773480762,1359893119,2600822924,528734635,1541459225]),Fd=Uint32Array.from([1779033703,4089235720,3144134277,2227873595,1013904242,4271175723,2773480762,1595750129,1359893119,2917565137,2600822924,725511199,528734635,4215389547,1541459225,327033209]),Id=Uint32Array.from([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]),Ld=new Uint32Array(64),Rd=class extends Nd{A=0;B=0;C=0;D=0;E=0;F=0;G=0;H=0;constructor(e,t){super(64,e,8,!1),this.A=t[0]|0,this.B=t[1]|0,this.C=t[2]|0,this.D=t[3]|0,this.E=t[4]|0,this.F=t[5]|0,this.G=t[6]|0,this.H=t[7]|0}get(){let{A:e,B:t,C:n,D:r,E:i,F:a,G:o,H:s}=this;return[e,t,n,r,i,a,o,s]}set(e,t,n,r,i,a,o,s){this.A=e|0,this.B=t|0,this.C=n|0,this.D=r|0,this.E=i|0,this.F=a|0,this.G=o|0,this.H=s|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Ld[n]=e.getUint32(t,!1);for(let e=16;e<64;e++){let t=Ld[e-15],n=Ld[e-2],r=bd(t,7)^bd(t,18)^t>>>3,i=bd(n,17)^bd(n,19)^n>>>10;Ld[e]=i+Ld[e-7]+r+Ld[e-16]|0}let{A:n,B:r,C:i,D:a,E:o,F:s,G:c,H:l}=this;for(let e=0;e<64;e++){let t=bd(o,6)^bd(o,11)^bd(o,25),u=l+t+jd(o,s,c)+Id[e]+Ld[e]|0,d=(bd(n,2)^bd(n,13)^bd(n,22))+Md(n,r,i)|0;l=c,c=s,s=o,o=a+u|0,a=i,i=r,r=n,n=u+d|0}n=n+this.A|0,r=r+this.B|0,i=i+this.C|0,a=a+this.D|0,o=o+this.E|0,s=s+this.F|0,c=c+this.G|0,l=l+this.H|0,this.set(n,r,i,a,o,s,c,l)}roundClean(){vd(Ld)}destroy(){this.destroyed=!0,this.set(0,0,0,0,0,0,0,0),vd(this.buffer)}},zd=class extends Rd{constructor(){super(32,Pd)}},Bd=Ku(`0x428a2f98d728ae22.0x7137449123ef65cd.0xb5c0fbcfec4d3b2f.0xe9b5dba58189dbbc.0x3956c25bf348b538.0x59f111f1b605d019.0x923f82a4af194f9b.0xab1c5ed5da6d8118.0xd807aa98a3030242.0x12835b0145706fbe.0x243185be4ee4b28c.0x550c7dc3d5ffb4e2.0x72be5d74f27b896f.0x80deb1fe3b1696b1.0x9bdc06a725c71235.0xc19bf174cf692694.0xe49b69c19ef14ad2.0xefbe4786384f25e3.0x0fc19dc68b8cd5b5.0x240ca1cc77ac9c65.0x2de92c6f592b0275.0x4a7484aa6ea6e483.0x5cb0a9dcbd41fbd4.0x76f988da831153b5.0x983e5152ee66dfab.0xa831c66d2db43210.0xb00327c898fb213f.0xbf597fc7beef0ee4.0xc6e00bf33da88fc2.0xd5a79147930aa725.0x06ca6351e003826f.0x142929670a0e6e70.0x27b70a8546d22ffc.0x2e1b21385c26c926.0x4d2c6dfc5ac42aed.0x53380d139d95b3df.0x650a73548baf63de.0x766a0abb3c77b2a8.0x81c2c92e47edaee6.0x92722c851482353b.0xa2bfe8a14cf10364.0xa81a664bbc423001.0xc24b8b70d0f89791.0xc76c51a30654be30.0xd192e819d6ef5218.0xd69906245565a910.0xf40e35855771202a.0x106aa07032bbd1b8.0x19a4c116b8d2d0c8.0x1e376c085141ab53.0x2748774cdf8eeb99.0x34b0bcb5e19b48a8.0x391c0cb3c5c95a63.0x4ed8aa4ae3418acb.0x5b9cca4f7763e373.0x682e6ff3d6b2b8a3.0x748f82ee5defb2fc.0x78a5636f43172f60.0x84c87814a1f0ab72.0x8cc702081a6439ec.0x90befffa23631e28.0xa4506cebde82bde9.0xbef9a3f7b2c67915.0xc67178f2e372532b.0xca273eceea26619c.0xd186b8c721c0c207.0xeada7dd6cde0eb1e.0xf57d4f7fee6ed178.0x06f067aa72176fba.0x0a637dc5a2c898a6.0x113f9804bef90dae.0x1b710b35131c471b.0x28db77f523047d84.0x32caab7b40c72493.0x3c9ebe0a15c9bebc.0x431d67c49c100d4c.0x4cc5d4becb3e42b6.0x597f299cfc657e2a.0x5fcb6fab3ad6faec.0x6c44198c4a475817`.split(`.`).map(e=>BigInt(e))),Vd=Bd[0],Hd=Bd[1],Ud=new Uint32Array(80),Wd=new Uint32Array(80),Gd=class extends Nd{Ah=0;Al=0;Bh=0;Bl=0;Ch=0;Cl=0;Dh=0;Dl=0;Eh=0;El=0;Fh=0;Fl=0;Gh=0;Gl=0;Hh=0;Hl=0;constructor(e,t){super(128,e,16,!1),this.Ah=t[0]|0,this.Al=t[1]|0,this.Bh=t[2]|0,this.Bl=t[3]|0,this.Ch=t[4]|0,this.Cl=t[5]|0,this.Dh=t[6]|0,this.Dl=t[7]|0,this.Eh=t[8]|0,this.El=t[9]|0,this.Fh=t[10]|0,this.Fl=t[11]|0,this.Gh=t[12]|0,this.Gl=t[13]|0,this.Hh=t[14]|0,this.Hl=t[15]|0}get(){let{Ah:e,Al:t,Bh:n,Bl:r,Ch:i,Cl:a,Dh:o,Dl:s,Eh:c,El:l,Fh:u,Fl:d,Gh:f,Gl:p,Hh:m,Hl:h}=this;return[e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h]}set(e,t,n,r,i,a,o,s,c,l,u,d,f,p,m,h){this.Ah=e|0,this.Al=t|0,this.Bh=n|0,this.Bl=r|0,this.Ch=i|0,this.Cl=a|0,this.Dh=o|0,this.Dl=s|0,this.Eh=c|0,this.El=l|0,this.Fh=u|0,this.Fl=d|0,this.Gh=f|0,this.Gl=p|0,this.Hh=m|0,this.Hl=h|0}_cloneInto(e){return(e||=new this.constructor).set(...this.get()),this._cloneIntoMeta(e)}process(e,t){for(let n=0;n<16;n++,t+=4)Ud[n]=e.getUint32(t),Wd[n]=e.getUint32(t+=4);for(let e=16;e<80;e++){let t=Ud[e-15]|0,n=Wd[e-15]|0,r=Qu(t,n,1)^Qu(t,n,8)^Xu(t,n,7),i=$u(t,n,1)^$u(t,n,8)^Zu(t,n,7),a=Ud[e-2]|0,o=Wd[e-2]|0,s=Qu(a,o,19)^ed(a,o,61)^Xu(a,o,6),c=ad(i,$u(a,o,19)^td(a,o,61)^Zu(a,o,6),Wd[e-7],Wd[e-16]),l=od(c,r,s,Ud[e-7],Ud[e-16]);Ud[e]=l|0,Wd[e]=c|0}let{Ah:n,Al:r,Bh:i,Bl:a,Ch:o,Cl:s,Dh:c,Dl:l,Eh:u,El:d,Fh:f,Fl:p,Gh:m,Gl:h,Hh:g,Hl:_}=this;for(let e=0;e<80;e++){let t=Qu(u,d,14)^Qu(u,d,18)^ed(u,d,41),v=$u(u,d,14)^$u(u,d,18)^td(u,d,41),y=u&f^~u&m,b=d&p^~d&h,x=sd(_,v,b,Hd[e],Wd[e]),S=cd(x,g,t,y,Vd[e],Ud[e]),C=x|0,w=Qu(n,r,28)^ed(n,r,34)^ed(n,r,39),T=$u(n,r,28)^td(n,r,34)^td(n,r,39),E=n&i^n&o^i&o,D=r&a^r&s^a&s;g=m|0,_=h|0,m=f|0,h=p|0,f=u|0,p=d|0,{h:u,l:d}=nd(c|0,l|0,S|0,C|0),c=o|0,l=s|0,o=i|0,s=a|0,i=n|0,a=r|0;let O=rd(C,T,D);n=id(O,S,w,E),r=O|0}({h:n,l:r}=nd(this.Ah|0,this.Al|0,n|0,r|0)),{h:i,l:a}=nd(this.Bh|0,this.Bl|0,i|0,a|0),{h:o,l:s}=nd(this.Ch|0,this.Cl|0,o|0,s|0),{h:c,l}=nd(this.Dh|0,this.Dl|0,c|0,l|0),{h:u,l:d}=nd(this.Eh|0,this.El|0,u|0,d|0),{h:f,l:p}=nd(this.Fh|0,this.Fl|0,f|0,p|0),{h:m,l:h}=nd(this.Gh|0,this.Gl|0,m|0,h|0),{h:g,l:_}=nd(this.Hh|0,this.Hl|0,g|0,_|0),this.set(n,r,i,a,o,s,c,l,u,d,f,p,m,h,g,_)}roundClean(){vd(Ud,Wd)}destroy(){this.destroyed=!0,vd(this.buffer),this.set(0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0)}},Kd=class extends Gd{constructor(){super(64,Fd)}},qd=Od(()=>new zd,Ad(1)),Jd=Od(()=>new Kd,Ad(3)),Y=e=>{let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t).replace(/\+/g,`-`).replace(/\//g,`_`).replace(/=+$/,``)},X=e=>{if(!/^[A-Za-z0-9_-]*$/.test(e))return null;let t=e.replace(/-/g,`+`).replace(/_/g,`/`).padEnd(Math.ceil(e.length/4)*4,`=`);try{let e=atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;t++)n[t]=e.charCodeAt(t);return n}catch{return null}},Yd=`0123456789ABCDEFGHJKMNPQRSTVWXYZ`,Xd=e=>{let t=0,n=0,r=``;for(let i of e)for(n=n<<8|i,t+=8;t>=5;)r+=Yd[n>>>t-5&31],t-=5;return t>0&&(r+=Yd[n<<5-t&31]),r},Zd=e=>[...e].every(e=>Yd.includes(e)),Qd=e=>e.toUpperCase().replaceAll(`O`,`0`).replaceAll(`I`,`1`).replaceAll(`L`,`1`).replace(/[^0-9A-Z]/g,``),$d=e=>{let t=0,n=0,r=[];for(let i of e){let e=Yd.indexOf(i);if(e<0)return null;n=n<<5|e,t+=5,t>=8&&(r.push(n>>>t-8&255),t-=8)}return t>0&&n&(1<<t)-1?null:new Uint8Array(r)},ef=/^[a-z0-9]+(?:_[a-z0-9]+)*$/,tf=new Set(`a.admin.administrator.anonymous.deleted.e.everyone.guest.help.here.i.index.me.mod.moderator.null.official.root.security.social.staff.support.system.team.u.undefined.unknown.you`.split(`.`)),nf=e=>e.trim().replace(/[A-Z]/g,e=>String.fromCharCode(e.charCodeAt(0)+32)),rf=e=>{let t=nf(e);return t.length===0?{ok:!1,reason:`empty`}:ef.test(t)?t.length<3?{ok:!1,reason:`too-short`}:t.length>20?{ok:!1,reason:`too-long`}:t.startsWith(`fkn`)||tf.has(t)?{ok:!1,reason:`reserved`}:{ok:!0,name:t}:{ok:!1,reason:`characters`}},af=e=>{let t=rf(e);return t.ok&&t.name===e},of=e=>Y(qd(e)),sf=e=>Xd(qd(e)).slice(0,16),cf=(e,t)=>`${e}#${sf(t)}`,lf=e=>Xd(qd(e)).slice(0,24).match(/.{4}/g)?.join(`-`)??``,uf=e=>{let t=qd(e),n=(t[0]*256+t[1])%360,r=[];for(let e=0;e<5;e++)for(let n=0;n<5;n++){let i=n<3?n:4-n,a=e*3+i;r.push((t[2+(a>>3)]>>(a&7)&1)==1)}return{hue:n,cells:r}},df=e=>e<=31||e>=127&&e<=159||e>=8234&&e<=8238||e>=8294&&e<=8297,ff=(e,{max:t,multiline:n})=>{if(e.normalize(`NFC`)!==e)return`characters`;let r=0;for(let t of e){if(df(t.codePointAt(0))&&!(n&&t===`
|
|
4
|
+
`))return`characters`;r+=1}return r>t?`too-long`:null},pf=(e,t=200)=>{let n;try{n=new URL(e.trim())}catch{return null}return n.protocol===`https:`&&n.href.length<=t?n.href:null},mf=1e3,hf=/^[A-Za-z0-9_-]{43}$/,gf=e=>{if(e===null)return null;if(typeof e!=`object`)return;let{url:t,key:n}=e;return typeof t==`string`&&t.length<=200&&typeof n==`string`&&hf.test(n)?{url:t,key:n}:void 0},_f=e=>{let t=e.profile.visibility?.value.level;return t===`me`||t===`public`?{level:t}:{level:`friends`}},vf=e=>ff(e,{max:32,multiline:!1})===null,yf=e=>ff(e,{max:mf,multiline:!0})===null,bf=e=>{let t=e.displayName.normalize(`NFC`).trim();if(!vf(t))return{ok:!1,reason:`display-name`};let n=e.bio.normalize(`NFC`).replaceAll(`\r
|
|
5
|
+
`,`
|
|
6
|
+
`).trim();if(!yf(n))return{ok:!1,reason:`bio`};let r=e.links.map(e=>e.trim()).filter(e=>e!==``);if(r.length>5)return{ok:!1,reason:`links`};let i=[];for(let[e,t]of r.entries()){let n=pf(t);if(n===null)return{ok:!1,reason:`link`,index:e};i.push(n)}return{ok:!0,profile:{displayName:t,bio:n,links:i}}},xf=e=>{let{displayName:t,bio:n,links:r}=e.profile;return{displayName:t?.value??``,bio:n?.value??``,links:r?.value??[],version:Math.max(0,...Object.values(e.profile).map(e=>e?.lamport??0))}},Sf=e=>{let t=xf(e);return _f(e).level===`me`?{displayName:``,bio:``,links:[],version:t.version}:t},Cf=e=>{if(typeof e!=`object`||!e)return null;let{displayName:t,bio:n,links:r,version:i}=e;return typeof t!=`string`||!vf(t)||typeof n!=`string`||!yf(n)||!Array.isArray(r)||r.length>5||!r.every(e=>typeof e==`string`&&pf(e)===e)||typeof i!=`number`||!Number.isSafeInteger(i)||i<0?null:{displayName:t,bio:n,links:r,version:i}},wf=(e,t)=>e!==null&&t.version<=e.version?e:t,Tf=new TextDecoder,Ef=e=>({list:async()=>(await e.list()).map(({path:e,updatedAt:t})=>({path:e,updatedAt:Date.parse(t)})),read:async t=>{try{return Tf.decode((await e.readFileSealed(t)).data)}catch(n){if(!e.isNotFound(n))throw n;if((await e.list()).some(e=>e.path===t))throw Error(`social: ${t} is listed, but reading it found nothing`,{cause:n});return null}},write:(t,n)=>e.writeFile(t,n),remove:t=>e.unlink(t)}),Df=[`fkn:e2e-stale-epoch`,`fkn:e2e-integrity`,`fkn:e2e-retired-format`],Of=`FKN_E2E_LOCKED`,kf=e=>{let t=e instanceof Error?e.message:String(e);return Df.some(e=>t.includes(e))?`reset`:e?.code===Of||t.includes(`fkn:e2e-locked`)?`locked`:`unreachable`},Af=(e,t)=>e.lamport===t.lamport?e.by>t.by:e.lamport>t.lamport,jf=(e,t)=>Af(e,t)?e:t,Mf=(e,t)=>{let n={...e};for(let[e,r]of Object.entries(t)){let t=n[e];n[e]=t===void 0?r:jf(t,r)}return n},Nf=e=>{let t=0;for(let n of e)n.lamport>t&&(t=n.lamport);return t+1},Pf=()=>({v:2,profile:{},friends:{},apps:{},seen:{}}),Ff=(e,t)=>Mf(e,t),If=(e,t)=>{let n=e.friends,r=e.profile,i=e.apps;for(let e of t)n=Mf(n,e.friends),r=Ff(r,e.profile),i=Mf(i,e.apps);return{v:2,profile:r,friends:n,apps:i,seen:e.seen}},Lf=e=>[...Object.values(e.friends),...Object.values(e.profile).filter(e=>e!==void 0),...Object.values(e.apps)],Rf=(e,t)=>({lamport:Nf(Lf(e)),by:t}),zf=e=>Object.entries(e.friends).filter(([,e])=>e.value.state===`active`).map(([e,t])=>({...t.value,fingerprint:e})).sort((e,t)=>e.fingerprint.localeCompare(t.fingerprint)),Bf=(e,t)=>t.filter(({writerId:t,updatedAt:n})=>{let r=e.seen[t];return r===void 0||r.updatedAt!==n}).map(({writerId:e})=>e),Vf=`v1/roster.json`,Hf=e=>`v1/w/${e}.json`,Uf=`v1/w/`,Wf=e=>{if(e===null)return null;try{return JSON.parse(e)}catch{return null}},Gf=e=>e.startsWith(Uf)&&e.endsWith(`.json`)?e.slice(5,-5):null,Kf=`social: the friend list was saved by a newer FKN Social`,qf=e=>{let{v:t,apps:n}=e;if(t!==1&&t!==2)throw Error(Kf);return{...e,v:2,apps:t===2?n??{}:{}}},Jf=async e=>{let[t,n]=await Promise.all([e.list(),e.read(Vf)]),r=t.map(({path:e,updatedAt:t})=>({writerId:Gf(e),updatedAt:t})).filter(e=>e.writerId!==null),i=qf(Wf(n)??Pf()),a=Bf(i,r);return{roster:i,cells:(await Promise.all(a.map(t=>e.read(Hf(t))))).map(e=>Wf(e)).filter(e=>e!==null).map(qf),listed:r}},Yf=e=>If(e.roster,e.cells),Xf=e=>({v:2,by:e,friends:{},profile:{},apps:{}}),Zf=async(e,t,n,r)=>{let i=If(t.roster,[...t.cells,n]),a=r(Rf(i,n.by),n,i);return await e.write(Hf(n.by),JSON.stringify(a)),a},Qf=async(e,t)=>{let n=Yf(t),r={...n.seen};for(let{writerId:e,updatedAt:n}of t.listed){let i=t.cells.find(t=>t.by===e);r[e]={lamport:i===void 0?r[e]?.lamport??0:Math.max(0,...Object.values(i.friends).map(e=>e.lamport)),updatedAt:n}}let i={v:2,profile:n.profile,friends:n.friends,apps:n.apps,seen:r};return await e.write(Vf,JSON.stringify(i)),Wf(await e.read(`v1/roster.json`))??i},$f=async(e,t,n)=>{let r=await Jf(e),i=Wf(await e.read(Hf(t))),a=await Zf(e,r,i===null?Xf(t):qf(i),n);try{let t=await Jf(e);return await Qf(e,t),Yf(t)}catch{return If(r.roster,[...r.cells,a])}},ep=e=>e instanceof Error&&e.message===`social: the friend list was saved by a newer FKN Social`?`newer`:kf(e),tp=async({cloud:e})=>{try{return{ok:!0,roster:Yf(await Jf(e))}}catch(e){return{ok:!1,reason:ep(e)}}},np=async({cloud:e,writerId:t,exclusive:n},r)=>{if(t===null)return{ok:!1,reason:`no-writer`};try{return{ok:!0,roster:await n(()=>$f(e,t,r))}}catch(e){return{ok:!1,reason:ep(e)}}},rp=(e,t)=>JSON.stringify(e)===JSON.stringify(t),ip=async(e,t,n)=>{let r=bf(t);return r.ok?np(e,(e,t)=>{let i={...t.profile};for(let t of[`displayName`,`bio`,`links`]){let a=r.profile[t];rp(n[t],a)||(i[t]={value:a,...e})}return{...t,profile:i}}):r},ap=(e,t)=>np(e,(e,n,r)=>{let i={...n.profile};for(let[n,a]of Object.entries(t(r)))i[n]={value:a,...e};return{...n,profile:i}}),op=(e,t,n)=>np(e,(e,r,i)=>{let a=n(i);if(a===null)return r;let o={...r.apps,[t]:{value:a.grant,...e}};return a.page===void 0?{...r,apps:o}:{...r,apps:o,profile:{...r.profile,page:{value:a.page,...e}}}}),sp=async(e,t,n)=>{let r=null,i=!0;return{outcome:await ap(e,e=>(r=e.profile[t]?.value??null,i=n===null||_f(e).level!==`me`,i?{[t]:n}:{})),replaced:r,applied:i}},cp=(e,t,n)=>np(e,(e,r,i)=>{let a=i.friends[t];return a===void 0?r:{...r,friends:{...r.friends,[t]:{value:n(a.value),...e}}}}),lp=(e,t,n)=>cp(e,t,e=>({...e,nickname:n})),up=(e,t)=>cp(e,t,e=>({...e,state:`removed`})),dp=(e,t,n)=>({signKey:Y(t.signKey),dhKey:Y(t.dhKey),name:t.name,nickname:e?.nickname??null,profile:wf(e?.profile??null,t.profile),pairNonce:Y(t.pairNonce),linkedAt:e?.state===`active`?e.linkedAt:n,linkedVia:e?.state===`active`?e.linkedVia:t.linkedVia,inbox:t.inbox??e?.inbox??null,state:`active`}),fp=(e,t,n)=>{let r=of(t.signKey);return np(e,(e,i,a)=>({...i,friends:{...i.friends,[r]:{value:dp(a.friends[r]?.value,t,n),...e}}}))},pp={displayName:``,bio:``,links:[],version:0},mp=async(e,t,n)=>{let r=of(t.signKey),i=``,a=await np(e,(e,a,o)=>{let s=o.friends[r]?.value;if(s?.state===`active`||s?.state===`requested`)return i=s.pairNonce,a;i=Y(crypto.getRandomValues(new Uint8Array(32)));let c={signKey:Y(t.signKey),dhKey:Y(t.dhKey),name:t.name,nickname:s?.nickname??null,profile:s?.profile??pp,pairNonce:i,linkedAt:n,linkedVia:`request`,inbox:t.inbox,state:`requested`};return{...a,friends:{...a.friends,[r]:{value:c,...e}}}});return a.ok?{ok:!0,nonce:i}:a},hp=async(e,t,n)=>{let r=of(t.signKey),i=Y(t.pairNonce),a=!1;return{outcome:await np(e,(e,o,s)=>{let c=s.friends[r]?.value;return a=c?.state===`active`||c?.state===`requested`&&c.pairNonce===i,a&&c!==void 0?{...o,friends:{...o.friends,[r]:{value:dp(c,{...t,name:c.name},n),...e}}}:o}),applied:a}},gp={avatar:262144,background:2097152},_p={avatar:4194304,background:10485760},vp={avatar:512,background:1920},yp={avatar:1024,background:3840},bp=1048576,xp=4194304,Sp=1920,Cp=2048,wp=e=>e===`artwork`?{staticBytes:bp,maxBytes:xp,side:Sp,animatedSide:Cp}:{staticBytes:gp[e],maxBytes:_p[e],side:vp[e],animatedSide:yp[e]},Tp=(e,t,n)=>{for(let r=0;r<n.length;r++)if(e[t+r]!==n.charCodeAt(r))return!1;return!0},Ep=(e,t)=>(e[t]|e[t+1]<<8|e[t+2]<<16|e[t+3]<<24)>>>0,Dp=(e,t,n)=>{e[t]=n&255,e[t+1]=n>>>8&255,e[t+2]=n>>>16&255,e[t+3]=n>>>24&255},Op=e=>{let t=0;for(let n of e)t+=n.length;let n=new Uint8Array(t),r=0;for(let t of e)n.set(t,r),r+=t.length;return n},kp=(e,t)=>{let n=t;for(;n<e.length;){let t=e[n++];if(t===0)return n;if(n+=t,n>e.length)return-1}return-1},Ap=(e,t)=>{if(e.length<14||!Tp(e,0,`GIF87a`)&&!Tp(e,0,`GIF89a`))return null;let n=13+(e[10]&128?3*(1<<(e[10]&7)+1):0);if(n>e.length)return null;t?.push(e.subarray(0,n));let r=0;for(;n<e.length;){let i=n,a=e[n++];if(a===59)break;if(a===44){if(n+9>e.length)return null;if(r+=1,t===void 0&&r>=2)return r;let a=e[n+8],o=a&128?3*(1<<(a&7)+1):0;if(n+=9+o,n>=e.length||(n=kp(e,n+1),n<0))return null;t?.push(e.subarray(i,n))}else if(a===33){if(n>=e.length)return null;let r=e[n++],a=n;if(n=kp(e,a),n<0)return null;if(t!==void 0){let o=r===255&&a+12<=n&&e[a]===11&&(Tp(e,a+1,`NETSCAPE2.0`)||Tp(e,a+1,`ANIMEXTS1.0`));(r===249||o)&&t.push(e.subarray(i,n))}}else return null}return r<2?null:(t?.push(Uint8Array.of(59)),r)},jp=e=>(Ap(e)??0)>=2,Mp=e=>{let t=[];return Ap(e,t)===null?null:Op(t)},Np=new Set([`VP8X`,`ICCP`,`ANIM`,`ANMF`]),Pp=(e,t)=>{if(e.length<12||!Tp(e,0,`RIFF`)||!Tp(e,8,`WEBP`))return null;let n=Math.min(e.length,8+Ep(e,4)),r=[],i=12,a=!1,o=!1,s=0;for(;i+8<=n;){let c=Ep(e,i+4),l=i+8;if(c>n-l)return null;let u=String.fromCharCode(e[i],e[i+1],e[i+2],e[i+3]);if(u===`VP8X`&&c>=10&&e[l]&2?a=!0:u===`ANIM`?o=!0:u===`ANMF`&&(s+=1),t&&Np.has(u)){let t=c+(c&1),n=new Uint8Array(8+t);n.set(e.subarray(i,i+4),0),Dp(n,4,c),n.set(e.subarray(l,l+c),8),u===`VP8X`&&c>=10&&(n[8]&=-13),r.push(n)}i=l+c+(c&1)}return{anim:(a||o)&&s>=2,parts:r}},Fp=e=>Pp(e,!1)?.anim??!1,Ip=e=>{let t=Pp(e,!0);if(t===null||!t.anim)return null;let n=Op(t.parts),r=new Uint8Array(12+n.length);return r.set(e.subarray(0,4),0),Dp(r,4,4+n.length),r.set(e.subarray(8,12),8),r.set(n,12),r},Lp=e=>{let t=Rp(e);return t===`image/gif`?jp(e):t===`image/webp`&&Fp(e)},Rp=e=>e[0]===137&&Tp(e,1,`PNG\r
|
|
7
|
+
|
|
8
|
+
`)?`image/png`:e[0]===255&&e[1]===216&&e[2]===255?`image/jpeg`:Tp(e,0,`GIF87a`)||Tp(e,0,`GIF89a`)?`image/gif`:Tp(e,0,`RIFF`)&&Tp(e,8,`WEBP`)?`image/webp`:null,zp=e=>e?.code,Bp=async(e,t)=>{for(let n of t)n!==null&&await e.delete(n.url).catch(()=>{})},Vp=async(e,t,n)=>{if(t.size>n)return{ok:!1,reason:`too-large`};if(Rp(new Uint8Array(await t.slice(0,12).arrayBuffer()))===null)return{ok:!1,reason:`kind`};try{let n=await e.put(t);return{ok:!0,picture:{url:n.url,key:n.key}}}catch(e){let t=zp(e);return{ok:!1,reason:t===`quota`||t===`too-many`?t:`storage-unavailable`}}},Hp=async(e,t,n)=>{let r=await Vp(e.storage,n,_p[t]);if(!r.ok)return r;let i=r.picture,{outcome:a,replaced:o,applied:s}=await sp(e,t,i);return await Bp(e.storage,[a.ok&&s?o:i]),a.ok&&!s?{ok:!1,reason:`not-public`}:a},Up=async(e,t)=>{let{outcome:n,replaced:r}=await sp(e,t,null);return n.ok&&await Bp(e.storage,[r]),n},Wp=async(e,t,n)=>{if(t===null)return null;try{let r=await e.get(t.url,t.key);if(r.size>n)return null;let i=new Uint8Array(await r.arrayBuffer()),a=Rp(i);return i.length>n||a===null?null:URL.createObjectURL(new Blob([i],{type:a}))}catch{return null}},Gp=[.86,.72,.58,.44],Kp=6,qp=33554432,Jp=4194304,Yp=async(e,t,n,r)=>{let i=wp(n),a=e===`image/gif`?Mp(t):Ip(t);if(a===null)return{ok:!1,reason:`kind`};if(a.length>i.maxBytes)return{ok:!1,reason:`too-large`};let o=new Blob([a.slice()],{type:e}),s;try{s=await r.decode(o)}catch{return{ok:!1,reason:`kind`}}try{let{width:e,height:t}=s;return e>0&&t>0?Math.max(e,t)>i.animatedSide?{ok:!1,reason:`too-large`}:{ok:!0,picture:{blob:o,width:e,height:t,animated:!0}}:{ok:!1,reason:`kind`}}finally{r.release?.(s.source)}},Xp=async(e,t,n)=>{let r=wp(t),i=Rp(new Uint8Array(await e.slice(0,12).arrayBuffer()));if(i===`image/gif`||i===`image/webp`){if(e.size>r.maxBytes){let t=new Uint8Array(await(e.size<=qp?e:e.slice(0,Jp)).arrayBuffer());if(Lp(t)||i===`image/webp`&&e.size>qp&&t.length>=21&&Tp(t,12,`VP8X`)&&t[20]&2)return{ok:!1,reason:`too-large`}}else{let r=new Uint8Array(await e.arrayBuffer());if(Lp(r))return Yp(i,r,t,n)}}let a;try{a=await n.decode(e)}catch{return{ok:!1,reason:`kind`}}let{source:o,width:s,height:c}=a;try{if(!(s>0&&c>0))return{ok:!1,reason:`kind`};let e=Math.min(1,r.side/Math.max(s,c)),t={width:Math.max(1,Math.round(s*e)),height:Math.max(1,Math.round(c*e))},i=`image/webp`;for(let e=0;e<Kp;e++){for(let e of Gp){let a=await n.encode(o,t.width,t.height,i,e);if(a.type!==i&&i===`image/webp`&&(i=`image/jpeg`,a=await n.encode(o,t.width,t.height,i,e)),a.type!==i)return{ok:!1,reason:`kind`};if(a.size<=r.staticBytes)return{ok:!0,picture:{blob:a,...t}}}t={width:Math.max(1,Math.round(t.width*.75)),height:Math.max(1,Math.round(t.height*.75))}}return{ok:!1,reason:`too-large`}}catch{return{ok:!1,reason:`kind`}}finally{n.release?.(o)}},Zp={decode:async e=>{let t=await createImageBitmap(e,{imageOrientation:`from-image`});return{source:t,width:t.width,height:t.height}},encode:(e,t,n,r,i)=>new Promise((a,o)=>{let s=document.createElement(`canvas`);s.width=t,s.height=n;let c=s.getContext(`2d`);if(c===null)return o(Error(`social: no 2d canvas`));r===`image/jpeg`&&(c.fillStyle=`#fff`,c.fillRect(0,0,t,n)),c.imageSmoothingQuality=`high`,c.drawImage(e,0,0,t,n),s.toBlob(e=>e===null?o(Error(`social: the picture did not encode`)):a(e),r,i)}),release:e=>e.close()},Qp=2e3,$p=/^[A-Za-z0-9_-]{8,32}$/,em=()=>Y(crypto.getRandomValues(new Uint8Array(12))),tm=e=>{let t=e.normalize(`NFC`).trim();return t!==``&&ff(t,{max:80,multiline:!1})===null?t:null},nm=e=>{let t=e.normalize(`NFC`).replaceAll(`\r
|
|
9
|
+
`,`
|
|
10
|
+
`).trim();return t!==``&&ff(t,{max:2e3,multiline:!0})===null?t:null},rm=e=>{if(e===void 0)return;let t=e.normalize(`NFC`).trim();if(t!==``)return ff(t,{max:120,multiline:!1})===null?t:null},im=e=>typeof e==`string`&&$p.test(e),am=e=>typeof e==`string`&&e.trim()===e&&e!==``&&ff(e,{max:80,multiline:!1})===null,om=e=>typeof e==`string`&&e.trim()===e&&e!==``&&ff(e,{max:2e3,multiline:!0})===null,sm=e=>{if(e!==void 0)return typeof e!=`string`||e.trim()!==e||e===``||ff(e,{max:120,multiline:!1})!==null?null:e},cm=e=>{if(typeof e!=`object`||!e)return null;let{url:t,key:n,caption:r}=e,i=gf({url:t,key:n}),a=sm(r);return i==null||a===null?null:a===void 0?{url:i.url,key:i.key}:{url:i.url,key:i.key,caption:a}},lm=e=>e.kind===`text`?{id:e.id,kind:`text`,title:e.title,body:e.body}:{id:e.id,kind:`artwork`,title:e.title,items:e.items.map(({url:e,key:t,caption:n})=>n===void 0||n===``?{url:e,key:t}:{url:e,key:t,caption:n})},um=e=>{if(typeof e!=`object`||!e)return null;let{id:t,kind:n,title:r}=e;if(!im(t)||!am(r))return null;if(n===`text`){let{body:n}=e;return om(n)?{id:t,kind:`text`,title:r,body:n}:null}if(n===`artwork`){let{items:n}=e;if(!Array.isArray(n)||n.length===0||n.length>4)return null;let i=[];for(let e of n){let t=cm(e);t!==null&&!i.some(e=>e.url===t.url)&&i.push(t)}return i.length>0?{id:t,kind:`artwork`,title:r,items:i}:null}return null},dm=e=>{let t=[];for(let n of Array.isArray(e)?e:[]){let e=um(n);e!==null&&!t.some(t=>t.id===e.id)&&t.length<6&&t.push(e)}return t},fm=e=>{let t=new Set;for(let n of Array.isArray(e)?e:[])if(im(n)&&t.add(n),t.size>=12)break;return[...t]},pm=new Set([`public`,`friends`,`off`]),mm=e=>{if(typeof e!=`object`||!e)return null;let{id:t,kind:n,title:r,level:i}=e;if(!im(t)||!am(r)||typeof i!=`string`||!pm.has(i))return null;if(n===`text`){let{body:n}=e;return om(n)?{id:t,kind:`text`,title:r,body:n,level:i}:null}if(n===`artwork`){let{items:n}=e;if(!Array.isArray(n)||n.length>4)return null;let a=[];for(let e of n){if(typeof e!=`object`||!e)continue;let{picture:t,caption:n}=e,r=gf(t),i=sm(n);r!=null&&i!==null&&!a.some(e=>e.picture.url===r.url)&&a.push(i===void 0?{picture:r}:{picture:r,caption:i})}return{id:t,kind:`artwork`,title:r,items:a,level:i}}return null},hm=e=>{let t=[];for(let n of Array.isArray(e.profile.panels?.value)?e.profile.panels.value:[]){let e=mm(n);e!==null&&!t.some(t=>t.id===e.id)&&t.length<6&&t.push(e)}return t},gm=e=>e.level===`off`?null:e.kind===`text`?{id:e.id,kind:`text`,title:e.title,body:e.body}:e.items.length===0?null:{id:e.id,kind:`artwork`,title:e.title,items:e.items.map(({picture:e,caption:t})=>t===void 0?{url:e.url,key:e.key}:{url:e.url,key:e.key,caption:t})},_m=e=>hm(e).filter(e=>e.level===`public`).map(gm).filter(e=>e!==null),vm=e=>hm(e).filter(e=>e.level===`friends`).map(gm).filter(e=>e!==null),ym=e=>hm(e).filter(e=>gm(e)!==null).map(e=>e.id),bm=e=>e.kind===`artwork`?e.items.map(e=>e.picture):[],xm=async(e,t)=>{let n=tm(t.title);if(n===null)return{ok:!1,reason:`title`};let r=nm(t.body);if(r===null)return{ok:!1,reason:`body`};let i=!1,a=await ap(e,e=>{let a=hm(e);return a.length>=6?(i=!0,{}):{panels:[...a,{id:em(),kind:`text`,title:n,body:r,level:t.level}]}});return i?{ok:!1,reason:`full`}:a},Sm=async(e,t)=>{let n=tm(t.title);if(n===null)return{ok:!1,reason:`title`};let r=!1,i=await ap(e,e=>{let i=hm(e);return i.length>=6?(r=!0,{}):{panels:[...i,{id:em(),kind:`artwork`,title:n,items:[],level:t.level}]}});return r?{ok:!1,reason:`full`}:i},Cm=async(e,t,n)=>{let r=tm(n.title);if(r===null)return{ok:!1,reason:`title`};let i=nm(n.body);if(i===null)return{ok:!1,reason:`body`};let a=!1,o=await ap(e,e=>{let n=hm(e),o=n.findIndex(e=>e.id===t&&e.kind===`text`);if(o<0)return a=!0,{};let s=[...n];return s[o]={...n[o],title:r,body:i},{panels:s}});return a?{ok:!1,reason:`not-found`}:o},wm=async(e,t,n)=>{let r=tm(n.title);if(r===null)return{ok:!1,reason:`title`};let i={};for(let[e,t]of Object.entries(n.captions)){let n=rm(t);if(n===null)return{ok:!1,reason:`caption`};i[e]=n}let a=!1,o=await ap(e,e=>{let n=hm(e),o=n.findIndex(e=>e.id===t&&e.kind===`artwork`);if(o<0)return a=!0,{};let s=n[o],c=s.items.map(e=>{if(!Object.hasOwn(i,e.picture.url))return e;let t=i[e.picture.url];return t===void 0?{picture:e.picture}:{picture:e.picture,caption:t}}),l=[...n];return l[o]={...s,title:r,items:c},{panels:l}});return a?{ok:!1,reason:`not-found`}:o},Tm=async(e,t,n)=>ap(e,e=>{let r=hm(e),i=r.findIndex(e=>e.id===t),a=i+n;if(i<0||a<0||a>=r.length)return{};let o=[...r];return[o[i],o[a]]=[o[a],o[i]],{panels:o}}),Em=async(e,t,n)=>{let r=[],i=await ap(e,e=>{let i=hm(e),a=i.findIndex(e=>e.id===t);if(a<0)return{};let o=i[a];if(o.level===n)return{};let s=o.level===`public`&&n!==`public`||o.level===`friends`&&n===`off`,c=[...i];return o.kind===`artwork`&&s&&o.items.length>0?(r=bm(o),c[a]={...o,items:[],level:n}):c[a]={...o,level:n},{panels:c}});return{outcome:i,dropped:i.ok?r:[]}},Dm=async(e,t)=>{let n=[],r=await ap(e,e=>{let r=hm(e),i=r.find(e=>e.id===t);return i===void 0?{}:(n=bm(i),{panels:r.filter(e=>e.id!==t)})});return{outcome:r,dropped:r.ok?n:[]}},Om=async(e,t,n,r)=>{let i=rm(r);if(i===null)return{ok:!1,reason:`caption`};let a=await Vp(e.storage,n,xp);if(!a.ok)return a;let o=null,s=await ap(e,e=>{let n=hm(e),r=n.findIndex(e=>e.id===t&&e.kind===`artwork`);if(r<0)return o=`not-found`,{};let s=n[r];if(s.level===`off`)return o=`off`,{};if(s.items.length>=4)return o=`items-full`,{};let c=i===void 0?{picture:a.picture}:{picture:a.picture,caption:i},l=[...n];return l[r]={...s,items:[...s.items,c]},{panels:l}});return(!s.ok||o!==null)&&await Bp(e.storage,[a.picture]),o===null?s:{ok:!1,reason:o}},km=async(e,t,n)=>{let r=[],i=await ap(e,e=>{let i=hm(e),a=i.findIndex(e=>e.id===t&&e.kind===`artwork`);if(a<0)return{};let o=i[a],s=o.items.find(e=>e.picture.url===n);if(s===void 0)return{};r=[s.picture];let c=[...i];return c[a]={...o,items:o.items.filter(e=>e.picture.url!==n)},{panels:c}});return{outcome:i,dropped:i.ok?r:[]}},Am=Symbol.for(`pv`),jm=0;Array.isArray;function Z(e,t,n,r,i,a){t||={};var o,s,c=t;if(`ref`in c&&typeof e!=`function`)for(s in c={},t)s==`ref`?o=t[s]:c[s]=t[s];var l={type:e,props:c,key:n,ref:o,__k:null,__:null,__b:0,__e:null,__c:null,constructor:Am,__v:--jm,__i:-1,__u:0};return(i||a)&&(l.__source=i,l.__self=a),G.vnode&&G.vnode(l),l}var Mm=({size:e=18})=>Z(`svg`,{width:e,height:e,viewBox:`0 0 20 20`,fill:`none`,stroke:`currentColor`,strokeWidth:1.75,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`2.25`,y:`2.25`,width:`15.5`,height:`15.5`}),Z(`path`,{d:`M2.25 10h8.5V2.25`}),Z(`rect`,{x:`11.5`,y:`11.5`,width:`3.75`,height:`3.75`,fill:`currentColor`,stroke:`none`})]}),Nm=({id:e})=>{switch(e){case`overview`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`2`,y:`2`,width:`5`,height:`5`}),Z(`rect`,{x:`9`,y:`2`,width:`5`,height:`5`}),Z(`rect`,{x:`2`,y:`9`,width:`5`,height:`5`}),Z(`rect`,{x:`9`,y:`9`,width:`5`,height:`5`})]});case`customize`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`path`,{d:`M2 4h12M2 8h12M2 12h12`}),Z(`rect`,{x:`4`,y:`2.5`,width:`2.5`,height:`3`,fill:`currentColor`}),Z(`rect`,{x:`9.5`,y:`6.5`,width:`2.5`,height:`3`,fill:`currentColor`}),Z(`rect`,{x:`5`,y:`10.5`,width:`2.5`,height:`3`,fill:`currentColor`})]});case`friends`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`2.5`,y:`3`,width:`4.5`,height:`4.5`}),Z(`path`,{d:`M1.5 13.5V10h6.5v3.5`}),Z(`rect`,{x:`9.5`,y:`4`,width:`4`,height:`4`}),Z(`path`,{d:`M9.5 10h4.5v3.5`})]});case`inbox`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`2`,y:`3`,width:`12`,height:`10`}),Z(`path`,{d:`M2 8.5h3.5l1.5 2h2l1.5-2H14`})]});case`apps`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`2`,y:`2.5`,width:`12`,height:`11`}),Z(`path`,{d:`M2 6h12M6 6v7.5`})]});case`account`:return Z(`svg`,{className:`social-ico`,width:16,height:16,viewBox:`0 0 16 16`,fill:`none`,stroke:`currentColor`,strokeWidth:1.5,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:[Z(`rect`,{x:`3`,y:`2.5`,width:`5.5`,height:`5.5`}),Z(`path`,{d:`M8.5 5.25H14V8M11.75 5.25V7.5`}),Z(`path`,{d:`M2.5 13.5h11`})]})}},Pm=()=>Z(`svg`,{className:`social-ico`,width:13,height:13,viewBox:`0 0 14 14`,fill:`none`,stroke:`currentColor`,strokeWidth:1.75,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:Z(`path`,{d:`M7 11.5V3M3.5 6.5 7 3l3.5 3.5`})}),Fm=()=>Z(`svg`,{className:`social-ico`,width:13,height:13,viewBox:`0 0 14 14`,fill:`none`,stroke:`currentColor`,strokeWidth:1.75,strokeLinecap:`square`,strokeLinejoin:`miter`,"aria-hidden":`true`,children:Z(`path`,{d:`M7 2.5V11M3.5 7.5 7 11l3.5-3.5`})});new URL(Vu).host;var Im=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Lm=({children:e})=>Z(`main`,{className:`social-shell`,children:Z(`section`,{className:`social-panel`,children:[Z(`div`,{className:`social-panel-mark`,"aria-hidden":`true`,children:Z(Mm,{size:18})}),e]})}),Rm=({label:e,state:t,error:n})=>Z(`main`,{className:`social-loader-stage`,"data-social-state":t,children:Z(`div`,{className:`social-loader-box`,children:[n,Z(`div`,{className:`social-loader-mark`,"aria-hidden":`true`,children:Z(Mm,{size:24})}),Z(`div`,{className:`social-loader-brand`,children:`FKN Social`}),Z(`div`,{className:`social-loader-track`,"aria-hidden":`true`,children:Z(`div`,{className:`social-loader-bar`})}),Z(`p`,{className:`social-loader-status`,role:`status`,children:e})]})}),zm=`Your FKN storage is locked on this device, so nothing changed. Unlock it under Security in your FKN settings, then try again.`,Bm=`Your saved friend list will not open, so nothing changed. If you downloaded your FKN data before, bring it back under Security in your FKN settings.`,Vm={empty:`Pick a name.`,"too-short":`A name has at least 3 characters.`,"too-long":`A name has at most 20 characters.`,characters:`Use lowercase letters and digits, with single underscores between them.`,reserved:`That name is reserved. Try another.`,taken:`That name is taken. Try another.`,"out-of-claims":`No claimed rooms left. Unclaim one under Rooms in your FKN settings, then try again.`,busy:`That name has too many connections right now. Close other FKN Social tabs, or try again in a moment.`,unrecorded:`The name's record could not be written. Check that Messages kept is on for it under Rooms in your FKN settings, then try again.`,unavailable:`FKN rooms did not answer. Try again in a moment.`,unreachable:`FKN could not be reached. Check your connection, then try again.`,locked:zm,reset:`Your saved identity will not open, so nothing changed. Reload the page, then enter your recovery key.`,"list-reset":Bm,newer:`This needs a newer FKN Social. Reload the page to update.`,"no-writer":`This browser keeps no site data for FKN Social. Allow site data, then reload.`,"bad-recovery-key":`That is not a recovery key. A recovery key starts with FKNS, followed by 52 letters and digits.`},Hm=({reason:e})=>e===null?null:Z(`p`,{className:`social-error`,role:`alert`,children:Vm[e]}),Um=e=>Vm[e],Wm={reset:Bm,locked:zm,unreachable:`FKN could not be reached, so nothing changed. Check your connection, then try again.`,"no-writer":`This browser keeps no site data for FKN Social. Allow site data, then reload.`,newer:`Your friend list was saved by a newer FKN Social. Reload the page to update.`},Gm={"display-name":`A display name has at most 32 characters, and no control or text direction characters.`,bio:`A bio has at most ${mf.toLocaleString(`en`)} characters, and no control or text direction characters.`,links:`You can list at most 5 links.`,link:`Each link starts with https:// and has at most 200 characters.`},Km={title:`Give the panel a title of at most 80 characters, with no control or text direction characters.`,body:`Write panel text of at most ${Qp.toLocaleString(`en`)} characters, with no control or text direction characters.`,caption:`A caption has at most 120 characters, with no control or text direction characters.`,full:`You can have up to 6 panels. Delete one to add another.`,"items-full":`Each artwork panel holds up to 4 pictures. Remove one to add another.`,"not-found":`That panel is no longer on your page. Reload to see the latest list.`,off:`Set this panel to Friends or Public before uploading artwork.`,"sync-failed":`Your panel changed, but FKN rooms did not update yet. Reload in a moment to sync your page.`},qm=`FKN rooms did not answer, so nothing changed. Try again in a moment.`,Jm={...Wm,unavailable:qm,"out-of-claims":Vm[`out-of-claims`],"not-public":`Your profile is set to Only me, so the picture was not saved. Reload the page.`,"too-large":`That picture is too large or could not be made small enough. Pick another.`,kind:`Pick a PNG, JPEG, GIF or WebP picture.`,quota:`Your FKN storage is full, so the picture was not published. Free some space, then try again.`,"too-many":`FKN is not accepting new files from your account right now, so the picture was not published. Try again later.`,"storage-unavailable":`FKN storage did not answer, so the picture was not published. Try again in a moment.`},Ym=e=>{let t=e.replace(/[a-ln-vx-z0-9_]/g,``).length;return t*1.05+(e.length-t)*.72},Xm=e=>({fontSize:`clamp(0.875rem, ${100/Math.max(1,...e.split(/\s+/).map(Ym))}cqi, 1.75rem)`}),Zm=e=>{e?.focus()},Qm=({children:e})=>e===null?null:Z(`p`,{className:`social-error`,role:`alert`,children:e}),$m=({signKey:e,label:t=`Your identicon`,small:n=!1})=>{let{hue:r,cells:i}=uf(e);return Z(`svg`,{className:n?`social-identicon social-identicon-small`:`social-identicon`,viewBox:`0 0 6 6`,role:`img`,"aria-label":t,children:[Z(`rect`,{width:6,height:6,fill:`hsl(${r} 45% 92%)`}),i.map((e,t)=>e&&Z(`rect`,{x:.5+t%5,y:.5+Math.floor(t/5),width:1,height:1,fill:`hsl(${r} 55% 42%)`},t))]})},eh=(e,t,n)=>{let r=t?.url??null,i=t?.key??null,[a,o]=q({storage:null,url:null,key:null,max:0,objectUrl:null});return hu(()=>{if(r===null||i===null){o(e=>e.objectUrl===null&&e.url===null?e:{storage:null,url:null,key:null,max:0,objectUrl:null});return}let t=!0,a=null;return Wp(e,{url:r,key:i},n).then(s=>{if(!t){s!==null&&URL.revokeObjectURL(s);return}a=s,o({storage:e,url:r,key:i,max:n,objectUrl:s})}),()=>{t=!1,a!==null&&URL.revokeObjectURL(a)}},[e,r,i,n]),r===null||i===null?null:a.storage===e&&a.url===r&&a.key===i&&a.max===n?a.objectUrl:void 0},th=({signKey:e,src:t,url:n,label:r=`Your identicon`,avatarAlt:i=`Your avatar`,small:a=!1})=>{let o=a?`social-identicon social-identicon-small`:`social-identicon`;return t===void 0?Z(`span`,{className:o,"data-social-avatar-reading":!0,"aria-hidden":`true`}):t===null?Z($m,{signKey:e,label:r,small:a}):Z(`img`,{className:`${o} social-avatar-img`,src:t,alt:i,"data-social-avatar":n})},nh=async e=>{try{return await navigator.clipboard.writeText(e),!0}catch{return!1}},rh=({text:e,label:t=`Copy`})=>{let[n,r]=q(null);return Z(K,{children:[Z(`button`,{type:`button`,onClick:()=>void nh(e).then(e=>r(e?`Copied`:`Copy did not work. Select the text and copy it.`)),children:t}),n!==null&&Z(`span`,{className:`social-muted`,role:`status`,"data-social-copied":n===`Copied`,children:n})]})},ih=({url:e,site:t})=>{let[n,r]=q(!1),i=t();return Z(`div`,{className:`social-link`,"data-social-link":e,children:[Z(`div`,{className:`social-link-bar`,children:[Z(`span`,{className:`social-link-text`,children:e}),Z(`div`,{className:`social-link-actions`,children:[i!==null&&Z(`button`,{type:`button`,"data-open-link":!0,onClick:()=>void i.open(e).catch(()=>r(!0)),children:`Open`}),Z(rh,{text:e})]})]}),n&&Z(`p`,{className:`social-muted`,children:`It did not open. Copy it instead.`})]})},ah={started:`Started`,watched:`Watched`,completed:`Finished`,rated:`Rated`},oh=Object.keys(ah),sh=36e5,ch={public:[],friends:[]},lh=/^[A-Za-z0-9_-]{22}$/,uh=RegExp(`^[\\x20-\\x7e]{1,64}$`),dh=(e,t)=>typeof e==`string`&&e!==``&&e.isWellFormed()&&ff(e,{max:t,multiline:!1})===null,fh=e=>typeof e==`string`&&pf(e,300)===e,ph=e=>{try{return new URL(e)}catch{return null}},mh=e=>dh(e,100),hh=e=>{let t=ph(e);return t!==null&&(t.protocol===`https:`||t.protocol===`http:`)&&t.origin===e?t.host:e},gh=(e,t)=>{let n=ph(t);return n?.protocol!==`https:`||n.origin!==t||ph(e)?.origin===t},_h=({id:e,app:t,at:n,kind:r,title:i,link:a,detail:o,image:s,subject:c})=>({id:e,app:t,at:n,kind:r,title:i,link:a,...o===void 0?{}:{detail:o},...s===void 0?{}:{image:s},...c===void 0?{}:{subject:c}}),vh=e=>{if(typeof e!=`object`||!e)return null;let{id:t,app:n,at:r,kind:i,title:a,detail:o,link:s,image:c,subject:l}=e;return typeof t!=`string`||!lh.test(t)||!dh(n,100)||typeof r!=`number`||!Number.isSafeInteger(r)||r<0||typeof i!=`string`||!Object.hasOwn(ah,i)||!dh(a,150)||!fh(s)||!gh(s,n)||o!==void 0&&!dh(o,40)||c!==void 0&&!fh(c)||l!==void 0&&(typeof l!=`string`||!uh.test(l))?null:_h({id:t,app:n,at:r,kind:i,title:a,link:s,detail:o,image:c,subject:l})},yh=e=>typeof e==`string`?e.normalize(`NFC`).trim():e,bh=(e,t,n)=>{if(typeof e!=`object`||!e)return null;let{kind:r,title:i,detail:a,link:o,image:s,subject:c}=e,l=yh(a),u=e=>typeof e==`string`?pf(e,300)??``:e;return vh({id:Y(crypto.getRandomValues(new Uint8Array(16))),app:t,at:n,kind:r,title:yh(i),link:u(o),...l===void 0||l===``?{}:{detail:l},...s===void 0?{}:{image:u(s)},...c===void 0?{}:{subject:c}})},xh=e=>{if(!Array.isArray(e))return[];let t=new Set,n=[];for(let r of e){let e=vh(r);if(!(e===null||t.has(e.id))&&(t.add(e.id),n.push(e),n.length===50))break}return n},Sh=(e,t)=>{let n=new Map;for(let r of[...e,...t])n.has(r.id)||n.set(r.id,r);return[...n.values()].sort((e,t)=>t.at-e.at||(e.id<t.id?-1:+(e.id>t.id))).slice(0,50)},Ch=(e,t,n)=>[...e.public,...e.friends].filter(e=>e.app===t&&e.at>n).length,wh=(e,t)=>({...e,public:e.public.filter(e=>!t.includes(e.id)),friends:e.friends.filter(e=>!t.includes(e.id))}),Th=(e,t)=>({...e,public:e.public.filter(e=>e.app!==t),friends:e.friends.filter(e=>e.app!==t)}),Eh=(e,t)=>({...e,public:e.public.filter(e=>e.app!==t),friends:Sh(e.friends,e.public.filter(e=>e.app===t))}),Dh=(e,t)=>[t,...e.filter(e=>e.id!==t.id)].slice(0,50),Oh=(e,t)=>t===`off`?{...e,public:[],friends:[]}:t===`friends`?{...e,public:[],friends:Sh(e.friends,e.public)}:e;function kh(e,t,n=()=>{}){if(!Array.isArray(e))throw TypeError(`"${t}" expected array, got type=${typeof e}`);for(let r=0;r<e.length;r++)n(e[r],`${t}[${r}]`);return e}var Ah=(e,t,n)=>fd(e,t,n),jh=dd;function Mh(e,t=`object`){if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`);return e}function Nh(e,t){if(typeof e!=`function`)throw TypeError(`"${t}" is invalid: expected function, got ${typeof e}`);return e}var Ph=Cd,Fh=(...e)=>Ed(...e),Ih=e=>Td(e),Lh=ld,Rh=e=>kd(e),zh=BigInt(0),Bh=BigInt(1),Vh=e=>e?`"${e}" `:``;function Hh(e,t=``){if(typeof e!=`boolean`)throw TypeError(Vh(t)+`expected boolean, got type=`+typeof e);return e}function Uh(e){if(typeof e==`bigint`){if(!Zh(e))throw RangeError(`positive bigint expected, got `+e)}else jh(e);return e}function Wh(e,t=``){if(typeof e!=`number`){let n=t&&`"${t}" `;throw TypeError(n+`expected number, got type=`+typeof e)}if(!Number.isSafeInteger(e)){let n=t&&`"${t}" `;throw RangeError(n+`expected safe integer, got `+e)}}function Gh(e){if(typeof e!=`string`)throw TypeError(`hex string expected, got `+typeof e);return e===``?zh:BigInt(`0x`+e)}function Kh(e){return Gh(Cd(e))}function qh(e){return Gh(Cd(Xh(fd(e)).reverse()))}function Jh(e,t){if(dd(t),t===0)throw Error(`zero output length is invalid`);e=Uh(e);let n=t*2,r=e.toString(16);if(r.length>n)throw RangeError(`number is too large`);return Td(r.padStart(n,`0`))}function Yh(e,t){return Jh(e,t).reverse()}function Xh(e){return Uint8Array.from(Ah(e))}function Zh(e){return typeof e==`bigint`&&zh<=e}function Qh(e,t,n){return Zh(e)&&Zh(t)&&Zh(n)&&t<=e&&e<n}function $h(e,t,n,r){if(!Qh(t,n,r))throw RangeError(`expected valid `+e+`: `+n+` <= n < `+r+`, got `+t)}function eg(e){if(e<zh)throw Error(`expected non-negative bigint, got `+e);return e===zh?0:e.toString(2).length}var tg=e=>(Wh(e,`n`),(Bh<<BigInt(e))-Bh);function ng(e,t={},n={},r=`object`){Mh(e,r),Mh(t,`fields`),Mh(n,`optFields`);function i(t,n,i){let a=r===`object`?`param "${String(t)}"`:`"${r}.${String(t)}"`,o=e[t];if(!Object.hasOwn(e,t)&&(i?o!==void 0:n!==`function`))throw TypeError(`${a} is invalid: expected own property`);if(i&&o===void 0)return;let s=typeof o;if(s!==n||o===null)throw TypeError(`${a} is invalid: expected ${n}, got ${s}`)}let a=(e,t)=>Object.entries(e).forEach(([e,n])=>i(e,n,t));a(t,!1),a(n,!0)}var rg=BigInt(0),Q=BigInt(1),ig=BigInt(2),ag=BigInt(3),og=BigInt(4),sg=BigInt(5),cg=BigInt(7),lg=BigInt(8),ug=BigInt(9),dg=BigInt(15),fg=BigInt(16),pg=BigInt(`0x10000000000000000`);function mg(e,t){if(t<=rg)throw Error(`mod: expected positive modulus, got `+t);let n=e%t;return n>=rg?n:t+n}function hg(e,t,n){if(n<=Q)throw Error(`pow: expected modulus > 1, got `+n);if(typeof t!=`bigint`)throw TypeError(`invalid exponent: expected bigint, got `+typeof t);if(t<rg)throw Error(`invalid exponent, negatives unsupported`);if(t===rg)return Q;if(t===Q)return e;let r=e%n;if(r<rg&&(r+=n),t<pg){let e=Q;for(;t>rg;)t&Q&&(e=e*r%n),r=r*r%n,t>>=Q;return e}let i=[];for(;t>rg;)i.push(Number(t&dg)),t>>=og;let a=Array(16);a[0]=Q,a[1]=r;for(let e=2;e<16;e++)a[e]=a[e-1]*r%n;let o=a[i[i.length-1]];for(let e=i.length-2;e>=0;e--){o=o*o%n,o=o*o%n,o=o*o%n,o=o*o%n;let t=i[e];t!==0&&(o=o*a[t]%n)}return o}function gg(e,t,n){if(n<=Q)throw Error(`pow2: expected modulus > 1, got `+n);if(t<rg)throw Error(`pow2: expected non-negative exponent, got `+t);let r=e;for(;t-->rg;)r*=r,r%=n;return r}function _g(e,t){if(e===rg)throw Error(`invert: expected non-zero number`);if(t<=Q)throw Error(`invert: expected modulus > 1, got `+t);let n=mg(e,t),r=t,i=rg,a=Q;for(;n!==rg;){let e=r/n,t=r-n*e,o=i-a*e;r=n,n=t,i=a,a=o}if(r!==Q)throw Error(`invert: does not exist`);return mg(i,t)}function vg(e,t,n){let r=e;if(!r.eql(r.sqr(t),n))throw Error(`Cannot find square root`)}function yg(e,t){if((e&Q)===rg)throw Error(t+`: expected odd modulus, got `+e)}function bg(e,t){let n=e,r=(n.ORDER+Q)/og,i=n.pow(t,r);return vg(n,i,t),i}function xg(e,t){let n=e,r=(n.ORDER-sg)/lg,i=n.mul(t,ig),a=n.pow(i,r),o=n.mul(t,a),s=n.mul(n.mul(o,ig),a),c=n.mul(o,n.sub(s,n.ONE));return vg(n,c,t),c}function Sg(e){let t=Ng(e),n=Cg(e),r=n(t,t.neg(t.ONE)),i=n(t,r),a=n(t,t.neg(r)),o=(e+cg)/fg;return((e,t)=>{let n=e,s=n.pow(t,o),c=n.mul(s,r),l=n.mul(s,i),u=n.mul(s,a),d=n.eql(n.sqr(c),t),f=n.eql(n.sqr(l),t);s=n.cmov(s,c,d),c=n.cmov(u,l,f);let p=n.eql(n.sqr(c),t),m=n.cmov(s,c,p);return vg(n,m,t),m})}function Cg(e){if(e<ag)throw Error(`sqrt is not defined for small field`);yg(e,`tonelliShanks`);let t=e-Q,n=0;for(;t%ig===rg;)t/=ig,n++;let r=ig,i=Ng(e);for(;kg(i,r)===1;)if(r++>1e3)throw Error(`Cannot find square root: probably non-prime P`);if(n===1)return bg;let a=i.pow(r,t),o=(t+Q)/ig;return function(e,r){let i=e;if(i.is0(r))return r;if(kg(i,r)!==1)throw Error(`Cannot find square root`);let s=n,c=i.mul(i.ONE,a),l=i.pow(r,t),u=i.pow(r,o);for(;!i.eql(l,i.ONE);){if(i.is0(l))throw Error(`Cannot find square root: probably non-prime P`);let e=1,t=i.sqr(l);for(;!i.eql(t,i.ONE);)if(e++,t=i.sqr(t),e===s)throw Error(`Cannot find square root`);let n=Q<<BigInt(s-e-1),r=i.pow(c,n);s=e,c=i.sqr(r),l=i.mul(l,c),u=i.mul(u,r)}return u}}function wg(e){return yg(e,`Fp.sqrt`),e%og===ag?bg:e%lg===sg?xg:e%fg===ug?Sg(e):Cg(e)}var Tg=(e,t)=>(mg(e,t)&Q)===Q,Eg=[`create`,`isValid`,`is0`,`neg`,`inv`,`sqrt`,`sqr`,`eql`,`add`,`sub`,`mul`,`pow`,`div`,`addN`,`subN`,`mulN`,`sqrN`];function Dg(e){if(Mh(e,`field`),typeof e.ORDER!=`bigint`)throw TypeError(`param "ORDER" is invalid: expected bigint, got `+typeof e.ORDER);Wh(e.BYTES,`BYTES`),Wh(e.BITS,`BITS`);for(let t of Eg)Nh(e[t],`field.`+t);if(e.BYTES<1||e.BITS<1)throw Error(`invalid field: expected BYTES/BITS > 0`);if(e.ORDER<=Q)throw Error(`invalid field: expected ORDER > 1, got `+e.ORDER);return e}function Og(e,t,n=!1){Dg(e),kh(t,`nums`),Hh(n,`passZero`);let r=e,i=Array(t.length).fill(n?r.ZERO:void 0),a=t.reduce((e,t,n)=>r.is0(t)?e:(i[n]=e,r.mul(e,t)),r.ONE),o=r.inv(a);return t.reduceRight((e,t,n)=>r.is0(t)?e:(i[n]=r.mul(e,i[n]),r.mul(e,t)),o),i}function kg(e,t){Dg(e);let n=e;yg(n.ORDER,`FpLegendre`);let r=(n.ORDER-Q)/ig,i=n.pow(t,r),a=n.eql(i,n.ONE),o=n.eql(i,n.ZERO),s=n.eql(i,n.neg(n.ONE));if(!a&&!o&&!s)throw Error(`invalid Legendre symbol result`);return a?1:o?0:-1}function Ag(e,t){if(t!==void 0&&jh(t),e<=rg)throw Error(`invalid n length: expected positive n, got `+e);if(t!==void 0&&t<1)throw Error(`invalid n length: expected positive bit length, got `+t);let n=eg(e);if(t!==void 0&&t<n)throw Error(`invalid n length: expected nBitLength (${t}) >= bitLen(n) (${n})`);let r=t===void 0?n:t;return{nBitLength:r,nByteLength:Math.ceil(r/8)}}var jg=new WeakMap,Mg=class{ORDER;BITS;BYTES;isLE;ZERO=rg;ONE=Q;_lengths;_mod;constructor(e,t={}){if(e<=Q)throw Error(`invalid field: expected ORDER > 1, got `+e);let n;this.isLE=!1,typeof t==`object`&&t&&(typeof t.BITS==`number`&&(n=t.BITS),typeof t.sqrt==`function`&&Object.defineProperty(this,"sqrt",{value:t.sqrt,enumerable:!0}),typeof t.isLE==`boolean`&&(this.isLE=t.isLE),t.allowedLengths&&(this._lengths=Object.freeze(t.allowedLengths.slice())),typeof t.modFromBytes==`boolean`&&(this._mod=t.modFromBytes));let{nBitLength:r,nByteLength:i}=Ag(e,n);if(i>2048)throw Error(`invalid field: expected ORDER of <= 2048 bytes`);this.ORDER=e,this.BITS=r,this.BYTES=i,Object.freeze(this)}create(e){return mg(e,this.ORDER)}isValid(e){if(typeof e!=`bigint`)throw TypeError(`invalid field element: expected bigint, got `+typeof e);return rg<=e&&e<this.ORDER}is0(e){return e===rg}isValidNot0(e){return!this.is0(e)&&this.isValid(e)}isOdd(e){return(e&Q)===Q}neg(e){return mg(-e,this.ORDER)}eql(e,t){return e===t}sqr(e){return mg(e*e,this.ORDER)}add(e,t){return mg(e+t,this.ORDER)}sub(e,t){return mg(e-t,this.ORDER)}mul(e,t){return mg(e*t,this.ORDER)}pow(e,t){return hg(e,t,this.ORDER)}div(e,t){return mg(e*_g(t,this.ORDER),this.ORDER)}sqrN(e){return e*e}addN(e,t){return e+t}subN(e,t){return e-t}mulN(e,t){return e*t}inv(e){return _g(e,this.ORDER)}sqrt(e){let t=jg.get(this);return t||jg.set(this,t=wg(this.ORDER)),t(this,e)}toBytes(e){return this.isLE?Yh(e,this.BYTES):Jh(e,this.BYTES)}fromBytes(e,t=!1){Ah(e);let{_lengths:n,BYTES:r,isLE:i,ORDER:a,_mod:o}=this;if(n){if(e.length<1||!n.includes(e.length)||e.length>r)throw Error(`Field.fromBytes: expected `+n+` bytes, got `+e.length);let t=new Uint8Array(r);t.set(e,i?0:t.length-e.length),e=t}if(e.length!==r)throw Error(`Field.fromBytes: expected `+r+` bytes, got `+e.length);let s=i?qh(e):Kh(e);if(o&&(s=mg(s,a)),!t&&!this.isValid(s))throw Error(`invalid field element: outside of range 0..ORDER`);return s}invertBatch(e){return Og(this,e,!0)}cmov(e,t,n){return Hh(n,`condition`),n?t:e}};function Ng(e,t={}){return Object.freeze(Mg.prototype),new Mg(e,t)}var Pg=BigInt(0),Fg=BigInt(1),Ig=BigInt(4),Lg=16,Rg=128,zg=5,Bg=2**31;function Vg(e){let t=e;if(typeof t!=`function`)throw TypeError(`"Point" expected constructor, got type=`+typeof e);Nh(t.fromAffine,`Point.fromAffine`),Nh(t.fromBytes,`Point.fromBytes`),Nh(t.fromHex,`Point.fromHex`),Mh(t.BASE,`Point.BASE`),Mh(t.ZERO,`Point.ZERO`),Dg(t.Fp),Dg(t.Fn)}function Hg(e,t){Vg(e),Kg(t,e);let n=Og(e.Fp,t.map(e=>e.Z));return t.map((t,r)=>e.fromAffine(t.toAffine(n[r])))}function Ug(e,t,n=1){if(!Number.isSafeInteger(e)||e<n||e>t)throw Error(`invalid window size, expected [`+n+`..`+t+`], got W=`+e)}function Wg(e,t){let n=e*(4*t+128);if(n>Bg)throw Error(`invalid window size: table would need ~`+Math.ceil(n/2**20)+` MiB, max `+Bg/2**20+` MiB`)}function Gg(e,t){if(e!==void 0){Nh(e,`randomBytes`);try{let n=e(t);if(!Lh(n)||n.length!==t)return}catch{return}return e}}function Kg(e,t){kh(e,`points`),e.forEach((e,n)=>{if(!(e instanceof t))throw Error(`invalid point at index `+n)})}function qg(e,t,n){if(!Array.isArray(e))throw Error(`array of scalars expected`);e.forEach((e,r)=>{if(!(n===void 0?t.isValid(e):Zh(e)&&e<n))throw Error(`invalid scalar at index `+r)})}var Jg=new WeakMap;function Yg(e){return Jg.get(e)||1}function Xg(e,t){let n=e.double(),r=[e];for(let e=1;e<t;e++)r.push(r[e-1].add(n));return r}function Zg(e,t){let n=2**t,r=n/2,i=BigInt(n-1),a=[];for(;e>Pg;){let t=0;e&Fg&&(t=Number(e&i),t>=r&&(t-=n),e-=BigInt(t)),a.push(t),e>>=Fg}return a}function Qg(e,t,n){let r=2**t,i=r/2,a=BigInt(r-1),o=BigInt(t),s=[];for(let t=0;t<n;t++){let t=Number(e&a);e>>=o,t>i&&(t-=r,e+=Fg),s.push(t)}if(e!==Pg)throw Error(`invalid wnaf`);return s}function $g(e,t,n){let r=0;for(let e of n)r=Math.max(r,e.length);let i=e;for(let e=r-1;e>=0;e--){e!==r-1&&(i=i.double());for(let r=0;r<n.length;r++){let a=n[r][e];if(a){let e=t[r][Math.abs(a)-1>>1];i=i.add(a<0?e.negate():e)}}}return i}var e_=class{Point;BASE;ZERO;randomBytes;wnafPrecomputes=new WeakMap;baseCanBeBlinded;bits;constructor(e,t){Vg(e),this.randomBytes=Gg(t,Lg),this.Point=e,this.BASE=e.BASE,this.ZERO=e.ZERO,this.bits=e.Fn.BITS}buildWnafTable(e,t,n){let r=Math.ceil(n/t)+1,i=2**(t-1),a=[],o=e;for(let e=0;e<r;e++){let e=o;for(let t=0;t<i;t++)a.push(e),e=e.add(o);o=a[a.length-1].double()}return{W:t,bits:n,windows:r,comp:a}}wnafCachedCT(e,t){let{W:n,windows:r,comp:i}=e,a=2**(n-1),o=Qg(t,n,r),s=this.ZERO,c=this.BASE;for(let e=0;e<r;e++){let t=o[e],n=e*a,r=Math.abs(t)-1,l=i[n];for(let e=1;e<a;e++)l=e===r?i[n+e]:l;let u=l.negate();t===0?c=c.add(i[n]):s=s.add(t<0?u:l)}return{p:s,f:c}}getWnafPrecomputes(e,t,n,r){let i=this.wnafPrecomputes.get(t),a=i?.find(t=>t.W===e&&t.bits===n);return a||(a=this.buildWnafTable(t,e,n),typeof r==`function`&&(a={...a,comp:r(a.comp)}),i||(i=[],this.wnafPrecomputes.set(t,i)),i.push(a)),a}assertPoint(e){if(!(e instanceof this.Point))throw TypeError(`"point" expected Point instance, got type=`+typeof e)}validateMulInput(e,t){if(this.assertPoint(e),!Qh(t,Fg,this.Point.Fn.ORDER))throw Error(`invalid scalar`)}runCT(e,t,n,r){let i=Yg(e);return i===1?this.fixedWindowCT(e,t,n):this.wnafCachedCT(this.getWnafPrecomputes(i,e,n,r),t)}mulCT(e,t,n){return this.validateMulInput(e,t),this.runCT(e,t,this.bits,n)}mulCTBlinded(e,t,n){if(this.validateMulInput(e,t),this.randomBytes===void 0)throw Error(`randomBytes is required for scalar blinding`);let r=this.Point.Fn.BITS+Rg,i=this.randomBytes(Lg);if(!Lh(i)||i.length!==Lg)throw Error(`randomBytes returned invalid byte array`);i[0]=i[0]&63|128;let a=t+Kh(i)*this.Point.Fn.ORDER;return this.runCT(e,a,r,n)}fixedWindowCT(e,t,n){let r=zg,i=tg(r),a=Array(32);a[0]=this.ZERO;for(let t=1;t<32;t++)a[t]=a[t-1].add(e);let o=Math.ceil(n/r),s=this.ZERO;for(let e=o-1;e>=0;e--){if(e!==o-1)for(let e=0;e<r;e++)s=s.double();let n=Number(t>>BigInt(e*r)&i),c=a[0];for(let e=1;e<32;e++)c=e===n?a[e]:c;s=s.add(c)}return{p:s,f:s}}shouldBlind(e,t){return this.randomBytes===void 0?!1:t===Fg||e===this.BASE&&(this.baseCanBeBlinded===void 0&&(this.baseCanBeBlinded=this.mulUnsafe(this.BASE,this.Point.Fn.ORDER).is0()),this.baseCanBeBlinded)}mulSecret(e,t,n,r){return this.shouldBlind(e,n)?this.mulCTBlinded(e,t,r):this.mulCT(e,t,r)}mulUnsafe(e,t,n){if(this.assertPoint(e),!Zh(t))throw Error(`invalid scalar`);let r=Yg(e);if(r===1||t>=this.Point.Fn.ORDER)return t_(this.Point,[e],[t],!0);let i=this.getWnafPrecomputes(r,e,this.bits,n);return this.wnafCachedCT(i,t).p}setWindowSize(e,t){this.assertPoint(e),Ug(t,this.bits),Wg((Math.ceil((this.bits+Rg)/t)+1)*2**(t-1),this.Point.Fp.BYTES),Jg.set(e,t),this.wnafPrecomputes.delete(e)}hasWindowSize(e){return Yg(e)!==1}};function t_(e,t,n,r=!1){if(Vg(e),Kg(t,e),Hh(r,`allowOversized`),qg(n,e.Fn,r?e.Fn.ORDER**Ig:void 0),t.length!==n.length)throw Error(`arrays of points and scalars must have equal length`);let i=t.map(e=>Xg(e,4)),a=n.map(e=>Zg(e,4));return $g(e.ZERO,i,a)}function n_(e,t,n){if(t){if(t.ORDER!==e)throw Error(`Field.ORDER must match order: Fp == p, Fn == n`);return Dg(t),t}return Ng(e,{isLE:n})}function r_(e,t,n={},r){if(e!==`weierstrass`&&e!==`edwards`)throw Error(`expected curve type "weierstrass" or "edwards"`);if(r===void 0&&(r=e===`edwards`),!t||typeof t!=`object`)throw Error(`expected valid ${e} CURVE object`);ng(n);for(let e of[`p`,`n`,`h`]){let n=t[e];if(!(Zh(n)&&n!==Pg))throw Error(`CURVE.${e} must be positive bigint`)}let i=n_(t.p,n.Fp,r),a=n_(t.n,n.Fn,r),o=[`Gx`,`Gy`,`a`,e===`weierstrass`?`b`:`d`];for(let e of o)if(!i.isValid(t[e]))throw Error(`CURVE.${e} must be valid field element of CURVE.Fp`);return t=Object.freeze(Object.assign({},t)),{CURVE:t,Fp:i,Fn:a}}function i_(e,t){return function(n){let r=e(n);return{secretKey:r,publicKey:t(r)}}}var a_=BigInt(0),o_=BigInt(1),s_=BigInt(2),c_=BigInt(4),l_=BigInt(8);function u_(e,t,n,r){let i=e.sqr(n),a=e.sqr(r),o=e.add(e.mul(t.a,i),a),s=e.add(e.ONE,e.mul(t.d,e.mul(i,a)));return e.eql(o,s)}function d_(e,t={}){ng(t,{},{},`extraOpts`);let n=t,r=r_(`edwards`,e,n,n.FpFnLE),{Fp:i,Fn:a}=r,o=r.CURVE,{h:s}=o;if(kg(i,o.a)!==1)throw Error(`edwards: CURVE.a must be a square in Fp for complete addition formulas`);if(kg(i,o.d)!==-1)throw Error(`edwards: CURVE.d must be a non-square in Fp for complete addition formulas`);ng(n,{},{uvRatio:`function`,randomBytes:`function`});let c=n.randomBytes===void 0?Rh:n.randomBytes,l=s_<<BigInt(i.BYTES*8)-o_;function u(e){if(!i.isOdd)throw Error(`Field does not have .isOdd()`);return i.isOdd(e)}let d=n.uvRatio===void 0?(e,t)=>{try{return{isValid:!0,value:i.sqrt(i.div(e,t))}}catch{return{isValid:!1,value:a_}}}:n.uvRatio;if(!u_(i,o,o.Gx,o.Gy))throw Error(`bad curve params: generator point`);let f=i.eql(o.a,i.neg(i.ONE))?e=>i.neg(e):i.eql(o.a,i.ONE)?e=>e:e=>i.mul(o.a,e);function p(e,t,n=!1){let r=n?o_:a_;return $h(`coordinate `+e,t,r,l),t}function m(e){if(!(e instanceof h))throw Error(`EdwardsPoint expected`)}class h{static BASE=new h(o.Gx,o.Gy,i.ONE,i.mul(o.Gx,o.Gy));static ZERO=new h(i.ZERO,i.ONE,i.ONE,i.ZERO);static Fp=i;static Fn=a;X;Y;Z;T;constructor(e,t,n,r){this.X=p(`x`,e),this.Y=p(`y`,t),this.Z=p(`z`,n,!0),this.T=p(`t`,r),Object.freeze(this)}static CURVE(){return o}static fromAffine(e){if(e instanceof h)throw Error(`extended point not allowed`);let{x:t,y:n}=e||{};return p(`x`,t),p(`y`,n),new h(t,n,i.ONE,i.mul(t,n))}static fromBytes(e,t=!1){let n=i.BYTES,{a:r,d:a}=o;e=Xh(Ah(e,n,`point`)),Hh(t,`zip215`);let s=Xh(e),c=e[n-1];s[n-1]=c&-129;let f=qh(s);$h(`point.y`,f,a_,t?l:i.ORDER);let p=i.sqr(f),m=i.sub(p,i.ONE),g=i.sub(i.mulN(a,p),r),{isValid:_,value:v}=d(m,g);if(!_)throw Error(`bad point: invalid y coordinate`);let y=u(v),b=!!(c&128);if(!t&&i.is0(v)&&b)throw Error(`bad point: x=0 and x_0=1`);return b!==y&&(v=i.neg(v)),h.fromAffine({x:v,y:f})}static fromHex(e,t=!1){return h.fromBytes(Ih(e),t)}get x(){return this.toAffine().x}get y(){return this.toAffine().y}precompute(e=6,t=!0){return _.setWindowSize(this,e),t||this.multiply(s_),this}assertValidity(){let e=this,{a:t,d:n}=o;if(e.is0())throw Error(`bad point: ZERO`);let{X:r,Y:a,Z:s,T:c}=e,l=i.sqr(r),u=i.sqr(a),d=i.sqr(s),f=i.sqr(d),p=i.mul(l,t),m=i.mul(i.add(p,u),d),h=i.add(f,i.mul(n,i.mul(l,u)));if(!i.eql(m,h))throw Error(`bad point: equation left != right (1)`);let g=i.mul(r,a),_=i.mul(s,c);if(!i.eql(g,_))throw Error(`bad point: equation left != right (2)`)}equals(e){m(e);let{X:t,Y:n,Z:r}=this,{X:a,Y:o,Z:s}=e,c=i.mul(t,s),l=i.mul(a,r),u=i.mul(n,s),d=i.mul(o,r);return i.eql(c,l)&&i.eql(u,d)}is0(){return this.equals(h.ZERO)}negate(){return new h(i.neg(this.X),this.Y,this.Z,i.neg(this.T))}double(){let{X:e,Y:t,Z:n}=this,r=i.sqr(e),a=i.sqr(t),o=i.mul(i.sqr(n),s_),s=f(r),c=i.addN(e,t),l=i.sub(i.subN(i.sqr(c),r),a),u=i.addN(s,a),d=i.subN(u,o),p=i.subN(s,a),m=i.mul(l,d),g=i.mul(u,p),_=i.mul(l,p),v=i.mul(d,u);return new h(m,g,v,_)}add(e){m(e);let{d:t}=o,{X:n,Y:r,Z:a,T:s}=this,{X:c,Y:l,Z:u,T:d}=e,p=i.mul(n,c),g=i.mul(r,l),_=i.mul(i.mulN(s,t),d),v=i.mul(a,u),y=i.sub(i.subN(i.mulN(i.addN(n,r),i.addN(c,l)),p),g),b=i.subN(v,_),x=i.addN(v,_),S=i.sub(g,f(p)),C=i.mul(y,b),w=i.mul(x,S),T=i.mul(y,S),E=i.mul(b,x);return new h(C,w,E,T)}subtract(e){return m(e),this.add(e.negate())}multiply(e){if(!a.isValidNot0(e))throw RangeError(`invalid scalar: expected 1 <= sc < curve.n`);let{p:t,f:n}=_.mulSecret(this,e,s,g);return g([t,n])[0]}multiplyUnsafe(e){if(!a.isValid(e))throw RangeError(`invalid scalar: expected 0 <= sc < curve.n`);return e===a_?h.ZERO:this.is0()||e===o_?this:_.mulUnsafe(this,e,g)}isSmallOrder(){return this.clearCofactor().is0()}isTorsionFree(){return _.mulUnsafe(this,o.n).is0()}toAffine(e){let t=this,n=e;if(n!=null&&typeof n!=`bigint`)throw TypeError(`"invertedZ" expected bigint, got type=`+typeof n);let{X:r,Y:a,Z:o}=t,s=t.is0();n??=s?i.create(l_):i.inv(o);let c=i.mul(r,n),l=i.mul(a,n),u=i.mul(o,n);if(s)return{x:i.ZERO,y:i.ONE};if(!i.eql(u,i.ONE))throw Error(`invZ was invalid`);return{x:c,y:l}}clearCofactor(){return s===o_?this:s===s_?this.double():s===c_?this.double().double():s===l_?this.double().double().double():this.multiplyUnsafe(s)}toBytes(){let{x:e,y:t}=this.toAffine(),n=i.toBytes(t);return n[n.length-1]|=u(e)?128:0,n}toHex(){return Ph(this.toBytes())}toString(){return`<Point ${this.is0()?`ZERO`:this.toHex()}>`}}let g=e=>Hg(h,e),_=new e_(h,c);return _.bits>=6&&h.BASE.precompute(6),Object.freeze(h.prototype),Object.freeze(h),h}function f_(e,t,n={}){if(Vg(e),typeof t!=`function`)throw Error(`"hash" function param is required`);let r=t,i=n;ng(i,{},{adjustScalarBytes:`function`,randomBytes:`function`,domain:`function`,prehash:`function`,zip215:`boolean`,mapToCurve:`function`,toMontgomery:`function`,toMontgomerySecret:`function`});let{prehash:a}=i,{BASE:o,Fp:s,Fn:c}=e,l=r.outputLen,u=2*s.BYTES;if(l!==void 0&&(Wh(l,`hash.outputLen`),l!==u))throw Error(`hash.outputLen must be ${u}, got ${l}`);let d=i.randomBytes===void 0?Rh:i.randomBytes,f=i.toMontgomery,p=i.toMontgomerySecret,m=i.adjustScalarBytes===void 0?e=>e:i.adjustScalarBytes,h=i.domain===void 0?(e,t,n)=>{if(Hh(n,`phflag`),t.length||n)throw Error(`Contexts/pre-hash are not supported`);return e}:i.domain;function g(e){return c.create(qh(e))}function _(e){let t=T.secretKey;Ah(e,T.secretKey,`secretKey`);let n=Ah(r(e),2*t,`hashedSecretKey`),i=m(n.slice(0,t));return{head:i,prefix:n.slice(t,2*t),scalar:g(i)}}function v(e){let{head:t,prefix:n,scalar:r}=_(e),i=o.multiply(r);return{head:t,prefix:n,scalar:r,point:i,pointBytes:i.toBytes()}}function y(e){return v(e).pointBytes}function b(e=Uint8Array.of(),...t){let n=Fh(...t);return g(r(h(n,Ah(e,void 0,`context`),!!a)))}function x(e,t,n={}){ng(n,{},{},`options`),e=Xh(Ah(e,void 0,`message`)),a&&(e=a(e));let{prefix:r,scalar:i,pointBytes:s}=v(t),l=b(n.context,r,e),u=o.multiply(l).toBytes(),d=b(n.context,u,s,e),f=c.create(l+d*i);if(!c.isValid(f))throw Error(`sign failed: invalid s`);return Ah(Fh(u,c.toBytes(f)),T.signature,`result`)}let S={zip215:i.zip215};function C(t,n,r,i=S){ng(i);let{context:s}=i,c=i.zip215===void 0?!!S.zip215:i.zip215,l=T.signature;t=Ah(t,l,`signature`),n=Ah(n,void 0,`message`),r=Ah(r,T.publicKey,`publicKey`),c!==void 0&&Hh(c,`zip215`),a&&(n=a(n));let u=l/2,d=t.subarray(0,u),f=qh(t.subarray(u,l)),p,m,h;try{p=e.fromBytes(r,c),m=e.fromBytes(d,c),h=o.multiplyUnsafe(f)}catch{return!1}if(!c&&p.isSmallOrder())return!1;let g=b(s,d,r,n);return m.add(p.multiplyUnsafe(g)).subtract(h).clearCofactor().is0()}let w=s.BYTES,T={secretKey:w,publicKey:w,signature:2*w,seed:w};function E(e){return e=e===void 0?d(T.seed):e,Ah(e,T.seed,`seed`)}function D(e){return Lh(e)&&e.length===T.secretKey}function O(t,n){try{return!!e.fromBytes(t,n===void 0?S.zip215:n)}catch{return!1}}let k={getExtendedPublicKey:v,randomSecretKey:E,isValidSecretKey:D,isValidPublicKey:O,toMontgomery(t){if(f===void 0)throw Error(`Montgomery conversion is not supported for this curve`);return f(e.fromBytes(t))},toMontgomerySecret(e){if(p===void 0)throw Error(`Montgomery conversion is not supported for this curve`);return p(e)}};return Object.freeze(T),Object.freeze(k),Object.freeze({keygen:i_(E,y),getPublicKey:y,sign:x,verify:C,utils:k,Point:e,lengths:T})}var p_=BigInt(0),m_=BigInt(1),h_=BigInt(2);function g_(e,t){return e+t-(t>>m_<<m_)}function __(e){let t=BigInt(6)*e;return(n,r,i)=>{let a=r+i,o=((t+i-r)*n+r)%e;return{x_2:o,x_3:a-o}}}function v_(e){return ng(e,{P:`bigint`,type:`string`,adjustScalarBytes:`function`,powPminus2:`function`},{randomBytes:`function`,scalarMultBase:`function`}),Object.freeze({...e})}function y_(e){let t=v_(e),{P:n,type:r,adjustScalarBytes:i,powPminus2:a,randomBytes:o}=t,s=t.scalarMultBase,c=r===`x25519`;if(!c&&r!==`x448`)throw Error(`invalid type`);let l=o===void 0?Rh:o,u=c?255:448,d=__(n),f=c?32:56,p=BigInt(c?9:5),m=BigInt(c?121665:39081),h=c?h_**BigInt(254):h_**BigInt(447),g=h+(c?BigInt(8)*(h_**BigInt(251)-m_):BigInt(4)*(h_**BigInt(445)-m_))+m_,_=e=>mg(e,n),v=y(p);function y(e){return Yh(_(e),f)}function b(e){let t=Xh(Ah(e,f,`uCoordinate`));return c&&(t[31]&=127),_(qh(t))}function x(e){return qh(i(Xh(Ah(e,f,`scalar`))))}let S=new Set(c?[p_,m_,n-m_,BigInt(`325606250916557431795983626356110631294008115727848805560023387167927233504`),BigInt(`39382357235489614581723060781553021112529911719440698176882885853963445705823`)]:[p_,m_,n-m_]);function C(e,t){let n=b(t);if(S.has(n))throw Error(`invalid private or public key received`);let r=D(n,x(e));if(r===p_)throw Error(`invalid private or public key received`);return y(r)}function w(e){if(s===void 0)return C(e,v);let t=x(e);$h(`scalar`,t,h,g);let n=_(s(t));if(n===p_)throw Error(`invalid private or public key received`);return y(n)}let T=w,E=C;function D(e,t){$h(`u`,e,p_,n),$h(`scalar`,t,h,g);let r=t,i=e,o=m_,s=p_,c=e,l=m_,f=r^r>>m_;for(let e=BigInt(u-1);e>=p_;e--){let t=g_(n,f>>e);({x_2:o,x_3:c}=d(t,o,c)),{x_2:s,x_3:l}=d(t,s,l);let r=o+s,a=_(r*r),u=o-s,p=_(u*u),h=a-p,g=c+l,v=c-l,y=_(v*r),b=_(g*u),x=y+b,S=y-b;c=_(x*x),l=_(i*_(S*S)),o=_(a*p),s=_(h*(a+_(m*h)))}let p=g_(n,r);({x_2:o,x_3:c}=d(p,o,c)),{x_2:s,x_3:l}=d(p,s,l);let v=a(s);return _(o*v)}let O={secretKey:f,publicKey:f,seed:f},k=e=>(e=e===void 0?l(f):e,Ah(e,O.seed,`seed`),e),A={randomSecretKey:k};return Object.freeze(O),Object.freeze(A),Object.freeze({keygen:i_(k,T),getSharedSecret:E,getPublicKey:T,scalarMult:C,scalarMultBase:w,utils:A,GuBytes:v.slice(),lengths:O})}var b_=BigInt(0),x_=BigInt(1),S_=BigInt(2),C_=BigInt(3),w_=BigInt(5),T_=BigInt(8),E_=BigInt(`0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffed`),D_={p:E_,n:BigInt(`0x1000000000000000000000000000000014def9dea2f79cd65812631a5cf5d3ed`),h:T_,a:BigInt(`0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffec`),d:BigInt(`0x52036cee2b6ffe738cc740797779e89800700a4d4141d8ab75eb4dca135978a3`),Gx:BigInt(`0x216936d3cd6e53fec0a4e231fdd6dc5c692cc7609525a7b2c9562d608f25d51a`),Gy:BigInt(`0x6666666666666666666666666666666666666666666666666666666666666658`)};function O_(e){let t=BigInt(10),n=BigInt(20),r=BigInt(40),i=BigInt(80),a=E_,o=e*e%a*e%a,s=gg(gg(o,S_,a)*o%a,x_,a)*e%a,c=gg(s,w_,a)*s%a,l=gg(c,t,a)*c%a,u=gg(l,n,a)*l%a,d=gg(u,r,a)*u%a;return{pow_p_5_8:gg(gg(gg(gg(d,i,a)*d%a,i,a)*d%a,t,a)*c%a,S_,a)*e%a,b2:o}}function k_(e){return e[0]&=248,e[31]&=127,e[31]|=64,e}var A_=BigInt(`19681161376707505956807079304988542015446066515923890162744021073123829784752`);function j_(e,t){let n=E_,r=mg(t*t*t,n),i=O_(e*mg(r*r*t,n)).pow_p_5_8,a=mg(e*r*i,n),o=mg(t*a*a,n),s=a,c=mg(a*A_,n),l=o===e,u=o===mg(-e,n),d=o===mg(-e*A_,n);return l&&(a=s),(u||d)&&(a=c),Tg(a,n)&&(a=mg(-a,n)),{isValid:l||u,value:a}}var M_=d_(D_,{uvRatio:j_}),N_=M_.Fp;function P_(e){let{y:t}=e;return N_.toBytes(N_.div(x_+t,x_-t))}function F_(e){let t=M_.Fp.BYTES;return fd(e,t),k_(Jd(e.subarray(0,t))).subarray(0,t)}function I_(e){return f_(M_,Jd,Object.assign({adjustScalarBytes:k_,toMontgomery:P_,toMontgomerySecret:F_,zip215:!0},e))}var L_=I_({}),R_=(()=>{let e=E_,t=t=>{let{pow_p_5_8:n,b2:r}=O_(t);return mg(gg(n,C_,e)*r,e)};return y_({P:e,type:`x25519`,powPminus2:t,adjustScalarBytes:k_,scalarMultBase:n=>{let r=mg(n,M_.Fn.ORDER);if(r===b_)return b_;let i=M_.BASE.multiply(r);return mg((i.Z+i.Y)*t(mg(i.Z-i.Y,e)),e)}})})(),z_=class{oHash;iHash;blockLen;outputLen;canXOF=!1;finished=!1;destroyed=!1;constructor(e,t){if(pd(e),fd(t,void 0,`key`),this.iHash=e.create(),typeof this.iHash.update!=`function`)throw Error(`expected Hash instance`);this.blockLen=this.iHash.blockLen,this.outputLen=this.iHash.outputLen;let n=this.blockLen,r=new Uint8Array(n);r.set(t.length>n?e.create().update(t).digest():t);for(let e=0;e<r.length;e++)r[e]^=54;this.iHash.update(r),this.oHash=e.create();for(let e=0;e<r.length;e++)r[e]^=106;this.oHash.update(r),vd(r)}update(e){return gd(this),this.iHash.update(e),this}digestInto(e){gd(this),_d(e,this),this.finished=!0;let t=e.subarray(0,this.outputLen);this.iHash.digestInto(t),this.oHash.update(t),this.oHash.digestInto(t),this.destroy()}digest(){let e=new Uint8Array(this.oHash.outputLen);return this.digestInto(e),e}_cloneInto(e){e||=Object.create(Object.getPrototypeOf(this),{});let{oHash:t,iHash:n,finished:r,destroyed:i,blockLen:a,outputLen:o,canXOF:s}=this;return e=e,e.finished=r,e.destroyed=i,e.blockLen=a,e.outputLen=o,e.canXOF=s,e.oHash=t._cloneInto(e.oHash),e.iHash=n._cloneInto(e.iHash),e}clone(){return this._cloneInto()}destroy(){this.destroyed=!0,this.oHash.destroy(),this.iHash.destroy()}},B_=(()=>{let e=((e,t,n)=>new z_(e,t).update(n).digest());return e.create=(e,t)=>new z_(e,t),e})(),V_=Uint8Array.of(0),H_=Uint8Array.of();function U_(e,t,n,r=32,i){pd(e),dd(r,`length`),fd(t,void 0,`prk`);let a=e.outputLen;if(t.length<a)throw Error(`"prk" must be at least HashLen octets`);if(r>255*a)throw Error(`Length must be <= 255*HashLen`);let o=Math.ceil(r/a);if(n===void 0?n=H_:fd(n,void 0,`info`),!o)return i&&vd(t),new Uint8Array;let s=i&&o===1?t:new Uint8Array(o*a),{iHash:c,oHash:l}=B_.create(e,t),u=i?t:new Uint8Array(a),d=o>1?i?.iHash||e.create():void 0;for(let e=0;e<o-1;e++){V_[0]=e+1;let t=c._cloneInto(d);e&&t.update(u),t.update(n).update(V_).digestInto(u),l._cloneInto(d).update(u).digestInto(u),s.set(u,a*e)}if(V_[0]=o,o>1&&c.update(u),c.update(n).update(V_).digestInto(u),l.update(u).digestInto(u),s.set(u,a*(o-1)),c.destroy(),l.destroy(),d?.destroy(),u!==s&&vd(u),vd(V_),r===s.length)return s;let f=s.slice(0,r);return vd(s),f}var W_=(e,t,n,r,i)=>{pd(e),n===void 0&&(n=new Uint8Array(e.outputLen));let a=B_.create(e,n).update(t);return U_(e,a.digest(),r,i,a)},G_=`fkn/social/v1/sign`,K_=`fkn/social/v1/dh`,q_=`fkn/social/v1/hello`,J_=`fkn/social/v1/offer`,Y_=`fkn/social/v1/accept`,X_=`fkn/social/v1/handshake`,Z_=`fkn/social/v1/name`,Q_=`fkn/social/v2/name`,$_=`fkn/social/v1/name-room`,ev=`fkn/social/v1/request`,tv=`fkn/social/v1/request-seal`,nv=`fkn/social/v1/friends`,rv=`fkn/social/v1/friend-slot`,iv=`fkn/social/v1/page`,av=e=>new TextEncoder().encode(e),ov=()=>crypto.getRandomValues(new Uint8Array(32)),sv=e=>{if(e.length!==32)throw Error(`social: a seed is 32 bytes`);let t=W_(qd,e,void 0,av(G_),32),n=W_(qd,e,void 0,av(K_),32);return{signSeed:t,signKey:L_.getPublicKey(t),dhSeed:n,dhKey:R_.getPublicKey(n)}},cv={blue:{label:`Blue`,light:{accent:`#2f5bd3`,text:`#ffffff`},dark:{accent:`#7c9cff`,text:`#0d1430`}},purple:{label:`Purple`,light:{accent:`#7442c8`,text:`#ffffff`},dark:{accent:`#b99cff`,text:`#1f1236`}},pink:{label:`Pink`,light:{accent:`#b8327a`,text:`#ffffff`},dark:{accent:`#ff8ac4`,text:`#3a0f26`}},red:{label:`Red`,light:{accent:`#c0352b`,text:`#ffffff`},dark:{accent:`#ff8f84`,text:`#3d0f0b`}},orange:{label:`Orange`,light:{accent:`#b04e0f`,text:`#ffffff`},dark:{accent:`#ffa163`,text:`#3a1a05`}},green:{label:`Green`,light:{accent:`#2a7a3b`,text:`#ffffff`},dark:{accent:`#6fd38a`,text:`#0b2a13`}},teal:{label:`Teal`,light:{accent:`#0f7671`,text:`#ffffff`},dark:{accent:`#5fd0c8`,text:`#062a28`}},grey:{label:`Grey`,light:{accent:`#5c5a55`,text:`#ffffff`},dark:{accent:`#bdb9b0`,text:`#1d1c1a`}}},lv=Object.keys(cv),uv={steel:{label:`Steel`,light:!1,bg:`#13161a`,sheet:`#181c21`,panel:`#20252c`,head:`#2b333e`,border:`#38414e`,text:`#f0f2f5`,muted:`#adb5c0`,accent:`#8cb4d8`,accentText:`#0f1720`,pill:`#283647`,skyTop:`#262d37`,skyBot:`#13161a`},midnight:{label:`Midnight`,light:!1,bg:`#11161d`,sheet:`#151c26`,panel:`#1c2431`,head:`#243245`,border:`#34465e`,text:`#eef2f7`,muted:`#a4b2c4`,accent:`#7ea8de`,accentText:`#0c1422`,pill:`#23354c`,skyTop:`#1b283a`,skyBot:`#11161d`},forest:{label:`Forest`,light:!1,bg:`#111714`,sheet:`#151e19`,panel:`#1c2721`,head:`#23372c`,border:`#334d3f`,text:`#edf4ef`,muted:`#a5bdaf`,accent:`#76d690`,accentText:`#0a2412`,pill:`#213a2c`,skyTop:`#1c3126`,skyBot:`#111714`},crimson:{label:`Crimson`,light:!1,bg:`#181214`,sheet:`#20171a`,panel:`#281d21`,head:`#3c242c`,border:`#54353f`,text:`#f7eef0`,muted:`#c4a8b0`,accent:`#ee95a3`,accentText:`#290b12`,pill:`#41252e`,skyTop:`#351d24`,skyBot:`#181214`},slate:{label:`Slate`,light:!1,bg:`#141416`,sheet:`#1b1c1f`,panel:`#222428`,head:`#2d3036`,border:`#3d4149`,text:`#f1f2f4`,muted:`#b2b6be`,accent:`#c4c8d0`,accentText:`#141518`,pill:`#30333b`,skyTop:`#26282e`,skyBot:`#141416`},daylight:{label:`Daylight`,light:!0,bg:`#eceef2`,sheet:`#ffffff`,panel:`#f5f6f9`,head:`#e3e7ef`,border:`#cfd5e0`,text:`#14161a`,muted:`#505662`,accent:`#2752c4`,accentText:`#ffffff`,pill:`#dce5f5`,skyTop:`#d7dfec`,skyBot:`#eceef2`}},dv=Object.keys(uv),fv=`steel`,pv={light:{error:`#b3261e`,warnBg:`#fff4dc`,warnLine:`#e9c46a`},dark:{error:`#ff8a80`,warnBg:`#352b16`,warnLine:`#8a6d1f`}},mv={about:`About`,activity:`Activity`,favourites:`Favourites`,comments:`Comments`},hv=Object.keys(mv),gv={accent:`blue`,theme:fv,sections:[{id:`about`},{id:`activity`,level:`off`},{id:`favourites`,level:`off`},{id:`comments`,level:`off`}]},_v={accent:`blue`,sections:[`about`]},vv=16,yv=e=>typeof e==`string`&&hv.includes(e),bv=e=>typeof e==`string`&&Object.hasOwn(cv,e)?e:`blue`,xv=e=>typeof e==`string`&&Object.hasOwn(uv,e)?e:fv,Sv=new Set([`public`,`friends`,`off`]),Cv=(e,t)=>{if(e===`about`)return{id:e};let n=t?.level;return{id:e,level:typeof n==`string`&&Sv.has(n)?n:`off`}},wv=e=>{let t=e.profile.page?.value;if(typeof t!=`object`||!t)return gv;let{accent:n,theme:r,sections:i}=t,a=new Map;for(let e of Array.isArray(i)?i:[]){let t=e?.id;yv(t)&&!a.has(t)&&a.set(t,Cv(t,e))}for(let e of hv)a.has(e)||a.set(e,Cv(e));return{accent:bv(n),theme:xv(r),sections:[...a.values()]}},Tv=(e,t)=>{let n=e.sections.find(e=>e.id===t);return n!==void 0&&n.id!==`about`?n.level:`off`},Ev=(e,t)=>Tv(wv(e),t),Dv=(e,t,n)=>({...e,sections:e.sections.map(e=>e.id===t?{id:t,level:n}:e)}),Ov=(e,t,n)=>{let r=e.sections.findIndex(e=>e.id===t),i=r+n;if(r<0||i<0||i>=e.sections.length)return e;let a=[...e.sections];return[a[r],a[i]]=[a[i],a[r]],{...e,sections:a}},kv=(e,t)=>{if(e.profile.page===void 0)return null;let{accent:n,theme:r,sections:i}=wv(e);return{accent:n,...r===`steel`?{}:{theme:r},sections:i.filter(e=>e.id===`about`?t:e.level===`public`).map(({id:e})=>e)}},Av=(e,t)=>wv(e).sections.filter(e=>e.id===`about`?t:e.level!==`off`).map(({id:e})=>e),jv=e=>{if(typeof e!=`object`||!e)return _v;let{accent:t,theme:n,sections:r}=e;if(!Array.isArray(r)||r.length>vv||!r.every(e=>typeof e==`string`))return _v;let i=xv(n);return{accent:bv(t),...i===`steel`?{}:{theme:i},sections:[...new Set(r)].filter(yv)}},Mv=(e,t)=>JSON.stringify(e)===JSON.stringify(t),Nv=(e,t,n)=>ap(e,()=>Mv(t,n)?{}:{page:t}),Pv=(e,t)=>`${e}/${t}`,Fv={public:[],friends:[]},Iv=/^[A-Za-z0-9_-]{22}$/,Lv=new TextEncoder,Rv=e=>{if(typeof e!=`string`||!e.isWellFormed())return null;let t=e.normalize(`NFC`).trim();return t!==``&&ff(t,{max:500,multiline:!0})===null?t:null},zv=e=>Y(qd(Lv.encode(e)).slice(0,16)),Bv=({id:e,name:t,text:n,at:r})=>({id:e,name:t,text:n,at:r}),Vv=e=>{if(typeof e!=`object`||!e)return null;let{id:t,name:n,text:r,at:i}=e;return typeof t!=`string`||!Iv.test(t)||typeof n!=`string`||!af(n)||typeof r!=`string`||Rv(r)!==r||typeof i!=`number`||!Number.isSafeInteger(i)||i<0?null:{id:t,name:n,text:r,at:i}},Hv=(...e)=>{let t=new Map;for(let n of e.flat())t.has(n.id)||t.set(n.id,n);return[...t.values()].sort((e,t)=>t.at-e.at||(e.id<t.id?-1:+(e.id>t.id))).slice(0,20)},Uv=e=>Hv(Array.isArray(e)?e.map(Vv).filter(e=>e!==null):[]),Wv=e=>e.comments??Fv,Gv=(e,t)=>({public:Hv(Wv(e).public,Wv(t).public),friends:Hv(Wv(e).friends,Wv(t).friends)}),Kv=(e,t)=>{let n=Wv(e);return[...n.public,...n.friends].some(e=>e.id===t.id)?e:{...e,comments:{...n,public:Hv([t],n.public)}}},qv=(e,t)=>{let n=Wv(e);return{...e,comments:{public:n.public.filter(e=>!t.includes(e.id)),friends:n.friends.filter(e=>!t.includes(e.id))}}},Jv=(e,t)=>{let n=Wv(e);return t===`off`?{...e,comments:Fv}:t===`friends`?{...e,comments:{public:[],friends:Hv(n.friends,n.public)}}:e},Yv=e=>{if(typeof e!=`object`||!e)return null;let{title:t,link:n,image:r}=e;return!dh(t,150)||!fh(n)||r!==void 0&&!fh(r)?null:r===void 0?{title:t,link:n}:{title:t,link:n,image:r}},Xv=e=>{let t=[];for(let n of Array.isArray(e)?e:[]){let e=Yv(n);e!==null&&!t.some(t=>t.link===e.link)&&t.length<8&&t.push(e)}return t},Zv=e=>Xv(e.profile.favourites?.value),Qv=async(e,t,n)=>{let r=Yv(t);if(r===null)return{ok:!1,reason:`invalid`};let i=!1,a=await ap(e,e=>{let t=Zv(e),a=t.filter(e=>e.link!==r.link);return n?a.length<t.length?{}:(i=t.length>=8,i?{}:{favourites:[...t,r]}):a.length===t.length?{}:{favourites:a}});return i?{ok:!1,reason:`full`}:a},$v=/^[A-Za-z0-9_-]{43}$/,ey=e=>{if(typeof e!=`string`||e[43]!==`.`||!$v.test(e.slice(0,43)))return null;let t=e.slice(44);return t.length>=1&&t.length<=300&&!t.includes(`\0`)?e:null},ty=e=>e.slice(44);function ny(e){return e instanceof Uint8Array||ArrayBuffer.isView(e)&&e.constructor.name===`Uint8Array`&&`BYTES_PER_ELEMENT`in e&&e.BYTES_PER_ELEMENT===1}var ry=e=>e?`"${e}" `:``;function iy(e,t=``){if(typeof e!=`boolean`)throw TypeError(ry(t)+`expected boolean, got type=`+typeof e);return e}function ay(e,t=``){if(typeof e!=`number`)throw TypeError(ry(t)+`expected number, got `+typeof e);if(!Number.isSafeInteger(e)||e<0)throw RangeError(ry(t)+`expected integer >= 0, got `+e);return e}function oy(e,t,n=``){if(ny(e)&&(t===void 0||e.length===t))return e;t!==void 0&&ay(t,`length`);let r=ny(e),i=t===void 0?``:` of length ${t}`,a=r?`length=${e.length}`:`type=${typeof e}`,o=ry(n)+`expected Uint8Array`+i+`, got `+a;throw r?RangeError(o):TypeError(o)}var sy=(e,t)=>{if(typeof e!=`object`||!e||Array.isArray(e))throw TypeError(t===`object`?`expected valid options object`:`"${t}" expected object, got type=${typeof e}`)};function cy(e,t=!0){if(e.destroyed)throw Error(`hash was destroyed`);if(t&&e.finished)throw Error(`digest() was already called`)}function ly(e,t){oy(e,void 0,`output`);let n=t.outputLen;if(!(e.length>=n))throw RangeError(`"output" expected length >= `+n)}function uy(e){return new Uint32Array(e.buffer,e.byteOffset,Math.floor(e.byteLength/4))}function dy(...e){for(let t=0;t<e.length;t++)e[t].fill(0)}function fy(e){return new DataView(e.buffer,e.byteOffset,e.byteLength)}var py=new Uint8Array(new Uint32Array([287454020]).buffer)[0]===68;function my(e){return e<<24&4278190080|e<<8&16711680|e>>>8&65280|e>>>24&255}function hy(e){for(let t=0;t<e.length;t++)e[t]=my(e[t]);return e}var gy=py?e=>e:hy;function _y(e,t){return!e.byteLength||!t.byteLength?!1:e.buffer===t.buffer&&e.byteOffset<t.byteOffset+t.byteLength&&t.byteOffset<e.byteOffset+e.byteLength}function vy(e,t){if(_y(e,t)&&e.byteOffset<t.byteOffset)throw Error(`complex overlap of input and output is not supported`)}function yy(e,t){return sy(e,`defaults`),sy(t,`opts`),Object.assign(e,t)}function by(e,t){if(e=oy(e),t=oy(t),e.length!==t.length)return!1;let n=0;for(let r=0;r<e.length;r++)n|=e[r]^t[r];return n===0}function xy(e,t,n){let r=t,i=n||(()=>[]),a=(e,t)=>r(t,...i(e)).update(e).digest(),o=r(new Uint8Array(e),...i(new Uint8Array));return a.outputLen=o.outputLen,a.blockLen=o.blockLen,a.create=(e,...t)=>r(e,...t),a}var Sy=(e,t)=>{function n(n,...r){if(oy(n,void 0,`key`),e.nonceLength!==void 0){let t=r[0];oy(t,e.varSizeNonce?void 0:e.nonceLength,`nonce`)}let i=e.tagLength,a=e.nonceLength===void 0?0:1;if(!e.withAAD){for(let e=a;e<r.length;e++)if(ny(r[e]))throw Error(`AAD not supported`)}e.withAAD&&r[a]!==void 0&&oy(r[a],void 0,`AAD`);let o=t(n,...r),s=(e,t)=>{if(t!==void 0){if(e!==2)throw Error(`cipher output not supported`);oy(t,void 0,`output`)}},c=!1;return{encrypt(e,t){if(c)throw Error(`cannot encrypt() twice with same key + nonce`);return c=!0,oy(e,void 0,`data`),s(o.encrypt.length,t),o.encrypt(e,t)},decrypt(e,t){if(oy(e,void 0,`data`),i&&e.length<i)throw Error(`"ciphertext" expected length >= tagLength=`+i);return s(o.decrypt.length,t),o.decrypt(e,t)}}}return Object.assign(n,e),n};function Cy(e,t,n=!0){if(t===void 0)return new Uint8Array(e);if(oy(t,e,`output`),n&&!Ty(t))throw Error(`invalid output, must be aligned`);return t}function wy(e,t,n){ay(e),ay(t),iy(n);let r=new Uint8Array(16),i=fy(r);return i.setBigUint64(0,BigInt(t),n),i.setBigUint64(8,BigInt(e),n),r}function Ty(e){return e.byteOffset%4==0}function Ey(e){return Uint8Array.from(oy(e))}var Dy=e=>Uint8Array.from(e.split(``),e=>e.charCodeAt(0)),Oy=gy(uy(Dy(`expand 16-byte k`))),ky=gy(uy(Dy(`expand 32-byte k`)));function $(e,t){return e<<t|e>>>32-t}var Ay=64,jy=16,My=2**32-1,Ny=Uint32Array.of();function Py(e,t,n,r,i,a,o,s){let c=i.length,l=new Uint8Array(Ay),u=uy(l),d=py&&Ty(i)&&Ty(a),f=d?uy(i):Ny,p=d?uy(a):Ny;if(!py){for(let d=0;d<c;o++){if(e(t,n,r,u,o,s),gy(u),o>=My)throw Error(`arx: counter overflow`);let f=Math.min(Ay,c-d);for(let e=0,t;e<f;e++)t=d+e,a[t]=i[t]^l[e];d+=f}return}for(let m=0;m<c;o++){if(e(t,n,r,u,o,s),o>=My)throw Error(`arx: counter overflow`);let h=Math.min(Ay,c-m);if(d&&h===Ay){let e=m/4;if(m%4!=0)throw Error(`arx: invalid block position`);for(let t=0,n;t<jy;t++)n=e+t,p[n]=f[n]^u[t];m+=Ay;continue}for(let e=0,t;e<h;e++)t=m+e,a[t]=i[t]^l[e];m+=h}}function Fy(e,t){let{allowShortKeys:n,extendNonceFn:r,counterLength:i,counterRight:a,rounds:o}=yy({allowShortKeys:!1,counterLength:8,counterRight:!1,rounds:20},t);if(typeof e!=`function`)throw Error(`core must be a function`);return ay(i),ay(o),iy(a),iy(n),(t,s,c,l,u=0)=>{oy(t,void 0,`key`),oy(s,void 0,`nonce`),oy(c,void 0,`data`);let d=c.length,f=l!==void 0;if(l=Cy(d,l,!1),f&&vy(c,l),ay(u),u<0||u>=My)throw Error(`arx: counter overflow`);let p=[],m=t.length,h,g;if(m===32)p.push(h=Ey(t)),g=ky;else if(m===16&&n)h=new Uint8Array(32),h.set(t),h.set(t,16),g=Oy,p.push(h);else throw oy(t,32,`arx key`),Error(`invalid key size`);(!py||!Ty(s))&&p.push(s=Ey(s));let _=uy(h);if(r){if(s.length!==24)throw Error(`arx: extended nonce must be 24 bytes`);let e=s.subarray(0,16);if(py)r(g,_,uy(e),_);else{let t=gy(Uint32Array.from(g));r(t,_,uy(e),_),dy(t),gy(_)}s=s.subarray(16)}else py||gy(_);let v=16-i;if(v!==s.length)throw Error(`arx: nonce must be ${v} or 16 bytes`);if(v!==12){let e=new Uint8Array(12);e.set(s,a?0:12-s.length),s=e,p.push(s)}let y=gy(uy(s));try{return Py(e,g,_,y,c,l,u,o),l}finally{dy(...p)}}}function Iy(e,t){return e[t++]&255|(e[t++]&255)<<8}var Ly=class{blockLen=16;outputLen=16;buffer=new Uint8Array(16);r=new Uint16Array(10);h=new Uint16Array(10);pad=new Uint16Array(8);pos=0;finished=!1;destroyed=!1;constructor(e){e=Ey(oy(e,32,`key`));let t=Iy(e,0),n=Iy(e,2),r=Iy(e,4),i=Iy(e,6),a=Iy(e,8),o=Iy(e,10),s=Iy(e,12),c=Iy(e,14);this.r[0]=t&8191,this.r[1]=(t>>>13|n<<3)&8191,this.r[2]=(n>>>10|r<<6)&7939,this.r[3]=(r>>>7|i<<9)&8191,this.r[4]=(i>>>4|a<<12)&255,this.r[5]=a>>>1&8190,this.r[6]=(a>>>14|o<<2)&8191,this.r[7]=(o>>>11|s<<5)&8065,this.r[8]=(s>>>8|c<<8)&8191,this.r[9]=c>>>5&127;for(let t=0;t<8;t++)this.pad[t]=Iy(e,16+2*t)}process(e,t,n=!1){let r=n?0:2048,{h:i,r:a}=this,o=a[0],s=a[1],c=a[2],l=a[3],u=a[4],d=a[5],f=a[6],p=a[7],m=a[8],h=a[9],g=Iy(e,t+0),_=Iy(e,t+2),v=Iy(e,t+4),y=Iy(e,t+6),b=Iy(e,t+8),x=Iy(e,t+10),S=Iy(e,t+12),C=Iy(e,t+14),w=i[0]+(g&8191),T=i[1]+((g>>>13|_<<3)&8191),E=i[2]+((_>>>10|v<<6)&8191),D=i[3]+((v>>>7|y<<9)&8191),O=i[4]+((y>>>4|b<<12)&8191),k=i[5]+(b>>>1&8191),A=i[6]+((b>>>14|x<<2)&8191),j=i[7]+((x>>>11|S<<5)&8191),M=i[8]+((S>>>8|C<<8)&8191),N=i[9]+(C>>>5|r),P=0,F=P+w*o+5*h*T+5*m*E+5*p*D+5*f*O;P=F>>>13,F&=8191,F+=5*d*k+5*u*A+5*l*j+5*c*M+5*s*N,P+=F>>>13,F&=8191;let I=P+w*s+T*o+5*h*E+5*m*D+5*p*O;P=I>>>13,I&=8191,I+=5*f*k+5*d*A+5*u*j+5*l*M+5*c*N,P+=I>>>13,I&=8191;let L=P+w*c+T*s+E*o+5*h*D+5*m*O;P=L>>>13,L&=8191,L+=5*p*k+5*f*A+5*d*j+5*u*M+5*l*N,P+=L>>>13,L&=8191;let R=P+w*l+T*c+E*s+D*o+5*h*O;P=R>>>13,R&=8191,R+=5*m*k+5*p*A+5*f*j+5*d*M+5*u*N,P+=R>>>13,R&=8191;let z=P+w*u+T*l+E*c+D*s+O*o;P=z>>>13,z&=8191,z+=5*h*k+5*m*A+5*p*j+5*f*M+5*d*N,P+=z>>>13,z&=8191;let ee=P+w*d+T*u+E*l+D*c+O*s;P=ee>>>13,ee&=8191,ee+=k*o+5*h*A+5*m*j+5*p*M+5*f*N,P+=ee>>>13,ee&=8191;let te=P+w*f+T*d+E*u+D*l+O*c;P=te>>>13,te&=8191,te+=k*s+A*o+5*h*j+5*m*M+5*p*N,P+=te>>>13,te&=8191;let ne=P+w*p+T*f+E*d+D*u+O*l;P=ne>>>13,ne&=8191,ne+=k*c+A*s+j*o+5*h*M+5*m*N,P+=ne>>>13,ne&=8191;let re=P+w*m+T*p+E*f+D*d+O*u;P=re>>>13,re&=8191,re+=k*l+A*c+j*s+M*o+5*h*N,P+=re>>>13,re&=8191;let ie=P+w*h+T*m+E*p+D*f+O*d;P=ie>>>13,ie&=8191,ie+=k*u+A*l+j*c+M*s+N*o,P+=ie>>>13,ie&=8191,P=(P<<2)+P|0,P=P+F|0,F=P&8191,P>>>=13,I+=P,i[0]=F,i[1]=I,i[2]=L,i[3]=R,i[4]=z,i[5]=ee,i[6]=te,i[7]=ne,i[8]=re,i[9]=ie}finalize(){let{h:e,pad:t}=this,n=new Uint16Array(10),r=e[1]>>>13;e[1]&=8191;for(let t=2;t<10;t++)e[t]+=r,r=e[t]>>>13,e[t]&=8191;e[0]+=r*5,r=e[0]>>>13,e[0]&=8191,e[1]+=r,r=e[1]>>>13,e[1]&=8191,e[2]+=r,n[0]=e[0]+5,r=n[0]>>>13,n[0]&=8191;for(let t=1;t<10;t++)n[t]=e[t]+r,r=n[t]>>>13,n[t]&=8191;n[9]-=8192;let i=(r^1)-1;for(let e=0;e<10;e++)n[e]&=i;i=~i;for(let t=0;t<10;t++)e[t]=e[t]&i|n[t];e[0]=(e[0]|e[1]<<13)&65535,e[1]=(e[1]>>>3|e[2]<<10)&65535,e[2]=(e[2]>>>6|e[3]<<7)&65535,e[3]=(e[3]>>>9|e[4]<<4)&65535,e[4]=(e[4]>>>12|e[5]<<1|e[6]<<14)&65535,e[5]=(e[6]>>>2|e[7]<<11)&65535,e[6]=(e[7]>>>5|e[8]<<8)&65535,e[7]=(e[8]>>>8|e[9]<<5)&65535;let a=e[0]+t[0];e[0]=a&65535;for(let n=1;n<8;n++)a=(e[n]+t[n]|0)+(a>>>16)|0,e[n]=a&65535;dy(n)}update(e){cy(this),oy(e),e=Ey(e);let{buffer:t,blockLen:n}=this,r=e.length;for(let i=0;i<r;){let a=Math.min(n-this.pos,r-i);if(a===n){for(;n<=r-i;i+=n)this.process(e,i);continue}t.set(e.subarray(i,i+a),this.pos),this.pos+=a,i+=a,this.pos===n&&(this.process(t,0,!1),this.pos=0)}return this}destroy(){this.destroyed=!0,dy(this.h,this.r,this.buffer,this.pad)}digestInto(e){cy(this),ly(e,this),this.finished=!0;let{buffer:t,h:n}=this,{pos:r}=this;if(r){for(t[r++]=1;r<16;r++)t[r]=0;this.process(t,0,!0)}this.finalize();let i=0;for(let t=0;t<8;t++)e[i++]=n[t]>>>0,e[i++]=n[t]>>>8}digest(){let{buffer:e,outputLen:t}=this;this.digestInto(e);let n=e.slice(0,t);return this.destroy(),n}},Ry=xy(32,e=>new Ly(e));function zy(e,t,n,r,i,a=20){let o=e[0],s=e[1],c=e[2],l=e[3],u=t[0],d=t[1],f=t[2],p=t[3],m=t[4],h=t[5],g=t[6],_=t[7],v=i,y=n[0],b=n[1],x=n[2],S=o,C=s,w=c,T=l,E=u,D=d,O=f,k=p,A=m,j=h,M=g,N=_,P=v,F=y,I=b,L=x;for(let e=0;e<a;e+=2)S=S+E|0,P=$(P^S,16),A=A+P|0,E=$(E^A,12),S=S+E|0,P=$(P^S,8),A=A+P|0,E=$(E^A,7),C=C+D|0,F=$(F^C,16),j=j+F|0,D=$(D^j,12),C=C+D|0,F=$(F^C,8),j=j+F|0,D=$(D^j,7),w=w+O|0,I=$(I^w,16),M=M+I|0,O=$(O^M,12),w=w+O|0,I=$(I^w,8),M=M+I|0,O=$(O^M,7),T=T+k|0,L=$(L^T,16),N=N+L|0,k=$(k^N,12),T=T+k|0,L=$(L^T,8),N=N+L|0,k=$(k^N,7),S=S+D|0,L=$(L^S,16),M=M+L|0,D=$(D^M,12),S=S+D|0,L=$(L^S,8),M=M+L|0,D=$(D^M,7),C=C+O|0,P=$(P^C,16),N=N+P|0,O=$(O^N,12),C=C+O|0,P=$(P^C,8),N=N+P|0,O=$(O^N,7),w=w+k|0,F=$(F^w,16),A=A+F|0,k=$(k^A,12),w=w+k|0,F=$(F^w,8),A=A+F|0,k=$(k^A,7),T=T+E|0,I=$(I^T,16),j=j+I|0,E=$(E^j,12),T=T+E|0,I=$(I^T,8),j=j+I|0,E=$(E^j,7);let R=0;r[R++]=o+S|0,r[R++]=s+C|0,r[R++]=c+w|0,r[R++]=l+T|0,r[R++]=u+E|0,r[R++]=d+D|0,r[R++]=f+O|0,r[R++]=p+k|0,r[R++]=m+A|0,r[R++]=h+j|0,r[R++]=g+M|0,r[R++]=_+N|0,r[R++]=v+P|0,r[R++]=y+F|0,r[R++]=b+I|0,r[R++]=x+L|0}function By(e,t,n,r){let i=py?e:gy(e.slice(0,4)),a=py?t:gy(t.slice(0,8)),o=py?n:gy(n.slice(0,4)),s=new Uint32Array(16);zy(i,a,o.subarray(1),s,o[0]);let c=0;r[c++]=s[0]-i[0]|0,r[c++]=s[1]-i[1]|0,r[c++]=s[2]-i[2]|0,r[c++]=s[3]-i[3]|0,r[c++]=s[12]-o[0]|0,r[c++]=s[13]-o[1]|0,r[c++]=s[14]-o[2]|0,r[c++]=s[15]-o[3]|0,gy(r),py||dy(i,a,o),dy(s)}var Vy=Fy(zy,{counterRight:!1,counterLength:8,extendNonceFn:By,allowShortKeys:!1}),Hy=new Uint8Array(16),Uy=(e,t)=>{e.update(t);let n=t.length%16;n&&e.update(Hy.subarray(n))},Wy=new Uint8Array(32);function Gy(e,t,n,r,i){i!==void 0&&oy(i,void 0,`AAD`);let a=e(t,n,Wy),o=wy(r.length,i?i.length:0,!0),s=Ry.create(a);i&&Uy(s,i),Uy(s,r),s.update(o);let c=s.digest();return dy(a,o),c}var Ky=Sy({blockSize:64,nonceLength:24,tagLength:16,withAAD:!0},(e=>(t,n,r)=>({encrypt(i,a){let o=i.length;a=Cy(o+16,a,!1),a.set(i);let s=a.subarray(0,-16);e(t,n,s,s,1);let c=Gy(e,t,n,s,r);return a.set(c,o),dy(c),a},decrypt(i,a){a=Cy(i.length-16,a,!1);let o=i.subarray(0,-16),s=i.subarray(-16),c=Gy(e,t,n,o,r);if(!by(s,c))throw dy(c),Error(`invalid tag`);return a.set(i.subarray(0,-16)),e(t,n,a,a,1),dy(c),a}}))(Vy)),qy=new TextEncoder,Jy=new TextDecoder,Yy=e=>qy.encode(e),Xy=Uint8Array.of(0),Zy=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},Qy=(e,t,n)=>W_(qd,R_.getSharedSecret(e,t),Yy(n),Yy(X_),32),$y=(e,t,n,r,i,a)=>Zy([Yy(e),Xy,Yy(t),Xy,Yy(n),Xy,Yy(r),Xy,Yy(i),Xy,qd(a)]),eb=(e,t)=>{let n=crypto.getRandomValues(new Uint8Array(24));return Zy([n,Ky(e,n).encrypt(t)])},tb=(e,t)=>{if(t.length<=24)return null;try{return Ky(e,t.slice(0,24)).decrypt(t.slice(24))}catch{return null}},nb={"social.offer":J_,"social.accept":Y_},rb=(e,t,n,r)=>{let i=eb(Qy(r.dhSeed,r.theirDhKey,n.roomId),Yy(JSON.stringify(t)));return{t:e,v:1,to:n.toMemberId,i:n.id,b:Y(i),s:Y(L_.sign($y(nb[e],n.roomId,n.fromMemberId,n.toMemberId,n.id,i),r.signSeed))}},ib=(e,t,n)=>rb(`social.offer`,{n:Y(e.nonce),p:e.profile,x:e.inbox},t,n),ab=(e,t,n)=>rb(`social.accept`,{o:e.offerId,p:e.profile,x:e.inbox},t,n),ob=e=>{if(typeof e!=`object`||!e)return!1;let t=e;return(t.t===`social.offer`||t.t===`social.accept`)&&t.v===1&&typeof t.to==`string`&&typeof t.i==`string`&&typeof t.b==`string`&&typeof t.s==`string`},sb=(e,t,n,r)=>{if(!ob(t)||t.t!==e)return{ok:!1,reason:`malformed`};if(t.to!==n.selfMemberId)return{ok:!1,reason:`not-for-me`};let i=X(t.b),a=X(t.s);if(!i||!a||a.length!==64)return{ok:!1,reason:`malformed`};let o=$y(nb[e],n.roomId,n.fromMemberId,n.selfMemberId,t.i,i);try{if(!L_.verify(a,o,r.theirSignKey,{zip215:!1}))return{ok:!1,reason:`bad-signature`}}catch{return{ok:!1,reason:`bad-signature`}}let s=tb(Qy(r.dhSeed,r.theirDhKey,n.roomId),i);if(!s)return{ok:!1,reason:`unsealed`};if(s.length>16384)return{ok:!1,reason:`malformed`};try{let e=JSON.parse(Jy.decode(s));return typeof e!=`object`||!e?{ok:!1,reason:`malformed`}:{ok:!0,id:t.i,body:e}}catch{return{ok:!1,reason:`malformed`}}},cb=e=>e==null?null:ey(e)??void 0,lb=(e,t,n)=>{let r=sb(`social.offer`,e,t,n);if(!r.ok)return r;let i=typeof r.body.n==`string`?X(r.body.n):null,a=Cf(r.body.p),o=cb(r.body.x);return i?.length!==32||a===null||o===void 0?{ok:!1,reason:`malformed`}:{ok:!0,id:r.id,body:{nonce:i,profile:a,inbox:o}}},ub=(e,t,n)=>{let r=sb(`social.accept`,e,t,n);if(!r.ok)return r;let i=Cf(r.body.p),a=cb(r.body.x);return typeof r.body.o!=`string`||i===null||a===void 0?{ok:!1,reason:`malformed`}:{ok:!0,body:{offerId:r.body.o,profile:i,inbox:a}}},db=new TextEncoder,fb=new TextDecoder,pb=2e3,mb=(e,t)=>{if(e.includes(`\0`))throw Error(`social: a signed field may not contain a NUL`);return db.encode(`${ev}\u0000${e}\u0000${t}`)},hb=(e,t)=>W_(qd,e,db.encode(t),db.encode(tv),32),gb=(e,t,n,r)=>{let i=JSON.stringify({k:Y(r.signKey),d:Y(r.dhKey),...n}),a=Y(L_.sign(mb(e,i),r.signSeed)),o=R_.utils.randomSecretKey(),s=crypto.getRandomValues(new Uint8Array(24)),c=Ky(hb(R_.getSharedSecret(o,t),e),s).encrypt(db.encode(JSON.stringify({b:i,s:a}))),l=new Uint8Array(24+c.length);return l.set(s),l.set(c,24),JSON.stringify({t:`social.request`,v:1,e:Y(R_.getPublicKey(o)),b:Y(l)})},_b=e=>{try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:null}catch{return null}},vb=(e,t)=>{let n=typeof e==`string`?X(e):null;return n?.length===t?n:null},yb=(e,t,n,r)=>{let i=vb(n,32),a=typeof r==`string`?X(r):null;if(i===null||a===null||a.length<=24)return null;try{return Ky(hb(R_.getSharedSecret(e.dhSeed,i),t),a.slice(0,24)).decrypt(a.slice(24))}catch{return null}},bb=(e,t)=>{if(e.kind===`party`){let n=typeof e.url==`string`?pf(e.url,pb):null;return n!==null&&n===e.url?{...t,kind:`party`,url:n}:null}if(e.kind===`comment`)return Rv(e.text)===e.text?{...t,kind:`comment`,text:e.text}:null;if(e.kind!==`friend`&&e.kind!==`accept`)return null;let n=Cf(e.p),r=ey(e.x),i=vb(e.r,32)===null?null:e.r;return n===null||i===null?null:e.kind===`friend`?r===null?null:{...t,kind:`friend`,p:n,x:r,r:i}:r===null&&e.x!==null&&e.x!==void 0?null:{...t,kind:`accept`,p:n,x:r,r:i}},xb=(e,t,n)=>{let r=_b(e);if(r===null||r.t!==`social.request`||r.v!==1)return null;let i=yb(n,t,r.e,r.b),a=i===null?null:_b(fb.decode(i));if(a===null||typeof a.b!=`string`||db.encode(a.b).length>16384)return null;let o=vb(a.s,64),s=_b(a.b),c=vb(s?.k,32);if(s===null||o===null||c===null)return null;try{if(!L_.verify(o,mb(t,a.b),c,{zip215:!1}))return null}catch{return null}let{name:l,to:u}=s;if(u!==Y(n.signKey)||typeof l!=`string`||!af(l))return null;let d=vb(s.d,32);if(d===null)return null;let f=bb(s,{k:s.k,d:s.d,name:l,to:u});return f===null?null:{body:f,signKey:c,dhKey:d}},Sb=new TextEncoder,Cb=new TextDecoder,wb=Uint8Array.of(0),Tb=Uint8Array.of(1),Eb=(...e)=>{let t=e.map(e=>typeof e==`string`?Sb.encode(e):e),n=new Uint8Array(t.reduce((e,t)=>e+t.length,0)),r=0;for(let e of t)n.set(e,r),r+=e.length;return n},Db=(e,...t)=>B_(qd,e,Eb(...t)),Ob=e=>Math.max(8,2**Math.ceil(Math.log2(Math.max(1,e)))),kb=e=>W_(qd,e.dhSeed,void 0,Sb.encode(nv),32),Ab=(e,t,n)=>Db(e,`k`,t,wb,n),jb=(e,t,n)=>{try{return W_(qd,R_.getSharedSecret(e,t),Sb.encode(n),Sb.encode(rv),32)}catch{return null}},Mb=e=>e.map(Y).sort().join(`\0`),Nb=(e,t,n,r)=>{let i=kb(e),a=Sb.encode(Mb(n)),o=Db(i,`e`,[...r].sort().join(`\0`),Tb,a).slice(0,16),s=n.map(n=>jb(e.dhSeed,n,t)).filter(e=>e!==null);return{e:o,key:Ab(i,t,o),secret:i,members:a,slots:s}},Pb=e=>({displayName:e.displayName,bio:e.bio,links:e.links,...e.avatar==null?{}:{avatar:{url:e.avatar.url,key:e.avatar.key}},...e.background==null?{}:{background:{url:e.background.url,key:e.background.key}}}),Fb=e=>JSON.stringify({profile:e.profile===null?null:Pb(e.profile),sections:e.sections,feed:e.feed.map(_h),...e.favourites===void 0||e.favourites.length===0?{}:{favourites:e.favourites.map(({title:e,link:t,image:n})=>n===void 0?{title:e,link:t}:{title:e,link:t,image:n})},...e.comments===void 0||e.comments.length===0?{}:{comments:e.comments.map(Bv)},...e.panels===void 0||e.panels.length===0?{}:{panels:e.panels.map(lm)},...e.panelOrder===void 0||e.panelOrder.length===0?{}:{panelOrder:e.panelOrder}}),Ib=(e,t,n,r)=>{let i=Sb.encode(Fb(n)),a=Db(e.key,`z`,r,wb,i,wb,e.members).slice(0,16),o=Ky(e.key,Db(e.key,`c`,a).slice(0,24),Eb(t.roomId,wb,t.owner)).encrypt(i),s=e.slots.map(t=>({i:Y(Db(t,`i`,a).slice(0,16)),w:Y(Ky(t,Db(t,`w`,a).slice(0,24)).encrypt(e.key))}));for(let t=s.length;t<Ob(e.slots.length);t++){let n=W_(qd,e.secret,a,Eb(`p`,String(t)),64);s.push({i:Y(n.slice(0,16)),w:Y(n.slice(16))})}return{e:Y(e.e),z:Y(a),c:Y(o),s:s.sort((e,t)=>e.i<t.i?-1:+(e.i>t.i))}},Lb=(e,t)=>{let n=`A`.repeat(22);return{e:n,z:n,c:`A`.repeat(Math.ceil((Sb.encode(Fb(t)).length+16)*4/3)),s:Array.from({length:Ob(e.slots.length)},()=>({i:n,w:`A`.repeat(64)}))}},Rb=/^[A-Za-z0-9_-]{22}$/,zb=/^[A-Za-z0-9_-]{64}$/,Bb=e=>{if(typeof e!=`object`||!e)return null;let{e:t,z:n,c:r,s:i}=e;if(typeof t!=`string`||!Rb.test(t)||typeof n!=`string`||!Rb.test(n)||typeof r!=`string`||r===``||X(r)===null||!Array.isArray(i)||i.length>4096)return null;let a=[];for(let e of i){let{i:t,w:n}=e??{};if(typeof t!=`string`||!Rb.test(t)||typeof n!=`string`||!zb.test(n))return null;a.push({i:t,w:n})}return{e:t,z:n,c:r,s:a}},Vb=e=>{let t;try{t=JSON.parse(Cb.decode(e))}catch{return null}if(typeof t!=`object`||!t)return null;let{profile:n,sections:r,feed:i,favourites:a,comments:o,panels:s,panelOrder:c}=t,l=typeof n==`object`&&n?n:null,u=l===null?null:Cf({...l,version:0}),d=l?.avatar===void 0?null:gf(l.avatar)??null,f=l?.background===void 0?null:gf(l.background)??null,p=Array.isArray(r)?[...new Set(r)].filter(e=>typeof e==`string`&&Object.hasOwn(mv,e)):[],m=dm(s),h=fm(c);return{profile:u===null?null:{displayName:u.displayName,bio:u.bio,links:u.links,...d===null?{}:{avatar:d},...f===null?{}:{background:f}},sections:p,feed:xh(i),favourites:Xv(a),comments:Uv(o),...m.length>0?{panels:m}:{},...h.length>0?{panelOrder:h}:{}}},Hb=(e,t,n)=>{let r=X(n.z);try{return Vb(Ky(e,Db(e,`c`,r).slice(0,24),Eb(t.roomId,wb,t.owner)).decrypt(X(n.c)))}catch{return null}},Ub=(e,t,n)=>Hb(Ab(kb(e),t.roomId,X(n.e)),t,n),Wb=(e,t,n,r)=>{let i=jb(e.dhSeed,t,n.roomId);if(i===null)return null;let a=X(r.z),o=Y(Db(i,`i`,a).slice(0,16)),s=r.s.find(e=>e.i===o);if(s===void 0)return null;try{return Hb(Ky(i,Db(i,`w`,a).slice(0,24)).decrypt(X(s.w)),n,r)}catch{return null}},Gb=new TextEncoder,Kb={version:0,profile:null,inbox:null},qb=e=>Y(qd(Gb.encode(`${$_}\u0000${e}`))),Jb=(e,t,n)=>{if(e.includes(`\0`)||t.includes(`\0`))throw Error(`social: a signed field may not contain a NUL`);if(n.length!==32)throw Error(`social: a public key is 32 bytes`);let r=Gb.encode(`${Z_}\u0000${e}\u0000${t}\u0000`),i=new Uint8Array(r.length+32);return i.set(r),i.set(n,r.length),i},Yb=(e,t,n)=>{if(e.includes(`\0`)||t.includes(`\0`))throw Error(`social: a signed field may not contain a NUL`);return Gb.encode(`${Q_}\u0000${e}\u0000${t}\u0000${n}`)},Xb=(e,t,n,r={})=>{let{profile:i,inbox:a,displayName:o,pageRoom:s,page:c,favourites:l,panels:u}=t,{feed:d,comments:f,friends:p}=r;return JSON.stringify({k:Y(n.signKey),n:e,version:t.version,profile:i===null?null:{displayName:i.displayName,bio:i.bio,links:i.links,avatar:i.avatar,background:i.background},...a==null?{}:{inbox:{invite:a,dhKey:Y(n.dhKey)}},...o?{displayName:o}:{},...s==null?{}:{pageRoom:s},...c==null?{}:{page:{accent:c.accent,...c.theme===void 0?{}:{theme:c.theme},sections:c.sections}},...d===void 0||d.length===0?{}:{feed:d.map(_h)},...l===void 0||l.length===0?{}:{favourites:l.map(({title:e,link:t,image:n})=>n===void 0?{title:e,link:t}:{title:e,link:t,image:n})},...f===void 0||f.length===0?{}:{comments:f.map(Bv)},...u===void 0||u.length===0?{}:{panels:u.map(lm)},...p===void 0?{}:{friends:{e:p.e,z:p.z,c:p.c,s:p.s.map(({i:e,w:t})=>({i:e,w:t}))}}})},Zb=(e,t)=>({t:`social.name`,v:2,b:e,s:t}),Qb=e=>{try{let t=JSON.parse(e);return typeof t==`object`&&t&&!Array.isArray(t)?t:null}catch{return null}},$b=(e,t,n)=>{try{return L_.verify(e,t(),n,{zip215:!1})}catch{return!1}},ex=e=>{if(e==null)return null;if(typeof e!=`object`)return;let{invite:t,dhKey:n}=e,r=ey(t),i=typeof n==`string`?X(n):null;return r!==null&&i?.length===32?{invite:r,dhKey:i}:void 0},tx=(e,t)=>{if(e===null)return null;if(typeof e!=`object`)return;let{displayName:n,bio:r,links:i,avatar:a,background:o}=e,s=Cf({displayName:n,bio:r,links:i,version:t}),[c,l]=[gf(a),gf(o)];if(s!==null&&c!==void 0&&l!==void 0)return{displayName:s.displayName,bio:s.bio,links:s.links,avatar:c,background:l}},nx=(e,t,n)=>{let{n:r,k:i,s:a}=e;if(r!==n||typeof i!=`string`||typeof a!=`string`)return null;let o=X(i),s=X(a);return o?.length!==32||s?.length!==64?null:$b(s,()=>Jb(t,n,o),o)?{signKey:o,version:null,profile:null,inbox:null,page:_v,feed:[],favourites:[],comments:[],friends:null}:null},rx=(e,t,n,r)=>{let i=Qb(e);if(i===null||i.t!==`social.name`||!af(r))return null;if(i.v===1)return nx(i,t,r);let{v:a,b:o,s}=i;if(a!==2||typeof o!=`string`||typeof s!=`string`||Gb.encode(o).length>131072)return null;let c=Qb(o);if(c===null||typeof c.k!=`string`||c.n!==r)return null;let l=X(c.k),u=X(s);if(l?.length!==32||u?.length!==64||!$b(u,()=>Yb(t,n,o),l))return null;let{version:d}=c;if(typeof d!=`number`||!Number.isSafeInteger(d)||d<0)return null;let f=tx(c.profile,d),p=ex(c.inbox);if(f===void 0||p===void 0)return null;let m=c.pageRoom,h=m==null?void 0:ey(m);if(h===null)return null;let g=c.displayName,_;if(g!==void 0){if(typeof g!=`string`||g.trim().length===0||ff(g,{max:32,multiline:!1})!==null)return null;_=g}let v=dm(c.panels);return{signKey:l,version:d,profile:f,inbox:p,..._===void 0?{}:{displayName:_},...h===void 0?{}:{pageRoom:h},page:jv(c.page),feed:xh(c.feed),favourites:Xv(c.favourites),comments:Uv(c.comments),...v.length>0?{panels:v}:{},friends:Bb(c.friends)}},ix=new TextEncoder,ax=(e,t,n)=>{if(e.includes(`\0`)||t.includes(`\0`))throw Error(`social: a signed field may not contain a NUL`);return ix.encode(`${iv}\u0000${e}\u0000${t}\u0000${n}`)},ox=(e,t,n={})=>{let{profile:r,page:i,favourites:a,panels:o}=e,{feed:s,comments:c,friends:l}=n;return JSON.stringify({k:Y(t.signKey),version:e.version,profile:r===null?null:{displayName:r.displayName,bio:r.bio,links:r.links,avatar:r.avatar,background:r.background},...i==null?{}:{page:{accent:i.accent,...i.theme===void 0?{}:{theme:i.theme},sections:i.sections}},...s===void 0||s.length===0?{}:{feed:s.map(_h)},...a===void 0||a.length===0?{}:{favourites:a.map(({title:e,link:t,image:n})=>n===void 0?{title:e,link:t}:{title:e,link:t,image:n})},...c===void 0||c.length===0?{}:{comments:c.map(Bv)},...o===void 0||o.length===0?{}:{panels:o.map(lm)},...l===void 0?{}:{friends:{e:l.e,z:l.z,c:l.c,s:l.s.map(({i:e,w:t})=>({i:e,w:t}))}}})},sx=(e,t)=>({t:`social.page`,v:1,b:e,s:t}),cx=(e,t,n)=>{let r=Qb(e);if(r===null||r.t!==`social.page`)return null;let{v:i,b:a,s:o}=r;if(i!==1||typeof a!=`string`||typeof o!=`string`||ix.encode(a).length>131072)return null;let s=Qb(a);if(s===null||typeof s.k!=`string`)return null;let c=X(s.k),l=X(o);if(c?.length!==32||l?.length!==64||!$b(l,()=>ax(t,n,a),c))return null;let{version:u}=s;if(typeof u!=`number`||!Number.isSafeInteger(u)||u<0)return null;let d=tx(s.profile,u);if(d===void 0)return null;let f=dm(s.panels);return{signKey:c,version:u,profile:d,page:s.page===void 0?_v:jv(s.page),feed:xh(s.feed),favourites:Xv(s.favourites),comments:Uv(s.comments),...f.length>0?{panels:f}:{},friends:Bb(s.friends)}},lx=1e4,ux=async(e,t=lx)=>{let n=Date.now()+t;for(;!e();){if(Date.now()>n)throw Error(`social: the room did not answer in time`);await new Promise(e=>setTimeout(e,20))}},dx=async(e,t,n)=>{let r={},i=await e.on(n=>{n.type===`message`&&n.message.from===e.self.id&&n.message.text===t&&(r.seq??=n.message.seq)});try{await e.send(t,n),await ux(()=>r.seq!==void 0)}finally{i()}let a=r.seq,o=(t,n)=>e.delete(t,n).catch(()=>{});a>1&&await o(1,a-1),await o(a+1,2**53-1)},fx=async e=>{if((await e.usage())?.messages!==1)return null;let t=new Map,n=await e.on(e=>{e.type===`message`&&t.set(e.message.seq,{seq:e.message.seq,from:e.message.from,text:e.message.text,type:e.message.envelope?.type??null})});try{let{last:n}=await e.backlog(0);if(n===0)return null;await ux(()=>t.has(n))}finally{n()}let r=[...t.values()];return r.length===1?r[0]:null},px=async e=>(await fx(e))?.text??null,mx=e=>({type:`object`,properties:{type:{type:`string`,const:e}},required:[`type`],additionalProperties:!1}),hx={type:`page`},gx={type:`record`},_x={type:`request`},vx={version:2,types:{page:{envelope:mx(`page`),send:`owner`,maxBytes:262144}}},yx={version:1,types:{request:{envelope:mx(`request`),send:`accounts`,maxBytes:65536,perAccount:{messages:16,bytes:131072}}},maxStoredBytes:4e6},bx={version:1,types:{page:{envelope:mx(`page`),send:`owner`,maxBytes:262144}}},xx=(e,t)=>e.schema()===null?void 0:t,Sx=e=>{let t=e.schema()?.types;if(t!==void 0)return Object.hasOwn(t,hx.type)?hx:Object.hasOwn(t,gx.type)?gx:void 0},Cx=e=>{let t=e.schema()?.types;return t!==void 0&&Object.hasOwn(t,hx.type)?hx:void 0},wx=async(e,t)=>{(e.schema()?.version??0)<t.version&&await e.setSchema(t).catch(()=>{})},Tx=new TextEncoder,Ex=e=>Tx.encode(e).length,Dx=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),Ox={profile:null,sections:[],members:[],left:[]},kx=`A`.repeat(86),Ax=(e,t,n,r)=>{if(n===null||!e.claimed||e.owner!==e.self.id)return null;let i=r(n.text,e.id,e.owner);if(i!==null&&Dx(i.signKey,t.signKey))return{proof:i,owner:e.owner,currentOwner:!0};if(n.from===e.owner)return null;let a=r(n.text,e.id,n.from);return a!==null&&Dx(a.signKey,t.signKey)?{proof:a,owner:n.from,currentOwner:!1}:null},jx=(e,t,n,r=e.owner)=>{let i=n.friends===null?null:Ub(t,{roomId:e.id,owner:r},n.friends);return{public:n.feed,friends:i?.feed??[],comments:{public:n.comments,friends:i?.comments??[]}}},Mx=(e,t,n,r,i,a,o)=>{let s=n.friends??null,c=s===null?null:Nb(t,e.id,s.members,s.left),l=n.commentsLevel===`public`||n.commentsLevel===`friends`,u=r.comments??Fv,[d,f,p]=[r.public.slice(0,50),r.friends.slice(0,50),!0],[m,h]=[u.public.slice(0,20),u.friends.slice(0,20)];for(;;){let t=s!==null&&c!==null&&p&&(s.profile!==null||f.length>0||s.favourites!==void 0||(s.panels?.length??0)>0||h.length>0||l)?{profile:s.profile,sections:s.sections,feed:f,favourites:s.favourites,comments:h,...s.panels&&s.panels.length>0?{panels:s.panels}:{},...s.panelOrder&&s.panelOrder.length>0?{panelOrder:s.panelOrder}:{}}:null,r=i(n,{feed:d,comments:m,friends:c===null||t===null?void 0:Lb(c,t)}),u=a(r,kx);if(Ex(r)<=131072&&Ex(u)<=196568||d.length+f.length+m.length+h.length===0&&t===null){let r=c===null||t===null?void 0:Ib(c,{roomId:e.id,owner:e.self.id},t,i(n,{feed:d,comments:m})),s=i(n,{feed:d,comments:m,friends:r});return a(s,o(s))}f.length>0?f=f.slice(0,-1):h.length>0?h=h.slice(0,-1):t===null?d.length>0?d=d.slice(0,-1):m=m.slice(0,-1):p=!1}},Nx=async(e,t,n,r,i)=>{for(let a=0;a<2;a++){let a=await fx(e),o=Ax(e,t,a,r.read);if(o!==null&&o.currentOwner&&(o.proof.version??-1)>n.version)return`newer`;let s=r.prepare?r.prepare(o,n):n,c=r.emptyFeeds?.(s)||o===null?ch:jx(e,t,o.proof,o.owner),l=i?.(c)??c,u=n.activity===void 0?l:Oh(l,n.activity),d=n.commentsLevel===void 0?u:Jv(u,n.commentsLevel),f=s.friends==null&&(d.friends.length>0||(d.comments?.friends.length??0)>0)?{...s,friends:Ox}:s,p=r.fit(f,d);if(a?.text===p)return`written`;let m=r.envelope();if(a!==null&&m===hx&&a.type===hx.type&&a.from===e.self.id?await e.edit(a.seq,p,m):await dx(e,p,m),(await fx(e))?.text===p)return`written`}return`failed`},Px=`Your name and public page on FKN Social. Unclaiming it takes your page down and frees the name.`,Fx=e=>e?.code,Ix=new Set([`bad-key`,`not-found`,`denied`,`blocked`,`closed`]),Lx=(e,t)=>e.open(t,{key:qb(t),defaults:{send:!1,receive:!0}}),Rx=async e=>{e.defaults().send&&await e.setDefault(`send`,!1).catch(()=>{}),await wx(e,vx)},zx=(e,t)=>{let n=Fx(e);return n===`bad-key`||n===`denied`?`taken`:n===`full`?t===`open`?`busy`:`out-of-claims`:`unavailable`},Bx=async(e,t)=>{let n=await px(e);return n===null?null:rx(n,e.id,e.owner,t)},Vx=async(e,t,n)=>{let r=await Bx(e,t);return r!==null&&Dx(r.signKey,n)},Hx=(e,t,n,r,i=`none`)=>Nx(e,t.keys,n,{read:(e,n,r)=>rx(e,n,r,t.name),prepare:(e,n)=>{if(i===`none`||e===null)return n;let r=e.proof.inbox!==null&&Dx(e.proof.inbox.dhKey,t.keys.dhKey)?e.proof.inbox.invite:null;return{...n,inbox:r,...i===`all`&&e.proof.displayName!==void 0?{displayName:e.proof.displayName}:{},...i===`all`&&e.proof.pageRoom!==void 0?{pageRoom:e.proof.pageRoom}:{}}},emptyFeeds:e=>typeof e.pageRoom==`string`,fit:(n,r)=>Mx(e,t.keys,n,r,(e,n)=>Xb(t.name,e,t.keys,n),(e,t)=>JSON.stringify(Zb(e,t??``)),n=>Y(L_.sign(Yb(e.id,e.self.id,n),t.keys.signSeed))),envelope:()=>Sx(e)},r),Ux=async(e,t,n,r,i)=>{let a;try{a=await Lx(e,n)}catch(e){return{ok:!1,reason:zx(e,`open`)}}try{try{await a.claim({description:Px})}catch(e){return{ok:!1,reason:zx(e,`claim`)}}return await Rx(a),await Hx(a,{keys:t,name:n},r??Kb,i,r===void 0?`all`:`none`).catch(()=>`failed`)===`failed`?{ok:!1,reason:`unrecorded`}:{ok:!0}}finally{await a.leave().catch(()=>{})}},Wx=async(e,t)=>{let n;try{n=await Lx(e,t)}catch(e){return Fx(e)===`bad-key`}try{return!n.claimed||n.owner!==n.self.id||await n.release(),!0}catch{return!1}finally{await n.leave().catch(()=>{})}},Gx=async(e,t,n,r)=>{if(!af(t.name))return`retired`;let i;try{i=await Lx(e,t.name)}catch(e){return Fx(e)===`bad-key`?`taken`:`unknown`}try{if(!i.claimed)return`lost`;if(i.owner!==i.self.id)return`taken`;await Rx(i);let e=await n();if(e===null)return await Vx(i,t.name,t.keys.signKey)?`held`:`unrecorded`;let a=await r(e,async()=>{let e=Ax(i,t.keys,await fx(i),(e,n,r)=>rx(e,n,r,t.name));return e===null?ch:jx(i,t.keys,e.proof,e.owner)});return a===null?await Vx(i,t.name,t.keys.signKey)?`held`:`unrecorded`:(await i.claim({description:Px}).catch(()=>{}),await Hx(i,t,a).catch(()=>`failed`)===`failed`?`unrecorded`:`held`)}catch{return`unknown`}finally{await i.leave().catch(()=>{})}},Kx=(e,t,n)=>Gx(e,t,()=>Promise.resolve(n),async e=>e),qx=async(e,t,n,r)=>{if(!af(t.name))return`failed`;let i;try{i=await Lx(e,t.name)}catch{return`failed`}try{return!i.claimed||i.owner!==i.self.id?`failed`:await Hx(i,t,n,r,`inbox`)}catch{return`failed`}finally{await i.leave().catch(()=>{})}},Jx=async(e,t,n,r,i)=>{let a=!1,o=await qx(e,t,n,e=>(a=Ch(e,r.app,r.at-sh)>=10,a?e:{...e,[i]:Dh(e[i],r)}));return a?`too-many`:o},Yx=async(e,t,n)=>{if(!af(n))return ch;let r;try{r=await Lx(e,n)}catch(e){return Ix.has(String(Fx(e)))?ch:null}try{let e=Ax(r,t,await fx(r),(e,t,r)=>rx(e,t,r,n));return e===null?ch:jx(r,t,e.proof,e.owner)}catch{return null}finally{await r.leave().catch(()=>{})}},Xx=async(e,t)=>{if(!af(t.name))return{inbox:null,pageRoom:null};let n;try{n=await Lx(e,t.name)}catch{return{inbox:null,pageRoom:null}}try{let e=Ax(n,t.keys,await fx(n),(e,n,r)=>rx(e,n,r,t.name));return{inbox:e!==null&&e.proof.inbox!==null&&Dx(e.proof.inbox.dhKey,t.keys.dhKey)?e.proof.inbox.invite:null,pageRoom:e?.proof.pageRoom??null}}catch{return{inbox:null,pageRoom:null}}finally{await n.leave().catch(()=>{})}},Zx=async(e,t,n)=>{if(!af(t))return!1;let r;try{r=await Lx(e,t)}catch(e){return Fx(e)!==`bad-key`&&null}try{return await Vx(r,t,n)}catch{return null}finally{await r.leave().catch(()=>{})}},Qx=async(e,t)=>{let n;try{n=await Lx(e,t)}catch(e){let t=String(Fx(e));return t===`full`?{view:{kind:`busy`}}:{view:Ix.has(t)?{kind:`none`}:{kind:`unavailable`}}}try{if(!n.claimed)return{view:{kind:`unheld`}};let e=await px(n),r=e===null?null:rx(e,n.id,n.owner,t);if(r===null)return{view:{kind:`none`}};let i={kind:`shown`,signKey:r.signKey,...r.displayName===void 0?{}:{displayName:r.displayName},profile:r.profile,inbox:r.inbox,page:r.page,feed:r.feed,favourites:r.favourites,comments:r.comments,...r.panels===void 0?{}:{panels:r.panels}};return r.pageRoom!==void 0&&e!==null?{view:i,pageRoom:r.pageRoom,coreRecord:{roomId:n.id,owner:n.owner,text:e}}:{view:r.friends===null||e===null?i:{...i,record:{name:t,roomId:n.id,owner:n.owner,text:e}}}}catch{return{view:{kind:`unavailable`}}}finally{await n.leave().catch(()=>{})}},$x=async(e,t)=>(await Qx(e,t)).view,eS=`Your inbox on FKN Social. Unclaiming it deletes the requests waiting there.`,tS={send:!0,receive:!1,maxMessageBytes:65536},nS=5e3,rS=e=>e?.code,iS=e=>X(e),aS=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),oS=e=>{let t=e.profile.inbox;return t===void 0?void 0:ey(t.value)},sS=async(e,t)=>{if(t!==void 0){let n=await ap(e,e=>oS(e)===t?{inbox:null}:{});if(!n.ok)return n}let n;try{n=await e.rooms.create({defaults:tS,schema:yx})}catch(e){return{ok:!1,reason:rS(e)===`full`?`busy`:`unavailable`}}try{try{await n.claim({description:eS})}catch(t){if(rS(t)!==`full`)return{ok:!1,reason:`unavailable`};let n=await ap(e,e=>oS(e)===void 0?{inbox:null}:{});return{ok:!1,reason:`out-of-claims`,roster:n.ok?n.roster:void 0}}let t=await ap(e,e=>typeof oS(e)==`string`?{}:{inbox:n.invite});return(!t.ok||oS(t.roster)!==n.invite)&&await n.release().catch(()=>{}),t}finally{await n.leave().catch(()=>{})}},cS=async(e,t)=>{let n;try{n=await e.join(t)}catch(e){return rS(e)===`bad-key`}try{return!n.claimed||n.owner!==n.self.id||await n.release(),!0}catch{return!1}finally{await n.leave().catch(()=>{})}},lS=(e,t)=>({status:e,roster:t,waiting:[],accepted:[]}),uS=async e=>{let t=new Map,n=[],r=await e.on(e=>{e.type===`message`&&t.set(e.message.seq,e.message.text)});try{let r=0;for(;t.size<100;){let i=await e.backlog(r,100-t.size);if(i.last>r&&await ux(()=>t.has(i.last),nS).catch(()=>{n.push(i.last)}),!i.more||i.last<=r)break;r=i.last}}catch{}finally{r()}return{heard:[...t].sort(([e],[t])=>e-t).slice(0,100),unread:n}},dS=(e,t)=>e.friends[of(t)]?.value.state===`active`,fS=async(e,t,n,r,i)=>{let a=i,o=!1,s=[...r.unread],c=[],l=[],u=new Map;for(let[i,d]of r.heard){let r=xb(d,n.id,t);if(r===null||aS(r.signKey,t.signKey)){s.push(i);continue}let{body:f,signKey:p,dhKey:m}=r,h={signKey:p,dhKey:m,name:f.name,fingerprint:of(p),confirmed:null};if(f.kind===`accept`){let t=await hp(e,{signKey:p,dhKey:m,name:f.name,profile:f.p,pairNonce:iS(f.r),linkedVia:`request`,inbox:f.x},Date.now());if(!t.outcome.ok)continue;if(t.applied){a=t.outcome.roster,o=!0;let e=a.friends[h.fingerprint]?.value.name??f.name;l.includes(e)||l.push(e)}s.push(i)}else if(f.kind===`friend`){let e=u.get(h.fingerprint);e!==void 0&&(s.push(e.seq),c.splice(c.indexOf(e),1));let t={kind:`friend`,inbox:n.invite,seq:i,sender:h,request:f,friend:dS(a,p)};u.set(h.fingerprint,t),c.push(t)}else if(f.kind===`comment`){let e=a.friends[h.fingerprint]?.value;e?.state===`active`&&Ev(a,`comments`)!==`off`?c.push({kind:`comment`,inbox:n.invite,seq:i,sender:{...h,name:e.name},text:f.text,id:zv(d)}):s.push(i)}else dS(a,p)?c.push({kind:`party`,inbox:n.invite,seq:i,sender:h,url:f.url}):s.push(i)}return await Promise.all([...new Set(s)].map(e=>n.delete(e).catch(()=>{}))),{roster:o?a:void 0,waiting:c,accepted:l}},pS=async(e,t,n)=>{let r=oS(n);if(r===void 0){let t=await sS(e);return t.ok?lS(`ready`,t.roster):lS(t.reason===`out-of-claims`?`out-of-claims`:`unavailable`,t.roster)}if(r===null)return lS(`none`);let i=async()=>{let t=await ap(e,e=>oS(e)===r?{inbox:null}:{});return lS(`none`,t.ok?t.roster:void 0)},a;try{a=await e.rooms.join(r)}catch(e){return rS(e)===`bad-key`?i():lS(`unavailable`)}let o;try{if(!a.claimed)return await i();if(a.owner!==a.self.id)return lS(`taken`);if(await wx(a,yx),a.mailbox===null)return lS(`not-kept`);o=await fS(e,t,a,await uS(a),n)}catch{return lS(`unavailable`)}finally{await a.leave().catch(()=>{})}return{status:`ready`,roster:o.roster,waiting:o.waiting,accepted:o.accepted}},mS=new Set([`bad-key`,`not-found`,`denied`,`blocked`,`closed`,`invalid`]),hS=async(e,t,n,r,i)=>{let a;try{a=await e.join(t)}catch(e){let t=String(rS(e));return t===`full`?`busy`:mS.has(t)?`closed`:`unavailable`}try{return a.mailbox===null?`closed`:(await a.send(gb(a.id,n,r,i),xx(a,_x)),`sent`)}catch(e){let t=String(rS(e));return t===`storage`||t===`quota`||t===`full`?`full`:t===`rate-limited`?`busy`:t===`denied`||t===`blocked`?`closed`:`unavailable`}finally{await a.leave().catch(()=>{})}},gS=async(e,t,n)=>{let r;try{r=await e.join(t)}catch{return}try{r.claimed&&r.owner===r.self.id&&await r.delete(n).catch(()=>{})}finally{await r.leave().catch(()=>{})}},_S=async(e,t,n)=>{if(aS(n.signKey,t.keys.signKey))return{ok:!1,reason:`self`};if(t.inbox===null)return{ok:!1,reason:`no-inbox`};if(n.inbox===null)return{ok:!1,reason:`closed`};let{invite:r,dhKey:i}=n.inbox,a=await mp(e,{signKey:n.signKey,dhKey:i,name:n.name,inbox:r},Date.now());if(!a.ok)return a;let o=await hS(e.rooms,r,i,{to:Y(n.signKey),name:t.name,kind:`friend`,p:t.profile,x:t.inbox,r:a.nonce},t.keys);return o===`sent`?{ok:!0}:{ok:!1,reason:o}},vS=async(e,t,n,r)=>{if(!r)return await gS(e.rooms,n.inbox,n.seq),{ok:!0};let{sender:i,request:a}=n,o=await fp(e,{signKey:i.signKey,dhKey:i.dhKey,name:i.name,profile:a.p,pairNonce:iS(a.r),linkedVia:`request`,inbox:a.x},Date.now());return o.ok?await hS(e.rooms,a.x,i.dhKey,{to:a.k,name:t.name,kind:`accept`,p:t.profile,x:t.inbox,r:a.r},t.keys)===`sent`?(await gS(e.rooms,n.inbox,n.seq),{ok:!0,roster:o.roster}):{ok:!1,reason:`unsent`,roster:o.roster}:o},yS=async(e,t,n,r)=>{let i=ey(n.inbox);if(i===null)return{ok:!1,reason:`no-inbox`};let a=pf(r,pb);if(a===null)return{ok:!1,reason:`link`};let o=await hS(e.rooms,i,iS(n.dhKey),{to:n.signKey,name:t.name,kind:`party`,url:a},t.keys);return o===`sent`?{ok:!0}:{ok:!1,reason:o}},bS=(e,t)=>gS(e.rooms,t.inbox,t.seq),xS=async(e,t,n,r)=>{let i=Rv(r);if(i===null)return{ok:!1,reason:`invalid`};let a=await tp(e);if(!a.ok)return a;let o=await $x(e.rooms,n);if(o.kind===`busy`||o.kind===`unavailable`)return{ok:!1,reason:o.kind};if(o.kind!==`shown`||!dS(a.roster,o.signKey))return{ok:!1,reason:`not-friend`};if(o.inbox===null)return{ok:!1,reason:`closed`};let s=await hS(e.rooms,o.inbox.invite,o.inbox.dhKey,{to:Y(o.signKey),name:t.name,kind:`comment`,text:i},t.keys);return s===`sent`?{ok:!0}:{ok:!1,reason:s}},SS=`Your profile page on FKN Social. Unclaiming it deletes stored activity and comments and moves your profile back to your name room.`,CS={send:!1,receive:!0},wS=e=>e?.code,TS=e=>{let t=e.profile.pageRoom;return t===void 0?void 0:ey(t.value)},ES=e=>{let t=e.profile.visibility?.value;return t!==void 0&&`invite`in t&&typeof t.invite==`string`},DS=(e,t)=>{if(ES(e))return!1;if(_f(e).level===`public`)return!0;let n=xf(e);return n.displayName!==``||n.bio!==``||n.links.length>0||(e.profile.avatar?.value??null)!==null||(e.profile.background?.value??null)!==null||e.profile.page!==void 0||hm(e).length>0||Zv(e).length>0||t!==void 0&&(t.public.length>0||t.friends.length>0||(t.comments?.public.length??0)>0||(t.comments?.friends.length??0)>0)},OS=async e=>{e.defaults().send&&await e.setDefault(`send`,!1).catch(()=>{}),await wx(e,bx)},kS=(e,t,n,r)=>Nx(e,t,n,{read:cx,fit:(n,r)=>Mx(e,t,n,r,(e,n)=>ox(e,t,n),(e,t)=>JSON.stringify(sx(e,t??``)),n=>Y(L_.sign(ax(e.id,e.self.id,n),t.signSeed))),envelope:()=>Cx(e)},r),AS=e=>t=>({public:Sh(t.public,e.public),friends:Sh(t.friends,e.friends),comments:Gv(t,e)}),jS=async(e,t,n,r,i)=>{if(i!==void 0&&!(await ap(e,e=>TS(e)===i?{pageRoom:null}:{})).ok)return{ok:!1,reason:`unavailable`};let a;try{a=await e.rooms.create({defaults:CS,schema:bx})}catch{return{ok:!1,reason:`unavailable`}}try{try{await a.claim({description:SS})}catch(t){if(wS(t)!==`full`)return{ok:!1,reason:`unavailable`};let n=await ap(e,e=>TS(e)===void 0?{pageRoom:null}:{});return{ok:!1,reason:`out-of-claims`,roster:n.ok?n.roster:void 0}}if(await OS(a),await kS(a,t,n,r).catch(()=>`failed`)===`failed`)return await a.release().catch(()=>{}),{ok:!1,reason:`unavailable`};let i=await ap(e,e=>typeof TS(e)==`string`?{}:{pageRoom:a.invite});if(i.ok&&TS(i.roster)===a.invite)return{ok:!0,invite:a.invite,roster:i.roster};if(await a.release().catch(()=>{}),!i.ok)return{ok:!1,reason:`unavailable`};let o=TS(i.roster);if(typeof o==`string`){let a=await MS(e,t,o,n,r);return a.status===`ready`?{ok:!0,invite:o,roster:i.roster}:{ok:!1,reason:`unavailable`,roster:a.roster??i.roster}}return{ok:!1,reason:`unavailable`}}finally{await a.leave().catch(()=>{})}},MS=async(e,t,n,r,i)=>{let a=async()=>{let t=await ap(e,e=>TS(e)===n?{pageRoom:null}:{});return{status:`inline`,roster:t.ok?t.roster:void 0}},o;try{o=await e.rooms.join(n)}catch(e){return wS(e)===`bad-key`?await a():{status:`unavailable`}}try{return o.claimed?o.owner===o.self.id?(await OS(o),o.mailbox===null?{status:`not-kept`}:(await o.claim({description:SS}).catch(()=>{}),{status:await kS(o,t,r,i).catch(()=>`failed`)===`failed`?`unavailable`:`ready`})):{status:`taken`}:await a()}catch{return{status:`unavailable`}}finally{await o.leave().catch(()=>{})}},NS=async(e,t,n,r,i)=>{let a;try{a=await e.join(t)}catch{return`failed`}try{return!a.claimed||a.owner!==a.self.id||a.mailbox===null?`failed`:await kS(a,n,r,i)}catch{return`failed`}finally{await a.leave().catch(()=>{})}},PS=async(e,t,n,r,i,a)=>{let o=!1,s=await NS(e,t,n,r,e=>(o=Ch(e,i.app,i.at-sh)>=10,o?e:{...e,[a]:Dh(e[a],i)}));return o?`too-many`:s},FS=async(e,t)=>{let n;try{n=await e.join(t)}catch(e){return wS(e)===`bad-key`}try{return!n.claimed||n.owner!==n.self.id||await n.release(),!0}catch{return!1}finally{await n.leave().catch(()=>{})}},IS=async(e,t,n)=>{let r;try{r=await e.join(n)}catch{return}try{if(!r.claimed||r.owner!==r.self.id||r.mailbox===null)return;let e=Ax(r,t,await fx(r),cx);if(e===null||e.currentOwner)return;await OS(r),await kS(r,t,{version:0,profile:null})}catch{}finally{await r.leave().catch(()=>{})}},LS=e=>e?.code,RS=e=>[e.profile.avatar?.value??null,e.profile.background?.value??null],zS=e=>{let t=e.profile.visibility?.value;return t!==void 0&&`invite`in t&&typeof t.invite==`string`?t.invite:null},BS=e=>{let t=_f(e).level,n=zS(e)===null,{displayName:r,bio:i,links:a}=xf(e),[o,s]=RS(e),c=n?vm(e):[],l=n?_m(e):[];return{profile:t===`friends`&&n?{displayName:r,bio:i,links:a,...o===null?{}:{avatar:o},...s===null?{}:{background:s}}:null,sections:Av(e,t!==`me`&&n),...Ev(e,`favourites`)===`friends`?{favourites:Zv(e)}:{},...c.length>0?{panels:c}:{},...c.length>0&&l.length>0?{panelOrder:ym(e)}:{},members:zf(e).map(e=>X(e.dhKey)).filter(e=>e?.length===32),left:Object.entries(e.friends).filter(([,e])=>e.value.state!==`active`).map(([e])=>e).sort()}},VS=e=>{let t=xf(e),n=Math.max(0,...Lf(e).map(({lamport:e})=>e)),r=zS(e)===null,i=_f(e).level===`public`&&r,a=kv(e,i),o=Ev(e,`activity`),s=BS(e),c=Ev(e,`favourites`)===`public`?Zv(e):void 0,l=r?_m(e):[],u=Ev(e,`comments`);if(!i)return{version:n,profile:null,page:a,activity:o,favourites:c,commentsLevel:u,...l.length>0?{panels:l}:{},friends:s};let[d,f]=RS(e);return{version:n,profile:{displayName:t.displayName,bio:t.bio,links:t.links,avatar:d,background:f},page:a,activity:o,favourites:c,commentsLevel:u,...l.length>0?{panels:l}:{},friends:s}},HS=(e,t=!1)=>({...VS(e),inbox:t?null:oS(e)??null}),US=(e,t,n=!1)=>{let r=Math.max(0,...Lf(e).map(({lamport:e})=>e)),i=n?null:oS(e)??null,a=zS(e)===null,o=_f(e).level===`public`&&a,s=t!==null&&o?xf(e).displayName:``;return{version:r,profile:null,inbox:i,...s===``?{}:{displayName:s},...t===null?{}:{pageRoom:t}}},WS=e=>JSON.stringify({inbox:e.inbox??null,displayName:e.displayName??null,pageRoom:e.pageRoom??null}),GS=(e,t=!1)=>{let n=TS(e);return typeof n==`string`?US(e,n,t):HS(e,t)},KS=async(e,t,n,r)=>{if(r?.skipNameIfUnchanged===!0&&r.lastNameStatus===`held`&&n!==null&&!(`then`in n)){let{roster:i,inboxTaken:a}=n,o=TS(i);if(typeof o==`string`){let n=WS(US(i,o,a));if(n===r.lastCoreKey){let r=await MS(e,t.keys,o,VS(i));if(r.status!==`inline`)return{status:`held`,pageStatus:r.status,...r.roster?{roster:r.roster}:{},coreKey:n};let s=r.roster??i;return{status:await Kx(e.rooms,t,HS(s,a)),pageStatus:`inline`,...r.roster?{roster:r.roster}:{},coreKey:null}}}}let i=`unused`,a,o=null,s=n!==null&&!(`then`in n)?n:null,c=s?TS(s.roster):void 0,l=typeof c==`string`?MS(e,t.keys,c,VS(s.roster)):null,u=await Gx(e.rooms,t,()=>Promise.resolve(n),async({roster:n,inboxTaken:r},s)=>{let c=TS(n);if(typeof c==`string`){l??=MS(e,t.keys,c,VS(n));let s=await l;if(a=s.roster,s.status===`inline`)return i=`inline`,o=null,HS(s.roster??n,r);if(i=s.status,s.status===`unavailable`)return o=null,null;let u=US(n,c,r);return o=WS(u),u}if(c===void 0){let c=await s();if(!DS(n,c))return i=`unused`,o=null,HS(n,r);let l=await jS(e,t.keys,VS(n),AS(c));if(a=l.roster,l.ok){i=`ready`;let e=US(l.roster,l.invite,r);return o=WS(e),e}return i=l.reason===`out-of-claims`?`out-of-claims`:`unavailable`,o=null,HS(l.roster??n,r)}return i=`inline`,o=null,HS(n,r)}),d=await Promise.resolve(n);if(d!==null&&l===null&&typeof TS(d.roster)==`string`&&(l=MS(e,t.keys,TS(d.roster),VS(d.roster))),l!==null){let e=await l;i=e.status,e.roster!==void 0&&(a=e.roster)}return{status:u,pageStatus:i,...a?{roster:a}:{},coreKey:u===`held`?o:null}},qS=async(e,t,n)=>{for(let r=0;r<2;r++){let r=await tp(e);if(!r.ok)return`failed`;let i=TS(r.roster);if(typeof i==`string`&&e.rooms.join!==void 0){let a=await NS(e.rooms,i,t.keys,VS(r.roster),n);if(a!==`newer`)return a}else{let i=await qx(e.rooms,t,HS(r.roster),n);if(i!==`newer`)return i}}return`failed`},JS=async(e,t,n)=>{let r={id:n.id,name:n.sender.name,text:n.text,at:Date.now()};return await qS(e,t,e=>Kv(e,r))===`written`&&(await bS(e,n),!0)},YS=async(e,t,n=!1)=>{let r=await ap(e,e=>_f(e).level===`public`?{}:{visibility:{level:`public`}});if(!r.ok)return r;let i=await KS(e,t,{roster:r.roster,inboxTaken:n});return{ok:!0,roster:i.roster??r.roster,status:i.status,pageStatus:i.pageStatus}},XS=async(e,t,n=!1)=>{let r;try{r=await e.join(t)}catch(e){return LS(e)===`bad-key`}try{return r.claimed?r.owner===r.self.id?(await r.release(),!0):!n:!0}catch{return!1}finally{await r.leave().catch(()=>{})}},ZS=async(e,t,n,r,i=!1)=>{let a=zS(n);if(a!==null&&!await XS(e.rooms,a))return{ok:!1,reason:`unavailable`};let o=_f(n).level,s=o===`public`,c=o===`friends`&&r===`me`,l=[],u=await ap(e,e=>{if(s){let t=RS(e);return l=t.some(e=>e!==null)?t:RS(n),_f(e).level===r&&t.every(e=>e===null)?{}:{visibility:{level:r},avatar:null,background:null}}if(_f(e).level===`public`)return{};if(c){let t=RS(e);if(t.some(e=>e!==null))return l=t,{visibility:{level:r},avatar:null,background:null}}return{visibility:{level:r}}});if(!u.ok)return u;let d=await KS(e,t,{roster:u.roster,inboxTaken:i});return typeof TS(u.roster)==`string`&&d.pageStatus!==`ready`&&d.pageStatus!==`inline`?{ok:!1,reason:`unavailable`,pageStatus:d.pageStatus}:(await Bp(e.storage,l),{ok:!0,roster:d.roster??u.roster,status:d.status,pageStatus:d.pageStatus})},QS=async(e,t)=>{let n=zS(t);if(n===null)return{ok:!0,roster:t};if(!await XS(e.rooms,n,!0))return{ok:!1,reason:`unavailable`};let r=[],i=await ap(e,e=>zS(e)===n?(r=RS(e),{visibility:{level:`friends`},avatar:null,background:null}):{});return i.ok&&await Bp(e.storage,r),i},$S=`FKNS`,eC=e=>{if(e.length!==32)throw Error(`social: a seed is 32 bytes`);return`${$S}-${(Xd(e).match(/.{1,4}/g)??[]).join(`-`)}`},tC=e=>{let t=Qd(e),n=t.length===56&&t.startsWith(`FKNS`)?t.slice(4):t;if(n.length!==52||!Zd(n))return null;let r=$d(n);return r!==null&&r.length===32?r:null},nC=`v1/identity.json`,rC=1024,iC=3e3,aC=({seed:e,name:t})=>{let n=JSON.stringify({v:1,seed:Y(e),name:t,pad:``});return n.replace(`"pad":""`,`"pad":"${` `.repeat(rC-n.length)}"`)},oC=e=>{let t;try{t=JSON.parse(e)}catch{return null}if(typeof t!=`object`||!t)return null;let{v:n,seed:r,name:i}=t;if(n!==1)return`newer`;if(typeof r!=`string`||i!==null&&typeof i!=`string`)return null;let a=X(r);return a?.length===32?{seed:a,name:i}:null},sC=async e=>{let t;try{t=await e.read(nC)}catch(e){return{ok:!1,refusal:kf(e)}}if(t===null)return{ok:!0,identity:null};let n=oC(t);return n===`newer`?{ok:!1,refusal:`newer`}:n?{ok:!0,identity:n}:{ok:!1,refusal:`reset`}},cC=async(e,t)=>{try{return await e.write(nC,aC(t)),null}catch(e){return kf(e)}},lC=async(e,t)=>{let n=await sC(e);if(!n.ok||n.identity!==null)return n;let r=await cC(e,{seed:ov(),name:null});return r===null?(await t(iC),sC(e)):{ok:!1,refusal:r}},uC=(e,t)=>{let n=e=>t()?e():Promise.reject(Error(`social: the FKN account changed`)),{cloud:r,storage:i}=e;return{...e,cloud:{list:()=>n(()=>r.list()),read:e=>n(()=>r.read(e)),write:(e,t)=>n(()=>r.write(e,t)),remove:e=>n(()=>r.remove(e))},storage:{put:e=>n(()=>i.put(e)),get:(e,t)=>n(()=>i.get(e,t)),delete:e=>n(()=>i.delete(e)),list:()=>n(()=>i.list())}}},dC=e=>({kind:e}),fC=async({account:e,cloud:t},n)=>{let r=await e.availability().catch(()=>`unknown`);if(r===`unknown`)return{kind:`unreachable`};if(r===`disconnected`)return{kind:`signed-out`};let i=await e.encryption().catch(()=>null);if(i===null)return{kind:`unreachable`};if(!i.enrolled)return{kind:`no-keys`};if(!i.unlocked)return{kind:`locked`};n?.();let a=await sC(t);return a.ok?a.identity===null?{kind:`no-identity`}:{kind:`ready`,identity:a.identity}:dC(a.refusal)},pC=async(e,t,n)=>{let r=rf(t);if(!r.ok)return r;let i=await lC(e.cloud,e.sleep);if(!i.ok)return{ok:!1,reason:i.refusal};let a=i.identity;if(a===null)return{ok:!1,reason:`unreachable`};if(a.name===r.name)return{ok:!0};let o=sv(a.seed),s=typeof n?.pageRoom==`string`,c=a.name===null||s?void 0:await Yx(e.rooms,o,a.name);if(c===null)return{ok:!1,reason:`unavailable`};let l=await Ux(e.rooms,o,r.name,n,c===void 0?void 0:e=>({public:Sh(e.public,c.public),friends:Sh(e.friends,c.friends),comments:Gv(e,c)}));if(!l.ok&&l.reason!==`unrecorded`)return l;if(l.ok&&n===void 0){let t=await Xx(e.rooms,{keys:o,name:r.name});t.pageRoom!==null&&await IS(e.rooms,o,t.pageRoom)}if(!l.ok&&a.name!==null)return await Wx(e.rooms,r.name)?{ok:!1,reason:`unavailable`}:{ok:!1,reason:`unavailable`,kept:r.name};let u=await cC(e.cloud,{...a,name:r.name});return u===null?a.name===null||await Wx(e.rooms,a.name)?{ok:!0}:{ok:!0,kept:a.name}:{ok:!1,reason:u}},mC=async(e,t)=>await Wx(e.rooms,t)?{ok:!0}:{ok:!1,reason:`unavailable`},hC=async(e,t,n)=>t.name===null?{ok:!1,reason:`empty`}:Ux(e.rooms,sv(t.seed),t.name,n),gC=async(e,t)=>{let n=tC(t);if(n===null)return{ok:!1,reason:`bad-recovery-key`};let r=await cC(e.cloud,{seed:n,name:null});return r===null?{ok:!0}:{ok:!1,reason:r}},_C=async e=>{let t=await cC(e.cloud,{seed:ov(),name:null});return t===null?{ok:!0}:{ok:!1,reason:t}},vC=async({cloud:e,rooms:t,storage:n})=>{let r=await tp({cloud:e});if(r.ok)return{ok:!0};if(r.reason!==`reset`)return{ok:!1,reason:r.reason};let i=await sC(e);if(i.ok&&i.identity?.name!=null){let n=await Xx(t,{keys:sv(i.identity.seed),name:i.identity.name});if(n.inbox!==null||n.pageRoom!==null){let r=await tp({cloud:e});if(r.ok)return{ok:!0};if(r.reason!==`reset`)return{ok:!1,reason:r.reason};n.inbox!==null&&await cS(t,n.inbox),n.pageRoom!==null&&await FS(t,n.pageRoom)}}let a=await n.list().then(({objects:e})=>e,()=>[]);for(let{url:e}of a)await n.delete(e).catch(()=>{});try{let t=(await e.list()).map(({path:e})=>e).filter(e=>e!==nC);for(let n of t)await e.remove(n);return{ok:!0}}catch(e){return{ok:!1,reason:kf(e)}}},yC=e=>Array.isArray(e)?oh.filter(t=>e.includes(t)):[],bC=(e,t)=>{let n=e.apps[t]?.value;if(typeof n!=`object`||!n)return null;let{kinds:r,level:i,state:a}=n;return{kinds:yC(r),level:i===`public`?`public`:`friends`,state:a===`asked`||a===`allowed`?a:`stopped`}},xC=e=>e?.state===`allowed`?{state:`allowed`,kinds:e.kinds}:e?.state===`asked`?{state:`asked`}:{state:`off`},SC=e=>e.reason===`locked`?`locked`:`unavailable`,CC=async e=>{let t=await fC(e);if(t.kind===`locked`)return`locked`;if(t.kind===`no-identity`)return`no-name`;if(t.kind!==`ready`)return`unavailable`;let{seed:n,name:r}=t.identity;if(r===null)return`no-name`;let i=await tp(e);return i.ok?{me:{keys:sv(n),name:r},roster:i.roster}:SC(i)},wC=(e,t)=>e.length===t.length&&e.every(e=>t.includes(e)),TC=e=>{let t=async(t,n)=>{let r=await CC(e);if(typeof r==`string`)return{state:r};let i=bC(r.roster,t);if(n(i)===null)return xC(i);let a=await op(e,t,e=>{let r=n(bC(e,t));return r===null?null:{grant:r}});return a.ok?xC(bC(a.roster,t)):{state:SC(a)}},n=Promise.resolve(),r=e=>{let t=n.then(e,e);return n=t.catch(()=>{}),t};return{publishing:async t=>{let n=await CC(e);return typeof n==`string`?{state:n}:xC(bC(n.roster,t))},allow:(e,n)=>{let r=yC(n?.kinds);return t(e,e=>r.length===0||e?.state===`allowed`||e?.state===`asked`&&wC(e.kinds,r)?null:{kinds:r,level:e?.level??`friends`,state:`asked`})},stop:e=>t(e,e=>e===null||e.state===`stopped`?null:{...e,state:`stopped`}),publish:(t,n)=>r(async()=>{for(let r=0;r<2;r++){let r=await CC(e);if(typeof r==`string`)return{ok:!1,reason:r};let i=bC(r.roster,t),a=Ev(r.roster,`activity`);if(i?.state!==`allowed`||a===`off`)return{ok:!1,reason:`not-allowed`};let o=bh(n,t,Date.now());if(o===null)return{ok:!1,reason:`invalid`};if(!i.kinds.includes(o.kind))return{ok:!1,reason:`not-allowed`};let s=TS(r.roster),c=typeof s==`string`?await PS(e.rooms,s,r.me.keys,VS(r.roster),o,i.level):await Jx(e.rooms,r.me,HS(r.roster),o,i.level);if(c===`written`)return{ok:!0,id:o.id};if(c!==`newer`)return{ok:!1,reason:c===`too-many`?`too-many`:`unavailable`}}return{ok:!1,reason:`unavailable`}})}},EC=(e,t,n)=>op(e,t,e=>{let r=bC(e,t);if(r===null)return null;let i={...r,...n},a=i.state===`allowed`&&r.state!==`allowed`&&Ev(e,`activity`)===`off`?Dv(wv(e),`activity`,i.level):void 0;return a===void 0&&JSON.stringify(i)===JSON.stringify(r)?null:{grant:i,page:a}}),DC=new TextEncoder,OC=e=>DC.encode(e),kC=0,AC=e=>{let t=[e.roomId,e.memberId,String(e.at),e.name,e.displayName,e.avatarUrl];for(let e of t)if(e.includes(`\0`))throw Error(`social: a signed field may not contain a NUL`);if(e.signKey.length!==32||e.dhKey.length!==32)throw Error(`social: a public key is 32 bytes`);let n=[OC(q_),Uint8Array.of(kC),OC(e.roomId),Uint8Array.of(kC),OC(e.memberId),Uint8Array.of(kC),OC(String(e.at)),Uint8Array.of(kC),e.signKey,Uint8Array.of(kC),e.dhKey,Uint8Array.of(kC),OC(e.name.normalize(`NFC`)),Uint8Array.of(kC),OC(e.displayName.normalize(`NFC`)),Uint8Array.of(kC),OC(e.avatarUrl)],r=n.reduce((e,t)=>e+t.length,0),i=new Uint8Array(r),a=0;for(let e of n)i.set(e,a),a+=e.length;return i},jC=(e,t)=>({t:`social.hello`,v:1,k:Y(e.signKey),d:Y(e.dhKey),h:e.name,n:e.displayName,i:e.avatarUrl===``?null:e.avatarUrl,a:e.at,s:Y(L_.sign(AC(e),t))}),MC=e=>{if(typeof e!=`object`||!e)return!1;let t=e;return t.t===`social.hello`&&typeof t.k==`string`&&typeof t.d==`string`&&typeof t.h==`string`&&typeof t.n==`string`&&(t.i===null||typeof t.i==`string`)&&typeof t.a==`number`&&typeof t.s==`string`},NC=(e,t,n)=>{if(!MC(e))return{ok:!1,reason:`malformed`};if(e.v!==1)return{ok:!1,reason:`unsupported-version`};let r=X(e.k),i=X(e.d),a=X(e.s);if(!r||!i||!a)return{ok:!1,reason:`malformed`};if(r.length!==32||i.length!==32)return{ok:!1,reason:`bad-key`};if(a.length!==64||!Number.isSafeInteger(e.a))return{ok:!1,reason:`malformed`};let o={roomId:t,memberId:n,at:e.a,signKey:r,dhKey:i,name:e.h,displayName:e.n,avatarUrl:e.i??``},s;try{s=AC(o)}catch{return{ok:!1,reason:`malformed`}}try{if(!L_.verify(a,s,r,{zip215:!1}))return{ok:!1,reason:`bad-signature`}}catch{return{ok:!1,reason:`bad-signature`}}return{ok:!0,hello:o}},PC=(e,t)=>({roomId:e,selfMemberId:t,participants:new Map,keyByMember:new Map}),FC=(e,t)=>({memberId:e,status:`silent`,identity:null,refusal:null,self:e===t}),IC=(e,t)=>{e.participants.has(t)||e.participants.set(t,FC(t,e.selfMemberId))},LC=(e,t,n)=>{e.participants.set(t,{...FC(t,e.selfMemberId),status:`unverified`,refusal:n})},RC=(e,t,n)=>({fingerprint:of(t),handle:cf(e.h,t),name:e.h,displayName:e.n,avatar:e.i,signKey:e.k,dhKey:e.d,shortFingerprint:lf(t)}),zC=e=>X(e),BC=(e,t,n,r,i)=>{if(typeof n!=`object`||!n)return!1;let a=n;if(a.t!==`social.hello`)return!1;if(IC(e,t),typeof a.h!=`string`||!af(a.h)||typeof a.n!=`string`||ff(a.n,{max:32,multiline:!1})!==null)return LC(e,t,`bad-name`),!0;if(typeof a.a!=`number`||Math.abs(a.a-r)>6e5)return LC(e,t,`stale`),!0;let o=NC(n,e.roomId,t);if(!o.ok)return LC(e,t,o.reason),!0;let s=n,c=RC(s,zC(s.k),zC(s.d));for(let[n,r]of e.keyByMember)if(n!==t&&r===s.k)return LC(e,n,`duplicate-key`),LC(e,t,`duplicate-key`),e.keyByMember.set(t,s.k),!0;e.keyByMember.set(t,s.k);let l=i.friendByFingerprint(c.fingerprint)===null?i.friendNamed(c.name)?`rekeyed`:`verified`:`friend`;return e.participants.set(t,{memberId:t,status:l,identity:c,refusal:null,self:t===e.selfMemberId}),!0},VC=/^[A-Za-z0-9_-]+$/,HC=43,UC=(e,t)=>`${e}/i#${t.key}.${t.nonce}.${t.roomId}`,WC=e=>{if(e[HC]!==`.`||e[87]!==`.`)return null;let t=e.slice(0,HC),n=e.slice(44,87),r=e.slice(88);return r.length===0||!VC.test(t)||!VC.test(n)?null:{roomId:r,key:t,nonce:n}},GC=9e5,KC=1e4,qC={t:`social.whois`,v:1},JC=e=>({state:e,listeners:new Set}),YC=(e,t)=>{e.state=t;for(let n of e.listeners)n(t)},XC=e=>t=>(e.listeners.add(t),()=>{e.listeners.delete(t)}),ZC=()=>Y(crypto.getRandomValues(new Uint8Array(16))),QC=e=>{try{let t=JSON.parse(e);return typeof t==`object`&&t?t:null}catch{return null}},$C=(e,t)=>JSON.stringify(jC({roomId:e.id,memberId:e.self.id,at:Date.now(),signKey:t.keys.signKey,dhKey:t.keys.dhKey,name:t.name,displayName:``,avatarUrl:``},t.keys.signSeed)),ew=(e,t,n,r,i,a,o)=>{let s=PC(t.id,t.self.id);BC(s,r,i,a,{friendByFingerprint:()=>null,friendNamed:()=>!1});let c=s.participants.get(r)?.identity;if(!c)return null;let l={memberId:r,fingerprint:c.fingerprint,name:c.name,displayName:c.displayName,signKey:X(c.signKey),dhKey:X(c.dhKey),confirmed:null,friend:n(c.fingerprint)};return Zx(e.rooms,l.name,l.signKey).then(e=>o({...l,confirmed:e})),l},tw=async(e,t,n)=>{if(e.writerId===null)return{ok:!1,reason:`no-writer`};let r;try{r=await e.rooms.create({members:2})}catch{return{ok:!1,reason:`unavailable`}}let i=crypto.getRandomValues(new Uint8Array(32)),a=r.invite.indexOf(`.`),o=UC(Vu,{key:r.invite.slice(0,a),nonce:Y(i),roomId:r.invite.slice(a+1)}),s=Date.now()+GC,c=JC({kind:`waiting`}),l=new Map,u=null,d=null,f=!1,p=()=>{},m=()=>`peer`in c.state?c.state.peer:null,h=()=>c.state.kind===`friends`,g=async e=>{h()||YC(c,e),!f&&(f=!0,clearTimeout(x),p(),await r.leave().catch(()=>{}))},_=async()=>{let t=m();if(d===null||t===null)return;let n=await fp(e,d,Date.now());n.ok?await g({kind:`friends`,peer:t}):YC(c,{kind:`unsaved`,peer:t,reason:n.reason})},v=(t,i,a)=>{let o=m();if(o!==null&&o.memberId===t)return;let s=ew(e,r,n,t,i,a,e=>{m()?.memberId===e.memberId&&c.state.kind===`joined`&&YC(c,{kind:`joined`,peer:e})});s!==null&&(c.state.kind===`waiting`||c.state.kind===`left`)&&YC(c,{kind:`joined`,peer:s})},y=async(e,n)=>{let a=m();if(c.state.kind!==`offered`||a===null||a.memberId!==e)return;let o=ub(n,{roomId:r.id,fromMemberId:e,selfMemberId:r.self.id},{dhSeed:t.keys.dhSeed,theirSignKey:a.signKey,theirDhKey:a.dhKey});o.ok&&l.get(o.body.offerId)===e&&(d={signKey:a.signKey,dhKey:a.dhKey,name:a.name,profile:o.body.profile,pairNonce:i,linkedVia:`invite`,inbox:o.body.inbox},await _())},b=e=>{if(e.type===`left`&&d===null&&e.id===m()?.memberId&&(c.state.kind===`joined`||c.state.kind===`offered`)){YC(c,{kind:`left`});return}if(e.type!==`message`||e.message.from===r.self.id)return;let{from:n,text:i,at:a}=e.message,o=QC(i);o?.t===`social.whois`?(r.send($C(r,t)).catch(()=>{}),c.state.kind===`offered`&&m()?.memberId===n&&u!==null&&r.send(u).catch(()=>{})):o?.t===`social.hello`?v(n,o,a):o?.t===`social.accept`&&y(n,o)},x=setTimeout(()=>void g({kind:`closed`}),GC);return p=await r.on(b),r.closed.then(()=>void g({kind:`closed`})),{ok:!0,invite:{link:o,expiresAt:s,state:()=>c.state,on:XC(c),add:async()=>{let e=m();if(c.state.kind!==`joined`||e===null)return!1;let n=ZC(),a=JSON.stringify(ib({nonce:i,profile:t.profile,inbox:t.inbox},{roomId:r.id,fromMemberId:r.self.id,toMemberId:e.memberId,id:n},{signSeed:t.keys.signSeed,dhSeed:t.keys.dhSeed,theirDhKey:e.dhKey}));try{await r.send(a)}catch{return!1}return l.set(n,e.memberId),u=a,YC(c,{kind:`offered`,peer:e}),!0},saveAgain:_,close:()=>g({kind:`closed`})}}},nw=new Set([`bad-key`,`invalid`,`not-found`,`denied`,`blocked`,`closed`]),rw=(e,t,n,r)=>{let i=JC({kind:`joining`}),a=X(n.nonce),o=null,s=()=>{},c,l=null,u=null,d=!1,f=()=>`host`in i.state?i.state.host:null,p=()=>[`friends`,`closed`,`in-use`,`unavailable`].includes(i.state.kind),m=async e=>{p()||YC(i,e),!d&&(d=!0,clearTimeout(c),s(),await o?.leave().catch(()=>{}))},h=(n,o,s,u)=>{if(o!==n.owner)return;let d=QC(s);if(d?.t===`social.hello`&&f()===null){let a=ew(e,n,r,o,d,u,e=>{let t=i.state;`host`in t&&t.host?.memberId===e.memberId&&YC(i,{...t,host:e})});if(a===null)return;clearTimeout(c),YC(i,{kind:`waiting`,host:a}),n.send($C(n,t)).catch(()=>{})}else if(d?.t===`social.offer`){let e=f();if(e===null||i.state.kind!==`waiting`&&i.state.kind!==`offered`)return;let r=lb(d,{roomId:n.id,fromMemberId:o,selfMemberId:n.self.id},{dhSeed:t.keys.dhSeed,theirSignKey:e.signKey,theirDhKey:e.dhKey});if(!r.ok||a===null||!iw(r.body.nonce,a))return;l={id:r.id,nonce:r.body.nonce,profile:r.body.profile,inbox:r.body.inbox},YC(i,{kind:`offered`,host:e,profile:r.body.profile})}},g=async e=>{if(o!==null&&u!==null){try{await o.send(u)}catch{YC(i,{kind:`unsent`,host:e});return}await m({kind:`friends`,host:e})}};return(async()=>{let t;try{t=await e.rooms.join(`${n.key}.${n.roomId}`)}catch(e){let t=e?.code;YC(i,t===`full`?{kind:`in-use`}:nw.has(String(t))?{kind:`closed`}:{kind:`unavailable`});return}if(o=t,t.owner===t.self.id)return void m({kind:`closed`});if(d)return void t.leave().catch(()=>{});s=await t.on(e=>{e.type===`left`&&e.id===t.owner&&m({kind:`closed`}),e.type===`message`&&h(t,e.message.from,e.message.text,e.message.at)}),t.closed.then(()=>void m({kind:`closed`})),YC(i,{kind:`waiting`,host:null}),c=setTimeout(()=>{f()===null&&m({kind:`closed`})},KC),await t.send(JSON.stringify(qC)).catch(()=>{})})(),{state:()=>i.state,on:XC(i),accept:async()=>{let n=i.state;if(n.kind!==`offered`&&n.kind!==`failed`||l===null||o===null)return;let r=n.host;YC(i,{kind:`accepting`,host:r,profile:l.profile});let a=await fp(e,{signKey:r.signKey,dhKey:r.dhKey,name:r.name,profile:l.profile,pairNonce:l.nonce,linkedVia:`invite`,inbox:l.inbox},Date.now());if(!a.ok){YC(i,{kind:`failed`,host:r,profile:l.profile,reason:a.reason});return}u=JSON.stringify(ab({offerId:l.id,profile:t.profile,inbox:t.inbox},{roomId:o.id,fromMemberId:o.self.id,toMemberId:r.memberId,id:ZC()},{signSeed:t.keys.signSeed,dhSeed:t.keys.dhSeed,theirDhKey:r.dhKey})),await g(r)},sendAgain:async()=>{let e=f();i.state.kind===`unsent`&&e!==null&&await g(e)},decline:()=>m({kind:`closed`})}},iw=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),aw={started:`start`,watched:`watch`,completed:`finish`,rated:`rate`},ow=e=>oh.filter(t=>e.includes(t)),sw=(e,t)=>{let n=ow(t).map(e=>aw[e]);if(n.length===0)return`${hh(e)} asks to post to your page.`;let r=n.length===1?n[0]:`${n.slice(0,-1).join(`, `)} or ${n.at(-1)}`;return`${hh(e)} asks to post when you ${r} something.`},cw=()=>{let[e,t]=q(!1),[n,r]=q(null);return{busy:e,problem:n,run:async n=>{if(e)return!1;t(!0),r(null);let i=await n();return t(!1),r(i),i===null}}},lw=({asks:e,actions:t,onAnswered:n})=>{let{busy:r,problem:i,run:a}=cw(),o=async(e,r)=>{await a(()=>t.change(e,r))&&n?.()};return e.length===0?null:Z(`div`,{className:`social-stack`,"data-social-asks":!0,children:[e.map(({app:e,grant:t})=>Z(`div`,{className:`social-invite`,"data-social-ask":e,children:[Z(`p`,{children:sw(e,t.kinds)}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-social-allow":!0,"aria-disabled":r,onClick:()=>void o(e,{state:`allowed`,kinds:ow(t.kinds)}),children:`Allow`}),Z(`button`,{type:`button`,"data-social-not-now":!0,"aria-disabled":r,onClick:()=>void o(e,{state:`stopped`}),children:`Not now`})]})]},e)),Z(Qm,{children:i})]})},uw=[{level:`public`,label:`Public`},{level:`friends`,label:`Friends`}],dw=({app:e,grant:t,actions:n})=>{let{busy:r,problem:i,run:a}=cw(),[o,s]=q(!1),c=J(null),l=hh(e),u=t=>void a(()=>n.change(e,t)),d=e=>oh.filter(n=>n===e?!t.kinds.includes(n):t.kinds.includes(n)),f=()=>{s(!1),c.current?.focus()},p=async()=>{await a(()=>n.remove(e))&&f()};return Z(`li`,{className:`social-section`,"data-social-app":e,"data-social-app-state":t.state,children:[Z(`span`,{className:`social-choice-label`,children:l}),Z(`div`,{className:`social-stack`,children:[Z(`span`,{className:`social-label`,children:`What it posts`}),Z(`div`,{className:`social-checks`,role:`group`,"aria-label":`What it posts`,children:oh.map(e=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`checkbox`,value:e,checked:t.kinds.includes(e),"aria-disabled":r,onChange:()=>u({kinds:d(e)})}),Z(`span`,{className:`social-choice-label`,children:ah[e]})]},e))})]}),Z(`div`,{className:`social-stack`,children:[Z(`span`,{className:`social-label`,children:`Who sees its posts`}),Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`Who sees its posts`,children:uw.map(({level:n,label:i})=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`app-level-${e}`,value:n,checked:t.level===n,"aria-disabled":r,onChange:()=>u({level:n})}),Z(`span`,{className:`social-choice-label`,children:i})]},n))})]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,"data-social-app-switch":!0,"aria-disabled":r,onClick:()=>u(t.state===`allowed`?{state:`stopped`}:{state:`allowed`,kinds:ow(t.kinds)}),children:t.state===`allowed`?`Stop`:`Allow`}),Z(`button`,{type:`button`,"data-social-app-delete":!0,ref:c,"aria-disabled":r,onClick:()=>{r||s(!0)},children:`Delete everything it posted`})]}),o&&Z(`div`,{className:`social-warn`,"data-social-delete-app":!0,children:[Z(`p`,{children:[`Delete everything `,l,` posted?`]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,"data-social-delete-confirm":!0,ref:Zm,"aria-disabled":r,onClick:()=>void p(),children:`Delete`}),Z(`button`,{type:`button`,"aria-disabled":r,onClick:()=>{r||f()},children:`Cancel`})]})]}),Z(Qm,{children:i})]})},fw=({apps:e,actions:t})=>Z(`ul`,{className:`social-list`,"data-social-apps":!0,children:e.map(({app:e,grant:n})=>Z(dw,{app:e,grant:n,actions:t},e))}),pw=e=>t=>{t.key===`Enter`&&e()},mw=({name:e,label:t,placeholder:n,value:r,onChange:i,onSubmit:a})=>{let o=rf(r);return Z(K,{children:[Z(`input`,{name:e,"aria-label":t,autoComplete:`off`,autoCapitalize:`none`,spellcheck:!1,maxLength:40,placeholder:n,value:r,onChange:e=>i(e.currentTarget.value),onKeyDown:pw(a)}),!o.ok&&o.reason!==`empty`&&Z(`p`,{className:`social-muted`,children:Um(o.reason)})]})},hw=({label:e,onPick:t})=>{let[n,r]=q(``),[i,a]=q(!1),[o,s]=q(null),c=rf(n),l=async()=>{if(!c.ok||i)return;a(!0),s(null);let e=await t(c.name);a(!1),e.ok||s(e.reason)};return Z(`div`,{children:[Z(mw,{name:`name`,label:`Name`,placeholder:`your name`,value:n,onChange:e=>{r(e),s(null)},onSubmit:()=>void l()}),c.ok&&c.name!==n&&Z(`p`,{className:`social-muted`,children:[`Saved as `,c.name]}),Z(Hm,{reason:o}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-submit":!0,className:`social-primary`,"aria-disabled":!c.ok||i,onClick:()=>void l(),children:i?`Claiming...`:e})})]})},gw=({onRestore:e})=>{let[t,n]=q(``),[r,i]=q(!1),[a,o]=q(null),s=async()=>{if(r||t.trim()===``)return;i(!0),o(null);let n=await e(t);i(!1),n.ok||o(n.reason)};return Z(`div`,{children:[Z(`input`,{name:`recovery-key`,"aria-label":`Recovery key`,autoComplete:`off`,spellcheck:!1,placeholder:`FKNS-...`,value:t,onChange:e=>{n(e.currentTarget.value),o(null)},onKeyDown:pw(()=>void s())}),Z(Hm,{reason:a}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-submit":!0,"aria-disabled":t.trim()===``||r,onClick:()=>void s(),children:r?`Restoring...`:`Restore`})})]})},_w=({identity:e,fresh:t})=>{let[n,r]=q(t),i=eC(e.seed);return Z(K,{children:[Z(`h2`,{children:t?`Save your recovery key`:`Recovery key`}),Z(`p`,{className:`social-muted`,children:`Keep it somewhere private: anyone holding it can act as you.`}),n&&Z(`code`,{className:`social-key`,"data-recovery-key":!0,children:i}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,onClick:()=>r(!n),children:n?`Hide`:`Show recovery key`}),n&&Z(rh,{text:i})]})]})},vw={lost:`Your account no longer holds this name.`,unrecorded:`Your name's record is missing. Check that Messages kept is on for it under Rooms in your FKN settings, then write it again.`,taken:`Someone else holds this name now.`,retired:`Names like this one are no longer given out.`},yw={lost:`Claim it again`,unrecorded:`Write it again`},bw=({status:e,onClaimAgain:t,onRename:n})=>{let[r,i]=q(!1),[a,o]=q(null),s=vw[e];if(s===void 0)return null;let c=async()=>{if(r)return;i(!0);let e=await t();i(!1),o(e.ok?null:e.reason)},l=yw[e];return Z(`div`,{className:`social-warn`,role:`status`,children:[Z(`p`,{children:s}),Z(Hm,{reason:a}),Z(`div`,{className:`social-row`,children:[l!==void 0&&Z(`button`,{type:`button`,className:`social-primary`,"aria-disabled":r,onClick:()=>void c(),children:r?`Claiming...`:l}),Z(`button`,{type:`button`,onClick:n,children:`Pick another name`})]})]})},xw=({name:e,onGiveBack:t})=>{let[n,r]=q(!1),[i,a]=q(null),o=async()=>{if(n)return;r(!0);let e=await t();r(!1),a(e.ok?null:e.reason)};return Z(`div`,{className:`social-warn`,role:`status`,"data-social-kept":e,children:[Z(`p`,{children:[`Your FKN account still holds `,e,`.`]}),Z(Hm,{reason:i}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"aria-disabled":n,onClick:()=>void o(),children:n?`Giving back...`:`Give it back`})})]})},Sw=({identity:e,fresh:t,status:n,actions:r,avatar:i=null,avatarUrl:a,openRename:o=!1,onRenameOpened:s})=>{let[c,l]=q(!1),[u,d]=q(null),f=sv(e.seed);hu(()=>{o&&(l(!0),s?.())},[o,s]);let p=async e=>{let t=await r.rename(e);return t.ok&&l(!1),(t.ok||t.kept!==void 0)&&d(t.kept??null),t},m=async e=>{let t=await r.giveBack(e);return t.ok&&d(null),t};return Z(K,{children:[Z(`div`,{className:`social-card`,"data-social-claim":n,children:[Z(th,{signKey:f.signKey,src:i,url:a,avatarAlt:`${e.name}'s avatar`}),Z(`div`,{children:[Z(`div`,{className:`social-name`,"data-social-name":!0,style:Xm(e.name),children:e.name}),Z(`div`,{className:`social-muted`,children:`Your name on FKN Social`})]})]}),Z(bw,{status:n,onClaimAgain:r.claimAgain,onRename:()=>l(!0)}),u!==null&&Z(xw,{name:u,onGiveBack:()=>m(u)}),c?Z(K,{children:[Z(`h2`,{children:`Change your name`}),Z(`p`,{className:`social-muted`,children:[e.name,` is given back.`]}),Z(hw,{label:`Change name`,onPick:p}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:()=>l(!1),children:`Cancel`})})]}):Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:()=>l(!0),children:`Change name`})}),Z(_w,{identity:e,fresh:t})]})},Cw=`FKN rooms did not answer. Try again in a moment.`,ww=(e,t)=>({closed:`${t} is not taking friend requests.`,full:`${t}'s inbox is full. Try again later.`,busy:Cw,unavailable:Cw})[e],Tw=(e,t)=>({...Wm,self:`This is you.`,"no-inbox":`You need an inbox to send friend requests.`,closed:ww(`closed`,t),full:ww(`full`,t),busy:Cw,unavailable:Cw})[e],Ew={none:`You have no inbox.`,"out-of-claims":`No inbox: your FKN account holds as many claimed rooms as it can. Unclaim one under Rooms in your FKN settings.`,taken:`Someone else holds your inbox now.`,"not-kept":`Your inbox keeps no messages. Turn on Messages kept for it under Rooms in your FKN settings.`,unavailable:Cw},Dw={...Wm,"out-of-claims":Ew[`out-of-claims`],busy:Cw,unavailable:Cw},Ow=[`none`,`out-of-claims`,`taken`],kw=({onMake:e})=>{let[t,n]=q(!1),[r,i]=q(null),a=async()=>{if(t)return;n(!0);let r=await e();n(!1),i(r.ok?null:Dw[r.reason])};return Z(K,{children:[Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-make-inbox":!0,"aria-disabled":t,onClick:()=>void a(),children:t?`Making an inbox...`:`Make an inbox`})}),r!==null&&Z(`p`,{className:`social-error`,role:`alert`,children:r})]})},Aw=({status:e,onMake:t})=>e===`ready`?null:Z(`div`,{className:`social-stack`,"data-social-inbox-line":e,children:[Z(`p`,{className:`social-warn-text`,children:Ew[e]}),Ow.includes(e)&&Z(kw,{onMake:t})]}),jw=e=>{try{return new URL(e).host}catch{return e}},Mw=({signKey:e,name:t,displayName:n=``})=>Z(`div`,{className:`social-card`,children:[Z($m,{signKey:e,label:`${t}'s identicon`,small:!0}),Z(`div`,{children:[Z(`div`,{className:`social-person-name`,children:n||t}),n!==``&&n!==t&&Z(`div`,{className:`social-muted`,children:t})]})]}),Nw=({waiting:e,actions:t})=>{let[n,r]=q(!1),[i,a]=q(null),[o,s]=q(!1),{sender:c,request:l}=e,u=async i=>{if(n)return;r(!0);let o=await t.answer(e,i);r(!1),s(!o.ok&&o.reason===`unsent`),a(o.ok||o.reason===`unsent`?null:Wm[o.reason])};return Z(`div`,{className:`social-invite`,"data-social-request":c.name,"data-social-confirmed":String(c.confirmed),children:[Z(`p`,{children:[c.name,` sent you a friend request.`]}),Z(Mw,{signKey:c.signKey,name:c.name,displayName:l.p.displayName}),c.confirmed===!1&&Z(`p`,{className:`social-warn-text`,children:`Their name room does not confirm this name.`}),e.friend&&Z(`p`,{className:`social-muted`,children:`Already in your list.`}),o&&Z(`p`,{className:`social-error`,role:`alert`,children:[`Your answer did not reach `,c.name,`.`]}),i!==null&&Z(`p`,{className:`social-error`,role:`alert`,children:i}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-accept-request":!0,"aria-disabled":n,onClick:()=>void u(!0),children:o?`Send again`:`Accept`}),!o&&Z(`button`,{type:`button`,"data-decline-request":!0,"aria-disabled":n,onClick:()=>void u(!1),children:`Decline`})]})]})},Pw=({waiting:e,site:t,actions:n})=>{let[r,i]=q(!1),a=t(),o=async()=>{a!==null&&await a.open(e.url).catch(()=>i(!0))};return Z(`div`,{className:`social-invite`,"data-social-party":e.sender.name,children:[Z(`p`,{children:[e.sender.name,` invited you to a party at `,jw(e.url),`.`]}),Z(Mw,{signKey:e.sender.signKey,name:e.sender.name}),Z(`div`,{className:`social-row`,children:[a!==null&&Z(`button`,{type:`button`,className:`social-primary`,"data-open-party":!0,onClick:()=>void o(),children:`Open`}),Z(rh,{text:e.url}),Z(`button`,{type:`button`,"data-dismiss-party":!0,onClick:()=>void n.dismiss(e),children:`Dismiss`})]}),r&&Z(`p`,{className:`social-muted`,children:`It did not open. Copy it instead.`})]})},Fw=({waiting:e,actions:t})=>{let[n,r]=q(!1),[i,a]=q(!1),o=async()=>{if(n)return;r(!0);let i=await t.approve(e);r(!1),a(!i)};return Z(`div`,{className:`social-invite`,"data-social-comment":e.sender.name,children:[Z(`p`,{children:[e.sender.name,` commented on your page.`]}),Z(Mw,{signKey:e.sender.signKey,name:e.sender.name}),Z(`p`,{className:`social-bio`,"data-social-comment-text":!0,children:e.text}),i&&Z(`p`,{className:`social-error`,role:`alert`,children:`FKN rooms did not answer, so nothing changed. Try again in a moment.`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-approve-comment":!0,"aria-disabled":n,onClick:()=>void o(),children:`Approve`}),Z(`button`,{type:`button`,"data-delete-comment":!0,"aria-disabled":n,onClick:()=>{n||t.dismiss(e)},children:`Delete`})]})]})},Iw=({status:e,waiting:t,accepted:n,site:r,actions:i,onMake:a})=>Z(`div`,{className:`social-stack`,"data-social-inbox-status":e??`loading`,children:[n.map(e=>Z(`p`,{"data-social-accepted":e,children:[e,` accepted your friend request.`]},e)),t.map(e=>e.kind===`friend`?Z(Nw,{waiting:e,actions:i},e.seq):e.kind===`comment`?Z(Fw,{waiting:e,actions:i},e.seq):Z(Pw,{waiting:e,site:r,actions:i},e.seq)),e!==null&&Z(Aw,{status:e,onMake:a})]}),Lw=(e,t)=>({unheld:`Nobody holds the name ${t} on FKN Social right now.`,none:`${t}'s page shows nothing right now. Try again in a moment.`,busy:Cw,unavailable:Cw,malformed:`This link is incomplete. Ask for the link again.`})[e.kind],Rw=({onAdd:e})=>{let[t,n]=q(``),r=rf(t),i=()=>{r.ok&&(e(r.name),n(``))};return Z(`div`,{"data-social-add-by-name":!0,children:[Z(mw,{name:`friend-name`,label:`Friend's name`,placeholder:`their name`,value:t,onChange:n,onSubmit:i}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-add-by-name":!0,"aria-disabled":!r.ok,onClick:i,children:`Request friend`})})]})},zw=({name:e,own:t,isFriend:n,read:r,send:i,onMake:a,onClose:o})=>{let[s,c]=q(e===null?{kind:`malformed`}:null),[l,u]=q(!1),[d,f]=q(null),p=J(null);hu(()=>{let e=document.activeElement;return p.current?.focus(),()=>{e instanceof HTMLElement&&e!==document.body&&e.isConnected&&(document.activeElement===document.body||p.current?.contains(document.activeElement))&&e.focus()}},[]),hu(()=>{if(e===null)return;let t=!0;return r(e).then(e=>{t&&c(e)}),()=>{t=!1}},[e,r]);let m=e??``,h=s?.kind===`shown`&&e!==null?{name:e,signKey:s.signKey,inbox:s.inbox}:null,g=h===null?null:Im(h.signKey,t)?{ok:!1,reason:`self`}:h.inbox===null?{ok:!1,reason:`closed`}:null,_=d??g,v=g===null?h:null,y=_===null?s===null?`loading`:s.kind===`shown`?`ready`:s.kind:_.ok?`sent`:_.reason,b=async()=>{v===null||l||(u(!0),f(await i(v)),u(!1))};return Z(`div`,{ref:p,tabIndex:-1,className:`social-invite`,"data-social-send-request":y,children:[Z(`h2`,{children:e===null?`Add a friend`:`Add ${m} as a friend`}),s===null&&Z(`div`,{className:`social-inline-loader`,children:[Z(`span`,{className:`social-loader-track social-loader-track-sm`,"aria-hidden":`true`,children:Z(`span`,{className:`social-loader-bar`})}),Z(`span`,{className:`social-muted`,children:`Loading...`})]}),s!==null&&s.kind!==`shown`&&Z(`p`,{children:Lw(s,m)}),s?.kind===`shown`&&Z(Mw,{signKey:s.signKey,name:m,displayName:s.profile?.displayName??s.displayName}),v!==null&&n(v.signKey)&&Z(`p`,{className:`social-muted`,children:`Already in your list.`}),_?.ok===!0&&Z(`p`,{role:`status`,children:`Sent.`}),_?.ok===!1&&Z(`p`,{className:`social-error`,role:`alert`,children:Tw(_.reason,m)}),_?.ok===!1&&_.reason===`no-inbox`&&Z(kw,{onMake:async()=>{let e=await a();return e.ok&&f(null),e}}),Z(`div`,{className:`social-row`,children:[v!==null&&_?.ok!==!0&&Z(`button`,{type:`button`,className:`social-primary`,"data-send-request":!0,"aria-disabled":l,onClick:()=>void b(),children:l?`Sending...`:`Send friend request`}),Z(`button`,{type:`button`,"data-close-request":!0,onClick:o,children:`Close`})]})]})},Bw=e=>X(e.signKey)??new Uint8Array(32),Vw=e=>e.nickname??(e.profile.displayName||e.name),Hw=({friends:e,onOpen:t,focusRef:n})=>e.length===0?Z(`p`,{className:`social-muted`,"data-social-friends":`0`,children:`No friends yet.`}):Z(`ul`,{className:`social-list`,"data-social-friends":e.length,children:e.map(e=>Z(`li`,{children:Z(`button`,{type:`button`,className:`social-person`,"data-social-friend":e.name,ref:n?.(e.fingerprint),onClick:()=>t(e.fingerprint),children:[Z($m,{signKey:Bw(e),label:`${e.name}'s identicon`,small:!0}),Z(`span`,{children:[Z(`span`,{className:`social-person-name`,children:Vw(e)}),Vw(e)!==e.name&&Z(`span`,{className:`social-muted`,children:[` `,e.name]})]})]})},e.fingerprint))}),Uw={invite:`Met through an invite link.`,party:`Met in a party.`,request:`Met through a friend request.`},Ww=(e,t)=>e.ok?`Sent.`:e.reason===`link`?`A party link starts with https:// and has at most ${pb.toLocaleString(`en`)} characters.`:e.reason===`no-inbox`?`${t} has no inbox.`:e.reason===`closed`?`${t} cannot take party invites right now.`:ww(e.reason,t),Gw=({name:e,onInvite:t})=>{let[n,r]=q(``),[i,a]=q(!1),[o,s]=q(null),c=async()=>{if(i||n.trim()===``)return;a(!0);let e=await t(n);a(!1),s(e),e.ok&&r(``)};return Z(`div`,{className:`social-stack`,"data-social-party-invite":!0,children:[Z(`label`,{className:`social-label`,children:[`Party link`,Z(`input`,{name:`party-link`,autoComplete:`off`,inputMode:`url`,value:n,onChange:e=>{r(e.currentTarget.value),s(null)},onKeyDown:e=>{e.key===`Enter`&&c()}})]}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-send-party":!0,"aria-disabled":i||n.trim()===``,onClick:()=>void c(),children:i?`Sending...`:`Send invite`})}),o!==null&&Z(`p`,{className:o.ok?`social-muted`:`social-error`,role:o.ok?`status`:`alert`,children:Ww(o,e)})]})},Kw=({friend:e,site:t,onNickname:n,onRemove:r,onBack:i,onInvite:a})=>{let[o,s]=q(e.nickname??``),[c,l]=q(!1),[u,d]=q(!1),[f,p]=q(null),m=async e=>{if(u)return;d(!0);let t=await e();d(!1),p(t.ok?null:Wm[t.reason])},h=o.trim(),g=h===(e.nickname??``);return Z(`div`,{className:`social-stack`,"data-social-friend-view":e.name,children:[Z(`div`,{className:`social-card`,children:[Z($m,{signKey:Bw(e),label:`${e.name}'s identicon`}),Z(`div`,{children:[Z(`div`,{className:`social-name`,tabIndex:-1,ref:Zm,style:Xm(Vw(e)),children:Vw(e)}),Vw(e)!==e.name&&Z(`div`,{className:`social-muted`,children:e.name})]})]}),e.profile.displayName!==``&&e.nickname!==null&&Z(`p`,{children:e.profile.displayName}),e.profile.bio!==``&&Z(`p`,{className:`social-bio`,"data-social-bio":!0,children:e.profile.bio}),e.profile.links.map(e=>Z(ih,{url:e,site:t},e)),Z(`p`,{className:`social-muted`,children:[`Friends since `,new Date(e.linkedAt).toLocaleDateString(`en`,{year:`numeric`,month:`long`,day:`numeric`}),`.`,` `,Uw[e.linkedVia]]}),a!==void 0&&ey(e.inbox)!==null&&Z(K,{children:[Z(`h2`,{children:`Invite to a party`}),Z(Gw,{name:e.name,onInvite:a})]}),Z(`label`,{className:`social-label`,children:[`Nickname, only for you`,Z(`input`,{name:`nickname`,autoComplete:`off`,maxLength:64,value:o,onChange:e=>s(e.currentTarget.value)})]}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"aria-disabled":u||g,onClick:()=>{g||m(()=>n(h===``?null:h))},children:`Save nickname`})}),Z(Qm,{children:f}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,onClick:i,children:`Back to friends`}),c?Z(`button`,{type:`button`,className:`social-danger`,"aria-disabled":u,onClick:()=>void m(r),children:[`Remove `,e.name]}):Z(`button`,{type:`button`,onClick:()=>l(!0),children:`Remove`})]})]})},qw=(e=>(e[e.Border=-1]=`Border`,e[e.Data=0]=`Data`,e[e.Function=1]=`Function`,e[e.Position=2]=`Position`,e[e.Timing=3]=`Timing`,e[e.Alignment=4]=`Alignment`,e))(qw||{}),Jw=[0,1],Yw=[1,0],Xw=[2,3],Zw=[3,2],Qw={L:Jw,M:Yw,Q:Xw,H:Zw},$w=/^\d*$/,eT=/^[A-Z0-9 $%*+./:-]*$/,tT=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`,nT=1,rT=40,iT=3,aT=3,oT=40,sT=10,cT=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],lT=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],uT=class{constructor(e,t,n,r){if(this.version=e,this.ecc=t,e<nT||e>rT)throw RangeError(`Version value out of range`);if(r<-1||r>7)throw RangeError(`Mask value out of range`);this.size=e*4+17;let i=Array.from({length:this.size}).fill(!1);for(let e=0;e<this.size;e++)this.modules.push(i.slice()),this.types.push(i.map(()=>0));this.drawFunctionPatterns();let a=this.addEccAndInterleave(n);if(this.drawCodewords(a),r===-1){let e=1e9;for(let t=0;t<8;t++){this.applyMask(t),this.drawFormatBits(t);let n=this.getPenaltyScore();n<e&&(r=t,e=n),this.applyMask(t)}}this.mask=r,this.applyMask(r),this.drawFormatBits(r)}size;mask;modules=[];types=[];getModule(e,t){return e>=0&&e<this.size&&t>=0&&t<this.size&&this.modules[t][e]}drawFunctionPatterns(){for(let e=0;e<this.size;e++)this.setFunctionModule(6,e,e%2==0,qw.Timing),this.setFunctionModule(e,6,e%2==0,qw.Timing);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);let e=this.getAlignmentPatternPositions(),t=e.length;for(let n=0;n<t;n++)for(let r=0;r<t;r++)n===0&&r===0||n===0&&r===t-1||n===t-1&&r===0||this.drawAlignmentPattern(e[n],e[r]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(e){let t=this.ecc[1]<<3|e,n=t;for(let e=0;e<10;e++)n=n<<1^(n>>>9)*1335;let r=(t<<10|n)^21522;for(let e=0;e<=5;e++)this.setFunctionModule(8,e,fT(r,e));this.setFunctionModule(8,7,fT(r,6)),this.setFunctionModule(8,8,fT(r,7)),this.setFunctionModule(7,8,fT(r,8));for(let e=9;e<15;e++)this.setFunctionModule(14-e,8,fT(r,e));for(let e=0;e<8;e++)this.setFunctionModule(this.size-1-e,8,fT(r,e));for(let e=8;e<15;e++)this.setFunctionModule(8,this.size-15+e,fT(r,e));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let e=this.version;for(let t=0;t<12;t++)e=e<<1^(e>>>11)*7973;let t=this.version<<12|e;for(let e=0;e<18;e++){let n=fT(t,e),r=this.size-11+e%3,i=Math.floor(e/3);this.setFunctionModule(r,i,n),this.setFunctionModule(i,r,n)}}drawFinderPattern(e,t){for(let n=-4;n<=4;n++)for(let r=-4;r<=4;r++){let i=Math.max(Math.abs(r),Math.abs(n)),a=e+r,o=t+n;a>=0&&a<this.size&&o>=0&&o<this.size&&this.setFunctionModule(a,o,i!==2&&i!==4,qw.Position)}}drawAlignmentPattern(e,t){for(let n=-2;n<=2;n++)for(let r=-2;r<=2;r++)this.setFunctionModule(e+r,t+n,Math.max(Math.abs(r),Math.abs(n))!==1,qw.Alignment)}setFunctionModule(e,t,n,r=qw.Function){this.modules[t][e]=n,this.types[t][e]=r}addEccAndInterleave(e){let t=this.version,n=this.ecc;if(e.length!==DT(t,n))throw RangeError(`Invalid argument`);let r=lT[n[0]][t],i=cT[n[0]][t],a=Math.floor(ET(t)/8),o=r-a%r,s=Math.floor(a/r),c=[],l=OT(i);for(let t=0,n=0;t<r;t++){let r=e.slice(n,n+s-i+(t<o?0:1));n+=r.length;let a=kT(r,l);t<o&&r.push(0),c.push(r.concat(a))}let u=[];for(let e=0;e<c[0].length;e++)c.forEach((t,n)=>{(e!==s-i||n>=o)&&u.push(t[e])});return u}drawCodewords(e){if(e.length!==Math.floor(ET(this.version)/8))throw RangeError(`Invalid argument`);let t=0;for(let n=this.size-1;n>=1;n-=2){n===6&&(n=5);for(let r=0;r<this.size;r++)for(let i=0;i<2;i++){let a=n-i,o=n+1&2?r:this.size-1-r;!this.types[o][a]&&t<e.length*8&&(this.modules[o][a]=fT(e[t>>>3],7-(t&7)),t++)}}}applyMask(e){if(e<0||e>7)throw RangeError(`Mask value out of range`);for(let t=0;t<this.size;t++)for(let n=0;n<this.size;n++){let r;switch(e){case 0:r=(n+t)%2==0;break;case 1:r=t%2==0;break;case 2:r=n%3==0;break;case 3:r=(n+t)%3==0;break;case 4:r=(Math.floor(n/3)+Math.floor(t/2))%2==0;break;case 5:r=n*t%2+n*t%3==0;break;case 6:r=(n*t%2+n*t%3)%2==0;break;case 7:r=((n+t)%2+n*t%3)%2==0;break;default:throw Error(`Unreachable`)}!this.types[t][n]&&r&&(this.modules[t][n]=!this.modules[t][n])}}getPenaltyScore(){let e=0;for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[t][a]===n?(r++,r===5?e+=iT:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*oT),n=this.modules[t][a],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*oT}for(let t=0;t<this.size;t++){let n=!1,r=0,i=[0,0,0,0,0,0,0];for(let a=0;a<this.size;a++)this.modules[a][t]===n?(r++,r===5?e+=iT:r>5&&e++):(this.finderPenaltyAddHistory(r,i),n||(e+=this.finderPenaltyCountPatterns(i)*oT),n=this.modules[a][t],r=1);e+=this.finderPenaltyTerminateAndCount(n,r,i)*oT}for(let t=0;t<this.size-1;t++)for(let n=0;n<this.size-1;n++){let r=this.modules[t][n];r===this.modules[t][n+1]&&r===this.modules[t+1][n]&&r===this.modules[t+1][n+1]&&(e+=aT)}let t=0;for(let e of this.modules)t=e.reduce((e,t)=>e+ +!!t,t);let n=this.size*this.size,r=Math.ceil(Math.abs(t*20-n*10)/n)-1;return e+=r*sT,e}getAlignmentPatternPositions(){if(this.version===1)return[];{let e=Math.floor(this.version/7)+2,t=this.version===32?26:Math.ceil((this.version*4+4)/(e*2-2))*2,n=[6];for(let r=this.size-7;n.length<e;r-=t)n.splice(1,0,r);return n}}finderPenaltyCountPatterns(e){let t=e[1],n=t>0&&e[2]===t&&e[3]===t*3&&e[4]===t&&e[5]===t;return(n&&e[0]>=t*4&&e[6]>=t?1:0)+(n&&e[6]>=t*4&&e[0]>=t?1:0)}finderPenaltyTerminateAndCount(e,t,n){return e&&(this.finderPenaltyAddHistory(t,n),t=0),t+=this.size,this.finderPenaltyAddHistory(t,n),this.finderPenaltyCountPatterns(n)}finderPenaltyAddHistory(e,t){t[0]===0&&(e+=this.size),t.pop(),t.unshift(e)}};function dT(e,t,n){if(t<0||t>31||e>>>t)throw RangeError(`Value out of range`);for(let r=t-1;r>=0;r--)n.push(e>>>r&1)}function fT(e,t){return!!(e>>>t&1)}var pT=class{constructor(e,t,n){if(this.mode=e,this.numChars=t,this.bitData=n,t<0)throw RangeError(`Invalid argument`);this.bitData=n.slice()}getData(){return this.bitData.slice()}},mT=[1,10,12,14],hT=[2,9,11,13],gT=[4,8,16,16];function _T(e,t){return e[Math.floor((t+7)/17)+1]}function vT(e){let t=[];for(let n of e)dT(n,8,t);return new pT(gT,e.length,t)}function yT(e){if(!ST(e))throw RangeError(`String contains non-numeric characters`);let t=[];for(let n=0;n<e.length;){let r=Math.min(e.length-n,3);dT(Number.parseInt(e.substring(n,n+r),10),r*3+1,t),n+=r}return new pT(mT,e.length,t)}function bT(e){if(!CT(e))throw RangeError(`String contains unencodable characters in alphanumeric mode`);let t=[],n=0;for(;n+2<=e.length;n+=2){let r=tT.indexOf(e.charAt(n))*45;r+=tT.indexOf(e.charAt(n+1)),dT(r,11,t)}return n<e.length&&dT(tT.indexOf(e.charAt(n)),6,t),new pT(hT,e.length,t)}function xT(e){return e===``?[]:ST(e)?[yT(e)]:CT(e)?[bT(e)]:[vT(TT(e))]}function ST(e){return $w.test(e)}function CT(e){return eT.test(e)}function wT(e,t){let n=0;for(let r of e){let e=_T(r.mode,t);if(r.numChars>=1<<e)return 1/0;n+=4+e+r.bitData.length}return n}function TT(e){e=encodeURI(e);let t=[];for(let n=0;n<e.length;n++)e.charAt(n)===`%`?(t.push(Number.parseInt(e.substring(n+1,n+3),16)),n+=2):t.push(e.charCodeAt(n));return t}function ET(e){if(e<nT||e>rT)throw RangeError(`Version number out of range`);let t=(16*e+128)*e+64;if(e>=2){let n=Math.floor(e/7)+2;t-=(25*n-10)*n-55,e>=7&&(t-=36)}return t}function DT(e,t){return Math.floor(ET(e)/8)-cT[t[0]][e]*lT[t[0]][e]}function OT(e){if(e<1||e>255)throw RangeError(`Degree out of range`);let t=[];for(let n=0;n<e-1;n++)t.push(0);t.push(1);let n=1;for(let r=0;r<e;r++){for(let e=0;e<t.length;e++)t[e]=AT(t[e],n),e+1<t.length&&(t[e]^=t[e+1]);n=AT(n,2)}return t}function kT(e,t){let n=t.map(e=>0);for(let r of e){let e=r^n.shift();n.push(0),t.forEach((t,r)=>n[r]^=AT(t,e))}return n}function AT(e,t){if(e>>>8||t>>>8)throw RangeError(`Byte out of range`);let n=0;for(let r=7;r>=0;r--)n=n<<1^(n>>>7)*285,n^=(t>>>r&1)*e;return n}function jT(e,t,n=1,r=40,i=-1,a=!0){if(!(nT<=n&&n<=r&&r<=rT)||i<-1||i>7)throw RangeError(`Invalid value`);let o,s;for(o=n;;o++){let n=DT(o,t)*8,i=wT(e,o);if(i<=n){s=i;break}if(o>=r)throw RangeError(`Data too long`)}for(let e of[Yw,Xw,Zw])a&&s<=DT(o,e)*8&&(t=e);let c=[];for(let t of e){dT(t.mode[0],4,c),dT(t.numChars,_T(t.mode,o),c);for(let e of t.getData())c.push(e)}let l=DT(o,t)*8;dT(0,Math.min(4,l-c.length),c),dT(0,(8-c.length%8)%8,c);for(let e=236;c.length<l;e^=253)dT(e,8,c);let u=Array.from({length:Math.ceil(c.length/8)},()=>0);return c.forEach((e,t)=>u[t>>>3]|=e<<7-(t&7)),new uT(o,t,u,i)}function MT(e,t){let{ecc:n=`L`,boostEcc:r=!1,minVersion:i=1,maxVersion:a=40,maskPattern:o=-1,border:s=1}=t||{},c=typeof e==`string`?xT(e):Array.isArray(e)?[vT(e)]:void 0;if(!c)throw Error(`uqr only supports encoding string and binary data, but got: ${typeof e}`);let l=jT(c,Qw[n],i,a,o,r),u=NT({version:l.version,maskPattern:l.mask,size:l.size,data:l.modules,types:l.types},s);return t?.invert&&(u.data=u.data.map(e=>e.map(e=>!e))),t?.onEncoded?.(u),u}function NT(e,t=1){if(!t)return e;let{size:n}=e,r=n+t*2;e.size=r,e.data.forEach(e=>{for(let n=0;n<t;n++)e.unshift(!1),e.push(!1)});for(let n=0;n<t;n++)e.data.unshift(Array.from({length:r},e=>!1)),e.data.push(Array.from({length:r},e=>!1));let i=qw.Border;e.types.forEach(e=>{for(let n=0;n<t;n++)e.unshift(i),e.push(i)});for(let n=0;n<t;n++)e.types.unshift(Array.from({length:r},e=>i)),e.types.push(Array.from({length:r},e=>i));return e}var PT=({text:e})=>{let{size:t,data:n}=MT(e,{ecc:`L`,border:2}),r=``;return n.forEach((e,t)=>e.forEach((e,n)=>{e&&(r+=`M${n} ${t}h1v1h-1z`)})),Z(`svg`,{className:`social-qr`,viewBox:`0 0 ${t} ${t}`,role:`img`,"aria-label":`QR code of the invite link`,shapeRendering:`crispEdges`,children:[Z(`rect`,{width:t,height:t,fill:`#fff`}),Z(`path`,{d:r,fill:`#000`})]})},FT=(e,t)=>{let n=Math.max(0,Math.ceil((e-t)/1e3));return`${Math.floor(n/60)}:${String(n%60).padStart(2,`0`)}`},IT=()=>{let[e,t]=q(()=>Date.now());return hu(()=>{let e=setInterval(()=>t(Date.now()),1e3);return()=>clearInterval(e)},[]),e},LT=({peer:e})=>Z(`div`,{className:`social-stack`,"data-social-peer":e.name,"data-social-confirmed":String(e.confirmed),children:[Z(`div`,{className:`social-card`,children:[Z($m,{signKey:e.signKey,label:`${e.name}'s identicon`,small:!0}),Z(`div`,{children:[Z(`div`,{className:`social-person-name`,children:e.displayName||e.name}),Z(`div`,{className:`social-muted`,children:e.name})]})]}),e.confirmed===!1&&Z(`p`,{className:`social-warn-text`,children:`This name could not be confirmed.`}),e.friend&&Z(`p`,{className:`social-muted`,children:`Already your friend.`})]}),RT=({profile:e,site:t})=>Z(K,{children:[e.bio!==``&&Z(`p`,{className:`social-bio`,children:e.bio}),e.links.map(e=>Z(ih,{url:e,site:t},e))]}),zT=({link:e,expiresAt:t,state:n,onAdd:r,onClose:i,onSaveAgain:a,onDismiss:o})=>{let s=IT(),[c,l]=q(!1),u=n.kind!==`friends`&&n.kind!==`closed`,d=n.kind===`joined`||n.kind===`offered`||n.kind===`unsaved`;return Z(`div`,{className:`social-invite`,"data-social-host":n.kind,children:[u&&!d&&Z(K,{children:[Z(`code`,{className:`social-key`,"data-invite-link":!0,children:e}),Z(`div`,{className:`social-row`,children:Z(rh,{text:e,label:`Copy link`})}),Z(PT,{text:e}),Z(`p`,{className:`social-muted`,children:[`This link works while this tab is open, for `,FT(t,s),` more.`]})]}),Z(`div`,{className:`social-stack`,role:`status`,children:[n.kind===`waiting`&&Z(`p`,{children:`Waiting for someone to open the link.`}),n.kind===`left`&&Z(`p`,{children:`They left. The link still works until it ends.`}),n.kind===`joined`&&Z(K,{children:[Z(`p`,{children:`Someone opened your link:`}),Z(LT,{peer:n.peer}),c&&Z(`p`,{className:`social-error`,role:`alert`,children:`The offer did not go out. Try again in a moment.`}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,"data-add":!0,onClick:()=>void r().then(e=>l(!e)),children:[`Add `,n.peer.name]})})]}),n.kind===`offered`&&Z(K,{children:[Z(LT,{peer:n.peer}),Z(`p`,{children:[`Waiting for `,n.peer.name,` to accept.`]})]}),n.kind===`unsaved`&&Z(K,{children:[Z(LT,{peer:n.peer}),Z(`p`,{className:`social-error`,role:`alert`,children:[n.peer.name,` accepted, but your friend list was not saved. `,Wm[n.reason]]}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,onClick:a,children:`Save again`})})]}),n.kind===`friends`&&Z(`p`,{"data-social-done":!0,children:[`You and `,n.peer.name,` are now friends.`]}),n.kind===`closed`&&Z(`p`,{children:`This invite has ended.`})]}),Z(`div`,{className:`social-row`,children:u?Z(`button`,{type:`button`,"data-close-invite":!0,onClick:i,children:`Close the invite`}):Z(`button`,{type:`button`,onClick:o,children:`Done`})})]})},BT=`This browser keeps no site data for FKN Social. Allow site data, then open the link again.`,VT=({state:e,site:t,onAccept:n,onDecline:r,onSendAgain:i,onDismiss:a})=>{let o=e.kind===`friends`||e.kind===`closed`||e.kind===`in-use`||e.kind===`unavailable`,s=e.kind===`accepting`;return Z(`div`,{className:`social-invite`,"data-social-guest":e.kind,children:[Z(`h2`,{children:`An invite to be friends`}),Z(`div`,{className:`social-stack`,role:`status`,children:[e.kind===`joining`&&Z(`p`,{children:`Opening the invite...`}),e.kind===`waiting`&&(e.host===null?Z(`p`,{children:`Waiting for the person who made it to answer...`}):Z(K,{children:[Z(LT,{peer:e.host}),Z(`p`,{children:[`Waiting for `,e.host.name,` to add you.`]})]})),(e.kind===`offered`||e.kind===`accepting`||e.kind===`failed`)&&Z(K,{children:[Z(LT,{peer:{...e.host,displayName:e.profile.displayName}}),Z(RT,{profile:e.profile,site:t}),e.kind===`failed`&&Z(`p`,{className:`social-error`,role:`alert`,children:e.reason===`no-writer`?BT:Wm[e.reason]}),Z(`div`,{className:`social-row`,children:[(e.kind!==`failed`||e.reason!==`no-writer`)&&Z(`button`,{type:`button`,className:`social-primary`,"data-accept":!0,"aria-disabled":s,onClick:()=>{s||n()},children:s?`Accepting...`:e.kind===`failed`?`Try again`:`Accept`}),Z(`button`,{type:`button`,"aria-disabled":s,onClick:()=>{s||r()},children:`Decline`})]})]}),e.kind===`unsent`&&Z(K,{children:[Z(`p`,{className:`social-error`,role:`alert`,children:[e.host.name,` is in your friend list, but your answer did not reach them.`]}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,onClick:i,children:`Send again`})})]}),e.kind===`friends`&&Z(`p`,{"data-social-done":!0,children:[`You and `,e.host.name,` are now friends.`]}),e.kind===`in-use`&&Z(`p`,{children:`Someone else is already using this invite. Ask for a new link.`}),e.kind===`unavailable`&&Z(`p`,{children:`FKN rooms did not answer. Open the link again in a moment.`}),e.kind===`closed`&&Z(`p`,{children:`This invite is no longer open. Ask for a new link.`})]}),o&&Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:a,children:`Done`})})]})},HT=[{level:`public`,label:`Public`},{level:`friends`,label:`Friends`},{level:`off`,label:`Off`}],UT={activity:`Delete all activity?`,comments:`Delete all comments?`},WT=(e,t)=>Object.keys(UT).filter(n=>Tv(e,n)!==`off`&&Tv(t,n)===`off`),GT=({layout:e,onSave:t})=>{let[n,r]=q(e),[i,a]=q(e),[o,s]=q(!1),[c,l]=q(null),[u,d]=q(!1),[f,p]=q(null),m=J(null),h=J(null),g=J(!1),_=e=>{g.current=!0,e?T(!0):p(null)},v=e=>{e!==null&&g.current&&(g.current=!1,e.focus())},y=JSON.stringify(e),[b,x]=q(y);y!==b&&(x(y),y!==JSON.stringify(i)&&(JSON.stringify(n)===JSON.stringify(i)&&r(e),a(e)));let S=e=>{r(e),l(null),d(!1),p(null)},C=(e,t)=>{h.current=`${e}-${t===-1?`up`:`down`}`,S(Ov(n,e,t))};gu(()=>{if(h.current===null)return;let e=h.current;h.current=null,m.current?.querySelector(`[data-social-move="${e}"]`)?.focus()},[n.sections]);let w=(e,t)=>S(Dv(n,e,t)),T=async(e=!1)=>{if(o)return;let r=WT(i,n);if(!e&&r.length>0)return p(r.length>1?`Delete all activity and comments?`:UT[r[0]]);p(null),s(!0);let c=await t(n,i);s(!1),c.ok&&a(n),d(c.ok),l(c.ok?null:Wm[c.reason])};return Z(`div`,{className:`social-stack`,"data-social-page-editor":!0,children:[Z(`div`,{className:`social-stack`,role:`radiogroup`,"aria-label":`Theme`,children:[Z(`span`,{className:`social-label`,children:`Theme`}),Z(`div`,{className:`social-swatch-row`,children:dv.map(e=>Z(`label`,{className:`social-choice social-tile`,children:[Z(`input`,{type:`radio`,name:`theme`,value:e,checked:n.theme===e,onChange:()=>S({...n,theme:e})}),Z(`span`,{className:`social-swatch`,"data-social-theme-swatch":e,style:{background:`linear-gradient(135deg, ${uv[e].bg} 0% 50%, ${uv[e].accent} 50% 100%)`},"aria-hidden":`true`}),Z(`span`,{className:`social-choice-label`,children:uv[e].label})]},e))})]}),Z(`div`,{className:`social-stack`,role:`radiogroup`,"aria-label":`Colour`,children:[Z(`span`,{className:`social-label`,children:`Colour`}),Z(`div`,{className:`social-swatch-row`,children:lv.map(e=>Z(`label`,{className:`social-choice social-tile`,children:[Z(`input`,{type:`radio`,name:`accent`,value:e,checked:n.accent===e,onChange:()=>S({...n,accent:e})}),Z(`span`,{className:`social-swatch`,"data-social-accent":e,"aria-hidden":`true`}),Z(`span`,{className:`social-choice-label`,children:cv[e].label})]},e))})]}),Z(`span`,{className:`social-label`,children:`Sections`}),Z(`ul`,{className:`social-list`,ref:m,children:n.sections.map((e,t)=>{let r=mv[e.id],i=e=>e===-1?t===0:t===n.sections.length-1;return Z(`li`,{className:`social-section`,"data-social-section":e.id,children:[Z(`div`,{className:`social-section-head`,children:[Z(`span`,{className:`social-choice-label`,children:r}),Z(`div`,{className:`social-section-moves`,children:[[-1,`up`],[1,`down`]].map(([t,n])=>Z(`button`,{type:`button`,"aria-label":`Move ${r} ${n}`,"aria-disabled":i(t),"data-social-move":`${e.id}-${n}`,onClick:()=>{i(t)||C(e.id,t)},children:[Z(t===-1?Pm:Fm,{}),`Move `,n]},t))})]}),e.id!==`about`&&Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`Who sees ${r}`,children:HT.map(({level:t,label:n})=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`${e.id}-level`,value:t,checked:e.level===t,onChange:()=>w(e.id,t)}),Z(`span`,{className:`social-choice-label`,children:n})]},t))})]},e.id)})}),Z(Qm,{children:c}),f===null?Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-save-layout":!0,ref:v,"aria-disabled":o,onClick:()=>void T(),children:o?`Saving...`:`Save layout`}),u&&Z(`span`,{className:`social-muted`,"data-social-layout-saved":!0,children:`Saved`})]}):Z(`div`,{className:`social-warn`,"data-social-drop-activity":!0,children:[Z(`p`,{children:f}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,ref:Zm,"data-social-drop-confirm":!0,onClick:()=>_(!0),children:`Delete`}),Z(`button`,{type:`button`,onClick:()=>_(!1),children:`Cancel`})]})]})]})},KT=(e,t)=>{if(t===``)return;let n=e.at(-1);n?.kind===`text`?e[e.length-1]={kind:`text`,text:n.text+t}:e.push({kind:`text`,text:t})},qT=e=>e===` `||e===` `||e===`
|
|
11
|
+
`||e===`\r`,JT=e=>{if(/\s/.test(e))return null;let t=pf(e);if(t===null)return null;let n=new URL(t);return n.username===``&&n.password===``?t:null},YT=e=>{let t=[],n=[],r=!1,i=0;for(;i<e.length;){if(e[i]==="`"){if(!r){let t=e.indexOf("`",i+1);if(t>i+1){i=t+1;continue}t<0&&(r=!0)}i+=1;continue}if(e[i]===`*`){if(e[i+1]===`*`){let n=i+2;for(;e[n]===`*`;)n+=1;i>0&&!qT(e[i-1])&&t.push(n-2),i=n;continue}i>0&&e[i-1]!==`*`&&!qT(e[i-1])&&n.push(i)}i+=1}return{bold:t,italic:n}},XT=(e,t)=>{let{bold:n,italic:r}=t<2?YT(e):{bold:[],italic:[]},i=0,a=0,o=!1,s=!1,c=[],l=0;for(;l<e.length;){let u=e[l];if(u==="`"){if(!o){let t=e.indexOf("`",l+1);if(t>l+1){c.push({kind:`code`,text:e.slice(l+1,t)}),l=t+1;continue}t<0&&(o=!0)}}else if(u===`[`){let t=l+1;for(;t<e.length;){let n=e[t];if(n===`]`||n===`[`||n===`
|
|
12
|
+
`)break;t+=1}if(e[t]===`]`&&e[t+1]===`(`&&!s){let n=e.indexOf(`)`,t+2);if(n<0)s=!0;else{let r=JT(e.slice(t+2,n));if(r!==null){let i=e.slice(l+1,t).trim()||r;c.push({kind:`link`,label:i,href:r}),l=n+1;continue}}}}else if(t<2&&u===`*`){if(e[l+1]===`*`){if(!qT(e[l+2])){for(;i<n.length&&n[i]<=l+2;)i+=1;if(i<n.length){let r=n[i++];c.push({kind:`strong`,children:XT(e.slice(l+2,r),t+1)}),l=r+2;continue}}}else if(!qT(e[l+1])){for(;a<r.length&&r[a]<=l+1;)a+=1;if(a<r.length){let n=r[a++];c.push({kind:`em`,children:XT(e.slice(l+1,n),t+1)}),l=n+1;continue}}}KT(c,u),l+=1}return c},ZT=e=>e.startsWith(`### `)?{level:3,body:e.slice(4)}:e.startsWith(`## `)?{level:2,body:e.slice(3)}:e.startsWith(`# `)?{level:1,body:e.slice(2)}:null,QT=e=>e.startsWith(`- `)||e.startsWith(`* `)?e.slice(2):null,$T=e=>{let t=e.replaceAll(`\r
|
|
13
|
+
`,`
|
|
14
|
+
`).split(`
|
|
15
|
+
`),n=[],r=null,i=null,a=()=>{if(r===null)return;let e=[];for(let[t,n]of r.entries())t>0&&e.push({kind:`break`}),e.push(...XT(n,0));n.push({kind:`paragraph`,children:e}),r=null},o=()=>{i!==null&&(n.push({kind:`list`,items:i}),i=null)};for(let e of t){if(e.trim()===``){a(),o();continue}let t=ZT(e);if(t!==null){a(),o(),n.push({kind:`heading`,level:t.level,children:XT(t.body,0)});continue}let s=QT(e);if(s!==null){a(),i===null&&(i=[]),i.push(XT(s,0));continue}o(),r===null&&(r=[]),r.push(e)}return a(),o(),n},eE=(e,t)=>e.map((e,n)=>{let r=`${t}-${n}`;switch(e.kind){case`text`:return Z(K,{children:e.text},r);case`break`:return Z(`br`,{},r);case`code`:return Z(`code`,{children:e.text},r);case`strong`:return Z(`strong`,{children:eE(e.children,r)},r);case`em`:return Z(`em`,{children:eE(e.children,r)},r);case`link`:return Z(`a`,{className:`social-page-link`,href:e.href,target:`_blank`,rel:`noopener noreferrer nofollow ugc`,children:e.label},r)}}),tE=(e,t)=>{let n=`b-${t}`;switch(e.kind){case`heading`:{let t=eE(e.children,n);return e.level===1?Z(`h3`,{children:t},n):e.level===2?Z(`h4`,{children:t},n):Z(`h5`,{children:t},n)}case`paragraph`:return Z(`p`,{children:eE(e.children,n)},n);case`list`:return Z(`ul`,{children:e.items.map((e,t)=>Z(`li`,{children:eE(e,`${n}-i-${t}`)},`${n}-i-${t}`))},n)}},nE=({text:e})=>Z(`div`,{className:`social-md`,"data-social-markdown":!0,children:_u(()=>$T(e),[e]).map(tE)}),rE={...Wm,...Jm,...Km},iE=[{level:`public`,label:`Public`},{level:`friends`,label:`Friends`},{level:`off`,label:`Off`}],aE=e=>Math.max(1,Math.round(e/1024)).toLocaleString(`en`),oE=(e,t)=>e.kind===`artwork`&&e.items.length>0&&(e.level===`public`&&t!==`public`||e.level===`friends`&&t===`off`),sE=(e,t)=>e.kind===`artwork`&&e.items.length>0&&e.level!==`public`&&t===`public`,cE=e=>Object.fromEntries(e.items.map(e=>[e.picture.url,e.caption??``])),lE=({panel:e,index:t,total:n,onMove:r,onRemove:i,onListProblem:a,actions:o})=>{let[s,c]=q(e.title),[l,u]=q(e.kind===`text`?e.body:``),[d,f]=q(()=>e.kind===`artwork`?cE(e):{}),[p,m]=q(e.title),[h,g]=q(e.kind===`text`?e.body:``),[_,v]=q(()=>e.kind===`artwork`?JSON.stringify(e.items):``),[y,b]=q(()=>e.kind===`artwork`?cE(e):{});e.title!==p&&(m(e.title),c(e.title));let x=e.kind===`text`?e.body:``;x!==h&&(g(x),u(x));let S=e.kind===`artwork`?JSON.stringify(e.items):``;S!==_&&(v(S),e.kind===`artwork`?(b(cE(e)),f(t=>{let n={};for(let r of e.items){let e=r.picture.url,i=r.caption??``,a=y[e];n[e]=a!==void 0&&Object.hasOwn(t,e)&&t[e]!==a&&i===a?t[e]:i}return n})):b({}));let[C,w]=q(`write`),[T,E]=q(!1),[D,O]=q(!1),[k,A]=q(null),[j,M]=q(null),[N,P]=q(!1),[F,I]=q(!1),[L,R]=q(null),[z,ee]=q(``),te=J(null),ne=J(null),re=J(null),ie=J(null),B=J(null);hu(()=>()=>{L!==null&&URL.revokeObjectURL(L.url)},[L]);let ae=e.kind===`artwork`?e.items.length:0;gu(()=>{B.current===`level`&&j===null?(B.current=null,re.current?.querySelector(`input:checked`)?.focus()):B.current===`file-or-save`&&L===null&&(B.current=null,(te.current??ie.current)?.focus())},[j,e.level,L,ae]);let oe=async(e,t=!1)=>{if(T)return;E(!0),A(null),a(null),O(!1);let n=await e();return E(!1),n.ok?(M(null),P(!1),t&&O(!0)):(B.current=null,n.reason===`sync-failed`&&(M(null),P(!1)),A(rE[n.reason])),n},se=t=>{if(!T){if(A(null),t===e.level){M(null);return}if(oE(e,t)||sE(e,t)){M(t);return}oe(()=>o.setLevel(e.id,t))}},ce=t=>{B.current=`level`,oe(()=>o.setLevel(e.id,t))},le=()=>{T||(M(null),re.current?.querySelector(`input:checked`)?.focus())},ue=async e=>{if(T){A(`Another change is still saving. Try again in a moment.`);return}E(!0),I(!0),A(null),O(!1);let t=await o.fitArtwork(e);if(E(!1),I(!1),!t.ok){A(rE[t.reason]);return}R({...t.picture,url:URL.createObjectURL(t.picture.blob)}),ee(``)},de=()=>{B.current=`file-or-save`,R(null),ee(``)};return Z(`li`,{className:`social-section`,"data-social-panel-card":e.id,"data-social-panel-kind":e.kind,children:[Z(`div`,{className:`social-section-head`,children:[Z(`div`,{className:`social-panel-head-title`,children:[Z(`span`,{className:`social-panel-tag`,children:e.kind===`text`?`Text`:`Artwork`}),Z(`span`,{className:`social-choice-label`,children:e.title})]}),Z(`div`,{className:`social-section-moves`,children:[Z(`button`,{type:`button`,"aria-label":`Move ${e.title} up`,"aria-disabled":T||t===0,"data-panel-move":`${e.id}-up`,onClick:()=>{!T&&t>0&&r(-1)},children:[Z(Pm,{}),`Move up`]}),Z(`button`,{type:`button`,"aria-label":`Move ${e.title} down`,"aria-disabled":T||t===n-1,"data-panel-move":`${e.id}-down`,onClick:()=>{!T&&t<n-1&&r(1)},children:[Z(Fm,{}),`Move down`]}),Z(`button`,{type:`button`,ref:ne,className:`social-danger`,"aria-disabled":T,"data-panel-delete-start":e.id,onClick:()=>{T||P(!0)},children:`Delete`})]})]}),N&&Z(`div`,{className:`social-warn`,"data-panel-delete-confirm":e.id,children:[Z(`p`,{children:e.kind===`artwork`&&e.items.length>0?`Delete this panel and its uploaded artwork from storage?`:`Delete this panel?`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,ref:Zm,"data-panel-delete-confirm-btn":!0,"aria-disabled":T,onClick:()=>void oe(i),children:T?`Deleting...`:`Delete panel`}),Z(`button`,{type:`button`,"aria-disabled":T,onClick:()=>{T||(P(!1),ne.current?.focus())},children:`Cancel`})]})]}),Z(`div`,{className:`social-seg`,ref:re,role:`radiogroup`,"aria-label":`Who sees ${e.title}`,children:iE.map(({level:t,label:n})=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`panel-level-${e.id}`,value:t,checked:(j??e.level)===t,"aria-disabled":T,onChange:()=>se(t)}),Z(`span`,{className:`social-choice-label`,children:n})]},t))}),j!==null&&oE(e,j)&&Z(`div`,{className:`social-warn`,"data-panel-level-confirm":e.id,children:[Z(`p`,{children:e.level===`public`?`Making this artwork panel non-public deletes its uploaded artwork so no public URL stays exposed.`:`Turning this artwork panel off deletes its uploaded artwork from storage.`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,ref:Zm,"data-panel-level-confirm-btn":!0,"aria-disabled":T,onClick:()=>ce(j),children:T?`Saving...`:`Confirm change`}),Z(`button`,{type:`button`,"aria-disabled":T,onClick:le,children:[`Keep `,e.level===`public`?`public`:`for friends`]})]})]}),j!==null&&sE(e,j)&&Z(`div`,{className:`social-invite`,"data-panel-publish-confirm":e.id,children:[Z(`p`,{children:`Making this panel public lets anyone who opens your page see these artwork images.`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,ref:Zm,"data-panel-publish-confirm-btn":!0,"aria-disabled":T,onClick:()=>ce(`public`),children:T?`Publishing...`:`Make public`}),Z(`button`,{type:`button`,"aria-disabled":T,onClick:le,children:[`Keep `,e.level===`friends`?`for friends`:`off`]})]})]}),Z(`label`,{className:`social-label`,children:[`Title`,Z(`input`,{name:`panel-title-${e.id}`,autoComplete:`off`,value:s,onChange:e=>{c(e.currentTarget.value),O(!1),A(null)}})]}),e.kind===`text`?Z(K,{children:[Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`Markdown mode for ${e.title}`,children:[`write`,`preview`].map(t=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`panel-mode-${e.id}`,value:t,checked:C===t,onChange:()=>w(t)}),Z(`span`,{className:`social-choice-label`,children:t===`write`?`Write`:`Preview`})]},t))}),C===`write`?Z(K,{children:[Z(`label`,{className:`social-label`,children:[`Markdown text`,Z(`textarea`,{name:`panel-body-${e.id}`,rows:4,value:l,onChange:e=>{u(e.currentTarget.value),O(!1),A(null)}})]}),Z(`span`,{className:`social-muted`,children:[l.length,` / `,Qp]})]}):Z(`div`,{className:`social-md-preview`,"data-panel-preview":e.id,children:l.trim()?Z(nE,{text:l}):Z(`span`,{className:`social-muted`,children:`Nothing to preview yet.`})}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-panel-save":e.id,"aria-disabled":T,onClick:()=>void oe(()=>o.updateText(e.id,{title:s,body:l}),!0),children:T?`Saving...`:`Save panel`}),D&&Z(`span`,{className:`social-muted`,"data-panel-saved":e.id,children:`Saved`})]})]}):Z(K,{children:[e.items.length>0&&Z(`div`,{className:`social-art-list`,"data-panel-art-items":e.id,children:e.items.map((t,n)=>Z(`div`,{className:`social-art-row`,"data-panel-art-row":t.picture.url,children:[Z(`div`,{className:`social-art-row-head`,children:[Z(`span`,{className:`social-choice-label`,children:[`Artwork `,n+1]}),Z(`button`,{type:`button`,"data-panel-art-remove":t.picture.url,"aria-disabled":T,onClick:()=>void oe(()=>o.removeArtItem(e.id,t.picture.url)),children:`Remove`})]}),Z(`label`,{className:`social-label`,children:[`Caption`,Z(`input`,{name:`panel-caption-${e.id}-${n}`,autoComplete:`off`,value:d[t.picture.url]??``,placeholder:`Optional caption`,onChange:e=>{let n=e.currentTarget.value;f(e=>({...e,[t.picture.url]:n})),O(!1),A(null)}})]})]},t.picture.url))}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,ref:ie,className:`social-primary`,"data-panel-save":e.id,"aria-disabled":T,onClick:()=>void oe(()=>o.updateArtwork(e.id,{title:s,captions:d}),!0),children:T?`Saving...`:`Save panel`}),D&&Z(`span`,{className:`social-muted`,"data-panel-saved":e.id,children:`Saved`})]}),e.level===`off`?Z(`p`,{className:`social-muted`,"data-panel-art-off":e.id,children:`Set this panel to Friends or Public to upload artwork.`}):e.items.length<4&&Z(`div`,{className:`social-stack`,children:[Z(`label`,{className:`social-label`,children:[`Add artwork (`,e.items.length,` / `,4,`)`,F?`: resizing...`:``,Z(`input`,{ref:te,type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,"aria-disabled":T,"data-panel-file":e.id,onChange:e=>{let t=e.currentTarget.files?.[0];e.currentTarget.value=``,t&&ue(t)}})]}),L!==null&&Z(`div`,{className:`social-stack`,"data-panel-art-preview":e.id,children:[Z(`img`,{className:`social-preview`,src:L.url,alt:`Fitted artwork preview`,"data-panel-art-preview-img":!0}),Z(`p`,{className:`social-muted`,"data-panel-art-preview-size":!0,children:[L.width,` by `,L.height,` pixels, `,aE(L.blob.size),` KB`,L.animated?`, animated`:``]}),Z(`label`,{className:`social-label`,children:[`Caption (optional)`,Z(`input`,{name:`panel-new-caption-${e.id}`,autoComplete:`off`,value:z,onChange:e=>ee(e.currentTarget.value)})]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,ref:Zm,"data-panel-use-art":e.id,"aria-disabled":T,onClick:()=>{if(L===null)return;let t=L;oe(async()=>{let n=await o.addArtItem(e.id,t.blob,z);return(n.ok||n.reason===`sync-failed`)&&de(),n})},children:`Add artwork`}),Z(`button`,{type:`button`,"data-panel-another-art":e.id,"aria-disabled":T,onClick:()=>{T||de()},children:`Choose another`})]})]})]})]}),Z(Qm,{children:k})]})},uE=({panels:e,actions:t})=>{let[n,r]=q(null),[i,a]=q(null),[o,s]=q(null),[c,l]=q(!1),u=J(null),d=J(null),f=J(null),p=J(null),m=J(void 0);gu(()=>{if(p.current!==null){let e=p.current;p.current=null,u.current?.querySelector(`[data-panel-move="${e}"]`)?.focus()}if(m.current!==void 0){let e=m.current;m.current=void 0,e===null?d.current?.focus():(u.current?.querySelector(`[data-panel-delete-start="${e}"]`)??d.current)?.focus()}},[e]);let h=t=>{c||e.length>=6||(a(null),s(null),r({kind:t,title:``,body:``,level:`friends`,mode:`write`}))},g=async()=>{if(c||n===null)return;l(!0),a(null),s(null);let e=n.kind===`text`?await t.addText({title:n.title,body:n.body,level:n.level}):await t.addArtwork({title:n.title,level:n.level});l(!1),e.ok?r(null):e.reason===`sync-failed`?(r(null),s(rE[e.reason])):a(rE[e.reason])},_=async(n,r)=>{if(c)return;let i=e.findIndex(e=>e.id===n),a=i+r;if(i<0||a<0||a>=e.length)return;p.current=`${n}-${r===-1?`up`:`down`}`,l(!0),s(null);let o=await t.move(n,r);l(!1),o.ok||(p.current=null,s(rE[o.reason]))},v=async n=>{let r=e.findIndex(e=>e.id===n);m.current=r<0?null:e[r+1]?.id??e[r-1]?.id??null;let i=await t.remove(n);return i.ok||(m.current=void 0,i.reason===`sync-failed`&&s(rE[i.reason])),i};return Z(`div`,{className:`social-stack`,"data-social-panels-editor":!0,children:[Z(`div`,{className:`social-panel-bar`,children:[Z(`p`,{className:`social-muted`,children:`Add Markdown text boxes or artwork showcases. Public panels show on your page; Friends panels stay sealed for friends.`}),Z(`span`,{className:`social-panel-count`,"data-social-panel-count":!0,children:[e.length,` / `,6]})]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,ref:d,className:`social-primary`,"data-add-text-panel":!0,"aria-disabled":c||e.length>=6,onClick:()=>h(`text`),children:`Add text panel`}),Z(`button`,{type:`button`,ref:f,"data-add-artwork-panel":!0,"aria-disabled":c||e.length>=6,onClick:()=>h(`artwork`),children:`Add artwork panel`})]}),n!==null&&Z(`div`,{className:`social-invite`,"data-social-panel-create":n.kind,children:[Z(`h2`,{children:n.kind===`text`?`New text panel`:`New artwork panel`}),Z(`label`,{className:`social-label`,children:[`Title`,Z(`input`,{name:`panel-new-title`,ref:Zm,autoComplete:`off`,value:n.title,onChange:e=>{let t=e.currentTarget.value;r(e=>e===null?null:{...e,title:t}),a(null)}})]}),Z(`span`,{className:`social-label`,children:`Who sees it`}),Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`Who sees this new panel`,children:iE.map(({level:e,label:t})=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`panel-new-level`,value:e,checked:n.level===e,onChange:()=>r(t=>t===null?null:{...t,level:e})}),Z(`span`,{className:`social-choice-label`,children:t})]},e))}),n.kind===`text`&&Z(K,{children:[Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`New panel Markdown mode`,children:[`write`,`preview`].map(e=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`panel-new-mode`,value:e,checked:n.mode===e,onChange:()=>r(t=>t===null?null:{...t,mode:e})}),Z(`span`,{className:`social-choice-label`,children:e===`write`?`Write`:`Preview`})]},e))}),n.mode===`write`?Z(K,{children:[Z(`label`,{className:`social-label`,children:[`Markdown text`,Z(`textarea`,{name:`panel-new-body`,rows:5,value:n.body,onChange:e=>{let t=e.currentTarget.value;r(e=>e===null?null:{...e,body:t}),a(null)}})]}),Z(`div`,{className:`social-muted`,children:[n.body.length,` / `,2e3," - Supports # headings, - lists, **bold**, *italic*, `code`, and [links](https://...)."]})]}):Z(`div`,{className:`social-md-preview`,"data-social-new-preview":!0,children:n.body.trim()?Z(nE,{text:n.body}):Z(`span`,{className:`social-muted`,children:`Nothing to preview yet.`})})]}),Z(Qm,{children:i}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-create-panel":!0,"aria-disabled":c,onClick:()=>void g(),children:c?`Creating...`:`Create panel`}),Z(`button`,{type:`button`,"aria-disabled":c,onClick:()=>{if(c)return;let e=n.kind;r(null),(e===`text`?d:f).current?.focus()},children:`Cancel`})]})]}),Z(Qm,{children:o}),e.length===0?Z(`p`,{className:`social-muted`,"data-social-panels-empty":!0,children:`No custom panels yet.`}):Z(`ul`,{className:`social-list`,ref:u,children:e.map((n,r)=>Z(lE,{panel:n,index:r,total:e.length,onMove:e=>void _(n.id,e),onRemove:()=>v(n.id),onListProblem:s,actions:t},n.id))})]})},dE={...Wm,...Gm},fE=e=>e.length<5&&e.at(-1)!==``?[...e,``]:e,pE=e=>({displayName:e.displayName,bio:e.bio,links:fE(e.links)}),mE=({profile:e,onSave:t})=>{let[n,r]=q(()=>pE(e)),[i,a]=q(()=>({displayName:e.displayName,bio:e.bio,links:e.links})),[o,s]=q(!1),[c,l]=q(null),[u,d]=q(!1),f=e=>{r(t=>({...t,...e})),l(null),d(!1)},p=async()=>{if(o)return;s(!0);let e=await t(n,i);s(!1);let r=bf(n);e.ok&&r.ok&&a(r.profile),d(e.ok),l(e.ok?null:dE[e.reason])};return Z(`div`,{className:`social-stack`,"data-social-profile":!0,children:[Z(`label`,{className:`social-label`,children:[`Display name`,Z(`input`,{name:`display-name`,autoComplete:`off`,value:n.displayName,onChange:e=>f({displayName:e.currentTarget.value})})]}),Z(`label`,{className:`social-label`,children:[`Bio`,Z(`textarea`,{name:`bio`,rows:4,value:n.bio,onChange:e=>f({bio:e.currentTarget.value})})]}),Z(`span`,{className:`social-label`,children:`Links`}),n.links.map((e,t)=>Z(`input`,{name:`link-${t}`,"aria-label":`Link ${t+1}`,autoComplete:`off`,spellcheck:!1,placeholder:`https://`,value:e,onChange:e=>f({links:fE(n.links.map((n,r)=>r===t?e.currentTarget.value:n))})},t)),Z(Qm,{children:c}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-save-profile":!0,"aria-disabled":o,onClick:()=>void p(),children:o?`Saving...`:`Save profile`}),u&&Z(`span`,{className:`social-muted`,"data-social-saved":!0,children:`Saved`})]})]})},hE=[{level:`me`,label:`Only me`},{level:`friends`,label:`Friends`},{level:`public`,label:`Public`}],gE=({notice:e,page:t})=>{let n=t.replace(/^https?:\/\//,``);return e===`moved`?Z(`p`,{className:`social-warn`,role:`status`,"data-social-notice":`moved`,children:[`Your old page was taken down. Publish again to show your profile at `,n,`.`]}):e===`old-page-stands`?Z(`p`,{className:`social-muted`,role:`status`,"data-social-notice":`old-page-stands`,children:`Your old page could not be taken down yet. Reload to try again.`}):null},_E=[{slot:`avatar`,label:`Avatar`},{slot:`background`,label:`Background`}],vE=e=>Math.max(1,Math.round(e/1024)).toLocaleString(`en`),yE=({preview:e,busy:t,onUse:n,onAnother:r})=>Z(`div`,{className:`social-stack`,"data-social-preview":e.slot,children:[Z(`img`,{className:e.slot===`avatar`?`social-avatar`:`social-preview`,src:e.url,alt:`Your new ${e.slot}`,"data-social-preview-image":!0}),Z(`p`,{className:`social-muted`,"data-social-preview-size":!0,children:[e.width,` by `,e.height,` pixels, `,vE(e.blob.size),` KB`,e.animated?`, animated`:``]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-use-picture":!0,ref:Zm,"aria-disabled":t,onClick:n,children:`Use this picture`}),Z(`button`,{type:`button`,"data-another-picture":!0,"aria-disabled":t,onClick:r,children:`Choose another`})]})]}),bE=`Your page shows nothing: see the warning above.`,xE={lost:bE,taken:bE,retired:bE,unrecorded:`Your page could not be written. Write it again from the warning above.`,unknown:`Your page could not be checked just now. Reload to try again.`},SE={"not-kept":`Your profile page room keeps no messages. Turn on Messages kept for it under Rooms in your FKN settings.`,taken:`Someone else holds your profile page room now.`,"out-of-claims":`Your account is at its claimed room limit, so your profile is kept in your name room. Free a room under Rooms in your FKN settings, then make a page room.`,inline:`Your profile is kept in your name room instead of a separate page room.`,unavailable:`FKN rooms did not answer, so your profile page room has not updated yet.`},CE=({visibility:e,page:t,pictures:n,status:r,pageRoomStatus:i=null,oldPage:a=!1,site:o,actions:s})=>{let[c,l]=q(null),[u,d]=q(!1),[f,p]=q(null),[m,h]=q(null),[g,_]=q(null),v=J(null),y=J(!1),b=e.level,x=t.replace(/^https?:\/\//,``);hu(()=>()=>{m!==null&&URL.revokeObjectURL(m.url)},[m]);let S=async(e,t=!1)=>{if(u)return;d(!0),p(null);let n=await e();n.ok&&t&&(y.current=!0),d(!1),n.ok?(l(null),t&&h(null)):p(Jm[n.reason])},C=async(e,t)=>{if(u)return;d(!0),_(e),p(null);let n=await s.fitPicture(e,t);if(d(!1),_(null),!n.ok)return p(Jm[n.reason]);h({...n.picture,slot:e,url:URL.createObjectURL(n.picture.blob)})},w=e=>{v.current=e,h(null)},T=e=>void S(async()=>{let t=await s.putPicture(e.slot,e.blob);return t.ok&&w(e.slot),t}),E=e=>t=>{t!==null&&v.current===e&&(v.current=null,t.focus())},D=e=>{e!==null&&y.current&&(y.current=!1,(e.querySelector(`input:checked`)??e).focus())},O=e=>{u||(p(null),e===b?l(null):e===`public`||b===`public`||b===`friends`&&e===`me`&&(n.avatar||n.background)?l(e):S(async()=>{let t=await s.setLevel(e);return t.ok&&e===`me`&&h(null),t}))},k=_E.map(({slot:e,label:t})=>Z(`div`,{className:`social-stack`,"data-social-picture":e,"data-social-picture-set":n[e],children:[Z(`label`,{className:`social-label`,children:[t,` picture: `,g===e?`resizing...`:n[e]?`one is set`:`none yet`,Z(`input`,{type:`file`,accept:`image/png,image/jpeg,image/gif,image/webp`,"aria-disabled":u,"data-picture-input":e,ref:E(e),onChange:t=>{let n=t.currentTarget.files?.[0];t.currentTarget.value=``,n&&C(e,n)}})]}),m?.slot===e&&Z(yE,{preview:m,busy:u,onUse:()=>T(m),onAnother:()=>{u||w(e)}}),n[e]&&m?.slot!==e&&Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"aria-disabled":u,onClick:()=>void S(()=>s.removePicture(e)),children:[`Remove the `,t.toLowerCase()]})})]},e)),A=b===`public`&&c!==null&&c!==`public`?c:null,j=b===`friends`&&c===`me`,M=r===null?void 0:xE[r];return Z(`div`,{className:`social-stack`,"data-social-level":b,children:[Z(`div`,{className:`social-stack`,"data-social-page-link":t,children:[Z(`span`,{className:`social-label`,children:`Your page`}),Z(ih,{url:t,site:o})]}),Z(`div`,{className:`social-seg`,role:`radiogroup`,"aria-label":`Who sees your profile`,ref:b===`public`?void 0:D,children:hE.map(({level:e,label:t})=>Z(`label`,{className:`social-choice`,children:[Z(`input`,{type:`radio`,name:`visibility`,value:e,checked:(c??b)===e,"aria-disabled":u,onChange:()=>O(e)}),Z(`span`,{className:`social-choice-label`,children:t})]},e))}),c===`public`&&b!==`public`&&Z(`div`,{className:`social-invite`,"data-social-publish":!0,children:[Z(`h2`,{children:`Publish your profile`}),Z(`p`,{className:`social-muted`,children:[`Anyone who opens `,x,` sees your profile and pictures.`]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,"data-publish":!0,"aria-disabled":u,onClick:()=>void S(s.publish,!0),children:u?`Publishing...`:`Publish`}),Z(`button`,{type:`button`,"aria-disabled":u,onClick:()=>{u||l(null)},children:`Cancel`})]})]}),A!==null&&Z(`div`,{className:`social-warn`,"data-social-unpublish":!0,children:[Z(`p`,{children:[`Unpublishing deletes your pictures and shows your profile only to `,A===`friends`?`your friends`:`you`,`.`]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,"data-unpublish":!0,ref:Zm,"aria-disabled":u,onClick:()=>void S(()=>s.setLevel(A),!0),children:u?`Unpublishing...`:`Unpublish`}),Z(`button`,{type:`button`,"aria-disabled":u,onClick:()=>{u||l(null)},children:`Keep it public`})]})]}),j&&Z(`div`,{className:`social-warn`,"data-social-hide-pictures":!0,children:[Z(`p`,{children:`Switching to Only me deletes your pictures and hides your profile from your friends.`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,"data-hide-pictures":!0,ref:Zm,"aria-disabled":u,onClick:()=>void S(()=>s.setLevel(`me`),!0),children:u?`Saving...`:`Hide profile`}),Z(`button`,{type:`button`,"aria-disabled":u,onClick:()=>{u||l(null)},children:`Keep for friends`})]})]}),b===`friends`&&!a&&Z(`div`,{className:`social-invite`,"data-social-friends-pictures":!0,children:[Z(`h2`,{children:`Profile pictures`}),Z(`p`,{className:`social-muted`,children:`Shown only to your friends. Static images are resized; animated GIF and WebP files keep their motion.`}),k]}),b===`public`&&Z(`div`,{className:`social-invite`,"data-social-public":r??`checking`,children:[Z(`h2`,{tabIndex:-1,ref:D,children:`Your public page`}),M!==void 0&&Z(`p`,{className:`social-warn-text`,role:`status`,"data-social-page-status":!0,children:M}),!a&&Z(K,{children:[Z(`p`,{className:`social-muted`,children:`Static images are resized; animated GIF and WebP files keep their motion.`}),k]}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-unpublish-start":!0,"aria-disabled":u,onClick:()=>{u||l(`friends`)},children:`Unpublish`})})]}),i!==null&&SE[i]!==void 0&&Z(`div`,{className:`social-stack`,"data-social-page-room-status":i,children:[Z(`p`,{className:`social-warn-text`,role:`status`,children:SE[i]}),(i===`taken`||i===`out-of-claims`||i===`inline`)&&s.makePage!==void 0&&Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,"data-make-page":!0,"aria-disabled":u,onClick:()=>void S(s.makePage),children:`Make a page room`})})]}),u&&c===null&&Z(`p`,{className:`social-muted`,role:`status`,children:`Saving...`}),Z(Qm,{children:f})]})},wE=()=>null,TE=e=>Object.keys(e.apps).sort().flatMap(t=>{let n=bC(e,t);return n===null?[]:[{app:t,grant:n}]}),EE=(e,t)=>e.inbox===t.inbox&&e.seq===t.seq,DE=e=>{let[t,n]=q(e.state);return hu(()=>(n(e.state()),e.on(n)),[e]),t},OE=({invite:e,onDismiss:t})=>{let n=DE(e);return Z(zT,{link:e.link,expiresAt:e.expiresAt,state:n,onAdd:e.add,onClose:()=>void e.close(),onSaveAgain:()=>void e.saveAgain(),onDismiss:t})},kE=({invite:e,site:t,onDismiss:n})=>Z(VT,{state:DE(e),site:t,onAccept:()=>void e.accept(),onDecline:()=>{e.decline(),n()},onSendAgain:()=>void e.sendAgain(),onDismiss:n}),AE={me:`Only me`,friends:`Friends`,public:`Public`},jE=({services:e,identity:t,listed:n,fresh:r,cutShort:i,onChanged:a,site:o,staged:s,onStagedTaken:c,adding:l,onAddDone:u,onAdd:d,editing:f,onEditDone:p})=>{let[m,h]=q(null),[g,_]=q(null),[v,y]=q(null),[b,x]=q([]),[S,C]=q(null),[w,T]=q(!1),[E,D]=q(()=>f?`customize`:s!==null||l!==void 0?`friends`:r?`account`:`overview`),[O,k]=q(()=>f?`layout`:`general`),[A,j]=q(!1),M=J(null),N=_u(()=>sv(t.seed),[t.seed]),P=J(null);hu(()=>{let e=new Set;return P.current=e,()=>{P.current=null;for(let t of e)t()}},[]);let F=e=>P.current!==null&&(P.current.add(e),!0),I=J(null),[L,R]=q(!1),z=vu(e=>(e.ok&&(I.current=e.roster,h(e.roster)),_(e.ok?null:Wm[e.reason]),R(!e.ok&&e.reason===`reset`),e),[]),[ee,te]=q(!1),ne=vu(async t=>{z(await(t??tp(e))),te(!0)},[e,z]),re=J(n);hu(()=>{ne(re.current??void 0)},[ne]);let ie=J(Promise.resolve()),B=vu(e=>{let t=ie.current.then(e,e);return ie.current=t.catch(()=>{}),t},[]),[ae,oe]=q(null),[se,ce]=q(null),le=J(null),ue=J(null),[de,fe]=q(null),pe=_u(()=>({keys:N,name:t.name}),[N,t.name]),[me,he]=q(null),ge=J(!1),_e=J(!1),V=async t=>{let n=await tp(e);return n.ok?(z(n),t(GS(n.roster,_e.current))):{ok:!1,reason:n.reason===`reset`?`list-reset`:n.reason}},ve=vu(async(t=!1)=>{let n=I.current;if(n!==null&&zS(n)!==null){let t=await QS(e,n);fe(t.ok?`moved`:`old-page-stands`),t.ok&&(z(t),n=t.roster)}let r=n===null?null:ge.current?{roster:n,inboxTaken:_e.current}:(async t=>{ge.current=!0;let n=await pS(e,N,t);n.roster!==void 0&&z({ok:!0,roster:n.roster}),_e.current=n.status===`taken`,he(n);for(let t of n.waiting)Zx(e.rooms,t.sender.name,t.sender.signKey).then(e=>he(n=>n===null?n:{...n,waiting:n.waiting.map(n=>EE(n,t)?{...n,sender:{...n.sender,confirmed:e}}:n)}));return{roster:n.roster??t,inboxTaken:_e.current}})(n),i=await KS(e,pe,r,{lastNameStatus:le.current,lastCoreKey:ue.current,skipNameIfUnchanged:!t});return i.roster!==void 0&&z({ok:!0,roster:i.roster}),le.current=i.status,ue.current=i.coreKey,oe(i.status),ce(i.pageStatus),i},[e,N,pe,z]),ye=vu(()=>B(async()=>{await ve(!1)}),[B,ve]),be=vu(()=>B(async()=>{await ve(!0)}),[B,ve]);hu(()=>{ee&&be()},[ee,be]);let xe={claimAgain:async()=>{let n=await B(()=>V(n=>hC(e,t,n)));return await be(),n},rename:async t=>{let n=await B(()=>V(n=>pC(e,t,n)));return n.ok&&await a(),n},giveBack:t=>mC(e,t)},Se=e=>{z({ok:!0,roster:e.roster}),le.current=e.status,oe(e.status),e.pageStatus!==void 0&&ce(e.pageStatus);let t=TS(e.roster);ue.current=typeof t==`string`?WS(US(e.roster,t,_e.current)):null},Ce={setLevel:t=>B(async()=>{if(I.current===null)return{ok:!1,reason:`unavailable`};let n=await ZS(e,pe,I.current,t,_e.current);return n.ok?(Se(n),{ok:!0}):(n.pageStatus!==void 0&&ce(n.pageStatus),n)}),publish:()=>B(async()=>{let t=await YS(e,pe,_e.current);return t.ok?(Se(t),fe(null),{ok:!0}):t}),fitPicture:(e,t)=>Xp(t,e,Zp),putPicture:async(t,n)=>{let r=await B(()=>Hp(e,t,n));return r.ok?(z(r),await ye(),{ok:!0}):r},removePicture:async t=>{let n=await B(()=>Up(e,t));return n.ok?(z(n),await ye(),{ok:!0}):n},makePage:()=>B(async()=>{if(I.current===null)return{ok:!1,reason:`unavailable`};let t=I.current,n=TS(t)??void 0,r;if(n===void 0){let t=await Yx(e.rooms,N,pe.name);if(t===null)return{ok:!1,reason:`unavailable`};r=AS(t)}let i=await jS(e,N,VS(t),r,n);return i.roster!==void 0&&z({ok:!0,roster:i.roster}),i.ok?(await ve(!0)).pageStatus===`ready`?{ok:!0}:{ok:!1,reason:`unavailable`}:(i.reason===`out-of-claims`&&ce(`out-of-claims`),{ok:!1,reason:i.reason})})},we=e=>e.pageStatus===`ready`||(e.pageStatus===`inline`||e.pageStatus===`unused`||e.pageStatus===`out-of-claims`)&&e.status===`held`,Te=async e=>{if(!e.ok)return e;`roster`in e&&z(e);let t=await ve(!1).catch(()=>null);return t!==null&&we(t)?{ok:!0}:{ok:!1,reason:`sync-failed`}},Ee=async({outcome:t,dropped:n})=>{if(!t.ok)return t;z(t);let r=null;try{r=await ve(!1)}catch{r=null}finally{await Bp(e.storage,n)}return r!==null&&we(r)?{ok:!0}:{ok:!1,reason:`sync-failed`}},De={addText:t=>B(async()=>Te(await xm(e,t))),addArtwork:t=>B(async()=>Te(await Sm(e,t))),updateText:(t,n)=>B(async()=>Te(await Cm(e,t,n))),updateArtwork:(t,n)=>B(async()=>Te(await wm(e,t,n))),move:(t,n)=>B(async()=>Te(await Tm(e,t,n))),setLevel:(t,n)=>B(async()=>Ee(await Em(e,t,n))),remove:t=>B(async()=>Ee(await Dm(e,t))),fitArtwork:e=>Xp(e,`artwork`,Zp),addArtItem:(t,n,r)=>B(async()=>Te(await Om(e,t,n,r))),removeArtItem:(t,n)=>B(async()=>Ee(await km(e,t,n)))},Oe=e=>({keys:N,name:t.name,profile:Sf(e),inbox:_e.current?null:oS(e)??null}),ke=async()=>{let t=_e.current&&I.current!==null?oS(I.current):void 0,n=await B(()=>sS(e,typeof t==`string`?t:void 0));return n.roster!==void 0&&z({ok:!0,roster:n.roster}),n.ok&&(_e.current=!1,he({status:`ready`,waiting:me?.waiting??[],accepted:me?.accepted??[]}),await ye()),n},Ae=e=>he(t=>t===null?t:{...t,waiting:t.waiting.filter(t=>!EE(t,e))}),je={answer:async(t,n)=>{if(I.current===null)return{ok:!1,reason:`unreachable`};let r=await vS(e,Oe(I.current),t,n);return r.roster!==void 0&&z({ok:!0,roster:r.roster}),r.ok&&Ae(t),r.ok&&n&&ye(),r},dismiss:async t=>{await bS(e,t),Ae(t)},approve:async t=>{let n=await B(()=>JS(e,pe,t));return n&&Ae(t),n}},Me=vu(t=>$x(e.rooms,t),[e]),Ne=t=>B(async()=>{let n=await tp(e);if(!n.ok)return n;let r=await _S(e,Oe(n.roster),t);return ne(),r}),Pe=e=>t=>e.friends[t]?.value.state===`active`,Fe=e=>e.on(e=>{e.kind===`friends`&&ne().then(ye)});hu(()=>{if(s===null||m===null||M.current===s)return;M.current=s,c();let t=rw(e,Oe(m),s,Pe(m));F(t.decline),Fe(t),C(t)});let Ie=async()=>{if(m===null||w||b.length>=3)return;T(!0);let t=await tw(e,Oe(m),Pe(m));if(T(!1),!t.ok)return _(t.reason===`no-writer`?Wm[`no-writer`]:`No invite was made. Try again in a moment.`);if(!F(t.invite.close))return void t.invite.close();Fe(t.invite),x(e=>[...e,t.invite])},Le=t=>B(async()=>await qS(e,pe,t)===`written`?null:qm),Re={change:async(t,n)=>{if(`level`in n&&n.level===`friends`){let e=await Le(e=>Eh(e,t));if(e!==null)return e}let r=await EC(e,t,n);return r.ok?(z(r),ye(),null):Wm[r.reason]},remove:e=>Le(t=>Th(t,e))},ze=J(null),[Be,Ve]=q(!1);hu(()=>{Be&&(ze.current?.focus(),Ve(!1))},[Be]),hu(()=>{f&&(D(`customize`),k(`layout`))},[f]),hu(()=>{(s!==null||l!==void 0)&&D(`friends`)},[s,l]);let He=o()!==null,Ue=m===null||!He?[]:TE(m),We=Ue.filter(({grant:e})=>e.state===`asked`),Ge=Ue.filter(({grant:e})=>e.state!==`asked`),Ke=m===null?[]:zf(m),qe=Ke.find(e=>e.fingerprint===v)??null,Je=J(void 0),Ye=e=>t=>{t!==null&&Je.current===e&&(Je.current=void 0,t.focus())},Xe=e=>{Je.current=e,y(null)},Ze=async()=>{let t=await vC(e);return t.ok&&(Je.current=null,D(`friends`),await ne().then(ye)),t},Qe=e=>{e!==null&&f&&(e.focus(),p())},$e=We.length+(me?.waiting.length??0)+(me?.accepted.length??0),et=Pv(Vu,t.name),tt=m===null?null:xf(m),nt=m===null?`friends`:_f(m).level,rt=m?.profile.avatar?.value??null,it=eh(e.storage,rt,_p.avatar),at=[{id:`overview`,label:`Overview`},{id:`customize`,label:`Customize`},{id:`friends`,label:`Friends`,...Ke.length>0?{badge:Ke.length}:{}},{id:`inbox`,label:`Inbox`,...$e>0?{badge:$e,accentBadge:!0}:{}},...He?[{id:`apps`,label:`Apps`,...Ge.length>0?{badge:Ge.length}:{}}]:[],{id:`account`,label:`Account`}];return Z(`div`,{className:`social-workspace`,"data-social-state":`ready`,children:[Z(`aside`,{className:`social-sidebar`,children:[Z(`div`,{className:`social-sidebar-head`,children:Z(`span`,{className:`social-brand`,children:[Z(Mm,{size:16}),Z(`span`,{children:`FKN Social`})]})}),Z(`div`,{className:`social-sidebar-user`,"data-social-claim":ae??`unknown`,children:[Z(th,{signKey:N.signKey,src:it,url:rt?.url,avatarAlt:`${t.name}'s avatar`,small:!0}),Z(`div`,{children:[Z(`span`,{className:`social-brand-name`,"data-social-name":!0,children:t.name}),Z(`span`,{className:`social-muted`,children:AE[nt]})]})]}),Z(`nav`,{className:`social-nav`,"aria-label":`App pages`,children:at.map(e=>Z(`button`,{type:`button`,className:`social-nav-btn`,"data-social-nav":e.id,"aria-current":E===e.id?`page`:void 0,onClick:()=>D(e.id),children:[Z(`span`,{className:`social-nav-label`,children:[Z(Nm,{id:e.id}),Z(`span`,{children:e.label})]}),e.badge!==void 0&&Z(`span`,{className:e.accentBadge?`social-nav-badge social-nav-badge-accent`:`social-nav-badge`,children:e.badge})]},e.id))})]}),Z(`main`,{className:`social-main`,"data-social-tab":E,children:[i&&Z(`p`,{className:`social-error`,role:`alert`,"data-social-cut-link":!0,children:`This invite link is incomplete. Ask for the link again.`}),Z(gE,{notice:de,page:et}),E!==`account`&&Z(bw,{status:ae??`unknown`,onClaimAgain:xe.claimAgain,onRename:()=>{j(!0),D(`account`)}}),Z(Qm,{children:g}),m===null&&g!==null&&Z(`div`,{className:`social-card-box`,children:[Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:()=>void ne(),children:`Try again`})}),L&&Z(ME,{onReset:Ze})]}),E===`account`&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h1`,{children:`Account`})}),Z(`div`,{className:`social-card-box`,children:Z(Sw,{identity:t,fresh:r,status:ae??`unknown`,actions:xe,avatar:it,avatarUrl:rt?.url,openRename:A,onRenameOpened:()=>j(!1)})})]}),m!==null&&E!==`account`&&Z(K,{children:[E===`overview`&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h1`,{children:`Overview`})}),Z(`div`,{className:`social-overview-grid`,children:[Z(`div`,{className:`social-card-box`,children:[Z(`div`,{className:`social-card`,children:[Z(th,{signKey:N.signKey,src:it,url:rt?.url,avatarAlt:`${t.name}'s avatar`}),Z(`div`,{children:[Z(`div`,{className:`social-name`,style:Xm(tt?.displayName||t.name),children:tt?.displayName||t.name}),tt?.displayName&&tt.displayName!==t.name&&Z(`div`,{className:`social-muted`,children:t.name}),Z(`div`,{className:`social-muted`,children:AE[nt]})]})]}),tt?.bio&&Z(`p`,{className:`social-bio`,children:tt.bio}),Z(ih,{url:et,site:o})]}),Z(`div`,{className:`social-card-box`,children:[Z(`h2`,{children:`Shortcuts`}),Z(`div`,{className:`social-stats-strip`,children:[Z(`div`,{className:`social-stat-cell`,children:[Z(`span`,{className:`social-stat-label`,children:`Friends`}),Z(`strong`,{className:`social-stat-value`,children:Ke.length})]}),Z(`div`,{className:`social-stat-cell`,children:[Z(`span`,{className:`social-stat-label`,children:`Inbox`}),Z(`strong`,{className:`social-stat-value`,children:$e})]})]}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,onClick:()=>D(`customize`),children:`Customize`}),Z(`button`,{type:`button`,onClick:()=>D(`friends`),children:[`Friends (`,Ke.length,`)`]}),$e>0&&Z(`button`,{type:`button`,onClick:()=>D(`inbox`),children:[`Inbox (`,$e,`)`]})]}),me!==null&&me.status!==`ready`&&Z(`p`,{className:`social-warn-text`,children:`Check your inbox status under Inbox.`})]})]})]}),E===`customize`&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h1`,{children:`Customize`})}),Z(`nav`,{className:`social-subtabs`,"aria-label":`Customize sections`,children:[[`general`,`General`],[`panels`,`Panels`],[`layout`,`Page layout`],[`visibility`,`Privacy`]].map(([e,t])=>Z(`button`,{type:`button`,className:`social-subtab`,"data-social-subtab":e,"aria-current":O===e?`page`:void 0,onClick:()=>k(e),children:t},e))}),O===`general`&&Z(`div`,{className:`social-card-box`,children:[Z(`h2`,{children:`Profile`}),Z(mE,{profile:xf(m),onSave:async(t,n)=>{let r=await ip(e,t,n);return r.ok&&(z(r),ye()),r}})]}),O===`panels`&&Z(`div`,{className:`social-card-box`,children:[Z(`h2`,{children:`Custom panels`}),Z(uE,{panels:hm(m),actions:De})]}),O===`layout`&&Z(`div`,{className:`social-card-box`,children:[Z(`h2`,{tabIndex:-1,ref:Qe,"data-social-layout":!0,children:`Page layout`}),Z(GT,{layout:wv(m),onSave:async(t,n)=>{let r=await Nv(e,t,n);return r.ok&&(z(r),ye()),r}})]}),O===`visibility`&&Z(`div`,{className:`social-card-box`,children:[Z(`h2`,{children:`Who sees your profile`}),Z(CE,{visibility:_f(m),page:et,status:ae,pageRoomStatus:se,oldPage:zS(m)!==null,site:o,actions:Ce,pictures:{avatar:(m.profile.avatar?.value??null)!==null,background:(m.profile.background?.value??null)!==null}})]})]}),E===`friends`&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h2`,{tabIndex:-1,ref:Ye(null),children:`Friends`})}),S!==null&&Z(kE,{invite:S,site:o,onDismiss:()=>C(null)}),l!==void 0&&Z(zw,{name:l,own:N.signKey,isFriend:e=>Pe(m)(of(e)),read:Me,send:Ne,onMake:ke,onClose:u},l),b.map(e=>Z(OE,{invite:e,onDismiss:()=>x(t=>t.filter(t=>t!==e))},e.link)),qe===null?Z(`div`,{className:`social-friends-grid`,children:[Z(`div`,{className:`social-card-box`,children:Z(Hw,{friends:Ke,onOpen:y,focusRef:Ye})}),Z(`div`,{className:`social-card-box`,children:[Z(Rw,{onAdd:d}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,"data-new-invite":!0,"aria-disabled":w||b.length>=3,onClick:()=>void Ie(),children:w?`Making a link...`:`Invite a friend`})}),b.length>=3&&Z(`p`,{className:`social-muted`,children:`Close an invite, or press Done, to make another.`})]})]}):Z(`div`,{className:`social-card-box`,children:Z(Kw,{friend:qe,site:o,onBack:()=>Xe(qe.fingerprint),onInvite:async t=>yS(e,Oe(m),qe,t),onNickname:async t=>z(await lp(e,qe.fingerprint,t)),onRemove:async()=>{let t=Ke[Ke.indexOf(qe)+1]?.fingerprint??null,n=z(await up(e,qe.fingerprint));return n.ok&&(Xe(t),ye()),n}},qe.fingerprint)})]}),E===`inbox`&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h1`,{children:`Inbox`})}),Z(`div`,{className:`social-card-box`,children:[Z(lw,{asks:We,actions:Re,onAnswered:()=>{D(`apps`),Ve(!0)}}),Z(Iw,{status:me?.status??null,waiting:me?.waiting??[],accepted:me?.accepted??[],site:o,actions:je,onMake:ke}),We.length===0&&me?.status===`ready`&&me.waiting.length===0&&me.accepted.length===0&&Z(`p`,{className:`social-muted`,children:`Nothing waiting.`})]})]}),E===`apps`&&He&&Z(K,{children:[Z(`div`,{className:`social-main-head`,children:Z(`h2`,{ref:ze,tabIndex:-1,children:`Apps`})}),Z(`div`,{className:`social-card-box`,children:Ge.length>0?Z(fw,{apps:Ge,actions:Re}):Z(`p`,{className:`social-muted`,children:`No connected apps yet.`})})]})]})]})]})},ME=({onReset:e})=>{let[t,n]=q(!1),[r,i]=q(!1),[a,o]=q(null),s=J(null),c=()=>{r||(n(!1),o(null),s.current?.focus())},l=async()=>{if(r)return;i(!0),o(null);let t=await e();i(!1),t.ok||o(t.reason)};return Z(K,{children:[Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,ref:s,"data-social-reset":!0,onClick:()=>n(!0),children:`Reset Social`})}),t&&Z(`div`,{className:`social-warn`,"data-social-reset-ask":!0,children:[Z(`p`,{children:`Your friend list, profile, page layout, favourites and app permissions will be deleted for good.`}),Z(Hm,{reason:a}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-danger`,ref:Zm,"data-social-reset-confirm":!0,"aria-disabled":r,onClick:()=>void l(),children:r?`Resetting...`:`Reset`}),Z(`button`,{type:`button`,"aria-disabled":r,onClick:c,children:`Cancel`})]})]})]})},NE=({title:e,children:t,onRetry:n})=>Z(K,{children:[Z(`h1`,{children:e}),Z(`p`,{children:t}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:n,children:`Try again`})})]}),PE=({services:e,onChanged:t})=>{let[n,r]=q(!1),[i,a]=q(!1),[o,s]=q(null),c=async e=>(e.ok&&await t(),e),l=async()=>{if(i)return;a(!0),s(null);let t=await c(await _C(e));a(!1),t.ok||s(t.reason)};return Z(K,{children:[Z(`h1`,{children:`Your saved identity will not open`}),Z(`p`,{children:`Enter your recovery key to bring it back.`}),Z(gw,{onRestore:async t=>c(await gC(e,t))}),Z(`h2`,{children:`No recovery key?`}),Z(`p`,{className:`social-muted`,children:`You can start over with a new key, which nothing links to the old one.`}),Z(Hm,{reason:o}),Z(`div`,{className:`social-row`,children:n?Z(`button`,{type:`button`,"aria-disabled":i,onClick:()=>void l(),children:`Start over with a new key`}):Z(`button`,{type:`button`,onClick:()=>r(!0),children:`Start over`})})]})},FE=({services:e,canRestore:t,inviteWaiting:n,onPicked:r,onChanged:i})=>{let[a,o]=q(!1);return Z(K,{children:[Z(`h1`,{children:`Pick your name`}),n&&Z(`p`,{className:`social-warn`,"data-social-invite-waiting":!0,children:`Pick your name first, then the invite opens.`}),Z(hw,{label:`Claim name`,onPick:async t=>{let n=await pC(e,t);return n.ok&&await r(),n}}),t&&(a?Z(K,{children:[Z(`h2`,{children:`Restore from a recovery key`}),Z(gw,{onRestore:async t=>{let n=await gC(e,t);return n.ok&&await i(),n}})]}):Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,onClick:()=>o(!0),children:`I have a recovery key`})}))]})},IE=({state:e,props:t,listed:n=null,reload:r,fresh:i,setFresh:a,cutShort:o=!1,staged:s=null,onStagedTaken:c=()=>{},adding:l,onAddDone:u=()=>{},onAdd:d=()=>{},editing:f=!1,onEditDone:p=()=>{}})=>{let{services:m}=t,h=()=>void r();switch(e.kind){case`unreachable`:return Z(NE,{title:`FKN cannot be reached`,onRetry:h,children:`Check your connection, then try again.`});case`signed-out`:return Z(K,{children:[Z(`h1`,{children:`Sign in to FKN`}),Z(`p`,{children:`Sign in to FKN, then come back here.`}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,onClick:h,children:`I signed in`})})]});case`no-keys`:return Z(NE,{title:`Set up encryption first`,onRetry:h,children:`Set up an encryption key in your FKN account, then try again.`});case`locked`:return Z(K,{children:[Z(`h1`,{children:`Unlock your FKN storage`}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,onClick:()=>void t.unlock().then(r),children:`Unlock`})})]});case`reset`:return Z(PE,{services:m,onChanged:r});case`newer`:return Z(NE,{title:`This needs a newer FKN Social`,onRetry:h,children:`Reload the page to update.`});case`no-identity`:return Z(FE,{services:m,canRestore:!0,inviteWaiting:s!==null,onPicked:async()=>{a(!0),await r()},onChanged:r});case`ready`:{let{identity:h}=e;return h.name===null?Z(FE,{services:m,canRestore:!1,inviteWaiting:s!==null,onPicked:async()=>{a(!0),await r()},onChanged:r}):Z(jE,{services:m,identity:{...h,name:h.name},listed:n,fresh:i,cutShort:o,onChanged:r,site:t.site??wE,staged:s,onStagedTaken:c,adding:l,onAddDone:u,onAdd:d,editing:f,onEditDone:p})}}},LE=e=>{let[t,n]=q(null),[r,i]=q(null),[a,o]=q(!1),[s,c]=q(null),[l,u]=q(!1),[d,f]=q(void 0),[p,m]=q(!1),h=vu(()=>m(!1),[]),g=J(0),[_,v]=q(0),y=_u(()=>uC(e.services,()=>g.current===_),[e.services,_]),b=vu(async()=>{let e=null,t=await fC(y,()=>{e=tp(y)});g.current===_&&(i(e),n(t))},[y,_]);hu(()=>{b()},[b]);let{onAccountChange:x,invites:S,adds:C,edits:w}=e;hu(()=>{let e=x(e=>{e?.switched!==!1&&(g.current+=1,v(g.current),n(null),o(!1))});return()=>{e.then(e=>e())}},[x]),hu(()=>S?.(e=>{u(e===null),e!==null&&c(e)}),[S]),hu(()=>C?.(f),[C]),hu(()=>w?.(()=>m(!0)),[w]);let T=t?.kind===`ready`&&t.identity.name!==null;if(hu(()=>{p&&t!==null&&!T&&m(!1)},[p,t,T]),t===null)return Z(Rm,{state:`loading`,label:`Loading...`,error:l?Z(`p`,{className:`social-error`,role:`alert`,"data-social-cut-link":!0,children:`This invite link is incomplete. Ask for the link again.`}):void 0});let E=Z(IE,{state:t,props:{...e,services:y},listed:r,reload:b,fresh:a,setFresh:o,cutShort:l,staged:s,onStagedTaken:()=>c(null),adding:d,onAddDone:()=>f(void 0),onAdd:f,editing:p,onEditDone:h});return T?E:Z(Lm,{children:[l&&Z(`p`,{className:`social-error`,role:`alert`,"data-social-cut-link":!0,children:`This invite link is incomplete. Ask for the link again.`}),Z(`div`,{"data-social-state":t.kind,children:E})]})},{blue:RE}=cv,zE=e=>lv.map(t=>`[data-social-accent="${t}"] { --accent: ${cv[t][e].accent}; --accent-text: ${cv[t][e].text}; }`).join(`
|
|
16
|
+
`),BE=dv.map(e=>{let t=uv[e],n=t.light?pv.light:pv.dark,r=t.light?`#e3e7ef`:t.head,i=t.light?`#d5dbe6`:`color-mix(in srgb, ${t.head} 82%, #ffffff)`,a=t.light?`#9fa8b9`:`color-mix(in srgb, ${t.border} 72%, #ffffff)`,o=t.light?`color-mix(in srgb, ${t.accent} 86%, #000000)`:`color-mix(in srgb, ${t.accent} 86%, #ffffff)`;return`[data-social-theme="${e}"] {
|
|
17
|
+
color-scheme: ${t.light?`light`:`dark`};
|
|
18
|
+
--p-bg: ${t.bg};
|
|
19
|
+
--p-sheet: ${t.sheet};
|
|
20
|
+
--p-panel: ${t.panel};
|
|
21
|
+
--p-head: ${t.head};
|
|
22
|
+
--p-border: ${t.border};
|
|
23
|
+
--p-text: ${t.text};
|
|
24
|
+
--p-muted: ${t.muted};
|
|
25
|
+
--p-accent: ${t.accent};
|
|
26
|
+
--p-accent-text: ${t.accentText};
|
|
27
|
+
--p-pill: ${t.pill};
|
|
28
|
+
--p-sky-top: ${t.skyTop};
|
|
29
|
+
--p-sky-bot: ${t.skyBot};
|
|
30
|
+
--bg: ${t.bg};
|
|
31
|
+
--panel: ${t.panel};
|
|
32
|
+
--panel-2: ${t.head};
|
|
33
|
+
--control: ${r};
|
|
34
|
+
--control-hover: ${i};
|
|
35
|
+
--text: ${t.text};
|
|
36
|
+
--muted: ${t.muted};
|
|
37
|
+
--line: ${t.border};
|
|
38
|
+
--line-strong: ${a};
|
|
39
|
+
--accent: ${t.accent};
|
|
40
|
+
--accent-text: ${t.accentText};
|
|
41
|
+
--btn: ${t.accent};
|
|
42
|
+
--btn-ink: ${t.accentText};
|
|
43
|
+
--btn-hover: ${o};
|
|
44
|
+
--warn-bg: ${n.warnBg};
|
|
45
|
+
--warn-line: ${n.warnLine};
|
|
46
|
+
--error: ${n.error};
|
|
47
|
+
}`}).join(`
|
|
48
|
+
`),VE=`
|
|
49
|
+
:root {
|
|
50
|
+
color-scheme: light dark;
|
|
51
|
+
--bg: #f4f5f7;
|
|
52
|
+
--panel: #ffffff;
|
|
53
|
+
--panel-2: #eceef2;
|
|
54
|
+
--control: #e6e9ef;
|
|
55
|
+
--control-hover: #d8dde6;
|
|
56
|
+
--text: #14161a;
|
|
57
|
+
--muted: #525864;
|
|
58
|
+
--line: #dde0e7;
|
|
59
|
+
--line-strong: #b4bac8;
|
|
60
|
+
--line-ctrl: #767c8a;
|
|
61
|
+
--btn: #14161a;
|
|
62
|
+
--btn-ink: #ffffff;
|
|
63
|
+
--btn-hover: #2b2f38;
|
|
64
|
+
--accent: ${RE.light.accent};
|
|
65
|
+
--accent-text: ${RE.light.text};
|
|
66
|
+
--warn-bg: ${pv.light.warnBg};
|
|
67
|
+
--warn-line: ${pv.light.warnLine};
|
|
68
|
+
--error: ${pv.light.error};
|
|
69
|
+
font: 15px/1.55 system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
|
|
70
|
+
-webkit-font-smoothing: antialiased;
|
|
71
|
+
}
|
|
72
|
+
@media (prefers-color-scheme: dark) {
|
|
73
|
+
:root {
|
|
74
|
+
--bg: #0f1012;
|
|
75
|
+
--panel: #16181c;
|
|
76
|
+
--panel-2: #1d2026;
|
|
77
|
+
--control: #24272f;
|
|
78
|
+
--control-hover: #2f333d;
|
|
79
|
+
--text: #f2f3f5;
|
|
80
|
+
--muted: #989fa9;
|
|
81
|
+
--line: #272a32;
|
|
82
|
+
--line-strong: #3e4350;
|
|
83
|
+
--line-ctrl: #7c8391;
|
|
84
|
+
--btn: #f2f3f5;
|
|
85
|
+
--btn-ink: #0f1012;
|
|
86
|
+
--btn-hover: #d6d9df;
|
|
87
|
+
--accent: ${RE.dark.accent};
|
|
88
|
+
--accent-text: ${RE.dark.text};
|
|
89
|
+
--warn-bg: ${pv.dark.warnBg};
|
|
90
|
+
--warn-line: ${pv.dark.warnLine};
|
|
91
|
+
--error: ${pv.dark.error};
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
${zE(`light`)}
|
|
95
|
+
@media (prefers-color-scheme: dark) {
|
|
96
|
+
${zE(`dark`)}
|
|
97
|
+
}
|
|
98
|
+
${BE}
|
|
99
|
+
${lv.filter(e=>e!==`blue`).map(e=>`[data-social-theme][data-social-accent="${e}"]:not([data-social-theme="daylight"]) { --accent: ${cv[e].dark.accent}; --accent-text: ${cv[e].dark.text}; --btn: ${cv[e].dark.accent}; --btn-ink: ${cv[e].dark.text}; --btn-hover: color-mix(in srgb, ${cv[e].dark.accent} 86%, #ffffff); }`).join(`
|
|
100
|
+
`)}
|
|
101
|
+
${lv.map(e=>`[data-social-theme="daylight"][data-social-accent="${e}"] { --accent: ${cv[e].light.accent}; --accent-text: ${cv[e].light.text}; --btn: ${cv[e].light.accent}; --btn-ink: ${cv[e].light.text}; --btn-hover: color-mix(in srgb, ${cv[e].light.accent} 86%, #000000); }`).join(`
|
|
102
|
+
`)}
|
|
103
|
+
*, *::before, *::after { box-sizing: border-box; }
|
|
104
|
+
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
|
|
105
|
+
.social-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
|
|
106
|
+
.social-ico { flex: none; display: block; }
|
|
107
|
+
|
|
108
|
+
/* Architectural full-viewport loading screen */
|
|
109
|
+
@keyframes social-progress {
|
|
110
|
+
0% { transform: translateX(-100%); }
|
|
111
|
+
50% { transform: translateX(65%); }
|
|
112
|
+
100% { transform: translateX(260%); }
|
|
113
|
+
}
|
|
114
|
+
@keyframes social-shimmer {
|
|
115
|
+
0% { background-position: 100% 0; }
|
|
116
|
+
100% { background-position: -100% 0; }
|
|
117
|
+
}
|
|
118
|
+
.social-loader-stage { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); color: var(--text); }
|
|
119
|
+
.social-loader-box { width: 100%; max-width: 300px; display: grid; justify-items: center; gap: 14px; text-align: center; }
|
|
120
|
+
.social-loader-mark { width: 48px; height: 48px; border: 1px solid var(--line-strong); background: var(--panel); display: grid; place-items: center; color: var(--text); }
|
|
121
|
+
.social-loader-brand { font-size: 0.78rem; font-weight: 700; letter-spacing: 0.14em; text-transform: uppercase; color: var(--text); }
|
|
122
|
+
.social-loader-track { width: 180px; height: 2px; background: var(--line); position: relative; overflow: hidden; display: block; }
|
|
123
|
+
.social-loader-track-sm { width: 72px; }
|
|
124
|
+
.social-loader-bar { position: absolute; top: 0; left: 0; bottom: 0; width: 42%; background: var(--text); animation: social-progress 1.25s cubic-bezier(0.4, 0, 0.2, 1) infinite; }
|
|
125
|
+
.social-loader-status { margin: 0; font-size: 0.8125rem; font-family: ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: 0.04em; color: var(--muted); }
|
|
126
|
+
.social-inline-loader { display: flex; align-items: center; gap: 10px; padding: 6px 0; }
|
|
127
|
+
|
|
128
|
+
/* Centered auth / onboarding card */
|
|
129
|
+
.social-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px 16px; background: var(--bg); }
|
|
130
|
+
.social-panel { width: 100%; max-width: 460px; background: var(--panel); border: 1px solid var(--line-strong); border-radius: 0; padding: 28px 26px; }
|
|
131
|
+
.social-panel-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border: 1px solid var(--line-strong); background: var(--bg); margin-bottom: 16px; color: var(--text); }
|
|
132
|
+
.social-panel h1, .social-main h1 { font-size: 1.45rem; font-weight: 700; letter-spacing: -0.025em; line-height: 1.2; margin: 0 0 8px; }
|
|
133
|
+
.social-panel h2, .social-main h2 { font-size: 0.95rem; font-weight: 650; letter-spacing: -0.01em; margin: 18px 0 8px; }
|
|
134
|
+
.social-panel p, .social-main p { margin: 0 0 12px; }
|
|
135
|
+
.social-muted { color: var(--muted); font-size: 0.875rem; }
|
|
136
|
+
.social-error { color: var(--error); font-size: 0.875rem; margin: 8px 0 0; }
|
|
137
|
+
.social-warn { background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 0; padding: 12px 14px; margin: 12px 0; }
|
|
138
|
+
.social-row { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; align-items: center; }
|
|
139
|
+
|
|
140
|
+
/* Full-viewport multi-page architectural workspace */
|
|
141
|
+
.social-workspace { min-height: 100vh; display: grid; grid-template-columns: minmax(0, 1fr); background: var(--bg); color: var(--text); }
|
|
142
|
+
.social-sidebar { background: var(--panel); border-bottom: 1px solid var(--line); display: grid; gap: 0; align-content: start; }
|
|
143
|
+
.social-sidebar-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
|
|
144
|
+
.social-brand { display: inline-flex; align-items: center; gap: 9px; font-size: 0.8125rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text); }
|
|
145
|
+
.social-sidebar-user { display: flex; align-items: center; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); background: var(--bg); min-width: 0; }
|
|
146
|
+
.social-sidebar-user > div { min-width: 0; flex: 1 1 0; }
|
|
147
|
+
.social-brand-name { font-weight: 650; font-size: 0.9375rem; overflow-wrap: anywhere; display: block; line-height: 1.25; }
|
|
148
|
+
.social-sidebar-user .social-muted { font-size: 0.72rem; letter-spacing: 0.06em; text-transform: uppercase; font-weight: 600; display: block; margin-top: 2px; }
|
|
149
|
+
.social-nav { display: flex; flex-wrap: wrap; gap: 0; }
|
|
150
|
+
.social-nav-btn { appearance: none; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); font: inherit; font-size: 0.875rem; font-weight: 600; padding: 11px 14px; border-radius: 0; cursor: pointer; display: flex; align-items: center; justify-content: space-between; gap: 10px; text-align: left; transition: background-color 120ms ease, color 120ms ease, border-color 120ms ease; }
|
|
151
|
+
.social-nav-btn:hover { background: var(--panel-2); color: var(--text); }
|
|
152
|
+
.social-nav-btn[aria-current="page"] { background: var(--panel-2); border-bottom-color: var(--text); color: var(--text); }
|
|
153
|
+
.social-nav-label { display: inline-flex; align-items: center; gap: 9px; min-width: 0; }
|
|
154
|
+
.social-nav-badge { font: 600 0.72rem/1.4 ui-monospace, 'SF Mono', Menlo, monospace; font-variant-numeric: tabular-nums; padding: 1px 6px; border-radius: 0; background: var(--control); border: 1px solid var(--line-strong); color: var(--text); }
|
|
155
|
+
.social-nav-badge-accent { background: var(--btn); border-color: var(--btn); color: var(--btn-ink); }
|
|
156
|
+
.social-main { padding: 20px 16px 36px; max-width: 900px; width: 100%; margin: 0 auto; display: grid; gap: 18px; align-content: start; }
|
|
157
|
+
.social-main-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 12px; padding-bottom: 12px; border-bottom: 1px solid var(--line); }
|
|
158
|
+
.social-main-head h1, .social-main-head h2 { margin: 0; font-size: 1.45rem; font-weight: 700; letter-spacing: -0.025em; }
|
|
159
|
+
.social-card-box { background: var(--panel); border: 1px solid var(--line); border-radius: 0; padding: 20px; display: grid; gap: 14px; align-content: start; }
|
|
160
|
+
.social-card-box h2:first-child { margin-top: 0; }
|
|
161
|
+
.social-subtabs { display: flex; flex-wrap: wrap; gap: 2px; border-bottom: 1px solid var(--line); }
|
|
162
|
+
.social-subtab { appearance: none; border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px; background: transparent; color: var(--muted); font: inherit; font-size: 0.875rem; font-weight: 600; padding: 9px 14px; border-radius: 0; cursor: pointer; transition: color 120ms ease, background-color 120ms ease, border-color 120ms ease; }
|
|
163
|
+
.social-subtab:hover { color: var(--text); background: var(--panel-2); }
|
|
164
|
+
.social-subtab[aria-current="page"] { border-bottom-color: var(--text); color: var(--text); }
|
|
165
|
+
.social-overview-grid { display: grid; gap: 16px; align-items: start; }
|
|
166
|
+
.social-friends-grid { display: grid; gap: 16px; align-items: start; }
|
|
167
|
+
.social-stats-strip { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); background: var(--bg); }
|
|
168
|
+
.social-stat-cell { padding: 10px 12px; display: grid; gap: 2px; }
|
|
169
|
+
.social-stat-cell + .social-stat-cell { border-left: 1px solid var(--line); }
|
|
170
|
+
.social-stat-label { font-size: 0.72rem; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
|
|
171
|
+
.social-stat-value { font-size: 1.15rem; font-weight: 700; font-variant-numeric: tabular-nums; color: var(--text); }
|
|
172
|
+
|
|
173
|
+
@media (min-width: 840px) {
|
|
174
|
+
.social-workspace { grid-template-columns: 248px minmax(0, 1fr); }
|
|
175
|
+
.social-sidebar { border-bottom: 0; border-right: 1px solid var(--line); position: sticky; top: 0; min-height: 100vh; }
|
|
176
|
+
.social-nav { flex-direction: column; padding: 8px 0; }
|
|
177
|
+
.social-nav-btn { width: 100%; border-bottom: 0; border-left: 2px solid transparent; padding: 10px 16px; }
|
|
178
|
+
.social-nav-btn[aria-current="page"] { border-bottom-color: transparent; border-left-color: var(--text); }
|
|
179
|
+
.social-main { padding: 28px 34px 48px; }
|
|
180
|
+
.social-overview-grid { grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); }
|
|
181
|
+
.social-friends-grid { grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr); }
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
/* Shared controls, sharp architectural buttons, and form primitives */
|
|
185
|
+
.social-card { display: flex; flex-wrap: wrap; align-items: center; gap: 16px; margin-bottom: 8px; container-type: inline-size; }
|
|
186
|
+
.social-card > div { flex: 1 1 0; min-width: 0; max-width: 100%; overflow-wrap: break-word; }
|
|
187
|
+
.social-name { font-size: 1.75rem; font-weight: 700; letter-spacing: -0.025em; }
|
|
188
|
+
.social-panel h1.social-name, .social-page h1.social-name { font-size: 1.75rem; margin: 0; }
|
|
189
|
+
.social-identicon { width: 72px; height: 72px; border-radius: 0; border: 1px solid var(--line); flex: none; display: block; }
|
|
190
|
+
.social-avatar-img { object-fit: cover; background: var(--panel-2); }
|
|
191
|
+
.social-panel input, .social-panel textarea, .social-workspace input, .social-workspace textarea, .social-page input, .social-page textarea {
|
|
192
|
+
width: 100%; font: inherit; padding: 9px 11px; border-radius: 0; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); transition: border-color 120ms ease;
|
|
193
|
+
}
|
|
194
|
+
.social-panel textarea, .social-workspace textarea, .social-page textarea { resize: vertical; }
|
|
195
|
+
.social-panel input:focus-visible, .social-panel textarea:focus-visible, .social-workspace input:focus-visible, .social-workspace textarea:focus-visible, .social-page input:focus-visible, .social-page textarea:focus-visible,
|
|
196
|
+
.social-panel button:focus-visible, .social-workspace button:focus-visible, .social-page button:focus-visible, .social-page a:focus-visible {
|
|
197
|
+
outline: 2px solid var(--btn); outline-offset: 2px;
|
|
198
|
+
}
|
|
199
|
+
.social-page button:focus-visible, .social-page a:focus-visible, .social-page input:focus-visible, .social-page textarea:focus-visible {
|
|
200
|
+
outline-color: var(--accent);
|
|
201
|
+
}
|
|
202
|
+
.social-stack { display: grid; gap: 10px; }
|
|
203
|
+
.social-label { display: grid; gap: 6px; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase; color: var(--muted); }
|
|
204
|
+
.social-label input, .social-label textarea { font-size: 0.9375rem; font-weight: 400; letter-spacing: normal; text-transform: none; }
|
|
205
|
+
.social-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
|
|
206
|
+
.social-bio { white-space: pre-wrap; overflow-wrap: anywhere; }
|
|
207
|
+
.social-link { border: 1px solid var(--line); border-radius: 0; padding: 10px 12px; background: var(--bg); display: grid; gap: 6px; }
|
|
208
|
+
.social-link-bar { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
|
|
209
|
+
.social-link-text { font: 500 0.85rem/1.4 ui-monospace, 'SF Mono', Menlo, monospace; overflow-wrap: anywhere; color: var(--text); }
|
|
210
|
+
.social-link-actions { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
|
|
211
|
+
.social-invite { border: 1px solid var(--line-strong); border-radius: 0; padding: 16px; margin: 8px 0; display: grid; gap: 10px; background: var(--bg); }
|
|
212
|
+
.social-invite h2 { margin-top: 0; }
|
|
213
|
+
.social-qr { width: 180px; height: 180px; border-radius: 0; border: 1px solid var(--line); display: block; }
|
|
214
|
+
.social-warn-text { color: var(--text); background: var(--warn-bg); border: 1px solid var(--warn-line); border-radius: 0; padding: 8px 12px; font-size: 0.875rem; }
|
|
215
|
+
|
|
216
|
+
/* Uniform button hierarchy without selector specificity inflation */
|
|
217
|
+
.social-panel button:not(.social-person):not(.social-primary):not([aria-pressed="true"]):not(.social-danger),
|
|
218
|
+
.social-workspace button:not(.social-nav-btn):not(.social-subtab):not(.social-person):not(.social-primary):not([aria-pressed="true"]):not(.social-danger),
|
|
219
|
+
.social-page button:not(.social-primary):not([aria-pressed="true"]):not(.social-danger) {
|
|
220
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
|
221
|
+
font: inherit; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em;
|
|
222
|
+
min-height: 36px; padding: 7px 14px; border-radius: 0;
|
|
223
|
+
border: 1px solid var(--line-strong); background: var(--control); color: var(--text);
|
|
224
|
+
cursor: pointer; transition: background-color 120ms ease, border-color 120ms ease, color 120ms ease;
|
|
225
|
+
}
|
|
226
|
+
.social-panel button:not(.social-person):not(.social-primary):not([aria-pressed="true"]):not(.social-danger):hover:not([aria-disabled="true"]),
|
|
227
|
+
.social-workspace button:not(.social-nav-btn):not(.social-subtab):not(.social-person):not(.social-primary):not([aria-pressed="true"]):not(.social-danger):hover:not([aria-disabled="true"]),
|
|
228
|
+
.social-page button:not(.social-primary):not([aria-pressed="true"]):not(.social-danger):hover:not([aria-disabled="true"]) {
|
|
229
|
+
background: var(--control-hover); border-color: var(--muted);
|
|
230
|
+
}
|
|
231
|
+
.social-panel button.social-person, .social-workspace button.social-person {
|
|
232
|
+
width: 100%; display: flex; align-items: center; gap: 12px; text-align: left;
|
|
233
|
+
padding: 10px 12px; border-radius: 0; border: 1px solid var(--line);
|
|
234
|
+
background: var(--bg); color: var(--text); font: inherit; font-weight: 400; cursor: pointer;
|
|
235
|
+
overflow-wrap: anywhere; transition: background-color 120ms ease, border-color 120ms ease;
|
|
236
|
+
}
|
|
237
|
+
.social-panel button.social-person:hover, .social-workspace button.social-person:hover {
|
|
238
|
+
background: var(--panel-2); border-color: var(--line-strong);
|
|
239
|
+
}
|
|
240
|
+
.social-person-name { font-weight: 650; overflow-wrap: anywhere; }
|
|
241
|
+
.social-identicon-small { width: 36px; height: 36px; border-radius: 0; }
|
|
242
|
+
.social-panel button.social-primary, .social-panel button[aria-pressed="true"],
|
|
243
|
+
.social-workspace button.social-primary, .social-workspace button[aria-pressed="true"],
|
|
244
|
+
.social-page button.social-primary, .social-page button[aria-pressed="true"] {
|
|
245
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
|
246
|
+
font: inherit; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em;
|
|
247
|
+
min-height: 36px; padding: 7px 15px; border-radius: 0; cursor: pointer;
|
|
248
|
+
background: var(--btn); border: 1px solid var(--btn); color: var(--btn-ink);
|
|
249
|
+
transition: background-color 120ms ease, border-color 120ms ease;
|
|
250
|
+
}
|
|
251
|
+
.social-panel button.social-primary:hover:not([aria-disabled="true"]), .social-panel button[aria-pressed="true"]:hover:not([aria-disabled="true"]),
|
|
252
|
+
.social-workspace button.social-primary:hover:not([aria-disabled="true"]), .social-workspace button[aria-pressed="true"]:hover:not([aria-disabled="true"]),
|
|
253
|
+
.social-page button.social-primary:hover:not([aria-disabled="true"]), .social-page button[aria-pressed="true"]:hover:not([aria-disabled="true"]) {
|
|
254
|
+
background: var(--btn-hover); border-color: var(--btn-hover);
|
|
255
|
+
}
|
|
256
|
+
.social-panel button.social-danger, .social-workspace button.social-danger, .social-page button.social-danger {
|
|
257
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
|
258
|
+
font: inherit; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em;
|
|
259
|
+
min-height: 36px; padding: 7px 14px; border-radius: 0; cursor: pointer;
|
|
260
|
+
background: transparent; border: 1px solid var(--error); color: var(--error);
|
|
261
|
+
}
|
|
262
|
+
.social-panel button.social-danger:hover:not([aria-disabled="true"]),
|
|
263
|
+
.social-workspace button.social-danger:hover:not([aria-disabled="true"]),
|
|
264
|
+
.social-page button.social-danger:hover:not([aria-disabled="true"]) {
|
|
265
|
+
background: color-mix(in srgb, var(--error) 12%, transparent);
|
|
266
|
+
}
|
|
267
|
+
.social-panel [aria-disabled="true"], .social-workspace [aria-disabled="true"], .social-page [aria-disabled="true"] { opacity: 0.45; cursor: default; }
|
|
268
|
+
.social-panel a.social-action, .social-page a.social-action {
|
|
269
|
+
display: inline-flex; align-items: center; justify-content: center; gap: 7px;
|
|
270
|
+
font: inherit; font-size: 0.8125rem; font-weight: 600; letter-spacing: 0.02em;
|
|
271
|
+
min-height: 36px; padding: 7px 16px; border-radius: 0; text-decoration: none;
|
|
272
|
+
background: var(--btn); border: 1px solid var(--btn); color: var(--btn-ink);
|
|
273
|
+
}
|
|
274
|
+
.social-panel a.social-action:hover, .social-page a.social-action:hover { background: var(--btn-hover); border-color: var(--btn-hover); }
|
|
275
|
+
.social-key { display: block; font: 0.9rem/1.6 ui-monospace, 'SF Mono', Menlo, monospace; background: var(--bg); border: 1px solid var(--line-strong); border-radius: 0; padding: 10px 12px; overflow-wrap: anywhere; user-select: all; }
|
|
276
|
+
.social-panel input[type="file"], .social-workspace input[type="file"] { padding: 6px; font-size: 0.85rem; }
|
|
277
|
+
.social-panel input[type="file"]::file-selector-button, .social-workspace input[type="file"]::file-selector-button {
|
|
278
|
+
font: inherit; font-size: 0.8rem; font-weight: 600; padding: 5px 12px; margin-right: 10px;
|
|
279
|
+
border-radius: 0; border: 1px solid var(--line-strong); background: var(--control); color: var(--text); cursor: pointer;
|
|
280
|
+
}
|
|
281
|
+
|
|
282
|
+
/* Sharp tiles, segmented radio controls, checkboxes, and reorderable sections */
|
|
283
|
+
.social-swatch-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(126px, 1fr)); gap: 8px; }
|
|
284
|
+
.social-swatch { width: 18px; height: 18px; border-radius: 0; background: var(--accent); border: 1px solid var(--line-strong); flex: none; }
|
|
285
|
+
.social-choice { display: flex; gap: 9px; align-items: center; font-size: 0.875rem; cursor: pointer; }
|
|
286
|
+
.social-panel .social-choice input, .social-workspace .social-choice input { width: auto; flex: none; }
|
|
287
|
+
.social-choice-label { font-weight: 600; }
|
|
288
|
+
.social-tile { position: relative; padding: 9px 11px; border: 1px solid var(--line); background: var(--bg); transition: border-color 120ms ease, background-color 120ms ease; }
|
|
289
|
+
.social-tile:hover { border-color: var(--line-strong); background: var(--panel-2); }
|
|
290
|
+
.social-tile input { appearance: none; border-radius: 0; position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
|
|
291
|
+
.social-tile:has(input:checked) { border-color: var(--text); background: var(--control); box-shadow: inset 0 -2px 0 var(--text); }
|
|
292
|
+
.social-tile:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; position: relative; z-index: 1; }
|
|
293
|
+
.social-seg { display: inline-flex; flex-wrap: nowrap; border: 1px solid var(--line-strong); background: var(--bg); width: fit-content; max-width: 100%; }
|
|
294
|
+
.social-seg .social-choice { position: relative; gap: 0; padding: 6px 13px; border-right: 1px solid var(--line); font-size: 0.8125rem; color: var(--muted); transition: background-color 120ms ease, color 120ms ease; }
|
|
295
|
+
.social-seg .social-choice:last-child { border-right: 0; }
|
|
296
|
+
.social-seg .social-choice:hover { background: var(--panel-2); color: var(--text); }
|
|
297
|
+
.social-seg input { appearance: none; border-radius: 0; position: absolute; opacity: 0; width: 1px; height: 1px; margin: 0; pointer-events: none; }
|
|
298
|
+
.social-seg .social-choice:has(input:checked) { background: var(--btn); color: var(--btn-ink); }
|
|
299
|
+
.social-seg .social-choice:has(input:focus-visible) { outline: 2px solid var(--text); outline-offset: 2px; position: relative; z-index: 1; }
|
|
300
|
+
.social-checks { display: flex; flex-wrap: wrap; gap: 8px; }
|
|
301
|
+
.social-checks .social-choice { border: 1px solid var(--line); background: var(--bg); padding: 6px 11px; }
|
|
302
|
+
.social-checks .social-choice:has(input:checked) { border-color: var(--text); background: var(--control); }
|
|
303
|
+
.social-checks .social-choice input { appearance: none; position: relative; flex: none; width: 14px; height: 14px; padding: 0; margin: 0; border-radius: 0; border: 1px solid var(--line-ctrl); background: var(--panel); cursor: pointer; }
|
|
304
|
+
.social-checks .social-choice input:checked { background: var(--btn); border-color: var(--btn); }
|
|
305
|
+
.social-checks .social-choice input:checked::after { content: ''; position: absolute; left: 4px; top: 1px; width: 4px; height: 8px; border: solid var(--btn-ink); border-width: 0 2px 2px 0; transform: rotate(45deg); }
|
|
306
|
+
.social-section { border: 1px solid var(--line); border-radius: 0; padding: 12px 14px; background: var(--bg); display: grid; gap: 10px; }
|
|
307
|
+
.social-section-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; }
|
|
308
|
+
.social-section-moves { display: flex; gap: 6px; flex-wrap: wrap; }
|
|
309
|
+
.social-section .social-row { margin-top: 6px; }
|
|
310
|
+
.social-panel-bar { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
|
|
311
|
+
.social-panel-bar p { flex: 1 1 240px; margin: 0; }
|
|
312
|
+
.social-panel-count { font: 600 0.78rem/1.4 ui-monospace, 'SF Mono', Menlo, monospace; font-variant-numeric: tabular-nums; padding: 2px 8px; border: 1px solid var(--line-strong); background: var(--bg); color: var(--text); flex: none; }
|
|
313
|
+
.social-panel-head-title { display: inline-flex; align-items: center; gap: 8px; min-width: 0; }
|
|
314
|
+
.social-panel-tag { font: 700 0.7rem/1.3 ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: 0.06em; text-transform: uppercase; padding: 2px 6px; border: 1px solid var(--line-strong); background: var(--panel); color: var(--muted); flex: none; }
|
|
315
|
+
.social-md-preview { border: 1px solid var(--line); background: var(--panel); padding: 12px 14px; min-height: 76px; }
|
|
316
|
+
.social-art-list { display: grid; gap: 8px; }
|
|
317
|
+
.social-art-row { border: 1px solid var(--line); background: var(--panel); padding: 10px 12px; display: grid; gap: 8px; }
|
|
318
|
+
.social-art-row-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
|
|
319
|
+
|
|
320
|
+
/* only measured: fkn.app's broker draws the package frame over this rect, in its own frame */
|
|
321
|
+
.social-frame { position: fixed; inset: 0; pointer-events: none; }
|
|
322
|
+
|
|
323
|
+
/* Steam-inspired architectural /<name> profile layout */
|
|
324
|
+
.social-page { position: relative; min-height: 100vh; background: radial-gradient(ellipse 90% 420px at 50% 0%, var(--p-sky-top, var(--bg)), transparent 72%), linear-gradient(180deg, var(--p-sky-top, var(--bg)) 0%, var(--p-sky-bot, var(--bg)) 320px, var(--p-bg, var(--bg)) 100%); color: var(--p-text, var(--text)); display: grid; grid-template-rows: auto 1fr; }
|
|
325
|
+
.social-topbar { position: relative; z-index: 2; display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 44px; padding: 10px 20px; background: color-mix(in srgb, var(--p-bg, var(--bg)) 88%, var(--p-head, var(--panel))); border-bottom: 1px solid var(--p-border, var(--line)); }
|
|
326
|
+
.social-topbar-brand { display: inline-flex; align-items: center; gap: 8px; color: var(--p-text, var(--text)); text-decoration: none; font-weight: 700; font-size: 0.8125rem; letter-spacing: 0.08em; text-transform: uppercase; }
|
|
327
|
+
.social-backdrop { position: relative; z-index: 1; padding: 26px 16px 48px; }
|
|
328
|
+
.social-page-background { position: fixed; inset: 0; z-index: 0; background-size: cover; background-position: center; opacity: 0.36; pointer-events: none; -webkit-mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.45) 60%, transparent 100%); mask-image: linear-gradient(180deg, rgba(0, 0, 0, 0.92) 0%, rgba(0, 0, 0, 0.45) 60%, transparent 100%); }
|
|
329
|
+
.social-profile-sheet { position: relative; z-index: 1; width: 100%; max-width: 980px; margin: 0 auto; background: color-mix(in srgb, var(--p-sheet, var(--panel)) 94%, transparent); border: 1px solid var(--p-border, var(--line)); border-radius: 0; padding: 24px; display: grid; gap: 20px; box-shadow: 0 24px 60px rgba(0, 0, 0, 0.42); }
|
|
330
|
+
[data-social-theme="daylight"] .social-profile-sheet { box-shadow: 0 12px 32px rgba(15, 20, 30, 0.10); }
|
|
331
|
+
.social-hero { display: flex; flex-wrap: wrap; align-items: flex-start; justify-content: space-between; gap: 18px; margin: -24px -24px 0; padding: 24px; background: linear-gradient(180deg, color-mix(in srgb, var(--p-head, var(--panel-2)) 52%, transparent) 0%, transparent 100%); border-bottom: 1px solid var(--p-border, var(--line)); }
|
|
332
|
+
.social-hero .social-card { flex: 1 1 320px; margin-bottom: 0; }
|
|
333
|
+
.social-hero-side { display: grid; gap: 10px; justify-items: start; }
|
|
334
|
+
.social-hero-counts { display: flex; flex-wrap: wrap; gap: 0; border: 1px solid var(--p-border, var(--line)); background: var(--p-panel, var(--panel)); font-size: 0.8rem; font-variant-numeric: tabular-nums; color: var(--muted); }
|
|
335
|
+
.social-hero-counts > span { padding: 5px 10px; border-right: 1px solid var(--p-border, var(--line)); }
|
|
336
|
+
.social-hero-counts > span:last-child { border-right: 0; }
|
|
337
|
+
.social-hero-counts strong { color: var(--text); }
|
|
338
|
+
.social-avatar { width: 84px; height: 84px; border-radius: 0; border: 2px solid var(--accent); flex: none; object-fit: cover; background: var(--p-head, var(--panel-2)); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35); display: block; }
|
|
339
|
+
.social-hero .social-identicon { width: 84px; height: 84px; border-radius: 0; border: 2px solid var(--accent); box-shadow: 0 8px 22px rgba(0, 0, 0, 0.35); }
|
|
340
|
+
[data-social-private], [data-social-friends-only] { display: inline-block; margin-top: 6px; padding: 2px 7px; border: 1px solid var(--p-border, var(--line)); background: var(--p-panel, var(--panel)); font-size: 0.72rem; font-weight: 650; letter-spacing: 0.06em; text-transform: uppercase; }
|
|
341
|
+
.social-preview { width: 100%; max-height: 220px; border-radius: 0; border: 1px solid var(--p-border, var(--line)); object-fit: cover; display: block; }
|
|
342
|
+
.social-page-link { color: var(--accent); overflow-wrap: anywhere; text-decoration: none; }
|
|
343
|
+
.social-page-link:hover { text-decoration: underline; }
|
|
344
|
+
.social-steam-body { display: grid; gap: 18px; align-items: start; }
|
|
345
|
+
.social-page-main { display: grid; gap: 16px; min-width: 0; }
|
|
346
|
+
.social-page-rail { display: grid; gap: 16px; min-width: 0; }
|
|
347
|
+
.social-showcase { background: var(--p-panel, var(--panel)); border: 1px solid var(--p-border, var(--line)); border-radius: 0; }
|
|
348
|
+
.social-showcase-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 9px 14px; background: linear-gradient(90deg, var(--p-head, var(--panel-2)) 0%, color-mix(in srgb, var(--p-head, var(--panel-2)) 25%, var(--p-panel, var(--panel))) 100%); border-bottom: 1px solid var(--p-border, var(--line)); }
|
|
349
|
+
.social-showcase-head h2 { margin: 0; font-size: 0.78rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--p-text, var(--text)); }
|
|
350
|
+
.social-panel-badge { font: 700 0.68rem/1.3 ui-monospace, 'SF Mono', Menlo, monospace; letter-spacing: 0.06em; text-transform: uppercase; padding: 1px 6px; border: 1px solid var(--p-border, var(--line)); background: var(--p-panel, var(--panel)); color: var(--p-muted, var(--muted)); flex: none; }
|
|
351
|
+
.social-showcase-body { padding: 14px; display: grid; gap: 10px; }
|
|
352
|
+
.social-showcase-body p { margin: 0; }
|
|
353
|
+
.social-md { display: grid; gap: 10px; overflow-wrap: anywhere; }
|
|
354
|
+
.social-md h3, .social-md h4, .social-md h5 { margin: 2px 0 0; line-height: 1.3; font-weight: 700; color: var(--p-text, var(--text)); }
|
|
355
|
+
.social-md h3 { font-size: 1.05rem; }
|
|
356
|
+
.social-md h4 { font-size: 0.95rem; }
|
|
357
|
+
.social-md h5 { font-size: 0.875rem; color: var(--p-muted, var(--muted)); }
|
|
358
|
+
.social-md ul { margin: 0; padding-left: 18px; display: grid; gap: 4px; }
|
|
359
|
+
.social-md code { font: 0.85em/1.4 ui-monospace, 'SF Mono', Menlo, monospace; padding: 1px 5px; border: 1px solid var(--p-border, var(--line)); background: var(--p-bg, var(--bg)); }
|
|
360
|
+
.social-artwork-grid { display: grid; gap: 10px; grid-template-columns: minmax(0, 1fr); }
|
|
361
|
+
.social-artwork-tile { margin: 0; border: 1px solid var(--p-border, var(--line)); background: var(--p-bg, var(--bg)); display: grid; grid-template-rows: minmax(0, 1fr) auto; overflow: hidden; }
|
|
362
|
+
.social-artwork-tile img { width: 100%; display: block; object-fit: cover; max-height: 440px; }
|
|
363
|
+
.social-artwork-grid[data-social-artwork-count="1"] .social-artwork-tile img { object-fit: contain; height: auto; }
|
|
364
|
+
.social-artwork-grid[data-social-artwork-count="2"] .social-artwork-tile img,
|
|
365
|
+
.social-artwork-grid[data-social-artwork-count="4"] .social-artwork-tile img { aspect-ratio: 4 / 3; height: 100%; }
|
|
366
|
+
.social-artwork-skel { width: 100%; aspect-ratio: 4 / 3; min-height: 140px; }
|
|
367
|
+
.social-artwork-missing { padding: 28px 12px; text-align: center; font-size: 0.8125rem; color: var(--p-muted, var(--muted)); }
|
|
368
|
+
.social-artwork-caption { padding: 7px 10px; font-size: 0.8125rem; color: var(--p-muted, var(--muted)); border-top: 1px solid var(--p-border, var(--line)); background: var(--p-panel, var(--panel)); overflow-wrap: anywhere; }
|
|
369
|
+
@media (min-width: 560px) {
|
|
370
|
+
.social-artwork-grid[data-social-artwork-count="2"],
|
|
371
|
+
.social-artwork-grid[data-social-artwork-count="4"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
|
|
372
|
+
.social-artwork-grid[data-social-artwork-count="3"] { grid-template-columns: 1.55fr 1fr; }
|
|
373
|
+
.social-artwork-grid[data-social-artwork-count="3"] .social-artwork-tile:first-child { grid-row: span 2; }
|
|
374
|
+
.social-artwork-grid[data-social-artwork-count="3"] .social-artwork-tile:first-child img { height: 100%; min-height: 220px; }
|
|
375
|
+
.social-artwork-grid[data-social-artwork-count="3"] .social-artwork-tile:not(:first-child) img { aspect-ratio: 4 / 3; height: 100%; }
|
|
376
|
+
}
|
|
377
|
+
.social-rail-links { list-style: none; margin: -14px; padding: 0; display: grid; gap: 0; }
|
|
378
|
+
.social-rail-links li + li { border-top: 1px solid var(--p-border, var(--line)); }
|
|
379
|
+
.social-rail-links a { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 14px; background: transparent; font-size: 0.85rem; transition: background-color 120ms ease; }
|
|
380
|
+
.social-rail-links a:hover { background: var(--p-sheet, var(--panel)); text-decoration: underline; }
|
|
381
|
+
.social-rail-links a:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; position: relative; z-index: 1; }
|
|
382
|
+
.social-rail-url { min-width: 0; overflow-wrap: anywhere; }
|
|
383
|
+
|
|
384
|
+
@media (min-width: 840px) {
|
|
385
|
+
.social-avatar, .social-hero .social-identicon { width: 120px; height: 120px; }
|
|
386
|
+
.social-hero-side { justify-items: end; text-align: right; }
|
|
387
|
+
.social-steam-body.social-steam-split { grid-template-columns: minmax(0, 1fr) 264px; }
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
.social-entries { gap: 12px; }
|
|
391
|
+
.social-entries li + li { padding-top: 12px; border-top: 1px solid var(--p-border, var(--line)); }
|
|
392
|
+
.social-entry { display: flex; gap: 12px; align-items: flex-start; }
|
|
393
|
+
.social-entry-art { width: 48px; height: 48px; border-radius: 0; border: 1px solid var(--p-border, var(--line)); object-fit: cover; flex: none; display: block; }
|
|
394
|
+
.social-entry-text { flex: 1 1 0; min-width: 0; overflow-wrap: anywhere; }
|
|
395
|
+
.social-entry-text .social-row { margin-top: 6px; }
|
|
396
|
+
.social-favourites { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 12px; }
|
|
397
|
+
.social-favourite { display: grid; gap: 6px; align-content: start; overflow-wrap: anywhere; font-size: 0.875rem; }
|
|
398
|
+
.social-favourite img { width: 100%; aspect-ratio: 3 / 4; border-radius: 0; object-fit: cover; border: 1px solid var(--p-border, var(--line)); display: block; transition: border-color 120ms ease; }
|
|
399
|
+
.social-favourite a:hover, .social-favourite:hover img { border-color: var(--accent); }
|
|
400
|
+
|
|
401
|
+
/* Profile loading skeleton and avatar placeholder */
|
|
402
|
+
.social-skel, [data-social-avatar-reading] {
|
|
403
|
+
display: block;
|
|
404
|
+
background: linear-gradient(90deg, var(--p-head, var(--panel-2)) 25%, color-mix(in srgb, var(--p-border, var(--line)) 70%, var(--p-head, var(--panel-2))) 50%, var(--p-head, var(--panel-2)) 75%);
|
|
405
|
+
background-size: 200% 100%;
|
|
406
|
+
animation: social-shimmer 1.4s ease-in-out infinite;
|
|
407
|
+
}
|
|
408
|
+
.social-skeleton-hero .social-card { align-items: center; }
|
|
409
|
+
.social-skeleton-lines { display: grid; gap: 10px; min-width: 160px; }
|
|
410
|
+
.social-skel-avatar { width: 84px; height: 84px; border: 1px solid var(--p-border, var(--line)); flex: none; }
|
|
411
|
+
.social-skel-title { width: 180px; height: 22px; }
|
|
412
|
+
.social-skel-sub { width: 110px; height: 14px; }
|
|
413
|
+
.social-skel-btn { width: 126px; height: 34px; }
|
|
414
|
+
.social-skel-meta { width: 156px; height: 14px; }
|
|
415
|
+
.social-skel-head { width: 92px; height: 11px; }
|
|
416
|
+
.social-skel-line { width: 100%; height: 14px; }
|
|
417
|
+
.social-skel-short { width: 68%; }
|
|
418
|
+
.social-skel-row { width: 100%; height: 28px; }
|
|
419
|
+
.social-skeleton-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
|
|
420
|
+
.social-skel-tile { width: 100%; aspect-ratio: 3 / 4; }
|
|
421
|
+
@media (min-width: 840px) {
|
|
422
|
+
.social-skel-avatar { width: 120px; height: 120px; }
|
|
423
|
+
}
|
|
424
|
+
|
|
425
|
+
@media (prefers-reduced-motion: reduce) {
|
|
426
|
+
*, *::before, *::after { animation: none !important; transition: none !important; }
|
|
427
|
+
.social-loader-bar { left: 29%; width: 42%; transform: none; }
|
|
428
|
+
}
|
|
429
|
+
`,HE=()=>{let e=document.createElement(`style`);e.textContent=VE,document.head.append(e)},UE=(e,t)=>Object.assign(Error(t),{code:e}),WE=e=>2<e.min?{usable:!1,reason:`outdated`}:{usable:!0,level:Math.min(2,e.protocol)},GE=(e,t)=>e.usable&&e.level>=t,KE={available:1,me:1,attach:1,friends:1,openInvite:1,openAdd:1,publishing:2,allowPublishing:2,publish:2,stopPublishing:2,findByHandle:3,beFindable:3},qE=e=>{try{let t=JSON.parse(e);if(typeof t!=`object`||!t)return!1;let n=t.t;return typeof n==`string`&&n.startsWith(`social.`)}catch{return!1}},JE=(e,t)=>({memberId:e,status:`silent`,identity:null,self:e===t}),YE=e=>{let t=new Set([e]),n=new Set;return{participants:()=>[...t].sort().map(t=>JE(t,e)),of:t=>JE(t,e),on:e=>(n.add(e),()=>n.delete(e)),ingest:()=>!1,memberJoined:e=>{t.add(e)},memberLeft:e=>{t.delete(e)},announce:async()=>{},detach:async()=>{}}},XE=e=>{let t=null,n=null,r=null,i=async()=>{if(r!==null&&r!==`ready`)return r;if(t!==null&&n?.usable===!0)return r??`ready`;try{let i=await e(),a=WE(await i.hello());return a.usable?(t=i,n=a,r=await i.state(),r):(r=`outdated`,r)}catch{return r=`unavailable`,r}},a=async()=>i(),o=async e=>{if(await i()!==`ready`||t===null||n===null||!GE(n,KE.attach))return YE(e.selfMemberId);try{let n=await t.attach({roomId:e.roomId,selfMemberId:e.selfMemberId,observe:e.observe}),r=[],i=new Set,a=async()=>{r=await n.participants();for(let e of i)e(r)};return a(),{participants:()=>r,of:t=>r.find(e=>e.memberId===t)??JE(t,e.selfMemberId),on:e=>(i.add(e),()=>i.delete(e)),ingest:(e,t,r,i)=>qE(t)?(n.ingest(e,t,r,i).then(a,()=>{}),!0):!1,memberJoined:e=>{n.memberJoined(e).then(a,()=>{})},memberLeft:e=>{n.memberLeft(e).then(a,()=>{})},announce:()=>n.announce(),detach:()=>n.detach()}}catch{return YE(e.selfMemberId)}},s=e=>UE(`unsupported`,`social: ${e} needs a newer social package than this one`);return{available:a,attach:o,findByHandle:async()=>{throw await i(),s(`handle search`)}}},ZE=({connect:e,install:t})=>{let n=null,r=()=>{let t=n??=(async()=>{let t=await e();if(t===null)return`none`;let n=WE(await t.hello());return n.usable?GE(n,KE.publish)?{hub:t}:{refused:`unsupported`}:{refused:`outdated`}})();return t.then(e=>{e===`none`&&n===t&&(n=null)},()=>{n===t&&(n=null)}),t},i=async(e,i,a,o=!1)=>{try{let n=await r();if(n===`none`&&o){if(!await t())return i(`unavailable`);n=await r()}return n===`none`?o?i(`unavailable`):e:`refused`in n?i(n.refused):await a(n.hub)}catch{return n=null,i(`unavailable`)}},a={state:`off`},o=e=>({state:e});return{publishing:()=>i(a,o,e=>e.publishing()),allowPublishing:e=>i(a,o,t=>t.allowPublishing(e),!0),publish:e=>i({ok:!1,reason:`not-allowed`},e=>({ok:!1,reason:e}),t=>t.publish(e)),stopPublishing:()=>i(a,o,e=>e.stopPublishing())}},QE=`https:social.fkn.app`,$E=`social@1`,eD=(e=QE,t)=>async()=>{let n=await Zs(e,{noConfirm:!0});if(n===null)throw UE(`unavailable`,`social: the package was not installed`);let{remote:r}=await sc(n.uri,{protocol:$E,payload:t});return r},tD=(e=QE)=>({connect:async()=>{try{let{remote:t}=await sc(e,{protocol:$E});return t}catch(e){if(e?.code===`not-installed`)return null;throw e}},install:async()=>await Zs(e,{noConfirm:!0})!==null});({...XE(eD()),...ZE(tD())});var nD={ok:!1,reason:`none`},rD=(e,t)=>e.length===t.length&&e.every((e,n)=>e===t[n]),iD=e=>{if(typeof e!=`object`||!e)return!1;let{roomId:t,owner:n,text:r}=e;return typeof t==`string`&&typeof n==`string`&&typeof r==`string`},aD=e=>iD(e)&&typeof e.name==`string`&&(e.core===void 0||iD(e.core)),oD=e=>e===null?nD:{ok:!0,...e},sD=e=>{let t=rx(e.text,e.roomId,e.owner,e.name);if(t!==null)return t;if(e.core===void 0)return null;let n=rx(e.core.text,e.core.roomId,e.core.owner,e.name);if(n?.pageRoom===void 0||ty(n.pageRoom)!==e.roomId)return null;let r=cx(e.text,e.roomId,e.owner);return r!==null&&rD(r.signKey,n.signKey)?r:null},cD=async(e,t,n)=>{let r=sD(n);if(r?.friends==null)return nD;let i=await t();if(i.kind!==`ready`)return nD;let a=sv(i.identity.seed),o={roomId:n.roomId,owner:n.owner};if(rD(r.signKey,a.signKey))return oD(Ub(a,o,r.friends));let s=await tp(e),c=s.ok?s.roster.friends[of(r.signKey)]?.value:void 0,l=c?.state===`active`?X(c.dhKey):null;return l?.length===32?oD(Wb(a,l,o,r.friends)):nD},lD=e=>{let t=null,n=()=>t??=fC(e);return{own:async()=>{let e=await n();return e.kind===`ready`?sv(e.identity.seed).signKey:null},friends:t=>cD(e,n,t)}},uD=100,dD=e=>Array.isArray(e)&&e.length>0&&e.length<=uD&&e.every(e=>typeof e==`string`)?e:null,fD=[`not-friend`,`invalid`,`closed`,`full`],pD=e=>fD.includes(e),mD=e=>{let t=async()=>{let t=await fC(e);return t.kind===`ready`?t.identity.name===null?`none`:{keys:sv(t.identity.seed),name:t.identity.name}:`unavailable`},n=async e=>{let n=await t();return typeof n==`string`||n.name===e?n:`none`};return{deleteEntries:async t=>{let{name:r,ids:i}=t??{},a=dD(i);if(a===null)return{ok:!1,reason:`none`};let o=await n(r);return typeof o==`string`?{ok:!1,reason:o}:await qS(e,o,e=>wh(e,a))===`written`?{ok:!0}:{ok:!1,reason:`unavailable`}},deleteComments:async t=>{let{name:r,ids:i}=t??{},a=dD(i);if(a===null)return{ok:!1,reason:`none`};let o=await n(r);return typeof o==`string`?{ok:!1,reason:o}:await qS(e,o,e=>qv(e,a))===`written`?{ok:!0}:{ok:!1,reason:`unavailable`}},sendComment:async n=>{let{name:r,text:i}=n??{};if(typeof r!=`string`||!af(r))return{ok:!1,reason:`not-friend`};let a=await t();if(typeof a==`string`)return{ok:!1,reason:a};let o=await xS(e,a,r,i);return o.ok?o:{ok:!1,reason:pD(o.reason)?o.reason:`unavailable`}},setFavourite:async t=>{let{name:r,favourite:i,on:a}=t??{};if(typeof a!=`boolean`)return{ok:!1,reason:`none`};let o=await n(r);if(typeof o==`string`)return{ok:!1,reason:o};let s=await Qv(e,i,a);return s.ok?await qS(e,o,e=>e)===`written`?{ok:!0}:{ok:!1,reason:`unavailable`}:{ok:!1,reason:s.reason===`full`?`full`:s.reason===`invalid`?`none`:`unavailable`}}}},hD=e=>e.brokered===!0&&e.from===Vu,gD=e=>e.brokered===!0&&mh(e.from)?e.from:null,_D={state:`not-here`},vD=async(e,t,n)=>{let r=gD(e);return r===null?t:n(r)},yD=e=>hD(e)?e.remote:null,bD=(e,t,n={protocol:2,min:1})=>({hello:async()=>n,openInvite:async n=>{if(!hD(e))return{ok:!1,reason:`not-here`};let r=typeof n==`string`?WC(n):null;return t.onInvite(r),r===null?{ok:!1,reason:`malformed`}:{ok:!0}},openAdd:async n=>{if(!hD(e))return{ok:!1,reason:`not-here`};let r=typeof n==`string`?rf(n):null,i=r?.ok===!0?r.name:null;return t.onAdd(i),i===null?{ok:!1,reason:`malformed`}:{ok:!0}},openEdit:async()=>hD(e)?(t.onEdit(),{ok:!0}):{ok:!1,reason:`not-here`},ownKey:async()=>hD(e)?t.own():null,openFriends:async n=>hD(e)?aD(n)?t.friends(n):{ok:!1,reason:`none`}:{ok:!1,reason:`not-here`},deleteEntries:async n=>hD(e)?t.page.deleteEntries(n):{ok:!1,reason:`not-here`},setFavourite:async n=>hD(e)?t.page.setFavourite(n):{ok:!1,reason:`not-here`},deleteComments:async n=>hD(e)?t.page.deleteComments(n):{ok:!1,reason:`not-here`},sendComment:async n=>hD(e)?t.page.sendComment(n):{ok:!1,reason:`not-here`},publishing:()=>vD(e,_D,e=>t.apps.publishing(e)),allowPublishing:n=>vD(e,_D,e=>t.apps.allow(e,n)),publish:n=>vD(e,{ok:!1,reason:`not-here`},e=>t.apps.publish(e,n)),stopPublishing:()=>vD(e,_D,e=>t.apps.stop(e))}),xD=`social.writer`,SD=e=>{try{let t=e(),n=t.getItem(xD);if(n!==null&&/^[A-Za-z0-9_-]{22}$/.test(n))return n;let r=Y(crypto.getRandomValues(new Uint8Array(16)));return t.setItem(xD,r),t.getItem(`social.writer`)===r?r:null}catch{return null}},CD=`social.roster`,wD=Promise.resolve(),TD=e=>{let t=globalThis.navigator?.locks;if(t)return t.request(CD,e);let n=wD.then(e,e);return wD=n.catch(()=>{}),n},ED={open:async e=>{typeof e==`string`&&new URL(e).protocol===`https:`&&window.open(e,`_blank`,`noopener,noreferrer`)}},DD=e=>{if(typeof e!=`object`||!e)return!1;let{code:t,message:n}=e;return t===`denied`&&typeof n==`string`&&n.includes(`own frame`)},OD=async()=>{if(typeof window>`u`||window.parent===window||window.parent!==window.top)return!1;let e=oo(`shell.isAppTab`).then(e=>e.shell?.isAppTab?.()).then(e=>e===!0,()=>!1);return Promise.race([e,new Promise(e=>setTimeout(e,eo,!1))])},kD=()=>{let e=[],t=new Set;return{hand:n=>{t.size===0&&e.push(n);for(let e of t)e(n)},take:n=>{t.add(n);for(let t of e.splice(0))n(t);return()=>{t.delete(n)}}}},AD=({services:e,invites:t,adds:n,edits:r})=>{let[i,a]=q(`checking`),o=J(null),s=vu(async()=>{if(await Co().catch(()=>null)===null){oc(Hu).catch(()=>{}),a(`signed-out`);return}a(e=>e===`open`||e===`direct`?e:`opening`)},[]);return hu(()=>{s();let e=wo(()=>void s());return()=>{e.then(e=>e())}},[s]),hu(()=>{if(i!==`opening`||o.current===null)return;let e=o.current,t=!1;return(async()=>{let n=await eD(Hu)();if(!t){if(!WE(await n.hello()).usable){t||a(`outdated`);return}if(await ac(Hu,{element:e}),t){oc(Hu).catch(()=>{});return}a(`open`)}})().catch(e=>{t||a(DD(e)?`direct`:`failed`)}),()=>{t=!0}},[i]),i===`direct`?Z(LE,{services:e,unlock:cs,onAccountChange:wo,invites:t,adds:n,edits:r,site:()=>ED}):Z(K,{children:[Z(`div`,{className:`social-frame`,ref:o}),i!==`open`&&(i===`checking`||i===`opening`?Z(Rm,{state:`opening`,label:`Opening...`}):Z(Lm,{children:[Z(`h1`,{children:`FKN Social`}),i===`signed-out`?Z(K,{children:[Z(`p`,{children:`Sign in to FKN to manage your identity and friends.`}),Z(`div`,{className:`social-row`,children:Z(`button`,{type:`button`,className:`social-primary`,onClick:()=>void So().then(s),children:`Sign in`})})]}):i===`outdated`?Z(`p`,{children:`This page is older than FKN Social. Reload it to update.`}):Z(K,{children:[Z(`p`,{children:`FKN Social could not open. Try again or open it at social.fkn.app.`}),Z(`div`,{className:`social-row`,children:[Z(`button`,{type:`button`,className:`social-primary`,onClick:()=>a(`opening`),children:`Try again`}),Z(`a`,{className:`social-action`,href:Vu,target:`_blank`,rel:`noopener noreferrer`,children:`Open social.fkn.app`})]})]})]}))]})};(e=>{let t=kD(),n=kD(),r=kD(),i=null,a={account:{availability:$o,encryption:ss},cloud:Ef({list:Hs,readFileSealed:Us,writeFile:(e,t)=>Vs.writeFile(e,new TextEncoder().encode(t)),unlink:e=>Vs.unlink(e),isNotFound:jo}),rooms:{open:Wc,create:Gc,join:Kc},storage:{put:e=>ol(e),get:(e,t)=>cl(e,t),delete:ul,list:()=>ll()},sleep:e=>new Promise(t=>setTimeout(t,e)),writerId:SD(()=>localStorage),exclusive:TD},o=TC(a),s=mD(a);bc(e=>bD(e,{onInvite:t.hand,onAdd:n.hand,onEdit:()=>r.hand(!0),...lD(a),apps:o,page:s}),e=>{i=yD(e)??i}),HE();let c=!1;xc(e=>{e&&!c&&(c=!0,zu(document.body.appendChild(document.createElement(`div`))).render(Z(LE,{services:a,unlock:cs,onAccountChange:wo,invites:t.take,adds:n.take,edits:r.take,site:()=>i})))}),(e?.isAppTab??OD)().then(e=>{e&&!c&&(c=!0,zu(document.body.appendChild(document.createElement(`div`))).render(Z(AD,{services:a,invites:t.take,adds:n.take,edits:r.take})))})})();
|