@jasy/pdf 1.0.0-alpha.1 → 1.0.0-alpha.11

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.
Files changed (279) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +35 -21
  3. package/dist/api/args.d.ts +1 -1
  4. package/dist/api/args.js +2 -5
  5. package/dist/api/color.d.ts +4 -4
  6. package/dist/api/color.js +11 -17
  7. package/dist/api/content.d.ts +20 -13
  8. package/dist/api/content.js +44 -29
  9. package/dist/api/descriptor.d.ts +2 -2
  10. package/dist/api/descriptor.js +121 -31
  11. package/dist/api/dimension.d.ts +76 -0
  12. package/dist/api/dimension.js +43 -0
  13. package/dist/api/font-url.d.ts +28 -0
  14. package/dist/api/font-url.js +134 -0
  15. package/dist/api/forms.d.ts +347 -0
  16. package/dist/api/forms.js +189 -0
  17. package/dist/api/gradient.d.ts +53 -0
  18. package/dist/api/gradient.js +97 -0
  19. package/dist/api/index.d.ts +13 -8
  20. package/dist/api/index.js +13 -24
  21. package/dist/api/insets.d.ts +19 -12
  22. package/dist/api/insets.js +19 -12
  23. package/dist/api/layout.d.ts +149 -25
  24. package/dist/api/layout.js +182 -51
  25. package/dist/api/page-builder.d.ts +40 -0
  26. package/dist/api/page-builder.js +44 -0
  27. package/dist/api/structure.d.ts +107 -13
  28. package/dist/api/structure.js +187 -88
  29. package/dist/api/table.d.ts +5 -5
  30. package/dist/api/table.js +38 -26
  31. package/dist/api/text.d.ts +90 -4
  32. package/dist/api/text.js +116 -31
  33. package/dist/assets/font-data.d.ts +2 -0
  34. package/dist/assets/font-data.js +21 -0
  35. package/dist/assets/font-data.ts +37 -0
  36. package/dist/common/color.js +1 -5
  37. package/dist/constants/page-sizes.js +3 -6
  38. package/dist/constants/pdf-parts.js +1 -4
  39. package/dist/crypto/legacy-handler.d.ts +43 -0
  40. package/dist/crypto/legacy-handler.js +145 -0
  41. package/dist/crypto/security-handler.d.ts +62 -0
  42. package/dist/crypto/security-handler.js +155 -0
  43. package/dist/crypto/webcrypto.d.ts +11 -0
  44. package/dist/crypto/webcrypto.js +62 -0
  45. package/dist/edit/acroform-reader.d.ts +70 -0
  46. package/dist/edit/acroform-reader.js +126 -0
  47. package/dist/edit/appearance.d.ts +47 -0
  48. package/dist/edit/appearance.js +171 -0
  49. package/dist/edit/document.d.ts +145 -0
  50. package/dist/edit/document.js +642 -0
  51. package/dist/edit/fill.d.ts +65 -0
  52. package/dist/edit/fill.js +424 -0
  53. package/dist/edit/flatten.d.ts +54 -0
  54. package/dist/edit/flatten.js +462 -0
  55. package/dist/edit/index.d.ts +20 -0
  56. package/dist/edit/index.js +18 -0
  57. package/dist/edit/lexer.d.ts +30 -0
  58. package/dist/edit/lexer.js +285 -0
  59. package/dist/edit/objects.d.ts +68 -0
  60. package/dist/edit/objects.js +83 -0
  61. package/dist/edit/writer.d.ts +60 -0
  62. package/dist/edit/writer.js +283 -0
  63. package/dist/elements/container-element.d.ts +50 -5
  64. package/dist/elements/container-element.js +100 -39
  65. package/dist/elements/forms/checkbox-element.d.ts +51 -0
  66. package/dist/elements/forms/checkbox-element.js +48 -0
  67. package/dist/elements/forms/choice-element.d.ts +53 -0
  68. package/dist/elements/forms/choice-element.js +59 -0
  69. package/dist/elements/forms/push-button-element.d.ts +56 -0
  70. package/dist/elements/forms/push-button-element.js +49 -0
  71. package/dist/elements/forms/radio-element.d.ts +52 -0
  72. package/dist/elements/forms/radio-element.js +49 -0
  73. package/dist/elements/forms/signature-element.d.ts +54 -0
  74. package/dist/elements/forms/signature-element.js +47 -0
  75. package/dist/elements/forms/text-field-element.d.ts +61 -0
  76. package/dist/elements/forms/text-field-element.js +54 -0
  77. package/dist/elements/image-element.d.ts +58 -6
  78. package/dist/elements/image-element.js +145 -111
  79. package/dist/elements/index.d.ts +26 -10
  80. package/dist/elements/index.js +26 -28
  81. package/dist/elements/layout/anchor-element.d.ts +23 -0
  82. package/dist/elements/layout/anchor-element.js +27 -0
  83. package/dist/elements/layout/bookmark-element.d.ts +27 -0
  84. package/dist/elements/layout/bookmark-element.js +30 -0
  85. package/dist/elements/layout/default-text-style-element.d.ts +30 -0
  86. package/dist/elements/layout/default-text-style-element.js +47 -0
  87. package/dist/elements/layout/deferred-element.d.ts +3 -3
  88. package/dist/elements/layout/deferred-element.js +4 -8
  89. package/dist/elements/layout/expanded-element.d.ts +6 -4
  90. package/dist/elements/layout/expanded-element.js +22 -17
  91. package/dist/elements/layout/keep-together-element.d.ts +42 -0
  92. package/dist/elements/layout/keep-together-element.js +85 -0
  93. package/dist/elements/layout/link-element.d.ts +33 -0
  94. package/dist/elements/layout/link-element.js +39 -0
  95. package/dist/elements/layout/padding-element.d.ts +10 -5
  96. package/dist/elements/layout/padding-element.js +25 -16
  97. package/dist/elements/layout/page-break-element.d.ts +17 -0
  98. package/dist/elements/layout/page-break-element.js +24 -0
  99. package/dist/elements/layout/page-builder-element.d.ts +32 -0
  100. package/dist/elements/layout/page-builder-element.js +45 -0
  101. package/dist/elements/layout/positioned-element.d.ts +47 -0
  102. package/dist/elements/layout/positioned-element.js +73 -0
  103. package/dist/elements/layout/repeating-header-element.d.ts +3 -3
  104. package/dist/elements/layout/repeating-header-element.js +8 -12
  105. package/dist/elements/layout/rotated-box-element.d.ts +35 -0
  106. package/dist/elements/layout/rotated-box-element.js +54 -0
  107. package/dist/elements/layout/rotated-element.d.ts +32 -0
  108. package/dist/elements/layout/rotated-element.js +41 -0
  109. package/dist/elements/layout/sized-container-element.d.ts +2 -2
  110. package/dist/elements/layout/sized-container-element.js +6 -11
  111. package/dist/elements/layout/struct-group.d.ts +28 -0
  112. package/dist/elements/layout/struct-group.js +42 -0
  113. package/dist/elements/line-element.d.ts +3 -3
  114. package/dist/elements/line-element.js +5 -10
  115. package/dist/elements/page-element.d.ts +26 -6
  116. package/dist/elements/page-element.js +72 -27
  117. package/dist/elements/pdf-document-element.d.ts +10 -4
  118. package/dist/elements/pdf-document-element.js +11 -10
  119. package/dist/elements/pdf-element.d.ts +150 -4
  120. package/dist/elements/pdf-element.js +138 -20
  121. package/dist/elements/rectangle-element.d.ts +52 -11
  122. package/dist/elements/rectangle-element.js +129 -36
  123. package/dist/elements/row-element.d.ts +45 -4
  124. package/dist/elements/row-element.js +66 -18
  125. package/dist/elements/text-element.d.ts +139 -11
  126. package/dist/elements/text-element.js +234 -57
  127. package/dist/forms/acroform.d.ts +63 -0
  128. package/dist/forms/acroform.js +427 -0
  129. package/dist/forms/appearance.d.ts +58 -0
  130. package/dist/forms/appearance.js +204 -0
  131. package/dist/forms/field.d.ts +164 -0
  132. package/dist/forms/field.js +1 -0
  133. package/dist/forms/pdf.d.ts +19 -0
  134. package/dist/forms/pdf.js +28 -0
  135. package/dist/index.d.ts +3 -3
  136. package/dist/index.js +3 -19
  137. package/dist/ir/display-list.d.ts +197 -8
  138. package/dist/ir/display-list.js +8 -2
  139. package/dist/layout/alignment.d.ts +10 -0
  140. package/dist/layout/alignment.js +6 -0
  141. package/dist/layout/box-constraints.d.ts +61 -0
  142. package/dist/layout/box-constraints.js +88 -6
  143. package/dist/layout/collect-images.d.ts +9 -0
  144. package/dist/layout/collect-images.js +34 -0
  145. package/dist/layout/fragmentation.d.ts +20 -1
  146. package/dist/layout/fragmentation.js +74 -18
  147. package/dist/layout/insets.d.ts +28 -0
  148. package/dist/layout/insets.js +20 -0
  149. package/dist/platform/browser-fs.d.ts +2 -0
  150. package/dist/platform/browser-fs.js +9 -0
  151. package/dist/platform/browser-image.d.ts +5 -0
  152. package/dist/platform/browser-image.js +13 -0
  153. package/dist/platform/node-fs.d.ts +2 -0
  154. package/dist/platform/node-fs.js +10 -0
  155. package/dist/platform/node-image.d.ts +5 -0
  156. package/dist/platform/node-image.js +9 -0
  157. package/dist/renderer/anchor-renderer.d.ts +6 -0
  158. package/dist/renderer/anchor-renderer.js +11 -0
  159. package/dist/renderer/bookmark-renderer.d.ts +6 -0
  160. package/dist/renderer/bookmark-renderer.js +11 -0
  161. package/dist/renderer/container-renderer.d.ts +3 -3
  162. package/dist/renderer/container-renderer.js +11 -28
  163. package/dist/renderer/default-text-style-renderer.d.ts +6 -0
  164. package/dist/renderer/default-text-style-renderer.js +10 -0
  165. package/dist/renderer/deferred-renderer.d.ts +3 -3
  166. package/dist/renderer/deferred-renderer.js +8 -23
  167. package/dist/renderer/emoji-image.d.ts +9 -0
  168. package/dist/renderer/emoji-image.js +68 -0
  169. package/dist/renderer/expanded-renderer.d.ts +3 -3
  170. package/dist/renderer/expanded-renderer.js +6 -21
  171. package/dist/renderer/form-field-renderer.d.ts +20 -0
  172. package/dist/renderer/form-field-renderer.js +12 -0
  173. package/dist/renderer/image-renderer.d.ts +4 -4
  174. package/dist/renderer/image-renderer.js +86 -75
  175. package/dist/renderer/index.d.ts +10 -10
  176. package/dist/renderer/index.js +10 -26
  177. package/dist/renderer/keep-together-renderer.d.ts +10 -0
  178. package/dist/renderer/keep-together-renderer.js +12 -0
  179. package/dist/renderer/line-renderer.d.ts +3 -3
  180. package/dist/renderer/line-renderer.js +13 -28
  181. package/dist/renderer/link-renderer.d.ts +6 -0
  182. package/dist/renderer/link-renderer.js +11 -0
  183. package/dist/renderer/padding-renderer.d.ts +3 -3
  184. package/dist/renderer/padding-renderer.js +6 -21
  185. package/dist/renderer/page-break-renderer.d.ts +14 -0
  186. package/dist/renderer/page-break-renderer.js +15 -0
  187. package/dist/renderer/page-builder-renderer.d.ts +6 -0
  188. package/dist/renderer/page-builder-renderer.js +11 -0
  189. package/dist/renderer/page-renderer.d.ts +2 -2
  190. package/dist/renderer/page-renderer.js +115 -77
  191. package/dist/renderer/pdf-backend.d.ts +31 -4
  192. package/dist/renderer/pdf-backend.js +287 -49
  193. package/dist/renderer/pdf-config.js +4 -7
  194. package/dist/renderer/pdf-document-class.d.ts +5 -5
  195. package/dist/renderer/pdf-document-class.js +27 -41
  196. package/dist/renderer/pdf-document-renderer.d.ts +19 -10
  197. package/dist/renderer/pdf-document-renderer.js +135 -91
  198. package/dist/renderer/pdf-renderer.d.ts +2 -2
  199. package/dist/renderer/pdf-renderer.js +165 -90
  200. package/dist/renderer/positioned-renderer.d.ts +6 -0
  201. package/dist/renderer/positioned-renderer.js +10 -0
  202. package/dist/renderer/rectangle-renderer.d.ts +3 -3
  203. package/dist/renderer/rectangle-renderer.js +49 -44
  204. package/dist/renderer/repeating-header-renderer.d.ts +3 -3
  205. package/dist/renderer/repeating-header-renderer.js +10 -26
  206. package/dist/renderer/rotated-renderer.d.ts +7 -0
  207. package/dist/renderer/rotated-renderer.js +29 -0
  208. package/dist/renderer/row-renderer.d.ts +3 -3
  209. package/dist/renderer/row-renderer.js +11 -28
  210. package/dist/renderer/struct-group-renderer.d.ts +10 -0
  211. package/dist/renderer/struct-group-renderer.js +24 -0
  212. package/dist/renderer/text-renderer.d.ts +9 -5
  213. package/dist/renderer/text-renderer.js +437 -89
  214. package/dist/text/advance.d.ts +34 -0
  215. package/dist/text/advance.js +45 -0
  216. package/dist/text/arabic.d.ts +20 -0
  217. package/dist/text/arabic.js +101 -0
  218. package/dist/text/bidi.d.ts +33 -0
  219. package/dist/text/bidi.js +94 -0
  220. package/dist/text/emoji-codepoints.d.ts +1 -0
  221. package/dist/text/emoji-codepoints.js +29 -0
  222. package/dist/text/font-fallback.d.ts +25 -0
  223. package/dist/text/font-fallback.js +38 -0
  224. package/dist/text/glyph-coverage.d.ts +15 -0
  225. package/dist/text/glyph-coverage.js +77 -0
  226. package/dist/text/line-breaker.d.ts +50 -12
  227. package/dist/text/line-breaker.js +200 -54
  228. package/dist/text/line-metrics.d.ts +49 -0
  229. package/dist/text/line-metrics.js +57 -0
  230. package/dist/text/orphans-widows.d.ts +27 -0
  231. package/dist/text/orphans-widows.js +53 -0
  232. package/dist/text/shape.d.ts +29 -0
  233. package/dist/text/shape.js +67 -0
  234. package/dist/text/text-decoration.d.ts +50 -0
  235. package/dist/text/text-decoration.js +62 -0
  236. package/dist/text/text-style.d.ts +60 -0
  237. package/dist/text/text-style.js +79 -0
  238. package/dist/text/whitespace.d.ts +4 -0
  239. package/dist/text/whitespace.js +43 -0
  240. package/dist/utils/afm-parser.d.ts +34 -0
  241. package/dist/utils/afm-parser.js +76 -17
  242. package/dist/utils/bytes.d.ts +24 -0
  243. package/dist/utils/bytes.js +76 -0
  244. package/dist/utils/dest-registry.d.ts +22 -0
  245. package/dist/utils/dest-registry.js +32 -0
  246. package/dist/utils/flex-layout.d.ts +36 -9
  247. package/dist/utils/flex-layout.js +207 -30
  248. package/dist/utils/font-metrics.d.ts +26 -1
  249. package/dist/utils/font-metrics.js +1 -2
  250. package/dist/utils/font-path.js +3 -6
  251. package/dist/utils/gsub.d.ts +36 -0
  252. package/dist/utils/gsub.js +178 -0
  253. package/dist/utils/image-helper.d.ts +6 -5
  254. package/dist/utils/image-helper.js +101 -111
  255. package/dist/utils/inflate.d.ts +16 -0
  256. package/dist/utils/inflate.js +52 -0
  257. package/dist/utils/md5.d.ts +4 -0
  258. package/dist/utils/md5.js +79 -0
  259. package/dist/utils/outline.d.ts +21 -0
  260. package/dist/utils/outline.js +79 -0
  261. package/dist/utils/pdf-object-manager.d.ts +127 -8
  262. package/dist/utils/pdf-object-manager.js +615 -141
  263. package/dist/utils/renderer-registry.d.ts +13 -1
  264. package/dist/utils/renderer-registry.js +23 -6
  265. package/dist/utils/struct-tree.d.ts +44 -0
  266. package/dist/utils/struct-tree.js +129 -0
  267. package/dist/utils/ttf-parser.d.ts +134 -2
  268. package/dist/utils/ttf-parser.js +873 -50
  269. package/dist/utils/ttf-subsetter.d.ts +1 -1
  270. package/dist/utils/ttf-subsetter.js +40 -42
  271. package/dist/utils/ua-xmp.d.ts +9 -0
  272. package/dist/utils/ua-xmp.js +32 -0
  273. package/dist/utils/utf8-to-windows1252-encoder.d.ts +6 -0
  274. package/dist/utils/utf8-to-windows1252-encoder.js +11 -4
  275. package/dist/utils/woff.d.ts +10 -0
  276. package/dist/utils/woff.js +116 -0
  277. package/dist/validators/element-validator.d.ts +2 -2
  278. package/dist/validators/element-validator.js +31 -26
  279. package/package.json +22 -2
