renderpdf-js 0.1.0 → 0.2.1

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.
package/dist/layout.d.ts CHANGED
@@ -8,6 +8,8 @@ import type { LayoutSnapshot } from './types.js';
8
8
  export declare function snapshotLayout(root: HTMLElement, fonts: readonly RegisteredFont[], options?: {
9
9
  /** Strict mode keeps native errors unless a boundary has explicit data-raster markup. */
10
10
  fallback?: 'auto' | 'strict';
11
+ /** Reserve and replay a native THEAD on each body continuation page. */
12
+ repeatTableHeaders?: boolean;
11
13
  }): Promise<LayoutSnapshot>;
12
14
  /** Measure settled browser resources synchronously so a source guard can share the same task.
13
15
  * @param root Connected, visible HTMLElement with its fonts and source images already prepared.
@@ -17,4 +19,6 @@ export declare function snapshotLayout(root: HTMLElement, fonts: readonly Regist
17
19
  export declare function measurePreparedLayout(root: HTMLElement, fonts: readonly RegisteredFont[], options?: {
18
20
  /** Strict mode keeps native errors unless a boundary has explicit data-raster markup. */
19
21
  fallback?: 'auto' | 'strict';
22
+ /** Reserve and replay a native THEAD on each body continuation page. */
23
+ repeatTableHeaders?: boolean;
20
24
  }): LayoutSnapshot;
