@kaptures/cli 0.12.0 → 0.13.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -3,9 +3,9 @@ import{createRequire as e}from"node:module";import{formatWithOptions as t,parseA
3
3
  `)}function Fe(e){return typeof e==`function`?e():e}function Ie(e=[],t={}){let r=new Set(t.boolean||[]),i=new Set(t.string||[]),a=t.alias||{},o=t.default||{},s=new Map,c=new Map;for(let[e,t]of Object.entries(a)){let n=t;for(let t of n)s.set(e,t),c.has(t)||c.set(t,[]),c.get(t).push(e),s.set(t,e),c.has(e)||c.set(e,[]),c.get(e).push(t)}let l={};function u(e){if(r.has(e))return`boolean`;let t=c.get(e)||[];for(let e of t)if(r.has(e))return`boolean`;return`string`}let d=new Set([...r,...i,...Object.keys(a),...Object.values(a).flat(),...Object.keys(o)]);for(let e of d)l[e]||(l[e]={type:u(e),default:o[e]});for(let[e,t]of s.entries())e.length===1&&l[t]&&!l[t].short&&(l[t].short=e);let f=[],p={};for(let t=0;t<e.length;t++){let n=e[t];if(n===`--`){f.push(...e.slice(t));break}if(n.startsWith(`--no-`)){let e=n.slice(5);p[e]=!0;continue}f.push(n)}let m;try{m=n({args:f,options:Object.keys(l).length>0?l:void 0,allowPositionals:!0,strict:!1})}catch{m={values:{},positionals:f}}let h={_:[]};h._=m.positionals;for(let[e,t]of Object.entries(m.values))h[e]=t;for(let[e]of Object.entries(p)){h[e]=!1;let t=s.get(e);t&&(h[t]=!1);let n=c.get(e);if(n)for(let e of n)h[e]=!1}for(let[e,t]of s.entries())h[e]!==void 0&&h[t]===void 0&&(h[t]=h[e]),h[t]!==void 0&&h[e]===void 0&&(h[e]=h[t]);return h}function Le(e,t){let n={boolean:[],string:[],alias:{},default:{}},r=Re(t);for(let e of r){if(e.type===`positional`)continue;e.type===`string`||e.type===`enum`?n.string.push(e.name):e.type===`boolean`&&n.boolean.push(e.name),e.default!==void 0&&(n.default[e.name]=e.default),e.alias&&(n.alias[e.name]=e.alias);let t=Oe(e.name),r=ke(e.name);if(t!==e.name||r!==e.name){let i=Ne(n.alias[e.name]||[]);t!==e.name&&!i.includes(t)&&i.push(t),r!==e.name&&!i.includes(r)&&i.push(r),i.length>0&&(n.alias[e.name]=i)}}let i=Ie(e,n),[...a]=i._,o=new Proxy(i,{get(e,t){return e[t]??e[Oe(t)]??e[ke(t)]}});for(let[,e]of r.entries())if(e.type===`positional`){let t=a.shift();if(t!==void 0)o[e.name]=t;else if(e.default===void 0&&e.required!==!1)throw new We(`Missing required positional argument: ${e.name.toUpperCase()}`,`EARG`);else o[e.name]=e.default}else if(e.type===`enum`){let t=o[e.name],n=e.options||[];if(t!==void 0&&n.length>0&&!n.includes(t))throw new We(`Invalid value for argument: ${Je(`--${e.name}`)} (${Je(t)}). Expected one of: ${n.map(e=>Je(e)).join(`, `)}.`,`EARG`)}else if(e.required&&o[e.name]===void 0)throw new We(`Missing required argument: --${e.name}`,`EARG`);return o}function Re(e){let t=[];for(let[n,r]of Object.entries(e||{}))t.push({...r,name:n,alias:Ne(r.alias)});return t}function k(e){return e}async function ze(e,t){let n=await Fe(e.args||{}),r=Le(t.rawArgs,n),i={rawArgs:t.rawArgs,args:r,data:t.data,cmd:e};typeof e.setup==`function`&&await e.setup(i);let a;try{let n=await Fe(e.subCommands);if(n&&Object.keys(n).length>0){let r=t.rawArgs.findIndex(e=>!e.startsWith(`-`)),i=t.rawArgs[r];if(i){if(!n[i])throw new We(`Unknown command ${Je(i)}`,`E_UNKNOWN_COMMAND`);let e=await Fe(n[i]);e&&await ze(e,{rawArgs:t.rawArgs.slice(r+1)})}else if(!e.run)throw new We(`No command specified.`,`E_NO_COMMAND`)}typeof e.run==`function`&&(a=await e.run(i))}finally{typeof e.cleanup==`function`&&await e.cleanup(i)}return{result:a}}async function Be(e,t,n){let r=await Fe(e.subCommands);if(r&&Object.keys(r).length>0){let n=t.findIndex(e=>!e.startsWith(`-`)),i=t[n],a=await Fe(r[i]);if(a)return Be(a,t.slice(n+1),e)}return[e,n]}async function Ve(e,t){try{console.log(await He(e,t)+`
4
4
  `)}catch(e){console.error(e)}}async function He(e,t){let n=await Fe(e.meta||{}),r=Re(await Fe(e.args||{})),i=await Fe(t?.meta||{}),a=`${i.name?`${i.name} `:``}`+(n.name||process.argv[1]),o=[],s=[],c=[],l=[];for(let e of r)if(e.type===`positional`){let t=e.name.toUpperCase(),n=e.required!==!1&&e.default===void 0,r=e.default?`="${e.default}"`:``;s.push([Je(t+r),e.description||``,e.valueHint?`<${e.valueHint}>`:``]),l.push(n?`<${t}>`:`[${t}]`)}else{let t=e.required===!0&&e.default===void 0,n=[...(e.alias||[]).map(e=>`-${e}`),`--${e.name}`].join(`, `)+(e.type===`string`&&(e.valueHint||e.default)?`=${e.valueHint?`<${e.valueHint}>`:`"${e.default||``}"`}`:``)+(e.type===`enum`&&e.options?`=<${e.options.join(`|`)}>`:``);if(o.push([Je(n+(t?` (required)`:``)),e.description||``]),e.type===`boolean`&&(e.default===!0||e.negativeDescription)&&!Ze.test(e.name)){let n=[...(e.alias||[]).map(e=>`--no-${e}`),`--no-${e.name}`].join(`, `);o.push([Je(n+(t?` (required)`:``)),e.negativeDescription||``])}t&&l.push(n)}if(e.subCommands){let t=[],n=await Fe(e.subCommands);for(let[e,r]of Object.entries(n)){let n=await Fe((await Fe(r))?.meta);n?.hidden||(c.push([Je(e),n?.description||``]),t.push(e))}l.push(t.join(`|`))}let u=[],d=n.version||i.version;u.push(Ye(`${n.description} (${a+(d?` v${d}`:``)})`),``);let f=o.length>0||s.length>0;return u.push(`${Xe(qe(`USAGE`))} ${Je(`${a}${f?` [OPTIONS]`:``} ${l.join(` `)}`)}`,``),s.length>0&&(u.push(Xe(qe(`ARGUMENTS`)),``),u.push(Pe(s,` `)),u.push(``)),o.length>0&&(u.push(Xe(qe(`OPTIONS`)),``),u.push(Pe(o,` `)),u.push(``)),c.length>0&&(u.push(Xe(qe(`COMMANDS`)),``),u.push(Pe(c,` `)),u.push(``,`Use ${Je(`${a} <command> --help`)} for more information about a command.`)),u.filter(e=>typeof e==`string`).join(`
5
5
  `)}async function Ue(e,t={}){let n=t.rawArgs||process.argv.slice(2),r=t.showUsage||Ve;try{if(n.includes(`--help`)||n.includes(`-h`))await r(...await Be(e,n)),process.exit(0);else if(n.length===1&&n[0]===`--version`){let t=typeof e.meta==`function`?await e.meta():await e.meta;if(!t?.version)throw new We(`No version specified`,`E_NO_VERSION`);console.log(t.version)}else await ze(e,{rawArgs:n})}catch(t){t instanceof We?(await r(...await Be(e,n)),console.error(t.message)):console.error(t,`
6
- `),process.exit(1)}}var We,Ge,Ke,qe,Je,Ye,Xe,Ze,A=E((()=>{Me(),We=class extends Error{code;constructor(e,t){super(e),this.name=`CLIError`,this.code=t}},Ge=(()=>{let e=globalThis.process?.env??{};return e.NO_COLOR===`1`||e.TERM===`dumb`||e.TEST||e.CI})(),Ke=(e,t=39)=>n=>Ge?n:`\u001B[${e}m${n}\u001B[${t}m`,qe=Ke(1,22),Je=Ke(36),Ye=Ke(90),Xe=Ke(4,24),Ze=/^no[-A-Z]/}));A();var Qe=`0.12.0`;const $e=e(import.meta.url);async function et(e=!1){let t=$e.resolve(`agent-browser/package.json`),n=[f(a(t),`bin`,`agent-browser.js`),`install`];e&&n.push(`--with-deps`);let i=await new Promise((e,t)=>{let i=r(process.execPath,n,{stdio:`inherit`});i.once(`error`,t),i.once(`exit`,(n,r)=>{r?t(Error(`agent-browser install stopped by ${r}`)):e(n??1)})});if(i!==0)throw Error(`agent-browser install exited with code ${i}`)}const tt=k({meta:{name:`browser`,description:`Manage the Kapture browser runtime`},subCommands:{install:k({meta:{name:`install`,description:`Install the Chrome runtime used by agent-browser`},args:{"with-deps":{type:`boolean`,default:!1,description:`Also install Linux system dependencies`}},async run({args:e}){await et(e[`with-deps`])}})}}),nt=[`npm`,`yarn`,`pnpm`,`bun`],rt={node:`actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38`,bun:`oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6`,checkout:`actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803`,upload:`actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f`,download:`actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53`},j=e=>`\${{ ${e} }}`,it=JSON.stringify,at=(e,t=10)=>e.split(`
6
+ `),process.exit(1)}}var We,Ge,Ke,qe,Je,Ye,Xe,Ze,A=E((()=>{Me(),We=class extends Error{code;constructor(e,t){super(e),this.name=`CLIError`,this.code=t}},Ge=(()=>{let e=globalThis.process?.env??{};return e.NO_COLOR===`1`||e.TERM===`dumb`||e.TEST||e.CI})(),Ke=(e,t=39)=>n=>Ge?n:`\u001B[${e}m${n}\u001B[${t}m`,qe=Ke(1,22),Je=Ke(36),Ye=Ke(90),Xe=Ke(4,24),Ze=/^no[-A-Z]/}));A();var Qe=`0.13.0`;const $e=e(import.meta.url);async function et(e=!1){let t=$e.resolve(`agent-browser/package.json`),n=[f(a(t),`bin`,`agent-browser.js`),`install`];e&&n.push(`--with-deps`);let i=await new Promise((e,t)=>{let i=r(process.execPath,n,{stdio:`inherit`});i.once(`error`,t),i.once(`exit`,(n,r)=>{r?t(Error(`agent-browser install stopped by ${r}`)):e(n??1)})});if(i!==0)throw Error(`agent-browser install exited with code ${i}`)}const tt=k({meta:{name:`browser`,description:`Manage the Kapture browser runtime`},subCommands:{install:k({meta:{name:`install`,description:`Install the Chrome runtime used by agent-browser`},args:{"with-deps":{type:`boolean`,default:!1,description:`Also install Linux system dependencies`}},async run({args:e}){await et(e[`with-deps`])}})}}),nt=[`npm`,`yarn`,`pnpm`,`bun`],rt={node:`actions/setup-node@249970729cb0ef3589644e2896645e5dc5ba9c38`,bun:`oven-sh/setup-bun@0c5077e51419868618aeaa5fe8019c62421857d6`,checkout:`actions/checkout@d23441a48e516b6c34aea4fa41551a30e30af803`,upload:`actions/upload-artifact@b7c566a772e6b6bfb58ed0dc250532a479d7789f`,download:`actions/download-artifact@018cc2cf5baa6db3ef3c5f8a56943fffe632ef53`},j=e=>`\${{ ${e} }}`,it=JSON.stringify,at=(e,t=10)=>e.split(`
7
7
  `).map(e=>`${` `.repeat(t)}${e}`).join(`
8
- `);function ot(e){let t=` - uses: ${rt.node}\n with: { node-version: "24" }\n`;return e===`bun`?`${t} - uses: ${rt.bun}\n`:e===`yarn`||e===`pnpm`?`${t} - run: corepack enable\n`:t}function st(e,t){if(!/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/.test(t))throw Error(`CLI version must be exact SemVer`);let n=`@kaptures/cli@${t}`;switch(e){case`npm`:return`npx --yes ${n}`;case`yarn`:return`yarn dlx --package ${n} kapture`;case`pnpm`:return`pnpm dlx ${n}`;case`bun`:return`bunx ${n}`}}function ct(e){let t=e.packageManager;if(!nt.includes(t))throw Error(`Unsupported package manager`);let n=st(`npm`,e.cliVersion),r=ot(`npm`),i=ot(t),a=e.baseBranch??`main`,o=e.storybookDirectory??`storybook-static`,s=e.adapterPackageJson;if(e.allowInitialAdoption&&!s)throw Error(`Initial adoption requires adapterPackageJson`);let c=e.allowInitialAdoption?` --allow-initial-adoption --adapter-package-json ${s}`:``;for(let e of[o,...s?[s]:[]])if(!/^[A-Za-z0-9._/-]+$/.test(e)||e.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Expected safe project-relative paths`);if(!a||[...a].some(e=>e.charCodeAt(0)<32||e.charCodeAt(0)===127))throw Error(`Expected a branch name`);let l=e.installCommand??{npm:`npm ci`,yarn:`case "$(yarn --version)" in
8
+ `);function ot(e){let t=` - uses: ${rt.node}\n with: { node-version: "24" }\n`;return e===`bun`?`${t} - uses: ${rt.bun}\n`:e===`yarn`||e===`pnpm`?`${t} - run: corepack enable\n`:t}function st(e,t){if(!/^\d+\.\d+\.\d+(?:-[A-Za-z0-9.-]+)?$/.test(t))throw Error(`CLI version must be exact SemVer`);let n=`@kaptures/cli@${t}`;switch(e){case`npm`:return`npx --yes ${n}`;case`yarn`:return`yarn dlx --package ${n} kapture`;case`pnpm`:return`pnpm dlx ${n}`;case`bun`:return`bunx ${n}`}}function ct(e){let t=e.packageManager;if(!nt.includes(t))throw Error(`Unsupported package manager`);let n=st(`npm`,e.cliVersion),r=ot(`npm`),i=ot(t),a=e.baseBranch??`main`,o=e.storybookDirectory??`storybook-static`,s=e.adapterPackageJson;if((e.allowInitialAdoption||e.allowAdapterUpgrade)&&!s)throw Error(`Non-comparison modes require adapterPackageJson`);let c=[e.allowInitialAdoption?` --allow-initial-adoption`:``,e.allowAdapterUpgrade?` --allow-adapter-upgrade`:``,s?` --adapter-package-json ${s}`:``].join(``);for(let e of[o,...s?[s]:[]])if(!/^[A-Za-z0-9._/-]+$/.test(e)||e.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Expected safe project-relative paths`);if(!a||[...a].some(e=>e.charCodeAt(0)<32||e.charCodeAt(0)===127))throw Error(`Expected a branch name`);let l=e.installCommand??{npm:`npm ci`,yarn:`case "$(yarn --version)" in
9
9
  1.*) yarn install --frozen-lockfile ;;
10
10
  *) yarn install --immutable ;;
11
11
  esac`,pnpm:`pnpm install --frozen-lockfile`,bun:`bun install --frozen-lockfile`}[t],u=e.buildCommand??`${t} run build-storybook ${t===`npm`?`-- `:``}--output-dir ${o}`,d=j(`runner.temp`),f=j(`needs.context.outputs.artifact-suffix`),p=[`integration-mode`,`artifact-suffix`,`base-repository`,`base-sha`,`head-repository`,`head-sha`].map(e=>` ${e}: ${j(`steps.context.outputs.${e}`)}`).join(`
@@ -69,7 +69,7 @@ ${r} - id: context
69
69
  GITHUB_TOKEN: ${j(`github.token`)}
70
70
  KAPTURE_BASE_BRANCH: ${it(a)}
71
71
  run: >-
72
- ${n} github context --base-branch "$KAPTURE_BASE_BRANCH"${e.allowInitialAdoption?c:s?` --adapter-package-json ${s}`:``}
72
+ ${n} github context --base-branch "$KAPTURE_BASE_BRANCH"${c}
73
73
  --output "${d}/kapture-context/context.json"
74
74
  --changed-files-output "${d}/kapture-context/changed-files.json"
75
75
  - uses: ${rt.upload}
@@ -247,9 +247,9 @@ jobs:
247
247
  ${r} - env:
248
248
  GITHUB_TOKEN: ${j(`github.token`)}
249
249
  run: ${n} github approve
250
- `;return{"kapture-capture.yml":h+g,"kapture-report.yml":_,"kapture-approve.yml":v}}A();const lt=k({meta:{name:`ci`,description:`Generate provider-neutral GitHub Actions workflows for your package manager`},args:{"package-manager":{type:`string`,required:!0},"base-branch":{type:`string`,default:`main`},"storybook-directory":{type:`string`,default:`storybook-static`},"adapter-package-json":{type:`string`},"allow-initial-adoption":{type:`boolean`,default:!1},"install-command":{type:`string`},"build-command":{type:`string`},output:{type:`string`,default:`.github/workflows`}},async run({args:e}){let t=e[`package-manager`];if(!nt.includes(t))throw Error(`package-manager must be npm, yarn, pnpm, or bun`);let n=ct({packageManager:t,cliVersion:Qe,baseBranch:e[`base-branch`],storybookDirectory:e[`storybook-directory`],adapterPackageJson:e[`adapter-package-json`],allowInitialAdoption:e[`allow-initial-adoption`],installCommand:e[`install-command`],buildCommand:e[`build-command`]}),r=f(e.output);for(let e of Object.keys(n))if(await m(f(r,e)).then(()=>!0,e=>{if(e.code===`ENOENT`)return!1;throw e}))throw Error(`${e} already exists; generate into a new directory and review the diff`);await y(r,{recursive:!0});for(let[e,t]of Object.entries(n)){let n=await b(f(r,e),`wx`);try{await n.writeFile(t)}finally{await n.close()}}console.log(`Generated three workflows in ${r}. Configure the deployment step in kapture-report.yml for normal comparison. Initial adoption only uploads capture artifacts and writes a Job Summary. No commits or deployments were made.`)}}),ut=8192;async function dt(e,t){let n=[],r=await pt(e);r&&n.push(ft(r,t));for(let r of[`x-github-request-id`,`x-accepted-github-permissions`,`retry-after`]){let i=e.headers.get(r);i&&n.push(`${r}: ${ft(i,t)}`)}return n.length?` (${n.join(`; `)})`:``}function ft(e,t){return e.split(t).join(`[REDACTED]`).replace(/(?:github_pat_|gh[pousr]_)[A-Za-z0-9_]+/g,`[REDACTED]`).replace(/\b(?:Bearer|Basic)\s+\S+/gi,`[REDACTED]`).replace(/[\p{Cc}\p{Cf}]+/gu,` `).slice(0,512)}async function pt(e){let t=e.body?.getReader();if(!t)return;let n=new Uint8Array(ut),r=0;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;if(r+i.byteLength>ut)return;n.set(i,r),r+=i.byteLength}let e=JSON.parse(new TextDecoder().decode(n.subarray(0,r)));if(e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`)return e.message}catch{}finally{await t.cancel().catch(()=>{}),t.releaseLock()}}async function mt(e,t){let n=(await e.listWorkflowRuns(t.workflowId,t.headBranch)).filter(e=>e.headRepositoryId===t.headRepository.id);if(n.some(e=>e.id===t.id&&e.runNumber!==t.runNumber))throw Error(`Latest workflow run metadata conflicts with the triggering run`);return n.reduce((e,t)=>e?t.runNumber===e.runNumber?t.id>e.id?t:e:t.runNumber>e.runNumber?t:e:t,void 0)?.id===t.id}function ht(e,t,n,r,i,a={}){let{threshold:o=.1,alpha:s=.1,aaColor:c=[255,255,0],diffColor:l=[255,0,0],includeAA:u,diffColorAlt:d,diffMask:f}=a;if(!gt(e)||!gt(t)||n&&!gt(n))throw Error(`Image data: Uint8Array, Uint8ClampedArray or Buffer expected.`);if(e.length!==t.length||n&&n.length!==e.length)throw Error(`Image sizes do not match.`);if(e.length!==r*i*4)throw Error(`Image data size does not match width/height.`);let p=r*i,m=new Uint32Array(e.buffer,e.byteOffset,p),h=new Uint32Array(t.buffer,t.byteOffset,p),g=!0;for(let e=0;e<p;e++)if(m[e]!==h[e]){g=!1;break}if(g){if(n&&!f)for(let t=0;t<p;t++)xt(e,4*t,s,n);return 0}let _=35215*o*o,[v,y,ee]=c,[b,x,te]=l,[S,ne,re]=d||l,C=0;for(let a=0;a<i;a++)for(let o=0;o<r;o++){let c=a*r+o,l=c*4,d=m[c]===h[c]?0:yt(e,t,l,l,!1);if(Math.abs(d)>_){let s=_t(e,o,a,r,i,m,h)||_t(t,o,a,r,i,h,m);!u&&s?n&&!f&&bt(n,l,v,y,ee):(n&&(d<0?bt(n,l,S,ne,re):bt(n,l,b,x,te)),C++)}else n&&!f&&xt(e,l,s,n)}return C}function gt(e){return ArrayBuffer.isView(e)&&e.BYTES_PER_ELEMENT===1}function _t(e,t,n,r,i,a,o){let s=Math.max(t-1,0),c=Math.max(n-1,0),l=Math.min(t+1,r-1),u=Math.min(n+1,i-1),d=n*r+t,f=+(t===s||t===l||n===c||n===u),p=0,m=0,h=0,g=0,_=0,v=0;for(let i=s;i<=l;i++)for(let a=c;a<=u;a++){if(i===t&&a===n)continue;let o=yt(e,e,d*4,(a*r+i)*4,!0);if(o===0){if(f++,f>2)return!1}else o<p?(p=o,h=i,g=a):o>m&&(m=o,_=i,v=a)}return p===0||m===0?!1:vt(a,h,g,r,i)&&vt(o,h,g,r,i)||vt(a,_,v,r,i)&&vt(o,_,v,r,i)}function vt(e,t,n,r,i){let a=Math.max(t-1,0),o=Math.max(n-1,0),s=Math.min(t+1,r-1),c=Math.min(n+1,i-1),l=e[n*r+t],u=+(t===a||t===s||n===o||n===c);for(let i=a;i<=s;i++)for(let a=o;a<=c;a++)if((i!==t||a!==n)&&(u+=+(l===e[a*r+i]),u>2))return!0;return!1}function yt(e,t,n,r,i){let a=e[n],o=e[n+1],s=e[n+2],c=e[n+3],l=t[r],u=t[r+1],d=t[r+2],f=t[r+3],p=a-l,m=o-u,h=s-d,g=c-f;if(!p&&!m&&!h&&!g)return 0;if(c<255||f<255){let e=48+n%2*159,t=48+159*((n/1.618033988749895|0)%2),r=48+159*((n/2.618033988749895|0)%2);p=(a*c-l*f-e*g)/255,m=(o*c-u*f-t*g)/255,h=(s*c-d*f-r*g)/255}let _=p*.29889531+m*.58662247+h*.11448223;if(i)return _;let v=p*.59597799-m*.2741761-h*.32180189,y=p*.21147017-m*.52261711+h*.31114694,ee=.5053*_*_+.299*v*v+.1957*y*y;return _>0?-ee:ee}function bt(e,t,n,r,i){e[t+0]=n,e[t+1]=r,e[t+2]=i,e[t+3]=255}function xt(e,t,n,r){let i=255+(e[t]*.29889531+e[t+1]*.58662247+e[t+2]*.11448223-255)*n*e[t+3]/255;bt(r,t,i,i,i)}var St=E((()=>{})),Ct=D(((e,t)=>{let n=O(`util`),r=O(`stream`),i=t.exports=function(){r.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};n.inherits(i,r),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},i.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),wt=D((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),Tt=D(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),Et=D(((e,t)=>{let n=wt(),r=Tt();function i(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let a=t.exports=function(e,t){let r=e.width,a=e.height,o=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=n.getImagePasses(r,a);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(r,s,c),height:a,lineIndex:0});this._xComparison=c===8?s:c===16?s*2:1};a.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},a.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++){let n=e[1+a],o=a>i?t[a-r]:0;t[a]=n+o}},a.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++){let n=e[1+i],a=r?r[i]:0;t[i]=n+a}},a.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0,l=Math.floor((c+s)/2);t[o]=n+l}},a.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0,d=r(l,c,u);t[s]=n+d}},a.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),Dt=D(((e,t)=>{let n=O(`util`),r=Ct(),i=Et(),a=t.exports=function(e){r.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};n.inherits(a,r)})),Ot=D(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),kt=D(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),At=D(((e,t)=>{let n=Ot(),r=kt(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),jt=D((e=>{let t=wt(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function i(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a)}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function a(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function o(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,s=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=i(e,c));let f;f=c<=8?Buffer.alloc(r*s*4):new Uint16Array(r*s*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,s),g=t.getInterlaceIterator(r,s);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:s}]}for(let t=0;t<h.length;t++)c===8?m=a(h[t],f,g,l,e,m):o(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),Mt=D(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),Nt=D(((e,t)=>{let n=O(`util`),r=O(`zlib`),i=Ct(),a=Dt(),o=At(),s=jt(),c=Mt(),l=t.exports=function(e){i.call(this),this._parser=new o(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};n.inherits(l,i),l.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},l.prototype._inflateData=function(e){if(!this._inflate){if(this._bitmapInfo.interlace)this._inflate=r.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,r.Z_MIN_CHUNK);this._inflate=r.createInflate({chunkSize:t});let n=e,i=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&i(e)}),this._filter.on(`complete`,this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,a(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}}this._inflate.write(e)},l.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new a(this._bitmapInfo)},l.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},l.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},l.prototype._simpleTransparency=function(){this._metaData.alpha=!0},l.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},l.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},l.prototype._complete=function(e){if(this.errord)return;let t;try{let n=s.dataToBitMap(e,this._bitmapInfo);t=c(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),Pt=D(((e,t)=>{let n=Ot();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),Ft=D(((e,t)=>{let n=Tt();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function a(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function o(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function s(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function c(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function l(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function u(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function d(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function f(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let p={0:r,1:a,2:s,3:l,4:d},m={0:i,1:o,2:c,3:u,4:f};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=m[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,p[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),It=D(((e,t)=>{let n=Ot(),r=kt(),i=Pt(),a=Ft(),o=O(`zlib`),s=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||o.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:n.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:n.COLORTYPE_COLOR_ALPHA,[n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};s.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},s.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},s.prototype.filterData=function(e,t,r){let o=i(e,t,r,this._options),s=n.COLORTYPE_TO_BPP_MAP[this._options.colorType];return a(o,t,r,this._options,s)},s.prototype._packChunk=function(e,t){let n=t?t.length:0,i=Buffer.alloc(n+12);return i.writeUInt32BE(n,0),i.writeUInt32BE(e,4),t&&t.copy(i,8),i.writeInt32BE(r.crc32(i.slice(4,i.length-4)),i.length-4),i},s.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*n.GAMMA_DIVISION),0),this._packChunk(n.TYPE_gAMA,t)},s.prototype.packIHDR=function(e,t){let r=Buffer.alloc(13);return r.writeUInt32BE(e,0),r.writeUInt32BE(t,4),r[8]=this._options.bitDepth,r[9]=this._options.colorType,r[10]=0,r[11]=0,r[12]=0,this._packChunk(n.TYPE_IHDR,r)},s.prototype.packIDAT=function(e){return this._packChunk(n.TYPE_IDAT,e)},s.prototype.packIEND=function(){return this._packChunk(n.TYPE_IEND,null)}})),Lt=D(((e,t)=>{let n=O(`util`),r=O(`stream`),i=Ot(),a=It(),o=t.exports=function(e){r.call(this);let t=e||{};this._packer=new a(t),this._deflate=this._packer.createDeflate(),this.readable=!0};n.inherits(o,r),o.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(i.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let a=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(a)}})),Rt=D(((e,t)=>{let n=O(`assert`).ok,r=O(`zlib`),i=O(`util`),a=O(`buffer`).kMaxLength;function o(e){if(!(this instanceof o))return new o(e);e&&e.chunkSize<r.Z_MIN_CHUNK&&(e.chunkSize=r.Z_MIN_CHUNK),r.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function s(e){return new o(e)}function c(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}o.prototype._processChunk=function(e,t,i){if(typeof i==`function`)return r.Inflate._processChunk.call(this,e,t,i);let o=this,s=e&&e.length,l=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(o._hadError)return;let r=l-t;if(n(r>=0,`have should not go down`),r>0){let e=o._buffer.slice(o._offset,o._offset+r);if(o._offset+=r,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||o._offset>=o._chunkSize)&&(l=o._chunkSize,o._offset=0,o._buffer=Buffer.allocUnsafe(o._chunkSize)),t===0&&(d+=s-e,s=e,!0)}n(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,l),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=a)throw c(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+a.toString(16)+` bytes`);let _=Buffer.concat(f,p);return c(this),_},i.inherits(o,r.Inflate);function l(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=r.Z_FINISH,e._processChunk(t,n)}function u(e,t){return l(new o(t),e)}t.exports=e=u,e.Inflate=o,e.createInflate=s,e.inflateSync=u})),zt=D(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),Bt=D((e=>{let t=zt(),n=Et();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),Vt=D(((e,t)=>{let n=!0,r=O(`zlib`),i=Rt();r.deflateSync||(n=!1);let a=zt(),o=Bt(),s=At(),c=jt(),l=Mt();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let u;function d(e){u=e}let f;function p(e){f=e}function m(e){f.transColor=e}function h(e){f.palette=e}function g(){f.alpha=!0}let _;function v(e){_=e}let y=[];function ee(e){y.push(e)}let b=new a(e);if(new s(t,{read:b.read.bind(b),error:d,metadata:p,gamma:v,palette:h,transColor:m,inflateData:ee,simpleTransparency:g}).start(),b.process(),u)throw u;let x=Buffer.concat(y);y.length=0;let te;if(f.interlace)te=r.inflateSync(x);else{let e=((f.width*f.bpp*f.depth+7>>3)+1)*f.height;te=i(x,{chunkSize:e,maxLength:e})}if(x=null,!te||!te.length)throw Error(`bad png - invalid inflate data response`);let S=o.process(te,f);x=null;let ne=c.dataToBitMap(S,f);S=null;let re=l(ne,f,t.skipRescale);return f.data=re,f.gamma=_||0,f}})),Ht=D(((e,t)=>{let n=!0,r=O(`zlib`);r.deflateSync||(n=!1);let i=Ot(),a=It();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let o=new a(t||{}),s=[];s.push(Buffer.from(i.PNG_SIGNATURE)),s.push(o.packIHDR(e.width,e.height)),e.gamma&&s.push(o.packGAMA(e.gamma));let c=o.filterData(e.data,e.width,e.height),l=r.deflateSync(c,o.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(o.packIDAT(l)),s.push(o.packIEND()),Buffer.concat(s)}})),Ut=D((e=>{let t=Vt(),n=Ht();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),Wt=D((e=>{let t=O(`util`),n=O(`stream`),r=Nt(),i=Lt(),a=Ut(),o=e.PNG=function(e){n.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new r(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new i(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};t.inherits(o,n),o.sync=a,o.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},o.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},o.prototype.write=function(e){return this._parser.write(e),!0},o.prototype.end=function(e){this._parser.end(e)},o.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},o.prototype._gamma=function(e){this.gamma=e},o.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},o.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},o.prototype.bitblt=function(e,t,n,r,i,a,s){return o.bitblt(this,e,t,n,r,i,a,s),this},o.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},o.prototype.adjustGamma=function(){o.adjustGamma(this)}}));function M(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}function Gt(e){return e&&Object.assign(Jt,e),Jt}var Kt,qt,Jt,Yt=E((()=>{Object.freeze({status:`aborted`}),Kt=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},qt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},Jt={}}));function Xt(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function Zt(e,t){return typeof t==`bigint`?t.toString():t}function Qt(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function $t(e){return e==null}function en(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function tn(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=t.toString(),i=(r.split(`.`)[1]||``).length;if(i===0&&/\d?e-\d?/.test(r)){let e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}let a=n>i?n:i;return Number.parseInt(e.toFixed(a).replace(`.`,``))%Number.parseInt(t.toFixed(a).replace(`.`,``))/10**a}function N(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==En)return r===void 0&&(r=En,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function nn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function rn(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function an(e){return JSON.stringify(e)}function on(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}function sn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function cn(e){if(sn(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return sn(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function ln(e){return cn(e)?{...e}:Array.isArray(e)?[...e]:e}function un(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function dn(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function P(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function fn(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}function pn(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return dn(e,rn(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return nn(this,`shape`,e),e},checks:[]}))}function mn(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return dn(e,rn(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return nn(this,`shape`,r),r},checks:[]}))}function hn(e,t){if(!cn(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return dn(e,rn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return nn(this,`shape`,n),n}}))}function gn(e,t){if(!cn(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return dn(e,rn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return nn(this,`shape`,n),n}}))}function _n(e,t){return dn(e,rn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return nn(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function vn(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return dn(t,rn(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return nn(this,`shape`,i),i},checks:[]}))}function yn(e,t,n){return dn(t,rn(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return nn(this,`shape`,i),i}}))}function bn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function xn(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function Sn(e){return typeof e==`string`?e:e?.message}function Cn(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=Sn(e.inst?._zod.def?.error?.(e))??Sn(t?.error?.(e))??Sn(n.customError?.(e))??Sn(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function wn(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function Tn(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var En,Dn,On,kn,An,jn=E((()=>{En=Symbol(`evaluating`),Dn=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{},On=Qt(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}}),kn=new Set([`string`,`number`,`symbol`]),An={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}}));function Mn(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Nn(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}var Pn,Fn,In,Ln=E((()=>{Yt(),jn(),Pn=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,Zt,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},Fn=M(`$ZodError`,Pn),In=M(`$ZodError`,Pn,{Parent:Error})})),Rn,zn,Bn,Vn,Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn=E((()=>{Yt(),Ln(),jn(),Rn=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Kt;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Cn(e,a,Gt())));throw Dn(t,i?.callee),t}return o.value},zn=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Cn(e,a,Gt())));throw Dn(t,i?.callee),t}return o.value},Bn=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Kt;return a.issues.length?{success:!1,error:new(e??Fn)(a.issues.map(e=>Cn(e,i,Gt())))}:{success:!0,data:a.value}},Vn=Bn(In),Hn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>Cn(e,i,Gt())))}:{success:!0,data:a.value}},Un=Hn(In),Wn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Rn(e)(t,n,i)},Gn=e=>(t,n,r)=>Rn(e)(t,n,r),Kn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return zn(e)(t,n,i)},qn=e=>async(t,n,r)=>zn(e)(t,n,r),Jn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Bn(e)(t,n,i)},Yn=e=>(t,n,r)=>Bn(e)(t,n,r),Xn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Hn(e)(t,n,i)},Zn=e=>async(t,n,r)=>Hn(e)(t,n,r)}));function $n(){return new RegExp(pr,`u`)}function er(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function tr(e){return RegExp(`^${er(e)}$`)}function nr(e){let t=er({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${xr}T(?:${r})$`)}var rr,ir,ar,or,sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr=E((()=>{rr=/^[cC][^\s-]{8,}$/,ir=/^[0-9a-z]+$/,ar=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,or=/^[0-9a-vA-V]{20}$/,sr=/^[A-Za-z0-9]{27}$/,cr=/^[a-zA-Z0-9_-]{21}$/,lr=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,ur=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,dr=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,fr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,pr=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,mr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,hr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,gr=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,_r=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,vr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,yr=/^[A-Za-z0-9_-]*$/,br=/^\+[1-9]\d{6,14}$/,xr=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Sr=RegExp(`^${xr}$`),Cr=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},wr=/^-?\d+$/,Tr=/^-?\d+(?:\.\d+)?$/,Er=/^(?:true|false)$/i,Dr=/^[^A-Z]*$/,Or=/^[^a-z]*$/})),Ar,jr,Mr,Nr,Pr,Fr,Ir,Lr,Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr=E((()=>{Yt(),kr(),jn(),Ar=M(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),jr={number:`number`,bigint:`bigint`,object:`date`},Mr=M(`$ZodCheckLessThan`,(e,t)=>{Ar.init(e,t);let n=jr[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Nr=M(`$ZodCheckGreaterThan`,(e,t)=>{Ar.init(e,t);let n=jr[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Pr=M(`$ZodCheckMultipleOf`,(e,t)=>{Ar.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):tn(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Fr=M(`$ZodCheckNumberFormat`,(e,t)=>{Ar.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=An[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=wr)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),Ir=M(`$ZodCheckMaxLength`,(e,t)=>{var n;Ar.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!$t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=wn(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Lr=M(`$ZodCheckMinLength`,(e,t)=>{var n;Ar.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!$t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=wn(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Rr=M(`$ZodCheckLengthEquals`,(e,t)=>{var n;Ar.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!$t(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=wn(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),zr=M(`$ZodCheckStringFormat`,(e,t)=>{var n,r;Ar.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Br=M(`$ZodCheckRegex`,(e,t)=>{zr.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Vr=M(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=Dr,zr.init(e,t)}),Hr=M(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Or,zr.init(e,t)}),Ur=M(`$ZodCheckIncludes`,(e,t)=>{Ar.init(e,t);let n=un(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),Wr=M(`$ZodCheckStartsWith`,(e,t)=>{Ar.init(e,t);let n=RegExp(`^${un(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Gr=M(`$ZodCheckEndsWith`,(e,t)=>{Ar.init(e,t);let n=RegExp(`.*${un(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Kr=M(`$ZodCheckOverwrite`,(e,t)=>{Ar.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}})})),Jr,Yr=E((()=>{Jr=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
250
+ `;return{"kapture-capture.yml":h+g,"kapture-report.yml":_,"kapture-approve.yml":v}}const lt={"allow-adapter-upgrade":{type:`boolean`,default:!1,description:`Skip comparison for an exact stable adapter upgrade matching the head CLI`}};function ut(e,t){let n=dt(e);if(t){if(dt(t.headManifest)!==t.adapterVersion)throw Error(`Head adapter must match the exact CLI version`);if(n===void 0&&t.allowInitialAdoption)return`initial-adoption`;if(t.allowAdapterUpgrade&&ft(e,t.headManifest))return`adapter-upgrade`;if(n!==t.adapterVersion)throw Error(`Base adapter must match the exact CLI version or qualify for an explicitly allowed adapter upgrade`)}if(n!==void 0)return`compare`;throw Error(`The selected base package manifest does not declare @kaptures/storybook. Select the adapter's workspace manifest or omit --adapter-package-json to validate the built Storybook at capture time.`)}function dt(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Invalid package manifest`);let t=e,n;for(let e of[`dependencies`,`devDependencies`]){let r=t[e];if(r!==void 0&&(!r||typeof r!=`object`||Array.isArray(r)))throw Error(`Invalid package dependencies`);let i=r?.[`@kaptures/storybook`];if(r&&Object.hasOwn(r,`@kaptures/storybook`)){if(typeof i!=`string`||!i.trim())throw Error(`Invalid adapter declaration`);if(n!==void 0&&n!==i)throw Error(`Conflicting adapter declarations`);n=i}}return n}function ft(e,t){let n=dt(e),r=dt(t),i=/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;if(!n||!r||!i.test(n)||!i.test(r))return!1;let a=n.split(`.`).map(BigInt),o=r.split(`.`).map(BigInt);for(let e=0;e<3;e++)if(a[e]!==o[e])return a[e]<o[e];return!1}A();const pt=k({meta:{name:`ci`,description:`Generate provider-neutral GitHub Actions workflows for your package manager`},args:{...lt,"package-manager":{type:`string`,required:!0},"base-branch":{type:`string`,default:`main`},"storybook-directory":{type:`string`,default:`storybook-static`},"adapter-package-json":{type:`string`},"allow-initial-adoption":{type:`boolean`,default:!1},"install-command":{type:`string`},"build-command":{type:`string`},output:{type:`string`,default:`.github/workflows`}},async run({args:e}){let t=e[`package-manager`];if(!nt.includes(t))throw Error(`package-manager must be npm, yarn, pnpm, or bun`);let n=ct({packageManager:t,cliVersion:Qe,baseBranch:e[`base-branch`],storybookDirectory:e[`storybook-directory`],adapterPackageJson:e[`adapter-package-json`],allowInitialAdoption:e[`allow-initial-adoption`],allowAdapterUpgrade:e[`allow-adapter-upgrade`],installCommand:e[`install-command`],buildCommand:e[`build-command`]}),r=f(e.output);for(let e of Object.keys(n))if(await m(f(r,e)).then(()=>!0,e=>{if(e.code===`ENOENT`)return!1;throw e}))throw Error(`${e} already exists; generate into a new directory and review the diff`);await y(r,{recursive:!0});for(let[e,t]of Object.entries(n)){let n=await b(f(r,e),`wx`);try{await n.writeFile(t)}finally{await n.close()}}console.log(`Generated three workflows in ${r}. Configure the deployment step in kapture-report.yml for normal comparison. Initial adoption only uploads capture artifacts and writes a Job Summary. No commits or deployments were made.`)}}),mt=8192;async function ht(e,t){let n=[],r=await _t(e);r&&n.push(gt(r,t));for(let r of[`x-github-request-id`,`x-accepted-github-permissions`,`retry-after`]){let i=e.headers.get(r);i&&n.push(`${r}: ${gt(i,t)}`)}return n.length?` (${n.join(`; `)})`:``}function gt(e,t){return e.split(t).join(`[REDACTED]`).replace(/(?:github_pat_|gh[pousr]_)[A-Za-z0-9_]+/g,`[REDACTED]`).replace(/\b(?:Bearer|Basic)\s+\S+/gi,`[REDACTED]`).replace(/[\p{Cc}\p{Cf}]+/gu,` `).slice(0,512)}async function _t(e){let t=e.body?.getReader();if(!t)return;let n=new Uint8Array(mt),r=0;try{for(;;){let{done:e,value:i}=await t.read();if(e)break;if(r+i.byteLength>mt)return;n.set(i,r),r+=i.byteLength}let e=JSON.parse(new TextDecoder().decode(n.subarray(0,r)));if(e&&typeof e==`object`&&`message`in e&&typeof e.message==`string`)return e.message}catch{}finally{await t.cancel().catch(()=>{}),t.releaseLock()}}async function vt(e,t){let n=(await e.listWorkflowRuns(t.workflowId,t.headBranch)).filter(e=>e.headRepositoryId===t.headRepository.id);if(n.some(e=>e.id===t.id&&e.runNumber!==t.runNumber))throw Error(`Latest workflow run metadata conflicts with the triggering run`);return n.reduce((e,t)=>e?t.runNumber===e.runNumber?t.id>e.id?t:e:t.runNumber>e.runNumber?t:e:t,void 0)?.id===t.id}function yt(e,t,n,r,i,a={}){let{threshold:o=.1,alpha:s=.1,aaColor:c=[255,255,0],diffColor:l=[255,0,0],includeAA:u,diffColorAlt:d,diffMask:f}=a;if(!bt(e)||!bt(t)||n&&!bt(n))throw Error(`Image data: Uint8Array, Uint8ClampedArray or Buffer expected.`);if(e.length!==t.length||n&&n.length!==e.length)throw Error(`Image sizes do not match.`);if(e.length!==r*i*4)throw Error(`Image data size does not match width/height.`);let p=r*i,m=new Uint32Array(e.buffer,e.byteOffset,p),h=new Uint32Array(t.buffer,t.byteOffset,p),g=!0;for(let e=0;e<p;e++)if(m[e]!==h[e]){g=!1;break}if(g){if(n&&!f)for(let t=0;t<p;t++)Tt(e,4*t,s,n);return 0}let _=35215*o*o,[v,y,ee]=c,[b,x,te]=l,[S,ne,re]=d||l,C=0;for(let a=0;a<i;a++)for(let o=0;o<r;o++){let c=a*r+o,l=c*4,d=m[c]===h[c]?0:Ct(e,t,l,l,!1);if(Math.abs(d)>_){let s=xt(e,o,a,r,i,m,h)||xt(t,o,a,r,i,h,m);!u&&s?n&&!f&&wt(n,l,v,y,ee):(n&&(d<0?wt(n,l,S,ne,re):wt(n,l,b,x,te)),C++)}else n&&!f&&Tt(e,l,s,n)}return C}function bt(e){return ArrayBuffer.isView(e)&&e.BYTES_PER_ELEMENT===1}function xt(e,t,n,r,i,a,o){let s=Math.max(t-1,0),c=Math.max(n-1,0),l=Math.min(t+1,r-1),u=Math.min(n+1,i-1),d=n*r+t,f=+(t===s||t===l||n===c||n===u),p=0,m=0,h=0,g=0,_=0,v=0;for(let i=s;i<=l;i++)for(let a=c;a<=u;a++){if(i===t&&a===n)continue;let o=Ct(e,e,d*4,(a*r+i)*4,!0);if(o===0){if(f++,f>2)return!1}else o<p?(p=o,h=i,g=a):o>m&&(m=o,_=i,v=a)}return p===0||m===0?!1:St(a,h,g,r,i)&&St(o,h,g,r,i)||St(a,_,v,r,i)&&St(o,_,v,r,i)}function St(e,t,n,r,i){let a=Math.max(t-1,0),o=Math.max(n-1,0),s=Math.min(t+1,r-1),c=Math.min(n+1,i-1),l=e[n*r+t],u=+(t===a||t===s||n===o||n===c);for(let i=a;i<=s;i++)for(let a=o;a<=c;a++)if((i!==t||a!==n)&&(u+=+(l===e[a*r+i]),u>2))return!0;return!1}function Ct(e,t,n,r,i){let a=e[n],o=e[n+1],s=e[n+2],c=e[n+3],l=t[r],u=t[r+1],d=t[r+2],f=t[r+3],p=a-l,m=o-u,h=s-d,g=c-f;if(!p&&!m&&!h&&!g)return 0;if(c<255||f<255){let e=48+n%2*159,t=48+159*((n/1.618033988749895|0)%2),r=48+159*((n/2.618033988749895|0)%2);p=(a*c-l*f-e*g)/255,m=(o*c-u*f-t*g)/255,h=(s*c-d*f-r*g)/255}let _=p*.29889531+m*.58662247+h*.11448223;if(i)return _;let v=p*.59597799-m*.2741761-h*.32180189,y=p*.21147017-m*.52261711+h*.31114694,ee=.5053*_*_+.299*v*v+.1957*y*y;return _>0?-ee:ee}function wt(e,t,n,r,i){e[t+0]=n,e[t+1]=r,e[t+2]=i,e[t+3]=255}function Tt(e,t,n,r){let i=255+(e[t]*.29889531+e[t+1]*.58662247+e[t+2]*.11448223-255)*n*e[t+3]/255;wt(r,t,i,i,i)}var Et=E((()=>{})),Dt=D(((e,t)=>{let n=O(`util`),r=O(`stream`),i=t.exports=function(){r.call(this),this._buffers=[],this._buffered=0,this._reads=[],this._paused=!1,this._encoding=`utf8`,this.writable=!0};n.inherits(i,r),i.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t}),process.nextTick(function(){this._process(),this._paused&&this._reads&&this._reads.length>0&&(this._paused=!1,this.emit(`drain`))}.bind(this))},i.prototype.write=function(e,t){if(!this.writable)return this.emit(`error`,Error(`Stream not writable`)),!1;let n;return n=Buffer.isBuffer(e)?e:Buffer.from(e,t||this._encoding),this._buffers.push(n),this._buffered+=n.length,this._process(),this._reads&&this._reads.length===0&&(this._paused=!0),this.writable&&!this._paused},i.prototype.end=function(e,t){e&&this.write(e,t),this.writable=!1,this._buffers&&(this._buffers.length===0?this._end():(this._buffers.push(null),this._process()))},i.prototype.destroySoon=i.prototype.end,i.prototype._end=function(){this._reads.length>0&&this.emit(`error`,Error(`Unexpected end of input`)),this.destroy()},i.prototype.destroy=function(){this._buffers&&(this.writable=!1,this._reads=null,this._buffers=null,this.emit(`close`))},i.prototype._processReadAllowingLess=function(e){this._reads.shift();let t=this._buffers[0];t.length>e.length?(this._buffered-=e.length,this._buffers[0]=t.slice(e.length),e.func.call(this,t.slice(0,e.length))):(this._buffered-=t.length,this._buffers.shift(),e.func.call(this,t))},i.prototype._processRead=function(e){this._reads.shift();let t=0,n=0,r=Buffer.alloc(e.length);for(;t<e.length;){let i=this._buffers[n++],a=Math.min(i.length,e.length-t);i.copy(r,t,0,a),t+=a,a!==i.length&&(this._buffers[--n]=i.slice(a))}n>0&&this._buffers.splice(0,n),this._buffered-=e.length,e.func.call(this,r)},i.prototype._process=function(){try{for(;this._buffered>0&&this._reads&&this._reads.length>0;){let e=this._reads[0];if(e.allowLess)this._processReadAllowingLess(e);else if(this._buffered>=e.length)this._processRead(e);else break}this._buffers&&!this.writable&&this._end()}catch(e){this.emit(`error`,e)}}})),Ot=D((e=>{let t=[{x:[0],y:[0]},{x:[4],y:[0]},{x:[0,4],y:[4]},{x:[2,6],y:[0,4]},{x:[0,2,4,6],y:[2,6]},{x:[1,3,5,7],y:[0,2,4,6]},{x:[0,1,2,3,4,5,6,7],y:[1,3,5,7]}];e.getImagePasses=function(e,n){let r=[],i=e%8,a=n%8,o=(e-i)/8,s=(n-a)/8;for(let e=0;e<t.length;e++){let n=t[e],c=o*n.x.length,l=s*n.y.length;for(let e=0;e<n.x.length&&n.x[e]<i;e++)c++;for(let e=0;e<n.y.length&&n.y[e]<a;e++)l++;c>0&&l>0&&r.push({width:c,height:l,index:e})}return r},e.getInterlaceIterator=function(e){return function(n,r,i){let a=n%t[i].x.length,o=(n-a)/t[i].x.length*8+t[i].x[a],s=r%t[i].y.length,c=(r-s)/t[i].y.length*8+t[i].y[s];return o*4+c*e*4}}})),kt=D(((e,t)=>{t.exports=function(e,t,n){let r=e+t-n,i=Math.abs(r-e),a=Math.abs(r-t),o=Math.abs(r-n);return i<=a&&i<=o?e:a<=o?t:n}})),At=D(((e,t)=>{let n=Ot(),r=kt();function i(e,t,n){let r=e*t;return n!==8&&(r=Math.ceil(r/(8/n))),r}let a=t.exports=function(e,t){let r=e.width,a=e.height,o=e.interlace,s=e.bpp,c=e.depth;if(this.read=t.read,this.write=t.write,this.complete=t.complete,this._imageIndex=0,this._images=[],o){let e=n.getImagePasses(r,a);for(let t=0;t<e.length;t++)this._images.push({byteWidth:i(e[t].width,s,c),height:e[t].height,lineIndex:0})}else this._images.push({byteWidth:i(r,s,c),height:a,lineIndex:0});this._xComparison=c===8?s:c===16?s*2:1};a.prototype.start=function(){this.read(this._images[this._imageIndex].byteWidth+1,this._reverseFilterLine.bind(this))},a.prototype._unFilterType1=function(e,t,n){let r=this._xComparison,i=r-1;for(let a=0;a<n;a++){let n=e[1+a],o=a>i?t[a-r]:0;t[a]=n+o}},a.prototype._unFilterType2=function(e,t,n){let r=this._lastLine;for(let i=0;i<n;i++){let n=e[1+i],a=r?r[i]:0;t[i]=n+a}},a.prototype._unFilterType3=function(e,t,n){let r=this._xComparison,i=r-1,a=this._lastLine;for(let o=0;o<n;o++){let n=e[1+o],s=a?a[o]:0,c=o>i?t[o-r]:0,l=Math.floor((c+s)/2);t[o]=n+l}},a.prototype._unFilterType4=function(e,t,n){let i=this._xComparison,a=i-1,o=this._lastLine;for(let s=0;s<n;s++){let n=e[1+s],c=o?o[s]:0,l=s>a?t[s-i]:0,u=s>a&&o?o[s-i]:0,d=r(l,c,u);t[s]=n+d}},a.prototype._reverseFilterLine=function(e){let t=e[0],n,r=this._images[this._imageIndex],i=r.byteWidth;if(t===0)n=e.slice(1,i+1);else switch(n=Buffer.alloc(i),t){case 1:this._unFilterType1(e,n,i);break;case 2:this._unFilterType2(e,n,i);break;case 3:this._unFilterType3(e,n,i);break;case 4:this._unFilterType4(e,n,i);break;default:throw Error(`Unrecognised filter type - `+t)}this.write(n),r.lineIndex++,r.lineIndex>=r.height?(this._lastLine=null,this._imageIndex++,r=this._images[this._imageIndex]):this._lastLine=n,r?this.read(r.byteWidth+1,this._reverseFilterLine.bind(this)):(this._lastLine=null,this.complete())}})),jt=D(((e,t)=>{let n=O(`util`),r=Dt(),i=At(),a=t.exports=function(e){r.call(this);let t=[],n=this;this._filter=new i(e,{read:this.read.bind(this),write:function(e){t.push(e)},complete:function(){n.emit(`complete`,Buffer.concat(t))}}),this._filter.start()};n.inherits(a,r)})),Mt=D(((e,t)=>{t.exports={PNG_SIGNATURE:[137,80,78,71,13,10,26,10],TYPE_IHDR:1229472850,TYPE_IEND:1229278788,TYPE_IDAT:1229209940,TYPE_PLTE:1347179589,TYPE_tRNS:1951551059,TYPE_gAMA:1732332865,COLORTYPE_GRAYSCALE:0,COLORTYPE_PALETTE:1,COLORTYPE_COLOR:2,COLORTYPE_ALPHA:4,COLORTYPE_PALETTE_COLOR:3,COLORTYPE_COLOR_ALPHA:6,COLORTYPE_TO_BPP_MAP:{0:1,2:3,3:1,4:2,6:4},GAMMA_DIVISION:1e5}})),Nt=D(((e,t)=>{let n=[];(function(){for(let e=0;e<256;e++){let t=e;for(let e=0;e<8;e++)t&1?t=3988292384^t>>>1:t>>>=1;n[e]=t}})();let r=t.exports=function(){this._crc=-1};r.prototype.write=function(e){for(let t=0;t<e.length;t++)this._crc=n[(this._crc^e[t])&255]^this._crc>>>8;return!0},r.prototype.crc32=function(){return this._crc^-1},r.crc32=function(e){let t=-1;for(let r=0;r<e.length;r++)t=n[(t^e[r])&255]^t>>>8;return t^-1}})),Pt=D(((e,t)=>{let n=Mt(),r=Nt(),i=t.exports=function(e,t){this._options=e,e.checkCRC=e.checkCRC!==!1,this._hasIHDR=!1,this._hasIEND=!1,this._emittedHeadersFinished=!1,this._palette=[],this._colorType=0,this._chunks={},this._chunks[n.TYPE_IHDR]=this._handleIHDR.bind(this),this._chunks[n.TYPE_IEND]=this._handleIEND.bind(this),this._chunks[n.TYPE_IDAT]=this._handleIDAT.bind(this),this._chunks[n.TYPE_PLTE]=this._handlePLTE.bind(this),this._chunks[n.TYPE_tRNS]=this._handleTRNS.bind(this),this._chunks[n.TYPE_gAMA]=this._handleGAMA.bind(this),this.read=t.read,this.error=t.error,this.metadata=t.metadata,this.gamma=t.gamma,this.transColor=t.transColor,this.palette=t.palette,this.parsed=t.parsed,this.inflateData=t.inflateData,this.finished=t.finished,this.simpleTransparency=t.simpleTransparency,this.headersFinished=t.headersFinished||function(){}};i.prototype.start=function(){this.read(n.PNG_SIGNATURE.length,this._parseSignature.bind(this))},i.prototype._parseSignature=function(e){let t=n.PNG_SIGNATURE;for(let n=0;n<t.length;n++)if(e[n]!==t[n]){this.error(Error(`Invalid file signature`));return}this.read(8,this._parseChunkBegin.bind(this))},i.prototype._parseChunkBegin=function(e){let t=e.readUInt32BE(0),i=e.readUInt32BE(4),a=``;for(let t=4;t<8;t++)a+=String.fromCharCode(e[t]);let o=!!(e[4]&32);if(!this._hasIHDR&&i!==n.TYPE_IHDR){this.error(Error(`Expected IHDR on beggining`));return}if(this._crc=new r,this._crc.write(Buffer.from(a)),this._chunks[i])return this._chunks[i](t);if(!o){this.error(Error(`Unsupported critical chunk type `+a));return}this.read(t+4,this._skipChunk.bind(this))},i.prototype._skipChunk=function(){this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleChunkEnd=function(){this.read(4,this._parseChunkEnd.bind(this))},i.prototype._parseChunkEnd=function(e){let t=e.readInt32BE(0),n=this._crc.crc32();if(this._options.checkCRC&&n!==t){this.error(Error(`Crc error - `+t+` - `+n));return}this._hasIEND||this.read(8,this._parseChunkBegin.bind(this))},i.prototype._handleIHDR=function(e){this.read(e,this._parseIHDR.bind(this))},i.prototype._parseIHDR=function(e){this._crc.write(e);let t=e.readUInt32BE(0),r=e.readUInt32BE(4),i=e[8],a=e[9],o=e[10],s=e[11],c=e[12];if(i!==8&&i!==4&&i!==2&&i!==1&&i!==16){this.error(Error(`Unsupported bit depth `+i));return}if(!(a in n.COLORTYPE_TO_BPP_MAP)){this.error(Error(`Unsupported color type`));return}if(o!==0){this.error(Error(`Unsupported compression method`));return}if(s!==0){this.error(Error(`Unsupported filter method`));return}if(c!==0&&c!==1){this.error(Error(`Unsupported interlace method`));return}this._colorType=a;let l=n.COLORTYPE_TO_BPP_MAP[this._colorType];this._hasIHDR=!0,this.metadata({width:t,height:r,depth:i,interlace:!!c,palette:!!(a&n.COLORTYPE_PALETTE),color:!!(a&n.COLORTYPE_COLOR),alpha:!!(a&n.COLORTYPE_ALPHA),bpp:l,colorType:a}),this._handleChunkEnd()},i.prototype._handlePLTE=function(e){this.read(e,this._parsePLTE.bind(this))},i.prototype._parsePLTE=function(e){this._crc.write(e);let t=Math.floor(e.length/3);for(let n=0;n<t;n++)this._palette.push([e[n*3],e[n*3+1],e[n*3+2],255]);this.palette(this._palette),this._handleChunkEnd()},i.prototype._handleTRNS=function(e){this.simpleTransparency(),this.read(e,this._parseTRNS.bind(this))},i.prototype._parseTRNS=function(e){if(this._crc.write(e),this._colorType===n.COLORTYPE_PALETTE_COLOR){if(this._palette.length===0){this.error(Error(`Transparency chunk must be after palette`));return}if(e.length>this._palette.length){this.error(Error(`More transparent colors than palette size`));return}for(let t=0;t<e.length;t++)this._palette[t][3]=e[t];this.palette(this._palette)}this._colorType===n.COLORTYPE_GRAYSCALE&&this.transColor([e.readUInt16BE(0)]),this._colorType===n.COLORTYPE_COLOR&&this.transColor([e.readUInt16BE(0),e.readUInt16BE(2),e.readUInt16BE(4)]),this._handleChunkEnd()},i.prototype._handleGAMA=function(e){this.read(e,this._parseGAMA.bind(this))},i.prototype._parseGAMA=function(e){this._crc.write(e),this.gamma(e.readUInt32BE(0)/n.GAMMA_DIVISION),this._handleChunkEnd()},i.prototype._handleIDAT=function(e){this._emittedHeadersFinished||(this._emittedHeadersFinished=!0,this.headersFinished()),this.read(-e,this._parseIDAT.bind(this,e))},i.prototype._parseIDAT=function(e,t){if(this._crc.write(t),this._colorType===n.COLORTYPE_PALETTE_COLOR&&this._palette.length===0)throw Error(`Expected palette not found`);this.inflateData(t);let r=e-t.length;r>0?this._handleIDAT(r):this._handleChunkEnd()},i.prototype._handleIEND=function(e){this.read(e,this._parseIEND.bind(this))},i.prototype._parseIEND=function(e){this._crc.write(e),this._hasIEND=!0,this._handleChunkEnd(),this.finished&&this.finished()}})),Ft=D((e=>{let t=Ot(),n=[function(){},function(e,t,n,r){if(r===t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=255},function(e,t,n,r){if(r+1>=t.length)throw Error(`Ran out of data`);let i=t[r];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=t[r+1]},function(e,t,n,r){if(r+2>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=255},function(e,t,n,r){if(r+3>=t.length)throw Error(`Ran out of data`);e[n]=t[r],e[n+1]=t[r+1],e[n+2]=t[r+2],e[n+3]=t[r+3]}],r=[function(){},function(e,t,n,r){let i=t[0];e[n]=i,e[n+1]=i,e[n+2]=i,e[n+3]=r},function(e,t,n){let r=t[0];e[n]=r,e[n+1]=r,e[n+2]=r,e[n+3]=t[1]},function(e,t,n,r){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=r},function(e,t,n){e[n]=t[0],e[n+1]=t[1],e[n+2]=t[2],e[n+3]=t[3]}];function i(e,t){let n=[],r=0;function i(){if(r===e.length)throw Error(`Ran out of data`);let i=e[r];r++;let a,o,s,c,l,u,d,f;switch(t){default:throw Error(`unrecognised depth`);case 16:d=e[r],r++,n.push((i<<8)+d);break;case 4:d=i&15,f=i>>4,n.push(f,d);break;case 2:l=i&3,u=i>>2&3,d=i>>4&3,f=i>>6&3,n.push(f,d,u,l);break;case 1:a=i&1,o=i>>1&1,s=i>>2&1,c=i>>3&1,l=i>>4&1,u=i>>5&1,d=i>>6&1,f=i>>7&1,n.push(f,d,u,l,c,s,o,a)}}return{get:function(e){for(;n.length<e;)i();let t=n.slice(0,e);return n=n.slice(e),t},resetAfterLine:function(){n.length=0},end:function(){if(r!==e.length)throw Error(`extra data found`)}}}function a(e,t,r,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++)for(let c=0;c<s;c++){let s=r(c,e,l);n[i](t,a,s,o),o+=i}return o}function o(e,t,n,i,a,o){let s=e.width,c=e.height,l=e.index;for(let e=0;e<c;e++){for(let c=0;c<s;c++){let s=a.get(i),u=n(c,e,l);r[i](t,s,u,o)}a.resetAfterLine()}}e.dataToBitMap=function(e,n){let r=n.width,s=n.height,c=n.depth,l=n.bpp,u=n.interlace,d;c!==8&&(d=i(e,c));let f;f=c<=8?Buffer.alloc(r*s*4):new Uint16Array(r*s*4);let p=2**c-1,m=0,h,g;if(u)h=t.getImagePasses(r,s),g=t.getInterlaceIterator(r,s);else{let e=0;g=function(){let t=e;return e+=4,t},h=[{width:r,height:s}]}for(let t=0;t<h.length;t++)c===8?m=a(h[t],f,g,l,e,m):o(h[t],f,g,l,d,p);if(c===8){if(m!==e.length)throw Error(`extra data found`)}else d.end();return f}})),It=D(((e,t)=>{function n(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=i[e[a]];if(!n)throw Error(`index `+e[a]+` not in palette`);for(let e=0;e<4;e++)t[a+e]=n[e];a+=4}}function r(e,t,n,r,i){let a=0;for(let o=0;o<r;o++)for(let r=0;r<n;r++){let n=!1;if(i.length===1?i[0]===e[a]&&(n=!0):i[0]===e[a]&&i[1]===e[a+1]&&i[2]===e[a+2]&&(n=!0),n)for(let e=0;e<4;e++)t[a+e]=0;a+=4}}function i(e,t,n,r,i){let a=2**i-1,o=0;for(let i=0;i<r;i++)for(let r=0;r<n;r++){for(let n=0;n<4;n++)t[o+n]=Math.floor(e[o+n]*255/a+.5);o+=4}}t.exports=function(e,t,a=!1){let o=t.depth,s=t.width,c=t.height,l=t.colorType,u=t.transColor,d=t.palette,f=e;return l===3?n(e,f,s,c,d):(u&&r(e,f,s,c,u),o!==8&&!a&&(o===16&&(f=Buffer.alloc(s*c*4)),i(e,f,s,c,o))),f}})),Lt=D(((e,t)=>{let n=O(`util`),r=O(`zlib`),i=Dt(),a=jt(),o=Pt(),s=Ft(),c=It(),l=t.exports=function(e){i.call(this),this._parser=new o(e,{read:this.read.bind(this),error:this._handleError.bind(this),metadata:this._handleMetaData.bind(this),gamma:this.emit.bind(this,`gamma`),palette:this._handlePalette.bind(this),transColor:this._handleTransColor.bind(this),finished:this._finished.bind(this),inflateData:this._inflateData.bind(this),simpleTransparency:this._simpleTransparency.bind(this),headersFinished:this._headersFinished.bind(this)}),this._options=e,this.writable=!0,this._parser.start()};n.inherits(l,i),l.prototype._handleError=function(e){this.emit(`error`,e),this.writable=!1,this.destroy(),this._inflate&&this._inflate.destroy&&this._inflate.destroy(),this._filter&&(this._filter.destroy(),this._filter.on(`error`,function(){})),this.errord=!0},l.prototype._inflateData=function(e){if(!this._inflate){if(this._bitmapInfo.interlace)this._inflate=r.createInflate(),this._inflate.on(`error`,this.emit.bind(this,`error`)),this._filter.on(`complete`,this._complete.bind(this)),this._inflate.pipe(this._filter);else{let e=((this._bitmapInfo.width*this._bitmapInfo.bpp*this._bitmapInfo.depth+7>>3)+1)*this._bitmapInfo.height,t=Math.max(e,r.Z_MIN_CHUNK);this._inflate=r.createInflate({chunkSize:t});let n=e,i=this.emit.bind(this,`error`);this._inflate.on(`error`,function(e){n&&i(e)}),this._filter.on(`complete`,this._complete.bind(this));let a=this._filter.write.bind(this._filter);this._inflate.on(`data`,function(e){n&&(e.length>n&&(e=e.slice(0,n)),n-=e.length,a(e))}),this._inflate.on(`end`,this._filter.end.bind(this._filter))}}this._inflate.write(e)},l.prototype._handleMetaData=function(e){this._metaData=e,this._bitmapInfo=Object.create(e),this._filter=new a(this._bitmapInfo)},l.prototype._handleTransColor=function(e){this._bitmapInfo.transColor=e},l.prototype._handlePalette=function(e){this._bitmapInfo.palette=e},l.prototype._simpleTransparency=function(){this._metaData.alpha=!0},l.prototype._headersFinished=function(){this.emit(`metadata`,this._metaData)},l.prototype._finished=function(){this.errord||(this._inflate?this._inflate.end():this.emit(`error`,`No Inflate block`))},l.prototype._complete=function(e){if(this.errord)return;let t;try{let n=s.dataToBitMap(e,this._bitmapInfo);t=c(n,this._bitmapInfo,this._options.skipRescale),n=null}catch(e){this._handleError(e);return}this.emit(`parsed`,t)}})),Rt=D(((e,t)=>{let n=Mt();t.exports=function(e,t,r,i){let a=[n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(i.colorType)!==-1;if(i.colorType===i.inputColorType){let t=(function(){let e=new ArrayBuffer(2);return new DataView(e).setInt16(0,256,!0),new Int16Array(e)[0]!==256})();if(i.bitDepth===8||i.bitDepth===16&&t)return e}let o=i.bitDepth===16?new Uint16Array(e.buffer):e,s=255,c=n.COLORTYPE_TO_BPP_MAP[i.inputColorType];c===4&&!i.inputHasAlpha&&(c=3);let l=n.COLORTYPE_TO_BPP_MAP[i.colorType];i.bitDepth===16&&(s=65535,l*=2);let u=Buffer.alloc(t*r*l),d=0,f=0,p=i.bgColor||{};p.red===void 0&&(p.red=s),p.green===void 0&&(p.green=s),p.blue===void 0&&(p.blue=s);function m(){let e,t,r,c=s;switch(i.inputColorType){case n.COLORTYPE_COLOR_ALPHA:c=o[d+3],e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_COLOR:e=o[d],t=o[d+1],r=o[d+2];break;case n.COLORTYPE_ALPHA:c=o[d+1],e=o[d],t=e,r=e;break;case n.COLORTYPE_GRAYSCALE:e=o[d],t=e,r=e;break;default:throw Error(`input color type:`+i.inputColorType+` is not supported at present`)}return i.inputHasAlpha&&(a||(c/=s,e=Math.min(Math.max(Math.round((1-c)*p.red+c*e),0),s),t=Math.min(Math.max(Math.round((1-c)*p.green+c*t),0),s),r=Math.min(Math.max(Math.round((1-c)*p.blue+c*r),0),s))),{red:e,green:t,blue:r,alpha:c}}for(let e=0;e<r;e++)for(let e=0;e<t;e++){let e=m(o,d);switch(i.colorType){case n.COLORTYPE_COLOR_ALPHA:case n.COLORTYPE_COLOR:i.bitDepth===8?(u[f]=e.red,u[f+1]=e.green,u[f+2]=e.blue,a&&(u[f+3]=e.alpha)):(u.writeUInt16BE(e.red,f),u.writeUInt16BE(e.green,f+2),u.writeUInt16BE(e.blue,f+4),a&&u.writeUInt16BE(e.alpha,f+6));break;case n.COLORTYPE_ALPHA:case n.COLORTYPE_GRAYSCALE:{let t=(e.red+e.green+e.blue)/3;i.bitDepth===8?(u[f]=t,a&&(u[f+1]=e.alpha)):(u.writeUInt16BE(t,f),a&&u.writeUInt16BE(e.alpha,f+2));break}default:throw Error(`unrecognised color Type `+i.colorType)}d+=c,f+=l}return u}})),zt=D(((e,t)=>{let n=kt();function r(e,t,n,r,i){for(let a=0;a<n;a++)r[i+a]=e[t+a]}function i(e,t,n){let r=0,i=t+n;for(let n=t;n<i;n++)r+=Math.abs(e[n]);return r}function a(e,t,n,r,i,a){for(let o=0;o<n;o++){let n=o>=a?e[t+o-a]:0,s=e[t+o]-n;r[i+o]=s}}function o(e,t,n,r){let i=0;for(let a=0;a<n;a++){let n=a>=r?e[t+a-r]:0,o=e[t+a]-n;i+=Math.abs(o)}return i}function s(e,t,n,r,i){for(let a=0;a<n;a++){let o=t>0?e[t+a-n]:0,s=e[t+a]-o;r[i+a]=s}}function c(e,t,n){let r=0,i=t+n;for(let a=t;a<i;a++){let i=t>0?e[a-n]:0,o=e[a]-i;r+=Math.abs(o)}return r}function l(e,t,n,r,i,a){for(let o=0;o<n;o++){let s=o>=a?e[t+o-a]:0,c=t>0?e[t+o-n]:0,l=e[t+o]-(s+c>>1);r[i+o]=l}}function u(e,t,n,r){let i=0;for(let a=0;a<n;a++){let o=a>=r?e[t+a-r]:0,s=t>0?e[t+a-n]:0,c=e[t+a]-(o+s>>1);i+=Math.abs(c)}return i}function d(e,t,r,i,a,o){for(let s=0;s<r;s++){let c=s>=o?e[t+s-o]:0,l=t>0?e[t+s-r]:0,u=t>0&&s>=o?e[t+s-(r+o)]:0,d=e[t+s]-n(c,l,u);i[a+s]=d}}function f(e,t,r,i){let a=0;for(let o=0;o<r;o++){let s=o>=i?e[t+o-i]:0,c=t>0?e[t+o-r]:0,l=t>0&&o>=i?e[t+o-(r+i)]:0,u=e[t+o]-n(s,c,l);a+=Math.abs(u)}return a}let p={0:r,1:a,2:s,3:l,4:d},m={0:i,1:o,2:c,3:u,4:f};t.exports=function(e,t,n,r,i){let a;if(!(`filterType`in r)||r.filterType===-1)a=[0,1,2,3,4];else if(typeof r.filterType==`number`)a=[r.filterType];else throw Error(`unrecognised filter types`);r.bitDepth===16&&(i*=2);let o=t*i,s=0,c=0,l=Buffer.alloc((o+1)*n),u=a[0];for(let t=0;t<n;t++){if(a.length>1){let t=1/0;for(let n=0;n<a.length;n++){let r=m[a[n]](e,c,o,i);r<t&&(u=a[n],t=r)}}l[s]=u,s++,p[u](e,c,o,l,s,i),s+=o,c+=o}return l}})),Bt=D(((e,t)=>{let n=Mt(),r=Nt(),i=Rt(),a=zt(),o=O(`zlib`),s=t.exports=function(e){if(this._options=e,e.deflateChunkSize=e.deflateChunkSize||32768,e.deflateLevel=e.deflateLevel==null?9:e.deflateLevel,e.deflateStrategy=e.deflateStrategy==null?3:e.deflateStrategy,e.inputHasAlpha=e.inputHasAlpha==null||e.inputHasAlpha,e.deflateFactory=e.deflateFactory||o.createDeflate,e.bitDepth=e.bitDepth||8,e.colorType=typeof e.colorType==`number`?e.colorType:n.COLORTYPE_COLOR_ALPHA,e.inputColorType=typeof e.inputColorType==`number`?e.inputColorType:n.COLORTYPE_COLOR_ALPHA,[n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.colorType)===-1)throw Error(`option color type:`+e.colorType+` is not supported at present`);if([n.COLORTYPE_GRAYSCALE,n.COLORTYPE_COLOR,n.COLORTYPE_COLOR_ALPHA,n.COLORTYPE_ALPHA].indexOf(e.inputColorType)===-1)throw Error(`option input color type:`+e.inputColorType+` is not supported at present`);if(e.bitDepth!==8&&e.bitDepth!==16)throw Error(`option bit depth:`+e.bitDepth+` is not supported at present`)};s.prototype.getDeflateOptions=function(){return{chunkSize:this._options.deflateChunkSize,level:this._options.deflateLevel,strategy:this._options.deflateStrategy}},s.prototype.createDeflate=function(){return this._options.deflateFactory(this.getDeflateOptions())},s.prototype.filterData=function(e,t,r){let o=i(e,t,r,this._options),s=n.COLORTYPE_TO_BPP_MAP[this._options.colorType];return a(o,t,r,this._options,s)},s.prototype._packChunk=function(e,t){let n=t?t.length:0,i=Buffer.alloc(n+12);return i.writeUInt32BE(n,0),i.writeUInt32BE(e,4),t&&t.copy(i,8),i.writeInt32BE(r.crc32(i.slice(4,i.length-4)),i.length-4),i},s.prototype.packGAMA=function(e){let t=Buffer.alloc(4);return t.writeUInt32BE(Math.floor(e*n.GAMMA_DIVISION),0),this._packChunk(n.TYPE_gAMA,t)},s.prototype.packIHDR=function(e,t){let r=Buffer.alloc(13);return r.writeUInt32BE(e,0),r.writeUInt32BE(t,4),r[8]=this._options.bitDepth,r[9]=this._options.colorType,r[10]=0,r[11]=0,r[12]=0,this._packChunk(n.TYPE_IHDR,r)},s.prototype.packIDAT=function(e){return this._packChunk(n.TYPE_IDAT,e)},s.prototype.packIEND=function(){return this._packChunk(n.TYPE_IEND,null)}})),Vt=D(((e,t)=>{let n=O(`util`),r=O(`stream`),i=Mt(),a=Bt(),o=t.exports=function(e){r.call(this);let t=e||{};this._packer=new a(t),this._deflate=this._packer.createDeflate(),this.readable=!0};n.inherits(o,r),o.prototype.pack=function(e,t,n,r){this.emit(`data`,Buffer.from(i.PNG_SIGNATURE)),this.emit(`data`,this._packer.packIHDR(t,n)),r&&this.emit(`data`,this._packer.packGAMA(r));let a=this._packer.filterData(e,t,n);this._deflate.on(`error`,this.emit.bind(this,`error`)),this._deflate.on(`data`,function(e){this.emit(`data`,this._packer.packIDAT(e))}.bind(this)),this._deflate.on(`end`,function(){this.emit(`data`,this._packer.packIEND()),this.emit(`end`)}.bind(this)),this._deflate.end(a)}})),Ht=D(((e,t)=>{let n=O(`assert`).ok,r=O(`zlib`),i=O(`util`),a=O(`buffer`).kMaxLength;function o(e){if(!(this instanceof o))return new o(e);e&&e.chunkSize<r.Z_MIN_CHUNK&&(e.chunkSize=r.Z_MIN_CHUNK),r.Inflate.call(this,e),this._offset=this._offset===void 0?this._outOffset:this._offset,this._buffer=this._buffer||this._outBuffer,e&&e.maxLength!=null&&(this._maxLength=e.maxLength)}function s(e){return new o(e)}function c(e,t){t&&process.nextTick(t),e._handle&&=(e._handle.close(),null)}o.prototype._processChunk=function(e,t,i){if(typeof i==`function`)return r.Inflate._processChunk.call(this,e,t,i);let o=this,s=e&&e.length,l=this._chunkSize-this._offset,u=this._maxLength,d=0,f=[],p=0,m;this.on(`error`,function(e){m=e});function h(e,t){if(o._hadError)return;let r=l-t;if(n(r>=0,`have should not go down`),r>0){let e=o._buffer.slice(o._offset,o._offset+r);if(o._offset+=r,e.length>u&&(e=e.slice(0,u)),f.push(e),p+=e.length,u-=e.length,u===0)return!1}return(t===0||o._offset>=o._chunkSize)&&(l=o._chunkSize,o._offset=0,o._buffer=Buffer.allocUnsafe(o._chunkSize)),t===0&&(d+=s-e,s=e,!0)}n(this._handle,`zlib binding closed`);let g;do g=this._handle.writeSync(t,e,d,s,this._buffer,this._offset,l),g||=this._writeState;while(!this._hadError&&h(g[0],g[1]));if(this._hadError)throw m;if(p>=a)throw c(this),RangeError(`Cannot create final Buffer. It would be larger than 0x`+a.toString(16)+` bytes`);let _=Buffer.concat(f,p);return c(this),_},i.inherits(o,r.Inflate);function l(e,t){if(typeof t==`string`&&(t=Buffer.from(t)),!(t instanceof Buffer))throw TypeError(`Not a string or buffer`);let n=e._finishFlushFlag;return n??=r.Z_FINISH,e._processChunk(t,n)}function u(e,t){return l(new o(t),e)}t.exports=e=u,e.Inflate=o,e.createInflate=s,e.inflateSync=u})),Ut=D(((e,t)=>{let n=t.exports=function(e){this._buffer=e,this._reads=[]};n.prototype.read=function(e,t){this._reads.push({length:Math.abs(e),allowLess:e<0,func:t})},n.prototype.process=function(){for(;this._reads.length>0&&this._buffer.length;){let e=this._reads[0];if(this._buffer.length&&(this._buffer.length>=e.length||e.allowLess)){this._reads.shift();let t=this._buffer;this._buffer=t.slice(e.length),e.func.call(this,t.slice(0,e.length))}else break}if(this._reads.length>0)throw Error(`There are some read requests waitng on finished stream`);if(this._buffer.length>0)throw Error(`unrecognised content at end of stream`)}})),Wt=D((e=>{let t=Ut(),n=At();e.process=function(e,r){let i=[],a=new t(e);return new n(r,{read:a.read.bind(a),write:function(e){i.push(e)},complete:function(){}}).start(),a.process(),Buffer.concat(i)}})),Gt=D(((e,t)=>{let n=!0,r=O(`zlib`),i=Ht();r.deflateSync||(n=!1);let a=Ut(),o=Wt(),s=Pt(),c=Ft(),l=It();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let u;function d(e){u=e}let f;function p(e){f=e}function m(e){f.transColor=e}function h(e){f.palette=e}function g(){f.alpha=!0}let _;function v(e){_=e}let y=[];function ee(e){y.push(e)}let b=new a(e);if(new s(t,{read:b.read.bind(b),error:d,metadata:p,gamma:v,palette:h,transColor:m,inflateData:ee,simpleTransparency:g}).start(),b.process(),u)throw u;let x=Buffer.concat(y);y.length=0;let te;if(f.interlace)te=r.inflateSync(x);else{let e=((f.width*f.bpp*f.depth+7>>3)+1)*f.height;te=i(x,{chunkSize:e,maxLength:e})}if(x=null,!te||!te.length)throw Error(`bad png - invalid inflate data response`);let S=o.process(te,f);x=null;let ne=c.dataToBitMap(S,f);S=null;let re=l(ne,f,t.skipRescale);return f.data=re,f.gamma=_||0,f}})),Kt=D(((e,t)=>{let n=!0,r=O(`zlib`);r.deflateSync||(n=!1);let i=Mt(),a=Bt();t.exports=function(e,t){if(!n)throw Error(`To use the sync capability of this library in old node versions, please pin pngjs to v2.3.0`);let o=new a(t||{}),s=[];s.push(Buffer.from(i.PNG_SIGNATURE)),s.push(o.packIHDR(e.width,e.height)),e.gamma&&s.push(o.packGAMA(e.gamma));let c=o.filterData(e.data,e.width,e.height),l=r.deflateSync(c,o.getDeflateOptions());if(c=null,!l||!l.length)throw Error(`bad png - invalid compressed data response`);return s.push(o.packIDAT(l)),s.push(o.packIEND()),Buffer.concat(s)}})),qt=D((e=>{let t=Gt(),n=Kt();e.read=function(e,n){return t(e,n||{})},e.write=function(e,t){return n(e,t)}})),Jt=D((e=>{let t=O(`util`),n=O(`stream`),r=Lt(),i=Vt(),a=qt(),o=e.PNG=function(e){n.call(this),e||={},this.width=e.width|0,this.height=e.height|0,this.data=this.width>0&&this.height>0?Buffer.alloc(4*this.width*this.height):null,e.fill&&this.data&&this.data.fill(0),this.gamma=0,this.readable=this.writable=!0,this._parser=new r(e),this._parser.on(`error`,this.emit.bind(this,`error`)),this._parser.on(`close`,this._handleClose.bind(this)),this._parser.on(`metadata`,this._metadata.bind(this)),this._parser.on(`gamma`,this._gamma.bind(this)),this._parser.on(`parsed`,function(e){this.data=e,this.emit(`parsed`,e)}.bind(this)),this._packer=new i(e),this._packer.on(`data`,this.emit.bind(this,`data`)),this._packer.on(`end`,this.emit.bind(this,`end`)),this._parser.on(`close`,this._handleClose.bind(this)),this._packer.on(`error`,this.emit.bind(this,`error`))};t.inherits(o,n),o.sync=a,o.prototype.pack=function(){return!this.data||!this.data.length?(this.emit(`error`,`No data provided`),this):(process.nextTick(function(){this._packer.pack(this.data,this.width,this.height,this.gamma)}.bind(this)),this)},o.prototype.parse=function(e,t){if(t){let e,n;e=function(e){this.removeListener(`error`,n),this.data=e,t(null,this)}.bind(this),n=function(n){this.removeListener(`parsed`,e),t(n,null)}.bind(this),this.once(`parsed`,e),this.once(`error`,n)}return this.end(e),this},o.prototype.write=function(e){return this._parser.write(e),!0},o.prototype.end=function(e){this._parser.end(e)},o.prototype._metadata=function(e){this.width=e.width,this.height=e.height,this.emit(`metadata`,e)},o.prototype._gamma=function(e){this.gamma=e},o.prototype._handleClose=function(){!this._parser.writable&&!this._packer.readable&&this.emit(`close`)},o.bitblt=function(e,t,n,r,i,a,o,s){if(n|=0,r|=0,i|=0,a|=0,o|=0,s|=0,n>e.width||r>e.height||n+i>e.width||r+a>e.height)throw Error(`bitblt reading outside image`);if(o>t.width||s>t.height||o+i>t.width||s+a>t.height)throw Error(`bitblt writing outside image`);for(let c=0;c<a;c++)e.data.copy(t.data,(s+c)*t.width+o<<2,(r+c)*e.width+n<<2,(r+c)*e.width+n+i<<2)},o.prototype.bitblt=function(e,t,n,r,i,a,s){return o.bitblt(this,e,t,n,r,i,a,s),this},o.adjustGamma=function(e){if(e.gamma){for(let t=0;t<e.height;t++)for(let n=0;n<e.width;n++){let r=e.width*t+n<<2;for(let t=0;t<3;t++){let n=e.data[r+t]/255;n**=1/2.2/e.gamma,e.data[r+t]=Math.round(n*255)}}e.gamma=0}},o.prototype.adjustGamma=function(){o.adjustGamma(this)}}));function M(e,t,n){function r(n,r){if(n._zod||Object.defineProperty(n,"_zod",{value:{def:r,constr:o,traits:new Set},enumerable:!1}),n._zod.traits.has(e))return;n._zod.traits.add(e),t(n,r);let i=o.prototype,a=Object.keys(i);for(let e=0;e<a.length;e++){let t=a[e];t in n||(n[t]=i[t].bind(n))}}let i=n?.Parent??Object;class a extends i{}Object.defineProperty(a,"name",{value:e});function o(e){var t;let i=n?.Parent?new a:this;r(i,e),(t=i._zod).deferred??(t.deferred=[]);for(let e of i._zod.deferred)e();return i}return Object.defineProperty(o,"init",{value:r}),Object.defineProperty(o,Symbol.hasInstance,{value:t=>n?.Parent&&t instanceof n.Parent?!0:t?._zod?.traits?.has(e)}),Object.defineProperty(o,"name",{value:e}),o}function Yt(e){return e&&Object.assign(Qt,e),Qt}var Xt,Zt,Qt,$t=E((()=>{Object.freeze({status:`aborted`}),Xt=class extends Error{constructor(){super(`Encountered Promise during synchronous parse. Use .parseAsync() instead.`)}},Zt=class extends Error{constructor(e){super(`Encountered unidirectional transform during encode: ${e}`),this.name=`ZodEncodeError`}},Qt={}}));function en(e){let t=Object.values(e).filter(e=>typeof e==`number`);return Object.entries(e).filter(([e,n])=>t.indexOf(+e)===-1).map(([e,t])=>t)}function tn(e,t){return typeof t==`bigint`?t.toString():t}function nn(e){return{get value(){{let t=e();return Object.defineProperty(this,"value",{value:t}),t}}}}function rn(e){return e==null}function an(e){let t=+!!e.startsWith(`^`),n=e.endsWith(`$`)?e.length-1:e.length;return e.slice(t,n)}function on(e,t){let n=(e.toString().split(`.`)[1]||``).length,r=t.toString(),i=(r.split(`.`)[1]||``).length;if(i===0&&/\d?e-\d?/.test(r)){let e=r.match(/\d?e-(\d?)/);e?.[1]&&(i=Number.parseInt(e[1]))}let a=n>i?n:i;return Number.parseInt(e.toFixed(a).replace(`.`,``))%Number.parseInt(t.toFixed(a).replace(`.`,``))/10**a}function N(e,t,n){let r;Object.defineProperty(e,t,{get(){if(r!==An)return r===void 0&&(r=An,r=n()),r},set(n){Object.defineProperty(e,t,{value:n})},configurable:!0})}function sn(e,t,n){Object.defineProperty(e,t,{value:n,writable:!0,enumerable:!0,configurable:!0})}function cn(...e){let t={};for(let n of e){let e=Object.getOwnPropertyDescriptors(n);Object.assign(t,e)}return Object.defineProperties({},t)}function ln(e){return JSON.stringify(e)}function un(e){return e.toLowerCase().trim().replace(/[^\w\s-]/g,``).replace(/[\s_-]+/g,`-`).replace(/^-+|-+$/g,``)}function dn(e){return typeof e==`object`&&!!e&&!Array.isArray(e)}function fn(e){if(dn(e)===!1)return!1;let t=e.constructor;if(t===void 0||typeof t!=`function`)return!0;let n=t.prototype;return dn(n)!==!1&&Object.prototype.hasOwnProperty.call(n,`isPrototypeOf`)!==!1}function pn(e){return fn(e)?{...e}:Array.isArray(e)?[...e]:e}function mn(e){return e.replace(/[.*+?^${}()|[\]\\]/g,`\\$&`)}function hn(e,t,n){let r=new e._zod.constr(t??e._zod.def);return(!t||n?.parent)&&(r._zod.parent=e),r}function P(e){let t=e;if(!t)return{};if(typeof t==`string`)return{error:()=>t};if(t?.message!==void 0){if(t?.error!==void 0)throw Error("Cannot specify both `message` and `error` params");t.error=t.message}return delete t.message,typeof t.error==`string`?{...t,error:()=>t.error}:t}function gn(e){return Object.keys(e).filter(t=>e[t]._zod.optin===`optional`&&e[t]._zod.optout===`optional`)}function _n(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.pick() cannot be used on object schemas containing refinements`);return hn(e,cn(e._zod.def,{get shape(){let e={};for(let r in t){if(!(r in n.shape))throw Error(`Unrecognized key: "${r}"`);t[r]&&(e[r]=n.shape[r])}return sn(this,`shape`,e),e},checks:[]}))}function vn(e,t){let n=e._zod.def,r=n.checks;if(r&&r.length>0)throw Error(`.omit() cannot be used on object schemas containing refinements`);return hn(e,cn(e._zod.def,{get shape(){let r={...e._zod.def.shape};for(let e in t){if(!(e in n.shape))throw Error(`Unrecognized key: "${e}"`);t[e]&&delete r[e]}return sn(this,`shape`,r),r},checks:[]}))}function yn(e,t){if(!fn(t))throw Error(`Invalid input to extend: expected a plain object`);let n=e._zod.def.checks;if(n&&n.length>0){let n=e._zod.def.shape;for(let e in t)if(Object.getOwnPropertyDescriptor(n,e)!==void 0)throw Error("Cannot overwrite keys on object schemas containing refinements. Use `.safeExtend()` instead.")}return hn(e,cn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return sn(this,`shape`,n),n}}))}function bn(e,t){if(!fn(t))throw Error(`Invalid input to safeExtend: expected a plain object`);return hn(e,cn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t};return sn(this,`shape`,n),n}}))}function xn(e,t){return hn(e,cn(e._zod.def,{get shape(){let n={...e._zod.def.shape,...t._zod.def.shape};return sn(this,`shape`,n),n},get catchall(){return t._zod.def.catchall},checks:[]}))}function Sn(e,t,n){let r=t._zod.def.checks;if(r&&r.length>0)throw Error(`.partial() cannot be used on object schemas containing refinements`);return hn(t,cn(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in r))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t])}else for(let t in r)i[t]=e?new e({type:`optional`,innerType:r[t]}):r[t];return sn(this,`shape`,i),i},checks:[]}))}function Cn(e,t,n){return hn(t,cn(t._zod.def,{get shape(){let r=t._zod.def.shape,i={...r};if(n)for(let t in n){if(!(t in i))throw Error(`Unrecognized key: "${t}"`);n[t]&&(i[t]=new e({type:`nonoptional`,innerType:r[t]}))}else for(let t in r)i[t]=new e({type:`nonoptional`,innerType:r[t]});return sn(this,`shape`,i),i}}))}function wn(e,t=0){if(e.aborted===!0)return!0;for(let n=t;n<e.issues.length;n++)if(e.issues[n]?.continue!==!0)return!0;return!1}function Tn(e,t){return t.map(t=>{var n;return(n=t).path??(n.path=[]),t.path.unshift(e),t})}function En(e){return typeof e==`string`?e:e?.message}function Dn(e,t,n){let r={...e,path:e.path??[]};return e.message||(r.message=En(e.inst?._zod.def?.error?.(e))??En(t?.error?.(e))??En(n.customError?.(e))??En(n.localeError?.(e))??`Invalid input`),delete r.inst,delete r.continue,t?.reportInput||delete r.input,r}function On(e){return Array.isArray(e)?`array`:typeof e==`string`?`string`:`unknown`}function kn(...e){let[t,n,r]=e;return typeof t==`string`?{message:t,code:`custom`,input:n,inst:r}:{...t}}var An,jn,Mn,Nn,Pn,Fn=E((()=>{An=Symbol(`evaluating`),jn=`captureStackTrace`in Error?Error.captureStackTrace:(...e)=>{},Mn=nn(()=>{if(typeof navigator<`u`&&navigator?.userAgent?.includes(`Cloudflare`))return!1;try{return Function(``),!0}catch{return!1}}),Nn=new Set([`string`,`number`,`symbol`]),Pn={safeint:[-(2**53-1),2**53-1],int32:[-2147483648,2147483647],uint32:[0,4294967295],float32:[-34028234663852886e22,34028234663852886e22],float64:[-Number.MAX_VALUE,Number.MAX_VALUE]}}));function In(e,t=e=>e.message){let n={},r=[];for(let i of e.issues)i.path.length>0?(n[i.path[0]]=n[i.path[0]]||[],n[i.path[0]].push(t(i))):r.push(t(i));return{formErrors:r,fieldErrors:n}}function Ln(e,t=e=>e.message){let n={_errors:[]},r=e=>{for(let i of e.issues)if(i.code===`invalid_union`&&i.errors.length)i.errors.map(e=>r({issues:e}));else if(i.code===`invalid_key`)r({issues:i.issues});else if(i.code===`invalid_element`)r({issues:i.issues});else if(i.path.length===0)n._errors.push(t(i));else{let e=n,r=0;for(;r<i.path.length;){let n=i.path[r];r===i.path.length-1?(e[n]=e[n]||{_errors:[]},e[n]._errors.push(t(i))):e[n]=e[n]||{_errors:[]},e=e[n],r++}}};return r(e),n}var Rn,zn,Bn,Vn=E((()=>{$t(),Fn(),Rn=(e,t)=>{e.name=`$ZodError`,Object.defineProperty(e,"_zod",{value:e._zod,enumerable:!1}),Object.defineProperty(e,"issues",{value:t,enumerable:!1}),e.message=JSON.stringify(t,tn,2),Object.defineProperty(e,"toString",{value:()=>e.message,enumerable:!1})},zn=M(`$ZodError`,Rn),Bn=M(`$ZodError`,Rn,{Parent:Error})})),Hn,Un,Wn,Gn,Kn,qn,Jn,Yn,Xn,Zn,Qn,$n,er,tr,nr=E((()=>{$t(),Vn(),Fn(),Hn=e=>(t,n,r,i)=>{let a=r?Object.assign(r,{async:!1}):{async:!1},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise)throw new Xt;if(o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Dn(e,a,Yt())));throw jn(t,i?.callee),t}return o.value},Un=e=>async(t,n,r,i)=>{let a=r?Object.assign(r,{async:!0}):{async:!0},o=t._zod.run({value:n,issues:[]},a);if(o instanceof Promise&&(o=await o),o.issues.length){let t=new((i?.Err)??e)(o.issues.map(e=>Dn(e,a,Yt())));throw jn(t,i?.callee),t}return o.value},Wn=e=>(t,n,r)=>{let i=r?{...r,async:!1}:{async:!1},a=t._zod.run({value:n,issues:[]},i);if(a instanceof Promise)throw new Xt;return a.issues.length?{success:!1,error:new(e??zn)(a.issues.map(e=>Dn(e,i,Yt())))}:{success:!0,data:a.value}},Gn=Wn(Bn),Kn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{async:!0}):{async:!0},a=t._zod.run({value:n,issues:[]},i);return a instanceof Promise&&(a=await a),a.issues.length?{success:!1,error:new e(a.issues.map(e=>Dn(e,i,Yt())))}:{success:!0,data:a.value}},qn=Kn(Bn),Jn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Hn(e)(t,n,i)},Yn=e=>(t,n,r)=>Hn(e)(t,n,r),Xn=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Un(e)(t,n,i)},Zn=e=>async(t,n,r)=>Un(e)(t,n,r),Qn=e=>(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Wn(e)(t,n,i)},$n=e=>(t,n,r)=>Wn(e)(t,n,r),er=e=>async(t,n,r)=>{let i=r?Object.assign(r,{direction:`backward`}):{direction:`backward`};return Kn(e)(t,n,i)},tr=e=>async(t,n,r)=>Kn(e)(t,n,r)}));function rr(){return new RegExp(_r,`u`)}function ir(e){let t=`(?:[01]\\d|2[0-3]):[0-5]\\d`;return typeof e.precision==`number`?e.precision===-1?`${t}`:e.precision===0?`${t}:[0-5]\\d`:`${t}:[0-5]\\d\\.\\d{${e.precision}}`:`${t}(?::[0-5]\\d(?:\\.\\d+)?)?`}function ar(e){return RegExp(`^${ir(e)}$`)}function or(e){let t=ir({precision:e.precision}),n=[`Z`];e.local&&n.push(``),e.offset&&n.push(`([+-](?:[01]\\d|2[0-3]):[0-5]\\d)`);let r=`${t}(?:${n.join(`|`)})`;return RegExp(`^${Tr}T(?:${r})$`)}var sr,cr,lr,ur,dr,fr,pr,mr,hr,gr,_r,vr,yr,br,xr,Sr,Cr,wr,Tr,Er,Dr,Or,kr,Ar,jr,Mr,Nr=E((()=>{sr=/^[cC][^\s-]{8,}$/,cr=/^[0-9a-z]+$/,lr=/^[0-9A-HJKMNP-TV-Za-hjkmnp-tv-z]{26}$/,ur=/^[0-9a-vA-V]{20}$/,dr=/^[A-Za-z0-9]{27}$/,fr=/^[a-zA-Z0-9_-]{21}$/,pr=/^P(?:(\d+W)|(?!.*W)(?=\d|T\d)(\d+Y)?(\d+M)?(\d+D)?(T(?=\d)(\d+H)?(\d+M)?(\d+([.,]\d+)?S)?)?)$/,mr=/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12})$/,hr=e=>e?RegExp(`^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-${e}[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12})$`):/^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$/,gr=/^(?!\.)(?!.*\.\.)([A-Za-z0-9_'+\-\.]*)[A-Za-z0-9_+-]@([A-Za-z0-9][A-Za-z0-9\-]*\.)+[A-Za-z]{2,}$/,_r=`^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$`,vr=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,yr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:))$/,br=/^((25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/([0-9]|[1-2][0-9]|3[0-2])$/,xr=/^(([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}|::|([0-9a-fA-F]{1,4})?::([0-9a-fA-F]{1,4}:?){0,6})\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,Sr=/^$|^(?:[0-9a-zA-Z+/]{4})*(?:(?:[0-9a-zA-Z+/]{2}==)|(?:[0-9a-zA-Z+/]{3}=))?$/,Cr=/^[A-Za-z0-9_-]*$/,wr=/^\+[1-9]\d{6,14}$/,Tr=`(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))`,Er=RegExp(`^${Tr}$`),Dr=e=>{let t=e?`[\\s\\S]{${e?.minimum??0},${e?.maximum??``}}`:`[\\s\\S]*`;return RegExp(`^${t}$`)},Or=/^-?\d+$/,kr=/^-?\d+(?:\.\d+)?$/,Ar=/^(?:true|false)$/i,jr=/^[^A-Z]*$/,Mr=/^[^a-z]*$/})),F,Pr,Fr,Ir,Lr,Rr,zr,Br,Vr,Hr,Ur,Wr,Gr,Kr,qr,Jr,Yr,Xr=E((()=>{$t(),Nr(),Fn(),F=M(`$ZodCheck`,(e,t)=>{var n;e._zod??={},e._zod.def=t,(n=e._zod).onattach??(n.onattach=[])}),Pr={number:`number`,bigint:`bigint`,object:`date`},Fr=M(`$ZodCheckLessThan`,(e,t)=>{F.init(e,t);let n=Pr[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.maximum:n.exclusiveMaximum)??1/0;t.value<r&&(t.inclusive?n.maximum=t.value:n.exclusiveMaximum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value<=t.value:r.value<t.value)||r.issues.push({origin:n,code:`too_big`,maximum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Ir=M(`$ZodCheckGreaterThan`,(e,t)=>{F.init(e,t);let n=Pr[typeof t.value];e._zod.onattach.push(e=>{let n=e._zod.bag,r=(t.inclusive?n.minimum:n.exclusiveMinimum)??-1/0;t.value>r&&(t.inclusive?n.minimum=t.value:n.exclusiveMinimum=t.value)}),e._zod.check=r=>{(t.inclusive?r.value>=t.value:r.value>t.value)||r.issues.push({origin:n,code:`too_small`,minimum:typeof t.value==`object`?t.value.getTime():t.value,input:r.value,inclusive:t.inclusive,inst:e,continue:!t.abort})}}),Lr=M(`$ZodCheckMultipleOf`,(e,t)=>{F.init(e,t),e._zod.onattach.push(e=>{var n;(n=e._zod.bag).multipleOf??(n.multipleOf=t.value)}),e._zod.check=n=>{if(typeof n.value!=typeof t.value)throw Error(`Cannot mix number and bigint in multiple_of check.`);(typeof n.value==`bigint`?n.value%t.value===BigInt(0):on(n.value,t.value)===0)||n.issues.push({origin:typeof n.value,code:`not_multiple_of`,divisor:t.value,input:n.value,inst:e,continue:!t.abort})}}),Rr=M(`$ZodCheckNumberFormat`,(e,t)=>{F.init(e,t),t.format=t.format||`float64`;let n=t.format?.includes(`int`),r=n?`int`:`number`,[i,a]=Pn[t.format];e._zod.onattach.push(e=>{let r=e._zod.bag;r.format=t.format,r.minimum=i,r.maximum=a,n&&(r.pattern=Or)}),e._zod.check=o=>{let s=o.value;if(n){if(!Number.isInteger(s)){o.issues.push({expected:r,format:t.format,code:`invalid_type`,continue:!1,input:s,inst:e});return}if(!Number.isSafeInteger(s)){s>0?o.issues.push({input:s,code:`too_big`,maximum:2**53-1,note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort}):o.issues.push({input:s,code:`too_small`,minimum:-(2**53-1),note:`Integers must be within the safe integer range.`,inst:e,origin:r,inclusive:!0,continue:!t.abort});return}}s<i&&o.issues.push({origin:`number`,input:s,code:`too_small`,minimum:i,inclusive:!0,inst:e,continue:!t.abort}),s>a&&o.issues.push({origin:`number`,input:s,code:`too_big`,maximum:a,inclusive:!0,inst:e,continue:!t.abort})}}),zr=M(`$ZodCheckMaxLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!rn(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.maximum??1/0;t.maximum<n&&(e._zod.bag.maximum=t.maximum)}),e._zod.check=n=>{let r=n.value;if(r.length<=t.maximum)return;let i=On(r);n.issues.push({origin:i,code:`too_big`,maximum:t.maximum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Br=M(`$ZodCheckMinLength`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!rn(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag.minimum??-1/0;t.minimum>n&&(e._zod.bag.minimum=t.minimum)}),e._zod.check=n=>{let r=n.value;if(r.length>=t.minimum)return;let i=On(r);n.issues.push({origin:i,code:`too_small`,minimum:t.minimum,inclusive:!0,input:r,inst:e,continue:!t.abort})}}),Vr=M(`$ZodCheckLengthEquals`,(e,t)=>{var n;F.init(e,t),(n=e._zod.def).when??(n.when=e=>{let t=e.value;return!rn(t)&&t.length!==void 0}),e._zod.onattach.push(e=>{let n=e._zod.bag;n.minimum=t.length,n.maximum=t.length,n.length=t.length}),e._zod.check=n=>{let r=n.value,i=r.length;if(i===t.length)return;let a=On(r),o=i>t.length;n.issues.push({origin:a,...o?{code:`too_big`,maximum:t.length}:{code:`too_small`,minimum:t.length},inclusive:!0,exact:!0,input:n.value,inst:e,continue:!t.abort})}}),Hr=M(`$ZodCheckStringFormat`,(e,t)=>{var n,r;F.init(e,t),e._zod.onattach.push(e=>{let n=e._zod.bag;n.format=t.format,t.pattern&&(n.patterns??=new Set,n.patterns.add(t.pattern))}),t.pattern?(n=e._zod).check??(n.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:t.format,input:n.value,...t.pattern?{pattern:t.pattern.toString()}:{},inst:e,continue:!t.abort})}):(r=e._zod).check??(r.check=()=>{})}),Ur=M(`$ZodCheckRegex`,(e,t)=>{Hr.init(e,t),e._zod.check=n=>{t.pattern.lastIndex=0,!t.pattern.test(n.value)&&n.issues.push({origin:`string`,code:`invalid_format`,format:`regex`,input:n.value,pattern:t.pattern.toString(),inst:e,continue:!t.abort})}}),Wr=M(`$ZodCheckLowerCase`,(e,t)=>{t.pattern??=jr,Hr.init(e,t)}),Gr=M(`$ZodCheckUpperCase`,(e,t)=>{t.pattern??=Mr,Hr.init(e,t)}),Kr=M(`$ZodCheckIncludes`,(e,t)=>{F.init(e,t);let n=mn(t.includes),r=new RegExp(typeof t.position==`number`?`^.{${t.position}}${n}`:n);t.pattern=r,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(r)}),e._zod.check=n=>{n.value.includes(t.includes,t.position)||n.issues.push({origin:`string`,code:`invalid_format`,format:`includes`,includes:t.includes,input:n.value,inst:e,continue:!t.abort})}}),qr=M(`$ZodCheckStartsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`^${mn(t.prefix)}.*`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.startsWith(t.prefix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`starts_with`,prefix:t.prefix,input:n.value,inst:e,continue:!t.abort})}}),Jr=M(`$ZodCheckEndsWith`,(e,t)=>{F.init(e,t);let n=RegExp(`.*${mn(t.suffix)}$`);t.pattern??=n,e._zod.onattach.push(e=>{let t=e._zod.bag;t.patterns??=new Set,t.patterns.add(n)}),e._zod.check=n=>{n.value.endsWith(t.suffix)||n.issues.push({origin:`string`,code:`invalid_format`,format:`ends_with`,suffix:t.suffix,input:n.value,inst:e,continue:!t.abort})}}),Yr=M(`$ZodCheckOverwrite`,(e,t)=>{F.init(e,t),e._zod.check=e=>{e.value=t.tx(e.value)}})})),Zr,Qr=E((()=>{Zr=class{constructor(e=[]){this.content=[],this.indent=0,this&&(this.args=e)}indented(e){this.indent+=1,e(this),--this.indent}write(e){if(typeof e==`function`){e(this,{execution:`sync`}),e(this,{execution:`async`});return}let t=e.split(`
251
251
  `).filter(e=>e),n=Math.min(...t.map(e=>e.length-e.trimStart().length)),r=t.map(e=>e.slice(n)).map(e=>` `.repeat(this.indent*2)+e);for(let e of r)this.content.push(e)}compile(){let e=Function,t=this?.args,n=[...(this?.content??[``]).map(e=>` ${e}`)];return new e(...t,n.join(`
252
- `))}}})),Xr,Zr=E((()=>{Xr={major:4,minor:3,patch:6}}));function Qr(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}function $r(e){if(!yr.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return Qr(t.padEnd(Math.ceil(t.length/4)*4,`=`))}function ei(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}function ti(e,t,n){e.issues.length&&t.issues.push(...xn(n,e.issues)),t.value[n]=e.value}function ni(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...xn(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function ri(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=fn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function ii(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>ni(e,n,i,t,u))):ni(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}function ai(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!bn(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Cn(e,r,Gt())))}),t)}function oi(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(cn(e)&&cn(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=oi(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=oi(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function si(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),bn(e))return e;let o=oi(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}function ci(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}function li(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function ui(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function di(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}function fi(e){return e.value=Object.freeze(e.value),e}function pi(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(Tn(e))}}var F,mi,I,hi,gi,_i,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la=E((()=>{qr(),Yt(),Yr(),Qn(),kr(),jn(),Zr(),F=M(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=Xr;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=bn(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new Kt;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=bn(e,t))});else{if(e.issues.length===t)continue;r||=bn(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(bn(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new Kt;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new Kt;return o.then(e=>t(e,r,a))}return t(o,r,a)}}N(e,`~standard`,()=>({validate:t=>{try{let n=Vn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return Un(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),mi=M(`$ZodString`,(e,t)=>{F.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Cr(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),I=M(`$ZodStringFormat`,(e,t)=>{zr.init(e,t),mi.init(e,t)}),hi=M(`$ZodGUID`,(e,t)=>{t.pattern??=ur,I.init(e,t)}),gi=M(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=dr(e)}else t.pattern??=dr();I.init(e,t)}),_i=M(`$ZodEmail`,(e,t)=>{t.pattern??=fr,I.init(e,t)}),vi=M(`$ZodURL`,(e,t)=>{I.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),n.value=t.normalize?i.href:r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),yi=M(`$ZodEmoji`,(e,t)=>{t.pattern??=$n(),I.init(e,t)}),bi=M(`$ZodNanoID`,(e,t)=>{t.pattern??=cr,I.init(e,t)}),xi=M(`$ZodCUID`,(e,t)=>{t.pattern??=rr,I.init(e,t)}),Si=M(`$ZodCUID2`,(e,t)=>{t.pattern??=ir,I.init(e,t)}),Ci=M(`$ZodULID`,(e,t)=>{t.pattern??=ar,I.init(e,t)}),wi=M(`$ZodXID`,(e,t)=>{t.pattern??=or,I.init(e,t)}),Ti=M(`$ZodKSUID`,(e,t)=>{t.pattern??=sr,I.init(e,t)}),Ei=M(`$ZodISODateTime`,(e,t)=>{t.pattern??=nr(t),I.init(e,t)}),Di=M(`$ZodISODate`,(e,t)=>{t.pattern??=Sr,I.init(e,t)}),Oi=M(`$ZodISOTime`,(e,t)=>{t.pattern??=tr(t),I.init(e,t)}),ki=M(`$ZodISODuration`,(e,t)=>{t.pattern??=lr,I.init(e,t)}),Ai=M(`$ZodIPv4`,(e,t)=>{t.pattern??=mr,I.init(e,t),e._zod.bag.format=`ipv4`}),ji=M(`$ZodIPv6`,(e,t)=>{t.pattern??=hr,I.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Mi=M(`$ZodCIDRv4`,(e,t)=>{t.pattern??=gr,I.init(e,t)}),Ni=M(`$ZodCIDRv6`,(e,t)=>{t.pattern??=_r,I.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}}),Pi=M(`$ZodBase64`,(e,t)=>{t.pattern??=vr,I.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{Qr(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),Fi=M(`$ZodBase64URL`,(e,t)=>{t.pattern??=yr,I.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{$r(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),Ii=M(`$ZodE164`,(e,t)=>{t.pattern??=br,I.init(e,t)}),Li=M(`$ZodJWT`,(e,t)=>{I.init(e,t),e._zod.check=n=>{ei(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Ri=M(`$ZodNumber`,(e,t)=>{F.init(e,t),e._zod.pattern=e._zod.bag.pattern??Tr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),zi=M(`$ZodNumberFormat`,(e,t)=>{Fr.init(e,t),Ri.init(e,t)}),Bi=M(`$ZodBoolean`,(e,t)=>{F.init(e,t),e._zod.pattern=Er,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Vi=M(`$ZodUnknown`,(e,t)=>{F.init(e,t),e._zod.parse=e=>e}),Hi=M(`$ZodNever`,(e,t)=>{F.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)}),Ui=M(`$ZodArray`,(e,t)=>{F.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>ti(t,n,e))):ti(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}}),Wi=M(`$ZodObject`,(e,t)=>{if(F.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=Qt(()=>ri(t));N(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=sn,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>ni(n,t,e,s,r))):ni(i,t,e,s,r)}return i?ii(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Gi=M(`$ZodObjectJIT`,(e,t)=>{Wi.init(e,t);let n=e._zod.parse,r=Qt(()=>ri(t)),i=e=>{let t=new Jr([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=an(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=an(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
252
+ `))}}})),$r,ei=E((()=>{$r={major:4,minor:3,patch:6}}));function ti(e){if(e===``)return!0;if(e.length%4!=0)return!1;try{return atob(e),!0}catch{return!1}}function ni(e){if(!Cr.test(e))return!1;let t=e.replace(/[-_]/g,e=>e===`-`?`+`:`/`);return ti(t.padEnd(Math.ceil(t.length/4)*4,`=`))}function ri(e,t=null){try{let n=e.split(`.`);if(n.length!==3)return!1;let[r]=n;if(!r)return!1;let i=JSON.parse(atob(r));return!(`typ`in i&&i?.typ!==`JWT`||!i.alg||t&&(!(`alg`in i)||i.alg!==t))}catch{return!1}}function ii(e,t,n){e.issues.length&&t.issues.push(...Tn(n,e.issues)),t.value[n]=e.value}function ai(e,t,n,r,i){if(e.issues.length){if(i&&!(n in r))return;t.issues.push(...Tn(n,e.issues))}e.value===void 0?n in r&&(t.value[n]=void 0):t.value[n]=e.value}function oi(e){let t=Object.keys(e.shape);for(let n of t)if(!e.shape?.[n]?._zod?.traits?.has(`$ZodType`))throw Error(`Invalid element at key "${n}": expected a Zod schema`);let n=gn(e.shape);return{...e,keys:t,keySet:new Set(t),numKeys:t.length,optionalKeys:new Set(n)}}function si(e,t,n,r,i,a){let o=[],s=i.keySet,c=i.catchall._zod,l=c.def.type,u=c.optout===`optional`;for(let i in t){if(s.has(i))continue;if(l===`never`){o.push(i);continue}let a=c.run({value:t[i],issues:[]},r);a instanceof Promise?e.push(a.then(e=>ai(e,n,i,t,u))):ai(a,n,i,t,u)}return o.length&&n.issues.push({code:`unrecognized_keys`,keys:o,input:t,inst:a}),e.length?Promise.all(e).then(()=>n):n}function ci(e,t,n,r){for(let n of e)if(n.issues.length===0)return t.value=n.value,t;let i=e.filter(e=>!wn(e));return i.length===1?(t.value=i[0].value,i[0]):(t.issues.push({code:`invalid_union`,input:t.value,inst:n,errors:e.map(e=>e.issues.map(e=>Dn(e,r,Yt())))}),t)}function li(e,t){if(e===t||e instanceof Date&&t instanceof Date&&+e==+t)return{valid:!0,data:e};if(fn(e)&&fn(t)){let n=Object.keys(t),r=Object.keys(e).filter(e=>n.indexOf(e)!==-1),i={...e,...t};for(let n of r){let r=li(e[n],t[n]);if(!r.valid)return{valid:!1,mergeErrorPath:[n,...r.mergeErrorPath]};i[n]=r.data}return{valid:!0,data:i}}if(Array.isArray(e)&&Array.isArray(t)){if(e.length!==t.length)return{valid:!1,mergeErrorPath:[]};let n=[];for(let r=0;r<e.length;r++){let i=e[r],a=t[r],o=li(i,a);if(!o.valid)return{valid:!1,mergeErrorPath:[r,...o.mergeErrorPath]};n.push(o.data)}return{valid:!0,data:n}}return{valid:!1,mergeErrorPath:[]}}function ui(e,t,n){let r=new Map,i;for(let n of t.issues)if(n.code===`unrecognized_keys`){i??=n;for(let e of n.keys)r.has(e)||r.set(e,{}),r.get(e).l=!0}else e.issues.push(n);for(let t of n.issues)if(t.code===`unrecognized_keys`)for(let e of t.keys)r.has(e)||r.set(e,{}),r.get(e).r=!0;else e.issues.push(t);let a=[...r].filter(([,e])=>e.l&&e.r).map(([e])=>e);if(a.length&&i&&e.issues.push({...i,keys:a}),wn(e))return e;let o=li(t.value,n.value);if(!o.valid)throw Error(`Unmergable intersection. Error path: ${JSON.stringify(o.mergeErrorPath)}`);return e.value=o.data,e}function di(e,t){return e.issues.length&&t===void 0?{issues:[],value:void 0}:e}function fi(e,t){return e.value===void 0&&(e.value=t.defaultValue),e}function pi(e,t){return!e.issues.length&&e.value===void 0&&e.issues.push({code:`invalid_type`,expected:`nonoptional`,input:e.value,inst:t}),e}function mi(e,t,n){return e.issues.length?(e.aborted=!0,e):t._zod.run({value:e.value,issues:e.issues},n)}function hi(e){return e.value=Object.freeze(e.value),e}function gi(e,t,n,r){if(!e){let e={code:`custom`,input:n,inst:r,path:[...r._zod.def.path??[]],continue:!r._zod.def.abort};r._zod.def.params&&(e.params=r._zod.def.params),t.issues.push(kn(e))}}var I,_i,L,vi,yi,bi,xi,Si,Ci,wi,Ti,Ei,Di,Oi,ki,Ai,ji,Mi,Ni,Pi,Fi,Ii,Li,Ri,zi,Bi,Vi,Hi,Ui,Wi,Gi,Ki,qi,Ji,Yi,Xi,Zi,Qi,$i,ea,ta,na,ra,ia,aa,oa,sa,ca,la,ua,da,fa=E((()=>{Xr(),$t(),Qr(),nr(),Nr(),Fn(),ei(),I=M(`$ZodType`,(e,t)=>{var n;e??={},e._zod.def=t,e._zod.bag=e._zod.bag||{},e._zod.version=$r;let r=[...e._zod.def.checks??[]];e._zod.traits.has(`$ZodCheck`)&&r.unshift(e);for(let t of r)for(let n of t._zod.onattach)n(e);if(r.length===0)(n=e._zod).deferred??(n.deferred=[]),e._zod.deferred?.push(()=>{e._zod.run=e._zod.parse});else{let t=(e,t,n)=>{let r=wn(e),i;for(let a of t){if(a._zod.def.when){if(!a._zod.def.when(e))continue}else if(r)continue;let t=e.issues.length,o=a._zod.check(e);if(o instanceof Promise&&n?.async===!1)throw new Xt;if(i||o instanceof Promise)i=(i??Promise.resolve()).then(async()=>{await o,e.issues.length!==t&&(r||=wn(e,t))});else{if(e.issues.length===t)continue;r||=wn(e,t)}}return i?i.then(()=>e):e},n=(n,i,a)=>{if(wn(n))return n.aborted=!0,n;let o=t(i,r,a);if(o instanceof Promise){if(a.async===!1)throw new Xt;return o.then(t=>e._zod.parse(t,a))}return e._zod.parse(o,a)};e._zod.run=(i,a)=>{if(a.skipChecks)return e._zod.parse(i,a);if(a.direction===`backward`){let t=e._zod.parse({value:i.value,issues:[]},{...a,skipChecks:!0});return t instanceof Promise?t.then(e=>n(e,i,a)):n(t,i,a)}let o=e._zod.parse(i,a);if(o instanceof Promise){if(a.async===!1)throw new Xt;return o.then(e=>t(e,r,a))}return t(o,r,a)}}N(e,`~standard`,()=>({validate:t=>{try{let n=Gn(e,t);return n.success?{value:n.data}:{issues:n.error?.issues}}catch{return qn(e,t).then(e=>e.success?{value:e.data}:{issues:e.error?.issues})}},vendor:`zod`,version:1}))}),_i=M(`$ZodString`,(e,t)=>{I.init(e,t),e._zod.pattern=[...e?._zod.bag?.patterns??[]].pop()??Dr(e._zod.bag),e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=String(n.value)}catch{}return typeof n.value==`string`||n.issues.push({expected:`string`,code:`invalid_type`,input:n.value,inst:e}),n}}),L=M(`$ZodStringFormat`,(e,t)=>{Hr.init(e,t),_i.init(e,t)}),vi=M(`$ZodGUID`,(e,t)=>{t.pattern??=mr,L.init(e,t)}),yi=M(`$ZodUUID`,(e,t)=>{if(t.version){let e={v1:1,v2:2,v3:3,v4:4,v5:5,v6:6,v7:7,v8:8}[t.version];if(e===void 0)throw Error(`Invalid UUID version: "${t.version}"`);t.pattern??=hr(e)}else t.pattern??=hr();L.init(e,t)}),bi=M(`$ZodEmail`,(e,t)=>{t.pattern??=gr,L.init(e,t)}),xi=M(`$ZodURL`,(e,t)=>{L.init(e,t),e._zod.check=n=>{try{let r=n.value.trim(),i=new URL(r);t.hostname&&(t.hostname.lastIndex=0,t.hostname.test(i.hostname)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid hostname`,pattern:t.hostname.source,input:n.value,inst:e,continue:!t.abort})),t.protocol&&(t.protocol.lastIndex=0,t.protocol.test(i.protocol.endsWith(`:`)?i.protocol.slice(0,-1):i.protocol)||n.issues.push({code:`invalid_format`,format:`url`,note:`Invalid protocol`,pattern:t.protocol.source,input:n.value,inst:e,continue:!t.abort})),n.value=t.normalize?i.href:r;return}catch{n.issues.push({code:`invalid_format`,format:`url`,input:n.value,inst:e,continue:!t.abort})}}}),Si=M(`$ZodEmoji`,(e,t)=>{t.pattern??=rr(),L.init(e,t)}),Ci=M(`$ZodNanoID`,(e,t)=>{t.pattern??=fr,L.init(e,t)}),wi=M(`$ZodCUID`,(e,t)=>{t.pattern??=sr,L.init(e,t)}),Ti=M(`$ZodCUID2`,(e,t)=>{t.pattern??=cr,L.init(e,t)}),Ei=M(`$ZodULID`,(e,t)=>{t.pattern??=lr,L.init(e,t)}),Di=M(`$ZodXID`,(e,t)=>{t.pattern??=ur,L.init(e,t)}),Oi=M(`$ZodKSUID`,(e,t)=>{t.pattern??=dr,L.init(e,t)}),ki=M(`$ZodISODateTime`,(e,t)=>{t.pattern??=or(t),L.init(e,t)}),Ai=M(`$ZodISODate`,(e,t)=>{t.pattern??=Er,L.init(e,t)}),ji=M(`$ZodISOTime`,(e,t)=>{t.pattern??=ar(t),L.init(e,t)}),Mi=M(`$ZodISODuration`,(e,t)=>{t.pattern??=pr,L.init(e,t)}),Ni=M(`$ZodIPv4`,(e,t)=>{t.pattern??=vr,L.init(e,t),e._zod.bag.format=`ipv4`}),Pi=M(`$ZodIPv6`,(e,t)=>{t.pattern??=yr,L.init(e,t),e._zod.bag.format=`ipv6`,e._zod.check=n=>{try{new URL(`http://[${n.value}]`)}catch{n.issues.push({code:`invalid_format`,format:`ipv6`,input:n.value,inst:e,continue:!t.abort})}}}),Fi=M(`$ZodCIDRv4`,(e,t)=>{t.pattern??=br,L.init(e,t)}),Ii=M(`$ZodCIDRv6`,(e,t)=>{t.pattern??=xr,L.init(e,t),e._zod.check=n=>{let r=n.value.split(`/`);try{if(r.length!==2)throw Error();let[e,t]=r;if(!t)throw Error();let n=Number(t);if(`${n}`!==t||n<0||n>128)throw Error();new URL(`http://[${e}]`)}catch{n.issues.push({code:`invalid_format`,format:`cidrv6`,input:n.value,inst:e,continue:!t.abort})}}}),Li=M(`$ZodBase64`,(e,t)=>{t.pattern??=Sr,L.init(e,t),e._zod.bag.contentEncoding=`base64`,e._zod.check=n=>{ti(n.value)||n.issues.push({code:`invalid_format`,format:`base64`,input:n.value,inst:e,continue:!t.abort})}}),Ri=M(`$ZodBase64URL`,(e,t)=>{t.pattern??=Cr,L.init(e,t),e._zod.bag.contentEncoding=`base64url`,e._zod.check=n=>{ni(n.value)||n.issues.push({code:`invalid_format`,format:`base64url`,input:n.value,inst:e,continue:!t.abort})}}),zi=M(`$ZodE164`,(e,t)=>{t.pattern??=wr,L.init(e,t)}),Bi=M(`$ZodJWT`,(e,t)=>{L.init(e,t),e._zod.check=n=>{ri(n.value,t.alg)||n.issues.push({code:`invalid_format`,format:`jwt`,input:n.value,inst:e,continue:!t.abort})}}),Vi=M(`$ZodNumber`,(e,t)=>{I.init(e,t),e._zod.pattern=e._zod.bag.pattern??kr,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=Number(n.value)}catch{}let i=n.value;if(typeof i==`number`&&!Number.isNaN(i)&&Number.isFinite(i))return n;let a=typeof i==`number`?Number.isNaN(i)?`NaN`:Number.isFinite(i)?void 0:`Infinity`:void 0;return n.issues.push({expected:`number`,code:`invalid_type`,input:i,inst:e,...a?{received:a}:{}}),n}}),Hi=M(`$ZodNumberFormat`,(e,t)=>{Rr.init(e,t),Vi.init(e,t)}),Ui=M(`$ZodBoolean`,(e,t)=>{I.init(e,t),e._zod.pattern=Ar,e._zod.parse=(n,r)=>{if(t.coerce)try{n.value=!!n.value}catch{}let i=n.value;return typeof i==`boolean`||n.issues.push({expected:`boolean`,code:`invalid_type`,input:i,inst:e}),n}}),Wi=M(`$ZodUnknown`,(e,t)=>{I.init(e,t),e._zod.parse=e=>e}),Gi=M(`$ZodNever`,(e,t)=>{I.init(e,t),e._zod.parse=(t,n)=>(t.issues.push({expected:`never`,code:`invalid_type`,input:t.value,inst:e}),t)}),Ki=M(`$ZodArray`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!Array.isArray(i))return n.issues.push({expected:`array`,code:`invalid_type`,input:i,inst:e}),n;n.value=Array(i.length);let a=[];for(let e=0;e<i.length;e++){let o=i[e],s=t.element._zod.run({value:o,issues:[]},r);s instanceof Promise?a.push(s.then(t=>ii(t,n,e))):ii(s,n,e)}return a.length?Promise.all(a).then(()=>n):n}}),qi=M(`$ZodObject`,(e,t)=>{if(I.init(e,t),!Object.getOwnPropertyDescriptor(t,`shape`)?.get){let e=t.shape;Object.defineProperty(t,"shape",{get:()=>{let n={...e};return Object.defineProperty(t,"shape",{value:n}),n}})}let n=nn(()=>oi(t));N(e._zod,`propValues`,()=>{let e=t.shape,n={};for(let t in e){let r=e[t]._zod;if(r.values){n[t]??(n[t]=new Set);for(let e of r.values)n[t].add(e)}}return n});let r=dn,i=t.catchall,a;e._zod.parse=(t,o)=>{a??=n.value;let s=t.value;if(!r(s))return t.issues.push({expected:`object`,code:`invalid_type`,input:s,inst:e}),t;t.value={};let c=[],l=a.shape;for(let e of a.keys){let n=l[e],r=n._zod.optout===`optional`,i=n._zod.run({value:s[e],issues:[]},o);i instanceof Promise?c.push(i.then(n=>ai(n,t,e,s,r))):ai(i,t,e,s,r)}return i?si(c,s,t,o,n.value,e):c.length?Promise.all(c).then(()=>t):t}}),Ji=M(`$ZodObjectJIT`,(e,t)=>{qi.init(e,t);let n=e._zod.parse,r=nn(()=>oi(t)),i=e=>{let t=new Zr([`shape`,`payload`,`ctx`]),n=r.value,i=e=>{let t=ln(e);return`shape[${t}]._zod.run({ value: input[${t}], issues: [] }, ctx)`};t.write(`const input = payload.value;`);let a=Object.create(null),o=0;for(let e of n.keys)a[e]=`key_${o++}`;t.write(`const newResult = {};`);for(let r of n.keys){let n=a[r],o=ln(r),s=e[r]?._zod?.optout===`optional`;t.write(`const ${n} = ${i(r)};`),s?t.write(`
253
253
  if (${n}.issues.length) {
254
254
  if (${o} in input) {
255
255
  payload.issues = payload.issues.concat(${n}.issues.map(iss => ({
@@ -283,9 +283,9 @@ ${r} - env:
283
283
  newResult[${o}] = ${n}.value;
284
284
  }
285
285
 
286
- `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=sn,s=!Jt.jitless,c=s&&On.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?ii([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}}),Ki=M(`$ZodUnion`,(e,t)=>{F.init(e,t),N(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),N(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),N(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),N(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>en(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>ai(t,i,e,a)):ai(s,i,e,a)}}),qi=M(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Ki.init(e,t);let n=e._zod.parse;N(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=Qt(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!sn(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),Ji=M(`$ZodIntersection`,(e,t)=>{F.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>si(e,t,n)):si(e,i,a)}}),Yi=M(`$ZodRecord`,(e,t)=>{F.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!cn(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){s.add(typeof e==`number`?e.toString():e);let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...xn(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...xn(e,o.issues)),n.value[e]=o.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&Tr.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Cn(e,r,Gt())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...xn(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...xn(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),Xi=M(`$ZodEnum`,(e,t)=>{F.init(e,t);let n=Xt(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>kn.has(typeof e)).map(e=>typeof e==`string`?un(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),Zi=M(`$ZodLiteral`,(e,t)=>{if(F.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?un(e):e?un(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),Qi=M(`$ZodTransform`,(e,t)=>{F.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new qt(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Kt;return n.value=i,n}}),$i=M(`$ZodOptional`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${en(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>ci(t,e.value)):ci(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),ea=M(`$ZodExactOptional`,(e,t)=>{$i.init(e,t),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ta=M(`$ZodNullable`,(e,t)=>{F.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${en(e.source)}|null)$`):void 0}),N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),na=M(`$ZodDefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>li(e,t)):li(r,t)}}),ra=M(`$ZodPrefault`,(e,t)=>{F.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),ia=M(`$ZodNonOptional`,(e,t)=>{F.init(e,t),N(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>ui(t,e)):ui(i,e)}}),aa=M(`$ZodCatch`,(e,t)=>{F.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Cn(e,n,Gt()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Cn(e,n,Gt()))},input:e.value}),e.issues=[]),e)}}),oa=M(`$ZodPipe`,(e,t)=>{F.init(e,t),N(e._zod,`values`,()=>t.in._zod.values),N(e._zod,`optin`,()=>t.in._zod.optin),N(e._zod,`optout`,()=>t.out._zod.optout),N(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>di(e,t.in,n)):di(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>di(e,t.out,n)):di(r,t.out,n)}}),sa=M(`$ZodReadonly`,(e,t)=>{F.init(e,t),N(e._zod,`propValues`,()=>t.innerType._zod.propValues),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`optin`,()=>t.innerType?._zod?.optin),N(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(fi):fi(r)}}),ca=M(`$ZodCustom`,(e,t)=>{Ar.init(e,t),F.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>pi(t,n,r,e));pi(i,n,r,e)}})}));function ua(){return new fa}var da,fa,pa,ma=E((()=>{fa=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}},(da=globalThis).__zod_globalRegistry??(da.__zod_globalRegistry=ua()),pa=globalThis.__zod_globalRegistry}));function ha(e,t){return new e({type:`string`,...P(t)})}function ga(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...P(t)})}function _a(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...P(t)})}function va(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...P(t)})}function ya(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...P(t)})}function ba(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...P(t)})}function xa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...P(t)})}function Sa(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...P(t)})}function Ca(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...P(t)})}function wa(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...P(t)})}function Ta(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...P(t)})}function Ea(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...P(t)})}function Da(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...P(t)})}function Oa(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...P(t)})}function ka(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...P(t)})}function Aa(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...P(t)})}function ja(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...P(t)})}function Ma(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...P(t)})}function Na(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...P(t)})}function Pa(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...P(t)})}function Fa(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...P(t)})}function Ia(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...P(t)})}function La(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...P(t)})}function Ra(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...P(t)})}function za(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...P(t)})}function Ba(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...P(t)})}function Va(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...P(t)})}function Ha(e,t){return new e({type:`number`,checks:[],...P(t)})}function Ua(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...P(t)})}function Wa(e,t){return new e({type:`boolean`,...P(t)})}function Ga(e){return new e({type:`unknown`})}function Ka(e,t){return new e({type:`never`,...P(t)})}function qa(e,t){return new Mr({check:`less_than`,...P(t),value:e,inclusive:!1})}function Ja(e,t){return new Mr({check:`less_than`,...P(t),value:e,inclusive:!0})}function Ya(e,t){return new Nr({check:`greater_than`,...P(t),value:e,inclusive:!1})}function Xa(e,t){return new Nr({check:`greater_than`,...P(t),value:e,inclusive:!0})}function Za(e,t){return new Pr({check:`multiple_of`,...P(t),value:e})}function Qa(e,t){return new Ir({check:`max_length`,...P(t),maximum:e})}function $a(e,t){return new Lr({check:`min_length`,...P(t),minimum:e})}function eo(e,t){return new Rr({check:`length_equals`,...P(t),length:e})}function to(e,t){return new Br({check:`string_format`,format:`regex`,...P(t),pattern:e})}function no(e){return new Vr({check:`string_format`,format:`lowercase`,...P(e)})}function ro(e){return new Hr({check:`string_format`,format:`uppercase`,...P(e)})}function io(e,t){return new Ur({check:`string_format`,format:`includes`,...P(t),includes:e})}function ao(e,t){return new Wr({check:`string_format`,format:`starts_with`,...P(t),prefix:e})}function oo(e,t){return new Gr({check:`string_format`,format:`ends_with`,...P(t),suffix:e})}function so(e){return new Kr({check:`overwrite`,tx:e})}function co(e){return so(t=>t.normalize(e))}function lo(){return so(e=>e.trim())}function uo(){return so(e=>e.toLowerCase())}function fo(){return so(e=>e.toUpperCase())}function po(){return so(e=>on(e))}function mo(e,t,n){return new e({type:`array`,element:t,...P(n)})}function ho(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...P(n)})}function go(e){let t=_o(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(Tn(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(Tn(r))}},e(n.value,n)));return t}function _o(e,t){let n=new Ar({check:`custom`,...P(t)});return n._zod.check=e,n}var vo=E((()=>{qr(),jn()}));function yo(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??pa,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function L(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,L(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&So(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function bo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
286
+ `)}t.write(`payload.value = newResult;`),t.write(`return payload;`);let s=t.compile();return(t,n)=>s(e,t,n)},a,o=dn,s=!Qt.jitless,c=s&&Mn.value,l=t.catchall,u;e._zod.parse=(d,f)=>{u??=r.value;let p=d.value;return o(p)?s&&c&&f?.async===!1&&f.jitless!==!0?(a||=i(t.shape),d=a(d,f),l?si([],p,d,f,u,e):d):n(d,f):(d.issues.push({expected:`object`,code:`invalid_type`,input:p,inst:e}),d)}}),Yi=M(`$ZodUnion`,(e,t)=>{I.init(e,t),N(e._zod,`optin`,()=>t.options.some(e=>e._zod.optin===`optional`)?`optional`:void 0),N(e._zod,`optout`,()=>t.options.some(e=>e._zod.optout===`optional`)?`optional`:void 0),N(e._zod,`values`,()=>{if(t.options.every(e=>e._zod.values))return new Set(t.options.flatMap(e=>Array.from(e._zod.values)))}),N(e._zod,`pattern`,()=>{if(t.options.every(e=>e._zod.pattern)){let e=t.options.map(e=>e._zod.pattern);return RegExp(`^(${e.map(e=>an(e.source)).join(`|`)})$`)}});let n=t.options.length===1,r=t.options[0]._zod.run;e._zod.parse=(i,a)=>{if(n)return r(i,a);let o=!1,s=[];for(let e of t.options){let t=e._zod.run({value:i.value,issues:[]},a);if(t instanceof Promise)s.push(t),o=!0;else{if(t.issues.length===0)return t;s.push(t)}}return o?Promise.all(s).then(t=>ci(t,i,e,a)):ci(s,i,e,a)}}),Xi=M(`$ZodDiscriminatedUnion`,(e,t)=>{t.inclusive=!1,Yi.init(e,t);let n=e._zod.parse;N(e._zod,`propValues`,()=>{let e={};for(let n of t.options){let r=n._zod.propValues;if(!r||Object.keys(r).length===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(n)}"`);for(let[t,n]of Object.entries(r)){e[t]||(e[t]=new Set);for(let r of n)e[t].add(r)}}return e});let r=nn(()=>{let e=t.options,n=new Map;for(let r of e){let e=r._zod.propValues?.[t.discriminator];if(!e||e.size===0)throw Error(`Invalid discriminated union option at index "${t.options.indexOf(r)}"`);for(let t of e){if(n.has(t))throw Error(`Duplicate discriminator value "${String(t)}"`);n.set(t,r)}}return n});e._zod.parse=(i,a)=>{let o=i.value;if(!dn(o))return i.issues.push({code:`invalid_type`,expected:`object`,input:o,inst:e}),i;let s=r.value.get(o?.[t.discriminator]);return s?s._zod.run(i,a):t.unionFallback?n(i,a):(i.issues.push({code:`invalid_union`,errors:[],note:`No matching discriminator`,discriminator:t.discriminator,input:o,path:[t.discriminator],inst:e}),i)}}),Zi=M(`$ZodIntersection`,(e,t)=>{I.init(e,t),e._zod.parse=(e,n)=>{let r=e.value,i=t.left._zod.run({value:r,issues:[]},n),a=t.right._zod.run({value:r,issues:[]},n);return i instanceof Promise||a instanceof Promise?Promise.all([i,a]).then(([t,n])=>ui(e,t,n)):ui(e,i,a)}}),Qi=M(`$ZodRecord`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{let i=n.value;if(!fn(i))return n.issues.push({expected:`record`,code:`invalid_type`,input:i,inst:e}),n;let a=[],o=t.keyType._zod.values;if(o){n.value={};let s=new Set;for(let e of o)if(typeof e==`string`||typeof e==`number`||typeof e==`symbol`){s.add(typeof e==`number`?e.toString():e);let o=t.valueType._zod.run({value:i[e],issues:[]},r);o instanceof Promise?a.push(o.then(t=>{t.issues.length&&n.issues.push(...Tn(e,t.issues)),n.value[e]=t.value})):(o.issues.length&&n.issues.push(...Tn(e,o.issues)),n.value[e]=o.value)}let c;for(let e in i)s.has(e)||(c??=[],c.push(e));c&&c.length>0&&n.issues.push({code:`unrecognized_keys`,input:i,inst:e,keys:c})}else{n.value={};for(let o of Reflect.ownKeys(i)){if(o===`__proto__`)continue;let s=t.keyType._zod.run({value:o,issues:[]},r);if(s instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);if(typeof o==`string`&&kr.test(o)&&s.issues.length){let e=t.keyType._zod.run({value:Number(o),issues:[]},r);if(e instanceof Promise)throw Error(`Async schemas not supported in object keys currently`);e.issues.length===0&&(s=e)}if(s.issues.length){t.mode===`loose`?n.value[o]=i[o]:n.issues.push({code:`invalid_key`,origin:`record`,issues:s.issues.map(e=>Dn(e,r,Yt())),input:o,path:[o],inst:e});continue}let c=t.valueType._zod.run({value:i[o],issues:[]},r);c instanceof Promise?a.push(c.then(e=>{e.issues.length&&n.issues.push(...Tn(o,e.issues)),n.value[s.value]=e.value})):(c.issues.length&&n.issues.push(...Tn(o,c.issues)),n.value[s.value]=c.value)}}return a.length?Promise.all(a).then(()=>n):n}}),$i=M(`$ZodEnum`,(e,t)=>{I.init(e,t);let n=en(t.entries),r=new Set(n);e._zod.values=r,e._zod.pattern=RegExp(`^(${n.filter(e=>Nn.has(typeof e)).map(e=>typeof e==`string`?mn(e):e.toString()).join(`|`)})$`),e._zod.parse=(t,i)=>{let a=t.value;return r.has(a)||t.issues.push({code:`invalid_value`,values:n,input:a,inst:e}),t}}),ea=M(`$ZodLiteral`,(e,t)=>{if(I.init(e,t),t.values.length===0)throw Error(`Cannot create literal schema with no valid values`);let n=new Set(t.values);e._zod.values=n,e._zod.pattern=RegExp(`^(${t.values.map(e=>typeof e==`string`?mn(e):e?mn(e.toString()):String(e)).join(`|`)})$`),e._zod.parse=(r,i)=>{let a=r.value;return n.has(a)||r.issues.push({code:`invalid_value`,values:t.values,input:a,inst:e}),r}}),ta=M(`$ZodTransform`,(e,t)=>{I.init(e,t),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Zt(e.constructor.name);let i=t.transform(n.value,n);if(r.async)return(i instanceof Promise?i:Promise.resolve(i)).then(e=>(n.value=e,n));if(i instanceof Promise)throw new Xt;return n.value=i,n}}),na=M(`$ZodOptional`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,e._zod.optout=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,void 0]):void 0),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${an(e.source)})?$`):void 0}),e._zod.parse=(e,n)=>{if(t.innerType._zod.optin===`optional`){let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(t=>di(t,e.value)):di(r,e.value)}return e.value===void 0?e:t.innerType._zod.run(e,n)}}),ra=M(`$ZodExactOptional`,(e,t)=>{na.init(e,t),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`pattern`,()=>t.innerType._zod.pattern),e._zod.parse=(e,n)=>t.innerType._zod.run(e,n)}),ia=M(`$ZodNullable`,(e,t)=>{I.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`pattern`,()=>{let e=t.innerType._zod.pattern;return e?RegExp(`^(${an(e.source)}|null)$`):void 0}),N(e._zod,`values`,()=>t.innerType._zod.values?new Set([...t.innerType._zod.values,null]):void 0),e._zod.parse=(e,n)=>e.value===null?e:t.innerType._zod.run(e,n)}),aa=M(`$ZodDefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);if(e.value===void 0)return e.value=t.defaultValue,e;let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(e=>fi(e,t)):fi(r,t)}}),oa=M(`$ZodPrefault`,(e,t)=>{I.init(e,t),e._zod.optin=`optional`,N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>(n.direction===`backward`||e.value===void 0&&(e.value=t.defaultValue),t.innerType._zod.run(e,n))}),sa=M(`$ZodNonOptional`,(e,t)=>{I.init(e,t),N(e._zod,`values`,()=>{let e=t.innerType._zod.values;return e?new Set([...e].filter(e=>e!==void 0)):void 0}),e._zod.parse=(n,r)=>{let i=t.innerType._zod.run(n,r);return i instanceof Promise?i.then(t=>pi(t,e)):pi(i,e)}}),ca=M(`$ZodCatch`,(e,t)=>{I.init(e,t),N(e._zod,`optin`,()=>t.innerType._zod.optin),N(e._zod,`optout`,()=>t.innerType._zod.optout),N(e._zod,`values`,()=>t.innerType._zod.values),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(r=>(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Dn(e,n,Yt()))},input:e.value}),e.issues=[]),e)):(e.value=r.value,r.issues.length&&(e.value=t.catchValue({...e,error:{issues:r.issues.map(e=>Dn(e,n,Yt()))},input:e.value}),e.issues=[]),e)}}),la=M(`$ZodPipe`,(e,t)=>{I.init(e,t),N(e._zod,`values`,()=>t.in._zod.values),N(e._zod,`optin`,()=>t.in._zod.optin),N(e._zod,`optout`,()=>t.out._zod.optout),N(e._zod,`propValues`,()=>t.in._zod.propValues),e._zod.parse=(e,n)=>{if(n.direction===`backward`){let r=t.out._zod.run(e,n);return r instanceof Promise?r.then(e=>mi(e,t.in,n)):mi(r,t.in,n)}let r=t.in._zod.run(e,n);return r instanceof Promise?r.then(e=>mi(e,t.out,n)):mi(r,t.out,n)}}),ua=M(`$ZodReadonly`,(e,t)=>{I.init(e,t),N(e._zod,`propValues`,()=>t.innerType._zod.propValues),N(e._zod,`values`,()=>t.innerType._zod.values),N(e._zod,`optin`,()=>t.innerType?._zod?.optin),N(e._zod,`optout`,()=>t.innerType?._zod?.optout),e._zod.parse=(e,n)=>{if(n.direction===`backward`)return t.innerType._zod.run(e,n);let r=t.innerType._zod.run(e,n);return r instanceof Promise?r.then(hi):hi(r)}}),da=M(`$ZodCustom`,(e,t)=>{F.init(e,t),I.init(e,t),e._zod.parse=(e,t)=>e,e._zod.check=n=>{let r=n.value,i=t.fn(r);if(i instanceof Promise)return i.then(t=>gi(t,n,r,e));gi(i,n,r,e)}})}));function pa(){return new ha}var ma,ha,ga,_a=E((()=>{ha=class{constructor(){this._map=new WeakMap,this._idmap=new Map}add(e,...t){let n=t[0];return this._map.set(e,n),n&&typeof n==`object`&&`id`in n&&this._idmap.set(n.id,e),this}clear(){return this._map=new WeakMap,this._idmap=new Map,this}remove(e){let t=this._map.get(e);return t&&typeof t==`object`&&`id`in t&&this._idmap.delete(t.id),this._map.delete(e),this}get(e){let t=e._zod.parent;if(t){let n={...this.get(t)??{}};delete n.id;let r={...n,...this._map.get(e)};return Object.keys(r).length?r:void 0}return this._map.get(e)}has(e){return this._map.has(e)}},(ma=globalThis).__zod_globalRegistry??(ma.__zod_globalRegistry=pa()),ga=globalThis.__zod_globalRegistry}));function va(e,t){return new e({type:`string`,...P(t)})}function ya(e,t){return new e({type:`string`,format:`email`,check:`string_format`,abort:!1,...P(t)})}function ba(e,t){return new e({type:`string`,format:`guid`,check:`string_format`,abort:!1,...P(t)})}function xa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,...P(t)})}function Sa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v4`,...P(t)})}function Ca(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v6`,...P(t)})}function wa(e,t){return new e({type:`string`,format:`uuid`,check:`string_format`,abort:!1,version:`v7`,...P(t)})}function Ta(e,t){return new e({type:`string`,format:`url`,check:`string_format`,abort:!1,...P(t)})}function Ea(e,t){return new e({type:`string`,format:`emoji`,check:`string_format`,abort:!1,...P(t)})}function Da(e,t){return new e({type:`string`,format:`nanoid`,check:`string_format`,abort:!1,...P(t)})}function Oa(e,t){return new e({type:`string`,format:`cuid`,check:`string_format`,abort:!1,...P(t)})}function ka(e,t){return new e({type:`string`,format:`cuid2`,check:`string_format`,abort:!1,...P(t)})}function Aa(e,t){return new e({type:`string`,format:`ulid`,check:`string_format`,abort:!1,...P(t)})}function ja(e,t){return new e({type:`string`,format:`xid`,check:`string_format`,abort:!1,...P(t)})}function Ma(e,t){return new e({type:`string`,format:`ksuid`,check:`string_format`,abort:!1,...P(t)})}function Na(e,t){return new e({type:`string`,format:`ipv4`,check:`string_format`,abort:!1,...P(t)})}function Pa(e,t){return new e({type:`string`,format:`ipv6`,check:`string_format`,abort:!1,...P(t)})}function Fa(e,t){return new e({type:`string`,format:`cidrv4`,check:`string_format`,abort:!1,...P(t)})}function Ia(e,t){return new e({type:`string`,format:`cidrv6`,check:`string_format`,abort:!1,...P(t)})}function La(e,t){return new e({type:`string`,format:`base64`,check:`string_format`,abort:!1,...P(t)})}function Ra(e,t){return new e({type:`string`,format:`base64url`,check:`string_format`,abort:!1,...P(t)})}function za(e,t){return new e({type:`string`,format:`e164`,check:`string_format`,abort:!1,...P(t)})}function Ba(e,t){return new e({type:`string`,format:`jwt`,check:`string_format`,abort:!1,...P(t)})}function Va(e,t){return new e({type:`string`,format:`datetime`,check:`string_format`,offset:!1,local:!1,precision:null,...P(t)})}function Ha(e,t){return new e({type:`string`,format:`date`,check:`string_format`,...P(t)})}function Ua(e,t){return new e({type:`string`,format:`time`,check:`string_format`,precision:null,...P(t)})}function Wa(e,t){return new e({type:`string`,format:`duration`,check:`string_format`,...P(t)})}function Ga(e,t){return new e({type:`number`,checks:[],...P(t)})}function Ka(e,t){return new e({type:`number`,check:`number_format`,abort:!1,format:`safeint`,...P(t)})}function qa(e,t){return new e({type:`boolean`,...P(t)})}function Ja(e){return new e({type:`unknown`})}function Ya(e,t){return new e({type:`never`,...P(t)})}function Xa(e,t){return new Fr({check:`less_than`,...P(t),value:e,inclusive:!1})}function Za(e,t){return new Fr({check:`less_than`,...P(t),value:e,inclusive:!0})}function Qa(e,t){return new Ir({check:`greater_than`,...P(t),value:e,inclusive:!1})}function $a(e,t){return new Ir({check:`greater_than`,...P(t),value:e,inclusive:!0})}function eo(e,t){return new Lr({check:`multiple_of`,...P(t),value:e})}function to(e,t){return new zr({check:`max_length`,...P(t),maximum:e})}function no(e,t){return new Br({check:`min_length`,...P(t),minimum:e})}function ro(e,t){return new Vr({check:`length_equals`,...P(t),length:e})}function io(e,t){return new Ur({check:`string_format`,format:`regex`,...P(t),pattern:e})}function ao(e){return new Wr({check:`string_format`,format:`lowercase`,...P(e)})}function oo(e){return new Gr({check:`string_format`,format:`uppercase`,...P(e)})}function so(e,t){return new Kr({check:`string_format`,format:`includes`,...P(t),includes:e})}function co(e,t){return new qr({check:`string_format`,format:`starts_with`,...P(t),prefix:e})}function lo(e,t){return new Jr({check:`string_format`,format:`ends_with`,...P(t),suffix:e})}function uo(e){return new Yr({check:`overwrite`,tx:e})}function fo(e){return uo(t=>t.normalize(e))}function po(){return uo(e=>e.trim())}function mo(){return uo(e=>e.toLowerCase())}function ho(){return uo(e=>e.toUpperCase())}function go(){return uo(e=>un(e))}function _o(e,t,n){return new e({type:`array`,element:t,...P(n)})}function vo(e,t,n){return new e({type:`custom`,check:`custom`,fn:t,...P(n)})}function yo(e){let t=bo(n=>(n.addIssue=e=>{if(typeof e==`string`)n.issues.push(kn(e,n.value,t._zod.def));else{let r=e;r.fatal&&(r.continue=!1),r.code??=`custom`,r.input??=n.value,r.inst??=t,r.continue??=!t._zod.def.abort,n.issues.push(kn(r))}},e(n.value,n)));return t}function bo(e,t){let n=new F({check:`custom`,...P(t)});return n._zod.check=e,n}var xo=E((()=>{Xr(),Fn()}));function So(e){let t=e?.target??`draft-2020-12`;return t===`draft-4`&&(t=`draft-04`),t===`draft-7`&&(t=`draft-07`),{processors:e.processors??{},metadataRegistry:e?.metadata??ga,target:t,unrepresentable:e?.unrepresentable??`throw`,override:e?.override??(()=>{}),io:e?.io??`output`,counter:0,seen:new Map,cycles:e?.cycles??`ref`,reused:e?.reused??`inline`,external:e?.external??void 0}}function R(e,t,n={path:[],schemaPath:[]}){var r;let i=e._zod.def,a=t.seen.get(e);if(a)return a.count++,n.schemaPath.includes(e)&&(a.cycle=n.path),a.schema;let o={schema:{},count:1,cycle:void 0,path:n.path};t.seen.set(e,o);let s=e._zod.toJSONSchema?.();if(s)o.schema=s;else{let r={...n,schemaPath:[...n.schemaPath,e],path:n.path};if(e._zod.processJSONSchema)e._zod.processJSONSchema(t,o.schema,r);else{let n=o.schema,a=t.processors[i.type];if(!a)throw Error(`[toJSONSchema]: Non-representable type encountered: ${i.type}`);a(e,t,n,r)}let a=e._zod.parent;a&&(o.ref||=a,R(a,t,r),t.seen.get(a).isParent=!0)}let c=t.metadataRegistry.get(e);return c&&Object.assign(o.schema,c),t.io===`input`&&To(e)&&(delete o.schema.examples,delete o.schema.default),t.io===`input`&&o.schema._prefault&&((r=o.schema).default??(r.default=o.schema._prefault)),delete o.schema._prefault,t.seen.get(e).schema}function Co(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=new Map;for(let t of e.seen.entries()){let n=e.metadataRegistry.get(t[0])?.id;if(n){let e=r.get(n);if(e&&e!==t[0])throw Error(`Duplicate schema id "${n}" detected during JSON Schema conversion. Two different schemas cannot share the same id when converted together.`);r.set(n,t[0])}}let i=t=>{let r=e.target===`draft-2020-12`?`$defs`:`definitions`;if(e.external){let n=e.external.registry.get(t[0])?.id,i=e.external.uri??(e=>e);if(n)return{ref:i(n)};let a=t[1].defId??t[1].schema.id??`schema${e.counter++}`;return t[1].defId=a,{defId:a,ref:`${i(`__shared`)}#/${r}/${a}`}}if(t[1]===n)return{ref:`#`};let i=`#/${r}/`,a=t[1].schema.id??`__schema${e.counter++}`;return{defId:a,ref:i+a}},a=e=>{if(e[1].schema.$ref)return;let t=e[1],{ref:n,defId:r}=i(e);t.def={...t.schema},r&&(t.defId=r);let a=t.schema;for(let e in a)delete a[e];a.$ref=n};if(e.cycles===`throw`)for(let t of e.seen.entries()){let e=t[1];if(e.cycle)throw Error(`Cycle detected: #/${e.cycle?.join(`/`)}/<root>
287
287
 
288
- Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function xo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:wo(t,`input`,e.processors),output:wo(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function So(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return So(r.element,n);if(r.type===`set`)return So(r.valueType,n);if(r.type===`lazy`)return So(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return So(r.innerType,n);if(r.type===`intersection`)return So(r.left,n)||So(r.right,n);if(r.type===`record`||r.type===`map`)return So(r.keyType,n)||So(r.valueType,n);if(r.type===`pipe`)return So(r.in,n)||So(r.out,n);if(r.type===`object`){for(let e in r.shape)if(So(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(So(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(So(e,n))return!0;return!!(r.rest&&So(r.rest,n))}return!1}var Co,wo,To=E((()=>{ma(),Co=(e,t={})=>n=>{let r=yo({...n,processors:t});return L(e,r),bo(r,e),xo(r,e)},wo=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=yo({...i??{},target:a,io:t,processors:n});return L(e,o),bo(o,e),xo(o,e)}})),Eo,Do,Oo,ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo=E((()=>{To(),jn(),Eo={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Do=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=Eo[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},Oo=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},ko=(e,t,n,r)=>{n.type=`boolean`},Ao=(e,t,n,r)=>{n.not={}},jo=(e,t,n,r)=>{},Mo=(e,t,n,r)=>{let i=e._zod.def,a=Xt(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},No=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Po=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Fo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},Io=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=L(a.element,t,{...r,path:[...r.path,`items`]})},Lo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=L(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=L(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Ro=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>L(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},zo=(e,t,n,r)=>{let i=e._zod.def,a=L(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=L(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Bo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=L(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=L(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=L(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Vo=(e,t,n,r)=>{let i=e._zod.def,a=L(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Ho=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Uo=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},Wo=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Go=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Ko=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;L(a,t,r);let o=t.seen.get(e);o.ref=a},qo=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Jo=(e,t,n,r)=>{let i=e._zod.def;L(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType}})),Xo=E((()=>{Yt(),Qn(),Ln(),la(),qr(),Zr(),jn(),kr(),ma(),Yr(),vo(),To(),Yo(),To()})),Zo=E((()=>{Xo()}));function Qo(e){return Ra(ns,e)}function $o(e){return za(rs,e)}function es(e){return Ba(is,e)}function ts(e){return Va(as,e)}var ns,rs,is,as,os=E((()=>{Xo(),Lc(),ns=M(`ZodISODateTime`,(e,t)=>{Ei.init(e,t),U.init(e,t)}),rs=M(`ZodISODate`,(e,t)=>{Di.init(e,t),U.init(e,t)}),is=M(`ZodISOTime`,(e,t)=>{Oi.init(e,t),U.init(e,t)}),as=M(`ZodISODuration`,(e,t)=>{ki.init(e,t),U.init(e,t)})})),ss,cs,ls=E((()=>{Xo(),jn(),ss=(e,t)=>{Fn.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Nn(e,t)},flatten:{value:t=>Mn(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,Zt,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,Zt,2)}},isEmpty:{get(){return e.issues.length===0}}})},M(`ZodError`,ss),cs=M(`ZodError`,ss,{Parent:Error})})),us,ds,fs,ps,ms,hs,gs,_s,vs,ys,bs,xs,Ss=E((()=>{Xo(),ls(),us=Rn(cs),ds=zn(cs),fs=Bn(cs),ps=Hn(cs),ms=Wn(cs),hs=Gn(cs),gs=Kn(cs),_s=qn(cs),vs=Jn(cs),ys=Yn(cs),bs=Xn(cs),xs=Zn(cs)}));function R(e){return ha(qs,e)}function z(e){return Ha(pc,e)}function Cs(e){return Ua(mc,e)}function ws(e){return Wa(hc,e)}function Ts(){return Ga(gc)}function Es(e){return Ka(_c,e)}function Ds(e,t){return mo(vc,e,t)}function Os(e,t){let n={type:`object`,shape:e??{},...P(t)};return new yc(n)}function B(e,t){return new yc({type:`object`,shape:e,catchall:Es(),...P(t)})}function ks(e,t){return new bc({type:`union`,options:e,...P(t)})}function As(e,t,n){return new xc({type:`union`,options:t,discriminator:e,...P(n)})}function js(e,t){return new Sc({type:`intersection`,left:e,right:t})}function Ms(e,t,n){return new Cc({type:`record`,keyType:e,valueType:t,...P(n)})}function Ns(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new wc({type:`enum`,entries:n,...P(t)})}function V(e,t){return new Tc({type:`literal`,values:Array.isArray(e)?e:[e],...P(t)})}function Ps(e){return new Ec({type:`transform`,transform:e})}function Fs(e){return new Dc({type:`optional`,innerType:e})}function Is(e){return new Oc({type:`optional`,innerType:e})}function Ls(e){return new kc({type:`nullable`,innerType:e})}function Rs(e,t){return new Ac({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():ln(t)}})}function zs(e,t){return new jc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():ln(t)}})}function Bs(e,t){return new Mc({type:`nonoptional`,innerType:e,...P(t)})}function Vs(e,t){return new Nc({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}function Hs(e,t){return new Pc({type:`pipe`,in:e,out:t})}function Us(e){return new Fc({type:`readonly`,innerType:e})}function Ws(e,t={}){return ho(Ic,e,t)}function Gs(e){return go(e)}var H,Ks,qs,U,Js,Ys,Xs,Zs,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc,xc,Sc,Cc,wc,Tc,Ec,Dc,Oc,kc,Ac,jc,Mc,Nc,Pc,Fc,Ic,Lc=E((()=>{Xo(),Yo(),To(),Zo(),os(),Ss(),H=M(`ZodType`,(e,t)=>(F.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:wo(e,`input`),output:wo(e,`output`)}}),e.toJSONSchema=Co(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(rn(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>dn(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>us(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>fs(e,t,n),e.parseAsync=async(t,n)=>ds(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>ps(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>ms(e,t,n),e.decode=(t,n)=>hs(e,t,n),e.encodeAsync=async(t,n)=>gs(e,t,n),e.decodeAsync=async(t,n)=>_s(e,t,n),e.safeEncode=(t,n)=>vs(e,t,n),e.safeDecode=(t,n)=>ys(e,t,n),e.safeEncodeAsync=async(t,n)=>bs(e,t,n),e.safeDecodeAsync=async(t,n)=>xs(e,t,n),e.refine=(t,n)=>e.check(Ws(t,n)),e.superRefine=t=>e.check(Gs(t)),e.overwrite=t=>e.check(so(t)),e.optional=()=>Fs(e),e.exactOptional=()=>Is(e),e.nullable=()=>Ls(e),e.nullish=()=>Fs(Ls(e)),e.nonoptional=t=>Bs(e,t),e.array=()=>Ds(e),e.or=t=>ks([e,t]),e.and=t=>js(e,t),e.transform=t=>Hs(e,Ps(t)),e.default=t=>Rs(e,t),e.prefault=t=>zs(e,t),e.catch=t=>Vs(e,t),e.pipe=t=>Hs(e,t),e.readonly=()=>Us(e),e.describe=t=>{let n=e.clone();return pa.add(n,{description:t}),n},Object.defineProperty(e,"description",{get(){return pa.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return pa.get(e);let n=e.clone();return pa.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),Ks=M(`_ZodString`,(e,t)=>{mi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Do(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(to(...t)),e.includes=(...t)=>e.check(io(...t)),e.startsWith=(...t)=>e.check(ao(...t)),e.endsWith=(...t)=>e.check(oo(...t)),e.min=(...t)=>e.check($a(...t)),e.max=(...t)=>e.check(Qa(...t)),e.length=(...t)=>e.check(eo(...t)),e.nonempty=(...t)=>e.check($a(1,...t)),e.lowercase=t=>e.check(no(t)),e.uppercase=t=>e.check(ro(t)),e.trim=()=>e.check(lo()),e.normalize=(...t)=>e.check(co(...t)),e.toLowerCase=()=>e.check(uo()),e.toUpperCase=()=>e.check(fo()),e.slugify=()=>e.check(po())}),qs=M(`ZodString`,(e,t)=>{mi.init(e,t),Ks.init(e,t),e.email=t=>e.check(ga(Js,t)),e.url=t=>e.check(Sa(Zs,t)),e.jwt=t=>e.check(La(fc,t)),e.emoji=t=>e.check(Ca(Qs,t)),e.guid=t=>e.check(_a(Ys,t)),e.uuid=t=>e.check(va(Xs,t)),e.uuidv4=t=>e.check(ya(Xs,t)),e.uuidv6=t=>e.check(ba(Xs,t)),e.uuidv7=t=>e.check(xa(Xs,t)),e.nanoid=t=>e.check(wa($s,t)),e.guid=t=>e.check(_a(Ys,t)),e.cuid=t=>e.check(Ta(ec,t)),e.cuid2=t=>e.check(Ea(tc,t)),e.ulid=t=>e.check(Da(nc,t)),e.base64=t=>e.check(Pa(lc,t)),e.base64url=t=>e.check(Fa(uc,t)),e.xid=t=>e.check(Oa(rc,t)),e.ksuid=t=>e.check(ka(ic,t)),e.ipv4=t=>e.check(Aa(ac,t)),e.ipv6=t=>e.check(ja(oc,t)),e.cidrv4=t=>e.check(Ma(sc,t)),e.cidrv6=t=>e.check(Na(cc,t)),e.e164=t=>e.check(Ia(dc,t)),e.datetime=t=>e.check(Qo(t)),e.date=t=>e.check($o(t)),e.time=t=>e.check(es(t)),e.duration=t=>e.check(ts(t))}),U=M(`ZodStringFormat`,(e,t)=>{I.init(e,t),Ks.init(e,t)}),Js=M(`ZodEmail`,(e,t)=>{_i.init(e,t),U.init(e,t)}),Ys=M(`ZodGUID`,(e,t)=>{hi.init(e,t),U.init(e,t)}),Xs=M(`ZodUUID`,(e,t)=>{gi.init(e,t),U.init(e,t)}),Zs=M(`ZodURL`,(e,t)=>{vi.init(e,t),U.init(e,t)}),Qs=M(`ZodEmoji`,(e,t)=>{yi.init(e,t),U.init(e,t)}),$s=M(`ZodNanoID`,(e,t)=>{bi.init(e,t),U.init(e,t)}),ec=M(`ZodCUID`,(e,t)=>{xi.init(e,t),U.init(e,t)}),tc=M(`ZodCUID2`,(e,t)=>{Si.init(e,t),U.init(e,t)}),nc=M(`ZodULID`,(e,t)=>{Ci.init(e,t),U.init(e,t)}),rc=M(`ZodXID`,(e,t)=>{wi.init(e,t),U.init(e,t)}),ic=M(`ZodKSUID`,(e,t)=>{Ti.init(e,t),U.init(e,t)}),ac=M(`ZodIPv4`,(e,t)=>{Ai.init(e,t),U.init(e,t)}),oc=M(`ZodIPv6`,(e,t)=>{ji.init(e,t),U.init(e,t)}),sc=M(`ZodCIDRv4`,(e,t)=>{Mi.init(e,t),U.init(e,t)}),cc=M(`ZodCIDRv6`,(e,t)=>{Ni.init(e,t),U.init(e,t)}),lc=M(`ZodBase64`,(e,t)=>{Pi.init(e,t),U.init(e,t)}),uc=M(`ZodBase64URL`,(e,t)=>{Fi.init(e,t),U.init(e,t)}),dc=M(`ZodE164`,(e,t)=>{Ii.init(e,t),U.init(e,t)}),fc=M(`ZodJWT`,(e,t)=>{Li.init(e,t),U.init(e,t)}),pc=M(`ZodNumber`,(e,t)=>{Ri.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Oo(e,t,n,r),e.gt=(t,n)=>e.check(Ya(t,n)),e.gte=(t,n)=>e.check(Xa(t,n)),e.min=(t,n)=>e.check(Xa(t,n)),e.lt=(t,n)=>e.check(qa(t,n)),e.lte=(t,n)=>e.check(Ja(t,n)),e.max=(t,n)=>e.check(Ja(t,n)),e.int=t=>e.check(Cs(t)),e.safe=t=>e.check(Cs(t)),e.positive=t=>e.check(Ya(0,t)),e.nonnegative=t=>e.check(Xa(0,t)),e.negative=t=>e.check(qa(0,t)),e.nonpositive=t=>e.check(Ja(0,t)),e.multipleOf=(t,n)=>e.check(Za(t,n)),e.step=(t,n)=>e.check(Za(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null}),mc=M(`ZodNumberFormat`,(e,t)=>{zi.init(e,t),pc.init(e,t)}),hc=M(`ZodBoolean`,(e,t)=>{Bi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>ko(e,t,n,r)}),gc=M(`ZodUnknown`,(e,t)=>{Vi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(e,t,n,r)}),_c=M(`ZodNever`,(e,t)=>{Hi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r)}),vc=M(`ZodArray`,(e,t)=>{Ui.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check($a(t,n)),e.nonempty=t=>e.check($a(1,t)),e.max=(t,n)=>e.check(Qa(t,n)),e.length=(t,n)=>e.check(eo(t,n)),e.unwrap=()=>e.element}),yc=M(`ZodObject`,(e,t)=>{Gi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r),N(e,`shape`,()=>t.shape),e.keyof=()=>Ns(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Ts()}),e.loose=()=>e.clone({...e._zod.def,catchall:Ts()}),e.strict=()=>e.clone({...e._zod.def,catchall:Es()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>hn(e,t),e.safeExtend=t=>gn(e,t),e.merge=t=>_n(e,t),e.pick=t=>pn(e,t),e.omit=t=>mn(e,t),e.partial=(...t)=>vn(Dc,e,t[0]),e.required=(...t)=>yn(Mc,e,t[0])}),bc=M(`ZodUnion`,(e,t)=>{Ki.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r),e.options=t.options}),xc=M(`ZodDiscriminatedUnion`,(e,t)=>{bc.init(e,t),qi.init(e,t)}),Sc=M(`ZodIntersection`,(e,t)=>{Ji.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r)}),Cc=M(`ZodRecord`,(e,t)=>{Yi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType}),wc=M(`ZodEnum`,(e,t)=>{Xi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new wc({...t,checks:[],...P(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new wc({...t,checks:[],...P(r),entries:i})}}),Tc=M(`ZodLiteral`,(e,t)=>{Zi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})}),Ec=M(`ZodTransform`,(e,t)=>{Qi.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new qt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(Tn(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(Tn(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}}),Dc=M(`ZodOptional`,(e,t)=>{$i.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Oc=M(`ZodExactOptional`,(e,t)=>{ea.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),kc=M(`ZodNullable`,(e,t)=>{ta.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Ac=M(`ZodDefault`,(e,t)=>{na.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap}),jc=M(`ZodPrefault`,(e,t)=>{ra.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Mc=M(`ZodNonOptional`,(e,t)=>{ia.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Nc=M(`ZodCatch`,(e,t)=>{aa.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap}),Pc=M(`ZodPipe`,(e,t)=>{oa.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.in=t.in,e.out=t.out}),Fc=M(`ZodReadonly`,(e,t)=>{sa.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Ic=M(`ZodCustom`,(e,t)=>{ca.init(e,t),H.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r)})})),Rc=E((()=>{Xo()})),zc=E((()=>{Xo(),Lc(),Zo(),ls(),Ss(),Rc(),Yo(),ma(),Zo(),os(),Lc(),jn()})),Bc=E((()=>{zc(),zc()}));async function Vc(){let e=Wc(),[t,n]=await Promise.all([Uc(e,[`--version`]),Uc(e,[`doctor`,`--json`])]);return Hc(t,n)}function Hc(e,t){let n;try{n=JSON.parse(t)}catch(e){throw Error(`agent-browser doctor did not return valid JSON`,{cause:e})}let r=(n.checks?.find(e=>e.id===`chrome.installed`&&e.status===`pass`)?.message)?.split(` at `)[0];if(!r?.match(/^Google Chrome for Testing \d+\.\d+\.\d+\.\d+$/))throw Error(`Kapture requires an exact installed Google Chrome for Testing version`);return`${e}; ${r}`}function Uc(e,t){return new Promise((n,i)=>{let a=r(e,t,{stdio:[`ignore`,`pipe`,`pipe`]}),o=[];a.stdout.on(`data`,e=>o.push(e)),a.once(`error`,i),a.once(`close`,e=>{if(e!==0)return i(Error(`agent-browser ${t.join(` `)} failed (${e})`));n(Buffer.concat(o).toString(`utf8`).trim())})})}function Wc(){try{let t=e(import.meta.url),n=t.resolve(`agent-browser/package.json`),r=a(n),i=t(n),o=typeof i.bin==`string`?i.bin:i.bin?.[`agent-browser`]??`bin/agent-browser.js`;return f(r,o)}catch{return`agent-browser`}}async function Gc(e,t,n){let r=JSON.stringify({id:t.id,browserMajor:t.browserVersion.match(/Chrome(?: for Testing)? (\d+)/)?.[1],locale:t.locale,timezone:t.timezone,deviceScaleFactor:t.deviceScaleFactor,colorScheme:t.colorScheme,reducedMotion:t.reducedMotion,frozenTimestamp:Date.parse(t.frozenTime)}),i=JSON.stringify(n);return e.evaluate(`(async () => {
288
+ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.`)}for(let n of e.seen.entries()){let r=n[1];if(t===n[0]){a(n);continue}if(e.external){let r=e.external.registry.get(n[0])?.id;if(t!==n[0]&&r){a(n);continue}}if(e.metadataRegistry.get(n[0])?.id){a(n);continue}if(r.cycle){a(n);continue}if(r.count>1&&e.reused===`ref`){a(n);continue}}}function wo(e,t){let n=e.seen.get(t);if(!n)throw Error(`Unprocessed schema. This is a bug in Zod.`);let r=t=>{let n=e.seen.get(t);if(n.ref===null)return;let i=n.def??n.schema,a={...i},o=n.ref;if(n.ref=null,o){r(o);let n=e.seen.get(o),s=n.schema;if(s.$ref&&(e.target===`draft-07`||e.target===`draft-04`||e.target===`openapi-3.0`)?(i.allOf=i.allOf??[],i.allOf.push(s)):Object.assign(i,s),Object.assign(i,a),t._zod.parent===o)for(let e in i)e!==`$ref`&&e!==`allOf`&&(e in a||delete i[e]);if(s.$ref&&n.def)for(let e in i)e!==`$ref`&&e!==`allOf`&&e in n.def&&JSON.stringify(i[e])===JSON.stringify(n.def[e])&&delete i[e]}let s=t._zod.parent;if(s&&s!==o){r(s);let t=e.seen.get(s);if(t?.schema.$ref&&(i.$ref=t.schema.$ref,t.def))for(let e in i)e!==`$ref`&&e!==`allOf`&&e in t.def&&JSON.stringify(i[e])===JSON.stringify(t.def[e])&&delete i[e]}e.override({zodSchema:t,jsonSchema:i,path:n.path??[]})};for(let t of[...e.seen.entries()].reverse())r(t[0]);let i={};if(e.target===`draft-2020-12`?i.$schema=`https://json-schema.org/draft/2020-12/schema`:e.target===`draft-07`?i.$schema=`http://json-schema.org/draft-07/schema#`:e.target===`draft-04`?i.$schema=`http://json-schema.org/draft-04/schema#`:e.target,e.external?.uri){let n=e.external.registry.get(t)?.id;if(!n)throw Error("Schema is missing an `id` property");i.$id=e.external.uri(n)}Object.assign(i,n.def??n.schema);let a=e.external?.defs??{};for(let t of e.seen.entries()){let e=t[1];e.def&&e.defId&&(a[e.defId]=e.def)}e.external||Object.keys(a).length>0&&(e.target===`draft-2020-12`?i.$defs=a:i.definitions=a);try{let n=JSON.parse(JSON.stringify(i));return Object.defineProperty(n,"~standard",{value:{...t[`~standard`],jsonSchema:{input:Do(t,`input`,e.processors),output:Do(t,`output`,e.processors)}},enumerable:!1,writable:!1}),n}catch{throw Error(`Error converting schema to JSON.`)}}function To(e,t){let n=t??{seen:new Set};if(n.seen.has(e))return!1;n.seen.add(e);let r=e._zod.def;if(r.type===`transform`)return!0;if(r.type===`array`)return To(r.element,n);if(r.type===`set`)return To(r.valueType,n);if(r.type===`lazy`)return To(r.getter(),n);if(r.type===`promise`||r.type===`optional`||r.type===`nonoptional`||r.type===`nullable`||r.type===`readonly`||r.type==="default"||r.type===`prefault`)return To(r.innerType,n);if(r.type===`intersection`)return To(r.left,n)||To(r.right,n);if(r.type===`record`||r.type===`map`)return To(r.keyType,n)||To(r.valueType,n);if(r.type===`pipe`)return To(r.in,n)||To(r.out,n);if(r.type===`object`){for(let e in r.shape)if(To(r.shape[e],n))return!0;return!1}if(r.type===`union`){for(let e of r.options)if(To(e,n))return!0;return!1}if(r.type===`tuple`){for(let e of r.items)if(To(e,n))return!0;return!!(r.rest&&To(r.rest,n))}return!1}var Eo,Do,Oo=E((()=>{_a(),Eo=(e,t={})=>n=>{let r=So({...n,processors:t});return R(e,r),Co(r,e),wo(r,e)},Do=(e,t,n={})=>r=>{let{libraryOptions:i,target:a}=r??{},o=So({...i??{},target:a,io:t,processors:n});return R(e,o),Co(o,e),wo(o,e)}})),ko,Ao,jo,Mo,No,Po,Fo,Io,Lo,Ro,zo,Bo,Vo,Ho,Uo,Wo,Go,Ko,qo,Jo,Yo,Xo,Zo,Qo=E((()=>{Oo(),Fn(),ko={guid:`uuid`,url:`uri`,datetime:`date-time`,json_string:`json-string`,regex:``},Ao=(e,t,n,r)=>{let i=n;i.type=`string`;let{minimum:a,maximum:o,format:s,patterns:c,contentEncoding:l}=e._zod.bag;if(typeof a==`number`&&(i.minLength=a),typeof o==`number`&&(i.maxLength=o),s&&(i.format=ko[s]??s,i.format===``&&delete i.format,s===`time`&&delete i.format),l&&(i.contentEncoding=l),c&&c.size>0){let e=[...c];e.length===1?i.pattern=e[0].source:e.length>1&&(i.allOf=[...e.map(e=>({...t.target===`draft-07`||t.target===`draft-04`||t.target===`openapi-3.0`?{type:`string`}:{},pattern:e.source}))])}},jo=(e,t,n,r)=>{let i=n,{minimum:a,maximum:o,format:s,multipleOf:c,exclusiveMaximum:l,exclusiveMinimum:u}=e._zod.bag;i.type=typeof s==`string`&&s.includes(`int`)?`integer`:`number`,typeof u==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.minimum=u,i.exclusiveMinimum=!0):i.exclusiveMinimum=u),typeof a==`number`&&(i.minimum=a,typeof u==`number`&&t.target!==`draft-04`&&(u>=a?delete i.minimum:delete i.exclusiveMinimum)),typeof l==`number`&&(t.target===`draft-04`||t.target===`openapi-3.0`?(i.maximum=l,i.exclusiveMaximum=!0):i.exclusiveMaximum=l),typeof o==`number`&&(i.maximum=o,typeof l==`number`&&t.target!==`draft-04`&&(l<=o?delete i.maximum:delete i.exclusiveMaximum)),typeof c==`number`&&(i.multipleOf=c)},Mo=(e,t,n,r)=>{n.type=`boolean`},No=(e,t,n,r)=>{n.not={}},Po=(e,t,n,r)=>{},Fo=(e,t,n,r)=>{let i=e._zod.def,a=en(i.entries);a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),n.enum=a},Io=(e,t,n,r)=>{let i=e._zod.def,a=[];for(let e of i.values)if(e===void 0){if(t.unrepresentable===`throw`)throw Error("Literal `undefined` cannot be represented in JSON Schema")}else if(typeof e==`bigint`){if(t.unrepresentable===`throw`)throw Error(`BigInt literals cannot be represented in JSON Schema`);a.push(Number(e))}else a.push(e);if(a.length!==0){if(a.length===1){let e=a[0];n.type=e===null?`null`:typeof e,t.target===`draft-04`||t.target===`openapi-3.0`?n.enum=[e]:n.const=e}else a.every(e=>typeof e==`number`)&&(n.type=`number`),a.every(e=>typeof e==`string`)&&(n.type=`string`),a.every(e=>typeof e==`boolean`)&&(n.type=`boolean`),a.every(e=>e===null)&&(n.type=`null`),n.enum=a}},Lo=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Custom types cannot be represented in JSON Schema`)},Ro=(e,t,n,r)=>{if(t.unrepresentable===`throw`)throw Error(`Transforms cannot be represented in JSON Schema`)},zo=(e,t,n,r)=>{let i=n,a=e._zod.def,{minimum:o,maximum:s}=e._zod.bag;typeof o==`number`&&(i.minItems=o),typeof s==`number`&&(i.maxItems=s),i.type=`array`,i.items=R(a.element,t,{...r,path:[...r.path,`items`]})},Bo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`,i.properties={};let o=a.shape;for(let e in o)i.properties[e]=R(o[e],t,{...r,path:[...r.path,`properties`,e]});let s=new Set(Object.keys(o)),c=new Set([...s].filter(e=>{let n=a.shape[e]._zod;return t.io===`input`?n.optin===void 0:n.optout===void 0}));c.size>0&&(i.required=Array.from(c)),a.catchall?._zod.def.type===`never`?i.additionalProperties=!1:a.catchall?a.catchall&&(i.additionalProperties=R(a.catchall,t,{...r,path:[...r.path,`additionalProperties`]})):t.io===`output`&&(i.additionalProperties=!1)},Vo=(e,t,n,r)=>{let i=e._zod.def,a=i.inclusive===!1,o=i.options.map((e,n)=>R(e,t,{...r,path:[...r.path,a?`oneOf`:`anyOf`,n]}));a?n.oneOf=o:n.anyOf=o},Ho=(e,t,n,r)=>{let i=e._zod.def,a=R(i.left,t,{...r,path:[...r.path,`allOf`,0]}),o=R(i.right,t,{...r,path:[...r.path,`allOf`,1]}),s=e=>`allOf`in e&&Object.keys(e).length===1;n.allOf=[...s(a)?a.allOf:[a],...s(o)?o.allOf:[o]]},Uo=(e,t,n,r)=>{let i=n,a=e._zod.def;i.type=`object`;let o=a.keyType,s=o._zod.bag?.patterns;if(a.mode===`loose`&&s&&s.size>0){let e=R(a.valueType,t,{...r,path:[...r.path,`patternProperties`,`*`]});i.patternProperties={};for(let t of s)i.patternProperties[t.source]=e}else(t.target===`draft-07`||t.target===`draft-2020-12`)&&(i.propertyNames=R(a.keyType,t,{...r,path:[...r.path,`propertyNames`]})),i.additionalProperties=R(a.valueType,t,{...r,path:[...r.path,`additionalProperties`]});let c=o._zod.values;if(c){let e=[...c].filter(e=>typeof e==`string`||typeof e==`number`);e.length>0&&(i.required=e)}},Wo=(e,t,n,r)=>{let i=e._zod.def,a=R(i.innerType,t,r),o=t.seen.get(e);t.target===`openapi-3.0`?(o.ref=i.innerType,n.nullable=!0):n.anyOf=[a,{type:`null`}]},Go=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType},Ko=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.default=JSON.parse(JSON.stringify(i.defaultValue))},qo=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,t.io===`input`&&(n._prefault=JSON.parse(JSON.stringify(i.defaultValue)))},Jo=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType;let o;try{o=i.catchValue(void 0)}catch{throw Error(`Dynamic catch values are not supported in JSON Schema`)}n.default=o},Yo=(e,t,n,r)=>{let i=e._zod.def,a=t.io===`input`?i.in._zod.def.type===`transform`?i.out:i.in:i.out;R(a,t,r);let o=t.seen.get(e);o.ref=a},Xo=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType,n.readOnly=!0},Zo=(e,t,n,r)=>{let i=e._zod.def;R(i.innerType,t,r);let a=t.seen.get(e);a.ref=i.innerType}})),$o=E((()=>{$t(),nr(),Vn(),fa(),Xr(),ei(),Fn(),Nr(),_a(),Qr(),xo(),Oo(),Qo(),Oo()})),es=E((()=>{$o()}));function ts(e){return Va(as,e)}function ns(e){return Ha(os,e)}function rs(e){return Ua(ss,e)}function is(e){return Wa(cs,e)}var as,os,ss,cs,ls=E((()=>{$o(),Bc(),as=M(`ZodISODateTime`,(e,t)=>{ki.init(e,t),W.init(e,t)}),os=M(`ZodISODate`,(e,t)=>{Ai.init(e,t),W.init(e,t)}),ss=M(`ZodISOTime`,(e,t)=>{ji.init(e,t),W.init(e,t)}),cs=M(`ZodISODuration`,(e,t)=>{Mi.init(e,t),W.init(e,t)})})),us,ds,fs=E((()=>{$o(),Fn(),us=(e,t)=>{zn.init(e,t),e.name=`ZodError`,Object.defineProperties(e,{format:{value:t=>Ln(e,t)},flatten:{value:t=>In(e,t)},addIssue:{value:t=>{e.issues.push(t),e.message=JSON.stringify(e.issues,tn,2)}},addIssues:{value:t=>{e.issues.push(...t),e.message=JSON.stringify(e.issues,tn,2)}},isEmpty:{get(){return e.issues.length===0}}})},M(`ZodError`,us),ds=M(`ZodError`,us,{Parent:Error})})),ps,ms,hs,gs,_s,vs,ys,bs,xs,Ss,Cs,ws,Ts=E((()=>{$o(),fs(),ps=Hn(ds),ms=Un(ds),hs=Wn(ds),gs=Kn(ds),_s=Jn(ds),vs=Yn(ds),ys=Xn(ds),bs=Zn(ds),xs=Qn(ds),Ss=$n(ds),Cs=er(ds),ws=tr(ds)}));function z(e){return va(Xs,e)}function B(e){return Ga(gc,e)}function Es(e){return Ka(_c,e)}function Ds(e){return qa(vc,e)}function Os(){return Ja(yc)}function ks(e){return Ya(bc,e)}function As(e,t){return _o(xc,e,t)}function js(e,t){let n={type:`object`,shape:e??{},...P(t)};return new Sc(n)}function V(e,t){return new Sc({type:`object`,shape:e,catchall:ks(),...P(t)})}function Ms(e,t){return new Cc({type:`union`,options:e,...P(t)})}function Ns(e,t,n){return new wc({type:`union`,options:t,discriminator:e,...P(n)})}function Ps(e,t){return new Tc({type:`intersection`,left:e,right:t})}function Fs(e,t,n){return new Ec({type:`record`,keyType:e,valueType:t,...P(n)})}function Is(e,t){let n=Array.isArray(e)?Object.fromEntries(e.map(e=>[e,e])):e;return new Dc({type:`enum`,entries:n,...P(t)})}function H(e,t){return new Oc({type:`literal`,values:Array.isArray(e)?e:[e],...P(t)})}function Ls(e){return new kc({type:`transform`,transform:e})}function Rs(e){return new Ac({type:`optional`,innerType:e})}function zs(e){return new jc({type:`optional`,innerType:e})}function Bs(e){return new Mc({type:`nullable`,innerType:e})}function Vs(e,t){return new Nc({type:`default`,innerType:e,get defaultValue(){return typeof t==`function`?t():pn(t)}})}function Hs(e,t){return new Pc({type:`prefault`,innerType:e,get defaultValue(){return typeof t==`function`?t():pn(t)}})}function Us(e,t){return new Fc({type:`nonoptional`,innerType:e,...P(t)})}function Ws(e,t){return new Ic({type:`catch`,innerType:e,catchValue:typeof t==`function`?t:()=>t})}function Gs(e,t){return new Lc({type:`pipe`,in:e,out:t})}function Ks(e){return new Rc({type:`readonly`,innerType:e})}function qs(e,t={}){return vo(zc,e,t)}function Js(e){return yo(e)}var U,Ys,Xs,W,Zs,Qs,$s,ec,tc,nc,rc,ic,ac,oc,sc,cc,lc,uc,dc,fc,pc,mc,hc,gc,_c,vc,yc,bc,xc,Sc,Cc,wc,Tc,Ec,Dc,Oc,kc,Ac,jc,Mc,Nc,Pc,Fc,Ic,Lc,Rc,zc,Bc=E((()=>{$o(),Qo(),Oo(),es(),ls(),Ts(),U=M(`ZodType`,(e,t)=>(I.init(e,t),Object.assign(e[`~standard`],{jsonSchema:{input:Do(e,`input`),output:Do(e,`output`)}}),e.toJSONSchema=Eo(e,{}),e.def=t,e.type=t.type,Object.defineProperty(e,"_def",{value:t}),e.check=(...n)=>e.clone(cn(t,{checks:[...t.checks??[],...n.map(e=>typeof e==`function`?{_zod:{check:e,def:{check:`custom`},onattach:[]}}:e)]}),{parent:!0}),e.with=e.check,e.clone=(t,n)=>hn(e,t,n),e.brand=()=>e,e.register=((t,n)=>(t.add(e,n),e)),e.parse=(t,n)=>ps(e,t,n,{callee:e.parse}),e.safeParse=(t,n)=>hs(e,t,n),e.parseAsync=async(t,n)=>ms(e,t,n,{callee:e.parseAsync}),e.safeParseAsync=async(t,n)=>gs(e,t,n),e.spa=e.safeParseAsync,e.encode=(t,n)=>_s(e,t,n),e.decode=(t,n)=>vs(e,t,n),e.encodeAsync=async(t,n)=>ys(e,t,n),e.decodeAsync=async(t,n)=>bs(e,t,n),e.safeEncode=(t,n)=>xs(e,t,n),e.safeDecode=(t,n)=>Ss(e,t,n),e.safeEncodeAsync=async(t,n)=>Cs(e,t,n),e.safeDecodeAsync=async(t,n)=>ws(e,t,n),e.refine=(t,n)=>e.check(qs(t,n)),e.superRefine=t=>e.check(Js(t)),e.overwrite=t=>e.check(uo(t)),e.optional=()=>Rs(e),e.exactOptional=()=>zs(e),e.nullable=()=>Bs(e),e.nullish=()=>Rs(Bs(e)),e.nonoptional=t=>Us(e,t),e.array=()=>As(e),e.or=t=>Ms([e,t]),e.and=t=>Ps(e,t),e.transform=t=>Gs(e,Ls(t)),e.default=t=>Vs(e,t),e.prefault=t=>Hs(e,t),e.catch=t=>Ws(e,t),e.pipe=t=>Gs(e,t),e.readonly=()=>Ks(e),e.describe=t=>{let n=e.clone();return ga.add(n,{description:t}),n},Object.defineProperty(e,"description",{get(){return ga.get(e)?.description},configurable:!0}),e.meta=(...t)=>{if(t.length===0)return ga.get(e);let n=e.clone();return ga.add(n,t[0]),n},e.isOptional=()=>e.safeParse(void 0).success,e.isNullable=()=>e.safeParse(null).success,e.apply=t=>t(e),e)),Ys=M(`_ZodString`,(e,t)=>{_i.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ao(e,t,n,r);let n=e._zod.bag;e.format=n.format??null,e.minLength=n.minimum??null,e.maxLength=n.maximum??null,e.regex=(...t)=>e.check(io(...t)),e.includes=(...t)=>e.check(so(...t)),e.startsWith=(...t)=>e.check(co(...t)),e.endsWith=(...t)=>e.check(lo(...t)),e.min=(...t)=>e.check(no(...t)),e.max=(...t)=>e.check(to(...t)),e.length=(...t)=>e.check(ro(...t)),e.nonempty=(...t)=>e.check(no(1,...t)),e.lowercase=t=>e.check(ao(t)),e.uppercase=t=>e.check(oo(t)),e.trim=()=>e.check(po()),e.normalize=(...t)=>e.check(fo(...t)),e.toLowerCase=()=>e.check(mo()),e.toUpperCase=()=>e.check(ho()),e.slugify=()=>e.check(go())}),Xs=M(`ZodString`,(e,t)=>{_i.init(e,t),Ys.init(e,t),e.email=t=>e.check(ya(Zs,t)),e.url=t=>e.check(Ta(ec,t)),e.jwt=t=>e.check(Ba(hc,t)),e.emoji=t=>e.check(Ea(tc,t)),e.guid=t=>e.check(ba(Qs,t)),e.uuid=t=>e.check(xa($s,t)),e.uuidv4=t=>e.check(Sa($s,t)),e.uuidv6=t=>e.check(Ca($s,t)),e.uuidv7=t=>e.check(wa($s,t)),e.nanoid=t=>e.check(Da(nc,t)),e.guid=t=>e.check(ba(Qs,t)),e.cuid=t=>e.check(Oa(rc,t)),e.cuid2=t=>e.check(ka(ic,t)),e.ulid=t=>e.check(Aa(ac,t)),e.base64=t=>e.check(La(fc,t)),e.base64url=t=>e.check(Ra(pc,t)),e.xid=t=>e.check(ja(oc,t)),e.ksuid=t=>e.check(Ma(sc,t)),e.ipv4=t=>e.check(Na(cc,t)),e.ipv6=t=>e.check(Pa(lc,t)),e.cidrv4=t=>e.check(Fa(uc,t)),e.cidrv6=t=>e.check(Ia(dc,t)),e.e164=t=>e.check(za(mc,t)),e.datetime=t=>e.check(ts(t)),e.date=t=>e.check(ns(t)),e.time=t=>e.check(rs(t)),e.duration=t=>e.check(is(t))}),W=M(`ZodStringFormat`,(e,t)=>{L.init(e,t),Ys.init(e,t)}),Zs=M(`ZodEmail`,(e,t)=>{bi.init(e,t),W.init(e,t)}),Qs=M(`ZodGUID`,(e,t)=>{vi.init(e,t),W.init(e,t)}),$s=M(`ZodUUID`,(e,t)=>{yi.init(e,t),W.init(e,t)}),ec=M(`ZodURL`,(e,t)=>{xi.init(e,t),W.init(e,t)}),tc=M(`ZodEmoji`,(e,t)=>{Si.init(e,t),W.init(e,t)}),nc=M(`ZodNanoID`,(e,t)=>{Ci.init(e,t),W.init(e,t)}),rc=M(`ZodCUID`,(e,t)=>{wi.init(e,t),W.init(e,t)}),ic=M(`ZodCUID2`,(e,t)=>{Ti.init(e,t),W.init(e,t)}),ac=M(`ZodULID`,(e,t)=>{Ei.init(e,t),W.init(e,t)}),oc=M(`ZodXID`,(e,t)=>{Di.init(e,t),W.init(e,t)}),sc=M(`ZodKSUID`,(e,t)=>{Oi.init(e,t),W.init(e,t)}),cc=M(`ZodIPv4`,(e,t)=>{Ni.init(e,t),W.init(e,t)}),lc=M(`ZodIPv6`,(e,t)=>{Pi.init(e,t),W.init(e,t)}),uc=M(`ZodCIDRv4`,(e,t)=>{Fi.init(e,t),W.init(e,t)}),dc=M(`ZodCIDRv6`,(e,t)=>{Ii.init(e,t),W.init(e,t)}),fc=M(`ZodBase64`,(e,t)=>{Li.init(e,t),W.init(e,t)}),pc=M(`ZodBase64URL`,(e,t)=>{Ri.init(e,t),W.init(e,t)}),mc=M(`ZodE164`,(e,t)=>{zi.init(e,t),W.init(e,t)}),hc=M(`ZodJWT`,(e,t)=>{Bi.init(e,t),W.init(e,t)}),gc=M(`ZodNumber`,(e,t)=>{Vi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>jo(e,t,n,r),e.gt=(t,n)=>e.check(Qa(t,n)),e.gte=(t,n)=>e.check($a(t,n)),e.min=(t,n)=>e.check($a(t,n)),e.lt=(t,n)=>e.check(Xa(t,n)),e.lte=(t,n)=>e.check(Za(t,n)),e.max=(t,n)=>e.check(Za(t,n)),e.int=t=>e.check(Es(t)),e.safe=t=>e.check(Es(t)),e.positive=t=>e.check(Qa(0,t)),e.nonnegative=t=>e.check($a(0,t)),e.negative=t=>e.check(Xa(0,t)),e.nonpositive=t=>e.check(Za(0,t)),e.multipleOf=(t,n)=>e.check(eo(t,n)),e.step=(t,n)=>e.check(eo(t,n)),e.finite=()=>e;let n=e._zod.bag;e.minValue=Math.max(n.minimum??-1/0,n.exclusiveMinimum??-1/0)??null,e.maxValue=Math.min(n.maximum??1/0,n.exclusiveMaximum??1/0)??null,e.isInt=(n.format??``).includes(`int`)||Number.isSafeInteger(n.multipleOf??.5),e.isFinite=!0,e.format=n.format??null}),_c=M(`ZodNumberFormat`,(e,t)=>{Hi.init(e,t),gc.init(e,t)}),vc=M(`ZodBoolean`,(e,t)=>{Ui.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Mo(e,t,n,r)}),yc=M(`ZodUnknown`,(e,t)=>{Wi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Po(e,t,n,r)}),bc=M(`ZodNever`,(e,t)=>{Gi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>No(e,t,n,r)}),xc=M(`ZodArray`,(e,t)=>{Ki.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>zo(e,t,n,r),e.element=t.element,e.min=(t,n)=>e.check(no(t,n)),e.nonempty=t=>e.check(no(1,t)),e.max=(t,n)=>e.check(to(t,n)),e.length=(t,n)=>e.check(ro(t,n)),e.unwrap=()=>e.element}),Sc=M(`ZodObject`,(e,t)=>{Ji.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Bo(e,t,n,r),N(e,`shape`,()=>t.shape),e.keyof=()=>Is(Object.keys(e._zod.def.shape)),e.catchall=t=>e.clone({...e._zod.def,catchall:t}),e.passthrough=()=>e.clone({...e._zod.def,catchall:Os()}),e.loose=()=>e.clone({...e._zod.def,catchall:Os()}),e.strict=()=>e.clone({...e._zod.def,catchall:ks()}),e.strip=()=>e.clone({...e._zod.def,catchall:void 0}),e.extend=t=>yn(e,t),e.safeExtend=t=>bn(e,t),e.merge=t=>xn(e,t),e.pick=t=>_n(e,t),e.omit=t=>vn(e,t),e.partial=(...t)=>Sn(Ac,e,t[0]),e.required=(...t)=>Cn(Fc,e,t[0])}),Cc=M(`ZodUnion`,(e,t)=>{Yi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Vo(e,t,n,r),e.options=t.options}),wc=M(`ZodDiscriminatedUnion`,(e,t)=>{Cc.init(e,t),Xi.init(e,t)}),Tc=M(`ZodIntersection`,(e,t)=>{Zi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ho(e,t,n,r)}),Ec=M(`ZodRecord`,(e,t)=>{Qi.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Uo(e,t,n,r),e.keyType=t.keyType,e.valueType=t.valueType}),Dc=M(`ZodEnum`,(e,t)=>{$i.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Fo(e,t,n,r),e.enum=t.entries,e.options=Object.values(t.entries);let n=new Set(Object.keys(t.entries));e.extract=(e,r)=>{let i={};for(let r of e)if(n.has(r))i[r]=t.entries[r];else throw Error(`Key ${r} not found in enum`);return new Dc({...t,checks:[],...P(r),entries:i})},e.exclude=(e,r)=>{let i={...t.entries};for(let t of e)if(n.has(t))delete i[t];else throw Error(`Key ${t} not found in enum`);return new Dc({...t,checks:[],...P(r),entries:i})}}),Oc=M(`ZodLiteral`,(e,t)=>{ea.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Io(e,t,n,r),e.values=new Set(t.values),Object.defineProperty(e,"value",{get(){if(t.values.length>1)throw Error("This schema contains multiple valid literal values. Use `.values` instead.");return t.values[0]}})}),kc=M(`ZodTransform`,(e,t)=>{ta.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ro(e,t,n,r),e._zod.parse=(n,r)=>{if(r.direction===`backward`)throw new Zt(e.constructor.name);n.addIssue=r=>{if(typeof r==`string`)n.issues.push(kn(r,n.value,t));else{let t=r;t.fatal&&(t.continue=!1),t.code??=`custom`,t.input??=n.value,t.inst??=e,n.issues.push(kn(t))}};let i=t.transform(n.value,n);return i instanceof Promise?i.then(e=>(n.value=e,n)):(n.value=i,n)}}),Ac=M(`ZodOptional`,(e,t)=>{na.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),jc=M(`ZodExactOptional`,(e,t)=>{ra.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Zo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Mc=M(`ZodNullable`,(e,t)=>{ia.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Wo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Nc=M(`ZodDefault`,(e,t)=>{aa.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Ko(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeDefault=e.unwrap}),Pc=M(`ZodPrefault`,(e,t)=>{oa.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>qo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Fc=M(`ZodNonOptional`,(e,t)=>{sa.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Go(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),Ic=M(`ZodCatch`,(e,t)=>{ca.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Jo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType,e.removeCatch=e.unwrap}),Lc=M(`ZodPipe`,(e,t)=>{la.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Yo(e,t,n,r),e.in=t.in,e.out=t.out}),Rc=M(`ZodReadonly`,(e,t)=>{ua.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Xo(e,t,n,r),e.unwrap=()=>e._zod.def.innerType}),zc=M(`ZodCustom`,(e,t)=>{da.init(e,t),U.init(e,t),e._zod.processJSONSchema=(t,n,r)=>Lo(e,t,n,r)})})),Vc=E((()=>{$o()})),Hc=E((()=>{$o(),Bc(),es(),fs(),Ts(),Vc(),Qo(),_a(),es(),ls(),Bc(),Fn()})),Uc=E((()=>{Hc(),Hc()}));async function Wc(){let e=qc(),[t,n]=await Promise.all([Kc(e,[`--version`]),Kc(e,[`doctor`,`--json`])]);return Gc(t,n)}function Gc(e,t){let n;try{n=JSON.parse(t)}catch(e){throw Error(`agent-browser doctor did not return valid JSON`,{cause:e})}let r=(n.checks?.find(e=>e.id===`chrome.installed`&&e.status===`pass`)?.message)?.split(` at `)[0];if(!r?.match(/^Google Chrome for Testing \d+\.\d+\.\d+\.\d+$/))throw Error(`Kapture requires an exact installed Google Chrome for Testing version`);return`${e}; ${r}`}function Kc(e,t){return new Promise((n,i)=>{let a=r(e,t,{stdio:[`ignore`,`pipe`,`pipe`]}),o=[];a.stdout.on(`data`,e=>o.push(e)),a.once(`error`,i),a.once(`close`,e=>{if(e!==0)return i(Error(`agent-browser ${t.join(` `)} failed (${e})`));n(Buffer.concat(o).toString(`utf8`).trim())})})}function qc(){try{let t=e(import.meta.url),n=t.resolve(`agent-browser/package.json`),r=a(n),i=t(n),o=typeof i.bin==`string`?i.bin:i.bin?.[`agent-browser`]??`bin/agent-browser.js`;return f(r,o)}catch{return`agent-browser`}}async function Jc(e,t,n){let r=JSON.stringify({id:t.id,browserMajor:t.browserVersion.match(/Chrome(?: for Testing)? (\d+)/)?.[1],locale:t.locale,timezone:t.timezone,deviceScaleFactor:t.deviceScaleFactor,colorScheme:t.colorScheme,reducedMotion:t.reducedMotion,frozenTimestamp:Date.parse(t.frozenTime)}),i=JSON.stringify(n);return e.evaluate(`(async () => {
289
289
  const expected = ${r};
290
290
  const parameters = ${i};
291
291
  const actual = {
@@ -538,9 +538,9 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
538
538
  }
539
539
  }
540
540
  return { ignoredRegions };
541
- })()`)}async function Kc(e,t,n,r,i){let[o,s]=await Promise.all([x(e),x(t)]),c=ad.PNG.sync.read(o),l=ad.PNG.sync.read(s),u=Math.max(c.width,l.width),d=Math.max(c.height,l.height),f=Jc(c,u,d),p=Jc(l,u,d),m=qc(f,p,i?.base??[],i?.head??[]),h=new ad.PNG({width:u,height:d}),g=ht(f.data,p.data,h.data,u,d,{threshold:r,includeAA:!1,diffColor:[255,0,0],aaColor:[255,255,0]}),_=u*d-m.pixels;return await y(a(n),{recursive:!0}),await w(n,ad.PNG.sync.write(h)),{changedPixels:g,totalPixels:_,diffRatio:_===0?0:g/_,ignoredRegions:m.regions}}function qc(e,t,n,r){if(n.length===0||r.length===0)return{pixels:0,regions:[]};let{width:i,height:a}=e,o=new Uint8Array(i*a),s=new Map;for(let e of n)for(let t of r){let n=Math.max(0,e.x,t.x),r=Math.max(0,e.y,t.y),c=Math.min(i,e.x+e.width,t.x+t.width),l=Math.min(a,e.y+e.height,t.y+t.height);if(c<=n||l<=r)continue;let u={x:n,y:r,width:c-n,height:l-r};if(s.set(`${n}:${r}:${c}:${l}`,u),s.size>1e4)throw Error(`Too many ignored region intersections`);for(let e=r;e<l;e+=1)o.fill(1,e*i+n,e*i+c)}let c=0;for(let n=0;n<o.length;n+=1){if(o[n]===0)continue;c+=1;let r=n*4;e.data.fill(0,r,r+4),t.data.fill(0,r,r+4)}return{pixels:c,regions:[...s.values()]}}function Jc(e,t,n){if(e.width===t&&e.height===n)return e;let r=new ad.PNG({width:t,height:n}),i=e.width*4;for(let n=0;n<e.height;n+=1){let a=n*i;r.data.set(e.data.subarray(a,a+i),n*t*4)}return r}function Yc(e){return T(`sha256`).update(JSON.stringify(e)).digest(`hex`).slice(0,16)}function Xc(e){let t=[...e.allowedDomains??[`127.0.0.1`,`localhost`]].sort(),n=process.versions.bun,r={browser:`chromium`,browserVersion:e.browserVersion,orchestratorRuntime:e.orchestratorRuntime??(n?`bun ${n}`:`node ${process.version}`),operatingSystem:`${oe()}-${se()}`,architecture:ae(),deviceScaleFactor:e.deviceScaleFactor??1,locale:Zc(e.locale??`en-US`),timezone:Qc(e.timezone??`UTC`),colorScheme:e.colorScheme??`light`,reducedMotion:e.reducedMotion??`reduce`,frozenTime:e.frozenTime??`2026-01-01T00:00:00.000Z`,randomSeed:e.randomSeed??20260101,fontsFingerprint:e.fontsFingerprint??`storybook-bundled-fonts-v1`,stateIsolation:`fresh-browser-process-per-story-side-v1`,network:{mode:`allowlist`,allowedDomains:t,webRtc:`disabled`}};return{id:Yc(r),...r}}function Zc(e){if(!e.trim())throw Error(`Kapture locale must not be empty`);try{let[t]=Intl.getCanonicalLocales(e);if(!t)throw Error(`missing canonical locale`);return t}catch(t){throw Error(`Kapture locale must be a valid BCP 47 tag: ${e}`,{cause:t})}}function Qc(e){if(!e.trim())throw Error(`Kapture timezone must not be empty`);try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}catch(t){throw Error(`Kapture timezone must be a valid IANA time zone: ${e}`,{cause:t})}}function $c(e,t){if(e.id!==t.id||JSON.stringify(e)!==JSON.stringify(t))throw Error(`Kapture environment mismatch: base=${e.id}, head=${t.id}. Base and head must be captured with the exact same environment contract.`)}async function el(){try{let e=(await tl()).split(`
541
+ })()`)}async function Yc(e,t,n,r,i){let[o,s]=await Promise.all([x(e),x(t)]),c=cd.PNG.sync.read(o),l=cd.PNG.sync.read(s),u=Math.max(c.width,l.width),d=Math.max(c.height,l.height),f=Zc(c,u,d),p=Zc(l,u,d),m=Xc(f,p,i?.base??[],i?.head??[]),h=new cd.PNG({width:u,height:d}),g=yt(f.data,p.data,h.data,u,d,{threshold:r,includeAA:!1,diffColor:[255,0,0],aaColor:[255,255,0]}),_=u*d-m.pixels;return await y(a(n),{recursive:!0}),await w(n,cd.PNG.sync.write(h)),{changedPixels:g,totalPixels:_,diffRatio:_===0?0:g/_,ignoredRegions:m.regions}}function Xc(e,t,n,r){if(n.length===0||r.length===0)return{pixels:0,regions:[]};let{width:i,height:a}=e,o=new Uint8Array(i*a),s=new Map;for(let e of n)for(let t of r){let n=Math.max(0,e.x,t.x),r=Math.max(0,e.y,t.y),c=Math.min(i,e.x+e.width,t.x+t.width),l=Math.min(a,e.y+e.height,t.y+t.height);if(c<=n||l<=r)continue;let u={x:n,y:r,width:c-n,height:l-r};if(s.set(`${n}:${r}:${c}:${l}`,u),s.size>1e4)throw Error(`Too many ignored region intersections`);for(let e=r;e<l;e+=1)o.fill(1,e*i+n,e*i+c)}let c=0;for(let n=0;n<o.length;n+=1){if(o[n]===0)continue;c+=1;let r=n*4;e.data.fill(0,r,r+4),t.data.fill(0,r,r+4)}return{pixels:c,regions:[...s.values()]}}function Zc(e,t,n){if(e.width===t&&e.height===n)return e;let r=new cd.PNG({width:t,height:n}),i=e.width*4;for(let n=0;n<e.height;n+=1){let a=n*i;r.data.set(e.data.subarray(a,a+i),n*t*4)}return r}function Qc(e){return T(`sha256`).update(JSON.stringify(e)).digest(`hex`).slice(0,16)}function $c(e){let t=[...e.allowedDomains??[`127.0.0.1`,`localhost`]].sort(),n=process.versions.bun,r={browser:`chromium`,browserVersion:e.browserVersion,orchestratorRuntime:e.orchestratorRuntime??(n?`bun ${n}`:`node ${process.version}`),operatingSystem:`${oe()}-${se()}`,architecture:ae(),deviceScaleFactor:e.deviceScaleFactor??1,locale:el(e.locale??`en-US`),timezone:tl(e.timezone??`UTC`),colorScheme:e.colorScheme??`light`,reducedMotion:e.reducedMotion??`reduce`,frozenTime:e.frozenTime??`2026-01-01T00:00:00.000Z`,randomSeed:e.randomSeed??20260101,fontsFingerprint:e.fontsFingerprint??`storybook-bundled-fonts-v1`,stateIsolation:`fresh-browser-process-per-story-side-v1`,network:{mode:`allowlist`,allowedDomains:t,webRtc:`disabled`}};return{id:Qc(r),...r}}function el(e){if(!e.trim())throw Error(`Kapture locale must not be empty`);try{let[t]=Intl.getCanonicalLocales(e);if(!t)throw Error(`missing canonical locale`);return t}catch(t){throw Error(`Kapture locale must be a valid BCP 47 tag: ${e}`,{cause:t})}}function tl(e){if(!e.trim())throw Error(`Kapture timezone must not be empty`);try{return new Intl.DateTimeFormat(`en-US`,{timeZone:e}).resolvedOptions().timeZone}catch(t){throw Error(`Kapture timezone must be a valid IANA time zone: ${e}`,{cause:t})}}function nl(e,t){if(e.id!==t.id||JSON.stringify(e)!==JSON.stringify(t))throw Error(`Kapture environment mismatch: base=${e.id}, head=${t.id}. Base and head must be captured with the exact same environment contract.`)}async function rl(){try{let e=(await il()).split(`
542
542
  `).filter(Boolean).sort().join(`
543
- `);return`fontconfig:${T(`sha256`).update(e).digest(`hex`)}`}catch{return`fontconfig-unavailable:${oe()}-${se()}`}}function tl(){return new Promise((e,t)=>{let n=r(`fc-list`,[`--format`,`%{file}|%{family}|%{style}\\n`],{stdio:[`ignore`,`pipe`,`ignore`]}),i=[];n.stdout.on(`data`,e=>i.push(e)),n.once(`error`,t),n.once(`close`,n=>{if(n!==0)return t(Error(`fc-list failed (${n})`));e(Buffer.concat(i).toString(`utf8`))})})}function nl(e){let t=Date.parse(e.frozenTime);if(!Number.isFinite(t))throw Error(`Invalid frozenTime: ${e.frozenTime}`);return`(() => {
543
+ `);return`fontconfig:${T(`sha256`).update(e).digest(`hex`)}`}catch{return`fontconfig-unavailable:${oe()}-${se()}`}}function il(){return new Promise((e,t)=>{let n=r(`fc-list`,[`--format`,`%{file}|%{family}|%{style}\\n`],{stdio:[`ignore`,`pipe`,`ignore`]}),i=[];n.stdout.on(`data`,e=>i.push(e)),n.once(`error`,t),n.once(`close`,n=>{if(n!==0)return t(Error(`fc-list failed (${n})`));e(Buffer.concat(i).toString(`utf8`))})})}function al(e){let t=Date.parse(e.frozenTime);if(!Number.isFinite(t))throw Error(`Invalid frozenTime: ${e.frozenTime}`);return`(() => {
544
544
  const NativeDate = globalThis.Date;
545
545
  const frozenTimestamp = ${t};
546
546
  const KaptureDate = new Proxy(NativeDate, {
@@ -567,7 +567,7 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
567
567
  configurable: false,
568
568
  writable: false,
569
569
  });
570
- })();`}function rl(e){let t=new Set;for(let n of Object.values(e.entries)){for(let e of dd){let r=n[e];r&&t.add(r)}for(let e of[n.instability?.base,n.instability?.head])e?.repeatImage&&t.add(e.repeatImage),e?.diffImage&&t.add(e.diffImage)}return[...t].sort(ll)}function il(e){return sl({report:ol(e)})}function al(e,t){let n=rl(e),r=new Set(n),i=new Map;for(let e of t){if(!e.path||!fd.test(e.sha256))throw Error(`Invalid report image digest for ${e.path||`<empty path>`}`);if(i.has(e.path))throw Error(`Duplicate report image digest for ${e.path}`);i.set(e.path,e.sha256)}for(let e of n)if(!i.has(e))throw Error(`Missing report image digest for ${e}`);for(let e of i.keys())if(!r.has(e))throw Error(`Unexpected report image digest for ${e}`);return sl({report:ol(e),images:n.map(e=>({path:e,sha256:i.get(e)}))})}function ol(e){let{contentDigest:t,...n}=e;return n}function sl(e){return T(`sha256`).update(JSON.stringify(cl(e))).digest(`hex`)}function cl(e){return Array.isArray(e)?e.map(cl):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>ll(e,t)).map(([e,t])=>[e,cl(t)]))}function ll(e,t){return e<t?-1:+(e>t)}async function ul(e){let t=await x(e);return T(`sha256`).update(t).digest(`hex`)}function dl(e){let t=T(`sha256`).update(e).digest(`hex`).slice(0,12);return`${e.replace(/[^a-zA-Z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,120)||`snapshot`}-${t}.png`}async function fl(e){let{baseManifest:t,headManifest:n,baseRoot:r,headRoot:i,outputDir:a,threshold:o,coverage:s,stability:l}=e;$c(t.environment,n.environment),await re(c(a,`images`),{recursive:!0,force:!0}),await y(c(a,`images`),{recursive:!0});let u=s?new Set(s.selectedStoryIds):void 0,d=[...new Set([...Object.keys(t.snapshots),...Object.keys(n.snapshots)])].filter(e=>{if(!u)return!0;let r=n.snapshots[e]??t.snapshots[e];return r?u.has(r.storyId):!1}).sort(),f={};for(let e of d){let s=t.snapshots[e],c=n.snapshots[e];f[e]=await pl({id:e,base:s,head:c,baseRoot:r,headRoot:i,outputDir:a,threshold:o,stability:l&&s&&c?{base:l.baseManifest.snapshots[e],head:l.headManifest.snapshots[e],baseRoot:l.baseRoot,headRoot:l.headRoot}:void 0})}let p=Object.values(f),m={version:3,baseRevision:t.revision,headRevision:n.revision,environment:t.environment,createdAt:new Date().toISOString(),threshold:o,summary:{total:p.length,unchanged:p.filter(e=>e.status===`unchanged`).length,changed:p.filter(e=>e.status===`changed`).length,unstable:p.filter(e=>e.status===`unstable`).length,added:p.filter(e=>e.status===`added`).length,removed:p.filter(e=>e.status===`removed`).length,errors:p.filter(e=>e.status===`error`).length},...s?{coverage:s}:{},entries:f},h=[];for(let e of rl(m))h.push({path:e,sha256:await ul(c(a,e))});return m.contentDigest=al(m,h),await w(c(a,`report.json`),`${JSON.stringify(m,null,2)}\n`),m}async function pl(e){let{id:t,base:n,head:r,baseRoot:a,headRoot:o,outputDir:s,threshold:l,stability:u}=e,d=r??n;if(!d)throw Error(`Snapshot ${t} has no base or head record`);let f={id:t,storyId:d.storyId,title:d.title,name:d.name,viewport:d.viewport},p={...l,...r?.threshold??n?.threshold};if(n?.error||r?.error)return{...f,status:`error`,threshold:p,error:[n?.error,r?.error].filter(Boolean).join(` | `)};if(!n&&r)return{...f,status:`added`,threshold:p,headImage:await hl(`head`,r,o,s)};if(n&&!r)return{...f,status:`removed`,threshold:p,baseImage:await hl(`base`,n,a,s)};if(!n||!r)throw Error(`Invalid manifest pair for ${t}`);if(n.viewport.width!==r.viewport.width||n.viewport.height!==r.viewport.height)return{...f,status:`error`,threshold:p,error:`Viewport contract differs: base=${n.viewport.width}x${n.viewport.height}, head=${r.viewport.width}x${r.viewport.height}`};if(n.sha256===r.sha256)return{...f,status:`unchanged`,threshold:p};let m=`images/diff/${i(n.imageFile)}`;try{let e=await Kc(c(a,n.imageFile),c(o,r.imageFile),c(s,m),p.pixelColorThreshold,{base:n.ignoredRegions??[],head:r.ignoredRegions??[]});if(e.diffRatio<=p.maxChangedPixelRatio)return await re(c(s,m),{force:!0}),{...f,status:`unchanged`,threshold:p,changedPixels:e.changedPixels,diffRatio:e.diffRatio};let[i,l]=await Promise.all([hl(`base`,n,a,s),hl(`head`,r,o,s)]),d=u?await ml({id:t,base:n,head:r,baseRepeat:u.base,headRepeat:u.head,baseRoot:a,headRoot:o,baseRepeatRoot:u.baseRoot,headRepeatRoot:u.headRoot,outputDir:s,threshold:p}):void 0;return{...f,status:d?`unstable`:`changed`,threshold:p,baseImage:i,headImage:l,diffImage:m,changedPixels:e.changedPixels,diffRatio:e.diffRatio,ignoredRegions:e.ignoredRegions,...d?{instability:d}:{}}}catch(e){return{...f,status:`error`,threshold:p,error:e instanceof Error?e.message:String(e)}}}async function ml(e){let t={};for(let n of[`base`,`head`]){let r=e[n],a=n===`base`?e.baseRepeat:e.headRepeat;if(!a)throw Error(`Kapture ${n} stability recapture is missing for ${e.id}`);if(a.error)throw Error(`Kapture ${n} stability recapture failed: ${a.error}`);if(r.sha256===a.sha256)continue;let o=n===`base`?e.baseRepeatRoot:e.headRepeatRoot,s=n===`base`?e.baseRoot:e.headRoot,l=`images/${n}-instability-diff/${i(r.imageFile)}`,u=await Kc(c(s,r.imageFile),c(o,a.imageFile),c(e.outputDir,l),e.threshold.pixelColorThreshold,{base:r.ignoredRegions??[],head:a.ignoredRegions??[]});if(u.diffRatio<=e.threshold.maxChangedPixelRatio){await re(c(e.outputDir,l),{force:!0});continue}t[n]={repeatImage:await hl(`${n}-repeat`,a,o,e.outputDir),diffImage:l,changedPixels:u.changedPixels,diffRatio:u.diffRatio}}return t.base||t.head?t:void 0}async function hl(e,t,n,r){let a=`images/${e}/${i(t.imageFile)}`;return await y(c(r,`images`,e),{recursive:!0}),await g(c(n,t.imageFile),c(r,a)),a}async function gl(e){let t=await S(f(e)),n=le(async(e,n)=>{try{let r=decodeURIComponent(new URL(e.url??`/`,`http://localhost`).pathname),i=f(t,`.${r}`);if(!_l(t,i)){n.writeHead(403).end(`Forbidden`);return}let a=await S(i);if(!_l(t,a)){n.writeHead(403).end(`Forbidden`);return}if((await C(a)).isDirectory()&&(a=await S(f(a,`index.html`)),!_l(t,a))){n.writeHead(403).end(`Forbidden`);return}let s=await x(a);n.writeHead(200,{"cache-control":`no-store`,"content-type":pd[o(a)]??`application/octet-stream`}),n.end(s)}catch{n.writeHead(404).end(`Not found`)}});await vl(n);let r=n.address();if(!r||typeof r==`string`)throw Error(`Static server has no TCP address`);return{url:`http://127.0.0.1:${r.port}/`,close:()=>yl(n)}}function _l(e,t){return t===e||t.startsWith(`${e}${p}`)}function vl(e){return new Promise((t,n)=>{e.once(`error`,n),e.listen(0,`127.0.0.1`,()=>{e.off(`error`,n),t()})})}function yl(e){return new Promise((t,n)=>{e.close(e=>e?n(e):t())})}async function bl(e,t){await y(a(e),{recursive:!0}),await w(e,`${JSON.stringify(t,null,2)}\n`)}async function xl(e){return _d.parse(JSON.parse(await x(e,`utf8`)))}async function Sl(e,t){let n=T(`sha256`).update(`kapture-capture-cache\0${t}\0`);async function r(e,t){let i=await v(e);if(i.isSymbolicLink())throw Error(`Capture cache cannot fingerprint symlinks`);if(i.isDirectory())for(let n of(await te(e)).sort())await r(c(e,n),`${t}/${n}`);else if(i.isFile()){n.update(`${t}\0${i.size}\0`);for await(let t of de(e))n.update(t)}else throw Error(`Unsupported Storybook file type`)}return await r(e,``),n.digest(`hex`)}async function Cl(e,t){let n=vd.parse(JSON.parse(await x(c(e,`cache.json`),`utf8`)));if(n.buildDigest!==t)throw Error(`Capture cache build mismatch`);if(await ul(c(e,`manifest.json`))!==n.manifestDigest)throw Error(`Capture cache manifest digest mismatch`);let r=await xl(c(e,`manifest.json`));if(Object.values(r.snapshots).some(e=>e.error))throw Error(`Capture cache contains errors`);return r}async function wl(e,t,n,r){if(!(!Object.keys(r.snapshots).length||Object.values(r.snapshots).some(e=>e.error))){await y(c(e,`images`),{recursive:!0});for(let n of Object.values(r.snapshots)){let r=c(t,n.imageFile);if(await ul(r)!==n.sha256)throw Error(`Capture cache image digest mismatch`);await g(r,c(e,n.imageFile))}await bl(c(e,`manifest.json`),r),await w(c(e,`cache.json`),JSON.stringify({version:1,buildDigest:n,manifestDigest:await ul(c(e,`manifest.json`))}))}}function Tl(e){return Ad.parse(e)}async function El(e){let t=c(e,yd),n;try{n=await x(t)}catch(e){return Fl(e)?{evidence:{state:`missing`}}:{evidence:{state:`invalid`}}}try{let t=await Dl(e,Tl(JSON.parse(n.toString(`utf8`))));return{manifest:t,evidence:{state:`valid`,digest:Al(t)}}}catch{return{evidence:{state:`invalid`,digest:Nl(n)}}}}async function Dl(e,t){let n=!0;for(let[r,i]of Object.entries(t.outputInventory))try{let t=c(e,r),a=await v(t);if(!a.isFile()||a.isSymbolicLink()){n=!1;break}let o=await x(t);if(o.byteLength!==i.size||Nl(o)!==i.sha256){n=!1;break}}catch{n=!1;break}if(n)for(let r of t.outputInventoryPrefixes){let i=await Ol(e,r),a=Object.keys(t.outputInventory).filter(e=>e.startsWith(r)).sort();if(!i||!kl(i,a)){n=!1;break}}return n?t:Ad.parse({...t,complete:!1,diagnostics:[...new Set([...t.diagnostics,`output-inventory-mismatch`])].sort()})}async function Ol(e,t){let n=[],r=[t===``?``:t.slice(0,-1)];try{for(;r.length>0;){let t=r.pop(),i=await te(c(e,t),{withFileTypes:!0});for(let e of i){let i=t?`${t}/${e.name}`:e.name;if(e.isSymbolicLink())return null;if(e.isDirectory())r.push(i);else if(e.isFile())i!==`kapture-dependencies.json`&&n.push(i);else return null;if(n.length+r.length>1e5)return null}}}catch{return null}return n.sort()}function kl(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Al(e){return Nl(JSON.stringify(Pl(e)))}function jl(e,t){return{base:e?{state:`valid`,digest:Al(e)}:{state:`missing`},head:t?{state:`valid`,digest:Al(t)}:{state:`missing`}}}function Ml(e){return e!==``&&!e.includes(`\\`)&&!e.includes(`\0`)&&!e.startsWith(`/`)&&!/^[A-Za-z]:\//.test(e)&&e!==`.`&&e!==`..`&&!e.startsWith(`./`)&&!e.startsWith(`../`)&&!e.split(`/`).some(e=>e===`.`||e===`..`)&&!e.includes(`//`)&&!e.endsWith(`/`)}function Nl(e){return T(`sha256`).update(e).digest(`hex`)}function Pl(e){return Array.isArray(e)?e.map(Pl):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Pl(t)]))}function Fl(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}async function Il({baseDir:e,headDir:t,changedFiles:n,changedFilesComplete:r=!0,changedFilesEvidence:i}){let[a,o,s,c]=await Promise.all([Rl(e),Rl(t),Zl(e,`base`),Zl(t,`head`)]);return Ll({baseIndex:a,headIndex:o,baseManifest:s.manifest,headManifest:c.manifest,changedFiles:n,changedFilesComplete:r,changedFilesEvidence:i,dependencyManifests:{base:s.evidence,head:c.evidence},initialFallbackReasons:[...s.reason?[s.reason]:[],...c.reason?[c.reason]:[]]})}function Ll(e){let t=Yl(e.changedFiles.map(Hl)),n=zl(e.baseIndex),r=zl(e.headIndex),i=Yl([...n.keys(),...r.keys()]),a=[...r.keys()].filter(e=>!n.has(e)).sort(),o=[...n.keys()].filter(e=>!r.has(e)).sort(),s=[...e.initialFallbackReasons??[],...e.changedFilesComplete===!1?[{code:`changed-files-incomplete`}]:[]],{baseManifest:c,headManifest:l}=e,u=e.dependencyManifests??jl(c,l),d=new Set,f=new Set;!c&&!s.some(e=>e.code.startsWith(`base-manifest`))&&s.push({code:`base-manifest-missing`,side:`base`}),!l&&!s.some(e=>e.code.startsWith(`head-manifest`))&&s.push({code:`head-manifest-missing`,side:`head`}),c&&!c.complete&&s.push({code:`manifest-incomplete`,side:`base`}),l&&!l.complete&&s.push({code:`manifest-incomplete`,side:`head`});let p=new Map;if(c&&l){c.globalRuntimeFingerprint!==l.globalRuntimeFingerprint&&s.push({code:`global-runtime`});for(let e of new Set([...Object.keys(c.globalOutputFingerprints),...Object.keys(l.globalOutputFingerprints)]))(c.globalOutputFingerprints[e]!==l.globalOutputFingerprints[e]||!Jl(new Set(c.globalOutputStories[e]??[]),new Set(l.globalOutputStories[e]??[])))&&f.add(e);for(let e of new Set([...Object.keys(c.renderedOutputFingerprints),...Object.keys(l.renderedOutputFingerprints)]))c.renderedOutputFingerprints[e]!==l.renderedOutputFingerprints[e]&&d.add(e);if(c.moduleFingerprints&&l.moduleFingerprints)for(let e of new Set([...Object.keys(c.moduleFingerprints),...Object.keys(l.moduleFingerprints)]))c.moduleFingerprints[e]!==l.moduleFingerprints[e]&&d.add(e);for(let e of i){let t=n.get(e),i=r.get(e),a=t?Bl(t,c,`base`,s):void 0,o=i?Bl(i,l,`head`,s):void 0;p.set(e,{base:a,head:o})}let e=new Set,a=new Set;for(let t of[c,l])for(let[n,r]of Object.entries(t.modules)){e.add(n);for(let t of r)e.add(t)}for(let e of p.values()){if(e.base)for(let t of Gl(c,e.base))a.add(t);if(e.head)for(let t of Gl(l,e.head))a.add(t)}for(let e of f){let t=Kl(c,l,e);if(!t||[...t].some(e=>!a.has(e))){s.push({code:`global-output`,path:e});continue}for(let e of t)d.add(e)}for(let e of d)(Ul(e,c.globalInputs)||Ul(e,l.globalInputs))&&s.push({code:`global-input`,path:e});for(let n of t){if(Ul(n,c.globalInputs)||Ul(n,l.globalInputs)){s.push({code:`global-input`,path:n});continue}let t=Ul(n,c.ignoredInputs)&&Ul(n,l.ignoredInputs),r=Wl(c)&&Wl(l)&&Ul(n,c.fingerprintedInputs??[])&&Ul(n,l.fingerprintedInputs??[]);!t&&!r&&(!e.has(n)||!a.has(n))&&s.push({code:`unknown-input`,path:n})}}let m=Xl(s);if(m.length>0||!c||!l)return{version:1,selectionMode:`full-fallback`,changedFiles:t,...e.changedFilesEvidence?{changedFilesEvidence:{...e.changedFilesEvidence}}:{},dependencyManifests:eu(u),totalStoryIds:i,selectedStoryIds:i,skippedStoryIds:[],addedStoryIds:a,removedStoryIds:o,fallbackReasons:m};let h=new Set([...a,...o]);for(let e of i){let n=p.get(e);if(!n)continue;if(n.base!==n.head){h.add(e);continue}let r=n.base?Gl(c,n.base):new Set,i=n.head?Gl(l,n.head):new Set;if(!Jl(r,i)){h.add(e);continue}let a=new Set([...r,...i]);(t.some(e=>a.has(e))||[...a].some(e=>d.has(e)))&&h.add(e)}let g=[...h].sort();return{version:1,selectionMode:`affected`,changedFiles:t,...e.changedFilesEvidence?{changedFilesEvidence:{...e.changedFilesEvidence}}:{},dependencyManifests:eu(u),totalStoryIds:i,selectedStoryIds:g,skippedStoryIds:i.filter(e=>!h.has(e)),addedStoryIds:a,removedStoryIds:o,fallbackReasons:[]}}async function Rl(e){return Nd.parse(JSON.parse(await x(c(e,`index.json`),`utf8`)))}function zl(e){return new Map(Object.values(e.entries).filter(e=>e.type===`story`).sort((e,t)=>e.id.localeCompare(t.id)).map(e=>[e.id,e]))}function Bl(e,t,n,r){if(!e.importPath){r.push({code:`story-import-missing`,storyId:e.id,side:n});return}let i;try{i=Vl(t.storybookRoot,e.importPath)}catch{r.push({code:`story-import-missing`,storyId:e.id,side:n});return}if(!t.modules[i]){r.push({code:`story-module-missing`,storyId:e.id,side:n});return}if(t.renderedModules&&!t.renderedModules[i]?.includes(i)){r.push({code:`story-module-missing`,storyId:e.id,side:n});return}return i}function Vl(e,t){let n=t.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(s(n)||/^[A-Za-z]:\//.test(n))throw Error(`Story importPath must be relative`);let r=u.normalize(u.join(e,n));if(r===`..`||r.startsWith(`../`)||r===`.`)throw Error(`Story importPath must stay within project root`);return r}function Hl(e){let t=e.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(t.length===0||t.includes(`\0`)||s(t)||/^[A-Za-z]:\//.test(t)||t===`..`||t.startsWith(`../`)||t.split(`/`).some(e=>e===`.`||e===`..`)||t.includes(`//`)||t.endsWith(`/`))throw Error(`Changed file must be a normalized project-relative path: ${e}`);return t}function Ul(e,t){return t.some(t=>e===t||l(e,t))}function Wl(e){return!e.complete||!e.moduleFingerprints?!1:Object.keys(e.modules).every(t=>e.moduleFingerprints?.[t]!==void 0)}function Gl(e,t){let n=ql(e,t),r=e.renderedModules?.[t];return r?new Set(r):n}function Kl(e,t,n){let r=e.globalOutputFingerprints[n]!==void 0,i=t.globalOutputFingerprints[n]!==void 0;if(r&&i&&e.globalOutputFingerprints[n]!==t.globalOutputFingerprints[n])return null;let a=new Set(e.globalOutputStories[n]??[]),o=new Set(t.globalOutputStories[n]??[]);if(r&&a.size===0||i&&o.size===0)return null;let s=new Set([...a,...o]);return s.size>0?s:null}function ql(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(!(!t||n.has(t))){n.add(t);for(let i of e.modules[t]??[])n.has(i)||r.push(i)}}return n}function Jl(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function Yl(e){return[...new Set(e)].sort()}function Xl(e){let t=new Map;for(let n of e)t.set($l(n),n);let n=[...t.values()].sort(Ql);return n.length<=1e3?n:[...n.filter(e=>e.code!==`fallback-reasons-truncated`).slice(0,999),{code:`fallback-reasons-truncated`}].sort(Ql)}async function Zl(e,t){let n=await El(e);if(n.manifest)return n;let r=`${t}-manifest-${n.evidence.state}`;return{evidence:n.evidence,reason:{code:r,side:t}}}function Ql(e,t){return $l(e).localeCompare($l(t))}function $l(e){return`${e.code}:${e.side??``}:${e.path??``}:${e.storyId??``}`}function eu(e){return{base:{...e.base},head:{...e.head}}}async function tu(e){let t=await fetch(new URL(`index.json`,iu(e)));if(!t.ok)throw Error(`Failed to read Storybook index (${t.status}) from ${e}`);return Fd.parse(await t.json())}function nu(e){return Object.values(e.entries).filter(e=>e.type===`story`).sort((e,t)=>e.id.localeCompare(t.id))}function ru(e,t){let n=new URL(`iframe.html`,iu(e));return n.searchParams.set(`id`,t),n.searchParams.set(`viewMode`,`story`),n.toString()}function iu(e){return e.endsWith(`/`)?e:`${e}/`}function au(e){let t=hu(e,`bridge`);if(t.protocolVersion!==4)throw Error(`Unsupported Kapture Storybook protocol ${String(t.protocolVersion)}; expected 4`);let n=_u(t.adapterVersion,`adapterVersion`),r=t.state;if(r===`booting`)return{protocolVersion:4,adapterVersion:n,state:r};if(![`rendering`,`ready`,`error`].includes(r))throw Error(`Invalid Kapture Storybook bridge state: ${String(r)}`);let i=_u(t.storyId,`storyId`),a=wu(t.generation,`generation`),o=bu(t.renderId,`renderId`);if(r===`rendering`)return{protocolVersion:4,adapterVersion:n,state:r,storyId:i,generation:a,renderId:o,parameters:t.parameters===void 0?void 0:ou(t.parameters)};if(r===`ready`){if(o===void 0)throw Error(`Kapture ready bridge requires renderId`);return{protocolVersion:4,adapterVersion:n,state:r,storyId:i,generation:a,renderId:o,parameters:ou(t.parameters)}}let s=hu(t.error,`error`);if(s.kind!==`configuration`&&s.kind!==`storybook`)throw Error(`Invalid Kapture bridge error kind: ${String(s.kind)}`);return{protocolVersion:4,adapterVersion:n,state:`error`,storyId:i,generation:a,renderId:o,error:{kind:s.kind,message:_u(s.message,`error.message`)}}}function ou(e){let t=hu(e,`parameters`);return Du({captureEnabled:yu(t.captureEnabled,`captureEnabled`),captureViewports:su(t.captureViewports),captureArea:cu(t.captureArea),captureDelayMs:Su(t.captureDelayMs,`captureDelayMs`),waitForElement:uu(t.waitForElement),animationState:du(t.animationState),maskSelectors:mu(t.maskSelectors,`maskSelectors`),diffIgnoreSelectors:mu(t.diffIgnoreSelectors,`diffIgnoreSelectors`),waitForFonts:yu(t.waitForFonts,`waitForFonts`),fontAssertions:t.fontAssertions===void 0?void 0:gu(t.fontAssertions,`fontAssertions`).map((e,t)=>fu(e,`fontAssertions[${t}]`)),diff:pu(t.diff)})}function su(e){if(e===void 0)return;let t=gu(e,`captureViewports`);if(t.length===0)throw Error(`Kapture captureViewports must contain at least one viewport; use captureEnabled: false to skip`);return t.map((e,t)=>lu(e,`captureViewports[${t}]`))}function cu(e){if(e===void 0||e===`full-page`||e===`viewport`)return e;throw Error(`Invalid Kapture captureArea: ${String(e)}`)}function lu(e,t){let n=hu(e,t);return{name:_u(n.name,`${t}.name`),width:Cu(n.width,`${t}.width`),height:Cu(n.height,`${t}.height`)}}function uu(e){if(e===void 0)return;let t=hu(e,`waitForElement`),n=t.state;if(n!==void 0&&n!==`attached`&&n!==`visible`&&n!==`hidden`&&n!==`detached`)throw Error(`Invalid Kapture waitForElement state: ${String(n)}`);return Du({selector:_u(t.selector,`waitForElement.selector`),state:n,timeoutMs:Su(t.timeoutMs,`waitForElement.timeoutMs`)})}function du(e){if(e!==void 0)return e===`disabled`||e===`start`||e===`end`?e:{atMs:xu(hu(e,`animationState`).atMs,`animationState.atMs`)}}function fu(e,t){let n=hu(e,t),r=n.weight;if(r!==void 0&&typeof r!=`string`&&typeof r!=`number`)throw Error(`${t}.weight must be a string or number`);return Du({family:_u(n.family,`${t}.family`),glyphs:_u(n.glyphs,`${t}.glyphs`),style:vu(n.style,`${t}.style`),weight:r})}function pu(e){if(e===void 0)return;let t=hu(e,`diff`);if(`maxChangedPixelRatio`in t)throw Error(`Kapture diff.maxChangedPixelRatio is not supported; use diff.maxChangedPixelPercentage with a value between 0 and 100`);return Du({pixelColorThreshold:Tu(t.pixelColorThreshold,`diff.pixelColorThreshold`),maxChangedPixelPercentage:Eu(t.maxChangedPixelPercentage,`diff.maxChangedPixelPercentage`)})}function mu(e,t){if(e!==void 0)return gu(e,t).map((e,n)=>_u(e,`${t}[${n}]`))}function hu(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Kapture ${t} must be an object`);return e}function gu(e,t){if(!Array.isArray(e))throw Error(`Kapture ${t} must be an array`);return e}function _u(e,t){if(typeof e!=`string`||!e.trim())throw Error(`Kapture ${t} must be a non-empty string`);return e}function vu(e,t){return e===void 0?void 0:_u(e,t)}function yu(e,t){if(e!==void 0){if(typeof e!=`boolean`)throw Error(`Kapture ${t} must be a boolean`);return e}}function bu(e,t){if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Kapture ${t} must be a finite number`);return e}}function xu(e,t){let n=bu(e,t);if(n===void 0||n<0)throw Error(`Kapture ${t} must be a non-negative number`);return n}function Su(e,t){return e===void 0?void 0:xu(e,t)}function Cu(e,t){let n=bu(e,t);if(n===void 0||n<=0)throw Error(`Kapture ${t} must be positive`);return n}function wu(e,t){let n=xu(e,t);if(!Number.isInteger(n))throw Error(`Kapture ${t} must be an integer`);return n}function Tu(e,t){if(e===void 0)return;let n=xu(e,t);if(n>1)throw Error(`Kapture ${t} must be between 0 and 1`);return n}function Eu(e,t){if(e===void 0)return;let n=xu(e,t);if(n>100)throw Error(`Kapture ${t} must be between 0 and 100`);return n}function Du(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function Ou(e,t,n){let r=JSON.stringify(t),i=await e.evaluate(`(async () => {
570
+ })();`}function ol(e){let t=new Set;for(let n of Object.values(e.entries)){for(let e of md){let r=n[e];r&&t.add(r)}for(let e of[n.instability?.base,n.instability?.head])e?.repeatImage&&t.add(e.repeatImage),e?.diffImage&&t.add(e.diffImage)}return[...t].sort(fl)}function sl(e){return ul({report:ll(e)})}function cl(e,t){let n=ol(e),r=new Set(n),i=new Map;for(let e of t){if(!e.path||!hd.test(e.sha256))throw Error(`Invalid report image digest for ${e.path||`<empty path>`}`);if(i.has(e.path))throw Error(`Duplicate report image digest for ${e.path}`);i.set(e.path,e.sha256)}for(let e of n)if(!i.has(e))throw Error(`Missing report image digest for ${e}`);for(let e of i.keys())if(!r.has(e))throw Error(`Unexpected report image digest for ${e}`);return ul({report:ll(e),images:n.map(e=>({path:e,sha256:i.get(e)}))})}function ll(e){let{contentDigest:t,...n}=e;return n}function ul(e){return T(`sha256`).update(JSON.stringify(dl(e))).digest(`hex`)}function dl(e){return Array.isArray(e)?e.map(dl):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0).sort(([e],[t])=>fl(e,t)).map(([e,t])=>[e,dl(t)]))}function fl(e,t){return e<t?-1:+(e>t)}async function pl(e){let t=await x(e);return T(`sha256`).update(t).digest(`hex`)}function ml(e){let t=T(`sha256`).update(e).digest(`hex`).slice(0,12);return`${e.replace(/[^a-zA-Z0-9_-]+/g,`-`).replace(/^-+|-+$/g,``).slice(0,120)||`snapshot`}-${t}.png`}async function hl(e){let{baseManifest:t,headManifest:n,baseRoot:r,headRoot:i,outputDir:a,threshold:o,coverage:s,stability:l}=e;nl(t.environment,n.environment),await re(c(a,`images`),{recursive:!0,force:!0}),await y(c(a,`images`),{recursive:!0});let u=s?new Set(s.selectedStoryIds):void 0,d=[...new Set([...Object.keys(t.snapshots),...Object.keys(n.snapshots)])].filter(e=>{if(!u)return!0;let r=n.snapshots[e]??t.snapshots[e];return r?u.has(r.storyId):!1}).sort(),f={};for(let e of d){let s=t.snapshots[e],c=n.snapshots[e];f[e]=await gl({id:e,base:s,head:c,baseRoot:r,headRoot:i,outputDir:a,threshold:o,stability:l&&s&&c?{base:l.baseManifest.snapshots[e],head:l.headManifest.snapshots[e],baseRoot:l.baseRoot,headRoot:l.headRoot}:void 0})}let p=Object.values(f),m={version:3,baseRevision:t.revision,headRevision:n.revision,environment:t.environment,createdAt:new Date().toISOString(),threshold:o,summary:{total:p.length,unchanged:p.filter(e=>e.status===`unchanged`).length,changed:p.filter(e=>e.status===`changed`).length,unstable:p.filter(e=>e.status===`unstable`).length,added:p.filter(e=>e.status===`added`).length,removed:p.filter(e=>e.status===`removed`).length,errors:p.filter(e=>e.status===`error`).length},...s?{coverage:s}:{},entries:f},h=[];for(let e of ol(m))h.push({path:e,sha256:await pl(c(a,e))});return m.contentDigest=cl(m,h),await w(c(a,`report.json`),`${JSON.stringify(m,null,2)}\n`),m}async function gl(e){let{id:t,base:n,head:r,baseRoot:a,headRoot:o,outputDir:s,threshold:l,stability:u}=e,d=r??n;if(!d)throw Error(`Snapshot ${t} has no base or head record`);let f={id:t,storyId:d.storyId,title:d.title,name:d.name,viewport:d.viewport},p={...l,...r?.threshold??n?.threshold};if(n?.error||r?.error)return{...f,status:`error`,threshold:p,error:[n?.error,r?.error].filter(Boolean).join(` | `)};if(!n&&r)return{...f,status:`added`,threshold:p,headImage:await vl(`head`,r,o,s)};if(n&&!r)return{...f,status:`removed`,threshold:p,baseImage:await vl(`base`,n,a,s)};if(!n||!r)throw Error(`Invalid manifest pair for ${t}`);if(n.viewport.width!==r.viewport.width||n.viewport.height!==r.viewport.height)return{...f,status:`error`,threshold:p,error:`Viewport contract differs: base=${n.viewport.width}x${n.viewport.height}, head=${r.viewport.width}x${r.viewport.height}`};if(n.sha256===r.sha256)return{...f,status:`unchanged`,threshold:p};let m=`images/diff/${i(n.imageFile)}`;try{let e=await Yc(c(a,n.imageFile),c(o,r.imageFile),c(s,m),p.pixelColorThreshold,{base:n.ignoredRegions??[],head:r.ignoredRegions??[]});if(e.diffRatio<=p.maxChangedPixelRatio)return await re(c(s,m),{force:!0}),{...f,status:`unchanged`,threshold:p,changedPixels:e.changedPixels,diffRatio:e.diffRatio};let[i,l]=await Promise.all([vl(`base`,n,a,s),vl(`head`,r,o,s)]),d=u?await _l({id:t,base:n,head:r,baseRepeat:u.base,headRepeat:u.head,baseRoot:a,headRoot:o,baseRepeatRoot:u.baseRoot,headRepeatRoot:u.headRoot,outputDir:s,threshold:p}):void 0;return{...f,status:d?`unstable`:`changed`,threshold:p,baseImage:i,headImage:l,diffImage:m,changedPixels:e.changedPixels,diffRatio:e.diffRatio,ignoredRegions:e.ignoredRegions,...d?{instability:d}:{}}}catch(e){return{...f,status:`error`,threshold:p,error:e instanceof Error?e.message:String(e)}}}async function _l(e){let t={};for(let n of[`base`,`head`]){let r=e[n],a=n===`base`?e.baseRepeat:e.headRepeat;if(!a)throw Error(`Kapture ${n} stability recapture is missing for ${e.id}`);if(a.error)throw Error(`Kapture ${n} stability recapture failed: ${a.error}`);if(r.sha256===a.sha256)continue;let o=n===`base`?e.baseRepeatRoot:e.headRepeatRoot,s=n===`base`?e.baseRoot:e.headRoot,l=`images/${n}-instability-diff/${i(r.imageFile)}`,u=await Yc(c(s,r.imageFile),c(o,a.imageFile),c(e.outputDir,l),e.threshold.pixelColorThreshold,{base:r.ignoredRegions??[],head:a.ignoredRegions??[]});if(u.diffRatio<=e.threshold.maxChangedPixelRatio){await re(c(e.outputDir,l),{force:!0});continue}t[n]={repeatImage:await vl(`${n}-repeat`,a,o,e.outputDir),diffImage:l,changedPixels:u.changedPixels,diffRatio:u.diffRatio}}return t.base||t.head?t:void 0}async function vl(e,t,n,r){let a=`images/${e}/${i(t.imageFile)}`;return await y(c(r,`images`,e),{recursive:!0}),await g(c(n,t.imageFile),c(r,a)),a}async function yl(e){let t=await S(f(e)),n=le(async(e,n)=>{try{let r=decodeURIComponent(new URL(e.url??`/`,`http://localhost`).pathname),i=f(t,`.${r}`);if(!bl(t,i)){n.writeHead(403).end(`Forbidden`);return}let a=await S(i);if(!bl(t,a)){n.writeHead(403).end(`Forbidden`);return}if((await C(a)).isDirectory()&&(a=await S(f(a,`index.html`)),!bl(t,a))){n.writeHead(403).end(`Forbidden`);return}let s=await x(a);n.writeHead(200,{"cache-control":`no-store`,"content-type":gd[o(a)]??`application/octet-stream`}),n.end(s)}catch{n.writeHead(404).end(`Not found`)}});await xl(n);let r=n.address();if(!r||typeof r==`string`)throw Error(`Static server has no TCP address`);return{url:`http://127.0.0.1:${r.port}/`,close:()=>Sl(n)}}function bl(e,t){return t===e||t.startsWith(`${e}${p}`)}function xl(e){return new Promise((t,n)=>{e.once(`error`,n),e.listen(0,`127.0.0.1`,()=>{e.off(`error`,n),t()})})}function Sl(e){return new Promise((t,n)=>{e.close(e=>e?n(e):t())})}async function Cl(e,t){await y(a(e),{recursive:!0}),await w(e,`${JSON.stringify(t,null,2)}\n`)}async function wl(e){return bd.parse(JSON.parse(await x(e,`utf8`)))}async function Tl(e,t){let n=T(`sha256`).update(`kapture-capture-cache\0${t}\0`);async function r(e,t){let i=await v(e);if(i.isSymbolicLink())throw Error(`Capture cache cannot fingerprint symlinks`);if(i.isDirectory())for(let n of(await te(e)).sort())await r(c(e,n),`${t}/${n}`);else if(i.isFile()){n.update(`${t}\0${i.size}\0`);for await(let t of de(e))n.update(t)}else throw Error(`Unsupported Storybook file type`)}return await r(e,``),n.digest(`hex`)}async function El(e,t){let n=xd.parse(JSON.parse(await x(c(e,`cache.json`),`utf8`)));if(n.buildDigest!==t)throw Error(`Capture cache build mismatch`);if(await pl(c(e,`manifest.json`))!==n.manifestDigest)throw Error(`Capture cache manifest digest mismatch`);let r=await wl(c(e,`manifest.json`));if(Object.values(r.snapshots).some(e=>e.error))throw Error(`Capture cache contains errors`);return r}async function Dl(e,t,n,r){if(!(!Object.keys(r.snapshots).length||Object.values(r.snapshots).some(e=>e.error))){await y(c(e,`images`),{recursive:!0});for(let n of Object.values(r.snapshots)){let r=c(t,n.imageFile);if(await pl(r)!==n.sha256)throw Error(`Capture cache image digest mismatch`);await g(r,c(e,n.imageFile))}await Cl(c(e,`manifest.json`),r),await w(c(e,`cache.json`),JSON.stringify({version:1,buildDigest:n,manifestDigest:await pl(c(e,`manifest.json`))}))}}function Ol(e){return Nd.parse(e)}async function kl(e){let t=c(e,Sd),n;try{n=await x(t)}catch(e){return Rl(e)?{evidence:{state:`missing`}}:{evidence:{state:`invalid`}}}try{let t=await Al(e,Ol(JSON.parse(n.toString(`utf8`))));return{manifest:t,evidence:{state:`valid`,digest:Nl(t)}}}catch{return{evidence:{state:`invalid`,digest:Il(n)}}}}async function Al(e,t){let n=!0;for(let[r,i]of Object.entries(t.outputInventory))try{let t=c(e,r),a=await v(t);if(!a.isFile()||a.isSymbolicLink()){n=!1;break}let o=await x(t);if(o.byteLength!==i.size||Il(o)!==i.sha256){n=!1;break}}catch{n=!1;break}if(n)for(let r of t.outputInventoryPrefixes){let i=await jl(e,r),a=Object.keys(t.outputInventory).filter(e=>e.startsWith(r)).sort();if(!i||!Ml(i,a)){n=!1;break}}return n?t:Nd.parse({...t,complete:!1,diagnostics:[...new Set([...t.diagnostics,`output-inventory-mismatch`])].sort()})}async function jl(e,t){let n=[],r=[t===``?``:t.slice(0,-1)];try{for(;r.length>0;){let t=r.pop(),i=await te(c(e,t),{withFileTypes:!0});for(let e of i){let i=t?`${t}/${e.name}`:e.name;if(e.isSymbolicLink())return null;if(e.isDirectory())r.push(i);else if(e.isFile())i!==`kapture-dependencies.json`&&n.push(i);else return null;if(n.length+r.length>1e5)return null}}}catch{return null}return n.sort()}function Ml(e,t){return e.length===t.length&&e.every((e,n)=>e===t[n])}function Nl(e){return Il(JSON.stringify(Ll(e)))}function Pl(e,t){return{base:e?{state:`valid`,digest:Nl(e)}:{state:`missing`},head:t?{state:`valid`,digest:Nl(t)}:{state:`missing`}}}function Fl(e){return e!==``&&!e.includes(`\\`)&&!e.includes(`\0`)&&!e.startsWith(`/`)&&!/^[A-Za-z]:\//.test(e)&&e!==`.`&&e!==`..`&&!e.startsWith(`./`)&&!e.startsWith(`../`)&&!e.split(`/`).some(e=>e===`.`||e===`..`)&&!e.includes(`//`)&&!e.endsWith(`/`)}function Il(e){return T(`sha256`).update(e).digest(`hex`)}function Ll(e){return Array.isArray(e)?e.map(Ll):!e||typeof e!=`object`?e:Object.fromEntries(Object.entries(e).sort(([e],[t])=>e.localeCompare(t)).map(([e,t])=>[e,Ll(t)]))}function Rl(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}async function zl({baseDir:e,headDir:t,changedFiles:n,changedFilesComplete:r=!0,changedFilesEvidence:i}){let[a,o,s,c]=await Promise.all([Vl(e),Vl(t),eu(e,`base`),eu(t,`head`)]);return Bl({baseIndex:a,headIndex:o,baseManifest:s.manifest,headManifest:c.manifest,changedFiles:n,changedFilesComplete:r,changedFilesEvidence:i,dependencyManifests:{base:s.evidence,head:c.evidence},initialFallbackReasons:[...s.reason?[s.reason]:[],...c.reason?[c.reason]:[]]})}function Bl(e){let t=Ql(e.changedFiles.map(Gl)),n=Hl(e.baseIndex),r=Hl(e.headIndex),i=Ql([...n.keys(),...r.keys()]),a=[...r.keys()].filter(e=>!n.has(e)).sort(),o=[...n.keys()].filter(e=>!r.has(e)).sort(),s=[...e.initialFallbackReasons??[],...e.changedFilesComplete===!1?[{code:`changed-files-incomplete`}]:[]],{baseManifest:c,headManifest:l}=e,u=e.dependencyManifests??Pl(c,l),d=new Set,f=new Set;!c&&!s.some(e=>e.code.startsWith(`base-manifest`))&&s.push({code:`base-manifest-missing`,side:`base`}),!l&&!s.some(e=>e.code.startsWith(`head-manifest`))&&s.push({code:`head-manifest-missing`,side:`head`}),c&&!c.complete&&s.push({code:`manifest-incomplete`,side:`base`}),l&&!l.complete&&s.push({code:`manifest-incomplete`,side:`head`});let p=new Map;if(c&&l){c.globalRuntimeFingerprint!==l.globalRuntimeFingerprint&&s.push({code:`global-runtime`});for(let e of new Set([...Object.keys(c.globalOutputFingerprints),...Object.keys(l.globalOutputFingerprints)]))(c.globalOutputFingerprints[e]!==l.globalOutputFingerprints[e]||!Zl(new Set(c.globalOutputStories[e]??[]),new Set(l.globalOutputStories[e]??[])))&&f.add(e);for(let e of new Set([...Object.keys(c.renderedOutputFingerprints),...Object.keys(l.renderedOutputFingerprints)]))c.renderedOutputFingerprints[e]!==l.renderedOutputFingerprints[e]&&d.add(e);if(c.moduleFingerprints&&l.moduleFingerprints)for(let e of new Set([...Object.keys(c.moduleFingerprints),...Object.keys(l.moduleFingerprints)]))c.moduleFingerprints[e]!==l.moduleFingerprints[e]&&d.add(e);for(let e of i){let t=n.get(e),i=r.get(e),a=t?Ul(t,c,`base`,s):void 0,o=i?Ul(i,l,`head`,s):void 0;p.set(e,{base:a,head:o})}let e=new Set,a=new Set;for(let t of[c,l])for(let[n,r]of Object.entries(t.modules)){e.add(n);for(let t of r)e.add(t)}for(let e of p.values()){if(e.base)for(let t of Jl(c,e.base))a.add(t);if(e.head)for(let t of Jl(l,e.head))a.add(t)}for(let e of f){let t=Yl(c,l,e);if(!t||[...t].some(e=>!a.has(e))){s.push({code:`global-output`,path:e});continue}for(let e of t)d.add(e)}for(let e of d)(Kl(e,c.globalInputs)||Kl(e,l.globalInputs))&&s.push({code:`global-input`,path:e});for(let n of t){if(Kl(n,c.globalInputs)||Kl(n,l.globalInputs)){s.push({code:`global-input`,path:n});continue}let t=Kl(n,c.ignoredInputs)&&Kl(n,l.ignoredInputs),r=ql(c)&&ql(l)&&Kl(n,c.fingerprintedInputs??[])&&Kl(n,l.fingerprintedInputs??[]);!t&&!r&&(!e.has(n)||!a.has(n))&&s.push({code:`unknown-input`,path:n})}}let m=$l(s);if(m.length>0||!c||!l)return{version:1,selectionMode:`full-fallback`,changedFiles:t,...e.changedFilesEvidence?{changedFilesEvidence:{...e.changedFilesEvidence}}:{},dependencyManifests:ru(u),totalStoryIds:i,selectedStoryIds:i,skippedStoryIds:[],addedStoryIds:a,removedStoryIds:o,fallbackReasons:m};let h=new Set([...a,...o]);for(let e of i){let n=p.get(e);if(!n)continue;if(n.base!==n.head){h.add(e);continue}let r=n.base?Jl(c,n.base):new Set,i=n.head?Jl(l,n.head):new Set;if(!Zl(r,i)){h.add(e);continue}let a=new Set([...r,...i]);(t.some(e=>a.has(e))||[...a].some(e=>d.has(e)))&&h.add(e)}let g=[...h].sort();return{version:1,selectionMode:`affected`,changedFiles:t,...e.changedFilesEvidence?{changedFilesEvidence:{...e.changedFilesEvidence}}:{},dependencyManifests:ru(u),totalStoryIds:i,selectedStoryIds:g,skippedStoryIds:i.filter(e=>!h.has(e)),addedStoryIds:a,removedStoryIds:o,fallbackReasons:[]}}async function Vl(e){return Id.parse(JSON.parse(await x(c(e,`index.json`),`utf8`)))}function Hl(e){return new Map(Object.values(e.entries).filter(e=>e.type===`story`).sort((e,t)=>e.id.localeCompare(t.id)).map(e=>[e.id,e]))}function Ul(e,t,n,r){if(!e.importPath){r.push({code:`story-import-missing`,storyId:e.id,side:n});return}let i;try{i=Wl(t.storybookRoot,e.importPath)}catch{r.push({code:`story-import-missing`,storyId:e.id,side:n});return}if(!t.modules[i]){r.push({code:`story-module-missing`,storyId:e.id,side:n});return}if(t.renderedModules&&!t.renderedModules[i]?.includes(i)){r.push({code:`story-module-missing`,storyId:e.id,side:n});return}return i}function Wl(e,t){let n=t.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(s(n)||/^[A-Za-z]:\//.test(n))throw Error(`Story importPath must be relative`);let r=u.normalize(u.join(e,n));if(r===`..`||r.startsWith(`../`)||r===`.`)throw Error(`Story importPath must stay within project root`);return r}function Gl(e){let t=e.replaceAll(`\\`,`/`).replace(/^\.\//,``);if(t.length===0||t.includes(`\0`)||s(t)||/^[A-Za-z]:\//.test(t)||t===`..`||t.startsWith(`../`)||t.split(`/`).some(e=>e===`.`||e===`..`)||t.includes(`//`)||t.endsWith(`/`))throw Error(`Changed file must be a normalized project-relative path: ${e}`);return t}function Kl(e,t){return t.some(t=>e===t||l(e,t))}function ql(e){return!e.complete||!e.moduleFingerprints?!1:Object.keys(e.modules).every(t=>e.moduleFingerprints?.[t]!==void 0)}function Jl(e,t){let n=Xl(e,t),r=e.renderedModules?.[t];return r?new Set(r):n}function Yl(e,t,n){let r=e.globalOutputFingerprints[n]!==void 0,i=t.globalOutputFingerprints[n]!==void 0;if(r&&i&&e.globalOutputFingerprints[n]!==t.globalOutputFingerprints[n])return null;let a=new Set(e.globalOutputStories[n]??[]),o=new Set(t.globalOutputStories[n]??[]);if(r&&a.size===0||i&&o.size===0)return null;let s=new Set([...a,...o]);return s.size>0?s:null}function Xl(e,t){let n=new Set,r=[t];for(;r.length>0;){let t=r.pop();if(!(!t||n.has(t))){n.add(t);for(let i of e.modules[t]??[])n.has(i)||r.push(i)}}return n}function Zl(e,t){return e.size===t.size&&[...e].every(e=>t.has(e))}function Ql(e){return[...new Set(e)].sort()}function $l(e){let t=new Map;for(let n of e)t.set(nu(n),n);let n=[...t.values()].sort(tu);return n.length<=1e3?n:[...n.filter(e=>e.code!==`fallback-reasons-truncated`).slice(0,999),{code:`fallback-reasons-truncated`}].sort(tu)}async function eu(e,t){let n=await kl(e);if(n.manifest)return n;let r=`${t}-manifest-${n.evidence.state}`;return{evidence:n.evidence,reason:{code:r,side:t}}}function tu(e,t){return nu(e).localeCompare(nu(t))}function nu(e){return`${e.code}:${e.side??``}:${e.path??``}:${e.storyId??``}`}function ru(e){return{base:{...e.base},head:{...e.head}}}async function iu(e){let t=await fetch(new URL(`index.json`,su(e)));if(!t.ok)throw Error(`Failed to read Storybook index (${t.status}) from ${e}`);return Rd.parse(await t.json())}function au(e){return Object.values(e.entries).filter(e=>e.type===`story`).sort((e,t)=>e.id.localeCompare(t.id))}function ou(e,t){let n=new URL(`iframe.html`,su(e));return n.searchParams.set(`id`,t),n.searchParams.set(`viewMode`,`story`),n.toString()}function su(e){return e.endsWith(`/`)?e:`${e}/`}function cu(e){let t=vu(e,`bridge`);if(t.protocolVersion!==4)throw Error(`Unsupported Kapture Storybook protocol ${String(t.protocolVersion)}; expected 4`);let n=bu(t.adapterVersion,`adapterVersion`),r=t.state;if(r===`booting`)return{protocolVersion:4,adapterVersion:n,state:r};if(![`rendering`,`ready`,`error`].includes(r))throw Error(`Invalid Kapture Storybook bridge state: ${String(r)}`);let i=bu(t.storyId,`storyId`),a=Du(t.generation,`generation`),o=Cu(t.renderId,`renderId`);if(r===`rendering`)return{protocolVersion:4,adapterVersion:n,state:r,storyId:i,generation:a,renderId:o,parameters:t.parameters===void 0?void 0:lu(t.parameters)};if(r===`ready`){if(o===void 0)throw Error(`Kapture ready bridge requires renderId`);return{protocolVersion:4,adapterVersion:n,state:r,storyId:i,generation:a,renderId:o,parameters:lu(t.parameters)}}let s=vu(t.error,`error`);if(s.kind!==`configuration`&&s.kind!==`storybook`)throw Error(`Invalid Kapture bridge error kind: ${String(s.kind)}`);return{protocolVersion:4,adapterVersion:n,state:`error`,storyId:i,generation:a,renderId:o,error:{kind:s.kind,message:bu(s.message,`error.message`)}}}function lu(e){let t=vu(e,`parameters`);return Au({captureEnabled:Su(t.captureEnabled,`captureEnabled`),captureViewports:uu(t.captureViewports),captureArea:du(t.captureArea),captureDelayMs:Tu(t.captureDelayMs,`captureDelayMs`),waitForElement:pu(t.waitForElement),animationState:mu(t.animationState),maskSelectors:_u(t.maskSelectors,`maskSelectors`),diffIgnoreSelectors:_u(t.diffIgnoreSelectors,`diffIgnoreSelectors`),waitForFonts:Su(t.waitForFonts,`waitForFonts`),fontAssertions:t.fontAssertions===void 0?void 0:yu(t.fontAssertions,`fontAssertions`).map((e,t)=>hu(e,`fontAssertions[${t}]`)),diff:gu(t.diff)})}function uu(e){if(e===void 0)return;let t=yu(e,`captureViewports`);if(t.length===0)throw Error(`Kapture captureViewports must contain at least one viewport; use captureEnabled: false to skip`);return t.map((e,t)=>fu(e,`captureViewports[${t}]`))}function du(e){if(e===void 0||e===`full-page`||e===`viewport`)return e;throw Error(`Invalid Kapture captureArea: ${String(e)}`)}function fu(e,t){let n=vu(e,t);return{name:bu(n.name,`${t}.name`),width:Eu(n.width,`${t}.width`),height:Eu(n.height,`${t}.height`)}}function pu(e){if(e===void 0)return;let t=vu(e,`waitForElement`),n=t.state;if(n!==void 0&&n!==`attached`&&n!==`visible`&&n!==`hidden`&&n!==`detached`)throw Error(`Invalid Kapture waitForElement state: ${String(n)}`);return Au({selector:bu(t.selector,`waitForElement.selector`),state:n,timeoutMs:Tu(t.timeoutMs,`waitForElement.timeoutMs`)})}function mu(e){if(e!==void 0)return e===`disabled`||e===`start`||e===`end`?e:{atMs:wu(vu(e,`animationState`).atMs,`animationState.atMs`)}}function hu(e,t){let n=vu(e,t),r=n.weight;if(r!==void 0&&typeof r!=`string`&&typeof r!=`number`)throw Error(`${t}.weight must be a string or number`);return Au({family:bu(n.family,`${t}.family`),glyphs:bu(n.glyphs,`${t}.glyphs`),style:xu(n.style,`${t}.style`),weight:r})}function gu(e){if(e===void 0)return;let t=vu(e,`diff`);if(`maxChangedPixelRatio`in t)throw Error(`Kapture diff.maxChangedPixelRatio is not supported; use diff.maxChangedPixelPercentage with a value between 0 and 100`);return Au({pixelColorThreshold:Ou(t.pixelColorThreshold,`diff.pixelColorThreshold`),maxChangedPixelPercentage:ku(t.maxChangedPixelPercentage,`diff.maxChangedPixelPercentage`)})}function _u(e,t){if(e!==void 0)return yu(e,t).map((e,n)=>bu(e,`${t}[${n}]`))}function vu(e,t){if(typeof e!=`object`||!e||Array.isArray(e))throw Error(`Kapture ${t} must be an object`);return e}function yu(e,t){if(!Array.isArray(e))throw Error(`Kapture ${t} must be an array`);return e}function bu(e,t){if(typeof e!=`string`||!e.trim())throw Error(`Kapture ${t} must be a non-empty string`);return e}function xu(e,t){return e===void 0?void 0:bu(e,t)}function Su(e,t){if(e!==void 0){if(typeof e!=`boolean`)throw Error(`Kapture ${t} must be a boolean`);return e}}function Cu(e,t){if(e!==void 0){if(typeof e!=`number`||!Number.isFinite(e))throw Error(`Kapture ${t} must be a finite number`);return e}}function wu(e,t){let n=Cu(e,t);if(n===void 0||n<0)throw Error(`Kapture ${t} must be a non-negative number`);return n}function Tu(e,t){return e===void 0?void 0:wu(e,t)}function Eu(e,t){let n=Cu(e,t);if(n===void 0||n<=0)throw Error(`Kapture ${t} must be positive`);return n}function Du(e,t){let n=wu(e,t);if(!Number.isInteger(n))throw Error(`Kapture ${t} must be an integer`);return n}function Ou(e,t){if(e===void 0)return;let n=wu(e,t);if(n>1)throw Error(`Kapture ${t} must be between 0 and 1`);return n}function ku(e,t){if(e===void 0)return;let n=wu(e,t);if(n>100)throw Error(`Kapture ${t} must be between 0 and 100`);return n}function Au(e){return Object.fromEntries(Object.entries(e).filter(([,e])=>e!==void 0))}async function ju(e,t,n){let r=JSON.stringify(t),i=await e.evaluate(`(async () => {
571
571
  const expectedStoryId = ${r};
572
572
  const deadline = performance.now() + 10000;
573
573
  let sawAdapter = false;
@@ -595,80 +595,83 @@ Set the \`cycles\` parameter to \`"ref"\` to resolve cyclical schemas with defs.
595
595
  }
596
596
  await new Promise(resolve => setTimeout(resolve, 20));
597
597
  }
598
- })()`);if(i.kind===`timeout`)throw i.sawAdapter?Error(`Kapture Storybook adapter did not become ready for ${t} (last state: ${i.lastState??`unknown`}).`):Error(`Kapture Storybook adapter was not found for ${t}. Install @kaptures/storybook and register kapture() in .storybook/preview.`);let a;try{a=au(i.value)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`${t}. Install matching versions of @kaptures/cli and @kaptures/storybook.`,{cause:e})}if(a.state===`error`){let e=a.error.kind===`configuration`?`configuration`:`lifecycle`;throw Error(`Kapture Storybook ${e} error for ${t}: ${a.error.message}`)}if(a.state!==`ready`||a.storyId!==t)throw Error(`Kapture Storybook returned invalid terminal state for ${t}`);if(a.adapterVersion!==n)throw Error(`Kapture adapter version mismatch for ${t}: CLI ${n}, Storybook ${a.adapterVersion}. Install matching exact versions of @kaptures/cli and @kaptures/storybook.`);return{adapterVersion:a.adapterVersion,generation:a.generation,parameters:a.parameters}}function ku(e,t){return e.adapterVersion===t.adapterVersion&&e.generation===t.generation}async function Au(e,t=Id){let n=e.workers??4;if(!Number.isInteger(n)||n<1||n>8)throw Error(`Kapture workers must be between 1 and 8`);let r=f(e.outputDir);await y(r),await y(c(r,`images`));let i=await gl(e.headDir);try{let a=nu(await tu(i.url));if(!a.length)throw Error(`Initial adoption requires at least one story`);let[o,s]=await Promise.all([t.getBrowserVersion(),t.getFontsFingerprint()]),l=Xc({browserVersion:o,fontsFingerprint:s,frozenTime:e.frozenTime,randomSeed:e.randomSeed,locale:e.locale,timezone:e.timezone}),u=c(r,`hermetic-init.js`);await w(u,nl(l));let d=Nu(e.headRevision,l);if(await Mu({pairs:a.map(e=>({id:e.id,head:e})),requestedWorkers:n,namespace:`i-${process.pid.toString(36)}-${Date.now().toString(36)}`,initScriptPath:u,options:{...e,baseDir:e.headDir,baseRevision:e.headRevision},baseUrl:``,headUrl:i.url,baseOutput:r,headOutput:r,baseManifest:Nu(e.headRevision,l),headManifest:d,environment:l,captureBase:!1}),await bl(c(r,`manifest.json`),d),!Object.keys(d.snapshots).length)throw Error(`Initial adoption requires at least one enabled snapshot`);return d}finally{await i.close()}}async function ju(e,t=Id){let n=f(e.outputDir),r=c(n,`capture`,`base`),i=c(n,`capture`,`head`),a=c(n,`report`);await re(n,{recursive:!0,force:!0}),await Promise.all([y(c(r,`images`),{recursive:!0}),y(c(i,`images`),{recursive:!0}),y(a,{recursive:!0})]);let o=[];try{let s=await gl(e.baseDir);o.push(s);let l=await gl(e.headDir);o.push(l);let[u,d,f,p]=await Promise.all([tu(s.url),tu(l.url),El(e.baseDir),El(e.headDir)]),m=nu(u),h=nu(d),g=Iu(m,h,e,{base:f.evidence,head:p.evidence}),_=Fu(m,h,g.selectedStoryIds),[v,ee]=_.length===0&&!e.baseCaptureDir?[`not-launched:no-affected-stories-v1`,`not-inspected:no-affected-stories-v1`]:await Promise.all([t.getBrowserVersion(),t.getFontsFingerprint()]),b=Xc({browserVersion:v,fontsFingerprint:ee,frozenTime:e.frozenTime,randomSeed:e.randomSeed,locale:e.locale,timezone:e.timezone}),x=c(n,`hermetic-init.js`);await w(x,nl(b));let te=`k-${process.pid.toString(36)}-${Date.now().toString(36)}`,S=e.baseCaptureDir?await Gu(e.baseCaptureDir,r,e.baseRevision,b,_):void 0;if(!S&&e.captureCacheDir&&_.length>0)try{let t=await Sl(e.baseDir,e.adapterVersion),n=await Cl(e.captureCacheDir,t),i=await Gu(e.captureCacheDir,r,n.revision,b,_,!0);for(let e of Object.values(i.manifest.snapshots))e.sourceRevision??=n.revision;i.manifest.revision=e.baseRevision,S=i}catch(e){console.warn(`Kapture capture cache miss: ${e instanceof Error?e.message:String(e)}`)}S&&(g.baseline={mode:`reused`,revision:S.manifest.revision,manifestDigest:S.manifestDigest});let ne=S?.manifest??Nu(e.baseRevision,b),C=Nu(e.headRevision,b),T=e.workers??4;if(!Number.isInteger(T)||T<1||T>8)throw Error(`Kapture workers must be between 1 and 8`);await Mu({pairs:_,requestedWorkers:T,namespace:te,initScriptPath:x,options:e,baseUrl:s.url,headUrl:l.url,baseOutput:r,headOutput:i,baseManifest:ne,headManifest:C,environment:b,captureBase:!S||!!e.captureCacheDir,cachedBaseStoryIds:S?new Set(Object.values(S.manifest.snapshots).map(e=>e.storyId)):void 0}),S&&await Ku({baseline:S.manifest,baselineRoot:S.root,headManifest:C,headOutput:i,selectedStoryIds:g.selectedStoryIds,removedStoryIds:g.removedStoryIds??[]}),await Promise.all([bl(c(r,`manifest.json`),ne),bl(c(i,`manifest.json`),C)]);let ie={...ud,...e.threshold},ae=c(n,`stability-candidates`),oe=await fl({baseManifest:ne,headManifest:C,baseRoot:r,headRoot:i,outputDir:ae,threshold:ie,coverage:g}),se=new Set(Object.values(oe.entries).filter(e=>e.status===`changed`).map(e=>e.id)),ce;if(se.size>0){let t=new Set(Object.values(oe.entries).filter(e=>se.has(e.id)).map(e=>e.storyId)),r=_.filter(e=>t.has(e.id)),i=c(n,`capture`,`base-repeat`),a=c(n,`capture`,`head-repeat`);await Promise.all([y(c(i,`images`),{recursive:!0}),y(c(a,`images`),{recursive:!0})]);let o=Nu(e.baseRevision,b),u=Nu(e.headRevision,b);await Mu({pairs:r,requestedWorkers:T,namespace:`${te}-s`,initScriptPath:x,options:e,baseUrl:s.url,headUrl:l.url,baseOutput:i,headOutput:a,baseManifest:o,headManifest:u,environment:b,captureBase:!0}),await Promise.all([bl(c(i,`manifest.json`),o),bl(c(a,`manifest.json`),u)]),ce={baseManifest:o,headManifest:u,baseRoot:i,headRoot:a}}await re(ae,{recursive:!0,force:!0});let le=await fl({baseManifest:ne,headManifest:C,baseRoot:r,headRoot:i,outputDir:a,threshold:ie,coverage:g,stability:ce});if(e.captureCacheOutput&&le.summary.errors===0&&le.summary.unstable===0)try{let t=await Sl(e.headDir,e.adapterVersion);await wl(e.captureCacheOutput,i,t,C)}catch(e){console.warn(`Kapture capture cache export unavailable: ${e instanceof Error?e.message:String(e)}`)}return{baseManifest:ne,headManifest:C,report:le}}finally{await Promise.allSettled(o.map(e=>e.close()))}}async function Mu(e){let t=Math.min(e.requestedWorkers,e.pairs.length),n=e.captureBase&&e.pairs.some(t=>!!t.base&&!e.cachedBaseStoryIds?.has(t.id)),r=e.pairs.some(e=>!!e.head),i=[...e.pairs],a=[],o=[];try{for(let i=0;i<t;i+=1){let t={};n&&(t.base=Pu(i,`base`,e.options,{namespace:e.namespace,initScriptPath:e.initScriptPath,environment:e.environment}),o.push(t.base)),r&&(t.head=Pu(i,`head`,e.options,{namespace:e.namespace,initScriptPath:e.initScriptPath,environment:e.environment}),o.push(t.head)),a.push(t)}await Promise.all(a.map(async t=>{for(;i.length>0;){let n=i.shift();if(!n)return;await Vu({workers:t,pair:n,baseUrl:e.baseUrl,headUrl:e.headUrl,baseOutput:e.baseOutput,headOutput:e.headOutput,baseManifest:e.baseManifest,headManifest:e.headManifest,environment:e.environment,adapterVersion:e.options.adapterVersion,captureBase:e.captureBase&&!e.cachedBaseStoryIds?.has(n.id)})}}))}finally{await Promise.allSettled(o.map(e=>Promise.resolve().then(()=>e.close())))}}function Nu(e,t){return{version:2,revision:e,environment:t,createdAt:new Date().toISOString(),snapshots:{}}}function Pu(e,t,n,r){let i={...r,target:t};return n.workerFactory?n.workerFactory(e,i):new sd({id:`${r.namespace}-${t}-${e}`,namespace:r.namespace,initScriptPath:r.initScriptPath,timezone:r.environment.timezone,locale:r.environment.locale,deviceScaleFactor:r.environment.deviceScaleFactor,allowedDomains:r.environment.network.allowedDomains})}function Fu(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=new Map(t.map(e=>[e.id,e])),a=[...new Set([...r.keys(),...i.keys()])].sort(),o=n?[...new Set(n)].sort():a,s=new Set(a),c=o.filter(e=>!s.has(e));if(c.length>0)throw Error(`Unknown Kapture story IDs: ${c.join(`, `)}`);return o.map(e=>({id:e,base:r.get(e),head:i.get(e)}))}function Iu(e,t,n,r){if(n.selectionPlan&&n.storyIds)throw Error(`Kapture selectionPlan and storyIds cannot be provided together`);let i=[...new Set([...e,...t].map(e=>e.id))].sort(),a=new Set(e.map(e=>e.id)),o=new Set(t.map(e=>e.id)),s=i.filter(e=>!a.has(e)&&o.has(e)),c=i.filter(e=>a.has(e)&&!o.has(e)),l=Lu(r,n.baseRevision,n.headRevision),u=n.selectionPlan;if(u){if(Bu(u.totalStoryIds,i,`selection plan catalog`),Bu(u.addedStoryIds,s,`selection plan added stories`),Bu(u.removedStoryIds,c,`selection plan removed stories`),Ru(u.dependencyManifests,r),zu(u.selectedStoryIds,u.skippedStoryIds,i),u.selectionMode===`full-fallback`&&u.fallbackReasons.length===0)throw Error(`Kapture full-fallback selection plan requires a fallback reason`);if(u.selectionMode===`affected`&&u.fallbackReasons.length>0)throw Error(`Kapture affected selection plan cannot contain fallback reasons`);return{plannerVersion:1,mode:u.selectionMode,...u.changedFilesEvidence?{changedFilesEvidence:{...u.changedFilesEvidence}}:{},dependencyManifests:l,storyIds:i,selectedStoryIds:[...u.selectedStoryIds],skippedStoryIds:[...u.skippedStoryIds],addedStoryIds:s,removedStoryIds:c,fallbackReasons:u.fallbackReasons.map(e=>({...e}))}}if(n.storyIds){let e=[...new Set(n.storyIds)].sort(),t=new Set(i),r=e.filter(e=>!t.has(e));if(r.length>0)throw Error(`Unknown Kapture story IDs: ${r.join(`, `)}`);let a=new Set(e);return{plannerVersion:1,mode:`affected`,dependencyManifests:l,storyIds:i,selectedStoryIds:e,skippedStoryIds:i.filter(e=>!a.has(e)),addedStoryIds:s,removedStoryIds:c,fallbackReasons:[]}}return{plannerVersion:1,mode:`full`,dependencyManifests:l,storyIds:i,selectedStoryIds:i,skippedStoryIds:[],addedStoryIds:s,removedStoryIds:c,fallbackReasons:[]}}function Lu(e,t,n){return{base:{...e.base,revision:t},head:{...e.head,revision:n}}}function Ru(e,t){if(JSON.stringify(e)!==JSON.stringify(t))throw Error(`Kapture selection plan dependency manifests do not match the built Storybook artifacts`)}function zu(e,t,n){Bu(e,[...new Set(e)].sort(),`selected stories`),Bu(t,[...new Set(t)].sort(),`skipped stories`);let r=new Set(e),i=[...e,...t].sort();if(t.some(e=>r.has(e)))throw Error(`Kapture selection plan cannot select and skip the same story`);Bu(i,n,`selection plan partition`)}function Bu(e,t,n){if(e.length!==t.length||e.some((e,n)=>e!==t[n]))throw Error(`Kapture ${n} does not match the built Storybook catalog`)}async function Vu(e){let t={base:Hu(!!e.pair.base&&e.captureBase),head:Hu(!!e.pair.head)},n=[];e.pair.base&&e.captureBase&&n.push(Uu(e,`base`,t)),e.pair.head&&n.push(Uu(e,`head`,t)),await Promise.all(n)}function Hu(e){if(!e)return{promise:Promise.resolve(void 0),resolve:()=>void 0};let t=()=>void 0,n=!1;return{promise:new Promise(e=>{t=e}),resolve(e){n||(n=!0,t(e))}}}async function Uu(e,t,n){let r=e.pair[t];if(!r)return;let i=e.workers[t];if(!i)throw Error(`Kapture ${t} browser worker was not initialized`);let a=t===`base`?e.baseManifest:e.headManifest,o=t===`base`?e.baseUrl:e.headUrl,s=t===`base`?e.baseOutput:e.headOutput,c=t===`base`?`head`:`base`;try{await i.runAttempt({target:t,storyId:r.id},async i=>{let l=await qu(i,o,r,e.environment,e.adapterVersion).catch(ed);if(n[t].resolve(l),l instanceof Error){Qu(a,r,l);return}let u=await n[c].promise;if(u instanceof Error)return;let d=t===`base`?l.parameters:u?.parameters,f=t===`head`?l.parameters:u?.parameters,p=e.captureBase?Ju(d,f,!!e.pair.base,!!e.pair.head):Wu(e.baseManifest,e.pair.id,f,!!e.pair.head);for(let n of p){let c=n[t];!c||l.parameters.captureEnabled===!1||await Yu({driver:i,story:r,baseUrl:o,outputRoot:s,manifest:a,viewport:c,parameters:l.parameters,captureArea:l.parameters.captureArea,threshold:Xu(l.parameters.diff),adapterVersion:e.adapterVersion})}})}catch(e){let i=ed(e);n[t].resolve(i),$u(a,r,i)}}function Wu(e,t,n,r=!0){let i=Object.values(e.snapshots).filter(e=>e.storyId===t).map(e=>e.viewport),a=!r||n?.captureEnabled===!1?[]:n?.captureViewports??[ld],o=new Map(i.map(e=>[e.name,e])),s=new Map(a.map(e=>[e.name,e]));return[...new Set([...o.keys(),...s.keys()])].sort().map(e=>({base:o.get(e),head:s.get(e)}))}async function Gu(e,t,n,r,i,a=!1){let o=f(e),s=c(o,`manifest.json`),l=await xl(s);if(l.revision!==n)throw Error(`Kapture baseline revision ${l.revision} does not match requested base ${n}`);$c(l.environment,r);let u=new Set(i.filter(e=>e.base).map(e=>e.id)),d={...l.snapshots};for(let e of u)if(!a&&!Object.values(d).some(t=>t.storyId===e))throw Error(`Kapture baseline does not contain selected base story ${e}`);return await Promise.all(Object.values(d).map(async e=>{if(e.error)return;let n=c(o,e.imageFile);if(await ul(n)!==e.sha256)throw Error(`Kapture baseline image digest mismatch for ${e.id}`);await g(n,c(t,e.imageFile))})),{root:t,manifest:{...l,snapshots:d},manifestDigest:await ul(s)}}async function Ku(e){let t=new Set(e.selectedStoryIds),n=new Set(e.removedStoryIds);await Promise.all(Object.values(e.baseline.snapshots).map(async r=>{t.has(r.storyId)||n.has(r.storyId)||(e.headManifest.snapshots[r.id]={...r,sourceRevision:r.sourceRevision??e.baseline.revision},!r.error&&await g(c(e.baselineRoot,r.imageFile),c(e.headOutput,r.imageFile)))}))}async function qu(e,t,n,r,i){return await e.setViewport(ld),await e.setMedia(r.colorScheme,r.reducedMotion===`reduce`),await e.open(ru(t,n.id)),Ou(e,n.id,i)}function Ju(e,t,n=!0,r=!0){let i=!n||e?.captureEnabled===!1?[]:e?.captureViewports??[ld],a=!r||t?.captureEnabled===!1?[]:t?.captureViewports??[ld],o=new Map(i.map(e=>[e.name,e])),s=new Map(a.map(e=>[e.name,e]));return[...new Set([...o.keys(),...s.keys()])].sort().map(e=>({base:o.get(e),head:s.get(e)}))}async function Yu(e){let{driver:t,story:n,baseUrl:r,outputRoot:i,manifest:a,viewport:o,parameters:s,captureArea:l,threshold:u,adapterVersion:f}=e,p=`${n.id}@${o.name}`,m=c(`images`,dl(p)),h=c(i,m),g=performance.now();try{await t.setViewport(o),await t.setMedia(a.environment.colorScheme,a.environment.reducedMotion===`reduce`),await t.open(ru(r,n.id));let e=await Ou(t,n.id,f);Zu(e,s,n.id);let c;for(let r=1;r<=3;r+=1){c=await Gc(t,a.environment,e.parameters);let i=await Ou(t,n.id,f);if(Zu(i,s,n.id),ku(e,i))break;if(r===3)throw Error(`Kapture story ${n.id} kept rerendering while the capture was stabilizing`);e=i,c=void 0}if(!c)throw Error(`Kapture could not stabilize ${n.id}`);await t.screenshot(h,{fullPage:l!==`viewport`}),a.snapshots[p]={id:p,storyId:n.id,title:n.title,name:n.name,viewport:o,imageFile:d(i,h),sha256:await ul(h),capturedAt:new Date().toISOString(),durationMs:Math.round(performance.now()-g),ignoredRegions:c.ignoredRegions.length>0?c.ignoredRegions:void 0,threshold:u}}catch(e){a.snapshots[p]={id:p,storyId:n.id,title:n.title,name:n.name,viewport:o,imageFile:m,sha256:``,capturedAt:new Date().toISOString(),durationMs:Math.round(performance.now()-g),threshold:u,error:e instanceof Error?e.message:String(e)}}}function Xu(e){if(e)return{...e.pixelColorThreshold===void 0?{}:{pixelColorThreshold:e.pixelColorThreshold},...e.maxChangedPixelPercentage===void 0?{}:{maxChangedPixelRatio:e.maxChangedPixelPercentage/100}}}function Zu(e,t,n){if(JSON.stringify(e.parameters)!==JSON.stringify(t))throw Error(`Kapture parameters changed between metadata and capture for ${n}`)}function Qu(e,t,n){let r=`${t.id}@metadata`;e.snapshots[r]={id:r,storyId:t.id,title:t.title,name:t.name,viewport:ld,imageFile:``,sha256:``,capturedAt:new Date().toISOString(),durationMs:0,error:n.message}}function $u(e,t,n){let r=`${t.id}@attempt`;e.snapshots[r]={id:r,storyId:t.id,title:t.title,name:t.name,viewport:ld,imageFile:``,sha256:``,capturedAt:new Date().toISOString(),durationMs:0,error:n.message}}function ed(e){return e instanceof Error?e:Error(String(e))}async function td(e,t){if(!(await C(e)).isDirectory())throw Error(`Dashboard build is not a directory: ${e}`);await _(e,t,{recursive:!0,force:!0});let n=f(t,`index.html`),r=f(t,`report.json`),[i,a]=await Promise.all([x(n,`utf8`),x(r,`utf8`)]),o=nd(i,/<link\b[^>]*\brel=["']stylesheet["'][^>]*\bhref=["']([^"']+)["'][^>]*>/i,`stylesheet`),s=nd(i,/<script\b[^>]*\bsrc=["']([^"']+)["'][^>]*><\/script>/i,`module script`),[c,l]=await Promise.all([rd(t,o.url),rd(t,s.url)]),u=id(c,o.url),d=`<script id="kapture-report-data" type="application/json">${a.trim().replaceAll(`<`,`\\u003c`)}<\/script>\n<script data-kapture-dashboard>"use strict";\n${l.replace(/<\/script/gi,`<\\/script`)}<\/script>`,p=i.replace(o.tag,()=>`<style>${u}</style>`).replace(s.tag,``);if(!p.includes(`</body>`))throw Error(`Dashboard index is missing its closing body tag`);let m=p.replace(`</body>`,()=>`${d}\n</body>`);await w(n,m)}function nd(e,t,n){let r=e.match(t);if(!r?.[1])throw Error(`Dashboard index is missing its ${n}`);return{tag:r[0],url:r[1]}}async function rd(e,t){if(/^[a-z]+:/i.test(t)||t.startsWith(`/`)||t.includes(`?`))throw Error(`Dashboard asset must be a relative local path: ${t}`);let n=f(e),r=f(n,t);if(!r.startsWith(`${n}${p}`))throw Error(`Dashboard asset resolves outside the report directory: ${t}`);return x(r,`utf8`)}function id(e,t){let n=u.dirname(t);return e.replace(/url\((["']?)(\.\/[^"')]+)\1\)/g,(e,t,r)=>{let i=u.join(n,r);return`url(${t}${i.startsWith(`.`)?i:`./${i}`}${t})`})}var ad,od,sd,cd,ld,ud,dd,fd,pd,md,hd,gd,_d,vd,yd,bd,xd,Sd,Cd,wd,Td,Ed,Dd,Od,kd,Ad,jd,Md,Nd,Pd,Fd,Id,Ld=E((()=>{St(),ad=Wt(),Bc(),od=class{session;isolation=`browser-process`;namespace;initScriptPath;timezone;locale;deviceScaleFactor;allowedDomains;timeoutMs;bin;commandStarted=!1;closePromise;constructor(e){this.session=e.session,this.namespace=e.namespace,this.initScriptPath=e.initScriptPath,this.timezone=e.timezone,this.locale=e.locale,this.deviceScaleFactor=e.deviceScaleFactor,this.allowedDomains=e.allowedDomains,this.timeoutMs=e.timeoutMs??3e4,this.bin=Wc()}open(e){return this.execVoid([`open`,e])}setViewport(e){return this.execVoid([`set`,`viewport`,String(e.width),String(e.height)])}setMedia(e,t){let n=[`set`,`media`,e];return t&&n.push(`reduced-motion`),this.execVoid(n)}async evaluate(e){let t=await this.exec([`eval`,e]),n=JSON.parse(t);if(n.success===!1)throw Error(n.error??`agent-browser eval failed`);return n.data&&typeof n.data==`object`&&`result`in n.data?n.data.result:n.data===void 0?n.result===void 0?n:n.result:n.data}screenshot(e,t){return this.execVoid([`screenshot`,...t.fullPage?[`--full`]:[],e])}close(){return this.closePromise?this.closePromise:this.commandStarted?(this.closePromise=this.execVoid([`close`],!0),this.closePromise):(this.closePromise=Promise.resolve(),this.closePromise)}async execVoid(e,t=!1){let n=await this.exec(e,t);try{let t=JSON.parse(n);if(t.success===!1)throw Error(t.error??`agent-browser command failed: ${e.join(` `)}`)}catch(e){if(e instanceof SyntaxError)return;throw e}}exec(e,t=!1){if(this.closePromise&&!t)return Promise.reject(Error(`agent-browser session ${this.session} is closed`));t||(this.commandStarted=!0);let n=[`--session`,this.session,`--namespace`,this.namespace,`--init-script`,this.initScriptPath,`--allowed-domains`,this.allowedDomains.join(`,`),`--args`,`--force-device-scale-factor=${this.deviceScaleFactor},--lang=${this.locale}`,`--json`,...e];return new Promise((t,i)=>{let a=r(this.bin,n,{env:{...process.env,LANG:`${this.locale}.UTF-8`,TZ:this.timezone},stdio:[`ignore`,`pipe`,`pipe`]}),o=[],s=[];a.stdout.on(`data`,e=>o.push(e)),a.stderr.on(`data`,e=>s.push(e));let c=setTimeout(()=>{a.kill(),i(Error(`agent-browser timed out after ${this.timeoutMs}ms: ${e.join(` `)}`))},this.timeoutMs);a.once(`error`,e=>{clearTimeout(c),i(e)}),a.once(`close`,e=>{clearTimeout(c);let n=Buffer.concat(o).toString(`utf8`).trim(),r=Buffer.concat(s).toString(`utf8`).trim();if(e!==0){i(Error(`agent-browser failed (${e}): ${r||n}`));return}t(n)})})}},sd=class{id;options;attemptFactory;sessionPrefix;attemptNumber=0;activeAttempt;closed=!1;constructor(e,t=e=>new od(e)){this.id=e.id,this.sessionPrefix=`kw-${T(`sha256`).update(e.id).digest(`hex`).slice(0,8)}`;let{id:n,...r}=e;this.options=r,this.attemptFactory=t}async runAttempt(e,t){if(this.closed)throw Error(`Browser worker ${this.id} is closed`);if(this.activeAttempt)throw Error(`Browser worker ${this.id} already has an active attempt`);let n=++this.attemptNumber,r=new cd(e,this.attemptFactory({...this.options,session:`${this.sessionPrefix}-${e.target[0]}-${n.toString(36)}`}));this.activeAttempt=r;let i,a,o=!1;try{i=await t(r)}catch(e){o=!0,a=e}let s,c=!1;try{await r.close()}catch(e){c=!0,s=e}finally{this.activeAttempt===r&&(this.activeAttempt=void 0)}if(o&&c)throw AggregateError([a,s],`Browser attempt ${r.session} failed and could not be closed`);if(o)throw a;if(c)throw s;return i}async close(){if(this.closed)return;this.closed=!0;let e=this.activeAttempt;e&&(await e.close(),this.activeAttempt===e&&(this.activeAttempt=void 0))}},cd=class{scope;driver;isolation=`browser-process`;closePromise;constructor(e,t){this.scope=e,this.driver=t}get session(){return this.driver.session}open(e){return this.driver.open(e)}setViewport(e){return this.driver.setViewport(e)}setMedia(e,t){return this.driver.setMedia(e,t)}evaluate(e){return this.driver.evaluate(e)}screenshot(e,t){return this.driver.screenshot(e,t)}close(){return this.closePromise??=this.driver.close(),this.closePromise}},ld={name:`default`,width:1280,height:800},ud={pixelColorThreshold:.2,maxChangedPixelRatio:0},dd=[`baseImage`,`headImage`,`diffImage`],fd=/^[0-9a-f]{64}$/,pd={".css":`text/css; charset=utf-8`,".html":`text/html; charset=utf-8`,".ico":`image/x-icon`,".jpeg":`image/jpeg`,".jpg":`image/jpeg`,".js":`text/javascript; charset=utf-8`,".json":`application/json; charset=utf-8`,".mjs":`text/javascript; charset=utf-8`,".png":`image/png`,".svg":`image/svg+xml`,".woff":`font/woff`,".woff2":`font/woff2`},md=B({name:R(),width:z(),height:z()}),hd=B({id:R(),browser:R(),browserVersion:R(),orchestratorRuntime:R(),operatingSystem:R(),architecture:R(),deviceScaleFactor:z(),locale:R(),timezone:R(),colorScheme:Ns([`light`,`dark`]),reducedMotion:Ns([`reduce`,`no-preference`]),frozenTime:R(),randomSeed:z(),fontsFingerprint:R(),stateIsolation:V(`fresh-browser-process-per-story-side-v1`).optional(),network:B({mode:V(`allowlist`),allowedDomains:Ds(R()),webRtc:V(`disabled`)})}),gd=B({id:R(),storyId:R(),title:R(),name:R(),viewport:md,imageFile:R(),sha256:R(),capturedAt:R(),durationMs:z(),sourceRevision:R().optional(),ignoredRegions:Ds(B({x:z().int().nonnegative(),y:z().int().nonnegative(),width:z().int().positive(),height:z().int().positive()})).optional(),threshold:B({pixelColorThreshold:z().optional(),maxChangedPixelRatio:z().optional()}).optional(),error:R().optional()}).superRefine((e,t)=>{e.error||(/^images\/[A-Za-z0-9._-]+\.png$/.test(e.imageFile)||t.addIssue({code:`custom`,path:[`imageFile`],message:`must be a safe image path`}),/^[0-9a-f]{64}$/.test(e.sha256)||t.addIssue({code:`custom`,path:[`sha256`],message:`must be a SHA-256 digest`}))}),_d=B({version:V(2),revision:R(),environment:hd,createdAt:R(),snapshots:Ms(R(),gd)}),vd=B({version:V(1),buildDigest:R().regex(/^[a-f0-9]{64}$/),manifestDigest:R().regex(/^[a-f0-9]{64}$/)}),yd=`kapture-dependencies.json`,bd=R().min(1).max(4096).refine(Ml,`must be a normalized project-relative path`),xd=R().max(4096).refine(e=>e===``||Ml(e),{message:`must be empty or a normalized project-relative path`}),Sd=Ds(bd).max(1e5).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),Cd=R().regex(/^[0-9a-f]{64}$/),wd=Os({type:Ns([`asset`,`chunk`]),size:z().int().nonnegative().max(1e9),sha256:Cd}).strict(),Td=R().max(4096).refine(e=>e===``||e.endsWith(`/`)&&Ml(e.slice(0,-1)),`must be empty or a normalized project-relative directory prefix`),Ed=R().min(1).max(1024),Dd=Ds(Ed).max(1e4).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),Od=Ms(bd,Ms(bd,Dd)),kd=Ms(bd,Ms(Ed,Os({module:bd,imported:Ed}).strict())),Ad=Os({kind:V(`kapture-storybook-dependencies`),version:V(1),complete:ws(),storybookRoot:xd,globalInputs:Sd,ignoredInputs:Sd,fingerprintedInputs:Sd.optional(),diagnostics:Ds(Ns([`module-outside-project-root`,`module-fingerprint-missing`,`unresolved-virtual-module`,`unresolved-project-module`,`rendered-output-fingerprint-missing`,`global-output-fingerprint-missing`,`global-runtime-fingerprint-missing`,`unowned-output-chunk`,`output-inventory-mismatch`])).max(20).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),modules:Ms(bd,Sd),moduleFingerprints:Ms(bd,Cd).optional(),globalOutputFingerprints:Ms(bd,Cd),globalOutputStories:Ms(bd,Sd),globalRuntimeFingerprint:Cd,outputInventory:Ms(bd,wd),outputInventoryPrefixes:Ds(Td).max(100).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),importBindings:Od.optional(),reexportBindings:kd.optional(),renderedModules:Ms(bd,Sd),renderedOutputFingerprints:Ms(bd,Cd)}).strict().superRefine((e,t)=>{let n=Object.entries(e.modules),r=new Set(n.map(([e])=>e));n.length>1e5&&t.addIssue({code:`custom`,path:[`modules`],message:`contains too many modules`});for(let[i,a]of n)a.includes(i)||t.addIssue({code:`custom`,path:[`modules`,i],message:`must include the module itself`}),e.complete&&a.some(e=>!r.has(e))&&t.addIssue({code:`custom`,path:[`modules`,i],message:`must resolve every project dependency when the manifest is complete`});Object.keys(e.globalOutputFingerprints).length>1e5&&t.addIssue({code:`custom`,path:[`globalOutputFingerprints`],message:`contains too many global output fingerprints`});let i=new Set(Object.keys(e.globalOutputFingerprints)),a=Object.entries(e.globalOutputStories);a.length>1e5&&t.addIssue({code:`custom`,path:[`globalOutputStories`],message:`contains too many global output story lists`});for(let[e,n]of a){i.has(e)||t.addIssue({code:`custom`,path:[`globalOutputStories`,e],message:`must identify a fingerprinted global output`});for(let i of n)if(!r.has(i)){t.addIssue({code:`custom`,path:[`globalOutputStories`,e],message:`must contain only rendered story modules`});break}}for(let n of i)n in e.globalOutputStories||t.addIssue({code:`custom`,path:[`globalOutputStories`,n],message:`must cover every fingerprinted global output`});let o=Object.entries(e.outputInventory);o.length>1e5&&t.addIssue({code:`custom`,path:[`outputInventory`],message:`contains too many output files`}),`kapture-dependencies.json`in e.outputInventory&&t.addIssue({code:`custom`,path:[`outputInventory`,yd],message:`must not inventory the manifest itself`});for(let n of e.outputInventoryPrefixes)o.some(([e])=>e.startsWith(n))||t.addIssue({code:`custom`,path:[`outputInventoryPrefixes`],message:`must cover at least one inventoried output`});let s=Object.entries(e.moduleFingerprints??{});s.length>1e5&&t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`contains too many module fingerprints`});for(let[e]of s)r.has(e)||t.addIssue({code:`custom`,path:[`moduleFingerprints`,e],message:`must identify a rendered module`});(e.fingerprintedInputs?.length??0)>0&&(e.moduleFingerprints?e.complete&&n.some(([t])=>!e.moduleFingerprints?.[t])&&t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`must cover every rendered module when the manifest is complete`}):t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`is required when fingerprintedInputs are configured`}));let c=0;for(let[n,i]of Object.entries(e.importBindings??{})){c+=Object.keys(i).length,r.has(n)||t.addIssue({code:`custom`,path:[`importBindings`,n],message:`must identify a rendered importer`});for(let r of Object.keys(i))e.modules[n]?.includes(r)||t.addIssue({code:`custom`,path:[`importBindings`,n,r],message:`must identify a direct project dependency`})}for(let[n,i]of Object.entries(e.reexportBindings??{})){c+=Object.keys(i).length,r.has(n)||t.addIssue({code:`custom`,path:[`reexportBindings`,n],message:`must identify a rendered barrel`});for(let[r,a]of Object.entries(i))e.modules[n]?.includes(a.module)||t.addIssue({code:`custom`,path:[`reexportBindings`,n,r],message:`must identify a direct project dependency`})}c>1e6&&t.addIssue({code:`custom`,path:[`importBindings`],message:`contains too many import and re-export bindings`});let l=Object.entries(e.renderedModules??{});l.length>1e5&&t.addIssue({code:`custom`,path:[`renderedModules`],message:`contains too many rendered module closures`});let u=0;for(let[e,n]of l){u+=n.length,r.has(e)||t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must identify a rendered entry module`}),n.includes(e)||t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must include the entry module itself`});for(let i of n)if(!r.has(i)){t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must contain only rendered project modules`});break}}u>5e6&&t.addIssue({code:`custom`,path:[`renderedModules`],message:`contains too many rendered module references`});let d=Object.entries(e.renderedOutputFingerprints);d.length>1e5&&t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`],message:`contains too many rendered output fingerprints`});for(let[e]of d)r.has(e)||t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`,e],message:`must identify a rendered entry module`});e.complete&&l.some(([t])=>e.renderedOutputFingerprints[t]===void 0)&&t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`],message:`must cover every rendered entry module when the manifest is complete`}),e.complete!==(e.diagnostics.length===0)&&t.addIssue({code:`custom`,path:[`complete`],message:`must agree with diagnostics`})}),jd=1e3,Md=Os({id:R().min(1),type:Ns([`story`,`docs`]),importPath:R().min(1).optional()}).passthrough(),Nd=Os({entries:Ms(R(),Md)}).passthrough(),Pd=Os({id:R().min(1),title:R(),name:R(),type:Ns([`story`,`docs`])}),Fd=Os({v:z(),entries:Ms(R(),Pd)}),Id={getBrowserVersion:Vc,getFontsFingerprint:el}}));Ld();function Rd(e){let t=e.trim().match(/^\/kapture[ \t]+approve[ \t]+([0-9a-f]{40})[ \t]+([0-9a-f]{64})(?:[ \t]+--allow-unstable[ \t]+([^\r\n]+))?$/i);if(!t?.[1]||!t[2])return null;let n=t[3]?.trim();return t[3]!==void 0&&!zd(n)?null:{headSha:t[1].toLowerCase(),reportDigest:t[2].toLowerCase(),...n?{mode:`allow-unstable`,reason:n}:{mode:`standard`}}}function zd(e){return typeof e==`string`&&e.trim().length>0&&e.length<=1e3&&Array.from(e).every(e=>{let t=e.charCodeAt(0);return t>31&&t!==127})&&e.trim()!==`<reason>`}function Bd(e){let t=`/kapture approve ${e.headSha} ${e.reportDigest}`;return e.mode===`standard`?t:`${t} --allow-unstable ${e.reason.trim()}`}const Vd={executionErrors:e=>`❌ **${e} execution error(s)** must be fixed.`,clean:`✅ No visual changes.`,changes:e=>`🔍 **${e} visual change(s)** require review.`,unstableWarning:e=>`⚠️ **${e} screen(s) could not be verified.** Capturing the same code again produced different images, so we cannot tell which differences came from your code changes. Fix the inconsistent rendering and rerun. Ordinary visual approval cannot bypass this check.`,comparison:(e,t)=>`**${e} stories · ${t} snapshots compared**`,coverage:(e,t,n,r,i,a)=>e===`affected`?`**${n} of ${t} affected stories selected · ${r} stories / ${i} snapshots compared · ${a} proven unaffected**`:`**${n} stories selected · ${r} stories / ${i} snapshots compared**`,fallback:e=>`- Safe full-capture fallback: ${e.join(`, `)}`,counts:e=>`- Unchanged ${e.unchanged} · Changed ${e.changed} · Unstable ${e.unstable} · Added ${e.added} · Removed ${e.removed} · Errors ${e.errors}`,branch:`Branch`,environment:`Environment`,reportDownload:`Download the full comparison report`,reportOpen:`Open the full comparison report`,storyOpen:`Open captured story`,sections:{error:`🚨 Execution errors`,removed:`⚠️ Removed snapshots`,changed:`🔍 Visual changes`,unstable:`⚠️ Unstable snapshots`,added:`➕ Added snapshots`},hidden:e=>`${e} more item(s) are available in the full comparison report.`,errorAdvice:`⚠️ Capture or comparison errors must be fixed before approval.`,approvalPrompt:`A reviewer with write permission can approve the full head build with:`,unstableApprovalPrompt:`A reviewer with write permission may accept the instability for this entire report with an explicit exception. Replace <reason> with your reason (one line, up to 1000 characters). The unstable evidence remains unchanged:`,unstableApproval:(e,t,n)=>`⚠️ @${e} accepted an unstable exception for Kapture report \`${t}\`.\n\nReason: ${n}\n\nThis accepts the entire report, including visual changes. Instability evidence is preserved; this does not prove reproducibility.`,captureError:`Capture or comparison failed.`,removedEntry:`Not found in the head Storybook`,addedEntry:`New snapshot`,approval:(e,t)=>`✅ @${e} approved Kapture report \`${t.slice(0,12)}\`.`},Hd={executionErrors:e=>`❌ **${e}개의 실행 오류**를 해결해 주세요.`,clean:`✅ 시각적 변경이 없습니다.`,changes:e=>`🔍 **${e}개의 시각적 변경**을 검토해 주세요.`,unstableWarning:e=>`⚠️ **${e}개 화면의 검증을 통과하지 못했어요.** 같은 코드로 화면을 다시 찍었는데 결과가 달라졌어요. 코드 변경으로 생긴 차이를 확인할 수 없으니, 화면이 달라지는 원인을 수정한 뒤 다시 실행해 주세요. 일반 시각 변경 승인으로는 이 검증을 통과시킬 수 없어요.`,comparison:(e,t)=>`**${e}개 스토리 · ${t}개 스냅샷 비교**`,coverage:(e,t,n,r,i,a)=>e===`affected`?`**전체 ${t}개 Story 중 영향받은 ${n}개 선택 · ${r}개 Story / ${i}개 스냅샷 비교 · ${a}개는 dependency graph로 제외**`:`**${n}개 Story 선택 · ${r}개 Story / ${i}개 스냅샷 비교**`,fallback:e=>`- 누락 방지를 위해 전체 캡처로 전환: ${e.join(`, `)}`,counts:e=>`- 동일 ${e.unchanged} · 변경 ${e.changed} · 불안정 ${e.unstable} · 추가 ${e.added} · 삭제 ${e.removed} · 오류 ${e.errors}`,branch:`브랜치`,environment:`환경`,reportDownload:`전체 비교 리포트 다운로드`,reportOpen:`전체 비교 리포트 열기`,storyOpen:`캡처한 Story 열기`,sections:{error:`🚨 실행 오류`,removed:`⚠️ 삭제된 스냅샷`,changed:`🔍 시각 변경`,unstable:`⚠️ 불안정한 스냅샷`,added:`➕ 추가된 스냅샷`},hidden:e=>`그 외 ${e}개 항목은 전체 비교 리포트에서 확인해 주세요.`,errorAdvice:`⚠️ 캡처 또는 비교 오류를 해결해야 합니다. 승인할 수 없습니다.`,approvalPrompt:`전체 head 빌드를 승인하려면 쓰기 권한이 있는 리뷰어가 다음 명령을 남겨 주세요.`,unstableApprovalPrompt:`쓰기 권한이 있는 리뷰어는 불안정성을 인지한 상태에서 전체 리포트를 예외 승인할 수 있어요. <reason>을 사유(한 줄, 최대 1000자)로 바꿔 주세요. 불안정 증거는 그대로 유지됩니다.`,unstableApproval:(e,t,n)=>`⚠️ @${e} 님이 Kapture 리포트 \`${t}\`의 불안정을 예외 승인했습니다.\n\n사유: ${n}\n\n시각 변경을 포함한 전체 리포트에 대한 승인입니다. 불안정 증거는 유지되며, 재현성 검증을 통과했다는 뜻은 아닙니다.`,captureError:`캡처 또는 비교에 실패했습니다.`,removedEntry:`head Storybook에서 찾을 수 없음`,addedEntry:`새 스냅샷`,approval:(e,t)=>`✅ @${e} 님이 Kapture 리포트 \`${t.slice(0,12)}\`를 승인했습니다.`};function Ud(e){if(e===`en`||e===`ko`)return e;throw Error(`Comment language must be en or ko`)}function Wd(e){return e===`ko`?Hd:Vd}const Gd=`<!-- kapture-report:`,Kd={error:0,removed:1,changed:2,unstable:3,added:4,unchanged:5};function qd(e){return e.contentDigest??il(e)}function Jd(e){return`${Gd}${Buffer.from(JSON.stringify(e)).toString(`base64url`)} -->`}function Yd(e){let t=e.indexOf(Gd);if(t<0)return null;let n=t+20,r=e.indexOf(` -->`,n);if(r<0)return null;try{let t=JSON.parse(Buffer.from(e.slice(n,r),`base64url`).toString());return t.version!==4||!Zd(t.baseSha)||!Zd(t.headSha)||!/^[0-9a-f]{64}$/.test(t.digest)||!uf(t.captureRunId)||!uf(t.captureRunAttempt)||!uf(t.captureWorkflowId)||!df(t.captureRunHeadBranch)||!uf(t.captureRunHeadRepositoryId)||![`clean`,`changed`,`unstable`,`error`].includes(t.status)||t.reportUrl!==void 0&&Qd(t.reportUrl)!==t.reportUrl?null:t}catch{return null}}function Xd(e,t,n=`Kapture Visual Review`,r=`en`){let{summary:i}=e,a=i.changed+i.added+i.removed,o=new Set(Object.values(e.entries).map(e=>e.storyId)).size,s=af(n,100),c=Wd(r),l=[Jd(t),`## ${s}`,``,i.errors>0?c.executionErrors(i.errors):i.unstable>0?c.unstableWarning(i.unstable):a===0?c.clean:c.changes(a),``,e.coverage?c.coverage(e.coverage.mode,e.coverage.storyIds.length,e.coverage.selectedStoryIds.length,o,i.total,e.coverage.skippedStoryIds.length):c.comparison(o,i.total),``,c.counts(i),`- ${c.branch} \`${sf(t.captureRunHeadBranch)}\` · ${c.environment} \`${sf(e.environment.id)}\` · base \`${lf(e.baseRevision)}\` → head \`${lf(e.headRevision)}\``];if(e.coverage?.mode===`full-fallback`&&l.push(c.fallback([...new Set(e.coverage.fallbackReasons.map(e=>e.code))])),i.unstable>0&&i.errors>0&&l.push(``,c.unstableWarning(i.unstable)),t.reportUrl){let e=cf(t.reportUrl)?c.reportDownload:c.reportOpen;l.push(``,`[${e}](${t.reportUrl})`)}let u=Object.values(e.entries).filter(e=>e.status!==`unchanged`).sort(rf),d=u.slice(0,20);for(let n of[`error`,`removed`,`changed`,`unstable`,`added`]){let r=u.filter(e=>e.status===n),i=d.filter(e=>e.status===n);if(i.length!==0){l.push(``,`### ${c.sections[n]} (${r.length})`,``);for(let n of i)l.push(tf(n,c,e.storybookUrl,t.reportUrl))}}let f=u.length-d.length;return f>0&&l.push(``,c.hidden(f)),i.errors>0?l.push(``,c.errorAdvice):i.unstable>0?l.push(``,c.unstableApprovalPrompt,``,`\`${Bd({headSha:e.headRevision,reportDigest:t.digest,mode:`allow-unstable`,reason:`<reason>`})}\``):a>0&&i.unstable===0&&l.push(``,c.approvalPrompt,``,`\`${Bd({headSha:e.headRevision,reportDigest:t.digest,mode:`standard`})}\``),`${l.join(`
599
- `)}\n`}function Zd(e){return/^[0-9a-f]{40}$/i.test(e)}function Qd(e){if(!e)return;if(e.length>2048)throw Error(`Report URL is too long`);let t;try{t=new URL(e)}catch{throw Error(`Report URL must be a valid HTTPS URL`)}if(t.protocol!==`https:`||t.username||t.password)throw Error(`Report URL must be an HTTPS URL without credentials`);return t.toString().replace(/\(/g,`%28`).replace(/\)/g,`%29`).replace(/\[/g,`%5B`).replace(/\]/g,`%5D`)}function $d(e){if(e){if(e===`./storybook/`)return e;try{return Qd(e)}catch{throw Error(`Storybook URL must be a valid HTTPS URL or ./storybook/`)}}}function ef(e){let t=of(e).replace(/\s+/g,` `).trim();if(!t||t.length>100)throw Error(`Status context must contain between 1 and 100 characters`);return t}function tf(e,t,n,r){let i=`**${af(e.title)} / ${af(e.name)}** · ${af(e.viewport.name)}`,a=n?nf(n,e.storyId,r):void 0,o=a?` · [${t.storyOpen}](${a})`:``;return e.status===`error`?`- ${i} — ${af(e.error??t.captureError,180)}${o}`:e.status===`removed`?`- ${i} — ${t.removedEntry}`:e.status===`added`?`- ${i} — ${t.addedEntry}${o}`:`- ${i}${o}`}function nf(e,t,n){if(e===`./storybook/`&&!n)return;let r=new URL(e,n);return r.searchParams.set(`path`,`/story/${t}`),Qd(r.toString())}function rf(e,t){let n=Kd[e.status]-Kd[t.status];return n===0?`${e.title}/${e.name}/${e.viewport.name}`.localeCompare(`${t.title}/${t.name}/${t.viewport.name}`):n}function af(e,t=240){let n=of(e).replace(/\s+/g,` `).trim();return(n.length>t?`${n.slice(0,t-3)}...`:n).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/\\/g,`\\\\`).replace(/([`*_[\]{}|])/g,`\\$1`).replace(/@/g,`@​`)}function of(e){return Array.from(e,e=>{let t=e.codePointAt(0)??0;return t<=31||t===127?` `:e}).join(``)}function sf(e){return e.replace(/`/g,`ˋ`).replace(/[\r\n]/g,` `).replace(/@/g,`@​`)}function cf(e){return e.includes(`/actions/runs/`)&&e.includes(`/artifacts/`)}function lf(e){return e.slice(0,8)}function uf(e){return typeof e==`number`&&Number.isInteger(e)&&e>0}function df(e){return typeof e!=`string`||e.length<1||e.length>512?!1:Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127})}async function ff(e,t,n){if(!Number.isSafeInteger(t)||t<=0)throw Error(`Download byte limit must be positive`);let r=e.headers.get(`content-length`);if(r!==null){let i=Number(r);if(!Number.isSafeInteger(i)||i<0||i>t)throw await e.body?.cancel().catch(()=>{}),Error(`${n} exceeds the ${t} byte download limit`)}if(!e.body)throw Error(`${n} download returned no body`);let i=e.body.getReader(),a=[],o=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if(o+=r.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`${n} exceeds the ${t} byte download limit`);a.push(Buffer.from(r))}}finally{i.releaseLock()}if(o<1)throw Error(`${n} download is empty`);return Buffer.concat(a,o)}var pf=E((()=>{}));pf();var mf=class{#e;#t;#n;constructor(e,t,n=fetch){if(!e)throw Error(`GITHUB_TOKEN is required`);this.#e=e,this.#t=t,this.#n=n}async getWorkflowRun(e){return gf(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}`))}async listWorkflowRuns(e,t){return kf(e=>this.#i(`GET`,`${this.#r()}${e}`),e,t)}async listRunArtifacts(e){let t=[];for(let n=1;n<=10;n+=1){let r=new URLSearchParams({per_page:`100`,page:String(n)}),i=Sf(W(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}/artifacts?${r}`),`artifacts response`).artifacts,`artifacts`).map(vf);if(t.push(...i),i.length<100)return t}throw Error(`GitHub returned more than 1000 workflow artifacts`)}async getArtifact(e){let t=await this.#o(`GET`,`${this.#r()}/actions/artifacts/${e}`);return t.status===404?null:(await hf(t,`GET`,`/actions/artifacts/${e}`),vf(await t.json()))}async listCaptureCacheArtifacts(e){let t=new URLSearchParams({name:e,per_page:`10`});return Sf(W(await this.#i(`GET`,`${this.#r()}/actions/artifacts?${t}`),`cache artifacts`).artifacts,`artifacts`).map(vf)}async isMergedCaptureRun(e,t){let n=Sf(W(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}`),`capture run`).pull_requests,`pull_requests`);n.length===0&&/^[a-f0-9]{40}$/.test(t)&&(n=Sf(await this.#i(`GET`,`${this.#r()}/commits/${t}/pulls?per_page=5`),`associated pull requests`));for(let e of n.slice(0,5)){let n=W(e,`pull request`).number;if(!Number.isSafeInteger(n)||Number(n)<=0)continue;let r=W(await this.#i(`GET`,`${this.#r()}/pulls/${n}`),`pull request`);if(r.merged===!0&&W(r.head,`head`).sha===t)return!0}return!1}async downloadArtifactArchive(e,t){if(!Number.isSafeInteger(t)||t<=0)throw Error(`Artifact download byte limit must be positive`);let n=await this.#o(`GET`,`${this.#r()}/actions/artifacts/${e}/zip`,`manual`),r=await this.#a(n,e);return await hf(r,`GET`,`/actions/artifacts/${e}/zip`),ff(r,t,`Artifact ${e}`)}async deleteArtifact(e){let t=await this.#o(`DELETE`,`${this.#r()}/actions/artifacts/${e}`);t.status!==404&&await hf(t,`DELETE`,`/actions/artifacts/${e}`)}async getPullRequest(e){return yf(await this.#i(`GET`,`${this.#r()}/pulls/${e}`))}async listOpenPullRequestsForHead(e,t,n){let r=xf(e),i=[];for(let e=1;e<=10;e+=1){let a=new URLSearchParams({state:`open`,base:n,head:`${r.owner}:${t}`,per_page:`100`,page:String(e)}),o=Sf(await this.#i(`GET`,`${this.#r()}/pulls?${a}`),`pull requests response`).map(yf);if(i.push(...o),o.length<100)return i}throw Error(`GitHub returned more than 1000 matching pull requests`)}async getContentSha(e,t,n){let r=xf(e),i=t.split(`/`).map(encodeURIComponent).join(`/`),a=new URLSearchParams({ref:n});return Df(W(await this.#i(`GET`,`/repos/${encodeURIComponent(r.owner)}/${encodeURIComponent(r.repo)}/contents/${i}?${a}`),`contents response`).sha,`contents SHA`)}#r(){let{owner:e,repo:t}=this.#t;return`/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}async#i(e,t){let n=await this.#o(e,t);return await hf(n,e,t),n.json()}async#a(e,t){if(e.status<300||e.status>399)return e;let n=e.headers.get(`location`);if(!n)throw Error(`Artifact ${t} redirect is missing its location`);let r;try{r=new URL(n)}catch{throw Error(`Artifact ${t} redirect location is invalid`)}if(r.protocol!==`https:`||r.username||r.password)throw Error(`Artifact ${t} redirect must be a credential-free HTTPS URL`);return this.#n(r,{method:`GET`,headers:{Accept:`application/octet-stream`,"User-Agent":`kapture-cli`},redirect:`follow`})}#o(e,t,n=`follow`){return this.#n(`https://api.github.com${t}`,{method:e,headers:{Accept:`application/vnd.github+json`,Authorization:`Bearer ${this.#e}`,"X-GitHub-Api-Version":`2022-11-28`,"User-Agent":`kapture-cli`},redirect:n})}};async function hf(e,t,n){if(!e.ok)throw Error(`GitHub API ${t} ${n} failed with status ${e.status}`)}function gf(e){let t=W(e,`workflow run`);return{id:Cf(t.id,`workflow run ID`),runNumber:Cf(t.run_number,`workflow run number`),runAttempt:Cf(t.run_attempt,`workflow run attempt`),workflowId:Cf(t.workflow_id,`workflow ID`),path:wf(t.path,`workflow path`),status:wf(t.status,`workflow run status`),conclusion:Tf(t.conclusion,`workflow run conclusion`),event:wf(t.event,`workflow run event`),headSha:Df(t.head_sha,`workflow run head SHA`),headBranch:wf(t.head_branch,`workflow run head branch`),headRepository:bf(t.head_repository,`workflow run head repository`),repository:bf(t.repository,`workflow run repository`)}}function _f(e){let t=W(e,`workflow run candidate`);return{id:Cf(t.id,`workflow run ID`),runNumber:Cf(t.run_number,`workflow run number`),headRepositoryId:Cf(W(t.head_repository,`workflow run head repository`).id,`workflow run head repository ID`)}}function vf(e){let t=W(e,`workflow artifact`),n=W(t.workflow_run,`artifact workflow run`);return{id:Cf(t.id,`artifact ID`),name:wf(t.name,`artifact name`),sizeInBytes:Cf(t.size_in_bytes,`artifact size`),digest:Of(t.digest,`artifact digest`),expired:Ef(t.expired,`artifact expired`),workflowRun:{id:Cf(n.id,`artifact workflow run ID`),repositoryId:Cf(n.repository_id,`artifact workflow repository ID`),headRepositoryId:Cf(n.head_repository_id,`artifact workflow head repository ID`),headBranch:wf(n.head_branch,`artifact workflow head branch`),headSha:Df(n.head_sha,`artifact workflow head SHA`)}}}function yf(e){let t=W(e,`pull request`),n=W(t.base,`pull request base`),r=W(t.head,`pull request head`),i=wf(t.state,`pull request state`);if(i!==`open`&&i!==`closed`)throw Error(`Pull request state is invalid`);return{number:Cf(t.number,`pull request number`),state:i,base:{ref:wf(n.ref,`pull request base ref`),sha:Df(n.sha,`pull request base SHA`),repository:bf(n.repo,`pull request base repository`)},head:{ref:wf(r.ref,`pull request head ref`),sha:Df(r.sha,`pull request head SHA`),repository:bf(r.repo,`pull request head repository`)}}}function bf(e,t){let n=W(e,t),r=wf(n.full_name,`${t} full name`);return xf(r),{id:Cf(n.id,`${t} ID`),fullName:r}}function xf(e){let t=e.match(/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);if(!t?.[1]||!t[2])throw Error(`Repository full name is invalid`);return{owner:t[1],repo:t[2]}}function W(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function Sf(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}function Cf(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function wf(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);for(let n of e){let e=n.codePointAt(0)??0;if(e<=31||e===127)throw Error(`${t} contains control characters`)}return e}function Tf(e,t){return e===null?null:wf(e,t)}function Ef(e,t){if(typeof e!=`boolean`)throw Error(`${t} must be a boolean`);return e}function Df(e,t){if(typeof e!=`string`||!/^[0-9a-f]{40}$/.test(e))throw Error(`${t} must be a lowercase full SHA`);return e}function Of(e,t){if(typeof e!=`string`||!/^sha256:[0-9a-f]{64}$/.test(e))throw Error(`${t} must be a SHA-256 digest`);return e}async function kf(e,t,n){let r=[];for(let i=1;i<=10;i+=1){let a=Sf(W(await e(`/actions/workflows/${t}/runs?${new URLSearchParams({event:`pull_request`,branch:n,per_page:`100`,page:String(i)})}`),`workflow runs response`).workflow_runs,`workflow_runs`).map(_f);if(r.push(...a),a.length<100)return r}throw Error(`GitHub returned more than 1000 workflow runs`)}var Af=class{#e;#t;#n;constructor(e,t){if(!e)throw Error(`GITHUB_TOKEN is required`);this.#e=e,this.#t=t,this.#n=jf(process.env.GITHUB_API_URL)}async setReviewStatus(e,t,n,r,i){await this.#i(`POST`,`/statuses/${encodeURIComponent(e)}`,{state:t,description:n.slice(0,140),context:r,target_url:i})}async postOrUpdateReportComment(e,t,n=Gd){let r=(await this.#r(e)).find(e=>e.user?.login===`github-actions[bot]`&&e.body?.includes(n));return r?(await this.#i(`PATCH`,`/issues/comments/${r.id}`,{body:t})).id:this.createIssueComment(e,t)}async findCurrentReportMarker(e,t,n){let r=await this.#r(e);for(let e of r.reverse()){if(e.user?.login!==`github-actions[bot]`||!e.body)continue;let r=Yd(e.body);if(r?.baseSha===t&&r.headSha===n)return r}return null}async assertCurrentCaptureRun(e,t,n,r,i){let a=gf(await this.#i(`GET`,`/actions/runs/${e}`));if(a.id!==e||a.runAttempt!==t||a.workflowId!==n||a.headBranch!==r||a.headRepository.id!==i||a.status!==`completed`||a.conclusion!==`success`||a.event!==`pull_request`)throw Error(`Kapture report does not belong to the current successful capture run`);if(!await mt({listWorkflowRuns:(e,t)=>kf(e=>this.#i(`GET`,e),e,t)},a))throw Error(`A newer Kapture capture run exists for this pull request`)}async getLatestReviewStatus(e,t){for(let n=1;n<=10;n+=1){let r=await this.#i(`GET`,`/commits/${encodeURIComponent(e)}/status?per_page=100&page=${n}`),i=r.statuses.find(e=>e.context===t);if(i)return Mf(i.state)?{state:i.state,description:i.description??void 0,targetUrl:i.target_url??void 0}:null;if(r.statuses.length<100)break}return null}async assertWritePermission(e){let t=await this.#i(`GET`,`/collaborators/${encodeURIComponent(e)}/permission`);if(!t.permission||![`admin`,`maintain`,`write`].includes(t.permission))throw Error(`@${e} does not have write permission for this repository`)}async getPullRequest(e){return this.#i(`GET`,`/pulls/${e}`)}async readPackageManifest(e,t){if(!/^[0-9a-f]{40}$/.test(t)||!/^[A-Za-z0-9._/-]+$/.test(e)||e.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Package manifest requires a project-relative path and exact revision`);let n=await this.#i(`GET`,`/contents/${e.split(`/`).map(encodeURIComponent).join(`/`)}?ref=${t}`);if(n.type!==`file`||n.encoding!==`base64`||typeof n.content!=`string`||!Number.isSafeInteger(n.size)||n.size<0||n.size>1048576||n.content.length>2097152)throw Error(`Expected a bounded package.json file at the exact base revision`);return JSON.parse(Buffer.from(n.content,`base64`).toString(`utf8`))}async getPullRequestForCapture(e){return this.#i(`GET`,`/pulls/${e}`)}async listPullRequestFilesPage(e,t,n){return this.#i(`GET`,`/pulls/${e}/files?per_page=${n}&page=${t}`)}async createIssueComment(e,t){return(await this.#i(`POST`,`/issues/${e}/comments`,{body:t})).id}async#r(e){let t=[];for(let n=1;n<=10;n+=1){let r=await this.#i(`GET`,`/issues/${e}/comments?per_page=100&page=${n}`);if(t.push(...r),r.length<100)break}return t}async#i(e,t,n){let{owner:r,repo:i}=this.#t,a=`/repos/${encodeURIComponent(r)}/${encodeURIComponent(i)}${t}`,o=await fetch(`${this.#n}${a}`,{method:e,headers:{Accept:`application/vnd.github+json`,Authorization:`Bearer ${this.#e}`,"X-GitHub-Api-Version":`2022-11-28`,"User-Agent":`kapture-cli`,...n?{"Content-Type":`application/json`}:{}},body:n?JSON.stringify(n):void 0});if(!o.ok)throw Error(`GitHub API ${e} ${t} failed with status ${o.status}${await dt(o,this.#e)}`);return await o.json()}};function jf(e){let t=e?.trim()||`https://api.github.com`,n;try{n=new URL(t)}catch{throw Error(`GITHUB_API_URL must be a valid absolute URL`)}let r=[`127.0.0.1`,`localhost`,`[::1]`].includes(n.hostname);if(n.protocol!==`https:`&&!(n.protocol===`http:`&&r))throw Error(`GITHUB_API_URL must use HTTPS (HTTP is allowed only for loopback tests)`);if(n.username||n.password||n.search||n.hash)throw Error(`GITHUB_API_URL must not contain credentials, a query, or a fragment`);return n.toString().replace(/\/+$/,``)}function Mf(e){return[`error`,`failure`,`pending`,`success`].includes(e)}async function Nf(){let e=process.env.GITHUB_EVENT_PATH;if(!e)throw Error(`GITHUB_EVENT_PATH is required`);let t=await C(e);if(!t.isFile()||t.size>10485760)throw Error(`GitHub event payload is missing or too large`);try{return JSON.parse(await x(e,`utf8`))}catch{throw Error(`GITHUB_EVENT_PATH does not contain valid JSON`)}}function Pf(e){let t=Vf(e,`GitHub event payload`);if(t.action!==`completed`)throw Error(`Kapture report requires a completed normalized event`);let n=Vf(t.kapture,`kapture normalized event`);if(n.schemaVersion!==1)throw Error(`Kapture report requires normalized event schemaVersion 1`);let r=Vf(n.pullRequest,`kapture.pullRequest`),i=Vf(n.captureRun,`kapture.captureRun`),a=Lf(r.headSha,`kapture.pullRequest.headSha`),o=zf(i.headBranch);if(!Bf(o))throw Error(`kapture.captureRun.headBranch is invalid`);return{repository:If(t),issueNumber:Rf(r.number,`pull request number`),headSha:a,captureRunId:Rf(i.id,`capture run ID`),captureRunAttempt:Rf(i.attempt,`capture run attempt`),captureWorkflowId:Rf(i.workflowId,`capture workflow ID`),captureRunHeadBranch:o,captureRunHeadRepositoryId:Rf(i.headRepositoryId,`capture run head repository ID`)}}function Ff(e){let t=Vf(e,`GitHub event payload`);if(t.action!==`created`)throw Error(`Kapture approval only accepts newly created issue comments`);let n=Vf(t.issue,`issue`);if(!n.pull_request)throw Error(`Kapture approval must be posted on a pull request`);let r=Rd(zf(Vf(t.comment,`comment`).body));if(!r)throw Error(`Expected /kapture approve <full-head-sha> <64-character-report-digest> [--allow-unstable <reason>]; reason must be one line, 1–1000 characters`);let i=zf(Vf(t.sender,`sender`).login);if(!/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/.test(i))throw Error(`GitHub event contains an invalid sender login`);return{repository:If(t),issueNumber:Rf(n.number,`pull request number`),...r,sender:i}}function If(e){let t=zf(Vf(Vf(e,`GitHub event payload`).repository,`repository`).full_name).match(/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);if(!t?.[1]||!t[2])throw Error(`GitHub event contains an invalid repository`);return{owner:t[1],repo:t[2]}}function Lf(e,t){let n=zf(e).toLowerCase();if(!Zd(n))throw Error(`${t} must be a full 40-character SHA`);return n}function Rf(e,t){if(typeof e!=`number`||!Number.isInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function zf(e){if(typeof e!=`string`)throw Error(`GitHub event contains an invalid string value`);return e}function Bf(e){return e.length<1||e.length>512?!1:Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127})}function Vf(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}const Hf={standard:{reportStatus:`changed`,state:`pending`,description:`Visual changes require approval`,approvedPrefix:`Approved by @`},"allow-unstable":{reportStatus:`unstable`,state:`failure`,description:`Unstable snapshots require exception approval`,approvedPrefix:`Unstable exception approved by @`}};function Uf(e){return Object.values(Hf).find(t=>t.reportStatus===e)}function Wf(e,t){let n=Hf[t].approvedPrefix;return e.state===`success`&&e.description?.startsWith(n)===!0&&/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(e.description.slice(n.length))}const Gf=`Publishing verified visual report`;async function Kf(e,t,n){let r=Jf(n.baseRevision,`Report base`),i=Jf(n.headRevision,`Report head`);if(i!==t.headSha)throw Error(`Report head ${n.headRevision} does not match workflow head ${t.headSha}`);let a=await e.getPullRequest(t.issueNumber);if(a.number!==t.issueNumber)throw Error(`GitHub returned PR #${a.number} instead of requested PR #${t.issueNumber}`);if(a.state!==`open`)throw Error(`Pull request #${t.issueNumber} is not open`);let o=Jf(a.head.sha,`Current PR head`),s=Jf(a.base.sha,`Current PR base`);if(o!==i)throw Error(`Report head ${n.headRevision} is stale; current PR head is ${a.head.sha}`);if(s!==r)throw Error(`Report base ${n.baseRevision} is stale; current PR base is ${a.base.sha}`);return a}async function qf(e,t,n,r,i,a=`en`){if(await Kf(e,t,n),!n.contentDigest)throw Error("GitHub report publishing requires an image-bound contentDigest; run `kapture report build` first");let o=qd(n),s=n.summary.changed+n.summary.added+n.summary.removed,c=n.summary.errors>0?`error`:n.summary.unstable>0?`unstable`:s>0?`changed`:`clean`,l={version:4,baseSha:n.baseRevision.toLowerCase(),headSha:n.headRevision.toLowerCase(),digest:o,captureRunId:t.captureRunId,captureRunAttempt:t.captureRunAttempt,captureWorkflowId:t.captureWorkflowId,captureRunHeadBranch:t.captureRunHeadBranch,captureRunHeadRepositoryId:t.captureRunHeadRepositoryId,status:c,reportUrl:i},u=Uf(c),d=u?.state??(c===`error`?`failure`:`success`),f=u?.description??(c===`error`?`${n.summary.errors} visual capture error(s)`:`No visual changes`);await e.assertCurrentCaptureRun(t.captureRunId,t.captureRunAttempt,t.captureWorkflowId,t.captureRunHeadBranch,t.captureRunHeadRepositoryId),await e.setReviewStatus(t.headSha,`pending`,Gf,r,i);let p=await e.postOrUpdateReportComment(t.issueNumber,Xd(n,l,r,a));await Kf(e,t,n),await e.assertCurrentCaptureRun(t.captureRunId,t.captureRunAttempt,t.captureWorkflowId,t.captureRunHeadBranch,t.captureRunHeadRepositoryId);let m=await e.getLatestReviewStatus(t.headSha,r);if(!m||m.state!==`pending`||m.description!==Gf||m.targetUrl!==i)throw Error(`Kapture status changed while the report was being published; retry report`);return await e.setReviewStatus(t.headSha,d,f,r,i),{status:c,changedCount:s,commentId:p,reportDigest:o}}function Jf(e,t){if(!Zd(e))throw Error(`${t} ${e} must be a full 40-character SHA`);return e.toLowerCase()}async function Yf(e,t,n,r=`en`){if(t.mode===`allow-unstable`&&!zd(t.reason))throw Error(`Unstable exception approval requires a reason of 1–1000 characters on one line`);await e.assertWritePermission(t.sender);let i=await e.getPullRequest(t.issueNumber);if(i.number!==t.issueNumber)throw Error(`GitHub returned PR #${i.number} instead of requested PR #${t.issueNumber}`);if(i.state!==`open`)throw Error(`Pull request #${t.issueNumber} is not open`);let a=Jf(i.base.sha,`Current PR base`),o=Jf(i.head.sha,`Current PR head`);if(o!==t.headSha)throw Error(`Approval SHA ${t.headSha} is stale; current PR head is ${i.head.sha}`);let s=await e.findCurrentReportMarker(t.issueNumber,a,o);if(!s)throw Error(`No Kapture report exists for current base ${a} and head ${o}`);let c=Hf[t.mode];if(s.version!==4||s.status!==c.reportStatus)throw Error(`Kapture report for ${t.headSha} is not eligible for approval (${s.status})`);if(s.digest!==t.reportDigest)throw Error(`Approval digest ${t.reportDigest} does not match current report ${s.digest}`);await e.assertCurrentCaptureRun(s.captureRunId,s.captureRunAttempt,s.captureWorkflowId,s.captureRunHeadBranch,s.captureRunHeadRepositoryId);let l=await e.getLatestReviewStatus(o,n);if(!l||l.state!==c.state||l.description!==c.description||l.targetUrl!==s.reportUrl)throw Error(`Current Kapture status is not awaiting approval for this report`);await e.createIssueComment(t.issueNumber,t.mode===`allow-unstable`?Wd(r).unstableApproval(t.sender,s.digest,af(t.reason,1e3)):Wd(r).approval(t.sender,s.digest));let u=await e.findCurrentReportMarker(t.issueNumber,a,o);if(!u||u.digest!==t.reportDigest||u.status!==c.reportStatus||u.captureRunId!==s.captureRunId||u.captureRunAttempt!==s.captureRunAttempt||u.captureWorkflowId!==s.captureWorkflowId||u.captureRunHeadBranch!==s.captureRunHeadBranch||u.captureRunHeadRepositoryId!==s.captureRunHeadRepositoryId||u.reportUrl!==s.reportUrl)throw Error(`Kapture report changed while approval was being applied; retry approval`);await e.assertCurrentCaptureRun(s.captureRunId,s.captureRunAttempt,s.captureWorkflowId,s.captureRunHeadBranch,s.captureRunHeadRepositoryId);let d=await e.getLatestReviewStatus(o,n);if(!d||d.state!==c.state||d.description!==c.description||d.targetUrl!==s.reportUrl)throw Error(`Current Kapture status changed while approval was being applied; retry approval`);let f=await e.getPullRequest(t.issueNumber);if(f.number!==t.issueNumber||f.state!==`open`||Jf(f.base.sha,`Current PR base`)!==a||Jf(f.head.sha,`Current PR head`)!==o)throw Error(`Pull request changed while approval was being applied; retry approval`);return await e.setReviewStatus(t.headSha,`success`,`${c.approvedPrefix}${t.sender}`,n,s.reportUrl),{status:`approved`,reportDigest:s.digest}}async function G(e){let t=process.env.GITHUB_OUTPUT;if(!t)return;let n=[];for(let[t,r]of Object.entries(e)){let e=String(r),i=`kapture_${ie()}`;n.push(`${t}<<${i}\n${e}\n${i}\n`)}await h(t,n.join(``),`utf8`)}A();const Xf=k({meta:{name:`approve`,description:`Approve the current full-SHA Kapture report`},args:{"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`Approval comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=Ff(await Nf()),r=await Yf(new Af(t,n.repository),n,ef(e[`status-context`]),Ud(e[`comment-language`]));await G({status:r.status,"report-digest":r.reportDigest})}catch(e){throw await G({status:`error`}),e}}}),K={silent:-1/0,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:1/0},Zf={silent:{level:-1},fatal:{level:K.fatal},error:{level:K.error},warn:{level:K.warn},log:{level:K.log},info:{level:K.info},success:{level:K.success},fail:{level:K.fail},ready:{level:K.info},start:{level:K.info},box:{level:K.info},debug:{level:K.debug},trace:{level:K.trace},verbose:{level:K.verbose}};function Qf(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function $f(e,t,n=`.`,r){if(!Qf(t))return $f(e,{},n,r);let i=Object.assign({},t);for(let t in e){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(i[t]=Array.isArray(a)&&Array.isArray(i[t])?[...a,...i[t]]:Qf(a)&&Qf(i[t])?$f(a,i[t],(n?`${n}.`:``)+t.toString(),r):a))}return i}function ep(e){return(...t)=>t.reduce((t,n)=>$f(t,n,``,e),{})}const tp=ep();function np(e){return Object.prototype.toString.call(e)===`[object Object]`}function rp(e){return!(!np(e)||!e.message&&!e.args||e.stack)}let ip=!1;const ap=[];var op=class e{options;_lastLog;_mockFn;constructor(e={}){let t=e.types||Zf;this.options=tp({...e,defaults:{...e.defaults},level:sp(e.level,t),reporters:[...e.reporters||[]]},{types:Zf,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(let e in t){let n={type:e,...this.options.defaults,...t[e]};this[e]=this._wrapLogFn(n),this[e].raw=this._wrapLogFn(n,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(e){this.options.level=sp(e,this.options.types,this.options.level)}prompt(e,t){if(!this.options.prompt)throw Error(`prompt is not supported!`);return this.options.prompt(e,t)}create(t){let n=new e({...this.options,...t});return this._mockFn&&n.mockTypes(this._mockFn),n}withDefaults(e){return this.create({...this.options,defaults:{...this.options.defaults,...e}})}withTag(e){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+`:`+e:e})}addReporter(e){return this.options.reporters.push(e),this}removeReporter(e){if(e){let t=this.options.reporters.indexOf(e);if(t!==-1)return this.options.reporters.splice(t,1)}else this.options.reporters.splice(0);return this}setReporters(e){return this.options.reporters=Array.isArray(e)?e:[e],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(let e in this.options.types)console[`__`+e]||(console[`__`+e]=console[e]),console[e]=this[e].raw}restoreConsole(){for(let e in this.options.types)console[`__`+e]&&(console[e]=console[`__`+e],delete console[`__`+e])}wrapStd(){this._wrapStream(this.options.stdout,`log`),this._wrapStream(this.options.stderr,`log`)}_wrapStream(e,t){e&&(e.__write||=e.write,e.write=e=>{this[t].raw(String(e).trim())})}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(e){e&&e.__write&&(e.write=e.__write,delete e.__write)}pauseLogs(){ip=!0}resumeLogs(){ip=!1;let e=ap.splice(0);for(let t of e)t[0]._logFn(t[1],t[2])}mockTypes(e){let t=e||this.options.mockFn;if(this._mockFn=t,typeof t==`function`)for(let e in this.options.types)this[e]=t(e,this.options.types[e])||this[e],this[e].raw=this[e]}_wrapLogFn(e,t){return(...n)=>{if(ip){ap.push([this,e,n,t]);return}return this._logFn(e,n,t)}}_logFn(e,t,n){if((e.level||0)>this.level)return!1;let r={date:new Date,args:[],...e,level:sp(e.level,this.options.types)};!n&&t.length===1&&rp(t[0])?Object.assign(r,t[0]):r.args=[...t],r.message&&(r.args.unshift(r.message),delete r.message),r.additional&&(Array.isArray(r.additional)||(r.additional=r.additional.split(`
598
+ })()`);if(i.kind===`timeout`)throw i.sawAdapter?Error(`Kapture Storybook adapter did not become ready for ${t} (last state: ${i.lastState??`unknown`}).`):Error(`Kapture Storybook adapter was not found for ${t}. Install @kaptures/storybook and register kapture() in .storybook/preview.`);let a;try{a=cu(i.value)}catch(e){let t=e instanceof Error?e.message:String(e);throw Error(`${t}. Install matching versions of @kaptures/cli and @kaptures/storybook.`,{cause:e})}if(a.state===`error`){let e=a.error.kind===`configuration`?`configuration`:`lifecycle`;throw Error(`Kapture Storybook ${e} error for ${t}: ${a.error.message}`)}if(a.state!==`ready`||a.storyId!==t)throw Error(`Kapture Storybook returned invalid terminal state for ${t}`);if(a.adapterVersion!==n)throw Error(`Kapture adapter version mismatch for ${t}: CLI ${n}, Storybook ${a.adapterVersion}. Install matching exact versions of @kaptures/cli and @kaptures/storybook.`);return{adapterVersion:a.adapterVersion,generation:a.generation,parameters:a.parameters}}function Mu(e,t){return e.adapterVersion===t.adapterVersion&&e.generation===t.generation}async function Nu(e,t=zd){let n=e.workers??4;if(!Number.isInteger(n)||n<1||n>8)throw Error(`Kapture workers must be between 1 and 8`);let r=f(e.outputDir);await y(r),await y(c(r,`images`));let i=await yl(e.headDir);try{let a=au(await iu(i.url));if(!a.length)throw Error(`Initial adoption requires at least one story`);let[o,s]=await Promise.all([t.getBrowserVersion(),t.getFontsFingerprint()]),l=$c({browserVersion:o,fontsFingerprint:s,frozenTime:e.frozenTime,randomSeed:e.randomSeed,locale:e.locale,timezone:e.timezone}),u=c(r,`hermetic-init.js`);await w(u,al(l));let d=Iu(e.headRevision,l);if(await Fu({pairs:a.map(e=>({id:e.id,head:e})),requestedWorkers:n,namespace:`i-${process.pid.toString(36)}-${Date.now().toString(36)}`,initScriptPath:u,options:{...e,baseDir:e.headDir,baseRevision:e.headRevision},baseUrl:``,headUrl:i.url,baseOutput:r,headOutput:r,baseManifest:Iu(e.headRevision,l),headManifest:d,environment:l,captureBase:!1}),await Cl(c(r,`manifest.json`),d),!Object.keys(d.snapshots).length)throw Error(`Initial adoption requires at least one enabled snapshot`);return d}finally{await i.close()}}async function Pu(e,t=zd){let n=f(e.outputDir),r=c(n,`capture`,`base`),i=c(n,`capture`,`head`),a=c(n,`report`);await re(n,{recursive:!0,force:!0}),await Promise.all([y(c(r,`images`),{recursive:!0}),y(c(i,`images`),{recursive:!0}),y(a,{recursive:!0})]);let o=[];try{let s=await yl(e.baseDir);o.push(s);let l=await yl(e.headDir);o.push(l);let[u,d,f,p]=await Promise.all([iu(s.url),iu(l.url),kl(e.baseDir),kl(e.headDir)]),m=au(u),h=au(d),g=zu(m,h,e,{base:f.evidence,head:p.evidence}),_=Ru(m,h,g.selectedStoryIds),[v,ee]=_.length===0&&!e.baseCaptureDir?[`not-launched:no-affected-stories-v1`,`not-inspected:no-affected-stories-v1`]:await Promise.all([t.getBrowserVersion(),t.getFontsFingerprint()]),b=$c({browserVersion:v,fontsFingerprint:ee,frozenTime:e.frozenTime,randomSeed:e.randomSeed,locale:e.locale,timezone:e.timezone}),x=c(n,`hermetic-init.js`);await w(x,al(b));let te=`k-${process.pid.toString(36)}-${Date.now().toString(36)}`,S=e.baseCaptureDir?await Ju(e.baseCaptureDir,r,e.baseRevision,b,_):void 0;if(!S&&e.captureCacheDir&&_.length>0)try{let t=await Tl(e.baseDir,e.adapterVersion),n=await El(e.captureCacheDir,t),i=await Ju(e.captureCacheDir,r,n.revision,b,_,!0);for(let e of Object.values(i.manifest.snapshots))e.sourceRevision??=n.revision;i.manifest.revision=e.baseRevision,S=i}catch(e){console.warn(`Kapture capture cache miss: ${e instanceof Error?e.message:String(e)}`)}S&&(g.baseline={mode:`reused`,revision:S.manifest.revision,manifestDigest:S.manifestDigest});let ne=S?.manifest??Iu(e.baseRevision,b),C=Iu(e.headRevision,b),T=e.workers??4;if(!Number.isInteger(T)||T<1||T>8)throw Error(`Kapture workers must be between 1 and 8`);await Fu({pairs:_,requestedWorkers:T,namespace:te,initScriptPath:x,options:e,baseUrl:s.url,headUrl:l.url,baseOutput:r,headOutput:i,baseManifest:ne,headManifest:C,environment:b,captureBase:!S||!!e.captureCacheDir,cachedBaseStoryIds:S?new Set(Object.values(S.manifest.snapshots).map(e=>e.storyId)):void 0}),S&&await Yu({baseline:S.manifest,baselineRoot:S.root,headManifest:C,headOutput:i,selectedStoryIds:g.selectedStoryIds,removedStoryIds:g.removedStoryIds??[]}),await Promise.all([Cl(c(r,`manifest.json`),ne),Cl(c(i,`manifest.json`),C)]);let ie={...pd,...e.threshold},ae=c(n,`stability-candidates`),oe=await hl({baseManifest:ne,headManifest:C,baseRoot:r,headRoot:i,outputDir:ae,threshold:ie,coverage:g}),se=new Set(Object.values(oe.entries).filter(e=>e.status===`changed`).map(e=>e.id)),ce;if(se.size>0){let t=new Set(Object.values(oe.entries).filter(e=>se.has(e.id)).map(e=>e.storyId)),r=_.filter(e=>t.has(e.id)),i=c(n,`capture`,`base-repeat`),a=c(n,`capture`,`head-repeat`);await Promise.all([y(c(i,`images`),{recursive:!0}),y(c(a,`images`),{recursive:!0})]);let o=Iu(e.baseRevision,b),u=Iu(e.headRevision,b);await Fu({pairs:r,requestedWorkers:T,namespace:`${te}-s`,initScriptPath:x,options:e,baseUrl:s.url,headUrl:l.url,baseOutput:i,headOutput:a,baseManifest:o,headManifest:u,environment:b,captureBase:!0}),await Promise.all([Cl(c(i,`manifest.json`),o),Cl(c(a,`manifest.json`),u)]),ce={baseManifest:o,headManifest:u,baseRoot:i,headRoot:a}}await re(ae,{recursive:!0,force:!0});let le=await hl({baseManifest:ne,headManifest:C,baseRoot:r,headRoot:i,outputDir:a,threshold:ie,coverage:g,stability:ce});if(e.captureCacheOutput&&le.summary.errors===0&&le.summary.unstable===0)try{let t=await Tl(e.headDir,e.adapterVersion);await Dl(e.captureCacheOutput,i,t,C)}catch(e){console.warn(`Kapture capture cache export unavailable: ${e instanceof Error?e.message:String(e)}`)}return{baseManifest:ne,headManifest:C,report:le}}finally{await Promise.allSettled(o.map(e=>e.close()))}}async function Fu(e){let t=Math.min(e.requestedWorkers,e.pairs.length),n=e.captureBase&&e.pairs.some(t=>!!t.base&&!e.cachedBaseStoryIds?.has(t.id)),r=e.pairs.some(e=>!!e.head),i=[...e.pairs],a=[],o=[];try{for(let i=0;i<t;i+=1){let t={};n&&(t.base=Lu(i,`base`,e.options,{namespace:e.namespace,initScriptPath:e.initScriptPath,environment:e.environment}),o.push(t.base)),r&&(t.head=Lu(i,`head`,e.options,{namespace:e.namespace,initScriptPath:e.initScriptPath,environment:e.environment}),o.push(t.head)),a.push(t)}await Promise.all(a.map(async t=>{for(;i.length>0;){let n=i.shift();if(!n)return;await Wu({workers:t,pair:n,baseUrl:e.baseUrl,headUrl:e.headUrl,baseOutput:e.baseOutput,headOutput:e.headOutput,baseManifest:e.baseManifest,headManifest:e.headManifest,environment:e.environment,adapterVersion:e.options.adapterVersion,captureBase:e.captureBase&&!e.cachedBaseStoryIds?.has(n.id)})}}))}finally{await Promise.allSettled(o.map(e=>Promise.resolve().then(()=>e.close())))}}function Iu(e,t){return{version:2,revision:e,environment:t,createdAt:new Date().toISOString(),snapshots:{}}}function Lu(e,t,n,r){let i={...r,target:t};return n.workerFactory?n.workerFactory(e,i):new ud({id:`${r.namespace}-${t}-${e}`,namespace:r.namespace,initScriptPath:r.initScriptPath,timezone:r.environment.timezone,locale:r.environment.locale,deviceScaleFactor:r.environment.deviceScaleFactor,allowedDomains:r.environment.network.allowedDomains})}function Ru(e,t,n){let r=new Map(e.map(e=>[e.id,e])),i=new Map(t.map(e=>[e.id,e])),a=[...new Set([...r.keys(),...i.keys()])].sort(),o=n?[...new Set(n)].sort():a,s=new Set(a),c=o.filter(e=>!s.has(e));if(c.length>0)throw Error(`Unknown Kapture story IDs: ${c.join(`, `)}`);return o.map(e=>({id:e,base:r.get(e),head:i.get(e)}))}function zu(e,t,n,r){if(n.selectionPlan&&n.storyIds)throw Error(`Kapture selectionPlan and storyIds cannot be provided together`);let i=[...new Set([...e,...t].map(e=>e.id))].sort(),a=new Set(e.map(e=>e.id)),o=new Set(t.map(e=>e.id)),s=i.filter(e=>!a.has(e)&&o.has(e)),c=i.filter(e=>a.has(e)&&!o.has(e)),l=Bu(r,n.baseRevision,n.headRevision),u=n.selectionPlan;if(u){if(Uu(u.totalStoryIds,i,`selection plan catalog`),Uu(u.addedStoryIds,s,`selection plan added stories`),Uu(u.removedStoryIds,c,`selection plan removed stories`),Vu(u.dependencyManifests,r),Hu(u.selectedStoryIds,u.skippedStoryIds,i),u.selectionMode===`full-fallback`&&u.fallbackReasons.length===0)throw Error(`Kapture full-fallback selection plan requires a fallback reason`);if(u.selectionMode===`affected`&&u.fallbackReasons.length>0)throw Error(`Kapture affected selection plan cannot contain fallback reasons`);return{plannerVersion:1,mode:u.selectionMode,...u.changedFilesEvidence?{changedFilesEvidence:{...u.changedFilesEvidence}}:{},dependencyManifests:l,storyIds:i,selectedStoryIds:[...u.selectedStoryIds],skippedStoryIds:[...u.skippedStoryIds],addedStoryIds:s,removedStoryIds:c,fallbackReasons:u.fallbackReasons.map(e=>({...e}))}}if(n.storyIds){let e=[...new Set(n.storyIds)].sort(),t=new Set(i),r=e.filter(e=>!t.has(e));if(r.length>0)throw Error(`Unknown Kapture story IDs: ${r.join(`, `)}`);let a=new Set(e);return{plannerVersion:1,mode:`affected`,dependencyManifests:l,storyIds:i,selectedStoryIds:e,skippedStoryIds:i.filter(e=>!a.has(e)),addedStoryIds:s,removedStoryIds:c,fallbackReasons:[]}}return{plannerVersion:1,mode:`full`,dependencyManifests:l,storyIds:i,selectedStoryIds:i,skippedStoryIds:[],addedStoryIds:s,removedStoryIds:c,fallbackReasons:[]}}function Bu(e,t,n){return{base:{...e.base,revision:t},head:{...e.head,revision:n}}}function Vu(e,t){if(JSON.stringify(e)!==JSON.stringify(t))throw Error(`Kapture selection plan dependency manifests do not match the built Storybook artifacts`)}function Hu(e,t,n){Uu(e,[...new Set(e)].sort(),`selected stories`),Uu(t,[...new Set(t)].sort(),`skipped stories`);let r=new Set(e),i=[...e,...t].sort();if(t.some(e=>r.has(e)))throw Error(`Kapture selection plan cannot select and skip the same story`);Uu(i,n,`selection plan partition`)}function Uu(e,t,n){if(e.length!==t.length||e.some((e,n)=>e!==t[n]))throw Error(`Kapture ${n} does not match the built Storybook catalog`)}async function Wu(e){let t={base:Gu(!!e.pair.base&&e.captureBase),head:Gu(!!e.pair.head)},n=[];e.pair.base&&e.captureBase&&n.push(Ku(e,`base`,t)),e.pair.head&&n.push(Ku(e,`head`,t)),await Promise.all(n)}function Gu(e){if(!e)return{promise:Promise.resolve(void 0),resolve:()=>void 0};let t=()=>void 0,n=!1;return{promise:new Promise(e=>{t=e}),resolve(e){n||(n=!0,t(e))}}}async function Ku(e,t,n){let r=e.pair[t];if(!r)return;let i=e.workers[t];if(!i)throw Error(`Kapture ${t} browser worker was not initialized`);let a=t===`base`?e.baseManifest:e.headManifest,o=t===`base`?e.baseUrl:e.headUrl,s=t===`base`?e.baseOutput:e.headOutput,c=t===`base`?`head`:`base`;try{await i.runAttempt({target:t,storyId:r.id},async i=>{let l=await Xu(i,o,r,e.environment,e.adapterVersion).catch(rd);if(n[t].resolve(l),l instanceof Error){td(a,r,l);return}let u=await n[c].promise;if(u instanceof Error)return;let d=t===`base`?l.parameters:u?.parameters,f=t===`head`?l.parameters:u?.parameters,p=e.captureBase?Zu(d,f,!!e.pair.base,!!e.pair.head):qu(e.baseManifest,e.pair.id,f,!!e.pair.head);for(let n of p){let c=n[t];!c||l.parameters.captureEnabled===!1||await Qu({driver:i,story:r,baseUrl:o,outputRoot:s,manifest:a,viewport:c,parameters:l.parameters,captureArea:l.parameters.captureArea,threshold:$u(l.parameters.diff),adapterVersion:e.adapterVersion})}})}catch(e){let i=rd(e);n[t].resolve(i),nd(a,r,i)}}function qu(e,t,n,r=!0){let i=Object.values(e.snapshots).filter(e=>e.storyId===t).map(e=>e.viewport),a=!r||n?.captureEnabled===!1?[]:n?.captureViewports??[fd],o=new Map(i.map(e=>[e.name,e])),s=new Map(a.map(e=>[e.name,e]));return[...new Set([...o.keys(),...s.keys()])].sort().map(e=>({base:o.get(e),head:s.get(e)}))}async function Ju(e,t,n,r,i,a=!1){let o=f(e),s=c(o,`manifest.json`),l=await wl(s);if(l.revision!==n)throw Error(`Kapture baseline revision ${l.revision} does not match requested base ${n}`);nl(l.environment,r);let u=new Set(i.filter(e=>e.base).map(e=>e.id)),d={...l.snapshots};for(let e of u)if(!a&&!Object.values(d).some(t=>t.storyId===e))throw Error(`Kapture baseline does not contain selected base story ${e}`);return await Promise.all(Object.values(d).map(async e=>{if(e.error)return;let n=c(o,e.imageFile);if(await pl(n)!==e.sha256)throw Error(`Kapture baseline image digest mismatch for ${e.id}`);await g(n,c(t,e.imageFile))})),{root:t,manifest:{...l,snapshots:d},manifestDigest:await pl(s)}}async function Yu(e){let t=new Set(e.selectedStoryIds),n=new Set(e.removedStoryIds);await Promise.all(Object.values(e.baseline.snapshots).map(async r=>{t.has(r.storyId)||n.has(r.storyId)||(e.headManifest.snapshots[r.id]={...r,sourceRevision:r.sourceRevision??e.baseline.revision},!r.error&&await g(c(e.baselineRoot,r.imageFile),c(e.headOutput,r.imageFile)))}))}async function Xu(e,t,n,r,i){return await e.setViewport(fd),await e.setMedia(r.colorScheme,r.reducedMotion===`reduce`),await e.open(ou(t,n.id)),ju(e,n.id,i)}function Zu(e,t,n=!0,r=!0){let i=!n||e?.captureEnabled===!1?[]:e?.captureViewports??[fd],a=!r||t?.captureEnabled===!1?[]:t?.captureViewports??[fd],o=new Map(i.map(e=>[e.name,e])),s=new Map(a.map(e=>[e.name,e]));return[...new Set([...o.keys(),...s.keys()])].sort().map(e=>({base:o.get(e),head:s.get(e)}))}async function Qu(e){let{driver:t,story:n,baseUrl:r,outputRoot:i,manifest:a,viewport:o,parameters:s,captureArea:l,threshold:u,adapterVersion:f}=e,p=`${n.id}@${o.name}`,m=c(`images`,ml(p)),h=c(i,m),g=performance.now();try{await t.setViewport(o),await t.setMedia(a.environment.colorScheme,a.environment.reducedMotion===`reduce`),await t.open(ou(r,n.id));let e=await ju(t,n.id,f);ed(e,s,n.id);let c;for(let r=1;r<=3;r+=1){c=await Jc(t,a.environment,e.parameters);let i=await ju(t,n.id,f);if(ed(i,s,n.id),Mu(e,i))break;if(r===3)throw Error(`Kapture story ${n.id} kept rerendering while the capture was stabilizing`);e=i,c=void 0}if(!c)throw Error(`Kapture could not stabilize ${n.id}`);await t.screenshot(h,{fullPage:l!==`viewport`}),a.snapshots[p]={id:p,storyId:n.id,title:n.title,name:n.name,viewport:o,imageFile:d(i,h),sha256:await pl(h),capturedAt:new Date().toISOString(),durationMs:Math.round(performance.now()-g),ignoredRegions:c.ignoredRegions.length>0?c.ignoredRegions:void 0,threshold:u}}catch(e){a.snapshots[p]={id:p,storyId:n.id,title:n.title,name:n.name,viewport:o,imageFile:m,sha256:``,capturedAt:new Date().toISOString(),durationMs:Math.round(performance.now()-g),threshold:u,error:e instanceof Error?e.message:String(e)}}}function $u(e){if(e)return{...e.pixelColorThreshold===void 0?{}:{pixelColorThreshold:e.pixelColorThreshold},...e.maxChangedPixelPercentage===void 0?{}:{maxChangedPixelRatio:e.maxChangedPixelPercentage/100}}}function ed(e,t,n){if(JSON.stringify(e.parameters)!==JSON.stringify(t))throw Error(`Kapture parameters changed between metadata and capture for ${n}`)}function td(e,t,n){let r=`${t.id}@metadata`;e.snapshots[r]={id:r,storyId:t.id,title:t.title,name:t.name,viewport:fd,imageFile:``,sha256:``,capturedAt:new Date().toISOString(),durationMs:0,error:n.message}}function nd(e,t,n){let r=`${t.id}@attempt`;e.snapshots[r]={id:r,storyId:t.id,title:t.title,name:t.name,viewport:fd,imageFile:``,sha256:``,capturedAt:new Date().toISOString(),durationMs:0,error:n.message}}function rd(e){return e instanceof Error?e:Error(String(e))}async function id(e,t){if(!(await C(e)).isDirectory())throw Error(`Dashboard build is not a directory: ${e}`);await _(e,t,{recursive:!0,force:!0});let n=f(t,`index.html`),r=f(t,`report.json`),[i,a]=await Promise.all([x(n,`utf8`),x(r,`utf8`)]),o=ad(i,/<link\b[^>]*\brel=["']stylesheet["'][^>]*\bhref=["']([^"']+)["'][^>]*>/i,`stylesheet`),s=ad(i,/<script\b[^>]*\bsrc=["']([^"']+)["'][^>]*><\/script>/i,`module script`),[c,l]=await Promise.all([od(t,o.url),od(t,s.url)]),u=sd(c,o.url),d=`<script id="kapture-report-data" type="application/json">${a.trim().replaceAll(`<`,`\\u003c`)}<\/script>\n<script data-kapture-dashboard>"use strict";\n${l.replace(/<\/script/gi,`<\\/script`)}<\/script>`,p=i.replace(o.tag,()=>`<style>${u}</style>`).replace(s.tag,``);if(!p.includes(`</body>`))throw Error(`Dashboard index is missing its closing body tag`);let m=p.replace(`</body>`,()=>`${d}\n</body>`);await w(n,m)}function ad(e,t,n){let r=e.match(t);if(!r?.[1])throw Error(`Dashboard index is missing its ${n}`);return{tag:r[0],url:r[1]}}async function od(e,t){if(/^[a-z]+:/i.test(t)||t.startsWith(`/`)||t.includes(`?`))throw Error(`Dashboard asset must be a relative local path: ${t}`);let n=f(e),r=f(n,t);if(!r.startsWith(`${n}${p}`))throw Error(`Dashboard asset resolves outside the report directory: ${t}`);return x(r,`utf8`)}function sd(e,t){let n=u.dirname(t);return e.replace(/url\((["']?)(\.\/[^"')]+)\1\)/g,(e,t,r)=>{let i=u.join(n,r);return`url(${t}${i.startsWith(`.`)?i:`./${i}`}${t})`})}var cd,ld,ud,dd,fd,pd,md,hd,gd,_d,vd,yd,bd,xd,Sd,Cd,wd,Td,Ed,Dd,Od,kd,Ad,jd,Md,Nd,Pd,Fd,Id,Ld,Rd,zd,Bd=E((()=>{Et(),cd=Jt(),Uc(),ld=class{session;isolation=`browser-process`;namespace;initScriptPath;timezone;locale;deviceScaleFactor;allowedDomains;timeoutMs;bin;commandStarted=!1;closePromise;constructor(e){this.session=e.session,this.namespace=e.namespace,this.initScriptPath=e.initScriptPath,this.timezone=e.timezone,this.locale=e.locale,this.deviceScaleFactor=e.deviceScaleFactor,this.allowedDomains=e.allowedDomains,this.timeoutMs=e.timeoutMs??3e4,this.bin=qc()}open(e){return this.execVoid([`open`,e])}setViewport(e){return this.execVoid([`set`,`viewport`,String(e.width),String(e.height)])}setMedia(e,t){let n=[`set`,`media`,e];return t&&n.push(`reduced-motion`),this.execVoid(n)}async evaluate(e){let t=await this.exec([`eval`,e]),n=JSON.parse(t);if(n.success===!1)throw Error(n.error??`agent-browser eval failed`);return n.data&&typeof n.data==`object`&&`result`in n.data?n.data.result:n.data===void 0?n.result===void 0?n:n.result:n.data}screenshot(e,t){return this.execVoid([`screenshot`,...t.fullPage?[`--full`]:[],e])}close(){return this.closePromise?this.closePromise:this.commandStarted?(this.closePromise=this.execVoid([`close`],!0),this.closePromise):(this.closePromise=Promise.resolve(),this.closePromise)}async execVoid(e,t=!1){let n=await this.exec(e,t);try{let t=JSON.parse(n);if(t.success===!1)throw Error(t.error??`agent-browser command failed: ${e.join(` `)}`)}catch(e){if(e instanceof SyntaxError)return;throw e}}exec(e,t=!1){if(this.closePromise&&!t)return Promise.reject(Error(`agent-browser session ${this.session} is closed`));t||(this.commandStarted=!0);let n=[`--session`,this.session,`--namespace`,this.namespace,`--init-script`,this.initScriptPath,`--allowed-domains`,this.allowedDomains.join(`,`),`--args`,`--force-device-scale-factor=${this.deviceScaleFactor},--lang=${this.locale}`,`--json`,...e];return new Promise((t,i)=>{let a=r(this.bin,n,{env:{...process.env,LANG:`${this.locale}.UTF-8`,TZ:this.timezone},stdio:[`ignore`,`pipe`,`pipe`]}),o=[],s=[];a.stdout.on(`data`,e=>o.push(e)),a.stderr.on(`data`,e=>s.push(e));let c=setTimeout(()=>{a.kill(),i(Error(`agent-browser timed out after ${this.timeoutMs}ms: ${e.join(` `)}`))},this.timeoutMs);a.once(`error`,e=>{clearTimeout(c),i(e)}),a.once(`close`,e=>{clearTimeout(c);let n=Buffer.concat(o).toString(`utf8`).trim(),r=Buffer.concat(s).toString(`utf8`).trim();if(e!==0){i(Error(`agent-browser failed (${e}): ${r||n}`));return}t(n)})})}},ud=class{id;options;attemptFactory;sessionPrefix;attemptNumber=0;activeAttempt;closed=!1;constructor(e,t=e=>new ld(e)){this.id=e.id,this.sessionPrefix=`kw-${T(`sha256`).update(e.id).digest(`hex`).slice(0,8)}`;let{id:n,...r}=e;this.options=r,this.attemptFactory=t}async runAttempt(e,t){if(this.closed)throw Error(`Browser worker ${this.id} is closed`);if(this.activeAttempt)throw Error(`Browser worker ${this.id} already has an active attempt`);let n=++this.attemptNumber,r=new dd(e,this.attemptFactory({...this.options,session:`${this.sessionPrefix}-${e.target[0]}-${n.toString(36)}`}));this.activeAttempt=r;let i,a,o=!1;try{i=await t(r)}catch(e){o=!0,a=e}let s,c=!1;try{await r.close()}catch(e){c=!0,s=e}finally{this.activeAttempt===r&&(this.activeAttempt=void 0)}if(o&&c)throw AggregateError([a,s],`Browser attempt ${r.session} failed and could not be closed`);if(o)throw a;if(c)throw s;return i}async close(){if(this.closed)return;this.closed=!0;let e=this.activeAttempt;e&&(await e.close(),this.activeAttempt===e&&(this.activeAttempt=void 0))}},dd=class{scope;driver;isolation=`browser-process`;closePromise;constructor(e,t){this.scope=e,this.driver=t}get session(){return this.driver.session}open(e){return this.driver.open(e)}setViewport(e){return this.driver.setViewport(e)}setMedia(e,t){return this.driver.setMedia(e,t)}evaluate(e){return this.driver.evaluate(e)}screenshot(e,t){return this.driver.screenshot(e,t)}close(){return this.closePromise??=this.driver.close(),this.closePromise}},fd={name:`default`,width:1280,height:800},pd={pixelColorThreshold:.2,maxChangedPixelRatio:0},md=[`baseImage`,`headImage`,`diffImage`],hd=/^[0-9a-f]{64}$/,gd={".css":`text/css; charset=utf-8`,".html":`text/html; charset=utf-8`,".ico":`image/x-icon`,".jpeg":`image/jpeg`,".jpg":`image/jpeg`,".js":`text/javascript; charset=utf-8`,".json":`application/json; charset=utf-8`,".mjs":`text/javascript; charset=utf-8`,".png":`image/png`,".svg":`image/svg+xml`,".woff":`font/woff`,".woff2":`font/woff2`},_d=V({name:z(),width:B(),height:B()}),vd=V({id:z(),browser:z(),browserVersion:z(),orchestratorRuntime:z(),operatingSystem:z(),architecture:z(),deviceScaleFactor:B(),locale:z(),timezone:z(),colorScheme:Is([`light`,`dark`]),reducedMotion:Is([`reduce`,`no-preference`]),frozenTime:z(),randomSeed:B(),fontsFingerprint:z(),stateIsolation:H(`fresh-browser-process-per-story-side-v1`).optional(),network:V({mode:H(`allowlist`),allowedDomains:As(z()),webRtc:H(`disabled`)})}),yd=V({id:z(),storyId:z(),title:z(),name:z(),viewport:_d,imageFile:z(),sha256:z(),capturedAt:z(),durationMs:B(),sourceRevision:z().optional(),ignoredRegions:As(V({x:B().int().nonnegative(),y:B().int().nonnegative(),width:B().int().positive(),height:B().int().positive()})).optional(),threshold:V({pixelColorThreshold:B().optional(),maxChangedPixelRatio:B().optional()}).optional(),error:z().optional()}).superRefine((e,t)=>{e.error||(/^images\/[A-Za-z0-9._-]+\.png$/.test(e.imageFile)||t.addIssue({code:`custom`,path:[`imageFile`],message:`must be a safe image path`}),/^[0-9a-f]{64}$/.test(e.sha256)||t.addIssue({code:`custom`,path:[`sha256`],message:`must be a SHA-256 digest`}))}),bd=V({version:H(2),revision:z(),environment:vd,createdAt:z(),snapshots:Fs(z(),yd)}),xd=V({version:H(1),buildDigest:z().regex(/^[a-f0-9]{64}$/),manifestDigest:z().regex(/^[a-f0-9]{64}$/)}),Sd=`kapture-dependencies.json`,Cd=z().min(1).max(4096).refine(Fl,`must be a normalized project-relative path`),wd=z().max(4096).refine(e=>e===``||Fl(e),{message:`must be empty or a normalized project-relative path`}),Td=As(Cd).max(1e5).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),Ed=z().regex(/^[0-9a-f]{64}$/),Dd=js({type:Is([`asset`,`chunk`]),size:B().int().nonnegative().max(1e9),sha256:Ed}).strict(),Od=z().max(4096).refine(e=>e===``||e.endsWith(`/`)&&Fl(e.slice(0,-1)),`must be empty or a normalized project-relative directory prefix`),kd=z().min(1).max(1024),Ad=As(kd).max(1e4).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),jd=Fs(Cd,Fs(Cd,Ad)),Md=Fs(Cd,Fs(kd,js({module:Cd,imported:kd}).strict())),Nd=js({kind:H(`kapture-storybook-dependencies`),version:H(1),complete:Ds(),storybookRoot:wd,globalInputs:Td,ignoredInputs:Td,fingerprintedInputs:Td.optional(),diagnostics:As(Is([`module-outside-project-root`,`module-fingerprint-missing`,`unresolved-virtual-module`,`unresolved-project-module`,`rendered-output-fingerprint-missing`,`global-output-fingerprint-missing`,`global-runtime-fingerprint-missing`,`unowned-output-chunk`,`output-inventory-mismatch`])).max(20).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),modules:Fs(Cd,Td),moduleFingerprints:Fs(Cd,Ed).optional(),globalOutputFingerprints:Fs(Cd,Ed),globalOutputStories:Fs(Cd,Td),globalRuntimeFingerprint:Ed,outputInventory:Fs(Cd,Dd),outputInventoryPrefixes:As(Od).max(100).refine(e=>new Set(e).size===e.length,`must not contain duplicates`),importBindings:jd.optional(),reexportBindings:Md.optional(),renderedModules:Fs(Cd,Td),renderedOutputFingerprints:Fs(Cd,Ed)}).strict().superRefine((e,t)=>{let n=Object.entries(e.modules),r=new Set(n.map(([e])=>e));n.length>1e5&&t.addIssue({code:`custom`,path:[`modules`],message:`contains too many modules`});for(let[i,a]of n)a.includes(i)||t.addIssue({code:`custom`,path:[`modules`,i],message:`must include the module itself`}),e.complete&&a.some(e=>!r.has(e))&&t.addIssue({code:`custom`,path:[`modules`,i],message:`must resolve every project dependency when the manifest is complete`});Object.keys(e.globalOutputFingerprints).length>1e5&&t.addIssue({code:`custom`,path:[`globalOutputFingerprints`],message:`contains too many global output fingerprints`});let i=new Set(Object.keys(e.globalOutputFingerprints)),a=Object.entries(e.globalOutputStories);a.length>1e5&&t.addIssue({code:`custom`,path:[`globalOutputStories`],message:`contains too many global output story lists`});for(let[e,n]of a){i.has(e)||t.addIssue({code:`custom`,path:[`globalOutputStories`,e],message:`must identify a fingerprinted global output`});for(let i of n)if(!r.has(i)){t.addIssue({code:`custom`,path:[`globalOutputStories`,e],message:`must contain only rendered story modules`});break}}for(let n of i)n in e.globalOutputStories||t.addIssue({code:`custom`,path:[`globalOutputStories`,n],message:`must cover every fingerprinted global output`});let o=Object.entries(e.outputInventory);o.length>1e5&&t.addIssue({code:`custom`,path:[`outputInventory`],message:`contains too many output files`}),`kapture-dependencies.json`in e.outputInventory&&t.addIssue({code:`custom`,path:[`outputInventory`,Sd],message:`must not inventory the manifest itself`});for(let n of e.outputInventoryPrefixes)o.some(([e])=>e.startsWith(n))||t.addIssue({code:`custom`,path:[`outputInventoryPrefixes`],message:`must cover at least one inventoried output`});let s=Object.entries(e.moduleFingerprints??{});s.length>1e5&&t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`contains too many module fingerprints`});for(let[e]of s)r.has(e)||t.addIssue({code:`custom`,path:[`moduleFingerprints`,e],message:`must identify a rendered module`});(e.fingerprintedInputs?.length??0)>0&&(e.moduleFingerprints?e.complete&&n.some(([t])=>!e.moduleFingerprints?.[t])&&t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`must cover every rendered module when the manifest is complete`}):t.addIssue({code:`custom`,path:[`moduleFingerprints`],message:`is required when fingerprintedInputs are configured`}));let c=0;for(let[n,i]of Object.entries(e.importBindings??{})){c+=Object.keys(i).length,r.has(n)||t.addIssue({code:`custom`,path:[`importBindings`,n],message:`must identify a rendered importer`});for(let r of Object.keys(i))e.modules[n]?.includes(r)||t.addIssue({code:`custom`,path:[`importBindings`,n,r],message:`must identify a direct project dependency`})}for(let[n,i]of Object.entries(e.reexportBindings??{})){c+=Object.keys(i).length,r.has(n)||t.addIssue({code:`custom`,path:[`reexportBindings`,n],message:`must identify a rendered barrel`});for(let[r,a]of Object.entries(i))e.modules[n]?.includes(a.module)||t.addIssue({code:`custom`,path:[`reexportBindings`,n,r],message:`must identify a direct project dependency`})}c>1e6&&t.addIssue({code:`custom`,path:[`importBindings`],message:`contains too many import and re-export bindings`});let l=Object.entries(e.renderedModules??{});l.length>1e5&&t.addIssue({code:`custom`,path:[`renderedModules`],message:`contains too many rendered module closures`});let u=0;for(let[e,n]of l){u+=n.length,r.has(e)||t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must identify a rendered entry module`}),n.includes(e)||t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must include the entry module itself`});for(let i of n)if(!r.has(i)){t.addIssue({code:`custom`,path:[`renderedModules`,e],message:`must contain only rendered project modules`});break}}u>5e6&&t.addIssue({code:`custom`,path:[`renderedModules`],message:`contains too many rendered module references`});let d=Object.entries(e.renderedOutputFingerprints);d.length>1e5&&t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`],message:`contains too many rendered output fingerprints`});for(let[e]of d)r.has(e)||t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`,e],message:`must identify a rendered entry module`});e.complete&&l.some(([t])=>e.renderedOutputFingerprints[t]===void 0)&&t.addIssue({code:`custom`,path:[`renderedOutputFingerprints`],message:`must cover every rendered entry module when the manifest is complete`}),e.complete!==(e.diagnostics.length===0)&&t.addIssue({code:`custom`,path:[`complete`],message:`must agree with diagnostics`})}),Pd=1e3,Fd=js({id:z().min(1),type:Is([`story`,`docs`]),importPath:z().min(1).optional()}).passthrough(),Id=js({entries:Fs(z(),Fd)}).passthrough(),Ld=js({id:z().min(1),title:z(),name:z(),type:Is([`story`,`docs`])}),Rd=js({v:B(),entries:Fs(z(),Ld)}),zd={getBrowserVersion:Wc,getFontsFingerprint:rl}}));Bd();function Vd(e){let t=e.trim().match(/^\/kapture[ \t]+approve[ \t]+([0-9a-f]{40})[ \t]+([0-9a-f]{64})(?:[ \t]+(--allow-unstable)(?:[ \t]+([^\r\n]+))?)?$/i);if(!t?.[1]||!t[2])return null;let n=t[4]?.trim()||void 0;return Hd(n)?{headSha:t[1].toLowerCase(),reportDigest:t[2].toLowerCase(),...t[3]?{mode:`allow-unstable`,reason:n}:{mode:`standard`}}:null}function Hd(e){return e===void 0||typeof e==`string`&&e.length<=1e3&&Array.from(e).every(e=>{let t=e.charCodeAt(0);return t>31&&t!==127})&&e.trim()!==`<reason>`}function Ud(e){let t=`/kapture approve ${e.headSha} ${e.reportDigest}`;return e.mode===`standard`?t:[t,`--allow-unstable`,e.reason?.trim()].filter(Boolean).join(` `)}const Wd={executionErrors:e=>`❌ **${e} execution error(s)** must be fixed.`,clean:`✅ No visual changes.`,changes:e=>`🔍 **${e} visual change(s)** require review.`,unstableWarning:e=>`⚠️ **${e} screen(s) could not be verified.** Capturing the same code again produced different images, so we cannot tell which differences came from your code changes. Fix the inconsistent rendering and rerun. Ordinary visual approval cannot bypass this check.`,comparison:(e,t)=>`**${e} stories · ${t} snapshots compared**`,coverage:(e,t,n,r,i,a)=>e===`affected`?`**${n} of ${t} affected stories selected · ${r} stories / ${i} snapshots compared · ${a} proven unaffected**`:`**${n} stories selected · ${r} stories / ${i} snapshots compared**`,fallback:e=>`- Safe full-capture fallback: ${e.join(`, `)}`,counts:e=>`- Unchanged ${e.unchanged} · Changed ${e.changed} · Unstable ${e.unstable} · Added ${e.added} · Removed ${e.removed} · Errors ${e.errors}`,branch:`Branch`,environment:`Environment`,reportDownload:`Download the full comparison report`,reportOpen:`Open the full comparison report`,storyOpen:`Open captured story`,sections:{error:`🚨 Execution errors`,removed:`⚠️ Removed snapshots`,changed:`🔍 Visual changes`,unstable:`⚠️ Unstable snapshots`,added:`➕ Added snapshots`},hidden:e=>`${e} more item(s) are available in the full comparison report.`,errorAdvice:`⚠️ Capture or comparison errors must be fixed before approval.`,approvalPrompt:`A reviewer with write permission can approve the full head build with:`,unstableApprovalPrompt:`A reviewer with write permission may accept the instability for this entire report with an explicit exception. Optionally append a reason (one line, up to 1000 characters). The unstable evidence remains unchanged:`,unstableApproval:(e,t,n)=>`⚠️ @${e} accepted an unstable exception for Kapture report \`${t}\`.${n?`\n\nReason: ${n}`:``}\n\nThis accepts the entire report, including visual changes. Instability evidence is preserved; this does not prove reproducibility.`,captureError:`Capture or comparison failed.`,removedEntry:`Not found in the head Storybook`,addedEntry:`New snapshot`,approval:(e,t)=>`✅ @${e} approved Kapture report \`${t.slice(0,12)}\`.`},Gd={executionErrors:e=>`❌ **${e}개의 실행 오류**를 해결해 주세요.`,clean:`✅ 시각적 변경이 없습니다.`,changes:e=>`🔍 **${e}개의 시각적 변경**을 검토해 주세요.`,unstableWarning:e=>`⚠️ **${e}개 화면의 검증을 통과하지 못했어요.** 같은 코드로 화면을 다시 찍었는데 결과가 달라졌어요. 코드 변경으로 생긴 차이를 확인할 수 없으니, 화면이 달라지는 원인을 수정한 뒤 다시 실행해 주세요. 일반 시각 변경 승인으로는 이 검증을 통과시킬 수 없어요.`,comparison:(e,t)=>`**${e}개 스토리 · ${t}개 스냅샷 비교**`,coverage:(e,t,n,r,i,a)=>e===`affected`?`**전체 ${t}개 Story 중 영향받은 ${n}개 선택 · ${r}개 Story / ${i}개 스냅샷 비교 · ${a}개는 dependency graph로 제외**`:`**${n}개 Story 선택 · ${r}개 Story / ${i}개 스냅샷 비교**`,fallback:e=>`- 누락 방지를 위해 전체 캡처로 전환: ${e.join(`, `)}`,counts:e=>`- 동일 ${e.unchanged} · 변경 ${e.changed} · 불안정 ${e.unstable} · 추가 ${e.added} · 삭제 ${e.removed} · 오류 ${e.errors}`,branch:`브랜치`,environment:`환경`,reportDownload:`전체 비교 리포트 다운로드`,reportOpen:`전체 비교 리포트 열기`,storyOpen:`캡처한 Story 열기`,sections:{error:`🚨 실행 오류`,removed:`⚠️ 삭제된 스냅샷`,changed:`🔍 시각 변경`,unstable:`⚠️ 불안정한 스냅샷`,added:`➕ 추가된 스냅샷`},hidden:e=>`그 외 ${e}개 항목은 전체 비교 리포트에서 확인해 주세요.`,errorAdvice:`⚠️ 캡처 또는 비교 오류를 해결해야 합니다. 승인할 수 없습니다.`,approvalPrompt:`전체 head 빌드를 승인하려면 쓰기 권한이 있는 리뷰어가 다음 명령을 남겨 주세요.`,unstableApprovalPrompt:`쓰기 권한이 있는 리뷰어는 불안정성을 인지한 상태에서 전체 리포트를 예외 승인할 수 있어요. 사유는 선택이며 명령 뒤에 덧붙일 수 있어요(한 줄, 최대 1000자). 불안정 증거는 그대로 유지됩니다.`,unstableApproval:(e,t,n)=>`⚠️ @${e} 님이 Kapture 리포트 \`${t}\`의 불안정을 예외 승인했습니다.${n?`\n\n사유: ${n}`:``}\n\n시각 변경을 포함한 전체 리포트에 대한 승인입니다. 불안정 증거는 유지되며, 재현성 검증을 통과했다는 뜻은 아닙니다.`,captureError:`캡처 또는 비교에 실패했습니다.`,removedEntry:`head Storybook에서 찾을 수 없음`,addedEntry:`새 스냅샷`,approval:(e,t)=>`✅ @${e} 님이 Kapture 리포트 \`${t.slice(0,12)}\`를 승인했습니다.`};function Kd(e){if(e===`en`||e===`ko`)return e;throw Error(`Comment language must be en or ko`)}function qd(e){return e===`ko`?Gd:Wd}const Jd=`<!-- kapture-report:`,Yd={error:0,removed:1,changed:2,unstable:3,added:4,unchanged:5};function Xd(e){return e.contentDigest??sl(e)}function Zd(e){return`${Jd}${Buffer.from(JSON.stringify(e)).toString(`base64url`)} -->`}function Qd(e){let t=e.indexOf(Jd);if(t<0)return null;let n=t+20,r=e.indexOf(` -->`,n);if(r<0)return null;try{let t=JSON.parse(Buffer.from(e.slice(n,r),`base64url`).toString());return t.version!==4||!ef(t.baseSha)||!ef(t.headSha)||!/^[0-9a-f]{64}$/.test(t.digest)||!pf(t.captureRunId)||!pf(t.captureRunAttempt)||!pf(t.captureWorkflowId)||!mf(t.captureRunHeadBranch)||!pf(t.captureRunHeadRepositoryId)||![`clean`,`changed`,`unstable`,`error`].includes(t.status)||t.reportUrl!==void 0&&tf(t.reportUrl)!==t.reportUrl?null:t}catch{return null}}function $d(e,t,n=`Kapture Visual Review`,r=`en`){let{summary:i}=e,a=i.changed+i.added+i.removed,o=new Set(Object.values(e.entries).map(e=>e.storyId)).size,s=cf(n,100),c=qd(r),l=[Zd(t),`## ${s}`,``,i.errors>0?c.executionErrors(i.errors):i.unstable>0?c.unstableWarning(i.unstable):a===0?c.clean:c.changes(a),``,e.coverage?c.coverage(e.coverage.mode,e.coverage.storyIds.length,e.coverage.selectedStoryIds.length,o,i.total,e.coverage.skippedStoryIds.length):c.comparison(o,i.total),``,c.counts(i),`- ${c.branch} \`${uf(t.captureRunHeadBranch)}\` · ${c.environment} \`${uf(e.environment.id)}\` · base \`${ff(e.baseRevision)}\` → head \`${ff(e.headRevision)}\``];if(e.coverage?.mode===`full-fallback`&&l.push(c.fallback([...new Set(e.coverage.fallbackReasons.map(e=>e.code))])),i.unstable>0&&i.errors>0&&l.push(``,c.unstableWarning(i.unstable)),t.reportUrl){let e=df(t.reportUrl)?c.reportDownload:c.reportOpen;l.push(``,`[${e}](${t.reportUrl})`)}let u=Object.values(e.entries).filter(e=>e.status!==`unchanged`).sort(sf),d=u.slice(0,20);for(let n of[`error`,`removed`,`changed`,`unstable`,`added`]){let r=u.filter(e=>e.status===n),i=d.filter(e=>e.status===n);if(i.length!==0){l.push(``,`### ${c.sections[n]} (${r.length})`,``);for(let n of i)l.push(af(n,c,e.storybookUrl,t.reportUrl))}}let f=u.length-d.length;return f>0&&l.push(``,c.hidden(f)),i.errors>0?l.push(``,c.errorAdvice):i.unstable>0?l.push(``,c.unstableApprovalPrompt,``,`\`${Ud({headSha:e.headRevision,reportDigest:t.digest,mode:`allow-unstable`})}\``):a>0&&i.unstable===0&&l.push(``,c.approvalPrompt,``,`\`${Ud({headSha:e.headRevision,reportDigest:t.digest,mode:`standard`})}\``),`${l.join(`
599
+ `)}\n`}function ef(e){return/^[0-9a-f]{40}$/i.test(e)}function tf(e){if(!e)return;if(e.length>2048)throw Error(`Report URL is too long`);let t;try{t=new URL(e)}catch{throw Error(`Report URL must be a valid HTTPS URL`)}if(t.protocol!==`https:`||t.username||t.password)throw Error(`Report URL must be an HTTPS URL without credentials`);return t.toString().replace(/\(/g,`%28`).replace(/\)/g,`%29`).replace(/\[/g,`%5B`).replace(/\]/g,`%5D`)}function nf(e){if(e){if(e===`./storybook/`)return e;try{return tf(e)}catch{throw Error(`Storybook URL must be a valid HTTPS URL or ./storybook/`)}}}function rf(e){let t=lf(e).replace(/\s+/g,` `).trim();if(!t||t.length>100)throw Error(`Status context must contain between 1 and 100 characters`);return t}function af(e,t,n,r){let i=`**${cf(e.title)} / ${cf(e.name)}** · ${cf(e.viewport.name)}`,a=n?of(n,e.storyId,r):void 0,o=a?` · [${t.storyOpen}](${a})`:``;return e.status===`error`?`- ${i} — ${cf(e.error??t.captureError,180)}${o}`:e.status===`removed`?`- ${i} — ${t.removedEntry}`:e.status===`added`?`- ${i} — ${t.addedEntry}${o}`:`- ${i}${o}`}function of(e,t,n){if(e===`./storybook/`&&!n)return;let r=new URL(e,n);return r.searchParams.set(`path`,`/story/${t}`),tf(r.toString())}function sf(e,t){let n=Yd[e.status]-Yd[t.status];return n===0?`${e.title}/${e.name}/${e.viewport.name}`.localeCompare(`${t.title}/${t.name}/${t.viewport.name}`):n}function cf(e,t=240){let n=lf(e).replace(/\s+/g,` `).trim();return(n.length>t?`${n.slice(0,t-3)}...`:n).replace(/&/g,`&amp;`).replace(/</g,`&lt;`).replace(/>/g,`&gt;`).replace(/\\/g,`\\\\`).replace(/([`*_[\]{}|])/g,`\\$1`).replace(/@/g,`@​`)}function lf(e){return Array.from(e,e=>{let t=e.codePointAt(0)??0;return t<=31||t===127?` `:e}).join(``)}function uf(e){return e.replace(/`/g,`ˋ`).replace(/[\r\n]/g,` `).replace(/@/g,`@​`)}function df(e){return e.includes(`/actions/runs/`)&&e.includes(`/artifacts/`)}function ff(e){return e.slice(0,8)}function pf(e){return typeof e==`number`&&Number.isInteger(e)&&e>0}function mf(e){return typeof e!=`string`||e.length<1||e.length>512?!1:Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127})}async function hf(e,t,n){if(!Number.isSafeInteger(t)||t<=0)throw Error(`Download byte limit must be positive`);let r=e.headers.get(`content-length`);if(r!==null){let i=Number(r);if(!Number.isSafeInteger(i)||i<0||i>t)throw await e.body?.cancel().catch(()=>{}),Error(`${n} exceeds the ${t} byte download limit`)}if(!e.body)throw Error(`${n} download returned no body`);let i=e.body.getReader(),a=[],o=0;try{for(;;){let{done:e,value:r}=await i.read();if(e)break;if(o+=r.byteLength,o>t)throw await i.cancel().catch(()=>{}),Error(`${n} exceeds the ${t} byte download limit`);a.push(Buffer.from(r))}}finally{i.releaseLock()}if(o<1)throw Error(`${n} download is empty`);return Buffer.concat(a,o)}var gf=E((()=>{}));gf();var _f=class{#e;#t;#n;constructor(e,t,n=fetch){if(!e)throw Error(`GITHUB_TOKEN is required`);this.#e=e,this.#t=t,this.#n=n}async getWorkflowRun(e){return yf(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}`))}async listWorkflowRuns(e,t){return Mf(e=>this.#i(`GET`,`${this.#r()}${e}`),e,t)}async listRunArtifacts(e){let t=[];for(let n=1;n<=10;n+=1){let r=new URLSearchParams({per_page:`100`,page:String(n)}),i=Tf(G(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}/artifacts?${r}`),`artifacts response`).artifacts,`artifacts`).map(xf);if(t.push(...i),i.length<100)return t}throw Error(`GitHub returned more than 1000 workflow artifacts`)}async getArtifact(e){let t=await this.#o(`GET`,`${this.#r()}/actions/artifacts/${e}`);return t.status===404?null:(await vf(t,`GET`,`/actions/artifacts/${e}`),xf(await t.json()))}async listCaptureCacheArtifacts(e){let t=new URLSearchParams({name:e,per_page:`10`});return Tf(G(await this.#i(`GET`,`${this.#r()}/actions/artifacts?${t}`),`cache artifacts`).artifacts,`artifacts`).map(xf)}async isMergedCaptureRun(e,t){let n=Tf(G(await this.#i(`GET`,`${this.#r()}/actions/runs/${e}`),`capture run`).pull_requests,`pull_requests`);n.length===0&&/^[a-f0-9]{40}$/.test(t)&&(n=Tf(await this.#i(`GET`,`${this.#r()}/commits/${t}/pulls?per_page=5`),`associated pull requests`));for(let e of n.slice(0,5)){let n=G(e,`pull request`).number;if(!Number.isSafeInteger(n)||Number(n)<=0)continue;let r=G(await this.#i(`GET`,`${this.#r()}/pulls/${n}`),`pull request`);if(r.merged===!0&&G(r.head,`head`).sha===t)return!0}return!1}async downloadArtifactArchive(e,t){if(!Number.isSafeInteger(t)||t<=0)throw Error(`Artifact download byte limit must be positive`);let n=await this.#o(`GET`,`${this.#r()}/actions/artifacts/${e}/zip`,`manual`),r=await this.#a(n,e);return await vf(r,`GET`,`/actions/artifacts/${e}/zip`),hf(r,t,`Artifact ${e}`)}async deleteArtifact(e){let t=await this.#o(`DELETE`,`${this.#r()}/actions/artifacts/${e}`);t.status!==404&&await vf(t,`DELETE`,`/actions/artifacts/${e}`)}async getPullRequest(e){return Sf(await this.#i(`GET`,`${this.#r()}/pulls/${e}`))}async listOpenPullRequestsForHead(e,t,n){let r=wf(e),i=[];for(let e=1;e<=10;e+=1){let a=new URLSearchParams({state:`open`,base:n,head:`${r.owner}:${t}`,per_page:`100`,page:String(e)}),o=Tf(await this.#i(`GET`,`${this.#r()}/pulls?${a}`),`pull requests response`).map(Sf);if(i.push(...o),o.length<100)return i}throw Error(`GitHub returned more than 1000 matching pull requests`)}async getContentSha(e,t,n){let r=wf(e),i=t.split(`/`).map(encodeURIComponent).join(`/`),a=new URLSearchParams({ref:n});return Af(G(await this.#i(`GET`,`/repos/${encodeURIComponent(r.owner)}/${encodeURIComponent(r.repo)}/contents/${i}?${a}`),`contents response`).sha,`contents SHA`)}#r(){let{owner:e,repo:t}=this.#t;return`/repos/${encodeURIComponent(e)}/${encodeURIComponent(t)}`}async#i(e,t){let n=await this.#o(e,t);return await vf(n,e,t),n.json()}async#a(e,t){if(e.status<300||e.status>399)return e;let n=e.headers.get(`location`);if(!n)throw Error(`Artifact ${t} redirect is missing its location`);let r;try{r=new URL(n)}catch{throw Error(`Artifact ${t} redirect location is invalid`)}if(r.protocol!==`https:`||r.username||r.password)throw Error(`Artifact ${t} redirect must be a credential-free HTTPS URL`);return this.#n(r,{method:`GET`,headers:{Accept:`application/octet-stream`,"User-Agent":`kapture-cli`},redirect:`follow`})}#o(e,t,n=`follow`){return this.#n(`https://api.github.com${t}`,{method:e,headers:{Accept:`application/vnd.github+json`,Authorization:`Bearer ${this.#e}`,"X-GitHub-Api-Version":`2022-11-28`,"User-Agent":`kapture-cli`},redirect:n})}};async function vf(e,t,n){if(!e.ok)throw Error(`GitHub API ${t} ${n} failed with status ${e.status}`)}function yf(e){let t=G(e,`workflow run`);return{id:Ef(t.id,`workflow run ID`),runNumber:Ef(t.run_number,`workflow run number`),runAttempt:Ef(t.run_attempt,`workflow run attempt`),workflowId:Ef(t.workflow_id,`workflow ID`),path:Df(t.path,`workflow path`),status:Df(t.status,`workflow run status`),conclusion:Of(t.conclusion,`workflow run conclusion`),event:Df(t.event,`workflow run event`),headSha:Af(t.head_sha,`workflow run head SHA`),headBranch:Df(t.head_branch,`workflow run head branch`),headRepository:Cf(t.head_repository,`workflow run head repository`),repository:Cf(t.repository,`workflow run repository`)}}function bf(e){let t=G(e,`workflow run candidate`);return{id:Ef(t.id,`workflow run ID`),runNumber:Ef(t.run_number,`workflow run number`),headRepositoryId:Ef(G(t.head_repository,`workflow run head repository`).id,`workflow run head repository ID`)}}function xf(e){let t=G(e,`workflow artifact`),n=G(t.workflow_run,`artifact workflow run`);return{id:Ef(t.id,`artifact ID`),name:Df(t.name,`artifact name`),sizeInBytes:Ef(t.size_in_bytes,`artifact size`),digest:jf(t.digest,`artifact digest`),expired:kf(t.expired,`artifact expired`),workflowRun:{id:Ef(n.id,`artifact workflow run ID`),repositoryId:Ef(n.repository_id,`artifact workflow repository ID`),headRepositoryId:Ef(n.head_repository_id,`artifact workflow head repository ID`),headBranch:Df(n.head_branch,`artifact workflow head branch`),headSha:Af(n.head_sha,`artifact workflow head SHA`)}}}function Sf(e){let t=G(e,`pull request`),n=G(t.base,`pull request base`),r=G(t.head,`pull request head`),i=Df(t.state,`pull request state`);if(i!==`open`&&i!==`closed`)throw Error(`Pull request state is invalid`);return{number:Ef(t.number,`pull request number`),state:i,base:{ref:Df(n.ref,`pull request base ref`),sha:Af(n.sha,`pull request base SHA`),repository:Cf(n.repo,`pull request base repository`)},head:{ref:Df(r.ref,`pull request head ref`),sha:Af(r.sha,`pull request head SHA`),repository:Cf(r.repo,`pull request head repository`)}}}function Cf(e,t){let n=G(e,t),r=Df(n.full_name,`${t} full name`);return wf(r),{id:Ef(n.id,`${t} ID`),fullName:r}}function wf(e){let t=e.match(/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);if(!t?.[1]||!t[2])throw Error(`Repository full name is invalid`);return{owner:t[1],repo:t[2]}}function G(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function Tf(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}function Ef(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function Df(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);for(let n of e){let e=n.codePointAt(0)??0;if(e<=31||e===127)throw Error(`${t} contains control characters`)}return e}function Of(e,t){return e===null?null:Df(e,t)}function kf(e,t){if(typeof e!=`boolean`)throw Error(`${t} must be a boolean`);return e}function Af(e,t){if(typeof e!=`string`||!/^[0-9a-f]{40}$/.test(e))throw Error(`${t} must be a lowercase full SHA`);return e}function jf(e,t){if(typeof e!=`string`||!/^sha256:[0-9a-f]{64}$/.test(e))throw Error(`${t} must be a SHA-256 digest`);return e}async function Mf(e,t,n){let r=[];for(let i=1;i<=10;i+=1){let a=Tf(G(await e(`/actions/workflows/${t}/runs?${new URLSearchParams({event:`pull_request`,branch:n,per_page:`100`,page:String(i)})}`),`workflow runs response`).workflow_runs,`workflow_runs`).map(bf);if(r.push(...a),a.length<100)return r}throw Error(`GitHub returned more than 1000 workflow runs`)}var Nf=class{#e;#t;#n;constructor(e,t){if(!e)throw Error(`GITHUB_TOKEN is required`);this.#e=e,this.#t=t,this.#n=Pf(process.env.GITHUB_API_URL)}async setReviewStatus(e,t,n,r,i){await this.#i(`POST`,`/statuses/${encodeURIComponent(e)}`,{state:t,description:n.slice(0,140),context:r,target_url:i})}async postOrUpdateReportComment(e,t,n=Jd){let r=(await this.#r(e)).find(e=>e.user?.login===`github-actions[bot]`&&e.body?.includes(n));return r?(await this.#i(`PATCH`,`/issues/comments/${r.id}`,{body:t})).id:this.createIssueComment(e,t)}async findCurrentReportMarker(e,t,n){let r=await this.#r(e);for(let e of r.reverse()){if(e.user?.login!==`github-actions[bot]`||!e.body)continue;let r=Qd(e.body);if(r?.baseSha===t&&r.headSha===n)return r}return null}async assertCurrentCaptureRun(e,t,n,r,i){let a=yf(await this.#i(`GET`,`/actions/runs/${e}`));if(a.id!==e||a.runAttempt!==t||a.workflowId!==n||a.headBranch!==r||a.headRepository.id!==i||a.status!==`completed`||a.conclusion!==`success`||a.event!==`pull_request`)throw Error(`Kapture report does not belong to the current successful capture run`);if(!await vt({listWorkflowRuns:(e,t)=>Mf(e=>this.#i(`GET`,e),e,t)},a))throw Error(`A newer Kapture capture run exists for this pull request`)}async getLatestReviewStatus(e,t){for(let n=1;n<=10;n+=1){let r=await this.#i(`GET`,`/commits/${encodeURIComponent(e)}/status?per_page=100&page=${n}`),i=r.statuses.find(e=>e.context===t);if(i)return Ff(i.state)?{state:i.state,description:i.description??void 0,targetUrl:i.target_url??void 0}:null;if(r.statuses.length<100)break}return null}async assertWritePermission(e){let t=await this.#i(`GET`,`/collaborators/${encodeURIComponent(e)}/permission`);if(!t.permission||![`admin`,`maintain`,`write`].includes(t.permission))throw Error(`@${e} does not have write permission for this repository`)}async getPullRequest(e){return this.#i(`GET`,`/pulls/${e}`)}async readPackageManifest(e,t){if(!/^[0-9a-f]{40}$/.test(t)||!/^[A-Za-z0-9._/-]+$/.test(e)||e.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Package manifest requires a project-relative path and exact revision`);let n=await this.#i(`GET`,`/contents/${e.split(`/`).map(encodeURIComponent).join(`/`)}?ref=${t}`);if(n.type!==`file`||n.encoding!==`base64`||typeof n.content!=`string`||!Number.isSafeInteger(n.size)||n.size<0||n.size>1048576||n.content.length>2097152)throw Error(`Expected a bounded package.json file at the exact base revision`);return JSON.parse(Buffer.from(n.content,`base64`).toString(`utf8`))}async getPullRequestForCapture(e){return this.#i(`GET`,`/pulls/${e}`)}async listPullRequestFilesPage(e,t,n){return this.#i(`GET`,`/pulls/${e}/files?per_page=${n}&page=${t}`)}async createIssueComment(e,t){return(await this.#i(`POST`,`/issues/${e}/comments`,{body:t})).id}async#r(e){let t=[];for(let n=1;n<=10;n+=1){let r=await this.#i(`GET`,`/issues/${e}/comments?per_page=100&page=${n}`);if(t.push(...r),r.length<100)break}return t}async#i(e,t,n){let{owner:r,repo:i}=this.#t,a=`/repos/${encodeURIComponent(r)}/${encodeURIComponent(i)}${t}`,o=await fetch(`${this.#n}${a}`,{method:e,headers:{Accept:`application/vnd.github+json`,Authorization:`Bearer ${this.#e}`,"X-GitHub-Api-Version":`2022-11-28`,"User-Agent":`kapture-cli`,...n?{"Content-Type":`application/json`}:{}},body:n?JSON.stringify(n):void 0});if(!o.ok)throw Error(`GitHub API ${e} ${t} failed with status ${o.status}${await ht(o,this.#e)}`);return await o.json()}};function Pf(e){let t=e?.trim()||`https://api.github.com`,n;try{n=new URL(t)}catch{throw Error(`GITHUB_API_URL must be a valid absolute URL`)}let r=[`127.0.0.1`,`localhost`,`[::1]`].includes(n.hostname);if(n.protocol!==`https:`&&!(n.protocol===`http:`&&r))throw Error(`GITHUB_API_URL must use HTTPS (HTTP is allowed only for loopback tests)`);if(n.username||n.password||n.search||n.hash)throw Error(`GITHUB_API_URL must not contain credentials, a query, or a fragment`);return n.toString().replace(/\/+$/,``)}function Ff(e){return[`error`,`failure`,`pending`,`success`].includes(e)}async function If(){let e=process.env.GITHUB_EVENT_PATH;if(!e)throw Error(`GITHUB_EVENT_PATH is required`);let t=await C(e);if(!t.isFile()||t.size>10485760)throw Error(`GitHub event payload is missing or too large`);try{return JSON.parse(await x(e,`utf8`))}catch{throw Error(`GITHUB_EVENT_PATH does not contain valid JSON`)}}function Lf(e){let t=Wf(e,`GitHub event payload`);if(t.action!==`completed`)throw Error(`Kapture report requires a completed normalized event`);let n=Wf(t.kapture,`kapture normalized event`);if(n.schemaVersion!==1)throw Error(`Kapture report requires normalized event schemaVersion 1`);let r=Wf(n.pullRequest,`kapture.pullRequest`),i=Wf(n.captureRun,`kapture.captureRun`),a=Bf(r.headSha,`kapture.pullRequest.headSha`),o=Hf(i.headBranch);if(!Uf(o))throw Error(`kapture.captureRun.headBranch is invalid`);return{repository:zf(t),issueNumber:Vf(r.number,`pull request number`),headSha:a,captureRunId:Vf(i.id,`capture run ID`),captureRunAttempt:Vf(i.attempt,`capture run attempt`),captureWorkflowId:Vf(i.workflowId,`capture workflow ID`),captureRunHeadBranch:o,captureRunHeadRepositoryId:Vf(i.headRepositoryId,`capture run head repository ID`)}}function Rf(e){let t=Wf(e,`GitHub event payload`);if(t.action!==`created`)throw Error(`Kapture approval only accepts newly created issue comments`);let n=Wf(t.issue,`issue`);if(!n.pull_request)throw Error(`Kapture approval must be posted on a pull request`);let r=Vd(Hf(Wf(t.comment,`comment`).body));if(!r)throw Error(`Expected /kapture approve <full-head-sha> <64-character-report-digest> [--allow-unstable [reason]]; an optional reason must be one line, at most 1000 characters`);let i=Hf(Wf(t.sender,`sender`).login);if(!/^[A-Za-z0-9](?:[A-Za-z0-9-]{0,38})$/.test(i))throw Error(`GitHub event contains an invalid sender login`);return{repository:zf(t),issueNumber:Vf(n.number,`pull request number`),...r,sender:i}}function zf(e){let t=Hf(Wf(Wf(e,`GitHub event payload`).repository,`repository`).full_name).match(/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/);if(!t?.[1]||!t[2])throw Error(`GitHub event contains an invalid repository`);return{owner:t[1],repo:t[2]}}function Bf(e,t){let n=Hf(e).toLowerCase();if(!ef(n))throw Error(`${t} must be a full 40-character SHA`);return n}function Vf(e,t){if(typeof e!=`number`||!Number.isInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function Hf(e){if(typeof e!=`string`)throw Error(`GitHub event contains an invalid string value`);return e}function Uf(e){return e.length<1||e.length>512?!1:Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127})}function Wf(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}const Gf={standard:{reportStatus:`changed`,state:`pending`,description:`Visual changes require approval`,approvedPrefix:`Approved by @`},"allow-unstable":{reportStatus:`unstable`,state:`failure`,description:`Unstable snapshots require exception approval`,approvedPrefix:`Unstable exception approved by @`}};function Kf(e){return Object.values(Gf).find(t=>t.reportStatus===e)}function qf(e,t){let n=Gf[t].approvedPrefix;return e.state===`success`&&e.description?.startsWith(n)===!0&&/^[A-Za-z0-9][A-Za-z0-9-]{0,38}$/.test(e.description.slice(n.length))}const Jf=`Publishing verified visual report`;async function Yf(e,t,n){let r=Zf(n.baseRevision,`Report base`),i=Zf(n.headRevision,`Report head`);if(i!==t.headSha)throw Error(`Report head ${n.headRevision} does not match workflow head ${t.headSha}`);let a=await e.getPullRequest(t.issueNumber);if(a.number!==t.issueNumber)throw Error(`GitHub returned PR #${a.number} instead of requested PR #${t.issueNumber}`);if(a.state!==`open`)throw Error(`Pull request #${t.issueNumber} is not open`);let o=Zf(a.head.sha,`Current PR head`),s=Zf(a.base.sha,`Current PR base`);if(o!==i)throw Error(`Report head ${n.headRevision} is stale; current PR head is ${a.head.sha}`);if(s!==r)throw Error(`Report base ${n.baseRevision} is stale; current PR base is ${a.base.sha}`);return a}async function Xf(e,t,n,r,i,a=`en`){if(await Yf(e,t,n),!n.contentDigest)throw Error("GitHub report publishing requires an image-bound contentDigest; run `kapture report build` first");let o=Xd(n),s=n.summary.changed+n.summary.added+n.summary.removed,c=n.summary.errors>0?`error`:n.summary.unstable>0?`unstable`:s>0?`changed`:`clean`,l={version:4,baseSha:n.baseRevision.toLowerCase(),headSha:n.headRevision.toLowerCase(),digest:o,captureRunId:t.captureRunId,captureRunAttempt:t.captureRunAttempt,captureWorkflowId:t.captureWorkflowId,captureRunHeadBranch:t.captureRunHeadBranch,captureRunHeadRepositoryId:t.captureRunHeadRepositoryId,status:c,reportUrl:i},u=Kf(c),d=u?.state??(c===`error`?`failure`:`success`),f=u?.description??(c===`error`?`${n.summary.errors} visual capture error(s)`:`No visual changes`);await e.assertCurrentCaptureRun(t.captureRunId,t.captureRunAttempt,t.captureWorkflowId,t.captureRunHeadBranch,t.captureRunHeadRepositoryId),await e.setReviewStatus(t.headSha,`pending`,Jf,r,i);let p=await e.postOrUpdateReportComment(t.issueNumber,$d(n,l,r,a));await Yf(e,t,n),await e.assertCurrentCaptureRun(t.captureRunId,t.captureRunAttempt,t.captureWorkflowId,t.captureRunHeadBranch,t.captureRunHeadRepositoryId);let m=await e.getLatestReviewStatus(t.headSha,r);if(!m||m.state!==`pending`||m.description!==Jf||m.targetUrl!==i)throw Error(`Kapture status changed while the report was being published; retry report`);return await e.setReviewStatus(t.headSha,d,f,r,i),{status:c,changedCount:s,commentId:p,reportDigest:o}}function Zf(e,t){if(!ef(e))throw Error(`${t} ${e} must be a full 40-character SHA`);return e.toLowerCase()}async function Qf(e,t,n,r=`en`){if(t.mode===`allow-unstable`&&!Hd(t.reason))throw Error(`An optional exception reason must be one line and at most 1000 characters`);await e.assertWritePermission(t.sender);let i=await e.getPullRequest(t.issueNumber);if(i.number!==t.issueNumber)throw Error(`GitHub returned PR #${i.number} instead of requested PR #${t.issueNumber}`);if(i.state!==`open`)throw Error(`Pull request #${t.issueNumber} is not open`);let a=Zf(i.base.sha,`Current PR base`),o=Zf(i.head.sha,`Current PR head`);if(o!==t.headSha)throw Error(`Approval SHA ${t.headSha} is stale; current PR head is ${i.head.sha}`);let s=await e.findCurrentReportMarker(t.issueNumber,a,o);if(!s)throw Error(`No Kapture report exists for current base ${a} and head ${o}`);let c=Gf[t.mode];if(s.version!==4||s.status!==c.reportStatus)throw Error(`Kapture report for ${t.headSha} is not eligible for approval (${s.status})`);if(s.digest!==t.reportDigest)throw Error(`Approval digest ${t.reportDigest} does not match current report ${s.digest}`);await e.assertCurrentCaptureRun(s.captureRunId,s.captureRunAttempt,s.captureWorkflowId,s.captureRunHeadBranch,s.captureRunHeadRepositoryId);let l=await e.getLatestReviewStatus(o,n);if(!l||l.state!==c.state||l.description!==c.description||l.targetUrl!==s.reportUrl)throw Error(`Current Kapture status is not awaiting approval for this report`);await e.createIssueComment(t.issueNumber,t.mode===`allow-unstable`?qd(r).unstableApproval(t.sender,s.digest,cf(t.reason?.trim()??``,1e3)):qd(r).approval(t.sender,s.digest));let u=await e.findCurrentReportMarker(t.issueNumber,a,o);if(!u||u.digest!==t.reportDigest||u.status!==c.reportStatus||u.captureRunId!==s.captureRunId||u.captureRunAttempt!==s.captureRunAttempt||u.captureWorkflowId!==s.captureWorkflowId||u.captureRunHeadBranch!==s.captureRunHeadBranch||u.captureRunHeadRepositoryId!==s.captureRunHeadRepositoryId||u.reportUrl!==s.reportUrl)throw Error(`Kapture report changed while approval was being applied; retry approval`);await e.assertCurrentCaptureRun(s.captureRunId,s.captureRunAttempt,s.captureWorkflowId,s.captureRunHeadBranch,s.captureRunHeadRepositoryId);let d=await e.getLatestReviewStatus(o,n);if(!d||d.state!==c.state||d.description!==c.description||d.targetUrl!==s.reportUrl)throw Error(`Current Kapture status changed while approval was being applied; retry approval`);let f=await e.getPullRequest(t.issueNumber);if(f.number!==t.issueNumber||f.state!==`open`||Zf(f.base.sha,`Current PR base`)!==a||Zf(f.head.sha,`Current PR head`)!==o)throw Error(`Pull request changed while approval was being applied; retry approval`);return await e.setReviewStatus(t.headSha,`success`,`${c.approvedPrefix}${t.sender}`,n,s.reportUrl),{status:`approved`,reportDigest:s.digest}}async function K(e){let t=process.env.GITHUB_OUTPUT;if(!t)return;let n=[];for(let[t,r]of Object.entries(e)){let e=String(r),i=`kapture_${ie()}`;n.push(`${t}<<${i}\n${e}\n${i}\n`)}await h(t,n.join(``),`utf8`)}A();const $f=k({meta:{name:`approve`,description:`Approve the current full-SHA Kapture report`},args:{"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`Approval comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=Rf(await If()),r=await Qf(new Nf(t,n.repository),n,rf(e[`status-context`]),Kd(e[`comment-language`]));await K({status:r.status,"report-digest":r.reportDigest})}catch(e){throw await K({status:`error`}),e}}}),q={silent:-1/0,fatal:0,error:0,warn:1,log:2,info:3,success:3,fail:3,ready:3,start:3,box:3,debug:4,trace:5,verbose:1/0},ep={silent:{level:-1},fatal:{level:q.fatal},error:{level:q.error},warn:{level:q.warn},log:{level:q.log},info:{level:q.info},success:{level:q.success},fail:{level:q.fail},ready:{level:q.info},start:{level:q.info},box:{level:q.info},debug:{level:q.debug},trace:{level:q.trace},verbose:{level:q.verbose}};function tp(e){if(typeof e!=`object`||!e)return!1;let t=Object.getPrototypeOf(e);return t!==null&&t!==Object.prototype&&Object.getPrototypeOf(t)!==null||Symbol.iterator in e?!1:Symbol.toStringTag in e?Object.prototype.toString.call(e)===`[object Module]`:!0}function np(e,t,n=`.`,r){if(!tp(t))return np(e,{},n,r);let i=Object.assign({},t);for(let t in e){if(t===`__proto__`||t===`constructor`)continue;let a=e[t];a!=null&&(r&&r(i,t,a,n)||(i[t]=Array.isArray(a)&&Array.isArray(i[t])?[...a,...i[t]]:tp(a)&&tp(i[t])?np(a,i[t],(n?`${n}.`:``)+t.toString(),r):a))}return i}function rp(e){return(...t)=>t.reduce((t,n)=>np(t,n,``,e),{})}const ip=rp();function ap(e){return Object.prototype.toString.call(e)===`[object Object]`}function op(e){return!(!ap(e)||!e.message&&!e.args||e.stack)}let sp=!1;const cp=[];var lp=class e{options;_lastLog;_mockFn;constructor(e={}){let t=e.types||ep;this.options=ip({...e,defaults:{...e.defaults},level:up(e.level,t),reporters:[...e.reporters||[]]},{types:ep,throttle:1e3,throttleMin:5,formatOptions:{date:!0,colors:!1,compact:!0}});for(let e in t){let n={type:e,...this.options.defaults,...t[e]};this[e]=this._wrapLogFn(n),this[e].raw=this._wrapLogFn(n,!0)}this.options.mockFn&&this.mockTypes(),this._lastLog={}}get level(){return this.options.level}set level(e){this.options.level=up(e,this.options.types,this.options.level)}prompt(e,t){if(!this.options.prompt)throw Error(`prompt is not supported!`);return this.options.prompt(e,t)}create(t){let n=new e({...this.options,...t});return this._mockFn&&n.mockTypes(this._mockFn),n}withDefaults(e){return this.create({...this.options,defaults:{...this.options.defaults,...e}})}withTag(e){return this.withDefaults({tag:this.options.defaults.tag?this.options.defaults.tag+`:`+e:e})}addReporter(e){return this.options.reporters.push(e),this}removeReporter(e){if(e){let t=this.options.reporters.indexOf(e);if(t!==-1)return this.options.reporters.splice(t,1)}else this.options.reporters.splice(0);return this}setReporters(e){return this.options.reporters=Array.isArray(e)?e:[e],this}wrapAll(){this.wrapConsole(),this.wrapStd()}restoreAll(){this.restoreConsole(),this.restoreStd()}wrapConsole(){for(let e in this.options.types)console[`__`+e]||(console[`__`+e]=console[e]),console[e]=this[e].raw}restoreConsole(){for(let e in this.options.types)console[`__`+e]&&(console[e]=console[`__`+e],delete console[`__`+e])}wrapStd(){this._wrapStream(this.options.stdout,`log`),this._wrapStream(this.options.stderr,`log`)}_wrapStream(e,t){e&&(e.__write||=e.write,e.write=e=>{this[t].raw(String(e).trim())})}restoreStd(){this._restoreStream(this.options.stdout),this._restoreStream(this.options.stderr)}_restoreStream(e){e&&e.__write&&(e.write=e.__write,delete e.__write)}pauseLogs(){sp=!0}resumeLogs(){sp=!1;let e=cp.splice(0);for(let t of e)t[0]._logFn(t[1],t[2])}mockTypes(e){let t=e||this.options.mockFn;if(this._mockFn=t,typeof t==`function`)for(let e in this.options.types)this[e]=t(e,this.options.types[e])||this[e],this[e].raw=this[e]}_wrapLogFn(e,t){return(...n)=>{if(sp){cp.push([this,e,n,t]);return}return this._logFn(e,n,t)}}_logFn(e,t,n){if((e.level||0)>this.level)return!1;let r={date:new Date,args:[],...e,level:up(e.level,this.options.types)};!n&&t.length===1&&op(t[0])?Object.assign(r,t[0]):r.args=[...t],r.message&&(r.args.unshift(r.message),delete r.message),r.additional&&(Array.isArray(r.additional)||(r.additional=r.additional.split(`
600
600
  `)),r.args.push(`
601
601
  `+r.additional.join(`
602
- `)),delete r.additional),r.type=typeof r.type==`string`?r.type.toLowerCase():`log`,r.tag=typeof r.tag==`string`?r.tag:``;let i=(e=!1)=>{let t=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&t>0){let e=[...this._lastLog.object.args];t>1&&e.push(`(repeated ${t} times)`),this._log({...this._lastLog.object,args:e}),this._lastLog.count=1}e&&(this._lastLog.object=r,this._log(r))};clearTimeout(this._lastLog.timeout);let a=this._lastLog.time&&r.date?r.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=r.date,a<this.options.throttle)try{let e=JSON.stringify([r.type,r.tag,r.args]),t=this._lastLog.serialized===e;if(this._lastLog.serialized=e,t&&(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin)){this._lastLog.timeout=setTimeout(i,this.options.throttle);return}}catch{}i(!0)}_log(e){for(let t of this.options.reporters)t.log(e,{options:this.options})}};function sp(e,t={},n=3){return e===void 0?n:typeof e==`number`?e:t[e]&&t[e].level!==void 0?t[e].level:n}op.prototype.add=op.prototype.addReporter,op.prototype.remove=op.prototype.removeReporter,op.prototype.clear=op.prototype.removeReporter,op.prototype.withScope=op.prototype.withTag,op.prototype.mock=op.prototype.mockTypes,op.prototype.pause=op.prototype.pauseLogs,op.prototype.resume=op.prototype.resumeLogs;function cp(e={}){return new op(e)}function lp(e,t){let n=process.cwd()+p;return e.split(`
602
+ `)),delete r.additional),r.type=typeof r.type==`string`?r.type.toLowerCase():`log`,r.tag=typeof r.tag==`string`?r.tag:``;let i=(e=!1)=>{let t=(this._lastLog.count||0)-this.options.throttleMin;if(this._lastLog.object&&t>0){let e=[...this._lastLog.object.args];t>1&&e.push(`(repeated ${t} times)`),this._log({...this._lastLog.object,args:e}),this._lastLog.count=1}e&&(this._lastLog.object=r,this._log(r))};clearTimeout(this._lastLog.timeout);let a=this._lastLog.time&&r.date?r.date.getTime()-this._lastLog.time.getTime():0;if(this._lastLog.time=r.date,a<this.options.throttle)try{let e=JSON.stringify([r.type,r.tag,r.args]),t=this._lastLog.serialized===e;if(this._lastLog.serialized=e,t&&(this._lastLog.count=(this._lastLog.count||0)+1,this._lastLog.count>this.options.throttleMin)){this._lastLog.timeout=setTimeout(i,this.options.throttle);return}}catch{}i(!0)}_log(e){for(let t of this.options.reporters)t.log(e,{options:this.options})}};function up(e,t={},n=3){return e===void 0?n:typeof e==`number`?e:t[e]&&t[e].level!==void 0?t[e].level:n}lp.prototype.add=lp.prototype.addReporter,lp.prototype.remove=lp.prototype.removeReporter,lp.prototype.clear=lp.prototype.removeReporter,lp.prototype.withScope=lp.prototype.withTag,lp.prototype.mock=lp.prototype.mockTypes,lp.prototype.pause=lp.prototype.pauseLogs,lp.prototype.resume=lp.prototype.resumeLogs;function dp(e={}){return new lp(e)}function fp(e,t){let n=process.cwd()+p;return e.split(`
603
603
  `).splice(t.split(`
604
- `).length).map(e=>e.trim().replace(`file://`,``).replace(n,``))}function up(e,t){return(t.__write||t.write).call(t,e)}const dp=e=>e?`[${e}]`:``;var fp=class{formatStack(e,t,n){let r=` `.repeat((n?.errorLevel||0)+1);return r+lp(e,t).join(`
604
+ `).length).map(e=>e.trim().replace(`file://`,``).replace(n,``))}function pp(e,t){return(t.__write||t.write).call(t,e)}const mp=e=>e?`[${e}]`:``;var hp=class{formatStack(e,t,n){let r=` `.repeat((n?.errorLevel||0)+1);return r+fp(e,t).join(`
605
605
  ${r}`)}formatError(e,n){let r=e.message??t(n,e),i=e.stack?this.formatStack(e.stack,r,n):``,a=n?.errorLevel||0,o=a>0?`${` `.repeat(a)}[cause]: `:``,s=e.cause?`
606
606
 
607
607
  `+this.formatError(e.cause,{...n,errorLevel:a+1}):``;return o+r+`
608
608
  `+i+s}formatArgs(e,n){let r=e.map(e=>e&&typeof e.stack==`string`?this.formatError(e,n):e);return t(n,...r)}formatDate(e,t){return t.date?e.toLocaleTimeString():``}filterAndJoin(e){return e.filter(Boolean).join(` `)}formatLogObj(e,t){let n=this.formatArgs(e.args,t);return e.type===`box`?`
609
- `+[dp(e.tag),e.title&&e.title,...n.split(`
609
+ `+[mp(e.tag),e.title&&e.title,...n.split(`
610
610
  `)].filter(Boolean).map(e=>` > `+e).join(`
611
611
  `)+`
612
- `:this.filterAndJoin([dp(e.type),dp(e.tag),n])}log(e,t){return up(this.formatLogObj(e,{columns:t.options.stdout.columns||0,...t.options.formatOptions})+`
613
- `,e.level<2?t.options.stderr||process.stderr:t.options.stdout||process.stdout)}};const{env:pp={},argv:mp=[],platform:hp=``}=typeof process>`u`?{}:process,gp=`NO_COLOR`in pp||mp.includes(`--no-color`),_p=`FORCE_COLOR`in pp||mp.includes(`--color`),vp=hp===`win32`,yp=pp.TERM===`dumb`,bp=ge&&ge.isatty&&ge.isatty(1)&&pp.TERM&&!yp,xp=`CI`in pp&&(`GITHUB_ACTIONS`in pp||`GITLAB_CI`in pp||`CIRCLECI`in pp),Sp=!gp&&(_p||vp&&!yp||bp||xp);function Cp(e,t,n,r,i=t.slice(0,Math.max(0,e))+r,a=t.slice(Math.max(0,e+n.length)),o=a.indexOf(n)){return i+(o<0?a:Cp(o,a,n,r))}function wp(e,t,n,r,i){return e<0?n+t+r:n+Cp(e,t,r,i)+r}function Tp(e,t,n=e,r=e.length+1){return i=>i||i!==``&&i!==void 0?wp((``+i).indexOf(t,r),i,e,t,n):``}function q(e,t,n){return Tp(`\x1B[${e}m`,`\x1B[${t}m`,n)}const Ep={reset:q(0,0),bold:q(1,22,`\x1B[22m\x1B[1m`),dim:q(2,22,`\x1B[22m\x1B[2m`),italic:q(3,23),underline:q(4,24),inverse:q(7,27),hidden:q(8,28),strikethrough:q(9,29),black:q(30,39),red:q(31,39),green:q(32,39),yellow:q(33,39),blue:q(34,39),magenta:q(35,39),cyan:q(36,39),white:q(37,39),gray:q(90,39),bgBlack:q(40,49),bgRed:q(41,49),bgGreen:q(42,49),bgYellow:q(43,49),bgBlue:q(44,49),bgMagenta:q(45,49),bgCyan:q(46,49),bgWhite:q(47,49),blackBright:q(90,39),redBright:q(91,39),greenBright:q(92,39),yellowBright:q(93,39),blueBright:q(94,39),magentaBright:q(95,39),cyanBright:q(96,39),whiteBright:q(97,39),bgBlackBright:q(100,49),bgRedBright:q(101,49),bgGreenBright:q(102,49),bgYellowBright:q(103,49),bgBlueBright:q(104,49),bgMagentaBright:q(105,49),bgCyanBright:q(106,49),bgWhiteBright:q(107,49)};function Dp(e=Sp){return e?Ep:Object.fromEntries(Object.keys(Ep).map(e=>[e,String]))}const Op=Dp();function kp(e,t=`reset`){return Op[e]||Op[t]}const Ap=[String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);function jp(e){return e.replace(new RegExp(Ap,`g`),``)}const Mp={solid:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},doubleSingle:{tl:`╓`,tr:`╖`,bl:`╙`,br:`╜`,h:`─`,v:`║`},doubleSingleRounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`║`},singleThick:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},singleDouble:{tl:`╒`,tr:`╕`,bl:`╘`,br:`╛`,h:`═`,v:`│`},singleDoubleRounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`═`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`}},Np={borderColor:`white`,borderStyle:`rounded`,valign:`center`,padding:2,marginLeft:1,marginTop:1,marginBottom:1};function Pp(e,t={}){let n={...t,style:{...Np,...t.style}},r=e.split(`
614
- `),i=[],a=kp(n.style.borderColor),o={...typeof n.style.borderStyle==`string`?Mp[n.style.borderStyle]||Mp.solid:n.style.borderStyle};if(a)for(let e in o)o[e]=a(o[e]);let s=n.style.padding%2==0?n.style.padding:n.style.padding+1,c=r.length+s,l=Math.max(...r.map(e=>jp(e).length),n.title?jp(n.title).length:0)+s,u=l+s,d=n.style.marginLeft>0?` `.repeat(n.style.marginLeft):``;if(n.style.marginTop>0&&i.push(``.repeat(n.style.marginTop)),n.title){let e=a?a(n.title):n.title,t=o.h.repeat(Math.floor((l-jp(n.title).length)/2)),r=o.h.repeat(l-jp(n.title).length-jp(t).length+s);i.push(`${d}${o.tl}${t}${e}${r}${o.tr}`)}else i.push(`${d}${o.tl}${o.h.repeat(u)}${o.tr}`);let f=n.style.valign===`center`?Math.floor((c-r.length)/2):n.style.valign===`top`?c-r.length-s:c-r.length;for(let e=0;e<c;e++)if(e<f||e>=f+r.length)i.push(`${d}${o.v}${` `.repeat(u)}${o.v}`);else{let t=r[e-f],n=` `.repeat(s),a=` `.repeat(l-jp(t).length);i.push(`${d}${o.v}${n}${t}${a}${o.v}`)}return i.push(`${d}${o.bl}${o.h.repeat(u)}${o.br}`),n.style.marginBottom>0&&i.push(``.repeat(n.style.marginBottom)),i.join(`
615
- `)}var Fp=Se({kCancel:()=>sh,prompt:()=>Yp});function Ip(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function Lp(){if(Zp)return Xp;Zp=1;let e={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};return Xp={cursor:e,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(t){let n=``;for(let r=0;r<t;r++)n+=this.line+(r<t-1?e.up():``);return t&&(n+=e.left),n}},beep:`\x07`},Xp}function Rp(){if(em)return $p.exports;em=1;let e=process||{},t=e.argv||[],n=e.env||{},r=!(n.NO_COLOR||t.includes(`--no-color`))&&(!!n.FORCE_COLOR||t.includes(`--color`)||e.platform===`win32`||(e.stdout||{}).isTTY&&n.TERM!==`dumb`||!!n.CI),i=(e,t,n=e)=>r=>{let i=``+r,o=i.indexOf(t,e.length);return~o?e+a(i,t,n,o)+t:e+i+t},a=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},o=(e=r)=>{let t=e?i:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};return $p.exports=o(),$p.exports.createColors=o,$p.exports}function zp({onlyFirst:e=!1}={}){let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}function Bp(e){if(typeof e!=`string`)throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(tm,``)}function Vp(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function Hp(e,t={}){if(typeof e!=`string`||e.length===0||(t={ambiguousIsNarrow:!0,...t},e=Bp(e),e.length===0))return 0;e=e.replace(om(),` `);let n=t.ambiguousIsNarrow?1:2,r=0;for(let t of e){let e=t.codePointAt(0);if(!(e<=31||e>=127&&e<=159||e>=768&&e<=879))switch(im.eastAsianWidth(t)){case`F`:case`W`:r+=2;break;case`A`:r+=n;break;default:r+=1}}return r}function Up(){let e=new Map;for(let[t,n]of Object.entries(Y)){for(let[t,r]of Object.entries(n))Y[t]={open:`\x1B[${r[0]}m`,close:`\x1B[${r[1]}m`},n[t]=Y[t],e.set(r[0],r[1]);Object.defineProperty(Y,t,{value:n,enumerable:!1})}return Object.defineProperty(Y,"codes",{value:e,enumerable:!1}),Y.color.close=`\x1B[39m`,Y.bgColor.close=`\x1B[49m`,Y.color.ansi=cm(),Y.color.ansi256=lm(),Y.color.ansi16m=um(),Y.bgColor.ansi=cm(sm),Y.bgColor.ansi256=lm(sm),Y.bgColor.ansi16m=um(sm),Object.defineProperties(Y,{rgbToAnsi256:{value:(e,t,n)=>e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5),enumerable:!1},hexToRgb:{value:e=>{let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=Number.parseInt(n,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:e=>Y.rgbToAnsi256(...Y.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value:e=>{if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,r;if(e>=232)t=((e-232)*10+8)/255,n=t,r=t;else{e-=16;let i=e%36;t=Math.floor(e/36)/5,n=Math.floor(i/6)/5,r=i%6/5}let i=Math.max(t,n,r)*2;if(i===0)return 30;let a=30+(Math.round(r)<<2|Math.round(n)<<1|Math.round(t));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>Y.ansi256ToAnsi(Y.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>Y.ansi256ToAnsi(Y.hexToAnsi256(e)),enumerable:!1}}),Y}function Wp(e,t,n){return String(e).normalize().replace(/\r\n/g,`
612
+ `:this.filterAndJoin([mp(e.type),mp(e.tag),n])}log(e,t){return pp(this.formatLogObj(e,{columns:t.options.stdout.columns||0,...t.options.formatOptions})+`
613
+ `,e.level<2?t.options.stderr||process.stderr:t.options.stdout||process.stdout)}};const{env:gp={},argv:_p=[],platform:vp=``}=typeof process>`u`?{}:process,yp=`NO_COLOR`in gp||_p.includes(`--no-color`),bp=`FORCE_COLOR`in gp||_p.includes(`--color`),xp=vp===`win32`,Sp=gp.TERM===`dumb`,Cp=ge&&ge.isatty&&ge.isatty(1)&&gp.TERM&&!Sp,wp=`CI`in gp&&(`GITHUB_ACTIONS`in gp||`GITLAB_CI`in gp||`CIRCLECI`in gp),Tp=!yp&&(bp||xp&&!Sp||Cp||wp);function Ep(e,t,n,r,i=t.slice(0,Math.max(0,e))+r,a=t.slice(Math.max(0,e+n.length)),o=a.indexOf(n)){return i+(o<0?a:Ep(o,a,n,r))}function Dp(e,t,n,r,i){return e<0?n+t+r:n+Ep(e,t,r,i)+r}function Op(e,t,n=e,r=e.length+1){return i=>i||i!==``&&i!==void 0?Dp((``+i).indexOf(t,r),i,e,t,n):``}function J(e,t,n){return Op(`\x1B[${e}m`,`\x1B[${t}m`,n)}const kp={reset:J(0,0),bold:J(1,22,`\x1B[22m\x1B[1m`),dim:J(2,22,`\x1B[22m\x1B[2m`),italic:J(3,23),underline:J(4,24),inverse:J(7,27),hidden:J(8,28),strikethrough:J(9,29),black:J(30,39),red:J(31,39),green:J(32,39),yellow:J(33,39),blue:J(34,39),magenta:J(35,39),cyan:J(36,39),white:J(37,39),gray:J(90,39),bgBlack:J(40,49),bgRed:J(41,49),bgGreen:J(42,49),bgYellow:J(43,49),bgBlue:J(44,49),bgMagenta:J(45,49),bgCyan:J(46,49),bgWhite:J(47,49),blackBright:J(90,39),redBright:J(91,39),greenBright:J(92,39),yellowBright:J(93,39),blueBright:J(94,39),magentaBright:J(95,39),cyanBright:J(96,39),whiteBright:J(97,39),bgBlackBright:J(100,49),bgRedBright:J(101,49),bgGreenBright:J(102,49),bgYellowBright:J(103,49),bgBlueBright:J(104,49),bgMagentaBright:J(105,49),bgCyanBright:J(106,49),bgWhiteBright:J(107,49)};function Ap(e=Tp){return e?kp:Object.fromEntries(Object.keys(kp).map(e=>[e,String]))}const jp=Ap();function Mp(e,t=`reset`){return jp[e]||jp[t]}const Np=[String.raw`[\u001B\u009B][[\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\d\/#&.:=?%@~_]+)*|[a-zA-Z\d]+(?:;[-a-zA-Z\d\/#&.:=?%@~_]*)*)?\u0007)`,String.raw`(?:(?:\d{1,4}(?:;\d{0,4})*)?[\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);function Pp(e){return e.replace(new RegExp(Np,`g`),``)}const Fp={solid:{tl:`┌`,tr:`┐`,bl:`└`,br:`┘`,h:`─`,v:`│`},double:{tl:`╔`,tr:`╗`,bl:`╚`,br:`╝`,h:`═`,v:`║`},doubleSingle:{tl:`╓`,tr:`╖`,bl:`╙`,br:`╜`,h:`─`,v:`║`},doubleSingleRounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`║`},singleThick:{tl:`┏`,tr:`┓`,bl:`┗`,br:`┛`,h:`━`,v:`┃`},singleDouble:{tl:`╒`,tr:`╕`,bl:`╘`,br:`╛`,h:`═`,v:`│`},singleDoubleRounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`═`,v:`│`},rounded:{tl:`╭`,tr:`╮`,bl:`╰`,br:`╯`,h:`─`,v:`│`}},Ip={borderColor:`white`,borderStyle:`rounded`,valign:`center`,padding:2,marginLeft:1,marginTop:1,marginBottom:1};function Lp(e,t={}){let n={...t,style:{...Ip,...t.style}},r=e.split(`
614
+ `),i=[],a=Mp(n.style.borderColor),o={...typeof n.style.borderStyle==`string`?Fp[n.style.borderStyle]||Fp.solid:n.style.borderStyle};if(a)for(let e in o)o[e]=a(o[e]);let s=n.style.padding%2==0?n.style.padding:n.style.padding+1,c=r.length+s,l=Math.max(...r.map(e=>Pp(e).length),n.title?Pp(n.title).length:0)+s,u=l+s,d=n.style.marginLeft>0?` `.repeat(n.style.marginLeft):``;if(n.style.marginTop>0&&i.push(``.repeat(n.style.marginTop)),n.title){let e=a?a(n.title):n.title,t=o.h.repeat(Math.floor((l-Pp(n.title).length)/2)),r=o.h.repeat(l-Pp(n.title).length-Pp(t).length+s);i.push(`${d}${o.tl}${t}${e}${r}${o.tr}`)}else i.push(`${d}${o.tl}${o.h.repeat(u)}${o.tr}`);let f=n.style.valign===`center`?Math.floor((c-r.length)/2):n.style.valign===`top`?c-r.length-s:c-r.length;for(let e=0;e<c;e++)if(e<f||e>=f+r.length)i.push(`${d}${o.v}${` `.repeat(u)}${o.v}`);else{let t=r[e-f],n=` `.repeat(s),a=` `.repeat(l-Pp(t).length);i.push(`${d}${o.v}${n}${t}${a}${o.v}`)}return i.push(`${d}${o.bl}${o.h.repeat(u)}${o.br}`),n.style.marginBottom>0&&i.push(``.repeat(n.style.marginBottom)),i.join(`
615
+ `)}var Rp=Se({kCancel:()=>uh,prompt:()=>Qp});function zp(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function Bp(){if(em)return $p;em=1;let e={to(e,t){return t?`[${t+1};${e+1}H`:`[${e+1}G`},move(e,t){let n=``;return e<0?n+=`[${-e}D`:e>0&&(n+=`[${e}C`),t<0?n+=`[${-t}A`:t>0&&(n+=`[${t}B`),n},up:(e=1)=>`[${e}A`,down:(e=1)=>`[${e}B`,forward:(e=1)=>`[${e}C`,backward:(e=1)=>`[${e}D`,nextLine:(e=1)=>`\x1B[E`.repeat(e),prevLine:(e=1)=>`\x1B[F`.repeat(e),left:`\x1B[G`,hide:`\x1B[?25l`,show:`\x1B[?25h`,save:`\x1B7`,restore:`\x1B8`};return $p={cursor:e,scroll:{up:(e=1)=>`\x1B[S`.repeat(e),down:(e=1)=>`\x1B[T`.repeat(e)},erase:{screen:`\x1B[2J`,up:(e=1)=>`\x1B[1J`.repeat(e),down:(e=1)=>`\x1B[J`.repeat(e),line:`\x1B[2K`,lineEnd:`\x1B[K`,lineStart:`\x1B[1K`,lines(t){let n=``;for(let r=0;r<t;r++)n+=this.line+(r<t-1?e.up():``);return t&&(n+=e.left),n}},beep:`\x07`},$p}function Vp(){if(rm)return nm.exports;rm=1;let e=process||{},t=e.argv||[],n=e.env||{},r=!(n.NO_COLOR||t.includes(`--no-color`))&&(!!n.FORCE_COLOR||t.includes(`--color`)||e.platform===`win32`||(e.stdout||{}).isTTY&&n.TERM!==`dumb`||!!n.CI),i=(e,t,n=e)=>r=>{let i=``+r,o=i.indexOf(t,e.length);return~o?e+a(i,t,n,o)+t:e+i+t},a=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},o=(e=r)=>{let t=e?i:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};return nm.exports=o(),nm.exports.createColors=o,nm.exports}function Hp({onlyFirst:e=!1}={}){let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}function Up(e){if(typeof e!=`string`)throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(im,``)}function Wp(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,`default`)?e.default:e}function Gp(e,t={}){if(typeof e!=`string`||e.length===0||(t={ambiguousIsNarrow:!0,...t},e=Up(e),e.length===0))return 0;e=e.replace(lm(),` `);let n=t.ambiguousIsNarrow?1:2,r=0;for(let t of e){let e=t.codePointAt(0);if(!(e<=31||e>=127&&e<=159||e>=768&&e<=879))switch(sm.eastAsianWidth(t)){case`F`:case`W`:r+=2;break;case`A`:r+=n;break;default:r+=1}}return r}function Kp(){let e=new Map;for(let[t,n]of Object.entries(X)){for(let[t,r]of Object.entries(n))X[t]={open:`\x1B[${r[0]}m`,close:`\x1B[${r[1]}m`},n[t]=X[t],e.set(r[0],r[1]);Object.defineProperty(X,t,{value:n,enumerable:!1})}return Object.defineProperty(X,"codes",{value:e,enumerable:!1}),X.color.close=`\x1B[39m`,X.bgColor.close=`\x1B[49m`,X.color.ansi=dm(),X.color.ansi256=fm(),X.color.ansi16m=pm(),X.bgColor.ansi=dm(um),X.bgColor.ansi256=fm(um),X.bgColor.ansi16m=pm(um),Object.defineProperties(X,{rgbToAnsi256:{value:(e,t,n)=>e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5),enumerable:!1},hexToRgb:{value:e=>{let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=Number.parseInt(n,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:e=>X.rgbToAnsi256(...X.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value:e=>{if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,r;if(e>=232)t=((e-232)*10+8)/255,n=t,r=t;else{e-=16;let i=e%36;t=Math.floor(e/36)/5,n=Math.floor(i/6)/5,r=i%6/5}let i=Math.max(t,n,r)*2;if(i===0)return 30;let a=30+(Math.round(r)<<2|Math.round(n)<<1|Math.round(t));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>X.ansi256ToAnsi(X.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>X.ansi256ToAnsi(X.hexToAnsi256(e)),enumerable:!1}}),X}function qp(e,t,n){return String(e).normalize().replace(/\r\n/g,`
616
616
  `).split(`
617
- `).map(e=>Em(e,t,n)).join(`
618
- `)}function Gp(e,t){if(typeof e==`string`)return Dm.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Gp(n,t))return!0;return!1}function Kp(e,t){if(e===t)return;let n=e.split(`
617
+ `).map(e=>km(e,t,n)).join(`
618
+ `)}function Jp(e,t){if(typeof e==`string`)return Am.aliases.get(e)===t;for(let n of e)if(n!==void 0&&Jp(n,t))return!0;return!1}function Yp(e,t){if(e===t)return;let n=e.split(`
619
619
  `),r=t.split(`
620
- `),i=[];for(let e=0;e<Math.max(n.length,r.length);e++)n[e]!==r[e]&&i.push(e);return i}function qp(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Jp(){return pe.platform===`win32`?!!pe.env.CI||!!pe.env.WT_SESSION||!!pe.env.TERMINUS_SUBLIME||pe.env.ConEmuTask===`{cmd::Cmder}`||pe.env.TERM_PROGRAM===`Terminus-Sublime`||pe.env.TERM_PROGRAM===`vscode`||pe.env.TERM===`xterm-256color`||pe.env.TERM===`alacritty`||pe.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:pe.env.TERM!==`linux`}async function Yp(e,t={}){let n=e=>{if(typeof e!=`symbol`||e.toString()!==`Symbol(clack:cancel)`)return e;switch(t.cancel){case`reject`:{let e=Error(`Prompt cancelled.`);throw e.name=`ConsolaPromptCancelledError`,Error.captureStackTrace&&Error.captureStackTrace(e,Yp),e}case`undefined`:return;case`null`:return null;case`symbol`:return sh;default:case`default`:return t.default??t.initial}};if(!t.type||t.type===`text`)return await rh({message:e,defaultValue:t.default,placeholder:t.placeholder,initialValue:t.initial}).then(n);if(t.type===`confirm`)return await ih({message:e,initialValue:t.initial}).then(n);if(t.type===`select`)return await ah({message:e,options:t.options.map(e=>typeof e==`string`?{value:e,label:e}:e),initialValue:t.initial}).then(n);if(t.type===`multiselect`)return await oh({message:e,options:t.options.map(e=>typeof e==`string`?{value:e,label:e}:e),required:t.required,initialValues:t.initial}).then(n);throw Error(`Unknown prompt type: ${t.type}`)}var Xp,Zp,Qp,$p,em,J,tm,nm,rm,im,am,om,sm,cm,lm,um,Y,dm,fm,pm,mm,hm,gm,_m,vm,ym,bm,xm,Sm,Cm,wm,Tm,Em,Dm,Om,km,Am,jm,Mm,Nm,Pm,Fm,Im,Lm,Rm,zm,Bm,Vm,Hm,Um,Wm,Gm,Km,qm,Jm,X,Ym,Xm,Zm,Qm,$m,eh,th,nh,rh,ih,ah,oh,sh,ch=E((()=>{Qp=Lp(),$p={exports:{}},J=Ip(Rp()),tm=zp(),nm={exports:{}},(function(e){var t={};e.exports=t,t.eastAsianWidth=function(e){var t=e.charCodeAt(0),n=e.length==2?e.charCodeAt(1):0,r=t;return 55296<=t&&t<=56319&&56320<=n&&n<=57343&&(t&=1023,n&=1023,r=t<<10|n,r+=65536),r==12288||65281<=r&&r<=65376||65504<=r&&r<=65510?`F`:r==8361||65377<=r&&r<=65470||65474<=r&&r<=65479||65482<=r&&r<=65487||65490<=r&&r<=65495||65498<=r&&r<=65500||65512<=r&&r<=65518?`H`:4352<=r&&r<=4447||4515<=r&&r<=4519||4602<=r&&r<=4607||9001<=r&&r<=9002||11904<=r&&r<=11929||11931<=r&&r<=12019||12032<=r&&r<=12245||12272<=r&&r<=12283||12289<=r&&r<=12350||12353<=r&&r<=12438||12441<=r&&r<=12543||12549<=r&&r<=12589||12593<=r&&r<=12686||12688<=r&&r<=12730||12736<=r&&r<=12771||12784<=r&&r<=12830||12832<=r&&r<=12871||12880<=r&&r<=13054||13056<=r&&r<=19903||19968<=r&&r<=42124||42128<=r&&r<=42182||43360<=r&&r<=43388||44032<=r&&r<=55203||55216<=r&&r<=55238||55243<=r&&r<=55291||63744<=r&&r<=64255||65040<=r&&r<=65049||65072<=r&&r<=65106||65108<=r&&r<=65126||65128<=r&&r<=65131||110592<=r&&r<=110593||127488<=r&&r<=127490||127504<=r&&r<=127546||127552<=r&&r<=127560||127568<=r&&r<=127569||131072<=r&&r<=194367||177984<=r&&r<=196605||196608<=r&&r<=262141?`W`:32<=r&&r<=126||162<=r&&r<=163||165<=r&&r<=166||r==172||r==175||10214<=r&&r<=10221||10629<=r&&r<=10630?`Na`:r==161||r==164||167<=r&&r<=168||r==170||173<=r&&r<=174||176<=r&&r<=180||182<=r&&r<=186||188<=r&&r<=191||r==198||r==208||215<=r&&r<=216||222<=r&&r<=225||r==230||232<=r&&r<=234||236<=r&&r<=237||r==240||242<=r&&r<=243||247<=r&&r<=250||r==252||r==254||r==257||r==273||r==275||r==283||294<=r&&r<=295||r==299||305<=r&&r<=307||r==312||319<=r&&r<=322||r==324||328<=r&&r<=331||r==333||338<=r&&r<=339||358<=r&&r<=359||r==363||r==462||r==464||r==466||r==468||r==470||r==472||r==474||r==476||r==593||r==609||r==708||r==711||713<=r&&r<=715||r==717||r==720||728<=r&&r<=731||r==733||r==735||768<=r&&r<=879||913<=r&&r<=929||931<=r&&r<=937||945<=r&&r<=961||963<=r&&r<=969||r==1025||1040<=r&&r<=1103||r==1105||r==8208||8211<=r&&r<=8214||8216<=r&&r<=8217||8220<=r&&r<=8221||8224<=r&&r<=8226||8228<=r&&r<=8231||r==8240||8242<=r&&r<=8243||r==8245||r==8251||r==8254||r==8308||r==8319||8321<=r&&r<=8324||r==8364||r==8451||r==8453||r==8457||r==8467||r==8470||8481<=r&&r<=8482||r==8486||r==8491||8531<=r&&r<=8532||8539<=r&&r<=8542||8544<=r&&r<=8555||8560<=r&&r<=8569||r==8585||8592<=r&&r<=8601||8632<=r&&r<=8633||r==8658||r==8660||r==8679||r==8704||8706<=r&&r<=8707||8711<=r&&r<=8712||r==8715||r==8719||r==8721||r==8725||r==8730||8733<=r&&r<=8736||r==8739||r==8741||8743<=r&&r<=8748||r==8750||8756<=r&&r<=8759||8764<=r&&r<=8765||r==8776||r==8780||r==8786||8800<=r&&r<=8801||8804<=r&&r<=8807||8810<=r&&r<=8811||8814<=r&&r<=8815||8834<=r&&r<=8835||8838<=r&&r<=8839||r==8853||r==8857||r==8869||r==8895||r==8978||9312<=r&&r<=9449||9451<=r&&r<=9547||9552<=r&&r<=9587||9600<=r&&r<=9615||9618<=r&&r<=9621||9632<=r&&r<=9633||9635<=r&&r<=9641||9650<=r&&r<=9651||9654<=r&&r<=9655||9660<=r&&r<=9661||9664<=r&&r<=9665||9670<=r&&r<=9672||r==9675||9678<=r&&r<=9681||9698<=r&&r<=9701||r==9711||9733<=r&&r<=9734||r==9737||9742<=r&&r<=9743||9748<=r&&r<=9749||r==9756||r==9758||r==9792||r==9794||9824<=r&&r<=9825||9827<=r&&r<=9829||9831<=r&&r<=9834||9836<=r&&r<=9837||r==9839||9886<=r&&r<=9887||9918<=r&&r<=9919||9924<=r&&r<=9933||9935<=r&&r<=9953||r==9955||9960<=r&&r<=9983||r==10045||r==10071||10102<=r&&r<=10111||11093<=r&&r<=11097||12872<=r&&r<=12879||57344<=r&&r<=63743||65024<=r&&r<=65039||r==65533||127232<=r&&r<=127242||127248<=r&&r<=127277||127280<=r&&r<=127337||127344<=r&&r<=127386||917760<=r&&r<=917999||983040<=r&&r<=1048573||1048576<=r&&r<=1114109?`A`:`N`},t.characterLength=function(e){var t=this.eastAsianWidth(e);return t==`F`||t==`W`||t==`A`?2:1};function n(e){return e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}t.length=function(e){for(var t=n(e),r=0,i=0;i<t.length;i++)r+=this.characterLength(t[i]);return r},t.slice=function(e,r,i){textLen=t.length(e),r||=0,i||=1,r<0&&(r=textLen+r),i<0&&(i=textLen+i);for(var a=``,o=0,s=n(e),c=0;c<s.length;c++){var l=s[c],u=t.length(l);if(o>=r-+(u==2)){if(o+u<=i)a+=l;else break}o+=u}return a}})(nm),rm=nm.exports,im=Vp(rm),am=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g},om=Vp(am),sm=10,cm=(e=0)=>t=>`\x1B[${t+e}m`,lm=(e=0)=>t=>`\x1B[${38+e};5;${t}m`,um=(e=0)=>(t,n,r)=>`\x1B[${38+e};2;${t};${n};${r}m`,Y={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Object.keys(Y.modifier),dm=Object.keys(Y.color),fm=Object.keys(Y.bgColor),[...dm,...fm],pm=Up(),mm=new Set([`\x1B`,`›`]),hm=39,gm=`\x07`,_m=`[`,vm=`]`,ym=`m`,bm=`${vm}8;;`,xm=e=>`${mm.values().next().value}${_m}${e}${ym}`,Sm=e=>`${mm.values().next().value}${bm}${e}${gm}`,Cm=e=>e.split(` `).map(e=>Hp(e)),wm=(e,t,n)=>{let r=[...t],i=!1,a=!1,o=Hp(Bp(e[e.length-1]));for(let[t,s]of r.entries()){let c=Hp(s);if(o+c<=n?e[e.length-1]+=s:(e.push(s),o=0),mm.has(s)&&(i=!0,a=r.slice(t+1).join(``).startsWith(bm)),i){a?s===gm&&(i=!1,a=!1):s===ym&&(i=!1);continue}o+=c,o===n&&t<r.length-1&&(e.push(``),o=0)}!o&&e[e.length-1].length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Tm=e=>{let t=e.split(` `),n=t.length;for(;n>0&&!(Hp(t[n-1])>0);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},Em=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=Cm(e),s=[``];for(let[r,i]of e.split(` `).entries()){n.trim!==!1&&(s[s.length-1]=s[s.length-1].trimStart());let e=Hp(s[s.length-1]);if(r!==0&&(e>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),e=0),(e>0||n.trim===!1)&&(s[s.length-1]+=` `,e++)),n.hard&&o[r]>t){let n=t-e,a=1+Math.floor((o[r]-n-1)/t);Math.floor((o[r]-1)/t)<a&&s.push(``),wm(s,i,t);continue}if(e+o[r]>t&&e>0&&o[r]>0){if(n.wordWrap===!1&&e<t){wm(s,i,t);continue}s.push(``)}if(e+o[r]>t&&n.wordWrap===!1){wm(s,i,t);continue}s[s.length-1]+=i}n.trim!==!1&&(s=s.map(e=>Tm(e)));let c=[...s.join(`
621
- `)];for(let[e,t]of c.entries()){if(r+=t,mm.has(t)){let{groups:t}=RegExp(`(?:\\${_m}(?<code>\\d+)m|\\${bm}(?<uri>.*)${gm})`).exec(c.slice(e).join(``))||{groups:{}};if(t.code!==void 0){let e=Number.parseFloat(t.code);i=e===hm?void 0:e}else t.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}let n=pm.codes.get(Number(i));c[e+1]===`
622
- `?(a&&(r+=Sm(``)),i&&n&&(r+=xm(n))):t===`
623
- `&&(i&&n&&(r+=xm(i)),a&&(r+=Sm(a)))}return r},Dm={actions:new Set([`up`,`down`,`left`,`right`,`space`,`enter`,`cancel`]),aliases:new Map([[`k`,`up`],[`j`,`down`],[`h`,`left`],[`l`,`right`],[``,`cancel`],[`escape`,`cancel`]])},globalThis.process.platform.startsWith(`win`),Om=Symbol(`clack:cancel`),km=Object.defineProperty,Am=(e,t,n)=>t in e?km(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,jm=(e,t,n)=>(Am(e,typeof t==`symbol`?t:t+``,n),n),Mm=class{constructor(e,t=!0){jm(this,`input`),jm(this,`output`),jm(this,`_abortSignal`),jm(this,`rl`),jm(this,`opts`),jm(this,`_render`),jm(this,`_track`,!1),jm(this,`_prevFrame`,``),jm(this,`_subscribers`,new Map),jm(this,`_cursor`,0),jm(this,`state`,`initial`),jm(this,`error`,``),jm(this,`value`);let{input:n=me,output:r=he,render:i,signal:a,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=t,this._abortSignal=a,this.input=n,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],r=[];for(let e of n)e.cb(...t),e.once&&r.push(()=>n.splice(n.indexOf(e),1));for(let e of r)e()}prompt(){return new Promise((e,t)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state=`cancel`,this.close(),e(Om);this._abortSignal.addEventListener(`abort`,()=>{this.state=`cancel`,this.close()},{once:!0})}let n=new _e(0);n._write=(e,t,n)=>{this._track&&(this.value=this.rl?.line.replace(/\t/g,``),this._cursor=this.rl?.cursor??0,this.emit(`value`,this.value)),n()},this.input.pipe(n),this.rl=ve.createInterface({input:this.input,output:n,tabSize:2,prompt:``,escapeCodeTimeout:50}),ve.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on(`keypress`,this.onKeypress),qp(this.input,!0),this.output.on(`resize`,this.render),this.render(),this.once(`submit`,()=>{this.output.write(Qp.cursor.show),this.output.off(`resize`,this.render),qp(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(Qp.cursor.show),this.output.off(`resize`,this.render),qp(this.input,!1),e(Om)})})}onKeypress(e,t){if(this.state===`error`&&(this.state=`active`),t?.name&&(!this._track&&Dm.aliases.has(t.name)&&this.emit(`cursor`,Dm.aliases.get(t.name)),Dm.actions.has(t.name)&&this.emit(`cursor`,t.name)),e&&(e.toLowerCase()===`y`||e.toLowerCase()===`n`)&&this.emit(`confirm`,e.toLowerCase()===`y`),e===` `&&this.opts.placeholder&&(this.value||(this.rl?.write(this.opts.placeholder),this.emit(`value`,this.opts.placeholder))),e&&this.emit(`key`,e.toLowerCase()),t?.name===`return`){if(this.opts.validate){let e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state=`error`,this.rl?.write(this.value))}this.state!==`error`&&(this.state=`submit`)}Gp([e,t?.name,t?.sequence],`cancel`)&&(this.state=`cancel`),(this.state===`submit`||this.state===`cancel`)&&this.emit(`finalize`),this.render(),(this.state===`submit`||this.state===`cancel`)&&this.close()}close(){this.input.unpipe(),this.input.removeListener(`keypress`,this.onKeypress),this.output.write(`
624
- `),qp(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=Wp(this._prevFrame,process.stdout.columns,{hard:!0}).split(`
625
- `).length-1;this.output.write(Qp.cursor.move(-999,e*-1))}render(){let e=Wp(this._render(this)??``,process.stdout.columns,{hard:!0});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(Qp.cursor.hide);else{let t=Kp(this._prevFrame,e);if(this.restoreCursor(),t&&t?.length===1){let n=t[0];this.output.write(Qp.cursor.move(0,n)),this.output.write(Qp.erase.lines(1));let r=e.split(`
626
- `);this.output.write(r[n]),this._prevFrame=e,this.output.write(Qp.cursor.move(0,r.length-n-1));return}if(t&&t?.length>1){let n=t[0];this.output.write(Qp.cursor.move(0,n)),this.output.write(Qp.erase.down());let r=e.split(`
620
+ `),i=[];for(let e=0;e<Math.max(n.length,r.length);e++)n[e]!==r[e]&&i.push(e);return i}function Xp(e,t){let n=e;n.isTTY&&n.setRawMode(t)}function Zp(){return pe.platform===`win32`?!!pe.env.CI||!!pe.env.WT_SESSION||!!pe.env.TERMINUS_SUBLIME||pe.env.ConEmuTask===`{cmd::Cmder}`||pe.env.TERM_PROGRAM===`Terminus-Sublime`||pe.env.TERM_PROGRAM===`vscode`||pe.env.TERM===`xterm-256color`||pe.env.TERM===`alacritty`||pe.env.TERMINAL_EMULATOR===`JetBrains-JediTerm`:pe.env.TERM!==`linux`}async function Qp(e,t={}){let n=e=>{if(typeof e!=`symbol`||e.toString()!==`Symbol(clack:cancel)`)return e;switch(t.cancel){case`reject`:{let e=Error(`Prompt cancelled.`);throw e.name=`ConsolaPromptCancelledError`,Error.captureStackTrace&&Error.captureStackTrace(e,Qp),e}case`undefined`:return;case`null`:return null;case`symbol`:return uh;default:case`default`:return t.default??t.initial}};if(!t.type||t.type===`text`)return await oh({message:e,defaultValue:t.default,placeholder:t.placeholder,initialValue:t.initial}).then(n);if(t.type===`confirm`)return await sh({message:e,initialValue:t.initial}).then(n);if(t.type===`select`)return await ch({message:e,options:t.options.map(e=>typeof e==`string`?{value:e,label:e}:e),initialValue:t.initial}).then(n);if(t.type===`multiselect`)return await lh({message:e,options:t.options.map(e=>typeof e==`string`?{value:e,label:e}:e),required:t.required,initialValues:t.initial}).then(n);throw Error(`Unknown prompt type: ${t.type}`)}var $p,em,tm,nm,rm,Y,im,am,om,sm,cm,lm,um,dm,fm,pm,X,mm,hm,gm,_m,vm,ym,bm,xm,Sm,Cm,wm,Tm,Em,Dm,Om,km,Am,jm,Mm,Nm,Pm,Fm,Im,Lm,Rm,zm,Bm,Vm,Hm,Um,Wm,Gm,Km,qm,Jm,Ym,Xm,Zm,Z,Qm,$m,eh,th,nh,rh,ih,ah,oh,sh,ch,lh,uh,dh=E((()=>{tm=Bp(),nm={exports:{}},Y=zp(Vp()),im=Hp(),am={exports:{}},(function(e){var t={};e.exports=t,t.eastAsianWidth=function(e){var t=e.charCodeAt(0),n=e.length==2?e.charCodeAt(1):0,r=t;return 55296<=t&&t<=56319&&56320<=n&&n<=57343&&(t&=1023,n&=1023,r=t<<10|n,r+=65536),r==12288||65281<=r&&r<=65376||65504<=r&&r<=65510?`F`:r==8361||65377<=r&&r<=65470||65474<=r&&r<=65479||65482<=r&&r<=65487||65490<=r&&r<=65495||65498<=r&&r<=65500||65512<=r&&r<=65518?`H`:4352<=r&&r<=4447||4515<=r&&r<=4519||4602<=r&&r<=4607||9001<=r&&r<=9002||11904<=r&&r<=11929||11931<=r&&r<=12019||12032<=r&&r<=12245||12272<=r&&r<=12283||12289<=r&&r<=12350||12353<=r&&r<=12438||12441<=r&&r<=12543||12549<=r&&r<=12589||12593<=r&&r<=12686||12688<=r&&r<=12730||12736<=r&&r<=12771||12784<=r&&r<=12830||12832<=r&&r<=12871||12880<=r&&r<=13054||13056<=r&&r<=19903||19968<=r&&r<=42124||42128<=r&&r<=42182||43360<=r&&r<=43388||44032<=r&&r<=55203||55216<=r&&r<=55238||55243<=r&&r<=55291||63744<=r&&r<=64255||65040<=r&&r<=65049||65072<=r&&r<=65106||65108<=r&&r<=65126||65128<=r&&r<=65131||110592<=r&&r<=110593||127488<=r&&r<=127490||127504<=r&&r<=127546||127552<=r&&r<=127560||127568<=r&&r<=127569||131072<=r&&r<=194367||177984<=r&&r<=196605||196608<=r&&r<=262141?`W`:32<=r&&r<=126||162<=r&&r<=163||165<=r&&r<=166||r==172||r==175||10214<=r&&r<=10221||10629<=r&&r<=10630?`Na`:r==161||r==164||167<=r&&r<=168||r==170||173<=r&&r<=174||176<=r&&r<=180||182<=r&&r<=186||188<=r&&r<=191||r==198||r==208||215<=r&&r<=216||222<=r&&r<=225||r==230||232<=r&&r<=234||236<=r&&r<=237||r==240||242<=r&&r<=243||247<=r&&r<=250||r==252||r==254||r==257||r==273||r==275||r==283||294<=r&&r<=295||r==299||305<=r&&r<=307||r==312||319<=r&&r<=322||r==324||328<=r&&r<=331||r==333||338<=r&&r<=339||358<=r&&r<=359||r==363||r==462||r==464||r==466||r==468||r==470||r==472||r==474||r==476||r==593||r==609||r==708||r==711||713<=r&&r<=715||r==717||r==720||728<=r&&r<=731||r==733||r==735||768<=r&&r<=879||913<=r&&r<=929||931<=r&&r<=937||945<=r&&r<=961||963<=r&&r<=969||r==1025||1040<=r&&r<=1103||r==1105||r==8208||8211<=r&&r<=8214||8216<=r&&r<=8217||8220<=r&&r<=8221||8224<=r&&r<=8226||8228<=r&&r<=8231||r==8240||8242<=r&&r<=8243||r==8245||r==8251||r==8254||r==8308||r==8319||8321<=r&&r<=8324||r==8364||r==8451||r==8453||r==8457||r==8467||r==8470||8481<=r&&r<=8482||r==8486||r==8491||8531<=r&&r<=8532||8539<=r&&r<=8542||8544<=r&&r<=8555||8560<=r&&r<=8569||r==8585||8592<=r&&r<=8601||8632<=r&&r<=8633||r==8658||r==8660||r==8679||r==8704||8706<=r&&r<=8707||8711<=r&&r<=8712||r==8715||r==8719||r==8721||r==8725||r==8730||8733<=r&&r<=8736||r==8739||r==8741||8743<=r&&r<=8748||r==8750||8756<=r&&r<=8759||8764<=r&&r<=8765||r==8776||r==8780||r==8786||8800<=r&&r<=8801||8804<=r&&r<=8807||8810<=r&&r<=8811||8814<=r&&r<=8815||8834<=r&&r<=8835||8838<=r&&r<=8839||r==8853||r==8857||r==8869||r==8895||r==8978||9312<=r&&r<=9449||9451<=r&&r<=9547||9552<=r&&r<=9587||9600<=r&&r<=9615||9618<=r&&r<=9621||9632<=r&&r<=9633||9635<=r&&r<=9641||9650<=r&&r<=9651||9654<=r&&r<=9655||9660<=r&&r<=9661||9664<=r&&r<=9665||9670<=r&&r<=9672||r==9675||9678<=r&&r<=9681||9698<=r&&r<=9701||r==9711||9733<=r&&r<=9734||r==9737||9742<=r&&r<=9743||9748<=r&&r<=9749||r==9756||r==9758||r==9792||r==9794||9824<=r&&r<=9825||9827<=r&&r<=9829||9831<=r&&r<=9834||9836<=r&&r<=9837||r==9839||9886<=r&&r<=9887||9918<=r&&r<=9919||9924<=r&&r<=9933||9935<=r&&r<=9953||r==9955||9960<=r&&r<=9983||r==10045||r==10071||10102<=r&&r<=10111||11093<=r&&r<=11097||12872<=r&&r<=12879||57344<=r&&r<=63743||65024<=r&&r<=65039||r==65533||127232<=r&&r<=127242||127248<=r&&r<=127277||127280<=r&&r<=127337||127344<=r&&r<=127386||917760<=r&&r<=917999||983040<=r&&r<=1048573||1048576<=r&&r<=1114109?`A`:`N`},t.characterLength=function(e){var t=this.eastAsianWidth(e);return t==`F`||t==`W`||t==`A`?2:1};function n(e){return e.match(/[\uD800-\uDBFF][\uDC00-\uDFFF]|[^\uD800-\uDFFF]/g)||[]}t.length=function(e){for(var t=n(e),r=0,i=0;i<t.length;i++)r+=this.characterLength(t[i]);return r},t.slice=function(e,r,i){textLen=t.length(e),r||=0,i||=1,r<0&&(r=textLen+r),i<0&&(i=textLen+i);for(var a=``,o=0,s=n(e),c=0;c<s.length;c++){var l=s[c],u=t.length(l);if(o>=r-+(u==2)){if(o+u<=i)a+=l;else break}o+=u}return a}})(am),om=am.exports,sm=Wp(om),cm=function(){return/\uD83C\uDFF4\uDB40\uDC67\uDB40\uDC62(?:\uDB40\uDC77\uDB40\uDC6C\uDB40\uDC73|\uDB40\uDC73\uDB40\uDC63\uDB40\uDC74|\uDB40\uDC65\uDB40\uDC6E\uDB40\uDC67)\uDB40\uDC7F|(?:\uD83E\uDDD1\uD83C\uDFFF\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFF\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFE])|(?:\uD83E\uDDD1\uD83C\uDFFE\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFE\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFD\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFD\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFC\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFC\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|(?:\uD83E\uDDD1\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1|\uD83D\uDC69\uD83C\uDFFB\u200D\uD83E\uDD1D\u200D(?:\uD83D[\uDC68\uDC69]))(?:\uD83C[\uDFFC-\uDFFF])|\uD83D\uDC68(?:\uD83C\uDFFB(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFC-\uDFFF])|[\u2695\u2696\u2708]\uFE0F|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))?|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFF]))|\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D)?\uD83D\uDC68|(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFE])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB-\uDFFD\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83E\uDD1D\u200D\uD83D\uDC68(?:\uD83C[\uDFFB\uDFFD-\uDFFF])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])\uFE0F|\u200D(?:(?:\uD83D[\uDC68\uDC69])\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D[\uDC66\uDC67])|\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC)?|(?:\uD83D\uDC69(?:\uD83C\uDFFB\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|(?:\uD83C[\uDFFC-\uDFFF])\u200D\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69]))|\uD83E\uDDD1(?:\uD83C[\uDFFB-\uDFFF])\u200D\uD83E\uDD1D\u200D\uD83E\uDDD1)(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67]))|\uD83D\uDC69(?:\u200D(?:\u2764\uFE0F\u200D(?:\uD83D\uDC8B\u200D(?:\uD83D[\uDC68\uDC69])|\uD83D[\uDC68\uDC69])|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83E\uDDD1(?:\u200D(?:\uD83E\uDD1D\u200D\uD83E\uDDD1|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFF\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFE\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFD\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFC\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD])|\uD83C\uDFFB\u200D(?:\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E[\uDDAF-\uDDB3\uDDBC\uDDBD]))|\uD83D\uDC69\u200D\uD83D\uDC66\u200D\uD83D\uDC66|\uD83D\uDC69\u200D\uD83D\uDC69\u200D(?:\uD83D[\uDC66\uDC67])|\uD83D\uDC69\u200D\uD83D\uDC67\u200D(?:\uD83D[\uDC66\uDC67])|(?:\uD83D\uDC41\uFE0F\u200D\uD83D\uDDE8|\uD83E\uDDD1(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDC69(?:\uD83C\uDFFF\u200D[\u2695\u2696\u2708]|\uD83C\uDFFE\u200D[\u2695\u2696\u2708]|\uD83C\uDFFD\u200D[\u2695\u2696\u2708]|\uD83C\uDFFC\u200D[\u2695\u2696\u2708]|\uD83C\uDFFB\u200D[\u2695\u2696\u2708]|\u200D[\u2695\u2696\u2708])|\uD83D\uDE36\u200D\uD83C\uDF2B|\uD83C\uDFF3\uFE0F\u200D\u26A7|\uD83D\uDC3B\u200D\u2744|(?:(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF])\u200D[\u2640\u2642]|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])\u200D[\u2640\u2642]|\uD83C\uDFF4\u200D\u2620|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])\u200D[\u2640\u2642]|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u2600-\u2604\u260E\u2611\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26B0\u26B1\u26C8\u26CF\u26D1\u26D3\u26E9\u26F0\u26F1\u26F4\u26F7\u26F8\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u3030\u303D\u3297\u3299]|\uD83C[\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]|\uD83D[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3])\uFE0F|\uD83C\uDFF3\uFE0F\u200D\uD83C\uDF08|\uD83D\uDC69\u200D\uD83D\uDC67|\uD83D\uDC69\u200D\uD83D\uDC66|\uD83D\uDE35\u200D\uD83D\uDCAB|\uD83D\uDE2E\u200D\uD83D\uDCA8|\uD83D\uDC15\u200D\uD83E\uDDBA|\uD83E\uDDD1(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83D\uDC69(?:\uD83C\uDFFF|\uD83C\uDFFE|\uD83C\uDFFD|\uD83C\uDFFC|\uD83C\uDFFB)?|\uD83C\uDDFD\uD83C\uDDF0|\uD83C\uDDF6\uD83C\uDDE6|\uD83C\uDDF4\uD83C\uDDF2|\uD83D\uDC08\u200D\u2B1B|\u2764\uFE0F\u200D(?:\uD83D\uDD25|\uD83E\uDE79)|\uD83D\uDC41\uFE0F|\uD83C\uDFF3\uFE0F|\uD83C\uDDFF(?:\uD83C[\uDDE6\uDDF2\uDDFC])|\uD83C\uDDFE(?:\uD83C[\uDDEA\uDDF9])|\uD83C\uDDFC(?:\uD83C[\uDDEB\uDDF8])|\uD83C\uDDFB(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA])|\uD83C\uDDFA(?:\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF])|\uD83C\uDDF9(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF])|\uD83C\uDDF8(?:\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF])|\uD83C\uDDF7(?:\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC])|\uD83C\uDDF5(?:\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE])|\uD83C\uDDF3(?:\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF])|\uD83C\uDDF2(?:\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF])|\uD83C\uDDF1(?:\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE])|\uD83C\uDDF0(?:\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF])|\uD83C\uDDEF(?:\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5])|\uD83C\uDDEE(?:\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9])|\uD83C\uDDED(?:\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA])|\uD83C\uDDEC(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE])|\uD83C\uDDEB(?:\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7])|\uD83C\uDDEA(?:\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA])|\uD83C\uDDE9(?:\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF])|\uD83C\uDDE8(?:\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF5\uDDF7\uDDFA-\uDDFF])|\uD83C\uDDE7(?:\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF])|\uD83C\uDDE6(?:\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF])|[#\*0-9]\uFE0F\u20E3|\u2764\uFE0F|(?:\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD])(?:\uD83C[\uDFFB-\uDFFF])|(?:\u26F9|\uD83C[\uDFCB\uDFCC]|\uD83D\uDD75)(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|\uD83C\uDFF4|(?:[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5])(?:\uD83C[\uDFFB-\uDFFF])|(?:[\u261D\u270C\u270D]|\uD83D[\uDD74\uDD90])(?:\uFE0F|\uD83C[\uDFFB-\uDFFF])|[\u270A\u270B]|\uD83C[\uDF85\uDFC2\uDFC7]|\uD83D[\uDC08\uDC15\uDC3B\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE2E\uDE35\uDE36\uDE4C\uDE4F\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1C\uDD1E\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5]|\uD83C[\uDFC3\uDFC4\uDFCA]|\uD83D[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4-\uDEB6]|\uD83E[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD-\uDDCF\uDDD4\uDDD6-\uDDDD]|\uD83D\uDC6F|\uD83E[\uDD3C\uDDDE\uDDDF]|[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0D\uDD0E\uDD10-\uDD17\uDD1D\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78\uDD7A-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCB\uDDD0\uDDE0-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6]|(?:[\u231A\u231B\u23E9-\u23EC\u23F0\u23F3\u25FD\u25FE\u2614\u2615\u2648-\u2653\u267F\u2693\u26A1\u26AA\u26AB\u26BD\u26BE\u26C4\u26C5\u26CE\u26D4\u26EA\u26F2\u26F3\u26F5\u26FA\u26FD\u2705\u270A\u270B\u2728\u274C\u274E\u2753-\u2755\u2757\u2795-\u2797\u27B0\u27BF\u2B1B\u2B1C\u2B50\u2B55]|\uD83C[\uDC04\uDCCF\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF7C\uDF7E-\uDF93\uDFA0-\uDFCA\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF4\uDFF8-\uDFFF]|\uD83D[\uDC00-\uDC3E\uDC40\uDC42-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDD7A\uDD95\uDD96\uDDA4\uDDFB-\uDE4F\uDE80-\uDEC5\uDECC\uDED0-\uDED2\uDED5-\uDED7\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])|(?:[#\*0-9\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23E9-\u23F3\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB-\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u261D\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692-\u2697\u2699\u269B\u269C\u26A0\u26A1\u26A7\u26AA\u26AB\u26B0\u26B1\u26BD\u26BE\u26C4\u26C5\u26C8\u26CE\u26CF\u26D1\u26D3\u26D4\u26E9\u26EA\u26F0-\u26F5\u26F7-\u26FA\u26FD\u2702\u2705\u2708-\u270D\u270F\u2712\u2714\u2716\u271D\u2721\u2728\u2733\u2734\u2744\u2747\u274C\u274E\u2753-\u2755\u2757\u2763\u2764\u2795-\u2797\u27A1\u27B0\u27BF\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B50\u2B55\u3030\u303D\u3297\u3299]|\uD83C[\uDC04\uDCCF\uDD70\uDD71\uDD7E\uDD7F\uDD8E\uDD91-\uDD9A\uDDE6-\uDDFF\uDE01\uDE02\uDE1A\uDE2F\uDE32-\uDE3A\uDE50\uDE51\uDF00-\uDF21\uDF24-\uDF93\uDF96\uDF97\uDF99-\uDF9B\uDF9E-\uDFF0\uDFF3-\uDFF5\uDFF7-\uDFFF]|\uD83D[\uDC00-\uDCFD\uDCFF-\uDD3D\uDD49-\uDD4E\uDD50-\uDD67\uDD6F\uDD70\uDD73-\uDD7A\uDD87\uDD8A-\uDD8D\uDD90\uDD95\uDD96\uDDA4\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA-\uDE4F\uDE80-\uDEC5\uDECB-\uDED2\uDED5-\uDED7\uDEE0-\uDEE5\uDEE9\uDEEB\uDEEC\uDEF0\uDEF3-\uDEFC\uDFE0-\uDFEB]|\uD83E[\uDD0C-\uDD3A\uDD3C-\uDD45\uDD47-\uDD78\uDD7A-\uDDCB\uDDCD-\uDDFF\uDE70-\uDE74\uDE78-\uDE7A\uDE80-\uDE86\uDE90-\uDEA8\uDEB0-\uDEB6\uDEC0-\uDEC2\uDED0-\uDED6])\uFE0F|(?:[\u261D\u26F9\u270A-\u270D]|\uD83C[\uDF85\uDFC2-\uDFC4\uDFC7\uDFCA-\uDFCC]|\uD83D[\uDC42\uDC43\uDC46-\uDC50\uDC66-\uDC78\uDC7C\uDC81-\uDC83\uDC85-\uDC87\uDC8F\uDC91\uDCAA\uDD74\uDD75\uDD7A\uDD90\uDD95\uDD96\uDE45-\uDE47\uDE4B-\uDE4F\uDEA3\uDEB4-\uDEB6\uDEC0\uDECC]|\uD83E[\uDD0C\uDD0F\uDD18-\uDD1F\uDD26\uDD30-\uDD39\uDD3C-\uDD3E\uDD77\uDDB5\uDDB6\uDDB8\uDDB9\uDDBB\uDDCD-\uDDCF\uDDD1-\uDDDD])/g},lm=Wp(cm),um=10,dm=(e=0)=>t=>`\x1B[${t+e}m`,fm=(e=0)=>t=>`\x1B[${38+e};5;${t}m`,pm=(e=0)=>(t,n,r)=>`\x1B[${38+e};2;${t};${n};${r}m`,X={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}},Object.keys(X.modifier),mm=Object.keys(X.color),hm=Object.keys(X.bgColor),[...mm,...hm],gm=Kp(),_m=new Set([`\x1B`,`›`]),vm=39,ym=`\x07`,bm=`[`,xm=`]`,Sm=`m`,Cm=`${xm}8;;`,wm=e=>`${_m.values().next().value}${bm}${e}${Sm}`,Tm=e=>`${_m.values().next().value}${Cm}${e}${ym}`,Em=e=>e.split(` `).map(e=>Gp(e)),Dm=(e,t,n)=>{let r=[...t],i=!1,a=!1,o=Gp(Up(e[e.length-1]));for(let[t,s]of r.entries()){let c=Gp(s);if(o+c<=n?e[e.length-1]+=s:(e.push(s),o=0),_m.has(s)&&(i=!0,a=r.slice(t+1).join(``).startsWith(Cm)),i){a?s===ym&&(i=!1,a=!1):s===Sm&&(i=!1);continue}o+=c,o===n&&t<r.length-1&&(e.push(``),o=0)}!o&&e[e.length-1].length>0&&e.length>1&&(e[e.length-2]+=e.pop())},Om=e=>{let t=e.split(` `),n=t.length;for(;n>0&&!(Gp(t[n-1])>0);)n--;return n===t.length?e:t.slice(0,n).join(` `)+t.slice(n).join(``)},km=(e,t,n={})=>{if(n.trim!==!1&&e.trim()===``)return``;let r=``,i,a,o=Em(e),s=[``];for(let[r,i]of e.split(` `).entries()){n.trim!==!1&&(s[s.length-1]=s[s.length-1].trimStart());let e=Gp(s[s.length-1]);if(r!==0&&(e>=t&&(n.wordWrap===!1||n.trim===!1)&&(s.push(``),e=0),(e>0||n.trim===!1)&&(s[s.length-1]+=` `,e++)),n.hard&&o[r]>t){let n=t-e,a=1+Math.floor((o[r]-n-1)/t);Math.floor((o[r]-1)/t)<a&&s.push(``),Dm(s,i,t);continue}if(e+o[r]>t&&e>0&&o[r]>0){if(n.wordWrap===!1&&e<t){Dm(s,i,t);continue}s.push(``)}if(e+o[r]>t&&n.wordWrap===!1){Dm(s,i,t);continue}s[s.length-1]+=i}n.trim!==!1&&(s=s.map(e=>Om(e)));let c=[...s.join(`
621
+ `)];for(let[e,t]of c.entries()){if(r+=t,_m.has(t)){let{groups:t}=RegExp(`(?:\\${bm}(?<code>\\d+)m|\\${Cm}(?<uri>.*)${ym})`).exec(c.slice(e).join(``))||{groups:{}};if(t.code!==void 0){let e=Number.parseFloat(t.code);i=e===vm?void 0:e}else t.uri!==void 0&&(a=t.uri.length===0?void 0:t.uri)}let n=gm.codes.get(Number(i));c[e+1]===`
622
+ `?(a&&(r+=Tm(``)),i&&n&&(r+=wm(n))):t===`
623
+ `&&(i&&n&&(r+=wm(i)),a&&(r+=Tm(a)))}return r},Am={actions:new Set([`up`,`down`,`left`,`right`,`space`,`enter`,`cancel`]),aliases:new Map([[`k`,`up`],[`j`,`down`],[`h`,`left`],[`l`,`right`],[``,`cancel`],[`escape`,`cancel`]])},globalThis.process.platform.startsWith(`win`),jm=Symbol(`clack:cancel`),Mm=Object.defineProperty,Nm=(e,t,n)=>t in e?Mm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Pm=(e,t,n)=>(Nm(e,typeof t==`symbol`?t:t+``,n),n),Fm=class{constructor(e,t=!0){Pm(this,`input`),Pm(this,`output`),Pm(this,`_abortSignal`),Pm(this,`rl`),Pm(this,`opts`),Pm(this,`_render`),Pm(this,`_track`,!1),Pm(this,`_prevFrame`,``),Pm(this,`_subscribers`,new Map),Pm(this,`_cursor`,0),Pm(this,`state`,`initial`),Pm(this,`error`,``),Pm(this,`value`);let{input:n=me,output:r=he,render:i,signal:a,...o}=e;this.opts=o,this.onKeypress=this.onKeypress.bind(this),this.close=this.close.bind(this),this.render=this.render.bind(this),this._render=i.bind(this),this._track=t,this._abortSignal=a,this.input=n,this.output=r}unsubscribe(){this._subscribers.clear()}setSubscriber(e,t){let n=this._subscribers.get(e)??[];n.push(t),this._subscribers.set(e,n)}on(e,t){this.setSubscriber(e,{cb:t})}once(e,t){this.setSubscriber(e,{cb:t,once:!0})}emit(e,...t){let n=this._subscribers.get(e)??[],r=[];for(let e of n)e.cb(...t),e.once&&r.push(()=>n.splice(n.indexOf(e),1));for(let e of r)e()}prompt(){return new Promise((e,t)=>{if(this._abortSignal){if(this._abortSignal.aborted)return this.state=`cancel`,this.close(),e(jm);this._abortSignal.addEventListener(`abort`,()=>{this.state=`cancel`,this.close()},{once:!0})}let n=new _e(0);n._write=(e,t,n)=>{this._track&&(this.value=this.rl?.line.replace(/\t/g,``),this._cursor=this.rl?.cursor??0,this.emit(`value`,this.value)),n()},this.input.pipe(n),this.rl=ve.createInterface({input:this.input,output:n,tabSize:2,prompt:``,escapeCodeTimeout:50}),ve.emitKeypressEvents(this.input,this.rl),this.rl.prompt(),this.opts.initialValue!==void 0&&this._track&&this.rl.write(this.opts.initialValue),this.input.on(`keypress`,this.onKeypress),Xp(this.input,!0),this.output.on(`resize`,this.render),this.render(),this.once(`submit`,()=>{this.output.write(tm.cursor.show),this.output.off(`resize`,this.render),Xp(this.input,!1),e(this.value)}),this.once(`cancel`,()=>{this.output.write(tm.cursor.show),this.output.off(`resize`,this.render),Xp(this.input,!1),e(jm)})})}onKeypress(e,t){if(this.state===`error`&&(this.state=`active`),t?.name&&(!this._track&&Am.aliases.has(t.name)&&this.emit(`cursor`,Am.aliases.get(t.name)),Am.actions.has(t.name)&&this.emit(`cursor`,t.name)),e&&(e.toLowerCase()===`y`||e.toLowerCase()===`n`)&&this.emit(`confirm`,e.toLowerCase()===`y`),e===` `&&this.opts.placeholder&&(this.value||(this.rl?.write(this.opts.placeholder),this.emit(`value`,this.opts.placeholder))),e&&this.emit(`key`,e.toLowerCase()),t?.name===`return`){if(this.opts.validate){let e=this.opts.validate(this.value);e&&(this.error=e instanceof Error?e.message:e,this.state=`error`,this.rl?.write(this.value))}this.state!==`error`&&(this.state=`submit`)}Jp([e,t?.name,t?.sequence],`cancel`)&&(this.state=`cancel`),(this.state===`submit`||this.state===`cancel`)&&this.emit(`finalize`),this.render(),(this.state===`submit`||this.state===`cancel`)&&this.close()}close(){this.input.unpipe(),this.input.removeListener(`keypress`,this.onKeypress),this.output.write(`
624
+ `),Xp(this.input,!1),this.rl?.close(),this.rl=void 0,this.emit(`${this.state}`,this.value),this.unsubscribe()}restoreCursor(){let e=qp(this._prevFrame,process.stdout.columns,{hard:!0}).split(`
625
+ `).length-1;this.output.write(tm.cursor.move(-999,e*-1))}render(){let e=qp(this._render(this)??``,process.stdout.columns,{hard:!0});if(e!==this._prevFrame){if(this.state===`initial`)this.output.write(tm.cursor.hide);else{let t=Yp(this._prevFrame,e);if(this.restoreCursor(),t&&t?.length===1){let n=t[0];this.output.write(tm.cursor.move(0,n)),this.output.write(tm.erase.lines(1));let r=e.split(`
626
+ `);this.output.write(r[n]),this._prevFrame=e,this.output.write(tm.cursor.move(0,r.length-n-1));return}if(t&&t?.length>1){let n=t[0];this.output.write(tm.cursor.move(0,n)),this.output.write(tm.erase.down());let r=e.split(`
627
627
  `).slice(n);this.output.write(r.join(`
628
- `)),this._prevFrame=e;return}this.output.write(Qp.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},Nm=class extends Mm{get cursor(){return+!this.value}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on(`value`,()=>{this.value=this._value}),this.on(`confirm`,e=>{this.output.write(Qp.cursor.move(0,-1)),this.value=e,this.state=`submit`,this.close()}),this.on(`cursor`,()=>{this.value=!this.value})}},Pm=Object.defineProperty,Fm=(e,t,n)=>t in e?Pm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Im=(e,t,n)=>(Fm(e,typeof t==`symbol`?t:t+``,n),n),Lm=class extends Mm{constructor(e){super(e,!1),Im(this,`options`),Im(this,`cursor`,0),this.options=e.options,this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:t})=>t===e.cursorAt),0),this.on(`key`,e=>{e===`a`&&this.toggleAll()}),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case`down`:case`right`:this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case`space`:this.toggleValue()}})}get _value(){return this.options[this.cursor].value}toggleAll(){let e=this.value.length===this.options.length;this.value=e?[]:this.options.map(e=>e.value)}toggleValue(){let e=this.value.includes(this._value);this.value=e?this.value.filter(e=>e!==this._value):[...this.value,this._value]}},Rm=Object.defineProperty,zm=(e,t,n)=>t in e?Rm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Bm=(e,t,n)=>(zm(e,typeof t==`symbol`?t:t+``,n),n),Vm=class extends Mm{constructor(e){super(e,!1),Bm(this,`options`),Bm(this,`cursor`,0),this.options=e.options,this.cursor=this.options.findIndex(({value:t})=>t===e.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case`down`:case`right`:this.cursor=this.cursor===this.options.length-1?0:this.cursor+1}this.changeValue()})}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value}},Hm=class extends Mm{get valueWithCursor(){if(this.state===`submit`)return this.value;if(this.cursor>=this.value.length)return`${this.value}\u2588`;let e=this.value.slice(0,this.cursor),[t,...n]=this.value.slice(this.cursor);return`${e}${J.inverse(t)}${n.join(``)}`}get cursor(){return this._cursor}constructor(e){super(e),this.on(`finalize`,()=>{this.value||=e.defaultValue})}},Um=Jp(),Wm=(e,t)=>Um?e:t,Gm=Wm(`❯`,`>`),Km=Wm(`■`,`x`),qm=Wm(`▲`,`x`),Jm=Wm(`✔`,`√`),X=Wm(``),Ym=Wm(``),Xm=Wm(`●`,`>`),Zm=Wm(`○`,` `),Qm=Wm(`◻`,`[•]`),$m=Wm(`◼`,`[+]`),eh=Wm(`◻`,`[ ]`),th=e=>{switch(e){case`initial`:case`active`:return J.cyan(Gm);case`cancel`:return J.red(Km);case`error`:return J.yellow(qm);case`submit`:return J.green(Jm)}},nh=e=>{let{cursor:t,options:n,style:r}=e,i=e.maxItems??1/0,a=Math.max(process.stdout.rows-4,0),o=Math.min(a,Math.max(i,5)),s=0;t>=s+o-3?s=Math.max(Math.min(t-o+3,n.length-o),0):t<s+2&&(s=Math.max(t-2,0));let c=o<n.length&&s>0,l=o<n.length&&s+o<n.length;return n.slice(s,s+o).map((e,n,i)=>{let a=n===0&&c,o=n===i.length-1&&l;return a||o?J.dim(`...`):r(e,n+s===t)})},rh=e=>new Hm({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,render(){let t=`${J.gray(X)}
629
- ${th(this.state)} ${e.message}
630
- `,n=e.placeholder?J.inverse(e.placeholder[0])+J.dim(e.placeholder.slice(1)):J.inverse(J.hidden(`_`)),r=this.value?this.valueWithCursor:n;switch(this.state){case`error`:return`${t.trim()}
631
- ${J.yellow(X)} ${r}
632
- ${J.yellow(Ym)} ${J.yellow(this.error)}
633
- `;case`submit`:return`${t}${J.gray(X)} ${J.dim(this.value||e.placeholder)}`;case`cancel`:return`${t}${J.gray(X)} ${J.strikethrough(J.dim(this.value??``))}${this.value?.trim()?`
634
- ${J.gray(X)}`:``}`;default:return`${t}${J.cyan(X)} ${r}
635
- ${J.cyan(Ym)}
636
- `}}}).prompt(),ih=e=>{let t=e.active??`Yes`,n=e.inactive??`No`;return new Nm({active:t,inactive:n,initialValue:e.initialValue??!0,render(){let r=`${J.gray(X)}
637
- ${th(this.state)} ${e.message}
638
- `,i=this.value?t:n;switch(this.state){case`submit`:return`${r}${J.gray(X)} ${J.dim(i)}`;case`cancel`:return`${r}${J.gray(X)} ${J.strikethrough(J.dim(i))}
639
- ${J.gray(X)}`;default:return`${r}${J.cyan(X)} ${this.value?`${J.green(Xm)} ${t}`:`${J.dim(Zm)} ${J.dim(t)}`} ${J.dim(`/`)} ${this.value?`${J.dim(Zm)} ${J.dim(n)}`:`${J.green(Xm)} ${n}`}
640
- ${J.cyan(Ym)}
641
- `}}}).prompt()},ah=e=>{let t=(e,t)=>{let n=e.label??String(e.value);switch(t){case`selected`:return`${J.dim(n)}`;case`active`:return`${J.green(Xm)} ${n} ${e.hint?J.dim(`(${e.hint})`):``}`;case`cancelled`:return`${J.strikethrough(J.dim(n))}`;default:return`${J.dim(Zm)} ${J.dim(n)}`}};return new Vm({options:e.options,initialValue:e.initialValue,render(){let n=`${J.gray(X)}
642
- ${th(this.state)} ${e.message}
643
- `;switch(this.state){case`submit`:return`${n}${J.gray(X)} ${t(this.options[this.cursor],`selected`)}`;case`cancel`:return`${n}${J.gray(X)} ${t(this.options[this.cursor],`cancelled`)}
644
- ${J.gray(X)}`;default:return`${n}${J.cyan(X)} ${nh({cursor:this.cursor,options:this.options,maxItems:e.maxItems,style:(e,n)=>t(e,n?`active`:`inactive`)}).join(`
645
- ${J.cyan(X)} `)}
646
- ${J.cyan(Ym)}
647
- `}}}).prompt()},oh=e=>{let t=(e,t)=>{let n=e.label??String(e.value);return t===`active`?`${J.cyan(Qm)} ${n} ${e.hint?J.dim(`(${e.hint})`):``}`:t===`selected`?`${J.green($m)} ${J.dim(n)}`:t===`cancelled`?`${J.strikethrough(J.dim(n))}`:t===`active-selected`?`${J.green($m)} ${n} ${e.hint?J.dim(`(${e.hint})`):``}`:t===`submitted`?`${J.dim(n)}`:`${J.dim(eh)} ${J.dim(n)}`};return new Lm({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(e){if(this.required&&e.length===0)return`Please select at least one option.
648
- ${J.reset(J.dim(`Press ${J.gray(J.bgWhite(J.inverse(` space `)))} to select, ${J.gray(J.bgWhite(J.inverse(` enter `)))} to submit`))}`},render(){let n=`${J.gray(X)}
649
- ${th(this.state)} ${e.message}
650
- `,r=(e,n)=>{let r=this.value.includes(e.value);return n&&r?t(e,`active-selected`):r?t(e,`selected`):t(e,n?`active`:`inactive`)};switch(this.state){case`submit`:return`${n}${J.gray(X)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>t(e,`submitted`)).join(J.dim(`, `))||J.dim(`none`)}`;case`cancel`:{let e=this.options.filter(({value:e})=>this.value.includes(e)).map(e=>t(e,`cancelled`)).join(J.dim(`, `));return`${n}${J.gray(X)} ${e.trim()?`${e}
651
- ${J.gray(X)}`:``}`}case`error`:{let t=this.error.split(`
652
- `).map((e,t)=>t===0?`${J.yellow(Ym)} ${J.yellow(e)}`:` ${e}`).join(`
653
- `);return`${n+J.yellow(X)} ${nh({options:this.options,cursor:this.cursor,maxItems:e.maxItems,style:r}).join(`
654
- ${J.yellow(X)} `)}
628
+ `)),this._prevFrame=e;return}this.output.write(tm.erase.down())}this.output.write(e),this.state===`initial`&&(this.state=`active`),this._prevFrame=e}}},Im=class extends Fm{get cursor(){return+!this.value}get _value(){return this.cursor===0}constructor(e){super(e,!1),this.value=!!e.initialValue,this.on(`value`,()=>{this.value=this._value}),this.on(`confirm`,e=>{this.output.write(tm.cursor.move(0,-1)),this.value=e,this.state=`submit`,this.close()}),this.on(`cursor`,()=>{this.value=!this.value})}},Lm=Object.defineProperty,Rm=(e,t,n)=>t in e?Lm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,zm=(e,t,n)=>(Rm(e,typeof t==`symbol`?t:t+``,n),n),Bm=class extends Fm{constructor(e){super(e,!1),zm(this,`options`),zm(this,`cursor`,0),this.options=e.options,this.value=[...e.initialValues??[]],this.cursor=Math.max(this.options.findIndex(({value:t})=>t===e.cursorAt),0),this.on(`key`,e=>{e===`a`&&this.toggleAll()}),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case`down`:case`right`:this.cursor=this.cursor===this.options.length-1?0:this.cursor+1;break;case`space`:this.toggleValue()}})}get _value(){return this.options[this.cursor].value}toggleAll(){let e=this.value.length===this.options.length;this.value=e?[]:this.options.map(e=>e.value)}toggleValue(){let e=this.value.includes(this._value);this.value=e?this.value.filter(e=>e!==this._value):[...this.value,this._value]}},Vm=Object.defineProperty,Hm=(e,t,n)=>t in e?Vm(e,t,{enumerable:!0,configurable:!0,writable:!0,value:n}):e[t]=n,Um=(e,t,n)=>(Hm(e,typeof t==`symbol`?t:t+``,n),n),Wm=class extends Fm{constructor(e){super(e,!1),Um(this,`options`),Um(this,`cursor`,0),this.options=e.options,this.cursor=this.options.findIndex(({value:t})=>t===e.initialValue),this.cursor===-1&&(this.cursor=0),this.changeValue(),this.on(`cursor`,e=>{switch(e){case`left`:case`up`:this.cursor=this.cursor===0?this.options.length-1:this.cursor-1;break;case`down`:case`right`:this.cursor=this.cursor===this.options.length-1?0:this.cursor+1}this.changeValue()})}get _value(){return this.options[this.cursor]}changeValue(){this.value=this._value.value}},Gm=class extends Fm{get valueWithCursor(){if(this.state===`submit`)return this.value;if(this.cursor>=this.value.length)return`${this.value}\u2588`;let e=this.value.slice(0,this.cursor),[t,...n]=this.value.slice(this.cursor);return`${e}${Y.inverse(t)}${n.join(``)}`}get cursor(){return this._cursor}constructor(e){super(e),this.on(`finalize`,()=>{this.value||=e.defaultValue})}},Km=Zp(),qm=(e,t)=>Km?e:t,Jm=qm(`❯`,`>`),Ym=qm(`■`,`x`),Xm=qm(`▲`,`x`),Zm=qm(`✔`,`√`),Z=qm(``),Qm=qm(``),$m=qm(`●`,`>`),eh=qm(`○`,` `),th=qm(`◻`,`[•]`),nh=qm(`◼`,`[+]`),rh=qm(`◻`,`[ ]`),ih=e=>{switch(e){case`initial`:case`active`:return Y.cyan(Jm);case`cancel`:return Y.red(Ym);case`error`:return Y.yellow(Xm);case`submit`:return Y.green(Zm)}},ah=e=>{let{cursor:t,options:n,style:r}=e,i=e.maxItems??1/0,a=Math.max(process.stdout.rows-4,0),o=Math.min(a,Math.max(i,5)),s=0;t>=s+o-3?s=Math.max(Math.min(t-o+3,n.length-o),0):t<s+2&&(s=Math.max(t-2,0));let c=o<n.length&&s>0,l=o<n.length&&s+o<n.length;return n.slice(s,s+o).map((e,n,i)=>{let a=n===0&&c,o=n===i.length-1&&l;return a||o?Y.dim(`...`):r(e,n+s===t)})},oh=e=>new Gm({validate:e.validate,placeholder:e.placeholder,defaultValue:e.defaultValue,initialValue:e.initialValue,render(){let t=`${Y.gray(Z)}
629
+ ${ih(this.state)} ${e.message}
630
+ `,n=e.placeholder?Y.inverse(e.placeholder[0])+Y.dim(e.placeholder.slice(1)):Y.inverse(Y.hidden(`_`)),r=this.value?this.valueWithCursor:n;switch(this.state){case`error`:return`${t.trim()}
631
+ ${Y.yellow(Z)} ${r}
632
+ ${Y.yellow(Qm)} ${Y.yellow(this.error)}
633
+ `;case`submit`:return`${t}${Y.gray(Z)} ${Y.dim(this.value||e.placeholder)}`;case`cancel`:return`${t}${Y.gray(Z)} ${Y.strikethrough(Y.dim(this.value??``))}${this.value?.trim()?`
634
+ ${Y.gray(Z)}`:``}`;default:return`${t}${Y.cyan(Z)} ${r}
635
+ ${Y.cyan(Qm)}
636
+ `}}}).prompt(),sh=e=>{let t=e.active??`Yes`,n=e.inactive??`No`;return new Im({active:t,inactive:n,initialValue:e.initialValue??!0,render(){let r=`${Y.gray(Z)}
637
+ ${ih(this.state)} ${e.message}
638
+ `,i=this.value?t:n;switch(this.state){case`submit`:return`${r}${Y.gray(Z)} ${Y.dim(i)}`;case`cancel`:return`${r}${Y.gray(Z)} ${Y.strikethrough(Y.dim(i))}
639
+ ${Y.gray(Z)}`;default:return`${r}${Y.cyan(Z)} ${this.value?`${Y.green($m)} ${t}`:`${Y.dim(eh)} ${Y.dim(t)}`} ${Y.dim(`/`)} ${this.value?`${Y.dim(eh)} ${Y.dim(n)}`:`${Y.green($m)} ${n}`}
640
+ ${Y.cyan(Qm)}
641
+ `}}}).prompt()},ch=e=>{let t=(e,t)=>{let n=e.label??String(e.value);switch(t){case`selected`:return`${Y.dim(n)}`;case`active`:return`${Y.green($m)} ${n} ${e.hint?Y.dim(`(${e.hint})`):``}`;case`cancelled`:return`${Y.strikethrough(Y.dim(n))}`;default:return`${Y.dim(eh)} ${Y.dim(n)}`}};return new Wm({options:e.options,initialValue:e.initialValue,render(){let n=`${Y.gray(Z)}
642
+ ${ih(this.state)} ${e.message}
643
+ `;switch(this.state){case`submit`:return`${n}${Y.gray(Z)} ${t(this.options[this.cursor],`selected`)}`;case`cancel`:return`${n}${Y.gray(Z)} ${t(this.options[this.cursor],`cancelled`)}
644
+ ${Y.gray(Z)}`;default:return`${n}${Y.cyan(Z)} ${ah({cursor:this.cursor,options:this.options,maxItems:e.maxItems,style:(e,n)=>t(e,n?`active`:`inactive`)}).join(`
645
+ ${Y.cyan(Z)} `)}
646
+ ${Y.cyan(Qm)}
647
+ `}}}).prompt()},lh=e=>{let t=(e,t)=>{let n=e.label??String(e.value);return t===`active`?`${Y.cyan(th)} ${n} ${e.hint?Y.dim(`(${e.hint})`):``}`:t===`selected`?`${Y.green(nh)} ${Y.dim(n)}`:t===`cancelled`?`${Y.strikethrough(Y.dim(n))}`:t===`active-selected`?`${Y.green(nh)} ${n} ${e.hint?Y.dim(`(${e.hint})`):``}`:t===`submitted`?`${Y.dim(n)}`:`${Y.dim(rh)} ${Y.dim(n)}`};return new Bm({options:e.options,initialValues:e.initialValues,required:e.required??!0,cursorAt:e.cursorAt,validate(e){if(this.required&&e.length===0)return`Please select at least one option.
648
+ ${Y.reset(Y.dim(`Press ${Y.gray(Y.bgWhite(Y.inverse(` space `)))} to select, ${Y.gray(Y.bgWhite(Y.inverse(` enter `)))} to submit`))}`},render(){let n=`${Y.gray(Z)}
649
+ ${ih(this.state)} ${e.message}
650
+ `,r=(e,n)=>{let r=this.value.includes(e.value);return n&&r?t(e,`active-selected`):r?t(e,`selected`):t(e,n?`active`:`inactive`)};switch(this.state){case`submit`:return`${n}${Y.gray(Z)} ${this.options.filter(({value:e})=>this.value.includes(e)).map(e=>t(e,`submitted`)).join(Y.dim(`, `))||Y.dim(`none`)}`;case`cancel`:{let e=this.options.filter(({value:e})=>this.value.includes(e)).map(e=>t(e,`cancelled`)).join(Y.dim(`, `));return`${n}${Y.gray(Z)} ${e.trim()?`${e}
651
+ ${Y.gray(Z)}`:``}`}case`error`:{let t=this.error.split(`
652
+ `).map((e,t)=>t===0?`${Y.yellow(Qm)} ${Y.yellow(e)}`:` ${e}`).join(`
653
+ `);return`${n+Y.yellow(Z)} ${ah({options:this.options,cursor:this.cursor,maxItems:e.maxItems,style:r}).join(`
654
+ ${Y.yellow(Z)} `)}
655
655
  ${t}
656
- `}default:return`${n}${J.cyan(X)} ${nh({options:this.options,cursor:this.cursor,maxItems:e.maxItems,style:r}).join(`
657
- ${J.cyan(X)} `)}
658
- ${J.cyan(Ym)}
659
- `}}}).prompt()},`${J.gray(X)}`,sh=Symbol.for(`cancel`)}));const lh=Object.create(null),uh=e=>globalThis.process?.env||import.meta.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?lh:globalThis),dh=new Proxy(lh,{get(e,t){return uh()[t]??lh[t]},has(e,t){return t in uh()||t in lh},set(e,t,n){let r=uh(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=uh(!0);return delete n[t],!0},ownKeys(){let e=uh(!0);return Object.keys(e)}}),fh=typeof process<`u`&&process.env&&process.env.NODE_ENV||``,ph=[[`APPVEYOR`],[`AWS_AMPLIFY`,`AWS_APP_ID`,{ci:!0}],[`AZURE_PIPELINES`,`SYSTEM_TEAMFOUNDATIONCOLLECTIONURI`],[`AZURE_STATIC`,`INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN`],[`APPCIRCLE`,`AC_APPCIRCLE`],[`BAMBOO`,`bamboo_planKey`],[`BITBUCKET`,`BITBUCKET_COMMIT`],[`BITRISE`,`BITRISE_IO`],[`BUDDY`,`BUDDY_WORKSPACE_ID`],[`BUILDKITE`],[`CIRCLE`,`CIRCLECI`],[`CIRRUS`,`CIRRUS_CI`],[`CLOUDFLARE_PAGES`,`CF_PAGES`,{ci:!0}],[`CODEBUILD`,`CODEBUILD_BUILD_ARN`],[`CODEFRESH`,`CF_BUILD_ID`],[`DRONE`],[`DRONE`,`DRONE_BUILD_EVENT`],[`DSARI`],[`GITHUB_ACTIONS`],[`GITLAB`,`GITLAB_CI`],[`GITLAB`,`CI_MERGE_REQUEST_ID`],[`GOCD`,`GO_PIPELINE_LABEL`],[`LAYERCI`],[`HUDSON`,`HUDSON_URL`],[`JENKINS`,`JENKINS_URL`],[`MAGNUM`],[`NETLIFY`],[`NETLIFY`,`NETLIFY_LOCAL`,{ci:!1}],[`NEVERCODE`],[`RENDER`],[`SAIL`,`SAILCI`],[`SEMAPHORE`],[`SCREWDRIVER`],[`SHIPPABLE`],[`SOLANO`,`TDDIUM`],[`STRIDER`],[`TEAMCITY`,`TEAMCITY_VERSION`],[`TRAVIS`],[`VERCEL`,`NOW_BUILDER`],[`VERCEL`,`VERCEL`,{ci:!1}],[`VERCEL`,`VERCEL_ENV`,{ci:!1}],[`APPCENTER`,`APPCENTER_BUILD_ID`],[`CODESANDBOX`,`CODESANDBOX_SSE`,{ci:!1}],[`CODESANDBOX`,`CODESANDBOX_HOST`,{ci:!1}],[`STACKBLITZ`],[`STORMKIT`],[`CLEAVR`],[`ZEABUR`],[`CODESPHERE`,`CODESPHERE_APP_ID`,{ci:!0}],[`RAILWAY`,`RAILWAY_PROJECT_ID`],[`RAILWAY`,`RAILWAY_SERVICE_ID`],[`DENO-DEPLOY`,`DENO_DEPLOYMENT_ID`],[`FIREBASE_APP_HOSTING`,`FIREBASE_APP_HOSTING`,{ci:!0}]];function mh(){if(globalThis.process?.env)for(let e of ph){let t=e[1]||e[0];if(globalThis.process?.env[t])return{name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL===`/bin/jsh`&&globalThis.process?.versions?.webcontainer?{name:`stackblitz`,ci:!1}:{name:``,ci:!1}}const hh=mh();hh.name;function gh(e){return e?e!==`false`:!1}const _h=globalThis.process?.platform||``,vh=gh(dh.CI)||hh.ci!==!1,yh=gh(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),bh=gh(dh.DEBUG),xh=fh===`test`||gh(dh.TEST);dh.MINIMAL;const Sh=/^win/i.test(_h);!gh(dh.NO_COLOR)&&(gh(dh.FORCE_COLOR)||(yh||Sh)&&dh.TERM);const Ch=(globalThis.process?.versions?.node||``).replace(/^v/,``)||null;Number(Ch?.split(`.`)[0]);const wh=globalThis.process||Object.create(null),Th={versions:{}};new Proxy(wh,{get(e,t){if(t===`env`)return dh;if(t in e)return e[t];if(t in Th)return Th[t]}});const Eh=globalThis.process?.release?.name===`node`,Dh=!!globalThis.Bun||!!globalThis.process?.versions?.bun,Oh=!!globalThis.Deno,kh=!!globalThis.fastly,Ah=!!globalThis.Netlify,jh=!!globalThis.EdgeRuntime,Mh=globalThis.navigator?.userAgent===`Cloudflare-Workers`,Nh=[[Ah,`netlify`],[jh,`edge-light`],[Mh,`workerd`],[kh,`fastly`],[Oh,`deno`],[Dh,`bun`],[Eh,`node`]];function Ph(){let e=Nh.find(e=>e[0]);if(e)return{name:e[1]}}Ph()?.name;function Fh({onlyFirst:e=!1}={}){let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}const Ih=Fh();function Lh(e){if(typeof e!=`string`)throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(Ih,``)}function Rh(e){return e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109}function zh(e){return e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510}function Bh(e){return e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9776&&e<=9783||e>=9800&&e<=9811||e===9855||e>=9866&&e<=9871||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12773||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101631&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e>=119552&&e<=119638||e>=119648&&e<=119670||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129673||e>=129679&&e<=129734||e>=129742&&e<=129756||e>=129759&&e<=129769||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141}function Vh(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function Hh(e,{ambiguousAsWide:t=!1}={}){return Vh(e),zh(e)||Bh(e)||t&&Rh(e)?2:1}const Uh=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g,Wh=globalThis.Intl?.Segmenter?new Intl.Segmenter:{segment:e=>e.split(``)},Gh=/^\p{Default_Ignorable_Code_Point}$/u;function Kh(e,t={}){if(typeof e!=`string`||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:r=!1}=t;if(r||(e=Lh(e)),e.length===0)return 0;let i=0,a={ambiguousAsWide:!n};for(let{segment:t}of Wh.segment(e)){let e=t.codePointAt(0);if(!(e<=31||e>=127&&e<=159)&&!(e>=8203&&e<=8207||e===65279)&&!(e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071)&&!(e>=55296&&e<=57343)&&!(e>=65024&&e<=65039)&&!Gh.test(t)){if(Uh().test(t)){i+=2;continue}i+=Hh(e,a)}}return i}function qh(){let{env:e}=pe,{TERM:t,TERM_PROGRAM:n}=e;return pe.platform===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||n===`Terminus-Sublime`||n===`vscode`||t===`xterm-256color`||t===`alacritty`||t===`rxvt-unicode`||t===`rxvt-unicode-256color`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`:t!==`linux`}const Jh={info:`cyan`,fail:`red`,success:`green`,ready:`green`,start:`magenta`},Yh={0:`red`,1:`yellow`},Xh=qh(),Zh=(e,t)=>Xh?e:t,Qh={error:Zh(`✖`,`×`),fatal:Zh(`✖`,`×`),ready:Zh(`✔`,`√`),warn:Zh(`⚠`,`‼`),info:Zh(`ℹ`,`i`),success:Zh(`✔`,`√`),debug:Zh(`⚙`,`D`),trace:Zh(`→`,`→`),fail:Zh(`✖`,`×`),start:Zh(`◐`,`o`),log:``};function $h(e){return typeof Intl!=`object`||!Intl.Segmenter?jp(e).length:Kh(e)}var eg=class extends fp{formatStack(e,t,n){let r=` `.repeat((n?.errorLevel||0)+1);return`
660
- ${r}`+lp(e,t).map(e=>` `+e.replace(/^at +/,e=>Op.gray(e)).replace(/\((.+)\)/,(e,t)=>`(${Op.cyan(t)})`)).join(`
661
- ${r}`)}formatType(e,t,n){let r=Jh[e.type]||Yh[e.level]||`gray`;if(t)return rg(r)(Op.black(` ${e.type.toUpperCase()} `));let i=typeof Qh[e.type]==`string`?Qh[e.type]:e.icon||e.type;return i?ng(r)(i):``}formatLogObj(e,t){let[n,...r]=this.formatArgs(e.args,t).split(`
662
- `);if(e.type===`box`)return Pp(tg(n+(r.length>0?`
656
+ `}default:return`${n}${Y.cyan(Z)} ${ah({options:this.options,cursor:this.cursor,maxItems:e.maxItems,style:r}).join(`
657
+ ${Y.cyan(Z)} `)}
658
+ ${Y.cyan(Qm)}
659
+ `}}}).prompt()},`${Y.gray(Z)}`,uh=Symbol.for(`cancel`)}));const fh=Object.create(null),ph=e=>globalThis.process?.env||import.meta.env||globalThis.Deno?.env.toObject()||globalThis.__env__||(e?fh:globalThis),mh=new Proxy(fh,{get(e,t){return ph()[t]??fh[t]},has(e,t){return t in ph()||t in fh},set(e,t,n){let r=ph(!0);return r[t]=n,!0},deleteProperty(e,t){if(!t)return!1;let n=ph(!0);return delete n[t],!0},ownKeys(){let e=ph(!0);return Object.keys(e)}}),hh=typeof process<`u`&&process.env&&process.env.NODE_ENV||``,gh=[[`APPVEYOR`],[`AWS_AMPLIFY`,`AWS_APP_ID`,{ci:!0}],[`AZURE_PIPELINES`,`SYSTEM_TEAMFOUNDATIONCOLLECTIONURI`],[`AZURE_STATIC`,`INPUT_AZURE_STATIC_WEB_APPS_API_TOKEN`],[`APPCIRCLE`,`AC_APPCIRCLE`],[`BAMBOO`,`bamboo_planKey`],[`BITBUCKET`,`BITBUCKET_COMMIT`],[`BITRISE`,`BITRISE_IO`],[`BUDDY`,`BUDDY_WORKSPACE_ID`],[`BUILDKITE`],[`CIRCLE`,`CIRCLECI`],[`CIRRUS`,`CIRRUS_CI`],[`CLOUDFLARE_PAGES`,`CF_PAGES`,{ci:!0}],[`CODEBUILD`,`CODEBUILD_BUILD_ARN`],[`CODEFRESH`,`CF_BUILD_ID`],[`DRONE`],[`DRONE`,`DRONE_BUILD_EVENT`],[`DSARI`],[`GITHUB_ACTIONS`],[`GITLAB`,`GITLAB_CI`],[`GITLAB`,`CI_MERGE_REQUEST_ID`],[`GOCD`,`GO_PIPELINE_LABEL`],[`LAYERCI`],[`HUDSON`,`HUDSON_URL`],[`JENKINS`,`JENKINS_URL`],[`MAGNUM`],[`NETLIFY`],[`NETLIFY`,`NETLIFY_LOCAL`,{ci:!1}],[`NEVERCODE`],[`RENDER`],[`SAIL`,`SAILCI`],[`SEMAPHORE`],[`SCREWDRIVER`],[`SHIPPABLE`],[`SOLANO`,`TDDIUM`],[`STRIDER`],[`TEAMCITY`,`TEAMCITY_VERSION`],[`TRAVIS`],[`VERCEL`,`NOW_BUILDER`],[`VERCEL`,`VERCEL`,{ci:!1}],[`VERCEL`,`VERCEL_ENV`,{ci:!1}],[`APPCENTER`,`APPCENTER_BUILD_ID`],[`CODESANDBOX`,`CODESANDBOX_SSE`,{ci:!1}],[`CODESANDBOX`,`CODESANDBOX_HOST`,{ci:!1}],[`STACKBLITZ`],[`STORMKIT`],[`CLEAVR`],[`ZEABUR`],[`CODESPHERE`,`CODESPHERE_APP_ID`,{ci:!0}],[`RAILWAY`,`RAILWAY_PROJECT_ID`],[`RAILWAY`,`RAILWAY_SERVICE_ID`],[`DENO-DEPLOY`,`DENO_DEPLOYMENT_ID`],[`FIREBASE_APP_HOSTING`,`FIREBASE_APP_HOSTING`,{ci:!0}]];function _h(){if(globalThis.process?.env)for(let e of gh){let t=e[1]||e[0];if(globalThis.process?.env[t])return{name:e[0].toLowerCase(),...e[2]}}return globalThis.process?.env?.SHELL===`/bin/jsh`&&globalThis.process?.versions?.webcontainer?{name:`stackblitz`,ci:!1}:{name:``,ci:!1}}const vh=_h();vh.name;function yh(e){return e?e!==`false`:!1}const bh=globalThis.process?.platform||``,xh=yh(mh.CI)||vh.ci!==!1,Sh=yh(globalThis.process?.stdout&&globalThis.process?.stdout.isTTY),Ch=yh(mh.DEBUG),wh=hh===`test`||yh(mh.TEST);mh.MINIMAL;const Th=/^win/i.test(bh);!yh(mh.NO_COLOR)&&(yh(mh.FORCE_COLOR)||(Sh||Th)&&mh.TERM);const Eh=(globalThis.process?.versions?.node||``).replace(/^v/,``)||null;Number(Eh?.split(`.`)[0]);const Dh=globalThis.process||Object.create(null),Oh={versions:{}};new Proxy(Dh,{get(e,t){if(t===`env`)return mh;if(t in e)return e[t];if(t in Oh)return Oh[t]}});const kh=globalThis.process?.release?.name===`node`,Ah=!!globalThis.Bun||!!globalThis.process?.versions?.bun,jh=!!globalThis.Deno,Mh=!!globalThis.fastly,Nh=!!globalThis.Netlify,Ph=!!globalThis.EdgeRuntime,Fh=globalThis.navigator?.userAgent===`Cloudflare-Workers`,Ih=[[Nh,`netlify`],[Ph,`edge-light`],[Fh,`workerd`],[Mh,`fastly`],[jh,`deno`],[Ah,`bun`],[kh,`node`]];function Lh(){let e=Ih.find(e=>e[0]);if(e)return{name:e[1]}}Lh()?.name;function Rh({onlyFirst:e=!1}={}){let t=[`[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]+)*|[a-zA-Z\\d]+(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?(?:\\u0007|\\u001B\\u005C|\\u009C))`,`(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-nq-uy=><~]))`].join(`|`);return new RegExp(t,e?void 0:`g`)}const zh=Rh();function Bh(e){if(typeof e!=`string`)throw TypeError(`Expected a \`string\`, got \`${typeof e}\``);return e.replace(zh,``)}function Vh(e){return e===161||e===164||e===167||e===168||e===170||e===173||e===174||e>=176&&e<=180||e>=182&&e<=186||e>=188&&e<=191||e===198||e===208||e===215||e===216||e>=222&&e<=225||e===230||e>=232&&e<=234||e===236||e===237||e===240||e===242||e===243||e>=247&&e<=250||e===252||e===254||e===257||e===273||e===275||e===283||e===294||e===295||e===299||e>=305&&e<=307||e===312||e>=319&&e<=322||e===324||e>=328&&e<=331||e===333||e===338||e===339||e===358||e===359||e===363||e===462||e===464||e===466||e===468||e===470||e===472||e===474||e===476||e===593||e===609||e===708||e===711||e>=713&&e<=715||e===717||e===720||e>=728&&e<=731||e===733||e===735||e>=768&&e<=879||e>=913&&e<=929||e>=931&&e<=937||e>=945&&e<=961||e>=963&&e<=969||e===1025||e>=1040&&e<=1103||e===1105||e===8208||e>=8211&&e<=8214||e===8216||e===8217||e===8220||e===8221||e>=8224&&e<=8226||e>=8228&&e<=8231||e===8240||e===8242||e===8243||e===8245||e===8251||e===8254||e===8308||e===8319||e>=8321&&e<=8324||e===8364||e===8451||e===8453||e===8457||e===8467||e===8470||e===8481||e===8482||e===8486||e===8491||e===8531||e===8532||e>=8539&&e<=8542||e>=8544&&e<=8555||e>=8560&&e<=8569||e===8585||e>=8592&&e<=8601||e===8632||e===8633||e===8658||e===8660||e===8679||e===8704||e===8706||e===8707||e===8711||e===8712||e===8715||e===8719||e===8721||e===8725||e===8730||e>=8733&&e<=8736||e===8739||e===8741||e>=8743&&e<=8748||e===8750||e>=8756&&e<=8759||e===8764||e===8765||e===8776||e===8780||e===8786||e===8800||e===8801||e>=8804&&e<=8807||e===8810||e===8811||e===8814||e===8815||e===8834||e===8835||e===8838||e===8839||e===8853||e===8857||e===8869||e===8895||e===8978||e>=9312&&e<=9449||e>=9451&&e<=9547||e>=9552&&e<=9587||e>=9600&&e<=9615||e>=9618&&e<=9621||e===9632||e===9633||e>=9635&&e<=9641||e===9650||e===9651||e===9654||e===9655||e===9660||e===9661||e===9664||e===9665||e>=9670&&e<=9672||e===9675||e>=9678&&e<=9681||e>=9698&&e<=9701||e===9711||e===9733||e===9734||e===9737||e===9742||e===9743||e===9756||e===9758||e===9792||e===9794||e===9824||e===9825||e>=9827&&e<=9829||e>=9831&&e<=9834||e===9836||e===9837||e===9839||e===9886||e===9887||e===9919||e>=9926&&e<=9933||e>=9935&&e<=9939||e>=9941&&e<=9953||e===9955||e===9960||e===9961||e>=9963&&e<=9969||e===9972||e>=9974&&e<=9977||e===9979||e===9980||e===9982||e===9983||e===10045||e>=10102&&e<=10111||e>=11094&&e<=11097||e>=12872&&e<=12879||e>=57344&&e<=63743||e>=65024&&e<=65039||e===65533||e>=127232&&e<=127242||e>=127248&&e<=127277||e>=127280&&e<=127337||e>=127344&&e<=127373||e===127375||e===127376||e>=127387&&e<=127404||e>=917760&&e<=917999||e>=983040&&e<=1048573||e>=1048576&&e<=1114109}function Hh(e){return e===12288||e>=65281&&e<=65376||e>=65504&&e<=65510}function Uh(e){return e>=4352&&e<=4447||e===8986||e===8987||e===9001||e===9002||e>=9193&&e<=9196||e===9200||e===9203||e===9725||e===9726||e===9748||e===9749||e>=9776&&e<=9783||e>=9800&&e<=9811||e===9855||e>=9866&&e<=9871||e===9875||e===9889||e===9898||e===9899||e===9917||e===9918||e===9924||e===9925||e===9934||e===9940||e===9962||e===9970||e===9971||e===9973||e===9978||e===9981||e===9989||e===9994||e===9995||e===10024||e===10060||e===10062||e>=10067&&e<=10069||e===10071||e>=10133&&e<=10135||e===10160||e===10175||e===11035||e===11036||e===11088||e===11093||e>=11904&&e<=11929||e>=11931&&e<=12019||e>=12032&&e<=12245||e>=12272&&e<=12287||e>=12289&&e<=12350||e>=12353&&e<=12438||e>=12441&&e<=12543||e>=12549&&e<=12591||e>=12593&&e<=12686||e>=12688&&e<=12773||e>=12783&&e<=12830||e>=12832&&e<=12871||e>=12880&&e<=42124||e>=42128&&e<=42182||e>=43360&&e<=43388||e>=44032&&e<=55203||e>=63744&&e<=64255||e>=65040&&e<=65049||e>=65072&&e<=65106||e>=65108&&e<=65126||e>=65128&&e<=65131||e>=94176&&e<=94180||e===94192||e===94193||e>=94208&&e<=100343||e>=100352&&e<=101589||e>=101631&&e<=101640||e>=110576&&e<=110579||e>=110581&&e<=110587||e===110589||e===110590||e>=110592&&e<=110882||e===110898||e>=110928&&e<=110930||e===110933||e>=110948&&e<=110951||e>=110960&&e<=111355||e>=119552&&e<=119638||e>=119648&&e<=119670||e===126980||e===127183||e===127374||e>=127377&&e<=127386||e>=127488&&e<=127490||e>=127504&&e<=127547||e>=127552&&e<=127560||e===127568||e===127569||e>=127584&&e<=127589||e>=127744&&e<=127776||e>=127789&&e<=127797||e>=127799&&e<=127868||e>=127870&&e<=127891||e>=127904&&e<=127946||e>=127951&&e<=127955||e>=127968&&e<=127984||e===127988||e>=127992&&e<=128062||e===128064||e>=128066&&e<=128252||e>=128255&&e<=128317||e>=128331&&e<=128334||e>=128336&&e<=128359||e===128378||e===128405||e===128406||e===128420||e>=128507&&e<=128591||e>=128640&&e<=128709||e===128716||e>=128720&&e<=128722||e>=128725&&e<=128727||e>=128732&&e<=128735||e===128747||e===128748||e>=128756&&e<=128764||e>=128992&&e<=129003||e===129008||e>=129292&&e<=129338||e>=129340&&e<=129349||e>=129351&&e<=129535||e>=129648&&e<=129660||e>=129664&&e<=129673||e>=129679&&e<=129734||e>=129742&&e<=129756||e>=129759&&e<=129769||e>=129776&&e<=129784||e>=131072&&e<=196605||e>=196608&&e<=262141}function Wh(e){if(!Number.isSafeInteger(e))throw TypeError(`Expected a code point, got \`${typeof e}\`.`)}function Gh(e,{ambiguousAsWide:t=!1}={}){return Wh(e),Hh(e)||Uh(e)||t&&Vh(e)?2:1}const Kh=()=>/[#*0-9]\uFE0F?\u20E3|[\xA9\xAE\u203C\u2049\u2122\u2139\u2194-\u2199\u21A9\u21AA\u231A\u231B\u2328\u23CF\u23ED-\u23EF\u23F1\u23F2\u23F8-\u23FA\u24C2\u25AA\u25AB\u25B6\u25C0\u25FB\u25FC\u25FE\u2600-\u2604\u260E\u2611\u2614\u2615\u2618\u2620\u2622\u2623\u2626\u262A\u262E\u262F\u2638-\u263A\u2640\u2642\u2648-\u2653\u265F\u2660\u2663\u2665\u2666\u2668\u267B\u267E\u267F\u2692\u2694-\u2697\u2699\u269B\u269C\u26A0\u26A7\u26AA\u26B0\u26B1\u26BD\u26BE\u26C4\u26C8\u26CF\u26D1\u26E9\u26F0-\u26F5\u26F7\u26F8\u26FA\u2702\u2708\u2709\u270F\u2712\u2714\u2716\u271D\u2721\u2733\u2734\u2744\u2747\u2757\u2763\u27A1\u2934\u2935\u2B05-\u2B07\u2B1B\u2B1C\u2B55\u3030\u303D\u3297\u3299]\uFE0F?|[\u261D\u270C\u270D](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\u270A\u270B](?:\uD83C[\uDFFB-\uDFFF])?|[\u23E9-\u23EC\u23F0\u23F3\u25FD\u2693\u26A1\u26AB\u26C5\u26CE\u26D4\u26EA\u26FD\u2705\u2728\u274C\u274E\u2753-\u2755\u2795-\u2797\u27B0\u27BF\u2B50]|\u26D3\uFE0F?(?:\u200D\uD83D\uDCA5)?|\u26F9(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\u2764\uFE0F?(?:\u200D(?:\uD83D\uDD25|\uD83E\uDE79))?|\uD83C(?:[\uDC04\uDD70\uDD71\uDD7E\uDD7F\uDE02\uDE37\uDF21\uDF24-\uDF2C\uDF36\uDF7D\uDF96\uDF97\uDF99-\uDF9B\uDF9E\uDF9F\uDFCD\uDFCE\uDFD4-\uDFDF\uDFF5\uDFF7]\uFE0F?|[\uDF85\uDFC2\uDFC7](?:\uD83C[\uDFFB-\uDFFF])?|[\uDFC4\uDFCA](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDFCB\uDFCC](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDCCF\uDD8E\uDD91-\uDD9A\uDE01\uDE1A\uDE2F\uDE32-\uDE36\uDE38-\uDE3A\uDE50\uDE51\uDF00-\uDF20\uDF2D-\uDF35\uDF37-\uDF43\uDF45-\uDF4A\uDF4C-\uDF7C\uDF7E-\uDF84\uDF86-\uDF93\uDFA0-\uDFC1\uDFC5\uDFC6\uDFC8\uDFC9\uDFCF-\uDFD3\uDFE0-\uDFF0\uDFF8-\uDFFF]|\uDDE6\uD83C[\uDDE8-\uDDEC\uDDEE\uDDF1\uDDF2\uDDF4\uDDF6-\uDDFA\uDDFC\uDDFD\uDDFF]|\uDDE7\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEF\uDDF1-\uDDF4\uDDF6-\uDDF9\uDDFB\uDDFC\uDDFE\uDDFF]|\uDDE8\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDEE\uDDF0-\uDDF7\uDDFA-\uDDFF]|\uDDE9\uD83C[\uDDEA\uDDEC\uDDEF\uDDF0\uDDF2\uDDF4\uDDFF]|\uDDEA\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDED\uDDF7-\uDDFA]|\uDDEB\uD83C[\uDDEE-\uDDF0\uDDF2\uDDF4\uDDF7]|\uDDEC\uD83C[\uDDE6\uDDE7\uDDE9-\uDDEE\uDDF1-\uDDF3\uDDF5-\uDDFA\uDDFC\uDDFE]|\uDDED\uD83C[\uDDF0\uDDF2\uDDF3\uDDF7\uDDF9\uDDFA]|\uDDEE\uD83C[\uDDE8-\uDDEA\uDDF1-\uDDF4\uDDF6-\uDDF9]|\uDDEF\uD83C[\uDDEA\uDDF2\uDDF4\uDDF5]|\uDDF0\uD83C[\uDDEA\uDDEC-\uDDEE\uDDF2\uDDF3\uDDF5\uDDF7\uDDFC\uDDFE\uDDFF]|\uDDF1\uD83C[\uDDE6-\uDDE8\uDDEE\uDDF0\uDDF7-\uDDFB\uDDFE]|\uDDF2\uD83C[\uDDE6\uDDE8-\uDDED\uDDF0-\uDDFF]|\uDDF3\uD83C[\uDDE6\uDDE8\uDDEA-\uDDEC\uDDEE\uDDF1\uDDF4\uDDF5\uDDF7\uDDFA\uDDFF]|\uDDF4\uD83C\uDDF2|\uDDF5\uD83C[\uDDE6\uDDEA-\uDDED\uDDF0-\uDDF3\uDDF7-\uDDF9\uDDFC\uDDFE]|\uDDF6\uD83C\uDDE6|\uDDF7\uD83C[\uDDEA\uDDF4\uDDF8\uDDFA\uDDFC]|\uDDF8\uD83C[\uDDE6-\uDDEA\uDDEC-\uDDF4\uDDF7-\uDDF9\uDDFB\uDDFD-\uDDFF]|\uDDF9\uD83C[\uDDE6\uDDE8\uDDE9\uDDEB-\uDDED\uDDEF-\uDDF4\uDDF7\uDDF9\uDDFB\uDDFC\uDDFF]|\uDDFA\uD83C[\uDDE6\uDDEC\uDDF2\uDDF3\uDDF8\uDDFE\uDDFF]|\uDDFB\uD83C[\uDDE6\uDDE8\uDDEA\uDDEC\uDDEE\uDDF3\uDDFA]|\uDDFC\uD83C[\uDDEB\uDDF8]|\uDDFD\uD83C\uDDF0|\uDDFE\uD83C[\uDDEA\uDDF9]|\uDDFF\uD83C[\uDDE6\uDDF2\uDDFC]|\uDF44(?:\u200D\uD83D\uDFEB)?|\uDF4B(?:\u200D\uD83D\uDFE9)?|\uDFC3(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDFF3\uFE0F?(?:\u200D(?:\u26A7\uFE0F?|\uD83C\uDF08))?|\uDFF4(?:\u200D\u2620\uFE0F?|\uDB40\uDC67\uDB40\uDC62\uDB40(?:\uDC65\uDB40\uDC6E\uDB40\uDC67|\uDC73\uDB40\uDC63\uDB40\uDC74|\uDC77\uDB40\uDC6C\uDB40\uDC73)\uDB40\uDC7F)?)|\uD83D(?:[\uDC3F\uDCFD\uDD49\uDD4A\uDD6F\uDD70\uDD73\uDD76-\uDD79\uDD87\uDD8A-\uDD8D\uDDA5\uDDA8\uDDB1\uDDB2\uDDBC\uDDC2-\uDDC4\uDDD1-\uDDD3\uDDDC-\uDDDE\uDDE1\uDDE3\uDDE8\uDDEF\uDDF3\uDDFA\uDECB\uDECD-\uDECF\uDEE0-\uDEE5\uDEE9\uDEF0\uDEF3]\uFE0F?|[\uDC42\uDC43\uDC46-\uDC50\uDC66\uDC67\uDC6B-\uDC6D\uDC72\uDC74-\uDC76\uDC78\uDC7C\uDC83\uDC85\uDC8F\uDC91\uDCAA\uDD7A\uDD95\uDD96\uDE4C\uDE4F\uDEC0\uDECC](?:\uD83C[\uDFFB-\uDFFF])?|[\uDC6E\uDC70\uDC71\uDC73\uDC77\uDC81\uDC82\uDC86\uDC87\uDE45-\uDE47\uDE4B\uDE4D\uDE4E\uDEA3\uDEB4\uDEB5](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD74\uDD90](?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?|[\uDC00-\uDC07\uDC09-\uDC14\uDC16-\uDC25\uDC27-\uDC3A\uDC3C-\uDC3E\uDC40\uDC44\uDC45\uDC51-\uDC65\uDC6A\uDC79-\uDC7B\uDC7D-\uDC80\uDC84\uDC88-\uDC8E\uDC90\uDC92-\uDCA9\uDCAB-\uDCFC\uDCFF-\uDD3D\uDD4B-\uDD4E\uDD50-\uDD67\uDDA4\uDDFB-\uDE2D\uDE2F-\uDE34\uDE37-\uDE41\uDE43\uDE44\uDE48-\uDE4A\uDE80-\uDEA2\uDEA4-\uDEB3\uDEB7-\uDEBF\uDEC1-\uDEC5\uDED0-\uDED2\uDED5-\uDED7\uDEDC-\uDEDF\uDEEB\uDEEC\uDEF4-\uDEFC\uDFE0-\uDFEB\uDFF0]|\uDC08(?:\u200D\u2B1B)?|\uDC15(?:\u200D\uD83E\uDDBA)?|\uDC26(?:\u200D(?:\u2B1B|\uD83D\uDD25))?|\uDC3B(?:\u200D\u2744\uFE0F?)?|\uDC41\uFE0F?(?:\u200D\uD83D\uDDE8\uFE0F?)?|\uDC68(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDC68\uDC69]\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?)|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?\uDC68\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D\uDC68\uD83C[\uDFFB-\uDFFE])))?))?|\uDC69(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:\uDC8B\u200D\uD83D)?[\uDC68\uDC69]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D(?:[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?|\uDC69\u200D\uD83D(?:\uDC66(?:\u200D\uD83D\uDC66)?|\uDC67(?:\u200D\uD83D[\uDC66\uDC67])?))|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFC-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFD-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFD\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D\uD83D(?:[\uDC68\uDC69]|\uDC8B\u200D\uD83D[\uDC68\uDC69])\uD83C[\uDFFB-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83D[\uDC68\uDC69]\uD83C[\uDFFB-\uDFFE])))?))?|\uDC6F(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDD75(?:\uD83C[\uDFFB-\uDFFF]|\uFE0F)?(?:\u200D[\u2640\u2642]\uFE0F?)?|\uDE2E(?:\u200D\uD83D\uDCA8)?|\uDE35(?:\u200D\uD83D\uDCAB)?|\uDE36(?:\u200D\uD83C\uDF2B\uFE0F?)?|\uDE42(?:\u200D[\u2194\u2195]\uFE0F?)?|\uDEB6(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?)|\uD83E(?:[\uDD0C\uDD0F\uDD18-\uDD1F\uDD30-\uDD34\uDD36\uDD77\uDDB5\uDDB6\uDDBB\uDDD2\uDDD3\uDDD5\uDEC3-\uDEC5\uDEF0\uDEF2-\uDEF8](?:\uD83C[\uDFFB-\uDFFF])?|[\uDD26\uDD35\uDD37-\uDD39\uDD3D\uDD3E\uDDB8\uDDB9\uDDCD\uDDCF\uDDD4\uDDD6-\uDDDD](?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDDDE\uDDDF](?:\u200D[\u2640\u2642]\uFE0F?)?|[\uDD0D\uDD0E\uDD10-\uDD17\uDD20-\uDD25\uDD27-\uDD2F\uDD3A\uDD3F-\uDD45\uDD47-\uDD76\uDD78-\uDDB4\uDDB7\uDDBA\uDDBC-\uDDCC\uDDD0\uDDE0-\uDDFF\uDE70-\uDE7C\uDE80-\uDE89\uDE8F-\uDEC2\uDEC6\uDECE-\uDEDC\uDEDF-\uDEE9]|\uDD3C(?:\u200D[\u2640\u2642]\uFE0F?|\uD83C[\uDFFB-\uDFFF])?|\uDDCE(?:\uD83C[\uDFFB-\uDFFF])?(?:\u200D(?:[\u2640\u2642]\uFE0F?(?:\u200D\u27A1\uFE0F?)?|\u27A1\uFE0F?))?|\uDDD1(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1|\uDDD1\u200D\uD83E\uDDD2(?:\u200D\uD83E\uDDD2)?|\uDDD2(?:\u200D\uD83E\uDDD2)?))|\uD83C(?:\uDFFB(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFC-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFC(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFD-\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFD(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFE(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFD\uDFFF]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?|\uDFFF(?:\u200D(?:[\u2695\u2696\u2708]\uFE0F?|\u2764\uFE0F?\u200D(?:\uD83D\uDC8B\u200D)?\uD83E\uDDD1\uD83C[\uDFFB-\uDFFE]|\uD83C[\uDF3E\uDF73\uDF7C\uDF84\uDF93\uDFA4\uDFA8\uDFEB\uDFED]|\uD83D[\uDCBB\uDCBC\uDD27\uDD2C\uDE80\uDE92]|\uD83E(?:[\uDDAF\uDDBC\uDDBD](?:\u200D\u27A1\uFE0F?)?|[\uDDB0-\uDDB3]|\uDD1D\u200D\uD83E\uDDD1\uD83C[\uDFFB-\uDFFF])))?))?|\uDEF1(?:\uD83C(?:\uDFFB(?:\u200D\uD83E\uDEF2\uD83C[\uDFFC-\uDFFF])?|\uDFFC(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFD-\uDFFF])?|\uDFFD(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB\uDFFC\uDFFE\uDFFF])?|\uDFFE(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFD\uDFFF])?|\uDFFF(?:\u200D\uD83E\uDEF2\uD83C[\uDFFB-\uDFFE])?))?)/g,qh=globalThis.Intl?.Segmenter?new Intl.Segmenter:{segment:e=>e.split(``)},Jh=/^\p{Default_Ignorable_Code_Point}$/u;function Yh(e,t={}){if(typeof e!=`string`||e.length===0)return 0;let{ambiguousIsNarrow:n=!0,countAnsiEscapeCodes:r=!1}=t;if(r||(e=Bh(e)),e.length===0)return 0;let i=0,a={ambiguousAsWide:!n};for(let{segment:t}of qh.segment(e)){let e=t.codePointAt(0);if(!(e<=31||e>=127&&e<=159)&&!(e>=8203&&e<=8207||e===65279)&&!(e>=768&&e<=879||e>=6832&&e<=6911||e>=7616&&e<=7679||e>=8400&&e<=8447||e>=65056&&e<=65071)&&!(e>=55296&&e<=57343)&&!(e>=65024&&e<=65039)&&!Jh.test(t)){if(Kh().test(t)){i+=2;continue}i+=Gh(e,a)}}return i}function Xh(){let{env:e}=pe,{TERM:t,TERM_PROGRAM:n}=e;return pe.platform===`win32`?!!e.WT_SESSION||!!e.TERMINUS_SUBLIME||e.ConEmuTask===`{cmd::Cmder}`||n===`Terminus-Sublime`||n===`vscode`||t===`xterm-256color`||t===`alacritty`||t===`rxvt-unicode`||t===`rxvt-unicode-256color`||e.TERMINAL_EMULATOR===`JetBrains-JediTerm`:t!==`linux`}const Zh={info:`cyan`,fail:`red`,success:`green`,ready:`green`,start:`magenta`},Qh={0:`red`,1:`yellow`},$h=Xh(),eg=(e,t)=>$h?e:t,tg={error:eg(`✖`,`×`),fatal:eg(`✖`,`×`),ready:eg(`✔`,`√`),warn:eg(`⚠`,`‼`),info:eg(`ℹ`,`i`),success:eg(`✔`,`√`),debug:eg(`⚙`,`D`),trace:eg(`→`,`→`),fail:eg(`✖`,`×`),start:eg(`◐`,`o`),log:``};function ng(e){return typeof Intl!=`object`||!Intl.Segmenter?Pp(e).length:Yh(e)}var rg=class extends hp{formatStack(e,t,n){let r=` `.repeat((n?.errorLevel||0)+1);return`
660
+ ${r}`+fp(e,t).map(e=>` `+e.replace(/^at +/,e=>jp.gray(e)).replace(/\((.+)\)/,(e,t)=>`(${jp.cyan(t)})`)).join(`
661
+ ${r}`)}formatType(e,t,n){let r=Zh[e.type]||Qh[e.level]||`gray`;if(t)return og(r)(jp.black(` ${e.type.toUpperCase()} `));let i=typeof tg[e.type]==`string`?tg[e.type]:e.icon||e.type;return i?ag(r)(i):``}formatLogObj(e,t){let[n,...r]=this.formatArgs(e.args,t).split(`
662
+ `);if(e.type===`box`)return Lp(ig(n+(r.length>0?`
663
663
  `+r.join(`
664
- `):``)),{title:e.title?tg(e.title):void 0,style:e.style});let i=this.formatDate(e.date,t),a=i&&Op.gray(i),o=e.badge??e.level<2,s=this.formatType(e,o,t),c=e.tag?Op.gray(e.tag):``,l,u=this.filterAndJoin([s,tg(n)]),d=this.filterAndJoin(t.columns?[c,a]:[c]),f=(t.columns||0)-$h(u)-$h(d)-2;if(l=f>0&&(t.columns||0)>=80?u+` `.repeat(f)+d:(d?`${Op.gray(`[${d}]`)} `:``)+u,l+=tg(r.length>0?`
664
+ `):``)),{title:e.title?ig(e.title):void 0,style:e.style});let i=this.formatDate(e.date,t),a=i&&jp.gray(i),o=e.badge??e.level<2,s=this.formatType(e,o,t),c=e.tag?jp.gray(e.tag):``,l,u=this.filterAndJoin([s,ig(n)]),d=this.filterAndJoin(t.columns?[c,a]:[c]),f=(t.columns||0)-ng(u)-ng(d)-2;if(l=f>0&&(t.columns||0)>=80?u+` `.repeat(f)+d:(d?`${jp.gray(`[${d}]`)} `:``)+u,l+=ig(r.length>0?`
665
665
  `+r.join(`
666
666
  `):``),e.type===`trace`){let t=Error(`Trace: `+e.message);l+=this.formatStack(t.stack||``,t.message)}return o?`
667
667
  `+l+`
668
- `:l}};function tg(e){return e.replace(/`([^`]+)`/gm,(e,t)=>Op.cyan(t)).replace(/\s+_([^_]+)_\s+/gm,(e,t)=>` ${Op.underline(t)} `)}function ng(e=`white`){return Op[e]||Op.white}function rg(e=`bgWhite`){return Op[`bg${e[0].toUpperCase()}${e.slice(1)}`]||Op.bgWhite}function ig(e={}){let t=ag();return process.env.CONSOLA_LEVEL&&(t=Number.parseInt(process.env.CONSOLA_LEVEL)??t),cp({level:t,defaults:{level:t},stdout:process.stdout,stderr:process.stderr,prompt:(...e)=>Promise.resolve().then(()=>(ch(),Fp)).then(t=>t.prompt(...e)),reporters:e.reporters||[e.fancy??!(vh||xh)?new eg:new fp],...e})}function ag(){return bh?K.debug:xh?K.warn:K.info}const Z=ig();function og(e){let t=Og.safeParse(sg(e));if(!t.success){let e=t.error.issues[0],n=e?.path.length?` at ${e.path.join(`.`)}`:``;throw Error(`Invalid Kapture report${n}: ${e?.message??`unknown error`}`)}return t.data}function sg(e){if(!e||typeof e!=`object`||Array.isArray(e))return e;let t=e;return t.version!==2||!t.summary||typeof t.summary!=`object`?e:{...t,version:3,summary:{...t.summary,unstable:0}}}async function cg(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${ug} bytes`);let r;try{r=JSON.parse(await x(t,`utf8`))}catch{throw Error(`Kapture report does not contain valid JSON`)}return og(r)}function lg(e){try{let t=new URL(e);return t.protocol===`https:`&&!t.username&&!t.password}catch{return!1}}var ug,dg,Q,$,fg,pg,mg,hg,gg,_g,vg,yg,bg,xg,Sg,Cg,wg,Tg,Eg,Dg,Og,kg=E((()=>{Ld(),Bc(),ug=10485760,dg=2e4,Q=R().max(4096),$=R().min(1).max(512),fg=$.refine(e=>Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127}),`must not contain control characters`),pg=z().int().min(0).max(2**53-1),mg=z().int().positive().max(2**53-1),hg=z().min(0).max(1),gg=B({name:$,width:z().int().positive().max(16384),height:z().int().positive().max(16384)}),_g=B({pixelColorThreshold:hg,maxChangedPixelRatio:hg}),vg=B({id:$,browser:$,browserVersion:$,orchestratorRuntime:$,operatingSystem:$,architecture:$,deviceScaleFactor:z().positive().max(8),locale:$,timezone:$,colorScheme:Ns([`light`,`dark`]),reducedMotion:Ns([`reduce`,`no-preference`]),frozenTime:$,randomSeed:z().int().min(0).max(2**53-1),fontsFingerprint:$,stateIsolation:V(`fresh-browser-process-per-story-side-v1`).optional(),network:B({mode:V(`allowlist`),allowedDomains:Ds($).max(100),webRtc:V(`disabled`)})}),yg=B({id:$,storyId:$,title:Q,name:Q,viewport:gg,status:Ns([`unchanged`,`changed`,`unstable`,`added`,`removed`,`error`]),baseImage:Q.optional(),headImage:Q.optional(),diffImage:Q.optional(),ignoredRegions:Ds(B({x:z().int().min(0).max(16384),y:z().int().min(0).max(32768),width:z().int().positive().max(16384),height:z().int().positive().max(32768)})).max(1e4).optional(),changedPixels:pg.optional(),diffRatio:hg.optional(),threshold:_g.optional(),instability:B({base:B({repeatImage:Q,diffImage:Q,changedPixels:pg,diffRatio:hg}).optional(),head:B({repeatImage:Q,diffImage:Q,changedPixels:pg,diffRatio:hg}).optional()}).optional(),error:Q.optional()}).superRefine((e,t)=>{e.status===`unstable`&&!e.instability?.base&&!e.instability?.head&&t.addIssue({code:`custom`,path:[`instability`],message:`unstable snapshots require base or head instability evidence`}),e.status!==`unstable`&&e.instability&&t.addIssue({code:`custom`,path:[`instability`],message:`only unstable snapshots can contain instability evidence`})}),bg=Ds($).max(dg).refine(e=>new Set(e).size===e.length,`must not contain duplicates`).refine(e=>e.every((t,n)=>n===0||e[n-1]<t),`must be sorted`),xg=B({code:Ns([`base-manifest-missing`,`base-manifest-invalid`,`head-manifest-missing`,`head-manifest-invalid`,`changed-files-incomplete`,`manifest-incomplete`,`global-input`,`global-output`,`global-runtime`,`unknown-input`,`story-import-missing`,`story-module-missing`,`fallback-reasons-truncated`]),path:Q.optional(),storyId:$.optional(),side:Ns([`base`,`head`]).optional()}),Sg=B({provider:V(`github-pull-request-files`),manifestDigest:R().regex(/^[0-9a-f]{64}$/),pullRequestNumber:mg,baseSha:R().regex(/^[0-9a-f]{40}$/),headSha:R().regex(/^[0-9a-f]{40}$/)}),Cg=R().regex(/^[0-9a-f]{64}$/),wg=As(`state`,[B({state:V(`valid`),digest:Cg,revision:$}),B({state:V(`invalid`),digest:Cg.optional(),revision:$}),B({state:V(`missing`),revision:$})]),Tg=B({base:wg,head:wg}),Eg=B({repository:$.regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/),number:mg,url:Q.refine(lg,`must be an HTTPS URL without credentials`),baseBranch:fg,headBranch:fg,workflowRunUrl:Q.refine(lg,`must be an HTTPS URL without credentials`)}),Dg=B({plannerVersion:V(1),mode:Ns([`full`,`affected`,`full-fallback`]),changedFilesEvidence:Sg.optional(),dependencyManifests:Tg.optional(),storyIds:bg,selectedStoryIds:bg,skippedStoryIds:bg,addedStoryIds:bg.optional(),removedStoryIds:bg.optional(),fallbackReasons:Ds(xg).max(jd),baseline:B({mode:V(`reused`),revision:$,manifestDigest:Cg}).optional()}).superRefine((e,t)=>{let n=new Set(e.storyIds),r=new Set(e.selectedStoryIds),i=new Set(e.skippedStoryIds);if((r.size+i.size!==n.size||[...r].some(e=>!n.has(e)||i.has(e))||[...i].some(e=>!n.has(e)))&&t.addIssue({code:`custom`,message:`selected and skipped stories must exactly partition the story catalog`}),e.mode!==`affected`&&i.size>0&&t.addIssue({code:`custom`,path:[`skippedStoryIds`],message:`full coverage modes cannot skip stories`}),e.mode===`full-fallback`&&e.fallbackReasons.length===0&&t.addIssue({code:`custom`,path:[`fallbackReasons`],message:`full-fallback coverage requires at least one reason`}),e.mode!==`full-fallback`&&e.fallbackReasons.length>0&&t.addIssue({code:`custom`,path:[`fallbackReasons`],message:`only full-fallback coverage can contain fallback reasons`}),e.addedStoryIds===void 0!=(e.removedStoryIds===void 0)&&t.addIssue({code:`custom`,message:`added and removed story catalogs must be provided together`}),e.addedStoryIds&&e.removedStoryIds){let i=new Set(e.addedStoryIds),a=new Set(e.removedStoryIds);([...i].some(e=>!n.has(e)||!r.has(e)||a.has(e))||[...a].some(e=>!n.has(e)||!r.has(e)))&&t.addIssue({code:`custom`,message:`added and removed stories must be disjoint selected catalog members`})}}),Og=B({version:V(3),contentDigest:R().regex(/^[0-9a-f]{64}$/).optional(),baseRevision:$,headRevision:$,headBranch:fg.optional(),baseBranch:fg.optional(),pullRequest:Eg.optional(),storybookUrl:Q.refine(e=>e===`./storybook/`||lg(e),`must be an HTTPS URL or ./storybook/ without credentials`).optional(),environment:vg,createdAt:$,threshold:_g,summary:B({total:pg,unchanged:pg,changed:pg,unstable:pg,added:pg,removed:pg,errors:pg}),coverage:Dg.optional(),entries:Ms(R(),yg)}).superRefine((e,t)=>{let n=Object.entries(e.entries);if(n.length>2e4){t.addIssue({code:`custom`,message:`Report contains more than ${dg} entries`,path:[`entries`]});return}for(let[e,r]of n)e!==r.id&&t.addIssue({code:`custom`,message:`Entry key must match entry.id`,path:[`entries`,e,`id`]});let r={unchanged:0,changed:0,unstable:0,added:0,removed:0,error:0};for(let t of Object.values(e.entries))r[t.status]+=1;if((e.summary.total!==n.length||e.summary.unchanged!==r.unchanged||e.summary.changed!==r.changed||e.summary.unstable!==r.unstable||e.summary.added!==r.added||e.summary.removed!==r.removed||e.summary.errors!==r.error)&&t.addIssue({code:`custom`,message:`Report summary does not match its entries`,path:[`summary`]}),e.coverage){let r=e.coverage.changedFilesEvidence;r&&(r.baseSha!==e.baseRevision||r.headSha!==e.headRevision)&&t.addIssue({code:`custom`,message:`Changed-files evidence must match the report base and head revisions`,path:[`coverage`,`changedFilesEvidence`]});let i=e.coverage.dependencyManifests;i&&(i.base.revision!==e.baseRevision||i.head.revision!==e.headRevision)&&t.addIssue({code:`custom`,message:`Dependency manifest evidence must match the report base and head revisions`,path:[`coverage`,`dependencyManifests`]});let a=new Set(e.coverage.selectedStoryIds),o=new Set(e.coverage.addedStoryIds??[]),s=new Set(e.coverage.removedStoryIds??[]);for(let[e,r]of n)a.has(r.storyId)||t.addIssue({code:`custom`,message:`Report entries must belong to selected stories`,path:[`entries`,e,`storyId`]}),o.has(r.storyId)&&r.status!==`added`&&r.status!==`error`&&t.addIssue({code:`custom`,message:`Entries for an added story must be added or error snapshots`,path:[`entries`,e,`status`]}),s.has(r.storyId)&&r.status!==`removed`&&r.status!==`error`&&t.addIssue({code:`custom`,message:`Entries for a removed story must be removed or error snapshots`,path:[`entries`,e,`status`]})}})}));Ld(),A();var Ag=Wt();kg();const jg=6e4,Mg=26214400,Ng=Buffer.from([137,80,78,71,13,10,26,10]),Pg=new Set([`acTL`,`fcTL`,`fdAT`]),Fg=[`baseImage`,`headImage`,`diffImage`,`baseRepeatImage`,`baseInstabilityDiffImage`,`headRepeatImage`,`headInstabilityDiffImage`],Ig=[`base`,`head`,`diff`,`base-repeat`,`base-instability-diff`,`head-repeat`,`head-instability-diff`],Lg=k({meta:{name:`build`,description:`Rebuild a trusted static report from an untrusted Kapture artifact`},args:{input:{type:`string`,required:!0,description:`Untrusted artifact report directory containing report.json and images`},output:{type:`string`,required:!0,description:`New directory for the trusted static report`},"storybook-url":{type:`string`,description:`Trusted HTTPS Storybook URL or the fixed same-origin ./storybook/ directory`},"base-branch":{type:`string`,description:`Trusted base branch display label (not a comparison revision)`},"head-branch":{type:`string`,description:`Trusted head branch display label (not a comparison revision)`}},async run({args:e}){let t=await Rg({inputDir:e.input,outputDir:e.output,storybookUrl:e[`storybook-url`],trustedBaseBranch:e[`base-branch`],trustedHeadBranch:e[`head-branch`]});Z.success(`Trusted report: ${t.report.summary.total} snapshots, ${t.imageCount} verified PNGs (${t.imageBytes} bytes)`),Z.info(`Output: ${t.outputDir}`)}});async function Rg(e){let t=f(e.inputDir),n=f(e.outputDir),r=zg(e.trustedHeadBranch),i=zg(e.trustedBaseBranch);if(await Zg(t),e_(t,n))throw Error(`Trusted report output must be outside the untrusted input directory`);await Qg(n);let o=e.dashboardDir?f(e.dashboardDir):f(a(fe(import.meta.url)),`dashboard`),s=a(n);await y(s,{recursive:!0});let c=await ee(`${s}${p}.kapture-report-`),l;try{l=await Vg(t,async(e,t)=>{let n=f(c,e.relativePath);await y(a(n),{recursive:!0}),await w(n,t,{flag:`wx`})});let{report:s,imageDigests:u,calculatedContentDigest:d}=l;if(s.contentDigest&&s.contentDigest!==d)throw Error(`Report content digest does not match its referenced PNGs: expected ${s.contentDigest}, calculated ${d}`);r?s.headBranch=r:delete s.headBranch,i?s.baseBranch=i:delete s.baseBranch,e.trustedPullRequest?s.pullRequest={...e.trustedPullRequest}:delete s.pullRequest;let p=$d(e.storybookUrl);p?s.storybookUrl=p:delete s.storybookUrl,s.contentDigest=al(s,u),await w(f(c,`report.json`),`${JSON.stringify(s)}\n`,{flag:`wx`}),await td(o,c),await ne(c,n)}catch(e){throw await re(c,{recursive:!0,force:!0}),e}if(!l)throw Error(`Trusted report validation did not complete`);return{report:l.report,outputDir:n,imageCount:l.references.length,imageBytes:l.imageBytes}}function zg(e){if(e!==void 0){if(e.length<1||e.length>512||Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127}))throw Error(`Trusted head branch must contain between 1 and 512 non-control characters`);return e}}async function Bg(e,t){if(!/^[0-9a-f]{64}$/.test(t))throw Error(`Expected trusted report content digest must be a lowercase SHA-256 digest`);let n=f(e);if(n!==f(a(n),`report.json`))throw Error(`Trusted report path must end in report.json`);let r=a(n);await Zg(r);let i=await Vg(r);if(i.report.contentDigest!==t||i.calculatedContentDigest!==t)throw Error(`Trusted report content digest does not match its actual structure and referenced PNGs`);return i.report}async function Vg(e,t){let n=Hg(await $g(e,`report.json`,ug)),r=Ug(n);if(r.length>6e4)throw Error(`Report references more than ${jg} PNG images`);let i=new Map,a=[],o=0;for(let n of r){let r=await $g(e,n.relativePath,Mg);if(o+=r.byteLength,o>536870912)throw Error(`Referenced PNGs exceed 536870912 total bytes`);i.set(n.relativePath,Jg(r,n.relativePath)),a.push({path:n.relativePath,sha256:T(`sha256`).update(r).digest(`hex`)}),await t?.(n,r)}return Xg(n,i),{report:n,references:r,imageDigests:a,imageBytes:o,calculatedContentDigest:al(n,a)}}function Hg(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch{throw Error(`Input report.json does not contain valid JSON`)}return og(t)}function Ug(e){let t=new Map;for(let n of Object.values(e.entries)){let e=Wg(n);for(let r of Fg){let i=Kg(n,r);if(e.has(r)&&!i)throw Error(`Report entry ${n.id} is missing ${r} for status ${n.status}`);if(!e.has(r)&&i)throw Error(`Report entry ${n.id} cannot contain ${r} for status ${n.status}`);if(!i)continue;let a=qg(i,Gg(r),n.id),o=t.get(a);if(o&&o.entryId!==n.id)throw Error(`Report entries ${o.entryId} and ${n.id} reference the same PNG: ${a}`);t.set(a,{relativePath:a,entryId:n.id})}}return[...t.values()]}function Wg(e){if(e.status===`changed`)return new Set([`baseImage`,`headImage`,`diffImage`]);if(e.status===`unstable`){if(!e.instability?.base&&!e.instability?.head)throw Error(`Report entry ${e.id} is unstable without instability evidence`);let t=[`baseImage`,`headImage`,`diffImage`];return e.instability.base&&t.push(`baseRepeatImage`,`baseInstabilityDiffImage`),e.instability.head&&t.push(`headRepeatImage`,`headInstabilityDiffImage`),new Set(t)}return e.status===`added`?new Set([`headImage`]):e.status===`removed`?new Set([`baseImage`]):new Set}function Gg(e){return e===`baseImage`?`base`:e===`headImage`?`head`:e===`diffImage`?`diff`:e===`baseRepeatImage`?`base-repeat`:e===`baseInstabilityDiffImage`?`base-instability-diff`:e===`headRepeatImage`?`head-repeat`:`head-instability-diff`}function Kg(e,t){return t===`baseImage`||t===`headImage`||t===`diffImage`?e[t]:t===`baseRepeatImage`?e.instability?.base?.repeatImage:t===`baseInstabilityDiffImage`?e.instability?.base?.diffImage:t===`headRepeatImage`?e.instability?.head?.repeatImage:e.instability?.head?.diffImage}function qg(e,t,n){let r=`images/${t}/`,i=e.slice(r.length);if(!e.startsWith(r)||!i||i.includes(`/`)||i.includes(`\\`)||i.length>255||!/^[a-zA-Z0-9][a-zA-Z0-9._-]*\.png$/.test(i))throw Error(`Report entry ${n} has an invalid ${t} PNG path: ${e}`);return e}function Jg(e,t){if(e.byteLength<33||!e.subarray(0,8).equals(Ng))throw Error(`Referenced image is not a PNG: ${t}`);let n=e.readUInt32BE(8),r=e.toString(`ascii`,12,16);if(n!==13||r!==`IHDR`)throw Error(`Referenced PNG has an invalid IHDR chunk: ${t}`);let i=e.readUInt32BE(16),a=e.readUInt32BE(20);if(i<1||a<1||i>16384||a>32768||i*a>33554432)throw Error(`Referenced PNG dimensions are outside the supported limits: ${t} (${i}x${a})`);Yg(e,t);try{let t=Ag.PNG.sync.read(e,{checkCRC:!0,skipRescale:!0});if(t.width!==i||t.height!==a)throw Error(`decoded dimensions differ from IHDR`)}catch{throw Error(`Referenced PNG cannot be decoded safely: ${t}`)}return{width:i,height:a}}function Yg(e,t){let n=Ng.byteLength,r=!1;for(;n+12<=e.byteLength;){let i=e.readUInt32BE(n),a=e.toString(`ascii`,n+4,n+8),o=n+12+i;if(o>e.byteLength)throw Error(`Referenced PNG has an invalid chunk boundary: ${t}`);if(Pg.has(a))throw Error(`Animated PNG is not supported in a static report: ${t}`);if(n=o,a===`IEND`){r=!0;break}}if(!r||n!==e.byteLength)throw Error(`Referenced PNG has an invalid chunk structure: ${t}`)}function Xg(e,t){for(let n of Object.values(e.entries)){if(n.status!==`changed`&&n.status!==`unstable`||!n.baseImage||!n.headImage||!n.diffImage)continue;let e=t.get(n.baseImage),r=t.get(n.headImage),i=t.get(n.diffImage);if(!e||!r||!i)throw Error(`Report entry ${n.id} is missing validated PNG dimensions`);let a=Math.max(e.width,r.width),o=Math.max(e.height,r.height);for(let e of n.ignoredRegions??[])if(e.x+e.width>a||e.y+e.height>o)throw Error(`Report entry ${n.id} ignored region exceeds its comparison canvas`);if(i.width!==a||i.height!==o)throw Error(`Report entry ${n.id} diff PNG must match the padded comparison canvas ${a}x${o}`);if(n.changedPixels!==void 0&&n.changedPixels>a*o)throw Error(`Report entry ${n.id} changedPixels exceeds its diff PNG pixel count`);for(let i of[n.instability?.base,n.instability?.head]){if(!i)continue;let a=t.get(i.repeatImage),o=t.get(i.diffImage);if(!a||!o)throw Error(`Report entry ${n.id} is missing instability PNG dimensions`);let s=i===n.instability?.base?e:r,c=Math.max(s.width,a.width),l=Math.max(s.height,a.height);if(o.width!==c||o.height!==l)throw Error(`Report entry ${n.id} instability diff PNG must match ${c}x${l}`);if(i.changedPixels>c*l)throw Error(`Report entry ${n.id} instability changedPixels exceeds its diff PNG pixel count`)}}}async function Zg(e){let t;try{t=await v(e)}catch(t){throw t_(t)?Error(`Input report directory does not exist: ${e}`):t}if(t.isSymbolicLink()||!t.isDirectory())throw Error(`Input report path must be a real directory, not a symbolic link`)}async function Qg(e){try{await v(e)}catch(e){if(t_(e))return;throw e}throw Error(`Trusted report output already exists: ${e}`)}async function $g(e,t,n){if(s(t)||t.includes(`\\`))throw Error(`Input file must be a normalized relative path: ${t}`);let r=t.split(`/`),i=e;for(let[e,n]of r.entries()){if(!n||n===`.`||n===`..`)throw Error(`Input file must be a normalized relative path: ${t}`);i=f(i,n);let a;try{a=await v(i)}catch(e){throw t_(e)?Error(`Referenced input file does not exist: ${t}`):e}if(a.isSymbolicLink())throw Error(`Referenced input path cannot contain a symbolic link: ${t}`);let o=e===r.length-1;if(!o&&!a.isDirectory()||o&&!a.isFile())throw Error(`Referenced input path is not a regular file: ${t}`)}let a=ue.O_RDONLY|(ue.O_NOFOLLOW??0),o=await b(i,a);try{let e=await o.stat();if(!e.isFile()||e.size>n)throw Error(`Input file exceeds ${n} bytes: ${t}`);let r=Buffer.alloc(e.size),i=0;for(;i<r.byteLength;){let{bytesRead:e}=await o.read(r,i,r.byteLength-i,i);if(e===0)throw Error(`Input file changed while being read: ${t}`);i+=e}let a=Buffer.alloc(1),{bytesRead:s}=await o.read(a,0,1,r.byteLength);if(s>0)throw Error(`Input file changed while being read: ${t}`);return r}finally{await o.close()}}function e_(e,t){let n=d(e,t);return n===``||!n.startsWith(`..${p}`)&&n!==`..`&&!s(n)}function t_(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}function n_(e,t){return i_(e,t).map(({path:e,compressedBytes:t,uncompressedBytes:n})=>({path:e,compressedBytes:t,uncompressedBytes:n}))}async function r_(e,t,n){let r=i_(e,n),i=f(t);await y(i,{recursive:!0});for(let t of r){let n=e.subarray(t.dataOffset,t.dataOffset+t.compressedBytes),r=t.compression===0?Buffer.from(n):be(n,{maxOutputLength:t.uncompressedBytes+1});if(r.byteLength!==t.uncompressedBytes)throw Error(`ZIP entry size mismatch: ${t.path}`);if(ye(r)!==t.crc)throw Error(`ZIP entry checksum mismatch: ${t.path}`);let o=f(i,t.path);if(!o.startsWith(`${i}${p}`))throw Error(`ZIP entry escapes the output directory: ${t.path}`);await y(a(o),{recursive:!0}),await w(o,r,{flag:`wx`})}return r}function i_(e,t){l_(t);let n=a_(e),r=e.readUInt16LE(n+4),i=e.readUInt16LE(n+6),a=e.readUInt16LE(n+8),o=e.readUInt16LE(n+10),s=e.readUInt32LE(n+12),c=e.readUInt32LE(n+16),l=e.readUInt16LE(n+20);if(n+22+l!==e.byteLength)throw Error(`ZIP end record does not match the archive size`);if(r!==0||i!==0||a!==o)throw Error(`Multi-disk ZIP archives are not supported`);if(o===65535||s===4294967295||c===4294967295)throw Error(`ZIP64 archives are not supported`);if(o>t.maxEntries)throw Error(`ZIP archive contains more than ${t.maxEntries} entries`);if(c+s!==n)throw Error(`ZIP central directory is malformed`);let u=[],d=new Set,f=c,p=0;for(let r=0;r<o;r+=1){if(f+46>n||e.readUInt32LE(f)!==33639248)throw Error(`ZIP central directory entry is malformed`);let r=e.readUInt16LE(f+4),i=e.readUInt16LE(f+8),a=e.readUInt16LE(f+10),o=e.readUInt32LE(f+16),s=e.readUInt32LE(f+20),l=e.readUInt32LE(f+24),m=e.readUInt16LE(f+28),h=e.readUInt16LE(f+30),g=e.readUInt16LE(f+32),_=e.readUInt16LE(f+34),v=e.readUInt32LE(f+38),y=e.readUInt32LE(f+42),ee=f+46+m+h+g;if(ee>n)throw Error(`ZIP central directory entry exceeds its bounds`);if(i&1)throw Error(`Encrypted ZIP entries are not supported`);if(a!==0&&a!==8)throw Error(`ZIP compression method ${a} is not supported`);if(_!==0)throw Error(`Multi-disk ZIP entries are not supported`);if(s===4294967295||l===4294967295||y===4294967295)throw Error(`ZIP64 entries are not supported`);let b=e.subarray(f+46,f+46+m),x=s_(b);f=ee;let te=x.endsWith(`/`);if(c_(r,v,x,te),d.has(x))throw Error(`ZIP archive contains duplicate path: ${x}`);if(d.add(x),te){if(!t.allowDirectoryPath(x))throw Error(`ZIP archive contains unexpected directory: ${x}`);if(i&8||a!==0||o!==0||s!==0||l!==0)throw Error(`ZIP directory entry must be empty and stored: ${x}`);o_(e,y,b,i,a,o,s,l,c);continue}if(!t.allowPath(x))throw Error(`ZIP archive contains unexpected path: ${x}`);if(l>t.maxFileBytes)throw Error(`ZIP entry exceeds ${t.maxFileBytes} bytes: ${x}`);if(p+=l,p>t.maxTotalBytes)throw Error(`ZIP archive exceeds ${t.maxTotalBytes} uncompressed bytes`);let S=o_(e,y,b,i,a,o,s,l,c);u.push({path:x,compression:a,crc:o,compressedBytes:s,uncompressedBytes:l,dataOffset:S})}if(f!==n)throw Error(`ZIP central directory size is inconsistent`);return u}function a_(e){let t=Math.max(0,e.byteLength-65557);for(let n=e.byteLength-22;n>=t;--n)if(e.readUInt32LE(n)===101010256)return n;throw Error(`ZIP end-of-central-directory record is missing`)}function o_(e,t,n,r,i,a,o,s,c){if(t+30>c||e.readUInt32LE(t)!==67324752)throw Error(`ZIP local entry header is malformed`);let l=e.readUInt16LE(t+6),u=e.readUInt16LE(t+8),d=e.readUInt32LE(t+14),f=e.readUInt32LE(t+18),p=e.readUInt32LE(t+22),m=e.readUInt16LE(t+26),h=e.readUInt16LE(t+28),g=t+30+m+h;if(g>c)throw Error(`ZIP local entry header exceeds its bounds`);let _=e.subarray(t+30,t+30+m);if(l!==r||u!==i||!_.equals(n))throw Error(`ZIP local and central directory entries do not match`);if(!(l&8)&&(d!==a||f!==o||p!==s))throw Error(`ZIP local and central directory sizes or checksum do not match`);if(g+o>c)throw Error(`ZIP entry data exceeds the archive bounds`);return g}function s_(e){let t=e.toString(`utf8`);if(!Buffer.from(t,`utf8`).equals(e))throw Error(`ZIP path is not valid UTF-8`);let n=t.endsWith(`/`),r=t.split(`/`),i=n?r.slice(0,-1):r;if(t.length<1||t.startsWith(`/`)||t.includes(`\\`)||t.includes(`\0`)||i.some(e=>!e||e===`.`||e===`..`)||Array.from(t).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127}))throw Error(`ZIP path is unsafe: ${JSON.stringify(t)}`);return t}function c_(e,t,n,r){if(e>>>8!=3)return;let i=t>>>16&61440;if(i!==0&&i!==(r?16384:32768))throw Error(r?`ZIP entry is not a directory: ${n}`:`ZIP entry is not a regular file: ${n}`)}function l_(e){for(let[t,n]of Object.entries({maxEntries:e.maxEntries,maxFileBytes:e.maxFileBytes,maxTotalBytes:e.maxTotalBytes}))if(!Number.isSafeInteger(n)||n<=0)throw Error(`${t} must be positive`)}function u_(e,t){let n=v_(e,`GitHub pull_request event`),r=v_(n.pull_request,`pull_request`),i=p_(v_(n.repository,`repository`)),a=v_(r.base,`pull_request.base`),o=v_(r.head,`pull_request.head`),s=p_(v_(a.repo,`pull_request.base.repo`)),c=v_(o.repo,`pull_request.head.repo`),l=h_(a.ref,`pull_request.base.ref`),u=h_(o.ref,`pull_request.head.ref`),d=g_(r.number,`pull request number`);if(s!==i)throw Error(`Pull request base repository must match the workflow repository`);if(t!==void 0&&l!==h_(t,`base branch`))throw Error(`Pull request targets ${l}, expected ${t}`);return{schemaVersion:1,runId:g_(n.run_id??process.env.GITHUB_RUN_ID,`workflow run ID`),prNumber:d,base:{repository:s,ref:l,sha:m_(a.sha,`pull_request.base.sha`)},head:{repository:p_(c),repositoryId:g_(c.id,`head repository ID`),ref:u,sha:m_(o.sha,`pull_request.head.sha`)},preview:{branch:u,alias:f_(d,u)}}}function d_(e){return`pr-${e.prNumber}-base-${e.base.sha}-head-${e.head.sha}`}function f_(e,t){let n=`pr-${g_(e,`pull request number`)}-`,r=h_(t,`head branch`),i=r.normalize(`NFKD`).toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``),a=`-${T(`sha256`).update(r).digest(`hex`).slice(0,10)}`,o=Math.max(1,63-n.length-a.length);return`${n}${(i||`branch`).slice(0,o).replace(/-$/g,``)||`b`}${a}`}function p_(e){let t=__(e.full_name,`repository full name`);if(!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(t))throw Error(`GitHub event contains an invalid repository full name`);return t}function m_(e,t){let n=__(e,t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(n))throw Error(`${t} must be a full SHA`);return n}function h_(e,t){let n=__(e,t);if(n.length<1||n.length>512)throw Error(`${t} is invalid`);for(let e of n){let n=e.codePointAt(0)??0;if(n<=31||n===127)throw Error(`${t} is invalid`)}return n}function g_(e,t){let n=typeof e==`string`&&/^[1-9][0-9]*$/.test(e)?Number(e):e;if(typeof n!=`number`||!Number.isSafeInteger(n)||n<=0)throw Error(`${t} must be a positive integer`);return n}function __(e,t){if(typeof e!=`string`)throw Error(`${t} must be a string`);return e}function v_(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}const y_=3e3;async function b_(e,t){let n=await e.getPullRequestForCapture(t.prNumber);C_(n,t);let r=P_(n.changed_files,`pull request changed_files`),i=[],a=[],o=0;if(r>3e3)i.push({code:`github-file-limit`});else for(let n=1;n<=Math.ceil(r/100);n+=1){let s=await e.listPullRequestFilesPage(t.prNumber,n,100);if(o=n,!Array.isArray(s)){i.push({code:`pagination-incomplete`,page:n});break}let c=s.slice(0,100);s.length>100&&i.push({code:`pagination-incomplete`,page:n});for(let[e,t]of c.entries())a.push({value:t,page:n,index:e});if(c.length<100){a.length<r&&i.push({code:`pagination-incomplete`,page:n});break}}a.length!==r&&i.push({code:`file-count-mismatch`});let s=new Set,c=new Set;for(let e of a)w_(e,s,c,i);let l=await e.getPullRequestForCapture(t.prNumber);if(C_(l,t),l.changed_files!==r)throw Error(`Pull request changed while Kapture discovered changed files`);let u=D_(i);return{kind:`kapture-changed-files`,version:1,complete:u.length===0,pullRequest:{number:t.prNumber,baseSha:t.base.sha,headSha:t.head.sha},files:[...s].sort(),source:{provider:`github-pull-request-files`,expectedFileCount:r,fetchedFileCount:a.length,pageCount:o,perPage:100,maxFiles:y_},diagnostics:u}}function x_(e){let t=F_(e,`changed-files manifest`);if(j_(t,[`kind`,`version`,`complete`,`pullRequest`,`files`,`source`,`diagnostics`],`changed-files manifest`),t.kind!==`kapture-changed-files`||t.version!==1)throw Error(`changed-files manifest must use kapture-changed-files version 1`);if(typeof t.complete!=`boolean`)throw Error(`changed-files manifest complete must be a boolean`);if(!Array.isArray(t.files)||t.files.length>6e3)throw Error(`changed-files manifest files must be a bounded array`);let n=t.files.map(e=>S_(e,`changed file path`));if(!O_(n))throw Error(`changed-files manifest files must be unique and sorted`);let r=F_(t.pullRequest,`changed-files manifest pullRequest`);j_(r,[`number`,`baseSha`,`headSha`],`changed-files manifest pullRequest`);let i=F_(t.source,`changed-files manifest source`);if(j_(i,[`provider`,`expectedFileCount`,`fetchedFileCount`,`pageCount`,`perPage`,`maxFiles`],`changed-files manifest source`),i.provider!==`github-pull-request-files`)throw Error(`changed-files manifest source provider is invalid`);if(i.perPage!==100||i.maxFiles!==3e3)throw Error(`changed-files manifest source limits are invalid`);if(!Array.isArray(t.diagnostics)||t.diagnostics.length>6e3)throw Error(`changed-files manifest diagnostics must be a bounded array`);let a=t.diagnostics.map(E_);if(!O_(a.map(k_)))throw Error(`changed-files manifest diagnostics must be unique and sorted`);if(t.complete!==(a.length===0))throw Error(`changed-files manifest completeness disagrees with diagnostics`);let o=P_(i.expectedFileCount,`changed-files expected file count`),s=P_(i.fetchedFileCount,`changed-files fetched file count`),c=P_(i.pageCount,`changed-files page count`);if(s>3e3||c>30||s>c*100||n.length>s*2)throw Error(`changed-files manifest source counts are inconsistent`);if(t.complete&&(o!==s||o>3e3||c!==Math.ceil(s/100)||n.length<s))throw Error(`complete changed-files manifest source counts are inconsistent`);return{kind:`kapture-changed-files`,version:1,complete:t.complete,pullRequest:{number:N_(r.number,`changed-files pull request number`),baseSha:M_(r.baseSha,`changed-files base SHA`),headSha:M_(r.headSha,`changed-files head SHA`)},files:n,source:{provider:`github-pull-request-files`,expectedFileCount:o,fetchedFileCount:s,pageCount:c,perPage:100,maxFiles:y_},diagnostics:a}}function S_(e,t=`GitHub file path`){if(typeof e!=`string`)throw Error(`${t} must be a string`);let n=Array.from(e);if(e.length===0||e.length>4096||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`./`)||e===`.`||e===`..`||e.startsWith(`../`)||e.endsWith(`/`)||e.includes(`//`)||e.includes(`\\`)||e.split(`/`).some(e=>e===`.`||e===`..`)||n.some(e=>{let t=e.codePointAt(0)??0;return t<=31||t>=127&&t<=159}))throw Error(`${t} must be a normalized project-relative path`);return e}function C_(e,t){let n=e.head.repo;if(e.number!==t.prNumber||e.state!==`open`||e.base.ref!==t.base.ref||e.base.sha.toLowerCase()!==t.base.sha||e.base.repo.full_name!==t.base.repository||e.head.ref!==t.head.ref||e.head.sha.toLowerCase()!==t.head.sha||n?.id!==t.head.repositoryId||n.full_name!==t.head.repository)throw Error(`Live pull request does not match the exact Kapture capture context`)}function w_(e,t,n,r){if(!e.value||typeof e.value!=`object`||Array.isArray(e.value)){r.push({code:`invalid-file-record`,page:e.page,index:e.index});return}let i=e.value;if(typeof i.status!=`string`||typeof i.filename!=`string`){r.push({code:`invalid-file-record`,page:e.page,index:e.index});return}let a=JSON.stringify([i.status,i.filename,i.previous_filename]);if(n.has(a)&&r.push({code:`duplicate-file-entry`,page:e.page,index:e.index}),n.add(a),T_(i.filename,e,t,r),i.status===`renamed`||i.previous_filename!==void 0){if(typeof i.previous_filename!=`string`){r.push({code:`rename-source-missing`,page:e.page,index:e.index});return}T_(i.previous_filename,e,t,r)}}function T_(e,t,n,r){try{n.add(S_(e))}catch{r.push({code:`invalid-file-path`,page:t.page,index:t.index})}}function E_(e){let t=F_(e,`changed-files diagnostic`);if(j_(t,[`code`,`page`,`index`],`changed-files diagnostic`,!0),typeof t.code!=`string`||![`github-file-limit`,`pagination-incomplete`,`file-count-mismatch`,`invalid-file-record`,`invalid-file-path`,`rename-source-missing`,`duplicate-file-entry`].includes(t.code))throw Error(`changed-files diagnostic code is invalid`);let n=t.page===void 0?void 0:N_(t.page,`page`),r=t.index===void 0?void 0:P_(t.index,`diagnostic index`),i={code:t.code,...n===void 0?{}:{page:n},...r===void 0?{}:{index:r}};if(i.code===`github-file-limit`||i.code===`file-count-mismatch`?n!==void 0||r!==void 0:i.code===`pagination-incomplete`?n===void 0||n>30||r!==void 0:n===void 0||n>30||r===void 0||r>=100)throw Error(`changed-files diagnostic location is invalid`);return i}function D_(e){return[...new Map(e.map(e=>[JSON.stringify(e),e])).values()].sort((e,t)=>A_(k_(e),k_(t)))}function O_(e){return e.every((t,n)=>n===0||(e[n-1]??``)<t)}function k_(e){return`${e.code}:${String(e.page??0).padStart(2,`0`)}:${String(e.index??0).padStart(3,`0`)}`}function A_(e,t){return e<t?-1:+(e>t)}function j_(e,t,n,r=!1){let i=Object.keys(e).sort(),a=r?i.filter(e=>t.includes(e)).sort():[...t].sort();if(i.some(e=>!t.includes(e))||!r&&(i.length!==a.length||i.some((e,t)=>e!==a[t])))throw Error(`${n} contains unexpected or missing fields`)}function M_(e,t){if(typeof e!=`string`||!/^[0-9a-f]{40}$/.test(e))throw Error(`${t} must be a full lowercase SHA`);return e}function N_(e,t){let n=P_(e,t);if(n===0)throw Error(`${t} must be a positive integer`);return n}function P_(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative integer`);return e}function F_(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}Bc(),kg();const I_=2e4,L_=26214400,R_=1073741824,z_=jg+Ig.length+3,B_=/^[0-9a-f]{40}$/,V_=/^sha256:[0-9a-f]{64}$/,H_=/^[0-9a-f]{64}$/,U_=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,W_=/^\.github\/workflows\/[A-Za-z0-9_./-]+\.ya?ml$/,G_=RegExp(`^images/(?:${Ig.join(`|`)})/[A-Za-z0-9][A-Za-z0-9._-]*\\.png$`),K_=R().min(1).max(512).refine(e=>!ny(e),`must not contain control characters`),q_=R().regex(B_),J_=z().int().positive().max(2**53-1),Y_=R().regex(U_),X_=R().regex(V_),Z_=B({schemaVersion:V(1),runId:J_,prNumber:J_,base:B({repository:Y_,ref:K_,sha:q_}),head:B({repository:Y_,repositoryId:J_,ref:K_,sha:q_}),preview:B({branch:K_,alias:K_})}),Q_=B({id:J_,name:K_,sizeInBytes:J_,digest:X_}),$_=B({id:J_,name:K_,digest:X_}),ev=B({schemaVersion:V(1),artifacts:B({context:$_,baseStorybook:$_,headStorybook:$_})}),tv=B({schemaVersion:V(2),repository:B({id:J_,fullName:Y_}),context:Z_,captureRun:B({id:J_,runNumber:J_,attempt:J_,workflowId:J_,workflowPath:K_,headSha:q_,headBranch:K_,headRepositoryId:J_,headRepository:Y_}),artifacts:B({context:Q_,baseStorybook:Q_,headStorybook:Q_,report:Q_}),report:B({contentDigest:R().regex(H_)}),trustedArtifactName:K_});async function nv(e,t){let n=Jv(t.captureWorkflowPath),r=Qv(t.baseBranch,`base branch`),i=f(t.outputDir),a=f(t.receiptPath);if(ay(i,a))throw Error(`Trusted receipt must be outside the publicly deployed report directory`);await qv(a,`Trusted receipt`);let o=ov(t.event,n),s=await e.getWorkflowRun(o.run.id);Av(s,o),await cv(e,s);let c=lv(await e.listRunArtifacts(s.id),o),l=await Gv(t.temporaryRoot),u=!1;try{let d=await fv(e,c.context,33685504),p=f(l,`context`);_v(d),await r_(d,p,pv);let m=await Sv(f(p,`context.json`)),h=await Cv(f(p,`changed-files.json`),m);Tv(m,c.context),Ev(m,o,s,r),Ov(await e.getPullRequest(m.prNumber),m,o,r),await kv(e,m,n);let g=await fv(e,c.report,629145600),_=f(l,`untrusted-report`);vv(g),await r_(g,_,hv),xv(await bv(f(_,`capture-boundary.json`)),c);let v=await cg(f(_,`report.json`));wv(v,h),await Kf(e,Uv(o,m),v);let y=await Rg({inputDir:_,outputDir:i,trustedHeadBranch:m.head.ref,trustedPullRequest:{repository:m.base.repository,number:m.prNumber,url:`https://github.com/${m.base.repository}/pull/${m.prNumber}`,baseBranch:m.base.ref,headBranch:m.head.ref,workflowRunUrl:`https://github.com/${m.base.repository}/actions/runs/${o.run.id}`},...t.storybookUrl?{storybookUrl:t.storybookUrl}:{},...t.dashboardDir?{dashboardDir:f(t.dashboardDir)}:{}});if(u=!0,!y.report.contentDigest)throw Error(`Trusted report build did not produce an image-bound content digest`);await Hv(e,o,s,m,r,n);let ee=jv(o,s,m,c,y.report);return await Kv(a,ee),{receipt:ee,report:y.report,reportDirectory:i,reportPath:f(i,`report.json`),receiptPath:a,changedFiles:h}}catch(e){throw u&&await re(i,{recursive:!0,force:!0}),e}finally{await re(l,{recursive:!0,force:!0})}}async function rv(e,t,n){let r=await sv(n.receiptPath),i=ov(n.event,r.captureRun.workflowPath);Pv(r,i);let a=await e.getWorkflowRun(r.captureRun.id);Fv(a,r),await cv(e,a),await Iv(e,r,i),Ov(await e.getPullRequest(r.context.prNumber),r.context,i,r.context.base.ref),await kv(e,r.context,r.captureRun.workflowPath);let o=await Bg(n.reportPath,r.report.contentDigest);if(o.headBranch!==r.context.head.ref)throw Error(`Trusted report branch does not match its verified pull request context`);let s=Uv(i,r.context);return await Kf(e,s,o),qf(t,s,o,n.statusContext,n.reportUrl,n.commentLanguage)}async function iv(e,t){let n=Jv(t.captureWorkflowPath),r=Qv(t.baseBranch,`base branch`),i=f(t.outputDir),o=f(t.receiptPath);await qv(i,`Trusted Storybook output`);let s=await sv(o),c=ov(t.event,n);Pv(s,c);let l=await e.getWorkflowRun(s.captureRun.id);Fv(l,s),await cv(e,l),await Iv(e,s,c),Ov(await e.getPullRequest(s.context.prNumber),s.context,c,r),await kv(e,s.context,n);let u=f(t.temporaryRoot??a(i));if(ay(i,u))throw Error(`Trusted Storybook temporary root must be outside its output directory`);let d=await Gv(u),p=f(d,`storybook`);try{let t=await fv(e,s.artifacts.headStorybook,536870912);return yv(t),await r_(t,p,gv),await Hv(e,c,l,s.context,r,n),await Iv(e,s,c),await qv(i,`Trusted Storybook output`),await y(a(i),{recursive:!0}),await ne(p,i),{receipt:s,receiptPath:o,context:s.context,artifact:s.artifacts.headStorybook,storybookDirectory:i}}finally{await re(d,{recursive:!0,force:!0})}}async function av(e,t){let n=await sv(t.receiptPath),r=ov(t.event,n.captureRun.workflowPath);Pv(n,r),Fv(await e.getWorkflowRun(n.captureRun.id),n);let i=t.trustedArtifactId,a=t.trustedArtifactDigest?Bv(t.trustedArtifactDigest):void 0,o=[i,a];if(o.some(e=>e!==void 0)&&o.some(e=>e===void 0))throw Error(`trusted-artifact-id and trusted-artifact-digest must be provided together`);if(i!==void 0&&!ty(i))throw Error(`trusted-artifact-id must be a positive integer`);let s=i!==void 0&&a!==void 0?Vv():void 0,c=[];for(let t of Lv(n)){let n=await e.getArtifact(t.id);n&&(Rv(n,t,r),c.push({artifact:n,expected:t}))}if(i!==void 0&&a!==void 0&&s!==void 0){if(Lv(n).some(e=>e.id===i))throw Error(`trusted-artifact-id must not duplicate a source artifact ID`);let t=await e.getArtifact(i);t&&(zv(t,a,s,n),c.push({artifact:t,expected:{id:t.id,name:t.name,sizeInBytes:t.sizeInBytes,digest:t.digest}}))}let l=[...new Set(c.map(({artifact:e})=>e.id))];for(let t of l)await e.deleteArtifact(t);return l}function ov(e,t){let n=ry(e,`GitHub workflow_run event`);if(n.action!==`completed`)throw Error(`Kapture trusted run requires a completed workflow_run event`);let r=ry(n.repository,`event repository`),i=Yv(r.full_name,`event repository`),a=Xv(i),o=ey(r.id,`event repository ID`),s=ry(n.workflow_run,`workflow_run`),c=Jv($v(s.path,`workflow path`));if(c!==Jv(t))throw Error(`workflow_run path ${c} does not match ${t}`);if(s.status!==`completed`||s.conclusion!==`success`||s.event!==`pull_request`)throw Error(`Kapture trusted run requires one successful pull_request capture run`);let l=ry(s.head_repository,`workflow_run head repository`),u=iy(s.pull_requests,`workflow_run pull_requests`);if(u.length>1)throw Error(`workflow_run must contain at most one pull request`);let d=u[0]?Wv(u[0]):void 0;return{repository:{id:o,fullName:i,ref:a},run:{id:ey(s.id,`workflow run ID`),runNumber:ey(s.run_number,`workflow run number`),attempt:ey(s.run_attempt,`workflow run attempt`),workflowId:ey(s.workflow_id,`workflow ID`),workflowPath:c,status:`completed`,conclusion:`success`,event:`pull_request`,headSha:Zv(s.head_sha,`workflow run head SHA`),headBranch:Qv(s.head_branch,`workflow run head branch`),headRepository:{id:ey(l.id,`workflow run head repository ID`),fullName:Yv(l.full_name,`workflow run head repository`)}},...d?{pullRequest:d}:{}}}async function sv(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size<1||n.size>65536)throw Error(`Trusted receipt must be a file no larger than 65536 bytes`);let r;try{r=JSON.parse(await x(t,`utf8`))}catch{throw Error(`Trusted receipt does not contain valid JSON`)}let i=tv.safeParse(r);if(!i.success){let e=i.error.issues[0];throw Error(`Invalid trusted receipt${e?.path.length?` at ${e.path.join(`.`)}`:``}: ${e?.message??`unknown error`}`)}return Nv(i.data),i.data}async function cv(e,t){if(!await mt(e,t))throw Error(`A newer Kapture capture run owns this repository and branch`)}function lv(e,t){let n=/^kapture-context-pr-([1-9][0-9]*)-base-([0-9a-f]{40})-head-([0-9a-f]{40})$/,r=e.filter(e=>n.test(e.name)?dv(e,t):!1);if(r.length!==1||!r[0])throw Error(`Triggering run must contain exactly one immutable Kapture context artifact`);let i=r[0];if(i.sizeInBytes>33685504)throw Error(`Kapture context artifact exceeds its compressed size limit`);let a=i.name.match(n);if(!a?.[1]||!a[2]||!a[3])throw Error(`Kapture context artifact name is invalid`);let o=`kapture-visual-report-pr-${a[1]}-base-${a[2]}-head-${a[3]}`,s=e.filter(e=>e.name===o&&dv(e,t));if(s.length!==1||!s[0])throw Error(`Triggering run must contain exactly one matching Kapture report artifact`);if(s[0].sizeInBytes>629145600)throw Error(`Kapture report artifact exceeds its compressed size limit`);let c=`pr-${a[1]}-base-${a[2]}-head-${a[3]}`,l=uv(e,`kapture-storybook-base-${c}`,t),u=uv(e,`kapture-storybook-head-${c}`,t),d=[i,l,u,s[0]];if(new Set(d.map(e=>e.id)).size!==d.length||new Set(d.map(e=>e.name)).size!==d.length)throw Error(`Kapture artifact IDs and names must be distinct`);return{context:i,baseStorybook:l,headStorybook:u,report:s[0]}}function uv(e,t,n){let r=e.filter(e=>e.name===t&&dv(e,n));if(r.length!==1||!r[0])throw Error(`Triggering run must contain exactly one non-expired ${t} artifact`);if(r[0].sizeInBytes>536870912)throw Error(`${t} exceeds its compressed size limit`);return r[0]}function dv(e,t){return!e.expired&&e.workflowRun.id===t.run.id&&e.workflowRun.repositoryId===t.repository.id&&e.workflowRun.headRepositoryId===t.run.headRepository.id&&e.workflowRun.headBranch===t.run.headBranch&&e.workflowRun.headSha===t.run.headSha&&V_.test(e.digest)&&ty(e.id)&&ty(e.sizeInBytes)}async function fv(e,t,n){let r=await e.downloadArtifactArchive(t.id,n);if(r.byteLength!==t.sizeInBytes)throw Error(`Artifact ${t.id} download size does not match GitHub metadata`);if(`sha256:${T(`sha256`).update(r).digest(`hex`)}`!==t.digest)throw Error(`Artifact ${t.id} download digest does not match GitHub metadata`);return r}const pv={maxEntries:2,maxFileBytes:33554432,maxTotalBytes:33619968,allowPath:e=>e===`context.json`||e===`changed-files.json`,allowDirectoryPath:()=>!1},mv=new Set([`images/`,...Ig.map(e=>`images/${e}/`)]),hv={maxEntries:z_,maxFileBytes:Mg,maxTotalBytes:629145600,allowPath:e=>e===`report.json`||e===`capture-boundary.json`||G_.test(e),allowDirectoryPath:e=>mv.has(e)},gv={maxEntries:I_,maxFileBytes:L_,maxTotalBytes:R_,allowPath:()=>!0,allowDirectoryPath:()=>!0};function _v(e){let t=n_(e,pv);if(t.length!==2)throw Error(`Context archive must contain exactly context.json and changed-files.json`);let n=t.find(e=>e.path===`context.json`),r=t.find(e=>e.path===`changed-files.json`);if(!n||n.uncompressedBytes<1||n.uncompressedBytes>65536||!r||r.uncompressedBytes<1||r.uncompressedBytes>33554432)throw Error(`Context archive entries are outside their fixed size contract`)}function vv(e){let t=n_(e,hv),n=new Set,r=0,i=0;for(let e of t){let t=e.path.toLocaleLowerCase(`en-US`);if(n.has(t))throw Error(`Report archive contains a case-insensitive duplicate: ${e.path}`);if(n.add(t),e.uncompressedBytes<1)throw Error(`Report archive contains an empty file: ${e.path}`);if(e.path===`report.json`&&(r+=1,e.uncompressedBytes>10485760))throw Error(`report.json exceeds its uncompressed size limit`);if(e.path===`capture-boundary.json`&&(i+=1,e.uncompressedBytes>65536))throw Error(`capture-boundary.json exceeds its uncompressed size limit`)}if(r!==1)throw Error(`Report archive must contain one root report.json file`);if(i!==1)throw Error(`Report archive must contain one root capture-boundary.json file`)}function yv(e){let t=n_(e,gv),n=new Set,r=0;for(let e of t){let t=e.path.toLocaleLowerCase(`en-US`);if(n.has(t))throw Error(`Storybook archive contains a case-insensitive duplicate: ${e.path}`);n.add(t),e.path===`index.html`&&e.uncompressedBytes>0&&(r+=1)}if(r!==1)throw Error(`Storybook archive must contain one non-empty root index.html file`)}async function bv(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch(e){throw Error(`capture-boundary.json must contain valid JSON`,{cause:e})}return ev.parse(t)}function xv(e,t){for(let n of[`context`,`baseStorybook`,`headStorybook`]){let r=e.artifacts[n],i=t[n];if(i.id!==r.id||i.name!==r.name||i.digest!==r.digest)throw Error(`Capture ${n} artifact does not match its exact downloaded identity`)}}async function Sv(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch{throw Error(`Kapture context artifact does not contain valid JSON`)}let n=Z_.safeParse(t);if(!n.success){let e=n.error.issues[0];throw Error(`Invalid Kapture capture context${e?.path.length?` at ${e.path.join(`.`)}`:``}: ${e?.message??`unknown error`}`)}if(n.data.preview.branch!==n.data.head.ref||n.data.preview.alias!==f_(n.data.prNumber,n.data.head.ref))throw Error(`Kapture context preview identity is not derived from its pull request branch`);return n.data}async function Cv(e,t){let n=await C(e);if(!n.isFile()||n.size<1||n.size>33554432)throw Error(`changed-files.json is outside its fixed size contract`);let r;try{r=JSON.parse(await x(e,`utf8`))}catch{throw Error(`changed-files.json does not contain valid JSON`)}let i=x_(r);if(i.pullRequest.number!==t.prNumber||i.pullRequest.baseSha!==t.base.sha||i.pullRequest.headSha!==t.head.sha)throw Error(`changed-files.json does not belong to the exact capture context`);return i}function wv(e,t){let n=e.coverage;if(!n)throw Error(`Trusted workflow reports must include audited story coverage`);let r=n.changedFilesEvidence;if(!r)throw Error(`Trusted workflow report coverage must include changed-files evidence`);let i=T(`sha256`).update(JSON.stringify(t)).digest(`hex`);if(r.provider!==t.source.provider||r.manifestDigest!==i||r.pullRequestNumber!==t.pullRequest.number||r.baseSha!==t.pullRequest.baseSha||r.headSha!==t.pullRequest.headSha)throw Error(`Trusted workflow report changed-files evidence does not match its verified context manifest`)}function Tv(e,t){let n=`kapture-context-${d_(e)}`;if(t.name!==n)throw Error(`Kapture context contents do not match the immutable artifact name`)}function Ev(e,t,n,r){if(e.runId!==n.id||e.base.repository!==t.repository.fullName||e.base.ref!==r||e.head.repository!==n.headRepository.fullName||e.head.repositoryId!==n.headRepository.id||e.head.ref!==n.headBranch)throw Error(`Kapture capture context does not belong to the triggering workflow run`);Dv(t,e)}function Dv(e,t){let n=e.pullRequest;if(n&&(n.number!==t.prNumber||n.base.repositoryId!==e.repository.id||n.base.ref!==t.base.ref||n.base.sha!==t.base.sha||n.head.repositoryId!==t.head.repositoryId||n.head.ref!==t.head.ref||n.head.sha!==t.head.sha))throw Error(`workflow_run pull request metadata conflicts with the capture context`)}function Ov(e,t,n,r){if(e.number!==t.prNumber||e.state!==`open`||e.base.repository.id!==n.repository.id||e.base.repository.fullName!==t.base.repository||e.base.ref!==r||e.base.sha!==t.base.sha||e.head.repository.id!==t.head.repositoryId||e.head.repository.fullName!==t.head.repository||e.head.ref!==t.head.ref||e.head.sha!==t.head.sha)throw Error(`Kapture artifacts are stale or do not belong to the current open pull request`);Dv(n,t)}async function kv(e,t,n){let[r,i]=await Promise.all([e.getContentSha(t.base.repository,n,t.base.sha),e.getContentSha(t.head.repository,n,t.head.sha)]);if(!B_.test(r)||i!==r)throw Error(`Pull requests that modify the capture workflow require separate review before publishing`)}function Av(e,t){if(e.id!==t.run.id||e.runNumber!==t.run.runNumber||e.runAttempt!==t.run.attempt||e.workflowId!==t.run.workflowId||e.path!==t.run.workflowPath||e.status!==`completed`||e.conclusion!==`success`||e.event!==`pull_request`||e.headSha!==t.run.headSha||e.headBranch!==t.run.headBranch||e.headRepository.id!==t.run.headRepository.id||e.headRepository.fullName!==t.run.headRepository.fullName||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Triggering capture run metadata changed or no longer matches the event`)}function jv(e,t,n,r,i){if(!i.contentDigest)throw Error(`Trusted report is missing contentDigest`);if(i.headBranch!==n.head.ref)throw Error(`Trusted report branch does not match its verified pull request context`);let a=d_(n);return{schemaVersion:2,repository:{id:e.repository.id,fullName:e.repository.fullName},context:n,captureRun:{id:t.id,runNumber:t.runNumber,attempt:t.runAttempt,workflowId:t.workflowId,workflowPath:t.path,headSha:t.headSha,headBranch:t.headBranch,headRepositoryId:t.headRepository.id,headRepository:t.headRepository.fullName},artifacts:{context:Mv(r.context),baseStorybook:Mv(r.baseStorybook),headStorybook:Mv(r.headStorybook),report:Mv(r.report)},report:{contentDigest:i.contentDigest},trustedArtifactName:`kapture-trusted-report-${a}`}}function Mv(e){return{id:e.id,name:e.name,sizeInBytes:e.sizeInBytes,digest:e.digest}}function Nv(e){let t=d_(e.context);if(e.context.runId!==e.captureRun.id||e.context.base.repository!==e.repository.fullName||e.context.head.repository!==e.captureRun.headRepository||e.context.head.repositoryId!==e.captureRun.headRepositoryId||e.context.head.ref!==e.captureRun.headBranch||e.context.preview.branch!==e.context.head.ref||e.context.preview.alias!==f_(e.context.prNumber,e.context.head.ref)||e.artifacts.context.name!==`kapture-context-${t}`||e.artifacts.baseStorybook.name!==`kapture-storybook-base-${t}`||e.artifacts.headStorybook.name!==`kapture-storybook-head-${t}`||e.artifacts.report.name!==`kapture-visual-report-${t}`||e.trustedArtifactName!==`kapture-trusted-report-${t}`||new Set(Lv(e).map(e=>e.id)).size!==4||new Set(Lv(e).map(e=>e.name)).size!==4||e.artifacts.context.sizeInBytes>33685504||e.artifacts.baseStorybook.sizeInBytes>536870912||e.artifacts.headStorybook.sizeInBytes>536870912||e.artifacts.report.sizeInBytes>629145600||!W_.test(e.captureRun.workflowPath))throw Error(`Trusted receipt fields are not internally consistent`)}function Pv(e,t){if(Nv(e),e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName||e.captureRun.id!==t.run.id||e.captureRun.runNumber!==t.run.runNumber||e.captureRun.attempt!==t.run.attempt||e.captureRun.workflowId!==t.run.workflowId||e.captureRun.workflowPath!==t.run.workflowPath||e.captureRun.headSha!==t.run.headSha||e.captureRun.headBranch!==t.run.headBranch||e.captureRun.headRepositoryId!==t.run.headRepository.id||e.captureRun.headRepository!==t.run.headRepository.fullName)throw Error(`Trusted receipt does not belong to the triggering workflow_run event`);Dv(t,e.context)}function Fv(e,t){if(e.id!==t.captureRun.id||e.runNumber!==t.captureRun.runNumber||e.runAttempt!==t.captureRun.attempt||e.workflowId!==t.captureRun.workflowId||e.path!==t.captureRun.workflowPath||e.status!==`completed`||e.conclusion!==`success`||e.event!==`pull_request`||e.headSha!==t.captureRun.headSha||e.headBranch!==t.captureRun.headBranch||e.headRepository.id!==t.captureRun.headRepositoryId||e.headRepository.fullName!==t.captureRun.headRepository||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Capture run changed after prepare-run verification`)}async function Iv(e,t,n){let r=await e.listRunArtifacts(t.captureRun.id);for(let e of Lv(t)){let t=r.filter(t=>t.id===e.id);if(t.length!==1||!t[0])throw Error(`Receipt-bound artifact ${e.id} is no longer available`);Rv(t[0],e,n)}}function Lv(e){return[e.artifacts.context,e.artifacts.baseStorybook,e.artifacts.headStorybook,e.artifacts.report]}function Rv(e,t,n){if(e.id!==t.id||e.name!==t.name||e.sizeInBytes!==t.sizeInBytes||e.digest!==t.digest||!dv(e,n))throw Error(`Artifact ${t.id} no longer matches its trusted receipt binding`)}function zv(e,t,n,r){if(e.expired||e.name!==r.trustedArtifactName||e.digest!==t||e.workflowRun.id!==n||e.workflowRun.repositoryId!==r.repository.id||e.workflowRun.headRepositoryId!==r.repository.id||e.sizeInBytes>629145600)throw Error(`Trusted report artifact does not match the exact cleanup binding`)}function Bv(e){let t=e.startsWith(`sha256:`)?e:`sha256:${e}`;if(!V_.test(t))throw Error(`trusted-artifact-digest must be a 64-character SHA-256 digest`);return t}function Vv(){let e=process.env.GITHUB_RUN_ID;if(!e||!/^[1-9][0-9]*$/.test(e))throw Error(`GITHUB_RUN_ID must identify the current trusted reporter workflow run`);let t=Number(e);if(!Number.isSafeInteger(t))throw Error(`GITHUB_RUN_ID must be a safe positive integer`);return t}async function Hv(e,t,n,r,i,a){let o=await e.getWorkflowRun(n.id);Av(o,t),await cv(e,o),Ov(await e.getPullRequest(r.prNumber),r,t,i),await kv(e,r,a)}function Uv(e,t){return{repository:e.repository.ref,issueNumber:t.prNumber,headSha:t.head.sha,captureRunId:e.run.id,captureRunAttempt:e.run.attempt,captureWorkflowId:e.run.workflowId,captureRunHeadBranch:e.run.headBranch,captureRunHeadRepositoryId:e.run.headRepository.id}}function Wv(e){let t=ry(e,`workflow_run pull request`),n=ry(t.base,`workflow_run pull request base`),r=ry(t.head,`workflow_run pull request head`);return{number:ey(t.number,`workflow_run pull request number`),base:{repositoryId:ey(ry(n.repo,`workflow_run pull request base repository`).id,`workflow_run pull request base repository ID`),ref:Qv(n.ref,`workflow_run pull request base ref`),sha:Zv(n.sha,`workflow_run pull request base SHA`)},head:{repositoryId:ey(ry(r.repo,`workflow_run pull request head repository`).id,`workflow_run pull request head repository ID`),ref:Qv(r.ref,`workflow_run pull request head ref`),sha:Zv(r.sha,`workflow_run pull request head SHA`)}}}async function Gv(e){let t=f(e??process.env.RUNNER_TEMP??ce());return await y(t,{recursive:!0}),ee(`${t}${p}kapture-prepare-`)}async function Kv(e,t){let n=f(e),r=f(n,`..`);await y(r,{recursive:!0}),await w(n,`${JSON.stringify(t,null,2)}\n`,{flag:`wx`})}async function qv(e,t){try{await C(e)}catch(e){if(e.code===`ENOENT`)return;throw e}throw Error(`${t} already exists: ${e}`)}function Jv(e){if(!W_.test(e)||e.includes(`//`)||e.includes(`..`))throw Error(`capture-workflow-path must be a safe .github/workflows YAML path`);return e}function Yv(e,t){let n=$v(e,`${t} full name`);if(!U_.test(n))throw Error(`${t} full name is invalid`);return n}function Xv(e){let[t,n,...r]=e.split(`/`);if(!t||!n||r.length>0)throw Error(`Repository full name is invalid`);return{owner:t,repo:n}}function Zv(e,t){let n=$v(e,t);if(!B_.test(n))throw Error(`${t} must be a lowercase full SHA`);return n}function Qv(e,t){let n=$v(e,t);if(ny(n))throw Error(`${t} contains control characters`);return n}function $v(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);return e}function ey(e,t){if(!ty(e))throw Error(`${t} must be a positive integer`);return e}function ty(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function ny(e){return Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127})}function ry(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function iy(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}function ay(e,t){let n=d(e,t);return n===``||!s(n)&&n!==`..`&&!n.startsWith(`..${p}`)}function oy(e){let t=e.KAPTURE_ARTIFACT_SUFFIX;if(!t||!/^pr-[1-9][0-9]*-base-[0-9a-f]{40}-head-[0-9a-f]{40}$/.test(t))throw Error(`KAPTURE_ARTIFACT_SUFFIX must identify exact PR/base/head revisions`);let n=(n,r)=>{let i=e[`KAPTURE_${n}_ARTIFACT_ID`]??``,a=e[`KAPTURE_${n}_ARTIFACT_DIGEST`]??``;if(!/^[1-9][0-9]*$/.test(i)||!/^[0-9a-f]{64}$/.test(a))throw Error(`${n} requires an artifact ID and SHA-256 digest`);return{id:Number(i),name:`${r}-${t}`,digest:`sha256:${a}`}};return ev.parse({schemaVersion:1,artifacts:{context:n(`CONTEXT`,`kapture-context`),baseStorybook:n(`BASE`,`kapture-storybook-base`),headStorybook:n(`HEAD`,`kapture-storybook-head`)}})}A();const sy=k({meta:{name:`bind-artifacts`,description:`Record the exact downloaded artifact identities for trusted publication`},args:{output:{type:`string`,required:!0,description:`New capture-boundary.json path inside the raw report`}},async run({args:e}){let t=oy(process.env);await w(f(e.output),`${JSON.stringify(t)}\n`,{flag:`wx`,mode:384})}});A();const cy=k({meta:{name:`cleanup`,description:`Delete only exact receipt-bound Kapture artifact IDs`},args:{receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},"trusted-artifact-id":{type:`string`,description:`Exact current trusted report artifact ID`},"trusted-artifact-digest":{type:`string`,description:`upload-artifact SHA-256 digest for the current trusted report artifact`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf(),r=If(n),i=e[`trusted-artifact-id`]?ly(e[`trusted-artifact-id`],`trusted-artifact-id`):void 0,a=await av(new mf(t,r),{event:n,receiptPath:f(e.receipt),...i===void 0?{}:{trustedArtifactId:i},...e[`trusted-artifact-digest`]?{trustedArtifactDigest:e[`trusted-artifact-digest`]}:{}});await G({"deleted-artifact-count":a.length,"deleted-artifact-ids":a.join(`,`)})}});function ly(e,t){if(!/^[1-9][0-9]*$/.test(e))throw Error(`${t} must be a positive integer`);let n=Number(e);if(!Number.isSafeInteger(n))throw Error(`${t} must be a safe integer`);return n}A();const uy=k({meta:{name:`context`,description:`Validate a pull request event and write immutable Kapture capture context`},args:{"allow-initial-adoption":{type:`boolean`,default:!1,description:`Explicitly allow head-only setup validation when the base has no adapter`},"adapter-package-json":{type:`string`,description:`Optional project-relative package.json to check for the adapter on the exact base revision`},output:{type:`string`,required:!0,description:`Path for the normalized context JSON`},"changed-files-output":{type:`string`,required:!0,description:`Path for the versioned changed-files manifest`},"base-branch":{type:`string`,description:`Expected pull request base branch`}},async run({args:e}){let t=u_(await Nf(),e[`base-branch`]),n=process.env.GITHUB_TOKEN;if(!n)throw Error(`GITHUB_TOKEN is required`);let[r,i]=t.base.repository.split(`/`);if(!r||!i)throw Error(`Capture context repository is invalid`);let o=new Af(n,{owner:r,repo:i});if(e[`allow-initial-adoption`]&&!e[`adapter-package-json`])throw Error(`allow-initial-adoption requires adapter-package-json`);if(e[`allow-initial-adoption`]&&t.base.repository!==t.head.repository)throw Error(`Fork initial adoption is not supported`);let s=await b_(o,t),c=e[`adapter-package-json`]?dy(await o.readPackageManifest(e[`adapter-package-json`],t.base.sha),e[`allow-initial-adoption`]?{allowInitialAdoption:!0,headManifest:await o.readPackageManifest(e[`adapter-package-json`],t.head.sha),adapterVersion:Qe}:void 0):`compare`,l=f(e.output),u=f(e[`changed-files-output`]);if(l===u)throw Error(`output and changed-files-output must be different paths`);await Promise.all([y(a(l),{recursive:!0}),y(a(u),{recursive:!0})]),await Promise.all([w(l,`${JSON.stringify(t,null,2)}\n`,{flag:`wx`}),w(u,`${JSON.stringify(s,null,2)}\n`,{flag:`wx`})]),await G({"integration-mode":c,"artifact-suffix":d_(t),"base-repository":t.base.repository,"base-ref":t.base.ref,"base-sha":t.base.sha,"changed-files-complete":String(s.complete),"changed-files-count":s.files.length,"changed-files-path":u,"context-path":l,"head-repository":t.head.repository,"head-repository-id":t.head.repositoryId,"head-ref":t.head.ref,"head-sha":t.head.sha,"pr-number":t.prNumber,"preview-branch":t.preview.branch,"preview-alias":t.preview.alias})}});function dy(e,t){let n=fy(e);if(t?.allowInitialAdoption){if(fy(t.headManifest)!==t.adapterVersion)throw Error(`Head adapter must match the exact CLI version`);if(n===void 0)return`initial-adoption`;if(n!==t.adapterVersion)throw Error(`Base adapter must match the exact CLI version; not initial adoption`)}if(n!==void 0)return`compare`;throw Error(`The selected base package manifest does not declare @kaptures/storybook. Select the adapter's workspace manifest or omit --adapter-package-json to validate the built Storybook at capture time.`)}function fy(e){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`Invalid package manifest`);let t=e,n;for(let e of[`dependencies`,`devDependencies`]){let r=t[e];if(r!==void 0&&(!r||typeof r!=`object`||Array.isArray(r)))throw Error(`Invalid package dependencies`);let i=r?.[`@kaptures/storybook`];if(r&&Object.hasOwn(r,`@kaptures/storybook`)){if(typeof i!=`string`||!i.trim())throw Error(`Invalid adapter declaration`);if(n!==void 0&&n!==i)throw Error(`Conflicting adapter declarations`);n=i}}return n}const py=/^[0-9a-f]{40}$/,my=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,hy=/^\.github\/workflows\/[A-Za-z0-9_./-]+\.ya?ml$/,gy=`Base branch changed; rerun visual capture`,_y=new Set([`action_required`,`cancelled`,`failure`,`neutral`,`skipped`,`stale`,`startup_failure`,`success`,`timed_out`]);async function vy(e,t,n){let r=Ly(n.captureWorkflowPath),i=Vy(n.baseBranch,`base branch`),a=ef(n.statusContext),o=xy(n.event,r),s=await Sy(e,o,i);if(!s.ok)return Py(s.reason);if(await Ey(t,o,s.target))return Py(`final-report-exists`,s.target);let c=await Sy(e,o,i);if(!c.ok)return Py(c.reason,s.target);if(!Ny(s.target,c.target))return Py(`pull-request-changed`,c.target);if(await Ey(t,o,c.target))return Py(`final-report-exists`,c.target);let l=jy(o,c.target);return await t.setReviewStatus(c.target.headSha,l.state,l.description,a),{status:l.state,reason:`status-written`,prNumber:c.target.prNumber,headSha:c.target.headSha}}async function yy(e,t,n){let r=Ly(n.captureWorkflowPath),i=Vy(n.baseBranch,`base branch`),a=ef(n.statusContext),o=by(n.event,r),s=await Sy(e,o,i);if(!s.ok)return Fy(s.reason);let c=Oy(o,await Dy(t,o,s.target,a),s.target);if(c)return Fy(c,s.target);let l=await Sy(e,o,i);if(!l.ok)return Fy(l.reason,s.target);if(!Ny(s.target,l.target))return Fy(`pull-request-changed`,l.target);let u=Oy(o,await Dy(t,o,l.target,a),l.target);if(u)return Fy(u,l.target);let d=l.target.baseDrift?gy:o.run.conclusion===`success`?`Visual report publication did not complete`:`Visual capture did not succeed (${o.run.conclusion})`;return await t.setReviewStatus(l.target.headSha,`error`,d,a),{status:`error`,reason:`status-written`,prNumber:l.target.prNumber,headSha:l.target.headSha}}function by(e,t){let n=xy(e,t);if(n.run.status!==`completed`)throw Error(`Kapture finalize-run requires a completed workflow_run event`);return{...n,run:{...n.run,status:`completed`}}}function xy(e,t){let n=Ky(e,`GitHub workflow_run event`),r=Uy(n.action,`workflow_run action`);if(r!==`in_progress`&&r!==`completed`)throw Error(`Kapture reconcile-run requires an in_progress or completed workflow_run event`);let i=Ky(n.repository,`event repository`),a=Ry(i.full_name,`event repository`),o=Wy(i.id,`event repository ID`),s=Ky(n.workflow_run,`workflow_run`),c=Ly(Uy(s.path,`workflow path`));if(c!==Ly(t))throw Error(`workflow_run path ${c} does not match ${t}`);if(s.event!==`pull_request`)throw Error(`Kapture reconcile-run requires a pull_request capture run`);let l=Uy(s.status,`workflow run status`),u=Hy(s.conclusion,`workflow run conclusion`);if(r===`in_progress`&&(l!==`in_progress`||u!==null))throw Error(`An in_progress workflow_run event must describe an unfinished run`);if(r===`completed`&&(l!==`completed`||u===null||!_y.has(u)))throw Error(`A completed workflow_run event must have a supported conclusion`);let d=Ky(s.head_repository,`workflow_run head repository`),f={id:Wy(d.id,`workflow run head repository ID`),fullName:Ry(d.full_name,`workflow run head repository`)},p=Vy(s.head_branch,`workflow run head branch`),m=qy(s.pull_requests,`workflow_run pull requests`);if(m.length>1)throw Error(`workflow_run must contain at most one pull request`);let h=m[0]?Iy(m[0]):void 0;if(h&&(h.base.repositoryId!==o||h.head.repositoryId!==f.id||h.head.ref!==p))throw Error(`workflow_run pull request metadata conflicts with run provenance`);return{repository:{id:o,fullName:a,ref:zy(a)},run:{id:Wy(s.id,`workflow run ID`),runNumber:Wy(s.run_number,`workflow run number`),attempt:Wy(s.run_attempt,`workflow run attempt`),workflowId:Wy(s.workflow_id,`workflow ID`),workflowPath:c,status:l,conclusion:u,event:`pull_request`,headSha:By(s.head_sha,`workflow run head SHA`),headBranch:p,headRepository:f},...h?{pullRequest:h}:{}}}async function Sy(e,t,n){let r=await e.getWorkflowRun(t.run.id);return Cy(r,t),r.runAttempt===t.run.attempt?r.status!==t.run.status||r.conclusion!==t.run.conclusion?{ok:!1,reason:`stale-run-state`}:await mt(e,r)?wy(e,t,n):{ok:!1,reason:`superseded-run`}:{ok:!1,reason:`stale-run-attempt`}}function Cy(e,t){if(e.id!==t.run.id||e.runNumber!==t.run.runNumber||e.workflowId!==t.run.workflowId||Ly(e.path)!==t.run.workflowPath||e.event!==`pull_request`||e.headSha!==t.run.headSha||e.headBranch!==t.run.headBranch||e.headRepository.id!==t.run.headRepository.id||e.headRepository.fullName!==t.run.headRepository.fullName||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Triggering capture run identity no longer matches the workflow_run event`)}async function wy(e,t,n){if(t.pullRequest){if(t.pullRequest.base.ref!==n)return{ok:!1,reason:`base-branch-mismatch`};let r=await e.getPullRequest(t.pullRequest.number);return Ty(r,t,n)?{ok:!0,target:My(r,r.base.sha!==t.pullRequest.base.sha)}:{ok:!1,reason:`pull-request-not-current`}}let r=(await e.listOpenPullRequestsForHead(t.run.headRepository.fullName,t.run.headBranch,n)).filter(e=>e.state===`open`&&e.base.repository.id===t.repository.id&&e.base.repository.fullName===t.repository.fullName&&e.base.ref===n&&e.head.repository.id===t.run.headRepository.id&&e.head.repository.fullName===t.run.headRepository.fullName&&e.head.ref===t.run.headBranch);return r.length===0?{ok:!1,reason:`pull-request-not-found`}:r.length===1?{ok:!0,target:My(r[0])}:{ok:!1,reason:`pull-request-ambiguous`}}function Ty(e,t,n){let r=t.pullRequest;return!!(r&&e.number===r.number&&e.state===`open`&&e.base.repository.id===t.repository.id&&e.base.repository.fullName===t.repository.fullName&&e.base.ref===n&&e.head.repository.id===t.run.headRepository.id&&e.head.repository.fullName===t.run.headRepository.fullName&&e.head.ref===t.run.headBranch&&e.head.sha===r.head.sha)}async function Ey(e,t,n){return Ay(await e.findCurrentReportMarker(n.prNumber,n.baseSha,n.headSha),t)}async function Dy(e,t,n,r){let i=await e.findCurrentReportMarker(n.prNumber,n.baseSha,n.headSha),a=await e.getLatestReviewStatus(n.headSha,r);return{marker:Ay(i,t)?i:null,status:a}}function Oy(e,t,n){return n.baseDrift&&t.status?.state===`error`&&t.status.description===gy?`base-drift-already-recorded`:e.run.conclusion===`success`?ky(t)?`final-report-exists`:t.status?.state===`error`&&t.status.description===`Visual report publication did not complete`?`publication-failure-already-recorded`:void 0:t.status?.state===`error`?`capture-failure-already-recorded`:void 0}function ky(e){let{marker:t,status:n}=e;return!t?.reportUrl||!n||t.reportUrl!==n.targetUrl?!1:t.status===`clean`?n.state===`success`&&n.description===`No visual changes`:t.status===`changed`?n.state===`pending`&&n.description===Hf.standard.description||Wf(n,`standard`):t.status===`unstable`&&n.state===`success`?Wf(n,`allow-unstable`):n.state===`failure`}function Ay(e,t){return!!(e&&e.captureRunId===t.run.id&&e.captureRunAttempt===t.run.attempt&&e.captureWorkflowId===t.run.workflowId&&e.captureRunHeadBranch===t.run.headBranch&&e.captureRunHeadRepositoryId===t.run.headRepository.id)}function jy(e,t){return t.baseDrift?{state:`error`,description:gy}:e.run.status===`in_progress`?{state:`pending`,description:`Visual capture is in progress`}:e.run.conclusion===`success`?{state:`pending`,description:`Visual report is awaiting publication`}:{state:`error`,description:`Visual capture did not succeed (${e.run.conclusion})`}}function My(e,t=!1){return{prNumber:e.number,baseSha:e.base.sha,headSha:e.head.sha,baseDrift:t}}function Ny(e,t){return e.prNumber===t.prNumber&&e.baseSha===t.baseSha&&e.headSha===t.headSha&&e.baseDrift===t.baseDrift}function Py(e,t){return{status:`noop`,reason:e,...t?{prNumber:t.prNumber,headSha:t.headSha}:{}}}function Fy(e,t){return{status:`noop`,reason:e,...t?{prNumber:t.prNumber,headSha:t.headSha}:{}}}function Iy(e){let t=Ky(e,`workflow_run pull request`),n=Ky(t.base,`workflow_run pull request base`),r=Ky(t.head,`workflow_run pull request head`);return{number:Wy(t.number,`workflow_run pull request number`),base:{repositoryId:Wy(Ky(n.repo,`workflow_run pull request base repository`).id,`workflow_run pull request base repository ID`),ref:Vy(n.ref,`workflow_run pull request base ref`),sha:By(n.sha,`workflow_run pull request base SHA`)},head:{repositoryId:Wy(Ky(r.repo,`workflow_run pull request head repository`).id,`workflow_run pull request head repository ID`),ref:Vy(r.ref,`workflow_run pull request head ref`),sha:By(r.sha,`workflow_run pull request head SHA`)}}}function Ly(e){if(!hy.test(e)||e.includes(`//`)||e.includes(`..`))throw Error(`capture-workflow-path must be a safe .github/workflows YAML path`);return e}function Ry(e,t){let n=Uy(e,`${t} full name`);if(!my.test(n))throw Error(`${t} full name is invalid`);return n}function zy(e){let[t,n,...r]=e.split(`/`);if(!t||!n||r.length>0)throw Error(`Repository full name is invalid`);return{owner:t,repo:n}}function By(e,t){let n=Uy(e,t);if(!py.test(n))throw Error(`${t} must be a lowercase full SHA`);return n}function Vy(e,t){let n=Uy(e,t);if(Gy(n))throw Error(`${t} contains control characters`);return n}function Hy(e,t){return e===null?null:Uy(e,t)}function Uy(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);if(Gy(e))throw Error(`${t} contains control characters`);return e}function Wy(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function Gy(e){return Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127})}function Ky(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function qy(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}const Jy={"allow-initial-adoption":{type:`boolean`,default:!1},"adapter-package-json":{type:`string`}};async function Yy(e,t,n){if(!t[`allow-initial-adoption`])return!1;let r=t[`adapter-package-json`];if(!r)throw Error(`allow-initial-adoption requires adapter-package-json`);let i=process.env.GITHUB_TOKEN;if(!n&&!i)throw Error(`GITHUB_TOKEN is required`);let a=xy(e,t[`capture-workflow-path`]);if(a.run.headRepository.fullName!==a.repository.fullName)throw Error(`Fork initial adoption is not supported`);let o=await Sy(n?.runs??new mf(i,a.repository.ref),a,t[`base-branch`]);if(!o.ok||o.target.baseDrift)return!1;let s=n?.readPackageManifest??((e,t)=>new Af(i,a.repository.ref).readPackageManifest(e,t));return dy(await s(r,o.target.baseSha),{allowInitialAdoption:!0,adapterVersion:Qe,headManifest:await s(r,o.target.headSha)})===`initial-adoption`}A();const Xy=k({meta:{name:`finalize-run`,description:`Close an unfinished status for the exact completed trusted workflow run`},args:{...Jy,"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf();if(await Yy(n,e)){await G({status:`noop`,"finalize-reason":`initial-adoption-not-compared`});return}let r=If(n),i=await yy(new mf(t,r),new Af(t,r),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],statusContext:ef(e[`status-context`])});await G({status:i.status,"finalize-reason":i.reason,...i.prNumber===void 0?{}:{"pr-number":i.prNumber},...i.headSha?{"head-sha":i.headSha}:{}})}}),Zy={files:I_,fileBytes:L_,totalBytes:R_};function Qy(e,t){if(!t||s(t)||!/^[A-Za-z0-9._/-]+$/.test(t)||t.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Storybook directory must be a project-relative path without dot segments`);return f(e,t)}async function $y(e,t,n=Zy){let r=Qy(e,t),i=await S(e),a=f(e);for(let e of t.split(`/`)){a=c(a,e);let t=await v(a);if(t.isSymbolicLink()||!t.isDirectory())throw Error(`Storybook path must contain only non-symlink directories`)}let o=await S(r),l=d(i,o);if(l===`..`||l.startsWith(`..${p}`)||s(l))throw Error(`Storybook directory escapes the project root`);let u=(await v(r)).dev,m=[r],h=0,g=0,_=0;for(;m.length;){let e=m.pop();if(!e)break;for(let t of await te(e)){if(_++,_>n.files)throw Error(`Storybook exceeds its entry count boundary`);let r=c(e,t),i=await v(r);if(i.isSymbolicLink()||i.dev!==u)throw Error(`Storybook must not contain symbolic links or cross-device entries`);if(i.isDirectory()){m.push(r);continue}if(!i.isFile())throw Error(`Storybook must contain only regular files and directories`);if(h++,g+=i.size,h>n.files||i.size>n.fileBytes||g>n.totalBytes)throw Error(`Storybook exceeds its file or size boundary`)}}for(let e of[`index.html`,`iframe.html`,`index.json`])if(!(await v(c(r,e))).isFile())throw Error(`Storybook is missing a regular ${e}`);return{directory:r,files:h,bytes:g}}const eb=`<!-- kapture-preview -->`;function tb(e,t,n,r){if(e.base.repository!==e.head.repository||t.id!==e.runId||t.runAttempt!==n||t.path!==r||t.event!==`pull_request`||t.headBranch!==e.head.ref||t.headRepository.id!==e.head.repositoryId||t.headRepository.fullName!==e.head.repository||t.repository.fullName!==e.base.repository)throw Error(`Preview requires the exact same-repository pull request workflow run`)}function nb(e,t){if(t.baseRevision!==e.base.sha||t.headRevision!==e.head.sha)throw Error(`Preview report must match the exact event base/head revisions`)}function rb(e,t,n){let{summary:r}=e,i=Qd(t);if(!i)throw Error(`Preview report URL is required`);let a=Object.values(e.entries).filter(e=>e.status===`changed`).sort((e,t)=>e.id.localeCompare(t.id)),o=a.slice(0,10).map(e=>{let t=new URL(i);return t.hash=encodeURIComponent(e.id),`- [${af(`${e.title} / ${e.name} · ${e.viewport.name}`)}](${Qd(t.toString())})`});return a.length>10&&o.push(`- [View ${a.length-10} more changed snapshots](${i})`),[eb,`## Kapture preview`,``,`[Pixel comparison dashboard](${i})`,``,`Base: ${af(n.base.ref)} → Head: ${af(n.head.ref)}`,``,`Snapshots: ${r.total} · Changed: ${r.changed} · Unchanged: ${r.unchanged} · Unstable: ${r.unstable} · Added: ${r.added} · Removed: ${r.removed} · Errors: ${r.errors}`,...o.length?[``,`### Changed snapshots`,``,...o]:[],``,`Head: \`${e.headRevision}\``,`Report digest: \`${e.contentDigest}\``,``,`> Preview only. This result does not approve visual changes. Event-driven approval requires the production workflows on the default branch.`].join(`
669
- `)}A();const ib=k({meta:{name:`prepare-preview`,description:`Rebuild a same-repository pre-adoption preview without an approval gate`},args:{input:{type:`string`,required:!0},output:{type:`string`,required:!0},"base-branch":{type:`string`,required:!0},"storybook-directory":{type:`string`}},async run({args:e}){if(process.env.GITHUB_EVENT_NAME!==`pull_request`)throw Error(`Preview requires pull_request`);let t=u_(await Nf(),e[`base-branch`]);if(t.base.repository!==t.head.repository)throw Error(`Fork previews are not supported`);let n=f(e.output),r=await Rg({inputDir:f(e.input),outputDir:n,trustedBaseBranch:t.base.ref,trustedHeadBranch:t.head.ref,...e[`storybook-directory`]?{storybookUrl:`./storybook/`}:{}});if(nb(t,r.report),e[`storybook-directory`]){let t=f(e[`storybook-directory`]);await $y(a(t),i(t)),await _(t,f(n,`storybook`),{recursive:!0,errorOnExist:!0,force:!1})}await G({"report-directory":n,"report-path":f(n,`report.json`),"report-digest":r.report.contentDigest??``,"head-sha":t.head.sha,"preview-alias":t.preview.alias})}});A();const ab=k({meta:{name:`prepare-run`,description:`Download, verify, and rebuild a completed workflow_run report`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},output:{type:`string`,default:`.kapture/trusted-report`,description:`New directory for the trusted static report`},receipt:{type:`string`,default:`.kapture/trusted-run-receipt.json`,description:`Path for the strict trusted-run receipt`},"storybook-url":{type:`string`,description:`Trusted HTTPS Storybook URL or the fixed same-origin ./storybook/ directory`},"temporary-root":{type:`string`,description:`Trusted temporary directory root (defaults to RUNNER_TEMP)`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf(),r=await nv(new mf(t,If(n)),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],outputDir:f(e.output),receiptPath:f(e.receipt),...e[`storybook-url`]?{storybookUrl:e[`storybook-url`]}:{},...e[`temporary-root`]?{temporaryRoot:f(e[`temporary-root`])}:{}});await G({"base-sha":r.receipt.context.base.sha,"context-artifact-id":r.receipt.artifacts.context.id,"head-repository":r.receipt.context.head.repository,"head-sha":r.receipt.context.head.sha,"pr-number":r.receipt.context.prNumber,"preview-branch":r.receipt.context.preview.branch,"preview-alias":r.receipt.context.preview.alias,"raw-report-artifact-id":r.receipt.artifacts.report.id,"report-digest":r.receipt.report.contentDigest,"report-directory":r.reportDirectory,"report-path":r.reportPath,receipt:r.receiptPath,"run-attempt":r.receipt.captureRun.attempt,"run-head-branch":r.receipt.captureRun.headBranch,"run-head-repository-id":r.receipt.captureRun.headRepositoryId,"run-head-sha":r.receipt.captureRun.headSha,"run-id":r.receipt.captureRun.id,"changed-files-complete":String(r.changedFiles.complete),"changed-files-count":r.changedFiles.files.length,"trusted-artifact-name":r.receipt.trustedArtifactName,"workflow-id":r.receipt.captureRun.workflowId})}});A();const ob=k({meta:{name:`prepare-storybook-run`,description:`Verify and extract the exact receipt-bound head Storybook artifact`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},output:{type:`string`,required:!0,description:`New directory for the verified head Storybook`},receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},"temporary-root":{type:`string`,description:`Trusted temporary directory root (defaults beside output)`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf(),r=await iv(new mf(t,If(n)),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],outputDir:f(e.output),receiptPath:f(e.receipt),...e[`temporary-root`]?{temporaryRoot:f(e[`temporary-root`])}:{}});await G({"head-ref":r.context.head.ref,"head-repository":r.context.head.repository,"head-sha":r.context.head.sha,"head-storybook-artifact-id":r.artifact.id,"pr-number":r.context.prNumber,"preview-branch":r.context.preview.branch,"preview-alias":r.context.preview.alias,receipt:r.receiptPath,"storybook-directory":r.storybookDirectory})}});A();const sb=k({meta:{name:`reconcile-run`,description:`Reconcile a trusted workflow_run event with the current PR status`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf(),r=If(n),i=await vy(new mf(t,r),new Af(t,r),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],statusContext:ef(e[`status-context`])});await G({status:i.status,"reconcile-reason":i.reason,...i.prNumber===void 0?{}:{"pr-number":i.prNumber},...i.headSha?{"head-sha":i.headSha}:{}})}});A();async function cb(e,t,n=async(e,t)=>{switch(e){case`reconcile-run`:await ze(sb,{rawArgs:t});break;case`prepare-run`:await ze(ab,{rawArgs:t});break;case`prepare-storybook-run`:await ze(ob,{rawArgs:t})}}){let r=[`--capture-workflow-path`,t.captureWorkflowPath,`--base-branch`,t.baseBranch];if(await n(`reconcile-run`,[...r,`--status-context`,t.statusContext]),!e||typeof e!=`object`)throw Error(`Invalid workflow_run event`);let i=e;return i.action!==`completed`||i.workflow_run?.conclusion!==`success`?!1:(await n(`prepare-run`,[...r,`--output`,t.output,`--receipt`,t.receipt,...t.includeStorybook?[`--storybook-url`,`./storybook/`]:[]]),t.includeStorybook&&await n(`prepare-storybook-run`,[...r,`--output`,f(t.output,`storybook`),`--receipt`,t.receipt]),!0)}const lb=k({meta:{name:`prepare-review`,description:`Reconcile a workflow run and prepare verified static files for any hosting provider`},args:{...Jy,"capture-workflow-path":{type:`string`,default:`.github/workflows/kapture-capture.yml`},"base-branch":{type:`string`,required:!0},output:{type:`string`,required:!0},receipt:{type:`string`,required:!0},"include-storybook":{type:`boolean`,default:!1},"status-context":{type:`string`,default:`Kapture Visual Review`}},async run({args:e}){await G({ready:`false`});let t=await Nf();if(await Yy(t,e)){await G({"integration-mode":`initial-adoption`,comparison:`not-performed`});return}let n=await cb(t,{captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],output:f(e.output),receipt:f(e.receipt),includeStorybook:e[`include-storybook`],statusContext:e[`status-context`]});await G({ready:String(n)})}});A();const ub=k({meta:{name:`publish-preview`,description:`Publish a preview-only status and comment; never issue an approval marker`},args:{report:{type:`string`,required:!0},"report-digest":{type:`string`,required:!0},"report-url":{type:`string`,required:!0},"base-branch":{type:`string`,required:!0},"capture-workflow-path":{type:`string`,default:`.github/workflows/kapture-capture.yml`}},async run({args:e}){if(process.env.GITHUB_EVENT_NAME!==`pull_request`)throw Error(`Preview requires pull_request`);let t=u_(await Nf(),e[`base-branch`]),n=process.env.GITHUB_TOKEN;if(!n)throw Error(`GITHUB_TOKEN is required`);let[r,i]=t.base.repository.split(`/`);if(!r||!i)throw Error(`Invalid repository`);let a=new Af(n,{owner:r,repo:i}),o=new mf(n,{owner:r,repo:i}),s=await o.getWorkflowRun(t.runId);tb(t,s,Number(process.env.GITHUB_RUN_ATTEMPT),e[`capture-workflow-path`]);let c=await Bg(f(e.report),e[`report-digest`]);nb(t,c);let l=Qd(e[`report-url`]);if(!l)throw Error(`Preview report URL is required`);let u=async()=>{let n=await a.getPullRequest(t.prNumber);if(n.number!==t.prNumber||n.state!==`open`||n.head.sha!==t.head.sha||n.base.sha!==t.base.sha)throw Error(`Ignoring an obsolete preview result`);let r=await o.getWorkflowRun(t.runId);tb(t,r,s.runAttempt,e[`capture-workflow-path`]),await cv(o,r)};await u();let d=await a.postOrUpdateReportComment(t.prNumber,rb(c,l,t),eb);if(await u(),await a.setReviewStatus(t.head.sha,c.summary.errors?`failure`:`success`,`Preview only; visual changes require separate review`,`Kapture Preview`,l),await G({"comment-id":d,"report-digest":c.contentDigest??``}),c.summary.errors)throw Error(`Preview contains capture errors`)}});A();const db=k({meta:{name:`publish-run`,description:`Revalidate a prepare-run receipt and publish its deployed visual report`},args:{receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},report:{type:`string`,required:!0,description:`Path to the trusted image-bound report.json`},"report-url":{type:`string`,required:!0,description:`Immutable HTTPS URL of the deployed dashboard`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`PR comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await Nf(),r=If(n),i=Qd(e[`report-url`]);if(!i)throw Error(`report-url is required`);let a=await rv(new mf(t,r),new Af(t,r),{event:n,receiptPath:f(e.receipt),reportPath:f(e.report),reportUrl:i,statusContext:ef(e[`status-context`]),commentLanguage:Ud(e[`comment-language`])});if(await G({status:a.status,"changed-count":a.changedCount,"comment-id":a.commentId,"report-digest":a.reportDigest}),a.status===`error`)throw Error(`Visual capture errors were published to the trusted report`)}catch(e){throw await G({status:`error`}),e}}});A(),kg();const fb=k({meta:{name:`report`,description:`Publish a trusted Kapture PR report and commit status`},args:{report:{type:`string`,required:!0,description:`Path to image-bound trusted report.json`},"report-url":{type:`string`,description:`HTTPS URL for the full report or workflow run`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`PR comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await cg(e.report),r=Pf(await Nf()),i=ef(e[`status-context`]),a=Qd(e[`report-url`]),o=await qf(new Af(t,r.repository),r,n,i,a,Ud(e[`comment-language`]));if(await G({status:o.status,"changed-count":o.changedCount,"comment-id":o.commentId,"report-digest":o.reportDigest}),o.status===`error`)throw Error(`${n.summary.errors} visual capture error(s)`)}catch(e){throw await G({status:`error`}),e}}});async function pb(e){let t=``,n;try{let{client:r,repository:i,workflow:a,baseRevision:o,headRevision:s}=e,l=await r.getContentSha(i,a,o);if(await r.getContentSha(i,a,s)!==l)return e.warn(`Build cache disabled: capture workflow differs between base and head`),{name:t,directory:``};let u=JSON.stringify([1,i,o,a,l,e.version]);t=`kapture-build-${T(`sha256`).update(u).digest(`hex`)}`;let d=await r.listCaptureCacheArtifacts(t);for(let e of d.slice(0,5)){if(e.expired||e.name!==t||e.sizeInBytes>Zy.totalBytes||!/^sha256:[a-f0-9]{64}$/.test(e.digest))continue;let o=await r.getWorkflowRun(e.workflowRun.id);if(o.status!==`completed`||o.conclusion!==`success`||o.event!==`pull_request`||o.path!==a||o.repository.fullName!==i||o.headRepository.fullName!==i||o.headRepository.id!==o.repository.id||e.workflowRun.repositoryId!==o.repository.id||e.workflowRun.headRepositoryId!==o.repository.id||e.workflowRun.headSha!==o.headSha||!await r.isMergedCaptureRun(o.id,o.headSha)||await r.getContentSha(i,a,o.headSha)!==l)continue;let s=await r.downloadArtifactArchive(e.id,Zy.totalBytes);if(`sha256:${T(`sha256`).update(s).digest(`hex`)}`!==e.digest)throw Error(`Build cache archive digest mismatch`);n=await ee(c(ce(),`kapture-build-cache-`));let u=c(n,`storybook`);return await r_(s,u,{maxEntries:Zy.files,maxFileBytes:Zy.fileBytes,maxTotalBytes:Zy.totalBytes,allowPath:()=>!0,allowDirectoryPath:()=>!0}),await $y(n,`storybook`),{name:t,directory:u}}}catch(t){e.warn(`Build cache unavailable; build exact base: ${t instanceof Error?t.message:String(t)}`)}return n&&await re(n,{recursive:!0,force:!0}),{name:t,directory:``}}A();const mb=k({meta:{name:`restore-build`,description:`Restore a verified exact-base Storybook build`},args:{workflow:{type:`string`,required:!0,description:`Capture workflow path`}},async run({args:e}){if(!/^\.github\/workflows\/[A-Za-z0-9._-]+\.ya?ml$/.test(e.workflow))throw Error(`Expected repository-relative capture workflow path`);let t=u_(await Nf());if(t.base.repository!==t.head.repository)throw Error(`Build cache requires a same-repository pull request`);let[n,r]=t.base.repository.split(`/`),i=await pb({client:new mf(process.env.GITHUB_TOKEN??``,{owner:n,repo:r}),repository:t.base.repository,workflow:e.workflow,baseRevision:t.base.sha,headRevision:t.head.sha,version:Qe,warn:e=>console.warn(e)});await G({"cache-hit":String(!!i.directory),"cache-directory":i.directory,"cache-name":i.name})}});async function hb(e){let{client:t}=e,n=await t.getContentSha(e.repository,e.workflow,e.trustedRevision),r=await t.listCaptureCacheArtifacts(e.name);for(let i of r.slice(0,5)){if(i.expired||i.name!==e.name||i.sizeInBytes>1024**3||!/^sha256:[a-f0-9]{64}$/.test(i.digest))continue;let r=await t.getWorkflowRun(i.workflowRun.id);if(r.status!==`completed`||r.conclusion!==`success`||r.event!==`pull_request`||r.path!==e.workflow||r.repository.fullName!==e.repository||r.headRepository.fullName!==e.repository||i.workflowRun.repositoryId!==r.repository.id||i.workflowRun.headRepositoryId!==r.repository.id||!await t.isMergedCaptureRun(r.id,r.headSha)||await t.getContentSha(e.repository,e.workflow,r.headSha)!==n)continue;let a=await t.downloadArtifactArchive(i.id,1024**3);if(`sha256:${T(`sha256`).update(a).digest(`hex`)}`!==i.digest)throw Error(`Capture cache archive digest mismatch`);return await r_(a,e.output,{maxEntries:2e4,maxFileBytes:64*1024**2,maxTotalBytes:1024**3,allowPath:e=>e===`cache.json`||e===`manifest.json`||/^images\/[A-Za-z0-9._-]+\.png$/.test(e),allowDirectoryPath:e=>e===`images`}),!0}return!1}Ld(),A();const gb=k({meta:{name:`restore-capture`,description:`Restore merged head evidence matching the exact base build; cache misses never skip tests`},args:{"base-dir":{type:`string`,required:!0},"head-dir":{type:`string`,required:!0},workflow:{type:`string`,required:!0,description:`Repository-relative capture workflow path`},"base-revision":{type:`string`,required:!0}},async run({args:e}){if(!/^\.github\/workflows\/[A-Za-z0-9._-]+\.ya?ml$/.test(e.workflow)||!/^[a-f0-9]{40}$/.test(e[`base-revision`]))throw Error(`Expected capture workflow path and exact base revision`);let t=process.env.GITHUB_REPOSITORY??``,n=/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/.exec(t);if(!n)throw Error(`GITHUB_REPOSITORY is required`);let r=await Sl(f(e[`base-dir`]),Qe),i=await Sl(f(e[`head-dir`]),Qe),a=await ee(c(ce(),`kapture-capture-cache-`)),o=await ee(c(ce(),`kapture-head-cache-`)),s=!1;try{s=await hb({client:new mf(process.env.GITHUB_TOKEN??``,{owner:n[1],repo:n[2]}),name:`kapture-capture-${r}`,repository:t,workflow:e.workflow,trustedRevision:e[`base-revision`],output:a})}catch(e){console.warn(`Capture cache unavailable; capturing normally: ${e instanceof Error?e.message:String(e)}`)}await G({"cache-directory":a,"cache-hit":String(s),"head-cache-directory":o,"head-cache-name":`kapture-capture-${i}`})}});A();const _b=k({meta:{name:`validate-build`,description:`Validate a Storybook artifact boundary before upload or capture`},args:{root:{type:`string`,required:!0,description:`Trusted checkout or artifact extraction root`},directory:{type:`string`,required:!0,description:`Storybook directory relative to root`},"path-only":{type:`boolean`,default:!1,description:`Validate the input path before building`}},async run({args:e}){if(e[`path-only`]){await G({directory:Qy(e.root,e.directory)});return}let t=await $y(e.root,e.directory);await G(t),console.log(`Validated ${t.files} Storybook files (${t.bytes} bytes).`)}});A(),kg();const vb=k({meta:{name:`verify`,description:`Verify that a Kapture report matches the current pull request`},args:{report:{type:`string`,required:!0,description:`Path to untrusted report.json`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await cg(e.report),r=Pf(await Nf());await Kf(new Af(t,r.repository),r,n)}});A();const yb=k({meta:{name:`github`,description:`Verify, publish, and approve GitHub visual reviews`},subCommands:{"restore-build":mb,"restore-capture":gb,context:uy,"validate-build":_b,"bind-artifacts":sy,"prepare-review":lb,"prepare-preview":ib,"publish-preview":ub,verify:vb,report:fb,approve:Xf,"prepare-run":ab,"prepare-storybook-run":ob,"publish-run":db,"reconcile-run":sb,"finalize-run":Xy,cleanup:cy}});async function bb(e,t){let{report:n,resolveImage:r}=await xb(e),i=n.entries[t];if(!i)throw Error(`Kapture report does not contain snapshot ${t}`);let a=[],o=(e,t)=>{t&&(Eb(e,t),a.push({role:e,mediaType:`image/png`,source:r(t)}))};return o(`base`,i.baseImage),o(`head`,i.headImage),o(`diff`,i.diffImage),o(`base-repeat`,i.instability?.base?.repeatImage),o(`base-instability-diff`,i.instability?.base?.diffImage),o(`head-repeat`,i.instability?.head?.repeatImage),o(`head-instability-diff`,i.instability?.head?.diffImage),{version:1,report:{baseRevision:n.baseRevision,headRevision:n.headRevision,...n.contentDigest?{contentDigest:n.contentDigest}:{}},snapshot:{id:i.id,storyId:i.storyId,title:i.title,name:i.name,viewport:i.viewport,status:i.status,...i.changedPixels===void 0?{}:{changedPixels:i.changedPixels},...i.diffRatio===void 0?{}:{diffRatio:i.diffRatio},...i.threshold?{threshold:i.threshold}:{},...i.error?{error:i.error}:{}},images:a}}async function xb(e){let t=Tb(e);return t?Cb(t):Sb(e)}async function Sb(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${ug} bytes`);let r=wb(await x(t,`utf8`)),i=a(t);return{report:r,resolveImage:e=>{let t=f(i,e);if(d(i,t).startsWith(`..`))throw Error(`Kapture report contains an unsafe image path: ${e}`);return{type:`path`,value:t}}}}async function Cb(e){let t=await fetch(e,{redirect:`error`});if(!t.ok)throw Error(`Kapture report request failed with HTTP ${t.status}`);return{report:wb((await ff(t,ug,`Kapture report`)).toString(`utf8`)),resolveImage:t=>{let n=new URL(t,e);if(n.origin!==e.origin||n.protocol!==`https:`)throw Error(`Kapture report contains an unsafe image URL: ${t}`);return{type:`url`,value:n.toString()}}}}function wb(e){try{return og(JSON.parse(e))}catch(e){throw e instanceof SyntaxError?Error(`Kapture report does not contain valid JSON`):e}}function Tb(e){let t;try{t=new URL(e)}catch{return}if(t.protocol!==`https:`||t.username||t.password)throw Error(`Remote Kapture report must be an HTTPS URL without credentials`);return t}function Eb(e,t){let n=`images/${e}/`,r=t.slice(n.length);if(!t.startsWith(n)||!r||r.includes(`/`)||r.includes(`\\`)||!r.endsWith(`.png`))throw Error(`Kapture report contains an invalid ${e} image path: ${t}`)}var Db,Ob=E((()=>{A(),kg(),pf(),Db=k({meta:{name:`inspect`,description:`Print machine-readable snapshot evidence for agents and review tools`},args:{report:{type:`string`,required:!0,description:`Local report.json path or public HTTPS report.json URL`},snapshot:{type:`string`,required:!0,description:`Exact snapshot ID`}},async run({args:e}){let t=await bb(e.report,e.snapshot);process.stdout.write(`${JSON.stringify(t,null,2)}\n`)}})})),kb=E((()=>{zc()})),Ab=E((()=>{kb()})),jb=Se({createKaptureMcpServer:()=>Nb,getSnapshotEvidenceResult:()=>Pb,startKaptureMcpServer:()=>Mb});async function Mb(e){let{serveStdio:t}=await import(`@modelcontextprotocol/server/stdio`);t(()=>Nb(e),{onerror:e=>console.error(e.message)})}async function Nb(e){let{McpServer:t}=await import(`@modelcontextprotocol/server`),n=new t({name:`kapture`,version:Qe},{instructions:`Use list_snapshots to find visual changes, then get_snapshot_evidence to inspect the exact PNG evidence. Unstable snapshots are nondeterministic; accepting them requires an explicit GitHub exception approval with a reason, preserving the original evidence.`});return n.registerTool(`list_snapshots`,{title:`List Kapture snapshots`,description:`List snapshot IDs, statuses, stories, viewports, and diff metrics from a report.`,inputSchema:Os({status:Ns([`unchanged`,`changed`,`unstable`,`added`,`removed`,`error`]).optional().describe(`Optional exact status filter`)}),annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0}},async({status:t})=>{let{report:n}=await xb(e),r=Object.values(n.entries).filter(e=>!t||e.status===t).map(e=>({id:e.id,storyId:e.storyId,title:e.title,name:e.name,viewport:e.viewport,status:e.status,changedPixels:e.changedPixels,changedPixelPercentage:e.diffRatio===void 0?void 0:e.diffRatio*100})),i={baseRevision:n.baseRevision,headRevision:n.headRevision,summary:n.summary,snapshots:r};return{content:[{type:`text`,text:JSON.stringify(i,null,2)}],structuredContent:i}}),n.registerTool(`get_snapshot_evidence`,{title:`Get Kapture snapshot evidence`,description:`Return machine-readable metadata and the actual base, head, diff, and instability PNGs for one snapshot.`,inputSchema:Os({snapshotId:R().min(1).max(512).describe(`Exact ID returned by list_snapshots`)}),annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0}},async({snapshotId:t})=>Pb(e,t)),n}async function Pb(e,t){let n=await bb(e,t),r=await Promise.all(n.images.map(Fb));return{content:[{type:`text`,text:JSON.stringify(zb(n),null,2)},...r],structuredContent:zb(n)}}async function Fb(e){return{type:`image`,data:(e.source.type===`path`?await Ib(e.source.value):await Lb(e.source.value)).toString(`base64`),mimeType:`image/png`,_meta:{"kapture/role":e.role}}}async function Ib(e){let t=await v(e);if(t.isSymbolicLink()||!t.isFile()||t.size>Bb)throw Error(`Kapture evidence image must be no larger than ${Bb} bytes`);return Rb(await x(e),e)}async function Lb(e){let t=await fetch(e,{redirect:`error`});if(!t.ok)throw Error(`Kapture evidence request failed with HTTP ${t.status}`);return Rb(await ff(t,Bb,`Kapture evidence image`),e)}function Rb(e,t){if(e.byteLength>Bb||!e.subarray(0,8).equals(Vb))throw Error(`Kapture evidence is not a supported PNG: ${t}`);return e}function zb(e){return{...e,images:e.images.map(t=>({role:t.role,mediaType:t.mediaType,source:t.source,contentBlockIndex:e.images.indexOf(t)+1}))}}var Bb,Vb,Hb=E((()=>{Ab(),Ob(),pf(),Bb=26214400,Vb=Buffer.from([137,80,78,71,13,10,26,10])}));A();const Ub=k({meta:{name:`mcp`,description:`Serve Kapture snapshot evidence to agents over MCP stdio`},args:{report:{type:`string`,required:!0,description:`Local report.json path or public HTTPS report.json URL`}},async run({args:e}){let{startKaptureMcpServer:t}=await Promise.resolve().then(()=>(Hb(),jb));await t(e.report)}});Ld(),A();const Wb=k({meta:{name:`plan`,description:`Select affected Storybook stories from base/head dependency manifests`},args:{"base-dir":{type:`string`,required:!0,description:`Built base Storybook directory`},"head-dir":{type:`string`,required:!0,description:`Built head Storybook directory`},"changed-files":{type:`string`,required:!0,description:`Path to a versioned changed-files manifest or legacy JSON path array`},output:{type:`string`,default:`.kapture/plan.json`,description:`Affected-story plan output path`}},async run({args:e}){let t=await Gb(f(e[`changed-files`])),n=await Il({baseDir:f(e[`base-dir`]),headDir:f(e[`head-dir`]),changedFiles:t.files,changedFilesComplete:t.complete,...t.evidence?{changedFilesEvidence:t.evidence}:{}}),r=f(e.output);await y(a(r),{recursive:!0}),await w(r,`${JSON.stringify(n,null,2)}\n`,`utf8`),n.selectionMode===`affected`?Z.success(`Selected ${n.selectedStoryIds.length} of ${n.totalStoryIds.length} affected stories`):Z.warn(`Selected all ${n.totalStoryIds.length} stories (${n.fallbackReasons.map(e=>e.code).join(`, `)})`),Z.info(`Plan: ${r}`)}});async function Gb(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch(t){throw Error(`Failed to read changed files JSON from ${e}`,{cause:t})}if(!Array.isArray(t)){let e=x_(t);return{files:e.files,complete:e.complete,evidence:{provider:e.source.provider,manifestDigest:T(`sha256`).update(JSON.stringify(e)).digest(`hex`),pullRequestNumber:e.pullRequest.number,baseSha:e.pullRequest.baseSha,headSha:e.pullRequest.headSha}}}if(t.length>1e5)throw Error(`changed-files contains too many paths`);return{files:t.map(e=>S_(e,`changed file path`)),complete:!0}}A();const Kb=k({meta:{name:`report`,description:`Build trusted static Kapture reports`},subCommands:{build:Lg}});function qb(e){let t=`## Kapture initial adoption
668
+ `:l}};function ig(e){return e.replace(/`([^`]+)`/gm,(e,t)=>jp.cyan(t)).replace(/\s+_([^_]+)_\s+/gm,(e,t)=>` ${jp.underline(t)} `)}function ag(e=`white`){return jp[e]||jp.white}function og(e=`bgWhite`){return jp[`bg${e[0].toUpperCase()}${e.slice(1)}`]||jp.bgWhite}function sg(e={}){let t=cg();return process.env.CONSOLA_LEVEL&&(t=Number.parseInt(process.env.CONSOLA_LEVEL)??t),dp({level:t,defaults:{level:t},stdout:process.stdout,stderr:process.stderr,prompt:(...e)=>Promise.resolve().then(()=>(dh(),Rp)).then(t=>t.prompt(...e)),reporters:e.reporters||[e.fancy??!(xh||wh)?new rg:new hp],...e})}function cg(){return Ch?q.debug:wh?q.warn:q.info}const Q=sg();function lg(e){let t=Mg.safeParse(ug(e));if(!t.success){let e=t.error.issues[0],n=e?.path.length?` at ${e.path.join(`.`)}`:``;throw Error(`Invalid Kapture report${n}: ${e?.message??`unknown error`}`)}return t.data}function ug(e){if(!e||typeof e!=`object`||Array.isArray(e))return e;let t=e;return t.version!==2||!t.summary||typeof t.summary!=`object`?e:{...t,version:3,summary:{...t.summary,unstable:0}}}async function dg(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${pg} bytes`);let r;try{r=JSON.parse(await x(t,`utf8`))}catch{throw Error(`Kapture report does not contain valid JSON`)}return lg(r)}function fg(e){try{let t=new URL(e);return t.protocol===`https:`&&!t.username&&!t.password}catch{return!1}}var pg,mg,hg,$,gg,_g,vg,yg,bg,xg,Sg,Cg,wg,Tg,Eg,Dg,Og,kg,Ag,jg,Mg,Ng=E((()=>{Bd(),Uc(),pg=10485760,mg=2e4,hg=z().max(4096),$=z().min(1).max(512),gg=$.refine(e=>Array.from(e).every(e=>{let t=e.codePointAt(0)??0;return t>31&&t!==127}),`must not contain control characters`),_g=B().int().min(0).max(2**53-1),vg=B().int().positive().max(2**53-1),yg=B().min(0).max(1),bg=V({name:$,width:B().int().positive().max(16384),height:B().int().positive().max(16384)}),xg=V({pixelColorThreshold:yg,maxChangedPixelRatio:yg}),Sg=V({id:$,browser:$,browserVersion:$,orchestratorRuntime:$,operatingSystem:$,architecture:$,deviceScaleFactor:B().positive().max(8),locale:$,timezone:$,colorScheme:Is([`light`,`dark`]),reducedMotion:Is([`reduce`,`no-preference`]),frozenTime:$,randomSeed:B().int().min(0).max(2**53-1),fontsFingerprint:$,stateIsolation:H(`fresh-browser-process-per-story-side-v1`).optional(),network:V({mode:H(`allowlist`),allowedDomains:As($).max(100),webRtc:H(`disabled`)})}),Cg=V({id:$,storyId:$,title:hg,name:hg,viewport:bg,status:Is([`unchanged`,`changed`,`unstable`,`added`,`removed`,`error`]),baseImage:hg.optional(),headImage:hg.optional(),diffImage:hg.optional(),ignoredRegions:As(V({x:B().int().min(0).max(16384),y:B().int().min(0).max(32768),width:B().int().positive().max(16384),height:B().int().positive().max(32768)})).max(1e4).optional(),changedPixels:_g.optional(),diffRatio:yg.optional(),threshold:xg.optional(),instability:V({base:V({repeatImage:hg,diffImage:hg,changedPixels:_g,diffRatio:yg}).optional(),head:V({repeatImage:hg,diffImage:hg,changedPixels:_g,diffRatio:yg}).optional()}).optional(),error:hg.optional()}).superRefine((e,t)=>{e.status===`unstable`&&!e.instability?.base&&!e.instability?.head&&t.addIssue({code:`custom`,path:[`instability`],message:`unstable snapshots require base or head instability evidence`}),e.status!==`unstable`&&e.instability&&t.addIssue({code:`custom`,path:[`instability`],message:`only unstable snapshots can contain instability evidence`})}),wg=As($).max(mg).refine(e=>new Set(e).size===e.length,`must not contain duplicates`).refine(e=>e.every((t,n)=>n===0||e[n-1]<t),`must be sorted`),Tg=V({code:Is([`base-manifest-missing`,`base-manifest-invalid`,`head-manifest-missing`,`head-manifest-invalid`,`changed-files-incomplete`,`manifest-incomplete`,`global-input`,`global-output`,`global-runtime`,`unknown-input`,`story-import-missing`,`story-module-missing`,`fallback-reasons-truncated`]),path:hg.optional(),storyId:$.optional(),side:Is([`base`,`head`]).optional()}),Eg=V({provider:H(`github-pull-request-files`),manifestDigest:z().regex(/^[0-9a-f]{64}$/),pullRequestNumber:vg,baseSha:z().regex(/^[0-9a-f]{40}$/),headSha:z().regex(/^[0-9a-f]{40}$/)}),Dg=z().regex(/^[0-9a-f]{64}$/),Og=Ns(`state`,[V({state:H(`valid`),digest:Dg,revision:$}),V({state:H(`invalid`),digest:Dg.optional(),revision:$}),V({state:H(`missing`),revision:$})]),kg=V({base:Og,head:Og}),Ag=V({repository:$.regex(/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/),number:vg,url:hg.refine(fg,`must be an HTTPS URL without credentials`),baseBranch:gg,headBranch:gg,workflowRunUrl:hg.refine(fg,`must be an HTTPS URL without credentials`)}),jg=V({plannerVersion:H(1),mode:Is([`full`,`affected`,`full-fallback`]),changedFilesEvidence:Eg.optional(),dependencyManifests:kg.optional(),storyIds:wg,selectedStoryIds:wg,skippedStoryIds:wg,addedStoryIds:wg.optional(),removedStoryIds:wg.optional(),fallbackReasons:As(Tg).max(Pd),baseline:V({mode:H(`reused`),revision:$,manifestDigest:Dg}).optional()}).superRefine((e,t)=>{let n=new Set(e.storyIds),r=new Set(e.selectedStoryIds),i=new Set(e.skippedStoryIds);if((r.size+i.size!==n.size||[...r].some(e=>!n.has(e)||i.has(e))||[...i].some(e=>!n.has(e)))&&t.addIssue({code:`custom`,message:`selected and skipped stories must exactly partition the story catalog`}),e.mode!==`affected`&&i.size>0&&t.addIssue({code:`custom`,path:[`skippedStoryIds`],message:`full coverage modes cannot skip stories`}),e.mode===`full-fallback`&&e.fallbackReasons.length===0&&t.addIssue({code:`custom`,path:[`fallbackReasons`],message:`full-fallback coverage requires at least one reason`}),e.mode!==`full-fallback`&&e.fallbackReasons.length>0&&t.addIssue({code:`custom`,path:[`fallbackReasons`],message:`only full-fallback coverage can contain fallback reasons`}),e.addedStoryIds===void 0!=(e.removedStoryIds===void 0)&&t.addIssue({code:`custom`,message:`added and removed story catalogs must be provided together`}),e.addedStoryIds&&e.removedStoryIds){let i=new Set(e.addedStoryIds),a=new Set(e.removedStoryIds);([...i].some(e=>!n.has(e)||!r.has(e)||a.has(e))||[...a].some(e=>!n.has(e)||!r.has(e)))&&t.addIssue({code:`custom`,message:`added and removed stories must be disjoint selected catalog members`})}}),Mg=V({version:H(3),contentDigest:z().regex(/^[0-9a-f]{64}$/).optional(),baseRevision:$,headRevision:$,headBranch:gg.optional(),baseBranch:gg.optional(),pullRequest:Ag.optional(),storybookUrl:hg.refine(e=>e===`./storybook/`||fg(e),`must be an HTTPS URL or ./storybook/ without credentials`).optional(),environment:Sg,createdAt:$,threshold:xg,summary:V({total:_g,unchanged:_g,changed:_g,unstable:_g,added:_g,removed:_g,errors:_g}),coverage:jg.optional(),entries:Fs(z(),Cg)}).superRefine((e,t)=>{let n=Object.entries(e.entries);if(n.length>2e4){t.addIssue({code:`custom`,message:`Report contains more than ${mg} entries`,path:[`entries`]});return}for(let[e,r]of n)e!==r.id&&t.addIssue({code:`custom`,message:`Entry key must match entry.id`,path:[`entries`,e,`id`]});let r={unchanged:0,changed:0,unstable:0,added:0,removed:0,error:0};for(let t of Object.values(e.entries))r[t.status]+=1;if((e.summary.total!==n.length||e.summary.unchanged!==r.unchanged||e.summary.changed!==r.changed||e.summary.unstable!==r.unstable||e.summary.added!==r.added||e.summary.removed!==r.removed||e.summary.errors!==r.error)&&t.addIssue({code:`custom`,message:`Report summary does not match its entries`,path:[`summary`]}),e.coverage){let r=e.coverage.changedFilesEvidence;r&&(r.baseSha!==e.baseRevision||r.headSha!==e.headRevision)&&t.addIssue({code:`custom`,message:`Changed-files evidence must match the report base and head revisions`,path:[`coverage`,`changedFilesEvidence`]});let i=e.coverage.dependencyManifests;i&&(i.base.revision!==e.baseRevision||i.head.revision!==e.headRevision)&&t.addIssue({code:`custom`,message:`Dependency manifest evidence must match the report base and head revisions`,path:[`coverage`,`dependencyManifests`]});let a=new Set(e.coverage.selectedStoryIds),o=new Set(e.coverage.addedStoryIds??[]),s=new Set(e.coverage.removedStoryIds??[]);for(let[e,r]of n)a.has(r.storyId)||t.addIssue({code:`custom`,message:`Report entries must belong to selected stories`,path:[`entries`,e,`storyId`]}),o.has(r.storyId)&&r.status!==`added`&&r.status!==`error`&&t.addIssue({code:`custom`,message:`Entries for an added story must be added or error snapshots`,path:[`entries`,e,`status`]}),s.has(r.storyId)&&r.status!==`removed`&&r.status!==`error`&&t.addIssue({code:`custom`,message:`Entries for a removed story must be removed or error snapshots`,path:[`entries`,e,`status`]})}})}));Bd(),A();var Pg=Jt();Ng();const Fg=6e4,Ig=26214400,Lg=Buffer.from([137,80,78,71,13,10,26,10]),Rg=new Set([`acTL`,`fcTL`,`fdAT`]),zg=[`baseImage`,`headImage`,`diffImage`,`baseRepeatImage`,`baseInstabilityDiffImage`,`headRepeatImage`,`headInstabilityDiffImage`],Bg=[`base`,`head`,`diff`,`base-repeat`,`base-instability-diff`,`head-repeat`,`head-instability-diff`],Vg=k({meta:{name:`build`,description:`Rebuild a trusted static report from an untrusted Kapture artifact`},args:{input:{type:`string`,required:!0,description:`Untrusted artifact report directory containing report.json and images`},output:{type:`string`,required:!0,description:`New directory for the trusted static report`},"storybook-url":{type:`string`,description:`Trusted HTTPS Storybook URL or the fixed same-origin ./storybook/ directory`},"base-branch":{type:`string`,description:`Trusted base branch display label (not a comparison revision)`},"head-branch":{type:`string`,description:`Trusted head branch display label (not a comparison revision)`}},async run({args:e}){let t=await Hg({inputDir:e.input,outputDir:e.output,storybookUrl:e[`storybook-url`],trustedBaseBranch:e[`base-branch`],trustedHeadBranch:e[`head-branch`]});Q.success(`Trusted report: ${t.report.summary.total} snapshots, ${t.imageCount} verified PNGs (${t.imageBytes} bytes)`),Q.info(`Output: ${t.outputDir}`)}});async function Hg(e){let t=f(e.inputDir),n=f(e.outputDir),r=Ug(e.trustedHeadBranch),i=Ug(e.trustedBaseBranch);if(await t_(t),i_(t,n))throw Error(`Trusted report output must be outside the untrusted input directory`);await n_(n);let o=e.dashboardDir?f(e.dashboardDir):f(a(fe(import.meta.url)),`dashboard`),s=a(n);await y(s,{recursive:!0});let c=await ee(`${s}${p}.kapture-report-`),l;try{l=await Gg(t,async(e,t)=>{let n=f(c,e.relativePath);await y(a(n),{recursive:!0}),await w(n,t,{flag:`wx`})});let{report:s,imageDigests:u,calculatedContentDigest:d}=l;if(s.contentDigest&&s.contentDigest!==d)throw Error(`Report content digest does not match its referenced PNGs: expected ${s.contentDigest}, calculated ${d}`);r?s.headBranch=r:delete s.headBranch,i?s.baseBranch=i:delete s.baseBranch,e.trustedPullRequest?s.pullRequest={...e.trustedPullRequest}:delete s.pullRequest;let p=nf(e.storybookUrl);p?s.storybookUrl=p:delete s.storybookUrl,s.contentDigest=cl(s,u),await w(f(c,`report.json`),`${JSON.stringify(s)}\n`,{flag:`wx`}),await id(o,c),await ne(c,n)}catch(e){throw await re(c,{recursive:!0,force:!0}),e}if(!l)throw Error(`Trusted report validation did not complete`);return{report:l.report,outputDir:n,imageCount:l.references.length,imageBytes:l.imageBytes}}function Ug(e){if(e!==void 0){if(e.length<1||e.length>512||Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127}))throw Error(`Trusted head branch must contain between 1 and 512 non-control characters`);return e}}async function Wg(e,t){if(!/^[0-9a-f]{64}$/.test(t))throw Error(`Expected trusted report content digest must be a lowercase SHA-256 digest`);let n=f(e);if(n!==f(a(n),`report.json`))throw Error(`Trusted report path must end in report.json`);let r=a(n);await t_(r);let i=await Gg(r);if(i.report.contentDigest!==t||i.calculatedContentDigest!==t)throw Error(`Trusted report content digest does not match its actual structure and referenced PNGs`);return i.report}async function Gg(e,t){let n=Kg(await r_(e,`report.json`,pg)),r=qg(n);if(r.length>6e4)throw Error(`Report references more than ${Fg} PNG images`);let i=new Map,a=[],o=0;for(let n of r){let r=await r_(e,n.relativePath,Ig);if(o+=r.byteLength,o>536870912)throw Error(`Referenced PNGs exceed 536870912 total bytes`);i.set(n.relativePath,Qg(r,n.relativePath)),a.push({path:n.relativePath,sha256:T(`sha256`).update(r).digest(`hex`)}),await t?.(n,r)}return e_(n,i),{report:n,references:r,imageDigests:a,imageBytes:o,calculatedContentDigest:cl(n,a)}}function Kg(e){let t;try{t=JSON.parse(e.toString(`utf8`))}catch{throw Error(`Input report.json does not contain valid JSON`)}return lg(t)}function qg(e){let t=new Map;for(let n of Object.values(e.entries)){let e=Jg(n);for(let r of zg){let i=Xg(n,r);if(e.has(r)&&!i)throw Error(`Report entry ${n.id} is missing ${r} for status ${n.status}`);if(!e.has(r)&&i)throw Error(`Report entry ${n.id} cannot contain ${r} for status ${n.status}`);if(!i)continue;let a=Zg(i,Yg(r),n.id),o=t.get(a);if(o&&o.entryId!==n.id)throw Error(`Report entries ${o.entryId} and ${n.id} reference the same PNG: ${a}`);t.set(a,{relativePath:a,entryId:n.id})}}return[...t.values()]}function Jg(e){if(e.status===`changed`)return new Set([`baseImage`,`headImage`,`diffImage`]);if(e.status===`unstable`){if(!e.instability?.base&&!e.instability?.head)throw Error(`Report entry ${e.id} is unstable without instability evidence`);let t=[`baseImage`,`headImage`,`diffImage`];return e.instability.base&&t.push(`baseRepeatImage`,`baseInstabilityDiffImage`),e.instability.head&&t.push(`headRepeatImage`,`headInstabilityDiffImage`),new Set(t)}return e.status===`added`?new Set([`headImage`]):e.status===`removed`?new Set([`baseImage`]):new Set}function Yg(e){return e===`baseImage`?`base`:e===`headImage`?`head`:e===`diffImage`?`diff`:e===`baseRepeatImage`?`base-repeat`:e===`baseInstabilityDiffImage`?`base-instability-diff`:e===`headRepeatImage`?`head-repeat`:`head-instability-diff`}function Xg(e,t){return t===`baseImage`||t===`headImage`||t===`diffImage`?e[t]:t===`baseRepeatImage`?e.instability?.base?.repeatImage:t===`baseInstabilityDiffImage`?e.instability?.base?.diffImage:t===`headRepeatImage`?e.instability?.head?.repeatImage:e.instability?.head?.diffImage}function Zg(e,t,n){let r=`images/${t}/`,i=e.slice(r.length);if(!e.startsWith(r)||!i||i.includes(`/`)||i.includes(`\\`)||i.length>255||!/^[a-zA-Z0-9][a-zA-Z0-9._-]*\.png$/.test(i))throw Error(`Report entry ${n} has an invalid ${t} PNG path: ${e}`);return e}function Qg(e,t){if(e.byteLength<33||!e.subarray(0,8).equals(Lg))throw Error(`Referenced image is not a PNG: ${t}`);let n=e.readUInt32BE(8),r=e.toString(`ascii`,12,16);if(n!==13||r!==`IHDR`)throw Error(`Referenced PNG has an invalid IHDR chunk: ${t}`);let i=e.readUInt32BE(16),a=e.readUInt32BE(20);if(i<1||a<1||i>16384||a>32768||i*a>33554432)throw Error(`Referenced PNG dimensions are outside the supported limits: ${t} (${i}x${a})`);$g(e,t);try{let t=Pg.PNG.sync.read(e,{checkCRC:!0,skipRescale:!0});if(t.width!==i||t.height!==a)throw Error(`decoded dimensions differ from IHDR`)}catch{throw Error(`Referenced PNG cannot be decoded safely: ${t}`)}return{width:i,height:a}}function $g(e,t){let n=Lg.byteLength,r=!1;for(;n+12<=e.byteLength;){let i=e.readUInt32BE(n),a=e.toString(`ascii`,n+4,n+8),o=n+12+i;if(o>e.byteLength)throw Error(`Referenced PNG has an invalid chunk boundary: ${t}`);if(Rg.has(a))throw Error(`Animated PNG is not supported in a static report: ${t}`);if(n=o,a===`IEND`){r=!0;break}}if(!r||n!==e.byteLength)throw Error(`Referenced PNG has an invalid chunk structure: ${t}`)}function e_(e,t){for(let n of Object.values(e.entries)){if(n.status!==`changed`&&n.status!==`unstable`||!n.baseImage||!n.headImage||!n.diffImage)continue;let e=t.get(n.baseImage),r=t.get(n.headImage),i=t.get(n.diffImage);if(!e||!r||!i)throw Error(`Report entry ${n.id} is missing validated PNG dimensions`);let a=Math.max(e.width,r.width),o=Math.max(e.height,r.height);for(let e of n.ignoredRegions??[])if(e.x+e.width>a||e.y+e.height>o)throw Error(`Report entry ${n.id} ignored region exceeds its comparison canvas`);if(i.width!==a||i.height!==o)throw Error(`Report entry ${n.id} diff PNG must match the padded comparison canvas ${a}x${o}`);if(n.changedPixels!==void 0&&n.changedPixels>a*o)throw Error(`Report entry ${n.id} changedPixels exceeds its diff PNG pixel count`);for(let i of[n.instability?.base,n.instability?.head]){if(!i)continue;let a=t.get(i.repeatImage),o=t.get(i.diffImage);if(!a||!o)throw Error(`Report entry ${n.id} is missing instability PNG dimensions`);let s=i===n.instability?.base?e:r,c=Math.max(s.width,a.width),l=Math.max(s.height,a.height);if(o.width!==c||o.height!==l)throw Error(`Report entry ${n.id} instability diff PNG must match ${c}x${l}`);if(i.changedPixels>c*l)throw Error(`Report entry ${n.id} instability changedPixels exceeds its diff PNG pixel count`)}}}async function t_(e){let t;try{t=await v(e)}catch(t){throw a_(t)?Error(`Input report directory does not exist: ${e}`):t}if(t.isSymbolicLink()||!t.isDirectory())throw Error(`Input report path must be a real directory, not a symbolic link`)}async function n_(e){try{await v(e)}catch(e){if(a_(e))return;throw e}throw Error(`Trusted report output already exists: ${e}`)}async function r_(e,t,n){if(s(t)||t.includes(`\\`))throw Error(`Input file must be a normalized relative path: ${t}`);let r=t.split(`/`),i=e;for(let[e,n]of r.entries()){if(!n||n===`.`||n===`..`)throw Error(`Input file must be a normalized relative path: ${t}`);i=f(i,n);let a;try{a=await v(i)}catch(e){throw a_(e)?Error(`Referenced input file does not exist: ${t}`):e}if(a.isSymbolicLink())throw Error(`Referenced input path cannot contain a symbolic link: ${t}`);let o=e===r.length-1;if(!o&&!a.isDirectory()||o&&!a.isFile())throw Error(`Referenced input path is not a regular file: ${t}`)}let a=ue.O_RDONLY|(ue.O_NOFOLLOW??0),o=await b(i,a);try{let e=await o.stat();if(!e.isFile()||e.size>n)throw Error(`Input file exceeds ${n} bytes: ${t}`);let r=Buffer.alloc(e.size),i=0;for(;i<r.byteLength;){let{bytesRead:e}=await o.read(r,i,r.byteLength-i,i);if(e===0)throw Error(`Input file changed while being read: ${t}`);i+=e}let a=Buffer.alloc(1),{bytesRead:s}=await o.read(a,0,1,r.byteLength);if(s>0)throw Error(`Input file changed while being read: ${t}`);return r}finally{await o.close()}}function i_(e,t){let n=d(e,t);return n===``||!n.startsWith(`..${p}`)&&n!==`..`&&!s(n)}function a_(e){return typeof e==`object`&&!!e&&`code`in e&&e.code===`ENOENT`}function o_(e,t){return c_(e,t).map(({path:e,compressedBytes:t,uncompressedBytes:n})=>({path:e,compressedBytes:t,uncompressedBytes:n}))}async function s_(e,t,n){let r=c_(e,n),i=f(t);await y(i,{recursive:!0});for(let t of r){let n=e.subarray(t.dataOffset,t.dataOffset+t.compressedBytes),r=t.compression===0?Buffer.from(n):be(n,{maxOutputLength:t.uncompressedBytes+1});if(r.byteLength!==t.uncompressedBytes)throw Error(`ZIP entry size mismatch: ${t.path}`);if(ye(r)!==t.crc)throw Error(`ZIP entry checksum mismatch: ${t.path}`);let o=f(i,t.path);if(!o.startsWith(`${i}${p}`))throw Error(`ZIP entry escapes the output directory: ${t.path}`);await y(a(o),{recursive:!0}),await w(o,r,{flag:`wx`})}return r}function c_(e,t){p_(t);let n=l_(e),r=e.readUInt16LE(n+4),i=e.readUInt16LE(n+6),a=e.readUInt16LE(n+8),o=e.readUInt16LE(n+10),s=e.readUInt32LE(n+12),c=e.readUInt32LE(n+16),l=e.readUInt16LE(n+20);if(n+22+l!==e.byteLength)throw Error(`ZIP end record does not match the archive size`);if(r!==0||i!==0||a!==o)throw Error(`Multi-disk ZIP archives are not supported`);if(o===65535||s===4294967295||c===4294967295)throw Error(`ZIP64 archives are not supported`);if(o>t.maxEntries)throw Error(`ZIP archive contains more than ${t.maxEntries} entries`);if(c+s!==n)throw Error(`ZIP central directory is malformed`);let u=[],d=new Set,f=c,p=0;for(let r=0;r<o;r+=1){if(f+46>n||e.readUInt32LE(f)!==33639248)throw Error(`ZIP central directory entry is malformed`);let r=e.readUInt16LE(f+4),i=e.readUInt16LE(f+8),a=e.readUInt16LE(f+10),o=e.readUInt32LE(f+16),s=e.readUInt32LE(f+20),l=e.readUInt32LE(f+24),m=e.readUInt16LE(f+28),h=e.readUInt16LE(f+30),g=e.readUInt16LE(f+32),_=e.readUInt16LE(f+34),v=e.readUInt32LE(f+38),y=e.readUInt32LE(f+42),ee=f+46+m+h+g;if(ee>n)throw Error(`ZIP central directory entry exceeds its bounds`);if(i&1)throw Error(`Encrypted ZIP entries are not supported`);if(a!==0&&a!==8)throw Error(`ZIP compression method ${a} is not supported`);if(_!==0)throw Error(`Multi-disk ZIP entries are not supported`);if(s===4294967295||l===4294967295||y===4294967295)throw Error(`ZIP64 entries are not supported`);let b=e.subarray(f+46,f+46+m),x=d_(b);f=ee;let te=x.endsWith(`/`);if(f_(r,v,x,te),d.has(x))throw Error(`ZIP archive contains duplicate path: ${x}`);if(d.add(x),te){if(!t.allowDirectoryPath(x))throw Error(`ZIP archive contains unexpected directory: ${x}`);if(i&8||a!==0||o!==0||s!==0||l!==0)throw Error(`ZIP directory entry must be empty and stored: ${x}`);u_(e,y,b,i,a,o,s,l,c);continue}if(!t.allowPath(x))throw Error(`ZIP archive contains unexpected path: ${x}`);if(l>t.maxFileBytes)throw Error(`ZIP entry exceeds ${t.maxFileBytes} bytes: ${x}`);if(p+=l,p>t.maxTotalBytes)throw Error(`ZIP archive exceeds ${t.maxTotalBytes} uncompressed bytes`);let S=u_(e,y,b,i,a,o,s,l,c);u.push({path:x,compression:a,crc:o,compressedBytes:s,uncompressedBytes:l,dataOffset:S})}if(f!==n)throw Error(`ZIP central directory size is inconsistent`);return u}function l_(e){let t=Math.max(0,e.byteLength-65557);for(let n=e.byteLength-22;n>=t;--n)if(e.readUInt32LE(n)===101010256)return n;throw Error(`ZIP end-of-central-directory record is missing`)}function u_(e,t,n,r,i,a,o,s,c){if(t+30>c||e.readUInt32LE(t)!==67324752)throw Error(`ZIP local entry header is malformed`);let l=e.readUInt16LE(t+6),u=e.readUInt16LE(t+8),d=e.readUInt32LE(t+14),f=e.readUInt32LE(t+18),p=e.readUInt32LE(t+22),m=e.readUInt16LE(t+26),h=e.readUInt16LE(t+28),g=t+30+m+h;if(g>c)throw Error(`ZIP local entry header exceeds its bounds`);let _=e.subarray(t+30,t+30+m);if(l!==r||u!==i||!_.equals(n))throw Error(`ZIP local and central directory entries do not match`);if(!(l&8)&&(d!==a||f!==o||p!==s))throw Error(`ZIP local and central directory sizes or checksum do not match`);if(g+o>c)throw Error(`ZIP entry data exceeds the archive bounds`);return g}function d_(e){let t=e.toString(`utf8`);if(!Buffer.from(t,`utf8`).equals(e))throw Error(`ZIP path is not valid UTF-8`);let n=t.endsWith(`/`),r=t.split(`/`),i=n?r.slice(0,-1):r;if(t.length<1||t.startsWith(`/`)||t.includes(`\\`)||t.includes(`\0`)||i.some(e=>!e||e===`.`||e===`..`)||Array.from(t).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127}))throw Error(`ZIP path is unsafe: ${JSON.stringify(t)}`);return t}function f_(e,t,n,r){if(e>>>8!=3)return;let i=t>>>16&61440;if(i!==0&&i!==(r?16384:32768))throw Error(r?`ZIP entry is not a directory: ${n}`:`ZIP entry is not a regular file: ${n}`)}function p_(e){for(let[t,n]of Object.entries({maxEntries:e.maxEntries,maxFileBytes:e.maxFileBytes,maxTotalBytes:e.maxTotalBytes}))if(!Number.isSafeInteger(n)||n<=0)throw Error(`${t} must be positive`)}function m_(e,t){let n=S_(e,`GitHub pull_request event`),r=S_(n.pull_request,`pull_request`),i=__(S_(n.repository,`repository`)),a=S_(r.base,`pull_request.base`),o=S_(r.head,`pull_request.head`),s=__(S_(a.repo,`pull_request.base.repo`)),c=S_(o.repo,`pull_request.head.repo`),l=y_(a.ref,`pull_request.base.ref`),u=y_(o.ref,`pull_request.head.ref`),d=b_(r.number,`pull request number`);if(s!==i)throw Error(`Pull request base repository must match the workflow repository`);if(t!==void 0&&l!==y_(t,`base branch`))throw Error(`Pull request targets ${l}, expected ${t}`);return{schemaVersion:1,runId:b_(n.run_id??process.env.GITHUB_RUN_ID,`workflow run ID`),prNumber:d,base:{repository:s,ref:l,sha:v_(a.sha,`pull_request.base.sha`)},head:{repository:__(c),repositoryId:b_(c.id,`head repository ID`),ref:u,sha:v_(o.sha,`pull_request.head.sha`)},preview:{branch:u,alias:g_(d,u)}}}function h_(e){return`pr-${e.prNumber}-base-${e.base.sha}-head-${e.head.sha}`}function g_(e,t){let n=`pr-${b_(e,`pull request number`)}-`,r=y_(t,`head branch`),i=r.normalize(`NFKD`).toLowerCase().replace(/[^a-z0-9-]+/g,`-`).replace(/-+/g,`-`).replace(/^-|-$/g,``),a=`-${T(`sha256`).update(r).digest(`hex`).slice(0,10)}`,o=Math.max(1,63-n.length-a.length);return`${n}${(i||`branch`).slice(0,o).replace(/-$/g,``)||`b`}${a}`}function __(e){let t=x_(e.full_name,`repository full name`);if(!/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/.test(t))throw Error(`GitHub event contains an invalid repository full name`);return t}function v_(e,t){let n=x_(e,t).toLowerCase();if(!/^[0-9a-f]{40}$/.test(n))throw Error(`${t} must be a full SHA`);return n}function y_(e,t){let n=x_(e,t);if(n.length<1||n.length>512)throw Error(`${t} is invalid`);for(let e of n){let n=e.codePointAt(0)??0;if(n<=31||n===127)throw Error(`${t} is invalid`)}return n}function b_(e,t){let n=typeof e==`string`&&/^[1-9][0-9]*$/.test(e)?Number(e):e;if(typeof n!=`number`||!Number.isSafeInteger(n)||n<=0)throw Error(`${t} must be a positive integer`);return n}function x_(e,t){if(typeof e!=`string`)throw Error(`${t} must be a string`);return e}function S_(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}const C_=3e3;async function w_(e,t){let n=await e.getPullRequestForCapture(t.prNumber);D_(n,t);let r=R_(n.changed_files,`pull request changed_files`),i=[],a=[],o=0;if(r>3e3)i.push({code:`github-file-limit`});else for(let n=1;n<=Math.ceil(r/100);n+=1){let s=await e.listPullRequestFilesPage(t.prNumber,n,100);if(o=n,!Array.isArray(s)){i.push({code:`pagination-incomplete`,page:n});break}let c=s.slice(0,100);s.length>100&&i.push({code:`pagination-incomplete`,page:n});for(let[e,t]of c.entries())a.push({value:t,page:n,index:e});if(c.length<100){a.length<r&&i.push({code:`pagination-incomplete`,page:n});break}}a.length!==r&&i.push({code:`file-count-mismatch`});let s=new Set,c=new Set;for(let e of a)O_(e,s,c,i);let l=await e.getPullRequestForCapture(t.prNumber);if(D_(l,t),l.changed_files!==r)throw Error(`Pull request changed while Kapture discovered changed files`);let u=j_(i);return{kind:`kapture-changed-files`,version:1,complete:u.length===0,pullRequest:{number:t.prNumber,baseSha:t.base.sha,headSha:t.head.sha},files:[...s].sort(),source:{provider:`github-pull-request-files`,expectedFileCount:r,fetchedFileCount:a.length,pageCount:o,perPage:100,maxFiles:C_},diagnostics:u}}function T_(e){let t=z_(e,`changed-files manifest`);if(F_(t,[`kind`,`version`,`complete`,`pullRequest`,`files`,`source`,`diagnostics`],`changed-files manifest`),t.kind!==`kapture-changed-files`||t.version!==1)throw Error(`changed-files manifest must use kapture-changed-files version 1`);if(typeof t.complete!=`boolean`)throw Error(`changed-files manifest complete must be a boolean`);if(!Array.isArray(t.files)||t.files.length>6e3)throw Error(`changed-files manifest files must be a bounded array`);let n=t.files.map(e=>E_(e,`changed file path`));if(!M_(n))throw Error(`changed-files manifest files must be unique and sorted`);let r=z_(t.pullRequest,`changed-files manifest pullRequest`);F_(r,[`number`,`baseSha`,`headSha`],`changed-files manifest pullRequest`);let i=z_(t.source,`changed-files manifest source`);if(F_(i,[`provider`,`expectedFileCount`,`fetchedFileCount`,`pageCount`,`perPage`,`maxFiles`],`changed-files manifest source`),i.provider!==`github-pull-request-files`)throw Error(`changed-files manifest source provider is invalid`);if(i.perPage!==100||i.maxFiles!==3e3)throw Error(`changed-files manifest source limits are invalid`);if(!Array.isArray(t.diagnostics)||t.diagnostics.length>6e3)throw Error(`changed-files manifest diagnostics must be a bounded array`);let a=t.diagnostics.map(A_);if(!M_(a.map(N_)))throw Error(`changed-files manifest diagnostics must be unique and sorted`);if(t.complete!==(a.length===0))throw Error(`changed-files manifest completeness disagrees with diagnostics`);let o=R_(i.expectedFileCount,`changed-files expected file count`),s=R_(i.fetchedFileCount,`changed-files fetched file count`),c=R_(i.pageCount,`changed-files page count`);if(s>3e3||c>30||s>c*100||n.length>s*2)throw Error(`changed-files manifest source counts are inconsistent`);if(t.complete&&(o!==s||o>3e3||c!==Math.ceil(s/100)||n.length<s))throw Error(`complete changed-files manifest source counts are inconsistent`);return{kind:`kapture-changed-files`,version:1,complete:t.complete,pullRequest:{number:L_(r.number,`changed-files pull request number`),baseSha:I_(r.baseSha,`changed-files base SHA`),headSha:I_(r.headSha,`changed-files head SHA`)},files:n,source:{provider:`github-pull-request-files`,expectedFileCount:o,fetchedFileCount:s,pageCount:c,perPage:100,maxFiles:C_},diagnostics:a}}function E_(e,t=`GitHub file path`){if(typeof e!=`string`)throw Error(`${t} must be a string`);let n=Array.from(e);if(e.length===0||e.length>4096||e.startsWith(`/`)||/^[A-Za-z]:[\\/]/.test(e)||e.startsWith(`./`)||e===`.`||e===`..`||e.startsWith(`../`)||e.endsWith(`/`)||e.includes(`//`)||e.includes(`\\`)||e.split(`/`).some(e=>e===`.`||e===`..`)||n.some(e=>{let t=e.codePointAt(0)??0;return t<=31||t>=127&&t<=159}))throw Error(`${t} must be a normalized project-relative path`);return e}function D_(e,t){let n=e.head.repo;if(e.number!==t.prNumber||e.state!==`open`||e.base.ref!==t.base.ref||e.base.sha.toLowerCase()!==t.base.sha||e.base.repo.full_name!==t.base.repository||e.head.ref!==t.head.ref||e.head.sha.toLowerCase()!==t.head.sha||n?.id!==t.head.repositoryId||n.full_name!==t.head.repository)throw Error(`Live pull request does not match the exact Kapture capture context`)}function O_(e,t,n,r){if(!e.value||typeof e.value!=`object`||Array.isArray(e.value)){r.push({code:`invalid-file-record`,page:e.page,index:e.index});return}let i=e.value;if(typeof i.status!=`string`||typeof i.filename!=`string`){r.push({code:`invalid-file-record`,page:e.page,index:e.index});return}let a=JSON.stringify([i.status,i.filename,i.previous_filename]);if(n.has(a)&&r.push({code:`duplicate-file-entry`,page:e.page,index:e.index}),n.add(a),k_(i.filename,e,t,r),i.status===`renamed`||i.previous_filename!==void 0){if(typeof i.previous_filename!=`string`){r.push({code:`rename-source-missing`,page:e.page,index:e.index});return}k_(i.previous_filename,e,t,r)}}function k_(e,t,n,r){try{n.add(E_(e))}catch{r.push({code:`invalid-file-path`,page:t.page,index:t.index})}}function A_(e){let t=z_(e,`changed-files diagnostic`);if(F_(t,[`code`,`page`,`index`],`changed-files diagnostic`,!0),typeof t.code!=`string`||![`github-file-limit`,`pagination-incomplete`,`file-count-mismatch`,`invalid-file-record`,`invalid-file-path`,`rename-source-missing`,`duplicate-file-entry`].includes(t.code))throw Error(`changed-files diagnostic code is invalid`);let n=t.page===void 0?void 0:L_(t.page,`page`),r=t.index===void 0?void 0:R_(t.index,`diagnostic index`),i={code:t.code,...n===void 0?{}:{page:n},...r===void 0?{}:{index:r}};if(i.code===`github-file-limit`||i.code===`file-count-mismatch`?n!==void 0||r!==void 0:i.code===`pagination-incomplete`?n===void 0||n>30||r!==void 0:n===void 0||n>30||r===void 0||r>=100)throw Error(`changed-files diagnostic location is invalid`);return i}function j_(e){return[...new Map(e.map(e=>[JSON.stringify(e),e])).values()].sort((e,t)=>P_(N_(e),N_(t)))}function M_(e){return e.every((t,n)=>n===0||(e[n-1]??``)<t)}function N_(e){return`${e.code}:${String(e.page??0).padStart(2,`0`)}:${String(e.index??0).padStart(3,`0`)}`}function P_(e,t){return e<t?-1:+(e>t)}function F_(e,t,n,r=!1){let i=Object.keys(e).sort(),a=r?i.filter(e=>t.includes(e)).sort():[...t].sort();if(i.some(e=>!t.includes(e))||!r&&(i.length!==a.length||i.some((e,t)=>e!==a[t])))throw Error(`${n} contains unexpected or missing fields`)}function I_(e,t){if(typeof e!=`string`||!/^[0-9a-f]{40}$/.test(e))throw Error(`${t} must be a full lowercase SHA`);return e}function L_(e,t){let n=R_(e,t);if(n===0)throw Error(`${t} must be a positive integer`);return n}function R_(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<0)throw Error(`${t} must be a non-negative integer`);return e}function z_(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}Uc(),Ng();const B_=2e4,V_=26214400,H_=1073741824,U_=Fg+Bg.length+3,W_=/^[0-9a-f]{40}$/,G_=/^sha256:[0-9a-f]{64}$/,K_=/^[0-9a-f]{64}$/,q_=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,J_=/^\.github\/workflows\/[A-Za-z0-9_./-]+\.ya?ml$/,Y_=RegExp(`^images/(?:${Bg.join(`|`)})/[A-Za-z0-9][A-Za-z0-9._-]*\\.png$`),X_=z().min(1).max(512).refine(e=>!oy(e),`must not contain control characters`),Z_=z().regex(W_),Q_=B().int().positive().max(2**53-1),$_=z().regex(q_),ev=z().regex(G_),tv=V({schemaVersion:H(1),runId:Q_,prNumber:Q_,base:V({repository:$_,ref:X_,sha:Z_}),head:V({repository:$_,repositoryId:Q_,ref:X_,sha:Z_}),preview:V({branch:X_,alias:X_})}),nv=V({id:Q_,name:X_,sizeInBytes:Q_,digest:ev}),rv=V({id:Q_,name:X_,digest:ev}),iv=V({schemaVersion:H(1),artifacts:V({context:rv,baseStorybook:rv,headStorybook:rv})}),av=V({schemaVersion:H(2),repository:V({id:Q_,fullName:$_}),context:tv,captureRun:V({id:Q_,runNumber:Q_,attempt:Q_,workflowId:Q_,workflowPath:X_,headSha:Z_,headBranch:X_,headRepositoryId:Q_,headRepository:$_}),artifacts:V({context:nv,baseStorybook:nv,headStorybook:nv,report:nv}),report:V({contentDigest:z().regex(K_)}),trustedArtifactName:X_});async function ov(e,t){let n=Qv(t.captureWorkflowPath),r=ny(t.baseBranch,`base branch`),i=f(t.outputDir),a=f(t.receiptPath);if(ly(i,a))throw Error(`Trusted receipt must be outside the publicly deployed report directory`);await Zv(a,`Trusted receipt`);let o=uv(t.event,n),s=await e.getWorkflowRun(o.run.id);Pv(s,o),await fv(e,s);let c=pv(await e.listRunArtifacts(s.id),o),l=await Yv(t.temporaryRoot),u=!1;try{let d=await gv(e,c.context,33685504),p=f(l,`context`);xv(d),await s_(d,p,_v);let m=await Ev(f(p,`context.json`)),h=await Dv(f(p,`changed-files.json`),m);kv(m,c.context),Av(m,o,s,r),Mv(await e.getPullRequest(m.prNumber),m,o,r),await Nv(e,m,n);let g=await gv(e,c.report,629145600),_=f(l,`untrusted-report`);Sv(g),await s_(g,_,yv),Tv(await wv(f(_,`capture-boundary.json`)),c);let v=await dg(f(_,`report.json`));Ov(v,h),await Yf(e,qv(o,m),v);let y=await Hg({inputDir:_,outputDir:i,trustedHeadBranch:m.head.ref,trustedPullRequest:{repository:m.base.repository,number:m.prNumber,url:`https://github.com/${m.base.repository}/pull/${m.prNumber}`,baseBranch:m.base.ref,headBranch:m.head.ref,workflowRunUrl:`https://github.com/${m.base.repository}/actions/runs/${o.run.id}`},...t.storybookUrl?{storybookUrl:t.storybookUrl}:{},...t.dashboardDir?{dashboardDir:f(t.dashboardDir)}:{}});if(u=!0,!y.report.contentDigest)throw Error(`Trusted report build did not produce an image-bound content digest`);await Kv(e,o,s,m,r,n);let ee=Fv(o,s,m,c,y.report);return await Xv(a,ee),{receipt:ee,report:y.report,reportDirectory:i,reportPath:f(i,`report.json`),receiptPath:a,changedFiles:h}}catch(e){throw u&&await re(i,{recursive:!0,force:!0}),e}finally{await re(l,{recursive:!0,force:!0})}}async function sv(e,t,n){let r=await dv(n.receiptPath),i=uv(n.event,r.captureRun.workflowPath);Rv(r,i);let a=await e.getWorkflowRun(r.captureRun.id);zv(a,r),await fv(e,a),await Bv(e,r,i),Mv(await e.getPullRequest(r.context.prNumber),r.context,i,r.context.base.ref),await Nv(e,r.context,r.captureRun.workflowPath);let o=await Wg(n.reportPath,r.report.contentDigest);if(o.headBranch!==r.context.head.ref)throw Error(`Trusted report branch does not match its verified pull request context`);let s=qv(i,r.context);return await Yf(e,s,o),Xf(t,s,o,n.statusContext,n.reportUrl,n.commentLanguage)}async function cv(e,t){let n=Qv(t.captureWorkflowPath),r=ny(t.baseBranch,`base branch`),i=f(t.outputDir),o=f(t.receiptPath);await Zv(i,`Trusted Storybook output`);let s=await dv(o),c=uv(t.event,n);Rv(s,c);let l=await e.getWorkflowRun(s.captureRun.id);zv(l,s),await fv(e,l),await Bv(e,s,c),Mv(await e.getPullRequest(s.context.prNumber),s.context,c,r),await Nv(e,s.context,n);let u=f(t.temporaryRoot??a(i));if(ly(i,u))throw Error(`Trusted Storybook temporary root must be outside its output directory`);let d=await Yv(u),p=f(d,`storybook`);try{let t=await gv(e,s.artifacts.headStorybook,536870912);return Cv(t),await s_(t,p,bv),await Kv(e,c,l,s.context,r,n),await Bv(e,s,c),await Zv(i,`Trusted Storybook output`),await y(a(i),{recursive:!0}),await ne(p,i),{receipt:s,receiptPath:o,context:s.context,artifact:s.artifacts.headStorybook,storybookDirectory:i}}finally{await re(d,{recursive:!0,force:!0})}}async function lv(e,t){let n=await dv(t.receiptPath),r=uv(t.event,n.captureRun.workflowPath);Rv(n,r),zv(await e.getWorkflowRun(n.captureRun.id),n);let i=t.trustedArtifactId,a=t.trustedArtifactDigest?Wv(t.trustedArtifactDigest):void 0,o=[i,a];if(o.some(e=>e!==void 0)&&o.some(e=>e===void 0))throw Error(`trusted-artifact-id and trusted-artifact-digest must be provided together`);if(i!==void 0&&!ay(i))throw Error(`trusted-artifact-id must be a positive integer`);let s=i!==void 0&&a!==void 0?Gv():void 0,c=[];for(let t of Vv(n)){let n=await e.getArtifact(t.id);n&&(Hv(n,t,r),c.push({artifact:n,expected:t}))}if(i!==void 0&&a!==void 0&&s!==void 0){if(Vv(n).some(e=>e.id===i))throw Error(`trusted-artifact-id must not duplicate a source artifact ID`);let t=await e.getArtifact(i);t&&(Uv(t,a,s,n),c.push({artifact:t,expected:{id:t.id,name:t.name,sizeInBytes:t.sizeInBytes,digest:t.digest}}))}let l=[...new Set(c.map(({artifact:e})=>e.id))];for(let t of l)await e.deleteArtifact(t);return l}function uv(e,t){let n=sy(e,`GitHub workflow_run event`);if(n.action!==`completed`)throw Error(`Kapture trusted run requires a completed workflow_run event`);let r=sy(n.repository,`event repository`),i=$v(r.full_name,`event repository`),a=ey(i),o=iy(r.id,`event repository ID`),s=sy(n.workflow_run,`workflow_run`),c=Qv(ry(s.path,`workflow path`));if(c!==Qv(t))throw Error(`workflow_run path ${c} does not match ${t}`);if(s.status!==`completed`||s.conclusion!==`success`||s.event!==`pull_request`)throw Error(`Kapture trusted run requires one successful pull_request capture run`);let l=sy(s.head_repository,`workflow_run head repository`),u=cy(s.pull_requests,`workflow_run pull_requests`);if(u.length>1)throw Error(`workflow_run must contain at most one pull request`);let d=u[0]?Jv(u[0]):void 0;return{repository:{id:o,fullName:i,ref:a},run:{id:iy(s.id,`workflow run ID`),runNumber:iy(s.run_number,`workflow run number`),attempt:iy(s.run_attempt,`workflow run attempt`),workflowId:iy(s.workflow_id,`workflow ID`),workflowPath:c,status:`completed`,conclusion:`success`,event:`pull_request`,headSha:ty(s.head_sha,`workflow run head SHA`),headBranch:ny(s.head_branch,`workflow run head branch`),headRepository:{id:iy(l.id,`workflow run head repository ID`),fullName:$v(l.full_name,`workflow run head repository`)}},...d?{pullRequest:d}:{}}}async function dv(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size<1||n.size>65536)throw Error(`Trusted receipt must be a file no larger than 65536 bytes`);let r;try{r=JSON.parse(await x(t,`utf8`))}catch{throw Error(`Trusted receipt does not contain valid JSON`)}let i=av.safeParse(r);if(!i.success){let e=i.error.issues[0];throw Error(`Invalid trusted receipt${e?.path.length?` at ${e.path.join(`.`)}`:``}: ${e?.message??`unknown error`}`)}return Lv(i.data),i.data}async function fv(e,t){if(!await vt(e,t))throw Error(`A newer Kapture capture run owns this repository and branch`)}function pv(e,t){let n=/^kapture-context-pr-([1-9][0-9]*)-base-([0-9a-f]{40})-head-([0-9a-f]{40})$/,r=e.filter(e=>n.test(e.name)?hv(e,t):!1);if(r.length!==1||!r[0])throw Error(`Triggering run must contain exactly one immutable Kapture context artifact`);let i=r[0];if(i.sizeInBytes>33685504)throw Error(`Kapture context artifact exceeds its compressed size limit`);let a=i.name.match(n);if(!a?.[1]||!a[2]||!a[3])throw Error(`Kapture context artifact name is invalid`);let o=`kapture-visual-report-pr-${a[1]}-base-${a[2]}-head-${a[3]}`,s=e.filter(e=>e.name===o&&hv(e,t));if(s.length!==1||!s[0])throw Error(`Triggering run must contain exactly one matching Kapture report artifact`);if(s[0].sizeInBytes>629145600)throw Error(`Kapture report artifact exceeds its compressed size limit`);let c=`pr-${a[1]}-base-${a[2]}-head-${a[3]}`,l=mv(e,`kapture-storybook-base-${c}`,t),u=mv(e,`kapture-storybook-head-${c}`,t),d=[i,l,u,s[0]];if(new Set(d.map(e=>e.id)).size!==d.length||new Set(d.map(e=>e.name)).size!==d.length)throw Error(`Kapture artifact IDs and names must be distinct`);return{context:i,baseStorybook:l,headStorybook:u,report:s[0]}}function mv(e,t,n){let r=e.filter(e=>e.name===t&&hv(e,n));if(r.length!==1||!r[0])throw Error(`Triggering run must contain exactly one non-expired ${t} artifact`);if(r[0].sizeInBytes>536870912)throw Error(`${t} exceeds its compressed size limit`);return r[0]}function hv(e,t){return!e.expired&&e.workflowRun.id===t.run.id&&e.workflowRun.repositoryId===t.repository.id&&e.workflowRun.headRepositoryId===t.run.headRepository.id&&e.workflowRun.headBranch===t.run.headBranch&&e.workflowRun.headSha===t.run.headSha&&G_.test(e.digest)&&ay(e.id)&&ay(e.sizeInBytes)}async function gv(e,t,n){let r=await e.downloadArtifactArchive(t.id,n);if(r.byteLength!==t.sizeInBytes)throw Error(`Artifact ${t.id} download size does not match GitHub metadata`);if(`sha256:${T(`sha256`).update(r).digest(`hex`)}`!==t.digest)throw Error(`Artifact ${t.id} download digest does not match GitHub metadata`);return r}const _v={maxEntries:2,maxFileBytes:33554432,maxTotalBytes:33619968,allowPath:e=>e===`context.json`||e===`changed-files.json`,allowDirectoryPath:()=>!1},vv=new Set([`images/`,...Bg.map(e=>`images/${e}/`)]),yv={maxEntries:U_,maxFileBytes:Ig,maxTotalBytes:629145600,allowPath:e=>e===`report.json`||e===`capture-boundary.json`||Y_.test(e),allowDirectoryPath:e=>vv.has(e)},bv={maxEntries:B_,maxFileBytes:V_,maxTotalBytes:H_,allowPath:()=>!0,allowDirectoryPath:()=>!0};function xv(e){let t=o_(e,_v);if(t.length!==2)throw Error(`Context archive must contain exactly context.json and changed-files.json`);let n=t.find(e=>e.path===`context.json`),r=t.find(e=>e.path===`changed-files.json`);if(!n||n.uncompressedBytes<1||n.uncompressedBytes>65536||!r||r.uncompressedBytes<1||r.uncompressedBytes>33554432)throw Error(`Context archive entries are outside their fixed size contract`)}function Sv(e){let t=o_(e,yv),n=new Set,r=0,i=0;for(let e of t){let t=e.path.toLocaleLowerCase(`en-US`);if(n.has(t))throw Error(`Report archive contains a case-insensitive duplicate: ${e.path}`);if(n.add(t),e.uncompressedBytes<1)throw Error(`Report archive contains an empty file: ${e.path}`);if(e.path===`report.json`&&(r+=1,e.uncompressedBytes>10485760))throw Error(`report.json exceeds its uncompressed size limit`);if(e.path===`capture-boundary.json`&&(i+=1,e.uncompressedBytes>65536))throw Error(`capture-boundary.json exceeds its uncompressed size limit`)}if(r!==1)throw Error(`Report archive must contain one root report.json file`);if(i!==1)throw Error(`Report archive must contain one root capture-boundary.json file`)}function Cv(e){let t=o_(e,bv),n=new Set,r=0;for(let e of t){let t=e.path.toLocaleLowerCase(`en-US`);if(n.has(t))throw Error(`Storybook archive contains a case-insensitive duplicate: ${e.path}`);n.add(t),e.path===`index.html`&&e.uncompressedBytes>0&&(r+=1)}if(r!==1)throw Error(`Storybook archive must contain one non-empty root index.html file`)}async function wv(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch(e){throw Error(`capture-boundary.json must contain valid JSON`,{cause:e})}return iv.parse(t)}function Tv(e,t){for(let n of[`context`,`baseStorybook`,`headStorybook`]){let r=e.artifacts[n],i=t[n];if(i.id!==r.id||i.name!==r.name||i.digest!==r.digest)throw Error(`Capture ${n} artifact does not match its exact downloaded identity`)}}async function Ev(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch{throw Error(`Kapture context artifact does not contain valid JSON`)}let n=tv.safeParse(t);if(!n.success){let e=n.error.issues[0];throw Error(`Invalid Kapture capture context${e?.path.length?` at ${e.path.join(`.`)}`:``}: ${e?.message??`unknown error`}`)}if(n.data.preview.branch!==n.data.head.ref||n.data.preview.alias!==g_(n.data.prNumber,n.data.head.ref))throw Error(`Kapture context preview identity is not derived from its pull request branch`);return n.data}async function Dv(e,t){let n=await C(e);if(!n.isFile()||n.size<1||n.size>33554432)throw Error(`changed-files.json is outside its fixed size contract`);let r;try{r=JSON.parse(await x(e,`utf8`))}catch{throw Error(`changed-files.json does not contain valid JSON`)}let i=T_(r);if(i.pullRequest.number!==t.prNumber||i.pullRequest.baseSha!==t.base.sha||i.pullRequest.headSha!==t.head.sha)throw Error(`changed-files.json does not belong to the exact capture context`);return i}function Ov(e,t){let n=e.coverage;if(!n)throw Error(`Trusted workflow reports must include audited story coverage`);let r=n.changedFilesEvidence;if(!r)throw Error(`Trusted workflow report coverage must include changed-files evidence`);let i=T(`sha256`).update(JSON.stringify(t)).digest(`hex`);if(r.provider!==t.source.provider||r.manifestDigest!==i||r.pullRequestNumber!==t.pullRequest.number||r.baseSha!==t.pullRequest.baseSha||r.headSha!==t.pullRequest.headSha)throw Error(`Trusted workflow report changed-files evidence does not match its verified context manifest`)}function kv(e,t){let n=`kapture-context-${h_(e)}`;if(t.name!==n)throw Error(`Kapture context contents do not match the immutable artifact name`)}function Av(e,t,n,r){if(e.runId!==n.id||e.base.repository!==t.repository.fullName||e.base.ref!==r||e.head.repository!==n.headRepository.fullName||e.head.repositoryId!==n.headRepository.id||e.head.ref!==n.headBranch)throw Error(`Kapture capture context does not belong to the triggering workflow run`);jv(t,e)}function jv(e,t){let n=e.pullRequest;if(n&&(n.number!==t.prNumber||n.base.repositoryId!==e.repository.id||n.base.ref!==t.base.ref||n.base.sha!==t.base.sha||n.head.repositoryId!==t.head.repositoryId||n.head.ref!==t.head.ref||n.head.sha!==t.head.sha))throw Error(`workflow_run pull request metadata conflicts with the capture context`)}function Mv(e,t,n,r){if(e.number!==t.prNumber||e.state!==`open`||e.base.repository.id!==n.repository.id||e.base.repository.fullName!==t.base.repository||e.base.ref!==r||e.base.sha!==t.base.sha||e.head.repository.id!==t.head.repositoryId||e.head.repository.fullName!==t.head.repository||e.head.ref!==t.head.ref||e.head.sha!==t.head.sha)throw Error(`Kapture artifacts are stale or do not belong to the current open pull request`);jv(n,t)}async function Nv(e,t,n){let[r,i]=await Promise.all([e.getContentSha(t.base.repository,n,t.base.sha),e.getContentSha(t.head.repository,n,t.head.sha)]);if(!W_.test(r)||i!==r)throw Error(`Pull requests that modify the capture workflow require separate review before publishing`)}function Pv(e,t){if(e.id!==t.run.id||e.runNumber!==t.run.runNumber||e.runAttempt!==t.run.attempt||e.workflowId!==t.run.workflowId||e.path!==t.run.workflowPath||e.status!==`completed`||e.conclusion!==`success`||e.event!==`pull_request`||e.headSha!==t.run.headSha||e.headBranch!==t.run.headBranch||e.headRepository.id!==t.run.headRepository.id||e.headRepository.fullName!==t.run.headRepository.fullName||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Triggering capture run metadata changed or no longer matches the event`)}function Fv(e,t,n,r,i){if(!i.contentDigest)throw Error(`Trusted report is missing contentDigest`);if(i.headBranch!==n.head.ref)throw Error(`Trusted report branch does not match its verified pull request context`);let a=h_(n);return{schemaVersion:2,repository:{id:e.repository.id,fullName:e.repository.fullName},context:n,captureRun:{id:t.id,runNumber:t.runNumber,attempt:t.runAttempt,workflowId:t.workflowId,workflowPath:t.path,headSha:t.headSha,headBranch:t.headBranch,headRepositoryId:t.headRepository.id,headRepository:t.headRepository.fullName},artifacts:{context:Iv(r.context),baseStorybook:Iv(r.baseStorybook),headStorybook:Iv(r.headStorybook),report:Iv(r.report)},report:{contentDigest:i.contentDigest},trustedArtifactName:`kapture-trusted-report-${a}`}}function Iv(e){return{id:e.id,name:e.name,sizeInBytes:e.sizeInBytes,digest:e.digest}}function Lv(e){let t=h_(e.context);if(e.context.runId!==e.captureRun.id||e.context.base.repository!==e.repository.fullName||e.context.head.repository!==e.captureRun.headRepository||e.context.head.repositoryId!==e.captureRun.headRepositoryId||e.context.head.ref!==e.captureRun.headBranch||e.context.preview.branch!==e.context.head.ref||e.context.preview.alias!==g_(e.context.prNumber,e.context.head.ref)||e.artifacts.context.name!==`kapture-context-${t}`||e.artifacts.baseStorybook.name!==`kapture-storybook-base-${t}`||e.artifacts.headStorybook.name!==`kapture-storybook-head-${t}`||e.artifacts.report.name!==`kapture-visual-report-${t}`||e.trustedArtifactName!==`kapture-trusted-report-${t}`||new Set(Vv(e).map(e=>e.id)).size!==4||new Set(Vv(e).map(e=>e.name)).size!==4||e.artifacts.context.sizeInBytes>33685504||e.artifacts.baseStorybook.sizeInBytes>536870912||e.artifacts.headStorybook.sizeInBytes>536870912||e.artifacts.report.sizeInBytes>629145600||!J_.test(e.captureRun.workflowPath))throw Error(`Trusted receipt fields are not internally consistent`)}function Rv(e,t){if(Lv(e),e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName||e.captureRun.id!==t.run.id||e.captureRun.runNumber!==t.run.runNumber||e.captureRun.attempt!==t.run.attempt||e.captureRun.workflowId!==t.run.workflowId||e.captureRun.workflowPath!==t.run.workflowPath||e.captureRun.headSha!==t.run.headSha||e.captureRun.headBranch!==t.run.headBranch||e.captureRun.headRepositoryId!==t.run.headRepository.id||e.captureRun.headRepository!==t.run.headRepository.fullName)throw Error(`Trusted receipt does not belong to the triggering workflow_run event`);jv(t,e.context)}function zv(e,t){if(e.id!==t.captureRun.id||e.runNumber!==t.captureRun.runNumber||e.runAttempt!==t.captureRun.attempt||e.workflowId!==t.captureRun.workflowId||e.path!==t.captureRun.workflowPath||e.status!==`completed`||e.conclusion!==`success`||e.event!==`pull_request`||e.headSha!==t.captureRun.headSha||e.headBranch!==t.captureRun.headBranch||e.headRepository.id!==t.captureRun.headRepositoryId||e.headRepository.fullName!==t.captureRun.headRepository||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Capture run changed after prepare-run verification`)}async function Bv(e,t,n){let r=await e.listRunArtifacts(t.captureRun.id);for(let e of Vv(t)){let t=r.filter(t=>t.id===e.id);if(t.length!==1||!t[0])throw Error(`Receipt-bound artifact ${e.id} is no longer available`);Hv(t[0],e,n)}}function Vv(e){return[e.artifacts.context,e.artifacts.baseStorybook,e.artifacts.headStorybook,e.artifacts.report]}function Hv(e,t,n){if(e.id!==t.id||e.name!==t.name||e.sizeInBytes!==t.sizeInBytes||e.digest!==t.digest||!hv(e,n))throw Error(`Artifact ${t.id} no longer matches its trusted receipt binding`)}function Uv(e,t,n,r){if(e.expired||e.name!==r.trustedArtifactName||e.digest!==t||e.workflowRun.id!==n||e.workflowRun.repositoryId!==r.repository.id||e.workflowRun.headRepositoryId!==r.repository.id||e.sizeInBytes>629145600)throw Error(`Trusted report artifact does not match the exact cleanup binding`)}function Wv(e){let t=e.startsWith(`sha256:`)?e:`sha256:${e}`;if(!G_.test(t))throw Error(`trusted-artifact-digest must be a 64-character SHA-256 digest`);return t}function Gv(){let e=process.env.GITHUB_RUN_ID;if(!e||!/^[1-9][0-9]*$/.test(e))throw Error(`GITHUB_RUN_ID must identify the current trusted reporter workflow run`);let t=Number(e);if(!Number.isSafeInteger(t))throw Error(`GITHUB_RUN_ID must be a safe positive integer`);return t}async function Kv(e,t,n,r,i,a){let o=await e.getWorkflowRun(n.id);Pv(o,t),await fv(e,o),Mv(await e.getPullRequest(r.prNumber),r,t,i),await Nv(e,r,a)}function qv(e,t){return{repository:e.repository.ref,issueNumber:t.prNumber,headSha:t.head.sha,captureRunId:e.run.id,captureRunAttempt:e.run.attempt,captureWorkflowId:e.run.workflowId,captureRunHeadBranch:e.run.headBranch,captureRunHeadRepositoryId:e.run.headRepository.id}}function Jv(e){let t=sy(e,`workflow_run pull request`),n=sy(t.base,`workflow_run pull request base`),r=sy(t.head,`workflow_run pull request head`);return{number:iy(t.number,`workflow_run pull request number`),base:{repositoryId:iy(sy(n.repo,`workflow_run pull request base repository`).id,`workflow_run pull request base repository ID`),ref:ny(n.ref,`workflow_run pull request base ref`),sha:ty(n.sha,`workflow_run pull request base SHA`)},head:{repositoryId:iy(sy(r.repo,`workflow_run pull request head repository`).id,`workflow_run pull request head repository ID`),ref:ny(r.ref,`workflow_run pull request head ref`),sha:ty(r.sha,`workflow_run pull request head SHA`)}}}async function Yv(e){let t=f(e??process.env.RUNNER_TEMP??ce());return await y(t,{recursive:!0}),ee(`${t}${p}kapture-prepare-`)}async function Xv(e,t){let n=f(e),r=f(n,`..`);await y(r,{recursive:!0}),await w(n,`${JSON.stringify(t,null,2)}\n`,{flag:`wx`})}async function Zv(e,t){try{await C(e)}catch(e){if(e.code===`ENOENT`)return;throw e}throw Error(`${t} already exists: ${e}`)}function Qv(e){if(!J_.test(e)||e.includes(`//`)||e.includes(`..`))throw Error(`capture-workflow-path must be a safe .github/workflows YAML path`);return e}function $v(e,t){let n=ry(e,`${t} full name`);if(!q_.test(n))throw Error(`${t} full name is invalid`);return n}function ey(e){let[t,n,...r]=e.split(`/`);if(!t||!n||r.length>0)throw Error(`Repository full name is invalid`);return{owner:t,repo:n}}function ty(e,t){let n=ry(e,t);if(!W_.test(n))throw Error(`${t} must be a lowercase full SHA`);return n}function ny(e,t){let n=ry(e,t);if(oy(n))throw Error(`${t} contains control characters`);return n}function ry(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);return e}function iy(e,t){if(!ay(e))throw Error(`${t} must be a positive integer`);return e}function ay(e){return typeof e==`number`&&Number.isSafeInteger(e)&&e>0}function oy(e){return Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127})}function sy(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function cy(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}function ly(e,t){let n=d(e,t);return n===``||!s(n)&&n!==`..`&&!n.startsWith(`..${p}`)}function uy(e){let t=e.KAPTURE_ARTIFACT_SUFFIX;if(!t||!/^pr-[1-9][0-9]*-base-[0-9a-f]{40}-head-[0-9a-f]{40}$/.test(t))throw Error(`KAPTURE_ARTIFACT_SUFFIX must identify exact PR/base/head revisions`);let n=(n,r)=>{let i=e[`KAPTURE_${n}_ARTIFACT_ID`]??``,a=e[`KAPTURE_${n}_ARTIFACT_DIGEST`]??``;if(!/^[1-9][0-9]*$/.test(i)||!/^[0-9a-f]{64}$/.test(a))throw Error(`${n} requires an artifact ID and SHA-256 digest`);return{id:Number(i),name:`${r}-${t}`,digest:`sha256:${a}`}};return iv.parse({schemaVersion:1,artifacts:{context:n(`CONTEXT`,`kapture-context`),baseStorybook:n(`BASE`,`kapture-storybook-base`),headStorybook:n(`HEAD`,`kapture-storybook-head`)}})}A();const dy=k({meta:{name:`bind-artifacts`,description:`Record the exact downloaded artifact identities for trusted publication`},args:{output:{type:`string`,required:!0,description:`New capture-boundary.json path inside the raw report`}},async run({args:e}){let t=uy(process.env);await w(f(e.output),`${JSON.stringify(t)}\n`,{flag:`wx`,mode:384})}});A();const fy=k({meta:{name:`cleanup`,description:`Delete only exact receipt-bound Kapture artifact IDs`},args:{receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},"trusted-artifact-id":{type:`string`,description:`Exact current trusted report artifact ID`},"trusted-artifact-digest":{type:`string`,description:`upload-artifact SHA-256 digest for the current trusted report artifact`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If(),r=zf(n),i=e[`trusted-artifact-id`]?py(e[`trusted-artifact-id`],`trusted-artifact-id`):void 0,a=await lv(new _f(t,r),{event:n,receiptPath:f(e.receipt),...i===void 0?{}:{trustedArtifactId:i},...e[`trusted-artifact-digest`]?{trustedArtifactDigest:e[`trusted-artifact-digest`]}:{}});await K({"deleted-artifact-count":a.length,"deleted-artifact-ids":a.join(`,`)})}});function py(e,t){if(!/^[1-9][0-9]*$/.test(e))throw Error(`${t} must be a positive integer`);let n=Number(e);if(!Number.isSafeInteger(n))throw Error(`${t} must be a safe integer`);return n}A();const my=k({meta:{name:`context`,description:`Validate a pull request event and write immutable Kapture capture context`},args:{...lt,"allow-initial-adoption":{type:`boolean`,default:!1,description:`Explicitly allow head-only setup validation when the base has no adapter`},"adapter-package-json":{type:`string`,description:`Optional project-relative package.json to check for the adapter on the exact base revision`},output:{type:`string`,required:!0,description:`Path for the normalized context JSON`},"changed-files-output":{type:`string`,required:!0,description:`Path for the versioned changed-files manifest`},"base-branch":{type:`string`,description:`Expected pull request base branch`}},async run({args:e}){let t=m_(await If(),e[`base-branch`]),n=process.env.GITHUB_TOKEN;if(!n)throw Error(`GITHUB_TOKEN is required`);let[r,i]=t.base.repository.split(`/`);if(!r||!i)throw Error(`Capture context repository is invalid`);let o=new Nf(n,{owner:r,repo:i}),s=e[`allow-initial-adoption`]||e[`allow-adapter-upgrade`];if(s&&!e[`adapter-package-json`])throw Error(`Non-comparison modes require adapter-package-json`);if(s&&t.base.repository!==t.head.repository)throw Error(`Fork non-comparison modes are not supported`);let c=await w_(o,t),l=e[`adapter-package-json`]?ut(await o.readPackageManifest(e[`adapter-package-json`],t.base.sha),s?{allowInitialAdoption:e[`allow-initial-adoption`],allowAdapterUpgrade:e[`allow-adapter-upgrade`],headManifest:await o.readPackageManifest(e[`adapter-package-json`],t.head.sha),adapterVersion:Qe}:void 0):`compare`;l===`adapter-upgrade`&&process.env.GITHUB_STEP_SUMMARY&&await h(process.env.GITHUB_STEP_SUMMARY,`## Kapture: comparison skipped
669
+
670
+ The adapter is being upgraded. No visual comparison or approval was performed; all visual changes in this PR require manual review. Compare again after both revisions use the same version.
671
+ `);let u=f(e.output),d=f(e[`changed-files-output`]);if(u===d)throw Error(`output and changed-files-output must be different paths`);await Promise.all([y(a(u),{recursive:!0}),y(a(d),{recursive:!0})]),await Promise.all([w(u,`${JSON.stringify(t,null,2)}\n`,{flag:`wx`}),w(d,`${JSON.stringify(c,null,2)}\n`,{flag:`wx`})]),await K({"integration-mode":l,"artifact-suffix":h_(t),"base-repository":t.base.repository,"base-ref":t.base.ref,"base-sha":t.base.sha,"changed-files-complete":String(c.complete),"changed-files-count":c.files.length,"changed-files-path":d,"context-path":u,"head-repository":t.head.repository,"head-repository-id":t.head.repositoryId,"head-ref":t.head.ref,"head-sha":t.head.sha,"pr-number":t.prNumber,"preview-branch":t.preview.branch,"preview-alias":t.preview.alias})}}),hy=/^[0-9a-f]{40}$/,gy=/^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/,_y=/^\.github\/workflows\/[A-Za-z0-9_./-]+\.ya?ml$/,vy=`Base branch changed; rerun visual capture`,yy=new Set([`action_required`,`cancelled`,`failure`,`neutral`,`skipped`,`stale`,`startup_failure`,`success`,`timed_out`]);async function by(e,t,n){let r=zy(n.captureWorkflowPath),i=Uy(n.baseBranch,`base branch`),a=rf(n.statusContext),o=Cy(n.event,r),s=await wy(e,o,i);if(!s.ok)return Iy(s.reason);if(await Oy(t,o,s.target))return Iy(`final-report-exists`,s.target);let c=await wy(e,o,i);if(!c.ok)return Iy(c.reason,s.target);if(!Fy(s.target,c.target))return Iy(`pull-request-changed`,c.target);if(await Oy(t,o,c.target))return Iy(`final-report-exists`,c.target);let l=Ny(o,c.target);return await t.setReviewStatus(c.target.headSha,l.state,l.description,a),{status:l.state,reason:`status-written`,prNumber:c.target.prNumber,headSha:c.target.headSha}}async function xy(e,t,n){let r=zy(n.captureWorkflowPath),i=Uy(n.baseBranch,`base branch`),a=rf(n.statusContext),o=Sy(n.event,r),s=await wy(e,o,i);if(!s.ok)return Ly(s.reason);let c=Ay(o,await ky(t,o,s.target,a),s.target);if(c)return Ly(c,s.target);let l=await wy(e,o,i);if(!l.ok)return Ly(l.reason,s.target);if(!Fy(s.target,l.target))return Ly(`pull-request-changed`,l.target);let u=Ay(o,await ky(t,o,l.target,a),l.target);if(u)return Ly(u,l.target);let d=l.target.baseDrift?vy:o.run.conclusion===`success`?`Visual report publication did not complete`:`Visual capture did not succeed (${o.run.conclusion})`;return await t.setReviewStatus(l.target.headSha,`error`,d,a),{status:`error`,reason:`status-written`,prNumber:l.target.prNumber,headSha:l.target.headSha}}function Sy(e,t){let n=Cy(e,t);if(n.run.status!==`completed`)throw Error(`Kapture finalize-run requires a completed workflow_run event`);return{...n,run:{...n.run,status:`completed`}}}function Cy(e,t){let n=Jy(e,`GitHub workflow_run event`),r=Gy(n.action,`workflow_run action`);if(r!==`in_progress`&&r!==`completed`)throw Error(`Kapture reconcile-run requires an in_progress or completed workflow_run event`);let i=Jy(n.repository,`event repository`),a=By(i.full_name,`event repository`),o=Ky(i.id,`event repository ID`),s=Jy(n.workflow_run,`workflow_run`),c=zy(Gy(s.path,`workflow path`));if(c!==zy(t))throw Error(`workflow_run path ${c} does not match ${t}`);if(s.event!==`pull_request`)throw Error(`Kapture reconcile-run requires a pull_request capture run`);let l=Gy(s.status,`workflow run status`),u=Wy(s.conclusion,`workflow run conclusion`);if(r===`in_progress`&&(l!==`in_progress`||u!==null))throw Error(`An in_progress workflow_run event must describe an unfinished run`);if(r===`completed`&&(l!==`completed`||u===null||!yy.has(u)))throw Error(`A completed workflow_run event must have a supported conclusion`);let d=Jy(s.head_repository,`workflow_run head repository`),f={id:Ky(d.id,`workflow run head repository ID`),fullName:By(d.full_name,`workflow run head repository`)},p=Uy(s.head_branch,`workflow run head branch`),m=Yy(s.pull_requests,`workflow_run pull requests`);if(m.length>1)throw Error(`workflow_run must contain at most one pull request`);let h=m[0]?Ry(m[0]):void 0;if(h&&(h.base.repositoryId!==o||h.head.repositoryId!==f.id||h.head.ref!==p))throw Error(`workflow_run pull request metadata conflicts with run provenance`);return{repository:{id:o,fullName:a,ref:Vy(a)},run:{id:Ky(s.id,`workflow run ID`),runNumber:Ky(s.run_number,`workflow run number`),attempt:Ky(s.run_attempt,`workflow run attempt`),workflowId:Ky(s.workflow_id,`workflow ID`),workflowPath:c,status:l,conclusion:u,event:`pull_request`,headSha:Hy(s.head_sha,`workflow run head SHA`),headBranch:p,headRepository:f},...h?{pullRequest:h}:{}}}async function wy(e,t,n){let r=await e.getWorkflowRun(t.run.id);return Ty(r,t),r.runAttempt===t.run.attempt?r.status!==t.run.status||r.conclusion!==t.run.conclusion?{ok:!1,reason:`stale-run-state`}:await vt(e,r)?Ey(e,t,n):{ok:!1,reason:`superseded-run`}:{ok:!1,reason:`stale-run-attempt`}}function Ty(e,t){if(e.id!==t.run.id||e.runNumber!==t.run.runNumber||e.workflowId!==t.run.workflowId||zy(e.path)!==t.run.workflowPath||e.event!==`pull_request`||e.headSha!==t.run.headSha||e.headBranch!==t.run.headBranch||e.headRepository.id!==t.run.headRepository.id||e.headRepository.fullName!==t.run.headRepository.fullName||e.repository.id!==t.repository.id||e.repository.fullName!==t.repository.fullName)throw Error(`Triggering capture run identity no longer matches the workflow_run event`)}async function Ey(e,t,n){if(t.pullRequest){if(t.pullRequest.base.ref!==n)return{ok:!1,reason:`base-branch-mismatch`};let r=await e.getPullRequest(t.pullRequest.number);return Dy(r,t,n)?{ok:!0,target:Py(r,r.base.sha!==t.pullRequest.base.sha)}:{ok:!1,reason:`pull-request-not-current`}}let r=(await e.listOpenPullRequestsForHead(t.run.headRepository.fullName,t.run.headBranch,n)).filter(e=>e.state===`open`&&e.base.repository.id===t.repository.id&&e.base.repository.fullName===t.repository.fullName&&e.base.ref===n&&e.head.repository.id===t.run.headRepository.id&&e.head.repository.fullName===t.run.headRepository.fullName&&e.head.ref===t.run.headBranch);return r.length===0?{ok:!1,reason:`pull-request-not-found`}:r.length===1?{ok:!0,target:Py(r[0])}:{ok:!1,reason:`pull-request-ambiguous`}}function Dy(e,t,n){let r=t.pullRequest;return!!(r&&e.number===r.number&&e.state===`open`&&e.base.repository.id===t.repository.id&&e.base.repository.fullName===t.repository.fullName&&e.base.ref===n&&e.head.repository.id===t.run.headRepository.id&&e.head.repository.fullName===t.run.headRepository.fullName&&e.head.ref===t.run.headBranch&&e.head.sha===r.head.sha)}async function Oy(e,t,n){return My(await e.findCurrentReportMarker(n.prNumber,n.baseSha,n.headSha),t)}async function ky(e,t,n,r){let i=await e.findCurrentReportMarker(n.prNumber,n.baseSha,n.headSha),a=await e.getLatestReviewStatus(n.headSha,r);return{marker:My(i,t)?i:null,status:a}}function Ay(e,t,n){return n.baseDrift&&t.status?.state===`error`&&t.status.description===vy?`base-drift-already-recorded`:e.run.conclusion===`success`?jy(t)?`final-report-exists`:t.status?.state===`error`&&t.status.description===`Visual report publication did not complete`?`publication-failure-already-recorded`:void 0:t.status?.state===`error`?`capture-failure-already-recorded`:void 0}function jy(e){let{marker:t,status:n}=e;return!t?.reportUrl||!n||t.reportUrl!==n.targetUrl?!1:t.status===`clean`?n.state===`success`&&n.description===`No visual changes`:t.status===`changed`?n.state===`pending`&&n.description===Gf.standard.description||qf(n,`standard`):t.status===`unstable`&&n.state===`success`?qf(n,`allow-unstable`):n.state===`failure`}function My(e,t){return!!(e&&e.captureRunId===t.run.id&&e.captureRunAttempt===t.run.attempt&&e.captureWorkflowId===t.run.workflowId&&e.captureRunHeadBranch===t.run.headBranch&&e.captureRunHeadRepositoryId===t.run.headRepository.id)}function Ny(e,t){return t.baseDrift?{state:`error`,description:vy}:e.run.status===`in_progress`?{state:`pending`,description:`Visual capture is in progress`}:e.run.conclusion===`success`?{state:`pending`,description:`Visual report is awaiting publication`}:{state:`error`,description:`Visual capture did not succeed (${e.run.conclusion})`}}function Py(e,t=!1){return{prNumber:e.number,baseSha:e.base.sha,headSha:e.head.sha,baseDrift:t}}function Fy(e,t){return e.prNumber===t.prNumber&&e.baseSha===t.baseSha&&e.headSha===t.headSha&&e.baseDrift===t.baseDrift}function Iy(e,t){return{status:`noop`,reason:e,...t?{prNumber:t.prNumber,headSha:t.headSha}:{}}}function Ly(e,t){return{status:`noop`,reason:e,...t?{prNumber:t.prNumber,headSha:t.headSha}:{}}}function Ry(e){let t=Jy(e,`workflow_run pull request`),n=Jy(t.base,`workflow_run pull request base`),r=Jy(t.head,`workflow_run pull request head`);return{number:Ky(t.number,`workflow_run pull request number`),base:{repositoryId:Ky(Jy(n.repo,`workflow_run pull request base repository`).id,`workflow_run pull request base repository ID`),ref:Uy(n.ref,`workflow_run pull request base ref`),sha:Hy(n.sha,`workflow_run pull request base SHA`)},head:{repositoryId:Ky(Jy(r.repo,`workflow_run pull request head repository`).id,`workflow_run pull request head repository ID`),ref:Uy(r.ref,`workflow_run pull request head ref`),sha:Hy(r.sha,`workflow_run pull request head SHA`)}}}function zy(e){if(!_y.test(e)||e.includes(`//`)||e.includes(`..`))throw Error(`capture-workflow-path must be a safe .github/workflows YAML path`);return e}function By(e,t){let n=Gy(e,`${t} full name`);if(!gy.test(n))throw Error(`${t} full name is invalid`);return n}function Vy(e){let[t,n,...r]=e.split(`/`);if(!t||!n||r.length>0)throw Error(`Repository full name is invalid`);return{owner:t,repo:n}}function Hy(e,t){let n=Gy(e,t);if(!hy.test(n))throw Error(`${t} must be a lowercase full SHA`);return n}function Uy(e,t){let n=Gy(e,t);if(qy(n))throw Error(`${t} contains control characters`);return n}function Wy(e,t){return e===null?null:Gy(e,t)}function Gy(e,t){if(typeof e!=`string`||e.length<1||e.length>512)throw Error(`${t} must be a non-empty bounded string`);if(qy(e))throw Error(`${t} contains control characters`);return e}function Ky(e,t){if(typeof e!=`number`||!Number.isSafeInteger(e)||e<=0)throw Error(`${t} must be a positive integer`);return e}function qy(e){return Array.from(e).some(e=>{let t=e.codePointAt(0)??0;return t<=31||t===127})}function Jy(e,t){if(!e||typeof e!=`object`||Array.isArray(e))throw Error(`${t} must be an object`);return e}function Yy(e,t){if(!Array.isArray(e))throw Error(`${t} must be an array`);return e}async function Xy(e,t,n){if(!t[`allow-adapter-upgrade`])return null;let r=t[`adapter-package-json`];if(!r)throw Error(`allow-adapter-upgrade requires adapter-package-json`);let i=Cy(e,t[`capture-workflow-path`]);if(i.run.headRepository.id!==i.repository.id||i.run.headRepository.fullName!==i.repository.fullName)throw Error(`Fork adapter upgrades are not supported`);let a=rf(t[`status-context`]),o=process.env.GITHUB_TOKEN;if(!n&&!o)throw Error(`GITHUB_TOKEN is required`);let s=n?.review??new Nf(o,i.repository.ref),c=n?.runs??new _f(o,i.repository.ref),l=n?.readPackageManifest??((e,t)=>new Nf(o,i.repository.ref).readPackageManifest(e,t)),u=await wy(c,i,t[`base-branch`]);if(!u.ok)return{status:`noop`,reason:u.reason};if(u.target.baseDrift)return null;let[d,f]=await Promise.all([l(r,u.target.baseSha),l(r,u.target.headSha)]);if(!ft(d,f))return null;let p=await wy(c,i,t[`base-branch`]);if(!p.ok)return{status:`noop`,reason:p.reason};if(p.target.baseDrift||p.target.baseSha!==u.target.baseSha||p.target.headSha!==u.target.headSha||p.target.prNumber!==u.target.prNumber)return{status:`noop`,reason:`pull-request-changed`};let m=i.run.status===`in_progress`,h=i.run.conclusion===`success`,g=m?`pending`:h?`success`:`error`;return await s.setReviewStatus(p.target.headSha,g,m?`Adapter upgrade checks are in progress`:h?`Comparison skipped: adapter upgrade`:`Adapter upgrade checks did not succeed (${i.run.conclusion})`,a),{status:g,reason:`adapter-upgrade-not-compared`}}const Zy={"allow-initial-adoption":{type:`boolean`,default:!1},"adapter-package-json":{type:`string`}};async function Qy(e,t,n){if(!t[`allow-initial-adoption`])return!1;let r=t[`adapter-package-json`];if(!r)throw Error(`allow-initial-adoption requires adapter-package-json`);let i=process.env.GITHUB_TOKEN;if(!n&&!i)throw Error(`GITHUB_TOKEN is required`);let a=Cy(e,t[`capture-workflow-path`]);if(a.run.headRepository.fullName!==a.repository.fullName)throw Error(`Fork initial adoption is not supported`);let o=await wy(n?.runs??new _f(i,a.repository.ref),a,t[`base-branch`]);if(!o.ok||o.target.baseDrift)return!1;let s=n?.readPackageManifest??((e,t)=>new Nf(i,a.repository.ref).readPackageManifest(e,t));return ut(await s(r,o.target.baseSha),{allowInitialAdoption:!0,adapterVersion:Qe,headManifest:await s(r,o.target.headSha)})===`initial-adoption`}A();const $y=k({meta:{name:`finalize-run`,description:`Close an unfinished status for the exact completed trusted workflow run`},args:{...Zy,...lt,"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If();Sy(n,e[`capture-workflow-path`]);let r=await Xy(n,e);if(r){await K({status:r.status,"finalize-reason":r.reason,...r.status===`noop`?{}:{"integration-mode":`adapter-upgrade`,comparison:`not-performed`}});return}if(await Qy(n,e)){await K({status:`noop`,"finalize-reason":`initial-adoption-not-compared`});return}let i=zf(n),a=await xy(new _f(t,i),new Nf(t,i),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],statusContext:rf(e[`status-context`])});await K({status:a.status,"finalize-reason":a.reason,...a.prNumber===void 0?{}:{"pr-number":a.prNumber},...a.headSha?{"head-sha":a.headSha}:{}})}}),eb={files:B_,fileBytes:V_,totalBytes:H_};function tb(e,t){if(!t||s(t)||!/^[A-Za-z0-9._/-]+$/.test(t)||t.split(`/`).some(e=>!e||e===`.`||e===`..`))throw Error(`Storybook directory must be a project-relative path without dot segments`);return f(e,t)}async function nb(e,t,n=eb){let r=tb(e,t),i=await S(e),a=f(e);for(let e of t.split(`/`)){a=c(a,e);let t=await v(a);if(t.isSymbolicLink()||!t.isDirectory())throw Error(`Storybook path must contain only non-symlink directories`)}let o=await S(r),l=d(i,o);if(l===`..`||l.startsWith(`..${p}`)||s(l))throw Error(`Storybook directory escapes the project root`);let u=(await v(r)).dev,m=[r],h=0,g=0,_=0;for(;m.length;){let e=m.pop();if(!e)break;for(let t of await te(e)){if(_++,_>n.files)throw Error(`Storybook exceeds its entry count boundary`);let r=c(e,t),i=await v(r);if(i.isSymbolicLink()||i.dev!==u)throw Error(`Storybook must not contain symbolic links or cross-device entries`);if(i.isDirectory()){m.push(r);continue}if(!i.isFile())throw Error(`Storybook must contain only regular files and directories`);if(h++,g+=i.size,h>n.files||i.size>n.fileBytes||g>n.totalBytes)throw Error(`Storybook exceeds its file or size boundary`)}}for(let e of[`index.html`,`iframe.html`,`index.json`])if(!(await v(c(r,e))).isFile())throw Error(`Storybook is missing a regular ${e}`);return{directory:r,files:h,bytes:g}}const rb=`<!-- kapture-preview -->`;function ib(e,t,n,r){if(e.base.repository!==e.head.repository||t.id!==e.runId||t.runAttempt!==n||t.path!==r||t.event!==`pull_request`||t.headBranch!==e.head.ref||t.headRepository.id!==e.head.repositoryId||t.headRepository.fullName!==e.head.repository||t.repository.fullName!==e.base.repository)throw Error(`Preview requires the exact same-repository pull request workflow run`)}function ab(e,t){if(t.baseRevision!==e.base.sha||t.headRevision!==e.head.sha)throw Error(`Preview report must match the exact event base/head revisions`)}function ob(e,t,n){let{summary:r}=e,i=tf(t);if(!i)throw Error(`Preview report URL is required`);let a=Object.values(e.entries).filter(e=>e.status===`changed`).sort((e,t)=>e.id.localeCompare(t.id)),o=a.slice(0,10).map(e=>{let t=new URL(i);return t.hash=encodeURIComponent(e.id),`- [${cf(`${e.title} / ${e.name} · ${e.viewport.name}`)}](${tf(t.toString())})`});return a.length>10&&o.push(`- [View ${a.length-10} more changed snapshots](${i})`),[rb,`## Kapture preview`,``,`[Pixel comparison dashboard](${i})`,``,`Base: ${cf(n.base.ref)} → Head: ${cf(n.head.ref)}`,``,`Snapshots: ${r.total} · Changed: ${r.changed} · Unchanged: ${r.unchanged} · Unstable: ${r.unstable} · Added: ${r.added} · Removed: ${r.removed} · Errors: ${r.errors}`,...o.length?[``,`### Changed snapshots`,``,...o]:[],``,`Head: \`${e.headRevision}\``,`Report digest: \`${e.contentDigest}\``,``,`> Preview only. This result does not approve visual changes. Event-driven approval requires the production workflows on the default branch.`].join(`
672
+ `)}A();const sb=k({meta:{name:`prepare-preview`,description:`Rebuild a same-repository pre-adoption preview without an approval gate`},args:{input:{type:`string`,required:!0},output:{type:`string`,required:!0},"base-branch":{type:`string`,required:!0},"storybook-directory":{type:`string`}},async run({args:e}){if(process.env.GITHUB_EVENT_NAME!==`pull_request`)throw Error(`Preview requires pull_request`);let t=m_(await If(),e[`base-branch`]);if(t.base.repository!==t.head.repository)throw Error(`Fork previews are not supported`);let n=f(e.output),r=await Hg({inputDir:f(e.input),outputDir:n,trustedBaseBranch:t.base.ref,trustedHeadBranch:t.head.ref,...e[`storybook-directory`]?{storybookUrl:`./storybook/`}:{}});if(ab(t,r.report),e[`storybook-directory`]){let t=f(e[`storybook-directory`]);await nb(a(t),i(t)),await _(t,f(n,`storybook`),{recursive:!0,errorOnExist:!0,force:!1})}await K({"report-directory":n,"report-path":f(n,`report.json`),"report-digest":r.report.contentDigest??``,"head-sha":t.head.sha,"preview-alias":t.preview.alias})}});A();const cb=k({meta:{name:`prepare-run`,description:`Download, verify, and rebuild a completed workflow_run report`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},output:{type:`string`,default:`.kapture/trusted-report`,description:`New directory for the trusted static report`},receipt:{type:`string`,default:`.kapture/trusted-run-receipt.json`,description:`Path for the strict trusted-run receipt`},"storybook-url":{type:`string`,description:`Trusted HTTPS Storybook URL or the fixed same-origin ./storybook/ directory`},"temporary-root":{type:`string`,description:`Trusted temporary directory root (defaults to RUNNER_TEMP)`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If(),r=await ov(new _f(t,zf(n)),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],outputDir:f(e.output),receiptPath:f(e.receipt),...e[`storybook-url`]?{storybookUrl:e[`storybook-url`]}:{},...e[`temporary-root`]?{temporaryRoot:f(e[`temporary-root`])}:{}});await K({"base-sha":r.receipt.context.base.sha,"context-artifact-id":r.receipt.artifacts.context.id,"head-repository":r.receipt.context.head.repository,"head-sha":r.receipt.context.head.sha,"pr-number":r.receipt.context.prNumber,"preview-branch":r.receipt.context.preview.branch,"preview-alias":r.receipt.context.preview.alias,"raw-report-artifact-id":r.receipt.artifacts.report.id,"report-digest":r.receipt.report.contentDigest,"report-directory":r.reportDirectory,"report-path":r.reportPath,receipt:r.receiptPath,"run-attempt":r.receipt.captureRun.attempt,"run-head-branch":r.receipt.captureRun.headBranch,"run-head-repository-id":r.receipt.captureRun.headRepositoryId,"run-head-sha":r.receipt.captureRun.headSha,"run-id":r.receipt.captureRun.id,"changed-files-complete":String(r.changedFiles.complete),"changed-files-count":r.changedFiles.files.length,"trusted-artifact-name":r.receipt.trustedArtifactName,"workflow-id":r.receipt.captureRun.workflowId})}});A();const lb=k({meta:{name:`prepare-storybook-run`,description:`Verify and extract the exact receipt-bound head Storybook artifact`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},output:{type:`string`,required:!0,description:`New directory for the verified head Storybook`},receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},"temporary-root":{type:`string`,description:`Trusted temporary directory root (defaults beside output)`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If(),r=await cv(new _f(t,zf(n)),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],outputDir:f(e.output),receiptPath:f(e.receipt),...e[`temporary-root`]?{temporaryRoot:f(e[`temporary-root`])}:{}});await K({"head-ref":r.context.head.ref,"head-repository":r.context.head.repository,"head-sha":r.context.head.sha,"head-storybook-artifact-id":r.artifact.id,"pr-number":r.context.prNumber,"preview-branch":r.context.preview.branch,"preview-alias":r.context.preview.alias,receipt:r.receiptPath,"storybook-directory":r.storybookDirectory})}});A();const ub=k({meta:{name:`reconcile-run`,description:`Reconcile a trusted workflow_run event with the current PR status`},args:{"capture-workflow-path":{type:`string`,default:`.github/workflows/visual-capture.yml`,description:`Trusted path of the pull_request capture workflow`},"base-branch":{type:`string`,required:!0,description:`Expected pull request base branch`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If(),r=zf(n),i=await by(new _f(t,r),new Nf(t,r),{event:n,captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],statusContext:rf(e[`status-context`])});await K({status:i.status,"reconcile-reason":i.reason,...i.prNumber===void 0?{}:{"pr-number":i.prNumber},...i.headSha?{"head-sha":i.headSha}:{}})}});A();async function db(e,t,n=async(e,t)=>{switch(e){case`reconcile-run`:await ze(ub,{rawArgs:t});break;case`prepare-run`:await ze(cb,{rawArgs:t});break;case`prepare-storybook-run`:await ze(lb,{rawArgs:t})}}){let r=[`--capture-workflow-path`,t.captureWorkflowPath,`--base-branch`,t.baseBranch];if(await n(`reconcile-run`,[...r,`--status-context`,t.statusContext]),!e||typeof e!=`object`)throw Error(`Invalid workflow_run event`);let i=e;return i.action!==`completed`||i.workflow_run?.conclusion!==`success`?!1:(await n(`prepare-run`,[...r,`--output`,t.output,`--receipt`,t.receipt,...t.includeStorybook?[`--storybook-url`,`./storybook/`]:[]]),t.includeStorybook&&await n(`prepare-storybook-run`,[...r,`--output`,f(t.output,`storybook`),`--receipt`,t.receipt]),!0)}const fb=k({meta:{name:`prepare-review`,description:`Reconcile a workflow run and prepare verified static files for any hosting provider`},args:{...Zy,...lt,"capture-workflow-path":{type:`string`,default:`.github/workflows/kapture-capture.yml`},"base-branch":{type:`string`,required:!0},output:{type:`string`,required:!0},receipt:{type:`string`,required:!0},"include-storybook":{type:`boolean`,default:!1},"status-context":{type:`string`,default:`Kapture Visual Review`}},async run({args:e}){await K({ready:`false`});let t=await If(),n=await Xy(t,e);if(n){await K({status:n.status,"reconcile-reason":n.reason,...n.status===`noop`?{}:{"integration-mode":`adapter-upgrade`,comparison:`not-performed`}});return}if(await Qy(t,e)){await K({"integration-mode":`initial-adoption`,comparison:`not-performed`});return}let r=await db(t,{captureWorkflowPath:e[`capture-workflow-path`],baseBranch:e[`base-branch`],output:f(e.output),receipt:f(e.receipt),includeStorybook:e[`include-storybook`],statusContext:e[`status-context`]});await K({ready:String(r)})}});A();const pb=k({meta:{name:`publish-preview`,description:`Publish a preview-only status and comment; never issue an approval marker`},args:{report:{type:`string`,required:!0},"report-digest":{type:`string`,required:!0},"report-url":{type:`string`,required:!0},"base-branch":{type:`string`,required:!0},"capture-workflow-path":{type:`string`,default:`.github/workflows/kapture-capture.yml`}},async run({args:e}){if(process.env.GITHUB_EVENT_NAME!==`pull_request`)throw Error(`Preview requires pull_request`);let t=m_(await If(),e[`base-branch`]),n=process.env.GITHUB_TOKEN;if(!n)throw Error(`GITHUB_TOKEN is required`);let[r,i]=t.base.repository.split(`/`);if(!r||!i)throw Error(`Invalid repository`);let a=new Nf(n,{owner:r,repo:i}),o=new _f(n,{owner:r,repo:i}),s=await o.getWorkflowRun(t.runId);ib(t,s,Number(process.env.GITHUB_RUN_ATTEMPT),e[`capture-workflow-path`]);let c=await Wg(f(e.report),e[`report-digest`]);ab(t,c);let l=tf(e[`report-url`]);if(!l)throw Error(`Preview report URL is required`);let u=async()=>{let n=await a.getPullRequest(t.prNumber);if(n.number!==t.prNumber||n.state!==`open`||n.head.sha!==t.head.sha||n.base.sha!==t.base.sha)throw Error(`Ignoring an obsolete preview result`);let r=await o.getWorkflowRun(t.runId);ib(t,r,s.runAttempt,e[`capture-workflow-path`]),await fv(o,r)};await u();let d=await a.postOrUpdateReportComment(t.prNumber,ob(c,l,t),rb);if(await u(),await a.setReviewStatus(t.head.sha,c.summary.errors?`failure`:`success`,`Preview only; visual changes require separate review`,`Kapture Preview`,l),await K({"comment-id":d,"report-digest":c.contentDigest??``}),c.summary.errors)throw Error(`Preview contains capture errors`)}});A();const mb=k({meta:{name:`publish-run`,description:`Revalidate a prepare-run receipt and publish its deployed visual report`},args:{receipt:{type:`string`,required:!0,description:`Path to the strict prepare-run receipt`},report:{type:`string`,required:!0,description:`Path to the trusted image-bound report.json`},"report-url":{type:`string`,required:!0,description:`Immutable HTTPS URL of the deployed dashboard`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`PR comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await If(),r=zf(n),i=tf(e[`report-url`]);if(!i)throw Error(`report-url is required`);let a=await sv(new _f(t,r),new Nf(t,r),{event:n,receiptPath:f(e.receipt),reportPath:f(e.report),reportUrl:i,statusContext:rf(e[`status-context`]),commentLanguage:Kd(e[`comment-language`])});if(await K({status:a.status,"changed-count":a.changedCount,"comment-id":a.commentId,"report-digest":a.reportDigest}),a.status===`error`)throw Error(`Visual capture errors were published to the trusted report`)}catch(e){throw await K({status:`error`}),e}}});A(),Ng();const hb=k({meta:{name:`report`,description:`Publish a trusted Kapture PR report and commit status`},args:{report:{type:`string`,required:!0,description:`Path to image-bound trusted report.json`},"report-url":{type:`string`,description:`HTTPS URL for the full report or workflow run`},"status-context":{type:`string`,default:`Kapture Visual Review`,description:`GitHub commit status context`},"comment-language":{type:`string`,default:`en`,description:`PR comment language (en or ko)`}},async run({args:e}){try{let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await dg(e.report),r=Lf(await If()),i=rf(e[`status-context`]),a=tf(e[`report-url`]),o=await Xf(new Nf(t,r.repository),r,n,i,a,Kd(e[`comment-language`]));if(await K({status:o.status,"changed-count":o.changedCount,"comment-id":o.commentId,"report-digest":o.reportDigest}),o.status===`error`)throw Error(`${n.summary.errors} visual capture error(s)`)}catch(e){throw await K({status:`error`}),e}}});async function gb(e){let t=``,n;try{let{client:r,repository:i,workflow:a,baseRevision:o,headRevision:s}=e,l=await r.getContentSha(i,a,o);if(await r.getContentSha(i,a,s)!==l)return e.warn(`Build cache disabled: capture workflow differs between base and head`),{name:t,directory:``};let u=JSON.stringify([1,i,o,a,l,e.version]);t=`kapture-build-${T(`sha256`).update(u).digest(`hex`)}`;let d=await r.listCaptureCacheArtifacts(t);for(let e of d.slice(0,5)){if(e.expired||e.name!==t||e.sizeInBytes>eb.totalBytes||!/^sha256:[a-f0-9]{64}$/.test(e.digest))continue;let o=await r.getWorkflowRun(e.workflowRun.id);if(o.status!==`completed`||o.conclusion!==`success`||o.event!==`pull_request`||o.path!==a||o.repository.fullName!==i||o.headRepository.fullName!==i||o.headRepository.id!==o.repository.id||e.workflowRun.repositoryId!==o.repository.id||e.workflowRun.headRepositoryId!==o.repository.id||e.workflowRun.headSha!==o.headSha||!await r.isMergedCaptureRun(o.id,o.headSha)||await r.getContentSha(i,a,o.headSha)!==l)continue;let s=await r.downloadArtifactArchive(e.id,eb.totalBytes);if(`sha256:${T(`sha256`).update(s).digest(`hex`)}`!==e.digest)throw Error(`Build cache archive digest mismatch`);n=await ee(c(ce(),`kapture-build-cache-`));let u=c(n,`storybook`);return await s_(s,u,{maxEntries:eb.files,maxFileBytes:eb.fileBytes,maxTotalBytes:eb.totalBytes,allowPath:()=>!0,allowDirectoryPath:()=>!0}),await nb(n,`storybook`),{name:t,directory:u}}}catch(t){e.warn(`Build cache unavailable; build exact base: ${t instanceof Error?t.message:String(t)}`)}return n&&await re(n,{recursive:!0,force:!0}),{name:t,directory:``}}A();const _b=k({meta:{name:`restore-build`,description:`Restore a verified exact-base Storybook build`},args:{workflow:{type:`string`,required:!0,description:`Capture workflow path`}},async run({args:e}){if(!/^\.github\/workflows\/[A-Za-z0-9._-]+\.ya?ml$/.test(e.workflow))throw Error(`Expected repository-relative capture workflow path`);let t=m_(await If());if(t.base.repository!==t.head.repository)throw Error(`Build cache requires a same-repository pull request`);let[n,r]=t.base.repository.split(`/`),i=await gb({client:new _f(process.env.GITHUB_TOKEN??``,{owner:n,repo:r}),repository:t.base.repository,workflow:e.workflow,baseRevision:t.base.sha,headRevision:t.head.sha,version:Qe,warn:e=>console.warn(e)});await K({"cache-hit":String(!!i.directory),"cache-directory":i.directory,"cache-name":i.name})}});async function vb(e){let{client:t}=e,n=await t.getContentSha(e.repository,e.workflow,e.trustedRevision),r=await t.listCaptureCacheArtifacts(e.name);for(let i of r.slice(0,5)){if(i.expired||i.name!==e.name||i.sizeInBytes>1024**3||!/^sha256:[a-f0-9]{64}$/.test(i.digest))continue;let r=await t.getWorkflowRun(i.workflowRun.id);if(r.status!==`completed`||r.conclusion!==`success`||r.event!==`pull_request`||r.path!==e.workflow||r.repository.fullName!==e.repository||r.headRepository.fullName!==e.repository||i.workflowRun.repositoryId!==r.repository.id||i.workflowRun.headRepositoryId!==r.repository.id||!await t.isMergedCaptureRun(r.id,r.headSha)||await t.getContentSha(e.repository,e.workflow,r.headSha)!==n)continue;let a=await t.downloadArtifactArchive(i.id,1024**3);if(`sha256:${T(`sha256`).update(a).digest(`hex`)}`!==i.digest)throw Error(`Capture cache archive digest mismatch`);return await s_(a,e.output,{maxEntries:2e4,maxFileBytes:64*1024**2,maxTotalBytes:1024**3,allowPath:e=>e===`cache.json`||e===`manifest.json`||/^images\/[A-Za-z0-9._-]+\.png$/.test(e),allowDirectoryPath:e=>e===`images`}),!0}return!1}Bd(),A();const yb=k({meta:{name:`restore-capture`,description:`Restore merged head evidence matching the exact base build; cache misses never skip tests`},args:{"base-dir":{type:`string`,required:!0},"head-dir":{type:`string`,required:!0},workflow:{type:`string`,required:!0,description:`Repository-relative capture workflow path`},"base-revision":{type:`string`,required:!0}},async run({args:e}){if(!/^\.github\/workflows\/[A-Za-z0-9._-]+\.ya?ml$/.test(e.workflow)||!/^[a-f0-9]{40}$/.test(e[`base-revision`]))throw Error(`Expected capture workflow path and exact base revision`);let t=process.env.GITHUB_REPOSITORY??``,n=/^([A-Za-z0-9_.-]+)\/([A-Za-z0-9_.-]+)$/.exec(t);if(!n)throw Error(`GITHUB_REPOSITORY is required`);let r=await Tl(f(e[`base-dir`]),Qe),i=await Tl(f(e[`head-dir`]),Qe),a=await ee(c(ce(),`kapture-capture-cache-`)),o=await ee(c(ce(),`kapture-head-cache-`)),s=!1;try{s=await vb({client:new _f(process.env.GITHUB_TOKEN??``,{owner:n[1],repo:n[2]}),name:`kapture-capture-${r}`,repository:t,workflow:e.workflow,trustedRevision:e[`base-revision`],output:a})}catch(e){console.warn(`Capture cache unavailable; capturing normally: ${e instanceof Error?e.message:String(e)}`)}await K({"cache-directory":a,"cache-hit":String(s),"head-cache-directory":o,"head-cache-name":`kapture-capture-${i}`})}});A();const bb=k({meta:{name:`validate-build`,description:`Validate a Storybook artifact boundary before upload or capture`},args:{root:{type:`string`,required:!0,description:`Trusted checkout or artifact extraction root`},directory:{type:`string`,required:!0,description:`Storybook directory relative to root`},"path-only":{type:`boolean`,default:!1,description:`Validate the input path before building`}},async run({args:e}){if(e[`path-only`]){await K({directory:tb(e.root,e.directory)});return}let t=await nb(e.root,e.directory);await K(t),console.log(`Validated ${t.files} Storybook files (${t.bytes} bytes).`)}});A(),Ng();const xb=k({meta:{name:`verify`,description:`Verify that a Kapture report matches the current pull request`},args:{report:{type:`string`,required:!0,description:`Path to untrusted report.json`}},async run({args:e}){let t=process.env.GITHUB_TOKEN;if(!t)throw Error(`GITHUB_TOKEN is required`);let n=await dg(e.report),r=Lf(await If());await Yf(new Nf(t,r.repository),r,n)}});A();const Sb=k({meta:{name:`github`,description:`Verify, publish, and approve GitHub visual reviews`},subCommands:{"restore-build":_b,"restore-capture":yb,context:my,"validate-build":bb,"bind-artifacts":dy,"prepare-review":fb,"prepare-preview":sb,"publish-preview":pb,verify:xb,report:hb,approve:$f,"prepare-run":cb,"prepare-storybook-run":lb,"publish-run":mb,"reconcile-run":ub,"finalize-run":$y,cleanup:fy}});async function Cb(e,t){let{report:n,resolveImage:r}=await wb(e),i=n.entries[t];if(!i)throw Error(`Kapture report does not contain snapshot ${t}`);let a=[],o=(e,t)=>{t&&(kb(e,t),a.push({role:e,mediaType:`image/png`,source:r(t)}))};return o(`base`,i.baseImage),o(`head`,i.headImage),o(`diff`,i.diffImage),o(`base-repeat`,i.instability?.base?.repeatImage),o(`base-instability-diff`,i.instability?.base?.diffImage),o(`head-repeat`,i.instability?.head?.repeatImage),o(`head-instability-diff`,i.instability?.head?.diffImage),{version:1,report:{baseRevision:n.baseRevision,headRevision:n.headRevision,...n.contentDigest?{contentDigest:n.contentDigest}:{}},snapshot:{id:i.id,storyId:i.storyId,title:i.title,name:i.name,viewport:i.viewport,status:i.status,...i.changedPixels===void 0?{}:{changedPixels:i.changedPixels},...i.diffRatio===void 0?{}:{diffRatio:i.diffRatio},...i.threshold?{threshold:i.threshold}:{},...i.error?{error:i.error}:{}},images:a}}async function wb(e){let t=Ob(e);return t?Eb(t):Tb(e)}async function Tb(e){let t=f(e),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${pg} bytes`);let r=Db(await x(t,`utf8`)),i=a(t);return{report:r,resolveImage:e=>{let t=f(i,e);if(d(i,t).startsWith(`..`))throw Error(`Kapture report contains an unsafe image path: ${e}`);return{type:`path`,value:t}}}}async function Eb(e){let t=await fetch(e,{redirect:`error`});if(!t.ok)throw Error(`Kapture report request failed with HTTP ${t.status}`);return{report:Db((await hf(t,pg,`Kapture report`)).toString(`utf8`)),resolveImage:t=>{let n=new URL(t,e);if(n.origin!==e.origin||n.protocol!==`https:`)throw Error(`Kapture report contains an unsafe image URL: ${t}`);return{type:`url`,value:n.toString()}}}}function Db(e){try{return lg(JSON.parse(e))}catch(e){throw e instanceof SyntaxError?Error(`Kapture report does not contain valid JSON`):e}}function Ob(e){let t;try{t=new URL(e)}catch{return}if(t.protocol!==`https:`||t.username||t.password)throw Error(`Remote Kapture report must be an HTTPS URL without credentials`);return t}function kb(e,t){let n=`images/${e}/`,r=t.slice(n.length);if(!t.startsWith(n)||!r||r.includes(`/`)||r.includes(`\\`)||!r.endsWith(`.png`))throw Error(`Kapture report contains an invalid ${e} image path: ${t}`)}var Ab,jb=E((()=>{A(),Ng(),gf(),Ab=k({meta:{name:`inspect`,description:`Print machine-readable snapshot evidence for agents and review tools`},args:{report:{type:`string`,required:!0,description:`Local report.json path or public HTTPS report.json URL`},snapshot:{type:`string`,required:!0,description:`Exact snapshot ID`}},async run({args:e}){let t=await Cb(e.report,e.snapshot);process.stdout.write(`${JSON.stringify(t,null,2)}\n`)}})})),Mb=E((()=>{Hc()})),Nb=E((()=>{Mb()})),Pb=Se({createKaptureMcpServer:()=>Ib,getSnapshotEvidenceResult:()=>Lb,startKaptureMcpServer:()=>Fb});async function Fb(e){let{serveStdio:t}=await import(`@modelcontextprotocol/server/stdio`);t(()=>Ib(e),{onerror:e=>console.error(e.message)})}async function Ib(e){let{McpServer:t}=await import(`@modelcontextprotocol/server`),n=new t({name:`kapture`,version:Qe},{instructions:`Use list_snapshots to find visual changes, then get_snapshot_evidence to inspect the exact PNG evidence. Unstable snapshots are nondeterministic; accepting them requires an explicit GitHub exception approval with an optional reason, preserving the original evidence.`});return n.registerTool(`list_snapshots`,{title:`List Kapture snapshots`,description:`List snapshot IDs, statuses, stories, viewports, and diff metrics from a report.`,inputSchema:js({status:Is([`unchanged`,`changed`,`unstable`,`added`,`removed`,`error`]).optional().describe(`Optional exact status filter`)}),annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0}},async({status:t})=>{let{report:n}=await wb(e),r=Object.values(n.entries).filter(e=>!t||e.status===t).map(e=>({id:e.id,storyId:e.storyId,title:e.title,name:e.name,viewport:e.viewport,status:e.status,changedPixels:e.changedPixels,changedPixelPercentage:e.diffRatio===void 0?void 0:e.diffRatio*100})),i={baseRevision:n.baseRevision,headRevision:n.headRevision,summary:n.summary,snapshots:r};return{content:[{type:`text`,text:JSON.stringify(i,null,2)}],structuredContent:i}}),n.registerTool(`get_snapshot_evidence`,{title:`Get Kapture snapshot evidence`,description:`Return machine-readable metadata and the actual base, head, diff, and instability PNGs for one snapshot.`,inputSchema:js({snapshotId:z().min(1).max(512).describe(`Exact ID returned by list_snapshots`)}),annotations:{readOnlyHint:!0,destructiveHint:!1,idempotentHint:!0}},async({snapshotId:t})=>Lb(e,t)),n}async function Lb(e,t){let n=await Cb(e,t),r=await Promise.all(n.images.map(Rb));return{content:[{type:`text`,text:JSON.stringify(Hb(n),null,2)},...r],structuredContent:Hb(n)}}async function Rb(e){return{type:`image`,data:(e.source.type===`path`?await zb(e.source.value):await Bb(e.source.value)).toString(`base64`),mimeType:`image/png`,_meta:{"kapture/role":e.role}}}async function zb(e){let t=await v(e);if(t.isSymbolicLink()||!t.isFile()||t.size>Ub)throw Error(`Kapture evidence image must be no larger than ${Ub} bytes`);return Vb(await x(e),e)}async function Bb(e){let t=await fetch(e,{redirect:`error`});if(!t.ok)throw Error(`Kapture evidence request failed with HTTP ${t.status}`);return Vb(await hf(t,Ub,`Kapture evidence image`),e)}function Vb(e,t){if(e.byteLength>Ub||!e.subarray(0,8).equals(Wb))throw Error(`Kapture evidence is not a supported PNG: ${t}`);return e}function Hb(e){return{...e,images:e.images.map(t=>({role:t.role,mediaType:t.mediaType,source:t.source,contentBlockIndex:e.images.indexOf(t)+1}))}}var Ub,Wb,Gb=E((()=>{Nb(),jb(),gf(),Ub=26214400,Wb=Buffer.from([137,80,78,71,13,10,26,10])}));A();const Kb=k({meta:{name:`mcp`,description:`Serve Kapture snapshot evidence to agents over MCP stdio`},args:{report:{type:`string`,required:!0,description:`Local report.json path or public HTTPS report.json URL`}},async run({args:e}){let{startKaptureMcpServer:t}=await Promise.resolve().then(()=>(Gb(),Pb));await t(e.report)}});Bd(),A();const qb=k({meta:{name:`plan`,description:`Select affected Storybook stories from base/head dependency manifests`},args:{"base-dir":{type:`string`,required:!0,description:`Built base Storybook directory`},"head-dir":{type:`string`,required:!0,description:`Built head Storybook directory`},"changed-files":{type:`string`,required:!0,description:`Path to a versioned changed-files manifest or legacy JSON path array`},output:{type:`string`,default:`.kapture/plan.json`,description:`Affected-story plan output path`}},async run({args:e}){let t=await Jb(f(e[`changed-files`])),n=await zl({baseDir:f(e[`base-dir`]),headDir:f(e[`head-dir`]),changedFiles:t.files,changedFilesComplete:t.complete,...t.evidence?{changedFilesEvidence:t.evidence}:{}}),r=f(e.output);await y(a(r),{recursive:!0}),await w(r,`${JSON.stringify(n,null,2)}\n`,`utf8`),n.selectionMode===`affected`?Q.success(`Selected ${n.selectedStoryIds.length} of ${n.totalStoryIds.length} affected stories`):Q.warn(`Selected all ${n.totalStoryIds.length} stories (${n.fallbackReasons.map(e=>e.code).join(`, `)})`),Q.info(`Plan: ${r}`)}});async function Jb(e){let t;try{t=JSON.parse(await x(e,`utf8`))}catch(t){throw Error(`Failed to read changed files JSON from ${e}`,{cause:t})}if(!Array.isArray(t)){let e=T_(t);return{files:e.files,complete:e.complete,evidence:{provider:e.source.provider,manifestDigest:T(`sha256`).update(JSON.stringify(e)).digest(`hex`),pullRequestNumber:e.pullRequest.number,baseSha:e.pullRequest.baseSha,headSha:e.pullRequest.headSha}}}if(t.length>1e5)throw Error(`changed-files contains too many paths`);return{files:t.map(e=>E_(e,`changed file path`)),complete:!0}}A();const Yb=k({meta:{name:`report`,description:`Build trusted static Kapture reports`},subCommands:{build:Vg}});function Xb(e){let t=`## Kapture initial adoption
670
673
 
671
674
  **Comparison not performed. Visual approval is unavailable.**
672
675
 
673
- `;if(`error`in e)return`${t}Capture failed before a complete result was saved: ${af(e.error,500)}\n`;let{report:n}=e,r=n.snapshots.filter(e=>e.error!==void 0).length,i=[...n.snapshots].sort((e,t)=>Number(t.error!==void 0)-Number(e.error!==void 0));return[t,`Base: \`${n.baseRevision}\` → Head: \`${n.headRevision}\``,``,`Snapshots: ${i.length} · Captured: ${i.length-r} · Errors: ${r}`,``,`Head-only installation validation. Download this run's artifact for setup.json and PNGs; this is not a baseline or a visual review result.`,``,`| Story | Viewport | Capture result |`,`| --- | --- | --- |`,...i.slice(0,100).map(e=>`| ${af(`${e.title} / ${e.name}`)} | ${af(e.viewport.name)} (${e.viewport.width} × ${e.viewport.height}) | ${e.error===void 0?`Captured`:`Error: ${af(e.error)}`} |`),...i.length>100?[``,`Showing the first 100 snapshots (errors first). See setup.json for all snapshots.`]:[],``].join(`
674
- `)}async function Jb(e){let t=process.env.GITHUB_STEP_SUMMARY;t&&await h(t,qb(e))}Bc();const Yb=R().max(4096),Xb=R().regex(/^[a-f0-9]{40}$/),Zb=B({id:Yb,title:Yb,name:Yb,viewport:B({name:Yb,width:z().int().positive(),height:z().int().positive()}),image:R().regex(/^images\/[a-zA-Z0-9._-]+\.png$/).optional(),sha256:R().regex(/^[a-f0-9]{64}$/).optional(),error:Yb.optional()}).superRefine((e,t)=>{(e.error===void 0?!e.image||!e.sha256:e.image||e.sha256)&&t.addIssue({code:`custom`,message:`Snapshot must contain an image digest or an error`})}),Qb=B({version:V(1),kind:V(`initial-adoption`),comparison:V(`not-performed`),baseRevision:Xb,headRevision:Xb,snapshots:Ds(Zb).min(1).max(jg)}).superRefine((e,t)=>{new Set(e.snapshots.map(e=>e.id)).size!==e.snapshots.length&&t.addIssue({code:`custom`,message:`Duplicate snapshot IDs`})});function $b(e,t){return Qb.parse({version:1,kind:`initial-adoption`,comparison:`not-performed`,baseRevision:t,headRevision:e.revision,snapshots:Object.values(e.snapshots).sort((e,t)=>e.id.localeCompare(t.id)).map(e=>({id:e.id,title:e.title,name:e.name,viewport:e.viewport,...e.error===void 0?{image:e.imageFile,sha256:e.sha256}:{error:e.error}}))})}Ld(),A();const ex=k({meta:{name:`setup`,description:`Head-only installation validation without visual comparison or approval`},subCommands:{capture:k({meta:{name:`capture`,description:`Save head PNGs and setup.json, and write a GitHub Job Summary`},args:{"head-dir":{type:`string`,required:!0},"base-revision":{type:`string`,required:!0},"head-revision":{type:`string`,required:!0},output:{type:`string`,required:!0},workers:{type:`string`,default:`4`},locale:{type:`string`,default:`en-US`},timezone:{type:`string`,default:`UTC`},"install-browser":{type:`boolean`,default:!1},"browser-with-deps":{type:`boolean`,default:!1}},async run({args:e}){try{for(let t of[e[`base-revision`],e[`head-revision`]])if(!/^[a-f0-9]{40}$/.test(t))throw Error(`Setup requires full revision SHAs`);let t=Number(e.workers);if(!Number.isInteger(t)||t<1||t>8)throw Error(`Invalid workers`);e[`install-browser`]&&await et(e[`browser-with-deps`]);let n=f(e.output),r=$b(await Au({headDir:f(e[`head-dir`]),headRevision:e[`head-revision`],outputDir:n,adapterVersion:Qe,workers:t,locale:e.locale,timezone:e.timezone}),e[`base-revision`]);await w(c(n,`setup.json`),JSON.stringify(r),{flag:`wx`});let i=r.snapshots.filter(e=>e.error!==void 0).length;await Jb({report:r}),await G({"artifact-directory":n,"capture-errors":i,comparison:`not-performed`}),console.log(`Setup validation: ${r.snapshots.length} snapshots, ${i} errors. Comparison not performed.`),i&&(process.exitCode=2)}catch(e){throw await Jb({error:e instanceof Error?e.message:String(e)}),e}}})}});Ld(),A();const tx=k({meta:{name:`test`,description:`Capture and compare base/head Storybooks in one hermetic browser environment`},args:{"github-artifacts":{type:`boolean`,default:!1,description:`Validate downloaded builds, bind Actions artifact identities and preserve error reports for publication`},"base-dir":{type:`string`,required:!0,description:`Built base Storybook directory`},"head-dir":{type:`string`,required:!0,description:`Built head Storybook directory`},"base-capture-dir":{type:`string`,description:`Verified capture directory for the exact base revision; captures head only`},"capture-cache-dir":{type:`string`,description:`Optional verified content-addressed head cache to reuse as base; misses capture normally`},"capture-cache-output":{type:`string`,description:`Export stable head capture evidence for subsequent runs`},"base-revision":{type:`string`,required:!0,description:`Base Git revision`},"head-revision":{type:`string`,required:!0,description:`Head Git revision`},"changed-files":{type:`string`,description:`Versioned changed-files manifest used to capture only provably affected stories`},"install-browser":{type:`boolean`,default:!1,description:`Install the pinned Chrome runtime only when at least one story is selected`},"browser-with-deps":{type:`boolean`,default:!1,description:`Install Linux browser dependencies together with Chrome`},output:{type:`string`,default:`.kapture`,description:`Output directory`},workers:{type:`string`,default:`4`,description:`Concurrent isolated story lanes`},"pixel-color-threshold":{type:`string`,default:`0.2`,description:`Per-pixel perceptual color threshold`},"max-changed-pixel-percentage":{type:`string`,default:`0`,description:`Maximum percentage of changed pixels allowed without review (0 to 100)`},"frozen-time":{type:`string`,default:`2026-01-01T00:00:00.000Z`,description:`ISO time exposed to stories`},"random-seed":{type:`string`,default:`20260101`,description:`Math.random seed`},locale:{type:`string`,default:`en-US`,description:`BCP 47 browser locale`},timezone:{type:`string`,default:`UTC`,description:`IANA browser time zone`},"dashboard-dir":{type:`string`,description:`Dashboard build directory (defaults to the CLI embedded dashboard)`}},async run({args:e}){let t=ox(e.workers),n=sx(e[`pixel-color-threshold`],`pixel-color-threshold`),r=cx(e[`max-changed-pixel-percentage`],`max-changed-pixel-percentage`),o=ax(e[`random-seed`],`random-seed`),s=f(e[`base-dir`]),c=f(e[`head-dir`]),l=e[`github-artifacts`]?oy(process.env):void 0;if(l){let t=`-base-${e[`base-revision`]}-head-${e[`head-revision`]}`;if(!l.artifacts.context.name.endsWith(t))throw Error(`Artifact identities must match the requested base/head revisions`);await Promise.all([s,c].map(e=>$y(a(e),i(e))))}let u=e[`changed-files`]?await nx(s,c,f(e[`changed-files`]),e[`base-revision`],e[`head-revision`]):void 0;ix(u),e[`install-browser`]&&rx(u)&&(Z.start(`Installing the Kapture browser runtime…`),await et(e[`browser-with-deps`])),Z.start(e[`base-capture-dir`]?`Reusing the verified base capture and capturing affected head stories…`:`Capturing base and head Storybooks in one hermetic environment…`);let d=await ju({baseDir:s,headDir:c,...e[`base-capture-dir`]?{baseCaptureDir:f(e[`base-capture-dir`])}:{},...e[`capture-cache-dir`]?{captureCacheDir:f(e[`capture-cache-dir`])}:{},...e[`capture-cache-output`]?{captureCacheOutput:f(e[`capture-cache-output`])}:{},baseRevision:e[`base-revision`],headRevision:e[`head-revision`],outputDir:f(e.output),workers:t,threshold:{pixelColorThreshold:n,maxChangedPixelRatio:r/100},frozenTime:e[`frozen-time`],randomSeed:o,locale:e.locale,timezone:e.timezone,adapterVersion:Qe,selectionPlan:u});await td(e[`dashboard-dir`]?f(e[`dashboard-dir`]):f(a(fe(import.meta.url)),`dashboard`),f(e.output,`report`)),l&&(await w(f(e.output,`report`,`capture-boundary.json`),`${JSON.stringify(l)}\n`,{flag:`wx`,mode:384}),await G({"report-directory":f(e.output,`report`),"report-path":f(e.output,`report`,`report.json`),"capture-errors":d.report.summary.errors}));let{summary:p}=d.report;Z.success(`${p.total} snapshots: ${p.changed} changed, ${p.unstable} unstable, ${p.added} added, ${p.removed} removed, ${p.unchanged} unchanged, ${p.errors} errors`),Z.info(`Environment: ${d.report.environment.id}`),Z.info(`Report: ${f(e.output,`report`,`report.json`)}`),p.errors>0&&!l&&(process.exitCode=2)}});async function nx(e,t,n,r,i){let a=await Gb(n);if(a.evidence&&(a.evidence.baseSha!==r||a.evidence.headSha!==i))throw Error(`changed-files manifest base/head SHAs must match --base-revision and --head-revision`);return Il({baseDir:e,headDir:t,changedFiles:a.files,changedFilesComplete:a.complete,...a.evidence?{changedFilesEvidence:a.evidence}:{}})}function rx(e){return!e||e.selectedStoryIds.length>0}function ix(e){if(!e){Z.info(`Story coverage: full capture (no changed-files manifest)`);return}if(e.selectionMode===`affected`){Z.info(`Story coverage: ${e.selectedStoryIds.length} affected, ${e.skippedStoryIds.length} proven unaffected`);return}Z.warn(`Story coverage: full fallback (${e.fallbackReasons.map(e=>e.code).join(`, `)})`)}function ax(e,t){let n=Number.parseInt(e,10);if(!Number.isInteger(n)||n<=0)throw Error(`${t} must be a positive integer`);return n}function ox(e){let t=ax(e,`workers`);if(t>8)throw Error(`workers must be between 1 and 8`);return t}function sx(e,t){let n=Number.parseFloat(e);if(!Number.isFinite(n)||n<0||n>1)throw Error(`${t} must be between 0 and 1`);return n}function cx(e,t){let n=Number(e);if(!Number.isFinite(n)||n<0||n>100)throw Error(`${t} must be between 0 and 100`);return n}A(),kg();const lx=k({meta:{name:`validate`,description:`Validate a Kapture report as a CI gate`},args:{report:{type:`string`,required:!0,description:`Path to report.json`},"fail-on-diff":{type:`boolean`,default:!1,description:`Exit 1 when visual changes require review`}},async run({args:e}){let t=f(e.report),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${ug} bytes`);let r=og(JSON.parse(await x(t,`utf8`)));if(r.summary.errors>0){Z.error(`${r.summary.errors} capture or comparison error(s)`),process.exitCode=2;return}let i=r.summary.changed+r.summary.added+r.summary.removed;if(r.summary.unstable>0){Z.error(`${r.summary.unstable} screen(s) could not be verified: capturing the same code again produced different images. Fix the inconsistent rendering and rerun.`),process.exitCode=3;return}if(i>0&&e[`fail-on-diff`]){Z.warn(`${i} visual change(s) require human approval`),process.exitCode=1;return}Z.success(i>0?`${i} visual change(s) detected`:`No visual changes`)}});A(),Ob(),Ue(k({meta:{name:`kapture`,version:Qe,description:`Hermetic Storybook visual review`},subCommands:{setup:ex,test:tx,validate:lx,browser:tt,ci:lt,plan:Wb,report:Kb,github:yb,inspect:Db,mcp:Ub}}));export{};
676
+ `;if(`error`in e)return`${t}Capture failed before a complete result was saved: ${cf(e.error,500)}\n`;let{report:n}=e,r=n.snapshots.filter(e=>e.error!==void 0).length,i=[...n.snapshots].sort((e,t)=>Number(t.error!==void 0)-Number(e.error!==void 0));return[t,`Base: \`${n.baseRevision}\` → Head: \`${n.headRevision}\``,``,`Snapshots: ${i.length} · Captured: ${i.length-r} · Errors: ${r}`,``,`Head-only installation validation. Download this run's artifact for setup.json and PNGs; this is not a baseline or a visual review result.`,``,`| Story | Viewport | Capture result |`,`| --- | --- | --- |`,...i.slice(0,100).map(e=>`| ${cf(`${e.title} / ${e.name}`)} | ${cf(e.viewport.name)} (${e.viewport.width} × ${e.viewport.height}) | ${e.error===void 0?`Captured`:`Error: ${cf(e.error)}`} |`),...i.length>100?[``,`Showing the first 100 snapshots (errors first). See setup.json for all snapshots.`]:[],``].join(`
677
+ `)}async function Zb(e){let t=process.env.GITHUB_STEP_SUMMARY;t&&await h(t,Xb(e))}Uc();const Qb=z().max(4096),$b=z().regex(/^[a-f0-9]{40}$/),ex=V({id:Qb,title:Qb,name:Qb,viewport:V({name:Qb,width:B().int().positive(),height:B().int().positive()}),image:z().regex(/^images\/[a-zA-Z0-9._-]+\.png$/).optional(),sha256:z().regex(/^[a-f0-9]{64}$/).optional(),error:Qb.optional()}).superRefine((e,t)=>{(e.error===void 0?!e.image||!e.sha256:e.image||e.sha256)&&t.addIssue({code:`custom`,message:`Snapshot must contain an image digest or an error`})}),tx=V({version:H(1),kind:H(`initial-adoption`),comparison:H(`not-performed`),baseRevision:$b,headRevision:$b,snapshots:As(ex).min(1).max(Fg)}).superRefine((e,t)=>{new Set(e.snapshots.map(e=>e.id)).size!==e.snapshots.length&&t.addIssue({code:`custom`,message:`Duplicate snapshot IDs`})});function nx(e,t){return tx.parse({version:1,kind:`initial-adoption`,comparison:`not-performed`,baseRevision:t,headRevision:e.revision,snapshots:Object.values(e.snapshots).sort((e,t)=>e.id.localeCompare(t.id)).map(e=>({id:e.id,title:e.title,name:e.name,viewport:e.viewport,...e.error===void 0?{image:e.imageFile,sha256:e.sha256}:{error:e.error}}))})}Bd(),A();const rx=k({meta:{name:`setup`,description:`Head-only installation validation without visual comparison or approval`},subCommands:{capture:k({meta:{name:`capture`,description:`Save head PNGs and setup.json, and write a GitHub Job Summary`},args:{"head-dir":{type:`string`,required:!0},"base-revision":{type:`string`,required:!0},"head-revision":{type:`string`,required:!0},output:{type:`string`,required:!0},workers:{type:`string`,default:`4`},locale:{type:`string`,default:`en-US`},timezone:{type:`string`,default:`UTC`},"install-browser":{type:`boolean`,default:!1},"browser-with-deps":{type:`boolean`,default:!1}},async run({args:e}){try{for(let t of[e[`base-revision`],e[`head-revision`]])if(!/^[a-f0-9]{40}$/.test(t))throw Error(`Setup requires full revision SHAs`);let t=Number(e.workers);if(!Number.isInteger(t)||t<1||t>8)throw Error(`Invalid workers`);e[`install-browser`]&&await et(e[`browser-with-deps`]);let n=f(e.output),r=nx(await Nu({headDir:f(e[`head-dir`]),headRevision:e[`head-revision`],outputDir:n,adapterVersion:Qe,workers:t,locale:e.locale,timezone:e.timezone}),e[`base-revision`]);await w(c(n,`setup.json`),JSON.stringify(r),{flag:`wx`});let i=r.snapshots.filter(e=>e.error!==void 0).length;await Zb({report:r}),await K({"artifact-directory":n,"capture-errors":i,comparison:`not-performed`}),console.log(`Setup validation: ${r.snapshots.length} snapshots, ${i} errors. Comparison not performed.`),i&&(process.exitCode=2)}catch(e){throw await Zb({error:e instanceof Error?e.message:String(e)}),e}}})}});Bd(),A();const ix=k({meta:{name:`test`,description:`Capture and compare base/head Storybooks in one hermetic browser environment`},args:{"github-artifacts":{type:`boolean`,default:!1,description:`Validate downloaded builds, bind Actions artifact identities and preserve error reports for publication`},"base-dir":{type:`string`,required:!0,description:`Built base Storybook directory`},"head-dir":{type:`string`,required:!0,description:`Built head Storybook directory`},"base-capture-dir":{type:`string`,description:`Verified capture directory for the exact base revision; captures head only`},"capture-cache-dir":{type:`string`,description:`Optional verified content-addressed head cache to reuse as base; misses capture normally`},"capture-cache-output":{type:`string`,description:`Export stable head capture evidence for subsequent runs`},"base-revision":{type:`string`,required:!0,description:`Base Git revision`},"head-revision":{type:`string`,required:!0,description:`Head Git revision`},"changed-files":{type:`string`,description:`Versioned changed-files manifest used to capture only provably affected stories`},"install-browser":{type:`boolean`,default:!1,description:`Install the pinned Chrome runtime only when at least one story is selected`},"browser-with-deps":{type:`boolean`,default:!1,description:`Install Linux browser dependencies together with Chrome`},output:{type:`string`,default:`.kapture`,description:`Output directory`},workers:{type:`string`,default:`4`,description:`Concurrent isolated story lanes`},"pixel-color-threshold":{type:`string`,default:`0.2`,description:`Per-pixel perceptual color threshold`},"max-changed-pixel-percentage":{type:`string`,default:`0`,description:`Maximum percentage of changed pixels allowed without review (0 to 100)`},"frozen-time":{type:`string`,default:`2026-01-01T00:00:00.000Z`,description:`ISO time exposed to stories`},"random-seed":{type:`string`,default:`20260101`,description:`Math.random seed`},locale:{type:`string`,default:`en-US`,description:`BCP 47 browser locale`},timezone:{type:`string`,default:`UTC`,description:`IANA browser time zone`},"dashboard-dir":{type:`string`,description:`Dashboard build directory (defaults to the CLI embedded dashboard)`}},async run({args:e}){let t=lx(e.workers),n=ux(e[`pixel-color-threshold`],`pixel-color-threshold`),r=dx(e[`max-changed-pixel-percentage`],`max-changed-pixel-percentage`),o=cx(e[`random-seed`],`random-seed`),s=f(e[`base-dir`]),c=f(e[`head-dir`]),l=e[`github-artifacts`]?uy(process.env):void 0;if(l){let t=`-base-${e[`base-revision`]}-head-${e[`head-revision`]}`;if(!l.artifacts.context.name.endsWith(t))throw Error(`Artifact identities must match the requested base/head revisions`);await Promise.all([s,c].map(e=>nb(a(e),i(e))))}let u=e[`changed-files`]?await ax(s,c,f(e[`changed-files`]),e[`base-revision`],e[`head-revision`]):void 0;sx(u),e[`install-browser`]&&ox(u)&&(Q.start(`Installing the Kapture browser runtime…`),await et(e[`browser-with-deps`])),Q.start(e[`base-capture-dir`]?`Reusing the verified base capture and capturing affected head stories…`:`Capturing base and head Storybooks in one hermetic environment…`);let d=await Pu({baseDir:s,headDir:c,...e[`base-capture-dir`]?{baseCaptureDir:f(e[`base-capture-dir`])}:{},...e[`capture-cache-dir`]?{captureCacheDir:f(e[`capture-cache-dir`])}:{},...e[`capture-cache-output`]?{captureCacheOutput:f(e[`capture-cache-output`])}:{},baseRevision:e[`base-revision`],headRevision:e[`head-revision`],outputDir:f(e.output),workers:t,threshold:{pixelColorThreshold:n,maxChangedPixelRatio:r/100},frozenTime:e[`frozen-time`],randomSeed:o,locale:e.locale,timezone:e.timezone,adapterVersion:Qe,selectionPlan:u});await id(e[`dashboard-dir`]?f(e[`dashboard-dir`]):f(a(fe(import.meta.url)),`dashboard`),f(e.output,`report`)),l&&(await w(f(e.output,`report`,`capture-boundary.json`),`${JSON.stringify(l)}\n`,{flag:`wx`,mode:384}),await K({"report-directory":f(e.output,`report`),"report-path":f(e.output,`report`,`report.json`),"capture-errors":d.report.summary.errors}));let{summary:p}=d.report;Q.success(`${p.total} snapshots: ${p.changed} changed, ${p.unstable} unstable, ${p.added} added, ${p.removed} removed, ${p.unchanged} unchanged, ${p.errors} errors`),Q.info(`Environment: ${d.report.environment.id}`),Q.info(`Report: ${f(e.output,`report`,`report.json`)}`),p.errors>0&&!l&&(process.exitCode=2)}});async function ax(e,t,n,r,i){let a=await Jb(n);if(a.evidence&&(a.evidence.baseSha!==r||a.evidence.headSha!==i))throw Error(`changed-files manifest base/head SHAs must match --base-revision and --head-revision`);return zl({baseDir:e,headDir:t,changedFiles:a.files,changedFilesComplete:a.complete,...a.evidence?{changedFilesEvidence:a.evidence}:{}})}function ox(e){return!e||e.selectedStoryIds.length>0}function sx(e){if(!e){Q.info(`Story coverage: full capture (no changed-files manifest)`);return}if(e.selectionMode===`affected`){Q.info(`Story coverage: ${e.selectedStoryIds.length} affected, ${e.skippedStoryIds.length} proven unaffected`);return}Q.warn(`Story coverage: full fallback (${e.fallbackReasons.map(e=>e.code).join(`, `)})`)}function cx(e,t){let n=Number.parseInt(e,10);if(!Number.isInteger(n)||n<=0)throw Error(`${t} must be a positive integer`);return n}function lx(e){let t=cx(e,`workers`);if(t>8)throw Error(`workers must be between 1 and 8`);return t}function ux(e,t){let n=Number.parseFloat(e);if(!Number.isFinite(n)||n<0||n>1)throw Error(`${t} must be between 0 and 1`);return n}function dx(e,t){let n=Number(e);if(!Number.isFinite(n)||n<0||n>100)throw Error(`${t} must be between 0 and 100`);return n}A(),Ng();const fx=k({meta:{name:`validate`,description:`Validate a Kapture report as a CI gate`},args:{report:{type:`string`,required:!0,description:`Path to report.json`},"fail-on-diff":{type:`boolean`,default:!1,description:`Exit 1 when visual changes require review`}},async run({args:e}){let t=f(e.report),n=await C(t);if(!n.isFile()||n.size>10485760)throw Error(`Kapture report must be a file no larger than ${pg} bytes`);let r=lg(JSON.parse(await x(t,`utf8`)));if(r.summary.errors>0){Q.error(`${r.summary.errors} capture or comparison error(s)`),process.exitCode=2;return}let i=r.summary.changed+r.summary.added+r.summary.removed;if(r.summary.unstable>0){Q.error(`${r.summary.unstable} screen(s) could not be verified: capturing the same code again produced different images. Fix the inconsistent rendering and rerun.`),process.exitCode=3;return}if(i>0&&e[`fail-on-diff`]){Q.warn(`${i} visual change(s) require human approval`),process.exitCode=1;return}Q.success(i>0?`${i} visual change(s) detected`:`No visual changes`)}});A(),jb(),Ue(k({meta:{name:`kapture`,version:Qe,description:`Hermetic Storybook visual review`},subCommands:{setup:rx,test:ix,validate:fx,browser:tt,ci:pt,plan:qb,report:Yb,github:Sb,inspect:Ab,mcp:Kb}}));export{};