svgdiff

Deterministic visual-semantic SVG comparison with typed reports for programs and text-only agents.

svg
diff
visual-semantics
structured-report
agent
moon add Milky2018/svgdiff@0.7.1
Download zip
Author
Version
0.7.1
License
Apache-2.0
Last updated
5 days ago
Downloads
96
README

#svgdiff for MoonBit

Milky2018/svgdiff compares two deterministic static SVG source strings and returns a typed Structured Report for programs and agents that need visual-semantic differences without inspecting images directly.

#Install

moon add Milky2018/svgdiff@0.7.1

#Compare SVG sources

///|
test "compare SVG source strings through the public package" {
let before = "<svg width='16' height='16'><rect width='8' height='8' fill='red'/></svg>"
let after = "<svg width='16' height='16'><rect width='8' height='8' fill='blue'/></svg>"
let report = @svgdiff.compare(
before,
after,
@svgdiff.ComparisonProfile::v1_default(),
)
assert_eq(report.schema_version, "2.0")
assert_eq(report.analysis_status, "complete")
assert_true(report.atomic_differences.length() > 0)
assert_true(report.events.length() > 0)
}

The root package is the stable library interface. Native, WASIp1, and browser entrypoints live in sibling packages under cmd.

#
AlignmentEvidence

Reviewable selection evidence for one Subject Alignment.

confidence remains null while confidence_status is not_calibrated; deterministic selection does not imply a calibrated probability.

#
AtomicDifference

Smallest independently reportable visual-semantic change.

Domain, evidence layers, computed relation, magnitude, and ordering remain independent so representation and measured visual impact are not conflated.

#
CauseEnvelope

Conservative Changed Fact candidates for one Difference Region.

A sound_overapproximation contains every actual changed cause within complete analysis coverage, but may contain false positives.

#
ChangedFact

One changed supported authored fact and the subjects it may affect.

#
ComparisonControl

#
ComparisonProfile

Rendering and normalization conditions recorded for one comparison.

The root schema 2.0 API accepts caller-provided viewport dimensions, Perceptual Background, FLIP Viewing Conditions, and FLIP error threshold, and canonicalizes the remaining fields to v1_default.

#
ComputedRelation

Relationship between the supported before and after computed facts.

status is equivalent, different, indeterminate, or not_applicable; reason_code and Diagnostic references explain why.

#
DeclaredVisualFact

One supported authored visual declaration with exact source provenance.

#
Diagnostic

Structured coverage limitation or analysis failure.

#
DiagnosticSourceLocation

One source-qualified location establishing a Diagnostic.

#
DifferenceMagnitude

Domain-appropriate magnitude vector for one Atomic Difference.

Optional components that were not computed serialize as null rather than zero.

#
DifferenceRegion

Pixel-space and CSS-space localization of one visual outcome component.

#
DomainOrdering

Versioned lexicographic components for ordering differences in one domain.

#
FeatureCoverage

Coverage of one encountered feature at each canonical evidence layer.

Layer status is covered, limited, not_applicable, or failed. Diagnostics explain every limited or failed row.

#
FlipErrorThreshold

Explicit optional reporting threshold for LDR-FLIP error values.

#
FlipViewingConditions

Explicit LDR-FLIP viewing conditions with a bounded filter domain.

#
ImpactAssessment

Additive versioned main-event assessment that preserves partial ordering.

#
ImpactDominationWitness

One deterministic explanation for excluding a dominated event.

#
ImpactFrontierGroup

One singleton or exact measured-tie group on the main-event frontier.

#
ImpactMeasurement

Common whole-canvas event measurements used by one Impact Assessment.

#
IntrinsicRasterMagnitude

Intrinsic decoded-raster comparison, independent of final SVG compositing.

#
PaintedBoundaryDisplacementMagnitude

Symmetric nearest-boundary statistics from the pinned renderer's alpha support.

#
PaintedCoverageDifferenceMagnitude

Symmetric alpha-only isolated painted-coverage comparison.

#
PerceptualBackground

One explicit opaque sRGB8 background for future perceptual compositing.

#
PerceptualColorEvidence

Availability and optional event-local perceptual-color magnitude.

#
PerceptualColorMagnitude

Displayed-color magnitude for one selected rendered outcome after explicit background compositing.

#
PerceptualFlipAreaAboveThreshold

Explicit-threshold spatial extent for one event-local LDR-FLIP response.

#
PerceptualFlipEvidence

Availability and optional event-local LDR-FLIP map.

#
PerceptualFlipMap

Deterministic quantized LDR-FLIP map for one selected rendered outcome.

#
PerceptualFlipStatistics

Separate pooled domains over one unquantized LDR-FLIP map.

#
PresenceMagnitude

