@vyaz/core 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +25 -0
- package/src/compile/DocumentCompiler.ts +94 -0
- package/src/index.ts +76 -0
- package/src/layout/AutoFitEngine.ts +101 -0
- package/src/layout/LineBoxValidator.ts +161 -0
- package/src/layout/ParagraphLayoutEngine.ts +202 -0
- package/src/layout/PositioningEngine.ts +391 -0
- package/src/layout/TextFrameLayoutEngine.ts +86 -0
- package/src/measure/FontMetricsProvider.ts +190 -0
- package/src/measure/canvas-polyfill.d.ts +6 -0
- package/src/measure/canvas-polyfill.ts +186 -0
- package/src/measure/fontkit.d.ts +44 -0
- package/src/types/Document.ts +540 -0
- package/src/types/FontTypes.ts +71 -0
- package/src/types/LayoutTypes.ts +136 -0
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* LayoutTypes.ts — output types (Physical Box Model).
|
|
3
|
+
*
|
|
4
|
+
* ParagraphLayoutResult → LineBox[] → FragmentBox[]
|
|
5
|
+
* This is the contract between layout engine and renderers.
|
|
6
|
+
*
|
|
7
|
+
* Based on plan.md §2.5 (Output — Physical Box Model / Layout Tree)
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { TextRun, InlineWidget, TextAlignment } from './Document.js';
|
|
11
|
+
|
|
12
|
+
// ── FragmentBox (render atom) ─────────────────────────────────────────────
|
|
13
|
+
|
|
14
|
+
export interface FragmentBox {
|
|
15
|
+
/** Offset from LineBox.x */
|
|
16
|
+
x: number;
|
|
17
|
+
/** Physical fragment width */
|
|
18
|
+
width: number;
|
|
19
|
+
/** Fragment text (or " " for justify spaces) */
|
|
20
|
+
text: string;
|
|
21
|
+
/** Index of the source run in the paragraph's `children` array. */
|
|
22
|
+
itemIndex: number;
|
|
23
|
+
/** ID of the source paragraph (for SVG grouping). */
|
|
24
|
+
paragraphId?: string;
|
|
25
|
+
|
|
26
|
+
/** Physical font metrics for this fragment */
|
|
27
|
+
fontMetrics: FragmentFontMetrics;
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* A snapshot of the source run's style at layout time.
|
|
31
|
+
* Copied from the corresponding `TextRun` in the paragraph's `children` array.
|
|
32
|
+
*/
|
|
33
|
+
style: TextRun;
|
|
34
|
+
|
|
35
|
+
/** InlineWidget data (if fragment is an inline-box) */
|
|
36
|
+
inlineWidget?: InlineWidget;
|
|
37
|
+
|
|
38
|
+
/** Per-character advance widths (for selection/tracking) */
|
|
39
|
+
glyphAdvances?: number[];
|
|
40
|
+
|
|
41
|
+
/** Fragment type: 'text' — regular text, 'space' — whitespace fragment */
|
|
42
|
+
type: 'text' | 'space';
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Trailing whitespace flag.
|
|
46
|
+
* - true: fragment is at end of line, does not participate in line advance
|
|
47
|
+
* and is not stretched during justify (zero width for calculations).
|
|
48
|
+
* - undefined/false: regular fragment.
|
|
49
|
+
*
|
|
50
|
+
* See CSS Text Module Level 3 §4.1.3 (Tracking and Dropping Spaces)
|
|
51
|
+
* and Parley LineItemData::has_trailing_whitespace.
|
|
52
|
+
*/
|
|
53
|
+
trailing?: boolean;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* Line break mode after this fragment.
|
|
57
|
+
* 'soft' — soft line break (insufficient space)
|
|
58
|
+
* 'hard' — forced break (\n, explicit separator)
|
|
59
|
+
* undefined — not end of line
|
|
60
|
+
*/
|
|
61
|
+
breakType?: 'soft' | 'hard';
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
export interface FragmentFontMetrics {
|
|
65
|
+
ascent: number;
|
|
66
|
+
descent: number;
|
|
67
|
+
fontSize: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
// ── LineBox (single line) ────────────────────────────────────────────────
|
|
71
|
+
|
|
72
|
+
export interface LineBox {
|
|
73
|
+
/** Absolute X within container (alignment + indent) */
|
|
74
|
+
x: number;
|
|
75
|
+
/** Absolute Y of line top edge */
|
|
76
|
+
y: number;
|
|
77
|
+
/** Line content width (without alignment) */
|
|
78
|
+
width: number;
|
|
79
|
+
/** Full line height (max fragments × lineHeight) */
|
|
80
|
+
height: number;
|
|
81
|
+
|
|
82
|
+
/** Baseline offset from y */
|
|
83
|
+
baseline: number;
|
|
84
|
+
/** Maximum ascent in line */
|
|
85
|
+
ascent: number;
|
|
86
|
+
/** Maximum descent in line */
|
|
87
|
+
descent: number;
|
|
88
|
+
|
|
89
|
+
/** Index of first character in the original paragraph text */
|
|
90
|
+
startIndex: number;
|
|
91
|
+
/** Index of last character + 1 (for convenient length calculation) */
|
|
92
|
+
endIndex: number;
|
|
93
|
+
|
|
94
|
+
/** Paragraph alignment (optional, for PowerPoint render) */
|
|
95
|
+
alignment?: TextAlignment;
|
|
96
|
+
|
|
97
|
+
fragments: FragmentBox[];
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// ── ParagraphLayoutResult (single paragraph) ─────────────────────────────
|
|
101
|
+
|
|
102
|
+
export interface ParagraphLayoutResult {
|
|
103
|
+
width: number; // paragraph width (maxWidth)
|
|
104
|
+
height: number; // full paragraph height including spacing
|
|
105
|
+
lines: LineBox[];
|
|
106
|
+
/** Actual content width (text bbox, without voids) */
|
|
107
|
+
contentWidth: number;
|
|
108
|
+
/** Actual content height (text bbox) */
|
|
109
|
+
contentHeight: number;
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// ── Text region for YAML snapshots ───────────────────────────────────────
|
|
113
|
+
|
|
114
|
+
/** Semantic fragment for snapshots (without physical metrics) */
|
|
115
|
+
export interface SemanticFragment {
|
|
116
|
+
text: string;
|
|
117
|
+
x: number;
|
|
118
|
+
width: number;
|
|
119
|
+
style?: 'bold' | 'italic' | 'normal';
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
/** Semantic line for snapshots */
|
|
123
|
+
export interface SemanticLine {
|
|
124
|
+
y: number;
|
|
125
|
+
width: number;
|
|
126
|
+
height: number;
|
|
127
|
+
baseline: number;
|
|
128
|
+
fragments: SemanticFragment[];
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/** Semantic paragraph for YAML snapshots */
|
|
132
|
+
export interface SemanticParagraph {
|
|
133
|
+
width: number;
|
|
134
|
+
height: number;
|
|
135
|
+
lines: SemanticLine[];
|
|
136
|
+
}
|