conformtools 0.6.16 → 0.6.17

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.
Files changed (100) hide show
  1. package/README.md +1 -1
  2. package/dist/{account-W7Z2MYZU.js → account-VXAKXGY6.js} +1 -1
  3. package/dist/{agent-hook-setup-JCIZG3Q3.js → agent-hook-setup-HBT2LTVR.js} +1 -1
  4. package/dist/{analysis-engine-DCHJHZ7W.js → analysis-engine-BZUEBW55.js} +1 -1
  5. package/dist/{arriraw-YIJ3BYNN.js → arriraw-GZ63YMLZ.js} +7 -7
  6. package/dist/bridge-DRC6BQFR.js +3 -0
  7. package/dist/browser/timeline_core_bg.wasm +0 -0
  8. package/dist/{chunk-HOACOBAY.js → chunk-2SDAOYP5.js} +3 -3
  9. package/dist/{chunk-XVZ7KJRI.js → chunk-2VH2Z6RD.js} +1 -1
  10. package/dist/chunk-3PVQ5QP4.js +3 -0
  11. package/dist/chunk-73RFYAVG.js +3 -0
  12. package/dist/{chunk-RGMTLNMF.js → chunk-BBCQMZQN.js} +1 -1
  13. package/dist/{chunk-JL454FFL.js → chunk-CRMGV32N.js} +2 -2
  14. package/dist/{chunk-JM5LHKTU.js → chunk-CZ6OZKR6.js} +222 -216
  15. package/dist/chunk-GRJLKGBG.js +3 -0
  16. package/dist/chunk-GTPTZRO6.js +3 -0
  17. package/dist/{chunk-4RA57LTJ.js → chunk-IG2X534U.js} +1 -1
  18. package/dist/{chunk-MGMDNGNX.js → chunk-JT3HI632.js} +2 -2
  19. package/dist/chunk-JTRM2JCE.js +7 -0
  20. package/dist/{chunk-UAURERD3.js → chunk-M5CEBOLK.js} +1 -1
  21. package/dist/{chunk-XDI6CPPV.js → chunk-MTAXVOHK.js} +1 -1
  22. package/dist/{chunk-WJ5EWXP2.js → chunk-MVQ5RGZB.js} +1 -1
  23. package/dist/{chunk-VETHR2O7.js → chunk-NN444GPH.js} +1 -1
  24. package/dist/chunk-OSUIS4JU.js +3 -0
  25. package/dist/chunk-P4PCSGEH.js +10 -0
  26. package/dist/{chunk-DPA26AOI.js → chunk-QNF4NMIW.js} +1 -1
  27. package/dist/{chunk-QRZO5GOI.js → chunk-R2WEXCVQ.js} +1 -1
  28. package/dist/chunk-RITYQNOO.js +3 -0
  29. package/dist/{chunk-RJD44NQU.js → chunk-S2WAFMRV.js} +2 -2
  30. package/dist/chunk-S5AOIOTT.js +3 -0
  31. package/dist/chunk-STGGRRYM.js +3 -0
  32. package/dist/{chunk-FLLB6UZJ.js → chunk-T7S2UBNN.js} +1 -1
  33. package/dist/chunk-TWHNQFKI.js +3 -0
  34. package/dist/chunk-UBWUED67.js +3 -0
  35. package/dist/{chunk-VWFEMXYZ.js → chunk-VCBLWNQR.js} +102 -101
  36. package/dist/{chunk-6V4OEOOX.js → chunk-VFXMP7IF.js} +1 -1
  37. package/dist/{chunk-5W57ITT2.js → chunk-WKNX742H.js} +2 -2
  38. package/dist/{chunk-UKXSKFL3.js → chunk-YGAAGTLE.js} +1 -1
  39. package/dist/{claude-setup-CM7G2YSG.js → claude-setup-W27DLJIO.js} +1 -1
  40. package/dist/cli.js +2 -2
  41. package/dist/{cr3-wasm-NYCB34ND.js → cr3-wasm-VUEEZYKQ.js} +1 -1
  42. package/dist/{demo-engine-CBFAAPPO.js → demo-engine-5TCNOTTH.js} +1 -1
  43. package/dist/dng-wasm-5RQBGYAK.js +3 -0
  44. package/dist/dpx-wasm-OQVTNGOB.js +3 -0
  45. package/dist/{engine-6YYXTF2Q.js → engine-4X6TDWWA.js} +2 -2
  46. package/dist/exr-wasm-72YZFOME.js +3 -0
  47. package/dist/framing-HGW5RCUA.js +3 -0
  48. package/dist/gfx-worker.js +1 -1
  49. package/dist/{h264-MAUVJTR4.js → h264-QCYEI6RF.js} +1 -1
  50. package/dist/{h264-mxf-2O4SAUTA.js → h264-mxf-2BYKXDGT.js} +1 -1
  51. package/dist/hook.js +2 -2
  52. package/dist/{host-relink-NVLUO73P.js → host-relink-37DCSN47.js} +1 -1
  53. package/dist/hosted-M2OZSONX.js +3 -0
  54. package/dist/hosts-IAJTORJD.js +3 -0
  55. package/dist/http.js +3 -3
  56. package/dist/{inspect-YIFLNOJW.js → inspect-R4RWCK3X.js} +2 -2
  57. package/dist/isobmff-RH4JKUUB.js +3 -0
  58. package/dist/{mc-video-HRZC7HGH.js → mc-video-MMKWEKFZ.js} +1 -1
  59. package/dist/mcp.js +8 -8
  60. package/dist/media-6MB7EKA7.js +3 -0
  61. package/dist/mxf-7HFFEBNW.js +3 -0
  62. package/dist/{ops-XIUVNJE2.js → ops-EM345H7F.js} +1 -1
  63. package/dist/{probe-GIAKRPFV.js → probe-YDOFGCGD.js} +1 -1
  64. package/dist/{r3d-I6EYEYX7.js → r3d-DDOTSYZH.js} +5 -5
  65. package/dist/r3d-G34YLXXA.js +3 -0
  66. package/dist/sequence-patch-2S7IPE52.js +3 -0
  67. package/dist/{source-QGWWLMME.js → source-L2JNTYS6.js} +1 -1
  68. package/dist/{still-4UR35GZH.js → still-AGBF3OOY.js} +1 -1
  69. package/dist/{still-wasm-RTPOMH7S.js → still-wasm-6YLI6NQQ.js} +1 -1
  70. package/dist/{store-MWNX47IK.js → store-LWUDJD76.js} +1 -1
  71. package/dist/tiff-wasm-6APT7FYP.js +3 -0
  72. package/dist/timeline-EZ6WUHCB.js +3 -0
  73. package/dist/{wav-HSCUCY4U.js → wav-CV43ZAJI.js} +1 -1
  74. package/package.json +5 -5
  75. package/dist/bridge-UPSJ7F3S.js +0 -3
  76. package/dist/chunk-DKGGJM6Z.js +0 -3
  77. package/dist/chunk-DLF5AKXT.js +0 -10
  78. package/dist/chunk-EEDLRRKU.js +0 -3
  79. package/dist/chunk-IDJIOKXA.js +0 -3
  80. package/dist/chunk-ISKNIQVO.js +0 -3
  81. package/dist/chunk-JKOB3U54.js +0 -3
  82. package/dist/chunk-OWWXUNJF.js +0 -7
  83. package/dist/chunk-PFZVET7S.js +0 -3
  84. package/dist/chunk-QH5DTYSE.js +0 -3
  85. package/dist/chunk-RVZQ3Y6N.js +0 -3
  86. package/dist/chunk-X527E5VI.js +0 -3
  87. package/dist/chunk-YUO3UWPH.js +0 -3
  88. package/dist/dng-wasm-XCPPBXPZ.js +0 -3
  89. package/dist/dpx-wasm-XACWNFPB.js +0 -3
  90. package/dist/exr-wasm-FQBUR6QT.js +0 -3
  91. package/dist/framing-QYRCUEB5.js +0 -3
  92. package/dist/hosted-2XACQY7J.js +0 -3
  93. package/dist/hosts-GEXAZFB3.js +0 -3
  94. package/dist/isobmff-MTMGQKLK.js +0 -3
  95. package/dist/media-WC4ZVKIL.js +0 -3
  96. package/dist/mxf-J5QHA3VY.js +0 -3
  97. package/dist/r3d-2PCOFR2Z.js +0 -3
  98. package/dist/sequence-patch-DFGEAJGB.js +0 -3
  99. package/dist/tiff-wasm-N2S267IA.js +0 -3
  100. package/dist/timeline-Z3KD2CJX.js +0 -3
