rekix-mcp 0.1.5 → 0.1.6

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/index.js CHANGED
@@ -1,22 +1,5 @@
1
1
  #!/usr/bin/env bun
2
2
  // @bun
3
- var __create = Object.create;
4
- var __getProtoOf = Object.getPrototypeOf;
5
- var __defProp = Object.defineProperty;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __toESM = (mod, isNodeMode, target) => {
9
- target = mod != null ? __create(__getProtoOf(mod)) : {};
10
- const to = isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target;
11
- for (let key of __getOwnPropNames(mod))
12
- if (!__hasOwnProp.call(to, key))
13
- __defProp(to, key, {
14
- get: () => mod[key],
15
- enumerable: true
16
- });
17
- return to;
18
- };
19
- var __require = import.meta.require;
20
3
 
21
4
  // src/index.ts
22
5
  import { serveStdio } from "@modelcontextprotocol/server/stdio";
@@ -401,9 +384,9 @@ function buildRekixSvg(opts) {
401
384
  return `<svg xmlns="${SVG_NS}" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">` + `<metadata id="rekix-meta">${escapeAttr(metaJson)}</metadata>` + `<defs id="rekix-defs"></defs>` + `<style id="rekix-anim"></style>` + `<rect id="rekix-bg" width="100%" height="100%" fill="${escapeAttr(background)}"/>` + `<g id="rekix-root"></g>` + `</svg>`;
402
385
  }
