@vyaz/core 0.0.6 → 0.0.7
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.
|
@@ -5,6 +5,9 @@
|
|
|
5
5
|
* inline-box: text → \uFFFC, dimensions in metadata.inlineWidget.
|
|
6
6
|
* super/sub: fontSize *= 0.65, baselineOffset in metadata.
|
|
7
7
|
*
|
|
8
|
+
* splitParagraphByHardBreaks() — zero phase: splits a Paragraph into
|
|
9
|
+
* virtual Paragraph[] on \n boundaries (for pre, pre-line, pre-wrap).
|
|
10
|
+
*
|
|
8
11
|
* Simple JSON-serialisable format — does not depend on pretext directly.
|
|
9
12
|
*/
|
|
10
13
|
import type { Paragraph, TextRun } from '../types/Document.js';
|
|
@@ -30,10 +33,50 @@ export interface PreparedRichInlineItem {
|
|
|
30
33
|
inlineWidget?: TextRun['inlineWidget'];
|
|
31
34
|
};
|
|
32
35
|
}
|
|
36
|
+
/**
|
|
37
|
+
* Collapse consecutive collapsible whitespace → single space.
|
|
38
|
+
* Trim leading/trailing. CSS Text §4.1.1.
|
|
39
|
+
*
|
|
40
|
+
* Uses native regex (C++ in V8) instead of a manual JS loop.
|
|
41
|
+
*/
|
|
42
|
+
export declare function collapseSegmentWhitespace(segment: string): string;
|
|
43
|
+
/**
|
|
44
|
+
* Split text on \n, collapse whitespace per segment (pre-line).
|
|
45
|
+
* Empty segments preserved (for \n\n → empty line).
|
|
46
|
+
*
|
|
47
|
+
* Three native calls: replace → split → map (trim).
|
|
48
|
+
* CSS Text §4.1.1 (pre-line): collapsing + segment break transformation.
|
|
49
|
+
*/
|
|
50
|
+
export declare function splitAndCollapseByHardBreaks(text: string): string[];
|
|
33
51
|
/**
|
|
34
52
|
* Compile a paragraph into PreparedRichInlineItem[].
|
|
35
53
|
*/
|
|
36
54
|
export declare function compileParagraph(paragraph: Paragraph): PreparedRichInlineItem[];
|
|
55
|
+
/**
|
|
56
|
+
* Zero phase: split a Paragraph into virtual Paragraph[] on \n boundaries.
|
|
57
|
+
*
|
|
58
|
+
* For `pre-line`: whitespace is collapsed per segment.
|
|
59
|
+
* For `pre`/`pre-wrap`: whitespace is preserved.
|
|
60
|
+
* For `normal`/`nowrap`/`undefined`: returns [paragraph] unchanged.
|
|
61
|
+
*
|
|
62
|
+
* Each \n produces an empty Paragraph (children: []) which the layout engine
|
|
63
|
+
* can fast-path as a hard-break line.
|
|
64
|
+
*
|
|
65
|
+
* Supports multi-run: when a run contains \n, the text after \n starts
|
|
66
|
+
* a new virtual paragraph. Runs after the split run belong to the new
|
|
67
|
+
* paragraph.
|
|
68
|
+
*
|
|
69
|
+
* @example
|
|
70
|
+
* "Hello\nWorld" (pre-line)
|
|
71
|
+
* → [{ children: [{ text: "Hello" }] }, { children: [{ text: "World" }] }]
|
|
72
|
+
*
|
|
73
|
+
* "Hello\n\nWorld" (pre-line)
|
|
74
|
+
* → [{ children: [{ text: "Hello" }] }, { children: [] }, { children: [{ text: "World" }] }]
|
|
75
|
+
*
|
|
76
|
+
* ["Hello Bold", "\n", "World"] (pre)
|
|
77
|
+
* → [{ children: [{ text: "Hello Bold" }] }, { children: [] }, { children: [{ text: "World" }] }]
|
|
78
|
+
*/
|
|
79
|
+
export declare function splitParagraphByHardBreaks(paragraph: Paragraph): Paragraph[];
|
|
37
80
|
/**
|
|
38
81
|
* Get the full text of a paragraph (for INDEX_CONSIST checks).
|
|
39
82
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -20,7 +20,7 @@ export { groupLinesByParagraph } from './utils/groupLinesByParagraph.js';
|
|
|
20
20
|
export type { ParagraphGroup } from './utils/groupLinesByParagraph.js';
|
|
21
21
|
export { transformText } from './utils/textTransform.js';
|
|
22
22
|
export { formatListNumber, defaultBulletChar, BULLET_CHARACTERS } from './utils/list.js';
|
|
23
|
-
export { compileParagraph, getParagraphText, makeFontToken } from './compile/DocumentCompiler.js';
|
|
23
|
+
export { compileParagraph, getParagraphText, makeFontToken, splitParagraphByHardBreaks, collapseSegmentWhitespace } from './compile/DocumentCompiler.js';
|
|
24
24
|
export type { PreparedRichInlineItem } from './compile/DocumentCompiler.js';
|
|
25
25
|
export type { FontFace } from './measure/FontEngine.js';
|
|
26
26
|
export { createFontFace, getGlyphAdvance, computePixelMetrics, isFontEngineAvailable } from './measure/FontEngine.js';
|
package/dist/index.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
export {
|
|
3
3
|
transformText,
|
|
4
4
|
systemFontRegistry,
|
|
5
|
+
splitParagraphByHardBreaks,
|
|
5
6
|
positionLines,
|
|
6
7
|
paragraphLayoutEngine,
|
|
7
8
|
makeFontToken,
|
|
@@ -19,6 +20,7 @@ export {
|
|
|
19
20
|
createFontFace,
|
|
20
21
|
computePixelMetrics,
|
|
21
22
|
compileParagraph,
|
|
23
|
+
collapseSegmentWhitespace,
|
|
22
24
|
assertLineInvariants,
|
|
23
25
|
applyScale,
|
|
24
26
|
SystemFontRegistry,
|
package/dist/types/Document.d.ts
CHANGED
|
@@ -121,10 +121,15 @@ export type ScriptType = 'normal' | 'sub' | 'super';
|
|
|
121
121
|
* CSS `white-space` equivalent.
|
|
122
122
|
*
|
|
123
123
|
* Controls how whitespace and line breaks are handled inside a paragraph.
|
|
124
|
+
* - `'normal'`: collapse whitespace, auto-wrap.
|
|
125
|
+
* - `'nowrap'`: collapse whitespace, no wrap.
|
|
126
|
+
* - `'pre'`: preserve whitespace, wrap on newline only.
|
|
127
|
+
* - `'pre-line'`: collapse whitespace, wrap on newline and auto-wrap.
|
|
128
|
+
* - `'pre-wrap'`: preserve whitespace, wrap on newline and auto-wrap.
|
|
124
129
|
*
|
|
125
130
|
* @see {@link https://www.w3.org/TR/css-text-3/#white-space-property | CSS Text: white-space}
|
|
126
131
|
*/
|
|
127
|
-
export type WhiteSpace = 'normal' | 'nowrap' | 'pre';
|
|
132
|
+
export type WhiteSpace = 'normal' | 'nowrap' | 'pre' | 'pre-line' | 'pre-wrap';
|
|
128
133
|
/**
|
|
129
134
|
* Type of list marker.
|
|
130
135
|
*
|
|
@@ -409,6 +414,7 @@ export interface ParagraphStyle {
|
|
|
409
414
|
* - `'normal'`: collapse whitespace, auto-wrap.
|
|
410
415
|
* - `'nowrap'`: collapse whitespace, no wrap.
|
|
411
416
|
* - `'pre'`: preserve whitespace, wrap on newline only.
|
|
417
|
+
* - `'pre-line'`: collapse whitespace, wrap on newline and auto-wrap.
|
|
412
418
|
*/
|
|
413
419
|
whiteSpace?: WhiteSpace;
|
|
414
420
|
/**
|
|
@@ -94,6 +94,15 @@ export interface Line {
|
|
|
94
94
|
alignment?: TextAlignment;
|
|
95
95
|
/** Column index (0-based) when frame has multi-column layout. */
|
|
96
96
|
columnIndex?: number;
|
|
97
|
+
/**
|
|
98
|
+
* True when this line was created by a forced hard break (\n),
|
|
99
|
+
* as opposed to a soft wrap from line width exceeding maxWidth.
|
|
100
|
+
*
|
|
101
|
+
* Used by the editor to distinguish user-inserted line breaks
|
|
102
|
+
* from automatic wrapping (affects Home/End, arrow up/down,
|
|
103
|
+
* Backspace merging behaviour).
|
|
104
|
+
*/
|
|
105
|
+
isHardBreak?: boolean;
|
|
97
106
|
spans: Span[];
|
|
98
107
|
}
|
|
99
108
|
export interface ParagraphLayoutResult {
|