markdown-flow-ui 0.3.2-dev.2 → 0.3.2

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 (283) hide show
  1. package/README.md +0 -13
  2. package/dist/_virtual/index.es8.js +2 -2
  3. package/dist/_virtual/index.es9.js +2 -2
  4. package/dist/_virtual/index8.cjs +1 -1
  5. package/dist/_virtual/index9.cjs +1 -1
  6. package/dist/assets/markdown-flow-ui.css +1 -1
  7. package/dist/components/ContentRender/IframeSandbox.cjs.map +1 -1
  8. package/dist/components/ContentRender/IframeSandbox.es.js.map +1 -1
  9. package/dist/components/ContentRender/utils/video-markdown-run.cjs.map +1 -1
  10. package/dist/components/ContentRender/utils/video-markdown-run.es.js.map +1 -1
  11. package/dist/components/MarkdownFlow/ScrollToBottomButton.cjs.map +1 -1
  12. package/dist/components/MarkdownFlow/ScrollToBottomButton.es.js.map +1 -1
  13. package/dist/components/MarkdownFlow/ScrollToBottomControl.cjs.map +1 -1
  14. package/dist/components/MarkdownFlow/ScrollToBottomControl.es.js.map +1 -1
  15. package/dist/components/MarkdownFlow/useScrollToBottom.cjs.map +1 -1
  16. package/dist/components/MarkdownFlow/useScrollToBottom.es.js.map +1 -1
  17. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs +1 -1
  18. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.cjs.map +1 -1
  19. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.d.ts +2 -2
  20. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js +323 -562
  21. package/dist/components/MarkdownFlowEditor/MarkdownFlowEditor.es.js.map +1 -1
  22. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.cjs +1 -1
  23. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.cjs.map +1 -1
  24. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.d.ts +0 -8
  25. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.es.js +64 -107
  26. package/dist/components/MarkdownFlowEditor/components/EditorToolbar.es.js.map +1 -1
  27. package/dist/components/MarkdownFlowEditor/editor-context.cjs +1 -1
  28. package/dist/components/MarkdownFlowEditor/editor-context.cjs.map +1 -1
  29. package/dist/components/MarkdownFlowEditor/editor-context.es.js +4 -10
  30. package/dist/components/MarkdownFlowEditor/editor-context.es.js.map +1 -1
  31. package/dist/components/MarkdownFlowEditor/editorI18n.d.ts +0 -308
  32. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.cjs +1 -1
  33. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.d.ts +1 -15
  34. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js +87 -115
  35. package/dist/components/MarkdownFlowEditor/locales/ar-SA.json.es.js.map +1 -1
  36. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.cjs +1 -1
  37. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.d.ts +1 -15
  38. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js +88 -116
  39. package/dist/components/MarkdownFlowEditor/locales/de-DE.json.es.js.map +1 -1
  40. package/dist/components/MarkdownFlowEditor/locales/en-US.json.cjs +1 -1
  41. package/dist/components/MarkdownFlowEditor/locales/en-US.json.d.ts +1 -15
  42. package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js +88 -116
  43. package/dist/components/MarkdownFlowEditor/locales/en-US.json.es.js.map +1 -1
  44. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.cjs +1 -1
  45. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.d.ts +1 -15
  46. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js +80 -108
  47. package/dist/components/MarkdownFlowEditor/locales/es-ES.json.es.js.map +1 -1
  48. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.cjs +1 -1
  49. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.d.ts +1 -15
  50. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js +82 -110
  51. package/dist/components/MarkdownFlowEditor/locales/fil-PH.json.es.js.map +1 -1
  52. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.cjs +1 -1
  53. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.d.ts +1 -15
  54. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js +86 -114
  55. package/dist/components/MarkdownFlowEditor/locales/fr-FR.json.es.js.map +1 -1
  56. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.cjs +1 -1
  57. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.d.ts +1 -15
  58. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js +88 -116
  59. package/dist/components/MarkdownFlowEditor/locales/ja-JP.json.es.js.map +1 -1
  60. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.cjs +1 -1
  61. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.d.ts +1 -15
  62. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js +85 -113
  63. package/dist/components/MarkdownFlowEditor/locales/th-TH.json.es.js.map +1 -1
  64. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.cjs +1 -1
  65. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.d.ts +1 -15
  66. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js +94 -122
  67. package/dist/components/MarkdownFlowEditor/locales/ur-PK.json.es.js.map +1 -1
  68. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.cjs +1 -1
  69. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.d.ts +1 -15
  70. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js +74 -102
  71. package/dist/components/MarkdownFlowEditor/locales/vi-VN.json.es.js.map +1 -1
  72. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.cjs +1 -1
  73. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.d.ts +1 -15
  74. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js +72 -100
  75. package/dist/components/MarkdownFlowEditor/locales/zh-CN.json.es.js.map +1 -1
  76. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs +1 -1
  77. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.cjs.map +1 -1
  78. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.d.ts +2 -1
  79. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js +62 -53
  80. package/dist/components/MarkdownFlowEditor/plugins/ImgPlaceholder.es.js.map +1 -1
  81. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.cjs.map +1 -1
  82. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.d.ts +1 -1
  83. package/dist/components/MarkdownFlowEditor/plugins/PlaceholderWidget.es.js.map +1 -1
  84. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs +3 -3
  85. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.cjs.map +1 -1
  86. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.d.ts +1 -5
  87. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js +149 -154
  88. package/dist/components/MarkdownFlowEditor/plugins/SyntaxHighlighter.es.js.map +1 -1
  89. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs +1 -1
  90. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.cjs.map +1 -1
  91. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.d.ts +2 -1
  92. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js +53 -42
  93. package/dist/components/MarkdownFlowEditor/plugins/VideoPlaceholder.es.js.map +1 -1
  94. package/dist/components/MarkdownFlowEditor/types.cjs +1 -1
  95. package/dist/components/MarkdownFlowEditor/types.cjs.map +1 -1
  96. package/dist/components/MarkdownFlowEditor/types.d.ts +1 -11
  97. package/dist/components/MarkdownFlowEditor/types.es.js +2 -2
  98. package/dist/components/MarkdownFlowEditor/types.es.js.map +1 -1
  99. package/dist/components/MarkdownFlowEditor/utils.cjs +1 -1
  100. package/dist/components/MarkdownFlowEditor/utils.cjs.map +1 -1
  101. package/dist/components/MarkdownFlowEditor/utils.d.ts +0 -10
  102. package/dist/components/MarkdownFlowEditor/utils.es.js +59 -73
  103. package/dist/components/MarkdownFlowEditor/utils.es.js.map +1 -1
  104. package/dist/components/Slide/MarkdownSlideScaling.cjs.map +1 -1
  105. package/dist/components/Slide/MarkdownSlideScaling.es.js.map +1 -1
  106. package/dist/components/Slide/MobilePlayerSettingsSheet.es.js +16 -16
  107. package/dist/components/Slide/Player.cjs.map +1 -1
  108. package/dist/components/Slide/Player.es.js.map +1 -1
  109. package/dist/components/Slide/Slide.cjs.map +1 -1
  110. package/dist/components/Slide/Slide.es.js.map +1 -1
  111. package/dist/components/Slide/SubtitleOverlay.cjs.map +1 -1
  112. package/dist/components/Slide/SubtitleOverlay.es.js.map +1 -1
  113. package/dist/components/Slide/slideI18n.cjs.map +1 -1
  114. package/dist/components/Slide/slideI18n.es.js.map +1 -1
  115. package/dist/components/Slide/useSlide.cjs.map +1 -1
  116. package/dist/components/Slide/useSlide.es.js.map +1 -1
  117. package/dist/components/Slide/utils/streamingNavigation.cjs.map +1 -1
  118. package/dist/components/Slide/utils/streamingNavigation.es.js.map +1 -1
  119. package/dist/components/ui/dialog.cjs +1 -1
  120. package/dist/components/ui/dialog.cjs.map +1 -1
  121. package/dist/components/ui/dialog.es.js +27 -27
  122. package/dist/components/ui/dialog.es.js.map +1 -1
  123. package/dist/lib/interaction-defaults.cjs.map +1 -1
  124. package/dist/lib/interaction-defaults.es.js.map +1 -1
  125. package/dist/markdown-flow-ui-lib.css +1 -1
  126. package/dist/markdown-flow-ui.css +1 -1
  127. package/dist/node_modules/@braintree/sanitize-url/dist/index.cjs +1 -1
  128. package/dist/node_modules/@braintree/sanitize-url/dist/index.es.js +1 -1
  129. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs +1 -1
  130. package/dist/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -1
  131. package/dist/node_modules/@radix-ui/react-context/dist/index.es.js +34 -49
  132. package/dist/node_modules/@radix-ui/react-context/dist/index.es.js.map +1 -1
  133. package/dist/node_modules/@radix-ui/react-dialog/dist/index.cjs +1 -5
  134. package/dist/node_modules/@radix-ui/react-dialog/dist/index.cjs.map +1 -1
  135. package/dist/node_modules/@radix-ui/react-dialog/dist/index.es.js +206 -220
  136. package/dist/node_modules/@radix-ui/react-dialog/dist/index.es.js.map +1 -1
  137. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/primitive/dist/index.cjs +2 -0
  138. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/primitive/dist/index.cjs.map +1 -0
  139. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/primitive/dist/index.es.js +50 -0
  140. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/primitive/dist/index.es.js.map +1 -0
  141. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +2 -0
  142. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -0
  143. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-compose-refs/dist/index.es.js +34 -0
  144. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-compose-refs/dist/index.es.js.map +1 -0
  145. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-context/dist/index.cjs +2 -0
  146. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-context/dist/index.cjs.map +1 -0
  147. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-context/dist/index.es.js +82 -0
  148. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-context/dist/index.es.js.map +1 -0
  149. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs +2 -0
  150. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer/dist/index.cjs.map +1 -0
  151. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer/dist/index.es.js +216 -0
  152. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-dismissable-layer/dist/index.es.js.map +1 -0
  153. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-id/dist/index.cjs +2 -0
  154. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-id/dist/index.cjs.map +1 -0
  155. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-id/dist/index.es.js +15 -0
  156. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-id/dist/index.es.js.map +1 -0
  157. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal/dist/index.cjs +2 -0
  158. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal/dist/index.cjs.map +1 -0
  159. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal/dist/index.es.js +18 -0
  160. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-portal/dist/index.es.js.map +1 -0
  161. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence/dist/index.cjs +2 -0
  162. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence/dist/index.cjs.map +1 -0
  163. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence/dist/index.es.js +104 -0
  164. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-presence/dist/index.es.js.map +1 -0
  165. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive/dist/index.cjs +2 -0
  166. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -0
  167. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive/dist/index.es.js +39 -0
  168. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-primitive/dist/index.es.js.map +1 -0
  169. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +2 -0
  170. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.map +1 -0
  171. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-callback-ref/dist/index.es.js +13 -0
  172. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-callback-ref/dist/index.es.js.map +1 -0
  173. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs +2 -0
  174. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-controllable-state/dist/index.cjs.map +1 -0
  175. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-controllable-state/dist/index.es.js +70 -0
  176. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-controllable-state/dist/index.es.js.map +1 -0
  177. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-effect-event/dist/index.cjs +2 -0
  178. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-effect-event/dist/index.cjs.map +1 -0
  179. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-effect-event/dist/index.es.js +20 -0
  180. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-effect-event/dist/index.es.js.map +1 -0
  181. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs +2 -0
  182. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-layout-effect/dist/index.cjs.map +1 -0
  183. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-layout-effect/dist/index.es.js +7 -0
  184. package/dist/node_modules/@radix-ui/react-dialog/node_modules/@radix-ui/react-use-layout-effect/dist/index.es.js.map +1 -0
  185. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs +1 -1
  186. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.cjs.map +1 -1
  187. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.es.js +18 -9
  188. package/dist/node_modules/@radix-ui/react-focus-guards/dist/index.es.js.map +1 -1
  189. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs +1 -1
  190. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.cjs.map +1 -1
  191. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.es.js +148 -100
  192. package/dist/node_modules/@radix-ui/react-focus-scope/dist/index.es.js.map +1 -1
  193. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +2 -0
  194. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -0
  195. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-compose-refs/dist/index.es.js +34 -0
  196. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-compose-refs/dist/index.es.js.map +1 -0
  197. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive/dist/index.cjs +2 -0
  198. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -0
  199. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive/dist/index.es.js +39 -0
  200. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-primitive/dist/index.es.js.map +1 -0
  201. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs +2 -0
  202. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-use-callback-ref/dist/index.cjs.map +1 -0
  203. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-use-callback-ref/dist/index.es.js +13 -0
  204. package/dist/node_modules/@radix-ui/react-focus-scope/node_modules/@radix-ui/react-use-callback-ref/dist/index.es.js.map +1 -0
  205. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs +1 -1
  206. package/dist/node_modules/@radix-ui/react-id/dist/index.cjs.map +1 -1
  207. package/dist/node_modules/@radix-ui/react-id/dist/index.es.js +8 -8
  208. package/dist/node_modules/@radix-ui/react-id/dist/index.es.js.map +1 -1
  209. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs +1 -1
  210. package/dist/node_modules/@radix-ui/react-primitive/dist/index.cjs.map +1 -1
  211. package/dist/node_modules/@radix-ui/react-primitive/dist/index.es.js +1 -1
  212. package/dist/node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot/dist/index.cjs +2 -0
  213. package/dist/node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -0
  214. package/dist/node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot/dist/index.es.js +50 -0
  215. package/dist/node_modules/@radix-ui/react-primitive/node_modules/@radix-ui/react-slot/dist/index.es.js.map +1 -0
  216. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs +1 -1
  217. package/dist/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -1
  218. package/dist/node_modules/@radix-ui/react-slot/dist/index.es.js +80 -41
  219. package/dist/node_modules/@radix-ui/react-slot/dist/index.es.js.map +1 -1
  220. package/dist/node_modules/@radix-ui/react-slot/node_modules/@radix-ui/react-compose-refs/dist/index.cjs +2 -0
  221. package/dist/node_modules/@radix-ui/react-slot/node_modules/@radix-ui/react-compose-refs/dist/index.cjs.map +1 -0
  222. package/dist/node_modules/@radix-ui/react-slot/node_modules/@radix-ui/react-compose-refs/dist/index.es.js +34 -0
  223. package/dist/node_modules/@radix-ui/react-slot/node_modules/@radix-ui/react-compose-refs/dist/index.es.js.map +1 -0
  224. package/dist/node_modules/@radix-ui/react-tooltip/dist/index.cjs +1 -1
  225. package/dist/node_modules/@radix-ui/react-tooltip/dist/index.cjs.map +1 -1
  226. package/dist/node_modules/@radix-ui/react-tooltip/dist/index.es.js +1 -1
  227. package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-slot/dist/index.cjs +2 -0
  228. package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-slot/dist/index.cjs.map +1 -0
  229. package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-slot/dist/index.es.js +12 -0
  230. package/dist/node_modules/@radix-ui/react-tooltip/node_modules/@radix-ui/react-slot/dist/index.es.js.map +1 -0
  231. package/dist/node_modules/classnames/index.cjs +1 -1
  232. package/dist/node_modules/classnames/index.es.js +1 -1
  233. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs +2 -2
  234. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.cjs.map +1 -1
  235. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.es.js +75 -72
  236. package/dist/node_modules/react-remove-scroll/dist/es2015/SideEffect.es.js.map +1 -1
  237. package/package.json +10 -10
  238. package/dist/components/MarkdownFlowEditor/components/CustomPopover.cjs +0 -2
  239. package/dist/components/MarkdownFlowEditor/components/CustomPopover.cjs.map +0 -1
  240. package/dist/components/MarkdownFlowEditor/components/CustomPopover.d.ts +0 -17
  241. package/dist/components/MarkdownFlowEditor/components/CustomPopover.es.js +0 -46
  242. package/dist/components/MarkdownFlowEditor/components/CustomPopover.es.js.map +0 -1
  243. package/dist/components/MarkdownFlowEditor/components/VariableSearchDropdown.cjs +0 -2
  244. package/dist/components/MarkdownFlowEditor/components/VariableSearchDropdown.cjs.map +0 -1
  245. package/dist/components/MarkdownFlowEditor/components/VariableSearchDropdown.d.ts +0 -18
  246. package/dist/components/MarkdownFlowEditor/components/VariableSearchDropdown.es.js +0 -184
  247. package/dist/components/MarkdownFlowEditor/components/VariableSearchDropdown.es.js.map +0 -1
  248. package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs +0 -2
  249. package/dist/components/MarkdownFlowEditor/components/VariableSelect.cjs.map +0 -1
  250. package/dist/components/MarkdownFlowEditor/components/VariableSelect.d.ts +0 -11
  251. package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js +0 -172
  252. package/dist/components/MarkdownFlowEditor/components/VariableSelect.es.js.map +0 -1
  253. package/dist/components/MarkdownFlowEditor/components/icons/SearchBracesIcon.cjs +0 -2
  254. package/dist/components/MarkdownFlowEditor/components/icons/SearchBracesIcon.cjs.map +0 -1
  255. package/dist/components/MarkdownFlowEditor/components/icons/SearchBracesIcon.d.ts +0 -3
  256. package/dist/components/MarkdownFlowEditor/components/icons/SearchBracesIcon.es.js +0 -32
  257. package/dist/components/MarkdownFlowEditor/components/icons/SearchBracesIcon.es.js.map +0 -1
  258. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs +0 -3
  259. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.cjs.map +0 -1
  260. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.d.ts +0 -9
  261. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js +0 -53
  262. package/dist/components/MarkdownFlowEditor/plugins/VariablePlaceholder.es.js.map +0 -1
  263. package/dist/components/ui/popover.cjs +0 -2
  264. package/dist/components/ui/popover.cjs.map +0 -1
  265. package/dist/components/ui/popover.es.js +0 -24
  266. package/dist/components/ui/popover.es.js.map +0 -1
  267. package/dist/node_modules/@radix-ui/react-popover/dist/index.cjs +0 -2
  268. package/dist/node_modules/@radix-ui/react-popover/dist/index.cjs.map +0 -1
  269. package/dist/node_modules/@radix-ui/react-popover/dist/index.es.js +0 -241
  270. package/dist/node_modules/@radix-ui/react-popover/dist/index.es.js.map +0 -1
  271. package/dist/node_modules/lucide-react/dist/esm/icons/braces.cjs +0 -7
  272. package/dist/node_modules/lucide-react/dist/esm/icons/braces.cjs.map +0 -1
  273. package/dist/node_modules/lucide-react/dist/esm/icons/braces.es.js +0 -25
  274. package/dist/node_modules/lucide-react/dist/esm/icons/braces.es.js.map +0 -1
  275. package/dist/node_modules/lucide-react/dist/esm/icons/plus.cjs +0 -7
  276. package/dist/node_modules/lucide-react/dist/esm/icons/plus.cjs.map +0 -1
  277. package/dist/node_modules/lucide-react/dist/esm/icons/plus.es.js +0 -16
  278. package/dist/node_modules/lucide-react/dist/esm/icons/plus.es.js.map +0 -1
  279. package/dist/node_modules/lucide-react/dist/esm/icons/search.cjs +0 -7
  280. package/dist/node_modules/lucide-react/dist/esm/icons/search.cjs.map +0 -1
  281. package/dist/node_modules/lucide-react/dist/esm/icons/search.es.js +0 -16
  282. package/dist/node_modules/lucide-react/dist/esm/icons/search.es.js.map +0 -1
  283. /package/dist/components/MarkdownFlowEditor/plugins/{VariablePlaceholder.test.d.ts → MediaPlaceholder.variables.test.d.ts} +0 -0
