sliccy 2.3.1 → 2.4.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/README.md +1 -1
- package/dist/ui/assets/{es-C70AgaBB.js → es-6oFxNVOv.js} +1 -1
- package/dist/ui/assets/fs-CFxFn45v.js +3 -0
- package/dist/ui/assets/{index-oz1QVZKm.js → index-BxvCGJ1l.js} +163 -163
- package/dist/ui/assets/{skills-CTCIxQqH.js → skills-DBBQyHko.js} +1 -1
- package/dist/ui/index.html +3 -3
- package/dist/ui/packages/webapp/index.html +3 -3
- package/package.json +1 -1
- package/dist/ui/assets/fs-bsu2i7du.js +0 -3
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import{r as e}from"./chunk-jRWAZmH_.js";import{a as t,c as n,d as r,f as i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./constants-DdIXxN9e.js";import"./fs-
|
|
1
|
+
import{r as e}from"./chunk-jRWAZmH_.js";import{a as t,c as n,d as r,f as i,l as a,n as o,o as s,r as c,s as l,t as u,u as d}from"./constants-DdIXxN9e.js";import"./fs-CFxFn45v.js";import{r as f,t as p}from"./path-utils-CNNVZ3-O.js";function m(e){let t={},n=e.split(`
|
|
2
2
|
`),r=null,i=!1,a={},o=null;for(let e of n){let n=e.trim();if(!n||n.startsWith(`#`))continue;if(n.startsWith(`- `)){let e=n.slice(2).trim();i&&o?o.push(e):r&&r.push(e);continue}let s=n.indexOf(`:`);if(s===-1)continue;let c=n.slice(0,s).trim(),l=n.slice(s+1).trim(),u=e.search(/\S/);if(c===`structured`){i=!0,a={},t.structured=a;continue}if(i&&u>=2){if(u>=4&&o)continue;l===``||l===`[]`?(o=[],a[c]=o):(a[c]=l,o=null);continue}u===0&&(i=!1),l===``||l===`[]`?(r=[],t[c]=r):(t[c]=l,r=null)}return t}function h(e,t=u){let n=m(e);if(!n.skill||typeof n.skill!=`string`)throw Error(`Invalid manifest: missing 'skill' field in ${t}`);if(!n.version||typeof n.version!=`string`)throw Error(`Invalid manifest: missing 'version' field in ${t}`);return{skill:n.skill,version:n.version,description:n.description||``,adds:n.adds||[],modifies:n.modifies||[],structured:n.structured,conflicts:n.conflicts||[],depends:n.depends||[],test:n.test,author:n.author}}async function g(e,t){let n=`${t}/${u}`;return h(await e.readTextFile(n),n)}function _(e,t){let n=(e.depends||[]).filter(e=>!t.includes(e));return{ok:n.length===0,missing:n}}function v(e,t){let n=(e.conflicts||[]).filter(e=>t.includes(e));return{ok:n.length===0,conflicting:n}}var y=/^[A-Za-z0-9][A-Za-z0-9._-]*$/,b=class extends Error{};function x(e){return new TextDecoder().decode(e)}function S(e){let t=e.replace(/\\/g,`/`);if(!t||t.endsWith(`/`))return null;if(t.startsWith(`/`)||/^[A-Za-z]:\//.test(t))throw Error(`Blocked suspicious path "${e}".`);let n=t.split(`/`);if(n.some(e=>e===``||e===`.`||e===`..`))throw Error(`Blocked suspicious path "${e}".`);return n.join(`/`)}function ee(e){if(!y.test(e))throw Error(`Invalid manifest: skill name "${e}" must be a simple directory name.`)}function C(e){let t=[];for(let[n,r]of Object.entries(e)){let e=S(n);e&&t.push({originalPath:n,path:e,bytes:r})}return t}function w(e){let t=e.filter(e=>e.path===`manifest.yaml`||e.path.endsWith(`/manifest.yaml`));if(t.length===0)throw Error(`Skill archive is missing ${u}.`);if(t.length>1)throw Error(`Skill archive contains multiple ${u} files.`);return t[0]}function T(e){let t=0,n=0;return i(e,{filter(e){if(t++,t>1e3)throw new b(`Skill archives may contain at most ${o} entries.`);if(n+=e.originalSize,n>52428800)throw new b(`Skill archives must expand to 50 MB or smaller after extraction.`);return!0}})}function E(e){return p(r,`.${e}.tmp-${`${Date.now()}-${Math.random().toString(16).slice(2,8)}`}`)}async function D(e,t){if(!t.name.toLowerCase().endsWith(`.skill`))throw Error(`Only ${l} archives can be installed with drag and drop.`);if(t.size>52428800)throw Error(`Skill archives must be 50 MB or smaller.`);let n;try{n=T(new Uint8Array(await t.arrayBuffer()))}catch(e){if(e instanceof b)throw e;let t=e instanceof Error?e.message:String(e);throw Error(`Invalid .skill archive: ${t}`)}let i=C(n),a=w(i),o=h(x(a.bytes),a.path);ee(o.skill);let s=p(r,o.skill);if(await e.exists(s))throw Error(`Skill "${o.skill}" already exists at ${s}.`);let c=E(o.skill),d=a.path===`manifest.yaml`?``:a.path.slice(0,-(u.length+1));await e.mkdir(c,{recursive:!0});try{let t=0;for(let n of i){if(d&&(n.path===d||!n.path.startsWith(`${d}/`)))continue;let r=d?n.path.slice(d.length+1):n.path;if(!r)continue;let i=p(c,r),{dir:a}=f(i);a!==`/`&&await e.mkdir(a,{recursive:!0}),await e.writeFile(i,n.bytes),t++}return await e.rename(c,s),{skillName:o.skill,destinationPath:s,fileCount:t}}catch(t){throw await e.exists(c)&&await e.rm(c,{recursive:!0}),t}}var O=`/${a}/${d}`;async function k(e){try{await e.mkdir(`/${a}`)}catch{}try{await e.stat(O)}catch{let t={version:s,applied_skills:[]};await e.writeFile(O,JSON.stringify(t,null,2))}}async function A(e){try{let t=await e.readTextFile(O);return JSON.parse(t)}catch(e){if(typeof e==`object`&&e&&e.code===`ENOENT`)return{version:s,applied_skills:[]};throw e}}async function j(e,t){await k(e),await e.writeFile(O,JSON.stringify(t,null,2))}async function M(e){return(await A(e)).applied_skills.map(e=>e.name)}async function N(e,t){let n=await A(e);n.applied_skills=n.applied_skills.filter(e=>e.name!==t.name),n.applied_skills.push(t),await j(e,n)}async function te(e,t){let n=await A(e);n.applied_skills=n.applied_skills.filter(e=>e.name!==t),await j(e,n)}async function P(e){let t=new TextEncoder().encode(e),n=await crypto.subtle.digest(`SHA-256`,t);return Array.from(new Uint8Array(n)).map(e=>e.toString(16).padStart(2,`0`)).join(``)}function F(e){return e.startsWith(`/`)?{valid:!1,error:`Absolute path not allowed: ${e}`}:e.split(`/`).some(e=>e===`..`)?{valid:!1,error:`Path traversal not allowed: ${e}`}:e.includes(`%2e%2e`)||e.includes(`%2E%2E`)?{valid:!1,error:`Encoded path traversal not allowed: ${e}`}:{valid:!0}}async function I(e,t){let n=t.split(`/`).filter(Boolean),r=``;for(let t of n){r+=`/`+t;try{await e.mkdir(r)}catch{}}}async function L(e,t,n=`/workspace/skills`){let r=`${n}/${t}`;await k(e);let i;try{i=await g(e,r)}catch(e){return{success:!1,skill:t,version:`unknown`,error:`Failed to read manifest: ${e instanceof Error?e.message:String(e)}`}}if(i.skill!==t)return{success:!1,skill:t,version:i.version,error:`Manifest skill name "${i.skill}" does not match directory name "${t}"`};let a=await M(e);if(a.includes(i.skill))return{success:!1,skill:i.skill,version:i.version,error:`Skill "${i.skill}" is already installed`};let o=_(i,a);if(!o.ok)return{success:!1,skill:i.skill,version:i.version,error:`Missing dependencies: ${o.missing.join(`, `)}`};let s=v(i,a);if(!s.ok)return{success:!1,skill:i.skill,version:i.version,error:`Conflicting skills: ${s.conflicting.join(`, `)}`};let c={},l=[];try{if(i.adds&&i.adds.length>0)for(let t of i.adds){let n=F(t);if(!n.valid)return{success:!1,skill:i.skill,version:i.version,error:n.error};let a=`${r}/add/${t}`,o=`/${t}`;try{let n=o.substring(0,o.lastIndexOf(`/`));n&&await I(e,n),await e.copyFile(a,o),l.push(t),c[t]=await P(await e.readTextFile(o))}catch(e){return{success:!1,skill:i.skill,version:i.version,error:`Failed to copy ${t}: ${e instanceof Error?e.message:String(e)}`}}}if(i.modifies&&i.modifies.length>0)for(let t of i.modifies){let n=F(t);if(!n.valid)return{success:!1,skill:i.skill,version:i.version,error:n.error};let a=`${r}/modify/${t}`;try{let n=await e.readTextFile(a),r=``;try{r=await e.readTextFile(`/${t}`)}catch{}let i;if(n.includes(`// APPEND_AFTER:`)){let e=n.split(`
|
|
3
3
|
`),t=e.find(e=>e.includes(`// APPEND_AFTER:`))?.split(`// APPEND_AFTER:`)[1]?.trim(),a=e.filter(e=>!e.includes(`// APPEND_AFTER:`)).join(`
|
|
4
4
|
`);if(t&&r.includes(t)){let e=r.indexOf(t)+t.length,n=r.indexOf(`
|
package/dist/ui/index.html
CHANGED
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>slicc</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="/logos/sliccy-color-1scoops-32x32.png" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BxvCGJ1l.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-jRWAZmH_.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-D4M6sveU.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/logger-B-No_qN_.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/path-utils-CNNVZ3-O.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/fs-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/fs-CFxFn45v.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/env-api-keys-7VVTY3n7.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/simple-options-GPCv4BUJ.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/json-parse-Dn8fsQhn.js">
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<link rel="modulepreload" crossorigin href="/assets/cdp-CsCvDwW3.js">
|
|
23
23
|
<link rel="modulepreload" crossorigin href="/assets/db-CmHnV4DS.js">
|
|
24
24
|
<link rel="modulepreload" crossorigin href="/assets/magick-wasm-DA8eLvGf.js">
|
|
25
|
-
<link rel="modulepreload" crossorigin href="/assets/skills-
|
|
25
|
+
<link rel="modulepreload" crossorigin href="/assets/skills-DBBQyHko.js">
|
|
26
26
|
<link rel="stylesheet" crossorigin href="/assets/index-Bj1XpXDE.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
|
@@ -5,12 +5,12 @@
|
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>slicc</title>
|
|
7
7
|
<link rel="icon" type="image/png" href="/logos/sliccy-color-1scoops-32x32.png" />
|
|
8
|
-
<script type="module" crossorigin src="/assets/index-
|
|
8
|
+
<script type="module" crossorigin src="/assets/index-BxvCGJ1l.js"></script>
|
|
9
9
|
<link rel="modulepreload" crossorigin href="/assets/chunk-jRWAZmH_.js">
|
|
10
10
|
<link rel="modulepreload" crossorigin href="/assets/preload-helper-D4M6sveU.js">
|
|
11
11
|
<link rel="modulepreload" crossorigin href="/assets/logger-B-No_qN_.js">
|
|
12
12
|
<link rel="modulepreload" crossorigin href="/assets/path-utils-CNNVZ3-O.js">
|
|
13
|
-
<link rel="modulepreload" crossorigin href="/assets/fs-
|
|
13
|
+
<link rel="modulepreload" crossorigin href="/assets/fs-CFxFn45v.js">
|
|
14
14
|
<link rel="modulepreload" crossorigin href="/assets/env-api-keys-7VVTY3n7.js">
|
|
15
15
|
<link rel="modulepreload" crossorigin href="/assets/simple-options-GPCv4BUJ.js">
|
|
16
16
|
<link rel="modulepreload" crossorigin href="/assets/json-parse-Dn8fsQhn.js">
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
<link rel="modulepreload" crossorigin href="/assets/cdp-CsCvDwW3.js">
|
|
23
23
|
<link rel="modulepreload" crossorigin href="/assets/db-CmHnV4DS.js">
|
|
24
24
|
<link rel="modulepreload" crossorigin href="/assets/magick-wasm-DA8eLvGf.js">
|
|
25
|
-
<link rel="modulepreload" crossorigin href="/assets/skills-
|
|
25
|
+
<link rel="modulepreload" crossorigin href="/assets/skills-DBBQyHko.js">
|
|
26
26
|
<link rel="stylesheet" crossorigin href="/assets/index-Bj1XpXDE.css">
|
|
27
27
|
</head>
|
|
28
28
|
<body>
|
package/package.json
CHANGED
|
@@ -1,3 +0,0 @@
|
|
|
1
|
-
import{a as e,n as t,o as n,r,t as i}from"./chunk-jRWAZmH_.js";import{t as a}from"./logger-B-No_qN_.js";import{n as o,r as s,t as c}from"./path-utils-CNNVZ3-O.js";var l=i(((e,t)=>{t.exports=n;function n(e){var t,n;if(typeof e!=`function`)throw Error(`expected a function but got `+e);return function(){return t?n:(t=!0,n=e.apply(this,arguments),n)}}})),u=i((()=>{(function(e){function t(e,t){var n;return n=e instanceof Buffer?e:Buffer.from(e.buffer,e.byteOffset,e.byteLength),n.toString(t)}var n=function(e){return Buffer.from(e)};function r(e){for(var t=0,n=Math.min(256*256,e.length+1),r=new Uint16Array(n),i=[],a=0;;){var o=t<e.length;if(!o||a>=n-1){var s=r.subarray(0,a);if(i.push(String.fromCharCode.apply(null,s)),!o)return i.join(``);e=e.subarray(t),t=0,a=0}var c=e[t++];if(!(c&128))r[a++]=c;else if((c&224)==192){var l=e[t++]&63;r[a++]=(c&31)<<6|l}else if((c&240)==224){var l=e[t++]&63,u=e[t++]&63;r[a++]=(c&31)<<12|l<<6|u}else if((c&248)==240){var l=e[t++]&63,u=e[t++]&63,d=e[t++]&63,f=(c&7)<<18|l<<12|u<<6|d;f>65535&&(f-=65536,r[a++]=f>>>10&1023|55296,f=56320|f&1023),r[a++]=f}}}function i(e){for(var t=0,n=e.length,r=0,i=Math.max(32,n+(n>>>1)+7),a=new Uint8Array(i>>>3<<3);t<n;){var o=e.charCodeAt(t++);if(o>=55296&&o<=56319){if(t<n){var s=e.charCodeAt(t);(s&64512)==56320&&(++t,o=((o&1023)<<10)+(s&1023)+65536)}if(o>=55296&&o<=56319)continue}if(r+4>a.length){i+=8,i*=1+t/e.length*2,i=i>>>3<<3;var c=new Uint8Array(i);c.set(a),a=c}if(!(o&4294967168)){a[r++]=o;continue}else if(!(o&4294965248))a[r++]=o>>>6&31|192;else if(!(o&4294901760))a[r++]=o>>>12&15|224,a[r++]=o>>>6&63|128;else if(!(o&4292870144))a[r++]=o>>>18&7|240,a[r++]=o>>>12&63|128,a[r++]=o>>>6&63|128;else continue;a[r++]=o&63|128}return a.slice?a.slice(0,r):a.subarray(0,r)}var a=`Failed to `,o=function(e,t,n){if(e)throw Error(`${a}${t}: the '${n}' option is unsupported.`)},s=typeof Buffer==`function`&&Buffer.from,c=s?n:i;function l(){this.encoding=`utf-8`}l.prototype.encode=function(e,t){return o(t&&t.stream,`encode`,`stream`),c(e)};function u(e){var t;try{var n=new Blob([e],{type:`text/plain;charset=UTF-8`});t=URL.createObjectURL(n);var r=new XMLHttpRequest;return r.open(`GET`,t,!1),r.send(),r.responseText}finally{t&&URL.revokeObjectURL(t)}}var d=!s&&typeof Blob==`function`&&typeof URL==`function`&&typeof URL.createObjectURL==`function`,f=[`utf-8`,`utf8`,`unicode-1-1-utf-8`],p=r;s?p=t:d&&(p=function(e){try{return u(e)}catch{return r(e)}});var m=`construct 'TextDecoder'`,h=`${a} ${m}: the `;function g(e,t){o(t&&t.fatal,m,`fatal`),e||=`utf-8`;var n;if(n=s?Buffer.isEncoding(e):f.indexOf(e.toLowerCase())!==-1,!n)throw RangeError(`${h} encoding label provided ('${e}') is invalid.`);this.encoding=e,this.fatal=!1,this.ignoreBOM=!1}g.prototype.decode=function(e,t){o(t&&t.stream,`decode`,`stream`);var n;return n=e instanceof Uint8Array?e:e.buffer instanceof ArrayBuffer?new Uint8Array(e.buffer):new Uint8Array(e),p(n,this.encoding)},e.TextEncoder=e.TextEncoder||l,e.TextDecoder=e.TextDecoder||g})(typeof window<`u`?window:typeof globalThis<`u`?globalThis:void 0)})),d=i(((e,t)=>{u(),t.exports={encode:e=>new TextEncoder().encode(e),decode:e=>new TextDecoder().decode(e)}})),f=i(((e,t)=>{t.exports=n;function n(e,t,n){var r;return function(){if(!t)return e.apply(this,arguments);var i=this,a=arguments,o=n&&!r;if(clearTimeout(r),r=setTimeout(function(){if(r=null,!o)return e.apply(i,a)},t),o)return e.apply(this,arguments)}}})),p=i(((e,t)=>{function n(e){if(e.length===0)return`.`;let t=a(e);return t=t.reduce(c,[]),i(...t)}function r(...e){let t=``;for(let r of e)t=r.startsWith(`/`)?r:n(i(t,r));return t}function i(...e){if(e.length===0)return``;let t=e.join(`/`);return t=t.replace(/\/{2,}/g,`/`),t}function a(e){if(e.length===0)return[];if(e===`/`)return[`/`];let t=e.split(`/`);return t[t.length-1]===``&&t.pop(),e[0]===`/`?t[0]=`/`:t[0]!==`.`&&t.unshift(`.`),t}function o(e){let t=e.lastIndexOf(`/`);if(t===-1)throw Error(`Cannot get dirname of "${e}"`);return t===0?`/`:e.slice(0,t)}function s(e){if(e===`/`)throw Error(`Cannot get basename of "${e}"`);let t=e.lastIndexOf(`/`);return t===-1?e:e.slice(t+1)}function c(e,t){if(e.length===0)return e.push(t),e;if(t===`.`)return e;if(t===`..`){if(e.length===1){if(e[0]===`/`)throw Error(`Unable to normalize path - traverses above root directory`);if(e[0]===`.`)return e.push(t),e}return e[e.length-1]===`..`?(e.push(`..`),e):(e.pop(),e)}return e.push(t),e}t.exports={join:i,normalize:n,split:a,basename:s,dirname:o,resolve:r}})),m=i(((e,t)=>{function n(e){return class extends Error{constructor(...t){super(...t),this.code=e,this.message?this.message=e+`: `+this.message:this.message=e}}}t.exports={EEXIST:n(`EEXIST`),ENOENT:n(`ENOENT`),ENOTDIR:n(`ENOTDIR`),ENOTEMPTY:n(`ENOTEMPTY`),ETIMEDOUT:n(`ETIMEDOUT`),EISDIR:n(`EISDIR`)}})),h=i(((e,t)=>{var n=p(),{EEXIST:r,ENOENT:i,ENOTDIR:a,ENOTEMPTY:o,EISDIR:s}=m(),c=0;t.exports=class{constructor(){}_makeRoot(e=new Map){return e.set(c,{mode:511,type:`dir`,size:0,ino:0,mtimeMs:Date.now()}),e}activate(e=null){e===null?this._root=new Map([[`/`,this._makeRoot()]]):typeof e==`string`?this._root=new Map([[`/`,this._makeRoot(this.parse(e))]]):this._root=e}get activated(){return!!this._root}deactivate(){this._root=void 0}size(){return this._countInodes(this._root.get(`/`))-1}_countInodes(e){let t=1;for(let[n,r]of e)n!==c&&(t+=this._countInodes(r));return t}autoinc(){return this._maxInode(this._root.get(`/`))+1}_maxInode(e){let t=e.get(c).ino;for(let[n,r]of e)n!==c&&(t=Math.max(t,this._maxInode(r)));return t}print(e=this._root.get(`/`)){let t=``,n=(e,r)=>{for(let[i,a]of e){if(i===0)continue;let e=a.get(c),o=e.mode.toString(8);t+=`${` `.repeat(r)}${i}\t${o}`,e.type===`file`?t+=`\t${e.size}\t${e.mtimeMs}\n`:(t+=`
|
|
2
|
-
`,n(a,r+1))}};return n(e,0),t}parse(e){let t=0;function n(e){let n=++t,r=e.length===1?`dir`:`file`,[i,a,o]=e;return i=parseInt(i,8),a=a?parseInt(a):0,o=o?parseInt(o):Date.now(),new Map([[c,{mode:i,type:r,size:a,mtimeMs:o,ino:n}]])}let r=e.trim().split(`
|
|
3
|
-
`),i=this._makeRoot(),a=[{indent:-1,node:i},{indent:0,node:null}];for(let e of r){let t=e.match(/^\t*/)[0].length;e=e.slice(t);let[r,...i]=e.split(` `),o=n(i);if(t<=a[a.length-1].indent)for(;t<=a[a.length-1].indent;)a.pop();a.push({indent:t,node:o}),a[a.length-2].node.set(r,o)}return i}_lookup(e,t=!0){let r=this._root,a=`/`,o=n.split(e);for(let s=0;s<o.length;++s){let l=o[s];if(r=r.get(l),!r)throw new i(e);if(t||s<o.length-1){let e=r.get(c);if(e.type===`symlink`){let t=n.resolve(a,e.target);r=this._lookup(t)}a=a?n.join(a,l):l}}return r}mkdir(e,{mode:t}){if(e===`/`)throw new r;let i=this._lookup(n.dirname(e)),a=n.basename(e);if(i.has(a))throw new r;let o=new Map,s={mode:t,type:`dir`,size:0,mtimeMs:Date.now(),ino:this.autoinc()};o.set(c,s),i.set(a,o)}rmdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;if(t.size>1)throw new o;let r=this._lookup(n.dirname(e)),i=n.basename(e);r.delete(i)}readdir(e){let t=this._lookup(e);if(t.get(c).type!==`dir`)throw new a;return[...t.keys()].filter(e=>typeof e==`string`)}writeStat(e,t,{mode:r}){let i,a;try{a=this.stat(e)}catch{}if(a!==void 0){if(a.type===`dir`)throw new s;r??=a.mode,i=a.ino}r??=438,i??=this.autoinc();let o=this._lookup(n.dirname(e)),l=n.basename(e),u={mode:r,type:`file`,size:t,mtimeMs:Date.now(),ino:i},d=new Map;return d.set(c,u),o.set(l,d),u}unlink(e){let t=this._lookup(n.dirname(e)),r=n.basename(e);t.delete(r)}rename(e,t){let r=n.basename(t),i=this._lookup(e);this._lookup(n.dirname(t)).set(r,i),this.unlink(e)}stat(e){return this._lookup(e).get(c)}lstat(e){return this._lookup(e,!1).get(c)}readlink(e){return this._lookup(e,!1).get(c).target}symlink(e,t){let r,i;try{let e=this.stat(t);i===null&&(i=e.mode),r=e.ino}catch{}i??=40960,r??=this.autoinc();let a=this._lookup(n.dirname(t)),o=n.basename(t),s={mode:i,type:`symlink`,target:e,size:0,mtimeMs:Date.now(),ino:r},l=new Map;return l.set(c,s),a.set(o,l),s}_du(e){let t=0;for(let[n,r]of e.entries())n===c?t+=r.size:t+=this._du(r);return t}du(e){let t=this._lookup(e);return this._du(t)}}})),g=r({Store:()=>T,clear:()=>S,close:()=>w,del:()=>x,get:()=>v,keys:()=>C,set:()=>y,update:()=>b});function _(){return E||=new T,E}function v(e,t=_()){let n;return t._withIDBStore(`readwrite`,t=>{n=t.get(e)}).then(()=>n.result)}function y(e,t,n=_()){return n._withIDBStore(`readwrite`,n=>{n.put(t,e)})}function b(e,t,n=_()){return n._withIDBStore(`readwrite`,n=>{let r=n.get(e);r.onsuccess=()=>{n.put(t(r.result),e)}})}function x(e,t=_()){return t._withIDBStore(`readwrite`,t=>{t.delete(e)})}function S(e=_()){return e._withIDBStore(`readwrite`,e=>{e.clear()})}function C(e=_()){let t=[];return e._withIDBStore(`readwrite`,e=>{(e.openKeyCursor||e.openCursor).call(e).onsuccess=function(){this.result&&(t.push(this.result.key),this.result.continue())}}).then(()=>t)}function w(e=_()){return e._close()}var T,E,D=t((()=>{T=class{constructor(e=`keyval-store`,t=`keyval`){this.storeName=t,this._dbName=e,this._storeName=t,this._init()}_init(){this._dbp||=new Promise((e,t)=>{let n=indexedDB.open(this._dbName);n.onerror=()=>t(n.error),n.onsuccess=()=>e(n.result),n.onupgradeneeded=()=>{n.result.createObjectStore(this._storeName)}})}_withIDBStore(e,t){return this._init(),this._dbp.then(n=>new Promise((r,i)=>{let a=n.transaction(this.storeName,e);a.oncomplete=()=>r(),a.onabort=a.onerror=()=>i(a.error),t(a.objectStore(this.storeName))}))}_close(){return this._init(),this._dbp.then(e=>{e.close(),this._dbp=void 0})}}})),O=i(((t,n)=>{var r=(D(),e(g));n.exports=class{constructor(e,t){this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename)}saveSuperblock(e){return r.set(`!root`,e,this._store)}loadSuperblock(){return r.get(`!root`,this._store)}readFile(e){return r.get(e,this._store)}writeFile(e,t){return r.set(e,t,this._store)}unlink(e){return r.del(e,this._store)}wipe(){return r.clear(this._store)}close(){return r.close(this._store)}}})),k=i(((e,t)=>{t.exports=class{constructor(e){this._url=e}loadSuperblock(){return fetch(this._url+`/.superblock.txt`).then(e=>e.ok?e.text():null)}async readFile(e){let t=await fetch(this._url+e);if(t.status===200)return t.arrayBuffer();throw Error(`ENOENT`)}async sizeFile(e){let t=await fetch(this._url+e,{method:`HEAD`});if(t.status===200)return t.headers.get(`content-length`);throw Error(`ENOENT`)}}})),A=i(((t,n)=>{var r=(D(),e(g)),i=e=>new Promise(t=>setTimeout(t,e));n.exports=class{constructor(e,t){this._id=Math.random(),this._database=e,this._storename=t,this._store=new r.Store(this._database,this._storename),this._lock=null}async has({margin:e=2e3}={}){if(this._lock&&this._lock.holder===this._id){let t=Date.now();return this._lock.expires>t+e?!0:await this.renew()}else return!1}async renew({ttl:e=5e3}={}){let t;return await r.update(`lock`,n=>{let r=Date.now()+e;return t=n&&n.holder===this._id,this._lock=t?{holder:this._id,expires:r}:n,this._lock},this._store),t}async acquire({ttl:e=5e3}={}){let t,n,i;if(await r.update(`lock`,r=>{let a=Date.now(),o=a+e;return n=r&&r.expires<a,t=r===void 0||n,i=r&&r.holder===this._id,this._lock=t?{holder:this._id,expires:o}:r,this._lock},this._store),i)throw Error(`Mutex double-locked`);return t}async wait({interval:e=100,limit:t=6e3,ttl:n}={}){for(;t--;){if(await this.acquire({ttl:n}))return!0;await i(e)}throw Error(`Mutex timeout`)}async release({force:e=!1}={}){let t,n,i;if(await r.update(`lock`,r=>(t=e||r&&r.holder===this._id,n=r===void 0,i=r&&r.holder!==this._id,this._lock=t?void 0:r,this._lock),this._store),await r.close(this._store),!t&&!e){if(n)throw Error(`Mutex double-freed`);if(i)throw Error(`Mutex lost ownership`)}return t}}})),j=i(((e,t)=>{t.exports=class{constructor(e){this._id=Math.random(),this._database=e,this._has=!1,this._release=null}async has(){return this._has}async acquire(){return new Promise(e=>{navigator.locks.request(this._database+`_lock`,{ifAvailable:!0},t=>(this._has=!!t,e(!!t),new Promise(e=>{this._release=e})))})}async wait({timeout:e=6e5}={}){return new Promise((t,n)=>{let r=new AbortController;setTimeout(()=>{r.abort(),n(Error(`Mutex timeout`))},e),navigator.locks.request(this._database+`_lock`,{signal:r.signal},e=>(this._has=!!e,t(!!e),new Promise(e=>{this._release=e})))})}async release({force:e=!1}={}){this._has=!1,this._release?this._release():e&&navigator.locks.request(this._database+`_lock`,{steal:!0},e=>!0)}}})),M=i(((e,t)=>{var{encode:n,decode:r}=d(),i=f(),a=h(),{ENOENT:o,ENOTEMPTY:s,ETIMEDOUT:c}=m(),l=O(),u=k(),g=A(),_=j(),v=p();t.exports=class{constructor(){this.saveSuperblock=i(()=>{this.flush()},500)}async init(e,{wipe:t,url:n,urlauto:r,fileDbName:i=e,db:o=null,fileStoreName:s=e+`_files`,lockDbName:c=e+`_lock`,lockStoreName:d=e+`_lock`}={}){this._name=e,this._idb=o||new l(i,s),this._mutex=navigator.locks?new _(e):new g(c,d),this._cache=new a(e),this._opts={wipe:t,url:n},this._needsWipe=!!t,n&&(this._http=new u(n),this._urlauto=!!r)}async activate(){if(this._cache.activated)return;this._needsWipe&&(this._needsWipe=!1,await this._idb.wipe(),await this._mutex.release({force:!0})),await this._mutex.has()||await this._mutex.wait();let e=await this._idb.loadSuperblock();if(e)this._cache.activate(e);else if(this._http){let e=await this._http.loadSuperblock();this._cache.activate(e),await this._saveSuperblock()}else this._cache.activate();if(!await this._mutex.has())throw new c}async deactivate(){await this._mutex.has()&&await this._saveSuperblock(),this._cache.deactivate();try{await this._mutex.release()}catch(e){console.log(e)}await this._idb.close()}async _saveSuperblock(){this._cache.activated&&(this._lastSavedAt=Date.now(),await this._idb.saveSuperblock(this._cache._root))}_writeStat(e,t,n){let r=v.split(v.dirname(e)),i=r.shift();for(let e of r){i=v.join(i,e);try{this._cache.mkdir(i,{mode:511})}catch{}}return this._cache.writeStat(e,t,n)}async readFile(e,t){let n=typeof t==`string`?t:t&&t.encoding;if(n&&n!==`utf8`)throw Error(`Only "utf8" encoding is supported in readFile`);let i=null,a=null;try{a=this._cache.stat(e),i=await this._idb.readFile(a.ino)}catch(e){if(!this._urlauto)throw e}if(!i&&this._http){let t=this._cache.lstat(e);for(;t.type===`symlink`;)e=v.resolve(v.dirname(e),t.target),t=this._cache.lstat(e);i=await this._http.readFile(e)}if(i&&((!a||a.size!=i.byteLength)&&(a=await this._writeStat(e,i.byteLength,{mode:a?a.mode:438}),this.saveSuperblock()),n===`utf8`?i=r(i):i.toString=()=>r(i)),!a)throw new o(e);return i}async writeFile(e,t,r){let{mode:i,encoding:a=`utf8`}=r;if(typeof t==`string`){if(a!==`utf8`)throw Error(`Only "utf8" encoding is supported in writeFile`);t=n(t)}let o=await this._cache.writeStat(e,t.byteLength,{mode:i});await this._idb.writeFile(o.ino,t)}async unlink(e,t){let n=this._cache.lstat(e);this._cache.unlink(e),n.type!==`symlink`&&await this._idb.unlink(n.ino)}readdir(e,t){return this._cache.readdir(e)}mkdir(e,t){let{mode:n=511}=t;this._cache.mkdir(e,{mode:n})}rmdir(e,t){if(e===`/`)throw new s;this._cache.rmdir(e)}rename(e,t){this._cache.rename(e,t)}stat(e,t){return this._cache.stat(e)}lstat(e,t){return this._cache.lstat(e)}readlink(e,t){return this._cache.readlink(e)}symlink(e,t){this._cache.symlink(e,t)}async backFile(e,t){let n=await this._http.sizeFile(e);await this._writeStat(e,n,t)}du(e){return this._cache.du(e)}flush(){return this._saveSuperblock()}}})),N=i(((e,t)=>{t.exports=class{constructor(e){this.type=e.type,this.mode=e.mode,this.size=e.size,this.ino=e.ino,this.mtimeMs=e.mtimeMs,this.ctimeMs=e.ctimeMs||e.mtimeMs,this.uid=1,this.gid=1,this.dev=1}isFile(){return this.type===`file`}isDirectory(){return this.type===`dir`}isSymbolicLink(){return this.type===`symlink`}}})),P=i(((e,t)=>{var n=M(),r=N(),i=p();function a(e,t,...n){return e=i.normalize(e),(t===void 0||typeof t==`function`)&&(t={}),typeof t==`string`&&(t={encoding:t}),[e,t,...n]}function o(e,t,n,...r){return e=i.normalize(e),(n===void 0||typeof n==`function`)&&(n={}),typeof n==`string`&&(n={encoding:n}),[e,t,n,...r]}function s(e,t,...n){return[i.normalize(e),i.normalize(t),...n]}t.exports=class{constructor(e,t={}){this.init=this.init.bind(this),this.readFile=this._wrap(this.readFile,a,!1),this.writeFile=this._wrap(this.writeFile,o,!0),this.unlink=this._wrap(this.unlink,a,!0),this.readdir=this._wrap(this.readdir,a,!1),this.mkdir=this._wrap(this.mkdir,a,!0),this.rmdir=this._wrap(this.rmdir,a,!0),this.rename=this._wrap(this.rename,s,!0),this.stat=this._wrap(this.stat,a,!1),this.lstat=this._wrap(this.lstat,a,!1),this.readlink=this._wrap(this.readlink,a,!1),this.symlink=this._wrap(this.symlink,s,!0),this.backFile=this._wrap(this.backFile,a,!0),this.du=this._wrap(this.du,a,!1),this._deactivationPromise=null,this._deactivationTimeout=null,this._activationPromise=null,this._operations=new Set,e&&this.init(e,t)}async init(...e){return this._initPromiseResolve&&await this._initPromise,this._initPromise=this._init(...e),this._initPromise}async _init(e,t={}){await this._gracefulShutdown(),this._activationPromise&&await this._deactivate(),this._backend&&this._backend.destroy&&await this._backend.destroy(),this._backend=t.backend||new n,this._backend.init&&await this._backend.init(e,t),this._initPromiseResolve&&=(this._initPromiseResolve(),null),t.defer||this.stat(`/`)}async _gracefulShutdown(){this._operations.size>0&&(this._isShuttingDown=!0,await new Promise(e=>this._gracefulShutdownResolve=e),this._isShuttingDown=!1,this._gracefulShutdownResolve=null)}_wrap(e,t,n){return async(...r)=>{r=t(...r);let i={name:e.name,args:r};this._operations.add(i);try{return await this._activate(),await e.apply(this,r)}finally{this._operations.delete(i),n&&this._backend.saveSuperblock(),this._operations.size===0&&(this._deactivationTimeout||clearTimeout(this._deactivationTimeout),this._deactivationTimeout=setTimeout(this._deactivate.bind(this),500))}}}async _activate(){this._initPromise||console.warn(Error(`Attempted to use LightningFS ${this._name} before it was initialized.`)),await this._initPromise,this._deactivationTimeout&&=(clearTimeout(this._deactivationTimeout),null),this._deactivationPromise&&await this._deactivationPromise,this._deactivationPromise=null,this._activationPromise||=this._backend.activate?this._backend.activate():Promise.resolve(),await this._activationPromise}async _deactivate(){return this._activationPromise&&await this._activationPromise,this._deactivationPromise||=this._backend.deactivate?this._backend.deactivate():Promise.resolve(),this._activationPromise=null,this._gracefulShutdownResolve&&this._gracefulShutdownResolve(),this._deactivationPromise}async readFile(e,t){return this._backend.readFile(e,t)}async writeFile(e,t,n){return await this._backend.writeFile(e,t,n),null}async unlink(e,t){return await this._backend.unlink(e,t),null}async readdir(e,t){return this._backend.readdir(e,t)}async mkdir(e,t){return await this._backend.mkdir(e,t),null}async rmdir(e,t){return await this._backend.rmdir(e,t),null}async rename(e,t){return await this._backend.rename(e,t),null}async stat(e,t){return new r(await this._backend.stat(e,t))}async lstat(e,t){return new r(await this._backend.lstat(e,t))}async readlink(e,t){return this._backend.readlink(e,t)}async symlink(e,t){return await this._backend.symlink(e,t),null}async backFile(e,t){return await this._backend.backFile(e,t),null}async du(e){return this._backend.du(e)}async flush(){return this._backend.flush()}}})),F=n(i(((e,t)=>{var n=l(),r=P();function i(e,t){return typeof e==`function`&&(t=e),t=n(t),[(...e)=>t(null,...e),t]}t.exports=class{constructor(...e){this.promises=new r(...e),this.init=this.init.bind(this),this.readFile=this.readFile.bind(this),this.writeFile=this.writeFile.bind(this),this.unlink=this.unlink.bind(this),this.readdir=this.readdir.bind(this),this.mkdir=this.mkdir.bind(this),this.rmdir=this.rmdir.bind(this),this.rename=this.rename.bind(this),this.stat=this.stat.bind(this),this.lstat=this.lstat.bind(this),this.readlink=this.readlink.bind(this),this.symlink=this.symlink.bind(this),this.backFile=this.backFile.bind(this),this.du=this.du.bind(this),this.flush=this.flush.bind(this)}init(e,t){return this.promises.init(e,t)}readFile(e,t,n){let[r,a]=i(t,n);this.promises.readFile(e,t).then(r).catch(a)}writeFile(e,t,n,r){let[a,o]=i(n,r);this.promises.writeFile(e,t,n).then(a).catch(o)}unlink(e,t,n){let[r,a]=i(t,n);this.promises.unlink(e,t).then(r).catch(a)}readdir(e,t,n){let[r,a]=i(t,n);this.promises.readdir(e,t).then(r).catch(a)}mkdir(e,t,n){let[r,a]=i(t,n);this.promises.mkdir(e,t).then(r).catch(a)}rmdir(e,t,n){let[r,a]=i(t,n);this.promises.rmdir(e,t).then(r).catch(a)}rename(e,t,n){let[r,a]=i(n);this.promises.rename(e,t).then(r).catch(a)}stat(e,t,n){let[r,a]=i(t,n);this.promises.stat(e).then(r).catch(a)}lstat(e,t,n){let[r,a]=i(t,n);this.promises.lstat(e).then(r).catch(a)}readlink(e,t,n){let[r,a]=i(t,n);this.promises.readlink(e).then(r).catch(a)}symlink(e,t,n){let[r,a]=i(n);this.promises.symlink(e,t).then(r).catch(a)}backFile(e,t,n){let[r,a]=i(t,n);this.promises.backFile(e,t).then(r).catch(a)}du(e,t){let[n,r]=i(t);this.promises.du(e).then(n).catch(r)}flush(e){let[t,n]=i(e);this.promises.flush().then(t).catch(n)}}}))(),1),I=class extends Error{constructor(e,t,n){super(`${e}: ${t}${n?` '${n}'`:``}`),this.code=e,this.path=n,this.name=`FsError`}},L=`slicc-mount-table`,R=1,z=`mounts`;function B(){return new Promise((e,t)=>{let n=indexedDB.open(L,R);n.onupgradeneeded=()=>{let e=n.result;e.objectStoreNames.contains(z)||e.createObjectStore(z)},n.onsuccess=()=>e(n.result),n.onerror=()=>t(n.error)})}async function V(e,t){let n=await B();try{let r=n.transaction(z,`readwrite`);r.objectStore(z).put(t,e),await new Promise((e,t)=>{r.oncomplete=()=>e(),r.onerror=()=>t(r.error),r.onabort=()=>t(r.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{n.close()}}async function H(e){let t=await B();try{let n=t.transaction(z,`readwrite`);n.objectStore(z).delete(e),await new Promise((e,t)=>{n.oncomplete=()=>e(),n.onerror=()=>t(n.error),n.onabort=()=>t(n.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{t.close()}}async function U(){let e=await B();try{let t=e.transaction(z,`readonly`),n=t.objectStore(z),r=()=>t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`),i=await new Promise((e,i)=>{let a=n.getAllKeys();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())}),a=await new Promise((e,i)=>{let a=n.getAll();a.onsuccess=()=>e(a.result),a.onerror=()=>i(a.error),t.onabort=()=>i(r())});return i.map((e,t)=>({path:e,handle:a[t]}))}finally{e.close()}}async function W(){let e=await B();try{let t=e.transaction(z,`readwrite`);t.objectStore(z).clear(),await new Promise((e,n)=>{t.oncomplete=()=>e(),t.onerror=()=>n(t.error),t.onabort=()=>n(t.error??new DOMException(`IndexedDB transaction aborted`,`AbortError`))})}finally{e.close()}}var G=10,K=class e{lfs;rawFs;_ready;mountPoints=new Map;watcher=null;dbName;mountSyncChannel=null;constructor(e,t){this.dbName=e;let n=new F.default(e,{wipe:t});if(this.rawFs=n,this.lfs=n.promises,this._ready=this.lfs.stat(`/`).then(()=>{}).catch(()=>{}),typeof BroadcastChannel<`u`)try{this.mountSyncChannel=new BroadcastChannel(`vfs-mount-sync:${e}`),this.mountSyncChannel.onmessage=e=>{let{type:t,path:n,handle:r}=e.data??{};t===`mount`&&typeof n==`string`&&r?(this.mountPoints.set(n,r),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}])):t===`unmount`&&typeof n==`string`&&(this.mountPoints.delete(n),this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]))}}catch{}}static async create(t){let n=t?.dbName??`browser-fs`,r=t?.wipe??!1,i=new e(n,r);return await i._ready,r&&await W().catch(()=>{}),i}getLightningFS(){return this.lfs}canWrite(e){return!0}setWatcher(e){this.watcher=e}getWatcher(){return this.watcher}async dispose(){this.mountSyncChannel?.close(),this.mountSyncChannel=null,this.watcher?.dispose(),this.watcher=null;let e=this.lfs;if(e._deactivationTimeout&&=(clearTimeout(e._deactivationTimeout),null),e._operations?.size>0&&await e._gracefulShutdown?.(),e._backend?.saveSuperblock?.cancel&&e._backend.saveSuperblock.cancel(),e._backend){try{e._backend.flush&&await e._backend.flush()}catch{}e._backend.deactivate&&await e._backend.deactivate()}if(e._backend=null,e._activationPromise=null,e._deactivationPromise=null,e._initPromise=null,typeof indexedDB<`u`&&indexedDB.deleteDatabase)try{let e=indexedDB.deleteDatabase(this.dbName);await new Promise((t,n)=>{e.onsuccess=()=>t(),e.onerror=()=>n(e.error)})}catch{}}getCacheFS(){try{let e=this.lfs._backend?._cache;return e?.activated&&e._root instanceof Map?e:null}catch{return null}}readDirSync(e){let t=o(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.readdir(t),r=[];for(let i of e){let e=t===`/`?`/${i}`:`${t}/${i}`;try{let t=n.lstat(e),a=t.type===`symlink`?`symlink`:t.type===`dir`?`directory`:`file`;r.push({name:i,type:a})}catch{}}return r}catch{return null}}statSync(e){let t=o(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=this.resolveSymlinksSync(n,t);if(e===null)return null;let r=n.lstat(e);return{type:r.type===`dir`?`directory`:`file`,size:r.size??0,mtime:r.mtimeMs??Date.now(),ctime:r.mtimeMs??Date.now()}}catch{return null}}resolveSymlinksSync(e,t,n={count:0}){let r=t.split(`/`).filter(Boolean),i=`/`;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{let t=e.lstat(i);if(t.type===`symlink`){if(++n.count>G)return null;let r=t.target;if(r.startsWith(`/`))i=o(r);else{let{dir:e}=s(i);i=o(c(e,r))}let a=this.resolveSymlinksSync(e,i,n);if(a===null)return null;i=a}}catch{return null}}return i}lstatSync(e){let t=o(e);if(this.findMount(t))return null;let n=this.getCacheFS();if(!n)return null;try{let e=n.lstat(t);return e.type===`symlink`?{type:`symlink`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now(),isSymlink:!0,symlinkTarget:e.target}:{type:e.type===`dir`?`directory`:`file`,size:e.size??0,mtime:e.mtimeMs??Date.now(),ctime:e.mtimeMs??Date.now()}}catch{return null}}async mount(e,t){let n=o(e);if(this.mountPoints.has(n))throw new I(`EEXIST`,`mount point is already mounted`,n);try{if((await this.lstat(n)).type!==`directory`)throw new I(`ENOTDIR`,`mount point must be a directory`,n);if((await this.readDir(n)).length>0)throw new I(`ENOTEMPTY`,`mount point must be empty to avoid shadowing existing files`,n)}catch(e){if(!(e instanceof I)||e.code!==`ENOENT`)throw e}let{dir:r}=s(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.mkdir(n)}catch{}this.mountPoints.set(n,t);try{this.mountSyncChannel?.postMessage({type:`mount`,path:n,handle:t})}catch{}this.watcher?.notify([{type:`modify`,path:n,entryType:`directory`}]);try{await V(n,t)}catch{}}async unmount(e){let t=o(e);this.mountPoints.delete(t);try{this.mountSyncChannel?.postMessage({type:`unmount`,path:t})}catch{}this.watcher?.notify([{type:`modify`,path:t,entryType:`directory`}]);try{await H(t)}catch{}}listMounts(){return[...this.mountPoints.keys()]}isPathUnderMount(e){for(let t of this.mountPoints.keys())if(e===t||e.startsWith(t+`/`))return!0;return!1}findMount(e){let t=null;for(let[n,r]of this.mountPoints)(e===n||e.startsWith(n+`/`))&&(!t||n.length>t.mountPath.length)&&(t={mountPath:n,handle:r});return t?e===t.mountPath?{handle:t.handle,relParts:[]}:{handle:t.handle,relParts:e.slice(t.mountPath.length+1).split(`/`).filter(Boolean)}:null}static async fsaNavDir(e,t,n=!1){let r=e;for(let e of t)r=await r.getDirectoryHandle(e,{create:n});return r}static async fsaGetFile(t,n,r=!1){return(await e.fsaNavDir(t,n.slice(0,-1),r)).getFileHandle(n[n.length-1],{create:r})}convertFsaError(e,t){if(e instanceof I)return e;if(e instanceof Error){if(e.name===`NotFoundError`)return new I(`ENOENT`,`no such file or directory`,t);if(e.name===`TypeMismatchError`)return new I(`ENOTDIR`,`not a directory`,t);if(e.name===`NotAllowedError`)return new I(`EINVAL`,`permission denied`,t);if(e.name===`InvalidModificationError`)return new I(`ENOTEMPTY`,`directory not empty`,t)}return new I(`EINVAL`,e instanceof Error?e.message:String(e),t)}async readFile(t,n){let r=o(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new I(`EISDIR`,`is a directory`,r);try{let t=await(await e.fsaGetFile(i.handle,i.relParts)).getFile();return(n?.encoding??`utf-8`)===`utf-8`?await t.text():new Uint8Array(await t.arrayBuffer())}catch(e){throw this.convertFsaError(e,r)}}let a=await this.resolveSymlinks(r);try{return(n?.encoding??`utf-8`)===`utf-8`?await this.lfs.readFile(a,{encoding:`utf8`}):await this.lfs.readFile(a)}catch(e){throw this.convertError(e,r)}}async writeFile(t,n,r){let i=o(t),a=this.findMount(i);if(a){if(a.relParts.length===0)throw new I(`EISDIR`,`is a directory`,i);let t=!1;try{await this.stat(i),t=!0}catch{}try{let t=await(await e.fsaGetFile(a.handle,a.relParts,!0)).createWritable(),r=typeof n==`string`?new TextEncoder().encode(n):n instanceof Uint8Array?new Uint8Array(n.buffer,n.byteOffset,n.byteLength):new Uint8Array(n);await t.write(r),await t.close()}catch(e){throw this.convertFsaError(e,i)}this.watcher?.notify([{type:t?`modify`:`create`,path:i,entryType:`file`}]);return}let c;try{c=await this.resolveSymlinks(i)}catch{c=i}let l=!1;try{await this.lfs.stat(c),l=!0}catch{}let{dir:u}=s(c);u!==`/`&&await this.mkdir(u,{recursive:!0});try{await this.lfs.writeFile(c,n)}catch(e){throw this.convertError(e,i)}this.watcher?.notify([{type:l?`modify`:`create`,path:c,entryType:`file`}])}async readDir(t){let n=o(t),r=this.findMount(n);if(r)try{let t=r.relParts.length===0?r.handle:await e.fsaNavDir(r.handle,r.relParts),i=new Map;for await(let[e,n]of t)i.set(e,{name:e,type:n.kind===`directory`?`directory`:`file`});let a=n===`/`?`/`:`${n}/`;for(let e of this.mountPoints.keys()){if(e===n||!e.startsWith(a))continue;let t=e.slice(a.length);!t||t.includes(`/`)||i.has(t)||i.set(t,{name:t,type:`directory`})}return[...i.values()]}catch(e){throw this.convertFsaError(e,n)}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.readdir(i),t=[];for(let n of e){let e=i===`/`?`/${n}`:`${i}/${n}`;try{let r=await this.lfs.lstat(e);r.isSymbolicLink()?t.push({name:n,type:`symlink`}):t.push({name:n,type:r.isDirectory()?`directory`:`file`})}catch{}}return t}catch(e){throw this.convertError(e,n)}}async mkdir(t,n){let r=o(t);if(r===`/`)return;let i=this.findMount(r);if(i){if(i.relParts.length===0)return;try{let t=await this.exists(r);await e.fsaNavDir(i.handle,i.relParts,!0),t||this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}catch(e){throw this.convertFsaError(e,r)}return}if(n?.recursive){let e=r.split(`/`).filter(Boolean),t=``;for(let n of e){t+=`/`+n;try{await this.lfs.mkdir(t)}catch(e){if(e instanceof Error&&!e.message.includes(`EEXIST`))throw this.convertError(e,t)}}}else{try{await this.lfs.mkdir(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`create`,path:r,entryType:`directory`}])}}async rm(t,n){let r=o(t),i=this.findMount(r);if(i){if(i.relParts.length===0)throw new I(`EINVAL`,`cannot remove a mount point — use unmount`,r);let t;try{t=(await this.stat(r)).type}catch{}try{let t=i.relParts.slice(0,-1),r=i.relParts[i.relParts.length-1];await(t.length===0?i.handle:await e.fsaNavDir(i.handle,t)).removeEntry(r,{recursive:n?.recursive})}catch(e){throw this.convertFsaError(e,r)}this.watcher?.notify([{type:`delete`,path:r,entryType:t}]);return}try{let e=await this.lfs.lstat(r);e.isSymbolicLink()?await this.lfs.unlink(r):e.isDirectory()?n?.recursive?await this.rmRecursive(r):await this.lfs.rmdir(r):await this.lfs.unlink(r)}catch(e){throw this.convertError(e,r)}this.watcher?.notify([{type:`delete`,path:r}])}async rmRecursive(e){let t=await this.lfs.readdir(e);for(let n of t){let t=e===`/`?`/${n}`:`${e}/${n}`;(await this.lfs.stat(t)).isDirectory()?await this.rmRecursive(t):await this.lfs.unlink(t)}await this.lfs.rmdir(e)}async stat(t){let n=o(t),r=this.findMount(n);if(r){if(r.relParts.length===0)try{let e=await this.lfs.stat(n);return{type:`directory`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch{return{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}try{try{let t=await(await e.fsaGetFile(r.handle,r.relParts)).getFile();return{type:`file`,size:t.size,mtime:t.lastModified,ctime:t.lastModified}}catch{return await e.fsaNavDir(r.handle,r.relParts),{type:`directory`,size:0,mtime:Date.now(),ctime:Date.now()}}}catch(e){throw this.convertFsaError(e,n)}}let i=await this.resolveSymlinks(n);try{let e=await this.lfs.stat(i);return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,n)}}async exists(e){let t=o(e),n=this.findMount(t);if(n){if(n.relParts.length===0)return!0;try{return await this.stat(t),!0}catch{return!1}}try{return await this.stat(t),!0}catch{try{return await this.lfs.lstat(t),!0}catch{return!1}}}async rename(e,t){let n=o(e),r=o(t),i;try{i=(await this.lstat(n)).type}catch{}try{await this.lfs.rename(n,r)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`delete`,path:n,entryType:i},{type:`create`,path:r,entryType:i}])}async readTextFile(e){return await this.readFile(e,{encoding:`utf-8`})}async*walk(e,t){let n=o(e),r=t??new Set,i;try{i=await this.realpath(n)}catch{i=n}if(r.has(i))return;r.add(i);let a=await this.readDir(n);for(let e of a){let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;if(e.type===`file`)yield t;else if(e.type===`symlink`)try{let e=await this.stat(t);e.type===`file`?yield t:e.type===`directory`&&(yield*this.walk(t,r))}catch{}else yield*this.walk(t,r)}}async copyFile(e,t){if((await this.stat(e)).type===`directory`)throw new I(`EISDIR`,`is a directory`,e);let n=await this.readFile(e,{encoding:`binary`});await this.writeFile(t,n)}dirname(e){return s(o(e)).dir}basename(e){return s(o(e)).base}async symlink(e,t){let n=o(t);if(this.findMount(n))throw new I(`EINVAL`,`symlinks not supported on mounted filesystems`,n);let{dir:r}=s(n);r!==`/`&&await this.mkdir(r,{recursive:!0});try{await this.lfs.symlink(e,n)}catch(e){throw this.convertError(e,n)}this.watcher?.notify([{type:`create`,path:n,entryType:`symlink`}])}async readlink(e){let t=o(e);try{return await this.lfs.readlink(t)}catch(e){throw this.convertError(e,t)}}async lstat(e){let t=o(e);if(this.findMount(t))return this.stat(t);try{let e=await this.lfs.lstat(t);if(e.isSymbolicLink()){let n=await this.lfs.readlink(t);return{type:`symlink`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs,isSymlink:!0,symlinkTarget:n}}return{type:e.isDirectory()?`directory`:`file`,size:e.size,mtime:e.mtimeMs,ctime:e.ctimeMs}}catch(e){throw this.convertError(e,t)}}async realpath(e,t=0){let n=o(e);if(this.findMount(n))return n;let r=n.split(`/`).filter(Boolean),i=`/`,a=t;for(let t of r){i=i===`/`?`/${t}`:`${i}/${t}`;try{if((await this.lfs.lstat(i)).isSymbolicLink()){if(++a>G)throw new I(`ELOOP`,`too many levels of symbolic links`,e);let t=await this.lfs.readlink(i);if(t.startsWith(`/`))i=o(t);else{let{dir:e}=s(i);i=o(c(e,t))}i=await this.realpath(i,a)}}catch(e){throw e instanceof I?e:this.convertError(e,i)}}return i}async resolveSymlinks(e){return this.findMount(e)?e:this.realpath(e)}convertError(e,t){if(e instanceof I)return e;let n=e instanceof Error?e.message:String(e);return n.includes(`ENOENT`)?new I(`ENOENT`,`no such file or directory`,t):n.includes(`EEXIST`)?new I(`EEXIST`,`file already exists`,t):n.includes(`ENOTDIR`)?new I(`ENOTDIR`,`not a directory`,t):n.includes(`EISDIR`)?new I(`EISDIR`,`is a directory`,t):n.includes(`ENOTEMPTY`)?new I(`ENOTEMPTY`,`directory not empty`,t):n.includes(`ELOOP`)?new I(`ELOOP`,`too many levels of symbolic links`,t):new I(`EINVAL`,n,t)}},q=class{vfs;allowedPrefixes;readOnlyPrefixes;constructor(e,t,n=[]){this.vfs=e;let r=e=>{let t=o(e);return t.endsWith(`/`)?t:t+`/`};this.allowedPrefixes=t.map(r),this.readOnlyPrefixes=n.map(r)}getAllPrefixes(){let e=this.vfs.listMounts().map(e=>e.endsWith(`/`)?e:e+`/`);return[...this.allowedPrefixes,...this.readOnlyPrefixes,...e]}isAllowed(e){let t=o(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e)||t===`/`||e.startsWith(t+`/`))}isAllowedStrict(e){let t=o(e);return this.getAllPrefixes().some(e=>t===e.slice(0,-1)||t.startsWith(e))}isWritable(e){let t=o(e);return this.allowedPrefixes.some(e=>t===e.slice(0,-1)||t.startsWith(e))}canWrite(e){return this.isWritable(e)}checkWrite(e){if(!this.isWritable(e))throw new I(`EACCES`,`permission denied`,o(e))}async resolveAndCheckRead(e){try{let t=await this.vfs.realpath(e);if(!this.isAllowedStrict(t))throw new I(`ENOENT`,`no such file or directory`,o(e));return t}catch(t){throw t instanceof I?t:new I(`ENOENT`,`no such file or directory`,o(e))}}async resolveAndCheckWrite(e){try{let t=await this.vfs.realpath(e);if(!this.isWritable(t))throw new I(`EACCES`,`permission denied`,o(e));return t}catch(t){throw t instanceof I?t:new I(`EACCES`,`permission denied`,o(e))}}getUnderlyingFS(){return this.vfs}getLightningFS(){return this.vfs.getLightningFS()}async readFile(e,t){if(!this.isAllowedStrict(e))throw new I(`ENOENT`,`no such file or directory`,o(e));let n=await this.resolveAndCheckRead(e);return this.vfs.readFile(n,t)}async readDir(e){if(!this.isAllowed(e))return[];let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return[]}let n=await this.vfs.readDir(t);if(!this.isAllowedStrict(e)){let t=o(e);return n.filter(e=>{let n=t===`/`?`/${e.name}`:`${t}/${e.name}`;return this.isAllowed(n)})}return n}async stat(e){if(!this.isAllowed(e))throw new I(`ENOENT`,`no such file or directory`,o(e));if(this.isAllowedStrict(e)){let t=await this.resolveAndCheckRead(e);return this.vfs.stat(t)}return this.vfs.stat(e)}scanPathForSymlinks(e,t){let n=o(e);if(n===`/`)return!1;let r=n.slice(1).split(`/`),i=t?r.length:r.length-1,a=``;for(let e=0;e<i;e++){a=a+`/`+r[e];let t=this.vfs.lstatSync(a);if(t===null)return null;if(t.type===`symlink`)return!0}return!1}statSync(e){return!this.isAllowedStrict(e)||this.scanPathForSymlinks(e,!0)!==!1?null:this.vfs.statSync(e)}lstatSync(e){return!this.isAllowed(e)||this.scanPathForSymlinks(e,!1)!==!1?null:this.vfs.lstatSync(e)}readDirSync(e){if(!this.isAllowed(e)||this.scanPathForSymlinks(e,!0)!==!1)return null;let t=this.vfs.readDirSync(e);if(t===null)return null;if(this.isAllowedStrict(e))return t;let n=o(e);return t.filter(e=>{let t=n===`/`?`/${e.name}`:`${n}/${e.name}`;return this.isAllowed(t)})}async realpath(e){let t;try{t=await this.vfs.realpath(e)}catch(t){throw t instanceof I?t:new I(`ENOENT`,`no such file or directory`,o(e))}if(!this.isAllowedStrict(t))throw new I(`ENOENT`,`no such file or directory`,o(e));return t}async exists(e){if(!this.isAllowed(e))return!1;if(this.isAllowedStrict(e))try{await this.resolveAndCheckRead(e)}catch{return!1}return this.vfs.exists(e)}async readTextFile(e){if(!this.isAllowedStrict(e))throw new I(`ENOENT`,`no such file or directory`,o(e));let t=await this.resolveAndCheckRead(e);return this.vfs.readTextFile(t)}async*walk(e){if(!this.isAllowed(e))return;let t=e;if(this.isAllowedStrict(e))try{t=await this.resolveAndCheckRead(e)}catch{return}for await(let e of this.vfs.walk(t))this.isAllowed(e)&&(yield e)}async writeFile(e,t,n){this.checkWrite(e);let r=this.vfs.dirname(e),i=this.vfs.basename(e);try{let t=await this.vfs.realpath(r);if(!this.isWritable(t+`/`+i))throw new I(`EACCES`,`permission denied`,o(e))}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(e)).type===`symlink`&&await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.writeFile(e,t,n)}async mkdir(e,t){this.checkWrite(e);let n=this.vfs.dirname(e),r=this.vfs.basename(e);try{let t=await this.vfs.realpath(n);if(!this.isWritable(t+`/`+r))throw new I(`EACCES`,`permission denied`,o(e))}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.mkdir(e,t)}async rm(e,t){this.checkWrite(e);try{(await this.vfs.lstat(e)).type===`symlink`||await this.resolveAndCheckWrite(e)}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.rm(e,t)}async rename(e,t){this.checkWrite(e),this.checkWrite(t),await this.resolveAndCheckWrite(e);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new I(`EACCES`,`permission denied`,o(t))}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.rename(e,t)}async copyFile(e,t){if(!this.isAllowed(e))throw new I(`ENOENT`,`no such file or directory`,o(e));this.checkWrite(t);let n=await this.resolveAndCheckRead(e),r=this.vfs.dirname(t),i=this.vfs.basename(t);try{let e=await this.vfs.realpath(r);if(!this.isWritable(e+`/`+i))throw new I(`EACCES`,`permission denied`,o(t))}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}try{(await this.vfs.lstat(t)).type===`symlink`&&await this.resolveAndCheckWrite(t)}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.copyFile(n,t)}async symlink(e,t){this.checkWrite(t);let n=this.vfs.dirname(t),r=this.vfs.basename(t);try{let e=await this.vfs.realpath(n);if(!this.isWritable(e+`/`+r))throw new I(`EACCES`,`permission denied`,o(t))}catch(e){if(e instanceof I&&e.code===`EACCES`)throw e}return this.vfs.symlink(e,t)}async readlink(e){if(!this.isAllowedStrict(e))throw new I(`ENOENT`,`no such file or directory`,o(e));let t=await this.vfs.readlink(e),n;if(n=t.startsWith(`/`)?o(t):o(this.vfs.dirname(e)+`/`+t),!this.isAllowedStrict(n))throw new I(`ENOENT`,`no such file or directory`,o(e));return t}async lstat(e){if(!this.isAllowed(e))throw new I(`ENOENT`,`no such file or directory`,o(e));let t=o(e),n=this.vfs.dirname(t),r=this.vfs.basename(t),i;if(n===t)i=n;else try{i=await this.vfs.realpath(n)}catch{throw new I(`ENOENT`,`no such file or directory`,t)}let a=i===`/`?`/${r}`:`${i}/${r}`;if(!this.isAllowed(a))throw new I(`ENOENT`,`no such file or directory`,t);return this.vfs.lstat(a)}watch(e,t,n){if(!this.isAllowed(e))throw new I(`EACCES`,`permission denied`,o(e));let r=this.vfs.getWatcher();if(!r)throw new I(`EINVAL`,`no watcher configured`);return r.watch(o(e),t,n)}dirname(e){return this.vfs.dirname(e)}basename(e){return this.vfs.basename(e)}async dispose(){await this.vfs.dispose()}},J=a(`fs-watcher`),Y=0;function X(e,t){return t===`/`||e===t||e.startsWith(t+`/`)}var Z=class{registrations=new Map;watch(e,t,n){let r=`fsw-${++Y}`;return this.registrations.set(r,{id:r,basePath:e,filter:t,callback:n}),J.debug(`Watch registered`,{id:r,basePath:e}),()=>{this.registrations.delete(r),J.debug(`Watch unregistered`,{id:r})}}notify(e){if(e.length!==0)for(let[,t]of this.registrations){let n=e.filter(e=>X(e.path,t.basePath)&&t.filter(e.path));if(n.length>0)try{t.callback(n)}catch(e){J.error(`Watch callback error`,{id:t.id,error:e instanceof Error?e.message:String(e)})}}}dispose(){this.registrations.clear(),J.debug(`All watchers disposed`)}get size(){return this.registrations.size}},Q=r({VirtualFS:()=>K});export{U as a,K as i,Z as n,I as o,q as r,Q as t};
|