|
| 1 | +import { wrapText } from '../utils'; |
| 2 | + |
| 3 | +export const abstract = (ctx, width, height, scale, data) => { |
| 4 | + const { repoOwner, repoName, description, language, stars, forks } = data; |
| 5 | + // ABSTRACT SHAPES (Memphis-ish) |
| 6 | + |
| 7 | + // Background: Soft Off-White |
| 8 | + ctx.fillStyle = '#fdfbf7'; |
| 9 | + ctx.fillRect(0, 0, width, height); |
| 10 | + |
| 11 | + // Random Shapes Background |
| 12 | + const colors = ['#ff6b6b', '#4ecdc4', '#45b7d1', '#f7d794', '#1a535c']; |
| 13 | + |
| 14 | + // Helper to draw random shapes |
| 15 | + for(let i=0; i<15; i++) { |
| 16 | + ctx.fillStyle = colors[Math.floor(Math.random() * colors.length)]; |
| 17 | + ctx.save(); |
| 18 | + ctx.globalAlpha = 0.2; |
| 19 | + const type = Math.random(); |
| 20 | + const x = Math.random() * width; |
| 21 | + const y = Math.random() * height; |
| 22 | + const size = (50 + Math.random() * 150) * scale; |
| 23 | + |
| 24 | + ctx.translate(x, y); |
| 25 | + ctx.rotate(Math.random() * Math.PI * 2); |
| 26 | + |
| 27 | + ctx.beginPath(); |
| 28 | + if (type < 0.33) { |
| 29 | + // Circle |
| 30 | + ctx.arc(0, 0, size/2, 0, Math.PI*2); |
| 31 | + } else if (type < 0.66) { |
| 32 | + // Rect |
| 33 | + ctx.rect(-size/2, -size/2, size, size); |
| 34 | + } else { |
| 35 | + // Triangle |
| 36 | + ctx.moveTo(0, -size/2); |
| 37 | + ctx.lineTo(size/2, size/2); |
| 38 | + ctx.lineTo(-size/2, size/2); |
| 39 | + } |
| 40 | + ctx.fill(); |
| 41 | + ctx.restore(); |
| 42 | + } |
| 43 | + |
| 44 | + // Main Card (Floating) |
| 45 | + const cardW = width * 0.7; |
| 46 | + const cardH = height * 0.6; |
| 47 | + const cardX = (width - cardW) / 2; |
| 48 | + const cardY = (height - cardH) / 2; |
| 49 | + |
| 50 | + // Shadow |
| 51 | + ctx.fillStyle = '#000'; // Hard shadow |
| 52 | + ctx.fillRect(cardX + 20*scale, cardY + 20*scale, cardW, cardH); |
| 53 | + |
| 54 | + // Card Body |
| 55 | + ctx.fillStyle = '#fff'; |
| 56 | + ctx.strokeStyle = '#000'; |
| 57 | + ctx.lineWidth = 4 * scale; |
| 58 | + ctx.fillRect(cardX, cardY, cardW, cardH); |
| 59 | + ctx.strokeRect(cardX, cardY, cardW, cardH); |
| 60 | + |
| 61 | + // Header Decoration inside card |
| 62 | + ctx.fillStyle = '#ff6b6b'; |
| 63 | + ctx.fillRect(cardX, cardY, cardW, 20 * scale); |
| 64 | + ctx.strokeRect(cardX, cardY, cardW, 20 * scale); |
| 65 | + |
| 66 | + // Content |
| 67 | + const padding = 60 * scale; |
| 68 | + const contentY = cardY + padding + 20*scale; |
| 69 | + |
| 70 | + ctx.fillStyle = '#000'; |
| 71 | + ctx.textAlign = 'center'; |
| 72 | + |
| 73 | + // Title |
| 74 | + ctx.font = `900 ${70 * scale}px "Arial Black", sans-serif`; |
| 75 | + ctx.fillText(repoName, width/2, contentY + 40*scale); |
| 76 | + |
| 77 | + // Owner |
| 78 | + ctx.font = `bold ${30 * scale}px "Courier New", monospace`; |
| 79 | + ctx.fillText(repoOwner.toUpperCase(), width/2, contentY - 20*scale); |
| 80 | + |
| 81 | + // Description |
| 82 | + ctx.font = `normal ${28 * scale}px "Arial", sans-serif`; |
| 83 | + wrapText(ctx, description, width/2, contentY + 120*scale, cardW - padding*2, 40*scale); |
| 84 | + |
| 85 | + // Stats Bubbles (Bottom of card) |
| 86 | + const statY = cardY + cardH - 60 * scale; |
| 87 | + |
| 88 | + const drawStat = (text, x, color) => { |
| 89 | + ctx.fillStyle = color; |
| 90 | + const w = ctx.measureText(text).width + 40*scale; |
| 91 | + ctx.beginPath(); |
| 92 | + ctx.roundRect(x - w/2, statY - 25*scale, w, 50*scale, 25*scale); |
| 93 | + ctx.fill(); |
| 94 | + ctx.stroke(); // Outline |
| 95 | + |
| 96 | + ctx.fillStyle = '#000'; |
| 97 | + ctx.font = `bold ${20 * scale}px "Arial", sans-serif`; |
| 98 | + ctx.fillText(text, x, statY + 8*scale); |
| 99 | + }; |
| 100 | + |
| 101 | + let cx = width/2; |
| 102 | + // Spread based on content |
| 103 | + if (stars && forks) { |
| 104 | + drawStat(`★ ${stars}`, cx - 120*scale, '#f7d794'); |
| 105 | + drawStat(language, cx, '#4ecdc4'); |
| 106 | + drawStat(`⑂ ${forks}`, cx + 120*scale, '#45b7d1'); |
| 107 | + } else { |
| 108 | + drawStat(language, cx, '#4ecdc4'); |
| 109 | + } |
| 110 | +}; |
0 commit comments