@haneeshsai/cartd 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/bin/cartd.mjs ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ // Shim — after `npm run build`, tsc emits bin/cartd.js; we exec it.
3
+ import { createRequire } from 'node:module'
4
+ import { fileURLToPath } from 'node:url'
5
+ import { dirname, join } from 'node:path'
6
+
7
+ const __dirname = dirname(fileURLToPath(import.meta.url))
8
+ await import(join(__dirname, '..', 'dist', 'bin', 'cartd.js'))
@@ -0,0 +1,3 @@
1
+ #!/usr/bin/env node
2
+ export {};
3
+ //# sourceMappingURL=cartd.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartd.d.ts","sourceRoot":"","sources":["../../bin/cartd.ts"],"names":[],"mappings":""}
@@ -0,0 +1,185 @@
1
+ #!/usr/bin/env node
2
+ import { program } from 'commander';
3
+ import chalk from 'chalk';
4
+ import ora from 'ora';
5
+ import { writeFileSync, existsSync } from 'node:fs';
6
+ import { join } from 'node:path';
7
+ import { v4 as uuidv4 } from 'uuid';
8
+ import { execa } from 'execa';
9
+ import { loadConfig, scaffoldConfig } from '../src/config.js';
10
+ import { detectFramework } from '../src/detect.js';
11
+ import { createProxy } from '../src/proxy.js';
12
+ import { startSidecar } from '../src/sidecar.js';
13
+ import { search } from '../src/searcher.js';
14
+ const SIDECAR_PORT = 4242;
15
+ const cwd = process.cwd();
16
+ program
17
+ .name('cartd')
18
+ .description('Cartd visual editor CLI')
19
+ .version('0.1.0');
20
+ // ── cartd dev ────────────────────────────────────────────────────────
21
+ program
22
+ .command('dev')
23
+ .description('Start dev server + Cartd editor sidecar')
24
+ .action(async () => {
25
+ console.log('\n' + chalk.bold(' ◆ Cartd Editor') + '\n');
26
+ const spinner = ora({ prefixText: ' ' });
27
+ // 1. Load config (fall back to auto-detect if none)
28
+ let config;
29
+ try {
30
+ config = await loadConfig(cwd);
31
+ }
32
+ catch {
33
+ spinner.start('Detecting framework…');
34
+ const detected = detectFramework(cwd);
35
+ config = {
36
+ framework: detected.framework,
37
+ devPort: detected.devPort,
38
+ scanDirs: detected.scanDirs,
39
+ ignore: ['node_modules', '.next', 'dist', 'build', '.git'],
40
+ relay: 'wss://relay.cartd.io',
41
+ };
42
+ spinner.succeed(`Framework detected: ${chalk.cyan(friendlyName(config.framework))}`);
43
+ }
44
+ const token = uuidv4();
45
+ // 2. Start the user's dev server
46
+ spinner.start('Starting dev server…');
47
+ const devCmd = getDevCommandFromConfig(config);
48
+ let devProc = null;
49
+ if (devCmd) {
50
+ const [bin, ...args] = devCmd.split(' ');
51
+ devProc = execa(bin, args, { cwd, stdio: 'pipe', reject: false });
52
+ devProc.catch(() => { }); // handled via exit
53
+ // Wait for dev server to be ready
54
+ await waitForPort(config.devPort, 30000);
55
+ spinner.succeed(`Dev server started on ${chalk.cyan(`:${config.devPort}`)}`);
56
+ }
57
+ else {
58
+ spinner.warn('No dev command — skipping dev server start');
59
+ }
60
+ // 3. Start proxy
61
+ spinner.start('Starting proxy…');
62
+ const proxyServer = createProxy(config.devPort);
63
+ await new Promise((resolve, reject) => {
64
+ proxyServer.listen(SIDECAR_PORT, (err) => {
65
+ if (err)
66
+ reject(err);
67
+ else
68
+ resolve();
69
+ });
70
+ });
71
+ spinner.stop();
72
+ // 4. Connect relay + start sidecar
73
+ const stopSidecar = startSidecar({
74
+ config,
75
+ cwd,
76
+ token,
77
+ httpServer: proxyServer,
78
+ onReady: () => {
79
+ console.log(` ${chalk.green('✓')} Relay connected`);
80
+ },
81
+ });
82
+ // Print session info immediately — proxy works even without relay
83
+ const localUrl = `http://localhost:${SIDECAR_PORT}?cartd=true`;
84
+ const editorUrl = `https://cartd.io/editor?token=${token}`;
85
+ console.log(`\n ${chalk.green('✓')} Proxy running on ${chalk.cyan(`:${SIDECAR_PORT}`)}\n`);
86
+ console.log(` Preview (with editor overlay) → ${chalk.bold(localUrl)}`);
87
+ console.log(` Editor UI → ${chalk.bold.underline(editorUrl)}`);
88
+ console.log(` ${chalk.dim('(relay connects in background — retries automatically)')}\n`);
89
+ // 5. Graceful shutdown
90
+ const shutdown = () => {
91
+ process.stdout.write('\n [cartd] Shutting down…\n');
92
+ stopSidecar();
93
+ proxyServer.close();
94
+ devProc?.kill();
95
+ process.exit(0);
96
+ };
97
+ process.on('SIGINT', shutdown);
98
+ process.on('SIGTERM', shutdown);
99
+ });
100
+ // ── cartd init ───────────────────────────────────────────────────────
101
+ program
102
+ .command('init')
103
+ .description('Scaffold cartd.config.ts in the current directory')
104
+ .action(async () => {
105
+ const dest = join(cwd, 'cartd.config.ts');
106
+ if (existsSync(dest)) {
107
+ console.log(chalk.yellow(' cartd.config.ts already exists — skipping'));
108
+ return;
109
+ }
110
+ const detected = detectFramework(cwd);
111
+ const content = scaffoldConfig(cwd, { framework: detected.framework, devPort: detected.devPort, scanDirs: detected.scanDirs });
112
+ writeFileSync(dest, content, 'utf-8');
113
+ console.log(chalk.green(' ✓ Created cartd.config.ts'));
114
+ });
115
+ // ── cartd scan ───────────────────────────────────────────────────────
116
+ program
117
+ .command('scan')
118
+ .description('Dry-run: print all detectable editable elements in the project')
119
+ .option('--text', 'scan text nodes')
120
+ .option('--images', 'scan image src attributes')
121
+ .action(async (opts) => {
122
+ let config;
123
+ try {
124
+ config = await loadConfig(cwd);
125
+ }
126
+ catch {
127
+ const detected = detectFramework(cwd);
128
+ config = { framework: detected.framework, devPort: detected.devPort, scanDirs: detected.scanDirs, ignore: ['node_modules', '.next', 'dist', 'build'], relay: 'wss://relay.cartd.io' };
129
+ }
130
+ const types = [];
131
+ if (opts.text || (!opts.text && !opts.images))
132
+ types.push('text');
133
+ if (opts.images || (!opts.text && !opts.images))
134
+ types.push('image');
135
+ console.log(chalk.bold('\n ◆ Cartd Scan\n'));
136
+ let total = 0;
137
+ for (const type of types) {
138
+ const matches = search({ type, textContent: '', tagName: '*' }, config.scanDirs, cwd, config.ignore);
139
+ for (const m of matches) {
140
+ console.log(` ${chalk.dim(m.file + ':' + m.line)} ${chalk.cyan(type)} col ${m.colStart}`);
141
+ total++;
142
+ }
143
+ }
144
+ console.log(`\n ${total} editable element${total !== 1 ? 's' : ''} found\n`);
145
+ });
146
+ program.parse();
147
+ // ── Helpers ───────────────────────────────────────────────────────────
148
+ function friendlyName(fw) {
149
+ const map = {
150
+ 'nextjs-app': 'Next.js (App Router)',
151
+ 'nextjs-pages': 'Next.js (Pages Router)',
152
+ 'vite': 'Vite',
153
+ 'html': 'HTML',
154
+ };
155
+ return map[fw] ?? fw;
156
+ }
157
+ function getDevCommandFromConfig(config) {
158
+ const defaults = {
159
+ 'nextjs-app': 'next dev',
160
+ 'nextjs-pages': 'next dev',
161
+ 'vite': 'vite',
162
+ 'html': '',
163
+ };
164
+ return defaults[config.framework] ?? '';
165
+ }
166
+ async function waitForPort(port, timeout) {
167
+ const { default: net } = await import('node:net');
168
+ const start = Date.now();
169
+ return new Promise((resolve) => {
170
+ function attempt() {
171
+ const s = net.createConnection(port, '127.0.0.1');
172
+ s.on('connect', () => { s.destroy(); resolve(); });
173
+ s.on('error', () => {
174
+ s.destroy();
175
+ if (Date.now() - start > timeout) {
176
+ resolve();
177
+ return;
178
+ } // give up, proceed
179
+ setTimeout(attempt, 500);
180
+ });
181
+ }
182
+ attempt();
183
+ });
184
+ }
185
+ //# sourceMappingURL=cartd.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cartd.js","sourceRoot":"","sources":["../../bin/cartd.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA;AACnC,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,GAAG,MAAM,KAAK,CAAA;AACrB,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AACnD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAChC,OAAO,EAAE,EAAE,IAAI,MAAM,EAAE,MAAM,MAAM,C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AC,CAAC,EAAE,CAAC,SAAS,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,EAAE,CAAA,CAAC,CAAC,CAAC,CAAA;YACjD,CAAC,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;gBACjB,CAAC,CAAC,OAAO,EAAE,CAAA;gBACX,IAAI,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK,GAAG,OAAO,EAAE,CAAC;oBAAC,OAAO,EAAE,CAAC;oBAAC,OAAM;gBAAC,CAAC,CAAC,mBAAmB;gBAC3E,UAAU,CAAC,OAAO,EAAE,GAAG,CAAC,CAAA;YAC1B,CAAC,CAAC,CAAA;QACJ,CAAC;QACD,OAAO,EAAE,CAAA;IACX,CAAC,CAAC,CAAA;AACJ,CAAC"}
@@ -0,0 +1,25 @@
1
+ import { z } from 'zod';
2
+ declare const ConfigSchema: z.ZodObject<{
3
+ framework: z.ZodEnum<["nextjs-app", "nextjs-pages", "vite", "html"]>;
4
+ devPort: z.ZodDefault<z.ZodNumber>;
5
+ scanDirs: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
6
+ ignore: z.ZodDefault<z.ZodArray<z.ZodString, "many">>;
7
+ relay: z.ZodDefault<z.ZodString>;
8
+ }, "strip", z.ZodTypeAny, {
9
+ framework: "nextjs-app" | "nextjs-pages" | "vite" | "html";
10
+ devPort: number;
11
+ scanDirs: string[];
12
+ ignore: string[];
13
+ relay: string;
14
+ }, {
15
+ framework: "nextjs-app" | "nextjs-pages" | "vite" | "html";
16
+ devPort?: number | undefined;
17
+ scanDirs?: string[] | undefined;
18
+ ignore?: string[] | undefined;
19
+ relay?: string | undefined;
20
+ }>;
21
+ export type CartdConfig = z.infer<typeof ConfigSchema>;
22
+ export declare function loadConfig(cwd: string): Promise<CartdConfig>;
23
+ export declare function scaffoldConfig(cwd: string, detected: Partial<CartdConfig>): string;
24
+ export {};
25
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;EAMhB,CAAA;AAEF,MAAM,MAAM,WAAW,GAAG,CAAC,CAAC,KAAK,CAAC,OAAO,YAAY,CAAC,CAAA;AAItD,wBAAsB,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAC,WAAW,CAAC,CAkClE;AAED,wBAAgB,cAAc,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,MAAM,CAalF"}
@@ -0,0 +1,62 @@
1
+ import { existsSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ import { pathToFileURL } from 'node:url';
4
+ import { z } from 'zod';
5
+ const ConfigSchema = z.object({
6
+ framework: z.enum(['nextjs-app', 'nextjs-pages', 'vite', 'html']),
7
+ devPort: z.number().int().min(1).max(65535).default(3000),
8
+ scanDirs: z.array(z.string()).default(['app', 'src', 'components', 'pages']),
9
+ ignore: z.array(z.string()).default(['node_modules', '.next', 'dist', 'build', '.git']),
10
+ relay: z.string().url().default('wss://relay.cartd.io'),
11
+ });
12
+ const CONFIG_FILENAMES = ['cartd.config.ts', 'cartd.config.mjs', 'cartd.config.js'];
13
+ export async function loadConfig(cwd) {
14
+ for (const filename of CONFIG_FILENAMES) {
15
+ const configPath = join(cwd, filename);
16
+ if (!existsSync(configPath))
17
+ continue;
18
+ try {
19
+ // For .ts configs, use esbuild to transpile on-the-fly to a temp file
20
+ if (filename.endsWith('.ts')) {
21
+ const { build } = await import('esbuild');
22
+ const tmpOut = join(cwd, '.cartd-config-tmp.mjs');
23
+ await build({
24
+ entryPoints: [configPath],
25
+ outfile: tmpOut,
26
+ format: 'esm',
27
+ platform: 'node',
28
+ bundle: false,
29
+ write: true,
30
+ });
31
+ const mod = await import(pathToFileURL(tmpOut).href + `?t=${Date.now()}`);
32
+ const { unlinkSync } = await import('node:fs');
33
+ try {
34
+ unlinkSync(tmpOut);
35
+ }
36
+ catch { }
37
+ return ConfigSchema.parse(mod.default);
38
+ }
39
+ const mod = await import(pathToFileURL(configPath).href + `?t=${Date.now()}`);
40
+ return ConfigSchema.parse(mod.default);
41
+ }
42
+ catch (err) {
43
+ throw new Error(`Failed to load ${filename}: ${err instanceof Error ? err.message : String(err)}`);
44
+ }
45
+ }
46
+ throw new Error('No cartd.config.ts found. Run `cartd init` to scaffold one.');
47
+ }
48
+ export function scaffoldConfig(cwd, detected) {
49
+ return `import type { CartdConfig } from '@cartd/editor'
50
+
51
+ const config: CartdConfig = {
52
+ framework: '${detected.framework ?? 'nextjs-app'}',
53
+ devPort: ${detected.devPort ?? 3000},
54
+ scanDirs: ${JSON.stringify(detected.scanDirs ?? ['app', 'components', 'src'])},
55
+ ignore: ${JSON.stringify(detected.ignore ?? ['node_modules', '.next', 'dist', 'build'])},
56
+ relay: 'wss://relay.cartd.io',
57
+ }
58
+
59
+ export default config
60
+ `;
61
+ }
62
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../src/config.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,UAAU,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAW,IAAI,EAAE,MAAM,WAAW,CAAA;AACzC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AACxC,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvB,MAAM,YAAY,GAAG,CAAC,CAAC,MAAM,CAAC;IAC5B,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;IACjE,OAAO,EAAE,CAAC,CAAC,MAAM,EAAE,CAAC,GAAG,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,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;;;;CAKxF,CAAA;AACD,CAAC"}
@@ -0,0 +1,12 @@
1
+ import type { CartdConfig } from './config.ts';
2
+ export type Framework = CartdConfig['framework'];
3
+ interface DetectResult {
4
+ framework: Framework;
5
+ devPort: number;
6
+ devCommand: string;
7
+ scanDirs: string[];
8
+ }
9
+ export declare function detectFramework(cwd: string): DetectResult;
10
+ export declare function getDevCommand(framework: Framework, pkg: Record<string, Record<string, string>> | null): string;
11
+ export {};
12
+ //# sourceMappingURL=detect.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.d.ts","sourceRoot":"","sources":["../../src/detect.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAE9C,MAAM,MAAM,SAAS,GAAG,WAAW,CAAC,WAAW,CAAC,CAAA;AAEhD,UAAU,YAAY;IACpB,SAAS,EAAE,SAAS,CAAA;IACpB,OAAO,EAAE,MAAM,CAAA;IACf,UAAU,EAAE,MAAM,CAAA;IAClB,QAAQ,EAAE,MAAM,EAAE,CAAA;CACnB;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,YAAY,CA+CzD;AAYD,wBAAgB,aAAa,CAAC,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,GAAG,IAAI,GAAG,MAAM,CAa9G"}
@@ -0,0 +1,69 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { join } from 'node:path';
3
+ export function detectFramework(cwd) {
4
+ const pkg = readPackageJson(cwd);
5
+ const deps = {
6
+ ...pkg?.dependencies,
7
+ ...pkg?.devDependencies,
8
+ };
9
+ const hasNext = 'next' in deps;
10
+ const hasVite = 'vite' in deps;
11
+ if (hasNext) {
12
+ const isAppRouter = existsSync(join(cwd, 'app')) &&
13
+ (existsSync(join(cwd, 'app', 'page.tsx')) ||
14
+ existsSync(join(cwd, 'app', 'page.jsx')) ||
15
+ existsSync(join(cwd, 'app', 'layout.tsx')));
16
+ const framework = isAppRouter ? 'nextjs-app' : 'nextjs-pages';
17
+ const scanDirs = isAppRouter
18
+ ? ['app', 'components', 'src']
19
+ : ['pages', 'components', 'src'];
20
+ return {
21
+ framework,
22
+ devPort: 3000,
23
+ devCommand: 'next dev',
24
+ scanDirs,
25
+ };
26
+ }
27
+ if (hasVite) {
28
+ return {
29
+ framework: 'vite',
30
+ devPort: 5173,
31
+ devCommand: 'vite',
32
+ scanDirs: ['src', 'components'],
33
+ };
34
+ }
35
+ // Fallback: plain HTML
36
+ return {
37
+ framework: 'html',
38
+ devPort: 3000,
39
+ devCommand: '',
40
+ scanDirs: ['.'],
41
+ };
42
+ }
43
+ function readPackageJson(cwd) {
44
+ const pkgPath = join(cwd, 'package.json');
45
+ if (!existsSync(pkgPath))
46
+ return null;
47
+ try {
48
+ return JSON.parse(readFileSync(pkgPath, 'utf-8'));
49
+ }
50
+ catch {
51
+ return null;
52
+ }
53
+ }
54
+ export function getDevCommand(framework, pkg) {
55
+ // Prefer scripts defined in package.json
56
+ const scripts = pkg?.scripts ?? {};
57
+ if (scripts['dev'])
58
+ return scripts['dev'];
59
+ if (scripts['start'])
60
+ return scripts['start'];
61
+ const defaults = {
62
+ 'nextjs-app': 'next dev',
63
+ 'nextjs-pages': 'next dev',
64
+ 'vite': 'vite',
65
+ 'html': '',
66
+ };
67
+ return defaults[framework];
68
+ }
69
+ //# sourceMappingURL=detect.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"detect.js","sourceRoot":"","sources":["../../src/detect.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,YAAY,EAAE,MAAM,SAAS,CAAA;AAClD,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAA;AAYhC,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,GAAG,GAAG,eAAe,CAAC,GAAG,CAAC,CAAA;IAEhC,MAAM,IAAI,GAAG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ClC,MAAM,OAAO,GAAG,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,CAAA;IACzC,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC;QAAE,OAAO,IAAI,CAAA;IACrC,IAAI,CAAC;QACH,OAAO,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAA;IACnD,CAAC;IAAC,MAAM,CAAC;QACP,OAAO,IAAI,CAAA;IACb,CAAC;AACH,CAAC;AAED,MAAM,UAAU,aAAa,CAAC,SAAoB,EAAE,GAAkD;IACpG,yCAAyC;IACzC,MAAM,OAAO,GAAG,GAAG,EAAE,OAAO,IAAI,EAAE,CAAA;IAClC,IAAI,OAAO,CAAC,KAAK,CAAC;QAAE,OAAO,OAAO,CAAC,KAAK,CAAC,CAAA;IACzC,IAAI,OAAO,CAAC,OAAO,CAAC;QAAE,OAAO,OAAO,CAAC,OAAO,CAAC,CAAA;IAE7C,MAAM,QAAQ,GAA8B;QAC1C,YAAY,EAAE,UAAU;QACxB,cAAc,EAAE,UAAU;QAC1B,MAAM,EAAE,MAAM;QACd,MAAM,EAAE,EAAE;KACX,CAAA;IACD,OAAO,QAAQ,CAAC,SAAS,CAAC,CAAA;AAC5B,CAAC"}
@@ -0,0 +1,8 @@
1
+ export type { CartdConfig } from './config.js';
2
+ export { loadConfig, scaffoldConfig } from './config.js';
3
+ export { detectFramework } from './detect.js';
4
+ export { search } from './searcher.js';
5
+ export { patch } from './patcher.js';
6
+ export { startSidecar } from './sidecar.js';
7
+ export { createProxy } from './proxy.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AACA,YAAY,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAC9C,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,7 @@
1
+ export { loadConfig, scaffoldConfig } from './config.js';
2
+ export { detectFramework } from './detect.js';
3
+ export { search } from './searcher.js';
4
+ export { patch } from './patcher.js';
5
+ export { startSidecar } from './sidecar.js';
6
+ export { createProxy } from './proxy.js';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,UAAU,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAA;AAC7C,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAA;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAA;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAA"}
@@ -0,0 +1,2 @@
1
+ export declare const INJECTED_SCRIPT = "\"use strict\";(()=>{var S=\"#2563eb\",B=\"rgba(37,99,235,0.08)\",P=\"rgba(22,163,74,0.15)\";function z(){return new URLSearchParams(location.search).get(\"cartd\")===\"true\"||document.cookie.split(\";\").some(l=>l.trim()===\"__CARTD_ACTIVE__=1\")}if(z()){let b=function(){l=new WebSocket(\"ws://localhost:4242/inject\"),l.onopen=()=>{y=1e3},l.onclose=()=>{l=null,setTimeout(()=>{y=Math.min(y*2,3e4),b()},y)},l.onmessage=t=>{let e;try{e=JSON.parse(t.data)}catch{return}N(e)}},N=function(t){if(t.type===\"search-result\"){let e=t.matches,n=t.editType,r=t.currentValue??\"\";if(!e?.length){h(\"Not found in source files.\");return}e.length===1?E(e[0],n,r):R(e,n,r);return}if(t.type===\"patch-success\"){p(),O(t.cartdId);return}t.type===\"error\"&&h(t.message??\"Something went wrong.\")},w=function(t){let e=t.target;if(!e||e.nodeType!==1)return null;let n=e.tagName===\"IMG\"?e:e.closest(\"img\");if(n&&n.src&&!n.src.startsWith(\"data:\"))return{el:n,type:\"image\",src:n.src,rect:n.getBoundingClientRect()};let r=getComputedStyle(e).backgroundImage;if(r&&r!==\"none\"){let c=r.match(/url\\([\"']?([^\"')]+)[\"']?\\)/)?.[1];if(c&&!c.startsWith(\"data:\"))return{el:e,type:\"image\",src:c,rect:e.getBoundingClientRect()}}let s=_(t.clientX,t.clientY);if(s){let a=s.textContent?.trim()??\"\";if(a.length>=3){let c=s.parentElement??e;return{el:c,type:\"text\",text:a,rect:c.getBoundingClientRect()}}}let i=Array.from(e.childNodes).filter(a=>a.nodeType===Node.TEXT_NODE).map(a=>a.textContent?.trim()).filter(Boolean).join(\" \").trim();if(i.length>=3)return{el:e,type:\"text\",text:i,rect:e.getBoundingClientRect()};let f=document.elementsFromPoint(t.clientX,t.clientY);for(let a of f){let c=getComputedStyle(a).backgroundImage;if(c&&c!==\"none\"){let o=c.match(/url\\([\"']?([^\"')]+)[\"']?\\)/)?.[1];if(o&&!o.startsWith(\"data:\"))return{el:a,type:\"image\",src:o,rect:a.getBoundingClientRect()}}}return null},_=function(t,e){if(document.caretRangeFromPoint){let s=document.caretRangeFromPoint(t,e);if(s?.startContainer?.nodeType===Node.TEXT_NODE)return s.startContainer}let r=document.caretPositionFromPoint?.(t,e);return r?.offsetNode?.nodeType===Node.TEXT_NODE?r.offsetNode:null},I=function(t){t.dataset.cartdOutline=t.style.outline,t.dataset.cartdBg=t.style.backgroundColor,t.style.outline=`2px solid ${S}`,t.style.backgroundColor=B},T=function(t){t.style.outline=t.dataset.cartdOutline??\"\",t.style.backgroundColor=t.dataset.cartdBg??\"\",delete t.dataset.cartdOutline,delete t.dataset.cartdBg},R=function(t,e,n){let r=L();r.appendChild(u(\"div\",{style:\"font-size:11px;color:#a8a29e;letter-spacing:0.08em;text-transform:uppercase;margin-bottom:10px\"},`Found in ${t.length} places \\u2014 pick one`)),t.forEach(s=>{let i=u(\"div\",{style:\"padding:8px 10px;border-radius:4px;cursor:pointer;font-size:12px;font-family:monospace;color:#e2e8f0;margin-bottom:2px\"},`${v(s.file)}:${s.line}`);i.addEventListener(\"mouseenter\",()=>{i.style.background=\"#2d2d2d\"}),i.addEventListener(\"mouseleave\",()=>{i.style.background=\"\"}),i.addEventListener(\"click\",f=>{f.stopPropagation(),E(s,e,n)}),r.appendChild(i)}),k(r),C(r)},E=function(t,e,n){let r=L();r.appendChild(u(\"div\",{style:\"font-size:11px;color:#a8a29e;letter-spacing:0.06em;margin-bottom:12px;font-family:monospace\"},v(t.file)+\":\"+t.line));let s=n.includes(`\n`)||n.length>60,i;if(s){let o=document.createElement(\"textarea\");o.value=n,o.rows=Math.min(Math.max(n.split(`\n`).length,2),6),o.style.cssText=M()+\"resize:vertical;\",i=o}else{let o=document.createElement(\"input\");o.type=\"text\",o.value=n,o.style.cssText=M(),i=o}i.addEventListener(\"click\",o=>o.stopPropagation()),i.addEventListener(\"keydown\",o=>{o.key===\"Enter\"&&!o.shiftKey&&!s&&(o.preventDefault(),H()),o.key===\"Escape\"&&p(),o.stopPropagation()}),r.appendChild(i);let f=u(\"div\",{style:\"display:flex;gap:8px;margin-top:10px\"}),a=u(\"button\",{style:\"flex:1;padding:7px 0;background:#2563eb;color:white;border:none;border-radius:4px;font-size:12px;font-weight:500;cursor:pointer\"},\"Save\"),c=u(\"button\",{style:\"padding:7px 14px;background:transparent;color:#a8a29e;border:1px solid #3f3f46;border-radius:4px;font-size:12px;cursor:pointer\"},\"Cancel\");a.addEventListener(\"click\",o=>{o.stopPropagation(),H()}),c.addEventListener(\"click\",o=>{o.stopPropagation(),p()}),f.appendChild(a),f.appendChild(c),r.appendChild(f),k(r),C(r),setTimeout(()=>{i.focus(),i.select?.()},30);function H(){let o=i.value.trim();if(!o||o===n){p();return}l?.send(JSON.stringify({type:\"change\",payload:{match:t,type:e,newValue:o,cartdId:x?.payload?.cartdId}})),a.textContent=\"Saving\\u2026\",a.style.opacity=\"0.6\",a.disabled=!0}},h=function(t){let e=u(\"div\",{style:\"position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:#7f1d1d;color:#fca5a5;padding:10px 16px;border-radius:6px;font-size:12px;font-family:system-ui;z-index:2147483647;pointer-events:none\"},t);document.body.appendChild(e),setTimeout(()=>e.remove(),3e3)},L=function(){p();let t=u(\"div\",{style:\"position:fixed;z-index:2147483647;background:#1c1917;border:1px solid #3f3f46;border-radius:8px;padding:14px;width:280px;box-shadow:0 8px 32px rgba(0,0,0,0.5);font-family:system-ui,-apple-system,sans-serif;box-sizing:border-box\"});return t.dataset.cartdPanel=\"1\",t},k=function(t){if(!x)return;let{rect:e}=x,n=280,r=200,s=e.bottom+8,i=e.left;i+n>window.innerWidth-8&&(i=window.innerWidth-n-8),i<8&&(i=8),s+r>window.innerHeight-8&&(s=e.top-r-8),s<8&&(s=8),t.style.top=`${s}px`,t.style.left=`${i}px`},C=function(t){document.body.appendChild(t),g=t,m=!0,d&&(T(d),d=null)},p=function(){g?.remove(),g=null,m=!1},M=function(){return\"width:100%;background:#0c0a09;border:1px solid #3f3f46;border-radius:4px;color:#fafaf9;font-size:13px;padding:8px 10px;box-sizing:border-box;outline:none;font-family:system-ui,-apple-system,sans-serif;\"},v=function(t){return t.split(\"/\").slice(-2).join(\"/\")},u=function(t,e,n){let r=document.createElement(t);for(let[s,i]of Object.entries(e))r.setAttribute(s,i);return n&&(r.textContent=n),r},O=function(t){let e=t?document.querySelector(`[data-cartd-id=\"${t}\"]`):null;if(!e)return;let n=e.style.backgroundColor;e.style.transition=\"background-color 0.3s\",e.style.backgroundColor=P,setTimeout(()=>{e.style.backgroundColor=n},1400)};D=b,G=N,W=w,A=_,X=I,$=T,F=R,j=E,J=h,U=L,Y=k,q=C,K=p,Q=M,Z=v,V=u,tt=O;let l=null,y=1e3,d=null,x=null,g=null,m=!1;document.addEventListener(\"mouseover\",t=>{if(m)return;let e=t.target;!e||e.nodeType!==1||g?.contains(e)||(d&&d!==e&&T(d),d=e,I(e))},{capture:!0}),document.addEventListener(\"mouseout\",t=>{if(m)return;let e=t.target;e===d&&(T(e),d=null)},{capture:!0}),document.addEventListener(\"click\",t=>{if(g&&g.contains(t.target))return;if(m){p(),t.preventDefault(),t.stopPropagation();return}let e=w(t);if(!e)return;t.preventDefault(),t.stopPropagation();let n={tagName:e.el.tagName.toLowerCase(),type:e.type,textContent:e.text??\"\",src:e.src,cartdId:e.el.dataset.cartdId??void 0,className:e.el.className,rect:{x:e.rect.x,y:e.rect.y,width:e.rect.width,height:e.rect.height,top:e.rect.top,left:e.rect.left,bottom:e.rect.bottom,right:e.rect.right}};x={payload:n,rect:e.rect},l?.send(JSON.stringify({type:\"element-clicked\",payload:n}))},{capture:!0}),document.addEventListener(\"keydown\",t=>{t.key===\"Escape\"&&m&&p()}),b()}var D,G,W,A,X,$,F,j,J,U,Y,q,K,Q,Z,V,tt;})();\n";
2
+ //# sourceMappingURL=injected-content.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injected-content.d.ts","sourceRoot":"","sources":["../../src/injected-content.ts"],"names":[],"mappings":"AACA,eAAO,MAAM,eAAe,2sOAA2sO,CAAA"}
@@ -0,0 +1,3 @@
1
+ // AUTO-GENERATED — do not edit
2
+ export const INJECTED_SCRIPT = "\"use strict\";(()=>{var S=\"#2563eb\",B=\"rgba(37,99,235,0.08)\",P=\"rgba(22,163,74,0.15)\";function z(){return new URLSearchParams(location.search).get(\"cartd\")===\"true\"||document.cookie.split(\";\").some(l=>l.trim()===\"__CARTD_ACTIVE__=1\")}if(z()){let b=function(){l=new WebSocket(\"ws://localhost:4242/inject\"),l.onopen=()=>{y=1e3},l.onclose=()=>{l=null,setTimeout(()=>{y=Math.min(y*2,3e4),b()},y)},l.onmessage=t=>{let e;try{e=JSON.parse(t.data)}catch{return}N(e)}},N=function(t){if(t.type===\"search-result\"){let e=t.matches,n=t.editType,r=t.currentValue??\"\";if(!e?.length){h(\"Not found in source files.\");return}e.length===1?E(e[0],n,r):R(e,n,r);return}if(t.type===\"patch-success\"){p(),O(t.cartdId);return}t.type===\"error\"&&h(t.message??\"Something went wrong.\")},w=function(t){let e=t.target;if(!e||e.nodeType!==1)return null;let n=e.tagName===\"IMG\"?e:e.closest(\"img\");if(n&&n.src&&!n.src.startsWith(\"data:\"))return{el:n,type:\"image\",src:n.src,rect:n.getBoundingClientRect()};let r=getComputedStyle(e).backgroundImage;if(r&&r!==\"none\"){let c=r.match(/url\\([\"']?([^\"')]+)[\"']?\\)/)?.[1];if(c&&!c.startsWith(\"data:\"))return{el:e,type:\"image\",src:c,rect:e.getBoundingClientRect()}}let s=_(t.clientX,t.clientY);if(s){let a=s.textContent?.trim()??\"\";if(a.length>=3){let c=s.parentElement??e;return{el:c,type:\"text\",text:a,rect:c.getBoundingClientRect()}}}let i=Array.from(e.childNodes).filter(a=>a.nodeType===Node.TEXT_NODE).map(a=>a.textContent?.trim()).filter(Boolean).join(\" \").trim();if(i.length>=3)return{el:e,type:\"text\",text:i,rect:e.getBoundingClientRect()};let f=document.elementsFromPoint(t.clientX,t.clientY);for(let a of f){let c=getComputedStyle(a).backgroundImage;if(c&&c!==\"none\"){let o=c.match(/url\\([\"']?([^\"')]+)[\"']?\\)/)?.[1];if(o&&!o.startsWith(\"data:\"))return{el:a,type:\"image\",src:o,rect:a.getBoundingClientRect()}}}return null},_=function(t,e){if(document.caretRangeFromPoint){let s=document.caretRangeFromPoint(t,e);if(s?.startContainer?.nodeType===Node.TEXT_NODE)return s.startContainer}let r=document.caretPositionFromPoint?.(t,e);return r?.offsetNode?.nodeType===Node.TEXT_NODE?r.offsetNode:null},I=function(t){t.dataset.cartdOutline=t.style.outline,t.dataset.cartdBg=t.style.backgroundColor,t.style.outline=`2px solid ${S}`,t.style.backgroundColor=B},T=function(t){t.style.outline=t.dataset.cartdOutline??\"\",t.style.backgroundColor=t.dataset.cartdBg??\"\",delete t.dataset.cartdOutline,delete t.dataset.cartdBg},R=function(t,e,n){let r=L();r.appendChild(u(\"div\",{style:\"font-size:11px;color:#a8a29e;letter-spacing:0.08em;text-transform:uppercase;margin-bottom:10px\"},`Found in ${t.length} places \\u2014 pick one`)),t.forEach(s=>{let i=u(\"div\",{style:\"padding:8px 10px;border-radius:4px;cursor:pointer;font-size:12px;font-family:monospace;color:#e2e8f0;margin-bottom:2px\"},`${v(s.file)}:${s.line}`);i.addEventListener(\"mouseenter\",()=>{i.style.background=\"#2d2d2d\"}),i.addEventListener(\"mouseleave\",()=>{i.style.background=\"\"}),i.addEventListener(\"click\",f=>{f.stopPropagation(),E(s,e,n)}),r.appendChild(i)}),k(r),C(r)},E=function(t,e,n){let r=L();r.appendChild(u(\"div\",{style:\"font-size:11px;color:#a8a29e;letter-spacing:0.06em;margin-bottom:12px;font-family:monospace\"},v(t.file)+\":\"+t.line));let s=n.includes(`\n`)||n.length>60,i;if(s){let o=document.createElement(\"textarea\");o.value=n,o.rows=Math.min(Math.max(n.split(`\n`).length,2),6),o.style.cssText=M()+\"resize:vertical;\",i=o}else{let o=document.createElement(\"input\");o.type=\"text\",o.value=n,o.style.cssText=M(),i=o}i.addEventListener(\"click\",o=>o.stopPropagation()),i.addEventListener(\"keydown\",o=>{o.key===\"Enter\"&&!o.shiftKey&&!s&&(o.preventDefault(),H()),o.key===\"Escape\"&&p(),o.stopPropagation()}),r.appendChild(i);let f=u(\"div\",{style:\"display:flex;gap:8px;margin-top:10px\"}),a=u(\"button\",{style:\"flex:1;padding:7px 0;background:#2563eb;color:white;border:none;border-radius:4px;font-size:12px;font-weight:500;cursor:pointer\"},\"Save\"),c=u(\"button\",{style:\"padding:7px 14px;background:transparent;color:#a8a29e;border:1px solid #3f3f46;border-radius:4px;font-size:12px;cursor:pointer\"},\"Cancel\");a.addEventListener(\"click\",o=>{o.stopPropagation(),H()}),c.addEventListener(\"click\",o=>{o.stopPropagation(),p()}),f.appendChild(a),f.appendChild(c),r.appendChild(f),k(r),C(r),setTimeout(()=>{i.focus(),i.select?.()},30);function H(){let o=i.value.trim();if(!o||o===n){p();return}l?.send(JSON.stringify({type:\"change\",payload:{match:t,type:e,newValue:o,cartdId:x?.payload?.cartdId}})),a.textContent=\"Saving\\u2026\",a.style.opacity=\"0.6\",a.disabled=!0}},h=function(t){let e=u(\"div\",{style:\"position:fixed;bottom:20px;left:50%;transform:translateX(-50%);background:#7f1d1d;color:#fca5a5;padding:10px 16px;border-radius:6px;font-size:12px;font-family:system-ui;z-index:2147483647;pointer-events:none\"},t);document.body.appendChild(e),setTimeout(()=>e.remove(),3e3)},L=function(){p();let t=u(\"div\",{style:\"position:fixed;z-index:2147483647;background:#1c1917;border:1px solid #3f3f46;border-radius:8px;padding:14px;width:280px;box-shadow:0 8px 32px rgba(0,0,0,0.5);font-family:system-ui,-apple-system,sans-serif;box-sizing:border-box\"});return t.dataset.cartdPanel=\"1\",t},k=function(t){if(!x)return;let{rect:e}=x,n=280,r=200,s=e.bottom+8,i=e.left;i+n>window.innerWidth-8&&(i=window.innerWidth-n-8),i<8&&(i=8),s+r>window.innerHeight-8&&(s=e.top-r-8),s<8&&(s=8),t.style.top=`${s}px`,t.style.left=`${i}px`},C=function(t){document.body.appendChild(t),g=t,m=!0,d&&(T(d),d=null)},p=function(){g?.remove(),g=null,m=!1},M=function(){return\"width:100%;background:#0c0a09;border:1px solid #3f3f46;border-radius:4px;color:#fafaf9;font-size:13px;padding:8px 10px;box-sizing:border-box;outline:none;font-family:system-ui,-apple-system,sans-serif;\"},v=function(t){return t.split(\"/\").slice(-2).join(\"/\")},u=function(t,e,n){let r=document.createElement(t);for(let[s,i]of Object.entries(e))r.setAttribute(s,i);return n&&(r.textContent=n),r},O=function(t){let e=t?document.querySelector(`[data-cartd-id=\"${t}\"]`):null;if(!e)return;let n=e.style.backgroundColor;e.style.transition=\"background-color 0.3s\",e.style.backgroundColor=P,setTimeout(()=>{e.style.backgroundColor=n},1400)};D=b,G=N,W=w,A=_,X=I,$=T,F=R,j=E,J=h,U=L,Y=k,q=C,K=p,Q=M,Z=v,V=u,tt=O;let l=null,y=1e3,d=null,x=null,g=null,m=!1;document.addEventListener(\"mouseover\",t=>{if(m)return;let e=t.target;!e||e.nodeType!==1||g?.contains(e)||(d&&d!==e&&T(d),d=e,I(e))},{capture:!0}),document.addEventListener(\"mouseout\",t=>{if(m)return;let e=t.target;e===d&&(T(e),d=null)},{capture:!0}),document.addEventListener(\"click\",t=>{if(g&&g.contains(t.target))return;if(m){p(),t.preventDefault(),t.stopPropagation();return}let e=w(t);if(!e)return;t.preventDefault(),t.stopPropagation();let n={tagName:e.el.tagName.toLowerCase(),type:e.type,textContent:e.text??\"\",src:e.src,cartdId:e.el.dataset.cartdId??void 0,className:e.el.className,rect:{x:e.rect.x,y:e.rect.y,width:e.rect.width,height:e.rect.height,top:e.rect.top,left:e.rect.left,bottom:e.rect.bottom,right:e.rect.right}};x={payload:n,rect:e.rect},l?.send(JSON.stringify({type:\"element-clicked\",payload:n}))},{capture:!0}),document.addEventListener(\"keydown\",t=>{t.key===\"Escape\"&&m&&p()}),b()}var D,G,W,A,X,$,F,j,J,U,Y,q,K,Q,Z,V,tt;})();\n";
3
+ //# sourceMappingURL=injected-content.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"injected-content.js","sourceRoot":"","sources":["../../src/injected-content.ts"],"names":[],"mappings":"AAAA,+BAA+B;AAC/B,MAAM,CAAC,MAAM,eAAe,GAAG,wsOAAwsO,CAAA"}
@@ -0,0 +1,6 @@
1
+ import type { SearchMatch, ChangePayload } from '@ecom-baas/types';
2
+ export interface PatchResult {
3
+ cartdId: string;
4
+ }
5
+ export declare function patch(match: SearchMatch, change: ChangePayload): PatchResult;
6
+ //# sourceMappingURL=patcher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"patcher.d.ts","sourceRoot":"","sources":["../../src/patcher.ts"],"names":[],"mappings":"AASA,OAAO,KAAK,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAOlE,MAAM,WAAW,WAAW;IAC1B,OAAO,EAAE,MAAM,CAAA;CAChB;AAED,wBAAgB,KAAK,CAAC,KAAK,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,GAAG,WAAW,CAc5E"}