effect-browser 0.3.0-beta.23 → 0.3.0-beta.25

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 (348) hide show
  1. package/README.md +437 -142
  2. package/dist/Action.d.mts +1 -1
  3. package/dist/Action.mjs +61 -9
  4. package/dist/Action.mjs.map +1 -1
  5. package/dist/Browser.d.mts +2 -2
  6. package/dist/Browser.mjs +2 -2
  7. package/dist/BrowserError.d.mts +2 -2
  8. package/dist/BrowserError.mjs +194 -41
  9. package/dist/BrowserError.mjs.map +1 -1
  10. package/dist/BrowserEvent.d.mts +2 -2
  11. package/dist/BrowserEvent.mjs +185 -35
  12. package/dist/BrowserEvent.mjs.map +1 -1
  13. package/dist/Cdp.d.mts +15 -0
  14. package/dist/Cdp.mjs +22 -0
  15. package/dist/Cdp.mjs.map +1 -0
  16. package/dist/Change.d.mts +2 -2
  17. package/dist/Change.mjs +40 -7
  18. package/dist/Change.mjs.map +1 -1
  19. package/dist/Frame.d.mts +2 -2
  20. package/dist/Frame.mjs +132 -14
  21. package/dist/Frame.mjs.map +1 -1
  22. package/dist/InputStyle.d.mts +153 -0
  23. package/dist/InputStyle.mjs +2 -0
  24. package/dist/Layout.d.mts +2 -0
  25. package/dist/Layout.mjs +123 -0
  26. package/dist/Layout.mjs.map +1 -0
  27. package/dist/Overlay.d.mts +2 -0
  28. package/dist/Overlay.mjs +58 -0
  29. package/dist/Overlay.mjs.map +1 -0
  30. package/dist/Page.d.mts +2 -2
  31. package/dist/Page.mjs +2 -2
  32. package/dist/PageTime.d.mts +2 -0
  33. package/dist/PageTime.mjs +17 -0
  34. package/dist/PageTime.mjs.map +1 -0
  35. package/dist/Pose.d.mts +2 -0
  36. package/dist/Pose.mjs +65 -0
  37. package/dist/Pose.mjs.map +1 -0
  38. package/dist/Site.d.mts +984 -0
  39. package/dist/Site.mjs +110 -0
  40. package/dist/Site.mjs.map +1 -0
  41. package/dist/Snapshot.d.mts +2 -2
  42. package/dist/Snapshot.mjs +87 -6
  43. package/dist/Snapshot.mjs.map +1 -1
  44. package/dist/Text.d.mts +2 -0
  45. package/dist/Text.mjs +45 -0
  46. package/dist/Text.mjs.map +1 -0
  47. package/dist/Window.d.mts +2 -2
  48. package/dist/Window.mjs +31 -6
  49. package/dist/Window.mjs.map +1 -1
  50. package/dist/ai/BrowserTools.d.mts +4987 -0
  51. package/dist/ai/BrowserTools.mjs +3 -0
  52. package/dist/ai/PageControl.d.mts +286 -0
  53. package/dist/ai/PageControl.mjs +426 -0
  54. package/dist/ai/PageControl.mjs.map +1 -0
  55. package/dist/ai/PromptCache.d.mts +16 -0
  56. package/dist/ai/PromptCache.mjs +72 -0
  57. package/dist/ai/PromptCache.mjs.map +1 -0
  58. package/dist/ai/Tabs.d.mts +2 -0
  59. package/dist/ai/Tabs.mjs +72 -0
  60. package/dist/ai/Tabs.mjs.map +1 -0
  61. package/dist/ai/ToolError.d.mts +34 -0
  62. package/dist/ai/ToolError.mjs +2 -0
  63. package/dist/ai/index.d.mts +6 -0
  64. package/dist/ai/index.mjs +6 -0
  65. package/dist/index.d.mts +7 -15
  66. package/dist/index.mjs +9 -8
  67. package/dist/{Action-24sLOubi.d.mts → internal/Action-CkanNTUw.d.mts} +64 -4
  68. package/dist/{Browser-wZhwZSlG.d.mts → internal/Browser-DD9Vm1c-.d.mts} +80 -10
  69. package/dist/{Browser-BKPAbyys.mjs → internal/Browser-vzD7i2oj.mjs} +658 -495
  70. package/dist/internal/Browser-vzD7i2oj.mjs.map +1 -0
  71. package/dist/{BrowserError-BlcmLVzn.d.mts → internal/BrowserError-CsuRYcDX.d.mts} +187 -28
  72. package/dist/{BrowserEvent-lLqJ3GJS.d.mts → internal/BrowserEvent-tGPYYf6R.d.mts} +197 -18
  73. package/dist/internal/BrowserTools-Yi3lOX4h.mjs +497 -0
  74. package/dist/internal/BrowserTools-Yi3lOX4h.mjs.map +1 -0
  75. package/dist/{Style-AO4V7Czt.mjs → internal/InputStyle-CPzxoN4g.mjs} +94 -16
  76. package/dist/internal/InputStyle-CPzxoN4g.mjs.map +1 -0
  77. package/dist/{moment/Moment.mjs → internal/Moment-CstaX1mR.mjs} +49 -16
  78. package/dist/internal/Moment-CstaX1mR.mjs.map +1 -0
  79. package/dist/{moment/Moment.d.mts → internal/Moment-DOcldBdf.d.mts} +54 -21
  80. package/dist/internal/Page-BfGxn7oN.d.mts +1553 -0
  81. package/dist/{Page-BF5izr8R.mjs → internal/Page-DqF-tuTx.mjs} +62 -72
  82. package/dist/internal/Page-DqF-tuTx.mjs.map +1 -0
  83. package/dist/internal/Release-CFONkPDP.d.mts +39 -0
  84. package/dist/internal/Stage-D5ymSXDT.mjs +298 -0
  85. package/dist/internal/Stage-D5ymSXDT.mjs.map +1 -0
  86. package/dist/internal/Stillness-DCPeAN1a.mjs +1124 -0
  87. package/dist/internal/Stillness-DCPeAN1a.mjs.map +1 -0
  88. package/dist/internal/Supervisor-BcY_QNIY.d.mts +108 -0
  89. package/dist/internal/Supervisor-BcglY23c.mjs +531 -0
  90. package/dist/internal/Supervisor-BcglY23c.mjs.map +1 -0
  91. package/dist/internal/Tabs-dXMscIUQ.d.mts +52 -0
  92. package/dist/internal/TestPage-CYiYbh63.d.mts +159 -0
  93. package/dist/internal/ToolError-DArsRS2m.mjs +117 -0
  94. package/dist/internal/ToolError-DArsRS2m.mjs.map +1 -0
  95. package/dist/{plan/index.d.mts → internal/Walk-BNXcfZ2z.d.mts} +59 -35
  96. package/dist/{plan/index.mjs → internal/Walk-C5ky7uSf.mjs} +83 -51
  97. package/dist/internal/Walk-C5ky7uSf.mjs.map +1 -0
  98. package/dist/{ActionPort.mjs → internal/action-port-B5EkeGOR.mjs} +6 -12
  99. package/dist/internal/action-port-B5EkeGOR.mjs.map +1 -0
  100. package/dist/internal/cdp/workerd.d.mts +13 -0
  101. package/dist/internal/cdp/workerd.mjs +19 -0
  102. package/dist/internal/cdp/workerd.mjs.map +1 -0
  103. package/dist/{Clock.mjs → internal/clock-BKSAEf00.mjs} +13 -13
  104. package/dist/internal/clock-BKSAEf00.mjs.map +1 -0
  105. package/dist/{connection-2KHI4_KN.d.mts → internal/connection-BaB0vp1o.d.mts} +6 -6
  106. package/dist/{connection-CK83pvqP.mjs → internal/connection-C2X4GmXM.mjs} +19 -15
  107. package/dist/internal/connection-C2X4GmXM.mjs.map +1 -0
  108. package/dist/internal/events-DzCrww-y.mjs +72 -0
  109. package/dist/internal/events-DzCrww-y.mjs.map +1 -0
  110. package/dist/internal/fold.inpage-CyVZQHZL.d.mts +49 -0
  111. package/dist/internal/fold.inpage-uhrT-dOB.mjs +49 -0
  112. package/dist/internal/fold.inpage-uhrT-dOB.mjs.map +1 -0
  113. package/dist/internal/functions-jBOs6GKv.mjs +27 -0
  114. package/dist/internal/functions-jBOs6GKv.mjs.map +1 -0
  115. package/dist/{Geometry-DJx9qrYy.d.mts → internal/geometry-Dhj_ztJs.d.mts} +3 -3
  116. package/dist/{Geometry.mjs → internal/geometry-Lxyflb9J.mjs} +3 -12
  117. package/dist/internal/geometry-Lxyflb9J.mjs.map +1 -0
  118. package/dist/{Matching.mjs → internal/matching-Cs-UeOY0.mjs} +24 -19
  119. package/dist/internal/matching-Cs-UeOY0.mjs.map +1 -0
  120. package/dist/internal/page-DFQb-YOK.mjs +436 -0
  121. package/dist/internal/page-DFQb-YOK.mjs.map +1 -0
  122. package/dist/internal/pose.inpage-CBFeWcVa.mjs +1996 -0
  123. package/dist/internal/pose.inpage-CBFeWcVa.mjs.map +1 -0
  124. package/dist/{Url.mjs → internal/url-DB0pQYk6.mjs} +3 -12
  125. package/dist/internal/url-DB0pQYk6.mjs.map +1 -0
  126. package/dist/policy/Policy.d.mts +60 -6
  127. package/dist/policy/Policy.mjs +52 -9
  128. package/dist/policy/Policy.mjs.map +1 -1
  129. package/dist/policy/index.d.mts +2 -0
  130. package/dist/policy/index.mjs +2 -0
  131. package/dist/presentation/Film.d.mts +332 -0
  132. package/dist/presentation/Film.mjs +298 -0
  133. package/dist/presentation/Film.mjs.map +1 -0
  134. package/dist/presentation/Motion.d.mts +5 -1
  135. package/dist/presentation/Motion.mjs +16 -2
  136. package/dist/presentation/Motion.mjs.map +1 -1
  137. package/dist/presentation/Presentation.d.mts +48 -6
  138. package/dist/presentation/Presentation.mjs +28 -9
  139. package/dist/presentation/Presentation.mjs.map +1 -1
  140. package/dist/presentation/Stage.d.mts +40 -6
  141. package/dist/presentation/Stage.mjs +1 -262
  142. package/dist/presentation/index.d.mts +5 -0
  143. package/dist/presentation/index.mjs +5 -0
  144. package/dist/supervisor/Release.d.mts +2 -0
  145. package/dist/supervisor/Release.mjs +40 -0
  146. package/dist/supervisor/Release.mjs.map +1 -0
  147. package/dist/supervisor/Supervisor.d.mts +2 -104
  148. package/dist/supervisor/Supervisor.mjs +2 -515
  149. package/dist/supervisor/index.d.mts +3 -0
  150. package/dist/supervisor/index.mjs +3 -0
  151. package/dist/testing/HttpCassette.d.mts +98 -0
  152. package/dist/testing/HttpCassette.mjs +146 -0
  153. package/dist/testing/HttpCassette.mjs.map +1 -0
  154. package/dist/testing/Story.d.mts +31 -0
  155. package/dist/testing/Story.mjs +76 -0
  156. package/dist/testing/Story.mjs.map +1 -0
  157. package/dist/testing/TestBrowser.d.mts +191 -0
  158. package/dist/testing/TestBrowser.mjs +105 -0
  159. package/dist/testing/TestBrowser.mjs.map +1 -0
  160. package/dist/testing/TestModel.d.mts +133 -0
  161. package/dist/testing/TestModel.mjs +209 -0
  162. package/dist/testing/TestModel.mjs.map +1 -0
  163. package/dist/testing/TestPage.d.mts +2 -0
  164. package/dist/testing/TestPage.mjs +47 -0
  165. package/dist/testing/TestPage.mjs.map +1 -0
  166. package/dist/testing/index.d.mts +6 -337
  167. package/dist/testing/index.mjs +6 -515
  168. package/dist/timeline/Moment.d.mts +3 -0
  169. package/dist/timeline/Moment.mjs +3 -0
  170. package/dist/timeline/Stillness.d.mts +34 -0
  171. package/dist/timeline/Stillness.mjs +2 -0
  172. package/dist/timeline/index.d.mts +3 -0
  173. package/dist/timeline/index.mjs +3 -0
  174. package/dist/walk/Walk.d.mts +2 -0
  175. package/dist/walk/Walk.mjs +2 -0
  176. package/dist/walk/index.d.mts +2 -0
  177. package/dist/walk/index.mjs +2 -0
  178. package/package.json +54 -133
  179. package/src/Action.ts +73 -8
  180. package/src/Browser.ts +85 -14
  181. package/src/BrowserError.ts +258 -63
  182. package/src/BrowserEvent.ts +264 -48
  183. package/src/Cdp.ts +42 -0
  184. package/src/Change.ts +75 -4
  185. package/src/Frame.ts +247 -14
  186. package/src/{Style.ts → InputStyle.ts} +130 -18
  187. package/src/Layout.ts +187 -0
  188. package/src/Overlay.ts +76 -0
  189. package/src/Page.ts +144 -275
  190. package/src/PageTime.ts +72 -0
  191. package/src/Pose.ts +81 -0
  192. package/src/Site.ts +136 -0
  193. package/src/Snapshot.ts +179 -3
  194. package/src/Text.ts +60 -0
  195. package/src/Window.ts +53 -3
  196. package/src/ai/BrowserTools.ts +778 -0
  197. package/src/ai/PageControl.ts +702 -0
  198. package/src/ai/PromptCache.ts +87 -0
  199. package/src/ai/Tabs.ts +84 -0
  200. package/src/ai/ToolError.ts +50 -0
  201. package/src/ai/index.ts +36 -0
  202. package/src/ai/internal/crops.ts +38 -0
  203. package/src/ai/internal/points.ts +57 -0
  204. package/src/ai/internal/receipts.ts +107 -0
  205. package/src/index.ts +87 -6
  206. package/src/{ActionPort.ts → internal/action-port.ts} +3 -3
  207. package/src/{providers → internal/cdp}/connection.ts +19 -12
  208. package/src/internal/cdp/workerd.ts +36 -0
  209. package/src/{Clock.ts → internal/clock.ts} +20 -0
  210. package/src/internal/input/actions.ts +1 -1
  211. package/src/internal/input/dispatch.ts +2 -2
  212. package/src/internal/input/guard.inpage.ts +1 -1
  213. package/src/internal/input/guard.ts +1 -1
  214. package/src/internal/input/perform.ts +35 -7
  215. package/src/internal/input/pointer.ts +9 -6
  216. package/src/internal/input/targets.inpage.ts +3 -3
  217. package/src/internal/input/targets.ts +1 -1
  218. package/src/{Matching.ts → internal/matching.ts} +28 -19
  219. package/src/internal/page/bridge.ts +67 -35
  220. package/src/internal/page/clock.inpage.ts +306 -0
  221. package/src/internal/page/compose.inpage.ts +101 -0
  222. package/src/internal/page/context.ts +4 -2
  223. package/src/internal/page/functions.ts +84 -0
  224. package/src/internal/page/navigation.ts +1 -1
  225. package/src/internal/page/openings.ts +2 -2
  226. package/src/internal/page/overlay.inpage.ts +96 -0
  227. package/src/internal/page/overlay.ts +89 -0
  228. package/src/internal/page/page.ts +39 -29
  229. package/src/internal/page/port.ts +14 -8
  230. package/src/internal/page/pose.inpage.ts +200 -0
  231. package/src/internal/page/pose.ts +80 -0
  232. package/src/internal/page/replies.ts +1 -1
  233. package/src/internal/page/requests.ts +1 -1
  234. package/src/internal/page/scripts.ts +1 -1
  235. package/src/internal/page/time.inpage.ts +49 -0
  236. package/src/internal/page/time.ts +122 -0
  237. package/src/internal/page/viewport.ts +3 -2
  238. package/src/internal/pictures/capture.ts +1 -4
  239. package/src/internal/pictures/dimensions.ts +1 -1
  240. package/src/internal/pictures/frame.ts +1 -1
  241. package/src/internal/pictures/pictures.ts +144 -91
  242. package/src/internal/reading/context.inpage.ts +2 -2
  243. package/src/internal/reading/expect.inpage.ts +1 -1
  244. package/src/internal/reading/layout.inpage.ts +193 -0
  245. package/src/internal/reading/layout.ts +101 -0
  246. package/src/internal/reading/names.inpage.ts +15 -0
  247. package/src/internal/reading/outline.inpage.ts +5 -21
  248. package/src/internal/reading/reading.ts +33 -21
  249. package/src/internal/reading/ready.inpage.ts +21 -26
  250. package/src/internal/reading/ready.ts +26 -5
  251. package/src/internal/reading/subjects.inpage.ts +3 -3
  252. package/src/internal/reading/text.inpage.ts +3 -16
  253. package/src/internal/reading/walk.inpage.ts +1 -1
  254. package/src/internal/timeline/changes.inpage.ts +7 -15
  255. package/src/internal/timeline/changes.ts +17 -5
  256. package/src/internal/timeline/record.inpage.ts +15 -6
  257. package/src/internal/timeline/sight.inpage.ts +2 -2
  258. package/src/internal/timeline/window.ts +3 -4
  259. package/src/policy/Policy.ts +70 -16
  260. package/src/policy/index.ts +12 -0
  261. package/src/presentation/Film.ts +451 -0
  262. package/src/presentation/Motion.ts +45 -3
  263. package/src/presentation/Presentation.ts +60 -14
  264. package/src/presentation/Stage.ts +73 -35
  265. package/src/presentation/index.ts +30 -0
  266. package/src/presentation/{feed.ts → internal/feed.ts} +1 -1
  267. package/src/supervisor/Release.ts +45 -0
  268. package/src/supervisor/Supervisor.ts +80 -5
  269. package/src/supervisor/index.ts +18 -0
  270. package/src/supervisor/{contract.ts → internal/contract.ts} +14 -10
  271. package/src/supervisor/{lifecycle.ts → internal/lifecycle.ts} +7 -7
  272. package/src/supervisor/{runtime.ts → internal/runtime.ts} +7 -7
  273. package/src/testing/HttpCassette.ts +260 -0
  274. package/src/testing/Story.ts +103 -0
  275. package/src/testing/TestBrowser.ts +14 -4
  276. package/src/testing/TestModel.ts +297 -0
  277. package/src/testing/TestPage.ts +92 -4
  278. package/src/testing/index.ts +35 -1
  279. package/src/testing/{evidence.ts → internal/evidence.ts} +19 -11
  280. package/src/testing/{model.ts → internal/model.ts} +14 -8
  281. package/src/testing/{page.ts → internal/page.ts} +55 -51
  282. package/src/{moment → timeline}/Moment.ts +79 -29
  283. package/src/{stillness → timeline}/Stillness.ts +89 -46
  284. package/src/timeline/index.ts +18 -0
  285. package/src/{stillness/Pixels.ts → timeline/internal/pixels.ts} +27 -1
  286. package/src/{moment → timeline/internal}/words.ts +2 -2
  287. package/src/walk/Walk.ts +165 -0
  288. package/src/walk/index.ts +12 -0
  289. package/src/{plan → walk/internal}/choose.ts +23 -14
  290. package/src/{plan → walk/internal}/data.ts +37 -14
  291. package/src/{plan → walk/internal}/execute.ts +79 -36
  292. package/src/{plan → walk/internal}/record.ts +6 -6
  293. package/src/{plan → walk/internal}/targets.ts +35 -25
  294. package/dist/ActionPort.d.mts +0 -15
  295. package/dist/ActionPort.mjs.map +0 -1
  296. package/dist/Browser-BKPAbyys.mjs.map +0 -1
  297. package/dist/Change-Ba7INmay.d.mts +0 -69
  298. package/dist/Clock.d.mts +0 -57
  299. package/dist/Clock.mjs.map +0 -1
  300. package/dist/Frame-UEH2hO5T.d.mts +0 -124
  301. package/dist/Geometry.d.mts +0 -2
  302. package/dist/Geometry.mjs.map +0 -1
  303. package/dist/Matching.d.mts +0 -37
  304. package/dist/Matching.mjs.map +0 -1
  305. package/dist/Page-BF5izr8R.mjs.map +0 -1
  306. package/dist/Page-CvsOEorc.d.mts +0 -566
  307. package/dist/Released-tURbFmal.d.mts +0 -15
  308. package/dist/Snapshot-CtBVOtuu.d.mts +0 -73
  309. package/dist/Stillness-CNlvayIo.mjs +0 -136
  310. package/dist/Stillness-CNlvayIo.mjs.map +0 -1
  311. package/dist/Style-AO4V7Czt.mjs.map +0 -1
  312. package/dist/Style.d.mts +0 -72
  313. package/dist/Style.mjs +0 -2
  314. package/dist/Url.d.mts +0 -26
  315. package/dist/Url.mjs.map +0 -1
  316. package/dist/Window-CMddGMt1.d.mts +0 -34
  317. package/dist/connection-CK83pvqP.mjs.map +0 -1
  318. package/dist/moment/Moment.mjs.map +0 -1
  319. package/dist/plan/index.mjs.map +0 -1
  320. package/dist/presentation/Stage.mjs.map +0 -1
  321. package/dist/presentation/feed.d.mts +0 -20
  322. package/dist/presentation/feed.mjs +0 -18
  323. package/dist/presentation/feed.mjs.map +0 -1
  324. package/dist/providers/Cdp.d.mts +0 -9
  325. package/dist/providers/Cdp.mjs +0 -15
  326. package/dist/providers/Cdp.mjs.map +0 -1
  327. package/dist/providers/Chromium.d.mts +0 -32
  328. package/dist/providers/Chromium.mjs +0 -55
  329. package/dist/providers/Chromium.mjs.map +0 -1
  330. package/dist/providers/Released.d.mts +0 -2
  331. package/dist/providers/Released.mjs +0 -12
  332. package/dist/providers/Released.mjs.map +0 -1
  333. package/dist/stillness/Stillness.d.mts +0 -12
  334. package/dist/stillness/Stillness.mjs +0 -2
  335. package/dist/supervisor/Supervisor.mjs.map +0 -1
  336. package/dist/testing/index.mjs.map +0 -1
  337. package/dist/workerd/Cdp.d.mts +0 -8
  338. package/dist/workerd/Cdp.mjs +0 -13
  339. package/dist/workerd/Cdp.mjs.map +0 -1
  340. package/src/plan/index.ts +0 -36
  341. package/src/providers/Cdp.ts +0 -16
  342. package/src/providers/Chromium.ts +0 -99
  343. package/src/providers/Released.ts +0 -13
  344. package/src/workerd/Cdp.ts +0 -11
  345. /package/dist/{rolldown-runtime-D7D4PA-g.mjs → internal/rolldown-runtime-D7D4PA-g.mjs} +0 -0
  346. /package/src/{Geometry.ts → internal/geometry.ts} +0 -0
  347. /package/src/{Url.ts → internal/url.ts} +0 -0
  348. /package/src/{stillness → timeline/internal}/utilsBundle.d.ts +0 -0
