@myrialabs/clopen 0.4.36 → 0.4.37

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.
@@ -0,0 +1,125 @@
1
+ import { afterEach, beforeEach, describe, expect, test } from 'bun:test';
2
+ import { mkdtemp, rm, writeFile, mkdir } from 'node:fs/promises';
3
+ import { tmpdir } from 'node:os';
4
+ import path from 'node:path';
5
+ import { execGit } from '../../git/git-executor';
6
+ import { buildBudgetedStagedDiff, COMMIT_MESSAGE_BUDGET, type DiffBudget } from './diff-budget';
7
+
8
+ /**
9
+ * The AI generators used to inline the raw `git diff --cached` output, which had
10
+ * no upper bound at all. These assert the replacement stays inside its budget
11
+ * while still describing the whole change.
12
+ */
13
+
14
+ let repo: string;
15
+
16
+ async function git(...args: string[]) {
17
+ const result = await execGit(args, repo);
18
+ if (result.exitCode !== 0) throw new Error(`git ${args.join(' ')}: ${result.stderr}`);
19
+ return result.stdout;
20
+ }
21
+
22
+ const TINY_BUDGET: DiffBudget = {
23
+ perFileBytes: 400,
24
+ totalBytes: 900,
25
+ maxFiles: 3,
26
+ contextLines: 1
27
+ };
28
+
29
+ beforeEach(async () => {
30
+ repo = await mkdtemp(path.join(tmpdir(), 'clopen-diffbudget-'));
31
+ await git('init', '-b', 'main', '.');
32
+ await git('config', 'user.email', 'test@example.com');
33
+ await git('config', 'user.name', 'Test');
34
+ await git('config', 'commit.gpgsign', 'false');
35
+ });
36
+
37
+ afterEach(async () => {
38
+ await rm(repo, { recursive: true, force: true });
39
+ });
40
+
41
+ describe('buildBudgetedStagedDiff', () => {
42
+ test('reports an empty staging area', async () => {
43
+ const result = await buildBudgetedStagedDiff(repo, COMMIT_MESSAGE_BUDGET);
44
+ expect(result.isEmpty).toBe(true);
45
+ expect(result.text).toBe('');
46
+ });
47
+
48
+ test('includes the stat header and the patch for a small change', async () => {
49
+ await writeFile(path.join(repo, 'a.ts'), 'export const a = 1;\n');
50
+ await git('add', '-A');
51
+
52
+ const result = await buildBudgetedStagedDiff(repo, COMMIT_MESSAGE_BUDGET);
53
+ expect(result.isEmpty).toBe(false);
54
+ expect(result.truncated).toBe(false);
55
+ expect(result.text).toContain('Files changed:');
56
+ expect(result.text).toContain('a.ts');
57
+ expect(result.text).toContain('export const a = 1;');
58
+ });
59
+
60
+ test('skips lockfiles and generated output but still names them', async () => {
61
+ await writeFile(path.join(repo, 'bun.lock'), 'x'.repeat(50_000));
62
+ await mkdir(path.join(repo, 'dist'), { recursive: true });
63
+ await writeFile(path.join(repo, 'dist', 'bundle.js'), 'y'.repeat(50_000));
64
+ await writeFile(path.join(repo, 'src.ts'), 'export const keep = true;\n');
65
+ await git('add', '-A');
66
+
67
+ const result = await buildBudgetedStagedDiff(repo, COMMIT_MESSAGE_BUDGET);
68
+ expect(result.text).toContain('Binary or generated files (diff omitted)');
69
+ expect(result.text).toContain('bun.lock');
70
+ expect(result.text).toContain('dist/bundle.js');
71
+ // The real source file still gets its patch.
72
+ expect(result.text).toContain('export const keep = true;');
73
+ // And none of the 100 KB of noise made it into the prompt.
74
+ expect(result.text).not.toContain('x'.repeat(200));
75
+ expect(result.text).not.toContain('y'.repeat(200));
76
+ });
77
+
78
+ test('omits a binary file from the patch body', async () => {
79
+ await writeFile(path.join(repo, 'image.dat'), Buffer.from([0, 1, 2, 0, 255, 0]));
80
+ await git('add', '-A');
81
+
82
+ const result = await buildBudgetedStagedDiff(repo, COMMIT_MESSAGE_BUDGET);
83
+ expect(result.text).toContain('Binary or generated files (diff omitted)');
84
+ expect(result.text).toContain('image.dat');
85
+ });
86
+
87
+ test('clips an oversized file and says so', async () => {
88
+ const big = Array.from({ length: 400 }, (_, i) => `line ${i}`).join('\n');
89
+ await writeFile(path.join(repo, 'big.ts'), `${big}\n`);
90
+ await git('add', '-A');
91
+
92
+ const result = await buildBudgetedStagedDiff(repo, TINY_BUDGET);
93
+ expect(result.truncated).toBe(true);
94
+ expect(result.text).toContain('… truncated');
95
+ expect(result.text).toContain('sampled');
96
+ // The whole point: the prompt stays near the budget, not the file size.
97
+ expect(result.text.length).toBeLessThan(TINY_BUDGET.totalBytes * 3);
98
+ });
99
+
100
+ test('stops opening files once the budget is spent, and reports the remainder', async () => {
101
+ for (let i = 0; i < 8; i++) {
102
+ const body = Array.from({ length: 60 }, (_, n) => `const v${i}_${n} = ${n};`).join('\n');
103
+ await writeFile(path.join(repo, `f${i}.ts`), `${body}\n`);
104
+ }
105
+ await git('add', '-A');
106
+
107
+ const result = await buildBudgetedStagedDiff(repo, TINY_BUDGET);
108
+ expect(result.truncated).toBe(true);
109
+ expect(result.text).toContain('were omitted');
110
+ // Every file is still visible in the stat header, so the model can
111
+ // describe the change as a whole.
112
+ expect(result.text).toContain('f7.ts');
113
+ });
114
+
115
+ test('handles a rename without losing the path', async () => {
116
+ await writeFile(path.join(repo, 'old.ts'), 'export const x = 1;\n');
117
+ await git('add', '-A');
118
+ await git('commit', '-m', 'init');
119
+ await git('mv', 'old.ts', 'new.ts');
120
+
121
+ const result = await buildBudgetedStagedDiff(repo, COMMIT_MESSAGE_BUDGET);
122
+ expect(result.isEmpty).toBe(false);
123
+ expect(result.text).toContain('new.ts');
124
+ });
125
+ });
@@ -0,0 +1,220 @@
1
+ /**
2
+ * Budgeted staged-diff builder for the AI generators.
3
+ *
4
+ * The commit-message and branch-name handlers used to inline the raw output of
5
+ * `git diff --cached` into the prompt. That has no upper bound: a lockfile
6
+ * refresh or a vendored bundle turns one "generate commit message" click into
7
+ * hundreds of thousands of tokens, and on strict-context models it fails
8
+ * outright instead of degrading.
9
+ *
10
+ * This builds the same information under a hard budget: the `--stat` header
11
+ * always survives (it is small and describes the *whole* change), noisy paths
12
+ * are skipped by name, and the patch body is filled file by file until the
13
+ * budget runs out. Truncation is announced in the text so the model knows it is
14
+ * looking at a sample rather than the complete change.
15
+ */
16
+
17
+ import { execGit } from '../../git/git-executor';
18
+ import { assertSafeGitPathOperand } from '../../git/git-spawn-validation';
19
+
20
+ export interface DiffBudget {
21
+ /** Max bytes of patch text kept for any single file. */
22
+ perFileBytes: number;
23
+ /** Max bytes of patch text across all files. */
24
+ totalBytes: number;
25
+ /** Max number of files we spawn a `git diff` for. */
26
+ maxFiles: number;
27
+ /** Lines of surrounding context per hunk. */
28
+ contextLines: number;
29
+ }
30
+
31
+ /**
32
+ * Budget for commit messages. Big enough that a normal feature change arrives
33
+ * whole, small enough that a lockfile-sized diff cannot blow up the request.
34
+ */
35
+ export const COMMIT_MESSAGE_BUDGET: DiffBudget = {
36
+ perFileBytes: 6 * 1024,
37
+ totalBytes: 24 * 1024,
38
+ maxFiles: 40,
39
+ contextLines: 3
40
+ };
41
+
42
+ /**
43
+ * Budget for branch names. A branch name is one to three words about the *topic*
44
+ * of the change, so the file list carries almost all the signal and the patch is
45
+ * only there to disambiguate.
46
+ */
47
+ export const BRANCH_NAME_BUDGET: DiffBudget = {
48
+ perFileBytes: 2 * 1024,
49
+ totalBytes: 4 * 1024,
50
+ maxFiles: 15,
51
+ contextLines: 0
52
+ };
53
+
54
+ /**
55
+ * Paths whose diff is machine-generated: enormous, uninformative, and the single
56
+ * biggest source of wasted context. They still appear in the `--stat` header, so
57
+ * the model can see they changed.
58
+ */
59
+ const GENERATED_PATH_PATTERNS: RegExp[] = [
60
+ /(^|\/)(bun\.lock|bun\.lockb|package-lock\.json|yarn\.lock|pnpm-lock\.yaml)$/,
61
+ /(^|\/)(Cargo\.lock|composer\.lock|Gemfile\.lock|poetry\.lock|go\.sum)$/,
62
+ /(^|\/)(dist|build|out|vendor|node_modules|coverage)\//,
63
+ /\.(min\.js|min\.css|map|snap)$/,
64
+ /(^|\/)__snapshots__\//
65
+ ];
66
+
67
+ function isGeneratedPath(filePath: string): boolean {
68
+ return GENERATED_PATH_PATTERNS.some(pattern => pattern.test(filePath));
69
+ }
70
+
71
+ interface NumstatEntry {
72
+ path: string;
73
+ isBinary: boolean;
74
+ }
75
+
76
+ /**
77
+ * `git diff --cached --numstat -z` emits `adds\tdels\tpath\0`, with `-` counts
78
+ * for binary files. Renames add two extra NUL-separated path fields after an
79
+ * empty path slot, which is why the parser advances through the stream rather
80
+ * than splitting it into fixed records.
81
+ */
82
+ function parseNumstat(output: string): NumstatEntry[] {
83
+ const entries: NumstatEntry[] = [];
84
+ const fields = output.split('\0');
85
+
86
+ for (let i = 0; i < fields.length; i++) {
87
+ const field = fields[i];
88
+ if (!field.trim()) continue;
89
+ const parts = field.split('\t');
90
+ if (parts.length < 3) continue;
91
+
92
+ const [adds, dels, rawPath] = parts;
93
+ let filePath = rawPath;
94
+ if (filePath === '') {
95
+ // Rename/copy: the old and new paths follow as their own fields.
96
+ const newPath = fields[i + 2];
97
+ if (newPath) filePath = newPath;
98
+ i += 2;
99
+ }
100
+ if (!filePath) continue;
101
+
102
+ entries.push({ path: filePath, isBinary: adds === '-' && dels === '-' });
103
+ }
104
+
105
+ return entries;
106
+ }
107
+
108
+ function truncate(text: string, limit: number): { text: string; truncated: boolean } {
109
+ if (text.length <= limit) return { text, truncated: false };
110
+ const clipped = text.slice(0, limit);
111
+ // Cut on a line boundary so the model never sees half a diff line.
112
+ const lastNewline = clipped.lastIndexOf('\n');
113
+ const body = lastNewline > 0 ? clipped.slice(0, lastNewline) : clipped;
114
+ const droppedLines = text.slice(body.length).split('\n').length;
115
+ return {
116
+ text: `${body}\n… truncated, ${droppedLines} more line${droppedLines === 1 ? '' : 's'} in this file`,
117
+ truncated: true
118
+ };
119
+ }
120
+
121
+ export interface BudgetedDiff {
122
+ /** The rendered prompt section, ready to append. */
123
+ text: string;
124
+ /** True when any file's patch was clipped or dropped. */
125
+ truncated: boolean;
126
+ /** True when there is nothing staged at all. */
127
+ isEmpty: boolean;
128
+ }
129
+
130
+ /**
131
+ * Build the staged-diff section of an AI prompt under `budget`.
132
+ *
133
+ * We deliberately spawn one `git diff` per file rather than one for everything:
134
+ * it lets us stop as soon as the budget is spent, so a 200 MB staged blob is
135
+ * never read into memory in the first place.
136
+ */
137
+ export async function buildBudgetedStagedDiff(
138
+ cwd: string,
139
+ budget: DiffBudget
140
+ ): Promise<BudgetedDiff> {
141
+ const numstat = await execGit(['diff', '--cached', '--numstat', '-z', '-M'], cwd);
142
+ const entries = parseNumstat(numstat.stdout);
143
+
144
+ if (entries.length === 0) {
145
+ return { text: '', truncated: false, isEmpty: true };
146
+ }
147
+
148
+ const statResult = await execGit(['diff', '--cached', '--stat=200', '-M'], cwd);
149
+ const stat = statResult.stdout.trim();
150
+
151
+ const skipped: string[] = [];
152
+ const candidates: string[] = [];
153
+ for (const entry of entries) {
154
+ if (entry.isBinary || isGeneratedPath(entry.path)) {
155
+ skipped.push(entry.path);
156
+ continue;
157
+ }
158
+ candidates.push(entry.path);
159
+ }
160
+
161
+ const patches: string[] = [];
162
+ let used = 0;
163
+ let truncated = false;
164
+ let filesOmitted = 0;
165
+
166
+ for (const [index, filePath] of candidates.entries()) {
167
+ if (index >= budget.maxFiles || used >= budget.totalBytes) {
168
+ filesOmitted = candidates.length - index;
169
+ truncated = true;
170
+ break;
171
+ }
172
+
173
+ try {
174
+ assertSafeGitPathOperand(filePath, 'diff path');
175
+ } catch {
176
+ skipped.push(filePath);
177
+ continue;
178
+ }
179
+
180
+ const result = await execGit(
181
+ [
182
+ 'diff',
183
+ '--cached',
184
+ '--no-color',
185
+ `--unified=${budget.contextLines}`,
186
+ '-M',
187
+ '--',
188
+ filePath
189
+ ],
190
+ cwd
191
+ );
192
+ if (result.exitCode !== 0 || !result.stdout.trim()) continue;
193
+
194
+ const remaining = budget.totalBytes - used;
195
+ const limit = Math.min(budget.perFileBytes, remaining);
196
+ const clipped = truncate(result.stdout.trimEnd(), limit);
197
+ if (clipped.truncated) truncated = true;
198
+ patches.push(clipped.text);
199
+ used += clipped.text.length;
200
+ }
201
+
202
+ const sections: string[] = [];
203
+ if (stat) sections.push(`Files changed:\n${stat}`);
204
+ if (skipped.length > 0) {
205
+ const shown = skipped.slice(0, 10).join(', ');
206
+ const rest = skipped.length > 10 ? `, and ${skipped.length - 10} more` : '';
207
+ sections.push(`Binary or generated files (diff omitted): ${shown}${rest}`);
208
+ }
209
+ if (patches.length > 0) {
210
+ const header = truncated
211
+ ? 'Staged diff (sampled — some files or lines were omitted to fit context):'
212
+ : 'Staged diff:';
213
+ sections.push(`${header}\n${patches.join('\n')}`);
214
+ }
215
+ if (filesOmitted > 0) {
216
+ sections.push(`${filesOmitted} further changed file(s) were omitted; see the file list above.`);
217
+ }
218
+
219
+ return { text: sections.join('\n\n'), truncated, isEmpty: false };
220
+ }
@@ -59,4 +59,29 @@ export const logHandler = createRouter()
59
59
  data.branch,
