pywire 0.1.2__py3-none-any.whl → 0.1.3__py3-none-any.whl

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.
pywire/cli/main.py CHANGED
@@ -145,7 +145,7 @@ rich.panel.Panel.__init__ = panel_init # type: ignore[method-assign]
145
145
  @click.version_option()
146
146
  def cli() -> None:
147
147
  """
148
- [bold white on cyan] pywire [/] [bold cyan]v0.1.0[/] Build faster python web apps.
148
+ [bold white on cyan] pywire [/] [bold cyan]v0.1.3[/] Build faster python web apps.
149
149
 
150
150
  Run [bold cyan]pywire dev APP[/] to start development server.
151
151
  Run [bold cyan]pywire run APP[/] to start production server.
pywire/client/build.mjs CHANGED
@@ -38,7 +38,7 @@ function getBuildOptions(bundle) {
38
38
  'process.env.NODE_ENV': isDev ? '"development"' : '"production"',
39
39
  },
40
40
  banner: {
41
- js: `/* PyWire Client ${bundle.name} v0.1.0 - https://github.com/pywire/pywire */`,
41
+ js: `/* PyWire Client ${bundle.name} v0.1.3 - https://github.com/pywire/pywire */`,
42
42
  },
43
43
  }
44
44
  }
@@ -274,7 +274,6 @@ async def run_dev_server(
274
274
  if not cert_path or not key_path:
275
275
  # Check for existing trusted certificates (e.g. from mkcert) in .pywire or root
276
276
  potential_certs = [
277
- (dot_pywire / "localhost-key.pem", dot_pywire / "localhost.pem"),
278
277
  (dot_pywire / "localhost.pem", dot_pywire / "localhost-key.pem"),
279
278
  (Path("localhost+2.pem"), Path("localhost+2-key.pem")),
280
279
  (Path("localhost.pem"), Path("localhost-key.pem")),
@@ -0,0 +1,3 @@
1
+ /* PyWire Client core v0.1.3 - https://github.com/pywire/pywire */
2
+ "use strict";var PyWireCore=(()=>{var ie=Object.defineProperty;var Ve=Object.getOwnPropertyDescriptor;var Xe=Object.getOwnPropertyNames;var Ge=Object.prototype.hasOwnProperty;var Ye=(s,e,t)=>e in s?ie(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var Je=(s,e)=>{for(var t in e)ie(s,t,{get:e[t],enumerable:!0})},qe=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let i of Xe(e))!Ge.call(s,i)&&i!==t&&ie(s,i,{get:()=>e[i],enumerable:!(n=Ve(e,i))||n.enumerable});return s};var Ze=s=>qe(ie({},"__esModule",{value:!0}),s);var c=(s,e,t)=>(Ye(s,typeof e!="symbol"?e+"":e,t),t);var Rt={};Je(Rt,{DOMUpdater:()=>b,HTTPTransport:()=>F,PyWireApp:()=>O,TransportManager:()=>_,WebSocketTransport:()=>z,WebTransportTransport:()=>L,app:()=>Ee});var B=class{constructor(){this.messageHandlers=[];this.statusHandlers=[];this.connected=!1}onMessage(e){this.messageHandlers.push(e)}onStatusChange(e){this.statusHandlers.push(e)}isConnected(){return this.connected}notifyHandlers(e){for(let t of this.messageHandlers)try{t(e)}catch(n){console.error("PyWire: Error in message handler",n)}}notifyStatus(e){if(this.connected!==e){this.connected=e;for(let t of this.statusHandlers)try{t(e)}catch(n){console.error("PyWire: Error in status handler",n)}}}};var L=class s extends B{constructor(t){super();this.name="WebTransport";this.transport=null;this.writer=null;this.encoder=new TextEncoder;this.decoder=new TextDecoder;this.url=t||this.getDefaultUrl()}getDefaultUrl(){return`https://${window.location.host}/_pywire/webtransport`}static isSupported(){return typeof WebTransport<"u"}async connect(){if(!s.isSupported())throw new Error("WebTransport not supported in this browser");try{let t={},n=window.PYWIRE_CERT_HASH;n&&Array.isArray(n)&&(t.serverCertificateHashes=[{algorithm:"sha-256",value:new Uint8Array(n).buffer}],console.log("PyWire: Using explicit certificate hash for WebTransport")),this.transport=new WebTransport(this.url,t),await this.transport.ready,console.log("PyWire: WebTransport ready"),this.connected=!0,this.startReading()}catch(t){throw this.handleDisconnect(),t}}async startReading(){if(!this.transport)return;let t=this.transport.incomingBidirectionalStreams.getReader();try{for(;;){let{value:n,done:i}=await t.read();if(i)break;this.handleStream(n)}}catch(n){this.connected&&(console.error("PyWire: WebTransport read error",n),this.handleDisconnect())}}async handleStream(t){let n=t.readable.getReader();try{for(;;){let{value:i,done:r}=await n.read();if(r)break;if(i){let o=this.decoder.decode(i);try{let a=JSON.parse(o);this.notifyHandlers(a)}catch(a){console.error("PyWire: Error parsing WebTransport message",a)}}}}catch(i){console.error("PyWire: Stream read error",i)}}async send(t){if(!this.transport||!this.connected){console.warn("PyWire: Cannot send message, WebTransport not connected");return}try{let n=await this.transport.createBidirectionalStream(),i=n.writable.getWriter(),r=this.encoder.encode(JSON.stringify(t));await i.write(r),await i.close(),this.handleStream(n)}catch(n){console.error("PyWire: WebTransport send error",n)}}disconnect(){this.transport&&(this.transport.close(),this.transport=null),this.writer=null,this.connected=!1}handleDisconnect(){this.connected=!1,this.transport=null,this.writer=null}};function Pe(s){let e=s.length,t=0,n=0;for(;n<e;){let i=s.charCodeAt(n++);if(i&4294967168)if(!(i&4294965248))t+=2;else{if(i>=55296&&i<=56319&&n<e){let r=s.charCodeAt(n);(r&64512)===56320&&(++n,i=((i&1023)<<10)+(r&1023)+65536)}i&4294901760?t+=4:t+=3}else{t++;continue}}return t}function Qe(s,e,t){let n=s.length,i=t,r=0;for(;r<n;){let o=s.charCodeAt(r++);if(o&4294967168)if(!(o&4294965248))e[i++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&r<n){let a=s.charCodeAt(r);(a&64512)===56320&&(++r,o=((o&1023)<<10)+(a&1023)+65536)}o&4294901760?(e[i++]=o>>18&7|240,e[i++]=o>>12&63|128,e[i++]=o>>6&63|128):(e[i++]=o>>12&15|224,e[i++]=o>>6&63|128)}else{e[i++]=o;continue}e[i++]=o&63|128}}var je=new TextEncoder,et=50;function tt(s,e,t){je.encodeInto(s,e.subarray(t))}function Be(s,e,t){s.length>et?tt(s,e,t):Qe(s,e,t)}var nt=4096;function xe(s,e,t){let n=e,i=n+t,r=[],o="";for(;n<i;){let a=s[n++];if(!(a&128))r.push(a);else if((a&224)===192){let d=s[n++]&63;r.push((a&31)<<6|d)}else if((a&240)===224){let d=s[n++]&63,w=s[n++]&63;r.push((a&31)<<12|d<<6|w)}else if((a&248)===240){let d=s[n++]&63,w=s[n++]&63,g=s[n++]&63,m=(a&7)<<18|d<<12|w<<6|g;m>65535&&(m-=65536,r.push(m>>>10&1023|55296),m=56320|m&1023),r.push(m)}else r.push(a);r.length>=nt&&(o+=String.fromCharCode(...r),r.length=0)}return r.length>0&&(o+=String.fromCharCode(...r)),o}var it=new TextDecoder,st=200;function rt(s,e,t){let n=s.subarray(e,e+t);return it.decode(n)}function Ie(s,e,t){return t>st?rt(s,e,t):xe(s,e,t)}var W=class{constructor(e,t){c(this,"type");c(this,"data");this.type=e,this.data=t}};var x=class s extends Error{constructor(e){super(e);let t=Object.create(s.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:s.name})}};function Le(s,e,t){let n=t/4294967296,i=t;s.setUint32(e,n),s.setUint32(e+4,i)}function se(s,e,t){let n=Math.floor(t/4294967296),i=t;s.setUint32(e,n),s.setUint32(e+4,i)}function re(s,e){let t=s.getInt32(e),n=s.getUint32(e+4);return t*4294967296+n}function We(s,e){let t=s.getUint32(e),n=s.getUint32(e+4);return t*4294967296+n}var ot=-1,at=4294967296-1,ct=17179869184-1;function dt({sec:s,nsec:e}){if(s>=0&&e>=0&&s<=ct)if(e===0&&s<=at){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,s),t}else{let t=s/4294967296,n=s&4294967295,i=new Uint8Array(8),r=new DataView(i.buffer);return r.setUint32(0,e<<2|t&3),r.setUint32(4,n),i}else{let t=new Uint8Array(12),n=new DataView(t.buffer);return n.setUint32(0,e),se(n,4,s),t}}function lt(s){let e=s.getTime(),t=Math.floor(e/1e3),n=(e-t*1e3)*1e6,i=Math.floor(n/1e9);return{sec:t+i,nsec:n-i*1e9}}function ht(s){if(s instanceof Date){let e=lt(s);return dt(e)}else return null}function ft(s){let e=new DataView(s.buffer,s.byteOffset,s.byteLength);switch(s.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{let t=e.getUint32(0),n=e.getUint32(4),i=(t&3)*4294967296+n,r=t>>>2;return{sec:i,nsec:r}}case 12:{let t=re(e,4),n=e.getUint32(0);return{sec:t,nsec:n}}default:throw new x(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${s.length}`)}}function ut(s){let e=ft(s);return new Date(e.sec*1e3+e.nsec/1e6)}var Ce={type:ot,encode:ht,decode:ut};var oe=class oe{constructor(){c(this,"__brand");c(this,"builtInEncoders",[]);c(this,"builtInDecoders",[]);c(this,"encoders",[]);c(this,"decoders",[]);this.register(Ce)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let i=-1-e;this.builtInEncoders[i]=t,this.builtInDecoders[i]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let i=this.builtInEncoders[n];if(i!=null){let r=i(e,t);if(r!=null){let o=-1-n;return new W(o,r)}}}for(let n=0;n<this.encoders.length;n++){let i=this.encoders[n];if(i!=null){let r=i(e,t);if(r!=null){let o=n;return new W(o,r)}}}return e instanceof W?e:null}decode(e,t,n){let i=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return i?i(e,t,n):new W(t,e)}};c(oe,"defaultCodec",new oe);var $=oe;function pt(s){return s instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&s instanceof SharedArrayBuffer}function G(s){return s instanceof Uint8Array?s:ArrayBuffer.isView(s)?new Uint8Array(s.buffer,s.byteOffset,s.byteLength):pt(s)?new Uint8Array(s):Uint8Array.from(s)}var gt=100,mt=2048,ae=class s{constructor(e){c(this,"extensionCodec");c(this,"context");c(this,"useBigInt64");c(this,"maxDepth");c(this,"initialBufferSize");c(this,"sortKeys");c(this,"forceFloat32");c(this,"ignoreUndefined");c(this,"forceIntegerToFloat");c(this,"pos");c(this,"view");c(this,"bytes");c(this,"entered",!1);this.extensionCodec=e?.extensionCodec??$.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??gt,this.initialBufferSize=e?.initialBufferSize??mt,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new s({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){let t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){let t=new ArrayBuffer(e),n=new Uint8Array(t),i=new DataView(t);n.set(this.bytes),this.view=i,this.bytes=n}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let n=Pe(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),Be(e,this.bytes,this.pos),this.pos+=n}encodeObject(e,t){let n=this.extensionCodec.tryToEncode(e,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw new Error(`Too large binary: ${t}`);let n=G(e);this.writeU8a(n)}encodeArray(e,t){let n=e.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw new Error(`Too large array: ${n}`);for(let i of e)this.doEncode(i,t+1)}countWithoutUndefined(e,t){let n=0;for(let i of t)e[i]!==void 0&&n++;return n}encodeMap(e,t){let n=Object.keys(e);this.sortKeys&&n.sort();let i=this.ignoreUndefined?this.countWithoutUndefined(e,n):n.length;if(i<16)this.writeU8(128+i);else if(i<65536)this.writeU8(222),this.writeU16(i);else if(i<4294967296)this.writeU8(223),this.writeU32(i);else throw new Error(`Too large map object: ${i}`);for(let r of n){let o=e[r];this.ignoreUndefined&&o===void 0||(this.encodeString(r),this.doEncode(o,t+1))}}encodeExtension(e){if(typeof e.data=="function"){let n=e.data(this.pos+6),i=n.length;if(i>=4294967296)throw new Error(`Too large extension object: ${i}`);this.writeU8(201),this.writeU32(i),this.writeI8(e.type),this.writeU8a(n);return}let t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw new Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),Le(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),se(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};function N(s,e){return new ae(e).encodeSharedRef(s)}function ce(s){return`${s<0?"-":""}0x${Math.abs(s).toString(16).padStart(2,"0")}`}var wt=16,yt=16,de=class{constructor(e=wt,t=yt){c(this,"hit",0);c(this,"miss",0);c(this,"caches");c(this,"maxKeyLength");c(this,"maxLengthPerKey");this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let n=0;n<this.maxKeyLength;n++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let i=this.caches[n-1];e:for(let r of i){let o=r.bytes;for(let a=0;a<n;a++)if(o[a]!==e[t+a])continue e;return r.str}return null}store(e,t){let n=this.caches[e.length-1],i={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=i:n.push(i)}decode(e,t,n){let i=this.find(e,t,n);if(i!=null)return this.hit++,i;this.miss++;let r=xe(e,t,n),o=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(o,r),r}};var ve="array",q="map_key",He="map_value",xt=s=>{if(typeof s=="string"||typeof s=="number")return s;throw new x("The type of key must be string or number but "+typeof s)},Se=class{constructor(){c(this,"stack",[]);c(this,"stackHeadPosition",-1)}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=ve,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=q,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===ve){let n=e;n.size=0,n.array=void 0,n.position=0,n.type=void 0}if(e.type===q||e.type===He){let n=e;n.size=0,n.map=void 0,n.readCount=0,n.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},J=-1,Te=new DataView(new ArrayBuffer(0)),vt=new Uint8Array(Te.buffer);try{Te.getInt8(0)}catch(s){if(!(s instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var De=new RangeError("Insufficient data"),St=new de,le=class s{constructor(e){c(this,"extensionCodec");c(this,"context");c(this,"useBigInt64");c(this,"rawStrings");c(this,"maxStrLength");c(this,"maxBinLength");c(this,"maxArrayLength");c(this,"maxMapLength");c(this,"maxExtLength");c(this,"keyDecoder");c(this,"mapKeyConverter");c(this,"totalPos",0);c(this,"pos",0);c(this,"view",Te);c(this,"bytes",vt);c(this,"headByte",J);c(this,"stack",new Se);c(this,"entered",!1);this.extensionCodec=e?.extensionCodec??$.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:St,this.mapKeyConverter=e?.mapKeyConverter??xt}clone(){return new s({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=J,this.stack.reset()}setBuffer(e){let t=G(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===J&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=G(e),i=new Uint8Array(t.length+n.length);i.set(t),i.set(n,t.length),this.setBuffer(i)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return new RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let a of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{n=this.doDecodeSync(),t=!0}catch(d){if(!(d instanceof RangeError))throw d}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:i,pos:r,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${ce(i)} at ${o} (${r} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,i=-1;for await(let r of e){if(t&&i===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(r),n&&(i=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--i!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let i=e-128;if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e<160){let i=e-144;if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else{let i=e-160;t=this.decodeString(i,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)this.useBigInt64?t=this.readU64AsBigInt():t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)this.useBigInt64?t=this.readI64AsBigInt():t=this.readI64();else if(e===217){let i=this.lookU8();t=this.decodeString(i,1)}else if(e===218){let i=this.lookU16();t=this.decodeString(i,2)}else if(e===219){let i=this.lookU32();t=this.decodeString(i,4)}else if(e===220){let i=this.readU16();if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else if(e===221){let i=this.readU32();if(i!==0){this.pushArrayState(i),this.complete();continue e}else t=[]}else if(e===222){let i=this.readU16();if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e===223){let i=this.readU32();if(i!==0){this.pushMapState(i),this.complete();continue e}else t={}}else if(e===196){let i=this.lookU8();t=this.decodeBinary(i,1)}else if(e===197){let i=this.lookU16();t=this.decodeBinary(i,2)}else if(e===198){let i=this.lookU32();t=this.decodeBinary(i,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let i=this.lookU8();t=this.decodeExtension(i,1)}else if(e===200){let i=this.lookU16();t=this.decodeExtension(i,2)}else if(e===201){let i=this.lookU32();t=this.decodeExtension(i,4)}else throw new x(`Unrecognized type byte: ${ce(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let i=n.top();if(i.type===ve)if(i.array[i.position]=t,i.position++,i.position===i.size)t=i.array,n.release(i);else continue e;else if(i.type===q){if(t==="__proto__")throw new x("The key __proto__ is not allowed");i.key=this.mapKeyConverter(t),i.type=He;continue e}else if(i.map[i.key]=t,i.readCount++,i.readCount===i.size)t=i.map,n.release(i);else{i.key=null,i.type=q;continue e}}return t}}readHeadByte(){return this.headByte===J&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=J}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new x(`Unrecognized array type byte: ${ce(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new x(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new x(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new x(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw De;let n=this.pos+t,i;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?i=this.keyDecoder.decode(this.bytes,n,e):i=Ie(this.bytes,n,e),this.pos+=t+e,i}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===q:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new x(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw De;let n=this.pos+t,i=this.bytes.subarray(n,n+e);return this.pos+=t+e,i}decodeExtension(e,t){if(e>this.maxExtLength)throw new x(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),i=this.decodeBinary(e,t+1);return this.extensionCodec.decode(i,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=We(this.view,this.pos);return this.pos+=8,e}readI64(){let e=re(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function C(s,e){return new le(e).decode(s)}var z=class extends B{constructor(t){super();this.name="WebSocket";this.socket=null;this.reconnectAttempts=0;this.maxReconnectDelay=5e3;this.shouldReconnect=!0;this.url=t||this.getDefaultUrl()}getDefaultUrl(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/_pywire/ws`}connect(){return new Promise((t,n)=>{try{this.socket=new WebSocket(this.url),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{console.log("PyWire: WebSocket connected"),this.notifyStatus(!0),this.reconnectAttempts=0,t()},this.socket.onmessage=i=>{try{let r=C(i.data);this.notifyHandlers(r)}catch(r){console.error("PyWire: Error parsing WebSocket message",r)}},this.socket.onclose=()=>{console.log("PyWire: WebSocket disconnected"),this.notifyStatus(!1),this.shouldReconnect&&this.scheduleReconnect()},this.socket.onerror=i=>{console.error("PyWire: WebSocket error",i),this.connected||n(new Error("WebSocket connection failed"))}}catch(i){n(i)}})}send(t){this.socket&&this.socket.readyState===WebSocket.OPEN?this.socket.send(N(t)):console.warn("PyWire: Cannot send message, WebSocket not open")}disconnect(){this.shouldReconnect=!1,this.socket&&(this.socket.close(),this.socket=null),this.notifyStatus(!1)}scheduleReconnect(){let t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),this.maxReconnectDelay);console.log(`PyWire: Reconnecting in ${t}ms...`),setTimeout(()=>{this.reconnectAttempts++,this.connect().catch(()=>{})},t)}};var F=class extends B{constructor(t){super();this.name="HTTP";this.polling=!1;this.pollAbortController=null;this.sessionId=null;this.baseUrl=t||`${window.location.origin}/_pywire`}async connect(){try{let t=await fetch(`${this.baseUrl}/session`,{method:"POST",headers:{"Content-Type":"application/x-msgpack",Accept:"application/x-msgpack"},body:N({path:window.location.pathname+window.location.search})});if(!t.ok)throw new Error(`HTTP session init failed: ${t.status}`);let n=await t.arrayBuffer(),i=C(n);this.sessionId=i.sessionId,console.log("PyWire: HTTP transport connected"),this.notifyStatus(!0),this.startPolling()}catch(t){throw console.error("PyWire: HTTP transport connection failed",t),t}}async startPolling(){if(!this.polling)for(this.polling=!0;this.polling&&this.connected;)try{this.pollAbortController=new AbortController;let t=await fetch(`${this.baseUrl}/poll?session=${this.sessionId}`,{method:"GET",signal:this.pollAbortController.signal,headers:{Accept:"application/x-msgpack"}});if(!t.ok){if(t.status===404){console.warn("PyWire: HTTP session expired, reconnecting..."),this.notifyStatus(!1),await this.connect();return}throw new Error(`Poll failed: ${t.status}`)}let n=await t.arrayBuffer(),i=C(n);for(let r of i)this.notifyHandlers(r)}catch(t){if(t instanceof Error&&t.name==="AbortError")break;console.error("PyWire: HTTP poll error",t),await this.sleep(1e3)}}async send(t){if(!this.connected||!this.sessionId){console.warn("PyWire: Cannot send message, HTTP transport not connected");return}try{let n=await fetch(`${this.baseUrl}/event`,{method:"POST",headers:{"Content-Type":"application/x-msgpack",Accept:"application/x-msgpack","X-PyWire-Session":this.sessionId},body:N(t)});if(!n.ok)throw new Error(`Event send failed: ${n.status}`);let i=await n.arrayBuffer(),r=C(i);this.notifyHandlers(r)}catch(n){console.error("PyWire: HTTP send error",n)}}disconnect(){this.polling=!1,this.notifyStatus(!1),this.pollAbortController&&(this.pollAbortController.abort(),this.pollAbortController=null),this.sessionId=null}sleep(t){return new Promise(n=>setTimeout(n,t))}};var Tt={enableWebTransport:!0,enableWebSocket:!0,enableHTTP:!0},_=class{constructor(e={}){this.transport=null;this.messageHandlers=[];this.statusHandlers=[];this.config={...Tt,...e}}async connect(){let e=this.getTransportPriority();for(let t of e)try{console.log(`PyWire: Trying ${t.name}...`),this.transport=new t;for(let n of this.messageHandlers)this.transport.onMessage(n);this.transport.onStatusChange(n=>{this.notifyStatusHandlers(n)}),await this.transport.connect(),console.log(`PyWire: Connected via ${this.transport.name}`);return}catch(n){console.warn(`PyWire: ${t.name} failed, trying next...`,n),this.transport=null}throw new Error("PyWire: All transports failed")}getTransportPriority(){let e=[];return this.config.enableWebTransport&&L.isSupported()&&window.location.protocol==="https:"&&e.push(L),this.config.enableWebSocket&&typeof WebSocket<"u"&&e.push(z),this.config.enableHTTP&&e.push(F),e}send(e){this.transport?this.transport.send(e):console.warn("PyWire: No active transport")}onMessage(e){this.messageHandlers.push(e),this.transport&&this.transport.onMessage(e)}onStatusChange(e){this.statusHandlers.push(e)}notifyStatusHandlers(e){for(let t of this.statusHandlers)t(e)}disconnect(){this.transport&&(this.transport.disconnect(),this.transport=null,this.notifyStatusHandlers(!1))}getActiveTransport(){return this.transport?.name||null}isConnected(){return this.transport?.isConnected()||!1}};var Re=11;function bt(s,e){var t=e.attributes,n,i,r,o,a;if(!(e.nodeType===Re||s.nodeType===Re)){for(var d=t.length-1;d>=0;d--)n=t[d],i=n.name,r=n.namespaceURI,o=n.value,r?(i=n.localName||i,a=s.getAttributeNS(r,i),a!==o&&(n.prefix==="xmlns"&&(i=n.name),s.setAttributeNS(r,i,o))):(a=s.getAttribute(i),a!==o&&s.setAttribute(i,o));for(var w=s.attributes,g=w.length-1;g>=0;g--)n=w[g],i=n.name,r=n.namespaceURI,r?(i=n.localName||i,e.hasAttributeNS(r,i)||s.removeAttributeNS(r,i)):e.hasAttribute(i)||s.removeAttribute(i)}}var he,Ut="http://www.w3.org/1999/xhtml",v=typeof document>"u"?void 0:document,Et=!!v&&"content"in v.createElement("template"),At=!!v&&v.createRange&&"createContextualFragment"in v.createRange();function Mt(s){var e=v.createElement("template");return e.innerHTML=s,e.content.childNodes[0]}function kt(s){he||(he=v.createRange(),he.selectNode(v.body));var e=he.createContextualFragment(s);return e.childNodes[0]}function Pt(s){var e=v.createElement("body");return e.innerHTML=s,e.childNodes[0]}function Bt(s){return s=s.trim(),Et?Mt(s):At?kt(s):Pt(s)}function fe(s,e){var t=s.nodeName,n=e.nodeName,i,r;return t===n?!0:(i=t.charCodeAt(0),r=n.charCodeAt(0),i<=90&&r>=97?t===n.toUpperCase():r<=90&&i>=97?n===t.toUpperCase():!1)}function It(s,e){return!e||e===Ut?v.createElement(s):v.createElementNS(e,s)}function Lt(s,e){for(var t=s.firstChild;t;){var n=t.nextSibling;e.appendChild(t),t=n}return e}function be(s,e,t){s[t]!==e[t]&&(s[t]=e[t],s[t]?s.setAttribute(t,""):s.removeAttribute(t))}var $e={OPTION:function(s,e){var t=s.parentNode;if(t){var n=t.nodeName.toUpperCase();n==="OPTGROUP"&&(t=t.parentNode,n=t&&t.nodeName.toUpperCase()),n==="SELECT"&&!t.hasAttribute("multiple")&&(s.hasAttribute("selected")&&!e.selected&&(s.setAttribute("selected","selected"),s.removeAttribute("selected")),t.selectedIndex=-1)}be(s,e,"selected")},INPUT:function(s,e){be(s,e,"checked"),be(s,e,"disabled"),s.value!==e.value&&(s.value=e.value),e.hasAttribute("value")||s.removeAttribute("value")},TEXTAREA:function(s,e){var t=e.value;s.value!==t&&(s.value=t);var n=s.firstChild;if(n){var i=n.nodeValue;if(i==t||!t&&i==s.placeholder)return;n.nodeValue=t}},SELECT:function(s,e){if(!e.hasAttribute("multiple")){for(var t=-1,n=0,i=s.firstChild,r,o;i;)if(o=i.nodeName&&i.nodeName.toUpperCase(),o==="OPTGROUP")r=i,i=r.firstChild,i||(i=r.nextSibling,r=null);else{if(o==="OPTION"){if(i.hasAttribute("selected")){t=n;break}n++}i=i.nextSibling,!i&&r&&(i=r.nextSibling,r=null)}s.selectedIndex=t}}},Z=1,Ne=11,ze=3,Fe=8;function I(){}function Wt(s){if(s)return s.getAttribute&&s.getAttribute("id")||s.id}function Ct(s){return function(t,n,i){if(i||(i={}),typeof n=="string")if(t.nodeName==="#document"||t.nodeName==="HTML"||t.nodeName==="BODY"){var r=n;n=v.createElement("html"),n.innerHTML=r}else n=Bt(n);else n.nodeType===Ne&&(n=n.firstElementChild);var o=i.getNodeKey||Wt,a=i.onBeforeNodeAdded||I,d=i.onNodeAdded||I,w=i.onBeforeElUpdated||I,g=i.onElUpdated||I,m=i.onBeforeNodeDiscarded||I,E=i.onNodeDiscarded||I,V=i.onBeforeElChildrenUpdated||I,S=i.skipFromChildren||I,X=i.addChild||function(l,h){return l.appendChild(h)},D=i.childrenOnly===!0,T=Object.create(null),A=[];function M(l){A.push(l)}function Ae(l,h){if(l.nodeType===Z)for(var p=l.firstChild;p;){var f=void 0;h&&(f=o(p))?M(f):(E(p),p.firstChild&&Ae(p,h)),p=p.nextSibling}}function Q(l,h,p){m(l)!==!1&&(h&&h.removeChild(l),E(l),Ae(l,p))}function pe(l){if(l.nodeType===Z||l.nodeType===Ne)for(var h=l.firstChild;h;){var p=o(h);p&&(T[p]=h),pe(h),h=h.nextSibling}}pe(t);function ge(l){d(l);for(var h=l.firstChild;h;){var p=h.nextSibling,f=o(h);if(f){var u=T[f];u&&fe(h,u)?(h.parentNode.replaceChild(u,h),j(u,h)):ge(h)}else ge(h);h=p}}function _e(l,h,p){for(;h;){var f=h.nextSibling;(p=o(h))?M(p):Q(h,l,!0),h=f}}function j(l,h,p){var f=o(h);if(f&&delete T[f],!p){var u=w(l,h);if(u===!1||(u instanceof HTMLElement&&(l=u,pe(l)),s(l,h),g(l),V(l,h)===!1))return}l.nodeName!=="TEXTAREA"?Ke(l,h):$e.TEXTAREA(l,h)}function Ke(l,h){var p=S(l,h),f=h.firstChild,u=l.firstChild,H,U,R,te,k;e:for(;f;){for(te=f.nextSibling,H=o(f);!p&&u;){if(R=u.nextSibling,f.isSameNode&&f.isSameNode(u)){f=te,u=R;continue e}U=o(u);var ne=u.nodeType,P=void 0;if(ne===f.nodeType&&(ne===Z?(H?H!==U&&((k=T[H])?R===k?P=!1:(l.insertBefore(k,u),U?M(U):Q(u,l,!0),u=k,U=o(u)):P=!1):U&&(P=!1),P=P!==!1&&fe(u,f),P&&j(u,f)):(ne===ze||ne==Fe)&&(P=!0,u.nodeValue!==f.nodeValue&&(u.nodeValue=f.nodeValue))),P){f=te,u=R;continue e}U?M(U):Q(u,l,!0),u=R}if(H&&(k=T[H])&&fe(k,f))p||X(l,k),j(k,f);else{var ye=a(f);ye!==!1&&(ye&&(f=ye),f.actualize&&(f=f.actualize(l.ownerDocument||v)),X(l,f),ge(f))}f=te,u=R}_e(l,u,U);var ke=$e[l.nodeName];ke&&ke(l,h)}var y=t,ee=y.nodeType,Me=n.nodeType;if(!D){if(ee===Z)Me===Z?fe(t,n)||(E(t),y=Lt(t,It(n.nodeName,n.namespaceURI))):y=n;else if(ee===ze||ee===Fe){if(Me===ee)return y.nodeValue!==n.nodeValue&&(y.nodeValue=n.nodeValue),y;y=n}}if(y===n)E(t);else{if(n.isSameNode&&n.isSameNode(y))return;if(j(y,n,D),A)for(var me=0,Oe=A.length;me<Oe;me++){var we=T[A[me]];we&&Q(we,we.parentNode,!1)}}return!D&&y!==t&&t.parentNode&&(y.actualize&&(y=y.actualize(t.ownerDocument||v)),t.parentNode.replaceChild(y,t)),y}}var Dt=Ct(bt),Ue=Dt;var K=class K{constructor(e=!1){this.debug=e}getNodeKey(e){if(e instanceof HTMLElement){for(let t of e.attributes)if(t.name.startsWith("data-on-"))return`${e.tagName}-${t.name}-${t.value}`;if(e.id&&!e.id.startsWith("pywire-uid-"))return e.id;if((e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&e.name)return`${e.tagName}-name-${e.name}`}}getElementSelector(e){if(e.id)return`#${e.id}`;let t=[],n=e;for(;n&&n!==document.body&&t.length<5;){let i=n.tagName.toLowerCase();if(n.id){i=`#${n.id}`,t.unshift(i);break}(n instanceof HTMLInputElement||n instanceof HTMLSelectElement||n instanceof HTMLTextAreaElement)&&n.name&&(i+=`[name="${n.name}"]`);for(let r of n.attributes)if(r.name.startsWith("data-on-")){i+=`[${r.name}="${r.value}"]`;break}if(n.parentElement){let o=Array.from(n.parentElement.children).filter(a=>a.tagName===n.tagName);if(o.length>1){let a=o.indexOf(n)+1;i+=`:nth-of-type(${a})`}}t.unshift(i),n=n.parentElement}return t.join(" > ")}captureFocusState(){let e=document.activeElement;if(!e||e===document.body||e===document.documentElement)return null;let t={selector:this.getElementSelector(e),id:e.id||null,tagName:e.tagName,selectionStart:null,selectionEnd:null,scrollTop:0,scrollLeft:0,value:""};return(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&(t.selectionStart=e.selectionStart,t.selectionEnd=e.selectionEnd,t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft,t.value=e.value),t}restoreFocusState(e){if(!e)return;let t=null;if(e.id&&(t=document.getElementById(e.id)),!t&&e.selector)try{t=document.querySelector(e.selector)}catch{}if(t&&(t.focus(),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)){if(e.value&&t.value!==e.value&&(t.value=e.value),e.selectionStart!==null&&e.selectionEnd!==null)try{t.setSelectionRange(e.selectionStart,e.selectionEnd)}catch{}t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft}}applyUpdate(e,t){K.isUpdating=!0,this.debug&&console.log("[DOMUpdater] Starting update, isUpdating =",K.isUpdating);try{let n=this.captureFocusState();if(Ue){try{Ue(e,t,{getNodeKey:i=>this.getNodeKey(i),onBeforeElUpdated:(i,r)=>{if(i instanceof HTMLInputElement&&r instanceof HTMLInputElement)if(i.type==="checkbox"||i.type==="radio")r.checked=i.checked;else{let o=r.value||"",a=i.value||"";(a.startsWith(o)||o.startsWith(a))&&(r.value=a)}if(i instanceof HTMLTextAreaElement&&r instanceof HTMLTextAreaElement){let o=r.value||"",a=i.value||"";(a.startsWith(o)||o.startsWith(a))&&(r.value=a)}return i instanceof HTMLSelectElement&&r instanceof HTMLSelectElement&&(i.value&&Array.from(r.options).some(o=>o.value===i.value)?r.value=i.value:i.selectedIndex>=0&&i.selectedIndex<r.options.length&&(r.selectedIndex=i.selectedIndex)),i.id&&i.id.startsWith("pywire-uid-")&&!r.id&&(r.id=i.id),!0},onBeforeNodeDiscarded:()=>!0})}catch(i){console.error("Morphdom failed:",i),e===document.documentElement&&(document.open(),document.write(t),document.close())}this.restoreFocusState(n)}else e===document.documentElement&&(document.open(),document.write(t),document.close())}finally{setTimeout(()=>{K.isUpdating=!1},0)}}update(e){let t=/<html[\s>]/i.test(e),n=/<body[\s>]/i.test(e);if(!t&&document.body){if(n){this.applyUpdate(document.body,e);return}let i=`<body>${e}</body>`;this.applyUpdate(document.body,i);return}this.applyUpdate(document.documentElement,e)}updateRegion(e,t){let n=document.querySelector(`[data-pw-region="${e}"]`);if(!n){this.debug&&console.warn("[DOMUpdater] Region not found:",e);return}this.applyUpdate(n,t),n.getAttribute("data-pw-region")||n.setAttribute("data-pw-region",e)}};K.isUpdating=!1;var b=K;var ue=class{constructor(e){this.debouncers=new Map;this.throttlers=new Map;this.supportedEvents=["click","submit","input","change","keydown","keyup","focus","blur","mouseenter","mouseleave","scroll","contextmenu"];this.suppressDuringUpdate=["focus","blur","mouseenter","mouseleave"];this.app=e}debugLog(...e){this.app.getConfig().debug&&console.log(...e)}init(){this.supportedEvents.forEach(e=>{let t=e==="mouseenter"||e==="mouseleave"||e==="focus"||e==="blur"||e==="scroll"?{capture:!0}:void 0;document.addEventListener(e,n=>this.handleEvent(n),t)})}getHandlers(e,t){let n=`data-on-${t}`,i=e.getAttribute(n);if(!i)return[];if(i.trim().startsWith("["))try{let r=JSON.parse(i);if(Array.isArray(r))return r.flatMap(o=>{if(!o||typeof o!="object")return[];let a="handler"in o&&typeof o.handler=="string"?o.handler:null;if(!a)return[];let d="modifiers"in o&&Array.isArray(o.modifiers)?o.modifiers.filter(g=>typeof g=="string"):[],w="args"in o&&Array.isArray(o.args)?o.args:void 0;return[{name:a,modifiers:d,args:w}]})}catch(r){console.error("Error parsing event handlers:",r)}else{let r=e.getAttribute(`data-modifiers-${t}`),o=r?r.split(" ").filter(a=>a):[];return[{name:i,modifiers:o,args:void 0}]}return[]}async handleEvent(e){let t=e.type;if(b.isUpdating&&this.suppressDuringUpdate.includes(t)){this.debugLog("[Handler] SUPPRESSING event during update:",t,"isUpdating=",b.isUpdating);return}this.debugLog("[Handler] Processing event:",t,"isUpdating=",b.isUpdating);let n=e.composedPath?e.composedPath():[],i=!1;for(let r of n){if(i)break;if(r instanceof HTMLElement){let o=r,a=this.getHandlers(o,t);if(a.length>0){this.debugLog("[handleEvent] Found handlers on",o.tagName,a);for(let d of a)!d.modifiers.includes("window")&&!d.modifiers.includes("outside")&&(this.processEvent(o,t,d.name,d.modifiers,e,d.args),e.cancelBubble&&(i=!0))}}}this.handleGlobalEvent(e)}handleGlobalEvent(e){let t=e.type,n=`[data-modifiers-${t}*="window"]`,i=`[data-modifiers-${t}*="outside"]`;document.querySelectorAll(`${n}, ${i}`).forEach(o=>{if(!(o instanceof HTMLElement))return;let a=this.getHandlers(o,t);for(let d of a)if(d.modifiers.includes("window")&&this.processEvent(o,t,d.name,d.modifiers,e,d.args),d.modifiers.includes("outside")){let w=e.target;w&&!o.contains(w)&&this.processEvent(o,t,d.name,d.modifiers,e,d.args)}})}processEvent(e,t,n,i,r,o){if(this.debugLog("[processEvent]",t,"handler:",n,"modifiers:",i),(i.includes("prevent")||t==="submit")&&(this.debugLog("[processEvent] Calling preventDefault"),r.preventDefault()),i.includes("stop")&&r.stopPropagation(),i.includes("self")&&r.target!==e||i.includes("shift")&&(!("shiftKey"in r)||!r.shiftKey)||i.includes("ctrl")&&(!("ctrlKey"in r)||!r.ctrlKey)||i.includes("alt")&&(!("altKey"in r)||!r.altKey)||i.includes("meta")&&(!("metaKey"in r)||!r.metaKey)||i.includes("cmd")&&(!("metaKey"in r)||!r.metaKey))return;if(r instanceof KeyboardEvent){let m=["enter","escape","space","tab","up","down","left","right"],E=["shift","ctrl","alt","meta","cmd","window","outside","prevent","stop","self","debounce","throttle"],V=i.filter(S=>E.includes(S)||S.startsWith("debounce")||S.startsWith("throttle")||S.endsWith("ms")?!1:m.includes(S)||S.length===1);if(V.length>0){let S=r.key.toLowerCase();this.debugLog("[processEvent] Key check. Pressed:",S,"Modifiers:",V);let X={escape:"escape",esc:"escape",enter:"enter",space:" ",spacebar:" "," ":" ",tab:"tab",up:"arrowup",arrowup:"arrowup",down:"arrowdown",arrowdown:"arrowdown",left:"arrowleft",arrowleft:"arrowleft",right:"arrowright",arrowright:"arrowright"},D=X[S]||S,T=!1;for(let A of V){let M=X[A]||A;if(this.debugLog("[processEvent] Comparing constraint:",A,"->",M,"vs",D,"code:",r.code),M===D){T=!0;break}if(r.code&&r.code.toLowerCase()===`key${M}`){T=!0;break}}if(!T){this.debugLog("[processEvent] No key match found.");return}}}let a=i.find(m=>m.startsWith("debounce")),d=i.find(m=>m.startsWith("throttle")),g=`${e.id||this.getUniqueId(e)}-${t}-${n}`;if(a){let m=this.parseDuration(i,250);this.debouncers.has(g)&&window.clearTimeout(this.debouncers.get(g));let E=window.setTimeout(()=>{this.debouncers.delete(g),this.dispatchEvent(e,t,n,r,o)},m);this.debouncers.set(g,E);return}if(d){let m=this.parseDuration(i,250);if(this.throttlers.has(g))return;this.throttlers.set(g,Date.now()),this.dispatchEvent(e,t,n,r,o),window.setTimeout(()=>{this.throttlers.delete(g)},m);return}this.dispatchEvent(e,t,n,r,o)}dispatchEvent(e,t,n,i,r){let o={};r&&r.length>0?r.forEach((d,w)=>{o[`arg${w}`]=d}):o=this.getArgs(e);let a={type:t,id:e.id,args:o};if(e instanceof HTMLInputElement?(a.value=e.value,(e.type==="checkbox"||e.type==="radio")&&(a.checked=e.checked)):(e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(a.value=e.value),i instanceof KeyboardEvent&&(a.key=i.key,a.keyCode=i.keyCode),t==="submit"&&e instanceof HTMLFormElement){let d=new FormData(e),w={};d.forEach((g,m)=>{g instanceof File||(w[m]=g.toString())}),a.formData=w}this.app.sendEvent(n,a)}parseDuration(e,t){let n=e.findIndex(a=>a.startsWith("debounce")),i=e.findIndex(a=>a.startsWith("throttle")),r=n!==-1?n:i;if(r!==-1&&e[r+1]){let a=e[r+1];if(a.endsWith("ms")){let d=parseInt(a);if(!isNaN(d))return d}}let o=e[r];if(o&&o.includes("-")){let a=o.split("-"),d=parseInt(a[1]);if(!isNaN(d))return d}return t}getUniqueId(e){return e.id||(e.id="pywire-uid-"+Math.random().toString(36).substr(2,9)),e.id}getArgs(e){let t={};if(e instanceof HTMLElement){for(let n in e.dataset)if(n.startsWith("arg"))try{t[n]=JSON.parse(e.dataset[n]||"null")}catch{t[n]=e.dataset[n]}}return t}};var Ht={autoInit:!0,enableWebTransport:!0,enableWebSocket:!0,enableHTTP:!0,debug:!1},O=class{constructor(e={}){this.initialized=!1;this.siblingPaths=[];this.pathRegexes=[];this.pjaxEnabled=!1;this.isConnected=!1;this.config={...Ht,...e},this.transport=new _(this.config),this.updater=new b(this.config.debug),this.eventHandler=new ue(this)}getConfig(){return this.config}async init(){if(!this.initialized){this.initialized=!0,this.transport.onMessage(e=>this.handleMessage(e)),this.transport.onStatusChange(e=>this.handleStatusChange(e));try{await this.transport.connect()}catch(e){console.error("PyWire: Failed to connect:",e)}this.loadSPAMetadata(),this.setupSPANavigation(),this.eventHandler.init(),console.log(`PyWire: Initialized (transport: ${this.transport.getActiveTransport()}, spa_paths: ${this.siblingPaths.length}, pjax: ${this.pjaxEnabled})`)}}handleStatusChange(e){this.isConnected=e}loadSPAMetadata(){let e=document.getElementById("_pywire_spa_meta");if(e)try{let t=JSON.parse(e.textContent||"{}");this.siblingPaths=t.sibling_paths||[],this.pjaxEnabled=!!t.enable_pjax,t.debug!==void 0&&(this.config.debug=!!t.debug),this.pathRegexes=this.siblingPaths.map(n=>this.patternToRegex(n))}catch(t){console.warn("PyWire: Failed to parse SPA metadata",t)}}patternToRegex(e){let t=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&");return t=t.replace(/:(\\w+)(:\\w+)?/g,"([^/]+)"),t=t.replace(/\\{(\\w+)(:\\w+)?\\}/g,"([^/]+)"),new RegExp(`^${t}$`)}isSiblingPath(e){return this.pathRegexes.some(t=>t.test(e))}setupSPANavigation(){window.addEventListener("popstate",()=>{this.sendRelocate(window.location.pathname+window.location.search)}),!(this.siblingPaths.length===0&&!this.pjaxEnabled)&&document.addEventListener("click",e=>{let t=e.target.closest("a[href]");if(!t||t.origin!==window.location.origin||t.hasAttribute("download")||t.target==="_blank")return;let n=!1;(this.pjaxEnabled||this.isSiblingPath(t.pathname))&&(n=!0),n&&(e.preventDefault(),this.navigateTo(t.pathname+t.search))})}navigateTo(e){if(!this.isConnected){console.warn("PyWire: Navigation blocked - Offline");return}history.pushState({},"",e),this.sendRelocate(e)}sendRelocate(e){let t={type:"relocate",path:e};this.transport.send(t)}sendEvent(e,t){let n={type:"event",handler:e,path:window.location.pathname+window.location.search,data:t};this.transport.send(n)}async handleMessage(e){switch(e.type){case"update":e.regions&&e.regions.length>0?e.regions.forEach(t=>{this.updater.updateRegion(t.region,t.html)}):e.html&&this.updater.update(e.html);break;case"reload":console.log("PyWire: Reloading..."),window.location.reload();break;case"error":console.error("PyWire: Server error:",e.error);break;case"error_trace":console.error("PyWire: Error:",e.error);break;case"console":if(e.lines&&e.lines.length>0){let t="PyWire Server:",n=e.lines.join(`
3
+ `);e.level==="error"?console.error(t,n):e.level==="warn"?console.warn(t,n):console.log(t,n)}break;default:console.warn("PyWire: Unknown message type",e)}}getTransport(){return this.transport.getActiveTransport()}disconnect(){this.transport.disconnect()}};var Ee=new O;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Ee.init()):Ee.init();return Ze(Rt);})();
@@ -0,0 +1,20 @@
1
+ /* PyWire Client dev v0.1.3 - https://github.com/pywire/pywire */
2
+ "use strict";var PyWire=(()=>{var oe=Object.defineProperty;var Ye=Object.getOwnPropertyDescriptor;var Je=Object.getOwnPropertyNames;var qe=Object.prototype.hasOwnProperty;var Ze=(i,e,t)=>e in i?oe(i,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):i[e]=t;var Qe=(i,e)=>{for(var t in e)oe(i,t,{get:e[t],enumerable:!0})},je=(i,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of Je(e))!qe.call(i,r)&&r!==t&&oe(i,r,{get:()=>e[r],enumerable:!(n=Ye(e,r))||n.enumerable});return i};var et=i=>je(oe({},"__esModule",{value:!0}),i);var c=(i,e,t)=>(Ze(i,typeof e!="symbol"?e+"":e,t),t);var Ft={};Qe(Ft,{DOMUpdater:()=>T,ErrorTraceHandler:()=>X,HTTPTransport:()=>z,PyWireApp:()=>O,PyWireDevApp:()=>G,StatusOverlay:()=>V,TransportManager:()=>_,WebSocketTransport:()=>F,WebTransportTransport:()=>C,app:()=>Me});var B=class{constructor(){this.messageHandlers=[];this.statusHandlers=[];this.connected=!1}onMessage(e){this.messageHandlers.push(e)}onStatusChange(e){this.statusHandlers.push(e)}isConnected(){return this.connected}notifyHandlers(e){for(let t of this.messageHandlers)try{t(e)}catch(n){console.error("PyWire: Error in message handler",n)}}notifyStatus(e){if(this.connected!==e){this.connected=e;for(let t of this.statusHandlers)try{t(e)}catch(n){console.error("PyWire: Error in status handler",n)}}}};var C=class i extends B{constructor(t){super();this.name="WebTransport";this.transport=null;this.writer=null;this.encoder=new TextEncoder;this.decoder=new TextDecoder;this.url=t||this.getDefaultUrl()}getDefaultUrl(){return`https://${window.location.host}/_pywire/webtransport`}static isSupported(){return typeof WebTransport<"u"}async connect(){if(!i.isSupported())throw new Error("WebTransport not supported in this browser");try{let t={},n=window.PYWIRE_CERT_HASH;n&&Array.isArray(n)&&(t.serverCertificateHashes=[{algorithm:"sha-256",value:new Uint8Array(n).buffer}],console.log("PyWire: Using explicit certificate hash for WebTransport")),this.transport=new WebTransport(this.url,t),await this.transport.ready,console.log("PyWire: WebTransport ready"),this.connected=!0,this.startReading()}catch(t){throw this.handleDisconnect(),t}}async startReading(){if(!this.transport)return;let t=this.transport.incomingBidirectionalStreams.getReader();try{for(;;){let{value:n,done:r}=await t.read();if(r)break;this.handleStream(n)}}catch(n){this.connected&&(console.error("PyWire: WebTransport read error",n),this.handleDisconnect())}}async handleStream(t){let n=t.readable.getReader();try{for(;;){let{value:r,done:s}=await n.read();if(s)break;if(r){let o=this.decoder.decode(r);try{let a=JSON.parse(o);this.notifyHandlers(a)}catch(a){console.error("PyWire: Error parsing WebTransport message",a)}}}}catch(r){console.error("PyWire: Stream read error",r)}}async send(t){if(!this.transport||!this.connected){console.warn("PyWire: Cannot send message, WebTransport not connected");return}try{let n=await this.transport.createBidirectionalStream(),r=n.writable.getWriter(),s=this.encoder.encode(JSON.stringify(t));await r.write(s),await r.close(),this.handleStream(n)}catch(n){console.error("PyWire: WebTransport send error",n)}}disconnect(){this.transport&&(this.transport.close(),this.transport=null),this.writer=null,this.connected=!1}handleDisconnect(){this.connected=!1,this.transport=null,this.writer=null}};function Ce(i){let e=i.length,t=0,n=0;for(;n<e;){let r=i.charCodeAt(n++);if(r&4294967168)if(!(r&4294965248))t+=2;else{if(r>=55296&&r<=56319&&n<e){let s=i.charCodeAt(n);(s&64512)===56320&&(++n,r=((r&1023)<<10)+(s&1023)+65536)}r&4294901760?t+=4:t+=3}else{t++;continue}}return t}function tt(i,e,t){let n=i.length,r=t,s=0;for(;s<n;){let o=i.charCodeAt(s++);if(o&4294967168)if(!(o&4294965248))e[r++]=o>>6&31|192;else{if(o>=55296&&o<=56319&&s<n){let a=i.charCodeAt(s);(a&64512)===56320&&(++s,o=((o&1023)<<10)+(a&1023)+65536)}o&4294901760?(e[r++]=o>>18&7|240,e[r++]=o>>12&63|128,e[r++]=o>>6&63|128):(e[r++]=o>>12&15|224,e[r++]=o>>6&63|128)}else{e[r++]=o;continue}e[r++]=o&63|128}}var nt=new TextEncoder,rt=50;function it(i,e,t){nt.encodeInto(i,e.subarray(t))}function Le(i,e,t){i.length>rt?it(i,e,t):tt(i,e,t)}var st=4096;function be(i,e,t){let n=e,r=n+t,s=[],o="";for(;n<r;){let a=i[n++];if(!(a&128))s.push(a);else if((a&224)===192){let l=i[n++]&63;s.push((a&31)<<6|l)}else if((a&240)===224){let l=i[n++]&63,p=i[n++]&63;s.push((a&31)<<12|l<<6|p)}else if((a&248)===240){let l=i[n++]&63,p=i[n++]&63,y=i[n++]&63,g=(a&7)<<18|l<<12|p<<6|y;g>65535&&(g-=65536,s.push(g>>>10&1023|55296),g=56320|g&1023),s.push(g)}else s.push(a);s.length>=st&&(o+=String.fromCharCode(...s),s.length=0)}return s.length>0&&(o+=String.fromCharCode(...s)),o}var ot=new TextDecoder,at=200;function ct(i,e,t){let n=i.subarray(e,e+t);return ot.decode(n)}function We(i,e,t){return t>at?ct(i,e,t):be(i,e,t)}var L=class{constructor(e,t){c(this,"type");c(this,"data");this.type=e,this.data=t}};var x=class i extends Error{constructor(e){super(e);let t=Object.create(i.prototype);Object.setPrototypeOf(this,t),Object.defineProperty(this,"name",{configurable:!0,enumerable:!1,value:i.name})}};function He(i,e,t){let n=t/4294967296,r=t;i.setUint32(e,n),i.setUint32(e+4,r)}function ae(i,e,t){let n=Math.floor(t/4294967296),r=t;i.setUint32(e,n),i.setUint32(e+4,r)}function ce(i,e){let t=i.getInt32(e),n=i.getUint32(e+4);return t*4294967296+n}function De(i,e){let t=i.getUint32(e),n=i.getUint32(e+4);return t*4294967296+n}var lt=-1,dt=4294967296-1,ht=17179869184-1;function ft({sec:i,nsec:e}){if(i>=0&&e>=0&&i<=ht)if(e===0&&i<=dt){let t=new Uint8Array(4);return new DataView(t.buffer).setUint32(0,i),t}else{let t=i/4294967296,n=i&4294967295,r=new Uint8Array(8),s=new DataView(r.buffer);return s.setUint32(0,e<<2|t&3),s.setUint32(4,n),r}else{let t=new Uint8Array(12),n=new DataView(t.buffer);return n.setUint32(0,e),ae(n,4,i),t}}function ut(i){let e=i.getTime(),t=Math.floor(e/1e3),n=(e-t*1e3)*1e6,r=Math.floor(n/1e9);return{sec:t+r,nsec:n-r*1e9}}function pt(i){if(i instanceof Date){let e=ut(i);return ft(e)}else return null}function gt(i){let e=new DataView(i.buffer,i.byteOffset,i.byteLength);switch(i.byteLength){case 4:return{sec:e.getUint32(0),nsec:0};case 8:{let t=e.getUint32(0),n=e.getUint32(4),r=(t&3)*4294967296+n,s=t>>>2;return{sec:r,nsec:s}}case 12:{let t=ce(e,4),n=e.getUint32(0);return{sec:t,nsec:n}}default:throw new x(`Unrecognized data size for timestamp (expected 4, 8, or 12): ${i.length}`)}}function mt(i){let e=gt(i);return new Date(e.sec*1e3+e.nsec/1e6)}var Re={type:lt,encode:pt,decode:mt};var le=class le{constructor(){c(this,"__brand");c(this,"builtInEncoders",[]);c(this,"builtInDecoders",[]);c(this,"encoders",[]);c(this,"decoders",[]);this.register(Re)}register({type:e,encode:t,decode:n}){if(e>=0)this.encoders[e]=t,this.decoders[e]=n;else{let r=-1-e;this.builtInEncoders[r]=t,this.builtInDecoders[r]=n}}tryToEncode(e,t){for(let n=0;n<this.builtInEncoders.length;n++){let r=this.builtInEncoders[n];if(r!=null){let s=r(e,t);if(s!=null){let o=-1-n;return new L(o,s)}}}for(let n=0;n<this.encoders.length;n++){let r=this.encoders[n];if(r!=null){let s=r(e,t);if(s!=null){let o=n;return new L(o,s)}}}return e instanceof L?e:null}decode(e,t,n){let r=t<0?this.builtInDecoders[-1-t]:this.decoders[t];return r?r(e,t,n):new L(t,e)}};c(le,"defaultCodec",new le);var $=le;function yt(i){return i instanceof ArrayBuffer||typeof SharedArrayBuffer<"u"&&i instanceof SharedArrayBuffer}function q(i){return i instanceof Uint8Array?i:ArrayBuffer.isView(i)?new Uint8Array(i.buffer,i.byteOffset,i.byteLength):yt(i)?new Uint8Array(i):Uint8Array.from(i)}var wt=100,xt=2048,de=class i{constructor(e){c(this,"extensionCodec");c(this,"context");c(this,"useBigInt64");c(this,"maxDepth");c(this,"initialBufferSize");c(this,"sortKeys");c(this,"forceFloat32");c(this,"ignoreUndefined");c(this,"forceIntegerToFloat");c(this,"pos");c(this,"view");c(this,"bytes");c(this,"entered",!1);this.extensionCodec=e?.extensionCodec??$.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.maxDepth=e?.maxDepth??wt,this.initialBufferSize=e?.initialBufferSize??xt,this.sortKeys=e?.sortKeys??!1,this.forceFloat32=e?.forceFloat32??!1,this.ignoreUndefined=e?.ignoreUndefined??!1,this.forceIntegerToFloat=e?.forceIntegerToFloat??!1,this.pos=0,this.view=new DataView(new ArrayBuffer(this.initialBufferSize)),this.bytes=new Uint8Array(this.view.buffer)}clone(){return new i({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,maxDepth:this.maxDepth,initialBufferSize:this.initialBufferSize,sortKeys:this.sortKeys,forceFloat32:this.forceFloat32,ignoreUndefined:this.ignoreUndefined,forceIntegerToFloat:this.forceIntegerToFloat})}reinitializeState(){this.pos=0}encodeSharedRef(e){if(this.entered)return this.clone().encodeSharedRef(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.subarray(0,this.pos)}finally{this.entered=!1}}encode(e){if(this.entered)return this.clone().encode(e);try{return this.entered=!0,this.reinitializeState(),this.doEncode(e,1),this.bytes.slice(0,this.pos)}finally{this.entered=!1}}doEncode(e,t){if(t>this.maxDepth)throw new Error(`Too deep objects in depth ${t}`);e==null?this.encodeNil():typeof e=="boolean"?this.encodeBoolean(e):typeof e=="number"?this.forceIntegerToFloat?this.encodeNumberAsFloat(e):this.encodeNumber(e):typeof e=="string"?this.encodeString(e):this.useBigInt64&&typeof e=="bigint"?this.encodeBigInt64(e):this.encodeObject(e,t)}ensureBufferSizeToWrite(e){let t=this.pos+e;this.view.byteLength<t&&this.resizeBuffer(t*2)}resizeBuffer(e){let t=new ArrayBuffer(e),n=new Uint8Array(t),r=new DataView(t);n.set(this.bytes),this.view=r,this.bytes=n}encodeNil(){this.writeU8(192)}encodeBoolean(e){e===!1?this.writeU8(194):this.writeU8(195)}encodeNumber(e){!this.forceIntegerToFloat&&Number.isSafeInteger(e)?e>=0?e<128?this.writeU8(e):e<256?(this.writeU8(204),this.writeU8(e)):e<65536?(this.writeU8(205),this.writeU16(e)):e<4294967296?(this.writeU8(206),this.writeU32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(207),this.writeU64(e)):e>=-32?this.writeU8(224|e+32):e>=-128?(this.writeU8(208),this.writeI8(e)):e>=-32768?(this.writeU8(209),this.writeI16(e)):e>=-2147483648?(this.writeU8(210),this.writeI32(e)):this.useBigInt64?this.encodeNumberAsFloat(e):(this.writeU8(211),this.writeI64(e)):this.encodeNumberAsFloat(e)}encodeNumberAsFloat(e){this.forceFloat32?(this.writeU8(202),this.writeF32(e)):(this.writeU8(203),this.writeF64(e))}encodeBigInt64(e){e>=BigInt(0)?(this.writeU8(207),this.writeBigUint64(e)):(this.writeU8(211),this.writeBigInt64(e))}writeStringHeader(e){if(e<32)this.writeU8(160+e);else if(e<256)this.writeU8(217),this.writeU8(e);else if(e<65536)this.writeU8(218),this.writeU16(e);else if(e<4294967296)this.writeU8(219),this.writeU32(e);else throw new Error(`Too long string: ${e} bytes in UTF-8`)}encodeString(e){let n=Ce(e);this.ensureBufferSizeToWrite(5+n),this.writeStringHeader(n),Le(e,this.bytes,this.pos),this.pos+=n}encodeObject(e,t){let n=this.extensionCodec.tryToEncode(e,this.context);if(n!=null)this.encodeExtension(n);else if(Array.isArray(e))this.encodeArray(e,t);else if(ArrayBuffer.isView(e))this.encodeBinary(e);else if(typeof e=="object")this.encodeMap(e,t);else throw new Error(`Unrecognized object: ${Object.prototype.toString.apply(e)}`)}encodeBinary(e){let t=e.byteLength;if(t<256)this.writeU8(196),this.writeU8(t);else if(t<65536)this.writeU8(197),this.writeU16(t);else if(t<4294967296)this.writeU8(198),this.writeU32(t);else throw new Error(`Too large binary: ${t}`);let n=q(e);this.writeU8a(n)}encodeArray(e,t){let n=e.length;if(n<16)this.writeU8(144+n);else if(n<65536)this.writeU8(220),this.writeU16(n);else if(n<4294967296)this.writeU8(221),this.writeU32(n);else throw new Error(`Too large array: ${n}`);for(let r of e)this.doEncode(r,t+1)}countWithoutUndefined(e,t){let n=0;for(let r of t)e[r]!==void 0&&n++;return n}encodeMap(e,t){let n=Object.keys(e);this.sortKeys&&n.sort();let r=this.ignoreUndefined?this.countWithoutUndefined(e,n):n.length;if(r<16)this.writeU8(128+r);else if(r<65536)this.writeU8(222),this.writeU16(r);else if(r<4294967296)this.writeU8(223),this.writeU32(r);else throw new Error(`Too large map object: ${r}`);for(let s of n){let o=e[s];this.ignoreUndefined&&o===void 0||(this.encodeString(s),this.doEncode(o,t+1))}}encodeExtension(e){if(typeof e.data=="function"){let n=e.data(this.pos+6),r=n.length;if(r>=4294967296)throw new Error(`Too large extension object: ${r}`);this.writeU8(201),this.writeU32(r),this.writeI8(e.type),this.writeU8a(n);return}let t=e.data.length;if(t===1)this.writeU8(212);else if(t===2)this.writeU8(213);else if(t===4)this.writeU8(214);else if(t===8)this.writeU8(215);else if(t===16)this.writeU8(216);else if(t<256)this.writeU8(199),this.writeU8(t);else if(t<65536)this.writeU8(200),this.writeU16(t);else if(t<4294967296)this.writeU8(201),this.writeU32(t);else throw new Error(`Too large extension object: ${t}`);this.writeI8(e.type),this.writeU8a(e.data)}writeU8(e){this.ensureBufferSizeToWrite(1),this.view.setUint8(this.pos,e),this.pos++}writeU8a(e){let t=e.length;this.ensureBufferSizeToWrite(t),this.bytes.set(e,this.pos),this.pos+=t}writeI8(e){this.ensureBufferSizeToWrite(1),this.view.setInt8(this.pos,e),this.pos++}writeU16(e){this.ensureBufferSizeToWrite(2),this.view.setUint16(this.pos,e),this.pos+=2}writeI16(e){this.ensureBufferSizeToWrite(2),this.view.setInt16(this.pos,e),this.pos+=2}writeU32(e){this.ensureBufferSizeToWrite(4),this.view.setUint32(this.pos,e),this.pos+=4}writeI32(e){this.ensureBufferSizeToWrite(4),this.view.setInt32(this.pos,e),this.pos+=4}writeF32(e){this.ensureBufferSizeToWrite(4),this.view.setFloat32(this.pos,e),this.pos+=4}writeF64(e){this.ensureBufferSizeToWrite(8),this.view.setFloat64(this.pos,e),this.pos+=8}writeU64(e){this.ensureBufferSizeToWrite(8),He(this.view,this.pos,e),this.pos+=8}writeI64(e){this.ensureBufferSizeToWrite(8),ae(this.view,this.pos,e),this.pos+=8}writeBigUint64(e){this.ensureBufferSizeToWrite(8),this.view.setBigUint64(this.pos,e),this.pos+=8}writeBigInt64(e){this.ensureBufferSizeToWrite(8),this.view.setBigInt64(this.pos,e),this.pos+=8}};function N(i,e){return new de(e).encodeSharedRef(i)}function he(i){return`${i<0?"-":""}0x${Math.abs(i).toString(16).padStart(2,"0")}`}var vt=16,St=16,fe=class{constructor(e=vt,t=St){c(this,"hit",0);c(this,"miss",0);c(this,"caches");c(this,"maxKeyLength");c(this,"maxLengthPerKey");this.maxKeyLength=e,this.maxLengthPerKey=t,this.caches=[];for(let n=0;n<this.maxKeyLength;n++)this.caches.push([])}canBeCached(e){return e>0&&e<=this.maxKeyLength}find(e,t,n){let r=this.caches[n-1];e:for(let s of r){let o=s.bytes;for(let a=0;a<n;a++)if(o[a]!==e[t+a])continue e;return s.str}return null}store(e,t){let n=this.caches[e.length-1],r={bytes:e,str:t};n.length>=this.maxLengthPerKey?n[Math.random()*n.length|0]=r:n.push(r)}decode(e,t,n){let r=this.find(e,t,n);if(r!=null)return this.hit++,r;this.miss++;let s=be(e,t,n),o=Uint8Array.prototype.slice.call(e,t,t+n);return this.store(o,s),s}};var Te="array",j="map_key",Ne="map_value",bt=i=>{if(typeof i=="string"||typeof i=="number")return i;throw new x("The type of key must be string or number but "+typeof i)},Ue=class{constructor(){c(this,"stack",[]);c(this,"stackHeadPosition",-1)}get length(){return this.stackHeadPosition+1}top(){return this.stack[this.stackHeadPosition]}pushArrayState(e){let t=this.getUninitializedStateFromPool();t.type=Te,t.position=0,t.size=e,t.array=new Array(e)}pushMapState(e){let t=this.getUninitializedStateFromPool();t.type=j,t.readCount=0,t.size=e,t.map={}}getUninitializedStateFromPool(){if(this.stackHeadPosition++,this.stackHeadPosition===this.stack.length){let e={type:void 0,size:0,array:void 0,position:0,readCount:0,map:void 0,key:null};this.stack.push(e)}return this.stack[this.stackHeadPosition]}release(e){if(this.stack[this.stackHeadPosition]!==e)throw new Error("Invalid stack state. Released state is not on top of the stack.");if(e.type===Te){let n=e;n.size=0,n.array=void 0,n.position=0,n.type=void 0}if(e.type===j||e.type===Ne){let n=e;n.size=0,n.map=void 0,n.readCount=0,n.type=void 0}this.stackHeadPosition--}reset(){this.stack.length=0,this.stackHeadPosition=-1}},Q=-1,Ee=new DataView(new ArrayBuffer(0)),Tt=new Uint8Array(Ee.buffer);try{Ee.getInt8(0)}catch(i){if(!(i instanceof RangeError))throw new Error("This module is not supported in the current JavaScript engine because DataView does not throw RangeError on out-of-bounds access")}var $e=new RangeError("Insufficient data"),Ut=new fe,ue=class i{constructor(e){c(this,"extensionCodec");c(this,"context");c(this,"useBigInt64");c(this,"rawStrings");c(this,"maxStrLength");c(this,"maxBinLength");c(this,"maxArrayLength");c(this,"maxMapLength");c(this,"maxExtLength");c(this,"keyDecoder");c(this,"mapKeyConverter");c(this,"totalPos",0);c(this,"pos",0);c(this,"view",Ee);c(this,"bytes",Tt);c(this,"headByte",Q);c(this,"stack",new Ue);c(this,"entered",!1);this.extensionCodec=e?.extensionCodec??$.defaultCodec,this.context=e?.context,this.useBigInt64=e?.useBigInt64??!1,this.rawStrings=e?.rawStrings??!1,this.maxStrLength=e?.maxStrLength??4294967295,this.maxBinLength=e?.maxBinLength??4294967295,this.maxArrayLength=e?.maxArrayLength??4294967295,this.maxMapLength=e?.maxMapLength??4294967295,this.maxExtLength=e?.maxExtLength??4294967295,this.keyDecoder=e?.keyDecoder!==void 0?e.keyDecoder:Ut,this.mapKeyConverter=e?.mapKeyConverter??bt}clone(){return new i({extensionCodec:this.extensionCodec,context:this.context,useBigInt64:this.useBigInt64,rawStrings:this.rawStrings,maxStrLength:this.maxStrLength,maxBinLength:this.maxBinLength,maxArrayLength:this.maxArrayLength,maxMapLength:this.maxMapLength,maxExtLength:this.maxExtLength,keyDecoder:this.keyDecoder})}reinitializeState(){this.totalPos=0,this.headByte=Q,this.stack.reset()}setBuffer(e){let t=q(e);this.bytes=t,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength),this.pos=0}appendBuffer(e){if(this.headByte===Q&&!this.hasRemaining(1))this.setBuffer(e);else{let t=this.bytes.subarray(this.pos),n=q(e),r=new Uint8Array(t.length+n.length);r.set(t),r.set(n,t.length),this.setBuffer(r)}}hasRemaining(e){return this.view.byteLength-this.pos>=e}createExtraByteError(e){let{view:t,pos:n}=this;return new RangeError(`Extra ${t.byteLength-n} of ${t.byteLength} byte(s) found at buffer[${e}]`)}decode(e){if(this.entered)return this.clone().decode(e);try{this.entered=!0,this.reinitializeState(),this.setBuffer(e);let t=this.doDecodeSync();if(this.hasRemaining(1))throw this.createExtraByteError(this.pos);return t}finally{this.entered=!1}}*decodeMulti(e){if(this.entered){yield*this.clone().decodeMulti(e);return}try{for(this.entered=!0,this.reinitializeState(),this.setBuffer(e);this.hasRemaining(1);)yield this.doDecodeSync()}finally{this.entered=!1}}async decodeAsync(e){if(this.entered)return this.clone().decodeAsync(e);try{this.entered=!0;let t=!1,n;for await(let a of e){if(t)throw this.entered=!1,this.createExtraByteError(this.totalPos);this.appendBuffer(a);try{n=this.doDecodeSync(),t=!0}catch(l){if(!(l instanceof RangeError))throw l}this.totalPos+=this.pos}if(t){if(this.hasRemaining(1))throw this.createExtraByteError(this.totalPos);return n}let{headByte:r,pos:s,totalPos:o}=this;throw new RangeError(`Insufficient data in parsing ${he(r)} at ${o} (${s} in the current buffer)`)}finally{this.entered=!1}}decodeArrayStream(e){return this.decodeMultiAsync(e,!0)}decodeStream(e){return this.decodeMultiAsync(e,!1)}async*decodeMultiAsync(e,t){if(this.entered){yield*this.clone().decodeMultiAsync(e,t);return}try{this.entered=!0;let n=t,r=-1;for await(let s of e){if(t&&r===0)throw this.createExtraByteError(this.totalPos);this.appendBuffer(s),n&&(r=this.readArraySize(),n=!1,this.complete());try{for(;yield this.doDecodeSync(),--r!==0;);}catch(o){if(!(o instanceof RangeError))throw o}this.totalPos+=this.pos}}finally{this.entered=!1}}doDecodeSync(){e:for(;;){let e=this.readHeadByte(),t;if(e>=224)t=e-256;else if(e<192)if(e<128)t=e;else if(e<144){let r=e-128;if(r!==0){this.pushMapState(r),this.complete();continue e}else t={}}else if(e<160){let r=e-144;if(r!==0){this.pushArrayState(r),this.complete();continue e}else t=[]}else{let r=e-160;t=this.decodeString(r,0)}else if(e===192)t=null;else if(e===194)t=!1;else if(e===195)t=!0;else if(e===202)t=this.readF32();else if(e===203)t=this.readF64();else if(e===204)t=this.readU8();else if(e===205)t=this.readU16();else if(e===206)t=this.readU32();else if(e===207)this.useBigInt64?t=this.readU64AsBigInt():t=this.readU64();else if(e===208)t=this.readI8();else if(e===209)t=this.readI16();else if(e===210)t=this.readI32();else if(e===211)this.useBigInt64?t=this.readI64AsBigInt():t=this.readI64();else if(e===217){let r=this.lookU8();t=this.decodeString(r,1)}else if(e===218){let r=this.lookU16();t=this.decodeString(r,2)}else if(e===219){let r=this.lookU32();t=this.decodeString(r,4)}else if(e===220){let r=this.readU16();if(r!==0){this.pushArrayState(r),this.complete();continue e}else t=[]}else if(e===221){let r=this.readU32();if(r!==0){this.pushArrayState(r),this.complete();continue e}else t=[]}else if(e===222){let r=this.readU16();if(r!==0){this.pushMapState(r),this.complete();continue e}else t={}}else if(e===223){let r=this.readU32();if(r!==0){this.pushMapState(r),this.complete();continue e}else t={}}else if(e===196){let r=this.lookU8();t=this.decodeBinary(r,1)}else if(e===197){let r=this.lookU16();t=this.decodeBinary(r,2)}else if(e===198){let r=this.lookU32();t=this.decodeBinary(r,4)}else if(e===212)t=this.decodeExtension(1,0);else if(e===213)t=this.decodeExtension(2,0);else if(e===214)t=this.decodeExtension(4,0);else if(e===215)t=this.decodeExtension(8,0);else if(e===216)t=this.decodeExtension(16,0);else if(e===199){let r=this.lookU8();t=this.decodeExtension(r,1)}else if(e===200){let r=this.lookU16();t=this.decodeExtension(r,2)}else if(e===201){let r=this.lookU32();t=this.decodeExtension(r,4)}else throw new x(`Unrecognized type byte: ${he(e)}`);this.complete();let n=this.stack;for(;n.length>0;){let r=n.top();if(r.type===Te)if(r.array[r.position]=t,r.position++,r.position===r.size)t=r.array,n.release(r);else continue e;else if(r.type===j){if(t==="__proto__")throw new x("The key __proto__ is not allowed");r.key=this.mapKeyConverter(t),r.type=Ne;continue e}else if(r.map[r.key]=t,r.readCount++,r.readCount===r.size)t=r.map,n.release(r);else{r.key=null,r.type=j;continue e}}return t}}readHeadByte(){return this.headByte===Q&&(this.headByte=this.readU8()),this.headByte}complete(){this.headByte=Q}readArraySize(){let e=this.readHeadByte();switch(e){case 220:return this.readU16();case 221:return this.readU32();default:{if(e<160)return e-144;throw new x(`Unrecognized array type byte: ${he(e)}`)}}}pushMapState(e){if(e>this.maxMapLength)throw new x(`Max length exceeded: map length (${e}) > maxMapLengthLength (${this.maxMapLength})`);this.stack.pushMapState(e)}pushArrayState(e){if(e>this.maxArrayLength)throw new x(`Max length exceeded: array length (${e}) > maxArrayLength (${this.maxArrayLength})`);this.stack.pushArrayState(e)}decodeString(e,t){return!this.rawStrings||this.stateIsMapKey()?this.decodeUtf8String(e,t):this.decodeBinary(e,t)}decodeUtf8String(e,t){if(e>this.maxStrLength)throw new x(`Max length exceeded: UTF-8 byte length (${e}) > maxStrLength (${this.maxStrLength})`);if(this.bytes.byteLength<this.pos+t+e)throw $e;let n=this.pos+t,r;return this.stateIsMapKey()&&this.keyDecoder?.canBeCached(e)?r=this.keyDecoder.decode(this.bytes,n,e):r=We(this.bytes,n,e),this.pos+=t+e,r}stateIsMapKey(){return this.stack.length>0?this.stack.top().type===j:!1}decodeBinary(e,t){if(e>this.maxBinLength)throw new x(`Max length exceeded: bin length (${e}) > maxBinLength (${this.maxBinLength})`);if(!this.hasRemaining(e+t))throw $e;let n=this.pos+t,r=this.bytes.subarray(n,n+e);return this.pos+=t+e,r}decodeExtension(e,t){if(e>this.maxExtLength)throw new x(`Max length exceeded: ext length (${e}) > maxExtLength (${this.maxExtLength})`);let n=this.view.getInt8(this.pos+t),r=this.decodeBinary(e,t+1);return this.extensionCodec.decode(r,n,this.context)}lookU8(){return this.view.getUint8(this.pos)}lookU16(){return this.view.getUint16(this.pos)}lookU32(){return this.view.getUint32(this.pos)}readU8(){let e=this.view.getUint8(this.pos);return this.pos++,e}readI8(){let e=this.view.getInt8(this.pos);return this.pos++,e}readU16(){let e=this.view.getUint16(this.pos);return this.pos+=2,e}readI16(){let e=this.view.getInt16(this.pos);return this.pos+=2,e}readU32(){let e=this.view.getUint32(this.pos);return this.pos+=4,e}readI32(){let e=this.view.getInt32(this.pos);return this.pos+=4,e}readU64(){let e=De(this.view,this.pos);return this.pos+=8,e}readI64(){let e=ce(this.view,this.pos);return this.pos+=8,e}readU64AsBigInt(){let e=this.view.getBigUint64(this.pos);return this.pos+=8,e}readI64AsBigInt(){let e=this.view.getBigInt64(this.pos);return this.pos+=8,e}readF32(){let e=this.view.getFloat32(this.pos);return this.pos+=4,e}readF64(){let e=this.view.getFloat64(this.pos);return this.pos+=8,e}};function W(i,e){return new ue(e).decode(i)}var F=class extends B{constructor(t){super();this.name="WebSocket";this.socket=null;this.reconnectAttempts=0;this.maxReconnectDelay=5e3;this.shouldReconnect=!0;this.url=t||this.getDefaultUrl()}getDefaultUrl(){return`${window.location.protocol==="https:"?"wss:":"ws:"}//${window.location.host}/_pywire/ws`}connect(){return new Promise((t,n)=>{try{this.socket=new WebSocket(this.url),this.socket.binaryType="arraybuffer",this.socket.onopen=()=>{console.log("PyWire: WebSocket connected"),this.notifyStatus(!0),this.reconnectAttempts=0,t()},this.socket.onmessage=r=>{try{let s=W(r.data);this.notifyHandlers(s)}catch(s){console.error("PyWire: Error parsing WebSocket message",s)}},this.socket.onclose=()=>{console.log("PyWire: WebSocket disconnected"),this.notifyStatus(!1),this.shouldReconnect&&this.scheduleReconnect()},this.socket.onerror=r=>{console.error("PyWire: WebSocket error",r),this.connected||n(new Error("WebSocket connection failed"))}}catch(r){n(r)}})}send(t){this.socket&&this.socket.readyState===WebSocket.OPEN?this.socket.send(N(t)):console.warn("PyWire: Cannot send message, WebSocket not open")}disconnect(){this.shouldReconnect=!1,this.socket&&(this.socket.close(),this.socket=null),this.notifyStatus(!1)}scheduleReconnect(){let t=Math.min(1e3*Math.pow(2,this.reconnectAttempts),this.maxReconnectDelay);console.log(`PyWire: Reconnecting in ${t}ms...`),setTimeout(()=>{this.reconnectAttempts++,this.connect().catch(()=>{})},t)}};var z=class extends B{constructor(t){super();this.name="HTTP";this.polling=!1;this.pollAbortController=null;this.sessionId=null;this.baseUrl=t||`${window.location.origin}/_pywire`}async connect(){try{let t=await fetch(`${this.baseUrl}/session`,{method:"POST",headers:{"Content-Type":"application/x-msgpack",Accept:"application/x-msgpack"},body:N({path:window.location.pathname+window.location.search})});if(!t.ok)throw new Error(`HTTP session init failed: ${t.status}`);let n=await t.arrayBuffer(),r=W(n);this.sessionId=r.sessionId,console.log("PyWire: HTTP transport connected"),this.notifyStatus(!0),this.startPolling()}catch(t){throw console.error("PyWire: HTTP transport connection failed",t),t}}async startPolling(){if(!this.polling)for(this.polling=!0;this.polling&&this.connected;)try{this.pollAbortController=new AbortController;let t=await fetch(`${this.baseUrl}/poll?session=${this.sessionId}`,{method:"GET",signal:this.pollAbortController.signal,headers:{Accept:"application/x-msgpack"}});if(!t.ok){if(t.status===404){console.warn("PyWire: HTTP session expired, reconnecting..."),this.notifyStatus(!1),await this.connect();return}throw new Error(`Poll failed: ${t.status}`)}let n=await t.arrayBuffer(),r=W(n);for(let s of r)this.notifyHandlers(s)}catch(t){if(t instanceof Error&&t.name==="AbortError")break;console.error("PyWire: HTTP poll error",t),await this.sleep(1e3)}}async send(t){if(!this.connected||!this.sessionId){console.warn("PyWire: Cannot send message, HTTP transport not connected");return}try{let n=await fetch(`${this.baseUrl}/event`,{method:"POST",headers:{"Content-Type":"application/x-msgpack",Accept:"application/x-msgpack","X-PyWire-Session":this.sessionId},body:N(t)});if(!n.ok)throw new Error(`Event send failed: ${n.status}`);let r=await n.arrayBuffer(),s=W(r);this.notifyHandlers(s)}catch(n){console.error("PyWire: HTTP send error",n)}}disconnect(){this.polling=!1,this.notifyStatus(!1),this.pollAbortController&&(this.pollAbortController.abort(),this.pollAbortController=null),this.sessionId=null}sleep(t){return new Promise(n=>setTimeout(n,t))}};var Et={enableWebTransport:!0,enableWebSocket:!0,enableHTTP:!0},_=class{constructor(e={}){this.transport=null;this.messageHandlers=[];this.statusHandlers=[];this.config={...Et,...e}}async connect(){let e=this.getTransportPriority();for(let t of e)try{console.log(`PyWire: Trying ${t.name}...`),this.transport=new t;for(let n of this.messageHandlers)this.transport.onMessage(n);this.transport.onStatusChange(n=>{this.notifyStatusHandlers(n)}),await this.transport.connect(),console.log(`PyWire: Connected via ${this.transport.name}`);return}catch(n){console.warn(`PyWire: ${t.name} failed, trying next...`,n),this.transport=null}throw new Error("PyWire: All transports failed")}getTransportPriority(){let e=[];return this.config.enableWebTransport&&C.isSupported()&&window.location.protocol==="https:"&&e.push(C),this.config.enableWebSocket&&typeof WebSocket<"u"&&e.push(F),this.config.enableHTTP&&e.push(z),e}send(e){this.transport?this.transport.send(e):console.warn("PyWire: No active transport")}onMessage(e){this.messageHandlers.push(e),this.transport&&this.transport.onMessage(e)}onStatusChange(e){this.statusHandlers.push(e)}notifyStatusHandlers(e){for(let t of this.statusHandlers)t(e)}disconnect(){this.transport&&(this.transport.disconnect(),this.transport=null,this.notifyStatusHandlers(!1))}getActiveTransport(){return this.transport?.name||null}isConnected(){return this.transport?.isConnected()||!1}};var Fe=11;function At(i,e){var t=e.attributes,n,r,s,o,a;if(!(e.nodeType===Fe||i.nodeType===Fe)){for(var l=t.length-1;l>=0;l--)n=t[l],r=n.name,s=n.namespaceURI,o=n.value,s?(r=n.localName||r,a=i.getAttributeNS(s,r),a!==o&&(n.prefix==="xmlns"&&(r=n.name),i.setAttributeNS(s,r,o))):(a=i.getAttribute(r),a!==o&&i.setAttribute(r,o));for(var p=i.attributes,y=p.length-1;y>=0;y--)n=p[y],r=n.name,s=n.namespaceURI,s?(r=n.localName||r,e.hasAttributeNS(s,r)||i.removeAttributeNS(s,r)):e.hasAttribute(r)||i.removeAttribute(r)}}var pe,kt="http://www.w3.org/1999/xhtml",v=typeof document>"u"?void 0:document,Mt=!!v&&"content"in v.createElement("template"),Pt=!!v&&v.createRange&&"createContextualFragment"in v.createRange();function Bt(i){var e=v.createElement("template");return e.innerHTML=i,e.content.childNodes[0]}function It(i){pe||(pe=v.createRange(),pe.selectNode(v.body));var e=pe.createContextualFragment(i);return e.childNodes[0]}function Ct(i){var e=v.createElement("body");return e.innerHTML=i,e.childNodes[0]}function Lt(i){return i=i.trim(),Mt?Bt(i):Pt?It(i):Ct(i)}function ge(i,e){var t=i.nodeName,n=e.nodeName,r,s;return t===n?!0:(r=t.charCodeAt(0),s=n.charCodeAt(0),r<=90&&s>=97?t===n.toUpperCase():s<=90&&r>=97?n===t.toUpperCase():!1)}function Wt(i,e){return!e||e===kt?v.createElement(i):v.createElementNS(e,i)}function Ht(i,e){for(var t=i.firstChild;t;){var n=t.nextSibling;e.appendChild(t),t=n}return e}function Ae(i,e,t){i[t]!==e[t]&&(i[t]=e[t],i[t]?i.setAttribute(t,""):i.removeAttribute(t))}var ze={OPTION:function(i,e){var t=i.parentNode;if(t){var n=t.nodeName.toUpperCase();n==="OPTGROUP"&&(t=t.parentNode,n=t&&t.nodeName.toUpperCase()),n==="SELECT"&&!t.hasAttribute("multiple")&&(i.hasAttribute("selected")&&!e.selected&&(i.setAttribute("selected","selected"),i.removeAttribute("selected")),t.selectedIndex=-1)}Ae(i,e,"selected")},INPUT:function(i,e){Ae(i,e,"checked"),Ae(i,e,"disabled"),i.value!==e.value&&(i.value=e.value),e.hasAttribute("value")||i.removeAttribute("value")},TEXTAREA:function(i,e){var t=e.value;i.value!==t&&(i.value=t);var n=i.firstChild;if(n){var r=n.nodeValue;if(r==t||!t&&r==i.placeholder)return;n.nodeValue=t}},SELECT:function(i,e){if(!e.hasAttribute("multiple")){for(var t=-1,n=0,r=i.firstChild,s,o;r;)if(o=r.nodeName&&r.nodeName.toUpperCase(),o==="OPTGROUP")s=r,r=s.firstChild,r||(r=s.nextSibling,s=null);else{if(o==="OPTION"){if(r.hasAttribute("selected")){t=n;break}n++}r=r.nextSibling,!r&&s&&(r=s.nextSibling,s=null)}i.selectedIndex=t}}},ee=1,_e=11,Ke=3,Oe=8;function I(){}function Dt(i){if(i)return i.getAttribute&&i.getAttribute("id")||i.id}function Rt(i){return function(t,n,r){if(r||(r={}),typeof n=="string")if(t.nodeName==="#document"||t.nodeName==="HTML"||t.nodeName==="BODY"){var s=n;n=v.createElement("html"),n.innerHTML=s}else n=Lt(n);else n.nodeType===_e&&(n=n.firstElementChild);var o=r.getNodeKey||Dt,a=r.onBeforeNodeAdded||I,l=r.onNodeAdded||I,p=r.onBeforeElUpdated||I,y=r.onElUpdated||I,g=r.onBeforeNodeDiscarded||I,E=r.onNodeDiscarded||I,Y=r.onBeforeElChildrenUpdated||I,S=r.skipFromChildren||I,J=r.addChild||function(d,h){return d.appendChild(h)},H=r.childrenOnly===!0,b=Object.create(null),A=[];function k(d){A.push(d)}function Pe(d,h){if(d.nodeType===ee)for(var m=d.firstChild;m;){var f=void 0;h&&(f=o(m))?k(f):(E(m),m.firstChild&&Pe(m,h)),m=m.nextSibling}}function te(d,h,m){g(d)!==!1&&(h&&h.removeChild(d),E(d),Pe(d,m))}function ye(d){if(d.nodeType===ee||d.nodeType===_e)for(var h=d.firstChild;h;){var m=o(h);m&&(b[m]=h),ye(h),h=h.nextSibling}}ye(t);function we(d){l(d);for(var h=d.firstChild;h;){var m=h.nextSibling,f=o(h);if(f){var u=b[f];u&&ge(h,u)?(h.parentNode.replaceChild(u,h),ne(u,h)):we(h)}else we(h);h=m}}function Ve(d,h,m){for(;h;){var f=h.nextSibling;(m=o(h))?k(m):te(h,d,!0),h=f}}function ne(d,h,m){var f=o(h);if(f&&delete b[f],!m){var u=p(d,h);if(u===!1||(u instanceof HTMLElement&&(d=u,ye(d)),i(d,h),y(d),Y(d,h)===!1))return}d.nodeName!=="TEXTAREA"?Xe(d,h):ze.TEXTAREA(d,h)}function Xe(d,h){var m=S(d,h),f=h.firstChild,u=d.firstChild,D,U,R,ie,M;e:for(;f;){for(ie=f.nextSibling,D=o(f);!m&&u;){if(R=u.nextSibling,f.isSameNode&&f.isSameNode(u)){f=ie,u=R;continue e}U=o(u);var se=u.nodeType,P=void 0;if(se===f.nodeType&&(se===ee?(D?D!==U&&((M=b[D])?R===M?P=!1:(d.insertBefore(M,u),U?k(U):te(u,d,!0),u=M,U=o(u)):P=!1):U&&(P=!1),P=P!==!1&&ge(u,f),P&&ne(u,f)):(se===Ke||se==Oe)&&(P=!0,u.nodeValue!==f.nodeValue&&(u.nodeValue=f.nodeValue))),P){f=ie,u=R;continue e}U?k(U):te(u,d,!0),u=R}if(D&&(M=b[D])&&ge(M,f))m||J(d,M),ne(M,f);else{var Se=a(f);Se!==!1&&(Se&&(f=Se),f.actualize&&(f=f.actualize(d.ownerDocument||v)),J(d,f),we(f))}f=ie,u=R}Ve(d,u,U);var Ie=ze[d.nodeName];Ie&&Ie(d,h)}var w=t,re=w.nodeType,Be=n.nodeType;if(!H){if(re===ee)Be===ee?ge(t,n)||(E(t),w=Ht(t,Wt(n.nodeName,n.namespaceURI))):w=n;else if(re===Ke||re===Oe){if(Be===re)return w.nodeValue!==n.nodeValue&&(w.nodeValue=n.nodeValue),w;w=n}}if(w===n)E(t);else{if(n.isSameNode&&n.isSameNode(w))return;if(ne(w,n,H),A)for(var xe=0,Ge=A.length;xe<Ge;xe++){var ve=b[A[xe]];ve&&te(ve,ve.parentNode,!1)}}return!H&&w!==t&&t.parentNode&&(w.actualize&&(w=w.actualize(t.ownerDocument||v)),t.parentNode.replaceChild(w,t)),w}}var $t=Rt(At),ke=$t;var K=class K{constructor(e=!1){this.debug=e}getNodeKey(e){if(e instanceof HTMLElement){for(let t of e.attributes)if(t.name.startsWith("data-on-"))return`${e.tagName}-${t.name}-${t.value}`;if(e.id&&!e.id.startsWith("pywire-uid-"))return e.id;if((e instanceof HTMLInputElement||e instanceof HTMLSelectElement||e instanceof HTMLTextAreaElement)&&e.name)return`${e.tagName}-name-${e.name}`}}getElementSelector(e){if(e.id)return`#${e.id}`;let t=[],n=e;for(;n&&n!==document.body&&t.length<5;){let r=n.tagName.toLowerCase();if(n.id){r=`#${n.id}`,t.unshift(r);break}(n instanceof HTMLInputElement||n instanceof HTMLSelectElement||n instanceof HTMLTextAreaElement)&&n.name&&(r+=`[name="${n.name}"]`);for(let s of n.attributes)if(s.name.startsWith("data-on-")){r+=`[${s.name}="${s.value}"]`;break}if(n.parentElement){let o=Array.from(n.parentElement.children).filter(a=>a.tagName===n.tagName);if(o.length>1){let a=o.indexOf(n)+1;r+=`:nth-of-type(${a})`}}t.unshift(r),n=n.parentElement}return t.join(" > ")}captureFocusState(){let e=document.activeElement;if(!e||e===document.body||e===document.documentElement)return null;let t={selector:this.getElementSelector(e),id:e.id||null,tagName:e.tagName,selectionStart:null,selectionEnd:null,scrollTop:0,scrollLeft:0,value:""};return(e instanceof HTMLInputElement||e instanceof HTMLTextAreaElement)&&(t.selectionStart=e.selectionStart,t.selectionEnd=e.selectionEnd,t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft,t.value=e.value),t}restoreFocusState(e){if(!e)return;let t=null;if(e.id&&(t=document.getElementById(e.id)),!t&&e.selector)try{t=document.querySelector(e.selector)}catch{}if(t&&(t.focus(),t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement)){if(e.value&&t.value!==e.value&&(t.value=e.value),e.selectionStart!==null&&e.selectionEnd!==null)try{t.setSelectionRange(e.selectionStart,e.selectionEnd)}catch{}t.scrollTop=e.scrollTop,t.scrollLeft=e.scrollLeft}}applyUpdate(e,t){K.isUpdating=!0,this.debug&&console.log("[DOMUpdater] Starting update, isUpdating =",K.isUpdating);try{let n=this.captureFocusState();if(ke){try{ke(e,t,{getNodeKey:r=>this.getNodeKey(r),onBeforeElUpdated:(r,s)=>{if(r instanceof HTMLInputElement&&s instanceof HTMLInputElement)if(r.type==="checkbox"||r.type==="radio")s.checked=r.checked;else{let o=s.value||"",a=r.value||"";(a.startsWith(o)||o.startsWith(a))&&(s.value=a)}if(r instanceof HTMLTextAreaElement&&s instanceof HTMLTextAreaElement){let o=s.value||"",a=r.value||"";(a.startsWith(o)||o.startsWith(a))&&(s.value=a)}return r instanceof HTMLSelectElement&&s instanceof HTMLSelectElement&&(r.value&&Array.from(s.options).some(o=>o.value===r.value)?s.value=r.value:r.selectedIndex>=0&&r.selectedIndex<s.options.length&&(s.selectedIndex=r.selectedIndex)),r.id&&r.id.startsWith("pywire-uid-")&&!s.id&&(s.id=r.id),!0},onBeforeNodeDiscarded:()=>!0})}catch(r){console.error("Morphdom failed:",r),e===document.documentElement&&(document.open(),document.write(t),document.close())}this.restoreFocusState(n)}else e===document.documentElement&&(document.open(),document.write(t),document.close())}finally{setTimeout(()=>{K.isUpdating=!1},0)}}update(e){let t=/<html[\s>]/i.test(e),n=/<body[\s>]/i.test(e);if(!t&&document.body){if(n){this.applyUpdate(document.body,e);return}let r=`<body>${e}</body>`;this.applyUpdate(document.body,r);return}this.applyUpdate(document.documentElement,e)}updateRegion(e,t){let n=document.querySelector(`[data-pw-region="${e}"]`);if(!n){this.debug&&console.warn("[DOMUpdater] Region not found:",e);return}this.applyUpdate(n,t),n.getAttribute("data-pw-region")||n.setAttribute("data-pw-region",e)}};K.isUpdating=!1;var T=K;var me=class{constructor(e){this.debouncers=new Map;this.throttlers=new Map;this.supportedEvents=["click","submit","input","change","keydown","keyup","focus","blur","mouseenter","mouseleave","scroll","contextmenu"];this.suppressDuringUpdate=["focus","blur","mouseenter","mouseleave"];this.app=e}debugLog(...e){this.app.getConfig().debug&&console.log(...e)}init(){this.supportedEvents.forEach(e=>{let t=e==="mouseenter"||e==="mouseleave"||e==="focus"||e==="blur"||e==="scroll"?{capture:!0}:void 0;document.addEventListener(e,n=>this.handleEvent(n),t)})}getHandlers(e,t){let n=`data-on-${t}`,r=e.getAttribute(n);if(!r)return[];if(r.trim().startsWith("["))try{let s=JSON.parse(r);if(Array.isArray(s))return s.flatMap(o=>{if(!o||typeof o!="object")return[];let a="handler"in o&&typeof o.handler=="string"?o.handler:null;if(!a)return[];let l="modifiers"in o&&Array.isArray(o.modifiers)?o.modifiers.filter(y=>typeof y=="string"):[],p="args"in o&&Array.isArray(o.args)?o.args:void 0;return[{name:a,modifiers:l,args:p}]})}catch(s){console.error("Error parsing event handlers:",s)}else{let s=e.getAttribute(`data-modifiers-${t}`),o=s?s.split(" ").filter(a=>a):[];return[{name:r,modifiers:o,args:void 0}]}return[]}async handleEvent(e){let t=e.type;if(T.isUpdating&&this.suppressDuringUpdate.includes(t)){this.debugLog("[Handler] SUPPRESSING event during update:",t,"isUpdating=",T.isUpdating);return}this.debugLog("[Handler] Processing event:",t,"isUpdating=",T.isUpdating);let n=e.composedPath?e.composedPath():[],r=!1;for(let s of n){if(r)break;if(s instanceof HTMLElement){let o=s,a=this.getHandlers(o,t);if(a.length>0){this.debugLog("[handleEvent] Found handlers on",o.tagName,a);for(let l of a)!l.modifiers.includes("window")&&!l.modifiers.includes("outside")&&(this.processEvent(o,t,l.name,l.modifiers,e,l.args),e.cancelBubble&&(r=!0))}}}this.handleGlobalEvent(e)}handleGlobalEvent(e){let t=e.type,n=`[data-modifiers-${t}*="window"]`,r=`[data-modifiers-${t}*="outside"]`;document.querySelectorAll(`${n}, ${r}`).forEach(o=>{if(!(o instanceof HTMLElement))return;let a=this.getHandlers(o,t);for(let l of a)if(l.modifiers.includes("window")&&this.processEvent(o,t,l.name,l.modifiers,e,l.args),l.modifiers.includes("outside")){let p=e.target;p&&!o.contains(p)&&this.processEvent(o,t,l.name,l.modifiers,e,l.args)}})}processEvent(e,t,n,r,s,o){if(this.debugLog("[processEvent]",t,"handler:",n,"modifiers:",r),(r.includes("prevent")||t==="submit")&&(this.debugLog("[processEvent] Calling preventDefault"),s.preventDefault()),r.includes("stop")&&s.stopPropagation(),r.includes("self")&&s.target!==e||r.includes("shift")&&(!("shiftKey"in s)||!s.shiftKey)||r.includes("ctrl")&&(!("ctrlKey"in s)||!s.ctrlKey)||r.includes("alt")&&(!("altKey"in s)||!s.altKey)||r.includes("meta")&&(!("metaKey"in s)||!s.metaKey)||r.includes("cmd")&&(!("metaKey"in s)||!s.metaKey))return;if(s instanceof KeyboardEvent){let g=["enter","escape","space","tab","up","down","left","right"],E=["shift","ctrl","alt","meta","cmd","window","outside","prevent","stop","self","debounce","throttle"],Y=r.filter(S=>E.includes(S)||S.startsWith("debounce")||S.startsWith("throttle")||S.endsWith("ms")?!1:g.includes(S)||S.length===1);if(Y.length>0){let S=s.key.toLowerCase();this.debugLog("[processEvent] Key check. Pressed:",S,"Modifiers:",Y);let J={escape:"escape",esc:"escape",enter:"enter",space:" ",spacebar:" "," ":" ",tab:"tab",up:"arrowup",arrowup:"arrowup",down:"arrowdown",arrowdown:"arrowdown",left:"arrowleft",arrowleft:"arrowleft",right:"arrowright",arrowright:"arrowright"},H=J[S]||S,b=!1;for(let A of Y){let k=J[A]||A;if(this.debugLog("[processEvent] Comparing constraint:",A,"->",k,"vs",H,"code:",s.code),k===H){b=!0;break}if(s.code&&s.code.toLowerCase()===`key${k}`){b=!0;break}}if(!b){this.debugLog("[processEvent] No key match found.");return}}}let a=r.find(g=>g.startsWith("debounce")),l=r.find(g=>g.startsWith("throttle")),y=`${e.id||this.getUniqueId(e)}-${t}-${n}`;if(a){let g=this.parseDuration(r,250);this.debouncers.has(y)&&window.clearTimeout(this.debouncers.get(y));let E=window.setTimeout(()=>{this.debouncers.delete(y),this.dispatchEvent(e,t,n,s,o)},g);this.debouncers.set(y,E);return}if(l){let g=this.parseDuration(r,250);if(this.throttlers.has(y))return;this.throttlers.set(y,Date.now()),this.dispatchEvent(e,t,n,s,o),window.setTimeout(()=>{this.throttlers.delete(y)},g);return}this.dispatchEvent(e,t,n,s,o)}dispatchEvent(e,t,n,r,s){let o={};s&&s.length>0?s.forEach((l,p)=>{o[`arg${p}`]=l}):o=this.getArgs(e);let a={type:t,id:e.id,args:o};if(e instanceof HTMLInputElement?(a.value=e.value,(e.type==="checkbox"||e.type==="radio")&&(a.checked=e.checked)):(e instanceof HTMLTextAreaElement||e instanceof HTMLSelectElement)&&(a.value=e.value),r instanceof KeyboardEvent&&(a.key=r.key,a.keyCode=r.keyCode),t==="submit"&&e instanceof HTMLFormElement){let l=new FormData(e),p={};l.forEach((y,g)=>{y instanceof File||(p[g]=y.toString())}),a.formData=p}this.app.sendEvent(n,a)}parseDuration(e,t){let n=e.findIndex(a=>a.startsWith("debounce")),r=e.findIndex(a=>a.startsWith("throttle")),s=n!==-1?n:r;if(s!==-1&&e[s+1]){let a=e[s+1];if(a.endsWith("ms")){let l=parseInt(a);if(!isNaN(l))return l}}let o=e[s];if(o&&o.includes("-")){let a=o.split("-"),l=parseInt(a[1]);if(!isNaN(l))return l}return t}getUniqueId(e){return e.id||(e.id="pywire-uid-"+Math.random().toString(36).substr(2,9)),e.id}getArgs(e){let t={};if(e instanceof HTMLElement){for(let n in e.dataset)if(n.startsWith("arg"))try{t[n]=JSON.parse(e.dataset[n]||"null")}catch{t[n]=e.dataset[n]}}return t}};var Nt={autoInit:!0,enableWebTransport:!0,enableWebSocket:!0,enableHTTP:!0,debug:!1},O=class{constructor(e={}){this.initialized=!1;this.siblingPaths=[];this.pathRegexes=[];this.pjaxEnabled=!1;this.isConnected=!1;this.config={...Nt,...e},this.transport=new _(this.config),this.updater=new T(this.config.debug),this.eventHandler=new me(this)}getConfig(){return this.config}async init(){if(!this.initialized){this.initialized=!0,this.transport.onMessage(e=>this.handleMessage(e)),this.transport.onStatusChange(e=>this.handleStatusChange(e));try{await this.transport.connect()}catch(e){console.error("PyWire: Failed to connect:",e)}this.loadSPAMetadata(),this.setupSPANavigation(),this.eventHandler.init(),console.log(`PyWire: Initialized (transport: ${this.transport.getActiveTransport()}, spa_paths: ${this.siblingPaths.length}, pjax: ${this.pjaxEnabled})`)}}handleStatusChange(e){this.isConnected=e}loadSPAMetadata(){let e=document.getElementById("_pywire_spa_meta");if(e)try{let t=JSON.parse(e.textContent||"{}");this.siblingPaths=t.sibling_paths||[],this.pjaxEnabled=!!t.enable_pjax,t.debug!==void 0&&(this.config.debug=!!t.debug),this.pathRegexes=this.siblingPaths.map(n=>this.patternToRegex(n))}catch(t){console.warn("PyWire: Failed to parse SPA metadata",t)}}patternToRegex(e){let t=e.replace(/[.+?^${}()|[\]\\]/g,"\\$&");return t=t.replace(/:(\\w+)(:\\w+)?/g,"([^/]+)"),t=t.replace(/\\{(\\w+)(:\\w+)?\\}/g,"([^/]+)"),new RegExp(`^${t}$`)}isSiblingPath(e){return this.pathRegexes.some(t=>t.test(e))}setupSPANavigation(){window.addEventListener("popstate",()=>{this.sendRelocate(window.location.pathname+window.location.search)}),!(this.siblingPaths.length===0&&!this.pjaxEnabled)&&document.addEventListener("click",e=>{let t=e.target.closest("a[href]");if(!t||t.origin!==window.location.origin||t.hasAttribute("download")||t.target==="_blank")return;let n=!1;(this.pjaxEnabled||this.isSiblingPath(t.pathname))&&(n=!0),n&&(e.preventDefault(),this.navigateTo(t.pathname+t.search))})}navigateTo(e){if(!this.isConnected){console.warn("PyWire: Navigation blocked - Offline");return}history.pushState({},"",e),this.sendRelocate(e)}sendRelocate(e){let t={type:"relocate",path:e};this.transport.send(t)}sendEvent(e,t){let n={type:"event",handler:e,path:window.location.pathname+window.location.search,data:t};this.transport.send(n)}async handleMessage(e){switch(e.type){case"update":e.regions&&e.regions.length>0?e.regions.forEach(t=>{this.updater.updateRegion(t.region,t.html)}):e.html&&this.updater.update(e.html);break;case"reload":console.log("PyWire: Reloading..."),window.location.reload();break;case"error":console.error("PyWire: Server error:",e.error);break;case"error_trace":console.error("PyWire: Error:",e.error);break;case"console":if(e.lines&&e.lines.length>0){let t="PyWire Server:",n=e.lines.join(`
3
+ `);e.level==="error"?console.error(t,n):e.level==="warn"?console.warn(t,n):console.log(t,n)}break;default:console.warn("PyWire: Unknown message type",e)}}getTransport(){return this.transport.getActiveTransport()}disconnect(){this.transport.disconnect()}};var V=class{constructor(){this.element=null;this.create()}create(){this.element=document.createElement("div"),this.element.style.cssText=`
4
+ position: fixed;
5
+ bottom: 20px;
6
+ right: 20px;
7
+ background: rgba(0, 0, 0, 0.8);
8
+ color: white;
9
+ padding: 10px 20px;
10
+ border-radius: 5px;
11
+ font-family: system-ui, -apple-system, sans-serif;
12
+ font-size: 14px;
13
+ z-index: 10000;
14
+ display: none;
15
+ transition: opacity 0.3s;
16
+ pointer-events: none;
17
+ `,document.body.appendChild(this.element)}update(e){this.element&&(e?this.element.style.display="none":(this.element.textContent="Connection Lost - Reconnecting...",this.element.style.display="block",this.element.style.backgroundColor="rgba(0, 0, 0, 0.8)"))}showNavigationBlocked(){this.element&&(this.element.style.backgroundColor="rgba(200, 0, 0, 0.9)",this.element.textContent="Cannot navigate - Offline",this.element.style.display="block",setTimeout(()=>{this.element&&(this.element.style.backgroundColor="rgba(0, 0, 0, 0.8)")},1500))}};var X=class{constructor(){this.loadedSources=new Set}getVirtualUrl(e){let t=btoa(e).replace(/\+/g,"-").replace(/\//g,"_").replace(/=+$/,""),n=e.split(/[/\\]/).pop()||"unknown";return`${window.location.origin}/_pywire/file/${t}/${n}`}async handle(e,t){let n=new Set;for(let o of t)this.loadedSources.has(o.filename)||n.add(o.filename);await Promise.all(Array.from(n).map(async o=>{try{let a=this.getVirtualUrl(o),l=`/_pywire/source?path=${encodeURIComponent(o)}`,p=await fetch(l);if(p.ok){let g=`${await p.text()}
18
+ //# sourceURL=${a}`;try{(0,eval)(g)}catch{}this.loadedSources.add(o)}this.loadedSources.add(o)}catch(a){console.warn("PyWire: Failed to load source",o,a)}}));let r=new Error(e),s=[`${r.name}: ${r.message}`];for(let o of t){let a=o.name||"<module>",l=this.getVirtualUrl(o.filename),p=o.colno??1;s.push(` at ${a} (${l}:${o.lineno}:${p})`)}r.stack=s.join(`
19
+ `),console.error(r.stack)}};var G=class extends O{constructor(t={}){super(t);this.overlay=null;this.errorHandler=new X}async init(){this.overlay=new V,await super.init()}handleStatusChange(t){super.handleStatusChange(t),this.overlay&&this.overlay.update(t)}navigateTo(t){if(!this.isConnected){console.warn("PyWire: Navigation blocked - Offline"),this.overlay&&this.overlay.showNavigationBlocked();return}super.navigateTo(t)}async handleMessage(t){switch(t.type){case"error_trace":t.trace&&await this.errorHandler.handle(t.error||"Unknown Error",t.trace);return;case"console":if(t.lines&&t.lines.length>0){let n="PyWire Server:",r=t.lines.join(`
20
+ `);t.level==="error"?(console.group(n+" Error"),console.error(r),console.groupEnd()):t.level==="warn"?(console.groupCollapsed(n+" Warning"),console.warn(r),console.groupEnd()):t.lines.length===1?console.log(n,r):(console.groupCollapsed(n+" Log"),console.log(r),console.groupEnd())}return;default:await super.handleMessage(t)}}};var Me=new G;document.readyState==="loading"?document.addEventListener("DOMContentLoaded",()=>Me.init()):Me.init();return et(Ft);})();
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: pywire
3
- Version: 0.1.2
3
+ Version: 0.1.3
4
4
  Summary: HTML-over-the-wire Python web framework
5
5
  Author-email: Reece Holmdahl <reece@pywire.dev>
6
6
  License-File: LICENSE
@@ -2,12 +2,12 @@ pywire/__init__.py,sha256=Vnf8jVQs1hz9PGw9qtkvz_5SGhuLpasPeDFAuDixH7w,78
2
2
  pywire/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
3
  pywire/cli/__init__.py,sha256=SNDCMbWNEM6_UNFDVB666srR-6Ak_HKLAX2Umy2O85I,18
4
4
  pywire/cli/generators.py,sha256=5tgXdhGJua9PhR8FkOxWaK9vHvOuFHdXOf3qamB7f3Q,1009
5
- pywire/cli/main.py,sha256=cj3zBsem5Me3j3rWeLF1wUeTNGM_akX56FgWGhBuiS0,9082
5
+ pywire/cli/main.py,sha256=n3OdvmJB_MUB3obejxqOsBoqSwKt13CetrICsDFoa0U,9082
6
6
  pywire/cli/tui.py,sha256=USInBXWUUc8BpihqTdtnRrPJtW3U9c7hFBMRup0mkGs,21714
7
7
  pywire/cli/validate.py,sha256=CPUQjFpoPcwpvAx3HvQ8Vq_w_suJ07n3oOhXKmKFwB4,769
8
8
  pywire/client/.prettierignore,sha256=TKRNv7wugFj9ig2T6SdoCZxMi_l9X-ninE8j72JdFzM,87
9
9
  pywire/client/.prettierrc,sha256=NwmnhqxkL9ATCDtQVOrgKBHtpN8L9niFT2j_SYmImzw,107
10
- pywire/client/build.mjs,sha256=IDiYOfeHoKy7jwlIJHT5Xo2GfxWcI9-p_jTZaHI1mWk,1944
10
+ pywire/client/build.mjs,sha256=DWkD9icyrJYWJR4MkX7lWU9u3-Ywq4raw2hPWVGuNoI,1944
11
11
  pywire/client/eslint.config.js,sha256=QxkvVaKeMnqSkPGDSjxQFvgfcyPWMbzct0zeMnpzQ4o,992
12
12
  pywire/client/package.json,sha256=K4pQlex2QKefhkANWbpoBZhpOoveRACp6BkjmWKMPsk,1130
13
13
  pywire/client/pnpm-lock.yaml,sha256=fPLYdbqVkvTTX6QheVLy0_32RHwWn90M9v6pAfondKw,78073
@@ -74,7 +74,7 @@ pywire/runtime/aioquic_server.py,sha256=n9GuK81xtc6PUT54uMhqMlGXn8NrH-ryZ6Rl9qQW
74
74
  pywire/runtime/app.py,sha256=ebJ5SDDgJTk95R6AunWtJOi6RI4R4dJKCM31051hGy8,36217
75
75
  pywire/runtime/compile_error_page.py,sha256=sqPTqG9dv_e2uBgYuAgOcDHx0D3Gwq2liFbBRrz4_iY,8205
76
76
  pywire/runtime/debug.py,sha256=6U-Ot1defe7eDXaAxNip4NtRPQjtjS9LNCUnk_pmmeQ,7416
77
- pywire/runtime/dev_server.py,sha256=QQ2tr7bgSdM1yDwfW7h_-x7r2RZ4qsd5A59GAvbceu0,16096
77
+ pywire/runtime/dev_server.py,sha256=DUVbktSBAujiwALxXG2iWLTdpjcAe80l44GPDJRdV6w,16018
78
78
  pywire/runtime/dev_server.py.broken,sha256=cAPPLFNe6qJ-KouATG3FfIabGd-o3qCqlMGqQQF03sc,11030
79
79
  pywire/runtime/error_page.py,sha256=fnE8Qjf1a7fjLOys6G2uDsK0VYGMZg2yGWgDagk39j0,2497
80
80
  pywire/runtime/error_renderer.py,sha256=HNS9seD5gX4jE3L4GPsJsyxvpMTiiNo3E43trUNiuX0,701
@@ -97,8 +97,10 @@ pywire/templates/error/404.html,sha256=cZavWjs-aXoSRpEy-8D0rulP7g5Sn31MsIXmkZUQn
97
97
  pywire/templates/error/500.html,sha256=545CPh1XyhN-zdSAD8R-6Cuos6hLC--TXJy4EQHrpjM,1282
98
98
  pywire/templates/error/base.html,sha256=nlBlBIg-VFAWtTLWky7c2igNVsFjj9M8Wyw3v3_4KGQ,4863
99
99
  pywire/templates/error/compile_error.html,sha256=FMqU3HXYWMeiXG3eTAysNpAHH-AOPx2Apbz8f_HBvtw,837
100
- pywire-0.1.2.dist-info/METADATA,sha256=YY8GcGmn6gFSwfczEJHF_rWvPn3-rgj6aL9OosQLTag,2386
101
- pywire-0.1.2.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
102
- pywire-0.1.2.dist-info/entry_points.txt,sha256=L0n4cNLZIocOo6lG05uOoUN1GHgA_uQOHvapDAhULBI,47
103
- pywire-0.1.2.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
104
- pywire-0.1.2.dist-info/RECORD,,
100
+ pywire/static/pywire.core.min.js,sha256=SGZYyI_NgoUphlWWJ_WM9_S3Ix-2-6JykU3frlhW_6A,47482
101
+ pywire/static/pywire.dev.min.js,sha256=v7C7Gkh-0eernYfHGvqzTFdjCqiXLt4EQSvPl2l6-oM,50520
102
+ pywire-0.1.3.dist-info/METADATA,sha256=xotwogdm8P9eqUWNFqrPYrsQMUUeFkEVgkLBgerzpAo,2386
103
+ pywire-0.1.3.dist-info/WHEEL,sha256=WLgqFyCfm_KASv4WHyYy0P3pM_m7J5L9k2skdKLirC8,87
104
+ pywire-0.1.3.dist-info/entry_points.txt,sha256=L0n4cNLZIocOo6lG05uOoUN1GHgA_uQOHvapDAhULBI,47
105
+ pywire-0.1.3.dist-info/licenses/LICENSE,sha256=xx0jnfkXJvxRnG63LTGOxlggYnIysveWIZ6H3PNdCrQ,11357
106
+ pywire-0.1.3.dist-info/RECORD,,
File without changes