Numeric footprint of inserted or deleted visual subjects.

#
RenderedEvidence

Availability and optional magnitude of canonical rendered evidence.

A computed zero magnitude is distinct from not_computed.

#
RenderedMagnitude

Continuous canonical raster measurements for one rendered outcome.

#
RendererCapabilityGap

One renderer capability gap encountered by the current comparison.

support_status is guarded or unavailable. Diagnostic references remain the authority for affected subjects and evidence layers.

#
ReportSourceSpan

Half-open UTF-16 offsets into the original SVG source.

#
ResolvedVisualFact

One supported visual fact after declaration precedence and inheritance.

#
ResourceBundle

#
ResourceBundleEntry

#
SourceAuditDiagnostic

A bounded parse failure from one side of a source-only audit.

#
SourceAuditDifference

One changed, inserted, or deleted nonvisual source fact.

#
SourceAuditFact

One exact authored fact in the optional nonvisual source audit.

#
SourceAuditReport

An independently versioned source-only nonvisual metadata audit.

#
SourceResolutionPair

Before and after resolved facts for one subject property.

#
StructuredReport

Complete schema 2.0 result of one SVG comparison.

Read analysis_status and diagnostics before interpreting an empty atomic_differences array as profile-scoped equality.

#
SubjectAlignment

Set-to-set relationship between before and after visual subjects.

#
SubjectInstanceContext

Placement identity for a subject rendered through one or more use hosts.

The corresponding authored definition keeps its own identity and Source Spans; instance_id identifies only this rendered outcome.

#
SubjectReference

Report-local reference to one visual subject in an input SVG.

#
TransformEffectMagnitude

Tagged raw magnitude for one canonical transform-effect domain.

#
TransformResidualMagnitude

Exact singular linear transforms retained without a coefficient score.

#
TransformRotationMagnitude

Canonical paired rotation values and shortest signed angular change.

#
TransformScaleMagnitude

Canonical signed axis scales and their largest absolute paired delta.

#
TransformSkewMagnitude

Canonical paired X-skew values and shortest signed angular change.

#
TransformTranslationMagnitude

Viewport-space translation change and its Euclidean CSS-pixel magnitude.

#
VisualEvent

Agent-facing grouping of Atomic Differences around one subject outcome.

#
ComparisonInterrupted

pub(all) suberror ComparisonInterrupted {
Cancelled
CheckpointBudgetExceeded(max_checkpoints~ : Int)
} derive(Eq,
Debug
)

The controlled comparison stopped before a report was established.

#
audit_nonvisual_metadata

fn audit_nonvisual_metadata(before_svg : String, after_svg : String) ->
SourceAuditReport

Audit nonvisual metadata without adding it to visual Atomic Differences.

This independent source-only operation inventories exact authored content inside SVG title, desc, and metadata elements plus unprefixed aria-* and data-* attributes. It never changes comparison results.

#
compare

Compare two deterministic static SVG sources under one schema 2.0 profile.

The two SVG strings are analyzed under a shared viewport. The root API preserves profile.viewport_width, profile.viewport_height, the optional Perceptual Background, optional FLIP Viewing Conditions, and optional FLIP error threshold, and pins DPR, color interpretation, raster representation, renderer identity, and renderer conformance profile to the v1 defaults. Unsupported semantics produce Diagnostics and reduce analysis_status instead of being treated as equality.

Inspect analysis_status before using an empty atomic_differences array as a profile-scoped equality conclusion.

#
compare_with_control

Compare with cooperative cancellation and a deterministic checkpoint budget.

Interruption raises ComparisonInterrupted and returns no report. Checks occur at deterministic engine checkpoints; one dependency call cannot be preempted and may complete before the next checkpoint is observed.

#
compare_with_control_and_resources

Compare explicit resources with cooperative cancellation and checkpoint work.

#
compare_with_resources

Compare with separate explicit resource bundles for the two SVG sources.

Bundle locators are opaque exact-match keys. The engine performs no file or network I/O and resolves only caller-supplied PNG/JPEG bytes.

#
render_html_report

fn render_html_report(before_svg : String, after_svg : String, report :
StructuredReport
) -> String

Render a self-contained interactive HTML presentation of a report.

The original SVG sources are embedded as sandboxed preview documents. The supplied Structured Report remains the sole source of classification, ordering, magnitude, localization, and Diagnostics; this function does not run comparison again. Review marks and navigation are session-only UI state.

#
render_markdown_summary

fn render_markdown_summary(report :
StructuredReport
) -> String

Render a deterministic Markdown orientation summary from a report.

This is derived presentation only. The supplied Structured Report remains authoritative for every field, reference, magnitude, region, cause candidate, coverage result, and Diagnostic.

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io