conformtools 0.6.14 → 0.6.16

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 (81) hide show
  1. package/README.md +6 -1
  2. package/dist/account-W7Z2MYZU.js +3 -0
  3. package/dist/{agent-hook-setup-RTQT5JEN.js → agent-hook-setup-JCIZG3Q3.js} +1 -1
  4. package/dist/{analysis-engine-UWIK7AYB.js → analysis-engine-DCHJHZ7W.js} +1 -1
  5. package/dist/{bridge-46P34WCD.js → bridge-UPSJ7F3S.js} +1 -1
  6. package/dist/browser/timeline_core_bg.wasm +0 -0
  7. package/dist/{chunk-CQSNVQQE.js → chunk-4RA57LTJ.js} +1 -1
  8. package/dist/chunk-5W57ITT2.js +10 -0
  9. package/dist/chunk-DLF5AKXT.js +10 -0
  10. package/dist/chunk-FLLB6UZJ.js +7 -0
  11. package/dist/{chunk-FXK53VEO.js → chunk-HOACOBAY.js} +1 -1
  12. package/dist/{chunk-YKKB27VF.js → chunk-IDJIOKXA.js} +1 -1
  13. package/dist/{chunk-L3HRAIDR.js → chunk-JL454FFL.js} +1 -1
  14. package/dist/chunk-JM5LHKTU.js +510 -0
  15. package/dist/chunk-JV7TZDKJ.js +3 -0
  16. package/dist/chunk-MGMDNGNX.js +6 -0
  17. package/dist/chunk-OWWXUNJF.js +7 -0
  18. package/dist/{chunk-NZLL44HU.js → chunk-QH5DTYSE.js} +1 -1
  19. package/dist/{chunk-BO462NEL.js → chunk-QRZO5GOI.js} +1 -1
  20. package/dist/chunk-RJD44NQU.js +5 -0
  21. package/dist/{chunk-PHAMF4JF.js → chunk-ROGMKTND.js} +2 -2
  22. package/dist/{chunk-764P7TUD.js → chunk-RVZQ3Y6N.js} +1 -1
  23. package/dist/{chunk-6WLSIH2N.js → chunk-UAURERD3.js} +1 -1
  24. package/dist/{chunk-MOSLNNO5.js → chunk-UKXSKFL3.js} +1 -1
  25. package/dist/{chunk-EP4L2BWV.js → chunk-VETHR2O7.js} +1 -1
  26. package/dist/chunk-VWFEMXYZ.js +159 -0
  27. package/dist/chunk-X527E5VI.js +3 -0
  28. package/dist/{chunk-4BTTR6U3.js → chunk-XVZ7KJRI.js} +5 -5
  29. package/dist/{claude-setup-NGZ5NDYH.js → claude-setup-CM7G2YSG.js} +8 -8
  30. package/dist/cli.js +2 -2
  31. package/dist/demo-engine-CBFAAPPO.js +3 -0
  32. package/dist/engine-6YYXTF2Q.js +5 -0
  33. package/dist/framing-QYRCUEB5.js +3 -0
  34. package/dist/gfx-worker.js +1 -1
  35. package/dist/{h264-MAUQSLPY.js → h264-MAUVJTR4.js} +1 -1
  36. package/dist/{h264-mxf-2SZ66MPB.js → h264-mxf-2O4SAUTA.js} +1 -1
  37. package/dist/hook.js +1 -1
  38. package/dist/{host-relink-664IB3BC.js → host-relink-NVLUO73P.js} +1 -1
  39. package/dist/hosted-2XACQY7J.js +3 -0
  40. package/dist/hosts-GEXAZFB3.js +3 -0
  41. package/dist/http.js +3 -3
  42. package/dist/{inspect-ZM7IW23B.js → inspect-YIFLNOJW.js} +2 -2
  43. package/dist/isobmff-MTMGQKLK.js +3 -0
  44. package/dist/{mc-video-KMWTRVES.js → mc-video-HRZC7HGH.js} +1 -1
  45. package/dist/mcp.js +1 -1
  46. package/dist/{media-MSMXMA6E.js → media-WC4ZVKIL.js} +1 -1
  47. package/dist/{mxf-GOWHEH4A.js → mxf-J5QHA3VY.js} +1 -1
  48. package/dist/{ops-FI2NBTYK.js → ops-XIUVNJE2.js} +1 -1
  49. package/dist/probe-GIAKRPFV.js +3 -0
  50. package/dist/{r3d-LO5Z6DEX.js → r3d-2PCOFR2Z.js} +1 -1
  51. package/dist/resolve-bridge.py +116 -146
  52. package/dist/{sequence-patch-C2QRIT5V.js → sequence-patch-DFGEAJGB.js} +1 -1
  53. package/dist/{still-6FU7ALUV.js → still-4UR35GZH.js} +1 -1
  54. package/dist/{store-JNWELX35.js → store-MWNX47IK.js} +1 -1
  55. package/dist/timeline-Z3KD2CJX.js +3 -0
  56. package/dist/wasm/udf_bg.wasm +0 -0
  57. package/package.json +5 -5
  58. package/dist/account-F54SG45Q.js +0 -3
  59. package/dist/chunk-5PTQAFU5.js +0 -158
  60. package/dist/chunk-BTS3DFPD.js +0 -7
  61. package/dist/chunk-DP4KJ3KL.js +0 -514
  62. package/dist/chunk-EKTETRKB.js +0 -6
  63. package/dist/chunk-J43UCJ6G.js +0 -4
  64. package/dist/chunk-MJBJI6DV.js +0 -3
  65. package/dist/chunk-O372NT7V.js +0 -7
  66. package/dist/chunk-OD445COC.js +0 -7
  67. package/dist/chunk-P3EOFAZR.js +0 -10
  68. package/dist/chunk-XI6XF7FQ.js +0 -3
  69. package/dist/chunk-YYR3FM6A.js +0 -5
  70. package/dist/engine-6ACEWA4S.js +0 -5
  71. package/dist/framing-4HAHAG4I.js +0 -3
  72. package/dist/hosted-L26AGRIY.js +0 -3
  73. package/dist/hosts-BGWD7BKM.js +0 -3
  74. package/dist/isobmff-6ZPEXUF4.js +0 -3
  75. package/dist/nuke/panel/python/Startup/conformtools_nuke_startup.py +0 -44
  76. package/dist/nuke/panel/python/conformtools_nuke/__init__.py +0 -10
  77. package/dist/nuke/panel/python/conformtools_nuke/panel.py +0 -217
  78. package/dist/nuke/panel/python/conformtools_nuke/verbs.py +0 -837
  79. package/dist/probe-ZDX6XNRF.js +0 -3
  80. package/dist/resolve-presets/conform.tools.xml +0 -127
  81. package/dist/timeline-WVETLJZN.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 MCP or App plan ([pricing](https://conform.tools/pricing)); the free trial covers the web tools only. The engine is invite-only for now.
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.
14
14
 
15
15
  ## 1. Sign in
16
16
 
@@ -181,6 +181,11 @@ Claude Desktop has no hooks, so nothing is added there.
181
181
  conformtools hooks status # or on, or off; telemetry off removes it too
182
182
  ```
183
183
 
184
+ **In the desktop app, it also records which built-in tools you open, which view is in front, and whether a
185
+ run was reviewed, applied, undone or dropped.** A tool you built yourself is recorded as `custom`, never by
186
+ its name; no project, path, setting or anything you type is kept. It is how we see a tool that gets opened
187
+ and never used, or a review that gets dropped every time. The same switch turns it off.
188
+
184
189
  It records, for each tool run: the tool's name, whether it worked (or the error code and, for
185
190
  a failure, the error message with every name and path replaced by a placeholder), how
186
191
  long it took, the conformtools version, local or conform.tools, counts such as the number of
@@ -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{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};
@@ -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-BTS3DFPD.js";import"./chunk-XI6XF7FQ.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-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};
@@ -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-EP4L2BWV.js";import"./chunk-PHAMF4JF.js";import"./chunk-XI6XF7FQ.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-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};
@@ -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}from"./chunk-FXK53VEO.js";import"./chunk-764P7TUD.js";import"./chunk-XI6XF7FQ.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,i as resetHostBridge};
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}from"./chunk-HOACOBAY.js";import"./chunk-RVZQ3Y6N.js";import"./chunk-X527E5VI.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,i as resetHostBridge};
Binary file
@@ -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
- var s={scrub:{output:"rgba8",detail:"coarse"},thumbnail:{output:"rgba8",detail:"coarse"},park:{output:"rgba8",detail:"exact"},render:{output:"rgba8",detail:"exact"},transcode:{output:"rgb16",detail:"exact"}};function p(e){let t=new DataView(e.buffer,e.byteOffset,8),r=t.getUint32(0,!0),n=t.getUint32(4,!0),o=e.slice(8);return{width:r,height:n,rgb16:new Uint16Array(o.buffer,o.byteOffset,r*n*3)}}var a=class extends Error{constructor(r,n){super(`COVERAGE_MISS: frame ${r} not in linked media (${n} frames)`);this.index=r;this.frameCount=n;this.name="CoverageMissError"}},m=/(?:[A-Z0-9]+_)?COVERAGE_MISS\s+(\{[\s\S]*\})/;function d(e){let r=(e instanceof Error?e.message:String(e??"")).match(m);if(!r)return null;try{return JSON.parse(r[1])}catch{return{reason:"coverage_miss"}}}var i=class extends Error{constructor(r){super(`DELIVERY_COVERAGE_MISS: ${r.reason}`+(r.cut_in!=null?` cut [${r.cut_in}..${r.cut_out}] file_frames ${r.file_frames}`:""));this.detail=r;this.name="DeliveryCoverageMissError"}};function l(e){return e instanceof i?e.detail:d(e)}var u={mov:()=>import("./isobmff-6ZPEXUF4.js").then(e=>e.isobmffFormat),crm:()=>import("./isobmff-6ZPEXUF4.js").then(e=>e.isobmffFormat),braw:()=>import("./isobmff-6ZPEXUF4.js").then(e=>e.isobmffFormat),wav:()=>import("./wav-HSCUCY4U.js").then(e=>e.wavFormat),mxf:()=>import("./mxf-GOWHEH4A.js").then(e=>e.mxfFormat),r3d:()=>import("./r3d-LO5Z6DEX.js").then(e=>e.r3dFormat),still:()=>import("./still-6FU7ALUV.js").then(e=>e.stillFormat),avc1:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),avc3:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),h264:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),hvc1:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),hev1:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),hevc:()=>import("./h264-MAUQSLPY.js").then(e=>e.h264Format),h264_mxf:()=>import("./h264-mxf-2SZ66MPB.js").then(e=>e.h264MxfFormat),mcvideo:()=>import("./mc-video-KMWTRVES.js").then(e=>e.mcVideoFormat)};async function c(e){let t=u[e];return t?await t():null}async function f(e){let t=await c(e.format);if(!t)throw new Error(`extract: no handler for format '${e.format}'`);return t.extract(e)}async function b(e,t){let r=await c(e.format);if(!r){if(t.verb==="inspect")return null;throw new Error(`mediaOp: no handler for format '${e.format}' (verb ${t.verb})`)}switch(t.verb){case"inspect":{let n=await r.inspect(e);return n&&(n.source_facts_origin="probed"),n}case"sparsify":return r.sparsify(e,t.selection);case"trim":return r.trim(e,t.selection);case"decode":{let{output:n,detail:o}=s[t.intent];if(n==="rgb16"){if(!r.decode16)throw new Error(`mediaOp: format '${e.format}' has no 16-bit decoder (intent '${t.intent}')`);return r.decode16(e,t.index)}if(!r.decode)throw new Error(`mediaOp: format '${e.format}' has no decoder (no viewer)`);return r.decode(e,t.index,{detail:o})}}}export{s as a,p as b,a as c,d,i as e,l as f,c as g,f as h,b as i};
3
+ var s={scrub:{output:"rgba8",detail:"coarse"},thumbnail:{output:"rgba8",detail:"coarse"},park:{output:"rgba8",detail:"exact"},render:{output:"rgba8",detail:"exact"},transcode:{output:"rgb16",detail:"exact"}};function p(e){let t=new DataView(e.buffer,e.byteOffset,8),r=t.getUint32(0,!0),n=t.getUint32(4,!0),o=e.slice(8);return{width:r,height:n,rgb16:new Uint16Array(o.buffer,o.byteOffset,r*n*3)}}var a=class extends Error{constructor(r,n){super(`COVERAGE_MISS: frame ${r} not in linked media (${n} frames)`);this.index=r;this.frameCount=n;this.name="CoverageMissError"}},m=/(?:[A-Z0-9]+_)?COVERAGE_MISS\s+(\{[\s\S]*\})/;function d(e){let r=(e instanceof Error?e.message:String(e??"")).match(m);if(!r)return null;try{return JSON.parse(r[1])}catch{return{reason:"coverage_miss"}}}var i=class extends Error{constructor(r){super(`DELIVERY_COVERAGE_MISS: ${r.reason}`+(r.cut_in!=null?` cut [${r.cut_in}..${r.cut_out}] file_frames ${r.file_frames}`:""));this.detail=r;this.name="DeliveryCoverageMissError"}};function l(e){return e instanceof i?e.detail:d(e)}var u={mov:()=>import("./isobmff-MTMGQKLK.js").then(e=>e.isobmffFormat),crm:()=>import("./isobmff-MTMGQKLK.js").then(e=>e.isobmffFormat),braw:()=>import("./isobmff-MTMGQKLK.js").then(e=>e.isobmffFormat),wav:()=>import("./wav-HSCUCY4U.js").then(e=>e.wavFormat),mxf:()=>import("./mxf-J5QHA3VY.js").then(e=>e.mxfFormat),r3d:()=>import("./r3d-2PCOFR2Z.js").then(e=>e.r3dFormat),still:()=>import("./still-4UR35GZH.js").then(e=>e.stillFormat),avc1:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),avc3:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),h264:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),hvc1:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),hev1:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),hevc:()=>import("./h264-MAUVJTR4.js").then(e=>e.h264Format),h264_mxf:()=>import("./h264-mxf-2O4SAUTA.js").then(e=>e.h264MxfFormat),mcvideo:()=>import("./mc-video-HRZC7HGH.js").then(e=>e.mcVideoFormat)};async function c(e){let t=u[e];return t?await t():null}async function f(e){let t=await c(e.format);if(!t)throw new Error(`extract: no handler for format '${e.format}'`);return t.extract(e)}async function b(e,t){let r=await c(e.format);if(!r){if(t.verb==="inspect")return null;throw new Error(`mediaOp: no handler for format '${e.format}' (verb ${t.verb})`)}switch(t.verb){case"inspect":{let n=await r.inspect(e);return n&&(n.source_facts_origin="probed"),n}case"sparsify":return r.sparsify(e,t.selection);case"trim":return r.trim(e,t.selection);case"decode":{let{output:n,detail:o}=s[t.intent];if(n==="rgb16"){if(!r.decode16)throw new Error(`mediaOp: format '${e.format}' has no 16-bit decoder (intent '${t.intent}')`);return r.decode16(e,t.index)}if(!r.decode)throw new Error(`mediaOp: format '${e.format}' has no decoder (no viewer)`);return r.decode(e,t.index,{detail:o})}}}export{s as a,p as b,a as c,d,i as e,l as f,c as g,f as h,b as i};
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
+ import{a as Oe,b as dt}from"./chunk-MGMDNGNX.js";import{Q as lt,Ub as pt}from"./chunk-VWFEMXYZ.js";import{a as mt}from"./chunk-HOACOBAY.js";import{M as ct,S as X}from"./chunk-C2ESM27Z.js";import{b as Ee,d as ut}from"./chunk-NU3X7P4N.js";import{$ as fe,A as pe,B as Y,F as nt,H as me,L as q,M as rt,P as de,S as ot,V as st,W as it,_ as at,b as F,ba as I,g as H,i as Te,o as Pe,r as Xe,s as Ze,u as ce,v as le,x as ue,y as et,z as tt}from"./chunk-X527E5VI.js";function ft(n,e){let t=async()=>{throw new Error(`${n}: ${e}`)},r={ok:!1,reason:e};return{host:n,wired:!1,support:async()=>({export:r,open:r,render:r,markers:r}),export:t,open:t,renderStart:t,renderStatus:t,renderCancel:t}}async function ir(n,e,t,r){let o=new Promise(s=>r?.addEventListener("abort",()=>s(),{once:!0}));for(;e.state==="queued"||e.state==="rendering";){if(t?.(e.percent,100,"rendering"),await Promise.race([o.then(()=>!0),new Promise(i=>setTimeout(()=>i(!1),1e3))]))return await n.renderCancel(e.job_id);e=await n.renderStatus(e.job_id)}return e}var Wt=ArrayBuffer,O=Uint8Array,ge=Uint16Array,Kt=Int16Array;var he=Int32Array,Me=function(n,e,t){if(O.prototype.slice)return O.prototype.slice.call(n,e,t);(e==null||e<0)&&(e=0),(t==null||t>n.length)&&(t=n.length);var r=new O(t-e);return r.set(n.subarray(e,t)),r},ee=function(n,e,t,r){if(O.prototype.fill)return O.prototype.fill.call(n,e,t,r);for((t==null||t<0)&&(t=0),(r==null||r>n.length)&&(r=n.length);t<r;++t)n[t]=e;return n},Qt=function(n,e,t,r){if(O.prototype.copyWithin)return O.prototype.copyWithin.call(n,e,t,r);for((t==null||t<0)&&(t=0),(r==null||r>n.length)&&(r=n.length);t<r;)n[e++]=n[t++]};var Yt=["invalid zstd data","window size too large (>2046MB)","invalid block type","FSE accuracy too high","match distance too far back","unexpected EOF"],N=function(n,e,t){var r=new Error(e||Yt[n]);if(r.code=n,Error.captureStackTrace&&Error.captureStackTrace(r,N),!t)throw r;return r},gt=function(n,e,t){for(var r=0,o=0;r<t;++r)o|=n[e++]<<(r<<3);return o},Xt=function(n,e){return(n[e]|n[e+1]<<8|n[e+2]<<16|n[e+3]<<24)>>>0},Zt=function(n,e){var t=n[0]|n[1]<<8|n[2]<<16;if(t==3126568&&n[3]==253){var r=n[4],o=r>>5&1,s=r>>2&1,i=r&3,c=r>>6;r&8&&N(0);var a=6-o,p=i==3?4:i,l=gt(n,a,p);a+=p;var d=c?1<<c:o,f=gt(n,a,d)+(c==1&&256),h=f;if(!o){var u=1<<10+(n[5]>>3);h=u+(u>>3)*(n[5]&7)}h>2145386496&&N(1);var m=new O((e==1?f||h:e?0:h)+12);return m[0]=1,m[4]=4,m[8]=8,{b:a+d,y:0,l:0,d:l,w:e&&e!=1?e:m.subarray(12),e:h,o:new he(m.buffer,0,3),u:f,c:s,m:Math.min(131072,h)}}else if((t>>4|n[3]<<20)==25481893)return Xt(n,4)+8;N(0)},B=function(n){for(var e=0;1<<e<=n;++e);return e-1},te=function(n,e,t){var r=(e<<3)+4,o=(n[e]&15)+5;o>t&&N(3);for(var s=1<<o,i=s,c=-1,a=-1,p=-1,l=s,d=new Wt(512+(s<<2)),f=new Kt(d,0,256),h=new ge(d,0,256),u=new ge(d,512,s),m=512+(s<<1),g=new O(d,m,s),S=new O(d,m+s);c<255&&i>0;){var _=B(i+1),v=r>>3,R=(1<<_+1)-1,k=(n[v]|n[v+1]<<8|n[v+2]<<16)>>(r&7)&R,b=(1<<_)-1,w=R-i-1,T=k&b;if(T<w?(r+=_,k=T):(r+=_+1,k>b&&(k-=w)),f[++c]=--k,k==-1?(i+=k,g[--l]=c):i-=k,!k)do{var P=r>>3;a=(n[P]|n[P+1]<<8)>>(r&7)&3,r+=2,c+=a}while(a==3)}(c>255||i)&&N(0);for(var E=0,$=(s>>1)+(s>>3)+3,C=s-1,M=0;M<=c;++M){var y=f[M];if(y<1){h[M]=-y;continue}for(p=0;p<y;++p){g[E]=M;do E=E+$&C;while(E>=l)}}for(E&&N(0),p=0;p<s;++p){var x=h[g[p]]++,L=S[p]=o-B(x);u[p]=(x<<L)-s}return[r+7>>3,{b:o,s:g,n:S,t:u}]},en=function(n,e){var t=0,r=-1,o=new O(292),s=n[e],i=o.subarray(0,256),c=o.subarray(256,268),a=new ge(o.buffer,268);if(s<128){var p=te(n,e+1,6),l=p[0],d=p[1];e+=s;var f=l<<3,h=n[e];h||N(0);for(var u=0,m=0,g=d.b,S=g,_=(++e<<3)-8+B(h);_-=g,!(_<f);){var v=_>>3;if(u+=(n[v]|n[v+1]<<8)>>(_&7)&(1<<g)-1,i[++r]=d.s[u],_-=S,_<f)break;v=_>>3,m+=(n[v]|n[v+1]<<8)>>(_&7)&(1<<S)-1,i[++r]=d.s[m],g=d.n[u],u=d.t[u],S=d.n[m],m=d.t[m]}++r>255&&N(0)}else{for(r=s-127;t<r;t+=2){var R=n[++e];i[t]=R>>4,i[t+1]=R&15}++e}var k=0;for(t=0;t<r;++t){var b=i[t];b>11&&N(0),k+=b&&1<<b-1}var w=B(k)+1,T=1<<w,P=T-k;for(P&P-1&&N(0),i[r++]=B(P)+1,t=0;t<r;++t){var b=i[t];++c[i[t]=b&&w+1-b]}var E=new O(T<<1),$=E.subarray(0,T),C=E.subarray(T);for(a[w]=0,t=w;t>0;--t){var M=a[t];ee(C,t,M,a[t-1]=M+c[t]*(1<<w-t))}for(a[0]!=T&&N(0),t=0;t<r;++t){var y=i[t];if(y){var x=a[y];ee($,t,x,a[y]=x+(1<<w-y))}}return[e,{n:C,b:w,s:$}]},tn=te(new O([81,16,99,140,49,198,24,99,12,33,196,24,99,102,102,134,70,146,4]),0,6)[1],nn=te(new O([33,20,196,24,99,140,33,132,16,66,8,33,132,16,66,8,33,68,68,68,68,68,68,68,68,36,9]),0,6)[1],rn=te(new O([32,132,16,66,102,70,68,68,68,68,36,73,2]),0,5)[1],ht=function(n,e){for(var t=n.length,r=new he(t),o=0;o<t;++o)r[o]=e,e+=1<<n[o];return r},Ne=new O(new he([0,0,0,0,16843009,50528770,134678020,202050057,269422093]).buffer,0,36),on=ht(Ne,0),$e=new O(new he([0,0,0,0,0,0,0,0,16843009,50528770,117769220,185207048,252579084,16]).buffer,0,53),sn=ht($e,3),Z=function(n,e,t){var r=n.length,o=e.length,s=n[r-1],i=(1<<t.b)-1,c=-t.b;s||N(0);for(var a=0,p=t.b,l=(r<<3)-8+B(s)-p,d=-1;l>c&&d<o;){var f=l>>3,h=(n[f]|n[f+1]<<8|n[f+2]<<16)>>(l&7);a=(a<<p|h)&i,e[++d]=t.s[a],l-=p=t.n[a]}(l!=c||d+1!=o)&&N(0)},an=function(n,e,t){var r=6,o=e.length,s=o+3>>2,i=s<<1,c=s+i;Z(n.subarray(r,r+=n[0]|n[1]<<8),e.subarray(0,s),t),Z(n.subarray(r,r+=n[2]|n[3]<<8),e.subarray(s,i),t),Z(n.subarray(r,r+=n[4]|n[5]<<8),e.subarray(i,c),t),Z(n.subarray(r),e.subarray(c),t)},cn=function(n,e,t){var r,o=e.b,s=n[o],i=s>>1&3;e.l=s&1;var c=s>>3|n[o+1]<<5|n[o+2]<<13,a=(o+=3)+c;if(i==1)return o>=n.length?void 0:(e.b=o+1,t?(ee(t,n[o],e.y,e.y+=c),t):ee(new O(c),n[o]));if(!(a>n.length)){if(i==0)return e.b=a,t?(t.set(n.subarray(o,a),e.y),e.y+=c,t):Me(n,o,a);if(i==2){var p=n[o],l=p&3,d=p>>2&3,f=p>>4,h=0,u=0;l<2?d&1?f|=n[++o]<<4|(d&2&&n[++o]<<12):f=p>>3:(u=d,d<2?(f|=(n[++o]&63)<<4,h=n[o]>>6|n[++o]<<2):d==2?(f|=n[++o]<<4|(n[++o]&3)<<12,h=n[o]>>2|n[++o]<<6):(f|=n[++o]<<4|(n[++o]&63)<<12,h=n[o]>>6|n[++o]<<2|n[++o]<<10)),++o;var m=t?t.subarray(e.y,e.y+e.m):new O(e.m),g=m.length-f;if(l==0)m.set(n.subarray(o,o+=f),g);else if(l==1)ee(m,n[o++],g);else{var S=e.h;if(l==2){var _=en(n,o);h+=o-(o=_[0]),e.h=S=_[1]}else S||N(0);(u?an:Z)(n.subarray(o,o+=h),m.subarray(g),S)}var v=n[o++];if(v){v==255?v=(n[o++]|n[o++]<<8)+32512:v>127&&(v=v-128<<8|n[o++]);var R=n[o++];R&3&&N(0);for(var k=[nn,rn,tn],b=2;b>-1;--b){var w=R>>(b<<1)+2&3;if(w==1){var T=new O([0,0,n[o++]]);k[b]={s:T.subarray(2,3),n:T.subarray(0,1),t:new ge(T.buffer,0,1),b:0}}else w==2?(r=te(n,o,9-(b&1)),o=r[0],k[b]=r[1]):w==3&&(e.t||N(0),k[b]=e.t[b])}var P=e.t=k,E=P[0],$=P[1],C=P[2],M=n[a-1];M||N(0);var y=(a<<3)-8+B(M)-C.b,x=y>>3,L=0,re=(n[x]|n[x+1]<<8)>>(y&7)&(1<<C.b)-1;x=(y-=$.b)>>3;var oe=(n[x]|n[x+1]<<8)>>(y&7)&(1<<$.b)-1;x=(y-=E.b)>>3;var se=(n[x]|n[x+1]<<8)>>(y&7)&(1<<E.b)-1;for(++v;--v;){var Re=C.s[re],Je=C.n[re],Ae=E.s[se],We=E.n[se],Ke=$.s[oe],Qe=$.n[oe];x=(y-=Ke)>>3;var Ye=1<<Ke,U=Ye+((n[x]|n[x+1]<<8|n[x+2]<<16|n[x+3]<<24)>>>(y&7)&Ye-1);x=(y-=$e[Ae])>>3;var W=sn[Ae]+((n[x]|n[x+1]<<8|n[x+2]<<16)>>(y&7)&(1<<$e[Ae])-1);x=(y-=Ne[Re])>>3;var ie=on[Re]+((n[x]|n[x+1]<<8|n[x+2]<<16)>>(y&7)&(1<<Ne[Re])-1);if(x=(y-=Je)>>3,re=C.t[re]+((n[x]|n[x+1]<<8)>>(y&7)&(1<<Je)-1),x=(y-=We)>>3,se=E.t[se]+((n[x]|n[x+1]<<8)>>(y&7)&(1<<We)-1),x=(y-=Qe)>>3,oe=$.t[oe]+((n[x]|n[x+1]<<8)>>(y&7)&(1<<Qe)-1),U>3)e.o[2]=e.o[1],e.o[1]=e.o[0],e.o[0]=U-=3;else{var ae=U-(ie!=0);ae?(U=ae==3?e.o[0]-1:e.o[ae],ae>1&&(e.o[2]=e.o[1]),e.o[1]=e.o[0],e.o[0]=U):U=e.o[0]}for(var b=0;b<ie;++b)m[L+b]=m[g+b];L+=ie,g+=ie;var K=L-U;if(K<0){var Q=-K,Jt=e.e+K;Q>W&&(Q=W);for(var b=0;b<Q;++b)m[L+b]=e.w[Jt+b];L+=Q,W-=Q,K=0}for(var b=0;b<W;++b)m[L+b]=m[K+b];L+=W}if(L!=g)for(;g<m.length;)m[L++]=m[g++];else L=m.length;t?e.y+=L:m=Me(m,0,L)}else if(t){if(e.y+=f,g)for(var b=0;b<f;++b)m[b]=m[g+b]}else g&&(m=Me(m,g));return e.b=a,m}N(2)}},ln=function(n,e){if(n.length==1)return n[0];for(var t=new O(e),r=0,o=0;r<n.length;++r){var s=n[r];t.set(s,o),o+=s.length}return t};function we(n,e){for(var t=[],r=+!e,o=0,s=0;n.length;){var i=Zt(n,r||e);if(typeof i=="object"){for(r?(e=null,i.w.length==i.u&&(t.push(e=i.w),s+=i.u)):(t.push(e),i.e=0);!i.l;){var c=cn(n,i,e);c||N(5),e?i.e=i.y:(t.push(c),s+=c.length,Qt(i.w,0,c.length),i.w.set(c,i.w.length-c.length))}o=i.b+i.c*4}else o=i;n=n.subarray(o)}return ln(t,s)}function D(n){let e=[],t=0,r=()=>{let s=0,i=1;for(;;){let c=n[t++];if(s+=(c&127)*i,i*=128,!(c&128))return s}},o=s=>Array.from(s,i=>i.toString(16).padStart(2,"0")).join("");for(;t<n.length;){let s=t,i=r(),c=Math.floor(i/8),a=i&7,p;if(a===0){let l=t;r(),p=n.slice(l,t)}else if(a===2){let l=r();p=n.slice(t,t+l),t+=l}else if(a===5)p=n.slice(t,t+4),t+=4;else if(a===1)p=n.slice(t,t+8),t+=8;else throw new Error(`wire type ${a}`);e.push([c,a,o(n.slice(s,t)),p])}return e}var un=n=>Array.from(n,e=>e.toString(16).padStart(2,"0")).join(""),_t=n=>Uint8Array.from(n.match(/../g)??[],e=>parseInt(e,16));function ye(n){let e=n.trim().toLowerCase();if(e.startsWith("80"))return e;if(e.startsWith("81"))return"80"+un(we(_t(e.slice(2))));throw new Error(`grade body: unknown encoding 0x${e.slice(0,2)}`)}function wt(n){let e={};for(let t of n.matchAll(/<ListMgt::LmVersion DbId="[^"]+">([\s\S]*?)<\/ListMgt::LmVersion>/g)){let r=/<Name>([^<]*)<\/Name>/.exec(t[1])?.[1],o=/<Body>([0-9a-fA-F]+)<\/Body>/.exec(t[1])?.[1];r&&o&&(e[r]=ye(o))}return e}function yt(n){let e=new Map;for(let t of n.matchAll(/<ListMgt::LmVersion DbId="([^"]+)">([\s\S]*?)<\/ListMgt::LmVersion>/g)){let r=/<Body>([0-9a-fA-F]+)<\/Body>/.exec(t[2])?.[1];r&&e.set(t[1],ye(r))}return e}function bt(n){let e=X(n),t=p=>new TextDecoder().decode(e[p]),r=Object.keys(e).find(p=>p.startsWith("SeqContainer/")&&p.endsWith(".xml"));if(!r)throw new Error("grade bodies: no SeqContainer in the .drt");let o=new Map,s=new Map,i=Object.keys(e).filter(p=>p.startsWith("MediaPool/")&&p.endsWith(".xml"));for(let p of i)for(let l of t(p).matchAll(/<Sm2MpVideoClip DbId="([^"]+)">([\s\S]*?)<\/Sm2MpVideoClip>/g)){let d=/<pLmVerTable>([\s\S]*?)<\/pLmVerTable>/.exec(l[2]);d&&(o.set(l[1],wt(d[1])),s.set(l[1],yt(d[1])))}let c=new Map,a=0;for(let p of t(r).matchAll(/<Sm2TiTrack DbId="[^"]+">([\s\S]*?)<\/Sm2TiTrack>/g))if(/<Type>([^<]*)<\/Type>/.exec(p[1])?.[1]==="0"){a++;for(let l of p[1].matchAll(/<Sm2TiVideoClip DbId="[^"]+">([\s\S]*?)<\/Sm2TiVideoClip>/g)){let d=l[1],f=/<Start>(-?\d+)<\/Start>/.exec(d)?.[1],h=/<Name>([^<]*)<\/Name>/.exec(d)?.[1]??"";if(f===void 0)continue;let u=/<pLmVerTable>([\s\S]*?)<\/pLmVerTable>/.exec(d),m=/<MediaRef>([^<]+)<\/MediaRef>/.exec(d)?.[1],g=u&&/<pActive>([^<]+)<\/pActive>/.exec(u[1])?.[1],S=g?yt(u[1]).get(g)??(m?s.get(m)?.get(g):void 0):void 0;c.set(`${a}:${f}`,{name:h,local:u?wt(u[1]):{},remote:m&&o.get(m)||{},...S?{active:S}:{}})}}return c}function dr(n){let e=a=>D(a),t=a=>{let p=0,l=1;for(let d of a)if(p+=(d&127)*l,l*=128,!(d&128))break;return p},r=e(_t(n.slice(2))).find(a=>a[0]===3&&a[1]===2&&e(a[3]).some(p=>p[0]===8&&t(p[3])===84)),s=(r?e(r[3]).filter(a=>a[0]===9).flatMap(a=>e(a[3])):[]).find(a=>a[0]===1&&a[1]===2&&e(a[3]).some(p=>p[0]===1&&p[1]===0&&t(p[3])===10));return s?e(s[3]).filter(a=>a[0]===6&&a[1]===2).map(a=>{let p=e(a[3]),l=t(p.find(h=>h[0]===1&&h[1]===0)?.[3]??new Uint8Array([0]))/2,d=p.find(h=>h[0]===2&&h[1]===2)?.[3]??new Uint8Array,f={t:l,zoom:1,height:1,rotation:0,pan:0,tilt:0,flip_x:!1,flip_y:!1};for(let h of e(d)){if(h[0]===5&&h[1]===2){let R=e(h[3]);f.ease_in=t(R.find(k=>k[0]===1)?.[3]??new Uint8Array([1])),f.ease_out=t(R.find(k=>k[0]===2)?.[3]??new Uint8Array([1]));continue}if(h[0]!==3||h[1]!==2)continue;let u=e(h[3]),m=t(u.find(R=>R[0]===1)?.[3]??new Uint8Array),g=u.find(R=>R[0]===2)?.[3],S=g&&e(g).find(R=>R[0]===1&&R[1]===5),_=g&&e(g).find(R=>R[0]===2&&R[1]===0),v=S?new DataView(S[3].buffer,S[3].byteOffset,4).getFloat32(0,!0):_?t(_[3]):void 0;v!==void 0&&(m===271581186?f.height=v:m===271581187?f.zoom=v:m===271581188?f.rotation=v:m===271581189?f.pan=v:m===271581190?f.tilt=v:m===271581191?f.flip_y=!!v:m===271581192&&(f.flip_x=!!v))}return f}).sort((a,p)=>a.t-p.t):[]}var pn=n=>Array.from(n,e=>e.toString(16).padStart(2,"0")).join(""),V=n=>Uint8Array.from(n.match(/../g)??[],e=>parseInt(e,16)),St=n=>{let e=[];do e.push(n&127|(n>127?128:0)),n=Math.floor(n/128);while(n);return e};function vt(n){let e=V(n.trim());if(e.length<9)throw new Error("EffectFiltersBA: too short");if(e[8]===128)return e.slice(9);if(e[8]===129)return we(e.slice(9));throw new Error(`EffectFiltersBA: unknown encoding 0x${e[8].toString(16)}`)}function mn(n){let e=new Uint8Array(9);return new DataView(e.buffer).setUint32(0,2),new DataView(e.buffer).setUint32(4,n.length+1),e[8]=128,pn(new Uint8Array([...e,...n]))}var Ce=n=>{let e=D(n).find(t=>t[0]===1&&t[1]===0);return e?dn(e[3]):-1};function dn(n){let e=0,t=1;for(let r of n)if(e+=(r&127)*t,t*=128,!(r&128))break;return e}var Le=(n,e)=>new Uint8Array([...St(n<<3|2),...St(e.length),...e]);function fn(n,e){let t=new DataView(n.buffer,n.byteOffset,n.byteLength),r=-t.getInt32(0)/16;if(!Number.isInteger(r)||r<2||n.length!==4+r*16||n[10]!==12)return n;let o=Array.from({length:r},(a,p)=>({frame:t.getUint32(4+p*16,!0),value:t.getFloat64(4+p*16+8,!0)})),s=o.map(a=>e(a.frame));if(!s.slice(0,-1).some(Boolean))return n;let i=new Uint8Array(4+r*64),c=new DataView(i.buffer);return c.setInt32(0,-(r*64)),o.forEach((a,p)=>{let l=4+p*64;c.setUint32(l,a.frame,!0),i[l+6]=13,c.setFloat64(l+8,a.value,!0);let d=p>0?s[p-1]:void 0,f=p<r-1?s[p]:void 0;d&&c.setFloat64(l+16,-(d.in/10)*(a.frame-o[p-1].frame),!0),f&&c.setFloat64(l+32,f.out/10*(o[p+1].frame-a.frame),!0)}),i}function gn(n,e){let t=[];for(let r of D(n))if(r[0]===9&&r[1]===2&&r[3].length){let o=D(r[3]).map(s=>s[0]===10&&s[1]===2?[...Le(10,fn(s[3],e))]:[...V(s[2])]).flat();t.push(...Le(9,new Uint8Array(o)))}else t.push(...V(r[2]));return new Uint8Array(t)}function hn(n){let e=[];for(let t of D(n)){if(t[0]!==9||t[1]!==2||!t[3].length)continue;let r=D(t[3]).find(i=>i[0]===10&&i[1]===2)?.[3];if(!r||r.length<4)continue;let o=new DataView(r.buffer,r.byteOffset,r.byteLength),s=-o.getInt32(0)/16;Number.isInteger(s)&&s>e.length&&r.length===4+s*16&&Array.from({length:s},(i,c)=>r[4+c*16+6]).every(i=>i===12)&&(e=Array.from({length:s},(i,c)=>o.getUint32(4+c*16,!0)))}return e}function wn(n,e){let t=D(e).find(s=>s[0]===1&&s[1]===2&&Ce(s[3])===4);if(!t)throw new Error("the written clip carries no Transform group");let r=[],o=!1;for(let s of n?D(n):[]){if(s[0]===1&&s[1]===2&&Ce(s[3])===4){o||(r.push(...V(t[2])),o=!0);continue}r.push(...V(s[2]))}return o||r.push(...V(t[2])),new Uint8Array(r)}function xt(n){let e=[],t=0;for(let r of n.matchAll(/<Sm2TiTrack DbId="[^"]+">([\s\S]*?)<\/Sm2TiTrack>/g)){if(/<Type>([^<]*)<\/Type>/.exec(r[1])?.[1]!=="0")continue;t++;let o=r.index+r[0].indexOf(r[1]);for(let s of r[1].matchAll(/<Sm2TiVideoClip DbId="[^"]+">([\s\S]*?)<\/Sm2TiVideoClip>/g)){let i=/<Start>(-?\d+)<\/Start>/.exec(s[1])?.[1];i!==void 0&&e.push({track:t,start:Number(i),at:o+s.index,end:o+s.index+s[0].length,body:s[0]})}}return e}var kt=n=>Object.keys(n).find(e=>e.startsWith("SeqContainer/")&&e.endsWith(".xml"));function Rt(n,e,t,r){let o=X(n),s=X(e),i=kt(o),c=kt(s);if(!i||!c)throw new Error("no SeqContainer in the .drt");let a=new TextDecoder().decode(o[i]),p=xt(a),l=xt(new TextDecoder().decode(s[c])),d=[],f=[],h=[];for(let m of t){let g=`V${m.item.track}@${m.item.start}`,S=p.find(y=>y.track===m.item.track&&y.start===m.item.start+r),_=S?p.filter(y=>y.track===S.track).indexOf(S):-1,v=_>=0?l.filter(y=>y.track===m.item.track)[_]:void 0,R=v&&/<EffectFiltersBA>([0-9a-fA-F]+)<\/EffectFiltersBA>/.exec(v.body)?.[1];if(!S||!R){f.push(g);continue}let k=/<EffectFiltersBA>([0-9a-fA-F]*)<\/EffectFiltersBA>/.exec(S.body),b=D(vt(R)),w=b.find(y=>y[0]===1&&y[1]===2&&Ce(y[3])===4),T=w?hn(w[3]):[];if(T.length!==m.keys.length){f.push(`${g} (the engine wrote ${T.length} keys for ${m.keys.length})`);continue}let P=new Map(T.map((y,x)=>[y,m.keys[x].shape])),E=new Uint8Array(b.flatMap(y=>y===w?[...Le(1,gn(y[3],x=>P.get(x)))]:[...V(y[2])])),$=wn(k?.[1]?vt(k[1]):null,E),C=`<EffectFiltersBA>${mn($)}</EffectFiltersBA>`,M=k?S.body.replace(k[0],C):S.body.replace(/(<\/Sm2TiVideoClip>)$/,`${C}$1`);h.push({at:S.at,end:S.end,body:M}),d.push(g)}for(let m of h.sort((g,S)=>S.at-g.at))a=a.slice(0,m.at)+m.body+a.slice(m.end);let u={...o,[i]:new TextEncoder().encode(a)};return{drt:ct(u),keyed:d,missing:f}}function At(n,e,t){let r=n.source_range,o=n.timeline_range,s=r?.start.rate||t,i=r?.start.value??0,c=r?.duration&&o?.duration&&o.duration.value?r.duration.value/r.duration.rate/(o.duration.value/o.duration.rate)*s/t:s/t,a=[],p=0;for(let f of e){let h={value:i+f.t*c,rate:s},u=(m,g)=>a.push({id:`${n.id}-align-${p++}`,parameter_path:m,time:h,value:g,interp:"linear"});u("scale",f.transform.scale_x),e.some(m=>Math.abs(m.transform.scale_y-m.transform.scale_x)>.001)&&u("scale.y",f.transform.scale_y),u("position.x",f.transform.position_x),u("position.y",f.transform.position_y),u("rotation",f.transform.rotation)}let l=e[0].transform,d=(n.keyframes??[]).filter(f=>!/^(scale|position|rotation)/.test(String(f.parameter_path)));Object.assign(n,{scale:l.scale_x,position_x:l.position_x,position_y:l.position_y,rotation:l.rotation,keyframes:[...d,...a]}),Math.abs(l.scale_y-l.scale_x)>.001&&Object.assign(n,{scale_x:l.scale_x,scale_y:l.scale_y}),l.flip_h?n.flip_horizontal=!0:delete n.flip_horizontal,l.flip_v?n.flip_vertical=!0:delete n.flip_vertical}function Ot(n=H()){if(n==="win32"){let e=F("PROGRAMDATA")??"C:\\ProgramData",t=F("PROGRAMFILES")??"C:\\Program Files";return{api:`${e}\\Blackmagic Design\\DaVinci Resolve\\Support\\Developer\\Scripting`,lib:`${t}\\Blackmagic Design\\DaVinci Resolve\\fusionscript.dll`}}return n==="linux"?{api:"/opt/resolve/Developer/Scripting",lib:"/opt/resolve/libs/Fusion/fusionscript.so"}:{api:"/Library/Application Support/Blackmagic Design/DaVinci Resolve/Developer/Scripting",lib:"/Applications/DaVinci Resolve/DaVinci Resolve.app/Contents/Libraries/Fusion/fusionscript.so"}}async function yn(n){let e=F("RESOLVE_SCRIPT_LIB");if(e)return e;if(n==="darwin"){let r=(await de("ps",["-axo","comm="])).stdout.split(`
4
+ `).map(o=>o.trim()).find(o=>/\/Contents\/MacOS\/Resolve$/.test(o));if(r){let o=r.replace(/\/MacOS\/Resolve$/,"/Libraries/Fusion/fusionscript.so");if(await ce(o))return o}}return Ot(n).lib}async function Mt(){for(let n of["./bridge.py","./resolve-bridge.py"]){let e=Ze(new URL(n,import.meta.url));if(await le(e))return e}throw new Error("resolve: bridge.py is missing from this install")}var je=new Map;function _n(n){return je.has(n)||je.set(n,de(n,["-c","import sys; print(sys.base_prefix)"],{timeoutMs:2e4}).then(e=>e.stdout.trim().split(`
5
+ `).pop()||void 0).catch(()=>{})),je.get(n)}var bn=["PYTHON3HOME","FUSION_PYTHON3HOME","FUSION_PYTHON3_HOME","FUSION_PYTHON36_HOME"];async function Nt(n,e){let{api:t}=Ot(n),r=n==="win32"?await _n(e):void 0;return{RESOLVE_SCRIPT_API:F("RESOLVE_SCRIPT_API")??t,RESOLVE_SCRIPT_LIB:await yn(n),PYTHONPATH:I(F("RESOLVE_SCRIPT_API")??t,"Modules"),...r?Object.fromEntries(bn.map(o=>[o,r])):{}}}var G=null;async function Sn(n,e,t){if(G?.busy)return null;if(!G){let s=H(),i=Te(),c="",a={io:null,busy:!1,waiting:null,last:""};if(a.io=ot(i,[await Mt(),"serve"],p=>{c+=new TextDecoder().decode(p);let l;for(;(l=c.indexOf(`
6
+ `))>=0;){let d=c.slice(0,l);c=c.slice(l+1);let f=a.waiting;a.waiting=null,f?.(d)}},p=>{a.last=p.trim().split(`
7
+ `).pop()||a.last},{env:await Nt(s,i)}),a.io.exited.then(()=>{G===a&&(G=null),a.waiting?.("")}),G)return a.io.close(),null;G=a}let r=G;r.busy=!0,r.io.hold(!0);let o;try{let s=new Promise(a=>{r.waiting=a}),c=await r.io.write(new TextEncoder().encode(JSON.stringify({action:n,args:e})+`
8
+ `)).then(()=>!0,()=>!1)?await Promise.race([s,new Promise(a=>{o=setTimeout(()=>a(null),t)})]):"";if(c===null)return r.io.close(),{ok:!1,why:"bridge",detail:`no answer from Resolve within ${Math.round(t/1e3)} s`};try{return JSON.parse(c)}catch{return{ok:!1,why:"bridge",detail:r.last||"the Resolve bridge stopped"}}}finally{clearTimeout(o),r.waiting=null,r.busy=!1,r.io.hold(!1)}}var vn=async(n,e,t)=>(F("CONFORM_RESOLVE_ONESHOT")!=="1"?await Sn(n,e,t).catch(()=>null):null)??xn(n,e,t),xn=async(n,e,t)=>{let r=H(),o=Te(),s=await q("ct-bridge-"),i=I(s,"args.json"),c;try{await pe(i,JSON.stringify(e)),c=await de(o,[await Mt(),n,`@${i}`],{env:await Nt(r,o),timeoutMs:t})}finally{await me(s).catch(()=>{})}let a=c.stdout.trim().split(`
9
+ `).pop()??"";try{return JSON.parse(a)}catch{return{ok:!1,why:"bridge",detail:c.code==="ENOENT"||/Microsoft Store/.test(c.stderr)?`${o} is not installed (Resolve's scripting needs Python 3: python.org)`:c.stderr.trim().split(`
10
+ `).pop()||(typeof c.code=="string"?`the Resolve bridge could not start: ${c.code}`:`no answer from Resolve within ${Math.round(t/1e3)} s`)}}},kn=1500,Tt=Promise.resolve(),Pt=0;function Rn(n){let e=Tt.catch(()=>{}).then(async()=>{let t=Pt+kn-Date.now();t>0&&await new Promise(r=>setTimeout(r,t));try{return await n()}finally{Pt=Date.now()}});return Tt=e,e}var z=class extends Error{constructor(t,r){super(r);this.why=t}},An={module:"Install DaVinci Resolve (its scripting module ships with it).",no_connection:"Start Resolve and set Preferences > System > General > External scripting using: Local (Resolve Studio).",no_project:"Open a project in Resolve."},_e=class{constructor(e=vn){this.runner=e;this.host="resolve";this.restore=new Map;this.startNotes=new Map}async call(e,t={},r=6e4){let o=await this.runner(e,t,r);if(o.ok)return o;throw o.why==="resolve_error"&&/NoneType' object is not callable/.test(String(o.detail))&&!(await this.runner("version",{},1e4)).ok?new z("host_quit",`resolve: Resolve stopped responding during ${e} (it may have quit; see its log, ResolveDebug.txt). Restart Resolve and try again.`):new z(o.why??"unknown",`resolve: ${o.detail||o.why}`)}async support(){let e=await this.runner("version",{},15e3),t=e.ok?e.product==="DaVinci Resolve Studio"?{ok:!0}:{ok:!1,reason:`${e.product} has no external scripting (Resolve Studio has)`}:{ok:!1,reason:e.detail??String(e.why),setup:An[e.why??""]};return{export:t,open:t,render:t,markers:t}}async current(){return await this.call("current")}async project(e){return await this.call("project",e,e.export_dir||e.grades?9e5:12e4)}async clipLut(e){return await this.call("clip_lut",e,6e4)}async items(e){return e.selected?await Rn(()=>this.call("items",e,15e3)):await this.call("items",e,e.follow?15e3:12e4)}async apply(e){let t=e.ops.filter(o=>o.op==="edit_keys");if(t.length){let o=e.ops.filter(a=>a.op!=="edit_keys"),s=o.length?await this.apply({...e,ops:o}):{project:"",timeline:e.timeline??"",results:[],undo:[],applied:0,failed:0},i=await this.alignedCopy(e,t),c=i.results.filter(a=>a.ok).length;return{...s,project:s.project||i.project,timeline:s.timeline||i.timeline,results:[...s.results,...i.results],applied:s.applied+c,failed:s.failed+i.results.length-c}}let r=e.ops.filter(o=>(o.op==="grade_sizing"&&(o.target==="input"||o.target==="node")&&!o.reset||o.op==="node_structure")&&o.item&&"track"in o.item);for(let o of r){let s=o.node_structure??o.structure_path;if(!s)continue;let i=/<Body>([0-9a-fA-F]+)<\/Body>/.exec(new TextDecoder().decode(await ue(s)))?.[1];if(!i)throw new z("usage",`${s}: not a Resolve grade still (.drx with a <Body>)`);o.structure=ye(i),o.structure_name=s}if(r.length){let{grades:o,t0:s}=await this.grades(e.timeline,e.into?{into:e.into,scratch_project:e.scratch_project}:{}),i=c=>{let a=c.item;return o.get(`${a.track}:${a.start+s}`)};for(let c of r){let a=i(c);a&&(c.bodies={local:a.local,remote:a.remote})}}return await this.call("apply",e,6e4+e.ops.length*200)}async alignedCopy(e,t){let r=e.into?{into:e.into,scratch_project:e.scratch_project}:{},o=await q("ct-aligned-"),s=i=>({project:"",timeline:e.timeline??"",results:t.map(()=>({op:"edit_keys",ok:!1,refused:["aligned copy"],detail:`refused: ${i}; nothing changed`}))});try{let i=I(o,"export.drt"),c=await this.call("export",{timeline:e.timeline,out_path:i,...r}),a=String(c.timeline),p=Number(c.start_frame??0),{session:l}=await pt(i,"drt"),d=l.timelines[0],f=(d.fps_num??24)/(d.fps_den??1),h=d.tracks.filter(w=>String(w.kind).toLowerCase()==="video"),u=w=>Math.round(w.value*f/w.rate),m=[],g=[];for(let w of t){let T=h[w.item.track-1]?.items.find(P=>{let E=P.timeline_range?.start;return E&&[w.item.start,w.item.start+p].includes(u(E))});T?(At(T,w.keys,f),m.push(w)):g.push(`V${w.item.track}@${w.item.start}`)}let S=await lt("resolve-drt",l),_=typeof S.body=="string"?new TextEncoder().encode(S.body):S.body,v=Rt(await ue(i),_,m,p);if(!v.keyed.length)return s(`no clip could be keyed (${[...g,...v.missing].join(", ")})`);let R=I(o,`${a.replace(/[^\w.-]+/g,"_").slice(0,100)}_ALIGNED.drt`);await tt(R,v.drt);let k=await this.call("open",{path:R,name:`${a} ALIGNED`,link_existing:!0,same_as:a,...r}),b=new Map([...g.map(w=>[w,"not found in the timeline's export"]),...v.missing.map(w=>[w.split(" ")[0],w])]);return{project:String(k.project??""),timeline:String(k.timeline??""),results:t.map(w=>{let T=`V${w.item.track}@${w.item.start}`;return b.has(T)?{op:"edit_keys",ok:!1,refused:["not keyed"],detail:`refused: ${b.get(T)}; nothing changed`}:{op:"edit_keys",ok:!0,detail:`${w.keys.length} Edit-page keyframes on "${k.timeline}" (a copy of "${a}" with every grade and setting; "${a}" itself unchanged)`}})}}catch(i){return s(i instanceof Error?i.message:String(i))}finally{await me(o).catch(()=>{})}}async grades(e,t){let r=await q("ct-grades-");try{let o=I(r,"grades.drt"),s=await this.call("export",{timeline:e,out_path:o,...t});return{grades:await ue(o).then(bt).catch(()=>new Map),t0:Number(s.start_frame??0)}}finally{await me(r).catch(()=>{})}}async presets(e){return await this.call("presets",e,12e4)}async presetAuthor(e){return await this.call("preset_author",e,6e4)}async export(e){if(!e.out_path)throw new z("usage","resolve: export needs out_path");let t=await this.call("export",{timeline:e.timeline,out_path:e.out_path,...e.clip_id?{clip_id:e.clip_id}:{}});return{path:String(t.path),format:"drt",project:String(t.project),timeline:String(t.timeline)}}async open(e){let t=await this.call("open",{path:e.path,into:e.into??"current",name:e.name,media_dir:e.media_dirs?.[0],stay:e.stay??!1,folder:e.folder,create_folder:e.create_folder??!1,link_existing:e.link_existing??!1,...e.settings_from?{settings_from:e.settings_from}:{}},3e5),r=[...t.notes??[]];return(e.media_dirs?.length??0)>1&&r.push(`Resolve searches one media folder per import; used ${e.media_dirs[0]}`),{project:String(t.project),timeline:String(t.timeline),notes:r,restored:!!t.restored,...t.folder?{folder:String(t.folder)}:{},...t.settings?{settings:String(t.settings)}:{}}}async renderStart(e){let t=await this.call("render_start",{...e}),r=String(t.job_id);if(t.queued)return{job_id:r,state:"queued",percent:0,notes:["left in Resolve's render queue: start it on the Deliver page"]};this.restore.set(r,t.restore);let o=t.rejected_settings??[];return o.length&&this.startNotes.set(r,[`Resolve refused render setting(s) ${o.join(", ")} for this format; the rest were applied`]),{job_id:r,state:"queued",percent:0}}async renderStatus(e){let t=await this.call("render_status",{job_id:e},15e3),r={job_id:e,state:t.state,percent:Number(t.percent??0)};if(t.error&&(r.error=String(t.error)),r.state==="complete"||r.state==="failed"){let o=await this.call("render_finish",{job_id:e,restore:this.restore.get(e)});this.restore.delete(e),o.output&&(r.outputs=[String(o.output)]);let s=[...this.startNotes.get(e)??[],...o.tracks?[Et(o)]:[]];this.startNotes.delete(e),s.length&&(r.notes=s)}return r}async renderCancel(e){let t=await this.call("render_cancel",{job_id:e,restore:this.restore.get(e)});return this.restore.delete(e),{job_id:e,state:"cancelled",percent:0,...t.output?{outputs:[String(t.output)]}:{},...t.tracks?{notes:[Et(t)]}:{}}}},Et=n=>{let e=n.tracks.map(t=>`V${t}`).join(", ");return n.tracks_restored?`video track(s) ${e} switched back on`:`could NOT switch video track(s) ${e} back on: re-enable them on the Edit page`};async function kr(n,e){let t=[];for await(let r of rt(n))r.isFile&&r.name.startsWith(e)&&t.push(I(n,r.name));return t.sort()}var Tn="ws://localhost:1985",$t="localhost",Ct="conform_tools",Lt="conform.tools ",jt="Video_Full",Pn=n=>!!n&&typeof n=="object"&&"_handle"in n&&"_id"in n,J=class extends Error{constructor(t,r){super(r);this.code=t}},De=class n{constructor(e){this.ws=e;this.next=1;this.waiting=new Map;e.onMessage(t=>{let r;try{r=JSON.parse(t)}catch{return}let o=typeof r.id=="number"?this.waiting.get(r.id):void 0;if(!o)return;if(this.waiting.delete(r.id),r.error===void 0||r.error===null)return o.ok(r.result??null);let s=r.error;o.no(typeof s=="string"?new J(r.code??-1,s):new J(s.code??r.code??-1,s.message??JSON.stringify(s)))}),e.onClose(()=>{for(let t of this.waiting.values())t.no(new J("closed","Baselight closed the FLAPI connection"));this.waiting.clear()})}static async connect(e,t=3e3){let r=new n(await mt(e,{maxBytes:67108864,timeoutMs:t})),o=await En();return o&&await r.call("authenticate",{username:F("USER")??F("USERNAME")??"conform",token:o},null,t).catch(()=>null),r}call(e,t={},r=null,o=12e4){let s=this.next++;return new Promise((i,c)=>{let a=setTimeout(()=>{this.waiting.delete(s),c(new J("timeout",`${e}: no answer from Baselight within ${Math.round(o/1e3)} s`))},o);this.waiting.set(s,{ok:p=>{clearTimeout(a),i(p)},no:p=>{clearTimeout(a),c(p)}}),this.ws.send(JSON.stringify({jsonrpc:"2.0",method:e,target:r?r._id:null,params:t,id:s}))})}async forget(...e){for(let t of e)Pn(t)&&await this.call("forget",{},t).catch(()=>null)}close(){this.ws.close()}};async function En(){let n=F("FLAPI_TOKEN");if(n)return n.trim();let e=H()==="darwin"?I(Pe(),"Library","Preferences","FilmLight","flapi-token"):I(Pe(),".filmlight","flapi-token");try{return(await et(e)).trim()||null}catch{return null}}var Ft=(...n)=>Object.fromEntries(n.map(e=>[e,1])),On={[-30]:30,[-31]:30,[-32]:30,[-34]:25,[-35]:24};function be(n){if(!n||typeof n!="object")return null;let e=typeof n.fps=="string"?{TC_30DF:-30,TC_60HDF:-31}[n.fps]??Number(n.fps):n.fps,t=e>0?e:On[e]??30,r=((n.h*60+n.m)*60+n.s)*t+n.f;if(e!==-30&&e!==-31)return r;let o=n.h*60+n.m;return r-2*(o-Math.floor(o/10))}function Mn(n,e,t){let r=Math.round(e),o=n;if(t&&r===30){let p=Math.floor(o/17982),l=o%17982;o+=18*p+(l>2?2*Math.floor((l-2)/1798):0)}let s=o%r,i=Math.floor(o/r)%60,c=Math.floor(o/r/60)%60;return{_type:"timecode",h:Math.floor(o/r/3600)%24,m:c,s:i,f:s,phase:0,fps:t&&r===30?-30:r,wrap:24}}function It(n){let e=Math.round(n);return Math.abs(n-e)<.005?e:Math.abs(n-e*1e3/1001)<.01?e*1e3/1001:n}var j=class extends Error{constructor(t,r){super(`baselight: ${r}`);this.why=t}},Nn={darwin:"/Applications/Baselight",linux:"/usr/fl/baselight"},Se=class{constructor(e){this.url=e;this.host="baselight";this.jobs=new Map}async conn(e=3e3){let t=this.url??F("CONFORM_BASELIGHT_URL")??Tn;try{return await De.connect(t,e)}catch(r){let o=await ce(Nn[H()]??"/nonexistent");throw new j(o?"not_running":"not_installed",o?`Baselight is not answering FLAPI at ${t} (${r.message})`:"Baselight is not installed on this machine")}}async with(e){let t=await this.conn();try{return await e(t)}catch(r){throw r instanceof j?r:new j("flapi",r.message)}finally{t.close()}}async support(){let e;try{let t=await this.with(r=>r.call("Application.get_application_info"));e=/baselight|daylight/i.test(t.Product??"")?{ok:!0}:{ok:!1,reason:`the FLAPI server is ${t.Product??"unknown"}, not the Baselight app (port 1984 is the headless flapid)`,setup:"Point CONFORM_BASELIGHT_URL at the running Baselight (ws://localhost:1985)."}}catch(t){let r=t instanceof j?t.why:"flapi";e={ok:!1,reason:t.message.replace(/^baselight: /,""),setup:r==="not_installed"?"Install FilmLight Baselight (FLAPI ships with it; nothing else to install).":"Start Baselight. Its API server listens on port 1985 by default (Preferences > Advanced > API Server)."}}return{export:e,open:e,render:e,markers:{ok:!1,reason:"not wired for Baselight yet (FLAPI has marks: Scene.add_mark)"}}}async scenePath(e,t,r){if(t?.includes(":")){let i=await e.call("Scene.parse_path",{str:t});return{host:i.Host,job:i.Job,scene:i.Scene}}let o=await this.current(e),s=r??o?.job;if(t&&s)return{host:o?.host??$t,job:s,scene:t};if(!o)throw new j("no_scene",t?`no job to find scene "${t}" in: pass project (the job) or "host:job:scene"`:'no scene is open in Baselight: open one, or name it ("host:job:scene")');return o}async current(e){let t=await e.call("Application.get").catch(()=>null);if(!t)return null;try{let r=await e.call("Application.get_current_scene",{},t);if(!r)return null;try{let o=await e.call("Scene.get_scene_pathname",{},r),[s,i,...c]=o.split(":");return c.length?{host:s,job:i,scene:c.join(":")}:null}finally{await e.forget(r)}}finally{await e.forget(t)}}async export(e){if(!e.out_path)throw new j("usage","export needs out_path");return await this.with(async t=>{let r=await this.scenePath(t,e.timeline),o=await t.call("Scene.open_scene",{scenepath:{Host:r.host,Job:r.job,Scene:r.scene},flags:Ft("OPENFLAG_READ_ONLY")});try{let s=await Ln(t,o,r.scene);await Y(fe(e.out_path)),await pe(e.out_path,JSON.stringify(s,null,1))}finally{await t.call("Scene.close_scene",{},o).catch(()=>null),await t.forget(o)}return{path:e.out_path,format:"otio",project:r.job,timeline:r.scene}})}async open(e){let{readTimeline:t}=await import("./timeline-Z3KD2CJX.js"),{session:r}=await t(e.path),o=r.timelines.find(l=>l.kind!=="compound")??r.timelines[0];if(!o)throw new j("usage",`no timeline in ${e.path}`);let s=new Map((r.media_references??[]).map(l=>[l.id,l])),i=o.fps_num/o.fps_den,c=o.tracks.filter(l=>l.kind==="Video").sort((l,d)=>l.track_index-d.track_index),a=[];c.length>1&&a.push(`placed V1 only: Baselight builds layers above a shot, which FLAPI cannot place in time; ${c.slice(1).reduce((l,d)=>l+d.items.filter(f=>f.kind==="clip").length,0)} clip(s) on V2+ not placed`);let p=(c[0]?.items??[]).filter(l=>l.kind==="clip"||l.kind==="gap").sort((l,d)=>l.timeline_range.start.value-d.timeline_range.start.value);return await this.with(async l=>{let d=e.into==="scratch"?null:await this.current(l);e.into!=="scratch"&&!d&&a.push(`no scene open in Baselight, so it went into our job ${Ct}`);let f=d?.job??Ct,h=d?.host??$t;await l.call("JobManager.job_exists",{host:h,jobname:f})||await l.call("JobManager.create_job",{host:h,jobname:f});let u=(e.name??o.name??"conform.tools").replace(/[:/\\]+/g,"_"),m=u;for(let w=2;await l.call("JobManager.scene_exists",{host:h,jobname:f,scenename:m});w++)m=`${u} ${w}`;let g=await l.call("FormatSet.factory_formats"),S=o.resolution_w&&o.resolution_h?await l.call("FormatSet.get_basic_format_name",{width:o.resolution_w,height:o.resolution_h},g):null;await l.forget(g);let _=await l.call("Scene.new_scene",{scenepath:{Host:h,Job:f,Scene:m},options:{format:S,colourspace:jt,frame_rate:i}},null,3e5),v=0,R=0,k=0,b=0;try{await l.call("Scene.start_delta",{name:"conform.tools open"},_);try{let w=0;for(let P of p){let E=P.timeline_range.start.value,$=P.timeline_range.duration.value;if(E>w&&(await Fe(l,_,E-w),k++),w=Math.max(w,E+$),P.kind==="gap"){await Fe(l,_,$),k++;continue}let M=(P.media_reference_id?s.get(P.media_reference_id):void 0)?.target_url?.replace(/^file:\/\//,""),y=P.source_range,x=M&&y?await Cn(l,M,Math.round(y.start.value),Math.round(y.start.value)+$-1):null;if(!x){await Fe(l,_,$),R++;continue}y&&Math.abs(y.duration.value-$)>.5&&b++;let L=await l.call("Scene.insert_sequence",{sequence:x,where:"INSERT_END",relativeTo:null,colourSpace:null,format:null,frameRate:i},_);await l.forget(x,L),v++}let T=await l.call("Scene.get_scene_settings",{},_);await l.call("SceneSettings.set",{values:{StartTimecode:Mn(o.start_frame??0,i,!!o.is_drop_frame)}},T),await l.forget(T),await l.call("Scene.end_delta",{},_)}catch(w){throw await l.call("Scene.cancel_delta",{},_).catch(()=>null),w}await l.call("Scene.save_scene",{},_,3e5)}catch(w){throw await l.call("Scene.close_scene",{},_).catch(()=>null),await l.forget(_),await l.call("JobManager.delete_scene",{host:h,jobname:f,scenename:m}).catch(()=>null),w}return await l.call("Scene.close_scene",{},_),await l.forget(_),a.unshift(`new scene ${h}:${f}:${m}: ${v} shot(s)${k?`, ${k} gap(s) as black`:""}`),R&&a.push(`${R} clip(s) had no media on disk at their path: placed as black of the same length (relink in Baselight's Conform view)`),b&&a.push(`${b} retimed clip(s) placed at normal speed: FLAPI has no retime setter`),m!==u&&a.push(`"${u}" was taken in ${f}: named "${m}"`),e.media_dirs?.length&&a.push("media_dirs not used: Baselight places each clip from its own path"),e.stay&&a.push("stay: FLAPI cannot switch the scene the app shows; open it from the Scenes browser"),{project:f,timeline:m,notes:a,restored:!0}})}async renderStart(e){if(e.disable_tracks?.length)throw new j("usage","disable_tracks: a Baselight render takes every layer or one (RenderTrack); leave the tracks out in the scene");if(e.audio_tracks?.length)throw new j("usage","audio_tracks is a DaVinci Resolve option");return await this.with(async t=>{let r=await this.scenePath(t,e.timeline,e.project),o=await t.call("Scene.open_scene",{scenepath:{Host:r.host,Job:r.job,Scene:r.scene},flags:Ft("OPENFLAG_READ_ONLY")}),s=null,i=null;try{s=await t.call("RenderSetup.create_from_scene",{scene:o});let c=await t.call("RenderSetup.get_num_deliverables",{},s),a=0;if(e.preset){let u=await t.call("RenderSetup.get_deliverable_names",{},s);if(a=u.indexOf(e.preset),a<0)throw new j("usage",`no deliverable "${e.preset}" in ${r.scene} (it has: ${u.join(", ")||"none"})`)}let p=await t.call("RenderSetup.get_deliverable",{index:a},s),l=e.name??r.scene.replace(/[^\w.-]+/g,"_");Object.assign(p,{Disabled:0,Container:"",OutputDirectory:e.target_dir,FileNamePrefix:l}),e.preset||Object.assign(p,{Name:"conform.tools",IsMovie:1,FileType:"lqtmov",MovieCodec:"apch",ImageOptions:{},FileNameExtension:".mov",RenderColourSpace:jt,HandleEmptyFrames:"GMREB_BLACK",HandleIncompleteStacks:"GMREB_BLACK",HandleError:"BLACK",EmbedTimecode:1}),e.audio||(p.AudioCodec=""),await Y(e.target_dir),await t.call("RenderSetup.set_deliverable",{index:a,deliverable:p},s);for(let u=0;u<c;u++)u!==a&&await t.call("RenderSetup.set_deliverable_enabled",{index:u,enabled:0},s);if(e.range){let u=await t.call("Scene.get_scene_settings",{},o),m=be(await t.call("SceneSettings.get_single",{key:"StartTimecode"},u))??0;await t.forget(u);let g=e.range.in>=m?m:0;await t.call("RenderSetup.set_frames",{frames:[{Start:e.range.in-g,End:e.range.out-g}]},s)}else await t.call("RenderSetup.select_all",{},s);let d=await t.call("RenderSetup.get_output_filename_for_deliverable",{index:a},s);i=await t.call("QueueManager.create_local");let f=await t.call("RenderSetup.submit_to_queue",{queue:i,opname:`${Lt}${l}`},s),h=String(f.ID);return this.jobs.set(h,{op:f.ID,out:d,notes:f.Warning?[`Baselight: ${f.Warning}`]:[]}),{job_id:h,state:"queued",percent:0}}finally{await t.forget(s,i),await t.call("Scene.close_scene",{},o).catch(()=>null),await t.forget(o)}})}async ours(e,t,r){let o=Number(r),s=await e.call("QueueManager.get_operation",{id:o},t).catch(()=>null),i=String(s?.Description??s?.Name??"");if(!this.jobs.has(r)&&!i.startsWith(Lt))throw new j("not_ours",`queue operation ${r} is not a conform.tools render: left alone`);return o}async renderStatus(e){return await this.with(async t=>{let r=await t.call("QueueManager.create_local");try{let o=await this.ours(t,r,e),s=await t.call("QueueManager.get_operation_status",{id:o},r),i=$n(s.Status),c=Number(s.Progress??0),a={job_id:e,state:i,percent:i==="complete"?100:Math.round(c<=1?c*100:c)};if(i==="failed"||i==="complete"&&s.Errors){let l=(await t.call("QueueManager.get_operation_log",{id:o},r).catch(()=>[])).filter(d=>/fail|error|warn/i.test(d.Type)).slice(-6).map(d=>`${d.Message}${d.Detail?`: ${d.Detail}`:""}`);a.error=[s.ProgressText,...l].filter(Boolean).join("; ")||"Baselight reported a failed render",i==="complete"&&(a.state="failed")}if(a.state==="complete"||a.state==="failed"||a.state==="cancelled"){let p=this.jobs.get(e);a.state==="complete"&&p&&(a.outputs=[p.out]),p?.notes.length&&(a.notes=p.notes),await t.call("QueueManager.delete_operation",{id:o},r).catch(()=>null),this.jobs.delete(e)}return a}finally{await t.forget(r)}})}async renderCancel(e){return await this.with(async t=>{let r=await t.call("QueueManager.create_local");try{let o=await this.ours(t,r,e);return await t.call("QueueManager.delete_operation",{id:o},r),this.jobs.delete(e),{job_id:e,state:"cancelled",percent:0}}finally{await t.forget(r)}})}};function $n(n){let e=String(n).replace(/^OPSTATUS_/i,"").toLowerCase();return e==="done"?"complete":e==="active"?"rendering":e==="stopped"?"cancelled":e==="failed"||e==="crashed"||e==="toonew"?"failed":"queued"}async function Fe(n,e,t){let r=await n.call("Scene.insert_blank",{red:0,green:0,blue:0,duration:t,where:"INSERT_END",relativeTo:null,colourSpace:null},e);await n.forget(r)}async function Cn(n,e,t,r){let o=await n.call("SequenceDescriptor.get_for_template",{template:e,start:null,end:null}).catch(()=>[]);if(!o?.length)return null;let s=await n.call("SequenceDescriptor.get_start_handle",{},o[0]);await n.forget(...o);let i=await n.call("SequenceDescriptor.get_for_template",{template:e,start:s+t,end:s+r});return i?.length?(await n.forget(...i.slice(1)),i[0]):null}var Ue=(n,e)=>({OTIO_SCHEMA:"RationalTime.1",rate:e,value:n}),Ie=(n,e,t)=>({OTIO_SCHEMA:"TimeRange.1",start_time:Ue(n,t),duration:Ue(e,t)});async function Ln(n,e,t){let r=It(await n.call("Scene.get_working_frame_rate",{},e)),o=await n.call("Scene.get_scene_settings",{},e),s=be(await n.call("SceneSettings.get_single",{key:"StartTimecode"},o))??0;await n.forget(o);let i=await n.call("Scene.get_num_shots",{},e),c=i?await n.call("Scene.get_shot_ids",{firstIndex:0,lastIndex:i-1},e):[],a=[];for(let d of c){let f=Math.round(d.StartFrame),h=Math.round(d.EndFrame),u=await n.call("Scene.get_shot",{shot_id:d.ShotId},e);try{let m=await n.call("Shot.get_sequence_descriptor",{},u).catch(()=>null);if(!m){a.push({start:f,end:h,name:`shot ${d.ShotId}`});continue}try{let g=It(await n.call("Shot.get_frame_rate",{},u))||r,S=be(await n.call("Shot.get_src_start_timecode",{},u)),_=await n.call("Shot.get_src_start_frame",{},u),v=await n.call("Shot.get_src_end_frame",{},u),k=await n.call("SequenceDescriptor.is_movie",{},m)?Xe(await n.call("SequenceDescriptor.get_path",{},m),await n.call("SequenceDescriptor.get_name",{},m)):await n.call("SequenceDescriptor.get_full_filename_with_d",{},m),b=await n.call("SequenceDescriptor.get_name",{},m),w=await n.call("SequenceDescriptor.get_tape",{index:0},m).catch(()=>""),T=await n.call("SequenceDescriptor.get_start_frame",{},m),P=await n.call("SequenceDescriptor.get_start_handle",{},m),E=await n.call("SequenceDescriptor.get_end_handle",{},m),C=(be(await n.call("SequenceDescriptor.get_start_timecode",{index:0},m))??0)-(T-P),M=Math.round(v-_),y=h-f,x={OTIO_SCHEMA:"Clip.2",name:b,enabled:!0,source_range:Ie(S??C+(_-P),y,g),media_references:{DEFAULT_MEDIA:{OTIO_SCHEMA:"ExternalReference.1",target_url:k,available_range:Ie(C,E-P+1,g),available_image_bounds:null,name:b,metadata:{}}},active_media_reference_key:"DEFAULT_MEDIA",effects:M&&M!==y?[{OTIO_SCHEMA:"LinearTimeWarp.1",name:"",effect_name:"LinearTimeWarp",time_scalar:M/y,metadata:{}}]:[],markers:[],metadata:w?{baselight:{tape:w}}:{}};a.push({start:f,end:h,name:b,clip:x})}finally{await n.forget(m)}}finally{await n.forget(u)}}let p=[];for(let d of[...a].sort((f,h)=>f.start-h.start)){if(!d.clip)continue;let f=p.find(h=>h[h.length-1].end<=d.start);f?f.push(d):p.push([d])}let l=p.map((d,f)=>{let h=[],u=0;for(let m of d)m.start>u&&h.push({OTIO_SCHEMA:"Gap.1",name:"",enabled:!0,source_range:Ie(0,m.start-u,r),effects:[],markers:[],metadata:{}}),h.push(m.clip),u=m.end;return{OTIO_SCHEMA:"Track.1",name:`V${f+1}`,kind:"Video",enabled:!0,children:h,source_range:null,effects:[],markers:[],metadata:{}}});return{OTIO_SCHEMA:"Timeline.1",name:t,metadata:{baselight:{shots:c.length}},global_start_time:Ue(s,r),tracks:{OTIO_SCHEMA:"Stack.1",name:"tracks",enabled:!0,children:l,source_range:null,effects:[],markers:[],metadata:{}}}}var jn="127.0.0.1:31416",Fn="/ptsl.PTSL/SendGrpcRequest",In="CONFORM.TOOLS",Dn="CONFORM.TOOLS Desktop",He=[2025,6,0],ne=[2025,6],qe=1e4,Dt=5e3,Un="ConformTools",Hn="Start Pro Tools 2025.6 or newer with a session open (PTSL, its scripting door, listens on 127.0.0.1:31416).",Be={GetTrackList:3,HostReadyCheck:13,ExportSessionInfoAsText:30,GetSessionSampleRate:35,GetSessionTimeCodeRate:38,GetSessionFeetFramesRate:39,GetSessionName:42,GetSessionPath:43,GetSessionStartTime:44,GetSessionLength:45,GetPTSLVersion:55,GetTransportState:59,ClearMemoryLocation:61,EditMemoryLocation:68,GetMemoryLocations:69,RegisterConnection:70,CreateMemoryLocation:71,SetTimelineSelection:81,GetTimelineSelection:82,GetSessionIDs:97,GetMainCounterFormat:102},Bn=[3,6],Vn=[4,7],Ut=106,Gn=new TextEncoder,qn=new TextDecoder;function ve(n,e){for(;n>127;)e.push(n&127|128),n=Math.floor(n/128);e.push(n)}function Ht(n){let e=[];for(let[t,r]of n){if(typeof r=="number"){r&&(ve(t<<3,e),ve(r,e));continue}let o=typeof r=="string"?Gn.encode(r):r;if(o.length){ve(t<<3|2,e),ve(o.length,e);for(let s of o)e.push(s)}}return new Uint8Array(e)}function Bt(n){let e=new Map,t=0,r=()=>{let o=0,s=1,i;do i=n[t++],o+=(i&127)*s,s*=128;while(i&128&&t<n.length);return o};for(;t<n.length;){let o=r(),s=Math.floor(o/8),i=o&7;if(i===0)e.set(s,r());else if(i===2){let c=r();e.set(s,n.subarray(t,t+c)),t+=c}else if(i===1)t+=8;else if(i===5)t+=4;else throw new A("bad_answer",`Pro Tools sent a reply that is not protobuf (wire type ${i})`)}return e}var Vt=n=>n instanceof Uint8Array?qn.decode(n):"",zn=n=>typeof n=="number"?n:0;function Jn(n,e,t){let r=Ht([[2,n],[3,He[0]],[4,e],[5,He[1]],[6,He[2]]]);return Ht([[1,r],[2,t]])}function Wn(n){let e=Bt(n),t=e.get(1);return{status:t instanceof Uint8Array?zn(Bt(t).get(3)):0,body:Vt(e.get(2)),error:Vt(e.get(3))}}var A=class extends Error{constructor(t,r,o){super(r);this.code=t;this.errors=o}};function Kn(n){let e=null;try{e=JSON.parse(n)}catch{}let t=Array.isArray(e)?e:e&&typeof e=="object"?Array.isArray(e.errors)?e.errors:[e]:[],r=t.find(a=>!a.is_warning)??t[0],o=String(r?.command_error_message||n.trim()||"Pro Tools refused the command"),s=r?.command_error_type,c=s===Ut||s==="PT_NoOpenedSession"||s==="CEType_PT_NoOpenedSession"||s===String(Ut)?"no_session":/session id|not registered|register/i.test(o)?"not_registered":"command_failed";return new A(c,o,t.length?t:void 0)}var ze=class{constructor(e=jn){this.sessionId="";this.version=null;this.queue=Promise.resolve();let t=/^(127\.\d{1,3}\.\d{1,3}\.\d{1,3}):(\d{1,5})$/.exec(e)??/^\[(::1)\]:(\d{1,5})$/.exec(e);if(!t)throw new A("refused",`${e} is not a loopback IP address and port; PTSL is loopback only`);this.host=t[1],this.port=Number(t[2])}async send(e,t,r){let o;try{o=await it(this.host,this.port,Fn,Jn(e,this.sessionId,t),r)}catch(i){throw this.sessionId="",this.version=null,i instanceof st?i.code==="unavailable"?new A("not_running",`Pro Tools is not running (nothing answered on ${this.host}:${this.port})`):i.code==="deadline"?new A("timeout",`Pro Tools did not answer in ${r} ms (a modal dialog or a long command?)`):i.grpcStatus===12?new A("not_ptsl",`the program on ${this.host}:${this.port} is not Pro Tools`):new A("transport",`PTSL transport error: ${i.message}`):i}let s=Wn(o);if(Bn.includes(s.status)){if(!s.body.trim())return null;try{return JSON.parse(s.body)}catch{throw new A("bad_answer","Pro Tools sent a body that is not JSON")}}throw Vn.includes(s.status)?Kn(s.error):new A("bad_status",`Pro Tools answered with task status ${s.status}`)}async handshake(){if(!this.sessionId){let e=await this.send(Be.RegisterConnection,JSON.stringify({company_name:In,application_name:Dn}),Dt);if(!e?.session_id)throw new A("not_registered","Pro Tools did not give conform.tools a session id");this.sessionId=e.session_id}if(!this.version){let e=await this.send(Be.GetPTSLVersion,"",Dt),t=o=>Number(e?.[o]??0)||0,r=[t("version"),t("version_minor"),t("version_revision")];if(r[0]<ne[0]||r[0]===ne[0]&&r[1]<ne[1])throw this.sessionId="",new A("host_too_old",`Pro Tools ${r[0]}.${r[1]} is too old; conform.tools needs Pro Tools ${ne[0]}.${ne[1]} or newer`);this.version=r}}call(e,t,r=qe){let o=async()=>{if(e==="RegisterConnection")throw new A("refused","RegisterConnection is sent by the client itself");let i=Be[e];if(i===void 0)throw new A("unknown_command",`${e} is not a PTSL command conform.tools sends`);let c=t==null?"":typeof t=="string"?t:JSON.stringify(t);for(let a=0;;a++){if(await this.handshake(),e==="GetPTSLVersion"){let[p,l,d]=this.version;return{version:p,version_minor:l,version_revision:d}}try{return await this.send(i,c,r)}catch(p){if(p instanceof A&&p.code==="not_registered"&&a===0){this.sessionId="";continue}throw p}}},s=this.queue.then(o,o);return this.queue=s.catch(()=>{}),s}},Ve={23976:24e3/1001,24:24,25:25,2997:3e4/1001,30:30,47952:48e3/1001,48:48,50:50,5994:6e4/1001,60:60,100:100,11988:12e4/1001,120:120},Qn={1:["23976",!1],2:["24",!1],3:["25",!1],4:["2997",!1],5:["2997",!0],6:["30",!1],7:["30",!0],8:["47952",!1],9:["48",!1],10:["50",!1],11:["5994",!1],12:["5994",!0],13:["60",!1],14:["60",!0],15:["100",!1],16:["11988",!1],17:["11988",!0],18:["120",!1],19:["120",!0]};function Yn(n){if(typeof n=="number"||typeof n=="string"&&/^\d+$/.test(n.trim())){let t=Qn[Number(n)];return t?{fps:Ve[t[0]],drop:t[1]}:null}let e=/Fps(\d+)(Drop)?/i.exec(String(n??""));return e&&Ve[e[1]]?{fps:Ve[e[1]],drop:!!e[2]}:null}var Xn=/^-?\d{1,2}[:;.]\d{2}[:;.]\d{2}[:;.,]\d{2,3}(\.\d+)?$/,Zn=/^(?:(\d+):)?(\d+):(\d{2}(?:\.\d+)?)$/;function Ge(n,e){let t=String(n??"").trim();if(Xn.test(t))return ut(t.replace(/\.\d+$/,""),e.rate.fps,e.rate.drop);if(/^-?\d+$/.test(t))return e.start+Math.floor(Number(t)*e.rate.fps/e.sampleRate+1e-9);let r=Zn.exec(t);return r?e.start+Math.floor((Number(r[1]??0)*3600+Number(r[2])*60+Number(r[3]))*e.rate.fps+1e-9):null}var xe=["Blue","Cyan","Green","Yellow","Red","Pink","Purple","Fuchsia","Rose","Lavender","Sky","Mint","Lemon","Sand","Cocoa","Cream"],Gt=n=>{let e=Number(n);return e>=1?xe[(e-1)%xe.length]:xe[0]},er=n=>Math.max(0,xe.findIndex(e=>e.toLowerCase()===String(n??"").toLowerCase()))+1,qt=/(?:^| )\[ct:((?:[^[\]\\]|\\.)*)\]$/s;function tr(n,e){return!e&&!qt.test(n)?n:`${n}${n?" ":""}[ct:${e.replace(/[\\[\]]/g,t=>`\\${t}`)}]`}function nr(n){let e=qt.exec(n);return e?{note:n.slice(0,e.index),data:e[1].replace(/\\(.)/gs,"$1")}:{note:n,data:""}}function rr(n){return!n.includes(":")||n.includes("/")||n.includes("\\")?n:`/Volumes/${n.split(":").filter(Boolean).join("/")}`}var ke=class{constructor(e=new ze){this.ptsl=e;this.host="protools"}async sessionName(e=qe){try{return String((await this.ptsl.call("GetSessionName",null,e)).session_name??"")}catch(t){if(t instanceof A&&t.code==="no_session")return"";throw t}}async sessionPath(e=qe){let t=await this.ptsl.call("GetSessionPath",null,e),r=typeof t.session_path=="string"?t.session_path:t.session_path?.path??"";return r?rr(r):""}async current(e=2e3){try{let t=await this.sessionName(e);return t?{project:t,project_path:await this.sessionPath(e).catch(()=>"")}:null}catch{return null}}async facts(){let e=await this.sessionName();if(!e)throw new A("no_session","protools: no session is open");let t=(await this.ptsl.call("GetSessionTimeCodeRate")).current_setting,r=Yn(t);if(!r)throw new A("bad_answer",`protools: a timecode rate conform.tools does not know (${t})`);let o=/(\d{4,6})/.exec(String((await this.ptsl.call("GetSessionSampleRate")).sample_rate??""));if(!o)throw new A("bad_answer","protools: Pro Tools reported a sample rate conform.tools does not know");let s=(await this.ptsl.call("GetSessionStartTime")).session_start_time,i={name:e,rate:r,sampleRate:Number(o[1]),start:0},c=Ge(s,i);if(c==null)throw new A("bad_answer",`protools: a session start conform.tools cannot read (${s})`);return{...i,start:c}}async support(){let e={ok:!1,reason:"Pro Tools holds one session at a time, and importing a timeline changes it; write a .ptx or AAF with timeline_write and open that in Pro Tools"},t={ok:!1,reason:"bouncing from Pro Tools (ExportMix) is not wired"},r;try{r=await this.sessionName(3e3)?{ok:!0}:{ok:!1,reason:"Pro Tools is running with no session open"}}catch(o){r={ok:!1,reason:o instanceof Error?o.message:String(o),setup:Hn}}return{export:r,open:e,render:t,markers:r}}async export(e){let t=await this.sessionName();if(!t)throw new A("no_session","protools: no session is open");if(e.timeline&&e.timeline!==t)throw new A("not_found",`protools: the open session is "${t}"; Pro Tools has one timeline per session`);let r=await this.sessionPath();if(!r||!await le(r))throw new A("no_file",`protools: session "${t}" has no saved .ptx on disk${r?` (${r})`:""}; save it in Pro Tools first`);let o=e.out_path??I(await q("conform-protools-"),at(r));return await Y(fe(o)),await nt(r,o),{path:o,format:"ptx",project:t,timeline:t}}open(){return Promise.reject(new A("unsupported","protools: open is not supported: Pro Tools holds one session, and importing a timeline into it changes it"))}renderStart(){return Promise.reject(new A("unsupported","protools: rendering (a bounce) is not wired"))}renderStatus(){return this.renderStart()}renderCancel(){return this.renderStart()}async project(){let e=await this.facts(),t=await this.sessionPath().catch(()=>""),r=[],o=[];try{let i=await this.ptsl.call("GetTrackList",{page_limit:1e3,track_filter_list:[{filter:"All",is_inverted:!1}]}),c={video:0,audio:0};for(let a of i.track_list??[]){let p=/video/i.test(String(a.type))?"video":"audio",l=a.track_attributes??{},d=l.is_inactive===!0||/^(true|.*_?(set|on|inactive))$/i.test(String(l.is_inactive??""));r.push({kind:p,index:++c[p],name:String(a.name??""),enabled:!d})}}catch(i){o.push(`tracks not read: ${i instanceof Error?i.message:String(i)}`)}let s=(await this.locations(e).catch(()=>({locs:[]}))).locs.length;return{project:e.name,timeline:e.name,timelines:[e.name],session_path:t,fps:e.rate.fps,drop_frame:e.rate.drop,sample_rate:e.sampleRate,start_tc:Ee(e.start,e.rate.fps,e.rate.drop),ptsl_version:this.ptsl.version?.join("."),markers:s,notes:o,tracks:r,jobs:[],found:{},pool:{path:"",clips:0,folders:[]}}}async locations(e){let t=[];for(let o=0;;){let s=await this.ptsl.call("GetMemoryLocations",{pagination_request:{limit:1e3,offset:o}}),i=(s.memory_locations??[]).filter(c=>c&&typeof c=="object");if(t.push(...i),o+=i.length,!i.length||o>=Number((s.pagination_response??s.stats)?.total??0))break}let r=[];for(let o of t){let s=o.time_properties,i=typeof s=="number"||/^\d+$/.test(String(s))?{1:"Marker",2:"Selection"}[Number(s)]:String(s??"").split("_").pop();if(i!=="Marker"&&i!=="Selection")continue;let c=Ge(o.start_time,e);if(c==null)continue;let a=i==="Selection"?Ge(o.end_time,e):null,{note:p,data:l}=nr(String(o.comments??""));r.push({number:Number(o.number)||0,frame:c-e.start,duration:a==null?1:Math.max(1,a-c),name:String(o.name??""),note:p,data:l,color:Gt(o.color_index),raw:o})}return r.sort((o,s)=>o.frame-s.frame||o.number-s.number),{locs:r.filter((o,s)=>s===0||r[s-1].frame!==o.frame),numbers:t.map(o=>Number(o.number)||0)}}async writeFormat(){let e=await this.ptsl.call("GetMainCounterFormat"),t=e.current_setting??e.current_type,r=typeof t=="number"||/^\d+$/.test(String(t))?{3:"TimeCode",5:"Samples"}[Number(t)]:String(t??"").split("_").pop();if(r==="TimeCode")return"timecode";if(r==="Samples")return"samples";throw new A("counter_format","protools: set Pro Tools' main counter to Timecode or Samples to edit markers from conform.tools")}async apply(e){let t=await this.facts();if(e.timeline&&e.timeline!==t.name)throw new A("not_found",`protools: the open session is "${t.name}"`);let{locs:r,numbers:o}=await this.locations(t),s=new Map(r.map(u=>[u.frame,u])),i=null,c=u=>i==="samples"?String(Math.round(u*t.sampleRate/t.rate.fps)):Ee(t.start+u,t.rate.fps,t.rate.drop),a=async(u,m)=>{let g=Math.max(1,Math.round(u.duration??1)),S=m?.number??Math.max(0,...o)+1,_=m?.raw??{},v={number:S,name:u.name??"",start_time:c(u.frame),end_time:c(u.frame+(g>1?g:0)),time_properties:g>1?"TP_Selection":"TP_Marker",reference:_.reference||"MLR_Absolute",general_properties:_.general_properties||{zoom_settings:!1,pre_post_roll_times:!1,track_visibility:!1,track_heights:!1,group_enables:!1,window_configuration:!1},comments:tr(u.note??"",u.data??""),color_index:er(u.color),location:_.location||"MLC_MainRuler",..._.track_name?{track_name:_.track_name}:{}};await this.ptsl.call("CreateMemoryLocation",v),o.push(S),s.set(u.frame,{number:S,frame:u.frame,duration:g,name:u.name??"",note:u.note??"",data:u.data??"",color:Gt(v.color_index),raw:v})},p=async u=>{await this.ptsl.call("ClearMemoryLocation",{location_list:[u.number]}),s.delete(u.frame),o.splice(o.indexOf(u.number),1)},l=u=>({op:"marker_add",frame:u.frame,color:u.color,name:u.name,note:u.note,duration:u.duration,...u.data?{data:u.data}:{}}),d=[],f=[];for(let u of e.ops){let m=Number(u.frame);try{if(!u.op.startsWith("marker_")||u.item){d.push({op:u.op,ok:!1,detail:`protools: '${u.op}' is not reachable over PTSL (timeline markers only)`});continue}if(!Number.isInteger(m)){d.push({op:u.op,ok:!1,detail:"frame must be a whole number"});continue}i??=await this.writeFormat();let g=s.get(m);if(u.op==="marker_add")g&&await p(g),await a({frame:m,color:u.color,name:u.name,note:u.note,duration:Number(u.duration??1),data:u.data||Un}),d.push({op:u.op,ok:!0}),f.unshift({op:"marker_delete",frame:m},...g?[l(g)]:[]);else if(u.op==="marker_update"){if(!g){d.push({op:u.op,ok:!1,detail:`no marker at frame ${m}`});continue}let S=u.to_frame!==void 0?Number(u.to_frame):m;if(!Number.isInteger(S)){d.push({op:u.op,ok:!1,detail:"to_frame must be a whole number"});continue}if(S!==m&&s.has(S)){d.push({op:u.op,ok:!1,detail:`frame ${S} already has a marker`});continue}await p(g);let _=(v,R)=>u[v]!==void 0?u[v]:R;await a({frame:S,color:_("color",g.color),name:_("name",g.name),note:_("note",g.note),duration:Number(_("duration",g.duration)),data:_("data",g.data)},g),d.push({op:u.op,ok:!0}),f.unshift({op:"marker_update",frame:S,color:g.color,name:g.name,note:g.note,duration:g.duration,data:g.data,...S!==m?{to_frame:m}:{}})}else if(u.op==="marker_delete"){if(!g){d.push({op:u.op,ok:!1,detail:`no marker at frame ${m}`});continue}await p(g),d.push({op:u.op,ok:!0}),f.unshift(l(g))}else d.push({op:u.op,ok:!1,detail:`protools: unknown marker op '${u.op}'`})}catch(g){d.push({op:u.op,ok:!1,detail:g instanceof Error?g.message:String(g)})}}let h=d.filter(u=>u.ok).length;return{project:t.name,timeline:t.name,results:d,undo:f,applied:h,failed:d.length-h}}};var or="Install the conform.tools panel in Media Composer (mcp/hosts/avid/panel: package it, copy the .avpi into PanelSDKPlugins; an unsigned panel needs Avid's Feature Toggle Files), then open Tools > CONFORM.TOOLS. Its page loads from this engine's host bridge (port 48127) and connects by itself.",sr="Install the conform.tools hook (host_setup host=flame action=install_panel), then in Flame: Flame menu > Python > Rescan Python Hooks (or restart Flame), then Flame menu > CONFORM.TOOLS > Connect to CONFORM.TOOLS (or Connect Automatically).",zt={resolve:new _e,premiere:new dt,avid:new Oe({host:"avid",label:"Media Composer",setup:or}),flame:new Oe({host:"flame",label:"Flame",setup:sr,items:!0}),baselight:new Se,protools:new ke};function Ir(n,e){zt[n]=e}function Dr(n){return zt[n]??ft(n,"not wired yet")}export{bt as a,dr as b,vn as c,kr as d,ke as e,ir as f,or as g,sr as h,Ir as i,Dr as j};
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
+ import{a as R}from"./chunk-PFZVET7S.js";import{b as he,c as be,f as ge}from"./chunk-6V4OEOOX.js";import{f as K,h as fe}from"./chunk-XDI6CPPV.js";import{a as pe}from"./chunk-UKXSKFL3.js";import{i as D}from"./chunk-4RA57LTJ.js";import{b as M,d as z,f as F}from"./chunk-NU3X7P4N.js";import{Ia as de,ea as se,fa as ae,ja as ce,oa as le,wa as ue,xa as me}from"./chunk-DPA26AOI.js";import{a as ie}from"./chunk-ROGMKTND.js";import{$ as y,B as W,G as L,M as v,N as C,O as ne,R as oe,_ as b,aa as J,b as O,ba as _,c as Z,d as Q,g as q,k as ee,l as re,s as H,t as B,v as te,w as A,z as j}from"./chunk-X527E5VI.js";var V=!1;var P=8,Pe=0,Ee=3,N=2;async function Oe(e){let t=new Uint8Array(await e.slice(0,16).arrayBuffer()),o=s=>String.fromCharCode(t[s],t[s+1],t[s+2],t[s+3]);if(t[0]===6&&t[1]===14&&t[2]===43&&t[3]===52)return"mxf";if(o(4)==="RED1"||o(4)==="RED2")return"r3d";let r=t[0]<<24|t[1]<<16|t[2]<<8|t[3],i=o(4);return/^[A-Za-z0-9 ]{4}$/.test(i)&&(r>=8||r===1)&&r<=e.size?"isobmff":null}function Ae(e){let t=e.toLowerCase();return t.endsWith(".braw")?"braw":t.endsWith(".crm")?"crm":"mov"}function Ce(e){return async(t,o)=>new Uint8Array(await e.slice(t,Math.min(t+o,e.size)).arrayBuffer())}function we(e){let t=e.timecode;return!t||!t.fps_denominator?null:t.fps_numerator/t.fps_denominator}async function ir(e){return await de(),_e?_e.clip(e,V?"rec709":"",()=>ye(e)):ye(e)}var _e=null;async function ye(e){let t=await Oe(e),o=[];if(t==="r3d"){let r=e,i=r.parts&&r.bases?r.parts:[{name:e.name,size:e.size}],n=r.bases??[0],s=async(m,u,d)=>{let f=n[m]+u;return new Uint8Array(await e.slice(f,Math.min(f+d,n[m]+i[m].size)).arrayBuffer())},a=JSON.stringify(i.map(m=>({name:m.name,size:m.size}))),c=JSON.parse(await me(s,a)),l=JSON.parse(await ce(s,a));return i.length===1&&/_\d{3}\.r3d$/i.test(e.name)&&!/_001\.r3d$/i.test(e.name)&&o.push("spanned R3D part \u2014 only this part's frames are indexed"),{frames:l.map(m=>({offset:n[m.part??0]+m.essenceOffset,size:m.essenceLength})),w:c.width??0,h:c.height??0,fps:we(c),startFrame:c.timecode?.start_frame??0,dropFrame:c.timecode?.drop_frame??!1,label:"R3D",spec:{codec:"r3d",subbands:Pe},geometrySpec:{codec:"r3d",subbands:Ee},index:null,warnings:o}}if(t==="mxf"){let r=Ce(e),i=JSON.parse(await ue(r,e.size));if(!i)throw new Error(`${e.name}: MXF index unreadable`);let n=JSON.parse(await le(r,e.size)),s=[];for(let f=0;f<n.frame_count;f++)s.push({offset:n.frames[f*2],size:n.frames[f*2+1]});let a=s.filter(f=>f.size===0).length;a&&o.push(`${a} frame(s) had no locatable picture KLV`);let c=i.width??0,l=i.height??0,m=(i.inner_codec??"").toLowerCase(),u=null,d="MXF";return m==="arriraw"?(u={codec:"arriraw",w:c,h:l,scale:P},d="ARRIRAW"):m==="xocn"?(u={codec:"xocn",scale:P,...V?{display:"rec709"}:{}},d="X-OCN"):await ae(r,e.size)?(u={codec:"vc3",scale:P},d="DNxHR"):await se(r,e.size)?(u={codec:"prores"},d="ProRes"):o.push(`MXF inner codec ${m||"unknown"} not wired to the fingerprint pool`),{frames:u?s:[],w:c,h:l,fps:we(i),startFrame:i.timecode?.start_frame??0,dropFrame:i.timecode?.drop_frame??!1,label:d,spec:u,geometrySpec:u&&u.codec==="arriraw"?{...u,scale:N}:u&&u.codec==="xocn"?{codec:"xocn",scale:N,...V?{display:"rec709"}:{}}:u&&u.codec==="vc3"?{codec:"vc3",scale:N}:null,index:null,warnings:o}}if(t==="isobmff"){let r=await fe(e),i=Ae(e.name);if(r.kind==="prores")return{frames:r.offs,w:r.w,h:r.h,fps:r.fps,startFrame:r.startFrame,dropFrame:r.dropFrame,label:K(r.kind),spec:{codec:"prores"},geometrySpec:null,index:r,warnings:o};if(r.kind==="h264"||r.kind==="hevc")return{frames:r.offs,w:r.w,h:r.h,fps:r.fps,startFrame:r.startFrame,dropFrame:r.dropFrame,label:K(r.kind),spec:null,geometrySpec:null,index:r,warnings:o};let n=i==="braw"?{codec:"braw",scale:P}:r.codec==="aprh"||r.codec==="aprn"?{codec:"proresraw",scale:P}:null;return n||o.push(`codec ${r.codec} not wired to the fingerprint pool`),{frames:n?r.offs:[],w:r.w,h:r.h,fps:r.fps,startFrame:r.startFrame,dropFrame:r.dropFrame,label:n?i==="braw"?"BRAW":"ProRes RAW":`unsupported (${r.codec})`,spec:n,geometrySpec:n?{...n,scale:N}:null,index:r,warnings:o}}throw new Error(`${e.name}: unrecognised container`)}var De=Number(O("CONFORM_DECODERS")??0)||Math.max(2,Math.min(Math.floor(Q()/2),Math.floor(Z()/2**31))),X=0,xe=[],ze=async(...e)=>{X>=De?await new Promise(t=>xe.push(t)):X++;try{return await oe(...e)}finally{let t=xe.shift();t?t():X--}};async function Ne(){let e=q()==="win32"?"conformtools-decode.exe":"conformtools-decode",t=[O("CONFORM_NATIVE_DECODE"),ee(e),H(new URL(`./${e}`,import.meta.url)),H(new URL(`../../rust/target/release/${e}`,import.meta.url))].filter(Boolean);for(let o of t)if(await te(o))return o;return null}var $=class extends Error{constructor(o,r){super(r);this.why=o}};function Pr(e){let t=null;try{t=JSON.parse(e.trim().split(`
4
+ `).pop())}catch{}if(t?.why==="not_entitled")throw new ie("not_entitled",t.detail??"this machine is not licensed");return t?.detail??e.trim()}function Te(e,t){try{let o=JSON.parse(e.trim().split(`
5
+ `).pop()??"");return new $(o.why,o.detail)}catch{return new $("decoder",`the native decoder exited ${t}: ${e.trim().slice(-300)}`)}}function Ue(e){let t=e.reduce((i,n)=>i+n.length,0),o=new Uint8Array(t),r=0;for(let i of e)o.set(i,r),r+=i.length;return o}async function $e(e,t,o,r,i){let n=await Ne();if(!n)throw new $("missing",re("the native decoder (conformtools-decode)"));let s=null,a=[],c=0,l=d=>{let f=new Uint8Array(d),h=0;for(;h<d;){let p=a[0],g=Math.min(p.length,d-h);f.set(p.subarray(0,g),h),h+=g,g===p.length?a.shift():a[0]=p.subarray(g)}return c-=d,f},m=[e,t,"--width",String(i.width??32768)];i.from!=null&&m.push("--from",String(i.from)),i.count!=null&&m.push("--count",String(i.count)),i.range&&m.push("--range",i.range);let u=await ze(n,m,d=>{if(a.push(d),c+=d.length,!s){let h=Ue(a.splice(0));a.push(h);let p=h.indexOf(10);if(p<0)return;s=JSON.parse(new TextDecoder().decode(h.subarray(0,p))),l(p+1),o(s)}let f=4+s.w*s.h*(s.bpp??(e==="rgb16"?6:4));for(;c>=f;){let h=l(f);r(new DataView(h.buffer).getUint32(0,!0),h.subarray(4))}},{signal:i.signal});if(u.code!==0||!s)throw Te(u.stderr,u.code)}function ve(e,t,o,r={}){return $e("bgra",e,t,o,r)}function Se(e,t,o,r={}){return $e("rgb16",e,t,(i,n)=>o(i,new Uint16Array(n.buffer,n.byteOffset,n.length>>1)),r)}var ke=["none","rle","zips","zip","piz","pxr24","b44","b44a","dwaa","dwab","htj2k"],T=e=>(e>>4)*10+(e&15);function Ie(e){let t=T(e&63),o=T(e>>>8&127),r=T(e>>>16&127),i=T(e>>>24&63),n=s=>String(s).padStart(2,"0");return`${n(i)}:${n(r)}:${n(o)}${e&64?";":":"}${n(t)}`}function He(e){let t=new DataView(e.buffer,e.byteOffset,e.byteLength);if(e.length<8||t.getUint32(0,!0)!==20000630)return null;let o={fps:null,timecode:null,width:0,height:0,display:null,compression:null,attributes:[]},r=8,i=()=>{let s=r;for(;r<e.length&&e[r]!==0;)r++;let a=new TextDecoder().decode(e.subarray(s,r));return r++,a},n=s=>({width:t.getInt32(s+8,!0)-t.getInt32(s,!0)+1,height:t.getInt32(s+12,!0)-t.getInt32(s+4,!0)+1});for(;r<e.length;){let s=i();if(!s)break;let a=i();if(r+4>e.length)return null;let c=t.getInt32(r,!0);if(r+=4,c<0||r+c>e.length)return null;if(o.attributes.push(`${s}:${a}`),s==="framesPerSecond"&&a==="rational"&&c>=8){let l=t.getInt32(r,!0),m=t.getUint32(r+4,!0);o.fps=m?l/m:null}else s==="timeCode"&&a==="timecode"&&c>=8?o.timecode=Ie(t.getUint32(r,!0)):s==="dataWindow"&&a==="box2i"&&c>=16?{width:o.width,height:o.height}=n(r):s==="displayWindow"&&a==="box2i"&&c>=16?o.display=n(r):s==="compression"&&c>=1&&(o.compression=ke[e[r]]??`type ${e[r]}`);r+=c}return o}async function Be(e){let t=e,o=null,r=/^(.*?)\[(\d+)-(\d+)\](.*)$/.exec(b(e));if(await A(e))o=/^(.*?)(\d+)(\.exr)$/i;else{t=y(e);let n=r?[null,r[1],r[2],r[4]]:/^(.*?)(\d+)(\.exr)$/i.exec(b(e));if(!n)return{frames:[e],numbers:[]};let s=a=>a.replace(/[.*+?^${}()|[\]\\]/g,"\\$&");o=new RegExp(`^${s(n[1])}(\\d{${n[2].length}})${s(n[3])}$`,"i")}let i=[];for await(let n of v(t)){let s=n.isFile?o.exec(n.name):null;s&&i.push({n:Number(s[s.length===4?2:1]),f:_(t,n.name)})}return i.sort((n,s)=>n.n-s.n),{frames:i.map(n=>n.f),numbers:i.map(n=>n.n)}}async function Re(e){let t=await Be(e),o=t.frames[0];if(!o)throw new Error(`no .exr frames for '${b(e)}'`);let r=await C(o),i;try{i=He(await r.readAt(0,Math.min(r.size,1<<20)))}finally{await r.close()}if(!i)throw new Error(`'${b(o)}' is not an OpenEXR file`);let n=Math.max(1,t.frames.length),s=t.numbers.length>1?t.numbers[t.numbers.length-1]-t.numbers[0]+1-t.numbers.length:0,a=i.fps??0;return{id:b(o),kind:"external",target_url:o,local_path:o,content_kind:n>1?"video":"still",source_fps:i.fps??void 0,source_timecode:i.timecode??void 0,source_resolution_w:i.width,source_resolution_h:i.height,available_range:{start:{value:0,rate:a},duration:{value:n,rate:a}},streams:[{kind:"video",codec:"exr",width:i.width,height:i.height,rate:i.fps??void 0,codec_specific:{compression:i.compression}}],vendor_metadata:{exr:{frames:n,first_frame:t.numbers[0]??null,last_frame:t.numbers[t.numbers.length-1]??null,missing_frames:s,display_window:i.display,attributes:i.attributes,fps_source:i.fps!=null?"header framesPerSecond":"not in the header",timecode_source:i.timecode?"header timeCode (first frame)":"not in the header"}}}}var G=new Set([".mov",".mp4",".m4v",".mxf",".wav",".braw",".crm",".r3d",".aif",".aiff"]);async function je(e){let t=await C(e);return{path:e,file:t,size:t.size}}function We(e){return(t,o)=>e.file.readAt(t,o)}async function Le(e){let t=R(b(e));if(!t)return[e];let o=y(e),r=[];for await(let i of v(o)){if(!i.isFile)continue;let n=R(i.name);n&&n.clipBase===t.clipBase&&r.push({n:n.partNumber,p:_(o,i.name)})}return r.sort((i,n)=>i.n-n.n).map(i=>i.p)}async function Y(e){if(await A(e)){let n=[];for await(let s of v(e))s.isFile&&R(s.name)&&n.push(_(e,s.name));if(!n.length)throw new Error(`'${b(e)}' is a folder with no .R3D parts`);e=n.sort()[0]}let t=be(b(e));if(!t)throw new Error(`unsupported media file '${b(e)}' (supported: ${[...G].join(" ")})`);let o=await Le(e),r=await Promise.all(o.map(je));return{source:ge(t,r.map(n=>he(b(n.path),{fileSize:n.size,read:We(n)}))),parts:r,format:t,anchor:o[0],close:()=>r.forEach(n=>n.file.close())}}async function Je(e,t,o,r){if(!/h264|avc|hevc|h265/.test(o)){let i=null,n=await Y(e);try{return await D(n.source,{verb:"decode",index:t,intent:"park"})}catch(s){i=s}finally{n.close()}try{return await Me(e,t,r)}catch(s){throw/no decoder/.test(String(i))?s:i instanceof Error?i:new Error(String(i))}}return Me(e,t,r)}async function Hr(e,t,o,r={}){if(/\.mxf$/i.test(e)&&(!o||/h264|avc|mxf/.test(o))){let a=null,c=null;try{await Se(e,l=>{a=l},(l,m)=>{l===t&&(c=m.slice())},{from:t,count:1,range:r.range})}catch(l){if(!(l instanceof $)||!/unsupported|missing/.test(l.why))throw l}if(c&&a){let l=a;return{rgb:c,width:l.w,height:l.h,bits:l.bit_depth??16,decoder:"media-core",full_range:l.full_range??null}}}let i=await Je(e,t,o),n=i.width*i.height,s=new Uint16Array(n*3);for(let a=0;a<n;a++)s[a*3]=i.rgba[a*4]*257,s[a*3+1]=i.rgba[a*4+1]*257,s[a*3+2]=i.rgba[a*4+2]*257;return{rgb:s,width:i.width,height:i.height,bits:8,decoder:"8-bit",full_range:null}}async function Me(e,t,o){t=Math.round(t);let r=0,i=0,n=null;if(await ve(e,a=>{r=a.w,i=a.h},(a,c)=>{a===t&&(n=c)},{from:t,count:1,width:o}),!n)throw new Error(`the OS decoder returned no frame ${t} of ${b(e)}`);let s=n;for(let a=0;a<s.length;a+=4){let c=s[a];s[a]=s[a+2],s[a+2]=c}return{rgba:s,width:r,height:i}}async function E(e){if(/\.exr$/i.test(e))return Re(e);let t=await Y(e);try{let o=await D(t.source,{verb:"inspect"});if(!o)throw new Error(`could not read '${b(e)}' as ${t.format}`);return o.target_url=t.anchor,o.local_path=t.anchor,o.id=o.id||b(t.anchor),t.parts.length>1&&((o.vendor_metadata??={}).spanned_parts=t.parts.map(r=>b(r.path))),o.size_bytes=t.parts.reduce((r,i)=>r+i.size,0),o}finally{t.close()}}function Ke(e,t,o,r){let i=Math.abs(r*1001-Math.round(r*1001/1e3)*1e3)<1?Math.round(r)*1e3/1001:r,n=Math.floor(e*i/t+1e-6);return{tc:M(n,r),frames:Math.round(o*i/t)}}var Ve=e=>String(Math.round(e*1e3)/1e3);function Br(e,t){let o=e.streams?.find(u=>u.kind==="video"),r=e.streams?.filter(u=>u.kind==="audio")??[],i=e.vendor_metadata?.bext;if(!o&&e.available_range&&r[0]?.rate){let u=r[0].rate,d=e.available_range.duration.value,h=(t?[t]:[24e3/1001,24]).map(p=>{let g=Ke(i?.time_reference??0,i?.sample_rate||u,d,p);return`${i?`start TC ${g.tc}, `:""}${g.frames} frames @ ${Ve(p)} fps`});return[e.target_url??"",`audio only; ${d} samples (${(d/u).toFixed(3)} s)${i?`; BWF time_reference ${i.time_reference}`:"; no BWF timecode"}`,...h,...t?[]:["(pass fps for the project's rate)"],...r.map((p,g)=>`audio ${r.length>1?`${g+1}: `:""}${p.codec??"pcm"} ${p.channels??"?"}ch ${p.rate} Hz ${p.bit_depth??"?"}-bit`)].join(`
6
+ `)}let n=e.available_range?.duration?.value??e.declared_duration?.value??null,s=e.source_fps??o?.rate??null,a=e.size_bytes,c=e.vendor_metadata?.spanned_parts,l=o?.codec_specific??{},m=[l.profile?`${l.profile} (${l.fourcc})`:l.fourcc,l.pixel_format,o?.bit_depth?`${o.bit_depth}-bit`:null,l.colr?`color ${l.colr.primaries}/${l.colr.transfer}/${l.colr.matrix} (primaries/transfer/matrix)`:null].filter(Boolean).join(", ");return[e.target_url??"",o?`${o.codec??"?"} ${o.width??"?"}x${o.height??"?"}${s?` @ ${Math.round(s*1e3)/1e3} fps`:""}${m?`; ${m}`:""}`:"no video track",`start TC ${e.source_timecode??"none"}; ${n!=null?`${n} frames`:"length unknown"}${n!=null&&s?` (${(n/s).toFixed(2)} s)`:""}`,r.length?r.map((u,d)=>{let f=u.codec_specific?.channel_layout;return`audio ${r.length>1?`${d+1}: `:""}${u.codec??"pcm"} ${u.channels??"?"}ch${f?` (${f})`:""} ${u.rate??"?"} Hz ${u.bit_depth??"?"}-bit`}).join(`
7
+ `):"no audio",`${e.reel_name?`reel ${e.reel_name}; `:""}${a!=null?`${(a/1e6).toFixed(1)} MB`:""}${c?`; spanned ${c.length} parts`:""}`].join(`
8
+ `)}var Xe=8*1024*1024,U=e=>Uint8Array.from(atob(e),t=>t.charCodeAt(0));async function Ge(e,t,o){if(e.executable_locally===!1)throw new Error("this trim plan is server-side only");let r=new Map(t.parts.map(n=>[b(n.path),n]));await W(y(o));let i=await ne(o);try{await i.truncate(e.total_size),await i.writeAt(0,U(e.dest_header_bytes_base64));for(let n of e.src_byte_ranges){let s=n.src_file_name?r.get(b(n.src_file_name)):t.parts[0];if(!s)throw new Error(`plan references unknown source part '${n.src_file_name}'`);let a=0;for(;a<n.length;){let c=Math.min(Xe,n.length-a),l=await s.file.readAt(n.offset+a,c);if(l.length<c)throw new Error(`short read in ${b(s.path)} at ${n.offset+a}`);await i.writeAt(n.write_to_dest_offset+a,l),a+=c}}e.dest_footer_bytes_base64&&e.dest_footer_offset!=null&&await i.writeAt(e.dest_footer_offset,U(e.dest_footer_bytes_base64));for(let n of e.dest_patches??[])await i.writeAt(n.offset,U(n.bytes_base64))}finally{await i.close()}for(let n of e.dest_sidecar_writes??[])await j(_(y(o),n.name),U(n.bytes_base64))}function Ye(e,t){let o=[];for(let r of e){if(r.kind!=="clip"||!r.source_range)continue;let i=r.source_range.start.value,n=r.source_range.duration.value,s=Math.max(0,Math.floor(i)-t),a=Math.floor(i+n-1)+t;a>=s&&o.push({first_frame:s,last_frame:a})}return pe(o)}async function Ze(e,t,o,r,i){let n=await Y(e);try{let s=Ye(t,o);if(!s.length)throw new Error("no usable frame ranges (items need kind=clip with source_range)");let a=await D(n.source,{verb:"trim",selection:{items:t,handles:o}}),c=J(n.anchor),l=n.format==="r3d",m=l?R(b(n.anchor))?.clipBase??b(n.anchor,c):b(n.anchor,c),u=[];for(let[d,f]of a.entries()){let h=f.output_clip_number??(s.length>1?d+1:void 0),p=s[(h??1)-1]??s[0],g=h&&(f.output_clip_count??s.length)>1?`_S${String(h).padStart(3,"0")}`:"",w;if(l){let x=f.output_part_number??d+1;w=_(r,`${m}${g}.RDC`,`${m}_${String(x).padStart(3,"0")}.R3D`),u.push({path:w,bytes:f.total_size,island:p,part:x,clip:h})}else{let x=i&&a.length===1?i:`${m}${g||`_trim_${p.first_frame}-${p.last_frame}`}${c}`;w=_(r,x),u.push({path:w,bytes:f.total_size,island:p,clip:h})}await Ge(f,n,w)}return l||await Qe(e,u,!!i&&a.length===1),{outputs:u,islands:s,format:n.format}}finally{n.close()}}async function Qe(e,t,o){let r=await E(e).catch(()=>null),i=r?.source_fps??r?.streams?.find(n=>n.kind==="video")?.rate??null;if(!(!r?.source_timecode||!i))for(let n of t){if(!n.island)continue;let s=await E(n.path).catch(()=>null),a=s?.available_range?.duration?.value??s?.declared_duration?.value;if(!s?.source_timecode||!a)continue;let c=F(s.source_timecode,i,r.source_timecode);if(c===n.island.first_frame&&c+a-1===n.island.last_frame||(n.island={first_frame:c,last_frame:c+a-1},o))continue;let l=n.path.replace(/_trim_\d+-\d+(\.[^./\\]+)$/,`_trim_${c}-${c+a-1}$1`);l!==n.path&&(await L(n.path,l),n.path=l)}}async function jr(e){let t=await E(e.path),o=t.source_fps??t.streams?.find(g=>g.kind==="video")?.rate??null,r=t.available_range?.duration?.value??t.declared_duration?.value??null;if(!o)throw new Error("cannot trim: no frame rate / timecode track on this file");let i=F(e.in,o,t.source_timecode??null),n=F(e.out,o,t.source_timecode??null);e.out_exclusive&&(n-=1);let s=t.source_timecode??"00:00:00:00",a=r!=null?M((z(s,o)??0)+r-1,o,!!t.vendor_metadata?.drop_frame):null;if(n<i)throw new Error(`out ${e.out} is before in ${e.in}`);if(i<0)throw new Error(`in ${e.in} is before the file starts (${s}, frame 0)`);if(r!=null&&n>r-1)throw new Error(`out ${e.out} is past the end of the file (last frame ${a}, frame ${r-1})`);let c={id:"trim",kind:"clip",source_range:{start:{value:i,rate:o},duration:{value:n-i+1,rate:o}}},l=y(e.path),m;if(e.out_path)try{(await B(e.out_path)).isDirectory?l=e.out_path:(l=y(e.out_path),m=b(e.out_path))}catch{l=y(e.out_path),m=b(e.out_path)}let u=await Ze(e.path,[c],Math.max(0,Math.floor(e.handles??0)),l,m),d=u.islands[0],f=u.outputs.length===1&&u.outputs[0].island?u.outputs[0].island:d,h=f.first_frame,p=f.last_frame;return{outputs:u.outputs,first_frame:h,last_frame:p,frames:p-h+1,fps:o,facts:t,...h!==d.first_frame||p!==d.last_frame?{asked:{first_frame:d.first_frame,last_frame:d.last_frame}}:{}}}function Fe(e){let t=[...G].map(o=>o.slice(1)).join("|");return e.toLowerCase().replace(new RegExp(`\\.(${t})(?=[._\\s-]|$)`,"g"),"").replace(/[^a-z0-9]/g,"")}function qe(e,t){let o=Fe(e),r=Fe(t);if(r&&o.includes(r))return"name";let i=t.toLowerCase().split(/[^a-z0-9]+/).filter(n=>/\d/.test(n)&&n.length>=3);return i.length&&i.every(n=>o.includes(n))?"id":null}async function Wr(e,t,o){let r=[],i=0,n=null,s=Date.now()+o.time_limit_s*1e3,a=async(c,l)=>{try{for await(let m of v(c)){if(n&&!n.startsWith("folders"))return;if(++i>o.max_entries){n=`stopped after ${o.max_entries} entries (max_entries)`;return}if(Date.now()>s){n=`stopped after ${o.time_limit_s} s (time_limit_s)`;return}if(m.name.startsWith("."))continue;let u=_(c,m.name);if(m.isDirectory)l<o.max_depth?await a(u,l+1):n??=`folders deeper than max_depth=${o.max_depth} not searched (e.g. ${u})`;else if(m.isFile&&G.has(J(m.name).toLowerCase())){let d=qe(m.name,t);d&&r.push({path:u,match:d,size:(await B(u).catch(()=>({size:0}))).size})}}}catch{}};if(await a(e,0),o.probe)for(let c=0;c<r.length;c+=8)await Promise.all(r.slice(c,c+8).map(async l=>{try{l.facts=await E(l.path)}catch(m){l.error=m.message}}));return r.sort((c,l)=>c.path.localeCompare(l.path)),{hits:r,scanned:i,truncated:n}}function er(e){let t=e.streams?.find(a=>a.kind==="video"),o=e.source_fps??t?.rate??null,r=e.available_range?.duration?.value??e.declared_duration?.value??null,i=t?.codec_specific??{},n=e.source_timecode&&o?z(e.source_timecode,o):null,s=n!=null&&r!=null&&o?M((n+r)%(Math.round(o)*86400),o,e.source_timecode.includes(";")):null;return`${t?`${t.codec??"?"}${i.profile?` ${i.profile}`:""} ${t.width??"?"}x${t.height??"?"}`:"no video"}${o?` @ ${Math.round(o*1e3)/1e3} fps`:""}; TC ${e.source_timecode??"none"}${s?`\u2013${s}`:""}; ${r??"?"} fr${r!=null&&o?` (${(r/o).toFixed(2)} s)`:""}`}function Lr(e,t,o,r){let i=e.hits.slice(0,r),n=[];e.truncated&&n.push(`TRUNCATED: ${e.truncated} \u2014 the search did NOT cover all of ${t}; the matches below may be incomplete.`),e.hits.length>i.length&&n.push(`TRUNCATED: showing ${i.length} of ${e.hits.length} matches. Pass limit=${e.hits.length} or narrow the query.`),n.push(`${e.hits.length} file${e.hits.length===1?"":"s"} match "${o}" under ${t} (${e.scanned} entries scanned)`);let s=new Map;for(let c of e.hits)s.set(b(c.path).toLowerCase(),(s.get(b(c.path).toLowerCase())??0)+1);let a=[...s].filter(([,c])=>c>1);a.length&&n.push(`same name in several folders: ${a.map(([c,l])=>`${c} \xD7${l}`).join(", ")} \u2014 they can be DIFFERENT clips; match by TC + duration, never by name alone`);for(let c of i)n.push(`- ${c.path}${c.match==="id"?" (id match)":""}
9
+ ${c.facts?er(c.facts):c.error?`probe failed: ${c.error}`:`${(c.size/1e6).toFixed(1)} MB`}`);return n.join(`
10
+ `)}async function Jr(e,t,o=0){let r=await E(e),i=r.source_fps??r.streams?.find(d=>d.kind==="video")?.rate??null,n=r.available_range?.duration?.value??r.declared_duration?.value??null;if(!i||n==null)throw new Error(`cannot check coverage: ${b(e)} has no frame rate or length`);let s=Math.round(i)*86400,a=r.source_timecode?z(r.source_timecode,i)??0:0,c=!!r.source_timecode?.includes(";"),l=d=>{let f=F(d,i,r.source_timecode??null);return typeof d=="number"||/^\d+$/.test(d.trim())?f:f<-s/2?f+s:f>s/2?f-s:f},m=d=>M(((a+d)%s+s)%s,i,c),u=t.map((d,f)=>{let h=l(d.in),p=l(d.out),g=h,w=n-p,x=g>=0&&w>=0&&p>h,k=Math.max(0,-g),I=Math.max(0,-w),S=[];return p<=h?S.push("out is not after in"):x?S.push(`covered; handles head ${g} / tail ${w} fr`):S.push(`NOT covered: short ${[k?`${k} fr at head`:"",I?`${I} fr at tail`:""].filter(Boolean).join(", ")}`),x&&o&&(g<o||w<o)&&S.push(`handles short of ${o}: ${[g<o?`head by ${o-g}`:"",w<o?`tail by ${o-w}`:""].filter(Boolean).join(", ")}`),{label:d.label??`range ${f+1}`,in_tc:m(h),out_tc:m(p),frames:p-h,covered:x,head:g,tail:w,short_head:k,short_tail:I,note:S.join("; ")}});return{facts:r,rows:u}}export{ir as a,Ne as b,Pr as c,ve as d,Be as e,G as f,Le as g,Y as h,Je as i,Hr as j,E as k,Ke as l,Br as m,Ye as n,Ze as o,jr as p,Fe as q,qe as r,Wr as s,er as t,Lr as u,Jr as v};
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env node
2
+ import { createRequire as __conformRequire } from 'node:module'; const require = __conformRequire(import.meta.url);
3
+ import{A,B as w,F as y,a as h,ba as c,n as x,o as k,u,y as C}from"./chunk-X527E5VI.js";var O=new Set(["ffmpeg","ffprobe","ffplay","sox","soxi","mediainfo","exiftool","mkvmerge","mkvextract","mp4box","bmxtranswrap","raw2rgb","redline","art-cmd","oiiotool","iconvert","idiff","asdcp-wrap","asdcp-unwrap","asdcp-info","opendcp","dcp_inspect","handbrakecli","gst-launch-1.0","mencoder","mplayer","sips","afconvert","avconvert","qtfaststart","mediaconch","bwfmetaedit","x264","x265","aomenc","svtav1encapp","otiotool","otioconvert","otioview","cineform","ale2csv"]),I=["mov","mp4","m4v","mxf","mkv","avi","webm","mts","m2ts","mpg","mpeg","r3d","braw","ari","arx","crm","dng","dpx","exr","wav","aif","aiff","bwf","flac","mp3","aac","m4a","caf"],N=["aaf","avb","edl","drt","otio","fcpxml","fcpxmld","prproj","ptx","ale","xml","csv"],U=new Set(["xml","csv","png","jpg","jpeg","tif","tiff"]),L=new Set([...I,...N,...U]);var m="conformtools-hook",d=o=>o&&typeof o=="object"&&!Array.isArray(o)?o:{},g=o=>!!o&&typeof o=="object"&&typeof o.command=="string"&&o.command.includes(m);function $(o,e,t={}){let n=d(o.hooks),r=Array.isArray(n.PostToolUse)?[...n.PostToolUse]:[],s={type:"command",command:e,timeout:10,...t.async?{async:!0}:{}};for(let i=0;i<r.length;i++){let a=d(r[i]),l=Array.isArray(a.hooks)?a.hooks:[],f=l.findIndex(g);if(f<0)continue;if(JSON.stringify(l[f])===JSON.stringify(s)&&a.matcher==="Bash")return{settings:o,result:"kept"};let b=[...l];return b[f]=s,r[i]={...a,matcher:"Bash",hooks:b},{settings:{...o,hooks:{...n,PostToolUse:r}},result:"updated"}}return{settings:{...o,hooks:{...n,PostToolUse:[...r,{matcher:"Bash",hooks:[s]}]}},result:"installed"}}function S(o){let e=d(o.hooks);if(!Array.isArray(e.PostToolUse))return{settings:o,removed:!1};let t=!1,n=e.PostToolUse.map(i=>{let a=d(i);if(!Array.isArray(a.hooks))return i;let l=a.hooks.filter(f=>!g(f));return l.length!==a.hooks.length&&(t=!0),l.length?{...a,hooks:l}:null}).filter(i=>i!==null);if(!t)return{settings:o,removed:!1};let r={...e};n.length?r.PostToolUse=n:delete r.PostToolUse;let s={...o};return Object.keys(r).length?s.hooks=r:delete s.hooks,{settings:s,removed:!0}}function T(o,e,t){let n=d(o.hooks),r=Array.isArray(n.afterShellExecution)?[...n.afterShellExecution]:[],s={command:e,timeout:10,matcher:t},i=r.findIndex(g);return i>=0&&JSON.stringify(r[i])===JSON.stringify(s)?{settings:o,result:"kept"}:(i>=0?r[i]=s:r.push(s),{settings:{version:1,...o,hooks:{...n,afterShellExecution:r}},result:i>=0?"updated":"installed"})}function P(o){let e=d(o.hooks);if(!Array.isArray(e.afterShellExecution))return{settings:o,removed:!1};let t=e.afterShellExecution.filter(s=>!g(s));if(t.length===e.afterShellExecution.length)return{settings:o,removed:!1};let n={...e};t.length?n.afterShellExecution=t:delete n.afterShellExecution;let r={...o};return Object.keys(n).length?r.hooks=n:delete r.hooks,{settings:r,removed:!0}}function E(){return`\\b(${[...O].map(e=>e.replace(/[.+-]/g,"\\$&")).join("|")})\\b|\\.(${[...L].join("|")})\\b`}function F(o){let e=(o??"").toLowerCase();return e?e.includes("claude-code")||e.includes("claude code")?"claude":e.includes("codex")?"codex":e.includes("cursor")?"cursor":null:null}var J=["claude","codex","cursor"],p=()=>({claude:c(k(),".claude","settings.json"),codex:c(k(),".codex","hooks.json"),cursor:c(k(),".cursor","hooks.json")});async function M(){let o=new URL(import.meta.url),e=h(new URL("./hook.js",o));if(await u(e)){await w(x());let n=c(x(),`${m}.js`);return await y(e,n),`node "${n}"`}let t=h(new URL("../adapters/hook.ts",o));return await u(t)?`deno run --allow-read --allow-write --allow-env --no-check --unstable-sloppy-imports "${t}" ${m}`:null}async function v(o){if(!await u(o))return{};let e=await C(o);try{return e.trim()?JSON.parse(e):{}}catch{return"invalid"}}async function j(o,e){let t;return await u(o)?(t=`${o}.conformtools-backup`,await y(o,t)):await w(c(o,"..")),await A(o,JSON.stringify(e,null,2)+`
4
+ `),t}async function B(o,e={}){let t=e.file??p()[o];try{let n=e.command??await M();if(!n)return{client:o,file:t,result:"skipped",detail:"no hook script beside this build"};let r=await v(t);if(r==="invalid")return{client:o,file:t,result:"failed",detail:`${t} is not valid JSON; nothing was changed`};let s=o==="cursor"?T(r,n,E()):$(r,n,{async:o==="codex"});if(s.result==="kept")return{client:o,file:t,result:"kept"};let i=await j(t,s.settings);return{client:o,file:t,result:s.result,backup:i}}catch(n){return{client:o,file:t,result:"failed",detail:n instanceof Error?n.message:String(n)}}}async function z(o,e={}){let t=e.file??p()[o],n=await v(t);if(n==="invalid")return{client:o,file:t,removed:!1};let r=o==="cursor"?P(n):S(n);if(!r.removed)return{client:o,file:t,removed:!1};let s=await j(t,r.settings);return{client:o,file:t,removed:!0,backup:s}}async function R(){let o=p(),e=[];for(let t of J)await u(c(o[t],".."))&&e.push(t);return e}var Z=async()=>Promise.all((await R()).map(o=>B(o))),G=async()=>Promise.all((await R()).map(o=>z(o)));async function D(o,e=p()[o]){let t=await v(e);return t!=="invalid"&&JSON.stringify(t).includes(m)}var H={claude:"Claude Code",codex:"Codex",cursor:"Cursor"},_="which other programs the agent ran on media or timeline files (program names and file extensions only; never a command, a path, a name, a prompt or an output)";function q(o){return o.length?o.map(e=>{let t=H[e.client],n={installed:`${t}: agent hook installed in ${e.file}${e.backup?` (backup: ${e.backup})`:""}`,updated:`${t}: agent hook refreshed in ${e.file}`,kept:`${t}: agent hook already in ${e.file}`,skipped:`${t}: agent hook not installed (${e.detail})`,failed:`${t}: agent hook not installed: ${e.detail}`}[e.result];return e.client==="codex"&&(e.result==="installed"||e.result==="updated")?`${n}; Codex asks you to trust it once (/hooks)`:n}).concat(`It records ${_}. conformtools hooks off removes it; conformtools telemetry off removes it with the rest.`).join(`
5
+ `):"Agent hook: no Claude Code, Codex or Cursor folder on this machine; nothing to install."}function Q(o){let e=o.filter(t=>t.removed);return e.length?e.map(t=>`${H[t.client]}: agent hook removed from ${t.file}`).join(`
6
+ `):"Agent hook: not installed anywhere on this machine."}async function V(){let o=await R();return o.length?[...await Promise.all(o.map(async t=>`${H[t]}: agent hook ${await D(t)?"on":"off"} (${p()[t]})`)),`It records ${_}. conformtools hooks on|off.`].join(`
7
+ `):"Agent hook: no Claude Code, Codex or Cursor folder on this machine."}export{F as a,J as b,p as c,M as d,B as e,z as f,R as g,Z as h,G as i,D as j,_ as k,q as l,Q as m,V as n};
@@ -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-764P7TUD.js";import{A as R,C as W,D as I,aa as P,m as _,r as C,x as N,z as O}from"./chunk-XI6XF7FQ.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-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
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
@@ -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{c as r,d as t}from"./chunk-6V4OEOOX.js";import{i as n}from"./chunk-CQSNVQQE.js";async function d(e){if(!r(e.name))return null;try{return await n(t(e),{verb:"inspect"})}catch(i){return console.warn(`[probeMedia] ${e.name} probe failed:`,i),null}}export{d as a};
3
+ import{c as r,d as t}from"./chunk-6V4OEOOX.js";import{i as n}from"./chunk-4RA57LTJ.js";async function d(e){if(!r(e.name))return null;try{return await n(t(e),{verb:"inspect"})}catch(i){return console.warn(`[probeMedia] ${e.name} probe failed:`,i),null}}export{d as a};
@@ -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 Q,d as mt}from"./chunk-OD445COC.js";import{a as j}from"./chunk-PHAMF4JF.js";import{A as P,L as pt,aa as y,m as R,x as S,z as T}from"./chunk-XI6XF7FQ.js";import{createHash as qt}from"node:crypto";import{open as Zt}from"node:fs/promises";var Mt=new Uint16Array(256);for(let e=0;e<256;e++){let t=0,n=e<<8;for(let r=0;r<8;r++)(t^n)&32768?t=t<<1^4129:t=t<<1,n=n<<1;Mt[e]=t&65535}var tt=0,wt=2;var ne=Date.UTC(2020,0,1,0,0,0);function ht(e,t,n,r,o,s,i,a,g,c,u,_,p,w,d,b){let F=z(o,l.__wbindgen_export3,l.__wbindgen_export4),A=x,v=rt(i,l.__wbindgen_export3),W=x,Dt=l.udf_add_file_stream(f(e),f(t),f(n),f(r),F,A,s,v,W,a,g,c,u,_,p,w,d,b);return M(Dt)}function oe(e,t,n,r){let o,s;try{let p=l.__wbindgen_add_to_stack_pointer(-16),w=z(e,l.__wbindgen_export3,l.__wbindgen_export4),d=x,b=z(t,l.__wbindgen_export3,l.__wbindgen_export4),F=x,A=z(n,l.__wbindgen_export3,l.__wbindgen_export4),v=x;l.udf_build_layout(p,w,d,b,F,A,v,r);var i=h().getInt32(p+0,!0),a=h().getInt32(p+4,!0),g=h().getInt32(p+8,!0),c=h().getInt32(p+12,!0),u=i,_=a;if(c)throw u=0,_=0,M(g);return o=u,s=_,C(u,_)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(o,s,1)}}function xt(e,t,n,r,o,s,i){let a=z(o,l.__wbindgen_export3,l.__wbindgen_export4),g=x,c=rt(i,l.__wbindgen_export3),u=x,_=l.udf_fill_sparse_stream(f(e),f(t),f(n),f(r),a,g,s,c,u);return M(_)}function ie(){let e,t;try{let o=l.__wbindgen_add_to_stack_pointer(-16);l.udf_last_panic(o);var n=h().getInt32(o+0,!0),r=h().getInt32(o+4,!0);return e=n,t=r,C(n,r)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(e,t,1)}}function St(e,t){let n=l.udf_parse_stream(f(e),f(t));return M(n)}function se(e){let t,n;try{let s=l.__wbindgen_add_to_stack_pointer(-16),i=rt(e,l.__wbindgen_export3),a=x;l.udf_read_conform_iuvd(s,i,a);var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);return t=r,n=o,C(r,o)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(t,n,1)}}function Lt(){return{__proto__:null,"./udf_bg.js":{__proto__:null,__wbg___wbindgen_is_function_acc5528be2b923f2:function(t){return typeof m(t)=="function"},__wbg___wbindgen_is_undefined_721f8decd50c87a3:function(t){return m(t)===void 0},__wbg___wbindgen_number_get_1cc01dd708740256:function(t,n){let r=m(n),o=typeof r=="number"?r:void 0;h().setFloat64(t+8,O(o)?0:o,!0),h().setInt32(t+0,!O(o),!0)},__wbg___wbindgen_throw_ea4887a5f8f9a9db:function(t,n){throw new Error(C(t,n))},__wbg__wbg_cb_unref_33c39e13d73b25f6:function(t){m(t)._wbg_cb_unref()},__wbg_call_0e855b388e315e17:function(){return et(function(t,n,r,o){let s=m(t).call(m(n),m(r),m(o));return f(s)},arguments)},__wbg_call_5575218572ead796:function(){return et(function(t,n,r){let o=m(t).call(m(n),m(r));return f(o)},arguments)},__wbg_call_8e98ed2f3c86c4b5:function(){return et(function(t,n){let r=m(t).call(m(n));return f(r)},arguments)},__wbg_error_2b5d73c4c4804cfd:function(t,n){console.error(C(t,n))},__wbg_length_589238bdcf171f0e:function(t){return m(t).length},__wbg_new_81880fb5002cb255:function(t){let n=new Uint8Array(m(t));return f(n)},__wbg_new_from_slice_543b875b27789a8f:function(t,n){let r=new Uint8Array(yt(t,n));return f(r)},__wbg_new_no_args_2d7333de60de5ac7:function(t,n){let r=new Function(C(t,n));return f(r)},__wbg_new_typed_00a409eb4ec4f2d9:function(t,n){try{var r={a:t,b:n},o=(i,a)=>{let g=r.a;r.a=0;try{return $t(g,r.b,i,a)}finally{r.a=g}};let s=new Promise(o);return f(s)}finally{r.a=0}},__wbg_prototypesetcall_d721637c7ca66eb8:function(t,n,r){Uint8Array.prototype.set.call(yt(t,n),m(r))},__wbg_queueMicrotask_1c9b3800e321a967:function(t){let n=m(t).queueMicrotask;return f(n)},__wbg_queueMicrotask_311744e534a929a3:function(t){queueMicrotask(m(t))},__wbg_resolve_d82363d90af6928a:function(t){let n=Promise.resolve(m(t));return f(n)},__wbg_static_accessor_GLOBAL_THIS_2fee5048bcca5938:function(){let t=typeof globalThis>"u"?null:globalThis;return O(t)?0:f(t)},__wbg_static_accessor_GLOBAL_ce44e66a4935da8c:function(){let t=typeof global>"u"?null:global;return O(t)?0:f(t)},__wbg_static_accessor_SELF_44f6e0cb5e67cdad:function(){let t=typeof self>"u"?null:self;return O(t)?0:f(t)},__wbg_static_accessor_WINDOW_168f178805d978fe:function(){let t=typeof window>"u"?null:window;return O(t)?0:f(t)},__wbg_then_05edfc8a4fea5106:function(t,n,r){let o=m(t).then(m(n),m(r));return f(o)},__wbg_then_591b6b3a75ee817a:function(t,n){let r=m(t).then(m(n));return f(r)},__wbindgen_cast_0000000000000001:function(t,n){let r=zt(t,n,jt);return f(r)},__wbindgen_cast_0000000000000002:function(t){return f(t)},__wbindgen_cast_0000000000000003:function(t,n){let r=C(t,n);return f(r)},__wbindgen_object_clone_ref:function(t){let n=m(t);return f(n)},__wbindgen_object_drop_ref:function(t){M(t)}}}}function jt(e,t,n){try{let s=l.__wbindgen_add_to_stack_pointer(-16);l.__wasm_bindgen_func_elem_252(s,e,t,f(n));var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);if(o)throw M(r)}finally{l.__wbindgen_add_to_stack_pointer(16)}}function $t(e,t,n,r){l.__wasm_bindgen_func_elem_266(e,t,f(n),f(r))}function f(e){N===E.length&&E.push(E.length+1);let t=N;return N=E[t],E[t]=e,t}var bt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>l.__wbindgen_export2(e.a,e.b));function Nt(e){e<1028||(E[e]=N,N=e)}function yt(e,t){return e=e>>>0,D().subarray(e/1,e/1+t)}var U=null;function h(){return(U===null||U.buffer.detached===!0||U.buffer.detached===void 0&&U.buffer!==l.memory.buffer)&&(U=new DataView(l.memory.buffer)),U}function C(e,t){return Wt(e>>>0,t)}var $=null;function D(){return($===null||$.byteLength===0)&&($=new Uint8Array(l.memory.buffer)),$}function m(e){return E[e]}function et(e,t){try{return e.apply(this,t)}catch(n){l.__wbindgen_export(f(n))}}var E=new Array(1024).fill(void 0);E.push(void 0,null,!0,!1);var N=E.length;function O(e){return e==null}function zt(e,t,n){let r={a:e,b:t,cnt:1},o=(...s)=>{r.cnt++;let i=r.a;r.a=0;try{return n(i,r.b,...s)}finally{r.a=i,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--r.cnt===0&&(l.__wbindgen_export2(r.a,r.b),r.a=0,bt.unregister(r))},bt.register(o,r,r),o}function rt(e,t){let n=t(e.length*1,1)>>>0;return D().set(e,n/1),x=e.length,n}function z(e,t,n){if(n===void 0){let a=B.encode(e),g=t(a.length,1)>>>0;return D().subarray(g,g+a.length).set(a),x=a.length,g}let r=e.length,o=t(r,1)>>>0,s=D(),i=0;for(;i<r;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(e=e.slice(i)),o=n(o,r,r=i+e.length*3,1)>>>0;let a=D().subarray(o+i,o+r),g=B.encodeInto(e,a);i+=g.written,o=n(o,r,i,1)>>>0}return x=i,o}function M(e){let t=m(e);return Nt(e),t}var H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});H.decode();var Bt=2146435072,nt=0;function Wt(e,t){return nt+=t,nt>=Bt&&(H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),H.decode(),nt=t),H.decode(D().subarray(e,e+t))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(e,t){let n=B.encode(e);return t.set(n),{read:e.length,written:n.length}});var x=0,Ht,Gt,l;function Jt(e,t){return Gt=e,l=e.exports,Ht=t,U=null,$=null,l.__wbindgen_start(),l}async function Vt(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(o){if(e.ok&&n(e.type)&&e.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}function n(r){switch(r){case"basic":case"cors":case"default":return!0}return!1}}async function G(e){if(l!==void 0)return l;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),e===void 0&&(e=new URL("udf_bg.wasm",import.meta.url));let t=Lt();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Vt(await e,t);return Jt(n,r)}var ot=null;function Xt(e){return ot||(ot=(async()=>{if(e!==void 0)return G(e);if(typeof process<"u"&&process.versions?.node){let n="node:fs/promises",{readFile:r}=await import(n),o=await r(new URL("./wasm/udf_bg.wasm",import.meta.url));return G({module_or_path:o})}let{default:t}=await import("./udf_bg-B37GKRIH.js");return G({module_or_path:t})})()),ot}function J(){return Xt()}function V(e){return(t,n)=>e.read(t,n)}function it(e){return(t,n)=>e.write(t,n)}function X(e){return()=>e.getSize()}function st(e){return t=>e.setSize?e.setSize(t):Promise.resolve()}async function It(e){await J();let t=JSON.parse(await St(V(e),X(e)));if(t.error)throw new Error(t.error);let n=null;if(t.iuvdPayload)try{n=JSON.parse(t.iuvdPayload)}catch{}let r=null,o=t.files.find(s=>s.name===".i2o-manifest.json");if(o&&o.extents.length>0&&o.extents[0].type===tt){let s=o.extents[0].position,i=await e.read((t.partitionStartSector+s)*2048,o.totalSize);try{r=JSON.parse(new TextDecoder().decode(i))}catch{}}return{totalSectors:t.totalSectors,partitionStartSector:t.partitionStartSector,partitionLength:t.partitionLength,volumeName:t.volumeName,files:t.files,manifest:r,iuvdPayload:n,rootIcbSector:t.rootIcbSector,rootDataSector:t.rootDataSector,rootDataLength:t.rootDataLength,rootDataSectors:t.rootDataSectors,vdsStartSector:t.vdsStartSector,partitionDescVdsSector:t.partitionDescVdsSector}}function me(e){let t=[],n=0;for(let r of e.extents)r.type===wt&&t.push({offset:n,length:r.length}),n+=r.length;return t}function At(e){let t=[],n=0;for(let r of e.extents)r.type===tt&&t.push({offset:n,length:r.length,imageSector:r.position}),n+=r.length;return t}async function we(e,t,n,r,o){return await J(),await xt(V(e),it(e),X(e),st(e),n,r,o),It(e)}async function be(e,t,n,r,o,s=0){await J();let i=new Date,a=!!(o&&o.length>0);return await ht(V(e),it(e),X(e),st(e),n,r,a?o:new Uint8Array(0),a,s,i.getFullYear(),i.getMonth()+1,i.getDate(),i.getHours(),i.getMinutes(),i.getSeconds(),-i.getTimezoneOffset()),It(e)}var Y=1<<20,k=5*Y,Et=5*1024*Y,at=1e4,ct=8*Y,Kt=2048;function Ae(e,t,n=Math.max(16*Y,Math.ceil(e/(at-500)))){let r=[...t].filter(c=>c.len>0).sort((c,u)=>c.at-u.at),o=[];for(let c of r){let u=o[o.length-1];u&&c.at<u.at+u.len||(u&&u.at+u.len===c.at&&u.key===c.key&&u.offset+u.len===c.offset?u.len+=c.len:o.push({...c}))}let s=[],i=0;for(let c of o.filter(u=>u.len>=k))c.at>i&&s.push({at:i,len:c.at-i}),s.push({at:c.at,len:c.len,copy:c}),i=c.at+c.len;i<e&&s.push({at:i,len:e-i});let a=c=>c.reduce((u,_)=>{let p=u[u.length-1];return p&&!p.copy&&!_.copy?p.len+=_.len:u.push({..._}),u},[]);for(let c=!0;c;){c=!1,s=a(s);for(let u=0;u<s.length-1;u++){let _=s[u];if(_.len>=k)continue;let p=k-_.len,w=s[u+1],d=s[u-1];if(_.copy){delete _.copy,c=!0;break}w?.copy&&w.len-p>=k?(_.len+=p,w.at+=p,w.len-=p,w.copy={...w.copy,at:w.at,len:w.len,offset:w.copy.offset+p}):d?.copy&&d.len-p>=k?(d.len-=p,d.copy={...d.copy,len:d.len},_.at-=p,_.len+=p):w?.copy?delete w.copy:d?.copy&&delete d.copy,c=!0;break}}let g=[];for(let c of s){let u=c.copy?Math.min(Et,Math.max(n,k)):n;for(let _=c.at,p=c.at+c.len;_<p;){let w=Math.min(u,p-_);p-(_+w)>0&&p-(_+w)<k&&(w=p-_<=Et?p-_:w-k),g.push(c.copy?{kind:"copy",at:_,len:w,key:c.copy.key,offset:c.copy.offset+(_-c.at)}:{kind:"upload",at:_,len:w}),_+=w}}if(g.length>at)throw new Error(`the image needs ${g.length} pieces (S3 allows ${at})`);return g}function Ee(e,t,n,r){let o=[...r].sort((a,g)=>a.offset-g.offset),s=[],i=0;for(let a of o){let g=Math.min(a.offset,t);g>i&&s.push({at:i,len:g-i,key:e,offset:i}),i=Math.max(i,a.offset+a.length)}return i<Math.min(t,n)&&s.push({at:i,len:Math.min(t,n)-i,key:e,offset:i}),s}async function ve(e,t,n,r,o){let s=[];for(let i of t.files)for(let a of At(i)){let g=(t.partitionStartSector+a.imageSector)*Kt;for(let c=a.offset;c<a.offset+a.length;){let u=Math.min(a.offset+a.length,(Math.floor(c/ct)+1)*ct),_=g+(c-a.offset);s.push(o?.(_,u-c)??[qt("sha256").update(await e.read(_,u-c)).digest("hex"),_,u-c]),r?.(u-c),c=u}}return{v:1,block:ct,size:n,blocks:s}}function Te(e,t){let n=new Map;for(let o of t)for(let[s,i,a]of o.index.blocks)n.set(`${s}:${a}`,{key:o.key,offset:i});let r=[];for(let[o,s,i]of e.blocks){let a=n.get(`${o}:${i}`);a&&r.push({at:s,len:i,key:a.key,offset:a.offset})}return r}var vt=(e,t)=>`${Q().supabaseUrl}/functions/v1/${e}${t}`;async function lt(e,t,n={}){let r=await mt();if(!r)throw new Error("not signed in to conform.tools \u2014 run account_login");let o=await fetch(vt(e,t),{method:n.method??(n.body?"POST":"GET"),headers:{authorization:`Bearer ${r}`,apikey:Q().anonKey,...n.body?{"content-type":"application/json"}:{}},...n.body?{body:JSON.stringify(n.body)}:{},signal:AbortSignal.timeout(2e4)}),s=await o.text();if(!o.ok){let i=s;try{let a=JSON.parse(s);i=a.error?.message??a.message??a.error??s}catch{}throw o.status===404&&/Requested function was not found/i.test(String(i))?new Error(`${e} isn't deployed on ${new URL(vt(e,t)).host}: this server doesn't have that feature yet (an older server, or a staging/production mismatch)`):new Error(`${n.method??"GET"} ${t}: ${o.status} ${i}`)}return s?JSON.parse(s):{}}function Pe(e,t="org"){let n=`/v1/sessions/${e}/storage/multipart`,r=(o,s,i)=>lt("v1-sessions",o,{body:s,method:i});return{start:async o=>String((await r(`${n}/start`,{key:o,content_type:"application/x-iso9660-image"})).upload_id),partUrls:async(o,s,i,a)=>(await r(`${n}/${s}/part-urls`,{key:o,first_part:i,count:a})).parts,copyPart:async(o,s,i,a)=>String((await r(`${n}/${s}/copy-part`,{key:o,part_number:i,source_ref:{scheme:t,bucket:"i2o",key:a.key},byte_range:{offset:a.offset,length:a.length}})).etag),complete:async(o,s,i)=>{await r(`${n}/${s}/complete`,{key:o,parts:i})},abort:async(o,s)=>{await r(`${n}/${encodeURIComponent(s)}?key=${encodeURIComponent(o)}`,void 0,"DELETE")},readUrl:async o=>String((await r(`/v1/sessions/${e}/download-url`,{storage_path:o})).download_url)}}async function ut(e,t,n=4){for(let r=1;;r++)try{return await t()}catch(o){if(r>=n)throw new Error(`${e} failed after ${n} tries: ${o instanceof Error?o.message:o}`);await new Promise(s=>setTimeout(s,500*2**r))}}async function ke(e,t,n,r,o={}){let s=o.fetchFn??fetch,i=await e.start(t),a=n.reduce((d,b)=>d+b.len,0),g=new Array(n.length),c=0,u=0,_=new Map,p=async d=>(_.has(d)||(await e.partUrls(t,i,d+1,Math.min(100,n.length-d))).forEach((F,A)=>_.set(d+A,F)),_.get(d)),w=async d=>{let b=n[d];if(b.kind==="copy")g[d]=await ut(`copy piece ${d+1}`,()=>e.copyPart(t,i,d+1,{key:b.key,offset:b.offset,length:b.len}));else{let F=await r(b.at,b.len);g[d]=await ut(`upload piece ${d+1}`,async()=>{let A=await p(d),v=await s(A.upload_url,{method:A.method,headers:A.headers,body:F,signal:o.signal});if(!v.ok)throw _.delete(d),new Error(`${v.status} ${(await v.text()).slice(0,200)}`);let W=v.headers.get("etag");if(!W)throw new Error("the bucket returned no ETag (expose it in the bucket's CORS / response headers)");return W})}c+=b.len,o.onProgress?.(c,a)};try{await Promise.all(Array.from({length:Math.min(6,n.length)},async()=>{for(;u<n.length;)o.signal?.throwIfAborted(),await w(u++)})),await ut("complete",()=>e.complete(t,i,g.map((d,b)=>({part_number:b+1,etag:d}))))}catch(d){throw await e.abort(t,i).catch(()=>{}),d}return{uploaded:n.filter(d=>d.kind==="upload").reduce((d,b)=>d+b.len,0),copied:n.filter(d=>d.kind==="copy").reduce((d,b)=>d+b.len,0),pieces:n.length}}function Fe(e){let t=Zt(e,"r");return{read:async(n,r)=>{let o=new Uint8Array(r);return await(await t).read(o,0,r,n),o},close:async()=>{await(await t).close()}}}var gt="local",Pt=/^[A-Za-z0-9_-]{1,64}$/,I=e=>{if(!Pt.test(e))throw new j("invalid_args",`bad project_id '${e}'`);return y(R(),"projects",e)},dt=(e,t={})=>lt("v1-projects",e,t),kt=e=>Number(/: (\d{3}) /.exec(String(e?.message))?.[1]??0);async function Ft(e){let t="",n={base:null,by:null};try{t=await S(y(I(e),"CONTEXT.md"))}catch{}try{n=JSON.parse(await S(y(I(e),"context.json")))}catch{}return{text:t,meta:n}}async function _t(e,t,n){await P(I(e)),await T(y(I(e),"CONTEXT.md"),t),await T(y(I(e),"context.json"),JSON.stringify(n))}var ft=async(e,t)=>(await _t(e,t.context,{base:t.context_updated_at,by:t.context_updated_by_name??null}),{text:t.context,updated_at:t.context_updated_at,updated_by:t.context_updated_by_name??null});async function Me(e){I(e);let t=await Ft(e);if(e===gt)return{text:t.text,updated_at:null,updated_by:null};if(t.meta.pending)try{return await Tt(e,t.text,t.meta.base)}catch(n){if(!(n instanceof j&&n.code==="context_conflict"))return{text:t.text,updated_at:t.meta.base,updated_by:t.meta.by,offline:!0,pending:!0};let r=n.data?.current??{context:"",context_updated_at:null},o=`${r.context.trimEnd()}
3
+ import{a as Q,e as mt}from"./chunk-OWWXUNJF.js";import{a as j}from"./chunk-ROGMKTND.js";import{A as T,B as P,M as pt,ba as y,n as R,y as S}from"./chunk-X527E5VI.js";import{createHash as qt}from"node:crypto";import{open as Zt}from"node:fs/promises";var Mt=new Uint16Array(256);for(let e=0;e<256;e++){let t=0,n=e<<8;for(let r=0;r<8;r++)(t^n)&32768?t=t<<1^4129:t=t<<1,n=n<<1;Mt[e]=t&65535}var tt=0,wt=2;var ne=Date.UTC(2020,0,1,0,0,0);function ht(e,t,n,r,o,s,i,a,g,c,u,_,p,w,d,b){let F=z(o,l.__wbindgen_export3,l.__wbindgen_export4),A=x,v=rt(i,l.__wbindgen_export3),W=x,Dt=l.udf_add_file_stream(f(e),f(t),f(n),f(r),F,A,s,v,W,a,g,c,u,_,p,w,d,b);return M(Dt)}function oe(e,t,n,r){let o,s;try{let p=l.__wbindgen_add_to_stack_pointer(-16),w=z(e,l.__wbindgen_export3,l.__wbindgen_export4),d=x,b=z(t,l.__wbindgen_export3,l.__wbindgen_export4),F=x,A=z(n,l.__wbindgen_export3,l.__wbindgen_export4),v=x;l.udf_build_layout(p,w,d,b,F,A,v,r);var i=h().getInt32(p+0,!0),a=h().getInt32(p+4,!0),g=h().getInt32(p+8,!0),c=h().getInt32(p+12,!0),u=i,_=a;if(c)throw u=0,_=0,M(g);return o=u,s=_,C(u,_)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(o,s,1)}}function xt(e,t,n,r,o,s,i){let a=z(o,l.__wbindgen_export3,l.__wbindgen_export4),g=x,c=rt(i,l.__wbindgen_export3),u=x,_=l.udf_fill_sparse_stream(f(e),f(t),f(n),f(r),a,g,s,c,u);return M(_)}function ie(){let e,t;try{let o=l.__wbindgen_add_to_stack_pointer(-16);l.udf_last_panic(o);var n=h().getInt32(o+0,!0),r=h().getInt32(o+4,!0);return e=n,t=r,C(n,r)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(e,t,1)}}function St(e,t){let n=l.udf_parse_stream(f(e),f(t));return M(n)}function se(e){let t,n;try{let s=l.__wbindgen_add_to_stack_pointer(-16),i=rt(e,l.__wbindgen_export3),a=x;l.udf_read_conform_iuvd(s,i,a);var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);return t=r,n=o,C(r,o)}finally{l.__wbindgen_add_to_stack_pointer(16),l.__wbindgen_export5(t,n,1)}}function Lt(){return{__proto__:null,"./udf_bg.js":{__proto__:null,__wbg___wbindgen_is_function_acc5528be2b923f2:function(t){return typeof m(t)=="function"},__wbg___wbindgen_is_undefined_721f8decd50c87a3:function(t){return m(t)===void 0},__wbg___wbindgen_number_get_1cc01dd708740256:function(t,n){let r=m(n),o=typeof r=="number"?r:void 0;h().setFloat64(t+8,O(o)?0:o,!0),h().setInt32(t+0,!O(o),!0)},__wbg___wbindgen_throw_ea4887a5f8f9a9db:function(t,n){throw new Error(C(t,n))},__wbg__wbg_cb_unref_33c39e13d73b25f6:function(t){m(t)._wbg_cb_unref()},__wbg_call_0e855b388e315e17:function(){return et(function(t,n,r,o){let s=m(t).call(m(n),m(r),m(o));return f(s)},arguments)},__wbg_call_5575218572ead796:function(){return et(function(t,n,r){let o=m(t).call(m(n),m(r));return f(o)},arguments)},__wbg_call_8e98ed2f3c86c4b5:function(){return et(function(t,n){let r=m(t).call(m(n));return f(r)},arguments)},__wbg_error_2b5d73c4c4804cfd:function(t,n){console.error(C(t,n))},__wbg_length_589238bdcf171f0e:function(t){return m(t).length},__wbg_new_81880fb5002cb255:function(t){let n=new Uint8Array(m(t));return f(n)},__wbg_new_from_slice_543b875b27789a8f:function(t,n){let r=new Uint8Array(yt(t,n));return f(r)},__wbg_new_no_args_2d7333de60de5ac7:function(t,n){let r=new Function(C(t,n));return f(r)},__wbg_new_typed_00a409eb4ec4f2d9:function(t,n){try{var r={a:t,b:n},o=(i,a)=>{let g=r.a;r.a=0;try{return $t(g,r.b,i,a)}finally{r.a=g}};let s=new Promise(o);return f(s)}finally{r.a=0}},__wbg_prototypesetcall_d721637c7ca66eb8:function(t,n,r){Uint8Array.prototype.set.call(yt(t,n),m(r))},__wbg_queueMicrotask_1c9b3800e321a967:function(t){let n=m(t).queueMicrotask;return f(n)},__wbg_queueMicrotask_311744e534a929a3:function(t){queueMicrotask(m(t))},__wbg_resolve_d82363d90af6928a:function(t){let n=Promise.resolve(m(t));return f(n)},__wbg_static_accessor_GLOBAL_THIS_2fee5048bcca5938:function(){let t=typeof globalThis>"u"?null:globalThis;return O(t)?0:f(t)},__wbg_static_accessor_GLOBAL_ce44e66a4935da8c:function(){let t=typeof global>"u"?null:global;return O(t)?0:f(t)},__wbg_static_accessor_SELF_44f6e0cb5e67cdad:function(){let t=typeof self>"u"?null:self;return O(t)?0:f(t)},__wbg_static_accessor_WINDOW_168f178805d978fe:function(){let t=typeof window>"u"?null:window;return O(t)?0:f(t)},__wbg_then_05edfc8a4fea5106:function(t,n,r){let o=m(t).then(m(n),m(r));return f(o)},__wbg_then_591b6b3a75ee817a:function(t,n){let r=m(t).then(m(n));return f(r)},__wbindgen_cast_0000000000000001:function(t,n){let r=zt(t,n,jt);return f(r)},__wbindgen_cast_0000000000000002:function(t){return f(t)},__wbindgen_cast_0000000000000003:function(t,n){let r=C(t,n);return f(r)},__wbindgen_object_clone_ref:function(t){let n=m(t);return f(n)},__wbindgen_object_drop_ref:function(t){M(t)}}}}function jt(e,t,n){try{let s=l.__wbindgen_add_to_stack_pointer(-16);l.__wasm_bindgen_func_elem_268(s,e,t,f(n));var r=h().getInt32(s+0,!0),o=h().getInt32(s+4,!0);if(o)throw M(r)}finally{l.__wbindgen_add_to_stack_pointer(16)}}function $t(e,t,n,r){l.__wasm_bindgen_func_elem_282(e,t,f(n),f(r))}function f(e){N===E.length&&E.push(E.length+1);let t=N;return N=E[t],E[t]=e,t}var bt=typeof FinalizationRegistry>"u"?{register:()=>{},unregister:()=>{}}:new FinalizationRegistry(e=>l.__wbindgen_export2(e.a,e.b));function Nt(e){e<1028||(E[e]=N,N=e)}function yt(e,t){return e=e>>>0,D().subarray(e/1,e/1+t)}var U=null;function h(){return(U===null||U.buffer.detached===!0||U.buffer.detached===void 0&&U.buffer!==l.memory.buffer)&&(U=new DataView(l.memory.buffer)),U}function C(e,t){return Wt(e>>>0,t)}var $=null;function D(){return($===null||$.byteLength===0)&&($=new Uint8Array(l.memory.buffer)),$}function m(e){return E[e]}function et(e,t){try{return e.apply(this,t)}catch(n){l.__wbindgen_export(f(n))}}var E=new Array(1024).fill(void 0);E.push(void 0,null,!0,!1);var N=E.length;function O(e){return e==null}function zt(e,t,n){let r={a:e,b:t,cnt:1},o=(...s)=>{r.cnt++;let i=r.a;r.a=0;try{return n(i,r.b,...s)}finally{r.a=i,o._wbg_cb_unref()}};return o._wbg_cb_unref=()=>{--r.cnt===0&&(l.__wbindgen_export2(r.a,r.b),r.a=0,bt.unregister(r))},bt.register(o,r,r),o}function rt(e,t){let n=t(e.length*1,1)>>>0;return D().set(e,n/1),x=e.length,n}function z(e,t,n){if(n===void 0){let a=B.encode(e),g=t(a.length,1)>>>0;return D().subarray(g,g+a.length).set(a),x=a.length,g}let r=e.length,o=t(r,1)>>>0,s=D(),i=0;for(;i<r;i++){let a=e.charCodeAt(i);if(a>127)break;s[o+i]=a}if(i!==r){i!==0&&(e=e.slice(i)),o=n(o,r,r=i+e.length*3,1)>>>0;let a=D().subarray(o+i,o+r),g=B.encodeInto(e,a);i+=g.written,o=n(o,r,i,1)>>>0}return x=i,o}function M(e){let t=m(e);return Nt(e),t}var H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0});H.decode();var Bt=2146435072,nt=0;function Wt(e,t){return nt+=t,nt>=Bt&&(H=new TextDecoder("utf-8",{ignoreBOM:!0,fatal:!0}),H.decode(),nt=t),H.decode(D().subarray(e,e+t))}var B=new TextEncoder;"encodeInto"in B||(B.encodeInto=function(e,t){let n=B.encode(e);return t.set(n),{read:e.length,written:n.length}});var x=0,Ht,Gt,l;function Jt(e,t){return Gt=e,l=e.exports,Ht=t,U=null,$=null,l.__wbindgen_start(),l}async function Vt(e,t){if(typeof Response=="function"&&e instanceof Response){if(typeof WebAssembly.instantiateStreaming=="function")try{return await WebAssembly.instantiateStreaming(e,t)}catch(o){if(e.ok&&n(e.type)&&e.headers.get("Content-Type")!=="application/wasm")console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n",o);else throw o}let r=await e.arrayBuffer();return await WebAssembly.instantiate(r,t)}else{let r=await WebAssembly.instantiate(e,t);return r instanceof WebAssembly.Instance?{instance:r,module:e}:r}function n(r){switch(r){case"basic":case"cors":case"default":return!0}return!1}}async function G(e){if(l!==void 0)return l;e!==void 0&&(Object.getPrototypeOf(e)===Object.prototype?{module_or_path:e}=e:console.warn("using deprecated parameters for the initialization function; pass a single object instead")),e===void 0&&(e=new URL("udf_bg.wasm",import.meta.url));let t=Lt();(typeof e=="string"||typeof Request=="function"&&e instanceof Request||typeof URL=="function"&&e instanceof URL)&&(e=fetch(e));let{instance:n,module:r}=await Vt(await e,t);return Jt(n,r)}var ot=null;function Xt(e){return ot||(ot=(async()=>{if(e!==void 0)return G(e);if(typeof process<"u"&&process.versions?.node){let n="node:fs/promises",{readFile:r}=await import(n),o=await r(new URL("./wasm/udf_bg.wasm",import.meta.url));return G({module_or_path:o})}let{default:t}=await import("./udf_bg-B37GKRIH.js");return G({module_or_path:t})})()),ot}function J(){return Xt()}function V(e){return(t,n)=>e.read(t,n)}function it(e){return(t,n)=>e.write(t,n)}function X(e){return()=>e.getSize()}function st(e){return t=>e.setSize?e.setSize(t):Promise.resolve()}async function It(e){await J();let t=JSON.parse(await St(V(e),X(e)));if(t.error)throw new Error(t.error);let n=null;if(t.iuvdPayload)try{n=JSON.parse(t.iuvdPayload)}catch{}let r=null,o=t.files.find(s=>s.name===".i2o-manifest.json");if(o&&o.extents.length>0&&o.extents[0].type===tt){let s=o.extents[0].position,i=await e.read((t.partitionStartSector+s)*2048,o.totalSize);try{r=JSON.parse(new TextDecoder().decode(i))}catch{}}return{totalSectors:t.totalSectors,partitionStartSector:t.partitionStartSector,partitionLength:t.partitionLength,volumeName:t.volumeName,files:t.files,manifest:r,iuvdPayload:n,rootIcbSector:t.rootIcbSector,rootDataSector:t.rootDataSector,rootDataLength:t.rootDataLength,rootDataSectors:t.rootDataSectors,vdsStartSector:t.vdsStartSector,partitionDescVdsSector:t.partitionDescVdsSector}}function me(e){let t=[],n=0;for(let r of e.extents)r.type===wt&&t.push({offset:n,length:r.length}),n+=r.length;return t}function At(e){let t=[],n=0;for(let r of e.extents)r.type===tt&&t.push({offset:n,length:r.length,imageSector:r.position}),n+=r.length;return t}async function we(e,t,n,r,o){return await J(),await xt(V(e),it(e),X(e),st(e),n,r,o),It(e)}async function be(e,t,n,r,o,s=0){await J();let i=new Date,a=!!(o&&o.length>0);return await ht(V(e),it(e),X(e),st(e),n,r,a?o:new Uint8Array(0),a,s,i.getFullYear(),i.getMonth()+1,i.getDate(),i.getHours(),i.getMinutes(),i.getSeconds(),-i.getTimezoneOffset()),It(e)}var Y=1<<20,k=5*Y,Et=5*1024*Y,at=1e4,ct=8*Y,Kt=2048;function Ae(e,t,n=Math.max(16*Y,Math.ceil(e/(at-500)))){let r=[...t].filter(c=>c.len>0).sort((c,u)=>c.at-u.at),o=[];for(let c of r){let u=o[o.length-1];u&&c.at<u.at+u.len||(u&&u.at+u.len===c.at&&u.key===c.key&&u.offset+u.len===c.offset?u.len+=c.len:o.push({...c}))}let s=[],i=0;for(let c of o.filter(u=>u.len>=k))c.at>i&&s.push({at:i,len:c.at-i}),s.push({at:c.at,len:c.len,copy:c}),i=c.at+c.len;i<e&&s.push({at:i,len:e-i});let a=c=>c.reduce((u,_)=>{let p=u[u.length-1];return p&&!p.copy&&!_.copy?p.len+=_.len:u.push({..._}),u},[]);for(let c=!0;c;){c=!1,s=a(s);for(let u=0;u<s.length-1;u++){let _=s[u];if(_.len>=k)continue;let p=k-_.len,w=s[u+1],d=s[u-1];if(_.copy){delete _.copy,c=!0;break}w?.copy&&w.len-p>=k?(_.len+=p,w.at+=p,w.len-=p,w.copy={...w.copy,at:w.at,len:w.len,offset:w.copy.offset+p}):d?.copy&&d.len-p>=k?(d.len-=p,d.copy={...d.copy,len:d.len},_.at-=p,_.len+=p):w?.copy?delete w.copy:d?.copy&&delete d.copy,c=!0;break}}let g=[];for(let c of s){let u=c.copy?Math.min(Et,Math.max(n,k)):n;for(let _=c.at,p=c.at+c.len;_<p;){let w=Math.min(u,p-_);p-(_+w)>0&&p-(_+w)<k&&(w=p-_<=Et?p-_:w-k),g.push(c.copy?{kind:"copy",at:_,len:w,key:c.copy.key,offset:c.copy.offset+(_-c.at)}:{kind:"upload",at:_,len:w}),_+=w}}if(g.length>at)throw new Error(`the image needs ${g.length} pieces (S3 allows ${at})`);return g}function Ee(e,t,n,r){let o=[...r].sort((a,g)=>a.offset-g.offset),s=[],i=0;for(let a of o){let g=Math.min(a.offset,t);g>i&&s.push({at:i,len:g-i,key:e,offset:i}),i=Math.max(i,a.offset+a.length)}return i<Math.min(t,n)&&s.push({at:i,len:Math.min(t,n)-i,key:e,offset:i}),s}async function ve(e,t,n,r,o){let s=[];for(let i of t.files)for(let a of At(i)){let g=(t.partitionStartSector+a.imageSector)*Kt;for(let c=a.offset;c<a.offset+a.length;){let u=Math.min(a.offset+a.length,(Math.floor(c/ct)+1)*ct),_=g+(c-a.offset);s.push(o?.(_,u-c)??[qt("sha256").update(await e.read(_,u-c)).digest("hex"),_,u-c]),r?.(u-c),c=u}}return{v:1,block:ct,size:n,blocks:s}}function Te(e,t){let n=new Map;for(let o of t)for(let[s,i,a]of o.index.blocks)n.set(`${s}:${a}`,{key:o.key,offset:i});let r=[];for(let[o,s,i]of e.blocks){let a=n.get(`${o}:${i}`);a&&r.push({at:s,len:i,key:a.key,offset:a.offset})}return r}var vt=(e,t)=>`${Q().supabaseUrl}/functions/v1/${e}${t}`;async function lt(e,t,n={}){let r=await mt();if(!r)throw new Error("not signed in to conform.tools \u2014 run account_login");let o=await fetch(vt(e,t),{method:n.method??(n.body?"POST":"GET"),headers:{authorization:`Bearer ${r}`,apikey:Q().anonKey,...n.body?{"content-type":"application/json"}:{}},...n.body?{body:JSON.stringify(n.body)}:{},signal:AbortSignal.timeout(2e4)}),s=await o.text();if(!o.ok){let i=s;try{let a=JSON.parse(s);i=a.error?.message??a.message??a.error??s}catch{}throw o.status===404&&/Requested function was not found/i.test(String(i))?new Error(`${e} isn't deployed on ${new URL(vt(e,t)).host}: this server doesn't have that feature yet (an older server, or a staging/production mismatch)`):new Error(`${n.method??"GET"} ${t}: ${o.status} ${i}`)}return s?JSON.parse(s):{}}function Pe(e,t="org"){let n=`/v1/sessions/${e}/storage/multipart`,r=(o,s,i)=>lt("v1-sessions",o,{body:s,method:i});return{start:async o=>String((await r(`${n}/start`,{key:o,content_type:"application/x-iso9660-image"})).upload_id),partUrls:async(o,s,i,a)=>(await r(`${n}/${s}/part-urls`,{key:o,first_part:i,count:a})).parts,copyPart:async(o,s,i,a)=>String((await r(`${n}/${s}/copy-part`,{key:o,part_number:i,source_ref:{scheme:t,bucket:"i2o",key:a.key},byte_range:{offset:a.offset,length:a.length}})).etag),complete:async(o,s,i)=>{await r(`${n}/${s}/complete`,{key:o,parts:i})},abort:async(o,s)=>{await r(`${n}/${encodeURIComponent(s)}?key=${encodeURIComponent(o)}`,void 0,"DELETE")},readUrl:async o=>String((await r(`/v1/sessions/${e}/download-url`,{storage_path:o})).download_url)}}async function ut(e,t,n=4){for(let r=1;;r++)try{return await t()}catch(o){if(r>=n)throw new Error(`${e} failed after ${n} tries: ${o instanceof Error?o.message:o}`);await new Promise(s=>setTimeout(s,500*2**r))}}async function ke(e,t,n,r,o={}){let s=o.fetchFn??fetch,i=await e.start(t),a=n.reduce((d,b)=>d+b.len,0),g=new Array(n.length),c=0,u=0,_=new Map,p=async d=>(_.has(d)||(await e.partUrls(t,i,d+1,Math.min(100,n.length-d))).forEach((F,A)=>_.set(d+A,F)),_.get(d)),w=async d=>{let b=n[d];if(b.kind==="copy")g[d]=await ut(`copy piece ${d+1}`,()=>e.copyPart(t,i,d+1,{key:b.key,offset:b.offset,length:b.len}));else{let F=await r(b.at,b.len);g[d]=await ut(`upload piece ${d+1}`,async()=>{let A=await p(d),v=await s(A.upload_url,{method:A.method,headers:A.headers,body:F,signal:o.signal});if(!v.ok)throw _.delete(d),new Error(`${v.status} ${(await v.text()).slice(0,200)}`);let W=v.headers.get("etag");if(!W)throw new Error("the bucket returned no ETag (expose it in the bucket's CORS / response headers)");return W})}c+=b.len,o.onProgress?.(c,a)};try{await Promise.all(Array.from({length:Math.min(6,n.length)},async()=>{for(;u<n.length;)o.signal?.throwIfAborted(),await w(u++)})),await ut("complete",()=>e.complete(t,i,g.map((d,b)=>({part_number:b+1,etag:d}))))}catch(d){throw await e.abort(t,i).catch(()=>{}),d}return{uploaded:n.filter(d=>d.kind==="upload").reduce((d,b)=>d+b.len,0),copied:n.filter(d=>d.kind==="copy").reduce((d,b)=>d+b.len,0),pieces:n.length}}function Fe(e){let t=Zt(e,"r");return{read:async(n,r)=>{let o=new Uint8Array(r);return await(await t).read(o,0,r,n),o},close:async()=>{await(await t).close()}}}var gt="local",Pt=/^[A-Za-z0-9_-]{1,64}$/,I=e=>{if(!Pt.test(e))throw new j("invalid_args",`bad project_id '${e}'`);return y(R(),"projects",e)},dt=(e,t={})=>lt("v1-projects",e,t),kt=e=>Number(/: (\d{3}) /.exec(String(e?.message))?.[1]??0);async function Ft(e){let t="",n={base:null,by:null};try{t=await S(y(I(e),"CONTEXT.md"))}catch{}try{n=JSON.parse(await S(y(I(e),"context.json")))}catch{}return{text:t,meta:n}}async function _t(e,t,n){await P(I(e)),await T(y(I(e),"CONTEXT.md"),t),await T(y(I(e),"context.json"),JSON.stringify(n))}var ft=async(e,t)=>(await _t(e,t.context,{base:t.context_updated_at,by:t.context_updated_by_name??null}),{text:t.context,updated_at:t.context_updated_at,updated_by:t.context_updated_by_name??null});async function Me(e){I(e);let t=await Ft(e);if(e===gt)return{text:t.text,updated_at:null,updated_by:null};if(t.meta.pending)try{return await Tt(e,t.text,t.meta.base)}catch(n){if(!(n instanceof j&&n.code==="context_conflict"))return{text:t.text,updated_at:t.meta.base,updated_by:t.meta.by,offline:!0,pending:!0};let r=n.data?.current??{context:"",context_updated_at:null},o=`${r.context.trimEnd()}
4
4
 
5
5
  ## Saved offline on this machine (merge into the notes above)
6
6