Add measurement-validator module: Pretext vs DOM divergence detection#1
Draft
Add measurement-validator module: Pretext vs DOM divergence detection#1
Conversation
…, and test suite Agent-Logs-Url: https://github.com/Himaan1998Y/pretext/sessions/7bfad683-e3dc-4ab7-8671-45485362c873 Co-authored-by: Himaan1998Y <210527591+Himaan1998Y@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add measurement validator for Pretext canvas comparisons
Add measurement-validator module: Pretext vs DOM divergence detection
Apr 4, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Pretext users have no standard way to verify that canvas-based measurements match actual browser DOM rendering — silent divergences (font fallback, bidi shaping, emoji inflation, etc.) propagate silently into layout.
Adds
src/measurement-validator.tsexported as./measurement-validator, with four components:MeasurementComparator— compareslayoutWithLines()output against live DOM geometry;pretextOnly: truemode stubs DOM reads for Node/test environmentsDivergenceClassifier— infers root cause from text content and per-line delta data:bidi,emoji,pre-wrap,variable-font,font-fallback,unknownTestSuiteRunner— runs aMeasurementSample[]corpus, aggregates intoSuiteReport;failOnthreshold +runOrThrow()for CI gatingReportGenerator— rendersSuiteReportastext|json|htmlSeverity buckets:
exact(0 px) →minor(<0.5 px) →major(<2 px) →critical(≥2 px or line-count mismatch).Original prompt
Measurement Validator PRD: Professional In-Depth Planning
CONTEXT & VALIDATION
This document is the result of 5+ hours of research across:
PROBLEM STATEMENT
Current State
Pretext is a high-performance text measurement library used by 9+ shipping products to avoid DOM layout reflow. However, there is no standard way to validate that Pretext's canvas-based measurements match actual browser DOM rendering.
Real-world impact:
liyown/marknative(Markdown → PNG/SVG) silently produces wrong output if fonts fail to loadxiaoiver/infinite-canvas(WebGL whiteboard) renders text at wrong positions if measurements divergefastrepl/char(code editor) can't guarantee layout accuracyzuoban/zb-reader(EPUB reader) experiences layout shift on different fontsRoot Cause
Issue chenglou#77 reveals the core problem:
Current workaround: Hope the measurements are correct. Use DOM as fallback if broken.
Why This Matters
SCOPE & OBJECTIVES
PRIMARY GOAL
Build a Measurement Validator that:
SECONDARY GOALS
@pretext/measurement-validator)OUT OF SCOPE
TECHNICAL ARCHITECTURE
Component 1: Measurement Comparator
Purpose: Compare Pretext vs. DOM for a single text sample
Input:
Output:
Algorithm:
Component 2: Test Suite Runner
Purpose: Run validator against corpus of test cases
Input:
Output:
Test Coverage: