/* eslint-disable @typescript-eslint/no-explicit-any -- pomocný skript nad JSON výstupmi z prevodu */ // Zostavenie šablón cenoviek z výstupu convert-illustrator-svg.py (public/__svg/conv.json) a vrstiev // zmeraných v prehliadači (scripts/badges/layers.json, vytvára measure.js). Zapíše public/__svg/rows.json // (riadky tabuľky badges) a public/__svg/compare.html (porovnanie s originálmi). // Spustenie: npx tsx --tsconfig tsconfig.json scripts/badges/build-templates.ts [filter názvu] [mierka] import fs from 'fs'; import { renderCleanBadgeSvg, badgeFromRow } from '../../src/lib/badgeUtils'; const conv = JSON.parse(fs.readFileSync('public/__svg/conv.json', 'utf8')); const L = JSON.parse(fs.readFileSync('scripts/badges/layers.json', 'utf8')); const rows = L.map(([file, name, tags, crop, width, layers]: any) => { const c = conv.find((x: any) => x.file === file); return { file, name, svg_raw: ``, layers_config: { width, align: 'center', paddingTop: 4, paddingBottom: 4, importTags: tags, layers: layers.map(([text, al, x, y, fontSize, fill, font, ifs, ioy, iox, ls, sy]: any, i: number) => ({ id: `l-${c.key}-${i}`, type: 'text', text, align: { c: 'center', l: 'left', r: 'right' }[al as 'c'], x, y, fontSize, fill: fill === 'w' ? '#ffffff' : fill, fontFamily: font === 'A' ? 'Aptly' : 'korolev-condensed, Korolev Condensed', fontSource: 'adobe', fontWeight: font === 'A' ? '700' : font.slice(1), ...(ifs !== '' ? { indexFontSize: ifs, indexOffsetY: ioy, indexOffsetX: iox, longPriceScale: 0.8 } : {}), ...(ls !== '' ? { letterSpacing: ls } : {}), ...(sy !== '' ? { scaleY: sy } : {}) })).map((l: any, _i: number, all: any[]) => { // nápis „zľava“ len pri vyplnenej zľave – patrí k najbližšej premennej {zlava…} if (l.text !== 'zľava') return l; const d = all.filter((x: any) => /^\{zlava/.test(x.text)).sort((a: any, b: any) => Math.abs(a.y - l.y) - Math.abs(b.y - l.y))[0]; return d ? { ...l, showIfFilled: d.text } : l; }) } }; }); fs.writeFileSync('public/__svg/rows.json', JSON.stringify(rows)); const sample = { priceMain: '0', priceSub: '00', discountText: '00%', unitPrice: 'jednotková cena 000 EUR/kg', appPriceMain: '0', appPriceSub: '00', appDiscount: '00%', appUnitPrice: 'jednotková cena 000 EUR/kg', cardPriceMain: '0', cardPriceSub: '00', cardDiscount: '00%', cardUnitPrice: 'jednotková cena 000 EUR/kg', noCardPriceMain: '0', noCardPriceSub: '00', noCardDiscount: '00%', noCardUnitPrice: 'jednotková cena 000 EUR/kg' }; const only = process.argv[2] ? new RegExp(process.argv[2]) : null; const scale = Number(process.argv[3] || 1); let html = '