@vyaz/core 0.0.16 → 0.1.0

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 (44) hide show
  1. package/bin/vyaz.js +27 -0
  2. package/dist/cli/check.d.ts +12 -0
  3. package/dist/cli/check.d.ts.map +1 -0
  4. package/dist/cli/check.js +4077 -0
  5. package/dist/compile/ParagraphCompiler.d.ts +84 -0
  6. package/dist/compile/ParagraphCompiler.d.ts.map +1 -0
  7. package/dist/debug/lines-to-yaml.d.ts +14 -0
  8. package/dist/debug/lines-to-yaml.d.ts.map +1 -0
  9. package/dist/debug.d.ts +11 -0
  10. package/dist/debug.d.ts.map +1 -0
  11. package/dist/debug.js +4 -0
  12. package/dist/index.browser.d.ts +9 -4
  13. package/dist/index.browser.d.ts.map +1 -1
  14. package/dist/index.browser.js +3197 -5031
  15. package/dist/index.d.ts +12 -11
  16. package/dist/index.d.ts.map +1 -1
  17. package/dist/index.js +4709 -796
  18. package/dist/layout/AutoFitEngine.d.ts.map +1 -1
  19. package/dist/layout/LineBoxValidator.d.ts +5 -10
  20. package/dist/layout/LineBoxValidator.d.ts.map +1 -1
  21. package/dist/layout/ParagraphLayoutEngine.d.ts +13 -8
  22. package/dist/layout/ParagraphLayoutEngine.d.ts.map +1 -1
  23. package/dist/layout/PositioningEngine.d.ts +1 -1
  24. package/dist/layout/PositioningEngine.d.ts.map +1 -1
  25. package/dist/layout/TextFrameLayoutEngine.d.ts +84 -15
  26. package/dist/layout/TextFrameLayoutEngine.d.ts.map +1 -1
  27. package/dist/layout/create-engine.d.ts +32 -0
  28. package/dist/layout/create-engine.d.ts.map +1 -0
  29. package/dist/layout/resolve-font.d.ts +25 -0
  30. package/dist/layout/resolve-font.d.ts.map +1 -0
  31. package/dist/measure/FontEngine.d.ts +44 -1
  32. package/dist/measure/FontEngine.d.ts.map +1 -1
  33. package/dist/measure/FontMetricsProvider.d.ts +3 -10
  34. package/dist/measure/FontMetricsProvider.d.ts.map +1 -1
  35. package/dist/measure/FontkitMeasureContext.d.ts +109 -0
  36. package/dist/measure/FontkitMeasureContext.d.ts.map +1 -0
  37. package/dist/measure/canvas-polyfill.d.ts.map +1 -1
  38. package/dist/types/Document.d.ts +36 -23
  39. package/dist/types/Document.d.ts.map +1 -1
  40. package/dist/types/FontTypes.d.ts +1 -1
  41. package/dist/types/FontTypes.d.ts.map +1 -1
  42. package/dist/types/LayoutTypes.d.ts +19 -2
  43. package/dist/types/LayoutTypes.d.ts.map +1 -1
  44. package/package.json +16 -4
@@ -0,0 +1,84 @@
1
+ /**
2
+ * ParagraphCompiler.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, ResolvedTextRun } 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: ResolvedTextRun;
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;
84
+ //# sourceMappingURL=ParagraphCompiler.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ParagraphCompiler.d.ts","sourceRoot":"","sources":["../../src/compile/ParagraphCompiler.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,eAAe,EAAiB,MAAM,sBAAsB,CAAC;AAM/F,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAe/C,CAAC;AAEF,gEAAgE;AAChE,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,MAAM,CAI/E;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,GAAG,EAAE,OAAO,EAAE,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAK7E;AAED,8CAA8C;AAC9C,MAAM,WAAW,sBAAsB;IACrC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,KAAK,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAC;IAC3B,wGAAwG;IACxG,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,EAAE;QACR,gBAAgB,EAAE,MAAM,CAAC;QACzB,cAAc,EAAE,MAAM,CAAC;QACvB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,KAAK,EAAE,eAAe,CAAC;QACvB,YAAY,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAC;KACxC,CAAC;CACH;AAcD;;;;;GAKG;AACH,wBAAgB,yBAAyB,CAAC,OAAO,EAAE,MAAM,GAAG,MAAM,CAIjE;AAED;;;;;;GAMG;AACH,wBAAgB,4BAA4B,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,EAAE,CAMnE;AAID;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,sBAAsB,EAAE,CA2E/E;AAED;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,0BAA0B,CAAC,SAAS,EAAE,SAAS,GAAG,SAAS,EAAE,CAoD5E;AAOD;;GAEG;AACH,wBAAgB,gBAAgB,CAAC,SAAS,EAAE,SAAS,GAAG,MAAM,CAE7D"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * lines-to-yaml.ts — semantic YAML serialization of laid-out lines.
3
+ *
4
+ * Debug/snapshot tooling only. Reached through the `@vyaz/core/debug` entry so
5
+ * that `js-yaml` never lands in the production `@vyaz/core` bundle.
6
+ */
7
+ import type { Line } from '../types/LayoutTypes.js';
8
+ /**
9
+ * Convert Line[] to YAML string for snapshots.
10
+ * Only semantic data: text, x, width, style.
11
+ * No glyphAdvances, fontMetrics (noise), inlineWidget.
12
+ */
13
+ export declare function linesToYAML(lines: Line[], paragraphWidth: number, paragraphHeight: number): string;
14
+ //# sourceMappingURL=lines-to-yaml.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lines-to-yaml.d.ts","sourceRoot":"","sources":["../../src/debug/lines-to-yaml.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,IAAI,EAA2B,MAAM,yBAAyB,CAAC;AAU7E;;;;GAIG;AACH,wBAAgB,WAAW,CACzB,KAAK,EAAE,IAAI,EAAE,EACb,cAAc,EAAE,MAAM,EACtB,eAAe,EAAE,MAAM,GACtB,MAAM,CAwBR"}
@@ -0,0 +1,11 @@
1
+ /**
2
+ * @vyaz/core/debug — debugging & snapshot tooling.
3
+ *
4
+ * Kept out of the main entry so production consumers never pull `js-yaml`
5
+ * or the invariant-checking code into their bundle.
6
+ */
7
+ export { assertLineInvariants } from './layout/LineBoxValidator.js';
8
+ export type { InvariantError } from './layout/LineBoxValidator.js';
9
+ export { linesToYAML } from './debug/lines-to-yaml.js';
10
+ export type { SemanticParagraph, SemanticLine, SemanticFragment, } from './types/LayoutTypes.js';
11
+ //# sourceMappingURL=debug.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debug.d.ts","sourceRoot":"","sources":["../src/debug.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,YAAY,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAGnE,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,YAAY,EACV,iBAAiB,EACjB,YAAY,EACZ,gBAAgB,GACjB,MAAM,wBAAwB,CAAC"}
package/dist/debug.js ADDED
@@ -0,0 +1,4 @@
1
+ export {
2
+ linesToYAML,
3
+ assertLineInvariants
4
+ };
@@ -15,14 +15,19 @@
15
15
  export { ParagraphLayoutEngine, paragraphLayoutEngine } from './layout/ParagraphLayoutEngine.js';
