@tectra-ng/ui 0.4.3 → 0.4.5

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 (233) hide show
  1. package/amount/README.md +19 -1
  2. package/analog-clock/README.md +1 -1
  3. package/autocomplete/README.md +1 -1
  4. package/avatar/README.md +24 -4
  5. package/cascade-select/README.md +1 -1
  6. package/chips-input/README.md +10 -5
  7. package/color-picker/README.md +5 -0
  8. package/countdown/README.md +7 -1
  9. package/country/README.md +14 -1
  10. package/country-select/README.md +2 -1
  11. package/export/README.md +27 -2
  12. package/export-font/README.md +1 -1
  13. package/fesm2022/tectra-ng-ui-accordion.mjs +21 -21
  14. package/fesm2022/tectra-ng-ui-amount.mjs +99 -17
  15. package/fesm2022/tectra-ng-ui-amount.mjs.map +1 -1
  16. package/fesm2022/tectra-ng-ui-analog-clock.mjs +12 -25
  17. package/fesm2022/tectra-ng-ui-analog-clock.mjs.map +1 -1
  18. package/fesm2022/tectra-ng-ui-autocomplete.mjs +8 -7
  19. package/fesm2022/tectra-ng-ui-autocomplete.mjs.map +1 -1
  20. package/fesm2022/tectra-ng-ui-avatar.mjs +68 -26
  21. package/fesm2022/tectra-ng-ui-avatar.mjs.map +1 -1
  22. package/fesm2022/tectra-ng-ui-badge.mjs +3 -3
  23. package/fesm2022/tectra-ng-ui-breadcrumb.mjs +9 -9
  24. package/fesm2022/tectra-ng-ui-button-group.mjs +3 -3
  25. package/fesm2022/tectra-ng-ui-button.mjs +11 -11
  26. package/fesm2022/tectra-ng-ui-button.mjs.map +1 -1
  27. package/fesm2022/tectra-ng-ui-card.mjs +5 -5
  28. package/fesm2022/tectra-ng-ui-card.mjs.map +1 -1
  29. package/fesm2022/tectra-ng-ui-carousel.mjs +15 -15
  30. package/fesm2022/tectra-ng-ui-cascade-select.mjs +10 -7
  31. package/fesm2022/tectra-ng-ui-cascade-select.mjs.map +1 -1
  32. package/fesm2022/tectra-ng-ui-checkbox.mjs +9 -9
  33. package/fesm2022/tectra-ng-ui-chip.mjs +3 -3
  34. package/fesm2022/tectra-ng-ui-chips-input.mjs +120 -21
  35. package/fesm2022/tectra-ng-ui-chips-input.mjs.map +1 -1
  36. package/fesm2022/tectra-ng-ui-color-picker.mjs +96 -9
  37. package/fesm2022/tectra-ng-ui-color-picker.mjs.map +1 -1
  38. package/fesm2022/tectra-ng-ui-color-swatches.mjs +3 -3
  39. package/fesm2022/tectra-ng-ui-confirm.mjs +9 -9
  40. package/fesm2022/tectra-ng-ui-countdown.mjs +48 -19
  41. package/fesm2022/tectra-ng-ui-countdown.mjs.map +1 -1
  42. package/fesm2022/tectra-ng-ui-country-select.mjs +31 -8
  43. package/fesm2022/tectra-ng-ui-country-select.mjs.map +1 -1
  44. package/fesm2022/tectra-ng-ui-country.mjs +18 -9
  45. package/fesm2022/tectra-ng-ui-country.mjs.map +1 -1
  46. package/fesm2022/tectra-ng-ui-data-view.mjs +30 -30
  47. package/fesm2022/tectra-ng-ui-datepicker.mjs +53 -40
  48. package/fesm2022/tectra-ng-ui-datepicker.mjs.map +1 -1
  49. package/fesm2022/tectra-ng-ui-dialog.mjs +30 -30
  50. package/fesm2022/tectra-ng-ui-dialog.mjs.map +1 -1
  51. package/fesm2022/tectra-ng-ui-divider.mjs +3 -3
  52. package/fesm2022/tectra-ng-ui-drawer.mjs +9 -9
  53. package/fesm2022/tectra-ng-ui-email-suggestion.mjs +3 -3
  54. package/fesm2022/tectra-ng-ui-export.mjs +1264 -111
  55. package/fesm2022/tectra-ng-ui-export.mjs.map +1 -1
  56. package/fesm2022/tectra-ng-ui-field.mjs +4 -3
  57. package/fesm2022/tectra-ng-ui-field.mjs.map +1 -1
  58. package/fesm2022/tectra-ng-ui-fieldset.mjs +5 -5
  59. package/fesm2022/tectra-ng-ui-fieldset.mjs.map +1 -1
  60. package/fesm2022/tectra-ng-ui-file-upload.mjs +12 -12
  61. package/fesm2022/tectra-ng-ui-galleria.mjs +21 -21
  62. package/fesm2022/tectra-ng-ui-highlight-text.mjs +3 -3
  63. package/fesm2022/tectra-ng-ui-icon-field.mjs +63 -35
  64. package/fesm2022/tectra-ng-ui-icon-field.mjs.map +1 -1
  65. package/fesm2022/tectra-ng-ui-image.mjs +9 -9
  66. package/fesm2022/tectra-ng-ui-input-group.mjs +6 -6
  67. package/fesm2022/tectra-ng-ui-input-mask.mjs +3 -3
  68. package/fesm2022/tectra-ng-ui-input-number.mjs +5 -5
  69. package/fesm2022/tectra-ng-ui-input-number.mjs.map +1 -1
  70. package/fesm2022/tectra-ng-ui-input-otp.mjs +3 -3
  71. package/fesm2022/tectra-ng-ui-input.mjs +11 -10
  72. package/fesm2022/tectra-ng-ui-input.mjs.map +1 -1
  73. package/fesm2022/tectra-ng-ui-key-filter.mjs +87 -22
  74. package/fesm2022/tectra-ng-ui-key-filter.mjs.map +1 -1
  75. package/fesm2022/tectra-ng-ui-knob.mjs +30 -8
  76. package/fesm2022/tectra-ng-ui-knob.mjs.map +1 -1
  77. package/fesm2022/tectra-ng-ui-label.mjs +77 -18
  78. package/fesm2022/tectra-ng-ui-label.mjs.map +1 -1
  79. package/fesm2022/tectra-ng-ui-link.mjs +44 -20
  80. package/fesm2022/tectra-ng-ui-link.mjs.map +1 -1
  81. package/fesm2022/tectra-ng-ui-list-input.mjs +3 -3
  82. package/fesm2022/tectra-ng-ui-listbox.mjs +3 -3
  83. package/fesm2022/tectra-ng-ui-mention-textarea.mjs +19 -8
  84. package/fesm2022/tectra-ng-ui-mention-textarea.mjs.map +1 -1
  85. package/fesm2022/tectra-ng-ui-menu.mjs +15 -15
  86. package/fesm2022/tectra-ng-ui-menubar.mjs +6 -6
  87. package/fesm2022/tectra-ng-ui-message.mjs +23 -19
  88. package/fesm2022/tectra-ng-ui-message.mjs.map +1 -1
  89. package/fesm2022/tectra-ng-ui-month-calendar.mjs +32 -15
  90. package/fesm2022/tectra-ng-ui-month-calendar.mjs.map +1 -1
  91. package/fesm2022/tectra-ng-ui-multiselect.mjs +6 -5
  92. package/fesm2022/tectra-ng-ui-multiselect.mjs.map +1 -1
  93. package/fesm2022/tectra-ng-ui-overlay-badge.mjs +3 -3
  94. package/fesm2022/tectra-ng-ui-paginator.mjs +9 -9
  95. package/fesm2022/tectra-ng-ui-panel-menu.mjs +51 -20
  96. package/fesm2022/tectra-ng-ui-panel-menu.mjs.map +1 -1
  97. package/fesm2022/tectra-ng-ui-panel.mjs +7 -5
  98. package/fesm2022/tectra-ng-ui-panel.mjs.map +1 -1
  99. package/fesm2022/tectra-ng-ui-password-generator.mjs +24 -7
  100. package/fesm2022/tectra-ng-ui-password-generator.mjs.map +1 -1
  101. package/fesm2022/tectra-ng-ui-password.mjs +14 -14
  102. package/fesm2022/tectra-ng-ui-password.mjs.map +1 -1
  103. package/fesm2022/tectra-ng-ui-pill.mjs +39 -19
  104. package/fesm2022/tectra-ng-ui-pill.mjs.map +1 -1
  105. package/fesm2022/tectra-ng-ui-popover.mjs +15 -15
  106. package/fesm2022/tectra-ng-ui-progress-bar.mjs +6 -6
  107. package/fesm2022/tectra-ng-ui-progress-spinner.mjs +3 -3
  108. package/fesm2022/tectra-ng-ui-radio-button.mjs +6 -6
  109. package/fesm2022/tectra-ng-ui-rating.mjs +11 -11
  110. package/fesm2022/tectra-ng-ui-rating.mjs.map +1 -1
  111. package/fesm2022/tectra-ng-ui-scroll-panel.mjs +3 -3
  112. package/fesm2022/tectra-ng-ui-select-button.mjs +6 -6
  113. package/fesm2022/tectra-ng-ui-select.mjs +66 -43
  114. package/fesm2022/tectra-ng-ui-select.mjs.map +1 -1
  115. package/fesm2022/tectra-ng-ui-skeleton.mjs +6 -6
  116. package/fesm2022/tectra-ng-ui-slider.mjs +3 -3
  117. package/fesm2022/tectra-ng-ui-sparkline.mjs +3 -3
  118. package/fesm2022/tectra-ng-ui-speed-dial.mjs +3 -3
  119. package/fesm2022/tectra-ng-ui-split-button.mjs +3 -3
  120. package/fesm2022/tectra-ng-ui-splitter.mjs +6 -6
  121. package/fesm2022/tectra-ng-ui-stat-tiles.mjs +99 -14
  122. package/fesm2022/tectra-ng-ui-stat-tiles.mjs.map +1 -1
  123. package/fesm2022/tectra-ng-ui-status-icon.mjs +43 -6
  124. package/fesm2022/tectra-ng-ui-status-icon.mjs.map +1 -1
  125. package/fesm2022/tectra-ng-ui-stepper.mjs +41 -35
  126. package/fesm2022/tectra-ng-ui-stepper.mjs.map +1 -1
  127. package/fesm2022/tectra-ng-ui-table.mjs +74 -60
  128. package/fesm2022/tectra-ng-ui-table.mjs.map +1 -1
  129. package/fesm2022/tectra-ng-ui-tabs.mjs +18 -18
  130. package/fesm2022/tectra-ng-ui-tag.mjs +8 -8
  131. package/fesm2022/tectra-ng-ui-tag.mjs.map +1 -1
  132. package/fesm2022/tectra-ng-ui-textarea.mjs +9 -9
  133. package/fesm2022/tectra-ng-ui-timeline.mjs +15 -15
  134. package/fesm2022/tectra-ng-ui-toast.mjs +11 -11
  135. package/fesm2022/tectra-ng-ui-toast.mjs.map +1 -1
  136. package/fesm2022/tectra-ng-ui-toggle-button.mjs +3 -3
  137. package/fesm2022/tectra-ng-ui-toggle-switch.mjs +6 -6
  138. package/fesm2022/tectra-ng-ui-toolbar.mjs +12 -12
  139. package/fesm2022/tectra-ng-ui-tooltip.mjs +9 -9
  140. package/fesm2022/tectra-ng-ui-tree-select.mjs +13 -11
  141. package/fesm2022/tectra-ng-ui-tree-select.mjs.map +1 -1
  142. package/fesm2022/tectra-ng-ui-tree-table.mjs +7 -7
  143. package/fesm2022/tectra-ng-ui-tree-table.mjs.map +1 -1
  144. package/fesm2022/tectra-ng-ui-tree.mjs +30 -30
  145. package/fesm2022/tectra-ng-ui-truncate-text.mjs +36 -12
  146. package/fesm2022/tectra-ng-ui-truncate-text.mjs.map +1 -1
  147. package/fesm2022/tectra-ng-ui-virtual-scroller.mjs +15 -15
  148. package/fesm2022/tectra-ng-ui.mjs +1 -1
  149. package/icon-field/README.md +2 -1
  150. package/input/README.md +1 -1
  151. package/key-filter/README.md +3 -2
  152. package/knob/README.md +3 -1
  153. package/label/README.md +4 -1
  154. package/link/README.md +4 -1
  155. package/message/README.md +2 -2
  156. package/month-calendar/README.md +2 -1
  157. package/multiselect/README.md +1 -1
  158. package/package.json +4 -4
  159. package/panel/README.md +3 -1
  160. package/panel-menu/README.md +3 -2
  161. package/password-generator/README.md +2 -0
  162. package/pill/README.md +4 -4
  163. package/select/README.md +1 -1
  164. package/stat-tiles/README.md +17 -1
  165. package/status-icon/README.md +3 -1
  166. package/table/README.md +1 -1
  167. package/tag/README.md +2 -0
  168. package/tree-select/README.md +1 -1
  169. package/truncate-text/README.md +2 -1
  170. package/types/tectra-ng-ui-amount.d.ts +41 -1
  171. package/types/tectra-ng-ui-amount.d.ts.map +1 -1
  172. package/types/tectra-ng-ui-analog-clock.d.ts +1 -4
  173. package/types/tectra-ng-ui-analog-clock.d.ts.map +1 -1
  174. package/types/tectra-ng-ui-autocomplete.d.ts +1 -1
  175. package/types/tectra-ng-ui-avatar.d.ts +45 -12
  176. package/types/tectra-ng-ui-avatar.d.ts.map +1 -1
  177. package/types/tectra-ng-ui-cascade-select.d.ts +3 -2
  178. package/types/tectra-ng-ui-cascade-select.d.ts.map +1 -1
  179. package/types/tectra-ng-ui-chips-input.d.ts +54 -6
  180. package/types/tectra-ng-ui-chips-input.d.ts.map +1 -1
  181. package/types/tectra-ng-ui-color-picker.d.ts +38 -1
  182. package/types/tectra-ng-ui-color-picker.d.ts.map +1 -1
  183. package/types/tectra-ng-ui-countdown.d.ts +12 -1
  184. package/types/tectra-ng-ui-countdown.d.ts.map +1 -1
  185. package/types/tectra-ng-ui-country-select.d.ts +17 -4
  186. package/types/tectra-ng-ui-country-select.d.ts.map +1 -1
  187. package/types/tectra-ng-ui-country.d.ts +7 -1
  188. package/types/tectra-ng-ui-country.d.ts.map +1 -1
  189. package/types/tectra-ng-ui-datepicker.d.ts +4 -2
  190. package/types/tectra-ng-ui-datepicker.d.ts.map +1 -1
  191. package/types/tectra-ng-ui-export.d.ts +68 -8
  192. package/types/tectra-ng-ui-export.d.ts.map +1 -1
  193. package/types/tectra-ng-ui-icon-field.d.ts +9 -2
  194. package/types/tectra-ng-ui-icon-field.d.ts.map +1 -1
  195. package/types/tectra-ng-ui-input.d.ts +1 -1
  196. package/types/tectra-ng-ui-key-filter.d.ts +19 -4
  197. package/types/tectra-ng-ui-key-filter.d.ts.map +1 -1
  198. package/types/tectra-ng-ui-knob.d.ts +10 -2
  199. package/types/tectra-ng-ui-knob.d.ts.map +1 -1
  200. package/types/tectra-ng-ui-label.d.ts +8 -1
  201. package/types/tectra-ng-ui-label.d.ts.map +1 -1
  202. package/types/tectra-ng-ui-link.d.ts +8 -2
  203. package/types/tectra-ng-ui-link.d.ts.map +1 -1
  204. package/types/tectra-ng-ui-mention-textarea.d.ts +5 -0
  205. package/types/tectra-ng-ui-mention-textarea.d.ts.map +1 -1
  206. package/types/tectra-ng-ui-message.d.ts +1 -1
  207. package/types/tectra-ng-ui-message.d.ts.map +1 -1
  208. package/types/tectra-ng-ui-month-calendar.d.ts +14 -4
  209. package/types/tectra-ng-ui-month-calendar.d.ts.map +1 -1
  210. package/types/tectra-ng-ui-multiselect.d.ts +1 -1
  211. package/types/tectra-ng-ui-panel-menu.d.ts +34 -6
  212. package/types/tectra-ng-ui-panel-menu.d.ts.map +1 -1
  213. package/types/tectra-ng-ui-panel.d.ts +1 -1
  214. package/types/tectra-ng-ui-panel.d.ts.map +1 -1
  215. package/types/tectra-ng-ui-password-generator.d.ts +10 -3
  216. package/types/tectra-ng-ui-password-generator.d.ts.map +1 -1
  217. package/types/tectra-ng-ui-pill.d.ts +9 -5
  218. package/types/tectra-ng-ui-pill.d.ts.map +1 -1
  219. package/types/tectra-ng-ui-select.d.ts +5 -2
  220. package/types/tectra-ng-ui-select.d.ts.map +1 -1
  221. package/types/tectra-ng-ui-stat-tiles.d.ts +49 -5
  222. package/types/tectra-ng-ui-stat-tiles.d.ts.map +1 -1
  223. package/types/tectra-ng-ui-status-icon.d.ts +20 -2
  224. package/types/tectra-ng-ui-status-icon.d.ts.map +1 -1
  225. package/types/tectra-ng-ui-stepper.d.ts +1 -0
  226. package/types/tectra-ng-ui-stepper.d.ts.map +1 -1
  227. package/types/tectra-ng-ui-table.d.ts +2 -1
  228. package/types/tectra-ng-ui-table.d.ts.map +1 -1
  229. package/types/tectra-ng-ui-tree-select.d.ts +3 -3
  230. package/types/tectra-ng-ui-tree-select.d.ts.map +1 -1
  231. package/types/tectra-ng-ui-truncate-text.d.ts +7 -2
  232. package/types/tectra-ng-ui-truncate-text.d.ts.map +1 -1
  233. package/types/tectra-ng-ui.d.ts +1 -1