package/README.md CHANGED
@@ -10,7 +10,7 @@ language, or from a terminal.
10
10
  ## What you need
11
11
 
12
12
  - [Node.js](https://nodejs.org) 20 or newer
13
- - a conform.tools account on the Pro or Studio plan ([pricing](https://conform.tools/pricing)); the free Timeline Exchange covers the web tools only. The engine is in open beta.
13
+ - a conform.tools account on the Pro or Studio plan ([pricing](https://conform.tools/pricing)); a new account's 7-day free trial includes the MCP. The engine is in open beta.
14
14
 
15
15
  ## 1. Sign in
16
16
 
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
- import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-OWWXUNJF.js";import"./chunk-VETHR2O7.js";import"./chunk-ROGMKTND.js";import"./chunk-X527E5VI.js";import"./chunk-PSANHDZM.js";export{c as NET_TIMEOUT_MS,d as _forgetOffline,e as accessToken,f as accountStatus,a as config,h as includesOf,b as legacyKvStorePath,n as login,o as logout,l as requireApp,j as requireEntitled,k as requireMcp,m as requireStudioTool,i as setAccountGate,g as statusText};
3
+ import{a,b,c,d,e,f,g,h,i,j,k,l,m,n,o}from"./chunk-JTRM2JCE.js";import"./chunk-NN444GPH.js";import"./chunk-ROGMKTND.js";import"./chunk-GTPTZRO6.js";import"./chunk-PSANHDZM.js";export{c as NET_TIMEOUT_MS,d as _forgetOffline,e as accessToken,f as accountStatus,a as config,h as includesOf,b as legacyKvStorePath,n as login,o as logout,l as requireApp,j as requireEntitled,k as requireMcp,m as requireStudioTool,i as setAccountGate,g as statusText};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
- import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m}from"./chunk-FLLB6UZJ.js";import"./chunk-X527E5VI.js";import"./chunk-PSANHDZM.js";export{a as CLIENTS,j as WHAT_IT_RECORDS,f as clientsHere,b as hookFiles,i as hookInstalled,l as hooksRemovedText,m as hooksStatusText,k as hooksText,d as installAgentHook,g as installAllAgentHooks,c as installHookScript,e as removeAgentHook,h as removeAllAgentHooks};
3
+ import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h,j as i,k as j,l as k,m as l,n as m}from"./chunk-T7S2UBNN.js";import"./chunk-GTPTZRO6.js";import"./chunk-PSANHDZM.js";export{a as CLIENTS,j as WHAT_IT_RECORDS,f as clientsHere,b as hookFiles,i as hookInstalled,l as hooksRemovedText,m as hooksStatusText,k as hooksText,d as installAgentHook,g as installAllAgentHooks,c as installHookScript,e as removeAgentHook,h as removeAllAgentHooks};
@@ -1,3 +1,3 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
- import{a,b,c,d}from"./chunk-VETHR2O7.js";import"./chunk-ROGMKTND.js";import"./chunk-X527E5VI.js";import"./chunk-PSANHDZM.js";export{a as analysisEnginePath,c as analysisOp,d as startAnalysisEngine,b as startAnalysisJob};
3
+ import{a,b,c,d}from"./chunk-NN444GPH.js";import"./chunk-ROGMKTND.js";import"./chunk-GTPTZRO6.js";import"./chunk-PSANHDZM.js";export{a as analysisEnginePath,c as analysisOp,d as startAnalysisEngine,b as startAnalysisJob};
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
- import{a as F}from"./chunk-7D7H6VFW.js";import"./chunk-PSANHDZM.js";var k={MAP_READ:1,COPY_SRC:4,COPY_DST:8,UNIFORM:64,STORAGE:128},O={READ:1};var K=`// Stage 1: 13-bit reverse-packed (LSB-first) unpack \u2014 the elementwise read_sample form
3
+ import{a as z}from"./chunk-7D7H6VFW.js";import"./chunk-PSANHDZM.js";var w={MAP_READ:1,COPY_SRC:4,COPY_DST:8,UNIFORM:64,STORAGE:128},E={READ:1};var T=`// Stage 1: 13-bit reverse-packed (LSB-first) unpack \u2014 the elementwise read_sample form
4
4
  // (arriraw.rs read_sample), one thread per sample. Reads two aligned u32 words instead of
5
5
  // four bytes; bit-identical. \`packed\` is padded with one extra zero word so word+1 is
6
6
  // always in bounds.
@@ -27,7 +27,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
27
27
  }
28
28
  mosaic[i] = v & 0x1fffu;
29
29
  }
30
- `;var W=`// Stage 2: prep (arriraw_prep::prep_sample) \u2014 decompand (f32 LUT, fcvtzs truncate) \u2192
30
+ `;var O=`// Stage 2: prep (arriraw_prep::prep_sample) \u2014 decompand (f32 LUT, fcvtzs truncate) \u2192
31
31
  // white balance in 8.24 fixed point \u2192 recompand (u16 LUT, stored one code per u32).
32
32
  //
33
33
  // The Rust does \`(v as i64 * gain + (1<<23)) >> 24\`. WGSL has no i64, so the 64-bit
@@ -83,7 +83,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
83
83
  vi = clamp(vi, 0, WHITE);
84
84
  prepped[i] = rc[u32(vi)];
85
85
  }
86
- `;var $=`// Stage 3: ADA-7 fill green plane (arriraw_fill::green_plane) over [-1,h+1)x[-1,w+1),
86
+ `;var K=`// Stage 3: ADA-7 fill green plane (arriraw_fill::green_plane) over [-1,h+1)x[-1,w+1),
87
87
  // one thread per green node. The CPU pads the mosaic by 4 with reflect-101; here the
88
88
  // reflect is computed in-shader (never materialized) \u2014 identical samples.
89
89
  //
@@ -195,7 +195,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
195
195
  }
196
196
  green[gid.y * (u.w + 2u) + gid.x] = g;
197
197
  }