16
16
  /** @internal */
17
17
  export { positionLines } from './layout/PositioningEngine.js';
18
- /** @internal */
19
- export { assertLineInvariants, linesToYAML } from './layout/LineBoxValidator.js';
20
18
  export { groupLinesByParagraph } from './utils/groupLinesByParagraph.js';
21
19
  export { layoutTextFrame } from './layout/TextFrameLayoutEngine.js';
20
+ export { createLayoutEngine } from './layout/create-engine.js';
21
+ export type { LayoutEngine, LayoutEngineOptions } from './layout/create-engine.js';
22
+ export type { LayoutOptions, TextFrameLayoutResult, AutofitOutcome } from './layout/TextFrameLayoutEngine.js';
23
+ export type { OnMissingFont } from './layout/resolve-font.js';
22
24
  export { applyScale, findScale } from './layout/AutoFitEngine.js';
23
- export { compileParagraph, getParagraphText, makeFontToken, collapseSegmentWhitespace, splitParagraphByHardBreaks } from './compile/DocumentCompiler.js';
25
+ export { compileParagraph, getParagraphText, makeFontToken, collapseSegmentWhitespace, splitParagraphByHardBreaks } from './compile/ParagraphCompiler.js';
24
26
  export { FontMetricsProvider, fontMetricsProvider } from './measure/FontMetricsProvider.js';
25
- export { createFontFace, getGlyphAdvance, computePixelMetrics, isFontEngineAvailable } from './measure/FontEngine.js';
27
+ export { createFontFace, getGlyphAdvance, computePixelMetrics, isFontEngineAvailable, shapeRun } from './measure/FontEngine.js';
28
+ export type { ShapedRun, ShapedGlyph } from './measure/FontEngine.js';
29
+ export { setMeasureProfile, getMeasureProfile, measurePx } from './measure/FontkitMeasureContext.js';
30
+ export type { MeasureProfile } from './measure/FontkitMeasureContext.js';
26
31
  export { getFontBuffer } from './utils/font.js';
27
32
  export { FontNotFoundError } from './measure/FontNotFoundError.js';
28
33
  import type { ParagraphStyle, TextRun } from './types/Document.js';
@@ -1 +1 @@
1
- {"version":3,"file":"index.browser.d.ts","sourceRoot":"","sources":["../src/index.browser.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAGH,OAAO,EAAE,qBAAqB,EAAE,qBAAqB,EAAE,MAAM,mCAAmC,CAAC;AAEjG,gBAAgB;AAChB,OAAO,EAAE,aAAa,EAAE,MAAM,+BAA+B,CAAC;AAC9D,gBAAgB;AAChB,OAAO,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,8BAA8B,CAAC;AAGjF,OAAO,EAAE,qBAAqB,EAAE,MAAM,kCAAkC,CAAC;AAGzE,OAAO,EAAE,eAAe,EAAE,MAAM,mCAAmC,CAAC;AAGpE,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,2BAA2B,CAAC;AAGlE,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAE,yBAAyB,EAAE,0BAA0B,EAAE,MAAM,+BAA+B,CAAC;AAGzJ,OAAO,EAAE,mBAAmB,EAAE,mBAAmB,EAAE,MAAM,kCAAkC,CAAC;AAC5F,OAAO,EAAE,cAAc,EAAE,eAAe,EAAE,mBAAmB,EAAE,qBAAqB,EAAE,MAAM,yBAAyB,CAAC;AACtH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAGhD,OAAO,EAAE,iBAAiB,EAAE,MAAM,gCAAgC,CA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