@@ -0,0 +1,53 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { BoxConstraints, Offset, Size } from "../../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "../pdf-element.js";
4
+ import type { ChoiceOption, ChoiceSpec, FieldAlign, FieldStyle } from "../../forms/field.js";
5
+ export interface ChoiceParams {
6
+ name: string;
7
+ options: ChoiceOption[];
8
+ /** `true` = dropdown (combo box), `false` = list box. */
9
+ combo: boolean;
10
+ editable?: boolean;
11
+ multiSelect?: boolean;
12
+ value?: string;
13
+ values?: string[];
14
+ tooltip?: string;
15
+ readOnly?: boolean;
16
+ /** How the value sits in the box (default left). */
17
+ align?: FieldAlign;
18
+ /** Mark it as a field that must be filled in before submitting. */
19
+ required?: boolean;
20
+ /** Hide the widget entirely - neither on screen nor in print. */
21
+ hidden?: boolean;
22
+ /** Include the widget when printing (default true). */
23
+ print?: boolean;
24
+ /** Box width; omit to fill the offered width. */
25
+ width?: number;
26
+ /** Box height; omit for a single-line default (dropdown) / a few rows (list box). */
27
+ height?: number;
28
+ fontSize?: number;
29
+ color?: Color;
30
+ border?: Color;
31
+ background?: Color;
32
+ borderWidth?: number;
33
+ }
34
+ /**
35
+ * A choice field (AcroForm /Ch) - a dropdown or a list box, chosen by `combo`. A leaf that draws nothing
36
+ * itself: it reserves its box and emits a `formfield` IR node. The selected value is rendered by the
37
+ * viewer via /NeedAppearances (Step 1); Step 4 bakes its /AP.
38
+ */
39
+ export declare class ChoiceElement extends SizedPDFElement {
40
+ private spec;
41
+ private style;
42
+ private requested;
43
+ constructor(p: ChoiceParams);
44
+ calculateLayout(constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
45
+ getProps(): {
46
+ x: number;
47
+ y: number;
48
+ width: number;
49
+ height: number;
50
+ spec: ChoiceSpec;
51
+ style: FieldStyle;
52
+ };
53
+ }
@@ -0,0 +1,59 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { SizedPDFElement } from "../pdf-element.js";
3
+ /**
4
+ * A choice field (AcroForm /Ch) - a dropdown or a list box, chosen by `combo`. A leaf that draws nothing
5
+ * itself: it reserves its box and emits a `formfield` IR node. The selected value is rendered by the
6
+ * viewer via /NeedAppearances (Step 1); Step 4 bakes its /AP.
7
+ */
8
+ export class ChoiceElement extends SizedPDFElement {
9
+ constructor(p) {
10
+ super({ x: 0, y: 0, width: p.width, height: p.height });
11
+ const fontSize = p.fontSize ?? 12;
12
+ this.spec = {
13
+ kind: "choice",
14
+ name: p.name,
15
+ options: p.options,
16
+ combo: p.combo,
17
+ editable: p.editable,
18
+ multiSelect: p.multiSelect,
19
+ value: p.value,
20
+ values: p.values,
21
+ tooltip: p.tooltip,
22
+ readOnly: p.readOnly,
23
+ align: p.align,
24
+ required: p.required,
25
+ hidden: p.hidden,
26
+ print: p.print,
27
+ };
28
+ this.style = {
29
+ border: p.border ?? new Color(154, 164, 178),
30
+ background: p.background,
31
+ color: p.color ?? new Color(0, 0, 0),
32
+ fontSize,
33
+ borderWidth: p.borderWidth ?? 1,
34
+ };
35
+ this.requested = { width: p.width, height: p.height, fontSize, combo: p.combo };
36
+ }
37
+ calculateLayout(constraints, offset, _ctx) {
38
+ this.x = offset.x;
39
+ this.y = offset.y;
40
+ this.width = this.requested.width ?? (constraints.hasBoundedWidth ? constraints.maxWidth : 200);
41
+ // Dropdown: one line. List box: a few rows tall so several options are visible.
42
+ const oneLine = this.requested.fontSize + 9;
43
+ const rows = Math.max(3, Math.min(this.spec.options.length, 5));
44
+ this.height =
45
+ this.requested.height ??
46
+ (this.requested.combo ? oneLine : rows * (this.requested.fontSize + 4));
47
+ return { width: this.width, height: this.height };
48
+ }
49
+ getProps() {
50
+ return {
51
+ x: this.x,
52
+ y: this.y,
53
+ width: this.width ?? 0,
54
+ height: this.height ?? 0,
55
+ spec: this.spec,
56
+ style: this.style,
57
+ };
58
+ }
59
+ }
@@ -0,0 +1,56 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { BoxConstraints, Offset, Size } from "../../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "../pdf-element.js";
4
+ import type { ButtonAction, FieldStyle, PushButtonSpec } from "../../forms/field.js";
5
+ export interface PushButtonParams {
6
+ /** The field name (/T) - unique in the document. */
7
+ name: string;
8
+ /** The caption drawn on the button. */
9
+ label: string;
10
+ /** What clicking it does; omit for a button that does nothing. */
11
+ action?: ButtonAction;
12
+ /** Tooltip / accessible name. */
13
+ tooltip?: string;
14
+ /** Draw it but do not let it be clicked. */
15
+ readOnly?: boolean;
16
+ /** Mark it as a field that must be filled in before submitting. */
17
+ required?: boolean;
18
+ /** Hide the widget entirely - neither on screen nor in print. */
19
+ hidden?: boolean;
20
+ /** Include the widget when printing (default true). */
21
+ print?: boolean;
22
+ /** Button width in points; omit to fill the offered width. */
23
+ width?: number;
24
+ /** Button height in points; omit for a comfortable default. */
25
+ height?: number;
26
+ /** Caption font size (default 12). */
27
+ fontSize?: number;
28
+ /** Caption colour (default black). */
29
+ color?: Color;
30
+ /** Border colour (default a mid grey). */
31
+ border?: Color;
32
+ /** Button face fill (default a light grey, so it reads as a button). */
33
+ background?: Color;
34
+ /** Border thickness (default 1). */
35
+ borderWidth?: number;
36
+ }
37
+ /**
38
+ * A push button (AcroForm /Btn, Pushbutton flag). Holds no value - it fires an action. Draws nothing
39
+ * itself: it reserves its box and emits a `formfield` IR node whose caption is baked into an /AP at the
40
+ * seam, so the button looks identical in every viewer and in print.
41
+ */
42
+ export declare class PushButtonElement extends SizedPDFElement {
43
+ private spec;
44
+ private style;
45
+ private requested;
46
+ constructor(p: PushButtonParams);
47
+ calculateLayout(constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
48
+ getProps(): {
49
+ x: number;
50
+ y: number;
51
+ width: number;
52
+ height: number;
53
+ spec: PushButtonSpec;
54
+ style: FieldStyle;
55
+ };
56
+ }
@@ -0,0 +1,49 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { SizedPDFElement } from "../pdf-element.js";
3
+ /**
4
+ * A push button (AcroForm /Btn, Pushbutton flag). Holds no value - it fires an action. Draws nothing
5
+ * itself: it reserves its box and emits a `formfield` IR node whose caption is baked into an /AP at the
6
+ * seam, so the button looks identical in every viewer and in print.
7
+ */
8
+ export class PushButtonElement extends SizedPDFElement {
9
+ constructor(p) {
10
+ super({ x: 0, y: 0, width: p.width, height: p.height });
11
+ const fontSize = p.fontSize ?? 12;
12
+ this.spec = {
13
+ kind: "pushbutton",
14
+ name: p.name,
15
+ label: p.label,
16
+ action: p.action,
17
+ tooltip: p.tooltip,
18
+ readOnly: p.readOnly,
19
+ required: p.required,
20
+ hidden: p.hidden,
21
+ print: p.print,
22
+ };
23
+ this.style = {
24
+ border: p.border ?? new Color(154, 164, 178),
25
+ background: p.background ?? new Color(238, 240, 245),
26
+ color: p.color ?? new Color(0, 0, 0),
27
+ fontSize,
28
+ borderWidth: p.borderWidth ?? 1,
29
+ };
30
+ this.requested = { width: p.width, height: p.height, fontSize };
31
+ }
32
+ calculateLayout(constraints, offset, _ctx) {
33
+ this.x = offset.x;
34
+ this.y = offset.y;
35
+ this.width = this.requested.width ?? (constraints.hasBoundedWidth ? constraints.maxWidth : 120);
36
+ this.height = this.requested.height ?? this.requested.fontSize + 14;
37
+ return { width: this.width, height: this.height };
38
+ }
39
+ getProps() {
40
+ return {
41
+ x: this.x,
42
+ y: this.y,
43
+ width: this.width ?? 0,
44
+ height: this.height ?? 0,
45
+ spec: this.spec,
46
+ style: this.style,
47
+ };
48
+ }
49
+ }
@@ -0,0 +1,52 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { BoxConstraints, Offset, Size } from "../../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "../pdf-element.js";
4
+ import type { FieldStyle, RadioSpec } from "../../forms/field.js";
5
+ export interface RadioParams {
6
+ /** The shared group name - radios with the same `group` are one mutually-exclusive field. */
7
+ group: string;
8
+ /** This button's export value - unique within the group. */
9
+ value: string;
10
+ /** Whether this button starts selected (at most one per group should be). */
11
+ selected?: boolean;
12
+ /** Tooltip / accessible name. */
13
+ tooltip?: string;
14
+ /** Show but do not allow changing the group. */
15
+ readOnly?: boolean;
16
+ /** Mark it as a field that must be filled in before submitting. */
17
+ required?: boolean;
18
+ /** Hide the widget entirely - neither on screen nor in print. */
19
+ hidden?: boolean;
20
+ /** Include the widget when printing (default true). */
21
+ print?: boolean;
22
+ /** Button diameter in points (default 14). */
23
+ size?: number;
24
+ /** Dot colour (default black). */
25
+ color?: Color;
26
+ /** Ring colour (default a mid grey). */
27
+ border?: Color;
28
+ /** Fill behind the ring. */
29
+ background?: Color;
30
+ /** Ring thickness (default 1). */
31
+ borderWidth?: number;
32
+ }
33
+ /**
34
+ * One radio button (AcroForm /Btn, Radio flag). A small round leaf; several sharing a `group` become one
35
+ * mutually-exclusive field (see `RadioGroup` for the ergonomic wrapper). Draws nothing itself - it emits a
36
+ * `formfield` IR node whose radio spec bakes the ring + dot /AP at the seam.
37
+ */
38
+ export declare class RadioElement extends SizedPDFElement {
39
+ private spec;
40
+ private style;
41
+ private size;
42
+ constructor(p: RadioParams);
43
+ calculateLayout(_constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
44
+ getProps(): {
45
+ x: number;
46
+ y: number;
47
+ width: number;
48
+ height: number;
49
+ spec: RadioSpec;
50
+ style: FieldStyle;
51
+ };
52
+ }
@@ -0,0 +1,49 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { SizedPDFElement } from "../pdf-element.js";
3
+ /**
4
+ * One radio button (AcroForm /Btn, Radio flag). A small round leaf; several sharing a `group` become one
5
+ * mutually-exclusive field (see `RadioGroup` for the ergonomic wrapper). Draws nothing itself - it emits a
6
+ * `formfield` IR node whose radio spec bakes the ring + dot /AP at the seam.
7
+ */
8
+ export class RadioElement extends SizedPDFElement {
9
+ constructor(p) {
10
+ const size = p.size ?? 14;
11
+ super({ x: 0, y: 0, width: size, height: size });
12
+ this.size = size;
13
+ this.spec = {
14
+ kind: "radio",
15
+ group: p.group,
16
+ value: p.value,
17
+ selected: p.selected,
18
+ tooltip: p.tooltip,
19
+ readOnly: p.readOnly,
20
+ required: p.required,
21
+ hidden: p.hidden,
22
+ print: p.print,
23
+ };
24
+ this.style = {
25
+ border: p.border ?? new Color(102, 102, 102),
26
+ background: p.background,
27
+ color: p.color ?? new Color(0, 0, 0),
28
+ fontSize: 0,
29
+ borderWidth: p.borderWidth ?? 1,
30
+ };
31
+ }
32
+ calculateLayout(_constraints, offset, _ctx) {
33
+ this.x = offset.x;
34
+ this.y = offset.y;
35
+ this.width = this.size;
36
+ this.height = this.size;
37
+ return { width: this.size, height: this.size };
38
+ }
39
+ getProps() {
40
+ return {
41
+ x: this.x,
42
+ y: this.y,
43
+ width: this.width ?? 0,
44
+ height: this.height ?? 0,
45
+ spec: this.spec,
46
+ style: this.style,
47
+ };
48
+ }
49
+ }
@@ -0,0 +1,54 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { BoxConstraints, Offset, Size } from "../../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "../pdf-element.js";
4
+ import type { FieldStyle, SignatureSpec } from "../../forms/field.js";
5
+ export interface SignatureFieldParams {
6
+ /** The field name (/T) - unique in the document. */
7
+ name: string;
8
+ /** A hint drawn inside the empty box, e.g. "Signature". */
9
+ label?: string;
10
+ /** Tooltip / accessible name. */
11
+ tooltip?: string;
12
+ /** Draw it but do not let it be signed. */
13
+ readOnly?: boolean;
14
+ /** Mark it as a field that must be filled in before submitting. */
15
+ required?: boolean;
16
+ /** Hide the widget entirely - neither on screen nor in print. */
17
+ hidden?: boolean;
18
+ /** Include the widget when printing (default true). */
19
+ print?: boolean;
20
+ /** Box width in points; omit to fill the offered width. */
21
+ width?: number;
22
+ /** Box height in points (default 48 - room for a signature). */
23
+ height?: number;
24
+ /** Hint font size (default 9). */
25
+ fontSize?: number;
26
+ /** Hint colour (default a muted grey). */
27
+ color?: Color;
28
+ /** Box border + signing-rule colour (default a mid grey). */
29
+ border?: Color;
30
+ /** Box background fill. */
31
+ background?: Color;
32
+ /** Border thickness (default 1). */
33
+ borderWidth?: number;
34
+ }
35
+ /**
36
+ * A signature field (AcroForm /Sig) - a PLACEHOLDER someone can sign later. jasy creates the field and
37
+ * its empty "sign here" appearance; it does not sign (that needs a certificate and a byte-range digest -
38
+ * a separate feature). Draws nothing itself: it reserves its box and emits a `formfield` IR node.
39
+ */
40
+ export declare class SignatureFieldElement extends SizedPDFElement {
41
+ private spec;
42
+ private style;
43
+ private requested;
44
+ constructor(p: SignatureFieldParams);
45
+ calculateLayout(constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
46
+ getProps(): {
47
+ x: number;
48
+ y: number;
49
+ width: number;
50
+ height: number;
51
+ spec: SignatureSpec;
52
+ style: FieldStyle;
53
+ };
54
+ }
@@ -0,0 +1,47 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { SizedPDFElement } from "../pdf-element.js";
3
+ /**
4
+ * A signature field (AcroForm /Sig) - a PLACEHOLDER someone can sign later. jasy creates the field and
5
+ * its empty "sign here" appearance; it does not sign (that needs a certificate and a byte-range digest -
6
+ * a separate feature). Draws nothing itself: it reserves its box and emits a `formfield` IR node.
7
+ */
8
+ export class SignatureFieldElement extends SizedPDFElement {
9
+ constructor(p) {
10
+ super({ x: 0, y: 0, width: p.width, height: p.height });
11
+ this.spec = {
12
+ kind: "signature",
13
+ name: p.name,
14
+ label: p.label,
15
+ tooltip: p.tooltip,
16
+ readOnly: p.readOnly,
17
+ required: p.required,
18
+ hidden: p.hidden,
19
+ print: p.print,
20
+ };
21
+ this.style = {
22
+ border: p.border ?? new Color(154, 164, 178),
23
+ background: p.background,
24
+ color: p.color ?? new Color(107, 114, 128),
25
+ fontSize: p.fontSize ?? 9,
26
+ borderWidth: p.borderWidth ?? 1,
27
+ };
28
+ this.requested = { width: p.width, height: p.height };
29
+ }
30
+ calculateLayout(constraints, offset, _ctx) {
31
+ this.x = offset.x;
32
+ this.y = offset.y;
33
+ this.width = this.requested.width ?? (constraints.hasBoundedWidth ? constraints.maxWidth : 240);
34
+ this.height = this.requested.height ?? 48;
35
+ return { width: this.width, height: this.height };
36
+ }
37
+ getProps() {
38
+ return {
39
+ x: this.x,
40
+ y: this.y,
41
+ width: this.width ?? 0,
42
+ height: this.height ?? 0,
43
+ spec: this.spec,
44
+ style: this.style,
45
+ };
46
+ }
47
+ }
@@ -0,0 +1,61 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { BoxConstraints, Offset, Size } from "../../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "../pdf-element.js";
4
+ import type { FieldAlign, FieldStyle, TextFieldSpec } from "../../forms/field.js";
5
+ export interface TextFieldParams {
6
+ /** The field name (/T) - unique in the document; you read the value back by it. */
7
+ name: string;
8
+ /** Initial value (/V). */
9
+ value?: string;
10
+ /** Tooltip / accessible name (/TU). */
11
+ tooltip?: string;
12
+ /** Wrap across lines instead of one line. */
13
+ multiline?: boolean;
14
+ /** Mask the input. */
15
+ password?: boolean;
16
+ /** Maximum character count. */
17
+ maxLength?: number;
18
+ /** Show but do not allow editing. */
19
+ readOnly?: boolean;
20
+ /** How the value sits in the box (default left). */
21
+ align?: FieldAlign;
22
+ /** Mark it as a field that must be filled in before submitting. */
23
+ required?: boolean;
24
+ /** Hide the widget entirely - neither on screen nor in print. */
25
+ hidden?: boolean;
26
+ /** Include the widget when printing (default true). */
27
+ print?: boolean;
28
+ /** Box width in points; omit to fill the offered width. */
29
+ width?: number;
30
+ /** Box height in points; omit for a single-line default (`multiline` wants an explicit height). */
31
+ height?: number;
32
+ /** Value font size; `0` = viewer auto-size. */
33
+ fontSize?: number;
34
+ /** Value text colour. */
35
+ color?: Color;
36
+ /** Box border colour (omit for no border). */
37
+ border?: Color;
38
+ /** Box background fill (omit for transparent). */
39
+ background?: Color;
40
+ /** Border thickness in points. */
41
+ borderWidth?: number;
42
+ }
43
+ /**
44
+ * A text input field (AcroForm /Tx). A leaf that draws NOTHING itself: it reserves its box in the layout
45
+ * and emits a `formfield` IR node that becomes a Widget annotation + /AcroForm field at the seam.
46
+ */
47
+ export declare class TextFieldElement extends SizedPDFElement {
48
+ private spec;
49
+ private style;
50
+ private requested;
51
+ constructor(p: TextFieldParams);
52
+ calculateLayout(constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
53
+ getProps(): {
54
+ x: number;
55
+ y: number;
56
+ width: number;
57
+ height: number;
58
+ spec: TextFieldSpec;
59
+ style: FieldStyle;
60
+ };
61
+ }
@@ -0,0 +1,54 @@
1
+ import { Color } from "../../common/color.js";
2
+ import { SizedPDFElement } from "../pdf-element.js";
3
+ /**
4
+ * A text input field (AcroForm /Tx). A leaf that draws NOTHING itself: it reserves its box in the layout
5
+ * and emits a `formfield` IR node that becomes a Widget annotation + /AcroForm field at the seam.
6
+ */
7
+ export class TextFieldElement extends SizedPDFElement {
8
+ constructor(p) {
9
+ super({ x: 0, y: 0, width: p.width, height: p.height });
10
+ const fontSize = p.fontSize ?? 12;
11
+ this.spec = {
12
+ kind: "text",
13
+ name: p.name,
14
+ value: p.value,
15
+ tooltip: p.tooltip,
16
+ multiline: p.multiline,
17
+ password: p.password,
18
+ maxLength: p.maxLength,
19
+ readOnly: p.readOnly,
20
+ align: p.align,
21
+ required: p.required,
22
+ hidden: p.hidden,
23
+ print: p.print,
24
+ };
25
+ this.style = {
26
+ border: p.border,
27
+ background: p.background,
28
+ color: p.color ?? new Color(0, 0, 0),
29
+ fontSize,
30
+ borderWidth: p.borderWidth ?? 1,
31
+ };
32
+ this.requested = { width: p.width, height: p.height, fontSize };
33
+ }
34
+ calculateLayout(constraints, offset, _ctx) {
35
+ this.x = offset.x;
36
+ this.y = offset.y;
37
+ // Width: explicit, else fill the offered box (a form field with no width spans the column).
38
+ this.width = this.requested.width ?? (constraints.hasBoundedWidth ? constraints.maxWidth : 200);
39
+ // Height: explicit, else a comfortable single line (font size + padding). Multiline without an
40
+ // explicit height still gets the single-line default - the caller should size a multiline box.
41
+ this.height = this.requested.height ?? this.requested.fontSize + 9;
42
+ return { width: this.width, height: this.height };
43
+ }
44
+ getProps() {
45
+ return {
46
+ x: this.x,
47
+ y: this.y,
48
+ width: this.width ?? 0,
49
+ height: this.height ?? 0,
50
+ spec: this.spec,
51
+ style: this.style,
52
+ };
53
+ }
54
+ }
@@ -1,5 +1,6 @@
1
- import { BoxConstraints, Offset, Size } from "../layout/box-constraints";
2
- import { LayoutContext, SizedPDFElement } from "./pdf-element";
1
+ import type { Radii } from "../ir/display-list.js";
2
+ import { BoxConstraints, Offset, Size } from "../layout/box-constraints.js";
3
+ import { LayoutContext, SizedPDFElement } from "./pdf-element.js";
3
4
  export declare enum BoxFit {
4
5
  none = "NONE",
5
6
  contain = "CONTAIN",
@@ -19,6 +20,7 @@ export declare class CustomLocalImage extends CustomImage {
19
20
  private imagePath;
20
21
  private fileBuffer;
21
22
  private fileRawData;
23
+ private dims?;
22
24
  constructor(imagePath: string);
23
25
  init(): Promise<void>;
24
26
  getImageType(): Promise<string>;
@@ -29,19 +31,68 @@ export declare class CustomLocalImage extends CustomImage {
29
31
  height: number;
30
32
  }>;
31
33
  }
34
+ /**
35
+ * An image straight from raw bytes (a browser upload / fetch, no filesystem). The PDF filter is sniffed
36
+ * from the magic bytes: JPEG embeds raw (DCTDecode, no decode step), PNG is decoded to RGB (FlateDecode).
37
+ */
38
+ export declare class CustomBytesImage extends CustomImage {
39
+ private bytes;
40
+ private fileRawData;
41
+ private dims?;
42
+ constructor(bytes: Uint8Array);
43
+ init(): Promise<void>;
44
+ getImageType(): Promise<string>;
45
+ getFileData(): string;
46
+ getImageDimensions(): Promise<{
47
+ width: number;
48
+ height: number;
49
+ }>;
50
+ }
32
51
  interface ImageElementParams {
33
52
  image: CustomImage;
34
53
  width?: number;
35
54
  height?: number;
55
+ /** Width as a fraction (0..1) of the offered width instead of a fixed `width` (relative sizing). */
56
+ widthFactor?: number;
57
+ /** Height as a fraction (0..1) of the offered height; see `widthFactor`. */
58
+ heightFactor?: number;
59
+ /** Lower / upper bounds per axis, in points or as a fraction; see `SizingParams`. */
60
+ minWidth?: number;
61
+ maxWidth?: number;
62
+ minHeight?: number;
63
+ maxHeight?: number;
64
+ minWidthFactor?: number;
65
+ maxWidthFactor?: number;
66
+ minHeightFactor?: number;
67
+ maxHeightFactor?: number;
68
+ /** width / height; overrides the image's OWN ratio (CSS `aspect-ratio`), `fit` then places it. */
69
+ aspectRatio?: number;
36
70
  fit?: BoxFit;
37
- /** Corner radius in points; rounds the image box (0 = sharp, default). */
38
- radius?: number;
71
+ /** Corner radius in points - one number or per corner; rounds the image box (0 = sharp, default). */
72
+ radius?: number | Radii;
73
+ /** Alternate text for accessibility (tagged PDF). With `alt` the image is a Figure; without, decoration. */
74
+ alt?: string;
39
75
  }
40
76
  export declare class ImageElement extends SizedPDFElement {
41
77
  private image;
78
+ private widthFactor?;
79
+ private heightFactor?;
42
80
  private fit;
43
81
  private radius;
44
- constructor({ image, width, height, fit, radius }: ImageElementParams);
82
+ private readonly alt?;
83
+ private requested;
84
+ /** min/max/aspectRatio, kept as given so every layout pass re-resolves them. */
85
+ private sizing;
86
+ private intrinsic?;
87
+ constructor({ image, width, height, widthFactor, heightFactor, fit, radius, alt, ...sizing }: ImageElementParams);
88
+ /**
89
+ * Loads the image and records its intrinsic pixel size. Runs in the async pre-layout pass (layout
90
+ * itself is synchronous and cannot await jimp) so `calculateLayout` can turn a width-only image
91
+ * into a proportional box. Best-effort: a load failure leaves the size unresolved (the renderer
92
+ * surfaces the real error) and the image just keeps whatever explicit size it was given.
93
+ */
94
+ resolveIntrinsicSize(): Promise<void>;
95
+ relativeSizeFactor(horizontal: boolean): number | undefined;
45
96
  calculateLayout(constraints: BoxConstraints, offset: Offset, _ctx: LayoutContext): Size;
46
97
  getProps(): {
47
98
  x: number;
@@ -50,7 +101,8 @@ export declare class ImageElement extends SizedPDFElement {
50
101
  height: number | undefined;
51
102
  image: CustomImage;
52
103
  fit: BoxFit;
53
- radius: number;
104
+ radius: number | Radii;
105
+ alt: string | undefined;
54
106
  };
55
107
  }
56
108
  export {};