takumi-pdf 0.1.0 → 0.1.2

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/README.md CHANGED
@@ -84,6 +84,12 @@ const pdf = await render(<div style={{ width: "100%", height: "100%" }}>Certific
84
84
  });
85
85
  ```
86
86
 
87
+ Omit `height` to size the single page to its content, like a thermal receipt. Percentage heights do not resolve there.
88
+
89
+ ```tsx
90
+ const pdf = await render(receipt, { viewport: { width: 302 } });
91
+ ```
92
+
87
93
  `viewport` cannot be combined with `size`, `landscape`, `margin`, `header`, or `footer`.
88
94
 
89
95
  ## Fonts
package/dist/export.d.cts CHANGED
@@ -40,6 +40,11 @@ declare function __wbg_init(module_or_path?: {
40
40
  } | InitInput | Promise<InitInput>): Promise<InitOutput>;
41
41
  //#endregion
42
42
  //#region src/export.d.ts
43
+ declare module "react" {
44
+ interface DOMAttributes<T> {
45
+ tw?: string;
46
+ }
47
+ }
43
48
  /** A document input: a takumi node tree or JSX. */
44
49
  type NodeInput = Node | ReactNode | ReactElementLike;
45
50
  /** Explicit dimensions in CSS px (96 dpi). */
@@ -47,6 +52,11 @@ type Dimensions = {
47
52
  width: number;
48
53
  height: number;
49
54
  };
55
+ /** A single-page viewport. Omitting `height` sizes the page to the content. */
56
+ type ViewportInput = {
57
+ width: number;
58
+ height?: number;
59
+ };
50
60
  /** A page size: a preset name (case-insensitive) or explicit {@link Dimensions}. */
51
61
  type PageSize = "a4" | "letter" | Dimensions;
52
62
  /** A page margin in CSS px: one number for all sides, or per-side values (missing sides are zero). */
@@ -82,10 +92,12 @@ type PagedOptions = {
82
92
  };
83
93
  /**
84
94
  * Single-page output: a fixed viewport, like an image render. Percentage
85
- * heights resolve against it and overflowing content is clipped.
95
+ * heights resolve against it and overflowing content is clipped. Omitting
96
+ * `height` instead sizes the single page to the laid-out content, like a
97
+ * thermal receipt; percentage heights do not resolve there.
86
98
  */
87
99
  type ViewportOptions = {
88
- viewport: Dimensions;
100
+ viewport: ViewportInput;
89
101
  size?: never;
90
102
  landscape?: never;
91
103
  margin?: never;
@@ -121,4 +133,4 @@ declare class PdfRenderer {
121
133
  /** Renders with a lazily created shared {@link PdfRenderer}. */
122
134
  declare function render(node: NodeInput, options?: RenderOptions): Promise<Uint8Array>;
123
135
  //#endregion
124
- export { Dimensions, type FontLoader, type ImagesInput, NodeInput, PageMargin, PageSize, PdfRenderer, RenderOptions, __wbg_init as default, initSync, render };
136
+ export { Dimensions, type FontLoader, type ImagesInput, NodeInput, PageMargin, PageSize, PdfRenderer, RenderOptions, ViewportInput, __wbg_init as default, initSync, render };
package/dist/export.d.mts CHANGED
@@ -40,6 +40,11 @@ declare function __wbg_init(module_or_path?: {
40
40
  } | InitInput | Promise<InitInput>): Promise<InitOutput>;
41
41
  //#endregion
42
42
  //#region src/export.d.ts
43
+ declare module "react" {
44
+ interface DOMAttributes<T> {
45
+ tw?: string;
46
+ }
47
+ }
43
48
  /** A document input: a takumi node tree or JSX. */
44
49
  type NodeInput = Node | ReactNode | ReactElementLike;
45
50
  /** Explicit dimensions in CSS px (96 dpi). */
@@ -47,6 +52,11 @@ type Dimensions = {
47
52
  width: number;
48
53
  height: number;
49
54
  };
55
+ /** A single-page viewport. Omitting `height` sizes the page to the content. */
56
+ type ViewportInput = {
57
+ width: number;
58
+ height?: number;
59
+ };
50
60
  /** A page size: a preset name (case-insensitive) or explicit {@link Dimensions}. */
51
61
  type PageSize = "a4" | "letter" | Dimensions;
52
62
  /** A page margin in CSS px: one number for all sides, or per-side values (missing sides are zero). */
@@ -82,10 +92,12 @@ type PagedOptions = {
82
92
  };
83
93
  /**
84
94
  * Single-page output: a fixed viewport, like an image render. Percentage
85
- * heights resolve against it and overflowing content is clipped.
95
+ * heights resolve against it and overflowing content is clipped. Omitting
96
+ * `height` instead sizes the single page to the laid-out content, like a
97
+ * thermal receipt; percentage heights do not resolve there.
86
98
  */
87
99
  type ViewportOptions = {
88
- viewport: Dimensions;
100
+ viewport: ViewportInput;
89
101
  size?: never;
90
102
  landscape?: never;
91
103
  margin?: never;
@@ -121,4 +133,4 @@ declare class PdfRenderer {
121
133
  /** Renders with a lazily created shared {@link PdfRenderer}. */
122
134
  declare function render(node: NodeInput, options?: RenderOptions): Promise<Uint8Array>;
123
135
  //#endregion
124
- export { Dimensions, type FontLoader, type ImagesInput, NodeInput, PageMargin, PageSize, PdfRenderer, RenderOptions, __wbg_init as default, initSync, render };
136
+ export { Dimensions, type FontLoader, type ImagesInput, NodeInput, PageMargin, PageSize, PdfRenderer, RenderOptions, ViewportInput, __wbg_init as default, initSync, render };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "takumi-pdf",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "description": "HTML/JSX to paged, selectable-text PDF, powered by takumi. WebAssembly, no Chromium.",
5
5
  "keywords": [
6
6
  "css",
@@ -83,7 +83,7 @@
83
83
  "publish-lint": "attw --pack . && publint --strict ."
84
84
  },
85
85
  "dependencies": {
86
- "@takumi-rs/helpers": "2.5.5"
86
+ "@takumi-rs/helpers": "2.5.6"
87
87
  },
88
88
  "devDependencies": {
89
89
  "@types/bun": "^1.3.14",
Binary file