198
- `;var I=`// Stage 4: ADA-7 fill / reconstruct_pixel (arriraw_fill) \u2014 full RGB triple per pixel from
198
+ `;var W=`// Stage 4: ADA-7 fill / reconstruct_pixel (arriraw_fill) \u2014 full RGB triple per pixel from
199
199
  // the prepped mosaic + green plane. Pure integer. Writes three u32 planes.
200
200
  struct U {
201
201
  w: u32, h: u32, dir: u32, pad0: u32,
@@ -313,7 +313,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
313
313
  outG[i] = u32(gg);
314
314
  outB[i] = u32(bb);
315
315
  }
316
- `;var q=`// Stages 5/6: ADA-7 green-guided refine (arriraw_ada7::refine_pass / refine_pixel).
316
+ `;var $=`// Stages 5/6: ADA-7 green-guided refine (arriraw_ada7::refine_pass / refine_pixel).
317
317
  // SNAPSHOT semantics: reads src planes, writes dst planes (ping-pong) \u2014 never in place.
318
318
  // u.dir: 0 = horizontal (left/right), 1 = vertical (up/down). Green never changes, so a
319
319
  // single G plane serves both passes. Border neighbour is reflect-101 (x==0 \u2192 1,
@@ -378,7 +378,7 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
378
378
  dstR[c] = u32(clamp(new_r, 0, CL));
379
379
  dstB[c] = u32(clamp(new_b, 0, CL));
380
380
  }
381
- `;var H=`// Stage 7: colour kernel (kernel_recompand_f32_codes) + LogC4 normalize \u2014 the bit-exact
381
+ `;var q=`// Stage 7: colour kernel (kernel_recompand_f32_codes) + LogC4 normalize \u2014 the bit-exact
382
382
  // port from ../arriraw/kernel.wgsl, unchanged math, re-plumbed for the full frame:
383
383
  // * planar u32 code planes in, planar f32 planes out (per-binding < 128 MiB);
384
384
  // * the four per-clip tables live in ONE concatenated storage buffer
@@ -522,4 +522,4 @@ fn main(@builtin(global_invocation_id) gid: vec3<u32>) {
522
522
  outG[i] = divr(lut_lerp(mulr(scale, g_out) + 256.0), 65535.0);
523
523
  outB[i] = divr(lut_lerp(mulr(scale, b_out) + 256.0), 65535.0);
524
524
  }
