@linloir/limr 0.0.0-stage → 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 (421) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +197 -2
  3. package/benchmarks/results/browser.json +237 -0
  4. package/benchmarks/results/node.json +75 -0
  5. package/benchmarks/results/selection.json +172 -0
  6. package/dist/THIRD_PARTY_LICENSES.txt +117 -0
  7. package/dist/base.css +451 -0
  8. package/dist/chunk-65V5OZ4G.js +3070 -0
  9. package/dist/chunk-65V5OZ4G.js.map +1 -0
  10. package/dist/chunk-6N6TFHEN.js +83 -0
  11. package/dist/chunk-6N6TFHEN.js.map +1 -0
  12. package/dist/chunk-7JF5HHVF.js +465 -0
  13. package/dist/chunk-7JF5HHVF.js.map +1 -0
  14. package/dist/chunk-ETHLPBKQ.js +1193 -0
  15. package/dist/chunk-ETHLPBKQ.js.map +1 -0
  16. package/dist/chunk-V2OG4Y3F.js +1 -0
  17. package/dist/chunk-V2OG4Y3F.js.map +1 -0
  18. package/dist/core/index.d.ts +54 -0
  19. package/dist/core/index.js +37 -0
  20. package/dist/core/index.js.map +1 -0
  21. package/dist/engine-43u8B4yt.d.ts +172 -0
  22. package/dist/extensions/index.d.ts +130 -0
  23. package/dist/extensions/index.js +50 -0
  24. package/dist/extensions/index.js.map +1 -0
  25. package/dist/fonts/KaTeX_AMS-Regular.ttf +0 -0
  26. package/dist/fonts/KaTeX_AMS-Regular.woff +0 -0
  27. package/dist/fonts/KaTeX_AMS-Regular.woff2 +0 -0
  28. package/dist/fonts/KaTeX_Caligraphic-Bold.ttf +0 -0
  29. package/dist/fonts/KaTeX_Caligraphic-Bold.woff +0 -0
  30. package/dist/fonts/KaTeX_Caligraphic-Bold.woff2 +0 -0
  31. package/dist/fonts/KaTeX_Caligraphic-Regular.ttf +0 -0
  32. package/dist/fonts/KaTeX_Caligraphic-Regular.woff +0 -0
  33. package/dist/fonts/KaTeX_Caligraphic-Regular.woff2 +0 -0
  34. package/dist/fonts/KaTeX_Fraktur-Bold.ttf +0 -0
  35. package/dist/fonts/KaTeX_Fraktur-Bold.woff +0 -0
  36. package/dist/fonts/KaTeX_Fraktur-Bold.woff2 +0 -0
  37. package/dist/fonts/KaTeX_Fraktur-Regular.ttf +0 -0
  38. package/dist/fonts/KaTeX_Fraktur-Regular.woff +0 -0
  39. package/dist/fonts/KaTeX_Fraktur-Regular.woff2 +0 -0
  40. package/dist/fonts/KaTeX_Main-Bold.ttf +0 -0
  41. package/dist/fonts/KaTeX_Main-Bold.woff +0 -0
  42. package/dist/fonts/KaTeX_Main-Bold.woff2 +0 -0
  43. package/dist/fonts/KaTeX_Main-BoldItalic.ttf +0 -0
  44. package/dist/fonts/KaTeX_Main-BoldItalic.woff +0 -0
  45. package/dist/fonts/KaTeX_Main-BoldItalic.woff2 +0 -0
  46. package/dist/fonts/KaTeX_Main-Italic.ttf +0 -0
  47. package/dist/fonts/KaTeX_Main-Italic.woff +0 -0
  48. package/dist/fonts/KaTeX_Main-Italic.woff2 +0 -0
  49. package/dist/fonts/KaTeX_Main-Regular.ttf +0 -0
  50. package/dist/fonts/KaTeX_Main-Regular.woff +0 -0
  51. package/dist/fonts/KaTeX_Main-Regular.woff2 +0 -0
  52. package/dist/fonts/KaTeX_Math-BoldItalic.ttf +0 -0
  53. package/dist/fonts/KaTeX_Math-BoldItalic.woff +0 -0
  54. package/dist/fonts/KaTeX_Math-BoldItalic.woff2 +0 -0
  55. package/dist/fonts/KaTeX_Math-Italic.ttf +0 -0
  56. package/dist/fonts/KaTeX_Math-Italic.woff +0 -0
  57. package/dist/fonts/KaTeX_Math-Italic.woff2 +0 -0
  58. package/dist/fonts/KaTeX_SansSerif-Bold.ttf +0 -0
  59. package/dist/fonts/KaTeX_SansSerif-Bold.woff +0 -0
  60. package/dist/fonts/KaTeX_SansSerif-Bold.woff2 +0 -0
  61. package/dist/fonts/KaTeX_SansSerif-Italic.ttf +0 -0
  62. package/dist/fonts/KaTeX_SansSerif-Italic.woff +0 -0
  63. package/dist/fonts/KaTeX_SansSerif-Italic.woff2 +0 -0
  64. package/dist/fonts/KaTeX_SansSerif-Regular.ttf +0 -0
  65. package/dist/fonts/KaTeX_SansSerif-Regular.woff +0 -0
  66. package/dist/fonts/KaTeX_SansSerif-Regular.woff2 +0 -0
  67. package/dist/fonts/KaTeX_Script-Regular.ttf +0 -0
  68. package/dist/fonts/KaTeX_Script-Regular.woff +0 -0
  69. package/dist/fonts/KaTeX_Script-Regular.woff2 +0 -0
  70. package/dist/fonts/KaTeX_Size1-Regular.ttf +0 -0
  71. package/dist/fonts/KaTeX_Size1-Regular.woff +0 -0
  72. package/dist/fonts/KaTeX_Size1-Regular.woff2 +0 -0
  73. package/dist/fonts/KaTeX_Size2-Regular.ttf +0 -0
  74. package/dist/fonts/KaTeX_Size2-Regular.woff +0 -0
  75. package/dist/fonts/KaTeX_Size2-Regular.woff2 +0 -0
  76. package/dist/fonts/KaTeX_Size3-Regular.ttf +0 -0
  77. package/dist/fonts/KaTeX_Size3-Regular.woff +0 -0
  78. package/dist/fonts/KaTeX_Size3-Regular.woff2 +0 -0
  79. package/dist/fonts/KaTeX_Size4-Regular.ttf +0 -0
  80. package/dist/fonts/KaTeX_Size4-Regular.woff +0 -0
  81. package/dist/fonts/KaTeX_Size4-Regular.woff2 +0 -0
  82. package/dist/fonts/KaTeX_Typewriter-Regular.ttf +0 -0
  83. package/dist/fonts/KaTeX_Typewriter-Regular.woff +0 -0
  84. package/dist/fonts/KaTeX_Typewriter-Regular.woff2 +0 -0
  85. package/dist/fonts/LICENSE.txt +93 -0
  86. package/dist/fonts/manifest.json +2204 -0
  87. package/dist/fonts/maple-7.9-bold-005-5530d8c1d6.woff2 +0 -0
  88. package/dist/fonts/maple-7.9-bold-00f-1179d800a7.woff2 +0 -0
  89. package/dist/fonts/maple-7.9-bold-010-9974a942b1.woff2 +0 -0
  90. package/dist/fonts/maple-7.9-bold-011-9b9230baf2.woff2 +0 -0
  91. package/dist/fonts/maple-7.9-bold-012-c2545292b1.woff2 +0 -0
  92. package/dist/fonts/maple-7.9-bold-013-877b19fe05.woff2 +0 -0
  93. package/dist/fonts/maple-7.9-bold-014-6acf4a4e92.woff2 +0 -0
  94. package/dist/fonts/maple-7.9-bold-015-c889146da3.woff2 +0 -0
  95. package/dist/fonts/maple-7.9-bold-018-419ad5f31f.woff2 +0 -0
  96. package/dist/fonts/maple-7.9-bold-027-dd414483da.woff2 +0 -0
  97. package/dist/fonts/maple-7.9-bold-028-263744fbc7.woff2 +0 -0
  98. package/dist/fonts/maple-7.9-bold-029-ae3a163d8b.woff2 +0 -0
  99. package/dist/fonts/maple-7.9-bold-02a-515f0a82c2.woff2 +0 -0
  100. package/dist/fonts/maple-7.9-bold-02b-0823c5133d.woff2 +0 -0
  101. package/dist/fonts/maple-7.9-bold-02c-296fd5db38.woff2 +0 -0
  102. package/dist/fonts/maple-7.9-bold-02d-0bb4734363.woff2 +0 -0
  103. package/dist/fonts/maple-7.9-bold-02e-25415fed50.woff2 +0 -0
  104. package/dist/fonts/maple-7.9-bold-02f-19ed79a84e.woff2 +0 -0
  105. package/dist/fonts/maple-7.9-bold-030-21962a0327.woff2 +0 -0
  106. package/dist/fonts/maple-7.9-bold-031-d216fc0d68.woff2 +0 -0
  107. package/dist/fonts/maple-7.9-bold-032-d90ba34901.woff2 +0 -0
  108. package/dist/fonts/maple-7.9-bold-033-55ea37ea00.woff2 +0 -0
  109. package/dist/fonts/maple-7.9-bold-034-bc8649f808.woff2 +0 -0
  110. package/dist/fonts/maple-7.9-bold-035-03604fe40b.woff2 +0 -0
  111. package/dist/fonts/maple-7.9-bold-036-44fc7f77b2.woff2 +0 -0
  112. package/dist/fonts/maple-7.9-bold-037-8a1440f155.woff2 +0 -0
  113. package/dist/fonts/maple-7.9-bold-038-c65a618d5c.woff2 +0 -0
  114. package/dist/fonts/maple-7.9-bold-039-be05db966d.woff2 +0 -0
  115. package/dist/fonts/maple-7.9-bold-03a-ca3a10002d.woff2 +0 -0
  116. package/dist/fonts/maple-7.9-bold-03b-067b32e10b.woff2 +0 -0
  117. package/dist/fonts/maple-7.9-bold-03c-4da4f84530.woff2 +0 -0
  118. package/dist/fonts/maple-7.9-bold-03d-f0fe6a68c8.woff2 +0 -0
  119. package/dist/fonts/maple-7.9-bold-03e-0e97f89433.woff2 +0 -0
  120. package/dist/fonts/maple-7.9-bold-03f-3289a5e3bc.woff2 +0 -0
  121. package/dist/fonts/maple-7.9-bold-040-232dcd0d7b.woff2 +0 -0
  122. package/dist/fonts/maple-7.9-bold-041-e25e9a9c41.woff2 +0 -0
  123. package/dist/fonts/maple-7.9-bold-042-d64a2b1824.woff2 +0 -0
  124. package/dist/fonts/maple-7.9-bold-043-2d01cf5e52.woff2 +0 -0
  125. package/dist/fonts/maple-7.9-bold-044-0ab808b5f1.woff2 +0 -0
  126. package/dist/fonts/maple-7.9-bold-045-e41dc814b4.woff2 +0 -0
  127. package/dist/fonts/maple-7.9-bold-046-d5fe26344d.woff2 +0 -0
  128. package/dist/fonts/maple-7.9-bold-047-f322ded671.woff2 +0 -0
  129. package/dist/fonts/maple-7.9-bold-048-0cdcf7257f.woff2 +0 -0
  130. package/dist/fonts/maple-7.9-bold-049-aa280ca08a.woff2 +0 -0
  131. package/dist/fonts/maple-7.9-bold-04a-f51ad4d92c.woff2 +0 -0
  132. package/dist/fonts/maple-7.9-bold-04b-4e8c6fa3ee.woff2 +0 -0
  133. package/dist/fonts/maple-7.9-bold-04c-9bfdf4d743.woff2 +0 -0
  134. package/dist/fonts/maple-7.9-bold-04d-83ac1f5bb3.woff2 +0 -0
  135. package/dist/fonts/maple-7.9-bold-04e-bcec89804a.woff2 +0 -0
  136. package/dist/fonts/maple-7.9-bold-04f-d31e83b6ce.woff2 +0 -0
  137. package/dist/fonts/maple-7.9-bold-070-8a3b0fdf98.woff2 +0 -0
  138. package/dist/fonts/maple-7.9-bold-071-5bee0a62c4.woff2 +0 -0
  139. package/dist/fonts/maple-7.9-bold-072-97d891eee4.woff2 +0 -0
  140. package/dist/fonts/maple-7.9-bold-073-4d4c36aca0.woff2 +0 -0
  141. package/dist/fonts/maple-7.9-bold-074-6d3cc01e90.woff2 +0 -0
  142. package/dist/fonts/maple-7.9-bold-075-eab42ad657.woff2 +0 -0
  143. package/dist/fonts/maple-7.9-bold-076-2b1f5c4a42.woff2 +0 -0
  144. package/dist/fonts/maple-7.9-bold-077-1db0d50873.woff2 +0 -0
  145. package/dist/fonts/maple-7.9-bold-078-bc6994a28f.woff2 +0 -0
  146. package/dist/fonts/maple-7.9-bold-079-ad6c1757ce.woff2 +0 -0
  147. package/dist/fonts/maple-7.9-bold-07a-d08ed2b87d.woff2 +0 -0
  148. package/dist/fonts/maple-7.9-bold-07f-2f4af46cc6.woff2 +0 -0
  149. package/dist/fonts/maple-7.9-bold-0fc-42ed90884c.woff2 +0 -0
  150. package/dist/fonts/maple-7.9-bold-780-261fac1b24.woff2 +0 -0
  151. package/dist/fonts/maple-7.9-bold-781-377319a91b.woff2 +0 -0
  152. package/dist/fonts/maple-7.9-bold-782-3106f0be62.woff2 +0 -0
  153. package/dist/fonts/maple-7.9-bold-783-74fbfa8648.woff2 +0 -0
  154. package/dist/fonts/maple-7.9-bold-784-8570270664.woff2 +0 -0
  155. package/dist/fonts/maple-7.9-bold-785-cee8de1ded.woff2 +0 -0
  156. package/dist/fonts/maple-7.9-bold-786-5ab5ff7149.woff2 +0 -0
  157. package/dist/fonts/maple-7.9-bold-787-844b4c4373.woff2 +0 -0
  158. package/dist/fonts/maple-7.9-bold-788-01731198ab.woff2 +0 -0
  159. package/dist/fonts/maple-7.9-bold-789-f4c75fa806.woff2 +0 -0
  160. package/dist/fonts/maple-7.9-bold-78a-4370321ec6.woff2 +0 -0
  161. package/dist/fonts/maple-7.9-bold-78b-5cd412b56f.woff2 +0 -0
  162. package/dist/fonts/maple-7.9-bold-78c-f88e331085.woff2 +0 -0
  163. package/dist/fonts/maple-7.9-bold-78d-1b9b77f6e8.woff2 +0 -0
  164. package/dist/fonts/maple-7.9-bold-latin-3b4b2831f3.woff2 +0 -0
  165. package/dist/fonts/maple-7.9-bolditalic-005-d59fef8639.woff2 +0 -0
  166. package/dist/fonts/maple-7.9-bolditalic-00f-1bbda7af69.woff2 +0 -0
  167. package/dist/fonts/maple-7.9-bolditalic-010-5cdd4b46a7.woff2 +0 -0
  168. package/dist/fonts/maple-7.9-bolditalic-011-0d1f1ae687.woff2 +0 -0
  169. package/dist/fonts/maple-7.9-bolditalic-012-4ceb000b2e.woff2 +0 -0
  170. package/dist/fonts/maple-7.9-bolditalic-013-ad0a4f4313.woff2 +0 -0
  171. package/dist/fonts/maple-7.9-bolditalic-014-94d54b71b3.woff2 +0 -0
  172. package/dist/fonts/maple-7.9-bolditalic-015-7aede280da.woff2 +0 -0
  173. package/dist/fonts/maple-7.9-bolditalic-018-f21221b1c2.woff2 +0 -0
  174. package/dist/fonts/maple-7.9-bolditalic-027-d23d0e80a4.woff2 +0 -0
  175. package/dist/fonts/maple-7.9-bolditalic-028-23bd6f24df.woff2 +0 -0
  176. package/dist/fonts/maple-7.9-bolditalic-029-c481c0ad50.woff2 +0 -0
  177. package/dist/fonts/maple-7.9-bolditalic-02a-1c134be68e.woff2 +0 -0
  178. package/dist/fonts/maple-7.9-bolditalic-02b-3feb29ecfd.woff2 +0 -0
  179. package/dist/fonts/maple-7.9-bolditalic-02c-de8cc5a063.woff2 +0 -0
  180. package/dist/fonts/maple-7.9-bolditalic-02d-ea25c21fad.woff2 +0 -0
  181. package/dist/fonts/maple-7.9-bolditalic-02e-e68d6bd335.woff2 +0 -0
  182. package/dist/fonts/maple-7.9-bolditalic-02f-c88d1e92dc.woff2 +0 -0
  183. package/dist/fonts/maple-7.9-bolditalic-030-f26fefe87e.woff2 +0 -0
  184. package/dist/fonts/maple-7.9-bolditalic-031-f2aa1b8e22.woff2 +0 -0
  185. package/dist/fonts/maple-7.9-bolditalic-032-c4fafc4aa6.woff2 +0 -0
  186. package/dist/fonts/maple-7.9-bolditalic-033-288a1639ca.woff2 +0 -0
  187. package/dist/fonts/maple-7.9-bolditalic-034-7c982125bc.woff2 +0 -0
  188. package/dist/fonts/maple-7.9-bolditalic-035-fd1575dea2.woff2 +0 -0
  189. package/dist/fonts/maple-7.9-bolditalic-036-f6bf406353.woff2 +0 -0
  190. package/dist/fonts/maple-7.9-bolditalic-037-8ac1466916.woff2 +0 -0
  191. package/dist/fonts/maple-7.9-bolditalic-038-e9f7fed6a6.woff2 +0 -0
  192. package/dist/fonts/maple-7.9-bolditalic-039-6f90d42310.woff2 +0 -0
  193. package/dist/fonts/maple-7.9-bolditalic-03a-30c9409a7e.woff2 +0 -0
  194. package/dist/fonts/maple-7.9-bolditalic-03b-4f1741e9e9.woff2 +0 -0
  195. package/dist/fonts/maple-7.9-bolditalic-03c-6551c74e78.woff2 +0 -0
  196. package/dist/fonts/maple-7.9-bolditalic-03d-c8e2b07106.woff2 +0 -0
  197. package/dist/fonts/maple-7.9-bolditalic-03e-c3e98613d4.woff2 +0 -0
  198. package/dist/fonts/maple-7.9-bolditalic-03f-f1c580bad4.woff2 +0 -0
  199. package/dist/fonts/maple-7.9-bolditalic-040-32e8260076.woff2 +0 -0
  200. package/dist/fonts/maple-7.9-bolditalic-041-39805a0ed7.woff2 +0 -0
  201. package/dist/fonts/maple-7.9-bolditalic-042-13b4d84cd3.woff2 +0 -0
  202. package/dist/fonts/maple-7.9-bolditalic-043-d85780d0bd.woff2 +0 -0
  203. package/dist/fonts/maple-7.9-bolditalic-044-1b5eb624d7.woff2 +0 -0
  204. package/dist/fonts/maple-7.9-bolditalic-045-ad0b4f8762.woff2 +0 -0
  205. package/dist/fonts/maple-7.9-bolditalic-046-9966021b3a.woff2 +0 -0
  206. package/dist/fonts/maple-7.9-bolditalic-047-100d4f6f4e.woff2 +0 -0
  207. package/dist/fonts/maple-7.9-bolditalic-048-a0a1e8b29c.woff2 +0 -0
  208. package/dist/fonts/maple-7.9-bolditalic-049-0806f9b3cc.woff2 +0 -0
  209. package/dist/fonts/maple-7.9-bolditalic-04a-28fdef78b3.woff2 +0 -0
  210. package/dist/fonts/maple-7.9-bolditalic-04b-6e93ef0086.woff2 +0 -0
  211. package/dist/fonts/maple-7.9-bolditalic-04c-50b8da6282.woff2 +0 -0
  212. package/dist/fonts/maple-7.9-bolditalic-04d-f93277723d.woff2 +0 -0
  213. package/dist/fonts/maple-7.9-bolditalic-04e-72e2644690.woff2 +0 -0
  214. package/dist/fonts/maple-7.9-bolditalic-04f-4f234f1802.woff2 +0 -0
  215. package/dist/fonts/maple-7.9-bolditalic-070-a3658a8a23.woff2 +0 -0
  216. package/dist/fonts/maple-7.9-bolditalic-071-4987e49732.woff2 +0 -0
  217. package/dist/fonts/maple-7.9-bolditalic-072-e587fa72cd.woff2 +0 -0
  218. package/dist/fonts/maple-7.9-bolditalic-073-2aca01fdf6.woff2 +0 -0
  219. package/dist/fonts/maple-7.9-bolditalic-074-ae89f99a60.woff2 +0 -0
  220. package/dist/fonts/maple-7.9-bolditalic-075-5a77191665.woff2 +0 -0
  221. package/dist/fonts/maple-7.9-bolditalic-076-4c54a87277.woff2 +0 -0
  222. package/dist/fonts/maple-7.9-bolditalic-077-e47dce25ee.woff2 +0 -0
  223. package/dist/fonts/maple-7.9-bolditalic-078-b0b720dab6.woff2 +0 -0
  224. package/dist/fonts/maple-7.9-bolditalic-079-316ee96f6a.woff2 +0 -0
  225. package/dist/fonts/maple-7.9-bolditalic-07a-b10ccb8107.woff2 +0 -0
  226. package/dist/fonts/maple-7.9-bolditalic-07d-5667cb3be1.woff2 +0 -0
  227. package/dist/fonts/maple-7.9-bolditalic-07f-2ac6735ff8.woff2 +0 -0
  228. package/dist/fonts/maple-7.9-bolditalic-0fc-52171ca01e.woff2 +0 -0
  229. package/dist/fonts/maple-7.9-bolditalic-780-3c090c5f89.woff2 +0 -0
  230. package/dist/fonts/maple-7.9-bolditalic-781-ca4077b4fa.woff2 +0 -0
  231. package/dist/fonts/maple-7.9-bolditalic-782-42c3d52206.woff2 +0 -0
  232. package/dist/fonts/maple-7.9-bolditalic-783-d72840dd37.woff2 +0 -0
  233. package/dist/fonts/maple-7.9-bolditalic-784-b9ca097e50.woff2 +0 -0
  234. package/dist/fonts/maple-7.9-bolditalic-785-b81dec6af9.woff2 +0 -0
  235. package/dist/fonts/maple-7.9-bolditalic-786-76c266f6f5.woff2 +0 -0
  236. package/dist/fonts/maple-7.9-bolditalic-787-403bd73766.woff2 +0 -0
  237. package/dist/fonts/maple-7.9-bolditalic-788-71a4b8c2c5.woff2 +0 -0
  238. package/dist/fonts/maple-7.9-bolditalic-789-94527f3fa4.woff2 +0 -0
  239. package/dist/fonts/maple-7.9-bolditalic-78a-81918568b8.woff2 +0 -0
  240. package/dist/fonts/maple-7.9-bolditalic-78b-d0302b4bfe.woff2 +0 -0
  241. package/dist/fonts/maple-7.9-bolditalic-78c-e864792049.woff2 +0 -0
  242. package/dist/fonts/maple-7.9-bolditalic-78d-105ff69bf4.woff2 +0 -0
  243. package/dist/fonts/maple-7.9-bolditalic-latin-96412d165b.woff2 +0 -0
  244. package/dist/fonts/maple-7.9-italic-005-23b09473f8.woff2 +0 -0
  245. package/dist/fonts/maple-7.9-italic-00f-e9bf4dd93c.woff2 +0 -0
  246. package/dist/fonts/maple-7.9-italic-010-22933d6d77.woff2 +0 -0
  247. package/dist/fonts/maple-7.9-italic-011-71b0157ddc.woff2 +0 -0
  248. package/dist/fonts/maple-7.9-italic-012-b751ab3752.woff2 +0 -0
  249. package/dist/fonts/maple-7.9-italic-013-530b1d3f8b.woff2 +0 -0
  250. package/dist/fonts/maple-7.9-italic-014-0e842f6749.woff2 +0 -0
  251. package/dist/fonts/maple-7.9-italic-015-642211b03a.woff2 +0 -0
  252. package/dist/fonts/maple-7.9-italic-018-0c5b0001c6.woff2 +0 -0
  253. package/dist/fonts/maple-7.9-italic-027-9a09afbbb1.woff2 +0 -0
  254. package/dist/fonts/maple-7.9-italic-028-93fea67326.woff2 +0 -0
  255. package/dist/fonts/maple-7.9-italic-029-7d7627d4cc.woff2 +0 -0
  256. package/dist/fonts/maple-7.9-italic-02a-88e76d051b.woff2 +0 -0
  257. package/dist/fonts/maple-7.9-italic-02b-7d9219748b.woff2 +0 -0
  258. package/dist/fonts/maple-7.9-italic-02c-049df19d84.woff2 +0 -0
  259. package/dist/fonts/maple-7.9-italic-02d-663fc73c6e.woff2 +0 -0
  260. package/dist/fonts/maple-7.9-italic-02e-a98ed33998.woff2 +0 -0
  261. package/dist/fonts/maple-7.9-italic-02f-8ef9d93d09.woff2 +0 -0
  262. package/dist/fonts/maple-7.9-italic-030-74885d994d.woff2 +0 -0
  263. package/dist/fonts/maple-7.9-italic-031-4cf66c5d65.woff2 +0 -0
  264. package/dist/fonts/maple-7.9-italic-032-a608b7aed4.woff2 +0 -0
  265. package/dist/fonts/maple-7.9-italic-033-2978f66e55.woff2 +0 -0
  266. package/dist/fonts/maple-7.9-italic-034-38f7a0bf87.woff2 +0 -0
  267. package/dist/fonts/maple-7.9-italic-035-5cc45cd3b7.woff2 +0 -0
  268. package/dist/fonts/maple-7.9-italic-036-ca92d327e5.woff2 +0 -0
  269. package/dist/fonts/maple-7.9-italic-037-f887681c7d.woff2 +0 -0
  270. package/dist/fonts/maple-7.9-italic-038-06150b88f8.woff2 +0 -0
  271. package/dist/fonts/maple-7.9-italic-039-761da333b7.woff2 +0 -0
  272. package/dist/fonts/maple-7.9-italic-03a-1408ddaf2c.woff2 +0 -0
  273. package/dist/fonts/maple-7.9-italic-03b-1542b3b67c.woff2 +0 -0
  274. package/dist/fonts/maple-7.9-italic-03c-479f2f5011.woff2 +0 -0
  275. package/dist/fonts/maple-7.9-italic-03d-0f10590b11.woff2 +0 -0
  276. package/dist/fonts/maple-7.9-italic-03e-8b93e0ee0e.woff2 +0 -0
  277. package/dist/fonts/maple-7.9-italic-03f-2bd8815e3e.woff2 +0 -0
  278. package/dist/fonts/maple-7.9-italic-040-b85023679a.woff2 +0 -0
  279. package/dist/fonts/maple-7.9-italic-041-eb881b7b92.woff2 +0 -0
  280. package/dist/fonts/maple-7.9-italic-042-01490a139e.woff2 +0 -0
  281. package/dist/fonts/maple-7.9-italic-043-ffb21b6c4c.woff2 +0 -0
  282. package/dist/fonts/maple-7.9-italic-044-05cd1a1b14.woff2 +0 -0
  283. package/dist/fonts/maple-7.9-italic-045-1270935363.woff2 +0 -0
  284. package/dist/fonts/maple-7.9-italic-046-857077eab1.woff2 +0 -0
  285. package/dist/fonts/maple-7.9-italic-047-ca57774cc3.woff2 +0 -0
  286. package/dist/fonts/maple-7.9-italic-048-20969d6307.woff2 +0 -0
  287. package/dist/fonts/maple-7.9-italic-049-4066aa1a18.woff2 +0 -0
  288. package/dist/fonts/maple-7.9-italic-04a-1ed360d580.woff2 +0 -0
  289. package/dist/fonts/maple-7.9-italic-04b-2eba62d76b.woff2 +0 -0
  290. package/dist/fonts/maple-7.9-italic-04c-2f4effc460.woff2 +0 -0
  291. package/dist/fonts/maple-7.9-italic-04d-d858c0a9c1.woff2 +0 -0
  292. package/dist/fonts/maple-7.9-italic-04e-a19eb0289f.woff2 +0 -0
  293. package/dist/fonts/maple-7.9-italic-04f-8addde15f2.woff2 +0 -0
  294. package/dist/fonts/maple-7.9-italic-070-f0bd641f1c.woff2 +0 -0
  295. package/dist/fonts/maple-7.9-italic-071-e6ac564431.woff2 +0 -0
  296. package/dist/fonts/maple-7.9-italic-072-e6fea65bca.woff2 +0 -0
  297. package/dist/fonts/maple-7.9-italic-073-71621c00dc.woff2 +0 -0
  298. package/dist/fonts/maple-7.9-italic-074-4bd488962a.woff2 +0 -0
  299. package/dist/fonts/maple-7.9-italic-075-2838d95bd6.woff2 +0 -0
  300. package/dist/fonts/maple-7.9-italic-076-94e02ecc03.woff2 +0 -0
  301. package/dist/fonts/maple-7.9-italic-077-32c536ab6b.woff2 +0 -0
  302. package/dist/fonts/maple-7.9-italic-078-18256447bd.woff2 +0 -0
  303. package/dist/fonts/maple-7.9-italic-079-7a735e61cf.woff2 +0 -0
  304. package/dist/fonts/maple-7.9-italic-07a-2b57a6a905.woff2 +0 -0
  305. package/dist/fonts/maple-7.9-italic-07d-8ba1bbfb50.woff2 +0 -0
  306. package/dist/fonts/maple-7.9-italic-07f-0240d80c69.woff2 +0 -0
  307. package/dist/fonts/maple-7.9-italic-0fc-e5b20a692e.woff2 +0 -0
  308. package/dist/fonts/maple-7.9-italic-780-093cc90a9b.woff2 +0 -0
  309. package/dist/fonts/maple-7.9-italic-781-f6ec357f6d.woff2 +0 -0
  310. package/dist/fonts/maple-7.9-italic-782-5ca2ef4ddd.woff2 +0 -0
  311. package/dist/fonts/maple-7.9-italic-783-7450baabee.woff2 +0 -0
  312. package/dist/fonts/maple-7.9-italic-784-14a93cc4bd.woff2 +0 -0
  313. package/dist/fonts/maple-7.9-italic-785-d62fb8b4d7.woff2 +0 -0
  314. package/dist/fonts/maple-7.9-italic-786-1d2959dc83.woff2 +0 -0
  315. package/dist/fonts/maple-7.9-italic-787-70ae947136.woff2 +0 -0
  316. package/dist/fonts/maple-7.9-italic-788-cf1f156ebf.woff2 +0 -0
  317. package/dist/fonts/maple-7.9-italic-789-f0b79f9680.woff2 +0 -0
  318. package/dist/fonts/maple-7.9-italic-78a-5a53fd7870.woff2 +0 -0
  319. package/dist/fonts/maple-7.9-italic-78b-40be093bfd.woff2 +0 -0
  320. package/dist/fonts/maple-7.9-italic-78c-3b11646f8e.woff2 +0 -0
  321. package/dist/fonts/maple-7.9-italic-78d-b13ed8c48b.woff2 +0 -0
  322. package/dist/fonts/maple-7.9-italic-latin-befeb2b610.woff2 +0 -0
  323. package/dist/fonts/maple-7.9-regular-005-90bff107ac.woff2 +0 -0
  324. package/dist/fonts/maple-7.9-regular-00f-001e503e53.woff2 +0 -0
  325. package/dist/fonts/maple-7.9-regular-010-374da1ebb4.woff2 +0 -0
  326. package/dist/fonts/maple-7.9-regular-011-8f91fcc9e7.woff2 +0 -0
  327. package/dist/fonts/maple-7.9-regular-012-e4ec3016ef.woff2 +0 -0
  328. package/dist/fonts/maple-7.9-regular-013-e779e13a12.woff2 +0 -0
  329. package/dist/fonts/maple-7.9-regular-014-6b833ad501.woff2 +0 -0
  330. package/dist/fonts/maple-7.9-regular-015-4e058c4c42.woff2 +0 -0
  331. package/dist/fonts/maple-7.9-regular-018-6f776bc19b.woff2 +0 -0
  332. package/dist/fonts/maple-7.9-regular-027-92c0be3439.woff2 +0 -0
  333. package/dist/fonts/maple-7.9-regular-028-154c8c3039.woff2 +0 -0
  334. package/dist/fonts/maple-7.9-regular-029-9d88470aca.woff2 +0 -0
  335. package/dist/fonts/maple-7.9-regular-02a-7a94cb26f2.woff2 +0 -0
  336. package/dist/fonts/maple-7.9-regular-02b-1725b841c2.woff2 +0 -0
  337. package/dist/fonts/maple-7.9-regular-02c-e080c435d6.woff2 +0 -0
  338. package/dist/fonts/maple-7.9-regular-02d-a6461c4708.woff2 +0 -0
  339. package/dist/fonts/maple-7.9-regular-02e-2e55d9b957.woff2 +0 -0
  340. package/dist/fonts/maple-7.9-regular-02f-858a76fa1f.woff2 +0 -0
  341. package/dist/fonts/maple-7.9-regular-030-bbbe80f8ad.woff2 +0 -0
  342. package/dist/fonts/maple-7.9-regular-031-cafc1258ad.woff2 +0 -0
  343. package/dist/fonts/maple-7.9-regular-032-0ca83ecceb.woff2 +0 -0
  344. package/dist/fonts/maple-7.9-regular-033-6cb995f2e7.woff2 +0 -0
  345. package/dist/fonts/maple-7.9-regular-034-5877222be6.woff2 +0 -0
  346. package/dist/fonts/maple-7.9-regular-035-988d8f2d26.woff2 +0 -0
  347. package/dist/fonts/maple-7.9-regular-036-e91853e3ca.woff2 +0 -0
  348. package/dist/fonts/maple-7.9-regular-037-3eed60f359.woff2 +0 -0
  349. package/dist/fonts/maple-7.9-regular-038-5681f42a4a.woff2 +0 -0
  350. package/dist/fonts/maple-7.9-regular-039-07036fe444.woff2 +0 -0
  351. package/dist/fonts/maple-7.9-regular-03a-5495eead93.woff2 +0 -0
  352. package/dist/fonts/maple-7.9-regular-03b-d07b1d6c1e.woff2 +0 -0
  353. package/dist/fonts/maple-7.9-regular-03c-6291400ee0.woff2 +0 -0
  354. package/dist/fonts/maple-7.9-regular-03d-3787a51772.woff2 +0 -0
  355. package/dist/fonts/maple-7.9-regular-03e-ce4d945844.woff2 +0 -0
  356. package/dist/fonts/maple-7.9-regular-03f-95e98b329c.woff2 +0 -0
  357. package/dist/fonts/maple-7.9-regular-040-693b769fe8.woff2 +0 -0
  358. package/dist/fonts/maple-7.9-regular-041-7b436d2c09.woff2 +0 -0
  359. package/dist/fonts/maple-7.9-regular-042-9ad884cd73.woff2 +0 -0
  360. package/dist/fonts/maple-7.9-regular-043-372231e8e2.woff2 +0 -0
  361. package/dist/fonts/maple-7.9-regular-044-9922b540b1.woff2 +0 -0
  362. package/dist/fonts/maple-7.9-regular-045-8a88a91c22.woff2 +0 -0
  363. package/dist/fonts/maple-7.9-regular-046-82859ede10.woff2 +0 -0
  364. package/dist/fonts/maple-7.9-regular-047-6532babd62.woff2 +0 -0
  365. package/dist/fonts/maple-7.9-regular-048-abfdc5d7ce.woff2 +0 -0
  366. package/dist/fonts/maple-7.9-regular-049-adb7fa9ed3.woff2 +0 -0
  367. package/dist/fonts/maple-7.9-regular-04a-f3f794b1cb.woff2 +0 -0
  368. package/dist/fonts/maple-7.9-regular-04b-715211b8dd.woff2 +0 -0
  369. package/dist/fonts/maple-7.9-regular-04c-c6f978d10d.woff2 +0 -0
  370. package/dist/fonts/maple-7.9-regular-04d-61019a1c8f.woff2 +0 -0
  371. package/dist/fonts/maple-7.9-regular-04e-806d6efe85.woff2 +0 -0
  372. package/dist/fonts/maple-7.9-regular-04f-99d19aa8db.woff2 +0 -0
  373. package/dist/fonts/maple-7.9-regular-070-e94ba9445d.woff2 +0 -0
  374. package/dist/fonts/maple-7.9-regular-071-057314b533.woff2 +0 -0
  375. package/dist/fonts/maple-7.9-regular-072-a7699beb84.woff2 +0 -0
  376. package/dist/fonts/maple-7.9-regular-073-ebe1bd9ef4.woff2 +0 -0
  377. package/dist/fonts/maple-7.9-regular-074-722db38100.woff2 +0 -0
  378. package/dist/fonts/maple-7.9-regular-075-150ff7187b.woff2 +0 -0
  379. package/dist/fonts/maple-7.9-regular-076-c14595e715.woff2 +0 -0
  380. package/dist/fonts/maple-7.9-regular-077-6c88302a32.woff2 +0 -0
  381. package/dist/fonts/maple-7.9-regular-078-549b294c78.woff2 +0 -0
  382. package/dist/fonts/maple-7.9-regular-079-5131c42759.woff2 +0 -0
  383. package/dist/fonts/maple-7.9-regular-07a-c0dad221b5.woff2 +0 -0
  384. package/dist/fonts/maple-7.9-regular-07f-5cf5ebe065.woff2 +0 -0
  385. package/dist/fonts/maple-7.9-regular-0fc-b644c0c6d9.woff2 +0 -0
  386. package/dist/fonts/maple-7.9-regular-780-c6000d472a.woff2 +0 -0
  387. package/dist/fonts/maple-7.9-regular-781-86409ab7f7.woff2 +0 -0
  388. package/dist/fonts/maple-7.9-regular-782-9cd950637c.woff2 +0 -0
  389. package/dist/fonts/maple-7.9-regular-783-105c4d02df.woff2 +0 -0
  390. package/dist/fonts/maple-7.9-regular-784-00c042af97.woff2 +0 -0
  391. package/dist/fonts/maple-7.9-regular-785-022568d0b8.woff2 +0 -0
  392. package/dist/fonts/maple-7.9-regular-786-90b6f3aef5.woff2 +0 -0
  393. package/dist/fonts/maple-7.9-regular-787-e2888596c9.woff2 +0 -0
  394. package/dist/fonts/maple-7.9-regular-788-3416e1fda3.woff2 +0 -0
  395. package/dist/fonts/maple-7.9-regular-789-9ffc917b0b.woff2 +0 -0
  396. package/dist/fonts/maple-7.9-regular-78a-4a921d07f6.woff2 +0 -0
  397. package/dist/fonts/maple-7.9-regular-78b-9d71c5327b.woff2 +0 -0
  398. package/dist/fonts/maple-7.9-regular-78c-9ec048314b.woff2 +0 -0
  399. package/dist/fonts/maple-7.9-regular-78d-46a2ebd113.woff2 +0 -0
  400. package/dist/fonts/maple-7.9-regular-latin-59c752ba1d.woff2 +0 -0
  401. package/dist/fonts/maple.css +315 -0
  402. package/dist/index.d.ts +9 -0
  403. package/dist/index.js +132 -0
  404. package/dist/index.js.map +1 -0
  405. package/dist/math-renderer-L6DOH4RX.js +21 -0
  406. package/dist/math-renderer-L6DOH4RX.js.map +1 -0
  407. package/dist/math.css +1 -0
  408. package/dist/react/index.d.ts +112 -0
  409. package/dist/react/index.js +57 -0
  410. package/dist/react/index.js.map +1 -0
  411. package/dist/styles.css +451 -0
  412. package/dist/translations-BliabrPd.d.ts +310 -0
  413. package/docs/api.md +161 -0
  414. package/docs/extensions.md +309 -0
  415. package/docs/implementation.md +79 -0
  416. package/docs/performance.md +84 -0
  417. package/docs/styles.md +103 -0
  418. package/docs/visual-upgrade.md +148 -0
  419. package/examples/assistant.tsx +52 -0
  420. package/examples/notes.tsx +73 -0
  421. package/package.json +110 -3
