"""Build small, reproducible TVNID brand assets using only Python's standard library."""
from pathlib import Path
import colorsys
import html
import json
import math
import re
import struct
import zlib
import zipfile
import shutil
from brand_logo_blueprint import render_blueprint
ROOT = Path(__file__).resolve().parents[1]
WEB = ROOT / "artifacts/tvnid"
WORKSPACE = WEB.is_dir()
OUT = WEB / "public/brands" if WORKSPACE else ROOT
SOURCE = WEB / "brand-source" if WORKSPACE else Path(__file__).resolve().parent
DESIGN_SYSTEM = ROOT / "artifacts/tvnid-design-system"
TOKEN_SOURCE = DESIGN_SYSTEM / "tokens.json" if WORKSPACE else SOURCE / "tokens.json"
THEME_SOURCE = DESIGN_SYSTEM / "src/theme.css" if WORKSPACE else SOURCE / "theme.css"
TOKENS = json.loads(TOKEN_SOURCE.read_text())
def design_token(path):
node = TOKENS
for key in path.split("."):
node = node[key]
value = node["$value"]
return design_token(value[1:-1]) if isinstance(value, str) and value.startswith("{") else value
PHI = (1 + math.sqrt(5)) / 2
# Native sketch units: B=1, A=φ×B, W=H=A+B. Normalize once for every output.
NATIVE_B, NATIVE_A = 1, PHI
NATIVE_H = NATIVE_A + NATIVE_B
H, RX, RY = 1, NATIVE_B / NATIVE_H, .5
S, G = NATIVE_B / NATIVE_H, (2 * PHI - 3) / NATIVE_H
T = (2 - PHI) / NATIVE_H
CX = CY = G / 2
DL, BS = S + G, 1 - RX
BLUE, RED = design_token("tvnid.identity.blue"), design_token("tvnid.identity.red")
EXACT = {"height": "1", "total_width": "1", "stem": "B ÷ (A + B)",
"d_stem": "(2 − φ) ÷ (A + B)", "gap": "(2φ − 3) ÷ (A + B)", "rx": "B ÷ (A + B)",
"ry": "1 ÷ 2", "d_width": "T + Rx", "d_left": "S + G",
"cx": "G ÷ 2", "cy": "G ÷ 2", "curve_start": "A ÷ (A + B)",
"ellipse_width": "2B ÷ (A + B)", "partition": "A = φ × B; B = 1",
"width": "S + G + T + Rx = 1"}
GRID = {"divisions": 20, "major_every": 5, "padding_cells": 2, "cell_size_exact": "1 ÷ 20",
"major_step_exact": "1 ÷ 4", "origin": [0, 0], "extent": [1, 1]}
FAVICON_SIZES = (16, 32, 48, 96, 180, 192, 512)
ICON_MARK_SCALE = 1.0
CIRCULAR_CENTER = 0.5
CIRCULAR_RADIUS = 0.5
CIRCULAR_MARK_SCALE = ICON_MARK_SCALE
CSS_GENERIC_FONT_FAMILIES = {
"serif", "sans-serif", "monospace", "cursive", "fantasy",
"system-ui", "ui-serif", "ui-sans-serif", "ui-monospace",
"ui-rounded", "math", "emoji", "fangsong",
}
def css_font_family_name(family):
"""Serialize a font family token as one valid CSS family value."""
if family.lower() in CSS_GENERIC_FONT_FAMILIES:
return family
escaped = []
for char in family:
codepoint = ord(char)
if char in {'"', "\\"}:
escaped.append("\\" + char)
elif codepoint == 0 or 0xD800 <= codepoint <= 0xDFFF:
escaped.append("\\fffd ")
elif codepoint < 0x20 or 0x7F <= codepoint <= 0x9F:
escaped.append(f"\\{codepoint:x} ")
else:
escaped.append(char)
return '"' + "".join(escaped) + '"'
def favicon_filename(size):
if size == 180:
return "apple-touch-icon.png"
return f'{"favicon" if size < 180 else "icon"}-{size}.png'
def color(name, hsl, role):
h, s, l = hsl
rgb = colorsys.hls_to_rgb(h / 360, l / 100, s / 100)
return {"name": name, "hex": "#" + "".join(f"{round(v * 255):02x}" for v in rgb),
"hsl": f"hsl({h} {s}% {l}%)", "role": role}
def technical_capability_color(name, light_hex, dark_hex, role):
return {"name": name, "hex": light_hex, "dark_hex": dark_hex, "role": role}
def token_color(name, path, role):
value = design_token(path)
rgb = [int(value[i:i+2], 16) / 255 for i in (1, 3, 5)]
h, l, s = colorsys.rgb_to_hls(*rgb)
return {"name": name, "hex": value, "hsl": f"hsl({h*360:.2f} {s*100:.2f}% {l*100:.2f}%)", "role": role}
LIGHT = [
token_color("Website Numeric blue", "tvnid.representations.light.numeric", "Current light-theme Numeric representation"),
token_color("Website Visual orange-red", "tvnid.representations.light.visual", "Current light-theme Visual representation"),
token_color("Paper", "color.light.background", "Light background"),
token_color("Ink", "color.light.foreground", "Light-theme text"),
]
DARK = [
token_color("Night", "color.dark.background", "Dark background"),
token_color("Warm white", "color.dark.foreground", "Dark-theme text"),
]
TECHNICAL_CAPABILITIES = [
technical_capability_color(name.title(), design_token(f"tvnid.technicalCapabilities.light.{name}"),
design_token(f"tvnid.technicalCapabilities.dark.{name}"), node["$description"])
for name, node in TOKENS["tvnid"]["technicalCapabilities"]["light"].items()
if not name.startswith("$")
]
SUPPORT = [
token_color("Dark Numeric blue", "tvnid.representations.dark.numeric", "Dark-theme Numeric representation"),
token_color("Dark Visual coral", "tvnid.representations.dark.visual", "Dark-theme Visual representation"),
token_color("Muted text", "color.light.mutedForeground", "Secondary light-theme text"),
token_color("Border", "color.light.border", "Dividers and outlines, not body text"),
token_color("Card", "color.light.card", "Raised light-theme surface"),
token_color("Error", "color.light.destructive", "Error states"),
]
def svg(body, viewbox="0 0 64 64", title="TVNID logo", width=256, height=256):
return (f'\n')
def rounded_d(x):
return (f"M {x+CX} 0 H {BS} A {RX} {RY} 0 0 1 {BS} 1 "
f"H {x+CX} A {CX} {CY} 0 0 1 {x} {1-CY} "
f"V {CY} A {CX} {CY} 0 0 1 {x+CX} 0 Z")
def golden(gap):
return (f''
f''), 1
def write(name, content):
target = OUT / name
target.parent.mkdir(parents=True, exist_ok=True)
target.write_text(content, encoding="utf8")
def wordmarks():
source = SOURCE
outlines = json.loads((source / "wordmark-outlines.json").read_text())
view = outlines["viewBox"]
for name, fill in [("ink", LIGHT[3]["hex"]), ("white", "#ffffff")]:
paths = "".join(f'' for d in outlines["paths"])
write(f"wordmark-{name}.svg", svg(
f'{paths}', " ".join(str(v) for v in view),
"TVNID secondary wordmark — Bricolage Grotesque SemiBold 600",
400, round(400 * view[3] / view[2], 3)))
write("Bricolage-Grotesque-OFL.txt", (source / "OFL.txt").read_text())
def build_logo_lockups():
outlines = json.loads((SOURCE / "wordmark-outlines.json").read_text())
paths = outlines["paths"]
if len(paths) < 3:
raise ValueError("The Bricolage Grotesque source must include T, V, and N outlines.")
# The vector joins are optical kerning in the outlined artwork, not a font ligature.
# Their top and baseline align exactly with the 1 × 1 ID symbol.
cap_height = 660
reference_stroke = 107 # Bricolage's TVN top-bar height in the saved outlines.
t_bar_right = 539
v_outer_top = 555
v_outer_baseline = 776
v_shift = (
t_bar_right - v_outer_top
- (v_outer_baseline - v_outer_top) * reference_stroke / cap_height
)
v_path = paths[1]
# Extend the V's two inner edges to their intersection, removing the
# short flat at its bottom so the letter ends in a point.
v_tip_rise = 6 * 552 / 167
v_tip = (866, -108 + v_tip_rise)
v_flat = "L860-108L872-108"
v_flat_count = v_path.count(v_flat)
v_path = v_path.replace(v_flat, f"L{v_tip[0]:g}{v_tip[1]:.3f}", 1)
if v_flat_count != 1:
raise ValueError("The saved V outline no longer has its expected flat bottom.")
v_right_top = 1176 + v_shift
v_right_baseline = 953 + v_shift
n_left = v_right_top - (v_right_top - v_right_baseline) * reference_stroke / cap_height
n_shift = n_left - 1248
tv_join_depth = (
(t_bar_right - (v_outer_top + v_shift))
* cap_height / (v_outer_baseline - v_outer_top)
)
if not math.isclose(tv_join_depth, reference_stroke, abs_tol=1e-9):
raise ValueError("The V–T overlap no longer matches the T top-bar thickness.")
tvn_right = 1853 + n_shift
symbol_gap = 0.16
edge_padding = 0.04
symbol_x = tvn_right / cap_height + symbol_gap
view_width = symbol_x + 1 + edge_padding
n_path = paths[2]
# Remove the two short horizontal shelves at N's diagonal joints. Extend
# each pair of adjoining edges to its true intersection so both corners
# finish as pointed joins rather than tiny flats.
right_t = 315 * 491 / 306
right_point = (
1414 + 314 * right_t / 491,
-660 + right_t,
)
left_t = 5100 / 336
left_point = (
1374 - 328 * left_t / 510,
-510 + left_t,
)
right_flat = "L1728-169L1737-169"
left_flat = "L1374-510L1364-510"
right_count, left_count = n_path.count(right_flat), n_path.count(left_flat)
n_path = n_path.replace(right_flat, f"L{right_point[0]:.3f}{right_point[1]:.3f}", 1)
n_path = n_path.replace(left_flat, f"L{left_point[0]:.3f}{left_point[1]:.3f}", 1)
if right_count != 1 or left_count != 1:
raise ValueError("The saved N outline no longer has the two expected flat diagonal joints.")
tvn_paths = (
f''
f''
f''
)
mark_body, _ = golden(G)
mono_mark = mark_body.replace(BLUE, "#171c2c").replace(RED, "#171c2c")
def build(text_fill, symbol, title):
body = (
f'{tvn_paths}'
f'{symbol}'
)
return svg(body, f"0 0 {view_width:.12f} 1", title,
round(view_width * 1000), 1000)
write("logo-lockup.svg", build(
LIGHT[3]["hex"], mark_body,
"TVNID logo — Bricolage Grotesque TVN wordmark and ID symbol"))
write("logo-lockup-white.svg", build(
"#ffffff", mark_body,
"TVNID logo for dark backgrounds — white TVN wordmark and ID symbol"))
write("logo-lockup-mono.svg", build(
"#171c2c", mono_mark, "TVNID monochrome logo"))
return {
"height": 1,
"tvn_height": 1,
"id_height": 1,
"width_px": round(view_width * 1000),
"height_px": 1000,
"symbol_gap": symbol_gap,
"viewbox_width": view_width,
"font": "Bricolage Grotesque",
"weight": 600,
"optical_size": 18,
"reference_stroke": reference_stroke,
"vn_join_depth": reference_stroke,
"letter_connections": "The outlined V touches T and N; both overlaps match the T top-bar stroke.",
"tv_join_depth": round(tv_join_depth, 9),
"v_tip_style": "The two inner V edges meet at a pointed intersection.",
"n_joint_style": "Both N diagonal joints end at pointed line intersections.",
}
USAGE = """# TVNID brand artwork usage
One identifier. Two representations.
The official TVNID logo combines the TVN lettering with the unit-square ID
symbol. Use logo-lockup.svg on light backgrounds, logo-lockup-white.svg on
dark backgrounds, or logo-lockup-mono.svg for monochrome. TVN and the ID
symbol have the same height. The Bricolage Grotesque SemiBold 600 outlines
are optically positioned so V touches T and N. Both V–T and V–N overlaps
match the height of the top-bar stroke; this is a custom outlined lockup, not an
automatic font ligature. Both N diagonal joints end at pointed intersections
instead of short flat shelves. The V's lower tip also ends at the pointed
intersection of its two inner edges.
The standalone square ID symbol remains available as logo.svg for color or
logo-mono.svg for monochrome. It is also used by the PNG favicons and app icons.
The standalone TVNID wordmark is a secondary text-only option: Bricolage
Grotesque SemiBold 600, tracking -0.025em, optical size 18. Bricolage Grotesque
is the primary brand typeface for the logo lettering and headings; Instrument
Sans supports body/interface text and JetBrains Mono supports identifiers and
code. The outlined SVGs need no installed font. Live text needs the font loaded.
The font is licensed under SIL OFL 1.1; see Bricolage-Grotesque-OFL.txt.
You may use the provided TVNID logo artwork in websites, applications,
documentation, presentations, and ID-related features. Include a visible
credit to TVNID and a link to the TVNID website or its /brands page in an
appropriate place, such as your acknowledgments or documentation.
Suggested credit: “TVNID — One identifier. Two representations.”
Reference: the published TVNID website's /brands page.
No permanent production domain has been configured in this kit; replace
relative references with the published website URL when citing externally.
You may adapt the artwork with attribution. Identify adaptations as
“Based on the TVNID logo” and do not present a modified mark as an official
TVNID release. Do not imply sponsorship or endorsement.
Use accessible text such as “TVNID identifier” alongside an ID feature;
do not rely only on color or the icon to communicate its meaning.
For an icon-only control, supply an accessible name describing its action.
Keep an unmodified mark's proportions and colors. Do not stretch, rotate,
add effects, or place it on a background that obscures it. Recommended
clear space for the ID mark is at least one I-stem width. Check legibility
at the actual display size; 16px samples are examples, not a guarantee.
Superseded artwork is not included in the public kit. Older public logo
URLs resolve to the current TVNID artwork so existing integrations stay consistent.
Favicons use the approved golden-partition geometry and square ID design.
PNG canvases are 16 × 16, 32 × 32, 48 × 48, 96 × 96, 180 × 180,
192 × 192, and 512 × 512 pixels. The mark fills each
square canvas without added outer padding. Each output pixel uses 4 × 4
coverage samples of the exact geometry; dimensions are not independently
snapped to whole pixels. For size n and scale q=1: I stem = n × q × S,
D stem = n × q × T, gap = n × q × G, D width = n × q × (T + Rx),
horizontal/vertical corner radii = n × q × Cx and n × q × Cy, and bowl
radii = n × q × Rx and n × q × Ry.
Pixel measurements for each PNG are supplied in brand.json.
The manifest references PNG images; no maskable-icon safe area is implied.
Circular ID logos at the same canvas sizes are available under
circular-id-icons/. Each is a circular alpha crop of its matching square icon.
The circle is centered in the square with a radius equal to half its width.
Pixels outside the circle are transparent; the source mark is not rescaled.
The approved golden-partition ID uses native units B=1 and A=φ×B.
Native W=H=A+B. Across the top: I + gap + D = B + A.
Across the bottom: left block + bowl = A + B.
The top A region includes the gap; the filled D is A minus the native gap wide.
Native gap g=2φ−3 and D stem t=2−φ, so t=φ×g and t+g=A−B.
Normalize all lengths by A+B to produce the 1 × 1 square.
S=Rx=B/(A+B), G=g/(A+B), T=t/(A+B), Ry=1/2.
The bowl is the right half of an ellipse with height/width=φ²/2, not φ.
All six small corners are circular with Cx=Cy=G/2, a secondary design choice.
Corner radii are inside the letter bounds, never added to the stem widths.
S + G + T + Rx = 1, A/B=φ and T/G=φ.
Display exact expressions rather than decimals except in pixel tables.
Use this ID construction; there is no optional narrower variant.
TVNID service software is licensed under the Mozilla Public License 2.0
(MPL-2.0). This does not license the brand artwork; see NOTICE.md and the
adjacent license text. Font files and their SIL OFL licenses are included under
fonts/.
Load /brands/fonts.css and /brands/tokens.css. All active assets, JSON,
source scripts and the downloadable ZIP are served from /brands.
Run python3 source/build_brand_assets.py from an extracted kit to rebuild
the SVGs, PNGs, ICO compatibility file, metadata and ZIP without dependencies.
"""
def build_vectors():
body, width = golden(G)
logo_svg = svg(
body, f"0 0 {width:.12f} {H}", "TVNID unit-square ID",
width=round(width * 256, 3), height=256)
mono = logo_svg.replace(BLUE, "#171c2c").replace(RED, "#171c2c")
write("logo.svg", logo_svg)
write("logo-mono.svg", mono)
# Preserve old public URLs without retaining competing active geometry.
for filename in ("logo-golden-a.svg", "logo-solid-id.svg", "logo-current-light.svg", "logo-current-dark.svg"):
write(filename, logo_svg)
for filename in ("logo-solid-id-mono.svg", "logo-current-mono.svg"):
write(filename, mono)
blueprint = render_blueprint(S, G, T, RX, RY, CX, CY, body, rounded_d(DL), EXACT)
write("blueprint.svg", svg(blueprint, "-0.34 -0.36 1.64 1.7",
"TVNID golden-partition blueprint", 984, 1020))
def build_font_archive():
css = (OUT / "fonts.css").read_text(encoding="utf8")
files = ["fonts.css"]
for reference in re.findall(r"url\(([^)]+)\)", css):
reference = reference.strip().strip("'\"")
if not reference.startswith("./fonts/"):
raise ValueError(f"Font stylesheet reference must be local: {reference}")
path = Path(reference[2:])
if ".." in path.parts:
raise ValueError(f"Font stylesheet reference escapes the font directory: {reference}")
if not (OUT / path).is_file():
raise FileNotFoundError(f"Font stylesheet reference is missing: {reference}")
files.append(path.as_posix())
files.extend(path.relative_to(OUT).as_posix()
for path in sorted((OUT / "fonts").glob("*-OFL.txt")))
if not any(path.endswith("-OFL.txt") for path in files):
raise ValueError("No SIL OFL font notices were found.")
archive_path = OUT / "tvnid-fonts.zip"
with zipfile.ZipFile(archive_path, "w", zipfile.ZIP_DEFLATED) as archive:
for name in sorted(set(files)):
info = zipfile.ZipInfo(name, date_time=(2026, 1, 1, 0, 0, 0))
info.compress_type = zipfile.ZIP_DEFLATED
archive.writestr(info, (OUT / name).read_bytes())
def in_rounded(x, y, left, top, width, height, rx, ry):
if not left <= x <= left + width or not top <= y <= top + height:
return False
dx = max(left + rx - x, 0, x - (left + width - rx))
dy = max(top + ry - y, 0, y - (top + height - ry))
return (dx / rx)**2 + (dy / ry)**2 <= 1
def png(size, circular=False):
"""RGBA PNG with a square ID mark or its circular alpha crop."""
colors = [tuple(bytes.fromhex(color[1:])) for color in (BLUE, RED)]
raw = bytearray()
offsets = (.125, .375, .625, .875)
sample_count = len(offsets)**2
left = S + G
mark_scale = ICON_MARK_SCALE
for py in range(size):
raw.append(0) # PNG scanline filter: none.
for px in range(size):
rgb, hits = [0, 0, 0], 0
for sy in offsets:
for sx in offsets:
canvas_x, canvas_y = (px + sx) / size, (py + sy) / size
in_circle = (
(canvas_x - CIRCULAR_CENTER)**2
+ (canvas_y - CIRCULAR_CENTER)**2
<= CIRCULAR_RADIUS**2
)
if circular and not in_circle:
continue
x = .5 + (canvas_x - .5) / mark_scale
y = .5 + (canvas_y - .5) / mark_scale
index = None
if in_rounded(x, y, 0, 0, S, H, CX, CY):
index = 0
stem = (left <= x <= BS and 0 <= y <= H and
(x >= left + CX or CY <= y <= H - CY or
((x - left - CX) / CX)**2 +
((y - (CY if y < CY else H - CY)) / CY)**2 <= 1))
bowl = x >= BS and ((x - BS) / RX)**2 + ((y - RY) / RY)**2 <= 1
if stem or bowl:
index = 1
if index is not None:
hits += 1
rgb = [a + b for a, b in zip(rgb, colors[index])]
raw.extend([round(v / hits) if hits else 0 for v in rgb] + [round(255 * hits / sample_count)])
def chunk(kind, content):
return struct.pack(">I", len(content)) + kind + content + struct.pack(">I", zlib.crc32(kind + content))
return (b"\x89PNG\r\n\x1a\n" + chunk(b"IHDR", struct.pack(">IIBBBBB", size, size, 8, 6, 0, 0, 0))
+ chunk(b"IDAT", zlib.compress(raw, 9)) + chunk(b"IEND", b""))
def main():
OUT.mkdir(parents=True, exist_ok=True)
if WORKSPACE:
# The public brand kit remains independently usable: it carries its own
# CSS, font files and license notices even though the app theme loads
# fonts through the shared design-system package.
shutil.copytree(SOURCE / "fonts", OUT / "fonts", dirs_exist_ok=True)
write("fonts.css", (SOURCE / "fonts.css").read_text())
for name in ("build_brand_assets.py", "brand_logo_blueprint.py"):
write(f"source/{name}", Path(__file__).with_name(name).read_text())
for name in ("wordmark-outlines.json", "OFL.txt"):
write(f"source/{name}", (SOURCE / name).read_text())
write("source/theme.css", THEME_SOURCE.read_text())
write("source/tokens.json", TOKEN_SOURCE.read_text())
wordmarks()
build_vectors()
lockup = build_logo_lockups()
write("site.webmanifest", json.dumps({"name": "TVNID", "short_name": "TVNID",
"start_url": "../", "scope": "../", "display": "standalone",
"theme_color": BLUE, "background_color": LIGHT[2]["hex"],
"icons": [{"src": f"icon-{s}.png", "sizes": f"{s}x{s}", "type": "image/png"} for s in (192, 512)]}, indent=2))
# Keep legacy SVG/ICO URLs compatible, but advertise and package PNG favicons.
body, _ = golden(G)
write("solid-id-icons/favicon.svg",
svg(body, "0 0 1 1", "TVNID ID favicon"))
favicon_rasters = []
for size in FAVICON_SIZES:
filename = f"solid-id-icons/{favicon_filename(size)}"
(OUT / filename).write_bytes(png(size))
favicon_rasters.append({
"file": filename, "width_px": size, "height_px": size, "format": "image/png",
"stem_px": size*ICON_MARK_SCALE*S,
"d_stem_px": size*ICON_MARK_SCALE*T,
"gap_px": size*ICON_MARK_SCALE*G,
"d_width_px": size*ICON_MARK_SCALE*(T+RX),
"corner_x_px": size*ICON_MARK_SCALE*CX,
"corner_y_px": size*ICON_MARK_SCALE*CY,
"bowl_x_px": size*ICON_MARK_SCALE*RX,
"bowl_y_px": size*ICON_MARK_SCALE*RY,
})
circular_logo_rasters = []
(OUT / "circular-id-icons").mkdir(parents=True, exist_ok=True)
for size in FAVICON_SIZES:
filename = f"circular-id-icons/circle-{size}.png"
(OUT / filename).write_bytes(png(size, circular=True))
circular_logo_rasters.append({
"file": filename, "width_px": size, "height_px": size,
"format": "image/png", "shape": "transparent circular crop of square ID icon",
"mark_scale": CIRCULAR_MARK_SCALE,
"circle_center_fraction": [0.5, 0.5],
"circle_center_512": [256, 256],
"circle_radius_512": 256,
"circle_radius": CIRCULAR_RADIUS,
"source_file": f"solid-id-icons/{favicon_filename(size)}",
})
solid_png = (OUT / "solid-id-icons/favicon-32.png").read_bytes()
(OUT / "solid-id-icons/favicon.ico").write_bytes(struct.pack("