525
- `;var g={prepDecompand:65536,prepRecompand:262016,rptab:8192,gridA:4225,gridB:4225,finalLut:262144},ir=g.rptab+g.gridA+g.gridB+g.finalLut,D=k.STORAGE,z=k.COPY_DST,tr=k.COPY_SRC,N=["unpack13","prep","green","fill","refineH","refineV","color"],M=new WeakMap,S=new WeakMap,V=Promise.resolve(),Y=!1;function C(e,r){Y||(Y=!0,console.warn(`[media/gpu/arriraw] ${e} \u2014 falling back to the WASM lane`,r??""))}async function kr(){return await F()!==null}function ur(e){let r=M.get(e);if(!r){let a=u=>e.createComputePipelineAsync({layout:"auto",compute:{module:e.createShaderModule({code:u}),entryPoint:"main"}});r=Promise.all([a(K),a(W),a($),a(I),a(q),a(H)]).then(([u,t,n,i,o,s])=>({unpack13:u,prep:t,green:n,fill:i,refine:o,color:s})),M.set(e,r),r.catch(()=>M.delete(e))}return r}function or(e){let{width:r,height:a}=e;if(!Number.isInteger(r)||!Number.isInteger(a)||r<16||a<16)return`raster ${r}x${a} out of range`;if(r%2!==0||a%2!==0)return`raster ${r}x${a} is not even (Bayer phase)`;if(e.gains8_24.length!==4)return"gains8_24 must have 4 entries";for(let[u,t]of Object.entries(g)){let n=e[u];if(n.length!==t)return`${u} must have ${t} entries (got ${n.length})`}return e.cp.length!==4?"cp must have 4 entries":null}function sr(e,r,a){let u=(r+2)*(a+2)*4,t=e.limits;if(u>t.maxStorageBufferBindingSize||u>t.maxBufferSize)return`raster ${r}x${a} exceeds device buffer limits`;let n=Math.ceil((r+2)/8),i=Math.ceil((a+2)/8);return n>t.maxComputeWorkgroupsPerDimension||i>t.maxComputeWorkgroupsPerDimension?`raster ${r}x${a} exceeds dispatch limits`:null}function Z(e,r,a){let u=new ArrayBuffer(64),t=new Uint32Array(u),n=new Float32Array(u);t[0]=r.width,t[1]=r.height,t[2]=a,t[3]=0,n[4]=r.k2,n[5]=0,n[6]=1,n[7]=0,n.set(r.cp,8),t.set(r.gains8_24,12);let i=e.createBuffer({size:64,usage:k.UNIFORM|z});return e.queue.writeBuffer(i,0,u),i}function j(e,r,a,u){let t=a.width,n=a.height,i=t*n,o=(G,B=D|tr)=>e.createBuffer({size:G,usage:B}),s=G=>{let B=e.createBuffer({size:G.byteLength,usage:D|z});return e.queue.writeBuffer(B,0,G),B},c=(Math.ceil(u/4)+1)*4,l=e.createBuffer({size:c,usage:D|z}),w=s(a.prepDecompand),m=s(Uint32Array.from(a.prepRecompand)),f=new Float32Array(ir);f.set(a.rptab,0),f.set(a.gridA,g.rptab),f.set(a.gridB,g.rptab+g.gridA),f.set(a.finalLut,g.rptab+g.gridA+g.gridB);let h=s(f),y=o(i*4),v=o(i*4),A=o((t+2)*(n+2)*4),p=o(i*4),b=o(i*4),R=o(i*4),P=o(i*4),U=o(i*4),_=Z(e,a,0),T=Z(e,a,1),x=(G,B)=>e.createBindGroup({layout:G.getBindGroupLayout(0),entries:B.map((nr,ar)=>({binding:ar,resource:{buffer:nr}}))}),er={unpack13:x(r.unpack13,[l,y,_]),prep:x(r.prep,[y,w,m,v,_]),green:x(r.green,[v,A,_]),fill:x(r.fill,[v,A,p,b,R,_]),refineH:x(r.refine,[p,b,R,P,U,_]),refineV:x(r.refine,[P,b,U,p,R,T]),color:x(r.color,[h,p,b,R,P,A,U,_])};return{device:e,w:t,h:n,packedCapacity:c,packed:l,dec:w,rc:m,luts:h,u0:_,u1:T,mosaic:y,prepped:v,green:A,r0:p,g0:b,b0:R,r1:P,b1:U,groups:er}}function cr(e){for(let r of[e.packed,e.dec,e.rc,e.luts,e.u0,e.u1,e.mosaic,e.prepped,e.green,e.r0,e.g0,e.b0,e.r1,e.b1])r.destroy()}function lr(e,r){return r==="refineH"||r==="refineV"?e.refine:e[r]}function J(e,r,a,u){let t=Math.ceil(a.w/8),n=Math.ceil(a.h/8),i=Math.ceil((a.w+2)/8),o=Math.ceil((a.h+2)/8),s=e.createCommandEncoder();for(let c of u){let l=s.beginComputePass();l.setPipeline(lr(r,c)),l.setBindGroup(0,a.groups[c]),c==="green"?l.dispatchWorkgroups(i,o):l.dispatchWorkgroups(t,n),l.end()}e.queue.submit([s.finish()])}async function d(e,r,a){let u=e.createBuffer({size:a,usage:z|k.MAP_READ}),t=e.createCommandEncoder();t.copyBufferToBuffer(r,0,u,0,a),e.queue.submit([t.finish()]),await u.mapAsync(O.READ);let n=u.getMappedRange().slice(0);return u.unmap(),u.destroy(),n}async function X(e,r){let a=or(r);if(a)return C(`invalid clip state: ${a}`),null;let u=r.width*r.height*13>>3;if(e.length<u)return C(`essence ${e.length} B < ${u} B required for ${r.width}x${r.height}`),null;let t=await F();if(!t)return null;let n=sr(t,r.width,r.height);if(n)return C(n),null;let i=await ur(t),o=S.get(r);o&&o.device!==t&&(S.delete(r),o=void 0),o||(o=j(t,i,r,u),S.set(r,o)),o.packedCapacity<(Math.ceil(u/4)+1)*4&&(cr(o),S.delete(r),o=j(t,i,r,u),S.set(r,o));let s=e.subarray(e.length-u),c=new Uint8Array(o.packedCapacity);return c.set(s),t.queue.writeBuffer(o.packed,0,c),{device:t,lane:i,res:o}}function L(e,r,a){let u=e.length,t=new Uint16Array(u*3);for(let n=0;n<u;n++)t[3*n]=e[n],t[3*n+1]=r[n],t[3*n+2]=a[n];return t}function Q(e){for(let r of e)for(let a=0;a<r.length;a++)if(r[a]!==0)return!1;return!0}async function rr(e,r,a){let u=await X(e,r);if(!u)return null;let{device:t,lane:n,res:i}=u,o=i.w*i.h,s=a?N.slice(0,6):N;if(J(t,n,i,s),a){let[m,f,h]=await Promise.all([d(t,i.r0,o*4),d(t,i.g0,o*4),d(t,i.b0,o*4)]).then(y=>y.map(v=>new Uint32Array(v)));return Q([m,f,h])?(C("codes output came back all-zero (killed dispatch?)"),null):{width:i.w,height:i.h,codes:L(m,f,h)}}let[c,l,w]=await Promise.all([d(t,i.r1,o*4),d(t,i.green,o*4),d(t,i.b1,o*4)]).then(m=>m.map(f=>new Float32Array(f)));return Q([c,l,w])?(C("frame output came back all-zero (killed dispatch?)"),null):{width:i.w,height:i.h,r:c,g:l,b:w}}function E(e){let r=V.then(e,e).catch(a=>(C("GPU decode failed",a),null));return V=r,r}function Cr(e,r){return E(()=>rr(e,r,!1))}function Rr(e,r){return E(()=>rr(e,r,!0))}function Sr(e,r){return E(async()=>{let a=await X(e,r);if(!a)return null;let{device:u,lane:t,res:n}=a,i=n.w*n.h,o=p=>J(u,t,n,[p]),s=async(p,b)=>new Uint32Array(await d(u,p,b*4));o("unpack13");let c=Uint16Array.from(await s(n.mosaic,i));o("prep");let l=Uint16Array.from(await s(n.prepped,i));o("green");let w=new Int32Array(await d(u,n.green,(n.w+2)*(n.h+2)*4));o("fill");let m=L(await s(n.r0,i),await s(n.g0,i),await s(n.b0,i));o("refineH");let f=L(await s(n.r1,i),await s(n.g0,i),await s(n.b1,i));o("refineV");let h=L(await s(n.r0,i),await s(n.g0,i),await s(n.b0,i));o("color");let[y,v,A]=await Promise.all([d(u,n.r1,i*4),d(u,n.green,i*4),d(u,n.b1,i*4)]).then(p=>p.map(b=>new Float32Array(b)));return{unpacked:c,prepped:l,green:w,fill:m,refineH:f,codes:h,final:{width:n.w,height:n.h,r:y,g:v,b:A}}})}export{kr as arrirawGpuAvailable,Rr as decodeArrirawCodesGpu,Cr as decodeArrirawFrameGpu,Sr as decodeArrirawFrameGpuStaged};
525
+ `;var f={prepDecompand:65536,prepRecompand:262016,rptab:8192,gridA:4225,gridB:4225,finalLut:262144},er=f.rptab+f.gridA+f.gridB+f.finalLut,D=w.STORAGE,L=w.COPY_DST,nr=w.COPY_SRC,I=["unpack13","prep","green","fill","refineH","refineV","color"],F=new WeakMap,R=new WeakMap,N=Promise.resolve(),H=!1;function _(e,r){H||(H=!0,console.warn(`[media/gpu/arriraw] ${e} \u2014 falling back to the WASM lane`,r??""))}async function kr(){return await z()!==null}function ir(e){let r=F.get(e);if(!r){let n=a=>e.createComputePipelineAsync({layout:"auto",compute:{module:e.createShaderModule({code:a}),entryPoint:"main"}});r=Promise.all([n(T),n(O),n(K),n(W),n($),n(q)]).then(([a,i,t,u,o,s])=>({unpack13:a,prep:i,green:t,fill:u,refine:o,color:s})),F.set(e,r),r.catch(()=>F.delete(e))}return r}function ar(e){let{width:r,height:n}=e;if(!Number.isInteger(r)||!Number.isInteger(n)||r<16||n<16)return`raster ${r}x${n} out of range`;if(r%2!==0||n%2!==0)return`raster ${r}x${n} is not even (Bayer phase)`;if(e.gains8_24.length!==4)return"gains8_24 must have 4 entries";for(let[a,i]of Object.entries(f)){let t=e[a];if(t.length!==i)return`${a} must have ${i} entries (got ${t.length})`}return e.cp.length!==4?"cp must have 4 entries":null}function tr(e,r,n){let a=(r+2)*(n+2)*4,i=e.limits;if(a>i.maxStorageBufferBindingSize||a>i.maxBufferSize)return`raster ${r}x${n} exceeds device buffer limits`;let t=Math.ceil((r+2)/8),u=Math.ceil((n+2)/8);return t>i.maxComputeWorkgroupsPerDimension||u>i.maxComputeWorkgroupsPerDimension?`raster ${r}x${n} exceeds dispatch limits`:null}function V(e,r,n){let a=new ArrayBuffer(64),i=new Uint32Array(a),t=new Float32Array(a);i[0]=r.width,i[1]=r.height,i[2]=n,i[3]=0,t[4]=r.k2,t[5]=0,t[6]=1,t[7]=0,t.set(r.cp,8),i.set(r.gains8_24,12);let u=e.createBuffer({size:64,usage:w.UNIFORM|L});return e.queue.writeBuffer(u,0,a),u}function Y(e,r,n,a){let i=n.width,t=n.height,u=i*t,o=(v,h=D|nr)=>e.createBuffer({size:v,usage:h}),s=v=>{let h=e.createBuffer({size:v.byteLength,usage:D|L});return e.queue.writeBuffer(h,0,v),h},c=(Math.ceil(a/4)+1)*4,l=e.createBuffer({size:c,usage:D|L}),x=s(n.prepDecompand),g=s(Uint32Array.from(n.prepRecompand)),p=new Float32Array(er);p.set(n.rptab,0),p.set(n.gridA,f.rptab),p.set(n.gridB,f.rptab+f.gridA),p.set(n.finalLut,f.rptab+f.gridA+f.gridB);let G=s(p),B=o(u*4),b=o(u*4),P=o((i+2)*(t+2)*4),A=o(u*4),k=o(u*4),C=o(u*4),S=o(u*4),U=o(u*4),d=V(e,n,0),M=V(e,n,1),m=(v,h)=>e.createBindGroup({layout:v.getBindGroupLayout(0),entries:h.map((X,rr)=>({binding:rr,resource:{buffer:X}}))}),J={unpack13:m(r.unpack13,[l,B,d]),prep:m(r.prep,[B,x,g,b,d]),green:m(r.green,[b,P,d]),fill:m(r.fill,[b,P,A,k,C,d]),refineH:m(r.refine,[A,k,C,S,U,d]),refineV:m(r.refine,[S,k,U,A,C,M]),color:m(r.color,[G,A,k,C,S,P,U,d])};return{device:e,w:i,h:t,packedCapacity:c,packed:l,dec:x,rc:g,luts:G,u0:d,u1:M,mosaic:B,prepped:b,green:P,r0:A,g0:k,b0:C,r1:S,b1:U,groups:J}}function ur(e){for(let r of[e.packed,e.dec,e.rc,e.luts,e.u0,e.u1,e.mosaic,e.prepped,e.green,e.r0,e.g0,e.b0,e.r1,e.b1])r.destroy()}function or(e,r){return r==="refineH"||r==="refineV"?e.refine:e[r]}function sr(e,r,n,a){let i=Math.ceil(n.w/8),t=Math.ceil(n.h/8),u=Math.ceil((n.w+2)/8),o=Math.ceil((n.h+2)/8),s=e.createCommandEncoder();for(let c of a){let l=s.beginComputePass();l.setPipeline(or(r,c)),l.setBindGroup(0,n.groups[c]),c==="green"?l.dispatchWorkgroups(u,o):l.dispatchWorkgroups(i,t),l.end()}e.queue.submit([s.finish()])}async function y(e,r,n){let a=e.createBuffer({size:n,usage:L|w.MAP_READ}),i=e.createCommandEncoder();i.copyBufferToBuffer(r,0,a,0,n),e.queue.submit([i.finish()]),await a.mapAsync(E.READ);let t=a.getMappedRange().slice(0);return a.unmap(),a.destroy(),t}async function cr(e,r){let n=ar(r);if(n)return _(`invalid clip state: ${n}`),null;let a=r.width*r.height*13>>3;if(e.length<a)return _(`essence ${e.length} B < ${a} B required for ${r.width}x${r.height}`),null;let i=await z();if(!i)return null;let t=tr(i,r.width,r.height);if(t)return _(t),null;let u=await ir(i),o=R.get(r);o&&o.device!==i&&(R.delete(r),o=void 0),o||(o=Y(i,u,r,a),R.set(r,o)),o.packedCapacity<(Math.ceil(a/4)+1)*4&&(ur(o),R.delete(r),o=Y(i,u,r,a),R.set(r,o));let s=e.subarray(e.length-a),c=new Uint8Array(o.packedCapacity);return c.set(s),i.queue.writeBuffer(o.packed,0,c),{device:i,lane:u,res:o}}function lr(e,r,n){let a=e.length,i=new Uint16Array(a*3);for(let t=0;t<a;t++)i[3*t]=e[t],i[3*t+1]=r[t],i[3*t+2]=n[t];return i}function Z(e){for(let r of e)for(let n=0;n<r.length;n++)if(r[n]!==0)return!1;return!0}async function j(e,r,n){let a=await cr(e,r);if(!a)return null;let{device:i,lane:t,res:u}=a,o=u.w*u.h,s=n?I.slice(0,6):I;if(sr(i,t,u,s),n){let[g,p,G]=await Promise.all([y(i,u.r0,o*4),y(i,u.g0,o*4),y(i,u.b0,o*4)]).then(B=>B.map(b=>new Uint32Array(b)));return Z([g,p,G])?(_("codes output came back all-zero (killed dispatch?)"),null):{width:u.w,height:u.h,codes:lr(g,p,G)}}let[c,l,x]=await Promise.all([y(i,u.r1,o*4),y(i,u.green,o*4),y(i,u.b1,o*4)]).then(g=>g.map(p=>new Float32Array(p)));return Z([c,l,x])?(_("frame output came back all-zero (killed dispatch?)"),null):{width:u.w,height:u.h,r:c,g:l,b:x}}function Q(e){let r=N.then(e,e).catch(n=>(_("GPU decode failed",n),null));return N=r,r}function Cr(e,r){return Q(()=>j(e,r,!1))}function Rr(e,r){return Q(()=>j(e,r,!0))}export{kr as arrirawGpuAvailable,Rr as decodeArrirawCodesGpu,Cr as decodeArrirawFrameGpu};
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
+ import{b as a,c as b,d as c,e as d,f as e,g as f,h as g,i as h}from"./chunk-2SDAOYP5.js";import"./chunk-TWHNQFKI.js";import"./chunk-GTPTZRO6.js";import"./chunk-PSANHDZM.js";export{c as BridgeError,g as HostBridge,e as PANEL_PREFIX,b as PORTS,a as PROTOCOL,h as hostBridge,d as pairingPath,f as panelOrigins};
Binary file
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env node
2
2
  import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