@@ -0,0 +1,24 @@
1
+ import type { PageGeometry, RegisteredFont, RenderPDFOptions } from './api-types.js';
2
+ /** Copied, validated inputs for one repeated text band. */
3
+ export interface PageText {
4
+ /** Caller text with supported page placeholders preserved until pagination finishes. */
5
+ readonly text: string;
6
+ /** Reserved height in CSS pixels. */
7
+ readonly height: number;
8
+ /** Exact face also supplied to the source renderer. */
9
+ readonly font: RegisteredFont;
10
+ /** Font size in CSS pixels. */
11
+ readonly fontSize: number;
12
+ /** Horizontal placement inside the original page margins. */
13
+ readonly align: 'left' | 'center' | 'right';
14
+ }
15
+ /** Reserve page text outside the source area without changing the caller's DOM layout. */
16
+ export declare function resolvePageBands(
17
+ /** Original physical page and outer margins. */
18
+ page: PageGeometry,
19
+ /** Validated options whose font handles remain immutable. */
20
+ options: RenderPDFOptions): {
21
+ content: PageGeometry;
22
+ header: PageText | undefined;
23
+ footer: PageText | undefined;
24
+ };
package/dist/page.d.ts CHANGED
@@ -1,5 +1,9 @@
1
- import type { PageGeometry, RenderPDFOptions } from './api-types.js';
2
- /** Resolve physical paper dimensions and validate the small public option surface. */
3
- export declare function resolvePage(
1
+ import type { PageGeometry, PDFPageOptions, RenderPDFOptions } from './api-types.js';
2
+ /** Resolve physical paper dimensions without requiring DOM content or registered fonts. */
3
+ export declare function resolvePageGeometry(
4
4
  /** Caller-owned options; resolving them never changes their values. */
5
+ options: PDFPageOptions): PageGeometry;
6
+ /** Validate HTML rendering settings around the shared physical page geometry. */
7
+ export declare function resolvePage(
8
+ /** Caller-owned HTML rendering options. */
5
9
  options: RenderPDFOptions): PageGeometry;
@@ -1,11 +1,15 @@
1
1
  import type { RenderWarning } from './diagnostics.js';
2
- import type { LayoutSnapshot } from './types.js';
2
+ import type { LayoutSnapshot, TableHeader } from './types.js';
3
3
  /** One source-coordinate interval mapped into a PDF page. */
4
4
  export interface PageSlice {
5
5
  /** Inclusive source top in CSS pixels. */
6
6
  start: number;
7
7
  /** Exclusive source bottom in CSS pixels. */
8
8
  end: number;
9
+ /** Original header replayed before this continuation interval; absent on its first page. */
10
+ header?: TableHeader;
11
+ /** Reserved repeated band, counting any leading source row gap only once. */
12
+ headerHeight?: number;
9
13
  }
10
14
  /** Map one continuous source into pages with required cuts and best-effort CSS avoidance. */
11
15
  export declare function paginate(
package/dist/pdf.d.ts CHANGED
@@ -1,4 +1,5 @@
1
- import type { PageGeometry, RegisteredFont } from './api-types.js';
1
+ import type { PageGeometry, PDFMetadata, RegisteredFont, RenderProgress } from './api-types.js';
2
+ import type { PageText } from './page-bands.js';
2
3
  import type { PageSlice } from './pagination.js';
3
4
  import type { LayoutSnapshot } from './types.js';
4
5
  /** Bounded writer settings independent of DOM layout measurement. */
@@ -9,6 +10,14 @@ export interface PDFWriteOptions {
9
10
  includeRasterText?: boolean;
10
11
  /** Stop before beginning subsequent asynchronous writing stages. */
11
12
  signal?: AbortSignal;
13
+ /** Copied plain text placed above the source, outside its page clip. */
14
+ header?: PageText;
15
+ /** Copied plain text placed below the source, outside its page clip. */
16
+ footer?: PageText;
17
+ /** Owned Unicode document properties, resolved before preparation begins. */
18
+ metadata?: Readonly<PDFMetadata>;
19
+ /** Internal awaited reporter; public application callbacks remain synchronous. */
20
+ reportProgress?: (progress: RenderProgress) => Promise<void>;
12
21
  }
13
22
  /** Serialized PDF and the exact source intervals used for page ownership. */
14
23
  export interface PDFWriteResult {
@@ -0,0 +1,11 @@
1
+ import type { RenderProgress } from './api-types.js';
2
+ /** One export owns its callback error and optional browser scheduling state. */
3
+ export declare function createProgressReporter(
4
+ /** Synchronous application listener, absent when progress was not requested. */
5
+ callback: ((progress: RenderProgress) => void) | undefined,
6
+ /** Optional cooperative cancellation shared with the rendering pipeline. */
7
+ signal?: AbortSignal): {
8
+ report: ((progress: RenderProgress) => Promise<void>) | undefined;
9
+ /** Preserve application exceptions across lower-level PDF adapter error wrapping. */
10
+ rethrow(error: unknown): never;
11
+ };
@@ -0,0 +1,52 @@
1
+ import type { BorderOperation, Bounds } from './types.js';
2
+ /** One authored border competing for a measured collapsed grid edge. */
3
+ export interface TableBorderCandidate {
4
+ /** Horizontal or vertical source-coordinate grid line. */
5
+ direction: 'horizontal' | 'vertical';
6
+ /** Fixed grid coordinate perpendicular to the edge. */
7
+ position: number;
8
+ /** Inclusive coordinate along the edge. */
9
+ start: number;
10
+ /** Exclusive coordinate along the edge. */
11
+ end: number;
12
+ /** Computed thickness; hidden borders retain priority even when their computed width is zero. */
13
+ width: number;
14
+ /** Supported CSS border style; hidden suppresses every competing border. */
15
+ style: 'solid' | 'none' | 'hidden';
16
+ /** Browser-resolved color of this candidate. */
17
+ color: string;
18
+ /** Cells outrank the table when equally wide solid borders compete. */
19
+ owner: 'cell' | 'table';
20
+ /** Owner's top grid coordinate, used for the upper-cell tie break. */
21
+ row: number;
22
+ /** Owner's left grid coordinate, used for the left-cell tie break in LTR tables. */
23
+ column: number;
24
+ }
25
+ /** Native border paint and replay limits for one measured collapsed table. */
26
+ export interface CollapsedTablePaint {
27
+ /** Nonoverlapping final fills in border conflict priority order. */
28
+ operations: BorderOperation[];
29
+ /** Header grid bounds expanded through the outer top, left and right half-borders. */
30
+ headerBounds?: Bounds;
31
+ /** Continuations can reuse half-boundaries only when their horizontal winners agree. */
32
+ repeatSafe: boolean;
33
+ }
34
+ /** Resolve pure measured-border inputs without depending on browser or PDF globals.
35
+ * @param candidates Competing authored borders with already measured grid coordinates.
36
+ */
37
+ export declare function resolveCollapsedBorders(candidates: readonly TableBorderCandidate[]): BorderOperation[];
38
+ /** Find native HTML table parts whose borders participate in one collapsed grid.
39
+ * @param element Current element from the existing static layout traversal.
40
+ * @param style Already computed style for this element.
41
+ */
42
+ export declare function collapsedTableOwner(element: HTMLElement, style: CSSStyleDeclaration): HTMLTableElement | undefined;
43
+ /** Enforce the deliberately bounded collapsed-border contributions before native box emission.
44
+ * @param element Native table part whose sides will be resolved together after its cells.
45
+ * @param style Browser-computed authored sides, independent of the winning shared border.
46
+ */
47
+ export declare function validateCollapsedTablePart(element: HTMLElement, style: CSSStyleDeclaration): void;
48
+ /** Measure cell centerlines and resolve the native table's single border paint layer.
49
+ * @param table Connected native collapsed table with existing browser-calculated column widths.
50
+ * @param origin Source root rectangle defining the shared CSS pixel coordinate system.
51
+ */
52
+ export declare function measureCollapsedTableBorders(table: HTMLTableElement, origin: DOMRect): CollapsedTablePaint;
package/dist/text.d.ts CHANGED
@@ -32,6 +32,15 @@ export declare class PositionedFont {
32
32
  * @param kerning Whether CSS admits kerning for this line.
33
33
  */
34
34
  shape(text: string, kerning?: boolean): readonly PositionedGlyph[];
35
+ /** Measure shaped advance and ink extents so repeated page text cannot overflow its band.
36
+ * @param text Complete single line using this exact embedded font.
37
+ */
38
+ measure(text: string): {
39
+ left: number;
40
+ right: number;
41
+ ascent: number;
42
+ descent: number;
43
+ };
35
44
  /** Preserve extraction for every used shaped glyph, including uncoded ligatures.
36
45
  * @param document Export document owning the public font reference and object context.
37
46
  */
package/dist/tiff.d.ts ADDED
@@ -0,0 +1,23 @@
1
+ /** A single unrotated TIFF raster; the PDF writer applies its explicit orientation matrix. */
2
+ export interface TiffFrame {
3
+ /** Original stored columns, before orientation. */
4
+ width: number;
5
+ /** Original stored rows, before orientation. */
6
+ height: number;
7
+ /** Straight-alpha eight-bit RGBA pixels owned by this decode. */
8
+ rgba: Uint8Array;
9
+ /** TIFF orientation in the inclusive range one through eight. */
10
+ orientation: number;
11
+ }
12
+ /** Bounded metadata access without retaining decoded rasters for every page. */
13
+ export interface TiffDocument {
14
+ /** Number of image-bearing main IFDs in their original linked order. */
15
+ readonly pageCount: number;
16
+ /** Decode one requested frame; no previous frame raster is retained. */
17
+ decodeFrame(index: number): Promise<TiffFrame>;
18
+ }
19
+ /** Open only metadata first; decode requested scan frames individually through public UTIF APIs.
20
+ * @param input Complete caller-owned TIFF bytes; the adapter keeps an independent encoded copy.
21
+ * @param signal Cooperative cancellation before metadata work and each synchronous frame decode.
22
+ */
23
+ export declare function openTiff(input: Uint8Array, signal?: AbortSignal): Promise<TiffDocument>;
package/dist/types.d.ts CHANGED
@@ -57,6 +57,19 @@ export interface BoxOperation {
57
57
  /** Uniform border width in CSS pixels. */
58
58
  borderWidth: number;
59
59
  }
60
+ /** One disjoint solid fill belonging to a resolved collapsed table border. */
61
+ export interface BorderOperation {
62
+ /** Discriminant for native filled-border dispatch. */
63
+ kind: 'border';
64
+ /** Actual positive painted rectangle, including the half-width outside its grid line. */
65
+ bounds: Bounds;
66
+ /** Browser-computed winning border color, including any alpha component. */
67
+ color: string;
68
+ /** Winning CSS border thickness before crossing rectangles are partitioned. */
69
+ width: number;
70
+ /** Grid direction retained independently of the final clipped fill rectangle. */
71
+ direction: 'horizontal' | 'vertical';
72
+ }
60
73
  /** An explicitly isolated DOM subtree captured at its paint-order position. */
61
74
  export interface RasterOperation {
62
75
  /** Discriminant for ordered paint dispatch. */
@@ -76,7 +89,18 @@ export interface ImageOperation {
76
89
  element: HTMLImageElement;
77
90
  }
78
91
  /** A flattened, ordered experiment display list, not a general CSS paint tree. */
79
- export type PaintOperation = TextOperation | BoxOperation | RasterOperation | ImageOperation;
92
+ export type PaintOperation = TextOperation | BoxOperation | BorderOperation | RasterOperation | ImageOperation;
93
+ /** Native table header replayed above each continuation interval without changing source geometry. */
94
+ export interface TableHeader {
95
+ /** Original THEAD border box in source CSS pixels. */
96
+ bounds: Bounds;
97
+ /** First visible body row top; the gap after THEAD belongs to every repeated header. */
98
+ bodyStart: number;
99
+ /** Last visible body row bottom, excluding any TFOOT. */
100
+ bodyEnd: number;
101
+ /** Original paint references, including ancestor boxes clipped to the header band by the writer. */
102
+ operations: PaintOperation[];
103
+ }
80
104
  /** Immutable geometry metadata plus a bounded list of ordered paint operations. */
81
105
  export interface LayoutSnapshot {
82
106
  /** Measured root width in CSS pixels. */
@@ -93,4 +117,6 @@ export interface LayoutSnapshot {
93
117
  forcedBreaks?: number[];
94
118
  /** Preferred indivisible blocks; oversized preferences may relax with an explicit warning. */
95
119
  avoidBreakBounds?: Bounds[];
120
+ /** Explicitly requested native THEAD repetitions for nonoverlapping tables. */
121
+ tableHeaders?: TableHeader[];
96
122
  }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "renderpdf-js",
3
- "version": "0.1.0",
4
- "description": "Browser-only HTML to PDF renderer with explicit fonts and local raster regions",
3
+ "version": "0.2.1",
4
+ "description": "Convert HTML, PNG, JPEG and multipage TIFF to PDF in the browser.",
5
5
  "license": "MIT",
6
6
  "repository": {
7
7
  "type": "git",
@@ -16,7 +16,9 @@
16
16
  "html",
17
17
  "browser",
18
18
  "typescript",
19
- "html-to-pdf"
19
+ "html-to-pdf",
20
+ "image-to-pdf",
21
+ "tiff-to-pdf"
20
22
  ],
21
23
  "publishConfig": {
22
24
  "access": "public",
@@ -59,7 +61,8 @@
59
61
  "dependencies": {
60
62
  "@pdf-lib/fontkit": "^1.1.1",
61
63
  "html-to-image": "^1.11.13",
62
- "pdf-lib": "^1.17.1"
64
+ "pdf-lib": "^1.17.1",
65
+ "utif2": "4.1.0"
63
66
  },
64
67
  "devDependencies": {
65
68
  "@playwright/test": "^1.64.1",