@@ -1 +1 @@
1
- {"version":3,"file":"IframeSandbox.es.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport SandboxApp from \"./SandboxApp\";\nimport { normalizeContentViewportMinHeight } from \"./utils/content-viewport-min-height\";\nimport ContentRender from \"./ContentRender\";\nimport {\n EMPTY_ROOT_HEIGHT_META,\n inspectViewportHeightFromHtmlRootString,\n inspectViewportHeightFromNodeChain,\n parseExplicitHeight,\n resolveExplicitHeightFromNodeChain,\n} from \"./utils/iframe-viewport-height\";\nimport {\n SANDBOX_INTERACTION_MESSAGE_SOURCE,\n SANDBOX_INTERACTION_MESSAGE_TYPE,\n} from \"../../lib/sandboxInteraction\";\nimport {\n injectScalingSystem,\n type ScalingWindow,\n} from \"./utils/iframe-scaling\";\nimport {\n getMarkdownFlowDirection,\n getMarkdownFlowLanguage,\n type MarkdownFlowLocale,\n} from \"../../lib/locale\";\nimport { useDetachedLanguage } from \"../../lib/useDetachedLanguage\";\nimport { useResolvedDirection } from \"../../lib/useResolvedDirection\";\nimport { getContentRenderLocaleTexts } from \"./contentRenderI18n\";\nimport { CJK_SAFE_SANS_FONT_FAMILY } from \"./cjkFontFamily\";\n\ntype BlackboardVendorModule = typeof import(\"./blackboard-vendor\");\n\n// Cache the sandbox vendor loader so every iframe reuses the same preload request.\nlet blackboardVendorPromise: Promise<BlackboardVendorModule> | null = null;\n\nconst loadBlackboardVendor = () => {\n if (!blackboardVendorPromise) {\n blackboardVendorPromise = import(\"./blackboard-vendor\");\n }\n\n return blackboardVendorPromise;\n};\n\nconst COMPLETE_IMAGE_TAG_PATTERN = /<img\\b[^>]*>/i;\nconst POST_IMAGE_STREAM_DEBOUNCE_MS = 180;\nconst SANDBOX_INTERACTION_THROTTLE_MS = 240;\n\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n locale?: MarkdownFlowLocale;\n /** Overrides the locale-derived language without changing authored HTML language. */\n lang?: string;\n /** Overrides locale-derived direction without replacing authored HTML direction. */\n dir?: React.HTMLAttributes<HTMLDivElement>[\"dir\"];\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n exitFullScreenButtonText?: string;\n hideFullScreen?: boolean;\n mode?: \"content\" | \"blackboard\";\n type: \"sandbox\" | \"markdown\";\n replaceRootScreenHeightWithFull?: boolean;\n enableScaling?: boolean;\n disableLoadingOverlay?: boolean;\n}\n\nconst replaceRootScreenHeightToken = (className: string) =>\n className\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => {\n const segments = token.split(\":\");\n if (\n segments[segments.length - 1] !== \"h-screen\" &&\n segments[segments.length - 1] !== \"min-h-screen\"\n ) {\n return token;\n }\n segments[segments.length - 1] = \"h-full\";\n return segments.join(\":\");\n })\n .join(\" \");\n\nconst replaceRootScreenHeightWithFullClass = (\n html: string,\n enabled: boolean\n) => {\n if (!enabled || !html.trim()) {\n return html;\n }\n\n return html.replace(\n /^(\\s*<[a-zA-Z][\\w:-]*)(\\s[^>]*?)?>/,\n (match, tagStart: string, attrs = \"\") => {\n const classMatch = attrs.match(/\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/i);\n\n if (!classMatch) {\n return match;\n }\n\n const nextClassName = replaceRootScreenHeightToken(classMatch[2]);\n\n if (nextClassName === classMatch[2]) {\n return match;\n }\n\n return `${tagStart}${attrs.replace(\n classMatch[0],\n `class=${classMatch[1]}${nextClassName}${classMatch[1]}`\n )}>`;\n }\n );\n};\n\nconst IframeSandboxInstance: React.FC<IframeSandboxProps> = ({\n content,\n type,\n className,\n locale,\n lang,\n dir,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n exitFullScreenButtonText,\n hideFullScreen = false,\n mode = \"content\",\n replaceRootScreenHeightWithFull = false,\n enableScaling = false,\n disableLoadingOverlay = false,\n}) => {\n const localeTexts = getContentRenderLocaleTexts(locale);\n const direction = dir ?? getMarkdownFlowDirection(locale);\n const language = lang ?? getMarkdownFlowLanguage(locale);\n const resolvedFullScreenButtonText =\n fullScreenButtonText || localeTexts.sandboxFullscreenButtonText;\n const resolvedExitFullScreenButtonText =\n exitFullScreenButtonText || localeTexts.sandboxExitFullscreenButtonText;\n const containerRef = useRef<HTMLDivElement>(null);\n const fullscreenButtonRef = useRef<HTMLButtonElement>(null);\n const sandboxLanguage = useDetachedLanguage(containerRef, language);\n const { resolvedDirection } = useResolvedDirection(containerRef, direction);\n const markdownContainerRef = useRef<HTMLDivElement>(null);\n const markdownContentRef = useRef<HTMLElement>(null);\n const setMarkdownContentContainerRef = useCallback(\n (node: HTMLDivElement | null) => {\n markdownContainerRef.current = node;\n markdownContentRef.current =\n node?.querySelector<HTMLElement>(\".content-render\") ?? null;\n },\n []\n );\n const { resolvedDirection: markdownContentDirection } = useResolvedDirection(\n markdownContentRef,\n direction\n );\n const sandboxDirection = direction ?? resolvedDirection;\n const requestedDirectionRef = useRef(direction);\n requestedDirectionRef.current = direction;\n // Auto direction cannot inspect text across the iframe document boundary.\n // Mirror the rendered sandbox direction to host controls instead.\n const [sandboxContentDirection, setSandboxContentDirection] = useState<\n \"ltr\" | \"rtl\"\n >();\n let fullscreenControlDirection: \"ltr\" | \"rtl\" | undefined;\n if (direction === \"auto\") {\n fullscreenControlDirection = resolvedDirection;\n if (type === \"sandbox\") {\n fullscreenControlDirection = sandboxContentDirection ?? resolvedDirection;\n } else if (mode === \"blackboard\") {\n fullscreenControlDirection = markdownContentDirection;\n }\n }\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const rootRef = useRef<Root | null>(null);\n const updateHeightRef = useRef<() => void>(() => {});\n const [height, setHeight] = useState(480);\n const [contentHeight, setContentHeight] = useState<number | null>(null);\n const [containerWidth, setContainerWidth] = useState(0);\n const [fullscreenControlHeight, setFullscreenControlHeight] = useState(0);\n const isMeasuringContentRef = useRef(false);\n const pendingHeightUpdateRef = useRef(false);\n const lastSandboxInteractionTimeRef = useRef(0);\n const [resetToken, setResetToken] = useState(0);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const shouldInjectSandboxVendor = type === \"sandbox\";\n\n const isBlackboardMode = mode === \"blackboard\";\n const shouldEnableScaling =\n enableScaling && isBlackboardMode && type === \"sandbox\";\n const shouldMeasureDynamicHeight = isBlackboardMode && type === \"sandbox\";\n const shouldProcessRootScreenHeight =\n shouldMeasureDynamicHeight && replaceRootScreenHeightWithFull;\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(\n () => (type === \"sandbox\" ? content : \"\"),\n [content, type]\n );\n const normalizedHtmlContent = React.useMemo(\n () =>\n replaceRootScreenHeightWithFullClass(\n htmlContent,\n shouldProcessRootScreenHeight\n ),\n [htmlContent, shouldProcessRootScreenHeight]\n );\n const originalRootHeightMeta = React.useMemo(\n () =>\n shouldProcessRootScreenHeight\n ? inspectViewportHeightFromHtmlRootString(htmlContent)\n : EMPTY_ROOT_HEIGHT_META,\n [htmlContent, shouldProcessRootScreenHeight]\n );\n const shouldStretchRootHeight = React.useMemo(\n () =>\n shouldProcessRootScreenHeight &&\n originalRootHeightMeta.hasFullViewportHeight,\n [\n originalRootHeightMeta.hasFullViewportHeight,\n shouldProcessRootScreenHeight,\n ]\n );\n const [renderHtmlContent, setRenderHtmlContent] = useState(\n normalizedHtmlContent\n );\n const prevIncomingHtmlRef = useRef(normalizedHtmlContent);\n const pendingHtmlRef = useRef(normalizedHtmlContent);\n const deferRenderTimerRef = useRef<number | null>(null);\n const initialPaintFrameRef = useRef<number | null>(null);\n const renderViewportHeightCssRef = useRef<string | null>(null);\n\n const emitSandboxInteraction = useCallback((eventType: string) => {\n if (typeof window === \"undefined\") {\n return;\n }\n const now = Date.now();\n if (\n now - lastSandboxInteractionTimeRef.current <\n SANDBOX_INTERACTION_THROTTLE_MS\n ) {\n return;\n }\n lastSandboxInteractionTimeRef.current = now;\n window.postMessage(\n {\n source: SANDBOX_INTERACTION_MESSAGE_SOURCE,\n type: SANDBOX_INTERACTION_MESSAGE_TYPE,\n eventType,\n },\n window.location.origin\n );\n }, []);\n\n useEffect(() => {\n if (type !== \"markdown\" || mode !== \"blackboard\") return;\n const container = markdownContainerRef.current;\n if (!container) return;\n const handleClick = () => emitSandboxInteraction(\"click\");\n container.addEventListener(\"click\", handleClick);\n return () => container.removeEventListener(\"click\", handleClick);\n }, [emitSandboxInteraction, mode, type]);\n\n const clearDeferredRenderTimer = () => {\n if (deferRenderTimerRef.current === null) return;\n window.clearTimeout(deferRenderTimerRef.current);\n deferRenderTimerRef.current = null;\n };\n\n const clearInitialPaintFrames = () => {\n if (initialPaintFrameRef.current !== null) {\n window.cancelAnimationFrame(initialPaintFrameRef.current);\n initialPaintFrameRef.current = null;\n }\n };\n\n useEffect(\n () => () => {\n clearDeferredRenderTimer();\n clearInitialPaintFrames();\n },\n []\n );\n\n useEffect(() => {\n const prevIncomingHtml = prevIncomingHtmlRef.current;\n prevIncomingHtmlRef.current = normalizedHtmlContent;\n\n const isAppendOnlyStream =\n !!prevIncomingHtml &&\n normalizedHtmlContent.length > prevIncomingHtml.length &&\n normalizedHtmlContent.startsWith(prevIncomingHtml);\n const containsCompleteImage = COMPLETE_IMAGE_TAG_PATTERN.test(\n normalizedHtmlContent\n );\n const shouldDeferRender = isAppendOnlyStream && containsCompleteImage;\n\n if (!shouldDeferRender) {\n clearDeferredRenderTimer();\n pendingHtmlRef.current = normalizedHtmlContent;\n setRenderHtmlContent(normalizedHtmlContent);\n return;\n }\n\n pendingHtmlRef.current = normalizedHtmlContent;\n clearDeferredRenderTimer();\n deferRenderTimerRef.current = window.setTimeout(() => {\n setRenderHtmlContent(pendingHtmlRef.current);\n deferRenderTimerRef.current = null;\n }, POST_IMAGE_STREAM_DEBOUNCE_MS);\n }, [normalizedHtmlContent]);\n\n const rootViewportHeightCss = React.useMemo(() => {\n if (!shouldMeasureDynamicHeight) {\n return null;\n }\n\n return inspectViewportHeightFromHtmlRootString(renderHtmlContent)\n .viewportHeightCss;\n }, [renderHtmlContent, shouldMeasureDynamicHeight]);\n\n useEffect(() => {\n renderViewportHeightCssRef.current = rootViewportHeightCss;\n }, [rootViewportHeightCss]);\n\n const hasRootVhHeight = Boolean(rootViewportHeightCss);\n const sandboxViewportHeight =\n isBlackboardMode && type === \"sandbox\"\n ? shouldEnableScaling\n ? \"100%\"\n : shouldStretchRootHeight\n ? \"100%\"\n : (rootViewportHeightCss ?? `${height}px`)\n : undefined;\n useEffect(() => {\n if (mode !== \"blackboard\") {\n prevHtmlRef.current = normalizedHtmlContent;\n return;\n }\n const prev = prevHtmlRef.current;\n const isContinuation = prev && normalizedHtmlContent.startsWith(prev);\n if (!isContinuation && prev) {\n setResetToken((token) => token + 1);\n }\n prevHtmlRef.current = normalizedHtmlContent;\n }, [mode, normalizedHtmlContent]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (!iframe) return undefined;\n\n const doc = iframe.contentDocument;\n if (!doc) return undefined;\n\n doc.open();\n doc.write(`<!DOCTYPE html>\n<html${mode === \"blackboard\" ? ' style=\"height: 100%;\"' : \"\"}>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <style>\n :root { color-scheme: light; }\n html, body, #root { width: 100%; font-family: ${CJK_SAFE_SANS_FONT_FAMILY}; }\n ${mode === \"blackboard\" ? \"html, body, #root { height: 100%; }\" : \"\"}\n html, body { margin: 0; padding: 0; overflow: ${shouldEnableScaling ? \"hidden auto\" : mode === \"blackboard\" ? \"auto\" : \"hidden\"}; }\n *, *::before, *::after { box-sizing: border-box; }\n ${\n mode !== \"blackboard\"\n ? `\n .h-screen { height: auto !important; }\n .min-h-screen { min-height: auto !important; }\n .h-dvh, .h-svh, .h-lvh { height: auto !important; }\n .min-h-dvh, .min-h-svh, .min-h-lvh { min-height: auto !important; }\n `\n : \"\"\n }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n\n // Force iframe theme to stay in light mode regardless of host OS preference.\n doc.documentElement.setAttribute(\"data-theme\", \"light\");\n doc.documentElement.style.colorScheme = \"light\";\n doc.body?.style.setProperty(\"color-scheme\", \"light\");\n\n const shouldBridgeSandboxInteraction =\n isBlackboardMode && type === \"sandbox\";\n const handleSandboxClick = () => emitSandboxInteraction(\"click\");\n\n if (shouldBridgeSandboxInteraction) {\n doc.addEventListener(\"click\", handleSandboxClick, true);\n }\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\n let isDestroyed = false;\n const getHeightInspectionNode = (node: HTMLElement) => ({\n heightAttrValue: node.getAttribute(\"height\"),\n styleAttrValue: node.getAttribute(\"style\"),\n classAttrValue: node.getAttribute(\"class\"),\n });\n const getSingleChildElement = (node: HTMLElement) => {\n const childElements = Array.from(node.children) as HTMLElement[];\n\n return childElements.length === 1 ? childElements[0] : null;\n };\n\n const resolveExplicitHeight = () => {\n if (!shouldMeasureDynamicHeight) return null;\n if (!iframeRef.current || !doc.body) return null;\n const parentViewportHeight =\n iframeRef.current.ownerDocument?.documentElement?.clientHeight ||\n window.innerHeight;\n // Reuse parsed height metadata from the current html snapshot first to\n // avoid re-inspecting the same DOM chain on every height tick.\n const precomputedViewportHeightCss = renderViewportHeightCssRef.current;\n const parsed = precomputedViewportHeightCss\n ? parseExplicitHeight(\n precomputedViewportHeightCss,\n parentViewportHeight\n )\n : null;\n\n if (parsed !== null) {\n return Math.ceil(parsed);\n }\n\n const wrapper = doc.body.querySelector(\n \".sandbox-wrapper\"\n ) as HTMLElement | null;\n const container = wrapper?.firstElementChild as HTMLElement | null;\n if (!container) return null;\n const containerChildren = Array.from(container.children) as HTMLElement[];\n const rootContentElement =\n containerChildren.length === 1 ? containerChildren[0] : null;\n const runtimeHeightMeta = inspectViewportHeightFromNodeChain(\n rootContentElement,\n {\n getNode: getHeightInspectionNode,\n getSingleChild: getSingleChildElement,\n }\n );\n const runtimeViewportHeightCss = runtimeHeightMeta.viewportHeightCss;\n\n if (runtimeViewportHeightCss) {\n const runtimeViewportHeight = parseExplicitHeight(\n runtimeViewportHeightCss,\n parentViewportHeight\n );\n\n if (runtimeViewportHeight !== null) {\n return Math.ceil(runtimeViewportHeight);\n }\n }\n\n const explicitPixelHeight = resolveExplicitHeightFromNodeChain(\n rootContentElement,\n parentViewportHeight,\n {\n getNode: getHeightInspectionNode,\n getSingleChild: getSingleChildElement,\n }\n );\n\n return explicitPixelHeight !== null\n ? Math.ceil(explicitPixelHeight)\n : null;\n };\n\n const updateHeight = () => {\n if (!iframeRef.current || !doc.body) return;\n\n if (!isBlackboardMode) {\n // Guard: prevent re-entrant measurement from ResizeObserver /\n // MutationObserver callbacks triggered by our own height changes.\n if (isMeasuringContentRef.current) {\n // Mark that an update was requested while the guard was active.\n // We will retry once the guard releases (see setTimeout below).\n pendingHeightUpdateRef.current = true;\n return;\n }\n isMeasuringContentRef.current = true;\n const contentContainer =\n doc.body.querySelector<HTMLElement>(\".sandbox-container\");\n if (contentContainer)\n normalizeContentViewportMinHeight(contentContainer);\n\n // Content mode height measurement strategy:\n // Temporarily set iframe height to the 16:9 layout viewport so that:\n // 1. vmin units are stable: vmin = min(cw, minH)/100 = minH/100,\n // consistent with the final rendered 16:9 iframe.\n // 2. Viewport-filling content (e.g. inline style=\"height:100vh\")\n // retains its 16:9 viewport. Naturally sized content reserves only\n // its measured body height in the host page.\n // (Previously using cw caused such content to report 1:1 height,\n // overriding the 16:9 minimum.)\n const iframe = iframeRef.current;\n const cw = containerRef.current?.clientWidth || 0;\n const prevH = iframe.style.height;\n\n if (cw > 0) {\n const minH = Math.round((cw * 9) / 16);\n // Absolute height cap. Diverging vh-feedback (multiple `height:100vh`\n // siblings, or compound vh-relative children whose sum exceeds the\n // viewport) can otherwise grow the iframe geometrically across\n // repeated ResizeObserver/MutationObserver passes. 1:20 aspect is\n // a generous upper bound for any single sandbox slide.\n const maxH = Math.max(8192, cw * 20);\n iframe.style.height = minH + \"px\";\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n doc.body.offsetHeight; // force layout\n\n let measuredH = doc.body.scrollHeight;\n\n // Detect inner elements that clip overflowing content behind a\n // scrollbar (e.g. <div style=\"height:100vh; overflow-y:auto\"> whose\n // content is taller than the iframe). body.scrollHeight won't see\n // that overflow, so we walk the tree and factor in each scrollable\n // element's full scroll height based on its position in the iframe.\n const iframeWin = doc.defaultView;\n if (iframeWin) {\n // Include fixed-position widgets, which do not contribute to body\n // scrollHeight, as well as content behind internal scrollbars.\n const getInnerScrollableHeight = (root: Element): number => {\n let maxH = 0;\n const walk = (el: Element) => {\n const style = iframeWin.getComputedStyle(el);\n if (style.position === \"fixed\") {\n maxH = Math.max(\n maxH,\n Math.ceil(el.getBoundingClientRect().bottom)\n );\n }\n if (el !== root && el.scrollHeight > el.clientHeight + 1) {\n const oy = style.overflowY;\n if (oy === \"auto\" || oy === \"scroll\") {\n const rect = el.getBoundingClientRect();\n if (rect.top >= 0) {\n maxH = Math.max(\n maxH,\n Math.ceil(rect.top + el.scrollHeight)\n );\n }\n }\n }\n for (const child of el.children) walk(child);\n };\n walk(root);\n return maxH;\n };\n\n measuredH = Math.max(measuredH, getInnerScrollableHeight(doc.body));\n\n // Content that uses vh-relative sizing grows as the viewport\n // expands. Measure up to 8 more times at the expanded height so\n // we capture the full content height in a single updateHeight()\n // call rather than waiting for external re-triggers.\n for (let i = 0; i < 8 && measuredH > minH; i++) {\n iframe.style.height = measuredH + \"px\";\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n doc.body.offsetHeight; // force layout at expanded size\n const nextH = Math.max(\n doc.body.scrollHeight,\n getInnerScrollableHeight(doc.body)\n );\n if (nextH <= measuredH + 1) break; // stable — stop iterating\n // Geometric vh-feedback detection: vh-relative children scale\n // with the iframe viewport, so growing the iframe makes them\n // larger which grows scrollHeight — runaway divergence. Two\n // `height:100vh` siblings produce a 2× per-iteration multiplier.\n // Stop iterating; keep the prior (stable) measuredH.\n if (nextH >= measuredH * 1.5) break;\n measuredH = nextH;\n }\n }\n\n // Restore iframe to let React control it via contentModeStyle\n iframe.style.height = prevH;\n\n setContentHeight((prev) => {\n const next = Math.min(maxH, Math.max(1, Math.ceil(measuredH)));\n return prev === next ? prev : next;\n });\n }\n\n setTimeout(() => {\n isMeasuringContentRef.current = false;\n // Retry any update that was blocked while the guard was active\n // (e.g. dynamic content injected by scripts or images loading).\n if (pendingHeightUpdateRef.current) {\n pendingHeightUpdateRef.current = false;\n scheduleHeightUpdate();\n }\n }, 50);\n return;\n }\n\n // Scaling mode: viewport is fixed, content scales via font-size.\n if (shouldEnableScaling) return;\n\n // Blackboard mode: use existing measurement logic\n const bodyScrollH = doc.body.scrollHeight;\n const htmlScrollH = doc.documentElement?.scrollHeight || 0;\n const rootScrollH = rootEl?.scrollHeight || 0;\n const measuredHeight = Math.max(bodyScrollH, htmlScrollH, rootScrollH);\n\n if (shouldMeasureDynamicHeight) {\n const explicitHeight = resolveExplicitHeight();\n const nextHeight = Math.max(\n 200,\n explicitHeight ?? Math.ceil(measuredHeight)\n );\n setHeight((prevHeight) =>\n prevHeight === nextHeight ? prevHeight : nextHeight\n );\n }\n };\n const scheduleHeightUpdate = () => {\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n updateHeight();\n });\n };\n updateHeightRef.current = scheduleHeightUpdate;\n\n updateHeight();\n scheduleHeightUpdate();\n\n if (shouldInjectSandboxVendor) {\n // Inject Tailwind/DaisyUI/GSAP before rendering sandbox content to avoid FOUC.\n loadBlackboardVendor()\n .then(({ injectBlackboardLibraries }) => {\n if (isDestroyed) return;\n injectBlackboardLibraries(doc);\n if (shouldEnableScaling) {\n injectScalingSystem(doc);\n }\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n });\n })\n .catch(() => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n });\n }\n\n const hostElement = containerRef.current;\n let needsTailwindRefreshAfterHidden = Boolean(\n hostElement &&\n (hostElement.clientWidth <= 0 || hostElement.clientHeight <= 0)\n );\n let isTailwindRefreshQueued = false;\n let tailwindRefreshFrame: number | null = null;\n let tailwindRefreshTimer: number | null = null;\n const runPostTailwindRefreshLayout = () => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n const iframeWin = iframe.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_triggerFitContent?.();\n };\n const isHostVisible = () =>\n Boolean(\n hostElement &&\n hostElement.clientWidth > 0 &&\n hostElement.clientHeight > 0\n );\n const queueTailwindRefreshAfterHidden = () => {\n if (\n !shouldInjectSandboxVendor ||\n !hostElement ||\n !needsTailwindRefreshAfterHidden ||\n isTailwindRefreshQueued ||\n !isHostVisible()\n ) {\n return;\n }\n\n isTailwindRefreshQueued = true;\n loadBlackboardVendor()\n .then(({ refreshTailwindRuntime }) => {\n if (isDestroyed) return;\n\n tailwindRefreshFrame = window.requestAnimationFrame(() => {\n tailwindRefreshFrame = null;\n isTailwindRefreshQueued = false;\n\n const sandboxContainer = doc.querySelector(\".sandbox-container\");\n if (\n isDestroyed ||\n !isHostVisible() ||\n !sandboxContainer?.childNodes.length ||\n !refreshTailwindRuntime(doc)\n ) {\n return;\n }\n\n needsTailwindRefreshAfterHidden = false;\n runPostTailwindRefreshLayout();\n tailwindRefreshTimer = window.setTimeout(() => {\n tailwindRefreshTimer = null;\n runPostTailwindRefreshLayout();\n }, 100);\n });\n })\n .catch(() => {\n isTailwindRefreshQueued = false;\n });\n };\n const canObserveResize = typeof ResizeObserver !== \"undefined\";\n const hostResizeObserver =\n shouldInjectSandboxVendor && hostElement && canObserveResize\n ? new ResizeObserver((entries) => {\n const contentRect = entries[0]?.contentRect;\n const hostWidth = contentRect?.width ?? hostElement.clientWidth;\n const hostHeight = contentRect?.height ?? hostElement.clientHeight;\n const isHostSizeVisible = hostWidth > 0 && hostHeight > 0;\n\n if (!isHostSizeVisible) {\n return;\n }\n\n queueTailwindRefreshAfterHidden();\n })\n : null;\n if (hostResizeObserver && hostElement) {\n hostResizeObserver.observe(hostElement);\n }\n\n const resizeObserver = canObserveResize\n ? new ResizeObserver(() => updateHeight())\n : null;\n resizeObserver?.observe(doc.body);\n if (rootEl) {\n resizeObserver?.observe(rootEl);\n }\n\n const syncSandboxContentDirection = () => {\n if (type !== \"sandbox\" || requestedDirectionRef.current !== \"auto\") {\n return;\n }\n const wrapper = doc.querySelector<HTMLElement>(\".sandbox-wrapper\");\n const view = doc.defaultView;\n if (!wrapper || !view) return;\n const nextDirection =\n view.getComputedStyle(wrapper).direction === \"rtl\" ? \"rtl\" : \"ltr\";\n setSandboxContentDirection((currentDirection) =>\n currentDirection === nextDirection ? currentDirection : nextDirection\n );\n };\n\n // MutationObserver: detect DOM changes that ResizeObserver might miss\n // (e.g. content injected by scripts, images loading, dynamic rendering)\n const mutationObserver = new MutationObserver(() => {\n syncSandboxContentDirection();\n scheduleHeightUpdate();\n if (!isHostVisible()) {\n needsTailwindRefreshAfterHidden = true;\n return;\n }\n queueTailwindRefreshAfterHidden();\n });\n mutationObserver.observe(doc.body, {\n childList: true,\n characterData: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"style\", \"class\", \"dir\"],\n });\n\n return () => {\n isDestroyed = true;\n hostResizeObserver?.disconnect();\n resizeObserver?.disconnect();\n mutationObserver.disconnect();\n if (tailwindRefreshFrame !== null) {\n window.cancelAnimationFrame(tailwindRefreshFrame);\n }\n if (tailwindRefreshTimer !== null) {\n window.clearTimeout(tailwindRefreshTimer);\n }\n if (shouldEnableScaling) {\n const iframeWin = iframe.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_cleanupScaling?.();\n }\n if (shouldBridgeSandboxInteraction) {\n doc.removeEventListener(\"click\", handleSandboxClick, true);\n }\n if (rootRef.current === root) {\n rootRef.current = null;\n updateHeightRef.current = () => {};\n }\n // Defer unmount to avoid React warning when parent is mid-render\n setTimeout(() => {\n root.unmount();\n }, 0);\n };\n }, []);\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(Boolean(document.fullscreenElement));\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n }, []);\n\n // Track the layout viewport width and enough host space for its own control.\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const button = fullscreenButtonRef.current;\n const updateControlHeight = () => {\n setFullscreenControlHeight(\n button ? Math.ceil(button.offsetTop + button.offsetHeight) : 0\n );\n };\n if (typeof ResizeObserver === \"undefined\") {\n setContainerWidth(el.clientWidth);\n updateControlHeight();\n return;\n }\n const ro = new ResizeObserver((entries) => {\n const hostEntry = entries.find((entry) => entry.target === el);\n if (hostEntry) setContainerWidth(hostEntry.contentRect.width);\n updateControlHeight();\n });\n ro.observe(el);\n if (button) ro.observe(button);\n setContainerWidth(el.clientWidth);\n updateControlHeight();\n return () => ro.disconnect();\n }, [hideFullScreen]);\n\n // Keep a stable layout viewport for authored vh/vmin sizing, while the host\n // reserves only the measured content height. The iframe is top-aligned inside\n // the clipped host so a short card does not leave a slide-sized blank area.\n const contentModeStyle = useMemo<React.CSSProperties | undefined>(() => {\n if (isBlackboardMode || containerWidth === 0 || isFullscreen)\n return undefined;\n const minH = Math.round((containerWidth * 9) / 16);\n return { height: Math.max(contentHeight ?? minH, fullscreenControlHeight) };\n }, [\n isBlackboardMode,\n containerWidth,\n contentHeight,\n isFullscreen,\n fullscreenControlHeight,\n ]);\n\n const contentIframeHeight = contentModeStyle\n ? Math.max(Math.round((containerWidth * 9) / 16), contentHeight ?? 0)\n : undefined;\n\n const toggleFullscreen = () => {\n const target = containerRef.current || iframeRef.current;\n if (!target) return;\n if (document.fullscreenElement) {\n document.exitFullscreen().catch(() => {});\n return;\n }\n if (target.requestFullscreen) {\n target.requestFullscreen().catch(() => {});\n }\n };\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(\n <SandboxApp\n html={renderHtmlContent}\n locale={locale}\n dir={sandboxDirection}\n lang={sandboxLanguage}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n disableLoadingOverlay={disableLoadingOverlay}\n resetToken={resetToken}\n hasRootVhHeight={hasRootVhHeight}\n mode={mode}\n stretchRootHeight={shouldStretchRootHeight}\n enableScaling={shouldEnableScaling}\n />\n );\n\n // Schedule multiple measurements to catch async content (scripts, images, styles).\n initialPaintFrameRef.current = window.requestAnimationFrame(() => {\n updateHeightRef.current?.();\n if (shouldEnableScaling) {\n const iframeWin = iframeRef.current\n ?.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_triggerFitContent?.();\n }\n initialPaintFrameRef.current = null;\n });\n const t1 = setTimeout(() => updateHeightRef.current?.(), 100);\n const t2 = setTimeout(() => updateHeightRef.current?.(), 500);\n return () => {\n if (initialPaintFrameRef.current !== null) {\n window.cancelAnimationFrame(initialPaintFrameRef.current);\n initialPaintFrameRef.current = null;\n }\n clearTimeout(t1);\n clearTimeout(t2);\n };\n }, [\n renderHtmlContent,\n locale,\n sandboxDirection,\n sandboxLanguage,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n resetToken,\n disableLoadingOverlay,\n hasRootVhHeight,\n mode,\n shouldStretchRootHeight,\n shouldEnableScaling,\n ]);\n const containerClassName = [\n `w-full relative content-render-iframe-sandbox content-render-iframe-sandbox--${type}`,\n isBlackboardMode\n ? \"h-full overflow-auto flex flex-col\"\n : contentModeStyle\n ? \"overflow-hidden\"\n : \"aspect-[16/9] overflow-hidden flex items-center justify-center\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n return (\n <div\n ref={containerRef}\n dir={direction}\n lang={language}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className={containerClassName}\n style={\n sandboxViewportHeight\n ? {\n height: sandboxViewportHeight,\n minHeight: sandboxViewportHeight,\n }\n : contentModeStyle\n }\n >\n {!hideFullScreen && (\n <button\n ref={fullscreenButtonRef}\n type=\"button\"\n dir={fullscreenControlDirection}\n onClick={toggleFullscreen}\n className={\n \"absolute top-2 end-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer\"\n }\n >\n {isFullscreen\n ? resolvedExitFullScreenButtonText\n : resolvedFullScreenButtonText}\n </button>\n )}\n {mode === \"blackboard\" && type === \"markdown\" ? (\n <div ref={setMarkdownContentContainerRef}>\n <ContentRender\n content={content}\n locale={locale}\n dir={direction}\n lang={language}\n disableSandboxLoadingOverlay={disableLoadingOverlay}\n />\n </div>\n ) : (\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\"\n allow=\"fullscreen\"\n allowFullScreen\n className={[className, \"w-full h-full mx-auto my-auto block\"]\n .filter(Boolean)\n .join(\" \")}\n style={{\n height: sandboxViewportHeight ?? contentIframeHeight ?? \"100%\",\n minHeight: sandboxViewportHeight,\n margin: \"auto\",\n }}\n />\n )}\n </div>\n );\n};\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = (props) => {\n const mode = props.mode ?? \"content\";\n const shouldEnableScaling = Boolean(\n props.enableScaling && mode === \"blackboard\" && props.type === \"sandbox\"\n );\n // The iframe shell captures these initialization-only values. Remounting the\n // inner instance keeps old and new React roots from sharing cleanup refs.\n const lifecycleKey = `${props.type}:${mode}:${shouldEnableScaling ? \"scaled\" : \"unscaled\"}`;\n\n return <IframeSandboxInstance key={lifecycleKey} {...props} />;\n};\n\nexport default IframeSandbox;\n"],"names":["blackboardVendorPromise","loadBlackboardVendor","COMPLETE_IMAGE_TAG_PATTERN","POST_IMAGE_STREAM_DEBOUNCE_MS","SANDBOX_INTERACTION_THROTTLE_MS","replaceRootScreenHeightToken","className","token","segments","replaceRootScreenHeightWithFullClass","html","enabled","match","tagStart","attrs","classMatch","nextClassName","IframeSandboxInstance","content","type","locale","lang","dir","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","exitFullScreenButtonText","hideFullScreen","mode","replaceRootScreenHeightWithFull","enableScaling","disableLoadingOverlay","localeTexts","getContentRenderLocaleTexts","direction","getMarkdownFlowDirection","language","getMarkdownFlowLanguage","resolvedFullScreenButtonText","resolvedExitFullScreenButtonText","containerRef","useRef","fullscreenButtonRef","sandboxLanguage","useDetachedLanguage","resolvedDirection","useResolvedDirection","markdownContainerRef","markdownContentRef","setMarkdownContentContainerRef","useCallback","node","markdownContentDirection","sandboxDirection","requestedDirectionRef","sandboxContentDirection","setSandboxContentDirection","useState","fullscreenControlDirection","iframeRef","rootRef","updateHeightRef","height","setHeight","contentHeight","setContentHeight","containerWidth","setContainerWidth","fullscreenControlHeight","setFullscreenControlHeight","isMeasuringContentRef","pendingHeightUpdateRef","lastSandboxInteractionTimeRef","resetToken","setResetToken","isFullscreen","setIsFullscreen","shouldInjectSandboxVendor","isBlackboardMode","shouldEnableScaling","shouldMeasureDynamicHeight","shouldProcessRootScreenHeight","prevHtmlRef","htmlContent","React","normalizedHtmlContent","originalRootHeightMeta","inspectViewportHeightFromHtmlRootString","EMPTY_ROOT_HEIGHT_META","shouldStretchRootHeight","renderHtmlContent","setRenderHtmlContent","prevIncomingHtmlRef","pendingHtmlRef","deferRenderTimerRef","initialPaintFrameRef","renderViewportHeightCssRef","emitSandboxInteraction","eventType","now","SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","useEffect","container","handleClick","clearDeferredRenderTimer","clearInitialPaintFrames","prevIncomingHtml","isAppendOnlyStream","containsCompleteImage","rootViewportHeightCss","hasRootVhHeight","sandboxViewportHeight","prev","iframe","doc","CJK_SAFE_SANS_FONT_FAMILY","shouldBridgeSandboxInteraction","handleSandboxClick","rootEl","root","createRoot","isDestroyed","getHeightInspectionNode","getSingleChildElement","childElements","resolveExplicitHeight","parentViewportHeight","precomputedViewportHeightCss","parsed","parseExplicitHeight","containerChildren","rootContentElement","runtimeViewportHeightCss","inspectViewportHeightFromNodeChain","runtimeViewportHeight","explicitPixelHeight","resolveExplicitHeightFromNodeChain","updateHeight","contentContainer","normalizeContentViewportMinHeight","cw","prevH","minH","maxH","measuredH","iframeWin","getInnerScrollableHeight","walk","el","style","oy","rect","child","i","nextH","next","scheduleHeightUpdate","bodyScrollH","htmlScrollH","rootScrollH","measuredHeight","explicitHeight","nextHeight","prevHeight","injectBlackboardLibraries","injectScalingSystem","hostElement","needsTailwindRefreshAfterHidden","isTailwindRefreshQueued","tailwindRefreshFrame","tailwindRefreshTimer","runPostTailwindRefreshLayout","isHostVisible","queueTailwindRefreshAfterHidden","refreshTailwindRuntime","sandboxContainer","canObserveResize","hostResizeObserver","entries","contentRect","hostWidth","hostHeight","resizeObserver","syncSandboxContentDirection","wrapper","view","nextDirection","currentDirection","mutationObserver","onFullscreenChange","button","updateControlHeight","ro","hostEntry","entry","contentModeStyle","useMemo","contentIframeHeight","toggleFullscreen","target","jsx","SandboxApp","t1","t2","containerClassName","jsxs","ContentRender","IframeSandbox","props","lifecycleKey"],"mappings":";;;;;;;;;;;;;;AAu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AGiM,EAAA,GAAlBC,CAAyB;AAC9D;"}
1
+ {"version":3,"file":"IframeSandbox.es.js","sources":["../../../src/components/ContentRender/IframeSandbox.tsx"],"sourcesContent":["import React, {\n useCallback,\n useEffect,\n useMemo,\n useRef,\n useState,\n} from \"react\";\nimport { createRoot, Root } from \"react-dom/client\";\nimport SandboxApp from \"./SandboxApp\";\nimport { normalizeContentViewportMinHeight } from \"./utils/content-viewport-min-height\";\nimport ContentRender from \"./ContentRender\";\nimport {\n EMPTY_ROOT_HEIGHT_META,\n inspectViewportHeightFromHtmlRootString,\n inspectViewportHeightFromNodeChain,\n parseExplicitHeight,\n resolveExplicitHeightFromNodeChain,\n} from \"./utils/iframe-viewport-height\";\nimport {\n SANDBOX_INTERACTION_MESSAGE_SOURCE,\n SANDBOX_INTERACTION_MESSAGE_TYPE,\n} from \"../../lib/sandboxInteraction\";\nimport {\n injectScalingSystem,\n type ScalingWindow,\n} from \"./utils/iframe-scaling\";\nimport {\n getMarkdownFlowDirection,\n getMarkdownFlowLanguage,\n type MarkdownFlowLocale,\n} from \"../../lib/locale\";\nimport { useDetachedLanguage } from \"../../lib/useDetachedLanguage\";\nimport { useResolvedDirection } from \"../../lib/useResolvedDirection\";\nimport { getContentRenderLocaleTexts } from \"./contentRenderI18n\";\nimport { CJK_SAFE_SANS_FONT_FAMILY } from \"./cjkFontFamily\";\n\ntype BlackboardVendorModule = typeof import(\"./blackboard-vendor\");\n\n// Cache the sandbox vendor loader so every iframe reuses the same preload request.\nlet blackboardVendorPromise: Promise<BlackboardVendorModule> | null = null;\n\nconst loadBlackboardVendor = () => {\n if (!blackboardVendorPromise) {\n blackboardVendorPromise = import(\"./blackboard-vendor\");\n }\n\n return blackboardVendorPromise;\n};\n\nconst COMPLETE_IMAGE_TAG_PATTERN = /<img\\b[^>]*>/i;\nconst POST_IMAGE_STREAM_DEBOUNCE_MS = 180;\nconst SANDBOX_INTERACTION_THROTTLE_MS = 240;\n\nexport interface IframeSandboxProps {\n content: string;\n className?: string;\n locale?: MarkdownFlowLocale;\n /** Overrides the locale-derived language without changing authored HTML language. */\n lang?: string;\n /** Overrides locale-derived direction without replacing authored HTML direction. */\n dir?: React.HTMLAttributes<HTMLDivElement>[\"dir\"];\n loadingText?: string;\n styleLoadingText?: string;\n scriptLoadingText?: string;\n fullScreenButtonText?: string;\n exitFullScreenButtonText?: string;\n hideFullScreen?: boolean;\n mode?: \"content\" | \"blackboard\";\n type: \"sandbox\" | \"markdown\";\n replaceRootScreenHeightWithFull?: boolean;\n enableScaling?: boolean;\n disableLoadingOverlay?: boolean;\n}\n\nconst replaceRootScreenHeightToken = (className: string) =>\n className\n .split(/\\s+/)\n .filter(Boolean)\n .map((token) => {\n const segments = token.split(\":\");\n if (\n segments[segments.length - 1] !== \"h-screen\" &&\n segments[segments.length - 1] !== \"min-h-screen\"\n ) {\n return token;\n }\n segments[segments.length - 1] = \"h-full\";\n return segments.join(\":\");\n })\n .join(\" \");\n\nconst replaceRootScreenHeightWithFullClass = (\n html: string,\n enabled: boolean\n) => {\n if (!enabled || !html.trim()) {\n return html;\n }\n\n return html.replace(\n /^(\\s*<[a-zA-Z][\\w:-]*)(\\s[^>]*?)?>/,\n (match, tagStart: string, attrs = \"\") => {\n const classMatch = attrs.match(/\\bclass\\s*=\\s*([\"'])([^\"']*)\\1/i);\n\n if (!classMatch) {\n return match;\n }\n\n const nextClassName = replaceRootScreenHeightToken(classMatch[2]);\n\n if (nextClassName === classMatch[2]) {\n return match;\n }\n\n return `${tagStart}${attrs.replace(\n classMatch[0],\n `class=${classMatch[1]}${nextClassName}${classMatch[1]}`\n )}>`;\n }\n );\n};\n\nconst IframeSandboxInstance: React.FC<IframeSandboxProps> = ({\n content,\n type,\n className,\n locale,\n lang,\n dir,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n fullScreenButtonText,\n exitFullScreenButtonText,\n hideFullScreen = false,\n mode = \"content\",\n replaceRootScreenHeightWithFull = false,\n enableScaling = false,\n disableLoadingOverlay = false,\n}) => {\n const localeTexts = getContentRenderLocaleTexts(locale);\n const direction = dir ?? getMarkdownFlowDirection(locale);\n const language = lang ?? getMarkdownFlowLanguage(locale);\n const resolvedFullScreenButtonText =\n fullScreenButtonText || localeTexts.sandboxFullscreenButtonText;\n const resolvedExitFullScreenButtonText =\n exitFullScreenButtonText || localeTexts.sandboxExitFullscreenButtonText;\n const containerRef = useRef<HTMLDivElement>(null);\n const fullscreenButtonRef = useRef<HTMLButtonElement>(null);\n const sandboxLanguage = useDetachedLanguage(containerRef, language);\n const { resolvedDirection } = useResolvedDirection(containerRef, direction);\n const markdownContainerRef = useRef<HTMLDivElement>(null);\n const markdownContentRef = useRef<HTMLElement>(null);\n const setMarkdownContentContainerRef = useCallback(\n (node: HTMLDivElement | null) => {\n markdownContainerRef.current = node;\n markdownContentRef.current =\n node?.querySelector<HTMLElement>(\".content-render\") ?? null;\n },\n []\n );\n const { resolvedDirection: markdownContentDirection } = useResolvedDirection(\n markdownContentRef,\n direction\n );\n const sandboxDirection = direction ?? resolvedDirection;\n const requestedDirectionRef = useRef(direction);\n requestedDirectionRef.current = direction;\n // Auto direction cannot inspect text across the iframe document boundary.\n // Mirror the rendered sandbox direction to host controls instead.\n const [sandboxContentDirection, setSandboxContentDirection] = useState<\n \"ltr\" | \"rtl\"\n >();\n let fullscreenControlDirection: \"ltr\" | \"rtl\" | undefined;\n if (direction === \"auto\") {\n fullscreenControlDirection = resolvedDirection;\n if (type === \"sandbox\") {\n fullscreenControlDirection = sandboxContentDirection ?? resolvedDirection;\n } else if (mode === \"blackboard\") {\n fullscreenControlDirection = markdownContentDirection;\n }\n }\n const iframeRef = useRef<HTMLIFrameElement>(null);\n const rootRef = useRef<Root | null>(null);\n const updateHeightRef = useRef<() => void>(() => {});\n const [height, setHeight] = useState(480);\n const [contentHeight, setContentHeight] = useState<number | null>(null);\n const [containerWidth, setContainerWidth] = useState(0);\n const [fullscreenControlHeight, setFullscreenControlHeight] = useState(0);\n const isMeasuringContentRef = useRef(false);\n const pendingHeightUpdateRef = useRef(false);\n const lastSandboxInteractionTimeRef = useRef(0);\n const [resetToken, setResetToken] = useState(0);\n const [isFullscreen, setIsFullscreen] = useState(false);\n const shouldInjectSandboxVendor = type === \"sandbox\";\n\n const isBlackboardMode = mode === \"blackboard\";\n const shouldEnableScaling =\n enableScaling && isBlackboardMode && type === \"sandbox\";\n const shouldMeasureDynamicHeight = isBlackboardMode && type === \"sandbox\";\n const shouldProcessRootScreenHeight =\n shouldMeasureDynamicHeight && replaceRootScreenHeightWithFull;\n const prevHtmlRef = useRef<string>(\"\");\n const htmlContent = React.useMemo(\n () => (type === \"sandbox\" ? content : \"\"),\n [content, type]\n );\n const normalizedHtmlContent = React.useMemo(\n () =>\n replaceRootScreenHeightWithFullClass(\n htmlContent,\n shouldProcessRootScreenHeight\n ),\n [htmlContent, shouldProcessRootScreenHeight]\n );\n const originalRootHeightMeta = React.useMemo(\n () =>\n shouldProcessRootScreenHeight\n ? inspectViewportHeightFromHtmlRootString(htmlContent)\n : EMPTY_ROOT_HEIGHT_META,\n [htmlContent, shouldProcessRootScreenHeight]\n );\n const shouldStretchRootHeight = React.useMemo(\n () =>\n shouldProcessRootScreenHeight &&\n originalRootHeightMeta.hasFullViewportHeight,\n [\n originalRootHeightMeta.hasFullViewportHeight,\n shouldProcessRootScreenHeight,\n ]\n );\n const [renderHtmlContent, setRenderHtmlContent] = useState(\n normalizedHtmlContent\n );\n const prevIncomingHtmlRef = useRef(normalizedHtmlContent);\n const pendingHtmlRef = useRef(normalizedHtmlContent);\n const deferRenderTimerRef = useRef<number | null>(null);\n const initialPaintFrameRef = useRef<number | null>(null);\n const renderViewportHeightCssRef = useRef<string | null>(null);\n\n const emitSandboxInteraction = useCallback((eventType: string) => {\n if (typeof window === \"undefined\") {\n return;\n }\n const now = Date.now();\n if (\n now - lastSandboxInteractionTimeRef.current <\n SANDBOX_INTERACTION_THROTTLE_MS\n ) {\n return;\n }\n lastSandboxInteractionTimeRef.current = now;\n window.postMessage(\n {\n source: SANDBOX_INTERACTION_MESSAGE_SOURCE,\n type: SANDBOX_INTERACTION_MESSAGE_TYPE,\n eventType,\n },\n window.location.origin\n );\n }, []);\n\n useEffect(() => {\n if (type !== \"markdown\" || mode !== \"blackboard\") return;\n const container = markdownContainerRef.current;\n if (!container) return;\n const handleClick = () => emitSandboxInteraction(\"click\");\n container.addEventListener(\"click\", handleClick);\n return () => container.removeEventListener(\"click\", handleClick);\n }, [emitSandboxInteraction, mode, type]);\n\n const clearDeferredRenderTimer = () => {\n if (deferRenderTimerRef.current === null) return;\n window.clearTimeout(deferRenderTimerRef.current);\n deferRenderTimerRef.current = null;\n };\n\n const clearInitialPaintFrames = () => {\n if (initialPaintFrameRef.current !== null) {\n window.cancelAnimationFrame(initialPaintFrameRef.current);\n initialPaintFrameRef.current = null;\n }\n };\n\n useEffect(\n () => () => {\n clearDeferredRenderTimer();\n clearInitialPaintFrames();\n },\n []\n );\n\n useEffect(() => {\n const prevIncomingHtml = prevIncomingHtmlRef.current;\n prevIncomingHtmlRef.current = normalizedHtmlContent;\n\n const isAppendOnlyStream =\n !!prevIncomingHtml &&\n normalizedHtmlContent.length > prevIncomingHtml.length &&\n normalizedHtmlContent.startsWith(prevIncomingHtml);\n const containsCompleteImage = COMPLETE_IMAGE_TAG_PATTERN.test(\n normalizedHtmlContent\n );\n const shouldDeferRender = isAppendOnlyStream && containsCompleteImage;\n\n if (!shouldDeferRender) {\n clearDeferredRenderTimer();\n pendingHtmlRef.current = normalizedHtmlContent;\n setRenderHtmlContent(normalizedHtmlContent);\n return;\n }\n\n pendingHtmlRef.current = normalizedHtmlContent;\n clearDeferredRenderTimer();\n deferRenderTimerRef.current = window.setTimeout(() => {\n setRenderHtmlContent(pendingHtmlRef.current);\n deferRenderTimerRef.current = null;\n }, POST_IMAGE_STREAM_DEBOUNCE_MS);\n }, [normalizedHtmlContent]);\n\n const rootViewportHeightCss = React.useMemo(() => {\n if (!shouldMeasureDynamicHeight) {\n return null;\n }\n\n return inspectViewportHeightFromHtmlRootString(renderHtmlContent)\n .viewportHeightCss;\n }, [renderHtmlContent, shouldMeasureDynamicHeight]);\n\n useEffect(() => {\n renderViewportHeightCssRef.current = rootViewportHeightCss;\n }, [rootViewportHeightCss]);\n\n const hasRootVhHeight = Boolean(rootViewportHeightCss);\n const sandboxViewportHeight =\n isBlackboardMode && type === \"sandbox\"\n ? shouldEnableScaling\n ? \"100%\"\n : shouldStretchRootHeight\n ? \"100%\"\n : (rootViewportHeightCss ?? `${height}px`)\n : undefined;\n useEffect(() => {\n if (mode !== \"blackboard\") {\n prevHtmlRef.current = normalizedHtmlContent;\n return;\n }\n const prev = prevHtmlRef.current;\n const isContinuation = prev && normalizedHtmlContent.startsWith(prev);\n if (!isContinuation && prev) {\n setResetToken((token) => token + 1);\n }\n prevHtmlRef.current = normalizedHtmlContent;\n }, [mode, normalizedHtmlContent]);\n\n useEffect(() => {\n const iframe = iframeRef.current;\n if (!iframe) return undefined;\n\n const doc = iframe.contentDocument;\n if (!doc) return undefined;\n\n doc.open();\n doc.write(`<!DOCTYPE html>\n<html${mode === \"blackboard\" ? ' style=\"height: 100%;\"' : \"\"}>\n <head>\n <meta charset=\"utf-8\" />\n <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\" />\n <style>\n :root { color-scheme: light; }\n html, body, #root { width: 100%; font-family: ${CJK_SAFE_SANS_FONT_FAMILY}; }\n ${mode === \"blackboard\" ? \"html, body, #root { height: 100%; }\" : \"\"}\n html, body { margin: 0; padding: 0; overflow: ${shouldEnableScaling ? \"hidden auto\" : mode === \"blackboard\" ? \"auto\" : \"hidden\"}; }\n *, *::before, *::after { box-sizing: border-box; }\n ${\n mode !== \"blackboard\"\n ? `\n .h-screen { height: auto !important; }\n .min-h-screen { min-height: auto !important; }\n .h-dvh, .h-svh, .h-lvh { height: auto !important; }\n .min-h-dvh, .min-h-svh, .min-h-lvh { min-height: auto !important; }\n `\n : \"\"\n }\n </style>\n </head>\n <body>\n <div id=\"root\"></div>\n </body>\n</html>`);\n doc.close();\n\n // Force iframe theme to stay in light mode regardless of host OS preference.\n doc.documentElement.setAttribute(\"data-theme\", \"light\");\n doc.documentElement.style.colorScheme = \"light\";\n doc.body?.style.setProperty(\"color-scheme\", \"light\");\n\n const shouldBridgeSandboxInteraction =\n isBlackboardMode && type === \"sandbox\";\n const handleSandboxClick = () => emitSandboxInteraction(\"click\");\n\n if (shouldBridgeSandboxInteraction) {\n doc.addEventListener(\"click\", handleSandboxClick, true);\n }\n\n const rootEl = doc.getElementById(\"root\");\n if (!rootEl) return undefined;\n\n const root = createRoot(rootEl);\n rootRef.current = root;\n let isDestroyed = false;\n const getHeightInspectionNode = (node: HTMLElement) => ({\n heightAttrValue: node.getAttribute(\"height\"),\n styleAttrValue: node.getAttribute(\"style\"),\n classAttrValue: node.getAttribute(\"class\"),\n });\n const getSingleChildElement = (node: HTMLElement) => {\n const childElements = Array.from(node.children) as HTMLElement[];\n\n return childElements.length === 1 ? childElements[0] : null;\n };\n\n const resolveExplicitHeight = () => {\n if (!shouldMeasureDynamicHeight) return null;\n if (!iframeRef.current || !doc.body) return null;\n const parentViewportHeight =\n iframeRef.current.ownerDocument?.documentElement?.clientHeight ||\n window.innerHeight;\n // Reuse parsed height metadata from the current html snapshot first to\n // avoid re-inspecting the same DOM chain on every height tick.\n const precomputedViewportHeightCss = renderViewportHeightCssRef.current;\n const parsed = precomputedViewportHeightCss\n ? parseExplicitHeight(\n precomputedViewportHeightCss,\n parentViewportHeight\n )\n : null;\n\n if (parsed !== null) {\n return Math.ceil(parsed);\n }\n\n const wrapper = doc.body.querySelector(\n \".sandbox-wrapper\"\n ) as HTMLElement | null;\n const container = wrapper?.firstElementChild as HTMLElement | null;\n if (!container) return null;\n const containerChildren = Array.from(container.children) as HTMLElement[];\n const rootContentElement =\n containerChildren.length === 1 ? containerChildren[0] : null;\n const runtimeHeightMeta = inspectViewportHeightFromNodeChain(\n rootContentElement,\n {\n getNode: getHeightInspectionNode,\n getSingleChild: getSingleChildElement,\n }\n );\n const runtimeViewportHeightCss = runtimeHeightMeta.viewportHeightCss;\n\n if (runtimeViewportHeightCss) {\n const runtimeViewportHeight = parseExplicitHeight(\n runtimeViewportHeightCss,\n parentViewportHeight\n );\n\n if (runtimeViewportHeight !== null) {\n return Math.ceil(runtimeViewportHeight);\n }\n }\n\n const explicitPixelHeight = resolveExplicitHeightFromNodeChain(\n rootContentElement,\n parentViewportHeight,\n {\n getNode: getHeightInspectionNode,\n getSingleChild: getSingleChildElement,\n }\n );\n\n return explicitPixelHeight !== null\n ? Math.ceil(explicitPixelHeight)\n : null;\n };\n\n const updateHeight = () => {\n if (!iframeRef.current || !doc.body) return;\n\n if (!isBlackboardMode) {\n // Guard: prevent re-entrant measurement from ResizeObserver /\n // MutationObserver callbacks triggered by our own height changes.\n if (isMeasuringContentRef.current) {\n // Mark that an update was requested while the guard was active.\n // We will retry once the guard releases (see setTimeout below).\n pendingHeightUpdateRef.current = true;\n return;\n }\n isMeasuringContentRef.current = true;\n const contentContainer =\n doc.body.querySelector<HTMLElement>(\".sandbox-container\");\n if (contentContainer)\n normalizeContentViewportMinHeight(contentContainer);\n\n // Content mode height measurement strategy:\n // Temporarily set iframe height to the 16:9 layout viewport so that:\n // 1. vmin units are stable: vmin = min(cw, minH)/100 = minH/100,\n // consistent with the final rendered 16:9 iframe.\n // 2. Viewport-filling content (e.g. inline style=\"height:100vh\")\n // retains its 16:9 viewport. Naturally sized content reserves only\n // its measured body height in the host page.\n // (Previously using cw caused such content to report 1:1 height,\n // overriding the 16:9 minimum.)\n const iframe = iframeRef.current;\n const cw = containerRef.current?.clientWidth || 0;\n const prevH = iframe.style.height;\n\n if (cw > 0) {\n const minH = Math.round((cw * 9) / 16);\n // Absolute height cap. Diverging vh-feedback (multiple `height:100vh`\n // siblings, or compound vh-relative children whose sum exceeds the\n // viewport) can otherwise grow the iframe geometrically across\n // repeated ResizeObserver/MutationObserver passes. 1:20 aspect is\n // a generous upper bound for any single sandbox slide.\n const maxH = Math.max(8192, cw * 20);\n iframe.style.height = minH + \"px\";\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n doc.body.offsetHeight; // force layout\n\n let measuredH = doc.body.scrollHeight;\n\n // Detect inner elements that clip overflowing content behind a\n // scrollbar (e.g. <div style=\"height:100vh; overflow-y:auto\"> whose\n // content is taller than the iframe). body.scrollHeight won't see\n // that overflow, so we walk the tree and factor in each scrollable\n // element's full scroll height based on its position in the iframe.\n const iframeWin = doc.defaultView;\n if (iframeWin) {\n // Include fixed-position widgets, which do not contribute to body\n // scrollHeight, as well as content behind internal scrollbars.\n const getInnerScrollableHeight = (root: Element): number => {\n let maxH = 0;\n const walk = (el: Element) => {\n const style = iframeWin.getComputedStyle(el);\n if (style.position === \"fixed\") {\n maxH = Math.max(\n maxH,\n Math.ceil(el.getBoundingClientRect().bottom)\n );\n }\n if (el !== root && el.scrollHeight > el.clientHeight + 1) {\n const oy = style.overflowY;\n if (oy === \"auto\" || oy === \"scroll\") {\n const rect = el.getBoundingClientRect();\n if (rect.top >= 0) {\n maxH = Math.max(\n maxH,\n Math.ceil(rect.top + el.scrollHeight)\n );\n }\n }\n }\n for (const child of el.children) walk(child);\n };\n walk(root);\n return maxH;\n };\n\n measuredH = Math.max(measuredH, getInnerScrollableHeight(doc.body));\n\n // Content that uses vh-relative sizing grows as the viewport\n // expands. Measure up to 8 more times at the expanded height so\n // we capture the full content height in a single updateHeight()\n // call rather than waiting for external re-triggers.\n for (let i = 0; i < 8 && measuredH > minH; i++) {\n iframe.style.height = measuredH + \"px\";\n // eslint-disable-next-line @typescript-eslint/no-unused-expressions\n doc.body.offsetHeight; // force layout at expanded size\n const nextH = Math.max(\n doc.body.scrollHeight,\n getInnerScrollableHeight(doc.body)\n );\n if (nextH <= measuredH + 1) break; // stable — stop iterating\n // Geometric vh-feedback detection: vh-relative children scale\n // with the iframe viewport, so growing the iframe makes them\n // larger which grows scrollHeight — runaway divergence. Two\n // `height:100vh` siblings produce a 2× per-iteration multiplier.\n // Stop iterating; keep the prior (stable) measuredH.\n if (nextH >= measuredH * 1.5) break;\n measuredH = nextH;\n }\n }\n\n // Restore iframe to let React control it via contentModeStyle\n iframe.style.height = prevH;\n\n setContentHeight((prev) => {\n const next = Math.min(maxH, Math.max(1, Math.ceil(measuredH)));\n return prev === next ? prev : next;\n });\n }\n\n setTimeout(() => {\n isMeasuringContentRef.current = false;\n // Retry any update that was blocked while the guard was active\n // (e.g. dynamic content injected by scripts or images loading).\n if (pendingHeightUpdateRef.current) {\n pendingHeightUpdateRef.current = false;\n scheduleHeightUpdate();\n }\n }, 50);\n return;\n }\n\n // Scaling mode: viewport is fixed, content scales via font-size.\n if (shouldEnableScaling) return;\n\n // Blackboard mode: use existing measurement logic\n const bodyScrollH = doc.body.scrollHeight;\n const htmlScrollH = doc.documentElement?.scrollHeight || 0;\n const rootScrollH = rootEl?.scrollHeight || 0;\n const measuredHeight = Math.max(bodyScrollH, htmlScrollH, rootScrollH);\n\n if (shouldMeasureDynamicHeight) {\n const explicitHeight = resolveExplicitHeight();\n const nextHeight = Math.max(\n 200,\n explicitHeight ?? Math.ceil(measuredHeight)\n );\n setHeight((prevHeight) =>\n prevHeight === nextHeight ? prevHeight : nextHeight\n );\n }\n };\n const scheduleHeightUpdate = () => {\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n updateHeight();\n });\n };\n updateHeightRef.current = scheduleHeightUpdate;\n\n updateHeight();\n scheduleHeightUpdate();\n\n if (shouldInjectSandboxVendor) {\n // Inject Tailwind/DaisyUI/GSAP before rendering sandbox content to avoid FOUC.\n loadBlackboardVendor()\n .then(({ injectBlackboardLibraries }) => {\n if (isDestroyed) return;\n injectBlackboardLibraries(doc);\n if (shouldEnableScaling) {\n injectScalingSystem(doc);\n }\n requestAnimationFrame(() => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n });\n })\n .catch(() => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n });\n }\n\n const hostElement = containerRef.current;\n let needsTailwindRefreshAfterHidden = Boolean(\n hostElement &&\n (hostElement.clientWidth <= 0 || hostElement.clientHeight <= 0)\n );\n let isTailwindRefreshQueued = false;\n let tailwindRefreshFrame: number | null = null;\n let tailwindRefreshTimer: number | null = null;\n const runPostTailwindRefreshLayout = () => {\n if (isDestroyed) return;\n scheduleHeightUpdate();\n const iframeWin = iframe.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_triggerFitContent?.();\n };\n const isHostVisible = () =>\n Boolean(\n hostElement &&\n hostElement.clientWidth > 0 &&\n hostElement.clientHeight > 0\n );\n const queueTailwindRefreshAfterHidden = () => {\n if (\n !shouldInjectSandboxVendor ||\n !hostElement ||\n !needsTailwindRefreshAfterHidden ||\n isTailwindRefreshQueued ||\n !isHostVisible()\n ) {\n return;\n }\n\n isTailwindRefreshQueued = true;\n loadBlackboardVendor()\n .then(({ refreshTailwindRuntime }) => {\n if (isDestroyed) return;\n\n tailwindRefreshFrame = window.requestAnimationFrame(() => {\n tailwindRefreshFrame = null;\n isTailwindRefreshQueued = false;\n\n const sandboxContainer = doc.querySelector(\".sandbox-container\");\n if (\n isDestroyed ||\n !isHostVisible() ||\n !sandboxContainer?.childNodes.length ||\n !refreshTailwindRuntime(doc)\n ) {\n return;\n }\n\n needsTailwindRefreshAfterHidden = false;\n runPostTailwindRefreshLayout();\n tailwindRefreshTimer = window.setTimeout(() => {\n tailwindRefreshTimer = null;\n runPostTailwindRefreshLayout();\n }, 100);\n });\n })\n .catch(() => {\n isTailwindRefreshQueued = false;\n });\n };\n const canObserveResize = typeof ResizeObserver !== \"undefined\";\n const hostResizeObserver =\n shouldInjectSandboxVendor && hostElement && canObserveResize\n ? new ResizeObserver((entries) => {\n const contentRect = entries[0]?.contentRect;\n const hostWidth = contentRect?.width ?? hostElement.clientWidth;\n const hostHeight = contentRect?.height ?? hostElement.clientHeight;\n const isHostSizeVisible = hostWidth > 0 && hostHeight > 0;\n\n if (!isHostSizeVisible) {\n return;\n }\n\n queueTailwindRefreshAfterHidden();\n })\n : null;\n if (hostResizeObserver && hostElement) {\n hostResizeObserver.observe(hostElement);\n }\n\n const resizeObserver = canObserveResize\n ? new ResizeObserver(() => updateHeight())\n : null;\n resizeObserver?.observe(doc.body);\n if (rootEl) {\n resizeObserver?.observe(rootEl);\n }\n\n const syncSandboxContentDirection = () => {\n if (type !== \"sandbox\" || requestedDirectionRef.current !== \"auto\") {\n return;\n }\n const wrapper = doc.querySelector<HTMLElement>(\".sandbox-wrapper\");\n const view = doc.defaultView;\n if (!wrapper || !view) return;\n const nextDirection =\n view.getComputedStyle(wrapper).direction === \"rtl\" ? \"rtl\" : \"ltr\";\n setSandboxContentDirection((currentDirection) =>\n currentDirection === nextDirection ? currentDirection : nextDirection\n );\n };\n\n // MutationObserver: detect DOM changes that ResizeObserver might miss\n // (e.g. content injected by scripts, images loading, dynamic rendering)\n const mutationObserver = new MutationObserver(() => {\n syncSandboxContentDirection();\n scheduleHeightUpdate();\n if (!isHostVisible()) {\n needsTailwindRefreshAfterHidden = true;\n return;\n }\n queueTailwindRefreshAfterHidden();\n });\n mutationObserver.observe(doc.body, {\n childList: true,\n characterData: true,\n subtree: true,\n attributes: true,\n attributeFilter: [\"style\", \"class\", \"dir\"],\n });\n\n return () => {\n isDestroyed = true;\n hostResizeObserver?.disconnect();\n resizeObserver?.disconnect();\n mutationObserver.disconnect();\n if (tailwindRefreshFrame !== null) {\n window.cancelAnimationFrame(tailwindRefreshFrame);\n }\n if (tailwindRefreshTimer !== null) {\n window.clearTimeout(tailwindRefreshTimer);\n }\n if (shouldEnableScaling) {\n const iframeWin = iframe.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_cleanupScaling?.();\n }\n if (shouldBridgeSandboxInteraction) {\n doc.removeEventListener(\"click\", handleSandboxClick, true);\n }\n if (rootRef.current === root) {\n rootRef.current = null;\n updateHeightRef.current = () => {};\n }\n // Defer unmount to avoid React warning when parent is mid-render\n setTimeout(() => {\n root.unmount();\n }, 0);\n };\n }, []);\n\n useEffect(() => {\n const onFullscreenChange = () => {\n setIsFullscreen(Boolean(document.fullscreenElement));\n };\n document.addEventListener(\"fullscreenchange\", onFullscreenChange);\n return () =>\n document.removeEventListener(\"fullscreenchange\", onFullscreenChange);\n }, []);\n\n // Track the layout viewport width and enough host space for its own control.\n useEffect(() => {\n const el = containerRef.current;\n if (!el) return;\n const button = fullscreenButtonRef.current;\n const updateControlHeight = () => {\n setFullscreenControlHeight(\n button ? Math.ceil(button.offsetTop + button.offsetHeight) : 0\n );\n };\n if (typeof ResizeObserver === \"undefined\") {\n setContainerWidth(el.clientWidth);\n updateControlHeight();\n return;\n }\n const ro = new ResizeObserver((entries) => {\n const hostEntry = entries.find((entry) => entry.target === el);\n if (hostEntry) setContainerWidth(hostEntry.contentRect.width);\n updateControlHeight();\n });\n ro.observe(el);\n if (button) ro.observe(button);\n setContainerWidth(el.clientWidth);\n updateControlHeight();\n return () => ro.disconnect();\n }, [hideFullScreen]);\n\n // Keep a stable layout viewport for authored vh/vmin sizing, while the host\n // reserves only the measured content height. The iframe is top-aligned inside\n // the clipped host so a short card does not leave a slide-sized blank area.\n const contentModeStyle = useMemo<React.CSSProperties | undefined>(() => {\n if (isBlackboardMode || containerWidth === 0 || isFullscreen)\n return undefined;\n const minH = Math.round((containerWidth * 9) / 16);\n return { height: Math.max(contentHeight ?? minH, fullscreenControlHeight) };\n }, [\n isBlackboardMode,\n containerWidth,\n contentHeight,\n isFullscreen,\n fullscreenControlHeight,\n ]);\n\n const contentIframeHeight = contentModeStyle\n ? Math.max(Math.round((containerWidth * 9) / 16), contentHeight ?? 0)\n : undefined;\n\n const toggleFullscreen = () => {\n const target = containerRef.current || iframeRef.current;\n if (!target) return;\n if (document.fullscreenElement) {\n document.exitFullscreen().catch(() => {});\n return;\n }\n if (target.requestFullscreen) {\n target.requestFullscreen().catch(() => {});\n }\n };\n\n useEffect(() => {\n const root = rootRef.current;\n if (!root) return;\n\n root.render(\n <SandboxApp\n html={renderHtmlContent}\n locale={locale}\n dir={sandboxDirection}\n lang={sandboxLanguage}\n loadingText={loadingText}\n styleLoadingText={styleLoadingText}\n scriptLoadingText={scriptLoadingText}\n disableLoadingOverlay={disableLoadingOverlay}\n resetToken={resetToken}\n hasRootVhHeight={hasRootVhHeight}\n mode={mode}\n stretchRootHeight={shouldStretchRootHeight}\n enableScaling={shouldEnableScaling}\n />\n );\n\n // Schedule multiple measurements to catch async content (scripts, images, styles).\n initialPaintFrameRef.current = window.requestAnimationFrame(() => {\n updateHeightRef.current?.();\n if (shouldEnableScaling) {\n const iframeWin = iframeRef.current\n ?.contentWindow as ScalingWindow | null;\n iframeWin?.__mdf_triggerFitContent?.();\n }\n initialPaintFrameRef.current = null;\n });\n const t1 = setTimeout(() => updateHeightRef.current?.(), 100);\n const t2 = setTimeout(() => updateHeightRef.current?.(), 500);\n return () => {\n if (initialPaintFrameRef.current !== null) {\n window.cancelAnimationFrame(initialPaintFrameRef.current);\n initialPaintFrameRef.current = null;\n }\n clearTimeout(t1);\n clearTimeout(t2);\n };\n }, [\n renderHtmlContent,\n locale,\n sandboxDirection,\n sandboxLanguage,\n loadingText,\n styleLoadingText,\n scriptLoadingText,\n resetToken,\n disableLoadingOverlay,\n hasRootVhHeight,\n mode,\n shouldStretchRootHeight,\n shouldEnableScaling,\n ]);\n const containerClassName = [\n `w-full relative content-render-iframe-sandbox content-render-iframe-sandbox--${type}`,\n isBlackboardMode\n ? \"h-full overflow-auto flex flex-col\"\n : contentModeStyle\n ? \"overflow-hidden\"\n : \"aspect-[16/9] overflow-hidden flex items-center justify-center\",\n ]\n .filter(Boolean)\n .join(\" \");\n\n return (\n <div\n ref={containerRef}\n dir={direction}\n lang={language}\n data-root-vh={hasRootVhHeight ? \"true\" : \"false\"}\n className={containerClassName}\n style={\n sandboxViewportHeight\n ? {\n height: sandboxViewportHeight,\n minHeight: sandboxViewportHeight,\n }\n : contentModeStyle\n }\n >\n {!hideFullScreen && (\n <button\n ref={fullscreenButtonRef}\n type=\"button\"\n dir={fullscreenControlDirection}\n onClick={toggleFullscreen}\n className={\n \"absolute top-2 end-2 z-50 p-1.5 bg-black/75 text-white rounded-md cursor-pointer\"\n }\n >\n {isFullscreen\n ? resolvedExitFullScreenButtonText\n : resolvedFullScreenButtonText}\n </button>\n )}\n {mode === \"blackboard\" && type === \"markdown\" ? (\n <div ref={setMarkdownContentContainerRef}>\n <ContentRender\n content={content}\n locale={locale}\n dir={direction}\n lang={language}\n disableSandboxLoadingOverlay={disableLoadingOverlay}\n />\n </div>\n ) : (\n <iframe\n ref={iframeRef}\n sandbox=\"allow-scripts allow-same-origin allow-popups allow-popups-to-escape-sandbox\"\n allow=\"fullscreen\"\n allowFullScreen\n className={[className, \"w-full h-full mx-auto my-auto block\"]\n .filter(Boolean)\n .join(\" \")}\n style={{\n height: sandboxViewportHeight ?? contentIframeHeight ?? \"100%\",\n minHeight: sandboxViewportHeight,\n margin: \"auto\",\n }}\n />\n )}\n </div>\n );\n};\n\nconst IframeSandbox: React.FC<IframeSandboxProps> = (props) => {\n const mode = props.mode ?? \"content\";\n const shouldEnableScaling = Boolean(\n props.enableScaling && mode === \"blackboard\" && props.type === \"sandbox\"\n );\n // The iframe shell captures these initialization-only values. Remounting the\n // inner instance keeps old and new React roots from sharing cleanup refs.\n const lifecycleKey = `${props.type}:${mode}:${shouldEnableScaling ? \"scaled\" : \"unscaled\"}`;\n\n return <IframeSandboxInstance key={lifecycleKey} {...props} />;\n};\n\nexport default IframeSandbox;\n"],"names":["blackboardVendorPromise","loadBlackboardVendor","COMPLETE_IMAGE_TAG_PATTERN","POST_IMAGE_STREAM_DEBOUNCE_MS","SANDBOX_INTERACTION_THROTTLE_MS","replaceRootScreenHeightToken","className","token","segments","replaceRootScreenHeightWithFullClass","html","enabled","match","tagStart","attrs","classMatch","nextClassName","IframeSandboxInstance","content","type","locale","lang","dir","loadingText","styleLoadingText","scriptLoadingText","fullScreenButtonText","exitFullScreenButtonText","hideFullScreen","mode","replaceRootScreenHeightWithFull","enableScaling","disableLoadingOverlay","localeTexts","getContentRenderLocaleTexts","direction","getMarkdownFlowDirection","language","getMarkdownFlowLanguage","resolvedFullScreenButtonText","resolvedExitFullScreenButtonText","containerRef","useRef","fullscreenButtonRef","sandboxLanguage","useDetachedLanguage","resolvedDirection","useResolvedDirection","markdownContainerRef","markdownContentRef","setMarkdownContentContainerRef","useCallback","node","markdownContentDirection","sandboxDirection","requestedDirectionRef","sandboxContentDirection","setSandboxContentDirection","useState","fullscreenControlDirection","iframeRef","rootRef","updateHeightRef","height","setHeight","contentHeight","setContentHeight","containerWidth","setContainerWidth","fullscreenControlHeight","setFullscreenControlHeight","isMeasuringContentRef","pendingHeightUpdateRef","lastSandboxInteractionTimeRef","resetToken","setResetToken","isFullscreen","setIsFullscreen","shouldInjectSandboxVendor","isBlackboardMode","shouldEnableScaling","shouldMeasureDynamicHeight","shouldProcessRootScreenHeight","prevHtmlRef","htmlContent","React","normalizedHtmlContent","originalRootHeightMeta","inspectViewportHeightFromHtmlRootString","EMPTY_ROOT_HEIGHT_META","shouldStretchRootHeight","renderHtmlContent","setRenderHtmlContent","prevIncomingHtmlRef","pendingHtmlRef","deferRenderTimerRef","initialPaintFrameRef","renderViewportHeightCssRef","emitSandboxInteraction","eventType","now","SANDBOX_INTERACTION_MESSAGE_SOURCE","SANDBOX_INTERACTION_MESSAGE_TYPE","useEffect","container","handleClick","clearDeferredRenderTimer","clearInitialPaintFrames","prevIncomingHtml","isAppendOnlyStream","containsCompleteImage","rootViewportHeightCss","hasRootVhHeight","sandboxViewportHeight","prev","iframe","doc","CJK_SAFE_SANS_FONT_FAMILY","shouldBridgeSandboxInteraction","handleSandboxClick","rootEl","root","createRoot","isDestroyed","getHeightInspectionNode","getSingleChildElement","childElements","resolveExplicitHeight","parentViewportHeight","precomputedViewportHeightCss","parsed","parseExplicitHeight","containerChildren","rootContentElement","runtimeViewportHeightCss","inspectViewportHeightFromNodeChain","runtimeViewportHeight","explicitPixelHeight","resolveExplicitHeightFromNodeChain","updateHeight","contentContainer","normalizeContentViewportMinHeight","cw","prevH","minH","maxH","measuredH","iframeWin","getInnerScrollableHeight","walk","el","style","oy","rect","child","i","nextH","next","scheduleHeightUpdate","bodyScrollH","htmlScrollH","rootScrollH","measuredHeight","explicitHeight","nextHeight","prevHeight","injectBlackboardLibraries","injectScalingSystem","hostElement","needsTailwindRefreshAfterHidden","isTailwindRefreshQueued","tailwindRefreshFrame","tailwindRefreshTimer","runPostTailwindRefreshLayout","isHostVisible","queueTailwindRefreshAfterHidden","refreshTailwindRuntime","sandboxContainer","canObserveResize","hostResizeObserver","entries","contentRect","hostWidth","hostHeight","resizeObserver","syncSandboxContentDirection","wrapper","view","nextDirection","currentDirection","mutationObserver","onFullscreenChange","button","updateControlHeight","ro","hostEntry","entry","contentModeStyle","useMemo","contentIframeHeight","toggleFullscreen","target","jsx","SandboxApp","t1","t2","containerClassName","jsxs","ContentRender","IframeSandbox","props","lifecycleKey"],"mappings":";;;;;;;;;;;;;;AAuCA,IAAIA,KAAkE;AAEtE,MAAMC,KAAuB,OACtBD,OACHA,KAA0B,OAAO,2BAAqB,IAGjDA,KAGHE,KAA6B,iBAC7BC,KAAgC,KAChCC,KAAkC,KAuBlCC,KAA+B,CAACC,MACpCA,EACG,MAAM,KAAK,EACX,OAAO,OAAO,EACd,IAAI,CAACC,MAAU;AACd,QAAMC,IAAWD,EAAM,MAAM,GAAG;AAChC,SACEC,EAASA,EAAS,SAAS,CAAC,MAAM,cAClCA,EAASA,EAAS,SAAS,CAAC,MAAM,iBAE3BD,KAETC,EAASA,EAAS,SAAS,CAAC,IAAI,UACzBA,EAAS,KAAK,GAAG;AAC1B,CAAC,EACA,KAAK,GAAG,GAEPC,KAAuC,CAC3CC,GACAC,MAEI,CAACA,KAAW,CAACD,EAAK,SACbA,IAGFA,EAAK;AAAA,EACV;AAAA,EACA,CAACE,GAAOC,GAAkBC,IAAQ,OAAO;AACvC,UAAMC,IAAaD,EAAM,MAAM,iCAAiC;AAEhE,QAAI,CAACC;AAC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AAA0K;AAAA,UAAC;AAAA,UAAA;AAAA,YACC,KAAK9I;AAAA,YACL,SAAQ;AAAA,YACR,OAAM;AAAA,YACN,iBAAe;AAAA,YACf,WAAW,CAACtD,GAAW,qCAAqC,EACzD,OAAO,OAAO,EACd,KAAK,GAAG;AAAA,YACX,OAAO;AAAA,cACL,QAAQ2G,KAAyBsF,MAAuB;AAAA,cACxD,WAAWtF;AAAA,cACX,QAAQ;AAAA,YAAA;AAAA,UACV;AAAA,QAAA;AAAA,MACF;AAAA,IAAA;AAAA,EAAA;AAIR,GAEMgG,KAA8C,CAACC,MAAU;AAC7D,QAAMrL,IAAOqL,EAAM,QAAQ,WACrBlI,IAAsB,GAC1BkI,EAAM,iBAAiBrL,MAAS,gBAAgBqL,EAAM,SAAS,YAI3DC,IAAe,GAAGD,EAAM,IAAI,IAAIrL,CAAI,IAAImD,IAAsB,WAAW,UAAU;AAEzF,SAAO,gBAAA0H,EAACzL,IAAA,EAA0C,GAAGiM,EAAA,GAAlBC,CAAyB;AAC9D;"}
@@ -1 +1 @@
1
- {"version":3,"file":"video-markdown-run.cjs","sources":["../../../../src/components/ContentRender/utils/video-markdown-run.ts"],"sourcesContent":["import type { Element, Nodes, Root } from \"hast\";\nimport type { Root as MarkdownRoot } from \"mdast\";\nimport { decodeString } from \"micromark-util-decode-string\";\nimport {\n getMarkdownSourceAnalysis,\n type MarkdownSourceAnalysis,\n type MarkdownSourceTree,\n} from \"./inline-code-ranges\";\nimport type { RenderSegment } from \"./split-content\";\nimport { normalizeInlineHtml } from \"./normalize-inline-html\";\nimport {\n readHtmlMarkup,\n isHtmlRawTextTag,\n findStreamingHtmlElementEnd,\n} from \"./html-block-end\";\n\ntype Range = { start: number; end: number };\ntype SourceValue = Range & { value: string; type: string };\ntype Visibility = {\n ends?: number[];\n range?: Range;\n atomic?: boolean;\n structural?: boolean;\n svg?: boolean;\n active?: boolean;\n immediate?: boolean;\n svgSource?: string;\n};\nexport type VideoMarkdownRunPlan = {\n fullSource: string;\n markdownSource: string;\n /** Raw end offset for each normalized UTF-16 unit, only when source changed. */\n rawEnds?: readonly number[];\n segments: readonly RenderSegment[];\n offsets: readonly number[];\n immediateOffsets: readonly number[];\n sourceTree: MarkdownSourceTree;\n incompleteSvg?: Range;\n pendingMetadata: readonly Range[];\n tree?: Root;\n visibility: WeakMap<Nodes, Visibility>;\n};\ndeclare module \"hast\" {\n interface ElementData {\n contentRenderVisibility?: Visibility;\n }\n}\nconst stateKey = \"contentRenderVisibility\";\nconst firstAtOrAfter = (values: readonly number[], target: number) => {\n let low = 0;\n let high = values.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n if (values[middle] < target) low = middle + 1;\n else high = middle;\n }\n return low;\n};\nconst segmentAt = (plan: VideoMarkdownRunPlan, position: number) =>\n Math.max(0, firstAtOrAfter(plan.offsets, position + 1) - 1);\nconst rangeOf = (node: { position?: Nodes[\"position\"] }): Range | undefined => {\n const start = node.position?.start?.offset;\n const end = node.position?.end?.offset;\n return start === undefined || end === undefined ? undefined : { start, end };\n};\nexport const getVideoMarkdownNodeState = (\n node: Element\n): Visibility | undefined => node.data?.[stateKey] as Visibility | undefined;\n\nconst incompleteSvgRange = (raw: string, excluded: readonly Range[]) => {\n let position = 0;\n let rangeIndex = 0;\n while (position < raw.length) {\n const start = raw.indexOf(\"<\", position);\n if (start === -1) break;\n while (excluded[rangeIndex]?.end <= start) rangeIndex += 1;\n if (excluded[rangeIndex]?.start <= start) {\n position = excluded[rangeIndex].end;\n continue;\n }\n let backslashes = 0;\n for (let index = start - 1; index >= 0 && raw[index] === \"\\\\\"; index -= 1)\n backslashes += 1;\n if (backslashes % 2) {\n position = start + 1;\n continue;\n }\n const markup = readHtmlMarkup(raw, start);\n if (markup.kind === \"incomplete\")\n return /^<svg(?=[\\s/>]|$)/i.test(raw.slice(start))\n ? { start, end: raw.length }\n : undefined;\n position =\n markup.kind === \"tag\" &&\n !markup.closing &&\n !markup.selfClosing &&\n isHtmlRawTextTag(markup.name)\n ? findStreamingHtmlElementEnd(raw, start)\n : markup.kind === \"invalid\"\n ? start + 1\n : markup.end;\n }\n};\n\n// Inline HTML normalization only removes indentation and CRLF's CR. A monotonic\n// subsequence map retains the authored end offset of every remaining code unit.\nconst normalizedRawEnds = (raw: string, normalized: string) => {\n if (raw === normalized) return;\n const ends: number[] = [];\n let cursor = 0;\n for (let index = 0; index < normalized.length; index += 1) {\n cursor = raw.indexOf(normalized[index], cursor);\n if (cursor === -1)\n throw new Error(\"HTML normalization changed source characters\");\n ends.push(++cursor);\n }\n return ends;\n};\nconst rawOffset = (plan: VideoMarkdownRunPlan, offset: number, end = false) => {\n if (!plan.rawEnds) return offset;\n if (end) return offset === 0 ? 0 : plan.rawEnds[offset - 1];\n return offset === plan.markdownSource.length\n ? plan.fullSource.length\n : plan.rawEnds[offset] - 1;\n};\nconst rawRange = (plan: VideoMarkdownRunPlan, range?: Range) =>\n range && {\n start: rawOffset(plan, range.start),\n end: rawOffset(plan, range.end, true),\n };\n\n/** Transforms and raw HTML parsing use normalized coordinates until this step. */\nconst restoreRawPositions = (plan: VideoMarkdownRunPlan, tree: Root) => {\n if (!plan.rawEnds) return;\n const lines = [0];\n const newline = /\\r\\n|\\r|\\n/g;\n let match: RegExpExecArray | null;\n while ((match = newline.exec(plan.fullSource)))\n lines.push(match.index + match[0].length);\n const point = (\n value: NonNullable<Nodes[\"position\"]>[\"start\"],\n end: boolean\n ) => {\n if (value?.offset === undefined) return value;\n const offset = rawOffset(plan, value.offset, end);\n const line = firstAtOrAfter(lines, offset + 1);\n return { line, column: offset - lines[line - 1] + 1, offset };\n };\n const walk = (node: Nodes) => {\n const position = node === tree ? plan.sourceTree.position : node.position;\n if (position)\n node.position = {\n start: point(position.start, false),\n end: point(position.end, true),\n };\n if (\"children\" in node) node.children.forEach(walk);\n };\n walk(tree);\n};\n\n/** Runs parse only when source snapshots change; ticks never parse Markdown. */\nexport const createVideoMarkdownRunPlan = (\n segments: readonly RenderSegment[],\n analysis?: MarkdownSourceAnalysis\n): VideoMarkdownRunPlan => {\n const offsets: number[] = [];\n let fullSource = \"\";\n for (const segment of segments) {\n offsets.push(fullSource.length);\n fullSource += segment.value;\n }\n const received = analysis ?? getMarkdownSourceAnalysis(fullSource);\n const markdownSource = normalizeInlineHtml(fullSource, received.markdown);\n const rawEnds = normalizedRawEnds(fullSource, markdownSource);\n const parsed = rawEnds ? getMarkdownSourceAnalysis(markdownSource) : received;\n const media = segments.flatMap((segment, index) =>\n segment.type === \"markdown\" && segment.immediate\n ? [\n {\n start: rawEnds\n ? firstAtOrAfter(rawEnds, offsets[index] + 1)\n : offsets[index],\n end: rawEnds\n ? firstAtOrAfter(rawEnds, offsets[index] + segment.value.length) +\n 1\n : offsets[index] + segment.value.length,\n },\n ]\n : []\n );\n return {\n fullSource,\n markdownSource,\n rawEnds,\n segments,\n offsets,\n immediateOffsets: segments.flatMap((segment, index) =>\n segment.type === \"markdown\" && segment.immediate && !segment.pending\n ? [offsets[index]]\n : []\n ),\n sourceTree: parsed.tree,\n pendingMetadata: parsed.metadata.filter(\n (range) => range.pending && range.end === markdownSource.length\n ),\n incompleteSvg: incompleteSvgRange(\n markdownSource,\n [...parsed.literal, ...media].sort(\n (left, right) => left.start - right.start\n )\n ),\n visibility: new WeakMap(),\n };\n};\n\n// Decode each source token once and retain the raw end offset of every output\n// unit. An entity/escape becomes visible only after its entire token was typed.\ntype TextMode = \"markdown\" | \"html\" | \"code\";\nconst sourceUnits = (\n raw: string,\n range: Range,\n mode: TextMode = \"markdown\"\n) => {\n const units: { character: string; end: number }[] = [];\n const tokens =\n /\\\\[!-/:-@[-`{-~]|&(?:#(?:\\d{1,7}|x[\\da-f]{1,6})|[\\da-z]{1,31});|\\r\\n|\\r|[\\s\\S]/gi;\n const source = raw.slice(range.start, range.end);\n let token: RegExpExecArray | null;\n while ((token = tokens.exec(source))) {\n const value = token[0];\n const literal =\n mode === \"code\" || (mode === \"html\" && value.startsWith(\"\\\\\"));\n const decoded = (literal ? value : decodeString(value)).replace(\n /\\r\\n|\\r/g,\n \"\\n\"\n );\n for (let index = 0; index < decoded.length; index += 1)\n units.push({\n character: decoded[index],\n end:\n range.start +\n token.index +\n (decoded === value ? index + 1 : value.length),\n });\n }\n return units;\n};\nconst inlineCodeUnits = (raw: string, source: SourceValue) => {\n const opening = /^`+/.exec(raw.slice(source.start, source.end))?.[0] ?? \"\";\n const units = sourceUnits(\n raw,\n { start: source.start + opening.length, end: source.end - opening.length },\n \"code\"\n ).map((unit) => ({\n ...unit,\n character: unit.character === \"\\n\" ? \" \" : unit.character,\n }));\n if (\n units.length > source.value.length &&\n units[0]?.character === \" \" &&\n units.at(-1)?.character === \" \"\n )\n return units.slice(1, -1);\n return units;\n};\nconst blockCodeUnits = (raw: string, source: SourceValue) => {\n const block = raw.slice(source.start, source.end);\n const fenced = /^(?:`{3,}|~{3,})/.test(block);\n let cursor = source.start + (fenced ? block.indexOf(\"\\n\") + 1 : 0);\n const units: { character: string; end: number }[] = [];\n for (const line of source.value.split(\"\\n\")) {\n const newline = raw.indexOf(\"\\n\", cursor);\n const end = newline === -1 ? source.end : Math.min(newline, source.end);\n const lineEnd = raw[end - 1] === \"\\r\" ? end - 1 : end;\n const start = Math.max(cursor, lineEnd - line.length);\n for (let index = 0; index < line.length; index += 1)\n units.push({ character: line[index], end: start + index + 1 });\n units.push({ character: \"\\n\", end: Math.min(source.end, end + 1) });\n cursor = end + 1;\n }\n return units;\n};\n\n/** Preserve the existing SVG renderer's unfinished-header contract. */\nexport const cloneVideoMarkdownSourceTree = (\n plan: VideoMarkdownRunPlan\n): MarkdownRoot => {\n const tree = structuredClone(plan.sourceTree) as MarkdownRoot;\n type MutableNode = {\n type: string;\n value?: string;\n children?: MutableNode[];\n data?: { hName: string };\n position?: Nodes[\"position\"];\n };\n // An unfinished title is still parsed as ordinary prose by CommonMark.\n // Literalize only its HTML leaves; retain raw coordinates and any preceding\n // real HTML in the same node so immediate media keeps its stable parent.\n if (plan.pendingMetadata.length) {\n const lines = [0];\n for (let index = 0; index < plan.markdownSource.length; index += 1)\n if (plan.markdownSource[index] === \"\\n\") lines.push(index + 1);\n const pointAt = (offset: number) => {\n const line = firstAtOrAfter(lines, offset + 1);\n return { line, column: offset - lines[line - 1] + 1, offset };\n };\n const pendingStarts = plan.pendingMetadata.map(({ start }) => start);\n const literalize = (parent: MutableNode) => {\n parent.children = parent.children?.flatMap((child) => {\n if (child.children) literalize(child);\n const range = rangeOf(child);\n if (child.type !== \"html\" || !child.value || !range) return [child];\n let index = Math.max(\n 0,\n firstAtOrAfter(pendingStarts, range.start + 1) - 1\n );\n while (plan.pendingMetadata[index]?.end <= range.start) index += 1;\n if (!plan.pendingMetadata[index] || pendingStarts[index] >= range.end)\n return [child];\n const value = child.value;\n const raw = plan.markdownSource.slice(range.start, range.end);\n let ends: number[] | undefined;\n if (raw !== value) {\n let cursor = 0;\n ends = value.split(\"\").map((character) => {\n cursor = raw.indexOf(character, cursor);\n return range.start + ++cursor;\n });\n }\n const valueIndex = (offset: number) =>\n ends ? firstAtOrAfter(ends, offset + 1) : offset - range.start;\n const parts: MutableNode[] = [];\n let cursor = range.start;\n const push = (end: number, literal: boolean) => {\n if (end <= cursor) return;\n const part = value.slice(valueIndex(cursor), valueIndex(end));\n parts.push({\n ...child,\n type: literal ? \"text\" : \"html\",\n value: literal ? decodeString(part) : part,\n position: { start: pointAt(cursor), end: pointAt(end) },\n });\n cursor = end;\n };\n while (plan.pendingMetadata[index]?.start < range.end) {\n const pending = plan.pendingMetadata[index++];\n push(Math.max(cursor, pending.start), false);\n push(Math.min(range.end, pending.end), true);\n }\n push(range.end, false);\n return parts;\n });\n };\n literalize(tree as unknown as MutableNode);\n }\n const svg = plan.incompleteSvg;\n if (!svg) return tree;\n const before = plan.markdownSource.slice(0, svg.start);\n const point = {\n line: before.split(\"\\n\").length,\n column: svg.start - before.lastIndexOf(\"\\n\"),\n offset: svg.start,\n };\n const marker: MutableNode = {\n type: \"element\",\n data: { hName: \"svg\" },\n children: [],\n position: { start: point, end: tree.position!.end },\n };\n let inserted = false;\n const clip = (parent: MutableNode) => {\n parent.children = parent.children?.flatMap((child) => {\n const range = rangeOf(child);\n if (!range || range.end <= svg.start) return [child];\n if (range.start > svg.start || inserted) return [];\n if (child.children) {\n clip(child);\n return [child];\n }\n const units = sourceUnits(plan.markdownSource, range);\n let cursor = 0;\n let length = 0;\n for (const character of (child.value ?? \"\").split(\"\")) {\n while (units[cursor] && units[cursor].character !== character)\n cursor += 1;\n if (!units[cursor] || units[cursor].end > svg.start) break;\n cursor += 1;\n length += 1;\n }\n const prefix: MutableNode[] = length\n ? [\n {\n ...child,\n value: child.value!.slice(0, length),\n position: { start: child.position!.start, end: point },\n },\n ]\n : [];\n inserted = true;\n return [...prefix, marker];\n });\n };\n clip(tree as unknown as MutableNode);\n return tree;\n};\n\n/** Annotate the complete HTML tree before formatting plugins replace leaves. */\nexport const prepareVideoMarkdownRun = (\n sourcePlan: VideoMarkdownRunPlan,\n tree: Root,\n format: (tree: Root) => Root = (value) => value\n): VideoMarkdownRunPlan => {\n const plan: VideoMarkdownRunPlan = {\n ...sourcePlan,\n visibility: new WeakMap(),\n };\n restoreRawPositions(plan, tree);\n const sources = new Map<string, SourceValue>();\n const taskMarkers = new Map<string, Range>();\n const containerRanges = new Set<string>();\n const collect = (\n node: MarkdownRoot[\"children\"][number] | MarkdownSourceTree\n ) => {\n const range = rawRange(plan, rangeOf(node));\n if (range && node.type !== \"root\" && \"children\" in node)\n containerRanges.add(`${range.start}:${range.end}`);\n if (\n range &&\n node.type === \"listItem\" &&\n typeof node.checked === \"boolean\"\n ) {\n // GFM has already validated this marker and removed it from its paragraph.\n // Its value can contain a tab or line ending with container prefixes, so\n // locate its brackets only inside this confirmed item's leading source.\n const normalized = rangeOf(node)!;\n const start = plan.markdownSource.indexOf(\"[\", normalized.start);\n const end = plan.markdownSource.indexOf(\"]\", start + 1) + 1;\n if (start >= normalized.start && end > start && end <= normalized.end) {\n const marker = rawRange(plan, { start, end })!;\n taskMarkers.set(`${range.start}:${range.end}`, marker);\n const paragraph = node.children[0];\n const paragraphRange = paragraph && rawRange(plan, rangeOf(paragraph));\n // Tight items place the generated input in the li; loose items place it\n // in the first p. Exact ranges keep nested items on their own markers.\n if (paragraph?.type === \"paragraph\" && paragraphRange)\n taskMarkers.set(\n `${paragraphRange.start}:${paragraphRange.end}`,\n marker\n );\n }\n }\n if (range && \"value\" in node && typeof node.value === \"string\")\n sources.set(`${range.start}:${range.end}`, {\n ...range,\n value: node.value,\n type: node.type,\n });\n if (\"children\" in node)\n for (const child of node.children)\n collect(child as MarkdownRoot[\"children\"][number]);\n };\n collect(plan.sourceTree);\n\n const math = (node: Element) => {\n const classes = node.properties.className;\n return (\n Array.isArray(classes) &&\n classes.some(\n (value) =>\n value === \"language-math\" ||\n value === \"math-inline\" ||\n value === \"math-display\"\n )\n );\n };\n const wrapMath = (parent: Root | Element, inherited?: Range) => {\n parent.children = parent.children.map((child) => {\n if (child.type !== \"element\") return child;\n const range = rangeOf(child) ?? inherited;\n const isMath =\n math(child) ||\n (child.tagName === \"pre\" &&\n child.children.some((node) => node.type === \"element\" && math(node)));\n if (isMath && range) {\n const wrapper: Element = {\n type: \"element\",\n tagName: \"span\",\n properties: {},\n children: [child],\n position: child.position,\n };\n plan.visibility.set(wrapper, { range, atomic: true });\n return wrapper;\n }\n wrapMath(child, range);\n return child;\n }) as typeof parent.children;\n };\n wrapMath(tree);\n plan.tree = format(tree);\n\n // Generated structural parents (for example a table body) belong to their\n // positioned descendants, rather than the enclosing block's earlier start.\n const generatedRanges = new WeakMap<Nodes, Range>();\n const bindRanges = (node: Nodes): Range | undefined => {\n const authored = rangeOf(node);\n let children: Range | undefined;\n if (\"children\" in node)\n for (const child of node.children) {\n const range = bindRanges(child);\n if (range)\n children = children\n ? {\n start: Math.min(children.start, range.start),\n end: Math.max(children.end, range.end),\n }\n : range;\n }\n if (!authored && children) generatedRanges.set(node, children);\n return authored ?? children;\n };\n bindRanges(plan.tree);\n\n const containsImmediate = (range: Range) => {\n const next = firstAtOrAfter(plan.immediateOffsets, range.start);\n if (plan.immediateOffsets[next] < range.end) return true;\n const previous = plan.immediateOffsets[next - 1];\n if (previous === undefined) return false;\n const index = segmentAt(plan, previous);\n return range.start < previous + plan.segments[index].value.length;\n };\n\n type Cursor = {\n range: Range;\n mode: TextMode;\n source?: SourceValue;\n units?: ReturnType<typeof sourceUnits>;\n index: number;\n rawCursor: number;\n breakEnd?: number;\n };\n const unitsOf = (context: Cursor) =>\n (context.units ??=\n context.source?.type === \"code\"\n ? blockCodeUnits(plan.fullSource, context.source)\n : context.source?.type === \"inlineCode\"\n ? inlineCodeUnits(plan.fullSource, context.source)\n : sourceUnits(plan.fullSource, context.range, context.mode));\n const pendingMetadata = plan.pendingMetadata.map(\n (range) => rawRange(plan, range)!\n );\n const pendingStarts = pendingMetadata.map(({ start }) => start);\n const isPendingMetadata = (range: Range) => {\n const pending =\n pendingMetadata[firstAtOrAfter(pendingStarts, range.start + 1) - 1];\n return Boolean(pending && range.end <= pending.end);\n };\n const htmlRanges = [...sources.values()].filter(\n ({ type }) => type === \"html\"\n );\n // remark-flow replaces its tokenizer nodes with positionless elements.\n // Recover each replacement from the actual parsed span in its parent range.\n const flows = [...sources.values()].filter(\n ({ type }) => type === \"flowInteraction\"\n );\n const flowStarts = flows.map(({ start }) => start);\n const htmlContains = (range: Range) => {\n let low = 0;\n let high = htmlRanges.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n if (htmlRanges[middle].start <= range.start) low = middle + 1;\n else high = middle;\n }\n const html = htmlRanges[low - 1];\n return Boolean(html && html.end >= range.end);\n };\n const walk = (node: Nodes, inherited?: Cursor) => {\n let range = rangeOf(node);\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"custom-variable\" &&\n inherited\n ) {\n const cursor = Math.max(\n inherited.rawCursor,\n inherited.units?.[inherited.index - 1]?.end ?? 0\n );\n const flow = flows[firstAtOrAfter(flowStarts, cursor)];\n if (flow && flow.end <= inherited.range.end) range = flow;\n }\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"input\" &&\n node.properties.type === \"checkbox\" &&\n node.properties.disabled === true &&\n inherited\n )\n range = taskMarkers.get(\n `${inherited.range.start}:${inherited.range.end}`\n );\n // remark-breaks creates positionless breaks. Recover the authored newline\n // from the same source cursor used by the adjacent text, including CRLF.\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"br\" &&\n inherited\n ) {\n const units = unitsOf(inherited);\n let index = inherited.index;\n while (\n index < units.length &&\n (units[index].end <= inherited.rawCursor ||\n units[index].character !== \"\\n\")\n )\n index += 1;\n const end = units[index]?.end;\n if (end !== undefined) {\n inherited.index = index + 1;\n range = {\n start: end - (plan.fullSource.slice(end - 2, end) === \"\\r\\n\" ? 2 : 1),\n end,\n };\n }\n }\n range ??= generatedRanges.get(node);\n const source = range && sources.get(`${range.start}:${range.end}`);\n let context = inherited;\n const isCode = source?.type === \"code\" || source?.type === \"inlineCode\";\n if (\n range &&\n (!inherited ||\n range.start !== inherited.range.start ||\n range.end !== inherited.range.end)\n ) {\n context = {\n range,\n source,\n mode: isCode\n ? \"code\"\n : isPendingMetadata(range)\n ? \"markdown\"\n : htmlContains(range)\n ? \"html\"\n : (inherited?.mode ?? \"markdown\"),\n index: 0,\n rawCursor: range.start,\n };\n }\n if (node.type === \"text\" && context) {\n // Generated block-separator whitespace is not authored prose. Avoid\n // allocating the entire root's text map just to display these separators.\n if (!node.position && !node.value.trim() && context.mode !== \"code\")\n return;\n const units = unitsOf(context);\n while (units[context.index]?.end <= context.rawCursor) context.index += 1;\n const ends: number[] = [];\n const characters = node.value.split(\"\");\n // mdast-to-hast adds a newline after a Markdown break. It represents the\n // same source newline, rather than a second authored character to seek.\n if (\n context.breakEnd !== undefined &&\n characters[0] === \"\\n\" &&\n !node.position?.start\n ) {\n ends.push(context.breakEnd);\n characters.shift();\n }\n context.breakEnd = undefined;\n for (const character of characters) {\n while (\n context.index < units.length &&\n units[context.index].character !== character\n )\n context.index += 1;\n ends.push(units[context.index]?.end ?? context.range.end);\n context.index += 1;\n }\n plan.visibility.set(node, { ends });\n } else if (node.type === \"element\") {\n const state = plan.visibility.get(node);\n if (state?.atomic) return;\n const effectiveRange = range ?? context?.range;\n if (effectiveRange) {\n const waitsForEnd =\n node.tagName === \"input\" ||\n node.tagName === \"a\" ||\n node.tagName.startsWith(\"custom-\") ||\n node.tagName === \"svg\";\n const structural =\n !waitsForEnd &&\n (node.children.length > 0 ||\n (!node.position &&\n containerRanges.has(\n `${effectiveRange.start}:${effectiveRange.end}`\n )));\n const index = segmentAt(plan, effectiveRange.start);\n const segment = plan.segments[index];\n plan.visibility.set(node, {\n range: effectiveRange,\n structural,\n svg: node.tagName === \"svg\",\n immediate:\n // Ancestors of immediate HTML keep their stable host elements.\n // Leaves inside a received HTML span share its budget.\n ((structural || node.children.length > 0) &&\n containsImmediate(effectiveRange)) ||\n (segment.type === \"markdown\" &&\n segment.immediate &&\n !segment.pending &&\n effectiveRange.end <= plan.offsets[index] + segment.value.length),\n });\n }\n if (node.tagName === \"br\" && range && inherited && !htmlContains(range))\n inherited.breakEnd = range.end;\n }\n if (\"children\" in node) {\n for (const child of node.children) walk(child, context);\n const state = plan.visibility.get(node);\n // A generated token may precede its author's remaining source position:\n // GFM removes a task marker from the loose item's paragraph range.\n if (state?.structural && state.range)\n for (const child of node.children) {\n const childRange = plan.visibility.get(child)?.range;\n if (childRange && childRange.start < state.range.start)\n state.range = { ...state.range, start: childRange.start };\n }\n }\n if (inherited && context !== inherited && range)\n inherited.rawCursor = Math.max(inherited.rawCursor, range.end);\n };\n walk(plan.tree);\n return plan;\n};\n\n/** Project text and activation state without changing the complete tree shape. */\nexport const projectVideoMarkdownRun = (\n plan: VideoMarkdownRunPlan,\n renderedSegments: readonly RenderSegment[]\n): Root => {\n if (!plan.tree) throw new Error(\"Video Markdown run has not been prepared\");\n const visibleEnds = plan.segments.map(\n (segment, index) =>\n plan.offsets[index] +\n (segment.type === \"markdown\" && segment.pending\n ? 0\n : Math.min(\n renderedSegments[index]?.value.length ?? 0,\n segment.value.length\n ))\n );\n const visible = (end: number) => end <= visibleEnds[segmentAt(plan, end - 1)];\n const containsVisibleImmediate = (range: Range) => {\n const next = firstAtOrAfter(plan.immediateOffsets, range.start);\n const offset = plan.immediateOffsets[next];\n if (offset < range.end && visibleEnds[segmentAt(plan, offset)] > offset)\n return true;\n const previous = plan.immediateOffsets[next - 1];\n return (\n previous !== undefined &&\n range.start < visibleEnds[segmentAt(plan, previous)]\n );\n };\n const copy = (node: Nodes, atomic = false): Nodes => {\n const state = plan.visibility.get(node);\n if (node.type === \"text\") {\n let length = node.value.length;\n if (!atomic && state?.ends) {\n length = 0;\n while (length < state.ends.length && visible(state.ends[length]))\n length += 1;\n }\n return { ...node, value: node.value.slice(0, length) };\n }\n if (\"children\" in node) {\n const children = node.children.map((child) =>\n copy(child, atomic || Boolean(state?.atomic))\n );\n if (node.type === \"element\") {\n const projected: Element = {\n ...node,\n properties: { ...node.properties },\n children: children as Element[\"children\"],\n };\n if (state?.range) {\n const active =\n (Boolean(state.immediate) &&\n containsVisibleImmediate(state.range)) ||\n visible(state.structural ? state.range.start + 1 : state.range.end);\n const svgEnd = state.svg\n ? visibleEnds[segmentAt(plan, state.range.start)]\n : state.range.start;\n projected.data = {\n ...node.data,\n [stateKey]: {\n ...state,\n active,\n svgSource: state.svg\n ? plan.fullSource.slice(\n state.range.start,\n Math.min(\n state.range.end,\n Math.max(state.range.start, svgEnd)\n )\n )\n : undefined,\n },\n };\n }\n return projected;\n }\n return { ...node, children } as Root;\n }\n return { ...node };\n };\n return copy(plan.tree) as Root;\n};\n"],"names":["stateKey","firstAtOrAfter","values","target","low","high","middle","segmentAt","plan","position","rangeOf","node","start","end","getVideoMarkdownNodeState","incompleteSvgRange","raw","excluded","rangeIndex","backslashes","index","markup","readHtmlMarkup","isHtmlRawTextTag","findStreamingHtmlElementEnd","normalizedRawEnds","normalized","ends","cursor","rawOffset","offset","rawRange","range","restoreRawPositions","tree","lines","newline","match","point","value","line","walk","createVideoMarkdownRunPlan","segments","analysis","offsets","fullSource","segment","received","getMarkdownSourceAnalysis","markdownSource","normalizeInlineHtml","rawEnds","parsed","media","left","right","sourceUnits","mode","units","tokens","source","token","decoded","decodeString","inlineCodeUnits","opening","unit","blockCodeUnits","block","fenced","lineEnd","cloneVideoMarkdownSourceTree","pointAt","pendingStarts","literalize","parent","child","character","valueIndex","parts","push","literal","part","pending","svg","before","marker","inserted","clip","length","prefix","prepareVideoMarkdownRun","sourcePlan","format","sources","taskMarkers","containerRanges","collect","paragraph","paragraphRange","math","classes","wrapMath","inherited","wrapper","generatedRanges","bindRanges","authored","children","containsImmediate","next","previous","unitsOf","context","pendingMetadata","isPendingMetadata","htmlRanges","type","flows","flowStarts","htmlContains","html","flow","isCode","characters","effectiveRange","structural","state","childRange","projectVideoMarkdownRun","renderedSegments","visibleEnds","visible","containsVisibleImmediate","copy","atomic","projected","active","svgEnd"],"mappings":"iRA+CMA,EAAW,0BACXC,EAAiB,CAACC,EAA2BC,IAAmB,CACpE,IAAIC,EAAM,EACNC,EAAOH,EAAO,OAClB,KAAOE,EAAMC,GAAM,CACjB,MAAMC,EAAUF,EAAMC,IAAU,EAC5BH,EAAOI,CAAM,EAAIH,IAAcG,EAAS,EACvCD,EAAOC,CACd,CACA,OAAOF,CACT,EACMG,EAAY,CAACC,EAA4BC,IAC7C,KAAK,IAAI,EAAGR,EAAeO,EAAK,QAASC,EAAW,CAAC,EAAI,CAAC,EACtDC,EAAWC,GAA8D,CAC7E,MAAMC,EAAQD,EAAK,UAAU,OAAO,OAC9BE,EAAMF,EAAK,UAAU,KAAK,OAChC,OAAOC,IAAU,QAAaC,IAAQ,OAAY,OAAY,CAAE,MAAAD,EAAO,IAAAC,CAAA,CACzE,EACaC,EACXH,GAC2BA,EAAK,OAAOX,CAAQ,EAE3Ce,EAAqB,CAACC,EAAaC,IAA+B,CACtE,IAAIR,EAAW,EACXS,EAAa,E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AAS/E,EAAK,MAAM,OACxB,GAAI,CAAC6H,GAAUR,GAAO,KAEpB,IADAtC,EAAS,EACFA,EAASsC,EAAM,KAAK,QAAUK,EAAQL,EAAM,KAAKtC,CAAM,CAAC,GAC7DA,GAAU,EAEd,MAAO,CAAE,GAAG/E,EAAM,MAAOA,EAAK,MAAM,MAAM,EAAG+E,CAAM,CAAA,CACrD,CACA,GAAI,aAAc/E,EAAM,CACtB,MAAMkG,EAAWlG,EAAK,SAAS,IAAKkE,GAClC0D,EAAK1D,EAAO2D,GAAU,EAAQR,GAAO,MAAO,CAAA,EAE9C,GAAIrH,EAAK,OAAS,UAAW,CAC3B,MAAM8H,EAAqB,CACzB,GAAG9H,EACH,WAAY,CAAE,GAAGA,EAAK,UAAA,EACtB,SAAAkG,CAAA,EAEF,GAAImB,GAAO,MAAO,CAChB,MAAMU,EACH,EAAQV,EAAM,WACbM,EAAyBN,EAAM,KAAK,GACtCK,EAAQL,EAAM,WAAaA,EAAM,MAAM,MAAQ,EAAIA,EAAM,MAAM,GAAG,EAC9DW,EAASX,EAAM,IACjBI,EAAY7H,EAAUC,EAAMwH,EAAM,MAAM,KAAK,CAAC,EAC9CA,EAAM,MAAM,MAChBS,EAAU,KAAO,CACf,GAAG9H,EAAK,KACR,CAACX,CAAQ,EAAG,CACV,GAAGgI,EACH,OAAAU,EACA,UAAWV,EAAM,IACbxH,EAAK,WAAW,MACdwH,EAAM,MAAM,MACZ,KAAK,IACHA,EAAM,MAAM,IACZ,KAAK,IAAIA,EAAM,MAAM,MAAOW,CAAM,CAAA,CACpC,EAEF,MAAA,CACN,CAEJ,CACA,OAAOF,CACT,CACA,MAAO,CAAE,GAAG9H,EAAM,SAAAkG,CAAA,CACpB,CACA,MAAO,CAAE,GAAGlG,CAAA,CACd,EACA,OAAO4H,EAAK/H,EAAK,IAAI,CACvB"}
1
+ {"version":3,"file":"video-markdown-run.cjs","sources":["../../../../src/components/ContentRender/utils/video-markdown-run.ts"],"sourcesContent":["import type { Element, Nodes, Root } from \"hast\";\nimport type { Root as MarkdownRoot } from \"mdast\";\nimport { decodeString } from \"micromark-util-decode-string\";\nimport {\n getMarkdownSourceAnalysis,\n type MarkdownSourceAnalysis,\n type MarkdownSourceTree,\n} from \"./inline-code-ranges\";\nimport type { RenderSegment } from \"./split-content\";\nimport { normalizeInlineHtml } from \"./normalize-inline-html\";\nimport {\n readHtmlMarkup,\n isHtmlRawTextTag,\n findStreamingHtmlElementEnd,\n} from \"./html-block-end\";\n\ntype Range = { start: number; end: number };\ntype SourceValue = Range & { value: string; type: string };\ntype Visibility = {\n ends?: number[];\n range?: Range;\n atomic?: boolean;\n structural?: boolean;\n svg?: boolean;\n active?: boolean;\n immediate?: boolean;\n svgSource?: string;\n};\nexport type VideoMarkdownRunPlan = {\n fullSource: string;\n markdownSource: string;\n /** Raw end offset for each normalized UTF-16 unit, only when source changed. */\n rawEnds?: readonly number[];\n segments: readonly RenderSegment[];\n offsets: readonly number[];\n immediateOffsets: readonly number[];\n sourceTree: MarkdownSourceTree;\n incompleteSvg?: Range;\n pendingMetadata: readonly Range[];\n tree?: Root;\n visibility: WeakMap<Nodes, Visibility>;\n};\ndeclare module \"hast\" {\n interface ElementData {\n contentRenderVisibility?: Visibility;\n }\n}\nconst stateKey = \"contentRenderVisibility\";\nconst firstAtOrAfter = (values: readonly number[], target: number) => {\n let low = 0;\n let high = values.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n if (values[middle] < target) low = middle + 1;\n else high = middle;\n }\n return low;\n};\nconst segmentAt = (plan: VideoMarkdownRunPlan, position: number) =>\n Math.max(0, firstAtOrAfter(plan.offsets, position + 1) - 1);\nconst rangeOf = (node: { position?: Nodes[\"position\"] }): Range | undefined => {\n const start = node.position?.start?.offset;\n const end = node.position?.end?.offset;\n return start === undefined || end === undefined ? undefined : { start, end };\n};\nexport const getVideoMarkdownNodeState = (\n node: Element\n): Visibility | undefined => node.data?.[stateKey] as Visibility | undefined;\n\nconst incompleteSvgRange = (raw: string, excluded: readonly Range[]) => {\n let position = 0;\n let rangeIndex = 0;\n while (position < raw.length) {\n const start = raw.indexOf(\"<\", position);\n if (start === -1) break;\n while (excluded[rangeIndex]?.end <= start) rangeIndex += 1;\n if (excluded[rangeIndex]?.start <= start) {\n position = excluded[rangeIndex].end;\n continue;\n }\n let backslashes = 0;\n for (let index = start - 1; index >= 0 && raw[index] === \"\\\\\"; index -= 1)\n backslashes += 1;\n if (backslashes % 2) {\n position = start + 1;\n continue;\n }\n const markup = readHtmlMarkup(raw, start);\n if (markup.kind === \"incomplete\")\n return /^<svg(?=[\\s/>]|$)/i.test(raw.slice(start))\n ? { start, end: raw.length }\n : undefined;\n position =\n markup.kind === \"tag\" &&\n !markup.closing &&\n !markup.selfClosing &&\n isHtmlRawTextTag(markup.name)\n ? findStreamingHtmlElementEnd(raw, start)\n : markup.kind === \"invalid\"\n ? start + 1\n : markup.end;\n }\n};\n\n// Inline HTML normalization only removes indentation and CRLF's CR. A monotonic\n// subsequence map retains the authored end offset of every remaining code unit.\nconst normalizedRawEnds = (raw: string, normalized: string) => {\n if (raw === normalized) return;\n const ends: number[] = [];\n let cursor = 0;\n for (let index = 0; index < normalized.length; index += 1) {\n cursor = raw.indexOf(normalized[index], cursor);\n if (cursor === -1)\n throw new Error(\"HTML normalization changed source characters\");\n ends.push(++cursor);\n }\n return ends;\n};\nconst rawOffset = (plan: VideoMarkdownRunPlan, offset: number, end = false) => {\n if (!plan.rawEnds) return offset;\n if (end) return offset === 0 ? 0 : plan.rawEnds[offset - 1];\n return offset === plan.markdownSource.length\n ? plan.fullSource.length\n : plan.rawEnds[offset] - 1;\n};\nconst rawRange = (plan: VideoMarkdownRunPlan, range?: Range) =>\n range && {\n start: rawOffset(plan, range.start),\n end: rawOffset(plan, range.end, true),\n };\n\n/** Transforms and raw HTML parsing use normalized coordinates until this step. */\nconst restoreRawPositions = (plan: VideoMarkdownRunPlan, tree: Root) => {\n if (!plan.rawEnds) return;\n const lines = [0];\n const newline = /\\r\\n|\\r|\\n/g;\n let match: RegExpExecArray | null;\n while ((match = newline.exec(plan.fullSource)))\n lines.push(match.index + match[0].length);\n const point = (\n value: NonNullable<Nodes[\"position\"]>[\"start\"],\n end: boolean\n ) => {\n if (value?.offset === undefined) return value;\n const offset = rawOffset(plan, value.offset, end);\n const line = firstAtOrAfter(lines, offset + 1);\n return { line, column: offset - lines[line - 1] + 1, offset };\n };\n const walk = (node: Nodes) => {\n const position = node === tree ? plan.sourceTree.position : node.position;\n if (position)\n node.position = {\n start: point(position.start, false),\n end: point(position.end, true),\n };\n if (\"children\" in node) node.children.forEach(walk);\n };\n walk(tree);\n};\n\n/** Runs parse only when source snapshots change; ticks never parse Markdown. */\nexport const createVideoMarkdownRunPlan = (\n segments: readonly RenderSegment[],\n analysis?: MarkdownSourceAnalysis\n): VideoMarkdownRunPlan => {\n const offsets: number[] = [];\n let fullSource = \"\";\n for (const segment of segments) {\n offsets.push(fullSource.length);\n fullSource += segment.value;\n }\n const received = analysis ?? getMarkdownSourceAnalysis(fullSource);\n const markdownSource = normalizeInlineHtml(fullSource, received.markdown);\n const rawEnds = normalizedRawEnds(fullSource, markdownSource);\n const parsed = rawEnds ? getMarkdownSourceAnalysis(markdownSource) : received;\n const media = segments.flatMap((segment, index) =>\n segment.type === \"markdown\" && segment.immediate\n ? [\n {\n start: rawEnds\n ? firstAtOrAfter(rawEnds, offsets[index] + 1)\n : offsets[index],\n end: rawEnds\n ? firstAtOrAfter(rawEnds, offsets[index] + segment.value.length) +\n 1\n : offsets[index] + segment.value.length,\n },\n ]\n : []\n );\n return {\n fullSource,\n markdownSource,\n rawEnds,\n segments,\n offsets,\n immediateOffsets: segments.flatMap((segment, index) =>\n segment.type === \"markdown\" && segment.immediate && !segment.pending\n ? [offsets[index]]\n : []\n ),\n sourceTree: parsed.tree,\n pendingMetadata: parsed.metadata.filter(\n (range) => range.pending && range.end === markdownSource.length\n ),\n incompleteSvg: incompleteSvgRange(\n markdownSource,\n [...parsed.literal, ...media].sort(\n (left, right) => left.start - right.start\n )\n ),\n visibility: new WeakMap(),\n };\n};\n\n// Decode each source token once and retain the raw end offset of every output\n// unit. An entity/escape becomes visible only after its entire token was typed.\ntype TextMode = \"markdown\" | \"html\" | \"code\";\nconst sourceUnits = (\n raw: string,\n range: Range,\n mode: TextMode = \"markdown\"\n) => {\n const units: { character: string; end: number }[] = [];\n const tokens =\n /\\\\[!-/:-@[-`{-~]|&(?:#(?:\\d{1,7}|x[\\da-f]{1,6})|[\\da-z]{1,31});|\\r\\n|\\r|[\\s\\S]/gi;\n const source = raw.slice(range.start, range.end);\n let token: RegExpExecArray | null;\n while ((token = tokens.exec(source))) {\n const value = token[0];\n const literal =\n mode === \"code\" || (mode === \"html\" && value.startsWith(\"\\\\\"));\n const decoded = (literal ? value : decodeString(value)).replace(\n /\\r\\n|\\r/g,\n \"\\n\"\n );\n for (let index = 0; index < decoded.length; index += 1)\n units.push({\n character: decoded[index],\n end:\n range.start +\n token.index +\n (decoded === value ? index + 1 : value.length),\n });\n }\n return units;\n};\nconst inlineCodeUnits = (raw: string, source: SourceValue) => {\n const opening = /^`+/.exec(raw.slice(source.start, source.end))?.[0] ?? \"\";\n const units = sourceUnits(\n raw,\n { start: source.start + opening.length, end: source.end - opening.length },\n \"code\"\n ).map((unit) => ({\n ...unit,\n character: unit.character === \"\\n\" ? \" \" : unit.character,\n }));\n if (\n units.length > source.value.length &&\n units[0]?.character === \" \" &&\n units.at(-1)?.character === \" \"\n )\n return units.slice(1, -1);\n return units;\n};\nconst blockCodeUnits = (raw: string, source: SourceValue) => {\n const block = raw.slice(source.start, source.end);\n const fenced = /^(?:`{3,}|~{3,})/.test(block);\n let cursor = source.start + (fenced ? block.indexOf(\"\\n\") + 1 : 0);\n const units: { character: string; end: number }[] = [];\n for (const line of source.value.split(\"\\n\")) {\n const newline = raw.indexOf(\"\\n\", cursor);\n const end = newline === -1 ? source.end : Math.min(newline, source.end);\n const lineEnd = raw[end - 1] === \"\\r\" ? end - 1 : end;\n const start = Math.max(cursor, lineEnd - line.length);\n for (let index = 0; index < line.length; index += 1)\n units.push({ character: line[index], end: start + index + 1 });\n units.push({ character: \"\\n\", end: Math.min(source.end, end + 1) });\n cursor = end + 1;\n }\n return units;\n};\n\n/** Preserve the existing SVG renderer's unfinished-header contract. */\nexport const cloneVideoMarkdownSourceTree = (\n plan: VideoMarkdownRunPlan\n): MarkdownRoot => {\n const tree = structuredClone(plan.sourceTree) as MarkdownRoot;\n type MutableNode = {\n type: string;\n value?: string;\n children?: MutableNode[];\n data?: { hName: string };\n position?: Nodes[\"position\"];\n };\n // An unfinished title is still parsed as ordinary prose by CommonMark.\n // Literalize only its HTML leaves; retain raw coordinates and any preceding\n // real HTML in the same node so immediate media keeps its stable parent.\n if (plan.pendingMetadata.length) {\n const lines = [0];\n for (let index = 0; index < plan.markdownSource.length; index += 1)\n if (plan.markdownSource[index] === \"\\n\") lines.push(index + 1);\n const pointAt = (offset: number) => {\n const line = firstAtOrAfter(lines, offset + 1);\n return { line, column: offset - lines[line - 1] + 1, offset };\n };\n const pendingStarts = plan.pendingMetadata.map(({ start }) => start);\n const literalize = (parent: MutableNode) => {\n parent.children = parent.children?.flatMap((child) => {\n if (child.children) literalize(child);\n const range = rangeOf(child);\n if (child.type !== \"html\" || !child.value || !range) return [child];\n let index = Math.max(\n 0,\n firstAtOrAfter(pendingStarts, range.start + 1) - 1\n );\n while (plan.pendingMetadata[index]?.end <= range.start) index += 1;\n if (!plan.pendingMetadata[index] || pendingStarts[index] >= range.end)\n return [child];\n const value = child.value;\n const raw = plan.markdownSource.slice(range.start, range.end);\n let ends: number[] | undefined;\n if (raw !== value) {\n let cursor = 0;\n ends = value.split(\"\").map((character) => {\n cursor = raw.indexOf(character, cursor);\n return range.start + ++cursor;\n });\n }\n const valueIndex = (offset: number) =>\n ends ? firstAtOrAfter(ends, offset + 1) : offset - range.start;\n const parts: MutableNode[] = [];\n let cursor = range.start;\n const push = (end: number, literal: boolean) => {\n if (end <= cursor) return;\n const part = value.slice(valueIndex(cursor), valueIndex(end));\n parts.push({\n ...child,\n type: literal ? \"text\" : \"html\",\n value: literal ? decodeString(part) : part,\n position: { start: pointAt(cursor), end: pointAt(end) },\n });\n cursor = end;\n };\n while (plan.pendingMetadata[index]?.start < range.end) {\n const pending = plan.pendingMetadata[index++];\n push(Math.max(cursor, pending.start), false);\n push(Math.min(range.end, pending.end), true);\n }\n push(range.end, false);\n return parts;\n });\n };\n literalize(tree as unknown as MutableNode);\n }\n const svg = plan.incompleteSvg;\n if (!svg) return tree;\n const before = plan.markdownSource.slice(0, svg.start);\n const point = {\n line: before.split(\"\\n\").length,\n column: svg.start - before.lastIndexOf(\"\\n\"),\n offset: svg.start,\n };\n const marker: MutableNode = {\n type: \"element\",\n data: { hName: \"svg\" },\n children: [],\n position: { start: point, end: tree.position!.end },\n };\n let inserted = false;\n const clip = (parent: MutableNode) => {\n parent.children = parent.children?.flatMap((child) => {\n const range = rangeOf(child);\n if (!range || range.end <= svg.start) return [child];\n if (range.start > svg.start || inserted) return [];\n if (child.children) {\n clip(child);\n return [child];\n }\n const units = sourceUnits(plan.markdownSource, range);\n let cursor = 0;\n let length = 0;\n for (const character of (child.value ?? \"\").split(\"\")) {\n while (units[cursor] && units[cursor].character !== character)\n cursor += 1;\n if (!units[cursor] || units[cursor].end > svg.start) break;\n cursor += 1;\n length += 1;\n }\n const prefix: MutableNode[] = length\n ? [\n {\n ...child,\n value: child.value!.slice(0, length),\n position: { start: child.position!.start, end: point },\n },\n ]\n : [];\n inserted = true;\n return [...prefix, marker];\n });\n };\n clip(tree as unknown as MutableNode);\n return tree;\n};\n\n/** Annotate the complete HTML tree before formatting plugins replace leaves. */\nexport const prepareVideoMarkdownRun = (\n sourcePlan: VideoMarkdownRunPlan,\n tree: Root,\n format: (tree: Root) => Root = (value) => value\n): VideoMarkdownRunPlan => {\n const plan: VideoMarkdownRunPlan = {\n ...sourcePlan,\n visibility: new WeakMap(),\n };\n restoreRawPositions(plan, tree);\n const sources = new Map<string, SourceValue>();\n const taskMarkers = new Map<string, Range>();\n const containerRanges = new Set<string>();\n const collect = (\n node: MarkdownRoot[\"children\"][number] | MarkdownSourceTree\n ) => {\n const range = rawRange(plan, rangeOf(node));\n if (range && node.type !== \"root\" && \"children\" in node)\n containerRanges.add(`${range.start}:${range.end}`);\n if (\n range &&\n node.type === \"listItem\" &&\n typeof node.checked === \"boolean\"\n ) {\n // GFM has already validated this marker and removed it from its paragraph.\n // Its value can contain a tab or line ending with container prefixes, so\n // locate its brackets only inside this confirmed item's leading source.\n const normalized = rangeOf(node)!;\n const start = plan.markdownSource.indexOf(\"[\", normalized.start);\n const end = plan.markdownSource.indexOf(\"]\", start + 1) + 1;\n if (start >= normalized.start && end > start && end <= normalized.end) {\n const marker = rawRange(plan, { start, end })!;\n taskMarkers.set(`${range.start}:${range.end}`, marker);\n const paragraph = node.children[0];\n const paragraphRange = paragraph && rawRange(plan, rangeOf(paragraph));\n // Tight items place the generated input in the li; loose items place it\n // in the first p. Exact ranges keep nested items on their own markers.\n if (paragraph?.type === \"paragraph\" && paragraphRange)\n taskMarkers.set(\n `${paragraphRange.start}:${paragraphRange.end}`,\n marker\n );\n }\n }\n if (range && \"value\" in node && typeof node.value === \"string\")\n sources.set(`${range.start}:${range.end}`, {\n ...range,\n value: node.value,\n type: node.type,\n });\n if (\"children\" in node)\n for (const child of node.children)\n collect(child as MarkdownRoot[\"children\"][number]);\n };\n collect(plan.sourceTree);\n\n const math = (node: Element) => {\n const classes = node.properties.className;\n return (\n Array.isArray(classes) &&\n classes.some(\n (value) =>\n value === \"language-math\" ||\n value === \"math-inline\" ||\n value === \"math-display\"\n )\n );\n };\n const wrapMath = (parent: Root | Element, inherited?: Range) => {\n parent.children = parent.children.map((child) => {\n if (child.type !== \"element\") return child;\n const range = rangeOf(child) ?? inherited;\n const isMath =\n math(child) ||\n (child.tagName === \"pre\" &&\n child.children.some((node) => node.type === \"element\" && math(node)));\n if (isMath && range) {\n const wrapper: Element = {\n type: \"element\",\n tagName: \"span\",\n properties: {},\n children: [child],\n position: child.position,\n };\n plan.visibility.set(wrapper, { range, atomic: true });\n return wrapper;\n }\n wrapMath(child, range);\n return child;\n }) as typeof parent.children;\n };\n wrapMath(tree);\n plan.tree = format(tree);\n\n // Generated structural parents (for example a table body) belong to their\n // positioned descendants, rather than the enclosing block's earlier start.\n const generatedRanges = new WeakMap<Nodes, Range>();\n const bindRanges = (node: Nodes): Range | undefined => {\n const authored = rangeOf(node);\n let children: Range | undefined;\n if (\"children\" in node)\n for (const child of node.children) {\n const range = bindRanges(child);\n if (range)\n children = children\n ? {\n start: Math.min(children.start, range.start),\n end: Math.max(children.end, range.end),\n }\n : range;\n }\n if (!authored && children) generatedRanges.set(node, children);\n return authored ?? children;\n };\n bindRanges(plan.tree);\n\n const containsImmediate = (range: Range) => {\n const next = firstAtOrAfter(plan.immediateOffsets, range.start);\n if (plan.immediateOffsets[next] < range.end) return true;\n const previous = plan.immediateOffsets[next - 1];\n if (previous === undefined) return false;\n const index = segmentAt(plan, previous);\n return range.start < previous + plan.segments[index].value.length;\n };\n\n type Cursor = {\n range: Range;\n mode: TextMode;\n source?: SourceValue;\n units?: ReturnType<typeof sourceUnits>;\n index: number;\n rawCursor: number;\n breakEnd?: number;\n };\n const unitsOf = (context: Cursor) =>\n (context.units ??=\n context.source?.type === \"code\"\n ? blockCodeUnits(plan.fullSource, context.source)\n : context.source?.type === \"inlineCode\"\n ? inlineCodeUnits(plan.fullSource, context.source)\n : sourceUnits(plan.fullSource, context.range, context.mode));\n const pendingMetadata = plan.pendingMetadata.map((range) =>\n rawRange(plan, range)!\n );\n const pendingStarts = pendingMetadata.map(({ start }) => start);\n const isPendingMetadata = (range: Range) => {\n const pending =\n pendingMetadata[firstAtOrAfter(pendingStarts, range.start + 1) - 1];\n return Boolean(pending && range.end <= pending.end);\n };\n const htmlRanges = [...sources.values()].filter(\n ({ type }) => type === \"html\"\n );\n // remark-flow replaces its tokenizer nodes with positionless elements.\n // Recover each replacement from the actual parsed span in its parent range.\n const flows = [...sources.values()].filter(\n ({ type }) => type === \"flowInteraction\"\n );\n const flowStarts = flows.map(({ start }) => start);\n const htmlContains = (range: Range) => {\n let low = 0;\n let high = htmlRanges.length;\n while (low < high) {\n const middle = (low + high) >>> 1;\n if (htmlRanges[middle].start <= range.start) low = middle + 1;\n else high = middle;\n }\n const html = htmlRanges[low - 1];\n return Boolean(html && html.end >= range.end);\n };\n const walk = (node: Nodes, inherited?: Cursor) => {\n let range = rangeOf(node);\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"custom-variable\" &&\n inherited\n ) {\n const cursor = Math.max(\n inherited.rawCursor,\n inherited.units?.[inherited.index - 1]?.end ?? 0\n );\n const flow = flows[firstAtOrAfter(flowStarts, cursor)];\n if (flow && flow.end <= inherited.range.end) range = flow;\n }\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"input\" &&\n node.properties.type === \"checkbox\" &&\n node.properties.disabled === true &&\n inherited\n )\n range = taskMarkers.get(\n `${inherited.range.start}:${inherited.range.end}`\n );\n // remark-breaks creates positionless breaks. Recover the authored newline\n // from the same source cursor used by the adjacent text, including CRLF.\n if (\n !range &&\n node.type === \"element\" &&\n node.tagName === \"br\" &&\n inherited\n ) {\n const units = unitsOf(inherited);\n let index = inherited.index;\n while (\n index < units.length &&\n (units[index].end <= inherited.rawCursor ||\n units[index].character !== \"\\n\")\n )\n index += 1;\n const end = units[index]?.end;\n if (end !== undefined) {\n inherited.index = index + 1;\n range = {\n start: end - (plan.fullSource.slice(end - 2, end) === \"\\r\\n\" ? 2 : 1),\n end,\n };\n }\n }\n range ??= generatedRanges.get(node);\n const source = range && sources.get(`${range.start}:${range.end}`);\n let context = inherited;\n const isCode = source?.type === \"code\" || source?.type === \"inlineCode\";\n if (\n range &&\n (!inherited ||\n range.start !== inherited.range.start ||\n range.end !== inherited.range.end)\n ) {\n context = {\n range,\n source,\n mode: isCode\n ? \"code\"\n : isPendingMetadata(range)\n ? \"markdown\"\n : htmlContains(range)\n ? \"html\"\n : (inherited?.mode ?? \"markdown\"),\n index: 0,\n rawCursor: range.start,\n };\n }\n if (node.type === \"text\" && context) {\n // Generated block-separator whitespace is not authored prose. Avoid\n // allocating the entire root's text map just to display these separators.\n if (!node.position && !node.value.trim() && context.mode !== \"code\")\n return;\n const units = unitsOf(context);\n while (units[context.index]?.end <= context.rawCursor) context.index += 1;\n const ends: number[] = [];\n const characters = node.value.split(\"\");\n // mdast-to-hast adds a newline after a Markdown break. It represents the\n // same source newline, rather than a second authored character to seek.\n if (\n context.breakEnd !== undefined &&\n characters[0] === \"\\n\" &&\n !node.position?.start\n ) {\n ends.push(context.breakEnd);\n characters.shift();\n }\n context.breakEnd = undefined;\n for (const character of characters) {\n while (\n context.index < units.length &&\n units[context.index].character !== character\n )\n context.index += 1;\n ends.push(units[context.index]?.end ?? context.range.end);\n context.index += 1;\n }\n plan.visibility.set(node, { ends });\n } else if (node.type === \"element\") {\n const state = plan.visibility.get(node);\n if (state?.atomic) return;\n const effectiveRange = range ?? context?.range;\n if (effectiveRange) {\n const waitsForEnd =\n node.tagName === \"input\" ||\n node.tagName === \"a\" ||\n node.tagName.startsWith(\"custom-\") ||\n node.tagName === \"svg\";\n const structural =\n !waitsForEnd &&\n (node.children.length > 0 ||\n (!node.position &&\n containerRanges.has(\n `${effectiveRange.start}:${effectiveRange.end}`\n )));\n const index = segmentAt(plan, effectiveRange.start);\n const segment = plan.segments[index];\n plan.visibility.set(node, {\n range: effectiveRange,\n structural,\n svg: node.tagName === \"svg\",\n immediate:\n // Ancestors of immediate HTML keep their stable host elements.\n // Leaves inside a received HTML span share its budget.\n ((structural || node.children.length > 0) &&\n containsImmediate(effectiveRange)) ||\n (segment.type === \"markdown\" &&\n segment.immediate &&\n !segment.pending &&\n effectiveRange.end <= plan.offsets[index] + segment.value.length),\n });\n }\n if (node.tagName === \"br\" && range && inherited && !htmlContains(range))\n inherited.breakEnd = range.end;\n }\n if (\"children\" in node) {\n for (const child of node.children) walk(child, context);\n const state = plan.visibility.get(node);\n // A generated token may precede its author's remaining source position:\n // GFM removes a task marker from the loose item's paragraph range.\n if (state?.structural && state.range)\n for (const child of node.children) {\n const childRange = plan.visibility.get(child)?.range;\n if (childRange && childRange.start < state.range.start)\n state.range = { ...state.range, start: childRange.start };\n }\n }\n if (inherited && context !== inherited && range)\n inherited.rawCursor = Math.max(inherited.rawCursor, range.end);\n };\n walk(plan.tree);\n return plan;\n};\n\n/** Project text and activation state without changing the complete tree shape. */\nexport const projectVideoMarkdownRun = (\n plan: VideoMarkdownRunPlan,\n renderedSegments: readonly RenderSegment[]\n): Root => {\n if (!plan.tree) throw new Error(\"Video Markdown run has not been prepared\");\n const visibleEnds = plan.segments.map(\n (segment, index) =>\n plan.offsets[index] +\n (segment.type === \"markdown\" && segment.pending\n ? 0\n : Math.min(\n renderedSegments[index]?.value.length ?? 0,\n segment.value.length\n ))\n );\n const visible = (end: number) => end <= visibleEnds[segmentAt(plan, end - 1)];\n const containsVisibleImmediate = (range: Range) => {\n const next = firstAtOrAfter(plan.immediateOffsets, range.start);\n const offset = plan.immediateOffsets[next];\n if (offset < range.end && visibleEnds[segmentAt(plan, offset)] > offset)\n return true;\n const previous = plan.immediateOffsets[next - 1];\n return (\n previous !== undefined &&\n range.start < visibleEnds[segmentAt(plan, previous)]\n );\n };\n const copy = (node: Nodes, atomic = false): Nodes => {\n const state = plan.visibility.get(node);\n if (node.type === \"text\") {\n let length = node.value.length;\n if (!atomic && state?.ends) {\n length = 0;\n while (length < state.ends.length && visible(state.ends[length]))\n length += 1;\n }\n return { ...node, value: node.value.slice(0, length) };\n }\n if (\"children\" in node) {\n const children = node.children.map((child) =>\n copy(child, atomic || Boolean(state?.atomic))\n );\n if (node.type === \"element\") {\n const projected: Element = {\n ...node,\n properties: { ...node.properties },\n children: children as Element[\"children\"],\n };\n if (state?.range) {\n const active =\n (Boolean(state.immediate) &&\n containsVisibleImmediate(state.range)) ||\n visible(state.structural ? state.range.start + 1 : state.range.end);\n const svgEnd = state.svg\n ? visibleEnds[segmentAt(plan, state.range.start)]\n : state.range.start;\n projected.data = {\n ...node.data,\n [stateKey]: {\n ...state,\n active,\n svgSource: state.svg\n ? plan.fullSource.slice(\n state.range.start,\n Math.min(\n state.range.end,\n Math.max(state.range.start, svgEnd)\n )\n )\n : undefined,\n },\n };\n }\n return projected;\n }\n return { ...node, children } as Root;\n }\n return { ...node };\n };\n return copy(plan.tree) as Root;\n};\n"],"names":["stateKey","firstAtOrAfter","values","target","low","high","middle","segmentAt","plan","position","rangeOf","node","start","end","getVideoMarkdownNodeState","incompleteSvgRange","raw","excluded","rangeIndex","backslashes","index","markup","readHtmlMarkup","isHtmlRawTextTag","findStreamingHtmlElementEnd","normalizedRawEnds","normalized","ends","cursor","rawOffset","offset","rawRange","range","restoreRawPositions","tree","lines","newline","match","point","value","line","walk","createVideoMarkdownRunPlan","segments","analysis","offsets","fullSource","segment","received","getMarkdownSourceAnalysis","markdownSource","normalizeInlineHtml","rawEnds","parsed","media","left","right","sourceUnits","mode","units","tokens","source","token","decoded","decodeString","inlineCodeUnits","opening","unit","blockCodeUnits","block","fenced","lineEnd","cloneVideoMarkdownSourceTree","pointAt","pendingStarts","literalize","parent","child","character","valueIndex","parts","push","literal","part","pending","svg","before","marker","inserted","clip","length","prefix","prepareVideoMarkdownRun","sourcePlan","format","sources","taskMarkers","containerRanges","collect","paragraph","paragraphRange","math","classes","wrapMath","inherited","wrapper","generatedRanges","bindRanges","authored","children","containsImmediate","next","previous","unitsOf","context","pendingMetadata","isPendingMetadata","htmlRanges","type","flows","flowStarts","htmlContains","html","flow","isCode","characters","effectiveRange","structural","state","childRange","projectVideoMarkdownRun","renderedSegments","visibleEnds","visible","containsVisibleImmediate","copy","atomic","projected","active","svgEnd"],"mappings":"iRA+CMA,EAAW,0BACXC,EAAiB,CAACC,EAA2BC,IAAmB,CACpE,IAAIC,EAAM,EACNC,EAAOH,EAAO,OAClB,KAAOE,EAAMC,GAAM,CACjB,M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