JavaScript Python PHP
async function executar(values) {
function generateFrontendShapes(v) {
const shape = feChoice(v.shape, ['onda', 'blob', 'divisor', 'pontos']), w = feInteger(v.width, 'Largura', 16, 2048), h = feInteger(v.height, 'Altura', 16, 2048), bg = feColor(v.background), fg = feColor(v.foreground), intensity = feInteger(v.intensity, 'Intensidade', 1, 100);
const a = h * intensity / 200, n = (v) => Math.round(v * 1000) / 1000;
let body = '';
if (shape === 'onda')
body = `<path d="M0 ${n(h / 2)} C${n(w / 3)} ${n(h / 2 - a)} ${n(2 * w / 3)} ${n(h / 2 + a)} ${w} ${n(h / 2)} L${w} ${h} L0 ${h}Z" fill="${fg}"/>`;
if (shape === 'divisor')
body = `<path d="M0 ${n(h - a * 2)} L${w} ${h} H0Z" fill="${fg}"/>`;
if (shape === 'pontos') {
const spacing = 8 + intensity;
body = `<defs><pattern id="dots" width="${spacing}" height="${spacing}" patternUnits="userSpaceOnUse"><circle cx="${spacing / 2}" cy="${spacing / 2}" r="${Math.max(1, spacing / 10)}" fill="${fg}"/></pattern></defs><rect width="${w}" height="${h}" fill="url(#dots)"/>`;
}
if (shape === 'blob') {
const points = Array.from({ length: 12 }, (_, i) => { const angle = i * Math.PI / 6, r = .34 + Math.sin(i * 2.3) * intensity / 1000; return `${n(w / 2 + Math.cos(angle) * w * r)},${n(h / 2 + Math.sin(angle) * h * r)}`; });
body = `<path d="M${points[0]} ${points.slice(1).map((p, i) => { const [x, y] = points[i].split(',').map(Number), [nx, ny] = p.split(',').map(Number); return `Q${x} ${y} ${n((x + nx) / 2)} ${n((y + ny) / 2)}`; }).join(' ')} Q${points[11].replace(',', ' ')} ${points[0].replace(',', ' ')}Z" fill="${fg}"/>`;
}
return feImage(feSvg(w, h, `<rect width="${w}" height="${h}" fill="${bg}"/>${body}`), 'Forma SVG: ' + shape);
}
function feInteger(value, label, min, max) {
if (!/^-?\d+$/.test(value || '') || !Number.isSafeInteger(Number(value)) || Number(value) < min || Number(value) > max)
throw new Error(`${label}: use um inteiro de ${min} a ${max}.`);
return Number(value);
}
function feColor(value) {
if (!/^#[\da-f]{6}$/i.test(value || ''))
throw new Error('Informe cores HEX com # e seis dígitos.');
return value.toLowerCase();
}
function feChoice(value, choices) {
if (!choices.includes(value))
throw new Error('Opção não suportada: ' + value);
return value;
}
function feSvg(width, height, body) {
return `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">${body}</svg>`;
}
function feImage(svg, label) {
return { text: svg, images: [{ label, svg }] };
}
for (const value of Object.values(values)) if (typeof value !== "string" || value.length > 100000) throw new Error("Use até 100 mil caracteres por campo.");
return await generateFrontendShapes(values);
}
import html
import json
import math
import re
from urllib.parse import urlsplit, urlunsplit
def executar(values):
def text(value, limit=100000):
if not isinstance(value, str) or len(value.encode('utf-16-le')) // 2 > limit:
raise ValueError('Texto excede o limite permitido.')
if re.search(r'[\x00-\x08\x0b\x0c\x0e-\x1f\ufffe\uffff\ud800-\udfff]', value):
raise ValueError('Controle ou Unicode inválido.')
return value
def integer(value, minimum, maximum):
if not isinstance(value, str) or not re.fullmatch(r'-?[0-9]+', value) or not minimum <= int(value) <= maximum:
raise ValueError('Inteiro fora dos limites permitidos.')
return int(value)
def color(value):
if not re.fullmatch(r'#[0-9a-fA-F]{6}', value):
raise ValueError('Cor HEX inválida.')
return value.lower()
def choice(value, options):
if value not in options:
raise ValueError('Opção não suportada.')
return value
def esc(value):
return html.escape(text(value), quote=True).replace(''', ''')
def url(value):
text(value, 2048)
parsed = urlsplit(value)
if not re.match(r'https?://', value, re.I) or parsed.scheme not in ('http', 'https') or not parsed.hostname or parsed.username or parsed.password or re.search(r'[\s\\]', value):
raise ValueError('Use uma URL HTTP/HTTPS absoluta sem credenciais.')
if parsed.port is not None and not 0 <= parsed.port <= 65535:
raise ValueError('Porta inválida.')
return value
def svg(width, height, body):
return f'<svg xmlns="http://www.w3.org/2000/svg" width="{width}" height="{height}" viewBox="0 0 {width} {height}">{body}</svg>'
def image(markup, label):
return {'text': markup, 'images': [{'label': label, 'svg': markup}]}
def num(value):
rounded = math.floor(value * 1000 + 0.5) / 1000
return str(int(rounded)) if rounded.is_integer() else str(rounded)
for value in values.values():
if not isinstance(value, str) or len(value.encode('utf-16-le')) // 2 > 100000:
raise ValueError('Use até 100 mil caracteres por campo.')
shape = choice(values['shape'], ['onda', 'blob', 'divisor', 'pontos'])
width, height = integer(values['width'], 16, 2048), integer(values['height'], 16, 2048)
bg, fg, intensity = color(values['background']), color(values['foreground']), integer(values['intensity'], 1, 100)
amplitude, body = height * intensity / 200, ''
if shape == 'onda':
body = f'<path d="M0 {num(height / 2)} C{num(width / 3)} {num(height / 2 - amplitude)} {num(2 * width / 3)} {num(height / 2 + amplitude)} {width} {num(height / 2)} L{width} {height} L0 {height}Z" fill="{fg}"/>'
elif shape == 'divisor':
body = f'<path d="M0 {num(height - amplitude * 2)} L{width} {height} H0Z" fill="{fg}"/>'
elif shape == 'pontos':
spacing = 8 + intensity
body = f'<defs><pattern id="dots" width="{spacing}" height="{spacing}" patternUnits="userSpaceOnUse"><circle cx="{num(spacing / 2)}" cy="{num(spacing / 2)}" r="{num(max(1, spacing / 10))}" fill="{fg}"/></pattern></defs><rect width="{width}" height="{height}" fill="url(#dots)"/>'
else:
points = []
for i in range(12):
angle, radius = i * math.pi / 6, 0.34 + math.sin(i * 2.3) * intensity / 1000
points.append((float(num(width / 2 + math.cos(angle) * width * radius)), float(num(height / 2 + math.sin(angle) * height * radius))))
commands = []
for i in range(11):
x, y = points[i]
nx, ny = points[i + 1]
commands.append(f'Q{num(x)} {num(y)} {num((x + nx) / 2)} {num((y + ny) / 2)}')
body = f'<path d="M{num(points[0][0])},{num(points[0][1])} ' + ' '.join(commands) + f' Q{num(points[11][0])} {num(points[11][1])} {num(points[0][0])} {num(points[0][1])}Z" fill="{fg}"/>'
return image(svg(width, height, f'<rect width="{width}" height="{height}" fill="{bg}"/>' + body), 'Forma SVG: ' + shape)
<?php
function executar(array $values): array {
$text = static function ($value, $limit = 100000) {
if (!is_string($value) || !preg_match('//u', $value) || strlen(iconv('UTF-8', 'UTF-16LE', $value)) / 2 > $limit || preg_match('/[\x00-\x08\x0b\x0c\x0e-\x1f\x{fffe}\x{ffff}]/u', $value)) { throw new InvalidArgumentException('Texto excede o limite ou contém caracteres inválidos.'); }
return $value;
};
$integer = static function ($value, $min, $max) {
if (!is_string($value) || !preg_match('/^-?[0-9]+$/D', $value) || strlen(ltrim($value, '-0')) > 10 || (float)$value < $min || (float)$value > $max) { throw new InvalidArgumentException('Inteiro fora dos limites permitidos.'); }
return (int)$value;
};
$color = static function ($value) {
if (!preg_match('/^#[0-9a-fA-F]{6}$/D', $value)) { throw new InvalidArgumentException('Cor HEX inválida.'); }
return strtolower($value);
};
$choice = static function ($value, $options) {
if (!in_array($value, $options, true)) { throw new InvalidArgumentException('Opção não suportada.'); }
return $value;
};
$esc = static function ($value) use ($text) { return str_replace(''', ''', htmlspecialchars($text($value), ENT_QUOTES | ENT_HTML401, 'UTF-8')); };
$url = static function ($value) use ($text) {
$text($value, 2048); $p = parse_url($value);
if (!$p || !isset($p['host']) || !in_array(strtolower($p['scheme'] ?? ''), ['http', 'https'], true) || isset($p['user']) || isset($p['pass']) || preg_match('/[\s\\\\]/u', $value)) { throw new InvalidArgumentException('Use URL HTTP/HTTPS absoluta sem credenciais.'); }
return $value;
};
$svg = static function ($w, $h, $body) { return '<svg xmlns="http://www.w3.org/2000/svg" width="' . $w . '" height="' . $h . '" viewBox="0 0 ' . $w . ' ' . $h . '">' . $body . '</svg>'; };
$image = static function ($markup, $label) { return ['text' => $markup, 'images' => [['label' => $label, 'svg' => $markup]]]; };
$num = static function ($value) { return (string)(floor($value * 1000 + 0.5) / 1000); };
foreach ($values as $value) { if (!is_string($value) || !preg_match('//u', $value) || strlen(iconv('UTF-8', 'UTF-16LE', $value)) / 2 > 100000) { throw new InvalidArgumentException('Use até 100 mil caracteres por campo.'); } }
$shape = $choice($values['shape'], ['onda', 'blob', 'divisor', 'pontos']); $w = $integer($values['width'], 16, 2048); $h = $integer($values['height'], 16, 2048); $bg = $color($values['background']); $fg = $color($values['foreground']); $intensity = $integer($values['intensity'], 1, 100); $a = $h * $intensity / 200;
if ($shape === 'onda') { $body = '<path d="M0 ' . $num($h / 2) . ' C' . $num($w / 3) . ' ' . $num($h / 2 - $a) . ' ' . $num(2 * $w / 3) . ' ' . $num($h / 2 + $a) . ' ' . $w . ' ' . $num($h / 2) . ' L' . $w . ' ' . $h . ' L0 ' . $h . 'Z" fill="' . $fg . '"/>'; }
elseif ($shape === 'divisor') { $body = '<path d="M0 ' . $num($h - 2 * $a) . ' L' . $w . ' ' . $h . ' H0Z" fill="' . $fg . '"/>'; }
elseif ($shape === 'pontos') { $s = 8 + $intensity; $body = '<defs><pattern id="dots" width="' . $s . '" height="' . $s . '" patternUnits="userSpaceOnUse"><circle cx="' . $num($s / 2) . '" cy="' . $num($s / 2) . '" r="' . $num(max(1, $s / 10)) . '" fill="' . $fg . '"/></pattern></defs><rect width="' . $w . '" height="' . $h . '" fill="url(#dots)"/>'; }
else { $p = []; for ($i = 0; $i < 12; $i++) { $angle = $i * M_PI / 6; $r = 0.34 + sin($i * 2.3) * $intensity / 1000; $p[] = [(float)$num($w / 2 + cos($angle) * $w * $r), (float)$num($h / 2 + sin($angle) * $h * $r)]; } $body = '<path d="M' . $num($p[0][0]) . ',' . $num($p[0][1]) . ' '; for ($i = 0; $i < 11; $i++) { $body .= 'Q' . $num($p[$i][0]) . ' ' . $num($p[$i][1]) . ' ' . $num(($p[$i][0] + $p[$i + 1][0]) / 2) . ' ' . $num(($p[$i][1] + $p[$i + 1][1]) / 2) . ($i < 10 ? ' ' : ''); } $body .= ' Q' . $num($p[11][0]) . ' ' . $num($p[11][1]) . ' ' . $num($p[0][0]) . ' ' . $num($p[0][1]) . 'Z" fill="' . $fg . '"/>'; }
return $image($svg($w, $h, '<rect width="' . $w . '" height="' . $h . '" fill="' . $bg . '"/>' . $body), 'Forma SVG: ' . $shape);
}