@@ -129,6 +129,9 @@ function hexColor(color, fallback) {
129
129
  const full = value.length === 3 ? value.replace(/./g, (char) => char + char) : value;
130
130
  return /^[0-9a-f]{6}$/i.test(full) ? full.toUpperCase() : fallback.replace("#", "").toUpperCase();
131
131
  }
132
+ function loadDefaultExportFont() {
133
+ return import("@tectra-ng/ui/export-font").then((module) => module.TX_EXPORT_FONT);
134
+ }
132
135
  const SIZES = {
133
136
  a3: [841.89, 1190.55],
134
137
  a4: [595.28, 841.89],
@@ -370,6 +373,260 @@ async function writeDocx(table, options = {}, context = {
370
373
  ], date, options.compress !== false);
371
374
  return new Blob([bytes], { type: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" });
372
375
  }
376
+ const VOID_TAG = /^(?:area|base|br|col|embed|hr|img|input|link|meta|param|source|track|wbr)$/;
377
+ const RAW_TAGS = /* @__PURE__ */ new Set([
378
+ "script",
379
+ "style",
380
+ "textarea",
381
+ "title"
382
+ ]);
383
+ const SKIPPED_TAGS = /* @__PURE__ */ new Set([
384
+ "script",
385
+ "style",
386
+ "template",
387
+ "title",
388
+ "head",
389
+ "noscript",
390
+ "svg",
391
+ "canvas",
392
+ "iframe",
393
+ "object",
394
+ "select",
395
+ "button",
396
+ "input",
397
+ "textarea"
398
+ ]);
399
+ const BLOCK_TAG = /^(?:address|article|aside|blockquote|center|details|dialog|div|dl|fieldset|figcaption|figure|footer|form|h[1-6]|header|hr|main|menu|nav|ol|p|pre|section|summary|table|ul)$/;
400
+ const SECTIONS = /^(?:thead|tbody|tfoot|tr|td|th|caption)$/;
401
+ const TABLE_SCOPE = /^table$/;
402
+ const IMPLIED_ENDS = {
403
+ li: {
404
+ closes: /^li$/,
405
+ scope: /^(?:ul|ol|menu)$/
406
+ },
407
+ dt: {
408
+ closes: /^(?:dt|dd)$/,
409
+ scope: /^dl$/
410
+ },
411
+ dd: {
412
+ closes: /^(?:dt|dd)$/,
413
+ scope: /^dl$/
414
+ },
415
+ tr: {
416
+ closes: /^(?:tr|td|th|caption)$/,
417
+ scope: /^(?:table|thead|tbody|tfoot)$/
418
+ },
419
+ td: {
420
+ closes: /^(?:td|th)$/,
421
+ scope: /^(?:tr|table)$/
422
+ },
423
+ th: {
424
+ closes: /^(?:td|th)$/,
425
+ scope: /^(?:tr|table)$/
426
+ },
427
+ thead: {
428
+ closes: SECTIONS,
429
+ scope: TABLE_SCOPE
430
+ },
431
+ tbody: {
432
+ closes: SECTIONS,
433
+ scope: TABLE_SCOPE
434
+ },
435
+ tfoot: {
436
+ closes: SECTIONS,
437
+ scope: TABLE_SCOPE
438
+ }
439
+ };
440
+ const ENTITIES = {
441
+ amp: "&",
442
+ lt: "<",
443
+ gt: ">",
444
+ quot: "\"",
445
+ apos: "'",
446
+ nbsp: "\xA0",
447
+ ensp: " ",
448
+ emsp: " ",
449
+ thinsp: " ",
450
+ shy: "",
451
+ zwnj: "‌",
452
+ zwj: "‍",
453
+ copy: "©",
454
+ reg: "®",
455
+ trade: "™",
456
+ hellip: "…",
457
+ mdash: "—",
458
+ ndash: "–",
459
+ minus: "−",
460
+ lsquo: "‘",
461
+ rsquo: "’",
462
+ sbquo: "‚",
463
+ ldquo: "“",
464
+ rdquo: "”",
465
+ bdquo: "„",
466
+ laquo: "«",
467
+ raquo: "»",
468
+ bull: "•",
469
+ middot: "·",
470
+ deg: "°",
471
+ plusmn: "±",
472
+ times: "×",
473
+ divide: "÷",
474
+ euro: "€",
475
+ pound: "£",
476
+ yen: "¥",
477
+ cent: "¢",
478
+ sect: "§",
479
+ para: "¶",
480
+ numero: "№",
481
+ larr: "←",
482
+ rarr: "→",
483
+ uarr: "↑",
484
+ darr: "↓",
485
+ harr: "↔",
486
+ check: "✓"
487
+ };
488
+ function decodeEntities(text) {
489
+ return text.replace(/&(#x[\da-f]+|#\d+|[a-z][a-z\d]*);/gi, (entity, body) => {
490
+ if (body[0] === "#") {
491
+ const code = body[1] === "x" || body[1] === "X" ? parseInt(body.slice(2), 16) : parseInt(body.slice(1), 10);
492
+ return code > 0 && code <= 1114111 ? String.fromCodePoint(code) : entity;
493
+ }
494
+ return ENTITIES[body.toLowerCase()] ?? entity;
495
+ });
496
+ }
497
+ function parseAttributes(source) {
498
+ const attrs = {};
499
+ for (const match of source.matchAll(/([^\s"'<>/=]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'=<>`]+)))?/g)) attrs[match[1].toLowerCase()] = decodeEntities(match[2] ?? match[3] ?? match[4] ?? "");
500
+ return attrs;
501
+ }
502
+ function tagEnd(html, from) {
503
+ let quote = "";
504
+ for (let index = from; index < html.length; index++) {
505
+ const char = html[index];
506
+ if (quote) {
507
+ if (char === quote) quote = "";
508
+ } else if (char === "\"" || char === "'") quote = char;
509
+ else if (char === ">") return index;
510
+ }
511
+ return html.length;
512
+ }
513
+ function parseHtml(html) {
514
+ const root = {
515
+ tag: "#root",
516
+ attrs: {},
517
+ children: []
518
+ };
519
+ const stack = [root];
520
+ const top = () => stack[stack.length - 1];
521
+ const text = (value) => {
522
+ if (value) top().children.push(decodeEntities(value));
523
+ };
524
+ const closeImplied = (tag) => {
525
+ const rule = IMPLIED_ENDS[tag];
526
+ if (rule) {
527
+ let close = 0;
528
+ for (let index = stack.length - 1; index > 0 && !rule.scope.test(stack[index].tag); index--) if (rule.closes.test(stack[index].tag)) close = index;
529
+ if (close) stack.length = close;
530
+ }
531
+ if (BLOCK_TAG.test(tag)) for (let index = stack.length - 1; index > 0; index--) {
532
+ const open = stack[index].tag;
533
+ if (open === "p") {
534
+ stack.length = index;
535
+ break;
536
+ }
537
+ if (BLOCK_TAG.test(open) || open === "li" || open === "td" || open === "th") break;
538
+ }
539
+ };
540
+ let index = 0;
541
+ while (index < html.length) {
542
+ const open = html.indexOf("<", index);
543
+ if (open < 0) {
544
+ text(html.slice(index));
545
+ break;
546
+ }
547
+ text(html.slice(index, open));
548
+ if (html.startsWith("<!--", open)) {
549
+ const end = html.indexOf("-->", open + 4);
550
+ index = end < 0 ? html.length : end + 3;
551
+ continue;
552
+ }
553
+ const name = /^<(\/?)([a-zA-Z][\w:-]*)/.exec(html.slice(open, open + 64));
554
+ if (!name) {
555
+ if (html[open + 1] === "!" || html[open + 1] === "?") index = tagEnd(html, open) + 1;
556
+ else {
557
+ text("<");
558
+ index = open + 1;
559
+ }
560
+ continue;
561
+ }
562
+ const end = tagEnd(html, open + name[0].length);
563
+ const tag = name[2].toLowerCase();
564
+ index = end + 1;
565
+ if (name[1]) {
566
+ const at = stack.map((element) => element.tag).lastIndexOf(tag);
567
+ if (at > 0) stack.length = at;
568
+ else if (tag === "br") top().children.push({
569
+ tag,
570
+ attrs: {},
571
+ children: []
572
+ });
573
+ continue;
574
+ }
575
+ const body = html.slice(open + name[0].length, end);
576
+ closeImplied(tag);
577
+ const element = {
578
+ tag,
579
+ attrs: parseAttributes(body),
580
+ children: []
581
+ };
582
+ top().children.push(element);
583
+ if (RAW_TAGS.has(tag)) {
584
+ const close = html.toLowerCase().indexOf(`</${tag}`, index);
585
+ const stop = close < 0 ? html.length : close;
586
+ element.children.push(html.slice(index, stop));
587
+ index = close < 0 ? html.length : tagEnd(html, close) + 1;
588
+ continue;
589
+ }
590
+ if (!VOID_TAG.test(tag) && !body.trimEnd().endsWith("/")) stack.push(element);
591
+ }
592
+ return root;
593
+ }
594
+ function domChildren(node) {
595
+ return Array.from(node.childNodes).flatMap((child) => {
596
+ const read = fromDomNode(child);
597
+ return read === null ? [] : [read];
598
+ });
599
+ }
600
+ function fromDomNode(node) {
601
+ if (node.nodeType === 3) return node.nodeValue;
602
+ if (node.nodeType !== 1) return null;
603
+ const attrs = {};
604
+ for (const attr of Array.from(node.attributes)) attrs[attr.name.toLowerCase()] = attr.value;
605
+ return {
606
+ tag: node.tagName.toLowerCase(),
607
+ attrs,
608
+ children: domChildren(node)
609
+ };
610
+ }
611
+ function readDom(node) {
612
+ const source = node;
613
+ if (source.nodeType === 9) return {
614
+ tag: "#root",
615
+ attrs: {},
616
+ children: source.body ? domChildren(source.body) : []
617
+ };
618
+ if (source.nodeType === 11) return {
619
+ tag: "#root",
620
+ attrs: {},
621
+ children: domChildren(source)
622
+ };
623
+ const read = fromDomNode(source);
624
+ return {
625
+ tag: "#root",
626
+ attrs: {},
627
+ children: read === null ? [] : [read]
628
+ };
629
+ }
373
630
  const KEEP_TABLES = [
374
631
  "OS/2",
375
632
  "cmap",
@@ -629,13 +886,13 @@ var PdfFont = class {
629
886
  }
630
887
  width(text, size) {
631
888
  let units = 0;
632
- for (const char of text) units += this.ttf.advance(this.ttf.glyphId(char.codePointAt(0) ?? 0));
889
+ for (const char of text) units += this.ttf.advance(this.ttf.glyphId(char.codePointAt(0)));
633
890
  return units * size / this.ttf.unitsPerEm;
634
891
  }
635
892
  encode(text) {
636
893
  let hex = "";
637
894
  for (const char of text) {
638
- const code = char.codePointAt(0) ?? 0;
895
+ const code = char.codePointAt(0);
639
896
  const glyph = this.ttf.glyphId(code);
640
897
  if (!this.used.has(glyph)) this.used.set(glyph, code);
641
898
  hex += glyph.toString(16).padStart(4, "0");
@@ -666,10 +923,955 @@ function utf16Hex(text) {
666
923
  function pdfString(text) {
667
924
  return `<FEFF${utf16Hex(text)}>`;
668
925
  }
926
+ function asciiString(text) {
927
+ return `(${encodeURI(decodeUriSafe(text)).replace(/[\\()]/g, (char) => `\\${char}`)})`;
928
+ }
929
+ function decodeUriSafe(text) {
930
+ try {
931
+ return decodeURI(text);
932
+ } catch {
933
+ return text;
934
+ }
935
+ }
669
936
  function pdfDate(date) {
670
937
  const pad = (value) => String(value).padStart(2, "0");
671
938
  return `D:${date.getFullYear()}${pad(date.getMonth() + 1)}${pad(date.getDate())}${pad(date.getHours())}${pad(date.getMinutes())}${pad(date.getSeconds())}`;
672
939
  }
940
+ async function loadPdfFonts(font) {
941
+ return {
942
+ regular: parseTrueType(toBytes(font.regular)),
943
+ bold: font.bold ? parseTrueType(toBytes(font.bold)) : null
944
+ };
945
+ }
946
+ function loadOptionalFont(source) {
947
+ return source ? parseTrueType(toBytes(source)) : null;
948
+ }
949
+ async function assemblePdf(document) {
950
+ const objects = [];
951
+ const reserve = () => {
952
+ objects.push(null);
953
+ return objects.length;
954
+ };
955
+ const set = (id, body) => {
956
+ objects[id - 1] = typeof body === "string" ? utf8(`${id} 0 obj\n${body}\nendobj\n`) : body;
957
+ };
958
+ const stream = async (id, dict, data) => {
959
+ const packed = document.compress === false ? null : await compress(data, "deflate");
960
+ const body = packed ?? data;
961
+ set(id, concatBytes([
962
+ utf8(`${id} 0 obj\n<< ${dict} /Length ${body.length}${packed ? " /Filter /FlateDecode" : ""} >>\nstream\n`),
963
+ body,
964
+ utf8("\nendstream\nendobj\n")
965
+ ]));
966
+ };
967
+ const catalog = reserve();
968
+ const pagesId = reserve();
969
+ const info = reserve();
970
+ const fontIds = /* @__PURE__ */ new Map();
971
+ for (const pdfFont of document.fonts) fontIds.set(pdfFont, reserve());
972
+ const pageIds = document.pages.map((page) => ({
973
+ page: reserve(),
974
+ content: reserve(),
975
+ links: page.links.map(() => reserve())
976
+ }));
977
+ const fontsDict = [...fontIds].map(([pdfFont, id]) => `/${pdfFont.resource} ${id} 0 R`).join(" ");
978
+ for (const [index, ids] of pageIds.entries()) {
979
+ const page = document.pages[index];
980
+ const annots = ids.links.length ? ` /Annots [${ids.links.map((id) => `${id} 0 R`).join(" ")}]` : "";
981
+ set(ids.page, `<< /Type /Page /Parent ${pagesId} 0 R /MediaBox [0 0 ${num(document.width)} ${num(document.height)}] /Resources << /Font << ${fontsDict} >> >> /Contents ${ids.content} 0 R${annots} >>`);
982
+ await stream(ids.content, "", utf8(page.ops.join("\n")));
983
+ page.links.forEach((link, linkIndex) => {
984
+ const rect = [
985
+ link.x,
986
+ link.y,
987
+ link.x + link.width,
988
+ link.y + link.height
989
+ ].map(num).join(" ");
990
+ set(ids.links[linkIndex], `<< /Type /Annot /Subtype /Link /Rect [${rect}] /Border [0 0 0] /A << /Type /Action /S /URI /URI ${asciiString(link.uri)} >> >>`);
991
+ });
992
+ }
993
+ for (const [pdfFont, id] of fontIds) {
994
+ const ttf = pdfFont.ttf;
995
+ const scale = (value) => Math.round(value * 1e3 / ttf.unitsPerEm);
996
+ const glyphs = [...pdfFont.used.keys()].sort((a, b) => a - b);
997
+ const baseFont = `${pdfFont.tag}+${ttf.name}`;
998
+ const cid = reserve();
999
+ const descriptor = reserve();
1000
+ const file = reserve();
1001
+ const toUnicode = reserve();
1002
+ set(id, `<< /Type /Font /Subtype /Type0 /BaseFont /${baseFont} /Encoding /Identity-H /DescendantFonts [${cid} 0 R] /ToUnicode ${toUnicode} 0 R >>`);
1003
+ const w = glyphs.map((glyph) => `${glyph} [${scale(ttf.advance(glyph))}]`).join(" ");
1004
+ set(cid, `<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${baseFont} /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor ${descriptor} 0 R /DW ${scale(ttf.advance(0))} /W [${w}] /CIDToGIDMap /Identity >>`);
1005
+ set(descriptor, `<< /Type /FontDescriptor /FontName /${baseFont} /Flags 32 /FontBBox [${ttf.bbox.map(scale).join(" ")}] /ItalicAngle 0 /Ascent ${scale(ttf.ascent)} /Descent ${scale(ttf.descent)} /CapHeight ${scale(ttf.capHeight)} /StemV 80 /FontFile2 ${file} 0 R >>`);
1006
+ const subset = ttf.subset(new Set(glyphs));
1007
+ await stream(file, `/Length1 ${subset.length}`, subset);
1008
+ const entries = glyphs.map((glyph) => `<${glyph.toString(16).padStart(4, "0")}> <${utf16Hex(String.fromCodePoint(pdfFont.used.get(glyph)))}>`);
1009
+ const chunks = [];
1010
+ for (let index = 0; index < entries.length; index += 100) {
1011
+ const chunk = entries.slice(index, index + 100);
1012
+ chunks.push(`${chunk.length} beginbfchar\n${chunk.join("\n")}\nendbfchar`);
1013
+ }
1014
+ await stream(toUnicode, "", utf8(`/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n${chunks.join("\n")}\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend`));
1015
+ }
1016
+ set(catalog, `<< /Type /Catalog /Pages ${pagesId} 0 R >>`);
1017
+ set(pagesId, `<< /Type /Pages /Kids [${pageIds.map((ids) => `${ids.page} 0 R`).join(" ")}] /Count ${pageIds.length} >>`);
1018
+ const infoParts = [`/Producer (tectra)`, `/CreationDate (${pdfDate(document.date)})`];
1019
+ if (document.title) infoParts.push(`/Title ${pdfString(document.title)}`);
1020
+ if (document.author) infoParts.push(`/Author ${pdfString(document.author)}`);
1021
+ set(info, `<< ${infoParts.join(" ")} >>`);
1022
+ const header = utf8("%PDF-1.7\n%âãÏÓ\n");
1023
+ const offsets = [];
1024
+ let offset = header.length;
1025
+ for (const object of objects) {
1026
+ offsets.push(offset);
1027
+ offset += object.length;
1028
+ }
1029
+ const xref = [`xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`, ...offsets.map((value) => `${String(value).padStart(10, "0")} 00000 n \n`)].join("");
1030
+ const trailer = `trailer\n<< /Size ${objects.length + 1} /Root ${catalog} 0 R /Info ${info} 0 R >>\nstartxref\n${offset}\n%%EOF\n`;
1031
+ const bytes = concatBytes([
1032
+ header,
1033
+ ...objects,
1034
+ utf8(xref + trailer)
1035
+ ]);
1036
+ return new Blob([bytes], { type: "application/pdf" });
1037
+ }
1038
+ const PLAIN = {
1039
+ bold: false,
1040
+ italic: false,
1041
+ code: false,
1042
+ block: false,
1043
+ underline: false,
1044
+ strike: false,
1045
+ link: null,
1046
+ color: null,
1047
+ scale: 1,
1048
+ rise: 0
1049
+ };
1050
+ const HEADING_SCALE = [
1051
+ 2,
1052
+ 1.6,
1053
+ 1.35,
1054
+ 1.15,
1055
+ 1,
1056
+ .9
1057
+ ];
1058
+ const FLOW_PARTS = /* @__PURE__ */ new Set([
1059
+ "li",
1060
+ "dt",
1061
+ "dd",
1062
+ "html",
1063
+ "body",
1064
+ "caption",
1065
+ "thead",
1066
+ "tbody",
1067
+ "tfoot",
1068
+ "tr",
1069
+ "td",
1070
+ "th"
1071
+ ]);
1072
+ const TABLE_TAG = /^table$/;
1073
+ const LINK_SCHEMES = /^(https?:|mailto:|tel:)/i;
1074
+ function isFlow(tag) {
1075
+ return BLOCK_TAG.test(tag) || FLOW_PARTS.has(tag);
1076
+ }
1077
+ function styleOf(element) {
1078
+ const result = {};
1079
+ for (const part of (element.attrs["style"] ?? "").split(";")) {
1080
+ const colon = part.indexOf(":");
1081
+ if (colon > 0) result[part.slice(0, colon).trim().toLowerCase()] = part.slice(colon + 1).trim().toLowerCase();
1082
+ }
1083
+ return result;
1084
+ }
1085
+ function alignOf(element, fallback) {
1086
+ const value = styleOf(element)["text-align"] ?? element.attrs["align"]?.toLowerCase();
1087
+ if (value === "center") return "center";
1088
+ if (value === "right" || value === "end") return "end";
1089
+ if (value === "left" || value === "start" || value === "justify") return "start";
1090
+ return fallback;
1091
+ }
1092
+ function breaks(element, side) {
1093
+ const css = styleOf(element);
1094
+ return ["page", "always"].includes(css[`break-${side}`] ?? css[`page-break-${side}`] ?? "");
1095
+ }
1096
+ function inlineStyle(element, style, linkColor) {
1097
+ const css = styleOf(element);
1098
+ const next = { ...style };
1099
+ switch (element.tag) {
1100
+ case "b":
1101
+ case "strong":
1102
+ next.bold = true;
1103
+ break;
1104
+ case "i":
1105
+ case "em":
1106
+ case "cite":
1107
+ case "dfn":
1108
+ case "var":
1109
+ next.italic = true;
1110
+ break;
1111
+ case "code":
1112
+ case "kbd":
1113
+ case "samp":
1114
+ case "tt":
1115
+ next.code = true;
1116
+ break;
1117
+ case "u":
1118
+ case "ins":
1119
+ next.underline = true;
1120
+ break;
1121
+ case "s":
1122
+ case "strike":
1123
+ case "del":
1124
+ next.strike = true;
1125
+ break;
1126
+ case "small":
1127
+ next.scale = style.scale * .85;
1128
+ break;
1129
+ case "sub":
1130
+ case "sup":
1131
+ next.scale = style.scale * .75;
1132
+ next.rise = element.tag === "sup" ? .35 : -.15;
1133
+ break;
1134
+ case "a": {
1135
+ const href = element.attrs["href"] ?? "";
1136
+ if (LINK_SCHEMES.test(href)) {
1137
+ next.link = href;
1138
+ next.underline = true;
1139
+ next.color = linkColor;
1140
+ }
1141
+ break;
1142
+ }
1143
+ }
1144
+ const weight = css["font-weight"];
1145
+ if (/^bold/.test(weight ?? "") || Number(weight) >= 600) next.bold = true;
1146
+ if (/^(?:italic|oblique)/.test(css["font-style"] ?? "")) next.italic = true;
1147
+ if (/underline/.test(css["text-decoration"] ?? "")) next.underline = true;
1148
+ if (/line-through/.test(css["text-decoration"] ?? "")) next.strike = true;
1149
+ return next;
1150
+ }
1151
+ function sameStyle(a, b) {
1152
+ return Object.keys(a).every((key) => a[key] === b[key]);
1153
+ }
1154
+ var HtmlPdfLayout = class {
1155
+ fonts;
1156
+ items = [];
1157
+ pending = 0;
1158
+ fresh = true;
1159
+ marker = null;
1160
+ depth = 0;
1161
+ size;
1162
+ lineFactor;
1163
+ text;
1164
+ muted;
1165
+ link;
1166
+ border;
1167
+ headerFill;
1168
+ codeFill;
1169
+ constructor(fonts, options) {
1170
+ this.fonts = fonts;
1171
+ this.size = options.fontSize ?? 10;
1172
+ this.lineFactor = options.lineHeight ?? 1.45;
1173
+ this.text = hexColor(options.textColor, "1D2939");
1174
+ this.muted = hexColor(options.mutedColor, "667085");
1175
+ this.link = hexColor(options.linkColor, "2560E4");
1176
+ this.border = hexColor(options.borderColor, "D0D5DD");
1177
+ this.headerFill = options.headerBackground === "none" ? null : hexColor(options.headerBackground, "F2F4F7");
1178
+ this.codeFill = hexColor(options.codeBackground, "F2F4F7");
1179
+ }
1180
+ flow(nodes, frame, style, pre = false) {
1181
+ let runs = [];
1182
+ const flush = () => {
1183
+ this.paragraph(runs, frame, pre);
1184
+ runs = [];
1185
+ };
1186
+ for (const node of nodes) if (typeof node === "string") runs.push({
1187
+ text: node,
1188
+ style
1189
+ });
1190
+ else if (SKIPPED_TAGS.has(node.tag)) continue;
1191
+ else if (isFlow(node.tag)) {
1192
+ flush();
1193
+ this.block(node, frame, style);
1194
+ } else this.inline(node, style, runs);
1195
+ flush();
1196
+ }
1197
+ inline(element, style, runs) {
1198
+ if (SKIPPED_TAGS.has(element.tag)) return;
1199
+ if (element.tag === "br") {
1200
+ runs.push({
1201
+ text: "",
1202
+ style,
1203
+ brk: "hard"
1204
+ });
1205
+ return;
1206
+ }
1207
+ if (element.tag === "img") {
1208
+ const alt = element.attrs["alt"]?.trim();
1209
+ if (alt) runs.push({
1210
+ text: alt,
1211
+ style: {
1212
+ ...style,
1213
+ italic: true
1214
+ }
1215
+ });
1216
+ return;
1217
+ }
1218
+ const cell = element.tag === "td" || element.tag === "th";
1219
+ const block = isFlow(element.tag) && !cell;
1220
+ const next = isFlow(element.tag) ? style : inlineStyle(element, style, this.link);
1221
+ if (block) runs.push({
1222
+ text: "",
1223
+ style,
1224
+ brk: "soft"
1225
+ });
1226
+ if (element.tag === "li") runs.push({
1227
+ text: "• ",
1228
+ style
1229
+ });
1230
+ if (element.tag === "q") runs.push({
1231
+ text: "“",
1232
+ style
1233
+ });
1234
+ for (const child of element.children) if (typeof child === "string") runs.push({
1235
+ text: child,
1236
+ style: next
1237
+ });
1238
+ else this.inline(child, next, runs);
1239
+ if (element.tag === "q") runs.push({
1240
+ text: "”",
1241
+ style
1242
+ });
1243
+ if (block) runs.push({
1244
+ text: "",
1245
+ style,
1246
+ brk: "soft"
1247
+ });
1248
+ if (cell) runs.push({
1249
+ text: " ",
1250
+ style
1251
+ });
1252
+ }
1253
+ block(element, frame, style) {
1254
+ if (breaks(element, "before")) this.pageBreak();
1255
+ const aligned = {
1256
+ ...frame,
1257
+ align: alignOf(element, frame.align)
1258
+ };
1259
+ const size = this.size;
1260
+ const tag = element.tag;
1261
+ if (/^h[1-6]$/.test(tag)) {
1262
+ const level = Number(tag[1]);
1263
+ this.gap(size * (1.5 - level * .08));
1264
+ this.paragraph(this.runs(element.children, {
1265
+ ...style,
1266
+ bold: true,
1267
+ scale: HEADING_SCALE[level - 1]
1268
+ }), aligned, false, true);
1269
+ this.gap(size * .5);
1270
+ } else if (tag === "p" || tag === "figure" || tag === "dl" || tag === "details" || tag === "fieldset") {
1271
+ this.gap(size * .75);
1272
+ this.flow(element.children, aligned, style);
1273
+ this.gap(size * .75);
1274
+ } else if (tag === "ul" || tag === "ol" || tag === "menu") this.list(element, aligned, style);
1275
+ else if (tag === "li") this.listItem(element, aligned, style, 16, null);
1276
+ else if (tag === "dt") {
1277
+ this.gap(size * .4);
1278
+ this.flow(element.children, aligned, {
1279
+ ...style,
1280
+ bold: true
1281
+ });
1282
+ } else if (tag === "dd") this.flow(element.children, {
1283
+ ...aligned,
1284
+ left: frame.left + 18,
1285
+ width: frame.width - 18
1286
+ }, style);
1287
+ else if (tag === "figcaption" || tag === "caption") this.flow(element.children, aligned, {
1288
+ ...style,
1289
+ color: this.muted,
1290
+ scale: style.scale * .9
1291
+ });
1292
+ else if (tag === "blockquote") {
1293
+ this.gap(size * .75);
1294
+ this.open(frame);
1295
+ this.flow(element.children, {
1296
+ ...aligned,
1297
+ left: frame.left + 14,
1298
+ width: frame.width - 14,
1299
+ bars: [...frame.bars, frame.left + 2]
1300
+ }, {
1301
+ ...style,
1302
+ color: this.muted
1303
+ });
1304
+ this.gap(size * .75);
1305
+ } else if (tag === "pre") this.code(element, frame, style);
1306
+ else if (tag === "hr") this.rule(frame);
1307
+ else if (TABLE_TAG.test(tag)) this.table(element, aligned, style);
1308
+ else this.flow(element.children, aligned, style);
1309
+ if (breaks(element, "after")) this.pageBreak();
1310
+ }
1311
+ runs(nodes, style) {
1312
+ const runs = [];
1313
+ for (const node of nodes) if (typeof node === "string") runs.push({
1314
+ text: node,
1315
+ style
1316
+ });
1317
+ else this.inline(node, style, runs);
1318
+ return runs;
1319
+ }
1320
+ gap(value) {
1321
+ if (!this.fresh) this.pending = Math.max(this.pending, value);
1322
+ }
1323
+ open(frame) {
1324
+ this.flushGap(frame);
1325
+ this.fresh = true;
1326
+ }
1327
+ flushGap(frame) {
1328
+ if (this.pending > 0) this.items.push(this.spaceItem(this.pending, frame.bars));
1329
+ this.pending = 0;
1330
+ }
1331
+ emit(item, frame) {
1332
+ this.flushGap(frame);
1333
+ this.fresh = false;
1334
+ this.items.push(item);
1335
+ }
1336
+ pageBreak() {
1337
+ this.pending = 0;
1338
+ this.fresh = true;
1339
+ this.items.push({
1340
+ ...this.spaceItem(0, []),
1341
+ space: false,
1342
+ pageBreak: true
1343
+ });
1344
+ }
1345
+ spaceItem(height, bars) {
1346
+ return {
1347
+ height,
1348
+ space: true,
1349
+ draw: (page, top) => this.drawBars(page, bars, top, height)
1350
+ };
1351
+ }
1352
+ drawBars(page, bars, top, height) {
1353
+ for (const x of bars) page.ops.push(`${rgb(this.border)} rg ${num(x)} ${num(top - height)} 3 ${num(height)} re f`);
1354
+ }
1355
+ fontOf(style) {
1356
+ const { regular, bold, italic, mono, fakeBold } = this.fonts;
1357
+ if (style.code && mono) return {
1358
+ font: mono,
1359
+ fakeBold: false,
1360
+ slant: style.italic
1361
+ };
1362
+ if (style.bold) return {
1363
+ font: bold,
1364
+ fakeBold,
1365
+ slant: style.italic
1366
+ };
1367
+ if (style.italic) return italic ? {
1368
+ font: italic,
1369
+ fakeBold: false,
1370
+ slant: false
1371
+ } : {
1372
+ font: regular,
1373
+ fakeBold: false,
1374
+ slant: true
1375
+ };
1376
+ return {
1377
+ font: regular,
1378
+ fakeBold: false,
1379
+ slant: false
1380
+ };
1381
+ }
1382
+ pieceSize(style) {
1383
+ return this.size * style.scale * (style.code ? .9 : 1);
1384
+ }
1385
+ piece(text, style, space) {
1386
+ const size = this.pieceSize(style);
1387
+ return {
1388
+ text,
1389
+ style,
1390
+ size,
1391
+ space,
1392
+ width: this.fontOf(style).font.width(text, size)
1393
+ };
1394
+ }
1395
+ tokens(runs, pre) {
1396
+ const tokens = [];
1397
+ for (const run of runs) {
1398
+ if (run.brk) {
1399
+ tokens.push(run.brk);
1400
+ continue;
1401
+ }
1402
+ (pre ? run.text.replace(/\r\n?/g, "\n").replace(/\t/g, " ").split("\n") : [run.text.replace(/[ \t\n\r\f]+/g, " ")]).forEach((part, index) => {
1403
+ if (index > 0) tokens.push("hard");
1404
+ for (const word of part.split(pre ? /( +)/ : /( )/)) if (word) tokens.push(this.piece(word, run.style, word.trim() === ""));
1405
+ });
1406
+ }
1407
+ return tokens;
1408
+ }
1409
+ layout(runs, width, pre) {
1410
+ const lines = [];
1411
+ let pieces = [];
1412
+ let x = 0;
1413
+ const push = (force) => {
1414
+ if (!pre) while (pieces.length && pieces[pieces.length - 1].space) x -= pieces.pop().width;
1415
+ if (!pieces.length && !force) return;
1416
+ const size = Math.max(this.size * (pre ? .9 : 1), ...pieces.map((piece) => piece.size));
1417
+ lines.push({
1418
+ pieces,
1419
+ width: x,
1420
+ size,
1421
+ height: size * this.lineFactor
1422
+ });
1423
+ pieces = [];
1424
+ x = 0;
1425
+ };
1426
+ for (const token of this.tokens(runs, pre)) {
1427
+ if (token === "hard" || token === "soft") {
1428
+ push(token === "hard");
1429
+ continue;
1430
+ }
1431
+ if (token.space && !pre && (!pieces.length || pieces[pieces.length - 1].space)) continue;
1432
+ if (x + token.width > width && pieces.some((piece) => !piece.space)) {
1433
+ push(true);
1434
+ if (token.space && !pre) continue;
1435
+ }
1436
+ if (token.width > width && !token.space) {
1437
+ let part = "";
1438
+ for (const char of token.text) {
1439
+ const next = part + char;
1440
+ if (part && x + this.piece(next, token.style, false).width > width) {
1441
+ const piece = this.piece(part, token.style, false);
1442
+ pieces.push(piece);
1443
+ x += piece.width;
1444
+ push(true);
1445
+ part = char;
1446
+ } else part = next;
1447
+ }
1448
+ const rest = this.piece(part, token.style, false);
1449
+ pieces.push(rest);
1450
+ x += rest.width;
1451
+ continue;
1452
+ }
1453
+ pieces.push(token);
1454
+ x += token.width;
1455
+ }
1456
+ push(false);
1457
+ return lines;
1458
+ }
1459
+ paragraph(runs, frame, pre, keep = false, fill = null, inset = 0) {
1460
+ const lines = this.layout(runs, frame.width - inset * 2, pre);
1461
+ lines.forEach((line, index) => {
1462
+ const marker = this.marker;
1463
+ this.marker = null;
1464
+ this.emit({
1465
+ height: line.height,
1466
+ keep: keep && index === lines.length - 1,
1467
+ draw: (page, top) => {
1468
+ if (fill) page.ops.push(`${rgb(fill)} rg ${num(frame.left)} ${num(top - line.height)} ${num(frame.width)} ${num(line.height)} re f`);
1469
+ this.drawBars(page, frame.bars, top, line.height);
1470
+ const baseline = this.drawLine(page, line, frame, top, inset);
1471
+ if (marker) this.drawMarker(page, marker, baseline);
1472
+ }
1473
+ }, frame);
1474
+ });
1475
+ }
1476
+ baseline(line, top) {
1477
+ const { ascent, descent } = this.fonts;
1478
+ return top - (line.height - (ascent + descent) * line.size) / 2 - ascent * line.size;
1479
+ }
1480
+ drawLine(page, line, frame, top, inset) {
1481
+ const baseline = this.baseline(line, top);
1482
+ const room = frame.width - inset * 2;
1483
+ let x = frame.left + inset + (frame.align === "center" ? (room - line.width) / 2 : frame.align === "end" ? room - line.width : 0);
1484
+ const segments = [];
1485
+ for (const piece of line.pieces) {
1486
+ const last = segments[segments.length - 1];
1487
+ if (last && sameStyle(last.style, piece.style)) segments[segments.length - 1] = {
1488
+ ...last,
1489
+ text: last.text + piece.text,
1490
+ width: last.width + piece.width
1491
+ };
1492
+ else segments.push(piece);
1493
+ }
1494
+ for (const segment of segments) {
1495
+ this.drawSegment(page, segment, x, baseline);
1496
+ x += segment.width;
1497
+ }
1498
+ return baseline;
1499
+ }
1500
+ drawSegment(page, piece, x, baseline) {
1501
+ const { style, size, width } = piece;
1502
+ const { ascent, descent } = this.fonts;
1503
+ const y = baseline + style.rise * this.size;
1504
+ const color = style.color ?? this.text;
1505
+ if (style.code && !style.block) page.ops.push(`${rgb(this.codeFill)} rg ${num(x - 1.5)} ${num(y - descent * size)} ${num(width + 3)} ${num((ascent + descent) * size)} re f`);
1506
+ const { font, fakeBold, slant } = this.fontOf(style);
1507
+ const effect = fakeBold ? `2 Tr ${num(size * .03)} w ${rgb(color)} RG ` : "";
1508
+ const position = slant ? `1 0 0.2 1 ${num(x)} ${num(y)} Tm` : `${num(x)} ${num(y)} Td`;
1509
+ page.ops.push(`q BT ${effect}/${font.resource} ${num(size)} Tf ${rgb(color)} rg ${position} <${font.encode(piece.text)}> Tj ET Q`);
1510
+ const stroke = (offset) => page.ops.push(`${rgb(color)} RG ${num(size * .06)} w ${num(x)} ${num(y + offset)} m ${num(x + width)} ${num(y + offset)} l S`);
1511
+ if (style.underline) stroke(-size * .12);
1512
+ if (style.strike) stroke(size * .28);
1513
+ if (style.link) page.links.push({
1514
+ x,
1515
+ y: y - descent * size,
1516
+ width,
1517
+ height: (ascent + descent) * size,
1518
+ uri: style.link
1519
+ });
1520
+ }
1521
+ drawMarker(page, marker, baseline) {
1522
+ const size = this.size;
1523
+ if (marker.label !== null) {
1524
+ const font = this.fonts.regular;
1525
+ page.ops.push(`BT /${font.resource} ${num(size)} Tf ${rgb(this.text)} rg ${num(marker.right - font.width(marker.label, size))} ${num(baseline)} Td <${font.encode(marker.label)}> Tj ET`);
1526
+ return;
1527
+ }
1528
+ const r = size * .17;
1529
+ const cx = marker.right - r - 1;
1530
+ const cy = baseline + size * .33;
1531
+ const shape = marker.depth % 3;
1532
+ if (shape === 2) {
1533
+ page.ops.push(`${rgb(this.text)} rg ${num(cx - r)} ${num(cy - r)} ${num(r * 2)} ${num(r * 2)} re f`);
1534
+ return;
1535
+ }
1536
+ const k = r * .5523;
1537
+ const circle = `${num(cx + r)} ${num(cy)} m ${num(cx + r)} ${num(cy + k)} ${num(cx + k)} ${num(cy + r)} ${num(cx)} ${num(cy + r)} c ${num(cx - k)} ${num(cy + r)} ${num(cx - r)} ${num(cy + k)} ${num(cx - r)} ${num(cy)} c ${num(cx - r)} ${num(cy - k)} ${num(cx - k)} ${num(cy - r)} ${num(cx)} ${num(cy - r)} c ${num(cx + k)} ${num(cy - r)} ${num(cx + r)} ${num(cy - k)} ${num(cx + r)} ${num(cy)} c`;
1538
+ page.ops.push(shape === 0 ? `${rgb(this.text)} rg ${circle} f` : `${rgb(this.text)} RG ${num(size * .07)} w ${circle} S`);
1539
+ }
1540
+ list(element, frame, style) {
1541
+ const ordered = element.tag === "ol";
1542
+ const items = element.children.filter((child) => typeof child !== "string" && child.tag === "li");
1543
+ const start = Number.parseInt(element.attrs["start"] ?? "", 10);
1544
+ const first = Number.isFinite(start) ? start : 1;
1545
+ const widest = ordered ? Math.max(...items.map((_, index) => this.fonts.regular.width(`${first + index}.`, this.size))) : 0;
1546
+ const indent = Math.max(16, widest + 8);
1547
+ this.gap(this.depth ? this.size * .25 : this.size * .75);
1548
+ this.depth++;
1549
+ let number = first;
1550
+ for (const child of element.children) {
1551
+ if (typeof child === "string") continue;
1552
+ if (child.tag === "li") this.listItem(child, frame, style, indent, ordered ? `${number++}.` : null);
1553
+ else this.flow([child], {
1554
+ ...frame,
1555
+ left: frame.left + indent,
1556
+ width: frame.width - indent
1557
+ }, style);
1558
+ }
1559
+ this.depth--;
1560
+ this.gap(this.depth ? this.size * .25 : this.size * .75);
1561
+ }
1562
+ listItem(element, frame, style, indent, label) {
1563
+ const inner = {
1564
+ ...frame,
1565
+ left: frame.left + indent,
1566
+ width: frame.width - indent
1567
+ };
1568
+ this.gap(this.size * .3);
1569
+ this.open(frame);
1570
+ this.marker = {
1571
+ label,
1572
+ depth: Math.max(0, this.depth - 1),
1573
+ right: inner.left - 5
1574
+ };
1575
+ this.flow(element.children, inner, style);
1576
+ if (this.marker) this.paragraph([{
1577
+ text: "",
1578
+ style,
1579
+ brk: "hard"
1580
+ }], inner, false);
1581
+ this.gap(this.size * .3);
1582
+ }
1583
+ code(element, frame, style) {
1584
+ const pad = 8;
1585
+ const codeStyle = {
1586
+ ...style,
1587
+ code: true,
1588
+ block: true,
1589
+ color: null
1590
+ };
1591
+ const runs = this.runs(element.children, codeStyle);
1592
+ const first = runs.find((run) => !run.brk);
1593
+ if (first) first.text = first.text.replace(/^\r?\n/, "");
1594
+ const last = [...runs].reverse().find((run) => !run.brk);
1595
+ if (last) last.text = last.text.replace(/\r?\n$/, "");
1596
+ this.gap(this.size * .75);
1597
+ const fillItem = () => ({
1598
+ height: pad * .75,
1599
+ draw: (page, top) => {
1600
+ page.ops.push(`${rgb(this.codeFill)} rg ${num(frame.left)} ${num(top - pad * .75)} ${num(frame.width)} ${num(pad * .75)} re f`);
1601
+ this.drawBars(page, frame.bars, top, pad * .75);
1602
+ }
1603
+ });
1604
+ this.emit(fillItem(), frame);
1605
+ this.paragraph(runs, {
1606
+ ...frame,
1607
+ align: "start"
1608
+ }, true, false, this.codeFill, pad);
1609
+ this.emit(fillItem(), frame);
1610
+ this.gap(this.size * .75);
1611
+ }
1612
+ rule(frame) {
1613
+ this.gap(this.size * .9);
1614
+ this.emit({
1615
+ height: 1,
1616
+ draw: (page, top) => page.ops.push(`${rgb(this.border)} RG 0.75 w ${num(frame.left)} ${num(top - .5)} m ${num(frame.left + frame.width)} ${num(top - .5)} l S`)
1617
+ }, frame);
1618
+ this.gap(this.size * .9);
1619
+ }
1620
+ table(element, frame, style) {
1621
+ const rows = [];
1622
+ const captions = [];
1623
+ const readRow = (tr, head) => {
1624
+ const cells = tr.children.filter((cell) => typeof cell !== "string" && (cell.tag === "td" || cell.tag === "th")).map((cell) => {
1625
+ const header = cell.tag === "th" || head;
1626
+ return {
1627
+ header,
1628
+ span: Math.max(1, Number.parseInt(cell.attrs["colspan"] ?? "1", 10) || 1),
1629
+ align: alignOf(cell, "start"),
1630
+ runs: this.runs(cell.children, header ? {
1631
+ ...style,
1632
+ bold: true
1633
+ } : style)
1634
+ };
1635
+ });
1636
+ if (cells.length) rows.push({
1637
+ cells,
1638
+ head
1639
+ });
1640
+ };
1641
+ const walk = (nodes, head) => {
1642
+ for (const node of nodes) {
1643
+ if (typeof node === "string") continue;
1644
+ if (node.tag === "tr") readRow(node, head);
1645
+ else if (node.tag === "caption") captions.push(node);
1646
+ else if (node.tag === "thead" || node.tag === "tbody" || node.tag === "tfoot") walk(node.children, node.tag === "thead");
1647
+ }
1648
+ };
1649
+ walk(element.children, false);
1650
+ if (!rows.some((row) => row.head) && rows.length > 1 && rows[0].cells.every((cell) => cell.header)) rows[0].head = true;
1651
+ const count = Math.max(0, ...rows.map((row) => row.cells.reduce((sum, cell) => sum + cell.span, 0)));
1652
+ this.gap(this.size * .75);
1653
+ for (const caption of captions) this.block(caption, {
1654
+ ...frame,
1655
+ align: "center"
1656
+ }, style);
1657
+ if (!count) {
1658
+ this.gap(this.size * .75);
1659
+ return;
1660
+ }
1661
+ const padX = 5;
1662
+ const padY = 3.5;
1663
+ const natural = new Array(count).fill(0);
1664
+ const minimum = new Array(count).fill(0);
1665
+ for (const row of rows) {
1666
+ let column = 0;
1667
+ for (const cell of row.cells) {
1668
+ if (cell.span === 1 && column < count) {
1669
+ const lines = this.layout(cell.runs, Number.POSITIVE_INFINITY, false);
1670
+ natural[column] = Math.max(natural[column], ...lines.map((line) => line.width + 10));
1671
+ const words = lines.flatMap((line) => line.pieces.filter((piece) => !piece.space).map((piece) => piece.width));
1672
+ minimum[column] = Math.max(minimum[column], ...words.map((width) => width + 10));
1673
+ }
1674
+ column += cell.span;
1675
+ }
1676
+ }
1677
+ const xs = this.columnWidths(natural, minimum, frame.width).reduce((acc, width, index) => [...acc, acc[index] + width], [frame.left]);
1678
+ const header = [];
1679
+ const items = rows.map((row) => {
1680
+ let column = 0;
1681
+ const cells = row.cells.map((cell) => {
1682
+ const from = Math.min(column, count - 1);
1683
+ column += cell.span;
1684
+ const to = Math.min(column, count);
1685
+ const x = xs[from];
1686
+ const width = xs[to] - x;
1687
+ return {
1688
+ x,
1689
+ width,
1690
+ align: cell.align,
1691
+ header: cell.header,
1692
+ lines: this.layout(cell.runs, Math.max(1, width - 10), false)
1693
+ };
1694
+ });
1695
+ const item = this.rowItem(cells, padX, padY, row.head ? void 0 : header);
1696
+ if (row.head) header.push(item);
1697
+ return item;
1698
+ });
1699
+ if (header.length) header[header.length - 1].keep = true;
1700
+ for (const item of items) this.emit(item, frame);
1701
+ this.gap(this.size * .75);
1702
+ }
1703
+ columnWidths(natural, minimum, available) {
1704
+ const sum = (values) => values.reduce((total, value) => total + value, 0);
1705
+ const wanted = natural.map((value, index) => Math.max(value, minimum[index], 12));
1706
+ if (sum(wanted) <= available) {
1707
+ const total = sum(wanted);
1708
+ return wanted.map((value) => value * available / total);
1709
+ }
1710
+ const floor = minimum.map((value) => Math.max(12, Math.min(value, available / natural.length)));
1711
+ const room = available - sum(floor);
1712
+ const extra = wanted.map((value, index) => value - floor[index]);
1713
+ const extraSum = sum(extra);
1714
+ if (room <= 0 || extraSum <= 0) {
1715
+ const total = sum(floor);
1716
+ return floor.map((value) => value * available / total);
1717
+ }
1718
+ return floor.map((value, index) => value + extra[index] * room / extraSum);
1719
+ }
1720
+ rowItem(cells, padX, padY, header) {
1721
+ const contentHeight = (lines) => lines.reduce((total, line) => total + line.height, 0);
1722
+ const height = Math.max(this.size * this.lineFactor, ...cells.map((cell) => contentHeight(cell.lines))) + padY * 2;
1723
+ return {
1724
+ height,
1725
+ header,
1726
+ draw: (page, top) => {
1727
+ for (const cell of cells) {
1728
+ if (cell.header && this.headerFill) page.ops.push(`${rgb(this.headerFill)} rg ${num(cell.x)} ${num(top - height)} ${num(cell.width)} ${num(height)} re f`);
1729
+ let y = top - padY;
1730
+ for (const line of cell.lines) {
1731
+ this.drawLine(page, line, {
1732
+ left: cell.x,
1733
+ width: cell.width,
1734
+ bars: [],
1735
+ align: cell.align
1736
+ }, y, padX);
1737
+ y -= line.height;
1738
+ }
1739
+ }
1740
+ for (const cell of cells) page.ops.push(`${rgb(this.border)} RG 0.5 w ${num(cell.x)} ${num(top - height)} ${num(cell.width)} ${num(height)} re S`);
1741
+ },
1742
+ split: (room) => {
1743
+ const fit = room - padY * 2;
1744
+ const counts = cells.map((cell) => {
1745
+ let used = 0;
1746
+ let taken = 0;
1747
+ while (taken < cell.lines.length && used + cell.lines[taken].height <= fit) used += cell.lines[taken++].height;
1748
+ return taken;
1749
+ });
1750
+ if (counts.every((taken) => taken === 0) || counts.every((taken, index) => taken === cells[index].lines.length)) return null;
1751
+ const part = (from) => cells.map((cell, index) => ({
1752
+ ...cell,
1753
+ lines: from(cell, index)
1754
+ }));
1755
+ return [this.rowItem(part((cell, index) => cell.lines.slice(0, counts[index])), padX, padY, header), this.rowItem(part((cell, index) => cell.lines.slice(counts[index])), padX, padY, header)];
1756
+ }
1757
+ };
1758
+ }
1759
+ };
1760
+ function paginate(items, height, top, bottom) {
1761
+ const pages = [];
1762
+ let page = {
1763
+ ops: [],
1764
+ links: []
1765
+ };
1766
+ let y = 0;
1767
+ let atTop = true;
1768
+ const newPage = () => {
1769
+ page = {
1770
+ ops: [],
1771
+ links: []
1772
+ };
1773
+ pages.push(page);
1774
+ y = height - top;
1775
+ atTop = true;
1776
+ };
1777
+ const place = (item) => {
1778
+ item.draw(page, y);
1779
+ y -= item.height;
1780
+ atTop = false;
1781
+ };
1782
+ const breakPage = (item) => {
1783
+ newPage();
1784
+ for (const head of item.header ?? []) place(head);
1785
+ };
1786
+ newPage();
1787
+ for (let index = 0; index < items.length; index++) {
1788
+ let item = items[index];
1789
+ if (item.pageBreak) {
1790
+ if (!atTop) newPage();
1791
+ continue;
1792
+ }
1793
+ if (item.space) {
1794
+ if (item.height > y - bottom) newPage();
1795
+ else place(item);
1796
+ continue;
1797
+ }
1798
+ let keepRoom = 0;
1799
+ if (item.keep) {
1800
+ let next = index + 1;
1801
+ while (items[next]?.space) keepRoom += items[next++].height;
1802
+ keepRoom = items[next] && !items[next].pageBreak ? keepRoom + Math.min(items[next].height, 30) : 0;
1803
+ }
1804
+ if (!atTop && item.height + keepRoom > y - bottom) {
1805
+ const parts = item.split && !keepRoom ? item.split(y - bottom) : null;
1806
+ if (parts) {
1807
+ place(parts[0]);
1808
+ item = parts[1];
1809
+ }
1810
+ breakPage(item);
1811
+ }
1812
+ while (item.split && item.height > y - bottom) {
1813
+ const parts = item.split(y - bottom);
1814
+ if (!parts) break;
1815
+ place(parts[0]);
1816
+ breakPage(item);
1817
+ item = parts[1];
1818
+ }
1819
+ place(item);
1820
+ }
1821
+ return pages;
1822
+ }
1823
+ async function writeHtmlPdf(source, options = {}, date = /* @__PURE__ */ new Date()) {
1824
+ const font = await (options.font ?? loadDefaultExportFont)();
1825
+ const loaded = await loadPdfFonts(font);
1826
+ const regular = new PdfFont(loaded.regular, "F1", "TXREGU");
1827
+ const bold = loaded.bold ? new PdfFont(loaded.bold, "F2", "TXBOLD") : regular;
1828
+ const italicFont = loadOptionalFont(font.italic);
1829
+ const monoFont = loadOptionalFont(font.mono);
1830
+ const fonts = {
1831
+ regular,
1832
+ bold,
1833
+ italic: italicFont ? new PdfFont(italicFont, "F3", "TXITAL") : null,
1834
+ mono: monoFont ? new PdfFont(monoFont, "F4", "TXMONO") : null,
1835
+ fakeBold: bold === regular,
1836
+ ascent: loaded.regular.ascent / loaded.regular.unitsPerEm,
1837
+ descent: -loaded.regular.descent / loaded.regular.unitsPerEm
1838
+ };
1839
+ const page = pageGeometry(options.pageSize, options.orientation === "landscape" ? "landscape" : "portrait", options.margin ?? 48, 0);
1840
+ const [top, right, bottom, left] = page.margin;
1841
+ const layout = new HtmlPdfLayout(fonts, options);
1842
+ const tree = typeof source === "string" ? parseHtml(source) : readDom(source);
1843
+ layout.flow(tree.children, {
1844
+ left,
1845
+ width: page.width - left - right,
1846
+ bars: [],
1847
+ align: "start"
1848
+ }, PLAIN);
1849
+ const pages = paginate(layout.items, page.height, top, bottom);
1850
+ if (options.pageNumbers !== false) {
1851
+ const muted = hexColor(options.mutedColor, "667085");
1852
+ const size = layout.size * .85;
1853
+ pages.forEach((pdfPage, index) => {
1854
+ const label = `${index + 1} / ${pages.length}`;
1855
+ pdfPage.ops.push(`BT /${regular.resource} ${num(size)} Tf ${rgb(muted)} rg ${num((page.width - regular.width(label, size)) / 2)} ${num(Math.max(12, bottom / 2 - size / 2))} Td <${regular.encode(label)}> Tj ET`);
1856
+ });
1857
+ }
1858
+ const used = [
1859
+ regular,
1860
+ bold,
1861
+ fonts.italic,
1862
+ fonts.mono
1863
+ ].filter((pdfFont, index) => !!pdfFont && (index === 0 || pdfFont.used.size > 0));
1864
+ return assemblePdf({
1865
+ width: page.width,
1866
+ height: page.height,
1867
+ pages,
1868
+ fonts: [...new Set(used)],
1869
+ title: options.title,
1870
+ author: options.author,
1871
+ compress: options.compress,
1872
+ date
1873
+ });
1874
+ }
673
1875
  function wrapText(text, width, measure) {
674
1876
  const lines = [];
675
1877
  for (const paragraph of text.replace(/\t/g, " ").split(/\r?\n/)) {
@@ -724,12 +1926,6 @@ function layoutColumns(table, texts, regular, bold, size, padding, available) {
724
1926
  if (total > available) widths = widths.map((width) => width * available / total);
725
1927
  return { widths };
726
1928
  }
727
- async function loadPdfFonts(font) {
728
- return {
729
- regular: parseTrueType(toBytes(font.regular)),
730
- bold: font.bold ? parseTrueType(toBytes(font.bold)) : null
731
- };
732
- }
733
1929
  async function writePdf(table, options, font, context = {
734
1930
  yes: "Yes",
735
1931
  no: "No"
@@ -842,78 +2038,19 @@ async function writePdf(table, options, font, context = {
842
2038
  const footerSize = size * .85;
843
2039
  drawText(label, (page.width - regular.width(label, footerSize)) / 2, Math.max(12, bottom / 2 - footerSize / 2), regular, footerSize, muted);
844
2040
  });
845
- const objects = [];
846
- const reserve = () => {
847
- objects.push(null);
848
- return objects.length;
849
- };
850
- const set = (id, body) => {
851
- objects[id - 1] = typeof body === "string" ? utf8(`${id} 0 obj\n${body}\nendobj\n`) : body;
852
- };
853
- const stream = async (id, dict, data) => {
854
- const packed = options.compress === false ? null : await compress(data, "deflate");
855
- const body = packed ?? data;
856
- set(id, concatBytes([
857
- utf8(`${id} 0 obj\n<< ${dict} /Length ${body.length}${packed ? " /Filter /FlateDecode" : ""} >>\nstream\n`),
858
- body,
859
- utf8("\nendstream\nendobj\n")
860
- ]));
861
- };
862
- const catalog = reserve();
863
- const pagesId = reserve();
864
- const info = reserve();
865
- const fontIds = /* @__PURE__ */ new Map();
866
- for (const pdfFont of /* @__PURE__ */ new Set([regular, bold])) fontIds.set(pdfFont, reserve());
867
- const pageIds = pages.map(() => [reserve(), reserve()]);
868
- for (const [index, [pageId, contentId]] of pageIds.entries()) {
869
- const fontsDict = [...fontIds].map(([pdfFont, id]) => `/${pdfFont.resource} ${id} 0 R`).join(" ");
870
- set(pageId, `<< /Type /Page /Parent ${pagesId} 0 R /MediaBox [0 0 ${num(page.width)} ${num(page.height)}] /Resources << /Font << ${fontsDict} >> >> /Contents ${contentId} 0 R >>`);
871
- await stream(contentId, "", utf8(pages[index].join("\n")));
872
- }
873
- for (const [pdfFont, id] of fontIds) {
874
- const ttf = pdfFont.ttf;
875
- const scale = (value) => Math.round(value * 1e3 / ttf.unitsPerEm);
876
- const glyphs = [...pdfFont.used.keys()].sort((a, b) => a - b);
877
- const baseFont = `${pdfFont.tag}+${ttf.name}`;
878
- const cid = reserve();
879
- const descriptor = reserve();
880
- const file = reserve();
881
- const toUnicode = reserve();
882
- set(id, `<< /Type /Font /Subtype /Type0 /BaseFont /${baseFont} /Encoding /Identity-H /DescendantFonts [${cid} 0 R] /ToUnicode ${toUnicode} 0 R >>`);
883
- const w = glyphs.map((glyph) => `${glyph} [${scale(ttf.advance(glyph))}]`).join(" ");
884
- set(cid, `<< /Type /Font /Subtype /CIDFontType2 /BaseFont /${baseFont} /CIDSystemInfo << /Registry (Adobe) /Ordering (Identity) /Supplement 0 >> /FontDescriptor ${descriptor} 0 R /DW ${scale(ttf.advance(0))} /W [${w}] /CIDToGIDMap /Identity >>`);
885
- set(descriptor, `<< /Type /FontDescriptor /FontName /${baseFont} /Flags 32 /FontBBox [${ttf.bbox.map(scale).join(" ")}] /ItalicAngle 0 /Ascent ${scale(ttf.ascent)} /Descent ${scale(ttf.descent)} /CapHeight ${scale(ttf.capHeight)} /StemV 80 /FontFile2 ${file} 0 R >>`);
886
- const subset = ttf.subset(new Set(glyphs));
887
- await stream(file, `/Length1 ${subset.length}`, subset);
888
- const entries = glyphs.map((glyph) => `<${glyph.toString(16).padStart(4, "0")}> <${utf16Hex(String.fromCodePoint(pdfFont.used.get(glyph) ?? 65533))}>`);
889
- const chunks = [];
890
- for (let index = 0; index < entries.length; index += 100) {
891
- const chunk = entries.slice(index, index + 100);
892
- chunks.push(`${chunk.length} beginbfchar\n${chunk.join("\n")}\nendbfchar`);
893
- }
894
- await stream(toUnicode, "", utf8(`/CIDInit /ProcSet findresource begin\n12 dict begin\nbegincmap\n/CIDSystemInfo << /Registry (Adobe) /Ordering (UCS) /Supplement 0 >> def\n/CMapName /Adobe-Identity-UCS def\n/CMapType 2 def\n1 begincodespacerange\n<0000> <FFFF>\nendcodespacerange\n${chunks.join("\n")}\nendcmap\nCMapName currentdict /CMap defineresource pop\nend\nend`));
895
- }
896
- set(catalog, `<< /Type /Catalog /Pages ${pagesId} 0 R >>`);
897
- set(pagesId, `<< /Type /Pages /Kids [${pageIds.map(([pageId]) => `${pageId} 0 R`).join(" ")}] /Count ${pageIds.length} >>`);
898
- const infoParts = [`/Producer (tectra)`, `/CreationDate (${pdfDate(date)})`];
899
- if (options.title) infoParts.push(`/Title ${pdfString(options.title)}`);
900
- if (options.author) infoParts.push(`/Author ${pdfString(options.author)}`);
901
- set(info, `<< ${infoParts.join(" ")} >>`);
902
- const header = utf8("%PDF-1.7\n%âãÏÓ\n");
903
- const offsets = [];
904
- let offset = header.length;
905
- for (const object of objects) {
906
- offsets.push(offset);
907
- offset += object.length;
908
- }
909
- const xref = [`xref\n0 ${objects.length + 1}\n0000000000 65535 f \n`, ...offsets.map((value) => `${String(value).padStart(10, "0")} 00000 n \n`)].join("");
910
- const trailer = `trailer\n<< /Size ${objects.length + 1} /Root ${catalog} 0 R /Info ${info} 0 R >>\nstartxref\n${offset}\n%%EOF\n`;
911
- const bytes = concatBytes([
912
- header,
913
- ...objects,
914
- utf8(xref + trailer)
915
- ]);
916
- return new Blob([bytes], { type: "application/pdf" });
2041
+ return assemblePdf({
2042
+ width: page.width,
2043
+ height: page.height,
2044
+ pages: pages.map((pageOps) => ({
2045
+ ops: pageOps,
2046
+ links: []
2047
+ })),
2048
+ fonts: [.../* @__PURE__ */ new Set([regular, bold])],
2049
+ title: options.title,
2050
+ author: options.author,
2051
+ compress: options.compress,
2052
+ date
2053
+ });
917
2054
  }
918
2055
  function printHtml(document, html) {
919
2056
  return new Promise((resolve) => {
@@ -1231,9 +2368,6 @@ function mergeExportOptions(...layers) {
1231
2368
  }
1232
2369
  return merged;
1233
2370
  }
1234
- function loadDefaultExportFont() {
1235
- return import("@tectra-ng/ui/export-font").then((module) => module.TX_EXPORT_FONT);
1236
- }
1237
2371
  var TxExportService = class TxExportService {
1238
2372
  document = inject(DOCUMENT);
1239
2373
  defaults = inject(TX_EXPORT_OPTIONS);
@@ -1327,6 +2461,25 @@ var TxExportService = class TxExportService {
1327
2461
  };
1328
2462
  }
1329
2463
  }
2464
+ async exportHtmlPdf(source, options = {}) {
2465
+ const { blob, filename } = await this.htmlPdfFile(source, options);
2466
+ downloadBlob(this.document, blob, filename);
2467
+ return filename;
2468
+ }
2469
+ async htmlPdfFile(source, options = {}) {
2470
+ const { filename, ...pdf } = options;
2471
+ const defaults = {
2472
+ title: this.defaults.title,
2473
+ ...this.defaults.pdf
2474
+ };
2475
+ return {
2476
+ filename: withExtension(filename || this.defaults.filename || "ExportedData", "pdf"),
2477
+ blob: await writeHtmlPdf(source, {
2478
+ ...defaults,
2479
+ ...pdf
2480
+ })
2481
+ };
2482
+ }
1330
2483
  textContext(options = {}) {
1331
2484
  const translations = this.locale.translations();
1332
2485
  return {
@@ -1370,7 +2523,7 @@ var TxExportService = class TxExportService {
1370
2523
  }
1371
2524
  static ɵfac = i0.ɵɵngDeclareFactory({
1372
2525
  minVersion: "12.0.0",
1373
- version: "22.2.5",
2526
+ version: "22.2.6",
1374
2527
  ngImport: i0,
1375
2528
  type: TxExportService,
1376
2529
  deps: [],
@@ -1378,7 +2531,7 @@ var TxExportService = class TxExportService {
1378
2531
  });
1379
2532
  static ɵprov = i0.ɵɵngDeclareInjectable({
1380
2533
  minVersion: "12.0.0",
1381
- version: "22.2.5",
2534
+ version: "22.2.6",
1382
2535
  ngImport: i0,
1383
2536
  type: TxExportService,
1384
2537
  providedIn: "root"
@@ -1386,7 +2539,7 @@ var TxExportService = class TxExportService {
1386
2539
  };
1387
2540
  i0.ɵɵngDeclareClassMetadata({
1388
2541
  minVersion: "12.0.0",
1389
- version: "22.2.5",
2542
+ version: "22.2.6",
1390
2543
  ngImport: i0,
1391
2544
  type: TxExportService,
1392
2545
  decorators: [{
@@ -1495,7 +2648,7 @@ var TxExportAction = class TxExportAction {
1495
2648
  }
1496
2649
  static ɵfac = i0.ɵɵngDeclareFactory({
1497
2650
  minVersion: "12.0.0",
1498
- version: "22.2.5",
2651
+ version: "22.2.6",
1499
2652
  ngImport: i0,
1500
2653
  type: TxExportAction,
1501
2654
  deps: [],
@@ -1503,7 +2656,7 @@ var TxExportAction = class TxExportAction {
1503
2656
  });
1504
2657
  static ɵdir = i0.ɵɵngDeclareDirective({
1505
2658
  minVersion: "17.1.0",
1506
- version: "22.2.5",
2659
+ version: "22.2.6",
1507
2660
  type: TxExportAction,
1508
2661
  isStandalone: true,
1509
2662
  inputs: {
@@ -1624,7 +2777,7 @@ var TxExportAction = class TxExportAction {
1624
2777
  };
1625
2778
  i0.ɵɵngDeclareClassMetadata({
1626
2779
  minVersion: "12.0.0",
1627
- version: "22.2.5",
2780
+ version: "22.2.6",
1628
2781
  ngImport: i0,
1629
2782
  type: TxExportAction,
1630
2783
  decorators: [{
@@ -1811,7 +2964,7 @@ var TxExportButtonBase = class TxExportButtonBase extends TxExportAction {
1811
2964
  ariaLabel = computed(() => this.label() ? null : this.resolvedTooltip(), ...ngDevMode ? [{ debugName: "ariaLabel" }] : /* istanbul ignore next */ []);
1812
2965
  static ɵfac = i0.ɵɵngDeclareFactory({
1813
2966
  minVersion: "12.0.0",
1814
- version: "22.2.5",
2967
+ version: "22.2.6",
1815
2968
  ngImport: i0,
1816
2969
  type: TxExportButtonBase,
1817
2970
  deps: null,
@@ -1819,7 +2972,7 @@ var TxExportButtonBase = class TxExportButtonBase extends TxExportAction {
1819
2972
  });
1820
2973
  static ɵdir = i0.ɵɵngDeclareDirective({
1821
2974
  minVersion: "17.1.0",
1822
- version: "22.2.5",
2975
+ version: "22.2.6",
1823
2976
  type: TxExportButtonBase,
1824
2977
  isStandalone: true,
1825
2978
  inputs: { pt: {
@@ -1835,7 +2988,7 @@ var TxExportButtonBase = class TxExportButtonBase extends TxExportAction {
1835
2988
  };
1836
2989
  i0.ɵɵngDeclareClassMetadata({
1837
2990
  minVersion: "12.0.0",
1838
- version: "22.2.5",
2991
+ version: "22.2.6",
1839
2992
  ngImport: i0,
1840
2993
  type: TxExportButtonBase,
1841
2994
  decorators: [{ type: Directive }],
@@ -1853,7 +3006,7 @@ var TxExportButton = class TxExportButton extends TxExportButtonBase {
1853
3006
  resolvedFormat = computed(() => this.format(), ...ngDevMode ? [{ debugName: "resolvedFormat" }] : /* istanbul ignore next */ []);
1854
3007
  static ɵfac = i0.ɵɵngDeclareFactory({
1855
3008
  minVersion: "12.0.0",
1856
- version: "22.2.5",
3009
+ version: "22.2.6",
1857
3010
  ngImport: i0,
1858
3011
  type: TxExportButton,
1859
3012
  deps: null,
@@ -1861,7 +3014,7 @@ var TxExportButton = class TxExportButton extends TxExportButtonBase {
1861
3014
  });
1862
3015
  static ɵcmp = i0.ɵɵngDeclareComponent({
1863
3016
  minVersion: "17.1.0",
1864
- version: "22.2.5",
3017
+ version: "22.2.6",
1865
3018
  type: TxExportButton,
1866
3019
  isStandalone: true,
1867
3020
  selector: "tx-export-button",
@@ -1947,7 +3100,7 @@ var TxExportButton = class TxExportButton extends TxExportButtonBase {
1947
3100
  };
1948
3101
  i0.ɵɵngDeclareClassMetadata({
1949
3102
  minVersion: "12.0.0",
1950
- version: "22.2.5",
3103
+ version: "22.2.6",
1951
3104
  ngImport: i0,
1952
3105
  type: TxExportButton,
1953
3106
  decorators: [{
@@ -1977,7 +3130,7 @@ var TxExportCsv = class TxExportCsv extends TxExportButtonBase {
1977
3130
  resolvedFormat = () => "csv";
1978
3131
  static ɵfac = i0.ɵɵngDeclareFactory({
1979
3132
  minVersion: "12.0.0",
1980
- version: "22.2.5",
3133
+ version: "22.2.6",
1981
3134
  ngImport: i0,
1982
3135
  type: TxExportCsv,
1983
3136
  deps: null,
@@ -1985,7 +3138,7 @@ var TxExportCsv = class TxExportCsv extends TxExportButtonBase {
1985
3138
  });
1986
3139
  static ɵcmp = i0.ɵɵngDeclareComponent({
1987
3140
  minVersion: "14.0.0",
1988
- version: "22.2.5",
3141
+ version: "22.2.6",
1989
3142
  type: TxExportCsv,
1990
3143
  isStandalone: true,
1991
3144
  selector: "tx-export-csv",
@@ -2064,7 +3217,7 @@ var TxExportCsv = class TxExportCsv extends TxExportButtonBase {
2064
3217
  };
2065
3218
  i0.ɵɵngDeclareClassMetadata({
2066
3219
  minVersion: "12.0.0",
2067
- version: "22.2.5",
3220
+ version: "22.2.6",
2068
3221
  ngImport: i0,
2069
3222
  type: TxExportCsv,
2070
3223
  decorators: [{
@@ -2086,7 +3239,7 @@ var TxExportExcel = class TxExportExcel extends TxExportButtonBase {
2086
3239
  resolvedFormat = () => "excel";
2087
3240
  static ɵfac = i0.ɵɵngDeclareFactory({
2088
3241
  minVersion: "12.0.0",
2089
- version: "22.2.5",
3242
+ version: "22.2.6",
2090
3243
  ngImport: i0,
2091
3244
  type: TxExportExcel,
2092
3245
  deps: null,
@@ -2094,7 +3247,7 @@ var TxExportExcel = class TxExportExcel extends TxExportButtonBase {
2094
3247
  });
2095
3248
  static ɵcmp = i0.ɵɵngDeclareComponent({
2096
3249
  minVersion: "14.0.0",
2097
- version: "22.2.5",
3250
+ version: "22.2.6",
2098
3251
  type: TxExportExcel,
2099
3252
  isStandalone: true,
2100
3253
  selector: "tx-export-excel",
@@ -2173,7 +3326,7 @@ var TxExportExcel = class TxExportExcel extends TxExportButtonBase {
2173
3326
  };
2174
3327
  i0.ɵɵngDeclareClassMetadata({
2175
3328
  minVersion: "12.0.0",
2176
- version: "22.2.5",
3329
+ version: "22.2.6",
2177
3330
  ngImport: i0,
2178
3331
  type: TxExportExcel,
2179
3332
  decorators: [{
@@ -2195,7 +3348,7 @@ var TxExportWord = class TxExportWord extends TxExportButtonBase {
2195
3348
  resolvedFormat = () => "word";
2196
3349
  static ɵfac = i0.ɵɵngDeclareFactory({
2197
3350
  minVersion: "12.0.0",
2198
- version: "22.2.5",
3351
+ version: "22.2.6",
2199
3352
  ngImport: i0,
2200
3353
  type: TxExportWord,
2201
3354
  deps: null,
@@ -2203,7 +3356,7 @@ var TxExportWord = class TxExportWord extends TxExportButtonBase {
2203
3356
  });
2204
3357
  static ɵcmp = i0.ɵɵngDeclareComponent({
2205
3358
  minVersion: "14.0.0",
2206
- version: "22.2.5",
3359
+ version: "22.2.6",
2207
3360
  type: TxExportWord,
2208
3361
  isStandalone: true,
2209
3362
  selector: "tx-export-word",
@@ -2282,7 +3435,7 @@ var TxExportWord = class TxExportWord extends TxExportButtonBase {
2282
3435
  };
2283
3436
  i0.ɵɵngDeclareClassMetadata({
2284
3437
  minVersion: "12.0.0",
2285
- version: "22.2.5",
3438
+ version: "22.2.6",
2286
3439
  ngImport: i0,
2287
3440
  type: TxExportWord,
2288
3441
  decorators: [{
@@ -2304,7 +3457,7 @@ var TxExportPdf = class TxExportPdf extends TxExportButtonBase {
2304
3457
  resolvedFormat = () => "pdf";
2305
3458
  static ɵfac = i0.ɵɵngDeclareFactory({
2306
3459
  minVersion: "12.0.0",
2307
- version: "22.2.5",
3460
+ version: "22.2.6",
2308
3461
  ngImport: i0,
2309
3462
  type: TxExportPdf,
2310
3463
  deps: null,
@@ -2312,7 +3465,7 @@ var TxExportPdf = class TxExportPdf extends TxExportButtonBase {
2312
3465
  });
2313
3466
  static ɵcmp = i0.ɵɵngDeclareComponent({
2314
3467
  minVersion: "14.0.0",
2315
- version: "22.2.5",
3468
+ version: "22.2.6",
2316
3469
  type: TxExportPdf,
2317
3470
  isStandalone: true,
2318
3471
  selector: "tx-export-pdf",
@@ -2391,7 +3544,7 @@ var TxExportPdf = class TxExportPdf extends TxExportButtonBase {
2391
3544
  };
2392
3545
  i0.ɵɵngDeclareClassMetadata({
2393
3546
  minVersion: "12.0.0",
2394
- version: "22.2.5",
3547
+ version: "22.2.6",
2395
3548
  ngImport: i0,
2396
3549
  type: TxExportPdf,
2397
3550
  decorators: [{
@@ -2448,7 +3601,7 @@ var TxExport = class TxExport extends TxExportAction {
2448
3601
  }, ...ngDevMode ? [{ debugName: "items" }] : /* istanbul ignore next */ []);
2449
3602
  static ɵfac = i0.ɵɵngDeclareFactory({
2450
3603
  minVersion: "12.0.0",
2451
- version: "22.2.5",
3604
+ version: "22.2.6",
2452
3605
  ngImport: i0,
2453
3606
  type: TxExport,
2454
3607
  deps: null,
@@ -2456,7 +3609,7 @@ var TxExport = class TxExport extends TxExportAction {
2456
3609
  });
2457
3610
  static ɵcmp = i0.ɵɵngDeclareComponent({
2458
3611
  minVersion: "17.1.0",
2459
- version: "22.2.5",
3612
+ version: "22.2.6",
2460
3613
  type: TxExport,
2461
3614
  isStandalone: true,
2462
3615
  selector: "tx-export",
@@ -2540,7 +3693,7 @@ var TxExport = class TxExport extends TxExportAction {
2540
3693
  };
2541
3694
  i0.ɵɵngDeclareClassMetadata({
2542
3695
  minVersion: "12.0.0",
2543
- version: "22.2.5",
3696
+ version: "22.2.6",
2544
3697
  ngImport: i0,
2545
3698
  type: TxExport,
2546
3699
  decorators: [{
@@ -2594,6 +3747,6 @@ i0.ɵɵngDeclareClassMetadata({
2594
3747
  }]
2595
3748
  }
2596
3749
  });
2597
- export { TX_EXPORT_EXTENSIONS, TX_EXPORT_FORMATS, TX_EXPORT_ICONS, TX_EXPORT_OPTIONS, TxExport, TxExportAction, TxExportButton, TxExportCsv, TxExportExcel, TxExportPdf, TxExportService, TxExportWord, buildExportTable, cellText, columnName, crc32, csvCell, docxDocument, downloadBlob, downloadCsv, escapeXml, excelSerial, excelWidths, exportMatrix, fieldsFor, hexColor, htmlTable, inferType, loadDefaultExportFont, localIso, matrixToCsv, mergeExportOptions, parseTrueType, provideTxExport, readExportField, safeExportText, sheetName, toDate, withExtension, wrapText, writeCsv, writeDocx, writeHtml, writeJson, writeMarkdown, writePdf, writeTsv, writeXlsx, xlsxParts, zip };
3750
+ export { TX_EXPORT_EXTENSIONS, TX_EXPORT_FORMATS, TX_EXPORT_ICONS, TX_EXPORT_OPTIONS, TxExport, TxExportAction, TxExportButton, TxExportCsv, TxExportExcel, TxExportPdf, TxExportService, TxExportWord, buildExportTable, cellText, columnName, crc32, csvCell, docxDocument, downloadBlob, downloadCsv, escapeXml, excelSerial, excelWidths, exportMatrix, fieldsFor, hexColor, htmlTable, inferType, loadDefaultExportFont, localIso, matrixToCsv, mergeExportOptions, parseTrueType, provideTxExport, readExportField, safeExportText, sheetName, toDate, withExtension, wrapText, writeCsv, writeDocx, writeHtml, writeHtmlPdf, writeJson, writeMarkdown, writePdf, writeTsv, writeXlsx, xlsxParts, zip };
2598
3751
 
2599
3752
  //# sourceMappingURL=tectra-ng-ui-export.mjs.map