@@ -0,0 +1,306 @@
1
+ /**
2
+ * In the page's main world, before its own scripts: the page clock, which `PageTime.hold` holds and
3
+ * steps. Until held it keeps real time. Held, the page's timers and intervals, its animation
4
+ * frames, `performance.now`, `Date.now`, `new Date()` and `Date()`, and its CSS transitions, CSS
5
+ * animations and Web Animations move only when stepped: due timers run in time order, each at its
6
+ * own time, animations are moved to each of those times, and then one animation frame runs at the
7
+ * step's end. A timer or frame asked for before the hold waits for page time, and what is left of
8
+ * it goes back to real time on release, when page time carries on from where it was, never back.
9
+ * Workers, media, `requestIdleCallback`, `MessageChannel` and events' `timeStamp` keep real time,
10
+ * as does a frame's document, which keeps its own clock.
11
+ *
12
+ * It listens for one event name, which only the library knows, on the document: the library's
13
+ * isolated world dispatches it with what to do, and the clock acknowledges by preventing its
14
+ * default. Its parts use only their parameters, the DOM and what they define, and the page's
15
+ * globals as they were before the page's scripts ran.
16
+ */
17
+
18
+ /** The page's timing globals as they were before its scripts ran. */
19
+ export interface Real {
20
+ readonly setTimeout: (run: () => void, millis: number) => number;
21
+ readonly clearTimeout: (id: number) => void;
22
+ readonly now: () => number;
23
+ }
24
+
25
+ /** The page's timers and intervals by the ids it holds, each due at a page time. */
26
+ export const timers = (
27
+ real: Real,
28
+ now: () => number,
29
+ held: () => boolean,
30
+ report: (error: unknown) => void,
31
+ ) => {
32
+ interface Timer {
33
+ readonly run: () => void;
34
+ readonly every: number;
35
+ at: number;
36
+ real?: number | undefined;
37
+ }
38
+ const all = new Map<number, Timer>();
39
+ let next = 1;
40
+
41
+ const arm = (id: number, timer: Timer) => {
42
+ timer.real = real.setTimeout(
43
+ () => {
44
+ if (all.get(id) === timer && !held()) fire(id, timer);
45
+ },
46
+ Math.max(0, timer.at - now()),
47
+ );
48
+ };
49
+
50
+ const fire = (id: number, timer: Timer) => {
51
+ if (timer.every > 0) {
52
+ timer.at = Math.max(timer.at + timer.every, now());
53
+ if (!held()) arm(id, timer);
54
+ } else all.delete(id);
55
+ try {
56
+ timer.run();
57
+ } catch (error) {
58
+ report(error);
59
+ }
60
+ };
61
+
62
+ const schedule =
63
+ (every: boolean) =>
64
+ (handler: TimerHandler, delay?: unknown, ...args: Array<unknown>) => {
65
+ const id = next++;
66
+ const millis = Math.max(every ? 1 : 0, Number(delay) || 0);
67
+
68
+ const run = () => {
69
+ if (typeof handler === "function") Reflect.apply(handler, window, args);
70
+ // oxlint-disable-next-line no-eval -- the page's own string handler, run globally as its native timer would
71
+ else (0, eval)(handler);
72
+ };
73
+
74
+ const timer: Timer = { run, every: every ? millis : 0, at: now() + millis };
75
+
76
+ all.set(id, timer);
77
+ if (!held()) arm(id, timer);
78
+
79
+ return id;
80
+ };
81
+
82
+ const clear = (id: unknown) => {
83
+ const timer = all.get(Number(id));
84
+
85
+ if (timer?.real !== undefined) real.clearTimeout(timer.real);
86
+ all.delete(Number(id));
87
+ };
88
+
89
+ // Run the first timer due by `target`, once `reach` has taken the page to its time.
90
+ const runDue = (target: number, reach: (at: number) => void) => {
91
+ let due: [number, Timer] | undefined;
92
+
93
+ for (const entry of all)
94
+ if (entry[1].at <= target && (due === undefined || entry[1].at < due[1].at)) due = entry;
95
+ if (due === undefined) return false;
96
+ reach(due[1].at);
97
+ fire(...due);
98
+
99
+ return true;
100
+ };
101
+
102
+ return {
103
+ setTimeout: schedule(false),
104
+ setInterval: schedule(true),
105
+ clear,
106
+ runDue,
107
+ pause: () => {
108
+ for (const timer of all.values()) if (timer.real !== undefined) real.clearTimeout(timer.real);
109
+ },
110
+ resume: () => {
111
+ for (const [id, timer] of all) arm(id, timer);
112
+ },
113
+ };
114
+ };
115
+
116
+ /** The page's animations the clock paused, which it moves and which play again on release. */
117
+ export const animations = () => {
118
+ let ours = new WeakSet<Animation>();
119
+
120
+ // Every animation the page runs is paused at page time: one the clock has not seen began now.
121
+ const catchUp = () => {
122
+ for (const animation of document.getAnimations())
123
+ if (animation.playState === "running") {
124
+ animation.pause();
125
+ if (!ours.has(animation)) animation.currentTime = 0;
126
+ ours.add(animation);
127
+ }
128
+ };
129
+
130
+ const move = (by: number) => {
131
+ if (by <= 0) return;
132
+ for (const animation of document.getAnimations()) {
133
+ if (!ours.has(animation) || animation.playState !== "paused") continue;
134
+ const at = Number(animation.currentTime) + by * animation.playbackRate;
135
+ const end = Number(animation.effect?.getComputedTiming().endTime ?? Infinity);
136
+
137
+ if (animation.playbackRate >= 0 ? at >= end : at <= 0) {
138
+ ours.delete(animation);
139
+ animation.finish();
140
+ } else animation.currentTime = at;
141
+ }
142
+ };
143
+
144
+ const play = () => {
145
+ for (const animation of document.getAnimations())
146
+ if (ours.has(animation) && animation.playState === "paused") animation.play();
147
+ ours = new WeakSet();
148
+ };
149
+
150
+ return { catchUp, move, play };
151
+ };
152
+
153
+ export interface ClockParts {
154
+ readonly timers: typeof timers;
155
+ readonly animations: typeof animations;
156
+ }
157
+
158
+ export const clock = (parts: ClockParts) => (name: string) => {
159
+ if (window !== window.top) return;
160
+
161
+ const real = {
162
+ setTimeout: window.setTimeout.bind(window),
163
+ clearTimeout: window.clearTimeout.bind(window),
164
+ requestAnimationFrame: window.requestAnimationFrame.bind(window),
165
+ cancelAnimationFrame: window.cancelAnimationFrame.bind(window),
166
+ now: performance.now.bind(performance),
167
+ dateNow: Date.now,
168
+ Date,
169
+ };
170
+
171
+ let held = false;
172
+ // Page time while held; otherwise real time moved on by `shift`, so it never goes back. The
173
+ // date is page time from the real date's distance from it when the clock was first held.
174
+ let frozen = 0;
175
+ let shift = 0;
176
+ let dated: number | undefined;
177
+ let nextFrame = 1;
178
+ const pageNow = () => (held ? frozen : real.now() + shift);
179
+ const dateNow = () => (dated === undefined ? real.dateNow() : Math.floor(pageNow() + dated));
180
+
181
+ const report = (error: unknown) => {
182
+ real.setTimeout(() => {
183
+ throw error;
184
+ });
185
+ };
186
+
187
+ const timed = parts.timers(real, pageNow, () => held, report);
188
+ const animated = parts.animations();
189
+
190
+ // Animation frames by the ids the page holds, with their real frame while not held.
191
+ const frames = new Map<number, { readonly run: FrameRequestCallback; real?: number }>();
192
+
193
+ const request = (id: number, frame: { readonly run: FrameRequestCallback; real?: number }) => {
194
+ frame.real = real.requestAnimationFrame(() => {
195
+ frames.delete(id);
196
+ frame.run(pageNow());
197
+ });
198
+ };
199
+
200
+ // Move the page's animations and time on to `at`.
201
+ const reach = (at: number) => {
202
+ animated.catchUp();
203
+ animated.move(at - frozen);
204
+ frozen = Math.max(frozen, at);
205
+ };
206
+
207
+ const hold = () => {
208
+ if (held) return;
209
+ dated ??= real.dateNow() - real.now();
210
+ frozen = pageNow();
211
+ held = true;
212
+ timed.pause();
213
+ for (const frame of frames.values())
214
+ if (frame.real !== undefined) real.cancelAnimationFrame(frame.real);
215
+ animated.catchUp();
216
+ };
217
+
218
+ const advance = (by: number) => {
219
+ const target = frozen + by;
220
+
221
+ for (let guard = 0; guard < 10_000 && timed.runDue(target, reach); guard++);
222
+ reach(target);
223
+ const callbacks = [...frames.values()];
224
+
225
+ frames.clear();
226
+ for (const frame of callbacks)
227
+ try {
228
+ frame.run(frozen);
229
+ } catch (error) {
230
+ report(error);
231
+ }
232
+ animated.catchUp();
233
+ };
234
+
235
+ const release = () => {
236
+ if (!held) return;
237
+ held = false;
238
+ shift = Math.max(shift, frozen - real.now());
239
+ timed.resume();
240
+ for (const [id, frame] of frames) request(id, frame);
241
+ animated.play();
242
+ };
243
+
244
+ const define = (target: object, key: string, value: unknown) =>
245
+ Object.defineProperty(target, key, { value, writable: true, configurable: true });
246
+
247
+ define(window, "setTimeout", timed.setTimeout);
248
+ define(window, "setInterval", timed.setInterval);
249
+ define(window, "clearTimeout", timed.clear);
250
+ define(window, "clearInterval", timed.clear);
251
+ define(window, "requestAnimationFrame", (run: FrameRequestCallback) => {
252
+ const id = nextFrame++;
253
+ const frame = { run };
254
+
255
+ frames.set(id, frame);
256
+ if (!held) request(id, frame);
257
+
258
+ return id;
259
+ });
260
+ define(window, "cancelAnimationFrame", (id: number) => {
261
+ const frame = frames.get(id);
262
+
263
+ if (frame?.real !== undefined) real.cancelAnimationFrame(frame.real);
264
+ frames.delete(id);
265
+ });
266
+ define(performance, "now", pageNow);
267
+
268
+ // `Date` reads page time when it is given no time of its own.
269
+ function PageDate(this: unknown, ...args: Array<unknown>) {
270
+ if (new.target === undefined) return new real.Date(dateNow()).toString();
271
+
272
+ const made: unknown = Reflect.construct(
273
+ real.Date,
274
+ args.length === 0 ? [dateNow()] : args,
275
+ new.target,
276
+ );
277
+
278
+ return made;
279
+ }
280
+ Object.setPrototypeOf(PageDate, real.Date);
281
+ PageDate.prototype = real.Date.prototype;
282
+ define(PageDate, "now", dateNow);
283
+ define(window, "Date", PageDate);
284
+
285
+ document.addEventListener(
286
+ name,
287
+ (event) => {
288
+ const detail: unknown = "detail" in event ? event.detail : undefined;
289
+ const op = typeof detail === "object" && detail !== null && "op" in detail ? detail.op : "";
290
+
291
+ const by =
292
+ typeof detail === "object" && detail !== null && "by" in detail ? Number(detail.by) : 0;
293
+
294
+ if (op === "holds") {
295
+ if (held) event.preventDefault();
296
+
297
+ return;
298
+ }
299
+ if (op === "hold" || op === "advance") hold();
300
+ if (op === "advance" && Number.isFinite(by) && by >= 0) advance(by);
301
+ if (op === "release") release();
302
+ event.preventDefault();
303
+ },
304
+ true,
305
+ );
306
+ };
@@ -0,0 +1,101 @@
1
+ /**
2
+ * In the page: the readers, the change record, the overlay and element poses, composed from their
3
+ * parts in the order they depend on one another. The page script installs this with trusted
4
+ * input's checks and held time over it (`bridge.ts`); a site that owns its page calls it in its
5
+ * own bundle (`Site.ts`). See `names.inpage.ts` for what a page-side part may use.
6
+ */
7
+ import type { match } from "../matching.ts";
8
+ import type { context } from "../reading/context.inpage.ts";
9
+ import type { controls } from "../reading/controls.inpage.ts";
10
+ import type { expectations } from "../reading/expect.inpage.ts";
11
+ import type { layout } from "../reading/layout.inpage.ts";
12
+ import type { elements, names } from "../reading/names.inpage.ts";
13
+ import type { outline } from "../reading/outline.inpage.ts";
14
+ import type { ready } from "../reading/ready.inpage.ts";
15
+ import type { states, subjects } from "../reading/subjects.inpage.ts";
16
+ import type { text } from "../reading/text.inpage.ts";
17
+ import type { walk } from "../reading/walk.inpage.ts";
18
+ import type { changes } from "../timeline/changes.inpage.ts";
19
+ import type { fold } from "../timeline/fold.inpage.ts";
20
+ import type { history } from "../timeline/history.inpage.ts";
21
+ import type { marks } from "../timeline/marks.inpage.ts";
22
+ import type { record } from "../timeline/record.inpage.ts";
23
+ import type { sight } from "../timeline/sight.inpage.ts";
24
+ import type { addresses } from "../url.ts";
25
+ import type { overlay } from "./overlay.inpage.ts";
26
+ import type { pose } from "./pose.inpage.ts";
27
+
28
+ /** The parts composed, by name. */
29
+ export interface Composed {
30
+ readonly elements: typeof elements;
31
+ readonly names: typeof names;
32
+ readonly walk: typeof walk;
33
+ readonly match: typeof match;
34
+ readonly context: typeof context;
35
+ readonly subjects: typeof subjects;
36
+ readonly states: typeof states;
37
+ readonly expectations: typeof expectations;
38
+ readonly text: typeof text;
39
+ readonly layout: typeof layout;
40
+ readonly controls: typeof controls;
41
+ readonly fold: typeof fold;
42
+ readonly history: typeof history;
43
+ readonly sight: typeof sight;
44
+ readonly marks: typeof marks;
45
+ readonly record: typeof record;
46
+ readonly changes: typeof changes;
47
+ readonly ready: typeof ready;
48
+ readonly outline: typeof outline;
49
+ readonly overlay: typeof overlay;
50
+ readonly pose: typeof pose;
51
+ readonly addresses: typeof addresses;
52
+ }
53
+
54
+ /** Compose the parts; refs go on from `next`, as a script installed before left them. */
55
+ export const compose = (parts: Composed, next?: number) => {
56
+ const named = parts.names(parts.elements());
57
+
58
+ if (next !== undefined) named.refs.next = next;
59
+ const walked = parts.walk(named);
60
+ const placing = parts.context(named, walked);
61
+ const matching = parts.match();
62
+ const subjected = parts.subjects(named, walked, matching, placing, parts.states(named));
63
+ const texts = parts.text(named, walked);
64
+ const controlled = parts.controls(named, subjected, texts);
65
+ const kept = parts.history(parts.fold());
66
+ const seeing = parts.sight(named, walked, texts, kept);
67
+ const marking = parts.marks(named, kept, seeing);
68
+ const recorder = parts.record(named, texts, kept, seeing, marking);
69
+ const url = parts.addresses();
70
+ const read = parts.outline(named, walked, subjected, texts, controlled, url);
71
+ const readiness = parts.ready(walked, texts, kept);
72
+ const overlaid = parts.overlay(named);
73
+ const posing = parts.pose(named);
74
+
75
+ return {
76
+ named,
77
+ walked,
78
+ placing,
79
+ overlaid,
80
+ posing,
81
+ recorder,
82
+ url,
83
+ reads: {
84
+ refs: named.refs,
85
+ snapshot: read.snapshot,
86
+ find: subjected.find,
87
+ layout: parts.layout(named, walked, subjected, matching, placing).read,
88
+ overlay: overlaid.draw,
89
+ pose: posing.set,
90
+ unpose: posing.clear,
91
+ until: parts.expectations(named, subjected, matching).until,
92
+ text: texts.read,
93
+ record: recorder.start,
94
+ stopRecord: recorder.stop,
95
+ changes: parts.changes(named, walked, placing, kept, seeing, marking, recorder).read,
96
+ ready: readiness.wait,
97
+ settle: readiness.settle,
98
+ viewport: read.viewport,
99
+ },
100
+ };
101
+ };
@@ -19,8 +19,8 @@ import type { CDPSession, Page as PlaywrightPage } from "playwright-core";
19
19
  import type { CaptureSource } from "../../Browser.ts";
