@vyaz/core 0.0.5 → 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.
Files changed (45) hide show
  1. package/dist/compile/DocumentCompiler.d.ts +83 -0
  2. package/dist/index.browser.d.ts +28 -0
  3. package/dist/index.browser.js +18 -0
  4. package/dist/index.d.ts +30 -0
  5. package/dist/index.js +13 -147930
  6. package/dist/layout/AutoFitEngine.d.ts +44 -0
  7. package/dist/layout/LineBoxValidator.d.ts +25 -0
  8. package/dist/layout/ParagraphLayoutEngine.d.ts +46 -0
  9. package/dist/layout/PositioningEngine.d.ts +68 -0
  10. package/dist/layout/TextFrameLayoutEngine.d.ts +50 -0
  11. package/{src/layout/estimateWidth.ts → dist/layout/estimateWidth.d.ts} +2 -40
  12. package/dist/measure/FontEngine.d.ts +47 -0
  13. package/dist/measure/FontMetricsProvider.d.ts +49 -0
  14. package/dist/measure/FontNotFoundError.d.ts +6 -0
  15. package/dist/measure/SystemFontRegistry.d.ts +46 -0
  16. package/dist/measure/canvas-polyfill.d.ts +30 -0
  17. package/dist/types/Document.d.ts +599 -0
  18. package/dist/types/FontTypes.d.ts +61 -0
  19. package/dist/types/LayoutTypes.d.ts +137 -0
  20. package/{src/utils/env.ts → dist/utils/env.d.ts} +1 -8
  21. package/{src/utils/font.ts → dist/utils/font.d.ts} +1 -13
  22. package/{src/utils/groupLinesByParagraph.ts → dist/utils/groupLinesByParagraph.d.ts} +7 -37
  23. package/dist/utils/list.d.ts +41 -0
  24. package/dist/utils/textTransform.d.ts +32 -0
  25. package/package.json +13 -13
  26. package/src/compile/DocumentCompiler.ts +0 -144
  27. package/src/index.browser.ts +0 -90
  28. package/src/index.ts +0 -97
  29. package/src/layout/AutoFitEngine.ts +0 -101
  30. package/src/layout/LineBoxValidator.ts +0 -162
  31. package/src/layout/ParagraphLayoutEngine.ts +0 -264
  32. package/src/layout/PositioningEngine.ts +0 -615
  33. package/src/layout/TextFrameLayoutEngine.ts +0 -363
  34. package/src/measure/FontEngine.ts +0 -144
  35. package/src/measure/FontMetricsProvider.ts +0 -224
  36. package/src/measure/FontNotFoundError.ts +0 -16
  37. package/src/measure/SystemFontRegistry.ts +0 -152
  38. package/src/measure/canvas-polyfill.d.ts +0 -6
  39. package/src/measure/canvas-polyfill.ts +0 -243
  40. package/src/measure/fontkit.d.ts +0 -44
  41. package/src/types/Document.ts +0 -666
  42. package/src/types/FontTypes.ts +0 -74
  43. package/src/types/LayoutTypes.ts +0 -158
  44. package/src/utils/list.ts +0 -107
  45. package/src/utils/textTransform.ts +0 -96
