castle-web-cli 0.4.222 → 0.4.224
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/api.d.ts +1 -0
- package/dist/api.js +8 -0
- package/dist/index.js +31 -0
- package/dist/init.js +1 -1
- package/dist/platformDoc.js +1 -0
- package/dist/playPagePolicy.d.ts +2 -0
- package/dist/playPagePolicy.js +81 -0
- package/dist/resetLeaderboards.d.ts +14 -0
- package/dist/resetLeaderboards.js +38 -0
- package/dist/serve.d.ts +1 -1
- package/dist/serve.js +8 -5
- package/dist/shell/assets/{index-C1ZRv-OZ.js → index-D9oRe6Yi.js} +2 -2
- package/dist/shell/index.html +1 -1
- package/kits/base/castle.json +1 -1
- package/kits/base/sdk/README.md +11 -3
- package/kits/base/sdk/runtime.js +7 -0
- package/kits/multiplayer-2d/castle.json +2 -2
- package/package.json +1 -1
package/dist/api.d.ts
CHANGED
|
@@ -179,6 +179,7 @@ export interface DeckMeta {
|
|
|
179
179
|
}
|
|
180
180
|
export declare function deckMeta(deckId: string): Promise<DeckMeta | null>;
|
|
181
181
|
export declare function webDeckSource(deckId: string): Promise<WebDeckSource | null>;
|
|
182
|
+
export declare function clearDeckLeaderboards(deckId: string): Promise<void>;
|
|
182
183
|
export declare function saveWebDeckSource(deckId: string, uploadId: string, expectedS3Key?: string | null): Promise<WebDeckSource>;
|
|
183
184
|
export type CloudDeckKit = 'PHYSICS_2D' | 'PHYSICS_3D' | 'MULTIPLAYER_2D' | 'MULTIPLAYER_3D' | 'TURN_BASED' | 'NONE';
|
|
184
185
|
export interface RegisteredCloudDeck {
|
package/dist/api.js
CHANGED
|
@@ -292,6 +292,14 @@ export async function webDeckSource(deckId) {
|
|
|
292
292
|
handleAPIError(data);
|
|
293
293
|
return pickData(data, 'webDeckSource');
|
|
294
294
|
}
|
|
295
|
+
// Starts every leaderboard on the deck over from empty. Ghost allows it only for
|
|
296
|
+
// the deck's creator.
|
|
297
|
+
export async function clearDeckLeaderboards(deckId) {
|
|
298
|
+
const data = await graphql(`mutation($deckId: ID!) {
|
|
299
|
+
clearDeckLeaderboards(deckId: $deckId)
|
|
300
|
+
}`, { deckId });
|
|
301
|
+
handleAPIError(data);
|
|
302
|
+
}
|
|
295
303
|
// `expectedS3Key` is the save precondition: omitted (undefined) means no check, null means
|
|
296
304
|
// "there must be no saved source yet", and a key means "the saved source must still be this
|
|
297
305
|
// one" -- otherwise Ghost refuses with WEB_DECK_SOURCE_STALE. The argument is left out of the
|
package/dist/index.js
CHANGED
|
@@ -8,6 +8,8 @@ import { saveDeck } from './save-deck.js';
|
|
|
8
8
|
import { getDeck } from './get-deck.js';
|
|
9
9
|
import { addImport, updateImport } from './imports.js';
|
|
10
10
|
import { listDecks } from './list-decks.js';
|
|
11
|
+
import { isYes, resetLeaderboards } from './resetLeaderboards.js';
|
|
12
|
+
import { readCastleJson } from './castleJson.js';
|
|
11
13
|
import { getCliVersion, init } from './init.js';
|
|
12
14
|
import { install } from './install.js';
|
|
13
15
|
import { check } from './check.js';
|
|
@@ -91,6 +93,31 @@ function readStdin() {
|
|
|
91
93
|
process.stdin.on('error', reject);
|
|
92
94
|
});
|
|
93
95
|
}
|
|
96
|
+
async function askTerminal(question) {
|
|
97
|
+
const readline = await import('readline/promises');
|
|
98
|
+
const terminal = readline.createInterface({ input: process.stdin, output: process.stdout });
|
|
99
|
+
try {
|
|
100
|
+
return isYes(await terminal.question(question));
|
|
101
|
+
}
|
|
102
|
+
finally {
|
|
103
|
+
terminal.close();
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// `castle-web reset-leaderboards [dir] [--deck-id ID] [--yes]`.
|
|
107
|
+
async function resetLeaderboardsCommand() {
|
|
108
|
+
const deckDir = path.resolve(findPositionalDir());
|
|
109
|
+
await resetLeaderboards({
|
|
110
|
+
deckId: getFlagValue('--deck-id') ?? readCastleJson(deckDir)?.deckId,
|
|
111
|
+
yes: hasFlag('--yes'),
|
|
112
|
+
}, {
|
|
113
|
+
signedIn: !!config.getToken(),
|
|
114
|
+
deckTitle: async (deckId) => (await api.deckMeta(deckId))?.title ?? null,
|
|
115
|
+
clearDeckLeaderboards: api.clearDeckLeaderboards,
|
|
116
|
+
interactive: !!process.stdin.isTTY,
|
|
117
|
+
confirm: askTerminal,
|
|
118
|
+
log: (line) => console.log(line),
|
|
119
|
+
});
|
|
120
|
+
}
|
|
94
121
|
function readServeSocketPort(dir) {
|
|
95
122
|
try {
|
|
96
123
|
const serveJson = JSON.parse(fs.readFileSync(path.join(path.resolve(dir), '.castle', 'serve.json'), 'utf-8'));
|
|
@@ -160,6 +187,7 @@ function usage() {
|
|
|
160
187
|
castle-web get-deck <dir> --side [--deck-id ID] [--json] (fetches the saved copy into <dir>/.castle/agent/saved-source/<stamp>/, touching nothing else)
|
|
161
188
|
castle-web source-status <dir> [--adopt] [--notify] [--json] (whether the deck's saved copy is newer than this folder)
|
|
162
189
|
castle-web list-decks [dir] [--kind mine|saved|kits] (decks this one could import; ids are what add-import takes)
|
|
190
|
+
castle-web reset-leaderboards [dir] [--deck-id ID] [--yes] (clears every leaderboard on the deck, for good; creator only; --yes skips the prompt)
|
|
163
191
|
castle-web add-import <deckId|url|kit> [dir] [--as ALIAS] (adds another deck, or a kit this CLI ships, as a read-only dependency in imports/)
|
|
164
192
|
castle-web fork-import-file <imports/...> [dir] (this deck's own version of one imported file)
|
|
165
193
|
castle-web revert-import-file <imports/...> [dir]
|
|
@@ -547,6 +575,9 @@ async function main() {
|
|
|
547
575
|
await listDecks(findPositionalDir(), { kind: getFlagValue('--kind') });
|
|
548
576
|
break;
|
|
549
577
|
}
|
|
578
|
+
case 'reset-leaderboards':
|
|
579
|
+
await resetLeaderboardsCommand();
|
|
580
|
+
break;
|
|
550
581
|
case 'fork-import-file': {
|
|
551
582
|
// `castle-web fork-import-file <imports/...> [dir]`
|
|
552
583
|
const { deckDir, relPosix } = readImportFileArgs();
|
package/dist/init.js
CHANGED
|
@@ -54,7 +54,7 @@ if (!(await mountEditorRoute())) startGame(initCard());
|
|
|
54
54
|
// Registry version of castle-web-sdk to inject when scaffolding from a
|
|
55
55
|
// globally-installed castle-web (not from inside the workspace). Bumped
|
|
56
56
|
// alongside cli/sdk version bumps.
|
|
57
|
-
const PUBLISHED_SDK_VERSION = '0.4.
|
|
57
|
+
const PUBLISHED_SDK_VERSION = '0.4.42';
|
|
58
58
|
// Range, not a pin: `castle-web-fonts` is its own package precisely so a tenth
|
|
59
59
|
// face can ship without a cli release, and a caret range means an existing
|
|
60
60
|
// deck's next install picks it up. Nothing here has to move when it does.
|
package/dist/platformDoc.js
CHANGED
|
@@ -224,6 +224,7 @@ const COMMON_SECTIONS = `## Imports are read-only
|
|
|
224
224
|
- **The deck plays inside a fixed 5:7 portrait card, not the full window.** The card is sized to fit the screen (at most about 450x630px), clips overflow, and does not scroll. Design the whole layout to fit inside that portrait box: size UI relative to the card with percentages, flex/grid, \`min()\`, \`clamp()\`, or viewport-relative units instead of fixed tall panels. Let playfields scale down on smaller cards rather than overflowing; anything outside the card edges is cut off. The SDK exports \`CARD_RATIO\` (= 5 / 7) if you need the exact ratio.
|
|
225
225
|
- **Hand-rolled \`<canvas>\` elements must account for devicePixelRatio, or the game looks blurry on phones.** Size the backing store to the CSS layout size times \`devicePixelRatio\` (e.g. \`canvas.width = rect.width * dpr\`), keep the CSS width/height as the layout size, and scale the 2D context (\`ctx.scale(dpr, dpr)\`) so drawing code stays in CSS units — re-apply on resize. Kit decks don't need to do this by hand; the kit's engine already configures its canvas for DPR.
|
|
226
226
|
- Exception: deliberate pixel art wants a fixed low-resolution backing store with \`image-rendering: pixelated\` CSS instead — don't DPR-scale that; the crisp chunky look is the point.
|
|
227
|
+
- **A WebGL canvas must be created with \`preserveDrawingBuffer: true\`, or every in-page capture of the deck comes back blank** — the Play panel's Snap and \`npm run screenshot\` both read the canvas after the frame has been shown, and by then the browser has cleared it, so the image is just the card's background. Pass it through whatever library makes the canvas: \`new THREE.WebGLRenderer({ preserveDrawingBuffer: true })\`, PixiJS \`app.init({ preserveDrawingBuffer: true })\`, or \`canvas.getContext('webgl2', { preserveDrawingBuffer: true })\`. A 2D canvas needs nothing, and kit decks already set it.
|
|
227
228
|
|
|
228
229
|
## Multiplayer
|
|
229
230
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
// What a published deck runs under, applied to the play page the serve hands
|
|
2
|
+
// out, so a deck that only works without these limits fails in Play and not
|
|
3
|
+
// after it ships.
|
|
4
|
+
// Copy of DECK_CSP in ghost-server `src/rest/modules/sceneData.ts`, which every
|
|
5
|
+
// published bundle gets. The two must match; change both together.
|
|
6
|
+
const CDN_HOSTS = 'https://esm.sh https://cdnjs.cloudflare.com';
|
|
7
|
+
const PLAY_HOSTS = 'wss://*.play.castle.xyz';
|
|
8
|
+
const DECK_CSP = [
|
|
9
|
+
"default-src 'self' data: blob:",
|
|
10
|
+
`script-src 'self' 'unsafe-inline' 'unsafe-eval' 'wasm-unsafe-eval' data: blob: ${CDN_HOSTS}`,
|
|
11
|
+
"style-src 'self' 'unsafe-inline' data: blob: https://fonts.googleapis.com",
|
|
12
|
+
"font-src 'self' data: blob: https://fonts.gstatic.com",
|
|
13
|
+
"img-src 'self' data: blob:",
|
|
14
|
+
"media-src 'self' data: blob:",
|
|
15
|
+
`connect-src 'self' data: blob: ${CDN_HOSTS} ${PLAY_HOSTS}`,
|
|
16
|
+
"frame-src 'none'",
|
|
17
|
+
"child-src 'self' blob:",
|
|
18
|
+
"worker-src 'self' blob:",
|
|
19
|
+
"form-action 'none'",
|
|
20
|
+
"base-uri 'self'",
|
|
21
|
+
].join('; ');
|
|
22
|
+
// A <meta> policy binds only what follows it, so it goes first in <head>.
|
|
23
|
+
const DECK_CSP_TAG = `<meta http-equiv="Content-Security-Policy" content="${DECK_CSP}">`;
|
|
24
|
+
// Copy of EXPERIMENTAL_WEB_IFRAME_BLOCK_SCRIPT in castle-client
|
|
25
|
+
// `mobile/js/common/experimentalWebHardening.ts`: the mobile app removes every
|
|
26
|
+
// frame element from a deck. One change: html2canvas composites a card through
|
|
27
|
+
// an iframe of its own (class `html2canvas-container`), and the Play panel's
|
|
28
|
+
// capture uses it, so that iframe is kept.
|
|
29
|
+
const IFRAME_BLOCK_SCRIPT = `<script>
|
|
30
|
+
(function () {
|
|
31
|
+
if (window.__castleIframeBlockInstalled) return;
|
|
32
|
+
window.__castleIframeBlockInstalled = true;
|
|
33
|
+
var SELECTOR = 'iframe,frame,frameset';
|
|
34
|
+
// Captured at document-start, before any deck code runs: a deck that later
|
|
35
|
+
// no-ops Node.prototype.removeChild can't quietly disarm the sweep with it.
|
|
36
|
+
var removeChild = Node.prototype.removeChild;
|
|
37
|
+
var queryAll = Element.prototype.querySelectorAll;
|
|
38
|
+
var matches = Element.prototype.matches;
|
|
39
|
+
function cut(node) {
|
|
40
|
+
if (node && node.parentNode && node.className !== 'html2canvas-container') removeChild.call(node.parentNode, node);
|
|
41
|
+
}
|
|
42
|
+
function drop(node) {
|
|
43
|
+
if (!node || node.nodeType !== 1) return;
|
|
44
|
+
if (matches.call(node, SELECTOR)) {
|
|
45
|
+
cut(node);
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
var found = queryAll.call(node, SELECTOR);
|
|
49
|
+
for (var i = 0; i < found.length; i++) cut(found[i]);
|
|
50
|
+
}
|
|
51
|
+
function sweep() { drop(document.documentElement); }
|
|
52
|
+
window.__castleApplyIframeBlock = sweep;
|
|
53
|
+
sweep();
|
|
54
|
+
if (window.MutationObserver) {
|
|
55
|
+
new MutationObserver(function (records) {
|
|
56
|
+
for (var i = 0; i < records.length; i++) {
|
|
57
|
+
var added = records[i].addedNodes;
|
|
58
|
+
for (var j = 0; j < added.length; j++) drop(added[j]);
|
|
59
|
+
}
|
|
60
|
+
}).observe(document.documentElement || document, { childList: true, subtree: true });
|
|
61
|
+
}
|
|
62
|
+
document.addEventListener('DOMContentLoaded', sweep);
|
|
63
|
+
})();
|
|
64
|
+
</script>`;
|
|
65
|
+
// The play page is the one loaded with `edit=0`: the Play panel and playtest
|
|
66
|
+
// both build its URL with playPagePath, and the page's own role script reads
|
|
67
|
+
// the same parameter.
|
|
68
|
+
export function isPlayPageUrl(url) {
|
|
69
|
+
if (!url) {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
try {
|
|
73
|
+
return new URL(url, 'http://localhost').searchParams.get('edit') === '0';
|
|
74
|
+
}
|
|
75
|
+
catch {
|
|
76
|
+
return false;
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
export function playPageHeadInjection() {
|
|
80
|
+
return `\n ${DECK_CSP_TAG}\n ${IFRAME_BLOCK_SCRIPT}`;
|
|
81
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export interface ResetLeaderboardsOptions {
|
|
2
|
+
deckId?: string;
|
|
3
|
+
yes: boolean;
|
|
4
|
+
}
|
|
5
|
+
export interface ResetLeaderboardsDeps {
|
|
6
|
+
signedIn: boolean;
|
|
7
|
+
deckTitle(deckId: string): Promise<string | null>;
|
|
8
|
+
clearDeckLeaderboards(deckId: string): Promise<void>;
|
|
9
|
+
interactive: boolean;
|
|
10
|
+
confirm(question: string): Promise<boolean>;
|
|
11
|
+
log(line: string): void;
|
|
12
|
+
}
|
|
13
|
+
export declare function resetLeaderboards(options: ResetLeaderboardsOptions, deps: ResetLeaderboardsDeps): Promise<void>;
|
|
14
|
+
export declare function isYes(answer: string): boolean;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
// `castle-web reset-leaderboards` -- clears every leaderboard on a deck, for its
|
|
2
|
+
// creator. Ghost's clearDeckLeaderboards starts each variable and scope on the
|
|
3
|
+
// deck over from empty; the old scores are never shown again, and there is no
|
|
4
|
+
// undo. The classic editor's "Reset all leaderboards" button sends the same
|
|
5
|
+
// mutation.
|
|
6
|
+
//
|
|
7
|
+
// This command is for a signed-in creator at a terminal. The mutation is left
|
|
8
|
+
// out of the cloud sandbox's GraphQL allowlist, so the deck agent cannot send it.
|
|
9
|
+
export async function resetLeaderboards(options, deps) {
|
|
10
|
+
const deckId = options.deckId;
|
|
11
|
+
if (!deckId) {
|
|
12
|
+
throw new Error('No deckId. Either pass --deck-id <id> or run from a directory whose castle.json has one.');
|
|
13
|
+
}
|
|
14
|
+
if (!deps.signedIn) {
|
|
15
|
+
throw new Error('Not logged in. Run `castle-web login`.');
|
|
16
|
+
}
|
|
17
|
+
// A deck the server does not return has no title to show; the reset itself
|
|
18
|
+
// still decides whether the deck exists and is this user's.
|
|
19
|
+
const title = await deps.deckTitle(deckId);
|
|
20
|
+
const named = title ? `"${title}" (${deckId})` : `deck ${deckId}`;
|
|
21
|
+
if (!options.yes) {
|
|
22
|
+
if (!deps.interactive) {
|
|
23
|
+
throw new Error(`Not resetting the leaderboards of ${named}: there is no terminal to confirm on. Pass --yes to reset anyway.`);
|
|
24
|
+
}
|
|
25
|
+
const question = `Reset every leaderboard on ${named}? All of its scores are cleared, and this cannot be undone. [y/N] `;
|
|
26
|
+
if (!(await deps.confirm(question))) {
|
|
27
|
+
deps.log('Nothing was reset.');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
await deps.clearDeckLeaderboards(deckId);
|
|
32
|
+
deps.log(`Reset every leaderboard on ${named}. They start empty from the next score.`);
|
|
33
|
+
}
|
|
34
|
+
// The answer to the confirmation question: only a y or yes resets.
|
|
35
|
+
export function isYes(answer) {
|
|
36
|
+
const word = answer.trim().toLowerCase();
|
|
37
|
+
return word === 'y' || word === 'yes';
|
|
38
|
+
}
|
package/dist/serve.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export declare function appendCapped(file: string, line: string): void;
|
|
|
3
3
|
export declare function isViteClientUpgrade(req: http.IncomingMessage): boolean;
|
|
4
4
|
export declare function isAllowedShellHost(hostHeader: string | undefined, configuredHost?: string): boolean;
|
|
5
5
|
export declare function isAllowedContentFilesRequest(role: 'edit' | 'play' | null, method: string | undefined, reqPath: string): boolean;
|
|
6
|
-
export declare function injectDeckHead(html: string): string;
|
|
6
|
+
export declare function injectDeckHead(html: string, play?: boolean): string;
|
|
7
7
|
export declare function serve(dir: string, options?: {
|
|
8
8
|
port?: string;
|
|
9
9
|
host?: string;
|
package/dist/serve.js
CHANGED
|
@@ -32,6 +32,7 @@ import { atomicWriteFileSync } from './atomicFile.js';
|
|
|
32
32
|
import { isSameOriginUpgrade } from './wsOrigin.js';
|
|
33
33
|
import { createAssetCompression } from './assetCompression.js';
|
|
34
34
|
import { playCoverHeadInjection } from './playCoverGate.js';
|
|
35
|
+
import { isPlayPageUrl, playPageHeadInjection } from './playPagePolicy.js';
|
|
35
36
|
import { resolveServerConfig } from './castleJson.js';
|
|
36
37
|
import { startDevSessionServer, } from './devSessionServer.js';
|
|
37
38
|
// The log is a tail, not an archive: append, and once it passes the cap drop
|
|
@@ -530,9 +531,10 @@ function injectIntoHead(html, injected) {
|
|
|
530
531
|
}
|
|
531
532
|
// Everything the serve adds to a deck page's <head>: Castle's favicon, the
|
|
532
533
|
// shell-origin and readiness script, the redbox, the console forward, and --
|
|
533
|
-
// behind CASTLE_PLAY_COVER -- the Play cover capture bridge.
|
|
534
|
-
//
|
|
535
|
-
|
|
534
|
+
// behind CASTLE_PLAY_COVER -- the Play cover capture bridge. The play page
|
|
535
|
+
// also gets a published deck's CSP and iframe removal (playPagePolicy.ts).
|
|
536
|
+
// Exported for the tests that pin what a deck page receives.
|
|
537
|
+
export function injectDeckHead(html, play = false) {
|
|
536
538
|
// Give the deck page Castle's favicon too -- it's a real page when
|
|
537
539
|
// opened directly (play surface / `?edit=0`), not just the editor's
|
|
538
540
|
// iframe. Injected here rather than in the kit templates so bare
|
|
@@ -548,7 +550,8 @@ export function injectDeckHead(html) {
|
|
|
548
550
|
// The bridge is placed last, by playCoverPlacement.ts: it leads <head> when
|
|
549
551
|
// nothing that could run comes before it, else it goes at the very start
|
|
550
552
|
// of the document -- and nothing the serve adds lands ahead of it.
|
|
551
|
-
const
|
|
553
|
+
const policy = play ? playPageHeadInjection() : '';
|
|
554
|
+
const injected = `${policy}${favicon}\n <script>
|
|
552
555
|
window.CastleEmbed={edit:true,host:'dev'};
|
|
553
556
|
window.__castleShellOrigin=(function(){
|
|
554
557
|
var h=location.hostname.toLowerCase();
|
|
@@ -608,7 +611,7 @@ function castlePlugin(security, ideServer, agentServer, scriptErrors, configured
|
|
|
608
611
|
name: 'castle-dev',
|
|
609
612
|
transformIndexHtml: {
|
|
610
613
|
order: 'pre',
|
|
611
|
-
handler: injectDeckHead,
|
|
614
|
+
handler: (html, context) => injectDeckHead(html, isPlayPageUrl(context.originalUrl)),
|
|
612
615
|
},
|
|
613
616
|
configureServer(server) {
|
|
614
617
|
server.middlewares.use(createAssetCompression());
|
|
@@ -380,8 +380,8 @@ ${s.join(`
|
|
|
380
380
|
@keyframes castle-lb-spin { to { transform: rotate(360deg); } }
|
|
381
381
|
`,EG=`<svg viewBox="0 0 24 24" fill="none" stroke="#E3E6FD" stroke-width="2.5" stroke-linecap="round"><path d="M4 4 L20 20 M20 4 L4 20"/></svg>`;function DG(e,t,n){let r=e.createElement(t);return r.className=n,r}function OG(e,t){e.classList.toggle(`castle-lb-hidden`,t)}function kG(e,t){OG(e,!t),e.src=t??``}function AG(e){let t=DG(e,`div`,`castle-lb-row`),n=DG(e,`div`,`castle-lb-place`),r=DG(e,`div`,`castle-lb-avatar-box castle-lb-tappable`),i=DG(e,`img`,`castle-lb-avatar`),a=DG(e,`img`,`castle-lb-avatar-frame`),o=DG(e,`div`,`castle-lb-name-box castle-lb-tappable`),s=DG(e,`div`,`castle-lb-name-row`),c=DG(e,`div`,`castle-lb-username`),l=DG(e,`img`,`castle-lb-badge`),u=DG(e,`div`,`castle-lb-annotation`),d=DG(e,`div`,`castle-lb-score`);return r.append(i,a),s.append(c,l),o.append(s,u),t.append(n,r,o,d),{root:t,place:n,avatarBox:r,avatar:i,frame:a,nameBox:o,username:c,badge:l,annotation:u,score:d}}function jG(e){let t=DG(e,`div`,`castle-lb-row`),n=DG(e,`img`,`castle-lb-party-single`),r=DG(e,`div`,`castle-lb-party-multi`),i=DG(e,`img`,`castle-lb-party-multi-a`),a=DG(e,`img`,`castle-lb-party-multi-b`),o=DG(e,`div`,`castle-lb-name-box`),s=DG(e,`div`,`castle-lb-party-name`),c=DG(e,`div`,`castle-lb-party-time`);return r.append(DG(e,`div`,`castle-lb-party-multi-slot castle-lb-party-multi-slot-a`),i,DG(e,`div`,`castle-lb-party-multi-slot castle-lb-party-multi-slot-b`),a),o.append(s),t.append(n,r,o,c),{root:t,single:n,multi:r,multiA:i,multiB:a,name:s,time:c}}function MG(e){let t=DG(e,`div`,`castle-lb-tabs`),n=DG(e,`div`,`castle-lb-tab castle-lb-at-foryou`);n.textContent=`FOR YOU`;let r=DG(e,`div`,`castle-lb-tab castle-lb-at-global`);r.textContent=`GLOBAL`;let i=DG(e,`div`,`castle-lb-indicator castle-lb-at-foryou`),a=DG(e,`div`,`castle-lb-indicator castle-lb-at-global`),o=DG(e,`div`,`castle-lb-close`);return o.innerHTML=EG,t.append(n,r,DG(e,`div`,`castle-lb-rule`),i,a,o),{root:t,forYou:n,global:r,forYouIndicator:i,globalIndicator:a,close:o}}function NG(e){let t=DG(e,`div`,`castle-lb-root`),n=DG(e,`div`,`castle-lb-panel`),r=MG(e),i=DG(e,`div`,`castle-lb-header`),a=DG(e,`div`,`castle-lb-header-name`),o=DG(e,`div`,`castle-lb-header-label`);i.append(a,o);let s=DG(e,`div`,`castle-lb-rows`),c=[];for(let t=0;t<gG;t+=1){let t=AG(e);c.push(t),s.append(t.root)}let l=DG(e,`div`,`castle-lb-row castle-lb-parties-header`);l.textContent=`PARTIES TO PLAY WITH`,s.append(l);let u=[];for(let t=0;t<_G;t+=1){let t=jG(e);u.push(t),s.append(t.root)}let d=DG(e,`div`,`castle-lb-spinner`),f=DG(e,`div`,`castle-lb-share`);return n.append(r.root,i,s,d),t.append(n,f),{root:t,panel:n,tabs:r,nameHeader:a,labelHeader:o,rows:c,partiesHeader:l,parties:u,spinner:d,share:f}}var PG=60,FG=PG*60,IG=FG*24,LG=IG*7,RG=IG*365/12,zG=IG*365;function BG(e){if(e===0)return`0`;let t=e>0?e:1,[n,r]=t<PG?[Math.round(t),`s`]:t<FG?[Math.round(t/PG),`m`]:t<IG?[Math.round(t/FG),`h`]:t<LG?[Math.round(t/IG),`d`]:t<RG?[Math.round(t/LG),`w`]:t<zG?[Math.round(t/RG),`mo`]:[Math.round(t/zG),`yr`];return`${n}${r.length>1&&n!==1?`${r}s`:r}`}function VG(e){let t=new Date(e).getTime();return Number.isFinite(t)?BG((Date.now()-t)/1e3):null}function HG(e,t){let n=t>0?gG-1-t:gG;if(e.length<=n)return e;let r=e.slice();for(;r.length>n;){let e=-1;for(let t=r.length-1;t>=0;--t)if(!r[t]?.isRequiredUser){e=t;break}if(e===-1)break;r.splice(e,1)}return r.slice(0,n)}function UG(e){return e.isDeckCreator?`Creator`:e.isLinkSharer?`Challenger`:e.user.isAnonymous?`Tap to save your score`:e.isRequiredUser?`You`:null}function WG(e,t,n){OG(e.root,!1),OG(e.place,!n),e.place.textContent=t.place===null?``:`#${t.place}`,e.score.textContent=t.score,e.username.textContent=t.user.isAnonymous?`You are not signed in`:t.user.username??``,e.username.style.color=t.user.isAnonymous?bG:t.user.color??(t.isRequiredUser?`#FFFFFF`:vG),e.avatar.src=t.user.avatarUrl??hG,kG(e.badge,t.user.badgeUrl),kG(e.frame,t.user.frameUrl);let r=UG(t);e.annotation.textContent=r??``,OG(e.annotation,!r),e.nameBox.classList.toggle(`castle-lb-annotated`,!!r)}function GG(e,t){OG(e.root,!1),e.name.textContent=t.name;let n=t.avatarUrls[0]??null,r=t.avatarUrls[1]??null,i=!!(n&&r);kG(e.single,i?null:n),OG(e.multi,!i),e.multiA.src=n??``,e.multiB.src=r??``;let a=t.lastMessageTime?VG(t.lastMessageTime):null;e.time.textContent=a??``,OG(e.time,!a),e.time.style.width=a?`calc(${30+a.length*20} * var(--castle-lb-u))`:``}function KG(e){OG(e.panel,!0),OG(e.share,!0),OG(e.spinner,!0),OG(e.partiesHeader,!0),e.nameHeader.textContent=``,e.labelHeader.textContent=``,e.rows.forEach(e=>OG(e.root,!0)),e.parties.forEach(e=>OG(e.root,!0))}function qG(e,t,n){let r=()=>{n(t.user.isAnonymous?{type:`savePrompt`,userId:t.user.userId}:{type:`openProfile`,userId:t.user.userId,username:t.user.username})};e.avatarBox.onclick=r,e.nameBox.onclick=r}function JG(e,t,n,r){let i=n===`forYou`,a=t.loading===!0;OG(e.panel,!1),e.tabs.forYou.classList.toggle(`castle-lb-tab-active`,i),e.tabs.global.classList.toggle(`castle-lb-tab-active`,!i),OG(e.tabs.forYouIndicator,!i),OG(e.tabs.globalIndicator,i),e.nameHeader.textContent=i?`RELEVANT PLAYERS`:`NAME`,e.labelHeader.textContent=t.label.toUpperCase(),OG(e.nameHeader,a),OG(e.labelHeader,a),OG(e.spinner,!a),OG(e.share,!1),e.share.textContent=t.isAnonymous?`Share Deck`:`Share Leaderboard`,e.share.classList.toggle(`castle-lb-share-narrow`,t.isAnonymous);let o=i&&t.showParties&&!a?t.parties.slice(0,_G):[],s=a?[]:HG(i?t.followList:t.list,o.length);e.rows.forEach((e,t)=>{let n=s[t];if(!n){OG(e.root,!0);return}WG(e,n,!i),qG(e,n,r)}),OG(e.partiesHeader,o.length===0),e.parties.forEach((e,t)=>{let n=o[t];n?GG(e,n):OG(e.root,!0)})}function YG(e){if(e.getElementById(xG))return;let t=e.createElement(`style`);t.id=xG,t.textContent=XG()+TG,(e.head??e.documentElement).append(t)}function XG(){return`@font-face{font-family:'Castle Overlay';font-weight:500;font-display:block;src:url(data:font/woff2;base64,${QG}) format('woff2')}`}function ZG(e,t){let n=e.ownerDocument;YG(n),n.defaultView?.getComputedStyle(e).position===`static`&&(e.style.position=`relative`);let r=NG(n);e.append(r.root);let i=null,a=`forYou`,o=e=>{try{t(e)}catch{}},s=()=>{i&&JG(r,i,a,o)},c=e=>{!i||i.loading||a===e||(a=e,o({type:`switchTab`,tab:e}),s())},l=()=>{let t=e.clientWidth;t>0&&r.root.style.setProperty(`--castle-lb-u`,`${t/800}px`)};r.root.addEventListener(`click`,e=>{e.target===r.root&&o({type:`close`})}),r.tabs.close.addEventListener(`click`,()=>o({type:`close`})),r.tabs.forYou.addEventListener(`click`,()=>c(`forYou`)),r.tabs.global.addEventListener(`click`,()=>c(`global`)),r.share.addEventListener(`click`,()=>o({type:`share`})),l();let u=typeof ResizeObserver>`u`?null:new ResizeObserver(l);u?.observe(e);let d=()=>{i=null,a=`forYou`,KG(r)};return d(),{render(e){i=e,a=`forYou`,l(),s()},clear:d,destroy(){u?.disconnect(),r.root.remove()}}}var QG=`d09GMgABAAAAAGwIABEAAAABGVAAAGukAAEzMwAAAAAAAAAAAAAAAAAAAAAAAAAAGoFAG4GOHhyJBgZgAIkgCGAJnAwRCAqCvVSCmjoBNgIkA40AC4ZOAAQgBYlEB5MzDIE9Wz8DcQQHh6sE/t+u4V2nSKYfbGlWwXbl4bbBWzvrB1xkNiJyOwRK/69nZP///+9IKjJmk0HabaIIoIIe9Zf/JubuFoJczLPAqxzjkHOXi465KHfFcwY/9eVcvEAHPoz04BObPVU9lVMlXLCT8DraTdaJ9aJZ7LzUYKspC+8mdJy0LiTyw/Rll9ZsKfNTJth6HGHRja1HqjucMFZwOAQKilPZdE56wXaxKxOP9vh1SezhSd5hUjvG7dvEf5wKhRJ8LCx4NPP+aHLmW4f7/FsCa9/bWCGsOob9NfKCYc/wQfeESJlZbXq1Xf8iLiY9lOYpkprfWdhE7k5Pw6u0ZTCxTKvE1PgqMHY9RNVYp14iyC7+q2dxeMQHEYFiCCOl9uf5bf6571FSBpEiIYI2mCh2bK0uy0WKVUvn0sSoZf7v0rlwncaqXZSK/5Wq9d5P3Q2AkqmQSSpMCgETooonCvayYPg09oajCxuk23lDGqDprLBK2gBVTdpGRO9ySe5yEW3Ea2lyqSo6WqyIyAbM2LzYzFgf5sB+YuiGT4zDubzYxo5REytAxSjk5GbnH4mTlp7v9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72TRjAZRRnloOEjwbmR7YNl3TYzH+XweQ9xndn36wUYfeUDilSs6oFHYecvHhjnJ6vAm+BM59pWNZuokD7H9kmNz+AFovjvNzKbEhNzkU/m0n/d8PY6W0Kq3SJt8rzKbVi7xM3QgoxlE8ld2+6G+my9x8kfWSYhLwutGLh9tXQLcZVj433WAY6x9tQMwql7zx+nDaeciTPdaIg5YsyG6dIJcl/MRoUvzuuHe5/kWG9EVhWoliT/tACsyB1hXDi8JYqUiaC1WZu/xrGMNC7J/O1+j9QWtf25d/5Oe6H/uRV/qY8mYcHB6XfjY/QXjB6gynPjzUwph8cWdt6kpfD0+v02en4WgGMQxB3yjQvljWhVV+5kQrnhu9b4UVWwA0xTXv8H99KEtglbfowVHbgrZ+HlT3DOw8vJJ83c3RBTHxYg/OdPgcTcXvE0o/wIbS32bKSgm7AwA=`;function $G(e){let t=e;return!!(t&&Array.isArray(t.list)&&Array.isArray(t.followList))}function eK(e){window.open(e,`_blank`)?.focus()}function tK(e){if(!e.deckId)return null;let t=new URLSearchParams({lv:e.variable,lt:e.type,label:e.label});return e.scope&&t.set(`ls`,e.scope),`https://castle.xyz/d/${e.deckId}?${t.toString()}`}function nK(){let e=g.useRef(null),t=g.useRef(null),n=g.useRef(null),[r,i]=g.useState(!1);return g.useEffect(()=>{let r=e.current;if(!r)return;let a=ZG(r,e=>{if(e.type===`close`)i(!1),a.clear();else if(e.type===`share`&&n.current){let e=tK(n.current);e&&eK(e)}else e.type===`openProfile`&&e.username&&eK(`https://castle.xyz/@${e.username}`)});t.current=a;let o=cS(`castle_leaderboard_show`,e=>{$G(e.payload)&&(n.current=e.payload,a.render(e.payload),i(!0))});return()=>{o(),a.destroy(),t.current=null}},[]),(0,G.jsx)(`div`,{ref:e,className:`play-leaderboard-overlay`,style:{position:`absolute`,inset:0,visibility:r?`visible`:`hidden`,pointerEvents:r?`auto`:`none`}})}var rK=/\.(md|txt)$/i;function iK(e,t){let n=t;return!n||n.type!==`castle-params-applied`||typeof n.path!=`string`||!e.paths.has(n.path)||(typeof n.seq==`number`?n.seq:null)!==e.seq?null:{path:n.path,ok:n.ok===!0}}function aK(e){let t=!1;for(let n of e){if(n.tuned&&n.tuned.length>0){t=!0;continue}if(!(n.affected.length===0&&rK.test(n.path)))return`restart`}return t?`await-ack`:`ignore`}function oK(e,t={}){let n=[`edit=0`];return t.logs&&n.push(`logs=1`),e&&n.push(`scene=${encodeURIComponent(e)}`),`/index.html?${n.join(`&`)}`}var sK=1568,cK=/^data:image\/(png|jpe?g|gif|webp);base64,[A-Za-z0-9+/=]+$/,lK=new Set([`image/jpeg`,`image/heic`,`image/heif`]),uK=.9,dK=12e7,fK=class extends Error{};function pK(e){return typeof e==`string`&&/^data:image\//i.test(e)}function mK(e){return new Promise((t,n)=>{let r=new Image;r.onload=()=>t(r),r.onerror=()=>n(Error(`Could not decode image.`)),r.src=e})}function hK(e){return new Promise((t,n)=>{let r=new FileReader;r.onload=()=>typeof r.result==`string`?t(r.result):n(Error(`Could not read file.`)),r.onerror=()=>n(r.error??Error(`Could not read file.`)),r.readAsDataURL(e)})}function gK(e){let t=/^data:([^;,]+)/.exec(e);return t?t[1].toLowerCase():``}function _K(e,t){let n=Math.max(e,t);return n>1568?sK/n:1}function vK(e,t){let n=lK.has(t)?null:e.toDataURL(`image/png`);if(n!==null&&n.length<=11744051.2)return n;let r=e.toDataURL(`image/jpeg`,uK);if(r.length>11744051.2)throw new fK(`Image is too large to send.`);return r}async function yK(e){let t=gK(e),n=await mK(e);if(!n.naturalWidth||!n.naturalHeight)throw Error(`Could not measure image.`);if(n.naturalWidth*n.naturalHeight>dK)throw new fK(`Image is too large to resize.`);let r=_K(n.naturalWidth,n.naturalHeight);if(r===1&&cK.test(e)&&e.length<=11744051.2)return e;let i=document.createElement(`canvas`);i.width=Math.max(1,Math.round(n.naturalWidth*r)),i.height=Math.max(1,Math.round(n.naturalHeight*r));let a=i.getContext(`2d`);if(!a)throw Error(`Could not resize image.`);return a.drawImage(n,0,0,i.width,i.height),vK(i,t)}function bK(e){return typeof e.name==`string`&&e.name?e.name:`file`}function xK(e){let t=typeof e.type==`string`?e.type:``;return(typeof e.size==`number`?e.size:0)>33554432?`too-large`:t===``||t===`application/octet-stream`||t.startsWith(`image/`)?null:`unreadable`}async function SK(e,t=6){let n=[],r=[],i=0;for(let a of Array.from(e)){let e=xK(a);if(e){r.push({name:bK(a),reason:e});continue}if(n.length>=t){i+=1;continue}try{let e=await yK(await hK(a));n.push({name:bK(a),dataUrl:e})}catch(e){r.push({name:bK(a),reason:e instanceof fK?`too-large`:`unreadable`})}}return{images:n,skipped:r,dropped:i}}function CK(e,t){let n=[],r=e.filter(e=>e.reason===`unreadable`),i=e.filter(e=>e.reason===`too-large`);if(r.length===1?n.push(`Couldn't read ${r[0].name}.`):r.length>1&&n.push(`Couldn't read ${r.length} files.`),i.length===1?n.push(`${i[0].name} is too large.`):i.length>1&&n.push(`${i.length} files are too large.`),t>0){let e=t===1?`1 was`:`${t} were`;n.push(`Only 6 images fit, so ${e} left out.`)}return n.length>0?n.join(` `):null}var wK=[],TK=new Set;function EK(e){if(TK.size>0){let t=!1;for(let n of[...TK])t=n(e)||t;return t}return wK.length>=6?!1:(wK=[...wK,e],!0)}function DK(){let e=wK;return wK=[],e}function OK(e){return TK.add(e),()=>{TK.delete(e)}}var kK=[`ttfbMs`,`domContentLoadedMs`,`loadMs`,`resources`,`scripts`,`transferKb`],AK=6e5;function jK(e){if(!e||typeof e!=`object`)return null;let t=e,n=e=>typeof e==`number`&&Number.isInteger(e)&&e>=0&&e<AK?e:null,r={};for(let e of kK){let i=n(t[e]);if(i===null)return null;r[e]=i}if(t.firstContentfulPaintMs===null)r.firstContentfulPaintMs=null;else{let e=n(t.firstContentfulPaintMs);if(e===null)return null;r.firstContentfulPaintMs=e}return r}function MK(e,t){let n=window.__CASTLE_CONTENT_ORIGINS__?.[e];if(!n)throw Error(`Deck content origin was not configured.`);return new URL(t,`${n}/`).toString()}var NK=new Map,PK=new WeakMap,FK=1,IK=1,LK=!1;function RK(e){let t=PK.get(e);if(t)return t;let n=`e${IK++}`;return PK.set(e,n),n}var zK=new Set;function BK(e){return zK.add(e),()=>{zK.delete(e)}}function VK(){for(let e of[...zK])e()}function HK(){let e=[];for(let[t,n]of NK)n.frame.isConnected||e.push(t);if(e.length){for(let t of e)NK.get(t)?.port.close(),NK.delete(t);VK()}}function UK(e){for(let[t,n]of NK)n.frame===e&&(n.port.close(),NK.delete(t));HK(),VK()}function WK(){HK();let e=new Set;for(let t of NK.values())e.add(RK(t.frame));return e}function GK(e){HK();for(let[t,n]of NK){if(e.source!==n.frame.contentWindow)continue;let r;try{r=new URL(n.frame.src).origin}catch{return null}return e.origin===r?{role:n.role,frameId:t,elementId:RK(n.frame)}:null}return null}function KK(){LK||(LK=!0,window.addEventListener(`message`,e=>{let t=e.data;if(!t||t.type!==`castle-content-frame-ready`)return;let n=GK(e);if(!(!n||t.role!==n.role)&&window.parent!==window){let e=jK(t.metrics);window.parent.postMessage(e?{type:`castle-content-frame-ready`,role:n.role,metrics:e}:{type:`castle-content-frame-ready`,role:n.role},window.__CASTLE_HOST_ORIGIN__||`*`)}}),gS(e=>{let t=typeof e.requestId==`string`?e.requestId:null;if(t){let n=t.indexOf(`:`);if(n>0){let r=t.slice(0,n),i=NK.get(r);i&&i.port.postMessage({...e,requestId:t.slice(n+1)});return}}if(e.type===`restart`||e.type===`files_changed`||e.type===`screenshot_request`)for(let t of NK.values())t.port.postMessage(e)}))}function qK(e,t,n){if(!e.src||e.src===`about:blank`)return;KK(),HK();for(let[t,n]of NK)n.frame===e&&(n.port.close(),NK.delete(t));let r=`f${FK++}`;RK(e);let i=new MessageChannel,a=new URL(e.src).origin;NK.set(r,{frame:e,role:t,port:i.port1}),i.port1.onmessage=e=>{let i=e.data;if(!i||typeof i.type!=`string`)return;let o=i;typeof i.requestId==`string`&&(i.type===`write_file`||i.type===`rename_file`||i.type===`castle_command`||i.type===`castle_command_cancel`)&&(o={...i,requestId:`${r}:${i.requestId}`}),vS({type:`deck_bridge`,frameId:r,role:t,contentOrigin:a,...t===`play`&&n?{playSessionSlot:n}:{},message:o})},i.port1.start(),e.contentWindow?.postMessage({type:`castle-bridge-init`,role:t},a,[i.port2]),e.contentWindow?.postMessage({type:`castle-request-content-frame-ready`},a)}var JK=`castle-capture-cover`,YK=`castle-capture-cover-result`,XK=1500;function ZK(e,t=8e3){let n=e.contentWindow,r;try{r=new URL(e.src).origin}catch{return Promise.reject(Error(`No deck is running.`))}if(!n||e.src===`about:blank`)return Promise.reject(Error(`No deck is running.`));let i=`cap-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,8)}`;return new Promise((a,o)=>{let s=()=>{clearTimeout(c),clearInterval(d),window.removeEventListener(`message`,l)},c=setTimeout(()=>{s(),o(Error(`The deck didn't answer in time. Try again once it has loaded, or update its base kit if it never does.`))},t),l=e=>{if(e.source!==n||e.origin!==r)return;let t=e.data;!t||t.type!==YK||t.requestId!==i||(s(),t.ok!==!1&&pK(t.dataUrl)?a(t.dataUrl):o(Error(`The deck could not capture itself.`)))};window.addEventListener(`message`,l);let u=()=>{if(!e.isConnected||e.contentWindow!==n){s(),o(Error(`The deck restarted before it answered.`));return}try{n.postMessage({type:JK,requestId:i},r)}catch{s(),o(Error(`The deck restarted before it answered.`))}},d=setInterval(u,XK);u()})}function QK(e){if(window.isSecureContext&&navigator.clipboard?.writeText){navigator.clipboard.writeText(e);return}let t=document.createElement(`textarea`);t.value=e,t.setAttribute(`readonly`,``),t.style.position=`fixed`,t.style.top=`0`,t.style.left=`0`,t.style.opacity=`0`,document.body.appendChild(t),t.focus(),t.select(),t.setSelectionRange(0,t.value.length);try{document.execCommand(`copy`)}finally{t.remove()}}function $K(e){return(0,G.jsxs)(`div`,{className:ux(`castle-feedback-banner`,`castle-feedback-danger`,`files-feedback-banner`,e.className),role:`alert`,children:[(0,G.jsx)(`span`,{className:`castle-icon-cell`,"aria-hidden":`true`,children:(0,G.jsx)(K,{name:`warning`})}),(0,G.jsx)(`span`,{children:e.children}),e.onDismiss?(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon`,onClick:e.onDismiss,"aria-label":`Dismiss`,children:(0,G.jsx)(K,{name:`times`})}):null]})}var eq=new Map,tq=new Set,nq=!1;function rq(){for(let e of[...tq])e()}function iq(e){return`${e.source}:${e.path}`}function aq(e){let t=iq(e),n=eq.get(t);n&&n.message===e.message&&n.line===e.line||(eq.set(t,e),rq())}function oq(e){let t=!1;for(let[n,r]of eq)r.path===e&&(eq.delete(n),t=!0);t&&rq()}function sq(e){let t=!1;for(let[n,r]of eq)r.source===e&&(eq.delete(n),t=!0);t&&rq()}function cq(){let e=WK(),t=!1;for(let[n,r]of eq)r.source===`serve`||e.has(r.source)||(eq.delete(n),t=!0);t&&rq()}function lq(){nq||(nq=!0,cS(`script_error`,e=>{let t=typeof e.path==`string`?e.path:``;t&&aq({path:t,message:typeof e.message==`string`?e.message:`Failed to compile`,line:typeof e.line==`number`?e.line:void 0,column:typeof e.column==`number`?e.column:void 0,source:`serve`})}),cS(`script_ok`,e=>{typeof e.path==`string`&&oq(e.path)}),BK(cq),window.addEventListener(`message`,e=>{let t=e.data;if(!t||t.type!==`castle-frame-error`)return;let n=GK(e);n&&(aq({path:typeof t.path==`string`?t.path:``,message:typeof t.message==`string`?t.message:`The deck hit an error`,line:typeof t.line==`number`&&t.line>0?t.line:void 0,column:typeof t.column==`number`&&t.column>0?t.column:void 0,source:n.elementId}),cq())}),window.addEventListener(`message`,e=>{let t=e.data;if(!t||t.type!==`castle-content-frame-ready`)return;let n=GK(e);n&&(sq(n.elementId),cq())}))}function uq(){let[e,t]=g.useState(()=>[...eq.values()]);return g.useEffect(()=>{lq();let e=()=>t([...eq.values()]);return tq.add(e),cq(),e(),()=>{tq.delete(e)}},[]),e}function dq(e){let t=e.path?`${e.path}${e.line?`:${e.line}`:``}`:``;return t?`${t} — ${e.message}`:e.message}function fq(){let e=uq(),[t,n]=g.useState(``),r=new Set,i=[];for(let t of e){let e=dq(t);r.has(e)||(r.add(e),i.push(e))}let a=i.join(`|`);if(!i.length||a===t)return null;let o=i[0],s=i.length-1;return(0,G.jsxs)($K,{onDismiss:()=>n(a),children:[o,s>0?` (+${s} more)`:``]})}var pq=`castle-play-cover-capture`,mq=`castle-play-cover-cancel`,hq=1400,gq=6*1024*1024,_q=`data:image/png;base64,`,vq={UNSUPPORTED_ELEMENT:`The card contains an element a cover cannot copy (an iframe, video, or script).`,UNSUPPORTED_SHADOW_ROOT:`The card uses a shadow root, which a cover cannot copy.`,UNSUPPORTED_NAMESPACE:`The card contains markup a cover cannot copy (such as MathML).`,UNSUPPORTED_SVG_ELEMENT:`The card contains SVG a cover cannot copy.`,UNSUPPORTED_SVG_REFERENCE:`The card contains SVG that references other content.`,UNSUPPORTED_EVENT_HANDLER:`The card contains SVG with an event handler.`,UNSUPPORTED_RESOURCE:`The card shows an image a cover cannot embed.`,UNSUPPORTED_RESOURCE_SCHEME:`The card shows an image a cover cannot embed.`,UNSUPPORTED_RESOURCE_REFERENCE:`The card shows an image a cover cannot embed.`,RESOURCE_ORIGIN_NOT_ALLOWED:`The card uses an image or font from a site that does not allow copying it.`,RESOURCE_FETCH_FAILED:`An image or font on the card could not be loaded for the cover.`,RESOURCE_TYPE_MISMATCH:`The card shows an animated or unsupported image format (use PNG or JPEG).`,IMAGE_NOT_LOADED:`An image on the card hasn't finished loading. Try again once it shows.`,IMAGE_NOT_READABLE:`The card shows an image from another site that the cover cannot check. Serve it from the deck itself, or allow it with CORS: an Access-Control-Allow-Origin header, plus crossorigin="anonymous" on an <img>.`,IMAGE_CHANGED:`An image on the card loads differently each time, so the cover could not copy the one on screen.`,RESOURCE_BLOCKED_BY_PAGE:`The card uses an image the deck's own content security policy blocks.`,RESOURCE_TOO_LARGE:`An image or font on the card is too large to embed.`,RESOURCE_BUDGET_EXCEEDED:`The images and fonts on the card are too large to embed.`,TOO_MANY_RESOURCES:`The card uses too many images and fonts to embed.`,UNSUPPORTED_FONT:`Text on the card uses a web font the cover cannot embed.`,UNSUPPORTED_FONT_SOURCE:`Text on the card uses a local font the cover cannot embed.`,UNSUPPORTED_FONT_STYLESHEET:`A font stylesheet on the card could not be read.`,UNSUPPORTED_FONT_DESCRIPTOR:`A font on the card uses a setting the cover cannot copy.`,TOO_MANY_FONT_FACES:`The card's fonts load more separate font files than the cover can check. Use fewer fonts, or fewer characters from large ones.`,TOO_MANY_FONT_STYLES:`Text on the card uses more fonts, weights and styles than the cover can check. Use fewer on the card.`,UNSUPPORTED_FONT_DISPLAY:`Text on the card uses a web font with font-display: optional or fallback, so the cover can't tell whether the page is showing it. Use font-display: swap or block.`,FONTS_PENDING:`Fonts were still loading. Try again in a moment.`,UNSUPPORTED_PSEUDO_RESOURCE:`The card uses a CSS pseudo-element image, which a cover cannot copy.`,UNSUPPORTED_PSEUDO_STYLE:`The card styles a first letter, first line or list marker on its own (a drop cap, say), which a cover cannot copy.`,CARD_TEXT_SELECTED:`Text on the card is selected. Click elsewhere to clear it, then try again.`,UNSUPPORTED_HIGHLIGHT:`The card highlights text with the CSS Highlight API, which a cover cannot copy.`,UNSUPPORTED_MARKER:`A list marker on the card uses a web font in a style the cover cannot check.`,UNSUPPORTED_NATIVE_CONTROL:`The card shows a native button, progress or meter bar, which a cover draws unstyled. Style it yourself (appearance: none and your own CSS).`,UNSUPPORTED_TOP_LAYER:`The card has an open modal dialog or popover, which a cover cannot copy. Close it and try again.`,UNSUPPORTED_ANCESTOR_EFFECT:`Something around the card fades, filters, blends or clips it, which a cover cannot copy.`,UNSUPPORTED_IMAGE_SET:`The card uses image-set() for an image, which a cover cannot resolve the same way.`,UNSUPPORTED_FIXED_POSITION:`The card has an element fixed to the page rather than the card, which a cover cannot place the same way.`,UNSUPPORTED_LINE_CLAMP:`The card has a line clamp the cover can't be sure is applied (its box is declared both as -webkit-box and as something else, or in a stylesheet it can't read).`,UNSUPPORTED_FORCED_COLORS:`The browser is in a forced-colors (high contrast) mode, which a cover can't copy. Turn it off to set a cover.`,UNSUPPORTED_PSEUDO_CONTENT:`The card uses CSS generated content a cover cannot copy.`,UNSUPPORTED_SCROLL_LAYOUT:`A scrolled box on the card lays its content out in a way a cover can't copy (flex, grid, sticky or pinned items, or right-to-left). Scroll it back to the top and try again.`,UNSUPPORTED_SCROLLBARS:`The card shows scrollbars, which a cover can't copy. Hide them (scrollbar-width: none) and try again.`,SENSITIVE_FORM_CONTROL:`The card shows a password field.`,UNSUPPORTED_FORM_VALUE:`The card shows a text field or menu, whose contents a cover cannot copy.`,UNSUPPORTED_NODE:`The card contains content a cover cannot copy.`,CANVAS_CONTEXT_UNKNOWN:`A canvas on the card was drawn before the capture could observe it. Restart the deck and try again.`,UNSUPPORTED_CANVAS_CONTEXT:`A canvas on the card uses a drawing mode a cover cannot read (such as WebGPU or bitmaprenderer).`,CANVAS_READBACK_FAILED:`A canvas on the card shows an image from another site, so it cannot be read.`,WEBGL_CAPTURE_REQUIRED:`The WebGL canvas was not drawn during an animation frame.`,WEBGL_NOT_RENDERED_THIS_FRAME:`The WebGL canvas was not drawn during the captured animation frame.`,WEBGL_CAPTURE_STALE:`The WebGL canvas changed while it was being copied. Try again.`,WEBGL_CONTEXT_LOST:`The WebGL canvas lost its context.`,WEBGL_CONTEXT_NOT_TRACKED:`A WebGL canvas on the card was created before the capture could observe it.`,WEBGL_NONDEFAULT_FRAMEBUFFER:`The WebGL canvas was bound to an offscreen framebuffer at the end of the frame.`,WEBGL_NONDEFAULT_READ_FRAMEBUFFER:`The WebGL canvas was bound to an offscreen framebuffer at the end of the frame.`,WEBGL_EMPTY_BUFFER:`The WebGL canvas has no pixels.`,WEBGL_READBACK_FAILED:`The WebGL canvas could not be read.`,WEBGL_TRANSPARENCY_UNSUPPORTED:`The WebGL canvas is transparent; covers need an opaque WebGL canvas.`,APPLICATION_FRAME_TIMEOUT:`The deck did not draw a new frame in time. Is it paused?`,FRAME_NOT_VISIBLE:`The browser paused the deck because it isn't on screen. Bring the Play panel fully into view and try again.`,FRAME_CHANGED_AFTER_CAPTURE:`The card changed while it was being copied. Try again.`,PACKAGE_TOO_COMPLEX:`The card has too many elements to copy.`,PACKAGE_TOO_LARGE:`The card is too large to copy.`,EMPTY_TARGET:`The card has no visible size.`,TARGET_NOT_FOUND:`No card was found to capture.`,UNSUPPORTED_ROOT_TRANSFORM:`The card is rotated or skewed, which a cover cannot copy.`,QUIRKS_MODE_DOCUMENT:`The deck's index.html has no <!doctype html>, so its layout cannot be copied exactly.`,RASTERIZE_BLOCKED:`This browser would not turn the capture into an image. Try Chrome.`,RASTERIZE_FAILED:`The capture could not be turned into an image.`,EFFECT_NOT_REPRODUCIBLE:`The card uses a shadow or blur this browser can't copy into a cover exactly (a backdrop-filter, or a shadow cut off at an edge).`,CAPTURE_UNVERIFIABLE:`This browser can't be checked copying an image or canvas on this card. Set this cover from Chrome or Edge on a computer instead.`,BUILTINS_MODIFIED:`The deck replaces built-in browser functions the cover relies on, so its capture cannot be trusted.`,BROWSER_UNSUPPORTED:`Safari and other WebKit browsers can't make a cover exactly yet. Set this cover from Chrome or Edge on a computer instead.`,RASTERIZE_MISMATCH:`This browser drew the capture differently from the page, so it wasn't used. Try Chrome.`,COVER_TOO_LARGE:`The captured image is too large to use as a cover.`,CAPTURE_BUSY:`A capture is already in progress.`,CAPTURE_TIMEOUT:`The capture took too long.`,CAPTURE_CANCELED:`The capture was canceled.`,NATIVE_CAPTURE_UNAVAILABLE:`This version of the Castle app can't capture a cover. Update the app and try again.`,NATIVE_CAPTURE_FAILED:`The Castle app couldn't copy the screen. Try again.`,KEYBOARD_VISIBLE:`Close the keyboard, then try again.`,CAPTURE_OFFSCREEN:`The card isn't fully on screen. Bring it into view and try again.`,VIEWPORT_ZOOMED:`The page is zoomed. Zoom back out and try again.`,CAPTURE_OBSCURED:`Something is covering the card. Close it and try again.`,EDITOR_NOT_VISIBLE:`The editor has to be on screen to capture a cover. Go back to it and try again.`,NATIVE_CAPTURE_TOO_LARGE:`This frame is too detailed to save as a cover. Try a different moment.`,INVALID_COVER:`The Castle app's capture wasn't a usable image. Try again.`,INVALID_REQUEST:`The cover request was not understood. Update the Castle app and try again.`},yq=`The deck could not be captured.`,bq=`Safari and other WebKit browsers can't copy shadows or blur into a cover exactly. Set this cover from Chrome or Edge on a computer instead.`;function xq(e,t=!1){return t&&e===`EFFECT_NOT_REPRODUCIBLE`?bq:vq[e]??yq}var Sq=/\((?:iPhone|iPad|iPod)[;)]/,Cq=/\b(?:CriOS|FxiOS|EdgiOS|OPiOS|GSA)\//,wq=/\b(?:Chrome|Chromium|HeadlessChrome)\//;function Tq(e){let t=e.userAgent;return Sq.test(t)||Cq.test(t)||e.platform===`MacIntel`&&(e.maxTouchPoints??0)>1?!0:wq.test(t)?!1:/AppleWebKit\//.test(t)||e.vendor===`Apple Computer, Inc.`}var Eq=typeof navigator>`u`?null:{userAgent:navigator.userAgent,platform:navigator.platform,maxTouchPoints:navigator.maxTouchPoints,vendor:navigator.vendor};function Dq(){return typeof window<`u`&&window.__castleCoverAssumeWebKit===!0?!0:Eq!==null&&Tq(Eq)}var Oq={open:!1,preview:null,busy:null,op:0,published:null,notice:null},kq=`Cover set`;function Aq(e,t,n){return e.busy===n&&e.op===t}function jq(e,t,n,r=!1){let i=e.preview?`${t} Your previous capture is still shown.`:t;return{...e,busy:null,notice:r?{kind:n,text:i,final:r}:{kind:n,text:i}}}function Mq(e,t){return t&&e.busy===null}function Nq(e,t){switch(t.type){case`capture-start`:return e.busy?e:{...e,open:!0,busy:`capturing`,op:t.op,notice:null};case`capture-done`:return Aq(e,t.op,`capturing`)?{...e,busy:null,preview:t.preview,published:null,notice:null}:e;case`capture-failed`:return Aq(e,t.op,`capturing`)?jq(e,t.message,`error`,t.final===!0):e;case`capture-canceled`:return Aq(e,t.op,`capturing`)?jq(e,t.message,`info`):e;case`discard`:return e.busy===`publishing`?e:{...Oq,op:e.op};case`publish-start`:return e.busy||!e.preview?e:{...e,busy:`publishing`,op:t.op,notice:null};case`publish-done`:return Aq(e,t.op,`publishing`)?{...e,busy:null,published:e.preview?.id??null,notice:{kind:`success`,text:kq}}:e;case`publish-failed`:return Aq(e,t.op,`publishing`)?{...e,busy:null,notice:{kind:`error`,text:t.message}}:e;default:return e}}var Pq=class extends Error{code;constructor(e,t){super(t),this.name=`CoverRequestError`,this.code=e}},Fq=/^[A-Za-z0-9+/]*={0,2}$/,Iq=`PNG\r
|
|
382
382
|
|
|
383
|
-
`,Lq=new Set([`viewbox`,`transform`,`transform-padded`,`zoom`,`native`]),Rq=[`bitmapsChecked`,`fontFacesChecked`,`unverifiedBitmaps`,`strippedMarks`],zq=100,Bq=1e4;function Vq(e,t){return Number.isSafeInteger(e)&&e>=0&&e<=t?e:null}function Hq(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.geometry!=`string`||!Lq.has(t.geometry))return null;let n=Vq(t.attempts,zq);if(n===null)return null;let r={geometry:t.geometry,attempts:n,bitmapsChecked:0,fontFacesChecked:0,unverifiedBitmaps:0,strippedMarks:0};for(let e of Rq){let n=Vq(t[e],Bq);if(n===null)return null;r[e]=n}return r}function Uq(e){let t=new Image;return t.src=e,t.decode().then(()=>({width:t.naturalWidth,height:t.naturalHeight}))}function Wq(e){throw new Pq(`INVALID_COVER`,e)}function Gq(e){let t=e.endsWith(`==`)?2:e.endsWith(`=`)?1:0;return Math.floor(e.length*3/4)-t}async function Kq(e,t=Uq){let n=e.dataUrl;(typeof n!=`string`||!n.startsWith(`data:image/png;base64,`))&&Wq(`The deck sent back something that is not a PNG.`);let r=n.slice(_q.length);(!r||!Fq.test(r))&&Wq(`The deck sent back an unreadable image.`),Gq(r)>6291456&&Wq(`The capture is larger than the ${gq/(1024*1024)} MB cover limit.`);let i;try{i=atob(r.slice(0,12))}catch{Wq(`The deck sent back an unreadable image.`)}i.slice(0,8)!==Iq&&Wq(`The deck sent back something that is not a PNG.`);let a;try{a=await t(n)}catch{Wq(`The capture could not be decoded as an image.`)}let o=e=>Number.isInteger(e)&&e>=1&&e<=1400;(!o(a.width)||!o(a.height))&&Wq(`The capture is ${a.width}x${a.height}; a cover is at most ${hq} pixels on a side.`),(e.width!==a.width||e.height!==a.height)&&Wq(`The capture is not the size the deck said it was.`);let s={dataUrl:n,width:a.width,height:a.height},c=Hq(e.diagnostics);return c&&(s.diagnostics=c),s}var qq=/^[A-Z][A-Z0-9_]{0,63}$/;function Jq(){return`cover-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`.slice(0,64)}function Yq(e=!1){return Dq()&&!e?`${xq(`BROWSER_UNSUPPORTED`,!0)} (BROWSER_UNSUPPORTED)`:null}function Xq(e){return typeof e.reason==`string`?e.reason:`The capture was canceled.`}function Zq(e){let t=typeof e.code==`string`&&qq.test(e.code)?e.code:`CAPTURE_FAILED`;return new Pq(t,`${xq(t,Dq())} (${t})`)}function Qq(e,t){let n=e.contentWindow,r;try{r=new URL(e.src).origin}catch{return Promise.reject(new Pq(`NO_DECK`,`No deck is running.`))}if(!n||e.src===`about:blank`||r===`null`)return Promise.reject(new Pq(`NO_DECK`,`No deck is running.`));let{signal:i}=t;if(i.aborted)return Promise.reject(new Pq(`CAPTURE_CANCELED`,Xq(i)));let a=Yq();if(a)return Promise.reject(new Pq(`BROWSER_UNSUPPORTED`,a));let o=Jq(),s=e=>{try{n.postMessage({type:e,requestId:o},r)}catch{}};return new Promise((e,a)=>{let c=()=>{window.clearTimeout(d),window.removeEventListener(`message`,f),i.removeEventListener(`abort`,u)},l=e=>{c(),s(mq),a(e)},u=()=>l(new Pq(`CAPTURE_CANCELED`,Xq(i))),d=window.setTimeout(()=>l(new Pq(`CAPTURE_TIMEOUT`,`The deck did not finish the capture in time.`)),t.timeoutMs??3e4),f=t=>{if(t.source!==n||t.origin!==r)return;let i=t.data;!i||i.type!==`castle-play-cover-result`||i.requestId!==o||(c(),i.ok===!0?e(i):a(Zq(i)))};window.addEventListener(`message`,f),i.addEventListener(`abort`,u),s(pq)}).then(e=>Kq(e,t.decode))}var $q=`castle-capture-native-cover`,eJ=`is-native-cover-capture`,tJ={geometry:`native`,attempts:1,bitmapsChecked:0,fontFacesChecked:0,unverifiedBitmaps:0,strippedMarks:0},nJ=!1,rJ=new Set;function iJ(e){nJ!==e&&(nJ=e,rJ.forEach(t=>t(e)))}function aJ(e){let t=gJ();if(!t||!Ob(e)||e.origin!==t)return;let n=e.data;!n||n.type!==`castle-deck-meta`||iJ(n.hostCapabilities?.nativeCover===!0)}typeof window<`u`&&typeof window.addEventListener==`function`&&window.addEventListener(`message`,aJ);function oJ(){return nJ&&gJ()!==null}function sJ(e){return rJ.add(e),()=>{rJ.delete(e)}}function cJ(){return new Promise(e=>{let t=window.requestAnimationFrame?.bind(window);if(!t){window.setTimeout(e,32);return}t(()=>t(()=>e()))})}function lJ(e){let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||r<=0||i<=0?null:{x:t,y:n,width:r,height:i}}function uJ(e,t,n){let r=gJ();if(!r||!nJ)return Promise.reject(new Pq(`NATIVE_CAPTURE_UNAVAILABLE`,`${xq(`NATIVE_CAPTURE_UNAVAILABLE`)} (NATIVE_CAPTURE_UNAVAILABLE)`));let{signal:i}=n;if(i.aborted)return Promise.reject(new Pq(`CAPTURE_CANCELED`,Xq(i)));let a=Jq();return t.classList.add(eJ),new Promise((o,s)=>{let c=!1,l=()=>{c=!0,window.clearTimeout(d),window.removeEventListener(`message`,f),i.removeEventListener(`abort`,u),t.classList.remove(eJ)},u=()=>{c||(l(),s(new Pq(`CAPTURE_CANCELED`,Xq(i))))},d=window.setTimeout(()=>{c||(l(),s(new Pq(`CAPTURE_TIMEOUT`,`${xq(`CAPTURE_TIMEOUT`)} (CAPTURE_TIMEOUT)`)))},n.timeoutMs??2e4);function f(e){if(!Ob(e)||e.origin!==r)return;let t=e.data;!t||t.type!==`castle-capture-native-cover-result`||t.requestId!==a||(l(),t.ok===!0?o(t):s(Zq(t)))}window.addEventListener(`message`,f),i.addEventListener(`abort`,u),(n.nextPaint??cJ)().then(()=>{if(c)return;let t=lJ(e.getBoundingClientRect());if(!t){l(),s(new Pq(`EMPTY_TARGET`,`${xq(`EMPTY_TARGET`)} (EMPTY_TARGET)`));return}try{window.parent.postMessage({type:$q,requestId:a,rect:t},r)}catch{l(),s(new Pq(`NATIVE_CAPTURE_UNAVAILABLE`,`${xq(`NATIVE_CAPTURE_UNAVAILABLE`)} (NATIVE_CAPTURE_UNAVAILABLE)`))}})}).then(e=>Kq(e,n.decode)).then(e=>({...e,diagnostics:tJ}))}var dJ=`castle-set-cover`,fJ=`castle-set-cover-result`,pJ=3e4,mJ=`Covers can only be set from the Castle editor.`,hJ=new Set([`https://castle.xyz`]);function gJ(){if(typeof window>`u`||window.parent===window)return null;let e=window.__CASTLE_HOST_ORIGIN__;return e&&hJ.has(e)?e:null}function _J(){return gJ()!==null}var vJ=new Set([`not_pushed`,`not_an_image`,`upload_failed`]);function yJ(e,t=pJ){let n=gJ();return n?new Promise(r=>{let i=Jq(),a=e=>{window.clearTimeout(o),window.removeEventListener(`message`,s),r(e)},o=window.setTimeout(()=>a({ok:!1,error:`The Castle editor did not respond. Try again.`,reason:`host_timeout`}),t);function s(e){if(!Ob(e)||e.origin!==n)return;let t=e.data;!t||t.type!==fJ||t.requestId!==i||(t.ok===!0?a({ok:!0}):a({ok:!1,error:typeof t.error==`string`&&t.error?t.error:`Could not set the cover.`,reason:typeof t.code==`string`&&vJ.has(t.code)?t.code:`host_refused`}))}window.addEventListener(`message`,s),window.parent.postMessage({type:dJ,requestId:i,dataUrl:e},n)}):Promise.resolve({ok:!1,error:mJ,reason:`no_host`})}var bJ=`castle-play-cover-event`,xJ=/^[A-Z_]{1,40}$/,SJ=12e4;function CJ(e){return Number.isFinite(e)?Math.min(SJ,Math.max(0,Math.round(e))):0}function wJ(e){let t=e instanceof Pq?e.code:`UNKNOWN`;return xJ.test(t)?t:`OTHER`}function TJ(e,t,n){return{event:`capture_succeeded`,captureMs:CJ(t),captureIndex:n,width:e.width,height:e.height,...e.diagnostics}}function EJ(e,t,n){return{event:`capture_refused`,code:wJ(e),captureMs:CJ(t),captureIndex:n}}function DJ(e,t){return e.ok?{event:`use_as_cover_succeeded`,publishMs:CJ(t)}:{event:`use_as_cover_failed`,reason:e.reason??`host_refused`,publishMs:CJ(t)}}function OJ(){let e=new Uint8Array(8);try{crypto.getRandomValues(e)}catch{for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function kJ(e,t){try{let n=gJ();if(!n)return;window.parent.postMessage({type:bJ,sessionId:e,...t},n)}catch{}}var AJ=`The capture was discarded.`,jJ=`The deck restarted, so the capture was canceled.`,MJ=`The Play panel closed, so the capture was canceled.`;function NJ(){let[e,t]=g.useState(oJ);return g.useEffect(()=>(t(oJ()),sJ(()=>t(oJ()))),[]),e}function PJ(e){let t=e.closest(`.play-frame-shell`),n=e.closest(`.play-panel`);return t&&n?{card:t,panel:n}:null}function FJ(){return typeof performance<`u`?performance.now():Date.now()}function IJ(e,t,n){let[r,i]=g.useReducer(Nq,Oq),a=g.useRef(r);a.current=r;let o=g.useRef(n);o.current=n;let s=g.useRef(0),c=g.useRef(null),l=g.useRef(!0),u=g.useRef(null),d=g.useCallback(e=>{let t=c.current;c.current=null,t?.abort(e)},[]);g.useEffect(()=>(l.current=!0,()=>{l.current=!1,d(MJ)}),[d]),g.useEffect(()=>()=>d(jJ),[t,d]);let f=g.useCallback(()=>{let t=e.current;if(!t||!Mq(a.current,o.current))return;let n=++s.current,r=new AbortController;c.current=r,(!a.current.open||!u.current)&&(u.current={id:OJ(),captures:0});let d=u.current,f=++d.captures;a.current.preview&&kJ(d.id,{event:`retake`});let p=FJ();i({type:`capture-start`,op:n});let m=oJ()?PJ(t):null;(m?uJ(m.card,m.panel,{signal:r.signal}):Qq(t,{signal:r.signal})).then(e=>{kJ(d.id,TJ(e,FJ()-p,f)),c.current===r&&(c.current=null),l.current&&i({type:`capture-done`,op:n,preview:{id:n,...e}})},e=>{if(kJ(d.id,EJ(e,FJ()-p,f)),c.current===r&&(c.current=null),!l.current)return;let t=e instanceof Error?e.message:`The deck could not be captured.`,a=e instanceof Pq?e.code:null;i(a===`CAPTURE_CANCELED`?{type:`capture-canceled`,op:n,message:t}:{type:`capture-failed`,op:n,message:t,final:a===`BROWSER_UNSUPPORTED`})})},[e]),p=g.useCallback(()=>{let e=a.current;if(e.busy||!e.preview)return;let t=++s.current,n=u.current?.id??null,r=FJ();i({type:`publish-start`,op:t}),yJ(e.preview.dataUrl).then(e=>{n&&kJ(n,DJ(e,FJ()-r)),l.current&&(e.ok?i({type:`publish-done`,op:t}):i({type:`publish-failed`,op:t,message:e.error??`Could not set the cover.`}))})},[]),m=g.useCallback(()=>{let e=a.current;e.busy!==`publishing`&&(e.open&&u.current&&kJ(u.current.id,{event:`discarded`,hadPreview:e.preview!==null,coverSet:e.preview!==null&&e.published===e.preview.id}),u.current=null,d(AJ),i({type:`discard`}))},[d]),h=NJ(),_=g.useMemo(()=>Yq(h),[h]);return{state:r,canCapture:_===null&&Mq(r,n),unavailable:_,capture:f,publish:p,discard:m}}function LJ(e){return e===`error`?`castle-feedback-danger`:`castle-feedback-quiet`}function RJ(e){let{preview:t,busy:n}=e.state;return t?(0,G.jsx)(`img`,{className:`play-cover-preview`,src:t.dataUrl,width:t.width,height:t.height,alt:`The captured frame, as the cover would look`}):n===`capturing`?(0,G.jsx)(`p`,{className:`castle-feedback-note castle-feedback-quiet`,children:`Capturing the current frame…`}):null}function zJ(e){let{state:t,canCapture:n,capture:r,publish:i,discard:a}=e.cover;if(!t.open)return null;let o=_J(),s=t.preview!==null&&t.published===t.preview.id,c=t.notice??(t.preview&&!o?{kind:`info`,text:`Covers can only be set from the Castle editor.`}:null);return(0,G.jsx)(`div`,{className:`play-cover-anchor`,children:(0,G.jsxs)(`div`,{className:`castle-popover play-cover-popover`,role:`dialog`,"aria-label":`Cover`,children:[(0,G.jsx)(RJ,{state:t}),(0,G.jsxs)(`p`,{className:`castle-feedback-note ${c?LJ(c.kind):``} play-cover-notice${c?``:` is-silent`}`,role:`status`,children:[c?.kind===`success`?(0,G.jsx)(K,{name:`check`}):null,c?.text??``]}),(0,G.jsxs)(`div`,{className:`play-cover-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:i,disabled:!t.preview||t.busy!==null||s||!o,children:(0,G.jsx)(`span`,{children:t.busy===`publishing`?`Setting cover…`:s?kq:`Use as cover`})}),t.notice?.final&&!t.preview?null:(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:r,disabled:!n,children:(0,G.jsx)(`span`,{children:t.busy===`capturing`?`Capturing…`:t.preview?`Retake`:`Try again`})}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:a,disabled:t.busy===`publishing`,children:(0,G.jsx)(`span`,{children:`Discard`})})]})]})})}function BJ(e){let t=e.role??`edit`,n=g.useRef(null);return g.useEffect(()=>{let e=n.current;return()=>{e&&UK(e)}},[]),(0,G.jsx)(`div`,{className:`deck-panel`,children:(0,G.jsx)(`iframe`,{ref:n,className:`deck-frame`,src:e.src,title:e.title,onLoad:e=>qK(e.currentTarget,t),allow:`autoplay; clipboard-read; clipboard-write; fullscreen; gamepad`})})}function VJ(e){return e===`code`?`code`:`visual`}function HJ(e){return ve(e).map(e=>({mode:VJ(e.classId),label:e.label}))}function UJ(e){let{state:t,refresh:n}=xw(e.file),[r,i]=g.useState(null),[a,o]=g.useState(null),s=t=>{i(null),o(null),t(e.file).then(n).then(e.onSwapped).catch(e=>o(e instanceof Error?e.message:String(e)))},c=t?.ownFork===!0,l=e.alias??`an import`;return(0,G.jsxs)(`div`,{className:`editor-import-banner`,role:`status`,children:[(0,G.jsx)(`span`,{className:c?`editor-import-chip editor-fork-chip`:`editor-import-chip`,children:c?`Forked`:`Read Only`}),(0,G.jsx)(`span`,{className:`editor-import-banner-text`,children:a??(c?`Your version of a file from ${l}`:`Imported from ${l}`)}),(c||t?.forkable)&&(0,G.jsx)(`button`,{type:`button`,className:`editor-import-banner-action`,onClick:()=>i(c?`revert`:`fork`),children:c?`Drop fork`:`Fork`}),r===`fork`&&(0,G.jsx)(_C,{title:`Fork this file?`,body:`This file is from the import '${l}'. Fork this file so you can modify it?`,confirmLabel:`Fork`,onConfirm:()=>s(Re),onClose:()=>i(null)}),r===`revert`&&(0,G.jsx)(_C,{title:`Drop this fork?`,body:vC(e.file,t),confirmLabel:`Drop fork`,onConfirm:()=>s(ze),onClose:()=>i(null)})]})}var WJ=e=>{let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)},GJ=e=>e.split(`/`).pop()||e,KJ=(0,G.jsx)(K,{name:`sidebar`});function qJ(e){let t=YS(),[n,r]=g.useState(null);g.useEffect(()=>{let e=!0;return je().then(t=>e&&r(t),()=>e&&r([])),()=>{e=!1}},[]);let i=g.useMemo(()=>{let e=new Map;for(let t of n??[]){let n=WJ(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[n]);return(0,G.jsx)(`aside`,{className:`editor-drawer`,children:n===null?(0,G.jsx)(`div`,{className:`editor-drawer-empty`,children:`loading…`}):n.length===0?(0,G.jsx)(`div`,{className:`editor-drawer-empty`,children:`no files`}):i.map(([n,r])=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`editor-drawer-folder`,children:n||`/`}),r.sort().map(n=>(0,G.jsx)(`button`,{type:`button`,className:`editor-drawer-item${n===e.currentFile?` current`:``}`,title:n,onClick:()=>t.openFile(n),children:GJ(n)},n))]},n||`(root)`))})}function JJ(e){let t=YS(),n=e.file??``,r=t.kitEditorExts,i=g.useRef(null),{lifecycle:a}=e,o=VJ(e.editorClass??``),[s,c]=g.useState(o);g.useEffect(()=>c(o),[n,o]);let[l,u]=g.useState(!1),d=e.drawerOpen??l,f=u;g.useEffect(()=>{let e=()=>{let e=i.current,t=e?.querySelector(`.cm-content`);t?DF(t):e?.querySelector(`iframe`)?.focus()};TF(a.id,e);let t=a.onDidActiveChange(t=>{t&&requestAnimationFrame(e)});return()=>{EF(a.id),t()}},[a]);let p=r!==null&&r.includes(Ye(n)),m=Ce(n),h=m?we(n):null,_=r===null?[]:HJ(n),v=_.some(e=>e.mode===s)?s:_[0]?.mode??`code`,y=p&&v===`visual`,b=g.useRef(null);y&&b.current?.file!==n&&(b.current={file:n,at:nC(n,`fragment`)?.fragment});let S=y?b.current?.at:void 0,C;if(r===null)C=(0,G.jsx)(`div`,{className:`code-editor-overlay`,children:`loading…`});else if(y){let e=pe(n)?.module;C=(0,G.jsx)(BJ,{src:MK(`edit`,x(`/index.html?file=${encodeURIComponent(n)}`)+(e?`&editorModule=${encodeURIComponent(e)}`:``)+(S?`&at=${encodeURIComponent(S)}`:``)),title:n,role:`edit`})}else C=(0,G.jsx)(jI,{file:n,panelId:a.id});return fC(i,a.id,y,n),(0,G.jsxs)(`div`,{ref:i,className:`editor-panel-root`,children:[!e.hideContextBar&&(0,G.jsxs)(`div`,{className:`editor-contextbar`,children:[(0,G.jsx)(`button`,{type:`button`,className:`editor-drawer-toggle${d?` on`:``}`,"aria-label":`Toggle files`,"aria-pressed":d,title:`Toggle files`,onClick:()=>f(e=>!e),children:KJ}),_.length>=2&&(0,G.jsx)(`select`,{className:`editor-view-picker`,value:v,onChange:e=>c(e.target.value),"aria-label":`Editor view`,title:`Switch editor view`,children:_.map(e=>(0,G.jsx)(`option`,{value:e.mode,children:e.label},e.mode))}),(0,G.jsx)(`span`,{className:`editor-contextbar-path`,title:n,children:n}),p&&v===`visual`&&(0,G.jsx)(`button`,{type:`button`,className:`editor-contextbar-reload`,"aria-label":`Reload panel`,title:`Reload this panel to pick up code changes`,onClick:()=>tT(i.current),children:(0,G.jsx)(K,{name:`sync`})})]}),(0,G.jsxs)(`div`,{className:`editor-shell`,children:[d&&(e.drawer??(0,G.jsx)(qJ,{currentFile:n})),(0,G.jsxs)(`div`,{className:`editor-panel-body`,children:[m&&(0,G.jsx)(UJ,{alias:h,file:n,onSwapped:()=>tT(i.current)}),(0,G.jsx)(fq,{}),(0,G.jsx)(`div`,{className:`editor-panel-view`,children:C})]})]})]})}var YJ=500;function XJ(e){QK(e.map(e=>e.text).join(`
|
|
384
|
-
`))}function ZJ(){document.body.classList.remove(`play-logs-resizing`)}function QJ(e){if(e.button!==0)return;let t=e.currentTarget,n=t.closest(`.play-logs`),r=n?.closest(`.play-panel`);if(!(n instanceof HTMLElement)||!(r instanceof HTMLElement)||!n.classList.contains(`is-open`))return;e.preventDefault(),e.stopPropagation();let i=e.pointerId;try{t.setPointerCapture(i)}catch{}let a=e.clientY,o=n.getBoundingClientRect().height,s=n.querySelector(`.play-logs-header`),c=n.querySelector(`.play-logs-toolbar`),l=(s instanceof HTMLElement?s.offsetHeight:0)+(c instanceof HTMLElement?c.offsetHeight:0)+32,u=Math.max(l,r.clientHeight-80);document.body.classList.add(`play-logs-resizing`);let d=e=>{let t=Math.min(u,Math.max(l,o+(a-e.clientY)));n.style.setProperty(`--play-logs-height`,`${t}px`)},f=()=>{ZJ(),t.removeEventListener(`pointermove`,d),t.removeEventListener(`pointerup`,f),t.removeEventListener(`pointercancel`,f);try{t.releasePointerCapture(i)}catch{}};t.addEventListener(`pointermove`,d),t.addEventListener(`pointerup`,f),t.addEventListener(`pointercancel`,f)}function $J(e){let[t,n]=g.useState(!1),r=g.useId(),i=g.useRef(null);return g.useEffect(()=>{t&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e.logs,t]),g.useEffect(()=>()=>ZJ(),[]),(0,G.jsxs)(`div`,{className:`play-logs${t?` is-open`:``}`,children:[(0,G.jsx)(`div`,{className:`play-logs-resize`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize logs`,onPointerDown:QJ}),(0,G.jsxs)(`div`,{className:`play-logs-header${e.onSnap?` has-snap`:``}${e.onCover?` has-cover`:``}`,children:[(0,G.jsx)(`button`,{type:`button`,className:`play-logs-expand`,onClick:()=>n(e=>!e),"aria-expanded":t,"aria-label":t?`Collapse logs`:`Expand logs`}),(0,G.jsxs)(`span`,{className:`play-logs-label`,children:[(0,G.jsx)(K,{name:t?`chevron-down`:`chevron-right`}),(0,G.jsx)(`span`,{className:`castle-text-style-smallcaps`,children:`Logs`}),e.logs.length>0?(0,G.jsx)(`span`,{className:`castle-button-badge`,children:e.logs.length}):null]}),e.onSnap!==void 0||e.snapping||e.snapError?(0,G.jsx)(`p`,{className:`play-logs-pending is-error${e.snapError?``:` is-silent`}`,role:`status`,children:e.snapError??``}):null,!e.snapError&&e.pending?(0,G.jsx)(`p`,{className:`play-logs-pending`,children:`Changes available`}):null,e.onSnap?(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-snap`,onClick:e.onSnap,disabled:e.snapping,"aria-label":`Send a screenshot to the operator`,title:`Take a screenshot of the running deck and attach it to your next message`,children:[(0,G.jsx)(K,{name:`camera`}),(0,G.jsx)(`span`,{children:e.snapping?`Snapping…`:`Snap`})]}):null,e.onCover&&e.coverUnavailable?(0,G.jsx)(`p`,{className:`play-logs-pending is-note`,id:r,children:e.coverUnavailable}):null,e.onCover?(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-cover`,onClick:e.onCover,disabled:e.coverDisabled,"aria-haspopup":`dialog`,"aria-expanded":e.coverOpen===!0,"aria-describedby":e.coverUnavailable?r:void 0,title:e.coverUnavailable??`Capture this frame to preview as the deck's cover`,children:[(0,G.jsx)(K,{name:`image`}),(0,G.jsx)(`span`,{children:`Cover`})]}):null,(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-restart${e.pending?` is-pending`:``}`,onClick:e.onReload,"aria-label":e.pending?`Restart deck to apply changes`:`Restart deck`,title:e.pending?`Files changed since this run started. Restart to apply them.`:`Restart the deck`,children:[(0,G.jsx)(`span`,{className:`play-logs-restart-icon${e.reloadSpinning?` is-spinning`:``}`,children:(0,G.jsx)(K,{name:`sync`})}),(0,G.jsx)(`span`,{children:`Restart`})]})]}),t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`play-logs-toolbar`,children:[e.actions,(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onClear,children:[(0,G.jsx)(K,{name:`trash`}),(0,G.jsx)(`span`,{children:`Clear`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:()=>XJ(e.logs),children:[(0,G.jsx)(K,{name:`copy`}),(0,G.jsx)(`span`,{children:`Copy`})]})]}),(0,G.jsx)(`div`,{className:`play-logs-body`,ref:i,children:e.logs.length===0?(0,G.jsx)(`div`,{className:`play-logs-empty`,children:`No output`}):e.logs.map(e=>(0,G.jsx)(`div`,{className:`play-logs-line play-logs-${e.level}`,children:e.text},e.id))})]}):null]})}var eY=e=>e.replace(/^scenes\//,``).replace(/\.scene$/,``);function tY(e){let[t,n]=g.useState([]),r=g.useRef(1),i=g.useCallback((e,t)=>{let i=e===`warn`||e===`error`?e:`log`;n(e=>{let n=e.concat({id:r.current++,level:i,text:typeof t==`string`?t:``});return n.length>YJ?n.slice(n.length-YJ):n})},[]);return g.useEffect(()=>{let t=t=>{if(!e.current||t.source!==e.current.contentWindow)return;let n=t.data;!n||n.type!==`castle-console`||i(n.level,n.text)};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[i,e]),g.useEffect(()=>cS(`server_log`,e=>i(e.level,e.text)),[i]),{logs:t,clear:()=>n([])}}var nY=1e3;function rY(e,t,n){let r=g.useRef(new Set);return g.useEffect(()=>{let e=r.current;return()=>{for(let t of[...e])t()}},[]),g.useCallback(i=>{let a=e.current?.contentWindow??null,o=t.current;if(!a)return n();let s=new Set(i.changes.filter(e=>e.tuned).map(e=>e.path)),c={seq:i.seq,paths:s},l=0,u=e=>{window.clearTimeout(l),window.removeEventListener(`message`,f),r.current.delete(d),!e&&t.current===o&&n()},d=()=>u(!0),f=e=>{if(e.source!==a)return;let t=iK(c,e.data);if(t){if(!t.ok)return u(!1);s.delete(t.path),s.size===0&&u(!0)}};r.current.add(d),window.addEventListener(`message`,f),l=window.setTimeout(()=>u(!1),nY)},[e,n,t])}function iY(e){let t=e.scene??ye()??``,[n,r]=g.useState(t),[i,a]=g.useState([]);g.useEffect(()=>{let e=!0;return je().then(t=>{e&&a(t.filter(e=>e.startsWith(`scenes/`)&&e.endsWith(`.scene`)).sort())},()=>{}),()=>{e=!1}},[]);let o=MK(`play`,x(oK(n||null,{logs:!0}))),s=g.useRef(null),{logs:c,clear:l}=tY(s),[u,d]=g.useState(!1),f=oY(s),[p,m]=g.useState(0);g.useEffect(()=>{let e=s.current;return()=>{e&&UK(e)}},[p]);let[h,_]=g.useState(!1),[y,b]=g.useState(!1),S=`${p}|${h?``:o}`,[C,w]=g.useState(null),T=IJ(s,S,C===S),E=!h&&!v&&de(),D=g.useCallback(()=>{_(!1),m(e=>e+1),b(!1)},[]),O=g.useCallback(()=>{D(),d(!0),window.setTimeout(()=>d(!1),600)},[D]),k=g.useRef(y);k.current=y;let A=g.useRef(p);A.current=p;let{lifecycle:j}=e,ee=g.useCallback(()=>{b(!0),j.isVisible()||_(!0)},[j]),M=rY(s,A,ee);return g.useEffect(()=>oS(e=>{let t=aK(e.changes);t!==`ignore`&&(t===`restart`?ee():M(e))}),[M,ee]),g.useEffect(()=>j.onDidVisibilityChange(e=>{e&&k.current&&D()}),[j,D]),(0,G.jsxs)(`div`,{className:`play-panel`,children:[(0,G.jsx)(`div`,{className:`play-stage`,children:(0,G.jsxs)(`div`,{className:`play-frame-shell`,children:[(0,G.jsx)(`iframe`,{ref:s,className:`deck-frame`,src:h?`about:blank`:o,title:`play`,onLoad:()=>{h||b(!1),h||w(S),s.current&&!h&&qK(s.current,`play`,e.playSessionSlot)},allow:`autoplay; clipboard-read; clipboard-write; fullscreen; gamepad`},p),(0,G.jsx)(nK,{})]})}),i.length>1?(0,G.jsx)(`div`,{className:`play-scene-picker`,children:(0,G.jsx)(`select`,{className:`castle-select`,value:n,onChange:e=>r(e.target.value),"aria-label":`Scene`,children:i.map(e=>(0,G.jsx)(`option`,{value:e,children:eY(e)},e))})}):null,E?(0,G.jsx)(zJ,{cover:T}):null,(0,G.jsx)($J,{logs:c,onClear:l,onReload:O,reloadSpinning:u,pending:y,onSnap:h||v||!ue()?void 0:f.snap,snapping:f.snapping,snapError:f.error,onCover:E?T.capture:void 0,coverDisabled:!T.canCapture||T.state.open,coverUnavailable:T.unavailable,coverOpen:T.state.open})]})}var aY=6e3;function oY(e){let t=YS(),[n,r]=g.useState(!1),[i,a]=g.useState(null);g.useEffect(()=>{if(!i)return;let e=window.setTimeout(()=>a(null),aY);return()=>window.clearTimeout(e)},[i]);let o=g.useRef(t);return o.current=t,{snap:g.useCallback(()=>{let t=e.current;t&&(r(!0),a(null),ZK(t).then(yK).then(e=>{let t=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19);o.current.attachImageToChat({name:`snap-${t}.png`,dataUrl:e})||a(`6 images are already waiting for your next message.`)}).catch(e=>{a(e instanceof Error?e.message:`Could not capture the deck.`)}).finally(()=>r(!1)))},[e]),snapping:n,error:i}}function sY(e){let t=YS(),n=g.useRef(null),r=g.useRef(null),{lifecycle:i}=e;return g.useEffect(()=>{let e=n.current;if(!e)return;let a=mG(e,t.terminalTheme);r.current=a;let o=()=>{i.isVisible()&&(a.activate(),a.fit(),i.isActive()&&a.focus())};o();let s=i.onDidVisibilityChange(o),c=i.onDidActiveChange(o);return()=>{s(),c(),a.dispose(),r.current=null}},[i]),g.useEffect(()=>{r.current?.setTheme(t.terminalTheme)},[t.terminalTheme]),(0,G.jsx)(`div`,{className:`term-panel`,children:(0,G.jsx)(`div`,{className:`term-host`,ref:n})})}function cY(e){let[t,n]=g.useState(null);g.useEffect(()=>{let e=!0,t=()=>{je().then(t=>e&&n(t),()=>e&&n([]))};t();let r=oS(e=>{e.changes.some(e=>e.event!==`change`)&&t()});return()=>{e=!1,r()}},[]);let{onSetView:r}=e;return(0,G.jsxs)(`aside`,{className:`flow-class-drawer`,children:[r&&(0,G.jsx)(ZT,{file:e.currentFile,view:e.view,onSetView:r}),(0,G.jsx)(XT,{currentFile:e.currentFile,filterClass:e.filterClass,files:t,recent:cx(be()),onOpen:e.onOpen})]})}var lY=x(`/__castle/import/`);function uY(e){return!!(e&&e.hasSource&&!e.imported)}var dY=class extends Error{code;constructor(e,t){super(e),this.name=`ImportRequestError`,this.code=t}};async function fY(e,t){let n=await fetch(`${lY}${e}`,t),r=await n.json().catch(()=>null);if(!r)throw n.ok?new dY("This serve is older than the editor. Restart `castle-web serve` to pick up importing.",`stale-serve`):new dY(`Request failed (${n.status})`,null);if(!n.ok)throw new dY(r.error??`Request failed (${n.status})`,r.code??null);return r}async function pY(e){let t=await Te().catch(()=>[]),n=new Set(t.map(e=>e.deckId).filter(Boolean));return e.map(e=>({...e,imported:n.has(e.deckId)}))}var mY=15e3,hY=null;function gY(e,t){return typeof window>`u`||window.parent===window||hY===!1?Promise.resolve(null):new Promise((n,r)=>{let i=Math.random().toString(36).slice(2),a=setTimeout(()=>{hY=!1,o(),n(null)},mY);function o(){clearTimeout(a),window.removeEventListener(`message`,s)}function s(t){if(!Ob(t))return;let a=t.data;!a||a.type!==`${e}-result`||a.requestId!==i||(hY=!0,o(),a.ok&&a.data?n(a.data):r(new dY(a.error??`The editor host could not answer.`,a.code??null)))}window.addEventListener(`message`,s),window.parent.postMessage({type:e,requestId:i,...t},kb())})}async function _Y(e){let t=await gY(`castle-import-list`,{tab:e});return t?{...t,decks:await pY(t.decks)}:fY(`list?tab=${e}`)}function vY(){return typeof window<`u`&&window.parent!==window}function yY(){sS(`import_list_request`,async e=>({ok:!0,list:await _Y(e.tab===`saved`||e.tab===`kits`?e.tab:`mine`)}))}async function bY(e){let t=await gY(`castle-import-resolve`,{ref:e});return t?(await pY([t.deck]))[0]:(await fY(`resolve?ref=${encodeURIComponent(e)}`)).deck}async function xY(e){return(await fY(`files?deckId=${encodeURIComponent(e)}`)).fileCount}function SY(e){return fY(`add`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({deckRef:e})})}var CY=[{id:`mine`,label:`My decks`},{id:`saved`,label:`Saved`},{id:`kits`,label:`Kits`},{id:`link`,label:`From a link`},{id:`updates`,label:`Updates`}];function wY(e){return e instanceof Error?e.message:String(e)}function TY(e){let[t,n]=g.useState({}),[r,i]=g.useState({}),a=g.useRef(new Set);return g.useEffect(()=>{e===`link`||e===`updates`||a.current.has(e)||(a.current.add(e),_Y(e).then(t=>n(n=>({...n,[e]:t}))).catch(t=>i(n=>({...n,[e]:wY(t)}))))},[e]),{list:t[e]??null,error:r[e]??null}}function EY(e){let[t,n]=g.useState({}),r=g.useRef(new Set);return g.useEffect(()=>{let t=e?.hasSource?e.deckId:null;!t||r.current.has(t)||(r.current.add(t),xY(t).then(e=>{e!==null&&n(n=>({...n,[t]:e}))}).catch(()=>{}))},[e]),t}function DY(){let[e,t]=g.useState([]);return g.useEffect(()=>{let e=!0;return Te().then(n=>{e&&t(n.filter(e=>e.updateAvailable))}),()=>{e=!1}},[]),e}function OY(e){let{initialUpdateAlias:t}=e,[n,r]=g.useState(t?`updates`:`mine`),[i,a]=g.useState(null),[o,s]=g.useState(()=>new Set(t?[t]:[])),[c,l]=g.useState(``),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[m,h]=g.useState(null),{list:_,error:v}=TY(n),y=DY(),b=EY(i),x=u||f,S=y.filter(e=>o.has(e.alias)),C=e=>{r(e),a(null),l(``),h(null)},w=e=>{h(null),s(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},T=()=>{h(null),s(S.length===y.length?new Set:new Set(y.map(e=>e.alias)))},E=()=>{i&&(d(!0),h(null),SY(i.deckId).then(e.onImported).catch(e=>{h(wY(e)),d(!1)}))},D=()=>{S.length!==0&&(p(!0),h(null),(async()=>{for(let e of S)try{await Ee(e.alias)}catch(t){h(`${e.alias}: ${wY(t)}`),p(!1);return}e.onUpdated(S.map(e=>e.alias))})())},O=n===`updates`;return(0,gb.createPortal)((0,G.jsx)(`div`,{className:`castle-modal-scrim`,onClick:x?void 0:e.onClose,children:(0,G.jsxs)(`div`,{className:`castle-modal castle-import-modal`,role:`dialog`,"aria-label":`Import a deck`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`castle-modal-text`,children:`Import a deck`}),(0,G.jsx)(`div`,{className:`castle-key-tabs castle-import-tabs`,children:CY.map(e=>(0,G.jsx)(`button`,{type:`button`,className:ux(`castle-key-tab`,n===e.id&&`active`),onClick:()=>C(e.id),children:e.id===`updates`&&y.length>0?`${e.label} (${y.length})`:e.label},e.id))}),O?(0,G.jsx)(AY,{outdated:y,ticked:o,onToggle:w,onToggleAll:T}):n===`link`?(0,G.jsx)(IY,{selected:i,counts:b,onResolved:a}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`input`,{className:`castle-key-input castle-import-filter`,placeholder:`Filter`,spellCheck:!1,value:c,onChange:e=>l(e.target.value)}),(0,G.jsx)(FY,{list:_,error:v,filter:c,selected:i,counts:b,onSelect:a})]}),m?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:m}):null,(0,G.jsxs)(`div`,{className:`castle-modal-actions`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:x,children:`Cancel`}),O?(0,G.jsx)(`button`,{type:`button`,onClick:D,disabled:x||S.length===0,children:kY(S.length,f)}):(0,G.jsx)(`button`,{type:`button`,onClick:E,disabled:x||!uY(i),children:u?`Importing…`:`Import`})]})]})}),document.body)}function kY(e,t){return t?`Updating…`:e>1?`Update ${e}`:`Update`}function AY(e){let{outdated:t,ticked:n}=e;if(t.length===0)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`Every import is at its deck’s latest version.`});let r=t.filter(e=>n.has(e.alias)).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`castle-import-select-bar`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-import-select-all`,onClick:e.onToggleAll,children:r===t.length?`Clear all`:`Select all`}),(0,G.jsxs)(`span`,{className:`castle-import-row-meta`,children:[r,` of `,t.length,` selected`]})]}),(0,G.jsx)(`div`,{className:`castle-import-list`,children:t.map(t=>(0,G.jsx)(NY,{status:t,ticked:n.has(t.alias),onToggle:()=>e.onToggle(t.alias)},t.alias))})]})}function jY(e,t){if(!e)return`unknown`;let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,...t?{second:`2-digit`}:{}})}function MY(e){let t=jY(e.version,!1),n=jY(e.latest,!1);return t===n?`${jY(e.version,!0)} → ${jY(e.latest,!0)}`:`${t} → ${n}`}function NY(e){let{status:t,ticked:n}=e;return(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-import-row castle-import-update-row`,n&&`selected`),onClick:e.onToggle,role:`checkbox`,"aria-checked":n,children:[(0,G.jsx)(`span`,{className:ux(`castle-import-tick`,n&&`checked`),children:n?(0,G.jsx)(K,{name:`check`}):null}),(0,G.jsxs)(`span`,{className:`castle-import-row-text`,children:[(0,G.jsx)(`span`,{className:`castle-import-row-title`,children:t.alias}),(0,G.jsx)(`span`,{className:`castle-import-row-meta`,children:MY(t)})]})]})}function PY(e,t){let n=t.trim().toLowerCase();return n?`${e.title} @${e.creator??``}`.toLowerCase().includes(n):!0}function FY(e){let{list:t,error:n,filter:r,selected:i,counts:a,onSelect:o}=e;if(n)return(0,G.jsxs)(`div`,{className:`castle-import-empty`,children:[`could not list decks: `,n]});if(!t)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`Loading…`});if(!t.signedIn)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:vY()?`Sign in to Castle to see your decks.`:"Run `castle-web login` to see your decks."});if(t.decks.length===0)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`No decks here with source files to import.`});let s=t.decks.filter(e=>PY(e,r));return s.length===0?(0,G.jsxs)(`div`,{className:`castle-import-empty`,children:[`Nothing matches “`,r.trim(),`”.`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-import-list`,children:s.map(e=>(0,G.jsx)(LY,{deck:e,fileCount:a[e.deckId],selected:i?.deckId===e.deckId,onSelect:()=>o(e)},e.deckId))}),t.truncated?(0,G.jsxs)(`div`,{className:`castle-import-note`,children:[`Showing the first `,t.decks.length,`; there are more.`]}):null]})}function IY(e){let[t,n]=g.useState(``),[r,i]=g.useState(!1),[a,o]=g.useState(null),s=()=>{let n=t.trim();!n||r||(i(!0),o(null),e.onResolved(null),bY(n).then(e.onResolved).catch(e=>o(wY(e))).finally(()=>i(!1)))};return(0,G.jsxs)(`div`,{className:`castle-import-link`,children:[(0,G.jsxs)(`div`,{className:`castle-import-link-row`,children:[(0,G.jsx)(`input`,{className:`castle-key-input`,placeholder:`castle.xyz/d/… or a deck id`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s())}}),(0,G.jsx)(`button`,{type:`button`,onClick:s,disabled:r||!t.trim(),children:r?`Looking…`:`Look up`})]}),a?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:a}):null,e.selected?(0,G.jsx)(`div`,{className:`castle-import-list`,children:(0,G.jsx)(LY,{deck:e.selected,fileCount:e.counts[e.selected.deckId],selected:!0,onSelect:()=>void 0})}):null]})}function LY(e){let{deck:t,fileCount:n,selected:r}=e,i=uY(t),a=t.imported?`already imported`:t.hasSource?n===void 0?null:`${n} files`:`no source files`,o=[t.creator?`@${t.creator}`:null,a].filter(Boolean);return(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-import-row`,r&&`selected`,!i&&`disabled`),onClick:e.onSelect,disabled:!i,"aria-pressed":r,children:[t.imageUrl?(0,G.jsx)(`img`,{className:`castle-import-thumb`,src:t.imageUrl,alt:``}):(0,G.jsx)(`span`,{className:`castle-import-thumb`}),(0,G.jsxs)(`span`,{className:`castle-import-row-text`,children:[(0,G.jsx)(`span`,{className:`castle-import-row-title`,children:t.title}),(0,G.jsx)(`span`,{className:`castle-import-row-meta`,children:o.join(` · `)}),t.parentCreator?(0,G.jsxs)(`span`,{className:`castle-import-row-meta`,children:[(0,G.jsx)(K,{name:`clone`}),` remix of @`,t.parentCreator]}):null]})]})}var RY=`/ (Deck root)`;function zY(e){return e||RY}function BY(e){return e.trim().replace(/^\/+|\/+$/g,``)}function VY(e,t){let n=e.split(`/`);for(let e of n){if(!e)return`Path cannot have empty segments.`;if(e===`.`||e===`..`)return`Path cannot contain “.” or “..”.`;if(e.startsWith(`.`))return`Hidden folders cannot be created here.`}return Ce(e)?`Imported files cannot be a destination.`:t.includes(e)?`“${e}” is already a file.`:null}function HY(e,t){let n=BY(t).toLowerCase();return n?e.filter(e=>zY(e).toLowerCase().includes(n)):e.slice()}function UY(e){let t=[],n=[];for(let r of e.split(`/`))r&&(t.push(r),n.push(t.join(`/`)));return n}function WY(e){return(0,G.jsxs)(`button`,{type:`button`,role:`menuitem`,className:ux(`castle-menu-item`,e.danger&&`castle-menu-item-danger`),disabled:e.disabled,"data-folder-selected":e.checked?``:void 0,onClick:e.onClick,children:[(0,G.jsx)(`span`,{className:`castle-menu-icon`,children:(0,G.jsx)(K,{name:e.icon})}),(0,G.jsx)(`span`,{className:`castle-menu-item-label`,children:e.label}),e.checked?(0,G.jsx)(`span`,{className:`castle-menu-check`,children:`✓`}):null]})}function GY(e){let{folders:t,existingFiles:n,selected:r,disabled:i,onChoose:a}=e,[o,s]=g.useState(``),[c,l]=g.useState([]),[u,d]=g.useState(null),f=g.useRef(null),p=g.useRef(null);g.useEffect(()=>f.current?.focus(),[]),g.useEffect(()=>{p.current?.querySelector(`[data-folder-selected]`)?.scrollIntoView({block:`nearest`})},[]);let m=g.useMemo(()=>[...new Set([``,...t,...c])].sort((e,t)=>e.localeCompare(t)),[t,c]),h=HY(m,o),_=BY(o),v=_.length>0&&h.length===0,y=e=>{d(null),a(e)},b=()=>{if(!_)return;let e=VY(_,n);if(e){d(e);return}m.includes(_)||l(e=>[...new Set([...e,...UY(_)])]),s(_),y(_)};return(0,G.jsxs)(`div`,{className:`castle-file-picker`,children:[e.header?(0,G.jsx)(`div`,{className:`castle-menu-header`,children:e.header}):null,e.label?(0,G.jsx)(`p`,{className:`castle-file-picker-label castle-text-style-smallcaps`,children:e.label}):null,(0,G.jsx)(`input`,{ref:f,className:`castle-text-field`,type:`text`,placeholder:`Filter or type a path`,autoComplete:`off`,spellCheck:!1,disabled:i,value:o,onChange:e=>{s(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`&&e.preventDefault()}}),(0,G.jsx)(`div`,{ref:p,className:`castle-file-picker-list`,hidden:h.length===0,role:`group`,"aria-label":`Destination folder`,children:h.map(e=>(0,G.jsx)(WY,{icon:`folder`,label:zY(e),checked:r===e,disabled:i,onClick:()=>y(e)},e||`(root)`))}),v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`folder-plus`,label:`Create “${_}”`,disabled:i,onClick:b})]}):null,u?(0,G.jsx)(`p`,{className:`castle-menu-error`,children:u}):null]})}function KY(e){return e instanceof Error?e.message:String(e)}function qY(e){return e.replace(/[\\/]+/g,`-`).replace(/^\.+/,``).trim()||`upload`}function JY(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function YY(e){let{item:t,editing:n,busy:r}=e,[i,a]=g.useState(t.name),o=g.useRef(null),s=g.useRef(!1),c=P(t.name);g.useEffect(()=>{if(!n)return;s.current=!1,a(t.name);let e=o.current;e&&(e.focus(),JY(e))},[n,t.name]);let l=()=>{let n=i.trim()?qY(i):t.name;e.onCommit(n)};return(0,G.jsxs)(`div`,{className:ux(`castle-upload-picked-row`,n&&`is-editing`),children:[(0,G.jsxs)(`span`,{className:`castle-upload-picked-name`,children:[n?(0,G.jsx)(`input`,{ref:o,className:`castle-text-field`,type:`text`,value:i,autoComplete:`off`,spellCheck:!1,disabled:r,"aria-label":`Rename file`,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),l()):t.key===`Escape`&&(t.preventDefault(),s.current=!0,e.onCancelEdit())},onBlur:()=>{s.current||l()}}):(0,G.jsx)(`span`,{className:`castle-upload-picked-label`,children:t.name}),c?(0,G.jsx)(`span`,{className:`castle-upload-picked-warning`,children:c}):null]}),(0,G.jsx)(`span`,{className:`castle-upload-picked-size`,children:CF(t.file.size)}),n?null:(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon castle-button-quiet`,"aria-label":`Rename ${t.name}`,disabled:r,onClick:e.onStartEdit,children:(0,G.jsx)(K,{name:`pen`})}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon castle-button-quiet`,"aria-label":`Remove ${t.name}`,disabled:r,onClick:e.onRemove,children:(0,G.jsx)(K,{name:`times`})})]})}function XY(e){let[t,n]=g.useState([]),[r,i]=g.useState(null),[a,o]=g.useState(e.dir),[s,c]=g.useState(!1),[l,u]=g.useState(null),[d,f]=g.useState(null),p=g.useRef(null),m=g.useRef(1),h=l!==null,_=e=>{let t=Array.from(e??[]);t.length>0&&(f(null),n(e=>[...e,...t.map(e=>({id:m.current++,file:e,name:qY(e.name)}))]))},v=async()=>{let r=new Set(e.existingFiles),i=[],o=[];for(let[e,n]of t.entries()){u(t.length>1?`Uploading ${e+1} of ${t.length}…`:`Uploading…`);let s=et(Qe(a,n.name),r);r.add(s);try{await He(s,n.file),i.push(s)}catch(e){o.push(KY(e))}}if(u(null),o.length>0){n([]),f(o.join(` · `)),e.onUploaded(i);return}e.onUploaded(i),e.onClose()};return(0,gb.createPortal)((0,G.jsx)(`div`,{className:`castle-modal-scrim`,onClick:h?void 0:e.onClose,children:(0,G.jsxs)(`div`,{className:`castle-modal castle-upload-modal`,role:`dialog`,"aria-label":`Upload files`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`castle-modal-text`,children:`Upload files`}),(0,G.jsx)(`input`,{ref:p,type:`file`,multiple:!0,className:`castle-upload-input`,onChange:e=>{_(e.currentTarget.files),e.currentTarget.value=``}}),(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-upload-drop`,s&&`over`),onClick:()=>p.current?.click(),onDragOver:e=>{e.preventDefault(),c(!0)},onDragLeave:()=>c(!1),onDrop:e=>{e.preventDefault(),c(!1),_(e.dataTransfer.files)},children:[(0,G.jsx)(K,{name:`upload`}),(0,G.jsx)(`span`,{className:`castle-upload-drop-label`,children:t.length===0?`Choose files`:`Add more files`}),(0,G.jsx)(`span`,{className:`castle-upload-drop-hint`,children:`or drop them here`})]}),t.length>0?(0,G.jsx)(`div`,{className:`castle-upload-picked`,children:t.map(e=>(0,G.jsx)(YY,{item:e,editing:r===e.id,busy:h,onStartEdit:()=>i(e.id),onCommit:t=>{n(n=>n.map(n=>n.id===e.id?{...n,name:t}:n)),i(null)},onCancelEdit:()=>i(null),onRemove:()=>{i(t=>t===e.id?null:t),n(t=>t.filter(t=>t.id!==e.id))}},e.id))}):null,(0,G.jsx)(GY,{folders:e.folders,existingFiles:e.existingFiles,selected:a,label:`Upload to`,disabled:h,onChoose:o}),d?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:d}):null,(0,G.jsxs)(`div`,{className:`castle-modal-actions`,children:[(0,G.jsx)(`span`,{className:`castle-upload-status`,children:l}),(0,G.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:h,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void v(),disabled:h||t.length===0,children:t.length>1?`Upload ${t.length} files`:`Upload`})]})]})}),document.body)}var ZY=`preview.png`,QY=400,$Y=5e3,eX=3e4,tX=16*6e4;function nX(){let[e,t]=g.useState(null),[n,r]=g.useState([]),[i,a]=g.useState(!1),[o,s]=g.useState(!1),[c,l]=g.useState(``),[u,d]=g.useState(null),[f,p]=g.useState(!1),[m,h]=g.useState(!1),[_,v]=g.useState(null),[y,b]=g.useState(null),x=g.useRef(``),S=g.useRef(null),C=g.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null},[]),w=g.useCallback(e=>{let n=JSON.stringify(e);n!==x.current&&(x.current=n,t(e.versions),r(e.pending),a(e.git),s(e.loading===!0))},[]),T=g.useRef(0),E=g.useCallback(async()=>{let e=++T.current;try{let t=await De();return e===T.current?t:null}catch(t){if(e!==T.current)return null;throw t}},[]),D=g.useCallback(async()=>{try{let e=await E();e&&w(e)}catch(e){v(e instanceof Error?e.message:String(e))}},[w,E]);g.useEffect(()=>{D();let e=()=>{C(),S.current=setTimeout(()=>void D(),QY)},t=oS(t=>{t.changes.every(e=>e.path===ZY)||e()}),n=cS(`git_head_changed`,e);return()=>{C(),t(),n()}},[D,C]),g.useEffect(()=>{if(!o)return;let e=!1,t=$Y,n=Date.now()+tX,r=null,i=async()=>{document.hidden||await D(),!(e||Date.now()>=n)&&(t=Math.min(t*2,eX),r=setTimeout(()=>void i(),t))};r=setTimeout(()=>void i(),t);let a=()=>{document.hidden||D()};return document.addEventListener(`visibilitychange`,a),()=>{e=!0,r&&clearTimeout(r),document.removeEventListener(`visibilitychange`,a)}},[o,D]);let O=g.useCallback(async(e,t={})=>{C(),h(!0),v(null),b(null);let n=null,r=null;try{n=await e()}catch(e){r=e instanceof Error?e.message:String(e)}let i=null;try{i=await E()}catch(e){r??=e instanceof Error?e.message:String(e)}C(),h(!1),r&&v(r),n&&b(n),t.clearMessage&&!r&&l(``),i&&w(i)},[w,C,E]),k=!m&&c.trim().length>0,A=g.useCallback(()=>{if(!k)return;let e=c.trim();O(async()=>await Oe(e)?null:`Nothing had changed, so no version was saved.`,{clearMessage:!0})},[k,c,O]),j=g.useCallback(e=>{O(async()=>(await ke(e)).alreadyThere?`Already at that version.`:null)},[O]);return(0,G.jsxs)(`div`,{className:`castle-versions`,children:[_?(0,G.jsx)($K,{className:`versions-error`,onDismiss:()=>v(null),children:_}):null,n.length>0?(0,G.jsxs)(`article`,{className:ux(`version`,`version-new`,f&&`is-expanded`),children:[(0,G.jsxs)(`button`,{type:`button`,className:`version-toggle`,"aria-expanded":f,onClick:()=>p(e=>!e),children:[(0,G.jsx)(`span`,{className:`castle-icon-cell`,"aria-hidden":`true`,children:(0,G.jsx)(K,{name:`plus`})}),(0,G.jsxs)(`div`,{className:`version-main`,children:[(0,G.jsx)(`div`,{className:`version-heading`,children:(0,G.jsx)(`span`,{className:`version-message`,children:`New version`})}),(0,G.jsxs)(`span`,{className:`version-meta`,children:[n.length,` file`,n.length===1?``:`s`]})]})]}),(0,G.jsxs)(`div`,{className:`version-detail`,children:[(0,G.jsxs)(`div`,{className:`versions-save`,children:[(0,G.jsx)(`input`,{className:`castle-text-field`,type:`text`,value:c,placeholder:`Describe changes to save`,disabled:m,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A()}}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,disabled:!k,onClick:A,children:`Save`})]}),(0,G.jsx)(`p`,{className:`version-summary`,children:sX(n)})]})]}):null,y?(0,G.jsx)(`div`,{className:`versions-note`,children:y}):null,(0,G.jsx)(rX,{versions:e,git:i,historyLoading:o,expanded:u,busy:m,onToggle:e=>d(t=>t===e?null:e),onRestore:j})]})}function rX(e){let{versions:t}=e;if(t===null)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`Loading…`});if(t.length===0&&e.git&&e.historyLoading)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`History is loading… This deck’s saved versions come back in a moment.`});if(t.length===0&&e.git)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`No commits yet. The first save starts this deck’s history.`});if(t.length===0)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`No versions yet. This deck’s history starts at your first save — there is no earlier state to go back to.`});let n=t.findIndex(e=>!e.later);return(0,G.jsx)(`div`,{className:`castle-versions-list`,children:t.map((r,i)=>(0,G.jsx)(cX,{version:r,olderHeading:r.older===!0&&t[i-1]?.older!==!0,showCurrent:i===n&&n>0,expanded:e.expanded===r.id,busy:e.busy,onToggle:()=>e.onToggle(r.id),onRestore:()=>e.onRestore(r.id)},r.id))})}var iX=4,aX=[{label:`Added`,kind:`added`},{label:`Deleted`,kind:`deleted`},{label:`Edited`,kind:`changed`}];function oX(e,t){let n=!e.includes(`/`);return n===!t.includes(`/`)?e.localeCompare(t):n?1:-1}function sX(e){let t=[];for(let n of aX){let r=e.filter(e=>e.kind===n.kind).map(e=>e.path).sort(oX);if(r.length===0)continue;let i=r.slice(0,iX).join(`, `);t.push(`${n.label} ${i}${r.length>iX?`, …`:``}.`)}return t.join(` `)}function cX(e){let{version:t}=e,n=t.changes.length,r=t.agent?` · by the agent`:t.author?` · ${t.author}`:``;return(0,G.jsxs)(G.Fragment,{children:[e.olderHeading?(0,G.jsx)(`div`,{className:`versions-note`,children:`Older versions, from before this deck used git`}):null,(0,G.jsxs)(`article`,{className:ux(`version`,e.expanded&&`is-expanded`,(t.later||t.older)&&`later`),children:[(0,G.jsxs)(`button`,{type:`button`,className:`version-toggle`,"aria-expanded":e.expanded,onClick:e.onToggle,children:[(0,G.jsx)(`span`,{className:`castle-icon-cell`,"aria-hidden":`true`,children:(0,G.jsx)(K,{name:e.expanded?`chevron-down`:`chevron-right`})}),(0,G.jsxs)(`div`,{className:`version-main`,children:[(0,G.jsx)(`div`,{className:`version-heading`,children:(0,G.jsx)(`span`,{className:`version-message`,children:t.message||(0,G.jsx)(`span`,{className:`version-nomessage`,children:`No message`})})}),(0,G.jsxs)(`span`,{className:`version-meta`,children:[SF(t.createdAt),` · `,n,` file`,n===1?``:`s`,e.showCurrent?` · current`:``,t.later?` · later`:``,r]})]})]}),t.older?null:(0,G.jsx)(`div`,{className:`version-actions`,children:(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,disabled:e.busy,onClick:e.onRestore,children:`Restore`})}),(0,G.jsx)(`div`,{className:`version-detail`,children:(0,G.jsx)(`p`,{className:`version-summary`,children:sX(t.changes)})})]})]})}var lX={label:`New file`,icon:`file-code`,ext:``};function uX(){let e=fe();return e?[lX,...e.filter(e=>typeof e.new==`string`&&e.new).map(e=>({label:e.new,icon:e.icon??`file`,ext:e.ext}))]:[lX]}function dX(e){let{showHidden:t,hidesFiles:n,showVersions:r}=e;return(0,G.jsxs)(`div`,{className:ux(`castle-file-toolbar`,r&&`versions-toolbar`),children:[r?(0,G.jsx)(`span`,{className:`versions-toolbar-label castle-text-style-smallcaps`,children:`Versions`}):v?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onNew,title:`New file`,children:[(0,G.jsx)(K,{name:`plus`}),(0,G.jsx)(`span`,{children:`New`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onImport,title:`Import another deck`,children:[(0,G.jsx)(K,{name:`plus`}),(0,G.jsx)(`span`,{children:`Import`})]}),n?(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon`,onClick:e.onToggleHidden,"aria-pressed":t,title:t?`Hide hidden files & folders`:`Show hidden files & folders`,children:(0,G.jsx)(K,{name:`eye`})}):null]}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon`,onClick:e.onToggleVersions,"aria-pressed":r,title:r?`Back to files`:`Version history`,"aria-label":r?`Back to files`:`Version history`,children:(0,G.jsx)(K,{name:`history`})})]})}function fX(e){let t=YS(),[n,r]=g.useState(null),[i,a]=g.useState(null),[o,s]=g.useState(``),[c,l]=g.useState(!1),[u,d]=g.useState(le),[f,p]=g.useState(!1),[m,h]=g.useState(new Set),[_,v]=g.useState(new Set),[y,b]=g.useState(null),[x,S]=g.useState(!1),[C,w]=g.useState(null),T=g.useRef([]);T.current=n??[];let E=g.useRef(!1);E.current=c;let D=g.useCallback(()=>{je(E.current).then(e=>{r(e),a(null)}).catch(e=>a(e instanceof Error?e.message:String(e))),Te().then(e=>h(new Set(e.filter(e=>e.updateAvailable).map(e=>e.alias)))),Le().then(e=>v(new Set(e.map(e=>e.path))))},[]),O=g.useCallback(()=>{S(!1),w(null)},[]),[k,A]=g.useState(null),j=g.useCallback(()=>{E.current=!E.current,l(E.current),D()},[D]),{lifecycle:ee}=e;g.useEffect(()=>{D();let e=ee.onDidVisibilityChange(e=>{e&&D()}),t=ce(()=>{let e=le();d(e),e||(E.current=!1,l(!1)),D()}),n=oS(e=>{e.changes.some(e=>e.event!==`change`||e.forkChanged)&&D()});return()=>{e(),t(),n()}},[D,ee]),g.useEffect(()=>{s(t.activeEditorPath??``)},[t.activeEditorPath]);let M=g.useCallback(e=>{s(e),t.openFile(e)},[t]),N=mX({closeEditor:e=>t.closeEditor(e),refresh:D,onOpen:M,filesRef:T,selected:o,clearSelected:()=>s(``)}),te=g.useMemo(()=>Object.fromEntries((n??[]).map(e=>[e,``])),[n]),ne=g.useMemo(()=>_X(n??[]),[n]);return(0,G.jsxs)(`div`,{className:`castle-file-panel`,children:[(0,G.jsx)(dX,{showHidden:c,hidesFiles:u,showVersions:f,onNew:N.openNewMenu,onImport:()=>S(!0),onToggleHidden:j,onToggleVersions:()=>p(e=>!e)}),N.actionError?(0,G.jsx)($K,{onDismiss:()=>N.setActionError(null),children:N.actionError}):null,f?(0,G.jsx)(nX,{}):i?(0,G.jsxs)($K,{children:[`Could not list files: `,i]}):(0,G.jsx)(PT,{files:te,selectedPath:o,onSelect:M,onContextMenu:N.onContextMenu,edit:N.edit,outdatedImports:m,forkedPaths:_,onUpdateImport:e=>{w(e),S(!0)}}),N.menu?(0,G.jsx)(hX,{menu:N.menu,folders:ne,showHidden:c,hidesFiles:u,forkedPaths:_,onClose:N.closeMenu,onOpenIn:(e,n)=>{s(e),t.openFile(e,n),N.closeMenu()},onShowParams:e=>{t.openParams(e),N.closeMenu()},onCreate:N.startCreate,onMove:N.moveTo,onRename:N.startRename,onDuplicate:N.duplicate,onFork:N.fork,onDropFork:e=>{N.closeMenu(),b(e)},onConfirmDelete:N.confirmDelete,existingFiles:n??[],onUpload:e=>{N.closeMenu(),A(e)},onToggleHidden:j}):null,y?(0,G.jsx)(yC,{path:y,onClose:()=>b(null),onReverted:()=>{b(null),D()}}):null,k===null?null:(0,G.jsx)(XY,{dir:k,folders:ne,existingFiles:n??[],onClose:()=>A(null),onUploaded:e=>{D(),e.length>0&&M(e[0])}}),x?(0,G.jsx)(OY,{initialUpdateAlias:C,onClose:O,onImported:()=>{O(),D(),pX()},onUpdated:()=>{O(),D()}}):null]})}function pX(){for(let e of Array.from(document.querySelectorAll(`iframe.deck-frame`))){let t=e;try{t.contentWindow?.location.reload()}catch{t.src=t.src}}}function mX(e){let{closeEditor:t,refresh:n,onOpen:r,filesRef:i,selected:a,clearSelected:o}=e,[s,c]=g.useState(null),[l,u]=g.useState(null),[d,f]=g.useState(null),p=g.useCallback((e,t,a)=>{let o=a.trim();if(!o)return u(null);let s=t&&!o.endsWith(t)?`${o}${t}`:o,c=Qe(e,s);if(i.current.includes(c))return u(e=>e&&{...e,error:`“${s}” already exists`});Ie(c,Ke(c)).then(()=>{u(null),n(),r(c)}).catch(e=>u(t=>t&&{...t,error:gX(e)}))},[n,r,i]),m=g.useCallback((e,a)=>{let o=a.trim();if(!o||o===Xe(e))return u(null);let s=Qe(Ze(e),o);if(s.toLowerCase()!==e.toLowerCase()&&i.current.includes(s))return u(e=>e&&{...e,error:`“${o}” already exists`});Ue(e,s).then(()=>{u(null),n(),t(e),r(s)}).catch(e=>u(t=>t&&{...t,error:gX(e)}))},[n,r,i,t]),h=g.useCallback((e,t)=>{f(null),c(null),u({mode:`create`,dir:t,suffix:e.ext,error:null,onCommit:n=>p(t,e.ext,n),onCancel:()=>u(null)})},[p]),_=g.useCallback(e=>{f(null),c(null),u({mode:`rename`,dir:Ze(e),path:e,suffix:``,error:null,onCommit:t=>m(e,t),onCancel:()=>u(null)})},[m]),v=g.useCallback(e=>{f(null),c(null);let t=vX(e,i.current);Pe(e,t).then(()=>{n(),r(t)}).catch(e=>c(gX(e)))},[n,r,i]),y=g.useCallback(e=>{f(null),c(null),Re(e).then(()=>{n(),r(e)}).catch(e=>c(gX(e)))},[n,r]),b=g.useCallback((e,a)=>{f(null),c(null);let o=Qe(a,Xe(e));if(o!==e){if(i.current.includes(o))return c(`“${Xe(e)}” already exists in ${a||`root`}`);Ue(e,o).then(()=>{n(),t(e),r(o)}).catch(e=>c(gX(e)))}},[n,r,i,t]),x=g.useCallback(e=>{c(null),We(e).then(()=>{f(null),n(),t(e),a===e&&o()}).catch(e=>{f(null),c(gX(e))})},[n,a,t,o]),S=g.useCallback((e,t)=>{e.preventDefault(),u(null),f({x:e.clientX,y:e.clientY,target:t,fromToolbar:!1})},[]),C=g.useCallback(e=>{let t=e.currentTarget.getBoundingClientRect();u(null),f({x:t.left,y:t.bottom+4,target:{type:`root`,path:``},fromToolbar:!0})},[]);return{edit:l,menu:d,actionError:s,setActionError:c,closeMenu:g.useCallback(()=>f(null),[]),startCreate:h,startRename:_,duplicate:v,fork:y,moveTo:b,confirmDelete:x,onContextMenu:S,openNewMenu:C}}function hX(e){let{menu:t,folders:n,showHidden:r,hidesFiles:i,onClose:a}=e,o=g.useRef(null),[s,c]=g.useState(`default`),l=g.useRef(null);Xw(o,a);let u=Qw(o,t,[s]),d=t.target.type===`file`&&Ce(t.target.path)?t.target.path:null,[f,p]=g.useState(null);g.useEffect(()=>{if(d===null)return;let e=!0;return p(null),Le(d).then(t=>{e&&p(t.find(e=>e.path===d)??null)}),()=>{e=!1}},[d]);let m=t=>{let n=l.current;n?.action===`create`?e.onCreate(n.type,t):n?.action===`move`&&e.onMove(n.file,t),a()},h=()=>e.onUpload(t.target.type===`directory`?t.target.path:``),_=n=>{t.target.type===`directory`?(e.onCreate(n,t.target.path),a()):(l.current={action:`create`,type:n},c(`pickFolder`))},v;if(s===`pickFolder`){let t=l.current;v=(0,G.jsx)(GY,{folders:n,existingFiles:e.existingFiles,header:t?.action===`move`?`Move \u201c${Xe(t.file)}\u201d to\u2026`:`Create new file in…`,onChoose:m})}else if(t.target.type===`file`){let n=t.target.path,r=ve(n),i=r.length>=2||KS(n)?(0,G.jsxs)(G.Fragment,{children:[r.length>=2&&r.map(t=>(0,G.jsx)(WY,{icon:t.icon,label:`Open in ${t.label} editor`,onClick:()=>e.onOpenIn(n,t.classId)},t.classId)),KS(n)&&(0,G.jsx)(WY,{icon:`sliders`,label:`Show parameters`,onClick:()=>e.onShowParams(n)})]}):null;v=s===`confirmDelete`?(0,G.jsxs)(`div`,{className:`castle-menu-confirm`,children:[(0,G.jsxs)(`div`,{className:`castle-menu-confirm-text`,children:[`Delete “`,Xe(n),`”?`]}),(0,G.jsxs)(`div`,{className:`castle-menu-confirm-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:a,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-danger`,onClick:()=>e.onConfirmDelete(n),children:`Delete`})]})]}):Ce(n)?(0,G.jsxs)(G.Fragment,{children:[i,i?(0,G.jsx)(`div`,{className:`castle-menu-separator`}):null,e.forkedPaths.has(n)?(0,G.jsx)(WY,{icon:`code-fork`,label:`Drop fork`,onClick:()=>e.onDropFork(n)}):(0,G.jsx)(WY,{icon:`code-fork`,label:`Fork`,disabled:f!==null&&!f.forkable,onClick:()=>e.onFork(n)})]}):(0,G.jsxs)(G.Fragment,{children:[i,i?(0,G.jsx)(`div`,{className:`castle-menu-separator`}):null,(0,G.jsx)(WY,{icon:`clone`,label:`Duplicate`,onClick:()=>e.onDuplicate(n)}),(0,G.jsx)(WY,{icon:`pen`,label:`Rename`,onClick:()=>e.onRename(n)}),(0,G.jsx)(WY,{icon:`arrow-right`,label:`Move to…`,onClick:()=>{l.current={action:`move`,file:n},c(`pickFolder`)}}),(0,G.jsx)(WY,{icon:`trash`,label:`Delete`,danger:!0,onClick:()=>c(`confirmDelete`)})]})}else v=(0,G.jsxs)(G.Fragment,{children:[uX().map(e=>(0,G.jsx)(WY,{icon:e.icon,label:e.label,onClick:()=>_(e)},e.label)),(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`upload`,label:`Upload files…`,onClick:h}),t.target.type===`root`&&!t.fromToolbar&&i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`eye`,label:`Show hidden files & folders`,checked:r,onClick:()=>{e.onToggleHidden(),a()}})]}):null]});return(0,gb.createPortal)((0,G.jsx)(`div`,{ref:o,className:`castle-menu castle-file-menu`,role:`menu`,style:u,children:v}),document.body)}function gX(e){return e instanceof Error?e.message:String(e)}function _X(e){let t=new Set;for(let n of e){if(Ce(n))continue;let e=n.split(`/`);for(let n=1;n<e.length;n++)t.add(e.slice(0,n).join(`/`))}return[...t].sort()}function vX(e,t){let{stem:n,ext:r}=$e(Xe(e)),i=Ze(e),a=new Set(t);for(let e=1;;e++){let t=Qe(i,`${n} ${e===1?`copy`:`copy ${e}`}${r}`);if(!a.has(t))return t}}var yX=null,bX=new Set;function xX(e){if(bX.size>0){for(let t of[...bX])t(e);return}yX=e}function SX(){let e=yX;return yX=null,e}function CX(e){return bX.add(e),()=>{bX.delete(e)}}function wX(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var TX=wX();function EX(e){TX=e}var DX={exec:()=>null};function OX(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function kX(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(jX.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var AX=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),jX={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:OX(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:OX(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:OX(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:OX(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:OX(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:OX(e=>RegExp(`^ {0,${e}}>`))},MX=/^(?:[ \t]*(?:\n|$))+/,NX=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,PX=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,FX=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,IX=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,LX=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,RX=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,zX=kX(RX).replace(/bull/g,LX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),BX=kX(RX).replace(/bull/g,LX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),VX=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,HX=/^[^\n]+/,UX=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,WX=kX(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,UX).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),GX=kX(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,LX).getRegex(),KX=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,qX=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,JX=kX(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,qX).replace(`tag`,KX).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),YX=kX(VX).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex(),XX={blockquote:kX(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,YX).getRegex(),code:NX,def:WX,fences:PX,heading:IX,hr:FX,html:JX,lheading:zX,list:GX,newline:MX,paragraph:YX,table:DX,text:HX},ZX=kX(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex(),QX={...XX,lheading:BX,table:ZX,paragraph:kX(VX).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,ZX).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex()},$X={...XX,html:kX(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,qX).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:DX,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:kX(VX).replace(`hr`,FX).replace(`heading`,` *#{1,6} *[^
|
|
383
|
+
`,Lq=new Set([`viewbox`,`transform`,`transform-padded`,`zoom`,`native`]),Rq=[`bitmapsChecked`,`fontFacesChecked`,`unverifiedBitmaps`,`strippedMarks`],zq=100,Bq=1e4;function Vq(e,t){return Number.isSafeInteger(e)&&e>=0&&e<=t?e:null}function Hq(e){if(!e||typeof e!=`object`)return null;let t=e;if(typeof t.geometry!=`string`||!Lq.has(t.geometry))return null;let n=Vq(t.attempts,zq);if(n===null)return null;let r={geometry:t.geometry,attempts:n,bitmapsChecked:0,fontFacesChecked:0,unverifiedBitmaps:0,strippedMarks:0};for(let e of Rq){let n=Vq(t[e],Bq);if(n===null)return null;r[e]=n}return r}function Uq(e){let t=new Image;return t.src=e,t.decode().then(()=>({width:t.naturalWidth,height:t.naturalHeight}))}function Wq(e){throw new Pq(`INVALID_COVER`,e)}function Gq(e){let t=e.endsWith(`==`)?2:e.endsWith(`=`)?1:0;return Math.floor(e.length*3/4)-t}async function Kq(e,t=Uq){let n=e.dataUrl;(typeof n!=`string`||!n.startsWith(`data:image/png;base64,`))&&Wq(`The deck sent back something that is not a PNG.`);let r=n.slice(_q.length);(!r||!Fq.test(r))&&Wq(`The deck sent back an unreadable image.`),Gq(r)>6291456&&Wq(`The capture is larger than the ${gq/(1024*1024)} MB cover limit.`);let i;try{i=atob(r.slice(0,12))}catch{Wq(`The deck sent back an unreadable image.`)}i.slice(0,8)!==Iq&&Wq(`The deck sent back something that is not a PNG.`);let a;try{a=await t(n)}catch{Wq(`The capture could not be decoded as an image.`)}let o=e=>Number.isInteger(e)&&e>=1&&e<=1400;(!o(a.width)||!o(a.height))&&Wq(`The capture is ${a.width}x${a.height}; a cover is at most ${hq} pixels on a side.`),(e.width!==a.width||e.height!==a.height)&&Wq(`The capture is not the size the deck said it was.`);let s={dataUrl:n,width:a.width,height:a.height},c=Hq(e.diagnostics);return c&&(s.diagnostics=c),s}var qq=/^[A-Z][A-Z0-9_]{0,63}$/;function Jq(){return`cover-${Date.now().toString(36)}-${Math.random().toString(36).slice(2,10)}`.slice(0,64)}function Yq(e=!1){return Dq()&&!e?`${xq(`BROWSER_UNSUPPORTED`,!0)} (BROWSER_UNSUPPORTED)`:null}function Xq(e){return typeof e.reason==`string`?e.reason:`The capture was canceled.`}function Zq(e){let t=typeof e.code==`string`&&qq.test(e.code)?e.code:`CAPTURE_FAILED`;return new Pq(t,`${xq(t,Dq())} (${t})`)}function Qq(e,t){let n=e.contentWindow,r;try{r=new URL(e.src).origin}catch{return Promise.reject(new Pq(`NO_DECK`,`No deck is running.`))}if(!n||e.src===`about:blank`||r===`null`)return Promise.reject(new Pq(`NO_DECK`,`No deck is running.`));let{signal:i}=t;if(i.aborted)return Promise.reject(new Pq(`CAPTURE_CANCELED`,Xq(i)));let a=Yq();if(a)return Promise.reject(new Pq(`BROWSER_UNSUPPORTED`,a));let o=Jq(),s=e=>{try{n.postMessage({type:e,requestId:o},r)}catch{}};return new Promise((e,a)=>{let c=()=>{window.clearTimeout(d),window.removeEventListener(`message`,f),i.removeEventListener(`abort`,u)},l=e=>{c(),s(mq),a(e)},u=()=>l(new Pq(`CAPTURE_CANCELED`,Xq(i))),d=window.setTimeout(()=>l(new Pq(`CAPTURE_TIMEOUT`,`The deck did not finish the capture in time.`)),t.timeoutMs??3e4),f=t=>{if(t.source!==n||t.origin!==r)return;let i=t.data;!i||i.type!==`castle-play-cover-result`||i.requestId!==o||(c(),i.ok===!0?e(i):a(Zq(i)))};window.addEventListener(`message`,f),i.addEventListener(`abort`,u),s(pq)}).then(e=>Kq(e,t.decode))}var $q=`castle-capture-native-cover`,eJ=`is-native-cover-capture`,tJ={geometry:`native`,attempts:1,bitmapsChecked:0,fontFacesChecked:0,unverifiedBitmaps:0,strippedMarks:0},nJ=!1,rJ=new Set;function iJ(e){nJ!==e&&(nJ=e,rJ.forEach(t=>t(e)))}function aJ(e){let t=gJ();if(!t||!Ob(e)||e.origin!==t)return;let n=e.data;!n||n.type!==`castle-deck-meta`||iJ(n.hostCapabilities?.nativeCover===!0)}typeof window<`u`&&typeof window.addEventListener==`function`&&window.addEventListener(`message`,aJ);function oJ(){return nJ&&gJ()!==null}function sJ(e){return rJ.add(e),()=>{rJ.delete(e)}}function cJ(){return new Promise(e=>{let t=window.requestAnimationFrame?.bind(window);if(!t){window.setTimeout(e,32);return}t(()=>t(()=>e()))})}function lJ(e){let{x:t,y:n,width:r,height:i}=e;return![t,n,r,i].every(Number.isFinite)||r<=0||i<=0?null:{x:t,y:n,width:r,height:i}}function uJ(e,t,n){let r=gJ();if(!r||!nJ)return Promise.reject(new Pq(`NATIVE_CAPTURE_UNAVAILABLE`,`${xq(`NATIVE_CAPTURE_UNAVAILABLE`)} (NATIVE_CAPTURE_UNAVAILABLE)`));let{signal:i}=n;if(i.aborted)return Promise.reject(new Pq(`CAPTURE_CANCELED`,Xq(i)));let a=Jq();return t.classList.add(eJ),new Promise((o,s)=>{let c=!1,l=()=>{c=!0,window.clearTimeout(d),window.removeEventListener(`message`,f),i.removeEventListener(`abort`,u),t.classList.remove(eJ)},u=()=>{c||(l(),s(new Pq(`CAPTURE_CANCELED`,Xq(i))))},d=window.setTimeout(()=>{c||(l(),s(new Pq(`CAPTURE_TIMEOUT`,`${xq(`CAPTURE_TIMEOUT`)} (CAPTURE_TIMEOUT)`)))},n.timeoutMs??2e4);function f(e){if(!Ob(e)||e.origin!==r)return;let t=e.data;!t||t.type!==`castle-capture-native-cover-result`||t.requestId!==a||(l(),t.ok===!0?o(t):s(Zq(t)))}window.addEventListener(`message`,f),i.addEventListener(`abort`,u),(n.nextPaint??cJ)().then(()=>{if(c)return;let t=lJ(e.getBoundingClientRect());if(!t){l(),s(new Pq(`EMPTY_TARGET`,`${xq(`EMPTY_TARGET`)} (EMPTY_TARGET)`));return}try{window.parent.postMessage({type:$q,requestId:a,rect:t},r)}catch{l(),s(new Pq(`NATIVE_CAPTURE_UNAVAILABLE`,`${xq(`NATIVE_CAPTURE_UNAVAILABLE`)} (NATIVE_CAPTURE_UNAVAILABLE)`))}})}).then(e=>Kq(e,n.decode)).then(e=>({...e,diagnostics:tJ}))}var dJ=`castle-set-cover`,fJ=`castle-set-cover-result`,pJ=3e4,mJ=`Covers can only be set from the Castle editor.`,hJ=new Set([`https://castle.xyz`]);function gJ(){if(typeof window>`u`||window.parent===window)return null;let e=window.__CASTLE_HOST_ORIGIN__;return e&&hJ.has(e)?e:null}function _J(){return gJ()!==null}var vJ=new Set([`not_pushed`,`not_an_image`,`upload_failed`]);function yJ(e,t=pJ){let n=gJ();return n?new Promise(r=>{let i=Jq(),a=e=>{window.clearTimeout(o),window.removeEventListener(`message`,s),r(e)},o=window.setTimeout(()=>a({ok:!1,error:`The Castle editor did not respond. Try again.`,reason:`host_timeout`}),t);function s(e){if(!Ob(e)||e.origin!==n)return;let t=e.data;!t||t.type!==fJ||t.requestId!==i||(t.ok===!0?a({ok:!0}):a({ok:!1,error:typeof t.error==`string`&&t.error?t.error:`Could not set the cover.`,reason:typeof t.code==`string`&&vJ.has(t.code)?t.code:`host_refused`}))}window.addEventListener(`message`,s),window.parent.postMessage({type:dJ,requestId:i,dataUrl:e},n)}):Promise.resolve({ok:!1,error:mJ,reason:`no_host`})}var bJ=`castle-play-cover-event`,xJ=/^[A-Z_]{1,40}$/,SJ=12e4;function CJ(e){return Number.isFinite(e)?Math.min(SJ,Math.max(0,Math.round(e))):0}function wJ(e){let t=e instanceof Pq?e.code:`UNKNOWN`;return xJ.test(t)?t:`OTHER`}function TJ(e,t,n){return{event:`capture_succeeded`,captureMs:CJ(t),captureIndex:n,width:e.width,height:e.height,...e.diagnostics}}function EJ(e,t,n){return{event:`capture_refused`,code:wJ(e),captureMs:CJ(t),captureIndex:n}}function DJ(e,t){return e.ok?{event:`use_as_cover_succeeded`,publishMs:CJ(t)}:{event:`use_as_cover_failed`,reason:e.reason??`host_refused`,publishMs:CJ(t)}}function OJ(){let e=new Uint8Array(8);try{crypto.getRandomValues(e)}catch{for(let t=0;t<e.length;t++)e[t]=Math.floor(Math.random()*256)}return Array.from(e,e=>e.toString(16).padStart(2,`0`)).join(``)}function kJ(e,t){try{let n=gJ();if(!n)return;window.parent.postMessage({type:bJ,sessionId:e,...t},n)}catch{}}var AJ=`The capture was discarded.`,jJ=`The deck restarted, so the capture was canceled.`,MJ=`The Play panel closed, so the capture was canceled.`;function NJ(){let[e,t]=g.useState(oJ);return g.useEffect(()=>(t(oJ()),sJ(()=>t(oJ()))),[]),e}function PJ(e){let t=e.closest(`.play-frame-shell`),n=e.closest(`.play-panel`);return t&&n?{card:t,panel:n}:null}function FJ(){return typeof performance<`u`?performance.now():Date.now()}function IJ(e,t,n){let[r,i]=g.useReducer(Nq,Oq),a=g.useRef(r);a.current=r;let o=g.useRef(n);o.current=n;let s=g.useRef(0),c=g.useRef(null),l=g.useRef(!0),u=g.useRef(null),d=g.useCallback(e=>{let t=c.current;c.current=null,t?.abort(e)},[]);g.useEffect(()=>(l.current=!0,()=>{l.current=!1,d(MJ)}),[d]),g.useEffect(()=>()=>d(jJ),[t,d]);let f=g.useCallback(()=>{let t=e.current;if(!t||!Mq(a.current,o.current))return;let n=++s.current,r=new AbortController;c.current=r,(!a.current.open||!u.current)&&(u.current={id:OJ(),captures:0});let d=u.current,f=++d.captures;a.current.preview&&kJ(d.id,{event:`retake`});let p=FJ();i({type:`capture-start`,op:n});let m=oJ()?PJ(t):null;(m?uJ(m.card,m.panel,{signal:r.signal}):Qq(t,{signal:r.signal})).then(e=>{kJ(d.id,TJ(e,FJ()-p,f)),c.current===r&&(c.current=null),l.current&&i({type:`capture-done`,op:n,preview:{id:n,...e}})},e=>{if(kJ(d.id,EJ(e,FJ()-p,f)),c.current===r&&(c.current=null),!l.current)return;let t=e instanceof Error?e.message:`The deck could not be captured.`,a=e instanceof Pq?e.code:null;i(a===`CAPTURE_CANCELED`?{type:`capture-canceled`,op:n,message:t}:{type:`capture-failed`,op:n,message:t,final:a===`BROWSER_UNSUPPORTED`})})},[e]),p=g.useCallback(()=>{let e=a.current;if(e.busy||!e.preview)return;let t=++s.current,n=u.current?.id??null,r=FJ();i({type:`publish-start`,op:t}),yJ(e.preview.dataUrl).then(e=>{n&&kJ(n,DJ(e,FJ()-r)),l.current&&(e.ok?i({type:`publish-done`,op:t}):i({type:`publish-failed`,op:t,message:e.error??`Could not set the cover.`}))})},[]),m=g.useCallback(()=>{let e=a.current;e.busy!==`publishing`&&(e.open&&u.current&&kJ(u.current.id,{event:`discarded`,hadPreview:e.preview!==null,coverSet:e.preview!==null&&e.published===e.preview.id}),u.current=null,d(AJ),i({type:`discard`}))},[d]),h=NJ(),_=g.useMemo(()=>Yq(h),[h]);return{state:r,canCapture:_===null&&Mq(r,n),unavailable:_,capture:f,publish:p,discard:m}}function LJ(e){return e===`error`?`castle-feedback-danger`:`castle-feedback-quiet`}function RJ(e){let{preview:t,busy:n}=e.state;return t?(0,G.jsx)(`img`,{className:`play-cover-preview`,src:t.dataUrl,width:t.width,height:t.height,alt:`The captured frame, as the cover would look`}):n===`capturing`?(0,G.jsx)(`p`,{className:`castle-feedback-note castle-feedback-quiet`,children:`Capturing the current frame…`}):null}function zJ(e){let{state:t,canCapture:n,capture:r,publish:i,discard:a}=e.cover;if(!t.open)return null;let o=_J(),s=t.preview!==null&&t.published===t.preview.id,c=t.notice??(t.preview&&!o?{kind:`info`,text:`Covers can only be set from the Castle editor.`}:null);return(0,G.jsx)(`div`,{className:`play-cover-anchor`,children:(0,G.jsxs)(`div`,{className:`castle-popover play-cover-popover`,role:`dialog`,"aria-label":`Cover`,children:[(0,G.jsx)(RJ,{state:t}),(0,G.jsxs)(`p`,{className:`castle-feedback-note ${c?LJ(c.kind):``} play-cover-notice${c?``:` is-silent`}`,role:`status`,children:[c?.kind===`success`?(0,G.jsx)(K,{name:`check`}):null,c?.text??``]}),(0,G.jsxs)(`div`,{className:`play-cover-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:i,disabled:!t.preview||t.busy!==null||s||!o,children:(0,G.jsx)(`span`,{children:t.busy===`publishing`?`Setting cover…`:s?kq:`Use as cover`})}),t.notice?.final&&!t.preview?null:(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:r,disabled:!n,children:(0,G.jsx)(`span`,{children:t.busy===`capturing`?`Capturing…`:t.preview?`Retake`:`Try again`})}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:a,disabled:t.busy===`publishing`,children:(0,G.jsx)(`span`,{children:`Discard`})})]})]})})}function BJ(e){let t=e.role??`edit`,n=g.useRef(null);return g.useEffect(()=>{let e=n.current;return()=>{e&&UK(e)}},[]),(0,G.jsx)(`div`,{className:`deck-panel`,children:(0,G.jsx)(`iframe`,{ref:n,className:`deck-frame`,src:e.src,title:e.title,onLoad:e=>qK(e.currentTarget,t),allow:`autoplay; clipboard-read; clipboard-write; fullscreen; gamepad; accelerometer; gyroscope; magnetometer`})})}function VJ(e){return e===`code`?`code`:`visual`}function HJ(e){return ve(e).map(e=>({mode:VJ(e.classId),label:e.label}))}function UJ(e){let{state:t,refresh:n}=xw(e.file),[r,i]=g.useState(null),[a,o]=g.useState(null),s=t=>{i(null),o(null),t(e.file).then(n).then(e.onSwapped).catch(e=>o(e instanceof Error?e.message:String(e)))},c=t?.ownFork===!0,l=e.alias??`an import`;return(0,G.jsxs)(`div`,{className:`editor-import-banner`,role:`status`,children:[(0,G.jsx)(`span`,{className:c?`editor-import-chip editor-fork-chip`:`editor-import-chip`,children:c?`Forked`:`Read Only`}),(0,G.jsx)(`span`,{className:`editor-import-banner-text`,children:a??(c?`Your version of a file from ${l}`:`Imported from ${l}`)}),(c||t?.forkable)&&(0,G.jsx)(`button`,{type:`button`,className:`editor-import-banner-action`,onClick:()=>i(c?`revert`:`fork`),children:c?`Drop fork`:`Fork`}),r===`fork`&&(0,G.jsx)(_C,{title:`Fork this file?`,body:`This file is from the import '${l}'. Fork this file so you can modify it?`,confirmLabel:`Fork`,onConfirm:()=>s(Re),onClose:()=>i(null)}),r===`revert`&&(0,G.jsx)(_C,{title:`Drop this fork?`,body:vC(e.file,t),confirmLabel:`Drop fork`,onConfirm:()=>s(ze),onClose:()=>i(null)})]})}var WJ=e=>{let t=e.lastIndexOf(`/`);return t<0?``:e.slice(0,t)},GJ=e=>e.split(`/`).pop()||e,KJ=(0,G.jsx)(K,{name:`sidebar`});function qJ(e){let t=YS(),[n,r]=g.useState(null);g.useEffect(()=>{let e=!0;return je().then(t=>e&&r(t),()=>e&&r([])),()=>{e=!1}},[]);let i=g.useMemo(()=>{let e=new Map;for(let t of n??[]){let n=WJ(t),r=e.get(n);r?r.push(t):e.set(n,[t])}return[...e.entries()].sort((e,t)=>e[0].localeCompare(t[0]))},[n]);return(0,G.jsx)(`aside`,{className:`editor-drawer`,children:n===null?(0,G.jsx)(`div`,{className:`editor-drawer-empty`,children:`loading…`}):n.length===0?(0,G.jsx)(`div`,{className:`editor-drawer-empty`,children:`no files`}):i.map(([n,r])=>(0,G.jsxs)(`div`,{children:[(0,G.jsx)(`div`,{className:`editor-drawer-folder`,children:n||`/`}),r.sort().map(n=>(0,G.jsx)(`button`,{type:`button`,className:`editor-drawer-item${n===e.currentFile?` current`:``}`,title:n,onClick:()=>t.openFile(n),children:GJ(n)},n))]},n||`(root)`))})}function JJ(e){let t=YS(),n=e.file??``,r=t.kitEditorExts,i=g.useRef(null),{lifecycle:a}=e,o=VJ(e.editorClass??``),[s,c]=g.useState(o);g.useEffect(()=>c(o),[n,o]);let[l,u]=g.useState(!1),d=e.drawerOpen??l,f=u;g.useEffect(()=>{let e=()=>{let e=i.current,t=e?.querySelector(`.cm-content`);t?DF(t):e?.querySelector(`iframe`)?.focus()};TF(a.id,e);let t=a.onDidActiveChange(t=>{t&&requestAnimationFrame(e)});return()=>{EF(a.id),t()}},[a]);let p=r!==null&&r.includes(Ye(n)),m=Ce(n),h=m?we(n):null,_=r===null?[]:HJ(n),v=_.some(e=>e.mode===s)?s:_[0]?.mode??`code`,y=p&&v===`visual`,b=g.useRef(null);y&&b.current?.file!==n&&(b.current={file:n,at:nC(n,`fragment`)?.fragment});let S=y?b.current?.at:void 0,C;if(r===null)C=(0,G.jsx)(`div`,{className:`code-editor-overlay`,children:`loading…`});else if(y){let e=pe(n)?.module;C=(0,G.jsx)(BJ,{src:MK(`edit`,x(`/index.html?file=${encodeURIComponent(n)}`)+(e?`&editorModule=${encodeURIComponent(e)}`:``)+(S?`&at=${encodeURIComponent(S)}`:``)),title:n,role:`edit`})}else C=(0,G.jsx)(jI,{file:n,panelId:a.id});return fC(i,a.id,y,n),(0,G.jsxs)(`div`,{ref:i,className:`editor-panel-root`,children:[!e.hideContextBar&&(0,G.jsxs)(`div`,{className:`editor-contextbar`,children:[(0,G.jsx)(`button`,{type:`button`,className:`editor-drawer-toggle${d?` on`:``}`,"aria-label":`Toggle files`,"aria-pressed":d,title:`Toggle files`,onClick:()=>f(e=>!e),children:KJ}),_.length>=2&&(0,G.jsx)(`select`,{className:`editor-view-picker`,value:v,onChange:e=>c(e.target.value),"aria-label":`Editor view`,title:`Switch editor view`,children:_.map(e=>(0,G.jsx)(`option`,{value:e.mode,children:e.label},e.mode))}),(0,G.jsx)(`span`,{className:`editor-contextbar-path`,title:n,children:n}),p&&v===`visual`&&(0,G.jsx)(`button`,{type:`button`,className:`editor-contextbar-reload`,"aria-label":`Reload panel`,title:`Reload this panel to pick up code changes`,onClick:()=>tT(i.current),children:(0,G.jsx)(K,{name:`sync`})})]}),(0,G.jsxs)(`div`,{className:`editor-shell`,children:[d&&(e.drawer??(0,G.jsx)(qJ,{currentFile:n})),(0,G.jsxs)(`div`,{className:`editor-panel-body`,children:[m&&(0,G.jsx)(UJ,{alias:h,file:n,onSwapped:()=>tT(i.current)}),(0,G.jsx)(fq,{}),(0,G.jsx)(`div`,{className:`editor-panel-view`,children:C})]})]})]})}var YJ=500;function XJ(e){QK(e.map(e=>e.text).join(`
|
|
384
|
+
`))}function ZJ(){document.body.classList.remove(`play-logs-resizing`)}function QJ(e){if(e.button!==0)return;let t=e.currentTarget,n=t.closest(`.play-logs`),r=n?.closest(`.play-panel`);if(!(n instanceof HTMLElement)||!(r instanceof HTMLElement)||!n.classList.contains(`is-open`))return;e.preventDefault(),e.stopPropagation();let i=e.pointerId;try{t.setPointerCapture(i)}catch{}let a=e.clientY,o=n.getBoundingClientRect().height,s=n.querySelector(`.play-logs-header`),c=n.querySelector(`.play-logs-toolbar`),l=(s instanceof HTMLElement?s.offsetHeight:0)+(c instanceof HTMLElement?c.offsetHeight:0)+32,u=Math.max(l,r.clientHeight-80);document.body.classList.add(`play-logs-resizing`);let d=e=>{let t=Math.min(u,Math.max(l,o+(a-e.clientY)));n.style.setProperty(`--play-logs-height`,`${t}px`)},f=()=>{ZJ(),t.removeEventListener(`pointermove`,d),t.removeEventListener(`pointerup`,f),t.removeEventListener(`pointercancel`,f);try{t.releasePointerCapture(i)}catch{}};t.addEventListener(`pointermove`,d),t.addEventListener(`pointerup`,f),t.addEventListener(`pointercancel`,f)}function $J(e){let[t,n]=g.useState(!1),r=g.useId(),i=g.useRef(null);return g.useEffect(()=>{t&&i.current&&(i.current.scrollTop=i.current.scrollHeight)},[e.logs,t]),g.useEffect(()=>()=>ZJ(),[]),(0,G.jsxs)(`div`,{className:`play-logs${t?` is-open`:``}`,children:[(0,G.jsx)(`div`,{className:`play-logs-resize`,role:`separator`,"aria-orientation":`horizontal`,"aria-label":`Resize logs`,onPointerDown:QJ}),(0,G.jsxs)(`div`,{className:`play-logs-header${e.onSnap?` has-snap`:``}${e.onCover?` has-cover`:``}`,children:[(0,G.jsx)(`button`,{type:`button`,className:`play-logs-expand`,onClick:()=>n(e=>!e),"aria-expanded":t,"aria-label":t?`Collapse logs`:`Expand logs`}),(0,G.jsxs)(`span`,{className:`play-logs-label`,children:[(0,G.jsx)(K,{name:t?`chevron-down`:`chevron-right`}),(0,G.jsx)(`span`,{className:`castle-text-style-smallcaps`,children:`Logs`}),e.logs.length>0?(0,G.jsx)(`span`,{className:`castle-button-badge`,children:e.logs.length}):null]}),e.onSnap!==void 0||e.snapping||e.snapError?(0,G.jsx)(`p`,{className:`play-logs-pending is-error${e.snapError?``:` is-silent`}`,role:`status`,children:e.snapError??``}):null,!e.snapError&&e.pending?(0,G.jsx)(`p`,{className:`play-logs-pending`,children:`Changes available`}):null,e.onSnap?(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-snap`,onClick:e.onSnap,disabled:e.snapping,"aria-label":`Send a screenshot to the operator`,title:`Take a screenshot of the running deck and attach it to your next message`,children:[(0,G.jsx)(K,{name:`camera`}),(0,G.jsx)(`span`,{children:e.snapping?`Snapping…`:`Snap`})]}):null,e.onCover&&e.coverUnavailable?(0,G.jsx)(`p`,{className:`play-logs-pending is-note`,id:r,children:e.coverUnavailable}):null,e.onCover?(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-cover`,onClick:e.onCover,disabled:e.coverDisabled,"aria-haspopup":`dialog`,"aria-expanded":e.coverOpen===!0,"aria-describedby":e.coverUnavailable?r:void 0,title:e.coverUnavailable??`Capture this frame to preview as the deck's cover`,children:[(0,G.jsx)(K,{name:`image`}),(0,G.jsx)(`span`,{children:`Cover`})]}):null,(0,G.jsxs)(`button`,{type:`button`,className:`castle-button play-logs-restart${e.pending?` is-pending`:``}`,onClick:e.onReload,"aria-label":e.pending?`Restart deck to apply changes`:`Restart deck`,title:e.pending?`Files changed since this run started. Restart to apply them.`:`Restart the deck`,children:[(0,G.jsx)(`span`,{className:`play-logs-restart-icon${e.reloadSpinning?` is-spinning`:``}`,children:(0,G.jsx)(K,{name:`sync`})}),(0,G.jsx)(`span`,{children:`Restart`})]})]}),t?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`play-logs-toolbar`,children:[e.actions,(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onClear,children:[(0,G.jsx)(K,{name:`trash`}),(0,G.jsx)(`span`,{children:`Clear`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:()=>XJ(e.logs),children:[(0,G.jsx)(K,{name:`copy`}),(0,G.jsx)(`span`,{children:`Copy`})]})]}),(0,G.jsx)(`div`,{className:`play-logs-body`,ref:i,children:e.logs.length===0?(0,G.jsx)(`div`,{className:`play-logs-empty`,children:`No output`}):e.logs.map(e=>(0,G.jsx)(`div`,{className:`play-logs-line play-logs-${e.level}`,children:e.text},e.id))})]}):null]})}var eY=e=>e.replace(/^scenes\//,``).replace(/\.scene$/,``);function tY(e){let[t,n]=g.useState([]),r=g.useRef(1),i=g.useCallback((e,t)=>{let i=e===`warn`||e===`error`?e:`log`;n(e=>{let n=e.concat({id:r.current++,level:i,text:typeof t==`string`?t:``});return n.length>YJ?n.slice(n.length-YJ):n})},[]);return g.useEffect(()=>{let t=t=>{if(!e.current||t.source!==e.current.contentWindow)return;let n=t.data;!n||n.type!==`castle-console`||i(n.level,n.text)};return window.addEventListener(`message`,t),()=>window.removeEventListener(`message`,t)},[i,e]),g.useEffect(()=>cS(`server_log`,e=>i(e.level,e.text)),[i]),{logs:t,clear:()=>n([])}}var nY=1e3;function rY(e,t,n){let r=g.useRef(new Set);return g.useEffect(()=>{let e=r.current;return()=>{for(let t of[...e])t()}},[]),g.useCallback(i=>{let a=e.current?.contentWindow??null,o=t.current;if(!a)return n();let s=new Set(i.changes.filter(e=>e.tuned).map(e=>e.path)),c={seq:i.seq,paths:s},l=0,u=e=>{window.clearTimeout(l),window.removeEventListener(`message`,f),r.current.delete(d),!e&&t.current===o&&n()},d=()=>u(!0),f=e=>{if(e.source!==a)return;let t=iK(c,e.data);if(t){if(!t.ok)return u(!1);s.delete(t.path),s.size===0&&u(!0)}};r.current.add(d),window.addEventListener(`message`,f),l=window.setTimeout(()=>u(!1),nY)},[e,n,t])}function iY(e){let t=e.scene??ye()??``,[n,r]=g.useState(t),[i,a]=g.useState([]);g.useEffect(()=>{let e=!0;return je().then(t=>{e&&a(t.filter(e=>e.startsWith(`scenes/`)&&e.endsWith(`.scene`)).sort())},()=>{}),()=>{e=!1}},[]);let o=MK(`play`,x(oK(n||null,{logs:!0}))),s=g.useRef(null),{logs:c,clear:l}=tY(s),[u,d]=g.useState(!1),f=oY(s),[p,m]=g.useState(0);g.useEffect(()=>{let e=s.current;return()=>{e&&UK(e)}},[p]);let[h,_]=g.useState(!1),[y,b]=g.useState(!1),S=`${p}|${h?``:o}`,[C,w]=g.useState(null),T=IJ(s,S,C===S),E=!h&&!v&&de(),D=g.useCallback(()=>{_(!1),m(e=>e+1),b(!1)},[]),O=g.useCallback(()=>{D(),d(!0),window.setTimeout(()=>d(!1),600)},[D]),k=g.useRef(y);k.current=y;let A=g.useRef(p);A.current=p;let{lifecycle:j}=e,ee=g.useCallback(()=>{b(!0),j.isVisible()||_(!0)},[j]),M=rY(s,A,ee);return g.useEffect(()=>oS(e=>{let t=aK(e.changes);t!==`ignore`&&(t===`restart`?ee():M(e))}),[M,ee]),g.useEffect(()=>j.onDidVisibilityChange(e=>{e&&k.current&&D()}),[j,D]),(0,G.jsxs)(`div`,{className:`play-panel`,children:[(0,G.jsx)(`div`,{className:`play-stage`,children:(0,G.jsxs)(`div`,{className:`play-frame-shell`,children:[(0,G.jsx)(`iframe`,{ref:s,className:`deck-frame`,src:h?`about:blank`:o,title:`play`,onLoad:()=>{h||b(!1),h||w(S),s.current&&!h&&qK(s.current,`play`,e.playSessionSlot)},allow:`autoplay; fullscreen; gamepad; accelerometer; gyroscope; magnetometer`},p),(0,G.jsx)(nK,{})]})}),i.length>1?(0,G.jsx)(`div`,{className:`play-scene-picker`,children:(0,G.jsx)(`select`,{className:`castle-select`,value:n,onChange:e=>r(e.target.value),"aria-label":`Scene`,children:i.map(e=>(0,G.jsx)(`option`,{value:e,children:eY(e)},e))})}):null,E?(0,G.jsx)(zJ,{cover:T}):null,(0,G.jsx)($J,{logs:c,onClear:l,onReload:O,reloadSpinning:u,pending:y,onSnap:h||v||!ue()?void 0:f.snap,snapping:f.snapping,snapError:f.error,onCover:E?T.capture:void 0,coverDisabled:!T.canCapture||T.state.open,coverUnavailable:T.unavailable,coverOpen:T.state.open})]})}var aY=6e3;function oY(e){let t=YS(),[n,r]=g.useState(!1),[i,a]=g.useState(null);g.useEffect(()=>{if(!i)return;let e=window.setTimeout(()=>a(null),aY);return()=>window.clearTimeout(e)},[i]);let o=g.useRef(t);return o.current=t,{snap:g.useCallback(()=>{let t=e.current;t&&(r(!0),a(null),ZK(t).then(yK).then(e=>{let t=new Date().toISOString().replace(/[:.]/g,`-`).slice(0,19);o.current.attachImageToChat({name:`snap-${t}.png`,dataUrl:e})||a(`6 images are already waiting for your next message.`)}).catch(e=>{a(e instanceof Error?e.message:`Could not capture the deck.`)}).finally(()=>r(!1)))},[e]),snapping:n,error:i}}function sY(e){let t=YS(),n=g.useRef(null),r=g.useRef(null),{lifecycle:i}=e;return g.useEffect(()=>{let e=n.current;if(!e)return;let a=mG(e,t.terminalTheme);r.current=a;let o=()=>{i.isVisible()&&(a.activate(),a.fit(),i.isActive()&&a.focus())};o();let s=i.onDidVisibilityChange(o),c=i.onDidActiveChange(o);return()=>{s(),c(),a.dispose(),r.current=null}},[i]),g.useEffect(()=>{r.current?.setTheme(t.terminalTheme)},[t.terminalTheme]),(0,G.jsx)(`div`,{className:`term-panel`,children:(0,G.jsx)(`div`,{className:`term-host`,ref:n})})}function cY(e){let[t,n]=g.useState(null);g.useEffect(()=>{let e=!0,t=()=>{je().then(t=>e&&n(t),()=>e&&n([]))};t();let r=oS(e=>{e.changes.some(e=>e.event!==`change`)&&t()});return()=>{e=!1,r()}},[]);let{onSetView:r}=e;return(0,G.jsxs)(`aside`,{className:`flow-class-drawer`,children:[r&&(0,G.jsx)(ZT,{file:e.currentFile,view:e.view,onSetView:r}),(0,G.jsx)(XT,{currentFile:e.currentFile,filterClass:e.filterClass,files:t,recent:cx(be()),onOpen:e.onOpen})]})}var lY=x(`/__castle/import/`);function uY(e){return!!(e&&e.hasSource&&!e.imported)}var dY=class extends Error{code;constructor(e,t){super(e),this.name=`ImportRequestError`,this.code=t}};async function fY(e,t){let n=await fetch(`${lY}${e}`,t),r=await n.json().catch(()=>null);if(!r)throw n.ok?new dY("This serve is older than the editor. Restart `castle-web serve` to pick up importing.",`stale-serve`):new dY(`Request failed (${n.status})`,null);if(!n.ok)throw new dY(r.error??`Request failed (${n.status})`,r.code??null);return r}async function pY(e){let t=await Te().catch(()=>[]),n=new Set(t.map(e=>e.deckId).filter(Boolean));return e.map(e=>({...e,imported:n.has(e.deckId)}))}var mY=15e3,hY=null;function gY(e,t){return typeof window>`u`||window.parent===window||hY===!1?Promise.resolve(null):new Promise((n,r)=>{let i=Math.random().toString(36).slice(2),a=setTimeout(()=>{hY=!1,o(),n(null)},mY);function o(){clearTimeout(a),window.removeEventListener(`message`,s)}function s(t){if(!Ob(t))return;let a=t.data;!a||a.type!==`${e}-result`||a.requestId!==i||(hY=!0,o(),a.ok&&a.data?n(a.data):r(new dY(a.error??`The editor host could not answer.`,a.code??null)))}window.addEventListener(`message`,s),window.parent.postMessage({type:e,requestId:i,...t},kb())})}async function _Y(e){let t=await gY(`castle-import-list`,{tab:e});return t?{...t,decks:await pY(t.decks)}:fY(`list?tab=${e}`)}function vY(){return typeof window<`u`&&window.parent!==window}function yY(){sS(`import_list_request`,async e=>({ok:!0,list:await _Y(e.tab===`saved`||e.tab===`kits`?e.tab:`mine`)}))}async function bY(e){let t=await gY(`castle-import-resolve`,{ref:e});return t?(await pY([t.deck]))[0]:(await fY(`resolve?ref=${encodeURIComponent(e)}`)).deck}async function xY(e){return(await fY(`files?deckId=${encodeURIComponent(e)}`)).fileCount}function SY(e){return fY(`add`,{method:`POST`,headers:{"content-type":`application/json`},body:JSON.stringify({deckRef:e})})}var CY=[{id:`mine`,label:`My decks`},{id:`saved`,label:`Saved`},{id:`kits`,label:`Kits`},{id:`link`,label:`From a link`},{id:`updates`,label:`Updates`}];function wY(e){return e instanceof Error?e.message:String(e)}function TY(e){let[t,n]=g.useState({}),[r,i]=g.useState({}),a=g.useRef(new Set);return g.useEffect(()=>{e===`link`||e===`updates`||a.current.has(e)||(a.current.add(e),_Y(e).then(t=>n(n=>({...n,[e]:t}))).catch(t=>i(n=>({...n,[e]:wY(t)}))))},[e]),{list:t[e]??null,error:r[e]??null}}function EY(e){let[t,n]=g.useState({}),r=g.useRef(new Set);return g.useEffect(()=>{let t=e?.hasSource?e.deckId:null;!t||r.current.has(t)||(r.current.add(t),xY(t).then(e=>{e!==null&&n(n=>({...n,[t]:e}))}).catch(()=>{}))},[e]),t}function DY(){let[e,t]=g.useState([]);return g.useEffect(()=>{let e=!0;return Te().then(n=>{e&&t(n.filter(e=>e.updateAvailable))}),()=>{e=!1}},[]),e}function OY(e){let{initialUpdateAlias:t}=e,[n,r]=g.useState(t?`updates`:`mine`),[i,a]=g.useState(null),[o,s]=g.useState(()=>new Set(t?[t]:[])),[c,l]=g.useState(``),[u,d]=g.useState(!1),[f,p]=g.useState(!1),[m,h]=g.useState(null),{list:_,error:v}=TY(n),y=DY(),b=EY(i),x=u||f,S=y.filter(e=>o.has(e.alias)),C=e=>{r(e),a(null),l(``),h(null)},w=e=>{h(null),s(t=>{let n=new Set(t);return n.delete(e)||n.add(e),n})},T=()=>{h(null),s(S.length===y.length?new Set:new Set(y.map(e=>e.alias)))},E=()=>{i&&(d(!0),h(null),SY(i.deckId).then(e.onImported).catch(e=>{h(wY(e)),d(!1)}))},D=()=>{S.length!==0&&(p(!0),h(null),(async()=>{for(let e of S)try{await Ee(e.alias)}catch(t){h(`${e.alias}: ${wY(t)}`),p(!1);return}e.onUpdated(S.map(e=>e.alias))})())},O=n===`updates`;return(0,gb.createPortal)((0,G.jsx)(`div`,{className:`castle-modal-scrim`,onClick:x?void 0:e.onClose,children:(0,G.jsxs)(`div`,{className:`castle-modal castle-import-modal`,role:`dialog`,"aria-label":`Import a deck`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`castle-modal-text`,children:`Import a deck`}),(0,G.jsx)(`div`,{className:`castle-key-tabs castle-import-tabs`,children:CY.map(e=>(0,G.jsx)(`button`,{type:`button`,className:ux(`castle-key-tab`,n===e.id&&`active`),onClick:()=>C(e.id),children:e.id===`updates`&&y.length>0?`${e.label} (${y.length})`:e.label},e.id))}),O?(0,G.jsx)(AY,{outdated:y,ticked:o,onToggle:w,onToggleAll:T}):n===`link`?(0,G.jsx)(IY,{selected:i,counts:b,onResolved:a}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`input`,{className:`castle-key-input castle-import-filter`,placeholder:`Filter`,spellCheck:!1,value:c,onChange:e=>l(e.target.value)}),(0,G.jsx)(FY,{list:_,error:v,filter:c,selected:i,counts:b,onSelect:a})]}),m?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:m}):null,(0,G.jsxs)(`div`,{className:`castle-modal-actions`,children:[(0,G.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:x,children:`Cancel`}),O?(0,G.jsx)(`button`,{type:`button`,onClick:D,disabled:x||S.length===0,children:kY(S.length,f)}):(0,G.jsx)(`button`,{type:`button`,onClick:E,disabled:x||!uY(i),children:u?`Importing…`:`Import`})]})]})}),document.body)}function kY(e,t){return t?`Updating…`:e>1?`Update ${e}`:`Update`}function AY(e){let{outdated:t,ticked:n}=e;if(t.length===0)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`Every import is at its deck’s latest version.`});let r=t.filter(e=>n.has(e.alias)).length;return(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`div`,{className:`castle-import-select-bar`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-import-select-all`,onClick:e.onToggleAll,children:r===t.length?`Clear all`:`Select all`}),(0,G.jsxs)(`span`,{className:`castle-import-row-meta`,children:[r,` of `,t.length,` selected`]})]}),(0,G.jsx)(`div`,{className:`castle-import-list`,children:t.map(t=>(0,G.jsx)(NY,{status:t,ticked:n.has(t.alias),onToggle:()=>e.onToggle(t.alias)},t.alias))})]})}function jY(e,t){if(!e)return`unknown`;let n=new Date(e);return Number.isNaN(n.getTime())?e:n.toLocaleString(void 0,{month:`short`,day:`numeric`,hour:`numeric`,minute:`2-digit`,...t?{second:`2-digit`}:{}})}function MY(e){let t=jY(e.version,!1),n=jY(e.latest,!1);return t===n?`${jY(e.version,!0)} → ${jY(e.latest,!0)}`:`${t} → ${n}`}function NY(e){let{status:t,ticked:n}=e;return(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-import-row castle-import-update-row`,n&&`selected`),onClick:e.onToggle,role:`checkbox`,"aria-checked":n,children:[(0,G.jsx)(`span`,{className:ux(`castle-import-tick`,n&&`checked`),children:n?(0,G.jsx)(K,{name:`check`}):null}),(0,G.jsxs)(`span`,{className:`castle-import-row-text`,children:[(0,G.jsx)(`span`,{className:`castle-import-row-title`,children:t.alias}),(0,G.jsx)(`span`,{className:`castle-import-row-meta`,children:MY(t)})]})]})}function PY(e,t){let n=t.trim().toLowerCase();return n?`${e.title} @${e.creator??``}`.toLowerCase().includes(n):!0}function FY(e){let{list:t,error:n,filter:r,selected:i,counts:a,onSelect:o}=e;if(n)return(0,G.jsxs)(`div`,{className:`castle-import-empty`,children:[`could not list decks: `,n]});if(!t)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`Loading…`});if(!t.signedIn)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:vY()?`Sign in to Castle to see your decks.`:"Run `castle-web login` to see your decks."});if(t.decks.length===0)return(0,G.jsx)(`div`,{className:`castle-import-empty`,children:`No decks here with source files to import.`});let s=t.decks.filter(e=>PY(e,r));return s.length===0?(0,G.jsxs)(`div`,{className:`castle-import-empty`,children:[`Nothing matches “`,r.trim(),`”.`]}):(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-import-list`,children:s.map(e=>(0,G.jsx)(LY,{deck:e,fileCount:a[e.deckId],selected:i?.deckId===e.deckId,onSelect:()=>o(e)},e.deckId))}),t.truncated?(0,G.jsxs)(`div`,{className:`castle-import-note`,children:[`Showing the first `,t.decks.length,`; there are more.`]}):null]})}function IY(e){let[t,n]=g.useState(``),[r,i]=g.useState(!1),[a,o]=g.useState(null),s=()=>{let n=t.trim();!n||r||(i(!0),o(null),e.onResolved(null),bY(n).then(e.onResolved).catch(e=>o(wY(e))).finally(()=>i(!1)))};return(0,G.jsxs)(`div`,{className:`castle-import-link`,children:[(0,G.jsxs)(`div`,{className:`castle-import-link-row`,children:[(0,G.jsx)(`input`,{className:`castle-key-input`,placeholder:`castle.xyz/d/… or a deck id`,spellCheck:!1,value:t,onChange:e=>n(e.target.value),onKeyDown:e=>{e.key===`Enter`&&(e.preventDefault(),s())}}),(0,G.jsx)(`button`,{type:`button`,onClick:s,disabled:r||!t.trim(),children:r?`Looking…`:`Look up`})]}),a?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:a}):null,e.selected?(0,G.jsx)(`div`,{className:`castle-import-list`,children:(0,G.jsx)(LY,{deck:e.selected,fileCount:e.counts[e.selected.deckId],selected:!0,onSelect:()=>void 0})}):null]})}function LY(e){let{deck:t,fileCount:n,selected:r}=e,i=uY(t),a=t.imported?`already imported`:t.hasSource?n===void 0?null:`${n} files`:`no source files`,o=[t.creator?`@${t.creator}`:null,a].filter(Boolean);return(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-import-row`,r&&`selected`,!i&&`disabled`),onClick:e.onSelect,disabled:!i,"aria-pressed":r,children:[t.imageUrl?(0,G.jsx)(`img`,{className:`castle-import-thumb`,src:t.imageUrl,alt:``}):(0,G.jsx)(`span`,{className:`castle-import-thumb`}),(0,G.jsxs)(`span`,{className:`castle-import-row-text`,children:[(0,G.jsx)(`span`,{className:`castle-import-row-title`,children:t.title}),(0,G.jsx)(`span`,{className:`castle-import-row-meta`,children:o.join(` · `)}),t.parentCreator?(0,G.jsxs)(`span`,{className:`castle-import-row-meta`,children:[(0,G.jsx)(K,{name:`clone`}),` remix of @`,t.parentCreator]}):null]})]})}var RY=`/ (Deck root)`;function zY(e){return e||RY}function BY(e){return e.trim().replace(/^\/+|\/+$/g,``)}function VY(e,t){let n=e.split(`/`);for(let e of n){if(!e)return`Path cannot have empty segments.`;if(e===`.`||e===`..`)return`Path cannot contain “.” or “..”.`;if(e.startsWith(`.`))return`Hidden folders cannot be created here.`}return Ce(e)?`Imported files cannot be a destination.`:t.includes(e)?`“${e}” is already a file.`:null}function HY(e,t){let n=BY(t).toLowerCase();return n?e.filter(e=>zY(e).toLowerCase().includes(n)):e.slice()}function UY(e){let t=[],n=[];for(let r of e.split(`/`))r&&(t.push(r),n.push(t.join(`/`)));return n}function WY(e){return(0,G.jsxs)(`button`,{type:`button`,role:`menuitem`,className:ux(`castle-menu-item`,e.danger&&`castle-menu-item-danger`),disabled:e.disabled,"data-folder-selected":e.checked?``:void 0,onClick:e.onClick,children:[(0,G.jsx)(`span`,{className:`castle-menu-icon`,children:(0,G.jsx)(K,{name:e.icon})}),(0,G.jsx)(`span`,{className:`castle-menu-item-label`,children:e.label}),e.checked?(0,G.jsx)(`span`,{className:`castle-menu-check`,children:`✓`}):null]})}function GY(e){let{folders:t,existingFiles:n,selected:r,disabled:i,onChoose:a}=e,[o,s]=g.useState(``),[c,l]=g.useState([]),[u,d]=g.useState(null),f=g.useRef(null),p=g.useRef(null);g.useEffect(()=>f.current?.focus(),[]),g.useEffect(()=>{p.current?.querySelector(`[data-folder-selected]`)?.scrollIntoView({block:`nearest`})},[]);let m=g.useMemo(()=>[...new Set([``,...t,...c])].sort((e,t)=>e.localeCompare(t)),[t,c]),h=HY(m,o),_=BY(o),v=_.length>0&&h.length===0,y=e=>{d(null),a(e)},b=()=>{if(!_)return;let e=VY(_,n);if(e){d(e);return}m.includes(_)||l(e=>[...new Set([...e,...UY(_)])]),s(_),y(_)};return(0,G.jsxs)(`div`,{className:`castle-file-picker`,children:[e.header?(0,G.jsx)(`div`,{className:`castle-menu-header`,children:e.header}):null,e.label?(0,G.jsx)(`p`,{className:`castle-file-picker-label castle-text-style-smallcaps`,children:e.label}):null,(0,G.jsx)(`input`,{ref:f,className:`castle-text-field`,type:`text`,placeholder:`Filter or type a path`,autoComplete:`off`,spellCheck:!1,disabled:i,value:o,onChange:e=>{s(e.target.value),d(null)},onKeyDown:e=>{e.key===`Enter`&&e.preventDefault()}}),(0,G.jsx)(`div`,{ref:p,className:`castle-file-picker-list`,hidden:h.length===0,role:`group`,"aria-label":`Destination folder`,children:h.map(e=>(0,G.jsx)(WY,{icon:`folder`,label:zY(e),checked:r===e,disabled:i,onClick:()=>y(e)},e||`(root)`))}),v?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`folder-plus`,label:`Create “${_}”`,disabled:i,onClick:b})]}):null,u?(0,G.jsx)(`p`,{className:`castle-menu-error`,children:u}):null]})}function KY(e){return e instanceof Error?e.message:String(e)}function qY(e){return e.replace(/[\\/]+/g,`-`).replace(/^\.+/,``).trim()||`upload`}function JY(e){let t=e.value.lastIndexOf(`.`);t>0?e.setSelectionRange(0,t):e.select()}function YY(e){let{item:t,editing:n,busy:r}=e,[i,a]=g.useState(t.name),o=g.useRef(null),s=g.useRef(!1),c=P(t.name);g.useEffect(()=>{if(!n)return;s.current=!1,a(t.name);let e=o.current;e&&(e.focus(),JY(e))},[n,t.name]);let l=()=>{let n=i.trim()?qY(i):t.name;e.onCommit(n)};return(0,G.jsxs)(`div`,{className:ux(`castle-upload-picked-row`,n&&`is-editing`),children:[(0,G.jsxs)(`span`,{className:`castle-upload-picked-name`,children:[n?(0,G.jsx)(`input`,{ref:o,className:`castle-text-field`,type:`text`,value:i,autoComplete:`off`,spellCheck:!1,disabled:r,"aria-label":`Rename file`,onChange:e=>a(e.target.value),onKeyDown:t=>{t.key===`Enter`?(t.preventDefault(),l()):t.key===`Escape`&&(t.preventDefault(),s.current=!0,e.onCancelEdit())},onBlur:()=>{s.current||l()}}):(0,G.jsx)(`span`,{className:`castle-upload-picked-label`,children:t.name}),c?(0,G.jsx)(`span`,{className:`castle-upload-picked-warning`,children:c}):null]}),(0,G.jsx)(`span`,{className:`castle-upload-picked-size`,children:CF(t.file.size)}),n?null:(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon castle-button-quiet`,"aria-label":`Rename ${t.name}`,disabled:r,onClick:e.onStartEdit,children:(0,G.jsx)(K,{name:`pen`})}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon castle-button-quiet`,"aria-label":`Remove ${t.name}`,disabled:r,onClick:e.onRemove,children:(0,G.jsx)(K,{name:`times`})})]})}function XY(e){let[t,n]=g.useState([]),[r,i]=g.useState(null),[a,o]=g.useState(e.dir),[s,c]=g.useState(!1),[l,u]=g.useState(null),[d,f]=g.useState(null),p=g.useRef(null),m=g.useRef(1),h=l!==null,_=e=>{let t=Array.from(e??[]);t.length>0&&(f(null),n(e=>[...e,...t.map(e=>({id:m.current++,file:e,name:qY(e.name)}))]))},v=async()=>{let r=new Set(e.existingFiles),i=[],o=[];for(let[e,n]of t.entries()){u(t.length>1?`Uploading ${e+1} of ${t.length}…`:`Uploading…`);let s=et(Qe(a,n.name),r);r.add(s);try{await He(s,n.file),i.push(s)}catch(e){o.push(KY(e))}}if(u(null),o.length>0){n([]),f(o.join(` · `)),e.onUploaded(i);return}e.onUploaded(i),e.onClose()};return(0,gb.createPortal)((0,G.jsx)(`div`,{className:`castle-modal-scrim`,onClick:h?void 0:e.onClose,children:(0,G.jsxs)(`div`,{className:`castle-modal castle-upload-modal`,role:`dialog`,"aria-label":`Upload files`,onClick:e=>e.stopPropagation(),children:[(0,G.jsx)(`div`,{className:`castle-modal-text`,children:`Upload files`}),(0,G.jsx)(`input`,{ref:p,type:`file`,multiple:!0,className:`castle-upload-input`,onChange:e=>{_(e.currentTarget.files),e.currentTarget.value=``}}),(0,G.jsxs)(`button`,{type:`button`,className:ux(`castle-upload-drop`,s&&`over`),onClick:()=>p.current?.click(),onDragOver:e=>{e.preventDefault(),c(!0)},onDragLeave:()=>c(!1),onDrop:e=>{e.preventDefault(),c(!1),_(e.dataTransfer.files)},children:[(0,G.jsx)(K,{name:`upload`}),(0,G.jsx)(`span`,{className:`castle-upload-drop-label`,children:t.length===0?`Choose files`:`Add more files`}),(0,G.jsx)(`span`,{className:`castle-upload-drop-hint`,children:`or drop them here`})]}),t.length>0?(0,G.jsx)(`div`,{className:`castle-upload-picked`,children:t.map(e=>(0,G.jsx)(YY,{item:e,editing:r===e.id,busy:h,onStartEdit:()=>i(e.id),onCommit:t=>{n(n=>n.map(n=>n.id===e.id?{...n,name:t}:n)),i(null)},onCancelEdit:()=>i(null),onRemove:()=>{i(t=>t===e.id?null:t),n(t=>t.filter(t=>t.id!==e.id))}},e.id))}):null,(0,G.jsx)(GY,{folders:e.folders,existingFiles:e.existingFiles,selected:a,label:`Upload to`,disabled:h,onChoose:o}),d?(0,G.jsx)(`div`,{className:`castle-import-error`,role:`alert`,children:d}):null,(0,G.jsxs)(`div`,{className:`castle-modal-actions`,children:[(0,G.jsx)(`span`,{className:`castle-upload-status`,children:l}),(0,G.jsx)(`button`,{type:`button`,onClick:e.onClose,disabled:h,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,onClick:()=>void v(),disabled:h||t.length===0,children:t.length>1?`Upload ${t.length} files`:`Upload`})]})]})}),document.body)}var ZY=`preview.png`,QY=400,$Y=5e3,eX=3e4,tX=16*6e4;function nX(){let[e,t]=g.useState(null),[n,r]=g.useState([]),[i,a]=g.useState(!1),[o,s]=g.useState(!1),[c,l]=g.useState(``),[u,d]=g.useState(null),[f,p]=g.useState(!1),[m,h]=g.useState(!1),[_,v]=g.useState(null),[y,b]=g.useState(null),x=g.useRef(``),S=g.useRef(null),C=g.useCallback(()=>{S.current&&clearTimeout(S.current),S.current=null},[]),w=g.useCallback(e=>{let n=JSON.stringify(e);n!==x.current&&(x.current=n,t(e.versions),r(e.pending),a(e.git),s(e.loading===!0))},[]),T=g.useRef(0),E=g.useCallback(async()=>{let e=++T.current;try{let t=await De();return e===T.current?t:null}catch(t){if(e!==T.current)return null;throw t}},[]),D=g.useCallback(async()=>{try{let e=await E();e&&w(e)}catch(e){v(e instanceof Error?e.message:String(e))}},[w,E]);g.useEffect(()=>{D();let e=()=>{C(),S.current=setTimeout(()=>void D(),QY)},t=oS(t=>{t.changes.every(e=>e.path===ZY)||e()}),n=cS(`git_head_changed`,e);return()=>{C(),t(),n()}},[D,C]),g.useEffect(()=>{if(!o)return;let e=!1,t=$Y,n=Date.now()+tX,r=null,i=async()=>{document.hidden||await D(),!(e||Date.now()>=n)&&(t=Math.min(t*2,eX),r=setTimeout(()=>void i(),t))};r=setTimeout(()=>void i(),t);let a=()=>{document.hidden||D()};return document.addEventListener(`visibilitychange`,a),()=>{e=!0,r&&clearTimeout(r),document.removeEventListener(`visibilitychange`,a)}},[o,D]);let O=g.useCallback(async(e,t={})=>{C(),h(!0),v(null),b(null);let n=null,r=null;try{n=await e()}catch(e){r=e instanceof Error?e.message:String(e)}let i=null;try{i=await E()}catch(e){r??=e instanceof Error?e.message:String(e)}C(),h(!1),r&&v(r),n&&b(n),t.clearMessage&&!r&&l(``),i&&w(i)},[w,C,E]),k=!m&&c.trim().length>0,A=g.useCallback(()=>{if(!k)return;let e=c.trim();O(async()=>await Oe(e)?null:`Nothing had changed, so no version was saved.`,{clearMessage:!0})},[k,c,O]),j=g.useCallback(e=>{O(async()=>(await ke(e)).alreadyThere?`Already at that version.`:null)},[O]);return(0,G.jsxs)(`div`,{className:`castle-versions`,children:[_?(0,G.jsx)($K,{className:`versions-error`,onDismiss:()=>v(null),children:_}):null,n.length>0?(0,G.jsxs)(`article`,{className:ux(`version`,`version-new`,f&&`is-expanded`),children:[(0,G.jsxs)(`button`,{type:`button`,className:`version-toggle`,"aria-expanded":f,onClick:()=>p(e=>!e),children:[(0,G.jsx)(`span`,{className:`castle-icon-cell`,"aria-hidden":`true`,children:(0,G.jsx)(K,{name:`plus`})}),(0,G.jsxs)(`div`,{className:`version-main`,children:[(0,G.jsx)(`div`,{className:`version-heading`,children:(0,G.jsx)(`span`,{className:`version-message`,children:`New version`})}),(0,G.jsxs)(`span`,{className:`version-meta`,children:[n.length,` file`,n.length===1?``:`s`]})]})]}),(0,G.jsxs)(`div`,{className:`version-detail`,children:[(0,G.jsxs)(`div`,{className:`versions-save`,children:[(0,G.jsx)(`input`,{className:`castle-text-field`,type:`text`,value:c,placeholder:`Describe changes to save`,disabled:m,onChange:e=>l(e.target.value),onKeyDown:e=>{e.key===`Enter`&&A()}}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,disabled:!k,onClick:A,children:`Save`})]}),(0,G.jsx)(`p`,{className:`version-summary`,children:sX(n)})]})]}):null,y?(0,G.jsx)(`div`,{className:`versions-note`,children:y}):null,(0,G.jsx)(rX,{versions:e,git:i,historyLoading:o,expanded:u,busy:m,onToggle:e=>d(t=>t===e?null:e),onRestore:j})]})}function rX(e){let{versions:t}=e;if(t===null)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`Loading…`});if(t.length===0&&e.git&&e.historyLoading)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`History is loading… This deck’s saved versions come back in a moment.`});if(t.length===0&&e.git)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`No commits yet. The first save starts this deck’s history.`});if(t.length===0)return(0,G.jsx)(`div`,{className:`versions-empty`,children:`No versions yet. This deck’s history starts at your first save — there is no earlier state to go back to.`});let n=t.findIndex(e=>!e.later);return(0,G.jsx)(`div`,{className:`castle-versions-list`,children:t.map((r,i)=>(0,G.jsx)(cX,{version:r,olderHeading:r.older===!0&&t[i-1]?.older!==!0,showCurrent:i===n&&n>0,expanded:e.expanded===r.id,busy:e.busy,onToggle:()=>e.onToggle(r.id),onRestore:()=>e.onRestore(r.id)},r.id))})}var iX=4,aX=[{label:`Added`,kind:`added`},{label:`Deleted`,kind:`deleted`},{label:`Edited`,kind:`changed`}];function oX(e,t){let n=!e.includes(`/`);return n===!t.includes(`/`)?e.localeCompare(t):n?1:-1}function sX(e){let t=[];for(let n of aX){let r=e.filter(e=>e.kind===n.kind).map(e=>e.path).sort(oX);if(r.length===0)continue;let i=r.slice(0,iX).join(`, `);t.push(`${n.label} ${i}${r.length>iX?`, …`:``}.`)}return t.join(` `)}function cX(e){let{version:t}=e,n=t.changes.length,r=t.agent?` · by the agent`:t.author?` · ${t.author}`:``;return(0,G.jsxs)(G.Fragment,{children:[e.olderHeading?(0,G.jsx)(`div`,{className:`versions-note`,children:`Older versions, from before this deck used git`}):null,(0,G.jsxs)(`article`,{className:ux(`version`,e.expanded&&`is-expanded`,(t.later||t.older)&&`later`),children:[(0,G.jsxs)(`button`,{type:`button`,className:`version-toggle`,"aria-expanded":e.expanded,onClick:e.onToggle,children:[(0,G.jsx)(`span`,{className:`castle-icon-cell`,"aria-hidden":`true`,children:(0,G.jsx)(K,{name:e.expanded?`chevron-down`:`chevron-right`})}),(0,G.jsxs)(`div`,{className:`version-main`,children:[(0,G.jsx)(`div`,{className:`version-heading`,children:(0,G.jsx)(`span`,{className:`version-message`,children:t.message||(0,G.jsx)(`span`,{className:`version-nomessage`,children:`No message`})})}),(0,G.jsxs)(`span`,{className:`version-meta`,children:[SF(t.createdAt),` · `,n,` file`,n===1?``:`s`,e.showCurrent?` · current`:``,t.later?` · later`:``,r]})]})]}),t.older?null:(0,G.jsx)(`div`,{className:`version-actions`,children:(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,disabled:e.busy,onClick:e.onRestore,children:`Restore`})}),(0,G.jsx)(`div`,{className:`version-detail`,children:(0,G.jsx)(`p`,{className:`version-summary`,children:sX(t.changes)})})]})]})}var lX={label:`New file`,icon:`file-code`,ext:``};function uX(){let e=fe();return e?[lX,...e.filter(e=>typeof e.new==`string`&&e.new).map(e=>({label:e.new,icon:e.icon??`file`,ext:e.ext}))]:[lX]}function dX(e){let{showHidden:t,hidesFiles:n,showVersions:r}=e;return(0,G.jsxs)(`div`,{className:ux(`castle-file-toolbar`,r&&`versions-toolbar`),children:[r?(0,G.jsx)(`span`,{className:`versions-toolbar-label castle-text-style-smallcaps`,children:`Versions`}):v?null:(0,G.jsxs)(G.Fragment,{children:[(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onNew,title:`New file`,children:[(0,G.jsx)(K,{name:`plus`}),(0,G.jsx)(`span`,{children:`New`})]}),(0,G.jsxs)(`button`,{type:`button`,className:`castle-button`,onClick:e.onImport,title:`Import another deck`,children:[(0,G.jsx)(K,{name:`plus`}),(0,G.jsx)(`span`,{children:`Import`})]}),n?(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon`,onClick:e.onToggleHidden,"aria-pressed":t,title:t?`Hide hidden files & folders`:`Show hidden files & folders`,children:(0,G.jsx)(K,{name:`eye`})}):null]}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-icon`,onClick:e.onToggleVersions,"aria-pressed":r,title:r?`Back to files`:`Version history`,"aria-label":r?`Back to files`:`Version history`,children:(0,G.jsx)(K,{name:`history`})})]})}function fX(e){let t=YS(),[n,r]=g.useState(null),[i,a]=g.useState(null),[o,s]=g.useState(``),[c,l]=g.useState(!1),[u,d]=g.useState(le),[f,p]=g.useState(!1),[m,h]=g.useState(new Set),[_,v]=g.useState(new Set),[y,b]=g.useState(null),[x,S]=g.useState(!1),[C,w]=g.useState(null),T=g.useRef([]);T.current=n??[];let E=g.useRef(!1);E.current=c;let D=g.useCallback(()=>{je(E.current).then(e=>{r(e),a(null)}).catch(e=>a(e instanceof Error?e.message:String(e))),Te().then(e=>h(new Set(e.filter(e=>e.updateAvailable).map(e=>e.alias)))),Le().then(e=>v(new Set(e.map(e=>e.path))))},[]),O=g.useCallback(()=>{S(!1),w(null)},[]),[k,A]=g.useState(null),j=g.useCallback(()=>{E.current=!E.current,l(E.current),D()},[D]),{lifecycle:ee}=e;g.useEffect(()=>{D();let e=ee.onDidVisibilityChange(e=>{e&&D()}),t=ce(()=>{let e=le();d(e),e||(E.current=!1,l(!1)),D()}),n=oS(e=>{e.changes.some(e=>e.event!==`change`||e.forkChanged)&&D()});return()=>{e(),t(),n()}},[D,ee]),g.useEffect(()=>{s(t.activeEditorPath??``)},[t.activeEditorPath]);let M=g.useCallback(e=>{s(e),t.openFile(e)},[t]),N=mX({closeEditor:e=>t.closeEditor(e),refresh:D,onOpen:M,filesRef:T,selected:o,clearSelected:()=>s(``)}),te=g.useMemo(()=>Object.fromEntries((n??[]).map(e=>[e,``])),[n]),ne=g.useMemo(()=>_X(n??[]),[n]);return(0,G.jsxs)(`div`,{className:`castle-file-panel`,children:[(0,G.jsx)(dX,{showHidden:c,hidesFiles:u,showVersions:f,onNew:N.openNewMenu,onImport:()=>S(!0),onToggleHidden:j,onToggleVersions:()=>p(e=>!e)}),N.actionError?(0,G.jsx)($K,{onDismiss:()=>N.setActionError(null),children:N.actionError}):null,f?(0,G.jsx)(nX,{}):i?(0,G.jsxs)($K,{children:[`Could not list files: `,i]}):(0,G.jsx)(PT,{files:te,selectedPath:o,onSelect:M,onContextMenu:N.onContextMenu,edit:N.edit,outdatedImports:m,forkedPaths:_,onUpdateImport:e=>{w(e),S(!0)}}),N.menu?(0,G.jsx)(hX,{menu:N.menu,folders:ne,showHidden:c,hidesFiles:u,forkedPaths:_,onClose:N.closeMenu,onOpenIn:(e,n)=>{s(e),t.openFile(e,n),N.closeMenu()},onShowParams:e=>{t.openParams(e),N.closeMenu()},onCreate:N.startCreate,onMove:N.moveTo,onRename:N.startRename,onDuplicate:N.duplicate,onFork:N.fork,onDropFork:e=>{N.closeMenu(),b(e)},onConfirmDelete:N.confirmDelete,existingFiles:n??[],onUpload:e=>{N.closeMenu(),A(e)},onToggleHidden:j}):null,y?(0,G.jsx)(yC,{path:y,onClose:()=>b(null),onReverted:()=>{b(null),D()}}):null,k===null?null:(0,G.jsx)(XY,{dir:k,folders:ne,existingFiles:n??[],onClose:()=>A(null),onUploaded:e=>{D(),e.length>0&&M(e[0])}}),x?(0,G.jsx)(OY,{initialUpdateAlias:C,onClose:O,onImported:()=>{O(),D(),pX()},onUpdated:()=>{O(),D()}}):null]})}function pX(){for(let e of Array.from(document.querySelectorAll(`iframe.deck-frame`))){let t=e;try{t.contentWindow?.location.reload()}catch{t.src=t.src}}}function mX(e){let{closeEditor:t,refresh:n,onOpen:r,filesRef:i,selected:a,clearSelected:o}=e,[s,c]=g.useState(null),[l,u]=g.useState(null),[d,f]=g.useState(null),p=g.useCallback((e,t,a)=>{let o=a.trim();if(!o)return u(null);let s=t&&!o.endsWith(t)?`${o}${t}`:o,c=Qe(e,s);if(i.current.includes(c))return u(e=>e&&{...e,error:`“${s}” already exists`});Ie(c,Ke(c)).then(()=>{u(null),n(),r(c)}).catch(e=>u(t=>t&&{...t,error:gX(e)}))},[n,r,i]),m=g.useCallback((e,a)=>{let o=a.trim();if(!o||o===Xe(e))return u(null);let s=Qe(Ze(e),o);if(s.toLowerCase()!==e.toLowerCase()&&i.current.includes(s))return u(e=>e&&{...e,error:`“${o}” already exists`});Ue(e,s).then(()=>{u(null),n(),t(e),r(s)}).catch(e=>u(t=>t&&{...t,error:gX(e)}))},[n,r,i,t]),h=g.useCallback((e,t)=>{f(null),c(null),u({mode:`create`,dir:t,suffix:e.ext,error:null,onCommit:n=>p(t,e.ext,n),onCancel:()=>u(null)})},[p]),_=g.useCallback(e=>{f(null),c(null),u({mode:`rename`,dir:Ze(e),path:e,suffix:``,error:null,onCommit:t=>m(e,t),onCancel:()=>u(null)})},[m]),v=g.useCallback(e=>{f(null),c(null);let t=vX(e,i.current);Pe(e,t).then(()=>{n(),r(t)}).catch(e=>c(gX(e)))},[n,r,i]),y=g.useCallback(e=>{f(null),c(null),Re(e).then(()=>{n(),r(e)}).catch(e=>c(gX(e)))},[n,r]),b=g.useCallback((e,a)=>{f(null),c(null);let o=Qe(a,Xe(e));if(o!==e){if(i.current.includes(o))return c(`“${Xe(e)}” already exists in ${a||`root`}`);Ue(e,o).then(()=>{n(),t(e),r(o)}).catch(e=>c(gX(e)))}},[n,r,i,t]),x=g.useCallback(e=>{c(null),We(e).then(()=>{f(null),n(),t(e),a===e&&o()}).catch(e=>{f(null),c(gX(e))})},[n,a,t,o]),S=g.useCallback((e,t)=>{e.preventDefault(),u(null),f({x:e.clientX,y:e.clientY,target:t,fromToolbar:!1})},[]),C=g.useCallback(e=>{let t=e.currentTarget.getBoundingClientRect();u(null),f({x:t.left,y:t.bottom+4,target:{type:`root`,path:``},fromToolbar:!0})},[]);return{edit:l,menu:d,actionError:s,setActionError:c,closeMenu:g.useCallback(()=>f(null),[]),startCreate:h,startRename:_,duplicate:v,fork:y,moveTo:b,confirmDelete:x,onContextMenu:S,openNewMenu:C}}function hX(e){let{menu:t,folders:n,showHidden:r,hidesFiles:i,onClose:a}=e,o=g.useRef(null),[s,c]=g.useState(`default`),l=g.useRef(null);Xw(o,a);let u=Qw(o,t,[s]),d=t.target.type===`file`&&Ce(t.target.path)?t.target.path:null,[f,p]=g.useState(null);g.useEffect(()=>{if(d===null)return;let e=!0;return p(null),Le(d).then(t=>{e&&p(t.find(e=>e.path===d)??null)}),()=>{e=!1}},[d]);let m=t=>{let n=l.current;n?.action===`create`?e.onCreate(n.type,t):n?.action===`move`&&e.onMove(n.file,t),a()},h=()=>e.onUpload(t.target.type===`directory`?t.target.path:``),_=n=>{t.target.type===`directory`?(e.onCreate(n,t.target.path),a()):(l.current={action:`create`,type:n},c(`pickFolder`))},v;if(s===`pickFolder`){let t=l.current;v=(0,G.jsx)(GY,{folders:n,existingFiles:e.existingFiles,header:t?.action===`move`?`Move \u201c${Xe(t.file)}\u201d to\u2026`:`Create new file in…`,onChoose:m})}else if(t.target.type===`file`){let n=t.target.path,r=ve(n),i=r.length>=2||KS(n)?(0,G.jsxs)(G.Fragment,{children:[r.length>=2&&r.map(t=>(0,G.jsx)(WY,{icon:t.icon,label:`Open in ${t.label} editor`,onClick:()=>e.onOpenIn(n,t.classId)},t.classId)),KS(n)&&(0,G.jsx)(WY,{icon:`sliders`,label:`Show parameters`,onClick:()=>e.onShowParams(n)})]}):null;v=s===`confirmDelete`?(0,G.jsxs)(`div`,{className:`castle-menu-confirm`,children:[(0,G.jsxs)(`div`,{className:`castle-menu-confirm-text`,children:[`Delete “`,Xe(n),`”?`]}),(0,G.jsxs)(`div`,{className:`castle-menu-confirm-actions`,children:[(0,G.jsx)(`button`,{type:`button`,className:`castle-button`,onClick:a,children:`Cancel`}),(0,G.jsx)(`button`,{type:`button`,className:`castle-button castle-button-danger`,onClick:()=>e.onConfirmDelete(n),children:`Delete`})]})]}):Ce(n)?(0,G.jsxs)(G.Fragment,{children:[i,i?(0,G.jsx)(`div`,{className:`castle-menu-separator`}):null,e.forkedPaths.has(n)?(0,G.jsx)(WY,{icon:`code-fork`,label:`Drop fork`,onClick:()=>e.onDropFork(n)}):(0,G.jsx)(WY,{icon:`code-fork`,label:`Fork`,disabled:f!==null&&!f.forkable,onClick:()=>e.onFork(n)})]}):(0,G.jsxs)(G.Fragment,{children:[i,i?(0,G.jsx)(`div`,{className:`castle-menu-separator`}):null,(0,G.jsx)(WY,{icon:`clone`,label:`Duplicate`,onClick:()=>e.onDuplicate(n)}),(0,G.jsx)(WY,{icon:`pen`,label:`Rename`,onClick:()=>e.onRename(n)}),(0,G.jsx)(WY,{icon:`arrow-right`,label:`Move to…`,onClick:()=>{l.current={action:`move`,file:n},c(`pickFolder`)}}),(0,G.jsx)(WY,{icon:`trash`,label:`Delete`,danger:!0,onClick:()=>c(`confirmDelete`)})]})}else v=(0,G.jsxs)(G.Fragment,{children:[uX().map(e=>(0,G.jsx)(WY,{icon:e.icon,label:e.label,onClick:()=>_(e)},e.label)),(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`upload`,label:`Upload files…`,onClick:h}),t.target.type===`root`&&!t.fromToolbar&&i?(0,G.jsxs)(G.Fragment,{children:[(0,G.jsx)(`div`,{className:`castle-menu-separator`}),(0,G.jsx)(WY,{icon:`eye`,label:`Show hidden files & folders`,checked:r,onClick:()=>{e.onToggleHidden(),a()}})]}):null]});return(0,gb.createPortal)((0,G.jsx)(`div`,{ref:o,className:`castle-menu castle-file-menu`,role:`menu`,style:u,children:v}),document.body)}function gX(e){return e instanceof Error?e.message:String(e)}function _X(e){let t=new Set;for(let n of e){if(Ce(n))continue;let e=n.split(`/`);for(let n=1;n<e.length;n++)t.add(e.slice(0,n).join(`/`))}return[...t].sort()}function vX(e,t){let{stem:n,ext:r}=$e(Xe(e)),i=Ze(e),a=new Set(t);for(let e=1;;e++){let t=Qe(i,`${n} ${e===1?`copy`:`copy ${e}`}${r}`);if(!a.has(t))return t}}var yX=null,bX=new Set;function xX(e){if(bX.size>0){for(let t of[...bX])t(e);return}yX=e}function SX(){let e=yX;return yX=null,e}function CX(e){return bX.add(e),()=>{bX.delete(e)}}function wX(){return{async:!1,breaks:!1,extensions:null,gfm:!0,hooks:null,pedantic:!1,renderer:null,silent:!1,tokenizer:null,walkTokens:null}}var TX=wX();function EX(e){TX=e}var DX={exec:()=>null};function OX(e){let t=[];return n=>{let r=Math.max(0,Math.min(3,n-1)),i=t[r];return i||(i=e(r),t[r]=i),i}}function kX(e,t=``){let n=typeof e==`string`?e:e.source,r={replace:(e,t)=>{let i=typeof t==`string`?t:t.source;return i=i.replace(jX.caret,`$1`),n=n.replace(e,i),r},getRegex:()=>new RegExp(n,t)};return r}var AX=((e=``)=>{try{return!!RegExp(`(?<=1)(?<!1)`+e)}catch{return!1}})(),jX={codeRemoveIndent:/^(?: {1,4}| {0,3}\t)/gm,outputLinkReplace:/\\([\[\]])/g,indentCodeCompensation:/^(\s+)(?:```)/,beginningSpace:/^\s+/,endingHash:/#$/,startingSpaceChar:/^ /,endingSpaceChar:/ $/,nonSpaceChar:/[^ ]/,newLineCharGlobal:/\n/g,tabCharGlobal:/\t/g,multipleSpaceGlobal:/\s+/g,blankLine:/^[ \t]*$/,doubleBlankLine:/\n[ \t]*\n[ \t]*$/,blockquoteStart:/^ {0,3}>/,blockquoteSetextReplace:/\n {0,3}((?:=+|-+) *)(?=\n|$)/g,blockquoteSetextReplace2:/^ {0,3}>[ \t]?/gm,listReplaceNesting:/^ {1,4}(?=( {4})*[^ ])/g,listIsTask:/^\[[ xX]\] +\S/,listReplaceTask:/^\[[ xX]\] +/,listTaskCheckbox:/\[[ xX]\]/,anyLine:/\n.*\n/,hrefBrackets:/^<(.*)>$/,tableDelimiter:/[:|]/,tableAlignChars:/^\||\| *$/g,tableRowBlankLine:/\n[ \t]*$/,tableAlignRight:/^ *-+: *$/,tableAlignCenter:/^ *:-+: *$/,tableAlignLeft:/^ *:-+ *$/,startATag:/^<a /i,endATag:/^<\/a>/i,startPreScriptTag:/^<(pre|code|kbd|script)(\s|>)/i,endPreScriptTag:/^<\/(pre|code|kbd|script)(\s|>)/i,startAngleBracket:/^</,endAngleBracket:/>$/,pedanticHrefTitle:/^([^'"]*[^\s])\s+(['"])(.*)\2/,unicodeAlphaNumeric:/[\p{L}\p{N}]/u,escapeTest:/[&<>"']/,escapeReplace:/[&<>"']/g,escapeTestNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/,escapeReplaceNoEncode:/[<>"']|&(?!(#\d{1,7}|#[Xx][a-fA-F0-9]{1,6}|\w+);)/g,caret:/(^|[^\[])\^/g,percentDecode:/%25/g,findPipe:/\|/g,splitPipe:/ \|/,slashPipe:/\\\|/g,carriageReturn:/\r\n|\r/g,spaceLine:/^ +$/gm,notSpaceStart:/^\S*/,endingNewline:/\n$/,listItemRegex:e=>RegExp(`^( {0,3}${e})((?:[ ][^\\n]*)?(?:\\n|$))`),nextBulletRegex:OX(e=>RegExp(`^ {0,${e}}(?:[*+-]|\\d{1,9}[.)])((?:[ ][^\\n]*)?(?:\\n|$))`)),hrRegex:OX(e=>RegExp(`^ {0,${e}}((?:- *){3,}|(?:_ *){3,}|(?:\\* *){3,})(?:\\n+|$)`)),fencesBeginRegex:OX(e=>RegExp(`^ {0,${e}}(?:\`\`\`|~~~)`)),headingBeginRegex:OX(e=>RegExp(`^ {0,${e}}#`)),htmlBeginRegex:OX(e=>RegExp(`^ {0,${e}}<(?:[a-z].*>|!--)`,`i`)),blockquoteBeginRegex:OX(e=>RegExp(`^ {0,${e}}>`))},MX=/^(?:[ \t]*(?:\n|$))+/,NX=/^((?: {4}| {0,3}\t)[^\n]+(?:\n(?:[ \t]*(?:\n|$))*)?)+/,PX=/^ {0,3}(`{3,}(?=[^`\n]*(?:\n|$))|~{3,})([^\n]*)(?:\n|$)(?:|([\s\S]*?)(?:\n|$))(?: {0,3}\1[~`]* *(?=\n|$)|$)/,FX=/^ {0,3}((?:-[\t ]*){3,}|(?:_[ \t]*){3,}|(?:\*[ \t]*){3,})(?:\n+|$)/,IX=/^ {0,3}(#{1,6})(?=\s|$)(.*)(?:\n+|$)/,LX=/ {0,3}(?:[*+-]|\d{1,9}[.)])/,RX=/^(?!bull |blockCode|fences|blockquote|heading|html|table)((?:.|\n(?!\s*?\n|bull |blockCode|fences|blockquote|heading|html|table))+?)\n {0,3}(=+|-+) *(?:\n+|$)/,zX=kX(RX).replace(/bull/g,LX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/\|table/g,``).getRegex(),BX=kX(RX).replace(/bull/g,LX).replace(/blockCode/g,/(?: {4}| {0,3}\t)/).replace(/fences/g,/ {0,3}(?:`{3,}|~{3,})/).replace(/blockquote/g,/ {0,3}>/).replace(/heading/g,/ {0,3}#{1,6}/).replace(/html/g,/ {0,3}<[^\n>]+>\n/).replace(/table/g,/ {0,3}\|?(?:[:\- ]*\|)+[\:\- ]*\n/).getRegex(),VX=/^([^\n]+(?:\n(?!hr|heading|lheading|blockquote|fences|list|html|table| +\n)[^\n]+)*)/,HX=/^[^\n]+/,UX=/(?!\s*\])(?:\\[\s\S]|[^\[\]\\])+/,WX=kX(/^ {0,3}\[(label)\]: *(?:\n[ \t]*)?([^<\s][^\s]*|<.*?>)(?:(?: +(?:\n[ \t]*)?| *\n[ \t]*)(title))? *(?:\n+|$)/).replace(`label`,UX).replace(`title`,/(?:"(?:\\"?|[^"\\])*"|'[^'\n]*(?:\n[^'\n]+)*\n?'|\([^()]*\))/).getRegex(),GX=kX(/^(bull)([ \t][^\n]*?)?(?:\n|$)/).replace(/bull/g,LX).getRegex(),KX=`address|article|aside|base|basefont|blockquote|body|caption|center|col|colgroup|dd|details|dialog|dir|div|dl|dt|fieldset|figcaption|figure|footer|form|frame|frameset|h[1-6]|head|header|hr|html|iframe|legend|li|link|main|menu|menuitem|meta|nav|noframes|ol|optgroup|option|p|param|search|section|summary|table|tbody|td|tfoot|th|thead|title|tr|track|ul`,qX=/<!--(?:-?>|[\s\S]*?(?:-->|$))/,JX=kX(`^ {0,3}(?:<(script|pre|style|textarea)[\\s>][\\s\\S]*?(?:</\\1>[^\\n]*\\n+|$)|comment[^\\n]*(\\n+|$)|<\\?[\\s\\S]*?(?:\\?>\\n*|$)|<![A-Z][\\s\\S]*?(?:>\\n*|$)|<!\\[CDATA\\[[\\s\\S]*?(?:\\]\\]>\\n*|$)|</?(tag)(?: +|\\n|/?>)[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|<(?!script|pre|style|textarea)([a-z][\\w-]*)(?:attribute)*? */?>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$)|</(?!script|pre|style|textarea)[a-z][\\w-]*\\s*>(?=[ \\t]*(?:\\n|$))[\\s\\S]*?(?:(?:\\n[ ]*)+\\n|$))`,`i`).replace(`comment`,qX).replace(`tag`,KX).replace(`attribute`,/ +[a-zA-Z:_][\w.:-]*(?: *= *"[^"\n]*"| *= *'[^'\n]*'| *= *[^\s"'=<>`]+)?/).getRegex(),YX=kX(VX).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex(),XX={blockquote:kX(/^( {0,3}> ?(paragraph|[^\n]*)(?:\n|$))+/).replace(`paragraph`,YX).getRegex(),code:NX,def:WX,fences:PX,heading:IX,hr:FX,html:JX,lheading:zX,list:GX,newline:MX,paragraph:YX,table:DX,text:HX},ZX=kX(`^ *([^\\n ].*)\\n {0,3}((?:\\| *)?:?-+:? *(?:\\| *:?-+:? *)*(?:\\| *)?)(?:\\n((?:(?! *\\n|hr|heading|blockquote|code|fences|list|html).*(?:\\n|$))*)\\n*|$)`).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`blockquote`,` {0,3}>`).replace(`code`,`(?: {4}| {0,3} )[^\\n]`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex(),QX={...XX,lheading:BX,table:ZX,paragraph:kX(VX).replace(`hr`,FX).replace(`heading`,` {0,3}#{1,6}(?:\\s|$)`).replace(`|lheading`,``).replace(`table`,ZX).replace(`blockquote`,` {0,3}>`).replace(`fences`," {0,3}(?:`{3,}(?=[^`\\n]*\\n)|~{3,})[^\\n]*\\n").replace(`list`,` {0,3}(?:[*+-]|1[.)])[ \\t]+[^ \\t\\n]`).replace(`html`,`</?(?:tag)(?: +|\\n|/?>)|<(?:script|pre|style|textarea|!--)`).replace(`tag`,KX).getRegex()},$X={...XX,html:kX(`^ *(?:comment *(?:\\n|\\s*$)|<(tag)[\\s\\S]+?</\\1> *(?:\\n{2,}|\\s*$)|<tag(?:"[^"]*"|'[^']*'|\\s[^'"/>\\s]*)*?/?> *(?:\\n{2,}|\\s*$))`).replace(`comment`,qX).replace(/tag/g,`(?!(?:a|em|strong|small|s|cite|q|dfn|abbr|data|time|code|var|samp|kbd|sub|sup|i|b|u|mark|ruby|rt|rp|bdi|bdo|span|br|wbr|ins|del|img)\\b)\\w+(?!:|[^\\w\\s@]*@)\\b`).getRegex(),def:/^ *\[([^\]]+)\]: *<?([^\s>]+)>?(?: +(["(][^\n]+[")]))? *(?:\n+|$)/,heading:/^(#{1,6})(.*)(?:\n+|$)/,fences:DX,lheading:/^(.+?)\n {0,3}(=+|-+) *(?:\n+|$)/,paragraph:kX(VX).replace(`hr`,FX).replace(`heading`,` *#{1,6} *[^
|
|
385
385
|
]`).replace(`lheading`,zX).replace(`|table`,``).replace(`blockquote`,` {0,3}>`).replace(`|fences`,``).replace(`|list`,``).replace(`|html`,``).replace(`|tag`,``).getRegex()},eZ=/^\\([!"#$%&'()*+,\-./:;<=>?@\[\]\\^_`{|}~])/,tZ=/^(`+)([^`]|[^`][\s\S]*?[^`])\1(?!`)/,nZ=/^( {2,}|\\)\n(?!\s*$)/,rZ=/^(`+|[^`])(?:(?= {2,}\n)|[\s\S]*?(?:(?=[\\<!\[`*_]|\b_|$)|[^ ](?= {2,}\n)))/,iZ=/[\p{P}\p{S}]/u,aZ=/[\s\p{P}\p{S}]/u,oZ=/[^\s\p{P}\p{S}]/u,sZ=kX(/^((?![*_])punctSpace)/,`u`).replace(/punctSpace/g,aZ).getRegex(),cZ=/(?!~)[\p{P}\p{S}]/u,lZ=/(?!~)[\s\p{P}\p{S}]/u,uZ=/(?:[^\s\p{P}\p{S}]|~)/u,dZ=kX(/link|precode-code|html/,`g`).replace(`link`,/\[(?:[^\[\]`]|(?<a>`+)[^`]+\k<a>(?!`))*?\]\((?:\\[\s\S]|[^\\\(\)]|\((?:\\[\s\S]|[^\\\(\)])*\))*\)/).replace(`precode-`,AX?"(?<!`)()":"(^^|[^`])").replace(`code`,/(?<b>`+)[^`]+\k<b>(?!`)/).replace(`html`,/<(?! )[^<>]*?>/).getRegex(),fZ=/^(?:\*+(?:((?!\*)punct)|([^\s*]))?)|^_+(?:((?!_)punct)|([^\s_]))?/,pZ=kX(fZ,`u`).replace(/punct/g,iZ).getRegex(),mZ=kX(fZ,`u`).replace(/punct/g,cZ).getRegex(),hZ=`^[^_*]*?__[^_*]*?\\*[^_*]*?(?=__)|[^*]+(?=[^*])|(?!\\*)punct(\\*+)(?=[\\s]|$)|notPunctSpace(\\*+)(?!\\*)(?=punctSpace|$)|(?!\\*)punctSpace(\\*+)(?=notPunctSpace)|[\\s](\\*+)(?!\\*)(?=punct)|(?!\\*)punct(\\*+)(?!\\*)(?=punct)|notPunctSpace(\\*+)(?=notPunctSpace)`,gZ=kX(hZ,`gu`).replace(/notPunctSpace/g,oZ).replace(/punctSpace/g,aZ).replace(/punct/g,iZ).getRegex(),_Z=kX(hZ,`gu`).replace(/notPunctSpace/g,uZ).replace(/punctSpace/g,lZ).replace(/punct/g,cZ).getRegex(),vZ=kX(`^[^_*]*?\\*\\*[^_*]*?_[^_*]*?(?=\\*\\*)|[^_]+(?=[^_])|(?!_)punct(_+)(?=[\\s]|$)|notPunctSpace(_+)(?!_)(?=punctSpace|$)|(?!_)punctSpace(_+)(?=notPunctSpace)|[\\s](_+)(?!_)(?=punct)|(?!_)punct(_+)(?!_)(?=punct)`,`gu`).replace(/notPunctSpace/g,oZ).replace(/punctSpace/g,aZ).replace(/punct/g,iZ).getRegex(),yZ=kX(/^~~?(?:((?!~)punct)|[^\s~])/,`u`).replace(/punct/g,iZ).getRegex(),bZ=kX(`^[^~]+(?=[^~])|(?!~)punct(~~?)(?=[\\s]|$)|notPunctSpace(~~?)(?!~)(?=punctSpace|$)|(?!~)punctSpace(~~?)(?=notPunctSpace)|[\\s](~~?)(?!~)(?=punct)|(?!~)punct(~~?)(?!~)(?=punct)|notPunctSpace(~~?)(?=notPunctSpace)`,`gu`).replace(/notPunctSpace/g,oZ).replace(/punctSpace/g,aZ).replace(/punct/g,iZ).getRegex(),xZ=kX(/\\(punct)/,`gu`).replace(/punct/g,iZ).getRegex(),SZ=kX(/^<(scheme:[^\s\x00-\x1f<>]*|email)>/).replace(`scheme`,/[a-zA-Z][a-zA-Z0-9+.-]{1,31}/).replace(`email`,/[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+(@)[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)+(?![-_])/).getRegex(),CZ=kX(qX).replace(`(?:-->|$)`,`-->`).getRegex(),wZ=kX(`^comment|^</[a-zA-Z][\\w:-]*\\s*>|^<[a-zA-Z][\\w-]*(?:attribute)*?\\s*/?>|^<\\?[\\s\\S]*?\\?>|^<![a-zA-Z]+\\s[\\s\\S]*?>|^<!\\[CDATA\\[[\\s\\S]*?\\]\\]>`).replace(`comment`,CZ).replace(`attribute`,/\s+[a-zA-Z:_][\w.:-]*(?:\s*=\s*"[^"]*"|\s*=\s*'[^']*'|\s*=\s*[^\s"'=<>`]+)?/).getRegex(),TZ=/(?:\[(?:\\[\s\S]|[^\[\]\\])*\]|\\[\s\S]|`+(?!`)[^`]*?`+(?!`)|``+(?=\])|[^\[\]\\`])*?/,EZ=kX(/^!?\[(label)\]\(\s*(href)(?:(?:[ \t]+(?:\n[ \t]*)?|\n[ \t]*)(title))?\s*\)/).replace(`label`,TZ).replace(`href`,/<(?:\\.|[^\n<>\\])+>|[^ \t\n\x00-\x1f]*/).replace(`title`,/"(?:\\"?|[^"\\])*"|'(?:\\'?|[^'\\])*'|\((?:\\\)?|[^)\\])*\)/).getRegex(),DZ=kX(/^!?\[(label)\]\[(ref)\]/).replace(`label`,TZ).replace(`ref`,UX).getRegex(),OZ=kX(/^!?\[(ref)\](?:\[\])?/).replace(`ref`,UX).getRegex(),kZ=kX(`reflink|nolink(?!\\()`,`g`).replace(`reflink`,DZ).replace(`nolink`,OZ).getRegex(),AZ=/[hH][tT][tT][pP][sS]?|[fF][tT][pP]/,jZ={_backpedal:DX,anyPunctuation:xZ,autolink:SZ,blockSkip:dZ,br:nZ,code:tZ,del:DX,delLDelim:DX,delRDelim:DX,emStrongLDelim:pZ,emStrongRDelimAst:gZ,emStrongRDelimUnd:vZ,escape:eZ,link:EZ,nolink:OZ,punctuation:sZ,reflink:DZ,reflinkSearch:kZ,tag:wZ,text:rZ,url:DX},MZ={...jZ,link:kX(/^!?\[(label)\]\((.*?)\)/).replace(`label`,TZ).getRegex(),reflink:kX(/^!?\[(label)\]\s*\[([^\]]*)\]/).replace(`label`,TZ).getRegex()},NZ={...jZ,emStrongRDelimAst:_Z,emStrongLDelim:mZ,delLDelim:yZ,delRDelim:bZ,url:kX(/^((?:protocol):\/\/|www\.)(?:[a-zA-Z0-9\-]+\.?)+[^\s<]*|^email/).replace(`protocol`,AZ).replace(`email`,/[A-Za-z0-9._+-]+(@)[a-zA-Z0-9-_]+(?:\.[a-zA-Z0-9-_]*[a-zA-Z0-9])+(?![-_])/).getRegex(),_backpedal:/(?:[^?!.,:;*_'"~()&]+|\([^)]*\)|&(?![a-zA-Z0-9]+;$)|[?!.,:;*_'"~)]+(?!$))+/,del:/^(~~?)(?=[^\s~])((?:\\[\s\S]|[^\\])*?(?:\\[\s\S]|[^\s~\\]))\1(?=[^~]|$)/,text:kX(/^([`~]+|[^`~])(?:(?= {2,}\n)|(?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)|[\s\S]*?(?:(?=[\\<!\[`*~_]|\b_|protocol:\/\/|www\.|$)|[^ ](?= {2,}\n)|[^a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-](?=[a-zA-Z0-9.!#$%&'*+\/=?_`{\|}~-]+@)))/).replace(`protocol`,AZ).getRegex()},PZ={...NZ,br:kX(nZ).replace(`{2,}`,`*`).getRegex(),text:kX(NZ.text).replace(`\\b_`,`\\b_| {2,}\\n`).replace(/\{2,\}/g,`*`).getRegex()},FZ={normal:XX,gfm:QX,pedantic:$X},IZ={normal:jZ,gfm:NZ,breaks:PZ,pedantic:MZ},LZ={"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`},RZ=e=>LZ[e];function zZ(e,t){if(t){if(jX.escapeTest.test(e))return e.replace(jX.escapeReplace,RZ)}else if(jX.escapeTestNoEncode.test(e))return e.replace(jX.escapeReplaceNoEncode,RZ);return e}function BZ(e){try{e=encodeURI(e).replace(jX.percentDecode,`%`)}catch{return null}return e}function VZ(e,t){let n=e.replace(jX.findPipe,(e,t,n)=>{let r=!1,i=t;for(;--i>=0&&n[i]===`\\`;)r=!r;return r?`|`:` |`}).split(jX.splitPipe),r=0;if(n[0].trim()||n.shift(),n.length>0&&!n.at(-1)?.trim()&&n.pop(),t)if(n.length>t)n.splice(t);else for(;n.length<t;)n.push(``);for(;r<n.length;r++)n[r]=n[r].trim().replace(jX.slashPipe,`|`);return n}function HZ(e,t,n){let r=e.length;if(r===0)return``;let i=0;for(;i<r;){let a=e.charAt(r-i-1);if(a===t&&!n)i++;else if(a!==t&&n)i++;else break}return e.slice(0,r-i)}function UZ(e){let t=e.split(`
|
|
386
386
|
`),n=t.length-1;for(;n>=0&&jX.blankLine.test(t[n]);)n--;return t.length-n<=2?e:t.slice(0,n+1).join(`
|
|
387
387
|
`)}function WZ(e,t){if(e.indexOf(t[1])===-1)return-1;let n=0;for(let r=0;r<e.length;r++)if(e[r]===`\\`)r++;else if(e[r]===t[0])n++;else if(e[r]===t[1]&&(n--,n<0))return r;return n>0?-2:-1}function GZ(e,t=0){let n=t,r=``;for(let t of e)if(t===` `){let e=4-n%4;r+=` `.repeat(e),n+=e}else r+=t,n++;return r}function KZ(e,t,n,r,i){let a=t.href,o=t.title||null,s=e[1].replace(i.other.outputLinkReplace,`$1`);r.state.inLink=!0;let c={type:e[0].charAt(0)===`!`?`image`:`link`,raw:n,href:a,title:o,text:s,tokens:r.inlineTokens(s)};return r.state.inLink=!1,c}function qZ(e,t,n){let r=e.match(n.other.indentCodeCompensation);if(r===null)return t;let i=r[1];return t.split(`
|
package/dist/shell/index.html
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
<link rel="icon" type="image/png" sizes="32x32" href="/__castle/ide/favicon-32x32.png" />
|
|
11
11
|
<link rel="icon" type="image/png" sizes="16x16" href="/__castle/ide/favicon-16x16.png" />
|
|
12
12
|
<link rel="icon" href="/__castle/ide/favicon.ico" sizes="any" />
|
|
13
|
-
<script type="module" crossorigin src="/__castle/ide/assets/index-
|
|
13
|
+
<script type="module" crossorigin src="/__castle/ide/assets/index-D9oRe6Yi.js"></script>
|
|
14
14
|
<link rel="stylesheet" crossorigin href="/__castle/ide/assets/index-BrKPEU3b.css">
|
|
15
15
|
</head>
|
|
16
16
|
<body>
|
package/kits/base/castle.json
CHANGED
package/kits/base/sdk/README.md
CHANGED
|
@@ -253,17 +253,18 @@ guide.
|
|
|
253
253
|
### Limits
|
|
254
254
|
|
|
255
255
|
The platform caps key length, value size, how many keys one read may
|
|
256
|
-
name, and how much
|
|
256
|
+
name, and how much each player may store, and it limits how fast a
|
|
257
257
|
player may read and write. Going over one of these rejects with a
|
|
258
258
|
`CastleError` whose `code` says which, so a deck can tell a player it is
|
|
259
|
-
saving too fast apart from a
|
|
259
|
+
saving too fast apart from a player who is out of space:
|
|
260
260
|
|
|
261
261
|
| limit | value |
|
|
262
262
|
|---|---|
|
|
263
263
|
| key | 128 bytes |
|
|
264
264
|
| value | 256 KB |
|
|
265
265
|
| keys in one `get` | 32 |
|
|
266
|
-
|
|
|
266
|
+
| one player's data in a deck | 10 MB, 50,000 keys |
|
|
267
|
+
| the deck's shared data (`Store.deck`) | 500 MB, 1,000,000 keys |
|
|
267
268
|
| one player's calls | 20 a second, 512 KB a second |
|
|
268
269
|
| every player of a deck together | 500 calls a second, 8 MB a second |
|
|
269
270
|
|
|
@@ -273,6 +274,13 @@ A `list` page holds at most 1,000 entries (a larger `limit` is lowered to
|
|
|
273
274
|
it) and ends early once it reaches 1 MB; take the next page with its
|
|
274
275
|
`cursor`.
|
|
275
276
|
|
|
277
|
+
A player's data is everything stored for them: their `Store.private`
|
|
278
|
+
keys, their `Store.user(id)` keys, and their scores on every board.
|
|
279
|
+
Each player has their own allowance, so a deck with more
|
|
280
|
+
players can hold more, and one player filling theirs does not stop
|
|
281
|
+
anyone else. A write that shrinks what a player stores always succeeds,
|
|
282
|
+
so a player who is full can always free space.
|
|
283
|
+
|
|
276
284
|
A value is JSON, so binary data such as a picture or a video clip costs
|
|
277
285
|
about a third more once encoded, and a clip of more than a few seconds
|
|
278
286
|
does not fit in one. Ship media with the deck instead.
|
package/kits/base/sdk/runtime.js
CHANGED
|
@@ -8,6 +8,8 @@ const HOST_CAPTURE_REQUEST = "castle-capture-cover";
|
|
|
8
8
|
const HOST_CAPTURE_RESULT = "castle-capture-cover-result";
|
|
9
9
|
let ws = null;
|
|
10
10
|
let logBuffer = [];
|
|
11
|
+
// The shell's play log keeps the same number of lines.
|
|
12
|
+
const MAX_BUFFERED_MESSAGES = 500;
|
|
11
13
|
let nextRequestId = 1;
|
|
12
14
|
const pendingRequests = new Map();
|
|
13
15
|
// Local-dev command channel: the `castle-web serve` dev server is the host, so
|
|
@@ -306,6 +308,11 @@ function sendMsg(msg) {
|
|
|
306
308
|
}
|
|
307
309
|
else {
|
|
308
310
|
logBuffer.push(msg);
|
|
311
|
+
// A deck logging every frame fills this while no socket is open, so the
|
|
312
|
+
// oldest messages are dropped.
|
|
313
|
+
if (logBuffer.length > MAX_BUFFERED_MESSAGES) {
|
|
314
|
+
logBuffer.splice(0, logBuffer.length - MAX_BUFFERED_MESSAGES);
|
|
315
|
+
}
|
|
309
316
|
}
|
|
310
317
|
}
|
|
311
318
|
function sendLocalRequest(msg) {
|
|
@@ -11,7 +11,7 @@
|
|
|
11
11
|
},
|
|
12
12
|
"castle.physics-2d": {
|
|
13
13
|
"deckId": "ckRZGFW4iPrx",
|
|
14
|
-
"version": "2026-09-
|
|
14
|
+
"version": "2026-09-25T17:51:55.024Z"
|
|
15
15
|
},
|
|
16
16
|
"castle.base": {
|
|
17
17
|
"deckId": "yRcmH4_aYllE",
|
|
@@ -27,5 +27,5 @@
|
|
|
27
27
|
},
|
|
28
28
|
"deckId": "oiFu96LkwZ09",
|
|
29
29
|
"cardId": "nkJgrvrCby3H",
|
|
30
|
-
"publishedVersion": "2026-09-
|
|
30
|
+
"publishedVersion": "2026-09-27T21:23:27.537Z"
|
|
31
31
|
}
|