- import{a as L}from"./chunk-RVZQ3Y6N.js";import{A as O,B as R,D as W,E as I,ba as P,n as _,s as C,y as N}from"./chunk-X527E5VI.js";import X from"node:http";import{connect as Y}from"node:net";import{createHash as M,randomBytes as U}from"node:crypto";import{Buffer as d}from"node:buffer";var j="258EAFA5-E914-47DA-95CA-C5AB0DC85B11";function A(a,e,c=!1){let n=e.length,r=c?128:0,s=n<126?d.from([128|a,r|n]):n<65536?d.from([128|a,r|126,n>>8,n&255]):(()=>{let o=d.alloc(10);return o[0]=128|a,o[1]=r|127,o.writeBigUInt64BE(BigInt(n),2),o})();if(!c)return d.concat([s,d.from(e)]);let t=U(4),i=d.from(e);for(let o=0;o<i.length;o++)i[o]^=t[o&3];return d.concat([s,t,i])}function D(a,e,c,n=!1){let r=d.alloc(0),s=[],t=0,i=!1,o=[],p=[],u=()=>{i||(i=!0,p.forEach(l=>l()))},f=(l=1e3,g="")=>{if(i)return;let h=d.from(g),m=d.alloc(2+h.length);m.writeUInt16BE(l,0),h.copy(m,2);try{a.write(A(8,m,n))}catch{}a.end(),u()};return a.on("data",l=>{for(r=d.concat([r,l]);r.length>=2;){let g=(r[0]&128)!==0,h=r[0]&15,m=(r[1]&128)!==0,v=r[1]&127,w=2;if(v===126){if(r.length<4)return;v=r.readUInt16BE(2),w=4}else if(v===127){if(r.length<10)return;let b=r.readBigUInt64BE(2);if(b>BigInt(c))return f(1009,"too big");v=Number(b),w=10}if(m===n)return f(1002,n?"server frames must not be masked":"client frames must be masked");if(v>c||t+v>c)return f(1009,"message too big");let T=m?4:0;if(r.length<w+T+v)return;let S=d.from(r.subarray(w+T,w+T+v));if(m){let b=r.subarray(w,w+4);for(let x=0;x<S.length;x++)S[x]^=b[x&3]}if(r=r.subarray(w+T+v),h===8)return f(1e3);if(h===9){a.write(A(10,S,n));continue}if(h!==10){if(h===1||h===0){if(s.push(S),t+=S.length,g){let b=d.concat(s).toString("utf8");s=[],t=0,o.forEach(x=>x(b))}continue}return f(1003,"text frames only")}}}),a.on("close",u),a.on("error",u),{origin:e,send:l=>{i||a.write(A(1,d.from(l,"utf8"),n))},close:f,onMessage:l=>{o.push(l)},onClose:l=>{p.push(l)}}}function J(a,e){let c=new Set,n=X.createServer((r,s)=>{let t=n.address();a.onHttp?.(r,s,typeof t=="object"&&t?t.port:a.port)||(s.writeHead(426,{"content-type":"text/plain"}),s.end("websocket only"))});return n.on("upgrade",(r,s)=>{let t=r.headers["sec-websocket-key"];if(r.url?.split("?")[0]!==a.path||typeof t!="string"||String(r.headers.upgrade).toLowerCase()!=="websocket"){s.end(`HTTP/1.1 400 Bad Request\r
3
+ import{a as L}from"./chunk-TWHNQFKI.js";import{A as O,B as R,D as W,E as I,ba as P,n as _,s as H,y as N}from"./chunk-GTPTZRO6.js";import X from"node:http";import{connect as Y}from"node:net";import{createHash as M,randomBytes as U}from"node:crypto";import{Buffer as d}from"node:buffer";var j="258EAFA5-E914-47DA-95CA-C5AB0DC85B11";function A(a,e,c=!1){let n=e.length,r=c?128:0,s=n<126?d.from([128|a,r|n]):n<65536?d.from([128|a,r|126,n>>8,n&255]):(()=>{let o=d.alloc(10);return o[0]=128|a,o[1]=r|127,o.writeBigUInt64BE(BigInt(n),2),o})();if(!c)return d.concat([s,d.from(e)]);let t=U(4),i=d.from(e);for(let o=0;o<i.length;o++)i[o]^=t[o&3];return d.concat([s,t,i])}function D(a,e,c,n=!1){let r=d.alloc(0),s=[],t=0,i=!1,o=[],p=[],u=()=>{i||(i=!0,p.forEach(l=>l()))},f=(l=1e3,m="")=>{if(i)return;let h=d.from(m),g=d.alloc(2+h.length);g.writeUInt16BE(l,0),h.copy(g,2);try{a.write(A(8,g,n))}catch{}a.end(),u()};return a.on("data",l=>{for(r=d.concat([r,l]);r.length>=2;){let m=(r[0]&128)!==0,h=r[0]&15,g=(r[1]&128)!==0,v=r[1]&127,w=2;if(v===126){if(r.length<4)return;v=r.readUInt16BE(2),w=4}else if(v===127){if(r.length<10)return;let b=r.readBigUInt64BE(2);if(b>BigInt(c))return f(1009,"too big");v=Number(b),w=10}if(g===n)return f(1002,n?"server frames must not be masked":"client frames must be masked");if(v>c||t+v>c)return f(1009,"message too big");let E=g?4:0;if(r.length<w+E+v)return;let S=d.from(r.subarray(w+E,w+E+v));if(g){let b=r.subarray(w,w+4);for(let x=0;x<S.length;x++)S[x]^=b[x&3]}if(r=r.subarray(w+E+v),h===8)return f(1e3);if(h===9){a.write(A(10,S,n));continue}if(h!==10){if(h===1||h===0){if(s.push(S),t+=S.length,m){let b=d.concat(s).toString("utf8");s=[],t=0,o.forEach(x=>x(b))}continue}return f(1003,"text frames only")}}}),a.on("close",u),a.on("error",u),{origin:e,send:l=>{i||a.write(A(1,d.from(l,"utf8"),n))},close:f,onMessage:l=>{o.push(l)},onClose:l=>{p.push(l)}}}function J(a,e){let c=new Set,n=X.createServer((r,s)=>{let t=n.address();a.onHttp?.(r,s,typeof t=="object"&&t?t.port:a.port)||(s.writeHead(426,{"content-type":"text/plain"}),s.end("websocket only"))});return n.on("upgrade",(r,s)=>{let t=r.headers["sec-websocket-key"];if(r.url?.split("?")[0]!==a.path||typeof t!="string"||String(r.headers.upgrade).toLowerCase()!=="websocket"){s.end(`HTTP/1.1 400 Bad Request\r
4
4
  \r
5
5
  `);return}let i=M("sha1").update(t+j).digest("base64");s.write(`HTTP/1.1 101 Switching Protocols\r
6
6
  Upgrade: websocket\r
@@ -16,5 +16,5 @@ Sec-WebSocket-Version: 13\r
16
16
  \r
17
17
  `));let p=d.alloc(0),u=f=>{p=d.concat([p,f]);let l=p.indexOf(`\r
18
18
  \r
19
- `);if(l<0)return;i.off("data",u);let g=p.subarray(0,l).toString("latin1").split(`\r
20
- `),h=g.find(w=>/^sec-websocket-accept:/i.test(w))?.split(":")[1]?.trim();if(!/^HTTP\/1\.1 101/.test(g[0])||h!==r)return o(new Error(`${c.host} refused the WebSocket upgrade: ${g[0]}`));i.setTimeout(0),i.off("error",o);let m=p.subarray(l+4),v=D(i,null,e.maxBytes,!0);m.length&&i.emit("data",m),s(v)};i.on("data",u)})}import{existsSync as K,readFileSync as Q}from"node:fs";var k=1,Z=[48127,48128,48129,48130,48131,48132,48133,48134],q=5e3,F=4,ee=8*1024*1024,y=class extends Error{constructor(c,n){super(n);this.code=c}},$=()=>P(_(),"host-bridge","pairing.json"),B="/avid-panel/",te="/avid-panel/pairing",G="avid",z={"index.html":"text/html; charset=utf-8","panel.js":"text/javascript; charset=utf-8","panel.css":"text/css; charset=utf-8","icon.svg":"image/svg+xml"},ne="default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self' ws://localhost:{port} ws://127.0.0.1:{port} http://localhost:* http://127.0.0.1:* https://localhost:* https://127.0.0.1:*; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",V=a=>[`http://localhost:${a}`,`http://127.0.0.1:${a}`];function re(){for(let a of["./avid/panel/web-dist/","./avid-panel/"]){let e=C(new URL(a,import.meta.url));if(K(P(e,"index.html")))return e}return null}function oe(){let a=new Uint8Array(32);return crypto.getRandomValues(a),Array.from(a,e=>e.toString(16).padStart(2,"0")).join("")}var H=class{constructor(){this.token=oe();this.port=0;this.live=new Map;this.waiters=[];this.seq=0;this.events=[]}async start(e=Z){let c;for(let n of e)try{this.server=await J({hostname:"127.0.0.1",port:n,path:"/host-bridge",maxBytes:ee,onHttp:(r,s,t)=>this.servePanel(r,s,t)},r=>this.accept(r)),this.port=this.server.port;break}catch(r){c=r}if(!this.server)throw new y("no_port",`every host-bridge port (${e.join(", ")}) is taken: ${c}`);await R(P(_(),"host-bridge")),await O($(),JSON.stringify({protocol:k,url:`ws://127.0.0.1:${this.port}/host-bridge`,port:this.port,token:this.token})),await I($(),384)}async stop(){for(let e of this.live.values())e.conn.close(1001,"engine stopping");this.live.clear(),await this.server?.close();try{JSON.parse(await N($())).token===this.token&&await W($())}catch{}}peers(){return[...this.live.values()].map(e=>e.peer)}peer(e){return this.live.get(e)?.peer}async waitFor(e,c){return this.live.has(e)?this.peer(e):(await Promise.race([new Promise(n=>this.waiters.push({host:e,resolve:n})),new Promise(n=>setTimeout(n,c))]),this.peer(e))}request(e,c,n={},r=3e4){let s=this.live.get(e);if(!s)return Promise.reject(new y("not_connected",`${e}: its panel is not connected`));let t=`r${++this.seq}`;return new Promise((i,o)=>{let p=setTimeout(()=>{s.pending.delete(t),o(new y("timeout",`${e}: no answer to ${c} within ${Math.round(r/1e3)} s`))},r);s.pending.set(t,{resolve:i,reject:o,timer:p}),s.conn.send(JSON.stringify({type:"request",id:t,method:c,params:n}))})}servePanel(e,c,n){let r=(e.url??"").split("?")[0];if(!r.startsWith(B)&&r!==B.slice(0,-1))return!1;let s=(f,l,g,h=!1)=>{let m=typeof g=="string"?new TextEncoder().encode(g):g;return c.writeHead(f,{"content-type":l,"content-length":String(m.length),"cache-control":"no-store","x-content-type-options":"nosniff","referrer-policy":"no-referrer","cross-origin-resource-policy":"same-origin","x-frame-options":"DENY","content-security-policy":ne.replaceAll("{port}",String(n))}),c.end(h?void 0:m),!0},t=(f,l)=>s(f,"text/plain; charset=utf-8",l),i=f=>{let l=e.headers[f];return typeof l=="string"?l:void 0},o=(i("host")??"").toLowerCase();if(o!==`localhost:${n}`&&o!==`127.0.0.1:${n}`)return t(421,"misdirected request");if(r===te)return e.method==="POST"&&V(n).includes(i("origin")??"")&&(i("sec-fetch-site")??"same-origin")==="same-origin"&&i("x-ct-panel")==="1"&&(i("content-length")??"0").trim()==="0"?s(200,"application/json",JSON.stringify({protocol:k,url:`ws://localhost:${n}/host-bridge`,port:n,token:this.token})):t(403,"forbidden");if(e.method!=="GET"&&e.method!=="HEAD")return t(405,"method not allowed");let p=r.slice(B.length)||"index.html",u=re();return!z[p]||!u?t(404,"not found"):s(200,z[p],Q(P(u,p)),e.method==="HEAD")}accept(e){let c=!!e.origin&&V(this.port).includes(e.origin);if(e.origin&&/^https?:/i.test(e.origin)&&!c){e.send(JSON.stringify({type:"error",code:"origin_refused",message:"web pages may not use the host bridge"})),e.close(1008,"origin");return}let n=null,r=setTimeout(()=>{n||(e.send(JSON.stringify({type:"error",code:"hello_timeout",message:"no hello"})),e.close(1008,"hello"))},q);e.onMessage(s=>{let t;try{t=JSON.parse(s)}catch{return}if(!n){let o=(l,g)=>{clearTimeout(r),e.send(JSON.stringify({type:"error",code:l,message:g})),e.close(1008,l)};if(t.type!=="hello")return o("hello_expected","the first frame must be hello");if(t.protocol!==k)return o("protocol_mismatch",`this engine speaks protocol ${k}`);if(t.token!==this.token)return o("bad_token","the pairing token does not match: re-read the pairing file");let p=t.host??{},u=String(p.id??"");if(!/^[a-z][a-z0-9_-]{1,31}$/.test(u))return o("bad_host","host.id is missing or malformed");if(c&&u!==G)return o("origin_mismatch",`a connection from the panel page may only be host ${G}`);if(!this.live.has(u)&&this.live.size>=F)return o("too_many_peers",`at most ${F} panels`);clearTimeout(r),this.live.get(u)?.conn.close(1e3,"replaced by a newer connection"),n=u;let f={id:u,name:String(p.name??u),version:String(p.version??""),platform:String(p.platform??""),capabilities:Array.isArray(t.capabilities)?t.capabilities.map(String):[],optional_verbs:Array.isArray(t.optional_verbs)?t.optional_verbs.map(String):[]};this.live.set(u,{peer:f,conn:e,pending:new Map}),e.send(JSON.stringify({type:"welcome",protocol:k,app:{name:"conformtools",version:L}})),this.waiters=this.waiters.filter(l=>l.host===u?(l.resolve(),!1):!0);return}let i=this.live.get(n);if(!(!i||i.conn!==e))if(t.type==="response"){let o=i.pending.get(String(t.id));if(!o)return;if(i.pending.delete(String(t.id)),clearTimeout(o.timer),t.ok)o.resolve(t.result??null);else{let p=t.error??{};o.reject(new y(p.code??"peer_error",`${n}: ${p.message??p.code??"error"}`))}}else t.type==="event"&&(this.events.push({host:n,name:String(t.name),data:t.data}),this.events.length>200&&this.events.shift())}),e.onClose(()=>{if(clearTimeout(r),!n)return;let s=this.live.get(n);if(s?.conn===e){for(let t of s.pending.values())clearTimeout(t.timer),t.reject(new y("disconnected",`${n}: the panel disconnected`));this.live.delete(n)}})}},E=null;function me(){return E??=(async()=>{let a=new H;return await a.start(),a})(),E.catch(()=>{E=null}),E}function he(){E=null}export{le as a,k as b,Z as c,y as d,$ as e,B as f,V as g,H as h,me as i,he as j};
19
+ `);if(l<0)return;i.off("data",u);let m=p.subarray(0,l).toString("latin1").split(`\r
20
+ `),h=m.find(w=>/^sec-websocket-accept:/i.test(w))?.split(":")[1]?.trim();if(!/^HTTP\/1\.1 101/.test(m[0])||h!==r)return o(new Error(`${c.host} refused the WebSocket upgrade: ${m[0]}`));i.setTimeout(0),i.off("error",o);let g=p.subarray(l+4),v=D(i,null,e.maxBytes,!0);g.length&&i.emit("data",g),s(v)};i.on("data",u)})}import{existsSync as K,readFileSync as Q}from"node:fs";var k=1,Z=[48127,48128,48129,48130,48131,48132,48133,48134],q=5e3,F=4,ee=8*1024*1024,y=class extends Error{constructor(c,n){super(n);this.code=c}},T=()=>P(_(),"host-bridge","pairing.json"),B="/avid-panel/",te="/avid-panel/pairing",G="avid",z={"index.html":"text/html; charset=utf-8","panel.js":"text/javascript; charset=utf-8","panel.css":"text/css; charset=utf-8","icon.svg":"image/svg+xml"},ne="default-src 'none'; script-src 'self'; style-src 'self'; img-src 'self' data:; connect-src 'self' ws://localhost:{port} ws://127.0.0.1:{port} http://localhost:* http://127.0.0.1:* https://localhost:* https://127.0.0.1:*; base-uri 'none'; form-action 'none'; frame-ancestors 'none'",V=a=>[`http://localhost:${a}`,`http://127.0.0.1:${a}`];function re(){for(let a of["./avid/panel/web-dist/","./avid-panel/"]){let e=H(new URL(a,import.meta.url));if(K(P(e,"index.html")))return e}return null}function oe(){let a=new Uint8Array(32);return crypto.getRandomValues(a),Array.from(a,e=>e.toString(16).padStart(2,"0")).join("")}var C=class{constructor(){this.token=oe();this.port=0;this.live=new Map;this.waiters=[];this.seq=0;this.events=[]}async start(e=Z){let c;for(let n of e)try{this.server=await J({hostname:"127.0.0.1",port:n,path:"/host-bridge",maxBytes:ee,onHttp:(r,s,t)=>this.servePanel(r,s,t)},r=>this.accept(r)),this.port=this.server.port;break}catch(r){c=r}if(!this.server)throw new y("no_port",`every host-bridge port (${e.join(", ")}) is taken: ${c}`);await R(P(_(),"host-bridge")),await O(T(),JSON.stringify({protocol:k,url:`ws://127.0.0.1:${this.port}/host-bridge`,port:this.port,token:this.token})),await I(T(),384)}async stop(){for(let e of this.live.values())e.conn.close(1001,"engine stopping");this.live.clear(),await this.server?.close();try{JSON.parse(await N(T())).token===this.token&&await W(T())}catch{}}peers(){return[...this.live.values()].map(e=>e.peer)}peer(e){return this.live.get(e)?.peer}async waitFor(e,c){return this.live.has(e)?this.peer(e):(await Promise.race([new Promise(n=>this.waiters.push({host:e,resolve:n})),new Promise(n=>setTimeout(n,c))]),this.peer(e))}request(e,c,n={},r=3e4){let s=this.live.get(e);if(!s)return Promise.reject(new y("not_connected",`${e}: its panel is not connected`));let t=`r${++this.seq}`;return new Promise((i,o)=>{let p=setTimeout(()=>{s.pending.delete(t),o(new y("timeout",`${e}: no answer to ${c} within ${Math.round(r/1e3)} s`))},r);s.pending.set(t,{resolve:i,reject:o,timer:p}),s.conn.send(JSON.stringify({type:"request",id:t,method:c,params:n}))})}servePanel(e,c,n){let r=(e.url??"").split("?")[0];if(!r.startsWith(B)&&r!==B.slice(0,-1))return!1;let s=(f,l,m,h=!1)=>{let g=typeof m=="string"?new TextEncoder().encode(m):m;return c.writeHead(f,{"content-type":l,"content-length":String(g.length),"cache-control":"no-store","x-content-type-options":"nosniff","referrer-policy":"no-referrer","cross-origin-resource-policy":"same-origin","x-frame-options":"DENY","content-security-policy":ne.replaceAll("{port}",String(n))}),c.end(h?void 0:g),!0},t=(f,l)=>s(f,"text/plain; charset=utf-8",l),i=f=>{let l=e.headers[f];return typeof l=="string"?l:void 0},o=(i("host")??"").toLowerCase();if(o!==`localhost:${n}`&&o!==`127.0.0.1:${n}`)return t(421,"misdirected request");if(r===te)return e.method==="POST"&&V(n).includes(i("origin")??"")&&(i("sec-fetch-site")??"same-origin")==="same-origin"&&i("x-ct-panel")==="1"&&(i("content-length")??"0").trim()==="0"?s(200,"application/json",JSON.stringify({protocol:k,url:`ws://localhost:${n}/host-bridge`,port:n,token:this.token})):t(403,"forbidden");if(e.method!=="GET"&&e.method!=="HEAD")return t(405,"method not allowed");let p=r.slice(B.length)||"index.html",u=re();return!z[p]||!u?t(404,"not found"):s(200,z[p],Q(P(u,p)),e.method==="HEAD")}accept(e){let c=!!e.origin&&V(this.port).includes(e.origin);if(e.origin&&/^https?:/i.test(e.origin)&&!c){e.send(JSON.stringify({type:"error",code:"origin_refused",message:"web pages may not use the host bridge"})),e.close(1008,"origin");return}let n=null,r=setTimeout(()=>{n||(e.send(JSON.stringify({type:"error",code:"hello_timeout",message:"no hello"})),e.close(1008,"hello"))},q);e.onMessage(s=>{let t;try{t=JSON.parse(s)}catch{return}if(!n){let o=(l,m)=>{clearTimeout(r),e.send(JSON.stringify({type:"error",code:l,message:m})),e.close(1008,l)};if(t.type!=="hello")return o("hello_expected","the first frame must be hello");if(t.protocol!==k)return o("protocol_mismatch",`this engine speaks protocol ${k}`);if(t.token!==this.token)return o("bad_token","the pairing token does not match: re-read the pairing file");let p=t.host??{},u=String(p.id??"");if(!/^[a-z][a-z0-9_-]{1,31}$/.test(u))return o("bad_host","host.id is missing or malformed");if(c&&u!==G)return o("origin_mismatch",`a connection from the panel page may only be host ${G}`);if(!this.live.has(u)&&this.live.size>=F)return o("too_many_peers",`at most ${F} panels`);clearTimeout(r),this.live.get(u)?.conn.close(1e3,"replaced by a newer connection"),n=u;let f={id:u,name:String(p.name??u),version:String(p.version??""),platform:String(p.platform??""),capabilities:Array.isArray(t.capabilities)?t.capabilities.map(String):[],optional_verbs:Array.isArray(t.optional_verbs)?t.optional_verbs.map(String):[]};this.live.set(u,{peer:f,conn:e,pending:new Map}),e.send(JSON.stringify({type:"welcome",protocol:k,app:{name:"conformtools",version:L}})),this.waiters=this.waiters.filter(l=>l.host===u?(l.resolve(),!1):!0);return}let i=this.live.get(n);if(!(!i||i.conn!==e))if(t.type==="response"){let o=i.pending.get(String(t.id));if(!o)return;if(i.pending.delete(String(t.id)),clearTimeout(o.timer),t.ok)o.resolve(t.result??null);else{let p=t.error??{};o.reject(new y(p.code??"peer_error",`${n}: ${p.message??p.code??"error"}`))}}else t.type==="event"&&(this.events.push({host:n,name:String(t.name),data:t.data}),this.events.length>200&&this.events.shift())}),e.onClose(()=>{if(clearTimeout(r),!n)return;let s=this.live.get(n);if(s?.conn===e){for(let t of s.pending.values())clearTimeout(t.timer),t.reject(new y("disconnected",`${n}: the panel disconnected`));this.live.delete(n)}})}},$=null;function ge(){return $??=(async()=>{let a=new C;return await a.start(),a})(),$.catch(()=>{$=null}),$}export{le as a,k as b,Z as c,y as d,T as e,B as f,V as g,C as h,ge as i};