@nemu-ai/pdf 1.0.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,112 @@
1
+ import type { PageDimensions, DocumentOptions, MarginValues, StyleProperties } from "./types";
2
+ import type { Theme, ShapeStyle } from "./theme";
3
+ import { Vector, type VectorLike } from "../lib/vector";
4
+ interface FontInfo {
5
+ name: string;
6
+ path: string;
7
+ registered: boolean;
8
+ }
9
+ interface ImageInfo {
10
+ name: string;
11
+ path: string;
12
+ width: number;
13
+ height: number;
14
+ }
15
+ export interface TextMeasurement {
16
+ width: number;
17
+ height: number;
18
+ }
19
+ export declare class Document {
20
+ pages: Page[];
21
+ page_width: number;
22
+ page_height: number;
23
+ margin: MarginValues;
24
+ fonts: Map<string, FontInfo>;
25
+ images: Map<string, ImageInfo>;
26
+ pdf_doc: any;
27
+ default_theme: Theme | null;
28
+ constructor(options?: DocumentOptions);
29
+ get_page_dimensions(options?: DocumentOptions): PageDimensions;
30
+ set_theme(theme: Theme): void;
31
+ create_page(theme?: Theme): Page;
32
+ add_page(): Page;
33
+ load_font(name: string, file_path: string): Promise<void>;
34
+ load_font_sync(name: string, file_path: string): void;
35
+ load_image(name: string, file_path: string): Promise<void>;
36
+ load_image_sync(name: string, file_path: string): void;
37
+ get_font(name: string): FontInfo | undefined;
38
+ get_image(name: string): ImageInfo | undefined;
39
+ set_pdf_doc(pdoc: any): void;
40
+ get_pdf_doc(): any;
41
+ build(file_path: string): Promise<void>;
42
+ }
43
+ export declare class Container {
44
+ private owner;
45
+ private theme;
46
+ private ops;
47
+ constructor(owner: Document, theme: Theme | null);
48
+ rect(pos: Vector, size: Vector, style?: ShapeStyle): void;
49
+ text(options: {
50
+ content: string;
51
+ style?: StyleProperties;
52
+ classname?: string;
53
+ position?: Vector;
54
+ width?: number;
55
+ }): void;
56
+ header(options: {
57
+ text: string;
58
+ style?: StyleProperties;
59
+ classname?: string;
60
+ position?: Vector;
61
+ width?: number;
62
+ }): void;
63
+ move_down(amount?: number): void;
64
+ render(pdoc: any, position: Vector): void;
65
+ }
66
+ export declare class Page {
67
+ private owner;
68
+ private operations;
69
+ private theme;
70
+ private cursor;
71
+ constructor(owner: Document, theme?: Theme);
72
+ get_width(): number;
73
+ get_height(): number;
74
+ get_content_width(): number;
75
+ get_content_height(): number;
76
+ get_margin_left(): number;
77
+ get_margin_right(): number;
78
+ get_margin_top(): number;
79
+ get_margin_bottom(): number;
80
+ get_cursor(): Vector;
81
+ set_cursor(pos: VectorLike): void;
82
+ get_cursor_x(): number;
83
+ get_cursor_y(): number;
84
+ measure_text(content: string, style?: StyleProperties): TextMeasurement;
85
+ container(position?: Vector): Container;
86
+ text(options: {
87
+ content: string;
88
+ style?: StyleProperties;
89
+ classname?: string;
90
+ position?: Vector;
91
+ width?: number;
92
+ }): void;
93
+ header(options: {
94
+ text: string;
95
+ style?: StyleProperties;
96
+ classname?: string;
97
+ position?: Vector;
98
+ width?: number;
99
+ }): void;
100
+ move_down(amount?: number): void;
101
+ rect(pos: Vector, size: Vector, style?: ShapeStyle): void;
102
+ image(options: {
103
+ name: string;
104
+ position?: Vector;
105
+ width?: number;
106
+ height?: number;
107
+ }): void;
108
+ push_op(callback: (pdoc: any) => void): void;
109
+ render(pdoc: any): void;
110
+ }
111
+ export { Theme, create_theme } from "./theme";
112
+ export { Vector, vector, type VectorLike } from "../lib/vector";
@@ -0,0 +1,25 @@
1
+ import type { ColorValue, MarginValues, StyleProperties } from "./types";
2
+ export declare const parse_color: (color_str: string) => ColorValue;
3
+ export declare const parse_dimension: (value: number | string | undefined, reference: number) => number;
4
+ export declare const normalize_margin: (margin: number | Partial<MarginValues> | undefined) => MarginValues;
5
+ export declare const expand_shorthand: (style: StyleProperties) => StyleProperties;
6
+ export declare const merge_styles: (base: StyleProperties, override: StyleProperties) => StyleProperties;
7
+ export declare class Style {
8
+ properties: StyleProperties;
9
+ constructor(properties?: StyleProperties);
10
+ get_margin(): {
11
+ top: number;
12
+ right: number;
13
+ bottom: number;
14
+ left: number;
15
+ };
16
+ get_padding(): {
17
+ top: number;
18
+ right: number;
19
+ bottom: number;
20
+ left: number;
21
+ };
22
+ get_color(): ColorValue | null;
23
+ get_background_color(): ColorValue | null;
24
+ get_dimension(property: "width" | "height", reference: number): number;
25
+ }
@@ -0,0 +1,55 @@
1
+ import type { StyleProperties } from "./types";
2
+ export interface ThemeDefinition {
3
+ colors: Record<string, string>;
4
+ fonts: {
5
+ heading: string;
6
+ body: string;
7
+ mono: string;
8
+ };
9
+ spacing: {
10
+ xs: number;
11
+ sm: number;
12
+ md: number;
13
+ lg: number;
14
+ xl: number;
15
+ };
16
+ border_radius: {
17
+ sm: number;
18
+ md: number;
19
+ lg: number;
20
+ };
21
+ }
22
+ export interface ShapeStyle {
23
+ fill_color?: string;
24
+ stroke_color?: string;
25
+ stroke_width?: number;
26
+ opacity?: number;
27
+ border_radius?: number;
28
+ }
29
+ export interface Position {
30
+ x: number;
31
+ y: number;
32
+ }
33
+ export interface Size {
34
+ width: number;
35
+ height: number;
36
+ }
37
+ export declare class Theme {
38
+ name: string;
39
+ definition: ThemeDefinition;
40
+ private classnames;
41
+ constructor(name: string, definition?: Partial<ThemeDefinition>);
42
+ define_classname(name: string, style: StyleProperties): void;
43
+ define_classname(definitions: Array<string | StyleProperties>): void;
44
+ get_classname(name: string): StyleProperties | undefined;
45
+ has_classname(name: string): boolean;
46
+ remove_classname(name: string): boolean;
47
+ clear_classnames(): void;
48
+ merge_classname(base_style: StyleProperties, classname: string): StyleProperties;
49
+ get_color(key: string): string;
50
+ get_font(key: keyof ThemeDefinition["fonts"]): string;
51
+ get_spacing(key: keyof ThemeDefinition["spacing"]): number;
52
+ get_border_radius(key: keyof ThemeDefinition["border_radius"]): number;
53
+ apply_to_style(base_style: StyleProperties, element_type?: "heading" | "text" | "container" | "shape"): StyleProperties;
54
+ }
55
+ export declare const create_theme: (name: string, definition?: Partial<ThemeDefinition>) => Theme;
@@ -0,0 +1,119 @@
1
+ export type PageSize = "A4" | "Letter" | "Legal" | "Custom";
2
+ export interface PageDimensions {
3
+ width: number;
4
+ height: number;
5
+ }
6
+ export interface DocumentOptions {
7
+ page_size?: PageSize;
8
+ custom_dimensions?: PageDimensions;
9
+ margin?: number | MarginValues;
10
+ }
11
+ export interface MarginValues {
12
+ top: number;
13
+ right: number;
14
+ bottom: number;
15
+ left: number;
16
+ }
17
+ export interface ColorValue {
18
+ r: number;
19
+ g: number;
20
+ b: number;
21
+ }
22
+ export interface StyleProperties {
23
+ margin?: number | string;
24
+ margin_top?: number | string;
25
+ margin_right?: number | string;
26
+ margin_bottom?: number | string;
27
+ margin_left?: number | string;
28
+ padding?: number | string;
29
+ padding_top?: number | string;
30
+ padding_right?: number | string;
31
+ padding_bottom?: number | string;
32
+ padding_left?: number | string;
33
+ border?: string;
34
+ border_top?: string;
35
+ border_right?: string;
36
+ border_bottom?: string;
37
+ border_left?: string;
38
+ background_color?: string;
39
+ font_family?: string;
40
+ font_size?: number;
41
+ font_weight?: "normal" | "bold" | number;
42
+ font_style?: "normal" | "italic" | "oblique";
43
+ color?: string;
44
+ text_align?: "left" | "center" | "right" | "justify";
45
+ text_transform?: "none" | "capitalize" | "uppercase" | "lowercase";
46
+ text_decoration?: "none" | "underline" | "line-through" | "overline";
47
+ line_height?: number;
48
+ letter_spacing?: number;
49
+ line_style?: "solid" | "dashed" | "dotted" | "double";
50
+ width?: number | string;
51
+ height?: number | string;
52
+ display?: "block" | "inline" | "none";
53
+ position?: "static" | "relative" | "absolute";
54
+ top?: number | string;
55
+ right?: number | string;
56
+ bottom?: number | string;
57
+ left?: number | string;
58
+ opacity?: number;
59
+ z_index?: number;
60
+ transform?: string;
61
+ transition?: string;
62
+ animation?: string;
63
+ cursor?: string;
64
+ overflow?: "visible" | "hidden" | "scroll" | "auto";
65
+ white_space?: "normal" | "nowrap" | "pre" | "pre-wrap" | "pre-line";
66
+ word_break?: "normal" | "break-all" | "keep-all";
67
+ word_wrap?: "normal" | "break-word";
68
+ text_overflow?: "clip" | "ellipsis";
69
+ vertical_align?: "baseline" | "top" | "middle" | "bottom" | "sub" | "super" | string;
70
+ visibility?: "visible" | "hidden" | "collapse";
71
+ }
72
+ export interface ElementBounds {
73
+ x: number;
74
+ y: number;
75
+ width: number;
76
+ height: number;
77
+ }
78
+ export interface FontDefinition {
79
+ name: string;
80
+ family: string;
81
+ data: Buffer;
82
+ subtype: "Type1" | "TrueType";
83
+ }
84
+ export interface ImageDefinition {
85
+ name: string;
86
+ width: number;
87
+ height: number;
88
+ data: Buffer;
89
+ format: "png" | "jpeg";
90
+ }
91
+ export interface PdfObject {
92
+ id: number;
93
+ generation: number;
94
+ content: string;
95
+ }
96
+ export interface PdfStream {
97
+ length: number;
98
+ content: string;
99
+ filters?: string[];
100
+ }
101
+ export declare abstract class Element {
102
+ style: StyleProperties;
103
+ bounds: ElementBounds;
104
+ constructor(style?: StyleProperties);
105
+ abstract render(context: RenderContext): string;
106
+ abstract calculate_layout(available_width: number, available_height: number): ElementBounds;
107
+ }
108
+ export interface RenderContext {
109
+ page_width: number;
110
+ page_height: number;
111
+ margin_top: number;
112
+ margin_right: number;
113
+ margin_bottom: number;
114
+ margin_left: number;
115
+ fonts: Map<string, FontDefinition>;
116
+ images: Map<string, ImageDefinition>;
117
+ current_y: number;
118
+ page_number: number;
119
+ }
@@ -0,0 +1,6 @@
1
+ export { Document, Page, Container } from "./document/document";
2
+ export { Theme, create_theme } from "./document/theme";
3
+ export { Vector, vector } from "./lib/vector";
4
+ export type { PageSize, PageDimensions, DocumentOptions, MarginValues, StyleProperties, ElementBounds, } from "./document/types";
5
+ export type { VectorLike } from "./lib/vector";
6
+ export type { ShapeStyle } from "./document/theme";