60
60
  data.allBranches ?? false
61
61
  );
62
+ })
63
+
64
+ /**
65
+ * The repo's undo journal. Unlike `git log` this still lists commits that a
66
+ * reset, a branch delete or a rebase orphaned, so it is the recovery path for
67
+ * every destructive action the panel offers.
68
+ */
69
+ .http('git:reflog', {
70
+ data: t.Object({
71
+ projectId: t.String(),
72
+ limit: t.Optional(t.Number()),
73
+ repoPath: t.Optional(t.String())
74
+ }),
75
+ response: t.Array(t.Object({
76
+ hash: t.String(),
77
+ hashShort: t.String(),
78
+ selector: t.String(),
79
+ action: t.String(),
80
+ subject: t.String(),
81
+ date: t.String()
82
+ }))
83
+ }, async ({ data, conn }) => {
84
+ const { root } = requireProjectWorkspace(conn, data.projectId);
85
+ const cwd = resolveRepoCwd(root, data.repoPath);
86
+ return await gitService.getReflog(cwd, data.limit ?? 100);
62
87
  });
@@ -120,6 +120,11 @@ export const remoteHandler = createRouter()
120
120
  remote: t.Optional(t.String()),
121
121
  branch: t.Optional(t.String()),
122
122
  force: t.Optional(t.Boolean()),
123
+ /**
124
+ * Follow the branch's own upstream instead of `remote`. Default true —
125
+ * only set false for a deliberate "push this somewhere else" action.
126
+ */
127
+ useUpstream: t.Optional(t.Boolean()),
123
128
  repoPath: t.Optional(t.String())
124
129
  }),
125
130
  response: t.Object({
@@ -129,7 +134,59 @@ export const remoteHandler = createRouter()
129
134
  }, async ({ data, conn }) => {
130
135
  const { root } = requireProjectWorkspace(conn, data.projectId);
131
136
  const cwd = resolveRepoCwd(root, data.repoPath);
132
- return await gitService.push(cwd, data.remote, data.branch, data.force);
137
+ return await gitService.push(cwd, data.remote, data.branch, data.force, {
138
+ useUpstream: data.useUpstream ?? true
139
+ });
140
+ })
141
+
142
+ /** Where a push would actually land — drives the Push button's label. */
143
+ .http('git:push-target', {
144
+ data: t.Object({
145
+ projectId: t.String(),
146
+ branch: t.Optional(t.String()),
147
+ repoPath: t.Optional(t.String())
148
+ }),
149
+ response: t.Object({
150
+ remote: t.String(),
151
+ remoteBranch: t.String(),
152
+ hasUpstream: t.Boolean(),
153
+ isUrl: t.Boolean(),
154
+ branch: t.String()
155
+ })
156
+ }, async ({ data, conn }) => {
157
+ const { root } = requireProjectWorkspace(conn, data.projectId);
158
+ const cwd = resolveRepoCwd(root, data.repoPath);
159
+ return await gitService.getPushTarget(cwd, data.branch);
160
+ })
161
+
162
+ .http('git:set-upstream', {
163
+ data: t.Object({
164
+ projectId: t.String(),
165
+ branch: t.String({ minLength: 1 }),
166
+ remote: t.String({ minLength: 1 }),
167
+ remoteBranch: t.Optional(t.String()),
168
+ repoPath: t.Optional(t.String())
169
+ }),
170
+ response: t.Object({ ok: t.Boolean() })
171
+ }, async ({ data, conn }) => {
172
+ const { root } = requireProjectWorkspace(conn, data.projectId);
173
+ const cwd = resolveRepoCwd(root, data.repoPath);
174
+ await gitService.setUpstream(cwd, data.branch, data.remote, data.remoteBranch);
175
+ return { ok: true };
176
+ })
177
+
178
+ .http('git:unset-upstream', {
179
+ data: t.Object({
180
+ projectId: t.String(),
181
+ branch: t.String({ minLength: 1 }),
182
+ repoPath: t.Optional(t.String())
183
+ }),
184
+ response: t.Object({ ok: t.Boolean() })
185
+ }, async ({ data, conn }) => {
186
+ const { root } = requireProjectWorkspace(conn, data.projectId);
187
+ const cwd = resolveRepoCwd(root, data.repoPath);
188
+ await gitService.unsetUpstream(cwd, data.branch);
189
+ return { ok: true };
133
190
  })
134
191
 
135
192
  .http('git:add-remote', {
@@ -273,6 +330,23 @@ export const remoteHandler = createRouter()
273
330
  return await gitService.stashPop(cwd, data.index);
274
331
  })
275
332
 