@@ -0,0 +1,3070 @@
1
+ import {
2
+ createDocument,
3
+ defaultHighlight,
4
+ intersects,
5
+ mapText,
6
+ rangeOf,
7
+ resolveAnnotationAnchors,
8
+ safeUrl,
9
+ sameRange,
10
+ selectionFromRange,
11
+ textContent,
12
+ walk
13
+ } from "./chunk-7JF5HHVF.js";
14
+ import {
15
+ ResourceCache
16
+ } from "./chunk-6N6TFHEN.js";
17
+
18
+ // src/react/motion.ts
19
+ var flights = /* @__PURE__ */ new WeakMap();
20
+ function scrollWithMotion(root, top) {
21
+ flights.get(root)?.();
22
+ const element = root instanceof Window ? root.document.documentElement : root;
23
+ const start = root instanceof Window ? root.scrollY : root.scrollTop;
24
+ const target = Math.max(0, Math.min(top, element.scrollHeight - (root instanceof Window ? root.innerHeight : root.clientHeight)));
25
+ if (matchMedia("(prefers-reduced-motion: reduce)").matches) {
26
+ root.scrollTo({ top: target, behavior: "instant" });
27
+ return;
28
+ }
29
+ const duration = Math.min(560, 220 + Math.abs(target - start) * 0.15);
30
+ let frame = 0, begun = 0;
31
+ const keyboard = (event) => {
32
+ if (["ArrowDown", "ArrowUp", "PageDown", "PageUp", "Home", "End", " "].includes(event.key)) stop();
33
+ };
34
+ const stop = () => {
35
+ cancelAnimationFrame(frame);
36
+ root.removeEventListener("wheel", stop);
37
+ root.removeEventListener("touchstart", stop);
38
+ root.removeEventListener("pointerdown", stop);
39
+ root.removeEventListener("keydown", keyboard);
40
+ flights.delete(root);
41
+ };
42
+ const step = (time) => {
43
+ begun ||= time;
44
+ const t = Math.min(1, (time - begun) / duration);
45
+ root.scrollTo({ top: start + (target - start) * (1 - Math.pow(1 - t, 4)), behavior: "instant" });
46
+ if (t < 1) frame = requestAnimationFrame(step);
47
+ else stop();
48
+ };
49
+ flights.set(root, stop);
50
+ root.addEventListener("wheel", stop, { passive: true });
51
+ root.addEventListener("touchstart", stop, { passive: true });
52
+ root.addEventListener("pointerdown", stop, { passive: true });
53
+ root.addEventListener("keydown", keyboard);
54
+ frame = requestAnimationFrame(step);
55
+ }
56
+
57
+ // src/react/runtime.ts
58
+ var english = {
59
+ contents: "Contents",
60
+ annotations: "Annotations",
61
+ expand: "Expand",
62
+ collapse: "Collapse",
63
+ close: "Close",
64
+ copy: "Copy",
65
+ copied: "Copied",
66
+ copyFailed: "Copy failed",
67
+ copyImage: "Copy image URL",
68
+ copyFigures: "Copy figures Markdown",
69
+ loading: "Loading\u2026",
70
+ retry: "Retry",
71
+ unavailable: "Content unavailable",
72
+ footnotes: "Footnotes",
73
+ definition: "Definition",
74
+ question: "Question",
75
+ note: "Note",
76
+ extra: "Extended reading",
77
+ hint: "Hint",
78
+ answer: "Answer",
79
+ submit: "Submit",
80
+ correct: "Correct",
81
+ incorrect: "Try again",
82
+ play: "Play video",
83
+ highlight: "Highlight",
84
+ addHighlight: "Add highlight",
85
+ editHighlight: "Edit highlight",
86
+ highlightColor: "Color",
87
+ highlightStyle: "Style",
88
+ highlightBackground: "Background",
89
+ highlightUnderline: "Underline",
90
+ highlightDotted: "Dotted",
91
+ highlightWavy: "Wavy",
92
+ hideHighlight: "Hide highlight",
93
+ showHighlight: "Show highlight",
94
+ deleteAnnotations: "Delete",
95
+ deleteAnnotationsHint: "Deletes {count} annotations on this text and any highlight."
96
+ };
97
+ var chinese = {
98
+ contents: "\u76EE\u5F55",
99
+ annotations: "\u6CE8\u91CA",
100
+ expand: "\u5C55\u5F00",
101
+ collapse: "\u6536\u8D77",
102
+ close: "\u5173\u95ED",
103
+ copy: "\u590D\u5236",
104
+ copied: "\u5DF2\u590D\u5236",
105
+ copyFailed: "\u590D\u5236\u5931\u8D25",
106
+ copyImage: "\u590D\u5236\u56FE\u7247 URL",
107
+ copyFigures: "\u590D\u5236\u56FE\u7EC4 Markdown",
108
+ loading: "\u52A0\u8F7D\u4E2D\u2026",
109
+ retry: "\u91CD\u8BD5",
110
+ unavailable: "\u6682\u65E0\u5185\u5BB9",
111
+ footnotes: "\u811A\u6CE8",
112
+ definition: "\u91CA\u4E49",
113
+ question: "\u63D0\u95EE",
114
+ note: "\u6CE8\u91CA",
115
+ extra: "\u62D3\u5C55\u9605\u8BFB",
116
+ hint: "\u63D0\u793A",
117
+ answer: "\u7B54\u6848",
118
+ submit: "\u63D0\u4EA4",
119
+ correct: "\u56DE\u7B54\u6B63\u786E",
120
+ incorrect: "\u518D\u8BD5\u4E00\u6B21",
121
+ play: "\u64AD\u653E\u89C6\u9891",
122
+ highlight: "\u9AD8\u4EAE",
123
+ addHighlight: "\u6DFB\u52A0\u9AD8\u4EAE",
124
+ editHighlight: "\u8C03\u6574\u9AD8\u4EAE",
125
+ highlightColor: "\u989C\u8272",
126
+ highlightStyle: "\u6837\u5F0F",
127
+ highlightBackground: "\u5E95\u8272",
128
+ highlightUnderline: "\u4E0B\u5212\u7EBF",
129
+ highlightDotted: "\u70B9\u7EBF",
130
+ highlightWavy: "\u6CE2\u6D6A\u7EBF",
131
+ hideHighlight: "\u9690\u85CF\u9AD8\u4EAE",
132
+ showHighlight: "\u663E\u793A\u9AD8\u4EAE",
133
+ deleteAnnotations: "\u5220\u9664",
134
+ deleteAnnotationsHint: "\u5C06\u5220\u9664\u8FD9\u6BB5\u6587\u5B57\u5173\u8054\u7684 {count} \u4E2A\u6CE8\u91CA\u53CA\u9AD8\u4EAE\u3002"
135
+ };
136
+ var Store = class {
137
+ constructor(value) {
138
+ this.value = value;
139
+ }
140
+ value;
141
+ listeners = /* @__PURE__ */ new Set();
142
+ get = () => this.value;
143
+ subscribe = (listener) => {
144
+ this.listeners.add(listener);
145
+ return () => this.listeners.delete(listener);
146
+ };
147
+ set(value) {
148
+ if (Object.is(this.value, value)) return;
149
+ this.value = value;
150
+ for (const listener of this.listeners) listener();
151
+ }
152
+ };
153
+ var EMPTY = Object.freeze([]);
154
+ var emptyDecorations = Object.freeze({ occurrences: EMPTY, highlights: EMPTY });
155
+ var ReaderRuntime = class {
156
+ document;
157
+ interaction = new Store({ selection: null, activeHeading: null, hovered: null, active: null, editing: null, activeHighlight: null, hoveredHighlight: null });
158
+ layout = new Store(0);
159
+ viewport = new Store(0);
160
+ documentOffset = new Store(0);
161
+ decorations = new Store({ annotations: /* @__PURE__ */ new Map(), highlights: /* @__PURE__ */ new Map(), occurrences: [], byBlock: /* @__PURE__ */ new Map() });
162
+ configuration;
163
+ resources = new ResourceCache(128);
164
+ resourceVersions = new Store(/* @__PURE__ */ new Map());
165
+ resourceKeys = /* @__PURE__ */ new Map();
166
+ nextResource = 0;
167
+ anchors = /* @__PURE__ */ new Map();
168
+ blocks = /* @__PURE__ */ new Map();
169
+ headings = /* @__PURE__ */ new Map();
170
+ bindings = /* @__PURE__ */ new WeakMap();
171
+ textBinders = /* @__PURE__ */ new WeakMap();
172
+ components = {};
173
+ annotationTypes = /* @__PURE__ */ new Map();
174
+ locale = english;
175
+ content = null;
176
+ selectionRange = null;
177
+ /** Live geometry supplied by the paint layer; independent of native selection. */
178
+ highlightReference = null;
179
+ layoutFrame = 0;
180
+ observer = null;
181
+ headingPositions = [];
182
+ localAnnotations = [];
183
+ pendingOpen = null;
184
+ pendingAnnotations;
185
+ taskController = new AbortController();
186
+ get signal() {
187
+ return this.taskController.signal;
188
+ }
189
+ commands = {
190
+ addAnnotation: (annotation, options = {}) => {
191
+ this.changeAnnotations((items) => {
192
+ const next = [...items.filter((item) => item.id !== annotation.id), annotation];
193
+ if (annotation.type !== "highlight" && options.highlight !== false) {
194
+ const doc = this.document.getSnapshot();
195
+ for (const anchor of resolveAnnotationAnchors(annotation, doc)) {
196
+ if (anchor.range.start === anchor.range.end || next.some((item) => item.type === "highlight" && resolveAnnotationAnchors(item, doc).some((other) => sameRange(other.range, anchor.range)))) continue;
197
+ next.push({ id: `highlight-${crypto.randomUUID()}`, type: "highlight", anchors: [{ ...anchor, id: void 0 }], data: { ...defaultHighlight, ...options.highlight } });
198
+ }
199
+ }
200
+ return next;
201
+ });
202
+ if (options.edit) this.commands.editAnnotation(annotation.id);
203
+ },
204
+ updateAnnotation: (id, update) => this.changeAnnotations((items) => items.map((item) => item.id === id ? { ...item, ...update, id } : item)),
205
+ removeAnnotation: (id) => this.changeAnnotations((items) => items.filter((item) => item.id !== id)),
206
+ removeAnnotationsAt: (ranges) => this.changeAnnotations((items) => items.flatMap((item) => {
207
+ const anchors = item.anchors ?? (item.range ? [{ range: item.range }] : []);
208
+ const keep = anchors.filter((anchor) => !resolveAnnotationAnchors({ ...item, range: void 0, anchors: [anchor] }, this.document.getSnapshot()).some((resolved) => ranges.some((range) => sameRange(range, resolved.range))));
209
+ if (keep.length === anchors.length) return [item];
210
+ return keep.length ? [{ ...item, range: void 0, anchors: keep }] : [];
211
+ })),
212
+ editAnnotation: (id) => {
213
+ this.updateInteraction({ editing: id });
214
+ if (id) this.commands.activateAnnotation(id);
215
+ },
216
+ activateAnnotation: (id) => {
217
+ const occurrence = this.decorations.get().occurrences.find((item) => item.id === id || item.annotationIds.includes(id ?? ""));
218
+ this.pendingOpen = id && !occurrence ? id : null;
219
+ this.activate(occurrence?.id ?? null);
220
+ }
221
+ };
222
+ changeAnnotations(update) {
223
+ const config = this.configuration.get();
224
+ const current = this.pendingAnnotations && this.pendingAnnotations.input === config.annotations ? this.pendingAnnotations.value : config.annotations ?? this.localAnnotations;
225
+ const next = update(current);
226
+ if (config.annotations !== void 0 && !config.onAnnotationsChange) throw new Error("Controlled annotations require onAnnotationsChange to accept edits.");
227
+ if (config.annotations === void 0) {
228
+ this.localAnnotations = next;
229
+ this.rebuildDecorations();
230
+ } else this.pendingAnnotations = { input: config.annotations, value: next };
231
+ config.onAnnotationsChange?.(next);
232
+ }
233
+ start() {
234
+ if (this.taskController.signal.aborted) this.taskController = new AbortController();
235
+ }
236
+ dispose() {
237
+ this.taskController.abort();
238
+ this.resources.invalidate();
239
+ this.resourceKeys.clear();
240
+ }
241
+ getResourceKey(annotation) {
242
+ const old = this.resourceKeys.get(annotation.id);
243
+ if (old?.annotation === annotation) return old.key;
244
+ if (old) this.resources.invalidate(old.key);
245
+ const key = `${annotation.id}:${++this.nextResource}`;
246
+ this.resourceKeys.set(annotation.id, { annotation, key });
247
+ return key;
248
+ }
249
+ invalidateAnnotation(id) {
250
+ const current = this.resourceKeys.get(id);
251
+ if (current) this.resources.invalidate(current.key);
252
+ const versions = new Map(this.resourceVersions.get());
253
+ versions.set(id, (versions.get(id) ?? 0) + 1);
254
+ this.resourceVersions.set(versions);
255
+ }
256
+ constructor(id, source, streaming, config) {
257
+ this.configuration = new Store(config);
258
+ this.installConfiguration(config);
259
+ this.document = createDocument(source, { id, streaming, extensions: config.extensions });
260
+ this.rebuildDecorations();
261
+ this.document.subscribe(() => {
262
+ this.rebuildDecorations();
263
+ const selection = this.interaction.get().selection;
264
+ if (selection && selection.raw.ranges.length === 1) {
265
+ const doc = this.document.getSnapshot(), range = selection.raw.ranges[0];
266
+ this.updateInteraction({ selection: doc.source.slice(range.start, range.end) === selection.raw.sourceText ? selectionFromRange(doc, range, { text: selection.text, quality: selection.quality, settled: selection.settled }) : null });
267
+ }
268
+ this.requestLayout();
269
+ this.configuration.get().onDocumentChange?.(this.document.getSnapshot());
270
+ });
271
+ }
272
+ installConfiguration(config) {
273
+ this.components = Object.assign({}, ...(config.extensions ?? []).map((ext) => ext.components), config.components);
274
+ const annotationTypes = [...(config.extensions ?? []).flatMap((ext) => [...ext.annotationTypes ?? []]), ...config.annotationTypes ?? []];
275
+ this.annotationTypes = new Map(annotationTypes.map((type) => [type.type, type]));
276
+ this.locale = { ...english, ...config.locale };
277
+ }
278
+ configure(config) {
279
+ const old = this.configuration.get();
280
+ if (this.pendingAnnotations?.input !== config.annotations) this.pendingAnnotations = void 0;
281
+ this.installConfiguration(config);
282
+ this.configuration.set(config);
283
+ if (old.extensions !== config.extensions) this.document.setExtensions(config.extensions ?? []);
284
+ if (old.annotations !== config.annotations) this.rebuildDecorations();
285
+ if (old.annotationTypes !== config.annotationTypes || old.extensions !== config.extensions) this.resources.invalidate();
286
+ }
287
+ updateInteraction(patch) {
288
+ const old = this.interaction.get();
289
+ if (Object.keys(patch).every((key) => Object.is(old[key], patch[key]))) return;
290
+ this.interaction.set({ ...old, ...patch });
291
+ if ("selection" in patch) this.configuration.get().onSelectionChange?.(patch.selection ?? null);
292
+ }
293
+ hover(id, source = "marker") {
294
+ this.updateInteraction({ hovered: id, hoverSource: id ? source : null });
295
+ this.configuration.get().onAnnotationHover?.(this.decorations.get().occurrences.find((item) => item.id === id) ?? null);
296
+ }
297
+ activate(id, source = "marker") {
298
+ this.updateInteraction({ active: id, activeSource: id ? source : null, hovered: null, hoverSource: null });
299
+ const occurrence = this.decorations.get().occurrences.find((item) => item.id === id);
300
+ if (occurrence) this.configuration.get().onAnnotationClick?.(occurrence);
301
+ }
302
+ hoverHighlight(id) {
303
+ if (this.interaction.get().hoveredHighlight === id) return;
304
+ this.updateInteraction({ hoveredHighlight: id });
305
+ this.configuration.get().onHighlightHover?.(id ? this.decorations.get().annotations.get(this.decorations.get().highlights.get(id)?.annotationId ?? "") ?? null : null);
306
+ }
307
+ activateHighlight(id) {
308
+ this.updateInteraction({ activeHighlight: id, selection: null });
309
+ const highlight = id && this.decorations.get().highlights.get(id);
310
+ if (highlight) this.configuration.get().onHighlightClick?.(this.decorations.get().annotations.get(highlight.annotationId));
311
+ else this.highlightReference = null;
312
+ }
313
+ clearSelection() {
314
+ this.selectionRange = null;
315
+ const selection = typeof window === "undefined" ? null : window.getSelection();
316
+ if (selection?.anchorNode && this.content?.contains(selection.anchorNode)) selection.removeAllRanges();
317
+ this.highlightReference = null;
318
+ this.updateInteraction({ selection: null, activeHighlight: null });
319
+ }
320
+ prepareTextBindings(element) {
321
+ const block = element.closest("[data-limr-block]");
322
+ const bind = block && this.textBinders.get(block);
323
+ if (bind) {
324
+ this.textBinders.delete(block);
325
+ bind();
326
+ }
327
+ }
328
+ rebuildDecorations() {
329
+ const doc = this.document.getSnapshot();
330
+ const config = this.configuration.get();
331
+ const previous = this.decorations.get();
332
+ const annotations = new Map(doc.annotations.map((annotation) => [annotation.id, annotation]));
333
+ for (const annotation of config.annotations ?? this.localAnnotations) annotations.set(annotation.id, annotation);
334
+ for (const [id, resource] of this.resourceKeys) if (!annotations.has(id)) {
335
+ this.resources.invalidate(resource.key);
336
+ this.resourceKeys.delete(id);
337
+ }
338
+ const versions = this.resourceVersions.get();
339
+ if ([...versions.keys()].some((id) => !annotations.has(id))) this.resourceVersions.set(new Map([...versions].filter(([id]) => annotations.has(id))));
340
+ const occurrences = [...doc.occurrences];
341
+ const allHighlights = [];
342
+ for (const annotation of config.annotations ?? this.localAnnotations) {
343
+ resolveAnnotationAnchors(annotation, doc).forEach((anchor, index) => {
344
+ if (annotation.type === "highlight") {
345
+ const id = index ? `${annotation.id}:${index}` : annotation.id;
346
+ const value = { ...annotation.data, id, annotationId: annotation.id, range: anchor.range };
347
+ const old = previous.highlights.get(id);
348
+ allHighlights.push(old && sameRange(old.range, value.range) && old.color === value.color && old.style === value.style && old.hidden === value.hidden ? old : value);
349
+ } else occurrences.push({ ...anchor, id: anchor.id ?? `${doc.id}-${annotation.id}-${index}`, annotationIds: [annotation.id] });
350
+ });
351
+ }
352
+ occurrences.sort((a, b) => a.range.end - b.range.end || a.id.localeCompare(b.id));
353
+ const byBlock = /* @__PURE__ */ new Map();
354
+ for (const block of occurrences.length || allHighlights.length ? doc.blocks : []) {
355
+ const marks = occurrences.filter((item) => !item.embedded && item.range.end > block.range.start && item.range.end <= block.range.end);
356
+ const before = previous.byBlock.get(block.id) ?? emptyDecorations;
357
+ const old = before.occurrences;
358
+ const same = old && old.length === marks.length && old.every((item, index) => item.id === marks[index].id && item.range.start === marks[index].range.start && item.range.end === marks[index].range.end && item.annotationIds.join("\0") === marks[index].annotationIds.join("\0"));
359
+ const highlights2 = allHighlights.filter((item) => intersects(item.range, block.range));
360
+ const oldHighlights = before.highlights;
361
+ const sameHighlights = oldHighlights.length === highlights2.length && oldHighlights.every((item, i) => item === highlights2[i]);
362
+ if (marks.length || highlights2.length) byBlock.set(block.id, same && sameHighlights ? before : { occurrences: same ? old : marks, highlights: sameHighlights ? oldHighlights : highlights2 });
363
+ }
364
+ const sameBlocks = byBlock.size === previous.byBlock.size && [...byBlock].every(([id, value]) => previous.byBlock.get(id) === value);
365
+ const highlights = new Map(allHighlights.map((item) => [item.id, item]));
366
+ this.decorations.set({ annotations, highlights, occurrences, byBlock: sameBlocks ? previous.byBlock : byBlock });
367
+ const state = this.interaction.get();
368
+ if (state.editing && !annotations.has(state.editing) && this.pendingOpen !== state.editing) this.updateInteraction({ editing: null });
369
+ if (state.activeHighlight && !highlights.has(state.activeHighlight)) this.activateHighlight(null);
370
+ if (state.hoveredHighlight && !highlights.has(state.hoveredHighlight)) this.hoverHighlight(null);
371
+ if (state.active && !occurrences.some((item) => item.id === state.active)) this.activate(null);
372
+ if (state.hovered && !occurrences.some((item) => item.id === state.hovered)) this.hover(null);
373
+ if (this.pendingOpen) {
374
+ const occurrence = occurrences.find((item) => item.id === this.pendingOpen || item.annotationIds.includes(this.pendingOpen));
375
+ if (occurrence) {
376
+ this.pendingOpen = null;
377
+ this.activate(occurrence.id);
378
+ }
379
+ }
380
+ }
381
+ registerAnchor(id, element) {
382
+ if (element) this.anchors.set(id, element);
383
+ else this.anchors.delete(id);
384
+ this.requestLayout();
385
+ }
386
+ registerHeading(id, element) {
387
+ if (element) this.headings.set(id, element);
388
+ else this.headings.delete(id);
389
+ this.requestLayout();
390
+ }
391
+ observeBlock(element) {
392
+ if (element) {
393
+ if (element.dataset.limrBlock) this.blocks.set(element.dataset.limrBlock, element);
394
+ this.observer?.observe(element);
395
+ }
396
+ }
397
+ unobserveBlock(element) {
398
+ if (element.dataset.limrBlock) this.blocks.delete(element.dataset.limrBlock);
399
+ this.observer?.unobserve(element);
400
+ }
401
+ getScrollTop() {
402
+ return this.configuration.get().scrollRoot?.scrollTop ?? (typeof window !== "undefined" ? window.scrollY : 0);
403
+ }
404
+ getViewportTop() {
405
+ return this.configuration.get().scrollRoot?.getBoundingClientRect().top ?? 0;
406
+ }
407
+ getContentOffset() {
408
+ const translate = this.content && getComputedStyle(this.content).translate;
409
+ return translate ? parseFloat(translate.split(" ")[1] ?? "0") || 0 : 0;
410
+ }
411
+ scrollTo(top, behavior = "smooth") {
412
+ const root = this.configuration.get().scrollRoot ?? window;
413
+ if (behavior === "smooth") scrollWithMotion(root, top);
414
+ else root.scrollTo({ top: Math.max(0, top), behavior });
415
+ }
416
+ scrollToHeading(id) {
417
+ const element = this.headings.get(id);
418
+ if (element) this.scrollTo(element.getBoundingClientRect().top - this.getViewportTop() + this.getScrollTop() - (this.configuration.get().scrollOffset ?? 24));
419
+ }
420
+ scrollToOccurrence(id) {
421
+ const element = this.anchors.get(id);
422
+ if (element) this.scrollTo(element.getBoundingClientRect().top - this.getViewportTop() + this.getScrollTop() - (this.configuration.get().scrollOffset ?? 24));
423
+ }
424
+ followFragment = (event) => {
425
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey) return;
426
+ const link = event.target instanceof Element ? event.target.closest("a[href]") : null;
427
+ if (!link || link.hasAttribute("download") || link.target && link.target !== "_self" || !this.content?.contains(link)) return;
428
+ const url = new URL(link.href, document.baseURI);
429
+ if (!url.hash || url.origin !== location.origin || url.pathname !== location.pathname || url.search !== location.search) return;
430
+ let id;
431
+ try {
432
+ id = decodeURIComponent(url.hash.slice(1));
433
+ } catch {
434
+ return;
435
+ }
436
+ const target = this.content.querySelector(`[id="${CSS.escape(id)}"]`);
437
+ if (!target) return;
438
+ event.preventDefault();
439
+ this.scrollTo(target.getBoundingClientRect().top - this.getViewportTop() + this.getScrollTop() - (this.configuration.get().scrollOffset ?? 24));
440
+ if (event.detail === 0) {
441
+ if (!target.hasAttribute("tabindex")) {
442
+ target.tabIndex = -1;
443
+ target.addEventListener("blur", () => target.removeAttribute("tabindex"), { once: true });
444
+ }
445
+ target.focus({ preventScroll: true });
446
+ }
447
+ };
448
+ requestLayout = () => {
449
+ if (typeof window === "undefined" || !this.content || this.layoutFrame) return;
450
+ this.layoutFrame = window.requestAnimationFrame(() => {
451
+ this.layoutFrame = 0;
452
+ const offset = this.getScrollTop() - this.getViewportTop();
453
+ this.headingPositions = [...this.headings].filter(([, element]) => !element.closest("[inert]")).map(([id, element]) => ({ id, top: element.getBoundingClientRect().top + offset })).sort((a, b) => a.top - b.top);
454
+ const state = this.interaction.get();
455
+ if (state.active && this.anchors.get(state.active)?.closest("[inert]")) this.activate(null);
456
+ if (state.hovered && this.anchors.get(state.hovered)?.closest("[inert]")) this.hover(null);
457
+ this.layout.set(this.layout.get() + 1);
458
+ this.trackHeading();
459
+ });
460
+ };
461
+ trackHeading = () => {
462
+ const positions = this.headingPositions;
463
+ const top = this.getScrollTop() + (this.configuration.get().scrollOffset ?? 24) + 2;
464
+ let lo = 0, hi = positions.length;
465
+ while (lo < hi) {
466
+ const mid = lo + hi >>> 1;
467
+ if (positions[mid].top <= top) lo = mid + 1;
468
+ else hi = mid;
469
+ }
470
+ const root = this.configuration.get().scrollRoot;
471
+ const maximum = (root?.scrollHeight ?? document.documentElement.scrollHeight) - (root?.clientHeight ?? window.innerHeight);
472
+ const atEnd = maximum > 0 && this.getScrollTop() >= maximum - 2;
473
+ this.updateInteraction({ activeHeading: positions[atEnd ? positions.length - 1 : Math.max(0, lo - 1)]?.id ?? null });
474
+ };
475
+ mountContent(element) {
476
+ this.content = element;
477
+ this.observer = new ResizeObserver(this.requestLayout);
478
+ this.observer.observe(element);
479
+ element.querySelectorAll("[data-limr-block]").forEach((block) => this.observer.observe(block));
480
+ let frame = 0;
481
+ const scroll = () => {
482
+ if (frame) return;
483
+ frame = requestAnimationFrame(() => {
484
+ frame = 0;
485
+ this.trackHeading();
486
+ this.viewport.set(this.viewport.get() + 1);
487
+ });
488
+ };
489
+ const scrollRoot = this.configuration.get().scrollRoot ?? window;
490
+ scrollRoot.addEventListener("scroll", scroll, { passive: true });
491
+ window.addEventListener("resize", this.requestLayout);
492
+ document.fonts?.addEventListener("loadingdone", this.requestLayout);
493
+ element.addEventListener("load", this.requestLayout, true);
494
+ element.addEventListener("click", this.followFragment);
495
+ this.requestLayout();
496
+ return () => {
497
+ this.content = null;
498
+ this.observer?.disconnect();
499
+ this.observer = null;
500
+ cancelAnimationFrame(frame);
501
+ cancelAnimationFrame(this.layoutFrame);
502
+ this.layoutFrame = 0;
503
+ scrollRoot.removeEventListener("scroll", scroll);
504
+ window.removeEventListener("resize", this.requestLayout);
505
+ document.fonts?.removeEventListener("loadingdone", this.requestLayout);
506
+ element.removeEventListener("load", this.requestLayout, true);
507
+ element.removeEventListener("click", this.followFragment);
508
+ };
509
+ }
510
+ };
511
+ var emptyList = EMPTY;
512
+
513
+ // src/extensions/gfm.ts
514
+ import { gfm as syntax } from "micromark-extension-gfm";
515
+ import { gfmFromMarkdown } from "mdast-util-gfm";
516
+ function gfm() {
517
+ return { name: "gfm", micromark: [syntax()], mdast: gfmFromMarkdown(), scope: "local" };
518
+ }
519
+
520
+ // src/extensions/math.tsx
521
+ import { lazy, Suspense } from "react";
522
+ import { math as syntax2 } from "micromark-extension-math";
523
+ import { mathFromMarkdown } from "mdast-util-math";
524
+
525
+ // src/components/CopyButton.tsx
526
+ import { useEffect as useEffect9, useRef as useRef12, useState as useState9 } from "react";
527
+
528
+ // src/react/context.tsx
529
+ import { createContext as createContext2, useCallback as useCallback2, useContext as useContext3, useEffect as useEffect8, useId, useLayoutEffect, useMemo as useMemo4, useRef as useRef11, useState as useState8, useSyncExternalStore } from "react";
530
+
531
+ // src/extensions/code.tsx
532
+ import { useEffect, useRef, useState } from "react";
533
+
534
+ // src/react/literal.ts
535
+ function literalValue(node) {
536
+ return (node.value ?? "").replace(/\r\n?|\n/g, node.type === "inlineCode" ? " " : "\n");
537
+ }
538
+ function mapLiteral(source, node) {
539
+ const range = rangeOf(node), raw = source.slice(range.start, range.end), value = literalValue(node);
540
+ const starts = [], ends = [];
541
+ if (node.type === "inlineCode") {
542
+ const fence = /^`+/.exec(raw)?.[0].length ?? 0;
543
+ let from = fence, until = raw.length - fence;
544
+ const normalized = raw.slice(from, until).replace(/\r\n?|\n/g, " ");
545
+ if (normalized.startsWith(" ") && normalized.endsWith(" ") && /[^ ]/.test(normalized)) {
546
+ from += raw.slice(from, from + 2) === "\r\n" ? 2 : 1;
547
+ until -= raw.slice(until - 2, until) === "\r\n" ? 2 : 1;
548
+ }
549
+ for (let at = from; at < until; at++) {
550
+ const length = raw[at] === "\r" && raw[at + 1] === "\n" ? 2 : 1;
551
+ starts.push(range.start + at);
552
+ ends.push(range.start + at + length);
553
+ at += length - 1;
554
+ }
555
+ return { starts, ends, exact: starts.length === value.length };
556
+ }
557
+ const lines = [...raw.matchAll(/[^\r\n]*(?:\r\n|\r|\n|$)/g)].filter((match) => match[0]);
558
+ const fenced = /^[ \t]*(?:`{3,}|~{3,})/.test(lines[0]?.[0] ?? "");
559
+ let index = fenced ? 1 : 0;
560
+ let exact = true;
561
+ const values = value.split("\n");
562
+ for (let line = 0; line < values.length; line++, index++) {
563
+ const match = lines[index], text = values[line];
564
+ const rawLine = (match?.[0] ?? "").replace(/[\r\n]+$/, "");
565
+ const at = rawLine.endsWith(text) ? rawLine.length - text.length : -1;
566
+ if (at < 0 || !match) exact = false;
567
+ const start = range.start + (match?.index ?? raw.length) + Math.max(0, at);
568
+ for (let unit = 0; unit < text.length; unit++) {
569
+ starts.push(start + unit);
570
+ ends.push(start + unit + 1);
571
+ }
572
+ if (line < values.length - 1) {
573
+ starts.push(range.start + (match?.index ?? 0) + rawLine.length);
574
+ ends.push(range.start + (match?.index ?? 0) + (match?.[0].length ?? rawLine.length));
575
+ }
576
+ }
577
+ return { starts, ends, exact };
578
+ }
579
+
580
+ // src/extensions/code.tsx
581
+ import { jsx, jsxs } from "react/jsx-runtime";
582
+ var cache = new ResourceCache(96);
583
+ var aliases = { js: "javascript", ts: "typescript", py: "python", sh: "bash", yml: "yaml", md: "markdown", rs: "rust", "c++": "cpp", text: "text", txt: "text" };
584
+ function codeHighlight(options = {}) {
585
+ function CodeNode({ node, pending, renderValue }) {
586
+ const runtime = useRuntime();
587
+ const code = literalValue(node);
588
+ const language = String(node.lang ?? "text").toLowerCase();
589
+ const normalized = aliases[language] ?? language;
590
+ const [result, setResult] = useState(null);
591
+ const [visible, setVisible] = useState(options.eager ?? false);
592
+ const ref = useRef(null);
593
+ useEffect(() => {
594
+ if (visible) return;
595
+ if (typeof IntersectionObserver === "undefined") {
596
+ setVisible(true);
597
+ return;
598
+ }
599
+ const observer = new IntersectionObserver((entries) => {
600
+ if (entries.some((entry) => entry.isIntersecting)) {
601
+ setVisible(true);
602
+ observer.disconnect();
603
+ }
604
+ }, { root: runtime.configuration.get().scrollRoot, rootMargin: "400px" });
605
+ if (ref.current) observer.observe(ref.current);
606
+ return () => observer.disconnect();
607
+ }, [visible, runtime]);
608
+ useEffect(() => {
609
+ if (!visible || code.length > (options.maxLength ?? 1e5)) return;
610
+ let disposed = false;
611
+ let release;
612
+ const timer = setTimeout(() => {
613
+ if (normalized === "text" || options.languages && !options.languages.includes(normalized)) return;
614
+ const request = cache.acquire(JSON.stringify([code, normalized, options.lightTheme, options.darkTheme]), async () => {
615
+ const shiki = await import("shiki");
616
+ if (!(normalized in shiki.bundledLanguages) && !(normalized in shiki.bundledLanguagesAlias)) return [];
617
+ const result2 = await shiki.codeToTokens(code, { lang: normalized, themes: { light: options.lightTheme ?? "github-light", dark: options.darkTheme ?? "github-dark" }, defaultColor: false });
618
+ let offset = 0;
619
+ return result2.tokens.flatMap((line, index) => {
620
+ const tokens2 = line.map((token) => {
621
+ const start = offset;
622
+ offset += token.content.length;
623
+ return { content: token.content, offset: start, style: token.htmlStyle };
624
+ });
625
+ if (index < result2.tokens.length - 1) {
626
+ tokens2.push({ content: "\n", offset: offset++ });
627
+ }
628
+ return tokens2;
629
+ });
630
+ });
631
+ release = request.release;
632
+ request.promise.then((tokens2) => {
633
+ if (!disposed) setResult({ code, tokens: tokens2 });
634
+ }).catch(() => {
635
+ });
636
+ }, pending ? 180 : 0);
637
+ return () => {
638
+ disposed = true;
639
+ clearTimeout(timer);
640
+ release?.();
641
+ };
642
+ }, [code, normalized, pending, visible]);
643
+ const tokens = result?.code === code ? result.tokens : void 0;
644
+ return /* @__PURE__ */ jsxs("div", { className: "limr-code-block", ref, children: [
645
+ /* @__PURE__ */ jsxs("div", { className: "limr-code-header", "data-limr-ignore": "true", children: [
646
+ /* @__PURE__ */ jsx("span", { children: language }),
647
+ /* @__PURE__ */ jsx(CopyButton, { value: code })
648
+ ] }),
649
+ /* @__PURE__ */ jsx("pre", { className: tokens?.length ? "shiki" : void 0, children: /* @__PURE__ */ jsx("code", { children: renderValue(tokens) }) })
650
+ ] });
651
+ }
652
+ return { name: "code-highlight", scope: "local", components: { code: CodeNode } };
653
+ }
654
+
655
+ // src/extensions/annotations.tsx
656
+ import { useMemo as useMemo2, useRef as useRef6 } from "react";
657
+ import { fromMarkdown } from "mdast-util-from-markdown";
658
+
659
+ // src/react/Markdown.tsx
660
+ import { useContext, useEffect as useEffect4, useRef as useRef4 } from "react";
661
+
662
+ // src/react/render.tsx
663
+ import { cloneElement, Component, createElement, Fragment, isValidElement, memo, useCallback, useMemo, useRef as useRef2 } from "react";
664
+
665
+ // src/react/text-binding.ts
666
+ var atomic = /* @__PURE__ */ new Set(["inlineCode", "code", "math", "inlineMath", "image", "imageReference", "html"]);
667
+ var hidden = /* @__PURE__ */ new Set(["definition", "footnoteDefinition", "annotationDefinition", "footnoteReference"]);
668
+ var ordinary = /* @__PURE__ */ new Set(["text", "paragraph", "heading", "strong", "emphasis", "delete", "blockquote", "list", "listItem", "link", "linkReference", "table", "tableRow", "tableCell", "thematicBreak", "break", "annotationReference"]);
669
+ function compactTextNodes(node, components) {
670
+ const texts = [];
671
+ let supported = true;
672
+ const visit = (node2) => {
673
+ if (node2.selection === "atomic" || atomic.has(node2.type) || hidden.has(node2.type)) return;
674
+ if (!ordinary.has(node2.type) || components[node2.type]) {
675
+ supported = false;
676
+ return;
677
+ }
678
+ if (node2.type === "text") {
679
+ if (node2.value) texts.push(node2);
680
+ return;
681
+ }
682
+ node2.children?.forEach(visit);
683
+ };
684
+ visit(node);
685
+ return supported ? texts : null;
686
+ }
687
+ function bindingFor(node, source) {
688
+ const range = rangeOf(node), value = node.value ?? "";
689
+ const raw = source.slice(range.start, range.end);
690
+ const direct = raw === value;
691
+ let mapping;
692
+ const mapped = () => mapping ??= mapText(raw, value, { start: 0, end: raw.length });
693
+ return {
694
+ range,
695
+ atomic: false,
696
+ get exact() {
697
+ return direct || mapped().exact;
698
+ },
699
+ resolve(offset, edge) {
700
+ const at = Math.max(0, Math.min(value.length, offset));
701
+ return direct ? range.start + at : range.start + (edge === "start" ? mapped().starts[at] ?? raw.length : mapped().ends[at - 1] ?? 0);
702
+ }
703
+ };
704
+ }
705
+ function bindCompactText(element, nodes, runtime) {
706
+ const bound = [];
707
+ const clear = () => bound.forEach((node) => runtime.bindings.delete(node));
708
+ const bindings = nodes.map((node) => bindingFor(node, runtime.document.getSnapshot().source));
709
+ const walker = element.ownerDocument.createTreeWalker(element, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_TEXT, {
710
+ acceptNode(node) {
711
+ if (node.nodeType === Node.ELEMENT_NODE) {
712
+ const element2 = node;
713
+ return element2.hasAttribute("data-limr-ignore") || element2.hasAttribute("data-limr-text") || runtime.bindings.get(element2)?.atomic ? NodeFilter.FILTER_REJECT : NodeFilter.FILTER_SKIP;
714
+ }
715
+ return NodeFilter.FILTER_ACCEPT;
716
+ }
717
+ });
718
+ let index = 0, inValue = 0;
719
+ for (let text = walker.nextNode(); text; text = walker.nextNode()) {
720
+ const value = text.textContent ?? "";
721
+ if (!value) continue;
722
+ const parts2 = [];
723
+ for (let at = 0; at < value.length; ) {
724
+ const expected = nodes[index]?.value ?? "";
725
+ const size = Math.min(value.length - at, expected.length - inValue);
726
+ if (size <= 0 || value.slice(at, at + size) !== expected.slice(inValue, inValue + size)) {
727
+ clear();
728
+ return () => {
729
+ };
730
+ }
731
+ parts2.push({ start: at, end: at + size, offset: inValue, binding: bindings[index] });
732
+ at += size;
733
+ inValue += size;
734
+ if (inValue === expected.length) {
735
+ index++;
736
+ inValue = 0;
737
+ }
738
+ }
739
+ const first = parts2[0], last = parts2[parts2.length - 1];
740
+ runtime.bindings.set(text, parts2.length === 1 && first.offset === 0 && value === nodes[index - 1]?.value ? first.binding : {
741
+ range: { start: first.binding.range.start, end: last.binding.range.end },
742
+ atomic: false,
743
+ get exact() {
744
+ return parts2.every((part) => part.binding.exact);
745
+ },
746
+ resolve(offset, edge) {
747
+ const part = parts2.find((part2) => edge === "start" ? part2.end > offset : part2.end >= offset) ?? last;
748
+ return part.binding.resolve(part.offset + offset - part.start, edge);
749
+ }
750
+ });
751
+ bound.push(text);
752
+ }
753
+ return clear;
754
+ }
755
+
756
+ // src/react/render.tsx
757
+ import { Fragment as Fragment2, jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
758
+ var blockAttributes = (block) => block ? { "data-limr-block": block.id, "data-source-start": block.range.start, "data-source-end": block.range.end, "data-pending": block.pending || void 0 } : {};
759
+ function AnnotationMarker({ occurrence }) {
760
+ const runtime = useRuntime();
761
+ const annotation = useStoreSelector(runtime.decorations, (state) => state.annotations.get(occurrence.annotationIds[0]));
762
+ const active = useStoreSelector(runtime.interaction, (state) => state.active === occurrence.id);
763
+ const hovered = useStoreSelector(runtime.interaction, (state) => state.hovered === occurrence.id);
764
+ const definition2 = useStoreSelector(runtime.configuration, () => runtime.annotationTypes.get(annotation?.type ?? "citation"));
765
+ const Icon = definition2?.icon;
766
+ const Custom = definition2?.Marker;
767
+ const icon = typeof Icon === "function" || Icon && typeof Icon === "object" && !isValidElement(Icon) && "$$typeof" in Icon ? createElement(Icon) : Icon;
768
+ return /* @__PURE__ */ jsx2("span", { className: "limr-mark-wrap", "data-limr-ignore": "true", "data-limr-marker": occurrence.id, "data-source-start": occurrence.range.start, "data-source-end": occurrence.range.end, children: /* @__PURE__ */ jsxs2(
769
+ "button",
770
+ {
771
+ type: "button",
772
+ ref: (element) => runtime.registerAnchor(occurrence.id, element),
773
+ className: "limr-mark",
774
+ "data-limr-anchor": occurrence.id,
775
+ "data-active": active || hovered || void 0,
776
+ style: { "--limr-mark-color": definition2?.color },
777
+ "aria-label": definition2?.label ?? annotation?.type ?? "Annotation",
778
+ "aria-expanded": active,
779
+ onPointerEnter: (event) => {
780
+ if (event.pointerType !== "touch") runtime.hover(occurrence.id);
781
+ },
782
+ onPointerLeave: (event) => {
783
+ if (event.pointerType !== "touch" && runtime.interaction.get().hovered === occurrence.id && runtime.interaction.get().hoverSource === "marker") runtime.hover(null);
784
+ },
785
+ onFocus: (event) => {
786
+ if (event.currentTarget.matches(":focus-visible")) runtime.hover(occurrence.id);
787
+ },
788
+ onBlur: (event) => {
789
+ if (event.relatedTarget instanceof Element && event.relatedTarget.closest("[data-occurrence]")?.getAttribute("data-occurrence") === occurrence.id) return;
790
+ if (runtime.interaction.get().hovered === occurrence.id && runtime.interaction.get().hoverSource === "marker") runtime.hover(null);
791
+ },
792
+ onClick: () => {
793
+ const hovering = runtime.interaction.get().hovered === occurrence.id;
794
+ runtime.activate(active ? null : occurrence.id);
795
+ if (hovering) runtime.hover(occurrence.id);
796
+ },
797
+ children: [
798
+ /* @__PURE__ */ jsx2("span", { className: "limr-mark-icon", children: Custom && annotation ? /* @__PURE__ */ jsx2(Custom, { annotation, active }) : icon ?? "\u2022" }),
799
+ occurrence.annotationIds.length > 1 && /* @__PURE__ */ jsx2("span", { className: "limr-mark-count", children: occurrence.annotationIds.length })
800
+ ]
801
+ }
802
+ ) });
803
+ }
804
+ function Text({ node, context, mapping: literalMapping, marks: literalMarks, style, className }) {
805
+ const { runtime } = context;
806
+ const value = node.value ?? "";
807
+ const range = rangeOf(node);
808
+ const source = runtime.document.getSnapshot().source;
809
+ const mapped = useMemo(() => {
810
+ let mapping2;
811
+ const raw = source.slice(range.start, range.end);
812
+ return () => {
813
+ if (literalMapping) return literalMapping;
814
+ if (!mapping2) {
815
+ const relative = mapText(raw, value, { start: 0, end: raw.length }, { escapes: node.verbatimEscapes !== true });
816
+ mapping2 = { starts: relative.starts.map((offset) => offset + range.start), ends: relative.ends.map((offset) => offset + range.start), exact: relative.exact };
817
+ }
818
+ return mapping2;
819
+ };
820
+ }, [node, literalMapping]);
821
+ const marks = literalMarks ?? context.marks.get(node) ?? emptyList;
822
+ const highlights = context.highlights.filter((highlight) => intersects(highlight.range, range));
823
+ if (!marks.length && !highlights.length) {
824
+ const direct = !literalMapping && source.slice(range.start, range.end) === value;
825
+ return /* @__PURE__ */ jsx2("span", { style, className, "data-limr-text": "", "data-source-start": range.start, "data-source-end": range.end, ref: (element) => {
826
+ if (element) runtime.bindings.set(element, {
827
+ range,
828
+ atomic: false,
829
+ get exact() {
830
+ return direct || mapped().exact;
831
+ },
832
+ resolve: (offset, edge) => direct ? Math.max(range.start, Math.min(range.end, range.start + offset)) : edge === "start" ? mapped().starts[offset] ?? range.end : mapped().ends[offset - 1] ?? range.start
833
+ });
834
+ }, children: value });
835
+ }
836
+ const mapping = mapped();
837
+ const markerAt = /* @__PURE__ */ new Map();
838
+ const boundaries = /* @__PURE__ */ new Set([0, value.length]);
839
+ for (const mark of marks) {
840
+ let index = mapping.ends.findIndex((end) => end >= mark.range.end);
841
+ index = index < 0 ? value.length : index + 1;
842
+ boundaries.add(index);
843
+ markerAt.set(index, [...markerAt.get(index) ?? [], mark]);
844
+ }
845
+ for (const highlight of highlights) {
846
+ const start = mapping.ends.findIndex((end2) => end2 > highlight.range.start);
847
+ const end = mapping.starts.findIndex((start2) => start2 >= highlight.range.end);
848
+ boundaries.add(Math.max(0, start));
849
+ boundaries.add(end < 0 ? value.length : end);
850
+ }
851
+ const points = [...boundaries].sort((a, b) => a - b);
852
+ return /* @__PURE__ */ jsx2(Fragment2, { children: points.slice(1).map((end, index) => {
853
+ const start = points[index];
854
+ const segmentRange = { start: mapping.starts[start] ?? range.start, end: mapping.ends[end - 1] ?? range.end };
855
+ const styles = highlights.filter((highlight) => intersects(highlight.range, segmentRange));
856
+ let text = value.slice(start, end);
857
+ for (const highlight of styles) text = /* @__PURE__ */ jsx2("mark", { "data-limr-highlight": highlight.id, "data-hidden": highlight.hidden || void 0, className: `limr-highlight limr-highlight-${highlight.style ?? "background"}`, style: { "--limr-highlight": highlight.color ?? "#f3ce7380" }, children: text }, highlight.id);
858
+ return /* @__PURE__ */ jsxs2("span", { style, className, ref: (element) => {
859
+ if (element) runtime.bindings.set(element, { range: segmentRange, atomic: false, exact: mapping.exact, resolve: (offset, edge) => {
860
+ const at = Math.max(start, Math.min(end, start + offset));
861
+ return edge === "start" ? mapping.starts[at] ?? segmentRange.end : mapping.ends[at - 1] ?? segmentRange.start;
862
+ } });
863
+ }, "data-limr-text": "", "data-source-start": segmentRange.start, "data-source-end": segmentRange.end, children: [
864
+ text,
865
+ markerAt.get(end)?.map((occurrence) => /* @__PURE__ */ jsx2(AnnotationMarker, { occurrence }, occurrence.id))
866
+ ] }, start);
867
+ }) });
868
+ }
869
+ function LiteralValue({ node, context, tokens }) {
870
+ const source = context.runtime.document.getSnapshot().source;
871
+ const mapping = useMemo(() => mapLiteral(source, node), [node]);
872
+ const value = literalValue(node);
873
+ const marks = context.marks.get(node) ?? emptyList;
874
+ const segments = tokens?.length ? tokens : [{ content: value, offset: 0 }];
875
+ return /* @__PURE__ */ jsx2(Fragment2, { children: segments.map((token, index) => {
876
+ const start = token.offset, end = start + token.content.length;
877
+ const mapped = { starts: mapping.starts.slice(start, end), ends: mapping.ends.slice(start, end), exact: mapping.exact };
878
+ const range = { start: mapped.starts[0] ?? rangeOf(node).start, end: mapped.ends.at(-1) ?? rangeOf(node).end };
879
+ const leaf = { type: "text", value: token.content, position: { start: { offset: range.start, line: 0, column: 0 }, end: { offset: range.end, line: 0, column: 0 } } };
880
+ return /* @__PURE__ */ jsx2(Text, { className: token.style ? "limr-code-token" : void 0, style: token.style, node: leaf, context, mapping: mapped, marks: marks.filter((mark) => mark.range.end > range.start && mark.range.end <= range.end) }, index);
881
+ }) });
882
+ }
883
+ function Atomic({ node, context, children, inline, blockElement }) {
884
+ const range = rangeOf(node);
885
+ const selected = useStoreSelector(context.runtime.interaction, (state) => state.selection?.raw.ranges.some((selection) => intersects(selection, range)) ?? false);
886
+ const highlights = context.highlights.filter((highlight) => !highlight.hidden && intersects(highlight.range, range));
887
+ const Tag = inline ? "span" : "div";
888
+ const image = ["image", "imageReference"].includes(node.type) || node.type === "component" && node.name === "img";
889
+ const corner = image || !inline;
890
+ const marks = [...context.marks.get(node) ?? [], ...corner ? context.afterMarks.get(node) ?? [] : []];
891
+ const markers = marks.map((occurrence) => /* @__PURE__ */ jsx2(AnnotationMarker, { occurrence }, occurrence.id));
892
+ return /* @__PURE__ */ jsxs2(Fragment2, { children: [
893
+ /* @__PURE__ */ jsxs2(
894
+ Tag,
895
+ {
896
+ ...blockAttributes(blockElement),
897
+ className: `limr-atomic${image ? " limr-atomic-image" : ""}${corner ? " limr-atomic-corner" : ""}${highlights.length ? " limr-atomic-highlight" : ""}`,
898
+ "data-selected": selected || void 0,
899
+ "data-limr-media": image ? "image" : void 0,
900
+ "data-limr-atomic": inline ? "inline" : "block",
901
+ "data-source-start": range.start,
902
+ "data-source-end": range.end,
903
+ style: { "--limr-highlight": highlights[0]?.color ?? "#f3ce7380" },
904
+ ref: (element) => {
905
+ if (element) context.runtime.bindings.set(element, { range, atomic: true });
906
+ blockElement?.ref(element);
907
+ },
908
+ children: [
909
+ children,
910
+ corner && !!marks.length && /* @__PURE__ */ jsx2("span", { className: "limr-corner-marks", "data-limr-ignore": "true", children: markers })
911
+ ]
912
+ }
913
+ ),
914
+ !corner && markers
915
+ ] });
916
+ }
917
+ function HeadingNode({ node, children, runtime, blockElement }) {
918
+ const id = (() => {
919
+ const doc = runtime.document.getSnapshot();
920
+ const offset = node.position?.start.offset ?? 0;
921
+ let lo = 0, hi = doc.headings.length;
922
+ while (lo < hi) {
923
+ const mid = lo + hi >>> 1;
924
+ if (doc.headings[mid].range.start < offset) lo = mid + 1;
925
+ else hi = mid;
926
+ }
927
+ return doc.headings[lo]?.range.start === offset ? doc.headings[lo].id : void 0;
928
+ })();
929
+ return createElement(`h${node.depth}`, { ...blockAttributes(blockElement), id, ref: (element) => {
930
+ if (id) runtime.registerHeading(id, element);
931
+ blockElement?.ref(element);
932
+ } }, children);
933
+ }
934
+ function Reference({ node, children, image }) {
935
+ const definition2 = useDocumentSelector((doc) => doc.definitions.get(String(node.identifier)));
936
+ if (!definition2) return /* @__PURE__ */ jsx2(Fragment2, { children: children || String(node.alt ?? node.label ?? "") });
937
+ return image ? /* @__PURE__ */ jsx2("img", { src: safeUrl(definition2.url, true), alt: String(node.alt ?? ""), title: definition2.title ? String(definition2.title) : void 0, loading: "lazy", decoding: "async" }) : /* @__PURE__ */ jsx2("a", { href: safeUrl(definition2.url), title: definition2.title ? String(definition2.title) : void 0, children });
938
+ }
939
+ function FootnoteReference({ node }) {
940
+ const runtime = useRuntime();
941
+ const identifier2 = String(node.identifier);
942
+ const number = useDocumentSelector((doc) => doc.footnoteOrder.indexOf(identifier2) + 1);
943
+ return /* @__PURE__ */ jsx2("sup", { "data-limr-ignore": "true", children: /* @__PURE__ */ jsx2("a", { href: `#${runtime.document.id}-fn-${encodeURIComponent(identifier2)}`, id: `${runtime.document.id}-fnref-${rangeOf(node).start}`, "aria-label": `Footnote ${number}`, children: number }) });
944
+ }
945
+ var ExtensionBoundary = class extends Component {
946
+ state = { failed: false };
947
+ static getDerivedStateFromError() {
948
+ return { failed: true };
949
+ }
950
+ componentDidCatch(_error, _info) {
951
+ }
952
+ componentDidUpdate(previous) {
953
+ if (this.state.failed && previous.fallback !== this.props.fallback) this.setState({ failed: false });
954
+ }
955
+ render() {
956
+ return this.state.failed ? /* @__PURE__ */ jsx2("pre", { className: "limr-extension-error", children: this.props.fallback }) : this.props.children;
957
+ }
958
+ };
959
+ function containsBlock(node) {
960
+ return node.type === "component" && !node.inline || ["math", "code", "list", "table", "blockquote"].includes(node.type) || (node.children?.some(containsBlock) ?? false);
961
+ }
962
+ function renderNode(node, context, index = 0, trailing) {
963
+ const { runtime } = context;
964
+ if (node.type === "text" && context.compact) return node.value ?? "";
965
+ const blockElement = node === context.block.node ? context.blockElement : void 0;
966
+ const key = `${node.type}-${node.position?.start.offset ?? index}-${index}`;
967
+ const childContext = node.type === "list" ? { ...context, tightList: !node.spread } : context;
968
+ const renderChildren = (nodes, options) => {
969
+ let last = -1;
970
+ nodes.forEach((child, i) => {
971
+ if (!["definition", "footnoteDefinition", "annotationDefinition"].includes(child.type)) last = i;
972
+ });
973
+ if (last < 0 && options?.trailing) return [/* @__PURE__ */ jsx2(Fragment, { children: options.trailing }, "trailing")];
974
+ return nodes.map((child, i) => renderNode(child, childContext, i, i === last ? options?.trailing : void 0));
975
+ };
976
+ const children = node.type === "table" ? [] : node.type === "listItem" && context.tightList ? (node.children ?? []).flatMap((child, index2) => child.type === "paragraph" ? renderChildren(child.children ?? []) : renderNode(child, context, index2)) : renderChildren(node.children ?? []);
977
+ const Renderer = runtime.components[node.type === "component" ? node.name ?? "" : node.type];
978
+ let element;
979
+ if (Renderer) {
980
+ const range = rangeOf(node);
981
+ const renderAttribute = (name) => {
982
+ const attribute = node.attributeNodes?.[name];
983
+ if (!attribute) return String(node.attributes?.[name] ?? "");
984
+ const range2 = rangeOf(attribute);
985
+ return /* @__PURE__ */ jsx2(Text, { node: attribute, context, marks: context.occurrences.filter((item) => item.range.end > range2.start && item.range.end <= range2.end) });
986
+ };
987
+ element = /* @__PURE__ */ jsx2(ExtensionBoundary, { fallback: runtime.document.getSnapshot().source.slice(range.start, range.end), children: /* @__PURE__ */ jsx2(Renderer, { node, children, pending: context.block.pending, source: runtime.document.getSnapshot().source.slice(range.start, range.end), renderChildren, renderValue: (tokens) => /* @__PURE__ */ jsx2(LiteralValue, { node, context, tokens }), renderAttribute }) }, key);
988
+ } else {
989
+ switch (node.type) {
990
+ case "text":
991
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
992
+ context.compact ? node.value ?? "" : /* @__PURE__ */ jsx2(Text, { node, context }),
993
+ trailing
994
+ ] }, key);
995
+ case "paragraph":
996
+ element = containsBlock(node) ? /* @__PURE__ */ jsxs2("div", { className: "limr-paragraph", children: [
997
+ children,
998
+ trailing
999
+ ] }) : /* @__PURE__ */ jsxs2("p", { children: [
1000
+ children,
1001
+ trailing
1002
+ ] });
1003
+ trailing = void 0;
1004
+ break;
1005
+ case "heading":
1006
+ return /* @__PURE__ */ jsxs2(HeadingNode, { node, runtime, blockElement, children: [
1007
+ children,
1008
+ trailing
1009
+ ] }, key);
1010
+ case "strong":
1011
+ element = /* @__PURE__ */ jsx2("strong", { children });
1012
+ break;
1013
+ case "emphasis":
1014
+ element = /* @__PURE__ */ jsx2("em", { children });
1015
+ break;
1016
+ case "delete":
1017
+ element = /* @__PURE__ */ jsx2("del", { children });
1018
+ break;
1019
+ case "inlineCode":
1020
+ element = /* @__PURE__ */ jsx2("code", { className: "limr-inline-code", "data-limr-inline-syntax": "", "data-source-start": rangeOf(node).start, "data-source-end": rangeOf(node).end, children: /* @__PURE__ */ jsx2(LiteralValue, { node, context }) });
1021
+ break;
1022
+ case "code":
1023
+ element = /* @__PURE__ */ jsx2("pre", { children: /* @__PURE__ */ jsx2("code", { children: /* @__PURE__ */ jsx2(LiteralValue, { node, context }) }) });
1024
+ break;
1025
+ case "math":
1026
+ case "inlineMath":
1027
+ element = /* @__PURE__ */ jsx2("code", { children: node.value });
1028
+ break;
1029
+ case "blockquote":
1030
+ element = /* @__PURE__ */ jsxs2("blockquote", { className: "limr-note", children: [
1031
+ /* @__PURE__ */ jsx2("div", { className: "limr-card-label", "data-limr-ignore": "true", children: runtime.locale.note }),
1032
+ /* @__PURE__ */ jsx2("div", { className: "limr-block-content", children })
1033
+ ] });
1034
+ break;
1035
+ case "list":
1036
+ element = node.ordered ? /* @__PURE__ */ jsx2("ol", { start: Number(node.start ?? 1), children }) : /* @__PURE__ */ jsx2("ul", { children });
1037
+ break;
1038
+ case "listItem":
1039
+ element = /* @__PURE__ */ jsxs2("li", { className: typeof node.checked === "boolean" ? "limr-task-item" : void 0, children: [
1040
+ typeof node.checked === "boolean" && /* @__PURE__ */ jsx2("input", { type: "checkbox", checked: node.checked, disabled: true, "aria-label": "Task" }),
1041
+ children
1042
+ ] });
1043
+ break;
1044
+ case "link":
1045
+ element = /* @__PURE__ */ jsx2("a", { href: safeUrl(node.url), title: node.title ? String(node.title) : void 0, children });
1046
+ break;
1047
+ case "image":
1048
+ element = /* @__PURE__ */ jsx2("img", { src: safeUrl(node.url, true), alt: String(node.alt ?? ""), title: node.title ? String(node.title) : void 0, loading: "lazy", decoding: "async" });
1049
+ break;
1050
+ case "linkReference":
1051
+ element = /* @__PURE__ */ jsx2(Reference, { node, image: false, children });
1052
+ break;
1053
+ case "imageReference":
1054
+ element = /* @__PURE__ */ jsx2(Reference, { node, image: true, children });
1055
+ break;
1056
+ case "thematicBreak":
1057
+ element = /* @__PURE__ */ jsx2("hr", {});
1058
+ break;
1059
+ case "break":
1060
+ element = /* @__PURE__ */ jsx2("br", {});
1061
+ break;
1062
+ case "table": {
1063
+ const rows = node.children ?? [], alignment = node.align;
1064
+ element = /* @__PURE__ */ jsx2("div", { className: "limr-table-scroll", children: /* @__PURE__ */ jsxs2("table", { children: [
1065
+ /* @__PURE__ */ jsx2("thead", { children: rows.slice(0, 1).map((row, i) => /* @__PURE__ */ jsx2("tr", { children: row.children?.map((cell, j) => /* @__PURE__ */ jsx2("th", { style: { textAlign: alignment?.[j] }, children: renderChildren(cell.children ?? []) }, j)) }, i)) }),
1066
+ /* @__PURE__ */ jsx2("tbody", { children: rows.slice(1).map((row, i) => /* @__PURE__ */ jsx2("tr", { children: row.children?.map((cell, j) => /* @__PURE__ */ jsx2("td", { style: { textAlign: alignment?.[j] }, children: renderChildren(cell.children ?? []) }, j)) }, i)) })
1067
+ ] }) });
1068
+ break;
1069
+ }
1070
+ case "definition":
1071
+ case "footnoteDefinition":
1072
+ case "annotationDefinition":
1073
+ return null;
1074
+ case "footnoteReference":
1075
+ return /* @__PURE__ */ jsxs2(Fragment, { children: [
1076
+ /* @__PURE__ */ jsx2(FootnoteReference, { node }),
1077
+ trailing
1078
+ ] }, key);
1079
+ case "annotationReference": {
1080
+ const Tag = node.inline ? "span" : "div";
1081
+ element = /* @__PURE__ */ jsxs2(Tag, { children: [
1082
+ children,
1083
+ /* @__PURE__ */ jsx2(AnnotationMarker, { occurrence: { id: `${runtime.document.id}-ref-${rangeOf(node).start}`, range: rangeOf(node), annotationIds: node.annotationIds, embedded: true } })
1084
+ ] });
1085
+ break;
1086
+ }
1087
+ case "html":
1088
+ element = /* @__PURE__ */ jsx2("span", { className: "limr-literal", children: node.value });
1089
+ break;
1090
+ case "component":
1091
+ element = children;
1092
+ break;
1093
+ default:
1094
+ element = children.length ? children : node.value ?? null;
1095
+ }
1096
+ }
1097
+ const atomic2 = node.selection === "atomic" || ["math", "inlineMath", "image", "imageReference", "html"].includes(node.type);
1098
+ const corner = atomic2 && (!node.inline && !["inlineCode", "inlineMath", "html"].includes(node.type) || ["image", "imageReference"].includes(node.type) || node.name === "img");
1099
+ const after = corner ? void 0 : context.afterMarks.get(node);
1100
+ const withMarkers = (element2) => after?.length || trailing ? /* @__PURE__ */ jsxs2(Fragment, { children: [
1101
+ element2,
1102
+ after?.map((occurrence) => /* @__PURE__ */ jsx2(AnnotationMarker, { occurrence }, occurrence.id)),
1103
+ trailing
1104
+ ] }, key) : element2;
1105
+ if (atomic2) return withMarkers(/* @__PURE__ */ jsx2(Atomic, { node, context, blockElement, inline: node.inline || ["inlineCode", "inlineMath", "image", "imageReference", "html"].includes(node.type), children: element }, key));
1106
+ if (blockElement) {
1107
+ const attributes = { ...blockAttributes(blockElement), ref: blockElement.ref };
1108
+ return withMarkers(isValidElement(element) && typeof element.type === "string" ? cloneElement(element, { ...attributes, key }) : /* @__PURE__ */ jsx2("div", { ...attributes, children: element }, key));
1109
+ }
1110
+ return withMarkers(isValidElement(element) ? cloneElement(element, { key }) : /* @__PURE__ */ jsx2(Fragment, { children: element }, key));
1111
+ }
1112
+ var BlockView = memo(function BlockView2({ block, runtime, components, extensions, decorations, footnoteId }) {
1113
+ const element = useRef2(null);
1114
+ const clearBindings = useRef2(void 0);
1115
+ const { occurrences, highlights } = decorations;
1116
+ const root = useMemo(() => footnoteId ? { ...block.node, type: "listItem" } : block.node, [block, footnoteId]);
1117
+ const texts = useMemo(() => compactTextNodes(root, runtime.components), [root, runtime, components, extensions]);
1118
+ const compact = !!texts && !occurrences.length && !highlights.length;
1119
+ const observe = useCallback((next) => {
1120
+ clearBindings.current?.();
1121
+ clearBindings.current = void 0;
1122
+ if (element.current) runtime.textBinders.delete(element.current);
1123
+ if (element.current && element.current !== next) runtime.unobserveBlock(element.current);
1124
+ element.current = next;
1125
+ runtime.observeBlock(next);
1126
+ if (next && compact && texts.length) runtime.textBinders.set(next, () => {
1127
+ clearBindings.current = bindCompactText(next, texts, runtime);
1128
+ });
1129
+ }, [runtime, compact, texts]);
1130
+ const { marks, afterMarks } = useMemo(() => {
1131
+ const map = /* @__PURE__ */ new Map();
1132
+ const after = /* @__PURE__ */ new Map();
1133
+ if (!occurrences.length) return { marks: map, afterMarks: after };
1134
+ const leaves = [];
1135
+ const attributes = [];
1136
+ const paths = /* @__PURE__ */ new Map();
1137
+ const outside = /* @__PURE__ */ new Set(["strong", "emphasis", "delete", "link", "linkReference", "inlineCode", "code", "math", "inlineMath", "image", "imageReference", "html"]);
1138
+ function collect(node, ancestors = []) {
1139
+ if (node.attributeNodes) attributes.push(...Object.values(node.attributeNodes));
1140
+ const path = [...ancestors, node];
1141
+ if (node.selection === "atomic" || ["text", "inlineCode", "code", "math", "inlineMath", "image", "imageReference", "html"].includes(node.type)) {
1142
+ leaves.push(node);
1143
+ paths.set(node, path);
1144
+ } else node.children?.forEach((child) => collect(child, path));
1145
+ }
1146
+ collect(block.node);
1147
+ for (const occurrence of occurrences) {
1148
+ const target = [...leaves].reverse().find((node) => rangeOf(node).start < occurrence.range.end) ?? leaves[0];
1149
+ const image = target && (["image", "imageReference"].includes(target.type) || target.name === "img") && rangeOf(target).end >= occurrence.range.end;
1150
+ if (!image && attributes.some((attribute) => {
1151
+ const range = rangeOf(attribute);
1152
+ return occurrence.range.end > range.start && occurrence.range.end <= range.end;
1153
+ })) continue;
1154
+ if (target) {
1155
+ const outer = paths.get(target)?.find((node2) => (outside.has(node2.type) || node2.selection === "atomic") && rangeOf(node2).end <= occurrence.range.end);
1156
+ const destination = outer ? after : map, node = outer ?? target;
1157
+ destination.set(node, [...destination.get(node) ?? [], occurrence]);
1158
+ }
1159
+ }
1160
+ return { marks: map, afterMarks: after };
1161
+ }, [block, occurrences]);
1162
+ if (!footnoteId && ["definition", "footnoteDefinition", "annotationDefinition"].includes(block.node.type)) return null;
1163
+ const context = { runtime, block, marks, afterMarks, highlights, occurrences, compact, blockElement: { id: block.id, range: block.range, pending: block.pending, ref: observe } };
1164
+ if (footnoteId) return /* @__PURE__ */ jsx2("li", { id: `${runtime.document.id}-fn-${encodeURIComponent(footnoteId)}`, ...blockAttributes(context.blockElement), ref: observe, children: block.node.children?.map((child, index) => renderNode(child, { ...context, blockElement: void 0 }, index)) });
1165
+ return renderNode(block.node, context);
1166
+ });
1167
+ function Footnotes() {
1168
+ const runtime = useRuntime();
1169
+ const doc = useDocumentSelector((snapshot) => snapshot);
1170
+ const components = useStoreSelector(runtime.configuration, (config) => config.components);
1171
+ const extensions = useStoreSelector(runtime.configuration, (config) => config.extensions);
1172
+ const decorations = useStoreSelector(runtime.decorations, (state) => state.byBlock);
1173
+ const blocks = useMemo(() => new Map(doc.blocks.filter((block) => block.node.type === "footnoteDefinition").map((block) => [String(block.node.identifier), block])), [doc.blocks]);
1174
+ if (!doc.footnoteOrder.length) return null;
1175
+ return /* @__PURE__ */ jsxs2("section", { className: "limr-footnotes", "aria-label": runtime.locale.footnotes, children: [
1176
+ /* @__PURE__ */ jsx2("hr", {}),
1177
+ /* @__PURE__ */ jsx2("ol", { children: doc.footnoteOrder.map((id) => {
1178
+ const node = doc.footnotes.get(id);
1179
+ if (!node) return null;
1180
+ const block = blocks.get(id) ?? { id: `${doc.id}-fn-${id}`, range: rangeOf(node), node, pending: false };
1181
+ return /* @__PURE__ */ jsx2(BlockView, { block, runtime, components, extensions, footnoteId: id, decorations: decorations.get(block.id) ?? emptyDecorations }, id);
1182
+ }) })
1183
+ ] });
1184
+ }
1185
+
1186
+ // src/react/selection.ts
1187
+ import { useEffect as useEffect2 } from "react";
1188
+
1189
+ // src/react/source-geometry.ts
1190
+ function flowOf(element, container) {
1191
+ const known = element.closest("pre,p,figcaption,li,th,td,h1,h2,h3,h4,h5,h6,.limr-choice-text,.limr-definition-title,.limr-question-title,.limr-block-content");
1192
+ return known && container.contains(known) ? known : element.closest("[data-limr-block]") ?? container;
1193
+ }
1194
+ function leavesIn(block, runtime) {
1195
+ runtime.prepareTextBindings(block);
1196
+ const result = [];
1197
+ const visit = (node, inherited) => {
1198
+ if (node instanceof HTMLElement) {
1199
+ if (node !== block && node.hasAttribute("data-limr-document") || node.hasAttribute("inert")) return;
1200
+ const marker = node.dataset.limrMarker;
1201
+ const atomic2 = node.dataset.limrAtomic;
1202
+ if (marker || atomic2) {
1203
+ const image = node.dataset.limrMedia === "image";
1204
+ result.push({ node, kind: marker ? "marker" : image ? "image" : atomic2 === "block" ? "block" : "inline", range: { start: Number(node.dataset.sourceStart), end: Number(node.dataset.sourceEnd) }, flow: image ? node : flowOf(node, runtime.content), offset: 0 });
1205
+ return;
1206
+ }
1207
+ if (node.hasAttribute("data-limr-ignore")) return;
1208
+ const binding = runtime.bindings.get(node);
1209
+ if (binding) inherited = { binding, offset: 0 };
1210
+ }
1211
+ if (node.nodeType === Node.TEXT_NODE) {
1212
+ const binding = runtime.bindings.get(node) ?? inherited?.binding;
1213
+ const offset = runtime.bindings.has(node) ? 0 : inherited?.offset ?? 0;
1214
+ const length = node.textContent?.length ?? 0;
1215
+ if (binding?.resolve && length) result.push({ node, kind: "text", range: { start: binding.resolve(offset, "start"), end: binding.resolve(offset + length, "end") }, flow: flowOf(node.parentElement, runtime.content), binding, offset });
1216
+ if (inherited) inherited.offset += length;
1217
+ return;
1218
+ }
1219
+ node.childNodes.forEach((child) => visit(child, inherited));
1220
+ };
1221
+ visit(block);
1222
+ return result;
1223
+ }
1224
+ function textRange(leaf, source, viewport) {
1225
+ const node = leaf.node, length = node.length;
1226
+ const resolve = leaf.binding.resolve;
1227
+ let lo = 0, hi = length;
1228
+ while (lo < hi) {
1229
+ const mid = lo + hi >>> 1;
1230
+ if (resolve(leaf.offset + mid + 1, "end") <= source.start) lo = mid + 1;
1231
+ else hi = mid;
1232
+ }
1233
+ let start = lo;
1234
+ lo = start;
1235
+ hi = length;
1236
+ while (lo < hi) {
1237
+ const mid = lo + hi >>> 1;
1238
+ if (resolve(leaf.offset + mid, "start") < source.end) lo = mid + 1;
1239
+ else hi = mid;
1240
+ }
1241
+ if (start === lo) return null;
1242
+ let end = lo;
1243
+ const range = document.createRange();
1244
+ if (viewport && end - start > 1024) {
1245
+ range.setStart(node, start);
1246
+ range.setEnd(node, end);
1247
+ const box = range.getBoundingClientRect();
1248
+ if (box.height > viewport.bottom - viewport.top + 80) {
1249
+ lo = start;
1250
+ hi = end;
1251
+ while (lo < hi) {
1252
+ const mid = lo + hi >>> 1;
1253
+ range.setStart(node, mid);
1254
+ range.setEnd(node, mid + 1);
1255
+ if (range.getBoundingClientRect().bottom < viewport.top) lo = mid + 1;
1256
+ else hi = mid;
1257
+ }
1258
+ start = lo;
1259
+ hi = end;
1260
+ while (lo < hi) {
1261
+ const mid = lo + hi >>> 1;
1262
+ range.setStart(node, mid);
1263
+ range.setEnd(node, mid + 1);
1264
+ if (range.getBoundingClientRect().top <= viewport.bottom) lo = mid + 1;
1265
+ else hi = mid;
1266
+ }
1267
+ end = lo;
1268
+ }
1269
+ }
1270
+ if (start === end) return null;
1271
+ range.setStart(node, start);
1272
+ range.setEnd(node, end);
1273
+ return range;
1274
+ }
1275
+ function sourceRangeStartRect(runtime, source) {
1276
+ for (const block of runtime.document.getSnapshot().blocks) {
1277
+ if (!intersects(block.range, source)) continue;
1278
+ const element = runtime.blocks.get(block.id);
1279
+ if (!element) continue;
1280
+ for (const leaf of leavesIn(element, runtime)) {
1281
+ if (leaf.kind === "marker" || !intersects(leaf.range, source)) continue;
1282
+ if (leaf.kind === "text") {
1283
+ const range = textRange(leaf, source);
1284
+ if (!range) continue;
1285
+ const node = leaf.node, end = range.endOffset;
1286
+ for (let start = range.startOffset; start < end; ) {
1287
+ const next = Math.min(end, start + (node.data.codePointAt(start) > 65535 ? 2 : 1));
1288
+ range.setStart(node, start);
1289
+ range.setEnd(node, next);
1290
+ const rect = range.getBoundingClientRect();
1291
+ if (rect.width && rect.height) return rect;
1292
+ start = next;
1293
+ }
1294
+ } else {
1295
+ const node = leaf.node;
1296
+ const rect = (node.querySelector(leaf.kind === "image" ? "img" : "[data-limr-selection-surface]") ?? node).getBoundingClientRect();
1297
+ if (rect.width && rect.height) return rect;
1298
+ }
1299
+ }
1300
+ }
1301
+ return null;
1302
+ }
1303
+
1304
+ // src/react/selection.ts
1305
+ function visualSelection(runtime, native, options) {
1306
+ if (![...runtime.content.querySelectorAll('[data-limr-selection-order="visual"]')].some((element) => native.intersectsNode(element))) return;
1307
+ const blocks = [...runtime.blocks.values()].filter((block) => native.intersectsNode(block));
1308
+ blocks.sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1);
1309
+ const leaves = blocks.flatMap((block) => leavesIn(block, runtime)).filter((leaf) => leaf.kind !== "marker");
1310
+ const selected = [];
1311
+ for (const leaf of leaves) {
1312
+ if (!native.intersectsNode(leaf.node)) continue;
1313
+ if (leaf.kind !== "text") {
1314
+ selected.push(leaf.range);
1315
+ continue;
1316
+ }
1317
+ const node = leaf.node;
1318
+ const start = native.startContainer === node ? native.startOffset : 0;
1319
+ const end = native.endContainer === node ? native.endOffset : node.length;
1320
+ if (start < end) selected.push({ start: leaf.binding.resolve(leaf.offset + start, "start"), end: leaf.binding.resolve(leaf.offset + end, "end") });
1321
+ }
1322
+ if (!selected.length) return;
1323
+ const sourceOrder = leaves.map((leaf) => leaf.range).sort((a, b) => a.end - b.end);
1324
+ const ranges = [];
1325
+ for (const range of selected) {
1326
+ const previous = ranges.at(-1);
1327
+ let lo = 0, hi = sourceOrder.length;
1328
+ if (previous) while (lo < hi) {
1329
+ const mid = lo + hi >>> 1;
1330
+ if (sourceOrder[mid].end <= previous.end) lo = mid + 1;
1331
+ else hi = mid;
1332
+ }
1333
+ if (previous && range.start >= previous.end && (!sourceOrder[lo] || sourceOrder[lo].start >= range.start)) previous.end = range.end;
1334
+ else ranges.push({ ...range });
1335
+ }
1336
+ const snapshot = runtime.document.getSnapshot();
1337
+ const selections = ranges.map((range) => selectionFromRange(snapshot, range, options));
1338
+ const combine = (key) => {
1339
+ const seen = /* @__PURE__ */ new Set();
1340
+ const ranges2 = selections.flatMap((selection) => selection[key].ranges).filter((range) => {
1341
+ const key2 = `${range.start}:${range.end}`;
1342
+ if (seen.has(key2)) return false;
1343
+ seen.add(key2);
1344
+ return true;
1345
+ });
1346
+ return { ranges: ranges2, sourceText: ranges2.map((range) => snapshot.source.slice(range.start, range.end)).join("\n\n") };
1347
+ };
1348
+ return { ...selections[0], raw: combine("raw"), syntax: combine("syntax"), blocks: combine("blocks") };
1349
+ }
1350
+ function useSelectionTracking(runtime, enabled) {
1351
+ useEffect2(() => {
1352
+ const container = runtime.content;
1353
+ if (!container || !enabled) return;
1354
+ let frame = 0, dragging = false;
1355
+ let previous;
1356
+ function resolve(node, offset, edge) {
1357
+ let element = node.nodeType === Node.ELEMENT_NODE ? node : node.parentElement;
1358
+ if (!element || element.closest("[data-limr-document]") !== container || element.closest("[data-limr-ignore]")) return null;
1359
+ runtime.prepareTextBindings(element);
1360
+ const native = node.nodeType === Node.TEXT_NODE ? runtime.bindings.get(node) : void 0;
1361
+ if (native?.resolve) return { offset: native.resolve(offset, edge), atomic: false, exact: native.exact !== false };
1362
+ while (element && element !== container) {
1363
+ const binding = runtime.bindings.get(element);
1364
+ if (binding) {
1365
+ if (binding.atomic) return { offset: edge === "start" ? binding.range.start : binding.range.end, atomic: true, exact: true };
1366
+ const range = document.createRange();
1367
+ range.setStart(element, 0);
1368
+ try {
1369
+ range.setEnd(node, offset);
1370
+ } catch {
1371
+ return null;
1372
+ }
1373
+ const localOffset = range.toString().length;
1374
+ return { offset: binding.resolve?.(localOffset, edge) ?? (edge === "start" ? binding.range.start : binding.range.end), atomic: false, exact: binding.exact !== false };
1375
+ }
1376
+ element = element.parentElement;
1377
+ }
1378
+ const children = node.nodeType === Node.ELEMENT_NODE ? Array.from(node.childNodes) : [];
1379
+ const candidates = edge === "start" ? children.slice(offset) : children.slice(0, offset).reverse();
1380
+ const descend = (candidate) => {
1381
+ if (candidate.nodeType === Node.TEXT_NODE && candidate.textContent) return resolve(candidate, edge === "start" ? 0 : candidate.textContent.length, edge);
1382
+ if (candidate instanceof Element) {
1383
+ if (candidate.hasAttribute("data-limr-ignore") || candidate.hasAttribute("inert")) return null;
1384
+ const binding = runtime.bindings.get(candidate);
1385
+ if (binding?.atomic) return { offset: edge === "start" ? binding.range.start : binding.range.end, atomic: true, exact: true };
1386
+ }
1387
+ const list = Array.from(candidate.childNodes);
1388
+ if (edge === "end") list.reverse();
1389
+ for (const child of list) {
1390
+ const result = descend(child);
1391
+ if (result) return result;
1392
+ }
1393
+ return null;
1394
+ };
1395
+ for (const child of candidates) {
1396
+ const result = descend(child);
1397
+ if (result) return result;
1398
+ }
1399
+ return null;
1400
+ }
1401
+ function process() {
1402
+ frame = 0;
1403
+ if (!dragging && document.activeElement instanceof Element && document.activeElement.closest("[data-limr-selection-ui]")) return;
1404
+ const selection = window.getSelection();
1405
+ if (!selection || selection.isCollapsed || !selection.rangeCount) {
1406
+ if (!(document.activeElement instanceof Element) || !document.activeElement.closest("[data-limr-selection-ui]")) {
1407
+ previous = void 0;
1408
+ runtime.selectionRange = null;
1409
+ runtime.updateInteraction({ selection: null });
1410
+ }
1411
+ return;
1412
+ }
1413
+ const range = selection.getRangeAt(0);
1414
+ const revision = runtime.document.getSnapshot().revision;
1415
+ if (runtime.interaction.get().selection && previous?.startNode === range.startContainer && previous.start === range.startOffset && previous.endNode === range.endContainer && previous.end === range.endOffset && previous.revision === revision && previous.settled === !dragging) return;
1416
+ const start = resolve(range.startContainer, range.startOffset, "start");
1417
+ const end = resolve(range.endContainer, range.endOffset, "end");
1418
+ if (!start || !end) {
1419
+ previous = void 0;
1420
+ runtime.selectionRange = null;
1421
+ runtime.updateInteraction({ selection: null });
1422
+ return;
1423
+ }
1424
+ previous = { startNode: range.startContainer, start: range.startOffset, endNode: range.endContainer, end: range.endOffset, revision, settled: !dragging };
1425
+ runtime.selectionRange = range.cloneRange();
1426
+ runtime.highlightReference = null;
1427
+ const options = {
1428
+ text: selection.toString(),
1429
+ settled: !dragging,
1430
+ quality: !start.exact || !end.exact ? "unmapped" : start.atomic || end.atomic ? "atomic" : "exact"
1431
+ };
1432
+ runtime.updateInteraction({ activeHighlight: null, selection: visualSelection(runtime, range, options) ?? selectionFromRange(runtime.document.getSnapshot(), { start: start.offset, end: end.offset }, options) });
1433
+ }
1434
+ const schedule = () => {
1435
+ if (!frame) frame = requestAnimationFrame(process);
1436
+ };
1437
+ const down = () => {
1438
+ dragging = true;
1439
+ };
1440
+ const up = () => {
1441
+ dragging = false;
1442
+ schedule();
1443
+ };
1444
+ document.addEventListener("selectionchange", schedule);
1445
+ container.addEventListener("pointerdown", down);
1446
+ document.addEventListener("pointerup", up);
1447
+ document.addEventListener("pointercancel", up);
1448
+ document.addEventListener("keyup", schedule);
1449
+ if (window.getSelection()?.isCollapsed === false) schedule();
1450
+ return () => {
1451
+ cancelAnimationFrame(frame);
1452
+ document.removeEventListener("selectionchange", schedule);
1453
+ container.removeEventListener("pointerdown", down);
1454
+ document.removeEventListener("pointerup", up);
1455
+ document.removeEventListener("pointercancel", up);
1456
+ document.removeEventListener("keyup", schedule);
1457
+ };
1458
+ }, [runtime, enabled]);
1459
+ }
1460
+
1461
+ // src/react/selection-paint.tsx
1462
+ import { useEffect as useEffect3, useRef as useRef3 } from "react";
1463
+ import { jsx as jsx3 } from "react/jsx-runtime";
1464
+ function rectangles(leaves, source, viewport, measure) {
1465
+ const raw = [];
1466
+ const geometry = (leaf, rect, reference) => {
1467
+ const flowMetrics = measure(leaf.flow);
1468
+ const own = measure(reference?.element ?? (leaf.kind === "text" ? leaf.node.parentElement : leaf.flow));
1469
+ const baseline = reference ? reference.rect.top + own.ascent : leaf.kind === "text" ? rect.top + own.ascent : rect.bottom - flowMetrics.descent;
1470
+ return { left: rect.left, top: baseline - flowMetrics.ascent, width: rect.width, height: flowMetrics.height, baseline, flow: leaf.flow };
1471
+ };
1472
+ const neighbor = (index, direction) => {
1473
+ for (let at = index + direction; at >= 0 && at < leaves.length; at += direction) {
1474
+ const candidate = leaves[at];
1475
+ if (candidate.flow !== leaves[index].flow) return;
1476
+ if (candidate.kind === "text") {
1477
+ const value = candidate.node.textContent ?? "";
1478
+ if (value.trim()) return candidate;
1479
+ if (!value.includes("\n")) continue;
1480
+ }
1481
+ if (candidate.kind !== "marker") return;
1482
+ }
1483
+ };
1484
+ const edgeRect = (leaf, edge) => {
1485
+ const node = leaf.node;
1486
+ const range = document.createRange();
1487
+ const offset = edge === "first" ? 0 : Math.max(0, node.length - 1);
1488
+ range.setStart(node, offset);
1489
+ range.setEnd(node, Math.min(node.length, offset + 1));
1490
+ return range.getBoundingClientRect();
1491
+ };
1492
+ const referenceFor = (index, rect) => {
1493
+ const left = neighbor(index, -1), right = neighbor(index, 1);
1494
+ const candidates = [left && { rect: edgeRect(left, "last"), element: left.node.parentElement }, right && { rect: edgeRect(right, "first"), element: right.node.parentElement }].filter((value) => !!value);
1495
+ candidates.sort((a, b) => Math.abs(a.rect.bottom - rect.bottom) - Math.abs(b.rect.bottom - rect.bottom));
1496
+ const nearest = candidates[0];
1497
+ return nearest && Math.abs(nearest.rect.bottom - rect.bottom) < Math.max(rect.height, nearest.rect.height) ? nearest : void 0;
1498
+ };
1499
+ let first = 0, last = leaves.length;
1500
+ if (leaves.length > 80 && leaves[0].flow.tagName === "PRE" && leaves.at(-1)?.flow === leaves[0].flow) {
1501
+ const boxAt = (index) => {
1502
+ const leaf = leaves[index];
1503
+ if (leaf.kind !== "text") return leaf.node.getBoundingClientRect();
1504
+ const range = document.createRange();
1505
+ range.selectNodeContents(leaf.node);
1506
+ return range.getBoundingClientRect();
1507
+ };
1508
+ let lo = 0, hi = leaves.length;
1509
+ while (lo < hi) {
1510
+ const mid = lo + hi >>> 1;
1511
+ if (boxAt(mid).bottom < viewport.top) lo = mid + 1;
1512
+ else hi = mid;
1513
+ }
1514
+ first = lo;
1515
+ hi = leaves.length;
1516
+ while (lo < hi) {
1517
+ const mid = lo + hi >>> 1;
1518
+ if (boxAt(mid).top <= viewport.bottom) lo = mid + 1;
1519
+ else hi = mid;
1520
+ }
1521
+ last = lo;
1522
+ }
1523
+ for (let index = first; index < last; index++) {
1524
+ const leaf = leaves[index];
1525
+ if (leaf.kind === "marker") {
1526
+ const left = neighbor(index, -1), right = neighbor(index, 1);
1527
+ if (!left || !right || source.start >= left.range.end || source.end <= right.range.start) continue;
1528
+ const rect = leaf.node.getBoundingClientRect();
1529
+ if (!rect.width || !rect.height || rect.bottom < viewport.top || rect.top > viewport.bottom) continue;
1530
+ const item = geometry(leaf, rect, referenceFor(index, rect));
1531
+ raw.push({ ...item, marker: leaf.node.dataset.limrMarker });
1532
+ } else if (intersects(leaf.range, source)) {
1533
+ if (leaf.kind === "text") {
1534
+ const range = textRange(leaf, source, viewport);
1535
+ const shell = leaf.node.parentElement?.closest("[data-limr-inline-syntax]");
1536
+ const edges = shell ? Array.from(shell.getClientRects()) : [];
1537
+ const css = shell && getComputedStyle(shell);
1538
+ for (const rect of range?.getClientRects() ?? []) if (rect.width && rect.height && rect.bottom >= viewport.top && rect.top <= viewport.bottom) {
1539
+ const item = geometry(leaf, rect), first2 = edges[0], last2 = edges.at(-1);
1540
+ if (shell && css && first2 && source.start <= Number(shell.dataset.sourceStart) && Math.abs(first2.top - rect.top) < rect.height && Math.abs(rect.left - first2.left - parseFloat(css.paddingLeft)) < 1) {
1541
+ item.width += item.left - first2.left;
1542
+ item.left = first2.left;
1543
+ }
1544
+ if (shell && css && last2 && source.end >= Number(shell.dataset.sourceEnd) && Math.abs(last2.top - rect.top) < rect.height && Math.abs(last2.right - parseFloat(css.paddingRight) - rect.right) < 1) item.width = last2.right - item.left;
1545
+ raw.push(item);
1546
+ }
1547
+ } else {
1548
+ const element = leaf.node;
1549
+ const surface = leaf.kind === "image" ? element.querySelector("img") ?? element : leaf.kind === "block" ? element.querySelector("[data-limr-selection-surface]") ?? element : element;
1550
+ const rect = surface.getBoundingClientRect();
1551
+ if (!rect.width || !rect.height || rect.bottom < viewport.top || rect.top > viewport.bottom) continue;
1552
+ if (leaf.kind === "block" || leaf.kind === "image") raw.push({ left: rect.left, top: rect.top, width: rect.width, height: rect.height, atomic: true, image: leaf.kind === "image", baseline: rect.bottom, flow: leaf.kind === "image" ? element : surface, radius: getComputedStyle(surface).borderRadius });
1553
+ else {
1554
+ const item = geometry(leaf, rect, referenceFor(index, rect));
1555
+ raw.push({ ...item, atomic: true });
1556
+ }
1557
+ }
1558
+ }
1559
+ }
1560
+ const lines = /* @__PURE__ */ new Map();
1561
+ const aligned = raw.map((rect) => {
1562
+ if (rect.image || rect.atomic && rect.height > measure(rect.flow).height * 1.5) return rect;
1563
+ let flow = lines.get(rect.flow);
1564
+ if (!flow) {
1565
+ flow = /* @__PURE__ */ new Map();
1566
+ lines.set(rect.flow, flow);
1567
+ }
1568
+ const key = Math.floor(rect.baseline / 3);
1569
+ let line = [flow.get(key), flow.get(key - 1), flow.get(key + 1)].find((line2) => line2 && Math.abs(line2.baseline - rect.baseline) < 3);
1570
+ if (!line) {
1571
+ line = rect;
1572
+ flow.set(key, line);
1573
+ }
1574
+ return { ...rect, top: line.top, height: line.height };
1575
+ });
1576
+ const bridges = [];
1577
+ for (let i = 1; i < aligned.length; i++) {
1578
+ const left = aligned[i - 1], right = aligned[i];
1579
+ const gap = right.left - left.left - left.width;
1580
+ if (left.flow === right.flow && Math.abs(left.top - right.top) < 0.5 && gap > 0.1 && gap < left.height * 0.6) bridges.push({ left: left.left + left.width, top: left.top, width: gap, height: left.height, flow: left.flow });
1581
+ }
1582
+ return [...aligned, ...bridges];
1583
+ }
1584
+ function SelectionPaint({ runtime, interactive = true }) {
1585
+ const layer = useRef3(null);
1586
+ useEffect3(() => {
1587
+ const container = runtime.content, paint = layer.current;
1588
+ if (!container || !paint) return;
1589
+ let frame = 0;
1590
+ let leavesCache = /* @__PURE__ */ new WeakMap();
1591
+ let metrics = /* @__PURE__ */ new WeakMap();
1592
+ const fontMetrics = /* @__PURE__ */ new Map();
1593
+ let blocks;
1594
+ let snapshot = runtime.document.getSnapshot();
1595
+ let lastSelection = runtime.interaction.get().selection;
1596
+ let lastDecorations = runtime.decorations.get().byBlock;
1597
+ let lastHovered = runtime.interaction.get().hoveredHighlight;
1598
+ let lastActive = runtime.interaction.get().activeHighlight;
1599
+ let lastAnnotation = runtime.interaction.get().active;
1600
+ let lastHoveredAnnotation = runtime.interaction.get().hovered;
1601
+ const highlightLayers = /* @__PURE__ */ new Map();
1602
+ let hits = [];
1603
+ const highlightRects = (id) => [...highlightLayers.values()].flatMap((layer2) => Array.from(layer2.children).filter((item) => item.dataset.paint === id).map((item) => item.getBoundingClientRect()));
1604
+ const focusedRange = () => {
1605
+ const state = runtime.interaction.get(), decorations = runtime.decorations.get();
1606
+ return decorations.occurrences.find((item) => item.id === state.hovered)?.range ?? (state.activeHighlight ? decorations.highlights.get(state.activeHighlight)?.range : void 0) ?? decorations.occurrences.find((item) => item.id === state.active)?.range;
1607
+ };
1608
+ const feedback = () => {
1609
+ const state = runtime.interaction.get();
1610
+ const decorations = runtime.decorations.get();
1611
+ const focused = focusedRange();
1612
+ for (const layer2 of highlightLayers.values()) for (const item of layer2.children) {
1613
+ item.toggleAttribute("data-hovered", item.dataset.paint === state.hoveredHighlight);
1614
+ const highlight = decorations.highlights.get(item.dataset.paint ?? "");
1615
+ item.toggleAttribute("data-active", item.dataset.paint === state.activeHighlight || !!focused && !!highlight && sameRange(focused, highlight.range));
1616
+ item.toggleAttribute("data-muted", !!highlight?.hidden || !!focused && !!highlight && !sameRange(focused, highlight.range));
1617
+ }
1618
+ };
1619
+ const removeLayer = (host, layer2) => {
1620
+ layer2.remove();
1621
+ delete host.dataset.limrHighlightHost;
1622
+ delete host.dataset.limrHighlightPosition;
1623
+ highlightLayers.delete(host);
1624
+ };
1625
+ const canvas = document.createElement("canvas"), context = canvas.getContext("2d");
1626
+ const measure = (element) => {
1627
+ const saved = metrics.get(element);
1628
+ if (saved) return saved;
1629
+ const style = getComputedStyle(element), size = parseFloat(style.fontSize), lineHeight = parseFloat(style.lineHeight) || size * 1.5;
1630
+ const font = `${style.fontStyle} ${style.fontWeight} ${size}px ${style.fontFamily}`, key = `${font}/${lineHeight}`;
1631
+ let metric = fontMetrics.get(key);
1632
+ if (!metric) {
1633
+ if (context) context.font = font;
1634
+ const text = context?.measureText("Mg");
1635
+ const ascent = text?.fontBoundingBoxAscent ?? size * 0.9, descent = text?.fontBoundingBoxDescent ?? size * 0.25;
1636
+ const height = Math.min(ascent + descent, lineHeight - 0.5);
1637
+ metric = { ascent: ascent - Math.max(0, ascent + descent - height) / 2, descent, height };
1638
+ fontMetrics.set(key, metric);
1639
+ }
1640
+ metrics.set(element, metric);
1641
+ return metric;
1642
+ };
1643
+ const clear = () => {
1644
+ if (paint.childNodes.length) paint.replaceChildren();
1645
+ for (const [host, layer2] of highlightLayers) removeLayer(host, layer2);
1646
+ hits = [];
1647
+ };
1648
+ const render = () => {
1649
+ cancelAnimationFrame(frame);
1650
+ frame = 0;
1651
+ const selections = runtime.interaction.get().selection?.raw.ranges ?? [];
1652
+ const decorations = runtime.decorations.get().byBlock;
1653
+ if (!selections.length && ![...decorations.values()].some((value) => value.highlights.length)) {
1654
+ clear();
1655
+ return;
1656
+ }
1657
+ const doc = runtime.document.getSnapshot();
1658
+ if (doc !== snapshot) {
1659
+ snapshot = doc;
1660
+ blocks = void 0;
1661
+ }
1662
+ if (!blocks) {
1663
+ const notes = new Map(doc.blocks.filter((block) => block.node.type === "footnoteDefinition").map((block) => [String(block.node.identifier), block]));
1664
+ const ordered = [...doc.blocks.filter((block) => block.node.type !== "footnoteDefinition"), ...doc.footnoteOrder.flatMap((id) => {
1665
+ const block = notes.get(id), node = doc.footnotes.get(id);
1666
+ return block ? [block] : node ? [{ id: `${doc.id}-fn-${id}`, range: { start: node.position.start.offset, end: node.position.end.offset } }] : [];
1667
+ })];
1668
+ blocks = ordered.flatMap((block) => {
1669
+ const element = runtime.blocks.get(block.id);
1670
+ return element ? [{ element, range: block.range, id: block.id }] : [];
1671
+ });
1672
+ }
1673
+ const vv = window.visualViewport;
1674
+ const viewport = { top: vv?.offsetTop ?? 0, bottom: (vv?.offsetTop ?? 0) + (vv?.height ?? window.innerHeight), left: vv?.offsetLeft ?? 0, right: (vv?.offsetLeft ?? 0) + (vv?.width ?? window.innerWidth) };
1675
+ const root = runtime.configuration.get().scrollRoot;
1676
+ if (root) {
1677
+ const box = root.getBoundingClientRect();
1678
+ viewport.top = Math.max(viewport.top, box.top + root.clientTop);
1679
+ viewport.bottom = Math.min(viewport.bottom, box.top + root.clientTop + root.clientHeight);
1680
+ viewport.left = Math.max(viewport.left, box.left + root.clientLeft);
1681
+ viewport.right = Math.min(viewport.right, box.left + root.clientLeft + root.clientWidth);
1682
+ }
1683
+ let lo = 0, hi = blocks.length;
1684
+ while (lo < hi) {
1685
+ const mid = lo + hi >>> 1;
1686
+ if (blocks[mid].element.getBoundingClientRect().bottom < viewport.top - 32) lo = mid + 1;
1687
+ else hi = mid;
1688
+ }
1689
+ const origin = container.getBoundingClientRect();
1690
+ viewport.top = Math.max(viewport.top, origin.top);
1691
+ viewport.bottom = Math.min(viewport.bottom, origin.bottom);
1692
+ const scrollLeft = container.scrollLeft, scrollTop = container.scrollTop;
1693
+ const output = [];
1694
+ const clips = /* @__PURE__ */ new Map();
1695
+ const clipFor = (flow) => {
1696
+ const saved = clips.get(flow);
1697
+ if (saved) return saved;
1698
+ const clip = { ...viewport };
1699
+ for (let element = flow; element && element !== container; element = element.parentElement) {
1700
+ const css = getComputedStyle(element), box = element.getBoundingClientRect();
1701
+ if (/hidden|clip|auto|scroll/.test(css.overflowX)) {
1702
+ clip.left = Math.max(clip.left, box.left + element.clientLeft);
1703
+ clip.right = Math.min(clip.right, box.left + element.clientLeft + element.clientWidth);
1704
+ }
1705
+ if (/hidden|clip|auto|scroll/.test(css.overflowY)) {
1706
+ clip.top = Math.max(clip.top, box.top + element.clientTop);
1707
+ clip.bottom = Math.min(clip.bottom, box.top + element.clientTop + element.clientHeight);
1708
+ }
1709
+ }
1710
+ clips.set(flow, clip);
1711
+ return clip;
1712
+ };
1713
+ for (let index = lo; index < blocks.length; index++) {
1714
+ const block = blocks[index];
1715
+ if (block.element.getBoundingClientRect().top > viewport.bottom + 32) break;
1716
+ const tasks = [...decorations.get(block.id)?.highlights ?? []];
1717
+ for (const range of selections) if (intersects(range, block.range)) tasks.push({ id: "selection", range, selection: true });
1718
+ if (!tasks.length) continue;
1719
+ let leaves = leavesCache.get(block.element);
1720
+ if (!leaves) {
1721
+ leaves = leavesIn(block.element, runtime);
1722
+ leavesCache.set(block.element, leaves);
1723
+ }
1724
+ for (const task of tasks) {
1725
+ const rects = rectangles(leaves, task.range, { ...viewport, top: viewport.top - 32, bottom: viewport.bottom + 32 }, measure);
1726
+ for (const rect of rects) {
1727
+ const clip = clipFor(rect.flow);
1728
+ const left = Math.max(rect.left, clip.left), top = Math.max(rect.top, clip.top);
1729
+ const width = Math.min(rect.left + rect.width, clip.right) - left, height = Math.min(rect.top + rect.height, clip.bottom) - top;
1730
+ if (width <= 0 || height <= 0) continue;
1731
+ output.push({ rect: { ...rect, left: left - origin.left + scrollLeft, top: top - viewport.top, width, height }, task });
1732
+ }
1733
+ }
1734
+ }
1735
+ paint.style.top = `${viewport.top - origin.top + scrollTop}px`;
1736
+ paint.style.height = `${Math.max(0, viewport.bottom - viewport.top)}px`;
1737
+ const hostGeometry = /* @__PURE__ */ new Map();
1738
+ for (const { rect, task } of output) if (!task.selection && !hostGeometry.has(rect.flow)) {
1739
+ const host = rect.flow, box = host.getBoundingClientRect();
1740
+ hostGeometry.set(host, { box, top: Math.max(viewport.top, box.top) - box.top - host.clientTop + host.scrollTop, positioned: getComputedStyle(host).position !== "static" });
1741
+ }
1742
+ const counts = /* @__PURE__ */ new Map();
1743
+ const nextHits = [];
1744
+ output.forEach(({ rect, task }) => {
1745
+ let target = paint, left = rect.left, top = rect.top;
1746
+ if (!task.selection) {
1747
+ const host = rect.flow, geometry = hostGeometry.get(host);
1748
+ let layer2 = highlightLayers.get(host);
1749
+ if (!layer2) {
1750
+ layer2 = document.createElement("span");
1751
+ layer2.className = "limr-highlight-layer";
1752
+ layer2.dataset.limrIgnore = "true";
1753
+ layer2.setAttribute("aria-hidden", "true");
1754
+ host.dataset.limrHighlightHost = "true";
1755
+ if (!geometry.positioned) host.dataset.limrHighlightPosition = "true";
1756
+ host.append(layer2);
1757
+ highlightLayers.set(host, layer2);
1758
+ }
1759
+ layer2.style.top = `${geometry.top}px`;
1760
+ layer2.style.height = `${Math.max(0, Math.min(viewport.bottom, geometry.box.bottom) - Math.max(viewport.top, geometry.box.top))}px`;
1761
+ target = layer2;
1762
+ left += origin.left - geometry.box.left - host.clientLeft + host.scrollLeft;
1763
+ top += viewport.top - geometry.box.top - host.clientTop + host.scrollTop - geometry.top;
1764
+ nextHits.push({ id: task.id, rect: { left: rect.left + origin.left - scrollLeft, top: rect.top + viewport.top, width: rect.width, height: rect.height } });
1765
+ }
1766
+ const index = counts.get(target) ?? 0;
1767
+ counts.set(target, index + 1);
1768
+ const item = target.children[index] ?? document.createElement("span");
1769
+ const className = `limr-paint-rect limr-paint-${task.selection ? "selection" : task.style ?? "background"}`;
1770
+ if (item.className !== className) item.className = className;
1771
+ item.dataset.paint = task.id;
1772
+ if (rect.marker) item.dataset.marker = rect.marker;
1773
+ else delete item.dataset.marker;
1774
+ if (rect.atomic) item.dataset.atomic = "true";
1775
+ else delete item.dataset.atomic;
1776
+ if (rect.image) item.dataset.media = "image";
1777
+ else delete item.dataset.media;
1778
+ const css = `left:${left}px;top:${top}px;width:${rect.width}px;height:${rect.height}px;border-radius:${rect.radius ?? "0"};`;
1779
+ if (item.dataset.geometry !== css) {
1780
+ item.style.cssText = css;
1781
+ item.dataset.geometry = css;
1782
+ }
1783
+ if (!task.selection) item.style.setProperty("--limr-highlight", task.color ?? "#F2C744");
1784
+ if (!item.parentNode) target.append(item);
1785
+ });
1786
+ for (const layer2 of [paint, ...highlightLayers.values()]) while (layer2.children.length > (counts.get(layer2) ?? 0)) layer2.lastChild.remove();
1787
+ for (const [host, layer2] of highlightLayers) if (!counts.has(layer2)) removeLayer(host, layer2);
1788
+ hits = nextHits;
1789
+ const active = runtime.interaction.get().activeHighlight;
1790
+ if (active && !hits.some((hit) => hit.id === active)) runtime.clearSelection();
1791
+ feedback();
1792
+ };
1793
+ const schedule = () => {
1794
+ if (!frame) frame = requestAnimationFrame(render);
1795
+ };
1796
+ const invalidate = () => {
1797
+ blocks = void 0;
1798
+ metrics = /* @__PURE__ */ new WeakMap();
1799
+ schedule();
1800
+ };
1801
+ const fontsChanged = () => {
1802
+ fontMetrics.clear();
1803
+ invalidate();
1804
+ };
1805
+ const unsubscribers = [runtime.interaction.subscribe(() => {
1806
+ const state = runtime.interaction.get(), selection = state.selection;
1807
+ if (state.hoveredHighlight !== lastHovered || state.activeHighlight !== lastActive || state.active !== lastAnnotation || state.hovered !== lastHoveredAnnotation) {
1808
+ lastHovered = state.hoveredHighlight;
1809
+ lastActive = state.activeHighlight;
1810
+ lastAnnotation = state.active;
1811
+ lastHoveredAnnotation = state.hovered;
1812
+ feedback();
1813
+ }
1814
+ if (selection === lastSelection) return;
1815
+ lastSelection = selection;
1816
+ render();
1817
+ }), runtime.decorations.subscribe(() => {
1818
+ const decorations = runtime.decorations.get().byBlock;
1819
+ if (decorations === lastDecorations) return;
1820
+ lastDecorations = decorations;
1821
+ leavesCache = /* @__PURE__ */ new WeakMap();
1822
+ schedule();
1823
+ }), runtime.layout.subscribe(invalidate), runtime.configuration.subscribe(invalidate)];
1824
+ const observer = new MutationObserver((records) => {
1825
+ let changed = false;
1826
+ for (const record of records) {
1827
+ const target = record.target instanceof Element ? record.target : record.target.parentElement;
1828
+ if (!target || target === paint || paint.contains(target) || target.closest(".limr-highlight-layer")) continue;
1829
+ if (record.type === "childList" && [...record.addedNodes, ...record.removedNodes].every((node) => node instanceof Element && node.classList.contains("limr-highlight-layer"))) continue;
1830
+ const block = target.closest("[data-limr-block]");
1831
+ if (block) leavesCache.delete(block);
1832
+ else blocks = void 0;
1833
+ changed = true;
1834
+ }
1835
+ if (changed) {
1836
+ metrics = /* @__PURE__ */ new WeakMap();
1837
+ schedule();
1838
+ }
1839
+ });
1840
+ observer.observe(container, { subtree: true, childList: true, characterData: true, attributes: true, attributeFilter: ["class", "style", "inert", "open", "data-limr-theme", "data-limr-justify"] });
1841
+ const scroll = () => {
1842
+ runtime.hoverHighlight(null);
1843
+ schedule();
1844
+ };
1845
+ document.addEventListener("scroll", scroll, { capture: true, passive: true });
1846
+ window.visualViewport?.addEventListener("resize", schedule);
1847
+ window.visualViewport?.addEventListener("scroll", schedule);
1848
+ document.fonts?.addEventListener("loadingdone", fontsChanged);
1849
+ const hitAt = (event) => {
1850
+ const element = event.target instanceof Element ? event.target : null;
1851
+ if (!element || element.closest("[data-limr-document]") !== container || element.closest("button,input,textarea,select,[contenteditable],[data-limr-ignore]")) return null;
1852
+ const focused = focusedRange(), decorations = runtime.decorations.get();
1853
+ for (let index = hits.length - 1; index >= 0; index--) {
1854
+ const { rect, id } = hits[index];
1855
+ const highlight = decorations.highlights.get(id);
1856
+ if (highlight?.hidden || focused && highlight && !sameRange(focused, highlight.range)) continue;
1857
+ if (event.clientX >= rect.left && event.clientX <= rect.left + rect.width && event.clientY >= rect.top && event.clientY <= rect.top + rect.height) return id;
1858
+ }
1859
+ return null;
1860
+ };
1861
+ const move = (event) => {
1862
+ if (!event.buttons) runtime.hoverHighlight(hitAt(event));
1863
+ };
1864
+ const leave = () => runtime.hoverHighlight(null);
1865
+ let down = null;
1866
+ const pointerDown = (event) => {
1867
+ down = { x: event.clientX, y: event.clientY };
1868
+ };
1869
+ const click = (event) => {
1870
+ if (event.defaultPrevented || event.button !== 0 || event.metaKey || event.ctrlKey || event.shiftKey || event.altKey || !down || Math.hypot(event.clientX - down.x, event.clientY - down.y) > 4 || window.getSelection()?.isCollapsed === false) return;
1871
+ const id = hitAt(event);
1872
+ if (!id) return;
1873
+ event.preventDefault();
1874
+ const highlight = runtime.decorations.get().highlights.get(id);
1875
+ const text = [];
1876
+ let atomic2 = false;
1877
+ for (const block of runtime.document.getSnapshot().blocks) {
1878
+ if (!intersects(block.range, highlight.range)) continue;
1879
+ const element = runtime.blocks.get(block.id);
1880
+ if (!element) continue;
1881
+ const parts2 = [];
1882
+ for (const leaf of leavesIn(element, runtime)) {
1883
+ if (!intersects(leaf.range, highlight.range) || leaf.kind === "marker") continue;
1884
+ if (leaf.kind !== "text") {
1885
+ atomic2 = true;
1886
+ continue;
1887
+ }
1888
+ const range = textRange(leaf, highlight.range, { top: -Infinity, bottom: Infinity, left: -Infinity, right: Infinity });
1889
+ if (range) parts2.push(range.toString());
1890
+ }
1891
+ if (parts2.length) text.push(parts2.join(""));
1892
+ }
1893
+ runtime.highlightReference = {
1894
+ text: !atomic2 && text.length ? text.join("\n\n") : void 0,
1895
+ getClientRects: () => highlightRects(id),
1896
+ getBoundingClientRect: () => {
1897
+ const rects = highlightRects(id);
1898
+ if (!rects.length) return new DOMRect();
1899
+ const left = Math.min(...rects.map((rect) => rect.left)), top = Math.min(...rects.map((rect) => rect.top));
1900
+ return new DOMRect(left, top, Math.max(...rects.map((rect) => rect.right)) - left, Math.max(...rects.map((rect) => rect.bottom)) - top);
1901
+ }
1902
+ };
1903
+ runtime.activateHighlight(id);
1904
+ };
1905
+ if (interactive) {
1906
+ container.addEventListener("pointermove", move);
1907
+ container.addEventListener("pointerleave", leave);
1908
+ container.addEventListener("pointerdown", pointerDown);
1909
+ container.addEventListener("click", click);
1910
+ }
1911
+ container.dataset.limrPainted = "true";
1912
+ schedule();
1913
+ return () => {
1914
+ cancelAnimationFrame(frame);
1915
+ observer.disconnect();
1916
+ unsubscribers.forEach((unsubscribe) => unsubscribe());
1917
+ document.removeEventListener("scroll", scroll, true);
1918
+ window.visualViewport?.removeEventListener("resize", schedule);
1919
+ window.visualViewport?.removeEventListener("scroll", schedule);
1920
+ document.fonts?.removeEventListener("loadingdone", fontsChanged);
1921
+ container.removeEventListener("pointermove", move);
1922
+ container.removeEventListener("pointerleave", leave);
1923
+ container.removeEventListener("pointerdown", pointerDown);
1924
+ container.removeEventListener("click", click);
1925
+ delete container.dataset.limrPainted;
1926
+ clear();
1927
+ };
1928
+ }, [runtime, interactive]);
1929
+ return /* @__PURE__ */ jsx3("div", { ref: layer, className: "limr-paint-layer", "data-limr-ignore": "true", "aria-hidden": "true" });
1930
+ }
1931
+
1932
+ // src/react/Markdown.tsx
1933
+ import { jsx as jsx4, jsxs as jsxs3 } from "react/jsx-runtime";
1934
+ function Markdown({ className, style, interactive = true, followOutput = false, justify, ...props }) {
1935
+ const parent = useContext(RuntimeContext);
1936
+ if (props.source !== void 0 || !parent) return /* @__PURE__ */ jsx4(DocumentProvider, { ...props, justify, children: /* @__PURE__ */ jsx4(MarkdownBody, { className, style, interactive, followOutput }) });
1937
+ return /* @__PURE__ */ jsx4(MarkdownBody, { className, style, interactive, followOutput, justify });
1938
+ }
1939
+ function MarkdownBody({ className, style, interactive, followOutput, justify }) {
1940
+ const runtime = useRuntime();
1941
+ const document2 = useDocument();
1942
+ const appearance = useAppearance();
1943
+ const theme = useStoreSelector(runtime.configuration, (config) => config.theme ?? "light");
1944
+ const configuredJustify = useStoreSelector(runtime.configuration, (config) => config.justify ?? false);
1945
+ const scrollRoot = useStoreSelector(runtime.configuration, (config) => config.scrollRoot);
1946
+ const offset = useStoreSelector(runtime.documentOffset, (value) => value);
1947
+ const components = useStoreSelector(runtime.configuration, (config) => config.components);
1948
+ const extensions = useStoreSelector(runtime.configuration, (config) => config.extensions);
1949
+ const decorations = useStoreSelector(runtime.decorations, (state) => state.byBlock);
1950
+ const ref = useRef4(null);
1951
+ const pinned = useRef4(true);
1952
+ useIsomorphicLayoutEffect(() => ref.current ? runtime.mountContent(ref.current) : void 0, [runtime, scrollRoot]);
1953
+ useIsomorphicLayoutEffect(() => runtime.requestLayout(), [runtime, justify, configuredJustify]);
1954
+ useSelectionTracking(runtime, interactive);
1955
+ useEffect4(() => {
1956
+ if (!followOutput) return;
1957
+ const root = scrollRoot ?? window;
1958
+ const onScroll = () => {
1959
+ const element = scrollRoot ?? window.document.documentElement;
1960
+ const viewport = scrollRoot?.clientHeight ?? window.innerHeight;
1961
+ pinned.current = element.scrollHeight - runtime.getScrollTop() - viewport < 48;
1962
+ };
1963
+ root.addEventListener("scroll", onScroll, { passive: true });
1964
+ return () => root.removeEventListener("scroll", onScroll);
1965
+ }, [runtime, followOutput, scrollRoot]);
1966
+ useIsomorphicLayoutEffect(() => {
1967
+ if (!followOutput || !document2.streaming || !pinned.current) return;
1968
+ const frame = requestAnimationFrame(() => runtime.scrollTo(scrollRoot?.scrollHeight ?? window.document.documentElement.scrollHeight, "instant"));
1969
+ return () => cancelAnimationFrame(frame);
1970
+ }, [document2, runtime, followOutput, scrollRoot]);
1971
+ return /* @__PURE__ */ jsxs3("article", { ref, className: `limr-prose ${className ?? ""}`, style: { ...style, translate: offset ? `0 ${offset}px` : style?.translate }, "data-limr-theme": theme, "data-limr-appearance": appearance, "data-limr-document": document2.id, "data-limr-justify": justify ?? configuredJustify, children: [
1972
+ document2.blocks.map((block) => /* @__PURE__ */ jsx4(BlockView, { block, runtime, components, extensions, decorations: decorations.get(block.id) ?? emptyDecorations }, block.id)),
1973
+ /* @__PURE__ */ jsx4(Footnotes, {}),
1974
+ /* @__PURE__ */ jsx4(SelectionPaint, { runtime, interactive })
1975
+ ] });
1976
+ }
1977
+
1978
+ // src/components/OverlayScrollArea.tsx
1979
+ import { useRef as useRef5 } from "react";
1980
+ import { jsx as jsx5, jsxs as jsxs4 } from "react/jsx-runtime";
1981
+ function OverlayScrollArea({ children, active, resetKey, label }) {
1982
+ const area = useRef5(null);
1983
+ const content = useRef5(null);
1984
+ const thumb = useRef5(null);
1985
+ const track = useRef5(null);
1986
+ const drag = useRef5(null);
1987
+ const show = useRef5(() => {
1988
+ });
1989
+ useIsomorphicLayoutEffect(() => {
1990
+ const element = area.current, wrapper = element.parentElement;
1991
+ delete wrapper.dataset.scrolling;
1992
+ if (!active) return;
1993
+ element.scrollTop = 0;
1994
+ let frame = 0, timeout, previous = 0;
1995
+ const update = () => {
1996
+ frame = 0;
1997
+ const height = track.current.clientHeight;
1998
+ const overflow = element.scrollHeight - element.clientHeight;
1999
+ const size = Math.min(height, Math.max(20, height * element.clientHeight / Math.max(1, element.scrollHeight)));
2000
+ wrapper.toggleAttribute("data-overflow", overflow > 1);
2001
+ thumb.current.style.height = `${size}px`;
2002
+ thumb.current.style.transform = `translateY(${overflow > 0 ? Math.max(0, Math.min(1, element.scrollTop / overflow)) * (height - size) : 0}px)`;
2003
+ };
2004
+ const schedule = () => {
2005
+ if (!frame) frame = requestAnimationFrame(update);
2006
+ };
2007
+ show.current = () => {
2008
+ clearTimeout(timeout);
2009
+ if (wrapper.closest("[data-motion]")) return;
2010
+ wrapper.dataset.scrolling = "true";
2011
+ timeout = setTimeout(() => {
2012
+ if (!drag.current) delete wrapper.dataset.scrolling;
2013
+ }, 800);
2014
+ };
2015
+ const scroll = () => {
2016
+ schedule();
2017
+ if (element.scrollTop === previous) return;
2018
+ previous = element.scrollTop;
2019
+ show.current();
2020
+ };
2021
+ const observer = new ResizeObserver(schedule);
2022
+ observer.observe(element);
2023
+ observer.observe(content.current);
2024
+ element.addEventListener("scroll", scroll, { passive: true });
2025
+ update();
2026
+ return () => {
2027
+ observer.disconnect();
2028
+ element.removeEventListener("scroll", scroll);
2029
+ cancelAnimationFrame(frame);
2030
+ clearTimeout(timeout);
2031
+ drag.current = null;
2032
+ show.current = () => {
2033
+ };
2034
+ delete wrapper.dataset.scrolling;
2035
+ };
2036
+ }, [active, resetKey]);
2037
+ const startDrag = (event) => {
2038
+ if (event.button !== 0) return;
2039
+ const element = area.current, bar = thumb.current;
2040
+ const travel = track.current.clientHeight - bar.offsetHeight;
2041
+ if (travel <= 0) return;
2042
+ event.preventDefault();
2043
+ event.currentTarget.setPointerCapture(event.pointerId);
2044
+ const scale = (element.scrollHeight - element.clientHeight) / travel;
2045
+ if (event.target !== bar) element.scrollTop = (event.clientY - track.current.getBoundingClientRect().top - bar.offsetHeight / 2) * scale;
2046
+ drag.current = { pointerId: event.pointerId, y: event.clientY, scroll: element.scrollTop, scale };
2047
+ show.current();
2048
+ };
2049
+ const move = (event) => {
2050
+ const current = drag.current;
2051
+ if (current?.pointerId === event.pointerId) area.current.scrollTop = current.scroll + (event.clientY - current.y) * current.scale;
2052
+ };
2053
+ const end = (event) => {
2054
+ if (drag.current?.pointerId !== event.pointerId) return;
2055
+ drag.current = null;
2056
+ if (event.currentTarget.hasPointerCapture(event.pointerId)) event.currentTarget.releasePointerCapture(event.pointerId);
2057
+ show.current();
2058
+ };
2059
+ return /* @__PURE__ */ jsxs4("div", { className: "limr-overlay-scroll", children: [
2060
+ /* @__PURE__ */ jsx5("div", { ref: area, className: "limr-overlay-content", "data-limr-card-body": "", tabIndex: 0, role: "region", "aria-label": label, children: /* @__PURE__ */ jsx5("div", { ref: content, className: "limr-overlay-scroll-inner", children }) }),
2061
+ /* @__PURE__ */ jsx5("div", { ref: track, className: "limr-overlay-scrollbar", "aria-hidden": "true", onPointerDown: startDrag, onPointerMove: move, onPointerUp: end, onPointerCancel: end, onLostPointerCapture: end, children: /* @__PURE__ */ jsx5("div", { ref: thumb, className: "limr-overlay-scroll-thumb" }) })
2062
+ ] });
2063
+ }
2064
+
2065
+ // src/components/AnnotationCard.tsx
2066
+ import { Fragment as Fragment3, jsx as jsx6, jsxs as jsxs5 } from "react/jsx-runtime";
2067
+ function AnnotationCard({ title, bodyLabel, occurrence, expanded, pinned, canExpand, expand, collapse, close, children }) {
2068
+ const locale = useLocale();
2069
+ return /* @__PURE__ */ jsxs5(Fragment3, { children: [
2070
+ /* @__PURE__ */ jsxs5("div", { className: "limr-overlay-header", children: [
2071
+ /* @__PURE__ */ jsx6("span", { children: title }),
2072
+ /* @__PURE__ */ jsxs5("div", { className: "limr-overlay-controls", children: [
2073
+ expanded ? /* @__PURE__ */ jsx6("button", { type: "button", onClick: collapse, children: /* @__PURE__ */ jsx6("span", { className: "limr-underline", children: locale.collapse }) }) : canExpand && /* @__PURE__ */ jsx6("button", { type: "button", onClick: expand, children: /* @__PURE__ */ jsx6("span", { className: "limr-underline", children: locale.expand }) }),
2074
+ pinned && /* @__PURE__ */ jsx6("button", { type: "button", className: "limr-overlay-close", onClick: close, "aria-label": locale.close, children: "\xD7" })
2075
+ ] })
2076
+ ] }),
2077
+ /* @__PURE__ */ jsx6(OverlayScrollArea, { active: true, resetKey: occurrence.id, label: bodyLabel ?? (typeof title === "string" ? title : locale.annotations), children })
2078
+ ] });
2079
+ }
2080
+
2081
+ // src/extensions/annotations.tsx
2082
+ import { jsx as jsx7, jsxs as jsxs6 } from "react/jsx-runtime";
2083
+ var CitationParagraph = ({ children }) => /* @__PURE__ */ jsx7("p", { children: /* @__PURE__ */ jsx7("span", { className: "limr-underline", children }) });
2084
+ function CitationIcon() {
2085
+ return /* @__PURE__ */ jsx7("svg", { viewBox: "0 0 16 16", "aria-hidden": "true", fill: "currentColor", children: /* @__PURE__ */ jsx7("path", { d: "M2.5 4.2h4.3v4.3c0 2.1-1.2 3.3-3.5 3.8l-.5-1.4c1.4-.4 2-1 2-2H2.5V4.2Zm6.7 0h4.3v4.3c0 2.1-1.2 3.3-3.5 3.8l-.5-1.4c1.4-.4 2-1 2-2H9.2V4.2Z" }) });
2086
+ }
2087
+ function AnnotationMarkdown({ source, className, ...props }) {
2088
+ const runtime = useRuntime();
2089
+ const config = useStoreSelector(runtime.configuration, (config2) => config2);
2090
+ return /* @__PURE__ */ jsx7(Markdown, { source, extensions: config.extensions, parameters: config.parameters, components: config.components, annotationTypes: config.annotationTypes, theme: config.theme, appearance: config.appearance, locale: config.locale, interactive: false, ...props, className: `limr-annotation-markdown ${className ?? ""}` });
2091
+ }
2092
+ function citation(options = {}) {
2093
+ function Preview({ annotations }) {
2094
+ const summary = useMemo2(() => annotations.filter((annotation) => annotation.type === (options.type ?? "citation")).map((annotation) => {
2095
+ const data = annotation.data;
2096
+ const source = data?.summary?.trim() || data?.description?.trim();
2097
+ if (source) return fromMarkdown(source).children?.map(textContent).join(" ").replace(/\s+/g, " ").trim();
2098
+ return safeUrl(data?.url) || data?.title;
2099
+ }).filter(Boolean).join(" \xB7 "), [annotations]);
2100
+ return summary ? /* @__PURE__ */ jsx7("span", { title: summary, children: summary }) : null;
2101
+ }
2102
+ function Card(props) {
2103
+ const locale = useLocale();
2104
+ return /* @__PURE__ */ jsx7(AnnotationCard, { ...props, title: locale.annotations });
2105
+ }
2106
+ function Content({ data }) {
2107
+ const runtime = useRuntime();
2108
+ const configured = useStoreSelector(runtime.configuration, () => runtime.components);
2109
+ const components = useMemo2(() => ({ ...configured, paragraph: configured.paragraph ?? CitationParagraph }), [configured]);
2110
+ const link = useRef6(null);
2111
+ const url = safeUrl(data?.url);
2112
+ return /* @__PURE__ */ jsxs6("div", { className: "limr-citation-content", "data-linked": !!url || void 0, onClick: (event) => {
2113
+ if (url && !event.defaultPrevented && !event.target.closest('a,button,input,textarea,select,summary,[role="button"],[contenteditable="true"],[data-limr-card-interactive]') && window.getSelection()?.isCollapsed !== false) link.current?.click();
2114
+ }, children: [
2115
+ /* @__PURE__ */ jsx7("a", { ref: link, className: "limr-citation-title", href: url, target: "_blank", rel: "noopener noreferrer", children: /* @__PURE__ */ jsx7("span", { className: "limr-underline", children: data?.title ?? data?.url ?? "Citation" }) }),
2116
+ (data?.description || data?.summary) && /* @__PURE__ */ jsx7(AnnotationMarkdown, { source: data.description || data.summary, components })
2117
+ ] });
2118
+ }
2119
+ return {
2120
+ name: "citation",
2121
+ tags: ["citation", "ref"],
2122
+ scope: "local",
2123
+ annotationTypes: [{ type: "citation", label: "Citation", icon: CitationIcon, color: "#6366f1", Content, ...options, sidebar: { Preview, collapseOnContentClick: false, ...options.sidebar }, overlay: { Card, expand: false, ...options.overlay } }],
2124
+ transform(root) {
2125
+ walk(root, (node) => {
2126
+ if (node.type !== "component") return;
2127
+ if (node.name === "citation") {
2128
+ const attributes = node.attributes ?? {};
2129
+ const id = String(attributes["cite-id"] ?? attributes.id ?? "");
2130
+ node.type = "annotationDefinition";
2131
+ node.annotation = { id, type: "citation", data: { title: attributes.title, url: attributes.url, description: attributes.desc ?? attributes.description, summary: attributes.summary } };
2132
+ } else if (node.name === "ref") {
2133
+ const value = String(node.attributes?.["cite-from-ids"] ?? node.attributes?.ids ?? node.attributes?.id ?? "");
2134
+ let ids;
2135
+ try {
2136
+ const parsed = JSON.parse(value);
2137
+ ids = Array.isArray(parsed) ? parsed.map(String) : [String(parsed)];
2138
+ } catch {
2139
+ ids = value.split(",").map((id) => id.trim()).filter(Boolean);
2140
+ }
2141
+ node.type = "annotationReference";
2142
+ node.annotationIds = ids;
2143
+ }
2144
+ });
2145
+ }
2146
+ };
2147
+ }
2148
+
2149
+ // src/extensions/translations.tsx
2150
+ import { useRef as useRef8, useState as useState3 } from "react";
2151
+
2152
+ // src/components/InlineMarker.tsx
2153
+ import { forwardRef } from "react";
2154
+ import { jsx as jsx8 } from "react/jsx-runtime";
2155
+ var InlineMarker = forwardRef(function InlineMarker2({ label, color, children, className = "", style, ...props }, ref) {
2156
+ return /* @__PURE__ */ jsx8("span", { className: "limr-mark-wrap", "data-limr-ignore": "true", children: /* @__PURE__ */ jsx8(
2157
+ "button",
2158
+ {
2159
+ ...props,
2160
+ ref,
2161
+ type: "button",
2162
+ "aria-label": label,
2163
+ title: props.title ?? label,
2164
+ className: `limr-mark limr-action-mark ${className}`,
2165
+ style: { "--limr-mark-color": color, ...style },
2166
+ children: /* @__PURE__ */ jsx8("span", { className: "limr-mark-icon", children })
2167
+ }
2168
+ ) });
2169
+ });
2170
+
2171
+ // src/components/Collapse.tsx
2172
+ import { useRef as useRef7, useState as useState2 } from "react";
2173
+ import { jsx as jsx9 } from "react/jsx-runtime";
2174
+ function Collapse({ open, children, className = "", keepMounted = false }) {
2175
+ const [mounted, setMounted] = useState2(open);
2176
+ const [visible, setVisible] = useState2(open);
2177
+ const panel = useRef7(null);
2178
+ useIsomorphicLayoutEffect(() => {
2179
+ if (keepMounted) return;
2180
+ if (open) {
2181
+ if (!mounted) {
2182
+ setMounted(true);
2183
+ return;
2184
+ }
2185
+ panel.current?.getBoundingClientRect();
2186
+ setVisible(true);
2187
+ return;
2188
+ }
2189
+ setVisible(false);
2190
+ const timer = setTimeout(() => setMounted(false), 420);
2191
+ return () => clearTimeout(timer);
2192
+ }, [open, keepMounted, mounted]);
2193
+ return /* @__PURE__ */ jsx9("div", { ref: (element) => {
2194
+ panel.current = element;
2195
+ element?.toggleAttribute("inert", !open);
2196
+ }, className: `limr-collapse ${className}`, "data-open": (keepMounted ? open : visible) || void 0, "aria-hidden": !open, children: /* @__PURE__ */ jsx9("div", { className: "limr-collapse-inner", children: mounted || keepMounted ? children : null }) });
2197
+ }
2198
+
2199
+ // src/extensions/translations.tsx
2200
+ import { Fragment as Fragment4, jsx as jsx10, jsxs as jsxs7 } from "react/jsx-runtime";
2201
+ var modes = ["origin", "translation", "both"];
2202
+ var names = { origin: "\u539F\u6587", translation: "\u8BD1\u6587", both: "\u5BF9\u7167" };
2203
+ function TranslationIcon({ mode }) {
2204
+ return /* @__PURE__ */ jsx10("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: mode === "both" ? /* @__PURE__ */ jsxs7(Fragment4, { children: [
2205
+ /* @__PURE__ */ jsx10("rect", { x: "2.5", y: "4", width: "8", height: "16", rx: "2.5" }),
2206
+ /* @__PURE__ */ jsx10("rect", { x: "13.5", y: "4", width: "8", height: "16", rx: "2.5" }),
2207
+ /* @__PURE__ */ jsx10("path", { d: "M5 9h3M5 12h3M16 9h3M16 12h3" })
2208
+ ] }) : /* @__PURE__ */ jsxs7(Fragment4, { children: [
2209
+ /* @__PURE__ */ jsx10("rect", { x: "4.5", y: "3", width: "15", height: "18", rx: "3" }),
2210
+ mode === "origin" ? /* @__PURE__ */ jsx10("path", { d: "M8.5 8h7M8.5 12h7M8.5 16h4" }) : /* @__PURE__ */ jsx10("path", { d: "M8 8.5h8M12 6.5v2M14.5 8.5c-.5 4-3 6.5-6.5 8M9.5 11c1.2 2.5 3.2 4.2 6.5 5.5" })
2211
+ ] }) });
2212
+ }
2213
+ function modeOf(value, fallback) {
2214
+ return modes.includes(value) ? value : fallback;
2215
+ }
2216
+ function section(node, name) {
2217
+ for (const child of node.children ?? []) {
2218
+ if (child.name === name) return child;
2219
+ if (child.type === "paragraph") {
2220
+ const found = section(child, name);
2221
+ if (found) return found;
2222
+ }
2223
+ }
2224
+ }
2225
+ function translations(options = {}) {
2226
+ function Translations({ node, children, renderChildren }) {
2227
+ const origin = section(node, "origin"), translation = section(node, "translation");
2228
+ const [localMode, setLocalMode] = useState3();
2229
+ const globalMode = useRendererParameter("translationMode");
2230
+ const onGlobalChange = useRendererParameter("onTranslationModeChange");
2231
+ const requested = modeOf(globalMode ?? localMode ?? node.attributes?.default, options.defaultMode ?? "origin");
2232
+ const mode = !origin ? "translation" : !translation ? "origin" : requested;
2233
+ const next = modes[(modes.indexOf(mode) + 1) % modes.length];
2234
+ const marker = useRef8(null);
2235
+ const restoreFocus = useRef8(false);
2236
+ const locked = globalMode !== void 0 && !onGlobalChange;
2237
+ useIsomorphicLayoutEffect(() => {
2238
+ if (restoreFocus.current) {
2239
+ marker.current?.focus({ preventScroll: true });
2240
+ restoreFocus.current = false;
2241
+ }
2242
+ }, [mode]);
2243
+ if (!origin && !translation) return /* @__PURE__ */ jsx10(Fragment4, { children });
2244
+ const toggle = origin && translation ? /* @__PURE__ */ jsx10(
2245
+ InlineMarker,
2246
+ {
2247
+ ref: marker,
2248
+ "data-translation-switch": "",
2249
+ "data-mode": mode,
2250
+ color: "var(--limr-translation-accent, #6b8fb5)",
2251
+ disabled: locked,
2252
+ label: locked ? `\u5F53\u524D${names[mode]}\uFF0C\u7531\u5168\u5C40\u5C55\u793A\u6A21\u5F0F\u63A7\u5236` : `\u5F53\u524D${names[mode]}\uFF0C\u5207\u6362\u5230${names[next]}`,
2253
+ onClick: () => {
2254
+ restoreFocus.current = document.activeElement === marker.current;
2255
+ if (globalMode !== void 0) onGlobalChange?.(next);
2256
+ else setLocalMode(next);
2257
+ },
2258
+ children: /* @__PURE__ */ jsx10(TranslationIcon, { mode })
2259
+ }
2260
+ ) : void 0;
2261
+ return /* @__PURE__ */ jsxs7("div", { className: "limr-translations", "data-mode": mode, children: [
2262
+ translation && /* @__PURE__ */ jsx10(Collapse, { open: mode !== "origin", keepMounted: true, className: "limr-translation-panel", children: /* @__PURE__ */ jsx10("div", { className: "limr-translation-text", "data-language": "translation", children: renderChildren(translation.children ?? [], { trailing: mode === "translation" ? toggle : void 0 }) }) }),
2263
+ origin && /* @__PURE__ */ jsx10(Collapse, { open: mode !== "translation", keepMounted: true, className: "limr-translation-panel", children: /* @__PURE__ */ jsx10("div", { className: "limr-translation-text", "data-language": "origin", children: renderChildren(origin.children ?? [], { trailing: mode !== "translation" ? toggle : void 0 }) }) })
2264
+ ] });
2265
+ }
2266
+ return {
2267
+ name: "translations",
2268
+ tags: ["translations", "origin", "translation"],
2269
+ directives: ["translations", "origin", "translation"],
2270
+ display: "block",
2271
+ scope: "local",
2272
+ parameters: { translationMode: void 0, onTranslationModeChange: void 0 },
2273
+ components: { translations: Translations, origin: ({ children }) => /* @__PURE__ */ jsx10(Fragment4, { children }), translation: ({ children }) => /* @__PURE__ */ jsx10(Fragment4, { children }) }
2274
+ };
2275
+ }
2276
+
2277
+ // src/extensions/blocks.tsx
2278
+ import { useState as useState7 } from "react";
2279
+
2280
+ // src/extensions/define.ts
2281
+ function defineBlock({ name, component, tags = [name], directives = [name], selection = "content" }) {
2282
+ return { name, tags, directives, selection, display: "block", scope: "local", components: Object.fromEntries([.../* @__PURE__ */ new Set([...tags, ...directives])].map((tag) => [tag, component])) };
2283
+ }
2284
+ function defineAnnotation(type) {
2285
+ return { name: `annotation:${type.type}`, annotationTypes: [type], scope: "local" };
2286
+ }
2287
+ function defineExtension(extension) {
2288
+ return extension;
2289
+ }
2290
+
2291
+ // src/components/Disclosure.tsx
2292
+ import { useEffect as useEffect5, useState as useState4 } from "react";
2293
+ import { jsx as jsx11, jsxs as jsxs8 } from "react/jsx-runtime";
2294
+ function Disclosure({ title, open, onChange, children }) {
2295
+ const [present, setPresent] = useState4(open);
2296
+ useEffect5(() => {
2297
+ if (open) {
2298
+ setPresent(true);
2299
+ return;
2300
+ }
2301
+ const timer = setTimeout(() => setPresent(false), 420);
2302
+ return () => clearTimeout(timer);
2303
+ }, [open]);
2304
+ return /* @__PURE__ */ jsxs8("details", { className: "limr-disclosure", open: present || open, "data-expanded": open || void 0, children: [
2305
+ /* @__PURE__ */ jsxs8("summary", { "aria-expanded": open, onClick: (event) => {
2306
+ event.preventDefault();
2307
+ onChange(!open);
2308
+ }, "data-limr-ignore": "true", children: [
2309
+ /* @__PURE__ */ jsx11("span", { className: "limr-underline", children: title }),
2310
+ /* @__PURE__ */ jsx11("svg", { viewBox: "0 0 20 20", fill: "none", "aria-hidden": "true", children: /* @__PURE__ */ jsx11("path", { d: "m6 8 4 4 4-4" }) })
2311
+ ] }),
2312
+ /* @__PURE__ */ jsx11(Collapse, { open, keepMounted: true, children: /* @__PURE__ */ jsx11("div", { className: "limr-question-detail", children }) })
2313
+ ] });
2314
+ }
2315
+
2316
+ // src/components/DiamondCheck.tsx
2317
+ import { jsx as jsx12, jsxs as jsxs9 } from "react/jsx-runtime";
2318
+ function DiamondCheck({ checked }) {
2319
+ return /* @__PURE__ */ jsxs9("svg", { className: "limr-choice-diamond", width: "14", height: "14", viewBox: "0 0 18 18", fill: "none", "aria-hidden": "true", "data-limr-ignore": "true", "data-checked": checked || void 0, children: [
2320
+ /* @__PURE__ */ jsx12("path", { className: "limr-diamond-outline", d: "M9 1.5L16.5 9L9 16.5L1.5 9Z", fill: "none" }),
2321
+ /* @__PURE__ */ jsx12("path", { className: "limr-diamond-fill", d: "M9 5L13 9L9 13L5 9Z", fill: "currentColor" })
2322
+ ] });
2323
+ }
2324
+
2325
+ // src/extensions/video.tsx
2326
+ import { useEffect as useEffect6, useRef as useRef9, useState as useState5 } from "react";
2327
+ import { jsx as jsx13, jsxs as jsxs10 } from "react/jsx-runtime";
2328
+ function resolveVideo(source, provider = "auto") {
2329
+ const safe = safeUrl(source);
2330
+ if (!safe) return;
2331
+ let parsed;
2332
+ try {
2333
+ parsed = new URL(safe.startsWith("//") ? `https:${safe}` : safe);
2334
+ } catch {
2335
+ return provider === "auto" || provider === "native" ? { url: safe, native: true } : void 0;
2336
+ }
2337
+ if (!["https:", "http:"].includes(parsed.protocol)) return;
2338
+ const youtube = /(?:^|\.)(?:youtube\.com|youtube-nocookie\.com)$/.test(parsed.hostname) || parsed.hostname === "youtu.be";
2339
+ const bilibili = /(?:^|\.)bilibili\.com$/.test(parsed.hostname);
2340
+ const kind = provider === "auto" ? youtube ? "youtube" : bilibili ? "bilibili" : "native" : provider;
2341
+ if (kind === "native") return { url: safe, native: true };
2342
+ if (kind === "youtube" && youtube) {
2343
+ const id = parsed.hostname === "youtu.be" ? parsed.pathname.split("/")[1] : parsed.searchParams.get("v") ?? /^\/(?:embed|shorts|live)\/([\w-]+)/.exec(parsed.pathname)?.[1];
2344
+ if (id && /^[\w-]{11}$/.test(id)) {
2345
+ const embed = new URL(`https://www.youtube.com/embed/${id}`);
2346
+ const time = parsed.searchParams.get("start") ?? parsed.searchParams.get("t");
2347
+ if (time) {
2348
+ const match = /^(?:(\d+)h)?(?:(\d+)m)?(?:(\d+)s?)?$/.exec(time);
2349
+ const seconds = match ? Number(match[1] ?? 0) * 3600 + Number(match[2] ?? 0) * 60 + Number(match[3] ?? 0) : 0;
2350
+ if (seconds > 0) embed.searchParams.set("start", String(seconds));
2351
+ }
2352
+ return { url: embed.href, native: false };
2353
+ }
2354
+ }
2355
+ if (kind === "bilibili" && bilibili) {
2356
+ const id = /\/video\/(BV[\w]+|av\d+)(?:\/|$)/.exec(parsed.pathname)?.[1];
2357
+ const bvid = id?.startsWith("BV") ? id : parsed.hostname === "player.bilibili.com" ? parsed.searchParams.get("bvid") : null;
2358
+ const aid = id?.startsWith("av") ? id.slice(2) : parsed.hostname === "player.bilibili.com" ? parsed.searchParams.get("aid") : null;
2359
+ if (bvid && /^BV[\w]+$/.test(bvid) || aid && /^\d+$/.test(aid)) {
2360
+ const embed = new URL("https://player.bilibili.com/player.html");
2361
+ embed.searchParams.set(bvid ? "bvid" : "aid", bvid || aid);
2362
+ embed.searchParams.set("autoplay", "0");
2363
+ embed.searchParams.set("high_quality", "1");
2364
+ embed.searchParams.set("danmaku", "0");
2365
+ const part = parsed.searchParams.get("p") ?? parsed.searchParams.get("page");
2366
+ if (part && /^[1-9]\d*$/.test(part)) embed.searchParams.set("page", part);
2367
+ return { url: embed.href, native: false };
2368
+ }
2369
+ }
2370
+ }
2371
+ function video(options = {}) {
2372
+ function Video({ node, source: markdown, renderAttribute }) {
2373
+ const runtime = useRuntime();
2374
+ const scrollRoot = useStoreSelector(runtime.configuration, (config) => config.scrollRoot);
2375
+ const element = useRef9(null);
2376
+ const [visible, setVisible] = useState5(false);
2377
+ const [playing, setPlaying] = useState5(false);
2378
+ const [failed, setFailed] = useState5(false);
2379
+ const provider = String(node.attributes?.provider ?? "auto");
2380
+ const source = String(node.attributes?.url ?? node.attributes?.src ?? "");
2381
+ const requested = node.attributes?.loading ?? options.loading ?? "visible";
2382
+ const loading2 = requested === "click" || requested === "eager" ? requested : "visible";
2383
+ const resolved = options.resolveUrl?.(provider, source);
2384
+ const media = resolved && safeUrl(resolved) ? { url: safeUrl(resolved), native: provider === "native" } : resolveVideo(source, provider);
2385
+ useEffect6(() => {
2386
+ setFailed(false);
2387
+ setPlaying(false);
2388
+ }, [source, provider]);
2389
+ useEffect6(() => {
2390
+ if (visible || loading2 !== "visible" || !element.current) return;
2391
+ if (typeof IntersectionObserver === "undefined") {
2392
+ setVisible(true);
2393
+ return;
2394
+ }
2395
+ const observer = new IntersectionObserver((entries) => {
2396
+ if (entries.some((entry) => entry.isIntersecting)) {
2397
+ setVisible(true);
2398
+ observer.disconnect();
2399
+ }
2400
+ }, { root: scrollRoot, rootMargin: "200px" });
2401
+ observer.observe(element.current);
2402
+ return () => observer.disconnect();
2403
+ }, [visible, loading2, scrollRoot]);
2404
+ const enabled = loading2 === "eager" || loading2 === "visible" && visible || playing;
2405
+ const title = String(node.attributes?.title ?? `${provider === "auto" ? "Video" : provider} video`);
2406
+ const original = safeUrl(source);
2407
+ return /* @__PURE__ */ jsxs10("div", { ref: element, className: "limr-video", "data-limr-selection-surface": "", "data-loading": loading2, children: [
2408
+ /* @__PURE__ */ jsx13("div", { className: "limr-video-frame", children: !media || failed ? /* @__PURE__ */ jsxs10("div", { className: "limr-video-error", children: [
2409
+ /* @__PURE__ */ jsx13("span", { children: runtime.locale.unavailable }),
2410
+ original && /* @__PURE__ */ jsx13("a", { href: original, target: "_blank", rel: "noopener noreferrer", children: source })
2411
+ ] }) : enabled ? media.native ? /* @__PURE__ */ jsx13("video", { controls: true, playsInline: true, preload: "metadata", src: media.url, "aria-label": title, onError: () => setFailed(true) }) : /* @__PURE__ */ jsx13("iframe", { src: media.url, title, allow: "accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share", allowFullScreen: true, referrerPolicy: "strict-origin-when-cross-origin", onError: () => setFailed(true) }) : /* @__PURE__ */ jsx13("button", { type: "button", className: "limr-video-play", onClick: () => setPlaying(true), "aria-label": runtime.locale.play, children: /* @__PURE__ */ jsx13("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: /* @__PURE__ */ jsx13("path", { d: "m8 5 11 7-11 7Z", fill: "currentColor" }) }) }) }),
2412
+ node.attributes?.title && /* @__PURE__ */ jsx13("div", { className: "limr-video-title", children: renderAttribute("title") }),
2413
+ /* @__PURE__ */ jsx13(CopyButton, { className: "limr-video-copy", variant: "glass", value: markdown })
2414
+ ] });
2415
+ }
2416
+ return defineBlock({ name: "video", tags: ["video", "md-video"], component: options.component ?? Video, selection: "atomic" });
2417
+ }
2418
+
2419
+ // src/extensions/figures.tsx
2420
+ import { createContext, useContext as useContext2, useEffect as useEffect7, useMemo as useMemo3, useRef as useRef10, useState as useState6 } from "react";
2421
+
2422
+ // src/extensions/figure-layout.ts
2423
+ var defaultFigureLimits = { minWidth: 220, maxWidth: 560, minHeight: 120, maxHeight: 480 };
2424
+ function figureWidths({ ratio, limits }) {
2425
+ const maximum = Math.min(limits.maxWidth, limits.maxHeight * ratio);
2426
+ return { maximum, minimum: Math.min(maximum, Math.max(limits.minWidth, limits.minHeight * ratio)) };
2427
+ }
2428
+ function figureColumns(width, items, gap, requested, responsive = true) {
2429
+ if (!items.length || width <= 0) return 1;
2430
+ const bounds = items.map(figureWidths);
2431
+ const fits = (count2) => {
2432
+ const slot = (width - (count2 - 1) * gap) / count2;
2433
+ return bounds.every((item) => slot >= item.minimum);
2434
+ };
2435
+ if (requested) {
2436
+ let count2 = Math.max(1, Math.min(24, Math.floor(requested)));
2437
+ if (responsive) while (count2 > 1 && !fits(count2)) count2--;
2438
+ return count2;
2439
+ }
2440
+ const maximum = Math.max(...bounds.map((item) => item.maximum));
2441
+ const minimum = Math.max(...bounds.map((item) => item.minimum));
2442
+ let count = 1;
2443
+ while (count < items.length && count < 24 && width >= count * maximum + count * gap + minimum && fits(count + 1)) count++;
2444
+ return count;
2445
+ }
2446
+ function dimension(value, fallback, optional = false) {
2447
+ if (optional && (value === false || value === "false" || value === "none")) return Infinity;
2448
+ if (typeof value !== "number" && (typeof value !== "string" || !/^\d+(?:\.\d+)?(?:px)?$/.test(value))) return fallback;
2449
+ const number = typeof value === "number" ? value : parseFloat(value);
2450
+ return Number.isFinite(number) && number >= 0 ? number : fallback;
2451
+ }
2452
+ function figureLimits(attributes = {}, defaults2 = defaultFigureLimits) {
2453
+ return {
2454
+ minWidth: dimension(attributes["min-width"], defaults2.minWidth),
2455
+ maxWidth: dimension(attributes["max-width"], defaults2.maxWidth, true),
2456
+ minHeight: dimension(attributes["min-height"], defaults2.minHeight),
2457
+ maxHeight: dimension(attributes["max-height"], defaults2.maxHeight, true)
2458
+ };
2459
+ }
2460
+
2461
+ // src/extensions/figures.tsx
2462
+ import { jsx as jsx14, jsxs as jsxs11 } from "react/jsx-runtime";
2463
+ var FigureContext = createContext(defaultFigureLimits);
2464
+ var captionNode = (node) => node.name === "figcaption" || node.name === "caption";
2465
+ var flatten = (nodes) => nodes.flatMap((node) => node.type === "paragraph" && node.children?.some((child) => child.name === "figure" || captionNode(child)) ? node.children : [node]);
2466
+ var identifier = (node) => node.attributes?.id ? String(node.attributes.id) : void 0;
2467
+ var ratioOf = (width, height) => {
2468
+ const ratio = Number(width) / Number(height);
2469
+ return Number.isFinite(ratio) && ratio > 0 ? ratio : 1;
2470
+ };
2471
+ function figures(options = {}) {
2472
+ const defaults2 = figureLimits({ "min-width": options.minWidth, "max-width": options.maxWidth, "min-height": options.minHeight, "max-height": options.maxHeight });
2473
+ function Figures({ node, renderChildren, renderAttribute, source }) {
2474
+ const locale = useLocale();
2475
+ const nodes = flatten(node.children ?? []);
2476
+ const panels = nodes.filter((child) => child.name === "figure");
2477
+ const captions = nodes.filter(captionNode);
2478
+ const body = nodes.filter((child) => !captionNode(child));
2479
+ const limits = useMemo3(() => figureLimits(node.attributes, defaults2), [node.attributes]);
2480
+ const grid = useRef10(null);
2481
+ const [columns, setColumns] = useState6(1);
2482
+ const gap = Math.min(100, dimension(node.attributes?.gap, options.gap ?? 16));
2483
+ const rows = dimension(node.attributes?.rows, options.rows ?? 0);
2484
+ const requested = dimension(node.attributes?.columns ?? node.attributes?.cols, options.columns ?? 0) || (rows > 0 ? Math.ceil(panels.length / rows) : void 0);
2485
+ const responsive = String(node.attributes?.responsive ?? options.responsive ?? true) !== "false";
2486
+ useEffect7(() => {
2487
+ const element = grid.current;
2488
+ if (!element) return;
2489
+ const measure = () => {
2490
+ const elements = [...element.querySelectorAll(":scope > .limr-figure")];
2491
+ const items = panels.map((panel, index) => {
2492
+ const image = elements[index]?.querySelector("img");
2493
+ const ratio = image?.naturalWidth && image.naturalHeight ? image.naturalWidth / image.naturalHeight : ratioOf(panel.attributes?.width, panel.attributes?.height);
2494
+ return { ratio, limits: figureLimits(panel.attributes, limits) };
2495
+ });
2496
+ setColumns(figureColumns(element.clientWidth, items, gap, requested, responsive));
2497
+ };
2498
+ const observer = new ResizeObserver(measure);
2499
+ observer.observe(element);
2500
+ element.addEventListener("load", measure, true);
2501
+ element.addEventListener("error", measure, true);
2502
+ measure();
2503
+ return () => {
2504
+ observer.disconnect();
2505
+ element.removeEventListener("load", measure, true);
2506
+ element.removeEventListener("error", measure, true);
2507
+ };
2508
+ }, [node, limits, gap, requested, responsive]);
2509
+ return /* @__PURE__ */ jsxs11("figure", { id: identifier(node), className: "limr-figures", "data-limr-selection-order": "visual", "data-columns": columns, "data-responsive": responsive, children: [
2510
+ /* @__PURE__ */ jsx14(CopyButton, { value: source, label: locale.copyFigures, variant: "glass", className: "limr-figures-copy" }),
2511
+ /* @__PURE__ */ jsx14(FigureContext.Provider, { value: limits, children: /* @__PURE__ */ jsx14("div", { ref: grid, className: "limr-figures-grid", style: { gridTemplateColumns: `repeat(${columns}, minmax(0, 1fr))`, gridTemplateRows: rows ? `repeat(${Math.max(1, Math.min(24, Math.floor(rows)))}, auto auto)` : void 0, gap }, children: renderChildren(body) }) }),
2512
+ captions.length ? renderChildren(captions) : node.attributes?.caption ? /* @__PURE__ */ jsx14("figcaption", { children: renderAttribute("caption") }) : null
2513
+ ] });
2514
+ }
2515
+ function Figure({ node, renderChildren, renderAttribute }) {
2516
+ const locale = useLocale();
2517
+ const inherited = useContext2(FigureContext);
2518
+ const limits = figureLimits(node.attributes, inherited === defaultFigureLimits ? defaults2 : inherited);
2519
+ const media = useRef10(null);
2520
+ const [ratio, setRatio] = useState6(ratioOf(node.attributes?.width, node.attributes?.height));
2521
+ const nodes = flatten(node.children ?? []);
2522
+ const captions = nodes.filter(captionNode);
2523
+ const body = nodes.filter((child) => !captionNode(child));
2524
+ useEffect7(() => {
2525
+ const element = media.current;
2526
+ if (!element) return;
2527
+ const measure = () => {
2528
+ const image = element.querySelector("img");
2529
+ if (image?.naturalWidth && image.naturalHeight) setRatio(image.naturalWidth / image.naturalHeight);
2530
+ };
2531
+ measure();
2532
+ element.addEventListener("load", measure, true);
2533
+ return () => element.removeEventListener("load", measure, true);
2534
+ }, [node]);
2535
+ const maximum = figureWidths({ ratio, limits }).maximum;
2536
+ return /* @__PURE__ */ jsxs11("figure", { id: identifier(node), className: "limr-figure", "data-limr-selection-order": "visual", style: {
2537
+ "--limr-figure-width": Number.isFinite(maximum) ? `${maximum}px` : "100%",
2538
+ "--limr-figure-min-height": `${Math.min(limits.minHeight, limits.maxHeight)}px`,
2539
+ "--limr-figure-max-height": Number.isFinite(limits.maxHeight) ? `${limits.maxHeight}px` : "none"
2540
+ }, children: [
2541
+ /* @__PURE__ */ jsx14("div", { ref: media, className: "limr-figure-media", children: renderChildren(body) }),
2542
+ /* @__PURE__ */ jsx14(CopyButton, { onCopy: async () => {
2543
+ const url = media.current?.querySelector("img")?.getAttribute("src");
2544
+ if (!url) throw new Error("Image URL unavailable");
2545
+ await navigator.clipboard.writeText(url);
2546
+ }, label: locale.copyImage, variant: "glass", className: "limr-figure-copy" }),
2547
+ captions.length ? renderChildren(captions) : node.attributes?.caption ? /* @__PURE__ */ jsx14("figcaption", { children: renderAttribute("caption") }) : null
2548
+ ] });
2549
+ }
2550
+ const Caption = ({ children }) => /* @__PURE__ */ jsx14("figcaption", { children });
2551
+ return {
2552
+ name: "figures",
2553
+ tags: ["figures", "figure", "figcaption", "caption", "img"],
2554
+ directives: ["figures", "figure", "figcaption"],
2555
+ scope: "local",
2556
+ display: "block",
2557
+ components: {
2558
+ figures: Figures,
2559
+ figure: Figure,
2560
+ figcaption: Caption,
2561
+ caption: Caption,
2562
+ img: ({ node }) => /* @__PURE__ */ jsx14("img", { src: safeUrl(node.attributes?.src, true), alt: String(node.attributes?.alt ?? ""), loading: "lazy", decoding: "async" })
2563
+ },
2564
+ transform(root) {
2565
+ const visit = (node) => {
2566
+ if (node.type === "component" && node.name === "img") {
2567
+ node.selection = "atomic";
2568
+ node.inline = true;
2569
+ }
2570
+ if (node.type === "component" && node.name === "figure" && (node.attributes?.src || node.attributes?.url)) {
2571
+ const image = node.attributeNodes?.[node.attributes.src ? "src" : "url"];
2572
+ node.children = [{ type: "image", url: node.attributes.src ?? node.attributes.url, alt: node.attributes.alt ?? "", position: image?.position ?? node.position }, ...node.children ?? []];
2573
+ }
2574
+ node.children?.forEach(visit);
2575
+ };
2576
+ visit(root);
2577
+ }
2578
+ };
2579
+ }
2580
+
2581
+ // src/extensions/blocks.tsx
2582
+ import { Fragment as Fragment5, jsx as jsx15, jsxs as jsxs12 } from "react/jsx-runtime";
2583
+ function parts(node, name) {
2584
+ const result = [];
2585
+ walk(node, (child) => {
2586
+ if (child !== node && child.name === name) result.push(child);
2587
+ });
2588
+ return result;
2589
+ }
2590
+ var PassThrough = ({ children }) => /* @__PURE__ */ jsx15(Fragment5, { children });
2591
+ function definition(options = {}) {
2592
+ function Definition({ node, children, renderChildren, renderAttribute }) {
2593
+ const runtime = useRuntime();
2594
+ const title = parts(node, "title")[0];
2595
+ const content = parts(node, "content")[0];
2596
+ return /* @__PURE__ */ jsxs12("aside", { className: "limr-definition", children: [
2597
+ /* @__PURE__ */ jsx15("div", { className: "limr-card-label", "data-limr-ignore": "true", children: runtime.locale.definition }),
2598
+ (title || node.attributes?.title) && /* @__PURE__ */ jsx15("div", { className: "limr-definition-title", children: title ? renderChildren(title.children ?? []) : renderAttribute("title") }),
2599
+ /* @__PURE__ */ jsx15("div", { className: "limr-block-content", children: content ? renderChildren(content.children ?? []) : children })
2600
+ ] });
2601
+ }
2602
+ return { ...defineBlock({ name: "definition", component: options.component ?? Definition }), tags: ["definition", "title", "content"], components: { definition: options.component ?? Definition, title: PassThrough, content: PassThrough } };
2603
+ }
2604
+ function question(options = {}) {
2605
+ function Question({ node, children, renderChildren, renderAttribute }) {
2606
+ const runtime = useRuntime();
2607
+ const [showHint, setHint] = useState7(false), [showAnswer, setAnswer] = useState7(false);
2608
+ const [selected, setSelected] = useState7([]), [checked, setChecked] = useState7(false);
2609
+ const content = parts(node, "question-content")[0];
2610
+ const hint = parts(node, "question-hint")[0];
2611
+ const answer = parts(node, "question-answer")[0];
2612
+ const group = parts(node, "question-sel-grp")[0];
2613
+ const selections = parts(node, "question-sel");
2614
+ const multi = String(group?.attributes?.multi ?? node.attributes?.multi ?? "false") === "true";
2615
+ let correct = [];
2616
+ try {
2617
+ const value = JSON.parse(String(group?.attributes?.answer ?? node.attributes?.answer ?? "[]"));
2618
+ correct = (Array.isArray(value) ? value : [value]).map(Number);
2619
+ } catch {
2620
+ }
2621
+ const success = correct.length === selected.length && correct.every((index) => selected.includes(index));
2622
+ return /* @__PURE__ */ jsxs12("section", { className: "limr-question", children: [
2623
+ /* @__PURE__ */ jsx15("div", { className: "limr-card-label", "data-limr-ignore": "true", children: runtime.locale.question }),
2624
+ node.attributes?.title && /* @__PURE__ */ jsx15("div", { className: "limr-question-title", children: renderAttribute("title") }),
2625
+ /* @__PURE__ */ jsx15("div", { className: "limr-block-content", children: content ? renderChildren(content.children ?? []) : !selections.length && !hint && !answer ? children : null }),
2626
+ selections.length > 0 && /* @__PURE__ */ jsxs12("fieldset", { className: "limr-question-options", children: [
2627
+ /* @__PURE__ */ jsx15("legend", { className: "limr-sr-only", children: String(node.attributes?.title ?? runtime.locale.question) }),
2628
+ selections.map((selection, index) => /* @__PURE__ */ jsxs12("label", { "data-selected": selected.includes(index) || void 0, "data-result": checked ? correct.includes(index) ? "correct" : selected.includes(index) ? "incorrect" : void 0 : void 0, children: [
2629
+ /* @__PURE__ */ jsx15("input", { type: multi ? "checkbox" : "radio", name: `${runtime.document.id}-question-${rangeOf(node).start}`, checked: selected.includes(index), disabled: checked, onChange: () => {
2630
+ setSelected(multi ? selected.includes(index) ? selected.filter((item) => item !== index) : [...selected, index] : [index]);
2631
+ } }),
2632
+ /* @__PURE__ */ jsx15(DiamondCheck, { checked: selected.includes(index) || checked && correct.includes(index) }),
2633
+ /* @__PURE__ */ jsx15("span", { className: "limr-choice-text", children: renderChildren(selection.children ?? []) })
2634
+ ] }, index))
2635
+ ] }),
2636
+ selections.length > 0 && correct.length > 0 && /* @__PURE__ */ jsxs12("div", { className: "limr-question-actions", "data-limr-ignore": "true", children: [
2637
+ /* @__PURE__ */ jsx15("button", { type: "button", "data-checked": checked || void 0, disabled: !checked && !selected.length, onClick: () => {
2638
+ if (checked) {
2639
+ setChecked(false);
2640
+ setSelected([]);
2641
+ setAnswer(false);
2642
+ } else {
2643
+ setChecked(true);
2644
+ setAnswer(true);
2645
+ }
2646
+ }, children: /* @__PURE__ */ jsx15("span", { className: "limr-button-label", children: checked ? runtime.locale.retry : runtime.locale.submit }, checked ? "retry" : "submit") }),
2647
+ /* @__PURE__ */ jsx15(Collapse, { open: checked, children: /* @__PURE__ */ jsx15("span", { role: "status", className: `limr-question-result ${success ? "limr-success" : "limr-error"}`, children: success ? runtime.locale.correct : runtime.locale.incorrect }) })
2648
+ ] }),
2649
+ hint && /* @__PURE__ */ jsx15(Disclosure, { title: runtime.locale.hint, open: showHint, onChange: setHint, children: renderChildren(hint.children ?? []) }),
2650
+ answer && /* @__PURE__ */ jsx15(Disclosure, { title: runtime.locale.answer, open: showAnswer, onChange: setAnswer, children: renderChildren(answer.children ?? []) })
2651
+ ] });
2652
+ }
2653
+ const names2 = ["question-content", "question-hint", "question-answer", "question-sel-grp", "question-sel"];
2654
+ return { ...defineBlock({ name: "question", component: options.component ?? Question }), tags: ["question", ...names2], components: { question: options.component ?? Question, ...Object.fromEntries(names2.map((name) => [name, PassThrough])) } };
2655
+ }
2656
+ function extras(options = {}) {
2657
+ const Extra = ({ node, children, renderAttribute }) => /* @__PURE__ */ jsxs12("div", { className: "limr-extra", children: [
2658
+ /* @__PURE__ */ jsxs12("a", { className: "limr-extra-link", href: safeUrl(node.attributes?.url), target: "_blank", rel: "noreferrer", children: [
2659
+ /* @__PURE__ */ jsx15("span", { className: "limr-underline", children: renderAttribute(node.attributes?.title ? "title" : "url") }),
2660
+ node.attributes?.desc && /* @__PURE__ */ jsx15("p", { children: /* @__PURE__ */ jsx15("span", { className: "limr-underline", children: renderAttribute("desc") }) })
2661
+ ] }),
2662
+ children
2663
+ ] });
2664
+ const Extras = ({ children }) => {
2665
+ const runtime = useRuntime();
2666
+ return /* @__PURE__ */ jsxs12("aside", { className: "limr-extras", children: [
2667
+ /* @__PURE__ */ jsx15("div", { className: "limr-card-label", "data-limr-ignore": "true", children: runtime.locale.extra }),
2668
+ children
2669
+ ] });
2670
+ };
2671
+ return { ...defineBlock({ name: "extras", component: options.component ?? Extras }), tags: ["extras", "extra"], components: { extras: options.component ?? Extras, extra: Extra } };
2672
+ }
2673
+
2674
+ // src/extensions/standard.ts
2675
+ function standard() {
2676
+ return [gfm(), math(), codeHighlight(), definition(), question(), extras(), video(), figures(), citation(), translations()];
2677
+ }
2678
+
2679
+ // src/react/context.tsx
2680
+ import { jsx as jsx16 } from "react/jsx-runtime";
2681
+ var defaults;
2682
+ var RuntimeContext = createContext2(null);
2683
+ var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect8;
2684
+ function DocumentProvider({ children, source = "", streaming = false, documentId, ...options }) {
2685
+ const generatedId = useId();
2686
+ const extensions = useMemo4(() => {
2687
+ const base = options.extensions ?? (defaults ??= standard());
2688
+ return options.plugins?.length ? [...base, ...options.plugins] : base;
2689
+ }, [options.extensions, options.plugins]);
2690
+ const config = { ...options, extensions };
2691
+ const [runtime] = useState8(() => new ReaderRuntime(documentId ?? `limr-${generatedId.replace(/[^a-z\d_-]/gi, "")}`, source, streaming, config));
2692
+ const previous = useRef11({ source, streaming, config });
2693
+ useIsomorphicLayoutEffect(() => {
2694
+ const old = previous.current;
2695
+ const changed = Object.keys({ ...old.config, ...config }).some((key) => old.config[key] !== config[key]);
2696
+ if (changed) runtime.configure(config);
2697
+ if (old.source !== source || old.streaming !== streaming) runtime.document.update(source, { streaming });
2698
+ previous.current = { source, streaming, config };
2699
+ });
2700
+ useEffect8(() => {
2701
+ runtime.start();
2702
+ return () => runtime.dispose();
2703
+ }, [runtime]);
2704
+ return /* @__PURE__ */ jsx16(RuntimeContext.Provider, { value: runtime, children });
2705
+ }
2706
+ function useRuntime() {
2707
+ const runtime = useContext3(RuntimeContext);
2708
+ if (!runtime) throw new Error("This LiMR component needs a DocumentProvider or Reader. Markdown can also be used on its own.");
2709
+ return runtime;
2710
+ }
2711
+ function useRendererParameter(name) {
2712
+ const runtime = useRuntime();
2713
+ return useStoreSelector(runtime.configuration, (config) => {
2714
+ if (config.parameters?.[name] !== void 0) return config.parameters[name];
2715
+ for (let index = (config.extensions?.length ?? 0) - 1; index >= 0; index--) {
2716
+ const parameters = config.extensions[index].parameters;
2717
+ if (parameters && name in parameters) return parameters[name];
2718
+ }
2719
+ return void 0;
2720
+ });
2721
+ }
2722
+ function useStoreSelector(store, select) {
2723
+ const selectRef = useRef11(select);
2724
+ selectRef.current = select;
2725
+ const cache2 = useRef11(void 0);
2726
+ const get = useCallback2(() => {
2727
+ const state = store.get();
2728
+ if (cache2.current && cache2.current.state === state && cache2.current.select === selectRef.current) return cache2.current.value;
2729
+ const value = selectRef.current(state);
2730
+ cache2.current = { state, select: selectRef.current, value };
2731
+ return value;
2732
+ }, [store]);
2733
+ return useSyncExternalStore(store.subscribe, get, get);
2734
+ }
2735
+ function useDocument() {
2736
+ const runtime = useRuntime();
2737
+ return useSyncExternalStore(runtime.document.subscribe, runtime.document.getSnapshot, runtime.document.getSnapshot);
2738
+ }
2739
+ function useDocumentSelector(select) {
2740
+ const runtime = useRuntime();
2741
+ const store = useMemo4(() => ({ subscribe: runtime.document.subscribe, get: runtime.document.getSnapshot }), [runtime]);
2742
+ return useStoreSelector(store, select);
2743
+ }
2744
+ function useSelection() {
2745
+ return useStoreSelector(useRuntime().interaction, (state) => state.selection);
2746
+ }
2747
+ function useTheme() {
2748
+ return useStoreSelector(useRuntime().configuration, (config) => config.theme ?? "light");
2749
+ }
2750
+ function useAppearance() {
2751
+ return useStoreSelector(useRuntime().configuration, (config) => config.appearance ?? "classic");
2752
+ }
2753
+ function useLocale() {
2754
+ const runtime = useRuntime();
2755
+ useStoreSelector(runtime.configuration, (config) => config.locale);
2756
+ return runtime.locale;
2757
+ }
2758
+ function useAnnotation(id) {
2759
+ return useStoreSelector(useRuntime().decorations, (state) => state.annotations.get(id));
2760
+ }
2761
+ function useAnnotations() {
2762
+ const state = useStoreSelector(useRuntime().decorations, (state2) => state2);
2763
+ return useMemo4(() => ({ annotations: state.annotations, occurrences: state.occurrences }), [state.annotations, state.occurrences]);
2764
+ }
2765
+ function useAnnotationState() {
2766
+ const runtime = useRuntime();
2767
+ const active = useStoreSelector(runtime.interaction, (state) => state.active);
2768
+ const hovered = useStoreSelector(runtime.interaction, (state) => state.hovered);
2769
+ return { active, hovered, activate: (id) => runtime.activate(id), hover: (id) => runtime.hover(id) };
2770
+ }
2771
+ function useAnchor(id) {
2772
+ const runtime = useRuntime();
2773
+ useSyncExternalStore(runtime.layout.subscribe, runtime.layout.get, runtime.layout.get);
2774
+ useSyncExternalStore(runtime.viewport.subscribe, runtime.viewport.get, runtime.viewport.get);
2775
+ const element = runtime.anchors.get(id);
2776
+ return { element: element ?? null, rect: element?.getBoundingClientRect() ?? null, contentRect: runtime.content?.getBoundingClientRect() ?? null };
2777
+ }
2778
+ function useLiMR() {
2779
+ const runtime = useRuntime();
2780
+ return useMemo4(() => ({
2781
+ ...runtime.commands,
2782
+ document: runtime.document,
2783
+ get signal() {
2784
+ return runtime.signal;
2785
+ },
2786
+ clearSelection: () => runtime.clearSelection(),
2787
+ scrollToHeading: (id) => runtime.scrollToHeading(id),
2788
+ scrollToAnnotation: (id) => runtime.scrollToOccurrence(id),
2789
+ invalidateAnnotation: (id) => runtime.invalidateAnnotation(id)
2790
+ }), [runtime]);
2791
+ }
2792
+
2793
+ // src/components/CopyButton.tsx
2794
+ import { jsx as jsx17, jsxs as jsxs13 } from "react/jsx-runtime";
2795
+ function CopyButton({ value = "", onCopy, label, variant = "plain", className = "" }) {
2796
+ const locale = useLocale();
2797
+ const [status, setStatus] = useState9("idle");
2798
+ const timer = useRef12(void 0);
2799
+ const mounted = useRef12(true);
2800
+ const title = status === "copied" ? locale.copied : status === "error" ? locale.copyFailed : label ?? locale.copy;
2801
+ useEffect9(() => {
2802
+ mounted.current = true;
2803
+ return () => {
2804
+ mounted.current = false;
2805
+ clearTimeout(timer.current);
2806
+ };
2807
+ }, []);
2808
+ const copy = async () => {
2809
+ try {
2810
+ if (onCopy) await onCopy();
2811
+ else await navigator.clipboard.writeText(value);
2812
+ if (!mounted.current) return;
2813
+ setStatus("copied");
2814
+ } catch {
2815
+ if (!mounted.current) return;
2816
+ setStatus("error");
2817
+ }
2818
+ clearTimeout(timer.current);
2819
+ timer.current = setTimeout(() => setStatus("idle"), 2200);
2820
+ };
2821
+ return /* @__PURE__ */ jsxs13(
2822
+ "button",
2823
+ {
2824
+ type: "button",
2825
+ className: `limr-copy-button ${className}`,
2826
+ "data-variant": variant,
2827
+ "data-status": status,
2828
+ "data-limr-ignore": "true",
2829
+ "aria-label": title,
2830
+ title,
2831
+ onClick: copy,
2832
+ children: [
2833
+ /* @__PURE__ */ jsxs13("svg", { className: "limr-copy-glyph", viewBox: "0 0 24 24", fill: "none", "aria-hidden": "true", children: [
2834
+ /* @__PURE__ */ jsxs13("g", { className: "limr-copy-sheets", children: [
2835
+ /* @__PURE__ */ jsx17("rect", { x: "8.5", y: "8", width: "10.5", height: "12", rx: "3" }),
2836
+ /* @__PURE__ */ jsx17("path", { d: "M15.5 8V6.8A2.8 2.8 0 0 0 12.7 4H7A3 3 0 0 0 4 7v6a3 3 0 0 0 3 3h1.5" })
2837
+ ] }),
2838
+ /* @__PURE__ */ jsx17("path", { className: "limr-copy-check", d: "m5.5 12 4.2 4.2 8.8-9", pathLength: "1" })
2839
+ ] }),
2840
+ /* @__PURE__ */ jsx17("span", { className: status === "error" ? "limr-copy-error" : "limr-sr-only", role: "status", children: status === "copied" ? locale.copied : status === "error" ? locale.copyFailed : "" })
2841
+ ]
2842
+ }
2843
+ );
2844
+ }
2845
+
2846
+ // src/extensions/math.tsx
2847
+ import { jsx as jsx18, jsxs as jsxs14 } from "react/jsx-runtime";
2848
+ var loaded;
2849
+ var loading;
2850
+ var load = () => loading ??= import("./math-renderer-L6DOH4RX.js").then((module) => {
2851
+ loaded = module.default;
2852
+ return module;
2853
+ });
2854
+ var MathContent = lazy(load);
2855
+ async function preloadMath() {
2856
+ await load();
2857
+ }
2858
+ function math(options = {}) {
2859
+ function MathNode({ node }) {
2860
+ const display = node.type === "math";
2861
+ const fallback = /* @__PURE__ */ jsx18("code", { className: "limr-math-source", children: node.value });
2862
+ const Renderer = loaded ?? MathContent;
2863
+ const content = /* @__PURE__ */ jsx18(Suspense, { fallback, children: /* @__PURE__ */ jsx18(Renderer, { value: node.value ?? "", display, options }) });
2864
+ return display ? /* @__PURE__ */ jsxs14("div", { className: "limr-math-block", children: [
2865
+ content,
2866
+ /* @__PURE__ */ jsx18(CopyButton, { className: "limr-math-copy", variant: "glass", label: "Copy LaTeX", value: `$$
2867
+ ${node.value ?? ""}
2868
+ $$` })
2869
+ ] }) : content;
2870
+ }
2871
+ return { name: "math", micromark: [syntax2()], mdast: [mathFromMarkdown()], scope: "local", components: { math: MathNode, inlineMath: MathNode } };
2872
+ }
2873
+
2874
+ // src/components/ToolIcon.tsx
2875
+ import { Fragment as Fragment6, jsx as jsx19, jsxs as jsxs15 } from "react/jsx-runtime";
2876
+ function ToolIcon({ name, ...props }) {
2877
+ return /* @__PURE__ */ jsx19("svg", { viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.7", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", ...props, children: /* @__PURE__ */ jsxs15("g", { transform: name === "highlight" ? "translate(0 -1.25)" : name === "comment" ? "translate(0 -.5)" : void 0, children: [
2878
+ (name === "eye" || name === "eye-off") && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2879
+ /* @__PURE__ */ jsx19("path", { d: "M3 12s3.3-6 9-6 9 6 9 6-3.3 6-9 6-9-6-9-6Z" }),
2880
+ /* @__PURE__ */ jsx19("circle", { cx: "12", cy: "12", r: "2.7" }),
2881
+ name === "eye-off" && /* @__PURE__ */ jsx19("path", { d: "m4 4 16 16" })
2882
+ ] }),
2883
+ name === "question" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2884
+ /* @__PURE__ */ jsx19("circle", { cx: "12", cy: "12", r: "8.5" }),
2885
+ /* @__PURE__ */ jsx19("path", { d: "M9.4 9a2.7 2.7 0 0 1 5.2 1c0 1.8-2.6 2-2.6 3.7M12 17h.01" })
2886
+ ] }),
2887
+ name === "highlight" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2888
+ /* @__PURE__ */ jsx19("path", { d: "m8 15 7.6-9a2 2 0 0 1 2.8-.2l.8.7a2 2 0 0 1 .2 2.8L12 18l-4-3Z" }),
2889
+ /* @__PURE__ */ jsx19("path", { d: "m8 15-2 3 3 1 3-1M4 21h10M14 8l4 3.5" })
2890
+ ] }),
2891
+ name === "edit" && /* @__PURE__ */ jsx19(Fragment6, { children: /* @__PURE__ */ jsx19("path", { d: "m14.5 5.5 4 4M4.5 19.5l4.5-1 11-11a2.1 2.1 0 0 0 0-3 2.1 2.1 0 0 0-3 0l-11 11-1.5 4Z" }) }),
2892
+ name === "close" && /* @__PURE__ */ jsx19("path", { d: "m6 6 12 12M18 6 6 18" }),
2893
+ name === "copy" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2894
+ /* @__PURE__ */ jsx19("rect", { x: "8.5", y: "8", width: "10.5", height: "12", rx: "3" }),
2895
+ /* @__PURE__ */ jsx19("path", { d: "M15.5 8V6.8A2.8 2.8 0 0 0 12.7 4H7A3 3 0 0 0 4 7v6a3 3 0 0 0 3 3h1.5" })
2896
+ ] }),
2897
+ ["background", "underline", "dotted", "wavy"].includes(name) && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2898
+ name === "background" && /* @__PURE__ */ jsx19("rect", { x: "3", y: "3", width: "18", height: "18", rx: "5", fill: "currentColor", fillOpacity: ".13", stroke: "none" }),
2899
+ /* @__PURE__ */ jsx19("path", { d: "m8 15 3-8a1.05 1.05 0 0 1 2 0l3 8M9.2 12h5.6" }),
2900
+ name === "background" && /* @__PURE__ */ jsx19("path", { d: "M7 19h10", strokeWidth: "2.5" }),
2901
+ name === "underline" && /* @__PURE__ */ jsx19("path", { d: "M5 20h14" }),
2902
+ name === "dotted" && /* @__PURE__ */ jsx19("path", { d: "M5 20h14", strokeDasharray: ".1 3.4", strokeWidth: "2.4" }),
2903
+ name === "wavy" && /* @__PURE__ */ jsx19("path", { d: "M4 20c1.3-2 2.7-2 4 0s2.7 2 4 0 2.7-2 4 0 2.7 2 4 0" })
2904
+ ] }),
2905
+ name === "chevron" && /* @__PURE__ */ jsx19("path", { d: "m8 10 4 4 4-4" }),
2906
+ name === "check" && /* @__PURE__ */ jsx19("path", { d: "m5.5 12 4.2 4.2 8.8-9" }),
2907
+ name === "trash" && /* @__PURE__ */ jsx19(Fragment6, { children: /* @__PURE__ */ jsx19("path", { d: "M4.5 7h15M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2M7 7l.7 12a2 2 0 0 0 2 2h4.6a2 2 0 0 0 2-2L17 7M10 11v6M14 11v6" }) }),
2908
+ name === "note" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2909
+ /* @__PURE__ */ jsx19("path", { d: "M14 3H7a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3h10a3 3 0 0 0 3-3V9l-6-6Z" }),
2910
+ /* @__PURE__ */ jsx19("path", { d: "M14 3v4a2 2 0 0 0 2 2h4M8 13h8M8 17h5" })
2911
+ ] }),
2912
+ name === "comment" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2913
+ /* @__PURE__ */ jsx19("path", { d: "M8 19 4 21V7a3 3 0 0 1 3-3h10a3 3 0 0 1 3 3v9a3 3 0 0 1-3 3H8Z" }),
2914
+ /* @__PURE__ */ jsx19("path", { d: "M8 9h8M8 13h5" })
2915
+ ] }),
2916
+ name === "footnote" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2917
+ /* @__PURE__ */ jsx19("path", { d: "M5 7h9M5 11h12M5 15h8M5 20h14M18 4h2v5" }),
2918
+ /* @__PURE__ */ jsx19("path", { d: "M17.5 9h4" })
2919
+ ] }),
2920
+ name === "sparkles" && /* @__PURE__ */ jsxs15(Fragment6, { children: [
2921
+ /* @__PURE__ */ jsx19("path", { d: "m10.5 4 1.8 4.8 4.7 1.7-4.7 1.8-1.8 4.7-1.7-4.7L4 10.5l4.8-1.7L10.5 4Z" }),
2922
+ /* @__PURE__ */ jsx19("path", { d: "m19 15 .8 2.2L22 18l-2.2.8L19 21l-.8-2.2L16 18l2.2-.8L19 15ZM19 3v4M17 5h4" })
2923
+ ] })
2924
+ ] }) });
2925
+ }
2926
+
2927
+ // src/extensions/selection-actions.tsx
2928
+ import { jsx as jsx20, jsxs as jsxs16 } from "react/jsx-runtime";
2929
+ var highlightColors = [
2930
+ { color: "#E57373", label: "Rose", labelZh: "\u73AB\u7470" },
2931
+ { color: "#F2C744", label: "Gold", labelZh: "\u6696\u9EC4" },
2932
+ { color: "#81B29A", label: "Sage", labelZh: "\u9F20\u5C3E\u8349" },
2933
+ { color: "#6B9BD2", label: "Blue", labelZh: "\u96FE\u84DD" },
2934
+ { color: "#B39DDB", label: "Lavender", labelZh: "\u85B0\u8863\u8349" },
2935
+ { color: "#E5A06E", label: "Apricot", labelZh: "\u674F\u6A59" },
2936
+ { color: "#61AAA5", label: "Teal", labelZh: "\u9752\u74F7" }
2937
+ ];
2938
+ function copyText(options = {}) {
2939
+ return {
2940
+ id: `copy-${options.format ?? "text"}`,
2941
+ label: options.label ?? ((context) => context.locale.copy),
2942
+ icon: /* @__PURE__ */ jsx20(ToolIcon, { name: "copy" }),
2943
+ successLabel: (context) => context.locale.copied,
2944
+ successIcon: /* @__PURE__ */ jsx20(ToolIcon, { name: "check" }),
2945
+ run: async ({ selection }) => {
2946
+ const format = options.format ?? "text";
2947
+ await navigator.clipboard.writeText(format === "text" ? selection.text : selection[format].sourceText);
2948
+ }
2949
+ };
2950
+ }
2951
+ function HighlightSettings({ context, options }) {
2952
+ const { locale, highlight, highlightAppearance } = context;
2953
+ const color = highlightAppearance.color ?? defaultHighlight.color;
2954
+ const style = highlightAppearance.style ?? "background";
2955
+ const styles = [
2956
+ ["background", locale.highlightBackground],
2957
+ ["underline", locale.highlightUnderline],
2958
+ ["dotted", locale.highlightDotted],
2959
+ ["wavy", locale.highlightWavy]
2960
+ ];
2961
+ const change = (nextColor, nextStyle) => {
2962
+ const appearance = { ...highlightAppearance, color: nextColor, style: nextStyle };
2963
+ context.setHighlightAppearance(appearance);
2964
+ if (highlight) void context.run((current) => current.updateAnnotation(highlight.id, { data: appearance }));
2965
+ };
2966
+ return /* @__PURE__ */ jsxs16("div", { className: "limr-highlight-settings", children: [
2967
+ /* @__PURE__ */ jsxs16("fieldset", { disabled: context.busy, children: [
2968
+ /* @__PURE__ */ jsx20("legend", { children: locale.highlightStyle }),
2969
+ /* @__PURE__ */ jsx20("div", { className: "limr-highlight-styles", children: styles.map(([value, label]) => /* @__PURE__ */ jsxs16("button", { type: "button", "aria-pressed": style === value, onClick: () => change(color, value), children: [
2970
+ /* @__PURE__ */ jsx20(ToolIcon, { name: value }),
2971
+ /* @__PURE__ */ jsx20("span", { className: "limr-underline", children: label })
2972
+ ] }, value)) })
2973
+ ] }),
2974
+ /* @__PURE__ */ jsxs16("fieldset", { disabled: context.busy, children: [
2975
+ /* @__PURE__ */ jsx20("legend", { children: locale.highlightColor }),
2976
+ /* @__PURE__ */ jsx20("div", { className: "limr-highlight-colors", children: (options.colors ?? highlightColors).map((item) => /* @__PURE__ */ jsx20("button", { type: "button", className: "limr-color-swatch", "aria-label": locale.highlight === "\u9AD8\u4EAE" ? item.labelZh ?? item.label : item.label, title: locale.highlight === "\u9AD8\u4EAE" ? item.labelZh ?? item.label : item.label, "aria-pressed": color.toLowerCase() === item.color.toLowerCase(), style: { "--swatch": item.color }, onClick: () => change(item.color, style), children: /* @__PURE__ */ jsx20(ToolIcon, { name: "check" }) }, item.color)) })
2977
+ ] })
2978
+ ] });
2979
+ }
2980
+ function highlightPalette(options = {}) {
2981
+ return {
2982
+ id: "highlight-palette",
2983
+ label: (context) => context.locale.editHighlight,
2984
+ icon: /* @__PURE__ */ jsx20(ToolIcon, { name: "background" }),
2985
+ placement: "start",
2986
+ render: (context) => /* @__PURE__ */ jsx20("button", { type: "button", className: "limr-toolbar-swatch", "aria-label": context.locale.editHighlight, "aria-expanded": context.expanded, disabled: context.busy, onClick: () => context.expanded ? context.collapse() : context.expand(), style: { "--swatch": context.highlightAppearance.color ?? defaultHighlight.color } }),
2987
+ renderExpanded: (context) => /* @__PURE__ */ jsx20(HighlightSettings, { context, options })
2988
+ };
2989
+ }
2990
+ function highlightSelection() {
2991
+ return {
2992
+ id: "highlight",
2993
+ label: (context) => !context.highlight ? context.locale.addHighlight : context.highlight.data?.hidden ? context.locale.showHighlight : context.locale.hideHighlight,
2994
+ icon: (context) => /* @__PURE__ */ jsx20(ToolIcon, { name: !context.highlight ? "highlight" : context.highlight.data?.hidden ? "eye" : "eye-off" }),
2995
+ visible: (context) => !context.highlight || context.annotations.some((annotation) => annotation.type !== "highlight"),
2996
+ run: (context) => {
2997
+ if (context.highlight) context.updateAnnotation(context.highlight.id, { data: { ...context.highlight.data, hidden: !context.highlight.data?.hidden } });
2998
+ else {
2999
+ context.addAnnotation({ id: `highlight-${crypto.randomUUID()}`, type: "highlight", data: { ...context.highlightAppearance, hidden: false }, anchors: context.selection.syntax.ranges.map((range) => ({ range, documentId: context.document.id, quote: context.document.source.slice(range.start, range.end) })) });
3000
+ context.clearSelection();
3001
+ }
3002
+ }
3003
+ };
3004
+ }
3005
+ function deleteAnnotations() {
3006
+ return {
3007
+ id: "delete-annotations",
3008
+ label: (context) => context.locale.deleteAnnotations,
3009
+ icon: /* @__PURE__ */ jsx20(ToolIcon, { name: "trash" }),
3010
+ placement: "end",
3011
+ tone: "danger",
3012
+ visible: (context) => context.annotations.length > 0,
3013
+ run: (context) => {
3014
+ context.removeAnnotationsAt([...context.selection.raw.ranges, ...context.selection.syntax.ranges]);
3015
+ context.activateAnnotation(null);
3016
+ context.clearSelection();
3017
+ }
3018
+ };
3019
+ }
3020
+
3021
+ export {
3022
+ scrollWithMotion,
3023
+ english,
3024
+ chinese,
3025
+ gfm,
3026
+ preloadMath,
3027
+ math,
3028
+ codeHighlight,
3029
+ sourceRangeStartRect,
3030
+ Markdown,
3031
+ OverlayScrollArea,
3032
+ AnnotationCard,
3033
+ AnnotationMarkdown,
3034
+ citation,
3035
+ InlineMarker,
3036
+ Collapse,
3037
+ translations,
3038
+ defineBlock,
3039
+ defineAnnotation,
3040
+ defineExtension,
3041
+ video,
3042
+ figures,
3043
+ definition,
3044
+ question,
3045
+ extras,
3046
+ standard,
3047
+ useIsomorphicLayoutEffect,
3048
+ DocumentProvider,
3049
+ useRuntime,
3050
+ useRendererParameter,
3051
+ useStoreSelector,
3052
+ useDocument,
3053
+ useDocumentSelector,
3054
+ useSelection,
3055
+ useTheme,
3056
+ useAppearance,
3057
+ useLocale,
3058
+ useAnnotation,
3059
+ useAnnotations,
3060
+ useAnnotationState,
3061
+ useAnchor,
3062
+ useLiMR,
3063
+ ToolIcon,
3064
+ highlightColors,
3065
+ copyText,
3066
+ highlightPalette,
3067
+ highlightSelection,
3068
+ deleteAnnotations
3069
+ };
3070
+ //# sourceMappingURL=chunk-65V5OZ4G.js.map