tiny.zen.diagram.ego.model
Defined in diagram.ego.
API (21)
Actions
Public operations.
safeHrefslotsPerBand: Returns the bounded visible slot count for one call-map band.validatevalidateBandvalidateNode
Types and contracts
Public types and contracts.
ArrangementBand: One call direction with exact total count and a bounded ordered sample.ErrorGeometryNetwork: A declaration and its direct callers and callees.Node: One declaration in a call map.Surface: Selects geometry for a documentation margin or the wider reading surface.
Values and defaults
Public values and defaults.
badge_bytes_maxcontext_bytes_maxhref_bytes_maxlabel_bytes_maxmargin_slots_per_bandmax_slots_per_bandmax_source_nodes_per_bandtitle_bytes_maxwide_slots_per_band
Source
Source: lib/zen/src/diagram/ego/model.zig
zig
const std = @import("std");pub const max_source_nodes_per_band: usize = 12;pub const max_slots_per_band: usize = 6;pub const margin_slots_per_band: u8 = 3;pub const wide_slots_per_band: u8 = 6;pub const label_bytes_max: usize = 40;pub const context_bytes_max: usize = 48;pub const badge_bytes_max: usize = 48;pub const title_bytes_max: usize = 192;pub const href_bytes_max: usize = 512;/// One declaration in a call map. An empty href renders non-interactive text.pub const Node = struct { label: []const u8, context: []const u8 = "", badge: []const u8 = "", title: []const u8 = "", href: []const u8,};/// One call direction with exact total count and a bounded ordered sample.pub const Band = struct { nodes: []const Node = &.{}, total: u32 = 0, more_href: []const u8 = "",};/// A declaration and its direct callers and callees.pub const Network = struct { subject: Node, callers: Band = .{}, callees: Band = .{}, recursive: bool = false,};/// Selects geometry for a documentation margin or the wider reading surface.pub const Surface = enum { margin, wide,};/// Returns the bounded visible slot count for one call-map band.pub fn slotsPerBand(surface: Surface) u8 { return switch (surface) { .margin => margin_slots_per_band, .wide => wide_slots_per_band, };}pub const Arrangement = enum { horizontal, vertical,};pub const Geometry = struct { arrangement: Arrangement, width: u16, height: u16, slots_per_band: u8, outer_inset: f32, node_width: f32, subject_width: f32, node_height: f32, subject_height: f32, heading_size: f32, empty_size: f32, label_size: f32, context_size: f32, badge_size: f32, subject_label_size: f32,};pub const Error = error{ EmptyNodeLabel, InvalidBandTotal, InvalidText, MissingOverflowLink, NodeBadgeTooLong, NodeContextTooLong, NodeLabelTooLong, NodeLinkTooLong, NodeTitleTooLong, TooManySourceNodes, UnsafeNodeLink,};pub fn validate(network: Network) Error!void { try validateNode(network.subject); try validateBand(network.callers); try validateBand(network.callees);}pub fn validateNode(node: Node) Error!void { if (node.label.len == 0) return error.EmptyNodeLabel; if (node.label.len > label_bytes_max) return error.NodeLabelTooLong; if (node.context.len > context_bytes_max) return error.NodeContextTooLong; if (node.badge.len > badge_bytes_max) return error.NodeBadgeTooLong; if (node.title.len > title_bytes_max) return error.NodeTitleTooLong; if (node.href.len > href_bytes_max) return error.NodeLinkTooLong; if (!validText(node.label) or !validText(node.context) or !validText(node.badge) or !validText(node.title) or !validText(node.href)) return error.InvalidText; if (node.href.len > 0 and !safeHref(node.href)) return error.UnsafeNodeLink;}pub fn validateBand(band: Band) Error!void { if (band.nodes.len > max_source_nodes_per_band) { return error.TooManySourceNodes; } if (band.total < band.nodes.len) return error.InvalidBandTotal; std.debug.assert(band.nodes.len <= max_source_nodes_per_band); for (band.nodes) |node| try validateNode(node); if (band.more_href.len > href_bytes_max) return error.NodeLinkTooLong; if (!validText(band.more_href)) return error.InvalidText; if (band.more_href.len > 0 and !safeHref(band.more_href)) { return error.UnsafeNodeLink; }}fn validText(value: []const u8) bool { if (!std.unicode.utf8ValidateSlice(value)) return false; for (value) |byte| { if (byte < ' ' and byte != '\t') return false; if (byte == 0x7f) return false; } return true;}pub fn safeHref(value: []const u8) bool { std.debug.assert(value.len > 0); if (switch (value[0]) { '#', '/', '?', '.' => true, else => false, }) return true; const authority_start = if (std.mem.startsWith(u8, value, "https://")) "https://".len else if (std.mem.startsWith(u8, value, "http://")) "http://".len else return false; const authority_end = std.mem.indexOfScalarPos( u8, value, authority_start, '/', ) orelse value.len; if (authority_end == authority_start) return false; for (value) |byte| switch (byte) { ' ', '\t', '\\', '"', '\'', '<', '>' => return false, else => {}, }; return true;}Source: lib/zen/src/diagram/ego/root.zig:2
zig
pub const model = @import("model.zig");Audit
| Definitions | 22 |
|---|---|
| Public names | 29 |
| Members | 42 |
| Version | 26.7.0 |
| Revision | daab053ee433 |