@json-to-office/core-docx 1.4.0 → 1.5.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.
@@ -0,0 +1,82 @@
1
+ import type { PreparedDocument, QualityFact } from '@json-to-office/quality';
2
+ import type { FontRuntimeOpts, GenerationWarning } from '@json-to-office/shared';
3
+ import type { ReportComponentDefinition } from '../types';
4
+ import type { ThemeConfig } from '../styles';
5
+ import { type GenerationThemeContext } from '../core/generationContext';
6
+ import { type ResolvedDocumentTree } from '../core/structure';
7
+ export interface DocxTableWidthFact extends QualityFact {
8
+ kind: 'docx/table-width';
9
+ totalWidthTwips: number;
10
+ availableWidthTwips: number;
11
+ hasExplicitWidth: boolean;
12
+ allColumnsExplicit: boolean;
13
+ pointSum: number;
14
+ percentSum: number;
15
+ /**
16
+ * Authored explicit widths by column index (points as numbers, `"NN%"`
17
+ * strings kept verbatim) — what a fix has to rescale. Columns without an
18
+ * explicit width are absent.
19
+ */
20
+ explicitWidths: ReadonlyArray<{
21
+ index: number;
22
+ width: number | string;
23
+ }>;
24
+ }
25
+ export interface DocxHeadingFact extends QualityFact {
26
+ kind: 'docx/heading';
27
+ level: number;
28
+ previousLevel?: number;
29
+ }
30
+ /**
31
+ * A paragraph pinned into a floating frame — the one place in DOCX where the
32
+ * author, not the layout engine, decides how much room the text gets. Flowed
33
+ * body copy repaginates; a frame keeps its declared box and lets the text spill
34
+ * or break inside it.
35
+ */
36
+ export interface DocxFrameTextFact extends QualityFact {
37
+ kind: 'docx/frame-text';
38
+ text: string;
39
+ fontSizePt: number;
40
+ /** Height of one line, including the resolved line-spacing rule. */
41
+ lineHeightPt: number;
42
+ /** Signed tracking in points: negative when the run is condensed. */
43
+ characterSpacingPt: number;
44
+ frameWidthTwips: number;
45
+ frameHeightTwips?: number;
46
+ /** Frame top, when pinned with an absolute vertical offset. */
47
+ offsetYTwips?: number;
48
+ /** The paper edge — the last twip anything can render on. */
49
+ pageBottomTwips: number;
50
+ /** The longest whitespace-delimited token — the one with nowhere to wrap. */
51
+ longestWord: string;
52
+ }
53
+ /**
54
+ * A `<text>` element inside an inline SVG, with the canvas it has to sit in.
55
+ * SVG has no overflow rule to fall back on: a baseline past the viewBox is
56
+ * simply not painted, and the words leave the document's text layer with it.
57
+ */
58
+ export interface DocxSvgTextFact extends QualityFact {
59
+ kind: 'docx/svg-text';
60
+ content: string;
61
+ /** Baseline position and nominal size, in viewBox units. */
62
+ baselineY: number;
63
+ fontSizeUnits: number;
64
+ viewBoxMinY: number;
65
+ viewBoxHeight: number;
66
+ }
67
+ export type DocxQualityFact = DocxTableWidthFact | DocxHeadingFact | DocxFrameTextFact | DocxSvgTextFact;
68
+ export interface DocxQualityModel {
69
+ authored: ReportComponentDefinition;
70
+ context: GenerationThemeContext;
71
+ document: ResolvedDocumentTree;
72
+ themeName: string;
73
+ }
74
+ export interface PrepareDocxQualityOptions {
75
+ customThemes?: Record<string, ThemeConfig>;
76
+ fonts?: FontRuntimeOpts;
77
+ warnings?: GenerationWarning[];
78
+ context?: GenerationThemeContext;
79
+ renderer?: string;
80
+ }
81
+ export declare function prepareDocxQualityDocument(document: ReportComponentDefinition, options?: PrepareDocxQualityOptions): PreparedDocument<DocxQualityModel, DocxQualityFact>;
82
+ //# sourceMappingURL=facts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"facts.d.ts","sourceRoot":"","sources":["../../src/quality/facts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,gBAAgB,EAEhB,WAAW,EACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAuB,yBAAyB,EAAE,MAAM,UAAU,CAAC;AAC/E,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAEL,KAAK,sBAAsB,EAC5B,MAAM,2BAA2B,CAAC;AAEnC,OAAO,E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CAAC;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,MAAM,CAAC;CACvB;AAED,MAAM,MAAM,eAAe,GACvB,kBAAkB,GAClB,eAAe,GACf,iBAAiB,GACjB,eAAe,CAAC;AAEpB,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,EAAE,yBAAyB,CAAC;IACpC,OAAO,EAAE,sBAAsB,CAAC;IAChC,QAAQ,EAAE,oBAAoB,CAAC;IAC/B,SAAS,EAAE,MAAM,CAAC;CACnB;AAED,MAAM,WAAW,yBAAyB;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;IAC3C,KAAK,CAAC,EAAE,eAAe,CAAC;IACxB,QAAQ,CAAC,EAAE,iBAAiB,EAAE,CAAC;IAC/B,OAAO,CAAC,EAAE,sBAAsB,CAAC;IACjC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAkPD,wBAAgB,0BAA0B,CACxC,QAAQ,EAAE,yBAAyB,EACnC,OAAO,GAAE,yBAA8B,GACtC,gBAAgB,CAAC,gBAAgB,EAAE,eAAe,CAAC,CA+ErD"}
@@ -0,0 +1,15 @@
1
+ /** DOCX quality analysis over renderer-aligned prepared facts. */
2
+ import { type PreparedDocument, type QualityAnalysis, type QualityPolicy, type QualityProfile } from '@json-to-office/quality';
3
+ import type { ThemeConfig } from '../styles';
4
+ import type { DocxQualityFact, DocxQualityModel } from './facts';
5
+ export interface DocxQualityOptions {
6
+ customThemes?: Record<string, ThemeConfig>;
7
+ }
8
+ export interface DocxQualityAnalysisOptions extends DocxQualityOptions {
9
+ renderer?: string;
10
+ profile?: QualityProfile;
11
+ policy?: QualityPolicy;
12
+ prepared?: PreparedDocument<DocxQualityModel, DocxQualityFact>;
13
+ }
14
+ export declare function analyzeDocxQuality(doc: unknown, options?: DocxQualityAnalysisOptions): QualityAnalysis;
15
+ //# sourceMappingURL=preflight.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"preflight.d.ts","sourceRoot":"","sources":["../../src/quality/preflight.ts"],"names":[],"mappings":"AAAA,kEAAkE;AAElE,OAAO,EAGL,KAAK,gBAAgB,EACrB,KAAK,eAAe,EACpB,KAAK,aAAa,EAClB,KAAK,cAAc,EAEpB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AAG7C,OAAO,KAAK,EAAE,eAAe,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAUjE,MAAM,WAAW,kBAAkB;IACjC,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAC;CAC5C;AAED,MAAM,WAAW,0BAA2B,SAAQ,kBAAkB;IACpE,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,cAAc,CAAC;IACzB,MAAM,CAAC,EAAE,aAAa,CAAC;IACvB,QAAQ,CAAC,EAAE,gBAAgB,CAAC,gBAAgB,EAAE,eAAe,CAAC,CAAC;CAChE;AAiBD,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,OAAO,EACZ,OAAO,GAAE,0BAA+B,GACvC,eAAe,CA2CjB"}
@@ -0,0 +1,38 @@
1
+ import { QualityEngine, type QualityProfile, type QualityRule, type QualityRulePack } from '@json-to-office/quality';
2
+ import type { DocxQualityFact, DocxQualityModel } from './facts';
3
+ export declare const docxTableWidthRule: QualityRule<DocxQualityModel, DocxQualityFact>;
4
+ export declare const docxHeadingHierarchyRule: QualityRule<DocxQualityModel, DocxQualityFact>;
5
+ export declare const docxTextFitRule: QualityRule<DocxQualityModel, DocxQualityFact>;
6
+ export declare const docxSvgTextBoundsRule: QualityRule<DocxQualityModel, DocxQualityFact>;
7
+ export declare const DOCX_QUALITY_RULES: QualityRulePack<DocxQualityModel, DocxQualityFact>;
8
+ export declare const DOCX_QUALITY_PROFILES: {
9
+ readonly 'executive-report': {
10
+ readonly id: "executive-report";
11
+ readonly formats: readonly ["docx"];
12
+ readonly description: "Short decision document with strict outline continuity.";
13
+ readonly rules: {
14
+ readonly 'docx/heading-hierarchy': {
15
+ readonly severity: "warning";
16
+ };
17
+ };
18
+ };
19
+ readonly 'technical-report': {
20
+ readonly id: "technical-report";
21
+ readonly formats: readonly ["docx"];
22
+ readonly description: "Portable professional report defaults.";
23
+ };
24
+ readonly 'legal-appendix': {
25
+ readonly id: "legal-appendix";
26
+ readonly formats: readonly ["docx"];
27
+ readonly description: "Dense appendix: preserve integrity without editorial taste.";
28
+ };
29
+ };
30
+ export declare const DOCX_DEFAULT_QUALITY_PROFILE: QualityProfile;
31
+ /**
32
+ * Callers name a shipped profile by id — `{ id: 'executive-report', formats: ['docx'] }`.
33
+ * Without this lookup that request reaches the engine carrying nothing but its id,
34
+ * so the analysis runs on defaults while stamping the requested profileId.
35
+ */
36
+ export declare function resolveDocxQualityProfile(requested: QualityProfile | undefined): QualityProfile | undefined;
37
+ export declare const docxQualityEngine: QualityEngine<DocxQualityModel, DocxQualityFact>;
38
+ //# sourceMappingURL=rules.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rules.d.ts","sourceRoot":"","sources":["../../src/quality/rules.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,aAAa,EACb,KAAK,cAAc,EACnB,KAAK,WAAW,EAChB,KAAK,eAAe,EACrB,MAAM,yBAAyB,CAAC;AACjC,OAAO,KAAK,EAGV,eAAe,EACf,gBAAgB,EAGjB,MAAM,SAAS,CAAC;AAejB,eAAO,MAAM,kBAAkB,EAAE,WAAW,CAC1C,gBAAgB,EAChB,eAAe,CA6DhB,CAAC;AAEF,eAAO,MAAM,wBAAwB,EAAE,WAAW,CAChD,gBAAgB,EAChB,eAAe,CAuChB,CAAC;AAsBF,eAAO,MAAM,eAAe,EAAE,WAAW,CAAC,gBAAgB,EAAE,eAAe,CAwF1E,CAAC;AAEF,eAAO,MAAM,qBAAqB,EAAE,WAAW,CAC7C,gBAAgB,EAChB,eAAe,CAqChB,CAAC;AAEF,eAAO,MAAM,kBAAkB,EAAE,eAAe,CAC9C,gBAAgB,EAChB,eAAe,CAShB,CAAC;AAEF,eAAO,MAAM,qBAAqB;;;;;;;;;;;;;;;;;;;;;CAmBiB,CAAC;AAEpD,eAAO,MAAM,4BAA4B,EAAE,cACA,CAAC;AAK5C;;;;GAIG;AACH,wBAAgB,yBAAyB,CACvC,SAAS,EAAE,cAAc,GAAG,SAAS,GACpC,cAAc,GAAG,SAAS,CAK5B;AAED,eAAO,MAAM,iBAAiB,kDAA8C,CAAC"}
@@ -0,0 +1,34 @@
1
+ /**
2
+ * A width model for authored runs, used only to answer "does this text fit".
3
+ *
4
+ * A single characters-per-point factor cannot do this job. Measured against the
5
+ * shipped display headings (`pdftotext -bbox`), the implied factor ran 0.435
6
+ * for mixed-case words and 0.694 for all-caps — a 39% spread that no single
7
+ * constant survives, because caps and lowercase are simply different widths.
8
+ *
9
+ * These are the standard Helvetica advance widths in 1/1000 em. The grotesque
10
+ * sans faces the stock templates use (DM Sans, Inter, Geist, Archivo) track
11
+ * them closely enough that summing real characters lands within about 8% of the
12
+ * rendered width, and it under-estimates more often than it over-estimates —
13
+ * the safe direction for a rule that only speaks up on overflow.
14
+ *
15
+ * Validated against rendered geometry at authoring time:
16
+ *
17
+ * "Vision," 80pt model 179.2pt actual 182.7pt −1.9%
18
+ * "Financial" 80pt model 241.8pt actual 246.8pt −2.0%
19
+ * "Global" 107pt model 251.6pt actual 264.4pt −4.8%
20
+ * "Performance" 80pt model 362.2pt actual 383.0pt −5.4%
21
+ * "OUR" 76pt model 168.9pt actual 158.2pt +6.8%
22
+ */
23
+ /**
24
+ * Width of `text` in points at `fontSizePt`, with `trackingPt` of signed
25
+ * letter-spacing applied per character (negative when the run is condensed).
26
+ */
27
+ export declare function estimateTextWidthPt(text: string, fontSizePt: number, trackingPt?: number): number;
28
+ /**
29
+ * Lines `text` needs when wrapped at `widthPt`, breaking on spaces. A word
30
+ * wider than the line gets its own line here; the renderer would break it
31
+ * mid-word, which `docx/text-fit` reports separately.
32
+ */
33
+ export declare function estimateWrappedLines(text: string, widthPt: number, fontSizePt: number, trackingPt?: number): number;
34
+ //# sourceMappingURL=text-metrics.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"text-metrics.d.ts","sourceRoot":"","sources":["../../src/quality/text-metrics.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;GAqBG;AAgFH;;;GAGG;AACH,wBAAgB,mBAAmB,CACjC,IAAI,EAAE,MAAM,EACZ,UAAU,EAAE,MAAM,EAClB,UAAU,SAAI,GACb,MAAM,CAOR;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,MAAM,EACf,UAAU,EAAE,MAAM,EAClB,UAAU,SAAI,GACb,MAAM,CAuBR"}