@pstdio/workbench 0.1.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 +343 -0
- package/dist/context-key-service-C--cHa0B.js +447 -0
- package/dist/context-key-service-C--cHa0B.js.map +1 -0
- package/dist/core.d.ts +1885 -0
- package/dist/core.js +64 -0
- package/dist/core.js.map +1 -0
- package/dist/extensions.d.ts +1934 -0
- package/dist/extensions.js +1728 -0
- package/dist/extensions.js.map +1 -0
- package/dist/file-renderer-view-DrrhYnb_.js +171 -0
- package/dist/file-renderer-view-DrrhYnb_.js.map +1 -0
- package/dist/icon-B9XolQG8.js +35 -0
- package/dist/icon-B9XolQG8.js.map +1 -0
- package/dist/index.d.ts +1885 -0
- package/dist/index.js +64 -0
- package/dist/index.js.map +1 -0
- package/dist/react.d.ts +2020 -0
- package/dist/react.js +3905 -0
- package/dist/react.js.map +1 -0
- package/dist/storage.d.ts +128 -0
- package/dist/storage.js +87 -0
- package/dist/storage.js.map +1 -0
- package/dist/surface-reconcile-DkRf01ro.js +260 -0
- package/dist/surface-reconcile-DkRf01ro.js.map +1 -0
- package/dist/testing.d.ts +1620 -0
- package/dist/testing.js +46 -0
- package/dist/testing.js.map +1 -0
- package/dist/webview-runtime.d.ts +10 -0
- package/dist/webview-runtime.js +31 -0
- package/dist/webview-runtime.js.map +1 -0
- package/dist/workbench-core-DFpwi8Lo.js +2264 -0
- package/dist/workbench-core-DFpwi8Lo.js.map +1 -0
- package/dist/workbench-menu-paths-CQVH6z4_.js +11 -0
- package/dist/workbench-menu-paths-CQVH6z4_.js.map +1 -0
- package/package.json +95 -0
package/dist/testing.js
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { describe as c, beforeEach as w, afterEach as n, test as d, expect as i } from "bun:test";
|
|
2
|
+
import { g as y, e as B } from "./surface-reconcile-DkRf01ro.js";
|
|
3
|
+
const h = (e) => e.layout.getLayout().areas[B("primary")].widgets, l = (e) => h(e).filter((s) => !s.pinned), u = (e) => y(e.layout.getLayout(), "primary"), r = async () => {
|
|
4
|
+
await Promise.resolve(), await Promise.resolve();
|
|
5
|
+
}, g = (e) => {
|
|
6
|
+
c(`${e.name} navigation contract`, () => {
|
|
7
|
+
let s, a;
|
|
8
|
+
w(async () => {
|
|
9
|
+
s = await e.setup(), a = s.workbench;
|
|
10
|
+
}), n(() => {
|
|
11
|
+
s.dispose?.();
|
|
12
|
+
});
|
|
13
|
+
const o = async (t) => {
|
|
14
|
+
await a.resources.openResource(t, {
|
|
15
|
+
replaceActive: !0
|
|
16
|
+
}), await r();
|
|
17
|
+
};
|
|
18
|
+
if (d("root -> detail -> Back activates the root", async () => {
|
|
19
|
+
await o(e.root), await o(e.detail);
|
|
20
|
+
const t = a.history.goBack();
|
|
21
|
+
await r(), i(u(a)?.uri).toBe(e.root.uri), i(t?.resource?.uri).toBe(e.root.uri), i(l(a)).toHaveLength(1);
|
|
22
|
+
}), d("root -> detail -> Back -> Forward activates the detail", async () => {
|
|
23
|
+
await o(e.root), await o(e.detail), a.history.goBack(), await r();
|
|
24
|
+
const t = a.history.goForward();
|
|
25
|
+
await r(), i(u(a)?.uri).toBe(e.detail.uri), i(t?.resource?.uri).toBe(e.detail.uri), i(l(a)).toHaveLength(1);
|
|
26
|
+
}), e.detailB) {
|
|
27
|
+
const t = e.detailB;
|
|
28
|
+
d("detail A -> detail B -> Back activates detail A", async () => {
|
|
29
|
+
await o(e.root), await o(e.detail), await o(t), a.history.goBack(), await r(), i(u(a)?.uri).toBe(e.detail.uri), i(l(a)).toHaveLength(1);
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (e.expectedMode) {
|
|
33
|
+
const t = e.expectedMode;
|
|
34
|
+
d("activates the route mode and keeps it across Back", async () => {
|
|
35
|
+
await o(e.root), i(a.modes.getActiveModeId()).toBe(t), await o(e.detail), i(a.modes.getActiveModeId()).toBe(t), a.history.goBack(), await r(), i(a.modes.getActiveModeId()).toBe(t);
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
export {
|
|
41
|
+
u as activePrimaryResource,
|
|
42
|
+
g as describeResourceRouteContract,
|
|
43
|
+
h as primaryPlacements,
|
|
44
|
+
l as unpinnedPrimaryPlacements
|
|
45
|
+
};
|
|
46
|
+
//# sourceMappingURL=testing.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"testing.js","sources":["../src/testing/navigation-contract.ts"],"sourcesContent":["import { afterEach, beforeEach, describe, expect, test } from \"bun:test\";\nimport type { ResourceRef, WorkbenchCore } from \"../core\";\nimport { getAnchorResource, resolveAnchorArea } from \"../core\";\n\n// The primary/main surface hosts the \"primary\" anchor (see surface-map). Reading placements\n// and the active resource through the anchor — not the global activeResourceUri, which any\n// side-area activation can pollute — measures the exact signal history records, so the\n// contract asserts the user-visible navigation state.\nexport const primaryPlacements = (workbench: WorkbenchCore) =>\n workbench.layout.getLayout().areas[resolveAnchorArea(\"primary\")].widgets;\n\nexport const unpinnedPrimaryPlacements = (workbench: WorkbenchCore) =>\n primaryPlacements(workbench).filter((placement) => !placement.pinned);\n\nexport const activePrimaryResource = (workbench: WorkbenchCore) =>\n getAnchorResource(workbench.layout.getLayout(), \"primary\");\n\nexport interface RouteContractHarness {\n workbench: WorkbenchCore;\n dispose?: () => void;\n}\n\nexport interface ResourceRouteContract {\n // Route id / assertion label so a contract failure names the offending route.\n name: string;\n setup: () => RouteContractHarness | Promise<RouteContractHarness>;\n root: ResourceRef;\n detail: ResourceRef;\n detailB?: ResourceRef;\n expectedMode?: string;\n}\n\n// Two microtasks settle a Back/Forward replay: the cursor moves synchronously, then the\n// silent resource reopen resolves on the microtask queue.\nconst flush = async () => {\n await Promise.resolve();\n await Promise.resolve();\n};\n\n// Shared navigation invariants every resource-first root/detail route must satisfy. Drives a\n// real workbench core (provided by `setup`) and asserts the user-visible Back/Forward state:\n// root stays root, detail replays, mode is restored, and the primary area never grows tabs.\nexport const describeResourceRouteContract = (contract: ResourceRouteContract) => {\n describe(`${contract.name} navigation contract`, () => {\n let harness: RouteContractHarness;\n let workbench: WorkbenchCore;\n\n beforeEach(async () => {\n harness = await contract.setup();\n workbench = harness.workbench;\n });\n\n afterEach(() => {\n harness.dispose?.();\n });\n\n const open = async (resource: ResourceRef) => {\n await workbench.resources.openResource(resource, { replaceActive: true });\n await flush();\n };\n\n test(\"root -> detail -> Back activates the root\", async () => {\n await open(contract.root);\n await open(contract.detail);\n\n const back = workbench.history.goBack();\n await flush();\n\n expect(activePrimaryResource(workbench)?.uri).toBe(contract.root.uri);\n expect(back?.resource?.uri).toBe(contract.root.uri);\n expect(unpinnedPrimaryPlacements(workbench)).toHaveLength(1);\n });\n\n test(\"root -> detail -> Back -> Forward activates the detail\", async () => {\n await open(contract.root);\n await open(contract.detail);\n\n workbench.history.goBack();\n await flush();\n const forward = workbench.history.goForward();\n await flush();\n\n expect(activePrimaryResource(workbench)?.uri).toBe(contract.detail.uri);\n expect(forward?.resource?.uri).toBe(contract.detail.uri);\n expect(unpinnedPrimaryPlacements(workbench)).toHaveLength(1);\n });\n\n if (contract.detailB) {\n const detailB = contract.detailB;\n test(\"detail A -> detail B -> Back activates detail A\", async () => {\n await open(contract.root);\n await open(contract.detail);\n await open(detailB);\n\n workbench.history.goBack();\n await flush();\n\n expect(activePrimaryResource(workbench)?.uri).toBe(contract.detail.uri);\n expect(unpinnedPrimaryPlacements(workbench)).toHaveLength(1);\n });\n }\n\n if (contract.expectedMode) {\n const expectedMode = contract.expectedMode;\n test(\"activates the route mode and keeps it across Back\", async () => {\n await open(contract.root);\n expect(workbench.modes.getActiveModeId()).toBe(expectedMode);\n\n await open(contract.detail);\n expect(workbench.modes.getActiveModeId()).toBe(expectedMode);\n\n workbench.history.goBack();\n await flush();\n expect(workbench.modes.getActiveModeId()).toBe(expectedMode);\n });\n }\n });\n};\n"],"names":["primaryPlacements","workbench","layout","getLayout","areas","resolveAnchorArea","widgets","unpinnedPrimaryPlacements","filter","placement","pinned","activePrimaryResource","getAnchorResource","flush","Promise","resolve","describeResourceRouteContract","contract","describe","name","harness","beforeEach","setup","afterEach","dispose","open","resource","resources","openResource","replaceActive","test","root","detail","back","history","goBack","expect","uri","toBe","toHaveLength","forward","goForward","detailB","expectedMode","modes","getActiveModeId"],"mappings":"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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { renderExtensionRuntimeHtml } from 'pstdio-extensions/bridge/webview-runtime-html';
|
|
2
|
+
import { renderInlineExtensionRuntimeHtml } from 'pstdio-extensions/bridge/webview-runtime-html';
|
|
3
|
+
|
|
4
|
+
export declare const getExtensionRuntimeScript: () => string;
|
|
5
|
+
|
|
6
|
+
export { renderExtensionRuntimeHtml }
|
|
7
|
+
|
|
8
|
+
export { renderInlineExtensionRuntimeHtml }
|
|
9
|
+
|
|
10
|
+
export { }
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const r = '// Generated by packages/pstdio-extensions/scripts/build-runtime.ts\nfunction u(){let G=globalThis;if(G.window!==void 0&&G.document!==void 0)return"browser";if(G.WorkerGlobalScope!==void 0&&G.self!==void 0&&G.self instanceof G.WorkerGlobalScope||G.window===void 0&&G.self!==void 0&&typeof G.importScripts=="function")return"worker";let J=G.process;if(J&&typeof J=="object"){let K=J.versions??{},Q=J.release?.name;if(K.bun||Q==="bun"||G.Bun!==void 0)return"bun";if(K.node&&Q==="node")return"node"}return G.Bun===void 0?"browser":"bun"}function b(){return u()}function k(){return b()==="worker"}function A(){let G=b();return G==="node"||G==="bun"}function v(){return window.self!==window.top}function p(G){let J={};return function K(Q,z=""){Object.keys(Q).forEach(($)=>{let Z=z?`${z}.${$}`:$;Q[$]===Object(Q[$])&&K(Q[$],Z),typeof Q[$]=="function"&&(J[Z]=Q[$],delete Q[$])})}(G),J}function i(G){return!G||G==="null"?"*":G}function l(G,J,K){if(!G||typeof G!="object")return G;let Q=Array.isArray(J)?J:J.split(".").map(($)=>$.match(/^\\d+$/)?Number($):$),z=G;for(let $=0;$<Q.length;$++){let Z=Q[$];$===Q.length-1?z[Z]=K:((!z[Z]||typeof z[Z]!="object")&&(z[Z]=typeof Q[$+1]=="number"?[]:{}),z=z[Z])}return G}function r(G=10){let J="";for(let K=0;K<G;K++)J+="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789".charAt(Math.floor(Math.random()*62));return J}var y=b(),B=null;if(y==="node"||y==="bun")try{let G=globalThis.require;B=G?.("node:worker_threads")?.parentPort??null}catch{}function o(){if(A())return B;if(k())return self;if(v())return window.parent;throw Error("No valid target found for postMessage")}function C(G,J,K,Q){if(!G)throw Error("Rimless Error: No target specified for postMessage");if(A()&&G===B){G.postMessage(J,{transfer:Q});return}if(k()){G.postMessage(J,{transfer:Q});return}if(G.postMessage){G.postMessage(J,{targetOrigin:i(K),transfer:Q});return}throw Error("Rimless Error: Invalid target for postMessage")}function I(G){return B!==null&&G===B}function x(G,J,K){I(G)?G.on(J,K):("addEventListener"in G)&&G.addEventListener(J,K)}function L(G,J,K){I(G)?G.off(J,K):("removeEventListener"in G)&&G.removeEventListener(J,K)}function R(G){return G.data||G}var N=function(G){return G.MESSAGE="message",G}({}),D=function(G){return G.HANDSHAKE_REQUEST="RIMLESS/HANDSHAKE_REQUEST",G.HANDSHAKE_REPLY="RIMLESS/HANDSHAKE_REPLY",G.RPC_REQUEST="RIMLESS/RPC_REQUEST",G.RPC_RESOLVE="RIMLESS/RPC_RESOLVE",G.RPC_REJECT="RIMLESS/RPC_REJECT",G}({}),w=Symbol();function s(G={},J,K,Q,z){let $=[];for(let[Z,X]of Object.entries(G)){async function P(F){let{action:j,callID:Y,connectionID:q,callName:O,args:W=[]}=R(F);if(j!==D.RPC_REQUEST||!Y||!O||O!==Z||q!==J)return;let H={action:D.RPC_RESOLVE,callID:Y,callName:O,connectionID:q,error:null,result:null},V;try{H.result=await X(...W,z),H.result?.[w]&&(V=H.result[w]??[],delete H.result[w])}catch(T){H.action=D.RPC_REJECT,H.error=JSON.parse(JSON.stringify(T,Object.getOwnPropertyNames(T)))}C(Q,H,F?.origin,V)}x(K,N.MESSAGE,P),$.push(()=>L(K,N.MESSAGE,P))}return()=>$.forEach((Z)=>Z())}function a(G,J,K,Q=[],z,$){return(...Z)=>new Promise((X,P)=>{let F=r();function j(O){let{callID:W,connectionID:H,callName:V,result:T,error:d,action:_}=R(O);if(!(!W||!V)&&V===G&&W===F&&H===J){if(_===D.RPC_RESOLVE)return X(T);if(_===D.RPC_REJECT)return P(d)}}let Y={action:D.RPC_REQUEST,args:Z,callID:F,callName:G,connectionID:J},q=Z.reduce((O,W)=>W[w]?.length?O.concat(W[w]):O,Z[w]??[]);x(z,N.MESSAGE,j),Q.push(()=>L(z,N.MESSAGE,j)),C($,Y,K?.origin,q)})}function t(G={},J=[],K,Q,z,$){let Z={...G},X=[];for(let P of J)l(Z,P,a(P,K,Q,X,z,$));return{remote:Z,unregisterRemote:()=>X.forEach((P)=>P())}}function n(G={},J){return new Promise(async(K)=>{let Q=p(G),z=o(),$=self||window;async function Z(X){let P=R(X);if(P?.action!==D.HANDSHAKE_REPLY)return;let{remote:F,unregisterRemote:j}=t(P.schema,P.methodNames,P.connectionID,X,$,z),Y=s(Q,P.connectionID,$,z,F);return await J?.onConnectionSetup?.(F),C(z,{action:D.HANDSHAKE_REPLY,connectionID:P.connectionID},X?.origin),K({remote:F,close:()=>{L($,N.MESSAGE,Z),j(),Y()},id:P.connectionID})}x($,N.MESSAGE,Z),C(z,{action:D.HANDSHAKE_REQUEST,methodNames:Object.keys(Q),schema:G})})}var S={connect:n};var e=(G)=>typeof G==="object"&&G!==null,E=(G)=>{try{let J=JSON.stringify(G);if(typeof J==="string"&&J.length>0)return J}catch{}try{return String(G)}catch{return"Unknown error"}},f=(G)=>{if(G instanceof Error)return{message:G.message,stack:G.stack};if(typeof G==="string")return{message:G};if(e(G)){let J=typeof G.message==="string"?G.message:null,K=typeof G.stack==="string"?G.stack:void 0;if(J)return K?{message:J,stack:K}:{message:J};return{message:E(G)}}if(G===null||G===void 0)return{message:"Unknown error"};return{message:E(G)}};var U=(G)=>({id:G}),M=(G,J)=>({id:G,kind:J.kind,label:J.label,description:J.description,metadata:J.metadata}),UG={sidebar:M("project.sidebar",{kind:"view"}),headerPrimary:M("project.headerPrimary",{kind:"menu"}),headerOverflow:M("project.headerOverflow",{kind:"menu"}),settingsPanels:M("project.settingsPanels",{kind:"settings"})},FG={headerPrimary:M("session.headerPrimary",{kind:"menu"}),headerOverflow:M("session.headerOverflow",{kind:"menu"}),transcriptActions:M("session.transcriptActions",{kind:"menu"})},MG={headerPrimary:M("workspace.headerPrimary",{kind:"menu"}),headerOverflow:M("workspace.headerOverflow",{kind:"menu"}),sidebar:M("workspace.sidebar",{kind:"view"})},YG={opened:U("project.opened")},HG={started:U("session.started"),resumed:U("session.resumed"),awaitingInput:U("session.awaitingInput"),succeeded:U("session.succeeded"),failed:U("session.failed"),completed:U("session.completed")},DG={created:U("workspace.created"),provision:U("workspace.provision"),ready:U("workspace.ready"),archived:U("workspace.archived"),deleted:U("workspace.deleted")},jG={removed:U("worktree.removed")},OG={committed:U("git.committed"),rebased:U("git.rebased"),merged:U("git.merged"),conflicted:U("git.conflicted")};var GG=["commands.execute","resource.open","notification.show","notification.action","notification.resolve","notification.dismiss","preferences.get","preferences.set","extension.settings.all","extension.settings.get","extension.settings.set","extension.settings.delete","terminal.session","files.upload","files.list","files.delete"],JG=["host.dispatchKeyboardEvent"],WG=[...GG,...JG];var g=(G,J)=>({call:async(K,Q)=>await G({method:K,params:Q}),onEvent:J}),h=(G)=>{let J=G,K=new Set;return{get:()=>J,subscribe:(Q)=>{return K.add(Q),()=>K.delete(Q)},set:(Q)=>{J=Q;for(let z of K)z(J)}}};var c="pstdio-extension-mount",KG=()=>{let G=new Map;return{get length(){return G.size},clear:()=>G.clear(),getItem:(J)=>G.get(J)??null,key:(J)=>Array.from(G.keys())[J]??null,removeItem:(J)=>G.delete(J),setItem:(J,K)=>G.set(J,K)}},QG=()=>{for(let G of["localStorage","sessionStorage"])try{window[G]}catch{Object.defineProperty(window,G,{configurable:!0,value:KG()})}},m=(G,J)=>{let K=document.documentElement,Q=G==="dark"?"light":"dark";K.classList.remove(Q),K.classList.add(G),K.setAttribute("data-theme",G),K.style.colorScheme=G;for(let[z,$]of Object.entries(J))if(z.startsWith("--"))K.style.setProperty(z,$)},ZG=(G)=>{for(let J of G){let K=document.createElement("link");K.rel="stylesheet",K.href=J,document.head.appendChild(K)}},$G=()=>{let G=document.getElementById(c);if(!G)G=document.createElement("div"),G.id=c,G.style.height="100%",G.style.width="100%",document.body.appendChild(G);return G},zG=(G)=>G instanceof HTMLInputElement||G instanceof HTMLTextAreaElement||G instanceof HTMLSelectElement||G instanceof HTMLElement&&G.isContentEditable,PG=async()=>{QG();let G=h(void 0),J=new Map,K=(Z,X)=>{let P=J.get(Z)??new Set;return P.add(X),J.set(Z,P),()=>{P.delete(X)}},Q,z=!1,$=await S.connect({init:async(Z)=>{try{m(Z.theme,Z.themeVariables),ZG(Z.styles),G.set(Z.props);let X=$G(),P=await import(Z.moduleUrl),F=P.default??(P.mount?P:void 0);if(!F?.mount)throw Error("Extension module does not export a default view (defineExtensionView).");let j=g((q)=>$.remote.call(q),K),Y=await F.mount(X,j,G);if(Q=typeof Y==="function"?Y:void 0,!z)z=!0,document.addEventListener("keydown",(q)=>{if(!q.ctrlKey&&!q.metaKey&&!q.altKey)return;if(zG(q.target)&&!q.shiftKey)return;$.remote.call({method:"host.dispatchKeyboardEvent",params:{key:q.key,code:q.code,ctrlKey:q.ctrlKey,metaKey:q.metaKey,altKey:q.altKey,shiftKey:q.shiftKey,repeat:q.repeat}}).catch(()=>{})},!0)}catch(X){let P=f(X);throw $.remote.runtimeError(P),X instanceof Error?X:Error(P.message)}},themeUpdate:(Z)=>{m(Z.theme,Z.variables)},propsUpdate:(Z)=>{G.set(Z.props)},hostEvent:(Z)=>{for(let X of J.get(Z.scope)??[])X(Z.payload)}});$.remote.ready({}),window.addEventListener("beforeunload",()=>{Q?.()})};PG();\n', t = "pstdio-extension-mount", o = (e) => e.replaceAll("&", "&").replaceAll('"', """).replaceAll("<", "<"), i = (e) => e.replaceAll("<\/script", "<\\/script").replaceAll("<!--", "<\\!--"), n = (e) => `<!doctype html>
|
|
2
|
+
<html lang="en">
|
|
3
|
+
<head>
|
|
4
|
+
<meta charset="utf-8" />
|
|
5
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
6
|
+
<style>
|
|
7
|
+
html, body {
|
|
8
|
+
height: 100%;
|
|
9
|
+
margin: 0;
|
|
10
|
+
background: transparent;
|
|
11
|
+
}
|
|
12
|
+
#${t} {
|
|
13
|
+
height: 100%;
|
|
14
|
+
width: 100%;
|
|
15
|
+
display: block;
|
|
16
|
+
min-height: 0;
|
|
17
|
+
}
|
|
18
|
+
</style>
|
|
19
|
+
</head>
|
|
20
|
+
<body>
|
|
21
|
+
<div id="${t}"></div>
|
|
22
|
+
${e}
|
|
23
|
+
</body>
|
|
24
|
+
</html>
|
|
25
|
+
`, s = (e) => n(`<script src="${o(e)}"><\/script>`), a = (e) => n(`<script>${i(e)}<\/script>`), c = () => r;
|
|
26
|
+
export {
|
|
27
|
+
c as getExtensionRuntimeScript,
|
|
28
|
+
s as renderExtensionRuntimeHtml,
|
|
29
|
+
a as renderInlineExtensionRuntimeHtml
|
|
30
|
+
};
|
|
31
|
+
//# sourceMappingURL=webview-runtime.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"webview-runtime.js","sources":["../../pstdio-extensions/src/bridge/webview-runtime/runtime.bundle.js?raw","../../pstdio-extensions/src/bridge/webview-runtime/runtime-html.ts","../src/webview-runtime/index.ts"],"sourcesContent":["export default \"// Generated by packages/pstdio-extensions/scripts/build-runtime.ts\\nfunction u(){let G=globalThis;if(G.window!==void 0&&G.document!==void 0)return\\\"browser\\\";if(G.WorkerGlobalScope!==void 0&&G.self!==void 0&&G.self instanceof G.WorkerGlobalScope||G.window===void 0&&G.self!==void 0&&typeof G.importScripts==\\\"function\\\")return\\\"worker\\\";let J=G.process;if(J&&typeof J==\\\"object\\\"){let K=J.versions??{},Q=J.release?.name;if(K.bun||Q===\\\"bun\\\"||G.Bun!==void 0)return\\\"bun\\\";if(K.node&&Q===\\\"node\\\")return\\\"node\\\"}return G.Bun===void 0?\\\"browser\\\":\\\"bun\\\"}function b(){return u()}function k(){return b()===\\\"worker\\\"}function A(){let G=b();return G===\\\"node\\\"||G===\\\"bun\\\"}function v(){return window.self!==window.top}function p(G){let J={};return function K(Q,z=\\\"\\\"){Object.keys(Q).forEach(($)=>{let Z=z?`${z}.${$}`:$;Q[$]===Object(Q[$])&&K(Q[$],Z),typeof Q[$]==\\\"function\\\"&&(J[Z]=Q[$],delete Q[$])})}(G),J}function i(G){return!G||G===\\\"null\\\"?\\\"*\\\":G}function l(G,J,K){if(!G||typeof G!=\\\"object\\\")return G;let Q=Array.isArray(J)?J:J.split(\\\".\\\").map(($)=>$.match(/^\\\\d+$/)?Number($):$),z=G;for(let $=0;$<Q.length;$++){let Z=Q[$];$===Q.length-1?z[Z]=K:((!z[Z]||typeof z[Z]!=\\\"object\\\")&&(z[Z]=typeof Q[$+1]==\\\"number\\\"?[]:{}),z=z[Z])}return G}function r(G=10){let J=\\\"\\\";for(let K=0;K<G;K++)J+=\\\"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789\\\".charAt(Math.floor(Math.random()*62));return J}var y=b(),B=null;if(y===\\\"node\\\"||y===\\\"bun\\\")try{let G=globalThis.require;B=G?.(\\\"node:worker_threads\\\")?.parentPort??null}catch{}function o(){if(A())return B;if(k())return self;if(v())return window.parent;throw Error(\\\"No valid target found for postMessage\\\")}function C(G,J,K,Q){if(!G)throw Error(\\\"Rimless Error: No target specified for postMessage\\\");if(A()&&G===B){G.postMessage(J,{transfer:Q});return}if(k()){G.postMessage(J,{transfer:Q});return}if(G.postMessage){G.postMessage(J,{targetOrigin:i(K),transfer:Q});return}throw Error(\\\"Rimless Error: Invalid target for postMessage\\\")}function I(G){return B!==null&&G===B}function x(G,J,K){I(G)?G.on(J,K):(\\\"addEventListener\\\"in G)&&G.addEventListener(J,K)}function L(G,J,K){I(G)?G.off(J,K):(\\\"removeEventListener\\\"in G)&&G.removeEventListener(J,K)}function R(G){return G.data||G}var N=function(G){return G.MESSAGE=\\\"message\\\",G}({}),D=function(G){return G.HANDSHAKE_REQUEST=\\\"RIMLESS/HANDSHAKE_REQUEST\\\",G.HANDSHAKE_REPLY=\\\"RIMLESS/HANDSHAKE_REPLY\\\",G.RPC_REQUEST=\\\"RIMLESS/RPC_REQUEST\\\",G.RPC_RESOLVE=\\\"RIMLESS/RPC_RESOLVE\\\",G.RPC_REJECT=\\\"RIMLESS/RPC_REJECT\\\",G}({}),w=Symbol();function s(G={},J,K,Q,z){let $=[];for(let[Z,X]of Object.entries(G)){async function P(F){let{action:j,callID:Y,connectionID:q,callName:O,args:W=[]}=R(F);if(j!==D.RPC_REQUEST||!Y||!O||O!==Z||q!==J)return;let H={action:D.RPC_RESOLVE,callID:Y,callName:O,connectionID:q,error:null,result:null},V;try{H.result=await X(...W,z),H.result?.[w]&&(V=H.result[w]??[],delete H.result[w])}catch(T){H.action=D.RPC_REJECT,H.error=JSON.parse(JSON.stringify(T,Object.getOwnPropertyNames(T)))}C(Q,H,F?.origin,V)}x(K,N.MESSAGE,P),$.push(()=>L(K,N.MESSAGE,P))}return()=>$.forEach((Z)=>Z())}function a(G,J,K,Q=[],z,$){return(...Z)=>new Promise((X,P)=>{let F=r();function j(O){let{callID:W,connectionID:H,callName:V,result:T,error:d,action:_}=R(O);if(!(!W||!V)&&V===G&&W===F&&H===J){if(_===D.RPC_RESOLVE)return X(T);if(_===D.RPC_REJECT)return P(d)}}let Y={action:D.RPC_REQUEST,args:Z,callID:F,callName:G,connectionID:J},q=Z.reduce((O,W)=>W[w]?.length?O.concat(W[w]):O,Z[w]??[]);x(z,N.MESSAGE,j),Q.push(()=>L(z,N.MESSAGE,j)),C($,Y,K?.origin,q)})}function t(G={},J=[],K,Q,z,$){let Z={...G},X=[];for(let P of J)l(Z,P,a(P,K,Q,X,z,$));return{remote:Z,unregisterRemote:()=>X.forEach((P)=>P())}}function n(G={},J){return new Promise(async(K)=>{let Q=p(G),z=o(),$=self||window;async function Z(X){let P=R(X);if(P?.action!==D.HANDSHAKE_REPLY)return;let{remote:F,unregisterRemote:j}=t(P.schema,P.methodNames,P.connectionID,X,$,z),Y=s(Q,P.connectionID,$,z,F);return await J?.onConnectionSetup?.(F),C(z,{action:D.HANDSHAKE_REPLY,connectionID:P.connectionID},X?.origin),K({remote:F,close:()=>{L($,N.MESSAGE,Z),j(),Y()},id:P.connectionID})}x($,N.MESSAGE,Z),C(z,{action:D.HANDSHAKE_REQUEST,methodNames:Object.keys(Q),schema:G})})}var S={connect:n};var e=(G)=>typeof G===\\\"object\\\"&&G!==null,E=(G)=>{try{let J=JSON.stringify(G);if(typeof J===\\\"string\\\"&&J.length>0)return J}catch{}try{return String(G)}catch{return\\\"Unknown error\\\"}},f=(G)=>{if(G instanceof Error)return{message:G.message,stack:G.stack};if(typeof G===\\\"string\\\")return{message:G};if(e(G)){let J=typeof G.message===\\\"string\\\"?G.message:null,K=typeof G.stack===\\\"string\\\"?G.stack:void 0;if(J)return K?{message:J,stack:K}:{message:J};return{message:E(G)}}if(G===null||G===void 0)return{message:\\\"Unknown error\\\"};return{message:E(G)}};var U=(G)=>({id:G}),M=(G,J)=>({id:G,kind:J.kind,label:J.label,description:J.description,metadata:J.metadata}),UG={sidebar:M(\\\"project.sidebar\\\",{kind:\\\"view\\\"}),headerPrimary:M(\\\"project.headerPrimary\\\",{kind:\\\"menu\\\"}),headerOverflow:M(\\\"project.headerOverflow\\\",{kind:\\\"menu\\\"}),settingsPanels:M(\\\"project.settingsPanels\\\",{kind:\\\"settings\\\"})},FG={headerPrimary:M(\\\"session.headerPrimary\\\",{kind:\\\"menu\\\"}),headerOverflow:M(\\\"session.headerOverflow\\\",{kind:\\\"menu\\\"}),transcriptActions:M(\\\"session.transcriptActions\\\",{kind:\\\"menu\\\"})},MG={headerPrimary:M(\\\"workspace.headerPrimary\\\",{kind:\\\"menu\\\"}),headerOverflow:M(\\\"workspace.headerOverflow\\\",{kind:\\\"menu\\\"}),sidebar:M(\\\"workspace.sidebar\\\",{kind:\\\"view\\\"})},YG={opened:U(\\\"project.opened\\\")},HG={started:U(\\\"session.started\\\"),resumed:U(\\\"session.resumed\\\"),awaitingInput:U(\\\"session.awaitingInput\\\"),succeeded:U(\\\"session.succeeded\\\"),failed:U(\\\"session.failed\\\"),completed:U(\\\"session.completed\\\")},DG={created:U(\\\"workspace.created\\\"),provision:U(\\\"workspace.provision\\\"),ready:U(\\\"workspace.ready\\\"),archived:U(\\\"workspace.archived\\\"),deleted:U(\\\"workspace.deleted\\\")},jG={removed:U(\\\"worktree.removed\\\")},OG={committed:U(\\\"git.committed\\\"),rebased:U(\\\"git.rebased\\\"),merged:U(\\\"git.merged\\\"),conflicted:U(\\\"git.conflicted\\\")};var GG=[\\\"commands.execute\\\",\\\"resource.open\\\",\\\"notification.show\\\",\\\"notification.action\\\",\\\"notification.resolve\\\",\\\"notification.dismiss\\\",\\\"preferences.get\\\",\\\"preferences.set\\\",\\\"extension.settings.all\\\",\\\"extension.settings.get\\\",\\\"extension.settings.set\\\",\\\"extension.settings.delete\\\",\\\"terminal.session\\\",\\\"files.upload\\\",\\\"files.list\\\",\\\"files.delete\\\"],JG=[\\\"host.dispatchKeyboardEvent\\\"],WG=[...GG,...JG];var g=(G,J)=>({call:async(K,Q)=>await G({method:K,params:Q}),onEvent:J}),h=(G)=>{let J=G,K=new Set;return{get:()=>J,subscribe:(Q)=>{return K.add(Q),()=>K.delete(Q)},set:(Q)=>{J=Q;for(let z of K)z(J)}}};var c=\\\"pstdio-extension-mount\\\",KG=()=>{let G=new Map;return{get length(){return G.size},clear:()=>G.clear(),getItem:(J)=>G.get(J)??null,key:(J)=>Array.from(G.keys())[J]??null,removeItem:(J)=>G.delete(J),setItem:(J,K)=>G.set(J,K)}},QG=()=>{for(let G of[\\\"localStorage\\\",\\\"sessionStorage\\\"])try{window[G]}catch{Object.defineProperty(window,G,{configurable:!0,value:KG()})}},m=(G,J)=>{let K=document.documentElement,Q=G===\\\"dark\\\"?\\\"light\\\":\\\"dark\\\";K.classList.remove(Q),K.classList.add(G),K.setAttribute(\\\"data-theme\\\",G),K.style.colorScheme=G;for(let[z,$]of Object.entries(J))if(z.startsWith(\\\"--\\\"))K.style.setProperty(z,$)},ZG=(G)=>{for(let J of G){let K=document.createElement(\\\"link\\\");K.rel=\\\"stylesheet\\\",K.href=J,document.head.appendChild(K)}},$G=()=>{let G=document.getElementById(c);if(!G)G=document.createElement(\\\"div\\\"),G.id=c,G.style.height=\\\"100%\\\",G.style.width=\\\"100%\\\",document.body.appendChild(G);return G},zG=(G)=>G instanceof HTMLInputElement||G instanceof HTMLTextAreaElement||G instanceof HTMLSelectElement||G instanceof HTMLElement&&G.isContentEditable,PG=async()=>{QG();let G=h(void 0),J=new Map,K=(Z,X)=>{let P=J.get(Z)??new Set;return P.add(X),J.set(Z,P),()=>{P.delete(X)}},Q,z=!1,$=await S.connect({init:async(Z)=>{try{m(Z.theme,Z.themeVariables),ZG(Z.styles),G.set(Z.props);let X=$G(),P=await import(Z.moduleUrl),F=P.default??(P.mount?P:void 0);if(!F?.mount)throw Error(\\\"Extension module does not export a default view (defineExtensionView).\\\");let j=g((q)=>$.remote.call(q),K),Y=await F.mount(X,j,G);if(Q=typeof Y===\\\"function\\\"?Y:void 0,!z)z=!0,document.addEventListener(\\\"keydown\\\",(q)=>{if(!q.ctrlKey&&!q.metaKey&&!q.altKey)return;if(zG(q.target)&&!q.shiftKey)return;$.remote.call({method:\\\"host.dispatchKeyboardEvent\\\",params:{key:q.key,code:q.code,ctrlKey:q.ctrlKey,metaKey:q.metaKey,altKey:q.altKey,shiftKey:q.shiftKey,repeat:q.repeat}}).catch(()=>{})},!0)}catch(X){let P=f(X);throw $.remote.runtimeError(P),X instanceof Error?X:Error(P.message)}},themeUpdate:(Z)=>{m(Z.theme,Z.variables)},propsUpdate:(Z)=>{G.set(Z.props)},hostEvent:(Z)=>{for(let X of J.get(Z.scope)??[])X(Z.payload)}});$.remote.ready({}),window.addEventListener(\\\"beforeunload\\\",()=>{Q?.()})};PG();\\n\"","const MOUNT_ID = \"pstdio-extension-mount\";\n\nconst escapeAttribute = (value: string) =>\n value.replaceAll(\"&\", \"&\").replaceAll('\"', \""\").replaceAll(\"<\", \"<\");\n\nconst escapeScriptContent = (value: string) => value.replaceAll(\"</script\", \"<\\\\/script\").replaceAll(\"<!--\", \"<\\\\!--\");\n\nconst renderRuntimeHostDocument = (scriptTag: string) => `<!doctype html>\n<html lang=\"en\">\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1\" />\n <style>\n html, body {\n height: 100%;\n margin: 0;\n background: transparent;\n }\n #${MOUNT_ID} {\n height: 100%;\n width: 100%;\n display: block;\n min-height: 0;\n }\n </style>\n </head>\n <body>\n <div id=\"${MOUNT_ID}\"></div>\n ${scriptTag}\n </body>\n</html>\n`;\n\nexport const getExtensionRuntimeScriptUrl = () => new URL(\"./runtime.bundle.js\", import.meta.url).href;\n\nexport const renderExtensionRuntimeHtml = (scriptUrl: string) =>\n renderRuntimeHostDocument(`<script src=\"${escapeAttribute(scriptUrl)}\"></script>`);\n\nexport const renderInlineExtensionRuntimeHtml = (runtimeScript: string) =>\n renderRuntimeHostDocument(`<script>${escapeScriptContent(runtimeScript)}</script>`);\n","import runtimeScript from \"pstdio-extensions/bridge/webview-runtime.bundle.js?raw\";\n\nexport {\n renderExtensionRuntimeHtml,\n renderInlineExtensionRuntimeHtml,\n} from \"pstdio-extensions/bridge/webview-runtime-html\";\n\n// The guest runtime bundle is inlined here so a host app can serve it without\n// depending on the private pstdio-extensions package.\nexport const getExtensionRuntimeScript = () => runtimeScript;\n"],"names":["runtimeScript","MOUNT_ID","escapeAttribute","value","replaceAll","escapeScriptContent","renderRuntimeHostDocument","scriptTag","renderExtensionRuntimeHtml","scriptUrl","renderInlineExtensionRuntimeHtml","getExtensionRuntimeScript"],"mappings":"AAAA,MAAAA,IAAe,m/QCATC,IAAW,0BAEXC,IAAkBA,CAACC,MACvBA,EAAMC,WAAW,KAAK,OAAO,EAAEA,WAAW,KAAK,QAAQ,EAAEA,WAAW,KAAK,MAAM,GAE3EC,IAAsBA,CAACF,MAAkBA,EAAMC,WAAW,aAAY,YAAY,EAAEA,WAAW,QAAQ,QAAQ,GAE/GE,IAA4BA,CAACC,MAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,SAWhDN,CAAQ;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,eASFA,CAAQ;AAAA,MACjBM,CAAS;AAAA;AAAA;AAAA,GAOFC,IAA6BA,CAACC,MACzCH,EAA0B,gBAAgBJ,EAAgBO,CAAS,CAAC,cAAa,GAEtEC,IAAmCA,CAACV,MAC/CM,EAA0B,WAAWD,EAAoBL,CAAa,CAAC,YAAW,GC9BvEW,IAA4BA,MAAMX;"}
|