403
386
  async function atomicWriteFile(path, content) {
404
- const { dirname: dirname2 } = await import("path");
387
+ const { dirname } = await import("path");
405
388
  const { rename, unlink } = await import("fs/promises");
406
- const dir = dirname2(path);
389
+ const dir = dirname(path);
407
390
  if (dir && dir !== "." && dir !== "") {
408
391
  const { mkdir } = await import("fs/promises");
409
392
  await mkdir(dir, { recursive: true });
@@ -961,13 +944,13 @@ function resolveFontFamilies() {
961
944
  resolvedFonts = { sans, serif, mono, files };
962
945
  return resolvedFonts;
963
946
  }
964
- function getCustomFontFile(family) {
965
- const key = family.trim().toLowerCase();
947
+ function probeAndCacheFontFile(request) {
948
+ const key = request.trim().toLowerCase();
966
949
  if (customFontFiles.has(key))
967
950
  return customFontFiles.get(key) ?? null;
968
951
  let resolved = null;
969
952
  try {
970
- const p = probeFontFile(family.trim());
953
+ const p = probeFontFile(request.trim());
971
954
  if (p) {
972
955
  try {
973
956
  if (existsSync2(p))
@@ -982,6 +965,19 @@ function getCustomFontFile(family) {
982
965
  customFontFiles.set(key, resolved);
983
966
  return resolved;
984
967
  }
968
+ function getCustomFontFile(family) {
969
+ return probeAndCacheFontFile(family);
970
+ }
971
+ function getCustomFontFiles(family) {
972
+ const base = family.trim();
973
+ const out = [];
974
+ for (const req of [base, `${base}:bold`, `${base}:italic`]) {
975
+ const p = probeAndCacheFontFile(req);
976
+ if (p && !out.includes(p))
977
+ out.push(p);
978
+ }
979
+ return out;
980
+ }
985
981
  function extractRequestedFamilies(svgText) {
986
982
  const out = new Set;
987
983
  const attrRe = /font-family\s*=\s*("[^"]*"|'[^']*'|[^\s>"']+)/gi;
@@ -1005,9 +1001,10 @@ function extractRequestedFamilies(svgText) {
1005
1001
  return [...out];
1006
1002
  }
1007
1003
  function svgTextHasNonAscii(svgText) {
1008
- const re = /<(?:[A-Za-z_][\w.-]*:)?(?:text|tspan)\b[^>]*>([\s\S]*?)<\/(?:[A-Za-z_][\w.-]*:)?(?:text|tspan)>/gi;
1004
+ const stripped = svgText.replace(/<(?:[A-Za-z_][\w.-]*:)?style\b[^>]*>[\s\S]*?<\/(?:[A-Za-z_][\w.-]*:)?style\s*>/gi, "").replace(/<(?:[A-Za-z_][\w.-]*:)?metadata\b[^>]*>[\s\S]*?<\/(?:[A-Za-z_][\w.-]*:)?metadata\s*>/gi, "").replace(/<(?:[A-Za-z_][\w.-]*:)?defs\b[^>]*>[\s\S]*?<\/(?:[A-Za-z_][\w.-]*:)?defs\s*>/gi, "");
1005
+ const re = /<(?:[A-Za-z_][\w.-]*:)?text\b[^>]*>([\s\S]*?)<\/(?:[A-Za-z_][\w.-]*:)?text\s*>/gi;
1009
1006
  let m;
1010
- while ((m = re.exec(svgText)) !== null) {
1007
+ while ((m = re.exec(stripped)) !== null) {
1011
1008
  const inner = (m[1] ?? "").replace(/<[^>]*>/g, "");
1012
1009
  for (const ch of inner) {
1013
1010
  if ((ch.codePointAt(0) ?? 0) > 127)
@@ -1079,11 +1076,13 @@ function buildResvg(svgText, scale) {
1079
1076
  const extraFiles = [];
1080
1077
  let unresolvedCustom = false;
1081
1078
  for (const name of custom) {
1082
- const p = getCustomFontFile(name);
1083
- if (p && !f.files.includes(p) && !extraFiles.includes(p)) {
1084
- extraFiles.push(p);
1085
- } else if (!p) {
1079
+ const primary = getCustomFontFile(name);
1080
+ if (!primary)
1086
1081
  unresolvedCustom = true;
1082
+ for (const p of getCustomFontFiles(name)) {
1083
+ if (!f.files.includes(p) && !extraFiles.includes(p)) {
1084
+ extraFiles.push(p);
1085
+ }
1087
1086
  }
1088
1087
  }
1089
1088
  const combined = [...f.files, ...extraFiles];
@@ -1197,11 +1196,11 @@ class CdpConn {
1197
1196
  }
1198
1197
  static async connect(url) {
1199
1198
  const ws = new WebSocket(url);
1200
- await new Promise((resolve2, reject) => {
1199
+ await new Promise((resolve, reject) => {
1201
1200
  const timer = setTimeout(() => reject(new Error("Timed out connecting to Chromium DevTools.")), 1e4);
1202
1201
  ws.onopen = () => {
1203
1202
  clearTimeout(timer);
1204
- resolve2();
1203
+ resolve();
1205
1204
  };
1206
1205
  ws.onerror = () => {
1207
1206
  clearTimeout(timer);
@@ -1237,14 +1236,14 @@ class CdpConn {
1237
1236
  const payload = { id, method, params };
1238
1237
  if (sessionId)
1239
1238
  payload["sessionId"] = sessionId;
1240
- return new Promise((resolve2, reject) => {
1239
+ return new Promise((resolve, reject) => {
1241
1240
  const timer = setTimeout(() => {
1242
1241
  if (this.pending.has(id)) {
1243
1242
  this.pending.delete(id);
1244
1243
  reject(new Error(`CDP timeout waiting for ${method}.`));
1245
1244
  }
1246
1245
  }, 20000);
1247
- this.pending.set(id, { resolve: resolve2, reject, timer });
1246
+ this.pending.set(id, { resolve, reject, timer });
1248
1247
  try {
1249
1248
  this.ws.send(JSON.stringify(payload));
1250
1249
  } catch (e) {
@@ -2417,6 +2416,7 @@ async function handleRead(input) {
2417
2416
  return errText(`rekix_read failed: file not found: ${safePath}. Create it first with rekix_create.`);
2418
2417
  }
2419
2418
  const parsed = parseRekix(raw);
2419
+ setCurrentSvg(safePath, stripDebugOverlay(raw));
2420
2420
  let nodes = parsed.nodesFlat;
2421
2421
  if (bboxMode === "exact") {
2422
2422
  if (!findChromeBinary()) {
@@ -2756,11 +2756,11 @@ function parseEntryTiming(entry) {
2756
2756
  const times = [];
2757
2757
  let m;
2758
2758
  while ((m = timeRe.exec(timing)) !== null) {
2759
- const num2 = Number.parseFloat(m[1]);
2759
+ const num = Number.parseFloat(m[1]);
2760
2760
  const unit = m[2].toLowerCase();
2761
- if (!Number.isFinite(num2))
2761
+ if (!Number.isFinite(num))
2762
2762
  continue;
2763
- times.push(unit === "s" ? num2 * 1000 : num2);
2763
+ times.push(unit === "s" ? num * 1000 : num);
2764
2764
  }
2765
2765
  const durationMs = times[0] ?? 1000;
2766
2766
  const delayMs = times[1] ?? 0;
@@ -3114,6 +3114,7 @@ async function handleInspect(input) {
3114
3114
  assertCanvasBounds(parsed.width, parsed.height, parsed.meta.fps, parsed.meta.durationMs);
3115
3115
  const clean = stripDebugOverlay(raw);
3116
3116
  assertSafeSvgTree(loadXmlDoc(clean));
3117
+ setCurrentSvg(safePath, clean);
3117
3118
  const animated = parsed.animations.length > 0;
3118
3119
  const effScale = Math.max(0.05, Math.min(requestedScale, maxWidth / Math.max(1, parsed.width)));
3119
3120
  let png;
@@ -3261,7 +3262,7 @@ async function handleExport(input) {
3261
3262
 
3262
3263
  // src/server.ts
3263
3264
  function createServer() {
3264
- const server = new McpServer({ name: "rekix", version: "0.1.5" });
3265
+ const server = new McpServer({ name: "rekix", version: "0.1.6" });
3265
3266
  server.registerTool("rekix_create", {
3266
3267
  title: "Create canvas",
3267
3268
  description: "Initialize a .rekix.svg canvas with metadata, defs, style, background, and root. Notifies live preview.",
package/dist/viewer.html CHANGED
@@ -65,6 +65,10 @@
65
65
  footer button:hover { background: #fafafa; }
66
66
  #scrub { flex: 1; }
67
67
  #status { font-size: 11px; color: #a1a1aa; }
68
+ #zoomlabel { font-size: 12px; color: #71717a; font-variant-numeric: tabular-nums; min-width: 44px; text-align: right; }
69
+ #connstatus { font-size: 11px; color: #a1a1aa; }
70
+ #connstatus.on { color: #16a34a; }
71
+ #connstatus.off { color: #ca8a04; }
68
72
  </style>
69
73
  </head>
70
74
  <body>
@@ -72,6 +76,7 @@
72
76
  <h1>rekix preview</h1>
73
77
  <span id="filepath">waiting for file</span>
74
78
  <span style="flex:1"></span>
79
+ <span id="zoomlabel">100%</span>
75
80
  <button id="fit">Fit to screen</button>
76
81
  </header>
77
82
  <div id="stage">
@@ -83,6 +88,7 @@
83
88
  <button id="playpause">Pause</button>
84
89
  <input id="scrub" type="range" min="0" max="2000" value="0" step="1">
85
90
  <span id="timelabel">0 / 2000 ms</span>
91
+ <span id="connstatus" class="off">reconnecting</span>
86
92
  <span id="status"></span>
87
93
  </footer>
88
94
  <script>
@@ -95,6 +101,8 @@
95
101
  const fitBtn = document.getElementById('fit');
96
102
  const filepathEl = document.getElementById('filepath');
97
103
  const statusEl = document.getElementById('status');
104
+ const zoomlabel = document.getElementById('zoomlabel');
105
+ const connstatus = document.getElementById('connstatus');
98
106
 
99
107
  let scale = 1, tx = 40, ty = 40;
100
108
  let durationMs = 2000;
@@ -105,6 +113,7 @@
105
113
 
106
114
  function applyTransform() {
107
115
  artboard.style.transform = `translate(${tx}px, ${ty}px) scale(${scale})`;
116
+ if (zoomlabel) zoomlabel.textContent = `${Math.round(scale * 100)}%`;
108
117
  }
109
118
  function fit() {
110
119
  const r = viewport.getBoundingClientRect();
@@ -141,6 +150,7 @@
141
150
  applyTransform();
142
151
  });
143
152
  viewport.addEventListener('pointerup', () => { drag = null; viewport.classList.remove('dragging'); });
153
+ viewport.addEventListener('pointercancel', () => { drag = null; viewport.classList.remove('dragging'); });
144
154
  fitBtn.addEventListener('click', fit);
145
155
 
146
156
  function frameDoc() {
@@ -158,6 +168,15 @@
158
168
  try { return d.getAnimations(); } catch (e2) { return []; }
159
169
  }
160
170
  }
171
+ function seekTo(t) {
172
+ const c = Math.max(0, Math.min(Math.floor(t), durationMs));
173
+ const anims = allAnims();
174
+ anims.forEach((a) => { try { a.pause(); a.currentTime = c; } catch (e) {} });
175
+ playing = false;
176
+ playpause.textContent = 'Play';
177
+ scrub.value = String(c);
178
+ timelabel.textContent = `${c} / ${durationMs} ms`;
179
+ }
161
180
  playpause.addEventListener('click', () => {
162
181
  const anims = allAnims();
163
182
  playing = !playing;
@@ -165,24 +184,40 @@
165
184
  playpause.textContent = playing ? 'Pause' : 'Play';
166
185
  });
167
186
  scrub.addEventListener('input', () => {
168
- const t = Number(scrub.value);
169
- const anims = allAnims();
170
- anims.forEach((a) => { try { a.pause(); a.currentTime = t; } catch (e) {} });
171
- playing = false;
172
- playpause.textContent = 'Play';
173
- timelabel.textContent = `${t} / ${durationMs} ms`;
187
+ seekTo(Number(scrub.value));
188
+ });
189
+ document.addEventListener('keydown', (e) => {
190
+ const t = e.target;
191
+ if (t && (t.tagName === 'INPUT' || t.tagName === 'TEXTAREA' || t.tagName === 'SELECT' || t.isContentEditable)) return;
192
+ if (e.code === 'Space') {
193
+ e.preventDefault();
194
+ playpause.click();
195
+ } else if (e.key === '0') {
196
+ fit();
197
+ } else if (e.key === 'ArrowLeft') {
198
+ e.preventDefault();
199
+ seekTo(Number(scrub.value) - 50);
200
+ } else if (e.key === 'ArrowRight') {
201
+ e.preventDefault();
202
+ seekTo(Number(scrub.value) + 50);
203
+ }
174
204
  });
175
205
 
176
206
  setInterval(() => {
177
207
  if (!playing) return;
178
208
  const anims = allAnims();
179
209
  if (anims.length === 0) return;
180
- const t = anims[0].currentTime;
181
- if (typeof t === 'number' && isFinite(t)) {
182
- const c = Math.floor(t % (durationMs || 1));
183
- scrub.value = String(c);
184
- timelabel.textContent = `${c} / ${durationMs} ms`;
210
+ let best = -1;
211
+ for (const a of anims) {
212
+ try {
213
+ const t = a.currentTime;
214
+ if (typeof t === 'number' && isFinite(t) && t > best) best = t;
215
+ } catch (e) {}
185
216
  }
217
+ if (best < 0) return;
218
+ const c = Math.floor(best % (durationMs || 1));
219
+ scrub.value = String(c);
220
+ timelabel.textContent = `${c} / ${durationMs} ms`;
186
221
  }, 100);
187
222
 
188
223
  function parseSvgDims(svg) {
@@ -248,9 +283,24 @@
248
283
  frame.setAttribute('height', String(dims.h));
249
284
  frame.style.width = dims.w + 'px';
250
285
  frame.style.height = dims.h + 'px';
286
+ // Preserve a paused scrubber timestamp across reloads: replacing
287
+ // srcdoc destroys the iframe, so re-pause and restore currentTime
288
+ // on load instead of forcing playback from t=0.
289
+ const savedT = !playing ? Math.max(0, Math.min(Math.floor(Number(scrub.value) || 0), durationMs)) : 0;
290
+ const wasPaused = !playing;
291
+ frame.onload = wasPaused ? () => {
292
+ const anims = allAnims();
293
+ anims.forEach((a) => { try { a.pause(); a.currentTime = savedT; } catch (e) {} });
294
+ playing = false;
295
+ playpause.textContent = 'Play';
296
+ scrub.value = String(savedT);
297
+ timelabel.textContent = `${savedT} / ${durationMs} ms`;
298
+ } : null;
251
299
  frame.srcdoc = '<!doctype html><html><head><meta charset="utf-8"><meta http-equiv="Content-Security-Policy" content="default-src \'none\'; style-src \'unsafe-inline\'; img-src data:; font-src data:;"><style>html,body{margin:0;padding:0;background:transparent;overflow:hidden}svg{display:block}</style></head><body>' + text + '</body></html>';
252
- playing = true;
253
- playpause.textContent = 'Pause';
300
+ if (!wasPaused) {
301
+ playing = true;
302
+ playpause.textContent = 'Pause';
303
+ }
254
304
  // Only reset the camera on first load, path switch, or canvas resize.
255
305
  // Live patches preserve the user's zoom/pan.
256
306
  if (!fittedOnce || pathChanged || dimsChanged) {
@@ -266,17 +316,25 @@
266
316
  }
267
317
  }
268
318
 
319
+ function setConn(on) {
320
+ if (!connstatus) return;
321
+ connstatus.textContent = on ? 'connected' : 'reconnecting';
322
+ connstatus.classList.toggle('on', on);
323
+ connstatus.classList.toggle('off', !on);
324
+ }
325
+
269
326
  function connectWs() {
270
327
  let url = 'ws://' + location.host + '/ws';
271
328
  const ws = new WebSocket(url);
329
+ ws.onopen = () => setConn(true);
272
330
  ws.onmessage = (ev) => {
273
331
  try {
274
332
  const m = JSON.parse(ev.data);
275
333
  if (m.type === 'reload') load();
276
334
  } catch (e) { load(); }
277
335
  };
278
- ws.onclose = () => setTimeout(connectWs, 1500);
279
- ws.onerror = () => { try { ws.close(); } catch (e) {} };
336
+ ws.onclose = () => { setConn(false); setTimeout(connectWs, 1500); };
337
+ ws.onerror = () => { setConn(false); try { ws.close(); } catch (e) {} };
280
338
  }
281
339
 
282
340
  applyTransform();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rekix-mcp",
3
- "version": "0.1.5",
3
+ "version": "0.1.6",
4
4
  "description": "Local headless 2D SVG vector design and animation MCP server for coding agents - draw, animate, and export vectors locally with no cloud",
5
5
  "license": "MIT",
6
6
  "publishConfig": {