Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

visuals.gno

7.78 Kb · 270 lines
  1package hearthcore
  2
  3import (
  4	"strconv"
  5	"strings"
  6
  7	"gno.land/p/nt/svg/v0"
  8)
  9
 10// EscapeXML escapes special XML characters before embedding dynamic text inside
 11// deterministic on-chain SVG documents.
 12func EscapeXML(s string) string {
 13	r := strings.NewReplacer(
 14		"&", "&",
 15		"<", "&lt;",
 16		">", "&gt;",
 17		`"`, "&quot;",
 18		"'", "&#39;",
 19	)
 20	return r.Replace(s)
 21}
 22
 23// RenderHeroBannerSVG builds a deterministic on-chain SVG hero banner and
 24// stacked bounty distribution chart for gnoweb using gno.land/p/nt/svg/v0.
 25func RenderHeroBannerSVG(openCount, claimedCount, submittedCount, settledCount int, totalEscrowUgnot, totalSettledUgnot int64) string {
 26	c := svg.NewCanvas(860, 210).WithViewBox(0, 0, 860, 210)
 27	c.AddStyle("text", "font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;")
 28
 29	// Deep slate tavern backdrop with subtle border frame.
 30	bg := svg.NewRectangle(0, 0, 860, 210, "#0f172a")
 31	bg.RX = 14
 32	bg.RY = 14
 33	bg.Attr.Stroke = "#334155"
 34	bg.Attr.StrokeWidth = "2"
 35	c.Append(bg)
 36
 37	// Warm hearth accent bar on left edge.
 38	accent := svg.NewRectangle(0, 0, 10, 210, "#f59e0b")
 39	accent.RX = 5
 40	c.Append(accent)
 41
 42	// Brand emblem circle + ember spark.
 43	emblem := svg.NewCircle(54, 56, 22, "#1e293b")
 44	emblem.Attr.Stroke = "#f59e0b"
 45	emblem.Attr.StrokeWidth = "2.5"
 46	c.Append(emblem)
 47	c.Append(svg.NewCircle(54, 56, 9, "#f59e0b"))
 48	c.Append(svg.NewCircle(54, 53, 4, "#fef3c7"))
 49
 50	// Title and subtitle.
 51	title := svg.NewText(92, 52, "HEARTHBOUNTY", "#f8fafc")
 52	title.Attr.Style = "font-size:24px;font-weight:800;letter-spacing:1.4px;"
 53	c.Append(title)
 54
 55	sub := svg.NewText(92, 74, "On-Chain Micro-Bounty Escrow &amp; AI Agent Guild", "#94a3b8")
 56	sub.Attr.Style = "font-size:13px;font-weight:500;"
 57	c.Append(sub)
 58
 59	// Live metric pill cards on top right.
 60	drawMetricBox(c, 525, 22, 152, 62, "ESCROW LOCKED", EscapeXML(FormatGNOT(totalEscrowUgnot)), "#f59e0b")
 61	drawMetricBox(c, 690, 22, 152, 62, "SETTLED VOLUME", EscapeXML(FormatGNOT(totalSettledUgnot)), "#34d399")
 62
 63	// Stacked status distribution bar.
 64	barX := 34
 65	barY := 118
 66	barW := 792
 67	barH := 24
 68
 69	track := svg.NewRectangle(barX, barY, barW, barH, "#1e293b")
 70	track.RX = 6
 71	track.RY = 6
 72	c.Append(track)
 73
 74	total := openCount + claimedCount + submittedCount + settledCount
 75	if total > 0 {
 76		wOpen := (barW * openCount) / total
 77		wClaimed := (barW * claimedCount) / total
 78		wSubmitted := (barW * submittedCount) / total
 79		wSettled := barW - wOpen - wClaimed - wSubmitted
 80		if settledCount == 0 {
 81			wSettled = 0
 82		}
 83
 84		curX := barX
 85		if wOpen > 0 {
 86			r := svg.NewRectangle(curX, barY, wOpen, barH, "#f59e0b")
 87			r.RX = 4
 88			c.Append(r)
 89			curX += wOpen
 90		}
 91		if wClaimed > 0 {
 92			r := svg.NewRectangle(curX, barY, wClaimed, barH, "#38bdf8")
 93			c.Append(r)
 94			curX += wClaimed
 95		}
 96		if wSubmitted > 0 {
 97			r := svg.NewRectangle(curX, barY, wSubmitted, barH, "#a78bfa")
 98			c.Append(r)
 99			curX += wSubmitted
100		}
101		if wSettled > 0 {
102			r := svg.NewRectangle(curX, barY, wSettled, barH, "#34d399")
103			r.RX = 4
104			c.Append(r)
105		}
106	}
107
108	// Legend row.
109	drawLegendDot(c, 38, 174, "#f59e0b", "Open: "+strconv.Itoa(openCount))
110	drawLegendDot(c, 195, 174, "#38bdf8", "Claimed: "+strconv.Itoa(claimedCount))
111	drawLegendDot(c, 375, 174, "#a78bfa", "Submitted: "+strconv.Itoa(submittedCount))
112	drawLegendDot(c, 575, 174, "#34d399", "Settled: "+strconv.Itoa(settledCount))
113
114	badge := svg.NewText(718, 178, "MCP + gnoweb v1.8", "#64748b")
115	badge.Attr.Style = "font-size:11px;font-weight:600;"
116	c.Append(badge)
117
118	return c.Render("HearthBounty Live On-Chain Escrow Dashboard")
119}
120
121func drawMetricBox(c *svg.Canvas, x, y, w, h int, label, value, color string) {
122	box := svg.NewRectangle(x, y, w, h, "#1e293b")
123	box.RX = 8
124	box.RY = 8
125	box.Attr.Stroke = "#334155"
126	box.Attr.StrokeWidth = "1.5"
127	c.Append(box)
128
129	lbl := svg.NewText(x+12, y+22, label, "#94a3b8")
130	lbl.Attr.Style = "font-size:10px;font-weight:700;letter-spacing:0.8px;"
131	c.Append(lbl)
132
133	val := svg.NewText(x+12, y+47, value, color)
134	val.Attr.Style = "font-size:16px;font-weight:800;"
135	c.Append(val)
136}
137
138func drawLegendDot(c *svg.Canvas, x, y int, color, text string) {
139	c.Append(svg.NewCircle(x, y-4, 6, color))
140	t := svg.NewText(x+14, y, text, "#e2e8f0")
141	t.Attr.Style = "font-size:13px;font-weight:600;"
142	c.Append(t)
143}
144
145// RenderLifecycleSVG renders an on-chain 4-step bounty progression strip.
146func RenderLifecycleSVG(status Status, rewardUgnot int64) string {
147	c := svg.NewCanvas(820, 108).WithViewBox(0, 0, 820, 108)
148	c.AddStyle("text", "font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;")
149
150	bg := svg.NewRectangle(0, 0, 820, 108, "#0f172a")
151	bg.RX = 12
152	bg.RY = 12
153	bg.Attr.Stroke = "#334155"
154	bg.Attr.StrokeWidth = "1.5"
155	c.Append(bg)
156
157	steps := []string{"1. OPEN", "2. CLAIMED", "3. SUBMITTED", "4. SETTLED"}
158	activeIdx := status.StepIndex()
159
160	// Connector rail.
161	rail := svg.NewRectangle(72, 42, 480, 4, "#334155")
162	rail.RX = 2
163	c.Append(rail)
164
165	for i, label := range steps {
166		cx := 72 + i*160
167		fill := "#1e293b"
168		stroke := "#475569"
169		textColor := "#94a3b8"
170
171		if status == StatusCancelled {
172			stroke = "#ef4444"
173		} else if status == StatusDisputed && i == 2 {
174			fill = "#f97316"
175			stroke = "#fdba74"
176			textColor = "#f8fafc"
177		} else if activeIdx >= 0 && i < activeIdx {
178			fill = "#10b981"
179			stroke = "#34d399"
180			textColor = "#e2e8f0"
181		} else if activeIdx == i {
182			fill = "#f59e0b"
183			stroke = "#fde68a"
184			textColor = "#f8fafc"
185		}
186
187		node := svg.NewCircle(cx, 44, 15, fill)
188		node.Attr.Stroke = stroke
189		node.Attr.StrokeWidth = "2.5"
190		c.Append(node)
191
192		numColor := "#0f172a"
193		if activeIdx < i || status == StatusCancelled {
194			numColor = "#cbd5e1"
195		}
196		num := svg.NewText(cx-4, 49, strconv.Itoa(i+1), numColor)
197		num.Attr.Style = "font-size:13px;font-weight:800;"
198		c.Append(num)
199
200		lbl := svg.NewText(cx-34, 82, label, textColor)
201		lbl.Attr.Style = "font-size:11px;font-weight:700;letter-spacing:0.6px;"
202		c.Append(lbl)
203	}
204
205	// Reward badge on right side.
206	pill := svg.NewRectangle(618, 22, 182, 64, "#1e293b")
207	pill.RX = 10
208	pill.RY = 10
209	pill.Attr.Stroke = "#f59e0b"
210	pill.Attr.StrokeWidth = "2"
211	c.Append(pill)
212
213	st := svg.NewText(634, 44, "ESCROW: "+EscapeXML(strings.ToUpper(status.Label())), "#94a3b8")
214	st.Attr.Style = "font-size:10px;font-weight:700;letter-spacing:0.7px;"
215	c.Append(st)
216
217	rew := svg.NewText(634, 70, EscapeXML(FormatGNOT(rewardUgnot)), "#fbbf24")
218	rew.Attr.Style = "font-size:17px;font-weight:800;"
219	c.Append(rew)
220
221	return c.Render("Bounty Lifecycle Progress")
222}
223
224// RenderTierBadgeSVG creates a compact builder/agent reputation shield card.
225func RenderTierBadgeSVG(handle string, tier Tier, settledCount uint64, earnedUgnot int64, isAgent bool) string {
226	c := svg.NewCanvas(520, 86).WithViewBox(0, 0, 520, 86)
227	c.AddStyle("text", "font-family: ui-sans-serif, system-ui, -apple-system, sans-serif;")
228
229	bg := svg.NewRectangle(0, 0, 520, 86, "#0f172a")
230	bg.RX = 10
231	bg.RY = 10
232	bg.Attr.Stroke = tier.Color()
233	bg.Attr.StrokeWidth = "2"
234	c.Append(bg)
235
236	// Left rank circle.
237	rankDot := svg.NewCircle(42, 43, 22, "#1e293b")
238	rankDot.Attr.Stroke = tier.Color()
239	rankDot.Attr.StrokeWidth = "2.5"
240	c.Append(rankDot)
241
242	initial := "B"
243	initX := 36
244	if isAgent {
245		initial = "AI"
246		initX = 33
247	}
248	initTxt := svg.NewText(initX, 49, initial, tier.Color())
249	initTxt.Attr.Style = "font-size:15px;font-weight:800;"
250	c.Append(initTxt)
251
252	nameTxt := svg.NewText(80, 36, EscapeXML(handle), "#f8fafc")
253	nameTxt.Attr.Style = "font-size:17px;font-weight:800;"
254	c.Append(nameTxt)
255
256	role := "Builder"
257	if isAgent {
258		role = "Autonomous AI Agent"
259	}
260	meta := string(tier) + " · " + role + " · " + strconv.FormatUint(settledCount, 10) + " settled"
261	metaTxt := svg.NewText(80, 59, EscapeXML(meta), "#94a3b8")
262	metaTxt.Attr.Style = "font-size:12px;font-weight:600;"
263	c.Append(metaTxt)
264
265	earnedTxt := svg.NewText(370, 49, EscapeXML(FormatGNOT(earnedUgnot)), tier.Color())
266	earnedTxt.Attr.Style = "font-size:16px;font-weight:800;"
267	c.Append(earnedTxt)
268
269	return c.Render("HearthBounty Reputation Badge")
270}