inkmap-mcp 0.3.18 → 0.3.19

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.
@@ -57,6 +57,52 @@ function hasAccess(state, now = Date.now()) {
57
57
  return state.pro || (state.trialUntil ?? 0) > now;
58
58
  }
59
59
 
60
+ // packages/core/dist/images.js
61
+ var MAX_IMAGE_BYTES = 10 * 1024 * 1024;
62
+ var startsWith = (bytes, signature, offset = 0) => [...signature].every((char, i) => bytes[offset + i] === char.charCodeAt(0));
63
+ function sniffImage(bytes) {
64
+ if (startsWith(bytes, "\x89PNG\r\n\n"))
65
+ return "png";
66
+ if (startsWith(bytes, "\xFF\xD8\xFF"))
67
+ return "jpg";
68
+ if (startsWith(bytes, "GIF87a") || startsWith(bytes, "GIF89a"))
69
+ return "gif";
70
+ if (startsWith(bytes, "RIFF") && startsWith(bytes, "WEBP", 8))
71
+ return "webp";
72
+ return void 0;
73
+ }
74
+ function decodeImageDataUrl(dataUrl) {
75
+ const match = typeof dataUrl === "string" ? /^data:[\w.+/-]*;base64,([A-Za-z0-9+/]*={0,2})$/.exec(dataUrl) : null;
76
+ if (!match)
77
+ return { problem: "type" };
78
+ if (match[1].length * 3 / 4 - 2 > MAX_IMAGE_BYTES)
79
+ return { problem: "size" };
80
+ let binary;
81
+ try {
82
+ binary = atob(match[1]);
83
+ } catch {
84
+ return { problem: "type" };
85
+ }
86
+ if (binary.length > MAX_IMAGE_BYTES)
87
+ return { problem: "size" };
88
+ const bytes = Uint8Array.from(binary, (char) => char.charCodeAt(0));
89
+ const extension = sniffImage(bytes);
90
+ return extension ? { bytes, extension } : { problem: "type" };
91
+ }
92
+ function imageFolderName(documentFileName) {
93
+ const stem = documentFileName.replace(/\.(?:md|markdown)$/i, "").trim();
94
+ return `${/^\.*$/.test(stem) ? "images" : stem}.assets`;
95
+ }
96
+ function imageFileName(when, extension, attempt = 1) {
97
+ const two = (n) => String(n).padStart(2, "0");
98
+ const stamp = `${when.getFullYear()}${two(when.getMonth() + 1)}${two(when.getDate())}-${two(when.getHours())}${two(when.getMinutes())}${two(when.getSeconds())}`;
99
+ return `image-${stamp}${attempt > 1 ? `-${attempt}` : ""}.${extension}`;
100
+ }
101
+ function imageLinkPath(folder, file) {
102
+ const encode = (part) => part.replace(/[%\s()<>#?[\]\\"]/g, (char) => encodeURIComponent(char).replace(/\(/g, "%28").replace(/\)/g, "%29"));
103
+ return `${encode(folder)}/${encode(file)}`;
104
+ }
105
+
60
106
  // packages/core/dist/index.js
61
107
  function sanitizeViewState(raw) {
62
108
  if (!raw || typeof raw !== "object")
@@ -85,9 +131,9 @@ function sanitizeViewState(raw) {
85
131
  // packages/vscode/src/extension.ts
86
132
  var import_node_child_process4 = require("node:child_process");
87
133
  var import_node_fs2 = require("node:fs");
88
- var import_promises5 = require("node:fs/promises");
134
+ var import_promises6 = require("node:fs/promises");
89
135
  var import_node_os4 = require("node:os");
90
- var import_node_path4 = require("node:path");
136
+ var import_node_path5 = require("node:path");
91
137
  var vscode5 = __toESM(require("vscode"));
92
138
 
93
139
  // packages/vscode/src/browser.ts
@@ -97,11 +143,20 @@ var vscode2 = __toESM(require("vscode"));
97
143
  // packages/cli/src/server.ts
98
144
  var import_node_crypto2 = require("node:crypto");
99
145
  var import_node_fs = require("node:fs");
100
- var import_promises3 = require("node:fs/promises");
146
+ var import_promises4 = require("node:fs/promises");
101
147
  var import_node_http = require("node:http");
102
148
  var import_node_os3 = require("node:os");
149
+ var import_node_path4 = require("node:path");
150
+
151
+ // packages/cli/src/image-assets.ts
152
+ var import_promises3 = require("node:fs/promises");
103
153
  var import_node_path3 = require("node:path");
104
154
 
155
+ // packages/cli/src/workspace-fs.ts
156
+ var import_promises2 = require("node:fs/promises");
157
+ var import_node_os2 = require("node:os");
158
+ var import_node_path2 = require("node:path");
159
+
105
160
  // packages/cli/src/license.ts
106
161
  var import_node_child_process = require("node:child_process");
107
162
  var import_promises = require("node:fs/promises");
@@ -110,7 +165,7 @@ var import_node_os = require("node:os");
110
165
  var import_node_path = require("node:path");
111
166
 
112
167
  // packages/cli/src/version.ts
113
- var INKMAP_VERSION = "0.3.18";
168
+ var INKMAP_VERSION = "0.3.19";
114
169
 
115
170
  // packages/cli/src/license.ts
116
171
  var ZH_LOCALE_RE = /^zh(?:[-_.]|$)/i;
@@ -1066,37 +1121,8 @@ async function localTrialDeadline() {
1066
1121
  return Number.isSafeInteger(started) && started > 0 && started <= Date.now() ? started + TRIAL_MS : void 0;
1067
1122
  }
1068
1123
 
1069
- // packages/cli/src/open-browser.ts
1070
- var import_node_child_process2 = require("node:child_process");
1071
- function run(cmd, args, launched = false) {
1072
- return new Promise((done) => {
1073
- const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1074
- child.on("error", () => done(false));
1075
- if (launched) child.on("spawn", () => done(true));
1076
- else child.on("exit", (code) => done(code === 0));
1077
- child.unref();
1078
- });
1079
- }
1080
- async function openBrowserWindow(url) {
1081
- if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url)) return;
1082
- if (process.platform === "darwin") {
1083
- if (await run("open", ["-a", "Google Chrome", url])) return;
1084
- await run("open", [url]);
1085
- return;
1086
- }
1087
- if (process.platform === "win32") {
1088
- if (await run("cmd", ["/c", "start", "", "chrome", url])) return;
1089
- await run("cmd", ["/c", "start", "", url]);
1090
- return;
1091
- }
1092
- if (await run("google-chrome", [url], true)) return;
1093
- await run("xdg-open", [url], true);
1094
- }
1095
-
1096
1124
  // packages/cli/src/workspace-fs.ts
1097
- var import_promises2 = require("node:fs/promises");
1098
- var import_node_os2 = require("node:os");
1099
- var import_node_path2 = require("node:path");
1125
+ var say = (zh2, en2) => detectOsLocale() === "zh" ? zh2 : en2;
1100
1126
  var MAX_MARKDOWN_BYTES = 5 * 1024 * 1024;
1101
1127
  var SKIP_SCAN_DIRS = /* @__PURE__ */ new Set([
1102
1128
  ".git",
@@ -1182,6 +1208,53 @@ async function scanMarkdownFiles(rootDir, { maxFiles = 200, maxDepth = 4, byRece
1182
1208
  return found;
1183
1209
  }
1184
1210
 
1211
+ // packages/cli/src/image-assets.ts
1212
+ async function saveImageAsset(documentDir, documentFileName, image, when = /* @__PURE__ */ new Date()) {
1213
+ const folder = imageFolderName(documentFileName);
1214
+ const target = (0, import_node_path3.join)(documentDir, folder);
1215
+ await (0, import_promises3.mkdir)(target, { recursive: true });
1216
+ if (!insideOrEqual(await (0, import_promises3.realpath)(documentDir), await (0, import_promises3.realpath)(target))) {
1217
+ throw new Error(say("\u56FE\u7247\u76EE\u5F55\u6307\u5411\u6587\u6863\u76EE\u5F55\u4E4B\u5916\uFF0C\u672A\u4FDD\u5B58\u56FE\u7247\u3002", "The pictures folder leads outside the document's folder, so nothing was saved."));
1218
+ }
1219
+ for (let attempt = 1; attempt <= 100; attempt++) {
1220
+ const name = imageFileName(when, image.extension, attempt);
1221
+ try {
1222
+ await (0, import_promises3.writeFile)((0, import_node_path3.join)(target, name), image.bytes, { flag: "wx" });
1223
+ return imageLinkPath(folder, name);
1224
+ } catch (error) {
1225
+ if (error.code !== "EEXIST") throw error;
1226
+ }
1227
+ }
1228
+ throw new Error(say("\u65E0\u6CD5\u4E3A\u56FE\u7247\u751F\u6210\u65B0\u7684\u6587\u4EF6\u540D\u3002", "Could not find a free file name for the picture."));
1229
+ }
1230
+
1231
+ // packages/cli/src/open-browser.ts
1232
+ var import_node_child_process2 = require("node:child_process");
1233
+ function run(cmd, args, launched = false) {
1234
+ return new Promise((done) => {
1235
+ const child = (0, import_node_child_process2.spawn)(cmd, args, { stdio: "ignore", detached: true });
1236
+ child.on("error", () => done(false));
1237
+ if (launched) child.on("spawn", () => done(true));
1238
+ else child.on("exit", (code) => done(code === 0));
1239
+ child.unref();
1240
+ });
1241
+ }
1242
+ async function openBrowserWindow(url) {
1243
+ if (process.env.INKMAP_NO_OPEN === "1" || !/^http:\/\/(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+\//.test(url)) return;
1244
+ if (process.platform === "darwin") {
1245
+ if (await run("open", ["-a", "Google Chrome", url])) return;
1246
+ await run("open", [url]);
1247
+ return;
1248
+ }
1249
+ if (process.platform === "win32") {
1250
+ if (await run("cmd", ["/c", "start", "", "chrome", url])) return;
1251
+ await run("cmd", ["/c", "start", "", url]);
1252
+ return;
1253
+ }
1254
+ if (await run("google-chrome", [url], true)) return;
1255
+ await run("xdg-open", [url], true);
1256
+ }
1257
+
1185
1258
  // packages/cli/src/server.ts
1186
1259
  var MAX_BODY = 20 * 1024 * 1024;
1187
1260
  var TYPES = {
@@ -1211,49 +1284,49 @@ var HttpError = class extends Error {
1211
1284
  var LOOPBACK_HOST = /^(?:127\.0\.0\.1|localhost|\[::1\]):[0-9]+$/i;
1212
1285
  var hash = (s) => (0, import_node_crypto2.createHash)("sha1").update(s).digest("hex");
1213
1286
  function docName(path2) {
1214
- return (0, import_node_path3.basename)(path2).replace(/\.md$/i, "").replace(/\.markmap$/i, "");
1287
+ return (0, import_node_path4.basename)(path2).replace(/\.md$/i, "").replace(/\.markmap$/i, "");
1215
1288
  }
1216
1289
  function viewStateFile(key) {
1217
- const base = process.env.INKMAP_HOME || (0, import_node_path3.join)((0, import_node_os3.homedir)(), ".inkmap");
1218
- return (0, import_node_path3.join)(base, "view-state", hash(key) + ".json");
1290
+ const base = process.env.INKMAP_HOME || (0, import_node_path4.join)((0, import_node_os3.homedir)(), ".inkmap");
1291
+ return (0, import_node_path4.join)(base, "view-state", hash(key) + ".json");
1219
1292
  }
1220
1293
  async function readDiskViewState(key) {
1221
1294
  try {
1222
- return sanitizeViewState(JSON.parse(await (0, import_promises3.readFile)(viewStateFile(key), "utf8")));
1295
+ return sanitizeViewState(JSON.parse(await (0, import_promises4.readFile)(viewStateFile(key), "utf8")));
1223
1296
  } catch {
1224
1297
  return void 0;
1225
1298
  }
1226
1299
  }
1227
1300
  async function writeDiskViewState(key, state) {
1228
1301
  const target = viewStateFile(key);
1229
- await (0, import_promises3.mkdir)((0, import_node_path3.dirname)(target), { recursive: true, mode: 448 });
1302
+ await (0, import_promises4.mkdir)((0, import_node_path4.dirname)(target), { recursive: true, mode: 448 });
1230
1303
  const temp = `${target}.${process.pid}.${Date.now()}`;
1231
1304
  try {
1232
- await (0, import_promises3.writeFile)(temp, JSON.stringify(state), { mode: 384 });
1233
- await (0, import_promises3.rename)(temp, target);
1305
+ await (0, import_promises4.writeFile)(temp, JSON.stringify(state), { mode: 384 });
1306
+ await (0, import_promises4.rename)(temp, target);
1234
1307
  } finally {
1235
- await (0, import_promises3.rm)(temp, { force: true }).catch(() => {
1308
+ await (0, import_promises4.rm)(temp, { force: true }).catch(() => {
1236
1309
  });
1237
1310
  }
1238
1311
  }
1239
1312
  async function fileSource(file, log = () => {
1240
1313
  }) {
1241
- const path2 = await (0, import_promises3.realpath)((0, import_node_path3.resolve)(file)).catch(() => (0, import_node_path3.resolve)(file));
1242
- if (!(await (0, import_promises3.stat)(path2)).isFile()) throw new Error(`\u4E0D\u662F\u6587\u4EF6\uFF1A${path2}`);
1243
- const dir = (0, import_node_path3.dirname)(path2);
1314
+ const path2 = await (0, import_promises4.realpath)((0, import_node_path4.resolve)(file)).catch(() => (0, import_node_path4.resolve)(file));
1315
+ if (!(await (0, import_promises4.stat)(path2)).isFile()) throw new Error(`\u4E0D\u662F\u6587\u4EF6\uFF1A${path2}`);
1316
+ const dir = (0, import_node_path4.dirname)(path2);
1244
1317
  return {
1245
1318
  name: docName(path2),
1246
1319
  key: path2,
1247
1320
  dir,
1248
- read: () => (0, import_promises3.readFile)(path2, "utf8"),
1321
+ read: () => (0, import_promises4.readFile)(path2, "utf8"),
1249
1322
  async write(md) {
1250
- await (0, import_promises3.writeFile)(path2, md, "utf8");
1323
+ await (0, import_promises4.writeFile)(path2, md, "utf8");
1251
1324
  log(`\u5DF2\u5199\u56DE ${path2}`);
1252
1325
  },
1253
1326
  watch(onChange) {
1254
1327
  try {
1255
1328
  const watcher = (0, import_node_fs.watch)(dir, (_, changed) => {
1256
- if (!changed || changed === (0, import_node_path3.basename)(path2)) onChange();
1329
+ if (!changed || changed === (0, import_node_path4.basename)(path2)) onChange();
1257
1330
  });
1258
1331
  watcher.on("error", () => {
1259
1332
  });
@@ -1274,9 +1347,9 @@ function within(root, rel, allowAbsoluteInRoot = false) {
1274
1347
  } catch {
1275
1348
  return null;
1276
1349
  }
1277
- const resolvedRoot = (0, import_node_path3.resolve)(root);
1278
- const base = resolvedRoot.endsWith(import_node_path3.sep) ? resolvedRoot : resolvedRoot + import_node_path3.sep;
1279
- const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? (0, import_node_path3.normalize)(decoded) : (0, import_node_path3.normalize)((0, import_node_path3.join)(resolvedRoot, decoded));
1350
+ const resolvedRoot = (0, import_node_path4.resolve)(root);
1351
+ const base = resolvedRoot.endsWith(import_node_path4.sep) ? resolvedRoot : resolvedRoot + import_node_path4.sep;
1352
+ const full = allowAbsoluteInRoot && /^(?:[\\/]|[A-Za-z]:[\\/])/.test(decoded) ? (0, import_node_path4.normalize)(decoded) : (0, import_node_path4.normalize)((0, import_node_path4.join)(resolvedRoot, decoded));
1280
1353
  return full.startsWith(base) ? full : null;
1281
1354
  }
1282
1355
  async function serve({
@@ -1345,19 +1418,19 @@ data: ${JSON.stringify(data)}
1345
1418
  }), 80);
1346
1419
  };
1347
1420
  let unwatch = activeSource.watch(scheduleRefresh);
1348
- const canonicalActiveKey = async () => activeSource.key ? await (0, import_promises3.realpath)(activeSource.key).catch(() => activeSource.key) : void 0;
1421
+ const canonicalActiveKey = async () => activeSource.key ? await (0, import_promises4.realpath)(activeSource.key).catch(() => activeSource.key) : void 0;
1349
1422
  async function collectWorkspaceFiles() {
1350
1423
  const roots = /* @__PURE__ */ new Map();
1351
1424
  if (activeSource.key && !confineToWorkspaceRoots) {
1352
- const realKey = await (0, import_promises3.realpath)(activeSource.key).catch(() => activeSource.key);
1353
- const projRoot = await (0, import_promises3.realpath)(await findProjectRoot(realKey)).catch(() => (0, import_node_path3.dirname)(realKey));
1354
- roots.set(projRoot, { path: projRoot, name: (0, import_node_path3.basename)(projRoot), active: true });
1425
+ const realKey = await (0, import_promises4.realpath)(activeSource.key).catch(() => activeSource.key);
1426
+ const projRoot = await (0, import_promises4.realpath)(await findProjectRoot(realKey)).catch(() => (0, import_node_path4.dirname)(realKey));
1427
+ roots.set(projRoot, { path: projRoot, name: (0, import_node_path4.basename)(projRoot), active: true });
1355
1428
  }
1356
- const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(import_node_path3.delimiter)].filter(Boolean);
1429
+ const envRoots = [...workspaceRoots, ...(process.env.INKMAP_WORKSPACES || "").split(import_node_path4.delimiter)].filter(Boolean);
1357
1430
  for (const raw of envRoots) {
1358
- const real = await (0, import_promises3.realpath)((0, import_node_path3.resolve)(raw)).catch(() => null);
1431
+ const real = await (0, import_promises4.realpath)((0, import_node_path4.resolve)(raw)).catch(() => null);
1359
1432
  if (real && !roots.has(real)) {
1360
- roots.set(real, { path: real, name: (0, import_node_path3.basename)(real), active: roots.size === 0 });
1433
+ roots.set(real, { path: real, name: (0, import_node_path4.basename)(real), active: roots.size === 0 });
1361
1434
  }
1362
1435
  }
1363
1436
  const items = [];
@@ -1367,7 +1440,7 @@ data: ${JSON.stringify(data)}
1367
1440
  for (const f of files) {
1368
1441
  if (seen.has(f)) continue;
1369
1442
  seen.add(f);
1370
- const rel = (0, import_node_path3.relative)(root.path, f);
1443
+ const rel = (0, import_node_path4.relative)(root.path, f);
1371
1444
  items.push({
1372
1445
  path: f,
1373
1446
  label: `${root.name} / ${rel}`,
@@ -1379,7 +1452,7 @@ data: ${JSON.stringify(data)}
1379
1452
  if (activeSource.key && activeReal && !seen.has(activeReal)) {
1380
1453
  items.unshift({
1381
1454
  path: activeSource.key,
1382
- label: `${(0, import_node_path3.basename)(activeSource.dir)} / ${(0, import_node_path3.basename)(activeSource.key)}`,
1455
+ label: `${(0, import_node_path4.basename)(activeSource.dir)} / ${(0, import_node_path4.basename)(activeSource.key)}`,
1383
1456
  group: "active"
1384
1457
  });
1385
1458
  }
@@ -1389,10 +1462,10 @@ data: ${JSON.stringify(data)}
1389
1462
  async function switchSourceToFile(candidatePath, trustCaller = false) {
1390
1463
  const notMarkdown = () => new HttpError(400, zh2() ? "\u8BF7\u9009\u62E9 .md \u6216 .markmap.md \u6587\u4EF6\u3002" : "Choose a .md or .markmap.md file.");
1391
1464
  if (!candidatePath || typeof candidatePath !== "string" || !/\.md$/i.test(candidatePath)) throw notMarkdown();
1392
- const resolvedCandidate = (0, import_node_path3.resolve)(candidatePath);
1393
- const rawStat = await (0, import_promises3.lstat)(resolvedCandidate).catch(() => null);
1394
- const realTarget = await (0, import_promises3.realpath)(resolvedCandidate).catch(() => null);
1395
- const targetStat = realTarget ? await (0, import_promises3.stat)(realTarget).catch(() => null) : null;
1465
+ const resolvedCandidate = (0, import_node_path4.resolve)(candidatePath);
1466
+ const rawStat = await (0, import_promises4.lstat)(resolvedCandidate).catch(() => null);
1467
+ const realTarget = await (0, import_promises4.realpath)(resolvedCandidate).catch(() => null);
1468
+ const targetStat = realTarget ? await (0, import_promises4.stat)(realTarget).catch(() => null) : null;
1396
1469
  if (!rawStat || rawStat.isSymbolicLink() && !trustCaller || !realTarget || !targetStat?.isFile() || targetStat.size > MAX_MARKDOWN_BYTES) {
1397
1470
  throw new HttpError(403, zh2() ? "\u8BF7\u9009\u62E9 5 MiB \u4EE5\u5185\u7684\u666E\u901A Markdown \u6587\u4EF6\u3002" : "Choose a regular Markdown file up to 5 MiB.");
1398
1471
  }
@@ -1440,10 +1513,10 @@ data: ${JSON.stringify(data)}
1440
1513
  const sendFile = async (res, full) => {
1441
1514
  if (!full) return json(res, 403, { error: "forbidden" });
1442
1515
  try {
1443
- const ext = (0, import_node_path3.extname)(full).toLowerCase();
1516
+ const ext = (0, import_node_path4.extname)(full).toLowerCase();
1444
1517
  if (ext === ".html") {
1445
1518
  const osLoc = detectOsLocale();
1446
- const htmlText = (await (0, import_promises3.readFile)(full, "utf8")).replace(
1519
+ const htmlText = (await (0, import_promises4.readFile)(full, "utf8")).replace(
1447
1520
  /<html\b([^>]*)>/i,
1448
1521
  () => `<html lang="${osLoc === "zh" ? "zh-CN" : "en"}" data-os-locale="${osLoc}">`
1449
1522
  );
@@ -1451,7 +1524,7 @@ data: ${JSON.stringify(data)}
1451
1524
  res.end(htmlText, "utf8");
1452
1525
  return;
1453
1526
  }
1454
- const body = await (0, import_promises3.readFile)(full);
1527
+ const body = await (0, import_promises4.readFile)(full);
1455
1528
  const headers = {
1456
1529
  "content-type": TYPES[ext] ?? "application/octet-stream",
1457
1530
  "cache-control": sidebar ? "no-store" : "no-cache"
@@ -1537,6 +1610,18 @@ data: ${JSON.stringify(data)}
1537
1610
  return json(res, 200, { version });
1538
1611
  });
1539
1612
  }
1613
+ if (url.pathname === "/api/image" && req.method === "POST") {
1614
+ if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
1615
+ const image = decodeImageDataUrl(JSON.parse(await readBody(req)).dataUrl);
1616
+ if ("problem" in image) {
1617
+ return json(res, image.problem === "size" ? 413 : 415, { error: image.problem });
1618
+ }
1619
+ if (!hasAccess(await license?.state() ?? { pro: false })) return json(res, 403, { error: "Inkmap trial expired" });
1620
+ return await serialized(async () => {
1621
+ const name = activeSource.key ? (0, import_node_path4.basename)(activeSource.key) : activeSource.name;
1622
+ return json(res, 200, { path: await saveImageAsset(activeSource.dir, name, image) });
1623
+ });
1624
+ }
1540
1625
  if (url.pathname === "/api/license" && req.method === "GET") return json(res, 200, await license?.state({ forUi: true }) ?? { pro: false });
1541
1626
  if (url.pathname === "/api/open" && req.method === "POST") {
1542
1627
  if (!sameOriginWrite()) return json(res, 403, { error: "forbidden" });
@@ -1632,8 +1717,8 @@ data: ${JSON.stringify(data)}
1632
1717
  if (url.pathname.startsWith("/doc-assets/")) {
1633
1718
  let asset = within(activeSource.dir, url.pathname.slice("/doc-assets/".length), true);
1634
1719
  if (asset) {
1635
- const root = await (0, import_promises3.realpath)(activeSource.dir).catch(() => null);
1636
- asset = await (0, import_promises3.realpath)(asset).catch(() => null);
1720
+ const root = await (0, import_promises4.realpath)(activeSource.dir).catch(() => null);
1721
+ asset = await (0, import_promises4.realpath)(asset).catch(() => null);
1637
1722
  const allowedExt = sidebar ? /\.(?:png|jpe?g|gif|webp|avif|bmp|ico)$/i : /\.(?:png|jpe?g|gif|webp|avif|bmp|ico|svg)$/i;
1638
1723
  if (!root || !asset || !insideOrEqual(root, asset) || !allowedExt.test(asset)) asset = null;
1639
1724
  }
@@ -1782,6 +1867,8 @@ var zh = {
1782
1867
  trialExpired: "7 \u5929\u8BD5\u7528\u5DF2\u7ED3\u675F\u3002\u8BF7\u8D2D\u4E70 Pro\uFF0C\u6216\u767B\u5F55\u5DF2\u8D2D\u4E70 Pro \u7684\u8D26\u53F7\u3002",
1783
1868
  checkoutFailed: "\u65E0\u6CD5\u6253\u5F00\u8D2D\u4E70\u9875\u9762\u3002",
1784
1869
  saveExport: "\u5BFC\u51FA",
1870
+ saveBeforeImage: "\u8BF7\u5148\u4FDD\u5B58\u8FD9\u4E2A\u6587\u6863\uFF0C\u518D\u7C98\u8D34\u56FE\u7247\u3002",
1871
+ saveFailedImage: "\u65E0\u6CD5\u4E3A\u56FE\u7247\u751F\u6210\u65B0\u7684\u6587\u4EF6\u540D\u3002",
1785
1872
  onboardingTip: "\u{1F4A1} Inkmap \u601D\u7EF4\u5BFC\u56FE\u5DF2\u5C31\u7EEA\uFF1A\u70B9\u51FB\u5373\u53EF\u5728\u53F3\u4FA7\u5E76\u6392\u6253\u5F00\u53EF\u53CC\u5411\u7F16\u8F91\u7684\u8111\u56FE\u4E0E\u6D41\u7A0B\u56FE",
1786
1873
  onboardingAction: "\u7ACB\u5373\u6253\u5F00\u601D\u7EF4\u5BFC\u56FE",
1787
1874
  welcomeTip: "\u{1F4A1} Inkmap \u601D\u7EF4\u5BFC\u56FE\u5DF2\u5B89\u88C5\uFF1A\u4E00\u952E\u6253\u5F00\u793A\u4F8B\u8111\u56FE\u4F53\u9A8C\u53CC\u5411\u7F16\u8F91\uFF0C\u6216\u5728\u4EFB\u610F .md \u6587\u4EF6\u70B9\u51FB\u53F3\u4E0B\u89D2\u300C\u601D\u7EF4\u5BFC\u56FE\u300D",
@@ -1832,6 +1919,8 @@ var en = {
1832
1919
  trialExpired: "Your 7-day trial has ended. Buy Pro or sign in to an account that has Pro.",
1833
1920
  checkoutFailed: "Could not open checkout.",
1834
1921
  saveExport: "Export",
1922
+ saveBeforeImage: "Save this document first, then paste the picture.",
1923
+ saveFailedImage: "Could not find a free file name for the picture.",
1835
1924
  onboardingTip: "\u{1F4A1} Inkmap is ready: Open this Markdown file side-by-side as an interactive two-way mind map",
1836
1925
  onboardingAction: "Open Mind Map",
1837
1926
  welcomeTip: "\u{1F4A1} Inkmap Mind Map is installed: Try the interactive welcome mind map, or click \u201CMind Map\u201D in the status bar on any .md file",
@@ -1982,7 +2071,7 @@ async function openCheckout(license, mode, localeHint) {
1982
2071
 
1983
2072
  // packages/vscode/src/mindmapEditor.ts
1984
2073
  var import_node_crypto3 = require("node:crypto");
1985
- var import_promises4 = require("node:fs/promises");
2074
+ var import_promises5 = require("node:fs/promises");
1986
2075
  var vscode4 = __toESM(require("vscode"));
1987
2076
 
1988
2077
  // packages/vscode/src/html.ts
@@ -2152,6 +2241,12 @@ var MindmapEditorProvider = class {
2152
2241
  this.maybeOfferReview(edits);
2153
2242
  return post({ type: "saved", id: msg.id, version: String(document.version) });
2154
2243
  }
2244
+ case "saveImage":
2245
+ try {
2246
+ return post({ type: "imageSaved", id: msg.id, path: await saveImage(document, msg.dataUrl) });
2247
+ } catch (error) {
2248
+ return post({ type: "error", id: msg.id, message: error instanceof Error ? error.message : String(error) });
2249
+ }
2155
2250
  case "undo":
2156
2251
  case "redo":
2157
2252
  return vscode4.commands.executeCommand(msg.type);
@@ -2249,6 +2344,25 @@ var MindmapEditorProvider = class {
2249
2344
  });
2250
2345
  }
2251
2346
  };
2347
+ async function saveImage(document, dataUrl) {
2348
+ const image = decodeImageDataUrl(dataUrl);
2349
+ if ("problem" in image) throw new Error(image.problem);
2350
+ if (document.uri.scheme === "untitled") throw new Error(t("saveBeforeImage"));
2351
+ const fileName = document.uri.path.slice(document.uri.path.lastIndexOf("/") + 1);
2352
+ const folder = imageFolderName(fileName);
2353
+ const directory = vscode4.Uri.joinPath(document.uri, "..", folder);
2354
+ await vscode4.workspace.fs.createDirectory(directory);
2355
+ const now = /* @__PURE__ */ new Date();
2356
+ for (let attempt = 1; attempt <= 100; attempt++) {
2357
+ const name = imageFileName(now, image.extension, attempt);
2358
+ const target = vscode4.Uri.joinPath(directory, name);
2359
+ const taken = await vscode4.workspace.fs.stat(target).then(() => true, () => false);
2360
+ if (taken) continue;
2361
+ await vscode4.workspace.fs.writeFile(target, image.bytes);
2362
+ return imageLinkPath(folder, name);
2363
+ }
2364
+ throw new Error(t("saveFailedImage"));
2365
+ }
2252
2366
  async function saveDataUrl(name, dataUrl, dir) {
2253
2367
  const match = dataUrl.match(/^data:([^;,]+)?(;base64)?,(.*)$/s);
2254
2368
  if (!match) return false;
@@ -2264,7 +2378,7 @@ async function saveDataUrl(name, dataUrl, dir) {
2264
2378
  return true;
2265
2379
  }
2266
2380
  async function editorHtml(webview, webRoot, assets) {
2267
- return webviewHtml(await (0, import_promises4.readFile)(vscode4.Uri.joinPath(webRoot, "index.html").fsPath, "utf8"), {
2381
+ return webviewHtml(await (0, import_promises5.readFile)(vscode4.Uri.joinPath(webRoot, "index.html").fsPath, "utf8"), {
2268
2382
  webBase: webview.asWebviewUri(webRoot).toString(),
2269
2383
  assetBase: assets ? webview.asWebviewUri(assets).toString() + "/" : "",
2270
2384
  cspSource: webview.cspSource,
@@ -2276,14 +2390,14 @@ async function editorHtml(webview, webRoot, assets) {
2276
2390
  // packages/vscode/src/extension.ts
2277
2391
  function insideOrEqual2(root, target) {
2278
2392
  if (root === target) return true;
2279
- const rel = (0, import_node_path4.relative)(root, target);
2280
- return Boolean(rel && !(0, import_node_path4.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(".." + import_node_path4.sep));
2393
+ const rel = (0, import_node_path5.relative)(root, target);
2394
+ return Boolean(rel && !(0, import_node_path5.isAbsolute)(rel) && rel !== ".." && !rel.startsWith(".." + import_node_path5.sep));
2281
2395
  }
2282
2396
  function resolveEditorUri(filePath) {
2283
2397
  for (const folder of vscode5.workspace.workspaceFolders ?? []) {
2284
2398
  const folderPath = folder.uri.fsPath || folder.uri.path;
2285
2399
  if (folderPath && insideOrEqual2(folderPath, filePath)) {
2286
- const rel = (0, import_node_path4.relative)(folderPath, filePath).split(import_node_path4.sep).join("/");
2400
+ const rel = (0, import_node_path5.relative)(folderPath, filePath).split(import_node_path5.sep).join("/");
2287
2401
  return rel ? vscode5.Uri.joinPath(folder.uri, rel) : folder.uri;
2288
2402
  }
2289
2403
  }
@@ -2301,7 +2415,7 @@ function findColumnForFile(fileUri) {
2301
2415
  if (input?.uri && (input.uri.fsPath === targetFs || input.uri.path === targetFs)) {
2302
2416
  return group.viewColumn;
2303
2417
  }
2304
- if (tab.label && targetFs.endsWith(import_node_path4.sep + tab.label.replace(/^Preview\s+/i, ""))) {
2418
+ if (tab.label && targetFs.endsWith(import_node_path5.sep + tab.label.replace(/^Preview\s+/i, ""))) {
2305
2419
  return group.viewColumn;
2306
2420
  }
2307
2421
  }
@@ -2337,15 +2451,15 @@ async function openFileInEditorPane(filePath) {
2337
2451
  });
2338
2452
  }
2339
2453
  function startMcpTargetBridge() {
2340
- const inkmapDir = process.env.INKMAP_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".inkmap");
2341
- const targetPath = (0, import_node_path4.join)(inkmapDir, "antigravity-target.json");
2342
- const ackPath = (0, import_node_path4.join)(inkmapDir, "antigravity-target-ack.json");
2454
+ const inkmapDir = process.env.INKMAP_HOME || (0, import_node_path5.join)((0, import_node_os4.homedir)(), ".inkmap");
2455
+ const targetPath = (0, import_node_path5.join)(inkmapDir, "antigravity-target.json");
2456
+ const ackPath = (0, import_node_path5.join)(inkmapDir, "antigravity-target-ack.json");
2343
2457
  let lastSeq = Date.now() - 1e4;
2344
2458
  let debounceTimer;
2345
2459
  let disposed = false;
2346
2460
  const syncInitialSeq = async () => {
2347
2461
  try {
2348
- const raw = JSON.parse(await (0, import_promises5.readFile)(targetPath, "utf8"));
2462
+ const raw = JSON.parse(await (0, import_promises6.readFile)(targetPath, "utf8"));
2349
2463
  if (typeof raw?.seq === "number" && raw.seq < Date.now() - 8e3) {
2350
2464
  lastSeq = raw.seq;
2351
2465
  }
@@ -2355,7 +2469,7 @@ function startMcpTargetBridge() {
2355
2469
  };
2356
2470
  const alreadyAcked = async (seq) => {
2357
2471
  try {
2358
- const ack = JSON.parse(await (0, import_promises5.readFile)(ackPath, "utf8"));
2472
+ const ack = JSON.parse(await (0, import_promises6.readFile)(ackPath, "utf8"));
2359
2473
  return Boolean(ack && ack.ok === true && Number(ack.seq) >= seq);
2360
2474
  } catch {
2361
2475
  return false;
@@ -2365,7 +2479,7 @@ function startMcpTargetBridge() {
2365
2479
  if (disposed) return;
2366
2480
  let claimedSeq = 0;
2367
2481
  try {
2368
- const raw = JSON.parse(await (0, import_promises5.readFile)(targetPath, "utf8"));
2482
+ const raw = JSON.parse(await (0, import_promises6.readFile)(targetPath, "utf8"));
2369
2483
  if (!raw || raw.openInEditorPane !== true) return;
2370
2484
  const seq = Number(raw.seq) || 0;
2371
2485
  if (seq <= lastSeq || typeof raw.file !== "string" || !/\.md$/i.test(raw.file)) return;
@@ -2373,16 +2487,16 @@ function startMcpTargetBridge() {
2373
2487
  lastSeq = seq;
2374
2488
  return;
2375
2489
  }
2376
- const info = await (0, import_promises5.lstat)(raw.file).catch(() => null);
2490
+ const info = await (0, import_promises6.lstat)(raw.file).catch(() => null);
2377
2491
  if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
2378
- const realTarget = await (0, import_promises5.realpath)(raw.file).catch(() => raw.file);
2492
+ const realTarget = await (0, import_promises6.realpath)(raw.file).catch(() => raw.file);
2379
2493
  if (!/\.md$/i.test(realTarget)) return;
2380
2494
  const folders = vscode5.workspace.workspaceFolders ?? [];
2381
2495
  let matchesFolder = false;
2382
2496
  for (const folder of folders) {
2383
2497
  const folderPath = folder.uri.fsPath || folder.uri.path;
2384
2498
  if (!folderPath) continue;
2385
- const realFolder = await (0, import_promises5.realpath)(folderPath).catch(() => folderPath);
2499
+ const realFolder = await (0, import_promises6.realpath)(folderPath).catch(() => folderPath);
2386
2500
  if (insideOrEqual2(realFolder, realTarget)) {
2387
2501
  matchesFolder = true;
2388
2502
  break;
@@ -2401,7 +2515,7 @@ function startMcpTargetBridge() {
2401
2515
  const editorUrl = localEditorUrl(raw.editorUrl);
2402
2516
  if (editorUrl) await openUrlInEditorPane(editorUrl);
2403
2517
  else await openFileInEditorPane(realTarget);
2404
- await (0, import_promises5.writeFile)(ackPath, JSON.stringify({
2518
+ await (0, import_promises6.writeFile)(ackPath, JSON.stringify({
2405
2519
  seq,
2406
2520
  file: realTarget,
2407
2521
  ok: true,
@@ -2410,7 +2524,7 @@ function startMcpTargetBridge() {
2410
2524
  });
2411
2525
  } catch (err) {
2412
2526
  if (!claimedSeq) return;
2413
- await (0, import_promises5.writeFile)(ackPath, JSON.stringify({
2527
+ await (0, import_promises6.writeFile)(ackPath, JSON.stringify({
2414
2528
  seq: claimedSeq,
2415
2529
  ok: false,
2416
2530
  error: String(err instanceof Error ? err.message : err),
@@ -2451,13 +2565,13 @@ function startMcpTargetBridge() {
2451
2565
  var HARNESS_INDEX_URL = "https://zhiyuanv.com/dsh-index.json";
2452
2566
  var HARNESS_MARKET_BUNDLE = "@deepseek-ai/dsh-experimental-plugin-market-bundle";
2453
2567
  var HARNESS_PROMPTED = "inkmap.deepseekHarnessPrompted";
2454
- var harnessProfileDir = () => (0, import_node_path4.join)(process.env.DSH_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".dsh"), "profiles", "desktop");
2568
+ var harnessProfileDir = () => (0, import_node_path5.join)(process.env.DSH_HOME || (0, import_node_path5.join)((0, import_node_os4.homedir)(), ".dsh"), "profiles", "desktop");
2455
2569
  async function readHarnessProfile(dir) {
2456
- const patchPath = (0, import_node_path4.join)(dir, "cordis.patch.yml");
2457
- const patch = (0, import_node_fs2.existsSync)(patchPath) ? await (0, import_promises5.readFile)(patchPath, "utf8").catch(() => "") : "";
2570
+ const patchPath = (0, import_node_path5.join)(dir, "cordis.patch.yml");
2571
+ const patch = (0, import_node_fs2.existsSync)(patchPath) ? await (0, import_promises6.readFile)(patchPath, "utf8").catch(() => "") : "";
2458
2572
  let pkg;
2459
2573
  try {
2460
- pkg = JSON.parse(await (0, import_promises5.readFile)((0, import_node_path4.join)(dir, "package.json"), "utf8"));
2574
+ pkg = JSON.parse(await (0, import_promises6.readFile)((0, import_node_path5.join)(dir, "package.json"), "utf8"));
2461
2575
  } catch {
2462
2576
  }
2463
2577
  const bundles = pkg?.dsh?.profile?.bundles;
@@ -2474,8 +2588,8 @@ var harnessSetUp = (profile) => !profile.needsIndex && !profile.needsBundle && !
2474
2588
  function harnessCli() {
2475
2589
  return [
2476
2590
  process.platform === "darwin" ? "/Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh" : "",
2477
- process.platform === "darwin" ? (0, import_node_path4.join)((0, import_node_os4.homedir)(), "Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh") : "",
2478
- process.platform === "win32" ? (0, import_node_path4.join)(process.env.LOCALAPPDATA || (0, import_node_path4.join)((0, import_node_os4.homedir)(), "AppData", "Local"), "Programs", "DeepSeek Harness", "resources", "runtime", "cli", "bin", "dsh.cmd") : ""
2591
+ process.platform === "darwin" ? (0, import_node_path5.join)((0, import_node_os4.homedir)(), "Applications/DeepSeek Harness.app/Contents/Resources/runtime/cli/bin/dsh") : "",
2592
+ process.platform === "win32" ? (0, import_node_path5.join)(process.env.LOCALAPPDATA || (0, import_node_path5.join)((0, import_node_os4.homedir)(), "AppData", "Local"), "Programs", "DeepSeek Harness", "resources", "runtime", "cli", "bin", "dsh.cmd") : ""
2479
2593
  ].find((candidate) => candidate && (0, import_node_fs2.existsSync)(candidate));
2480
2594
  }
2481
2595
  function runHarnessCli(cli, args) {
@@ -2511,17 +2625,17 @@ async function installIntoHarness(profile) {
2511
2625
  `;
2512
2626
  const trimmed = profile.patch.trim();
2513
2627
  const next = !trimmed || trimmed === "[]" ? snippet : profile.patch.replace(/\n*$/, "\n\n") + snippet;
2514
- await (0, import_promises5.writeFile)((0, import_node_path4.join)(profile.dir, "cordis.patch.yml"), next, "utf8");
2628
+ await (0, import_promises6.writeFile)((0, import_node_path5.join)(profile.dir, "cordis.patch.yml"), next, "utf8");
2515
2629
  }
2516
2630
  if (profile.needsBundle && profile.pkg?.dsh?.profile?.bundles) {
2517
2631
  profile.pkg.dsh.profile.bundles.push(HARNESS_MARKET_BUNDLE);
2518
- await (0, import_promises5.writeFile)((0, import_node_path4.join)(profile.dir, "package.json"), JSON.stringify(profile.pkg, null, 2) + "\n", "utf8");
2632
+ await (0, import_promises6.writeFile)((0, import_node_path5.join)(profile.dir, "package.json"), JSON.stringify(profile.pkg, null, 2) + "\n", "utf8");
2519
2633
  }
2520
2634
  if (!profile.needsPlugin) return "installed";
2521
2635
  const cli = harnessCli();
2522
2636
  if (!cli) return "configured";
2523
- const staged = (0, import_node_path4.join)(process.env.INKMAP_HOME || (0, import_node_path4.join)((0, import_node_os4.homedir)(), ".inkmap"), "dsh-inkmap");
2524
- await runHarnessCli(cli, ["plugin", "--profile", "desktop", "add", (0, import_node_fs2.existsSync)((0, import_node_path4.join)(staged, "package.json")) ? staged : "dsh-inkmap"]);
2637
+ const staged = (0, import_node_path5.join)(process.env.INKMAP_HOME || (0, import_node_path5.join)((0, import_node_os4.homedir)(), ".inkmap"), "dsh-inkmap");
2638
+ await runHarnessCli(cli, ["plugin", "--profile", "desktop", "add", (0, import_node_fs2.existsSync)((0, import_node_path5.join)(staged, "package.json")) ? staged : "dsh-inkmap"]);
2525
2639
  return "installed";
2526
2640
  }
2527
2641
  async function installInDeepSeekHarness() {
@@ -2569,10 +2683,10 @@ function activate(context) {
2569
2683
  })
2570
2684
  );
2571
2685
  const openDemo = async () => {
2572
- const dir = context.globalStorageUri?.fsPath || (0, import_node_path4.join)((0, import_node_os4.tmpdir)(), "inkmap-welcome");
2686
+ const dir = context.globalStorageUri?.fsPath || (0, import_node_path5.join)((0, import_node_os4.tmpdir)(), "inkmap-welcome");
2573
2687
  (0, import_node_fs2.mkdirSync)(dir, { recursive: true });
2574
- const demoPath = (0, import_node_path4.join)(dir, "Inkmap-Welcome.md");
2575
- if (!(0, import_node_fs2.existsSync)(demoPath)) await (0, import_promises5.writeFile)(demoPath, t("welcomeDoc"), "utf8");
2688
+ const demoPath = (0, import_node_path5.join)(dir, "Inkmap-Welcome.md");
2689
+ if (!(0, import_node_fs2.existsSync)(demoPath)) await (0, import_promises6.writeFile)(demoPath, t("welcomeDoc"), "utf8");
2576
2690
  await vscode5.commands.executeCommand("vscode.openWith", vscode5.Uri.file(demoPath), MindmapEditorProvider.viewType, {
2577
2691
  viewColumn: vscode5.ViewColumn.Active,
2578
2692
  preserveFocus: false
@@ -2673,8 +2787,8 @@ function activate(context) {
2673
2787
  async handleUri(uri) {
2674
2788
  if (uri.path === "/open") {
2675
2789
  const target = new URLSearchParams(uri.query).get("path")?.trim();
2676
- if (!target || !(0, import_node_path4.isAbsolute)(target) || !/\.md$/i.test(target)) return;
2677
- const info = await (0, import_promises5.lstat)(target).catch(() => null);
2790
+ if (!target || !(0, import_node_path5.isAbsolute)(target) || !/\.md$/i.test(target)) return;
2791
+ const info = await (0, import_promises6.lstat)(target).catch(() => null);
2678
2792
  if (!info || info.isSymbolicLink() || !info.isFile() || info.size > 5 * 1024 * 1024) return;
2679
2793
  await openFileInEditorPane(target).catch(() => {
2680
2794
  });
@@ -2,7 +2,7 @@
2
2
  "name": "inkmap-vscode",
3
3
  "displayName": "%displayName%",
4
4
  "description": "%description%",
5
- "version": "0.3.18",
5
+ "version": "0.3.19",
6
6
  "publisher": "inkmap",
7
7
  "homepage": "https://zhiyuanv.com/software.html",
8
8
  "repository": {