@mantra-ai/core 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (385) hide show
  1. package/dist/ai/google/client.d.ts +67 -0
  2. package/dist/ai/google/client.d.ts.map +1 -0
  3. package/dist/ai/google/client.js +169 -0
  4. package/dist/ai/google/client.js.map +1 -0
  5. package/dist/ai/google/generate.d.ts +10 -0
  6. package/dist/ai/google/generate.d.ts.map +1 -0
  7. package/dist/ai/google/generate.js +137 -0
  8. package/dist/ai/google/generate.js.map +1 -0
  9. package/dist/ai/google/index.d.ts +4 -0
  10. package/dist/ai/google/index.d.ts.map +1 -0
  11. package/dist/ai/google/index.js +4 -0
  12. package/dist/ai/google/index.js.map +1 -0
  13. package/dist/ai/google/types.d.ts +88 -0
  14. package/dist/ai/google/types.d.ts.map +1 -0
  15. package/dist/ai/google/types.js +55 -0
  16. package/dist/ai/google/types.js.map +1 -0
  17. package/dist/ai/index.d.ts +3 -0
  18. package/dist/ai/index.d.ts.map +1 -0
  19. package/dist/ai/index.js +3 -0
  20. package/dist/ai/index.js.map +1 -0
  21. package/dist/ai/openai/client.d.ts +22 -0
  22. package/dist/ai/openai/client.d.ts.map +1 -0
  23. package/dist/ai/openai/client.js +49 -0
  24. package/dist/ai/openai/client.js.map +1 -0
  25. package/dist/ai/openai/generate.d.ts +14 -0
  26. package/dist/ai/openai/generate.d.ts.map +1 -0
  27. package/dist/ai/openai/generate.js +178 -0
  28. package/dist/ai/openai/generate.js.map +1 -0
  29. package/dist/ai/openai/index.d.ts +4 -0
  30. package/dist/ai/openai/index.d.ts.map +1 -0
  31. package/dist/ai/openai/index.js +4 -0
  32. package/dist/ai/openai/index.js.map +1 -0
  33. package/dist/ai/openai/types.d.ts +86 -0
  34. package/dist/ai/openai/types.d.ts.map +1 -0
  35. package/dist/ai/openai/types.js +56 -0
  36. package/dist/ai/openai/types.js.map +1 -0
  37. package/dist/ai/prompts/index.d.ts +1 -0
  38. package/dist/ai/prompts/index.d.ts.map +1 -0
  39. package/dist/ai/prompts/index.js +2 -0
  40. package/dist/ai/prompts/index.js.map +1 -0
  41. package/dist/errors/index.d.ts +3 -0
  42. package/dist/errors/index.d.ts.map +1 -0
  43. package/dist/errors/index.js +4 -0
  44. package/dist/errors/index.js.map +1 -0
  45. package/dist/errors/schemas.d.ts +304 -0
  46. package/dist/errors/schemas.d.ts.map +1 -0
  47. package/dist/errors/schemas.js +57 -0
  48. package/dist/errors/schemas.js.map +1 -0
  49. package/dist/errors/types.d.ts +30 -0
  50. package/dist/errors/types.d.ts.map +1 -0
  51. package/dist/errors/types.js +33 -0
  52. package/dist/errors/types.js.map +1 -0
  53. package/dist/index.d.ts +21 -0
  54. package/dist/index.d.ts.map +1 -0
  55. package/dist/index.js +21 -0
  56. package/dist/index.js.map +1 -0
  57. package/dist/normalization/jats/index.d.ts +4 -0
  58. package/dist/normalization/jats/index.d.ts.map +1 -0
  59. package/dist/normalization/jats/index.js +3 -0
  60. package/dist/normalization/jats/index.js.map +1 -0
  61. package/dist/normalization/jats/normalize.d.ts +7 -0
  62. package/dist/normalization/jats/normalize.d.ts.map +1 -0
  63. package/dist/normalization/jats/normalize.js +213 -0
  64. package/dist/normalization/jats/normalize.js.map +1 -0
  65. package/dist/normalization/jats/utils/build/finalize.d.ts +3 -0
  66. package/dist/normalization/jats/utils/build/finalize.d.ts.map +1 -0
  67. package/dist/normalization/jats/utils/build/finalize.js +462 -0
  68. package/dist/normalization/jats/utils/build/finalize.js.map +1 -0
  69. package/dist/normalization/jats/utils/build/flatten.d.ts +20 -0
  70. package/dist/normalization/jats/utils/build/flatten.d.ts.map +1 -0
  71. package/dist/normalization/jats/utils/build/flatten.js +502 -0
  72. package/dist/normalization/jats/utils/build/flatten.js.map +1 -0
  73. package/dist/normalization/jats/utils/build/meta.d.ts +10 -0
  74. package/dist/normalization/jats/utils/build/meta.d.ts.map +1 -0
  75. package/dist/normalization/jats/utils/build/meta.js +32 -0
  76. package/dist/normalization/jats/utils/build/meta.js.map +1 -0
  77. package/dist/normalization/jats/utils/build/version.d.ts +3 -0
  78. package/dist/normalization/jats/utils/build/version.d.ts.map +1 -0
  79. package/dist/normalization/jats/utils/build/version.js +11 -0
  80. package/dist/normalization/jats/utils/build/version.js.map +1 -0
  81. package/dist/normalization/jats/utils/category.d.ts +11 -0
  82. package/dist/normalization/jats/utils/category.d.ts.map +1 -0
  83. package/dist/normalization/jats/utils/category.js +431 -0
  84. package/dist/normalization/jats/utils/category.js.map +1 -0
  85. package/dist/normalization/jats/utils/collectors/abstracts.d.ts +3 -0
  86. package/dist/normalization/jats/utils/collectors/abstracts.d.ts.map +1 -0
  87. package/dist/normalization/jats/utils/collectors/abstracts.js +168 -0
  88. package/dist/normalization/jats/utils/collectors/abstracts.js.map +1 -0
  89. package/dist/normalization/jats/utils/collectors/back.d.ts +35 -0
  90. package/dist/normalization/jats/utils/collectors/back.d.ts.map +1 -0
  91. package/dist/normalization/jats/utils/collectors/back.js +801 -0
  92. package/dist/normalization/jats/utils/collectors/back.js.map +1 -0
  93. package/dist/normalization/jats/utils/collectors/contributors.d.ts +4 -0
  94. package/dist/normalization/jats/utils/collectors/contributors.d.ts.map +1 -0
  95. package/dist/normalization/jats/utils/collectors/contributors.js +77 -0
  96. package/dist/normalization/jats/utils/collectors/contributors.js.map +1 -0
  97. package/dist/normalization/jats/utils/collectors/keywords.d.ts +2 -0
  98. package/dist/normalization/jats/utils/collectors/keywords.d.ts.map +1 -0
  99. package/dist/normalization/jats/utils/collectors/keywords.js +14 -0
  100. package/dist/normalization/jats/utils/collectors/keywords.js.map +1 -0
  101. package/dist/normalization/jats/utils/collectors/meta.d.ts +6 -0
  102. package/dist/normalization/jats/utils/collectors/meta.d.ts.map +1 -0
  103. package/dist/normalization/jats/utils/collectors/meta.js +103 -0
  104. package/dist/normalization/jats/utils/collectors/meta.js.map +1 -0
  105. package/dist/normalization/jats/utils/collectors/sections.d.ts +7 -0
  106. package/dist/normalization/jats/utils/collectors/sections.d.ts.map +1 -0
  107. package/dist/normalization/jats/utils/collectors/sections.js +484 -0
  108. package/dist/normalization/jats/utils/collectors/sections.js.map +1 -0
  109. package/dist/normalization/jats/utils/licenses.d.ts +5 -0
  110. package/dist/normalization/jats/utils/licenses.d.ts.map +1 -0
  111. package/dist/normalization/jats/utils/licenses.js +64 -0
  112. package/dist/normalization/jats/utils/licenses.js.map +1 -0
  113. package/dist/normalization/jats/utils/po/nodes.d.ts +6 -0
  114. package/dist/normalization/jats/utils/po/nodes.d.ts.map +1 -0
  115. package/dist/normalization/jats/utils/po/nodes.js +60 -0
  116. package/dist/normalization/jats/utils/po/nodes.js.map +1 -0
  117. package/dist/normalization/jats/utils/po/query.d.ts +7 -0
  118. package/dist/normalization/jats/utils/po/query.d.ts.map +1 -0
  119. package/dist/normalization/jats/utils/po/query.js +67 -0
  120. package/dist/normalization/jats/utils/po/query.js.map +1 -0
  121. package/dist/normalization/jats/utils/po/serialize.d.ts +4 -0
  122. package/dist/normalization/jats/utils/po/serialize.d.ts.map +1 -0
  123. package/dist/normalization/jats/utils/po/serialize.js +329 -0
  124. package/dist/normalization/jats/utils/po/serialize.js.map +1 -0
  125. package/dist/normalization/jats/utils/po/text.d.ts +7 -0
  126. package/dist/normalization/jats/utils/po/text.d.ts.map +1 -0
  127. package/dist/normalization/jats/utils/po/text.js +114 -0
  128. package/dist/normalization/jats/utils/po/text.js.map +1 -0
  129. package/dist/normalization/jats/utils/references.d.ts +26 -0
  130. package/dist/normalization/jats/utils/references.d.ts.map +1 -0
  131. package/dist/normalization/jats/utils/references.js +371 -0
  132. package/dist/normalization/jats/utils/references.js.map +1 -0
  133. package/dist/normalization/jats/utils/strings.d.ts +8 -0
  134. package/dist/normalization/jats/utils/strings.d.ts.map +1 -0
  135. package/dist/normalization/jats/utils/strings.js +197 -0
  136. package/dist/normalization/jats/utils/strings.js.map +1 -0
  137. package/dist/normalization/jats/utils/types.d.ts +233 -0
  138. package/dist/normalization/jats/utils/types.d.ts.map +1 -0
  139. package/dist/normalization/jats/utils/types.js +2 -0
  140. package/dist/normalization/jats/utils/types.js.map +1 -0
  141. package/dist/normalization/jats/utils/xml.d.ts +5 -0
  142. package/dist/normalization/jats/utils/xml.d.ts.map +1 -0
  143. package/dist/normalization/jats/utils/xml.js +69 -0
  144. package/dist/normalization/jats/utils/xml.js.map +1 -0
  145. package/dist/normalization/normalized-doc-schema.d.ts +1094 -0
  146. package/dist/normalization/normalized-doc-schema.d.ts.map +1 -0
  147. package/dist/normalization/normalized-doc-schema.js +410 -0
  148. package/dist/normalization/normalized-doc-schema.js.map +1 -0
  149. package/dist/normalization/pdf/index.d.ts +4 -0
  150. package/dist/normalization/pdf/index.d.ts.map +1 -0
  151. package/dist/normalization/pdf/index.js +3 -0
  152. package/dist/normalization/pdf/index.js.map +1 -0
  153. package/dist/normalization/pdf/normalize.d.ts +31 -0
  154. package/dist/normalization/pdf/normalize.d.ts.map +1 -0
  155. package/dist/normalization/pdf/normalize.js +321 -0
  156. package/dist/normalization/pdf/normalize.js.map +1 -0
  157. package/dist/normalization/pdf/prompt.d.ts +3 -0
  158. package/dist/normalization/pdf/prompt.d.ts.map +1 -0
  159. package/dist/normalization/pdf/prompt.js +118 -0
  160. package/dist/normalization/pdf/prompt.js.map +1 -0
  161. package/dist/sources/arxiv/client.d.ts +4 -0
  162. package/dist/sources/arxiv/client.d.ts.map +1 -0
  163. package/dist/sources/arxiv/client.js +13 -0
  164. package/dist/sources/arxiv/client.js.map +1 -0
  165. package/dist/sources/biorxiv/client.d.ts +21 -0
  166. package/dist/sources/biorxiv/client.d.ts.map +1 -0
  167. package/dist/sources/biorxiv/client.js +173 -0
  168. package/dist/sources/biorxiv/client.js.map +1 -0
  169. package/dist/sources/crossref/client.d.ts +3 -0
  170. package/dist/sources/crossref/client.d.ts.map +1 -0
  171. package/dist/sources/crossref/client.js +24 -0
  172. package/dist/sources/crossref/client.js.map +1 -0
  173. package/dist/sources/europepmc/client.d.ts +3 -0
  174. package/dist/sources/europepmc/client.d.ts.map +1 -0
  175. package/dist/sources/europepmc/client.js +29 -0
  176. package/dist/sources/europepmc/client.js.map +1 -0
  177. package/dist/sources/medrxiv/browser.d.ts +16 -0
  178. package/dist/sources/medrxiv/browser.d.ts.map +1 -0
  179. package/dist/sources/medrxiv/browser.js +210 -0
  180. package/dist/sources/medrxiv/browser.js.map +1 -0
  181. package/dist/sources/medrxiv/client.d.ts +34 -0
  182. package/dist/sources/medrxiv/client.d.ts.map +1 -0
  183. package/dist/sources/medrxiv/client.js +673 -0
  184. package/dist/sources/medrxiv/client.js.map +1 -0
  185. package/dist/sources/medrxiv/shared.d.ts +7 -0
  186. package/dist/sources/medrxiv/shared.d.ts.map +1 -0
  187. package/dist/sources/medrxiv/shared.js +18 -0
  188. package/dist/sources/medrxiv/shared.js.map +1 -0
  189. package/dist/sources/plos/client.d.ts +13 -0
  190. package/dist/sources/plos/client.d.ts.map +1 -0
  191. package/dist/sources/plos/client.js +147 -0
  192. package/dist/sources/plos/client.js.map +1 -0
  193. package/dist/sources/preprint-discovery.d.ts +55 -0
  194. package/dist/sources/preprint-discovery.d.ts.map +1 -0
  195. package/dist/sources/preprint-discovery.js +115 -0
  196. package/dist/sources/preprint-discovery.js.map +1 -0
  197. package/dist/types/expand.d.ts +5 -0
  198. package/dist/types/expand.d.ts.map +1 -0
  199. package/dist/types/expand.js +20 -0
  200. package/dist/types/expand.js.map +1 -0
  201. package/dist/types/methods-types.d.ts +37 -0
  202. package/dist/types/methods-types.d.ts.map +1 -0
  203. package/dist/types/methods-types.js +2 -0
  204. package/dist/types/methods-types.js.map +1 -0
  205. package/dist/types/multi-input-types.d.ts +57 -0
  206. package/dist/types/multi-input-types.d.ts.map +1 -0
  207. package/dist/types/multi-input-types.js +2 -0
  208. package/dist/types/multi-input-types.js.map +1 -0
  209. package/dist/types/paper/types.d.ts +41 -0
  210. package/dist/types/paper/types.d.ts.map +1 -0
  211. package/dist/types/paper/types.js +2 -0
  212. package/dist/types/paper/types.js.map +1 -0
  213. package/dist/types/results-types.d.ts +122 -0
  214. package/dist/types/results-types.d.ts.map +1 -0
  215. package/dist/types/results-types.js +17 -0
  216. package/dist/types/results-types.js.map +1 -0
  217. package/dist/types/supp-types.d.ts +6 -0
  218. package/dist/types/supp-types.d.ts.map +1 -0
  219. package/dist/types/supp-types.js +2 -0
  220. package/dist/types/supp-types.js.map +1 -0
  221. package/dist/types/version.d.ts +1828 -0
  222. package/dist/types/version.d.ts.map +1 -0
  223. package/dist/types/version.js +311 -0
  224. package/dist/types/version.js.map +1 -0
  225. package/dist/types/work.d.ts +4455 -0
  226. package/dist/types/work.d.ts.map +1 -0
  227. package/dist/types/work.js +330 -0
  228. package/dist/types/work.js.map +1 -0
  229. package/dist/works/adapters/crossref.d.ts +28 -0
  230. package/dist/works/adapters/crossref.d.ts.map +1 -0
  231. package/dist/works/adapters/crossref.js +43 -0
  232. package/dist/works/adapters/crossref.js.map +1 -0
  233. package/dist/works/adapters/europepmc.d.ts +14 -0
  234. package/dist/works/adapters/europepmc.d.ts.map +1 -0
  235. package/dist/works/adapters/europepmc.js +46 -0
  236. package/dist/works/adapters/europepmc.js.map +1 -0
  237. package/dist/works/adapters/openalex.d.ts +5 -0
  238. package/dist/works/adapters/openalex.d.ts.map +1 -0
  239. package/dist/works/adapters/openalex.js +75 -0
  240. package/dist/works/adapters/openalex.js.map +1 -0
  241. package/dist/works/errors.d.ts +23 -0
  242. package/dist/works/errors.d.ts.map +1 -0
  243. package/dist/works/errors.js +37 -0
  244. package/dist/works/errors.js.map +1 -0
  245. package/dist/works/id/detect-identifier.d.ts +15 -0
  246. package/dist/works/id/detect-identifier.d.ts.map +1 -0
  247. package/dist/works/id/detect-identifier.js +50 -0
  248. package/dist/works/id/detect-identifier.js.map +1 -0
  249. package/dist/works/id/normalize-external-id.d.ts +3 -0
  250. package/dist/works/id/normalize-external-id.d.ts.map +1 -0
  251. package/dist/works/id/normalize-external-id.js +44 -0
  252. package/dist/works/id/normalize-external-id.js.map +1 -0
  253. package/dist/works/id/normalize-ids.d.ts +66 -0
  254. package/dist/works/id/normalize-ids.d.ts.map +1 -0
  255. package/dist/works/id/normalize-ids.js +112 -0
  256. package/dist/works/id/normalize-ids.js.map +1 -0
  257. package/dist/works/id/normalize-internals.d.ts +7 -0
  258. package/dist/works/id/normalize-internals.d.ts.map +1 -0
  259. package/dist/works/id/normalize-internals.js +65 -0
  260. package/dist/works/id/normalize-internals.js.map +1 -0
  261. package/dist/works/id/resolve.d.ts +31 -0
  262. package/dist/works/id/resolve.d.ts.map +1 -0
  263. package/dist/works/id/resolve.js +123 -0
  264. package/dist/works/id/resolve.js.map +1 -0
  265. package/dist/works/id/resolveIds/assign.d.ts +4 -0
  266. package/dist/works/id/resolveIds/assign.d.ts.map +1 -0
  267. package/dist/works/id/resolveIds/assign.js +15 -0
  268. package/dist/works/id/resolveIds/assign.js.map +1 -0
  269. package/dist/works/id/resolveIds/flags.d.ts +11 -0
  270. package/dist/works/id/resolveIds/flags.d.ts.map +1 -0
  271. package/dist/works/id/resolveIds/flags.js +27 -0
  272. package/dist/works/id/resolveIds/flags.js.map +1 -0
  273. package/dist/works/id/resolveIds/idctx.d.ts +4 -0
  274. package/dist/works/id/resolveIds/idctx.d.ts.map +1 -0
  275. package/dist/works/id/resolveIds/idctx.js +25 -0
  276. package/dist/works/id/resolveIds/idctx.js.map +1 -0
  277. package/dist/works/id/resolveIds/index.d.ts +13 -0
  278. package/dist/works/id/resolveIds/index.d.ts.map +1 -0
  279. package/dist/works/id/resolveIds/index.js +498 -0
  280. package/dist/works/id/resolveIds/index.js.map +1 -0
  281. package/dist/works/id/resolveIds/versioning.d.ts +27 -0
  282. package/dist/works/id/resolveIds/versioning.d.ts.map +1 -0
  283. package/dist/works/id/resolveIds/versioning.js +156 -0
  284. package/dist/works/id/resolveIds/versioning.js.map +1 -0
  285. package/dist/works/id/resolveIds/workWhere.d.ts +3 -0
  286. package/dist/works/id/resolveIds/workWhere.d.ts.map +1 -0
  287. package/dist/works/id/resolveIds/workWhere.js +35 -0
  288. package/dist/works/id/resolveIds/workWhere.js.map +1 -0
  289. package/dist/works/id/types.d.ts +6 -0
  290. package/dist/works/id/types.d.ts.map +1 -0
  291. package/dist/works/id/types.js +2 -0
  292. package/dist/works/id/types.js.map +1 -0
  293. package/dist/works/pdf-fallback/candidates.d.ts +12 -0
  294. package/dist/works/pdf-fallback/candidates.d.ts.map +1 -0
  295. package/dist/works/pdf-fallback/candidates.js +51 -0
  296. package/dist/works/pdf-fallback/candidates.js.map +1 -0
  297. package/dist/works/pdf-fallback/fetch.d.ts +21 -0
  298. package/dist/works/pdf-fallback/fetch.d.ts.map +1 -0
  299. package/dist/works/pdf-fallback/fetch.js +89 -0
  300. package/dist/works/pdf-fallback/fetch.js.map +1 -0
  301. package/dist/works/pdf-fallback/index.d.ts +28 -0
  302. package/dist/works/pdf-fallback/index.d.ts.map +1 -0
  303. package/dist/works/pdf-fallback/index.js +35 -0
  304. package/dist/works/pdf-fallback/index.js.map +1 -0
  305. package/dist/works/plan.d.ts +8 -0
  306. package/dist/works/plan.d.ts.map +1 -0
  307. package/dist/works/plan.js +62 -0
  308. package/dist/works/plan.js.map +1 -0
  309. package/dist/works/strategies/arxiv.d.ts +3 -0
  310. package/dist/works/strategies/arxiv.d.ts.map +1 -0
  311. package/dist/works/strategies/arxiv.js +56 -0
  312. package/dist/works/strategies/arxiv.js.map +1 -0
  313. package/dist/works/strategies/biorxiv.d.ts +3 -0
  314. package/dist/works/strategies/biorxiv.d.ts.map +1 -0
  315. package/dist/works/strategies/biorxiv.js +63 -0
  316. package/dist/works/strategies/biorxiv.js.map +1 -0
  317. package/dist/works/strategies/europepmc.d.ts +3 -0
  318. package/dist/works/strategies/europepmc.d.ts.map +1 -0
  319. package/dist/works/strategies/europepmc.js +15 -0
  320. package/dist/works/strategies/europepmc.js.map +1 -0
  321. package/dist/works/strategies/index.d.ts +12 -0
  322. package/dist/works/strategies/index.d.ts.map +1 -0
  323. package/dist/works/strategies/index.js +19 -0
  324. package/dist/works/strategies/index.js.map +1 -0
  325. package/dist/works/strategies/landing-url.d.ts +3 -0
  326. package/dist/works/strategies/landing-url.d.ts.map +1 -0
  327. package/dist/works/strategies/landing-url.js +10 -0
  328. package/dist/works/strategies/landing-url.js.map +1 -0
  329. package/dist/works/strategies/medrxiv.d.ts +3 -0
  330. package/dist/works/strategies/medrxiv.d.ts.map +1 -0
  331. package/dist/works/strategies/medrxiv.js +47 -0
  332. package/dist/works/strategies/medrxiv.js.map +1 -0
  333. package/dist/works/strategies/plos.d.ts +3 -0
  334. package/dist/works/strategies/plos.d.ts.map +1 -0
  335. package/dist/works/strategies/plos.js +15 -0
  336. package/dist/works/strategies/plos.js.map +1 -0
  337. package/dist/works/strategies/shared.d.ts +11 -0
  338. package/dist/works/strategies/shared.d.ts.map +1 -0
  339. package/dist/works/strategies/shared.js +97 -0
  340. package/dist/works/strategies/shared.js.map +1 -0
  341. package/dist/works/strategies/ten1101.d.ts +3 -0
  342. package/dist/works/strategies/ten1101.d.ts.map +1 -0
  343. package/dist/works/strategies/ten1101.js +84 -0
  344. package/dist/works/strategies/ten1101.js.map +1 -0
  345. package/dist/works/text/acquire-fulltext.d.ts +7 -0
  346. package/dist/works/text/acquire-fulltext.d.ts.map +1 -0
  347. package/dist/works/text/acquire-fulltext.js +62 -0
  348. package/dist/works/text/acquire-fulltext.js.map +1 -0
  349. package/dist/works/text/normalize.d.ts +40 -0
  350. package/dist/works/text/normalize.d.ts.map +1 -0
  351. package/dist/works/text/normalize.js +188 -0
  352. package/dist/works/text/normalize.js.map +1 -0
  353. package/dist/works/types.d.ts +215 -0
  354. package/dist/works/types.d.ts.map +1 -0
  355. package/dist/works/types.js +6 -0
  356. package/dist/works/types.js.map +1 -0
  357. package/dist/works/util/debug.d.ts +7 -0
  358. package/dist/works/util/debug.d.ts.map +1 -0
  359. package/dist/works/util/debug.js +9 -0
  360. package/dist/works/util/debug.js.map +1 -0
  361. package/dist/works/util/license.d.ts +9 -0
  362. package/dist/works/util/license.d.ts.map +1 -0
  363. package/dist/works/util/license.js +39 -0
  364. package/dist/works/util/license.js.map +1 -0
  365. package/dist/works/util/normalize.d.ts +2 -0
  366. package/dist/works/util/normalize.d.ts.map +1 -0
  367. package/dist/works/util/normalize.js +76 -0
  368. package/dist/works/util/normalize.js.map +1 -0
  369. package/dist/works/util/parse.d.ts +8 -0
  370. package/dist/works/util/parse.d.ts.map +1 -0
  371. package/dist/works/util/parse.js +32 -0
  372. package/dist/works/util/parse.js.map +1 -0
  373. package/dist/works/util/source.d.ts +10 -0
  374. package/dist/works/util/source.d.ts.map +1 -0
  375. package/dist/works/util/source.js +48 -0
  376. package/dist/works/util/source.js.map +1 -0
  377. package/dist/works/util/version-label.d.ts +2 -0
  378. package/dist/works/util/version-label.d.ts.map +1 -0
  379. package/dist/works/util/version-label.js +8 -0
  380. package/dist/works/util/version-label.js.map +1 -0
  381. package/dist/works/util/work-id.d.ts +2 -0
  382. package/dist/works/util/work-id.d.ts.map +1 -0
  383. package/dist/works/util/work-id.js +27 -0
  384. package/dist/works/util/work-id.js.map +1 -0
  385. package/package.json +208 -0
