playground-studio 0.1.1 → 0.1.2
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/cli.js
CHANGED
|
@@ -15040,9 +15040,9 @@ var require_picocolors = __commonJS({
|
|
|
15040
15040
|
var argv = p.argv || [];
|
|
15041
15041
|
var env = p.env || {};
|
|
15042
15042
|
var isColorSupported = !(!!env.NO_COLOR || argv.includes("--no-color")) && (!!env.FORCE_COLOR || argv.includes("--color") || p.platform === "win32" || (p.stdout || {}).isTTY && env.TERM !== "dumb" || !!env.CI);
|
|
15043
|
-
var formatter = (
|
|
15044
|
-
let string = "" + input, index2 = string.indexOf(close,
|
|
15045
|
-
return ~index2 ?
|
|
15043
|
+
var formatter = (open2, close, replace = open2) => (input) => {
|
|
15044
|
+
let string = "" + input, index2 = string.indexOf(close, open2.length);
|
|
15045
|
+
return ~index2 ? open2 + replaceClose(string, close, replace, index2) + close : open2 + string + close;
|
|
15046
15046
|
};
|
|
15047
15047
|
var replaceClose = (string, close, replace, index2) => {
|
|
15048
15048
|
let result = "", cursor = 0;
|
|
@@ -17073,27 +17073,27 @@ var require_util = __commonJS({
|
|
|
17073
17073
|
};
|
|
17074
17074
|
}
|
|
17075
17075
|
var normalize = lruMemoize(function normalize2(aPath) {
|
|
17076
|
-
var
|
|
17076
|
+
var path17 = aPath;
|
|
17077
17077
|
var url = urlParse(aPath);
|
|
17078
17078
|
if (url) {
|
|
17079
17079
|
if (!url.path) {
|
|
17080
17080
|
return aPath;
|
|
17081
17081
|
}
|
|
17082
|
-
|
|
17082
|
+
path17 = url.path;
|
|
17083
17083
|
}
|
|
17084
|
-
var isAbsolute = exports.isAbsolute(
|
|
17084
|
+
var isAbsolute = exports.isAbsolute(path17);
|
|
17085
17085
|
var parts = [];
|
|
17086
17086
|
var start = 0;
|
|
17087
17087
|
var i = 0;
|
|
17088
17088
|
while (true) {
|
|
17089
17089
|
start = i;
|
|
17090
|
-
i =
|
|
17090
|
+
i = path17.indexOf("/", start);
|
|
17091
17091
|
if (i === -1) {
|
|
17092
|
-
parts.push(
|
|
17092
|
+
parts.push(path17.slice(start));
|
|
17093
17093
|
break;
|
|
17094
17094
|
} else {
|
|
17095
|
-
parts.push(
|
|
17096
|
-
while (i <
|
|
17095
|
+
parts.push(path17.slice(start, i));
|
|
17096
|
+
while (i < path17.length && path17[i] === "/") {
|
|
17097
17097
|
i++;
|
|
17098
17098
|
}
|
|
17099
17099
|
}
|
|
@@ -17114,15 +17114,15 @@ var require_util = __commonJS({
|
|
|
17114
17114
|
}
|
|
17115
17115
|
}
|
|
17116
17116
|
}
|
|
17117
|
-
|
|
17118
|
-
if (
|
|
17119
|
-
|
|
17117
|
+
path17 = parts.join("/");
|
|
17118
|
+
if (path17 === "") {
|
|
17119
|
+
path17 = isAbsolute ? "/" : ".";
|
|
17120
17120
|
}
|
|
17121
17121
|
if (url) {
|
|
17122
|
-
url.path =
|
|
17122
|
+
url.path = path17;
|
|
17123
17123
|
return urlGenerate(url);
|
|
17124
17124
|
}
|
|
17125
|
-
return
|
|
17125
|
+
return path17;
|
|
17126
17126
|
});
|
|
17127
17127
|
exports.normalize = normalize;
|
|
17128
17128
|
function join(aRoot, aPath) {
|
|
@@ -18948,14 +18948,14 @@ var require_source_map = __commonJS({
|
|
|
18948
18948
|
var require_previous_map = __commonJS({
|
|
18949
18949
|
"../../node_modules/.pnpm/postcss@8.5.34/node_modules/postcss/lib/previous-map.js"(exports, module) {
|
|
18950
18950
|
"use strict";
|
|
18951
|
-
var { existsSync:
|
|
18951
|
+
var { existsSync: existsSync7, readFileSync: readFileSync2, realpathSync: realpathSync3 } = __require("fs");
|
|
18952
18952
|
var { dirname, isAbsolute, join, relative, sep } = __require("path");
|
|
18953
18953
|
var { SourceMapConsumer, SourceMapGenerator } = require_source_map();
|
|
18954
|
-
function realPath(
|
|
18954
|
+
function realPath(path17) {
|
|
18955
18955
|
try {
|
|
18956
|
-
return realpathSync3(
|
|
18956
|
+
return realpathSync3(path17);
|
|
18957
18957
|
} catch {
|
|
18958
|
-
return
|
|
18958
|
+
return path17;
|
|
18959
18959
|
}
|
|
18960
18960
|
}
|
|
18961
18961
|
function fromBase64(str) {
|
|
@@ -19018,19 +19018,19 @@ var require_previous_map = __commonJS({
|
|
|
19018
19018
|
this.annotation = this.getAnnotationURL(css.substring(start, end));
|
|
19019
19019
|
}
|
|
19020
19020
|
}
|
|
19021
|
-
loadFile(
|
|
19021
|
+
loadFile(path17, cssFile, trusted) {
|
|
19022
19022
|
if (!trusted && !this.unsafeMap) {
|
|
19023
|
-
if (!/\.map$/i.test(
|
|
19023
|
+
if (!/\.map$/i.test(path17)) return void 0;
|
|
19024
19024
|
if (!cssFile) return void 0;
|
|
19025
|
-
let rel = relative(realPath(dirname(cssFile)), realPath(
|
|
19025
|
+
let rel = relative(realPath(dirname(cssFile)), realPath(path17));
|
|
19026
19026
|
if (rel === ".." || rel.startsWith(".." + sep) || isAbsolute(rel)) {
|
|
19027
19027
|
return void 0;
|
|
19028
19028
|
}
|
|
19029
19029
|
}
|
|
19030
|
-
this.root = dirname(
|
|
19031
|
-
if (
|
|
19032
|
-
this.mapFile =
|
|
19033
|
-
return readFileSync2(
|
|
19030
|
+
this.root = dirname(path17);
|
|
19031
|
+
if (existsSync7(path17)) {
|
|
19032
|
+
this.mapFile = path17;
|
|
19033
|
+
return readFileSync2(path17, "utf-8").toString().trim();
|
|
19034
19034
|
}
|
|
19035
19035
|
}
|
|
19036
19036
|
loadMap(file, prev) {
|
|
@@ -19828,9 +19828,9 @@ var require_map_generator = __commonJS({
|
|
|
19828
19828
|
if (typeof this.mapOpts.annotation === "string") {
|
|
19829
19829
|
from = dirname(resolve2(from, this.mapOpts.annotation));
|
|
19830
19830
|
}
|
|
19831
|
-
let
|
|
19832
|
-
this.memoizedPaths.set(file,
|
|
19833
|
-
return
|
|
19831
|
+
let path17 = relative(from, file);
|
|
19832
|
+
this.memoizedPaths.set(file, path17);
|
|
19833
|
+
return path17;
|
|
19834
19834
|
}
|
|
19835
19835
|
previous() {
|
|
19836
19836
|
if (!this.previousMaps) {
|
|
@@ -19885,12 +19885,12 @@ var require_map_generator = __commonJS({
|
|
|
19885
19885
|
return window.btoa(unescape(encodeURIComponent(str)));
|
|
19886
19886
|
}
|
|
19887
19887
|
}
|
|
19888
|
-
toFileUrl(
|
|
19889
|
-
let cached = this.memoizedFileURLs.get(
|
|
19888
|
+
toFileUrl(path17) {
|
|
19889
|
+
let cached = this.memoizedFileURLs.get(path17);
|
|
19890
19890
|
if (cached) return cached;
|
|
19891
19891
|
if (pathToFileURL) {
|
|
19892
|
-
let fileURL = pathToFileURL(
|
|
19893
|
-
this.memoizedFileURLs.set(
|
|
19892
|
+
let fileURL = pathToFileURL(path17).toString();
|
|
19893
|
+
this.memoizedFileURLs.set(path17, fileURL);
|
|
19894
19894
|
return fileURL;
|
|
19895
19895
|
} else {
|
|
19896
19896
|
throw new Error(
|
|
@@ -19898,14 +19898,14 @@ var require_map_generator = __commonJS({
|
|
|
19898
19898
|
);
|
|
19899
19899
|
}
|
|
19900
19900
|
}
|
|
19901
|
-
toUrl(
|
|
19902
|
-
let cached = this.memoizedURLs.get(
|
|
19901
|
+
toUrl(path17) {
|
|
19902
|
+
let cached = this.memoizedURLs.get(path17);
|
|
19903
19903
|
if (cached) return cached;
|
|
19904
19904
|
if (sep === "\\") {
|
|
19905
|
-
|
|
19905
|
+
path17 = path17.replace(/\\/g, "/");
|
|
19906
19906
|
}
|
|
19907
|
-
let url = encodeURI(
|
|
19908
|
-
this.memoizedURLs.set(
|
|
19907
|
+
let url = encodeURI(path17).replace(/[#?]/g, encodeURIComponent);
|
|
19908
|
+
this.memoizedURLs.set(path17, url);
|
|
19909
19909
|
return url;
|
|
19910
19910
|
}
|
|
19911
19911
|
};
|
|
@@ -19960,7 +19960,7 @@ var require_parser = __commonJS({
|
|
|
19960
19960
|
let prev;
|
|
19961
19961
|
let shift;
|
|
19962
19962
|
let last = false;
|
|
19963
|
-
let
|
|
19963
|
+
let open2 = false;
|
|
19964
19964
|
let params = [];
|
|
19965
19965
|
let brackets = [];
|
|
19966
19966
|
while (!this.tokenizer.endOfFile()) {
|
|
@@ -19980,7 +19980,7 @@ var require_parser = __commonJS({
|
|
|
19980
19980
|
this.semicolon = true;
|
|
19981
19981
|
break;
|
|
19982
19982
|
} else if (type === "{") {
|
|
19983
|
-
|
|
19983
|
+
open2 = true;
|
|
19984
19984
|
break;
|
|
19985
19985
|
} else if (type === "}") {
|
|
19986
19986
|
if (params.length > 0) {
|
|
@@ -20022,7 +20022,7 @@ var require_parser = __commonJS({
|
|
|
20022
20022
|
node.raws.afterName = "";
|
|
20023
20023
|
node.params = "";
|
|
20024
20024
|
}
|
|
20025
|
-
if (
|
|
20025
|
+
if (open2) {
|
|
20026
20026
|
node.nodes = [];
|
|
20027
20027
|
this.current = node;
|
|
20028
20028
|
}
|
|
@@ -21961,10 +21961,10 @@ __export(setup_exports, {
|
|
|
21961
21961
|
runSetup: () => runSetup
|
|
21962
21962
|
});
|
|
21963
21963
|
import { spawnSync } from "node:child_process";
|
|
21964
|
-
import { accessSync as accessSync2, constants as constants2, existsSync as
|
|
21964
|
+
import { accessSync as accessSync2, constants as constants2, existsSync as existsSync6, lstatSync, mkdirSync, realpathSync, symlinkSync, unlinkSync } from "node:fs";
|
|
21965
21965
|
import { createInterface } from "node:readline/promises";
|
|
21966
21966
|
import { homedir } from "node:os";
|
|
21967
|
-
import
|
|
21967
|
+
import path14 from "node:path";
|
|
21968
21968
|
function exec(cmd, args) {
|
|
21969
21969
|
const r = spawnSync(cmd, args, { encoding: "utf8", shell: win, timeout: 3e4 });
|
|
21970
21970
|
return { ok: r.status === 0, out: `${r.stdout ?? ""}${r.stderr ?? ""}` };
|
|
@@ -21995,13 +21995,13 @@ async function runSetup({ cliPath, yes }) {
|
|
|
21995
21995
|
const found = which("pg-studio");
|
|
21996
21996
|
if (found && real(found) === real(cliPath)) ok(`The pg-studio command is ready ${dim(found)}`);
|
|
21997
21997
|
else if (found) skip(`A pg-studio command is already at ${found}. Left as it is.`);
|
|
21998
|
-
else if (win) skip(`To start Playground from any folder, run: npm install -g ${
|
|
21998
|
+
else if (win) skip(`To start Playground from any folder, run: npm install -g ${path14.dirname(path14.dirname(cliPath))}`);
|
|
21999
21999
|
else {
|
|
22000
22000
|
const npmBin = exec("npm", ["prefix", "-g"]);
|
|
22001
|
-
const dirs = [npmBin.ok ?
|
|
22001
|
+
const dirs = [npmBin.ok ? path14.join(npmBin.out.trim().split("\n").pop(), "bin") : "", path14.join(homedir(), ".local", "bin")];
|
|
22002
22002
|
const onPath = new Set(pathDirs().map(real));
|
|
22003
22003
|
const dir = dirs.find((d) => d && onPath.has(real(d)) && writable(d));
|
|
22004
|
-
const link = dir &&
|
|
22004
|
+
const link = dir && path14.join(dir, "pg-studio");
|
|
22005
22005
|
if (!link) {
|
|
22006
22006
|
warn("No folder on your PATH can take the pg-studio command. Start Playground with:");
|
|
22007
22007
|
indent(shown(["node", cliPath]));
|
|
@@ -22087,7 +22087,7 @@ var init_setup = __esm({
|
|
|
22087
22087
|
warn = (s) => console.log(`${paint(33)("!")} ${s}`);
|
|
22088
22088
|
skip = (s) => console.log(`${dim("\u2013")} ${s}`);
|
|
22089
22089
|
indent = (s) => console.log(` ${dim(s)}`);
|
|
22090
|
-
pathDirs = () => (process.env.PATH ?? "").split(
|
|
22090
|
+
pathDirs = () => (process.env.PATH ?? "").split(path14.delimiter).filter(Boolean);
|
|
22091
22091
|
real = (p) => {
|
|
22092
22092
|
try {
|
|
22093
22093
|
return realpathSync(p);
|
|
@@ -22103,7 +22103,7 @@ var init_setup = __esm({
|
|
|
22103
22103
|
return false;
|
|
22104
22104
|
}
|
|
22105
22105
|
};
|
|
22106
|
-
which = (name) => pathDirs().map((d) =>
|
|
22106
|
+
which = (name) => pathDirs().map((d) => path14.join(d, name)).find((p) => existsSync6(p)) ?? null;
|
|
22107
22107
|
}
|
|
22108
22108
|
});
|
|
22109
22109
|
|
|
@@ -22115,10 +22115,10 @@ __export(bridge_exports, {
|
|
|
22115
22115
|
runBridge: () => runBridge,
|
|
22116
22116
|
runWait: () => runWait
|
|
22117
22117
|
});
|
|
22118
|
-
import { spawn as
|
|
22118
|
+
import { spawn as spawn6 } from "node:child_process";
|
|
22119
22119
|
import { randomUUID as randomUUID2 } from "node:crypto";
|
|
22120
22120
|
import { mkdirSync as mkdirSync2, openSync, readFileSync, realpathSync as realpathSync2, writeFileSync } from "node:fs";
|
|
22121
|
-
import
|
|
22121
|
+
import path15 from "node:path";
|
|
22122
22122
|
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
22123
22123
|
import { Server } from "@modelcontextprotocol/server";
|
|
22124
22124
|
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
@@ -22133,8 +22133,8 @@ async function health(port2) {
|
|
|
22133
22133
|
async function ensureDaemon(root2, firstPort, cliPath) {
|
|
22134
22134
|
const want = real2(root2);
|
|
22135
22135
|
let free = null;
|
|
22136
|
-
const dir =
|
|
22137
|
-
const pidFile =
|
|
22136
|
+
const dir = path15.join(want, ".playground");
|
|
22137
|
+
const pidFile = path15.join(dir, "daemon.pid");
|
|
22138
22138
|
for (let port2 = firstPort; port2 < firstPort + 20; port2++) {
|
|
22139
22139
|
const h = await health(port2);
|
|
22140
22140
|
if (h?.project && real2(h.project.root) === want) {
|
|
@@ -22148,8 +22148,8 @@ async function ensureDaemon(root2, firstPort, cliPath) {
|
|
|
22148
22148
|
}
|
|
22149
22149
|
if (free === null) throw new Error(`No free port between ${firstPort} and ${firstPort + 19} to start Playground on.`);
|
|
22150
22150
|
mkdirSync2(dir, { recursive: true });
|
|
22151
|
-
const log = openSync(
|
|
22152
|
-
const child =
|
|
22151
|
+
const log = openSync(path15.join(dir, "daemon.log"), "a");
|
|
22152
|
+
const child = spawn6(process.execPath, [...process.execArgv, cliPath, want, "--port", String(free), "--no-open"], {
|
|
22153
22153
|
cwd: want,
|
|
22154
22154
|
detached: true,
|
|
22155
22155
|
stdio: ["ignore", log, log]
|
|
@@ -22171,7 +22171,7 @@ async function ensureDaemon(root2, firstPort, cliPath) {
|
|
|
22171
22171
|
return null;
|
|
22172
22172
|
})();
|
|
22173
22173
|
if (again) return again;
|
|
22174
|
-
throw new Error(`Playground did not start. See ${
|
|
22174
|
+
throw new Error(`Playground did not start. See ${path15.join(dir, "daemon.log")}.`);
|
|
22175
22175
|
}
|
|
22176
22176
|
function readPid(file) {
|
|
22177
22177
|
try {
|
|
@@ -22353,7 +22353,7 @@ var init_bridge = __esm({
|
|
|
22353
22353
|
try {
|
|
22354
22354
|
return realpathSync2(p);
|
|
22355
22355
|
} catch {
|
|
22356
|
-
return
|
|
22356
|
+
return path15.resolve(p);
|
|
22357
22357
|
}
|
|
22358
22358
|
};
|
|
22359
22359
|
INSTRUCTIONS = `Playground (pg-studio) is the designer's canvas for this project. When a <channel source="pg-studio"> message arrives, the designer wants you in Playground: call wait_for_handback right away and do what it returns, as you would after opening a screen.`;
|
|
@@ -22363,16 +22363,16 @@ var init_bridge = __esm({
|
|
|
22363
22363
|
|
|
22364
22364
|
// src/cli.ts
|
|
22365
22365
|
import { statSync as statSync2 } from "node:fs";
|
|
22366
|
-
import
|
|
22367
|
-
import { spawn as
|
|
22366
|
+
import path16 from "node:path";
|
|
22367
|
+
import { spawn as spawn7 } from "node:child_process";
|
|
22368
22368
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
22369
22369
|
import { parseArgs } from "node:util";
|
|
22370
22370
|
|
|
22371
22371
|
// ../daemon/src/server.ts
|
|
22372
22372
|
import { createServer as createServer2 } from "node:http";
|
|
22373
|
-
import { readFile as
|
|
22373
|
+
import { readFile as readFile9, realpath as realpath4, stat as stat4 } from "node:fs/promises";
|
|
22374
22374
|
import { fileURLToPath } from "node:url";
|
|
22375
|
-
import
|
|
22375
|
+
import path13 from "node:path";
|
|
22376
22376
|
import { localhostHostValidation, localhostOriginValidation, NodeStreamableHTTPServerTransport } from "@modelcontextprotocol/node";
|
|
22377
22377
|
import { WebSocketServer } from "ws";
|
|
22378
22378
|
|
|
@@ -23763,9 +23763,9 @@ function lin(c) {
|
|
|
23763
23763
|
function colorDistance(a, b) {
|
|
23764
23764
|
const [r1, g1, b1] = hexRgb(a);
|
|
23765
23765
|
const [r24, g2, b2] = hexRgb(b);
|
|
23766
|
-
const
|
|
23766
|
+
const rm4 = (r1 + r24) / 2;
|
|
23767
23767
|
const dr = r1 - r24, dg = g1 - g2, db = b1 - b2;
|
|
23768
|
-
return Math.sqrt((2 +
|
|
23768
|
+
return Math.sqrt((2 + rm4 / 256) * dr * dr + 4 * dg * dg + (2 + (255 - rm4) / 256) * db * db) / 3;
|
|
23769
23769
|
}
|
|
23770
23770
|
function hexHsl(hex3) {
|
|
23771
23771
|
const [r, g, b] = hexRgb(hex3).map((v) => v / 255);
|
|
@@ -24250,26 +24250,34 @@ function inGroup(cls, group, scale = TW_DEFAULT) {
|
|
|
24250
24250
|
return /^opacity-/.test(c);
|
|
24251
24251
|
}
|
|
24252
24252
|
}
|
|
24253
|
-
var
|
|
24254
|
-
|
|
24253
|
+
var TW_SCREENS = { sm: 640, md: 768, lg: 1024, xl: 1280, "2xl": 1536 };
|
|
24254
|
+
var isScreen = (s) => typeof s === "string" && s in TW_SCREENS;
|
|
24255
|
+
var atScreen = (c, screen) => screen ? c.startsWith(`${screen}:`) && !c.slice(screen.length + 1).includes(":") ? c.slice(screen.length + 1) : null : c.includes(":") ? null : c;
|
|
24256
|
+
var base = (c) => atScreen(c, null);
|
|
24257
|
+
function replaceGroup(classes, group, next, scale = TW_DEFAULT, screen) {
|
|
24255
24258
|
const out = [];
|
|
24256
24259
|
let at = -1;
|
|
24260
|
+
let after = -1;
|
|
24257
24261
|
for (const c of classes) {
|
|
24258
|
-
const b =
|
|
24262
|
+
const b = atScreen(c, screen);
|
|
24259
24263
|
if (b && inGroup(b, group, scale)) {
|
|
24260
24264
|
if (at < 0) at = out.length;
|
|
24261
24265
|
continue;
|
|
24262
24266
|
}
|
|
24263
24267
|
out.push(c);
|
|
24268
|
+
const plain2 = base(c);
|
|
24269
|
+
if (screen && plain2 && inGroup(plain2, group, scale)) after = out.length;
|
|
24264
24270
|
}
|
|
24265
|
-
const
|
|
24266
|
-
|
|
24267
|
-
|
|
24271
|
+
const want = screen ? next.map((c) => `${screen}:${c}`) : next;
|
|
24272
|
+
const add = want.filter((c) => !out.includes(c));
|
|
24273
|
+
const where = at >= 0 ? at : after;
|
|
24274
|
+
if (where < 0) return [...out, ...add];
|
|
24275
|
+
return [...out.slice(0, where), ...add, ...out.slice(where)];
|
|
24268
24276
|
}
|
|
24269
|
-
function rewriteClassString(text2, group, next, scale = TW_DEFAULT) {
|
|
24277
|
+
function rewriteClassString(text2, group, next, scale = TW_DEFAULT, screen) {
|
|
24270
24278
|
const tokens = text2.split(/(\s+)/);
|
|
24271
24279
|
const words2 = tokens.filter((t, i) => i % 2 === 0 && t);
|
|
24272
|
-
const updated = replaceGroup(words2, group, next, scale);
|
|
24280
|
+
const updated = replaceGroup(words2, group, next, scale, screen);
|
|
24273
24281
|
if (updated.join(" ") === words2.join(" ")) return text2;
|
|
24274
24282
|
return text2.match(/^\s*/)[0] + updated.join(" ") + text2.match(/\s*$/)[0];
|
|
24275
24283
|
}
|
|
@@ -24441,7 +24449,7 @@ function planAnimations(i, phase2, counts, reduced = false) {
|
|
|
24441
24449
|
const out = [];
|
|
24442
24450
|
const press = i.kind === "press";
|
|
24443
24451
|
const tracks = activeTracks(i);
|
|
24444
|
-
const
|
|
24452
|
+
const run5 = (who, index2, extra) => {
|
|
24445
24453
|
if (reduced) {
|
|
24446
24454
|
const fade2 = [{ opacity: press ? 1 : 0 }, { opacity: 1 }];
|
|
24447
24455
|
const d = Math.min(150, p.duration);
|
|
@@ -24459,10 +24467,10 @@ function planAnimations(i, phase2, counts, reduced = false) {
|
|
|
24459
24467
|
};
|
|
24460
24468
|
if (i.kind === "text") {
|
|
24461
24469
|
const steps = staggerSteps(counts.pieces, i.order ?? "first");
|
|
24462
|
-
for (let k = 0; k < counts.pieces; k++)
|
|
24470
|
+
for (let k = 0; k < counts.pieces; k++) run5("piece", k, steps[k] * i.stagger);
|
|
24463
24471
|
return out;
|
|
24464
24472
|
}
|
|
24465
|
-
|
|
24473
|
+
run5("self", 0, 0);
|
|
24466
24474
|
if (phase2 === "enter" && i.stagger > 0 && i.items > 1 && !reduced && counts.items) {
|
|
24467
24475
|
const steps = staggerSteps(counts.items, i.order ?? "first");
|
|
24468
24476
|
for (let k = 0; k < counts.items; k++) {
|
|
@@ -26847,9 +26855,9 @@ async function readTokens(root2) {
|
|
|
26847
26855
|
return { colors, fonts: f.fonts, ...f.radius !== void 0 ? { radius: f.radius } : {}, sources: [...f.sources] };
|
|
26848
26856
|
}
|
|
26849
26857
|
var DARK_SEL = /(?:\.dark|\[data-theme=["']?dark["']?\]|\[data-mode=["']?dark["']?\])[^{,]*\{/g;
|
|
26850
|
-
function blockEnd(css,
|
|
26858
|
+
function blockEnd(css, open2) {
|
|
26851
26859
|
let depth = 1;
|
|
26852
|
-
let i =
|
|
26860
|
+
let i = open2;
|
|
26853
26861
|
while (i < css.length && depth) {
|
|
26854
26862
|
if (css[i] === "{") depth++;
|
|
26855
26863
|
else if (css[i] === "}") depth--;
|
|
@@ -26931,10 +26939,10 @@ async function sourceFiles(root2, limit2 = 800) {
|
|
|
26931
26939
|
}
|
|
26932
26940
|
return out;
|
|
26933
26941
|
}
|
|
26934
|
-
function objectKeys(src,
|
|
26942
|
+
function objectKeys(src, open2) {
|
|
26935
26943
|
const keys = [];
|
|
26936
26944
|
let depth = 0;
|
|
26937
|
-
let i =
|
|
26945
|
+
let i = open2;
|
|
26938
26946
|
let str = null;
|
|
26939
26947
|
for (; i < src.length; i++) {
|
|
26940
26948
|
const c = src[i];
|
|
@@ -26956,8 +26964,8 @@ function objectKeys(src, open) {
|
|
|
26956
26964
|
}
|
|
26957
26965
|
if (depth === 1) {
|
|
26958
26966
|
const m = /^\s*["']?([\w-]+)["']?\s*:/.exec(src.slice(i, i + 60));
|
|
26959
|
-
const prev = src.slice(Math.max(
|
|
26960
|
-
if (m && (i ===
|
|
26967
|
+
const prev = src.slice(Math.max(open2, i - 1), i);
|
|
26968
|
+
if (m && (i === open2 + 1 || /[,{\s]/.test(prev)) && /[\s,{]/.test(src[i - 1] ?? " ")) {
|
|
26961
26969
|
keys.push({ key: m[1], at: i + m[0].length });
|
|
26962
26970
|
i += m[0].length - 1;
|
|
26963
26971
|
}
|
|
@@ -26968,9 +26976,9 @@ function objectKeys(src, open) {
|
|
|
26968
26976
|
function readVariants(src) {
|
|
26969
26977
|
const at = src.search(/variants\s*:\s*\{/);
|
|
26970
26978
|
if (at < 0) return {};
|
|
26971
|
-
const
|
|
26979
|
+
const open2 = src.indexOf("{", at);
|
|
26972
26980
|
const out = {};
|
|
26973
|
-
for (const { key, at: valAt } of objectKeys(src,
|
|
26981
|
+
for (const { key, at: valAt } of objectKeys(src, open2)) {
|
|
26974
26982
|
const brace = src.slice(valAt).search(/\S/);
|
|
26975
26983
|
if (src[valAt + brace] !== "{") continue;
|
|
26976
26984
|
const values3 = objectKeys(src, valAt + brace).map((k) => k.key);
|
|
@@ -27992,7 +28000,7 @@ function findElement(text2, line, tag) {
|
|
|
27992
28000
|
if (!el) return { ok: false, reason: `There's no <${tag || "element"}> at line ${line} any more. Save, let the page reload, then try again.` };
|
|
27993
28001
|
return { ok: true, ast, el };
|
|
27994
28002
|
}
|
|
27995
|
-
function writeClasses(text2, line, tag, group, next, scale) {
|
|
28003
|
+
function writeClasses(text2, line, tag, group, next, scale, screen) {
|
|
27996
28004
|
const found0 = findElement(text2, line, tag);
|
|
27997
28005
|
if (!found0.ok) return found0;
|
|
27998
28006
|
const { el } = found0;
|
|
@@ -28003,18 +28011,19 @@ function writeClasses(text2, line, tag, group, next, scale) {
|
|
|
28003
28011
|
}
|
|
28004
28012
|
const name = el.name;
|
|
28005
28013
|
const at = name.end;
|
|
28006
|
-
const
|
|
28007
|
-
|
|
28014
|
+
const cls = (screen ? next.map((c) => `${screen}:${c}`) : next).join(" ");
|
|
28015
|
+
const add = ` className="${cls}"`;
|
|
28016
|
+
return { ok: true, text: text2.slice(0, at) + add + text2.slice(at), before: "", after: cls, .../^[A-Z]/.test(nameOf(el)) ? { note: `Added className to <${nameOf(el)}>; it applies if the component passes it on.` } : {} };
|
|
28008
28017
|
}
|
|
28009
28018
|
const value = attr.value;
|
|
28010
28019
|
const found = value ? slots(value) : null;
|
|
28011
28020
|
if (!found) return { ok: false, reason: `The classes on <${nameOf(el)}> come from a variable, so Playground can't change them safely. Hand this one to your agent.` };
|
|
28012
|
-
const has = (s) => words(text2.slice(s.start, s.end)).some((c) =>
|
|
28021
|
+
const has = (s) => words(text2.slice(s.start, s.end)).some((c) => [atScreen(c, null), screen ? atScreen(c, screen) : null].some((b) => b && inGroup(b, group, scale)));
|
|
28013
28022
|
const fixed = found.filter((s) => !s.conditional);
|
|
28014
28023
|
const slot = fixed.find(has) ?? fixed[0];
|
|
28015
28024
|
if (!slot) return { ok: false, reason: `Every class on <${nameOf(el)}> depends on a condition, so Playground can't tell which to change. Hand this one to your agent.` };
|
|
28016
28025
|
const before = text2.slice(slot.start, slot.end);
|
|
28017
|
-
const after = rewriteClassString(before, group, next, scale);
|
|
28026
|
+
const after = rewriteClassString(before, group, next, scale, screen);
|
|
28018
28027
|
const also = found.filter((s) => s.conditional && has(s));
|
|
28019
28028
|
return {
|
|
28020
28029
|
ok: true,
|
|
@@ -28303,14 +28312,14 @@ function appendDecl(text2, c, base2, prop, value) {
|
|
|
28303
28312
|
` };
|
|
28304
28313
|
}
|
|
28305
28314
|
const r = c;
|
|
28306
|
-
const
|
|
28315
|
+
const open2 = text2.indexOf("{", base2 + r.source.start.offset) + 1;
|
|
28307
28316
|
const close = base2 + r.source.end.offset - 1;
|
|
28308
28317
|
const outer = (r.raws.before ?? "").split("\n").at(-1) ?? "";
|
|
28309
28318
|
const inner = (r.nodes ?? []).find((n) => n.raws.before?.includes("\n"))?.raws.before?.split("\n").at(-1) ?? `${outer} `;
|
|
28310
|
-
if (!text2.slice(
|
|
28319
|
+
if (!text2.slice(open2, close).trim()) return { start: open2, end: close, text: `
|
|
28311
28320
|
${inner}${prop}: ${value};
|
|
28312
28321
|
${outer}` };
|
|
28313
|
-
return { start:
|
|
28322
|
+
return { start: open2, end: open2, text: `
|
|
28314
28323
|
${inner}${prop}: ${value};` };
|
|
28315
28324
|
}
|
|
28316
28325
|
function restoreContainer(text2, c, base2, group, before) {
|
|
@@ -29014,8 +29023,9 @@ import { McpServer } from "@modelcontextprotocol/server";
|
|
|
29014
29023
|
import { z as z4 } from "zod";
|
|
29015
29024
|
|
|
29016
29025
|
// ../daemon/src/devserver.ts
|
|
29017
|
-
import { execFile as execFile2 } from "node:child_process";
|
|
29018
|
-
import {
|
|
29026
|
+
import { execFile as execFile2, spawn as spawn2 } from "node:child_process";
|
|
29027
|
+
import { existsSync as existsSync4 } from "node:fs";
|
|
29028
|
+
import { mkdir as mkdir3, open, readFile as readFile4, readlink, realpath } from "node:fs/promises";
|
|
29019
29029
|
import path7 from "node:path";
|
|
29020
29030
|
import { promisify as promisify2 } from "node:util";
|
|
29021
29031
|
var run2 = promisify2(execFile2);
|
|
@@ -29086,26 +29096,119 @@ async function findDevServers(root2, skipPorts = []) {
|
|
|
29086
29096
|
);
|
|
29087
29097
|
return found.sort((a, b) => a.port - b.port);
|
|
29088
29098
|
}
|
|
29089
|
-
async function
|
|
29099
|
+
async function devScript(root2) {
|
|
29090
29100
|
try {
|
|
29091
29101
|
const pkg = JSON.parse(await readFile4(path7.join(root2, "package.json"), "utf8"));
|
|
29092
29102
|
const scripts = pkg.scripts ?? {};
|
|
29093
|
-
const
|
|
29094
|
-
if (!
|
|
29095
|
-
const
|
|
29096
|
-
|
|
29103
|
+
const script = ["dev", "start", "serve"].find((s) => scripts[s]);
|
|
29104
|
+
if (!script) return null;
|
|
29105
|
+
const lock = (f) => existsSync4(path7.join(root2, f));
|
|
29106
|
+
const pm = pkg.packageManager?.split("@")[0] ?? (lock("pnpm-lock.yaml") ? "pnpm" : lock("yarn.lock") ? "yarn" : lock("bun.lockb") || lock("bun.lock") ? "bun" : "npm");
|
|
29107
|
+
return { pm, script };
|
|
29097
29108
|
} catch {
|
|
29098
29109
|
return null;
|
|
29099
29110
|
}
|
|
29100
29111
|
}
|
|
29101
|
-
async function
|
|
29102
|
-
|
|
29103
|
-
|
|
29104
|
-
return true;
|
|
29105
|
-
} catch {
|
|
29106
|
-
return false;
|
|
29107
|
-
}
|
|
29112
|
+
async function devCommand(root2) {
|
|
29113
|
+
const d = await devScript(root2);
|
|
29114
|
+
return d && `${d.pm} run ${d.script}`;
|
|
29108
29115
|
}
|
|
29116
|
+
var DevServerStarter = class {
|
|
29117
|
+
constructor(root2, dir, host, patience = 4e4, limit2 = 18e4) {
|
|
29118
|
+
this.root = root2;
|
|
29119
|
+
this.dir = dir;
|
|
29120
|
+
this.host = host;
|
|
29121
|
+
this.patience = patience;
|
|
29122
|
+
this.limit = limit2;
|
|
29123
|
+
}
|
|
29124
|
+
root;
|
|
29125
|
+
dir;
|
|
29126
|
+
host;
|
|
29127
|
+
patience;
|
|
29128
|
+
limit;
|
|
29129
|
+
child = null;
|
|
29130
|
+
ready = null;
|
|
29131
|
+
command = "";
|
|
29132
|
+
/** Whether Playground started the running one. */
|
|
29133
|
+
get running() {
|
|
29134
|
+
return !!this.child && this.child.exitCode === null && this.child.signalCode === null;
|
|
29135
|
+
}
|
|
29136
|
+
/** A running dev server for the project: one already there, or one Playground starts now. */
|
|
29137
|
+
async ensure(skipPorts = []) {
|
|
29138
|
+
const found = await findDevServers(this.root, skipPorts);
|
|
29139
|
+
if (found.length) return { ok: true, server: found[0], started: false };
|
|
29140
|
+
if (process.env.PG_NO_DEVSERVER) return { ok: false, starting: false, reason: "starting dev servers is turned off (PG_NO_DEVSERVER)" };
|
|
29141
|
+
this.ready ??= this.start(skipPorts).finally(() => this.ready = null);
|
|
29142
|
+
const waited = await Promise.race([this.ready, new Promise((r) => setTimeout(() => r(null), this.patience).unref())]);
|
|
29143
|
+
return waited ?? { ok: false, starting: true, command: this.command };
|
|
29144
|
+
}
|
|
29145
|
+
async start(skipPorts) {
|
|
29146
|
+
const dev = await devScript(this.root);
|
|
29147
|
+
if (!dev) return { ok: false, starting: false, reason: "package.json has no dev, start or serve script" };
|
|
29148
|
+
this.command = `${dev.pm} run ${dev.script}`;
|
|
29149
|
+
if (!existsSync4(path7.join(this.root, "node_modules"))) {
|
|
29150
|
+
return { ok: false, starting: false, reason: `its dependencies aren't installed. Run \`${dev.pm} install\`, then try again` };
|
|
29151
|
+
}
|
|
29152
|
+
await mkdir3(this.dir, { recursive: true });
|
|
29153
|
+
const logFile = path7.join(this.dir, "devserver.log");
|
|
29154
|
+
const out = await open(logFile, "w");
|
|
29155
|
+
this.host.notify("info", `Starting your dev server (${this.command})\u2026`);
|
|
29156
|
+
this.host.log(`starting the dev server: ${this.command}`);
|
|
29157
|
+
const win2 = process.platform === "win32";
|
|
29158
|
+
const child = spawn2(dev.pm, ["run", dev.script], {
|
|
29159
|
+
cwd: this.root,
|
|
29160
|
+
detached: !win2,
|
|
29161
|
+
shell: win2,
|
|
29162
|
+
stdio: ["ignore", out.fd, out.fd],
|
|
29163
|
+
// BROWSER=none: Create React App and others open a browser tab on start otherwise.
|
|
29164
|
+
env: { ...process.env, BROWSER: "none", FORCE_COLOR: "0", NO_COLOR: "1" }
|
|
29165
|
+
});
|
|
29166
|
+
void out.close();
|
|
29167
|
+
this.child = child;
|
|
29168
|
+
let exited = null;
|
|
29169
|
+
child.on("error", (err) => exited = err.message);
|
|
29170
|
+
child.on("exit", (code, signal) => {
|
|
29171
|
+
exited ??= signal ? `it stopped (${signal})` : `it exited with code ${code}`;
|
|
29172
|
+
if (this.child === child) this.child = null;
|
|
29173
|
+
});
|
|
29174
|
+
const tail = async () => {
|
|
29175
|
+
const text2 = (await readFile4(logFile, "utf8").catch(() => "")).replace(/\x1b\[[0-9;]*m/g, "");
|
|
29176
|
+
const lines = text2.trim().split("\n").filter(Boolean).slice(-6).join("\n");
|
|
29177
|
+
return lines ? `
|
|
29178
|
+
Last lines of .playground/devserver.log:
|
|
29179
|
+
${lines}` : "";
|
|
29180
|
+
};
|
|
29181
|
+
const until = Date.now() + this.limit;
|
|
29182
|
+
while (Date.now() < until) {
|
|
29183
|
+
await new Promise((r) => setTimeout(r, 400));
|
|
29184
|
+
if (exited) {
|
|
29185
|
+
this.host.notify("error", `Your dev server didn't start: ${exited}.`);
|
|
29186
|
+
return { ok: false, starting: false, reason: `\`${this.command}\` didn't start a server: ${exited}.${await tail()}` };
|
|
29187
|
+
}
|
|
29188
|
+
const found = await findDevServers(this.root, skipPorts);
|
|
29189
|
+
if (found.length) {
|
|
29190
|
+
this.host.notify("success", `Started your dev server on ${found[0].url}`);
|
|
29191
|
+
this.host.log(`dev server ready on ${found[0].url}`);
|
|
29192
|
+
return { ok: true, server: found[0], started: true };
|
|
29193
|
+
}
|
|
29194
|
+
}
|
|
29195
|
+
this.stop();
|
|
29196
|
+
this.host.notify("error", `Your dev server didn't answer within ${Math.round(this.limit / 1e3)} seconds, so Playground stopped it.`);
|
|
29197
|
+
return { ok: false, starting: false, reason: `\`${this.command}\` didn't serve a page within ${Math.round(this.limit / 1e3)} seconds.${await tail()}` };
|
|
29198
|
+
}
|
|
29199
|
+
/** Stops the dev server Playground started, and everything it started. */
|
|
29200
|
+
stop() {
|
|
29201
|
+
const child = this.child;
|
|
29202
|
+
this.child = null;
|
|
29203
|
+
if (!child?.pid || child.exitCode !== null) return;
|
|
29204
|
+
try {
|
|
29205
|
+
if (process.platform === "win32") spawn2("taskkill", ["/pid", String(child.pid), "/t", "/f"], { stdio: "ignore" });
|
|
29206
|
+
else process.kill(-child.pid, "SIGTERM");
|
|
29207
|
+
} catch {
|
|
29208
|
+
child.kill("SIGTERM");
|
|
29209
|
+
}
|
|
29210
|
+
}
|
|
29211
|
+
};
|
|
29109
29212
|
|
|
29110
29213
|
// ../daemon/src/mcp.ts
|
|
29111
29214
|
var requestContext = new AsyncLocalStorage();
|
|
@@ -29175,13 +29278,14 @@ function renderEvent(ev, agentName, lint = null, onCall = false, waitCmd = null,
|
|
|
29175
29278
|
"",
|
|
29176
29279
|
`In live frames, the designer changed ${ev.liveChanges.length === 1 ? "one thing" : `${ev.liveChanges.length} things`}. These are already written to the code:`,
|
|
29177
29280
|
...ev.liveChanges.map((c, i) => {
|
|
29178
|
-
const head2 = `${i + 1}. ${c.file}:${c.line}${c.component ? ` (${c.component})` : ""}: ${c.what} ${c.from} \u2192 ${c.to}`;
|
|
29281
|
+
const head2 = `${i + 1}. ${c.file}:${c.line}${c.component ? ` (${c.component})` : ""}: ${c.what} ${c.from} \u2192 ${c.to}${c.screen ? ` from the ${c.screen}: screen up only (smaller sizes keep the base classes)` : ""}`;
|
|
29179
29282
|
if (c.how === "prop") return `${head2}, the prop where the app uses <${c.tag}>: ${c.before || "not set"} \u2192 ${c.after || "not set (its default)"}`;
|
|
29180
29283
|
const how = !c.how || c.how === "tailwind" || !c.target ? `classes "${c.before}" \u2192 "${c.after}"` : `written to ${c.target.file}:${c.target.line}${c.target.selector ? ` (${c.target.selector})` : c.target.name ? ` (styled ${c.target.name})` : " (inline style)"} as "${c.before || "nothing"}" \u2192 "${c.after}"`;
|
|
29181
29284
|
return `${head2}, ${how}${c.note ? `. ${c.note}` : ""}`;
|
|
29182
29285
|
}),
|
|
29183
29286
|
"",
|
|
29184
|
-
"Keep these. Check whether the same fix belongs on sibling elements or other uses of the component, and say so rather than changing them unasked."
|
|
29287
|
+
"Keep these. Check whether the same fix belongs on sibling elements or other uses of the component, and say so rather than changing them unasked.",
|
|
29288
|
+
...ev.liveBranch ? [`Playground also saved these edits on the git branch ${ev.liveBranch}, which isn't checked out: the files you have already contain them. Leave that branch alone unless the designer asks.`] : []
|
|
29185
29289
|
);
|
|
29186
29290
|
}
|
|
29187
29291
|
if (ev.frame) {
|
|
@@ -29255,7 +29359,7 @@ function buildMcpServer(hub, showEditor = () => {
|
|
|
29255
29359
|
"open_screen",
|
|
29256
29360
|
{
|
|
29257
29361
|
title: "Open a screen in Playground",
|
|
29258
|
-
description: `Open a screen of this project in the Playground canvas for the designer to edit by hand. Playground loads the running page in a headless browser and turns it into editable layers (boxes, text, images, fonts) at their real positions. Pass url (for example http://localhost:5173/settings) when you know it. Without url, Playground finds the dev server this project is running and opens the page linked under the title (title "Settings" follows the app's Settings link). If no dev server is running,
|
|
29362
|
+
description: `Open a screen of this project in the Playground canvas for the designer to edit by hand. Playground loads the running page in a headless browser and turns it into editable layers (boxes, text, images, fonts) at their real positions. Pass url (for example http://localhost:5173/settings) when you know it. Without url, Playground finds the dev server this project is running and opens the page linked under the title (title "Settings" follows the app's Settings link). If no dev server is running, Playground starts it with the project's own dev script; if it can't, it says why. Pass blank: true only for an empty frame to sketch in. Pass mode: "live" to show the running app itself instead of a copy: the designer selects elements and changes spacing, type, colour and radius, and Playground writes each change to the code as Tailwind classes, which the dev server reloads. Live suits small fixes to a Tailwind app; the default copy suits trying layouts freely. Afterwards, call wait_for_handback: it pauses until the designer presses Hand back, then returns the exact changes, each with the source element (and React component and file when available) it came from.`,
|
|
29259
29363
|
inputSchema: z4.object({
|
|
29260
29364
|
title: z4.string().min(1).describe('Name of the screen, e.g. "Settings". Without url, the link with this name is opened'),
|
|
29261
29365
|
url: z4.string().url().optional().describe("The running page to import, e.g. http://localhost:5173/settings"),
|
|
@@ -29281,19 +29385,27 @@ function buildMcpServer(hub, showEditor = () => {
|
|
|
29281
29385
|
const h = height ?? 900;
|
|
29282
29386
|
let target = url;
|
|
29283
29387
|
let find;
|
|
29388
|
+
let started = "";
|
|
29284
29389
|
if (!target) {
|
|
29285
|
-
const
|
|
29286
|
-
if (
|
|
29390
|
+
const dev = hub.devServer ? await hub.devServer.ensure() : null;
|
|
29391
|
+
if (dev?.ok === false && dev.starting) {
|
|
29392
|
+
return text(
|
|
29393
|
+
`Playground is starting this project's dev server (\`${dev.command}\`) and it isn't serving yet. Call open_screen again in about 15 seconds. Don't start another one.`
|
|
29394
|
+
);
|
|
29395
|
+
}
|
|
29396
|
+
if (!dev?.ok) {
|
|
29287
29397
|
const cmd = await devCommand(hub.storage.root);
|
|
29398
|
+
const why = dev ? ` Playground tried to start it, but ${dev.reason}` : "";
|
|
29288
29399
|
hub.notify("error", `Couldn't open ${title}: this project's dev server isn't running.`, "open");
|
|
29289
29400
|
return {
|
|
29290
29401
|
...text(
|
|
29291
|
-
`Could not open "${title}": no dev server is running for this project (${hub.storage.root})
|
|
29402
|
+
`Could not open "${title}": no dev server is running for this project (${hub.storage.root}).${why} Fix that, or start it in the background${cmd ? ` (\`${cmd}\`)` : ""}, wait until it is ready, then call open_screen again. Pass url if the page is served from somewhere else.`
|
|
29292
29403
|
),
|
|
29293
29404
|
isError: true
|
|
29294
29405
|
};
|
|
29295
29406
|
}
|
|
29296
|
-
target =
|
|
29407
|
+
target = dev.server.url + "/";
|
|
29408
|
+
if (dev.started) started = `Playground started the dev server for this (${dev.server.url}); it keeps running until Playground stops, so don't start another. `;
|
|
29297
29409
|
find = title;
|
|
29298
29410
|
}
|
|
29299
29411
|
if (mode === "live") {
|
|
@@ -29301,7 +29413,7 @@ function buildMcpServer(hub, showEditor = () => {
|
|
|
29301
29413
|
const { session, live } = await hub.openLive(title, target);
|
|
29302
29414
|
hub.notify("success", `${who} opened ${title} live`, "open");
|
|
29303
29415
|
return text(
|
|
29304
|
-
`Opened ${live.url} live in Playground as "${title}", session ${session.id}. The designer sees the running app at desktop and phone widths. ` + (find ? `It opened on the app's first page; the designer can go to ${title} from there, or call open_screen again with its url. ` : "") + "Their edits are written to the code as they make them, where each element is styled (its Tailwind classes, CSS or SCSS rule, styled component or inline style), so keep the dev server running and leave those files alone until they hand back. " + next
|
|
29416
|
+
`Opened ${live.url} live in Playground as "${title}", session ${session.id}. The designer sees the running app at desktop and phone widths. ` + started + (find ? `It opened on the app's first page; the designer can go to ${title} from there, or call open_screen again with its url. ` : "") + "Their edits are written to the code as they make them, where each element is styled (its Tailwind classes, CSS or SCSS rule, styled component or inline style), so keep the dev server running and leave those files alone until they hand back. " + next
|
|
29305
29417
|
);
|
|
29306
29418
|
} catch (err) {
|
|
29307
29419
|
hub.notify("error", `Couldn't open ${title} live: ${err.message}`, "open");
|
|
@@ -29315,7 +29427,7 @@ function buildMcpServer(hub, showEditor = () => {
|
|
|
29315
29427
|
const frame = hub.doc.nodes[session.frameId];
|
|
29316
29428
|
const layers = imported.nodes.length - 1;
|
|
29317
29429
|
return text(
|
|
29318
|
-
`Imported ${imported.url} into Playground as "${title}" (${w}\xD7${Math.round(frame.h)}, ${layers} layers), session ${session.id}. The designer can see and edit it now. ` + (imported.notes.length ? `Notes: ${imported.notes.join(" ")} If this is not the right page, call open_screen again with its url. ` : "") + next
|
|
29430
|
+
`Imported ${imported.url} into Playground as "${title}" (${w}\xD7${Math.round(frame.h)}, ${layers} layers), session ${session.id}. The designer can see and edit it now. ` + started + (imported.notes.length ? `Notes: ${imported.notes.join(" ")} If this is not the right page, call open_screen again with its url. ` : "") + next
|
|
29319
29431
|
);
|
|
29320
29432
|
} catch (err) {
|
|
29321
29433
|
if (err instanceof LinkNotFound) {
|
|
@@ -29606,11 +29718,11 @@ ${html}`
|
|
|
29606
29718
|
placement: z4.enum(["top", "fill"]).optional().describe("On a frame: across the top, or covering the whole frame")
|
|
29607
29719
|
})
|
|
29608
29720
|
},
|
|
29609
|
-
async ({ node_id, path:
|
|
29721
|
+
async ({ node_id, path: path17, url, placement }) => {
|
|
29610
29722
|
touch();
|
|
29611
|
-
if (!
|
|
29723
|
+
if (!path17 && !url) return { ...text("Give a path or a url."), isError: true };
|
|
29612
29724
|
try {
|
|
29613
|
-
const r = await hub.placeAsset(node_id, { path:
|
|
29725
|
+
const r = await hub.placeAsset(node_id, { path: path17, url }, placement);
|
|
29614
29726
|
return text(r.message);
|
|
29615
29727
|
} catch (err) {
|
|
29616
29728
|
return { ...text(err.message), isError: true };
|
|
@@ -29713,6 +29825,10 @@ var Hub = class {
|
|
|
29713
29825
|
wakeGrace = WAKE_GRACE;
|
|
29714
29826
|
/** Playground's own agent, started when the designer needs one and no chat is listening. Set by the server. */
|
|
29715
29827
|
runner = null;
|
|
29828
|
+
/** Starts the project's dev server when a screen is opened and none is running. Set by the server. */
|
|
29829
|
+
devServer = null;
|
|
29830
|
+
/** Keeps live edits on a git branch of their own. Set by the server. */
|
|
29831
|
+
branch = null;
|
|
29716
29832
|
/** What Playground's agent is working on now: taken from the queue, given back if the run fails. */
|
|
29717
29833
|
running = [];
|
|
29718
29834
|
saveTimer = null;
|
|
@@ -29981,6 +30097,7 @@ var Hub = class {
|
|
|
29981
30097
|
codeEdits,
|
|
29982
30098
|
liveChanges,
|
|
29983
30099
|
...pictures.length ? { pictures } : {},
|
|
30100
|
+
...liveChanges && this.branch?.info()?.name ? { liveBranch: this.branch.info().name } : {},
|
|
29984
30101
|
...s.native ? { native: s.native } : {}
|
|
29985
30102
|
};
|
|
29986
30103
|
}
|
|
@@ -30013,6 +30130,7 @@ var Hub = class {
|
|
|
30013
30130
|
this.bg(this.storage.saveSession(this.session), "the session");
|
|
30014
30131
|
this.bg(this.storage.saveHandback(this.session.id, ev), "the hand back");
|
|
30015
30132
|
if (this.liveChanges.length) {
|
|
30133
|
+
void this.branch?.reset();
|
|
30016
30134
|
this.changesNow = [];
|
|
30017
30135
|
this.emitLive();
|
|
30018
30136
|
}
|
|
@@ -30037,8 +30155,8 @@ var Hub = class {
|
|
|
30037
30155
|
});
|
|
30038
30156
|
const how = this.deliver({ status: "request", sessionId: this.session.id, prompt, selection: items });
|
|
30039
30157
|
const who = this.agent.name ?? "your agent";
|
|
30040
|
-
const
|
|
30041
|
-
const message = how === "sent" ? `Sent to ${who}` : how === "woke" ? `Calling ${who} back\u2026` : how === "started" ? `${
|
|
30158
|
+
const run5 = this.runner?.name;
|
|
30159
|
+
const message = how === "sent" ? `Sent to ${who}` : how === "woke" ? `Calling ${who} back\u2026` : how === "started" ? `${run5} is on it` : how === "next" ? `${run5} takes it after what it's doing` : `Queued. ${cap(who)} isn't listening, so tell it in its chat to check Playground.`;
|
|
30042
30160
|
return { ok: true, message };
|
|
30043
30161
|
}
|
|
30044
30162
|
// ---------- drawn by the agent ----------
|
|
@@ -30458,16 +30576,22 @@ var Hub = class {
|
|
|
30458
30576
|
codeEdits: this.codeEdits,
|
|
30459
30577
|
live: this.live,
|
|
30460
30578
|
liveChanges: this.liveChanges,
|
|
30579
|
+
liveBranch: this.branch?.info() ?? null,
|
|
30461
30580
|
runner: this.runner?.info
|
|
30462
30581
|
};
|
|
30463
30582
|
}
|
|
30464
30583
|
// ---------- live frames ----------
|
|
30584
|
+
liveBranchChanged() {
|
|
30585
|
+
this.emitLive();
|
|
30586
|
+
}
|
|
30465
30587
|
emitLive() {
|
|
30466
|
-
this.emit({ type: "live", live: this.live, changes: this.liveChanges });
|
|
30588
|
+
this.emit({ type: "live", live: this.live, changes: this.liveChanges, branch: this.branch?.info() ?? null });
|
|
30467
30589
|
}
|
|
30468
30590
|
set changesNow(c) {
|
|
30469
30591
|
this.liveChanges = c;
|
|
30470
30592
|
this.bg(this.storage.saveLiveChanges(c), "the live changes");
|
|
30593
|
+
const title = (this.session?.title ?? this.live?.title ?? "").replace(/^\/+|\/+$/g, "") || "Live edits";
|
|
30594
|
+
if (this.branch) this.bg(this.branch.sync(title), "the branch");
|
|
30471
30595
|
if (c.length) this.reopenLive();
|
|
30472
30596
|
}
|
|
30473
30597
|
/** Open a handed-back session for more edits. The next hand back lists only what changes from here. */
|
|
@@ -30519,6 +30643,7 @@ var Hub = class {
|
|
|
30519
30643
|
this.queue = [];
|
|
30520
30644
|
this.session = this.newSession(title, "product", null, url);
|
|
30521
30645
|
this.setCodeEdits([]);
|
|
30646
|
+
void this.branch?.reset();
|
|
30522
30647
|
this.changesNow = [];
|
|
30523
30648
|
this.baseline = cloneDoc(this.doc);
|
|
30524
30649
|
this.bg(this.storage.saveSession(this.session, this.baseline), "the session");
|
|
@@ -30533,6 +30658,8 @@ var Hub = class {
|
|
|
30533
30658
|
*/
|
|
30534
30659
|
async writeLive(e) {
|
|
30535
30660
|
if (!this.sources) return { ok: false, reason: "Live edits are not available here." };
|
|
30661
|
+
const screen = e.screen ?? null;
|
|
30662
|
+
const cssOnly = { ok: false, reason: `This element is styled in CSS, so Playground can only change it for every size. Choose All sizes, or ask your agent to add a ${screen}: rule.` };
|
|
30536
30663
|
const rel = await this.sources.resolve(e.file);
|
|
30537
30664
|
if (!rel) return { ok: false, reason: `Playground can't find ${e.file} in this project.` };
|
|
30538
30665
|
const src = await this.sources.read(rel);
|
|
@@ -30541,15 +30668,16 @@ var Hub = class {
|
|
|
30541
30668
|
const name = e.site.name;
|
|
30542
30669
|
const tw = !!f?.className && await this.sources.usesTailwind();
|
|
30543
30670
|
if (!tw && !f?.style) return { ok: false, reason: `${name} doesn't pass className or style on to its outer element, so one ${name} can't change alone. Change every ${name}, or ask your agent to pass them on.` };
|
|
30544
|
-
|
|
30671
|
+
if (!tw && screen) return cssOnly;
|
|
30672
|
+
let next2 = e.next;
|
|
30545
30673
|
if (tw && (e.group === "padding" || e.group === "margin")) {
|
|
30546
30674
|
const siteRel = await this.sources.resolve(e.site.file);
|
|
30547
30675
|
const look = siteRel ? lookAt((await this.sources.read(siteRel)).text, e.site.line, name) : null;
|
|
30548
30676
|
const scale2 = await this.scale();
|
|
30549
|
-
const had = look?.ok ? look.look.classes.filter((c) => !c.conditional
|
|
30550
|
-
|
|
30677
|
+
const had = look?.ok ? look.look.classes.filter((c) => !c.conditional).flatMap((c) => atScreen(c.word, screen) ?? []).filter((w2) => inGroup(w2, e.group, scale2)) : [];
|
|
30678
|
+
next2 = mergeSideClasses(had, e.next);
|
|
30551
30679
|
}
|
|
30552
|
-
return this.writeLive({ ...e, next, file: e.site.file, line: e.site.line, tag: name, component: name, site: void 0, shared: void 0, instance: tw ? "tailwind" : "inline" });
|
|
30680
|
+
return this.writeLive({ ...e, next: next2, file: e.site.file, line: e.site.line, tag: name, component: name, site: void 0, shared: void 0, instance: tw ? "tailwind" : "inline" });
|
|
30553
30681
|
}
|
|
30554
30682
|
const scale = await this.scale();
|
|
30555
30683
|
const instanceNote = e.instance ? `Only this ${e.tag}, where this file uses it; ${e.tag} itself is unchanged.` : void 0;
|
|
@@ -30559,6 +30687,7 @@ var Hub = class {
|
|
|
30559
30687
|
const at = e.instance === "inline" ? { ok: true, place: { how: "inline" } } : await this.styleWriter().place(rel, src.text, e.line, e.tag, e.group, scale);
|
|
30560
30688
|
if (!at.ok) return at;
|
|
30561
30689
|
if (at.place.how !== "tailwind") {
|
|
30690
|
+
if (screen) return cssOnly;
|
|
30562
30691
|
const r4 = await this.styleWriter().write({ file: rel, text: src.text, version: src.version, line: e.line, tag: e.tag, group: e.group, css: e.css, fontSize: e.fontSize }, at.place);
|
|
30563
30692
|
if (!r4.ok) return r4;
|
|
30564
30693
|
if (r4.how === "tailwind") return { ok: false, reason: "Playground couldn\u2019t write that edit." };
|
|
@@ -30600,19 +30729,27 @@ var Hub = class {
|
|
|
30600
30729
|
return { ok: true, change: change2, how: r4.how };
|
|
30601
30730
|
}
|
|
30602
30731
|
}
|
|
30603
|
-
|
|
30732
|
+
let next = e.next;
|
|
30733
|
+
if (screen && !e.instance && (e.group === "padding" || e.group === "margin")) {
|
|
30734
|
+
const look = lookAt(src.text, e.line, e.tag);
|
|
30735
|
+
const had = look.ok ? look.look.classes.filter((c) => !c.conditional).flatMap((c) => atScreen(c.word, screen) ?? []).filter((w2) => inGroup(w2, e.group, scale)) : [];
|
|
30736
|
+
next = mergeSideClasses(had, e.next);
|
|
30737
|
+
}
|
|
30738
|
+
const r = writeClasses(src.text, e.line, e.tag, e.group, next, scale, screen);
|
|
30604
30739
|
if (!r.ok) return r;
|
|
30605
30740
|
const note = instanceNote ?? ([r.note, sharedNote].filter(Boolean).join(" ") || void 0);
|
|
30606
30741
|
if (r.text === src.text) return { ok: true, change: null, how: "tailwind" };
|
|
30607
30742
|
const w = await this.sources.write(rel, r.text, src.version);
|
|
30608
30743
|
if (!w.ok) return { ok: false, reason: "The file changed on disk while Playground was writing. Try again." };
|
|
30609
|
-
const prevGroup = r.before.split(/\s+/).
|
|
30610
|
-
const same2 = this.liveChanges.find(
|
|
30744
|
+
const prevGroup = r.before.split(/\s+/).flatMap((c) => c && atScreen(c, screen) || []).filter((c) => inGroup(c, e.group, scale));
|
|
30745
|
+
const same2 = this.liveChanges.find(
|
|
30746
|
+
(c) => c.file === rel && c.line === e.line && c.group === e.group && c.tag === e.tag && (c.how ?? "tailwind") === "tailwind" && (c.screen ?? null) === screen
|
|
30747
|
+
);
|
|
30611
30748
|
let change;
|
|
30612
30749
|
if (same2) {
|
|
30613
|
-
const back = same2.prev.join(" ") ===
|
|
30750
|
+
const back = same2.prev.join(" ") === next.join(" ");
|
|
30614
30751
|
this.changesNow = this.liveChanges.filter((c) => c !== same2);
|
|
30615
|
-
change = back ? null : { ...same2, to: e.to, after: r.after, next
|
|
30752
|
+
change = back ? null : { ...same2, to: e.to, after: r.after, next, at: (/* @__PURE__ */ new Date()).toISOString(), ...note ? { note } : {} };
|
|
30616
30753
|
} else {
|
|
30617
30754
|
change = {
|
|
30618
30755
|
id: newId("lc"),
|
|
@@ -30627,14 +30764,15 @@ var Hub = class {
|
|
|
30627
30764
|
group: e.group,
|
|
30628
30765
|
tag: e.tag,
|
|
30629
30766
|
prev: prevGroup,
|
|
30630
|
-
next
|
|
30767
|
+
next,
|
|
30631
30768
|
at: (/* @__PURE__ */ new Date()).toISOString(),
|
|
30632
30769
|
...scope,
|
|
30633
|
-
...note ? { note } : {}
|
|
30770
|
+
...note ? { note } : {},
|
|
30771
|
+
...screen ? { screen } : {}
|
|
30634
30772
|
};
|
|
30635
30773
|
}
|
|
30636
30774
|
if (change) this.changesNow = [...this.liveChanges, change];
|
|
30637
|
-
this.log(`live: ${rel}:${e.line} ${e.what} ${e.from} \u2192 ${e.to}`);
|
|
30775
|
+
this.log(`live: ${rel}:${e.line} ${e.what} ${e.from} \u2192 ${e.to}${screen ? ` (${screen}: and up)` : ""}`);
|
|
30638
30776
|
this.emitLive();
|
|
30639
30777
|
return { ok: true, change, how: "tailwind" };
|
|
30640
30778
|
}
|
|
@@ -30714,6 +30852,15 @@ var Hub = class {
|
|
|
30714
30852
|
this.emitLive();
|
|
30715
30853
|
return { ok: true, change };
|
|
30716
30854
|
}
|
|
30855
|
+
/** What Playground changed in each file this batch, for the tray's Review. */
|
|
30856
|
+
liveDiff() {
|
|
30857
|
+
return this.branch ? this.branch.diff() : Promise.resolve([]);
|
|
30858
|
+
}
|
|
30859
|
+
/** Push the branch and open a pull request, or update the open one. */
|
|
30860
|
+
openLivePr() {
|
|
30861
|
+
if (!this.branch) return Promise.resolve({ ok: false, message: "There\u2019s no branch for these edits." });
|
|
30862
|
+
return this.branch.openPr(this.liveChanges);
|
|
30863
|
+
}
|
|
30717
30864
|
/** Put one live edit's classes back as they were. */
|
|
30718
30865
|
async revertLive(id) {
|
|
30719
30866
|
const c = this.liveChanges.find((x) => x.id === id);
|
|
@@ -30738,7 +30885,7 @@ var Hub = class {
|
|
|
30738
30885
|
return { ok: true, message: `Reverted ${c.what} in ${(c.target?.file ?? c.file).split("/").pop()}` };
|
|
30739
30886
|
}
|
|
30740
30887
|
const src = await this.sources.read(c.file);
|
|
30741
|
-
const r = writeClasses(src.text, c.line, c.tag, c.group, c.prev, await this.scale());
|
|
30888
|
+
const r = writeClasses(src.text, c.line, c.tag, c.group, c.prev, await this.scale(), c.screen && c.screen in TW_SCREENS ? c.screen : null);
|
|
30742
30889
|
if (!r.ok) return { ok: false, message: r.reason };
|
|
30743
30890
|
const text2 = c.before === "" ? dropEmptyClassName(r.text, c.line, c.tag) : r.text;
|
|
30744
30891
|
if (text2 !== src.text) {
|
|
@@ -30791,10 +30938,10 @@ var Hub = class {
|
|
|
30791
30938
|
};
|
|
30792
30939
|
|
|
30793
30940
|
// ../daemon/src/runner.ts
|
|
30794
|
-
import { spawn as
|
|
30941
|
+
import { spawn as spawn3 } from "node:child_process";
|
|
30795
30942
|
import { randomUUID } from "node:crypto";
|
|
30796
30943
|
import { accessSync, constants, createWriteStream } from "node:fs";
|
|
30797
|
-
import { mkdir as
|
|
30944
|
+
import { mkdir as mkdir4, readFile as readFile5, writeFile as writeFile3 } from "node:fs/promises";
|
|
30798
30945
|
import path9 from "node:path";
|
|
30799
30946
|
var RUNNER_HEADER = "x-pg-runner";
|
|
30800
30947
|
var NAMES = { claude: "Claude Code", codex: "Codex" };
|
|
@@ -30900,7 +31047,7 @@ var Runner = class {
|
|
|
30900
31047
|
await this.save();
|
|
30901
31048
|
}
|
|
30902
31049
|
async save() {
|
|
30903
|
-
await
|
|
31050
|
+
await mkdir4(path9.dirname(this.file), { recursive: true });
|
|
30904
31051
|
await writeFile3(this.file, JSON.stringify(this.settings, null, 2) + "\n");
|
|
30905
31052
|
}
|
|
30906
31053
|
set(p) {
|
|
@@ -30980,7 +31127,7 @@ ${task}
|
|
|
30980
31127
|
} catch {
|
|
30981
31128
|
log = null;
|
|
30982
31129
|
}
|
|
30983
|
-
const child =
|
|
31130
|
+
const child = spawn3(bin, args, { cwd: this.root, env, stdio: ["pipe", "pipe", "pipe"] });
|
|
30984
31131
|
this.child = child;
|
|
30985
31132
|
this.stopped = false;
|
|
30986
31133
|
this.set({ running: true, activity: "Starting", last: this.info.last });
|
|
@@ -31114,8 +31261,8 @@ function plain(text2) {
|
|
|
31114
31261
|
}
|
|
31115
31262
|
|
|
31116
31263
|
// ../daemon/src/storage.ts
|
|
31117
|
-
import { mkdir as
|
|
31118
|
-
import { existsSync as
|
|
31264
|
+
import { mkdir as mkdir5, readFile as readFile6, rename, rm as rm2, writeFile as writeFile4 } from "node:fs/promises";
|
|
31265
|
+
import { existsSync as existsSync5 } from "node:fs";
|
|
31119
31266
|
import path10 from "node:path";
|
|
31120
31267
|
var tmpCounter = 0;
|
|
31121
31268
|
var Storage = class {
|
|
@@ -31139,7 +31286,7 @@ var Storage = class {
|
|
|
31139
31286
|
const prev = this.chains.get(file) ?? Promise.resolve();
|
|
31140
31287
|
const next = prev.catch(() => {
|
|
31141
31288
|
}).then(async () => {
|
|
31142
|
-
await
|
|
31289
|
+
await mkdir5(path10.dirname(file), { recursive: true });
|
|
31143
31290
|
await this.ignoreSelf();
|
|
31144
31291
|
const tmp = `${file}.${process.pid}.${++tmpCounter}.tmp`;
|
|
31145
31292
|
await writeFile4(tmp, body);
|
|
@@ -31158,14 +31305,14 @@ var Storage = class {
|
|
|
31158
31305
|
if (this.ignored) return;
|
|
31159
31306
|
this.ignored = true;
|
|
31160
31307
|
const f = this.file(".gitignore");
|
|
31161
|
-
if (!
|
|
31162
|
-
await
|
|
31308
|
+
if (!existsSync5(f)) {
|
|
31309
|
+
await mkdir5(this.dir, { recursive: true });
|
|
31163
31310
|
await writeFile4(f, "# Playground design sessions: local to this machine.\n*\n").catch(() => {
|
|
31164
31311
|
});
|
|
31165
31312
|
}
|
|
31166
31313
|
}
|
|
31167
31314
|
async readJson(file) {
|
|
31168
|
-
if (!
|
|
31315
|
+
if (!existsSync5(file)) return null;
|
|
31169
31316
|
try {
|
|
31170
31317
|
return JSON.parse(await readFile6(file, "utf8"));
|
|
31171
31318
|
} catch {
|
|
@@ -31241,7 +31388,7 @@ var Storage = class {
|
|
|
31241
31388
|
};
|
|
31242
31389
|
|
|
31243
31390
|
// ../daemon/src/source.ts
|
|
31244
|
-
import { execFile as execFile3, spawn as
|
|
31391
|
+
import { execFile as execFile3, spawn as spawn4 } from "node:child_process";
|
|
31245
31392
|
import { createHash as createHash3 } from "node:crypto";
|
|
31246
31393
|
import { access, readdir as readdir2, readFile as readFile7, realpath as realpath2, stat as stat3, writeFile as writeFile5 } from "node:fs/promises";
|
|
31247
31394
|
import path11 from "node:path";
|
|
@@ -31270,6 +31417,8 @@ var Sources = class {
|
|
|
31270
31417
|
files = null;
|
|
31271
31418
|
vocab = null;
|
|
31272
31419
|
editor = null;
|
|
31420
|
+
/** Told each file's text just before it is written. */
|
|
31421
|
+
onWrite = null;
|
|
31273
31422
|
/** Every source file, relative to the root. Cached for a few seconds. */
|
|
31274
31423
|
list() {
|
|
31275
31424
|
if (this.files && Date.now() - this.files.at < 5e3) return this.files.list;
|
|
@@ -31369,6 +31518,7 @@ var Sources = class {
|
|
|
31369
31518
|
const abs = await this.abs(rel);
|
|
31370
31519
|
const now = await readFile7(abs, "utf8");
|
|
31371
31520
|
if (hash(now) !== version) return { ok: false, conflict: { file: rel, text: now, version: hash(now) } };
|
|
31521
|
+
this.onWrite?.(rel, now);
|
|
31372
31522
|
await writeFile5(abs, text2, "utf8");
|
|
31373
31523
|
this.vocab = null;
|
|
31374
31524
|
return { ok: true, version: hash(text2) };
|
|
@@ -31426,7 +31576,7 @@ var Sources = class {
|
|
|
31426
31576
|
const abs = await this.abs(rel);
|
|
31427
31577
|
const at = Number.isFinite(line) && line > 0 ? Math.floor(line) : 1;
|
|
31428
31578
|
const e = await this.findEditor();
|
|
31429
|
-
const go = (cmd, args) =>
|
|
31579
|
+
const go = (cmd, args) => spawn4(cmd, args, { stdio: "ignore", detached: true }).unref();
|
|
31430
31580
|
if (process.platform === "darwin") {
|
|
31431
31581
|
go("open", [e ? e.url(abs, at) : abs]);
|
|
31432
31582
|
} else if (e) {
|
|
@@ -31438,6 +31588,285 @@ var Sources = class {
|
|
|
31438
31588
|
}
|
|
31439
31589
|
};
|
|
31440
31590
|
|
|
31591
|
+
// ../daemon/src/branch.ts
|
|
31592
|
+
import { spawn as spawn5 } from "node:child_process";
|
|
31593
|
+
import { mkdtemp as mkdtemp2, readFile as readFile8, realpath as realpath3, rm as rm3, writeFile as writeFile6 } from "node:fs/promises";
|
|
31594
|
+
import { tmpdir as tmpdir2 } from "node:os";
|
|
31595
|
+
import path12 from "node:path";
|
|
31596
|
+
function run4(cmd, args, cwd, opts = {}) {
|
|
31597
|
+
return new Promise((resolve2) => {
|
|
31598
|
+
const child = spawn5(cmd, args, { cwd, env: { ...process.env, ...opts.env, GIT_TERMINAL_PROMPT: "0" }, stdio: ["pipe", "pipe", "pipe"] });
|
|
31599
|
+
let out = "";
|
|
31600
|
+
let err = "";
|
|
31601
|
+
child.stdout.on("data", (d) => out += d);
|
|
31602
|
+
child.stderr.on("data", (d) => err += d);
|
|
31603
|
+
child.on("error", (e) => resolve2({ code: 127, out, err: e.message }));
|
|
31604
|
+
child.on("close", (code) => resolve2({ code: code ?? 1, out, err }));
|
|
31605
|
+
child.stdin.end(opts.input ?? "");
|
|
31606
|
+
});
|
|
31607
|
+
}
|
|
31608
|
+
var slug = (s) => s.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 40).replace(/-+$/, "") || "edits";
|
|
31609
|
+
var LiveBranch = class {
|
|
31610
|
+
constructor(root2, file, host) {
|
|
31611
|
+
this.root = root2;
|
|
31612
|
+
this.file = file;
|
|
31613
|
+
this.host = host;
|
|
31614
|
+
}
|
|
31615
|
+
root;
|
|
31616
|
+
file;
|
|
31617
|
+
host;
|
|
31618
|
+
state = null;
|
|
31619
|
+
/** Snapshots taken before a branch exists: the first write comes before the first sync. */
|
|
31620
|
+
pending = {};
|
|
31621
|
+
chain = Promise.resolve();
|
|
31622
|
+
top = null;
|
|
31623
|
+
/** The project folder as git sees it: macOS reports /private/var for /var. */
|
|
31624
|
+
real = "";
|
|
31625
|
+
why = null;
|
|
31626
|
+
busy = false;
|
|
31627
|
+
async load() {
|
|
31628
|
+
try {
|
|
31629
|
+
this.state = JSON.parse(await readFile8(this.file, "utf8"));
|
|
31630
|
+
} catch {
|
|
31631
|
+
this.state = null;
|
|
31632
|
+
}
|
|
31633
|
+
}
|
|
31634
|
+
save() {
|
|
31635
|
+
const s = this.state;
|
|
31636
|
+
return (s ? writeFile6(this.file, JSON.stringify(s)) : rm3(this.file, { force: true })).catch(() => {
|
|
31637
|
+
});
|
|
31638
|
+
}
|
|
31639
|
+
/** One git job at a time, in order. */
|
|
31640
|
+
queue(job) {
|
|
31641
|
+
const next = this.chain.then(job, job);
|
|
31642
|
+
this.chain = next.catch(() => {
|
|
31643
|
+
});
|
|
31644
|
+
return next;
|
|
31645
|
+
}
|
|
31646
|
+
git(args, opts) {
|
|
31647
|
+
return run4("git", args, this.top ?? this.root, opts);
|
|
31648
|
+
}
|
|
31649
|
+
info() {
|
|
31650
|
+
if (this.why) return { name: null, unavailable: this.why, files: [], pr: null, ahead: false, busy: false };
|
|
31651
|
+
const s = this.state;
|
|
31652
|
+
if (!s) return null;
|
|
31653
|
+
return { name: s.name, files: s.files, pr: s.pr ? { url: s.pr.url } : null, ahead: !!s.pr && s.tip !== s.pr.pushed, busy: this.busy };
|
|
31654
|
+
}
|
|
31655
|
+
/** Called with a file's text just before Playground writes it. */
|
|
31656
|
+
remember(rel, text2) {
|
|
31657
|
+
const snaps = this.state?.snapshots ?? this.pending;
|
|
31658
|
+
if (!(rel in snaps)) snaps[rel] = text2;
|
|
31659
|
+
}
|
|
31660
|
+
/** The next live edits go on a new branch. The current one stays as it is. */
|
|
31661
|
+
reset() {
|
|
31662
|
+
return this.queue(async () => {
|
|
31663
|
+
this.state = null;
|
|
31664
|
+
this.pending = {};
|
|
31665
|
+
await this.save();
|
|
31666
|
+
this.host.changed();
|
|
31667
|
+
});
|
|
31668
|
+
}
|
|
31669
|
+
/** Bring the branch up to date with the files after a live edit or revert. */
|
|
31670
|
+
sync(title) {
|
|
31671
|
+
return this.queue(() => this.doSync(title));
|
|
31672
|
+
}
|
|
31673
|
+
/** Whether this project can have a branch: inside a git repo with at least one commit. */
|
|
31674
|
+
async repo() {
|
|
31675
|
+
if (this.top) return true;
|
|
31676
|
+
const top = await run4("git", ["rev-parse", "--show-toplevel"], this.root);
|
|
31677
|
+
if (top.code !== 0) {
|
|
31678
|
+
this.why = top.code === 127 ? "Git isn\u2019t installed, so there\u2019s no branch." : "This project isn\u2019t a git repository, so there\u2019s no branch.";
|
|
31679
|
+
return false;
|
|
31680
|
+
}
|
|
31681
|
+
this.top = top.out.trim();
|
|
31682
|
+
this.real = await realpath3(this.root).catch(() => this.root);
|
|
31683
|
+
const head = await this.git(["rev-parse", "--verify", "--quiet", "HEAD"]);
|
|
31684
|
+
if (head.code !== 0) {
|
|
31685
|
+
this.top = null;
|
|
31686
|
+
this.why = "This repository has no commits yet, so there\u2019s no branch.";
|
|
31687
|
+
return false;
|
|
31688
|
+
}
|
|
31689
|
+
this.why = null;
|
|
31690
|
+
return true;
|
|
31691
|
+
}
|
|
31692
|
+
repoPath(rel) {
|
|
31693
|
+
return path12.relative(this.top, path12.join(this.real, rel)).split(path12.sep).join("/");
|
|
31694
|
+
}
|
|
31695
|
+
async show(rev, rel) {
|
|
31696
|
+
const r = await this.git(["show", `${rev}:${this.repoPath(rel)}`]);
|
|
31697
|
+
return r.code === 0 ? r.out : null;
|
|
31698
|
+
}
|
|
31699
|
+
async now(rel) {
|
|
31700
|
+
return readFile8(path12.join(this.root, rel), "utf8").catch(() => null);
|
|
31701
|
+
}
|
|
31702
|
+
/** The base commit's text with Playground's edits (snapshot → now) laid on top: none of the designer's own changes. */
|
|
31703
|
+
async onBase(baseText, snap, now) {
|
|
31704
|
+
if (baseText === null || baseText === snap) return now;
|
|
31705
|
+
const dir = await mkdtemp2(path12.join(tmpdir2(), "pg-merge-"));
|
|
31706
|
+
try {
|
|
31707
|
+
const [a, o, b] = ["f", "snap", "now"].map((n) => path12.join(dir, n));
|
|
31708
|
+
await Promise.all([writeFile6(a, baseText), writeFile6(o, snap), writeFile6(b, now)]);
|
|
31709
|
+
const d = await run4("git", ["diff", "--no-index", "--no-color", "-U0", o, b], dir);
|
|
31710
|
+
const at = d.out.indexOf("\n@@");
|
|
31711
|
+
if (at >= 0) {
|
|
31712
|
+
await writeFile6(path12.join(dir, "p.diff"), `--- a/f
|
|
31713
|
+
+++ b/f
|
|
31714
|
+
${d.out.slice(at + 1)}`);
|
|
31715
|
+
const r = await run4("git", ["apply", "--unidiff-zero", "p.diff"], dir);
|
|
31716
|
+
if (r.code === 0) return await readFile8(a, "utf8");
|
|
31717
|
+
}
|
|
31718
|
+
await writeFile6(a, baseText);
|
|
31719
|
+
const m = await run4("git", ["merge-file", "-p", a, o, b], dir);
|
|
31720
|
+
return m.code === 0 ? m.out : now;
|
|
31721
|
+
} finally {
|
|
31722
|
+
await rm3(dir, { recursive: true, force: true });
|
|
31723
|
+
}
|
|
31724
|
+
}
|
|
31725
|
+
async unique(title) {
|
|
31726
|
+
const d = /* @__PURE__ */ new Date();
|
|
31727
|
+
const pad = (n) => String(n).padStart(2, "0");
|
|
31728
|
+
const stem = `playground/${slug(title)}-${pad(d.getMonth() + 1)}${pad(d.getDate())}-${pad(d.getHours())}${pad(d.getMinutes())}`;
|
|
31729
|
+
for (let i = 1; ; i++) {
|
|
31730
|
+
const name = i === 1 ? stem : `${stem}-${i}`;
|
|
31731
|
+
if ((await this.git(["rev-parse", "--verify", "--quiet", `refs/heads/${name}`])).code !== 0) return name;
|
|
31732
|
+
}
|
|
31733
|
+
}
|
|
31734
|
+
async doSync(title) {
|
|
31735
|
+
if (!this.state && !Object.keys(this.pending).length) return;
|
|
31736
|
+
if (!await this.repo()) return this.host.changed();
|
|
31737
|
+
if (!this.state) {
|
|
31738
|
+
const base2 = (await this.git(["rev-parse", "HEAD"])).out.trim();
|
|
31739
|
+
const up = await this.git(["rev-parse", "--abbrev-ref", "--symbolic-full-name", "@{u}"]);
|
|
31740
|
+
this.state = { name: await this.unique(title), base: base2, upstream: up.code === 0 ? up.out.trim() : null, title, snapshots: this.pending, files: [], pr: null, tip: null };
|
|
31741
|
+
this.pending = {};
|
|
31742
|
+
}
|
|
31743
|
+
const s = this.state;
|
|
31744
|
+
const entries = [];
|
|
31745
|
+
const changed = [];
|
|
31746
|
+
for (const [rel, snap] of Object.entries(s.snapshots)) {
|
|
31747
|
+
const baseText = await this.show(s.base, rel);
|
|
31748
|
+
const now = await this.now(rel);
|
|
31749
|
+
const text2 = now === null || now === snap ? baseText : await this.onBase(baseText, snap, now);
|
|
31750
|
+
entries.push({ file: rel, text: text2 });
|
|
31751
|
+
if (text2 !== baseText) changed.push(rel);
|
|
31752
|
+
}
|
|
31753
|
+
if (!changed.length && !s.pr) {
|
|
31754
|
+
await this.git(["update-ref", "-d", `refs/heads/${s.name}`]);
|
|
31755
|
+
this.state = null;
|
|
31756
|
+
await this.save();
|
|
31757
|
+
return this.host.changed();
|
|
31758
|
+
}
|
|
31759
|
+
const parent = s.pr ? s.pr.pushed : s.base;
|
|
31760
|
+
const dir = await mkdtemp2(path12.join(tmpdir2(), "pg-index-"));
|
|
31761
|
+
const env = { GIT_INDEX_FILE: path12.join(dir, "index") };
|
|
31762
|
+
try {
|
|
31763
|
+
await this.git(["read-tree", parent], { env });
|
|
31764
|
+
for (const e of entries) {
|
|
31765
|
+
const p = this.repoPath(e.file);
|
|
31766
|
+
if (e.text === null) {
|
|
31767
|
+
await this.git(["update-index", "--force-remove", "--", p], { env });
|
|
31768
|
+
continue;
|
|
31769
|
+
}
|
|
31770
|
+
const sha = (await this.git(["hash-object", "-w", "--stdin"], { input: e.text })).out.trim();
|
|
31771
|
+
const mode = (await this.git(["ls-tree", s.base, "--", p])).out.split(/\s/)[0] || "100644";
|
|
31772
|
+
await this.git(["update-index", "--add", "--cacheinfo", `${mode},${sha},${p}`], { env });
|
|
31773
|
+
}
|
|
31774
|
+
const tree = (await this.git(["write-tree"], { env })).out.trim();
|
|
31775
|
+
const parentTree = (await this.git(["rev-parse", `${parent}^{tree}`])).out.trim();
|
|
31776
|
+
if (tree === parentTree && s.pr) {
|
|
31777
|
+
s.tip = s.pr.pushed;
|
|
31778
|
+
} else if (!s.tip || (await this.git(["rev-parse", `${s.tip}^{tree}`])).out.trim() !== tree) {
|
|
31779
|
+
const who = await this.git(["config", "user.email"]);
|
|
31780
|
+
const author = who.code === 0 && who.out.trim() ? {} : { GIT_AUTHOR_NAME: "Playground", GIT_AUTHOR_EMAIL: "playground@localhost", GIT_COMMITTER_NAME: "Playground", GIT_COMMITTER_EMAIL: "playground@localhost" };
|
|
31781
|
+
const msg = `Design changes: ${s.title}
|
|
31782
|
+
|
|
31783
|
+
Made by hand in Playground's live frames.`;
|
|
31784
|
+
const c = await this.git(["commit-tree", tree, "-p", parent, "-m", msg], { env: author });
|
|
31785
|
+
if (c.code !== 0) throw new Error(c.err.trim() || "git couldn\u2019t make the commit");
|
|
31786
|
+
s.tip = c.out.trim();
|
|
31787
|
+
await this.git(["update-ref", `refs/heads/${s.name}`, s.tip]);
|
|
31788
|
+
}
|
|
31789
|
+
s.files = changed;
|
|
31790
|
+
await this.save();
|
|
31791
|
+
} catch (err) {
|
|
31792
|
+
this.host.log(`live branch: ${err.message}`);
|
|
31793
|
+
} finally {
|
|
31794
|
+
await rm3(dir, { recursive: true, force: true });
|
|
31795
|
+
}
|
|
31796
|
+
this.host.changed();
|
|
31797
|
+
}
|
|
31798
|
+
/** What Playground changed in each file, as unified diff hunks. */
|
|
31799
|
+
diff() {
|
|
31800
|
+
return this.queue(async () => {
|
|
31801
|
+
const snaps = { ...this.pending, ...this.state?.snapshots };
|
|
31802
|
+
const out = [];
|
|
31803
|
+
const dir = await mkdtemp2(path12.join(tmpdir2(), "pg-diff-"));
|
|
31804
|
+
try {
|
|
31805
|
+
for (const [rel, snap] of Object.entries(snaps)) {
|
|
31806
|
+
const now = await this.now(rel) ?? "";
|
|
31807
|
+
if (now === snap) continue;
|
|
31808
|
+
const a = path12.join(dir, "before");
|
|
31809
|
+
const b = path12.join(dir, "after");
|
|
31810
|
+
await Promise.all([writeFile6(a, snap), writeFile6(b, now)]);
|
|
31811
|
+
const r = await run4("git", ["diff", "--no-index", "--no-color", "-U3", a, b], dir);
|
|
31812
|
+
const at = r.out.indexOf("\n@@");
|
|
31813
|
+
if (at >= 0) out.push({ file: rel, patch: r.out.slice(at + 1) });
|
|
31814
|
+
}
|
|
31815
|
+
} finally {
|
|
31816
|
+
await rm3(dir, { recursive: true, force: true });
|
|
31817
|
+
}
|
|
31818
|
+
return out;
|
|
31819
|
+
});
|
|
31820
|
+
}
|
|
31821
|
+
/** Push the branch and open a pull request with gh, or push the new edits to the one already open. */
|
|
31822
|
+
openPr(changes) {
|
|
31823
|
+
return this.queue(async () => {
|
|
31824
|
+
const s = this.state;
|
|
31825
|
+
if (!s?.tip || !s.files.length) return { ok: false, message: "There are no edits on the branch to put in a pull request." };
|
|
31826
|
+
const remotes = (await this.git(["remote"])).out.split("\n").filter(Boolean);
|
|
31827
|
+
const remote = remotes.includes("origin") ? "origin" : remotes[0];
|
|
31828
|
+
const branch = `refs/heads/${s.name}`;
|
|
31829
|
+
const commands = (r) => `git push ${r} ${s.name}
|
|
31830
|
+
gh pr create --head ${s.name}`;
|
|
31831
|
+
if (!remote) return { ok: false, message: "This repository has no remote to push the branch to. Add one, then try again." };
|
|
31832
|
+
const gh = process.env.PG_GH || findOnPath("gh");
|
|
31833
|
+
if (!gh) return { ok: false, message: `GitHub\u2019s gh command isn\u2019t installed. Install it, or run:
|
|
31834
|
+
${commands(remote)}` };
|
|
31835
|
+
if (!s.pr && (await run4(gh, ["auth", "status"], this.top)).code !== 0) {
|
|
31836
|
+
return { ok: false, message: `gh isn\u2019t signed in. Run gh auth login, then try again, or run:
|
|
31837
|
+
${commands(remote)}` };
|
|
31838
|
+
}
|
|
31839
|
+
if (s.pr && s.tip === s.pr.pushed) return { ok: true, url: s.pr.url, message: "The pull request is up to date." };
|
|
31840
|
+
this.busy = true;
|
|
31841
|
+
this.host.changed();
|
|
31842
|
+
try {
|
|
31843
|
+
const push = await this.git(["push", remote, `${branch}:${branch}`]);
|
|
31844
|
+
if (push.code !== 0) return { ok: false, message: `git couldn\u2019t push the branch: ${push.err.trim().split("\n").pop()}` };
|
|
31845
|
+
if (s.pr) {
|
|
31846
|
+
s.pr.pushed = s.tip;
|
|
31847
|
+
await this.save();
|
|
31848
|
+
return { ok: true, url: s.pr.url, message: "Pushed the new edits to the pull request." };
|
|
31849
|
+
}
|
|
31850
|
+
const [upRemote, ...upBranch] = (s.upstream ?? "").split("/");
|
|
31851
|
+
const base2 = upRemote === remote && upBranch.length ? ["--base", upBranch.join("/")] : [];
|
|
31852
|
+
const list3 = changes.map((c) => `- ${c.component || c.tag} \xB7 ${c.what}${c.screen ? ` (${c.screen}: and up)` : ""}: ${c.from} \u2192 ${c.to} (\`${c.file}:${c.line}\`)`);
|
|
31853
|
+
const body = [`Design changes made by hand in Playground's live frames on "${s.title}".`, "", ...list3, "", "Only Playground\u2019s edits are on this branch."].join("\n");
|
|
31854
|
+
const pr = await run4(gh, ["pr", "create", "--head", s.name, "--title", `Design changes: ${s.title}`, "--body", body, ...base2], this.top);
|
|
31855
|
+
const url = pr.out.split("\n").map((l) => l.trim()).filter((l) => /^https?:\/\//.test(l)).pop();
|
|
31856
|
+
if (pr.code !== 0 || !url) return { ok: false, message: `gh couldn\u2019t open the pull request: ${(pr.err || pr.out).trim().split("\n").pop()}` };
|
|
31857
|
+
s.pr = { url, pushed: s.tip };
|
|
31858
|
+
await this.save();
|
|
31859
|
+
const unpushed = Number((await this.git(["rev-list", "--count", s.base, "--not", `--remotes=${remote}`])).out.trim()) || 0;
|
|
31860
|
+
const note = unpushed ? ` It also has ${unpushed} commit${unpushed === 1 ? "" : "s"} of yours that weren\u2019t pushed before.` : "";
|
|
31861
|
+
return { ok: true, url, message: `Opened the pull request.${note}` };
|
|
31862
|
+
} finally {
|
|
31863
|
+
this.busy = false;
|
|
31864
|
+
this.host.changed();
|
|
31865
|
+
}
|
|
31866
|
+
});
|
|
31867
|
+
}
|
|
31868
|
+
};
|
|
31869
|
+
|
|
31441
31870
|
// ../daemon/src/server.ts
|
|
31442
31871
|
var GROUPS = /* @__PURE__ */ new Set(["padding", "margin", "gap", "width", "height", "font-size", "font-weight", "leading", "tracking", "radius", "bg", "text-color", "border-color", "opacity"]);
|
|
31443
31872
|
var MIME = {
|
|
@@ -31495,7 +31924,7 @@ async function startDaemon(opts) {
|
|
|
31495
31924
|
hub.origin = `http://127.0.0.1:${port2}`;
|
|
31496
31925
|
await hub.load();
|
|
31497
31926
|
if (opts.runner ?? !process.env.PG_NO_RUNNER) {
|
|
31498
|
-
const runner = new Runner(
|
|
31927
|
+
const runner = new Runner(path13.join(storage.dir, "agent.json"), opts.root, {
|
|
31499
31928
|
mcpUrl: () => `http://127.0.0.1:${port2}/mcp`,
|
|
31500
31929
|
changed: (info) => hub.runnerChanged(info),
|
|
31501
31930
|
ended: (ok2, stopped) => hub.runEnded(ok2, stopped),
|
|
@@ -31504,8 +31933,15 @@ async function startDaemon(opts) {
|
|
|
31504
31933
|
await runner.load();
|
|
31505
31934
|
hub.runner = runner;
|
|
31506
31935
|
}
|
|
31936
|
+
const branch = new LiveBranch(opts.root, path13.join(storage.dir, "branch.json"), { changed: () => hub.liveBranchChanged(), log });
|
|
31937
|
+
await branch.load();
|
|
31938
|
+
hub.branch = branch;
|
|
31939
|
+
sources.onWrite = (rel, before) => {
|
|
31940
|
+
if (hub.live) branch.remember(rel, before);
|
|
31941
|
+
};
|
|
31942
|
+
hub.devServer = new DevServerStarter(opts.root, storage.dir, { notify: (tone, text2) => hub.notify(tone, text2, "devserver"), log: (l) => (opts.log ?? console.error)(l) });
|
|
31507
31943
|
const project = {
|
|
31508
|
-
name:
|
|
31944
|
+
name: path13.basename(opts.root),
|
|
31509
31945
|
root: opts.root,
|
|
31510
31946
|
mcpUrl: `http://127.0.0.1:${port2}/mcp`,
|
|
31511
31947
|
connect: opts.cliPath ? `node ${JSON.stringify(opts.cliPath)} setup` : null,
|
|
@@ -31630,9 +32066,13 @@ async function startDaemon(opts) {
|
|
|
31630
32066
|
case "start": {
|
|
31631
32067
|
let url = str("url");
|
|
31632
32068
|
if (!url) {
|
|
31633
|
-
const
|
|
31634
|
-
if (!
|
|
31635
|
-
|
|
32069
|
+
const dev = await hub.devServer.ensure([port2]);
|
|
32070
|
+
if (!dev.ok) {
|
|
32071
|
+
if (dev.starting) return json(503, { error: `Your dev server is starting (${dev.command}). Switch to Live again in a moment.` });
|
|
32072
|
+
const cmd = await devCommand(opts.root);
|
|
32073
|
+
return json(404, { error: `Playground couldn't start this project's dev server: ${dev.reason.split("\n")[0]}${cmd ? ` Start it with ${cmd}` : " Start it"}, then switch to Live again.` });
|
|
32074
|
+
}
|
|
32075
|
+
url = dev.server.url + "/";
|
|
31636
32076
|
}
|
|
31637
32077
|
if (!isLocalOrigin(url)) return json(400, { error: "Live frames show apps running on this computer." });
|
|
31638
32078
|
return json(200, { live: await hub.startLive(url, str("title") || void 0) });
|
|
@@ -31646,15 +32086,15 @@ async function startDaemon(opts) {
|
|
|
31646
32086
|
const refs = Array.isArray(body.refs) ? body.refs.filter((r) => typeof r === "string").slice(0, 200) : [];
|
|
31647
32087
|
const live = hub.live;
|
|
31648
32088
|
const allowed = live ? [new URL(live.url).origin, `http://localhost:${live.port}`, `http://127.0.0.1:${live.port}`] : [];
|
|
31649
|
-
const root2 = await
|
|
32089
|
+
const root2 = await realpath4(opts.root).catch(() => opts.root);
|
|
31650
32090
|
const fetchText = async (u) => {
|
|
31651
32091
|
try {
|
|
31652
32092
|
if (u.startsWith("file://")) {
|
|
31653
32093
|
const raw = fileURLToPath(u.replace(/[?#].*$/, ""));
|
|
31654
|
-
const file = await
|
|
31655
|
-
const rel =
|
|
31656
|
-
if (!file || rel.startsWith("..") ||
|
|
31657
|
-
return await
|
|
32094
|
+
const file = await realpath4(raw).catch(() => "") || await realpath4(decodeURIComponent(raw)).catch(() => "");
|
|
32095
|
+
const rel = path13.relative(root2, file);
|
|
32096
|
+
if (!file || rel.startsWith("..") || path13.isAbsolute(rel) || !/\.(m?js|map)$/.test(file)) return null;
|
|
32097
|
+
return await readFile9(file, "utf8");
|
|
31658
32098
|
}
|
|
31659
32099
|
if (!allowed.includes(new URL(u).origin)) return null;
|
|
31660
32100
|
const r = await fetch(u, { signal: AbortSignal.timeout(1e4) });
|
|
@@ -31693,7 +32133,9 @@ async function startDaemon(opts) {
|
|
|
31693
32133
|
css,
|
|
31694
32134
|
...Number.isFinite(fontSize) && fontSize > 0 ? { fontSize } : {},
|
|
31695
32135
|
...site ? { site } : {},
|
|
31696
|
-
...shared ? { shared } : {}
|
|
32136
|
+
...shared ? { shared } : {},
|
|
32137
|
+
// From one Tailwind screen up (md:, lg:), for an edit made in the tablet or desktop frame.
|
|
32138
|
+
...isScreen(body.screen) ? { screen: body.screen } : {}
|
|
31697
32139
|
});
|
|
31698
32140
|
return json(r.ok ? 200 : 409, r.ok ? r : { error: r.reason });
|
|
31699
32141
|
}
|
|
@@ -31725,6 +32167,12 @@ async function startDaemon(opts) {
|
|
|
31725
32167
|
const r = await hub.revertLive(str("id"));
|
|
31726
32168
|
return json(r.ok ? 200 : 409, r.ok ? r : { error: r.message });
|
|
31727
32169
|
}
|
|
32170
|
+
case "diff":
|
|
32171
|
+
return json(200, { files: await hub.liveDiff() });
|
|
32172
|
+
case "pr": {
|
|
32173
|
+
const r = await hub.openLivePr();
|
|
32174
|
+
return json(r.ok ? 200 : 409, r.ok ? r : { error: r.message });
|
|
32175
|
+
}
|
|
31728
32176
|
case "revertAll": {
|
|
31729
32177
|
const r = await hub.revertAllLive();
|
|
31730
32178
|
return json(r.ok ? 200 : 409, r.ok ? r : { error: r.message });
|
|
@@ -31738,12 +32186,12 @@ async function startDaemon(opts) {
|
|
|
31738
32186
|
}
|
|
31739
32187
|
}
|
|
31740
32188
|
async function serveFile(req, res) {
|
|
31741
|
-
const name =
|
|
32189
|
+
const name = path13.basename(decodeURIComponent(new URL(req.url ?? "/", "http://x").pathname));
|
|
31742
32190
|
if (!/^[a-f0-9]{16}\.[a-z0-9]+$/.test(name)) return void res.writeHead(404).end();
|
|
31743
32191
|
try {
|
|
31744
|
-
const data = await
|
|
32192
|
+
const data = await readFile9(path13.join(hub.filesDir, name));
|
|
31745
32193
|
res.writeHead(200, {
|
|
31746
|
-
"content-type": MIME[
|
|
32194
|
+
"content-type": MIME[path13.extname(name)] ?? "application/octet-stream",
|
|
31747
32195
|
"cache-control": "public, max-age=31536000, immutable"
|
|
31748
32196
|
}).end(data);
|
|
31749
32197
|
} catch {
|
|
@@ -31780,16 +32228,16 @@ async function startDaemon(opts) {
|
|
|
31780
32228
|
const format = body?.format === "lottie" ? "lottie" : "mp4";
|
|
31781
32229
|
const ms = Math.min(3e4, Math.max(1e3, Number(body?.ms) || 6e3));
|
|
31782
32230
|
const url = `${origin ?? hub.origin}/?pg-stage=${encodeURIComponent(id)}&ms=${ms}`;
|
|
31783
|
-
const
|
|
32231
|
+
const slug2 = it.name.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-|-$/g, "") || "motion";
|
|
31784
32232
|
try {
|
|
31785
32233
|
if (format === "mp4") {
|
|
31786
32234
|
const data = await recordStage({ url, ms });
|
|
31787
|
-
res.writeHead(200, { "content-type": "video/mp4", "content-disposition": `attachment; filename="${
|
|
32235
|
+
res.writeHead(200, { "content-type": "video/mp4", "content-disposition": `attachment; filename="${slug2}.mp4"`, "cache-control": "no-store" }).end(data);
|
|
31788
32236
|
} else {
|
|
31789
32237
|
const stage = await measureStage({ url });
|
|
31790
32238
|
const script = loopScript(it, ms, { enter: phaseEnd(it, it.enter), exit: it.exit ? phaseEnd(it, it.exit) : 0 });
|
|
31791
32239
|
const data = JSON.stringify(toLottie(it, stage, script, ms));
|
|
31792
|
-
res.writeHead(200, { "content-type": "application/json", "content-disposition": `attachment; filename="${
|
|
32240
|
+
res.writeHead(200, { "content-type": "application/json", "content-disposition": `attachment; filename="${slug2}.json"`, "cache-control": "no-store" }).end(data);
|
|
31793
32241
|
}
|
|
31794
32242
|
} catch (err) {
|
|
31795
32243
|
fail(500, err.message);
|
|
@@ -31815,18 +32263,18 @@ async function startDaemon(opts) {
|
|
|
31815
32263
|
return;
|
|
31816
32264
|
}
|
|
31817
32265
|
const url = new URL(req.url ?? "/", "http://x");
|
|
31818
|
-
const safe =
|
|
31819
|
-
let file =
|
|
32266
|
+
const safe = path13.normalize(decodeURIComponent(url.pathname)).replace(/^(\.\.[/\\])+/, "");
|
|
32267
|
+
let file = path13.join(opts.editorDir, safe);
|
|
31820
32268
|
if (!file.startsWith(opts.editorDir)) return void res.writeHead(403).end();
|
|
31821
32269
|
try {
|
|
31822
|
-
if ((await stat4(file)).isDirectory()) file =
|
|
32270
|
+
if ((await stat4(file)).isDirectory()) file = path13.join(file, "index.html");
|
|
31823
32271
|
} catch {
|
|
31824
|
-
file =
|
|
32272
|
+
file = path13.join(opts.editorDir, "index.html");
|
|
31825
32273
|
}
|
|
31826
32274
|
try {
|
|
31827
|
-
const data = await
|
|
31828
|
-
const cache = file.includes(`${
|
|
31829
|
-
res.writeHead(200, { "content-type": MIME[
|
|
32275
|
+
const data = await readFile9(file);
|
|
32276
|
+
const cache = file.includes(`${path13.sep}assets${path13.sep}`) ? "public, max-age=31536000, immutable" : "no-cache";
|
|
32277
|
+
res.writeHead(200, { "content-type": MIME[path13.extname(file)] ?? "application/octet-stream", "cache-control": cache }).end(data);
|
|
31830
32278
|
} catch {
|
|
31831
32279
|
res.writeHead(404).end();
|
|
31832
32280
|
}
|
|
@@ -31938,6 +32386,7 @@ async function startDaemon(opts) {
|
|
|
31938
32386
|
close: () => new Promise((r) => {
|
|
31939
32387
|
void closeImporter();
|
|
31940
32388
|
hub.runner?.stop();
|
|
32389
|
+
hub.devServer?.stop();
|
|
31941
32390
|
void hub.closeLive();
|
|
31942
32391
|
for (const c of wss.clients) c.terminate();
|
|
31943
32392
|
wss.close();
|
|
@@ -32025,17 +32474,17 @@ if (positionals[0] === "setup") {
|
|
|
32025
32474
|
}
|
|
32026
32475
|
if (positionals[0] === "wait") {
|
|
32027
32476
|
const { runWait: runWait2 } = await Promise.resolve().then(() => (init_bridge(), bridge_exports));
|
|
32028
|
-
process.exit(await runWait2({ root:
|
|
32477
|
+
process.exit(await runWait2({ root: path16.resolve(positionals[1] ?? process.cwd()), port, name: values2.as }));
|
|
32029
32478
|
}
|
|
32030
32479
|
if (positionals[0] === "mcp") {
|
|
32031
32480
|
const { runBridge: runBridge2 } = await Promise.resolve().then(() => (init_bridge(), bridge_exports));
|
|
32032
32481
|
const folder = positionals[1] && !/\$\{\w+\}/.test(positionals[1]) ? positionals[1] : process.cwd();
|
|
32033
|
-
await runBridge2({ root:
|
|
32482
|
+
await runBridge2({ root: path16.resolve(folder), port, cliPath: fileURLToPath2(import.meta.url) });
|
|
32034
32483
|
} else {
|
|
32035
32484
|
await serve();
|
|
32036
32485
|
}
|
|
32037
32486
|
async function serve() {
|
|
32038
|
-
const root2 =
|
|
32487
|
+
const root2 = path16.resolve(positionals[0] ?? process.cwd());
|
|
32039
32488
|
let isDir = false;
|
|
32040
32489
|
try {
|
|
32041
32490
|
isDir = statSync2(root2).isDirectory();
|
|
@@ -32049,10 +32498,10 @@ Run pg-studio from your project folder, or pass its path: pg-studio ~/code/my-ap
|
|
|
32049
32498
|
);
|
|
32050
32499
|
process.exit(1);
|
|
32051
32500
|
}
|
|
32052
|
-
const editorDir = process.env.PG_EDITOR_DIR ?
|
|
32501
|
+
const editorDir = process.env.PG_EDITOR_DIR ? path16.resolve(process.env.PG_EDITOR_DIR) : path16.join(path16.dirname(fileURLToPath2(import.meta.url)), "editor");
|
|
32053
32502
|
const opener = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
|
|
32054
32503
|
const openInBrowser = (url2) => {
|
|
32055
|
-
if (!process.env.PG_STUDIO_NO_BROWSER)
|
|
32504
|
+
if (!process.env.PG_STUDIO_NO_BROWSER) spawn7(opener, [url2], { stdio: "ignore", detached: true }).unref();
|
|
32056
32505
|
};
|
|
32057
32506
|
let daemon;
|
|
32058
32507
|
try {
|