/** * QR Generator Pro (Neo-Brutalist QR Studio) * Scraped & Reverse-Engineered from https://generate-qr-alpha.vercel.app * * Full client-side QR vector generation engine with custom styling, * neo-brutalist presets, brand logos, gradients, and frames. * * @author Vamz Spectre (https://vamxapi.my.id) * * Download: * curl -sL "https://code.vamxapi.my.id/snippet/raw/generate-qr" -o generate-qr.js * * Usage: * node generate-qr.js "https://google.com" * node generate-qr.js "https://vamxapi.my.id" "neo-pop" * node generate-qr.js '{"type":"wifi","ssid":"VamxOffice","password":"secretpassword"}' "scan-me-pro" */ const QRCode = (() => { try { return require("qrcode"); } catch { try { return require("/root/websiteapi/node_modules/qrcode"); } catch { throw new Error("Package 'qrcode' is required. Run 'npm install qrcode'."); } } })(); // Curated Icons SVG Paths const ICONS = { none: "", whatsapp: "M12 2C6.48 2 2 6.48 2 12c0 1.76.46 3.42 1.27 4.88L2 22l5.3-1.25C8.68 21.46 10.3 22 12 22c5.52 0 10-4.48 10-10S17.52 2 12 2zm3.83 14.28c-.2.57-1.02 1.05-1.55 1.13-.5.08-1.15.15-3.32-.75-2.78-1.15-4.52-4.01-4.66-4.2-.14-.19-1.12-1.49-1.12-2.84 0-1.35.7-2.01.95-2.28.25-.27.65-.41.95-.41.1 0 .2 0 .3.01.3 0 .45.02.65.5.25.61.85 2.08.92 2.23.08.15.13.33.03.53-.1.2-.2.33-.35.5-.15.17-.32.38-.45.51-.15.15-.31.32-.13.63.18.31.81 1.34 1.74 2.17.93.83 1.72 1.09 2.03 1.22.31.13.49.1.67-.1.18-.21.78-.91.99-1.22.2-.31.41-.26.68-.16.28.1.1.78 1.48 1.47 1.47.69.69 1.27.76 1.42.79s.42-.08.62-.35c.2-.27.87-1.02 1.1-1.37.23-.35.45-.3.75-.19.3.11 1.91.9 2.24 1.06s.55.24.63.38c.08.14.08.82-.12 1.39z", wifi: "M12 3C7.03 3 2.5 5.03 0 8.5l1.5 1.5C3.5 7.5 7.5 6 12 6s8.5 1.5 10.5 4l1.5-1.5C21.5 5.03 16.97 3 12 3zm0 6c-3.31 0-6.19 1.39-8.19 3.59L12 21.5l8.19-8.91C18.19 10.39 15.31 9 12 9zm0 5c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z", google: "M12.24 10.285V13.4h6.86c-.277 1.56-1.602 4.585-6.86 4.585-4.54 0-8.24-3.765-8.24-8.4s3.7-8.4 8.24-8.4c2.58 0 4.307 1.095 5.298 2.045l2.465-2.37C18.575 1.5 15.69 0 12.24 0 5.58 0 0 5.37 0 12s5.58 12 12.24 12c6.96 0 11.57-4.89 11.57-11.79 0-.795-.085-1.4-.19-1.925H12.24z", url: "M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z", phone: "M6.62 10.79c1.44 2.82 3.76 5.14 6.59 6.59l2.2-2.2c.27-.27.67-.36 1.02-.24 1.12.37 2.33.57 3.57.57.55 0 1 .45 1 1V20c0 .55-.45 1-1 1-9.39 0-17-7.61-17-17 0-.55.45-1 1-1h3.5c.55 0 1 .45 1 1 0 1.25.2 2.45.57 3.57.11.35.03.74-.25 1.02l-2.2 2.2z", instagram: "M8 3h8a5 5 0 0 1 5 5v8a5 5 0 0 1-5 5H8a5 5 0 0 1-5-5V8a5 5 0 0 1 5-5Zm0 2a3 3 0 0 0-3 3v8a3 3 0 0 0 3 3h8a3 3 0 0 0 3-3V8a3 3 0 0 0-3-3H8Zm-1 7a5 5 0 1 1 10 0a5 5 0 0 1-10 0Zm2 0a3 3 0 1 0 6 0a3 3 0 0 0-6 0Zm8.2-4.4a1.2 1.2 0 1 1 2.4 0a1.2 1.2 0 0 1-2.4 0Z", tiktok: "M14 3h3c.3 2.2 1.8 3.7 4 4v3c-1.5 0-2.9-.5-4-1.3V15a5.5 5.5 0 1 1-5.5-5.5c.35 0 .7.03 1 .09V12.7a2.5 2.5 0 1 0 1.5 2.3V3Z", youtube: "M6.5 5h11A4.5 4.5 0 0 1 22 9.5v5a4.5 4.5 0 0 1-4.5 4.5h-11A4.5 4.5 0 0 1 2 14.5v-5A4.5 4.5 0 0 1 6.5 5Zm3.5 4v6l5.2-3L10 9Z", shopee: "M12 2a3 3 0 0 1 3 3v1h3.2a1 1 0 0 1 1 .92l1.06 12.06A2 2 0 0 1 18.27 21H5.73a2 2 0 0 1-2-2.02L4.8 6.92a1 1 0 0 1 1-.92H9V5a3 3 0 0 1 3-3Zm-1.5 4h3V5a1.5 1.5 0 0 0-3 0v1Zm-3.2 7.2a.9.9 0 0 1 1.27.2c.55.8 1.5 1.3 2.43 1.3s1.88-.5 2.43-1.3a.9.9 0 0 1 1.47 1.04c-.87 1.26-2.33 2.06-3.9 2.06s-3.03-.8-3.9-2.06a.9.9 0 0 1 .2-1.24Z", tokopedia: "M4 21V11a8 8 0 0 1 16 0v10h-4v-5a4 4 0 0 0-8 0v5H4Zm8-14a2.5 2.5 0 0 1 2.5 2.5.9.9 0 0 1-1.8 0a.7.7 0 0 0-1.4 0a.9.9 0 0 1-1.8 0A2.5 2.5 0 0 1 12 7Z", gopay: "M5 5h13a3 3 0 0 1 3 3v2.5h-3.5a2.5 2.5 0 0 0 0 5H21V16a3 3 0 0 1-3 3H5a3 3 0 0 1-3-3V8a3 3 0 0 1 3-3Zm12.5 6h3v1h-3a.5.5 0 0 1 0-1Z", ovo: "M4 12a8 5.5 0 1 1 16 0a8 5.5 0 0 1-16 0Zm3 0a5 3.2 0 1 0 10 0a5 3.2 0 0 0-10 0Z", dana: "M8 3h8a5 5 0 0 1 5 5v8a5 5 0 0 1-5 5H8a5 5 0 0 1-5-5V8a5 5 0 0 1 5-5Zm5 3-4.5 7h3L10.8 18l4.7-7h-3L13 6Z", linkaja: "M12 3c1 3 4 4.5 4 8a4 4 0 0 1-8 0c0-1.5.7-2.6 1.6-3.6C10.5 8.5 11.5 6 12 3Zm-1.8 8.5a1.8 1.8 0 1 0 3.6 0a1.8 1.8 0 0 0-3.6 0Z" }; // Design Presets const PRESETS = { "executive": { name: "Executive", tag: "Formal & Resmi", patch: { moduleStyle: "square", moduleRoundness: 0.2, eyeOuterStyle: "square", eyeInnerStyle: "square", colorType: "solid", primaryColor: "#0F172A", backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "none" } }, "neo-pop": { name: "Neo Pop", tag: "Bold Brutalism", patch: { moduleStyle: "rounded", moduleRoundness: 0.85, eyeOuterStyle: "rounded", eyeInnerStyle: "rounded", colorType: "solid", primaryColor: "#141414", backgroundColor: "#FFD43B", useCustomEyeColors: false, frameStyle: "none" } }, "indigo-luxe": { name: "Indigo Luxe", tag: "Gradient Modern", patch: { moduleStyle: "dots", moduleRoundness: 0.9, eyeOuterStyle: "rounded", eyeInnerStyle: "circle", colorType: "gradient", primaryColor: "#4F46E5", secondaryColor: "#06B6D4", gradientAngle: 45, backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "none" } }, "sunset-blaze": { name: "Sunset Blaze", tag: "Hangat & Kreatif", patch: { moduleStyle: "rounded", moduleRoundness: 0.7, eyeOuterStyle: "leaf", eyeInnerStyle: "rounded", colorType: "gradient", primaryColor: "#F97316", secondaryColor: "#EC4899", gradientAngle: 135, backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "none" } }, "ocean-breeze": { name: "Ocean Breeze", tag: "Segar & Bersih", patch: { moduleStyle: "dots", moduleRoundness: 1, eyeOuterStyle: "circle", eyeInnerStyle: "circle", colorType: "gradient", primaryColor: "#0EA5E9", secondaryColor: "#22D3EE", gradientAngle: 90, backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "none" } }, "forest-trust": { name: "Forest Trust", tag: "Natural & Tenang", patch: { moduleStyle: "rounded", moduleRoundness: 0.6, eyeOuterStyle: "leaf", eyeInnerStyle: "leaf", colorType: "solid", primaryColor: "#15803D", backgroundColor: "#FFFFFF", useCustomEyeColors: true, eyeOuterColor: "#14532D", eyeInnerColor: "#65A30D", frameStyle: "none" } }, "royal-velvet": { name: "Royal Velvet", tag: "Premium & Elegan", patch: { moduleStyle: "dots", moduleRoundness: 0.85, eyeOuterStyle: "leaf", eyeInnerStyle: "circle", colorType: "gradient", primaryColor: "#7C3AED", secondaryColor: "#DB2777", gradientAngle: 220, backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "none" } }, "midnight-pro": { name: "Midnight Pro", tag: "Dark Inverted", patch: { moduleStyle: "square", moduleRoundness: 0.3, eyeOuterStyle: "rounded", eyeInnerStyle: "square", colorType: "solid", primaryColor: "#F8FAFC", backgroundColor: "#0F172A", useCustomEyeColors: false, frameStyle: "none" } }, "scan-me-pro": { name: "Scan-Me Pro", tag: "Banner Print-Ready", patch: { moduleStyle: "rounded", moduleRoundness: 0.5, eyeOuterStyle: "rounded", eyeInnerStyle: "rounded", colorType: "solid", primaryColor: "#0F172A", backgroundColor: "#FFFFFF", useCustomEyeColors: false, frameStyle: "scan-me", frameText: "SCAN ME", frameColor: "#141414", frameTextColor: "#FFD43B" } } }; const DEFAULT_SETTINGS = { moduleStyle: "square", moduleRoundness: 0.5, eyeOuterStyle: "square", eyeInnerStyle: "square", colorType: "solid", primaryColor: "#141414", secondaryColor: "#141414", gradientAngle: 45, backgroundColor: "#FFFFFF", useCustomEyeColors: false, eyeOuterColor: "#141414", eyeInnerColor: "#141414", logoType: "none", customLogoUrl: undefined, logoScale: 0.18, logoPadding: 0, logoBgColor: "#FFFFFF", margin: 2, resolution: 512, errorCorrection: "M", frameStyle: "none", frameText: "", frameColor: "#141414", frameTextColor: "#FFFFFF" }; // String Escapers function escapeWifi(t) { return t ? t.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/:/g, "\\:").replace(/,/g, "\\,") : ""; } function escapeVCard(t) { return t ? t.replace(/\\/g, "\\\\").replace(/;/g, "\\;").replace(/,/g, "\\,").replace(/\r\n|\r|\n/g, "\\n") : ""; } // Payload Formatter function formatPayload(input) { if (typeof input === "string") { return input.trim(); } if (!input || typeof input !== "object") { throw new Error("Invalid input data format."); } const type = input.type || "text"; switch (type) { case "url": { let n = (input.url || "").trim(); if (n && !/^https?:\/\//i.test(n)) n = "https://" + n; return n; } case "text": return input.text || ""; case "email": { const email = (input.email || "").trim(); const subject = encodeURIComponent(input.subject || ""); const body = encodeURIComponent(input.body || ""); return `mailto:${email}?subject=${subject}&body=${body}`; } case "phone": return `tel:${(input.phone || "").trim().replace(/\s+/g, "")}`; case "sms": { const phone = (input.phone || "").trim().replace(/\s+/g, ""); const message = encodeURIComponent(input.message || ""); return `sms:${phone}?body=${message}`; } case "whatsapp": { let phone = (input.phone || "").trim(); if (phone.startsWith("+")) phone = phone.substring(1); if (phone.startsWith("0")) phone = "62" + phone.substring(1); phone = phone.replace(/[^0-9]/g, ""); const msg = encodeURIComponent(input.message || ""); return `https://wa.me/${phone}${msg ? `?text=${msg}` : ""}`; } case "wifi": { const ssid = escapeWifi(input.ssid || ""); const pass = input.password ? escapeWifi(input.password) : ""; const sec = input.security || "WPA"; const hid = input.hidden ? "true" : "false"; return `WIFI:S:${ssid};T:${sec};P:${pass};H:${hid};;`; } case "location": { if (input.mode === "mapsUrl" && input.mapsUrl) { let url = input.mapsUrl.trim(); if (!/^https?:\/\//i.test(url)) url = "https://" + url; return url; } return `https://www.google.com/maps/search/?api=1&query=${input.latitude || 0},${input.longitude || 0}`; } case "vcard": { const first = (input.firstName || "").trim(); const last = (input.lastName || "").trim(); const lines = [ "BEGIN:VCARD", "VERSION:3.0", `N:${escapeVCard(last)};${escapeVCard(first)};;;`, `FN:${escapeVCard(`${first} ${last}`.trim())}` ]; if (input.organization) lines.push(`ORG:${escapeVCard(input.organization.trim())}`); if (input.title) lines.push(`TITLE:${escapeVCard(input.title.trim())}`); if (input.phone) lines.push(`TEL;TYPE=CELL:${escapeVCard(input.phone.trim())}`); if (input.email) lines.push(`EMAIL;TYPE=PREF,INTERNET:${escapeVCard(input.email.trim())}`); if (input.url) { let u = input.url.trim(); if (!/^https?:\/\//i.test(u)) u = "https://" + u; lines.push(`URL:${escapeVCard(u)}`); } if (input.address) lines.push(`ADR;TYPE=WORK:;;${escapeVCard(input.address.trim())};;;;`); lines.push("END:VCARD"); return lines.join("\r\n"); } case "event": { const toUtc = (d) => { if (!d) return ""; const s = new Date(d); if (isNaN(s.getTime())) return ""; const pad = (v) => String(v).padStart(2, "0"); return `${s.getUTCFullYear()}${pad(s.getUTCMonth() + 1)}${pad(s.getUTCDate())}T${pad(s.getUTCHours())}${pad(s.getUTCMinutes())}${pad(s.getUTCSeconds())}Z`; }; const lines = [ "BEGIN:VCALENDAR", "VERSION:2.0", "PRODID:-//QR Generator Pro//EN", "BEGIN:VEVENT", `SUMMARY:${escapeVCard((input.title || "").trim())}` ]; if (input.location) lines.push(`LOCATION:${escapeVCard(input.location.trim())}`); if (input.description) lines.push(`DESCRIPTION:${escapeVCard(input.description.trim())}`); if (input.start) { const t = toUtc(input.start); if (t) lines.push(`DTSTART:${t}`); } if (input.end) { const t = toUtc(input.end); if (t) lines.push(`DTEND:${t}`); } lines.push("END:VEVENT"); lines.push("END:VCALENDAR"); return lines.join("\r\n"); } case "crypto": { const coin = (input.coin || "bitcoin").toLowerCase().trim(); const addr = (input.address || "").trim(); const amt = input.amount ? `?amount=${input.amount.trim()}` : ""; return `${coin}:${addr}${amt}`; } case "upi": { const pa = encodeURIComponent((input.vpa || "").trim()); const pn = encodeURIComponent((input.name || "").trim()); const am = input.amount ? `&am=${encodeURIComponent(input.amount.trim())}` : ""; const tn = input.note ? `&tn=${encodeURIComponent(input.note.trim())}` : ""; return `upi://pay?pa=${pa}&pn=${pn}${am}${tn}`; } default: return input.payload || input.text || ""; } } // QR Matrix calculation function getQrMatrix(text, errorCorrection = "M") { const ec = errorCorrection === "auto" ? "H" : errorCorrection; const qr = QRCode.create(text, { errorCorrectionLevel: ec }); const size = qr.modules.size; const matrix = []; for (let r = 0; r < size; r++) { const row = []; for (let c = 0; c < size; c++) { row.push(qr.modules.get(r, c) ? 1 : 0); } matrix.push(row); } return { size, matrix }; } // Finder Eye Detection Helper function isEye(r, c, size) { return r < 7 && c < 7 ? "tl" : r < 7 && c >= size - 7 ? "tr" : r >= size - 7 && c < 7 ? "bl" : null; } // Leaf-style Eye Path Generator function leafEyePath(x, y, size, radius, corner) { if (corner === "tl") { return `M${x + radius},${y} h${size - radius} v${size - radius} a${radius},${radius} 0 0,1 -${radius},${radius} h-${size - radius} v-${size - radius} a${radius},${radius} 0 0,1 ${radius},-${radius} z`; } if (corner === "tr") { return `M${x},${y} h${size - radius} a${radius},${radius} 0 0,1 ${radius},${radius} v${size - radius} h-${size - radius} a${radius},${radius} 0 0,1 -${radius},-${radius} v-${size - radius} z`; } return `M${x},${y} h${size} v${size - radius} a${radius},${radius} 0 0,1 -${radius},${radius} h-${size - 2 * radius} a${radius},${radius} 0 0,1 -${radius},-${radius} v-${size - radius} z`; } // Vector SVG Generator (Port of lw) function generateQrSvg(payload, userOpts = {}) { const opts = { ...DEFAULT_SETTINGS, ...userOpts }; // If preset is specified, merge it if (opts.preset && PRESETS[opts.preset]) { Object.assign(opts, PRESETS[opts.preset].patch, userOpts); } // If logo is enabled, recommend errorCorrection 'H' const hasLogo = opts.logoType && opts.logoType !== "none"; const ecLevel = hasLogo ? "H" : opts.errorCorrection || "M"; const { size, matrix } = getQrMatrix(payload, ecLevel); const res = opts.resolution || 512; let activeHeight = res; const isScanMe = opts.frameStyle === "scan-me"; if (isScanMe) { activeHeight = Math.floor(res * 0.83); } const margin = opts.margin >= 0 ? opts.margin : 2; const gridCount = size + 2 * margin; const cellSize = Math.floor(activeHeight / gridCount); const qrActualSize = cellSize * size; const offsetX = Math.floor((res - qrActualSize) / 2); const offsetY = Math.floor((activeHeight - qrActualSize) / 2); // Logo bounding box in matrix coordinates let logoStart = -1; let logoEnd = -1; if (hasLogo) { const logoModuleSize = Math.max(5, Math.floor(size * (opts.logoScale || 0.18))); logoStart = Math.floor((size - logoModuleSize) / 2); logoEnd = logoStart + logoModuleSize; } let defs = ""; let fillAttr = `fill="${opts.primaryColor}"`; if (opts.colorType === "gradient") { const angleRad = ((opts.gradientAngle || 45) * Math.PI) / 180; const x1 = 50 - Math.cos(angleRad) * 50; const y1 = 50 - Math.sin(angleRad) * 50; const x2 = 50 + Math.cos(angleRad) * 50; const y2 = 50 + Math.sin(angleRad) * 50; defs += ` `; fillAttr = 'fill="url(#qrGrad)"'; } let bodySvg = ""; if (defs) bodySvg += defs; // Background const bgColor = opts.backgroundColor === "transparent" ? "none" : opts.backgroundColor || "#FFFFFF"; bodySvg += ``; // Draw Matrix Modules let pathData = ""; for (let r = 0; r < size; r++) { for (let c = 0; c < size; c++) { if (matrix[r][c] === 0) continue; if (isEye(r, c, size)) continue; if (hasLogo && r >= logoStart && r < logoEnd && c >= logoStart && c < logoEnd) continue; const px = offsetX + c * cellSize; const py = offsetY + r * cellSize; if (opts.moduleStyle === "square") { pathData += ` M${px},${py} h${cellSize} v${cellSize} h-${cellSize} z`; } else if (opts.moduleStyle === "circle") { const radius = (cellSize / 2) * 0.9; const cx = px + cellSize / 2; const cy = py + cellSize / 2; pathData += ` M${cx},${cy - radius} a${radius},${radius} 0 1,1 0,${radius * 2} a${radius},${radius} 0 1,1 0,-${radius * 2}`; } else if (opts.moduleStyle === "dots") { const roundness = opts.moduleRoundness !== undefined ? opts.moduleRoundness : 0.8; const radius = (cellSize / 2) * roundness * 0.9; const cx = px + cellSize / 2; const cy = py + cellSize / 2; pathData += ` M${cx},${cy - radius} a${radius},${radius} 0 1,1 0,${radius * 2} a${radius},${radius} 0 1,1 0,-${radius * 2}`; } else if (opts.moduleStyle === "rounded") { const roundness = opts.moduleRoundness !== undefined ? opts.moduleRoundness : 0.5; const corner = Math.floor(cellSize * 0.45 * roundness); pathData += ` M${px + corner},${py} h${cellSize - 2 * corner} a${corner},${corner} 0 0,1 ${corner},${corner} v${cellSize - 2 * corner} a${corner},${corner} 0 0,1 -${corner},${corner} h-${cellSize - 2 * corner} a${corner},${corner} 0 0,1 -${corner},-${corner} v-${cellSize - 2 * corner} a${corner},${corner} 0 0,1 ${corner},-${corner} z`; } } } if (pathData) { bodySvg += ``; } // Draw 3 Finder Eyes const eyeOuterColor = opts.useCustomEyeColors ? opts.eyeOuterColor : opts.primaryColor; const eyeInnerColor = opts.useCustomEyeColors ? opts.eyeInnerColor : opts.primaryColor; const eyes = [ { name: "tl", x: offsetX, y: offsetY }, { name: "tr", x: offsetX + (size - 7) * cellSize, y: offsetY }, { name: "bl", x: offsetX, y: offsetY + (size - 7) * cellSize } ]; eyes.forEach((eye) => { const outerDim = 7 * cellSize; const innerDim = 3 * cellSize; const gap = 2 * cellSize; const ex = eye.x; const ey = eye.y; // Outer Frame Path let outerPath = ""; if (opts.eyeOuterStyle === "square") { outerPath = `M${ex},${ey} h${outerDim} v${outerDim} h-${outerDim} z`; } else if (opts.eyeOuterStyle === "rounded") { const rOuter = 1.75 * cellSize; outerPath = `M${ex + rOuter},${ey} h${outerDim - 2 * rOuter} a${rOuter},${rOuter} 0 0,1 ${rOuter},${rOuter} v${outerDim - 2 * rOuter} a${rOuter},${rOuter} 0 0,1 -${rOuter},${rOuter} h-${outerDim - 2 * rOuter} a${rOuter},${rOuter} 0 0,1 -${rOuter},-${rOuter} v-${outerDim - 2 * rOuter} a${rOuter},${rOuter} 0 0,1 ${rOuter},-${rOuter} z`; } else if (opts.eyeOuterStyle === "circle") { const rOuter = 3.5 * cellSize; const cx = ex + rOuter; const cy = ey + rOuter; outerPath = `M${cx},${cy - rOuter} a${rOuter},${rOuter} 0 1,1 0,${rOuter * 2} a${rOuter},${rOuter} 0 1,1 0,-${rOuter * 2}`; } else if (opts.eyeOuterStyle === "leaf") { outerPath = leafEyePath(ex, ey, outerDim, 3.5 * cellSize, eye.name); } // Cutout Hole Path (middle gap) let cutPath = ""; const cutX = ex + cellSize; const cutY = ey + cellSize; const cutDim = 5 * cellSize; if (opts.eyeOuterStyle === "square") { cutPath = `M${cutX},${cutY} h${cutDim} v${cutDim} h-${cutDim} z`; } else if (opts.eyeOuterStyle === "rounded") { const rCut = 1.25 * cellSize; cutPath = `M${cutX + rCut},${cutY} h${cutDim - 2 * rCut} a${rCut},${rCut} 0 0,1 ${rCut},${rCut} v${cutDim - 2 * rCut} a${rCut},${rCut} 0 0,1 -${rCut},${rCut} h-${cutDim - 2 * rCut} a${rCut},${rCut} 0 0,1 -${rCut},-${rCut} v-${cutDim - 2 * rCut} a${rCut},${rCut} 0 0,1 ${rCut},-${rCut} z`; } else if (opts.eyeOuterStyle === "circle") { const rCut = 2.5 * cellSize; const cx = cutX + rCut; const cy = cutY + rCut; cutPath = `M${cx},${cy - rCut} a${rCut},${rCut} 0 1,1 0,${rCut * 2} a${rCut},${rCut} 0 1,1 0,-${rCut * 2}`; } else if (opts.eyeOuterStyle === "leaf") { cutPath = leafEyePath(cutX, cutY, cutDim, 2.5 * cellSize, eye.name); } if (!opts.backgroundColor || opts.backgroundColor === "transparent") { bodySvg += ``; } else { bodySvg += ``; bodySvg += ``; } // Inner Pupil Path let pupilPath = ""; const px = ex + gap; const py = ey + gap; if (opts.eyeInnerStyle === "square") { pupilPath = `M${px},${py} h${innerDim} v${innerDim} h-${innerDim} z`; } else if (opts.eyeInnerStyle === "rounded") { const rPupil = 0.75 * cellSize; pupilPath = `M${px + rPupil},${py} h${innerDim - 2 * rPupil} a${rPupil},${rPupil} 0 0,1 ${rPupil},${rPupil} v${innerDim - 2 * rPupil} a${rPupil},${rPupil} 0 0,1 -${rPupil},${rPupil} h-${innerDim - 2 * rPupil} a${rPupil},${rPupil} 0 0,1 -${rPupil},-${rPupil} v-${innerDim - 2 * rPupil} a${rPupil},${rPupil} 0 0,1 ${rPupil},-${rPupil} z`; } else if (opts.eyeInnerStyle === "circle") { const rPupil = 1.5 * cellSize; const cx = px + rPupil; const cy = py + rPupil; pupilPath = `M${cx},${cy - rPupil} a${rPupil},${rPupil} 0 1,1 0,${rPupil * 2} a${rPupil},${rPupil} 0 1,1 0,-${rPupil * 2}`; } else if (opts.eyeInnerStyle === "leaf") { pupilPath = leafEyePath(px, py, innerDim, 1.5 * cellSize, eye.name); } bodySvg += ``; }); // Center Brand Logo if (hasLogo) { const logoPxSize = Math.floor(qrActualSize * (opts.logoScale || 0.18)); const lx = offsetX + Math.floor((qrActualSize - logoPxSize) / 2); const ly = offsetY + Math.floor((qrActualSize - logoPxSize) / 2); const pad = opts.logoPadding || 0; const bgBoxSize = logoPxSize + pad * 2; const bgX = lx - pad; const bgY = ly - pad; const bgRadius = Math.floor(bgBoxSize * 0.25); bodySvg += ``; if (opts.logoType === "custom" && opts.customLogoUrl) { bodySvg += ``; } else if (ICONS[opts.logoType]) { const iconPath = ICONS[opts.logoType]; const scale = logoPxSize / 24; bodySvg += ` `; } } // Frame Styles if (opts.frameStyle === "card") { const borderOffset = Math.floor(res * 0.03); const borderRad = Math.floor(res * 0.04); const strokeW = Math.max(2, Math.floor(res * 0.01)); bodySvg += ``; } else if (isScanMe) { const bannerHeight = res - activeHeight; const bannerY = activeHeight; bodySvg += ``; const fontSize = Math.floor(bannerHeight * 0.35); const label = opts.frameText || "SCAN ME"; bodySvg += `${label}`; } else if (opts.frameStyle === "ticket") { const hasBg = opts.backgroundColor && opts.backgroundColor !== "transparent"; const strokeW = Math.max(2, Math.floor(res * 0.014)); const outerMargin = Math.floor(res * 0.05); const cornerRad = Math.floor(res * 0.07); const notchRad = Math.floor(res * 0.034); const fColor = opts.frameColor || "#0F172A"; bodySvg += ``; const innerMargin = outerMargin + Math.floor(strokeW * 2.2); bodySvg += ``; if (hasBg) { bodySvg += ``; bodySvg += ``; bodySvg += ``; bodySvg += ``; } } return `${bodySvg}`; } /** * Main Generator Function */ async function generateQr(input, options = {}) { const startTime = Date.now(); let opts = {}; if (typeof options === "string") { // If second arg is preset name opts = { preset: options }; } else if (typeof options === "object") { opts = { ...options }; } const payload = formatPayload(input); if (!payload) { throw new Error("Input payload cannot be empty."); } const svg = generateQrSvg(payload, opts); const dataUri = `data:image/svg+xml;utf8,${encodeURIComponent(svg)}`; return { status: true, source: "https://generate-qr-alpha.vercel.app", payload, preset: opts.preset || "custom", options: { moduleStyle: opts.moduleStyle || (opts.preset && PRESETS[opts.preset]?.patch.moduleStyle) || "square", colorType: opts.colorType || (opts.preset && PRESETS[opts.preset]?.patch.colorType) || "solid", primaryColor: opts.primaryColor || (opts.preset && PRESETS[opts.preset]?.patch.primaryColor) || "#141414", backgroundColor: opts.backgroundColor || (opts.preset && PRESETS[opts.preset]?.patch.backgroundColor) || "#FFFFFF", logoType: opts.logoType || "none", frameStyle: opts.frameStyle || (opts.preset && PRESETS[opts.preset]?.patch.frameStyle) || "none", resolution: opts.resolution || 512 }, svg, dataUri, available_presets: Object.keys(PRESETS), available_icons: Object.keys(ICONS).filter((k) => k !== "none"), elapsed_ms: Date.now() - startTime }; } module.exports = { generateQr, generateQrSvg, formatPayload, PRESETS, ICONS, DEFAULT_SETTINGS }; // CLI Runner if (require.main === module || process.argv[1]?.endsWith("generate-qr.js")) { let argInput = process.argv[2] || "https://vamxapi.my.id"; let argOpts = process.argv[3]; try { if (argInput.startsWith("{") && argInput.endsWith("}")) { argInput = JSON.parse(argInput); } } catch {} let opts = {}; if (argOpts) { try { if (argOpts.startsWith("{") && argOpts.endsWith("}")) { opts = JSON.parse(argOpts); } else { opts = argOpts; } } catch { opts = argOpts; } } generateQr(argInput, opts) .then((res) => { console.log(JSON.stringify(res, null, 2)); }) .catch((err) => { console.error(JSON.stringify({ status: false, error: err.message }, null, 2)); process.exit(1); }); }