@openpresentation/opf 0.7.0 → 0.9.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.
@@ -95,8 +95,12 @@ interface ComposedItem {
95
95
  value: unknown;
96
96
  payload: Record<string, unknown>;
97
97
  box: LayoutBox;
98
- text?: TextFit | RichTextFit | ListFit;
98
+ text?: TextFit | RichTextFit | ListFit | CodeTextFit;
99
99
  textStyle?: TextStyle;
100
+ /** Complete accepted quote internals; consumers must reuse these fits and styles. */
101
+ quoteLayout?: QuoteLayout;
102
+ /** Complete accepted code internals, including source lines and literal tab positions. */
103
+ codeLayout?: CodeLayout;
100
104
  /** Effective container settings, including inherited readability constraints. */
101
105
  composition: Composition;
102
106
  }
@@ -121,6 +125,37 @@ interface ComposedFlow {
121
125
  itemCount: number;
122
126
  slotCount: number;
123
127
  }
128
+ /** Additive penalties in grid-score-v3; lower is preferred. These are not quality percentages. */
129
+ interface CompositionPenalties {
130
+ cellProportions: number;
131
+ fontReduction: number;
132
+ textOverflow: number;
133
+ tableOverflow: number;
134
+ smallCells: number;
135
+ emptySlots: number;
136
+ }
137
+ interface CompositionCandidate {
138
+ columns: number;
139
+ rows: number;
140
+ score: number;
141
+ penalties: CompositionPenalties;
142
+ }
143
+ interface CompositionDecision {
144
+ path: string;
145
+ mode: NonNullable<Composition['mode']> | 'regions';
146
+ reason: 'lowest-score' | 'configured-mode' | 'promoted-regions';
147
+ selectedColumns?: number;
148
+ /** Only candidates actually evaluated by automatic selection, in tie-break order. */
149
+ candidates: CompositionCandidate[];
150
+ }
151
+ interface CompositionExplanation {
152
+ algorithm: 'grid-score-v3';
153
+ /** Provided widths do not establish shaping, glyph coverage or native fidelity. */
154
+ textMeasurement: 'estimated' | 'provided';
155
+ decisions: CompositionDecision[];
156
+ /** Payloads whose complete internal fit is not covered by this scoring model. */
157
+ unmeasuredPayloads: string[];
158
+ }
124
159
  interface SlideComposition {
125
160
  width: number;
126
161
  height: number;
@@ -130,6 +165,7 @@ interface SlideComposition {
130
165
  flows: ComposedFlow[];
131
166
  diagnostics: LayoutDiagnostic[];
132
167
  composition: Composition;
168
+ explanation?: CompositionExplanation;
133
169
  }
134
170
  interface ComposeSlideOptions {
135
171
  fonts?: Partial<FontFamilies>;
@@ -138,16 +174,134 @@ interface ComposeSlideOptions {
138
174
  height?: number;
139
175
  slideIndex?: number;
140
176
  layout?: Record<string, unknown>;
177
+ /** Return candidate scores and coverage without changing the selected geometry. */
178
+ explain?: boolean;
141
179
  }
142
180
  declare class OPFCompositionError extends Error {
143
181
  readonly diagnostics: LayoutDiagnostic[];
144
182
  readonly code = "layout-overflow";
145
- constructor(diagnostics: LayoutDiagnostic[]);
183
+ readonly explanation?: CompositionExplanation;
184
+ constructor(diagnostics: LayoutDiagnostic[], explanation?: CompositionExplanation);
146
185
  }
147
186
  /** Deterministic estimate, not a font shaping engine. Preserves explicit line breaks. */
148
187
  declare function measureText(text: string, fontSize: number): number;
149
188
  declare function wrapText(text: string, width: number, fontSize: number, measure?: MeasureTextWidth): string[];
150
189
  declare function fitText(text: string, box: LayoutBox, requestedSize?: number, minFontSize?: number, measure?: MeasureTextWidth): TextFit;
190
+ interface QuoteContent {
191
+ text: string;
192
+ attribution?: string;
193
+ source?: string;
194
+ }
195
+ /** Source and displayed-text ranges are half-open UTF-16 offsets. Added punctuation has no source range. */
196
+ interface QuoteTextSource {
197
+ path: string;
198
+ start: number;
199
+ end: number;
200
+ outputStart: number;
201
+ outputEnd: number;
202
+ }
203
+ interface QuoteTextPart {
204
+ role: 'body' | 'footer';
205
+ path: string;
206
+ text: string;
207
+ sources: QuoteTextSource[];
208
+ /** Available space, before fitting. Invalid dimensions remain visible in failed results. */
209
+ box: LayoutBox;
210
+ requestedFontSize: number;
211
+ minFontSize: number;
212
+ requestedStyle: TextStyle;
213
+ style: TextStyle;
214
+ /** Absent when the available box is invalid; never fit against an invented one-pixel box. */
215
+ fit?: TextFit;
216
+ }
217
+ interface QuoteLayoutDiagnostic extends LayoutDiagnostic {
218
+ reason: 'invalid-part-box' | 'part-outside-cell' | 'text-fit' | 'part-overlap';
219
+ parts: QuoteTextPart['role'][];
220
+ }
221
+ interface QuoteLayout {
222
+ algorithm: 'quote-flow-v1';
223
+ textMeasurement: 'estimated' | 'provided';
224
+ parts: QuoteTextPart[];
225
+ diagnostics: QuoteLayoutDiagnostic[];
226
+ overflow: boolean;
227
+ }
228
+ interface QuoteLayoutOptions {
229
+ /** Canvas short edge divided by 720. Insets retain the current 18 reference-pixel contract. */
230
+ scale?: number;
231
+ fonts?: Partial<FontFamilies>;
232
+ /** Readability floor in reference pixels, before canvas scaling. */
233
+ minFontSize?: number;
234
+ overflow?: Composition['overflow'];
235
+ path?: string;
236
+ textMeasurement?: TextMeasurement;
237
+ }
238
+ /**
239
+ * Allocate and measure quote body/footer space for composition, rendering and export. Callers must
240
+ * check overflow before accepting the parts. Line boxes are not shaped glyph or native raster bounds.
241
+ */
242
+ declare function layoutQuote(value: string | QuoteContent, box: LayoutBox, options?: QuoteLayoutOptions): QuoteLayout;
243
+ interface CodeContent {
244
+ source: string;
245
+ language?: string;
246
+ filename?: string;
247
+ }
248
+ interface CodeLineSegment {
249
+ kind: 'text' | 'tab';
250
+ start: number;
251
+ end: number;
252
+ /** Measured position relative to this displayed line's origin, in reference pixels. */
253
+ x: number;
254
+ width: number;
255
+ }
256
+ /** Exact half-open UTF-16 offsets into the part text, including consumed hard line breaks. */
257
+ interface CodeLineSource {
258
+ start: number;
259
+ end: number;
260
+ nextStart: number;
261
+ boundary: 'soft' | 'hard' | 'end';
262
+ width: number;
263
+ /** Explicit tab placement is required in SVG; CSS tab-size alone does not implement it. */
264
+ segments: CodeLineSegment[];
265
+ }
266
+ interface CodeTextFit extends TextFit {
267
+ sourceLines: CodeLineSource[];
268
+ /** Tabs advance to the next multiple of four measured spaces from each displayed line's origin. */
269
+ tabSize: 4;
270
+ tabWidth: number;
271
+ }
272
+ interface CodeTextPart {
273
+ role: 'filename' | 'language' | 'body';
274
+ path: string;
275
+ /** Original text, without case conversion, whitespace normalization or discarded newlines. */
276
+ text: string;
277
+ sources: {
278
+ path: string;
279
+ start: number;
280
+ end: number;
281
+ }[];
282
+ generated: boolean;
283
+ box: LayoutBox;
284
+ requestedFontSize: number;
285
+ minFontSize: number;
286
+ requestedStyle: TextStyle;
287
+ style: TextStyle;
288
+ fit?: CodeTextFit;
289
+ }
290
+ interface CodeLayoutDiagnostic extends LayoutDiagnostic {
291
+ reason: 'invalid-part-box' | 'part-outside-cell' | 'text-fit' | 'part-overlap';
292
+ parts: CodeTextPart['role'][];
293
+ }
294
+ interface CodeLayout {
295
+ algorithm: 'code-flow-v1';
296
+ textMeasurement: 'estimated' | 'provided';
297
+ parts: CodeTextPart[];
298
+ diagnostics: CodeLayoutDiagnostic[];
299
+ overflow: boolean;
300
+ }
301
+ interface CodeLayoutOptions extends QuoteLayoutOptions {
302
+ }
303
+ /** Shared filename/language/body allocation. Consumers must reuse the accepted fits and styles. */
304
+ declare function layoutCode(value: string | CodeContent, box: LayoutBox, options?: CodeLayoutOptions): CodeLayout;
151
305
  interface RichTextRun {
152
306
  text: string;
153
307
  bold?: boolean;
@@ -272,4 +426,4 @@ declare function resolveCanvasDimensions(input: unknown): {
272
426
  height: number;
273
427
  };
274
428
 
275
- export { type ComposeSlideOptions, type ComposedFlow, type ComposedGroup, type ComposedItem, type Composition, type CompositionTrack, type FontFamilies, type LayoutBox, type LayoutDiagnostic, type ListEntryLayout, type ListFit, type ListText, type ListValue, MAX_COMPOSITION_DEPTH, type MeasureTextWidth, OPFCompositionError, type RichTextFit, type RichTextFragment, type RichTextLine, type RichTextOptions, type RichTextRun, type SlideComposition, type TableBorder, type TableCellLayout, type TableCellStyle, type TableGrid, type TableGridCell, type TableGridIssue, type TableLayout, type TableLayoutOptions, type TableRowLayout, type TextFit, type TextMeasurement, type TextStyle, composeSlide, fitList, fitRichText, fitText, layoutTable, measureText, resolveCanvasDimensions, resolveFontFamilies, resolveTextStyle, tableGrid, tableRowBoundaries, textWidthMeasurer, wrapText };
429
+ export { type CodeContent, type CodeLayout, type CodeLayoutDiagnostic, type CodeLayoutOptions, type CodeLineSegment, type CodeLineSource, type CodeTextFit, type CodeTextPart, type ComposeSlideOptions, type ComposedFlow, type ComposedGroup, type ComposedItem, type Composition, type CompositionCandidate, type CompositionDecision, type CompositionExplanation, type CompositionPenalties, type CompositionTrack, type FontFamilies, type LayoutBox, type LayoutDiagnostic, type ListEntryLayout, type ListFit, type ListText, type ListValue, MAX_COMPOSITION_DEPTH, type MeasureTextWidth, OPFCompositionError, type QuoteContent, type QuoteLayout, type QuoteLayoutDiagnostic, type QuoteLayoutOptions, type QuoteTextPart, type QuoteTextSource, type RichTextFit, type RichTextFragment, type RichTextLine, type RichTextOptions, type RichTextRun, type SlideComposition, type TableBorder, type TableCellLayout, type TableCellStyle, type TableGrid, type TableGridCell, type TableGridIssue, type TableLayout, type TableLayoutOptions, type TableRowLayout, type TextFit, type TextMeasurement, type TextStyle, composeSlide, fitList, fitRichText, fitText, layoutCode, layoutQuote, layoutTable, measureText, resolveCanvasDimensions, resolveFontFamilies, resolveTextStyle, tableGrid, tableRowBoundaries, textWidthMeasurer, wrapText };
@@ -1 +1 @@
1
- export { MAX_COMPOSITION_DEPTH, OPFCompositionError, composeSlide, fitList, fitRichText, fitText, layoutTable, measureText, resolveCanvasDimensions, resolveFontFamilies, resolveTextStyle, tableGrid, tableRowBoundaries, textWidthMeasurer, wrapText } from './chunk-OVPWNQIJ.js';
1
+ export { MAX_COMPOSITION_DEPTH, OPFCompositionError, composeSlide, fitList, fitRichText, fitText, layoutCode, layoutQuote, layoutTable, measureText, resolveCanvasDimensions, resolveFontFamilies, resolveTextStyle, tableGrid, tableRowBoundaries, textWidthMeasurer, wrapText } from './chunk-JA5W5TVA.js';