333
+ .http('git:stash-apply', {
334
+ data: t.Object({
335
+ projectId: t.String(),
336
+ index: t.Optional(t.Number()),
337
+ repoPath: t.Optional(t.String())
338
+ }),
339
+ response: t.Object({
340
+ success: t.Boolean(),
341
+ hasConflicts: t.Boolean(),
342
+ message: t.String()
343
+ })
344
+ }, async ({ data, conn }) => {
345
+ const { root } = requireProjectWorkspace(conn, data.projectId);
346
+ const cwd = resolveRepoCwd(root, data.repoPath);
347
+ return await gitService.stashApply(cwd, data.index);
348
+ })
349
+
276
350
  .http('git:stash-drop', {
277
351
  data: t.Object({
278
352
  projectId: t.String(),
@@ -1 +1 @@
1
- import{_ as ce}from"./main-BofFsH8E.js";async function ot(s={}){var t,e=s,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope,o=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(o){const{createRequire:n}=await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[]);var l=n(import.meta.url)}var p=(n,c)=>{throw c},m=import.meta.url,z="";function _(n){return e.locateFile?e.locateFile(n,z):z+n}var x,A;if(o){var a=l("node:fs");m.startsWith("file:")&&(z=l("node:path").dirname(l("node:url").fileURLToPath(m))+"/"),A=n=>{n=u(n)?new URL(n):n;var c=a.readFileSync(n);return c},x=async(n,c=!0)=>{n=u(n)?new URL(n):n;var f=a.readFileSync(n,c?void 0:"utf8");return f},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),p=(n,c)=>{throw process.exitCode=n,c}}else if(r||i){try{z=new URL(".",m).href}catch{}x=async n=>{var c=await fetch(n,{credentials:"same-origin"});if(c.ok)return c.arrayBuffer();throw new Error(c.status+" : "+c.url)}}var R=console.log.bind(console),C=console.error.bind(console),U,M=!1,T,u=n=>n.startsWith("file://"),d,D,B=!1;function E(){var n=ae.buffer;e.HEAPU8=V=new Uint8Array(n),P=new Uint32Array(n),Q=new BigInt64Array(n),new BigUint64Array(n)}function te(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Me(e.preRun.shift());ze(ye)}function fe(){B=!0,L.m()}function Y(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)Be(e.postRun.shift());ze(ge)}function X(n){e.onAbort?.(n),n=`Aborted(${n})`,C(n),M=!0,n+=". Build with -sASSERTIONS for more info.";var c=new WebAssembly.RuntimeError(n);throw D?.(c),c}var J;function ne(){return e.locateFile?_("zipkit-engine.wasm"):new URL("/assets/zipkit-engine-CaR0t_Uy.wasm",import.meta.url).href}function re(n){if(n==J&&U)return new Uint8Array(U);if(A)return A(n);throw"both async and sync fetching of the wasm failed"}async function K(n){if(!U)try{var c=await x(n);return new Uint8Array(c)}catch{}return re(n)}async function F(n,c){try{var f=await K(n),h=await WebAssembly.instantiate(f,c);return h}catch(b){C(`failed to asynchronously prepare wasm: ${b}`),X(b)}}async function _e(n,c,f){if(!n&&!o)try{var h=fetch(c,{credentials:"same-origin"}),b=await WebAssembly.instantiateStreaming(h,f);return b}catch(v){C(`wasm streaming compile failed: ${v}`),C("falling back to ArrayBuffer instantiation")}return F(c,f)}function se(){var n={a:rt};return n}async function ie(){function n(v,k){return L=v.exports,L=st(L),nt(L),E(),L}function c(v){return n(v.instance)}var f=se();if(e.instantiateWasm)return new Promise((v,k)=>{e.instantiateWasm(f,(I,N)=>{v(n(I))})});J??=ne();var h=await _e(U,J,f),b=c(h);return b}class oe{name="ExitStatus";constructor(c){this.message=`Program terminated with exit(${c})`,this.status=c}}var Q,P,V,ze=n=>{for(;n.length>0;)n.shift()(e)},ge=[],Be=n=>ge.push(n),ye=[],Me=n=>ye.push(n),me=!0,be=globalThis.TextDecoder&&new TextDecoder,Ie=(n,c,f,h)=>{for(var b=c+f;n[c]&&!(c>=b);)++c;return c},we=(n,c=0,f,h)=>{c>>>=0;var b=Ie(n,c,f);if(b-c>16&&n.buffer&&be)return be.decode(n.subarray(c,b));for(var v="";c<b;){var k=n[c++];if(!(k&128)){v+=String.fromCharCode(k);continue}var I=n[c++]&63;if((k&224)==192){v+=String.fromCharCode((k&31)<<6|I);continue}var N=n[c++]&63;if((k&240)==224?k=(k&15)<<12|I<<6|N:k=(k&7)<<18|I<<12|N<<6|n[c++]&63,k<65536)v+=String.fromCharCode(k);else{var Te=k-65536;v+=String.fromCharCode(55296|Te>>10,56320|Te&1023)}}return v},he=(n,c,f)=>(n>>>=0,n?we(V,n,c):"");function We(n,c,f,h){return n>>>=0,c>>>=0,h>>>=0,X(`Assertion failed: ${he(n)}, at: `+[c?he(c):"unknown filename",f,h?he(h):"unknown function"])}var Le=()=>X(""),ve=0,Ne=()=>{me=!1,ve=0},O={},ke=n=>{if(n instanceof oe||n=="unwind")return T;p(1,n)},xe=()=>me||ve>0,Ae=n=>{T=n,xe()||(e.onExit?.(n),M=!0),p(n,new oe(n))},He=(n,c)=>{T=n,Ae(n)},Se=He,Ke=()=>{if(!xe())try{Se(T)}catch(n){ke(n)}},Fe=n=>{if(!M)try{return n()}catch(c){ke(c)}finally{Ke()}},Re=()=>performance.now(),Ve=(n,c)=>{if(O[n]&&(clearTimeout(O[n].id),delete O[n]),!c)return 0;var f=setTimeout(()=>{delete O[n],Fe(()=>Ce(n,Re()))},c);return O[n]={id:f,timeout_ms:c},0},qe=()=>Date.now(),$e=n=>n>=0&&n<=3;function je(n,c,f){if(f>>>=0,!$e(n))return 28;var h;n===0?h=qe():h=Re();var b=Math.round(h*1e3*1e3);return Q[f>>>3>>>0]=BigInt(b),0}var Ze=()=>4294901760,Ge=(n,c)=>Math.ceil(n/c)*c,Ye=n=>{var c=ae.buffer.byteLength,f=(n-c+65535)/65536|0;try{return ae.grow(f),E(),1}catch{}};function Xe(n){n>>>=0;var c=V.length,f=Ze();if(n>f)return!1;for(var h=1;h<=4;h*=2){var b=c*(1+.2/h);b=Math.min(b,n+100663296);var v=Math.min(f,Ge(Math.max(n,b),65536)),k=Ye(v);if(k)return!0}return!1}var Je=n=>52;function Qe(n,c,f,h){return 70}var Oe=[null,[],[]],et=(n,c)=>{var f=Oe[n];c===0||c===10?((n===1?R:C)(we(f)),f.length=0):f.push(c)};function tt(n,c,f,h){c>>>=0,f>>>=0,h>>>=0;for(var b=0,v=0;v<f;v++){var k=P[c>>>2>>>0],I=P[c+4>>>2>>>0];c+=8;for(var N=0;N<I;N++)et(n,V[k+N>>>0]);b+=I}return P[h>>>2>>>0]=b,0}if(e.noExitRuntime&&(me=e.noExitRuntime),e.print&&(R=e.print),e.printErr&&(C=e.printErr),e.wasmBinary&&(U=e.wasmBinary),e.arguments&&e.arguments,e.thisProgram&&e.thisProgram,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();var Ce,ae;function nt(n){e._zk_input_ptr=n.n,e._zk_result_ptr=n.o,e._zk_result_len=n.p,e._zk_gzip_compress=n.q,e._zk_gzip_decompress=n.r,e._zk_deflate_compress=n.s,e._zk_deflate_decompress=n.t,e._zk_zlib_compress=n.u,e._zk_zlib_decompress=n.v,e._zk_crc32=n.w,e._zk_lz4_compress=n.x,e._zk_lz4_decompress=n.y,e._zk_zstd_compress=n.z,e._zk_zstd_decompress=n.A,e._zk_brotli_compress=n.B,e._zk_brotli_decompress=n.C,e._zk_snappy_compress=n.D,e._zk_snappy_decompress=n.E,e._zk_zstd_max_compress=n.F,e._zk_set_aux=n.G,e._zk_zstd_train_dict=n.H,e._zk_zstd_compress_dict=n.I,e._zk_zstd_decompress_dict=n.J,e._zk_lzma_compress=n.K,e._zk_lzma_decompress=n.L,e._zk_xz_ok=n.M,e._zk_xz_compress=n.N,e._zk_xz_decompress=n.O,e._zk_lzma2_decompress=n.P,e._zk_bzip2_compress=n.Q,e._zk_bzip2_decompress=n.R,e._zk_qoi_encode=n.S,e._zk_qoi_decode=n.T,e._zk_frame_delta_encode=n.U,e._zk_frame_delta_decode=n.V,Ce=n.W,ae=n.l,n.__indirect_function_table}var rt={a:We,f:Le,e:Ne,k:Ve,h:je,c:Xe,b:Se,j:Je,g:Qe,i:tt,d:Ae};function st(n){n=Object.assign({},n);var c=h=>b=>h(b)>>>0,f=h=>()=>h()>>>0;return n._emscripten_stack_alloc=c(n._emscripten_stack_alloc),n.emscripten_stack_get_current=f(n.emscripten_stack_get_current),n}function it(){te();function n(){e.calledRun=!0,!M&&(fe(),d?.(e),e.onRuntimeInitialized?.(),Y())}e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1),n()},1)):n()}var L;return L=await ie(),it(),B?t=e:t=new Promise((n,c)=>{d=n,D=c}),t}class ue{m;constructor(t){this.m=t}static async load(){const t=await ot();return new ue(t)}call(t,e){const r=this.m,i=r._zk_input_ptr(e.length);r.HEAPU8.set(e,i),t(e.length);const o=r._zk_result_ptr(),l=r._zk_result_len()>>>0;return r.HEAPU8.slice(o,o+l)}gzipCompress(t,e=9){return this.call(r=>this.m._zk_gzip_compress(r,e),t)}gzipDecompress(t){return this.call(e=>this.m._zk_gzip_decompress(e),t)}deflateCompress(t,e=9){return this.call(r=>this.m._zk_deflate_compress(r,e),t)}deflateDecompress(t){return this.call(e=>this.m._zk_deflate_decompress(e,0),t)}zlibCompress(t,e=9){return this.call(r=>this.m._zk_zlib_compress(r,e),t)}zlibDecompress(t){return this.call(e=>this.m._zk_zlib_decompress(e,0),t)}crc32(t,e=0){const r=this.m,i=r._zk_input_ptr(t.length);return r.HEAPU8.set(t,i),r._zk_crc32(t.length,e>>>0)>>>0}lz4Compress(t){return this.call(e=>this.m._zk_lz4_compress(e),t)}lz4Decompress(t){return this.call(e=>this.m._zk_lz4_decompress(e),t)}zstdCompress(t,e=19){return this.call(r=>this.m._zk_zstd_compress(r,e),t)}zstdDecompress(t){return this.call(e=>this.m._zk_zstd_decompress(e),t)}brotliCompress(t,e=11){return this.call(r=>this.m._zk_brotli_compress(r,e),t)}brotliDecompress(t){return this.call(e=>this.m._zk_brotli_decompress(e),t)}snappyCompress(t){return this.call(e=>this.m._zk_snappy_compress(e),t)}snappyDecompress(t){return this.call(e=>this.m._zk_snappy_decompress(e),t)}zstdMaxCompress(t,e=22){return this.call(r=>this.m._zk_zstd_max_compress(r,e),t)}lzmaCompress(t,e=9){return this.call(r=>this.m._zk_lzma_compress(r,e),t)}lzmaDecompress(t){return this.call(e=>this.m._zk_lzma_decompress(e),t)}lzma2Decompress(t,e,r){return this.call(i=>this.m._zk_lzma2_decompress(i,e,r),t)}xzCompress(t,e=6){const r=this.call(i=>this.m._zk_xz_compress(i,e),t);if(!this.m._zk_xz_ok())throw new Error("xz compression failed");return r}xzDecompress(t){const e=this.call(r=>this.m._zk_xz_decompress(r),t);if(!this.m._zk_xz_ok())throw new Error("xz decompression failed (corrupt stream or unsupported filter)");return e}setAux(t){const e=this.m,r=e._zk_input_ptr(t.length);e.HEAPU8.set(t,r),e._zk_set_aux(t.length)}zstdTrainDict(t,e,r){const i=this.m,o=i._zk_input_ptr(t.length);i.HEAPU8.set(t,o),i._zk_zstd_train_dict(t.length,e,r);const l=i._zk_result_ptr(),p=i._zk_result_len()>>>0;return i.HEAPU8.slice(l,l+p)}zstdCompressDict(t,e=19){return this.call(r=>this.m._zk_zstd_compress_dict(r,e),t)}zstdDecompressDict(t){return this.call(e=>this.m._zk_zstd_decompress_dict(e),t)}bzip2Compress(t,e=9){return this.call(r=>this.m._zk_bzip2_compress(r,e),t)}bzip2Decompress(t){return this.call(e=>this.m._zk_bzip2_decompress(e),t)}qoiEncode(t,e,r,i){return this.call(o=>this.m._zk_qoi_encode(o,e,r,i),t)}qoiDecode(t){return this.call(e=>this.m._zk_qoi_decode(e),t)}frameDeltaEncode(t,e){return this.call(r=>this.m._zk_frame_delta_encode(r,e),t)}frameDeltaDecode(t,e){return this.call(r=>this.m._zk_frame_delta_decode(r,e),t)}}let at;function w(){return at??=ue.load()}const ct=Object.freeze(Object.defineProperty({__proto__:null,ZipKitEngine:ue,getEngine:w},Symbol.toStringTag,{value:"Module"}));class pe extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}}class ee extends Error{constructor(t){super(t),this.name="ZipKitError"}}function lt(s,t,e,r){return s===void 0||!Number.isFinite(s)?r:Math.max(t,Math.min(e,Math.round(s)))}function de(s){return s?.mode??"balanced"}function H(s,t,e,r){return lt(s?.level,t,e,r[de(s)])}function W(){return globalThis.Bun}function ut(s){if(s?.aborted)throw new pe}async function y(s,t,e){ut(t?.signal),t?.onProgress?.(0,0);const r=s();return t?.onProgress?.(1,e),r}function ft(s){return de(s)!=="ratio"&&!!W()?.gzipSync}async function _t(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ft(t))return y(()=>r.gzipSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.gzipCompress(s,e),t,s.length)}async function mt(s,t){const e=W();if(e?.gunzipSync)return y(()=>e.gunzipSync(s),t,s.length);const r=await w();return y(()=>r.gzipDecompress(s),t,s.length)}function ht(s){return de(s)!=="ratio"&&!!W()?.deflateSync}async function pt(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ht(t))return y(()=>r.deflateSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.deflateCompress(s,e),t,s.length)}async function dt(s,t){const e=W();if(e?.inflateSync)return y(()=>e.inflateSync(s),t,s.length);const r=await w();return y(()=>r.deflateDecompress(s),t,s.length)}async function zt(s,t){const e=await w(),r=H(t,0,9,{speed:1,balanced:6,ratio:9});return y(()=>e.zlibCompress(s,r),t,s.length)}async function gt(s,t){const e=await w();return y(()=>e.zlibDecompress(s),t,s.length)}async function yt(s,t){const e=H(t,1,22,{speed:1,balanced:3,ratio:19}),r=W();if(r?.zstdCompressSync)return y(()=>r.zstdCompressSync(s,{level:e}),t,s.length);const i=await w(),o=e>19?()=>i.zstdMaxCompress(s,e):()=>i.zstdCompress(s,e);return y(o,t,s.length)}async function bt(s,t){const e=W();if(e?.zstdDecompressSync)return y(()=>e.zstdDecompressSync(s),t,s.length);const r=await w();return y(()=>r.zstdDecompress(s),t,s.length)}async function wt(s,t){const e=await w();return y(()=>e.lz4Compress(s),t,s.length)}async function vt(s,t){const e=await w();return y(()=>e.lz4Decompress(s),t,s.length)}async function kt(s,t){const e=await w();return y(()=>e.snappyCompress(s),t,s.length)}async function xt(s,t){const e=await w();return y(()=>e.snappyDecompress(s),t,s.length)}async function At(s,t){const e=await w(),r=H(t,0,11,{speed:4,balanced:6,ratio:11});return y(()=>e.brotliCompress(s,r),t,s.length)}async function St(s,t){const e=await w();return y(()=>e.brotliDecompress(s),t,s.length)}async function Rt(s,t){const e=await w(),r=H(t,0,9,{speed:3,balanced:6,ratio:9});return y(()=>e.lzmaCompress(s,r),t,s.length)}async function Ct(s,t){const e=await w();return y(()=>e.lzmaDecompress(s),t,s.length)}async function Tt(s,t){const e=await w(),r=H(t,1,9,{speed:1,balanced:6,ratio:9});return y(()=>e.bzip2Compress(s,r),t,s.length)}async function Dt(s,t){const e=await w();return y(()=>e.bzip2Decompress(s),t,s.length)}const Pt={gzip:_t,deflate:pt,zlib:zt,zstd:yt,lz4:wt,snappy:kt,brotli:At,lzma:Rt,bzip2:Tt},Ut={gzip:mt,deflate:dt,zlib:gt,zstd:bt,lz4:vt,snappy:xt,brotli:St,lzma:Ct,bzip2:Dt};function Et(s,t,e){const r=Pt[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}function Bt(s,t,e){const r=Ut[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}const Mt=Object.freeze(Object.defineProperty({__proto__:null,compress:Et,decompressWith:Bt},Symbol.toStringTag,{value:"Module"})),It=new URL(import.meta.url.endsWith(".ts")?"./worker.ts":"./worker.js",import.meta.url);function Wt(){const s=globalThis.navigator?.hardwareConcurrency??4;return Math.max(1,Math.min(s,8))}async function Lt(){try{return await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[])}catch{return}}class Nt{size;workers=[];pending=new Map;next=0;seq=0;ready;usable=!0;refWhileBusy(){const t=this.pending.size>0;for(const e of this.workers)(t?e.ref:e.unref).call(e)}constructor(t={}){this.size=t.size??Wt()}async ensure(){return this.ready?this.ready:(this.ready=(async()=>{const t=await Lt();if(!t){this.usable=!1;return}for(let e=0;e<this.size;e++){const r=new t.Worker(It);r.on("message",i=>this.settle(i)),r.on("error",i=>this.failAll(i)),r.unref(),this.workers.push(r)}})(),this.ready)}settle(t){const e=this.pending.get(t.id);e&&(this.pending.delete(t.id),this.refWhileBusy(),e.signal&&e.onAbort&&e.signal.removeEventListener("abort",e.onAbort),t.ok&&t.result?e.resolve(t.result):e.reject(new Error(t.error??"Worker operation failed")))}failAll(t){for(const[,e]of this.pending)e.reject(t);this.pending.clear(),this.refWhileBusy()}async run(t,e,r,i,o,l,p){if(l?.aborted)throw new pe;if(await this.ensure(),!this.usable){if(t==="zipCompress"){const{getEngine:A}=await ce(async()=>{const{getEngine:R}=await Promise.resolve().then(()=>ct);return{getEngine:R}},void 0),a=await A();return p==="zstd"?a.zstdCompress(e,i??19):a.deflateCompress(e,i??6)}const{compress:_,decompressWith:x}=await ce(async()=>{const{compress:A,decompressWith:a}=await Promise.resolve().then(()=>Mt);return{compress:A,decompressWith:a}},void 0);return t==="compress"?_(e,r,{level:i,mode:o}):x(e,r)}const m=this.seq++,z=this.workers[this.next++%this.workers.length];return new Promise((_,x)=>{const A={resolve:_,reject:x,signal:l};l&&(A.onAbort=()=>{this.pending.delete(m),this.refWhileBusy(),x(new pe)},l.addEventListener("abort",A.onAbort,{once:!0})),this.pending.set(m,A),this.refWhileBusy();const a=e.slice(),R={id:m,kind:t,codec:r,level:i,mode:o,method:p,data:a};z.postMessage(R,[a.buffer])})}compress(t,e,r){return this.run("compress",t,e,r?.level,r?.mode,r?.signal)}decompress(t,e,r){return this.run("decompress",t,e,void 0,void 0,r?.signal)}zipCompress(t,e,r){return this.run("zipCompress",t,e,r,void 0,void 0,e)}async destroy(){this.failAll(new Error("Worker pool destroyed")),await Promise.all(this.workers.map(t=>t.terminate())),this.workers=[],this.ready=void 0}}let Ht;function Kt(){return Ht??=new Nt}function Ft(s){const e=(Math.max(1980,s.getFullYear())-1980&127)<<9|s.getMonth()+1<<5|s.getDate(),r=s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>1;return{date:e,time:r}}let g,$,j,Z,G;const Vt=new Uint32Array([16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,452984832,905969664]);function qt(){g=new Uint8Array(256);const s=new Uint8Array(256);let t=1,e=1;do t=t^t<<1^(t&128?283:0),t&=255,e^=e<<1,e^=e<<2,e^=e<<4,e&=255,e&128&&(e^=9),e&=255,s[t]=e;while(t!==1);g[0]=99;for(let r=0;r<256;r++){let i=s[r],o=i;for(let l=0;l<4;l++)o=(o<<1|o>>>7)&255,i^=o;i^=99,g[r]=r===0?99:i}$=new Uint32Array(256),j=new Uint32Array(256),Z=new Uint32Array(256),G=new Uint32Array(256);for(let r=0;r<256;r++){const i=g[r],o=$t(i),l=o^i;$[r]=(o<<24|i<<16|i<<8|l)>>>0,j[r]=(l<<24|o<<16|i<<8|i)>>>0,Z[r]=(i<<24|l<<16|o<<8|i)>>>0,G[r]=(i<<24|i<<16|l<<8|o)>>>0}}function $t(s){return(s<<1^(s&128?283:0))&255}class jt{rk;rounds;constructor(t){if(g||qt(),t.length!==16&&t.length!==24&&t.length!==32)throw new Error(`AES key must be 16/24/32 bytes, got ${t.length}`);const e=t.length/4;this.rounds=e+6;const r=4*(this.rounds+1),i=new Uint32Array(r);for(let o=0;o<e;o++)i[o]=(t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3])>>>0;for(let o=e;o<r;o++){let l=i[o-1];o%e===0?l=(De(l<<8|l>>>24)^Vt[o/e-1])>>>0:e>6&&o%e===4&&(l=De(l)),i[o]=(i[o-e]^l)>>>0}this.rk=i}encryptBlock(t,e,r,i){const o=this.rk;let l=(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])^o[0],p=(t[e+4]<<24|t[e+5]<<16|t[e+6]<<8|t[e+7])^o[1],m=(t[e+8]<<24|t[e+9]<<16|t[e+10]<<8|t[e+11])^o[2],z=(t[e+12]<<24|t[e+13]<<16|t[e+14]<<8|t[e+15])^o[3],_=4;for(let x=1;x<this.rounds;x++){const A=($[l>>>24&255]^j[p>>>16&255]^Z[m>>>8&255]^G[z&255]^o[_])>>>0,a=($[p>>>24&255]^j[m>>>16&255]^Z[z>>>8&255]^G[l&255]^o[_+1])>>>0,R=($[m>>>24&255]^j[z>>>16&255]^Z[l>>>8&255]^G[p&255]^o[_+2])>>>0,C=($[z>>>24&255]^j[l>>>16&255]^Z[p>>>8&255]^G[m&255]^o[_+3])>>>0;l=A,p=a,m=R,z=C,_+=4}r[i]=(g[l>>>24&255]^o[_]>>>24)&255,r[i+1]=(g[p>>>16&255]^o[_]>>>16)&255,r[i+2]=(g[m>>>8&255]^o[_]>>>8)&255,r[i+3]=(g[z&255]^o[_])&255,r[i+4]=(g[p>>>24&255]^o[_+1]>>>24)&255,r[i+5]=(g[m>>>16&255]^o[_+1]>>>16)&255,r[i+6]=(g[z>>>8&255]^o[_+1]>>>8)&255,r[i+7]=(g[l&255]^o[_+1])&255,r[i+8]=(g[m>>>24&255]^o[_+2]>>>24)&255,r[i+9]=(g[z>>>16&255]^o[_+2]>>>16)&255,r[i+10]=(g[l>>>8&255]^o[_+2]>>>8)&255,r[i+11]=(g[p&255]^o[_+2])&255,r[i+12]=(g[z>>>24&255]^o[_+3]>>>24)&255,r[i+13]=(g[l>>>16&255]^o[_+3]>>>16)&255,r[i+14]=(g[p>>>8&255]^o[_+3]>>>8)&255,r[i+15]=(g[m&255]^o[_+3])&255}}function De(s){return(g[s>>>24&255]<<24|g[s>>>16&255]<<16|g[s>>>8&255]<<8|g[s&255])>>>0}function Zt(s,t){const e=new Uint8Array(t.length),r=new Uint8Array(16),i=new Uint8Array(16);let o=1;for(let l=0;l<t.length;l+=16){r[0]=o&255,r[1]=o>>>8&255,r[2]=o>>>16&255,r[3]=o>>>24&255,s.encryptBlock(r,0,i,0);const p=Math.min(16,t.length-l);for(let m=0;m<p;m++)e[l+m]=t[l+m]^i[m];o++}return e}const Gt={1:16,2:24,3:32},Yt={1:8,2:12,3:16},Ee=10,Xt=1e3;function le(){const s=globalThis.crypto;if(!s?.subtle)throw new ee("WebCrypto (crypto.subtle) is required for ZIP AES encryption");return s.subtle}function Jt(s){const t=globalThis.crypto;if(!t?.getRandomValues)throw new ee("crypto.getRandomValues is required to create encrypted ZIPs");return t.getRandomValues(new Uint8Array(s))}async function Qt(s,t,e){const r=Gt[e],i=await le().importKey("raw",new TextEncoder().encode(s),"PBKDF2",!1,["deriveBits"]),o=await le().deriveBits({name:"PBKDF2",salt:t,iterations:Xt,hash:"SHA-1"},i,(r*2+2)*8),l=new Uint8Array(o);return{aesKey:l.subarray(0,r),macKey:l.subarray(r,r*2),verifier:l.subarray(r*2,r*2+2)}}async function Ot(s,t){const e=await le().importKey("raw",s,{name:"HMAC",hash:"SHA-1"},!1,["sign"]),r=await le().sign("HMAC",e,t);return new Uint8Array(r).subarray(0,Ee)}async function en(s,t,e=3){const r=Jt(Yt[e]),{aesKey:i,macKey:o,verifier:l}=await Qt(t,r,e),p=Zt(new jt(i),s),m=await Ot(o,p),z=new Uint8Array(r.length+2+p.length+Ee);return z.set(r,0),z.set(l,r.length),z.set(p,r.length+2),z.set(m,r.length+2+p.length),{payload:z,strength:e}}const tn=256*1024,nn=67324752,rn=33639248,sn=101010256,on=101075792,an=117853008,S=4294967295,q=65535,cn={store:0,deflate:8,zstd:93};class ln{buf=new Uint8Array(1024);view=new DataView(this.buf.buffer);len=0;grow(t){if(this.len+t<=this.buf.length)return;let e=this.buf.length*2;for(;e<this.len+t;)e*=2;const r=new Uint8Array(e);r.set(this.buf.subarray(0,this.len)),this.buf=r,this.view=new DataView(this.buf.buffer)}u16(t){this.grow(2),this.view.setUint16(this.len,t,!0),this.len+=2}u32(t){this.grow(4),this.view.setUint32(this.len,t>>>0,!0),this.len+=4}u64(t){this.grow(8),this.view.setBigUint64(this.len,BigInt(t),!0),this.len+=8}bytes(t){this.grow(t.length),this.buf.set(t,this.len),this.len+=t.length}done(){return this.buf.slice(0,this.len)}}function Pe(s,t,e){s.u16(39169),s.u16(7),s.u16(2),s.u16(17729),s.bytes(new Uint8Array([t])),s.u16(e)}async function un(s,t,e){if(t==="store")return s;const r=await w();if(t==="deflate")return r.deflateCompress(s,e??6);if(t==="zstd")return r.zstdCompress(s,e??19);throw new ee(`Unsupported ZIP method: ${t}`)}const Ue=new TextEncoder;async function _n(s,t={}){const e=await w(),r=s.reduce((u,d)=>u+d.data.length,0),o=t.parallel??(s.length>=2&&r>=tn)?Kt():void 0,l=s.map(u=>e.crc32(u.data));let p=0;const m=t.onProgress,z=await Promise.all(s.map(u=>{const d=u.method??"deflate",D=d==="store"?Promise.resolve(u.data):o?o.zipCompress(u.data,d,u.level??(d==="zstd"?19:6)):un(u.data,d,u.level);return m?D.then(B=>(m(++p,s.length),B)):D})),_=3,x=t.password?await Promise.all(z.map(u=>en(u,t.password,_))):void 0,A=x?x.map(u=>u.payload):z,a=new ln,R=[];let C=s.length>q;for(let u=0;u<s.length;u++){const d=s[u],D=d.method??"deflate",B=cn[D],E=x!==void 0,te=E?99:B,fe=2048|(E?1:0),Y=Ue.encode(d.name),X=d.comment?Ue.encode(d.comment):new Uint8Array(0),J=l[u],ne=E?0:J,re=A[u],K=d.data.length,F=re.length,_e=d.mtime===void 0?new Date:new Date(d.mtime),{date:se,time:ie}=Ft(_e),oe=d.unixPermissions!==void 0?(d.unixPermissions&65535)<<16:0,Q=a.len,P=C||K>S||F>S||Q>S;P&&(C=!0);const V=(P?20:0)+(E?11:0);a.u32(nn),a.u16(P?45:20),a.u16(fe),a.u16(te),a.u16(ie),a.u16(se),a.u32(ne),a.u32(P?S:F),a.u32(P?S:K),a.u16(Y.length),a.u16(V),a.bytes(Y),P&&(a.u16(1),a.u16(16),a.u64(K),a.u64(F)),E&&Pe(a,_,B),a.bytes(re),R.push({nameBytes:Y,commentBytes:X,method:te,actualMethod:B,encrypted:E,crc:ne,compSize:F,size:K,dosDate:se,dosTime:ie,offset:Q,externalAttrs:oe,zip64:P})}const U=a.len;for(const u of R){a.u32(rn),a.u16(u.zip64?45:20),a.u16(u.zip64?45:20),a.u16(2048|(u.encrypted?1:0)),a.u16(u.method),a.u16(u.dosTime),a.u16(u.dosDate),a.u32(u.crc);const d=u.zip64;a.u32(d?S:u.compSize),a.u32(d?S:u.size),a.u16(u.nameBytes.length);const D=[];d&&D.push(u.size,u.compSize,u.offset);const B=(d?4+D.length*8:0)+(u.encrypted?11:0);if(a.u16(B),a.u16(u.commentBytes.length),a.u16(0),a.u16(0),a.u32(u.externalAttrs),a.u32(d?S:u.offset),a.bytes(u.nameBytes),d){a.u16(1),a.u16(D.length*8);for(const E of D)a.u64(E)}u.encrypted&&Pe(a,3,u.actualMethod),a.bytes(u.commentBytes)}const M=a.len-U,T=R.length;if(C||T>q||M>S||U>S){const u=a.len;a.u32(on),a.u64(44),a.u16(45),a.u16(45),a.u32(0),a.u32(0),a.u64(T),a.u64(T),a.u64(M),a.u64(U),a.u32(an),a.u32(0),a.u64(u),a.u32(1)}return a.u32(sn),a.u16(0),a.u16(0),a.u16(T>q?q:T),a.u16(T>q?q:T),a.u32(M>S?S:M),a.u32(U>S?S:U),a.u16(0),a.done()}new TextDecoder("utf-8");export{pe as AbortError,Nt as WorkerPool,ue as ZipKitEngine,ee as ZipKitError,At as brotli,Tt as bzip2,Et as compress,Bt as decompressWith,pt as deflate,w as getEngine,mt as gunzip,_t as gzip,dt as inflate,wt as lz4,Rt as lzma,Kt as sharedPool,kt as snappy,St as unbrotli,Dt as unbzip2,vt as unlz4,Ct as unlzma,xt as unsnappy,gt as unzlib,bt as unzstd,_n as zip,zt as zlib,yt as zstd};
1
+ import{_ as ce}from"./main-Df1I3hnw.js";async function ot(s={}){var t,e=s,r=!!globalThis.window,i=!!globalThis.WorkerGlobalScope,o=globalThis.process?.versions?.node&&globalThis.process?.type!="renderer";if(o){const{createRequire:n}=await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[]);var l=n(import.meta.url)}var p=(n,c)=>{throw c},m=import.meta.url,z="";function _(n){return e.locateFile?e.locateFile(n,z):z+n}var x,A;if(o){var a=l("node:fs");m.startsWith("file:")&&(z=l("node:path").dirname(l("node:url").fileURLToPath(m))+"/"),A=n=>{n=u(n)?new URL(n):n;var c=a.readFileSync(n);return c},x=async(n,c=!0)=>{n=u(n)?new URL(n):n;var f=a.readFileSync(n,c?void 0:"utf8");return f},process.argv.length>1&&process.argv[1].replace(/\\/g,"/"),process.argv.slice(2),p=(n,c)=>{throw process.exitCode=n,c}}else if(r||i){try{z=new URL(".",m).href}catch{}x=async n=>{var c=await fetch(n,{credentials:"same-origin"});if(c.ok)return c.arrayBuffer();throw new Error(c.status+" : "+c.url)}}var R=console.log.bind(console),C=console.error.bind(console),U,M=!1,T,u=n=>n.startsWith("file://"),d,D,B=!1;function E(){var n=ae.buffer;e.HEAPU8=V=new Uint8Array(n),P=new Uint32Array(n),Q=new BigInt64Array(n),new BigUint64Array(n)}function te(){if(e.preRun)for(typeof e.preRun=="function"&&(e.preRun=[e.preRun]);e.preRun.length;)Me(e.preRun.shift());ze(ye)}function fe(){B=!0,L.m()}function Y(){if(e.postRun)for(typeof e.postRun=="function"&&(e.postRun=[e.postRun]);e.postRun.length;)Be(e.postRun.shift());ze(ge)}function X(n){e.onAbort?.(n),n=`Aborted(${n})`,C(n),M=!0,n+=". Build with -sASSERTIONS for more info.";var c=new WebAssembly.RuntimeError(n);throw D?.(c),c}var J;function ne(){return e.locateFile?_("zipkit-engine.wasm"):new URL("/assets/zipkit-engine-CaR0t_Uy.wasm",import.meta.url).href}function re(n){if(n==J&&U)return new Uint8Array(U);if(A)return A(n);throw"both async and sync fetching of the wasm failed"}async function K(n){if(!U)try{var c=await x(n);return new Uint8Array(c)}catch{}return re(n)}async function F(n,c){try{var f=await K(n),h=await WebAssembly.instantiate(f,c);return h}catch(b){C(`failed to asynchronously prepare wasm: ${b}`),X(b)}}async function _e(n,c,f){if(!n&&!o)try{var h=fetch(c,{credentials:"same-origin"}),b=await WebAssembly.instantiateStreaming(h,f);return b}catch(v){C(`wasm streaming compile failed: ${v}`),C("falling back to ArrayBuffer instantiation")}return F(c,f)}function se(){var n={a:rt};return n}async function ie(){function n(v,k){return L=v.exports,L=st(L),nt(L),E(),L}function c(v){return n(v.instance)}var f=se();if(e.instantiateWasm)return new Promise((v,k)=>{e.instantiateWasm(f,(I,N)=>{v(n(I))})});J??=ne();var h=await _e(U,J,f),b=c(h);return b}class oe{name="ExitStatus";constructor(c){this.message=`Program terminated with exit(${c})`,this.status=c}}var Q,P,V,ze=n=>{for(;n.length>0;)n.shift()(e)},ge=[],Be=n=>ge.push(n),ye=[],Me=n=>ye.push(n),me=!0,be=globalThis.TextDecoder&&new TextDecoder,Ie=(n,c,f,h)=>{for(var b=c+f;n[c]&&!(c>=b);)++c;return c},we=(n,c=0,f,h)=>{c>>>=0;var b=Ie(n,c,f);if(b-c>16&&n.buffer&&be)return be.decode(n.subarray(c,b));for(var v="";c<b;){var k=n[c++];if(!(k&128)){v+=String.fromCharCode(k);continue}var I=n[c++]&63;if((k&224)==192){v+=String.fromCharCode((k&31)<<6|I);continue}var N=n[c++]&63;if((k&240)==224?k=(k&15)<<12|I<<6|N:k=(k&7)<<18|I<<12|N<<6|n[c++]&63,k<65536)v+=String.fromCharCode(k);else{var Te=k-65536;v+=String.fromCharCode(55296|Te>>10,56320|Te&1023)}}return v},he=(n,c,f)=>(n>>>=0,n?we(V,n,c):"");function We(n,c,f,h){return n>>>=0,c>>>=0,h>>>=0,X(`Assertion failed: ${he(n)}, at: `+[c?he(c):"unknown filename",f,h?he(h):"unknown function"])}var Le=()=>X(""),ve=0,Ne=()=>{me=!1,ve=0},O={},ke=n=>{if(n instanceof oe||n=="unwind")return T;p(1,n)},xe=()=>me||ve>0,Ae=n=>{T=n,xe()||(e.onExit?.(n),M=!0),p(n,new oe(n))},He=(n,c)=>{T=n,Ae(n)},Se=He,Ke=()=>{if(!xe())try{Se(T)}catch(n){ke(n)}},Fe=n=>{if(!M)try{return n()}catch(c){ke(c)}finally{Ke()}},Re=()=>performance.now(),Ve=(n,c)=>{if(O[n]&&(clearTimeout(O[n].id),delete O[n]),!c)return 0;var f=setTimeout(()=>{delete O[n],Fe(()=>Ce(n,Re()))},c);return O[n]={id:f,timeout_ms:c},0},qe=()=>Date.now(),$e=n=>n>=0&&n<=3;function je(n,c,f){if(f>>>=0,!$e(n))return 28;var h;n===0?h=qe():h=Re();var b=Math.round(h*1e3*1e3);return Q[f>>>3>>>0]=BigInt(b),0}var Ze=()=>4294901760,Ge=(n,c)=>Math.ceil(n/c)*c,Ye=n=>{var c=ae.buffer.byteLength,f=(n-c+65535)/65536|0;try{return ae.grow(f),E(),1}catch{}};function Xe(n){n>>>=0;var c=V.length,f=Ze();if(n>f)return!1;for(var h=1;h<=4;h*=2){var b=c*(1+.2/h);b=Math.min(b,n+100663296);var v=Math.min(f,Ge(Math.max(n,b),65536)),k=Ye(v);if(k)return!0}return!1}var Je=n=>52;function Qe(n,c,f,h){return 70}var Oe=[null,[],[]],et=(n,c)=>{var f=Oe[n];c===0||c===10?((n===1?R:C)(we(f)),f.length=0):f.push(c)};function tt(n,c,f,h){c>>>=0,f>>>=0,h>>>=0;for(var b=0,v=0;v<f;v++){var k=P[c>>>2>>>0],I=P[c+4>>>2>>>0];c+=8;for(var N=0;N<I;N++)et(n,V[k+N>>>0]);b+=I}return P[h>>>2>>>0]=b,0}if(e.noExitRuntime&&(me=e.noExitRuntime),e.print&&(R=e.print),e.printErr&&(C=e.printErr),e.wasmBinary&&(U=e.wasmBinary),e.arguments&&e.arguments,e.thisProgram&&e.thisProgram,e.preInit)for(typeof e.preInit=="function"&&(e.preInit=[e.preInit]);e.preInit.length>0;)e.preInit.shift()();var Ce,ae;function nt(n){e._zk_input_ptr=n.n,e._zk_result_ptr=n.o,e._zk_result_len=n.p,e._zk_gzip_compress=n.q,e._zk_gzip_decompress=n.r,e._zk_deflate_compress=n.s,e._zk_deflate_decompress=n.t,e._zk_zlib_compress=n.u,e._zk_zlib_decompress=n.v,e._zk_crc32=n.w,e._zk_lz4_compress=n.x,e._zk_lz4_decompress=n.y,e._zk_zstd_compress=n.z,e._zk_zstd_decompress=n.A,e._zk_brotli_compress=n.B,e._zk_brotli_decompress=n.C,e._zk_snappy_compress=n.D,e._zk_snappy_decompress=n.E,e._zk_zstd_max_compress=n.F,e._zk_set_aux=n.G,e._zk_zstd_train_dict=n.H,e._zk_zstd_compress_dict=n.I,e._zk_zstd_decompress_dict=n.J,e._zk_lzma_compress=n.K,e._zk_lzma_decompress=n.L,e._zk_xz_ok=n.M,e._zk_xz_compress=n.N,e._zk_xz_decompress=n.O,e._zk_lzma2_decompress=n.P,e._zk_bzip2_compress=n.Q,e._zk_bzip2_decompress=n.R,e._zk_qoi_encode=n.S,e._zk_qoi_decode=n.T,e._zk_frame_delta_encode=n.U,e._zk_frame_delta_decode=n.V,Ce=n.W,ae=n.l,n.__indirect_function_table}var rt={a:We,f:Le,e:Ne,k:Ve,h:je,c:Xe,b:Se,j:Je,g:Qe,i:tt,d:Ae};function st(n){n=Object.assign({},n);var c=h=>b=>h(b)>>>0,f=h=>()=>h()>>>0;return n._emscripten_stack_alloc=c(n._emscripten_stack_alloc),n.emscripten_stack_get_current=f(n.emscripten_stack_get_current),n}function it(){te();function n(){e.calledRun=!0,!M&&(fe(),d?.(e),e.onRuntimeInitialized?.(),Y())}e.setStatus?(e.setStatus("Running..."),setTimeout(()=>{setTimeout(()=>e.setStatus(""),1),n()},1)):n()}var L;return L=await ie(),it(),B?t=e:t=new Promise((n,c)=>{d=n,D=c}),t}class ue{m;constructor(t){this.m=t}static async load(){const t=await ot();return new ue(t)}call(t,e){const r=this.m,i=r._zk_input_ptr(e.length);r.HEAPU8.set(e,i),t(e.length);const o=r._zk_result_ptr(),l=r._zk_result_len()>>>0;return r.HEAPU8.slice(o,o+l)}gzipCompress(t,e=9){return this.call(r=>this.m._zk_gzip_compress(r,e),t)}gzipDecompress(t){return this.call(e=>this.m._zk_gzip_decompress(e),t)}deflateCompress(t,e=9){return this.call(r=>this.m._zk_deflate_compress(r,e),t)}deflateDecompress(t){return this.call(e=>this.m._zk_deflate_decompress(e,0),t)}zlibCompress(t,e=9){return this.call(r=>this.m._zk_zlib_compress(r,e),t)}zlibDecompress(t){return this.call(e=>this.m._zk_zlib_decompress(e,0),t)}crc32(t,e=0){const r=this.m,i=r._zk_input_ptr(t.length);return r.HEAPU8.set(t,i),r._zk_crc32(t.length,e>>>0)>>>0}lz4Compress(t){return this.call(e=>this.m._zk_lz4_compress(e),t)}lz4Decompress(t){return this.call(e=>this.m._zk_lz4_decompress(e),t)}zstdCompress(t,e=19){return this.call(r=>this.m._zk_zstd_compress(r,e),t)}zstdDecompress(t){return this.call(e=>this.m._zk_zstd_decompress(e),t)}brotliCompress(t,e=11){return this.call(r=>this.m._zk_brotli_compress(r,e),t)}brotliDecompress(t){return this.call(e=>this.m._zk_brotli_decompress(e),t)}snappyCompress(t){return this.call(e=>this.m._zk_snappy_compress(e),t)}snappyDecompress(t){return this.call(e=>this.m._zk_snappy_decompress(e),t)}zstdMaxCompress(t,e=22){return this.call(r=>this.m._zk_zstd_max_compress(r,e),t)}lzmaCompress(t,e=9){return this.call(r=>this.m._zk_lzma_compress(r,e),t)}lzmaDecompress(t){return this.call(e=>this.m._zk_lzma_decompress(e),t)}lzma2Decompress(t,e,r){return this.call(i=>this.m._zk_lzma2_decompress(i,e,r),t)}xzCompress(t,e=6){const r=this.call(i=>this.m._zk_xz_compress(i,e),t);if(!this.m._zk_xz_ok())throw new Error("xz compression failed");return r}xzDecompress(t){const e=this.call(r=>this.m._zk_xz_decompress(r),t);if(!this.m._zk_xz_ok())throw new Error("xz decompression failed (corrupt stream or unsupported filter)");return e}setAux(t){const e=this.m,r=e._zk_input_ptr(t.length);e.HEAPU8.set(t,r),e._zk_set_aux(t.length)}zstdTrainDict(t,e,r){const i=this.m,o=i._zk_input_ptr(t.length);i.HEAPU8.set(t,o),i._zk_zstd_train_dict(t.length,e,r);const l=i._zk_result_ptr(),p=i._zk_result_len()>>>0;return i.HEAPU8.slice(l,l+p)}zstdCompressDict(t,e=19){return this.call(r=>this.m._zk_zstd_compress_dict(r,e),t)}zstdDecompressDict(t){return this.call(e=>this.m._zk_zstd_decompress_dict(e),t)}bzip2Compress(t,e=9){return this.call(r=>this.m._zk_bzip2_compress(r,e),t)}bzip2Decompress(t){return this.call(e=>this.m._zk_bzip2_decompress(e),t)}qoiEncode(t,e,r,i){return this.call(o=>this.m._zk_qoi_encode(o,e,r,i),t)}qoiDecode(t){return this.call(e=>this.m._zk_qoi_decode(e),t)}frameDeltaEncode(t,e){return this.call(r=>this.m._zk_frame_delta_encode(r,e),t)}frameDeltaDecode(t,e){return this.call(r=>this.m._zk_frame_delta_decode(r,e),t)}}let at;function w(){return at??=ue.load()}const ct=Object.freeze(Object.defineProperty({__proto__:null,ZipKitEngine:ue,getEngine:w},Symbol.toStringTag,{value:"Module"}));class pe extends Error{constructor(t="The operation was aborted"){super(t),this.name="AbortError"}}class ee extends Error{constructor(t){super(t),this.name="ZipKitError"}}function lt(s,t,e,r){return s===void 0||!Number.isFinite(s)?r:Math.max(t,Math.min(e,Math.round(s)))}function de(s){return s?.mode??"balanced"}function H(s,t,e,r){return lt(s?.level,t,e,r[de(s)])}function W(){return globalThis.Bun}function ut(s){if(s?.aborted)throw new pe}async function y(s,t,e){ut(t?.signal),t?.onProgress?.(0,0);const r=s();return t?.onProgress?.(1,e),r}function ft(s){return de(s)!=="ratio"&&!!W()?.gzipSync}async function _t(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ft(t))return y(()=>r.gzipSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.gzipCompress(s,e),t,s.length)}async function mt(s,t){const e=W();if(e?.gunzipSync)return y(()=>e.gunzipSync(s),t,s.length);const r=await w();return y(()=>r.gzipDecompress(s),t,s.length)}function ht(s){return de(s)!=="ratio"&&!!W()?.deflateSync}async function pt(s,t){const e=H(t,0,9,{speed:1,balanced:6,ratio:9}),r=W();if(ht(t))return y(()=>r.deflateSync(s,{level:e}),t,s.length);const i=await w();return y(()=>i.deflateCompress(s,e),t,s.length)}async function dt(s,t){const e=W();if(e?.inflateSync)return y(()=>e.inflateSync(s),t,s.length);const r=await w();return y(()=>r.deflateDecompress(s),t,s.length)}async function zt(s,t){const e=await w(),r=H(t,0,9,{speed:1,balanced:6,ratio:9});return y(()=>e.zlibCompress(s,r),t,s.length)}async function gt(s,t){const e=await w();return y(()=>e.zlibDecompress(s),t,s.length)}async function yt(s,t){const e=H(t,1,22,{speed:1,balanced:3,ratio:19}),r=W();if(r?.zstdCompressSync)return y(()=>r.zstdCompressSync(s,{level:e}),t,s.length);const i=await w(),o=e>19?()=>i.zstdMaxCompress(s,e):()=>i.zstdCompress(s,e);return y(o,t,s.length)}async function bt(s,t){const e=W();if(e?.zstdDecompressSync)return y(()=>e.zstdDecompressSync(s),t,s.length);const r=await w();return y(()=>r.zstdDecompress(s),t,s.length)}async function wt(s,t){const e=await w();return y(()=>e.lz4Compress(s),t,s.length)}async function vt(s,t){const e=await w();return y(()=>e.lz4Decompress(s),t,s.length)}async function kt(s,t){const e=await w();return y(()=>e.snappyCompress(s),t,s.length)}async function xt(s,t){const e=await w();return y(()=>e.snappyDecompress(s),t,s.length)}async function At(s,t){const e=await w(),r=H(t,0,11,{speed:4,balanced:6,ratio:11});return y(()=>e.brotliCompress(s,r),t,s.length)}async function St(s,t){const e=await w();return y(()=>e.brotliDecompress(s),t,s.length)}async function Rt(s,t){const e=await w(),r=H(t,0,9,{speed:3,balanced:6,ratio:9});return y(()=>e.lzmaCompress(s,r),t,s.length)}async function Ct(s,t){const e=await w();return y(()=>e.lzmaDecompress(s),t,s.length)}async function Tt(s,t){const e=await w(),r=H(t,1,9,{speed:1,balanced:6,ratio:9});return y(()=>e.bzip2Compress(s,r),t,s.length)}async function Dt(s,t){const e=await w();return y(()=>e.bzip2Decompress(s),t,s.length)}const Pt={gzip:_t,deflate:pt,zlib:zt,zstd:yt,lz4:wt,snappy:kt,brotli:At,lzma:Rt,bzip2:Tt},Ut={gzip:mt,deflate:dt,zlib:gt,zstd:bt,lz4:vt,snappy:xt,brotli:St,lzma:Ct,bzip2:Dt};function Et(s,t,e){const r=Pt[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}function Bt(s,t,e){const r=Ut[t];if(!r)throw new ee(`Unknown codec: ${t}`);return r(s,e)}const Mt=Object.freeze(Object.defineProperty({__proto__:null,compress:Et,decompressWith:Bt},Symbol.toStringTag,{value:"Module"})),It=new URL(import.meta.url.endsWith(".ts")?"./worker.ts":"./worker.js",import.meta.url);function Wt(){const s=globalThis.navigator?.hardwareConcurrency??4;return Math.max(1,Math.min(s,8))}async function Lt(){try{return await ce(()=>import("./__vite-browser-external-BIHI7g3E.js"),[])}catch{return}}class Nt{size;workers=[];pending=new Map;next=0;seq=0;ready;usable=!0;refWhileBusy(){const t=this.pending.size>0;for(const e of this.workers)(t?e.ref:e.unref).call(e)}constructor(t={}){this.size=t.size??Wt()}async ensure(){return this.ready?this.ready:(this.ready=(async()=>{const t=await Lt();if(!t){this.usable=!1;return}for(let e=0;e<this.size;e++){const r=new t.Worker(It);r.on("message",i=>this.settle(i)),r.on("error",i=>this.failAll(i)),r.unref(),this.workers.push(r)}})(),this.ready)}settle(t){const e=this.pending.get(t.id);e&&(this.pending.delete(t.id),this.refWhileBusy(),e.signal&&e.onAbort&&e.signal.removeEventListener("abort",e.onAbort),t.ok&&t.result?e.resolve(t.result):e.reject(new Error(t.error??"Worker operation failed")))}failAll(t){for(const[,e]of this.pending)e.reject(t);this.pending.clear(),this.refWhileBusy()}async run(t,e,r,i,o,l,p){if(l?.aborted)throw new pe;if(await this.ensure(),!this.usable){if(t==="zipCompress"){const{getEngine:A}=await ce(async()=>{const{getEngine:R}=await Promise.resolve().then(()=>ct);return{getEngine:R}},void 0),a=await A();return p==="zstd"?a.zstdCompress(e,i??19):a.deflateCompress(e,i??6)}const{compress:_,decompressWith:x}=await ce(async()=>{const{compress:A,decompressWith:a}=await Promise.resolve().then(()=>Mt);return{compress:A,decompressWith:a}},void 0);return t==="compress"?_(e,r,{level:i,mode:o}):x(e,r)}const m=this.seq++,z=this.workers[this.next++%this.workers.length];return new Promise((_,x)=>{const A={resolve:_,reject:x,signal:l};l&&(A.onAbort=()=>{this.pending.delete(m),this.refWhileBusy(),x(new pe)},l.addEventListener("abort",A.onAbort,{once:!0})),this.pending.set(m,A),this.refWhileBusy();const a=e.slice(),R={id:m,kind:t,codec:r,level:i,mode:o,method:p,data:a};z.postMessage(R,[a.buffer])})}compress(t,e,r){return this.run("compress",t,e,r?.level,r?.mode,r?.signal)}decompress(t,e,r){return this.run("decompress",t,e,void 0,void 0,r?.signal)}zipCompress(t,e,r){return this.run("zipCompress",t,e,r,void 0,void 0,e)}async destroy(){this.failAll(new Error("Worker pool destroyed")),await Promise.all(this.workers.map(t=>t.terminate())),this.workers=[],this.ready=void 0}}let Ht;function Kt(){return Ht??=new Nt}function Ft(s){const e=(Math.max(1980,s.getFullYear())-1980&127)<<9|s.getMonth()+1<<5|s.getDate(),r=s.getHours()<<11|s.getMinutes()<<5|s.getSeconds()>>1;return{date:e,time:r}}let g,$,j,Z,G;const Vt=new Uint32Array([16777216,33554432,67108864,134217728,268435456,536870912,1073741824,2147483648,452984832,905969664]);function qt(){g=new Uint8Array(256);const s=new Uint8Array(256);let t=1,e=1;do t=t^t<<1^(t&128?283:0),t&=255,e^=e<<1,e^=e<<2,e^=e<<4,e&=255,e&128&&(e^=9),e&=255,s[t]=e;while(t!==1);g[0]=99;for(let r=0;r<256;r++){let i=s[r],o=i;for(let l=0;l<4;l++)o=(o<<1|o>>>7)&255,i^=o;i^=99,g[r]=r===0?99:i}$=new Uint32Array(256),j=new Uint32Array(256),Z=new Uint32Array(256),G=new Uint32Array(256);for(let r=0;r<256;r++){const i=g[r],o=$t(i),l=o^i;$[r]=(o<<24|i<<16|i<<8|l)>>>0,j[r]=(l<<24|o<<16|i<<8|i)>>>0,Z[r]=(i<<24|l<<16|o<<8|i)>>>0,G[r]=(i<<24|i<<16|l<<8|o)>>>0}}function $t(s){return(s<<1^(s&128?283:0))&255}class jt{rk;rounds;constructor(t){if(g||qt(),t.length!==16&&t.length!==24&&t.length!==32)throw new Error(`AES key must be 16/24/32 bytes, got ${t.length}`);const e=t.length/4;this.rounds=e+6;const r=4*(this.rounds+1),i=new Uint32Array(r);for(let o=0;o<e;o++)i[o]=(t[4*o]<<24|t[4*o+1]<<16|t[4*o+2]<<8|t[4*o+3])>>>0;for(let o=e;o<r;o++){let l=i[o-1];o%e===0?l=(De(l<<8|l>>>24)^Vt[o/e-1])>>>0:e>6&&o%e===4&&(l=De(l)),i[o]=(i[o-e]^l)>>>0}this.rk=i}encryptBlock(t,e,r,i){const o=this.rk;let l=(t[e]<<24|t[e+1]<<16|t[e+2]<<8|t[e+3])^o[0],p=(t[e+4]<<24|t[e+5]<<16|t[e+6]<<8|t[e+7])^o[1],m=(t[e+8]<<24|t[e+9]<<16|t[e+10]<<8|t[e+11])^o[2],z=(t[e+12]<<24|t[e+13]<<16|t[e+14]<<8|t[e+15])^o[3],_=4;for(let x=1;x<this.rounds;x++){const A=($[l>>>24&255]^j[p>>>16&255]^Z[m>>>8&255]^G[z&255]^o[_])>>>0,a=($[p>>>24&255]^j[m>>>16&255]^Z[z>>>8&255]^G[l&255]^o[_+1])>>>0,R=($[m>>>24&255]^j[z>>>16&255]^Z[l>>>8&255]^G[p&255]^o[_+2])>>>0,C=($[z>>>24&255]^j[l>>>16&255]^Z[p>>>8&255]^G[m&255]^o[_+3])>>>0;l=A,p=a,m=R,z=C,_+=4}r[i]=(g[l>>>24&255]^o[_]>>>24)&255,r[i+1]=(g[p>>>16&255]^o[_]>>>16)&255,r[i+2]=(g[m>>>8&255]^o[_]>>>8)&255,r[i+3]=(g[z&255]^o[_])&255,r[i+4]=(g[p>>>24&255]^o[_+1]>>>24)&255,r[i+5]=(g[m>>>16&255]^o[_+1]>>>16)&255,r[i+6]=(g[z>>>8&255]^o[_+1]>>>8)&255,r[i+7]=(g[l&255]^o[_+1])&255,r[i+8]=(g[m>>>24&255]^o[_+2]>>>24)&255,r[i+9]=(g[z>>>16&255]^o[_+2]>>>16)&255,r[i+10]=(g[l>>>8&255]^o[_+2]>>>8)&255,r[i+11]=(g[p&255]^o[_+2])&255,r[i+12]=(g[z>>>24&255]^o[_+3]>>>24)&255,r[i+13]=(g[l>>>16&255]^o[_+3]>>>16)&255,r[i+14]=(g[p>>>8&255]^o[_+3]>>>8)&255,r[i+15]=(g[m&255]^o[_+3])&255}}function De(s){return(g[s>>>24&255]<<24|g[s>>>16&255]<<16|g[s>>>8&255]<<8|g[s&255])>>>0}function Zt(s,t){const e=new Uint8Array(t.length),r=new Uint8Array(16),i=new Uint8Array(16);let o=1;for(let l=0;l<t.length;l+=16){r[0]=o&255,r[1]=o>>>8&255,r[2]=o>>>16&255,r[3]=o>>>24&255,s.encryptBlock(r,0,i,0);const p=Math.min(16,t.length-l);for(let m=0;m<p;m++)e[l+m]=t[l+m]^i[m];o++}return e}const Gt={1:16,2:24,3:32},Yt={1:8,2:12,3:16},Ee=10,Xt=1e3;function le(){const s=globalThis.crypto;if(!s?.subtle)throw new ee("WebCrypto (crypto.subtle) is required for ZIP AES encryption");return s.subtle}function Jt(s){const t=globalThis.crypto;if(!t?.getRandomValues)throw new ee("crypto.getRandomValues is required to create encrypted ZIPs");return t.getRandomValues(new Uint8Array(s))}async function Qt(s,t,e){const r=Gt[e],i=await le().importKey("raw",new TextEncoder().encode(s),"PBKDF2",!1,["deriveBits"]),o=await le().deriveBits({name:"PBKDF2",salt:t,iterations:Xt,hash:"SHA-1"},i,(r*2+2)*8),l=new Uint8Array(o);return{aesKey:l.subarray(0,r),macKey:l.subarray(r,r*2),verifier:l.subarray(r*2,r*2+2)}}async function Ot(s,t){const e=await le().importKey("raw",s,{name:"HMAC",hash:"SHA-1"},!1,["sign"]),r=await le().sign("HMAC",e,t);return new Uint8Array(r).subarray(0,Ee)}async function en(s,t,e=3){const r=Jt(Yt[e]),{aesKey:i,macKey:o,verifier:l}=await Qt(t,r,e),p=Zt(new jt(i),s),m=await Ot(o,p),z=new Uint8Array(r.length+2+p.length+Ee);return z.set(r,0),z.set(l,r.length),z.set(p,r.length+2),z.set(m,r.length+2+p.length),{payload:z,strength:e}}const tn=256*1024,nn=67324752,rn=33639248,sn=101010256,on=101075792,an=117853008,S=4294967295,q=65535,cn={store:0,deflate:8,zstd:93};class ln{buf=new Uint8Array(1024);view=new DataView(this.buf.buffer);len=0;grow(t){if(this.len+t<=this.buf.length)return;let e=this.buf.length*2;for(;e<this.len+t;)e*=2;const r=new Uint8Array(e);r.set(this.buf.subarray(0,this.len)),this.buf=r,this.view=new DataView(this.buf.buffer)}u16(t){this.grow(2),this.view.setUint16(this.len,t,!0),this.len+=2}u32(t){this.grow(4),this.view.setUint32(this.len,t>>>0,!0),this.len+=4}u64(t){this.grow(8),this.view.setBigUint64(this.len,BigInt(t),!0),this.len+=8}bytes(t){this.grow(t.length),this.buf.set(t,this.len),this.len+=t.length}done(){return this.buf.slice(0,this.len)}}function Pe(s,t,e){s.u16(39169),s.u16(7),s.u16(2),s.u16(17729),s.bytes(new Uint8Array([t])),s.u16(e)}async function un(s,t,e){if(t==="store")return s;const r=await w();if(t==="deflate")return r.deflateCompress(s,e??6);if(t==="zstd")return r.zstdCompress(s,e??19);throw new ee(`Unsupported ZIP method: ${t}`)}const Ue=new TextEncoder;async function _n(s,t={}){const e=await w(),r=s.reduce((u,d)=>u+d.data.length,0),o=t.parallel??(s.length>=2&&r>=tn)?Kt():void 0,l=s.map(u=>e.crc32(u.data));let p=0;const m=t.onProgress,z=await Promise.all(s.map(u=>{const d=u.method??"deflate",D=d==="store"?Promise.resolve(u.data):o?o.zipCompress(u.data,d,u.level??(d==="zstd"?19:6)):un(u.data,d,u.level);return m?D.then(B=>(m(++p,s.length),B)):D})),_=3,x=t.password?await Promise.all(z.map(u=>en(u,t.password,_))):void 0,A=x?x.map(u=>u.payload):z,a=new ln,R=[];let C=s.length>q;for(let u=0;u<s.length;u++){const d=s[u],D=d.method??"deflate",B=cn[D],E=x!==void 0,te=E?99:B,fe=2048|(E?1:0),Y=Ue.encode(d.name),X=d.comment?Ue.encode(d.comment):new Uint8Array(0),J=l[u],ne=E?0:J,re=A[u],K=d.data.length,F=re.length,_e=d.mtime===void 0?new Date:new Date(d.mtime),{date:se,time:ie}=Ft(_e),oe=d.unixPermissions!==void 0?(d.unixPermissions&65535)<<16:0,Q=a.len,P=C||K>S||F>S||Q>S;P&&(C=!0);const V=(P?20:0)+(E?11:0);a.u32(nn),a.u16(P?45:20),a.u16(fe),a.u16(te),a.u16(ie),a.u16(se),a.u32(ne),a.u32(P?S:F),a.u32(P?S:K),a.u16(Y.length),a.u16(V),a.bytes(Y),P&&(a.u16(1),a.u16(16),a.u64(K),a.u64(F)),E&&Pe(a,_,B),a.bytes(re),R.push({nameBytes:Y,commentBytes:X,method:te,actualMethod:B,encrypted:E,crc:ne,compSize:F,size:K,dosDate:se,dosTime:ie,offset:Q,externalAttrs:oe,zip64:P})}const U=a.len;for(const u of R){a.u32(rn),a.u16(u.zip64?45:20),a.u16(u.zip64?45:20),a.u16(2048|(u.encrypted?1:0)),a.u16(u.method),a.u16(u.dosTime),a.u16(u.dosDate),a.u32(u.crc);const d=u.zip64;a.u32(d?S:u.compSize),a.u32(d?S:u.size),a.u16(u.nameBytes.length);const D=[];d&&D.push(u.size,u.compSize,u.offset);const B=(d?4+D.length*8:0)+(u.encrypted?11:0);if(a.u16(B),a.u16(u.commentBytes.length),a.u16(0),a.u16(0),a.u32(u.externalAttrs),a.u32(d?S:u.offset),a.bytes(u.nameBytes),d){a.u16(1),a.u16(D.length*8);for(const E of D)a.u64(E)}u.encrypted&&Pe(a,3,u.actualMethod),a.bytes(u.commentBytes)}const M=a.len-U,T=R.length;if(C||T>q||M>S||U>S){const u=a.len;a.u32(on),a.u64(44),a.u16(45),a.u16(45),a.u32(0),a.u32(0),a.u64(T),a.u64(T),a.u64(M),a.u64(U),a.u32(an),a.u32(0),a.u64(u),a.u32(1)}return a.u32(sn),a.u16(0),a.u16(0),a.u16(T>q?q:T),a.u16(T>q?q:T),a.u32(M>S?S:M),a.u32(U>S?S:U),a.u16(0),a.done()}new TextDecoder("utf-8");export{pe as AbortError,Nt as WorkerPool,ue as ZipKitEngine,ee as ZipKitError,At as brotli,Tt as bzip2,Et as compress,Bt as decompressWith,pt as deflate,w as getEngine,mt as gunzip,_t as gzip,dt as inflate,wt as lz4,Rt as lzma,Kt as sharedPool,kt as snappy,St as unbrotli,Dt as unbzip2,vt as unlz4,Ct as unlzma,xt as unsnappy,gt as unzlib,bt as unzstd,_n as zip,zt as zlib,yt as zstd};
@@ -1 +1 @@
1
- import{s as _,_ as d,r as s,a as u}from"./main-BofFsH8E.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-BofFsH8E.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};
1
+ import{s as _,_ as d,r as s,a as u}from"./main-Df1I3hnw.js";import{C as T,P as y,W as E,d as L,b as g,c as v,h as P,l as b,m as k,e as D,n as O,f as R,g as S,t as V}from"./main-Df1I3hnw.js";async function h(o,e={}){const i=e.loading===!1?void 0:_(o,e.loadingText??"Loading…"),[{Terminal:l},{FitAddon:c}]=await Promise.all([d(()=>import("./xterm-B-qIQCd3.js"),[]),d(()=>import("./addon-fit-DX4qG4td.js"),[])]).catch(r=>{throw i?.(),r}),a=new l({scrollback:e.scrollback??5e3,fontSize:e.fontSize??13,fontFamily:e.fontFamily??"ui-monospace, SFMono-Regular, Menlo, monospace",lineHeight:e.lineHeight??1,cursorBlink:e.cursorBlink??!1,cursorStyle:e.cursorStyle??"block",disableStdin:e.stdin!==!0,allowProposedApi:!0,convertEol:!0,theme:s(e.theme),...e.cols?{cols:e.cols}:{},...e.rows?{rows:e.rows}:{},...e.terminalOptions??{}}),t=e.fit===!1?void 0:new c;if(t&&a.loadAddon(t),e.clipboard)try{const{ClipboardAddon:r}=await d(()=>import("./addon-clipboard-wHJhZAA4.js"),[]);a.loadAddon(new r)}catch{}if(e.webLinks)try{const{WebLinksAddon:r}=await d(()=>import("./addon-web-links-DIbG5aQx.js"),[]);a.loadAddon(new r)}catch{}if(e.unicode11)try{const{Unicode11Addon:r}=await d(()=>import("./addon-unicode11-Bt8F3D7-.js"),[]);a.loadAddon(new r),a.unicode.activeVersion="11"}catch{}for(const r of e.addons??[])a.loadAddon(r);if(a.open(o),e.ligatures)try{const{LigaturesAddon:r}=await d(()=>import("./addon-ligatures-DpDY8N_X.js"),[]);a.loadAddon(new r)}catch{}const m=t?u({resize:async()=>{}},a,t,{debounceMs:e.fitDebounceMs??100}):void 0;e.onReady?.(a),i?.();let n=!1;return{terminal:a,fitAddon:t,write:r=>a.write(r),clear:()=>{a.clear(),a.reset()},fit:()=>t?.fit(),setTheme:r=>{a.options.theme=s(r)},dispose(){n||(n=!0,m?.(),a.dispose())}}}export{T as ClientSession,y as PtyKitClient,E as WsCore,u as attachFit,L as darkTheme,g as defaultPersistence,v as draculaTheme,P as hostSocket,b as lightTheme,k as matrixTheme,D as mountTerminal,h as mountViewer,O as nordTheme,s as resolveTheme,_ as showLoadingOverlay,R as solarizedDarkTheme,S as solarizedLightTheme,V as themes};