@@ -0,0 +1,83 @@
1
+ /**
2
+ * DocumentCompiler.ts — compile Paragraph → PreparedRichInlineItem[].
3
+ *
4
+ * Each TextRun becomes a RichInlineItem for pretext.
5
+ * inline-box: text → \uFFFC, dimensions in metadata.inlineWidget.
6
+ * super/sub: fontSize *= 0.65, baselineOffset in metadata.
7
+ *
8
+ * splitParagraphByHardBreaks() — zero phase: splits a Paragraph into
9
+ * virtual Paragraph[] on \n boundaries (for pre, pre-line, pre-wrap).
10
+ *
11
+ * Simple JSON-serialisable format — does not depend on pretext directly.
12
+ */
13
+ import type { Paragraph, TextRun } from '../types/Document.js';
14
+ export declare const FONT_WEIGHTS: Record<string, number>;
15
+ /** Normalize fontWeight to a numeric value (400 by default). */
16
+ export declare function normalizeFontWeight(weight: number | string | undefined): number;
17
+ /** Font token for pretext: "${style}_${weight}_${fontSize}_${family}" */
18
+ export declare function makeFontToken(run: TextRun, effectiveFontSize: number): string;
19
+ /** Compilation context (passed to pretext) */
20
+ export interface PreparedRichInlineItem {
21
+ text: string;
22
+ font: string;
23
+ letterSpacing?: number;
24
+ extraWidth?: number;
25
+ break?: 'normal' | 'never';
26
+ /** Original text before text-transform (if transform was applied). Used for copy-paste / round-trip. */
27
+ originalText?: string;
28
+ metadata: {
29
+ originalRunIndex: number;
30
+ baselineOffset: number;
31
+ effectiveFontSize: number;
32
+ style: TextRun;
33
+ inlineWidget?: TextRun['inlineWidget'];
34
+ };
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[];
51
+ /**
52
+ * Compile a paragraph into PreparedRichInlineItem[].
53
+ */
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[];
80
+ /**
81
+ * Get the full text of a paragraph (for INDEX_CONSIST checks).
82
+ */
83
+ export declare function getParagraphText(paragraph: Paragraph): string;
@@ -0,0 +1,28 @@
1
+ /**
2
+ * @vyaz/core — Browser entry point.
3
+ *
4
+ * Re-exports everything from the main index **except** `SystemFontRegistry`
5
+ * and `systemFontRegistry`, which require Node.js built-in modules
6
+ * (`node:fs`, `get-system-fonts`).
7
+ *
8
+ * All server-only code paths are guarded by runtime checks (`isNodeLike`)
9
+ * so tree-shakers can safely eliminate dead branches.
10
+ *
11
+ * ✅ Safe for Vite / webpack / Rollup / esbuild browser builds.
12
+ */
13
+ export type { TextFrame, Paragraph, ParagraphStyle, TextRun, InlineWidget, AutofitConfig, TextAlignment, WritingMode, TextOrientation, VerticalAlignment, ScriptType, WhiteSpace, MultiColumnConfig, DominantBaseline, LineFitEdge, TextAlignLast, WordBreak, LineBreak, OverflowWrap, TextDecorationStyle, TextTransform, ListType, NumberFormat, ListStylePosition, ListStyle, } from './types/Document.js';
14
+ export { DEFAULT_PARAGRAPH_STYLE, DEFAULT_TEXT_STYLE, } from './types/Document.js';
15
+ export type { ParagraphLayoutResult, Line, Span, SpanFontMetrics, SemanticParagraph, SemanticLine, SemanticFragment, } from './types/LayoutTypes.js';
16
+ export type { FontMetrics, IFontMetricsProvider, GlyphData, } from './types/FontTypes.js';
17
+ export { ParagraphLayoutEngine, paragraphLayoutEngine } from './layout/ParagraphLayoutEngine.js';
18
+ export { positionLines } from './layout/PositioningEngine.js';
19
+ export { assertLineInvariants, linesToYAML } from './layout/LineBoxValidator.js';
20
+ export type { InvariantError } from './layout/LineBoxValidator.js';
21
+ export { layoutTextFrame } from './layout/TextFrameLayoutEngine.js';
22
+ export type { TextFrameLayoutResult } from './layout/TextFrameLayoutEngine.js';
23
+ export { applyScale, findScale } from './layout/AutoFitEngine.js';
24
+ export type { AutoFitOptions, AutoFitResult } from './layout/AutoFitEngine.js';
25
+ export { compileParagraph, getParagraphText, makeFontToken } from './compile/DocumentCompiler.js';
26
+ export type { PreparedRichInlineItem } from './compile/DocumentCompiler.js';
27
+ export { FontMetricsProvider, fontMetricsProvider } from './measure/FontMetricsProvider.js';
28
+ export { FontNotFoundError } from './measure/FontNotFoundError.js';
@@ -0,0 +1,18 @@
1
+ export {
2
+ positionLines,
3
+ paragraphLayoutEngine,
4
+ makeFontToken,
5
+ linesToYAML,
6
+ layoutTextFrame,
7
+ getParagraphText,
8
+ fontMetricsProvider,
9
+ findScale,
10
+ compileParagraph,
11
+ assertLineInvariants,
12
+ applyScale,
13
+ ParagraphLayoutEngine,
14
+ FontNotFoundError,
15
+ FontMetricsProvider,
16
+ DEFAULT_TEXT_STYLE,
17
+ DEFAULT_PARAGRAPH_STYLE
18
+ };
@@ -0,0 +1,30 @@
1
+ /**
2
+ * @vyaz/core — Public API.
3
+ *
4
+ * Exports input types (Logical level), output types (Physical Box Model),
5
+ * layout engines, font metric providers, renderers, and utilities.
6
+ */
7
+ export type { TextFrame, Paragraph, ParagraphStyle, TextRun, InlineWidget, AutofitConfig, TextAlignment, WritingMode, TextOrientation, VerticalAlignment, ScriptType, WhiteSpace, MultiColumnConfig, DominantBaseline, LineFitEdge, TextAlignLast, WordBreak, LineBreak, OverflowWrap, TextDecorationStyle, TextTransform, ListType, NumberFormat, ListStylePosition, ListStyle, } from './types/Document.js';
8
+ export { DEFAULT_PARAGRAPH_STYLE, DEFAULT_TEXT_STYLE, } from './types/Document.js';
9
+ export type { ParagraphLayoutResult, Line, Span, SpanFontMetrics, SemanticParagraph, SemanticLine, SemanticFragment, } from './types/LayoutTypes.js';
10
+ export type { FontMetrics, IFontMetricsProvider, GlyphData, } from './types/FontTypes.js';
11
+ export { ParagraphLayoutEngine, paragraphLayoutEngine } from './layout/ParagraphLayoutEngine.js';
12
+ export { positionLines } from './layout/PositioningEngine.js';
13
+ export { assertLineInvariants, linesToYAML } from './layout/LineBoxValidator.js';
14
+ export type { InvariantError } from './layout/LineBoxValidator.js';
15
+ export { layoutTextFrame } from './layout/TextFrameLayoutEngine.js';
16
+ export type { TextFrameLayoutResult } from './layout/TextFrameLayoutEngine.js';
17
+ export { applyScale, findScale } from './layout/AutoFitEngine.js';
18
+ export type { AutoFitOptions, AutoFitResult } from './layout/AutoFitEngine.js';
19
+ export { groupLinesByParagraph } from './utils/groupLinesByParagraph.js';
20
+ export type { ParagraphGroup } from './utils/groupLinesByParagraph.js';
21
+ export { transformText } from './utils/textTransform.js';
22
+ export { formatListNumber, defaultBulletChar, BULLET_CHARACTERS } from './utils/list.js';
23
+ export { compileParagraph, getParagraphText, makeFontToken, splitParagraphByHardBreaks, collapseSegmentWhitespace } from './compile/DocumentCompiler.js';
24
+ export type { PreparedRichInlineItem } from './compile/DocumentCompiler.js';
25
+ export type { FontFace } from './measure/FontEngine.js';
26
+ export { createFontFace, getGlyphAdvance, computePixelMetrics, isFontEngineAvailable } from './measure/FontEngine.js';
27
+ export { FontMetricsProvider, fontMetricsProvider } from './measure/FontMetricsProvider.js';
28
+ export { SystemFontRegistry, systemFontRegistry } from './measure/SystemFontRegistry.js';
29
+ export { getFontBuffer } from './utils/font.js';
30
+ export { FontNotFoundError } from './measure/FontNotFoundError.js';