umwd-components 0.1.827 → 0.1.828

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 (440) hide show
  1. package/dist/cjs/node_modules/object-assign/index.js +2 -2
  2. package/dist/cjs/node_modules/prop-types/factoryWithTypeCheckers.js +1 -1
  3. package/dist/cjs/node_modules/prop-types/index.js +1 -1
  4. package/dist/cjs/node_modules/prop-types/node_modules/react-is/index.js +1 -1
  5. package/dist/cjs/node_modules/safe-buffer/index.js +1 -1
  6. package/dist/cjs/src/components/e-commerce/products/EditReturnStockForm.js +1 -1
  7. package/dist/cjs/src/components/logistics/report/ReportMakingComponent.js +1 -1
  8. package/dist/cjs/src/components/logistics/vendor/EditVendorForm.js +1 -1
  9. package/dist/cjs/src/data/actions/logistics/note/createNoteAction.js +1 -1
  10. package/dist/cjs/src/data/actions/logistics/report/createReportAction.js +1 -1
  11. package/dist/cjs/src/index.js +1 -1
  12. package/dist/cjs/tsconfig.build.tsbuildinfo +1 -1
  13. package/dist/esm/_virtual/index2.js +2 -2
  14. package/dist/esm/_virtual/index3.js +2 -2
  15. package/dist/esm/_virtual/index4.js +2 -2
  16. package/dist/esm/node_modules/object-assign/index.js +74 -69
  17. package/dist/esm/node_modules/prop-types/factoryWithTypeCheckers.js +2 -2
  18. package/dist/esm/node_modules/prop-types/index.js +1 -1
  19. package/dist/esm/node_modules/prop-types/node_modules/react-is/index.js +1 -1
  20. package/dist/esm/node_modules/safe-buffer/index.js +1 -1
  21. package/dist/esm/src/components/e-commerce/products/EditReturnStockForm.js +11 -22
  22. package/dist/esm/src/components/logistics/report/ReportMakingComponent.js +0 -1
  23. package/dist/esm/src/components/logistics/vendor/EditVendorForm.js +0 -1
  24. package/dist/esm/src/data/actions/logistics/note/createNoteAction.js +0 -2
  25. package/dist/esm/src/data/actions/logistics/report/createReportAction.js +0 -2
  26. package/dist/esm/src/index.js +0 -1
  27. package/dist/esm/tsconfig.build.tsbuildinfo +1 -1
  28. package/dist/esm/types/data/actions/e-commerce/lead/contactFormAction.d.ts +1 -0
  29. package/dist/esm/types/index.d.ts +0 -3
  30. package/package.json +1 -1
  31. package/dist/cjs/_virtual/_commonjs-dynamic-modules.js +0 -6
  32. package/dist/cjs/_virtual/aes.js +0 -6
  33. package/dist/cjs/_virtual/b64.js +0 -6
  34. package/dist/cjs/_virtual/blowfish.js +0 -6
  35. package/dist/cjs/_virtual/cipher-core.js +0 -6
  36. package/dist/cjs/_virtual/clone.js +0 -6
  37. package/dist/cjs/_virtual/common.js +0 -6
  38. package/dist/cjs/_virtual/context.js +0 -6
  39. package/dist/cjs/_virtual/core2.js +0 -6
  40. package/dist/cjs/_virtual/decode.js +0 -6
  41. package/dist/cjs/_virtual/deflate.js +0 -6
  42. package/dist/cjs/_virtual/dictionary-browser.js +0 -6
  43. package/dist/cjs/_virtual/dictionary.js +0 -6
  44. package/dist/cjs/_virtual/en-us.js +0 -6
  45. package/dist/cjs/_virtual/enc-base64.js +0 -6
  46. package/dist/cjs/_virtual/enc-base64url.js +0 -6
  47. package/dist/cjs/_virtual/enc-utf16.js +0 -6
  48. package/dist/cjs/_virtual/events.js +0 -6
  49. package/dist/cjs/_virtual/evpkdf.js +0 -6
  50. package/dist/cjs/_virtual/format-hex.js +0 -6
  51. package/dist/cjs/_virtual/hmac.js +0 -6
  52. package/dist/cjs/_virtual/huffman.js +0 -6
  53. package/dist/cjs/_virtual/hyphen.js +0 -6
  54. package/dist/cjs/_virtual/index10.js +0 -6
  55. package/dist/cjs/_virtual/index5.js +0 -6
  56. package/dist/cjs/_virtual/index6.js +0 -6
  57. package/dist/cjs/_virtual/index7.js +0 -6
  58. package/dist/cjs/_virtual/index8.js +0 -6
  59. package/dist/cjs/_virtual/index9.js +0 -6
  60. package/dist/cjs/_virtual/inflate.js +0 -6
  61. package/dist/cjs/_virtual/inherits_browser.js +0 -6
  62. package/dist/cjs/_virtual/lib-typedarrays.js +0 -6
  63. package/dist/cjs/_virtual/md5.js +0 -6
  64. package/dist/cjs/_virtual/mode-cfb.js +0 -6
  65. package/dist/cjs/_virtual/mode-ctr-gladman.js +0 -6
  66. package/dist/cjs/_virtual/mode-ctr.js +0 -6
  67. package/dist/cjs/_virtual/mode-ecb.js +0 -6
  68. package/dist/cjs/_virtual/mode-ofb.js +0 -6
  69. package/dist/cjs/_virtual/pad-ansix923.js +0 -6
  70. package/dist/cjs/_virtual/pad-iso10126.js +0 -6
  71. package/dist/cjs/_virtual/pad-iso97971.js +0 -6
  72. package/dist/cjs/_virtual/pad-nopadding.js +0 -6
  73. package/dist/cjs/_virtual/pad-zeropadding.js +0 -6
  74. package/dist/cjs/_virtual/pbkdf2.js +0 -6
  75. package/dist/cjs/_virtual/prefix.js +0 -6
  76. package/dist/cjs/_virtual/rabbit-legacy.js +0 -6
  77. package/dist/cjs/_virtual/rabbit.js +0 -6
  78. package/dist/cjs/_virtual/rc4.js +0 -6
  79. package/dist/cjs/_virtual/ripemd160.js +0 -6
  80. package/dist/cjs/_virtual/scheduler.development.js +0 -6
  81. package/dist/cjs/_virtual/scheduler.production.js +0 -6
  82. package/dist/cjs/_virtual/sha1.js +0 -6
  83. package/dist/cjs/_virtual/sha224.js +0 -6
  84. package/dist/cjs/_virtual/sha256.js +0 -6
  85. package/dist/cjs/_virtual/sha3.js +0 -6
  86. package/dist/cjs/_virtual/sha384.js +0 -6
  87. package/dist/cjs/_virtual/sha512.js +0 -6
  88. package/dist/cjs/_virtual/streams.js +0 -6
  89. package/dist/cjs/_virtual/transform.js +0 -6
  90. package/dist/cjs/_virtual/trees.js +0 -6
  91. package/dist/cjs/_virtual/tripledes.js +0 -6
  92. package/dist/cjs/_virtual/x64-core.js +0 -6
  93. package/dist/cjs/node_modules/@react-pdf/fns/lib/index.js +0 -6
  94. package/dist/cjs/node_modules/@react-pdf/font/lib/index.browser.js +0 -6
  95. package/dist/cjs/node_modules/@react-pdf/image/lib/index.browser.js +0 -6
  96. package/dist/cjs/node_modules/@react-pdf/layout/lib/index.js +0 -6
  97. package/dist/cjs/node_modules/@react-pdf/pdfkit/lib/pdfkit.browser.js +0 -6
  98. package/dist/cjs/node_modules/@react-pdf/png-js/lib/png-js.browser.js +0 -6
  99. package/dist/cjs/node_modules/@react-pdf/primitives/lib/index.js +0 -6
  100. package/dist/cjs/node_modules/@react-pdf/reconciler/lib/index.js +0 -6
  101. package/dist/cjs/node_modules/@react-pdf/reconciler/lib/reconciler-23.js +0 -14
  102. package/dist/cjs/node_modules/@react-pdf/reconciler/lib/reconciler-31.js +0 -26
  103. package/dist/cjs/node_modules/@react-pdf/render/lib/index.js +0 -6
  104. package/dist/cjs/node_modules/@react-pdf/renderer/lib/react-pdf.browser.js +0 -6
  105. package/dist/cjs/node_modules/@react-pdf/stylesheet/lib/index.js +0 -6
  106. package/dist/cjs/node_modules/@react-pdf/textkit/lib/textkit.js +0 -13
  107. package/dist/cjs/node_modules/@swc/helpers/esm/_define_property.js +0 -6
  108. package/dist/cjs/node_modules/abs-svg-path/index.js +0 -6
  109. package/dist/cjs/node_modules/base64-js/index.js +0 -6
  110. package/dist/cjs/node_modules/bidi-js/dist/bidi.js +0 -6
  111. package/dist/cjs/node_modules/brotli/dec/bit_reader.js +0 -6
  112. package/dist/cjs/node_modules/brotli/dec/context.js +0 -6
  113. package/dist/cjs/node_modules/brotli/dec/decode.js +0 -6
  114. package/dist/cjs/node_modules/brotli/dec/dictionary-browser.js +0 -6
  115. package/dist/cjs/node_modules/brotli/dec/dictionary.bin.js +0 -6
  116. package/dist/cjs/node_modules/brotli/dec/dictionary.js +0 -6
  117. package/dist/cjs/node_modules/brotli/dec/huffman.js +0 -6
  118. package/dist/cjs/node_modules/brotli/dec/prefix.js +0 -6
  119. package/dist/cjs/node_modules/brotli/dec/streams.js +0 -6
  120. package/dist/cjs/node_modules/brotli/dec/transform.js +0 -6
  121. package/dist/cjs/node_modules/brotli/decompress.js +0 -6
  122. package/dist/cjs/node_modules/clone/clone.js +0 -6
  123. package/dist/cjs/node_modules/color-name/index.js +0 -6
  124. package/dist/cjs/node_modules/color-string/index.js +0 -6
  125. package/dist/cjs/node_modules/crypto-js/aes.js +0 -6
  126. package/dist/cjs/node_modules/crypto-js/blowfish.js +0 -6
  127. package/dist/cjs/node_modules/crypto-js/cipher-core.js +0 -6
  128. package/dist/cjs/node_modules/crypto-js/core.js +0 -6
  129. package/dist/cjs/node_modules/crypto-js/enc-base64.js +0 -6
  130. package/dist/cjs/node_modules/crypto-js/enc-base64url.js +0 -6
  131. package/dist/cjs/node_modules/crypto-js/enc-utf16.js +0 -6
  132. package/dist/cjs/node_modules/crypto-js/evpkdf.js +0 -6
  133. package/dist/cjs/node_modules/crypto-js/format-hex.js +0 -6
  134. package/dist/cjs/node_modules/crypto-js/hmac.js +0 -6
  135. package/dist/cjs/node_modules/crypto-js/index.js +0 -6
  136. package/dist/cjs/node_modules/crypto-js/lib-typedarrays.js +0 -6
  137. package/dist/cjs/node_modules/crypto-js/md5.js +0 -6
  138. package/dist/cjs/node_modules/crypto-js/mode-cfb.js +0 -6
  139. package/dist/cjs/node_modules/crypto-js/mode-ctr-gladman.js +0 -12
  140. package/dist/cjs/node_modules/crypto-js/mode-ctr.js +0 -6
  141. package/dist/cjs/node_modules/crypto-js/mode-ecb.js +0 -6
  142. package/dist/cjs/node_modules/crypto-js/mode-ofb.js +0 -6
  143. package/dist/cjs/node_modules/crypto-js/pad-ansix923.js +0 -6
  144. package/dist/cjs/node_modules/crypto-js/pad-iso10126.js +0 -6
  145. package/dist/cjs/node_modules/crypto-js/pad-iso97971.js +0 -6
  146. package/dist/cjs/node_modules/crypto-js/pad-nopadding.js +0 -6
  147. package/dist/cjs/node_modules/crypto-js/pad-zeropadding.js +0 -6
  148. package/dist/cjs/node_modules/crypto-js/pbkdf2.js +0 -6
  149. package/dist/cjs/node_modules/crypto-js/rabbit-legacy.js +0 -6
  150. package/dist/cjs/node_modules/crypto-js/rabbit.js +0 -6
  151. package/dist/cjs/node_modules/crypto-js/rc4.js +0 -6
  152. package/dist/cjs/node_modules/crypto-js/ripemd160.js +0 -17
  153. package/dist/cjs/node_modules/crypto-js/sha1.js +0 -6
  154. package/dist/cjs/node_modules/crypto-js/sha224.js +0 -6
  155. package/dist/cjs/node_modules/crypto-js/sha256.js +0 -6
  156. package/dist/cjs/node_modules/crypto-js/sha3.js +0 -6
  157. package/dist/cjs/node_modules/crypto-js/sha384.js +0 -6
  158. package/dist/cjs/node_modules/crypto-js/sha512.js +0 -6
  159. package/dist/cjs/node_modules/crypto-js/tripledes.js +0 -6
  160. package/dist/cjs/node_modules/crypto-js/x64-core.js +0 -6
  161. package/dist/cjs/node_modules/dfa/index.js +0 -6
  162. package/dist/cjs/node_modules/emoji-regex/index.js +0 -6
  163. package/dist/cjs/node_modules/events/events.js +0 -6
  164. package/dist/cjs/node_modules/fast-deep-equal/index.js +0 -6
  165. package/dist/cjs/node_modules/fontkit/dist/browser-module.js +0 -6
  166. package/dist/cjs/node_modules/hsl-to-hex/index.js +0 -6
  167. package/dist/cjs/node_modules/hsl-to-rgb-for-reals/converter.js +0 -6
  168. package/dist/cjs/node_modules/hyphen/hyphen.js +0 -6
  169. package/dist/cjs/node_modules/hyphen/patterns/en-us.js +0 -6
  170. package/dist/cjs/node_modules/inherits/inherits_browser.js +0 -6
  171. package/dist/cjs/node_modules/jay-peg/src/index.js +0 -6
  172. package/dist/cjs/node_modules/jay-peg/src/markers/dac.js +0 -6
  173. package/dist/cjs/node_modules/jay-peg/src/markers/dht.js +0 -6
  174. package/dist/cjs/node_modules/jay-peg/src/markers/dqt.js +0 -6
  175. package/dist/cjs/node_modules/jay-peg/src/markers/dri.js +0 -6
  176. package/dist/cjs/node_modules/jay-peg/src/markers/eoi.js +0 -6
  177. package/dist/cjs/node_modules/jay-peg/src/markers/exif.js +0 -6
  178. package/dist/cjs/node_modules/jay-peg/src/markers/jfif.js +0 -6
  179. package/dist/cjs/node_modules/jay-peg/src/markers/sof.js +0 -6
  180. package/dist/cjs/node_modules/jay-peg/src/markers/soi.js +0 -6
  181. package/dist/cjs/node_modules/jay-peg/src/markers/sos.js +0 -6
  182. package/dist/cjs/node_modules/jay-peg/src/markers/utils.js +0 -6
  183. package/dist/cjs/node_modules/linebreak/dist/module.js +0 -6
  184. package/dist/cjs/node_modules/linebreak/node_modules/base64-js/lib/b64.js +0 -6
  185. package/dist/cjs/node_modules/media-engine/src/index.js +0 -6
  186. package/dist/cjs/node_modules/media-engine/src/operators.js +0 -6
  187. package/dist/cjs/node_modules/media-engine/src/parser.js +0 -6
  188. package/dist/cjs/node_modules/media-engine/src/queries.js +0 -6
  189. package/dist/cjs/node_modules/normalize-svg-path/index.js +0 -6
  190. package/dist/cjs/node_modules/pako/lib/utils/common.js +0 -6
  191. package/dist/cjs/node_modules/pako/lib/zlib/adler32.js +0 -6
  192. package/dist/cjs/node_modules/pako/lib/zlib/constants.js +0 -6
  193. package/dist/cjs/node_modules/pako/lib/zlib/crc32.js +0 -6
  194. package/dist/cjs/node_modules/pako/lib/zlib/deflate.js +0 -6
  195. package/dist/cjs/node_modules/pako/lib/zlib/inffast.js +0 -6
  196. package/dist/cjs/node_modules/pako/lib/zlib/inflate.js +0 -6
  197. package/dist/cjs/node_modules/pako/lib/zlib/inftrees.js +0 -6
  198. package/dist/cjs/node_modules/pako/lib/zlib/messages.js +0 -6
  199. package/dist/cjs/node_modules/pako/lib/zlib/trees.js +0 -6
  200. package/dist/cjs/node_modules/pako/lib/zlib/zstream.js +0 -6
  201. package/dist/cjs/node_modules/parse-svg-path/index.js +0 -6
  202. package/dist/cjs/node_modules/postcss-value-parser/lib/parse.js +0 -6
  203. package/dist/cjs/node_modules/postcss-value-parser/lib/unit.js +0 -6
  204. package/dist/cjs/node_modules/queue/index.js +0 -6
  205. package/dist/cjs/node_modules/restructure/src/Array.js +0 -6
  206. package/dist/cjs/node_modules/restructure/src/Base.js +0 -6
  207. package/dist/cjs/node_modules/restructure/src/Bitfield.js +0 -6
  208. package/dist/cjs/node_modules/restructure/src/Buffer.js +0 -6
  209. package/dist/cjs/node_modules/restructure/src/DecodeStream.js +0 -6
  210. package/dist/cjs/node_modules/restructure/src/EncodeStream.js +0 -6
  211. package/dist/cjs/node_modules/restructure/src/LazyArray.js +0 -6
  212. package/dist/cjs/node_modules/restructure/src/Number.js +0 -6
  213. package/dist/cjs/node_modules/restructure/src/Optional.js +0 -6
  214. package/dist/cjs/node_modules/restructure/src/Pointer.js +0 -6
  215. package/dist/cjs/node_modules/restructure/src/Reserved.js +0 -6
  216. package/dist/cjs/node_modules/restructure/src/String.js +0 -6
  217. package/dist/cjs/node_modules/restructure/src/Struct.js +0 -6
  218. package/dist/cjs/node_modules/restructure/src/VersionedStruct.js +0 -6
  219. package/dist/cjs/node_modules/restructure/src/utils.js +0 -6
  220. package/dist/cjs/node_modules/scheduler/cjs/scheduler.development.js +0 -15
  221. package/dist/cjs/node_modules/scheduler/cjs/scheduler.production.js +0 -15
  222. package/dist/cjs/node_modules/scheduler/index.js +0 -6
  223. package/dist/cjs/node_modules/simple-swizzle/index.js +0 -6
  224. package/dist/cjs/node_modules/simple-swizzle/node_modules/is-arrayish/index.js +0 -6
  225. package/dist/cjs/node_modules/svg-arc-to-cubic-bezier/modules/index.js +0 -6
  226. package/dist/cjs/node_modules/tiny-inflate/index.js +0 -6
  227. package/dist/cjs/node_modules/tslib/tslib.es6.js +0 -6
  228. package/dist/cjs/node_modules/unicode-properties/dist/module.js +0 -6
  229. package/dist/cjs/node_modules/unicode-trie/index.js +0 -6
  230. package/dist/cjs/node_modules/unicode-trie/swap.js +0 -6
  231. package/dist/cjs/node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js +0 -6
  232. package/dist/cjs/node_modules/yoga-layout/dist/src/generated/YGEnums.js +0 -6
  233. package/dist/cjs/node_modules/yoga-layout/dist/src/load.js +0 -6
  234. package/dist/cjs/node_modules/yoga-layout/dist/src/wrapAssembly.js +0 -6
  235. package/dist/cjs/src/components/e-commerce/invoice/InvoicePDF.js +0 -7
  236. package/dist/esm/_virtual/_commonjs-dynamic-modules.js +0 -11
  237. package/dist/esm/_virtual/aes.js +0 -9
  238. package/dist/esm/_virtual/b64.js +0 -9
  239. package/dist/esm/_virtual/blowfish.js +0 -9
  240. package/dist/esm/_virtual/cipher-core.js +0 -9
  241. package/dist/esm/_virtual/clone.js +0 -9
  242. package/dist/esm/_virtual/common.js +0 -9
  243. package/dist/esm/_virtual/context.js +0 -9
  244. package/dist/esm/_virtual/core2.js +0 -9
  245. package/dist/esm/_virtual/decode.js +0 -9
  246. package/dist/esm/_virtual/deflate.js +0 -9
  247. package/dist/esm/_virtual/dictionary-browser.js +0 -9
  248. package/dist/esm/_virtual/dictionary.js +0 -9
  249. package/dist/esm/_virtual/en-us.js +0 -9
  250. package/dist/esm/_virtual/enc-base64.js +0 -9
  251. package/dist/esm/_virtual/enc-base64url.js +0 -9
  252. package/dist/esm/_virtual/enc-utf16.js +0 -9
  253. package/dist/esm/_virtual/events.js +0 -9
  254. package/dist/esm/_virtual/evpkdf.js +0 -9
  255. package/dist/esm/_virtual/format-hex.js +0 -9
  256. package/dist/esm/_virtual/hmac.js +0 -9
  257. package/dist/esm/_virtual/huffman.js +0 -9
  258. package/dist/esm/_virtual/hyphen.js +0 -9
  259. package/dist/esm/_virtual/index10.js +0 -9
  260. package/dist/esm/_virtual/index5.js +0 -9
  261. package/dist/esm/_virtual/index6.js +0 -9
  262. package/dist/esm/_virtual/index7.js +0 -9
  263. package/dist/esm/_virtual/index8.js +0 -9
  264. package/dist/esm/_virtual/index9.js +0 -9
  265. package/dist/esm/_virtual/inflate.js +0 -9
  266. package/dist/esm/_virtual/inherits_browser.js +0 -9
  267. package/dist/esm/_virtual/lib-typedarrays.js +0 -9
  268. package/dist/esm/_virtual/md5.js +0 -9
  269. package/dist/esm/_virtual/mode-cfb.js +0 -9
  270. package/dist/esm/_virtual/mode-ctr-gladman.js +0 -9
  271. package/dist/esm/_virtual/mode-ctr.js +0 -9
  272. package/dist/esm/_virtual/mode-ecb.js +0 -9
  273. package/dist/esm/_virtual/mode-ofb.js +0 -9
  274. package/dist/esm/_virtual/pad-ansix923.js +0 -9
  275. package/dist/esm/_virtual/pad-iso10126.js +0 -9
  276. package/dist/esm/_virtual/pad-iso97971.js +0 -9
  277. package/dist/esm/_virtual/pad-nopadding.js +0 -9
  278. package/dist/esm/_virtual/pad-zeropadding.js +0 -9
  279. package/dist/esm/_virtual/pbkdf2.js +0 -9
  280. package/dist/esm/_virtual/prefix.js +0 -9
  281. package/dist/esm/_virtual/rabbit-legacy.js +0 -9
  282. package/dist/esm/_virtual/rabbit.js +0 -9
  283. package/dist/esm/_virtual/rc4.js +0 -9
  284. package/dist/esm/_virtual/ripemd160.js +0 -9
  285. package/dist/esm/_virtual/scheduler.development.js +0 -9
  286. package/dist/esm/_virtual/scheduler.production.js +0 -9
  287. package/dist/esm/_virtual/sha1.js +0 -9
  288. package/dist/esm/_virtual/sha224.js +0 -9
  289. package/dist/esm/_virtual/sha256.js +0 -9
  290. package/dist/esm/_virtual/sha3.js +0 -9
  291. package/dist/esm/_virtual/sha384.js +0 -9
  292. package/dist/esm/_virtual/sha512.js +0 -9
  293. package/dist/esm/_virtual/streams.js +0 -9
  294. package/dist/esm/_virtual/transform.js +0 -9
  295. package/dist/esm/_virtual/trees.js +0 -9
  296. package/dist/esm/_virtual/tripledes.js +0 -9
  297. package/dist/esm/_virtual/x64-core.js +0 -9
  298. package/dist/esm/node_modules/@react-pdf/fns/lib/index.js +0 -254
  299. package/dist/esm/node_modules/@react-pdf/font/lib/index.browser.js +0 -481
  300. package/dist/esm/node_modules/@react-pdf/image/lib/index.browser.js +0 -2217
  301. package/dist/esm/node_modules/@react-pdf/layout/lib/index.js +0 -2982
  302. package/dist/esm/node_modules/@react-pdf/pdfkit/lib/pdfkit.browser.js +0 -47429
  303. package/dist/esm/node_modules/@react-pdf/png-js/lib/png-js.browser.js +0 -12606
  304. package/dist/esm/node_modules/@react-pdf/primitives/lib/index.js +0 -37
  305. package/dist/esm/node_modules/@react-pdf/reconciler/lib/index.js +0 -16
  306. package/dist/esm/node_modules/@react-pdf/reconciler/lib/reconciler-23.js +0 -22
  307. package/dist/esm/node_modules/@react-pdf/reconciler/lib/reconciler-31.js +0 -30
  308. package/dist/esm/node_modules/@react-pdf/render/lib/index.js +0 -2081
  309. package/dist/esm/node_modules/@react-pdf/renderer/lib/react-pdf.browser.js +0 -472
  310. package/dist/esm/node_modules/@react-pdf/stylesheet/lib/index.js +0 -771
  311. package/dist/esm/node_modules/@react-pdf/textkit/lib/textkit.js +0 -2854
  312. package/dist/esm/node_modules/@swc/helpers/esm/_define_property.js +0 -15
  313. package/dist/esm/node_modules/abs-svg-path/index.js +0 -78
  314. package/dist/esm/node_modules/base64-js/index.js +0 -158
  315. package/dist/esm/node_modules/bidi-js/dist/bidi.js +0 -1008
  316. package/dist/esm/node_modules/brotli/dec/bit_reader.js +0 -132
  317. package/dist/esm/node_modules/brotli/dec/context.js +0 -255
  318. package/dist/esm/node_modules/brotli/dec/decode.js +0 -965
  319. package/dist/esm/node_modules/brotli/dec/dictionary-browser.js +0 -35
  320. package/dist/esm/node_modules/brotli/dec/dictionary.bin.js +0 -17
  321. package/dist/esm/node_modules/brotli/dec/dictionary.js +0 -54
  322. package/dist/esm/node_modules/brotli/dec/huffman.js +0 -133
  323. package/dist/esm/node_modules/brotli/dec/prefix.js +0 -70
  324. package/dist/esm/node_modules/brotli/dec/streams.js +0 -44
  325. package/dist/esm/node_modules/brotli/dec/transform.js +0 -264
  326. package/dist/esm/node_modules/brotli/decompress.js +0 -14
  327. package/dist/esm/node_modules/clone/clone.js +0 -272
  328. package/dist/esm/node_modules/color-name/index.js +0 -158
  329. package/dist/esm/node_modules/color-string/index.js +0 -259
  330. package/dist/esm/node_modules/crypto-js/aes.js +0 -251
  331. package/dist/esm/node_modules/crypto-js/blowfish.js +0 -488
  332. package/dist/esm/node_modules/crypto-js/cipher-core.js +0 -909
  333. package/dist/esm/node_modules/crypto-js/core.js +0 -820
  334. package/dist/esm/node_modules/crypto-js/enc-base64.js +0 -149
  335. package/dist/esm/node_modules/crypto-js/enc-base64url.js +0 -161
  336. package/dist/esm/node_modules/crypto-js/enc-utf16.js +0 -162
  337. package/dist/esm/node_modules/crypto-js/evpkdf.js +0 -149
  338. package/dist/esm/node_modules/crypto-js/format-hex.js +0 -80
  339. package/dist/esm/node_modules/crypto-js/hmac.js +0 -156
  340. package/dist/esm/node_modules/crypto-js/index.js +0 -61
  341. package/dist/esm/node_modules/crypto-js/lib-typedarrays.js +0 -89
  342. package/dist/esm/node_modules/crypto-js/md5.js +0 -277
  343. package/dist/esm/node_modules/crypto-js/mode-cfb.js +0 -94
  344. package/dist/esm/node_modules/crypto-js/mode-ctr-gladman.js +0 -130
  345. package/dist/esm/node_modules/crypto-js/mode-ctr.js +0 -72
  346. package/dist/esm/node_modules/crypto-js/mode-ecb.js +0 -54
  347. package/dist/esm/node_modules/crypto-js/mode-ofb.js +0 -68
  348. package/dist/esm/node_modules/crypto-js/pad-ansix923.js +0 -63
  349. package/dist/esm/node_modules/crypto-js/pad-iso10126.js +0 -58
  350. package/dist/esm/node_modules/crypto-js/pad-iso97971.js +0 -54
  351. package/dist/esm/node_modules/crypto-js/pad-nopadding.js +0 -44
  352. package/dist/esm/node_modules/crypto-js/pad-zeropadding.js +0 -61
  353. package/dist/esm/node_modules/crypto-js/pbkdf2.js +0 -160
  354. package/dist/esm/node_modules/crypto-js/rabbit-legacy.js +0 -207
  355. package/dist/esm/node_modules/crypto-js/rabbit.js +0 -209
  356. package/dist/esm/node_modules/crypto-js/rc4.js +0 -156
  357. package/dist/esm/node_modules/crypto-js/ripemd160.js +0 -280
  358. package/dist/esm/node_modules/crypto-js/sha1.js +0 -163
  359. package/dist/esm/node_modules/crypto-js/sha224.js +0 -94
  360. package/dist/esm/node_modules/crypto-js/sha256.js +0 -212
  361. package/dist/esm/node_modules/crypto-js/sha3.js +0 -340
  362. package/dist/esm/node_modules/crypto-js/sha384.js +0 -98
  363. package/dist/esm/node_modules/crypto-js/sha512.js +0 -340
  364. package/dist/esm/node_modules/crypto-js/tripledes.js +0 -796
  365. package/dist/esm/node_modules/crypto-js/x64-core.js +0 -317
  366. package/dist/esm/node_modules/dfa/index.js +0 -101
  367. package/dist/esm/node_modules/emoji-regex/index.js +0 -12
  368. package/dist/esm/node_modules/events/events.js +0 -485
  369. package/dist/esm/node_modules/fast-deep-equal/index.js +0 -56
  370. package/dist/esm/node_modules/fontkit/dist/browser-module.js +0 -13295
  371. package/dist/esm/node_modules/hsl-to-hex/index.js +0 -72
  372. package/dist/esm/node_modules/hsl-to-rgb-for-reals/converter.js +0 -66
  373. package/dist/esm/node_modules/hyphen/hyphen.js +0 -424
  374. package/dist/esm/node_modules/hyphen/patterns/en-us.js +0 -48
  375. package/dist/esm/node_modules/inherits/inherits_browser.js +0 -39
  376. package/dist/esm/node_modules/jay-peg/src/index.js +0 -68
  377. package/dist/esm/node_modules/jay-peg/src/markers/dac.js +0 -25
  378. package/dist/esm/node_modules/jay-peg/src/markers/dht.js +0 -52
  379. package/dist/esm/node_modules/jay-peg/src/markers/dqt.js +0 -26
  380. package/dist/esm/node_modules/jay-peg/src/markers/dri.js +0 -17
  381. package/dist/esm/node_modules/jay-peg/src/markers/eoi.js +0 -17
  382. package/dist/esm/node_modules/jay-peg/src/markers/exif.js +0 -327
  383. package/dist/esm/node_modules/jay-peg/src/markers/jfif.js +0 -24
  384. package/dist/esm/node_modules/jay-peg/src/markers/sof.js +0 -32
  385. package/dist/esm/node_modules/jay-peg/src/markers/soi.js +0 -11
  386. package/dist/esm/node_modules/jay-peg/src/markers/sos.js +0 -57
  387. package/dist/esm/node_modules/jay-peg/src/markers/utils.js +0 -71
  388. package/dist/esm/node_modules/linebreak/dist/module.js +0 -1340
  389. package/dist/esm/node_modules/linebreak/node_modules/base64-js/lib/b64.js +0 -137
  390. package/dist/esm/node_modules/media-engine/src/index.js +0 -26
  391. package/dist/esm/node_modules/media-engine/src/operators.js +0 -36
  392. package/dist/esm/node_modules/media-engine/src/parser.js +0 -147
  393. package/dist/esm/node_modules/media-engine/src/queries.js +0 -64
  394. package/dist/esm/node_modules/normalize-svg-path/index.js +0 -126
  395. package/dist/esm/node_modules/pako/lib/utils/common.js +0 -114
  396. package/dist/esm/node_modules/pako/lib/zlib/adler32.js +0 -57
  397. package/dist/esm/node_modules/pako/lib/zlib/constants.js +0 -78
  398. package/dist/esm/node_modules/pako/lib/zlib/crc32.js +0 -65
  399. package/dist/esm/node_modules/pako/lib/zlib/deflate.js +0 -1880
  400. package/dist/esm/node_modules/pako/lib/zlib/inffast.js +0 -351
  401. package/dist/esm/node_modules/pako/lib/zlib/inflate.js +0 -1557
  402. package/dist/esm/node_modules/pako/lib/zlib/inftrees.js +0 -352
  403. package/dist/esm/node_modules/pako/lib/zlib/messages.js +0 -38
  404. package/dist/esm/node_modules/pako/lib/zlib/trees.js +0 -1232
  405. package/dist/esm/node_modules/pako/lib/zlib/zstream.js +0 -57
  406. package/dist/esm/node_modules/parse-svg-path/index.js +0 -68
  407. package/dist/esm/node_modules/postcss-value-parser/lib/parse.js +0 -333
  408. package/dist/esm/node_modules/postcss-value-parser/lib/unit.js +0 -132
  409. package/dist/esm/node_modules/queue/index.js +0 -211
  410. package/dist/esm/node_modules/restructure/src/Array.js +0 -112
  411. package/dist/esm/node_modules/restructure/src/Base.js +0 -25
  412. package/dist/esm/node_modules/restructure/src/Bitfield.js +0 -47
  413. package/dist/esm/node_modules/restructure/src/Buffer.js +0 -44
  414. package/dist/esm/node_modules/restructure/src/DecodeStream.js +0 -93
  415. package/dist/esm/node_modules/restructure/src/EncodeStream.js +0 -137
  416. package/dist/esm/node_modules/restructure/src/LazyArray.js +0 -82
  417. package/dist/esm/node_modules/restructure/src/Number.js +0 -80
  418. package/dist/esm/node_modules/restructure/src/Optional.js +0 -52
  419. package/dist/esm/node_modules/restructure/src/Pointer.js +0 -175
  420. package/dist/esm/node_modules/restructure/src/Reserved.js +0 -31
  421. package/dist/esm/node_modules/restructure/src/String.js +0 -161
  422. package/dist/esm/node_modules/restructure/src/Struct.js +0 -121
  423. package/dist/esm/node_modules/restructure/src/VersionedStruct.js +0 -147
  424. package/dist/esm/node_modules/restructure/src/utils.js +0 -42
  425. package/dist/esm/node_modules/scheduler/cjs/scheduler.development.js +0 -382
  426. package/dist/esm/node_modules/scheduler/cjs/scheduler.production.js +0 -359
  427. package/dist/esm/node_modules/scheduler/index.js +0 -21
  428. package/dist/esm/node_modules/simple-swizzle/index.js +0 -40
  429. package/dist/esm/node_modules/simple-swizzle/node_modules/is-arrayish/index.js +0 -17
  430. package/dist/esm/node_modules/svg-arc-to-cubic-bezier/modules/index.js +0 -189
  431. package/dist/esm/node_modules/tiny-inflate/index.js +0 -387
  432. package/dist/esm/node_modules/tslib/tslib.es6.js +0 -36
  433. package/dist/esm/node_modules/unicode-properties/dist/module.js +0 -132
  434. package/dist/esm/node_modules/unicode-trie/index.js +0 -150
  435. package/dist/esm/node_modules/unicode-trie/swap.js +0 -33
  436. package/dist/esm/node_modules/yoga-layout/dist/binaries/yoga-wasm-base64-esm.js +0 -81
  437. package/dist/esm/node_modules/yoga-layout/dist/src/generated/YGEnums.js +0 -217
  438. package/dist/esm/node_modules/yoga-layout/dist/src/load.js +0 -24
  439. package/dist/esm/node_modules/yoga-layout/dist/src/wrapAssembly.js +0 -130
  440. package/dist/esm/src/components/e-commerce/invoice/InvoicePDF.js +0 -181