@@ -0,0 +1,801 @@
1
+ import { poText } from "../po/text";
2
+ import { poChildren } from "../po/nodes";
3
+ import { poSerialize } from "../po/serialize";
4
+ import { poSerializeMinimal } from "../po/serialize";
5
+ import { poFindFirstByLocal } from "../po/query";
6
+ import { poFindDescendantsByLocal } from "../po/query";
7
+ import { poGetAttr } from "../po/nodes";
8
+ import { poIsTextNode, poTagName, poMatchesLocal } from "../po/nodes";
9
+ import { asString } from "../strings";
10
+ import { getText } from "../xml";
11
+ import { normalizeArray } from "../strings";
12
+ import { nsArray } from "../xml";
13
+ import { cleanHeading } from "../strings";
14
+ import { poFindSectionById } from "../po/query";
15
+ import { poCollectSectionTexts } from "../po/text";
16
+ import { collectSectionNode } from "./sections";
17
+ import { classifySection } from "../category";
18
+ export function collectAckRich(back, domPO) {
19
+ const out = { text: [] };
20
+ const pushText = (s) => {
21
+ if (s && s.trim())
22
+ out.text.push(s.trim());
23
+ };
24
+ const pushXml = (pNode) => {
25
+ const t = poText(poChildren(pNode)) || poText(pNode);
26
+ if (t && t.trim())
27
+ out.text.push(t.trim());
28
+ const x = poSerialize(pNode);
29
+ if (x && x.trim())
30
+ (out.xml = out.xml || []).push(x);
31
+ const xm = poSerializeMinimal(pNode);
32
+ if (xm && xm.trim())
33
+ (out.xml_minimal = out.xml_minimal || []).push(xm);
34
+ };
35
+ // PO path: prefer preserveOrder for accurate inline content
36
+ if (domPO) {
37
+ const backPO = poFindFirstByLocal(domPO, "back");
38
+ if (backPO) {
39
+ for (const ackPO of poFindDescendantsByLocal(backPO, "ack")) {
40
+ // Capture ack title when present
41
+ const tnode = poFindFirstByLocal(ackPO, "title") ||
42
+ poFindFirstByLocal(ackPO, "label");
43
+ const t = (tnode && (poText(poChildren(tnode)) || poText(tnode))) || undefined;
44
+ if (t && !out.title)
45
+ out.title = t;
46
+ const pNodes = poFindDescendantsByLocal(ackPO, "p");
47
+ if (pNodes.length) {
48
+ for (const p of pNodes)
49
+ pushXml(p);
50
+ }
51
+ else {
52
+ const t = poText(poChildren(ackPO)) || poText(ackPO);
53
+ pushText(t || undefined);
54
+ }
55
+ }
56
+ // Also consider back > sec[@sec-type contains 'ack']
57
+ for (const secPO of poFindDescendantsByLocal(backPO, "sec")) {
58
+ const secType = (poGetAttr(secPO, "sec-type") || "").toLowerCase();
59
+ const titleNode = poFindFirstByLocal(secPO, "title") ||
60
+ poFindFirstByLocal(secPO, "label");
61
+ const title = (titleNode && (poText(poChildren(titleNode)) || poText(titleNode))) ||
62
+ "";
63
+ if (title && !out.title)
64
+ out.title = title;
65
+ const hit = secType.includes("ack") || /acknowledg(e)?ments?/i.test(title || "");
66
+ if (hit) {
67
+ const pNodes = poFindDescendantsByLocal(secPO, "p");
68
+ if (pNodes.length) {
69
+ for (const p of pNodes)
70
+ pushXml(p);
71
+ }
72
+ else {
73
+ const t = poText(poChildren(secPO)) || poText(secPO);
74
+ pushText(t || undefined);
75
+ }
76
+ }
77
+ }
78
+ }
79
+ }
80
+ // Fallback to object-mode if we didn't capture anything
81
+ if (!out.text.length) {
82
+ const ack = back?.ack;
83
+ if (!out.title)
84
+ out.title = asString(ack?.title) || undefined;
85
+ if (ack) {
86
+ const paras = normalizeArray(ack?.p)
87
+ .map((p) => getText(p))
88
+ .filter(Boolean);
89
+ if (paras.length)
90
+ out.text.push(...paras);
91
+ else
92
+ pushText(getText(ack));
93
+ }
94
+ for (const sec of nsArray(back, "sec")) {
95
+ const st = asString(sec?.["@_sec-type"]) ||
96
+ cleanHeading(getText(sec?.title) || getText(sec?.label));
97
+ if (!st)
98
+ continue;
99
+ const stLow = String(st).toLowerCase();
100
+ if (stLow.includes("ack")) {
101
+ if (!out.title)
102
+ out.title = getText(sec?.title) || getText(sec?.label) || undefined;
103
+ for (const p of nsArray(sec, "p"))
104
+ pushText(getText(p));
105
+ if (!nsArray(sec, "p").length)
106
+ pushText(getText(sec));
107
+ }
108
+ }
109
+ }
110
+ return out;
111
+ }
112
+ export function collectBackSecRich(back, secTypes, domPO) {
113
+ const out = { text: [] };
114
+ const pushText = (s) => {
115
+ if (s && s.trim())
116
+ out.text.push(s.trim());
117
+ };
118
+ const pushXml = (pNode) => {
119
+ const t = poText(poChildren(pNode)) || poText(pNode);
120
+ if (t && t.trim())
121
+ out.text.push(t.trim());
122
+ const x = poSerialize(pNode);
123
+ if (x && x.trim())
124
+ (out.xml = out.xml || []).push(x);
125
+ const xm = poSerializeMinimal(pNode);
126
+ if (xm && xm.trim())
127
+ (out.xml_minimal = out.xml_minimal || []).push(xm);
128
+ };
129
+ const targets = new Set(secTypes.map((x) => x.toLowerCase()));
130
+ const backPO = domPO ? poFindFirstByLocal(domPO, "back") : undefined;
131
+ for (const sec of nsArray(back, "sec")) {
132
+ const st = (asString(sec?.["@_sec-type"]) || "").toLowerCase();
133
+ const title = cleanHeading(getText(sec?.title) || getText(sec?.label) || "") || "";
134
+ const tLow = title.toLowerCase();
135
+ const nameHit = targets.has(st);
136
+ const titleHit = (targets.has("supplementary-material") && /supplementary/.test(tLow)) ||
137
+ (targets.has("data-availability") &&
138
+ /(data\s*availability|availability\s*of\s*data)/.test(tLow)) ||
139
+ (targets.has("funding") &&
140
+ /(funding|funds|financial\s+support)/.test(tLow));
141
+ if (nameHit || titleHit) {
142
+ // Try preserveOrder extraction for accurate inline order and XML variants
143
+ const secId = asString(sec?.["@_id"]) ||
144
+ asString(sec?.id) ||
145
+ asString(sec?.["@_hwp:id"]) ||
146
+ undefined;
147
+ let pushed = false;
148
+ // Capture title from object-mode
149
+ if (!out.title)
150
+ out.title = getText(sec?.title) || undefined;
151
+ if (backPO && secId) {
152
+ const secPO = poFindSectionById(backPO, secId) || poFindSectionById(domPO, secId);
153
+ if (secPO) {
154
+ // Capture title from PO if available
155
+ const tnode = poFindFirstByLocal(secPO, "title") ||
156
+ poFindFirstByLocal(secPO, "label");
157
+ const t = (tnode && (poText(poChildren(tnode)) || poText(tnode))) ||
158
+ undefined;
159
+ if (t && !out.title)
160
+ out.title = t;
161
+ // Special handling for supplementary: avoid pulling <p> under <fig> to prevent duplicating legends
162
+ if (targets.has("supplementary-material")) {
163
+ const collected = poCollectSectionTexts(secPO);
164
+ if (collected.paragraphs.length) {
165
+ for (const p of collected.paragraphs)
166
+ pushText(p);
167
+ pushed = true;
168
+ }
169
+ }
170
+ else {
171
+ const pNodes = poFindDescendantsByLocal(secPO, "p");
172
+ if (pNodes.length) {
173
+ for (const p of pNodes)
174
+ pushXml(p);
175
+ pushed = true;
176
+ }
177
+ }
178
+ if (!pushed) {
179
+ const t = (poText(poChildren(secPO)) || poText(secPO))?.trim();
180
+ if (t) {
181
+ pushText(t);
182
+ pushed = true;
183
+ }
184
+ }
185
+ }
186
+ }
187
+ if (!pushed) {
188
+ const ps = nsArray(sec, "p")
189
+ .map((p) => getText(p))
190
+ .filter(Boolean);
191
+ if (ps.length)
192
+ out.text.push(...ps);
193
+ else
194
+ pushText(getText(sec));
195
+ }
196
+ }
197
+ }
198
+ return out;
199
+ }
200
+ export function collectNotesRich(back, domPO) {
201
+ const out = { text: [] };
202
+ const pushText = (s) => {
203
+ if (s && s.trim())
204
+ out.text.push(s.trim());
205
+ };
206
+ const pushXml = (pNode) => {
207
+ const t = poText(poChildren(pNode)) || poText(pNode);
208
+ if (t && t.trim())
209
+ out.text.push(t.trim());
210
+ const x = poSerialize(pNode);
211
+ if (x && x.trim())
212
+ (out.xml = out.xml || []).push(x);
213
+ const xm = poSerializeMinimal(pNode);
214
+ if (xm && xm.trim())
215
+ (out.xml_minimal = out.xml_minimal || []).push(xm);
216
+ };
217
+ // Try preserveOrder
218
+ if (domPO) {
219
+ const backPO = poFindFirstByLocal(domPO, "back");
220
+ if (backPO) {
221
+ for (const fng of poFindDescendantsByLocal(backPO, "fn-group")) {
222
+ for (const fn of poFindDescendantsByLocal(fng, "fn")) {
223
+ const pNodes = poFindDescendantsByLocal(fn, "p");
224
+ if (pNodes.length) {
225
+ for (const p of pNodes)
226
+ pushXml(p);
227
+ }
228
+ else {
229
+ const t = poText(poChildren(fn)) || poText(fn);
230
+ pushText(t || undefined);
231
+ }
232
+ }
233
+ }
234
+ }
235
+ }
236
+ if (!out.text.length) {
237
+ const fng = back?.["fn-group"];
238
+ const fns = normalizeArray(fng?.fn);
239
+ for (const fn of fns) {
240
+ const txt = getText(fn);
241
+ if (txt)
242
+ out.text.push(txt);
243
+ }
244
+ }
245
+ return out;
246
+ }
247
+ export function collectSupplementary(body, back) {
248
+ const items = [
249
+ ...normalizeArray(body?.["supplementary-material"]),
250
+ ...normalizeArray(back?.["supplementary-material"]),
251
+ ];
252
+ return items.map((x) => ({
253
+ href: x?.["@_xlink:href"] || x?.["@_href"] || undefined,
254
+ content_type: x?.["@_content-type"] || undefined,
255
+ }));
256
+ }
257
+ // Collect supplementary graphics from figures and tables labeled/typed as supplementary
258
+ export function collectSupplementaryGraphics(domPO) {
259
+ const out = [];
260
+ const articlePO = poFindFirstByLocal(domPO, "article") || domPO;
261
+ if (!articlePO)
262
+ return out;
263
+ // Figures
264
+ for (const f of poFindDescendantsByLocal(articlePO, "fig")) {
265
+ const figId = poGetAttr(f, "id") || poGetAttr(f, "hwp:id");
266
+ const labelNode = poFindFirstByLocal(f, "label");
267
+ const label = (labelNode && (poText(poChildren(labelNode)) || poText(labelNode))) ||
268
+ undefined;
269
+ const isSupp = (figId && /^figs/i.test(figId)) ||
270
+ (label || "").toLowerCase().includes("supplementary");
271
+ if (!isSupp)
272
+ continue;
273
+ const caption = poFindFirstByLocal(f, "caption");
274
+ let titleText;
275
+ const capParas = [];
276
+ const capXml = [];
277
+ const capXmlMin = [];
278
+ if (caption) {
279
+ const titleNode = poFindFirstByLocal(caption, "title");
280
+ titleText =
281
+ (titleNode && (poText(poChildren(titleNode)) || poText(titleNode))) ||
282
+ undefined;
283
+ const pNodes = poFindDescendantsByLocal(caption, "p");
284
+ for (const pn of pNodes) {
285
+ const t = (poText(poChildren(pn)) || poText(pn) || "").trim();
286
+ if (t)
287
+ capParas.push(t);
288
+ const x = poSerialize(pn);
289
+ if (x && x.trim())
290
+ capXml.push(x);
291
+ const xm = poSerializeMinimal(pn);
292
+ if (xm && xm.trim())
293
+ capXmlMin.push(xm);
294
+ }
295
+ if (!capParas.length) {
296
+ const tAll = (poText(poChildren(caption)) || poText(caption) || "").trim();
297
+ if (tAll)
298
+ capParas.push(tAll);
299
+ const xAll = poSerialize(caption);
300
+ if (xAll && xAll.trim())
301
+ capXml.push(xAll);
302
+ const xmAll = poSerializeMinimal(caption);
303
+ if (xmAll && xmAll.trim())
304
+ capXmlMin.push(xmAll);
305
+ }
306
+ }
307
+ const slugNode = poFindDescendantsByLocal(f, "object-id").find((n) => {
308
+ const sub = poGetAttr(n, "hwp:sub-type");
309
+ return (sub || "").toLowerCase() === "slug";
310
+ });
311
+ const slug = (slugNode && (poText(poChildren(slugNode)) || poText(slugNode))) ||
312
+ undefined;
313
+ const figCaption = {
314
+ ...(capParas.length ? { paragraphs: capParas } : {}),
315
+ ...(capXml.length ? { xml: capXml } : {}),
316
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
317
+ };
318
+ out.push({
319
+ kind: "figure",
320
+ ...(figId ? { id: figId } : {}),
321
+ ...(label && label.trim() ? { label: label.trim() } : {}),
322
+ ...(titleText && titleText.trim() ? { title: titleText.trim() } : {}),
323
+ ...(slug && slug.trim() ? { slug: slug.trim() } : {}),
324
+ ...(Object.keys(figCaption).length ? { caption: figCaption } : {}),
325
+ });
326
+ }
327
+ // Tables
328
+ for (const t of poFindDescendantsByLocal(articlePO, "table-wrap")) {
329
+ const tblId = poGetAttr(t, "id") || poGetAttr(t, "hwp:id");
330
+ const labelNode = poFindFirstByLocal(t, "label");
331
+ const label = (labelNode && (poText(poChildren(labelNode)) || poText(labelNode))) ||
332
+ undefined;
333
+ const isSupp = (tblId && /^tbls/i.test(tblId)) ||
334
+ (label || "").toLowerCase().includes("supplementary");
335
+ if (!isSupp)
336
+ continue;
337
+ const caption = poFindFirstByLocal(t, "caption");
338
+ const titleNode = caption ? poFindFirstByLocal(caption, "title") : undefined;
339
+ const title = titleNode
340
+ ? (poText(poChildren(titleNode)) || poText(titleNode) || undefined)
341
+ : undefined;
342
+ const capParas = [];
343
+ const capXml = [];
344
+ const capXmlMin = [];
345
+ if (caption) {
346
+ const pNodes = poFindDescendantsByLocal(caption, "p");
347
+ for (const pn of pNodes) {
348
+ const txt = (poText(poChildren(pn)) || poText(pn) || "").trim();
349
+ if (!txt)
350
+ continue;
351
+ capParas.push(txt);
352
+ const x = poSerialize(pn);
353
+ if (x && x.trim())
354
+ capXml.push(x);
355
+ const xm = poSerializeMinimal(pn);
356
+ if (xm && xm.trim())
357
+ capXmlMin.push(xm);
358
+ }
359
+ }
360
+ const tblSlugNode = poFindDescendantsByLocal(t, "object-id").find((n) => {
361
+ const sub = poGetAttr(n, "hwp:sub-type");
362
+ return (sub || "").toLowerCase() === "slug";
363
+ });
364
+ const tblSlug = (tblSlugNode && (poText(poChildren(tblSlugNode)) || poText(tblSlugNode))) ||
365
+ undefined;
366
+ const tblCaption = {
367
+ ...(capParas.length ? { paragraphs: capParas } : {}),
368
+ ...(capXml.length ? { xml: capXml } : {}),
369
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
370
+ };
371
+ out.push({
372
+ kind: "table",
373
+ ...(tblId ? { id: tblId } : {}),
374
+ ...(label && label.trim() ? { label: label.trim() } : {}),
375
+ ...(title && title.trim() ? { title: title.trim() } : {}),
376
+ ...(tblSlug && tblSlug.trim() ? { slug: tblSlug.trim() } : {}),
377
+ ...(Object.keys(tblCaption).length ? { caption: tblCaption } : {}),
378
+ });
379
+ }
380
+ return out;
381
+ }
382
+ // Build a structured Supplementary Figures section with one child per <fig> that appears to be supplementary
383
+ export function collectSupplementaryFiguresSections(domPO) {
384
+ const articlePO = poFindFirstByLocal(domPO, "article") || domPO;
385
+ if (!articlePO)
386
+ return undefined;
387
+ const figs = poFindDescendantsByLocal(articlePO, "fig");
388
+ const blocks = [];
389
+ for (const f of figs) {
390
+ const figId = poGetAttr(f, "id");
391
+ const labelNode = poFindFirstByLocal(f, "label");
392
+ const label = (labelNode && (poText(poChildren(labelNode)) || poText(labelNode))) ||
393
+ undefined;
394
+ const isSupp = (figId && /^figs/i.test(figId)) ||
395
+ (label || "").toLowerCase().includes("supplementary");
396
+ if (!isSupp)
397
+ continue;
398
+ // Caption extraction
399
+ const caption = poFindFirstByLocal(f, "caption");
400
+ let titleText;
401
+ const capParas = [];
402
+ const capXml = [];
403
+ const capXmlMin = [];
404
+ if (caption) {
405
+ const titleNode = poFindFirstByLocal(caption, "title");
406
+ titleText =
407
+ (titleNode && (poText(poChildren(titleNode)) || poText(titleNode))) ||
408
+ undefined;
409
+ const pNodes = poFindDescendantsByLocal(caption, "p");
410
+ for (const pn of pNodes) {
411
+ const t = poText(poChildren(pn)) || poText(pn);
412
+ if (t && t.trim())
413
+ capParas.push(t.trim());
414
+ const x = poSerialize(pn);
415
+ if (x && x.trim())
416
+ capXml.push(x);
417
+ const xm = poSerializeMinimal(pn);
418
+ if (xm && xm.trim())
419
+ capXmlMin.push(xm);
420
+ }
421
+ // Fallback when caption has no <p>
422
+ if (!capParas.length) {
423
+ const tAll = (poText(poChildren(caption)) ||
424
+ poText(caption) ||
425
+ "").trim();
426
+ if (tAll)
427
+ capParas.push(tAll);
428
+ const xAll = poSerialize(caption);
429
+ if (xAll && xAll.trim())
430
+ capXml.push(xAll);
431
+ const xmAll = poSerializeMinimal(caption);
432
+ if (xmAll && xmAll.trim())
433
+ capXmlMin.push(xmAll);
434
+ }
435
+ }
436
+ const slugNode = poFindDescendantsByLocal(f, "object-id").find((n) => {
437
+ const sub = poGetAttr(n, "hwp:sub-type");
438
+ return (sub || "").toLowerCase() === "slug";
439
+ });
440
+ const slug = (slugNode && (poText(poChildren(slugNode)) || poText(slugNode))) ||
441
+ undefined;
442
+ const figCaption = {
443
+ ...(capParas.length ? { paragraphs: capParas } : {}),
444
+ ...(capXml.length ? { xml: capXml } : {}),
445
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
446
+ };
447
+ const figBlock = {
448
+ kind: "figure",
449
+ ...(figId ? { id: figId } : {}),
450
+ ...(label && label.trim() ? { label: label.trim() } : {}),
451
+ ...(titleText && titleText.trim() ? { title: titleText.trim() } : {}),
452
+ ...(slug && slug.trim() ? { slug: slug.trim() } : {}),
453
+ ...(Object.keys(figCaption).length ? { caption: figCaption } : {}),
454
+ };
455
+ blocks.push(figBlock);
456
+ }
457
+ if (!blocks.length)
458
+ return undefined;
459
+ const parent = {
460
+ title: "Supplementary Figures",
461
+ normalized_title: "Supplementary Material",
462
+ category: "supplementary",
463
+ blocks,
464
+ };
465
+ return parent;
466
+ }
467
+ // Build a structured Supplementary Tables section with one table block per <table-wrap> that appears to be supplementary
468
+ export function collectSupplementaryTablesSections(domPO) {
469
+ const articlePO = poFindFirstByLocal(domPO, "article") || domPO;
470
+ if (!articlePO)
471
+ return undefined;
472
+ const tables = poFindDescendantsByLocal(articlePO, "table-wrap");
473
+ const blocks = [];
474
+ for (const t of tables) {
475
+ const tblId = poGetAttr(t, "id") || poGetAttr(t, "hwp:id");
476
+ const labelNode = poFindFirstByLocal(t, "label");
477
+ const label = (labelNode && (poText(poChildren(labelNode)) || poText(labelNode))) ||
478
+ undefined;
479
+ const isSupp = (tblId && /^tbls/i.test(tblId)) ||
480
+ (label || "").toLowerCase().includes("supplementary");
481
+ if (!isSupp)
482
+ continue;
483
+ const caption = poFindFirstByLocal(t, "caption");
484
+ const titleNode = caption
485
+ ? poFindFirstByLocal(caption, "title")
486
+ : undefined;
487
+ const title = titleNode
488
+ ? poText(poChildren(titleNode)) || poText(titleNode) || undefined
489
+ : undefined;
490
+ const capParas = [];
491
+ const capXml = [];
492
+ const capXmlMin = [];
493
+ if (caption) {
494
+ const pNodes = poFindDescendantsByLocal(caption, "p");
495
+ for (const pn of pNodes) {
496
+ const txt = (poText(poChildren(pn)) || poText(pn) || "").trim();
497
+ if (!txt)
498
+ continue;
499
+ capParas.push(txt);
500
+ const x = poSerialize(pn);
501
+ if (x && x.trim())
502
+ capXml.push(x);
503
+ const xm = poSerializeMinimal(pn);
504
+ if (xm && xm.trim())
505
+ capXmlMin.push(xm);
506
+ }
507
+ }
508
+ const tblSlugNode = poFindDescendantsByLocal(t, "object-id").find((n) => {
509
+ const sub = poGetAttr(n, "hwp:sub-type");
510
+ return (sub || "").toLowerCase() === "slug";
511
+ });
512
+ const tblSlug = (tblSlugNode &&
513
+ (poText(poChildren(tblSlugNode)) || poText(tblSlugNode))) ||
514
+ undefined;
515
+ const tblCaption = {
516
+ ...(capParas.length ? { paragraphs: capParas } : {}),
517
+ ...(capXml.length ? { xml: capXml } : {}),
518
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
519
+ };
520
+ const tblBlock = {
521
+ kind: "table",
522
+ ...(tblId ? { id: tblId } : {}),
523
+ ...(label && label.trim() ? { label: label.trim() } : {}),
524
+ ...(title && title.trim() ? { title: title.trim() } : {}),
525
+ ...(tblSlug && tblSlug.trim() ? { slug: tblSlug.trim() } : {}),
526
+ ...(Object.keys(tblCaption).length ? { caption: tblCaption } : {}),
527
+ };
528
+ blocks.push(tblBlock);
529
+ }
530
+ if (!blocks.length)
531
+ return undefined;
532
+ const parent = {
533
+ title: "Supplementary Tables",
534
+ normalized_title: "Supplementary Material",
535
+ category: "supplementary",
536
+ blocks,
537
+ };
538
+ return parent;
539
+ }
540
+ // Collect generic back <sec> sections that are not handled by specific buckets
541
+ // like acknowledgements, data availability, funding, notes, or supplementary.
542
+ export function collectGenericBackSections(back, domPO) {
543
+ const out = [];
544
+ try {
545
+ const backPO = poFindFirstByLocal(domPO, "back");
546
+ const seenIds = new Set();
547
+ for (const sec of nsArray(back, "sec")) {
548
+ const id = asString(sec?.["@_id"]) ||
549
+ asString(sec?.id) ||
550
+ asString(sec?.["@_hwp:id"]) ||
551
+ undefined;
552
+ const sec_type = asString(sec?.["@_sec-type"]) || undefined;
553
+ const titleRaw = getText(sec?.title) || getText(sec?.label) || undefined;
554
+ const { category: cat, normalized_title: norm } = classifySection(titleRaw, sec_type, 0, undefined);
555
+ // Skip sections handled elsewhere and supplementary here
556
+ if (cat === "acknowledgements" ||
557
+ cat === "data_availability" ||
558
+ cat === "funding" ||
559
+ cat === "notes" ||
560
+ cat === "supplementary")
561
+ continue;
562
+ if (id) {
563
+ if (seenIds.has(id))
564
+ continue;
565
+ seenIds.add(id);
566
+ }
567
+ const blocks = [];
568
+ let paragraphs = [];
569
+ let paragraphs_xml = [];
570
+ let paragraphs_xml_minimal = [];
571
+ if (backPO && id) {
572
+ const secPO = poFindSectionById(backPO, id) || poFindSectionById(domPO, id);
573
+ if (secPO) {
574
+ const subObjs = nsArray(sec, "sec");
575
+ let poSecIdx = 0;
576
+ for (const ch of poChildren(secPO)) {
577
+ if (poIsTextNode(ch)) {
578
+ const t = (poText(ch) || "").trim();
579
+ if (t)
580
+ blocks.push({ kind: "paragraph", text: t });
581
+ continue;
582
+ }
583
+ const nm = poTagName(ch) || "";
584
+ if (poMatchesLocal(nm, "title") || poMatchesLocal(nm, "label"))
585
+ continue;
586
+ if (poMatchesLocal(nm, "sec")) {
587
+ const os = subObjs[poSecIdx];
588
+ const sub = os
589
+ ? collectSectionNode(os, 1, undefined, domPO, secPO, poSecIdx)
590
+ : { title: undefined, paragraphs: [] };
591
+ blocks.push({ kind: "section", section: sub });
592
+ poSecIdx += 1;
593
+ continue;
594
+ }
595
+ if (poMatchesLocal(nm, "p")) {
596
+ const t = (poText(poChildren(ch)) || poText(ch) || "").trim();
597
+ if (!t)
598
+ continue;
599
+ const x = poSerialize(ch);
600
+ const xm = poSerializeMinimal(ch);
601
+ blocks.push({
602
+ kind: "paragraph",
603
+ text: t,
604
+ ...(x && x.trim() ? { xml: x } : {}),
605
+ ...(xm && xm.trim() ? { xml_minimal: xm } : {}),
606
+ });
607
+ continue;
608
+ }
609
+ if (poMatchesLocal(nm, "list")) {
610
+ for (const it of poFindDescendantsByLocal(ch, "list-item")) {
611
+ const p = poFindFirstByLocal(it, "p");
612
+ const t = ((p && (poText(poChildren(p)) || poText(p))) ||
613
+ poText(it) ||
614
+ "").trim();
615
+ if (!t)
616
+ continue;
617
+ const x = p ? poSerialize(p) : undefined;
618
+ const xm = p ? poSerializeMinimal(p) : undefined;
619
+ blocks.push({
620
+ kind: "paragraph",
621
+ text: t,
622
+ ...(x && x?.trim() ? { xml: x } : {}),
623
+ ...(xm && xm?.trim() ? { xml_minimal: xm } : {}),
624
+ });
625
+ }
626
+ continue;
627
+ }
628
+ if (poMatchesLocal(nm, "boxed-text")) {
629
+ for (const p of poFindDescendantsByLocal(ch, "p")) {
630
+ const t = (poText(poChildren(p)) || poText(p) || "").trim();
631
+ if (!t)
632
+ continue;
633
+ const x = poSerialize(p);
634
+ const xm = poSerializeMinimal(p);
635
+ blocks.push({
636
+ kind: "paragraph",
637
+ text: t,
638
+ ...(x && x.trim() ? { xml: x } : {}),
639
+ ...(xm && xm.trim() ? { xml_minimal: xm } : {}),
640
+ });
641
+ }
642
+ continue;
643
+ }
644
+ if (poMatchesLocal(nm, "fig")) {
645
+ const figId = poGetAttr(ch, "id") || poGetAttr(ch, "hwp:id");
646
+ const labelNode = poFindFirstByLocal(ch, "label");
647
+ const label = (labelNode &&
648
+ (poText(poChildren(labelNode)) || poText(labelNode))) ||
649
+ undefined;
650
+ const cap = poFindFirstByLocal(ch, "caption");
651
+ const titleNode = cap ? poFindFirstByLocal(cap, "title") : undefined;
652
+ const title = titleNode
653
+ ? poText(poChildren(titleNode)) || poText(titleNode) || undefined
654
+ : undefined;
655
+ const capParas = [];
656
+ const capXml = [];
657
+ const capXmlMin = [];
658
+ if (cap) {
659
+ for (const p of poFindDescendantsByLocal(cap, "p")) {
660
+ const t = (poText(poChildren(p)) || poText(p) || "").trim();
661
+ if (!t)
662
+ continue;
663
+ capParas.push(t);
664
+ const x = poSerialize(p);
665
+ const xm = poSerializeMinimal(p);
666
+ if (x && x.trim())
667
+ capXml.push(x);
668
+ if (xm && xm.trim())
669
+ capXmlMin.push(xm);
670
+ }
671
+ }
672
+ const figCaption = {
673
+ ...(capParas.length ? { paragraphs: capParas } : {}),
674
+ ...(capXml.length ? { xml: capXml } : {}),
675
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
676
+ };
677
+ const figBlock = {
678
+ kind: "figure",
679
+ ...(figId ? { id: figId } : {}),
680
+ ...(label && label.trim() ? { label: label.trim() } : {}),
681
+ ...(title && title.trim() ? { title: title.trim() } : {}),
682
+ ...(Object.keys(figCaption).length ? { caption: figCaption } : {}),
683
+ };
684
+ blocks.push(figBlock);
685
+ continue;
686
+ }
687
+ if (poMatchesLocal(nm, "table-wrap")) {
688
+ const tblId = poGetAttr(ch, "id") || poGetAttr(ch, "hwp:id");
689
+ const labelNode = poFindFirstByLocal(ch, "label");
690
+ const label = (labelNode &&
691
+ (poText(poChildren(labelNode)) || poText(labelNode))) ||
692
+ undefined;
693
+ const cap = poFindFirstByLocal(ch, "caption");
694
+ const titleNode = cap ? poFindFirstByLocal(cap, "title") : undefined;
695
+ const title = titleNode
696
+ ? poText(poChildren(titleNode)) || poText(titleNode) || undefined
697
+ : undefined;
698
+ const capParas = [];
699
+ const capXml = [];
700
+ const capXmlMin = [];
701
+ if (cap) {
702
+ for (const p of poFindDescendantsByLocal(cap, "p")) {
703
+ const t = (poText(poChildren(p)) || poText(p) || "").trim();
704
+ if (!t)
705
+ continue;
706
+ capParas.push(t);
707
+ const x = poSerialize(p);
708
+ const xm = poSerializeMinimal(p);
709
+ if (x && x.trim())
710
+ capXml.push(x);
711
+ if (xm && xm.trim())
712
+ capXmlMin.push(xm);
713
+ }
714
+ }
715
+ const tblCaption = {
716
+ ...(capParas.length ? { paragraphs: capParas } : {}),
717
+ ...(capXml.length ? { xml: capXml } : {}),
718
+ ...(capXmlMin.length ? { xml_minimal: capXmlMin } : {}),
719
+ };
720
+ const tblBlock = {
721
+ kind: "table",
722
+ ...(tblId ? { id: tblId } : {}),
723
+ ...(label && label.trim() ? { label: label.trim() } : {}),
724
+ ...(title && title.trim() ? { title: title.trim() } : {}),
725
+ ...(Object.keys(tblCaption).length ? { caption: tblCaption } : {}),
726
+ };
727
+ blocks.push(tblBlock);
728
+ continue;
729
+ }
730
+ if (poMatchesLocal(nm, "def-list")) {
731
+ for (const di of poFindDescendantsByLocal(ch, "def-item")) {
732
+ const term = poFindFirstByLocal(di, "term");
733
+ const defn = poFindFirstByLocal(di, "def");
734
+ const line = [
735
+ poText(poChildren(term)) || poText(term),
736
+ poText(poChildren(defn)) || poText(defn),
737
+ ]
738
+ .filter(Boolean)
739
+ .map((s) => String(s).trim())
740
+ .filter(Boolean)
741
+ .join(" – ");
742
+ if (line)
743
+ blocks.push({ kind: "paragraph", text: line });
744
+ }
745
+ continue;
746
+ }
747
+ if (poMatchesLocal(nm, "disp-formula")) {
748
+ const t = (poText(poChildren(ch)) || poText(ch) || "").trim();
749
+ if (t)
750
+ blocks.push({ kind: "paragraph", text: t });
751
+ continue;
752
+ }
753
+ }
754
+ // Derive legacy arrays from blocks
755
+ if (blocks.length) {
756
+ for (const b of blocks) {
757
+ if (b.kind === "paragraph") {
758
+ paragraphs.push(b.text);
759
+ if (b.xml)
760
+ paragraphs_xml.push(b.xml);
761
+ if (b.xml_minimal)
762
+ paragraphs_xml_minimal.push(b.xml_minimal);
763
+ }
764
+ }
765
+ }
766
+ }
767
+ }
768
+ if (!paragraphs.length) {
769
+ for (const p of nsArray(sec, "p")) {
770
+ const t = getText(p);
771
+ if (t)
772
+ paragraphs.push(t);
773
+ }
774
+ if (!paragraphs.length) {
775
+ const t = getText(sec);
776
+ if (t)
777
+ paragraphs.push(t);
778
+ }
779
+ }
780
+ if (!paragraphs.length)
781
+ continue;
782
+ const section = { id, sec_type, title: titleRaw };
783
+ if (norm)
784
+ section.normalized_title = norm;
785
+ if (cat)
786
+ section.category = cat;
787
+ if (blocks.length)
788
+ section.blocks = blocks;
789
+ if (paragraphs.length)
790
+ section.paragraphs = paragraphs;
791
+ if (paragraphs_xml.length)
792
+ section.paragraphs_xml = paragraphs_xml;
793
+ if (paragraphs_xml_minimal.length)
794
+ section.paragraphs_xml_minimal = paragraphs_xml_minimal;
795
+ out.push(section);
796
+ }
797
+ }
798
+ catch { }
799
+ return out;
800
+ }
801
+ //# sourceMappingURL=back.js.map