sketchframe 0.7.2 → 0.10.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.
@@ -196,42 +196,59 @@ function apply(t, p) {
196
196
 
197
197
  // ../core/src/preview.ts
198
198
  function frameOrigin(preview, root, styles, overflow) {
199
- if (isObject(preview.origin)) {
200
- const x = number(preview.origin.x);
201
- const y = number(preview.origin.y);
202
- if (x !== void 0 && y !== void 0) return { x, y };
203
- }
204
- const resolved = (field) => typeof root[field] === "string" ? styles[root[field]] : root[field];
205
- let left = 0;
206
- let top = 0;
207
- let right = 0;
208
- let bottom = 0;
209
- const extend = (l, t, r, b) => {
210
- left = Math.max(left, l);
211
- top = Math.max(top, t);
212
- right = Math.max(right, r);
213
- bottom = Math.max(bottom, b);
199
+ const recorded = isObject(preview.origin) ? preview.origin : void 0;
200
+ const recordedX = recorded ? number(recorded.x) : void 0;
201
+ const recordedY = recorded ? number(recorded.y) : void 0;
202
+ const fallback = {
203
+ x: recordedX !== void 0 && recordedY !== void 0 ? recordedX : overflow.width / 2,
204
+ y: recordedX !== void 0 && recordedY !== void 0 ? recordedY : overflow.height / 2
214
205
  };
215
- const effects = resolved("effects");
216
- const shadows = isObject(effects) && Array.isArray(effects.shadows) ? effects.shadows.filter(isObject) : [];
217
- for (const shadow of shadows) {
218
- if (shadow.inset === true) continue;
219
- const x = number(shadow.x) ?? 0;
220
- const y = number(shadow.y) ?? 0;
221
- const reach = (number(shadow.blur) ?? 0) + (number(shadow.spread) ?? 0);
222
- extend(reach - x, reach - y, reach + x, reach + y);
223
- }
224
- const borders = resolved("borders");
225
- for (const border of Array.isArray(borders) ? borders.filter(isObject) : []) {
226
- const thickness = number(border.thickness) ?? 0;
227
- if (border.position === "outside") extend(thickness, thickness, thickness, thickness);
228
- if (border.position === "center") extend(thickness / 2, thickness / 2, thickness / 2, thickness / 2);
229
- }
206
+ const width = number(root.width) ?? 0;
207
+ const height = number(root.height) ?? 0;
208
+ const bounds2 = renderedBounds(root, styles);
209
+ const left = Math.floor(bounds2.left);
210
+ const top = Math.floor(bounds2.top);
211
+ const measuredWidth = Math.ceil(bounds2.right) - left;
212
+ const measuredHeight = Math.ceil(bounds2.bottom) - top;
230
213
  return {
231
- x: Math.abs(left + right - overflow.width) <= 1 ? left : overflow.width / 2,
232
- y: Math.abs(top + bottom - overflow.height) <= 1 ? top : overflow.height / 2
214
+ x: Math.abs(measuredWidth - (width + overflow.width)) <= 1 ? -left : fallback.x,
215
+ y: Math.abs(measuredHeight - (height + overflow.height)) <= 1 ? -top : fallback.y
233
216
  };
234
217
  }
218
+ function renderedBounds(root, styles) {
219
+ const bounds2 = { left: 0, top: 0, right: number(root.width) ?? 0, bottom: number(root.height) ?? 0 };
220
+ const include = (left, top, right, bottom) => {
221
+ bounds2.left = Math.min(bounds2.left, left);
222
+ bounds2.top = Math.min(bounds2.top, top);
223
+ bounds2.right = Math.max(bounds2.right, right);
224
+ bounds2.bottom = Math.max(bounds2.bottom, bottom);
225
+ };
226
+ const resolved = (node2, field) => typeof node2[field] === "string" ? styles[node2[field]] : node2[field];
227
+ const visit = (node2, parentX, parentY) => {
228
+ const x = parentX + (node2 === root ? 0 : number(node2.x) ?? 0);
229
+ const y = parentY + (node2 === root ? 0 : number(node2.y) ?? 0);
230
+ const right = x + (number(node2.width) ?? 0);
231
+ const bottom = y + (number(node2.height) ?? 0);
232
+ const effects = resolved(node2, "effects");
233
+ const shadows = isObject(effects) && Array.isArray(effects.shadows) ? effects.shadows.filter(isObject) : [];
234
+ for (const shadow of shadows) {
235
+ if (shadow.inset === true) continue;
236
+ const dx = number(shadow.x) ?? 0;
237
+ const dy = number(shadow.y) ?? 0;
238
+ const reach = (number(shadow.blur) ?? 0) + (number(shadow.spread) ?? 0);
239
+ include(x + dx - reach, y + dy - reach, right + dx + reach, bottom + dy + reach);
240
+ }
241
+ const borders = resolved(node2, "borders");
242
+ for (const border of Array.isArray(borders) ? borders.filter(isObject) : []) {
243
+ const thickness = number(border.thickness) ?? 0;
244
+ const reach = border.position === "outside" ? thickness : border.position === "center" ? thickness / 2 : 0;
245
+ include(x - reach, y - reach, right + reach, bottom + reach);
246
+ }
247
+ for (const child of Array.isArray(node2.children) ? node2.children.filter(isObject) : []) visit(child, x, y);
248
+ };
249
+ visit(root, 0, 0);
250
+ return bounds2;
251
+ }
235
252
 
236
253
  // ../core/src/model.ts
237
254
  var styleFields = ["fills", "borders", "effects", "corners", "layout", "textStyle"];
@@ -260,6 +277,9 @@ function loadSketchframe(files) {
260
277
  ([name, value]) => typeof value === "string" ? [[name, value]] : []
261
278
  )
262
279
  );
280
+ const missingAssets = (Array.isArray(design.missingAssets) ? design.missingAssets : []).flatMap(
281
+ (value) => isObject(value) && typeof value.id === "string" ? [{ id: value.id, name: string(value.name) ?? "" }] : []
282
+ );
263
283
  const previewObject = isObject(design.preview) ? design.preview : {};
264
284
  const previewScale = number(previewObject.scale) ?? 2;
265
285
  const preview = {
@@ -276,6 +296,7 @@ function loadSketchframe(files) {
276
296
  styles,
277
297
  colors,
278
298
  annotations: parseAnnotations(text(files, ANNOTATIONS_FILE)),
299
+ missingAssets,
279
300
  preview,
280
301
  frameOrigin: frameOrigin(previewObject, design.root, styles, {
281
302
  width: preview.pixelWidth / previewScale - root.size.width,
@@ -334,12 +355,19 @@ function findNode(frame, query) {
334
355
  if (trimmed === "" || trimmed === "/") return frame.root;
335
356
  const byId = nodes.find((node2) => node2.id === trimmed) ?? nodes.find((node2) => node2.sketchId === trimmed);
336
357
  if (byId) return byId;
337
- const path = trimmed.replace(/^\/+|\/+$/g, "").split("/");
358
+ const path = trimSlashes(trimmed).split("/");
338
359
  const byPath = frameNodes.find((node2) => node2.path.length === path.length && node2.path.every((name, i) => name === path[i]));
339
360
  if (byPath) return byPath;
340
361
  const byName = nodes.filter((node2) => node2.name === trimmed);
341
362
  return byName.length === 1 ? byName[0] : void 0;
342
363
  }
364
+ function trimSlashes(text3) {
365
+ let start = 0;
366
+ let end = text3.length;
367
+ while (start < end && text3[start] === "/") start++;
368
+ while (end > start && text3[end - 1] === "/") end--;
369
+ return text3.slice(start, end);
370
+ }
343
371
  function requireNode(frame, query) {
344
372
  const node2 = findNode(frame, query);
345
373
  if (node2) return node2;
@@ -354,6 +382,18 @@ function requireNode(frame, query) {
354
382
  function nodeForAnnotation(frame, annotation) {
355
383
  return annotatedNode(allNodes(frame.root), annotation);
356
384
  }
385
+ function isMissingAsset(frame, node2) {
386
+ return node2.raw.src === void 0 && missingAssetIds(frame).has(node2.id);
387
+ }
388
+ var missingAssetIdCache = /* @__PURE__ */ new WeakMap();
389
+ function missingAssetIds(frame) {
390
+ let ids = missingAssetIdCache.get(frame.missingAssets);
391
+ if (!ids) {
392
+ ids = new Set(frame.missingAssets.map((asset) => asset.id));
393
+ missingAssetIdCache.set(frame.missingAssets, ids);
394
+ }
395
+ return ids;
396
+ }
357
397
  function corners(node2) {
358
398
  const { width, height } = node2.size;
359
399
  return [
@@ -409,7 +449,7 @@ function htmlForNode(frame, node2) {
409
449
  const usedTokens = /* @__PURE__ */ new Set();
410
450
  const classNames = /* @__PURE__ */ new Map();
411
451
  const className = (current) => {
412
- const base = (current.name || current.type).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || current.type;
452
+ const base = trimDashes((current.name || current.type).toLowerCase().replace(/[^a-z0-9]+/g, "-")) || current.type;
413
453
  const safe = /^[a-z]/.test(base) ? base : `n-${base}`;
414
454
  const count = (classNames.get(safe) ?? 0) + 1;
415
455
  classNames.set(safe, count);
@@ -525,6 +565,8 @@ function htmlForNode(frame, node2) {
525
565
  if (isText && textStyle) css.push(...textCSS(textStyle, color));
526
566
  if (isText && fields.textBehaviour === "auto-width") css.push("white-space: nowrap");
527
567
  if (isText && Array.isArray(fields.textRuns) && fields.textRuns.length) notes.push("mixed text styles; see textRuns");
568
+ const missing = isMissingAsset(frame, current);
569
+ if (missing) notes.push("placeholder for a vector that couldn't be exported");
528
570
  rules.push(`${notes.length ? `/* ${notes.join("; ")} */
529
571
  ` : ""}.${name} {
530
572
  ${css.map((line) => ` ${line};`).join("\n")}
@@ -537,6 +579,10 @@ ${css.map((line) => ` ${line};`).join("\n")}
537
579
  if ((current.type === "image" || current.type === "vector") && string(fields.src)) {
538
580
  return `${indent}<img class="${name}"${label} src="${attribute(string(fields.src) ?? "")}" alt="${attribute(current.name)}">`;
539
581
  }
582
+ if (missing) {
583
+ return `${indent}<!-- vector "${comment(current.name)}" (${comment(current.id)}) couldn't be exported; rebuild it from the preview or ask for the asset -->
584
+ ${indent}<div class="${name}"${label} data-missing-asset></div>`;
585
+ }
540
586
  const children = isObject(layout) && layout.stackingOrder === "firstOnTop" ? current.children.map((child, index) => ({ child, z: current.children.length - index })) : current.children.map((child) => ({ child, z: 0 }));
541
587
  const inner = children.map(({ child }) => render(child, current, depth2 + 1));
542
588
  children.forEach(({ z }, index) => {
@@ -551,7 +597,7 @@ ${indent}</div>` : `${indent}<div class="${name}"${label}></div>`;
551
597
  const style = [variables.length ? `:root {
552
598
  ${variables.join("\n")}
553
599
  }` : "", ...rules].filter(Boolean).join("\n\n");
554
- return `<!-- "${node2.name}" (${node2.id}) from ${frame.name}.sketchframe. Image paths are inside the Sketchframe. -->
600
+ return `<!-- "${comment(node2.name)}" (${comment(node2.id)}) from ${comment(frame.name)}.sketchframe. Image paths are inside the Sketchframe. -->
555
601
  <style>
556
602
  ${style}
557
603
  </style>
@@ -575,7 +621,14 @@ function textCSS(style, color) {
575
621
  return css;
576
622
  }
577
623
  function tokenVariable(token) {
578
- return `--${token.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "token"}`;
624
+ return `--${trimDashes(token.toLowerCase().replace(/[^a-z0-9]+/g, "-")) || "token"}`;
625
+ }
626
+ function trimDashes(text3) {
627
+ let start = 0;
628
+ let end = text3.length;
629
+ while (start < end && text3[start] === "-") start++;
630
+ while (end > start && text3[end - 1] === "-") end--;
631
+ return text3.slice(start, end);
579
632
  }
580
633
  function px(value) {
581
634
  const n = typeof value === "number" ? value : 0;
@@ -584,6 +637,9 @@ function px(value) {
584
637
  function escape(text3) {
585
638
  return text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
586
639
  }
640
+ function comment(text3) {
641
+ return escape(text3).replace(/-(?=-)/g, "- ");
642
+ }
587
643
  function attribute(text3) {
588
644
  return escape(text3).replace(/"/g, "&quot;");
589
645
  }
@@ -726,7 +782,8 @@ function outline(frame, start = frame.root, options = {}) {
726
782
  typeof node2.raw.component === "string" ? `\u25C6 ${node2.raw.component}` : "",
727
783
  typeof node2.raw.rotation === "number" ? `\u21BB${node2.raw.rotation}\xB0` : "",
728
784
  typeof node2.raw.text === "string" ? JSON.stringify(truncate(node2.raw.text, 40)) : "",
729
- notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : ""
785
+ notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : "",
786
+ isMissingAsset(frame, node2) ? "\u26A0 asset missing" : ""
730
787
  ].filter(Boolean);
731
788
  lines.push(
732
789
  `${" ".repeat(depth2)}${node2.name || "(unnamed)"} [${node2.type}]${position} ${num(node2.size.width)}\xD7${num(node2.size.height)} ${node2.id}${extras.length ? ` ${extras.join(" ")}` : ""}`
@@ -747,9 +804,21 @@ function summary(frame) {
747
804
  return [
748
805
  `${frame.name}: ${num(frame.root.size.width)}\xD7${num(frame.root.size.height)} pt, ${nodes} layers` + (frame.components.length ? `, ${frame.components.length} components` : "") + (frame.annotations.length ? `, ${frame.annotations.length} annotations` : ""),
749
806
  `Preview: ${frame.preview.src}, ${pixelWidth}\xD7${pixelHeight} px at ${scale2}x; the frame starts ${num(frame.frameOrigin.x)},${num(frame.frameOrigin.y)} pt into it.`,
807
+ missingAssetsLine(frame),
750
808
  typeof frame.design.generator === "string" ? `Exported by ${frame.design.generator}${typeof frame.design.exportedAt === "string" ? ` at ${frame.design.exportedAt}` : ""}.` : ""
751
809
  ].filter(Boolean).join("\n");
752
810
  }
811
+ function missingAssetsLine(frame) {
812
+ const missing = everyNode(frame).filter((node2) => isMissingAsset(frame, node2));
813
+ if (!missing.length) return "";
814
+ const names = missing.map((node2) => {
815
+ const listed = frame.missingAssets.find((asset) => asset.id === node2.id);
816
+ const name = node2.path.join("/") || listed?.name || node2.name;
817
+ return name ? `${name} (${node2.id})` : node2.id;
818
+ });
819
+ const count = missing.length === 1 ? "1 vector couldn't" : `${missing.length} vectors couldn't`;
820
+ return `${count} be exported (${names.join(", ")}); rebuild ${missing.length === 1 ? "it" : "them"} from the preview or ask for the asset.`;
821
+ }
753
822
  function nodeContext(frame, node2, options = {}) {
754
823
  const tree = (current, depth2) => {
755
824
  const fields = resolvedFields(frame, current);
@@ -773,6 +842,11 @@ function nodeContext(frame, node2, options = {}) {
773
842
  const target = nodeForAnnotation(frame, annotation);
774
843
  return target && ids.has(target.id) ? [annotationSummary(annotation, target)] : [];
775
844
  }) : [];
845
+ const missingAssets = subtree.filter((each) => isMissingAsset(frame, each)).map((each) => ({
846
+ id: each.id,
847
+ name: each.name,
848
+ note: "This vector couldn't be exported as SVG, so it has no src. Rebuild it from the preview (get_screenshot) or ask for the asset."
849
+ }));
776
850
  return clean({
777
851
  id: node2.id,
778
852
  name: node2.name,
@@ -786,6 +860,7 @@ function nodeContext(frame, node2, options = {}) {
786
860
  reusedStyles: keys.length ? keys : void 0,
787
861
  sharedStyles: sharedStyles.length ? sharedStyles : void 0,
788
862
  annotations: annotations2.length ? annotations2 : void 0,
863
+ missingAssets: missingAssets.length ? missingAssets : void 0,
789
864
  node: tree(node2, 0)
790
865
  });
791
866
  }
@@ -1093,7 +1168,7 @@ function optionalInteger(value) {
1093
1168
  }
1094
1169
 
1095
1170
  // src/version.ts
1096
- var version = true ? "0.7.2" : "dev";
1171
+ var version = true ? "0.10.0" : "dev";
1097
1172
 
1098
1173
  // src/mcp.ts
1099
1174
  var protocolVersions = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
@@ -301,42 +301,59 @@ function apply(t, p) {
301
301
 
302
302
  // ../core/src/preview.ts
303
303
  function frameOrigin(preview, root, styles, overflow) {
304
- if (isObject(preview.origin)) {
305
- const x = number(preview.origin.x);
306
- const y = number(preview.origin.y);
307
- if (x !== void 0 && y !== void 0) return { x, y };
308
- }
309
- const resolved = (field) => typeof root[field] === "string" ? styles[root[field]] : root[field];
310
- let left = 0;
311
- let top = 0;
312
- let right = 0;
313
- let bottom = 0;
314
- const extend = (l, t, r, b) => {
315
- left = Math.max(left, l);
316
- top = Math.max(top, t);
317
- right = Math.max(right, r);
318
- bottom = Math.max(bottom, b);
304
+ const recorded = isObject(preview.origin) ? preview.origin : void 0;
305
+ const recordedX = recorded ? number(recorded.x) : void 0;
306
+ const recordedY = recorded ? number(recorded.y) : void 0;
307
+ const fallback = {
308
+ x: recordedX !== void 0 && recordedY !== void 0 ? recordedX : overflow.width / 2,
309
+ y: recordedX !== void 0 && recordedY !== void 0 ? recordedY : overflow.height / 2
319
310
  };
320
- const effects = resolved("effects");
321
- const shadows = isObject(effects) && Array.isArray(effects.shadows) ? effects.shadows.filter(isObject) : [];
322
- for (const shadow of shadows) {
323
- if (shadow.inset === true) continue;
324
- const x = number(shadow.x) ?? 0;
325
- const y = number(shadow.y) ?? 0;
326
- const reach = (number(shadow.blur) ?? 0) + (number(shadow.spread) ?? 0);
327
- extend(reach - x, reach - y, reach + x, reach + y);
328
- }
329
- const borders = resolved("borders");
330
- for (const border of Array.isArray(borders) ? borders.filter(isObject) : []) {
331
- const thickness = number(border.thickness) ?? 0;
332
- if (border.position === "outside") extend(thickness, thickness, thickness, thickness);
333
- if (border.position === "center") extend(thickness / 2, thickness / 2, thickness / 2, thickness / 2);
334
- }
311
+ const width = number(root.width) ?? 0;
312
+ const height = number(root.height) ?? 0;
313
+ const bounds2 = renderedBounds(root, styles);
314
+ const left = Math.floor(bounds2.left);
315
+ const top = Math.floor(bounds2.top);
316
+ const measuredWidth = Math.ceil(bounds2.right) - left;
317
+ const measuredHeight = Math.ceil(bounds2.bottom) - top;
335
318
  return {
336
- x: Math.abs(left + right - overflow.width) <= 1 ? left : overflow.width / 2,
337
- y: Math.abs(top + bottom - overflow.height) <= 1 ? top : overflow.height / 2
319
+ x: Math.abs(measuredWidth - (width + overflow.width)) <= 1 ? -left : fallback.x,
320
+ y: Math.abs(measuredHeight - (height + overflow.height)) <= 1 ? -top : fallback.y
338
321
  };
339
322
  }
323
+ function renderedBounds(root, styles) {
324
+ const bounds2 = { left: 0, top: 0, right: number(root.width) ?? 0, bottom: number(root.height) ?? 0 };
325
+ const include = (left, top, right, bottom) => {
326
+ bounds2.left = Math.min(bounds2.left, left);
327
+ bounds2.top = Math.min(bounds2.top, top);
328
+ bounds2.right = Math.max(bounds2.right, right);
329
+ bounds2.bottom = Math.max(bounds2.bottom, bottom);
330
+ };
331
+ const resolved = (node2, field) => typeof node2[field] === "string" ? styles[node2[field]] : node2[field];
332
+ const visit = (node2, parentX, parentY) => {
333
+ const x = parentX + (node2 === root ? 0 : number(node2.x) ?? 0);
334
+ const y = parentY + (node2 === root ? 0 : number(node2.y) ?? 0);
335
+ const right = x + (number(node2.width) ?? 0);
336
+ const bottom = y + (number(node2.height) ?? 0);
337
+ const effects = resolved(node2, "effects");
338
+ const shadows = isObject(effects) && Array.isArray(effects.shadows) ? effects.shadows.filter(isObject) : [];
339
+ for (const shadow of shadows) {
340
+ if (shadow.inset === true) continue;
341
+ const dx = number(shadow.x) ?? 0;
342
+ const dy = number(shadow.y) ?? 0;
343
+ const reach = (number(shadow.blur) ?? 0) + (number(shadow.spread) ?? 0);
344
+ include(x + dx - reach, y + dy - reach, right + dx + reach, bottom + dy + reach);
345
+ }
346
+ const borders = resolved(node2, "borders");
347
+ for (const border of Array.isArray(borders) ? borders.filter(isObject) : []) {
348
+ const thickness = number(border.thickness) ?? 0;
349
+ const reach = border.position === "outside" ? thickness : border.position === "center" ? thickness / 2 : 0;
350
+ include(x - reach, y - reach, right + reach, bottom + reach);
351
+ }
352
+ for (const child of Array.isArray(node2.children) ? node2.children.filter(isObject) : []) visit(child, x, y);
353
+ };
354
+ visit(root, 0, 0);
355
+ return bounds2;
356
+ }
340
357
 
341
358
  // ../core/src/model.ts
342
359
  var styleFields = ["fills", "borders", "effects", "corners", "layout", "textStyle"];
@@ -365,6 +382,9 @@ function loadSketchframe(files) {
365
382
  ([name, value]) => typeof value === "string" ? [[name, value]] : []
366
383
  )
367
384
  );
385
+ const missingAssets = (Array.isArray(design.missingAssets) ? design.missingAssets : []).flatMap(
386
+ (value) => isObject(value) && typeof value.id === "string" ? [{ id: value.id, name: string(value.name) ?? "" }] : []
387
+ );
368
388
  const previewObject = isObject(design.preview) ? design.preview : {};
369
389
  const previewScale = number(previewObject.scale) ?? 2;
370
390
  const preview = {
@@ -381,6 +401,7 @@ function loadSketchframe(files) {
381
401
  styles,
382
402
  colors,
383
403
  annotations: parseAnnotations(text(files, ANNOTATIONS_FILE)),
404
+ missingAssets,
384
405
  preview,
385
406
  frameOrigin: frameOrigin(previewObject, design.root, styles, {
386
407
  width: preview.pixelWidth / previewScale - root.size.width,
@@ -439,12 +460,19 @@ function findNode(frame, query) {
439
460
  if (trimmed === "" || trimmed === "/") return frame.root;
440
461
  const byId = nodes.find((node2) => node2.id === trimmed) ?? nodes.find((node2) => node2.sketchId === trimmed);
441
462
  if (byId) return byId;
442
- const path = trimmed.replace(/^\/+|\/+$/g, "").split("/");
463
+ const path = trimSlashes(trimmed).split("/");
443
464
  const byPath = frameNodes.find((node2) => node2.path.length === path.length && node2.path.every((name, i) => name === path[i]));
444
465
  if (byPath) return byPath;
445
466
  const byName = nodes.filter((node2) => node2.name === trimmed);
446
467
  return byName.length === 1 ? byName[0] : void 0;
447
468
  }
469
+ function trimSlashes(text3) {
470
+ let start = 0;
471
+ let end = text3.length;
472
+ while (start < end && text3[start] === "/") start++;
473
+ while (end > start && text3[end - 1] === "/") end--;
474
+ return text3.slice(start, end);
475
+ }
448
476
  function requireNode(frame, query) {
449
477
  const node2 = findNode(frame, query);
450
478
  if (node2) return node2;
@@ -459,6 +487,18 @@ function requireNode(frame, query) {
459
487
  function nodeForAnnotation(frame, annotation) {
460
488
  return annotatedNode(allNodes(frame.root), annotation);
461
489
  }
490
+ function isMissingAsset(frame, node2) {
491
+ return node2.raw.src === void 0 && missingAssetIds(frame).has(node2.id);
492
+ }
493
+ var missingAssetIdCache = /* @__PURE__ */ new WeakMap();
494
+ function missingAssetIds(frame) {
495
+ let ids = missingAssetIdCache.get(frame.missingAssets);
496
+ if (!ids) {
497
+ ids = new Set(frame.missingAssets.map((asset) => asset.id));
498
+ missingAssetIdCache.set(frame.missingAssets, ids);
499
+ }
500
+ return ids;
501
+ }
462
502
  function corners(node2) {
463
503
  const { width, height } = node2.size;
464
504
  return [
@@ -518,7 +558,8 @@ function outline(frame, start = frame.root, options = {}) {
518
558
  typeof node2.raw.component === "string" ? `\u25C6 ${node2.raw.component}` : "",
519
559
  typeof node2.raw.rotation === "number" ? `\u21BB${node2.raw.rotation}\xB0` : "",
520
560
  typeof node2.raw.text === "string" ? JSON.stringify(truncate(node2.raw.text, 40)) : "",
521
- notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : ""
561
+ notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : "",
562
+ isMissingAsset(frame, node2) ? "\u26A0 asset missing" : ""
522
563
  ].filter(Boolean);
523
564
  lines.push(
524
565
  `${" ".repeat(depth2)}${node2.name || "(unnamed)"} [${node2.type}]${position} ${num(node2.size.width)}\xD7${num(node2.size.height)} ${node2.id}${extras.length ? ` ${extras.join(" ")}` : ""}`
@@ -539,9 +580,21 @@ function summary(frame) {
539
580
  return [
540
581
  `${frame.name}: ${num(frame.root.size.width)}\xD7${num(frame.root.size.height)} pt, ${nodes} layers` + (frame.components.length ? `, ${frame.components.length} components` : "") + (frame.annotations.length ? `, ${frame.annotations.length} annotations` : ""),
541
582
  `Preview: ${frame.preview.src}, ${pixelWidth}\xD7${pixelHeight} px at ${scale2}x; the frame starts ${num(frame.frameOrigin.x)},${num(frame.frameOrigin.y)} pt into it.`,
583
+ missingAssetsLine(frame),
542
584
  typeof frame.design.generator === "string" ? `Exported by ${frame.design.generator}${typeof frame.design.exportedAt === "string" ? ` at ${frame.design.exportedAt}` : ""}.` : ""
543
585
  ].filter(Boolean).join("\n");
544
586
  }
587
+ function missingAssetsLine(frame) {
588
+ const missing = everyNode(frame).filter((node2) => isMissingAsset(frame, node2));
589
+ if (!missing.length) return "";
590
+ const names = missing.map((node2) => {
591
+ const listed = frame.missingAssets.find((asset) => asset.id === node2.id);
592
+ const name = node2.path.join("/") || listed?.name || node2.name;
593
+ return name ? `${name} (${node2.id})` : node2.id;
594
+ });
595
+ const count = missing.length === 1 ? "1 vector couldn't" : `${missing.length} vectors couldn't`;
596
+ return `${count} be exported (${names.join(", ")}); rebuild ${missing.length === 1 ? "it" : "them"} from the preview or ask for the asset.`;
597
+ }
545
598
  function nodeContext(frame, node2, options = {}) {
546
599
  const tree = (current, depth2) => {
547
600
  const fields = resolvedFields(frame, current);
@@ -565,6 +618,11 @@ function nodeContext(frame, node2, options = {}) {
565
618
  const target = nodeForAnnotation(frame, annotation);
566
619
  return target && ids.has(target.id) ? [annotationSummary(annotation, target)] : [];
567
620
  }) : [];
621
+ const missingAssets = subtree.filter((each) => isMissingAsset(frame, each)).map((each) => ({
622
+ id: each.id,
623
+ name: each.name,
624
+ note: "This vector couldn't be exported as SVG, so it has no src. Rebuild it from the preview (get_screenshot) or ask for the asset."
625
+ }));
568
626
  return clean({
569
627
  id: node2.id,
570
628
  name: node2.name,
@@ -578,6 +636,7 @@ function nodeContext(frame, node2, options = {}) {
578
636
  reusedStyles: keys.length ? keys : void 0,
579
637
  sharedStyles: sharedStyles.length ? sharedStyles : void 0,
580
638
  annotations: annotations2.length ? annotations2 : void 0,
639
+ missingAssets: missingAssets.length ? missingAssets : void 0,
581
640
  node: tree(node2, 0)
582
641
  });
583
642
  }
@@ -681,7 +740,7 @@ function htmlForNode(frame, node2) {
681
740
  const usedTokens = /* @__PURE__ */ new Set();
682
741
  const classNames = /* @__PURE__ */ new Map();
683
742
  const className = (current) => {
684
- const base = (current.name || current.type).toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || current.type;
743
+ const base = trimDashes((current.name || current.type).toLowerCase().replace(/[^a-z0-9]+/g, "-")) || current.type;
685
744
  const safe = /^[a-z]/.test(base) ? base : `n-${base}`;
686
745
  const count = (classNames.get(safe) ?? 0) + 1;
687
746
  classNames.set(safe, count);
@@ -797,6 +856,8 @@ function htmlForNode(frame, node2) {
797
856
  if (isText && textStyle) css.push(...textCSS(textStyle, color));
798
857
  if (isText && fields.textBehaviour === "auto-width") css.push("white-space: nowrap");
799
858
  if (isText && Array.isArray(fields.textRuns) && fields.textRuns.length) notes.push("mixed text styles; see textRuns");
859
+ const missing = isMissingAsset(frame, current);
860
+ if (missing) notes.push("placeholder for a vector that couldn't be exported");
800
861
  rules.push(`${notes.length ? `/* ${notes.join("; ")} */
801
862
  ` : ""}.${name} {
802
863
  ${css.map((line) => ` ${line};`).join("\n")}
@@ -809,6 +870,10 @@ ${css.map((line) => ` ${line};`).join("\n")}
809
870
  if ((current.type === "image" || current.type === "vector") && string(fields.src)) {
810
871
  return `${indent}<img class="${name}"${label} src="${attribute(string(fields.src) ?? "")}" alt="${attribute(current.name)}">`;
811
872
  }
873
+ if (missing) {
874
+ return `${indent}<!-- vector "${comment(current.name)}" (${comment(current.id)}) couldn't be exported; rebuild it from the preview or ask for the asset -->
875
+ ${indent}<div class="${name}"${label} data-missing-asset></div>`;
876
+ }
812
877
  const children = isObject(layout) && layout.stackingOrder === "firstOnTop" ? current.children.map((child, index) => ({ child, z: current.children.length - index })) : current.children.map((child) => ({ child, z: 0 }));
813
878
  const inner = children.map(({ child }) => render(child, current, depth2 + 1));
814
879
  children.forEach(({ z }, index) => {
@@ -823,7 +888,7 @@ ${indent}</div>` : `${indent}<div class="${name}"${label}></div>`;
823
888
  const style = [variables.length ? `:root {
824
889
  ${variables.join("\n")}
825
890
  }` : "", ...rules].filter(Boolean).join("\n\n");
826
- return `<!-- "${node2.name}" (${node2.id}) from ${frame.name}.sketchframe. Image paths are inside the Sketchframe. -->
891
+ return `<!-- "${comment(node2.name)}" (${comment(node2.id)}) from ${comment(frame.name)}.sketchframe. Image paths are inside the Sketchframe. -->
827
892
  <style>
828
893
  ${style}
829
894
  </style>
@@ -847,7 +912,14 @@ function textCSS(style, color) {
847
912
  return css;
848
913
  }
849
914
  function tokenVariable(token) {
850
- return `--${token.toLowerCase().replace(/[^a-z0-9]+/g, "-").replace(/^-+|-+$/g, "") || "token"}`;
915
+ return `--${trimDashes(token.toLowerCase().replace(/[^a-z0-9]+/g, "-")) || "token"}`;
916
+ }
917
+ function trimDashes(text3) {
918
+ let start = 0;
919
+ let end = text3.length;
920
+ while (start < end && text3[start] === "-") start++;
921
+ while (end > start && text3[end - 1] === "-") end--;
922
+ return text3.slice(start, end);
851
923
  }
852
924
  function px(value) {
853
925
  const n = typeof value === "number" ? value : 0;
@@ -856,6 +928,9 @@ function px(value) {
856
928
  function escape(text3) {
857
929
  return text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
858
930
  }
931
+ function comment(text3) {
932
+ return escape(text3).replace(/-(?=-)/g, "- ");
933
+ }
859
934
  function attribute(text3) {
860
935
  return escape(text3).replace(/"/g, "&quot;");
861
936
  }
@@ -1109,7 +1184,7 @@ function findSketchframes(root, limit = 200) {
1109
1184
  var import_node_fs2 = require("node:fs");
1110
1185
  var import_node_path2 = require("node:path");
1111
1186
  function skillText() {
1112
- const skill = true ? "---\nname: sketchframe\ndescription: Build UI from .sketchframe design files exported from Sketch. Use whenever a task mentions a .sketchframe file, a Sketch design or frame to implement, or asks to match a design, and the repository contains .sketchframe files.\n---\n\n# Building from a Sketchframe\n\nA `.sketchframe` is a design exported from Sketch: a rendered preview of one\nframe plus the full design tree (positions, sizes, fills, borders, effects,\ntypography, stack layouts, components, color tokens) and notes designers left\non layers. It is a zip archive (older exports are folders with the same\nfiles inside).\n\nDon't eyeball the preview alone, and don't read the whole `design.json`\neither: it can be huge. Use the tools to look at the outline, then pull the\ndetails of only the layers you're building.\n\n## Tools, in order of preference\n\n1. **MCP tools** (`sketchframe` server): `list_sketchframes`, `get_outline`,\n `get_node`, `get_screenshot`, `get_annotations`, `get_tokens`, `get_code`.\n2. **CLI**, when the MCP server isn't connected. Run it with\n `npx -y sketchframe <command>` (or `sketchframe` if installed, or\n `node path/to/sketchframe.cjs` if the repository commits the bundle):\n\n | MCP tool | CLI |\n |---|---|\n | `list_sketchframes` | `sketchframe list [dir]` |\n | `get_outline` | `sketchframe outline <file> [node] [--depth N]` |\n | `get_node` | `sketchframe node <file> <node> [--depth N]` |\n | `get_screenshot` | `sketchframe crop <file> [node] [-o out.png] [--padding N]`, then open the PNG with your Read tool |\n | `get_annotations` | `sketchframe annotations <file>` |\n | `get_tokens` | `sketchframe tokens <file>` |\n | `get_code` | `sketchframe code <file> <node>` |\n\n3. **No tools at all**: it's a zip.\n `unzip -p Design.sketchframe design.json`, or\n `python3 -m zipfile -e Design.sketchframe out/` and look at\n `out/preview@2x.png`. `docs/FORMAT.md` in the Sketchframe repository\n describes every field. (An older export is a folder; read its files\n directly.)\n\nA `<node>` is an id from the outline (`n4`), a `sketchId`, a layer path from\nthe frame's children down (`Header/Title`), or a unique layer name.\n\n## Workflow\n\n1. **Find the file** with `list_sketchframes` if you weren't given one.\n2. **Get the outline** (`get_outline`) and **look at the whole frame**\n (`get_screenshot` with no node). The outline gives every layer's name,\n type, position relative to its parent, size and id, and marks component\n instances (\u25C6), rotation (\u21BB) and annotated layers (\u270E).\n3. **Read the annotations** (`get_annotations`). They are instructions from\n the designer about specific layers (behaviour, accessibility, content,\n implementation notes, \"this is a mistake\"). Follow them; they override\n what the design shows.\n4. **Pick the layers to build**: usually the frame's direct children or the\n distinct sections, not every leaf.\n5. For each, **pull its context** (`get_node`) and **its screenshot**\n (`get_screenshot` with the node, maybe `padding` for context).\n `get_node` resolves shared styles inline, lists the tokens it uses with\n their values, includes its parent's layout, and the annotations on it.\n Use `depth` on large subtrees and fetch deeper children by id.\n6. **Map tokens** (`get_tokens`) onto the codebase's own design variables\n (CSS custom properties, Tailwind theme, Swift/Compose color assets)\n instead of hard-coding hex values. Reuse existing components where a\n Sketch component (instance `component` name) matches one.\n7. Optionally use **`get_code`** for an HTML/CSS starting point for a layer,\n then adapt it to the codebase's framework and conventions.\n8. **Compare** what you built against the screenshots.\n\n## Reading the values\n\n- Units are points (CSS px). `x`/`y` are relative to the parent node.\n- Stacks (`layout`) are flexbox: `mode` row/column, `gap`, `padding`,\n `justifyContent`, `alignItems`. Children with `position: \"absolute\"` sit\n outside the flow. `sizing` of `fill`/`hug`/`fixed` maps to\n `flex: 1`/`fit-content`/fixed size.\n- `fills` and `borders` are listed **top-most first**, like CSS backgrounds.\n- `effects.css` already holds ready-made `boxShadow` / `filter` /\n `backdropFilter` values.\n- Paints with `approximate: true` can't be expressed exactly in CSS; trust\n the screenshot for those.\n- `textStyle.fontWeight` is CSS (100\u2013900); `lineHeight` and `letterSpacing`\n are px. `textRuns` lists ranges styled differently.\n- Instances (`type: \"instance\"`) carry `component` (the symbol's name) and\n their resolved children; the symbol's own definition is in `components`.\n- Image and vector layers have `src` paths to files inside the archive\n (`assets/\u2026`); extract them with `sketchframe extract` if you need the\n originals.\n" : globalThis.SKETCHFRAME_SKILL;
1187
+ const skill = true ? "---\nname: sketchframe\ndescription: Build UI from .sketchframe design files exported from Sketch. Use whenever a task mentions a .sketchframe file, a Sketch design or frame to implement, or asks to match a design, and the repository contains .sketchframe files.\n---\n\n# Building from a Sketchframe\n\nA `.sketchframe` is a design exported from Sketch: a rendered preview of one\nframe plus the full design tree (positions, sizes, fills, borders, effects,\ntypography, stack layouts, components, color tokens) and notes designers left\non layers. It is a zip archive (older exports are folders with the same\nfiles inside).\n\nDon't eyeball the preview alone, and don't read the whole `design.json`\neither: it can be huge. Use the tools to look at the outline, then pull the\ndetails of only the layers you're building.\n\n## Tools, in order of preference\n\n1. **MCP tools** (`sketchframe` server): `list_sketchframes`, `get_outline`,\n `get_node`, `get_screenshot`, `get_annotations`, `get_tokens`, `get_code`.\n2. **CLI**, when the MCP server isn't connected. Run it with\n `npx -y sketchframe <command>` (or `sketchframe` if installed, or\n `node path/to/sketchframe.cjs` if the repository commits the bundle):\n\n | MCP tool | CLI |\n |---|---|\n | `list_sketchframes` | `sketchframe list [dir]` |\n | `get_outline` | `sketchframe outline <file> [node] [--depth N]` |\n | `get_node` | `sketchframe node <file> <node> [--depth N]` |\n | `get_screenshot` | `sketchframe crop <file> [node] [-o out.png] [--padding N]`, then open the PNG with your Read tool |\n | `get_annotations` | `sketchframe annotations <file>` |\n | `get_tokens` | `sketchframe tokens <file>` |\n | `get_code` | `sketchframe code <file> <node>` |\n\n3. **No tools at all**: it's a zip.\n `unzip -p Design.sketchframe design.json`, or\n `python3 -m zipfile -e Design.sketchframe out/` and look at\n `out/preview@2x.png`. `docs/FORMAT.md` in the Sketchframe repository\n describes every field. (An older export is a folder; read its files\n directly.)\n\nA `<node>` is an id from the outline (`n4`), a `sketchId`, a layer path from\nthe frame's children down (`Header/Title`), or a unique layer name.\n\n## Workflow\n\n1. **Find the file** with `list_sketchframes` if you weren't given one.\n2. **Get the outline** (`get_outline`) and **look at the whole frame**\n (`get_screenshot` with no node). The outline gives every layer's name,\n type, position relative to its parent, size and id, and marks component\n instances (\u25C6), rotation (\u21BB) and annotated layers (\u270E).\n3. **Read the annotations** (`get_annotations`). They are instructions from\n the designer about specific layers (behaviour, accessibility, content,\n implementation notes, \"this is a mistake\"). Follow them; they override\n what the design shows.\n4. **Pick the layers to build**: usually the frame's direct children or the\n distinct sections, not every leaf.\n5. For each, **pull its context** (`get_node`) and **its screenshot**\n (`get_screenshot` with the node, maybe `padding` for context).\n `get_node` resolves shared styles inline, lists the tokens it uses with\n their values, includes its parent's layout, and the annotations on it.\n Use `depth` on large subtrees and fetch deeper children by id.\n6. **Map tokens** (`get_tokens`) onto the codebase's own design variables\n (CSS custom properties, Tailwind theme, Swift/Compose color assets)\n instead of hard-coding hex values. Reuse existing components where a\n Sketch component (instance `component` name) matches one.\n7. Optionally use **`get_code`** for an HTML/CSS starting point for a layer,\n then adapt it to the codebase's framework and conventions.\n8. **Compare** what you built against the screenshots.\n\n## Reading the values\n\n- Units are points (CSS px). `x`/`y` are relative to the parent node.\n- Stacks (`layout`) are flexbox: `mode` row/column, `gap`, `padding`,\n `justifyContent`, `alignItems`. Children with `position: \"absolute\"` sit\n outside the flow. `sizing` of `fill`/`hug`/`fixed` maps to\n `flex: 1`/`fit-content`/fixed size.\n- `fills` and `borders` are listed **top-most first**, like CSS backgrounds.\n- `effects.css` already holds ready-made `boxShadow` / `filter` /\n `backdropFilter` values.\n- Paints with `approximate: true` can't be expressed exactly in CSS; trust\n the screenshot for those.\n- `textStyle.fontWeight` is CSS (100\u2013900); `lineHeight` and `letterSpacing`\n are px. `textRuns` lists ranges styled differently.\n- Instances (`type: \"instance\"`) carry `component` (the symbol's name) and\n their resolved children; the symbol's own definition is in `components`.\n- Image and vector layers have `src` paths to files inside the archive\n (`assets/\u2026`); extract them with `sketchframe extract` if you need the\n originals.\n- A vector the exporter couldn't turn into SVG has no `src`. The outline\n header names it, its line is marked `\u26A0 asset missing`, `get_node` lists it\n under `missingAssets`, and `get_code` leaves a commented placeholder. Rebuild\n it from the screenshot or ask for the asset; don't leave the box empty.\n" : globalThis.SKETCHFRAME_SKILL;
1113
1188
  if (typeof skill !== "string") throw new Error("This build of sketchframe has no skill embedded.");
1114
1189
  return skill;
1115
1190
  }
@@ -1303,7 +1378,7 @@ function optionalInteger(value) {
1303
1378
  }
1304
1379
 
1305
1380
  // src/version.ts
1306
- var version = true ? "0.7.2" : "dev";
1381
+ var version = true ? "0.10.0" : "dev";
1307
1382
 
1308
1383
  // src/mcp.ts
1309
1384
  var protocolVersions = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "sketchframe",
3
- "version": "0.7.2",
3
+ "version": "0.10.0",
4
4
  "description": "Read .sketchframe design files from the command line or an MCP server: outlines, layer details, screenshots, tokens and annotations for AI agents",
5
5
  "keywords": [
6
6
  "sketch",