@@ -1,2982 +0,0 @@
1
- /*
2
- * UMWD-Components
3
- * @copyright Jelle Paulus
4
- * @license MIT
5
- */
6
-
7
- import { asyncCompose, compose, isNil, upperFirst, matchPercent, pick, evolve, castArray, omit, parseFloat as parseFloat$1, without, capitalize, mapValues } from '../../fns/lib/index.js';
8
- import { Text, Svg, Document, Image, Link, Note, Canvas, TextInstance, Page, Tspan, Defs } from '../../primitives/lib/index.js';
9
- import resolveStyles$1, { flatten, transformColor } from '../../stylesheet/lib/index.js';
10
- import layoutEngine, { fromFragments, fontSubstitution, wordHyphenation, scriptItemizer, textDecoration, justification, linebreaker, bidi as bidiEngine } from '../../textkit/lib/textkit.js';
11
- import { loadYoga as loadYoga$1 } from '../../../yoga-layout/dist/src/load.js';
12
- import emojiRegex from '../../../emoji-regex/index.js';
13
- import resolveImage from '../../image/lib/index.browser.js';
14
- import { Edge, Gutter, Overflow, Wrap, Justify, Align, FlexDirection, Display, PositionType, MeasureMode } from '../../../yoga-layout/dist/src/generated/YGEnums.js';
15
-
16
- /**
17
- * Apply transformation to text string
18
- *
19
- * @param {string} text
20
- * @param {string} transformation type
21
- * @returns {string} transformed text
22
- */
23
- const transformText = (text, transformation) => {
24
- switch (transformation) {
25
- case 'uppercase':
26
- return text.toUpperCase();
27
- case 'lowercase':
28
- return text.toLowerCase();
29
- case 'capitalize':
30
- return capitalize(text);
31
- case 'upperfirst':
32
- return upperFirst(text);
33
- default:
34
- return text;
35
- }
36
- };
37
-
38
- const isTspan = (node) => node.type === Tspan;
39
- const isTextInstance$4 = (node) => node.type === TextInstance;
40
- const engines$1 = {
41
- bidi: bidiEngine,
42
- linebreaker,
43
- justification,
44
- textDecoration,
45
- scriptItemizer,
46
- wordHyphenation,
47
- fontSubstitution,
48
- };
49
- const engine$1 = layoutEngine(engines$1);
50
- const getFragments$1 = (fontStore, instance) => {
51
- if (!instance)
52
- return [{ string: '' }];
53
- const fragments = [];
54
- const { fill = 'black', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textDecorationColor, textDecorationStyle, textTransform, opacity, } = instance.props;
55
- const _textDecoration = instance.props.textDecoration;
56
- const fontFamilies = typeof fontFamily === 'string' ? [fontFamily] : [...(fontFamily || [])];
57
- // Fallback font
58
- fontFamilies.push('Helvetica');
59
- const font = fontFamilies.map((fontFamilyName) => {
60
- const opts = { fontFamily: fontFamilyName, fontWeight, fontStyle };
61
- const obj = fontStore.getFont(opts);
62
- return obj?.data;
63
- });
64
- const attributes = {
65
- font,
66
- opacity,
67
- fontSize,
68
- color: fill,
69
- underlineStyle: textDecorationStyle,
70
- underline: _textDecoration === 'underline' ||
71
- _textDecoration === 'underline line-through' ||
72
- _textDecoration === 'line-through underline',
73
- underlineColor: textDecorationColor || fill,
74
- strike: _textDecoration === 'line-through' ||
75
- _textDecoration === 'underline line-through' ||
76
- _textDecoration === 'line-through underline',
77
- strikeStyle: textDecorationStyle,
78
- strikeColor: textDecorationColor || fill,
79
- };
80
- for (let i = 0; i < instance.children.length; i += 1) {
81
- const child = instance.children[i];
82
- if (isTextInstance$4(child)) {
83
- fragments.push({
84
- string: transformText(child.value, textTransform),
85
- attributes,
86
- });
87
- }
88
- else if (child) {
89
- fragments.push(...getFragments$1(fontStore, child));
90
- }
91
- }
92
- return fragments;
93
- };
94
- const getAttributedString$1 = (fontStore, instance) => fromFragments(getFragments$1(fontStore, instance));
95
- const AlmostInfinity = 999999999999;
96
- const shrinkWhitespaceFactor = { before: -0.5, after: -0.5 };
97
- const layoutTspan = (fontStore) => (node, xOffset) => {
98
- const attributedString = getAttributedString$1(fontStore, node);
99
- const x = node.props.x === undefined ? xOffset : node.props.x;
100
- const y = node.props?.y || 0;
101
- const container = { x, y, width: AlmostInfinity, height: AlmostInfinity };
102
- const hyphenationCallback = node.props.hyphenationCallback ||
103
- fontStore?.getHyphenationCallback() ||
104
- null;
105
- const layoutOptions = { hyphenationCallback, shrinkWhitespaceFactor };
106
- const lines = engine$1(attributedString, container, layoutOptions).flat();
107
- return Object.assign({}, node, { lines });
108
- };
109
- // Consecutive TSpan elements should be joined with a space
110
- const joinTSpanLines = (node) => {
111
- const children = node.children.map((child, index) => {
112
- if (!isTspan(child))
113
- return child;
114
- const textInstance = child.children[0];
115
- if (child.props.x === undefined &&
116
- index < node.children.length - 1 &&
117
- textInstance?.value) {
118
- return Object.assign({}, child, {
119
- children: [{ ...textInstance, value: `${textInstance.value} ` }],
120
- });
121
- }
122
- return child;
123
- }, []);
124
- return Object.assign({}, node, { children });
125
- };
126
- const layoutText$1 = (fontStore, node) => {
127
- if (!node.children)
128
- return node;
129
- let currentXOffset = node.props?.x || 0;
130
- const layoutFn = layoutTspan(fontStore);
131
- const joinedNode = joinTSpanLines(node);
132
- const children = joinedNode.children.map((child) => {
133
- const childWithLayout = layoutFn(child, currentXOffset);
134
- currentXOffset += childWithLayout.lines[0].xAdvance;
135
- return childWithLayout;
136
- });
137
- return Object.assign({}, node, { children });
138
- };
139
-
140
- const isDefs = (node) => node.type === Defs;
141
- const getDefs = (node) => {
142
- const children = node.children || [];
143
- const defs = children.find(isDefs);
144
- const values = defs?.children || [];
145
- return values.reduce((acc, value) => {
146
- const id = value.props?.id;
147
- if (id)
148
- acc[id] = value;
149
- return acc;
150
- }, {});
151
- };
152
-
153
- const isNotDefs = (node) => node.type !== Defs;
154
- const detachDefs = (node) => {
155
- if (!node.children)
156
- return node;
157
- const children = node.children.filter(isNotDefs);
158
- return Object.assign({}, node, { children });
159
- };
160
- const URL_REGEX = /url\(['"]?#([^'"]+)['"]?\)/;
161
- const replaceDef = (defs, value) => {
162
- if (!value)
163
- return undefined;
164
- if (!URL_REGEX.test(value))
165
- return value;
166
- const match = value.match(URL_REGEX);
167
- return defs[match[1]];
168
- };
169
- const parseNodeDefs = (defs) => (node) => {
170
- const props = node.props;
171
- const fill = `fill` in props ? replaceDef(defs, props?.fill) : undefined;
172
- const clipPath = `clipPath` in props
173
- ? replaceDef(defs, props?.clipPath)
174
- : undefined;
175
- const newProps = Object.assign({}, node.props, { fill, clipPath });
176
- const children = node.children
177
- ? node.children.map(parseNodeDefs(defs))
178
- : undefined;
179
- return Object.assign({}, node, { props: newProps, children });
180
- };
181
- const parseDefs = (root) => {
182
- if (!root.children)
183
- return root;
184
- const defs = getDefs(root);
185
- const children = root.children.map(parseNodeDefs(defs));
186
- return Object.assign({}, root, { children });
187
- };
188
- const replaceDefs = (node) => {
189
- return detachDefs(parseDefs(node));
190
- };
191
-
192
- const parseViewbox = (value) => {
193
- if (!value)
194
- return null;
195
- if (typeof value !== 'string')
196
- return value;
197
- const values = value.split(/[,\s]+/).map(parseFloat$1);
198
- if (values.length !== 4)
199
- return null;
200
- return { minX: values[0], minY: values[1], maxX: values[2], maxY: values[3] };
201
- };
202
-
203
- const getContainer$1 = (node) => {
204
- const viewbox = parseViewbox(node.props.viewBox);
205
- if (viewbox) {
206
- return { width: viewbox.maxX, height: viewbox.maxY };
207
- }
208
- if (node.props.width && node.props.height) {
209
- return {
210
- width: parseFloat$1(node.props.width),
211
- height: parseFloat$1(node.props.height),
212
- };
213
- }
214
- return { width: 0, height: 0 };
215
- };
216
-
217
- const BASE_SVG_INHERITED_PROPS = [
218
- 'x',
219
- 'y',
220
- 'clipPath',
221
- 'clipRule',
222
- 'opacity',
223
- 'fill',
224
- 'fillOpacity',
225
- 'fillRule',
226
- 'stroke',
227
- 'strokeLinecap',
228
- 'strokeLinejoin',
229
- 'strokeOpacity',
230
- 'strokeWidth',
231
- 'textAnchor',
232
- 'dominantBaseline',
233
- 'color',
234
- 'fontFamily',
235
- 'fontSize',
236
- 'fontStyle',
237
- 'fontWeight',
238
- 'letterSpacing',
239
- 'opacity',
240
- 'textDecoration',
241
- 'lineHeight',
242
- 'textAlign',
243
- 'visibility',
244
- 'wordSpacing',
245
- ];
246
- // Do not inherit "x" for <tspan> elements from <text> parent
247
- const TEXT_SVG_INHERITED_PROPS = without(['x'], BASE_SVG_INHERITED_PROPS);
248
- const SVG_INHERITED_PROPS = {
249
- [Text]: TEXT_SVG_INHERITED_PROPS,
250
- };
251
- const getInheritProps = (node) => {
252
- const props = node.props || {};
253
- const svgInheritedProps = SVG_INHERITED_PROPS[node.type] ?? BASE_SVG_INHERITED_PROPS;
254
- return pick(svgInheritedProps, props);
255
- };
256
- const inheritProps = (node) => {
257
- if (!node.children)
258
- return node;
259
- const inheritedProps = getInheritProps(node);
260
- const children = node.children.map((child) => {
261
- const props = Object.assign({}, inheritedProps, child.props || {});
262
- const newChild = Object.assign({}, child, { props });
263
- return inheritProps(newChild);
264
- });
265
- return Object.assign({}, node, { children });
266
- };
267
-
268
- const parseAspectRatio = (value) => {
269
- if (typeof value !== 'string')
270
- return value;
271
- const match = value
272
- .replace(/[\s\r\t\n]+/gm, ' ')
273
- .replace(/^defer\s/, '')
274
- .split(' ');
275
- const align = (match[0] || 'xMidYMid');
276
- const meetOrSlice = (match[1] ||
277
- 'meet');
278
- return { align, meetOrSlice };
279
- };
280
-
281
- const STYLE_PROPS = [
282
- 'width',
283
- 'height',
284
- 'color',
285
- 'stroke',
286
- 'strokeWidth',
287
- 'opacity',
288
- 'fillOpacity',
289
- 'strokeOpacity',
290
- 'fill',
291
- 'fillRule',
292
- 'clipPath',
293
- 'offset',
294
- 'transform',
295
- 'strokeLinejoin',
296
- 'strokeLinecap',
297
- 'strokeDasharray',
298
- 'gradientUnits',
299
- 'gradientTransform',
300
- ];
301
- const VERTICAL_PROPS = ['y', 'y1', 'y2', 'height', 'cy', 'ry'];
302
- const HORIZONTAL_PROPS = ['x', 'x1', 'x2', 'width', 'cx', 'rx'];
303
- const isSvg$3 = (node) => node.type === Svg;
304
- const isText$5 = (node) => node.type === Text;
305
- const isTextInstance$3 = (node) => node.type === TextInstance;
306
- const transformPercent = (container) => (props) => mapValues(props, (value, key) => {
307
- const match = matchPercent(value);
308
- if (match && VERTICAL_PROPS.includes(key)) {
309
- return match.percent * container.height;
310
- }
311
- if (match && HORIZONTAL_PROPS.includes(key)) {
312
- return match.percent * container.width;
313
- }
314
- return value;
315
- });
316
- const parsePercent = (value) => {
317
- const match = matchPercent(value);
318
- return match ? match.percent : parseFloat$1(value);
319
- };
320
- const parseTransform = (container) => (value) => {
321
- return resolveStyles$1(container, { transform: value }).transform;
322
- };
323
- const parseProps = (container) => (node) => {
324
- let props = transformPercent(container)(node.props);
325
- props = evolve({
326
- x: parseFloat$1,
327
- x1: parseFloat$1,
328
- x2: parseFloat$1,
329
- y: parseFloat$1,
330
- y1: parseFloat$1,
331
- y2: parseFloat$1,
332
- r: parseFloat$1,
333
- rx: parseFloat$1,
334
- ry: parseFloat$1,
335
- cx: parseFloat$1,
336
- cy: parseFloat$1,
337
- width: parseFloat$1,
338
- height: parseFloat$1,
339
- offset: parsePercent,
340
- fill: transformColor,
341
- opacity: parsePercent,
342
- stroke: transformColor,
343
- stopOpacity: parsePercent,
344
- stopColor: transformColor,
345
- transform: parseTransform(container),
346
- gradientTransform: parseTransform(container),
347
- }, props);
348
- return Object.assign({}, node, { props });
349
- };
350
- const mergeStyles$1 = (node) => {
351
- const style = node.style || {};
352
- const props = Object.assign({}, style, node.props);
353
- return Object.assign({}, node, { props });
354
- };
355
- const removeNoneValues = (node) => {
356
- const removeNone = (value) => (value === 'none' ? null : value);
357
- const props = mapValues(node.props, removeNone);
358
- return Object.assign({}, node, { props });
359
- };
360
- const pickStyleProps = (node) => {
361
- const props = node.props || {};
362
- const styleProps = pick(STYLE_PROPS, props);
363
- const style = Object.assign({}, styleProps, node.style || {});
364
- return Object.assign({}, node, { style });
365
- };
366
- const parseSvgProps = (node) => {
367
- const props = evolve({
368
- width: parseFloat$1,
369
- height: parseFloat$1,
370
- viewBox: parseViewbox,
371
- preserveAspectRatio: parseAspectRatio,
372
- }, node.props);
373
- return Object.assign({}, node, { props });
374
- };
375
- const wrapBetweenTspan = (node) => ({
376
- type: Tspan,
377
- props: {},
378
- style: {},
379
- children: [node],
380
- });
381
- const addMissingTspan = (node) => {
382
- if (!isText$5(node))
383
- return node;
384
- if (!node.children)
385
- return node;
386
- const resolveChild = (child) => isTextInstance$3(child) ? wrapBetweenTspan(child) : child;
387
- const children = node.children.map(resolveChild);
388
- return Object.assign({}, node, { children });
389
- };
390
- const parseText = (fontStore) => (node) => {
391
- if (isText$5(node))
392
- return layoutText$1(fontStore, node);
393
- if (!node.children)
394
- return node;
395
- const children = node.children.map(parseText(fontStore));
396
- return Object.assign({}, node, { children });
397
- };
398
- const resolveSvgNode = (container) => compose(parseProps(container), addMissingTspan, removeNoneValues, mergeStyles$1);
399
- const resolveChildren = (container) => (node) => {
400
- if (!node.children)
401
- return node;
402
- const resolveChild = compose(resolveChildren(container), resolveSvgNode(container));
403
- const children = node.children.map(resolveChild);
404
- return Object.assign({}, node, { children });
405
- };
406
- const buildXLinksIndex = (node) => {
407
- const idIndex = {};
408
- const listToExplore = node.children?.slice(0) || [];
409
- while (listToExplore.length > 0) {
410
- const child = listToExplore.shift();
411
- if (child.props && 'id' in child.props) {
412
- idIndex[child.props.id] = child;
413
- }
414
- if (child.children)
415
- listToExplore.push(...child.children);
416
- }
417
- return idIndex;
418
- };
419
- const replaceXLinks = (node, idIndex) => {
420
- if (node.props && 'xlinkHref' in node.props) {
421
- const linkedNode = idIndex[node.props.xlinkHref.replace(/^#/, '')];
422
- // No node to extend from
423
- if (!linkedNode)
424
- return node;
425
- const newProps = Object.assign({}, linkedNode.props, node.props);
426
- delete newProps.xlinkHref;
427
- return Object.assign({}, linkedNode, { props: newProps });
428
- }
429
- const children = node.children?.map((child) => replaceXLinks(child, idIndex));
430
- return Object.assign({}, node, { children });
431
- };
432
- const resolveXLinks = (node) => {
433
- const idIndex = buildXLinksIndex(node);
434
- return replaceXLinks(node, idIndex);
435
- };
436
- const resolveSvgRoot = (node, fontStore) => {
437
- const container = getContainer$1(node);
438
- return compose(replaceDefs, parseText(fontStore), parseSvgProps, pickStyleProps, inheritProps, resolveChildren(container), resolveXLinks)(node);
439
- };
440
- /**
441
- * Pre-process SVG nodes so they can be rendered in the next steps
442
- *
443
- * @param node - Root node
444
- * @param fontStore - Font store
445
- * @returns Root node
446
- */
447
- const resolveSvg = (node, fontStore) => {
448
- if (!('children' in node))
449
- return node;
450
- const resolveChild = (child) => resolveSvg(child, fontStore);
451
- const root = isSvg$3(node) ? resolveSvgRoot(node, fontStore) : node;
452
- const children = root.children?.map(resolveChild);
453
- return Object.assign({}, root, { children });
454
- };
455
-
456
- let instancePromise;
457
- const loadYoga = async () => {
458
- // Yoga WASM binaries must be asynchronously compiled and loaded
459
- // to prevent Event emitter memory leak warnings, Yoga must be loaded only once
460
- const instance = await (instancePromise ??= loadYoga$1());
461
- const config = instance.Config.create();
462
- config.setPointScaleFactor(0);
463
- const node = { create: () => instance.Node.createWithConfig(config) };
464
- return { node };
465
- };
466
-
467
- const resolveYoga = async (root) => {
468
- const yoga = await loadYoga();
469
- return Object.assign({}, root, { yoga });
470
- };
471
-
472
- const getZIndex = (node) => node.style.zIndex;
473
- const shouldSort = (node) => node.type !== Document && node.type !== Svg;
474
- const sortZIndex = (a, b) => {
475
- const za = getZIndex(a);
476
- const zb = getZIndex(b);
477
- if (!za && !zb)
478
- return 0;
479
- if (!za)
480
- return 1;
481
- if (!zb)
482
- return -1;
483
- return zb - za;
484
- };
485
- /**
486
- * Sort children by zIndex value
487
- *
488
- * @param node
489
- * @returns Node
490
- */
491
- const resolveNodeZIndex = (node) => {
492
- if (!node.children)
493
- return node;
494
- const sortedChildren = shouldSort(node)
495
- ? node.children.sort(sortZIndex)
496
- : node.children;
497
- const children = sortedChildren.map(resolveNodeZIndex);
498
- return Object.assign({}, node, { children });
499
- };
500
- /**
501
- * Sort children by zIndex value
502
- *
503
- * @param node
504
- * @returns Node
505
- */
506
- const resolveZIndex = (root) => resolveNodeZIndex(root);
507
-
508
- // Caches emoji images data
509
- const emojis = {};
510
- const regex = emojiRegex();
511
- /**
512
- * When an emoji as no variations, it might still have 2 parts,
513
- * the canonical emoji and an empty string.
514
- * ex.
515
- * (no color) Array.from('❤️') => ["❤", "️"]
516
- * (w/ color) Array.from('👍🏿') => ["👍", "🏿"]
517
- *
518
- * The empty string needs to be removed otherwise the generated
519
- * url will be incorect.
520
- */
521
- const removeVariationSelectors = (x) => x !== '️';
522
- const getCodePoints = (string, withVariationSelectors = false) => Array.from(string)
523
- .filter(withVariationSelectors ? () => true : removeVariationSelectors)
524
- .map((char) => char.codePointAt(0).toString(16))
525
- .join('-');
526
- const buildEmojiUrl = (emoji, source) => {
527
- if ('builder' in source) {
528
- return source.builder(getCodePoints(emoji, source.withVariationSelectors));
529
- }
530
- const { url, format = 'png', withVariationSelectors } = source;
531
- return `${url}${getCodePoints(emoji, withVariationSelectors)}.${format}`;
532
- };
533
- const fetchEmojis = (string, source) => {
534
- if (!source)
535
- return [];
536
- const promises = [];
537
- Array.from(string.matchAll(regex)).forEach((match) => {
538
- const emoji = match[0];
539
- if (!emojis[emoji] || emojis[emoji].loading) {
540
- const emojiUrl = buildEmojiUrl(emoji, source);
541
- emojis[emoji] = { loading: true };
542
- promises.push(resolveImage({ uri: emojiUrl }).then((image) => {
543
- emojis[emoji].loading = false;
544
- emojis[emoji].data = image.data;
545
- }));
546
- }
547
- });
548
- return promises;
549
- };
550
- const embedEmojis = (fragments) => {
551
- const result = [];
552
- for (let i = 0; i < fragments.length; i += 1) {
553
- const fragment = fragments[i];
554
- let lastIndex = 0;
555
- Array.from(fragment.string.matchAll(regex)).forEach((match) => {
556
- const { index } = match;
557
- const emoji = match[0];
558
- const emojiSize = fragment.attributes.fontSize;
559
- const chunk = fragment.string.slice(lastIndex, index + match[0].length);
560
- // If emoji image was found, we create a new fragment with the
561
- // correct attachment and object substitution character;
562
- if (emojis[emoji] && emojis[emoji].data) {
563
- result.push({
564
- string: chunk.replace(match[0], String.fromCharCode(0xfffc)),
565
- attributes: {
566
- ...fragment.attributes,
567
- attachment: {
568
- width: emojiSize,
569
- height: emojiSize,
570
- yOffset: Math.floor(emojiSize * 0.1),
571
- image: emojis[emoji].data,
572
- },
573
- },
574
- });
575
- }
576
- else {
577
- // If no emoji data, we try to use emojis in the font
578
- result.push({
579
- string: chunk,
580
- attributes: fragment.attributes,
581
- });
582
- }
583
- lastIndex = index + emoji.length;
584
- });
585
- if (lastIndex < fragment.string.length) {
586
- result.push({
587
- string: fragment.string.slice(lastIndex),
588
- attributes: fragment.attributes,
589
- });
590
- }
591
- }
592
- return result;
593
- };
594
-
595
- /**
596
- * Get image source
597
- *
598
- * @param node - Image node
599
- * @returns Image src
600
- */
601
- const getSource = (node) => {
602
- if (node.props.src)
603
- return node.props.src;
604
- if (node.props.source)
605
- return node.props.source;
606
- };
607
-
608
- /**
609
- * Resolves `src` to `@react-pdf/image` interface.
610
- *
611
- * Also it handles factories and async sources.
612
- *
613
- * @param src
614
- * @returns Resolved src
615
- */
616
- const resolveSource = async (src) => {
617
- const source = typeof src === 'function' ? await src() : await src;
618
- return typeof source === 'string' ? { uri: source } : source;
619
- };
620
-
621
- /**
622
- * Fetches image and append data to node
623
- * Ideally this fn should be immutable.
624
- *
625
- * @param node
626
- */
627
- const fetchImage = async (node) => {
628
- const src = getSource(node);
629
- const { cache } = node.props;
630
- if (!src) {
631
- console.warn(false, 'Image should receive either a "src" or "source" prop');
632
- return;
633
- }
634
- try {
635
- const source = await resolveSource(src);
636
- if (!source) {
637
- throw new Error(`Image's "src" or "source" prop returned ${source}`);
638
- }
639
- node.image = await resolveImage(source, { cache });
640
- if (Buffer.isBuffer(source) || source instanceof Blob)
641
- return;
642
- node.image.key = 'data' in source ? source.data.toString() : source.uri;
643
- }
644
- catch (e) {
645
- console.warn(e.message);
646
- }
647
- };
648
-
649
- const isImage$2 = (node) => node.type === Image;
650
- /**
651
- * Get all asset promises that need to be resolved
652
- *
653
- * @param fontStore - Font store
654
- * @param node - Root node
655
- * @returns Asset promises
656
- */
657
- const fetchAssets = (fontStore, node) => {
658
- const promises = [];
659
- const listToExplore = node.children?.slice(0) || [];
660
- const emojiSource = fontStore ? fontStore.getEmojiSource() : null;
661
- while (listToExplore.length > 0) {
662
- const n = listToExplore.shift();
663
- if (isImage$2(n)) {
664
- promises.push(fetchImage(n));
665
- }
666
- if (fontStore && n.style?.fontFamily) {
667
- const fontFamilies = castArray(n.style.fontFamily);
668
- promises.push(...fontFamilies.map((fontFamily) => fontStore.load({
669
- fontFamily,
670
- fontStyle: n.style.fontStyle,
671
- fontWeight: n.style.fontWeight,
672
- })));
673
- }
674
- if (typeof n === 'string') {
675
- promises.push(...fetchEmojis(n, emojiSource));
676
- }
677
- if ('value' in n && typeof n.value === 'string') {
678
- promises.push(...fetchEmojis(n.value, emojiSource));
679
- }
680
- if (n.children) {
681
- n.children.forEach((childNode) => {
682
- listToExplore.push(childNode);
683
- });
684
- }
685
- }
686
- return promises;
687
- };
688
- /**
689
- * Fetch image, font and emoji assets in parallel.
690
- * Layout process will not be resumed until promise resolves.
691
- *
692
- * @param node root node
693
- * @param fontStore font store
694
- * @returns Root node
695
- */
696
- const resolveAssets = async (node, fontStore) => {
697
- const promises = fetchAssets(fontStore, node);
698
- await Promise.all(promises);
699
- return node;
700
- };
701
-
702
- const isLink$1 = (node) => node.type === Link;
703
- const DEFAULT_LINK_STYLES = {
704
- color: 'blue',
705
- textDecoration: 'underline',
706
- };
707
- /**
708
- * Computes styles using stylesheet
709
- *
710
- * @param container
711
- * @param node - Document node
712
- * @returns Computed styles
713
- */
714
- const computeStyle = (container, node) => {
715
- let baseStyle = [node.style];
716
- if (isLink$1(node)) {
717
- baseStyle = Array.isArray(node.style)
718
- ? [DEFAULT_LINK_STYLES, ...node.style]
719
- : [DEFAULT_LINK_STYLES, node.style];
720
- }
721
- return resolveStyles$1(container, baseStyle);
722
- };
723
- /**
724
- * Resolves node styles
725
- *
726
- * @param container
727
- * @returns Resolve node styles
728
- */
729
- const resolveNodeStyles = (container) => (node) => {
730
- const style = computeStyle(container, node);
731
- if (!node.children)
732
- return Object.assign({}, node, { style });
733
- const children = node.children.map(resolveNodeStyles(container));
734
- return Object.assign({}, node, { style, children });
735
- };
736
- /**
737
- * Resolves page styles
738
- *
739
- * @param page Document page
740
- * @returns Document page with resolved styles
741
- */
742
- const resolvePageStyles = (page) => {
743
- const dpi = page.props?.dpi || 72;
744
- const style = page.style;
745
- const width = page.box?.width || style.width;
746
- const height = page.box?.height || style.height;
747
- const orientation = page.props?.orientation || 'portrait';
748
- const remBase = style?.fontSize || 18;
749
- const container = { width, height, orientation, dpi, remBase };
750
- return resolveNodeStyles(container)(page);
751
- };
752
- /**
753
- * Resolves document styles
754
- *
755
- * @param root - Document root
756
- * @returns Document root with resolved styles
757
- */
758
- const resolveStyles = (root) => {
759
- if (!root.children)
760
- return root;
761
- const children = root.children.map(resolvePageStyles);
762
- return Object.assign({}, root, { children });
763
- };
764
-
765
- const getTransformStyle = (s) => (node) => isNil(node.style?.[s]) ? '50%' : node.style?.[s] ?? null;
766
- /**
767
- * Get node origin
768
- *
769
- * @param node
770
- * @returns {{ left?: number, top?: number }} node origin
771
- */
772
- const getOrigin = (node) => {
773
- if (!node.box)
774
- return null;
775
- const { left, top, width, height } = node.box;
776
- const transformOriginX = getTransformStyle('transformOriginX')(node);
777
- const transformOriginY = getTransformStyle('transformOriginY')(node);
778
- const percentX = matchPercent(transformOriginX);
779
- const percentY = matchPercent(transformOriginY);
780
- const offsetX = percentX ? width * percentX.percent : transformOriginX;
781
- const offsetY = percentY ? height * percentY.percent : transformOriginY;
782
- if (isNil(offsetX) || typeof offsetX === 'string')
783
- throw new Error(`Invalid origin offsetX: ${offsetX}`);
784
- if (isNil(offsetY) || typeof offsetY === 'string')
785
- throw new Error(`Invalid origin offsetY: ${offsetY}`);
786
- return { left: left + offsetX, top: top + offsetY };
787
- };
788
-
789
- /**
790
- * Resolve node origin
791
- *
792
- * @param node
793
- * @returns Node with origin attribute
794
- */
795
- const resolveNodeOrigin = (node) => {
796
- const origin = getOrigin(node);
797
- const newNode = Object.assign({}, node, { origin });
798
- if (!node.children)
799
- return newNode;
800
- const children = node.children.map(resolveNodeOrigin);
801
- return Object.assign({}, newNode, { children });
802
- };
803
- /**
804
- * Resolve document origins
805
- *
806
- * @param root - Document root
807
- * @returns Document root
808
- */
809
- const resolveOrigin = (root) => {
810
- if (!root.children)
811
- return root;
812
- const children = root.children.map(resolveNodeOrigin);
813
- return Object.assign({}, root, { children });
814
- };
815
-
816
- const getBookmarkValue = (bookmark) => {
817
- return typeof bookmark === 'string'
818
- ? { title: bookmark, fit: false, expanded: false }
819
- : bookmark;
820
- };
821
- const resolveBookmarks = (node) => {
822
- let refs = 0;
823
- const children = (node.children || []).slice(0);
824
- const listToExplore = children.map((value) => ({
825
- value,
826
- parent: null,
827
- }));
828
- while (listToExplore.length > 0) {
829
- const element = listToExplore.shift();
830
- if (!element)
831
- break;
832
- const child = element.value;
833
- let parent = element.parent;
834
- if (child.props && 'bookmark' in child.props) {
835
- const bookmark = getBookmarkValue(child.props.bookmark);
836
- const ref = refs++;
837
- const newHierarchy = { ref, parent: parent?.ref, ...bookmark };
838
- child.props.bookmark = newHierarchy;
839
- parent = newHierarchy;
840
- }
841
- if (child.children) {
842
- child.children.forEach((childNode) => {
843
- listToExplore.push({ value: childNode, parent });
844
- });
845
- }
846
- }
847
- return node;
848
- };
849
-
850
- const VALID_ORIENTATIONS = ['portrait', 'landscape'];
851
- /**
852
- * Get page orientation. Defaults to portrait
853
- *
854
- * @param page - Page object
855
- * @returns Page orientation
856
- */
857
- const getOrientation = (page) => {
858
- const value = page.props?.orientation || 'portrait';
859
- return VALID_ORIENTATIONS.includes(value) ? value : 'portrait';
860
- };
861
-
862
- /**
863
- * Return true if page is landscape
864
- *
865
- * @param page - Page instance
866
- * @returns Is page landscape
867
- */
868
- const isLandscape = (page) => getOrientation(page) === 'landscape';
869
-
870
- // Page sizes for 72dpi. 72dpi is used internally by pdfkit.
871
- const PAGE_SIZES = {
872
- '4A0': [4767.87, 6740.79],
873
- '2A0': [3370.39, 4767.87],
874
- A0: [2383.94, 3370.39],
875
- A1: [1683.78, 2383.94],
876
- A2: [1190.55, 1683.78],
877
- A3: [841.89, 1190.55],
878
- A4: [595.28, 841.89],
879
- A5: [419.53, 595.28],
880
- A6: [297.64, 419.53],
881
- A7: [209.76, 297.64],
882
- A8: [147.4, 209.76],
883
- A9: [104.88, 147.4],
884
- A10: [73.7, 104.88],
885
- B0: [2834.65, 4008.19],
886
- B1: [2004.09, 2834.65],
887
- B2: [1417.32, 2004.09],
888
- B3: [1000.63, 1417.32],
889
- B4: [708.66, 1000.63],
890
- B5: [498.9, 708.66],
891
- B6: [354.33, 498.9],
892
- B7: [249.45, 354.33],
893
- B8: [175.75, 249.45],
894
- B9: [124.72, 175.75],
895
- B10: [87.87, 124.72],
896
- C0: [2599.37, 3676.54],
897
- C1: [1836.85, 2599.37],
898
- C2: [1298.27, 1836.85],
899
- C3: [918.43, 1298.27],
900
- C4: [649.13, 918.43],
901
- C5: [459.21, 649.13],
902
- C6: [323.15, 459.21],
903
- C7: [229.61, 323.15],
904
- C8: [161.57, 229.61],
905
- C9: [113.39, 161.57],
906
- C10: [79.37, 113.39],
907
- RA0: [2437.8, 3458.27],
908
- RA1: [1729.13, 2437.8],
909
- RA2: [1218.9, 1729.13],
910
- RA3: [864.57, 1218.9],
911
- RA4: [609.45, 864.57],
912
- SRA0: [2551.18, 3628.35],
913
- SRA1: [1814.17, 2551.18],
914
- SRA2: [1275.59, 1814.17],
915
- SRA3: [907.09, 1275.59],
916
- SRA4: [637.8, 907.09],
917
- EXECUTIVE: [521.86, 756.0],
918
- FOLIO: [612.0, 936.0],
919
- LEGAL: [612.0, 1008.0],
920
- LETTER: [612.0, 792.0],
921
- TABLOID: [792.0, 1224.0],
922
- ID1: [153, 243],
923
- };
924
- /**
925
- * Parses scalar value in value and unit pairs
926
- *
927
- * @param value - Scalar value
928
- * @returns Parsed value
929
- */
930
- const parseValue = (value) => {
931
- if (typeof value === 'number')
932
- return { value, unit: undefined };
933
- const match = /^(-?\d*\.?\d+)(in|mm|cm|pt|px)?$/g.exec(value);
934
- return match
935
- ? { value: parseFloat(match[1]), unit: match[2] || 'pt' }
936
- : { value, unit: undefined };
937
- };
938
- /**
939
- * Transform given scalar value to 72dpi equivalent of size
940
- *
941
- * @param value - Styles value
942
- * @param inputDpi - User defined dpi
943
- * @returns Transformed value
944
- */
945
- const transformUnit = (value, inputDpi) => {
946
- if (!value)
947
- return 0;
948
- const scalar = parseValue(value);
949
- const outputDpi = 72;
950
- const mmFactor = (1 / 25.4) * outputDpi;
951
- const cmFactor = (1 / 2.54) * outputDpi;
952
- if (typeof scalar.value === 'string')
953
- throw new Error(`Invalid page size: ${value}`);
954
- switch (scalar.unit) {
955
- case 'in':
956
- return scalar.value * outputDpi;
957
- case 'mm':
958
- return scalar.value * mmFactor;
959
- case 'cm':
960
- return scalar.value * cmFactor;
961
- case 'px':
962
- return Math.round(scalar.value * (outputDpi / inputDpi));
963
- default:
964
- return scalar.value;
965
- }
966
- };
967
- const transformUnits = ({ width, height }, dpi) => ({
968
- width: transformUnit(width, dpi),
969
- height: transformUnit(height, dpi),
970
- });
971
- /**
972
- * Transforms array into size object
973
- *
974
- * @param v - Values array
975
- * @returns Size object with width and height
976
- */
977
- const toSizeObject = (v) => ({
978
- width: v[0],
979
- height: v[1],
980
- });
981
- /**
982
- * Flip size object
983
- *
984
- * @param v - Size object
985
- * @returns Flipped size object
986
- */
987
- const flipSizeObject = (v) => ({
988
- width: v.height,
989
- height: v.width,
990
- });
991
- /**
992
- * Returns size object from a given string
993
- *
994
- * @param v - Page size string
995
- * @returns Size object with width and height
996
- */
997
- const getStringSize = (v) => {
998
- return toSizeObject(PAGE_SIZES[v.toUpperCase()]);
999
- };
1000
- /**
1001
- * Returns size object from a single number
1002
- *
1003
- * @param n - Page size number
1004
- * @returns Size object with width and height
1005
- */
1006
- const getNumberSize = (n) => toSizeObject([n, n]);
1007
- /**
1008
- * Return page size in an object { width, height }
1009
- *
1010
- * @param page - Page node
1011
- * @returns Size object with width and height
1012
- */
1013
- const getSize = (page) => {
1014
- const value = page.props?.size || 'A4';
1015
- const dpi = page.props?.dpi || 72;
1016
- let size;
1017
- if (typeof value === 'string') {
1018
- size = getStringSize(value);
1019
- }
1020
- else if (Array.isArray(value)) {
1021
- size = transformUnits(toSizeObject(value), dpi);
1022
- }
1023
- else if (typeof value === 'number') {
1024
- size = transformUnits(getNumberSize(value), dpi);
1025
- }
1026
- else {
1027
- size = transformUnits(value, dpi);
1028
- }
1029
- return isLandscape(page) ? flipSizeObject(size) : size;
1030
- };
1031
-
1032
- /**
1033
- * Resolves page size
1034
- *
1035
- * @param page
1036
- * @returns Page with resolved size in style attribute
1037
- */
1038
- const resolvePageSize = (page) => {
1039
- const size = getSize(page);
1040
- const style = flatten(page.style || {});
1041
- return { ...page, style: { ...style, ...size } };
1042
- };
1043
- /**
1044
- * Resolves page sizes
1045
- *
1046
- * @param root -Document root
1047
- * @returns Document root with resolved page sizes
1048
- */
1049
- const resolvePageSizes = (root) => {
1050
- if (!root.children)
1051
- return root;
1052
- const children = root.children.map(resolvePageSize);
1053
- return Object.assign({}, root, { children });
1054
- };
1055
-
1056
- const isFixed = (node) => {
1057
- if (!node.props)
1058
- return false;
1059
- return 'fixed' in node.props ? node.props.fixed === true : false;
1060
- };
1061
-
1062
- /**
1063
- * Get line index at given height
1064
- *
1065
- * @param node
1066
- * @param height
1067
- */
1068
- const lineIndexAtHeight = (node, height) => {
1069
- let y = 0;
1070
- if (!node.lines)
1071
- return 0;
1072
- for (let i = 0; i < node.lines.length; i += 1) {
1073
- const line = node.lines[i];
1074
- if (y + line.box.height > height)
1075
- return i;
1076
- y += line.box.height;
1077
- }
1078
- return node.lines.length;
1079
- };
1080
-
1081
- /**
1082
- * Get height for given text line index
1083
- *
1084
- * @param node
1085
- * @param index
1086
- */
1087
- const heightAtLineIndex = (node, index) => {
1088
- let counter = 0;
1089
- if (!node.lines)
1090
- return counter;
1091
- for (let i = 0; i < index; i += 1) {
1092
- const line = node.lines[i];
1093
- if (!line)
1094
- break;
1095
- counter += line.box.height;
1096
- }
1097
- return counter;
1098
- };
1099
-
1100
- const getLineBreak = (node, height) => {
1101
- const top = node.box?.top || 0;
1102
- const widows = node.props.widows || 2;
1103
- const orphans = node.props.orphans || 2;
1104
- const linesQuantity = node.lines.length;
1105
- const slicedLine = lineIndexAtHeight(node, height - top);
1106
- if (slicedLine === 0) {
1107
- return 0;
1108
- }
1109
- if (linesQuantity < orphans) {
1110
- return linesQuantity;
1111
- }
1112
- if (slicedLine < orphans || linesQuantity < orphans + widows) {
1113
- return 0;
1114
- }
1115
- if (linesQuantity === orphans + widows) {
1116
- return orphans;
1117
- }
1118
- if (linesQuantity - slicedLine < widows) {
1119
- return linesQuantity - widows;
1120
- }
1121
- return slicedLine;
1122
- };
1123
- // Also receives contentArea in case it's needed
1124
- const splitText = (node, height) => {
1125
- const slicedLineIndex = getLineBreak(node, height);
1126
- const currentHeight = heightAtLineIndex(node, slicedLineIndex);
1127
- const nextHeight = node.box.height - currentHeight;
1128
- const current = Object.assign({}, node, {
1129
- box: {
1130
- ...node.box,
1131
- height: currentHeight,
1132
- borderBottomWidth: 0,
1133
- },
1134
- style: {
1135
- ...node.style,
1136
- marginBottom: 0,
1137
- paddingBottom: 0,
1138
- borderBottomWidth: 0,
1139
- borderBottomLeftRadius: 0,
1140
- borderBottomRightRadius: 0,
1141
- },
1142
- lines: node.lines.slice(0, slicedLineIndex),
1143
- });
1144
- const next = Object.assign({}, node, {
1145
- box: {
1146
- ...node.box,
1147
- top: 0,
1148
- height: nextHeight,
1149
- borderTopWidth: 0,
1150
- },
1151
- style: {
1152
- ...node.style,
1153
- marginTop: 0,
1154
- paddingTop: 0,
1155
- borderTopWidth: 0,
1156
- borderTopLeftRadius: 0,
1157
- borderTopRightRadius: 0,
1158
- },
1159
- lines: node.lines.slice(slicedLineIndex),
1160
- });
1161
- return [current, next];
1162
- };
1163
-
1164
- const getTop$1 = (node) => node.box?.top || 0;
1165
- const hasFixedHeight = (node) => !isNil(node.style?.height);
1166
- const splitNode = (node, height) => {
1167
- if (!node)
1168
- return [null, null];
1169
- const nodeTop = getTop$1(node);
1170
- const current = Object.assign({}, node, {
1171
- box: {
1172
- ...node.box,
1173
- borderBottomWidth: 0,
1174
- },
1175
- style: {
1176
- ...node.style,
1177
- marginBottom: 0,
1178
- paddingBottom: 0,
1179
- borderBottomWidth: 0,
1180
- borderBottomLeftRadius: 0,
1181
- borderBottomRightRadius: 0,
1182
- },
1183
- });
1184
- current.style.height = height - nodeTop;
1185
- const nextHeight = hasFixedHeight(node)
1186
- ? node.box.height - (height - nodeTop)
1187
- : null;
1188
- const next = Object.assign({}, node, {
1189
- box: {
1190
- ...node.box,
1191
- top: 0,
1192
- borderTopWidth: 0,
1193
- },
1194
- style: {
1195
- ...node.style,
1196
- marginTop: 0,
1197
- paddingTop: 0,
1198
- borderTopWidth: 0,
1199
- borderTopLeftRadius: 0,
1200
- borderTopRightRadius: 0,
1201
- },
1202
- });
1203
- if (nextHeight) {
1204
- next.style.height = nextHeight;
1205
- }
1206
- return [current, next];
1207
- };
1208
-
1209
- const NON_WRAP_TYPES = [Svg, Note, Image, Canvas];
1210
- const getWrap = (node) => {
1211
- if (NON_WRAP_TYPES.includes(node.type))
1212
- return false;
1213
- if (!node.props)
1214
- return true;
1215
- return 'wrap' in node.props ? node.props.wrap : true;
1216
- };
1217
-
1218
- const getComputedPadding = (node, edge) => {
1219
- const { yogaNode } = node;
1220
- return yogaNode ? yogaNode.getComputedPadding(edge) : null;
1221
- };
1222
- /**
1223
- * Get Yoga computed paddings. Zero otherwise
1224
- *
1225
- * @param node
1226
- * @returns paddings
1227
- */
1228
- const getPadding = (node) => {
1229
- const { style, box } = node;
1230
- const paddingTop = getComputedPadding(node, Edge.Top) ||
1231
- box?.paddingTop ||
1232
- style?.paddingTop ||
1233
- 0;
1234
- const paddingRight = getComputedPadding(node, Edge.Right) ||
1235
- box?.paddingRight ||
1236
- style?.paddingRight ||
1237
- 0;
1238
- const paddingBottom = getComputedPadding(node, Edge.Bottom) ||
1239
- box?.paddingBottom ||
1240
- style?.paddingBottom ||
1241
- 0;
1242
- const paddingLeft = getComputedPadding(node, Edge.Left) ||
1243
- box?.paddingLeft ||
1244
- style?.paddingLeft ||
1245
- 0;
1246
- return { paddingTop, paddingRight, paddingBottom, paddingLeft };
1247
- };
1248
-
1249
- const getWrapArea = (page) => {
1250
- const height = page.style?.height;
1251
- const { paddingBottom } = getPadding(page);
1252
- return height - paddingBottom;
1253
- };
1254
-
1255
- const getContentArea = (page) => {
1256
- const height = page.style?.height;
1257
- const { paddingTop, paddingBottom } = getPadding(page);
1258
- return height - paddingBottom - paddingTop;
1259
- };
1260
-
1261
- const isString = (value) => typeof value === 'string';
1262
- const isNumber = (value) => typeof value === 'number';
1263
- const isBoolean = (value) => typeof value === 'boolean';
1264
- const isFragment = (value) => value && value.type === Symbol.for('react.fragment');
1265
- /**
1266
- * Transforms a react element instance to internal element format.
1267
- *
1268
- * Can return multiple instances in the case of arrays or fragments.
1269
- *
1270
- * @param element - React element
1271
- * @returns Parsed React elements
1272
- */
1273
- const createInstances = (element) => {
1274
- if (!element)
1275
- return [];
1276
- if (Array.isArray(element)) {
1277
- return element.reduce((acc, el) => acc.concat(createInstances(el)), []);
1278
- }
1279
- if (isBoolean(element)) {
1280
- return [];
1281
- }
1282
- if (isString(element) || isNumber(element)) {
1283
- return [{ type: TextInstance, value: `${element}` }];
1284
- }
1285
- if (isFragment(element)) {
1286
- // @ts-expect-error figure out why this is complains
1287
- return createInstances(element.props.children);
1288
- }
1289
- if (!isString(element.type)) {
1290
- // @ts-expect-error figure out why this is complains
1291
- return createInstances(element.type(element.props));
1292
- }
1293
- const { type, props: { style = {}, children, ...props }, } = element;
1294
- const nextChildren = castArray(children).reduce((acc, child) => acc.concat(createInstances(child)), []);
1295
- return [
1296
- {
1297
- type,
1298
- style,
1299
- props,
1300
- children: nextChildren,
1301
- },
1302
- ];
1303
- };
1304
-
1305
- const getBreak = (node) => 'break' in node.props ? node.props.break : false;
1306
- const getMinPresenceAhead = (node) => 'minPresenceAhead' in node.props ? node.props.minPresenceAhead : 0;
1307
- const getFurthestEnd = (elements) => Math.max(...elements.map((node) => node.box.top + node.box.height));
1308
- const getEndOfMinPresenceAhead = (child) => {
1309
- return (child.box.top +
1310
- child.box.height +
1311
- child.box.marginBottom +
1312
- getMinPresenceAhead(child));
1313
- };
1314
- const getEndOfPresence = (child, futureElements) => {
1315
- const afterMinPresenceAhead = getEndOfMinPresenceAhead(child);
1316
- const endOfFurthestFutureElement = getFurthestEnd(futureElements.filter((node) => !('fixed' in node.props)));
1317
- return Math.min(afterMinPresenceAhead, endOfFurthestFutureElement);
1318
- };
1319
- const shouldBreak = (child, futureElements, height) => {
1320
- if ('fixed' in child.props)
1321
- return false;
1322
- const shouldSplit = height < child.box.top + child.box.height;
1323
- const canWrap = getWrap(child);
1324
- // Calculate the y coordinate where the desired presence of the child ends
1325
- const endOfPresence = getEndOfPresence(child, futureElements);
1326
- // If the child is already at the top of the page, breaking won't improve its presence
1327
- // (as long as react-pdf does not support breaking into differently sized containers)
1328
- const breakingImprovesPresence = child.box.top > child.box.marginTop;
1329
- return (getBreak(child) ||
1330
- (shouldSplit && !canWrap) ||
1331
- (!shouldSplit && endOfPresence > height && breakingImprovesPresence));
1332
- };
1333
-
1334
- const IGNORABLE_CODEPOINTS = [
1335
- 8232, // LINE_SEPARATOR
1336
- 8233, // PARAGRAPH_SEPARATOR
1337
- ];
1338
- const buildSubsetForFont = (font) => IGNORABLE_CODEPOINTS.reduce((acc, codePoint) => {
1339
- if (font &&
1340
- font.hasGlyphForCodePoint &&
1341
- font.hasGlyphForCodePoint(codePoint)) {
1342
- return acc;
1343
- }
1344
- return [...acc, String.fromCharCode(codePoint)];
1345
- }, []);
1346
- const ignoreChars = (fragments) => fragments.map((fragment) => {
1347
- const charSubset = buildSubsetForFont(fragment.attributes.font[0]);
1348
- const subsetRegex = new RegExp(charSubset.join('|'));
1349
- return {
1350
- string: fragment.string.replace(subsetRegex, ''),
1351
- attributes: fragment.attributes,
1352
- };
1353
- });
1354
-
1355
- const PREPROCESSORS = [ignoreChars, embedEmojis];
1356
- const isImage$1 = (node) => node.type === Image;
1357
- const isTextInstance$2 = (node) => node.type === TextInstance;
1358
- /**
1359
- * Get textkit fragments of given node object
1360
- *
1361
- * @param fontStore - Font store
1362
- * @param instance - Node
1363
- * @param parentLink - Parent link
1364
- * @param level - Fragment level
1365
- * @returns Text fragments
1366
- */
1367
- const getFragments = (fontStore, instance, parentLink = null, level = 0) => {
1368
- if (!instance)
1369
- return [{ string: '' }];
1370
- let fragments = [];
1371
- const { color = 'black', direction = 'ltr', fontFamily = 'Helvetica', fontWeight, fontStyle, fontSize = 18, textAlign, lineHeight, textDecoration, textDecorationColor, textDecorationStyle, textTransform, letterSpacing, textIndent, opacity, verticalAlign, } = instance.style;
1372
- const fontFamilies = typeof fontFamily === 'string' ? [fontFamily] : [...(fontFamily || [])];
1373
- // Fallback font
1374
- fontFamilies.push('Helvetica');
1375
- const font = fontFamilies.map((fontFamilyName) => {
1376
- const opts = { fontFamily: fontFamilyName, fontWeight, fontStyle };
1377
- const obj = fontStore.getFont(opts);
1378
- return obj?.data;
1379
- });
1380
- // Don't pass main background color to textkit. Will be rendered by the render package instead
1381
- const backgroundColor = level === 0 ? null : instance.style.backgroundColor;
1382
- const attributes = {
1383
- font,
1384
- color,
1385
- opacity,
1386
- fontSize,
1387
- lineHeight,
1388
- direction,
1389
- verticalAlign,
1390
- backgroundColor,
1391
- indent: textIndent,
1392
- characterSpacing: letterSpacing,
1393
- strikeStyle: textDecorationStyle,
1394
- underlineStyle: textDecorationStyle,
1395
- underline: textDecoration === 'underline' ||
1396
- textDecoration === 'underline line-through' ||
1397
- textDecoration === 'line-through underline',
1398
- strike: textDecoration === 'line-through' ||
1399
- textDecoration === 'underline line-through' ||
1400
- textDecoration === 'line-through underline',
1401
- strikeColor: textDecorationColor || color,
1402
- underlineColor: textDecorationColor || color,
1403
- // @ts-expect-error allow this props access
1404
- link: parentLink || instance.props?.src || instance.props?.href,
1405
- align: textAlign || (direction === 'rtl' ? 'right' : 'left'),
1406
- };
1407
- for (let i = 0; i < instance.children.length; i += 1) {
1408
- const child = instance.children[i];
1409
- if (isImage$1(child)) {
1410
- fragments.push({
1411
- string: String.fromCharCode(0xfffc),
1412
- attributes: {
1413
- ...attributes,
1414
- attachment: {
1415
- width: (child.style.width || fontSize),
1416
- height: (child.style.height || fontSize),
1417
- image: child.image.data,
1418
- },
1419
- },
1420
- });
1421
- }
1422
- else if (isTextInstance$2(child)) {
1423
- fragments.push({
1424
- string: transformText(child.value, textTransform),
1425
- attributes,
1426
- });
1427
- }
1428
- else if (child) {
1429
- fragments.push(...getFragments(fontStore, child, attributes.link, level + 1));
1430
- }
1431
- }
1432
- for (let i = 0; i < PREPROCESSORS.length; i += 1) {
1433
- const preprocessor = PREPROCESSORS[i];
1434
- fragments = preprocessor(fragments);
1435
- }
1436
- return fragments;
1437
- };
1438
- /**
1439
- * Get textkit attributed string from text node
1440
- *
1441
- * @param fontStore - Font store
1442
- * @param instance Node
1443
- * @returns Attributed string
1444
- */
1445
- const getAttributedString = (fontStore, instance) => {
1446
- const fragments = getFragments(fontStore, instance);
1447
- return fromFragments(fragments);
1448
- };
1449
-
1450
- const engines = {
1451
- bidi: bidiEngine,
1452
- linebreaker,
1453
- justification,
1454
- textDecoration,
1455
- scriptItemizer,
1456
- wordHyphenation,
1457
- fontSubstitution,
1458
- };
1459
- const engine = layoutEngine(engines);
1460
- const getMaxLines = (node) => node.style?.maxLines;
1461
- const getTextOverflow = (node) => node.style?.textOverflow;
1462
- /**
1463
- * Get layout container for specific text node
1464
- *
1465
- * @param {number} width
1466
- * @param {number} height
1467
- * @param {Object} node
1468
- * @returns {Object} layout container
1469
- */
1470
- const getContainer = (width, height, node) => {
1471
- const maxLines = getMaxLines(node);
1472
- const textOverflow = getTextOverflow(node);
1473
- return {
1474
- x: 0,
1475
- y: 0,
1476
- width,
1477
- maxLines,
1478
- height: height || Infinity,
1479
- truncateMode: textOverflow,
1480
- };
1481
- };
1482
- /**
1483
- * Get text layout options for specific text node
1484
- *
1485
- * @param {Object} node instance
1486
- * @returns {Object} layout options
1487
- */
1488
- const getLayoutOptions = (fontStore, node) => ({
1489
- hyphenationPenalty: node.props.hyphenationPenalty,
1490
- shrinkWhitespaceFactor: { before: -0.5, after: -0.5 },
1491
- hyphenationCallback: node.props.hyphenationCallback ||
1492
- fontStore?.getHyphenationCallback() ||
1493
- null,
1494
- });
1495
- /**
1496
- * Get text lines for given node
1497
- *
1498
- * @param node - Node
1499
- * @param width - Container width
1500
- * @param height - Container height
1501
- * @param fontStore - Font store
1502
- * @returns Layout lines
1503
- */
1504
- const layoutText = (node, width, height, fontStore) => {
1505
- const attributedString = getAttributedString(fontStore, node);
1506
- const container = getContainer(width, height, node);
1507
- const options = getLayoutOptions(fontStore, node);
1508
- const lines = engine(attributedString, container, options);
1509
- return lines.reduce((acc, line) => [...acc, ...line], []);
1510
- };
1511
-
1512
- const isSvg$2 = (node) => node.type === Svg;
1513
- const isText$4 = (node) => node.type === Text;
1514
- const shouldIterate = (node) => !isSvg$2(node) && !isText$4(node);
1515
- const shouldLayoutText = (node) => isText$4(node) && !node.lines;
1516
- /**
1517
- * Performs text layout on text node if wasn't calculated before.
1518
- * Text layout is usually performed on Yoga's layout process (via setMeasureFunc),
1519
- * but we need to layout those nodes with fixed width and height.
1520
- *
1521
- * @param node
1522
- * @returns Layout node
1523
- */
1524
- const resolveTextLayout = (node, fontStore) => {
1525
- if (shouldLayoutText(node)) {
1526
- const width = node.box.width - (node.box.paddingRight + node.box.paddingLeft);
1527
- const height = node.box.height - (node.box.paddingTop + node.box.paddingBottom);
1528
- node.lines = layoutText(node, width, height, fontStore);
1529
- }
1530
- if (shouldIterate(node)) {
1531
- if (!node.children)
1532
- return node;
1533
- const mapChild = (child) => resolveTextLayout(child, fontStore);
1534
- const children = node.children.map(mapChild);
1535
- return Object.assign({}, node, { children });
1536
- }
1537
- return node;
1538
- };
1539
-
1540
- const BASE_INHERITABLE_PROPERTIES = [
1541
- 'color',
1542
- 'fontFamily',
1543
- 'fontSize',
1544
- 'fontStyle',
1545
- 'fontWeight',
1546
- 'letterSpacing',
1547
- 'opacity',
1548
- 'textDecoration',
1549
- 'textTransform',
1550
- 'lineHeight',
1551
- 'textAlign',
1552
- 'visibility',
1553
- 'wordSpacing',
1554
- ];
1555
- const TEXT_INHERITABLE_PROPERTIES = [
1556
- ...BASE_INHERITABLE_PROPERTIES,
1557
- 'backgroundColor',
1558
- ];
1559
- const isType$2 = (type) => (node) => node.type === type;
1560
- const isSvg$1 = isType$2(Svg);
1561
- const isText$3 = isType$2(Text);
1562
- // Merge style values
1563
- const mergeValues = (styleName, value, inheritedValue) => {
1564
- switch (styleName) {
1565
- case 'textDecoration': {
1566
- // merge not none and not false textDecoration values to one rule
1567
- return [inheritedValue, value].filter((v) => v && v !== 'none').join(' ');
1568
- }
1569
- default:
1570
- return value;
1571
- }
1572
- };
1573
- // Merge inherited and node styles
1574
- const merge = (inheritedStyles, style) => {
1575
- const mergedStyles = { ...inheritedStyles };
1576
- Object.entries(style).forEach(([styleName, value]) => {
1577
- mergedStyles[styleName] = mergeValues(styleName, value, inheritedStyles[styleName]);
1578
- });
1579
- return mergedStyles;
1580
- };
1581
- /**
1582
- * Merges styles with node
1583
- *
1584
- * @param inheritedStyles - Style object
1585
- * @returns Merge styles function
1586
- */
1587
- const mergeStyles = (inheritedStyles) => (node) => {
1588
- const style = merge(inheritedStyles, node.style || {});
1589
- return Object.assign({}, node, { style });
1590
- };
1591
- /**
1592
- * Inherit style values from the root to the leafs
1593
- *
1594
- * @param node - Document root
1595
- * @returns Document root with inheritance
1596
- *
1597
- */
1598
- const resolveInheritance = (node) => {
1599
- if (isSvg$1(node))
1600
- return node;
1601
- if (!('children' in node))
1602
- return node;
1603
- const inheritableProperties = isText$3(node)
1604
- ? TEXT_INHERITABLE_PROPERTIES
1605
- : BASE_INHERITABLE_PROPERTIES;
1606
- const inheritStyles = pick(inheritableProperties, node.style || {});
1607
- const resolveChild = compose(resolveInheritance, mergeStyles(inheritStyles));
1608
- const children = node.children.map(resolveChild);
1609
- return Object.assign({}, node, { children });
1610
- };
1611
-
1612
- const getComputedMargin = (node, edge) => {
1613
- const { yogaNode } = node;
1614
- return yogaNode ? yogaNode.getComputedMargin(edge) : null;
1615
- };
1616
- /**
1617
- * Get Yoga computed magins. Zero otherwise
1618
- *
1619
- * @param node
1620
- * @returns Margins
1621
- */
1622
- const getMargin = (node) => {
1623
- const { style, box } = node;
1624
- const marginTop = getComputedMargin(node, Edge.Top) ||
1625
- box?.marginTop ||
1626
- style?.marginTop ||
1627
- 0;
1628
- const marginRight = getComputedMargin(node, Edge.Right) ||
1629
- box?.marginRight ||
1630
- style?.marginRight ||
1631
- 0;
1632
- const marginBottom = getComputedMargin(node, Edge.Bottom) ||
1633
- box?.marginBottom ||
1634
- style?.marginBottom ||
1635
- 0;
1636
- const marginLeft = getComputedMargin(node, Edge.Left) ||
1637
- box?.marginLeft ||
1638
- style?.marginLeft ||
1639
- 0;
1640
- return { marginTop, marginRight, marginBottom, marginLeft };
1641
- };
1642
-
1643
- /**
1644
- * Get Yoga computed position. Zero otherwise
1645
- *
1646
- * @param node
1647
- * @returns Position
1648
- */
1649
- const getPosition = (node) => {
1650
- const { yogaNode } = node;
1651
- return {
1652
- top: yogaNode?.getComputedTop() || 0,
1653
- right: yogaNode?.getComputedRight() || 0,
1654
- bottom: yogaNode?.getComputedBottom() || 0,
1655
- left: yogaNode?.getComputedLeft() || 0,
1656
- };
1657
- };
1658
-
1659
- const DEFAULT_DIMENSION = {
1660
- width: 0,
1661
- height: 0,
1662
- };
1663
- /**
1664
- * Get Yoga computed dimensions. Zero otherwise
1665
- *
1666
- * @param node
1667
- * @returns Dimensions
1668
- */
1669
- const getDimension = (node) => {
1670
- const { yogaNode } = node;
1671
- if (!yogaNode)
1672
- return DEFAULT_DIMENSION;
1673
- return {
1674
- width: yogaNode.getComputedWidth(),
1675
- height: yogaNode.getComputedHeight(),
1676
- };
1677
- };
1678
-
1679
- const getComputedBorder = (yogaNode, edge) => (yogaNode ? yogaNode.getComputedBorder(edge) : 0);
1680
- /**
1681
- * Get Yoga computed border width. Zero otherwise
1682
- *
1683
- * @param node
1684
- * @returns Border widths
1685
- */
1686
- const getBorderWidth = (node) => {
1687
- const { yogaNode } = node;
1688
- return {
1689
- borderTopWidth: getComputedBorder(yogaNode, Edge.Top),
1690
- borderRightWidth: getComputedBorder(yogaNode, Edge.Right),
1691
- borderBottomWidth: getComputedBorder(yogaNode, Edge.Bottom),
1692
- borderLeftWidth: getComputedBorder(yogaNode, Edge.Left),
1693
- };
1694
- };
1695
-
1696
- /**
1697
- * Set display attribute to node's Yoga instance
1698
- *
1699
- * @param value - Display
1700
- * @returns Node instance wrapper
1701
- */
1702
- const setDisplay = (value) => (node) => {
1703
- const { yogaNode } = node;
1704
- if (yogaNode) {
1705
- yogaNode.setDisplay(value === 'none' ? Display.None : Display.Flex);
1706
- }
1707
- return node;
1708
- };
1709
-
1710
- const OVERFLOW = {
1711
- hidden: Overflow.Hidden,
1712
- scroll: Overflow.Scroll,
1713
- };
1714
- /**
1715
- * Set overflow attribute to node's Yoga instance
1716
- *
1717
- * @param value - Overflow value
1718
- * @returns Node instance wrapper
1719
- */
1720
- const setOverflow = (value) => (node) => {
1721
- const { yogaNode } = node;
1722
- if (!isNil(value) && yogaNode) {
1723
- const overflow = OVERFLOW[value] || Overflow.Visible;
1724
- yogaNode.setOverflow(overflow);
1725
- }
1726
- return node;
1727
- };
1728
-
1729
- const FLEX_WRAP = {
1730
- wrap: Wrap.Wrap,
1731
- 'wrap-reverse': Wrap.WrapReverse,
1732
- };
1733
- /**
1734
- * Set flex wrap attribute to node's Yoga instance
1735
- *
1736
- * @param value - Flex wrap value
1737
- * @returns Node instance wrapper
1738
- */
1739
- const setFlexWrap = (value) => (node) => {
1740
- const { yogaNode } = node;
1741
- if (yogaNode) {
1742
- const flexWrap = FLEX_WRAP[value] || Wrap.NoWrap;
1743
- yogaNode.setFlexWrap(flexWrap);
1744
- }
1745
- return node;
1746
- };
1747
-
1748
- /**
1749
- * Set generic yoga attribute to node's Yoga instance, handing `auto`, edges and percentage cases
1750
- *
1751
- * @param attr - Property
1752
- * @param edge - Edge
1753
- * @returns Node instance wrapper
1754
- */
1755
- const setYogaValue = (attr, edge) => (value) => (node) => {
1756
- const { yogaNode } = node;
1757
- if (!isNil(value) && yogaNode) {
1758
- const hasEdge = !isNil(edge);
1759
- const fixedMethod = `set${upperFirst(attr)}`;
1760
- const autoMethod = `${fixedMethod}Auto`;
1761
- const percentMethod = `${fixedMethod}Percent`;
1762
- const percent = matchPercent(value);
1763
- if (percent && !yogaNode[percentMethod]) {
1764
- throw new Error(`You can't pass percentage values to ${attr} property`);
1765
- }
1766
- if (percent) {
1767
- if (hasEdge) {
1768
- yogaNode[percentMethod]?.(edge, percent.value);
1769
- }
1770
- else {
1771
- yogaNode[percentMethod]?.(percent.value);
1772
- }
1773
- }
1774
- else if (value === 'auto') {
1775
- if (hasEdge) {
1776
- yogaNode[autoMethod]?.(edge);
1777
- }
1778
- else {
1779
- yogaNode[autoMethod]?.();
1780
- }
1781
- }
1782
- else if (hasEdge) {
1783
- yogaNode[fixedMethod]?.(edge, value);
1784
- }
1785
- else {
1786
- yogaNode[fixedMethod]?.(value);
1787
- }
1788
- }
1789
- return node;
1790
- };
1791
-
1792
- /**
1793
- * Set flex grow attribute to node's Yoga instance
1794
- *
1795
- * @param value - Flex grow value
1796
- * @returns Node instance wrapper
1797
- */
1798
- const setFlexGrow = (value) => (node) => {
1799
- return setYogaValue('flexGrow')(value || 0)(node);
1800
- };
1801
-
1802
- /**
1803
- * Set flex basis attribute to node's Yoga instance
1804
- *
1805
- * @param flex - Basis value
1806
- * @param node - Node instance
1807
- * @returns Node instance
1808
- */
1809
- const setFlexBasis = setYogaValue('flexBasis');
1810
-
1811
- const ALIGN = {
1812
- 'flex-start': Align.FlexStart,
1813
- center: Align.Center,
1814
- 'flex-end': Align.FlexEnd,
1815
- stretch: Align.Stretch,
1816
- baseline: Align.Baseline,
1817
- 'space-between': Align.SpaceBetween,
1818
- 'space-around': Align.SpaceAround,
1819
- 'space-evenly': Align.SpaceEvenly,
1820
- };
1821
- /**
1822
- * Set generic align attribute to node's Yoga instance
1823
- *
1824
- * @param attr - Specific align property
1825
- * @param value - Specific align value
1826
- * @param node - Node
1827
- * @returns Node
1828
- */
1829
- const setAlign = (attr) => (value) => (node) => {
1830
- const { yogaNode } = node;
1831
- const defaultValue = attr === 'items' ? Align.Stretch : Align.Auto;
1832
- if (yogaNode) {
1833
- const align = ALIGN[value] || defaultValue;
1834
- yogaNode[`setAlign${upperFirst(attr)}`](align);
1835
- }
1836
- return node;
1837
- };
1838
-
1839
- /**
1840
- * Set align self attribute to node's Yoga instance
1841
- *
1842
- * @param align - Value
1843
- * @param node - Node instance
1844
- * @returns Node instance
1845
- */
1846
- const setAlignSelf = setAlign('self');
1847
-
1848
- /**
1849
- * Set align items attribute to node's Yoga instance
1850
- *
1851
- * @param align - Value
1852
- * @param node - Node instance
1853
- * @returns Node instance
1854
- */
1855
- const setAlignItems = setAlign('items');
1856
-
1857
- /**
1858
- * Set flex shrink attribute to node's Yoga instance
1859
- *
1860
- * @param value - Flex shrink value
1861
- * @returns Node instance wrapper
1862
- */
1863
- const setFlexShrink = (value) => (node) => {
1864
- return setYogaValue('flexShrink')(value || 1)(node);
1865
- };
1866
-
1867
- /**
1868
- * Set aspect ratio attribute to node's Yoga instance
1869
- *
1870
- * @param value - Ratio
1871
- * @returns Node instance
1872
- */
1873
- const setAspectRatio = (value) => (node) => {
1874
- const { yogaNode } = node;
1875
- if (!isNil(value) && yogaNode) {
1876
- yogaNode.setAspectRatio(value);
1877
- }
1878
- return node;
1879
- };
1880
-
1881
- /**
1882
- * Set align content attribute to node's Yoga instance
1883
- *
1884
- * @param align - Value
1885
- * @param node - Instance
1886
- * @returns Node instance
1887
- */
1888
- const setAlignContent = setAlign('content');
1889
-
1890
- const POSITION = {
1891
- absolute: PositionType.Absolute,
1892
- relative: PositionType.Relative,
1893
- static: PositionType.Static,
1894
- };
1895
- /**
1896
- * Set position type attribute to node's Yoga instance
1897
- *
1898
- * @param value - Position position type
1899
- * @returns Node instance
1900
- */
1901
- const setPositionType = (value) => (node) => {
1902
- const { yogaNode } = node;
1903
- if (!isNil(value) && yogaNode) {
1904
- yogaNode.setPositionType(POSITION[value]);
1905
- }
1906
- return node;
1907
- };
1908
-
1909
- const FLEX_DIRECTIONS = {
1910
- row: FlexDirection.Row,
1911
- 'row-reverse': FlexDirection.RowReverse,
1912
- 'column-reverse': FlexDirection.ColumnReverse,
1913
- };
1914
- /**
1915
- * Set flex direction attribute to node's Yoga instance
1916
- *
1917
- * @param value - Flex direction value
1918
- * @returns Node instance wrapper
1919
- */
1920
- const setFlexDirection = (value) => (node) => {
1921
- const { yogaNode } = node;
1922
- if (yogaNode) {
1923
- const flexDirection = FLEX_DIRECTIONS[value] || FlexDirection.Column;
1924
- yogaNode.setFlexDirection(flexDirection);
1925
- }
1926
- return node;
1927
- };
1928
-
1929
- const JUSTIFY_CONTENT = {
1930
- center: Justify.Center,
1931
- 'flex-end': Justify.FlexEnd,
1932
- 'space-between': Justify.SpaceBetween,
1933
- 'space-around': Justify.SpaceAround,
1934
- 'space-evenly': Justify.SpaceEvenly,
1935
- };
1936
- /**
1937
- * Set justify content attribute to node's Yoga instance
1938
- *
1939
- * @param value - Justify content value
1940
- * @returns Node instance wrapper
1941
- */
1942
- const setJustifyContent = (value) => (node) => {
1943
- const { yogaNode } = node;
1944
- if (!isNil(value) && yogaNode) {
1945
- const justifyContent = JUSTIFY_CONTENT[value] || Justify.FlexStart;
1946
- yogaNode.setJustifyContent(justifyContent);
1947
- }
1948
- return node;
1949
- };
1950
-
1951
- /**
1952
- * Set margin top attribute to node's Yoga instance
1953
- *
1954
- * @param margin - Margin top
1955
- * @param node - Node instance
1956
- * @returns Node instance
1957
- */
1958
- const setMarginTop = setYogaValue('margin', Edge.Top);
1959
- /**
1960
- * Set margin right attribute to node's Yoga instance
1961
- *
1962
- * @param margin - Margin right
1963
- * @param node - Node instance
1964
- * @returns Node instance
1965
- */
1966
- const setMarginRight = setYogaValue('margin', Edge.Right);
1967
- /**
1968
- * Set margin bottom attribute to node's Yoga instance
1969
- *
1970
- * @param margin - Margin bottom
1971
- * @param node - Node instance
1972
- * @returns Node instance
1973
- */
1974
- const setMarginBottom = setYogaValue('margin', Edge.Bottom);
1975
- /**
1976
- * Set margin left attribute to node's Yoga instance
1977
- *
1978
- * @param margin - Margin left
1979
- * @param node - Node instance
1980
- * @returns Node instance
1981
- */
1982
- const setMarginLeft = setYogaValue('margin', Edge.Left);
1983
-
1984
- /**
1985
- * Set padding top attribute to node's Yoga instance
1986
- *
1987
- * @param padding - Padding top
1988
- * @param node - Node instance
1989
- * @returns Node instance
1990
- */
1991
- const setPaddingTop = setYogaValue('padding', Edge.Top);
1992
- /**
1993
- * Set padding right attribute to node's Yoga instance
1994
- *
1995
- * @param padding - Padding right
1996
- * @param node - Node instance
1997
- * @returns Node instance
1998
- */
1999
- const setPaddingRight = setYogaValue('padding', Edge.Right);
2000
- /**
2001
- * Set padding bottom attribute to node's Yoga instance
2002
- *
2003
- * @param padding - Padding bottom
2004
- * @param node Node instance
2005
- * @returns Node instance
2006
- */
2007
- const setPaddingBottom = setYogaValue('padding', Edge.Bottom);
2008
- /**
2009
- * Set padding left attribute to node's Yoga instance
2010
- *
2011
- * @param padding - Padding left
2012
- * @param node - Node instance
2013
- * @returns Node instance
2014
- */
2015
- const setPaddingLeft = setYogaValue('padding', Edge.Left);
2016
-
2017
- /**
2018
- * Set border top attribute to node's Yoga instance
2019
- *
2020
- * @param border - Border top width
2021
- * @param node - Node instance
2022
- * @returns Node instance
2023
- */
2024
- const setBorderTop = setYogaValue('border', Edge.Top);
2025
- /**
2026
- * Set border right attribute to node's Yoga instance
2027
- *
2028
- * @param border - Border right width
2029
- * @param node - Node instance
2030
- * @returns Node instance
2031
- */
2032
- const setBorderRight = setYogaValue('border', Edge.Right);
2033
- /**
2034
- * Set border bottom attribute to node's Yoga instance
2035
- *
2036
- * @param border - Border bottom width
2037
- * @param node - Node instance
2038
- * @returns Node instance
2039
- */
2040
- const setBorderBottom = setYogaValue('border', Edge.Bottom);
2041
- /**
2042
- * Set border left attribute to node's Yoga instance
2043
- *
2044
- * @param border - Border left width
2045
- * @param node - Node instance
2046
- * @returns Node instance
2047
- */
2048
- const setBorderLeft = setYogaValue('border', Edge.Left);
2049
-
2050
- /**
2051
- * Set position top attribute to node's Yoga instance
2052
- *
2053
- * @param position - Position top
2054
- * @param node - Node instance
2055
- * @returns Node instance
2056
- */
2057
- const setPositionTop = setYogaValue('position', Edge.Top);
2058
- /**
2059
- * Set position right attribute to node's Yoga instance
2060
- *
2061
- * @param position - Position right
2062
- * @param node - Node instance
2063
- * @returns Node instance
2064
- */
2065
- const setPositionRight = setYogaValue('position', Edge.Right);
2066
- /**
2067
- * Set position bottom attribute to node's Yoga instance
2068
- *
2069
- * @param position - Position bottom
2070
- * @param node - Node instance
2071
- * @returns Node instance
2072
- */
2073
- const setPositionBottom = setYogaValue('position', Edge.Bottom);
2074
- /**
2075
- * Set position left attribute to node's Yoga instance
2076
- *
2077
- * @param position - Position left
2078
- * @param node - Node instance
2079
- * @returns Node instance
2080
- */
2081
- const setPositionLeft = setYogaValue('position', Edge.Left);
2082
-
2083
- /**
2084
- * Set width to node's Yoga instance
2085
- *
2086
- * @param width - Width
2087
- * @param node - Node instance
2088
- * @returns Node instance
2089
- */
2090
- const setWidth = setYogaValue('width');
2091
- /**
2092
- * Set min width to node's Yoga instance
2093
- *
2094
- * @param min - Width
2095
- * @param node - Node instance
2096
- * @returns Node instance
2097
- */
2098
- const setMinWidth = setYogaValue('minWidth');
2099
- /**
2100
- * Set max width to node's Yoga instance
2101
- *
2102
- * @param max - Width
2103
- * @param node - Node instance
2104
- * @returns Node instance
2105
- */
2106
- const setMaxWidth = setYogaValue('maxWidth');
2107
- /**
2108
- * Set height to node's Yoga instance
2109
- *
2110
- * @param height - Height
2111
- * @param node - Node instance
2112
- * @returns Node instance
2113
- */
2114
- const setHeight = setYogaValue('height');
2115
- /**
2116
- * Set min height to node's Yoga instance
2117
- *
2118
- * @param min - Height
2119
- * @param node - Node instance
2120
- * @returns Node instance
2121
- */
2122
- const setMinHeight = setYogaValue('minHeight');
2123
- /**
2124
- * Set max height to node's Yoga instance
2125
- *
2126
- * @param max - Height
2127
- * @param node - Node instance
2128
- * @returns Node instance
2129
- */
2130
- const setMaxHeight = setYogaValue('maxHeight');
2131
-
2132
- /**
2133
- * Set rowGap value to node's Yoga instance
2134
- *
2135
- * @param value - Gap value
2136
- * @returns Node instance wrapper
2137
- */
2138
- const setRowGap = setYogaValue('gap', Gutter.Row);
2139
- /**
2140
- * Set columnGap value to node's Yoga instance
2141
- *
2142
- * @param value - Gap value
2143
- * @returns Node instance wrapper
2144
- */
2145
- const setColumnGap = setYogaValue('gap', Gutter.Column);
2146
-
2147
- const getAspectRatio = (viewbox) => {
2148
- if (!viewbox)
2149
- return null;
2150
- if (typeof viewbox === 'string')
2151
- return null;
2152
- return (viewbox.maxX - viewbox.minX) / (viewbox.maxY - viewbox.minY);
2153
- };
2154
- /**
2155
- * Yoga svg measure function
2156
- *
2157
- * @param page
2158
- * @param node
2159
- * @returns Measure svg
2160
- */
2161
- const measureCanvas$1 = (page, node) => (width, widthMode, height, heightMode) => {
2162
- const aspectRatio = getAspectRatio(node.props.viewBox) || 1;
2163
- if (widthMode === MeasureMode.Exactly ||
2164
- widthMode === MeasureMode.AtMost) {
2165
- return { width, height: width / aspectRatio };
2166
- }
2167
- if (heightMode === MeasureMode.Exactly) {
2168
- return { width: height * aspectRatio };
2169
- }
2170
- return {};
2171
- };
2172
-
2173
- /**
2174
- * Get lines width (if any)
2175
- *
2176
- * @param node
2177
- * @returns Lines width
2178
- */
2179
- const linesWidth = (node) => {
2180
- if (!node.lines)
2181
- return 0;
2182
- return Math.max(0, ...node.lines.map((line) => line.xAdvance));
2183
- };
2184
-
2185
- /**
2186
- * Get lines height (if any)
2187
- *
2188
- * @param node
2189
- * @returns Lines height
2190
- */
2191
- const linesHeight = (node) => {
2192
- if (!node.lines)
2193
- return -1;
2194
- return node.lines.reduce((acc, line) => acc + line.box.height, 0);
2195
- };
2196
-
2197
- const ALIGNMENT_FACTORS = { center: 0.5, right: 1 };
2198
- /**
2199
- * Yoga text measure function
2200
- *
2201
- * @param page
2202
- * @param node
2203
- * @param fontStore
2204
- * @returns {MeasureText} measure text function
2205
- */
2206
- const measureText = (page, node, fontStore) => (width, widthMode, height) => {
2207
- if (widthMode === MeasureMode.Exactly) {
2208
- if (!node.lines)
2209
- node.lines = layoutText(node, width, height, fontStore);
2210
- return { height: linesHeight(node) };
2211
- }
2212
- if (widthMode === MeasureMode.AtMost) {
2213
- const alignFactor = ALIGNMENT_FACTORS[node.style?.textAlign] || 0;
2214
- if (!node.lines) {
2215
- node.lines = layoutText(node, width, height, fontStore);
2216
- node.alignOffset = (width - linesWidth(node)) * alignFactor; // Compensate align in variable width containers
2217
- }
2218
- return {
2219
- height: linesHeight(node),
2220
- width: Math.min(width, linesWidth(node)),
2221
- };
2222
- }
2223
- return {};
2224
- };
2225
-
2226
- /**
2227
- * Get image ratio
2228
- *
2229
- * @param node - Image node
2230
- * @returns Image ratio
2231
- */
2232
- const getRatio = (node) => {
2233
- return node.image?.data ? node.image.width / node.image.height : 1;
2234
- };
2235
-
2236
- /**
2237
- * Checks if page has auto height
2238
- *
2239
- * @param page
2240
- * @returns Is page height auto
2241
- */
2242
- const isHeightAuto = (page) => isNil(page.box?.height);
2243
-
2244
- const SAFETY_HEIGHT$1 = 10;
2245
- /**
2246
- * Yoga image measure function
2247
- *
2248
- * @param page - Page
2249
- * @param node - Node
2250
- * @returns Measure image
2251
- */
2252
- const measureImage = (page, node) => (width, widthMode, height, heightMode) => {
2253
- const imageRatio = getRatio(node);
2254
- const imageMargin = getMargin(node);
2255
- const pagePadding = getPadding(page);
2256
- // TODO: Check image percentage margins
2257
- const pageArea = isHeightAuto(page)
2258
- ? Infinity
2259
- : (page.box?.height || 0) -
2260
- pagePadding.paddingTop -
2261
- pagePadding.paddingBottom -
2262
- imageMargin.marginTop -
2263
- imageMargin.marginBottom -
2264
- SAFETY_HEIGHT$1;
2265
- // Skip measure if image data not present yet
2266
- if (!node.image)
2267
- return { width: 0, height: 0 };
2268
- if (widthMode === MeasureMode.Exactly &&
2269
- heightMode === MeasureMode.Undefined) {
2270
- const scaledHeight = width / imageRatio;
2271
- return { height: Math.min(pageArea, scaledHeight) };
2272
- }
2273
- if (heightMode === MeasureMode.Exactly &&
2274
- (widthMode === MeasureMode.AtMost ||
2275
- widthMode === MeasureMode.Undefined)) {
2276
- return { width: Math.min(height * imageRatio, width) };
2277
- }
2278
- if (widthMode === MeasureMode.Exactly &&
2279
- heightMode === MeasureMode.AtMost) {
2280
- const scaledHeight = width / imageRatio;
2281
- return { height: Math.min(height, pageArea, scaledHeight) };
2282
- }
2283
- if (widthMode === MeasureMode.AtMost &&
2284
- heightMode === MeasureMode.AtMost) {
2285
- if (imageRatio > 1) {
2286
- return {
2287
- width,
2288
- height: Math.min(width / imageRatio, height),
2289
- };
2290
- }
2291
- return {
2292
- height,
2293
- width: Math.min(height * imageRatio, width),
2294
- };
2295
- }
2296
- return { height, width };
2297
- };
2298
-
2299
- const SAFETY_HEIGHT = 10;
2300
- const getMax = (values) => Math.max(-Infinity, ...values);
2301
- /**
2302
- * Helper object to predict canvas size
2303
- * TODO: Implement remaining functions (as close as possible);
2304
- */
2305
- const measureCtx = () => {
2306
- const ctx = {};
2307
- const points = [];
2308
- const nil = () => ctx;
2309
- const addPoint = (x, y) => points.push([x, y]);
2310
- const moveTo = (x, y) => {
2311
- addPoint(x, y);
2312
- return ctx;
2313
- };
2314
- const rect = (x, y, w, h) => {
2315
- addPoint(x, y);
2316
- addPoint(x + w, y);
2317
- addPoint(x, y + h);
2318
- addPoint(x + w, y + h);
2319
- return ctx;
2320
- };
2321
- const ellipse = (x, y, rx, ry) => {
2322
- ry = ry || rx;
2323
- addPoint(x - rx, y - ry);
2324
- addPoint(x + rx, y - ry);
2325
- addPoint(x + rx, y + ry);
2326
- addPoint(x - rx, y + ry);
2327
- return ctx;
2328
- };
2329
- const polygon = (...pts) => {
2330
- points.push(...pts);
2331
- return ctx;
2332
- };
2333
- // Change dimensions
2334
- ctx.rect = rect;
2335
- ctx.moveTo = moveTo;
2336
- ctx.lineTo = moveTo;
2337
- ctx.circle = ellipse;
2338
- ctx.polygon = polygon;
2339
- ctx.ellipse = ellipse;
2340
- ctx.roundedRect = rect;
2341
- // To be implemented
2342
- ctx.text = nil;
2343
- ctx.path = nil;
2344
- ctx.lineWidth = nil;
2345
- ctx.bezierCurveTo = nil;
2346
- ctx.quadraticCurveTo = nil;
2347
- ctx.scale = nil;
2348
- ctx.rotate = nil;
2349
- ctx.translate = nil;
2350
- // These don't change dimensions
2351
- ctx.dash = nil;
2352
- ctx.clip = nil;
2353
- ctx.save = nil;
2354
- ctx.fill = nil;
2355
- ctx.font = nil;
2356
- ctx.stroke = nil;
2357
- ctx.lineCap = nil;
2358
- ctx.opacity = nil;
2359
- ctx.restore = nil;
2360
- ctx.lineJoin = nil;
2361
- ctx.fontSize = nil;
2362
- ctx.fillColor = nil;
2363
- ctx.miterLimit = nil;
2364
- ctx.strokeColor = nil;
2365
- ctx.fillOpacity = nil;
2366
- ctx.strokeOpacity = nil;
2367
- ctx.linearGradient = nil;
2368
- ctx.radialGradient = nil;
2369
- ctx.getWidth = () => getMax(points.map((p) => p[0]));
2370
- ctx.getHeight = () => getMax(points.map((p) => p[1]));
2371
- return ctx;
2372
- };
2373
- /**
2374
- * @typedef {Function} MeasureCanvas
2375
- * @returns {{ width: number, height: number }} canvas width and height
2376
- */
2377
- /**
2378
- * Yoga canvas measure function
2379
- *
2380
- * @param {Object} page
2381
- * @param {Object} node
2382
- * @returns {MeasureCanvas} measure canvas
2383
- */
2384
- const measureCanvas = (page, node) => () => {
2385
- const imageMargin = getMargin(node);
2386
- const pagePadding = getPadding(page);
2387
- // TODO: Check image percentage margins
2388
- const pageArea = isHeightAuto(page)
2389
- ? Infinity
2390
- : (page.box?.height || 0) -
2391
- pagePadding.paddingTop -
2392
- pagePadding.paddingBottom -
2393
- imageMargin.marginTop -
2394
- imageMargin.marginBottom -
2395
- SAFETY_HEIGHT;
2396
- const ctx = measureCtx();
2397
- node.props.paint(ctx);
2398
- const width = ctx.getWidth();
2399
- const height = Math.min(pageArea, ctx.getHeight());
2400
- return { width, height };
2401
- };
2402
-
2403
- const isType$1 = (type) => (node) => node.type === type;
2404
- const isSvg = isType$1(Svg);
2405
- const isText$2 = isType$1(Text);
2406
- const isNote = isType$1(Note);
2407
- const isPage = isType$1(Page);
2408
- const isImage = isType$1(Image);
2409
- const isCanvas = isType$1(Canvas);
2410
- const isTextInstance$1 = isType$1(TextInstance);
2411
- const setNodeHeight = (node) => {
2412
- const value = isPage(node) ? node.box?.height : node.style?.height;
2413
- return setHeight(value);
2414
- };
2415
- /**
2416
- * Set styles valeus into yoga node before layout calculation
2417
- *
2418
- * @param node
2419
- */
2420
- const setYogaValues = (node) => {
2421
- compose(setNodeHeight(node), setWidth(node.style.width), setMinWidth(node.style.minWidth), setMaxWidth(node.style.maxWidth), setMinHeight(node.style.minHeight), setMaxHeight(node.style.maxHeight), setMarginTop(node.style.marginTop), setMarginRight(node.style.marginRight), setMarginBottom(node.style.marginBottom), setMarginLeft(node.style.marginLeft), setPaddingTop(node.style.paddingTop), setPaddingRight(node.style.paddingRight), setPaddingBottom(node.style.paddingBottom), setPaddingLeft(node.style.paddingLeft), setPositionType(node.style.position), setPositionTop(node.style.top), setPositionRight(node.style.right), setPositionBottom(node.style.bottom), setPositionLeft(node.style.left), setBorderTop(node.style.borderTopWidth), setBorderRight(node.style.borderRightWidth), setBorderBottom(node.style.borderBottomWidth), setBorderLeft(node.style.borderLeftWidth), setDisplay(node.style.display), setFlexDirection(node.style.flexDirection), setAlignSelf(node.style.alignSelf), setAlignContent(node.style.alignContent), setAlignItems(node.style.alignItems), setJustifyContent(node.style.justifyContent), setFlexWrap(node.style.flexWrap), setOverflow(node.style.overflow), setAspectRatio(node.style.aspectRatio), setFlexBasis(node.style.flexBasis), setFlexGrow(node.style.flexGrow), setFlexShrink(node.style.flexShrink), setRowGap(node.style.rowGap), setColumnGap(node.style.columnGap))(node);
2422
- };
2423
- /**
2424
- * Inserts child into parent' yoga node
2425
- *
2426
- * @param parent parent
2427
- * @returns Insert yoga nodes
2428
- */
2429
- const insertYogaNodes = (parent) => (child) => {
2430
- parent.insertChild(child.yogaNode, parent.getChildCount());
2431
- return child;
2432
- };
2433
- const setMeasureFunc = (node, page, fontStore) => {
2434
- const { yogaNode } = node;
2435
- if (isText$2(node)) {
2436
- yogaNode.setMeasureFunc(measureText(page, node, fontStore));
2437
- }
2438
- if (isImage(node)) {
2439
- yogaNode.setMeasureFunc(measureImage(page, node));
2440
- }
2441
- if (isCanvas(node)) {
2442
- yogaNode.setMeasureFunc(measureCanvas(page, node));
2443
- }
2444
- if (isSvg(node)) {
2445
- yogaNode.setMeasureFunc(measureCanvas$1(page, node));
2446
- }
2447
- return node;
2448
- };
2449
- const isLayoutElement = (node) => !isText$2(node) && !isNote(node) && !isSvg(node);
2450
- /**
2451
- * @typedef {Function} CreateYogaNodes
2452
- * @param {Object} node
2453
- * @returns {Object} node with appended yoga node
2454
- */
2455
- /**
2456
- * Creates and add yoga node to document tree
2457
- * Handles measure function for text and image nodes
2458
- *
2459
- * @returns Create yoga nodes
2460
- */
2461
- const createYogaNodes = (page, fontStore, yoga) => (node) => {
2462
- const yogaNode = yoga.node.create();
2463
- const result = Object.assign({}, node, { yogaNode });
2464
- setYogaValues(result);
2465
- if (isLayoutElement(node) && node.children) {
2466
- const resolveChild = compose(insertYogaNodes(yogaNode), createYogaNodes(page, fontStore, yoga));
2467
- result.children = node.children.map(resolveChild);
2468
- }
2469
- setMeasureFunc(result, page, fontStore);
2470
- return result;
2471
- };
2472
- /**
2473
- * Performs yoga calculation
2474
- *
2475
- * @param page - Page node
2476
- * @returns Page node
2477
- */
2478
- const calculateLayout = (page) => {
2479
- page.yogaNode.calculateLayout();
2480
- return page;
2481
- };
2482
- /**
2483
- * Saves Yoga layout result into 'box' attribute of node
2484
- *
2485
- * @param node
2486
- * @returns Node with box data
2487
- */
2488
- const persistDimensions = (node) => {
2489
- if (isTextInstance$1(node))
2490
- return node;
2491
- const box = Object.assign(getPadding(node), getMargin(node), getBorderWidth(node), getPosition(node), getDimension(node));
2492
- const newNode = Object.assign({}, node, { box });
2493
- if (!node.children)
2494
- return newNode;
2495
- const children = node.children.map(persistDimensions);
2496
- return Object.assign({}, newNode, { children });
2497
- };
2498
- /**
2499
- * Removes yoga node from document tree
2500
- *
2501
- * @param node
2502
- * @returns Node without yoga node
2503
- */
2504
- const destroyYogaNodes = (node) => {
2505
- const newNode = Object.assign({}, node);
2506
- delete newNode.yogaNode;
2507
- if (!node.children)
2508
- return newNode;
2509
- const children = node.children.map(destroyYogaNodes);
2510
- return Object.assign({}, newNode, { children });
2511
- };
2512
- /**
2513
- * Free yoga node from document tree
2514
- *
2515
- * @param node
2516
- * @returns Node without yoga node
2517
- */
2518
- const freeYogaNodes = (node) => {
2519
- if (node.yogaNode)
2520
- node.yogaNode.freeRecursive();
2521
- return node;
2522
- };
2523
- /**
2524
- * Calculates page object layout using Yoga.
2525
- * Takes node values from 'box' and 'style' attributes, and persist them back into 'box'
2526
- * Destroy yoga values at the end.
2527
- *
2528
- * @param page - Object
2529
- * @returns Page object with correct 'box' layout attributes
2530
- */
2531
- const resolvePageDimensions = (page, fontStore, yoga) => {
2532
- if (isNil(page))
2533
- return null;
2534
- return compose(destroyYogaNodes, freeYogaNodes, persistDimensions, calculateLayout, createYogaNodes(page, fontStore, yoga))(page);
2535
- };
2536
- /**
2537
- * Calculates root object layout using Yoga.
2538
- *
2539
- * @param node - Root object
2540
- * @param fontStore - Font store
2541
- * @returns Root object with correct 'box' layout attributes
2542
- */
2543
- const resolveDimensions = (node, fontStore) => {
2544
- if (!node.children)
2545
- return node;
2546
- const resolveChild = (child) => resolvePageDimensions(child, fontStore, node.yoga);
2547
- const children = node.children.map(resolveChild);
2548
- return Object.assign({}, node, { children });
2549
- };
2550
-
2551
- const isText$1 = (node) => node.type === Text;
2552
- // Prevent splitting elements by low decimal numbers
2553
- const SAFETY_THRESHOLD = 0.001;
2554
- const assingChildren = (children, node) => Object.assign({}, node, { children });
2555
- const getTop = (node) => node.box?.top || 0;
2556
- const allFixed = (nodes) => nodes.every(isFixed);
2557
- const isDynamic = (node) => node.props && 'render' in node.props;
2558
- const relayoutPage = compose(resolveTextLayout, resolvePageDimensions, resolveInheritance, resolvePageStyles);
2559
- const warnUnavailableSpace = (node) => {
2560
- console.warn(`Node of type ${node.type} can't wrap between pages and it's bigger than available page height`);
2561
- };
2562
- const splitNodes = (height, contentArea, nodes) => {
2563
- const currentChildren = [];
2564
- const nextChildren = [];
2565
- for (let i = 0; i < nodes.length; i += 1) {
2566
- const child = nodes[i];
2567
- const futureNodes = nodes.slice(i + 1);
2568
- const futureFixedNodes = futureNodes.filter(isFixed);
2569
- const nodeTop = getTop(child);
2570
- const nodeHeight = child.box.height;
2571
- const isOutside = height <= nodeTop;
2572
- const shouldBreak$1 = shouldBreak(child, futureNodes, height);
2573
- const shouldSplit = height + SAFETY_THRESHOLD < nodeTop + nodeHeight;
2574
- const canWrap = getWrap(child);
2575
- const fitsInsidePage = nodeHeight <= contentArea;
2576
- if (isFixed(child)) {
2577
- nextChildren.push(child);
2578
- currentChildren.push(child);
2579
- continue;
2580
- }
2581
- if (isOutside) {
2582
- const box = Object.assign({}, child.box, { top: child.box.top - height });
2583
- const next = Object.assign({}, child, { box });
2584
- nextChildren.push(next);
2585
- continue;
2586
- }
2587
- if (!fitsInsidePage && !canWrap) {
2588
- currentChildren.push(child);
2589
- nextChildren.push(...futureNodes);
2590
- warnUnavailableSpace(child);
2591
- break;
2592
- }
2593
- if (shouldBreak$1) {
2594
- const box = Object.assign({}, child.box, { top: child.box.top - height });
2595
- const props = Object.assign({}, child.props, {
2596
- wrap: true,
2597
- break: false,
2598
- });
2599
- const next = Object.assign({}, child, { box, props });
2600
- currentChildren.push(...futureFixedNodes);
2601
- nextChildren.push(next, ...futureNodes);
2602
- break;
2603
- }
2604
- if (shouldSplit) {
2605
- const [currentChild, nextChild] = split(child, height, contentArea);
2606
- // All children are moved to the next page, it doesn't make sense to show the parent on the current page
2607
- if (child.children.length > 0 && currentChild.children.length === 0) {
2608
- // But if the current page is empty then we can just include the parent on the current page
2609
- if (currentChildren.length === 0) {
2610
- currentChildren.push(child, ...futureFixedNodes);
2611
- nextChildren.push(...futureNodes);
2612
- }
2613
- else {
2614
- const box = Object.assign({}, child.box, {
2615
- top: child.box.top - height,
2616
- });
2617
- const next = Object.assign({}, child, { box });
2618
- currentChildren.push(...futureFixedNodes);
2619
- nextChildren.push(next, ...futureNodes);
2620
- }
2621
- break;
2622
- }
2623
- if (currentChild)
2624
- currentChildren.push(currentChild);
2625
- if (nextChild)
2626
- nextChildren.push(nextChild);
2627
- continue;
2628
- }
2629
- currentChildren.push(child);
2630
- }
2631
- return [currentChildren, nextChildren];
2632
- };
2633
- const splitChildren = (height, contentArea, node) => {
2634
- const children = node.children || [];
2635
- const availableHeight = height - getTop(node);
2636
- return splitNodes(availableHeight, contentArea, children);
2637
- };
2638
- const splitView = (node, height, contentArea) => {
2639
- const [currentNode, nextNode] = splitNode(node, height);
2640
- const [currentChilds, nextChildren] = splitChildren(height, contentArea, node);
2641
- return [
2642
- assingChildren(currentChilds, currentNode),
2643
- assingChildren(nextChildren, nextNode),
2644
- ];
2645
- };
2646
- const split = (node, height, contentArea) => isText$1(node) ? splitText(node, height) : splitView(node, height, contentArea);
2647
- const shouldResolveDynamicNodes = (node) => {
2648
- const children = node.children || [];
2649
- return isDynamic(node) || children.some(shouldResolveDynamicNodes);
2650
- };
2651
- const resolveDynamicNodes = (props, node) => {
2652
- const isNodeDynamic = isDynamic(node);
2653
- // Call render prop on dynamic nodes and append result to children
2654
- const resolveChildren = (children = []) => {
2655
- if (isNodeDynamic) {
2656
- const res = node.props.render(props);
2657
- return (createInstances(res)
2658
- .filter(Boolean)
2659
- // @ts-expect-error rework dynamic nodes. conflicting types
2660
- .map((n) => resolveDynamicNodes(props, n)));
2661
- }
2662
- return children.map((c) => resolveDynamicNodes(props, c));
2663
- };
2664
- // We reset dynamic text box so it can be computed again later on
2665
- const resetHeight = isNodeDynamic && isText$1(node);
2666
- const box = resetHeight ? { ...node.box, height: 0 } : node.box;
2667
- const children = resolveChildren(node.children);
2668
- // @ts-expect-error handle text here specifically
2669
- const lines = isNodeDynamic ? null : node.lines;
2670
- return Object.assign({}, node, { box, lines, children });
2671
- };
2672
- const resolveDynamicPage = (props, page, fontStore, yoga) => {
2673
- if (shouldResolveDynamicNodes(page)) {
2674
- const resolvedPage = resolveDynamicNodes(props, page);
2675
- return relayoutPage(resolvedPage, fontStore, yoga);
2676
- }
2677
- return page;
2678
- };
2679
- const splitPage = (page, pageNumber, fontStore, yoga) => {
2680
- const wrapArea = getWrapArea(page);
2681
- const contentArea = getContentArea(page);
2682
- const dynamicPage = resolveDynamicPage({ pageNumber }, page, fontStore, yoga);
2683
- const height = page.style.height;
2684
- const [currentChilds, nextChilds] = splitNodes(wrapArea, contentArea, dynamicPage.children);
2685
- const relayout = (node) =>
2686
- // @ts-expect-error rework pagination
2687
- relayoutPage(node, fontStore, yoga);
2688
- const currentBox = { ...page.box, height };
2689
- const currentPage = relayout(Object.assign({}, page, { box: currentBox, children: currentChilds }));
2690
- if (nextChilds.length === 0 || allFixed(nextChilds))
2691
- return [currentPage, null];
2692
- const nextBox = omit('height', page.box);
2693
- const nextProps = omit('bookmark', page.props);
2694
- const nextPage = relayout(Object.assign({}, page, {
2695
- props: nextProps,
2696
- box: nextBox,
2697
- children: nextChilds,
2698
- }));
2699
- return [currentPage, nextPage];
2700
- };
2701
- const resolvePageIndices = (fontStore, yoga, page, pageNumber, pages) => {
2702
- const totalPages = pages.length;
2703
- const props = {
2704
- totalPages,
2705
- pageNumber: pageNumber + 1,
2706
- subPageNumber: page.subPageNumber + 1,
2707
- subPageTotalPages: page.subPageTotalPages,
2708
- };
2709
- return resolveDynamicPage(props, page, fontStore, yoga);
2710
- };
2711
- const assocSubPageData = (subpages) => {
2712
- return subpages.map((page, i) => ({
2713
- ...page,
2714
- subPageNumber: i,
2715
- subPageTotalPages: subpages.length,
2716
- }));
2717
- };
2718
- const dissocSubPageData = (page) => {
2719
- return omit(['subPageNumber', 'subPageTotalPages'], page);
2720
- };
2721
- const paginate = (page, pageNumber, fontStore, yoga) => {
2722
- if (!page)
2723
- return [];
2724
- if (page.props?.wrap === false)
2725
- return [page];
2726
- let splittedPage = splitPage(page, pageNumber, fontStore, yoga);
2727
- const pages = [splittedPage[0]];
2728
- let nextPage = splittedPage[1];
2729
- while (nextPage !== null) {
2730
- splittedPage = splitPage(nextPage, pageNumber + pages.length, fontStore, yoga);
2731
- pages.push(splittedPage[0]);
2732
- nextPage = splittedPage[1];
2733
- }
2734
- return pages;
2735
- };
2736
- /**
2737
- * Performs pagination. This is the step responsible of breaking the whole document
2738
- * into pages following pagiation rules, such as `fixed`, `break` and dynamic nodes.
2739
- *
2740
- * @param root - Document node
2741
- * @param fontStore - Font store
2742
- * @returns Layout node
2743
- */
2744
- const resolvePagination = (root, fontStore) => {
2745
- let pages = [];
2746
- let pageNumber = 1;
2747
- for (let i = 0; i < root.children.length; i += 1) {
2748
- const page = root.children[i];
2749
- let subpages = paginate(page, pageNumber, fontStore, root.yoga);
2750
- subpages = assocSubPageData(subpages);
2751
- pageNumber += subpages.length;
2752
- pages = pages.concat(subpages);
2753
- }
2754
- pages = pages.map((...args) => dissocSubPageData(resolvePageIndices(fontStore, root.yoga, ...args)));
2755
- return assingChildren(pages, root);
2756
- };
2757
-
2758
- /**
2759
- * Translates page percentage horizontal paddings in fixed ones
2760
- *
2761
- * @param container - Page container
2762
- * @returns Resolve page horizontal padding
2763
- */
2764
- const resolvePageHorizontalPadding = (container) => (value) => {
2765
- const match = matchPercent(value);
2766
- const width = container.width;
2767
- return match ? match.percent * width : value;
2768
- };
2769
- /**
2770
- * Translates page percentage vertical paddings in fixed ones
2771
- *
2772
- * @param container - Page container
2773
- * @returns Resolve page vertical padding
2774
- */
2775
- const resolvePageVerticalPadding = (container) => (value) => {
2776
- const match = matchPercent(value);
2777
- const height = container.height;
2778
- return match ? match.percent * height : value;
2779
- };
2780
- /**
2781
- * Translates page percentage paddings in fixed ones
2782
- *
2783
- * @param page
2784
- * @returns Page with fixed paddings
2785
- */
2786
- const resolvePagePaddings = (page) => {
2787
- const container = page.style;
2788
- const style = evolve({
2789
- paddingTop: resolvePageVerticalPadding(container),
2790
- paddingLeft: resolvePageHorizontalPadding(container),
2791
- paddingRight: resolvePageHorizontalPadding(container),
2792
- paddingBottom: resolvePageVerticalPadding(container),
2793
- }, page.style);
2794
- return Object.assign({}, page, { style });
2795
- };
2796
- /**
2797
- * Translates all pages percentage paddings in fixed ones
2798
- * This has to be computed from pages calculated size and not by Yoga
2799
- * because at this point we didn't performed pagination yet.
2800
- *
2801
- * @param root - Document root
2802
- * @returns Document root with translated page paddings
2803
- */
2804
- const resolvePagesPaddings = (root) => {
2805
- if (!root.children)
2806
- return root;
2807
- const children = root.children.map(resolvePagePaddings);
2808
- return Object.assign({}, root, { children });
2809
- };
2810
-
2811
- const resolveRadius = (box) => (value) => {
2812
- if (!value)
2813
- return undefined;
2814
- const match = matchPercent(value);
2815
- return match ? match.percent * Math.min(box.width, box.height) : value;
2816
- };
2817
- /**
2818
- * Transforms percent border radius into fixed values
2819
- *
2820
- * @param node
2821
- * @returns Node
2822
- */
2823
- const resolvePercentRadius = (node) => {
2824
- const style = evolve({
2825
- borderTopLeftRadius: resolveRadius(node.box),
2826
- borderTopRightRadius: resolveRadius(node.box),
2827
- borderBottomRightRadius: resolveRadius(node.box),
2828
- borderBottomLeftRadius: resolveRadius(node.box),
2829
- }, node.style || {});
2830
- const newNode = Object.assign({}, node, { style });
2831
- if (!node.children)
2832
- return newNode;
2833
- const children = node.children.map(resolvePercentRadius);
2834
- return Object.assign({}, newNode, { children });
2835
- };
2836
-
2837
- /**
2838
- * Transform percent height into fixed
2839
- *
2840
- * @param height
2841
- * @returns Height
2842
- */
2843
- const transformHeight = (pageArea, height) => {
2844
- const match = matchPercent(height);
2845
- return match ? match.percent * pageArea : height;
2846
- };
2847
- /**
2848
- * Get page area (height minus paddings)
2849
- *
2850
- * @param page
2851
- * @returns Page area
2852
- */
2853
- const getPageArea = (page) => {
2854
- const pageHeight = page.style.height;
2855
- const pagePaddingTop = (page.style?.paddingTop || 0);
2856
- const pagePaddingBottom = (page.style?.paddingBottom || 0);
2857
- return pageHeight - pagePaddingTop - pagePaddingBottom;
2858
- };
2859
- /**
2860
- * Transform node percent height to fixed
2861
- *
2862
- * @param page
2863
- * @param node
2864
- * @returns Transformed node
2865
- */
2866
- const resolveNodePercentHeight = (page, node) => {
2867
- if (isNil(page.style?.height))
2868
- return node;
2869
- if (isNil(node.style?.height))
2870
- return node;
2871
- const pageArea = getPageArea(page);
2872
- const height = transformHeight(pageArea, node.style.height);
2873
- const style = Object.assign({}, node.style, { height });
2874
- return Object.assign({}, node, { style });
2875
- };
2876
- /**
2877
- * Transform page immediate children with percent height to fixed
2878
- *
2879
- * @param page
2880
- * @returns Transformed page
2881
- */
2882
- const resolvePagePercentHeight = (page) => {
2883
- if (!page.children)
2884
- return page;
2885
- const resolveChild = (child) => resolveNodePercentHeight(page, child);
2886
- const children = page.children.map(resolveChild);
2887
- return Object.assign({}, page, { children });
2888
- };
2889
- /**
2890
- * Transform all page immediate children with percent height to fixed.
2891
- * This is needed for computing correct dimensions on pre-pagination layout.
2892
- *
2893
- * @param root - Document root
2894
- * @returns Transformed document root
2895
- */
2896
- const resolvePercentHeight = (root) => {
2897
- if (!root.children)
2898
- return root;
2899
- const children = root.children.map(resolvePagePercentHeight);
2900
- return Object.assign({}, root, { children });
2901
- };
2902
-
2903
- const isType = (type) => (node) => node.type === type;
2904
- const isLink = isType(Link);
2905
- const isText = isType(Text);
2906
- const isTextInstance = isType(TextInstance);
2907
- /**
2908
- * Checks if node has render prop
2909
- *
2910
- * @param node
2911
- * @returns Has render prop?
2912
- */
2913
- const hasRenderProp = (node) => 'render' in node.props;
2914
- /**
2915
- * Checks if node is text type (Text or TextInstance)
2916
- *
2917
- * @param node
2918
- * @returns Are all children text instances?
2919
- */
2920
- const isTextType = (node) => isText(node) || isTextInstance(node);
2921
- /**
2922
- * Checks if is tet link that needs to be wrapped in Text
2923
- *
2924
- * @param node
2925
- * @returns Are all children text instances?
2926
- */
2927
- const isTextLink = (node) => {
2928
- const children = node.children || [];
2929
- // Text string inside a Link
2930
- if (children.every(isTextInstance))
2931
- return true;
2932
- // Text node inside a Link
2933
- if (children.every(isText))
2934
- return false;
2935
- return children.every(isTextType);
2936
- };
2937
- /**
2938
- * Wraps node children inside Text node
2939
- *
2940
- * @param node
2941
- * @returns Node with intermediate Text child
2942
- */
2943
- const wrapText = (node) => {
2944
- const textElement = {
2945
- type: Text,
2946
- props: {},
2947
- style: {},
2948
- box: {},
2949
- children: node.children,
2950
- };
2951
- return Object.assign({}, node, { children: [textElement] });
2952
- };
2953
- const transformLink = (node) => {
2954
- if (!isLink(node))
2955
- return node;
2956
- // If has render prop substitute the instance by a Text, that will
2957
- // ultimately render the inline Link via the textkit PDF renderer.
2958
- if (hasRenderProp(node))
2959
- return Object.assign({}, node, { type: Text });
2960
- // If is a text link (either contains Text or TextInstance), wrap it
2961
- // inside a Text element so styles are applied correctly
2962
- if (isTextLink(node))
2963
- return wrapText(node);
2964
- return node;
2965
- };
2966
- /**
2967
- * Transforms Link layout to correctly render text and dynamic rendered links
2968
- *
2969
- * @param node
2970
- * @returns Node with link substitution
2971
- */
2972
- const resolveLinkSubstitution = (node) => {
2973
- if (!node.children)
2974
- return node;
2975
- const resolveChild = compose(transformLink, resolveLinkSubstitution);
2976
- const children = node.children.map(resolveChild);
2977
- return Object.assign({}, node, { children });
2978
- };
2979
-
2980
- const layout = asyncCompose(resolveZIndex, resolveOrigin, resolveAssets, resolvePagination, resolveTextLayout, resolvePercentRadius, resolveDimensions, resolveSvg, resolveAssets, resolveInheritance, resolvePercentHeight, resolvePagesPaddings, resolveStyles, resolveLinkSubstitution, resolveBookmarks, resolvePageSizes, resolveYoga);
2981
-
2982
- export { layout as default };