289 lines
9.0 KiB
Plaintext
289 lines
9.0 KiB
Plaintext
// Shared Typst graphical elements. The variants preserve the original report and diagnostic palettes and spacing.
|
|
#import "@preview/primaviz:0.10.0": progress-bar
|
|
#let diag-progress-bar = progress-bar
|
|
|
|
#let dict-get(dict, key, default) = {
|
|
if key in dict {
|
|
dict.at(key)
|
|
} else {
|
|
default
|
|
}
|
|
}
|
|
|
|
#let as-content(value) = {
|
|
if value == none {
|
|
[]
|
|
} else {
|
|
str(value)
|
|
}
|
|
}
|
|
|
|
#let theme-color(theme, key) = rgb(str(dict-get(theme, key, "#000000")))
|
|
|
|
#let severity-color(theme, value) = {
|
|
let value = lower(str(value))
|
|
|
|
if value == "critical" or value == "high" {
|
|
theme-color(theme, "critical")
|
|
} else if value == "warning" or value == "medium" {
|
|
theme-color(theme, "warning")
|
|
} else if value == "ok" or value == "success" or value == "resolved" {
|
|
theme-color(theme, "success")
|
|
} else {
|
|
theme-color(theme, "info")
|
|
}
|
|
}
|
|
|
|
#let badge(
|
|
body,
|
|
color: none,
|
|
) = {
|
|
box(
|
|
inset: (x: 5pt, y: 2pt),
|
|
radius: 2pt,
|
|
fill: color.lighten(85%),
|
|
stroke: 0.6pt + color.lighten(45%),
|
|
text(
|
|
size: 7.5pt,
|
|
weight: "bold",
|
|
fill: color,
|
|
upper(str(body)),
|
|
),
|
|
)
|
|
}
|
|
|
|
#let metadata-line(theme, label, value) = {
|
|
if value != none and str(value) != "" {
|
|
stack(
|
|
spacing: 1.5pt,
|
|
text(
|
|
size: 8.5pt,
|
|
fill: theme-color(theme, "muted"),
|
|
weight: "bold",
|
|
)[#label],
|
|
text(
|
|
size: 8.5pt,
|
|
fill: theme-color(theme, "ink"),
|
|
)[#as-content(value)],
|
|
)
|
|
}
|
|
}
|
|
|
|
#let section-title(theme, body) = {
|
|
block(
|
|
above: 1.1em,
|
|
below: 0.55em,
|
|
width: 100%,
|
|
)[
|
|
#text(
|
|
size: 13pt,
|
|
weight: "bold",
|
|
fill: theme-color(theme, "accent"),
|
|
)[#body]
|
|
|
|
#v(2.5pt)
|
|
|
|
#line(
|
|
length: 100%,
|
|
stroke: 0.7pt + theme-color(theme, "line"),
|
|
)
|
|
]
|
|
}
|
|
|
|
#let subsection-title(theme, body) = {
|
|
block(
|
|
above: 0.8em,
|
|
below: 0.35em,
|
|
)[
|
|
#text(
|
|
size: 10.5pt,
|
|
weight: "bold",
|
|
fill: theme-color(theme, "ink"),
|
|
)[#body]
|
|
]
|
|
}
|
|
|
|
#let callout(
|
|
theme,
|
|
body,
|
|
title: none,
|
|
kind: "info",
|
|
breakable: true,
|
|
) = {
|
|
let color = severity-color(theme, kind)
|
|
|
|
block(
|
|
width: 100%,
|
|
inset: 8pt,
|
|
breakable: breakable,
|
|
radius: 2pt,
|
|
fill: color.lighten(91%),
|
|
stroke: (
|
|
left: 2.5pt + color,
|
|
top: 0.5pt + color.lighten(65%),
|
|
right: 0.5pt + color.lighten(65%),
|
|
bottom: 0.5pt + color.lighten(65%),
|
|
),
|
|
)[
|
|
#if title != none {
|
|
text(
|
|
size: 9pt,
|
|
weight: "bold",
|
|
fill: color,
|
|
)[ #title ]
|
|
|
|
v(3pt)
|
|
}
|
|
|
|
#body
|
|
]
|
|
}
|
|
|
|
#let code-block(theme, body) = {
|
|
block(
|
|
width: 100%,
|
|
inset: 7pt,
|
|
radius: 2pt,
|
|
fill: rgb("#f2f3f4"),
|
|
stroke: 0.5pt + theme-color(theme, "line"),
|
|
)[
|
|
#text(
|
|
font: dict-get(theme, "mono_font", "DejaVu Sans Mono"),
|
|
size: 8.2pt,
|
|
fill: theme-color(theme, "ink"),
|
|
)[
|
|
#body
|
|
]
|
|
]
|
|
}
|
|
|
|
|
|
|
|
#let diag-get(dict, key, default) = if key in dict and dict.at(key) != none { dict.at(key) } else { default }
|
|
#let diag-color(theme, key) = rgb(str(diag-get(theme, key, "#000000")))
|
|
#let diag-ink(theme) = diag-color(theme, "ink")
|
|
#let diag-muted(theme) = diag-color(theme, "muted")
|
|
#let diag-accent(theme) = diag-color(theme, "accent")
|
|
#let diag-line-color(theme) = diag-color(theme, "line")
|
|
#let diag-soft(theme) = diag-color(theme, "paper_soft")
|
|
|
|
#let diag-severity-color(theme, severity) = {
|
|
let value = lower(str(severity))
|
|
if value == "critical" or value == "high" { diag-color(theme, "critical") }
|
|
else if value == "warning" or value == "medium" { diag-color(theme, "warning") }
|
|
else if value == "success" or value == "ok" { diag-color(theme, "success") }
|
|
else if value == "unanalysed" { diag-color(theme, "info") }
|
|
else { diag-color(theme, "info") }
|
|
}
|
|
|
|
#let diag-badge(body, fill) = box(
|
|
inset: (x: 5pt, y: 2pt), radius: 2pt,
|
|
fill: fill.lighten(86%), stroke: .5pt + fill.lighten(50%),
|
|
text(size: 7pt, weight: "bold", fill: fill)[#upper(str(body))],
|
|
)
|
|
|
|
#let diag-heading(theme, body) = block(above: 10pt, below: 5pt, width: 100%)[
|
|
#text(size: 14pt, weight: "bold", fill: diag-accent(theme))[#body]
|
|
#v(2pt)
|
|
#line(length: 100%, stroke: .7pt + diag-line-color(theme))
|
|
]
|
|
|
|
#let diag-part-title(theme, number, body, description: none) = block(width: 100%, below: 10pt)[
|
|
#text(size: 7.5pt, weight: "bold", fill: diag-muted(theme))[SECTION #number]
|
|
#v(2pt)
|
|
#text(size: 19pt, weight: "bold", fill: diag-accent(theme))[#body]
|
|
#if description != none { v(2pt); text(size: 8.5pt, fill: diag-muted(theme))[#description] }
|
|
#v(4pt)
|
|
#line(length: 100%, stroke: .8pt + diag-line-color(theme))
|
|
]
|
|
|
|
#let diag-panel(theme, body, stroke: none, fill: none) = block(
|
|
width: 100%, inset: 8pt, radius: 3pt,
|
|
fill: if fill == none { diag-soft(theme) } else { fill },
|
|
stroke: .5pt + if stroke == none { diag-line-color(theme) } else { stroke },
|
|
body,
|
|
)
|
|
|
|
#let diag-metric(theme, title, value, note: none, tone: none) = {
|
|
let tone = if tone == none { diag-accent(theme) } else { tone }
|
|
block(width: 100%, inset: 7pt, radius: 3pt, fill: tone.lighten(91%), stroke: .5pt + tone.lighten(60%))[
|
|
#text(size: 7pt, weight: "bold", fill: diag-muted(theme))[#upper(title)]
|
|
#v(2pt)
|
|
#text(size: 16pt, weight: "bold", fill: tone)[#value]
|
|
#if note != none { v(1pt); text(size: 7pt, fill: diag-muted(theme))[#note] }
|
|
]
|
|
}
|
|
|
|
#let diag-short-text(value, limit: 400) = {
|
|
let text = str(value)
|
|
if text.len() > limit { text.slice(0, limit) + "… [excerpt; full text in source JSON]" } else { text }
|
|
}
|
|
#let diag-finding-target(index) = label("diagnostic-finding-" + str(index))
|
|
|
|
#let diag-finding-card(theme, finding, show-remediation: true, target-index: none, link-index: none) = {
|
|
let tone = diag-severity-color(theme, diag-get(finding, "severity", "info"))
|
|
if target-index != none { [#metadata("finding") #diag-finding-target(target-index)] }
|
|
block(width: 100%, breakable: true, inset: 7pt, radius: 3pt,
|
|
stroke: (left: 2.5pt + tone, top: .5pt + diag-line-color(theme), right: .5pt + diag-line-color(theme), bottom: .5pt + diag-line-color(theme)),
|
|
)[
|
|
#grid(columns: (1fr, auto), gutter: 6pt,
|
|
text(weight: "bold", fill: diag-ink(theme))[#diag-get(finding, "title", "Finding")],
|
|
[#diag-badge(diag-get(finding, "severity", "info"), tone) #h(3pt) #diag-badge(str(diag-get(finding, "confidence", 50)) + "% confidence", tone)],
|
|
)
|
|
#v(3pt)
|
|
#text(size: 8.5pt, fill: diag-ink(theme))[#diag-get(finding, "detail", "")]
|
|
#if show-remediation and diag-get(finding, "evidence", "") != "" {
|
|
v(2pt)
|
|
text(size: 7.5pt, fill: diag-muted(theme))[Evidence: #diag-short-text(finding.evidence)]
|
|
}
|
|
#if show-remediation and diag-get(finding, "watch_id", none) != none {
|
|
v(2pt)
|
|
text(size: 7.5pt, fill: diag-accent(theme))[#link(label("watchlist-" + finding.watch_id))[View known-issue list →]]
|
|
}
|
|
#if link-index != none {
|
|
v(3pt)
|
|
text(size: 7.5pt, weight: "bold", fill: diag-accent(theme))[
|
|
#link(diag-finding-target(link-index))[View resolution →]
|
|
]
|
|
}
|
|
#if diag-get(finding, "fading", false) and diag-get(finding, "weight_factor", 1.0) < 1.0 {
|
|
v(2pt)
|
|
let pct = calc.round(diag-get(finding, "weight_factor", 1.0) * 100)
|
|
text(size: 7pt, style: "italic", fill: diag-muted(theme))[Age-adjusted to #pct% weight at #diag-get(finding, "age_days", 0) days old; never reduced below 50%.]
|
|
}
|
|
#if show-remediation and (diag-get(finding, "resolution_steps", ()).len() > 0 or diag-get(finding, "remediation", "") != "") {
|
|
v(4pt)
|
|
text(size: 7.5pt, weight: "bold", fill: tone)[RESOLUTION PATH]
|
|
v(2pt)
|
|
let steps = diag-get(finding, "resolution_steps", ())
|
|
if steps.len() > 0 {
|
|
for (index, step) in steps.enumerate() {
|
|
grid(columns: (10pt, 1fr), gutter: 3pt, text(size: 7.8pt, weight: "bold", fill: tone)[#str(index + 1).], text(size: 8pt, fill: diag-ink(theme))[#step])
|
|
v(1.5pt)
|
|
}
|
|
} else {
|
|
grid(columns: (10pt, 1fr), gutter: 3pt, text(size: 7.8pt, weight: "bold", fill: tone)[1.], text(size: 8pt, fill: diag-ink(theme))[#diag-get(finding, "remediation", "")])
|
|
}
|
|
let url = diag-get(finding, "reference_url", "")
|
|
if url != "" { v(2pt); text(size: 7.5pt, fill: diag-accent(theme))[#link(url)[#diag-get(finding, "reference_label", "Reference guidance") ↗]] }
|
|
}
|
|
#if diag-get(finding, "count", 0) > 1 {
|
|
v(2pt)
|
|
text(size: 7.5pt, fill: diag-muted(theme))[Observed #diag-get(finding, "count", 0) times in the captured window.]
|
|
}
|
|
]
|
|
v(5pt)
|
|
}
|
|
|
|
#let diag-evidence(theme, item) = block(width: 100%, breakable: diag-get(item, "text", "").len() > 2000, below: 6pt)[
|
|
#let tone = diag-severity-color(theme, diag-get(item, "severity", "info"))
|
|
#text(size: 9pt, weight: "bold", fill: tone)[#diag-get(item, "title", "Evidence")]
|
|
#v(3pt)
|
|
#block(width: 100%, inset: 6pt, radius: 2pt, fill: tone.lighten(94%), stroke: (left: 2pt + tone, top: .4pt + diag-line-color(theme), right: .4pt + diag-line-color(theme), bottom: .4pt + diag-line-color(theme)))[
|
|
#text(font: diag-get(theme, "mono_font", "DejaVu Sans Mono"), size: 6.8pt, fill: diag-ink(theme))[
|
|
#diag-get(item, "text", "")
|
|
]
|
|
]
|
|
]
|
|
|