sketchframe 0.7.1 → 0.9.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,41 +196,58 @@ 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
216
+ };
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);
233
248
  };
249
+ visit(root, 0, 0);
250
+ return bounds2;
234
251
  }
235
252
 
236
253
  // ../core/src/model.ts
@@ -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,
@@ -354,6 +375,18 @@ function requireNode(frame, query) {
354
375
  function nodeForAnnotation(frame, annotation) {
355
376
  return annotatedNode(allNodes(frame.root), annotation);
356
377
  }
378
+ function isMissingAsset(frame, node2) {
379
+ return node2.raw.src === void 0 && missingAssetIds(frame).has(node2.id);
380
+ }
381
+ var missingAssetIdCache = /* @__PURE__ */ new WeakMap();
382
+ function missingAssetIds(frame) {
383
+ let ids = missingAssetIdCache.get(frame.missingAssets);
384
+ if (!ids) {
385
+ ids = new Set(frame.missingAssets.map((asset) => asset.id));
386
+ missingAssetIdCache.set(frame.missingAssets, ids);
387
+ }
388
+ return ids;
389
+ }
357
390
  function corners(node2) {
358
391
  const { width, height } = node2.size;
359
392
  return [
@@ -525,6 +558,8 @@ function htmlForNode(frame, node2) {
525
558
  if (isText && textStyle) css.push(...textCSS(textStyle, color));
526
559
  if (isText && fields.textBehaviour === "auto-width") css.push("white-space: nowrap");
527
560
  if (isText && Array.isArray(fields.textRuns) && fields.textRuns.length) notes.push("mixed text styles; see textRuns");
561
+ const missing = isMissingAsset(frame, current);
562
+ if (missing) notes.push("placeholder for a vector that couldn't be exported");
528
563
  rules.push(`${notes.length ? `/* ${notes.join("; ")} */
529
564
  ` : ""}.${name} {
530
565
  ${css.map((line) => ` ${line};`).join("\n")}
@@ -537,6 +572,10 @@ ${css.map((line) => ` ${line};`).join("\n")}
537
572
  if ((current.type === "image" || current.type === "vector") && string(fields.src)) {
538
573
  return `${indent}<img class="${name}"${label} src="${attribute(string(fields.src) ?? "")}" alt="${attribute(current.name)}">`;
539
574
  }
575
+ if (missing) {
576
+ return `${indent}<!-- vector "${comment(current.name)}" (${comment(current.id)}) couldn't be exported; rebuild it from the preview or ask for the asset -->
577
+ ${indent}<div class="${name}"${label} data-missing-asset></div>`;
578
+ }
540
579
  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
580
  const inner = children.map(({ child }) => render(child, current, depth2 + 1));
542
581
  children.forEach(({ z }, index) => {
@@ -551,7 +590,7 @@ ${indent}</div>` : `${indent}<div class="${name}"${label}></div>`;
551
590
  const style = [variables.length ? `:root {
552
591
  ${variables.join("\n")}
553
592
  }` : "", ...rules].filter(Boolean).join("\n\n");
554
- return `<!-- "${node2.name}" (${node2.id}) from ${frame.name}.sketchframe. Image paths are inside the Sketchframe. -->
593
+ return `<!-- "${comment(node2.name)}" (${comment(node2.id)}) from ${comment(frame.name)}.sketchframe. Image paths are inside the Sketchframe. -->
555
594
  <style>
556
595
  ${style}
557
596
  </style>
@@ -584,6 +623,9 @@ function px(value) {
584
623
  function escape(text3) {
585
624
  return text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
586
625
  }
626
+ function comment(text3) {
627
+ return escape(text3).replace(/-(?=-)/g, "- ");
628
+ }
587
629
  function attribute(text3) {
588
630
  return escape(text3).replace(/"/g, "&quot;");
589
631
  }
@@ -726,7 +768,8 @@ function outline(frame, start = frame.root, options = {}) {
726
768
  typeof node2.raw.component === "string" ? `\u25C6 ${node2.raw.component}` : "",
727
769
  typeof node2.raw.rotation === "number" ? `\u21BB${node2.raw.rotation}\xB0` : "",
728
770
  typeof node2.raw.text === "string" ? JSON.stringify(truncate(node2.raw.text, 40)) : "",
729
- notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : ""
771
+ notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : "",
772
+ isMissingAsset(frame, node2) ? "\u26A0 asset missing" : ""
730
773
  ].filter(Boolean);
731
774
  lines.push(
732
775
  `${" ".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 +790,21 @@ function summary(frame) {
747
790
  return [
748
791
  `${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
792
  `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.`,
793
+ missingAssetsLine(frame),
750
794
  typeof frame.design.generator === "string" ? `Exported by ${frame.design.generator}${typeof frame.design.exportedAt === "string" ? ` at ${frame.design.exportedAt}` : ""}.` : ""
751
795
  ].filter(Boolean).join("\n");
752
796
  }
797
+ function missingAssetsLine(frame) {
798
+ const missing = everyNode(frame).filter((node2) => isMissingAsset(frame, node2));
799
+ if (!missing.length) return "";
800
+ const names = missing.map((node2) => {
801
+ const listed = frame.missingAssets.find((asset) => asset.id === node2.id);
802
+ const name = node2.path.join("/") || listed?.name || node2.name;
803
+ return name ? `${name} (${node2.id})` : node2.id;
804
+ });
805
+ const count = missing.length === 1 ? "1 vector couldn't" : `${missing.length} vectors couldn't`;
806
+ return `${count} be exported (${names.join(", ")}); rebuild ${missing.length === 1 ? "it" : "them"} from the preview or ask for the asset.`;
807
+ }
753
808
  function nodeContext(frame, node2, options = {}) {
754
809
  const tree = (current, depth2) => {
755
810
  const fields = resolvedFields(frame, current);
@@ -773,6 +828,11 @@ function nodeContext(frame, node2, options = {}) {
773
828
  const target = nodeForAnnotation(frame, annotation);
774
829
  return target && ids.has(target.id) ? [annotationSummary(annotation, target)] : [];
775
830
  }) : [];
831
+ const missingAssets = subtree.filter((each) => isMissingAsset(frame, each)).map((each) => ({
832
+ id: each.id,
833
+ name: each.name,
834
+ 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."
835
+ }));
776
836
  return clean({
777
837
  id: node2.id,
778
838
  name: node2.name,
@@ -786,6 +846,7 @@ function nodeContext(frame, node2, options = {}) {
786
846
  reusedStyles: keys.length ? keys : void 0,
787
847
  sharedStyles: sharedStyles.length ? sharedStyles : void 0,
788
848
  annotations: annotations2.length ? annotations2 : void 0,
849
+ missingAssets: missingAssets.length ? missingAssets : void 0,
789
850
  node: tree(node2, 0)
790
851
  });
791
852
  }
@@ -1093,7 +1154,7 @@ function optionalInteger(value) {
1093
1154
  }
1094
1155
 
1095
1156
  // src/version.ts
1096
- var version = true ? "0.7.1" : "dev";
1157
+ var version = true ? "0.9.0" : "dev";
1097
1158
 
1098
1159
  // src/mcp.ts
1099
1160
  var protocolVersions = ["2025-11-25", "2025-06-18", "2025-03-26", "2024-11-05"];
@@ -301,41 +301,58 @@ 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
321
+ };
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);
338
353
  };
354
+ visit(root, 0, 0);
355
+ return bounds2;
339
356
  }
340
357
 
341
358
  // ../core/src/model.ts
@@ -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,
@@ -459,6 +480,18 @@ function requireNode(frame, query) {
459
480
  function nodeForAnnotation(frame, annotation) {
460
481
  return annotatedNode(allNodes(frame.root), annotation);
461
482
  }
483
+ function isMissingAsset(frame, node2) {
484
+ return node2.raw.src === void 0 && missingAssetIds(frame).has(node2.id);
485
+ }
486
+ var missingAssetIdCache = /* @__PURE__ */ new WeakMap();
487
+ function missingAssetIds(frame) {
488
+ let ids = missingAssetIdCache.get(frame.missingAssets);
489
+ if (!ids) {
490
+ ids = new Set(frame.missingAssets.map((asset) => asset.id));
491
+ missingAssetIdCache.set(frame.missingAssets, ids);
492
+ }
493
+ return ids;
494
+ }
462
495
  function corners(node2) {
463
496
  const { width, height } = node2.size;
464
497
  return [
@@ -518,7 +551,8 @@ function outline(frame, start = frame.root, options = {}) {
518
551
  typeof node2.raw.component === "string" ? `\u25C6 ${node2.raw.component}` : "",
519
552
  typeof node2.raw.rotation === "number" ? `\u21BB${node2.raw.rotation}\xB0` : "",
520
553
  typeof node2.raw.text === "string" ? JSON.stringify(truncate(node2.raw.text, 40)) : "",
521
- notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : ""
554
+ notes.get(node2.id) ? `\u270E${notes.get(node2.id)}` : "",
555
+ isMissingAsset(frame, node2) ? "\u26A0 asset missing" : ""
522
556
  ].filter(Boolean);
523
557
  lines.push(
524
558
  `${" ".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 +573,21 @@ function summary(frame) {
539
573
  return [
540
574
  `${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
575
  `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.`,
576
+ missingAssetsLine(frame),
542
577
  typeof frame.design.generator === "string" ? `Exported by ${frame.design.generator}${typeof frame.design.exportedAt === "string" ? ` at ${frame.design.exportedAt}` : ""}.` : ""
543
578
  ].filter(Boolean).join("\n");
544
579
  }
580
+ function missingAssetsLine(frame) {
581
+ const missing = everyNode(frame).filter((node2) => isMissingAsset(frame, node2));
582
+ if (!missing.length) return "";
583
+ const names = missing.map((node2) => {
584
+ const listed = frame.missingAssets.find((asset) => asset.id === node2.id);
585
+ const name = node2.path.join("/") || listed?.name || node2.name;
586
+ return name ? `${name} (${node2.id})` : node2.id;
587
+ });
588
+ const count = missing.length === 1 ? "1 vector couldn't" : `${missing.length} vectors couldn't`;
589
+ return `${count} be exported (${names.join(", ")}); rebuild ${missing.length === 1 ? "it" : "them"} from the preview or ask for the asset.`;
590
+ }
545
591
  function nodeContext(frame, node2, options = {}) {
546
592
  const tree = (current, depth2) => {
547
593
  const fields = resolvedFields(frame, current);
@@ -565,6 +611,11 @@ function nodeContext(frame, node2, options = {}) {
565
611
  const target = nodeForAnnotation(frame, annotation);
566
612
  return target && ids.has(target.id) ? [annotationSummary(annotation, target)] : [];
567
613
  }) : [];
614
+ const missingAssets = subtree.filter((each) => isMissingAsset(frame, each)).map((each) => ({
615
+ id: each.id,
616
+ name: each.name,
617
+ 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."
618
+ }));
568
619
  return clean({
569
620
  id: node2.id,
570
621
  name: node2.name,
@@ -578,6 +629,7 @@ function nodeContext(frame, node2, options = {}) {
578
629
  reusedStyles: keys.length ? keys : void 0,
579
630
  sharedStyles: sharedStyles.length ? sharedStyles : void 0,
580
631
  annotations: annotations2.length ? annotations2 : void 0,
632
+ missingAssets: missingAssets.length ? missingAssets : void 0,
581
633
  node: tree(node2, 0)
582
634
  });
583
635
  }
@@ -797,6 +849,8 @@ function htmlForNode(frame, node2) {
797
849
  if (isText && textStyle) css.push(...textCSS(textStyle, color));
798
850
  if (isText && fields.textBehaviour === "auto-width") css.push("white-space: nowrap");
799
851
  if (isText && Array.isArray(fields.textRuns) && fields.textRuns.length) notes.push("mixed text styles; see textRuns");
852
+ const missing = isMissingAsset(frame, current);
853
+ if (missing) notes.push("placeholder for a vector that couldn't be exported");
800
854
  rules.push(`${notes.length ? `/* ${notes.join("; ")} */
801
855
  ` : ""}.${name} {
802
856
  ${css.map((line) => ` ${line};`).join("\n")}
@@ -809,6 +863,10 @@ ${css.map((line) => ` ${line};`).join("\n")}
809
863
  if ((current.type === "image" || current.type === "vector") && string(fields.src)) {
810
864
  return `${indent}<img class="${name}"${label} src="${attribute(string(fields.src) ?? "")}" alt="${attribute(current.name)}">`;
811
865
  }
866
+ if (missing) {
867
+ return `${indent}<!-- vector "${comment(current.name)}" (${comment(current.id)}) couldn't be exported; rebuild it from the preview or ask for the asset -->
868
+ ${indent}<div class="${name}"${label} data-missing-asset></div>`;
869
+ }
812
870
  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
871
  const inner = children.map(({ child }) => render(child, current, depth2 + 1));
814
872
  children.forEach(({ z }, index) => {
@@ -823,7 +881,7 @@ ${indent}</div>` : `${indent}<div class="${name}"${label}></div>`;
823
881
  const style = [variables.length ? `:root {
824
882
  ${variables.join("\n")}
825
883
  }` : "", ...rules].filter(Boolean).join("\n\n");
826
- return `<!-- "${node2.name}" (${node2.id}) from ${frame.name}.sketchframe. Image paths are inside the Sketchframe. -->
884
+ return `<!-- "${comment(node2.name)}" (${comment(node2.id)}) from ${comment(frame.name)}.sketchframe. Image paths are inside the Sketchframe. -->
827
885
  <style>
828
886
  ${style}
829
887
  </style>
@@ -856,6 +914,9 @@ function px(value) {
856
914
  function escape(text3) {
857
915
  return text3.replace(/&/g, "&amp;").replace(/</g, "&lt;").replace(/>/g, "&gt;");
858
916
  }
917
+ function comment(text3) {
918
+ return escape(text3).replace(/-(?=-)/g, "- ");
919
+ }
859
920
  function attribute(text3) {
860
921
  return escape(text3).replace(/"/g, "&quot;");
861
922
  }
@@ -1109,7 +1170,7 @@ function findSketchframes(root, limit = 200) {
1109
1170
  var import_node_fs2 = require("node:fs");
1110
1171
  var import_node_path2 = require("node:path");
1111
1172
  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;
1173
+ 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
1174
  if (typeof skill !== "string") throw new Error("This build of sketchframe has no skill embedded.");
1114
1175
  return skill;
1115
1176
  }
@@ -1303,7 +1364,7 @@ function optionalInteger(value) {
1303
1364
  }
1304
1365
 
1305
1366
  // src/version.ts
1306
- var version = true ? "0.7.1" : "dev";
1367
+ var version = true ? "0.9.0" : "dev";
1307
1368
 
1308
1369
  // src/mcp.ts
1309
1370
  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.1",
3
+ "version": "0.9.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",