20
20
  import * as Errors from "../../BrowserError.ts";
21
21
  import type { BrowserEvent } from "../../BrowserEvent.ts";
22
- import * as BrowserClock from "../../Clock.ts";
23
22
  import type { InputGuard, Point } from "../../Page.ts";
23
+ import * as BrowserClock from "../clock.ts";
24
24
  import type { Gate } from "../input/gate.ts";
25
25
  import * as Lane from "./lane.ts";
26
26
  import type { Openings } from "./openings.ts";
@@ -35,9 +35,11 @@ export interface Settings {
35
35
  readonly actionTimeout: Duration.Duration;
36
36
  readonly policyTimeout: Duration.Duration;
37
37
  readonly navigationTimeout: Duration.Duration;
38
- /** How long screencast frames stay in `recentFrames`, measured back from the newest. */
38
+ /** How long screencast frames stay in `Frame.recent`, measured back from the newest. */
39
39
  readonly frameHistory: Duration.Duration;
40
40
  readonly guard: InputGuard | undefined;
41
+ /** The page clock's event name, when the browser runs one in each document. */
42
+ readonly pageTime?: string | undefined;
41
43
  }
42
44
 
43
45
  export interface MakeOptions {
@@ -0,0 +1,84 @@
1
+ /**
2
+ * What a page does behind the functions of its types' modules, such as `Snapshot.read`. `Page`
3
+ * gains a member only for identity, order, time or input; everything else a page does is one of
4
+ * these, which each page carries under `key`, and the modules' functions reach it there. `Page`'s
5
+ * type names nothing callable there, so the functions are the only way in.
6
+ */
7
+ import { type Effect, type Option, Predicate, type Scope } from "effect";
8
+
9
+ import type { BrowserError } from "../../BrowserError.ts";
10
+ import type { Box } from "../../BrowserEvent.ts";
11
+ import type { Changes, ChangesOptions } from "../../Change.ts";
12
+ import type {
13
+ Capture,
14
+ Frame,
15
+ FrameOptions,
16
+ Paint,
17
+ Region,
18
+ ScreencastOptions,
19
+ Zoom,
20
+ } from "../../Frame.ts";
21
+ import type { Layout, Picks } from "../../Layout.ts";
22
+ import type { Overlay } from "../../Overlay.ts";
23
+ import type { Page } from "../../Page.ts";
24
+ import type { Held } from "../../PageTime.ts";
25
+ import type { Poses } from "../../Pose.ts";
26
+ import type {
27
+ FindQuery,
28
+ Found,
29
+ Snapshot,
30
+ SnapshotOptions,
31
+ UntilResult,
32
+ UntilWant,
33
+ } from "../../Snapshot.ts";
34
+ import type { Text, TextOptions } from "../../Text.ts";
35
+ import type { Window, WindowOptions } from "../../Window.ts";
36
+
37
+ export const key = "~effect-browser/Page";
38
+
39
+ export interface Functions {
40
+ readonly snapshot: (options?: SnapshotOptions) => Effect.Effect<Snapshot, BrowserError>;
41
+ readonly find: (query?: FindQuery) => Effect.Effect<ReadonlyArray<Found>, BrowserError>;
42
+ readonly until: (
43
+ query: FindQuery,
44
+ want: UntilWant,
45
+ millis: number,
46
+ ) => Effect.Effect<UntilResult, BrowserError>;
47
+ readonly text: (options?: TextOptions) => Effect.Effect<Text, BrowserError>;
48
+ readonly layout: (picks: Picks) => Effect.Effect<Layout, BrowserError>;
49
+ readonly changes: (options?: ChangesOptions) => Effect.Effect<Changes, BrowserError>;
50
+ readonly window: (options: WindowOptions) => Effect.Effect<Window, BrowserError>;
51
+ readonly overlay: Effect.Effect<Overlay, BrowserError, Scope.Scope>;
52
+ readonly drawn: Effect.Effect<Option.Option<ReadonlyArray<Box>>>;
53
+ readonly poses: Effect.Effect<Poses, BrowserError, Scope.Scope>;
54
+ readonly hold: Effect.Effect<Held, BrowserError, Scope.Scope>;
55
+ readonly frame: (options?: FrameOptions) => Effect.Effect<Frame, BrowserError>;
56
+ readonly zoom: (
57
+ region: Region,
58
+ options?: Pick<FrameOptions, "quality" | "format" | "scale">,
59
+ ) => Effect.Effect<Zoom, BrowserError>;
60
+ readonly capture: (
61
+ options?: ScreencastOptions,
62
+ ) => Effect.Effect<Capture, BrowserError, Scope.Scope>;
63
+ readonly recentFrames: Effect.Effect<ReadonlyArray<Frame>>;
64
+ readonly paint: (options: Paint) => Effect.Effect<void, BrowserError, Scope.Scope>;
65
+ }
66
+
67
+ /** What a page carries under `key`: its functions, out of reach of any type outside this class. */
68
+ export class Implementation {
69
+ readonly #functions: Functions;
70
+
71
+ constructor(functions: Functions) {
72
+ this.#functions = functions;
73
+ }
74
+
75
+ static functionsOf(page: Page): Functions {
76
+ return page[key].#functions;
77
+ }
78
+ }
79
+
80
+ /** What `page` does behind its types' modules' functions. */
81
+ export const functionsOf = (page: Page): Functions => Implementation.functionsOf(page);
82
+
83
+ /** A page, as the library made it: what `dual` tells from a function's other arguments. */
84
+ export const isPage = (value: unknown): value is Page => Predicate.hasProperty(value, key);
@@ -7,9 +7,9 @@ import { Deferred, Duration, Effect, Schedule } from "effect";
7
7
 
8
8
  import { type Action, nameOf } from "../../Action.ts";
9
9
  import { BrowserError, NavigationFailed, NotActionable, NotFound } from "../../BrowserError.ts";
10
- import * as Url from "../../Url.ts";
11
10
  import type { Guard } from "../input/guard.ts";
12
11
  import type { InputMarks, Perform } from "../input/perform.ts";
12
+ import * as Url from "../url.ts";
13
13
  import { failWith, type PageContext, refuse } from "./context.ts";
14
14
  import { Current } from "./replies.ts";
15
15
 
@@ -7,7 +7,7 @@ import {
7
7
  type BrowserError,
8
8
  Closed,
9
9
  Failed,
10
- type Reason,
10
+ type BrowserErrorReason,
11
11
  } from "../../BrowserError.ts";
12
12
  import type * as Page from "../../Page.ts";
13
13
 
@@ -26,7 +26,7 @@ export const make = Effect.fnUntraced(function* (
26
26
  registrations: Registrations,
27
27
  closedBy: () => Closed["cause"],
28
28
  ) {
29
- const failed = (reason: Reason) => Exit.fail(undispatched("newPage", reason));
29
+ const failed = (reason: BrowserErrorReason) => Exit.fail(undispatched("newPage", reason));
30
30
 
31
31
  let active: Mark | undefined;
32
32
  const gone = Deferred.makeUnsafe<never, BrowserError>();
@@ -0,0 +1,96 @@
1
+ /**
2
+ * In the page: the library's overlay, a layer over the page that it draws a caller's SVG into,
3
+ * knowing nothing of what it shows. The layer is a closed shadow root on a host fixed over the
4
+ * viewport, above the page's own layers, that takes no pointer events, so input passes through to
5
+ * the page, and undoes the zoom the page sets on its root. Its styles are set through the CSSOM,
6
+ * which a strict `style-src` allows, and with priority, so the page's styles cannot reach it. The
7
+ * host is the library's own (see `names.inpage.ts`), so no reader reads it; the page's scripts can
8
+ * find the host, never what it holds. A site that owns its page can `mount` a layer of its own,
9
+ * whose root it renders into and whose parts may take the pointer. See `names.inpage.ts` for what a
10
+ * page-side part may use.
11
+ */
12
+ import type { Names } from "../reading/names.inpage.ts";
13
+
14
+ export const overlay = (names: Names) => {
15
+ const svgNamespace = "http://www.w3.org/2000/svg";
16
+ let host: HTMLElement | undefined;
17
+ let root: ShadowRoot | undefined;
18
+
19
+ const mount = (): ShadowRoot => {
20
+ if (host === undefined || root === undefined) {
21
+ host = document.createElement("div");
22
+ root = host.attachShadow({ mode: "closed" });
23
+ names.adopt(host);
24
+ const sheet = new CSSStyleSheet();
25
+
26
+ sheet.replaceSync(
27
+ "svg { position: absolute; left: 0; top: 0; width: 100%; height: 100%; overflow: visible }",
28
+ );
29
+ root.adoptedStyleSheets = [sheet];
30
+ }
31
+ const zoom = Number(getComputedStyle(document.documentElement).zoom) || 1;
32
+
33
+ for (const [name, value] of Object.entries({
34
+ all: "initial",
35
+ display: "block",
36
+ position: "fixed",
37
+ left: "0",
38
+ top: "0",
39
+ width: "100vw",
40
+ height: "100vh",
41
+ "pointer-events": "none",
42
+ "z-index": "2147483647",
43
+ contain: "strict",
44
+ zoom: String(1 / zoom),
45
+ }))
46
+ host.style.setProperty(name, value, "important");
47
+ if (host.parentNode !== document.documentElement) document.documentElement.append(host);
48
+
49
+ return root;
50
+ };
51
+
52
+ // The drawing's top-level parts, by their boxes in viewport CSS pixels; at most 32.
53
+ const boxes = (drawing: Element) =>
54
+ Array.from(drawing.children)
55
+ .slice(0, 32)
56
+ .map((part) => {
57
+ const { x, y, width, height } = part.getBoundingClientRect();
58
+
59
+ return { x, y, width, height };
60
+ })
61
+ .filter((box) => box.width > 0 && box.height > 0);
62
+
63
+ /**
64
+ * Draw an SVG document over the viewport, in place of what was drawn, or take the layer away
65
+ * with null. Says where the drawing's parts are. Its scripts and handlers are dropped.
66
+ */
67
+ const draw = (markup: string | null) => {
68
+ if (markup === null) {
69
+ host?.remove();
70
+
71
+ return [];
72
+ }
73
+ const parsed = new DOMParser().parseFromString(markup, "image/svg+xml");
74
+ const drawing = parsed.documentElement;
75
+
76
+ if (
77
+ parsed.getElementsByTagName("parsererror").length > 0 ||
78
+ drawing.namespaceURI !== svgNamespace ||
79
+ drawing.localName !== "svg"
80
+ )
81
+ throw new Error("the overlay's markup is not an SVG document");
82
+ for (const script of Array.from(drawing.getElementsByTagName("script"))) script.remove();
83
+ for (const element of [drawing, ...Array.from(drawing.querySelectorAll("*"))])
84
+ for (const attribute of Array.from(element.attributes))
85
+ if (/^on/i.test(attribute.name)) element.removeAttribute(attribute.name);
86
+ const shown = document.importNode(drawing, true);
87
+
88
+ mount().replaceChildren(shown);
89
+
90
+ return boxes(shown);
91
+ };
92
+
93
+ return { draw, mount };
94
+ };
95
+
96
+ export type Overlay = ReturnType<typeof overlay>;