@farcaster/snap-hono 2.1.3 → 2.1.5

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/og-image.js CHANGED
@@ -372,6 +372,8 @@ function mapCellGrid(el, accent) {
372
372
  const gapMap = { none: 0, sm: 1, md: 2, lg: 4 };
373
373
  const gapPx = gapMap[gap] ?? 1;
374
374
  const cellW = Math.floor((OG_CARD_INNER_WIDTH_PX - (cols - 1) * gapPx) / cols);
375
+ const squareCells = el.cellAspectRatio === "square";
376
+ const rowHeight = typeof el.rowHeight === "number" ? el.rowHeight : 28;
375
377
  const cellMap = new Map();
376
378
  for (const c of cells) {
377
379
  cellMap.set(`${Number(c.row ?? 0)},${Number(c.col ?? 0)}`, { color: c.color, content: c.content });
@@ -384,7 +386,7 @@ function mapCellGrid(el, accent) {
384
386
  const bg = cell?.color ? colorHex(cell.color, accent) : "#F3F4F6";
385
387
  cellNodes.push(h("div", {
386
388
  display: "flex", alignItems: "center", justifyContent: "center",
387
- width: cellW, height: cellW > 28 ? 28 : cellW, borderRadius: 4,
389
+ width: cellW, height: squareCells ? cellW : Math.min(rowHeight, cellW), borderRadius: 4,
388
390
  backgroundColor: bg, border: "1px solid #E5E7EB",
389
391
  fontSize: 10, fontWeight: 600, color: "#374151",
390
392
  }, cell?.content ?? ""));
@@ -587,11 +589,18 @@ function estimateElementHeight(el, imageMap) {
587
589
  return Math.max(1, bars.length) * 26;
588
590
  }
589
591
  case "cell_grid": {
592
+ const cols = Number(el.cols ?? 2);
590
593
  const rows = Number(el.rows ?? 2);
591
594
  const gap = String(el.gap ?? "sm");
592
595
  const gapMap = { none: 0, sm: 1, md: 2, lg: 4 };
593
596
  const gapPx = gapMap[gap] ?? 1;
594
- return rows * 28 + (rows - 1) * gapPx;
597
+ const cellW = Math.floor((OG_CARD_INNER_WIDTH_PX - (cols - 1) * gapPx) / cols);
598
+ const rowHeight = el.cellAspectRatio === "square"
599
+ ? cellW
600
+ : typeof el.rowHeight === "number"
601
+ ? Math.min(el.rowHeight, cellW)
602
+ : Math.min(28, cellW);
603
+ return rows * rowHeight + (rows - 1) * gapPx;
595
604
  }
596
605
  case "group": {
597
606
  const children = el.children ?? [];
@@ -352,6 +352,8 @@ function renderElement(key, spec, accent) {
352
352
  const gap = String(p.gap ?? "sm");
353
353
  const gapMap = { none: 0, sm: 1, md: 2, lg: 4 };
354
354
  const gapPx = gapMap[gap] ?? 1;
355
+ const squareCells = p.cellAspectRatio === "square";
356
+ const rowHeight = typeof p.rowHeight === "number" ? p.rowHeight : 28;
355
357
  const cellMap = new Map();
356
358
  for (const c of cells) {
357
359
  cellMap.set(`${Number(c.row ?? 0)},${Number(c.col ?? 0)}`, {
@@ -365,7 +367,8 @@ function renderElement(key, spec, accent) {
365
367
  const cell = cellMap.get(`${r},${c}`);
366
368
  const bg = cell?.color ? colorHex(cell.color, accent) : "transparent";
367
369
  const content = cell?.content ? esc(cell.content) : "";
368
- html += `<div style="min-height:28px;border:1px solid #E5E7EB;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:#374151;background:${bg}">${content}</div>`;
370
+ const sizeStyle = squareCells ? "aspect-ratio:1/1;" : `min-height:${rowHeight}px;`;
371
+ html += `<div style="${sizeStyle}border:1px solid #E5E7EB;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:#374151;background:${bg}">${content}</div>`;
369
372
  }
370
373
  }
371
374
  html += `</div>`;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@farcaster/snap-hono",
3
- "version": "2.1.3",
3
+ "version": "2.1.5",
4
4
  "description": "Hono integration for Farcaster Snap servers",
5
5
  "repository": {
6
6
  "type": "git",
@@ -28,7 +28,7 @@
28
28
  "dependencies": {
29
29
  "@resvg/resvg-wasm": "^2.6.2",
30
30
  "satori": "^0.10.0",
31
- "@farcaster/snap": "2.4.0"
31
+ "@farcaster/snap": "2.5.1"
32
32
  },
33
33
  "peerDependencies": {
34
34
  "hono": ">=4.0.0"
package/src/og-image.ts CHANGED
@@ -552,6 +552,8 @@ function mapCellGrid(el: El, accent: string): VNode {
552
552
  const gapMap: Record<string, number> = { none: 0, sm: 1, md: 2, lg: 4 };
553
553
  const gapPx = gapMap[gap] ?? 1;
554
554
  const cellW = Math.floor((OG_CARD_INNER_WIDTH_PX - (cols - 1) * gapPx) / cols);
555
+ const squareCells = el.cellAspectRatio === "square";
556
+ const rowHeight = typeof el.rowHeight === "number" ? el.rowHeight : 28;
555
557
 
556
558
  const cellMap = new Map<string, { color?: string; content?: string }>();
557
559
  for (const c of cells) {
@@ -567,7 +569,7 @@ function mapCellGrid(el: El, accent: string): VNode {
567
569
  cellNodes.push(
568
570
  h("div", {
569
571
  display: "flex", alignItems: "center", justifyContent: "center",
570
- width: cellW, height: cellW > 28 ? 28 : cellW, borderRadius: 4,
572
+ width: cellW, height: squareCells ? cellW : Math.min(rowHeight, cellW), borderRadius: 4,
571
573
  backgroundColor: bg, border: "1px solid #E5E7EB",
572
574
  fontSize: 10, fontWeight: 600, color: "#374151",
573
575
  }, cell?.content ?? ""),
@@ -812,11 +814,19 @@ function estimateElementHeight(el: El, imageMap: Map<string, string>): number {
812
814
  return Math.max(1, bars.length) * 26;
813
815
  }
814
816
  case "cell_grid": {
817
+ const cols = Number(el.cols ?? 2);
815
818
  const rows = Number(el.rows ?? 2);
816
819
  const gap = String(el.gap ?? "sm");
817
820
  const gapMap: Record<string, number> = { none: 0, sm: 1, md: 2, lg: 4 };
818
- const gapPx = gapMap[gap] ?? 1;
819
- return rows * 28 + (rows - 1) * gapPx;
821
+ const gapPx = gapMap[gap] ?? 1;
822
+ const cellW = Math.floor((OG_CARD_INNER_WIDTH_PX - (cols - 1) * gapPx) / cols);
823
+ const rowHeight =
824
+ el.cellAspectRatio === "square"
825
+ ? cellW
826
+ : typeof el.rowHeight === "number"
827
+ ? Math.min(el.rowHeight, cellW)
828
+ : Math.min(28, cellW);
829
+ return rows * rowHeight + (rows - 1) * gapPx;
820
830
  }
821
831
  case "group": {
822
832
  const children = (el.children as El[]) ?? [];
@@ -458,6 +458,8 @@ function renderElement(key: string, spec: SnapSpec, accent: string): string {
458
458
  const gap = String(p.gap ?? "sm");
459
459
  const gapMap: Record<string, number> = { none: 0, sm: 1, md: 2, lg: 4 };
460
460
  const gapPx = gapMap[gap] ?? 1;
461
+ const squareCells = p.cellAspectRatio === "square";
462
+ const rowHeight = typeof p.rowHeight === "number" ? p.rowHeight : 28;
461
463
  const cellMap = new Map<string, { color?: string; content?: string }>();
462
464
  for (const c of cells) {
463
465
  cellMap.set(`${Number(c.row ?? 0)},${Number(c.col ?? 0)}`, {
@@ -471,7 +473,8 @@ function renderElement(key: string, spec: SnapSpec, accent: string): string {
471
473
  const cell = cellMap.get(`${r},${c}`);
472
474
  const bg = cell?.color ? colorHex(cell.color, accent) : "transparent";
473
475
  const content = cell?.content ? esc(cell.content) : "";
474
- html += `<div style="min-height:28px;border:1px solid #E5E7EB;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:#374151;background:${bg}">${content}</div>`;
476
+ const sizeStyle = squareCells ? "aspect-ratio:1/1;" : `min-height:${rowHeight}px;`;
477
+ html += `<div style="${sizeStyle}border:1px solid #E5E7EB;border-radius:4px;display:flex;align-items:center;justify-content:center;font-size:12px;font-weight:600;color:#374151;background:${bg}">${content}</div>`;
475
478
  }
476
479
  }
477
480
  html += `</div>`;